forked from mappum/DCPU-16
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
277 lines (242 loc) · 7.46 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<!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 {
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/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 I, 0
:printloop
IFE [data+I], 0
SET PC, break
SET [0x8000+I], [data+I]
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>
<textarea id="console" cols="30" rows="12" readonly="readonly" class="perspective"></textarea>
<br />
<input id="input" type="text" style="width:200px; height:32px; vertical-align: bottom" />
<button id="submit" style="width:68px" onclick="sendInput()">>></button>
</div>
</div>
<script type="text/javascript">
var Display = (function() {
function Display(el) {
var length = 32*12;
this.screen = [];
this.screen.length = length;
this.length = length;
this.el = el;
// bind the callbacks
this.get = this.get.bind(this);
this.set = this.set.bind(this);
this.reset();
}
Display.prototype = {
get: function(idx) {
return this.screen[idx];
},
set: function(idx, val) {
this.screen[idx] = [val >> 7, val & 0x7F];
var string = '';
for (var i = 0, _len = this.screen.length; i < _len; ++i)
string += String.fromCharCode(this.screen[i][1]);
string.replace('\n', '');
this.el.value = string;
},
reset: function() {
for (var i = 0, _len = this.screen.length; i < _len; ++i)
this.screen[i] = [0, 32];
}
};
return Display;
})();
var cpu = new DCPU16.CPU();
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.clear();
document.getElementById('debug').value = cpu.getDump();
document.getElementById('console').value = '';
}
function sendInput() {
input.write(document.getElementById('input').value);
document.getElementById('input').value = '';
}
cpu.onEnd(function() {
display.reset();
document.getElementById('debug').value = cpu.getDump();
});
</script>
<script type="text/javascript" src="lib/Three.js"></script>
<script type="text/javascript">
var scene, camera, renderer, cubes = [];
function init() {
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 1, 10000);
camera.position.y = 150;
camera.position.z = 500;
scene.add(camera);
for(var i = 0; i < 40; i++) {
var color = (Math.random() * 60) + 100;
color |= color << 8;
color |= (color & 0xff) << 16;
materials = new THREE.MeshBasicMaterial({color: color});
var geom = new THREE.CubeGeometry(Math.random() * 200 + 100,
Math.random() * 200 + 100, Math.random() * 200 + 100);
var cube = new THREE.Mesh(geom, materials);
cube.doubleSided = true;
cube.position.x = Math.random() * window.innerWidth - window.innerWidth / 2;
cube.position.y = Math.random() * window.innerWidth - window.innerWidth / 2;
cube.position.z = Math.random() * -600 - 200;
cube.rotation.x = Math.random() * 360;
cube.rotation.y = Math.random() * 360;
cube.rotation.z = Math.random() * 360;
scene.add(cube);
cubes.push(cube);
}
var light = new THREE.PointLight(0xffffff);
light.position.x = 500;
light.position.y = 550;
light.position.z = 500;
scene.add(light);
renderer = new THREE.CanvasRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
var el = renderer.domElement;
el.style.position = 'absolute';
el.style.left = 0;
el.style.top = 0;
el.style['z-index'] = -1;
document.body.appendChild(el);
}
if(navigator.platform.substr(0, 3) === 'Win'
|| navigator.platform === 'Mac'
|| navigator.platform === 'Linux') {
init();
renderer.render(scene, camera);
}
</script>
</body>
</html>