/
dcpu.htm
185 lines (172 loc) · 7.65 KB
/
dcpu.htm
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
<html>
<head>
<title>DCPU-16 emulator</title>
<link rel="stylesheet" href="css/dcpu.css">
<script type="text/javascript" src="js/common.js?v=1"></script>
<script type="text/javascript" src="js/assembler.js?v=4"></script>
<script type="text/javascript" src="js/disassembler.js?v=1"></script>
<script type="text/javascript" src="js/emulator.js?v=1"></script>
<script type="text/javascript" src="js/screen.js?v=1"></script>
<script type="text/javascript" src="js/keyboard.js?v=1"></script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-31249994-1']);
_gaq.push(['_setDomainName', 'dcpu.ru']);
_gaq.push(['_setAllowLinker', true]);
_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>
<style>
</style>
</head>
<body>
<h3>DCPU-16 Assembler, Emulator & Disassembler</h3>
<div class="notice">by deNULL. Report any problems at <a href="mailto:me@denull.ru">me@denull.ru</a>.</div>
<table width="100%" border=0 cellpadding=0 cellspacing=0 style="padding-top: 6px"><tr valign=top>
<td width="80%">
<div class="tabs"><a href="javascript:" onclick="toggleTab(0)" class="tab_active" id="tab0">Assembler</a><a href="javascript:" onclick="toggleTab(1)" class="tab_inactive" id="tab1">Disassembler</a></div>
<div id="tab0_wrapper">
<table width="100%" id="assembler" cellpadding=0 cellspacing=0><tr valign=top>
<td width="20"><div class="hlight_wrap"><div class="line_highlight" id="hlight1"></div></div><div class="editor" id="linenums"></div></td>
<td width="60%"><div class="hlight_wrap"><div class="line_highlight" id="hlight2"></div></div><textarea class="editor" id="code" onkeyup="assemble()" onchange="assemble()" wrap=off spellcheck="false" placeholder="Place your code here"><?php
$default_code = <<<EOF
; 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, crash ; 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, crash ; 7dc1 001a [*]
:testsub SHL X, 4 ; 9037
SET PC, POP ; 61c1
; Hang forever. X should now be 0x40 if everything went right.
:crash SET PC, crash ; 7dc1 001a [*]
; [*]: Note that these can be one word shorter and one cycle faster by using the short form (0x00-0x1f) of literals,
; but my assembler doesn't support short form labels yet.
EOF;
$code = $default_code;
if (isset($_REQUEST['code'])) {
$code = $_REQUEST['code'];
}
echo htmlspecialchars($code);?></textarea>
</td>
<!--
; Assembler test for DCPU
; by Markus Persson
:start
set i, 0
set j, 0
set b, 0xf100
:nextchar
set a, [data+i]
ife a, 0
set PC, end
ifg a, 0xff
set PC, setcolor
bor a, b
set [0x8000+j], a
add i, 1
add j, 1
set PC, nextchar
:setcolor
set b, a
and b, 0xff
shl b, 8
ifg a, 0x1ff
add b, 0x80
add i, 1
set PC, nextchar
:data
dat 0x170, "Hello ", 0x2e1, "world", 0x170, ", how are you?"
:end
set PC, start
-->
<td width="30"><div class="hlight_wrap"><div class="line_highlight" id="hlight3"></div></div><div class="editor" id="offsets"></div></td>
<td width="40%"><div class="hlight_wrap"><div class="line_highlight" id="hlight4"></div></div><div class="editor" id="dump"></div></td>
</tr>
<tr valign=top><td></td><td colspan=3>
<!--<button id="loadsrc" onclick="ge('savesrc_f').click();">Load source...</button>
<button onclick="ge('savesrc_f').click();" id="savesrc">Save source...</button>
<button onclick="ge('savebin_f').click();" id="savebin">Save assembled code...</button>-->
<span class="notice">Click on the line numbers to toggle breakpoints.</span>
</td></tr>
</table>
</div>
<div id="tab1_wrapper">
<table width="100%" id="disassembler" cellpadding=0 cellspacing=0><tr valign=top>
<td width="40%"><textarea class="editor" id="da_input" onkeyup="disassemble()" onchange="disassemble()" wrap=off placeholder="Place your hex codes here"></textarea></td>
<td width="30"><div class="editor" id="da_lines"></div></td>
<td width="60%"><div class="editor" id="da_code"></div></td>
</tr>
<tr valign=top><td colspan=3>
<!--<button onclick="loadbin()" id="loadbin">Load binary...</button>
<button onclick="savebin2()" id="savebin2">Save binary...</button>
<button onclick="savedisasm()" id="savedisasm">Save disassembled code...</button>-->
</td></tr>
</table>
</div>
</td>
<td rowspan=2 width="20%" id="debugger" style="padding-left: 20px">
<span>Cycles: </span><span id="cycles">0</span><br/>
<button onclick="run(this)" id="button_run" class="big"/>↓ Run (F5)</button><button onclick="step()" class="big"/>↪ Step (F6)</button><button onclick="reset()" class="big">↺ Reset</button><br/>
<label for="show_pc"><input type="checkbox" id="show_pc" name="show_pc" checked="checked" onchange="toggleShowPC()"/> Show current line</label>
<h4>Screen:</h4>
<div id="screen_wrapper">
<canvas id="screen" width="384" height="288"></canvas>
<img id="loading_overlay" src="http://i.imgur.com/DcNzS.png" width="384" height="288"/>
</div>
<div class="notice">Keyboard input is available while the program is running.</div>
<h4>Registers:</h4>
<table border=0 class="editor">
<tr>
<td class="reg_name">PC:</td><td id="regPC" class="cur_pc">0</td>
<td class="reg_name">SP:</td><td id="regSP" class="cur_sp">0</td>
<td class="reg_name">IA:</td><td id="regIA" class="cur_ia">0</td>
</tr> <tr>
<td class="reg_name">A:</td><td id="regA">0</td>
<td class="reg_name">B:</td><td id="regB">0</td>
<td class="reg_name">C:</td><td id="regC">0</td>
</tr> <tr>
<td class="reg_name">X:</td><td id="regX">0</td>
<td class="reg_name">Y:</td><td id="regY">0</td>
<td class="reg_name">Z:</td><td id="regZ">0</td>
</tr> <tr>
<td class="reg_name">I:</td><td id="regI">0</td>
<td class="reg_name">J:</td><td id="regJ">0</td>
</tr> <tr>
<td class="reg_name">EX:</td><td id="regEX">0</td>
</tr>
</table>
<button onclick="disassembleDump()" id="disassembleDump">Disassemble</button>
<h4>Memory dump:</h4>
<div id="memory_wrapper">
<div id="memory_window" onscroll="updateMemoryView()">
<div id="memory_stub">
<div id="memory_lines" class="editor"></div>
<div id="memory_view" class="editor"></div></div>
</div>
</div>
</td>
</tr><tr valign=top>
<td colspan=3>
<div id="log" class="editor"></div></td>
</tr></table>
<canvas id="fontCanvas" style="display: none"></canvas>
<script language="javascript" src="js/ui.js?v=1">
</script>
</body>
</html>