-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
516 lines (494 loc) · 22.5 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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link href="./_css/mirac.css" rel="stylesheet" type="text/css" media="all">
<title>
MIRAC Emulator
</title>
<link rel="apple-touch-icon" sizes="180x180" href="./apple-touch-icon-180x180.png">
<link rel="icon" type="image/png" href="./favicon-192x192.png" sizes="192x192">
<link rel="icon" type="image/png" href="./favicon-160x160.png" sizes="160x160">
<link rel="icon" type="image/png" href="./favicon-96x96.png" sizes="96x96">
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16">
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32">
<meta name="mobile-web-app-capable" content="yes" />
</head>
<body>
<div id="centrificator">
<div class="register">
<h2>Program Ctr</h2>
<div id="r1" class="registerValue"></div>
</div><div class="register">
<h2>Accumulator</h2>
<div id="r0" class="registerValue"></div>
</div><div class="register">
<h2>Instruction</h2>
<div id="r2" class="registerValue"></div>
</div><div class="register">
<h2>Argument Rg</h2>
<div id="r3" class="registerValue"></div>
</div><div class="register">
<h2>ALU Operand</h2>
<div id="r4" class="registerValue"></div>
</div><div class="register">
<h2>Address Bus</h2>
<div id="r5" class="registerValue"></div>
</div><div class="register">
<h2>Data Bus In</h2>
<div id="r6" class="registerValue"></div>
</div><div class="register">
<h2>DataBus Out</h2>
<div id="r7" class="registerValue"></div>
</div>
<br />
<div id="moreRegistersPanel">
<div class="register">
<h2>StackPointr</h2>
<div id="r11" class="registerValue"></div>
</div><div class="register">
<h2>Gen.Purpose</h2>
<div id="r100" class="registerValue" title="g0"></div>
<div id="r101" class="registerValue" title="g1"></div>
<div id="r102" class="registerValue" title="g2"></div>
<div id="r103" class="registerValue" title="g3"></div>
<div id="r104" class="registerValue" title="g4"></div>
<div id="r105" class="registerValue" title="g5"></div>
<div id="r106" class="registerValue" title="g6"></div>
<div id="r107" class="registerValue" title="g7"></div>
</div><div class="register">
<h2>Device Addr</h2>
<div id="r8" class="registerValue"></div>
</div><div class="register">
<h2>Device Din</h2>
<div id="r9" class="registerValue"></div>
</div><div class="register">
<h2>Device Dout</h2>
<div id="r10" class="registerValue"></div>
</div>
</div><div id="about">
<img src="./Mirac-Logo.svg" id="miracLogo" width="320" alt="MIRAC Emulator"/>
<br />
<p>
This is a JavaScript emulation of the<br />
Minecraft Redstone Automatic Computer.
</p>
<p>
Documentation about the architecture, instruction set, assembly language and other topics:<br />
<a href="./docs/Mirac.pdf" target="_blank">Download</a> (pdf, 42k).
</p>
<p>
<a href="https://github.com/RolandR/MIRAC-Emulator" target="_blank">Github Repository</a>. Made by <a href="http://rolandrytz.ch" target="_blank">Roland Rytz</a>.
</p>
</div><div id="romInput" class="panel">
<h2>
<abbr title="MIDAS - Mirac Direct Assembly">MIDAS</abbr> Assembly Input
<button id="loadProgramButton" onclick="Control.showPopup('exampleProgramsPopup');">Load example...</button>
<button id="biggerButton" onclick="Control.toggleEditorSize();"></button>
</h2>
<div id="#romLines">
</div>
<div id="romTextContainer"><!--TextAreas are bugged-->
<textarea
id="romText"
spellcheck="false"
oninput="setTimeout(editor.onEdit)"
onkeydown="setTimeout(editor.onEdit);"
onkeyup="editor.onEdit();"
onpaste="setTimeout(editor.onEdit);"
onmouseup="editor.onEdit();"
onscroll="editor.onScroll();"
></textarea>
</div>
<div id="romDisplay" contenteditable="true"></div>
<div id="romControls">
<button id="loadRamButton" onclick="Control.loadToRam();"><span></span>Load to RAM</button>
<span id="atAddress"> starting at octal address </span>
<input id="loadToAddress" type="text" value="0">
</div>
</div>
<br />
<div id="leftpanel"><div id="ram" class="panel">
<h2>Memory</h2>
<table id="ramtable" class="memtable">
<tbody id="ramtbody"></tbody>
</table>
</div><br /><div id="octJoystick"><div id="octalDisplay" class="panel">
<h2 title="Device Address: 020">Oct Display</h2>
<div class="displayContainer">
<div class="displaySegment" id="displaySegment0"></div><div class="displaySegment" id="displaySegment1"></div><div class="displaySegment" id="displaySegment2"></div>
</div>
<span class="peripheryDocs" onclick="Control.showPopup('octalDisplayInfoPopup');">Docs</span>
</div><br /><!--div id="joystick" class="panel">
<h2 title="Device Address: 050">Joystick</h2>
<div class="joystickContainer">
<table>
<tr>
<td></td><td><button>^</button></td><td></td>
</tr>
<tr>
<td><button><</button></td><td><button>o</button></td><td><button>></button></td>
</tr>
<tr>
<td></td><td><button>v</button></td><td></td>
</tr>
</table>
</div>
<span class="peripheryDocs" onclick="Control.showPopup('dotMatrixInfoPopup');">Docs</span>
</div--></div><div id="dotMatrix" class="panel">
<h2 title="Device Addresses: 030 - 034">Dot Matrix</h2>
<div class="dotMatrixContainer">
<canvas id="dotMatrixCanvas" height="160" width="160"></canvas>
</div>
<span class="peripheryDocs" onclick="Control.showPopup('dotMatrixInfoPopup');">Docs</span>
</div><div id="asciiDisplay" class="panel">
<h2 title="Device Address: 040">ASCII Display</h2>
<div class="asciiDisplayContainer">
<span id="displayChar0">
</span><span id="displayChar1">
</span><span id="displayChar2">
</span><span id="displayChar3">
</span><span id="displayChar4">
</span><span id="displayChar5">
</span><span id="displayChar6">
</span><span id="displayChar7">
</span><span id="displayChar8">
</span><span id="displayChar9">
</span></div>
<span class="peripheryDocs" onclick="Control.showPopup('asciiDisplayInfoPopup');">Docs</span>
</div></div><div id="rightpanel"><div id="control" class="rightPanelDiv panel">
<h2>Control</h2>
<button id="run" class="runButton" onclick="Control.toggleRun()"><span></span>Start</button><!-- Maaaaan, why does html interpret line breaks? Even for inline elements, that's somewhat silly.
--><button id="resetpc" onclick="Control.reset();" title="Clears registers and flags."><span></span>Reset to start</button><br /><!--
--><button id="cycle" onclick="Control.cycle();" title="Single cycle step."><span></span>Step</button><!--
--><button id="resetmem" onclick="Control.hardReset();" title="Clears memory and all registers and flags."><span></span>Hard reset</button><!--
--><hr /><!--
--><span class="controlValueLabel">Cycle interval: </span><!--
--><input class="controlValue" id="cycleInterval" type="number" value="" /><!--
--><button class="controlValueButton" id="cycleIntervalButton" onclick="Control.updateCycleInterval();">Apply</button><!--
--><hr /><!--
--><span class="controlValueLabel">Set PC (octal): </span><!--
--><input class="controlValue" id="setPC" type="text" value="0" /><!--
--><button class="controlValueButton" id="setPCButton" onclick="Control.setPC();">Apply</button><!--
--><hr /><!--
--><span class="controlValueLabel" id="frequencyLabel">Running at: </span><!--
--><span class="controlValueLabel" id="frequency" title="Breathtaking speeds!">(Paused)</span><!--
--><hr /><!--
--><span class="controlValueLabel">Use animations: </span><!--
--><input class="controlValue" id="useAnimations" type="checkbox" checked="true" onclick="Control.updateUseAnimations();" /><!--
--><hr /><!--
--><span class="controlValueLabel">Update values: </span><!--
--><input class="controlValue" id="displayValues" type="checkbox" checked="true" onclick="Control.updateDisplayValues();" />
</div><div id="flags" class="rightPanelDiv panel">
<h2>Flags</h2>
<table id="flagtable">
<tbody>
<tr>
<td>Carry</td>
<td>Zero</td>
<td>Overflow</td>
<td>Negative</td>
</tr>
<tr>
<td id="f0" class="">0</td>
<td id="f1" class="">0</td>
<td id="f2" class="">0</td>
<td id="f3" class="">0</td>
</tr>
</tbody>
</table>
</div><div id="stack" class="rightPanelDiv panel">
<h2>Call Stack</h2>
<table id="stacktable" class="memtable">
<tbody id="stacktbody"></tbody>
</table>
</div>
<div id="rdLogoContainer">
<a href="http://rolandrytz.ch">
<img src="./RedstoneDigital-Logo.svg" id="rdLogo" width="320" alt="Redstone Digital"/>
</a>
</div>
</div>
</div>
<div id="popupOverlay">
<div id="overlayContainer">
<div class="popup" id="octalDisplayInfoPopup">
<h2>Info: Octal Display <button class="popupCloseButton" onclick="Control.hidePopup(this.parentElement.parentElement.id);">x</button></h2>
<section>
<h3>Octal Number Display</h3>
<table>
<tr><th>Address</th><th>Mode</th></tr>
<tr><td>020</td><td>Display single byte</td></tr>
</table>
<h3>Description</h3>
The octal display can display a single byte in base 8.<br />
Use is simple: Write a single bite to device address 020.
<h3>Examples</h3>
<code>
<span class="e-comment">// write octal 123 to display</span>
<br />
<span class="e-valid-instruction" title="Opcode 101">PDAI</span>
<span class="e-octal" title="Binary: 00010000">020</span>
<span class="e-comment">// set device address</span>
<br />
<span class="e-valid-instruction" title="Opcode 103">PDWI</span>
<span class="e-octal" title="Binary: 01010011">123</span>
<span class="e-comment">// write immediate byte</span>
</code>
<code>
<span class="e-comment">// write byte from memory address</span>
<br />
<span class="e-valid-instruction" title="Opcode 101">PDAI</span>
<span class="e-octal" title="Binary: 00010000">020</span>
<span class="e-comment">// set device address</span>
<br />
<span class="e-valid-instruction" title="Opcode 104">PDWM</span>
<span class="e-octal" title="Binary: 01000000">100</span>
<span class="e-comment">// write bite at memory location 100</span>
</code>
<code>
<span class="e-comment">// write byte from accumulator</span>
<br />
<span class="e-comment">// we're going to use the result of an addition</span>
<br />
<span class="e-valid-instruction" title="Opcode 002">LDAI</span>
<span class="e-decimal" title="Octal: 024">20.</span>
<span class="e-comment">// load decimal 20</span>
<br />
<span class="e-valid-instruction" title="Opcode 005">OPRA</span>
<span class="e-comment">// write accumulator to operand register</span>
<br />
<span class="e-valid-instruction" title="Opcode 002">LDAI</span>
<span class="e-decimal" title="Octal: 052">42.</span>
<span class="e-comment">// load decimal 42</span>
<br />
<span class="e-valid-instruction" title="Opcode 006">ADDC</span>
<span class="e-comment">// perform addition</span>
<br />
<span class="e-valid-instruction" title="Opcode 101">PDAI</span>
<span class="e-octal" title="Binary: 00010000">020</span>
<span class="e-comment">// set device address</span>
<br />
<span class="e-valid-instruction" title="Opcode 105">PDWA</span>
<span class="e-comment">// write addition result to display</span>
</code>
</section>
</div>
<div class="popup" id="dotMatrixInfoPopup">
<h2>Info: Dot Matrix <button class="popupCloseButton" onclick="Control.hidePopup(this.parentElement.parentElement.id);">x</button></h2>
<section>
<h3>Dot Matrix Display</h3>
<table>
<tr><th>Address</th><th>Mode</th></tr>
<tr><td>030</td><td>Flip pixel at coordinates YYYY XXXX</td></tr>
<tr><td>031</td><td>Turn on pixel at coordinates YYYY XXXX</td></tr>
<tr><td>032</td><td>Turn off pixel at coordinates YYYY XXXX</td></tr>
<tr><td>033</td><td>Push byte to dot matrix, each byte controlling a pixel.</td></tr>
<tr><td>034</td><td>Fill matrix with pattern in pdout</td></tr>
</table>
<h3>Description</h3>
A 16x16 pixel monochrome dot matrix display.<br />
There are various modes for controlling it, including manipulating single pixels, badge feeding entire bytes and filling the screen with a single-byte pattern.
<h3>Examples</h3>
<code>
<span class="e-comment">// Flip a pixel somewhere in the middle</span>
<br />
<span class="e-valid-instruction" title="Opcode 101">PDAI</span>
<span class="e-octal" title="Binary: 00011000">030</span>
<br />
<span class="e-valid-instruction" title="Opcode 103">PDWI</span>
<span class="e-binary" title="Octal: 131">#01011001</span>
<span class="e-comment">// y = 5, x = 9</span>
</code>
<code>
<span class="e-comment">// Turn on and then off the bottom left pixel</span>
<br />
<span class="e-valid-instruction" title="Opcode 101">pdai</span>
<span class="e-octal" title="Binary: 00011001">031</span>
<br />
<span class="e-valid-instruction" title="Opcode 103">pdwi</span>
<span class="e-binary" title="Octal: 360">#11110000</span>
<span class="e-comment">// y = 15, x = 0</span>
<br />
<span class="e-valid-instruction" title="Opcode 101">pdai</span>
<span class="e-octal" title="Binary: 00011010">032</span>
<br />
<span class="e-valid-instruction" title="Opcode 103">pdwi</span>
<span class="e-binary" title="Octal: 360">#11110000</span>
</code>
<code>
<span class="e-comment">// Fill in some pixels, starting from the top</span>
<br />
<span class="e-valid-instruction" title="Opcode 101">pdai</span>
<span class="e-octal" title="Binary: 00011011">033</span>
<br />
<span class="e-valid-instruction" title="Opcode 103">pdwi</span>
<span class="e-binary" title="Octal: 210">#10001000</span>
<span class="e-valid-instruction" title="Opcode 103">pdwi</span>
<span class="e-binary" title="Octal: 210">#10001000</span>
<br />
<span class="e-valid-instruction" title="Opcode 103">pdwi</span>
<span class="e-binary" title="Octal: 314">#11001100</span>
<span class="e-valid-instruction" title="Opcode 103">pdwi</span>
<span class="e-binary" title="Octal: 314">#11001100</span>
<br />
<span class="e-valid-instruction" title="Opcode 103">pdwi</span>
<span class="e-binary" title="Octal: 252">#10101010</span>
<span class="e-valid-instruction" title="Opcode 103">pdwi</span>
<span class="e-binary" title="Octal: 252">#10101010</span>
<br />
<span class="e-valid-instruction" title="Opcode 103">pdwi</span>
<span class="e-binary" title="Octal: 377">#11111111</span>
<span class="e-valid-instruction" title="Opcode 103">pdwi</span>
<span class="e-binary" title="Octal: 377">#11111111</span>
<br />
<span class="e-comment">// Mode 033 is useful for displaying entire images</span>
</code>
<code>
<span class="e-comment">// Blank screen</span>
<br />
<span class="e-valid-instruction" title="Opcode 101">pdai</span>
<span class="e-octal" title="Binary: 00011100">034</span>
<br />
<span class="e-valid-instruction" title="Opcode 103">pdwi</span>
<span class="e-binary" title="Octal: 000">#00000000</span>
</code>
</section>
</div>
<div class="popup" id="asciiDisplayInfoPopup">
<h2>Info: ASCII Display <button class="popupCloseButton" onclick="Control.hidePopup(this.parentElement.parentElement.id);">x</button></h2>
<section>
<h3>ASCII Text Display</h3>
<table>
<tr><th>Address</th><th>Mode</th></tr>
<tr><td>040</td><td>Set or replace character right of caret</td></tr>
<tr><td>041</td><td>Set or replace character at caret</td></tr>
<tr><td>042</td><td>Clear and reset</td></tr>
</table>
<h3>Description</h3>
A 10-character ASCII text display.<br />
The display has an internal caret (cursor).<br />
It increments if characters are written in mode 040. It wraps around when it reaches the last position.<br />
Reset (Mode 042) resets the caret to position 0.<br />
<br />
The character 127 (octal 177) acts as backspace.<br />
It will clear the character at the caret, and decrement the caret position.<br />
<h3>Examples</h3>
<code>
<span class="e-comment">// Write "Foo" at cursor</span>
<br />
<span class="e-valid-instruction" title="Opcode 101">pdai</span>
<span class="e-octal" title="Binary: 00100000">040</span>
<br />
<span class="e-valid-instruction" title="Opcode 103">pdwi</span>
<span class="e-valid-char" title="Octal: 70">'F'</span>
<br />
<span class="e-valid-instruction" title="Opcode 103">pdwi</span>
<span class="e-valid-char" title="Octal: 111">'o'</span>
<br />
<span class="e-valid-instruction" title="Opcode 103">pdwi</span>
<span class="e-valid-char" title="Octal: 112">'p'</span>
<br />
<span class="e-valid-instruction" title="Opcode 103">pdwi</span>
<span class="e-decimal" title="Octal: 177">127.</span>
<span class="e-comment">//127 is backspace</span>
<br />
<span class="e-valid-instruction" title="Opcode 103">pdwi</span>
<span class="e-valid-char" title="Octal: 111">'o'</span>
</code>
<code>
<span class="e-comment">// Clear and reset</span>
<br />
<span class="e-valid-instruction" title="Opcode 101">pdai</span>
<span class="e-octal" title="Binary: 00100010">042</span>
<br />
<span class="e-valid-instruction" title="Opcode 103">pdwi</span>
<span class="e-octal" title="Binary: 00000000">000</span>
<span class="e-comment">// Could be any value</span>
</code>
<code>
<span class="e-comment">// Blinking cursor animation</span>
<br />
<span class="e-valid-instruction" title="Opcode 101">pdai</span>
<span class="e-octal" title="Binary: 00100001">041</span>
<br />
<span class="e-define-label">$loop:</span>
<br />
<span class="e-valid-instruction" title="Opcode 103">pdwi</span>
<span class="e-valid-char" title="Octal: 32">' '</span>
<br />
<span class="e-valid-instruction" title="Opcode 000">nope</span>
<span class="e-comment">// for timing, because jmpi takes one tick</span>
<br />
<span class="e-valid-instruction" title="Opcode 103">pdwi</span>
<span class="e-valid-char" title="Octal: 95">'_'</span>
<br />
<span class="e-valid-instruction" title="Opcode 004">jmpi</span>
<span class="e-label">$loop</span>
</code>
</section>
</div>
<div class="popup" id="exampleProgramsPopup">
<h2>Example Programs <button class="popupCloseButton" onclick="Control.hidePopup(this.parentElement.parentElement.id);">x</button></h2>
<section>
<div class="sampleProgram">
<button class="sampleProgramButton" onclick="Control.openSampleProgram('bouncing_ball.midas')">Open</button>
<h3>Bouncing Ball</h3>
Displays a bouncing ball on the dot matrix.
</div>
<div class="sampleProgram">
<button class="sampleProgramButton" onclick="Control.openSampleProgram('show_picture.midas')">Open</button>
<h3>Show Picture</h3>
Displays a static image on the dot matrix.
</div>
<div class="sampleProgram">
<button class="sampleProgramButton" onclick="Control.openSampleProgram('winking_owl.midas')">Open</button>
<h3>Winking Owl</h3>
Shows a way to display two alternating images.
</div>
<div class="sampleProgram">
<button class="sampleProgramButton" onclick="Control.openSampleProgram('visual_quine.midas')">Open</button>
<h3>Visual Quine</h3>
This program draws a visual representation of itself.
</div>
<div class="sampleProgram">
<button class="sampleProgramButton" onclick="Control.openSampleProgram('string_loader.midas')">Open</button>
<h3>String Loader</h3>
Displays a string of characters on the ASCII display.
</div>
<div class="sampleProgram">
<button class="sampleProgramButton" onclick="Control.openSampleProgram('generic_sample_program.midas')">Open</button>
<h3>Stack demo</h3>
A simple example program with recursion.
</div>
</section>
</div>
<div class="popup" id="errorPopup">
<h2>Error <button class="popupCloseButton" onclick="Control.hidePopup(this.parentElement.parentElement.id);">x</button></h2>
<section id="errors">
</section>
</div>
</div>
</div>
<script type="text/javascript" src="./_js/setZeroTimeout.js"></script>
<script type="text/javascript" src="./_js/loadFile.js"></script>
<script type="text/javascript" src="./_js/Config.js"></script>
<script type="text/javascript" src="./_js/Conversions.js"></script>
<script type="text/javascript" src="./_js/Register.js"></script>
<script type="text/javascript" src="./_js/Flag.js"></script>
<script type="text/javascript" src="./_js/Mem.js"></script>
<script type="text/javascript" src="./_js/Mirac.js"></script>
<script type="text/javascript" src="./_js/ALU.js"></script>
<script type="text/javascript" src="./_js/OctalDisplay.js"></script>
<script type="text/javascript" src="./_js/DotMatrix.js"></script>
<script type="text/javascript" src="./_js/AsciiDisplay.js"></script>
<script type="text/javascript" src="./_js/Devices.js"></script>
<script type="text/javascript" src="./_js/Ins.js"></script>
<script type="text/javascript" src="./_js/Opcode.js"></script>
<script type="text/javascript" src="./_js/Opcodes.js"></script>
<script type="text/javascript" src="./_js/Assembler.js"></script>
<script type="text/javascript" src="./_js/Control.js"></script>
<script type="text/javascript" src="./_js/Editor.js"></script>
<script type="text/javascript" src="./_js/Emulator.js"></script>
</body>
</html>