title MACRO LIBRARY ; note: macros4.z80 contains 4 byte macros list off ;* load - general load macro load macro #dst,#src if "#src(1)" = "(" if "#src" = "(hl)" ldm #dst,#src ;;(hl) load else load2 #dst,#src ;;(ix+..) load endif else ldr #dst,#src ;;register load endif mend ;* stor - general store macro stor macro #src,#dst if "#dst" = "(hl)" stm #src,#dst ;;(hl) store else stor2 #src,#dst ;;(ix+..) store endif mend ;* ldr - load register ldr macro #dst,#src if ("#src(1)" = "i") or ("#dst(1)" = "i") push #src pop #dst else ld #dst(1),#src(1) ld #dst(2),#src(2) endif mend ;* ldm - load from memory (hl) ldm macro #dst irpc #arg,'#dst(4)#dst(3)#dst(2)#dst(1)' ld #arg,(hl) inc hl mend irpc mend ;* stm - store to memory (hl) stm macro #src irpc #arg,'#src(4)#src(3)#src(2)#src(1)' ld (hl),#arg inc hl mend irpc mend ;* load2 - load from indexed memory load2 macro #dst,#mem ld #dst(2),#mem ld #dst(1),#mem+1 mend ;* load4 - load from indexed memory load4 macro #dst,#mem ld #dst(4),#mem ld #dst(3),#mem+1 ld #dst(2),#mem+2 ld #dst(1),#mem+3 mend ;* load6 - load 6 byte number load6 macro #dst,#mem ld #dst(6),#mem ld #dst(5),#mem+1 ld #dst(4),#mem+2 ld #dst(3),#mem+3 ld #dst(2),#mem+4 ld #dst(1),#mem+5 mend ;* loadx - load from indexed memory (byte reversed) loadx macro #dst,#mem ld #dst(1),#mem ld #dst(2),#mem+1 mend ;* load4x - load from indexed memory (byte reversed) load4x macro #dst,#mem ld #dst(1),#mem ld #dst(2),#mem+1 ld #dst(3),#mem+2 ld #dst(4),#mem+3 mend ;* load6x - load 6 byte number (byte reversed) load6x macro #dst,#mem ld #dst(1),#mem ld #dst(2),#mem+1 ld #dst(3),#mem+2 ld #dst(4),#mem+3 ld #dst(5),#mem+4 ld #dst(6),#mem+5 mend ;* stor2 - store into indexed memory stor2 macro #src,#mem ld #mem,#src(2) ld #mem+1,#src(1) mend ;* stor4 - store into indexed memory stor4 macro #src,#mem ld #mem,#src(4) ld #mem+1,#src(3) ld #mem+2,#src(2) ld #mem+3,#src(1) mend ;* stor6 - store into indexed memory stor6 macro #src,#mem ld #mem,#src(6) ld #mem+1,#src(5) ld #mem+2,#src(4) ld #mem+3,#src(3) ld #mem+4,#src(2) ld #mem+5,#src(1) mend ;* storx - store into indexed memory (byte reversed) storx macro #src,#mem ld #mem,#src(1) ld #mem+1,#src(2) mend ;* stor4x - store into indexed memory (byte reversed) stor4x macro #src,#mem ld #mem,#src(1) ld #mem+1,#src(2) ld #mem+2,#src(3) ld #mem+3,#src(4) mend ;* stor6x - store into indexed memory (byte reversed) stor6x macro #src,#mem ld #mem,#src(1) ld #mem+1,#src(2) ld #mem+2,#src(3) ld #mem+3,#src(4) ld #mem+4,#src(5) ld #mem+5,#src(6) mend ;* cmpr - general compare macro cmpr macro #reg,#dst if "#dst(1)" = "(" cmpr2 #reg,#dst ;;memory compare else cpr #reg,#dst ;;register compare endif mend ;* cmpr2 - compare 2 bytes with indexed memory cmpr2 macro #reg,#mem ld a,#reg(1) cp a,#mem+1 jr nz,..#sym ld a,#reg(2) cp a,#mem ..#sym: mend ;* cmprx - compare 2 bytes with indexed memory (byte reversed) cmprx macro #reg,#mem ld a,#reg(1) cp a,#mem jr nz,..#sym ld a,#reg(2) cp a,#mem+1 ..#sym: mend ;* cmpi - compare 2 bytes immediate cmpi macro #reg,#val ld a,#reg(1) cp a,high (#val) jr nz,..#sym ld a,#reg(2) cp a,low (#val) ..#sym: mend ;* cpr - compare register cpr macro #1,#2 ld a,#1(1) cp a,#2(1) jr nz,..#sym ld a,#1(2) cp a,#2(2) ..#sym: mend ;* cpl2 -- complement 2 bytes cpl2 macro #reg ld a,#reg(1) cpl ld #reg(1),a ld a,#reg(2) cpl ld #reg(2),a mend ;* cpl4 -- complement 4 bytes cpl4 macro #reg cpl2 #reg(1,2) cpl2 #reg(3,4) mend ;* neg2 -- negate 2 bytes neg2 macro #reg cpl2 #reg inc #reg mend ;* neg4 -- negate 4 bytes neg4 macro #reg cpl4 #reg inc #reg(3,4) test #reg(3,4) jr nz,..#sym inc #reg(1,2) ..#sym: mend ;* test -- test registers for zero test macro #reg ld a,#reg(1) if "#reg(2)" = "" or a,a else irpc #arg,'#reg(2,-1)' or a,#arg mend irpc endif mend ;* test1 -- macro to test 1 byte of indexed memory test1 macro #mem ld a,#mem or a,a mend ;* test2 -- macro to test 2 bytes of indexed memory test2 macro #mem ld a,#mem or a,#mem+1 mend ;* test4 -- macro to test 4 bytes of indexed memory test4 macro #mem ld a,#mem or a,#mem+1 or a,#mem+2 or a,#mem+3 mend ;* clr1 -- macro to clear (zero) 1 byte of indexed memory clr1 macro #mem ld #mem,0 mend ;* clr2 -- macro to clear (zero) 2 bytes of indexed memory clr2 macro #mem ld #mem,0 ld #mem+1,0 mend ;* clr4 -- macro to clear (zero) 4 bytes of indexed memory clr4 macro #mem ld #mem,0 ld #mem+1,0 ld #mem+2,0 ld #mem+3,0 mend ;* stori1 -- store immediate 1 byte stori1 macro #mem,#val ld #mem,#val mend ;* stori2 -- store immediate 2 bytes stori2 macro #mem,#val ld #mem,low (#val) ld #mem+1,high (#val) mend ;* stori4 -- store immediate 4 bytes stori4 macro #mem,#hval,#lval stori2 #mem,#lval stori2 #mem+2,#hval mend ;* inc1 -- increment 1 byte of indexed memory inc1 macro #mem inc #mem mend ;* inc2 -- increment 2 bytes of indexed memory inc2 macro #mem inc #mem jr nz,..#sym inc #mem+1 ..#sym: mend ;* inc4 -- increment 4 bytes of indexed memory inc4 macro #mem inc #mem jr nz,..#sym inc #mem+1 jr nz,..#sym inc #mem+2 jr nz,..#sym inc #mem+3 ..#sym: mend ;* seterr -- set ERR flag seterr macro scf mend ;* clrerr -- clear ERR flag clrerr macro or a,a mend ;* reterr -- return error code reterr macro #err ld a,#err scf mend ;* srl2 -- shift 2 bytes right logical srl2 macro #reg srl #reg(1) rr #reg(2) mend ;* srl4 -- shift 4 bytes right logical srl4 macro #reg srl #reg(1) rr #reg(2) rr #reg(3) rr #reg(4) mend ;* sra2 -- shift 2 bytes right arithmetic sra2 macro #reg sra #reg(1) rr #reg(2) mend ;* sra4 -- shift 4 bytes right arithmetic sra4 macro #reg sra #reg(1) rr #reg(2) rr #reg(3) rr #reg(4) mend ;* sla2 -- shift 2 bytes left arithmetic sla2 macro #reg sla #reg(2) rl #reg(1) mend ;* sla4 -- shift 4 bytes left arithmetic sla4 macro #reg sla #reg(4) rl #reg(3) rl #reg(2) rl #reg(1) mend ;* rl2 -- rotate 2 bytes left rl2 macro #reg rl #reg(2) rl #reg(1) mend ;* rl4 -- rotate 4 bytes left rl4 macro #reg rl #reg(4) rl #reg(3) rl #reg(2) rl #reg(1) mend ;* rr2 -- rotate 2 bytes right rr2 macro #reg rr #reg(1) rr #reg(2) mend ;* rr4 -- rotate 4 bytes right rr4 macro #reg rr #reg(1) rr #reg(2) rr #reg(3) rr #reg(4) mend ;* subhl--macro to subtract a double register from hl, clearing carry first subhl macro #reg or a,a sbc hl,#reg mend ;* disable -- macro to save interrupt state & disable interrupts disable macro ld a,i di push af mend ;* enable -- macro to restore interrupt state enable macro pop af jp po,en#sym ei en#sym: mend ;* save -- macro to save many registers (af,bc,de,hl,ix,iy) ; note: registers are push'ed in order save macro #1,#2,#3,#4,#5,#6 irp #arg,#1,#2,#3,#4,#5,#6 if "#arg" <> "" push #arg endif mend irp mend ;* restor -- macro to restore many registers ; note: registers are pop'ed in reverse order restor macro #1,#2,#3,#4,#5,#6 irp #arg,#6,#5,#4,#3,#2,#1 if "#arg" <> "" pop #arg endif mend irp mend *include macros4.z80 ;include in listing list on