0 Members and 1 Guest are viewing this topic.
Hm...I say this as an Axe programmer, not knowing ASM...how about UPSIDE DOWN TEXT! om nom nom nom
p_SDiv: .db __SDivEnd-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_Div pop af ret p xor a sub l ld l,a sbc a,a sub h ld h,a ret__SDivEnd:
p_SDiv: .db __SDivEnd-1-$ ld a,h xor d push af xor d ; a = h jp p,$+9 xor a sub l ld l,a sbc a,a sub h ld h,a ; a = high byte of abs(hl) ; therefore, bit 7 is clear ; xor d ; or works too ; jp p,$+9 ; Edit: doesn't work if hl = $8000 ; because abs($8000) = $8000 bit 7,d jr z,$+8 xor a sub e ld e,a sbc a,a sub d ld d,a call $3F00+sub_Div pop af ret p xor a sub l ld l,a sbc a,a sub h ld h,a ret__SDivEnd:
p_SDiv: .db __SDivEnd-1-$ ld a,h xor d push af xor d ; a = h jp p,$+9 xor a sub l ld l,a sbc a,a sub h ld h,a ld a,d or a jp p,$+9 xor a sub e ld e,a sbc a,a sub d ld d,a ld b,b .db 2 call $3F00+sub_Div pop af ret p xor a sub l ld l,a sbc a,a sub h ld h,a ret__SDivEnd:p_Div: .db __DivEnd-1-$ ld a,d or a ld b,16 ; ...
p_SDiv: .db __SDivEnd-1-$ ld a,h xor d push af ld b,2__SDivRepeat: ex de,hl xor h jp p,__SDivSkip xor a sub l ld l,a sbc a,a sub h ld h,a__SDivSkip: xor a djnz __SDivRepeat call $3F00+sub_Div pop af ret p xor a sub l ld l,a sbc a,a sub h ld h,a ret__SDivEnd:
p_SDiv: .db __SDivEnd-1-$ ld a,h xor d ld b,2__SDivRepeat: push af xor d jp p,__SDivSkip xor a sub l ld l,a sbc a,a sub h ld h,a__SDivSkip: dec b ret m ex de,hl ld b,b .db 1 call z,$3F00+sub_Div inc b pop af djnz __SDivRepeat jr __SDivRepeat+2__SDivEnd:p_Div: .db __DivEnd-1-$ ld a,d or a ld b,16 ; ...
p_SortD: .db __SortDEnd-1-$ ld c,l ex de,hl__SortDLoop2: ld b,c push hl jr __SortDJumpIn__SortDLoop1: inc hl cp (hl) jr c,__SortDSkip__SortDJumpIn: ld a,(hl) ld d,h ld e,l__SortDSkip: djnz __SortDLoop1 ld b,(hl) ld (hl),a ld a,b ld (de),a pop hl dec c jr nz,__SortDLoop2 ret__SortDEnd:
p_SortD: .db __SortDEnd-1-$ ld c,l ex de,hl__SortDLoop2: ld b,c push hl jr __SortDJumpIn__SortDLoop1: inc hl cp (hl) jr c,__SortDSkip__SortDJumpIn: ld a,(hl) ld d,h ld e,l__SortDSkip: djnz __SortDLoop1 ldi dec hl ld (hl),a pop hl jp pe,__SortDLoop2 ret__SortDEnd:
p_Reciprocal: .db __ReciprocalEnd-1-$ xor a bit 7,h push af jr z,$+7 sub l ld l,a sbc a,a sub h ld h,a ex de,hl ld bc,$1000 ld hl,1 xor a ld b,b .db 10 call $3F00+sub_Div pop af ret z sub l ld l,a sbc a,a sub h ld h,a ret__ReciprocalEnd:
p_Reciprocal: .db __ReciprocalEnd-1-$ xor a bit 7,h push af jr z,$+8 sub l ld l,a sbc a,a sub h ld h,a xor a ex de,hl ld bc,$1000 ld hl,1 ld b,b .db 10 call $3F00+sub_Div pop af ret z sub l ld l,a sbc a,a sub h ld h,a ret__ReciprocalEnd:
p_Reciprocal: .db __ReciprocalEnd-1-$ xor a bit 7,h push af jr z,$+8 sub l ld l,a sbc a,a sub h ld h,a xor a ex de,hl ld bc,$1001 ld hl,2 ld b,b .db 16 call $3F00+sub_Div pop af ret z sub l ld l,a sbc a,a sub h ld h,a ret__ReciprocalEnd:
p_Mod: .db __ModEnd-1-$ ld a,h ld c,l ld hl,0 ld b,16__ModLoop: scf rl c rla adc hl,hl sbc hl,de jr nc,__ModSkip add hl,de dec c__ModSkip: djnz __ModLoop ret__ModEnd:
p_Mod: .db __ModEnd-1-$ ld a,h ld c,l ld hl,0 ld b,16__ModLoop: sla c rla adc hl,hl sbc hl,de jr nc,__ModSkip add hl,de__ModSkip: djnz __ModLoop ret__ModEnd:
Not an optimization, but I'm posting this here since more assembly people will read it. Since the Bitmap() command is being replaced with something actually useful, that means the "Fix 8" and "Fix 9" will also need to be replaced. Are there any useful flags (particularly for text) that would be useful to Axe programmers that I haven't already covered with the other fix commands? A couple I can think of are an APD toggle or Lowercase toggle.
p_GetKeyPause: ; Change to subroutine .db __GetKeyPauseEnd-1-$ B_CALL(_GetKeyRetOff) res 7,(iy+40) ld h,0 ld l,a cp $fc ret c ld a,($8446) ld h,a ; Edit: something like inc h \ ld l,a might be easier ; since lowercase letters would be consecutive ; or ld hl,($8446) \ ld h,a ret__GetKeyPauseEnd-1-$
.db 3 sbc hl,de ld a,h or l .db 2 sbc hl,de
.db 8 ld de,$0000 add hl,de sbc hl,hl inc hl dec hl .db 6 ld de,$0000 add hl,de sbc hl,hl
.db 3 sbc hl,hl ld a,h or l .db 2 sbc hl,hl
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 pairity rla ;/ jr c,__ArcTanSS ;\ add hl,de ; | add hl,de ; |__ArcTanSS: ; | or a ; |hl = x +- y sbc hl,de ;/ 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-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_DrawBmp: ; ...__DrawBmpGoodSize: ld b,a ;B = plot_height push bc ;****** BEGIN BUFFER CALCULATIONS ****** ; ...__DrawBmpLeftLoop: inc c dec c jr z,__DrawBmpSkipMain dec c ; ...__DrawBmpOnLeft: ;A = X + 8 inc c dec c ld d,(hl) inc hl ld e,c ;E = 0 if z jr z,__DrawBmpSt ; ...__DrawBmpStSkip: ld a,e pop de ;D = X ld e,c pop bc ld c,e ;C = bytes ; ...__DrawBmpColWall: inc c dec c jr z,__DrawBmpSkipMain dec c ld a,d jr nz,__DrawBmpColLeft cp 88 ld d,(hl) inc hl jr nc,__DrawBmpSkipMain ld e,c jr __DrawBmpSt ; ...
p_DrawBmp: ; ... c = bytes + 1 is required for the rest of the optimizations__DrawBmpGoodSize: ld b,a ;B = plot_height inc c ;C = bytes+1 push bc ;****** BEGIN BUFFER CALCULATIONS ****** ; ... undo inc c above, affect z flag the same as before, c is still one more than before__DrawBmpLeftLoop: dec c jr z,__DrawBmpSkipMain ; ... since c is one more than before, check e = c - 1 for 0, instead of c__DrawBmpOnLeft: ;A = X + 8 ld d,(hl) inc hl ld e,c dec e ;E = 0 and z (if bytes = 0) jr z,__DrawBmpSt ; ... this stores one more than before to e, but all code paths lead to ; either pop de, ld e,(hl), or ld e,c before e is ever used.__DrawBmpStSkip: ld a,e pop de ;D = X ld e,c pop bc ld c,e ;C = bytes+1 ; ... same as above__DrawBmpColWall: dec c jr z,__DrawBmpSkipMain ld a,d jr nz,__DrawBmpColLeft cp 88 ld d,(hl) inc hl jr nc,__DrawBmpSkipMain ; I do not understand the reason for ld e,c, however, c is one more than before, ; so dec e to have e be the same as before, but I don't know if this is necessary. ld e,c dec e jr __DrawBmpSt ; ...
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-$ ld a,h xor d push af xor d ; a = h jp p,$+9-p_88Mul-1 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_SDiv: .db __SDivEnd-1-$ ld a,h xor d push af xor d ; a = h jp p,$+9-p_SDiv-1 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_Div pop af ret p xor a sub l ld l,a sbc a,a sub h ld h,a ret__SDivEnd:
p_Reciprocal: .db __ReciprocalEnd-1-$ xor a bit 7,h push af jr z,$+8 sub l ld l,a sbc a,a sub h ld h,a xor a ex de,hl ld bc,$1000 ld hl,1 ld b,b \ .db 7 \ call $3F00+sub_Mod ld h,a ld l,c pop af ret z sub l ld l,a sbc a,a sub h ld h,a ret__ReciprocalEnd:
p_Reciprocal: .db __ReciprocalEnd-1-$ xor a bit 7,h push af jr z,$+8 sub l ld l,a sbc a,a sub h ld h,a xor a ex de,hl ld bc,$1001 ld hl,2 ld b,b \ .db 13 \ call $3F00+sub_Mod ld h,a ld l,c pop af ret z sub l ld l,a sbc a,a sub h ld h,a ret__ReciprocalEnd:
p_Mul: .db __MulEnd-1-$ ld c,h ld a,l ld b,16__MulNext: add hl,hl add a,a rl c jr nc,__MulSkip add hl,de__MulSkip: djnz __MulNext ret__MulEnd:
p_Mul: .db __MulEnd-1-$ ld c,l ld a,h call __MulByte ld a,c__MulByte: ld b,8__MulNext: add hl,hl add a,a jr nc,__MulSkip add hl,de__MulSkip: djnz __MulNext ret__MulEnd:
p_Mul: .db __MulEnd-1-$ ld c,l xor a ld l,a add a,h call nz,__MulByte ld a,c__MulByte: ld b,8__MulNext: add hl,hl add a,a jr nc,__MulSkip add hl,de__MulSkip: djnz __MulNext ret__MulEnd: