NEWCMOVE.S 27 KB

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