-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
92 lines (70 loc) · 2.13 KB
/
index.html
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<!DOCTYPE html>
<html>
<head>
<title>chASM</title>
<meta charset='UTF-8'>
<link rel='stylesheet' href='./src/index.css'>
</head>
<body>
<h1>chASM</h1>
<p>CHIP-8 Assembly Language in JavaScript</p>
<hr>
<!-- FRONTEND -->
<div>
<!-- chasm input -->
<textarea id='chasm-input' class='codein' spellcheck='false'></textarea>
<br>
<!-- chasm output -->
<button id='chasm-compile' class='button'>ASSEMBLE</button>
<button id='chasm-hexdump' class='button'>HEXDUMP</button>
<br>
<!-- chasm debug -->
<pre id='chasm-hexout' class='codeout'>(hexdump)</pre>
</div>
<!-- BACKEND -->
<script src='./src/filesaver.js'></script>
<script src='./src/chasm.js'></script>
<script>
window.onload = function () {
function $ (id) {
return document.getElementById (id);
};
// Elements //
var html = {
input: $ ('chasm-input'),
compile: $ ('chasm-compile'),
hexdump: $ ('chasm-hexdump'),
hexout: $ ('chasm-hexout')
};
html.input.addEventListener('keydown', function(e) {
if (e.key == 'Tab') {
e.preventDefault();
var start = this.selectionStart;
var end = this.selectionEnd;
// set textarea value to: text before caret + tab + text after caret
this.value = this.value.substring(0, start) +
"\t" + this.value.substring(end);
// put caret at right position again
this.selectionStart =
this.selectionEnd = start + 1;
}
});
// Element Functions //
html.compile.onclick = function () {
var bin = _Assemble (html.input.value, html.hexout);
var blob = new Blob ([new Uint8Array (bin)], {type: 'application/octet-stream'});
saveAs (blob, 'src.bin');
};
html.hexdump.onclick = function () {
var bin = _Assemble (html.input.value, html.hexout);
html.hexout.innerHTML = 'HEXDUMP:\n' + _GetHexdump (bin);
};
};
</script>
<hr>
<div>
<p>nectarboy - 2020</p>
<a href='https://github.com/nectarboy/chasm'><p>source</p></a>
</div>
</body>
</html>