0 Members and 1 Guest are viewing this topic.
p_88Mul: .db __88MulEnd-1-$ ld a,h xor d push af bit 7,h jr z,$+8 xor a sub l ld l,a sbc a,a sub h ld h,a bit 7,d jr z,$+8 xor a sub e ld e,a sbc a,a sub d ld d,a call $3F00+sub_MulFull ld l,h ld h,a pop af xor h ret p xor a sub l ld l,a sbc a,a sub h ld h,a ret__88MulEnd:
p_88Mul: .db __88MulEnd-1-$ push hl call $3F00+sub_MulFull pop bc bit 7,b jr z,$+3 sub e ld l,h ld h,a bit 7,d ret z sub c ld h,a ret__88MulEnd:
p_88Mul: .db __88MulEnd-1-$ push hl ld c,l ld a,h ld l,0 ld b,b \ .db 8 \ call $3F00+sub_Mul ld a,c ld bc,8<<8+0__88MulNext: add hl,hl rla jr nc,__88MulSkip add hl,de adc a,c__88MulSkip: djnz __88MulNext pop bc bit 7,b jr z,$+3 sub e ld l,h ld h,a bit 7,d ret z sub c ld h,a ret__88MulEnd:
p_88Mul: .db __88MulEnd-1-$ push hl ld c,l ld a,h ld l,0 ld b,b \ .db 8 \ call $3F00+sub_Mul ld b,8__88MulNext: add hl,hl rla rl c jr nc,__88MulSkip add hl,de adc a,0__88MulSkip: djnz __88MulNext pop bc bit 7,b jr z,$+3 sub e ld l,h ld h,a bit 7,d ret z sub c ld h,a ret__88MulEnd:
ld de,-range add hl,de ld de,jumptable_end jr c,default add hl,hl add hl,de ld e,(hl) inc hl ld d,(hl)default: ex de,hl jp (hl) .dw Label0 .dw Label1 .dw Label2 ;.....jumptable_end:
ld de,-range add hl,de jr c,default add hl,hl ld de,jumptable_end add hl,de ld e,(hl) inc hl ld d,(hl) ex de,hl jp (hl)default:
ld de,-range add hl,de jr c,routine_end ex de,hl ld hl,jumptable_end add hl,de ld a,(hl) add hl,de ld l,(hl) ld h,a jp (hl)routine_end:
p_SGT0: .db 8 ld a,h or l jr z,$+6 add hl,hl sbc hl,hl inc hlp_SLE0: .db 9 ld a,h or l jr z,$+6 add hl,hl ccf sbc hl,hl inc hlp_SLtLeXX: .db 11 ld a,h add a,$80 ld h,a ld de,$0000 ;$8000-const add hl,de sbc hl,hl inc hl .db rp_Ans,6p_SGtGeXX: .db 12 ld a,h add a,$80 ld h,a xor a ld de,$0000 ;$8000-const add hl,de ld h,a rla ld l,a .db rp_Ans,6p_SIntGt: .db 11 scf sbc hl,de add hl,hl jp pe,$+4 ccf sbc hl,hl inc hlp_SIntGe: .db 11 xor a sbc hl,de add hl,hl jp po,$+4 ccf ld h,a rla ld l,ap_SIntLt: .db 11 scf sbc hl,de add hl,hl jp po,$+4 ccf sbc hl,hl inc hlp_SIntLe: .db 11 xor a sbc hl,de add hl,hl jp pe,$+4 ccf ld h,a rla ld l,a
xor a ld e,a dec a__DrawOffShift: srl c rr e rra djnz __DrawOffShift dec d jr z,__DrawOffSkipRight ld b,a and (hl) or e ld (hl),a ld a,b__DrawOffSkipRight: dec hl inc d jr z,__DrawOffSkipLeft cpl and (hl) or c ld (hl),a__DrawOffSkipLeft:
xor a ld e,$FF__DrawOffShift: srl c rr e rra djnz __DrawOffShift dec d jr z,__DrawOffSkipRight ld b,a or (hl) and e ld (hl),a ld a,b__DrawOffSkipRight: dec hl inc d jr z,__DrawOffSkipLeft and (hl) or c ld (hl),a__DrawOffSkipLeft:
p_Pix: .db __PixEnd-1-$ ;Draws pixel (c,l) ld de,plotSScreen pop af pop bc push af ld b,0 ld a,l cp 64 ld a,b ret nc ld a,c cp 96 ld a,b ret nc ld h,b ld a,l add a,a add a,l ld l,a add hl,hl add hl,hl add hl,de ld a,c srl c srl c srl c add hl,bc and %00000111 ld b,a ld a,%10000000 ret z___GetPixLoop: rrca djnz ___GetPixLoop ret__PixEnd:
p_Pix: .db __PixEnd-1-$ ;Draws pixel (c,l) ld de,plotSScreen pop af pop bc push af ld b,0 ld a,c cp 96 ld a,b ret nc sla l ret c sla l ret c ld h,b ex de,hl add hl,de add hl,de add hl,de ld a,c srl c srl c srl c add hl,bc and %00000111 ld b,a ld a,%10000000 ret z___GetPixLoop: rrca djnz ___GetPixLoop ret__PixEnd:
p_ArcTan: .db __ArcTanEnd-1-$ ex de,hl ;de = y pop hl ex (sp),hl ;hl = x push hl ld a,h ;\ xor d ;/ Get parity jp m,__ArcTanSS-p_ArcTan-1 add hl,de ;\ jr __ArcTanDS ; |__ArcTanSS: ; |hl = x +- y sbc hl,de ; |__ArcTanDS: ;/ ex de,hl ;de = x +- y ld b,6 ;\__ArcTan64: ; | add hl,hl ; |hl = 64y djnz __ArcTan64 ;/ call $3F00+sub_SDiv ;hl = 64y/(x +- y) pop af ;\ rla ; |Right side, fine ret nc ;/ sbc a,a ;\ sub h ; |Reverse sign extend ld h,a ;/ ld a,l ;\ add a,128 ; |Add or sub 128 ld l,a ;/ ret__ArcTanEnd:
p_ArcTan: .db __ArcTanEnd-1-$ ex de,hl ;de = y pop hl ex (sp),hl ;hl = x push hl ld a,h ;\ xor d ;/ Get parity jp m,__ArcTanSS-p_ArcTan-2 add hl,de ;\ ld c,c \ .db $FA ; | ;jr __ArcTanDS ; |__ArcTanSS: ; |hl = x +- y sbc hl,de ; |__ArcTanDS: ;/ ex de,hl ;de = x +- y ld b,6 ;\__ArcTan64: ; | add hl,hl ; |hl = 64y djnz __ArcTan64 ;/ call $3F00+sub_SDiv ;hl = 64y/(x +- y) pop af ;\ rla ; |Right side, fine ret nc ;/ sbc a,a ;\ sub h ; |Reverse sign extend ld h,a ;/ ld a,l ;\ add a,128 ; |Add or sub 128 ld l,a ;/ ret__ArcTanEnd:
p_DrawOr: .db __DrawOrEnd-1-$ push hl pop ix ;Input ix = Sprite ld hl,plotSScreen ;Input hl = Buffer pop af pop bc ;Input c = Sprite Y Position pop de ;Input e = Sprite X Position push af ld b,7 ld a,e add a,b cp 96+7 ret nc rrca rrca rrca and $1f ld d,a ld a,c add a,b jr c,__DrawOrClipTop sub 64+7 ret nc cpl cp b jr c,__DrawOrClipBottom ld a,b jr __DrawOrClipBottom__DrawOrClipTop: inc ix inc c jr nz,__DrawOrClipTop__DrawOrClipBottom: inc a ld b,0 sla c sla c add hl,bc add hl,bc add hl,bc ld c,d add hl,bc ld b,a ld a,e and 7 jr z,__DrawOrAligned ld c,a ld a,e cp -7 sbc a,a ld d,a and e cp 96-7 sbc a,a ld e,a__DrawOrLoop: push bc ld b,c ld c,(ix) xor a__DrawOrShift: srl c rra djnz __DrawOrShift and e or (hl) ld (hl),a dec hl ld a,c and d or (hl) ld (hl),a ld c,13 add hl,bc inc ix pop bc djnz __DrawOrLoop ret__DrawOrAligned: ld de,12__DrawOrAlignedLoop: ld a,(ix) or (hl) ld (hl),a inc ix add hl,de djnz __DrawOrAlignedLoop ret__DrawOrEnd:p_DrawXor: .db __DrawXorEnd-1-$ push hl pop ix ;Input ix = Sprite ld hl,plotSScreen ;Input hl = Buffer pop af pop bc ;Input c = Sprite Y Position pop de ;Input e = Sprite X Position push af ld b,7 ld a,e add a,b cp 96+7 ret nc rrca rrca rrca and $1f ld d,a ld a,c add a,b jr c,__DrawXorClipTop sub 64+7 ret nc cpl cp b jr c,__DrawXorClipBottom ld a,b jr __DrawXorClipBottom__DrawXorClipTop: inc ix inc c jr nz,__DrawXorClipTop__DrawXorClipBottom: inc a ld b,0 sla c sla c add hl,bc add hl,bc add hl,bc ld c,d add hl,bc ld b,a ld a,e and 7 jr z,__DrawXorAligned ld c,a ld a,e cp -7 sbc a,a ld d,a and e cp 96-7 sbc a,a ld e,a__DrawXorLoop: push bc ld b,c ld c,(ix) xor a__DrawXorShift: srl c rra djnz __DrawXorShift and e xor (hl) ld (hl),a dec hl ld a,c and d xor (hl) ld (hl),a ld c,13 add hl,bc inc ix pop bc djnz __DrawXorLoop ret__DrawXorAligned: ld de,12__DrawXorAlignedLoop: ld a,(ix) xor (hl) ld (hl),a inc ix add hl,de djnz __DrawXorAlignedLoop ret__DrawXorEnd:
dec hldec bcld a,bor cjr nz,__FreqOutLoop2
cpdjp pe,__FreqOutLoop2
p_FreqOut: xor a__FreqOutLoop1: push bc xor %00000011 ld e,a__FreqOutLoop2: ld a,h or l jr z,__FreqOutDone cpd ld a,e scf jp pe,__FreqOutLoop2__FreqOutDone: pop bc out ($00),a ret nc jr __FreqOutLoop1__FreqOutEnd:
p_DrawOr: .db __DrawOrEnd-1-$ push hl pop ix ;Input ix = Sprite ld hl,plotSScreen ;Input hl = Buffer pop af pop de ;Input e = Sprite Y Position pop bc ;Input c = Sprite X Position push af ld d,7 ld a,e add a,d jr c,__DrawOrClipTop sub 64+7 ret nc cpl cp d jr c,__DrawOrClipBottom ld b,d jr __DrawOrNoClipV__DrawOrClipTop: inc ix inc e jr nz,__DrawOrClipTop__DrawOrClipBottom: ld b,a__DrawOrNoClipV: ld a,c add a,d cp 96+7 ret nc rrca rrca rrca and $1f sla e sla e add hl,de add hl,de add hl,de ld e,a inc b ld a,c and d ld d,-7*3 add hl,de jr z,__DrawOrAligned ld e,c ld c,a ld a,e cp -7 sbc a,a ld d,a and e cp 96-7 sbc a,a ld e,a__DrawOrLoop: push bc ld b,c ld c,(ix) xor a__DrawOrShift: srl c rra djnz __DrawOrShift and e or (hl) ld (hl),a dec hl ld a,c and d or (hl) ld (hl),a ld c,13 add hl,bc inc ix pop bc djnz __DrawOrLoop ret__DrawOrAligned: ld de,12__DrawOrAlignedLoop: ld a,(ix) or (hl) ld (hl),a inc ix add hl,de djnz __DrawOrAlignedLoop ret__DrawOrEnd:p_DrawXor: .db __DrawXorEnd-1-$ push hl pop ix ;Input ix = Sprite ld hl,plotSScreen ;Input hl = Buffer pop af pop de ;Input e = Sprite Y Position pop bc ;Input c = Sprite X Position push af ld d,7 ld a,e add a,d jr c,__DrawXorClipTop sub 64+7 ret nc cpl cp d jr c,__DrawXorClipBottom ld b,d jr __DrawXorNoClipV__DrawXorClipTop: inc ix inc e jr nz,__DrawXorClipTop__DrawXorClipBottom: ld b,a__DrawXorNoClipV: ld a,c add a,d cp 96+7 ret nc rrca rrca rrca and $1f sla e sla e add hl,de add hl,de add hl,de ld e,a inc b ld a,c and d ld d,-7*3 add hl,de jr z,__DrawXorAligned ld e,c ld c,a ld a,e cp -7 sbc a,a ld d,a and e cp 96-7 sbc a,a ld e,a__DrawXorLoop: push bc ld b,c ld c,(ix) xor a__DrawXorShift: srl c rra djnz __DrawXorShift and e xor (hl) ld (hl),a dec hl ld a,c and d xor (hl) ld (hl),a ld c,13 add hl,bc inc ix pop bc djnz __DrawXorLoop ret__DrawXorAligned: ld de,12__DrawXorAlignedLoop: ld a,(ix) xor (hl) ld (hl),a inc ix add hl,de djnz __DrawXorAlignedLoop ret__DrawXorEnd:p_DrawOff: .db __DrawOffEnd-1-$ push hl pop ix ;Input ix = Sprite ld hl,plotSScreen ;Input hl = Buffer pop af pop de ;Input e = Sprite Y Position pop bc ;Input c = Sprite X Position push af ld d,7 ld a,e add a,d jr c,__DrawOffClipTop sub 64+7 ret nc cpl cp d jr c,__DrawOffClipBottom ld b,d jr __DrawOffNoClipV__DrawOffClipTop: inc ix inc e jr nz,__DrawOffClipTop__DrawOffClipBottom: ld b,a__DrawOffNoClipV: ld a,c add a,d cp 96+7 ret nc rrca rrca rrca and $1f ld d,0 sla e sla e add hl,de add hl,de add hl,de ld e,a add hl,de inc b ld a,c and 7 jr z,__DrawOffAligned ld e,c ld c,a ld a,e cp -7 jr nc,__DrawOffLoop inc d cp 96-7 jr nc,__DrawOffLoop inc d__DrawOffLoop: push bc ld b,c ld c,(ix+0) xor a ld e,$FF__DrawOffShift: srl c rr e rra djnz __DrawOffShift dec d jr z,__DrawOffSkipRight ld b,a or (hl) and e ld (hl),a ld a,b__DrawOffSkipRight: dec hl inc d jr z,__DrawOffSkipLeft and (hl) or c ld (hl),a__DrawOffSkipLeft: ld bc,13 add hl,bc inc ix pop bc djnz __DrawOffLoop ret__DrawOffAligned: ld e,12__DrawOffAlignedLoop: ld a,(ix) ld (hl),a inc ix add hl,de djnz __DrawOffAlignedLoop ret__DrawOffEnd:p_DrawMsk: .db __DrawMskEnd-1-$ ex (sp),hl pop ix ;Input hl = Sprite pop de pop bc push hl ld hl,plotSScreen ld d,7 ld a,e add a,d jr c,__DrawMskClipTop sub 64+7 ret nc cpl cp d jr c,__DrawMskClipBottom ld b,d jr __DrawMskNoClipV__DrawMskClipTop: inc ix inc e jr nz,__DrawMskClipTop__DrawMskClipBottom: ld b,a__DrawMskNoClipV: ld a,c add a,d cp 96+7 ret nc rrca rrca rrca and $1f ld d,0 sla e sla e add hl,de add hl,de add hl,de ld e,a add hl,de inc b ld a,c and 7 jr z,__DrawMskAligned ld e,c ld c,a ld a,e cp -7 jr nc,__DrawMskLoop inc d cp 96-7 jr nc,__DrawMskLoop inc d__DrawMskLoop: push bc push hl ld b,c ld e,(ix+0) xor a ld h,a ld c,(ix+8)__DrawMskShift: srl e rr h srl c rra djnz __DrawMskShift ld b,h pop hl push af dec d jr z,__DrawMskSkipRight1 push bc xor b cpl ld c,a ld a,(hl) or b and c ld (hl),a pop bc__DrawMskSkipRight1: dec hl inc d push de jr z,__DrawMskSkipLeft1 ld a,c xor e cpl ld d,a ld a,(hl) or e and d ld (hl),a__DrawMskSkipLeft1: ld de,appBackUpScreen-plotSScreen+1 add hl,de pop de pop af dec d jr z,__DrawMskSkipRight2 or b cpl and (hl) or b ld (hl),a__DrawMskSkipRight2: dec hl inc d jr z,__DrawMskSkipLeft2 ld a,c or e cpl and (hl) or e ld (hl),a__DrawMskSkipLeft2: ld bc,plotSScreen-appBackUpScreen+13 add hl,bc inc ix pop bc djnz __DrawMskLoop ret__DrawMskAligned: push hl ld de,appBackUpScreen-plotSScreen add hl,de ld a,(ix+0) ld d,a xor (ix+8) cpl ld e,a and (hl) or d ld (hl),a pop hl ld a,(hl) or d and e ld (hl),a inc ix ld de,12 add hl,de djnz __DrawMskAligned ret__DrawMskEnd:p_DrawMsk2: .db __DrawMsk2End-1-$ ex (sp),hl pop ix ;Input hl = Sprite pop de pop bc push hl ld hl,plotSScreen ld d,7 ld a,e add a,d jr c,__DrawMsk2ClipTop sub 64+7 ret nc cpl cp d jr c,__DrawMsk2ClipBottom ld b,d jr __DrawMsk2NoClipV__DrawMsk2ClipTop: inc ix inc e jr nz,__DrawMsk2ClipTop__DrawMsk2ClipBottom: ld b,a__DrawMsk2NoClipV: ld a,c add a,d cp 96+7 ret nc rrca rrca rrca and $1f ld d,0 sla e sla e add hl,de add hl,de add hl,de ld e,a add hl,de inc b ld a,c and 7 jr z,__DrawMsk2Aligned ld e,c ld c,a ld a,e cp -7 jr nc,__DrawMsk2Loop inc d cp 96-7 jr nc,__DrawMsk2Loop inc d__DrawMsk2Loop: push bc push hl ld b,c ld e,(ix+0) xor a ld h,a ld c,(ix+8)__DrawMsk2Shift: srl e rr h srl c rra djnz __DrawMsk2Shift ld b,h ;e = left spr, b = right spr, c = left msk, a = right msk pop hl dec d jr z,__DrawMsk2SkipRight cpl and (hl) xor b ld (hl),a__DrawMsk2SkipRight: dec hl inc d jr z,__DrawMsk2SkipLeft ld a,c cpl and (hl) xor e ld (hl),a__DrawMsk2SkipLeft: ld bc,13 add hl,bc inc ix pop bc djnz __DrawMsk2Loop ret__DrawMsk2Aligned: ld e,12__DrawMsk2AlignedLoop: ld a,(ix+8) cpl and (hl) xor (ix+0) ld (hl),a inc ix add hl,de djnz __DrawMsk2AlignedLoop ret__DrawMsk2End:
p_MulFull: .db __MulFullEnd-1-$ ld c,h ld a,l ld hl,0 ld b,16__MulFullNext: add hl,hl rla rl c jr nc,__MulFullSkip add hl,de adc a,0 jr nc,__MulFullSkip inc c__MulFullSkip: djnz __MulFullNext ret__MulFullEnd:
p_MulFull: .db __MulFullEnd-1-$ xor a ld c,h ld h,a or l ld l,h call nz,__MulFullByte-p_MulFull-1 ld a,c__MulFullByte: ld b,8__MulFullNext: rra jr nc,__MulFullSkip add hl,de__MulFullSkip: rr h rr l djnz __MulFullNext ret__MulFullEnd: