Geekboy

Untitled

Oct 27th, 2011
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;Player bullet handlers
  2. ;
  3. ;PBT located at $8D00
  4. ;First 64 bytes is PBT's FBT, all are filled with values indicating player
  5. ;bullet's LSB base location (multiples of 3 starting at $8D40
  6. ;Last 64*3 bytes is PBT's actual bullet data entries, described below, but
  7. ;is up to called routine's interpretation.
  8. ;
  9. ;FBT's location is in (pbtfreebullet). If bit 6 is ever set, then the FBT
  10. ;is full.
  11. ;
  12. ;Important note: Character's X and Y positions are not stored as normal. There
  13. ;are two bits of accuracy at the start so you're going to have to right-shift
  14. ;twice to get the actual X,Y positions.
  15. ;
  16. ;Y = YYYY YYSS , where S is subpixel data
  17. ;X = XXXX XXSS , where S is subpixel data
  18. ;
  19.  
  20. ;Player bullet structure (3 bytes)
  21. ;+0 : YTTTTTTT, T=Timer 0-127, Y=1 if focused shot
  22. ;+1 : Y position if applicable
  23. ;+2 : X position if applicable
  24.  
  25. ;The routine that is being called must be able to distinguish between
  26. ;unfocused and focused modes, since there won't be seperation at
  27. ;this stage of the routine call.
  28. ;
  29. ;Several things to edit.
  30. ;(1) PBTPlayerRoutineTables : How bullets are created. Below it are links.
  31. ;(2) PBTPlayerTypeTables : Types of bullets and how they move
  32. ;
  33. ;You can make creative use of the game timers to tell bullets apart
  34. ;(gametimer1) by creating only certain ones on certain slices of masked time.
  35. ;A good mask might be like %00000111 so you get 8 different time slices on
  36. ;each processing. Also pay attention to firing delays or you might not ever
  37. ;get a single bullet out.
  38. ;
  39. ;Other than that, good luck. You're gonna need it.
  40.  
  41.  
  42. #DEFINE PBTSHOT(xofs,yofs,count) call PBTCreate \ .db xofs,yofs,count
  43.  
  44.  
  45.  
  46. PlayerShoot:
  47.  ld a,(characterID)
  48.  add a,a
  49.  ld e,a
  50.  ld d,0
  51.  ld hl,PBTPlayerRoutineTables
  52.  add hl,de
  53.  ld e,(hl)
  54.  inc hl
  55.  ld d,(hl)
  56.  ld hl,charweapon1
  57.  bit isfocused,(iy+danmakuflags)
  58.  jr z,_
  59.  inc hl
  60.  inc de
  61.  inc de  ;if focused, charweapon2, and inc pointer to a focused standpoint
  62. _:
  63.  ld a,(hl)
  64.  add a,a
  65.  add a,a  ;x4 for weapon power thing
  66.  ld L,a
  67.  ld h,0
  68.  add hl,de
  69.  ld a,(hl)
  70.  inc hl
  71.  ld h,(hl)
  72.  ld L,a
  73.  jp (hl)
  74.  
  75. PBTMainDraw:
  76.  xor a
  77.  call PBTFillBulletDetails
  78.  ld (itemp1),sp
  79.  ld sp,$8D40
  80.  ld a,64
  81. PBTMainDrawLoop:
  82.  ex af,af'
  83. dec sp
  84. pop af
  85. pop de
  86. cp $FF
  87. jp z,PBTMainDrawRet
  88. ld hl,(itemp2) ;unfocused
  89. bit 7,a
  90. jr z,_
  91. ld hl,(itemp3) ;focused
  92. _:
  93. jp (hl)        ;routine being jumped to MUST keep B intact
  94. PBTMainDrawRet:
  95. ex af,af'
  96.  dec a
  97.  jr nz,PBTMainDrawLoop
  98.  ld sp,(itemp1)
  99.  ret
  100.  
  101. PBTMainMove:
  102.  ld a,4
  103.  call PBTFillBulletDetails
  104.  ld (itemp1),sp
  105.  ld sp,$8D40
  106.  ld a,64
  107. PBTMainMoveLoop:
  108.  ex af,af'
  109. dec sp
  110. pop af   ;A=tCCCCCCC, where t=type, C=counter
  111. pop de   ;E=Ypos ; D=Xpos (no accuracy bits, negative values may be used)
  112. cp $FF
  113. jp z,PBTMainMoveRet
  114. ld hl,(itemp2) ;unfocused
  115. bit 7,a
  116. jr z,_
  117. ld hl,(itemp3) ;focused
  118. _:
  119. jp (hl)        ;routine being jumped to MUST keep B intact
  120. PBTMainMoveRet:
  121. ex af,af'
  122.  dec a
  123.  jr nz,PBTMainMoveLoop
  124.  ld sp,(itemp1)
  125.  ret
  126. PBTNoCreate:
  127.  pop hl
  128.  inc hl
  129.  inc hl
  130.  inc hl
  131.  jp (hl)
  132. PBTCreate: ;in: macro'd. Xofs,Yofs,Count
  133.  ld hl,pbtfreebullet
  134.  bit 6,(hl)
  135.  jp nz,PBTNoCreate     ;stop routine if over 64 bullets
  136.  ld a,(hl) ;1.read
  137.  inc (hl)  ;2.increment
  138.  ld L,a
  139.  ld h,$8D
  140.  ld L,(hl) ;got bullet position
  141.  push hl
  142.  pop ix
  143.  ld de,(chary)
  144.  srl e \ srl e ;y
  145.  srl d \ srl d ;x
  146.  pop hl
  147.  ld a,d
  148.  add a,(hl)
  149.  inc hl
  150.  ld (ix+2),a
  151.  ld a,e
  152.  add a,(hl)
  153.  inc hl
  154.  ld (ix+1),a
  155.  ld a,(mdanmaku)  ;isfocused == bit 1. Need to shift to bit 7.
  156.  rrca
  157.  rrca
  158.  and $80
  159.  or (hl) ;combining new counter with focused mask
  160.  inc hl
  161.  ld (ix+0),a
  162.  jp (hl)
  163.  
  164. PBTCreate2: ;D=Xofs,E=Yofs,A=Count
  165.  push af
  166.   ld hl,pbtfreebullet
  167.   bit 6,(hl)
  168.   jr z,_        ;stop routine if over 64 bullets. Jump past if no stop.
  169.  pop af
  170.  ret
  171. _:
  172.   ld a,(hl) ;1.read
  173.   inc (hl)  ;2.increment
  174.   ld L,a
  175.   ld h,$8D
  176.   ld L,(hl) ;got bullet position
  177.   push hl
  178.   pop ix
  179.   ld a,(charx)
  180.   srl a \ srl a
  181.   add a,d
  182.   ld (ix+2),a
  183.   ld a,(chary)
  184.   srl a \ srl a
  185.   add a,e
  186.   ld (ix+1),a
  187.   ld a,(mdanmaku)
  188.   rrca
  189.   rrca
  190.   and $80
  191.  pop bc
  192.  or b    ;combining masks for b7=focused, b0-b6=counter
  193.  ld (ix+0),a
  194.  ret
  195.  
  196.  
  197.  
  198. PBTDestroy: ;must be called in MOVE routine b4 SP is changed to save values
  199.  ld hl,-3
  200.  add hl,sp
  201.  ld (hl),$FF
  202.  ex de,hl
  203.  ld hl,pbtfreebullet
  204.  dec (hl)
  205.  ld L,(hl)
  206.  ld h,$8D
  207.  ld (hl),e
  208.  jp PBTMainMoveRet
  209.  
  210. PBTFillBulletDetails:
  211.  ld c,a
  212.  ld b,0   ;offset (0 if render cycle, 4 if move/collide cycle)
  213.  ld a,(characterID)
  214.  add a,a
  215.  ld hl,PBTPlayerTypeTables
  216.  add a,L
  217.  ld L,a
  218.  jr nc,$+3
  219.  inc h
  220.  ld e,(hl)
  221.  inc hl
  222.  ld d,(hl) ;got address to character's bullet table in DE
  223.  ld a,(charweapon1)  ;unfocused weapon type
  224.  add a,a  ;x2
  225.  add a,a  ;x4
  226.  add a,a  ;x8  ;weapon power type now available.
  227.  add a,e
  228.  ld L,a
  229.  ld h,d
  230.  jr nc,_
  231.  inc h
  232. _:
  233.  add hl,bc
  234.  ld a,(hl)
  235.  inc hl
  236.  ld h,(hl)
  237.  ld L,a
  238.  ld (itemp2),hl  ;unfocused weapon type in itemp2 variable
  239.  ld a,(charweapon2)  ;focused weapon type
  240.  add a,a  ;x2
  241.  add a,a  ;x4
  242.  add a,a  ;x8
  243.  add a,2  ;+more offset for focused type
  244.  add a,e
  245.  ld L,a
  246.  ld h,d
  247.  jr nc,_
  248.  inc h
  249. _:
  250.  add hl,bc
  251.  ld a,(hl)
  252.  inc hl
  253.  ld h,(hl)
  254.  ld L,a
  255.  ld (itemp3),hl  ;focused weapon type in itemp3 variable
  256.  ret
  257.  
  258. ;-----------------------------------------------------------------------------
  259. ;PLAYER BULLET CREATION TABLES
  260. ;
  261.  
  262.  
  263. PBTPlayerRoutineTables:
  264. .dw PBTPRT00  ;Devblock  (ChID0) DO NOT CHANGE THESE ENTRIES
  265. .dw PBTPRT01  ;Iambian   (ChID1)
  266. .dw PBTPRT02  ;Netham45  (ChID2)
  267. .dw PBTPRT03  ;???       (ChID3)
  268. .dw PBTPRT04  ;???       (ChID4)
  269. .dw PBTPRT05  ;???       (ChID5)
  270. .dw PBTPRT06  ;Netham45L (ChID6)
  271. .dw PBTPRT07  ;???       (ChID7)
  272.  
  273. PBTPRT00:  ;Devblock  (ChID0)
  274. .dw DevBlockUnfPwr1   ;direct links to the routines that is about to be used
  275. .dw DevBlockFocPwr1
  276. .dw DevBlockUnfPwr2   ;direct links to the routines that is about to be used
  277. .dw DevBlockFocPwr2
  278. PBTPRT01:  ;Iambian   (ChID1)
  279. .dw IambianFireTest
  280. .dw IambianFireTest
  281. .dw IambianFireTest
  282. .dw IambianFireTest
  283. PBTPRT02:  ;Netham45  (ChID2)
  284. .dw TestRoutineUnFocPwr1
  285. .dw TestRoutineFocusPwr1
  286. .dw TestRoutineUnFocPwr2
  287. .dw TestRoutineFocusPwr2
  288. PBTPRT03:  ;???       (ChID3)
  289. .dw TestRoutineUnFocPwr1
  290. .dw TestRoutineFocusPwr1
  291. .dw TestRoutineUnFocPwr2
  292. .dw TestRoutineFocusPwr2
  293. PBTPRT04:  ;???       (ChID4)
  294. .dw TestRoutineUnFocPwr1
  295. .dw TestRoutineFocusPwr1
  296. .dw TestRoutineUnFocPwr2
  297. .dw TestRoutineFocusPwr2
  298. PBTPRT05:  ;Nanami    (ChID5)
  299. .dw TestRoutineUnFocPwr1
  300. .dw TestRoutineFocusPwr1
  301. .dw TestRoutineUnFocPwr2
  302. .dw TestRoutineFocusPwr2
  303. PBTPRT06:  ;Netham45L (ChID6)
  304. .dw ShotHyperdrive
  305. .dw TestRoutineFocusPwr1
  306. .dw TestRoutineUnFocPwr2
  307. .dw TestRoutineFocusPwr2
  308. PBTPRT07:  ;???       (ChID7)
  309. .dw TestRoutineUnFocPwr1
  310. .dw TestRoutineFocusPwr1
  311. .dw TestRoutineUnFocPwr2
  312. .dw TestRoutineFocusPwr2
  313.  
  314.  
  315. ;-----------------------------------------------------------------------------
  316. ;PLAYER BULLET RENDER/MOVE/COLLISION TABLES
  317. ;
  318.  
  319. PBTPlayerTypeTables:
  320. .dw PBTPTT00  ;Devblock  (ChID0) DO NOT CHANGE THESE ENTRIES
  321. .dw PBTPTT01  ;Iambian   (ChID1)
  322. .dw PBTPTT02  ;Netham45  (ChID2)
  323. .dw PBTPTT03  ;???       (ChID3)
  324. .dw PBTPTT04  ;???       (ChID4)
  325. .dw PBTPTT05  ;Nanami    (ChID5)
  326. .dw PBTPTT06  ;Netham45L (ChID6)
  327. .dw PBTPTT07  ;???       (ChID7)
  328.  
  329. ;SO FAR EVERY ENTRY IN THIS TABLE IS DUMMY ENTRIES. FILL IN WITH ACTUAL
  330. ;DATA CONNECTED TO ASSEMBLY ROUTINES WHENEVER YOU ARE READY TO CODE THIS
  331. ;HORRIBLE MESS.
  332. PBTPTT00:         ;Devblock  (ChID0)
  333. .dw PBTShot00Draw ;-Unfocused shot power 1 render
  334. .dw PBTShot00Draw ;-Focused   shot power 1 render
  335. .dw PBTShot00Move ;-Unfocused shot power 1 move/collide/remove
  336. .dw PBTShot00Move ;-Focused   shot power 1 move/collide/remove
  337. .dw PBTShot00Draw ;-Unfocused shot power 2 render
  338. .dw PBTShot00Draw ;-Focused   shot power 2 render
  339. .dw PBTShot00Move ;-Unfocused shot power 2 move/collide/remove
  340. .dw PBTShot00Move ;-Focused   shot power 2 move/collide/remove
  341. PBTPTT01:         ;Iambian   (ChID1)
  342. .dw PBTShot00DrawIam ;-Unfocused shot power 1 render
  343. .dw PBTShot00DrawIam ;-Focused   shot power 1 render
  344. .dw PBMoveANG ;-Unfocused shot power 1 move/collide/remove
  345. .dw PBMoveANG ;-Focused   shot power 1 move/collide/remove
  346. .dw PBTShot00DrawIam ;-Unfocused shot power 2 render
  347. .dw PBTShot00DrawIam ;-Focused   shot power 2 render
  348. .dw PBMoveANG ;-Unfocused shot power 2 move/collide/remove
  349. .dw PBMoveANG ;-Focused   shot power 2 move/collide/remove
  350. PBTPTT02:         ;Netham45  (ChID2)
  351. .dw PBTShot00Draw ;-Unfocused shot power 1 render
  352. .dw PBTShot00Draw ;-Focused   shot power 1 render
  353. .dw PBTShot00Move ;-Unfocused shot power 1 move/collide/remove
  354. .dw PBTShot00Move ;-Focused   shot power 1 move/collide/remove
  355. .dw PBTShot00Draw ;-Unfocused shot power 2 render
  356. .dw PBTShot00Draw ;-Focused   shot power 2 render
  357. .dw PBTShot00Move ;-Unfocused shot power 2 move/collide/remove
  358. .dw PBTShot00Move ;-Focused   shot power 2 move/collide/remove
  359. PBTPTT03:         ;???       (ChID3)
  360. .dw PBTShot00Draw ;-Unfocused shot power 1 render
  361. .dw PBTShot00Draw ;-Focused   shot power 1 render
  362. .dw PBTShot00Move ;-Unfocused shot power 1 move/collide/remove
  363. .dw PBTShot00Move ;-Focused   shot power 1 move/collide/remove
  364. .dw PBTShot00Draw ;-Unfocused shot power 2 render
  365. .dw PBTShot00Draw ;-Focused   shot power 2 render
  366. .dw PBTShot00Move ;-Unfocused shot power 2 move/collide/remove
  367. .dw PBTShot00Move ;-Focused   shot power 2 move/collide/remove
  368. PBTPTT04:         ;???       (ChID4)
  369. .dw PBTShot00Draw ;-Unfocused shot power 1 render
  370. .dw PBTShot00Draw ;-Focused   shot power 1 render
  371. .dw PBTShot00Move ;-Unfocused shot power 1 move/collide/remove
  372. .dw PBTShot00Move ;-Focused   shot power 1 move/collide/remove
  373. .dw PBTShot00Draw ;-Unfocused shot power 2 render
  374. .dw PBTShot00Draw ;-Focused   shot power 2 render
  375. .dw PBTShot00Move ;-Unfocused shot power 2 move/collide/remove
  376. .dw PBTShot00Move ;-Focused   shot power 2 move/collide/remove
  377. PBTPTT05:         ;Nanami    (ChID5)PB00MoveCollide: ;dummy routine
  378. .dw PBTShot00Draw ;-Unfocused shot power 1 render
  379. .dw PBTShot00Draw ;-Focused   shot power 1 render
  380. .dw PBTShot00Move ;-Unfocused shot power 1 move/collide/remove
  381. .dw PBTShot00Move ;-Focused   shot power 1 move/collide/remove
  382. .dw PBTShot00Draw ;-Unfocused shot power 2 render
  383. .dw PBTShot00Draw ;-Focused   shot power 2 render
  384. .dw PBTShot00Move ;-Unfocused shot power 2 move/collide/remove
  385. .dw PBTShot00Move ;-Focused   shot power 2 move/collide/remove
  386. PBTPTT06:         ;Netham45L (ChID6)
  387. .dw PBTShot00Draw ;-Unfocused shot power 1 render
  388. .dw PBTShot00Draw ;-Focused   shot power 1 render
  389. .dw PBTShot00Move ;-Unfocused shot power 1 move/collide/remove
  390. .dw PBTShot00Move ;-Focused   shot power 1 move/collide/remove
  391. .dw PBTShot00Draw ;-Unfocused shot power 2 render
  392. .dw PBTShot00Draw ;-Focused   shot power 2 render
  393. .dw PBTShot00Move ;-Unfocused shot power 2 move/collide/remove
  394. .dw PBTShot00Move ;-Focused   shot power 2 move/collide/remove
  395. PBTPTT07:         ;???       (ChID7)PB00Draw         ;dummy routine
  396. .dw PBTShot00Draw ;-Unfocused shot power 1 render
  397. .dw PBTShot00Draw ;-Focused   shot power 1 render
  398. .dw PBTShot00Move ;-Unfocused shot power 1 move/collide/remove
  399. .dw PBTShot00Move ;-Focused   shot power 1 move/collide/remove
  400. .dw PBTShot00Draw ;-Unfocused shot power 2 render
  401. .dw PBTShot00Draw ;-Focused   shot power 2 render
  402. .dw PBTShot00Move ;-Unfocused shot power 2 move/collide/remove
  403. .dw PBTShot00Move ;-Focused   shot power 2 move/collide/remove
  404.  
  405. ;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  406. ;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  407. ;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  408. ;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  409.  
  410. ;=============================================================================
  411. ;CHARACTER FIRING CODE (what happens when you push the fire button)
  412. ;
  413.  
  414. DevBlockUnfPwr1:  ;These routines pretty much all do the same thing
  415. TestRoutineUnFocPwr1:
  416. TestRoutineUnFocPwr2:
  417. DevBlockUnfPwr2:
  418. ;This routine fires a single centered shot on even cycles and
  419. ;two side shots on odd cycles, every other game cycle
  420.  ld hl,firedelay
  421.  dec (hl)
  422.  ret nz
  423.  ld (hl),2  ;FIRE DELAY FOR STANDARD SHOT IS TWO
  424.  ld hl,charweapondat
  425.  inc (hl)
  426.  bit 0,(hl)  ;check to see if even or odd. Using it to alternate bullet sets
  427.  ld hl,(chary)
  428.  jp z,_      ;jump to two side bullets thing
  429.  PBTSHOT(3,-1,0) ;xofs,yofs,cnt. centered bullet
  430.  ret
  431. _:
  432.  PBTSHOT(0,-1,0) ;left side
  433.  PBTSHOT(6,-1,0) ;right side
  434.  ret
  435.  
  436. DevBlockFocPwr1:  ;Again, these routines all pretty much do the same thing
  437. DevBlockFocPwr2:
  438. TestRoutineFocusPwr1:
  439. TestRoutineFocusPwr2:
  440. ;This routine fires two centered shots every game cycle
  441. ;
  442.  ld hl,firedelay
  443.  dec (hl)
  444.  ret nz
  445.  ld (hl),1  ;ONE GAME CYCLE. THIS CYCLING PROBABLY ISN'T NEEDED THO.
  446.  PBTSHOT(2,-1,0) ;left center
  447.  PBTSHOT(4,-1,0) ;right center
  448.  ret
  449.  
  450.  
  451. ShotHyperdrive:
  452.  PBTSHOT(3,-1,0)
  453.  PBTSHOT(3,-1,0)
  454.  PBTSHOT(3,-1,0)
  455.  PBTSHOT(3,-1,0)
  456.  PBTSHOT(3,-1,0)
  457.  PBTSHOT(3,-1,0)
  458.  PBTSHOT(3,-1,0)
  459.  PBTSHOT(3,-1,0)
  460.  ret
  461.  
  462.  
  463.  
  464.  
  465. IambianFiretest:
  466.  ld hl,firedelay
  467.  dec (hl)
  468.  ret nz
  469.  ld (hl),255  ;FIRE DELAY FOR STANDARD SHOT IS TWO
  470.  LD D,3
  471.  LD E,-1
  472.  LD A,%00000000
  473.  CALL PBTCREATE2
  474.  ret
  475.  
  476.  
  477. ;=============================================================================
  478. ;BULLET RENDERING CODE (cycle 2)
  479. ;
  480.  
  481. PBTShot00Draw:    ;standard 2x3 bullet
  482. ;E=Y D=X normalized (00yy yyyy,00xx xxxx)
  483.  ld c,d    ;keeping a backup of C for later screen merriment :)
  484.  ex de,hl  ;HL=00xxxxxx 00yyyyyy
  485.  sla h
  486.  sla h     ;HL=xxxxxx00 00yyyyyy
  487.  xor a
  488.  add hl,hl
  489.  rla
  490.  add hl,hl
  491.  rla
  492.  add hl,hl ;HL=xxx0000y yyyyy000 A=00000xxx (after next instruction)
  493.  rla
  494.  or L
  495.  ld L,a
  496.  ld a,h
  497.  and %00000001
  498.  or  %10000000
  499.  ld h,a         ;HL=address get. 99ccs. Not the best but filters out bad coord
  500.  ld a,c         ;saved X
  501.  ld b,7
  502.  and b
  503.  xor b          ;checking to see if xxx=7 (straddling bullet)
  504.  jr z,_  ;skip to special case bullets straddling the 8 bit boundary
  505.  xor b
  506.  add a,$20 ;bullet2x2 table, except we're drawing 2x3's
  507.  ld d,$40
  508.  ld e,a
  509.  ld a,(de)
  510.  ld c,a
  511.  ld de,8
  512.  ld a,(hl)
  513.  or c
  514.  ld (hl),a
  515.  add hl,de
  516.  ld a,(hl)
  517.  or c
  518.  ld (hl),a
  519.  add hl,de
  520.  ld a,(hl)
  521.  or c
  522.  ld (hl),a
  523.  jp PBTMainDrawRet     ;go back to main loop
  524. _:
  525.  ld de,7
  526.  set 0,(hl) \ inc hl \ set 7,(hl) \ add hl,de
  527.  set 0,(hl) \ inc hl \ set 7,(hl) \ add hl,de
  528.  set 0,(hl) \ inc hl \ set 7,(hl)
  529.  jp PBTMainDrawRet
  530.  
  531. PBTShot00DrawIam:    ;standard 2x3 bullet
  532. ;E=Y D=X normalized (00yy yyyy,00xx xxxx)
  533.  ld c,d    ;keeping a backup of C for later screen merriment :)
  534.  ex de,hl  ;HL=00xxxxxx 00yyyyyy
  535.  ld a,h
  536.  and %00111111
  537.  ld h,a
  538.  ld a,l
  539.  and %00111111
  540.  ld l,a
  541.  sla h
  542.  sla h     ;HL=xxxxxx00 00yyyyyy
  543.  xor a
  544.  add hl,hl
  545.  rla
  546.  add hl,hl
  547.  rla
  548.  add hl,hl ;HL=xxx0000y yyyyy000 A=00000xxx (after next instruction)
  549.  rla
  550.  or L
  551.  ld L,a
  552.  ld a,h
  553.  and %00000001
  554.  or  %10000000
  555.  ld h,a         ;HL=address get. 99ccs. Not the best but filters out bad coord
  556.  ld a,c         ;saved X
  557.  ld b,7
  558.  and b
  559.  xor b          ;checking to see if xxx=7 (straddling bullet)
  560.  jr z,_  ;skip to special case bullets straddling the 8 bit boundary
  561.  xor b
  562.  add a,$20 ;bullet2x2 table, except we're drawing 2x3's
  563.  ld d,$40
  564.  ld e,a
  565.  ld a,(de)
  566.  ld c,a
  567.  ld de,8
  568.  ld a,(hl)
  569.  or c
  570.  ld (hl),a
  571.  add hl,de
  572.  ld a,(hl)
  573.  or c
  574.  ld (hl),a
  575.  add hl,de
  576.  ld a,(hl)
  577.  or c
  578.  ld (hl),a
  579.  jp PBTMainDrawRet     ;go back to main loop
  580. _:
  581.  ld de,7
  582.  set 0,(hl) \ inc hl \ set 7,(hl) \ add hl,de
  583.  set 0,(hl) \ inc hl \ set 7,(hl) \ add hl,de
  584.  set 0,(hl) \ inc hl \ set 7,(hl)
  585.  jp PBTMainDrawRet
  586.  
  587.  
  588.  
  589. ;=============================================================================
  590. ;BULLET MOVEMENT/COLLISION CODE (cycle 5)
  591. ;
  592.  
  593. PBTShot00Move:    ;standard move by however manieth.
  594. ;E=Y D=X
  595.  inc e \ inc d           ;modify for collision routine
  596.  ld ix,PBTShot00MoveCont ;return address for collision routine
  597.  jp SmallBulletCollision ;IN: DE=XY,
  598. PBTShot00MoveCont:
  599.  dec e \ dec d     ;unmodify from collision routine
  600.  ld a,-3           ;Move the Y direction up by 3 pixels
  601.  add a,e           ;
  602.  bit 7,a           ;
  603.  jp nz,PBTDestroy  ;But if it went above the top (carry), then kill the bullet
  604.  ld e,a            ;Else store the result back to E and wait for the push
  605.  push de           ;save result of movement
  606.  
  607. ;********************************
  608. ;If you needed to modify the counter, you will need the following code.
  609. ;AND DON'T FORGET TO PRESERVE BIT 7 OF L SINCE THAT IS THE FOCUSED FLAG.
  610.  dec sp \ pop hl   ;ENTER CODE
  611.  inc L
  612.  ld a,L
  613.  and %01111111
  614.  cp 10
  615.  jr nz,_
  616.  push hl \ inc sp  ;EXIT CODE
  617.  pop de            ;back to the way it was...
  618.  jp PBTDestroy     ;and get rid of the bullet.
  619. _:
  620.  push hl \ inc sp  ;EXIT CODE
  621. ;********************************
  622.  pop de            ;then advance SP so the bullet table handler can continue
  623.  jp PBTMainMoveRet ;stack unavailable
  624.  
  625.  
  626. SmallBulletCollision: ;E=Y D=X (bullet)
  627.  ld hl,$8E01 ;starting off with byte needed to see if anything is there
  628.  ld bc,$0A08 ;ten enemies, using C as a constant for adjustments
  629. SmallBulletCollisionLoop:
  630.  xor a
  631.  cp (hl)
  632.  jr z,SmallBulletCollisionSkip
  633.  inc L
  634.  inc L
  635.  inc L  ;position Y
  636.  ld a,(hl)
  637.  sub e   ;bY-eY. 10-12. Carry means no collide
  638.  jr nc,SmallBulletCollisionSkipY
  639.  add a,c
  640.  jr nc,SmallBulletCollisionSkipY
  641.  inc L
  642.  ld a,(hl) ;position X
  643.  sub d   ;same deal as above. Skipping comments.
  644.  jr nc,SmallBulletCollisionSkipX
  645.  add a,c    ;
  646.  jr nc,SmallBulletCollisionSkipX
  647. ;Collision happened. We may trash this bullet entry now via calling.
  648.  ld c,1  ;BASE WEAPON POWER
  649.  call DamageEnemy
  650.  jp PBTDestroy
  651. SmallBulletCollisionSkip:
  652.  ld a,20
  653.  jp _
  654. SmallBulletCollisionSkipY:
  655.  ld a,17
  656.  jp _
  657. SmallBulletCollisionSkipX:
  658.  ld a,16
  659. _:
  660.  add a,L
  661.  ld L,a
  662.  djnz SmallBulletCollisionLoop
  663. SmallBulletCollisionBossCheck:
  664.  
  665.  xor a
  666.  cp (hl)
  667.  jp z,SmallBulletCollideReturn
  668.  inc L
  669.  inc L
  670.  inc L  ;position Y
  671.  ld a,(hl)
  672.  sub e   ;bY-eY. 10-12. Carry means no collide
  673.  jp nc,SmallBulletCollideReturn
  674.  add a,c    ;(bY-eY)-8. (22-20)-8. Carry means CAN collide, else no collide
  675.  jp nc,SmallBulletCollideReturn
  676.  inc L
  677.  ld a,(hl) ;position X
  678.  sub d   ;same deal as above. Skipping comments.
  679.  jp nc,SmallBulletCollideReturn
  680.  add a,c    ;
  681.  jp nc,SmallBulletCollideReturn
  682.  ld c,1 ;BASE POWER
  683.  call DamageBoss
  684.  jp PBTDestroy
  685. SmallBulletCollideReturn;
  686.  jp (ix)
  687.  
  688. PBMoveANG:
  689. ;Moves the bullet in the directoin given via an angle
  690. ;Stored in the LSB of the counter
  691.  push de
  692.  Dec sp \ pop HL  ; Get Angle/counter into HL
  693.  ld a,l
  694.  push hl \ inc sp ; restore sp we dont need to write values back in this portion of the routine
  695.  and %00001111    ; mask out un-needed information
  696.  add a,192-8        ;This is added for varience of the angle
  697.  ld h,$82
  698.  ld l,a           ; get pointer on sin/cos table
  699.  ld a,(hl)
  700.  pop de           ; Load D with Y and E with X
  701.  rlc d
  702.  rlc d            ; shift xpos to be our 6.2FP variable
  703.  rlc e
  704.  rlc e            ; Shift ypos to be our 6.2FP cariable
  705.  or a
  706.  RRA \ RRA \ RRA
  707.  RRA \ RRA \ RRA ; Shift sine value down to 000000SS (subject to change)
  708.  
  709.  add a,e
  710.  rrca \ rrca      ; shift back into SSYYYYYY
  711.  ld e,a           ; Merge for new Y pos and save back into D
  712.  
  713.  ld a,l
  714.  add a,64
  715.  ld l,a          ; Add 64 to get Cos value
  716.  
  717.  ld a,(hl)
  718.  cp 193
  719.  jp nc,+_        ;if x is Pos Skip the neg
  720.  neg             ; If X was in the -x rage neg itb2
  721. _:
  722.  or a
  723.  RRA \ RRA \ RRA
  724.  RRA \ RRA \ RRA ; Rotate Cos value to 00000cc
  725.  add a,d
  726.  rrca \ rrca     ; shift back into SSXXXXXX
  727.  ld d,a
  728.  
  729.  push de         ; save onto table
  730.  pop de
  731.  
  732.  jp PBTMainMoveRet
  733.  
  734.  
  735.  
  736.  
  737.  
  738. Add100ToScore:
  739.  ld a,8
  740.  ld (scoretime),a  ;resetting score timer
  741.  ld de,100
  742.  ld hl,(tempscore)
  743.  add hl,de
  744.  ld (tempscore),hl
  745.  ld e,0
  746.  ld hl,(tempscore+2)
  747.  adc hl,de
  748.  ld (tempscore+2),hl
  749.  ret
  750.  
  751. DamageBoss:
  752.  ld a,(charpower)
  753.  add a,c ;base power
  754.  ld hl,bossArmor
  755.  sub (hl)
  756.  jr nc,_
  757.  xor a   ;cannot pierce that armor.
  758. _:
  759.  ld c,a
  760.  ld b,0
  761.  ld hl,(bossHP)
  762.  sbc hl,bc
  763.  jr nc,_
  764.  ld hl,0  ;boss HP never go below 0. Check when script system is invoked
  765. _:
  766.  ld (bossHP),hl
  767.  jp Add100ToScore
  768.  
  769. DamageEnemy:
  770.  inc L
  771.  ld a,(hl) ;enemyHP
  772.  or a
  773.  jp z,Add100ToScore    ;skip trying to kill enemy. Enemy is invincible.
  774.  ld a,(charpower)
  775.  add a,c
  776.  ld c,a
  777.  ld a,(hl) ;curhp-dmg
  778.  sub c
  779.  ld (hl),a
  780.  jr z,$+4
  781.  jp nc,Add100ToScore   ;enemy still alive. Don't destruct
  782.  ld a,-5
  783.  add a,L
  784.  ld L,a
  785.  ld (hl),$00 ;remove enemy. Might want to make a fancy explosion. Not now.
  786.  jp Add100ToScore
Advertisement
Add Comment
Please, Sign In to add comment