0 Members and 1 Guest are viewing this topic.
This is a little late, but...Quote from: http://ourl.ca/2637/2558280.oWhat's the theory behind that? I've been trying to get aiming like that working since something like January...
he does some crazy fucking shit with it though to get it to be that accurate though...
ArcTanTable:.db 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00 ;|00 00|.db 64,32,19,13,10,08,07,06,05,05,04,04,03,03,03,03 ;|01 04|.db 64,45,32,24,19,16,13,11,10,09,08,07,07,06,06,05 ;|02 08|.db 64,51,40,32,26,22,19,16,15,13,12,11,10,09,09,08 ;|03 12|.db 64,54,45,38,32,27,24,21,19,17,16,14,13,12,11,11 ;|04 16|.db 64,56,48,42,37,32,28,25,23,21,19,17,16,15,14,13 ;|05 20|.db 64,57,51,45,40,36,32,29,26,24,22,20,19,18,16,16 ;|06 24|.db 64,58,53,48,43,39,35,32,29,27,25,23,22,20,19,18 ;|07 28|.db 64,59,54,49,45,41,38,35,32,30,27,26,24,22,21,20 ;|08 32|.db 64,59,55,51,47,43,40,37,34,32,30,28,26,25,23,22 ;|09 36|.db 64,60,56,52,48,45,42,39,37,34,32,30,28,27,25,24 ;|10 40|.db 64,60,57,53,50,47,44,41,38,36,34,32,30,29,27,26 ;|11 44|.db 64,61,57,54,51,48,45,42,40,38,36,34,32,30,29,27 ;|12 48|.db 64,61,58,55,52,49,46,44,42,39,37,35,34,32,30,29 ;|13 52|.db 64,61,58,55,53,50,48,45,43,41,39,37,35,34,32,31 ;|14 56|.db 64,61,59,56,53,51,48,46,44,42,40,38,37,35,33,32 ;|15 60|
;Warning: Loads and loads of register-juggling ahead.r.arctan: ;in: HL=(x1,y1) DE=(x2,y2) ld b,0 ;initializing... ld a,e ; rrca \ rrca \ and %00111111 sub L ;y1-y2 jr nc,_ ;result is negative. Set B for flags (bit 0) and adjust Y for pos. set 0,b neg_: ld e,a ;D=Y for later rlca \ rlca ;shifting so that %00yyyynn is %yyyynn00 for later. n matters not ld L,a ;half-result in L now ld a,d rrca \ rrca \ and %00111111 sub H ;x1-x2 jr nc,_ ;result is negative. Set B for flags (bit 1) and adjust X for pos. set 1,b neg _: ld c,a ;C=X for results later rrca \ rrca ;shifting so that %00xxxxnn is %nn00xxxx. n still matters not. xor L ;combine with Y and $0F ;mask out to keep old X low bits xor L ;and we have %yyyyxxxx ld L,b ;saving flags into L for now. ld h,e ;restore H for... stuffs ld ix,ArcTanTable ld e,a ld d,0 add ix,de ;We have our offset now.;So at this point, C=X, H=Y, L=flags.;Let's go ahead and do X-interpolation first. ld a,c and %00000011 ;value-ranking ld c,(ix+0) ;storing non-adjusted "output" value into C jr z,r.arctan.skipx ld e,a ;Loop for second half of X interpolate cpl ;ranking first value on inverse of distance to next number add a,5 ;So 1=3,2=2,3=1 ld b,a xor a_: add a,c djnz -_ ld c,(ix+1) ld b,e_: add a,c djnz -_ rra \ rra and %00111111 ld c,a ;out by the time we're done with everything.r.arctan.skipx: ld a,h ld H,c ;H=InterpolatedX and %00000011 ;value-ranking ld c,(ix+0) ;storing non-adjusted "output" value into C jr z,r.arctan.skipy ld e,a ;Loop for second half of Y interpolate cpl ;ranking first value on inverse of distance to next number add a,5 ;So 1=3,2=2,3=1 ld b,a xor a_: add a,c djnz -_ ld c,(ix+16) ld b,e_: add a,c djnz -_ rra \ rra ;Also trying to get any leftovers from too many values of 64 cp 64 jr z,_ and %00111111_: ld c,a ;added. Since 64*4 is a 9 bit number, getting that back.r.arctan.skipy: ld a,c add a,H rra cp 64 jr z,_ and %00111111 ;and NOW we have our final angle. (if it wasn't 64...)_: ld b,0 ;Set to 128 if X is negative. For additions later on. bit 1,L jr z,_ ld b,128 neg ;negate angle_: bit 0,L jr z,_ neg ;negate angle again if (-,-) else first neg. Still correct :)_: add a,b ;completing the angle ld c,a ;saving the completed angle to C ret