PILEHIT.S 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. ; PILEHIT.S
  2. ; THIS FILE CONTAINS THE ROUTINE "PILEHIT". IT ALSO CONTAINS THE SMALL
  3. ; ROUTINE "FOODADJ" WHICH IS CALLED FROM A CHARACTER DRIVER WHEN
  4. ; THE CHARACTER IS DETECTED CARRYING A FOOD.
  5. ; THIS ROUTINE IS LENGTHY AND COMPLEX BECAUSE IT MUST DO TWO THINGS:
  6. ; 1) CREATE A MOVING FOOD STRUCTURE AND ATTACH IT TO THE CHARACTER
  7. ; WHO'S PICKED IT UP;
  8. ; 2) MODIFY THE DISPLAY LIST DIRECTLY TO DISPLAY A FOOD PILE WITH
  9. ; ONE LESS FOOD.
  10. ;
  11. GLBL TAKEFOOD
  12. GLBL PILEHIT
  13. DYPILE EQU 10
  14. PILEHIT LDX #12 ; X WILL BE THE CHARACTER INDEX
  15. STX TEMPX ; IN CASE NXTPHPL IS REACHED
  16. PHLOOP1 LDA CYPOS,X ; THIS IS THE CHARACTER LOOP
  17. BNE PHCONT3 ; IF CHARACTER ON SCREEN, DO IT ALL
  18. NPHCHJ JMP NXTPHCH ; IF CHARACTER NOT ON SCREEN
  19. PHCONT3 LDA CSTATE,X
  20. CMP #CARRYING
  21. BEQ NPHCHJ ; IF HE'S NOT CARRYING, CHECK PILES
  22. ;;; JMP NXTPHCH ; IF ALREADY CARRYING, HE CAN'T PICKUP
  23. PHCONT5 CMP #FALLING
  24. BPL NPHCHJ ; IF STATE < FALLING, THEN CONTINUE
  25. ;;; JMP NXTPHCH
  26. ; NOW WE KNOW TO TEST THIS CHARACTER:
  27. PHCONT6 LDA CYPOS,X
  28. SEC
  29. SBC CHHITE,X
  30. STA TEMP1
  31. LDA CXPOS,X
  32. ; CLC
  33. ; ADC #0
  34. STA TEMP0
  35. LDY #PILESTRT+NUMEPILE ; START WITH LAST PILE AND DECREMENT
  36. DEY ; INDEX IS ONE LESS THAN THE NUMBER
  37. STY TEMPY ; IN CASE NXTPHPL IS REACHED
  38. PHLOOP2 LDA FSTATE,Y ; NUMBER OF FOODS IN PILE
  39. BNE PHCONT1
  40. NPHPLJ JMP NXTPHPL ; IF NO FOOD, SKIP TO NEXT PILE
  41. PHCONT1 LDA FYPOS,Y
  42. BEQ NPHPLJ
  43. ;;; JMP NXTPHPL ; IF NO PILE HERE IN THE FIRST PLACE
  44. ; MAKE SURE THAT THE PILE IS NOT THE BOTTOM HALF OF A TWO-HALF PILE.
  45. ; IF IT IS, SKIP TO THE NEXT PILE; WE JUST FINISHED THE TOP HALF.
  46. PHCONT2 LDA FINFO,Y ; BIT 6 HIGH MEANS BOTTOM HAFL
  47. ASL A ; TO GET BIT 6 INTO BIT 7 POSITION
  48. BMI NPHPLJ
  49. ;;; JMP NXTPHPL ; IF IT'S SET, SKIP THIS ONE
  50. ; NOW WE'VE FINALLY DECIDED THAT THE PILE IS REALLY THERE AND HAS FOOD
  51. ; IN IT.
  52. PHCONT4 LDA FYCENTER,Y
  53. SEC
  54. SBC TEMP1 ; CHARACTER Y
  55. BPL PHYPOS ; POSITIVE Y DIFFERENCE
  56. EOR #$FF ; ELSE 2'S COMPLEMENT
  57. CLC
  58. ADC #1
  59. PHYPOS CMP FDY,Y
  60. BPL NPHPLJ
  61. PHXTST LDA FCENTER,Y
  62. SEC
  63. SBC TEMP0 ; CHARACTER X
  64. BPL PHXPOS ; POSITIVE X DIFFERENCE
  65. EOR #$FF
  66. CLC
  67. ADC #1
  68. PHXPOS CMP FDX,Y
  69. BPL NPHPLJ
  70. ; THE CODE WILL REACH HERE IF THE CHARACTER AT INDEX X IS ON TOP OF THE
  71. ; PILE AT INDEX Y. NOW HE HAS TO PICK UP A FOOD AND DECREMENT
  72. ; THE PILE SIZE.
  73. PICKUP TXA ; IF A CHEF, NO PICKUP ON FIRST LEVEL
  74. BEQ PICKUP1 ; IF THE HERO, GO AHEAD
  75. LDA HOWHARD if "beginner" setting, no chef throw
  76. BEQ PU003 ; JMP NXTPHCH
  77. PICKUP0 LDA PLRACK
  78. BEQ PU003 ; JMP NXTPHCH
  79. PICKUP1 JSR TAKEFOOD
  80. BMI PHBYE if result is negative, no foods left
  81. LDX TEMPX ; GET CHARACTER INDEX BACK
  82. STA HELDFOOD,X ; FOOD INDEX PLACED IN A BY TAKEFOOD
  83. LDA #CARRYING
  84. STA CSTATE,X
  85. TXA
  86. BEQ PU002 ; IF CHARLEY
  87. JSR FOODADJ ; PLACES FOOD X,Y PROPERLY
  88. JMP PU003
  89. PU002 JSR CFOODADJ
  90. PU003 JMP NXTPHCH ; GO ON TO NEXT CHARACTER
  91. NXTPHPL LDX TEMPX
  92. LDY TEMPY
  93. DEY
  94. CPY #PILESTRT
  95. BMI ZPH03 ; END OF PILES FOR THIS CHARACTER
  96. ZPH02 STY TEMPY
  97. JMP PHLOOP2 ; DO IT AGAIN FOR THIS FOOD
  98. ZPH03
  99. NXTPHCH LDX TEMPX
  100. DEX
  101. DEX
  102. DEX
  103. BMI PHBYE
  104. STX TEMPX ; UPDATE THE TEMP REGISTER AS WELL
  105. JMP PHLOOP1 ; DO IT AGAIN FOR THE NEXT CHARACTER
  106. PHBYE RTS
  107. ; THIS ROUTINE ASSUMES THAT THE CHARACTER INDEX IS IN REGISTER X, AND
  108. ; THAT THE FOOD INDEX IS STORED IN "HELDFOOD,X".
  109. FOODADJ TYA
  110. PHA
  111. LDY HELDFOOD,X ; GET INDEX OF FOOD CHARACTER
  112. LDA CXPOS,X
  113. STA CXPOS,Y
  114. LDA CYPOS,X
  115. SEC
  116. SBC #4
  117. STA CYPOS,Y
  118. ; NOW ADJUST X POSITION DEPENDING ON CHARACTER DIRECTION:
  119. LDA CDIR,X
  120. CMP #4 ; 4-7 IS LEFT, 0-3 IS RIGHT
  121. BMI FARIGHT ; 0-3
  122. ;;; JMP FALEFT ; 0-3
  123. FALEFT LDA CXPOS,Y ; FOOD'S Y
  124. CLC
  125. ADC #04
  126. STA CXPOS,Y
  127. JMP FABYE
  128. FARIGHT LDA CXPOS,Y ; FOOD'S Y
  129. SEC
  130. SBC #04
  131. STA CXPOS,Y
  132. FABYE PLA
  133. TAY ; RESTORE Y VALUE
  134. RTS
  135. ; USED ONLY BY HERO
  136. CFOODADJ TYA
  137. PHA
  138. TXA
  139. PHA
  140. LDY HELDFOOD
  141. LDX CDIR
  142. ; If the food is not being carried, erase it and change the hero's state.
  143. LDA CSTATE,Y
  144. CMP #CARRIED
  145. BEQ FOODISOK
  146. LDA #RUNNING
  147. STA CSTATE
  148. LDA #0
  149. STA CYPOS,Y
  150. BEQ CADJEXIT ;JMP
  151. *********
  152. FOODISOK LDA CXPOS
  153. CLC
  154. ADC XFOODADJ,X
  155. STA CXPOS,Y
  156. LDA CYPOS
  157. CLC
  158. ADC YFOODADJ,X
  159. STA CYPOS,Y
  160. CADJEXIT
  161. PLA
  162. TAX
  163. PLA
  164. TAY
  165. RTS
  166. ; THIS ROUTINE IS ALSO CALLED FROM "FOODMOVE" AT THE END OF MOST RACKS.
  167. ATAKE
  168. TAKEFOOD LDA FINFO,Y ; TYPE OF FOOD
  169. AND #$3F ; MASK OUT DOUBLE PILE BITS
  170. STA TEMP2 ; CONTAINS TYPE OF FOOD
  171. ; NOW FIND THE FIRST FREE ENTRY IN THE "CSTRUCT" ARRAY:
  172. ; NOTE: IF "NUMSTUCK" IS NON-ZERO, WE CAN USE A FOOD WITH STATE
  173. ; OF "STICKING". IF ALL THE FOODS ARE DISPLAYED, LOOK
  174. ; NEXT FOR A FOOD WITH THIS STATE.
  175. STY TEMPY ; PILE INDEX
  176. LDY #FOODSTRT ; FIRST ENTRY AFTER CHEFS
  177. PHFREE1 LDA CYPOS,Y
  178. BEQ PHFREE2 ; IF 0, THIS ENTRY IS FREE !
  179. INY ; ELSE TRY NEXT ENTRY...
  180. CPY #FOODSTRT+NUMFOOD
  181. BMI PHFREE1
  182. LDA STATUS ; if foods flying through air, let
  183. CMP #STATBON ; them grab stuck ones.
  184. BEQ PHFREE12
  185. CMP #STATHIT
  186. BEQ PHFREE12
  187. LDA #$FF return negative if no food
  188. RTS ; WAS JMP PHBYE
  189. ; IF I GET HERE, THEN THERE MUST BE A FOOD WITH STATE "STICKING". FIND
  190. ; THE FIRST ONE AND GET IT.
  191. PHFREE12
  192. LDY #FOODSTRT
  193. PHFREE11 LDA CSTATE,Y
  194. CMP #STICKING
  195. BEQ PHFREE22
  196. INY
  197. JMP PHFREE11 ; MUST BE ONE HERE !
  198. PHFREE22 DEC NUMSTUCK ; ONE LESS STUCK FOOD NOW
  199. ; NOW Y CONTAINS THE INDEX OF THE FOOD ENTRY, X CONTAINS THE CHARACTER INDEX.
  200. PHFREE2 TXA ; SAVE THE CHARACTER INDEX IN
  201. STA CREATOR,Y ; THE "CREATOR" ARRAY
  202. STX TEMPX
  203. LDX TEMP2 ; TYPE OF FOOD
  204. LDA FLYCHAR,X
  205. STA CSTAMP,Y ; SET CHARACTER OF FLYING FOOD
  206. LDA #BLOCK1
  207. STA CHSTAMP,Y
  208. LDA FLYPALW,X
  209. STA CPALW,Y ; SET PALETTE/WIDTH OF FOOD
  210. LDA TEMP2 ; TYPE OF FOOD
  211. STA CINFO,Y
  212. STA CTYPE,Y
  213. LDA #CARRIED ; NEEDED BY FOOD DRIVERS
  214. STA CSTATE,Y
  215. TYA ; SAVE FOOD INDEX ON STACK
  216. PHA ; IN CASE "FOODMOVE" NEEDS IT
  217. ; FIND THE PROPER DLIST ENTRY AND
  218. ; MODIFY THE CHARACTER TO DISPLAY ONE LESS FOOD.
  219. ; NOTE: IF THIS IS A WATERMELON PILE, NO MODIFICATION IS NECESSARY.
  220. LDY TEMPY ; RESTORE FIXED CHARACTER INDEX
  221. LDA FINFO,Y ; TYPE OF PILE
  222. AND #$F
  223. CMP #4 ; WATERMELON
  224. BNE NOTWAT
  225. LDA STATUS
  226. CMP #STATHIT
  227. BEQ DECWAT
  228. CMP #STATBON
  229. BEQ DECWAT
  230. JMP TFOODBYE
  231. ; IF HITTING, DECREMENT "FSTATE" BUT NO NEED TO ALTER THE CHARACTER
  232. DECWAT LDA FSTATE,Y
  233. SEC
  234. SBC #1
  235. STA FSTATE,Y
  236. JMP TFOODBYE ; THIS IS IT !
  237. NOTWAT LDA FDLPOS,Y
  238. AND #$F ; LOWER 4 BITS ARE DLIST
  239. TAX
  240. LDA LISTTABL,X
  241. STA LISTPTRA
  242. LDA LISTTABH,X
  243. STA LISTPTRA+1
  244. LDA FDLPOS,Y ; NOW GET POSITION IN DLIST
  245. AND #$F0 ; TOP FOUR BITS
  246. LSR A
  247. LSR A ; DIVIDE BY 8 TO GET INDEX
  248. TAX
  249. ; X NOW CONTAINS THE APPROPRIATE DLIST INDEX; Y CONTAINS THE FIXED CHARACTER
  250. ; INDEX. (NOTE: "TEMPY" ALSO CONTAINS THE FIXED CHAR INDEX).
  251. ; SWITCH THE TWO INDICES SO THAT 1) THE "DEC FSTATE,X" CAN BE USED,
  252. ; 2) THE "STA (LISTPTRA),Y" CAN BE USED.
  253. TYA
  254. STX TEMP3 ; X GOES TO TEMP3 THEN TO Y
  255. TAX ; Y GOES TO A THEN TO X
  256. LDY TEMP3
  257. ; NOW REGISTER Y CONTAINS THE DLIST INDEX (JUST AS IN THE ROUTINE "MLOADER"),
  258. ; AND REGISTER X CONTAINS THE FSTRUCT INDEX.
  259. ; NOW FIND OUT WHICH CHARACTER SHOULD BE DISPLAYED HERE.
  260. DEC FSTATE,X
  261. BNE PHSHRINK ; SHRINK PILE BY ONE
  262. PHGONE LDA #NULLCHAR ; KEEP THE OLD "PALW" INFO
  263. STA (LISTPTRA),Y
  264. ; IF THIS IS THE TOP HALF OF A TWO-HALF PILE, THEN REMOVE THE FLAGS
  265. ; WHICH CONNECT THE TWO FSTRUCTS.
  266. LDA FINFO,X ; BIT 7 (NEG BIT) MEANS TOP HALF
  267. BPL TFOODBYE
  268. PHLOWER LDA #$3F ; MASK OUT THE TOP TWO BITS
  269. AND FINFO,X
  270. STA FINFO,X
  271. DEX ; BOTTOM HALF IS X-1
  272. LDA #$3F
  273. AND FINFO,X
  274. STA FINFO,X
  275. LDA FINFO,X
  276. ASL A
  277. ASL A
  278. ASL A
  279. CLC
  280. ADC #3 must be 4 high
  281. STX TEMP4
  282. LDY TEMP4
  283. TAX
  284. JMP NOTTOP reset the center and delta
  285. PHSHRINK LDA FINFO,X ; TYPE OF FOOD
  286. ASL A
  287. ASL A
  288. ASL A ; MULTIPLY BY 8
  289. CLC
  290. ADC FSTATE,X ; ADD NUMBER OF FOODS
  291. SEC
  292. SBC #1 ; INDEX IS ONE LESS THAN THIS
  293. STX TEMP4
  294. TAX ; USE AS "PILECHAR" INDEX
  295. LDA PILECHAR,X ; LOW BYTE -- FIRST HEADER
  296. STA (LISTPTRA),Y
  297. INY
  298. LDA PILEPALW,X ; SECOND HEADER
  299. STA (LISTPTRA),Y ; THIRD AND FOURTH HEADER UNCHANGED
  300. STX TEMP3 save away the table index
  301. LDY TEMP3 put the table index in y
  302. LDX TEMP4 pile index
  303. ; LDA FINFO,X
  304. ; BPL NOTTOP
  305. ; If this is the top of a pile, use the maximum width, which will
  306. ; be at the beginning of the table for this pile type
  307. ; (a multiple of 8) plus 3.
  308. ; note: this should only affect the X coordinate !
  309. ; LDA TEMP3 the table index for this pile
  310. ; AND #$FC multiple of 8
  311. ; CLC
  312. ; ADC #3
  313. ; TAY contains the table index
  314. NOTTOP JSR SETCTR in INIT.S
  315. TFOODBYE
  316. PLA ; PLACE FOOD INDEX IN A, FOR FOODMOVE
  317. RTS