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