Geekboy

Untitled

Oct 28th, 2011
145
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),1  ;FIRE DELAY FOR STANDARD SHOT IS TWO
  470.  LD D,3
  471.  LD E,-1
  472.     ld  hl,lfsrseed1
  473.     ld  a,(hl)
  474.     rrca
  475.     ld  (hl),a
  476.     jp nc,+_
  477.     xor %00111000
  478.     ld  (hl),a
  479. _:
  480.     and %01111111
  481.     set 6,a
  482.  CALL PBTCREATE2
  483.   LD D,3
  484.  LD E,-1
  485.     ld  hl,lfsrseed1
  486.     ld  a,(hl)
  487.     rrca
  488.     ld  (hl),a
  489.     jp nc,+_
  490.     xor %00111000
  491.     ld  (hl),a
  492. _:
  493.     and %01111111
  494.     set 6,a
  495.  
  496.  CALL PBTCREATE2
  497.   LD D,3
  498.  LD E,-1
  499.     ld  hl,lfsrseed1
  500.     ld  a,(hl)
  501.     rrca
  502.     ld  (hl),a
  503.     jp nc,+_
  504.     xor %00111000
  505.     ld  (hl),a
  506. _:
  507.     and %01111111
  508.     set 6,a
  509.  CALL PBTCREATE2
  510.  ret
  511.  
  512.  
  513. ;=============================================================================
  514. ;BULLET RENDERING CODE (cycle 2)
  515. ;
  516.  
  517. PBTShot00Draw:    ;standard 2x3 bullet
  518. ;E=Y D=X normalized (00yy yyyy,00xx xxxx)
  519.  ld c,d    ;keeping a backup of C for later screen merriment :)
  520.  ex de,hl  ;HL=00xxxxxx 00yyyyyy
  521.  sla h
  522.  sla h     ;HL=xxxxxx00 00yyyyyy
  523.  xor a
  524.  add hl,hl
  525.  rla
  526.  add hl,hl
  527.  rla
  528.  add hl,hl ;HL=xxx0000y yyyyy000 A=00000xxx (after next instruction)
  529.  rla
  530.  or L
  531.  ld L,a
  532.  ld a,h
  533.  and %00000001
  534.  or  %10000000
  535.  ld h,a         ;HL=address get. 99ccs. Not the best but filters out bad coord
  536.  ld a,c         ;saved X
  537.  ld b,7
  538.  and b
  539.  xor b          ;checking to see if xxx=7 (straddling bullet)
  540.  jr z,_  ;skip to special case bullets straddling the 8 bit boundary
  541.  xor b
  542.  add a,$20 ;bullet2x2 table, except we're drawing 2x3's
  543.  ld d,$40
  544.  ld e,a
  545.  ld a,(de)
  546.  ld c,a
  547.  ld de,8
  548.  ld a,(hl)
  549.  or c
  550.  ld (hl),a
  551.  add hl,de
  552.  ld a,(hl)
  553.  or c
  554.  ld (hl),a
  555.  add hl,de
  556.  ld a,(hl)
  557.  or c
  558.  ld (hl),a
  559.  jp PBTMainDrawRet     ;go back to main loop
  560. _:
  561.  ld de,7
  562.  set 0,(hl) \ inc hl \ set 7,(hl) \ add hl,de
  563.  set 0,(hl) \ inc hl \ set 7,(hl) \ add hl,de
  564.  set 0,(hl) \ inc hl \ set 7,(hl)
  565.  jp PBTMainDrawRet
  566.  
  567. PBTShot00DrawIam:    ;standard 2x3 bullet
  568. ;E=Y D=X normalized (00yy yyyy,00xx xxxx)
  569.  ld c,d    ;keeping a backup of C for later screen merriment :)
  570.  ex de,hl  ;HL=00xxxxxx 00yyyyyy
  571.  ld a,h
  572.  and %00111111
  573.  
  574.  ld h,a
  575.  ld a,l
  576.  and %00111111
  577.  ld l,a
  578.  cp 63
  579.  jp z,PBTMainDrawRet
  580.  sla h
  581.  sla h     ;HL=xxxxxx00 00yyyyyy
  582.  xor a
  583.  add hl,hl
  584.  rla
  585.  add hl,hl
  586.  rla
  587.  add hl,hl ;HL=xxx0000y yyyyy000 A=00000xxx (after next instruction)
  588.  rla
  589.  or L
  590.  ld L,a
  591.  ld a,h
  592.  and %00000001
  593.  or  %10000000
  594.  ld h,a         ;HL=address get. 99ccs. Not the best but filters out bad coord
  595.  ld a,c         ;saved X
  596.  ld b,7
  597.  and b
  598.  xor b          ;checking to see if xxx=7 (straddling bullet)
  599.  jr z,_  ;skip to special case bullets straddling the 8 bit boundary
  600.  xor b
  601.  add a,$20 ;bullet2x2 table, except we're drawing 2x3's
  602.  ld d,$40
  603.  ld e,a
  604.  ld a,(de)
  605.  ld c,a
  606.  ld de,8
  607.  ld a,(hl)
  608.  or c
  609.  ld (hl),a
  610.  add hl,de
  611.  ld a,(hl)
  612.  or c
  613.  ld (hl),a
  614.  add hl,de
  615.  ld a,(hl)
  616.  or c
  617.  ld (hl),a
  618.  jp PBTMainDrawRet     ;go back to main loop
  619. _:
  620.  ld a,c
  621.  cp 63
  622.  jp nc,PBTMainDrawREt
  623.  ld de,7
  624.  set 0,(hl) \ inc hl \ set 7,(hl) \ add hl,de
  625.  set 0,(hl) \ inc hl \ set 7,(hl) \ add hl,de
  626.  set 0,(hl) \ inc hl \ set 7,(hl)
  627.  jp PBTMainDrawRet
  628.  
  629.  
  630.  
  631. ;=============================================================================
  632. ;BULLET MOVEMENT/COLLISION CODE (cycle 5)
  633. ;
  634.  
  635. PBTShot00Move:    ;standard move by however manieth.
  636. ;E=Y D=X
  637.  inc e \ inc d           ;modify for collision routine
  638.  ld ix,PBTShot00MoveCont ;return address for collision routine
  639.  jp SmallBulletCollision ;IN: DE=XY,
  640. PBTShot00MoveCont:
  641.  dec e \ dec d     ;unmodify from collision routine
  642.  ld a,-3           ;Move the Y direction up by 3 pixels
  643.  add a,e           ;
  644.  bit 7,a           ;
  645.  jp nz,PBTDestroy  ;But if it went above the top (carry), then kill the bullet
  646.  ld e,a            ;Else store the result back to E and wait for the push
  647.  push de           ;save result of movement
  648.  
  649. ;********************************
  650. ;If you needed to modify the counter, you will need the following code.
  651. ;AND DON'T FORGET TO PRESERVE BIT 7 OF L SINCE THAT IS THE FOCUSED FLAG.
  652.  dec sp \ pop hl   ;ENTER CODE
  653.  inc L
  654.  ld a,L
  655.  and %01111111
  656.  cp 10
  657.  jr nz,_
  658.  push hl \ inc sp  ;EXIT CODE
  659.  pop de            ;back to the way it was...
  660.  jp PBTDestroy     ;and get rid of the bullet.
  661. _:
  662.  push hl \ inc sp  ;EXIT CODE
  663. ;********************************
  664.  pop de            ;then advance SP so the bullet table handler can continue
  665.  jp PBTMainMoveRet ;stack unavailable
  666.  
  667.  
  668. SmallBulletCollision: ;E=Y D=X (bullet)
  669.  ld hl,$8E01 ;starting off with byte needed to see if anything is there
  670.  ld bc,$0A08 ;ten enemies, using C as a constant for adjustments
  671. SmallBulletCollisionLoop:
  672.  xor a
  673.  cp (hl)
  674.  jr z,SmallBulletCollisionSkip
  675.  inc L
  676.  inc L
  677.  inc L  ;position Y
  678.  ld a,(hl)
  679.  sub e   ;bY-eY. 10-12. Carry means no collide
  680.  jr nc,SmallBulletCollisionSkipY
  681.  add a,c
  682.  jr nc,SmallBulletCollisionSkipY
  683.  inc L
  684.  ld a,(hl) ;position X
  685.  sub d   ;same deal as above. Skipping comments.
  686.  jr nc,SmallBulletCollisionSkipX
  687.  add a,c    ;
  688.  jr nc,SmallBulletCollisionSkipX
  689. ;Collision happened. We may trash this bullet entry now via calling.
  690.  ld c,1  ;BASE WEAPON POWER
  691.  call DamageEnemy
  692.  jp PBTDestroy
  693. SmallBulletCollisionSkip:
  694.  ld a,20
  695.  jp _
  696. SmallBulletCollisionSkipY:
  697.  ld a,17
  698.  jp _
  699. SmallBulletCollisionSkipX:
  700.  ld a,16
  701. _:
  702.  add a,L
  703.  ld L,a
  704.  djnz SmallBulletCollisionLoop
  705. SmallBulletCollisionBossCheck:
  706.  
  707.  xor a
  708.  cp (hl)
  709.  jp z,SmallBulletCollideReturn
  710.  inc L
  711.  inc L
  712.  inc L  ;position Y
  713.  ld a,(hl)
  714.  sub e   ;bY-eY. 10-12. Carry means no collide
  715.  jp nc,SmallBulletCollideReturn
  716.  add a,c    ;(bY-eY)-8. (22-20)-8. Carry means CAN collide, else no collide
  717.  jp nc,SmallBulletCollideReturn
  718.  inc L
  719.  ld a,(hl) ;position X
  720.  sub d   ;same deal as above. Skipping comments.
  721.  jp nc,SmallBulletCollideReturn
  722.  add a,c    ;
  723.  jp nc,SmallBulletCollideReturn
  724.  ld c,1 ;BASE POWER
  725.  call DamageBoss
  726.  jp PBTDestroy
  727. SmallBulletCollideReturn;
  728.  jp (ix)
  729.  
  730. PBMoveANG:
  731. ;Moves the bullet in the directoin given via an angle
  732. ;Stored in the LSB of the counter
  733. ;Doing: F.ttt.aaaa, where F=focused(donotmod),t=time,a=angle
  734. ;E=Y D=X
  735.  inc e \ inc d           ;modify for collision routine
  736.  ld ix,PBMoveANGcont     ;return address for collision routine
  737.  jp SmallBulletCollision ;IN: DE=XY,
  738. PBMoveANGcont:
  739.  dec e \ dec d     ;unmodify from collision routine
  740.  push de           ;move the stack back for something...
  741. ;********************************
  742. ;If you needed to modify the counter, you will need the following code.
  743. ;AND DON'T FORGET TO PRESERVE BIT 7 OF L SINCE THAT IS THE FOCUSED FLAG.
  744.  dec sp \ pop hl   ;ENTER CODE
  745.  ld a,(gametimer1)
  746.  and 1   ;ticking the timer every other game cycle
  747.  ld a,L
  748.  jr z,_
  749.  sub   %00010000
  750.  and   %01110000
  751.  or a
  752.  jr nz,_
  753.  push hl \ inc sp  ;EXIT CODE
  754.  pop de             ;back to the way it was...
  755.  jp PBTDestroy      ;and get rid of the bullet.
  756. _:
  757.  xor L
  758.  and %01110000
  759.  xor L
  760.  ld L,a
  761.  push hl \ inc sp   ;EXIT CODE
  762.  ld a,L
  763.  pop hl             ;then advance SP so the bullet table handler can continue
  764.  and %00001111
  765.  bit 3,a
  766.  add a,a            ;doubling the spread
  767.  add a,192-16        ;get true angle spread
  768.  ld c,a
  769.  ld b,$82           ;and now complete the address thinger. in BC
  770.  rlc L \ rlc L      ;From %ss.yyyyyy to %yyyyyy.ss
  771.  ld a,(bc)          ;Get %AAAaaaaa. Let's use upper 3 bits
  772.  rlca \ rlca \ rlca ;Got %aaaaaAAA
  773.  and %00000111
  774.  neg                ;We had a positive number but we need movement in negative
  775.  add a,L
  776.  jp nc,PBTDestroy   ;Bullet went past top. Destroy it.
  777.  cp 240
  778.  
  779.  jp nc,PBTDestroy    ; special case handling for top of screen shooting people
  780.  ld L,a
  781.  ld a,c
  782.  add a,64
  783.  ld c,a
  784.  ld a,(bc)          ;Getting X angle.
  785.  rlca \ rlca \ rlca ;like above
  786.  and %00000111
  787.  bit 7,c            ;zero-crossing?
  788.  jr z,_             ;jump if not negative.
  789.  neg
  790. _:
  791.  rlc h \ rlc h
  792.  add a,h
  793.  ld h,a
  794.  and %00111110
  795.  jp z,PBTDestroy
  796.  
  797.  ;jp m,PBTDestroy   ;If any of these bits set, then kill bullet
  798.  rrc h \ rrc h
  799.  rrc L \ rrc L
  800.  push hl
  801.  pop hl
  802.  jp PBTMainMoveRet ;stack unavailable
  803.  
  804.  
  805.  
  806.  
  807.  
  808.  
  809.  
  810.  
  811.  
  812.  
  813. Add100ToScore:
  814.  ld a,8
  815.  ld (scoretime),a  ;resetting score timer
  816.  ld de,100
  817.  ld hl,(tempscore)
  818.  add hl,de
  819.  ld (tempscore),hl
  820.  ld e,0
  821.  ld hl,(tempscore+2)
  822.  adc hl,de
  823.  ld (tempscore+2),hl
  824.  ret
  825.  
  826. DamageBoss:
  827.  ld a,(charpower)
  828.  add a,c ;base power
  829.  ld hl,bossArmor
  830.  sub (hl)
  831.  jr nc,_
  832.  xor a   ;cannot pierce that armor.
  833. _:
  834.  ld c,a
  835.  ld b,0
  836.  ld hl,(bossHP)
  837.  sbc hl,bc
  838.  jr nc,_
  839.  ld hl,0  ;boss HP never go below 0. Check when script system is invoked
  840. _:
  841.  ld (bossHP),hl
  842.  jp Add100ToScore
  843.  
  844. DamageEnemy:
  845.  inc L
  846.  ld a,(hl) ;enemyHP
  847.  or a
  848.  jp z,Add100ToScore    ;skip trying to kill enemy. Enemy is invincible.
  849.  ld a,(charpower)
  850.  add a,c
  851.  ld c,a
  852.  ld a,(hl) ;curhp-dmg
  853.  sub c
  854.  ld (hl),a
  855.  jr z,$+4
  856.  jp nc,Add100ToScore   ;enemy still alive. Don't destruct
  857.  ld a,-5
  858.  add a,L
  859.  ld L,a
  860.  xor a
  861.  ld (hl),a ;remove enemy. Might want to make a fancy explosion. Not now.
  862.  dec hl
  863.  dec a
  864.  ld (hl),a ;set primary counter to 0 (up to 8) for explosiony stuffs
  865.  jp Add100ToScore
Advertisement
Add Comment
Please, Sign In to add comment