0 Members and 3 Guests are viewing this topic.
Basically, it takes a parameter in the range [-128,128] and returns the corresponding cos/sin -compatible angle (between 0 and 256 inclusive)
acos:;Input:; L is the signed int from [-128,127] where -128 corresponds to -1;Output:; HL ld h,0 ld a,l or a jp p,acossub0 neg call acossub0 ld a,128 sub l ld l,a retacossub0: cp 14 jr c,$+7 cp 57 jr nc,$+3 dec a cp 68 jp nc,acossub1 inc a ld bc,0530h cp c \ jr c,$+3 \ sub c rla \ djnz $-5 or $E0 add a,65 ld l,a retacossub1:;now sub 68;between 0 and 21, slope is -2/5 sub 22 jr nc,acossub2 ld c,5 \ ld l,h inc l \ add a,c \ jr nc,$-2 sub 3 \ ld a,l adc a,a add a,1Fh ld l,a retacossub2:;original a>=90;between 0 and 17, slope is -1/2 sub 18 jr nc,acossub3 rra cpl add a,18h ld l,a ret;original a>=107acossub3: ld hl,acosLUT add a,l ld l,a jr nc,$+3 inc h ld l,(hl) ld h,0 retacosLUT:.db $17.db $16.db $16.db $15.db $15.db $14.db $13.db $13.db $12.db $11.db $10.db $F.db $E.db $E.db $D.db $B.db $A.db $9.db $7.db $5
acos:;Input:; L is the signed int from [-128,127] where -128 corresponds to -1;Output:; HL ld h,0 ld a,l or a jp p,acossub0 neg call acossub0 ld a,128 sub l ld l,a retacossub0: cp 90 jp nc,acossub1 inc a ld bc,0530h cp c \ jr c,$+3 \ sub c rla \ djnz $-5 or $E0 add a,65 ld l,a retacossub1:;now sub 90 ld hl,acosLUT add a,l ld l,a jr nc,$+3 inc h ld l,(hl) ld h,0 retacosLUT:.db $20.db $20.db $1F.db $1F.db $1E.db $1E.db $1D.db $1D.db $1C.db $1C.db $1B.db $1B.db $1A.db $1A.db $19.db $19.db $18.db $18.db $17.db $16.db $16.db $15.db $15.db $14.db $13.db $13.db $12.db $11.db $10.db $F.db $E.db $E.db $D.db $B.db $A.db $9.db $7.db $5