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/>.
41 ldi z_pcl,low (IPLADDR)
42 ldi z_pch,high(IPLADDR)
46 printstring "Ok, CPU is live!"
52 cpi z_pch,DBG_TRACE_BOTTOM
54 cpi z_pch,DBG_TRACE_TOP
62 cpi z_pch,DBG_TRACE_BOTTOM
64 cpi z_pch,DBG_TRACE_TOP
79 ;hier kommt die Interruptbehandlung rein
82 mem_read_ds zl,z_pc ;zl = memReadByte(z_pc)
92 ;--------------------------------------------------
93 ; Generate a table entry for one instruction
95 ; instr fetch, op, store
98 .ifndef opcjmp_table_pos_
99 .set todo_table_pos_ = PC
100 ; Place the opcode jump table on the next available location.
101 .equ opcjmp = (PC+255) & 0xff00
102 .set opcjmp_table_pos_ = opcjmp
105 .if todo_table_pos_ < opcjmp + 256 + 128
106 .if todo_table_pos_ + 3 >= opcjmp
107 .set todo_table_pos_ = opcjmp + 256 + 128
110 .set do_@0_@1_@2 = todo_table_pos_ ; make a label
112 .org opcjmp_table_pos_
113 rjmp do_@0_@1_@2 ; generate a jump to the label
114 .set opcjmp_table_pos_ = PC
118 .set fetch_ = (@0 != do_fetch_nop) ; must call or jump to fetch phase
119 .set op_ = (do_@1 != do_op_nop) ; must call or jump to op phase
120 .set store_ = (@2 != do_store_nop) ; must jump to store phase
122 .if fetch_ || op_ || store_ ; something to do
123 .if fetch_ ; must fetch
125 rcall @0 ; fetch and come back here
127 rjmp @0 ; fetch and return to main
130 .if op_ ; must exec op
132 rcall do_@1 ; do op and come back here
134 rjmp do_@1 ; do op and return to main
137 .if store_ ; must store
138 rjmp @2 ; store is allways last
141 ret ; nop, go back to main
144 .set todo_table_pos_ = PC
148 ; ------------ Fetch phase stuff -----------------
150 ;.org (PC+255) & 0xff00
233 mem_read_ds opl, z_pc
238 mem_read_ds opl, z_pc
240 mem_read_ds oph, z_pc
252 ; ------------ Store phase stuff -----------------
254 ;.org (PC+255) & 0xff00
350 printstring "Stack pop "
353 printstring ", SP is now "
370 printstring "Stack push "
373 printstring ", SP is now "
389 ; ------------ Operation phase stuff -----------------
391 ;----------------------------------------------------------------
395 ;| ZZZZZZZ 88888 000 |
401 ;| ZZZZZZZ 88888 000 |
403 ;| Z80 MICROPROCESSOR Instruction Set Summary |
405 ;----------------------------------------------------------------
406 ;----------------------------------------------------------------
407 ;|Mnemonic |SZHPNC|Description |Notes |
408 ;|----------+------+---------------------+----------------------|
409 ;|ADC A,s |***V0*|Add with Carry |A=A+s+CY |
410 ;|ADC HL,ss |**?V0*|Add with Carry |HL=HL+ss+CY |
411 ;|ADD A,s |***V0*|Add |A=A+s |
412 ;|ADD HL,ss |--?-0*|Add |HL=HL+ss |
413 ;|ADD IX,pp |--?-0*|Add |IX=IX+pp |
414 ;|ADD IY,rr |--?-0*|Add |IY=IY+rr |
415 ;|AND s |**1P00|Logical AND |A=A&s |
416 ;|BIT b,m |?*1?0-|Test Bit |m&{2^b} |
417 ;|CALL cc,nn|------|Conditional Call |If cc CALL |
418 ;|CALL nn |------|Unconditional Call |-[SP]=PC,PC=nn |
419 ;|CCF |--?-0*|Complement Carry Flag|CY=~CY |
420 ;|CP s |***V1*|Compare |A-s |
421 ;|CPD |****1-|Compare and Decrement|A-[HL],HL=HL-1,BC=BC-1|
422 ;|CPDR |****1-|Compare, Dec., Repeat|CPD till A=[HL]or BC=0|
423 ;|CPI |****1-|Compare and Increment|A-[HL],HL=HL+1,BC=BC-1|
424 ;|CPIR |****1-|Compare, Inc., Repeat|CPI till A=[HL]or BC=0|
425 ;|CPL |--1-1-|Complement |A=~A |
426 ;|DAA |***P-*|Decimal Adjust Acc. |A=BCD format |
427 ;|DEC s |***V1-|Decrement |s=s-1 |
428 ;|DEC xx |------|Decrement |xx=xx-1 |
429 ;|DEC ss |------|Decrement |ss=ss-1 |
430 ;|DI |------|Disable Interrupts | |
431 ;|DJNZ e |------|Dec., Jump Non-Zero |B=B-1 till B=0 |
432 ;|EI |------|Enable Interrupts | |
433 ;|EX [SP],HL|------|Exchange |[SP]<->HL |
434 ;|EX [SP],xx|------|Exchange |[SP]<->xx |
435 ;|EX AF,AF' |------|Exchange |AF<->AF' |
436 ;|EX DE,HL |------|Exchange |DE<->HL |
437 ;|EXX |------|Exchange |qq<->qq' (except AF)|
438 ;|HALT |------|Halt | |
439 ;|IM n |------|Interrupt Mode | (n=0,1,2)|
440 ;|IN A,[n] |------|Input |A=[n] |
441 ;|IN r,[C] |***P0-|Input |r=[C] |
442 ;|INC r |***V0-|Increment |r=r+1 |
443 ;|INC [HL] |***V0-|Increment |[HL]=[HL]+1 |
444 ;|INC xx |------|Increment |xx=xx+1 |
445 ;|INC [xx+d]|***V0-|Increment |[xx+d]=[xx+d]+1 |
446 ;|INC ss |------|Increment |ss=ss+1 |
447 ;|IND |?*??1-|Input and Decrement |[HL]=[C],HL=HL-1,B=B-1|
448 ;|INDR |?1??1-|Input, Dec., Repeat |IND till B=0 |
449 ;|INI |?*??1-|Input and Increment |[HL]=[C],HL=HL+1,B=B-1|
450 ;|INIR |?1??1-|Input, Inc., Repeat |INI till B=0 |
451 ;|JP [HL] |------|Unconditional Jump |PC=[HL] |
452 ;|JP [xx] |------|Unconditional Jump |PC=[xx] |
453 ;|JP nn |------|Unconditional Jump |PC=nn |
454 ;|JP cc,nn |------|Conditional Jump |If cc JP |
455 ;|JR e |------|Unconditional Jump |PC=PC+e |
456 ;|JR cc,e |------|Conditional Jump |If cc JR(cc=C,NC,NZ,Z)|
457 ;|LD dst,src|------|Load |dst=src |
458 ;|LD A,i |**0*0-|Load |A=i (i=I,R)|
459 ;|LDD |--0*0-|Load and Decrement |[DE]=[HL],HL=HL-1,# |
460 ;|LDDR |--000-|Load, Dec., Repeat |LDD till BC=0 |
461 ;|LDI |--0*0-|Load and Increment |[DE]=[HL],HL=HL+1,# |
462 ;|LDIR |--000-|Load, Inc., Repeat |LDI till BC=0 |
463 ;|NEG |***V1*|Negate |A=-A |
464 ;|NOP |------|No Operation | |
465 ;|OR s |**0P00|Logical inclusive OR |A=Avs |
466 ;|OTDR |?1??1-|Output, Dec., Repeat |OUTD till B=0 |
467 ;|OTIR |?1??1-|Output, Inc., Repeat |OUTI till B=0 |
468 ;|OUT [C],r |------|Output |[C]=r |
469 ;|OUT [n],A |------|Output |[n]=A |
470 ;|OUTD |?*??1-|Output and Decrement |[C]=[HL],HL=HL-1,B=B-1|
471 ;|OUTI |?*??1-|Output and Increment |[C]=[HL],HL=HL+1,B=B-1|
472 ;|POP xx |------|Pop |xx=[SP]+ |
473 ;|POP qq |------|Pop |qq=[SP]+ |
474 ;|PUSH xx |------|Push |-[SP]=xx |
475 ;|PUSH qq |------|Push |-[SP]=qq |
476 ;|RES b,m |------|Reset bit |m=m&{~2^b} |
477 ;|RET |------|Return |PC=[SP]+ |
478 ;|RET cc |------|Conditional Return |If cc RET |
479 ;|RETI |------|Return from Interrupt|PC=[SP]+ |
480 ;|RETN |------|Return from NMI |PC=[SP]+ |
481 ;|RL m |**0P0*|Rotate Left |m={CY,m}<- |
482 ;|RLA |--0-0*|Rotate Left Acc. |A={CY,A}<- |
483 ;|RLC m |**0P0*|Rotate Left Circular |m=m<- |
484 ;|RLCA |--0-0*|Rotate Left Circular |A=A<- |
485 ;|RLD |**0P0-|Rotate Left 4 bits |{A,[HL]}={A,[HL]}<- ##|
486 ;|RR m |**0P0*|Rotate Right |m=->{CY,m} |
487 ;|RRA |--0-0*|Rotate Right Acc. |A=->{CY,A} |
488 ;|RRC m |**0P0*|Rotate Right Circular|m=->m |
489 ;|RRCA |--0-0*|Rotate Right Circular|A=->A |
490 ;|RRD |**0P0-|Rotate Right 4 bits |{A,[HL]}=->{A,[HL]} ##|
491 ;|RST p |------|Restart | (p=0H,8H,10H,...,38H)|
492 ;|SBC A,s |***V1*|Subtract with Carry |A=A-s-CY |
493 ;|SBC HL,ss |**?V1*|Subtract with Carry |HL=HL-ss-CY |
494 ;|SCF |--0-01|Set Carry Flag |CY=1 |
495 ;|SET b,m |------|Set bit |m=mv{2^b} |
496 ;|SLA m |**0P0*|Shift Left Arithmetic|m=m*2 |
497 ;|SRA m |**0P0*|Shift Right Arith. |m=m/2 |
498 ;|SRL m |**0P0*|Shift Right Logical |m=->{0,m,CY} |
499 ;|SUB s |***V1*|Subtract |A=A-s |
500 ;|XOR s |**0P00|Logical Exclusive OR |A=Axs |
501 ;|----------+------+--------------------------------------------|
502 ;| F |-*01? |Flag unaffected/affected/reset/set/unknown |
503 ;| S |S |Sign flag (Bit 7) |
504 ;| Z | Z |Zero flag (Bit 6) |
505 ;| HC | H |Half Carry flag (Bit 4) |
506 ;| P/V | P |Parity/Overflow flag (Bit 2, V=overflow) |
507 ;| N | N |Add/Subtract flag (Bit 1) |
508 ;| CY | C|Carry flag (Bit 0) |
509 ;|-----------------+--------------------------------------------|
510 ;| n |Immediate addressing |
511 ;| nn |Immediate extended addressing |
512 ;| e |Relative addressing (PC=PC+2+offset) |
513 ;| [nn] |Extended addressing |
514 ;| [xx+d] |Indexed addressing |
515 ;| r |Register addressing |
516 ;| [rr] |Register indirect addressing |
517 ;| |Implied addressing |
518 ;| b |Bit addressing |
519 ;| p |Modified page zero addressing (see RST) |
520 ;|-----------------+--------------------------------------------|
521 ;|DEFB n(,...) |Define Byte(s) |
522 ;|DEFB 'str'(,...) |Define Byte ASCII string(s) |
523 ;|DEFS nn |Define Storage Block |
524 ;|DEFW nn(,...) |Define Word(s) |
525 ;|-----------------+--------------------------------------------|
526 ;| A B C D E |Registers (8-bit) |
527 ;| AF BC DE HL |Register pairs (16-bit) |
528 ;| F |Flag register (8-bit) |
529 ;| I |Interrupt page address register (8-bit) |
530 ;| IX IY |Index registers (16-bit) |
531 ;| PC |Program Counter register (16-bit) |
532 ;| R |Memory Refresh register |
533 ;| SP |Stack Pointer register (16-bit) |
534 ;|-----------------+--------------------------------------------|
535 ;| b |One bit (0 to 7) |
536 ;| cc |Condition (C,M,NC,NZ,P,PE,PO,Z) |
537 ;| d |One-byte expression (-128 to +127) |
538 ;| dst |Destination s, ss, [BC], [DE], [HL], [nn] |
539 ;| e |One-byte expression (-126 to +129) |
540 ;| m |Any register r, [HL] or [xx+d] |
541 ;| n |One-byte expression (0 to 255) |
542 ;| nn |Two-byte expression (0 to 65535) |
543 ;| pp |Register pair BC, DE, IX or SP |
544 ;| qq |Register pair AF, BC, DE or HL |
545 ;| qq' |Alternative register pair AF, BC, DE or HL |
546 ;| r |Register A, B, C, D, E, H or L |
547 ;| rr |Register pair BC, DE, IY or SP |
548 ;| s |Any register r, value n, [HL] or [xx+d] |
549 ;| src |Source s, ss, [BC], [DE], [HL], nn, [nn] |
550 ;| ss |Register pair BC, DE, HL or SP |
551 ;| xx |Index register IX or IY |
552 ;|-----------------+--------------------------------------------|
553 ;| + - * / ^ |Add/subtract/multiply/divide/exponent |
554 ;| & ~ v x |Logical AND/NOT/inclusive OR/exclusive OR |
555 ;| <- -> |Rotate left/right |
556 ;| [ ] |Indirect addressing |
557 ;| [ ]+ -[ ] |Indirect addressing auto-increment/decrement|
558 ;| { } |Combination of operands |
559 ;| # |Also BC=BC-1,DE=DE-1 |
560 ;| ## |Only lower 4 bits of accumulator A used |
561 ;----------------------------------------------------------------
563 ;How the flags are supposed to work:
564 ;7 ZFL_S - Sign flag (=MSBit of result)
565 ;6 ZFL_Z - Zero flag. Is 1 when the result is 0
566 ;4 ZFL_H - Half-carry (carry from bit 3 to 4)
567 ;2 ZFL_P - Parity/2-complement Overflow
568 ;1 ZFL_N - Subtract - set if last op was a subtract
571 ;I sure hope I got the mapping between flags and instructions correct...
589 ;------------------------------------------------;
590 ; Load table value from flash indexed by source reg.
592 ; ldpmx dstreg,tablebase,indexreg
594 ; (6 words, 8 cycles)
597 ldi zh,high(@1*2) ; table must be page aligned
602 .macro do_z80_flags_HP
604 bmov z_flags, ZFL_P, temp, AVR_V
605 bmov z_flags, ZFL_H, temp, AVR_H
609 .macro do_z80_flags_set_N
611 ori z_flags, (1<<ZFL_N) ; Negation auf 1
615 .macro do_z80_flags_set_HN
617 ori z_flags,(1<<ZFL_N)|(1<<ZFL_H)
621 .macro do_z80_flags_clear_N
623 andi z_flags,~(1<<ZFL_N)
627 .macro do_z80_flags_op_rotate
628 ; must not change avr carry flag!
630 andi z_flags, ~( (1<<ZFL_H) | (1<<ZFL_N) | (1<<ZFL_C) )
632 andi z_flags, ~( (1<<ZFL_C) )
636 .macro do_z80_flags_op_and
638 ori z_flags,(1<<ZFL_H)
640 ori z_flags,(1<<ZFL_H)
644 .macro do_z80_flags_op_or
650 ;----------------------------------------------------------------
655 printstring "Invalid opcode! "
663 ;----------------------------------------------------------------
664 ;|Mnemonic |SZHPNC|Description |Notes |
665 ;----------------------------------------------------------------
666 ;|OUT [n],A |------|Output |[n]=A |
669 ;Interface with peripherials goes here :)
670 do_op_outa: ; out (opl),a
673 printstring "Port write: "
686 ;----------------------------------------------------------------
687 ;|Mnemonic |SZHPNC|Description |Notes |
688 ;----------------------------------------------------------------
689 ;|IN A,[n] |------|Input |A=[n] |
692 do_op_in: ; in a,(opl)
695 printstring "Port read: ("
711 ;----------------------------------------------------------------
712 ;|Mnemonic |SZHPNC|Description |Notes |
713 ;----------------------------------------------------------------
714 ;|INC r |***V0-|Increment |r=r+1 |
715 ;|INC [HL] |***V0-|Increment |[HL]=[HL]+1 |
716 ;|INC [xx+d]|***V0-|Increment |[xx+d]=[xx+d]+1 |
717 ;|----------|SZHP C|---------- 8080 ----------------------------|
718 ;|INC r |**-P0-|Increment |r=r+1 |
719 ;|INC [HL] |**-P0-|Increment |[HL]=[HL]+1 |
727 andi z_flags,(1<<ZFL_H)|(1<<ZFL_C) ; preserve C-, and H-flag
728 ldpmx temp2, sz53p_tab, opl
738 andi z_flags,(1<<ZFL_H)|(1<<ZFL_C) ; preserve C-, and H-flag
739 ldpmx temp2, sz53p_tab, z_a
744 ;----------------------------------------------------------------
745 ;|Mnemonic |SZHPNC|Description |Notes |
746 ;----------------------------------------------------------------
747 ;|DEC r |***V1-|Decrement |s=s-1 |
748 ;|INC [HL] |***V0-|Increment |[HL]=[HL]+1 |
749 ;|INC [xx+d]|***V0-|Increment |[xx+d]=[xx+d]+1 |
750 ;|----------|SZHP C|---------- 8080 ----------------------------|
751 ;|DEC r |**-P -|Increment |r=r+1 |
752 ;|DEC [HL] |**-P -|Increment |[HL]=[HL]+1 |
760 andi z_flags,(1<<ZFL_H)|(1<<ZFL_C) ; preserve C-, and H-flag
761 ldpmx temp2, sz53p_tab, opl
772 andi z_flags,(1<<ZFL_H)|(1<<ZFL_C) ; preserve C-, and H-flag
773 ldpmx temp2, sz53p_tab, z_a
779 ;----------------------------------------------------------------
780 ;|Mnemonic |SZHPNC|Description |Notes |
781 ;----------------------------------------------------------------
782 ;|INC xx |------|Increment |xx=xx+1 |
783 ;|INC ss |------|Increment |ss=ss+1 |
791 ;----------------------------------------------------------------
792 ;|Mnemonic |SZHPNC|Description |Notes |
793 ;----------------------------------------------------------------
794 ;|DEC xx |------|Decrement |xx=xx-1 |
795 ;|DEC ss |------|Decrement |ss=ss-1 |
803 ;----------------------------------------------------------------
804 ;|Mnemonic |SZHPNC|Description |Notes |
805 ;----------------------------------------------------------------
806 ;|RLCA |--0-0*|Rotate Left Circular |A=A<- |
807 ;|----------|SZHP C|---------- 8080 ----------------------------|
808 ;|RLCA |---- *|Rotate Left Circular |A=A<- |
812 ;Rotate Left Cyclical. All bits move 1 to the
813 ;left, the msb becomes c and lsb.
814 do_z80_flags_op_rotate
818 ori z_flags, (1<<ZFL_C)
822 ;----------------------------------------------------------------
823 ;|Mnemonic |SZHPNC|Description |Notes |
824 ;----------------------------------------------------------------
825 ;|RRCA |--0-0*|Rotate Right Circular|A=->A |
826 ;|----------|SZHP C|---------- 8080 ----------------------------|
827 ;|RRCA |---- *|Rotate Right Circular|A=->A |
831 ;Rotate Right Cyclical. All bits move 1 to the
832 ;right, the lsb becomes c and msb.
833 do_z80_flags_op_rotate
837 ori z_flags, (1<<ZFL_C)
841 ;----------------------------------------------------------------
842 ;|Mnemonic |SZHPNC|Description |Notes |
843 ;----------------------------------------------------------------
844 ;|RRA |--0-0*|Rotate Right Acc. |A=->{CY,A} |
845 ;|----------|SZHP C|---------- 8080 ----------------------------|
846 ;|RRA |---- *|Rotate Right Acc. |A=->{CY,A} |
850 ;Rotate Right. All bits move 1 to the right, the lsb
851 ;becomes c, c becomes msb.
852 clc ; get z80 carry to avr carry
855 do_z80_flags_op_rotate ; (clear ZFL_C, doesn't change AVR_C)
856 bmov z_flags,ZFL_C, opl,0 ; Bit 0 --> CY
860 ;----------------------------------------------------------------
861 ;|Mnemonic |SZHPNC|Description |Notes |
862 ;----------------------------------------------------------------
863 ;|RLA |--0-0*|Rotate Left Acc. |A={CY,A}<- |
864 ;|----------|SZHP C|---------- 8080 ----------------------------|
865 ;|RLA |---- *|Rotate Left Acc. |A={CY,A}<- |
869 ;Rotate Left. All bits move 1 to the left, the msb
870 ;becomes c, c becomes lsb.
874 do_z80_flags_op_rotate ; (clear ZFL_C, doesn't change AVR_C)
875 bmov z_flags,ZFL_C, opl,7 ; Bit 7 --> CY
879 ;----------------------------------------------------------------
880 ;|Mnemonic |SZHPNC|Description |Notes |
881 ;----------------------------------------------------------------
882 ;|ADD A,s |***V0*|Add |A=A+s |
883 ;|----------|SZHP C|---------- 8080 ----------------------------|
884 ;|ADD A,s |***P *|Add |A=A+s |
890 ldpmx z_flags,sz53p_tab,z_a ;S,Z,P flag
891 bmov z_flags,ZFL_C, temp,AVR_C
895 ;----------------------------------------------------------------
896 ;|Mnemonic |SZHPNC|Description |Notes |
897 ;----------------------------------------------------------------
898 ;|ADC A,s |***V0*|Add with Carry |A=A+s+CY |
899 ;|----------|SZHP C|---------- 8080 ----------------------------|
900 ;|ADC A,s |***P *|Add with Carry |A=A+s+CY |
909 ldpmx z_flags,sz53p_tab,z_a ;S,Z,P
910 bmov z_flags,ZFL_C, temp,AVR_C
914 ;----------------------------------------------------------------
915 ;|Mnemonic |SZHPNC|Description |Notes |
916 ;----------------------------------------------------------------
917 ;|SUB s |***V1*|Subtract |A=A-s |
918 ;|----------|SZHP C|---------- 8080 ----------------------------|
919 ;|SUB s |***P *|Subtract |A=A-s |
925 ldpmx z_flags,sz53p_tab,z_a ;S,Z,P
926 bmov z_flags,ZFL_C, temp,AVR_C
931 ;----------------------------------------------------------------
932 ;|Mnemonic |SZHPNC|Description |Notes |
933 ;----------------------------------------------------------------
934 ;|CP s |***V1*|Compare |A-s |
935 ;|----------|SZHP C|---------- 8080 ----------------------------|
936 ;|CP s |***P *|Compare |A-s |
944 ldpmx z_flags,sz53p_tab,opl ;S,Z,P
945 bmov z_flags,ZFL_C, temp,AVR_C
950 ;----------------------------------------------------------------
951 ;|Mnemonic |SZHPNC|Description |Notes |
952 ;----------------------------------------------------------------
953 ;|SBC A,s |***V1*|Subtract with Carry |A=A-s-CY |
954 ;|----------|SZHP C|---------- 8080 ----------------------------|
955 ;|SBC A,s |***P *|Subtract with Carry |A=A-s-CY |
964 ldpmx z_flags,sz53p_tab,z_a ;S,Z,P
965 bmov z_flags,ZFL_C, temp,AVR_C
970 ;----------------------------------------------------------------
971 ;|Mnemonic |SZHPNC|Description |Notes |
972 ;----------------------------------------------------------------
973 ;|AND s |**1P00|Logical AND |A=A&s |
974 ;|----------|SZHP C|---------- 8080 ----------------------------|
975 ;|AND s |**-P 0|Logical AND |A=A&s |
980 ldpmx z_flags,sz53p_tab,z_a ;S,Z,P,N,C
985 ;----------------------------------------------------------------
986 ;|Mnemonic |SZHPNC|Description |Notes |
987 ;----------------------------------------------------------------
988 ;|OR s |**0P00|Logical inclusive OR |A=Avs |
989 ;|----------|SZHP C|---------- 8080 ----------------------------|
990 ;|OR s |**-P00|Logical inclusive OR |A=Avs |
995 ldpmx z_flags,sz53p_tab,z_a ;S,Z,H,P,N,C
999 ;----------------------------------------------------------------
1000 ;|Mnemonic |SZHPNC|Description |Notes |
1001 ;----------------------------------------------------------------
1002 ;|XOR s |**0P00|Logical Exclusive OR |A=Axs |
1003 ;|----------|SZHP C|---------- 8080 ----------------------------|
1004 ;|XOR s |**-P 0|Logical Exclusive OR |A=Axs |
1009 ldpmx z_flags,sz53p_tab,z_a ;S,Z,H,P,N,C
1013 ;----------------------------------------------------------------
1014 ;|Mnemonic |SZHPNC|Description |Notes |
1015 ;----------------------------------------------------------------
1016 ;|ADD HL,ss |--?-0*|Add |HL=HL+ss |
1017 ;|----------|SZHP C|---------- 8080 ----------------------------|
1018 ;|ADD HL,ss |---- *|Add |HL=HL+ss |
1027 bmov z_flags,ZFL_H, temp,AVR_H
1028 bmov z_flags,ZFL_C, temp,AVR_C
1029 do_z80_flags_clear_N
1032 ;----------------------------------------------------------------
1033 ;|Mnemonic |SZHPNC|Description |Notes |
1034 ;----------------------------------------------------------------
1035 ;|LD dst,src|------|Load |dst=src |
1038 do_op_sthl: ;store hl to mem loc in opl:h
1047 ;----------------------------------------------------------------
1048 ;|Mnemonic |SZHPNC|Description |Notes |
1049 ;----------------------------------------------------------------
1050 ;|LD dst,src|------|Load |dst=src |
1060 ;----------------------------------------------------------------
1061 ;|Mnemonic |SZHPNC|Description |Notes |
1062 ;----------------------------------------------------------------
1063 ;|LD dst,src|------|Load |dst=src |
1070 ;----------------------------------------------------------------
1071 ;|Mnemonic |SZHPNC|Description |Notes |
1072 ;----------------------------------------------------------------
1073 ;|DAA |***P-*|Decimal Adjust Acc. | |
1074 ;|----------|SZHP C|---------- 8080 ----------------------------|
1078 ; Description (http://www.z80.info/z80syntx.htm#DAA):
1079 ; This instruction conditionally adjusts the accumulator for BCD addition
1080 ; and subtraction operations. For addition (ADD, ADC, INC) or subtraction
1081 ; (SUB, SBC, DEC, NEC), the following table indicates the operation performed:
1083 ; -------------------------------------------------------------------------------
1084 ; | | C Flag | HEX value in | H Flag | HEX value in | Number | C flag|
1085 ; | Operation| Before | upper digit | Before | lower digit | added | After |
1086 ; | | DAA | (bit 7-4) | DAA | (bit 3-0) | to byte | DAA |
1087 ; |-----------------------------------------------------------------------------|
1088 ; | | 0 | 0-9 | 0 | 0-9 | 00 | 0 |
1089 ; | ADD | 0 | 0-8 | 0 | A-F | 06 | 0 |
1090 ; | | 0 | 0-9 | 1 | 0-3 | 06 | 0 |
1091 ; | ADC | 0 | A-F | 0 | 0-9 | 60 | 1 |
1092 ; | | 0 | 9-F | 0 | A-F | 66 | 1 |
1093 ; | INC | 0 | A-F | 1 | 0-3 | 66 | 1 |
1094 ; | | 1 | 0-2 | 0 | 0-9 | 60 | 1 |
1095 ; | | 1 | 0-2 | 0 | A-F | 66 | 1 |
1096 ; | | 1 | 0-3 | 1 | 0-3 | 66 | 1 |
1097 ; |-----------------------------------------------------------------------------|
1098 ; | SUB | 0 | 0-9 | 0 | 0-9 | 00 | 0 |
1099 ; | SBC | 0 | 0-8 | 1 | 6-F | FA | 0 |
1100 ; | DEC | 1 | 7-F | 0 | 0-9 | A0 | 1 |
1101 ; | NEG | 1 | 6-F | 1 | 6-F | 9A | 1 |
1102 ; |-----------------------------------------------------------------------------|
1105 ; C: See instruction.
1107 ; P/V: Set if Acc. is even parity after operation, reset otherwise.
1108 ; H: See instruction.
1109 ; Z: Set if Acc. is Zero after operation, reset otherwise.
1110 ; S: Set if most significant bit of Acc. is 1 after operation, reset otherwise.
1116 ldi oph,0 ; what to add
1117 sbrc z_flags,ZFL_H ; if H-Flag
1120 andi temp,0x0f ; ... or lower digit > 9
1126 sbrc z_flags,(1<<ZFL_C)
1135 ori z_flags,(1<<ZFL_C); set C
1137 sbrs z_flags,ZFL_N ; if sub-op
1138 rjmp op_da_add ; then
1141 op_da_add: ; else add-op
1154 ori z_flags,(1<<ZFL_C)
1155 andi z_flags,(1<<ZFL_N)|(1<<ZFL_C) ; preserve C,N
1156 ldpmx temp2, sz53p_tab, opl ; get S,Z,P
1158 bmov z_flags,ZFL_H, temp,AVR_H ; H (?)
1163 sbrc z_flags,ZFL_N ; if add-op
1164 rjmp do_op_da_sub ; then
1168 cpi temp,0x0a ; if lower digit > 9
1170 ori temp2,0x06 ; add 6 to lower digit
1172 sbrc z_flags,ZFL_H ; ... or H-Flag
1182 do_op_da_c: ; else sub-op
1183 sbrc z_flags,ZFL_C ;
1185 andi z_flags, ~( (1<<ZFL_S) | (1<<ZFL_Z) | (1<<ZFL_H) )
1188 bst temp,AVR_Z ;Z-Flag
1190 bst temp,AVR_N ;S-Flag
1192 sbrc temp2,5 ;C-Flag, set if 0x06 added
1193 ori z_flags,(1<<ZFL_C) ;
1197 do_op_da_sub: ;TODO:
1202 ;----------------------------------------------------------------
1203 ;|Mnemonic |SZHPNC|Description |Notes |
1204 ;----------------------------------------------------------------
1205 ;|SCF |--0-01|Set Carry Flag |CY=1 |
1206 ;|----------|SZHP C|---------- 8080 ----------------------------|
1210 andi z_flags,~((1<<ZFL_H)|(1<<ZFL_N))
1211 ori z_flags,(1<<ZFL_C)
1214 ;----------------------------------------------------------------
1215 ;|Mnemonic |SZHPNC|Description |Notes |
1216 ;----------------------------------------------------------------
1217 ;|CCF |--?-0*|Complement Carry Flag|CY=~CY |
1218 ;|----------|SZHP C|---------- 8080 ----------------------------|
1219 ;|SCF |---- 1|Set Carry Flag |CY=1 |
1223 do_z80_flags_clear_N
1228 ;----------------------------------------------------------------
1229 ;|Mnemonic |SZHPNC|Description |Notes |
1230 ;----------------------------------------------------------------
1231 ;|CPL |--1-1-|Complement |A=~A |
1232 ;|----------|SZHP C|---------- 8080 ----------------------------|
1233 ;|CPL |---- -|Complement |A=~A |
1242 ;----------------------------------------------------------------
1243 ;|Mnemonic |SZHPNC|Description |Notes |
1244 ;----------------------------------------------------------------
1245 ;|PUSH xx |------|Push |-[SP]=xx |
1246 ;|PUSH qq |------|Push |-[SP]=qq |
1259 printstring "Stack push "
1262 printstring ", SP is now "
1270 ;----------------------------------------------------------------
1271 ;|Mnemonic |SZHPNC|Description |Notes |
1272 ;----------------------------------------------------------------
1273 ;|POP xx |------|Pop |xx=[SP]+ |
1274 ;|POP qq |------|Pop |qq=[SP]+ |
1287 printstring "Stack pop "
1290 printstring ", SP is now "
1297 ;----------------------------------------------------------------
1298 ;|Mnemonic |SZHPNC|Description |Notes |
1299 ;----------------------------------------------------------------
1300 ;|EX [SP],HL|------|Exchange |[SP]<->HL |
1301 ;|EX DE,HL |------|Exchange |DE<->HL |
1302 ;-----------------------------Z80--------------------------------
1312 ;----------------------------------------------------------------
1313 ;|Mnemonic |SZHPNC|Description |Notes |
1314 ;----------------------------------------------------------------
1316 ; TODO: Implement IFF1, IFF2
1320 ;----------------------------------------------------------------
1321 ;|Mnemonic |SZHPNC|Description |Notes |
1322 ;----------------------------------------------------------------
1324 ; TODO: Implement IFF1, IFF2
1328 ;----------------------------------------------------------------
1329 ;|Mnemonic |SZHPNC|Description |Notes |
1330 ;----------------------------------------------------------------
1331 ;|CALL cc,nn|------|Conditional Call |If cc CALL |
1332 ;|JP cc,nn |------|Conditional Jump |If cc JP |
1333 ;|RET cc |------|Conditional Return |If cc RET |
1340 pop temp ; direkt zuruech zu main
1343 ;----------------------------------------------------------------
1344 ;|Mnemonic |SZHPNC|Description |Notes |
1345 ;----------------------------------------------------------------
1346 ;|CALL cc,nn|------|Conditional Call |If cc CALL |
1347 ;|JP cc,nn |------|Conditional Jump |If cc JP |
1348 ;|RET cc |------|Conditional Return |If cc RET |
1355 pop temp ; direkt zuruech zu main
1358 ;----------------------------------------------------------------
1359 ;|Mnemonic |SZHPNC|Description |Notes |
1360 ;----------------------------------------------------------------
1361 ;|CALL cc,nn|------|Conditional Call |If cc CALL |
1362 ;|JP cc,nn |------|Conditional Jump |If cc JP |
1363 ;|RET cc |------|Conditional Return |If cc RET |
1370 pop temp ; direkt zuruech zu main
1373 ;----------------------------------------------------------------
1374 ;|Mnemonic |SZHPNC|Description |Notes |
1375 ;----------------------------------------------------------------
1376 ;|CALL cc,nn|------|Conditional Call |If cc CALL |
1377 ;|JP cc,nn |------|Conditional Jump |If cc JP |
1378 ;|RET cc |------|Conditional Return |If cc RET |
1385 pop temp ; direkt zuruech zu main
1388 ;----------------------------------------------------------------
1389 ;|Mnemonic |SZHPNC|Description |Notes |
1390 ;----------------------------------------------------------------
1391 ;|CALL cc,nn|------|Conditional Call |If cc CALL |
1392 ;|JP cc,nn |------|Conditional Jump |If cc JP |
1393 ;|RET cc |------|Conditional Return |If cc RET |
1400 pop temp ; direkt zuruech zu main
1403 ;----------------------------------------------------------------
1404 ;|Mnemonic |SZHPNC|Description |Notes |
1405 ;----------------------------------------------------------------
1406 ;|CALL cc,nn|------|Conditional Call |If cc CALL |
1407 ;|JP cc,nn |------|Conditional Jump |If cc JP |
1408 ;|RET cc |------|Conditional Return |If cc RET |
1415 pop temp ; direkt zuruech zu main
1418 ;----------------------------------------------------------------
1419 ;|Mnemonic |SZHPNC|Description |Notes |
1420 ;----------------------------------------------------------------
1421 ;|CALL cc,nn|------|Conditional Call |If cc CALL |
1422 ;|JP cc,nn |------|Conditional Jump |If cc JP |
1423 ;|RET cc |------|Conditional Return |If cc RET |
1426 do_op_ifp: ;sign positive, aka s=0
1430 pop temp ; direkt zuruech zu main
1433 ;----------------------------------------------------------------
1434 ;|Mnemonic |SZHPNC|Description |Notes |
1435 ;----------------------------------------------------------------
1436 ;|CALL cc,nn|------|Conditional Call |If cc CALL |
1437 ;|JP cc,nn |------|Conditional Jump |If cc JP |
1438 ;|RET cc |------|Conditional Return |If cc RET |
1441 do_op_ifm: ;sign negative, aka s=1
1445 pop temp ; direkt zuruech zu main
1449 ; ----------------------- Opcode decoding -------------------------
1451 ; Lookup table for Z80 opcodes. Translates the first byte of the instruction word into three
1452 ; operations: fetch, do something, store.
1453 ; The table is made of 256 words.
1455 ; .org (PC+255) & 0xff00
1459 instr do_fetch_nop, op_nop, do_store_nop ;00 ;NOP
1460 instr do_fetch_DIR16, op_nop, do_store_BC ;01 nn nn ;LD BC,nn
1461 instr do_fetch_A, op_nop, do_store_MBC ;02 ;LD (BC),A
1462 instr do_fetch_BC, op_INC16, do_store_BC ;03 ;INC BC
1463 instr do_fetch_B, op_INC, do_store_B ;04 ;INC B
1464 instr do_fetch_B, op_DEC, do_store_B ;05 ;DEC B
1465 instr do_fetch_DIR8, op_nop, do_store_B ;06 ;LD B,n
1466 instr do_fetch_A, op_RLC, do_store_A ;07 ;RLCA
1467 instr do_fetch_nop, op_INV, do_store_nop ;08 ;EX AF,AF'
1468 instr do_fetch_BC, op_ADDHL, do_store_HL ;09 ;ADD HL,BC
1469 instr do_fetch_MBC, op_nop, do_store_A ;0A ;LD A,(BC)
1470 instr do_fetch_BC, op_DEC16, do_store_BC ;0B ;DEC BC
1471 instr do_fetch_C, op_INC, do_store_C ;0C ;INC C
1472 instr do_fetch_C, op_DEC, do_store_C ;0D ;DEC C
1473 instr do_fetch_DIR8, op_nop, do_store_C ;0E nn ;LD C,n
1474 instr do_fetch_A, op_RRC, do_store_A ;0F ;RRCA
1475 instr do_fetch_nop, op_INV, do_store_nop ;10 oo ;DJNZ o
1476 instr do_fetch_DIR16, op_nop, do_store_DE ;11 nn nn ;LD DE,nn
1477 instr do_fetch_A, op_nop, do_store_MDE ;12 ;LD (DE),A
1478 instr do_fetch_DE, op_INC16, do_store_DE ;13 ;INC DE
1479 instr do_fetch_D, op_INC, do_store_D ;14 ;INC D
1480 instr do_fetch_D, op_DEC, do_store_D ;15 ;DEC D
1481 instr do_fetch_DIR8, op_nop, do_store_D ;16 nn ;LD D,n
1482 instr do_fetch_A, op_RL, do_store_A ;17 ;RLA
1483 instr do_fetch_nop, op_INV, do_store_nop ;18 oo ;JR o
1484 instr do_fetch_DE, op_ADDHL, do_store_HL ;19 ;ADD HL,DE
1485 instr do_fetch_MDE, op_nop, do_store_A ;1A ;LD A,(DE)
1486 instr do_fetch_DE, op_DEC16, do_store_DE ;1B ;DEC DE
1487 instr do_fetch_E, op_INC, do_store_E ;1C ;INC E
1488 instr do_fetch_E, op_DEC, do_store_E ;1D ;DEC E
1489 instr do_fetch_DIR8, op_nop, do_store_E ;1E nn ;LD E,n
1490 instr do_fetch_A, op_RR, do_store_A ;1F ;RRA
1491 instr do_fetch_nop, op_INV, do_store_nop ;20 oo ;JR NZ,o
1492 instr do_fetch_DIR16, op_nop, do_store_HL ;21 nn nn ;LD HL,nn
1493 instr do_fetch_DIR16, op_STHL, do_store_nop ;22 nn nn ;LD (nn),HL
1494 instr do_fetch_HL, op_INC16, do_store_HL ;23 ;INC HL
1495 instr do_fetch_H, op_INC, do_store_H ;24 ;INC H
1496 instr do_fetch_H, op_DEC, do_store_H ;25 ;DEC H
1497 instr do_fetch_DIR8, op_nop, do_store_H ;26 nn ;LD H,n
1498 instr do_fetch_A, op_DA, do_store_A ;27 ;DAA
1499 instr do_fetch_nop, op_INV, do_store_nop ;28 oo ;JR Z,o
1500 instr do_fetch_HL, op_ADDHL, do_store_HL ;29 ;ADD HL,HL
1501 instr do_fetch_DIR16, op_RMEM16, do_store_HL ;2A nn nn ;LD HL,(nn)
1502 instr do_fetch_HL, op_DEC16, do_store_HL ;2B ;DEC HL
1503 instr do_fetch_L, op_INC, do_store_L ;2C ;INC L
1504 instr do_fetch_L, op_DEC, do_store_L ;2D ;DEC L
1505 instr do_fetch_DIR8, op_nop, do_store_L ;2E nn ;LD L,n
1506 instr do_fetch_nop, op_CPL, do_store_nop ;2F ;CPL
1507 instr do_fetch_nop, op_INV, do_store_nop ;30 oo ;JR NC,o
1508 instr do_fetch_DIR16, op_nop, do_store_SP ;31 nn nn ;LD SP,nn
1509 instr do_fetch_DIR16, op_nop, do_store_AM ;32 nn nn ;LD (nn),A
1510 instr do_fetch_SP, op_INC16, do_store_SP ;33 ;INC SP
1511 instr do_fetch_MHL, op_INC, do_store_MHL ;34 ;INC (HL)
1512 instr do_fetch_MHL, op_DEC, do_store_MHL ;35 ;DEC (HL)
1513 instr do_fetch_DIR8, op_nop, do_store_MHL ;36 nn ;LD (HL),n
1514 instr do_fetch_nop, op_SCF, do_store_nop ;37 ;SCF
1515 instr do_fetch_nop, op_INV, do_store_nop ;38 oo ;JR C,o
1516 instr do_fetch_SP, op_ADDHL, do_store_HL ;39 ;ADD HL,SP
1517 instr do_fetch_DIR16, op_RMEM8, do_store_A ;3A nn nn ;LD A,(nn)
1518 instr do_fetch_SP, op_DEC16, do_store_SP ;3B ;DEC SP
1519 instr do_fetch_nop, op_INCA, do_store_nop ;3C ;INC A
1520 instr do_fetch_nop, op_DECA, do_store_nop ;3D ;DEC A
1521 instr do_fetch_DIR8, op_nop, do_store_A ;3E nn ;LD A,n
1522 instr do_fetch_nop, op_CCF, do_store_nop ;3F ;CCF (Complement Carry Flag, gvd)
1523 instr do_fetch_B, op_nop, do_store_B ;40 ;LD B,B
1524 instr do_fetch_C, op_nop, do_store_B ;41 ;LD B,C
1525 instr do_fetch_D, op_nop, do_store_B ;42 ;LD B,D
1526 instr do_fetch_E, op_nop, do_store_B ;43 ;LD B,E
1527 instr do_fetch_H, op_nop, do_store_B ;44 ;LD B,H
1528 instr do_fetch_L, op_nop, do_store_B ;45 ;LD B,L
1529 instr do_fetch_MHL, op_nop, do_store_B ;46 ;LD B,(HL)
1530 instr do_fetch_A, op_nop, do_store_B ;47 ;LD B,A
1531 instr do_fetch_B, op_nop, do_store_C ;48 ;LD C,B
1532 instr do_fetch_C, op_nop, do_store_C ;49 ;LD C,C
1533 instr do_fetch_D, op_nop, do_store_C ;4A ;LD C,D
1534 instr do_fetch_E, op_nop, do_store_C ;4B ;LD C,E
1535 instr do_fetch_H, op_nop, do_store_C ;4C ;LD C,H
1536 instr do_fetch_L, op_nop, do_store_C ;4D ;LD C,L
1537 instr do_fetch_MHL, op_nop, do_store_C ;4E ;LD C,(HL)
1538 instr do_fetch_A, op_nop, do_store_C ;4F ;LD C,A
1539 instr do_fetch_B, op_nop, do_store_D ;50 ;LD D,B
1540 instr do_fetch_C, op_nop, do_store_D ;51 ;LD D,C
1541 instr do_fetch_D, op_nop, do_store_D ;52 ;LD D,D
1542 instr do_fetch_E, op_nop, do_store_D ;53 ;LD D,E
1543 instr do_fetch_H, op_nop, do_store_D ;54 ;LD D,H
1544 instr do_fetch_L, op_nop, do_store_D ;55 ;LD D,L
1545 instr do_fetch_MHL, op_nop, do_store_D ;56 ;LD D,(HL)
1546 instr do_fetch_A, op_nop, do_store_D ;57 ;LD D,A
1547 instr do_fetch_B, op_nop, do_store_E ;58 ;LD E,B
1548 instr do_fetch_C, op_nop, do_store_E ;59 ;LD E,C
1549 instr do_fetch_D, op_nop, do_store_E ;5A ;LD E,D
1550 instr do_fetch_E, op_nop, do_store_E ;5B ;LD E,E
1551 instr do_fetch_H, op_nop, do_store_E ;5C ;LD E,H
1552 instr do_fetch_L, op_nop, do_store_E ;5D ;LD E,L
1553 instr do_fetch_MHL, op_nop, do_store_E ;5E ;LD E,(HL)
1554 instr do_fetch_A, op_nop, do_store_E ;5F ;LD E,A
1555 instr do_fetch_B, op_nop, do_store_H ;60 ;LD H,B
1556 instr do_fetch_C, op_nop, do_store_H ;61 ;LD H,C
1557 instr do_fetch_D, op_nop, do_store_H ;62 ;LD H,D
1558 instr do_fetch_E, op_nop, do_store_H ;63 ;LD H,E
1559 instr do_fetch_H, op_nop, do_store_H ;64 ;LD H,H
1560 instr do_fetch_L, op_nop, do_store_H ;65 ;LD H,L
1561 instr do_fetch_MHL, op_nop, do_store_H ;66 ;LD H,(HL)
1562 instr do_fetch_A, op_nop, do_store_H ;67 ;LD H,A
1563 instr do_fetch_B, op_nop, do_store_L ;68 ;LD L,B
1564 instr do_fetch_C, op_nop, do_store_L ;69 ;LD L,C
1565 instr do_fetch_D, op_nop, do_store_L ;6A ;LD L,D
1566 instr do_fetch_E, op_nop, do_store_L ;6B ;LD L,E
1567 instr do_fetch_H, op_nop, do_store_L ;6C ;LD L,H
1568 instr do_fetch_L, op_nop, do_store_L ;6D ;LD L,L
1569 instr do_fetch_MHL, op_nop, do_store_L ;6E ;LD L,(HL)
1570 instr do_fetch_A, op_nop, do_store_L ;6F ;LD L,A
1571 instr do_fetch_B, op_nop, do_store_MHL ;70 ;LD (HL),B
1572 instr do_fetch_C, op_nop, do_store_MHL ;71 ;LD (HL),C
1573 instr do_fetch_D, op_nop, do_store_MHL ;72 ;LD (HL),D
1574 instr do_fetch_E, op_nop, do_store_MHL ;73 ;LD (HL),E
1575 instr do_fetch_H, op_nop, do_store_MHL ;74 ;LD (HL),H
1576 instr do_fetch_L, op_nop, do_store_MHL ;75 ;LD (HL),L
1577 instr do_fetch_nop, op_INV, do_store_nop ;76 ;HALT
1578 instr do_fetch_A, op_nop, do_store_MHL ;77 ;LD (HL),A
1579 instr do_fetch_B, op_nop, do_store_A ;78 ;LD A,B
1580 instr do_fetch_C, op_nop, do_store_A ;79 ;LD A,C
1581 instr do_fetch_D, op_nop, do_store_A ;7A ;LD A,D
1582 instr do_fetch_E, op_nop, do_store_A ;7B ;LD A,E
1583 instr do_fetch_H, op_nop, do_store_A ;7C ;LD A,H
1584 instr do_fetch_L, op_nop, do_store_A ;7D ;LD A,L
1585 instr do_fetch_MHL, op_nop, do_store_A ;7E ;LD A,(HL)
1586 instr do_fetch_A, op_nop, do_store_A ;7F ;LD A,A
1587 instr do_fetch_B, op_ADDA, do_store_nop ;80 ;ADD A,B
1588 instr do_fetch_C, op_ADDA, do_store_nop ;81 ;ADD A,C
1589 instr do_fetch_D, op_ADDA, do_store_nop ;82 ;ADD A,D
1590 instr do_fetch_E, op_ADDA, do_store_nop ;83 ;ADD A,E
1591 instr do_fetch_H, op_ADDA, do_store_nop ;84 ;ADD A,H
1592 instr do_fetch_L, op_ADDA, do_store_nop ;85 ;ADD A,L
1593 instr do_fetch_MHL, op_ADDA, do_store_nop ;86 ;ADD A,(HL)
1594 instr do_fetch_A, op_ADDA, do_store_nop ;87 ;ADD A,A
1595 instr do_fetch_B, op_ADCA, do_store_nop ;88 ;ADC A,B
1596 instr do_fetch_C, op_ADCA, do_store_nop ;89 ;ADC A,C
1597 instr do_fetch_D, op_ADCA, do_store_nop ;8A ;ADC A,D
1598 instr do_fetch_E, op_ADCA, do_store_nop ;8B ;ADC A,E
1599 instr do_fetch_H, op_ADCA, do_store_nop ;8C ;ADC A,H
1600 instr do_fetch_L, op_ADCA, do_store_nop ;8D ;ADC A,L
1601 instr do_fetch_MHL, op_ADCA, do_store_nop ;8E ;ADC A,(HL)
1602 instr do_fetch_A, op_ADCA, do_store_nop ;8F ;ADC A,A
1603 instr do_fetch_B, op_SUBFA, do_store_nop ;90 ;SUB A,B
1604 instr do_fetch_C, op_SUBFA, do_store_nop ;91 ;SUB A,C
1605 instr do_fetch_D, op_SUBFA, do_store_nop ;92 ;SUB A,D
1606 instr do_fetch_E, op_SUBFA, do_store_nop ;93 ;SUB A,E
1607 instr do_fetch_H, op_SUBFA, do_store_nop ;94 ;SUB A,H
1608 instr do_fetch_L, op_SUBFA, do_store_nop ;95 ;SUB A,L
1609 instr do_fetch_MHL, op_SUBFA, do_store_nop ;96 ;SUB A,(HL)
1610 instr do_fetch_A, op_SUBFA, do_store_nop ;97 ;SUB A,A
1611 instr do_fetch_B, op_SBCFA, do_store_nop ;98 ;SBC A,B
1612 instr do_fetch_C, op_SBCFA, do_store_nop ;99 ;SBC A,C
1613 instr do_fetch_D, op_SBCFA, do_store_nop ;9A ;SBC A,D
1614 instr do_fetch_E, op_SBCFA, do_store_nop ;9B ;SBC A,E
1615 instr do_fetch_H, op_SBCFA, do_store_nop ;9C ;SBC A,H
1616 instr do_fetch_L, op_SBCFA, do_store_nop ;9D ;SBC A,L
1617 instr do_fetch_MHL, op_SBCFA, do_store_nop ;9E ;SBC A,(HL)
1618 instr do_fetch_A, op_SBCFA, do_store_nop ;9F ;SBC A,A
1619 instr do_fetch_B, op_ANDA, do_store_nop ;A0 ;AND A,B
1620 instr do_fetch_C, op_ANDA, do_store_nop ;A1 ;AND A,C
1621 instr do_fetch_D, op_ANDA, do_store_nop ;A2 ;AND A,D
1622 instr do_fetch_E, op_ANDA, do_store_nop ;A3 ;AND A,E
1623 instr do_fetch_H, op_ANDA, do_store_nop ;A4 ;AND A,H
1624 instr do_fetch_L, op_ANDA, do_store_nop ;A5 ;AND A,L
1625 instr do_fetch_MHL, op_ANDA, do_store_nop ;A6 ;AND A,(HL)
1626 instr do_fetch_A, op_ANDA, do_store_nop ;A7 ;AND A,A
1627 instr do_fetch_B, op_XORA, do_store_nop ;A8 ;XOR A,B
1628 instr do_fetch_C, op_XORA, do_store_nop ;A9 ;XOR A,C
1629 instr do_fetch_D, op_XORA, do_store_nop ;AA ;XOR A,D
1630 instr do_fetch_E, op_XORA, do_store_nop ;AB ;XOR A,E
1631 instr do_fetch_H, op_XORA, do_store_nop ;AC ;XOR A,H
1632 instr do_fetch_L, op_XORA, do_store_nop ;AD ;XOR A,L
1633 instr do_fetch_MHL, op_XORA, do_store_nop ;AE ;XOR A,(HL)
1634 instr do_fetch_A, op_XORA, do_store_nop ;AF ;XOR A,A
1635 instr do_fetch_B, op_ORA, do_store_nop ;B0 ;OR A,B
1636 instr do_fetch_C, op_ORA, do_store_nop ;B1 ;OR A,C
1637 instr do_fetch_D, op_ORA, do_store_nop ;B2 ;OR A,D
1638 instr do_fetch_E, op_ORA, do_store_nop ;B3 ;OR A,E
1639 instr do_fetch_H, op_ORA, do_store_nop ;B4 ;OR A,H
1640 instr do_fetch_L, op_ORA, do_store_nop ;B5 ;OR A,L
1641 instr do_fetch_MHL, op_ORA, do_store_nop ;B6 ;OR A,(HL)
1642 instr do_fetch_A, op_ORA, do_store_nop ;B7 ;OR A,A
1643 instr do_fetch_B, op_CPFA, do_store_nop ;B8 ;CP A,B
1644 instr do_fetch_C, op_CPFA, do_store_nop ;B9 ;CP A,C
1645 instr do_fetch_D, op_CPFA, do_store_nop ;BA ;CP A,D
1646 instr do_fetch_E, op_CPFA, do_store_nop ;BB ;CP A,E
1647 instr do_fetch_H, op_CPFA, do_store_nop ;BC ;CP A,H
1648 instr do_fetch_L, op_CPFA, do_store_nop ;BD ;CP A,L
1649 instr do_fetch_MHL, op_CPFA, do_store_nop ;BE ;CP A,(HL)
1650 instr do_fetch_A, op_CPFA, do_store_nop ;BF ;CP A,A
1651 instr do_fetch_nop, op_IFNZ, do_store_RET ;C0 ;RET NZ
1652 instr do_fetch_nop, op_POP16, do_store_BC ;C1 ;POP BC
1653 instr do_fetch_DIR16, op_IFNZ, do_store_PC ;C2 nn nn ;JP NZ,nn
1654 instr do_fetch_DIR16, op_nop, do_store_PC ;C3 nn nn ;JP nn
1655 instr do_fetch_DIR16, op_IFNZ, do_store_CALL ;C4 nn nn ;CALL NZ,nn
1656 instr do_fetch_BC, op_PUSH16, do_store_nop ;C5 ;PUSH BC
1657 instr do_fetch_DIR8, op_ADDA, do_store_nop ;C6 nn ;ADD A,n
1658 instr do_fetch_RST, op_nop, do_store_CALL ;C7 ;RST 0
1659 instr do_fetch_nop, op_IFZ, do_store_RET ;C8 ;RET Z
1660 instr do_fetch_nop, op_nop, do_store_RET ;C9 ;RET
1661 instr do_fetch_DIR16, op_IFZ, do_store_PC ;CA nn nn ;JP Z,nn
1662 instr do_fetch_nop, op_INV, do_store_nop ;CB ;(Z80 specific)
1663 instr do_fetch_DIR16, op_IFZ, do_store_CALL ;CC nn nn ;CALL Z,nn
1664 instr do_fetch_DIR16, op_nop, do_store_CALL ;CD nn nn ;CALL nn
1665 instr do_fetch_DIR8, op_ADCA, do_store_nop ;CE nn ;ADC A,n
1666 instr do_fetch_RST, op_nop, do_store_CALL ;CF ;RST 8H
1667 instr do_fetch_nop, op_IFNC, do_store_RET ;D0 ;RET NC
1668 instr do_fetch_nop, op_POP16, do_store_DE ;D1 ;POP DE
1669 instr do_fetch_DIR16, op_IFNC, do_store_PC ;D2 nn nn ;JP NC,nn
1670 instr do_fetch_DIR8, op_OUTA, do_store_nop ;D3 nn ;OUT (n),A
1671 instr do_fetch_DIR16, op_IFNC, do_store_CALL ;D4 nn nn ;CALL NC,nn
1672 instr do_fetch_DE, op_PUSH16, do_store_nop ;D5 ;PUSH DE
1673 instr do_fetch_DIR8, op_SUBFA, do_store_nop ;D6 nn ;SUB n
1674 instr do_fetch_RST, op_nop, do_store_CALL ;D7 ;RST 10H
1675 instr do_fetch_nop, op_IFC, do_store_RET ;D8 ;RET C
1676 instr do_fetch_nop, op_nop, do_store_nop ;D9 ;EXX
1677 instr do_fetch_DIR16, op_IFC, do_store_PC ;DA nn nn ;JP C,nn
1678 instr do_fetch_DIR8, op_IN, do_store_A ;DB nn ;IN A,(n)
1679 instr do_fetch_DIR16, op_IFC, do_store_CALL ;DC nn nn ;CALL C,nn
1680 instr do_fetch_nop, op_INV, do_store_nop ;DD ;(Z80 specific)
1681 instr do_fetch_DIR8, op_SBCFA, do_store_nop ;DE nn ;SBC A,n
1682 instr do_fetch_RST, op_nop, do_store_CALL ;DF ;RST 18H
1683 instr do_fetch_nop, op_IFPO, do_store_RET ;E0 ;RET PO
1684 instr do_fetch_nop, op_POP16, do_store_HL ;E1 ;POP HL
1685 instr do_fetch_DIR16, op_IFPO, do_store_PC ;E2 nn nn ;JP PO,nn
1686 instr do_fetch_MSP, op_EXHL, do_store_MSP ;E3 ;EX (SP),HL
1687 instr do_fetch_DIR16, op_IFPO, do_store_CALL ;E4 nn nn ;CALL PO,nn
1688 instr do_fetch_HL, op_PUSH16, do_store_nop ;E5 ;PUSH HL
1689 instr do_fetch_DIR8, op_ANDA, do_store_nop ;E6 nn ;AND n
1690 instr do_fetch_RST, op_nop, do_store_CALL ;E7 ;RST 20H
1691 instr do_fetch_nop, op_IFPE, do_store_RET ;E8 ;RET PE
1692 instr do_fetch_HL, op_nop, do_store_PC ;E9 ;JP HL
1693 instr do_fetch_DIR16, op_IFPE, do_store_PC ;EA nn nn ;JP PE,nn
1694 instr do_fetch_DE, op_EXHL, do_store_DE ;EB ;EX DE,HL
1695 instr do_fetch_DIR16, op_IFPE, do_store_CALL ;EC nn nn ;CALL PE,nn
1696 instr do_fetch_nop, op_INV, do_store_nop ;ED ;(Z80 specific)
1697 instr do_fetch_DIR8, op_XORA, do_store_nop ;EE nn ;XOR n
1698 instr do_fetch_RST, op_nop, do_store_CALL ;EF ;RST 28H
1699 instr do_fetch_nop, op_IFP, do_store_RET ;F0 ;RET P
1700 instr do_fetch_nop, op_POP16, do_store_AF ;F1 ;POP AF
1701 instr do_fetch_DIR16, op_IFP, do_store_PC ;F2 nn nn ;JP P,nn
1702 instr do_fetch_nop, op_DI, do_store_nop ;F3 ;DI
1703 instr do_fetch_DIR16, op_IFP, do_store_CALL ;F4 nn nn ;CALL P,nn
1704 instr do_fetch_AF, op_PUSH16, do_store_nop ;F5 ;PUSH AF
1705 instr do_fetch_DIR8, op_ORA, do_store_nop ;F6 nn ;OR n
1706 instr do_fetch_RST, op_nop, do_store_CALL ;F7 ;RST 30H
1707 instr do_fetch_nop, op_IFM, do_store_RET ;F8 ;RET M
1708 instr do_fetch_HL, op_nop, do_store_SP ;F9 ;LD SP,HL
1709 instr do_fetch_DIR16, op_IFM, do_store_PC ;FA nn nn ;JP M,nn
1710 instr do_fetch_nop, op_EI, do_store_nop ;FB ;EI
1711 instr do_fetch_DIR16, op_IFM, do_store_CALL ;FC nn nn ;CALL M,nn
1712 instr do_fetch_nop, op_INV, do_store_nop ;FD ;(Z80 specific)
1713 instr do_fetch_DIR8, op_CPFA, do_store_nop ;FE nn ;CP n
1714 instr do_fetch_RST, op_nop, do_store_CALL ;FF ;RST 38H
1717 ;----------------------------------------------------------------
1718 ; Lookup table, stolen from z80ex, Z80 emulation library.
1719 ; http://z80ex.sourceforge.net/
1721 ; The S, Z, 5 and 3 bits and the parity of the lookup value
1723 ; .org (PC+255) & 0xff00
1726 .db 0x44,0x00,0x00,0x04,0x00,0x04,0x04,0x00
1727 .db 0x08,0x0c,0x0c,0x08,0x0c,0x08,0x08,0x0c
1728 .db 0x00,0x04,0x04,0x00,0x04,0x00,0x00,0x04
1729 .db 0x0c,0x08,0x08,0x0c,0x08,0x0c,0x0c,0x08
1730 .db 0x20,0x24,0x24,0x20,0x24,0x20,0x20,0x24
1731 .db 0x2c,0x28,0x28,0x2c,0x28,0x2c,0x2c,0x28
1732 .db 0x24,0x20,0x20,0x24,0x20,0x24,0x24,0x20
1733 .db 0x28,0x2c,0x2c,0x28,0x2c,0x28,0x28,0x2c
1734 .db 0x00,0x04,0x04,0x00,0x04,0x00,0x00,0x04
1735 .db 0x0c,0x08,0x08,0x0c,0x08,0x0c,0x0c,0x08
1736 .db 0x04,0x00,0x00,0x04,0x00,0x04,0x04,0x00
1737 .db 0x08,0x0c,0x0c,0x08,0x0c,0x08,0x08,0x0c
1738 .db 0x24,0x20,0x20,0x24,0x20,0x24,0x24,0x20
1739 .db 0x28,0x2c,0x2c,0x28,0x2c,0x28,0x28,0x2c
1740 .db 0x20,0x24,0x24,0x20,0x24,0x20,0x20,0x24
1741 .db 0x2c,0x28,0x28,0x2c,0x28,0x2c,0x2c,0x28
1742 .db 0x80,0x84,0x84,0x80,0x84,0x80,0x80,0x84
1743 .db 0x8c,0x88,0x88,0x8c,0x88,0x8c,0x8c,0x88
1744 .db 0x84,0x80,0x80,0x84,0x80,0x84,0x84,0x80
1745 .db 0x88,0x8c,0x8c,0x88,0x8c,0x88,0x88,0x8c
1746 .db 0xa4,0xa0,0xa0,0xa4,0xa0,0xa4,0xa4,0xa0
1747 .db 0xa8,0xac,0xac,0xa8,0xac,0xa8,0xa8,0xac
1748 .db 0xa0,0xa4,0xa4,0xa0,0xa4,0xa0,0xa0,0xa4
1749 .db 0xac,0xa8,0xa8,0xac,0xa8,0xac,0xac,0xa8
1750 .db 0x84,0x80,0x80,0x84,0x80,0x84,0x84,0x80
1751 .db 0x88,0x8c,0x8c,0x88,0x8c,0x88,0x88,0x8c
1752 .db 0x80,0x84,0x84,0x80,0x84,0x80,0x80,0x84
1753 .db 0x8c,0x88,0x88,0x8c,0x88,0x8c,0x8c,0x88
1754 .db 0xa0,0xa4,0xa4,0xa0,0xa4,0xa0,0xa0,0xa4
1755 .db 0xac,0xa8,0xa8,0xac,0xa8,0xac,0xac,0xa8
1756 .db 0xa4,0xa0,0xa0,0xa4,0xa0,0xa4,0xa4,0xa0
1757 .db 0xa8,0xac,0xac,0xa8,0xac,0xa8,0xa8,0xac
1759 ; vim:set ts=8 noet nowrap