INIT2.S 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. ; INIT2.S
  2. ; THIS ROUTINE HAS TO PICK BOTH RANDOM X AND RANDOM Y (DLIST). IT WILL
  3. ; ONLY ALLOW TWO PILES PER DLIST, AND USES "CINFO" AS A COUNTER ARRAY.
  4. ; THIS ROUTINE STARTS INSERTING PILES AT "PILESTRT", AND CONTINUES
  5. ; UNTIL "NUMHOLES" (WHICH HAS BEEN SET TO "PILESTRT+NUMHOLES").
  6. ; IF A BANANA OR TOMATO PILE GREATER THAN 4 IS DISPLAYED,
  7. ; "NUMHOLES" WILL BE INCREMENTED.
  8. PILEDRAW
  9. MOVE #PILESTRT,NEXTPILE ; FOR USE AT END OF RACK
  10. LDX PLRACK
  11. CPX #5 ; RACKS ABOVE 5 HAVE 8 PILES
  12. BPL ZPP00 ; IF RACK IS HIGHER, USE MAX. NUMBER
  13. MOVE #4,TEMP3 else 4 piles per zone (RACKS 0-4)
  14. LDA NUMPTAB,X
  15. CLC
  16. ADC #PILESTRT ; INDEX FROM BEGINNING OF PILES
  17. STA INDEX ; ACTUAL NUMBER + #PILESTRT
  18. LDX #PILESTRT ; INDEX TO START WITH
  19. BPL ZPP01
  20. ZPP00 LDA #PILESTRT+NUMPILES
  21. STA INDEX
  22. MOVE #8,TEMP3 8 piles per zone
  23. LDX #PILESTRT ; INDEX TO START WITH
  24. ZPP01 JSR RANDOMX ; RESULT IN A
  25. STA FXPOS,X
  26. ; DON'T LET A GIVEN ZONE CONTAIN MORE PILE ENTRIES THAN 2. THE INFORMATION
  27. ; FOR THE NUMBER OF PILES SO FAR IS CONTAINED IN THE ARRAY "CINFO".
  28. ; UPDATE: HIGHER RACKS HAVE SO MANY PILES THAT EACH ZONE MUST BE
  29. ; ALLOWED TO CONTAIN MORE THAN 2 ENTRIES. MAKE IT 3 IF
  30. ; "NUMPILES" IS >= 9.
  31. ZPP02 JSR RANDOMY ; REGISTER A CONTAINS A ZONE NUMBER
  32. STA TEMP4 ; CONTAINS THE HALF-ZONE
  33. LSR A ; NOW A CONTAINS THE ACTUAL ZONE
  34. TAY ; INDEX INTO DLIST COUNTER (CINFO)
  35. LDA CINFO,Y
  36. CMP TEMP3 ; THE NUMBER OF PILES PER ZONE IS
  37. BPL ZPP02 ; DETERMINED FROM "NUMPTAB"
  38. ; NOW SET THE ACTUAL COORDINATE BY MULTIPLYING THE ZONE HALF BY 8 AND ADDING
  39. ; 7 TO GET THE TOP OF THE ZONE HALF.
  40. LDA TEMP4 ; ZONE HALF
  41. ASL A ; TIMES 8
  42. ASL A
  43. ASL A
  44. ORA #$07
  45. STA FYPOS,X
  46. ; NOW PICK A FOOD TYPE AND A NUMBER OF FOODS FOR THE PILE.
  47. ; move this here so that SPACEm can be called twice if necessary.
  48. LDA PLBCD if one of the top two digits is set,
  49. BNE NOTRAND then it's not the first 4 racks
  50. LDA PLBCD+1
  51. CMP #4
  52. BCC ZPPRAND ; IF THE FIRST 4 RACKS
  53. NOTRAND
  54. LDA PLBCD+1 we don't want PLBCD !
  55. AND #$F
  56. STX TEMP1 ; SAVE X FOR THIS TRICK
  57. TAX
  58. LDA RACKTYPE,X
  59. LDX TEMP1
  60. CMP #$80
  61. BEQ ZPPRAND ; TYPE $80 = RANDOM
  62. CMP #$FF
  63. BNE ZPP041 ; TYPE $FF = SOME WATERMELONS
  64. ; BEQ ZPPSOME
  65. ZPPSOME CPX #PILESTRT+2 ; FIRST TWO ARE WATERMELON
  66. BPL ZPPRAND
  67. LDA #WATTYPE
  68. BPL ZPP041 a jump
  69. ZPPRAND JSR RANDOM ; "RANDOMLC" DOESN'T WORK WELL HERE
  70. AND #03 ; MASK TO 0-3
  71. ZPP041 ORA FINFO,X ; IN CASE BIT 7 WAS SET LAST TIME
  72. STA FINFO,X ; CONTAINS TYPE OF FOOD
  73. ASL A
  74. ASL A
  75. ASL A ; MULTIPLY BY 8 FOR FOOD TABLE BASE
  76. STA TEMP1
  77. JSR RANDOMLC ; NOW GET A RANDOM NUMBER FOR THE PILE
  78. AND #07 ; MASK TO 0-7
  79. CMP #4 ; IF LESS THAN FOUR, ADD 4
  80. BCS ZPMAKE2 ; >=
  81. ZPADD4
  82. ADC #4
  83. ZPMAKE2 STA TEMP2 ; TOTAL NUMBER OF FOODS IN PILE
  84. ; Find out if this pile will be two piles. If so, call spacem for the top
  85. ; half first; if not, skip around the test for the top half.
  86. LDA FINFO,X
  87. AND #$F
  88. CMP #WATTYPE
  89. BEQ ONESTAMP
  90. CMP #PEATYPE
  91. BEQ ONESTAMP
  92. ; Reaching here means there are two stamps (pies, tomatoes, or bananas)
  93. LDA FYPOS,X
  94. CLC
  95. ADC #8
  96. STA FYPOS,X
  97. JSR SPACEM the top half test
  98. BNE PPSKIP
  99. PP01JMP JMP ZPP01 didn't pass: find a new location
  100. PPSKIP LDY TEMPY contains the zone index-- must be
  101. LDA FYPOS,X restored before next SPACEM call
  102. SEC
  103. SBC #8
  104. STA FYPOS,X
  105. ; NOW MAKE SURE THAT THIS PILE ISN'T TOO CLOSE TO ANY OTHER ALREADY
  106. ; INITIALIZED PILES, BY CALLING THE ROUTINE "SPACEM".
  107. ONESTAMP JSR SPACEM
  108. BEQ PP01JMP ; IF A==0, HE'S TOO CLOSE
  109. LDY TEMPY ; ELSE, HE'S OKAY-- CONTINUE
  110. ; WE NOW KNOW THAT IT'S OKAY TO PUT THIS PILE HERE.
  111. ; SET UP FDLPOS--
  112. JSR ZFDLPOS
  113. ; INCREMENT "CINFO" FOR THE NEXT PILE TO TRY THIS ZONE:
  114. JSR INCCINFO
  115. ; NOW CHECK TO SEE IF THIS PILE ENTRY IS IN TWO DLISTS. IF SO, CINFO
  116. ; MUST BE INCREMENTED FOR THE FOLLOWING ZONE ALSO. THIS WILL BE
  117. ; THE CASE IF THE ZONE HALF (IN TEMP1) IS EVEN.
  118. LDA TEMP4
  119. LSR A ; GET ODDNESS BIT INTO CARRY
  120. BCS ZPP04 ; AN ODD ZONE HALF-- FITS INTO ONE ZN.
  121. ZPP03 DEY ; INDEX FOR NEXT LOWER ZONE
  122. JSR INCCINFO
  123. INY ; BACK UP TO THE SAME ZONE
  124. ZPP04 LDA FINFO,X ; TYPE OF FOOD
  125. AND #$3F ; IGNORE TOP TWO BITS
  126. CMP #1 ; 1 MEANS PEAS-- ONLY ONE ZONE HIGH
  127. BEQ ZPSKIP00
  128. CMP #4 ; WATERMELON-- ONE STAMP
  129. BNE ZPMAKE3
  130. ; IF NOT PEAS OR WATERMELON, MAKE
  131. ; 2 STAMPS HIGH
  132. ZPSKIP00 LDA TEMP2 ; ELSE, RESTORE A WITH NUMBER OF FOODS
  133. JMP ZP000 ; AND SKIP THE "BOTTOM HALF" STUFF
  134. ; IF WE GET HERE, WE KNOW THAT IT'S A BANANA OR TOMATO OR PIE PILE BIGGER
  135. ; THAN 4 HIGH. CREATE THE BOTTOM STAMP OF 4, AND SETUP
  136. ; THE ARRAYS FOR THE UPPER STAMP, INCREMENT X, AND CONTINUE
  137. ; AS BEFORE.
  138. ; SET "FINFO" HIGH BITS AS WELL.
  139. ZPMAKE3 INC INDEX ; END TEST IS ONE GREATER NOW
  140. LDA FINFO,X ; FIRST, COPY FOOD TYPE INTO TOP
  141. INX ; HALF OF PILE
  142. STA FINFO,X
  143. DEX
  144. LDA #$40 ; BOTTOM HALF
  145. ORA FINFO,X
  146. STA FINFO,X
  147. INX ; NEXT ONE IS TOP HALF
  148. LDA #$80 ; TOP HALF FLAG
  149. ORA FINFO,X
  150. STA FINFO,X ; PUT IT THERE FOR NEXT LOOP
  151. DEX
  152. MOVE #3,FSTATE,X ; THIS PILE IS 4 HIGH
  153. INC FSTATE,X ; STATE CONTAINS PILE NUMBER
  154. CLC
  155. ADC TEMP1 ; BASE INDEX INTO TABLE
  156. TAY ; TABLE INDEX IS 4+ TEMP1
  157. MOVE PILECHAR,Y,FSTAMP,X
  158. MOVE PILEPALW,Y,FPALW,X
  159. JSR SETCTR
  160. LDA FXPOS,X
  161. INX
  162. STA FXPOS,X
  163. DEX
  164. LDA FYPOS,X ; ADD 8 FOR YPOS OF TOP HALF
  165. INX
  166. CLC
  167. ADC #8
  168. STA FYPOS,X ; THIS IS THE TOP HALF !
  169. ; SET UP "FLDPOS" FOR THIS TOP HALF. IT MUST BE DONE HERE RATHER THAN
  170. ; BELOW, BECAUSE THE BELOW CODE GETS EXECUTED FOR ONE- AND TWO-
  171. ; ENTRY PILES; AND FDLPOS FOR ONE-ENTRY PILES HAS ALREADY BEEN DONE
  172. ; ABOVE.
  173. INC TEMP4 ; TOP HALF IS NEXT ZONE HALF UP
  174. LDA TEMP4 ; GET IT INTO A SO I CAN SHIFT IT
  175. LSR A ; ACTUAL ZONE INDEX
  176. TAY
  177. JSR ZFDLPOS ; SET UP FDLPOS
  178. JSR INCCINFO ; INC FOR NEXT TIME
  179. ; NOW, AS WITH THE FIRST HALF, CHECK TO SEE IF THIS HALF HANGS OVER
  180. ; INTO THE NEXT LOWER ZONE. THIS WILL BE TRUE IF THE "HALF-ZONE"
  181. ; IS EVEN.
  182. LDA TEMP4 ; HALF ZONE
  183. LSR A ; GET "ODDNESS" BIT IN CARRY
  184. BCS ZPP06 ; CARRY CLEAR IF EVEN
  185. ZPP05
  186. DEY ; INDEX TO NEXT LOWER ZONE
  187. JSR INCCINFO
  188. INY ; RESET INDEX TO CURRENT ZONE
  189. ZPP06 ; COME HERE IF THERE'S NO OVERHANG
  190. LDA TEMP2 ; THE NUMBER IN THE WHOLE PILE
  191. SEC
  192. SBC #4 ; TAKE OFF FOUR
  193. ZP000
  194. STA FSTATE,X ; THE STATE IS THE NUMBER OF FOODS
  195. INC FSTATE,X ; SHOULD BE 1-8, NOT 0-7
  196. CLC
  197. ADC TEMP1 ; ADD TO FOOD TABLE BASE INDEX
  198. TAY
  199. MOVE PILECHAR,Y,FSTAMP,X ; INDEX INTO PILECHAR TABLE
  200. MOVE PILEPALW,Y,FPALW,X
  201. LDA FINFO,X if this is the top of a two-entry
  202. BPL DOCTR pile, the delta is the maximum
  203. TYA if bit7 is set, it's a top
  204. AND #$FC
  205. CLC
  206. ADC #3 3 + 8N, N=0,1,2,3
  207. TAY
  208. DOCTR JSR SETCTR
  209. INX ; GO TO NEXT FREE STRUCTURE
  210. TXA
  211. CMP INDEX
  212. BPL PILEDBYE ; IF EQUAL OR GREATER, WE'RE FINISHED
  213. JMP ZPP01
  214. PILEDBYE
  215. RTS
  216. RACKTYPE DB $FF,TOMTYPE,$80,PIETYPE,$80
  217. DB WATTYPE,BANTYPE,$80,PEATYPE,$80
  218. ; Used to set the table values of the new pile. Called twice here
  219. ; and also called from PILEHIT
  220. AASETCTR
  221. SETCTR
  222. LDA FINFO,X
  223. BPL THEBOT
  224. TYA if the top of a pile, add 4 to the
  225. CLC index
  226. ADC #4
  227. TAY
  228. THEBOT LDA PILECTRY,Y do the Y first, in case index needs
  229. CLC to be changed for the X
  230. ADC FYPOS,X
  231. STA FYCENTER,X
  232. LDA PILEDY,Y
  233. STA FDY,X
  234. LDA FINFO,X whats this ? if it's the top of a
  235. BPL NOCHANGE pile, get rid of top bit, take
  236. TYA the index mod 8, and add 3 to get
  237. AND #$FC the index for a pile of size 4
  238. CLC
  239. ADC #3
  240. TAY
  241. NOCHANGE LDA PILECTR,Y
  242. CLC
  243. ADC FXPOS,X
  244. STA FCENTER,X
  245. LDA PILEDX,Y
  246. STA FDX,X
  247. RTS
  248. INCCINFO LDA CINFO,Y
  249. CLC
  250. ADC #$01
  251. STA CINFO,Y
  252. RTS
  253. ZFDLPOS LDA #2 ; 2 WALL ENTRIES
  254. CLC
  255. ADC CINFO,Y ; NUMBER OF PILES + 2
  256. ASL A
  257. ASL A
  258. ASL A
  259. ASL A ; SHIFT LEFT 4 TIMES (UPPER FIELD)
  260. STA TEMP0 ; UPPER FIELD (TOP FOUR BITS)
  261. TYA ; ACTUAL ZONE NUMBER IS IN Y
  262. ORA TEMP0 ; MASK IN THE UPPER FIELD (3 BITS)
  263. STA FDLPOS,X
  264. RTS
  265. ; "HOLEDRAW" IS ISOMORPHIC TO "PILEDRAW". ALL HOLES START OUT CLOSED;
  266. ; "CHEFINIT" WILL CHANGE SOME HOLES TO OPEN.
  267. HOLEDRAW
  268. LDA TEMP3 each zone has 3 more spaces for
  269. CLC holes
  270. ADC #3
  271. STA TEMP3
  272. LDA PLRACK
  273. CMP #8 ; RACKS ABOVE 7 HAVE 10 HOLES
  274. BPL ZHH00
  275. TAX
  276. LDA NUMHTAB,X ; NUMBER OF HOLES FOR RACK
  277. JMP ZHH01
  278. ZHH00 LDA #NUMHOLES ; MAXIMUM NUMBER OF HOLES
  279. ZHH01 STA HOLENUM ; USED IN "CHEFMOVE" WHEN RISING
  280. CLC
  281. ADC #HOLESTRT
  282. STA INDEX ; USED FOR END OF ROUTINE TEST
  283. LDX #HOLESTRT ; START WITH FIRST PILE
  284. ZNEWHOLE JSR RANDOMX ; RESULT IN A
  285. CMP #120 ; DON'T LET HOLE GET TOO CLOSE TO HERO
  286. BCS ZHSUB40
  287. JMP ZHSUB00
  288. ZHSUB40 SEC
  289. SBC #40 ; SUBTRACT 40 FROM X COORDINATE
  290. ZHSUB00 STA FXPOS,X
  291. ZHH02 JSR RANDOMY ; RANDOM DLIST
  292. LSR A ; GET ACTUAL ZONE
  293. TAY ; INTO INDEX REGISTER Y
  294. LDA CINFO,Y ; CHECK COUNTER (FROM "PILEDRAW")
  295. CMP TEMP3 ; VARIES DEPENDING ON TOTAL PILES
  296. BPL ZHH02 ; IF TWO THINGS ARE THERE, TRY ANOTHER
  297. TYA ; BRING DLIST NUMBER BACK INTO A
  298. ASL A ; MULTIPLY BY 16 TO GET THE COORD.
  299. ASL A
  300. ASL A
  301. ASL A
  302. CLC
  303. ADC #15 ; ADJUST AT THE TOP OF THE DLIST
  304. STA FYPOS,X
  305. ; NOW MAKE SURE HE'S NOT TOO CLOSE TO ANY OTHER PILE OR HOLE.
  306. JSR SPACEM
  307. BEQ ZNEWHOLE ; IF A==0, HE'S TOO CLOSE
  308. ; IF WE GET HERE, THIS LOCATION IS OK-- SET "FDLPOS" AND INCREMENT "CINFO"
  309. LDY TEMPY ; SAVED IN "SPACEM"
  310. JSR ZFDLPOS
  311. ; INCREMENT "CINFO"
  312. JSR INCCINFO
  313. MOVE #SHUTCHAR,FSTAMP,X ; ALL SHUT FOR NOW
  314. MOVE #HOLEPALW,FPALW,X
  315. MOVE #CLOSED,FSTATE,X ; HOLE STATE
  316. INX
  317. CPX INDEX ; LAST CHEF TO BE INITIALIZED
  318. BMI ZNEWHOLE
  319. ; CLEAR OUT "CINFO" SO THAT IT'S ZEROED WHEN RACK STARTS
  320. LDX #TOTALCH-1
  321. LDA #0
  322. ZHH03 STA CINFO,X
  323. DEX
  324. BPL ZHH03
  325. RTS
  326. ; "CHEFINIT"
  327. ; THIS ROUTINE WILL CAUSE THE CHEFS TO RISE FROM MANHOLES AND APPEAR
  328. ; ON THE PLAYFIELD. FOR NOW, IT JUST POPS THEM UP RIGHT ON TOP
  329. ; OF THE HOLE.
  330. CHEFINIT
  331. LDX HOWHARD
  332. LDA PLRACK
  333. CMP ZRACK,X
  334. BPL ZEROTHRW zero throw time
  335. MOVE LOWTIME,X,TEMP0 otherwise, read throw time from table
  336. MOVE HITIME,X,TEMP1
  337. LDY PLRACK
  338. LDA (TEMP0),Y
  339. JMP SETTHTF
  340. ZEROTHRW LDA #10
  341. SETTHTF STA THRWTUFF
  342. LDA PLRACK
  343. CMP #23
  344. BPL MAXTUFF
  345. LSR A
  346. TAX
  347. LDA MTUFFTAB,X ; DIRECTION CHANGE TIMER
  348. JMP SETTUFF
  349. MAXTUFF LDA #3
  350. SETTUFF STA MOODTUFF
  351. TUFFOVER LDY #HOLESTRT ; MANHOLE INDEX
  352. MOVE #$1F,COLORS+6 ; CHANGE THE WHITE TO YELLOW
  353. MOVE #0,NUMCHHIT ; NO CHEFS HIT YET
  354. LDA PLRACK
  355. BEQ CHEF02 ; FIRST RACK HAS 2 CHEFS
  356. CMP #1
  357. BEQ CHEF03 ; SECOND HAS THREE
  358. LDA #3 ; ALL FOUR CHEFS
  359. BNE ZCHINIT0 ; A JUMP
  360. CHEF02 MOVE #NOTYET,CSTATE+9
  361. STA CSTATE+12
  362. LDA #1 ; 2 CHEFS
  363. BNE ZCHINIT0 ; A JUMP
  364. CHEF03 MOVE #NOTYET,CSTATE+12 ; LAST CHEF ISN'T PROCESSED
  365. LDA #2 ; 3 CHEFS
  366. ZCHINIT0 STA INDEX ; TELLS HOW MANY CHEFS THIS LEVEL
  367. ; UP TILL NOW, I'VE BEEN SETTING PARAMETERS WHICH APPLY TO ALL THE CHEFS.
  368. ; THE FOLLOWING LOOP SETS PARAMETERS FOR EACH INDIVIDUAL CHEF
  369. LDX #CHEFSTRT ; INITIALIZE FOR THE FOLLOWING LOOP
  370. ZCHINIT1 JSR CHEFDRAW ; INITIALIZE THE RISING SEQUENCE
  371. ; SET UP CHARACTER INFO:
  372. ; TEMPORARY-- REMOVE FOR FINAL VERSION ?
  373. MOVE #$10,CINFO,X
  374. MOVE CHEFPALW-3,X,CPALW,X
  375. MOVE CHEFCHAR-3,X,CSTAMP,X
  376. MOVE CHEFPALW-2,X,CPALW+1,X
  377. MOVE CHEFCHAR-2,X,CSTAMP+1,X
  378. MOVE CHEFPALW-1,X,CPALW+2,X
  379. MOVE CHEFCHAR-1,X,CSTAMP+2,X
  380. INX ; GO TO NEXT CHEF
  381. INX
  382. INX
  383. INY ; POINT TO NEXT HOLE
  384. DEC INDEX
  385. BPL ZCHINIT1 ; CONTINUE FOR THIS MANY CHEFS
  386. ; WHEN ALL CHEFS HAVE STARTED RISING, SET THE NUMBER OF "FALLEN" CHEFS
  387. ; TO ENSURE THAT THERE'S ALWAYS AT LEAST ONE ON THE SCREEN
  388. LDA PLRACK
  389. BEQ CHEF012
  390. CMP #1
  391. BEQ CHEF013
  392. LDA #0
  393. JMP CHINBYE
  394. CHEF012 LDA #2 ; PRETEND THAT TWO HAVE FALLEN
  395. JMP CHINBYE
  396. CHEF013 LDA #1 ; PRETEND; SO THAT AT LEAST ONE CHEF
  397. CHINBYE STA NUMFALL ; WILL STILL BE ON SCREEN
  398. RTS
  399. ; THIS ROUTINE DRAWS A SINGLE CHEF. IT IS ALSO CALLED FROM "CHEFMOVE"
  400. ; WHEN A DEAD CHEF SHOULD RE-GROW FROM A HOLE.
  401. CHEFDRAW LDA STATUS
  402. CMP #STATWON
  403. BNE CDRW00
  404. RTS ; JMP CDRWBYE
  405. ; DON'T LET THEM RISE IF RACK IS OVER
  406. CDRW00 LDA RISESND-3,X
  407. JSR TUNIN
  408. MOVE THRWTUFF,THRWTIME,X
  409. MOVE #HATRISE,CSTATE,X ; HAT RISES FIRST
  410. MOVE RISEPALW-3,X,CPALW,X
  411. MOVE RISEPALW-2,X,CPALW+1,X
  412. MOVE RISEPALW-1,X,CPALW+2,X
  413. DEC NUMFALL ; ONE LESS CHEF IS DEAD
  414. LDA FYPOS,Y ; HOLE Y
  415. SEC
  416. SBC #14 ; BOTTOM LINE OF ZONE
  417. STA CYPOS,X ; HAT Y
  418. LDA FXPOS,Y ; HOLE X
  419. CLC
  420. ADC #2
  421. STA CXPOS,X ; HAT X
  422. MOVE #0,CFRAME,X ; STOPS WHEN "HATHITE" IS REACHED
  423. MOVE #RZSPEED,CACOUNT,X
  424. MOVE #$FF,CSECOND,X ; BOTTOM HALF INVISO
  425. STY TEMPY
  426. LDA PLRACK
  427. CMP #31
  428. BMI CDRW011 ; USE TABLES
  429. LDY #15 the chspeed tables are 16 long- JMP CDRW012 8 for 1-16, and 8 for 9-32
  430. CDRW011 STX TEMPX
  431. JSR MAXSET use different tables for
  432. DEX each value of MAXSET
  433. TXA
  434. ASL A
  435. ASL A
  436. ASL A
  437. STA TEMP0
  438. LDA PLRACK
  439. AND #$F
  440. LSR A ; 0-7
  441. ORA TEMP0
  442. TAY
  443. LDX TEMPX
  444. CDRW012 LDA CHSPEED,Y ; USED THROUGHOUT THE RACK
  445. LDY HOWHARD
  446. CPY #2
  447. BMI CDRW013
  448. SEC make chefs faster on top two
  449. SBC #1 difficulty settings
  450. CDRW013 STA CSINDEX,X
  451. TAY
  452. MOVE MTABSPD,Y,CSPEED,X
  453. LDY TEMPY
  454. ; NOW, SAVE INFORMATION ABOUT THE HOLE HE'S GROWING FROM.
  455. ; THE "CREATOR" TIMER WON'T START DECREMENTING UNTIL THE RISE
  456. ; IS COMPLETED.
  457. MOVE #$20,CREATOR,X ; 3 SECOND TIMER
  458. ; DON'T LET HIM DIE FOR THIS TIME
  459. TYA ; SO HE'LL KNOW WHICH HOLE THIS IS
  460. STA HOLEUSED,X
  461. ; NOW CHANGE THE MANHOLE TO BE OPEN FOR THE RISING SEQUENCE:
  462. MOVE #OPENCHAR,FSTAMP,Y
  463. MOVE #OPEN,FSTATE,Y
  464. CDRWBYE RTS
  465. ; THE REMAINING ROUTINES ARE "RANDOM" ROUTINES WHICH RETURN A VALUE
  466. ; IN REGISTER A.
  467. ; THIS ROUTINE RETURNS A ZONE. TO GET A FIXED CHARACTER'S Y COORD. AT THE
  468. ; TOP OF THIS ZONE, MULTIPLY THE ZONE BY 8, THEN ADD #7; THE VALUE
  469. ; WILL BE EQUAL TO "TOPZONE,ZONE#"
  470. RANDOMY
  471. JSR RANDOMLC
  472. AND #1F ; BOTTOM FIVE BITS -- 31 OR LESS
  473. CMP #18 ; I NEED A NUMBER 2 - 18
  474. BPL ZRAND00 ; IF IT'S GREATER, SUBTRACT 13
  475. JMP ZRAND01
  476. ZRAND00 SEC
  477. SBC #13
  478. ZRAND01 CMP #2
  479. BPL ZRAND08 ; IF IT'S >= 2, IT'S OKAY
  480. LDA #2 ; IF IT'S LESS THAN 2, MAKE IT 2
  481. ZRAND08 ; AT THIS POINT, "A" CONTAINS 2-18
  482. RTS
  483. RANDOMX
  484. STX TEMPX ; SAVE REGISTER
  485. JSR RANDOMLC
  486. AND #$7F ; 0 - 128
  487. CLC
  488. ADC #$0A ; 10 - 138
  489. LDX TEMPX ; RESTORE REGISTER
  490. RTS
  491. ; THIS ROUTINE IS USED DURING INITIALIZATION TO RETURN "LINEAR CONGRUENTIAL"
  492. ; RANDOM NUMBERS. IT CONTAINS A MULTIPLY !
  493. ; THIS COMPUTES: RANDOM0 := (RANDOM0 * RANDOMA) + RANDOMC {MODULO 256}
  494. RANDOMLC LDA RANDOM0
  495. STA RTEMP0
  496. LDA #0
  497. STA RANDOM0 ; ALL FACTORS OF POWERS OF 2 WILL
  498. ; BE ADDED TO THIS
  499. LDA #RANDOMA
  500. RANDLOOP LSR A
  501. STA RTEMP1
  502. BCC RAND000 ; IF ZERO, JUST SKIP THIS BIT
  503. LDA RANDOM0
  504. CLC
  505. ADC RTEMP0 ; THIS IS THE PROPER MULTIPLE OF
  506. STA RANDOM0 ; "RANDOM0" FOR THIS BIT
  507. RAND000
  508. ASL RTEMP0
  509. LDA RTEMP1
  510. BNE RANDLOOP
  511. LDA RANDOM0 ; IF THE "MULTIPLIER"==0, EXIT
  512. CLC
  513. ADC #RANDOMC
  514. STA RANDOM0
  515. RTS
  516. ; THIS ROUTINE IS USED DURING GAMEPLAY. IT RETURNS
  517. ; A RANDOM NUMBER BETWEEN 0 AND 255 IN REGISTER A
  518. ARANDOM
  519. RANDOM STY RTEMPY ; SAVE Y VALUE
  520. RNDCONT LDA #$07
  521. CLC
  522. ADC RANDOM0
  523. ADC RANDOM1
  524. LDY RANDOM0
  525. STY RANDOM1
  526. STA RANDOM0
  527. LDY RTEMPY ; RESTORE REGISTER
  528. RTS
  529. ; THIS ROUTINE IS CALLED FROM "PILEDRAW" AND "HOLEDRAW" TO MAKE
  530. ; SURE THAT THE PILE OR HOLE IS NOT TOO CLOSE TO ANOTHER
  531. ; PILE OR HOLE.
  532. ; ADDED 11/15/83: THE BYTES AT FYPOS-1 AND FXPOS-1 ARE CHUCK'S LOCATION.
  533. ; THE LOOP IS CHANGED TO TEST CLOSENESS TO CHUCK AS WELL.
  534. ; NOTE THAT Y INDICES MUST BE TESTED UP TO X+1, SINCE Y STARTS
  535. ; ONE LOCATION LOWER IN THE POSITION TABLES.
  536. ASPACEM
  537. SPACEM STX TEMPX ; STOP AT CURRENT INDEX
  538. INC TEMPX ; TO REFLECT Y INDEXING ONE LESS
  539. STY TEMPY
  540. LDY #0 ; START WITH CHUCK'S COORDS.
  541. MOVE #DXHCLOSE,TEMP0 for piles vs. hero
  542. MOVE #DYHCLOSE,TEMP5
  543. SPEMLOOP CPY TEMPX ; TEST FIRST, IN CASE IT'S THE FIRST
  544. BMI ZSPCONT1 ; PILE INITIALIZED
  545. LDA #TRUE ; IF THIS IS THE LAST, RETURN TRUE
  546. RTS ; JMP SPACEBYE
  547. ZSPCONT1 LDA FYPOS-1,Y ; OBJECT TO TEST
  548. BEQ ZSPNEXT
  549. SEC
  550. SBC FYPOS,X ; CURRENT OBJECT
  551. BPL ZSP001
  552. EOR #$FF
  553. CLC
  554. ADC #1
  555. ZSP001 CMP TEMP5
  556. ; BCC ZSPXTST
  557. BCS ZSPNEXT
  558. ZSPXTST LDA FXPOS-1,Y ; OBJECT BEING TESTED
  559. SEC
  560. SBC FXPOS,X ; CURRENT OBJECT
  561. BPL ZSP003
  562. EOR #$FF
  563. CLC
  564. ADC #1
  565. ZSP003 CMP TEMP0
  566. BCC ZRTNF ; RETURN FALSE
  567. ZSPNEXT MOVE #DXCLOSE,TEMP0 for piles vs. piles
  568. MOVE #DYCLOSE,TEMP5
  569. INY ; NEXT OBJECT
  570. JMP SPEMLOOP ; CONTINUE UNTIL JUST BEFORE CURRENT
  571. ZRTNF LDA #FALSE ; RETURN FALSE-- MUST PICK NEW COORD.
  572. SPACEBYE RTS
  573. ; Copy from a block of memory to another
  574. ; This routine is called from the macro COPY
  575. ZZZZCOPY LDA (TEMP0),Y
  576. STA (TEMP2),Y
  577. DEY
  578. BNE ZZZZCOPY
  579. DEC TEMP1
  580. DEC TEMP3
  581. DEX
  582. BNE ZZZZCOPY
  583. RTS