2 ; This is part of the Z80-CP/M emulator written by Sprite_tm.
5 ; Copyright (C) 2010 Sprite_tm
6 ; Copyright (C) 2010 Leo C.
7 ; Copyright (C) 2010 Horst S.
9 ; This file is part of avrcpm.
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.
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.
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/>.
27 ;--------------------------------------------------
28 ; Generate a table entry for one instruction
30 ; instr fetch, op, store
33 .db low(@2), low(@1), high(@1), low(@0)
51 ldi z_pcl,low (IPLADDR)
52 ldi z_pch,high(IPLADDR)
56 printstring "Ok, CPU is live!"
59 ;----------------------------------------------------------
61 ;.db (low)do_store (low)do_op (hihg)do_op (low)do_fetch
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
68 ;das wird direkt angesprungen
69 ;do_fetch woher beenden mit RET
75 cpi z_pch,DBG_TRACE_BOTTOM
77 cpi z_pch,DBG_TRACE_TOP
85 cpi z_pch,DBG_TRACE_BOTTOM
87 cpi z_pch,DBG_TRACE_TOP
103 ;hier kommt die Interruptbehandlung rein
105 ldi zl,low(main) ;da will ich wieder hin.
109 mem_read_s z_pc ;temp=memReadByte(z_pc)
111 ldi zl,low(todo_table*2) ;zhl=todo_table
112 ldi zh,high(todo_table*2) ;
117 ldi temp2,high(store_ops) ;
118 lpm temp,Z+ ;do_store
130 ldi zh,high(fetch_ops)
135 ; ------------ Fetch phase stuff -----------------
137 .org (PC+255) & 0xff00 ; wichtig !!!fetch und store muessen in einer page liegen
220 mem_read_ds opl, z_pc
225 mem_read_ds opl, z_pc
227 mem_read_ds oph, z_pc
239 ; ------------ Store phase stuff -----------------
241 .org (PC+255) & 0xff00 ; wichtig !!!fetch und store muessen in einer page liegen
336 printstring "Stack pop "
339 printstring ", SP is now "
356 printstring "Stack push "
359 printstring ", SP is now "
372 ; ------------ Operation phase stuff -----------------
375 ;----------------------------------------------------------------
379 ;| ZZZZZZZ 88888 000 |
385 ;| ZZZZZZZ 88888 000 |
387 ;| Z80 MICROPROCESSOR Instruction Set Summary |
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 ;----------------------------------------------------------------
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
555 ;I sure hope I got the mapping between flags and instructions correct...
572 ;------------------------------------------------;
573 ; Load table value from flash indexed by source reg.
575 ;ldpmx dstreg,tablebase,indexreg
577 ; (6 words, 8 cycles)
580 ldi zh,high(@1*2) ; table must be page aligned
585 .macro do_z80_flags_HP
587 bmov z_flags, ZFL_P, temp, AVR_V
588 bmov z_flags, ZFL_H, temp, AVR_H
592 .macro do_z80_flags_set_N
594 ori z_flags, (1<<ZFL_N) ; Negation auf 1
598 .macro do_z80_flags_set_HN
600 ori z_flags,(1<<ZFL_N)|(1<<ZFL_H)
604 .macro do_z80_flags_clear_N
606 andi z_flags,~(1<<ZFL_N)
610 .macro do_z80_flags_op_rotate
611 ; must not change avr carry flag!
613 andi z_flags, ~( (1<<ZFL_H) | (1<<ZFL_N) | (1<<ZFL_C) )
615 andi z_flags, ~( (1<<ZFL_C) )
619 .macro do_z80_flags_op_and
621 ori z_flags,(1<<ZFL_H)
623 ori z_flags,(1<<ZFL_H)
627 .macro do_z80_flags_op_or
633 ;----------------------------------------------------------------
636 printstring "Invalid opcode @ PC="
643 ;----------------------------------------------------------------
644 ;|Mnemonic |SZHPNC|Description |Notes |
645 ;----------------------------------------------------------------
646 ;|OUT [n],A |------|Output |[n]=A |
649 ;Interface with peripherials goes here :)
650 do_op_outa: ; out (opl),a
653 printstring "Port write: "
666 ;----------------------------------------------------------------
667 ;|Mnemonic |SZHPNC|Description |Notes |
668 ;----------------------------------------------------------------
669 ;|IN A,[n] |------|Input |A=[n] |
672 do_op_in: ; in a,(opl)
675 printstring "Port read: ("
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 |
707 andi z_flags,(1<<ZFL_H)|(1<<ZFL_C) ; preserve C-, and H-flag
708 ldpmx temp2, sz53p_tab, opl
718 andi z_flags,(1<<ZFL_H)|(1<<ZFL_C) ; preserve C-, and H-flag
719 ldpmx temp2, sz53p_tab, z_a
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 |
740 andi z_flags,(1<<ZFL_H)|(1<<ZFL_C) ; preserve C-, and H-flag
741 ldpmx temp2, sz53p_tab, opl
752 andi z_flags,(1<<ZFL_H)|(1<<ZFL_C) ; preserve C-, and H-flag
753 ldpmx temp2, sz53p_tab, z_a
759 ;----------------------------------------------------------------
760 ;|Mnemonic |SZHPNC|Description |Notes |
761 ;----------------------------------------------------------------
762 ;|INC xx |------|Increment |xx=xx+1 |
763 ;|INC ss |------|Increment |ss=ss+1 |
771 ;----------------------------------------------------------------
772 ;|Mnemonic |SZHPNC|Description |Notes |
773 ;----------------------------------------------------------------
774 ;|DEC xx |------|Decrement |xx=xx-1 |
775 ;|DEC ss |------|Decrement |ss=ss-1 |
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<- |
792 ;Rotate Left Cyclical. All bits move 1 to the
793 ;left, the msb becomes c and lsb.
794 do_z80_flags_op_rotate
798 ori z_flags, (1<<ZFL_C)
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 |
811 ;Rotate Right Cyclical. All bits move 1 to the
812 ;right, the lsb becomes c and msb.
813 do_z80_flags_op_rotate
817 ori z_flags, (1<<ZFL_C)
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} |
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
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
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}<- |
849 ;Rotate Left. All bits move 1 to the left, the msb
850 ;becomes c, c becomes lsb.
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
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 |
870 ldpmx z_flags,sz53p_tab,z_a ;S,Z,P flag
871 bmov z_flags,ZFL_C, temp,AVR_C
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 |
889 ldpmx z_flags,sz53p_tab,z_a ;S,Z,P
890 bmov z_flags,ZFL_C, temp,AVR_C
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 |
905 ldpmx z_flags,sz53p_tab,z_a ;S,Z,P
906 bmov z_flags,ZFL_C, temp,AVR_C
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 |
924 ldpmx z_flags,sz53p_tab,opl ;S,Z,P
925 bmov z_flags,ZFL_C, temp,AVR_C
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 |
944 ldpmx z_flags,sz53p_tab,z_a ;S,Z,P
945 bmov z_flags,ZFL_C, temp,AVR_C
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 |
960 ldpmx z_flags,sz53p_tab,z_a ;S,Z,P,N,C
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 |
975 ldpmx z_flags,sz53p_tab,z_a ;S,Z,H,P,N,C
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 |
989 ldpmx z_flags,sz53p_tab,z_a ;S,Z,H,P,N,C
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 |
1007 bmov z_flags,ZFL_H, temp,AVR_H
1008 bmov z_flags,ZFL_C, temp,AVR_C
1009 do_z80_flags_clear_N
1012 ;----------------------------------------------------------------
1013 ;|Mnemonic |SZHPNC|Description |Notes |
1014 ;----------------------------------------------------------------
1015 ;|LD dst,src|------|Load |dst=src |
1018 do_op_sthl: ;store hl to mem loc in opl:h
1027 ;----------------------------------------------------------------
1028 ;|Mnemonic |SZHPNC|Description |Notes |
1029 ;----------------------------------------------------------------
1030 ;|LD dst,src|------|Load |dst=src |
1040 ;----------------------------------------------------------------
1041 ;|Mnemonic |SZHPNC|Description |Notes |
1042 ;----------------------------------------------------------------
1043 ;|LD dst,src|------|Load |dst=src |
1050 ;----------------------------------------------------------------
1051 ;|Mnemonic |SZHPNC|Description |Notes |
1052 ;----------------------------------------------------------------
1053 ;|DAA |***P-*|Decimal Adjust Acc. | |
1054 ;|----------|SZHP C|---------- 8080 ----------------------------|
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:
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 ; |-----------------------------------------------------------------------------|
1085 ; C: See instruction.
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.
1096 ldi oph,0 ; what to add
1097 sbrc z_flags,ZFL_H ; if H-Flag
1100 andi temp,0x0f ; ... or lower digit > 9
1106 sbrc z_flags,(1<<ZFL_C)
1115 ori z_flags,(1<<ZFL_C); set C
1117 sbrs z_flags,ZFL_N ; if sub-op
1118 rjmp op_da_add ; then
1121 op_da_add: ; else add-op
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
1138 bmov z_flags,ZFL_H, temp,AVR_H ; H (?)
1143 sbrc z_flags,ZFL_N ; if add-op
1144 rjmp do_op_da_sub ; then
1148 cpi temp,0x0a ;if lower digit > 9
1150 ori temp2,0x06 ; add 6 to lower digit
1152 sbrc z_flags,ZFL_H ; ... or H-Flag
1162 do_op_da_c: ; else sub-op
1163 sbrc z_flags,ZFL_C ;
1165 andi z_flags, ~( (1<<ZFL_S) | (1<<ZFL_Z) | (1<<ZFL_H) )
1168 bst temp,AVR_Z ;Z-Flag
1170 bst temp,AVR_N ;S-Flag
1172 sbrc temp2,5 ;C-Flag, set if 0x06 added
1173 ori z_flags,(1<<ZFL_C) ;
1177 do_op_da_sub: ;TODO:
1182 ;----------------------------------------------------------------
1183 ;|Mnemonic |SZHPNC|Description |Notes |
1184 ;----------------------------------------------------------------
1185 ;|SCF |--0-01|Set Carry Flag |CY=1 |
1186 ;|----------|SZHP C|---------- 8080 ----------------------------|
1190 andi z_flags,~((1<<ZFL_H)|(1<<ZFL_N))
1191 ori z_flags,(1<<ZFL_C)
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 |
1203 do_z80_flags_clear_N
1208 ;----------------------------------------------------------------
1209 ;|Mnemonic |SZHPNC|Description |Notes |
1210 ;----------------------------------------------------------------
1211 ;|CPL |--1-1-|Complement |A=~A |
1212 ;|----------|SZHP C|---------- 8080 ----------------------------|
1213 ;|CPL |---- -|Complement |A=~A |
1222 ;----------------------------------------------------------------
1223 ;|Mnemonic |SZHPNC|Description |Notes |
1224 ;----------------------------------------------------------------
1225 ;|PUSH xx |------|Push |-[SP]=xx |
1226 ;|PUSH qq |------|Push |-[SP]=qq |
1239 printstring "Stack push "
1242 printstring ", SP is now "
1250 ;----------------------------------------------------------------
1251 ;|Mnemonic |SZHPNC|Description |Notes |
1252 ;----------------------------------------------------------------
1253 ;|POP xx |------|Pop |xx=[SP]+ |
1254 ;|POP qq |------|Pop |qq=[SP]+ |
1267 printstring "Stack pop "
1270 printstring ", SP is now "
1277 ;----------------------------------------------------------------
1278 ;|Mnemonic |SZHPNC|Description |Notes |
1279 ;----------------------------------------------------------------
1280 ;|EX [SP],HL|------|Exchange |[SP]<->HL |
1281 ;|EX DE,HL |------|Exchange |DE<->HL |
1282 ;-----------------------------Z80--------------------------------
1292 ;----------------------------------------------------------------
1293 ;|Mnemonic |SZHPNC|Description |Notes |
1294 ;----------------------------------------------------------------
1296 ; TODO: Implement IFF1, IFF2
1300 ;----------------------------------------------------------------
1301 ;|Mnemonic |SZHPNC|Description |Notes |
1302 ;----------------------------------------------------------------
1304 ; TODO: Implement IFF1, IFF2
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 |
1320 pop temp ; direkt zuruech zu main
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 |
1335 pop temp ; direkt zuruech zu main
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 |
1350 pop temp ; direkt zuruech zu main
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 |
1365 pop temp ; direkt zuruech zu main
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 |
1380 pop temp ; direkt zuruech zu main
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 |
1395 pop temp ; direkt zuruech zu main
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 |
1406 do_op_ifp: ;sign positive, aka s=0
1410 pop temp ; direkt zuruech zu main
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 |
1421 do_op_ifm: ;sign negative, aka s=1
1425 pop temp ; direkt zuruech zu main
1429 ; ----------------------- Opcode decoding -------------------------
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.
1435 ;.org (PC+255) & 0xff00
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
1694 ;----------------------------------------------------------------
1695 ; Lookup table, stolen from z80ex, Z80 emulation library.
1696 ; http://z80ex.sourceforge.net/
1698 ; The S, Z, 5 and 3 bits and the parity of the lookup value
1700 .org (PC+255) & 0xff00
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
1735 ; vim:set ts=8 noet nowrap