FOODMOVE.S 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. ; FOODMOVE.S
  2. ; (THIS FILE ALSO CONTAINS THE ICE CREAM CONE DRIVER, "ICEMELT").
  3. ; THIS ROUTINE MAKES THE FOODS FLY THROUGH THE AIR. IN ADDITION, IT
  4. ; DECREMENTS THE TIME COUNTER ("FINFO"), AND IF IT'S ZERO,
  5. ; DECREMENTS THE SECOND TIME COUNTER ("FLYTIMER"). WHEN THIS TIMER
  6. ; IS ZERO, THEN IT'S TIME TO FADE OUT THE FOOD.
  7. ; THE MOVEMENT ALGORITHM USED IS THE SAME AS FOR THE CHEFS AND CHUCK;
  8. ; TO GET A FASTER SPEED, DIFFERENT MOVEMENT TABLES MUST BE USED.
  9. ; THESE ARE USED BY CHUCK AND CHEFS IN HIGHER RACKS ANYWAY TO
  10. ; GET LIGHTNING FAST GAMES.
  11. ; 8/26/83 : CODE FOR THE ANIMATED BANANA INSERTED.
  12. ; 9/01/83 : CODE FOR THE DISPERSING PEAS INSERTED.
  13. ; 11/04/83 : CODE FOR ANGLED MOVEMENT INSERTED
  14. GLBL PLRACK,GOD
  15. GLBL STATBON,STATDIE
  16. GLBL NUMFOOD
  17. GLBL CHSTAMP,BLOCK1,SPLATCH,SPLATPW,THRWTIME
  18. GLBL NEXTPILE,LASTPILE,FINFO,NUMEPILE
  19. GLBL TAKEFOOD,FXPOS,FYPOS,CSPEED,CFRAME,CTYPE,CFLYTIME
  20. GLBL SPLAT,FLYING,STATHIT,CDIR
  21. GLBL CHASE,MOVE,DEAD,WON,CACOUNT,CSTAMP,CPALW
  22. GLBL ANGLE,STICKING,NUMSTUCK
  23. GLBL CINFO,NUMINAIR,ALLGONE
  24. GLBL STATEND
  25. GLBL STATENDR
  26. GLBL CXSPEED,CXSPEEDL,CYSPEED,CYSPEEDL
  27. GLBL CXPOSL,CYPOSL
  28. GLBL FLYCHAR,FLYPALW
  29. GLBL FSTATE
  30. GLBL FOODMOVE
  31. GLBL WAIT
  32. GLBL PIEFLY,PIEFLYPW,BANFLY,BANFLYPW,PEAFLY
  33. GLBL XVECTORH,XVECTORL,YVECTORH,YVECTORL,SCOREX
  34. FOODSTRT EQU $0F
  35. PILESTRT EQU $01
  36. SCOREY EQU $AF
  37. RAMDEF ; ZERO PAGE
  38. RSEG CODE2
  39. FOODMOVE LDA STATUS
  40. CMP #STATBON
  41. ; BNE FMCONT11
  42. BEQ FMWONJMP becomes a jump
  43. FMCONT11 CMP #STATHIT
  44. BNE FMCONT10
  45. FMWONJMP JMP FMWON
  46. FMWONBYE
  47. FMCONT10 LDX #$1E foodstrt($f) + numfood($10) - 1
  48. FLOOP LDA CYPOS,X
  49. ; BNE FMSKIP11
  50. BEQ NXTFJMP becomes a jump
  51. FMSKIP11 LDA CSTATE,X
  52. CMP #STICKING
  53. BNE FMSKIP12
  54. NXTFJMP JMP NXTFOOD
  55. FMSKIP12 CMP #SPLAT
  56. BNE FMSKIP1
  57. JMP FMSPLAT
  58. FMSKIP1
  59. STX TEMPX
  60. CMP #FLYING
  61. BEQ FM040
  62. CMP #ANGLE
  63. ; BEQ FM030
  64. BNE NXTFJMP same as a jump
  65. FM030 LDY TEMPX ; IF IT'S HITTING SCORE OR CHUCK
  66. ; PUT THE FOOD INDEX IN Y
  67. JSR SETDELTA
  68. LDX TEMPX ; RESTORE FOR "MOVE"
  69. FM040 JSR MOVE ; MOVES THE FOOD
  70. LDX TEMPX ; RESTORE FOOD INDEX
  71. FM060 LDA CSTATE,X ; SEE IF "MOVE" JUST SET THE FOOD
  72. CMP #SPLAT ; TO BE SPLATTING
  73. ; BNE FMSKIP21
  74. BEQ NXTFJMP same as a jump
  75. FMSKIP21 CMP #ANGLE ; IF FLYING AT END OF RACK,
  76. BEQ FMSKIP22 ; DON'T LET IT DISAPPEAR
  77. LDA NUMCYCLE only decrement once every second
  78. CMP #1
  79. BNE FMSKIP22
  80. DEC CFLYTIME,X ; DECREMENT THE TIMER
  81. BEQ FDERASE ; IF ZERO, REMOVE FOOD
  82. ; NOW TEST TO SEE IF ANIMATION IS NECESSARY:
  83. FMSKIP22 LDA CTYPE,X ; TYPE OF FOOD
  84. BEQ BANANI1 ; BANANA TYPE IS 0
  85. CMP #1 ; PEAS
  86. BEQ PEAANI1
  87. JNXTFD JMP NXTFOOD
  88. BANANI1 LDA CFRAME,X
  89. AND #$7F
  90. BNE NXTFOOD
  91. LDA PLRACK ; IF RACK 17 OR ABOVE
  92. AND #$F0 ; THEN ONLY ANIMATE EVERY OTHER TIME.
  93. BEQ BANANI2
  94. LDA CYCLECNT
  95. AND #$01
  96. BNE NXTFOOD
  97. BANANI2 LDA CACOUNT,X ; TELLS WHICH FRAME OF ANIMATION
  98. TAY
  99. LDA BANFLY,Y
  100. STA CSTAMP,X
  101. LDA BANFLYPW,Y
  102. STA CPALW,X
  103. DEC CACOUNT,X
  104. ; BMI ZFM001
  105. BPL JNXTFD
  106. ZFM001 LDA #7 ; 8 DIFFERENT BANANA FRAMES
  107. STA CACOUNT,X
  108. JMP NXTFOOD
  109. PEAANI1 DEC CINFO,X ; ANIMATE COUNTER
  110. ; BEQ PEAANI2
  111. BNE NXTFOOD same as a jump
  112. PEAANI2 LDA #8 ; RESET ANIMATE COUNTER
  113. STA CINFO,X
  114. LDY CACOUNT,X ; FRAME INDEX
  115. BMI NXTFOOD ; IF LAST FRAME WAS ALREADY REACHED
  116. LDA PEAFLY,Y
  117. STA CSTAMP,X
  118. DEC CACOUNT,X ; PREPARE FOR NEXT FRAME
  119. JMP NXTFOOD
  120. FDERASE LDA STATUS
  121. CMP #STATBON ; IF FLYING TOWARDS SCORE,
  122. BEQ FDERASE1 ; GO ALL THE WAY TO THE WALL
  123. CMP #STATDIE ; IF FLYING TOWARDS HERO,
  124. BMI FDERASE2
  125. FDERASE1 LDA #$7F ; KEEP IT FLYING
  126. STA CFLYTIME,X
  127. BNE NXTFOOD same as a jump
  128. FDERASE2 LDA #0
  129. STA CYPOS,X
  130. NXTFOOD DEX
  131. CPX #FOODSTRT
  132. BMI FMSKIP9
  133. JMP FLOOP
  134. FMSKIP9
  135. FMBYE
  136. RTS
  137. ; THIS CODE IS EXECUTED WHEN THE HERO HAS FINISHED MUNCHING AND
  138. ; IS SMILING; THE FOOD SHOULD ALL FLY UP TO THE SCORE
  139. ; THIS SAME CODE IS USED TO MAKE THE FOOD FLY AT THE HERO
  140. ; WHEN HE'S JUST DIED.
  141. ;FMDIE LDA STATUS
  142. ; CMP #STATHIT
  143. ; BEQ FMWON
  144. ; JMP FMBYE
  145. FMDIE
  146. FMWON
  147. LDA NUMINAIR ; IF THERE'S A FREE FOOD SPACE, THROW
  148. CMP #NUMFOOD
  149. ; BMI FMWCONT0
  150. BPL FMWBYE
  151. FMWCONT0 LDA ALLGONE ; TEST TO SEE IF ALL ARE IN THE AIR
  152. BNE ZFM003 ; IF SO, STOP IF NUMINAIR == 0
  153. LDA THRWTIME ; SPACES OUT FOOD THROWS
  154. BEQ ZFM004 ; THROW IF IT'S TIME
  155. DEC THRWTIME
  156. FMWBYE JMP FMWONBYE
  157. ZFM003 LDA NUMINAIR
  158. BNE FMWBYE
  159. JMP ALLOVER ; IF NO FOODS REMAIN IN THE AIR
  160. ZFM004 LDA #5 ; "DEBOUNCING" TIMER FOR FOOD
  161. STA THRWTIME
  162. LDX NEXTPILE ; FIND A FOOD
  163. STX LASTPILE
  164. ZFMLOOP1 LDA FINFO,X
  165. ASL A ; BIT 6 HIGH MEANS BOTTOM HALF
  166. BMI ZFMEND1 ; ONLY TOP HALVES
  167. AND #$08 ; DONT THROW WATERMELONS AT SCORE
  168. BEQ ZFMENDZZ
  169. LDA STATUS ; THROW WATERMELON IF CHARLIE DIED.
  170. CMP #STATHIT
  171. BNE ZFMEND1
  172. ZFMENDZZ LDA FSTATE,X
  173. BNE ZFMWONTH ; IF THE PILE IS NON-EMPTY
  174. ZFMEND1 INX
  175. STX NEXTPILE
  176. CPX LASTPILE
  177. BNE ZFMEND2
  178. JMP SETALLGN ; IF WE'VE LOOPED ALL THE WAY AROUND
  179. ZFMEND2 CPX #PILESTRT+NUMEPILE
  180. BMI ZFMLOOP1
  181. LDX #PILESTRT ; WE'VE REACHED THE END-- WRAP AROUND
  182. STX NEXTPILE
  183. CPX LASTPILE
  184. BNE ZFMLOOP1
  185. JMP SETALLGN
  186. ZFMWONTH INC NEXTPILE ; NEXT ONE TO CHECK IS ONE BEYOND
  187. LDA NEXTPILE
  188. CMP #PILESTRT+NUMEPILE
  189. BMI ITSOKAY
  190. LDA #PILESTRT
  191. STA NEXTPILE
  192. ITSOKAY TXA
  193. PHA ; SAVE PILE INDEX
  194. TAY ; PILE INDEX MUST BE IN Y
  195. JSR TAKEFOOD ; GET ONE FOOD FROM PILE
  196. TAY ; FOOD INDEX IS NOW IN A
  197. PLA
  198. TAX ; X CONTAINS PILE INDEX
  199. INC NUMINAIR
  200. LDA FXPOS,X ; SET FOOD POSITION
  201. STA CXPOS,Y
  202. LDA FYPOS,X
  203. STA CYPOS,Y
  204. LDA #ANGLE
  205. STA CSTATE,Y
  206. ; INITIALIZE THE DELTA VALUES FOR ANGLED MOVEMENT
  207. LDA STATUS
  208. CMP #STATBON
  209. BNE ZFMDIE ; "GOALN" SET IN "HEROKILL"
  210. LDX CURRENT ; ELSE ITS HITTING CHUCK
  211. LDA SCOREX,X
  212. STA GOALX
  213. LDA #SCOREY
  214. STA GOALY
  215. ZFMDIE
  216. JSR SETDELTA ; DOESN'T ALTER Y
  217. STY TEMPY
  218. LDX TEMPY ; FOOD INDEX IN "X" FOR CHASE
  219. JSR CHASE ; SETS "CDIR" FOR SPLAT POSITION
  220. LDY TEMPY ; "Y" USED BY "CHASE"
  221. LDA #0 ; INITIALIZE LOW BYTES OF POSITION
  222. STA CYPOSL,Y
  223. STA CXPOSL,Y
  224. ; NOW INITIALIZE FOOD FOR ANIMATION, CHARACTERS, ETC.
  225. ZFMANIM LDA CTYPE,Y
  226. CMP #2 ; PIE TYPE IS 2
  227. BEQ ZFMTH00
  228. CMP #1 ; PEAS
  229. BEQ ZFMTH01
  230. ZFMTH02 LDA #01 ;ANYTHING BUT PEAS
  231. STA CINFO,Y ; FOR ALL TYPES OTHER THAN PEAS
  232. LDA #0
  233. STA CACOUNT,Y
  234. JMP ZFMTH10
  235. ZFMTH00 LDA CDIR,Y ; USE DIRECTION AS TABLE INDEX
  236. TAX
  237. LDA PIEFLY,X ; GET STAMP
  238. STA CSTAMP,Y ; STORE IT
  239. LDA PIEFLYPW,X ; GET PALETTE WIDTH
  240. STA CPALW,Y
  241. JMP ZFMTH10
  242. ZFMTH01 LDA #1 ; IF IT'S PEAS, SET UP FOR DISPERSAL
  243. STA CACOUNT,Y ; FRAME INDEX
  244. LDA #16
  245. STA CINFO,Y
  246. *ZFMTH10 LDA #$81 ; DOUBLE THE SPEED
  247. ZFMTH10 LDA #0
  248. STA CSPEED,Y
  249. STA CFRAME,Y
  250. LDA #$FF ; 4 SECONDS
  251. STA CFLYTIME,Y
  252. JMP FMWONBYE ; THROW ONE PER CODE CYCLE
  253. SETALLGN LDA #$FF
  254. STA ALLGONE
  255. JMP FMWONBYE
  256. ALLOVER LDA STATUS
  257. CMP #STATBON ; IF HE'S WON
  258. BEQ ZALLOV01
  259. LDA #DEAD ; ELSE, WE KNOW HE'S LOST
  260. STA CSTATE
  261. JMP ZALLOV02
  262. ZALLOV01 LDA #WON
  263. STA CSTATE ; MAKES NEW RACK START
  264. ZALLOV02 LDA #90 ; WAIT FOR 1.5 SECONDS
  265. STA WAITCNT
  266. LDA DOITOVER
  267. BEQ ZALLOV03 ; NOT AN IR
  268. LDA #STATENDR ; AN IR
  269. JMP ZALLOV04
  270. ZALLOV03 LDA #STATEND ; ONLY CHEF DRIVER WILL RUN
  271. ZALLOV04 STA STATUS
  272. ; INSTEAD OF "RTS" TO "GAME", POP THE RETURN ADDRESS AND JUMP TO GOD
  273. PLA
  274. PLA
  275. ENDCYCLE
  276. ; HANDLE THE ANIMATION OF THE SPLATTING CHARACTER
  277. ; NOTE: IF IT'S HITTING THE HERO, MAKE IT STICK; THIS WILL BE THE CASE
  278. ; IF "STATUS" IS "STATHIT"
  279. FMSPLAT DEC CACOUNT,X
  280. BEQ ZFMSP00
  281. RTS ; JMP FMBYE
  282. ZFMSP00 LDA #2
  283. STA CACOUNT,X
  284. DEC CFRAME,X
  285. BMI AENDSPLT
  286. LDY CFRAME,X
  287. LDA SPLATCH,Y
  288. STA CSTAMP,X
  289. LDA CPALW,X
  290. AND #$E0 ; TOP THREE BITS ARE PALETTE
  291. ORA SPLATPW,Y
  292. STA CPALW,X
  293. JMP NXTFOOD
  294. ; Make the food dissappear-- check to see if it's hitting the score
  295. AENDSPLT LDA #DEAD ; NO LONGER SPLAT
  296. STA CSTATE,X
  297. LDA #0 ; MAKE IT AVAILABLE FOR NEXT TAKEFOOD
  298. STA CYPOS,X
  299. LDA STATUS
  300. CMP #STATBON
  301. BNE ZENDSP02
  302. DEC NUMINAIR
  303. ZENDSP02 LDA #BLOCK1
  304. STA CHSTAMP,X
  305. JMP NXTFOOD
  306. ; THIS ROUTINE IS CALLED FIRST WHEN EACH FOOD IS TAKEN FROM A PILE AND
  307. ; LATER TO PERIODICALLY UPDATE IT'S FLIGHT.
  308. SETDELTA LDA #0
  309. STA TEMP2
  310. STA TEMP3
  311. STA TEMP4
  312. LDA GOALX
  313. SEC
  314. SBC CXPOS,Y
  315. BCS SD0001
  316. INC TEMP2 ; FLAG FOR NEGATIVE DX
  317. EOR #$FF
  318. CLC
  319. ADC #1
  320. SD0001 STA TEMP0 ; DX
  321. LDA GOALY
  322. SEC
  323. SBC CYPOS,Y
  324. BCS SD0002
  325. INC TEMP3 ; FLAG FOR NEGATIVE DY
  326. EOR #$FF
  327. CLC
  328. ADC #1
  329. SD0002 STA TEMP1 ; DY
  330. ; NORMALIZE VECTOR FOR ASPECT RATIO. FLIP THE VECTOR TO THE FIRST OCTANT
  331. ; (NNE)
  332. LSR A ; 5/8 = 1/2 + 1/8
  333. STA TEMP5
  334. LSR A
  335. LSR A
  336. CLC
  337. ADC TEMP5
  338. CMP TEMP0
  339. BCS SD0003
  340. INC TEMP4 ; FLAG FOR OCTANT FLIP
  341. TAX ; SWITCH DX AND DY
  342. LDA TEMP0
  343. STX TEMP0
  344. SD0003 LSR A ; DY = DY/4
  345. LSR A
  346. STA TEMP1
  347. ; COMPUTE 3/8 DX
  348. LDA TEMP0
  349. LSR A
  350. LSR A
  351. STA TEMP5
  352. LSR A
  353. CLC
  354. ADC TEMP5
  355. STA TEMP6
  356. ; COMPUTE SECTOR 0,1,2,3
  357. LDA TEMP0
  358. LSR A
  359. STA TEMP5
  360. LSR A
  361. LSR A
  362. CLC
  363. ADC TEMP5
  364. LDX #0
  365. CMP TEMP1
  366. BCC SECTOR01
  367. LDX #2
  368. LDA #0
  369. JMP SECTOR23
  370. SECTOR01 LDA TEMP0
  371. SECTOR23 CLC
  372. ADC TEMP6
  373. CMP TEMP1
  374. BCC SECTOR02
  375. SECTOR13 INX
  376. SECTOR02 STX TEMP0
  377. ; NOW UNFOLD THIS 0-3 NUMBER INTO THE CORRECT OCTANT BY
  378. ; USING THE THREE "NEGATIVE" FLAGS:
  379. LDX TEMP4 ; DIAGONAL FLIP
  380. BEQ SD0010
  381. LDA #7
  382. SEC
  383. SBC TEMP0
  384. STA TEMP0
  385. SD0010
  386. LDX TEMP3 ; DY NEGATIVE
  387. BEQ SD0011
  388. LDA #15
  389. SEC
  390. SBC TEMP0
  391. STA TEMP0
  392. SD0011
  393. LDX TEMP2 ; DX NEGATIVE
  394. BEQ SD0012
  395. LDA #31
  396. SEC
  397. SBC TEMP0
  398. STA TEMP0
  399. SD0012
  400. LDA TEMP0
  401. AND #$1F
  402. ; NOW AT LAST WE'VE GOT AN INDEX 0-31. SET THE FIXNUM DELTAS FROM THE
  403. ; TABLES
  404. TAX
  405. LDA XVECTORH,X
  406. STA CXSPEED,Y
  407. LDA XVECTORL,X
  408. STA CXSPEEDL,Y
  409. LDA YVECTORH,X
  410. STA CYSPEED,Y
  411. LDA YVECTORL,X
  412. STA CYSPEEDL,Y
  413. RTS
  414. END