CHEFMOVE.S 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879
  1. ; CHEFMOVE.S
  2. ; THIS ROUTINE MAKES THE CHEFS CHASE THE HERO.
  3. ; EACH CHEF HAS A CERTAIN POINT ON THE SCREEN TO AIM FOR. THE
  4. ; COORDINATES OF THIS POINT ARE STORED IN "XGOAL", "YGOAL".
  5. ; THE FIRST PART OF THE CHEF LOOP FIGURES OUT THESE TWO VALUES
  6. ; DEPENDING ON WHICH CHEF IS CURRENTLY BEING PROCESSED; THE LATER
  7. ; PART MOVES THE CHEF TOWARDS THAT POINT.
  8. ; THE METHOD OF FIGURING THE DIRECTION IS OBSCURE:
  9. ; DO X AND Y AXES SEPARATELY. FIRST DO THE Y AXIS.
  10. ; FOR EACH AXIS, COMPARE THE GOAL AND THE CHEF COORDINATES-; IF
  11. ; EQUAL, "STA 0". SAVE THIS VALUE IN "TEMP0" WHILE DOING THE
  12. ; SAME FOR X AXIS. USE THE FOLLOWING FORMULA TO DERIVE AN INDEX
  13. ; INTO THE DIRECTION TABLE FROM THESE TWO VALUES:
  14. ; (X + 2) * 4 + (Y + 1) - 4
  15. GLBL CHASE
  16. GLBL CHEFMOVE
  17. GLBL MKREJOY
  18. CHEFMOVE LDA STATUS ; IF THEY'RE WAITING AFTER A RISE,
  19. CMP #STATWAIT ; THEN DON'T DO ANYTHING
  20. BNE CHCONT0
  21. JMP RISELOOP
  22. CHCONT0 LDX #12 ; #CHEFSTRT+#NUMCHEF-3
  23. DOCHEF STX TEMPX
  24. LDA CSTATE,X ; STATUS IS >= STATDIEH
  25. CMP #REJOYING
  26. BMI CHCONT12 there are two rejoice states, $15 and
  27. JMP REJOICE $16
  28. CHCONT12 CMP #FEETFALL ; THREE FALLING STATES
  29. BNE CHCONT1
  30. JMP FTFALL
  31. CHCONT1 CMP #HEADFALL
  32. BNE CHCONT2
  33. JMP HDFALL
  34. CHCONT2 CMP #HATFALL
  35. BNE CHCONT4
  36. JMP HTFALL
  37. CHCONT4 CMP #HATRISE ; THREE RISING STATES
  38. BNE CHCONT5
  39. JMP HTRISE
  40. CHCONT5 CMP #HEADRISE
  41. BNE CHCONT6
  42. JMP HDRISE
  43. CHCONT6 CMP #FEETRISE
  44. BNE CHCONT7
  45. JMP FTRISE
  46. CHCONT7 CMP #LEAVING
  47. BNE CHCONT8
  48. JMP CHMOVE
  49. CHCONT8 CMP #NOTYET ; IF THIS IS AN EARLY RACK
  50. BNE CHCONT9
  51. JMP NXTCHEF
  52. ; DON'T PROCESS INVISIBLE CHEFS IF THE STATUS IS WON OR BON.
  53. ; OR DYING !
  54. CHCONT9
  55. LDA STATUS
  56. CMP #STATWON ; IF HERO IS MUNCHING, KEEP DIRECTION
  57. BEQ ZCH204
  58. CMP #STATBON ; IF FOOD IS HITTING SCORE
  59. BEQ ZCH204
  60. CMP #STATDIEH ; IF CHUCK HAS DIED VIA ANYTHING
  61. BPL ZCH204 ; ALSO HANDLES "STATEND"
  62. LDA CREATOR,X ; COUNTER FOR DEATH AND REBIRTH
  63. BEQ ZCH202
  64. ZCH201 DEC CREATOR,X ; IF NOT ZERO, DECREMENT
  65. ZCH202 LDA CYPOS,X ; IF ZERO, GO TO CHEFWAIT
  66. BNE ZCH203 ; ELSE, MOVE HIM
  67. JMP CHEFWAIT
  68. ZCH203 LDA CINFO,X ; A DIRECTION-CHANGE TIMER
  69. BMI ZCH100 ; ONLY CHANGE WHEN IT REACHES 0
  70. DEC CINFO,X ; OTHERWISE, DECREMENT AND MOVE HIM
  71. ; WE ALWAYS COME HERE BEFORE CONTINUING THROUGH THIS ROUTINE:
  72. ZCH204 LDA CYPOS,X ; DO THIS TEST AGAIN FOR THE CASE
  73. BNE ZCH205 ; WHERE THE RACK IS ENDING
  74. JMP NXTCHEF ; DON'T PROCESS DEAD CHEFS
  75. ZCH205 JMP CHMOVE ; SKIP OVER DIRECTION CHANGE STUFF
  76. ; IF WE GET HERE, IT'S TIME TO CHANGE THE DIRECTION OF THIS CHEF:
  77. ZCH100 JSR RANDOM ; RESET THE MOOD COUNTER
  78. AND MOODTUFF ; 0-$1F
  79. STA CINFO,X
  80. ; THE NEXT BODY OF CODE DECIDES WHICH "GOALX, GOALY" SETTING ROUTINE
  81. ; TO USE.
  82. STX TEMP0 ; SAVE REGISTER
  83. LDA JOYDIR ; JOYSTICK FOR HERO
  84. CMP #8 ; IF JOYSTICK IS CENTERED,
  85. BNE SETCHASE
  86. ALLCHASE JMP FCHEF ; FOLLOWER ALGORITHM
  87. SETCHASE CPX #3 ; FOLLOWER
  88. BEQ ALLCHASE ; IF NOT, CONTINUE FCHEF
  89. ZCH010 CPX #9 ; INTERLOPER
  90. BNE ZCH020 ; IF NOT, CONTINUE
  91. JMP ICHEF ; INTERLOPER CHEF
  92. ZCH020 CPX #12 ; ANTICIPATOR CHEF
  93. BNE ZCH030
  94. JMP ACHEF
  95. ZCH030 JMP BCHEF ; BEHINDOR CHEF IS THE 2ND (IDX = 6)
  96. ZCHASE STA GOALY
  97. LDX TEMP0 ; RESTORE REGISTER
  98. JSR CHASE ; SETS NEW DIRECTION
  99. ; BASED ON VALUES IN "GOALX, GOALY".
  100. LDA CDIR,X ; NO CENTER FOR CHEFS !
  101. CMP #8
  102. BNE ZCHASE00
  103. LDA OLDDIR,X ; KEEP OLD DIRECTION.,
  104. STA CDIR,X
  105. ; NOW SET THE HEAD TO FACE IN THIS DIRECTION:
  106. ZCHASE00 TAY
  107. LDA CHHEADS,Y ; TELLS US THE CHARACTER
  108. STA CSTAMP+1,X ; HEAD STAMP (SECOND OF THE THREE)
  109. CHMOVE LDA CDIR,X ; IF DIRECTION HAS CHANGED,
  110. CMP OLDDIR,X ; RESET THE DELTAS
  111. BEQ CHMOVE01
  112. LDY CSINDEX,X
  113. LDA MTABINC,Y ; GET INDEX FOR PROPER TABLE AND DIR
  114. ASL A
  115. ASL A
  116. ASL A
  117. ADC CDIR,X
  118. TAY
  119. LDA STABXL,Y
  120. STA CXSPEEDL,X
  121. LDA STABXH,Y
  122. STA CXSPEED,X
  123. LDA STABYL,Y
  124. STA CYSPEEDL,X
  125. LDA STABYH,Y
  126. STA CYSPEED,X
  127. LDA CDIR,X
  128. STA OLDDIR,X
  129. CHMOVE01 JSR MOVE ; DO THE ACTUAL MOVEMENT
  130. ; AT THIS POINT, CFRAME,X+1 IS THE ANIMATE COUNTER. IF ZERO, DO THE
  131. ; ANIMATION; ELSE, JUST SKIP EVERYTHING.
  132. LDA CFRAME+1,X ; ANIMATE COUNT IS X+1
  133. BNE ZCHEFA00
  134. CHEFANIM
  135. LDA CDIR,X ; GET DIRECTION
  136. CMP #4 ; 0-3 GET RIGHT ANIMATION
  137. BPL CHFLANIM
  138. CHFRANIM LDY CACOUNT,X
  139. LDA CSTATE,X
  140. CMP #CARRYING ; IF CARRYING, USE ARM
  141. BEQ ZCHC00
  142. LDA CHRUNR,Y ; ELSE, DON'T
  143. JMP ZCHC01
  144. ZCHC00 LDA CHRUNRC,Y
  145. ZCHC01
  146. STA CSTAMP+2,X ; FEET STAMP
  147. JMP ZCHEFA01
  148. CHFLANIM LDA CACOUNT,X
  149. TAY
  150. LDA CSTATE,X
  151. CMP #CARRYING
  152. BEQ ZCHC02
  153. LDA CHRUNL,Y
  154. JMP ZCHC03
  155. ZCHC02 LDA CHRUNLC,Y
  156. ZCHC03
  157. STA CSTAMP+2,X ; STORE TO FEET STAMP (3RD STAMP)
  158. ZCHEFA01 DEC CACOUNT,X
  159. LDA CACOUNT,X
  160. BPL ZCHEFA00
  161. ZCHF001 LDA #3 ; NUMBER OF CHEF ANIMATIONS (4 FRAMES)
  162. STA CACOUNT,X
  163. ; CONTINUE PROCESSING AFTER MOVEMENT AND ANIMATION:
  164. ZCHEFA00
  165. LDA CSTATE,X
  166. CMP #CARRYING
  167. BEQ CHCONT31
  168. JMP CHCONT3 ; IF NOT CARRYING, DON'T ADJUST
  169. ; AND DON'T DEC THRWTIME
  170. ; IF WE GET HERE, THEN CHECK FOR THROWING AND/OR ADJUSTING FOOD:
  171. CHCONT31 JSR FOODADJ ; WE KNOW TO ADJUST IF HE'S CARRYING
  172. LDA THRWTIME,X
  173. BEQ CHTHROW
  174. DEC THRWTIME,X ; IN ANY CASE, IF TIMER IS NOT
  175. ; 0, THEN DECREMENT AND LEAVE
  176. JMP CHCONT3
  177. CHTHROW
  178. LDA THRWTUFF
  179. STA THRWTIME,X
  180. LDY HELDFOOD,X
  181. LDA CDIR,X
  182. STA CDIR,Y
  183. ; LDA CXSPEED,X ; SET FOOD DELTAS
  184. ; STA CXSPEED,Y
  185. ; LDA CXSPEEDL,X
  186. ; STA CXSPEEDL,Y
  187. ; LDA CYSPEED,X
  188. ; STA CYSPEED,Y
  189. ; LDA CYSPEEDL,X
  190. ; STA CYSPEEDL,Y
  191. LDA #FLYING ; FOR FOODMOVE
  192. STA CSTATE,Y
  193. LDA CTYPE,Y
  194. CMP #2 ; IF IT'S A PIE
  195. BEQ CHTH004
  196. CMP #1 ; PEAS
  197. BEQ CHTH0041
  198. CHTH0042 LDA #0 ; ANYTHING NOT PEAS (BANANAS)
  199. STA CACOUNT,Y
  200. LDA #1
  201. STA CINFO,Y
  202. JMP CHTH005
  203. CHTH004 LDA CDIR,X ; USE DIRECTION AS INDEX
  204. TAX
  205. LDA PIEFLY,X
  206. STA CSTAMP,Y ; STORE STAMP
  207. LDA PIEFLYPW,X
  208. STA CPALW,Y ; GET PROPER WIDTH OF STAMP
  209. JMP CHTH005 a jump
  210. CHTH0041 LDA #1 ; PEAS
  211. STA CACOUNT,Y
  212. LDA #16
  213. STA CINFO,Y
  214. CHTH005 LDA CTYPE,Y ; MODIFY FLYING SPEED BASED ON
  215. CMP #4
  216. BNE CHTH0051
  217. JSR RANDOM ; WATERMELON CHOOSES RANDOM BEHAVIOR
  218. AND #$3
  219. CHTH0051 TAX
  220. LDA FLYDIST,X ; MODIFY DISTANCE BASED ON TYPE OF
  221. STA CFLYTIME,Y ; FOOD AND NUMBER OF CYCLES PER FRAME
  222. ; GET THE "CSINDEX" AND SET "CSPEED" AND THE DELTAS ACCORDINGLY.
  223. LDA CHFLYSPD,X ; BASED ON FOOD TYPE
  224. SEC
  225. SBC HOWHARD faster based on difficulty level
  226. JSR SETFSPD sets all the food speed stuff
  227. LDX TEMPX
  228. LDA #RUNNING ; FREE HIM TO PICK UP MORE FOOD
  229. STA CSTATE,X
  230. CHCONT3 LDA CXPOS,X ; SET BOTTOM THIRD COORDS.
  231. STA CXPOS+2,X ; FEET
  232. STA CXPOS+1,X ; HEAD
  233. INC CXPOS+1,X
  234. LDA CYPOS,X
  235. SEC
  236. SBC #HEADTOP ; TOP OF THE HEAD
  237. STA CYPOS+1,X
  238. SEC
  239. SBC #FEETTOP ; TOP OF THE FEET (3RD) STAMP
  240. STA CYPOS+2,X
  241. JMP NXTCHEF
  242. ; JUMP HERE IF THE CHEF'S Y COORDINATE IS ZERO (DEAD CHEF).
  243. ; IF THE COUNTER HAS REACHED ZERO, THEN MAKE HIM APPEAR.
  244. ; THE COUNTER TAKES UP TWO BYTES-- LOW BYTE AT CACOUNT,X
  245. ; HIGH BYTE AT CACOUNT,X+1
  246. CHEFWAIT LDA CACOUNT,X
  247. BEQ CH301
  248. DEC CACOUNT,X ; LOW BYTE
  249. JMP NXTCHEF
  250. CH301
  251. LDA CACOUNT+1,X ; HIGH BYTE
  252. BEQ CH3032
  253. DEC CACOUNT+1,X
  254. LDA #$7F
  255. STA CACOUNT,X ; LOW BYTE
  256. JMP NXTCHEF
  257. ; THE CHEF CAN RISE OUT OF ANY HOLE, OPEN OR SHUT. "CHEFDRAW" WILL OPEN
  258. ; THE HOLE IF IT'S SHUT--
  259. CH3032 JSR RANDOM ; PICK A RANDOM OPEN HOLE
  260. AND #$0F ; TO GET 0-F
  261. CMP HOLENUM
  262. BMI CH303 ; NUMBER IS OK
  263. CH3031 SEC ; KEEP SUBTRACTING UNTIL IT'S OK
  264. SBC #3
  265. CMP HOLENUM
  266. BPL CH3031
  267. CH303 CLC
  268. ADC #HOLESTRT
  269. TAY
  270. LDA FINFO,Y ; IF "TRUE", SOMEONE'S RISING FROM IT
  271. BMI CH3032 ; ALREADY
  272. STY TEMPY ; PLACE IN Y FOR "CHEFDRAW"
  273. LDA FDLPOS,Y
  274. AND #$0F ; DISPLAY LIST
  275. TAX
  276. LDA LISTTABL,X
  277. STA LISTPTRA
  278. LDA LISTTABH,X
  279. STA LISTPTRA+1
  280. LDA FDLPOS,Y
  281. AND #$F0 ; GET POSITION IN DLIST
  282. LSR A ; POSITION TIMES 4
  283. LSR A
  284. TAY
  285. LDA #OPENCHAR ; DISPLAY THE OPEN HOLE CHARACTER
  286. STA (LISTPTRA),Y ; LOW BYTE OF HEADER
  287. LDX TEMPX
  288. LDY TEMPY
  289. JSR CHEFDRAW
  290. NXTCHEF DEX
  291. DEX
  292. DEX ; SUBTRACT THREE ! EACH CHEF IS
  293. ; THREE CHARACTERS
  294. CPX #CHEFSTRT ; COMPARE X WITH #CHEFSTRT
  295. BMI CHEFBYE
  296. JMP DOCHEF
  297. CHEFBYE
  298. RTS
  299. ; THE ROUTINES TO DETERMINE "GOALX, GOALY" FOLLOW:
  300. FCHEF LDA CXPOS
  301. STA GOALX
  302. LDA CYPOS ; STORE ABOVE
  303. JMP ZCHASE
  304. ICHEF LDA CXPOS ; GO BETWEEN HERO AND CONE
  305. CLC
  306. ADC FXPOS+CONESTRT ; ADD CONE X
  307. LSR A ; DIVIDE BY 2
  308. STA GOALX
  309. LDA CYPOS
  310. CLC
  311. ADC FYPOS+CONESTRT
  312. ROR A ; DIVIDE BY 2 (BRING IN CARRY BIT
  313. ; SINCE IT CAN BE > 256)
  314. JMP ZCHASE
  315. ACHEF LDX JOYDIR ; USE HERO'S DIR AS INDEX TO GOAL
  316. LDA XCHTAB,X ; COORD. TABLE
  317. CLC
  318. ADC CXPOS ; IN FRONT OF HERO
  319. STA GOALX
  320. LDA YCHTAB,X
  321. CLC
  322. ADC CYPOS ; STORE AFTER RETURN
  323. JMP ZCHASE
  324. BCHEF LDX JOYDIR ; USE SAME TABLE, BUT SUBTRACT
  325. LDA CXPOS
  326. SEC
  327. SBC XCHTAB,X ; GO BEHIND HERO
  328. STA GOALX
  329. LDA CYPOS
  330. SEC
  331. SBC YCHTAB,X ; STORE ABOVE
  332. JMP ZCHASE
  333. ; THESE TABLES TELL HOW FAR IN FRONT OF OR BEHIND THE HERO TO AIM FOR,
  334. ; FOR THE ANTICIPATOR AND BEHINDOR.
  335. ; requires a 00 in the following table:
  336. YCHTAB DB $10,$0D,$00,-$0D,-$10,-$0D,$00,$0D
  337. XCHTAB DB $00,$0D,$10,$0D,$00,-$0D,-$10,-$0D,$00
  338. CHASETAB DB 5,6,7,$FF,4,8,0,$FF,3,2,1 ; $FF REPRESENTS IMPOSSIBLE
  339. ; RESULTS FOR THE FORMULA
  340. ; THE FOLLOWING ROUTINES HANDLE THE THREE FALLING STAGES:
  341. FTFALL DEC CACOUNT,X
  342. BNE NCHFJMP ; BNE NXTCHEF
  343. ZFT001 LDA #FSPEED
  344. STA CACOUNT,X
  345. DEC CYPOS,X ; LOWER HAT
  346. DEC CYPOS+1,X ; LOWER HEAD
  347. DEC CYPOS+2,X ; LOWER FEET
  348. LDA CYPOS+2,X ; FEET Y POSITION
  349. CMP CFRAME,X ; BOTTOM OF ZONE
  350. BMI MKHDFALL ; IF IT'S THERE, GO TO HEAD FALL
  351. NCHFJMP JMP NXTCHEF
  352. MKHDFALL LDA #HEADFALL
  353. STA CSTATE,X
  354. LDA #$FF ; LOWER ZONE OF HEAD NOT VISIBLE
  355. STA CSECOND+1,X
  356. LDA #0
  357. STA CYPOS+2,X ; FEET POSITION-- ERASE FROM SCREEN
  358. BEQ NCHFJMP a jump
  359. HDFALL DEC CACOUNT,X
  360. BNE NCHFJMP ; A JUMP TO NXTCHEF
  361. ZHD001 LDA #FSPEED
  362. STA CACOUNT,X
  363. DEC CYPOS,X ; HAT POSITION
  364. DEC CYPOS+1,X ; HEAD POSITION
  365. LDA CYPOS+1,X
  366. CMP CFRAME,X ; BOTTOM OF ZONE
  367. BPL NCHFJMP ; JUMP NXTCHEF
  368. MKHTFALL LDA #HATFALL
  369. STA CSTATE,X
  370. LDA #$FF ; MAKE BOTTOM HALF OF HAT INVISO
  371. STA CSECOND,X
  372. LDA #0
  373. STA CYPOS+1,X ; ERASE HEAD STAMP
  374. JMP NXTCHEF
  375. HTFALL DEC CACOUNT,X
  376. BNE NCHFJMP
  377. ZHT001 LDA #FSPEED
  378. STA CACOUNT,X
  379. DEC CYPOS,X ; HAT POSITION
  380. LDA CYPOS,X
  381. CMP CFRAME,X ; BOTTOM OF ZONE
  382. BPL NCHFJMP ; JMP NXTCHEF
  383. FLEND LDA #0
  384. STA CYPOS,X ; ERASE HAT
  385. LDA #DEAD
  386. STA CSTATE,X
  387. LDY HOLEUSED,X ; HOLE NO LONGER IN USE
  388. LDA #FALSE
  389. STA FINFO,Y
  390. INC NUMFALL ; IF IT'S 3, ALL CHEFS HAVE FALLEN
  391. LDA NUMFALL
  392. CMP #4
  393. BNE ZFL002
  394. ZFL001 LDX LASTCHEF ; LOAD LAST CHEF TO HAVE FALLEN
  395. LDA #0
  396. STA CACOUNT,X ; SET COUNTER TO 0 SO IT RISES
  397. STA CACOUNT+1,X
  398. LDX TEMPX ; RESTORE CURRENT CHEF INDEX
  399. ZFL002 STX LASTCHEF ; IN CASE ALL HAVE FALLEN AT ONCE
  400. LDA #0 ; DISPLAY AS NORMAL WHEN REAPPEARS
  401. STA CSECOND,X
  402. STA CSECOND+1,X
  403. STA CSECOND+2,X
  404. LDA #$7F
  405. STA CACOUNT,X ; LOW BYTE OF TIMER
  406. LDA #1
  407. STA CACOUNT+1,X ; HIGH BYTE OF TIMER
  408. JMP NXTCHEF ; GO TO NEXT CHARACTER
  409. ; THE FOLLOWING ROUTINES HANDLE THE CHEF RISING FROM A HOLE:
  410. HTRISE DEC CACOUNT,X
  411. BNE NCHFJMP2
  412. ZHTRS01 LDA #RZSPEED
  413. STA CACOUNT,X
  414. INC CYPOS,X ; HAT Y
  415. INC CFRAME,X
  416. LDA CFRAME,X
  417. CMP #HATHITE ; GROW UNTIL ALL IS VISIBLE
  418. BNE NCHFJMP2
  419. MKHDRISE LDA #HEADRISE
  420. STA CSTATE,X
  421. LDA #0
  422. STA CSECOND,X ; MAKE HAT ALL VISIBLE
  423. LDA CXPOS,X ; HAT X
  424. CLC
  425. ADC #1
  426. STA CXPOS+1,X ; HEAD X
  427. LDA CYPOS,X ; HAT Y
  428. SEC
  429. SBC #HATHITE
  430. STA CYPOS+1,X ; HEAD Y
  431. LDA #$FF
  432. STA CSECOND+1,X ; HEAD-- SECOND HALF INVISO
  433. LDA #0
  434. STA CFRAME,X
  435. NCHFJMP2 JMP NXTCHEF
  436. HDRISE DEC CACOUNT,X
  437. BNE NCHFJMP2
  438. ZHDRS01 LDA #RZSPEED
  439. STA CACOUNT,X
  440. INC CYPOS,X ; HAT Y
  441. INC CYPOS+1,X ; HEAD Y
  442. INC CFRAME,X
  443. LDA CFRAME,X
  444. CMP #HEADHITE
  445. BNE NCHFJMP2 ; IF HEAD IS ALL VISIBLE
  446. MKFTRISE LDA #FEETRISE
  447. STA CSTATE,X
  448. LDA #0
  449. STA CSECOND+1,X ; MAKE HEAD ALL VISIBLE
  450. STA CFRAME,X
  451. LDA #$FF
  452. STA CSECOND+2,X ; MAKE BOTTOM HALF OF FEET INVISO
  453. LDA CXPOS,X ; HAT X
  454. STA CXPOS+2,X ; FEET X
  455. LDA #$38 ; FEET STAMP
  456. STA CSTAMP+2,X
  457. LDA CYPOS+1,X ; HEAD Y
  458. STA CYPOS+2,X ; FEET Y
  459. DEC CYPOS+2,X
  460. NCHFJMP3 JMP NXTCHEF
  461. FTRISE DEC CACOUNT,X
  462. BNE NCHFJMP3
  463. ZFTRS01 LDA #RZSPEED
  464. STA CACOUNT,X
  465. INC CYPOS,X ; HAT Y
  466. INC CYPOS+1,X ; HEAD Y
  467. INC CYPOS+2,X ; FEET Y
  468. INC CFRAME,X
  469. LDA CFRAME,X
  470. CMP #FEETHITE
  471. BNE NCHFJMP3 ; IF FEET ARE ALL VISIBLE
  472. ENDRISE LDA #0
  473. STA CSECOND+2,X ; FEET ALL VISIBLE
  474. LDY HOLEUSED,X ; FREE HOLE FOR RISINGS
  475. LDA #FALSE
  476. STA FINFO,Y
  477. LDA STATUS
  478. CMP #STATWON ; IF HE SHOULD RUN RIGHT AND RETREAT
  479. BEQ ZER000
  480. CMP #STATBON
  481. BEQ ZER000
  482. CMP #STATEND should cover STATENDR also
  483. BPL ZER011 means that chuck is dead
  484. CMP #STATDIEH ; REJOICE IF GREATER THAN THIS STATE
  485. BMI ZER001 ; ELSE, JUST START RUNNING
  486. ; Come here if STATEND or STATENDR. If it is, then chuck could have WON
  487. ; or be DEAD-- depending on this, chef should be LEAVING or
  488. ; REJOICING.
  489. ZER011 LDA CHEFPALW-3,X change him back from yellow
  490. STA CPALW,X
  491. LDA CHEFPALW-2,X
  492. STA CPALW+1,X
  493. LDA CHEFPALW-1,X
  494. STA CPALW+2,X
  495. LDA CSTATE make him LEAVE if CHUCK just won.
  496. CMP #WON
  497. BEQ ZER000
  498. JSR MKREJOY else, make him rejoice-- chuck is dead
  499. JMP NXTCHEF
  500. ZER000 LDA #2 ; MAKE HIM RUN RIGHT
  501. STA CDIR,X
  502. LDA #LEAVING ; SO THAT HE DOESN'T CHANGE DIRECTION
  503. JMP ZER0013
  504. ZER001 LDA #RUNNING
  505. ZER0013 STA CSTATE,X
  506. ZER0012 LDA CSPEED,X
  507. STA CFRAME,X
  508. ASL A
  509. STA CFRAME+1,X
  510. LDA #3
  511. STA CACOUNT,X
  512. LDA #10
  513. STA CINFO,X
  514. LDA STATUS
  515. CMP #STATINIT
  516. BEQ RWTSTRT ; MAKE THEM SIT GREY FOR AWHILE
  517. LDA CHEFPALW-3,X ; ELSE, MAKE THIS ONE CHANGE BACK
  518. STA CPALW,X ; TO REGULAR CHEF PALETTE
  519. LDA CHEFPALW-2,X
  520. STA CPALW+1,X
  521. LDA CHEFPALW-1,X
  522. STA CPALW+2,X
  523. JMP NXTCHEF
  524. RWTSTRT LDA CYCLECNT ; WAIT FOR TWO SECONDS
  525. CLC
  526. ADC #60
  527. STA WAITCNT
  528. LDA #STATWAIT
  529. STA STATUS
  530. CBIJUMP RTS ; JMP CHEFBYE
  531. RISELOOP LDA CYCLECNT
  532. CMP WAITCNT
  533. BNE CBIJUMP a jump
  534. RISEOVER LDA #STATPLAY ; MAKE THE GAME START
  535. STA STATUS
  536. ; SETUP THE OVERALL SPEED SCALING:
  537. JSR MAXSET
  538. LDA #$0F ; THE COLOR WHITE
  539. STA COLORS+6 ; MAKES THE CHEFS CHANGE
  540. RTS ; JMP CHEFBYE
  541. ; This routine is also called from INIT.S & CHUCK.S
  542. MAXSET LDX #1
  543. LDA PLRACK
  544. CMP #$10
  545. BMI MAXCSET if 1-16, set to 1
  546. INX else set to 2
  547. MAXCSET STX MAXCYCLE
  548. RTS
  549. ; THIS ROUTINE IS USED BY CHEFS MOSTLY, BUT ALSO BY THE FOOD WHEN
  550. ; IT MUST FLY AT THE HERO AT THE END OF A RACK.
  551. CHASE LDA CYPOS,X
  552. LDY #0 for later
  553. SEC
  554. SBC GOALY
  555. BPL ZCHEF011
  556. EOR #$FF
  557. CLC
  558. ADC #1
  559. ZCHEF011
  560. CMP #4 compares accumulator
  561. BCC YEND ; CHASE CHUCK ON THE HORIZONTAL
  562. LDA CYPOS,X ; ELSE, SEE IF HE'S ABOVE OR BELOW
  563. CMP GOALY ; DESTINATION Y COORD
  564. BCC ZCHEF01 ; GOAL IS ABOVE
  565. DEY
  566. BNE YEND a jump
  567. ZCHEF01 INY
  568. YEND STY TEMP0 ; Y VALUE
  569. LDY #0
  570. LDA CXPOS,X ; NOW DO THE X TEST
  571. SEC
  572. SBC GOALX
  573. BPL ZCHEF031
  574. EOR #$FF
  575. CLC
  576. ADC #1
  577. ZCHEF031
  578. CMP #4
  579. BCC XEND ; CHASE ALONG THE VERTICAL
  580. LDA CXPOS,X ; ELSE, HE'S RIGHT OR LEFT
  581. CMP GOALX ; DESTINATION X COORDINATE
  582. BCC ZCHEF04 ; HERO TO THE RIGHT
  583. DEY
  584. BNE XEND a jump
  585. ZCHEF04 INY
  586. XEND
  587. TYA
  588. ; NOW REGISTER A CONTAINS THE X AXIS INFO, AND "TEMP0" CONTAINS THE Y.
  589. ; CALCULATE THE "CHASETAB" INDEX USING THE FORMULA ABOVE:
  590. CLC
  591. ADC #2 ; X = 1,2,3
  592. ASL A
  593. ASL A ; X = 4,8,12
  594. CLC
  595. ADC TEMP0 ; ADD Y = -1,0,1
  596. SEC
  597. SBC #3 ; Y - 3 = -4,-3,-2
  598. TAY
  599. LDA CHASETAB,Y ; GET DIRECTION
  600. CMP #8
  601. BEQ CHASEBYE
  602. STA CDIR,X
  603. CHASEBYE RTS
  604. ; ALMOST THE SAME AS NORMAL ANIMATION, EXCEPT THERE'S NO VARIATION
  605. ; FOR DIRECTION
  606. REJOICE
  607. DEC CFRAME+1,X
  608. LDA CFRAME+1,X ; ANIMATE COUNT IS X+1
  609. BEQ REJANIM ; IF ZERO, ANIMATE
  610. JMP NXTCHEF ; ELSE, LEAVE THE ROUTINE
  611. REJANIM
  612. LDA CSPEED,X ; ANIMATE COUNT IS SPEED TIMES 2
  613. ASL A
  614. STA CFRAME+1,X
  615. LDA CACOUNT,X
  616. CMP #1 ; LAST TWO FRAMES ARE HIGHER
  617. BNE REJ001
  618. INC CYPOS+2,X
  619. LDA CACOUNT,X
  620. JMP REJ003
  621. REJ001 CMP #3 ; FIRST TWO FRAMES MUST BE LOWER
  622. BNE REJ003 a jump
  623. REJ002
  624. DEC CYPOS+2,X
  625. REJ003 LDY CACOUNT,X
  626. LDA REJOYCH,Y
  627. STA CSTAMP+2,X ; FEET STAMP
  628. DEC CACOUNT,X
  629. LDA CACOUNT,X
  630. BPL NCJUMP will be a jump
  631. ZREJ001 LDA #3 ; NUMBER OF CHEF ANIMATIONS (4 FRAMES)
  632. STA CACOUNT,X
  633. NCJUMP JMP NXTCHEF
  634. ; Used from both chuck and chefmove-- placing it here cuts the number of
  635. ; bytes needed in half !
  636. SETFSPD STA CSINDEX,Y
  637. TAX
  638. LDA MTABSPD,X
  639. STA CSPEED,Y
  640. STA CFRAME,Y
  641. LDA MTABINC,X ; TELLS WHICH INCREMENT TABLE TO USE
  642. ASL A ; MULTIPLY BY 8 FOR TABLE BASE
  643. ASL A
  644. ASL A
  645. ADC CDIR,Y ; GET INCREMENT FOR THIS DIRECTION
  646. TAX
  647. LDA STABXL,X ; SET FOOD DELTAS
  648. STA CXSPEEDL,Y
  649. LDA STABXH,X
  650. STA CXSPEED,Y
  651. LDA STABYL,X
  652. STA CYSPEEDL,Y
  653. LDA STABYH,X
  654. STA CYSPEED,Y
  655. RTS