-
Notifications
You must be signed in to change notification settings - Fork 18
/
index.html
185 lines (170 loc) · 5.44 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>DCPU-16</title>
<style type="text/css">
@font-face { font-family: Commodore; src: url('Commodore.ttf'); }
body {
background: #bbb;
font-family: Commodore;
}
#container {
padding: 6px;
z-index: 1000;
}
#container a {
color: #444;
}
button {
border: 4px solid #000;
background: #222;
color: #fff;
font-size: 24px;
font-family: Commodore;
}
button:active {
background: #aaf;
}
textarea, canvas {
background: #222;
color: #fff;
border: 8px solid #000;
font-family: Commodore;
font-size: 12px;
}
#consoleContainer {
-webkit-perspective: 2200;
-moz-perspective: 2200;
}
.perspective {
-webkit-transform: rotateY(32deg);
-moz-transform: rotateY(32deg);
}
canvas {
z-index: -1;
}
</style>
<script type="text/javascript" src="./lib/cpu.js"></script>
<script type="text/javascript" src="./lib/LEM1802.js"></script>
<script type="text/javascript" src="./lib/assembler.js"></script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-30599135-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<div id="container">
<a href="http://github.com/mappum/DCPU-16"><h1>DCPU-16 Emulator</h1></a>
<h2>V0.8 - By Mappum</h2>
<p><strong>Hey there!</strong> This page is mostly for testing the emulator. If you want a real site to develop on, go to <a href="http://0x10co.de">0x10co.de</a>.</p>
<textarea id="editor" cols="60" rows="40">
; Try some basic stuff
SET A, 0x30 ; 7c01 0030
SET [0x1000], 0x20 ; 7de1 1000 0020
SUB A, [0x1000] ; 7803 1000
IFN A, 0x10 ; c00d
SET PC, break ; 7dc1 001a [*]
; Do a loopy thing
SET I, 10 ; a861
SET A, 0x2000 ; 7c01 2000
:loop SET [0x2000+I], [A] ; 2161 2000
SUB I, 1 ; 8463
IFN I, 0 ; 806d
SET PC, loop ; 7dc1 000d [*]
; Call a subroutine
SET X, 0x4 ; 9031
JSR testsub ; 7c10 0018 [*]
SET PC, print ; 7dc1 001a [*]
:testsub SHL X, 4 ; 9037
SET PC, POP ; 61c1
; "Hello, world!"
; Set 0x8000 - 0x8180 to an ASCII value to output to console
:print
; Set up the display
SET A, 0
SET B, 0x8000
HWI 0
SET I, 0
:printloop
IFE [data+I], 0
SET PC, break
SET [0x8000+I], [data+I]
BOR [0x8000+I], 0xf000
ADD I, 1
SET PC, printloop
; BRK (break) is non-standard
:break BRK
:data DAT "Hello, world!\0"
</textarea>
<textarea id="debug" cols="45" rows="40" readonly="readonly"></textarea>
<div style="clear:both;">
<button onclick="compile()">Assemble</button>
<button onclick="step()">Step</button>
<button onclick="run()">Run</button>
<button onclick="stop()">Stop</button>
<button onclick="reset();">Reset</button>
<label for="debugToggle">Debug:</label>
<input id="debugToggle" type="checkbox" checked="checked" />
</div>
<hr />
<div id="consoleContainer">
<h2>Console:</h2>
<canvas id="console" class="perspective"></canvas>
<br />
<input id="input" type="text" style="margin-left: 300px; width:200px; height:32px; vertical-align: bottom" />
<button id="submit" style="width:68px" onclick="sendInput()">>></button>
</div>
</div>
<script type="text/javascript">
var cpu = new DCPU16.CPU(),
display = new LEM1802('console');
cpu.addDevice(display);
function compile() {
var assembler = new DCPU16.Assembler(cpu);
try {
console.log(assembler.serialize(document.getElementById('editor').value));
assembler.compile(document.getElementById('editor').value);
document.getElementById('debug').value = cpu.getDump();
} catch(e) {
document.getElementById('debug').value = e;
console.log(assembler);
}
}
function step() {
cpu.step();
document.getElementById('debug').value = cpu.getDump();
}
function run() {
cpu.run(function() {
if(document.getElementById('debugToggle').checked)
document.getElementById('debug').value = cpu.getDump();
});
if(!document.getElementById('debugToggle').checked) document.getElementById('debug').value = 'Executing...';
}
function stop() {
cpu.stop();
document.getElementById('debug').value = cpu.getDump();
}
function reset() {
cpu.reset();
document.getElementById('debug').value = cpu.getDump();
display.clear();
}
function sendInput() {
input.write(document.getElementById('input').value);
document.getElementById('input').value = '';
}
cpu.onEnd(function() {
document.getElementById('debug').value = cpu.getDump();
});
</script>
</body>
</html>