Geekboy

Untitled

May 23rd, 2012
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 7.61 KB | None | 0 0
  1.  
  2. nanamiTest:
  3.  
  4. ;1
  5. ; jp $
  6. ;Moves the bullet in the directoin given via an angle
  7. ; the angle is gotten from a lut and the lower bits of the counter are used for the lut table loc
  8. ; t = Ftttttt
  9. ; charweapondat holds the ttl for the angle
  10. ;E=Y D=X
  11.  ;inc e \ inc d           ;modify for collision routine
  12.  ;ld ix,PBMoveANGcont     ;return address for collision routine
  13.  ;jp SmallBulletCollision ;IN: DE=XY,
  14. ;PBMoveANGcont:
  15. ; dec e \ dec d     ;unmodify from collision routine
  16.  
  17. ; jp $
  18.  push de           ;move the stack back because xy is poped into de before teh jump
  19.  
  20.      
  21.      ld a,d
  22.      and %11111100
  23.      ld h,a
  24.      ld a,e
  25.     and %11111100  
  26.     ld l,a
  27.      
  28.    
  29.      ld de,(chary)   ; de = your pos
  30.     ; srl e \ srl d
  31.     ; srl e \ srl d  ; pos is stored same as enimies no need to much with them
  32.      ex de,hl
  33.      
  34.  ld b,0        ;initializing...
  35.  ld a,e        ;
  36.  rrca \ rrca \ and %00111111
  37.  sub L    ;y1-y2
  38.  jr nc,_  ;result is negative. Set B for flags (bit 0) and adjust Y for pos.
  39.  set 0,b
  40.  neg
  41. _:
  42.  ld e,a      ;D=Y for later
  43.  rlca \ rlca ;shifting so that %00yyyynn is %yyyynn00 for later. n matters not
  44.  ld L,a      ;half-result in L now
  45.  ld a,d
  46.  rrca \ rrca \ and %00111111
  47.  sub H     ;x1-x2
  48.  jr nc,_   ;result is negative. Set B for flags (bit 1) and adjust X for pos.
  49.  set 1,b
  50.  neg
  51. _:
  52.  ld c,a    ;C=X for results later
  53.  rrca \ rrca ;shifting so that %00xxxxnn is %nn00xxxx. n still matters not.
  54.  xor L     ;combine with Y
  55.  and $0F   ;mask out to keep old X low bits
  56.  xor L     ;and we have %yyyyxxxx
  57.  ld L,b    ;saving flags into L for now.
  58.  ld h,e    ;restore H for... stuffs
  59.  ld ix,ArcTanTable
  60.  ld e,a
  61.  ld d,0
  62.  add ix,de ;We have our offset now.
  63. ;So at this point, C=X, H=Y, L=flags.
  64. ;Let's go ahead and do X-interpolation first.
  65. ld a,c
  66. and %00000011 ;value-ranking
  67. ld c,(ix+0)   ;storing non-adjusted "output" value into C
  68. jr z,r.arctan.skipxx
  69. ld e,a  ;Loop for second half of X interpolate
  70. cpl     ;ranking first value on inverse of distance to next number
  71. add a,5 ;So 1=3,2=2,3=1
  72. ld b,a
  73. xor a
  74. _:
  75. add a,c
  76. djnz -_
  77. ld c,(ix+1)
  78. ld b,e
  79. _:
  80. add a,c
  81. djnz -_
  82. rra \ rra
  83. and %00111111
  84. ld c,a       ;out by the time we're done with everything.
  85. r.arctan.skipxx:
  86.  ld a,h
  87.  ld H,c     ;H=InterpolatedX
  88.  and %00000011 ;value-ranking
  89.  ld c,(ix+0)   ;storing non-adjusted "output" value into C
  90.  jr z,r.arctan.skipyy
  91.  ld e,a  ;Loop for second half of Y interpolate
  92.  cpl     ;ranking first value on inverse of distance to next number
  93.  add a,5 ;So 1=3,2=2,3=1
  94.  ld b,a
  95.  xor a
  96. _:
  97.  add a,c
  98.  djnz -_
  99.  ld c,(ix+16)
  100.  ld b,e
  101. _:
  102.  add a,c
  103.  djnz -_
  104.  rra \ rra    ;Also trying to get any leftovers from too many values of 64
  105.  cp 64
  106.  jr z,_
  107.  and %00111111
  108. _:
  109.  ld c,a       ;added. Since 64*4 is a 9 bit number, getting that back.
  110. r.arctan.skipyy:
  111.  ld a,c
  112.  add a,H
  113.  rra
  114.  cp 64
  115.  jr z,_
  116.  and %00111111 ;and NOW we have our final angle. (if it wasn't 64...)
  117. _:
  118. ld b,0        ;Set to 128 if X is negative. For additions later on.      
  119. bit 1,L
  120. jr z,_
  121. ld b,128
  122. neg           ;negate angle
  123. _:
  124. bit 0,L
  125. jr z,_
  126. neg           ;negate angle again if (-,-) else first neg. Still correct :)
  127. _:
  128. add a,b       ;completing the angle
  129.  
  130.      
  131.  
  132.   ld a,c    ; put angle in a
  133.  pop hl
  134. push hl ; restore xy
  135.  
  136. jp moveang
  137.  
  138.  
  139.  
  140. ;********************************
  141. ;If you needed to modify the counter, you will need the following code.
  142. ;AND DON'T FORGET TO PRESERVE BIT 7 OF L SINCE THAT IS THE FOCUSED FLAG.
  143.  dec sp \ pop hl   ;ENTER CODE
  144.  ; Lut pos is in L
  145.  ld a,(charweapondat)  ; load DTTTTTTT into a
  146.  and %01111111         ; clear d
  147.  cp 1              
  148.  jp z,INCLUT       ; if lut is 1 move to the next item on it
  149.  jp c,_           ; if the counter is at 0 go back to the player
  150.              ; dec angle timer
  151.  push hl \ inc sp
  152.  dec a
  153.  ld (charweapondat),a
  154.  ld a,l            ; put offset into a
  155.  and %01111111     ; clear focus bit
  156.  ld hl,nanamiLUT45 ; load hl with LUTptr
  157.  inc a             ; do this so we are looking at the second item at the pointer
  158.  add a,l           ; add l to a to make
  159.  ld l,a            ; LUT+ofs
  160.  ld a,(hl)         ; store the angle we get into a
  161.  and %01111111
  162.  add a,a  
  163.  jp moveang
  164. _:
  165. Follow_player:     ; gets a angle via the arctan function and sends the attack torwards the player
  166.  push hl
  167.  inc sp ; move the stack back to proper positions as we
  168.    ld hl,0          ; are moving it into temp storage
  169.    add hl,sp
  170.    ld sp,(itemp1)   ; old stack value was stored here
  171.    push hl          ; we have a stack now lets use it
  172.     ex af,af'       ; needed this last time dont ask me why
  173.    push af         ; save the shadow aff for some bloody reason
  174.  
  175.  
  176.     ld a,d
  177.    rlca \ rlca
  178.     ld h,a
  179.     ld a,e
  180.    rlca \ rlca    
  181.     ld l,a
  182.      
  183.  
  184.     ld de,(chary)   ; de = your pos
  185.    ; srl e \ srl d
  186.    ; srl e \ srl d  ; pos is stored same as enimies no need to much with them
  187.    ; ex de,hl
  188.     call r.arctan   ; returns angle in c and a
  189.                ; we leave it there so we can restore the stack
  190.  
  191.  
  192.    pop af
  193.    ex af,af'
  194.    pop hl
  195.    ld sp,hl
  196.  
  197.    ld a,c    ; put angle in a
  198.   pop hl
  199.  push hl ; restore xy
  200.  
  201.  jp moveang
  202.   ; we can do my own shit now stack is inited and old one is saved
  203.  
  204. _:
  205.  ;jp $
  206.  ld a,(charweapondat)  ;  load dttttttt into a
  207.  and %10000000         ;  preserve d
  208.  inc a                 ; make t = 1
  209.  ld (charweapondat),a  ; save
  210.  ld a,l
  211.  and %10000000
  212.  ld l,a
  213.  push hl \ inc sp      ; quit
  214.  pop de                ; ^
  215.  jp PBTDestroy         ; ...
  216. INCLUT:            ; must inc lut value by 2
  217.  ;ld b,a            ; save Dttttttt into b
  218.  ;jp $
  219.  ld a,l            ; load a with FLLLLLLL
  220.  inc a \ inc a     ; inc a twice we do not monitor F we should never have 127 entries
  221.  Xor l             ;
  222.  and %01111111    
  223.  xor l             ; merge bit 7 of L with bits 0-6 of a
  224.  ld l,A        
  225.  push hl \ inc sp  ; EXIT CODE for modifying the timer
  226.  ld hl,nanamiLUT45 ; load hl with pointer to the lut
  227.  and %01111111     ; and out F ===! this is new forgot this !===
  228.  add a,l           ; merge with lut addy to make pointer
  229.  ld l,a            ; ^
  230.  ld b,(hl)         ; load b with the angle count off hte lut
  231.  ld a,(charweapondat) ; load a with charweapondat
  232.  and %10000000       ; clear T
  233.  add a,b               ; merge
  234.  ld (charweapondat),a  ; save back
  235.  pop de                ; important shit
  236.  jp nanamitest         ; start over so we actually do something
  237. moveang:
  238.  ;jp $
  239.  
  240.  ; assumes x,y are in on teh table in the form of ss.^^^^^^ \ jp $
  241.  
  242.  pop hl             ;then advance SP so the bullet table handler can continue
  243.            ;doubling the spread
  244.  
  245.  ld c,a
  246.  ld b,$82           ;and now complete the address thinger. in BC
  247.  rlc L \ rlc L      ;From %ss.yyyyyy to %yyyyyy.ss
  248.  ld a,(bc)          ;Get %AAAaaaaa. Let's use upper 3 bits
  249. rlca \ rlca \ rlca ;Got %aaaaaAAA
  250. and %00000111
  251. bit 7,c
  252. jp z,_
  253. neg    ;We had a positive number but we need movement in negative
  254. _:
  255. add a,L
  256. ;jp nc,PBTDestroy   ;Bullet went past top. Destroy it.
  257. ;cp 240
  258. ;jp nc,PBTDestroy    ; special case handling for top of screen shooting people
  259. ld L,a
  260. ld a,c
  261. add a,64
  262. ld c,a
  263. ld a,(bc)          ;Getting X angle.
  264. rlca \ rlca \ rlca ;like above
  265. and %00000111
  266. ld b,a
  267. ld a,c
  268. and %11000000
  269. ld a,b    
  270. ; *phew*. Almost looks like I know what I'm doing :P  
  271.  jp po,_        
  272.  neg
  273. _:
  274.  rlc h \ rlc h  ;rotate x to xxxxxx.ss
  275.  add a,h        ;add our value to the X pos
  276.  ld h,a         ; save back
  277.  and %11111100  ; and for collision
  278.  ;jp z,PBTDestroy
  279.  
  280.  rrc h \ rrc h  ; rever
  281.  rrc L \ rrc L
  282.  push hl
  283.  pop hl
  284.  jp PBTMainMoveRet ;stack unavailable
  285.  
  286. ;2
Advertisement
Add Comment
Please, Sign In to add comment