comparison simple16.html @ 39:52d601e13ea4

WIP documentation
author Michael Pavone <pavone@retrodev.com>
date Wed, 06 Apr 2016 12:15:25 -0700
parents
children 413e7b9c0db1
comparison
equal deleted inserted replaced
38:3b7910575a00 39:52d601e13ea4
1 <!doctype html>
2 <html>
3 <head>
4 <style>
5 body {
6 font-family: Helvetica, Arial, sans-serif;
7 }
8 </style>
9 </head>
10 <body>
11 <h1>Simple 16</h1>
12 <p>
13 Simple 16 is a toy 16-bit video game console designed with simplicity of implementation in mind. While it is technically a 16-bit system,
14 it's capabilites are in many ways closer to an 8-bit system. Ultimately, the hope is that Simple 16 is simple enough to provide an easy
15 introduction for the novice emudev while still containing all the essential features of an older game console.
16
17 </p>
18 <h2>Table of Contents</h2>
19 <ul>
20 <li><a href="#cpu">CPU</a>
21 <ul>
22 <li><a href="#cpuover">Overview</a></li>
23 <li><a href="#cpuregs">Registers</a></li>
24 <li><a href="#instructions">Instructions</a></li>
25 <li><a href="#execution">Execution Details</a></li>
26 <li><a href="#interrupts">Exceptions and Interrupts</a></li>
27 </ul>
28 </li>
29 <li><a href="#video">Video</a></li>
30 <li><a href="#audio">Audio</a></li>
31 <li><a href="#timer">Timer</a></li>
32 <li><a href="#controllers">Controllers</a></li>
33 <li><a href="#serial">Serial Port</a></li>
34 <li><a href="#cart">Cartridge</a></li>
35 </ul>
36 <h2 id="cpu">CPU</h2>
37 <h3 id="cpuover">Overview</h3>
38 <p>
39 The Simple 16 CPU is a 16-bit RISC design. It has a main register file of 16 16-bit registers. Additionally, there are five special
40 purpose registers dedicated to exception processing. It has a flag 16-bit addres space. Instructions are a fixed size and are also 16-bits.
41 </p>
42 <h3 id="cpuregs">Registers</h3>
43 <p>
44 The first 14 registers in the main file have no fixed function and are named r0 through r13. r14 serves as the program counter and
45 points to the next instruction to be fetched. More information about instruction fetch and execution can be found in
46 <a href="#execution">Execution Details</a>. r15 serves as the status register. The status register contains bits corresponding
47 to the result of the last arithmetic instruction and the interrupt mask. The layout of the status register is given below.
48 </p>
49 <table>
50 <tr>
51 <th>Bit</th>
52 <th>Use</th>
53 <th>Notes</th>
54 <tr>
55 <td>15-5</td>
56 <td>Unused</td>
57 <td>Should be set to zero.</td>
58 </tr>
59 <tr>
60 <td>4</td>
61 <td>Negative Flag</td>
62 <td>Indicates the last result was negative.</td>
63 </tr>
64 <tr>
65 <td>3</td>
66 <td>Carry Flag</td>
67 <td>Generally indicates a carry out of bit 15. Last bit shifted out for shift instructions.</td>
68 </tr>
69 <tr>
70 <td>2</td>
71 <td>Zero fFag</td>
72 <td>Indicates the last result was zero.</td>
73 </tr>
74 <tr>
75 <td>1</td>
76 <td>Interrupt 1 enable</td>
77 <td>Interrupt 1 can be taken when this bit is set.</td>
78 </tr>
79 <tr>
80 <td>0</td>
81 <td>Interrupt 0 enable</td>
82 <td>Interrupt 0 can be taken when this bit is set.</td>
83 </tr>
84 </table>
85 <h3 id="instructions">Instructions</h3>
86 <ul>
87 <li><a href="#ldim">ldim IM, rD</a></li>
88 <li><a href="#ldimh">ldimh IM, rD</a></li>
89 <li><a href="#ld8">ld8 rA, rB, rD</a></li>
90 <li><a href="#ld16">ld16 rA, rB, rD</a></li>
91 <li><a href="#str8">str8 rA, rB, rD</a></li>
92 <li><a href="#str16">str16 rA, rB, rD</a></li>
93 <li><a href="#add">add rA, rB, rD</a></li>
94 <li><a href="#adc">add rA, rB, rD</a></li>
95 <li><a href="#and">and rA, rB, rD</a></li>
96 <li><a href="#or">or rA, rB, rD</a></li>
97 <li><a href="#xor">xor rA, rB, rD</a></li>
98 </ul>
99 <h4 id="ldim">ldim IM, rD</h4>
100 <p>
101 ldim sign extends an 8-bit immediate value to 16-bits and assigns it to the designated register.
102 </p>
103 <p>
104 <strong>Flags:</strong> No change
105 </p>
106 <h4 id="ldimh">lidmh IM, rD</h4>
107 <p>
108 ldimh assigns an 8-bit immediate value to the upper 8-bits of rD.
109 </p>
110 <p>
111 <strong>Flags:</strong> No change
112 </p>
113 <h4 id="ld8">ld8 rA, rB, rD</h4>
114 <p>
115 Reads a byte from the address indicated by the sum of rA and rB and loads it into rD
116 </p>
117 <p>
118 <strong>Flags:</strong> No change
119 </p>
120 <h4 id="ld16">ld16 rA, rB, rD</h4>
121 <p>
122 Reads a word from the address indicated by the sum of rA and rB and loads it into rD
123 </p>
124 <p>
125 <strong>Flags:</strong> No change
126 </p>
127 <h4 id="str8">str8 rA, rB, rD</h4>
128 <p>
129 Writes the byte stored in rD to the address indicated by the sum of rA and rB.
130 </p>
131 <p>
132 <strong>Flags:</strong> No change
133 </p>
134 <h4 id="str16">str16 rA, rB, rD</h4>
135 <p>
136 Writes the word stored in rD to the address indicated by the sum of rA and rB.
137 </p>
138 <p>
139 <strong>Flags:</strong> No change
140 </p>
141 <h4 id="add">add rA, rB, rD</h4>
142 <p>
143 Adds rA and rB. The result is stored in rD.
144 </p>
145 <p>
146 <strong>Flags:</strong> C = carry out of bit 15, N = result is negative, Z = result is zero
147 </p>
148 <h4 id="adc">adc rA, rB, rD</h4>
149 <p>
150 Adds rA, rB and the carry flag. The result is stored in rD.
151 </p>
152 <p>
153 <strong>Flags:</strong> C = carry out of bit 15, N = result is negative, Z = result is zero
154 </p>
155 <h4 id="and">and rA, rB, rD</h4>
156 <p>
157 Bitwise and of rA and rB is stored in rD.
158 </p>
159 <p>
160 <strong>Flags:</strong> C = unmodified, N = result is negative, Z = result is zero
161 </p>
162 <h4 id="or">or rA, rB, rD</h4>
163 <p>
164 Bitwise or of rA and rB is stored in rD.
165 </p>
166 <p>
167 <strong>Flags:</strong> C = unmodified, N = result is negative, Z = result is zero
168 </p>
169 <h4 id="xor">xor rA, rB, rD</h4>
170 <p>
171 Bitwise exclusive or of rA and rB is stored in rD.
172 </p>
173 <p>
174 <strong>Flags:</strong> C = unmodified, N = result is negative, Z = result is zero
175 </p>
176 <h4 id="lsl">lsl rA, rB, rD</h4>
177 <p>
178 The value in rA is shifted left by rB bits and stored in rD
179 </p>
180 <p>
181 <strong>Flags:</strong> C = last bit shifted out of rA, N = result is negative, Z = result is zero
182 </p>
183 <h4 id="lsr">lsr rA, rB, rD</h4>
184 <p>
185 The value in rA is shifted right by rB bits and stored in rD
186 </p>
187 <p>
188 <strong>Flags:</strong> C = last bit shifted out of rA, N = result is negative, Z = result is zero
189 </p>
190 <h4 id="asr">asr rA, rB, rD</h4>
191 <p>
192 The value in rA is arithmetically shifted right by rB bits and stored in rD. The most significant bit of rA is copied
193 into the newly shifted bits. This allows asr to be used for signed division by powers of 2 as the sign is preserved.
194 </p>
195 <h4 id="bcc">bCC</h4>
196 <p>
197 bCC performs a relative branch if the condition indicated by CC is true. It has a range of 131 instructions forward or
198 124 instructions backwards. CC must be one of the following values
199 <table>
200 <tr>
201 <th>CC</th>
202 <th>Mnemonic</th>
203 <th>Name</th>
204 <th>Description</th>
205 </tr>
206 <tr>
207 <td>0</td>
208 <td>ra</td>
209 <td>bRanch Always</td>
210 <td>Unconditionall branch</td>
211 </tr>
212 <tr>
213 <td>1</td>
214 <td>rf</td>
215 <td>bRanch False</td>
216 <td>Effectively a nop</td>
217 </tr>
218 <tr>
219 <td>2</td>
220 <td>eq</td>
221 <td>EQual</td>
222 <td>Branch if zero flag is 1</td>
223 </tr>
224 <tr>
225 <td>3</td>
226 <td>ne</td>
227 <td>Not Equal</td>
228 <td>Branch if zero flag is 0</td>
229 </tr>
230 <tr>
231 <td>4</td>
232 <td>mi</td>
233 <td>MInus</td>
234 <td>Branch if negative flag is 1</td>
235 </tr>
236 <tr>
237 <td>5</td>
238 <td>pl</td>
239 <td>PLus</td>
240 <td>Branch if negative flag is 0</td>
241 </tr>
242 <tr>
243 <td>6</td>
244 <td>cs</td>
245 <td>Carry Set</td>
246 <td>Branch if carry flag is 1. Unsigned "less than" when used with cmp</td>
247 </tr>
248 <tr>
249 <td>7</td>
250 <td>cc</td>
251 <td>Carry Clear</td>
252 <td>Branch if carry flag is 1. Unsigned "greater or equal" when used with cmp</td>
253 </tr>
254 <tr>
255 <td>8</td>
256 <td>gr</td>
257 <td>Greater</td>
258 <td>Branch if carry flag is 0 and the zero flag is zero. Unsigned "greater" when used with cmp</td>
259 </tr>
260 <tr>
261 <td>9</td>
262 <td>le</td>
263 <td>Less or Equal</td>
264 <td>Branch if carry flag is 1 or the zero flag is 1. Unsigned "lesser or equal" when used with cmp</td>
265 </tr>
266 </table>
267 Use of CC values greater than 9 will result in an invalid instruction exception.
268 </p>
269 <h4 id="mov">mov rA, rD</h4>
270 <p>
271 Stores the value of rA in rD. This can be used as a return or jump instruction if rD is PC.
272 </p>
273 <h4 id="neg">neg rA, rD</h4>
274 <p>
275 Calculates the 2s complement of rA and stores it in rD. This can be used in combination with add to implement subtraction.
276 </p>
277 <h4 id="not">not rA, rD</h4>
278 <p>
279 Calculates the 1s complement of rA and stores it in rD.
280 </p>
281 <h4 id="cmp">cmp rA, rD</h4>
282 <p>
283 Subtracts rA from rD and discards the result, but still updates flags.
284 </p>
285 <h4 id="call">call rA, rD</h4>
286 <p>
287 Stores the address of the next instruction in rD and sets PC to the value in rA. Used for calling subroutines.
288 </p>
289 <h4 id="swap">swap rA, rD</h4>
290 <p>
291 Swaps the values in rA and rD.
292 </p>
293 <h4 id="in">in rA, rD</h4>
294 <p>
295 Reads a word from the IO port indicated by rA and stores it in rD.
296 </p>
297 <h4 id="out">out rA, rD</h4>
298 <p>
299 Writes the word stored in rD to the IO port indicated by rA.
300 </p>
301 <h4 id="ini">ini IM, rD</h4>
302 <p>
303 Reads a word from the IO port indicated by IM and stores it in rD. IM can range from 0 to 15.
304 </p>
305 <h4 id="outi">outi</h4>
306 <p>
307 Writes the word stored in rD to the IO port indicated by IM. IM can range from 0 to 15.
308 </p>
309 <h4 id="addi">addi IM, rD</h4>
310 <p>
311 Adds IM to the value in rD and stores the result in rD. IM range from -8 to -1 or 1 to 8. A value of 0 is used to indicate 8.
312 </p>
313 <h4 id="andi">andi IM, rD</h4>
314 <p>
315 Performs a logical and of IM and the value in rD and stores the result in rD. IM can range from -8 to -1 or 1 to 8. A value of 0 is used to indicate 8.
316 </p>
317 <h4 id="ori">ori IM, rD</h4>
318 <p>
319 Performs a logical or of IM and the value in rD and stores the result in rD. IM can range from-8 to -1 or 1 to 8. A value of 0 is used to indicate 8.
320 </p>
321 <h4 id="lsli">lsli IM, rD</h4>
322 <p>
323 Shifts the value in rD IM bits to the left. IM can range from 1 to 8.
324 </p>
325 <h4 id="lsri">lsri IM, rD</h4>
326 <p>
327 Shifts the value in rD IM bits to the right. IM can range from 1 to 8.
328 </p>
329 <h4 id="cmpi">cmpi IM, rd</h4>
330 <p>
331 Subtracts IM from rD and discards the result, but updates flags. IM can range from -8 to 7.
332 </p>
333 <h4 id="reti">reti rD</h4>
334 <p>
335 Sets rD to the value storeed in EUR, SR to the value stored in ESR and PC to the value stored in EPC. This instruction is used for returning from an
336 exception or interrupt.
337 </p>
338 <h4 id="trap">trap rD</h4>
339 <p>
340 Causes an exception to be taken to the vector indicated by rD.
341 </p>
342 <h4 id="trapi">trapi IM</h4>
343 <p>
344 Causes an exception to be taken to the vecotr indicated by IM
345 </p>
346 <h4 id="getepc">getepc rD</h4>
347 <p>
348 Stores the value of EPC in rD.
349 </p>
350 <h4 id="setepc">setepc</h4>
351 <p>
352 Stores the vaule of rD in EPC.
353 </p>
354 <h4 id="getesr">getesr</h4>
355 <p>
356 </p>
357 <h4 id="setesr">setesr</h4>
358 <p>
359 </p>
360 <h4 id="geteur">geteur</h4>
361 <p>
362 </p>
363 <h4 id="seteur">seteur</h4>
364 <p>
365 </p>
366 <h4 id="getenum">getenum</h4>
367 <p>
368 </p>
369 <h4 id="setenum">setenum</h4>
370 <p>
371 </p>
372 <h4 id="getvbr">getvbr</h4>
373 <p>
374 </p>
375 <h4 id="setvbr">setvbr</h4>
376 <p>
377 </p>
378 <h2 id="video">Video</h2>
379 <h2 id="audio">Audio</h2>
380 <h2 id="timer">Timer</h2>
381 <h2 id="controllers">Controllers</h2>
382 <h2 id="serial">Serial Port</h2>
383 <h2 id="cart">Cartridge</h2>
384 </body>
385 </html>