forked from IchigoJam/asm15
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathasm15dom.js
73 lines (71 loc) · 2.24 KB
/
asm15dom.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"use strict";
function run_assemble() {
const dom_src=document.getElementById("textarea1");
const dom_fmt=document.getElementById("selfmt");
const dom_hex=document.getElementById("textarea2");
const dom_adr=document.getElementById("txtadr");
const dom_len=document.getElementById("uselineno");
const dom_lst=document.getElementById("linenostart");
const dom_lde=document.getElementById("linenodelta");
dom_hex.innerHTML=""
const result = assemble(dom_src.value, dom_fmt.value, {
startAddress: dom_adr.value,
useLineno: dom_len.checked,
linenoStart: dom_lst.value,
linenoDelta: dom_lde.value,
});
if (result.errors.length > 0) alert(result.errors.join("\n\n"));
const bas = result.bas;
let resultData = null;
if (bas instanceof ArrayBuffer) {
const basView = new Uint8Array(bas);
let hexdumped = "";
for (let i = 0; i < basView.length; i += 16) {
const address = "0000000" + i.toString(16);
hexdumped += address.substring(address.length - 8) + " ";
let hexs = "", chars = "";
for (let j = 0; j < 16 && i + j < basView.length; j++) {
const v = basView[i + j];
const hex = "0" + v.toString(16);
hexs += " " + hex.substring(hex.length - 2);
chars += 0x20 <= v && v < 0x7f ? String.fromCharCode(v) : ".";
}
hexdumped += hexs;
for (let i = hexs.length; i < 3 * 16; i += 3) hexdumped += " ";
hexdumped += " |" + chars + "|\n";
}
dom_hex.value = hexdumped;
resultData = bas;
} else {
dom_hex.value = bas;
resultData = new TextEncoder().encode(bas);
}
binsize.textContent = result.size;
URL.revokeObjectURL(downloadlink.href);
downloadlink.href = URL.createObjectURL(new Blob([resultData]));
downloadlink.setAttribute("download", "result." + fmt_dict[dom_fmt.value].ext);
/*
if (dom_hex.textContent==bas)
return;
dom_hex.textContent = bas;
if (dom_hex.textContent==bas)
return;
dom_hex.innerText=bas;
if (dom_hex.innerText==bas)
return;
dom_hex.innerHTML=bas;
if (dom_hex.innerHTML==bas)
return;
*/
}
function example() {
const dom_src = document.getElementById("textarea1");
const dom_ex = document.getElementById("selex");
const exname = dom_ex.value;
if (!exname) {
return false;
}
fetch("samples/" + exname + ".asm")
.then(res => res.text())
.then(text => dom_src.value = text);
}