home *** CD-ROM | disk | FTP | other *** search
- ** The undocumented Z80 instructions
- **
- ** (Except "In xx,(C)" and "Out (C),xx" which are in impldept.i, and
- ** the rotate/shift/set/reset operations on IX/IY with autocopy to
- ** a register are moved to distant.i.)
- **
- ** ----------------------------------------------------------------------
-
- IFD VERBOSE
- LIST
- ** Compiling the undoc_instr.i file.
- NOLIST
- ENDC
-
- IFND UNDOCINSTR_UNDEF
-
- IFD VERBOSE
- LIST
- ** Compiling routines for the "undocumented" instructions.
- NOLIST
- ENDC
-
- ** Let the undocumented cases of Neg and Retn use the "real" routines
- ** (they all have the same opcode form):
- undoc_neg = Neg-InstrBase
- undoc_retn = Retn-InstrBase
-
- ** Create actual routines for the "undocumented"-labels:
-
- adc_A_xyHL MACRO
- Adc_A_\1 opcode_2_bytes
- move.b Z80_\1(TableB),d7
- IFD BCDFLAGS
- move.b A,Z80_BCD_A(TableB) ;BCD_A=A
- move.b d7,Z80_BCD_B(TableB) ;BCD_B=register
- move.w d6,Z80_BCD_C(TableB) ;BCD_C=carry
- move.w #OP_ADC,Z80_BCD_OP(TableB) ;BCD_OP=adc
- ENDC
- lsr.w #1,d6 ;carry to X
- ori #4,CCR ;set Z
- addx.b d7,A
- putsr d6
- skip 1
- next
- ENDM
- adc_A_xyHL XH
- adc_A_xyHL XL
- adc_A_xyHL YH
- adc_A_xyHL YL
- ** --
- add_A_xyHL MACRO
- Add_A_\1 opcode_2_bytes
- IFD BCDFLAGS
- move.b A,Z80_BCD_A(TableB)
- move.b Z80_\1(TableB),Z80_BCD_B(TableB)
- clr.w Z80_BCD_OP(TableB)
- ENDC
- add.b Z80_\1(TableB),A
- putsr d6
- skip 1
- next
- ENDM
- add_A_xyHL XH
- add_A_xyHL XL
- add_A_xyHL YH
- add_A_xyHL YL
- ** --
- and_xyHL MACRO
- And_\1 opcode_2_bytes
- and.b Z80_\1(TableB),A ;V is cleared
- putsr d6
- parity A
- skip 1
- next
- ENDM
- and_xyHL XH
- and_xyHL XL
- and_xyHL YH
- and_xyHL YL
- ** --
- cp_xyHL MACRO
- Cp_\1 opcode_2_bytes
- cmp.b Z80_\1(TableB),A
- putsr d6
- skip 1
- next
- ENDM
- cp_xyHL XH
- cp_xyHL XL
- cp_xyHL YH
- cp_xyHL YL
- ** --
- dec_xyHL MACRO
- Dec_\1 opcode_2_bytes
- decb Z80_\1(TableB)
- putsr d7
- eor.w d7,d6
- and.w #1,d6 ;keep old carry
- eor.w d7,d6
- skip 1
- next
- ENDM
- dec_xyHL XH
- dec_xyHL XL
- dec_xyHL YH
- dec_xyHL YL
- ** --
- inc_xyHL MACRO
- Inc_\1 opcode_2_bytes
- incb Z80_\1(TableB)
- putsr d7
- eor.w d7,d6
- and.w #1,d6 ;keep old carry
- eor.w d7,d6
- skip 1
- next
- ENDM
- inc_xyHL XH
- inc_xyHL XL
- inc_xyHL YH
- inc_xyHL YL
- ** --
- ld_xyHL_n MACRO
- Ld_\1_n opcode_2_bytes
- getRPC
- incw d7
- getz d7,Z80_\1(TableB)
- skip 2
- next
- ENDM
- ld_xyHL_n XH
- ld_xyHL_n XL
- ld_xyHL_n YH
- ld_xyHL_n YL
- ** --
- ld_r_xyHL MACRO
- Ld_\1_\2 opcode_2_bytes
- move.b Z80_\2(TableB),\1
- skip 1
- next
- ENDM
-
- ldrxy_r MACRO
- ld_r_xyHL \1,XH
- ld_r_xyHL \1,XL
- ld_r_xyHL \1,YH
- ld_r_xyHL \1,YL
- ENDM
-
- ldrxy_r A
- ldrxy_r B
- ldrxy_r C
- ldrxy_r D
- ldrxy_r E
-
- ld_xyHL_r MACRO
- Ld_\1_\2 opcode_2_bytes
- move.b \2,Z80_\1(TableB)
- skip 1
- next
- ENDM
-
- ldxyr_r MACRO
- ld_xyHL_r XH,\1
- ld_xyHL_r XL,\1
- ld_xyHL_r YH,\1
- ld_xyHL_r YL,\1
- ENDM
-
- ldxyr_r A
- ldxyr_r B
- ldxyr_r C
- ldxyr_r D
- ldxyr_r E
-
- ldxyxy MACRO
- Ld_\1H_\1H opcode_2_bytes ;Ld XH,XH or XL,XL
- skip 1
- next
- Ld_\1L_\1L = Ld_\1H_\1H
-
- Ld_\1H_\1L opcode_2_bytes
- move.b Z80_XL(TableB),Z80_XH(TableB)
- skip 1
- next
- Ld_\1L_\1H opcode_2_bytes
- move.b Z80_XH(TableB),Z80_XL(TableB)
- skip 1
- next
- ENDM
-
- do_xy ldxyxy
- ** --
- or_xyHL MACRO
- Or_\1 opcode_2_bytes
- or.b Z80_\1(TableB),A ;C and V are reset
- putsr d6
- parity A
- skip 1
- next
- ENDM
- or_xyHL XH
- or_xyHL XL
- or_xyHL YH
- or_xyHL YL
- ** --
- ** Res/Set reg,bit,(IX/IY+d) routines placed in distant.i
- rsrbxy_op_r_b MACRO
- \1_\2_\3_1IX_d1 jmp d_\1_\2_\3_1IX_d1
- \1_\2_\3_1IY_d1 jmp d_\1_\2_\3_1IY_d1
- ENDM
-
- rsrbxy_op_b MACRO
- rsrbxy_op_r_b \1,A,\2
- rsrbxy_op_r_b \1,B,\2
- rsrbxy_op_r_b \1,C,\2
- rsrbxy_op_r_b \1,D,\2
- rsrbxy_op_r_b \1,E,\2
- rsrbxy_op_r_b \1,L,\2
- rsrbxy_op_r_b \1,H,\2
- ENDM
-
- rsrbxy_op MACRO
- rsrbxy_op_b \1,0
- rsrbxy_op_b \1,1
- rsrbxy_op_b \1,2
- rsrbxy_op_b \1,3
- rsrbxy_op_b \1,4
- rsrbxy_op_b \1,5
- rsrbxy_op_b \1,6
- rsrbxy_op_b \1,7
- ENDM
-
- rsrbxy_op Res
- rsrbxy_op Set
- ** --
- ** Rl, Rlc, Rr, Rrc, Sla, Sll, Sra, Srl (IX/IY+d) with copy-to-reg:
- ** Routines placed in distant.i
- rotxyr_op_r MACRO
- \1_\2_1IX_d1 jmp d_\1_\2_1IX_d1
- \1_\2_1IY_d1 jmp d_\1_\2_1IY_d1
- ENDM
-
- rotxyr_r MACRO
- rotxyr_op_r Rl,\1
- rotxyr_op_r Rlc,\1
- rotxyr_op_r Rr,\1
- rotxyr_op_r Rrc,\1
- rotxyr_op_r Sla,\1
- rotxyr_op_r Sll,\1
- rotxyr_op_r Sra,\1
- rotxyr_op_r Srl,\1
- ENDM
- do_r rotxyr_r
- rotxyr_r H
- ** --
- sbc_A_xyHL MACRO
- Sbc_A_\1 opcode_2_bytes
- move.b Z80_\1(TableB),d7
- IFD BCDFLAGS
- move.b A,Z80_BCD_A(TableB) ;BCD_A=A
- move.b d7,Z80_BCD_B(TableB) ;BCD_B=register
- move.w d6,Z80_BCD_C(TableB) ;BCD_C=flags
- move.w #OP_SBC,Z80_BCD_OP(TableB) ;BCD_OP=sbc
- ENDC
- lsr.w #1,d6 ;carry to X
- ori #4,CCR ;set Z
- subx.b d7,A
- putsr d6
- skip 1
- next
- ENDM
- sbc_A_xyHL XH
- sbc_A_xyHL XL
- sbc_A_xyHL YH
- sbc_A_xyHL YL
- ** --
- ** Sll, 'Shift left logically', shifts the byte left, moving a 1(!) into
- ** bit 0 and bit 7 to carry. Flag conditions like Srl.
- sll_r MACRO
- Sll_\1 opcode_2_bytes
- lsl.b #1,\1 ;V is cleared, bit 0 reset
- putsr d6
- incb \1 ;set bit 0
- parity \1
- skip 1
- next
- ENDM
- do_r sll_r
-
- Sll_H opcode_2_bytes
- move.w HL,(Work)
- clr.w d7 ;for parity index
- move.b (Work),d7
- lsl.b #1,d7
- putsr d6
- incb d7
- parity d7
- move.b d7,(Work)
- move.w (Work),HL
- skip 1
- next
- ** --
- Sll_1HL1 opcode_2_bytes
- clr.w d7
- getz HL,d7
- lsl.b #1,d7
- putsr d6
- incb d7
- parity d7
- putz d7,HL
- skip 1
- next
- ** --
- sll_1xy1 MACRO
- Sll_1I\1_d1 opcode_3_bytes
- index \1
- move.w A,(Work)
- getz d7,A
- lsl.b #1,A
- putsr d6
- incb A
- parity A
- putz A,d7
- move.w (Work),A
- skip 3
- next
- ENDM
- do_xy sll_1xy1
- ** --
- sub_xyHL MACRO
- Sub_\1 opcode_2_bytes
- IFD BCDFLAGS
- move.b A,Z80_BCD_A(TableB) ;BCD_A=A
- move.b Z80_\1(TableB),Z80_BCD_B(TableB) ;BCD_B=r
- move.w #OP_SUB,Z80_BCD_OP(TableB) ;BCD_OP=sub
- ENDC
- sub.b Z80_\1(TableB),A
- putsr d6
- skip 1
- next
- ENDM
- sub_xyHL XH
- sub_xyHL XL
- sub_xyHL YH
- sub_xyHL YL
- ** --
- xor_xyHL MACRO
- Xor_\1 opcode_2_bytes
- move.b Z80_\1(TableB),d7 ;can only eor from D-register
- eor.b d7,A ;V and C are reset
- putsr d6
- parity A
- skip 1
- next
- ENDM
- xor_xyHL XH
- xor_xyHL XL
- xor_xyHL YH
- xor_xyHL YL
-
- ** ---------------------------------------------------------------------
-
- ELSE ;IFND UNDOCINSTR_UNDEF
-
- IFD VERBOSE
- LIST
- ** Creating fake labels for the "undocumented" instructions, making
- ** them all behave as undefined opcodes.
- NOLIST
- ENDC
-
- ** Treat the "undocumented" instructions as undefined:
-
- ** Let the undocumented cases of Neg and Retn become "normal" undefined
- ** opcodes:
- undoc_neg EQU undef
- undoc_retn EQU undef
-
- ** Create fake labels for the "undocumented"-labels, being equal to
- ** the undefined-opcode routines:
-
- ** Ld labels:
- ldrxy_r_xy MACRO
- Ld_\1_\2H = Undef_Opcode_2
- Ld_\1_\2L = Undef_Opcode_2
- Ld_\2H_\1 = Undef_Opcode_2
- Ld_\2L_\1 = Undef_Opcode_2
- ENDM
-
- ldrxy_xy MACRO
- ldrxy_r_xy A,\1
- ldrxy_r_xy B,\1
- ldrxy_r_xy C,\1
- ldrxy_r_xy D,\1
- ldrxy_r_xy E,\1
- ENDM
-
- ldrxy_xy X
- ldrxy_xy Y
-
- Ld_XH_XH = Undef_Opcode_2
- Ld_XL_XL = Undef_Opcode_2
- Ld_YH_YH = Undef_Opcode_2
- Ld_YL_YL = Undef_Opcode_2
- Ld_XH_XL = Undef_Opcode_2
- Ld_XL_XH = Undef_Opcode_2
- Ld_YH_YL = Undef_Opcode_2
- Ld_YL_YH = Undef_Opcode_2
- ** --
- ** Res/Set reg,bit,(IX/IY+d) labels:
- rsrbxy_op_r_b MACRO
- \1_\2_\3_1IX_d1 = Undef_Opcode_3
- \1_\2_\3_1IY_d1 = Undef_Opcode_3
- ENDM
-
- rsrbxy_op_b MACRO
- rsrbxy_op_r_b \1,A,\2
- rsrbxy_op_r_b \1,B,\2
- rsrbxy_op_r_b \1,C,\2
- rsrbxy_op_r_b \1,D,\2
- rsrbxy_op_r_b \1,E,\2
- rsrbxy_op_r_b \1,L,\2
- rsrbxy_op_r_b \1,H,\2
- ENDM
-
- rsrbxy_op MACRO
- rsrbxy_op_b \1,0
- rsrbxy_op_b \1,1
- rsrbxy_op_b \1,2
- rsrbxy_op_b \1,3
- rsrbxy_op_b \1,4
- rsrbxy_op_b \1,5
- rsrbxy_op_b \1,6
- rsrbxy_op_b \1,7
- ENDM
-
- rsrbxy_op Res
- rsrbxy_op Set
- ** --
- ** Rl, Rlc, Rr, Rrc, Sla, Sll, Sra, Srl (IX/IY+d) with copy-to-reg:
- rotxyr_op_r MACRO
- \1_\2_1IX_d1 = Undef_Opcode_3
- \1_\2_1IY_d1 = Undef_Opcode_3
- ENDM
-
- rotxyr_r MACRO
- rotxyr_op_r Rl,\1
- rotxyr_op_r Rlc,\1
- rotxyr_op_r Rr,\1
- rotxyr_op_r Rrc,\1
- rotxyr_op_r Sla,\1
- rotxyr_op_r Sll,\1
- rotxyr_op_r Sra,\1
- rotxyr_op_r Srl,\1
- ENDM
- do_r rotxyr_r
- rotxyr_r H
- ** --
- sll_r MACRO
- Sll_\1 = Undef_Opcode_2
- ENDM
- do_r sll_r
-
- Sll_H = Undef_Opcode_2
- Sll_1HL1 = Undef_Opcode_2
- Sll_1IX_d1 = Undef_Opcode_3
- Sll_1IY_d1 = Undef_Opcode_3
- ** --
- ** Byte operations using IX/IY H and L:
- byteop_xyHL MACRO
-
- Adc_A_\1H = Undef_Opcode_2
- Adc_A_\1L = Undef_Opcode_2
-
- Add_A_\1H = Undef_Opcode_2
- Add_A_\1L = Undef_Opcode_2
-
- And_\1H = Undef_Opcode_2
- And_\1L = Undef_Opcode_2
-
- Cp_\1H = Undef_Opcode_2
- Cp_\1L = Undef_Opcode_2
-
- Dec_\1H = Undef_Opcode_2
- Dec_\1L = Undef_Opcode_2
-
- Inc_\1H = Undef_Opcode_2
- Inc_\1L = Undef_Opcode_2
-
- Ld_\1H_n = Undef_Opcode_2
- Ld_\1L_n = Undef_Opcode_2
-
- Or_\1H = Undef_Opcode_2
- Or_\1L = Undef_Opcode_2
-
- Sbc_A_\1H = Undef_Opcode_2
- Sbc_A_\1L = Undef_Opcode_2
-
- Sub_\1H = Undef_Opcode_2
- Sub_\1L = Undef_Opcode_2
-
- Xor_\1H = Undef_Opcode_2
- Xor_\1L = Undef_Opcode_2
-
- ENDM
-
- do_xy byteop_xyHL
-
- ENDC ;IFND UNDOCINSTR_UNDEF
-
- ** ======================================================================
-