Geekboy

Untitled

Jan 6th, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. nanamiTest:
  2.  
  3. ;1
  4. ; jp $
  5. ;Moves the bullet in the directoin given via an angle
  6. ; the angle is gotten from a lut and the lower bits of the counter are used for the lut table loc
  7. ; t = Ftttttt
  8. ; charweapondat holds the ttl for the angle
  9. ;E=Y D=X
  10.  ;inc e \ inc d           ;modify for collision routine
  11.  ;ld ix,PBMoveANGcont     ;return address for collision routine
  12.  ;jp SmallBulletCollision ;IN: DE=XY,
  13. ;PBMoveANGcont:
  14. ; dec e \ dec d     ;unmodify from collision routine
  15.  
  16. ; jp $
  17.  push de           ;move the stack back because xy is poped into de before teh jump
  18.  
  19.      
  20.      ld a,d
  21.      and %11111100
  22.      ld h,a
  23.      ld a,e
  24.     and %11111100  
  25.     ld l,a
  26.      
  27.    
  28.      ld de,(chary)   ; de = your pos
  29.     ; srl e \ srl d
  30.     ; srl e \ srl d  ; pos is stored same as enimies no need to muck with them
  31.      ex de,hl
  32.      
  33.  ld b,0        ;initializing...
  34.  ld a,e        ;
  35.  rrca \ rrca \ and %00111111
  36.  sub L    ;y1-y2
  37.  jr nc,_  ;result is negative. Set B for flags (bit 0) and adjust Y for pos.
  38.  set 0,b
  39.  neg
  40. _:
  41.  ld e,a      ;D=Y for later
  42.  rlca \ rlca ;shifting so that %00yyyynn is %yyyynn00 for later. n matters not
  43.  ld L,a      ;half-result in L now
  44.  ld a,d
  45.  rrca \ rrca \ and %00111111
  46.  sub H     ;x1-x2
  47.  jr nc,_   ;result is negative. Set B for flags (bit 1) and adjust X for pos.
  48.  set 1,b
  49.  neg
  50. _:
  51.  ld c,a    ;C=X for results later
  52.  rrca \ rrca ;shifting so that %00xxxxnn is %nn00xxxx. n still matters not.
  53.  xor L     ;combine with Y
  54.  and $0F   ;mask out to keep old X low bits
  55.  xor L     ;and we have %yyyyxxxx
  56.  ld L,b    ;saving flags into L for now.
  57.  ld h,e    ;restore H for... stuffs
  58.  ld ix,ArcTanTable
  59.  ld e,a
  60.  ld d,0
  61.  add ix,de ;We have our offset now.
  62. ;So at this point, C=X, H=Y, L=flags.
  63. ;Let's go ahead and do X-interpolation first.
  64.  ld a,c
  65.  and %00000011 ;value-ranking
  66.  ld c,(ix+0)   ;storing non-adjusted "output" value into C
  67.  jr z,r.arctan.skipxx
  68.  ld e,a  ;Loop for second half of X interpolate
  69.  cpl     ;ranking first value on inverse of distance to next number
  70.  add a,5 ;So 1=3,2=2,3=1
  71.  ld b,a
  72.  xor a
  73. _:
  74.  add a,c
  75.  djnz -_
  76.  ld c,(ix+1)
  77.  ld b,e
  78. _:
  79.  add a,c
  80.  djnz -_
  81.  rra \ rra
  82.  and %00111111
  83.  ld c,a       ;out by the time we're done with everything.
  84. r.arctan.skipxx:
  85.  ld a,h
  86.  ld H,c     ;H=InterpolatedX
  87.  and %00000011 ;value-ranking
  88.  ld c,(ix+0)   ;storing non-adjusted "output" value into C
  89.  jr z,r.arctan.skipyy
  90.  ld e,a  ;Loop for second half of Y interpolate
  91.  cpl     ;ranking first value on inverse of distance to next number
  92.  add a,5 ;So 1=3,2=2,3=1
  93.  ld b,a
  94.  xor a
  95. _:
  96.  add a,c
  97.  djnz -_
  98.  ld c,(ix+16)
  99.  ld b,e
  100. _:
  101.  add a,c
  102.  djnz -_
  103.  rra \ rra    ;Also trying to get any leftovers from too many values of 64
  104.  cp 64
  105.  jr z,_
  106.  and %00111111
  107. _:
  108.  ld c,a       ;added. Since 64*4 is a 9 bit number, getting that back.
  109. r.arctan.skipyy:
  110.  ld a,c
  111.  add a,H
  112.  rra
  113.  cp 64
  114.  jr z,_
  115.  and %00111111 ;and NOW we have our final angle. (if it wasn't 64...)
  116. _:
  117.  ld b,0        ;Set to 128 if X is negative. For additions later on.      
  118.  bit 1,L
  119.  jr z,_
  120.  ld b,128
  121.  neg           ;negate angle
  122. _:
  123.  bit 0,L
  124.  jr z,_
  125.  neg           ;negate angle again if (-,-) else first neg. Still correct :)
  126. _:
  127.  add a,b       ;completing the angle
  128.  
  129.      
  130.  
  131.    ld a,c    ; put angle in a
  132.   pop hl
  133.  push hl ; restore xy
  134.  
  135.  jp moveang
Advertisement
Add Comment
Please, Sign In to add comment