]>
Commit | Line | Data |
---|---|---|
1 | ; 8080 Interpreter. | |
2 | ; This is part of the Z80-CP/M emulator written by Sprite_tm. | |
3 | ; | |
4 | ||
5 | ; Copyright (C) 2010 Sprite_tm | |
6 | ; Copyright (C) 2010 Leo C. | |
7 | ; Copyright (C) 2010 Horst S. | |
8 | ||
9 | ; This file is part of avrcpm. | |
10 | ; | |
11 | ; avrcpm is free software: you can redistribute it and/or modify it | |
12 | ; under the terms of the GNU General Public License as published by | |
13 | ; the Free Software Foundation, either version 3 of the License, or | |
14 | ; (at your option) any later version. | |
15 | ; | |
16 | ; avrcpm is distributed in the hope that it will be useful, | |
17 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | ; GNU General Public License for more details. | |
20 | ; | |
21 | ; You should have received a copy of the GNU General Public License | |
22 | ; along with avrcpm. If not, see <http://www.gnu.org/licenses/>. | |
23 | ; | |
24 | ; $Id$ | |
25 | ; | |
26 | ||
27 | .dseg | |
28 | ||
29 | z_b: .byte 1 | |
30 | z_c: .byte 1 | |
31 | z_d: .byte 1 | |
32 | z_e: .byte 1 | |
33 | z_h: .byte 1 | |
34 | z_l: .byte 1 | |
35 | ||
36 | ||
37 | .cseg | |
38 | ||
39 | ;Init z80 | |
40 | z80_init: | |
41 | ldi z_pcl,low (IPLADDR) | |
42 | ldi z_pch,high(IPLADDR) | |
43 | ||
44 | cbi flags,trace | |
45 | printnewline | |
46 | printstring "Ok, CPU is live!" | |
47 | printnewline | |
48 | ||
49 | ||
50 | main: | |
51 | .if INS_DEBUG | |
52 | cbi flags,trace | |
53 | cpi z_pch,DBG_TRACE_BOTTOM | |
54 | brlo notraceon | |
55 | cpi z_pch,DBG_TRACE_TOP | |
56 | brsh notraceon | |
57 | sbi flags,trace | |
58 | notraceon: | |
59 | .endif | |
60 | ||
61 | ||
62 | .if PRINT_PC | |
63 | cpi z_pch,DBG_TRACE_BOTTOM | |
64 | brlo noprintpc | |
65 | cpi z_pch,DBG_TRACE_TOP | |
66 | brsh noprintpc | |
67 | ||
68 | printnewline | |
69 | printstring "PC=" | |
70 | movw temp,z_pcl | |
71 | rcall printhexw | |
72 | printstring " " | |
73 | noprintpc: | |
74 | .endif | |
75 | ||
76 | .if INS_DEBUG | |
77 | sbic flags,trace | |
78 | rcall printregs | |
79 | .endif | |
80 | ||
81 | ;hier kommt die Interruptbehandlung rein | |
82 | ||
83 | mem_read_s z_pc ;temp=memReadByte(z_pc) | |
84 | adiw z_pcl,1 ;++z_pc | |
85 | ldi zl,low(todo_table*2) ;zhl=todo_table | |
86 | ldi zh,high(todo_table*2) ; | |
87 | ldi temp2,3 ;1 | |
88 | mul temp,temp2 ;2 | |
89 | add zl,r0 ;1 | |
90 | adc zh,r1 ;1 | |
91 | lpm insdecl,Z+ ;do_store | |
92 | lpm insdech,Z+ ;do_op | |
93 | lpm zl,Z ;do_fetch | |
94 | ldi zh,high(fetch_ops) | |
95 | ijmp ;direkt | |
96 | ||
97 | ||
98 | ; .listmac | |
99 | ;----------------------------------------------------- | |
100 | ; Generate jump to target and position in table | |
101 | ; gen_opjmp target | |
102 | ; | |
103 | .macro gen_opjmp | |
104 | .ifndef opjmp_table_pos_ | |
105 | .set opjmp_table_page_ = high(PC) | |
106 | .set opjmp_table_pos_ = PC | |
107 | .endif | |
108 | .equ @0 = low(opjmp_table_pos_) | |
109 | .set opjmp_table_pos_ = opjmp_table_pos_ + 1 | |
110 | .if high(opjmp_table_pos_) != opjmp_table_page_ | |
111 | .warning "Table 'opjump' crosses page boarder." | |
112 | .message "Program will not work, unless the opjump table is relocated." | |
113 | .endif | |
114 | rjmp do_@0 | |
115 | .endm | |
116 | ||
117 | ;-------------------------------------------------- | |
118 | ; Generate a table entry for one instruction | |
119 | ; | |
120 | ; instr fetch, op, store | |
121 | ; | |
122 | .macro instr | |
123 | .ifndef inst_table_odd_ | |
124 | .set inst_table_odd_ = 0 | |
125 | .endif | |
126 | ||
127 | .if inst_table_odd_ | |
128 | .db inst_table_next_, low(@2), @1, low(@0) | |
129 | .set inst_table_odd_ = 0 | |
130 | .else | |
131 | .set inst_table_next_ = low(@0) | |
132 | .db low(@2), @1 | |
133 | .set inst_table_odd_ = 1 | |
134 | .endif | |
135 | .endm | |
136 | ||
137 | ;----------------------------------- | |
138 | ; go to op. | |
139 | ; | |
140 | .macro fetch_end | |
141 | ldi zh,high(opjumps) | |
142 | mov zl,insdech | |
143 | ijmp | |
144 | .endm | |
145 | ||
146 | ;----------------------------------- | |
147 | ; go to store. | |
148 | ; | |
149 | .macro op_end | |
150 | ldi zh,high(store_ops) ; | |
151 | mov zl,insdecl | |
152 | ijmp | |
153 | .endm | |
154 | ||
155 | ;----------------------------------- | |
156 | ; go back to main | |
157 | ; | |
158 | .macro store_end | |
159 | rjmp main | |
160 | .endm | |
161 | ||
162 | ;----------------------------------- | |
163 | ; go back to main directly | |
164 | ; | |
165 | .macro op_end_nojmp | |
166 | rjmp main | |
167 | .endm | |
168 | ||
169 | ||
170 | ; ------------ Fetch phase stuff ----------------- | |
171 | ||
172 | .org (PC+255) & 0xff00 | |
173 | fetch_ops: | |
174 | do_fetch_nop: | |
175 | fetch_end | |
176 | ||
177 | do_fetch_a: | |
178 | mov opl,z_a | |
179 | fetch_end | |
180 | ||
181 | do_fetch_b: | |
182 | lds opl,z_b | |
183 | fetch_end | |
184 | ||
185 | do_fetch_c: | |
186 | lds opl,z_c | |
187 | fetch_end | |
188 | ||
189 | do_fetch_d: | |
190 | lds opl,z_d | |
191 | fetch_end | |
192 | ||
193 | do_fetch_e: | |
194 | lds opl,z_e | |
195 | fetch_end | |
196 | ||
197 | do_fetch_h: | |
198 | lds opl,z_h | |
199 | fetch_end | |
200 | ||
201 | do_fetch_l: | |
202 | lds opl,z_l | |
203 | fetch_end | |
204 | ||
205 | do_fetch_af: | |
206 | mov opl,z_flags | |
207 | mov oph,z_a | |
208 | fetch_end | |
209 | ||
210 | do_fetch_bc: | |
211 | lds opl,z_c | |
212 | lds oph,z_b | |
213 | fetch_end | |
214 | ||
215 | do_fetch_de: | |
216 | lds opl,z_e | |
217 | lds oph,z_d | |
218 | fetch_end | |
219 | ||
220 | do_fetch_hl: | |
221 | lds opl,z_l | |
222 | lds oph,z_h | |
223 | fetch_end | |
224 | ||
225 | do_fetch_sp: | |
226 | movw opl,z_spl | |
227 | fetch_end | |
228 | ||
229 | do_fetch_mbc: | |
230 | lds xh,z_b | |
231 | lds xl,z_c | |
232 | mem_read_d opl | |
233 | fetch_end | |
234 | ||
235 | do_fetch_mde: | |
236 | lds xh,z_d | |
237 | lds xl,z_e | |
238 | mem_read_d opl | |
239 | fetch_end | |
240 | ||
241 | do_fetch_mhl: | |
242 | lds xh,z_h | |
243 | lds xl,z_l | |
244 | mem_read_d opl | |
245 | fetch_end | |
246 | ||
247 | do_fetch_msp: | |
248 | movw x,z_spl | |
249 | mem_read_d opl | |
250 | adiw x,1 | |
251 | mem_read_d oph | |
252 | fetch_end | |
253 | ||
254 | do_fetch_dir8: | |
255 | mem_read_ds opl, z_pc | |
256 | adiw z_pcl,1 | |
257 | fetch_end | |
258 | ||
259 | do_fetch_dir16: | |
260 | mem_read_ds opl, z_pc | |
261 | adiw z_pcl,1 | |
262 | mem_read_ds oph, z_pc | |
263 | adiw z_pcl,1 | |
264 | fetch_end | |
265 | ||
266 | do_fetch_rst: | |
267 | movw x,z_pcl | |
268 | sbiw x,1 | |
269 | mem_read_d opl | |
270 | andi opl,0x38 | |
271 | ldi oph,0 | |
272 | fetch_end | |
273 | ||
274 | ; ------------ Store phase stuff ----------------- | |
275 | ||
276 | .org (PC+255) & 0xff00 | |
277 | store_ops: | |
278 | do_store_nop: | |
279 | store_end | |
280 | ||
281 | do_store_a: | |
282 | mov z_a,opl | |
283 | store_end | |
284 | ||
285 | do_store_b: | |
286 | sts z_b,opl | |
287 | store_end | |
288 | ||
289 | do_store_c: | |
290 | sts z_c,opl | |
291 | store_end | |
292 | ||
293 | do_store_d: | |
294 | sts z_d,opl | |
295 | store_end | |
296 | ||
297 | do_store_e: | |
298 | sts z_e,opl | |
299 | store_end | |
300 | ||
301 | do_store_h: | |
302 | sts z_h,opl | |
303 | store_end | |
304 | ||
305 | do_store_l: | |
306 | sts z_l,opl | |
307 | store_end | |
308 | ||
309 | do_store_af: | |
310 | mov z_a,oph | |
311 | mov z_flags,opl | |
312 | store_end | |
313 | ||
314 | do_store_bc: | |
315 | sts z_b,oph | |
316 | sts z_c,opl | |
317 | store_end | |
318 | ||
319 | do_store_de: | |
320 | sts z_d,oph | |
321 | sts z_e,opl | |
322 | store_end | |
323 | ||
324 | do_store_hl: | |
325 | sts z_h,oph | |
326 | sts z_l,opl | |
327 | store_end | |
328 | ||
329 | do_store_mbc: | |
330 | lds xh,z_b | |
331 | lds xl,z_c | |
332 | mem_write_s opl | |
333 | store_end | |
334 | ||
335 | do_store_mde: | |
336 | lds xh,z_d | |
337 | lds xl,z_e | |
338 | mem_write_s opl | |
339 | store_end | |
340 | ||
341 | do_store_mhl: | |
342 | lds xh,z_h | |
343 | lds xl,z_l | |
344 | mem_write_s opl | |
345 | store_end | |
346 | ||
347 | do_store_msp: | |
348 | movw xl,z_spl | |
349 | mem_write_s opl | |
350 | adiw xl,1 | |
351 | mem_write_s oph | |
352 | store_end | |
353 | ||
354 | do_store_sp: | |
355 | movw z_spl,opl | |
356 | store_end | |
357 | ||
358 | do_store_pc: | |
359 | movw z_pcl,opl | |
360 | store_end | |
361 | ||
362 | do_store_ret: | |
363 | movw x,z_spl | |
364 | mem_read_d z_pcl | |
365 | adiw x,1 | |
366 | mem_read_d z_pch | |
367 | adiw x,1 | |
368 | movw z_spl,x | |
369 | ||
370 | .if STACK_DBG | |
371 | printnewline | |
372 | printstring "Stack pop " | |
373 | movw temp,z_pcl | |
374 | rcall printhexw | |
375 | printstring ", SP is now " | |
376 | movw temp,z_spl | |
377 | rcall printhexw | |
378 | printstring ". " | |
379 | .endif | |
380 | store_end | |
381 | ||
382 | do_store_call: | |
383 | movw xl,z_spl | |
384 | sbiw x,1 | |
385 | mem_write_s z_pch | |
386 | sbiw x,1 | |
387 | mem_write_s z_pcl | |
388 | movw z_spl,xl | |
389 | ||
390 | .if STACK_DBG | |
391 | printnewline | |
392 | printstring "Stack push " | |
393 | movw temp,z_pcl | |
394 | rcall printhexw | |
395 | printstring ", SP is now " | |
396 | movw temp,z_spl | |
397 | rcall printhexw | |
398 | printstring ". " | |
399 | .endif | |
400 | movw z_pcl,opl | |
401 | store_end | |
402 | ||
403 | ||
404 | do_store_am: | |
405 | mem_write_ds op, z_a | |
406 | store_end | |
407 | ||
408 | ||
409 | ||
410 | ; ------------ Operation phase stuff ----------------- | |
411 | ||
412 | ;.org (PC+255) & 0xff00 | |
413 | ||
414 | opjumps: | |
415 | gen_opjmp op_nop | |
416 | gen_opjmp op_inc | |
417 | gen_opjmp op_dec | |
418 | gen_opjmp op_inc16 | |
419 | gen_opjmp op_dec16 | |
420 | gen_opjmp op_rlc | |
421 | gen_opjmp op_rrc | |
422 | gen_opjmp op_rr | |
423 | gen_opjmp op_rl | |
424 | gen_opjmp op_adda | |
425 | gen_opjmp op_adca | |
426 | gen_opjmp op_subfa | |
427 | gen_opjmp op_sbcfa | |
428 | gen_opjmp op_anda | |
429 | gen_opjmp op_ora | |
430 | gen_opjmp op_xora | |
431 | gen_opjmp op_addhl | |
432 | gen_opjmp op_sthl | |
433 | gen_opjmp op_rmem16 | |
434 | gen_opjmp op_rmem8 | |
435 | gen_opjmp op_da | |
436 | gen_opjmp op_scf | |
437 | gen_opjmp op_cpl | |
438 | gen_opjmp op_ccf | |
439 | gen_opjmp op_pop16 | |
440 | gen_opjmp op_push16 | |
441 | gen_opjmp op_ifnz | |
442 | gen_opjmp op_ifz | |
443 | gen_opjmp op_ifnc | |
444 | gen_opjmp op_ifc | |
445 | gen_opjmp op_ifpo | |
446 | gen_opjmp op_ifpe | |
447 | gen_opjmp op_ifp | |
448 | gen_opjmp op_ifm | |
449 | gen_opjmp op_outa | |
450 | gen_opjmp op_in | |
451 | gen_opjmp op_exhl | |
452 | gen_opjmp op_di | |
453 | gen_opjmp op_ei | |
454 | gen_opjmp op_inv | |
455 | gen_opjmp op_cpfa | |
456 | gen_opjmp op_inca | |
457 | gen_opjmp op_deca | |
458 | ||
459 | ||
460 | ||
461 | ;---------------------------------------------------------------- | |
462 | ;| | | |
463 | ;| Zilog | | |
464 | ;| | | |
465 | ;| ZZZZZZZ 88888 000 | | |
466 | ;| Z 8 8 0 0 | | |
467 | ;| Z 8 8 0 0 0 | | |
468 | ;| Z 88888 0 0 0 | | |
469 | ;| Z 8 8 0 0 0 | | |
470 | ;| Z 8 8 0 0 | | |
471 | ;| ZZZZZZZ 88888 000 | | |
472 | ;| | | |
473 | ;| Z80 MICROPROCESSOR Instruction Set Summary | | |
474 | ;| | | |
475 | ;---------------------------------------------------------------- | |
476 | ;---------------------------------------------------------------- | |
477 | ;|Mnemonic |SZHPNC|Description |Notes | | |
478 | ;|----------+------+---------------------+----------------------| | |
479 | ;|ADC A,s |***V0*|Add with Carry |A=A+s+CY | | |
480 | ;|ADC HL,ss |**?V0*|Add with Carry |HL=HL+ss+CY | | |
481 | ;|ADD A,s |***V0*|Add |A=A+s | | |
482 | ;|ADD HL,ss |--?-0*|Add |HL=HL+ss | | |
483 | ;|ADD IX,pp |--?-0*|Add |IX=IX+pp | | |
484 | ;|ADD IY,rr |--?-0*|Add |IY=IY+rr | | |
485 | ;|AND s |**1P00|Logical AND |A=A&s | | |
486 | ;|BIT b,m |?*1?0-|Test Bit |m&{2^b} | | |
487 | ;|CALL cc,nn|------|Conditional Call |If cc CALL | | |
488 | ;|CALL nn |------|Unconditional Call |-[SP]=PC,PC=nn | | |
489 | ;|CCF |--?-0*|Complement Carry Flag|CY=~CY | | |
490 | ;|CP s |***V1*|Compare |A-s | | |
491 | ;|CPD |****1-|Compare and Decrement|A-[HL],HL=HL-1,BC=BC-1| | |
492 | ;|CPDR |****1-|Compare, Dec., Repeat|CPD till A=[HL]or BC=0| | |
493 | ;|CPI |****1-|Compare and Increment|A-[HL],HL=HL+1,BC=BC-1| | |
494 | ;|CPIR |****1-|Compare, Inc., Repeat|CPI till A=[HL]or BC=0| | |
495 | ;|CPL |--1-1-|Complement |A=~A | | |
496 | ;|DAA |***P-*|Decimal Adjust Acc. |A=BCD format | | |
497 | ;|DEC s |***V1-|Decrement |s=s-1 | | |
498 | ;|DEC xx |------|Decrement |xx=xx-1 | | |
499 | ;|DEC ss |------|Decrement |ss=ss-1 | | |
500 | ;|DI |------|Disable Interrupts | | | |
501 | ;|DJNZ e |------|Dec., Jump Non-Zero |B=B-1 till B=0 | | |
502 | ;|EI |------|Enable Interrupts | | | |
503 | ;|EX [SP],HL|------|Exchange |[SP]<->HL | | |
504 | ;|EX [SP],xx|------|Exchange |[SP]<->xx | | |
505 | ;|EX AF,AF' |------|Exchange |AF<->AF' | | |
506 | ;|EX DE,HL |------|Exchange |DE<->HL | | |
507 | ;|EXX |------|Exchange |qq<->qq' (except AF)| | |
508 | ;|HALT |------|Halt | | | |
509 | ;|IM n |------|Interrupt Mode | (n=0,1,2)| | |
510 | ;|IN A,[n] |------|Input |A=[n] | | |
511 | ;|IN r,[C] |***P0-|Input |r=[C] | | |
512 | ;|INC r |***V0-|Increment |r=r+1 | | |
513 | ;|INC [HL] |***V0-|Increment |[HL]=[HL]+1 | | |
514 | ;|INC xx |------|Increment |xx=xx+1 | | |
515 | ;|INC [xx+d]|***V0-|Increment |[xx+d]=[xx+d]+1 | | |
516 | ;|INC ss |------|Increment |ss=ss+1 | | |
517 | ;|IND |?*??1-|Input and Decrement |[HL]=[C],HL=HL-1,B=B-1| | |
518 | ;|INDR |?1??1-|Input, Dec., Repeat |IND till B=0 | | |
519 | ;|INI |?*??1-|Input and Increment |[HL]=[C],HL=HL+1,B=B-1| | |
520 | ;|INIR |?1??1-|Input, Inc., Repeat |INI till B=0 | | |
521 | ;|JP [HL] |------|Unconditional Jump |PC=[HL] | | |
522 | ;|JP [xx] |------|Unconditional Jump |PC=[xx] | | |
523 | ;|JP nn |------|Unconditional Jump |PC=nn | | |
524 | ;|JP cc,nn |------|Conditional Jump |If cc JP | | |
525 | ;|JR e |------|Unconditional Jump |PC=PC+e | | |
526 | ;|JR cc,e |------|Conditional Jump |If cc JR(cc=C,NC,NZ,Z)| | |
527 | ;|LD dst,src|------|Load |dst=src | | |
528 | ;|LD A,i |**0*0-|Load |A=i (i=I,R)| | |
529 | ;|LDD |--0*0-|Load and Decrement |[DE]=[HL],HL=HL-1,# | | |
530 | ;|LDDR |--000-|Load, Dec., Repeat |LDD till BC=0 | | |
531 | ;|LDI |--0*0-|Load and Increment |[DE]=[HL],HL=HL+1,# | | |
532 | ;|LDIR |--000-|Load, Inc., Repeat |LDI till BC=0 | | |
533 | ;|NEG |***V1*|Negate |A=-A | | |
534 | ;|NOP |------|No Operation | | | |
535 | ;|OR s |**0P00|Logical inclusive OR |A=Avs | | |
536 | ;|OTDR |?1??1-|Output, Dec., Repeat |OUTD till B=0 | | |
537 | ;|OTIR |?1??1-|Output, Inc., Repeat |OUTI till B=0 | | |
538 | ;|OUT [C],r |------|Output |[C]=r | | |
539 | ;|OUT [n],A |------|Output |[n]=A | | |
540 | ;|OUTD |?*??1-|Output and Decrement |[C]=[HL],HL=HL-1,B=B-1| | |
541 | ;|OUTI |?*??1-|Output and Increment |[C]=[HL],HL=HL+1,B=B-1| | |
542 | ;|POP xx |------|Pop |xx=[SP]+ | | |
543 | ;|POP qq |------|Pop |qq=[SP]+ | | |
544 | ;|PUSH xx |------|Push |-[SP]=xx | | |
545 | ;|PUSH qq |------|Push |-[SP]=qq | | |
546 | ;|RES b,m |------|Reset bit |m=m&{~2^b} | | |
547 | ;|RET |------|Return |PC=[SP]+ | | |
548 | ;|RET cc |------|Conditional Return |If cc RET | | |
549 | ;|RETI |------|Return from Interrupt|PC=[SP]+ | | |
550 | ;|RETN |------|Return from NMI |PC=[SP]+ | | |
551 | ;|RL m |**0P0*|Rotate Left |m={CY,m}<- | | |
552 | ;|RLA |--0-0*|Rotate Left Acc. |A={CY,A}<- | | |
553 | ;|RLC m |**0P0*|Rotate Left Circular |m=m<- | | |
554 | ;|RLCA |--0-0*|Rotate Left Circular |A=A<- | | |
555 | ;|RLD |**0P0-|Rotate Left 4 bits |{A,[HL]}={A,[HL]}<- ##| | |
556 | ;|RR m |**0P0*|Rotate Right |m=->{CY,m} | | |
557 | ;|RRA |--0-0*|Rotate Right Acc. |A=->{CY,A} | | |
558 | ;|RRC m |**0P0*|Rotate Right Circular|m=->m | | |
559 | ;|RRCA |--0-0*|Rotate Right Circular|A=->A | | |
560 | ;|RRD |**0P0-|Rotate Right 4 bits |{A,[HL]}=->{A,[HL]} ##| | |
561 | ;|RST p |------|Restart | (p=0H,8H,10H,...,38H)| | |
562 | ;|SBC A,s |***V1*|Subtract with Carry |A=A-s-CY | | |
563 | ;|SBC HL,ss |**?V1*|Subtract with Carry |HL=HL-ss-CY | | |
564 | ;|SCF |--0-01|Set Carry Flag |CY=1 | | |
565 | ;|SET b,m |------|Set bit |m=mv{2^b} | | |
566 | ;|SLA m |**0P0*|Shift Left Arithmetic|m=m*2 | | |
567 | ;|SRA m |**0P0*|Shift Right Arith. |m=m/2 | | |
568 | ;|SRL m |**0P0*|Shift Right Logical |m=->{0,m,CY} | | |
569 | ;|SUB s |***V1*|Subtract |A=A-s | | |
570 | ;|XOR s |**0P00|Logical Exclusive OR |A=Axs | | |
571 | ;|----------+------+--------------------------------------------| | |
572 | ;| F |-*01? |Flag unaffected/affected/reset/set/unknown | | |
573 | ;| S |S |Sign flag (Bit 7) | | |
574 | ;| Z | Z |Zero flag (Bit 6) | | |
575 | ;| HC | H |Half Carry flag (Bit 4) | | |
576 | ;| P/V | P |Parity/Overflow flag (Bit 2, V=overflow) | | |
577 | ;| N | N |Add/Subtract flag (Bit 1) | | |
578 | ;| CY | C|Carry flag (Bit 0) | | |
579 | ;|-----------------+--------------------------------------------| | |
580 | ;| n |Immediate addressing | | |
581 | ;| nn |Immediate extended addressing | | |
582 | ;| e |Relative addressing (PC=PC+2+offset) | | |
583 | ;| [nn] |Extended addressing | | |
584 | ;| [xx+d] |Indexed addressing | | |
585 | ;| r |Register addressing | | |
586 | ;| [rr] |Register indirect addressing | | |
587 | ;| |Implied addressing | | |
588 | ;| b |Bit addressing | | |
589 | ;| p |Modified page zero addressing (see RST) | | |
590 | ;|-----------------+--------------------------------------------| | |
591 | ;|DEFB n(,...) |Define Byte(s) | | |
592 | ;|DEFB 'str'(,...) |Define Byte ASCII string(s) | | |
593 | ;|DEFS nn |Define Storage Block | | |
594 | ;|DEFW nn(,...) |Define Word(s) | | |
595 | ;|-----------------+--------------------------------------------| | |
596 | ;| A B C D E |Registers (8-bit) | | |
597 | ;| AF BC DE HL |Register pairs (16-bit) | | |
598 | ;| F |Flag register (8-bit) | | |
599 | ;| I |Interrupt page address register (8-bit) | | |
600 | ;| IX IY |Index registers (16-bit) | | |
601 | ;| PC |Program Counter register (16-bit) | | |
602 | ;| R |Memory Refresh register | | |
603 | ;| SP |Stack Pointer register (16-bit) | | |
604 | ;|-----------------+--------------------------------------------| | |
605 | ;| b |One bit (0 to 7) | | |
606 | ;| cc |Condition (C,M,NC,NZ,P,PE,PO,Z) | | |
607 | ;| d |One-byte expression (-128 to +127) | | |
608 | ;| dst |Destination s, ss, [BC], [DE], [HL], [nn] | | |
609 | ;| e |One-byte expression (-126 to +129) | | |
610 | ;| m |Any register r, [HL] or [xx+d] | | |
611 | ;| n |One-byte expression (0 to 255) | | |
612 | ;| nn |Two-byte expression (0 to 65535) | | |
613 | ;| pp |Register pair BC, DE, IX or SP | | |
614 | ;| qq |Register pair AF, BC, DE or HL | | |
615 | ;| qq' |Alternative register pair AF, BC, DE or HL | | |
616 | ;| r |Register A, B, C, D, E, H or L | | |
617 | ;| rr |Register pair BC, DE, IY or SP | | |
618 | ;| s |Any register r, value n, [HL] or [xx+d] | | |
619 | ;| src |Source s, ss, [BC], [DE], [HL], nn, [nn] | | |
620 | ;| ss |Register pair BC, DE, HL or SP | | |
621 | ;| xx |Index register IX or IY | | |
622 | ;|-----------------+--------------------------------------------| | |
623 | ;| + - * / ^ |Add/subtract/multiply/divide/exponent | | |
624 | ;| & ~ v x |Logical AND/NOT/inclusive OR/exclusive OR | | |
625 | ;| <- -> |Rotate left/right | | |
626 | ;| [ ] |Indirect addressing | | |
627 | ;| [ ]+ -[ ] |Indirect addressing auto-increment/decrement| | |
628 | ;| { } |Combination of operands | | |
629 | ;| # |Also BC=BC-1,DE=DE-1 | | |
630 | ;| ## |Only lower 4 bits of accumulator A used | | |
631 | ;---------------------------------------------------------------- | |
632 | ||
633 | ;How the flags are supposed to work: | |
634 | ;7 ZFL_S - Sign flag (=MSBit of result) | |
635 | ;6 ZFL_Z - Zero flag. Is 1 when the result is 0 | |
636 | ;4 ZFL_H - Half-carry (carry from bit 3 to 4) | |
637 | ;2 ZFL_P - Parity/2-complement Overflow | |
638 | ;1 ZFL_N - Subtract - set if last op was a subtract | |
639 | ;0 ZFL_C - Carry | |
640 | ; | |
641 | ;I sure hope I got the mapping between flags and instructions correct... | |
642 | ||
643 | .equ ZFL_S = 7 | |
644 | .equ ZFL_Z = 6 | |
645 | .equ ZFL_H = 4 | |
646 | .equ ZFL_P = 2 | |
647 | .equ ZFL_N = 1 | |
648 | .equ ZFL_C = 0 | |
649 | ||
650 | ||
651 | .equ AVR_T = SREG_T | |
652 | .equ AVR_H = SREG_H | |
653 | .equ AVR_S = SREG_S | |
654 | .equ AVR_V = SREG_V | |
655 | .equ AVR_N = SREG_N | |
656 | .equ AVR_Z = SREG_Z | |
657 | .equ AVR_C = SREG_C | |
658 | ||
659 | ;------------------------------------------------; | |
660 | ; Load table value from flash indexed by source reg. | |
661 | ; | |
662 | ; ldpmx dstreg,tablebase,indexreg | |
663 | ; | |
664 | ; (6 words, 8 cycles) | |
665 | ||
666 | .macro ldpmx | |
667 | ldi zh,high(@1*2) ; table must be page aligned | |
668 | mov zl,@2 | |
669 | lpm @0,z | |
670 | .endm | |
671 | ||
672 | .macro do_z80_flags_HP | |
673 | #if EM_Z80 | |
674 | bmov z_flags, ZFL_P, temp, AVR_V | |
675 | bmov z_flags, ZFL_H, temp, AVR_H | |
676 | #endif | |
677 | .endm | |
678 | ||
679 | .macro do_z80_flags_set_N | |
680 | #if EM_Z80 | |
681 | ori z_flags, (1<<ZFL_N) ; Negation auf 1 | |
682 | #endif | |
683 | .endm | |
684 | ||
685 | .macro do_z80_flags_set_HN | |
686 | #if EM_Z80 | |
687 | ori z_flags,(1<<ZFL_N)|(1<<ZFL_H) | |
688 | #endif | |
689 | .endm | |
690 | ||
691 | .macro do_z80_flags_clear_N | |
692 | #if EM_Z80 | |
693 | andi z_flags,~(1<<ZFL_N) | |
694 | #endif | |
695 | .endm | |
696 | ||
697 | .macro do_z80_flags_op_rotate | |
698 | ; must not change avr carry flag! | |
699 | #if EM_Z80 | |
700 | andi z_flags, ~( (1<<ZFL_H) | (1<<ZFL_N) | (1<<ZFL_C) ) | |
701 | #else | |
702 | andi z_flags, ~( (1<<ZFL_C) ) | |
703 | #endif | |
704 | .endm | |
705 | ||
706 | .macro do_z80_flags_op_and | |
707 | #if EM_Z80 | |
708 | ori z_flags,(1<<ZFL_H) | |
709 | #else | |
710 | ori z_flags,(1<<ZFL_H) | |
711 | #endif | |
712 | .endm | |
713 | ||
714 | .macro do_z80_flags_op_or | |
715 | #if EM_Z80 | |
716 | #endif | |
717 | .endm | |
718 | ||
719 | ||
720 | ;---------------------------------------------------------------- | |
721 | ||
722 | do_op_inv: | |
723 | printstring "Invalid opcode @ PC=" | |
724 | movw temp,z_pcl | |
725 | rcall printhexw | |
726 | ||
727 | haltinv: | |
728 | rjmp haltinv | |
729 | ||
730 | do_op_nop: | |
731 | op_end | |
732 | ||
733 | ;---------------------------------------------------------------- | |
734 | ;|Mnemonic |SZHPNC|Description |Notes | | |
735 | ;---------------------------------------------------------------- | |
736 | ;|OUT [n],A |------|Output |[n]=A | | |
737 | ; | |
738 | ; | |
739 | ;Interface with peripherials goes here :) | |
740 | do_op_outa: ; out (opl),a | |
741 | .if PORT_DEBUG | |
742 | printnewline | |
743 | printstring "Port write: " | |
744 | mov temp,z_a | |
745 | rcall printhex | |
746 | printstring " -> (" | |
747 | mov temp,opl | |
748 | rcall printhex | |
749 | printstring ") " | |
750 | .endif | |
751 | mov temp,z_a | |
752 | mov temp2,opl | |
753 | rcall portWrite | |
754 | op_end | |
755 | ||
756 | ;---------------------------------------------------------------- | |
757 | ;|Mnemonic |SZHPNC|Description |Notes | | |
758 | ;---------------------------------------------------------------- | |
759 | ;|IN A,[n] |------|Input |A=[n] | | |
760 | ; | |
761 | ; | |
762 | do_op_in: ; in a,(opl) | |
763 | .if PORT_DEBUG | |
764 | printnewline | |
765 | printstring "Port read: (" | |
766 | mov temp,opl | |
767 | rcall printhex | |
768 | printstring ") -> " | |
769 | .endif | |
770 | ||
771 | mov temp2,opl | |
772 | rcall portRead | |
773 | mov opl,temp | |
774 | ||
775 | .if PORT_DEBUG | |
776 | rcall printhex | |
777 | printstring " " | |
778 | .endif | |
779 | op_end | |
780 | ||
781 | ;---------------------------------------------------------------- | |
782 | ;|Mnemonic |SZHPNC|Description |Notes | | |
783 | ;---------------------------------------------------------------- | |
784 | ;|INC r |***V0-|Increment |r=r+1 | | |
785 | ;|INC [HL] |***V0-|Increment |[HL]=[HL]+1 | | |
786 | ;|INC [xx+d]|***V0-|Increment |[xx+d]=[xx+d]+1 | | |
787 | ;|----------|SZHP C|---------- 8080 ----------------------------| | |
788 | ;|INC r |**-P0-|Increment |r=r+1 | | |
789 | ;|INC [HL] |**-P0-|Increment |[HL]=[HL]+1 | | |
790 | ; | |
791 | ; | |
792 | do_op_inc: | |
793 | inc opl | |
794 | #if EM_Z80 | |
795 | in temp, sreg | |
796 | #endif | |
797 | andi z_flags,(1<<ZFL_H)|(1<<ZFL_C) ; preserve C-, and H-flag | |
798 | ldpmx temp2, sz53p_tab, opl | |
799 | or z_flags,temp2 ; | |
800 | do_z80_flags_HP | |
801 | op_end | |
802 | ||
803 | do_op_inca: | |
804 | inc z_a | |
805 | #if EM_Z80 | |
806 | in temp, sreg | |
807 | #endif | |
808 | andi z_flags,(1<<ZFL_H)|(1<<ZFL_C) ; preserve C-, and H-flag | |
809 | ldpmx temp2, sz53p_tab, z_a | |
810 | or z_flags,temp2 ; | |
811 | do_z80_flags_HP | |
812 | op_end | |
813 | ||
814 | ;---------------------------------------------------------------- | |
815 | ;|Mnemonic |SZHPNC|Description |Notes | | |
816 | ;---------------------------------------------------------------- | |
817 | ;|DEC r |***V1-|Decrement |s=s-1 | | |
818 | ;|INC [HL] |***V0-|Increment |[HL]=[HL]+1 | | |
819 | ;|INC [xx+d]|***V0-|Increment |[xx+d]=[xx+d]+1 | | |
820 | ;|----------|SZHP C|---------- 8080 ----------------------------| | |
821 | ;|DEC r |**-P -|Increment |r=r+1 | | |
822 | ;|DEC [HL] |**-P -|Increment |[HL]=[HL]+1 | | |
823 | ; | |
824 | ; | |
825 | do_op_dec: | |
826 | dec opl | |
827 | #if EM_Z80 | |
828 | in temp, sreg | |
829 | #endif | |
830 | andi z_flags,(1<<ZFL_H)|(1<<ZFL_C) ; preserve C-, and H-flag | |
831 | ldpmx temp2, sz53p_tab, opl | |
832 | or z_flags,temp2 ; | |
833 | do_z80_flags_HP | |
834 | do_z80_flags_set_N | |
835 | op_end | |
836 | ||
837 | do_op_deca: | |
838 | dec z_a | |
839 | #if EM_Z80 | |
840 | in temp, sreg | |
841 | #endif | |
842 | andi z_flags,(1<<ZFL_H)|(1<<ZFL_C) ; preserve C-, and H-flag | |
843 | ldpmx temp2, sz53p_tab, z_a | |
844 | or z_flags,temp2 ; | |
845 | do_z80_flags_HP | |
846 | do_z80_flags_set_N | |
847 | op_end | |
848 | ||
849 | ;---------------------------------------------------------------- | |
850 | ;|Mnemonic |SZHPNC|Description |Notes | | |
851 | ;---------------------------------------------------------------- | |
852 | ;|INC xx |------|Increment |xx=xx+1 | | |
853 | ;|INC ss |------|Increment |ss=ss+1 | | |
854 | ; | |
855 | ; | |
856 | do_op_inc16: | |
857 | subi opl,low(-1) | |
858 | sbci oph,high(-1) | |
859 | op_end | |
860 | ||
861 | ;---------------------------------------------------------------- | |
862 | ;|Mnemonic |SZHPNC|Description |Notes | | |
863 | ;---------------------------------------------------------------- | |
864 | ;|DEC xx |------|Decrement |xx=xx-1 | | |
865 | ;|DEC ss |------|Decrement |ss=ss-1 | | |
866 | ; | |
867 | ; | |
868 | do_op_dec16: | |
869 | subi opl, 1 | |
870 | sbci oph, 0 | |
871 | op_end | |
872 | ||
873 | ;---------------------------------------------------------------- | |
874 | ;|Mnemonic |SZHPNC|Description |Notes | | |
875 | ;---------------------------------------------------------------- | |
876 | ;|RLCA |--0-0*|Rotate Left Circular |A=A<- | | |
877 | ;|----------|SZHP C|---------- 8080 ----------------------------| | |
878 | ;|RLCA |---- *|Rotate Left Circular |A=A<- | | |
879 | ; | |
880 | ; | |
881 | do_op_rlc: | |
882 | ;Rotate Left Cyclical. All bits move 1 to the | |
883 | ;left, the msb becomes c and lsb. | |
884 | do_z80_flags_op_rotate | |
885 | lsl opl | |
886 | brcc do_op_rlc_noc | |
887 | ori opl, 1 | |
888 | ori z_flags, (1<<ZFL_C) | |
889 | do_op_rlc_noc: | |
890 | op_end | |
891 | ||
892 | ;---------------------------------------------------------------- | |
893 | ;|Mnemonic |SZHPNC|Description |Notes | | |
894 | ;---------------------------------------------------------------- | |
895 | ;|RRCA |--0-0*|Rotate Right Circular|A=->A | | |
896 | ;|----------|SZHP C|---------- 8080 ----------------------------| | |
897 | ;|RRCA |---- *|Rotate Right Circular|A=->A | | |
898 | ; | |
899 | ; | |
900 | do_op_rrc: | |
901 | ;Rotate Right Cyclical. All bits move 1 to the | |
902 | ;right, the lsb becomes c and msb. | |
903 | do_z80_flags_op_rotate | |
904 | lsr opl | |
905 | brcc do_op_rrc_noc | |
906 | ori opl, 0x80 | |
907 | ori z_flags, (1<<ZFL_C) | |
908 | do_op_rrc_noc: | |
909 | op_end | |
910 | ||
911 | ;---------------------------------------------------------------- | |
912 | ;|Mnemonic |SZHPNC|Description |Notes | | |
913 | ;---------------------------------------------------------------- | |
914 | ;|RRA |--0-0*|Rotate Right Acc. |A=->{CY,A} | | |
915 | ;|----------|SZHP C|---------- 8080 ----------------------------| | |
916 | ;|RRA |---- *|Rotate Right Acc. |A=->{CY,A} | | |
917 | ; | |
918 | ; | |
919 | do_op_rr: | |
920 | ;Rotate Right. All bits move 1 to the right, the lsb | |
921 | ;becomes c, c becomes msb. | |
922 | clc ; get z80 carry to avr carry | |
923 | sbrc z_flags,ZFL_C | |
924 | sec | |
925 | do_z80_flags_op_rotate ; (clear ZFL_C, doesn't change AVR_C) | |
926 | bmov z_flags,ZFL_C, opl,0 ; Bit 0 --> CY | |
927 | ror opl | |
928 | op_end | |
929 | ||
930 | ;---------------------------------------------------------------- | |
931 | ;|Mnemonic |SZHPNC|Description |Notes | | |
932 | ;---------------------------------------------------------------- | |
933 | ;|RLA |--0-0*|Rotate Left Acc. |A={CY,A}<- | | |
934 | ;|----------|SZHP C|---------- 8080 ----------------------------| | |
935 | ;|RLA |---- *|Rotate Left Acc. |A={CY,A}<- | | |
936 | ; | |
937 | ; | |
938 | do_op_rl: | |
939 | ;Rotate Left. All bits move 1 to the left, the msb | |
940 | ;becomes c, c becomes lsb. | |
941 | clc | |
942 | sbrc z_flags,ZFL_C | |
943 | sec | |
944 | do_z80_flags_op_rotate ; (clear ZFL_C, doesn't change AVR_C) | |
945 | bmov z_flags,ZFL_C, opl,7 ; Bit 7 --> CY | |
946 | rol opl | |
947 | op_end | |
948 | ||
949 | ;---------------------------------------------------------------- | |
950 | ;|Mnemonic |SZHPNC|Description |Notes | | |
951 | ;---------------------------------------------------------------- | |
952 | ;|ADD A,s |***V0*|Add |A=A+s | | |
953 | ;|----------|SZHP C|---------- 8080 ----------------------------| | |
954 | ;|ADD A,s |***P *|Add |A=A+s | | |
955 | ; | |
956 | ; | |
957 | do_op_adda: | |
958 | add z_a,opl | |
959 | in temp,sreg | |
960 | ldpmx z_flags,sz53p_tab,z_a ;S,Z,P flag | |
961 | bmov z_flags,ZFL_C, temp,AVR_C | |
962 | do_z80_flags_HP | |
963 | op_end | |
964 | ||
965 | ;---------------------------------------------------------------- | |
966 | ;|Mnemonic |SZHPNC|Description |Notes | | |
967 | ;---------------------------------------------------------------- | |
968 | ;|ADC A,s |***V0*|Add with Carry |A=A+s+CY | | |
969 | ;|----------|SZHP C|---------- 8080 ----------------------------| | |
970 | ;|ADC A,s |***P *|Add with Carry |A=A+s+CY | | |
971 | ; | |
972 | ; | |
973 | do_op_adca: | |
974 | clc | |
975 | sbrc z_flags,ZFL_C | |
976 | sec | |
977 | adc z_a,opl | |
978 | in temp,sreg | |
979 | ldpmx z_flags,sz53p_tab,z_a ;S,Z,P | |
980 | bmov z_flags,ZFL_C, temp,AVR_C | |
981 | do_z80_flags_HP | |
982 | op_end | |
983 | ||
984 | ;---------------------------------------------------------------- | |
985 | ;|Mnemonic |SZHPNC|Description |Notes | | |
986 | ;---------------------------------------------------------------- | |
987 | ;|SUB s |***V1*|Subtract |A=A-s | | |
988 | ;|----------|SZHP C|---------- 8080 ----------------------------| | |
989 | ;|SUB s |***P *|Subtract |A=A-s | | |
990 | ||
991 | ; | |
992 | do_op_subfa: | |
993 | sub z_a,opl | |
994 | in temp,sreg | |
995 | ldpmx z_flags,sz53p_tab,z_a ;S,Z,P | |
996 | bmov z_flags,ZFL_C, temp,AVR_C | |
997 | do_z80_flags_HP | |
998 | do_z80_flags_set_N | |
999 | op_end | |
1000 | ||
1001 | ;---------------------------------------------------------------- | |
1002 | ;|Mnemonic |SZHPNC|Description |Notes | | |
1003 | ;---------------------------------------------------------------- | |
1004 | ;|CP s |***V1*|Compare |A-s | | |
1005 | ;|----------|SZHP C|---------- 8080 ----------------------------| | |
1006 | ;|CP s |***P *|Compare |A-s | | |
1007 | ||
1008 | ; | |
1009 | do_op_cpfa: | |
1010 | mov temp,z_a | |
1011 | sub temp,opl | |
1012 | mov opl,temp | |
1013 | in temp,sreg | |
1014 | ldpmx z_flags,sz53p_tab,opl ;S,Z,P | |
1015 | bmov z_flags,ZFL_C, temp,AVR_C | |
1016 | do_z80_flags_HP | |
1017 | do_z80_flags_set_N | |
1018 | op_end | |
1019 | ||
1020 | ;---------------------------------------------------------------- | |
1021 | ;|Mnemonic |SZHPNC|Description |Notes | | |
1022 | ;---------------------------------------------------------------- | |
1023 | ;|SBC A,s |***V1*|Subtract with Carry |A=A-s-CY | | |
1024 | ;|----------|SZHP C|---------- 8080 ----------------------------| | |
1025 | ;|SBC A,s |***P *|Subtract with Carry |A=A-s-CY | | |
1026 | ; | |
1027 | ; | |
1028 | do_op_sbcfa: | |
1029 | clc | |
1030 | sbrc z_flags,ZFL_C | |
1031 | sec | |
1032 | sbc z_a,opl | |
1033 | in temp,sreg | |
1034 | ldpmx z_flags,sz53p_tab,z_a ;S,Z,P | |
1035 | bmov z_flags,ZFL_C, temp,AVR_C | |
1036 | do_z80_flags_HP | |
1037 | do_z80_flags_set_N | |
1038 | op_end | |
1039 | ||
1040 | ;---------------------------------------------------------------- | |
1041 | ;|Mnemonic |SZHPNC|Description |Notes | | |
1042 | ;---------------------------------------------------------------- | |
1043 | ;|AND s |**1P00|Logical AND |A=A&s | | |
1044 | ;|----------|SZHP C|---------- 8080 ----------------------------| | |
1045 | ;|AND s |**-P 0|Logical AND |A=A&s | | |
1046 | ; | |
1047 | ; TODO H-Flag | |
1048 | do_op_anda: | |
1049 | and z_a,opl ; | |
1050 | ldpmx z_flags,sz53p_tab,z_a ;S,Z,P,N,C | |
1051 | do_z80_flags_op_and | |
1052 | op_end | |
1053 | ||
1054 | ||
1055 | ;---------------------------------------------------------------- | |
1056 | ;|Mnemonic |SZHPNC|Description |Notes | | |
1057 | ;---------------------------------------------------------------- | |
1058 | ;|OR s |**0P00|Logical inclusive OR |A=Avs | | |
1059 | ;|----------|SZHP C|---------- 8080 ----------------------------| | |
1060 | ;|OR s |**-P00|Logical inclusive OR |A=Avs | | |
1061 | ; | |
1062 | ; TODO: H-Flag | |
1063 | do_op_ora: | |
1064 | or z_a,opl | |
1065 | ldpmx z_flags,sz53p_tab,z_a ;S,Z,H,P,N,C | |
1066 | do_z80_flags_op_or | |
1067 | op_end | |
1068 | ||
1069 | ;---------------------------------------------------------------- | |
1070 | ;|Mnemonic |SZHPNC|Description |Notes | | |
1071 | ;---------------------------------------------------------------- | |
1072 | ;|XOR s |**0P00|Logical Exclusive OR |A=Axs | | |
1073 | ;|----------|SZHP C|---------- 8080 ----------------------------| | |
1074 | ;|XOR s |**-P 0|Logical Exclusive OR |A=Axs | | |
1075 | ; | |
1076 | ; TODO: H-Flag | |
1077 | do_op_xora: | |
1078 | eor z_a,opl | |
1079 | ldpmx z_flags,sz53p_tab,z_a ;S,Z,H,P,N,C | |
1080 | do_z80_flags_op_or | |
1081 | op_end | |
1082 | ||
1083 | ;---------------------------------------------------------------- | |
1084 | ;|Mnemonic |SZHPNC|Description |Notes | | |
1085 | ;---------------------------------------------------------------- | |
1086 | ;|ADD HL,ss |--?-0*|Add |HL=HL+ss | | |
1087 | ;|----------|SZHP C|---------- 8080 ----------------------------| | |
1088 | ;|ADD HL,ss |---- *|Add |HL=HL+ss | | |
1089 | ; | |
1090 | ; | |
1091 | do_op_addhl: | |
1092 | lds temp,z_l | |
1093 | lds temp2,z_h | |
1094 | add opl,temp | |
1095 | adc oph,temp2 | |
1096 | in temp,sreg | |
1097 | bmov z_flags,ZFL_H, temp,AVR_H | |
1098 | bmov z_flags,ZFL_C, temp,AVR_C | |
1099 | do_z80_flags_clear_N | |
1100 | op_end | |
1101 | ||
1102 | ;---------------------------------------------------------------- | |
1103 | ;|Mnemonic |SZHPNC|Description |Notes | | |
1104 | ;---------------------------------------------------------------- | |
1105 | ;|LD dst,src|------|Load |dst=src | | |
1106 | ; | |
1107 | ; | |
1108 | do_op_sthl: ;store hl to mem loc in opl:h | |
1109 | movw xl,opl | |
1110 | lds temp,z_l | |
1111 | mem_write | |
1112 | adiw xl,1 | |
1113 | lds temp,z_h | |
1114 | mem_write | |
1115 | op_end | |
1116 | ||
1117 | ;---------------------------------------------------------------- | |
1118 | ;|Mnemonic |SZHPNC|Description |Notes | | |
1119 | ;---------------------------------------------------------------- | |
1120 | ;|LD dst,src|------|Load |dst=src | | |
1121 | ; | |
1122 | ; | |
1123 | do_op_rmem16: | |
1124 | movw xl,opl | |
1125 | mem_read_d opl | |
1126 | adiw x,1 | |
1127 | mem_read_d oph | |
1128 | op_end | |
1129 | ||
1130 | ;---------------------------------------------------------------- | |
1131 | ;|Mnemonic |SZHPNC|Description |Notes | | |
1132 | ;---------------------------------------------------------------- | |
1133 | ;|LD dst,src|------|Load |dst=src | | |
1134 | ; | |
1135 | ; | |
1136 | do_op_rmem8: | |
1137 | mem_read_ds opl, op | |
1138 | op_end | |
1139 | ||
1140 | ;---------------------------------------------------------------- | |
1141 | ;|Mnemonic |SZHPNC|Description |Notes | | |
1142 | ;---------------------------------------------------------------- | |
1143 | ;|DAA |***P-*|Decimal Adjust Acc. | | | |
1144 | ;|----------|SZHP C|---------- 8080 ----------------------------| | |
1145 | ; | |
1146 | ; Not yet checked | |
1147 | ||
1148 | ; Description (http://www.z80.info/z80syntx.htm#DAA): | |
1149 | ; This instruction conditionally adjusts the accumulator for BCD addition | |
1150 | ; and subtraction operations. For addition (ADD, ADC, INC) or subtraction | |
1151 | ; (SUB, SBC, DEC, NEC), the following table indicates the operation performed: | |
1152 | ; | |
1153 | ; ------------------------------------------------------------------------------- | |
1154 | ; | | C Flag | HEX value in | H Flag | HEX value in | Number | C flag| | |
1155 | ; | Operation| Before | upper digit | Before | lower digit | added | After | | |
1156 | ; | | DAA | (bit 7-4) | DAA | (bit 3-0) | to byte | DAA | | |
1157 | ; |-----------------------------------------------------------------------------| | |
1158 | ; | | 0 | 0-9 | 0 | 0-9 | 00 | 0 | | |
1159 | ; | ADD | 0 | 0-8 | 0 | A-F | 06 | 0 | | |
1160 | ; | | 0 | 0-9 | 1 | 0-3 | 06 | 0 | | |
1161 | ; | ADC | 0 | A-F | 0 | 0-9 | 60 | 1 | | |
1162 | ; | | 0 | 9-F | 0 | A-F | 66 | 1 | | |
1163 | ; | INC | 0 | A-F | 1 | 0-3 | 66 | 1 | | |
1164 | ; | | 1 | 0-2 | 0 | 0-9 | 60 | 1 | | |
1165 | ; | | 1 | 0-2 | 0 | A-F | 66 | 1 | | |
1166 | ; | | 1 | 0-3 | 1 | 0-3 | 66 | 1 | | |
1167 | ; |-----------------------------------------------------------------------------| | |
1168 | ; | SUB | 0 | 0-9 | 0 | 0-9 | 00 | 0 | | |
1169 | ; | SBC | 0 | 0-8 | 1 | 6-F | FA | 0 | | |
1170 | ; | DEC | 1 | 7-F | 0 | 0-9 | A0 | 1 | | |
1171 | ; | NEG | 1 | 6-F | 1 | 6-F | 9A | 1 | | |
1172 | ; |-----------------------------------------------------------------------------| | |
1173 | ; | |
1174 | ; Flags: | |
1175 | ; C: See instruction. | |
1176 | ; N: Unaffected. | |
1177 | ; P/V: Set if Acc. is even parity after operation, reset otherwise. | |
1178 | ; H: See instruction. | |
1179 | ; Z: Set if Acc. is Zero after operation, reset otherwise. | |
1180 | ; S: Set if most significant bit of Acc. is 1 after operation, reset otherwise. | |
1181 | ||
1182 | ||
1183 | ||
1184 | #if 1 | |
1185 | do_op_da: | |
1186 | ldi oph,0 ; what to add | |
1187 | sbrc z_flags,ZFL_H ; if H-Flag | |
1188 | rjmp op_da_06 | |
1189 | mov temp,opl | |
1190 | andi temp,0x0f ; ... or lower digit > 9 | |
1191 | cpi temp,0x0a | |
1192 | brlo op_da_06n | |
1193 | op_da_06: | |
1194 | ori oph,0x06 | |
1195 | op_da_06n: | |
1196 | sbrc z_flags,(1<<ZFL_C) | |
1197 | rjmp op_da_60 | |
1198 | cpi opl,0xa0 | |
1199 | brlo op_da_60n | |
1200 | op_da_60: | |
1201 | ori oph,0x60 | |
1202 | op_da_60n: | |
1203 | cpi opl,0x9a | |
1204 | brlo op_da_99n | |
1205 | ori z_flags,(1<<ZFL_C); set C | |
1206 | op_da_99n: | |
1207 | sbrs z_flags,ZFL_N ; if sub-op | |
1208 | rjmp op_da_add ; then | |
1209 | sub opl,oph | |
1210 | rjmp op_da_ex | |
1211 | op_da_add: ; else add-op | |
1212 | cpi opl,0x91 | |
1213 | brlo op_da_60n2 | |
1214 | mov temp,opl | |
1215 | andi temp,0x0f | |
1216 | cpi temp,0x0a | |
1217 | brlo op_da_60n2 | |
1218 | ori oph,0x60 | |
1219 | op_da_60n2: | |
1220 | add opl,oph | |
1221 | op_da_ex: | |
1222 | in temp,SREG | |
1223 | sbrc temp,AVR_H | |
1224 | ori z_flags,(1<<ZFL_C) | |
1225 | andi z_flags,(1<<ZFL_N)|(1<<ZFL_C) ; preserve C,N | |
1226 | ldpmx temp2, sz53p_tab, opl ; get S,Z,P | |
1227 | or z_flags,temp2 | |
1228 | bmov z_flags,ZFL_H, temp,AVR_H ; H (?) | |
1229 | op_end | |
1230 | #else | |
1231 | ||
1232 | do_op_da: | |
1233 | sbrc z_flags,ZFL_N ; if add-op | |
1234 | rjmp do_op_da_sub ; then | |
1235 | ldi temp2,0 ; | |
1236 | mov temp,opl ; | |
1237 | andi temp,0x0f ; | |
1238 | cpi temp,0x0a ; if lower digit > 9 | |
1239 | brlo do_op_da_h ; | |
1240 | ori temp2,0x06 ; add 6 to lower digit | |
1241 | do_op_da_h: ; | |
1242 | sbrc z_flags,ZFL_H ; ... or H-Flag | |
1243 | ori temp2,0x06 ; | |
1244 | add opl,temp2 ; | |
1245 | ||
1246 | ldi temp2,0 ; | |
1247 | mov temp,opl ; | |
1248 | andi temp,0xf0 ; | |
1249 | cpi temp,0xa0 ; | |
1250 | brlo do_op_da_c ; | |
1251 | ori temp2,0x60 ; | |
1252 | do_op_da_c: ; else sub-op | |
1253 | sbrc z_flags,ZFL_C ; | |
1254 | ori temp2,0x60 ; | |
1255 | andi z_flags, ~( (1<<ZFL_S) | (1<<ZFL_Z) | (1<<ZFL_H) ) | |
1256 | add opl,temp2 ; | |
1257 | in temp,SREG ; | |
1258 | bst temp,AVR_Z ;Z-Flag | |
1259 | bld z_flags,ZFL_Z ; | |
1260 | bst temp,AVR_N ;S-Flag | |
1261 | bst z_flags,ZFL_S ; | |
1262 | sbrc temp2,5 ;C-Flag, set if 0x06 added | |
1263 | ori z_flags,(1<<ZFL_C) ; | |
1264 | ;H-Flag? | |
1265 | op_end | |
1266 | ||
1267 | do_op_da_sub: ;TODO: | |
1268 | rcall do_op_inv | |
1269 | op_end | |
1270 | #endif | |
1271 | ||
1272 | ;---------------------------------------------------------------- | |
1273 | ;|Mnemonic |SZHPNC|Description |Notes | | |
1274 | ;---------------------------------------------------------------- | |
1275 | ;|SCF |--0-01|Set Carry Flag |CY=1 | | |
1276 | ;|----------|SZHP C|---------- 8080 ----------------------------| | |
1277 | ; | |
1278 | ; | |
1279 | do_op_scf: | |
1280 | andi z_flags,~((1<<ZFL_H)|(1<<ZFL_N)) | |
1281 | ori z_flags,(1<<ZFL_C) | |
1282 | op_end | |
1283 | ||
1284 | ;---------------------------------------------------------------- | |
1285 | ;|Mnemonic |SZHPNC|Description |Notes | | |
1286 | ;---------------------------------------------------------------- | |
1287 | ;|CCF |--?-0*|Complement Carry Flag|CY=~CY | | |
1288 | ;|----------|SZHP C|---------- 8080 ----------------------------| | |
1289 | ;|SCF |---- 1|Set Carry Flag |CY=1 | | |
1290 | ; | |
1291 | ;TODO: H-Flag | |
1292 | do_op_ccf: | |
1293 | do_z80_flags_clear_N | |
1294 | ldi temp,(1<<ZFL_C) | |
1295 | eor z_flags,temp | |
1296 | op_end | |
1297 | ||
1298 | ;---------------------------------------------------------------- | |
1299 | ;|Mnemonic |SZHPNC|Description |Notes | | |
1300 | ;---------------------------------------------------------------- | |
1301 | ;|CPL |--1-1-|Complement |A=~A | | |
1302 | ;|----------|SZHP C|---------- 8080 ----------------------------| | |
1303 | ;|CPL |---- -|Complement |A=~A | | |
1304 | ; | |
1305 | ; | |
1306 | do_op_cpl: | |
1307 | com z_a | |
1308 | do_z80_flags_set_HN | |
1309 | op_end | |
1310 | ||
1311 | ||
1312 | ;---------------------------------------------------------------- | |
1313 | ;|Mnemonic |SZHPNC|Description |Notes | | |
1314 | ;---------------------------------------------------------------- | |
1315 | ;|PUSH xx |------|Push |-[SP]=xx | | |
1316 | ;|PUSH qq |------|Push |-[SP]=qq | | |
1317 | ; | |
1318 | ; | |
1319 | do_op_push16: | |
1320 | movw xl,z_spl | |
1321 | sbiw x,1 | |
1322 | mem_write_s oph | |
1323 | sbiw x,1 | |
1324 | mem_write_s opl | |
1325 | movw z_spl,xl | |
1326 | ||
1327 | .if STACK_DBG | |
1328 | printnewline | |
1329 | printstring "Stack push " | |
1330 | movw temp,opl | |
1331 | rcall printhexw | |
1332 | printstring ", SP is now " | |
1333 | movw temp,z_spl | |
1334 | rcall printhexw | |
1335 | printstring ". " | |
1336 | .endif | |
1337 | ||
1338 | op_end | |
1339 | ||
1340 | ;---------------------------------------------------------------- | |
1341 | ;|Mnemonic |SZHPNC|Description |Notes | | |
1342 | ;---------------------------------------------------------------- | |
1343 | ;|POP xx |------|Pop |xx=[SP]+ | | |
1344 | ;|POP qq |------|Pop |qq=[SP]+ | | |
1345 | ; | |
1346 | ; | |
1347 | do_op_pop16: | |
1348 | movw x,z_spl | |
1349 | mem_read_d opl | |
1350 | adiw x,1 | |
1351 | mem_read_d oph | |
1352 | adiw x,1 | |
1353 | movw z_spl,x | |
1354 | ||
1355 | .if STACK_DBG | |
1356 | printnewline | |
1357 | printstring "Stack pop " | |
1358 | movw temp,opl | |
1359 | rcall printhexw | |
1360 | printstring ", SP is now " | |
1361 | movw temp,z_spl | |
1362 | rcall printhexw | |
1363 | printstring ". " | |
1364 | .endif | |
1365 | op_end | |
1366 | ||
1367 | ;---------------------------------------------------------------- | |
1368 | ;|Mnemonic |SZHPNC|Description |Notes | | |
1369 | ;---------------------------------------------------------------- | |
1370 | ;|EX [SP],HL|------|Exchange |[SP]<->HL | | |
1371 | ;|EX DE,HL |------|Exchange |DE<->HL | | |
1372 | ;-----------------------------Z80-------------------------------- | |
1373 | ; | |
1374 | do_op_exhl: | |
1375 | lds temp,z_l | |
1376 | lds temp2,z_h | |
1377 | sts z_l,opl | |
1378 | sts z_h,oph | |
1379 | movw opl,temp | |
1380 | op_end | |
1381 | ||
1382 | ;---------------------------------------------------------------- | |
1383 | ;|Mnemonic |SZHPNC|Description |Notes | | |
1384 | ;---------------------------------------------------------------- | |
1385 | ; | |
1386 | ; TODO: Implement IFF1, IFF2 | |
1387 | do_op_di: | |
1388 | op_end | |
1389 | ||
1390 | ;---------------------------------------------------------------- | |
1391 | ;|Mnemonic |SZHPNC|Description |Notes | | |
1392 | ;---------------------------------------------------------------- | |
1393 | ; | |
1394 | ; TODO: Implement IFF1, IFF2 | |
1395 | do_op_ei: | |
1396 | op_end | |
1397 | ||
1398 | ;---------------------------------------------------------------- | |
1399 | ;|Mnemonic |SZHPNC|Description |Notes | | |
1400 | ;---------------------------------------------------------------- | |
1401 | ;|CALL cc,nn|------|Conditional Call |If cc CALL | | |
1402 | ;|JP cc,nn |------|Conditional Jump |If cc JP | | |
1403 | ;|RET cc |------|Conditional Return |If cc RET | | |
1404 | ; | |
1405 | ; | |
1406 | do_op_ifnz: | |
1407 | sbrc z_flags, ZFL_Z | |
1408 | op_end_nojmp | |
1409 | op_end | |
1410 | ||
1411 | ;---------------------------------------------------------------- | |
1412 | ;|Mnemonic |SZHPNC|Description |Notes | | |
1413 | ;---------------------------------------------------------------- | |
1414 | ;|CALL cc,nn|------|Conditional Call |If cc CALL | | |
1415 | ;|JP cc,nn |------|Conditional Jump |If cc JP | | |
1416 | ;|RET cc |------|Conditional Return |If cc RET | | |
1417 | ; | |
1418 | ; | |
1419 | do_op_ifz: | |
1420 | sbrs z_flags, ZFL_Z | |
1421 | op_end_nojmp | |
1422 | op_end | |
1423 | ||
1424 | ;---------------------------------------------------------------- | |
1425 | ;|Mnemonic |SZHPNC|Description |Notes | | |
1426 | ;---------------------------------------------------------------- | |
1427 | ;|CALL cc,nn|------|Conditional Call |If cc CALL | | |
1428 | ;|JP cc,nn |------|Conditional Jump |If cc JP | | |
1429 | ;|RET cc |------|Conditional Return |If cc RET | | |
1430 | ; | |
1431 | ; | |
1432 | do_op_ifnc: | |
1433 | sbrc z_flags, ZFL_C | |
1434 | op_end_nojmp | |
1435 | op_end | |
1436 | ||
1437 | ;---------------------------------------------------------------- | |
1438 | ;|Mnemonic |SZHPNC|Description |Notes | | |
1439 | ;---------------------------------------------------------------- | |
1440 | ;|CALL cc,nn|------|Conditional Call |If cc CALL | | |
1441 | ;|JP cc,nn |------|Conditional Jump |If cc JP | | |
1442 | ;|RET cc |------|Conditional Return |If cc RET | | |
1443 | ; | |
1444 | ; | |
1445 | do_op_ifc: | |
1446 | sbrs z_flags, ZFL_C | |
1447 | op_end_nojmp | |
1448 | op_end | |
1449 | ||
1450 | ;---------------------------------------------------------------- | |
1451 | ;|Mnemonic |SZHPNC|Description |Notes | | |
1452 | ;---------------------------------------------------------------- | |
1453 | ;|CALL cc,nn|------|Conditional Call |If cc CALL | | |
1454 | ;|JP cc,nn |------|Conditional Jump |If cc JP | | |
1455 | ;|RET cc |------|Conditional Return |If cc RET | | |
1456 | ; | |
1457 | ; | |
1458 | do_op_ifpo: | |
1459 | sbrc z_flags, ZFL_P | |
1460 | op_end_nojmp | |
1461 | op_end | |
1462 | ||
1463 | ;---------------------------------------------------------------- | |
1464 | ;|Mnemonic |SZHPNC|Description |Notes | | |
1465 | ;---------------------------------------------------------------- | |
1466 | ;|CALL cc,nn|------|Conditional Call |If cc CALL | | |
1467 | ;|JP cc,nn |------|Conditional Jump |If cc JP | | |
1468 | ;|RET cc |------|Conditional Return |If cc RET | | |
1469 | ; | |
1470 | ; | |
1471 | do_op_ifpe: | |
1472 | sbrs z_flags, ZFL_P | |
1473 | op_end_nojmp | |
1474 | op_end | |
1475 | ||
1476 | ;---------------------------------------------------------------- | |
1477 | ;|Mnemonic |SZHPNC|Description |Notes | | |
1478 | ;---------------------------------------------------------------- | |
1479 | ;|CALL cc,nn|------|Conditional Call |If cc CALL | | |
1480 | ;|JP cc,nn |------|Conditional Jump |If cc JP | | |
1481 | ;|RET cc |------|Conditional Return |If cc RET | | |
1482 | ; | |
1483 | ; | |
1484 | do_op_ifp: ;sign positive, aka s=0 | |
1485 | sbrc z_flags, ZFL_S | |
1486 | op_end_nojmp | |
1487 | op_end | |
1488 | ||
1489 | ;---------------------------------------------------------------- | |
1490 | ;|Mnemonic |SZHPNC|Description |Notes | | |
1491 | ;---------------------------------------------------------------- | |
1492 | ;|CALL cc,nn|------|Conditional Call |If cc CALL | | |
1493 | ;|JP cc,nn |------|Conditional Jump |If cc JP | | |
1494 | ;|RET cc |------|Conditional Return |If cc RET | | |
1495 | ; | |
1496 | ; | |
1497 | do_op_ifm: ;sign negative, aka s=1 | |
1498 | sbrs z_flags, ZFL_S | |
1499 | op_end_nojmp | |
1500 | op_end | |
1501 | ||
1502 | ||
1503 | ; ----------------------- Opcode decoding ------------------------- | |
1504 | ||
1505 | ; Lookup table for Z80 opcodes. Translates the first byte of the instruction word into three | |
1506 | ; operations: fetch, do something, store. | |
1507 | ; The table is made of 256 words. | |
1508 | ||
1509 | ;.org (PC+255) & 0xff00 | |
1510 | todo_table: | |
1511 | instr do_fetch_nop, op_nop, do_store_nop ;00 ;NOP | |
1512 | instr do_fetch_DIR16, op_nop, do_store_BC ;01 nn nn ;LD BC,nn | |
1513 | instr do_fetch_A, op_nop, do_store_MBC ;02 ;LD (BC),A | |
1514 | instr do_fetch_BC, op_INC16, do_store_BC ;03 ;INC BC | |
1515 | instr do_fetch_B, op_INC, do_store_B ;04 ;INC B | |
1516 | instr do_fetch_B, op_DEC, do_store_B ;05 ;DEC B | |
1517 | instr do_fetch_DIR8, op_nop, do_store_B ;06 ;LD B,n | |
1518 | instr do_fetch_A, op_RLC, do_store_A ;07 ;RLCA | |
1519 | instr do_fetch_nop, op_INV, do_store_nop ;08 ;EX AF,AF' | |
1520 | instr do_fetch_BC, op_ADDHL, do_store_HL ;09 ;ADD HL,BC | |
1521 | instr do_fetch_MBC, op_nop, do_store_A ;0A ;LD A,(BC) | |
1522 | instr do_fetch_BC, op_DEC16, do_store_BC ;0B ;DEC BC | |
1523 | instr do_fetch_C, op_INC, do_store_C ;0C ;INC C | |
1524 | instr do_fetch_C, op_DEC, do_store_C ;0D ;DEC C | |
1525 | instr do_fetch_DIR8, op_nop, do_store_C ;0E nn ;LD C,n | |
1526 | instr do_fetch_A, op_RRC, do_store_A ;0F ;RRCA | |
1527 | instr do_fetch_nop, op_INV, do_store_nop ;10 oo ;DJNZ o | |
1528 | instr do_fetch_DIR16, op_nop, do_store_DE ;11 nn nn ;LD DE,nn | |
1529 | instr do_fetch_A, op_nop, do_store_MDE ;12 ;LD (DE),A | |
1530 | instr do_fetch_DE, op_INC16, do_store_DE ;13 ;INC DE | |
1531 | instr do_fetch_D, op_INC, do_store_D ;14 ;INC D | |
1532 | instr do_fetch_D, op_DEC, do_store_D ;15 ;DEC D | |
1533 | instr do_fetch_DIR8, op_nop, do_store_D ;16 nn ;LD D,n | |
1534 | instr do_fetch_A, op_RL, do_store_A ;17 ;RLA | |
1535 | instr do_fetch_nop, op_INV, do_store_nop ;18 oo ;JR o | |
1536 | instr do_fetch_DE, op_ADDHL, do_store_HL ;19 ;ADD HL,DE | |
1537 | instr do_fetch_MDE, op_nop, do_store_A ;1A ;LD A,(DE) | |
1538 | instr do_fetch_DE, op_DEC16, do_store_DE ;1B ;DEC DE | |
1539 | instr do_fetch_E, op_INC, do_store_E ;1C ;INC E | |
1540 | instr do_fetch_E, op_DEC, do_store_E ;1D ;DEC E | |
1541 | instr do_fetch_DIR8, op_nop, do_store_E ;1E nn ;LD E,n | |
1542 | instr do_fetch_A, op_RR, do_store_A ;1F ;RRA | |
1543 | instr do_fetch_nop, op_INV, do_store_nop ;20 oo ;JR NZ,o | |
1544 | instr do_fetch_DIR16, op_nop, do_store_HL ;21 nn nn ;LD HL,nn | |
1545 | instr do_fetch_DIR16, op_STHL, do_store_nop ;22 nn nn ;LD (nn),HL | |
1546 | instr do_fetch_HL, op_INC16, do_store_HL ;23 ;INC HL | |
1547 | instr do_fetch_H, op_INC, do_store_H ;24 ;INC H | |
1548 | instr do_fetch_H, op_DEC, do_store_H ;25 ;DEC H | |
1549 | instr do_fetch_DIR8, op_nop, do_store_H ;26 nn ;LD H,n | |
1550 | instr do_fetch_A, op_DA, do_store_A ;27 ;DAA | |
1551 | instr do_fetch_nop, op_INV, do_store_nop ;28 oo ;JR Z,o | |
1552 | instr do_fetch_HL, op_ADDHL, do_store_HL ;29 ;ADD HL,HL | |
1553 | instr do_fetch_DIR16, op_RMEM16, do_store_HL ;2A nn nn ;LD HL,(nn) | |
1554 | instr do_fetch_HL, op_DEC16, do_store_HL ;2B ;DEC HL | |
1555 | instr do_fetch_L, op_INC, do_store_L ;2C ;INC L | |
1556 | instr do_fetch_L, op_DEC, do_store_L ;2D ;DEC L | |
1557 | instr do_fetch_DIR8, op_nop, do_store_L ;2E nn ;LD L,n | |
1558 | instr do_fetch_nop, op_CPL, do_store_nop ;2F ;CPL | |
1559 | instr do_fetch_nop, op_INV, do_store_nop ;30 oo ;JR NC,o | |
1560 | instr do_fetch_DIR16, op_nop, do_store_SP ;31 nn nn ;LD SP,nn | |
1561 | instr do_fetch_DIR16, op_nop, do_store_AM ;32 nn nn ;LD (nn),A | |
1562 | instr do_fetch_SP, op_INC16, do_store_SP ;33 ;INC SP | |
1563 | instr do_fetch_MHL, op_INC, do_store_MHL ;34 ;INC (HL) | |
1564 | instr do_fetch_MHL, op_DEC, do_store_MHL ;35 ;DEC (HL) | |
1565 | instr do_fetch_DIR8, op_nop, do_store_MHL ;36 nn ;LD (HL),n | |
1566 | instr do_fetch_nop, op_SCF, do_store_nop ;37 ;SCF | |
1567 | instr do_fetch_nop, op_INV, do_store_nop ;38 oo ;JR C,o | |
1568 | instr do_fetch_SP, op_ADDHL, do_store_HL ;39 ;ADD HL,SP | |
1569 | instr do_fetch_DIR16, op_RMEM8, do_store_A ;3A nn nn ;LD A,(nn) | |
1570 | instr do_fetch_SP, op_DEC16, do_store_SP ;3B ;DEC SP | |
1571 | instr do_fetch_nop, op_INCA, do_store_nop ;3C ;INC A | |
1572 | instr do_fetch_nop, op_DECA, do_store_nop ;3D ;DEC A | |
1573 | instr do_fetch_DIR8, op_nop, do_store_A ;3E nn ;LD A,n | |
1574 | instr do_fetch_nop, op_CCF, do_store_nop ;3F ;CCF (Complement Carry Flag, gvd) | |
1575 | instr do_fetch_B, op_nop, do_store_B ;40 ;LD B,B | |
1576 | instr do_fetch_C, op_nop, do_store_B ;41 ;LD B,C | |
1577 | instr do_fetch_D, op_nop, do_store_B ;42 ;LD B,D | |
1578 | instr do_fetch_E, op_nop, do_store_B ;43 ;LD B,E | |
1579 | instr do_fetch_H, op_nop, do_store_B ;44 ;LD B,H | |
1580 | instr do_fetch_L, op_nop, do_store_B ;45 ;LD B,L | |
1581 | instr do_fetch_MHL, op_nop, do_store_B ;46 ;LD B,(HL) | |
1582 | instr do_fetch_A, op_nop, do_store_B ;47 ;LD B,A | |
1583 | instr do_fetch_B, op_nop, do_store_C ;48 ;LD C,B | |
1584 | instr do_fetch_C, op_nop, do_store_C ;49 ;LD C,C | |
1585 | instr do_fetch_D, op_nop, do_store_C ;4A ;LD C,D | |
1586 | instr do_fetch_E, op_nop, do_store_C ;4B ;LD C,E | |
1587 | instr do_fetch_H, op_nop, do_store_C ;4C ;LD C,H | |
1588 | instr do_fetch_L, op_nop, do_store_C ;4D ;LD C,L | |
1589 | instr do_fetch_MHL, op_nop, do_store_C ;4E ;LD C,(HL) | |
1590 | instr do_fetch_A, op_nop, do_store_C ;4F ;LD C,A | |
1591 | instr do_fetch_B, op_nop, do_store_D ;50 ;LD D,B | |
1592 | instr do_fetch_C, op_nop, do_store_D ;51 ;LD D,C | |
1593 | instr do_fetch_D, op_nop, do_store_D ;52 ;LD D,D | |
1594 | instr do_fetch_E, op_nop, do_store_D ;53 ;LD D,E | |
1595 | instr do_fetch_H, op_nop, do_store_D ;54 ;LD D,H | |
1596 | instr do_fetch_L, op_nop, do_store_D ;55 ;LD D,L | |
1597 | instr do_fetch_MHL, op_nop, do_store_D ;56 ;LD D,(HL) | |
1598 | instr do_fetch_A, op_nop, do_store_D ;57 ;LD D,A | |
1599 | instr do_fetch_B, op_nop, do_store_E ;58 ;LD E,B | |
1600 | instr do_fetch_C, op_nop, do_store_E ;59 ;LD E,C | |
1601 | instr do_fetch_D, op_nop, do_store_E ;5A ;LD E,D | |
1602 | instr do_fetch_E, op_nop, do_store_E ;5B ;LD E,E | |
1603 | instr do_fetch_H, op_nop, do_store_E ;5C ;LD E,H | |
1604 | instr do_fetch_L, op_nop, do_store_E ;5D ;LD E,L | |
1605 | instr do_fetch_MHL, op_nop, do_store_E ;5E ;LD E,(HL) | |
1606 | instr do_fetch_A, op_nop, do_store_E ;5F ;LD E,A | |
1607 | instr do_fetch_B, op_nop, do_store_H ;60 ;LD H,B | |
1608 | instr do_fetch_C, op_nop, do_store_H ;61 ;LD H,C | |
1609 | instr do_fetch_D, op_nop, do_store_H ;62 ;LD H,D | |
1610 | instr do_fetch_E, op_nop, do_store_H ;63 ;LD H,E | |
1611 | instr do_fetch_H, op_nop, do_store_H ;64 ;LD H,H | |
1612 | instr do_fetch_L, op_nop, do_store_H ;65 ;LD H,L | |
1613 | instr do_fetch_MHL, op_nop, do_store_H ;66 ;LD H,(HL) | |
1614 | instr do_fetch_A, op_nop, do_store_H ;67 ;LD H,A | |
1615 | instr do_fetch_B, op_nop, do_store_L ;68 ;LD L,B | |
1616 | instr do_fetch_C, op_nop, do_store_L ;69 ;LD L,C | |
1617 | instr do_fetch_D, op_nop, do_store_L ;6A ;LD L,D | |
1618 | instr do_fetch_E, op_nop, do_store_L ;6B ;LD L,E | |
1619 | instr do_fetch_H, op_nop, do_store_L ;6C ;LD L,H | |
1620 | instr do_fetch_L, op_nop, do_store_L ;6D ;LD L,L | |
1621 | instr do_fetch_MHL, op_nop, do_store_L ;6E ;LD L,(HL) | |
1622 | instr do_fetch_A, op_nop, do_store_L ;6F ;LD L,A | |
1623 | instr do_fetch_B, op_nop, do_store_MHL ;70 ;LD (HL),B | |
1624 | instr do_fetch_C, op_nop, do_store_MHL ;71 ;LD (HL),C | |
1625 | instr do_fetch_D, op_nop, do_store_MHL ;72 ;LD (HL),D | |
1626 | instr do_fetch_E, op_nop, do_store_MHL ;73 ;LD (HL),E | |
1627 | instr do_fetch_H, op_nop, do_store_MHL ;74 ;LD (HL),H | |
1628 | instr do_fetch_L, op_nop, do_store_MHL ;75 ;LD (HL),L | |
1629 | instr do_fetch_nop, op_INV, do_store_nop ;76 ;HALT | |
1630 | instr do_fetch_A, op_nop, do_store_MHL ;77 ;LD (HL),A | |
1631 | instr do_fetch_B, op_nop, do_store_A ;78 ;LD A,B | |
1632 | instr do_fetch_C, op_nop, do_store_A ;79 ;LD A,C | |
1633 | instr do_fetch_D, op_nop, do_store_A ;7A ;LD A,D | |
1634 | instr do_fetch_E, op_nop, do_store_A ;7B ;LD A,E | |
1635 | instr do_fetch_H, op_nop, do_store_A ;7C ;LD A,H | |
1636 | instr do_fetch_L, op_nop, do_store_A ;7D ;LD A,L | |
1637 | instr do_fetch_MHL, op_nop, do_store_A ;7E ;LD A,(HL) | |
1638 | instr do_fetch_A, op_nop, do_store_A ;7F ;LD A,A | |
1639 | instr do_fetch_B, op_ADDA, do_store_nop ;80 ;ADD A,B | |
1640 | instr do_fetch_C, op_ADDA, do_store_nop ;81 ;ADD A,C | |
1641 | instr do_fetch_D, op_ADDA, do_store_nop ;82 ;ADD A,D | |
1642 | instr do_fetch_E, op_ADDA, do_store_nop ;83 ;ADD A,E | |
1643 | instr do_fetch_H, op_ADDA, do_store_nop ;84 ;ADD A,H | |
1644 | instr do_fetch_L, op_ADDA, do_store_nop ;85 ;ADD A,L | |
1645 | instr do_fetch_MHL, op_ADDA, do_store_nop ;86 ;ADD A,(HL) | |
1646 | instr do_fetch_A, op_ADDA, do_store_nop ;87 ;ADD A,A | |
1647 | instr do_fetch_B, op_ADCA, do_store_nop ;88 ;ADC A,B | |
1648 | instr do_fetch_C, op_ADCA, do_store_nop ;89 ;ADC A,C | |
1649 | instr do_fetch_D, op_ADCA, do_store_nop ;8A ;ADC A,D | |
1650 | instr do_fetch_E, op_ADCA, do_store_nop ;8B ;ADC A,E | |
1651 | instr do_fetch_H, op_ADCA, do_store_nop ;8C ;ADC A,H | |
1652 | instr do_fetch_L, op_ADCA, do_store_nop ;8D ;ADC A,L | |
1653 | instr do_fetch_MHL, op_ADCA, do_store_nop ;8E ;ADC A,(HL) | |
1654 | instr do_fetch_A, op_ADCA, do_store_nop ;8F ;ADC A,A | |
1655 | instr do_fetch_B, op_SUBFA, do_store_nop ;90 ;SUB A,B | |
1656 | instr do_fetch_C, op_SUBFA, do_store_nop ;91 ;SUB A,C | |
1657 | instr do_fetch_D, op_SUBFA, do_store_nop ;92 ;SUB A,D | |
1658 | instr do_fetch_E, op_SUBFA, do_store_nop ;93 ;SUB A,E | |
1659 | instr do_fetch_H, op_SUBFA, do_store_nop ;94 ;SUB A,H | |
1660 | instr do_fetch_L, op_SUBFA, do_store_nop ;95 ;SUB A,L | |
1661 | instr do_fetch_MHL, op_SUBFA, do_store_nop ;96 ;SUB A,(HL) | |
1662 | instr do_fetch_A, op_SUBFA, do_store_nop ;97 ;SUB A,A | |
1663 | instr do_fetch_B, op_SBCFA, do_store_nop ;98 ;SBC A,B | |
1664 | instr do_fetch_C, op_SBCFA, do_store_nop ;99 ;SBC A,C | |
1665 | instr do_fetch_D, op_SBCFA, do_store_nop ;9A ;SBC A,D | |
1666 | instr do_fetch_E, op_SBCFA, do_store_nop ;9B ;SBC A,E | |
1667 | instr do_fetch_H, op_SBCFA, do_store_nop ;9C ;SBC A,H | |
1668 | instr do_fetch_L, op_SBCFA, do_store_nop ;9D ;SBC A,L | |
1669 | instr do_fetch_MHL, op_SBCFA, do_store_nop ;9E ;SBC A,(HL) | |
1670 | instr do_fetch_A, op_SBCFA, do_store_nop ;9F ;SBC A,A | |
1671 | instr do_fetch_B, op_ANDA, do_store_nop ;A0 ;AND A,B | |
1672 | instr do_fetch_C, op_ANDA, do_store_nop ;A1 ;AND A,C | |
1673 | instr do_fetch_D, op_ANDA, do_store_nop ;A2 ;AND A,D | |
1674 | instr do_fetch_E, op_ANDA, do_store_nop ;A3 ;AND A,E | |
1675 | instr do_fetch_H, op_ANDA, do_store_nop ;A4 ;AND A,H | |
1676 | instr do_fetch_L, op_ANDA, do_store_nop ;A5 ;AND A,L | |
1677 | instr do_fetch_MHL, op_ANDA, do_store_nop ;A6 ;AND A,(HL) | |
1678 | instr do_fetch_A, op_ANDA, do_store_nop ;A7 ;AND A,A | |
1679 | instr do_fetch_B, op_XORA, do_store_nop ;A8 ;XOR A,B | |
1680 | instr do_fetch_C, op_XORA, do_store_nop ;A9 ;XOR A,C | |
1681 | instr do_fetch_D, op_XORA, do_store_nop ;AA ;XOR A,D | |
1682 | instr do_fetch_E, op_XORA, do_store_nop ;AB ;XOR A,E | |
1683 | instr do_fetch_H, op_XORA, do_store_nop ;AC ;XOR A,H | |
1684 | instr do_fetch_L, op_XORA, do_store_nop ;AD ;XOR A,L | |
1685 | instr do_fetch_MHL, op_XORA, do_store_nop ;AE ;XOR A,(HL) | |
1686 | instr do_fetch_A, op_XORA, do_store_nop ;AF ;XOR A,A | |
1687 | instr do_fetch_B, op_ORA, do_store_nop ;B0 ;OR A,B | |
1688 | instr do_fetch_C, op_ORA, do_store_nop ;B1 ;OR A,C | |
1689 | instr do_fetch_D, op_ORA, do_store_nop ;B2 ;OR A,D | |
1690 | instr do_fetch_E, op_ORA, do_store_nop ;B3 ;OR A,E | |
1691 | instr do_fetch_H, op_ORA, do_store_nop ;B4 ;OR A,H | |
1692 | instr do_fetch_L, op_ORA, do_store_nop ;B5 ;OR A,L | |
1693 | instr do_fetch_MHL, op_ORA, do_store_nop ;B6 ;OR A,(HL) | |
1694 | instr do_fetch_A, op_ORA, do_store_nop ;B7 ;OR A,A | |
1695 | instr do_fetch_B, op_CPFA, do_store_nop ;B8 ;CP A,B | |
1696 | instr do_fetch_C, op_CPFA, do_store_nop ;B9 ;CP A,C | |
1697 | instr do_fetch_D, op_CPFA, do_store_nop ;BA ;CP A,D | |
1698 | instr do_fetch_E, op_CPFA, do_store_nop ;BB ;CP A,E | |
1699 | instr do_fetch_H, op_CPFA, do_store_nop ;BC ;CP A,H | |
1700 | instr do_fetch_L, op_CPFA, do_store_nop ;BD ;CP A,L | |
1701 | instr do_fetch_MHL, op_CPFA, do_store_nop ;BE ;CP A,(HL) | |
1702 | instr do_fetch_A, op_CPFA, do_store_nop ;BF ;CP A,A | |
1703 | instr do_fetch_nop, op_IFNZ, do_store_RET ;C0 ;RET NZ | |
1704 | instr do_fetch_nop, op_POP16, do_store_BC ;C1 ;POP BC | |
1705 | instr do_fetch_DIR16, op_IFNZ, do_store_PC ;C2 nn nn ;JP NZ,nn | |
1706 | instr do_fetch_DIR16, op_nop, do_store_PC ;C3 nn nn ;JP nn | |
1707 | instr do_fetch_DIR16, op_IFNZ, do_store_CALL ;C4 nn nn ;CALL NZ,nn | |
1708 | instr do_fetch_BC, op_PUSH16, do_store_nop ;C5 ;PUSH BC | |
1709 | instr do_fetch_DIR8, op_ADDA, do_store_nop ;C6 nn ;ADD A,n | |
1710 | instr do_fetch_RST, op_nop, do_store_CALL ;C7 ;RST 0 | |
1711 | instr do_fetch_nop, op_IFZ, do_store_RET ;C8 ;RET Z | |
1712 | instr do_fetch_nop, op_nop, do_store_RET ;C9 ;RET | |
1713 | instr do_fetch_DIR16, op_IFZ, do_store_PC ;CA nn nn ;JP Z,nn | |
1714 | instr do_fetch_nop, op_INV, do_store_nop ;CB ;(Z80 specific) | |
1715 | instr do_fetch_DIR16, op_IFZ, do_store_CALL ;CC nn nn ;CALL Z,nn | |
1716 | instr do_fetch_DIR16, op_nop, do_store_CALL ;CD nn nn ;CALL nn | |
1717 | instr do_fetch_DIR8, op_ADCA, do_store_nop ;CE nn ;ADC A,n | |
1718 | instr do_fetch_RST, op_nop, do_store_CALL ;CF ;RST 8H | |
1719 | instr do_fetch_nop, op_IFNC, do_store_RET ;D0 ;RET NC | |
1720 | instr do_fetch_nop, op_POP16, do_store_DE ;D1 ;POP DE | |
1721 | instr do_fetch_DIR16, op_IFNC, do_store_PC ;D2 nn nn ;JP NC,nn | |
1722 | instr do_fetch_DIR8, op_OUTA, do_store_nop ;D3 nn ;OUT (n),A | |
1723 | instr do_fetch_DIR16, op_IFNC, do_store_CALL ;D4 nn nn ;CALL NC,nn | |
1724 | instr do_fetch_DE, op_PUSH16, do_store_nop ;D5 ;PUSH DE | |
1725 | instr do_fetch_DIR8, op_SUBFA, do_store_nop ;D6 nn ;SUB n | |
1726 | instr do_fetch_RST, op_nop, do_store_CALL ;D7 ;RST 10H | |
1727 | instr do_fetch_nop, op_IFC, do_store_RET ;D8 ;RET C | |
1728 | instr do_fetch_nop, op_nop, do_store_nop ;D9 ;EXX | |
1729 | instr do_fetch_DIR16, op_IFC, do_store_PC ;DA nn nn ;JP C,nn | |
1730 | instr do_fetch_DIR8, op_IN, do_store_A ;DB nn ;IN A,(n) | |
1731 | instr do_fetch_DIR16, op_IFC, do_store_CALL ;DC nn nn ;CALL C,nn | |
1732 | instr do_fetch_nop, op_INV, do_store_nop ;DD ;(Z80 specific) | |
1733 | instr do_fetch_DIR8, op_SBCFA, do_store_nop ;DE nn ;SBC A,n | |
1734 | instr do_fetch_RST, op_nop, do_store_CALL ;DF ;RST 18H | |
1735 | instr do_fetch_nop, op_IFPO, do_store_RET ;E0 ;RET PO | |
1736 | instr do_fetch_nop, op_POP16, do_store_HL ;E1 ;POP HL | |
1737 | instr do_fetch_DIR16, op_IFPO, do_store_PC ;E2 nn nn ;JP PO,nn | |
1738 | instr do_fetch_MSP, op_EXHL, do_store_MSP ;E3 ;EX (SP),HL | |
1739 | instr do_fetch_DIR16, op_IFPO, do_store_CALL ;E4 nn nn ;CALL PO,nn | |
1740 | instr do_fetch_HL, op_PUSH16, do_store_nop ;E5 ;PUSH HL | |
1741 | instr do_fetch_DIR8, op_ANDA, do_store_nop ;E6 nn ;AND n | |
1742 | instr do_fetch_RST, op_nop, do_store_CALL ;E7 ;RST 20H | |
1743 | instr do_fetch_nop, op_IFPE, do_store_RET ;E8 ;RET PE | |
1744 | instr do_fetch_HL, op_nop, do_store_PC ;E9 ;JP HL | |
1745 | instr do_fetch_DIR16, op_IFPE, do_store_PC ;EA nn nn ;JP PE,nn | |
1746 | instr do_fetch_DE, op_EXHL, do_store_DE ;EB ;EX DE,HL | |
1747 | instr do_fetch_DIR16, op_IFPE, do_store_CALL ;EC nn nn ;CALL PE,nn | |
1748 | instr do_fetch_nop, op_INV, do_store_nop ;ED ;(Z80 specific) | |
1749 | instr do_fetch_DIR8, op_XORA, do_store_nop ;EE nn ;XOR n | |
1750 | instr do_fetch_RST, op_nop, do_store_CALL ;EF ;RST 28H | |
1751 | instr do_fetch_nop, op_IFP, do_store_RET ;F0 ;RET P | |
1752 | instr do_fetch_nop, op_POP16, do_store_AF ;F1 ;POP AF | |
1753 | instr do_fetch_DIR16, op_IFP, do_store_PC ;F2 nn nn ;JP P,nn | |
1754 | instr do_fetch_nop, op_DI, do_store_nop ;F3 ;DI | |
1755 | instr do_fetch_DIR16, op_IFP, do_store_CALL ;F4 nn nn ;CALL P,nn | |
1756 | instr do_fetch_AF, op_PUSH16, do_store_nop ;F5 ;PUSH AF | |
1757 | instr do_fetch_DIR8, op_ORA, do_store_nop ;F6 nn ;OR n | |
1758 | instr do_fetch_RST, op_nop, do_store_CALL ;F7 ;RST 30H | |
1759 | instr do_fetch_nop, op_IFM, do_store_RET ;F8 ;RET M | |
1760 | instr do_fetch_HL, op_nop, do_store_SP ;F9 ;LD SP,HL | |
1761 | instr do_fetch_DIR16, op_IFM, do_store_PC ;FA nn nn ;JP M,nn | |
1762 | instr do_fetch_nop, op_EI, do_store_nop ;FB ;EI | |
1763 | instr do_fetch_DIR16, op_IFM, do_store_CALL ;FC nn nn ;CALL M,nn | |
1764 | instr do_fetch_nop, op_INV, do_store_nop ;FD ;(Z80 specific) | |
1765 | instr do_fetch_DIR8, op_CPFA, do_store_nop ;FE nn ;CP n | |
1766 | instr do_fetch_RST, op_nop, do_store_CALL ;FF ;RST 38H | |
1767 | ||
1768 | ;---------------------------------------------------------------- | |
1769 | ; Lookup table, stolen from z80ex, Z80 emulation library. | |
1770 | ; http://z80ex.sourceforge.net/ | |
1771 | ||
1772 | ; The S, Z, 5 and 3 bits and the parity of the lookup value | |
1773 | ||
1774 | .org (PC+255) & 0xff00 | |
1775 | sz53p_tab: | |
1776 | .db 0x44,0x00,0x00,0x04,0x00,0x04,0x04,0x00 | |
1777 | .db 0x08,0x0c,0x0c,0x08,0x0c,0x08,0x08,0x0c | |
1778 | .db 0x00,0x04,0x04,0x00,0x04,0x00,0x00,0x04 | |
1779 | .db 0x0c,0x08,0x08,0x0c,0x08,0x0c,0x0c,0x08 | |
1780 | .db 0x20,0x24,0x24,0x20,0x24,0x20,0x20,0x24 | |
1781 | .db 0x2c,0x28,0x28,0x2c,0x28,0x2c,0x2c,0x28 | |
1782 | .db 0x24,0x20,0x20,0x24,0x20,0x24,0x24,0x20 | |
1783 | .db 0x28,0x2c,0x2c,0x28,0x2c,0x28,0x28,0x2c | |
1784 | .db 0x00,0x04,0x04,0x00,0x04,0x00,0x00,0x04 | |
1785 | .db 0x0c,0x08,0x08,0x0c,0x08,0x0c,0x0c,0x08 | |
1786 | .db 0x04,0x00,0x00,0x04,0x00,0x04,0x04,0x00 | |
1787 | .db 0x08,0x0c,0x0c,0x08,0x0c,0x08,0x08,0x0c | |
1788 | .db 0x24,0x20,0x20,0x24,0x20,0x24,0x24,0x20 | |
1789 | .db 0x28,0x2c,0x2c,0x28,0x2c,0x28,0x28,0x2c | |
1790 | .db 0x20,0x24,0x24,0x20,0x24,0x20,0x20,0x24 | |
1791 | .db 0x2c,0x28,0x28,0x2c,0x28,0x2c,0x2c,0x28 | |
1792 | .db 0x80,0x84,0x84,0x80,0x84,0x80,0x80,0x84 | |
1793 | .db 0x8c,0x88,0x88,0x8c,0x88,0x8c,0x8c,0x88 | |
1794 | .db 0x84,0x80,0x80,0x84,0x80,0x84,0x84,0x80 | |
1795 | .db 0x88,0x8c,0x8c,0x88,0x8c,0x88,0x88,0x8c | |
1796 | .db 0xa4,0xa0,0xa0,0xa4,0xa0,0xa4,0xa4,0xa0 | |
1797 | .db 0xa8,0xac,0xac,0xa8,0xac,0xa8,0xa8,0xac | |
1798 | .db 0xa0,0xa4,0xa4,0xa0,0xa4,0xa0,0xa0,0xa4 | |
1799 | .db 0xac,0xa8,0xa8,0xac,0xa8,0xac,0xac,0xa8 | |
1800 | .db 0x84,0x80,0x80,0x84,0x80,0x84,0x84,0x80 | |
1801 | .db 0x88,0x8c,0x8c,0x88,0x8c,0x88,0x88,0x8c | |
1802 | .db 0x80,0x84,0x84,0x80,0x84,0x80,0x80,0x84 | |
1803 | .db 0x8c,0x88,0x88,0x8c,0x88,0x8c,0x8c,0x88 | |
1804 | .db 0xa0,0xa4,0xa4,0xa0,0xa4,0xa0,0xa0,0xa4 | |
1805 | .db 0xac,0xa8,0xa8,0xac,0xa8,0xac,0xac,0xa8 | |
1806 | .db 0xa4,0xa0,0xa0,0xa4,0xa0,0xa4,0xa4,0xa0 | |
1807 | .db 0xa8,0xac,0xac,0xa8,0xac,0xa8,0xa8,0xac | |
1808 | ||
1809 | ; vim:set ts=8 noet nowrap | |
1810 |