home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-12-21 | 36.5 KB | 2,397 lines |
- ** The non-implementation-dependent Z80 instructions
-
- ** -----------------------------------------------------------------------
-
- ** The address register named Work points to a longword called Workspace,
- ** which is used for fast temporary storage and byte swaps.
-
- ** In order for the parity test to work, bits 8-15 of the tested register
- ** must be zero. The V flag (bit 1 of d6) must be clear before executing
- ** the macro.
-
- ** -----------------------------------------------------------------------
-
- ** Following opcodes exactly follow Zaks' "Programming the Z80".
- **
- ** n = 8-bit number
- ** nn = 16-bit number
- ** e = 8-bit relative jump offset
- ** d = 8-bit displacement
- ** pq = 16-bit address
- ** p = 8-bit address
- **
- ** Label notation: Underscore used for SPACE, comma and +
- **
- ** 1 (one) used for ( and )
-
- ** =======================================================================
-
- IFD VERBOSE
- LIST
- ** Compiling the std_instr.i file.
- NOLIST
- ENDC
-
-
- adc_A_r MACRO
- Adc_A_\1
- IFD BCDFLAGS
- move.b A,Z80_BCD_A(TableB) ;BCD_A=A
- move.b \1,Z80_BCD_B(TableB) ;BCD_B=r
- 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 \1,A
- putsr d6
- next
- ENDM
- do_r adc_A_r
- ** --
- Adc_A_H move.w HL,(Work)
- move.b (Work),d7
- IFD BCDFLAGS
- move.b A,Z80_BCD_A(TableB)
- move.b d7,Z80_BCD_B(TableB)
- move.w d6,Z80_BCD_C(TableB)
- move.w #OP_ADC,Z80_BCD_OP(TableB)
- ENDC
- lsr.w #1,d6
- ori #4,CCR
- addx.b d7,A
- putsr d6
- next
- ** --
- Adc_A_n getRPC
- getz d7,d7
- IFD BCDFLAGS
- move.b A,Z80_BCD_A(TableB)
- move.b d7,Z80_BCD_B(TableB)
- move.w d6,Z80_BCD_C(TableB)
- move.w #OP_ADC,Z80_BCD_OP(TableB)
- ENDC
- lsr.w #1,d6
- ori #4,CCR
- addx.b d7,A
- putsr d6
- skip 1
- next
- ** --
- Adc_A_1HL1 getz HL,d7
- IFD BCDFLAGS
- move.b A,Z80_BCD_A(TableB)
- move.b d7,Z80_BCD_B(TableB)
- move.w d6,Z80_BCD_C(TableB)
- move.w #OP_ADC,Z80_BCD_OP(TableB)
- ENDC
- lsr.w #1,d6
- ori #4,CCR
- addx.b d7,A
- putsr d6
- next
- ** --
- adc_A_1xy1 MACRO
- Adc_A_1I\1_d1 opcode_2_bytes
- index \1
- getz d7,d7
- IFD BCDFLAGS
- move.b A,Z80_BCD_A(TableB)
- move.b d7,Z80_BCD_B(TableB)
- move.w d6,Z80_BCD_C(TableB)
- move.w #OP_ADC,Z80_BCD_OP(TableB)
- ENDC
- lsr.w #1,d6
- ori #4,CCR
- addx.b d7,A
- putsr d6
- skip 2
- next
- ENDM
- do_xy adc_A_1xy1
- ** --
- adc_HL_ss MACRO
- Adc_HL_\1\2 opcode_2_bytes
- join \1,\2
- lsr.w #1,d6
- ori #4,CCR
- addx.w d7,HL
- putsr d6
- skip 1
- next
- ENDM
- do_ss adc_HL_ss
- ** --
- Adc_HL_HL opcode_2_bytes
- lsr.w #1,d6
- ori #4,CCR
- addx.w HL,HL
- putsr d6
- skip 1
- next
- ** --
- Adc_HL_SP opcode_2_bytes
- move.w ZSP,d7
- lsr.w #1,d6
- ori #4,CCR
- addx.w d7,HL
- putsr d6
- skip 1
- next
- ** --
- add_A_r MACRO
- Add_A_\1
- IFD BCDFLAGS
- move.b A,Z80_BCD_A(TableB)
- move.b \1,Z80_BCD_B(TableB)
- clr.w Z80_BCD_OP(TableB)
- ENDC
- add.b \1,A
- putsr d6
- next
- ENDM
- do_r add_A_r
- ** --
- Add_A_H move.w HL,(Work)
- move.b (Work),d7
- IFD BCDFLAGS
- move.b A,Z80_BCD_A(TableB)
- move.b d7,Z80_BCD_B(TableB)
- clr.w Z80_BCD_OP(TableB)
- ENDC
- add.b d7,A
- putsr d6
- next
- ** --
- Add_A_n getRPC
- getz d7,d7
- IFD BCDFLAGS
- move.b A,Z80_BCD_A(TableB)
- move.b d7,Z80_BCD_B(TableB)
- clr.w Z80_BCD_OP(TableB)
- ENDC
- add.b d7,A
- putsr d6
- skip 1
- next
- ** --
- Add_A_1HL1 getz HL,d7
- IFD BCDFLAGS
- move.b A,Z80_BCD_A(TableB)
- move.b d7,Z80_BCD_B(TableB)
- clr.w Z80_BCD_OP(TableB)
- ENDC
- add.b d7,A
- putsr d6
- next
- ** --
- add_A_1xy1 MACRO
- Add_A_1I\1_d1 opcode_2_bytes
- index \1
- getz d7,d7
- IFD BCDFLAGS
- move.b A,Z80_BCD_A(TableB)
- move.b d7,Z80_BCD_B(TableB)
- clr.w Z80_BCD_OP(TableB)
- ENDC
- add.b d7,A
- putsr d6
- skip 2
- next
- ENDM
- do_xy add_A_1xy1
- ** --
- add_HL_ss MACRO
- Add_HL_\1\2 join \1,\2
- and.w #%1110,d6
- add.w d7,HL
- bcc.s .cc
- or.w #1,d6
- .cc next
- ENDM
- do_ss add_HL_ss
- ** --
- Add_HL_HL and.w #%1110,d6
- add.w HL,HL
- bcc.s .cc
- or.w #1,d6
- .cc next
- ** --
- Add_HL_SP and.w #%1110,d6
- add.w ZSP,HL
- bcc.s .cc
- or.w #1,d6
- .cc next
- ** --
- add_xy_ss MACRO
- Add_I\1_\2\3 opcode_2_bytes
- join \2,\3
- and.w #%1110,d6
- add.w Z80_I\1(TableB),d7
- bcc.s .cc
- or.w #1,d6
- .cc move.w d7,Z80_I\1(TableB)
- skip 1
- next
- ENDM
-
- add_xy_xy MACRO
- Add_I\1_I\1 opcode_2_bytes
- and.w #%1110,d6
- move.w Z80_I\1(TableB),d7
- add.w d7,d7
- bcc.s .cc
- or.w #1,d6
- .cc move.w d7,Z80_I\1(TableB)
- skip 1
- next
- ENDM
-
- add_xy_SP MACRO
- Add_I\1_SP opcode_2_bytes
- and.w #%1110,d6
- move.w Z80_I\1(TableB),d7
- add.w ZSP,d7
- bcc.s .cc
- or.w #1,d6
- .cc move.w d7,Z80_I\1(TableB)
- skip 1
- next
- ENDM
-
- addxy_xy MACRO
- add_xy_ss \1,B,C
- add_xy_ss \1,D,E
- add_xy_xy \1
- add_xy_SP \1
- ENDM
- do_xy addxy_xy
- ** --
- and_r MACRO
- And_\1 and.b \1,A ;V is cleared
- putsr d6
- parity A
- next
- ENDM
- do_r and_r
- ** --
- And_H move.w HL,(Work)
- and.b (Work),A
- putsr d6
- parity A
- next
- ** --
- And_n getRPC
- and.b (Z0,d7.w),A
- putsr d6
- parity A
- skip 1
- next
- ** --
- And_1HL1 and.b (Z0,HL.w),A
- putsr d6
- parity A
- next
- ** --
- and_1xy1 MACRO
- And_1I\1_d1 opcode_2_bytes
- index \1
- and.b (Z0,d7.w),A
- putsr d6
- parity A
- skip 2
- next
- ENDM
- do_xy and_1xy1
- ** --
- bit_b_r MACRO
- Bit_\1_\2 opcode_2_bytes
- or.w #%0100,d6
- btst #\1,\2
- beq.s .z
- and.w #%1011,d6
- .z skip 1
- next
- ENDM
-
- bit_b_H MACRO
- Bit_\1_H opcode_2_bytes
- or.w #%0100,d6
- btst #8+\1,HL
- beq.s .z
- and.w #%1011,d6
- .z skip 1
- next
- ENDM
-
- bit_b_HL MACRO
- Bit_\1_1HL1 opcode_2_bytes
- or.w #%0100,d6
- btst #\1,(Z0,HL.w)
- beq.s .z
- and.w #%1011,d6
- .z skip 1
- next
- ENDM
-
- bit_b_1xy1 MACRO
- Bit_\1_1I\2_d1 opcode_3_bytes
- index \2
- or.w #%0100,d6
- btst #\1,(Z0,d7.w)
- beq.s .z
- and.w #%1011,d6
- .z skip 3
- next
- ENDM
-
- bit_b MACRO
- bit_b_r \1,A
- bit_b_r \1,B
- bit_b_r \1,C
- bit_b_r \1,D
- bit_b_r \1,E
- bit_b_r \1,L
- bit_b_H \1
- bit_b_HL \1
- bit_b_1xy1 \1,X
- bit_b_1xy1 \1,Y
- ENDM
-
- bit_b 0
- bit_b 1
- bit_b 2
- bit_b 3
- bit_b 4
- bit_b 5
- bit_b 6
- bit_b 7
- ** --
- call_cc_pq MACRO
- Call_\1_pq skip 2
- getsr
- b\2.s 101$ ; 'exit' label in testreq macro
- getRPC
- move.w d7,(Work)
- decw ZSP
- putz (Work),ZSP
- decw ZSP
- putz d7,ZSP,2 ;2nd use
- decw d7
- getz d7,(Work)
- decw d7
- getz d7,1(Work)
- move.w (Work),d7
- makePPC
- testreq
- ENDM
- call_cc_pq NZ,eq
- call_cc_pq Z,ne
- call_cc_pq NC,cs
- call_cc_pq C,cc
- call_cc_pq PO,vs
- call_cc_pq PE,vc
- call_cc_pq P,mi
- call_cc_pq M,pl
- ** --
- Call_pq getRPC
- addq.w #2,d7
- move.w d7,(Work)
- decw ZSP
- putz (Work),ZSP
- decw ZSP
- putz d7,ZSP,2 ;2nd use
- decw d7
- getz d7,(Work)
- decw d7
- getz d7,1(Work)
- move.w (Work),d7
- makePPC
- testreq
- ** --
- Ccf eori.w #1,d6
- next
- ** --
- cp_r MACRO
- Cp_\1 cmp.b \1,A
- putsr d6
- next
- ENDM
- do_r cp_r
- ** --
- Cp_H move.w HL,(Work)
- cmp.b (Work),A
- putsr d6
- next
- ** --
- Cp_n getRPC
- cmp.b (Z0,d7.w),A
- putsr d6
- skip 1
- next
- ** --
- Cp_1HL1 cmp.b (Z0,HL.w),A
- putsr d6
- next
- ** --
- cp_1xy1 MACRO
- Cp_1I\1_d1 opcode_2_bytes
- index \1
- cmp.b (Z0,d7.w),A
- putsr d6
- skip 2
- next
- ENDM
- do_xy cp_1xy1
- ** --
- Cpd opcode_2_bytes
- cmp.b (Z0,HL.w),A
- putsr d7
- eor.w d7,d6 ;Join old carry and
- and.w #1,d6 ; new sign and zero
- eor.w d7,d6
- or.w #%0010,d6 ;V set if BC not zero
- decw HL ;dec HL
- decb C
- beq.s .Cz
- bcc.s .BCnz ;if carry, decrement B
- decb B
- bra.s .BCnz ;C<>0, so BC<>0
-
- .Cz tst.b B
- bne.s .BCnz
- and.w #%1101,d6 ;V reset if BC zero
- .BCnz skip 1
- next
- ** --
- Cpi opcode_2_bytes
- cmp.b (Z0,HL.w),A
- putsr d7
- eor.w d7,d6 ;Join old carry and
- and.w #1,d6 ; new sign and zero
- eor.w d7,d6
- or.w #%0010,d6 ;V set if BC not zero
- incw HL ;dec HL
- decb C
- beq.s .Cz
- bcc.s .BCnz ;if carry, decrement B
- decb B
- bra.s .BCnz ;C<>0, so BC<>0
-
- .Cz tst.b B
- bne.s .BCnz
- and.w #%1101,d6 ;V reset if BC zero
- .BCnz skip 1
- next
- ** --
- Cpdr opcode_2_bytes
- move.b B,(Work)
- move.w (Work),B
- move.b C,B ;use B (word) as counter
- .loop cmp.b (Z0,HL.w),A
- putsr d7
- beq.s .eq
- decw HL ;dec pointer
- decw B ;dec counter
- bne.s .loop
- .BCz and.w #%1101,d7 ;BC zero, so reset V
- .end eor.w d7,d6 ;join old carry
- and.w #1,d6 ; with new N, Z & V
- eor.w d7,d6
- move.b B,C ;BC=counter
- lsr.w #8,B ;restore B, zeroing bits 15-8
- skip 1
- next
-
- .eq decw HL ;one last dec pointer
- decw B ; and dec counter
- beq.s .BCz
- or.w #%0010,d7 ;BC not zero, so set V
- bra.s .end
- ** --
- Cpir opcode_2_bytes
- move.b B,(Work)
- move.w (Work),B
- move.b C,B ;use B (word) as counter
- .loop cmp.b (Z0,HL.w),A
- putsr d7
- beq.s .eq
- incw HL ;dec pointer
- decw B ;dec counter
- bne.s .loop
- .BCz and.w #%1101,d7 ;BC zero, so reset V
- .end eor.w d7,d6 ;join old carry
- and.w #1,d6 ; with new N, Z & V
- eor.w d7,d6
- move.b B,C ;BC=counter
- lsr.w #8,B ;restore B, zeroing bits 15-8
- skip 1
- next
-
- .eq incw HL ;one last dec pointer
- decw B ; and dec counter
- beq.s .BCz
- or.w #%0010,d7 ;BC not zero, so set V
- bra.s .end
- ** --
- Cpl not.b A
- next
- ** --
-
- Daa
- ;bit 15 of BCD_OP is 1 for adc/sbc, otherwise 0.
- ;bit 14 is 0 for add and 1 for sub.
-
- OP_ADD = 0 ;clr.w is used in several places
- OP_SUB = $4000
- OP_ADC = $8000
- OP_SBC = $C000
-
- IFD BCDFLAGS
- move.b Z80_BCD_A(TableB),A ;get destination
- move.b Z80_BCD_B(TableB),d7 ;get source
- move.w Z80_BCD_OP(TableB),d6 ;get operation
- add.w d6,d6 ;bit 15 to carry, bit 14 to 15
- bcs.s .c ;include C if it was set
- move.w #0,CCR ;else clear X
- .op tst.w d6 ;test add/sub bit (X unaffected)
- bmi.s .sub ;sub if it was set
- Abcd d7,A ;else add (with extend)
- .end putsr d6
- and.w #1,d6 ;keep only C (others useless)
- parity A ;V of d6 = parity
- tst.b A ;V & C of CCR cleared
- putsr d7
- or.w d7,d6
- next
-
- .sub Sbcd d7,A ;sub (with extend)
- bra.s .end
-
- .c lsr Z80_BCD_C(TableB) ;C to X
- bra.s .op
- ELSE
- move.w #-1,Z80_BCD_OP(TableB) ;"Daa used" marker
- next
- ENDC
- ** --
- dec_r MACRO
- Dec_\1 decb \1
- putsr d7
- eor.w d7,d6
- and.w #1,d6 ;keep old carry
- eor.w d7,d6
- next
- ENDM
- do_r dec_r
- ** --
- Dec_H move.w HL,(Work)
- decb (Work)
- putsr d7
- move.w (Work),HL
- eor.w d7,d6
- and.w #1,d6
- eor.w d7,d6
- next
- ** --
- Dec_1HL1
- IFD Z80_MEMCHECK
- getz HL,(Work)
- subq.b #1,(Work)
- putsr d7 ;flags first
- eor.w d7,d6
- and.w #1,d6
- eor.w d7,d6
- putz (Work),HL ;then write
- ELSE
- subq.b #1,(Z0,HL.w)
- putsr d7
- eor.w d7,d6
- and.w #1,d6
- eor.w d7,d6
- ENDC
- next
- ** --
- Dec_1xy1 MACRO
- Dec_1I\1_d1 opcode_2_bytes
- index \1
- IFD Z80_MEMCHECK
- move.w d7,-(sp)
- getz d7,(Work)
- subq.b #1,(Work)
- putsr d7
- eor.w d7,d6
- and.w #1,d6
- eor.w d7,d6
- move.w (sp)+,d7
- putz (Work),d7
- ELSE
- subq.b #1,(Z0,d7.w)
- putsr d7
- eor.w d7,d6
- and.w #1,d6
- eor.w d7,d6
- ENDC
- skip 2
- next
- ENDM
- do_xy Dec_1xy1
- ** --
- dec_rr MACRO
- Dec_\1\2 decb \2
- bcc.s .cc
- decb \1
- .cc next
- ENDM
- do_ss dec_rr
- ** --
- Dec_HL decw HL
- next
- ** --
- Dec_SP decw ZSP
- next
- ** --
- dec_xy MACRO
- Dec_I\1 opcode_2_bytes
- decw Z80_I\1(TableB)
- skip 1
- next
- ENDM
- do_xy dec_xy
- ** --
- Di clr.b Z80_IFF(TableB) ;clear IFF
- next
- ** --
- Djnz_e decb B
- beq.s .end
- getRPC
- move.w d7,PPC ;can't rotate addr.reg.
- getz PPC,d7
- ext.w d7
- add.w PPC,d7
- makePPC
- .end skip 1
- testreq
- ** --
- Ei move.b #$C0,Z80_IFF(TableB) ;set IFF2 and IFF1
- next
- ** --
- Ex_AF_AF move.w d6,d7
- move.w Z80_alt_CCR(TableB),d6
- move.w d7,Z80_alt_CCR(TableB)
- swap A
- next
- ** --
- Ex_DE_HL move.w HL,d7
- move.b D,(Work)
- move.w (Work),HL
- move.b E,HL
- move.w d7,(Work)
- move.b (Work),D
- move.b d7,E
- next
- ** --
- Ex_1SP1_HL getz ZSP,1(Work)
- incw ZSP
- getz ZSP,(Work)
- move.w (Work),d7
- move.w HL,(Work)
- putz (Work),ZSP
- decw ZSP
- putz L,ZSP,2 ;2nd use
- move.w d7,HL
- next
- ** --
- ex_1SP1_xy MACRO
- Ex_1SP1_I\1 opcode_2_bytes
- getz ZSP,1(Work)
- incw ZSP
- getz ZSP,(Work)
- move.w (Work),d7
- move.w Z80_I\1(TableB),(Work)
- putz (Work),ZSP
- decw ZSP
- putz 1(Work),ZSP,2 ;2nd use
- move.w d7,Z80_I\1(TableB)
- skip 1
- next
- ENDM
- do_xy ex_1SP1_xy
- ** --
- Exx swap B
- swap C
- swap D
- swap E
- move.w Z80_alt_HL(TableB),d7
- move.w HL,Z80_alt_HL(TableB)
- move.w d7,HL
- next
- ** --
- Halt move.w Z80_Request(TableB),d7
- beq.s Halt ;busy-wait for interrupt
- jmp (InstrB,d7.w)
- ** --
- Im_0 opcode_2_bytes
- move.b #-1,Z80_INTMOD(TableB) ;Intmode=0
- skip 1
- next
- ** --
- Im_1 opcode_2_bytes
- clr.b Z80_INTMOD(TableB) ;Intmode=1
- skip 1
- next
- ** --
- Im_2 opcode_2_bytes
- move.b #1,Z80_INTMOD(TableB) ;Intmode=2
- skip 1
- next
- ** --
-
- ** In r,(C) is in 'impldept.a'
-
- ** In A,(n) is in 'impldept.a'
-
- ** --
- inc_r MACRO
- Inc_\1 incb \1
- putsr d7
- eor.w d7,d6
- and.w #1,d6
- eor.w d7,d6
- next
- ENDM
- do_r inc_r
- ** --
- Inc_H move.w HL,(Work)
- incb (Work)
- putsr d7
- move.w (Work),HL
- eor.w d7,d6
- and.w #1,d6
- eor.w d7,d6
- next
- ** --
- Inc_1HL1
- IFD Z80_MEMCHECK
- getz HL,(Work)
- addq.b #1,(Work)
- putsr d7
- eor.w d7,d6
- and.w #1,d6
- eor.w d7,d6
- putz (Work),HL
- ELSE
- addq.b #1,(Z0,HL.w)
- putsr d7
- eor.w d7,d6
- and.w #1,d6
- eor.w d7,d6
- ENDC
- next
- ** --
- inc_1xy1 MACRO
- Inc_1I\1_d1 opcode_2_bytes
- index \1
- IFD Z80_MEMCHECK
- move.w d7,-(sp)
- getz d7,(Work)
- addq.b #1,(Work)
- putsr d7
- eor.w d7,d6
- and.w #1,d6
- eor.w d7,d6
- move.w (sp)+,d7
- putz (Work),d7
- ELSE
- addq.b #1,(Z0,d7.w)
- putsr d7
- eor.w d7,d6
- and.w #1,d6
- eor.w d7,d6
- ENDC
- skip 2
- next
- ENDM
- do_xy inc_1xy1
- ** --
- inc_rr MACRO
- Inc_\1\2 incb \2
- bcc.s .cc
- incb \1
- .cc next
- ENDM
- do_ss inc_rr
- ** --
- Inc_HL incw HL
- next
- ** --
- Inc_SP incw ZSP
- next
- ** --
- inc_xy MACRO
- Inc_I\1 opcode_2_bytes
- incw Z80_I\1(TableB)
- skip 1
- next
- ENDM
- do_xy inc_xy
- ** --
-
- ** Ind, Ini, Indr and Inir are in 'impldept.a'
-
- ** --
- jp_cc_pq MACRO
- Jp_\1_pq skip 2
- getsr
- b\2.s 101$ ;label in testreq macro
- getRPC
- decw d7
- getz d7,(Work)
- decw d7
- getz d7,1(Work)
- move.w (Work),d7
- makePPC
- testreq
- ENDM
- jp_cc_pq NZ,eq
- jp_cc_pq Z,ne
- jp_cc_pq NC,cs
- jp_cc_pq C,cc
- jp_cc_pq PO,vs
- jp_cc_pq PE,vc
- jp_cc_pq P,mi
- jp_cc_pq M,pl
- ** --
- Jp_pq getRPC
- getz d7,1(Work)
- incw d7
- getz d7,(Work)
- move.w (Work),d7
- makePPC
- testreq
- ** --
- Jp_1HL1 lea (CacheB,HL.w),PPC
- add.w HL,PPC
- testreq
- ** --
- jp_1xy1 MACRO
- Jp_1I\11 opcode_2_bytes
- move.w Z80_I\1(TableB),d7
- lea (CacheB,d7.w),PPC
- add.w d7,PPC
- testreq
- ENDM
- do_xy jp_1xy1
- ** --
- jr_cc_e MACRO
- Jr_\1_e getsr
- b\2.s .end
- getRPC
- move.w d7,PPC
- getz PPC,d7
- ext.w d7
- add.w PPC,d7
- makePPC
- .end skip 1
- testreq
- ENDM
- jr_cc_e NZ,eq
- jr_cc_e Z,ne
- jr_cc_e NC,cs
- jr_cc_e C,cc
- ** --
- Jr_e getRPC
- move.w d7,PPC
- getz PPC,d7
- incw PPC
- ext.w d7
- add.w PPC,d7
- makePPC
- testreq
- ** --
- ld_dd_1nn1 MACRO
- Ld_\1\2_1nn1 opcode_2_bytes
- getRPC
- incw d7
- getz d7,1(Work)
- incw d7
- getz d7,(Work)
- move.w (Work),d7
- getz d7,\2
- incw d7
- getz d7,\1
- skip 3
- next
- ENDM
- do_ss ld_dd_1nn1
- ** --
- ED_Ld_HL_1nn1 opcode_2_bytes
- getRPC
- incw d7
- getz d7,1(Work)
- incw d7
- getz d7,(Work)
- move.w (Work),d7
- getz d7,1(Work)
- incw d7
- getz d7,(Work)
- move.w (Work),HL
- skip 3
- next
- ** --
- Ld_SP_1nn1 opcode_2_bytes
- getRPC
- incw d7
- getz d7,1(Work)
- incw d7
- getz d7,(Work)
- move.w (Work),d7
- getz d7,1(Work)
- incw d7
- getz d7,(Work)
- move.w (Work),ZSP
- skip 3
- next
- ** --
- ld_dd_nn MACRO
- Ld_\1\2_nn getRPC
- getz d7,\2
- incw d7
- getz d7,\1
- skip 2
- next
- ENDM
- do_ss ld_dd_nn
- ** --
- Ld_HL_nn getRPC
- getz d7,1(Work)
- incw d7
- getz d7,(Work)
- move.w (Work),HL
- skip 2
- next
- ** --
- Ld_SP_nn getRPC
- getz d7,1(Work)
- incw d7
- getz d7,(Work)
- move.w (Work),ZSP
- skip 2
- next
- ** --
- ld_r_n MACRO
- Ld_\1_n getRPC
- getz d7,\1
- skip 1
- next
- ENDM
- do_r ld_r_n
- ** --
- Ld_H_n getRPC
- move.w HL,(Work)
- getz d7,(Work)
- move.w (Work),HL
- skip 1
- next
- ** --
- ld_r_r MACRO ;(Not from/to H)
- Ld_\1_\2 move.b \2,\1
- next
- ENDM
-
- ld_r_H MACRO ;(Not to H)
- Ld_\1_H move.w HL,(Work)
- move.b (Work),\1
- next
- ENDM
-
- ldrr_r MACRO
- ld_r_r \1,A
- ld_r_r \1,B
- ld_r_r \1,C
- ld_r_r \1,D
- ld_r_r \1,E
- ld_r_r \1,L
- ld_r_H \1
- ENDM
- do_r ldrr_r
-
- ld_H_regs MACRO ;(Not from H)
- Ld_H_\1 move.w HL,(Work)
- move.b \1,(Work)
- move.w (Work),HL
- next
- ENDM
- do_r ld_H_regs
-
- Ld_H_H next ;Well, I want to have the label there.
- ** --
- Ld_1BC1_A join B,C
- putz A,d7
- next
- ** --
- Ld_1DE1_A join D,E
- putz A,d7
- next
- ** --
- Ld_1HL1_n getRPC
- putz <(Z0,d7.w)>,HL
- skip 1
- next
- ** --
- ld_1HL1_r MACRO ;(Not from H)
- Ld_1HL1_\1 putz \1,HL
- next
- ENDM
- do_r ld_1HL1_r
- ** --
- Ld_1HL1_H move.w HL,(Work)
- putz (Work),HL
- next
- ** --
- ldrxy_r_1xy1 MACRO ;(Not to H)
- Ld_\1_1I\2_d1 index \2
- getz d7,\1
- skip 2
- next
- ENDM
-
- ldrxy_H_1xy1 MACRO
- Ld_H_1I\1_d1 opcode_2_bytes
- index \1
- move.w HL,(Work)
- getz d7,(Work)
- move.w (Work),HL
- skip 2
- next
- ENDM
-
- ldrxy_1xy1 MACRO
- ldrxy_r_1xy1 A,\1
- ldrxy_r_1xy1 B,\1
- ldrxy_r_1xy1 C,\1
- ldrxy_r_1xy1 D,\1
- ldrxy_r_1xy1 E,\1
- ldrxy_r_1xy1 L,\1
- ldrxy_H_1xy1 \1
- ENDM
- do_xy ldrxy_1xy1
- ** --
- ld_1xy1_n MACRO
- Ld_1I\1_d1_n opcode_2_bytes
- getRPC
- addq.w #2,d7
- getz d7,(Work) ;get data
- decw d7
- getz d7,d7 ;get offset
- ext.w d7
- add.w Z80_I\1(TableB),d7
- putz (Work),d7
- skip 3
- next
- ENDM
- do_xy ld_1xy1_n
- ** --
- ldxyr_1xy1_r MACRO ;(Not from H)
- Ld_1I\2_d1_\1 opcode_2_bytes
- index \2
- putz \1,d7
- skip 2
- next
- ENDM
-
- ldxyr_1xy1_H MACRO
- Ld_1I\1_d1_H opcode_2_bytes
- index \1
- move.w HL,(Work)
- putz (Work),d7
- skip 2
- next
- ENDM
-
- ldxyr_1xy1 MACRO
- ldxyr_1xy1_r A,\1
- ldxyr_1xy1_r B,\1
- ldxyr_1xy1_r C,\1
- ldxyr_1xy1_r D,\1
- ldxyr_1xy1_r E,\1
- ldxyr_1xy1_r L,\1
- ldxyr_1xy1_H \1
- ENDM
- do_xy ldxyr_1xy1
- ** --
- Ld_A_1nn1 getRPC
- getz d7,1(Work)
- incw d7
- getz d7,(Work)
- move.w (Work),d7
- getz d7,A
- skip 2
- next
- ** --
- Ld_1nn1_A getRPC
- getz d7,1(Work)
- incw d7
- getz d7,(Work)
- move.w (Work),d7
- putz A,d7
- skip 2
- next
- ** --
- ld_1nn1_dd MACRO
- Ld_1nn1_\1\2 opcode_2_bytes
- getRPC
- incw d7
- getz d7,1(Work)
- incw d7
- getz d7,(Work)
- move.w (Work),d7
- putz \2,d7
- incw d7
- putz \1,d7,2 ;2nd use
- skip 3
- next
- ENDM
- do_ss ld_1nn1_dd
- ** --
- ED_Ld_1nn1_HL opcode_2_bytes
- getRPC
- incw d7
- getz d7,1(Work)
- incw d7
- getz d7,(Work)
- move.w (Work),d7
- move.w HL,(Work)
- putz HL,d7
- incw d7
- putz (Work),d7,2 ;2nd use
- skip 3
- next
- ** --
- Ld_1nn1_SP opcode_2_bytes
- getRPC
- incw d7
- getz d7,1(Work)
- incw d7
- getz d7,(Work)
- move.w (Work),d7
- move.w ZSP,(Work)
- putz 1(Work),d7
- incw d7
- putz (Work),d7,2 ;2nd use
- skip 3
- next
- ** --
- Ld_1nn1_HL getRPC ;the prefixed kind is called ED_Ld_1nn1_HL
- getz d7,1(Work)
- incw d7
- getz d7,(Work)
- move.w (Work),d7
- move.w HL,(Work)
- putz HL,d7
- incw d7
- putz (Work),d7,2 ;2nd use
- skip 2
- next
- ** --
- ld_1nn1_xy MACRO
- Ld_1nn1_I\1 opcode_2_bytes
- getRPC
- getz d7,1(Work)
- incw d7
- getz d7,(Work)
- move.w (Work),d7
- move.w Z80_I\1(TableB),(Work)
- putz 1(Work),d7
- incw d7
- putz (Work),d7,2 ;2nd use
- skip 3
- next
- ENDM
- do_xy ld_1nn1_xy
- ** --
- Ld_A_1BC1 join B,C
- getz d7,A
- next
- ** --
- Ld_A_1DE1 join D,E
- getz d7,A
- next
- ** --
- Ld_A_I opcode_2_bytes
- move.b Z80_I(TableB),A ;V is cleared, Z and N tested.
- putsr d7
- eor.w d7,d6
- and.w #1,d6 ;keep old carry
- eor.w d7,d6
- tst.b Z80_IFF(TableB) ;test IFF2
- bpl.s .clear
- or.w #%0010,d6 ;set V if IFF2 set
- .clear skip 1
- next
- ** --
- Ld_I_A opcode_2_bytes
- move.b A,Z80_I(TableB)
- skip 1
- next
- ** --
-
- ** Ld A,R is in 'impldept.a'
-
- ** --
- Ld_HL_1nn1 getRPC ;the prefixed kind is called ED_Ld_HL_1nn1
- getz d7,1(Work)
- incw d7
- getz d7,(Work)
- move.w (Work),d7
- incw d7
- getz d7,(Work)
- move.w (Work),HL
- decw d7
- getz d7,HL
- skip 2
- next
- ** --
- ld_xy_nn MACRO
- Ld_I\1_nn opcode_2_bytes
- getRPC
- incw d7
- getz d7,1(Work)
- incw d7
- getz d7,(Work)
- move.w (Work),Z80_I\1(TableB)
- skip 3
- next
- ENDM
- do_xy ld_xy_nn
- ** --
- ld_xy_1nn1 MACRO
- Ld_I\1_1nn1 opcode_2_bytes
- getRPC
- incw d7
- getz d7,1(Work)
- incw d7
- getz d7,(Work)
- move.w (Work),d7
- getz d7,1(Work)
- incw d7
- getz d7,(Work)
- move.w (Work),Z80_I\1(TableB)
- skip 3
- next
- ENDM
- do_xy ld_xy_1nn1
- ** --
-
- ** Ld R,A is in 'impldept.a'
-
- ** --
- Ld_SP_HL move.w HL,ZSP
- next
- ** --
- ld_SP_xy MACRO
- Ld_SP_I\1 opcode_2_bytes
- move.w Z80_I\1(TableB),ZSP
- skip 1
- next
- ENDM
- do_xy ld_SP_xy
- ** --
- Ldd opcode_2_bytes
- or.w #%0010,d6 ;set V
- join D,E
- putz <(Z0,HL.w)>,d7 ;(HL) -> (DE)
- decb E ;dec DE
- bcc.s .nc
- decb D
- .nc decw HL ;dec HL
- decb C
- beq.s .Cz
- bcc.s .end
- decb B
- .end skip 1
- next
-
- .Cz tst.b B
- bne.s .end
- and.w #%1101,d6 ;BC=0 -> clear V
- bra.s .end
- ** --
- Ldi opcode_2_bytes
- or.w #%0010,d6 ;set V
- join D,E
- putz <(Z0,HL.w)>,d7 ;(HL) -> (DE)
- incb E ;inc DE
- bcc.s .nc
- incb D
- .nc incw HL ;inc HL
- decb C
- beq.s .Cz
- bcc.s .end
- decb B
- .end skip 1
- next
-
- .Cz tst.b B
- bne.s .end
- and.w #%1101,d6 ;BC=0 -> clear V
- bra.s .end
- ** --
- Lddr opcode_2_bytes
- and.w #%1101,d6 ;Clear V
- join D,E ;d7 as destination pointer
- move.b B,(Work)
- move.w (Work),B ;B (word) as counter
- move.b C,B
- .loop putz <(Z0,HL.w)>,d7
- decw d7 ;dec dest.
- decw HL ;dec source
- decw B
- bne.s .loop
- clr.w C ;low word of B already 0
- move.b d7,E ;dest. back to D and E
- move.w d7,(Work)
- move.b (Work),D
- skip 1
- next
- ** --
- Ldir opcode_2_bytes
- and.w #%1101,d6 ;Clear V
- join D,E ;d7 as destination pointer
- move.b B,(Work)
- move.w (Work),B ;B (word) as counter
- move.b C,B
- .loop putz <(Z0,HL.w)>,d7
- incw d7 ;inc dest.
- incw HL ;inc source
- decw B
- bne.s .loop
- clr.w C ;low word of B already 0
- move.b d7,E ;dest. back to D and E
- move.w d7,(Work)
- move.b (Work),D
- skip 1
- next
- ** --
- ld_r_1HL1 MACRO ;(Not to H)
- Ld_\1_1HL1 getz HL,\1
- next
- ENDM
- do_r ld_r_1HL1
- ** --
- Ld_H_1HL1 move.w HL,(Work)
- getz HL,(Work)
- move.w (Work),HL
- next
- ** --
- Neg opcode_2_bytes
- IFD BCDFLAGS
- clr.b Z80_BCD_A(TableB) ;BCD_A=0
- move.b A,Z80_BCD_B(TableB) ;BCD_B=A
- move.w #OP_SUB,Z80_BCD_OP(TableB) ;BCD_OP=sub
- ENDC
- neg.b A
- putsr d6
- skip 1
- next
- ** --
- Nop nop ;Well, why not?
- next
- ** --
- or_r MACRO
- Or_\1 or.b \1,A ;C and V are reset
- putsr d6
- parity A
- next
- ENDM
- do_r or_r
- ** --
- Or_H move.w HL,(Work)
- or.b (Work),A
- putsr d6
- parity A
- next
- ** --
- Or_n getRPC
- or.b (Z0,d7.w),A
- putsr d6
- parity A
- skip 1
- next
- ** --
- Or_1HL1 or.b (Z0,HL.w),A
- putsr d6
- parity A
- next
- ** --
- or_1xy1 MACRO
- Or_1I\1_d1 opcode_2_bytes
- index \1
- or.b (Z0,d7.w),A
- putsr d6
- parity A
- skip 2
- next
- ENDM
- do_xy or_1xy1
- ** --
-
- ** Otdr and Otir are in 'impldept.a'
-
- ** --
-
- ** Out (C),r is in 'impldept.a'
-
- ** Out (n),A is in 'impldept.a'
-
- ** -
-
- ** Outd and Outi are in 'impldept.a'
-
- ** --
- pop_qq MACRO
- Pop_\1\2 getz ZSP,\2
- incw ZSP
- getz ZSP,\1
- incw ZSP
- next
- ENDM
- do_ss pop_qq
- ** --
- Pop_HL getz ZSP,1(Work)
- incw ZSP
- getz ZSP,(Work)
- incw ZSP
- move.w (Work),HL
- next
- ** --
- ;Z80 VnCSZ (F) to 680x0 XNZVC (CCR) translation table.
- ; N = S. n (BCD negative) maps to X.
-
- ;0, Z, S, SZ, C, CZ, CS, CSZ,
- Pop_AF_table dc.b 0,%100,%1000,%1100,1,%101,%1001,%1101
- ;n, nZ, nS, nSZ, nC, nCZ, nCS, nCSZ
- dc.b %10000,%10100,%11000,%11100,%10001,%10101,%11001,%11101
- ;V, VZ, VS, VSZ, VC, VCZ, VCS, VCSZ,
- dc.b %10,%110,%1010,%1110,%11,%111,%1011,%1111
- ;Vn, VnZ, VnS, VnSZ, VnC, VnCZ, VnCS, VnCSZ
- dc.b %10010,%10110,%11010,%11110,%10011,%10111,%11011,%11111
-
- Pop_AF getz ZSP,d6
- IFND AFPUSHPOP_CCR
- ;Popped was Z80 F format, so remap to CCR-format.
- ;No information must be lost!
- ;V=P/V, N=S, n is Z80 BCD negative. h is Z80 bcd half-carry.
- rol.b #2,d6 ;SZ-h-VnC -> -h-VnCSZ
- move.b d6,d7
- and.w #$001F,d7 ;d7 = 000VnCSZ
- and.w #%11100000,d6 ;d6 = -h-00000
- or.b Pop_AF_table(pc,d7.w),d6 ;d6 = -h-XNZVC
- ENDC
- incw ZSP
- getz ZSP,A
- incw ZSP
- IFD BCDFLAGS
- IFD AFPUSHPOP_BCD
- ;Stack grows in positive direction. Data size is 6 bytes.
- ;Pop decrements, then reads.
- move.w Z80_BCD_SP(TableB),d7
- subq.w #6,d7
- bcc.s .nowrap
- move.w #6*(Z80_BCDSTACKSIZE-1),d7
- .nowrap move.w d7,Z80_BCD_SP(TableB)
- move.l Z80_BCDstack(TableB,d7.w),Z80_BCD_DATA(TableB)
- move.w Z80_BCDstack+4(TableB,d7.w),Z80_BCD_DATA+4(TableB)
- ENDC ;IFD AFPUSHPOP_BCD
- ENDC ;IFD BCDFLAGS
- next
- ** --
- pop_xy MACRO
- Pop_I\1 opcode_2_bytes
- getz ZSP,1(Work)
- incw ZSP
- getz ZSP,(Work)
- incw ZSP
- move.w (Work),Z80_I\1(TableB)
- skip 1
- next
- ENDM
- do_xy pop_xy
- ** --
- push_qq MACRO
- Push_\1\2 decw ZSP
- putz \1,ZSP
- decw ZSP
- putz \2,ZSP,2 ;2nd use
- next
- ENDM
- do_ss push_qq
- ** --
- Push_HL move.w HL,(Work)
- decw ZSP
- putz (Work),ZSP
- decw ZSP
- putz HL,ZSP,2 ;2nd use
- next
- ** --
- ;680x0 XNZVC (CCR) to Z80 VnCSZ (F) translation table.
- ; S = N. X maps to n (BCD negative).
-
- ;0,C, V, VC, Z, ZC, ZV, ZVC,
- Push_AF_table dc.b 0,%100,%10000,%10100,1,%101,%10001,%10101
- ;N, NC, NV, NVC, NZ, NZC, NZV, NZVC,
- dc.b %10,%110,%10010,%10110,%11,%111,%10011,%10111
- ;X, XC, XV, XVC, XZ, XZC, XZV, XZVC,
- dc.b %1000,%1100,%11000,%11100,%1001,%1101,%11001,%11101
- ;XN, XNC, XNV, XNVC, XNZ, XNZC, XNZV, XNZVC,
- dc.b %1010,%1110,%11010,%11110,%1011,%1111,%11011,%11111
-
- Push_AF decw ZSP
- putz A,ZSP
- decw ZSP
- IFND AFPUSHPOP_CCR
- ;Remap CCR form in d6 to Z80 F-format before pushing.
- ;No information must be lost!
- ;V=P/V, N=S, n is Z80 BCD negative. h is Z80 bcd half-carry.
- move.w d6,d7
- swap d6 ;don't destroy CCR flags
- move.w d7,d6
- and.w #%11100000,d6 ;d6 = ---00000
- and.w #$001F,d7 ;d7 = 000XNZVC
- or.b Push_AF_table(pc,d7.w),d6 ;d6 = ---VnCSZ
- ror.b #2,d6 ;d6 = SZ---VnC
- putz d6,ZSP,2 ;2nd use ;push F
- swap d6 ;restore CCR form
- ELSE
- ;Push the CCR directly.
- putz d6,ZSP,2 ;2nd use
- ENDC
- IFD BCDFLAGS
- IFD AFPUSHPOP_BCD
- ;Stack grows in positive direction. Data size is 6 bytes.
- ;Push stores, then increments.
- move.w Z80_BCD_SP(TableB),d7
- move.l Z80_BCD_DATA(TableB),Z80_BCDstack(TableB,d7.w)
- move.w Z80_BCD_DATA+4(TableB),Z80_BCDstack+4(TableB,d7.w)
- addq.w #6,d7
- cmp.w #6*Z80_BCDSTACKSIZE,d7
- blt.s .nowrap
- clr.w d7
- .nowrap move.w d7,Z80_BCD_SP(TableB)
- ENDC ;IFD AFPUSHPOP_BCD
- ENDC ;IFD BCDFLAGS
- next
- ** --
- push_xy MACRO
- Push_I\1 opcode_2_bytes
- move.w Z80_I\1(TableB),(Work)
- decw ZSP
- putz (Work),ZSP
- decw ZSP
- putz 1(Work),ZSP,2 ;2nd use
- skip 1
- next
- ENDM
- do_xy push_xy
- ** --
- res_b_r MACRO
- Res_\1_\2 opcode_2_bytes
- bclr #\1,\2
- skip 1
- next
- ENDM
-
- res_b_H MACRO
- Res_\1_H opcode_2_bytes
- bclr #8+(\1),HL
- skip 1
- next
- ENDM
-
- res_b_1HL1 MACRO
- Res_\1_1HL1 opcode_2_bytes
- IFD Z80_MEMCHECK
- getz HL,d7
- bclr #\1,d7
- putz d7,HL
- ELSE
- bclr #\1,(Z0,HL.w)
- ENDC
- skip 1
- next
- ENDM
-
- res_b_1xy1 MACRO
- Res_\1_1I\2_d1 opcode_3_bytes
- index \2
- IFD Z80_MEMCHECK
- getz d7,(Work)
- bclr #\1,(Work)
- putz (Work),d7
- ELSE
- bclr #\1,(Z0,d7.w)
- ENDC
- skip 3
- next
- ENDM
-
- res_b MACRO
- res_b_r \1,A
- res_b_r \1,B
- res_b_r \1,C
- res_b_r \1,D
- res_b_r \1,E
- res_b_r \1,L
- res_b_H \1
- res_b_1HL1 \1
- res_b_1xy1 \1,X
- res_b_1xy1 \1,Y
- ENDM
-
- res_b 0
- res_b 1
- res_b 2
- res_b 3
- res_b 4
- res_b 5
- res_b 6
- res_b 7
- ** --
- Ret getz ZSP,1(Work)
- incw ZSP
- getz ZSP,(Work)
- incw ZSP
- move.w (Work),d7
- makePPC
- testreq
- ** --
- ret_cc MACRO
- Ret_\1 getsr
- b\2.s 101$ ;label in testreq macro
- getz ZSP,1(Work)
- incw ZSP
- getz ZSP,(Work)
- incw ZSP
- move.w (Work),d7
- makePPC
- testreq
- ENDM
- ret_cc NZ,eq
- ret_cc Z,ne
- ret_cc NC,cs
- ret_cc C,cc
- ret_cc PO,vs
- ret_cc PE,vc
- ret_cc P,mi
- ret_cc M,pl
- ** --
-
- ** Reti and Retn are in 'impldept.a'
-
- ** --
- rl_r MACRO
- Rl_\1 opcode_2_bytes
- lsr.w #1,d6 ;carry to X
- roxl.b #1,\1 ;V cleared
- putsr d6
- parity \1
- skip 1
- next
- ENDM
- do_r rl_r
- ** --
- Rl_H opcode_2_bytes
- move.w HL,(Work)
- clr.w d7 ;for parity index
- move.b (Work),d7
- lsr.w #1,d6
- roxl.b #1,d7
- putsr d6
- parity d7
- move.b d7,(Work)
- move.w (Work),HL
- skip 1
- next
- ** --
- Rl_1HL1 opcode_2_bytes
- clr.w d7
- getz HL,d7
- lsr.w #1,d6
- roxl.b #1,d7
- putsr d6
- parity d7
- putz d7,HL
- skip 1
- next
- ** --
- rl_1xy1 MACRO
- Rl_1I\1_d1 opcode_3_bytes
- index \1
- move.w A,(Work)
- getz d7,A ;bits 15-8 already clear
- lsr.w #1,d6
- roxl.b #1,A
- putsr d6
- parity A
- putz A,d7
- move.w (Work),A
- skip 3
- next
- ENDM
- do_xy rl_1xy1
- ** --
- Rla move.w d6,d7
- or.w #1,d6
- lsr.w #1,d7
- roxl.b #1,A
- bcs.s .cs
- and.w #%1110,d6
- .cs next
- ** --
- Rlca or.w #1,d6
- rol.b #1,A
- bcs.s .cs
- and.w #%1110,d6
- .cs next
- ** --
- rlc_r MACRO
- Rlc_\1 opcode_2_bytes
- rol.b #1,\1 ;V is cleared
- putsr d6
- parity \1
- skip 1
- next
- ENDM
- do_r rlc_r
- ** --
- Rlc_H opcode_2_bytes
- move.w HL,(Work)
- clr.w d7 ;for parity index
- move.b (Work),d7
- rol.b #1,d7
- putsr d6
- parity d7
- move.b d7,(Work)
- move.w (Work),HL
- skip 1
- next
- ** --
- Rlc_1HL1 opcode_2_bytes
- clr.w d7
- getz HL,d7
- rol.b #1,d7
- putsr d6
- parity d7
- putz d7,HL
- skip 1
- next
- ** --
- rlc_1xy1 MACRO
- Rlc_1I\1_d1 opcode_3_bytes
- index \1
- move.w A,(Work)
- getz d7,A
- rol.b #1,A
- putsr d6
- parity A
- putz A,d7
- move.w (Work),A
- skip 3
- next
- ENDM
- do_xy rlc_1xy1
- ** --
- Rld opcode_2_bytes
- swap d6
- getz HL,d6
- rol.b #4,d6 ;swap nibbles of (HL)
- move.b d6,d7 ;save this
- eor.b A,d6 ;insert low nibble of A
- and.b #$f0,d6
- eor.b A,d6
- putz d6,HL ;store result in (HL)
- eor.b d7,A ;low nibble of saved byte to A
- and.b #$f0,A
- eor.b d7,A ;V reset, N & Z tested
- putsr d7
- swap d6
- eor.w d7,d6 ;join old carry with
- and.w #1,d6 ; new Z & N and the cleared V.
- eor.w d7,d6
- parity A ;parity to V
- skip 1
- next
- ** --
- rr_r MACRO
- Rr_\1 opcode_2_bytes
- lsr.w #1,d6 ;carry to extend
- roxr.b #1,\1 ;V cleared
- putsr d6
- parity \1
- skip 1
- next
- ENDM
- do_r rr_r
- ** --
- Rr_H opcode_2_bytes
- move.w HL,(Work)
- clr.w d7
- move.b (Work),d7
- lsr.w #1,d6
- roxr.b #1,d7
- putsr d6
- parity d7
- move.b d7,(Work)
- move.w (Work),HL
- skip 1
- next
- ** --
- Rr_1HL1 opcode_2_bytes
- clr.w d7
- getz HL,d7
- lsr.w #1,d6
- roxr.b #1,d7
- putsr d6
- parity d7
- putz d7,HL
- skip 1
- next
- ** --
- rr_1xy1 MACRO
- Rr_1I\1_d1 opcode_3_bytes
- index \1
- move.w A,(Work)
- getz d7,A
- lsr.w #1,d6
- roxr.b #1,A
- putsr d6
- parity A
- putz A,d7
- move.w (Work),A
- skip 3
- next
- ENDM
- do_xy rr_1xy1
- ** --
- Rra move.w d6,d7
- or.w #1,d6
- lsr.w #1,d7
- roxr.b #1,A
- bcs.s .cs
- and.w #%1110,d6
- .cs next
- ** --
- rrc_r MACRO
- Rrc_\1 opcode_2_bytes
- ror.b #1,\1
- putsr d6
- parity \1
- skip 1
- next
- ENDM
- do_r rrc_r
- ** --
- Rrc_H opcode_2_bytes
- move.w HL,(Work)
- clr.w d7
- move.b (Work),d7
- ror.b #1,d7
- putsr d6
- parity d7
- move.b d7,(Work)
- move.w (Work),HL
- skip 1
- next
- ** --
- Rrc_1HL1 opcode_2_bytes
- clr.w d7
- getz HL,d7
- ror.b #1,d7
- putsr d6
- parity d7
- putz d7,HL
- skip 1
- next
- ** --
- rrc_1xy1 MACRO
- Rrc_1I\1_d1 opcode_3_bytes
- index \1
- move.w A,(Work)
- getz d7,A
- ror.b #1,A
- putsr d6
- parity A
- putz A,d7
- move.w (Work),A
- skip 3
- next
- ENDM
- do_xy rrc_1xy1
- ** --
- Rrca or.w #1,d6
- ror.b #1,A
- bcs.s .cs
- and.w #%1110,d6
- .cs next
- ** --
- Rrd opcode_2_bytes
- swap d6
- getz HL,d6
- move.b A,d7 ;save A
- eor.b d6,A ;low nibble of (HL) to A
- and.b #$f0,A
- eor.b d6,A
- eor.b d7,d6 ;low nibble of saved A to (HL)
- and.b #$f0,d6
- eor.b d7,d6
- rol.b #4,d6 ;swap nibbles of (HL)
- putz d6,HL
- tst.b A ;test N & Z, clear V
- putsr d7
- swap d6
- eor.w d7,d6 ;join old carry with
- and.w #1,d6 ; new Z & N and the cleared V.
- eor.w d7,d6
- parity A ;parity to V
- skip 1
- next
- ** --
- rst_p MACRO
- Rst_\1 getRPC
- move.w d7,(Work)
- decw ZSP
- putz (Work),ZSP
- decw ZSP
- putz d7,ZSP,2 ;2nd use
- moveq #\1,d7
- makePPC
- testreq
- ENDM
- rst_p 0
- rst_p 8
- rst_p 16
- rst_p 24
- rst_p 32
- rst_p 40
- rst_p 48
- rst_p 56
- ** --
- sbc_A_r MACRO
- Sbc_A_\1
- IFD BCDFLAGS
- move.b A,Z80_BCD_A(TableB) ;BCD_A=A
- move.b \1,Z80_BCD_B(TableB) ;BCD_B=r
- 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 \1,A
- putsr d6
- next
- ENDM
- do_r sbc_A_r
- ** --
- Sbc_A_H move.w HL,(Work)
- move.b (Work),d7
- IFD BCDFLAGS
- move.b A,Z80_BCD_A(TableB)
- move.b d7,Z80_BCD_B(TableB)
- move.w d6,Z80_BCD_C(TableB)
- move.w #OP_SBC,Z80_BCD_OP(TableB)
- ENDC
- lsr.w #1,d6
- ori #4,CCR
- subx.b d7,A
- putsr d6
- next
- ** --
- Sbc_A_n getRPC
- getz d7,d7
- IFD BCDFLAGS
- move.b A,Z80_BCD_A(TableB)
- move.b d7,Z80_BCD_B(TableB)
- move.w d6,Z80_BCD_C(TableB)
- move.w #OP_SBC,Z80_BCD_OP(TableB)
- ENDC
- lsr.w #1,d6
- ori #4,CCR
- subx.b d7,A
- putsr d6
- skip 1
- next
- ** --
- Sbc_A_1HL1 getz HL,d7
- IFD BCDFLAGS
- move.b A,Z80_BCD_A(TableB)
- move.b d7,Z80_BCD_B(TableB)
- move.w d6,Z80_BCD_C(TableB)
- move.w #OP_SBC,Z80_BCD_OP(TableB)
- ENDC
- lsr.w #1,d6
- ori #4,CCR
- subx.b d7,A
- putsr d6
- next
- ** --
- sbc_A_1xy1 MACRO
- Sbc_A_1I\1_d1 opcode_2_bytes
- index \1
- getz d7,d7
- IFD BCDFLAGS
- move.b A,Z80_BCD_A(TableB)
- move.b d7,Z80_BCD_B(TableB)
- move.w d6,Z80_BCD_C(TableB)
- move.w #OP_SBC,Z80_BCD_OP(TableB)
- ENDC
- lsr.w #1,d6
- ori #4,CCR
- subx.b d7,A
- putsr d6
- skip 2
- next
- ENDM
- do_xy sbc_A_1xy1
- ** --
- sbc_HL_ss MACRO
- Sbc_HL_\1\2 opcode_2_bytes
- join \1,\2
- lsr.w #1,d6
- ori #4,CCR
- subx.w d7,HL
- putsr d6
- skip 1
- next
- ENDM
- do_ss sbc_HL_ss
- ** --
- Sbc_HL_HL opcode_2_bytes
- lsr.w #1,d6
- ori #4,CCR
- subx.w HL,HL
- putsr d6
- skip 1
- next
- ** --
- Sbc_HL_SP opcode_2_bytes
- move.w ZSP,d7
- lsr #1,d6
- ori #4,CCR
- subx.w d7,HL
- putsr d6
- skip 1
- next
- ** --
- Scf or.w #1,d6
- next
- ** --
- set_b_r MACRO
- Set_\1_\2 opcode_2_bytes
- bset #\1,\2
- skip 1
- next
- ENDM
-
- set_b_H MACRO
- Set_\1_H opcode_2_bytes
- bset #8+\1,HL
- skip 1
- next
- ENDM
-
- set_b_1HL1 MACRO
- Set_\1_1HL1 opcode_2_bytes
- IFD Z80_MEMCHECK
- getz HL,d7
- bset #\1,d7
- putz d7,HL
- ELSE
- bset #\1,(Z0,HL.w)
- ENDC
- skip 1
- next
- ENDM
-
- set_b_1xy1 MACRO
- Set_\1_1I\2_d1 opcode_3_bytes
- index \2
- IFD Z80_MEMCHECK
- getz d7,(Work)
- bset #\1,(Work)
- putz (Work),d7
- ELSE
- bset #\1,(Z0,d7.w)
- ENDC
- skip 3
- next
- ENDM
-
- set_b MACRO
- set_b_r \1,A
- set_b_r \1,B
- set_b_r \1,C
- set_b_r \1,D
- set_b_r \1,E
- set_b_r \1,L
- set_b_H \1
- set_b_1HL1 \1
- set_b_1xy1 \1,X
- set_b_1xy1 \1,Y
- ENDM
-
- set_b 0
- set_b 1
- set_b 2
- set_b 3
- set_b 4
- set_b 5
- set_b 6
- set_b 7
- ** --
- sla_r MACRO
- Sla_\1 opcode_2_bytes
- lsl.b #1,\1 ;V is cleared (it's not with Asl!)
- putsr d6
- parity \1
- skip 1
- next
- ENDM
- do_r sla_r
- ** --
- Sla_H opcode_2_bytes
- move.w HL,(Work)
- clr.w d7 ;for parity index
- move.b (Work),d7
- lsl.b #1,d7
- putsr d6
- parity d7
- move.b d7,(Work)
- move.w (Work),HL
- skip 1
- next
- ** --
- Sla_1HL1 opcode_2_bytes
- clr.w d7
- getz HL,d7
- lsl.b #1,d7
- putsr d6
- parity d7
- putz d7,HL
- skip 1
- next
- ** --
- sla_1xy1 MACRO
- Sla_1I\1_d1 opcode_3_bytes
- index \1
- move.w A,(Work)
- getz d7,A
- lsl.b #1,A
- putsr d6
- parity A
- putz A,d7
- move.w (Work),A
- skip 3
- next
- ENDM
- do_xy sla_1xy1
- ** --
- sra_r MACRO
- Sra_\1 opcode_2_bytes
- asr.b #1,\1 ;V is reset, since sign doesn't change.
- putsr d6
- parity \1
- skip 1
- next
- ENDM
- do_r sra_r
- ** --
- Sra_H opcode_2_bytes
- move.w HL,(Work)
- clr.w d7
- move.b (Work),d7
- asr.b #1,d7
- putsr d6
- parity d7
- move.b d7,(Work)
- move.w (Work),HL
- skip 1
- next
- ** --
- Sra_1HL1 opcode_2_bytes
- clr.w d7
- getz HL,d7
- asr.b #1,d7
- putsr d6
- parity d7
- putz d7,HL
- skip 1
- next
- ** --
- sra_1xy1 MACRO
- Sra_1I\1_d1 opcode_3_bytes
- index \1
- move.w A,(Work)
- getz d7,A
- asr.b #1,A
- putsr d6
- parity A
- putz A,d7
- move.w (Work),A
- skip 3
- next
- ENDM
- do_xy sra_1xy1
- ** --
- srl_r MACRO
- Srl_\1 opcode_2_bytes
- lsr.b #1,\1 ;V is cleared
- putsr d6
- parity \1
- skip 1
- next
- ENDM
- do_r srl_r
- ** --
- Srl_H opcode_2_bytes
- move.w HL,(Work)
- clr.w d7
- move.b (Work),d7
- lsr.b #1,d7
- putsr d6
- parity d7
- move.b d7,(Work)
- move.w (Work),HL
- skip 1
- next
- ** --
- Srl_1HL1 opcode_2_bytes
- clr.w d7
- getz HL,d7
- lsr.b #1,d7
- putsr d6
- parity d7
- putz d7,HL
- skip 1
- next
- ** --
- srl_1xy1 MACRO
- Srl_1I\1_d1 opcode_3_bytes
- index \1
- move.w A,(Work)
- getz d7,A
- lsr.b #1,A
- putsr d6
- parity A
- putz A,d7
- move.w (Work),A
- skip 3
- next
- ENDM
- do_xy srl_1xy1
- ** --
- sub_r MACRO
- Sub_\1
- IFD BCDFLAGS
- move.b A,Z80_BCD_A(TableB) ;BCD_A=A
- move.b \1,Z80_BCD_B(TableB) ;BCD_B=r
- move.w #OP_SUB,Z80_BCD_OP(TableB) ;BCD_OP=sub
- ENDC
- sub.b \1,A
- putsr d6
- next
- ENDM
- do_r sub_r
- ** --
- Sub_H move.w HL,(Work)
- IFD BCDFLAGS
- move.b A,Z80_BCD_A(TableB)
- move.b (Work),Z80_BCD_B(TableB)
- move.w #OP_SUB,Z80_BCD_OP(TableB)
- ENDC
- sub.b (Work),A
- putsr d6
- next
- ** --
- Sub_n getRPC
- getz d7,d7
- IFD BCDFLAGS
- move.b A,Z80_BCD_A(TableB)
- move.b d7,Z80_BCD_B(TableB)
- move.w #OP_SUB,Z80_BCD_OP(TableB)
- ENDC
- sub.b d7,A
- putsr d6
- skip 1
- next
- ** --
- Sub_1HL1 getz HL,d7
- IFD BCDFLAGS
- move.b A,Z80_BCD_A(TableB)
- move.b d7,Z80_BCD_B(TableB)
- move.w #OP_SUB,Z80_BCD_OP(TableB)
- ENDC
- sub.b d7,A
- putsr d6
- next
- ** --
- sub_1xy1 MACRO
- Sub_1I\1_d1 opcode_2_bytes
- index \1
- getz d7,d7
- IFD BCDFLAGS
- move.b A,Z80_BCD_A(TableB)
- move.b d7,Z80_BCD_B(TableB)
- move.w #OP_SUB,Z80_BCD_OP(TableB)
- ENDC
- sub.b d7,A
- putsr d6
- skip 2
- next
- ENDM
- do_xy sub_1xy1
- ** --
- xor_r MACRO
- Xor_\1 eor.b \1,A ;V and C are reset
- putsr d6
- parity A
- next
- ENDM
- do_r xor_r
- ** --
- Xor_H move.w HL,(Work)
- move.b (Work),d7
- eor.b d7,A
- putsr d6
- parity A
- next
- ** --
- Xor_n getRPC
- getz d7,d7
- eor.b d7,A
- putsr d6
- parity A
- skip 1
- next
- ** --
- Xor_1HL1 getz HL,d7
- eor.b d7,A
- putsr d6
- parity A
- next
- ** --
- xor_1xy1 MACRO
- Xor_1I\1_d1 opcode_2_bytes
- index \1
- getz d7,d7
- eor.b d7,A
- putsr d6
- parity A
- skip 2
- next
- ENDM
- do_xy xor_1xy1
-
- ** =====================================================================
-
- ** Why stop now, just when I'm hating it?
-