00001. ; Super Mario Bros. 3 Full Disassembly by Southbird 2012 
00002. ; For more info, see http://www.sonicepoch.com/sm3mix/ 
00003. ; 
00004. ; PLEASE INCLUDE A CREDIT TO THE SOUTHBIRD DISASSEMBLY 
00005. ; AND THE ABOVE LINK SOMEWHERE IN YOUR WORKS :) 
00006. ; 
00007. ; Original disassembler source generated by DCC6502 version v1.4 
00008. ; (With labels, comments, and some syntax corrections for nesasm by Southbird) 
00009. ; For more info about DCC6502, e-mail veilleux@ameth.org 
00010. ; 
00011. ; This source file last updated: 2012-03-28 13:51:54.652889989 -0500 
00012. ; Distribution package date: Fri Apr 6 23:46:16 UTC 2012 
00013. ;--------------------------------------------------------------------------- 
00014.  
00015. ; Some constants specific to title screen; they don't really match up with the gameplay 
00016. FALL_NORMAL = 5 ; Normal fall rate added to 'Y' 
00017. FALL_TAILWAG = 1 ; Adjusted fall rate for when wagging raccoon tail 
00018. FALL_OBJECT = 4 ; Fall rate for objects 
00019.  
00020. FALLRATE_TAILWAGMAX = 8 ; Maximum Y velocity falling rate when wagging raccoon tail 
00021. FALLRATE_MAX = $40 ; Maximum Y velocity falling rate 
00022. FALLRATE_OBJECTMAX = $60 ; Maximum Y velocity falling rate of an object 
00023.  
00024. Cinematic_ToadAndKing: 
00025. LDA Cine_ToadKing 
00026. LSR A 
00027. BNE PRG024_A03A ; If Cine_ToadKing > 1, jump to PRG024_A03A 
00028.  
00029. LDX #$00 ; X = 0 
00030.  
00031. JSR Level_PrepareNewObject 
00032.  
00033. ; Disable timer and animations 
00034. LDA #$81  
00035. STA Level_TimerEn 
00036.  
00037. ; CineKing_Timer = $20 
00038. LDA #$20 
00039. STA CineKing_Timer 
00040.  
00041. ; Initialize VRAM address for Toad and King Cinematic Dialog Box 
00042. LDA #$28 
00043. STA ToadTalk_VH 
00044. LDA #$86 
00045. STA ToadTalk_VL 
00046.  
00047. ; Initialize character counter 
00048. LDA #$00 
00049. STA ToadTalk_CPos 
00050.  
00051. LDA #168 
00052. STA <Objects_X 
00053.  
00054. LDA #$60 ; A = $60 
00055.  
00056. LDY World_Num ; Y = World_Num 
00057.  
00058. CPY #$01 
00059. BNE PRG024_A033 ; If World_Num <> 1 (World 2), jump to PRG024_A033 
00060.  
00061. LDA #$20 ; A = $20 
00062.  
00063. PRG024_A033: 
00064. STA King_Y 
00065.  
00066. INC Cine_ToadKing ; Cine_ToadKing = 2 
00067. RTS ; Return 
00068.  
00069. PRG024_A03A: 
00070.  
00071. ; Keep the Player halted 
00072. LDA #$02 
00073. STA Player_HaltTick 
00074.  
00075. LDA Player_HaltGame 
00076. BNE PRG024_A04A ; If gameplay is halted, jump to PRG024_A04A 
00077.  
00078. JSR King_Animate ; Do King's animation logic 
00079. JSR King_DoDialog ; Do King's dialog 
00080.  
00081. PRG024_A04A: 
00082. JMP PRG024_A39D ; Jump to PRG024_A39D 
00083.  
00084.  
00085. King_DoDialog: 
00086. ; Load font patterns 
00087. LDA #$5E 
00088. STA PatTable_BankSel+1 
00089.  
00090. LDA <CineKing_DialogState 
00091. JSR DynJump 
00092.  
00093. ; THESE MUST FOLLOW DynJump FOR THE DYNAMIC JUMP TO WORK!! 
00094. .word TAndK_DrawDiagBox ; 0: Draw the dialog box 
00095. .word TAndK_DoToadText ; 1: Do the text 
00096. .word TAndK_WaitPlayerButtonA ; 2: Wait for Player to push 'A' 
00097.  
00098. ; Patterns that make up the rows of the dialog box 
00099. DiagBox_R1: .byte $94, $90, $90, $90, $90, $90, $90, $90, $90, $90, $90, $90, $90, $90, $90, $90, $90, $90, $90, $90, $90, $96 
00100. DiagBox_R2: .byte $92, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $93 
00101. DiagBox_R3: .byte $95, $91, $91, $91, $91, $91, $91, $91, $91, $91, $91, $91, $91, $91, $91, $91, $91, $91, $91, $91, $91, $97 
00102.  
00103. DiagBox_RowOffs: 
00104. .byte (DiagBox_R1 - DiagBox_R1), (DiagBox_R2 - DiagBox_R1), (DiagBox_R2 - DiagBox_R1), (DiagBox_R2 - DiagBox_R1) 
00105. .byte (DiagBox_R2 - DiagBox_R1), (DiagBox_R2 - DiagBox_R1), (DiagBox_R2 - DiagBox_R1), (DiagBox_R3 - DiagBox_R1) 
00106. DiagBox_RowOffs_End 
00107.  
00108. TAndK_DrawDiagBox: 
00109. LDA CineKing_Timer  
00110. BNE PRG024_A119 ; If CineKing_Timer has not expired, jump to PRG024_A119 (RTS) 
00111.  
00112. LDA King_Y 
00113. CMP #90 
00114. BLT PRG024_A119 ; If King is higher than pixel line 90, jump to PRG024_A119 (RTS) 
00115.  
00116. LDX Graphics_BufCnt ; X = buffer count 
00117.  
00118. ; Set current VRAM address  
00119. LDA ToadTalk_VH 
00120. STA Graphics_Buffer,X 
00121. LDA ToadTalk_VL 
00122. STA Graphics_Buffer+1,X 
00123.  
00124. ; Jump to next video row 
00125. ADD #$20 ; 32 bytes to next row 
00126. STA ToadTalk_VL 
00127. BCC PRG024_A0CD 
00128. INC ToadTalk_VH ; Apply carry 
00129. PRG024_A0CD: 
00130.  
00131. LDA #(DiagBox_R2 - DiagBox_R1) ; run count per row 
00132. STA Graphics_Buffer+2,X 
00133. STA <Temp_Var1 ; -> Temp_Var1 
00134.  
00135. LDY ToadTalk_CPos ; Y = current dialog box row 
00136. LDA DiagBox_RowOffs,Y 
00137. TAY ; Y = offset to this row index 
00138.  
00139. PRG024_A0DB: 
00140. ; Store next pattern in dialog box 
00141. LDA DiagBox_R1,Y 
00142. STA Graphics_Buffer+3,X 
00143.  
00144. INY ; Y++ (next pattern for dialog box) 
00145. INX ; X++ (next index in graphics buffer) 
00146.  
00147. DEC <Temp_Var1 ; Temp_Var1-- 
00148. BNE PRG024_A0DB ; While Temp_Var1 > 0, loop! 
00149.  
00150. ; Insert terminator 
00151. LDA #$00 
00152. STA Graphics_Buffer+3,X 
00153.  
00154. ; X += 3 
00155. INX 
00156. INX 
00157. INX 
00158. STX Graphics_BufCnt 
00159.  
00160. INC ToadTalk_CPos ; Next row 
00161.  
00162. LDA ToadTalk_CPos 
00163. CMP #(DiagBox_RowOffs_End - DiagBox_RowOffs) 
00164. BLT PRG024_A119 ; If row count < 8, jump to PRG024_A119 
00165.  
00166. ; Dialog box is complete 
00167.  
00168. LDA #$00 ; A = 0 ("The King has been transformed!") 
00169.  
00170. LDY Map_Objects_IDs 
00171. BNE PRG024_A105 ; If the "HELP!" bubble is still present (haven't been on airship yet), jump to PRG024_A105 
00172.  
00173. LDA #(KingHelpMsg2 - KingHelpMsg1) ; ("Get the magic wand back from little koopa!") 
00174.  
00175. PRG024_A105: 
00176. STA ToadTalk_CPos ; Set proper character position 
00177.  
00178. ; Initialize VRAM address for Toad and King Cinematic Dialog Box Text 
00179. LDA #$28 
00180. STA ToadTalk_VH 
00181. LDA #$a7 
00182. STA ToadTalk_VL 
00183.  
00184. ; CineKing_Timer = $10 
00185. LDA #$10 
00186. STA CineKing_Timer 
00187.  
00188. INC <CineKing_DialogState ; CineKing_DialogState = 1 
00189.  
00190. PRG024_A119: 
00191. RTS ; Return 
00192.  
00193. ; English: "Oh,it's terrible!" / "The King has been" / "transformed!" / "Please find the" / "Magic Wand so we can" / "change him back" 
00194. KingHelpMsg1: 
00195. ; O h , i t ' s t e r r i b l e ! 
00196. .byte $BE, $D7, $9A, $D8, $CD, $AB, $CC, $FE, $CD, $D4, $CB, $CB, $D8, $D1, $DB, $D4, $EA, $FE, $FE, $FE 
00197.  
00198. ; T h e K i n g h a s b e e n 
00199. .byte $C3, $D7, $D4, $FE, $BA, $D8, $DD, $D6, $FE, $D7, $D0, $CC, $FE, $D1, $D4, $D4, $DD, $FE, $FE, $FE 
00200.  
00201. ; t r a n s f o r m e d ! 
00202. .byte $CD, $CB, $D0, $DD, $CC, $D5, $DE, $CB, $DC, $D4, $D3, $EA, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE 
00203.  
00204. ; P l e a s e f i n d t h e 
00205. .byte $BF, $DB, $D4, $D0, $CC, $D4, $FE, $D5, $D8, $DD, $D3, $FE, $CD, $D7, $D4, $FE, $FE, $FE, $FE, $FE 
00206.  
00207. ; M a g i c W a n d s o w e c a n 
00208. .byte $BC, $D0, $D6, $D8, $D2, $FE, $C6, $D0, $DD, $D3, $FE, $CC, $DE, $FE, $81, $D4, $FE, $D2, $D0, $DD 
00209.  
00210. ; c h a n g e h i m b a c k . 
00211. .byte $D2, $D7, $D0, $DD, $D6, $D4, $FE, $D7, $D8, $DC, $FE, $D1, $D0, $D2, $DA, $E9, $FE, $FE, $FE, $FE 
00212.  
00213. ; English: "Hurry! Hurry!" / "Get the Magic Wand" / "back from Little" / "Koopa." 
00214. KingHelpMsg2: 
00215. ; H u r r y ! H u r r y ! 
00216. .byte $B7, $CE, $CB, $CB, $8C, $EA, $FE, $B7, $CE, $CB, $CB, $8C, $EA, $FE, $FE, $FE, $FE, $FE, $FE, $FE 
00217.  
00218. ; G e t t h e M a g i c W a n d 
00219. .byte $B6, $D4, $CD, $FE, $CD, $D7, $D4, $FE, $BC, $D0, $D6, $D8, $D2, $FE, $C6, $D0, $DD, $D3, $FE, $FE 
00220.  
00221. ; b a c k f r o m L i t t l e 
00222. .byte $D1, $D0, $D2, $DA, $FE, $D5, $CB, $DE, $DC, $FE, $BB, $D8, $CD, $CD, $DB, $D4, $FE, $FE, $FE, $FE 
00223.  
00224. ; K o o p a . 
00225. .byte $BA, $DE, $DE, $DF, $D0, $E9, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE 
00226.  
00227. ; 
00228. .byte $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE 
00229.  
00230. ; 
00231. .byte $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE 
00232.  
00233. TAndK_DoToadText: 
00234. LDA CineKing_Timer 
00235. BNE PRG024_A260 ; If the timer is not expired, jump to PRG024_A260 
00236.  
00237. LDY ToadTalk_CPos ; Y = dialog message character position 
00238.  
00239. LDA KingHelpMsg1,Y ; Get next character of message 
00240.  
00241. LDY Graphics_BufCnt ; Y = graphics buffer counter 
00242. STA Graphics_Buffer+3,Y ; Store into buffer 
00243.  
00244. ; Insert one character into graphics buffer 
00245. LDA ToadTalk_VH 
00246. STA Graphics_Buffer,Y ; address high 
00247. LDA #$01  
00248. STA Graphics_Buffer+2,Y ; run length 
00249. LSR A 
00250. STA Graphics_Buffer+4,Y ; terminator 
00251. TYA 
00252. ADD #$04 
00253. STA Graphics_BufCnt ; count 
00254. LDA ToadTalk_VL 
00255. STA Graphics_Buffer+1,Y ; address low 
00256.  
00257. INC ToadTalk_CPos ; Next character in message 
00258. INC ToadTalk_VL ; Next VRAM byte 
00259. AND #$1f ; Get current column 
00260. CMP #$1a  
00261. BNE PRG024_A25B ; If we're not in column 26, jump to PRG024_A25B 
00262.  
00263. ; Line break! 
00264.  
00265. LDA ToadTalk_VL 
00266. ADC #$0b ; Add enough bytes to get to next row 
00267. STA ToadTalk_VL 
00268. BCC PRG024_A250 
00269. INC ToadTalk_VH ; Apply carry 
00270. PRG024_A250: 
00271.  
00272. CMP #$67  
00273. BNE PRG024_A25B ; If we haven't reached the last character, jump to PRG024_A25B 
00274.  
00275. INC <CineKing_DialogState ; CineKing_DialogState = 2 
00276.  
00277. LDA #$00 
00278. STA ToadTalk_CPos 
00279.  
00280. PRG024_A25B: 
00281. ; Reset tick counter for next character 
00282. LDA #$04 
00283. STA CineKing_Timer 
00284.  
00285. PRG024_A260: 
00286. RTS ; Return 
00287.  
00288.  
00289. TAndK_WaitPlayerButtonA: 
00290. LDA <Pad_Input 
00291. BPL PRG024_A282 ; If Player is not pushing 'A', jump to PRG024_A282 (RTS) 
00292.  
00293. LDA Map_Objects_IDs 
00294. BEQ PRG024_A27A ; If the "HELP!" bubble is gone, jump to PRG024_A27A 
00295.  
00296. ; Level_JctCtl = 3 (switch to airship) 
00297. LDA #$03 
00298. STA Level_JctCtl 
00299.  
00300. ; No more "HELP!" bubble... 
00301. LDA #MAPOBJ_EMPTY 
00302. STA Map_Objects_IDs 
00303.  
00304. ; Airship is in town now! 
00305. LDA #MAPOBJ_AIRSHIP 
00306. STA Map_Objects_IDs+1 
00307.  
00308. RTS ; Return 
00309.  
00310.  
00311. PRG024_A27A: 
00312. ; Standard exit to map 
00313. LDA #$00 
00314. STA Map_ReturnStatus 
00315. INC Level_ExitToMap 
00316.  
00317. PRG024_A282: 
00318. RTS ; Return 
00319.  
00320. ; Sets PatTable_BankSel+5 by world 1-7 
00321. King_PatTableByWorld: 
00322. .byte $27, $27, $27, $26, $26, $26, $27 
00323.  
00324. ; Sets King's sprite palette select by world 1-7 
00325. King_PalByWorld: 
00326. .byte SPR_PAL2, SPR_PAL2, SPR_PAL3, SPR_PAL2, SPR_PAL2, SPR_PAL2, SPR_PAL2 
00327.  
00328. ; Number of King's patterns (sprites) by world 1-7 
00329. King_NumPatsByWorld: 
00330. .byte (King_W1Pat0 - King_W1Pat1), (King_W2Pat1 - King_W2Pat0), (King_W3Pat0 - King_W3Pat1), (King_W4Pat0 - King_W4Pat1) 
00331. .byte (King_W5Pat1 - King_W5Pat0), (King_W6Pat1 - King_W6Pat0), (King_W7Pat0 - King_W7Pat1) 
00332.  
00333. ; King sprite data offset by world and frame (Left = 0, Right = 1) 
00334. King_SprDataOffByWorldAndFrame: 
00335. .byte (King_W1YOff - King_SprDataYOff), (King_W1YOff - King_SprDataYOff) ; World 1 
00336. .byte (King_W2YOff - King_SprDataYOff), (King_W2YOff - King_SprDataYOff) ; World 2 
00337. .byte (King_W3YOff0 - King_SprDataYOff), (King_W3YOff1 - King_SprDataYOff) ; World 3 
00338. .byte (King_W4YOff - King_SprDataYOff), (King_W4YOff - King_SprDataYOff) ; World 4 
00339. .byte (King_W5YOff - King_SprDataYOff), (King_W5YOff - King_SprDataYOff) ; World 5 
00340. .byte (King_W6YOff - King_SprDataYOff), (King_W6YOff - King_SprDataYOff) ; World 6 
00341. .byte (King_W7YOff0 - King_SprDataYOff), (King_W7YOff1 - King_SprDataYOff) ; World 7 
00342.  
00343. ; Y offset (from King_Y) per King sprite (must be parallel with King_SprDataX) 
00344. King_SprDataYOff: 
00345. King_W1YOff: .byte $09, $10, $10, $10, $20, $20, $20 
00346. King_W7YOff1: .byte $02, $10, $10, $20, $20 
00347. King_W7YOff0: .byte $03, $10, $10, $20, $20 
00348. King_W6YOff: .byte $00, $16, $16 
00349. King_W5YOff: .byte $EA, $F0, $F0, $F0, $00, $00, $00 
00350. King_W4YOff: .byte $0B, $10, $10, $10, $20, $20, $20 
00351. King_W2YOff: .byte $00, $00, $00 
00352. King_W3YOff1: .byte $0D, $10, $10, $20, $20, $20 
00353. King_W3YOff0: .byte $0E, $10, $10, $20, $20, $20 
00354.  
00355. ; X per King sprite (must be parallel with King_SprDataYOff) 
00356. King_SprDataX: 
00357. King_W1X: .byte $D7, $CC, $D4, $DC, $CC, $D4, $DC 
00358. King_W7X1: .byte $CC, $C8, $D0, $C8, $D0 
00359. King_W7X2: .byte $CC, $C8, $D0, $C8, $D0 
00360. King_W6X: .byte $C8, $C8, $D0 
00361. King_W5X: .byte $D4, $D0, $D8, $E0, $D0, $D8, $E0 
00362. King_W4X: .byte $D2, $D0, $D8, $E0, $D0, $D8, $E0 
00363. King_W2X: .byte $CC, $C8, $D0 
00364. King_W3X1: .byte $D3, $D0, $D8, $D0, $D8, $E0 
00365. King_W3X0: .byte $D1, $D0, $D8, $D0, $D8, $E0 
00366.  
00367. King_SprPatOffByWorldAndFrame: 
00368. .byte (King_W1Pat0 - King_SprPats), (King_W1Pat1 - King_SprPats) ; World 1 
00369. .byte (King_W2Pat0 - King_SprPats), (King_W2Pat1 - King_SprPats) ; World 2 
00370. .byte (King_W3Pat0 - King_SprPats), (King_W3Pat1 - King_SprPats) ; World 3 
00371. .byte (King_W4Pat0 - King_SprPats), (King_W4Pat1 - King_SprPats) ; World 4 
00372. .byte (King_W5Pat0 - King_SprPats), (King_W5Pat1 - King_SprPats) ; World 5 
00373. .byte (King_W6Pat0 - King_SprPats), (King_W6Pat1 - King_SprPats) ; World 6 
00374. .byte (King_W7Pat0 - King_SprPats), (King_W7Pat1 - King_SprPats) ; World 7 
00375.  
00376. King_SprPats: 
00377. King_W1Pat1: .byte $E1, $E3, $E5, $E7, $E9, $EB 
00378. King_W1Pat0: .byte $E1, $ED, $E5, $E7, $EF, $EB 
00379. King_W7Pat1: .byte $F1, $F3, $F5, $F7 
00380. King_W7Pat0: .byte $F9, $D5, $FD, $FF 
00381. King_W6Pat0: .byte $C1, $C3 
00382. King_W6Pat1: .byte $C5, $C7 
00383. King_W5Pat0: .byte $DB, $DD, $DF, $E1, $E3, $E5 
00384. King_W5Pat1: .byte $DB, $E7, $E9, $E1, $EB, $ED 
00385. King_W4Pat1: .byte $D5, $CB, $CD, $D7, $D9, $D3 
00386. King_W4Pat0: .byte $C9, $CB, $CD, $CF, $D1, $D3 
00387. King_W2Pat0: .byte $D9, $DB 
00388. King_W2Pat1: .byte $DD, $DF 
00389. King_W3Pat1: .byte $CB, $CD, $CF, $D1, $D3 
00390. King_W3Pat0: .byte $C1, $C3, $C5, $C7, $C9 
00391.  
00392. ; World 6 King is a seal juggling a crown (indexed by CineKing_Frame2) 
00393. King_W6Crown_YOff: .byte $06, $04, $0A, $09, $09, $02, $04, $06 
00394. King_W6Crown_Pattern: .byte -5, -3, -3, -5, -3, -3, -5, -5 
00395. King_W6Crown_Attr:  
00396. .byte SPR_PAL3, SPR_PAL3, SPR_PAL3 | SPR_VFLIP, SPR_PAL3 | SPR_VFLIP, SPR_PAL3 | SPR_HFLIP | SPR_VFLIP 
00397. .byte SPR_PAL3 | SPR_HFLIP, SPR_PAL3, SPR_PAL3 
00398.  
00399. PRG024_A36C: 
00400. .byte $30, $40, $50, $60 
00401.  
00402. ; Sprites that make up the yelling Toad 
00403. KingToad_Sprites: 
00404. .byte $80, $00, $01, $B8 
00405. .byte $80, $00, $01, $B0 
00406. .byte $80, $00, $01, $A8 
00407. .byte $70, $00, $01, $B8 
00408. .byte $70, $00, $01, $B0 
00409. .byte $70, $00, $01, $A8 
00410. KingToad_Sprites_End 
00411.  
00412. KingToad_Patterns: 
00413. ToadFrame0: .byte $A1, $A3, $A5, $A7, $A9, $AB 
00414. ToadFrame1: .byte $B9, $BB, $71, $BD, $BF, $71 
00415. ToadFrame2: .byte $AD, $AF, $B1, $B3, $B5, $B7 
00416.  
00417. KingToad_PatOffset: 
00418. .byte (ToadFrame0 - KingToad_Patterns), (ToadFrame1 - KingToad_Patterns), (ToadFrame2 - KingToad_Patterns) 
00419.  
00420. PRG024_A39D: 
00421. ; Load yelling Toad's graphics 
00422. LDA #$2a 
00423. STA PatTable_BankSel+4 
00424.  
00425. ; Copy in the sprites for yelling Toad 
00426. LDY #(KingToad_Sprites_End - KingToad_Sprites - 1) 
00427. PRG024_A3A4: 
00428. LDA KingToad_Sprites,Y 
00429. STA Sprite_RAM+$40,Y 
00430.  
00431. DEY ; Y-- 
00432. BPL PRG024_A3A4 ; While Y >= 0, loop 
00433.  
00434. LDY Objects_Frame ; Y = yelling Toad's frame 
00435. LDX KingToad_PatOffset,Y ; X = base offset into patterns for this frame 
00436.  
00437. ; Patch the patterns on the yelling Toad for the current frame 
00438. LDY #((KingToad_Sprites_End - KingToad_Sprites - 1) & ~3) 
00439. PRG024_A3B5: 
00440. LDA KingToad_Patterns,X 
00441. STA Sprite_RAM+$41,Y 
00442.  
00443. INX ; X++ (index to next patch pattern) 
00444.  
00445. ; Y -= 4 (previous sprite) 
00446. DEY 
00447. DEY 
00448. DEY 
00449. DEY 
00450.  
00451. BPL PRG024_A3B5 ; While Y >= 0, loop 
00452.  
00453. LDY World_Num ; Y = World_Num 
00454.  
00455. ; Set King's pattern table 
00456. LDA King_PatTableByWorld,Y 
00457. STA PatTable_BankSel+5  
00458.  
00459. ; King's Y -> Temp_Var1 
00460. LDA King_Y 
00461. STA <Temp_Var1 
00462.  
00463. ; King's palette select -> Temp_Var2 
00464. LDA King_PalByWorld,Y 
00465. STA <Temp_Var2 
00466.  
00467. ; King's number of patterns (sprites) -> Temp_Var4 and 5 
00468. LDA King_NumPatsByWorld,Y 
00469. STA <Temp_Var4 
00470. STA <Temp_Var5 
00471.  
00472. TYA ; A = Y (World_Num) 
00473. ASL A ; A = World_Num * 2 
00474. ORA CineKing_Frame ; OR'd King's frame (0 or 1) 
00475. PHA ; Save value 
00476. TAY ; -> 'Y' 
00477.  
00478. LDX King_SprDataOffByWorldAndFrame,Y ; X = root index of King Sprite data 
00479. LDY #$60 ; Y = $60 
00480. PRG024_A3E8: 
00481. ; Set King Sprite Y 
00482. LDA <Temp_Var1 
00483. ADD King_SprDataYOff,X 
00484. STA Sprite_RAM,Y 
00485.  
00486. ; Set King Sprite Attributes 
00487. LDA <Temp_Var2 
00488. STA Sprite_RAM+$02,Y 
00489.  
00490. ; Set King Sprite X 
00491. LDA King_SprDataX,X 
00492. STA Sprite_RAM+$03,Y 
00493.  
00494. INX ; X++ (next King sprite data) 
00495.  
00496. ; Y += 4 (Next King sprite) 
00497. INY 
00498. INY 
00499. INY 
00500. INY 
00501.  
00502. DEC <Temp_Var4 ; Temp_Var4-- 
00503. BPL PRG024_A3E8 ; While Temp_Var4 >= 0, loop 
00504.  
00505. PLA ; Restore A = (World_Num * 2) | CineKing_Frame 
00506. TAY ; -> 'Y' 
00507.  
00508. ; Copy in all the King sprite patterns 
00509. LDX King_SprPatOffByWorldAndFrame,Y ; X = root index of King Sprite patterns 
00510. LDY #$64 ; Y = $64 
00511. PRG024_A40C: 
00512. LDA King_SprPats,X 
00513. STA Sprite_RAM+$01,Y 
00514.  
00515. INX ; X++ (next King Sprite pattern index) 
00516.  
00517. ; Y += 4 (next King Sprite) 
00518. INY 
00519. INY 
00520. INY 
00521. INY 
00522.  
00523. DEC <Temp_Var5 ; Temp_Var5-- 
00524. BNE PRG024_A40C ; While Temp_Var5 <> 0, loop 
00525.  
00526. LDY World_Num 
00527. CPY #$05 
00528. BEQ PRG024_A48A ; If World_Num = 5 (World 6), jump to PRG024_A48A 
00529.  
00530. ; Not World 6... 
00531.  
00532. ; Just put a stationary crown there 
00533. LDA #$fb 
00534. STA Sprite_RAM+$61 
00535. LDA #$02 
00536. STA Sprite_RAM+$62 
00537.  
00538. CPY #$06 
00539. BNE PRG024_A439 ; If World_Num <> 6 (World 7), jump to PRG024_A439 
00540.  
00541. ; World 7 only... 
00542.  
00543. ; Set piranha's body palette to 3 
00544. LDA #SPR_PAL3 
00545. STA Sprite_RAM+$6E 
00546. STA Sprite_RAM+$72 
00547.  
00548. RTS ; Return 
00549.  
00550. PRG024_A439: 
00551. CPY #$01 
00552. BNE PRG024_A4A1 ; If World_Num <> 1 (World 2), jump to PRG024_A4A1 (RTS) 
00553.  
00554. ; World 2 only... 
00555.  
00556. ; Crown on the floor  
00557. LDA #$80 
00558. STA Sprite_RAM+$60 
00559.  
00560. ; Temp_Var4 = CineKing_DialogState 
00561. LDA <CineKing_DialogState 
00562. STA <Temp_Var4 
00563.  
00564. ; Temp_Var3 = $10 
00565. LDA #$10 
00566. STA <Temp_Var3 
00567.  
00568. LDY #$80 ; Y = $80 
00569. PRG024_A44C: 
00570. LDA <Temp_Var4 
00571. BEQ PRG024_A466 ; If Temp_Var4 (CineKing_DialogState) = 0, jump to PRG024_A466 
00572.  
00573. LDX #$03 ; X = 3 
00574.  
00575. CMP #$00 
00576. BNE PRG024_A45B ; Jump (technically always) to PRG024_A45B 
00577.  
00578. LDA ToadTalk_CPos 
00579. LSR A 
00580. TAX ; X = ToadTalk_CPos / 2 
00581.  
00582. PRG024_A45B: 
00583. LDA <Temp_Var3 
00584. CMP #$20 
00585. BLT PRG024_A466 ; If Temp_Var3 < $20, jump to PRG024_A466 
00586.  
00587. CMP PRG024_A36C,X 
00588. BLT PRG024_A47E ; If Temp_Var3 < PRG024_A36C[X], jump to PRG024_A47E 
00589.  
00590. PRG024_A466: 
00591.  
00592. ; Set web sprite Y 
00593. LDA <Temp_Var3 
00594. STA Sprite_RAM,Y 
00595.  
00596. ; Set web sprite pattern 
00597. LDA #$d7 
00598. STA Sprite_RAM+$01,Y 
00599.  
00600. ; Set web sprite attribute 
00601. LDA <Temp_Var2 
00602. STA Sprite_RAM+$02,Y 
00603.  
00604. ; Set web sprite X 
00605. LDA #$d0 
00606. STA Sprite_RAM+$03,Y 
00607.  
00608. ; Y += 4 (next sprite) 
00609. INY 
00610. INY 
00611. INY 
00612. INY 
00613.  
00614. PRG024_A47E: 
00615.  
00616. ; Temp_Var3 += $10 
00617. LDA <Temp_Var3 
00618. ADD #$10 
00619. STA <Temp_Var3 
00620.  
00621. CMP <Temp_Var1  
00622. BLT PRG024_A44C ; While Temp_Var3 < Temp_Var1, loop! 
00623.  
00624. RTS ; Return 
00625.  
00626. PRG024_A48A: 
00627. LDY <CineKing_Frame2 
00628.  
00629. ; Set crown sprite Y 
00630. LDA <Temp_Var1 ; King Sprite Y 
00631. ADD King_W6Crown_YOff,Y 
00632. STA Sprite_RAM+$60 
00633.  
00634. ; Set crown sprite pattern 
00635. LDA King_W6Crown_Pattern,Y 
00636. STA Sprite_RAM+$61 
00637.  
00638. ; Set crown sprite attributes 
00639. LDA King_W6Crown_Attr,Y 
00640. STA Sprite_RAM+$62 
00641.  
00642. PRG024_A4A1: 
00643. RTS ; Return 
00644.  
00645. ; Performs animation logic for the king 
00646. King_Animate: 
00647. LDA <Counter_1 
00648. AND #$07 
00649. BNE PRG024_A4B2 ; 6:7 ticks, jump to PRG024_A4B2 
00650.  
00651. ; Loop the panicking Toad's frame 2 to 0 
00652. DEC Objects_Frame 
00653. BPL PRG024_A4B2 
00654. LDA #$02 
00655. STA Objects_Frame 
00656.  
00657. PRG024_A4B2: 
00658. LDA World_Num 
00659. JSR DynJump 
00660.  
00661. ; THESE MUST FOLLOW DynJump FOR THE DYNAMIC JUMP TO WORK!! 
00662. .word King_W1347 ; World 1 King (Dog scratching ear) 
00663. .word King_W2 ; World 2 King (Spider with crown on floor) 
00664. .word King_W1347 ; World 3 King (Hunched green creature) 
00665. .word King_W1347 ; World 4 King (Dinosaur) 
00666. .word King_W5 ; World 5 King (Albatross) 
00667. .word King_W6 ; World 6 King (Seal juggling crown) 
00668. .word King_W1347 ; World 7 King (Fire Piranha) 
00669.  
00670. W6Seal_Frames: .byte $01, $01, $01, $00, $00, $00, $00, $01 
00671. W6Crown_Frames: .byte $00, $01, $02, $03, $04, $05, $00, $01 
00672.  
00673. King_W6: 
00674. LDA <Counter_1 
00675. LSR A 
00676. LSR A 
00677. LSR A 
00678. AND #$07 
00679. TAY ; Y = 0 to 7 by counter 
00680.  
00681. ; Set seal's frame 
00682. LDA W6Seal_Frames,Y 
00683. STA CineKing_Frame 
00684.  
00685. ; Set seal juggled crown frame 
00686. LDA W6Crown_Frames,Y 
00687. STA <CineKing_Frame2 
00688.  
00689. RTS ; Return 
00690.  
00691. King_YDelta: .byte $01, -$01, $01 
00692. King_W2_YLimit: .byte $70, $68 
00693.  
00694. King_W2: 
00695. JSR King_W1347 ; Do animation like other kings 
00696.  
00697. LDA King_Y 
00698. CMP #$68 
00699. BGE PRG024_A4FD ; If King_Y >= $68, jump to PRG024_A4FD  
00700.  
00701. INC King_Y ; King_Y++ 
00702.  
00703. RTS ; Return 
00704.  
00705. PRG024_A4FD: 
00706. LDA <Counter_1 
00707. AND #$03  
00708. BNE PRG024_A519 ; 3:4 ticks, jump to PRG024_A519 
00709.  
00710. LDY <CineKing_Var ; Y = CineKing_Var (0/1 as spider walks up and down) 
00711.  
00712. ; King spider moves up or down 
00713. LDA King_Y 
00714. ADD King_YDelta,Y 
00715. STA King_Y 
00716.  
00717. CMP King_W2_YLimit,Y 
00718. BNE PRG024_A519 ; If King has not hit Y limit in this direction, jump to PRG024_A519 
00719.  
00720. ; Reverse direction 
00721. TYA 
00722. EOR #$01 
00723. STA <CineKing_Var 
00724.  
00725. PRG024_A519: 
00726. RTS ; Return 
00727.  
00728. PRG024_A51A: 
00729. .byte %00100100 ; World 1 
00730. .byte %00001000 ; World 2 
00731. .byte %00101000 ; World 3 
00732. .byte %00101000 ; World 4 
00733. .byte %00010000 ; World 5 
00734. .byte %00000000 ; World 6 
00735. .byte %00010000 ; World 7 
00736.  
00737. King_W1347: 
00738. LDY World_Num ; Y = World_Num 
00739.  
00740. LDA <Counter_1 
00741. AND PRG024_A51A,Y ; Mask counter by value from PRG024_A51A 
00742. BEQ PRG024_A52D ; If this is the tick to fire on, jump to PRG024_A52D 
00743.  
00744. LDA #$01 ; A = 1 (frame) 
00745.  
00746. PRG024_A52D: 
00747. STA CineKing_Frame ; Set king frame 
00748.  
00749. RTS ; Return 
00750.  
00751. King_W5: 
00752. JSR King_W1347 ; Do animation like other kings 
00753.  
00754. TAY ; Y = King frame 
00755.  
00756. LDA <Counter_1 
00757. AND #$03  
00758. BNE PRG024_A545 ; 3:4 ticks, jump to PRG024_A545 
00759.  
00760. LDA King_Y 
00761. ADD King_YDelta+1,Y 
00762. STA King_Y 
00763.  
00764. PRG024_A545: 
00765. RTS ; Return 
00766.  
00767.  
00768. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
00769. ;;;;;;;;;;;;;;;;;;;;; BEGIN UNUSED COPY/PASTED CODE ;;;;;;;;;;;;;;;;;;;;; 
00770. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
00771.  
00772. ; The following are copied fragments from PRG022 ... THEY DO NOT BELONG HERE 
00773. ; They also are in the wrong address space (PRG024 is $Axxx, PRG022 is $Cxxx) 
00774. ; My guess... massive copy/paste error? :D 
00775.  
00776. ; $A546 
00777. STA <Temp_Var11 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00778.  
00779. PRG024_A548: ; <-- originally PRG022_C548 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00780. LDA Background_Tiles,X ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00781. STA [BonusText_BaseL],Y ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00782.  
00783. INY ; Y++ (next tile, DANGEROUS) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00784.  
00785. DEC <Temp_Var11 ; Temp_Var11-- (repeat) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00786. BPL PRG024_A548 ; While Temp_Var11 >= 0, loop! ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00787.  
00788. INC <Temp_Var12 ; Temp_Var12++ ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00789.  
00790. JMP PRG022_C51E ; Jump to PRG022_C51E (is what this should be) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00791.  
00792.  
00793. ; Player_BonusTiles_Big: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00794. .byte TILE15_BRICKBG, TILE15_PLAYERBIG_TOPM, TILE15_PLAYERBIG_TOPR ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00795. .byte TILE15_PLAYERBIG_HEADL, TILE15_PLAYERBIG_HEADM, TILE15_PLAYERBIG_HEADR ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00796. .byte TILE15_PLAYERBIG_TORL, TILE15_PLAYERBIG_TORM, TILE15_PLAYERBIG_TORR ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00797. .byte TILE15_PLAYERBIG_BOTL, TILE15_PLAYERBIG_BOTM, TILE15_PLAYERBIG_BOTR ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00798.  
00799. ; Player_BonusTiles_Raccoon: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00800. .byte TILE15_BRICKBG, TILE15_PLAYERRAC_TOPM, TILE15_PLAYERRAC_TOPR ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00801. .byte TILE15_PLAYERBIG_HEADL, TILE15_PLAYERBIG_HEADM, TILE15_PLAYERBIG_HEADR ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00802. .byte TILE15_PLAYERBIG_TORL, TILE15_PLAYERBIG_TORM, TILE15_PLAYERBIG_TORR ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00803. .byte TILE15_PLAYERBIG_RACL, TILE15_PLAYERBIG_RACM, TILE15_PLAYERBIG_BOTR ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00804.  
00805. ; Player_BonusTiles_Small: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00806. .byte TILE15_BRICKBG, TILE15_BRICKBG, TILE15_BRICKBG ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00807. .byte TILE15_BRICKBG, TILE15_BRICKBG, TILE15_BRICKBG ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00808. .byte TILE15_BRICKBG, TILE15_PLAYERSM_TOP, TILE15_BRICKBG ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00809. .byte TILE15_BRICKBG, TILE15_PLAYERSM_BOTTOM, TILE15_BRICKBG ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00810.  
00811. ; PlayerSuit_ToIndex: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00812. .byte PLAYERSUIT_BIG ; 0 (Default when all else fails) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00813. .byte PLAYERSUIT_RACCOON ; 1 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00814. .byte PLAYERSUIT_SMALL ; 2 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00815.  
00816. ; PlayerSuit_TileBaseIndex: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00817. .byte (Player_BonusTiles_Big - Player_BonusTiles_Big) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00818. .byte (Player_BonusTiles_Raccoon - Player_BonusTiles_Big) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00819. .byte (Player_BonusTiles_Small - Player_BonusTiles_Big) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00820.  
00821. ; LoadLevel_BonusPlayer: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00822.  
00823. ; This loop tries to match the Player's power up with an index ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00824. ; If nothing else, X = 0, which uses "Big" ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00825. LDX #(PlayerSuit_ToIndex_End - PlayerSuit_ToIndex - 1) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00826. LDY Player_Current ; Y = Player_Current ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00827. LDA World_Map_Power,Y ; Get current Player's power ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00828. PRG024_A589: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00829. CMP PlayerSuit_ToIndex,X ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00830. BEQ PRG024_A591 ; If this is the Player's current power up, jump to PRG024_A591 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00831.  
00832. DEX ; X-- ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00833. BNE PRG024_A589 ; While X > 0, loop! ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00834.  
00835. PRG024_A591: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00836.  
00837. ; Get starting tile for Player ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00838. LDA PlayerSuit_TileBaseIndex,X ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00839. TAX ; -> 'X' ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00840.  
00841. ; Temp_Var3 = 0 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00842. LDA #$00 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00843. STA <Temp_Var3 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00844.  
00845. LDY TileAddr_Off ; Y = TileAddr_Off ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00846.  
00847. PRG024_A59C: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00848. ; Temp_Var1 = 2 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00849. LDA #$02 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00850. STA <Temp_Var1 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00851.  
00852. PRG024_A5A0: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00853. ; Get tile for Player -> grid ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00854. LDA Player_BonusTiles_Big,X ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00855. STA [BonusText_BaseL],Y ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00856.  
00857. INY ; Y++ (next grid tile, DANGEROUS!) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00858. INX ; X++ (next Player tile) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00859.  
00860. INC <Temp_Var3 ; Temp_Var3++ ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00861. DEC <Temp_Var1 ; Temp_Var1-- ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00862.  
00863. BPL PRG024_A5A0 ; While Temp_Var1 >= 0, loop ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00864.  
00865. ; Go to next row of tiles ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00866. LDA TileAddr_Off ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00867. ADD #16 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00868. STA TileAddr_Off ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00869. TAY ; -> 'Y' ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00870.  
00871. LDA <Temp_Var3 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00872. CMP #(Player_BonusTiles_Raccoon - Player_BonusTiles_Big) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00873. BNE PRG024_A59C ; If we have more tiles to go, loop! ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00874.  
00875. RTS ; Return ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00876.  
00877. ; BonusUNKTALL_Tiles: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00878. .byte TILE15_UNKTALL_UL, TILE15_UNKTALL_UR ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00879. .byte TILE15_UNKTALL_R1L, TILE15_UNKTALL_R1R ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00880. .byte TILE15_UNKTALL_R2L, TILE15_UNKTALL_R2R ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00881. .byte TILE15_UNKTALL_LL, TILE15_UNKTALL_LR ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00882.  
00883. ; LoadLevel_UNKTALL: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00884. LDX #$00 ; X = 0 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00885. LDY TileAddr_Off ; Y = TileAddr_Off ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00886.  
00887. PRG024_A5CB: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00888. ; Temp_Var1 = 1 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00889. LDA #$01 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00890. STA <Temp_Var1 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00891.  
00892. PRG024_A5CF: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00893. LDA BonusUNKTALL_Tiles,X ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00894. STA [BonusText_BaseL],Y ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00895.  
00896. INY ; Y++ (next grid tile, DANGEROUS!) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00897. INX ; X++ ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00898.  
00899. DEC <Temp_Var1 ; Temp_Var1-- ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00900. BPL PRG024_A5CF ; While Temp_Var1 >= 0, loop ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00901.  
00902. ; Next tile row ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00903. LDA TileAddr_Off ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00904. ADD #16 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00905. STA TileAddr_Off ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00906. TAY ; -> 'Y' ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00907.  
00908. CPX #(BonusUNKTALL_Tiles_End - BonusUNKTALL_Tiles) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00909. BNE PRG024_A5CB ; While X < number of tiles, loop! ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00910.  
00911. RTS ; Return ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00912.  
00913.  
00914. ; LoadLevel_Border: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00915. LDY TileAddr_Off ; Y = TileAddr_Off ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00916.  
00917. ; Border upper left ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00918. LDA #TILE15_BORDER_UL ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00919. STA [BonusText_BaseL],Y ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00920.  
00921. ; Run of 14 middle tiles ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00922. PRG024_A5F0: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00923. INY ; Y++ ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00924.  
00925. LDA #TILE15_BORDER_UM ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00926. STA [BonusText_BaseL],Y ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00927.  
00928. CPY #$0f ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00929. BNE PRG024_A5F0 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00930.  
00931. ; Border upper right ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00932. LDA #TILE15_BORDER_UR ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00933. STA [BonusText_BaseL],Y ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00934.  
00935. PRG024_A5FD: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00936. INY ; Y++ ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00937. TYA ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00938. AND #$0f ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00939. BNE PRG024_A607 ; If not time to place left border, jump to PRG024_A607 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00940.  
00941. LDA #TILE15_BORDER_ML ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00942. BNE PRG024_A60D ; Jump (technically always) to PRG024_A60D ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00943.  
00944. PRG024_A607: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00945. CMP #$0f ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00946. BNE PRG024_A5FD ; If not time to place right border, jump to PRG024_A5FD ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00947.  
00948. LDA #TILE15_BORDER_MR ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00949.  
00950. PRG024_A60D: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00951. STA [BonusText_BaseL],Y ; Store appropriate middle border ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00952.  
00953. CPY #$9f ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00954. BNE PRG024_A5FD ; If Y <> $9F, loop! ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00955.  
00956. INY ; Y++ ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00957.  
00958. ; Lower left border ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00959. LDA #TILE15_BORDER_LL ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00960. STA [BonusText_BaseL],Y ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00961.  
00962. ; Run of 14 middle tiles ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00963. PRG024_A618: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00964. INY ; Y++ ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00965.  
00966. LDA #TILE15_BORDER_LM ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00967. STA [BonusText_BaseL],Y ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00968.  
00969. CPY #$af ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00970. BNE PRG024_A618 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00971.  
00972. ; Lower right border ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00973. LDA #TILE15_BORDER_LR ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00974. STA [BonusText_BaseL],Y ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00975.  
00976. RTS ; Return ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00977.  
00978. ; QBoxOrange_Tiles: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00979. .byte $C9, $CA, $CB, $CC ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00980.  
00981. ; LoadLevel_QBoxOrange: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00982. LDX #$00 ; X = 0 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00983. LDY TileAddr_Off ; Y = TileAddr_Off ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00984. PRG024_A62F: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00985.  
00986. ; Temp_Var1 = 1 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00987. LDA #$01 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00988. STA <Temp_Var1 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00989.  
00990. PRG024_A633: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00991.  
00992. ; Add prize box tile ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00993. LDA QBoxOrange_Tiles,X ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00994. STA [BonusText_BaseL],Y ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00995.  
00996. INY ; Y++ (next tile, DANGEROUS) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00997. INX ; X++ (next prize box tile) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
00998.  
00999. DEC <Temp_Var1 ; Temp_Var1-- ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01000. BPL PRG024_A633 ; While Temp_Var1 >= 0, loop! ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01001.  
01002. ; Next row ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01003. LDA TileAddr_Off ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01004. ADD #16 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01005. STA TileAddr_Off ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01006. TAY ; -> 'Y' ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01007.  
01008. CPX #(QBoxOrange_Tiles_End - QBoxOrange_Tiles) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01009. BNE PRG024_A62F ; While tiles to go, loop! ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01010.  
01011. RTS ; Return ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01012.  
01013. ; QBoxBlue_Tiles: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01014. .byte $87, $88, $89, $8A ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01015.  
01016.  
01017. ; LoadLevel_QBoxBlue: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01018. LDX #$00 ; X = 0 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01019. LDY TileAddr_Off ; Y = TileAddr_Off ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01020. PRG024_A656: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01021.  
01022. ; Temp_Var1 = 1 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01023. LDA #$01 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01024. STA <Temp_Var1 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01025.  
01026. PRG024_A65A: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01027.  
01028. ; Add prize box tile ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01029. LDA QBoxBlue_Tiles,X ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01030. STA [BonusText_BaseL],Y ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01031.  
01032. INY ; Y++ (next tile, DANGEROUS) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01033. INX ; X++ (next prize box tile) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01034.  
01035. DEC <Temp_Var1 ; Temp_Var1-- ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01036. BPL PRG024_A65A ; While Temp_Var1 >= 0, loop! ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01037.  
01038. ; Next row ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01039. LDA TileAddr_Off ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01040. ADD #16 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01041. STA TileAddr_Off ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01042. TAY ; -> 'Y' ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01043.  
01044. CPX #(QBoxBlue_Tiles_End - QBoxBlue_Tiles) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01045. BNE PRG024_A656 ; While tiles to go, loop! ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01046.  
01047. RTS ; Return ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01048.  
01049.  
01050. ;LoadLevel_BonusFloor: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01051.  
01052. ; Temp_Var1 = 1 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01053. LDA #$01 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01054. STA <Temp_Var1 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01055.  
01056. LDY TileAddr_Off ; Y = TileAddr_Off ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01057.  
01058. PRG024_A67B: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01059. LDA LL_ShapeDef ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01060. AND #$0f ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01061. TAX ; X = lower 4 bits of LL_ShapeDef ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01062.  
01063. PRG024_A681: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01064. LDA #TILE15_BRICKFLOOR ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01065. STA [Map_Tile_AddrL],Y ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01066.  
01067. INY ; Y++ (NOT SAFE!) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01068.  
01069. DEX ; X-- ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01070. BPL PRG024_A681 ; While X >= 0, loop ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01071.  
01072. ; Next row ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01073. LDA TileAddr_Off ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01074. ADD #16 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01075. STA TileAddr_Off ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01076. TAY ; -> 'Y' ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01077.  
01078. DEC <Temp_Var1 ; Temp_Var1-- ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01079. BPL PRG024_A67B ; While Temp_Var1 >= 0, loop ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01080.  
01081. RTS ; Return ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01082.  
01083. ; FIXME: Anyone want to claim this? ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01084. ; $C698 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01085.  
01086. ; Y += 16 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01087. TYA ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01088. ADD #16 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01089. TAY ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01090.  
01091. LDA <BonusText_BaseH ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01092. ADC #$00 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01093. STA <BonusText_BaseH ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01094.  
01095. RTS ; Return ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01096.  
01097. ; FIXME: Anyone want to claim this? ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01098. ; $C6A4 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01099. LDA <Temp_Var6 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01100. STA <BonusText_BaseH ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01101.  
01102. LDY TileAddr_Off ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01103. INY ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01104. TYA ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01105. AND #$0f ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01106. BNE PRG024_A6E2 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01107.  
01108. LDY #$00 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01109.  
01110. LDA <Temp_Var15 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01111. AND #$10 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01112. BEQ PRG024_A6BA ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01113.  
01114. INY ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01115.  
01116. PRG024_A6BA: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01117. STY <Temp_Var10 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01118.  
01119. LDA <BonusText_BaseL ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01120. ADD #$b0 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01121. STA <BonusText_BaseL ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01122. LDA <BonusText_BaseH ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01123. ADC <Temp_Var10 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01124. STA <BonusText_BaseH ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01125. STA <Temp_Var6 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01126.  
01127. LDA <Temp_Var16 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01128. AND #$f0 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01129. LSR A ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01130. LSR A ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01131. LSR A ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01132. TAY ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01133.  
01134. INY ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01135. INY ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01136.  
01137. LDA Tile_Mem_Addr+1,Y ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01138. STA <Temp_Var5 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01139.  
01140. INC <Temp_Var5 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01141.  
01142. LDA TileAddr_Off ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01143. AND #$f0 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01144. TAY ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01145.  
01146. PRG024_A6E2: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01147. STY TileAddr_Off ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01148. RTS ; Return ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01149.  
01150.  
01151. ; BonusGame_HostDraw: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01152. LDA Bonus_GameHost ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01153. JSR DynJump ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01154.  
01155. ; THESE MUST FOLLOW DynJump FOR THE DYNAMIC JUMP TO WORK!! ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01156. .word HostToad_Draw ; 0: Standard Toad Host ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01157. .word HostTroopa_DrawWithGameBits ; 1: (Unused, glitched) Koopa Troopa Host w/ (unused, glitched) large [?] and card ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01158. .word HostTroopa_Draw ; 2: (Unused, glitched) Koopa Troopa Host w/o the other thing ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01159. .word HostHammerBro_Draw ; 3: (Unused, glitched) Hammer Bro Host ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01160.  
01161. ; HostToad_Draw: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01162. JSR HostToad_DrawSprites ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01163. RTS ; Return ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01164.  
01165. ; HostTroopa_DrawWithGameBits: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01166. JSR HostTroopa_DrawSprites ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01167.  
01168. LDA #$3f ; <-- denotes starting tile, for other prize boxes?? ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01169. JSR Draw_KTPrizeGameBox ; Draw the Koopa Troopa "Prize" Game box and the prize ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01170.  
01171. RTS ; Return ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01172.  
01173. ; HostTroopa_Draw: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01174. JSR HostTroopa_DrawSprites ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01175. RTS ; Return ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01176.  
01177. ; HostHammerBro_Draw: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01178. JSR HostHammerBro_DrawSprites ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01179. RTS ; Return ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01180.  
01181. ; HostToad_SpriteYs: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01182. .byte $60, $60, $60, $60, $70, $70, $70, $70, $80, $80, $80 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01183.  
01184. ; HostToad_SpriteXs: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01185. .byte $C0, $C8, $D0, $D8, $C0, $C8, $D0, $D8, $C0, $C8, $D0 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01186.  
01187. ; HostToad_DrawSprites: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01188.  
01189. ; Temp_Var11 = $95 (starting pattern of Toad Host sprites) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01190. LDA #$95 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01191. STA <Temp_Var11 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01192.  
01193. LDY #$00 ; Y = 0 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01194. LDX #(HostToad_SpriteYs_End - HostToad_SpriteYs - 1) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01195. PRG024_A727: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01196.  
01197. ; Set Sprite Y of this sprite of the Toad Host ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01198. LDA HostToad_SpriteYs,X ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01199. STA Sprite_RAM+$10,Y ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01200.  
01201. INY ; Y++ (next sprite RAM byte) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01202.  
01203. ; Set pattern of this sprite of the Toad Host ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01204. LDA <Temp_Var11 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01205. STA Sprite_RAM+$10,Y ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01206.  
01207. INY ; Y++ (next sprite RAM byte) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01208.  
01209. ; Set palette of this sprite of the Toad Host ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01210. LDA #SPR_PAL0 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01211. STA Sprite_RAM+$10,Y ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01212.  
01213. INY ; Y++ (next sprite RAM byte) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01214.  
01215. ; Set Sprite X of this sprite of the Toad Host ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01216. LDA HostToad_SpriteXs,X ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01217. STA Sprite_RAM+$10,Y ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01218.  
01219. INY ; Y++ (next sprite RAM byte) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01220.  
01221. ; Temp_Var11 -= 2 (two patterns backward) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01222. DEC <Temp_Var11 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01223. DEC <Temp_Var11 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01224.  
01225. DEX ; X-- ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01226. BPL PRG024_A727 ; While X >= 0, loop ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01227.  
01228. RTS ; Return ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01229.  
01230. ; HostTroopa_SpriteYs: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01231. .byte $60, $60, $60, $70, $70, $70, $70, $80, $80, $80 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01232. ; HostTroopa_SpriteYs_End ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01233.  
01234. ; HostTroopa_SpriteXs: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01235. .byte $C0, $C8, $D0, $C0, $C8, $D0, $D8, $C8, $D0, $D8 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01236.  
01237. ; HostTroopa_DrawSprites: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01238. ; Temp_Var11 = $99 (starting pattern of Koopa Troopa Host sprites) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01239. LDA #$99 ; WRONG! Should be $A9, then he'll display correctly :D ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01240. STA <Temp_Var11 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01241.  
01242. LDY #$00 ; Y = 0 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01243. LDX #(HostTroopa_SpriteYs_End - HostTroopa_SpriteYs - 1) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01244. PRG024_A765: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01245.  
01246. ; Set Sprite Y of this sprite of the Koopa Troopa Host ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01247. LDA HostTroopa_SpriteYs,X ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01248. STA Sprite_RAM+$10,Y ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01249.  
01250. INY ; Y++ (next sprite RAM byte) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01251.  
01252. ; Set pattern of this sprite of the Koopa Troopa Host ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01253. LDA <Temp_Var11 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01254. STA Sprite_RAM+$10,Y ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01255.  
01256. INY ; Y++ (next sprite RAM byte) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01257.  
01258. ; Set palette of this sprite of the Koopa Troopa Host ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01259. LDA #SPR_PAL0 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01260. STA Sprite_RAM+$10,Y ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01261.  
01262. INY ; Y++ (next sprite RAM byte) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01263.  
01264. ; Set Sprite X of this sprite of the Koopa Troopa Host ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01265. LDA HostTroopa_SpriteXs,X ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01266. STA Sprite_RAM+$10,Y ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01267.  
01268. INY ; Y++ (next sprite RAM byte) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01269.  
01270. ; Temp_Var11 -= 2 (two patterns backward) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01271. DEC <Temp_Var11 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01272. DEC <Temp_Var11 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01273.  
01274. DEX ; X-- ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01275. BPL PRG024_A765 ; While X >= 0, loop ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01276.  
01277. RTS ; Return ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01278.  
01279.  
01280. ; HostHammerBro_SpriteYs: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01281. .byte $60, $60, $60, $70, $70, $70, $70, $80, $80, $80, $80 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01282.  
01283. ; HostHammerBro_SpriteXs: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01284. .byte $C0, $C8, $D0, $C0, $C8, $D0, $D8, $C0, $C8, $D0, $D8 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01285.  
01286.  
01287. ; HostHammerBro_DrawSprites: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01288. ; Temp_Var11 = $AF (starting pattern of Koopa Troopa Host sprites) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01289. LDA #$AF ; WRONG! Should be $BF, then he'll display correctly :D ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01290. STA <Temp_Var11 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01291.  
01292. LDY #$00 ; Y = 0 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01293. LDX #(HostHammerBro_SpriteYs_End - HostHammerBro_SpriteYs - 1) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01294. PRG024_A7A5: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01295. ; Set Sprite Y of this sprite of the Hammer Bro Host ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01296. LDA HostHammerBro_SpriteYs,X ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01297. STA Sprite_RAM+$10,Y ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01298.  
01299. INY ; Y++ (next sprite RAM byte) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01300.  
01301. ; Set pattern of this sprite of the Hammer Bro Host ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01302. LDA <Temp_Var11 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01303. STA Sprite_RAM+$10,Y ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01304.  
01305. INY ; Y++ (next sprite RAM byte) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01306.  
01307. ; Set palette of this sprite of the Hammer Bro Host ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01308. LDA #SPR_PAL0 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01309. STA Sprite_RAM+$10,Y ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01310.  
01311. INY ; Y++ (next sprite RAM byte) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01312.  
01313. ; Set Sprite X of this sprite of the Hammer Bro Host ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01314. LDA HostHammerBro_SpriteXs,X ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01315. STA Sprite_RAM+$10,Y ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01316.  
01317. INY ; Y++ (next sprite RAM byte) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01318.  
01319. ; Temp_Var11 -= 2 (two patterns backward) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01320. DEC <Temp_Var11 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01321. DEC <Temp_Var11 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01322.  
01323. DEX ; X-- ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01324. BPL PRG024_A7A5 ; While X >= 0, loop ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01325. RTS ; Return ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01326.  
01327. ; BonusGameBox_SpriteYs: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01328. .byte $70, $70, $70, $70, $80, $80, $80, $80 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01329.  
01330. ; BonusGameBox_SpriteXs: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01331. .byte $70, $78, $80, $88, $70, $78, $80, $88 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01332.  
01333. ; Bonus_KTPrizeFlipBits: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01334. .byte SPR_HFLIP, $00 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01335.  
01336. ; Bonus_KTPrizePattern: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01337. .byte $21, $25, $23, $27 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01338.  
01339. ; Draws the box and the "prize" for Koopa Troopa's "Prize" Game ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01340. ; Draw_KTPrizeGameBox: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01341. STA <Temp_Var11 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01342.  
01343.  
01344. ; Draw the game box first ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01345.  
01346. LDX #(BonusGameBox_SpriteYs_End - BonusGameBox_SpriteYs - 1) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01347. PRG024_A7E1: ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01348.  
01349. ; Set Sprite Y of this sprite ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01350. LDA BonusGameBox_SpriteYs,X ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01351. STA Sprite_RAM+$10,Y ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01352.  
01353. INY ; Y++ (next sprite RAM byte) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01354.  
01355. ; Set pattern of this sprite ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01356. LDA <Temp_Var11 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01357. STA Sprite_RAM+$10,Y ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01358.  
01359. INY ; Y++ (next sprite RAM byte) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01360.  
01361. ; Set palette of this sprite ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01362. LDA #SPR_PAL0 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01363. STA Sprite_RAM+$10,Y ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01364.  
01365. INY ; Y++ (next sprite RAM byte) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01366.  
01367. ; Set Sprite X of this sprite ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01368. LDA BonusGameBox_SpriteXs,X ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01369. STA Sprite_RAM+$10,Y ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01370.  
01371. INY ; Y++ (next sprite RAM byte) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01372.  
01373. ; Temp_Var11 -= 2 (two patterns backward) ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01374. DEC <Temp_Var11 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01375. DEC <Temp_Var11 ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01376.  
01377. DEX ; X-- ; UNUSED COPY FROM PRG022, DELETE DON'T MODIFY 
01378.  
01379. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
01380. ;;;;;;;;;;;;;;;;;;;;; END UNUSED COPY/PASTED CODE ;;;;;;;;;;;;;;;;;;;;; 
01381. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
01382.  
01383.  
01384. Debug_DownUp: .byte 1, -1 ; Add 1 or subtract 1 from current world on debug menu 
01385.  
01386. ; $A802 
01387. .byte $02, $FF, $00, $01 
01388.  
01389. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
01390. ; GraphicsBuf_Prep_And_WaitVSyn2 
01391. ; 
01392. ; This subroutine takes Graphics_Queue and loads and address 
01393. ; from Video_Upd_Table2 into the Video_Upd_Addr, then waits for 
01394. ; a VBlank cycle to occur via reading the VBlank_Tick after 
01395. ; force-setting it to zero. This gets the system into a state 
01396. ; where it can actually apply the update! 
01397. ; 
01398. ; See also GraphicsBuf_Prep_And_WaitVSync in PRG030 
01399. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
01400. GraphicsBuf_Prep_And_WaitVSyn2: 
01401. LDA <Graphics_Queue 
01402. ASL A  
01403. TAY ; Y = Graphics_Queue << 1 
01404.  
01405. ; Get the address where the video update data is 
01406. LDA Video_Upd_Table2,Y 
01407. STA <Video_Upd_AddrL 
01408. LDA Video_Upd_Table2+1,Y 
01409. STA <Video_Upd_AddrH  
01410.  
01411. LDA #$01  
01412. STA <VBlank_TickEn ; Enable the VBlank tick 
01413. LDA #$00  
01414. STA <VBlank_Tick ; Force VBlank_Tick = 0, so we know when a VBlank has occurred 
01415.  
01416. ; Waiting for VBlank... 
01417. PRG024_A81C: 
01418. LDA <VBlank_Tick 
01419. BPL PRG024_A81C 
01420.  
01421. LDA #$00  
01422. STA <VBlank_TickEn ; Disable the VBlank 
01423.  
01424. CLI ; Enable further masked interrupts 
01425. RTS ; Return 
01426.  
01427.  
01428. IntIRQ_TitleEnding: 
01429. STA MMC3_IRQENABLE 
01430.  
01431. ; Some kind of delay loop? 
01432. LDX #$04 ; X = 4 
01433. PRG024_A82B: 
01434. NOP ; ? 
01435. DEX ; X-- 
01436. BNE PRG024_A82B ; While X > 0, loop 
01437.  
01438. LDA PPU_STAT 
01439.  
01440. LDY #$0b 
01441. LDA #$00 
01442. STY PPU_VRAM_ADDR 
01443. STA PPU_VRAM_ADDR 
01444.  
01445. LDA PPU_VRAM_DATA 
01446.  
01447. LDA <PPU_CTL1_Copy  
01448. ORA <PPU_CTL1_Mod ; Combine bits from PPU_CTL1_Copy into PPU_CTL1_Mod 
01449. STA PPU_CTL1 ; Stored to the register! 
01450.  
01451. LDA PPU_STAT 
01452.  
01453. ; H-Scroll locked at 0 
01454. LDA #$00 
01455. STA PPU_SCROLL 
01456.  
01457. ; V-Scroll locked at $EF 
01458. LDA #$ef 
01459. STA PPU_SCROLL 
01460.  
01461. STA MMC3_IRQDISABLE 
01462.  
01463. JMP IntIRQ_Finish_NoDis ; Jump to IntIRQ_Finish_NoDis 
01464.  
01465. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  
01466. ; Video_Misc_Updates2 
01467. ; 
01468. ; This routine is responsible for arbitrary video updates 
01469. ; 
01470. ; Loads data as specified from table Video_Upd_Table2 in PRG024 (see Video_Upd_Table in PRG030 for format!) 
01471. ; Cloned in its entirety in PRG026 (i.e. Video_Misc_Updates) 
01472. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  
01473. Video_Misc_Updates2: 
01474. LDY #$00 ; Start at offset 0 
01475. LDA [Video_Upd_AddrL],Y ; Get next byte from data 
01476. BNE PRG024_A860 ; If not $00 (terminator), process it @ PRG024_A860 
01477. RTS ; Return 
01478.  
01479. PRG024_A860: 
01480. LDX PPU_STAT ; Flush video 
01481.  
01482. STA PPU_VRAM_ADDR ; Store byte into video address high 
01483. INY ; Y++ 
01484. LDA [Video_Upd_AddrL],Y ; Get next byte 
01485. STA PPU_VRAM_ADDR ; Store byte into video address low 
01486.  
01487. INY ; Y++ 
01488. LDA [Video_Upd_AddrL],Y ; Get next byte... 
01489.  
01490. ASL A ; Its uppermost bit dictates whether to use horizontal (1B) or vertical (32B) advancement 
01491. PHA ; Save A 
01492.  
01493. LDA <PPU_CTL1_Copy ; Get PPU_CTL1 settings 
01494. ORA #$04 ; Set PPU update vertical (each write advances by 32) 
01495. BCS PRG024_A879 ; If bit 7 was set, jump to PRG026_B2B2 
01496. AND #$fb ; Otherwise, use horizontal updates! (clears vertical bit) 
01497.  
01498. PRG024_A879: 
01499. STA PPU_CTL1 ; Update PPU_CTL1 
01500. STA <PPU_CTL1_Copy ; Update PPU_CTL1_Copy 
01501.  
01502. PLA ; Restore A 
01503.  
01504. ASL A ; Check next bit... 
01505. BCC PRG024_A885 ; If not set, jump to PRG026_B2BE 
01506. ORA #$02 ; Otherwise, remaining value gets bit 1 set (forces skip of first increment) 
01507. INY ; Y++  
01508.  
01509. PRG024_A885: 
01510. ; Restore remainder of byte read (6-bits for value) 
01511. LSR A 
01512. LSR A 
01513. TAX ; Keep it in X 
01514.  
01515. ; The following will continuously write bytes from the stream 
01516. ; directly into the PPU 'X+1' times 
01517. PRG024_A888: 
01518. BCS PRG024_A88B ; If carry set, jump to PRG026_B2C4 
01519. INY ; Y++ 
01520.  
01521. PRG024_A88B: 
01522. LDA [Video_Upd_AddrL],Y ; Get next byte 
01523. STA PPU_VRAM_DATA ; Store into PPU 
01524. DEX ; X-- 
01525. BNE PRG024_A888 ; While X <> 0, loop!  
01526.  
01527. ; This advances the current position of the pointer so 'Y' can go 
01528. ; back to zero and we begin again... 
01529. INY ; Y++ 
01530. TYA ; A = Y 
01531. ADD <Video_Upd_AddrL 
01532. STA <Video_Upd_AddrL 
01533. LDA <Video_Upd_AddrH 
01534. ADC #$00  
01535. STA <Video_Upd_AddrH ; Entire video address value has 'Y' added to it 
01536. JMP Video_Misc_Updates2 ; Jump back to start to process next command or terminate! 
01537.  
01538. Title_Obj_InitIdx: .byte $02, $00, $01, $03, $04, $05 ; Indexes into Title_ObjStates, inits to state 1 in this order 
01539. Title_ObjInitIdx_Time: .byte $03, $03, $06, $12, $11, $00 ; Timing values to delay the next Title_ObjInitIdx 
01540.  
01541. Do_Title_Screen: ; $A8AF 
01542. JSR Sprite_RAM_Clear ; Clear Sprite RAM Copy 
01543. JSR Reset_PPU_Clear_Nametables 
01544.  
01545. ; Basically just hiding everything 
01546. LDA #$00 
01547. STA PPU_CTL1 
01548. STA PPU_CTL2 
01549.  
01550. ; Clear the first 245 bytes of RAM 
01551. LDX #$f5 ; X = 245 
01552. PRG024_A8BF: 
01553. LDA #$00 ; A = $00 
01554. STA <Temp_Var1,X ; Clear this byte 
01555. DEX ; X-- 
01556. BNE PRG024_A8BF ; Loop... 
01557.  
01558.  
01559. ; Clearing memory used by various title screen objects 
01560. LDX #(Title_ObjFrame - Title_MLAccelCnt + 6) 
01561. PRG024_A8C8: 
01562. LDA #$00 ; A = 0 
01563. STA Title_MLAccelCnt,X ; Clear this byte 
01564. DEX ; X-- 
01565. BPL PRG024_A8C8 ; Loop while X >= 0... 
01566.  
01567. ; Set Mario and Luigi's lives to 4 
01568. LDA #$04 
01569. STA Player_Lives 
01570. STA Player_Lives+1 
01571.  
01572. LDA #$ff 
01573. STA <Title_ObjInitIdx ; Title_ObjInitIdx = $FF (Should be 0 - 5, does this have an early increment or something?) 
01574.  
01575. ; Set Mario and Luigi's Y position to 160 
01576. LDA #160 
01577. STA <Title_ObjY 
01578. STA <Title_ObjY+1 
01579.  
01580. LDA #240 
01581. STA <Title_ObjX ; Set Mario's X coordinate to 240 
01582.  
01583. LDA #$00 
01584. STA <Title_ObjX+1 ; Set Luigi's X coordinate to 0 
01585.  
01586. ; Set Mario and Luigi to "Big" power level 
01587. LDA #$01 
01588. STA <Title_ObjMLPower  
01589. STA <Title_ObjMLPower+1  
01590.  
01591. LDA #$88 
01592. STA Random_Pool ; Seed the randomizer 
01593.  
01594. LDA #%00101000 
01595. STA PPU_CTL1 ; use 8x16 sprites, sprites use PT2 
01596. STA <PPU_CTL1_Copy ; Sync with PPU_CTL1_Copy 
01597.  
01598. JSR Title_Display_Curtain ; Put up the curtain! 
01599.  
01600. ; Load the palette and checkerboard floor pattern 
01601. LDA #$01 ; A = 1 
01602. ASL A ; A = 2 
01603. TAY ; Y = 2 (Palette + Checkerboard floor) 
01604. LDA Video_Upd_Table2,Y 
01605. STA <Video_Upd_AddrL 
01606. LDA Video_Upd_Table2+1,Y 
01607. STA <Video_Upd_AddrH 
01608. JSR Video_Misc_Updates2 
01609.  
01610. ; Some kind of hardware thing perhaps 
01611. LDA #$00 
01612. STA PPU_VRAM_ADDR 
01613. STA PPU_VRAM_ADDR 
01614. LDA #$10  
01615. STA PPU_VRAM_ADDR 
01616. STA PPU_VRAM_ADDR 
01617. LDA #$00  
01618. STA PPU_VRAM_ADDR 
01619. STA PPU_VRAM_ADDR 
01620. LDA #$10  
01621. STA PPU_VRAM_ADDR  
01622. STA PPU_VRAM_ADDR  
01623.  
01624. ; Wait for V-Blank to end 
01625. PRG024_A930: 
01626. LDA PPU_STAT 
01627. AND #$80  
01628. BNE PRG024_A930  
01629.  
01630. LDA #%10101000 
01631. STA PPU_CTL1 ; Generate VBlank Resets, use 8x16 sprites, sprites use PT2 
01632. STA <PPU_CTL1_Copy ; Keep PPU_CTL1_Copy in sync! 
01633.  
01634. LDA #%00011110 
01635. STA <PPU_CTL2_Copy ; Setup for: No BG or sprite clipping, show BG and sprites 
01636.  
01637. LDA #53 
01638. STA <Title_Ticker ; Set Title_Ticker = 53 (initial delay prior to curtain raise) 
01639.  
01640. PRG024_A946: 
01641. ; Used for VSync 
01642. JSR GraphicsBuf_Prep_And_WaitVSyn2 
01643.  
01644. LDA <Pad_Input 
01645. AND #PAD_START 
01646. BEQ PRG024_A955 ; If Player is NOT pressing Start, jump to PRG024_A955 
01647.  
01648. ; Player pressed START -- skips rest of intro, if any 
01649. LDA #$06  
01650. STA <Title_State ; Title_State = 6  
01651. BEQ PRG024_A959 ; Jump technically never?? to skip title ticker 
01652.  
01653. PRG024_A955:  
01654. DEC <Title_Ticker ; Decrement title tick counter 
01655. BPL PRG024_A946 ; If >= 0, loop... 
01656.  
01657. PRG024_A959: 
01658. ; Title_Ticker = 0... 
01659.  
01660. ; Used for VSync 
01661. JSR GraphicsBuf_Prep_And_WaitVSyn2 
01662.  
01663. ; There are 6 objects on the title screen that need their states set; if this value hits 6, we're done with that 
01664. LDY <Title_ObjInitIdx ; Y = Title_ObjInitIdx 
01665. CPY #$06  
01666. BGE PRG024_A976 ; If Title_ObjInitIdx >= 6, jump to PRG024_A976 
01667.  
01668. ; Title_ObjInitIdx < 6... (more objects to go yet) 
01669.  
01670. ; Waiting for event timer to run out 
01671. DEC <Title_ObjInitDly ; Title_ObjInitDly-- 
01672. BNE PRG024_A976 ; If Title_ObjInitDly > 0, jump to PRG024_A976 
01673.  
01674. ; Load next delay for object init 
01675. ; Title_ObjInitIdx is 0 to 5 
01676. LDA Title_ObjInitIdx_Time,Y 
01677. STA <Title_ObjInitDly ; Title_ObjInitDly = Title_ObjInitIdx_Time[Title_ObjInitIdx] 
01678.  
01679. LDA Title_Obj_InitIdx,Y 
01680. TAY ; Y = Title_Obj_InitIdx[Title_ObjInitIdx] 
01681.  
01682. LDA #$01  
01683. STA Title_ObjStates,Y ; Title_ObjStates[Y] = 1 Set title screen object to state 1 
01684.  
01685. ; Doing next object... 
01686. INC <Title_ObjInitIdx ; Title_ObjInitIdx++ 
01687.  
01688. PRG024_A976: 
01689. JSR Title_DoState ; Do whatever this state of the title screen does 
01690.  
01691. ; Title_ResetTrig is the trigger to reset the title screen 
01692. LDA <Title_ResetTrig 
01693. BEQ PRG024_A980 ; If Title_ResetTrig = 0, jump to PRG024_A980 
01694.  
01695. JMP Do_Title_Screen ; Reset title screen... 
01696.  
01697. PRG024_A980: 
01698. ; Reset trigger is not set... 
01699.  
01700. LDA <Title_State 
01701. CMP #$05  
01702. BNE PRG024_A959 ; If Title_State <> 5, jump to PRG024_A959 
01703.  
01704. ; When Title_State = 5, we're about to finish and go off to the map! 
01705.  
01706. ; Performs a clearing loop starting from World_Map_Y + $80 ($F5) down and through 
01707. LDX #$80 ; Clearing $80 bytes 
01708. LDA #$00 ; Clear value 
01709. PRG024_A98A: 
01710. STA <World_Map_Y,X ; Clear this byte 
01711. DEX ; X-- 
01712. BPL PRG024_A98A ; X >= 0, loop! 
01713.  
01714. RTS ; Return 
01715.  
01716. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
01717. ; Title_Display_Curtain 
01718. ; 
01719. ; You know that nifty "bowser" curtain  
01720. ; on the title screen? Here it is... 
01721. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
01722. Title_Display_Curtain: 
01723. LDA PPU_STAT ; read PPU status to reset the high/low latch 
01724.  
01725. ; Set VRAM_ADDR to $2000 (Nametable 0) 
01726. LDA #$20 
01727. STA PPU_VRAM_ADDR 
01728. LDA #$00 
01729. STA PPU_VRAM_ADDR 
01730.  
01731. LDX #$02 ; X = 2 (performs loop twice) 
01732. LDA #$08 ; A = 8 (the Bowser curtain tile) 
01733. PRG024_A9A1: 
01734. LDY #$ff ; Y = $FF (fill count) 
01735. PRG024_A9A3: 
01736. STA PPU_VRAM_DATA ; Write $08/$09 to this byte in the VRAM 
01737. EOR #$01 ; Toggle between $08/$09 
01738. DEY ; Y-- 
01739. BNE PRG024_A9A3 ; Loop while Y not zero 
01740. STA PPU_VRAM_DATA ; One more write since we come up one short 
01741. EOR #$01 ; And its cooresponding flip 
01742. DEX ; X-- 
01743. BPL PRG024_A9A1 ; Loop while X >= 0... 
01744.  
01745. RTS ; Return! 
01746.  
01747.  
01748. Title_DoState: 
01749.  
01750. ; Clear the queues for Mario/Luigi 
01751. LDA #$00 
01752. STA <Title_ObjMLQueue 
01753. STA <Title_ObjMLQueue+1 
01754.  
01755. LDA <Title_State  
01756. JSR DynJump ; Dynamically jump based on Title_State... 
01757.  
01758. ; THESE MUST FOLLOW DynJump FOR THE DYNAMIC JUMP TO WORK!! 
01759. .word TitleState_CurtainRaise ; 00 - Curtain raise 
01760. .word TitleState_OpeningSequence ; 01 - Opening sequence (updates Mario/Luigi's action scripts, the title screen objects, makes the big '3' glow...) 
01761. .word Title_PrepForMenu ; 02 - Prepares some variables before going into 1P/2P menu mode 
01762. .word Title_Do1P2PMenu ; 03 - Runs the 1P/2P menu with the koopas 
01763. .word Title_PrepForWorldMap ; 04 - Final data initialization before going to world map 
01764. .word Title_DoNothing ; 05 - just RTS, bootstraps world map 
01765. .word Title_IntroSkip ; 06 - Skip intro sequence (cleanly jump to 1P/2P menu) 
01766. .word Title_DebugMenu ; 07 - Debug menu 
01767.  
01768. TitleState_CurtainRaise: 
01769. LDY #$01 ; Y = 1 
01770.  
01771. PRG024_A9D1: 
01772. ; Moving curtain up... 
01773. INC <Vert_Scroll ; Vert_Scroll++ 
01774. LDA <Vert_Scroll  
01775. CMP #208 
01776. BEQ Title_LoadGraphics ; If Vert_Scroll = 208, jump to Title_LoadGraphics 
01777.  
01778. ; Still haven't risen all the way... 
01779.  
01780. CMP #78  
01781. BNE PRG024_A9E4 ; If Vert_Scroll <> 78, jump to PRG024_A9E4 
01782.  
01783. ; Special stuff when curtain (Vert_Scroll) hits 78 
01784. LDA #$40 
01785. STA <Title_ObjMLStop ; Title_ObjMLStop = $40 (holds Mario/Luigi in place at first so they get a "running start") 
01786. STA Title_MLHoldTick ; Title_MLHoldTick = $40 (ticks until they are released) 
01787.  
01788. PRG024_A9E4: 
01789. DEY ; Y-- 
01790. BPL PRG024_A9D1 ; If Y >= 0, jump to PRG024_A9D1 
01791.  
01792. LDA <Title_ObjMLStop 
01793. BEQ PRG024_A9EE ; If Title_ObjMLStop = 0, jump to PRG024_A9EE (i.e. don't call Title_UpdateAllObjs) 
01794. JSR Title_UpdateAllObjs ; Update all objects! 
01795.  
01796. PRG024_A9EE: 
01797. LDA <Pad_Input 
01798. AND #PAD_START 
01799. BEQ PRG024_A9F8 ; If Player is NOT pressing start, jump to PRG024_A9F8 (RTS) 
01800.  
01801. LDA #$06  
01802. STA <Title_State ; Title_State = 6 (skip intro) 
01803.  
01804. PRG024_A9F8: 
01805. RTS ; Return 
01806.  
01807. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
01808. ; Title_LoadGraphics 
01809. ; 
01810. ; Loads several items from Video_Upd_Table2 in PRG025 
01811. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
01812. Title_LoadGraphics: 
01813. LDA #$02 
01814. STA <Title_EventIndex ; Title_EventIndex = $02 (first action taken [load the logo] and continue doing stuff!) 
01815.  
01816. LDA #$08 
01817. STA <Title_EventGrafX ; Title_EventGrafX = $08 (first item to load from Video_Upd_Table2 in PRG025, up to item $23; see Title_LoadSMB3) 
01818.  
01819. INC <Title_State ; Next title state... 
01820.  
01821. LDA #$00  
01822. STA <Title_ObjMLStop ; Title_ObjMLStop = 0 (releases Mario and Luigi) 
01823.  
01824. RTS ; Return 
01825.  
01826.  
01827. ; This is Mario and Luigi's "action script", which is a simple script to 
01828. ; dictate their actions on the title screen... 
01829. ; NOTE: The other objects are mostly autonomous, not scripted. They respond to 
01830. ; hardcoded values, timers, or flags from this, but that's it... 
01831. ; 
01832. ; Format: 
01833. ; [DELAY][QUEUE] 
01834. ; 
01835. ; Where: 
01836. ; [DELAY] is normally a tick count until the next event, EXCEPT: 
01837. ; 
01838. ; Mario's script: 
01839. ; - $FE to increment Title_State and reset Title_MActScriptPos 
01840. ; - $FF to set Title_EventIndex to the value that follows it 
01841. ; 
01842. ; Luigi's script: 
01843. ; - $FF is like Mario's $FE, i.e. Title_LActScriptPos = 0, but does not change Title_State 
01844. ; [QUEUE] is normally a value pumped into Title_MActScriptDirSet (buffer) and Title_ObjMLQueue (acted upon), 
01845. ; except for the prior $FE and $FF values as follows: 
01846. ; - For [CMD] $FE (Mario) or $FF (Luigi), it is not used (since Title_MActScriptPos is set to zero) 
01847. ; - For [CMD] $FF (Mario), it is the Title_EventIndex value to set 
01848.  
01849. ; Mario's action script 
01850. Title_MActionScript: 
01851. .byte $4C, $02, $14, $00, $20, $04, $03, $00, $FF, $03, $BD, $00, $30, $08, $17, $80 
01852. .byte $05, $00, $23, $82, $02, $00, $25, $80, $20, $00, $35, $01, $05, $10, $04, $01 
01853. .byte $05, $00, $04, $01, $05, $00, $04, $01, $05, $00, $04, $01, $05, $00, $04, $01 
01854. .byte $50, $00, $42, $02, $01, $80, $12, $02, $05, $01, $20, $00, $10, $01, $05, $20 
01855. .byte $20, $01, $05, $40, $C0, $00, $02, $02, $10, $00, $36, $41, $38, $42, $60, $00 
01856. .byte $60, $51, $FF, $08, $10, $00, $FE, $00 
01857.  
01858. ; Luigi's action script 
01859. Title_LActionScript: 
01860. .byte $2C, $01, $50, $80, $F0, $01, $90, $00, $70, $00, $10, $02, $10, $22, $09, $00 
01861. .byte $15, $02, $34, $00, $02, $42, $90, $00, $65, $01, $F0, $00, $FF 
01862.  
01863. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
01864. ; Title_3Glow 
01865. ; 
01866. ; Constantly pushes a palette adjustment into the 
01867. ; graphics buffer to enable the big '3' on the title 
01868. ; screen to glow... 
01869. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
01870. Title_3Glow: 
01871. DEC <Title_Ticker ; Title_Ticker-- 
01872. BPL PRG024_AAA9 ; If Title_Ticker >= 0, jump to PRG024_AAA9 (RTS) 
01873.  
01874. LDA #$04  
01875. STA <Title_Ticker ; Title_Ticker = 4 
01876.  
01877. LDY <Title_3GlowIndex ; Y = current 3glow index 
01878. LDA Title_3GlowColors,Y ; Get the cooresponding color 
01879.  
01880. STA Graphics_Buffer+3 ; Put that into the graphics buffer 
01881.  
01882. ; Address the palette 
01883. LDA #$3f  
01884. STA Graphics_Buffer 
01885. LDA #$0e  
01886. STA Graphics_Buffer+1 
01887.  
01888. ; 1 byte and terminator 
01889. LDA #$01  
01890. STA Graphics_Buffer+2  
01891. LDA #$00  
01892. STA Graphics_Buffer+4  
01893.  
01894. ; Title_3GlowIndex goes from 0 - 7, round and round 
01895. INC <Title_3GlowIndex 
01896. LDA <Title_3GlowIndex 
01897. AND #$07  
01898. STA <Title_3GlowIndex 
01899.  
01900. PRG024_AAA9: 
01901. RTS ; Return 
01902.  
01903. ; These are the color values used by Title_3Glow for the big '3' 
01904. Title_3GlowColors: 
01905. .byte $27, $17, $07, $17, $27, $37, $37, $27 
01906.  
01907.  
01908. TitleState_OpeningSequence: 
01909.  
01910. ; Update Mario's action script 
01911. DEC <Title_MActScriptDelay ; Title_MActScriptDelay-- 
01912. LDA <Title_MActScriptDelay 
01913. CMP #$ff 
01914. BNE PRG024_AABD ; If ticks remain, jump to PRG024_AABD 
01915.  
01916. JSR Title_MAS_DoNextEvent ; Performs an event or sets the Mario action queue 
01917.  
01918. PRG024_AABD: 
01919.  
01920. ; Update Luigi's action script 
01921. DEC <Title_LActScriptDelay ; Title_LActScriptDelay-- 
01922. LDA <Title_LActScriptDelay  
01923. CMP #$ff  
01924. BNE PRG024_AAC8 ; If ticks remain, jump to PRG024_AAC8 
01925.  
01926. JSR Title_LAS_DoNextEvent ; Performs an event or sets the Luigi action queue 
01927.  
01928. PRG024_AAC8: 
01929.  
01930. ; Copy MLDir settings in... 
01931. LDA <Title_MActScriptDirSet 
01932. STA <Title_ObjMLDir  
01933. LDA <Title_LActScriptDirSet 
01934. STA <Title_ObjMLDir+1  
01935.  
01936. JSR Title_DoEvent ; Perform current title screen events 
01937. JSR Title_UpdateAllObjs ; Update all title screen objects 
01938.  
01939. LDA <Title_3GlowFlag 
01940. BEQ PRG024_AADD ; If not glowing, jump to PRG024_AADD 
01941.  
01942. JSR Title_3Glow ; Make the big '3' glow! 
01943.  
01944. PRG024_AADD: 
01945. LDA <Pad_Input  
01946. AND #PAD_START 
01947.  
01948. BEQ PRG024_AAF3 ; If Player is not pressing START, jump to PRG024_AAF3 
01949.  
01950. ; Player pressed start... 
01951. LDA <Title_UnusedFlag 
01952. BNE PRG024_AAED ; If Title_UnusedFlag is set, jump to PRG024_AAED 
01953.  
01954. LDA #$06 
01955. STA <Title_State 
01956. BNE PRG024_AAF3 ; Title_State = 6 (skip) 
01957.  
01958. PRG024_AAED: 
01959. INC <Title_State ; Next title state... 
01960.  
01961. LDA #$07 
01962. STA <Graphics_Queue ; Graphics_Queue = 7 (load the 1P/2P select menu) 
01963.  
01964. PRG024_AAF3: 
01965. RTS ; Return 
01966.  
01967.  
01968. Title_IntroSkip: 
01969. LDA #$00  
01970. STA <Vert_Scroll ; Vert_Scroll = 0 
01971.  
01972. ; Disable display a second 
01973. LDA #$00 
01974. STA PPU_CTL1 
01975. STA PPU_CTL2 
01976.  
01977. ; This will load the title graphics in reverse, $22 to $6 
01978. LDA #$22  
01979. STA <Title_EventGrafX ; Title_EventGrafX = $22 (TitleScreen_Part27) 
01980.  
01981. PRG024_AB04: 
01982. LDA <Title_EventGrafX 
01983. ASL A  
01984. TAY ; Y = Title_EventGrafX << 1 (2 byte index) 
01985.  
01986. ; Get address, store into [Video_Upd_AddrH][Video_Upd_AddrL] 
01987. LDA Video_Upd_Table2,Y 
01988. STA <Video_Upd_AddrL  
01989. LDA Video_Upd_Table2+1,Y 
01990. STA <Video_Upd_AddrH  
01991.  
01992. JSR Video_Misc_Updates2 ; Load those graphics! 
01993.  
01994. DEC <Title_EventGrafX ; Title_EventGrafX-- 
01995.  
01996. LDA <Title_EventGrafX 
01997. CMP #$06  
01998. BGE PRG024_AB04 ; If Title_EventGrafX >= 6, loop! 
01999.  
02000. LDA #%00011000 
02001. STA <PPU_CTL2_Copy ; Show BG + sprites 
02002.  
02003. LDA #$02  
02004. STA <Title_State ; Title_State = 2 (prep for 1P/2P menu) 
02005. RTS ; Return 
02006.  
02007.  
02008. Title_MAS_DoNextEvent: 
02009. LDA #$00  
02010. STA <Title_MActScriptDirSet ; Clear Title_MActScriptDirSet  
02011. STA <Title_ObjMLQueue ; Clear Mario's action queue 
02012.  
02013. LDY <Title_MActScriptPos ; Get current position in action script 
02014. LDA Title_MActionScript,Y ; Get byte from action script 
02015.  
02016. CMP #$ff  
02017. BEQ Title_MAS_CmdFF ; If equal to $FF (set Title_EventIndex), jump to Title_MAS_CmdFF 
02018.  
02019. CMP #$fe  
02020. BEQ Title_MAS_CmdFE ; If equal to $FE, jump to Title_MAS_CmdFE 
02021.  
02022. ; Not $FF or $FE... 
02023.  
02024. ; Otherwise, just a tick delay 
02025. STA <Title_MActScriptDelay ; Store into Title_MActScriptDelay 
02026. INY ; Y++ 
02027.  
02028. LDA Title_MActionScript,Y ; Get next byte 
02029. STA <Title_MActScriptDirSet ; Store into Title_MActScriptDirSet 
02030. STA <Title_ObjMLQueue ; ... and into the Queue 
02031.  
02032. ; Two bytes read, so Title_MActScriptPos += 2 
02033. INC <Title_MActScriptPos 
02034. INC <Title_MActScriptPos 
02035. RTS ; Return...! 
02036.  
02037. Title_MAS_CmdFF: 
02038. ; Action script command $FF (set Title_EventIndex)... 
02039.  
02040. INY  
02041. LDA Title_MActionScript,Y ; Get next byte 
02042. STA <Title_EventIndex ; Store this into Title_EventIndex 
02043.  
02044. ; Title_MActScriptPos += 2 
02045. INC <Title_MActScriptPos 
02046. INC <Title_MActScriptPos 
02047.  
02048. LDA #$00 
02049. STA <Title_MActScriptDelay ; Title_MActScriptPos = 0 
02050.  
02051. RTS ; Return 
02052.  
02053. Title_MAS_CmdFE: 
02054. ; Action script command $FE (increment Title_State, reset Title_MActScriptPos)... 
02055.  
02056. INC <Title_State ; Next title state... 
02057.  
02058. LDA #$00 
02059. STA <Title_MActScriptPos ; Set Title_MActScriptPos = 0 
02060.  
02061. RTS ; Return 
02062.  
02063.  
02064. Title_LAS_DoNextEvent: 
02065. LDA #$00 
02066. STA <Title_LActScriptDirSet ; Clear Title_LActScriptDirSet  
02067. STA <Title_ObjMLQueue+1 ; Clear Luigi's action queue 
02068.  
02069. LDY <Title_LActScriptPos ; Get current position in action script 
02070. LDA Title_LActionScript,Y ; Get byte from action script 
02071.  
02072. CMP #$ff 
02073. BEQ Title_LAS_CmdFF ; If equal to $FF (set Title_EventIndex), jump to Title_LAS_CmdFF 
02074.  
02075.  
02076. ; Otherwise, just a tick delay 
02077. STA <Title_LActScriptDelay ; Store into Title_LActScriptDelay 
02078. INY ; Y++ 
02079.  
02080. LDA Title_LActionScript,Y ; Get next byte 
02081. STA <Title_LActScriptDirSet ; Store into Title_LActScriptDirSet 
02082. STA <Title_ObjMLQueue+1 ; ... and into the Queue 
02083.  
02084. ; Two bytes read, so Title_LActScriptPos += 2 
02085. INC <Title_LActScriptPos 
02086. INC <Title_LActScriptPos 
02087. RTS ; Return...! 
02088.  
02089.  
02090. Title_LAS_CmdFF: 
02091.  
02092. ; Title_LActScriptPos = 0 
02093. LDA #$00 
02094. STA <Title_LActScriptPos 
02095.  
02096. RTS ; Return 
02097.  
02098.  
02099. Title_DoEvent: 
02100. LDA <Title_EventIndex ; Get Title_EventIndex 
02101. JSR DynJump ; Dynamically jump based on the value of Title_EventIndex... 
02102.  
02103. ; THESE MUST FOLLOW DynJump FOR THE DYNAMIC JUMP TO WORK!! 
02104. .word Title_DoNothing ; 00 - Do nothing 
02105. .word Title_DoNothing ; 01 - Do nothing (never used I don't think!) 
02106. .word Title_LoadSMB3 ; 02 - Load title screen into the nametable 
02107. .word Title_Drop ; 03 - "Drops" the logo onto the screen 
02108. .word Title_LogoShakeUp ; 04 - Logo shake up 
02109. .word Title_LogoShakeDown ; 05 - Logo shake down, and check if we're done doing that 
02110. .word Title_InitObjects ; 06 - Prepare all title screen objects 
02111. .word Title_PalFadeIn ; 07 - Palette fade in 
02112. .word Title_DrawMenu ; 08 - Adds the 1P/2P select menu to the title screen 
02113. .word Title_DoNothing ; 09 - Do nothing, we're done! 
02114.  
02115. Title_DoNothing: 
02116. RTS  
02117.  
02118. ; Title_LoadSMB3 
02119. ; 
02120. ; This loads the title screen, specifically items $08 thru $23 of Video_Upd_Table2 
02121. ; The title screen is too complex to be loaded in one shot, so it's done over 
02122. ; several frames, in pieces 
02123. Title_LoadSMB3: 
02124.  
02125. ; Queue next item to load 
02126. LDA <Title_EventGrafX 
02127. STA Graphics_Queue  
02128.  
02129. ; Increment Title_EventGrafX 
02130. INC <Title_EventGrafX  
02131.  
02132.  
02133. LDA <Title_EventGrafX  
02134. CMP #$23 
02135. BNE PRG024_ABAC ; If not at item $23 yet, keep going... 
02136.  
02137. ; We're done, stop doing background event! 
02138. LDA #$00  
02139. STA <Title_EventIndex 
02140.  
02141. PRG024_ABAC: 
02142. RTS ; Return 
02143.  
02144.  
02145. ; Title_Drop 
02146. ; 
02147. ; The logo comes falling down... 
02148. Title_Drop: 
02149. LDY #$04 
02150.  
02151. ; Basically drops logo 4 pixels at a time, with a precise safety catch! 
02152. PRG024_ABAF: 
02153. DEC <Vert_Scroll 
02154. LDA <Vert_Scroll 
02155. BEQ PRG024_ABB9 ; If Vert_Scroll = 0, jump to PRG024_ABB9 
02156. DEY ; Y-- 
02157. BPL PRG024_ABAF ; If Y >= 0, loop! 
02158.  
02159. RTS ; Return 
02160.  
02161. PRG024_ABB9: 
02162. ; The logo has landed! 
02163.  
02164. LDA #$10  
02165. STA <Title_Ticker ; Title_Ticker = $10 
02166.  
02167. INC <Title_EventIndex ; Perform next event... 
02168. RTS ; Return... 
02169.  
02170. ; Title_LogoShakeUp 
02171. ; 
02172. ; Shake the logo up, go to the next state 
02173. Title_LogoShakeUp: 
02174.  
02175. ; Subtract 2 from Vert_Scroll 
02176. LDA <Vert_Scroll 
02177. SUB #$02  
02178. STA <Vert_Scroll 
02179.  
02180. INC <Title_EventIndex ; Shake down next 
02181. RTS ; Return! 
02182.  
02183. ; Title_LogoShakeDown 
02184. ; 
02185. ; Shake the logo down, go to the previous state,  
02186. ; or see if we're done yet... 
02187. Title_LogoShakeDown: 
02188.  
02189. ; Add 2 to Vert_Scroll 
02190. LDA <Vert_Scroll 
02191. ADD #$02  
02192. STA <Vert_Scroll 
02193.  
02194. DEC <Title_EventIndex ; Shake up next 
02195.  
02196. DEC <Title_Ticker ; Title_Ticker-- 
02197. BPL PRG024_ABE3 ; If we're not done yet, jump to PRG024_ABE3 (no change, shake away) 
02198.  
02199. ; Shaking is complete! 
02200. INC <Title_EventIndex 
02201. INC <Title_EventIndex ; Title_EventIndex += 2 (to make up for the decrement above), moving on to object init... 
02202.  
02203. LDA #$03  
02204. STA <Title_EventGrafX ; Title_EventGrafX = 3 (to fade in the palette, starting with Video_Upd_Table2 item $03) 
02205.  
02206. LDA #$02  
02207. STA <Title_Ticker ; Title_Ticker = 2 
02208.  
02209. PRG024_ABE3: 
02210. RTS ; Return 
02211.  
02212.  
02213. ; Title_InitObjects 
02214. ; 
02215. ; Queues the title screen objects to prepare themselves for appearing 
02216. Title_InitObjects: 
02217. DEC <Title_Ticker ; Title_Ticker-- 
02218. BPL PRG024_ABF6 ; If Title_Ticker >= 0, do nothing yet... 
02219.  
02220. ; Preparing to initialize objects that fall in the beginning... 
02221. LDA #$00 
02222. STA <Title_ObjInitIdx ; Title_ObjInitIdx = 0 
02223.  
02224. LDA #$01 
02225. STA <Title_ObjInitDly ; Title_ObjInitDly = 1 
02226.  
02227. INC <Title_EventIndex ; On to the next event (the palette fade-in) 
02228.  
02229. LDA #$16 
02230. STA <Title_Ticker ; Title_Ticker = 16 
02231.  
02232. PRG024_ABF6: 
02233. RTS ; Return 
02234.  
02235.  
02236. ; Title_PalFadeIn 
02237. ; 
02238. ; Loads palette colors to produce a "fade in" effect,  
02239. ; specifically items $03 thru $06 of Video_Upd_Table2 
02240. Title_PalFadeIn: 
02241. DEC <Title_Ticker ; Title_Ticker-- 
02242. BPL PRG024_AC0F ; If Title_Ticker >= 0, do nothing yet... 
02243.  
02244. LDA #$04 
02245. STA <Title_Ticker ; Title_Ticker = 4 
02246.  
02247. LDA <Title_EventGrafX  
02248. STA <Graphics_Queue ; Graphics_Queue = Title_EventGrafX 
02249. CMP #$06  
02250. BNE PRG024_AC10 ; If not at item $06 yet, keep going... 
02251.  
02252. ; Done with the fade in! 
02253. LDA #$00  
02254. STA <Title_EventIndex ; Stop doing anything 
02255.  
02256. LDA #$01  
02257. STA <Title_3GlowFlag ; Title_3GlowFlag = 1 
02258.  
02259. PRG024_AC0F: 
02260. RTS ; Return 
02261.  
02262. PRG024_AC10: 
02263. INC <Title_EventGrafX ; Next palette fade 
02264. RTS ; Return  
02265.  
02266.  
02267. ; Title_DrawMenu 
02268. ; 
02269. ; Loads in the tiles for the 1/2 PLAYER GAME and Nintendo copyright 
02270. Title_DrawMenu: 
02271. LDA #$07 
02272. STA <Graphics_Queue 
02273. INC <Title_EventIndex ; Do next thing (which is actually nothing; on purpose??) 
02274. RTS ; Return... 
02275.  
02276. Title_PrepForMenu: 
02277.  
02278. ; Clear objects 1-4 states 
02279. LDA #$00 
02280. STA <Title_ObjStates+1 
02281. STA <Title_ObjStates+2  
02282. STA <Title_ObjStates+3  
02283. STA <Title_ObjStates+4  
02284.  
02285. ; Set object 0's state to 1 (this is the leader koopa, he starts first, brings in the next) 
02286. LDA #$01 
02287. STA <Title_ObjStates 
02288.  
02289. ; This is the counter for when to reset the title sequence 
02290. LDA #20 
02291. STA <Title_ResetCnt ; Title_ResetCnt = 20 
02292.  
02293. ; This is the "fine" part of the reset count; when it goes to zero, it decrements Title_ResetCnt 
02294. LDA #60 
02295. STA <Title_ResetCnt2 ; Title_ResetCnt2 = 60 
02296.  
02297. INC <Title_State ; Next title state... 
02298. RTS ; Return 
02299.  
02300. Title_Menu_1P2PCursorY: 
02301. .byte 151, 167 ; Y position for the 1P/2P select cursor 
02302.  
02303. Title_Do1P2PMenu: 
02304. LDA <Controller2 
02305. AND #(PAD_A | PAD_B) 
02306. CMP #(PAD_A | PAD_B)  
02307. BNE PRG024_AC42 ; If Player 2 is not holding A+B, jump to PRG024_AC42 
02308.  
02309. ; NOTE: This probably WAS the debug menu activation... 
02310. NOP 
02311. NOP 
02312. NOP 
02313. NOP 
02314. NOP 
02315.  
02316. PRG024_AC42: 
02317. ; Title_ResetCnt and Title_ResetCnt2 gang together to form a large countdown timer 
02318.  
02319. DEC <Title_ResetCnt2 ; Title_ResetCnt2-- 
02320. BNE PRG024_AC52 ; If <> 0, jump to PRG024_AC52 
02321.  
02322. LDA #96 
02323. STA <Title_ResetCnt2 ; Title_ResetCnt2 = 96 
02324.  
02325. DEC <Title_ResetCnt ; Title_ResetCnt-- 
02326. BNE PRG024_AC52 ; If <> 0, jump to PRG024_AC52 
02327.  
02328. ; Title_ResetCnt and Title_ResetCnt2 have reached zero! 
02329. ; Trigger the reset! 
02330. LDA #$ff 
02331. STA <Title_ResetTrig ; Title_ResetTrig = $ff 
02332.  
02333. PRG024_AC52: 
02334. JSR Title_Menu_UpdateKoopas ; Update and draw koopas 
02335.  
02336. LDA <Pad_Input  
02337. AND #PAD_SELECT 
02338. BEQ PRG024_AC6B ; If Player is not pressing SELECT, jump to PRG024_AC6B 
02339.  
02340. LDA #SND_MAPPATHMOVE  
02341. STA Sound_QMap ; "Path move" sound (in this case, the "bleep" for the menu) 
02342.  
02343. ; Basically makes sure that the value of Total_Players is 0 or 1  
02344. INC Total_Players 
02345. LDA Total_Players 
02346. AND #$01  
02347. STA Total_Players 
02348.  
02349. PRG024_AC6B: 
02350. LDY Total_Players ; Y = Total_Players (0 or 1) 
02351. LDA Title_Menu_1P2PCursorY,Y ; Get proper Y value for where cursor is at 
02352. STA Sprite_RAM+$F0 ; Store into sprite 
02353.  
02354. LDA #$df  
02355. STA Sprite_RAM+$F1 ; Store pattern value into sprite 
02356.  
02357. LDA #$00  
02358. STA Sprite_RAM+$F2 ; Store attribute value into sprite 
02359.  
02360. LDA #72 
02361. STA Sprite_RAM+$F3 ; Store X value into sprite 
02362.  
02363. JSR Title_3Glow ; Keep the big '3' glowing! 
02364.  
02365. LDA <Pad_Input  
02366. AND #PAD_START 
02367. BEQ PRG024_ACBA ; If Player is not pressing START, jump to PRG024_ACBA (RTS) 
02368.  
02369. LDA #SND_LEVELCOIN  
02370. STA Sound_QLevel1 ; Play coin sound (in this case, selected and begin!) 
02371.  
02372. LDA Sprite_RAM+$F0 ; Get Y value of title screen cursor sprite 
02373. STA <Title_EventGrafX ; Reuse as a temp... 
02374.  
02375. PRG024_AC96: 
02376. JSR GraphicsBuf_Prep_And_WaitVSyn2 
02377.  
02378. INC <Title_ResetCnt ; Title_ResetCnt++ 
02379.  
02380. LDY #$f8 ; Y = $f8 (hide title screen cursor) 
02381.  
02382. LDA <Title_ResetCnt 
02383. AND #$18  
02384. BEQ PRG024_ACA5 ; Periodically jump to PRG024_ACA5 
02385.  
02386. LDY <Title_EventGrafX ; Y = reappear title screen cursor 
02387.  
02388. PRG024_ACA5: 
02389. STY Sprite_RAM+$F0 ; Set it! 
02390.  
02391. JSR Title_3Glow ; Make the big '3' glow! 
02392.  
02393. LDA SndCur_Level1 
02394. BNE PRG024_AC96 ; If the "gling" sound has not ended, loop! 
02395.  
02396. INC <Title_State ; Title_State++ 
02397.  
02398. ; World_Num = 0 (World 1) 
02399. LDA #$00 
02400. STA World_Num 
02401.  
02402. ; Debug_Flag = 0 (no debug mode) 
02403. STA Debug_Flag 
02404.  
02405. PRG024_ACBA: 
02406. RTS ; Return 
02407.  
02408. Title_PrepForWorldMap: 
02409. LDA #$00 
02410. STA World_Map_Power ; Mario starts as small on world map 
02411. STA World_Map_Power+1 ; Luigi starts as small on world map 
02412. INC Total_Players ; Total_Players should be 1/2, not 0/1 
02413. INC <Title_State ; Next title state... 
02414. RTS ; Return 
02415.  
02416. Title_DebugMenu: 
02417. JSR Title_Menu_UpdateKoopas ; Update the koopas 
02418.  
02419. LDA <Controller2 
02420. AND #$c1  
02421. CMP #$c1  
02422. BNE PRG024_ACD7 ; If Player 2 is NOT hitting A+B+Right (credits jump), jump to PRG024_ACD7 
02423.  
02424. JMP Ending_Credits ; Jump to credits 
02425.  
02426. PRG024_ACD7: 
02427. LDA <Controller2 
02428. AND #$c4  
02429. CMP #$c4  
02430. BNE PRG024_ACE2 ; If Player 2 is NOT hitting A+B+Down (jump to Princess rescue), jump to PRG024_ACE2 
02431.  
02432. JMP Rescue_Princess ; Jump to princess rescue 
02433.  
02434. PRG024_ACE2: 
02435. LDA <Pad_Input 
02436. AND #(PAD_UP | PAD_DOWN) 
02437. BEQ PRG024_ACFB ; If Player is not pressing Up or Down, jump to PRG024_ACFB 
02438.  
02439. LSR A 
02440. LSR A 
02441. LSR A 
02442. TAX ; X = 0 (Down) or 1 (Up) 
02443.  
02444. ; Properly add or subtract from world depending on direction pressed, 
02445. ; and loop around so it never leaves World 1 - 8 (0-7) 
02446. LDA World_Num_Debug 
02447. ADD Debug_DownUp,X 
02448. AND #$07  
02449. STA World_Num_Debug 
02450.  
02451. JMP PRG024_AD9C ; Jump to PRG024_AD9C 
02452.  
02453. PRG024_ACFB: 
02454. LDA <Pad_Input  
02455. AND #PAD_SELECT 
02456. BEQ PRG024_AD0C ; If Player is not pressing SELECT, jump to PRG024_AD0C 
02457.  
02458. ; Basically makes sure that the value of Total_Players is 0 or 1  
02459. INC Total_Players 
02460. LDA Total_Players 
02461. AND #$01  
02462. STA Total_Players 
02463.  
02464. PRG024_AD0C: 
02465. LDY Total_Players ; Y = Total_Players (0 or 1) 
02466. LDA Title_Menu_1P2PCursorY,Y ; Get proper Y value for where cursor is at 
02467. STA Sprite_RAM+$F0 ; Store into sprite 
02468.  
02469. LDA #$df  
02470. STA Sprite_RAM+$F1 ; Store pattern value into sprite 
02471.  
02472. LDA #$00  
02473. STA Sprite_RAM+$F2 ; Store attribute value into sprite 
02474.  
02475. LDA #72 
02476. STA Sprite_RAM+$F3 ; Store X value into sprite 
02477.  
02478. LDA <Pad_Input 
02479. AND #PAD_A 
02480. BEQ PRG024_AD54 ; If Player is not pressing A, jump to PRG024_AD54 
02481.  
02482. LDA Player_Lives 
02483. CMP #99 
02484. BEQ PRG024_AD3A ; If Player_Lives = 99, jump to PRG024_AD3A 
02485.  
02486. ; Otherwise, 5 more lives 
02487. LDA Player_Lives 
02488. ADD #$05  
02489. STA Player_Lives 
02490.  
02491. PRG024_AD3A: 
02492.  
02493. ; Updates number of lives 
02494. LDA #$21  
02495. STA Graphics_Buffer 
02496. LDA #$14  
02497. STA Graphics_Buffer+1 ; VRAM Address $2114 
02498.  
02499. LDA #$01  
02500. STA Graphics_Buffer+2 ; 1 byte 
02501.  
02502. LDA Player_Lives  
02503. STA Graphics_Buffer+3 ; Number of lives direct 
02504.  
02505. LDA #$00  
02506. STA Graphics_Buffer+4 ; Terminator 
02507.  
02508. PRG024_AD54: 
02509. LDA <Pad_Input  
02510. AND #PAD_START 
02511. BEQ PRG024_AD9C ; If Player is NOT pressing START, jump to PRG024_AD9C 
02512.  
02513. LDA #$80  
02514. STA Debug_Flag ; Activate debug functions 
02515.  
02516. LDA #$04 
02517. STA <Title_State ; Title_State = 4 (prep for world map) 
02518.  
02519. ; Quick loop to set up Mario and Luigi with the lives start and world map power 
02520. LDX Total_Players ; X = Total_Players 
02521. LDY Player_Lives ; Y = Player_Lives 
02522. PRG024_AD69: 
02523. TYA ; A = Player_Lives 
02524. STA Player_Lives,X ; Store to this player 
02525. LDA #$00  
02526. STA World_Map_Power,X ; This player starts small on world map 
02527. DEX ; X-- 
02528. BPL PRG024_AD69 ; While X >= 0, loop... 
02529.  
02530. LDA World_Num_Debug 
02531. STA World_Num ; Transfer the selected world to the game's world variable 
02532.  
02533. ; Fills entire inventory of Mario and Luigi with P-Wings first 
02534. LDX #$1b 
02535. LDA #$08  
02536. PRG024_AD7F: 
02537. STA Inventory_Items,X  
02538. STA Inventory_Items2,X  
02539. DEX ; X-- 
02540. BPL PRG024_AD7F ; While X >= 0, loop... 
02541.  
02542. ; Fill beginning of inventory with one of everything 
02543. LDX #$0d  
02544.  
02545. ; Give second warp whistle 
02546. LDA #$0c 
02547. STA Inventory_Items,X 
02548. STA Inventory_Items2,X 
02549. PRG024_AD92: 
02550. TXA 
02551. STA Inventory_Items-1,X 
02552. STA Inventory_Items2-1,X 
02553. DEX ; X-- 
02554. BNE PRG024_AD92 ; While X <> 0, loop! (Don't want 0 because of the "-1" indexing) 
02555.  
02556. PRG024_AD9C: 
02557.  
02558. ; Draw the world select cursor 
02559. LDA World_Num_Debug 
02560. ASL A  
02561. ASL A  
02562. ASL A  
02563. ASL A  
02564. ADD #$30  
02565. STA Sprite_RAM+$50 
02566. LDA #$6f  
02567. STA Sprite_RAM+$51 
02568. LDA #$00  
02569. STA Sprite_RAM+$52 
02570. LDA #$20  
02571. STA Sprite_RAM+$53 
02572.  
02573. RTS ; Return 
02574.  
02575.  
02576. T_SP_Off .func \1-Title_SpritePattern ; "Title SpritePattern Offset" 
02577.  
02578. ; Index into Title_SpritePattern for all of Mario/Luigi's complex frames 
02579. Title_SpritePatternIndex: 
02580. .byte T_SP_Off(T_SP_00), T_SP_Off(T_SP_01), T_SP_Off(T_SP_02), T_SP_Off(T_SP_03) 
02581. .byte T_SP_Off(T_SP_04), T_SP_Off(T_SP_05), T_SP_Off(T_SP_06), T_SP_Off(T_SP_07) 
02582. .byte T_SP_Off(T_SP_08), T_SP_Off(T_SP_09), T_SP_Off(T_SP_0A), T_SP_Off(T_SP_0B) 
02583. .byte T_SP_Off(T_SP_0C), T_SP_Off(T_SP_0D), T_SP_Off(T_SP_0E), T_SP_Off(T_SP_0F) 
02584. .byte T_SP_Off(T_SP_10), T_SP_Off(T_SP_11), T_SP_Off(T_SP_12), T_SP_Off(T_SP_13) 
02585. .byte T_SP_Off(T_SP_14), T_SP_Off(T_SP_15), T_SP_Off(T_SP_16), T_SP_Off(T_SP_17) 
02586. .byte T_SP_Off(T_SP_18), T_SP_Off(T_SP_19), T_SP_Off(T_SP_1A), T_SP_Off(T_SP_1B) 
02587.  
02588. ; Block of patterns, based on offsets from Title_SpritePatternIndex 
02589. ; For use with Mario/Luigi's sprites 
02590. Title_SpritePattern: 
02591. T_SP_00: .byte $01, $03, $F1, $05, $07, $F1 
02592. T_SP_01: .byte $0B, $0D, $F1, $0F, $29, $F1 
02593. T_SP_02: .byte $2D, $2F, $F1, $19, $1B, $F1 
02594. T_SP_03: .byte $01, $03, $F1, $05, $07, $09 
02595. T_SP_04: .byte $0B, $0D, $F1, $0F, $29, $2B 
02596. T_SP_05: .byte $2D, $2F, $F1, $19, $1B, $1D 
02597. T_SP_06: .byte $31, $33, $F1, $35, $37, $F1 
02598. T_SP_07: .byte $31, $33, $F1, $35, $37, $39 
02599. T_SP_08: .byte $01, $03, $F1, $05, $07, $39 
02600. T_SP_09: .byte $01, $03, $F1, $05, $07, $3B 
02601. T_SP_0A: .byte $25, $25, $F1, $27, $27, $F1 
02602. T_SP_0B: .byte $31, $33, $F1, $35, $37, $F1 
02603. T_SP_0C: .byte $29, $2B, $F1, $2D, $2F, $F1 
02604. T_SP_0D: .byte $27, $19, $F1, $1D, $1F, $F1 
02605. T_SP_0E: .byte $01, $03, $F1, $05, $07, $09 
02606. T_SP_0F: .byte $01, $03, $F1, $0B, $0D, $0F 
02607. T_SP_10: .byte $01, $03, $F1, $21, $23, $25 
02608. T_SP_11: .byte $F1, $F1, $F1, $05, $07, $F1 
02609. T_SP_12: .byte $F1, $F1, $F1, $01, $03, $F1 
02610. T_SP_13: .byte $F1, $F1, $F1, $21, $23, $F1 
02611. T_SP_14: .byte $19, $1B, $F1, $1D, $21, $F1 
02612. T_SP_15: .byte $19, $1B, $F1, $1D, $21, $23 
02613. T_SP_16: .byte $01, $03, $05, $07, $09, $0B 
02614. T_SP_17: .byte $0D, $0F, $F1, $11, $13, $F1 
02615. T_SP_18: .byte $F1, $F1, $F1, $F1, $F1, $F1 
02616. T_SP_19: .byte $25, $27, $F1, $29, $2B, $F1 
02617. T_SP_1A: .byte $2D, $2F, $F1, $19, $1B, $F1 
02618. T_SP_1B: .byte $31, $33, $F1, $35, $37, $F1 
02619.  
02620. ; Specify proper VROM page for Title_ObjMLSprite sprite index 
02621. Title_SpriteVROMPage: 
02622. .byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $45 
02623. .byte $02, $02, $02, $02, $02, $03, $03, $03, $03, $03, $7F, $7F, $00, $13, $13, $13 
02624.  
02625.  
02626. ; Walking animation sprite frames 
02627. ; Values per frame (0 - 3, +4 for each power level they are) 
02628. Title_ObjMLWalkSprite: 
02629. .byte $11, $12, $11, $12 ; Small  
02630. .byte $00, $01, $02, $01 ; Big 
02631. .byte $03, $04, $05, $04 ; Leaf Raccoon 
02632. .byte $1A, $1B, $1A, $1B ; The Princess 
02633.  
02634. ; Duck sprite frames 
02635. Title_ObjMLDuckSprite: 
02636. .byte $12 ; Small (no duck sprite) 
02637. .byte $06 ; Big 
02638. .byte $07 ; Leaf Raccoon 
02639.  
02640. ; Skid sprite frames 
02641. Title_ObjMLSkidSprite: 
02642. .byte $13 ; Small 
02643. .byte $0C ; Big / Leaf Raccoon 
02644.  
02645. ; Leaf raccoon tail wag animation sprite frames 
02646. Title_ObjMLTailWagSprite: 
02647. .byte $09, $03, $08 
02648.  
02649. ; Carrying item while walking 
02650. Title_ObjMLCarrySprite: 
02651. .byte $0E, $0F, $10, $0E 
02652.  
02653. ; Powering down (shrinking) animation 
02654. Title_ObjMarioPowerDown: 
02655. .byte $11, $0B, $11, $0B, $11, $0B, $02, $0B, $02, $0B, $02, $0B 
02656.  
02657. ; Initial X positions of Mario and Luigi 
02658. Title_ObjInitX: 
02659. .byte $F0, $00 
02660.  
02661. ; Initial sprite flags of Mario and Luigi 
02662. Title_ObjInitFlags: 
02663. .byte $00, SPR_HFLIP 
02664.  
02665.  
02666. ; Title_UpdateAllObjs 
02667. ;  
02668. ; This routine updates ALL of the objects on the title screen; Mario and Luigi 
02669. ; and the assorted other things that appear on there. Handles all of the 
02670. ; related logic as well. Pretty much the driving force of all the action! 
02671. ; 
02672. ; ... except for the final koopa troopas who march across, they're a 
02673. ; different bit of code... 
02674. Title_UpdateAllObjs: 
02675. JSR PRG024_SpriteClear ; Clear all sprites 
02676.  
02677. ; The first byte of Title_MLAccelCnt constantly subtracts $90, discarding any of the low 4 bits 
02678. ; This provides a slow, semi-natural acceleration for the Bros on the title screen 
02679. LDA Title_MLAccelCnt 
02680. AND #$f0  
02681. SUB #$90  
02682. STA Title_MLAccelCnt 
02683.  
02684. LDA #$10  
02685. STA <Title_ObjMLSprRAMOff ; Mario's sprite RAM starts at Sprite_RAM + $10 
02686.  
02687. LDA #$28  
02688. STA <Title_ObjMLSprRAMOff+1 ; Luigi's sprite RAM starts at Sprite_RAM + $28 
02689.  
02690. LDX #$01 
02691.  
02692. PRG024_AEDD: 
02693. STX <Title_CurMLIndex ; Store current index 
02694.  
02695. LDA <Title_ObjMLStop 
02696. BEQ PRG024_AF0C ; If Title_ObjMLStop = 0, jump to PRG024_AF0C 
02697.  
02698. LDA #$08  
02699.  
02700. LDY Title_MLHoldTick 
02701. BEQ PRG024_AEEF ; If Title_MLHoldTick = 0, jump to PRG024_AEEF 
02702.  
02703. DEC Title_MLHoldTick ; Otherwise, decrement Title_MLHoldTick 
02704.  
02705. ; Initialize Mario and Luigi title screen objects! 
02706.  
02707. LDA #$00 
02708. PRG024_AEEF: 
02709. ; Set the initial X velocity (zero) 
02710. STA <Title_ObjXVel,X  
02711.  
02712. ; Set the initial X coordinates 
02713. LDA Title_ObjInitX,X  
02714. STA <Title_ObjX,X  
02715.  
02716. ; Set the initial Y coordinate (160) 
02717. LDA #160 
02718. STA <Title_ObjY,X 
02719.  
02720. ; Set the initial flags 
02721. LDA Title_ObjInitFlags,X 
02722. STA <Title_ObjMLFlags,X  
02723.  
02724. JSR Title_AnimateMarioLuigi ; Animate Mario/Luigi 
02725. JSR Title_DrawMarioLuigi ; Draw Mario/Luigi 
02726.  
02727. LDA #$00  
02728. STA <Title_ObjXVel,X ; Zero Mario/Luigi's X velocity 
02729. JMP PRG024_AF3D ; Jump to PRG024_AF3D 
02730.  
02731. PRG024_AF0C: 
02732. ; When Title_ObjMLStop = 0... 
02733.  
02734. JSR Title_MLXAccel ; Update and apply X velocities of Mario/Luigi 
02735. JSR Title_ML_DoGravity ; Update and apply Y velocities of Mario/Luigi 
02736. JSR Title_AnimateMarioLuigi ; Animate Mario/Luigi 
02737. JSR Title_MLDetermineSpriteVis ; Determine what "slivers" of Mario/Luigi sprites are visible 
02738. JSR Title_MarioDoPoof ; Update and draw the "poof" 
02739.  
02740. LDA Title_MarioPoof 
02741. BNE PRG024_AF23 ; If Mario is doing the "powerup poof", jump to PRG024_AF23 
02742.  
02743. ; Otherwise, draw Mario and Luigi in the standard way! 
02744. JSR Title_DrawMarioLuigi 
02745.  
02746. PRG024_AF23: 
02747. LDA <Title_XPosHi,X  
02748. BEQ PRG024_AF3D ; If the "high" component of the X position is zero, jump to PRG024_AF3D 
02749. BPL PRG024_AF33 ; If it is greater than zero, jump to PRG024_AF33 
02750.  
02751. ; The XHi is less than zero... 
02752.  
02753. LDA <Title_ObjX,X ; Get the X coordinate 
02754. CMP #-64 
02755. BGE PRG024_AF3D ; If the X coordinate is >= -64, jump to PRG024_AF3D 
02756.  
02757. ; Don't let the X coordinate go below -64 
02758. LDA #$c0 
02759. BNE PRG024_AF3B ; Jump (technically always) to PRG024_AF3B 
02760.  
02761. PRG024_AF33: 
02762.  
02763. ; The XHi is greater than zero... 
02764.  
02765. LDA <Title_ObjX,X 
02766. CMP #64 
02767. BLT PRG024_AF3D ; If the X coordinate is less than 64, jump to PRG024_AF3D 
02768.  
02769. ; Don't let the X coordinate go above 64 off the right side of the screen 
02770. LDA #63 
02771.  
02772. PRG024_AF3B: 
02773. STA <Title_ObjX,X ; Update the X coordinate 
02774.  
02775. PRG024_AF3D: 
02776. DEX ; X-- (Process Mario after Luigi) 
02777. BPL PRG024_AEDD ; If X >= 0, loop! 
02778.  
02779.  
02780. ; Done processing Mario and Luigi 
02781.  
02782. JSR Title_UpdateOtherObjs ; Update the "other", minor objects! 
02783.  
02784. RTS ; Return 
02785.  
02786.  
02787. ; Quick and dirty sprite RAM "clear" function (pushes the Y component out of visible range) 
02788. PRG024_SpriteClear: 
02789. LDY #$1c 
02790. LDA #$f8 
02791.  
02792. PRG024_AF48: 
02793. STA Sprite_RAM,Y 
02794. STA Sprite_RAM+$20,Y 
02795. STA Sprite_RAM+$40,Y 
02796. STA Sprite_RAM+$60,Y 
02797. STA Sprite_RAM+$80,Y 
02798. STA Sprite_RAM+$A0,Y 
02799. STA Sprite_RAM+$C0,Y 
02800. STA Sprite_RAM+$E0,Y 
02801. DEY  
02802. DEY  
02803. DEY  
02804. DEY  
02805. BPL PRG024_AF48 
02806.  
02807. RTS ; Return 
02808.  
02809. PRG024_AF67: 
02810. .byte -1, 0, 1 
02811.  
02812. ; Values added to Title_MLAccelCnt 
02813. Title_MLAccelFactors: 
02814. .byte $60, $E0, $70 ; $E0 is most common, directly affects their ability to accelerate 
02815.  
02816. ; Title_MLXAccel 
02817. ; 
02818. ; Figures out Mario/Luigi's X acceleration and applies it 
02819. Title_MLXAccel: 
02820. ; X is 0/1, Mario/Luigi 
02821.  
02822. LDY #$02 ; Y = 2 
02823. LDA <Title_ObjXVel,X ; Get Mario/Luigi's X velocity 
02824. BPL PRG024_AF7A ; If velocity is >= 0, jump to PRG024_AF7A 
02825.  
02826. ; Otherwise, negate it (get the absolute value) 
02827. NEG 
02828.  
02829. LDY #$01 ; Also, Y = 1 
02830.  
02831. PRG024_AF7A: 
02832. BNE PRG024_AF7D ; If velocity is non-zero, jump to PRG024_AF7D 
02833.  
02834. ; X velocity is zero 
02835. TAY ; Y = A (which is zero) 
02836.  
02837. PRG024_AF7D: 
02838. ; At this point, Y is a standard direction value -- 0 = Not moving, 1 = Leftward, 2 = Rightward 
02839.  
02840. STA <Temp_Var15 ; Store velocity into Temp_Var15 
02841. STY <Title_ObjMLMoveDir,X ; Store movement direction into Title_ObjMLMoveDir 
02842.  
02843. LDY #$18 ; Y = $18 
02844. LDA <Title_ObjMLDir,X ; Get the direction vector value 
02845. AND #$40 ; Check bit 6 (FIXME??) 
02846. BEQ PRG024_AF8B ; If not set, jump to PRG024_AF8B 
02847.  
02848. LDY #$28 ; Y = $28 
02849.  
02850. PRG024_AF8B: 
02851. STY <Temp_Var14 ; Store Y -> Temp_Var14 
02852.  
02853. LDY #$00 ; Y = 0 
02854. LDA <Title_ObjMLDir,X ; Get direction vector 
02855. AND #$03 ; Check for bit 0 or 1 (left/right) 
02856. BNE PRG024_AFA1 ; If either is set, jump to PRG024_AFA1 
02857.  
02858. ; Neither left nor right bits are set in vector 
02859. LDA <Title_ObjYVelChng,X ; Get Y velocity change 
02860. BNE PRG024_AFE9 ; If there's been a Y change, jump to PRG024_AFE9 
02861.  
02862. LDA <Title_ObjXVel,X ; Get the X velocity 
02863. BEQ PRG024_AFE9 ; If zero, jump to PRG024_AFE9 
02864. BMI PRG024_AFBB ; If < 0, jump to PRG024_AFBB 
02865. BPL PRG024_AFD3 ; If > 0, jump to PRG024_AFD3 
02866.  
02867. PRG024_AFA1: 
02868. INY 
02869. INY ; Y += 2 (Y = 2) 
02870.  
02871. AND <Title_ObjMLMoveDir,X ; Check if movement direction's corresponding bit is set in the Title_ObjMLDir direction vector 
02872. BNE PRG024_AFB5 ; If it is, jump to PRG024_AFB5 
02873.  
02874. DEY ; Y-- (Y = 1) 
02875.  
02876. LDA <Temp_Var15 ; Get velocity 
02877. CMP <Temp_Var14  
02878. BEQ PRG024_AFE9 ; If velocity equals key value ($18 or $28), jump to PRG024_AFE9 
02879. BLS PRG024_AFB5 ; If less, jump to PRG024_AFB5 
02880.  
02881. LDA <Title_ObjYVelChng,X 
02882. BNE PRG024_AFE9 ; If there's a Y velocity change, jump to PRG024_AFE9 
02883.  
02884. DEY ; Otherwise, Y-- (Y = 0) 
02885.  
02886. PRG024_AFB5: 
02887. LDA <Title_ObjMLDir,X 
02888. AND #$01  
02889. BNE PRG024_AFD3 ; If bit 1 (left) is set in the direction vector, jump to PRG024_AFD3 
02890.  
02891. PRG024_AFBB: 
02892. LDA #$00  
02893. SUB Title_MLAccelFactors,Y ; A = -Title_MLAccelFactors[Y] (negates values compared to the routine at PRG024_AFD3) 
02894. STA <Temp_Var1 ; Store into Temp_Var1 
02895.  
02896. LDA PRG024_AF67,Y ;  
02897. EOR #$ff ; A = PRG024_AF67[Y] ^ $FF  
02898. STA <Temp_Var2 ; Store into Temp_Var2 
02899.  
02900. LDA <Temp_Var1  
02901. BNE PRG024_AFDD ; If Temp_Var1 is non-zero, jump to PRG024_AFDD (never false??) 
02902.  
02903. ; NOTE: I don't think the following two lines of code can ever be reached 
02904. INC <Temp_Var2 ; Temp_Var2++ 
02905. JMP PRG024_AFDD ; Jump to PRG024_AFDD 
02906.  
02907. PRG024_AFD3: 
02908. LDA Title_MLAccelFactors,Y ; A = Title_MLAccelFactors[Y] 
02909. STA <Temp_Var1 ; Store into Temp_Var1 
02910.  
02911. LDA PRG024_AF67,Y ; A = PRG024_AF67[Y] 
02912. STA <Temp_Var2 ; Store into Temp_Var2 
02913.  
02914. PRG024_AFDD: 
02915.  
02916. ; High-precision adding here... 
02917. LDA <Temp_Var1  
02918. ADD Title_MLAccelCnt ; Title_MLAccelCnt += Temp_Var1 
02919.  
02920. LDA <Title_ObjXVel,X ; Get X velocity 
02921. ADC <Temp_Var2 ; Add Temp_Var2, including carry from above operation 
02922. STA <Title_ObjXVel,X ; Store result back... 
02923.  
02924. PRG024_AFE9: 
02925. JSR Title_AddVel_toPos ; Apply the X velocity 
02926. RTS ; Return... 
02927.  
02928. .byte $D0, $CE, $CC, $CA, $CA, $CA 
02929.  
02930. PRG024_AFF3: .byte $C8 ; Just a constant (base Y velocity for the queue function) 
02931. PRG024_AFF4: .byte $00, $02, $04, $08 ; Loaded by X velocity "whole" part (reduction in that Y velocity based on X speed) 
02932.  
02933.  
02934.  
02935. ; Title_ML_DoGravity 
02936. ; 
02937. ; Handles applying appropriate "fall" rates and the Y velocity of Mario/Luigi 
02938. ; Also processes queue event $80 
02939. Title_ML_DoGravity: 
02940.  
02941. LDA <Title_ObjMLQueue,X  
02942. AND #$80  
02943. STA <Temp_Var1 ; Temp_Var1 = Title_ObjMLQueue & $80 
02944. BEQ PRG024_B023 ; If bit 7 not set, jump to PRG024_B023 
02945.  
02946. ; Begin queue event $80 
02947.  
02948. LDA <Title_ObjYVelChng,X 
02949. BNE PRG024_B023 ; If there's a Y velocity change, jump to PRG024_B023 
02950.  
02951. LDA <Title_ObjXVel,X ; Get X velocity -> A 
02952. BPL PRG024_B00D ; If >= 0, jump to PRG024_B00D 
02953.  
02954. ; Otherwise, negate it! (Get absolute value) 
02955. NEG 
02956.  
02957. PRG024_B00D: 
02958. LSR A 
02959. LSR A 
02960. LSR A 
02961. LSR A  
02962. TAY ; Y = X velocity >> 4 (the upper "whole" part of this 4.4FP number) 
02963. LDA PRG024_AFF3 ; A = $C8 (unnecessary constant memory load?) 
02964. SUB PRG024_AFF4,Y ; Variable subtracted value (faster the X velocity is, the less of a Y velocity we end up with) 
02965. STA <Title_ObjYVel,X ; Store result as Y velocity 
02966.  
02967. LDA #$01  
02968. STA <Title_ObjYVelChng,X ; Indicate a Y velocity change 
02969. LDA #$00 
02970. STA <Title_ObjMLTailTick,X ; Zero out the tail wagging 
02971.  
02972. ; End of queue event $80 
02973.  
02974.  
02975. PRG024_B023: 
02976. LDA <Title_ObjYVelChng,X 
02977. BEQ PRG024_B053 ; If no Y velocity change, jump to PRG024_B053 
02978.  
02979. LDY #FALL_NORMAL ; Y = FALL_NORMAL (normal falling rate) 
02980.  
02981. LDA <Title_ObjYVel,X ; Get the Y velocity 
02982. CMP #-32  
02983. BGS PRG024_B037 ; If Y velocity >= -32, jump to PRG024_B037 
02984.  
02985. LDA <Title_ObjMLDir,X ; Get the direction vector 
02986. AND #$80  
02987. BEQ PRG024_B037 ; If bit 7 (tail wagging) is not set, jump to PRG024_B037 
02988.  
02989. LDY #FALL_TAILWAG ; Y = FALL_TAILWAG (slower falling rate when wagging raccoon tail) 
02990.  
02991. PRG024_B037: 
02992. TYA ; A = Y (1 or 5) 
02993. ADD <Title_ObjYVel,X  
02994. STA <Title_ObjYVel,X ; Title_ObjYVel += Y (1 or 5) 
02995.  
02996. LDA <Title_ObjMLPower,X  
02997. CMP #$02  
02998. BNE PRG024_B053 ; If Mario/Luigi's power level is not 2 (leaf raccoon), jump to PRG024_B053 
02999.  
03000. ; Leaf raccoon only... 
03001. LDA <Title_ObjMLDir,X 
03002. AND #$80  
03003. BEQ PRG024_B053 ; If direction vector bit 7 is not set, jump to PRG024_B053 
03004.  
03005. LDA <Title_ObjYVel,X  
03006. CMP #FALLRATE_TAILWAGMAX  
03007. BLS PRG024_B053 ; If Y velocity < FALLRATE_TAILWAGMAX, jump to PRG024_B053 
03008.  
03009. ; Prevent Y velocity from being any greater than FALLRATE_TAILWAGMAX 
03010. ; Allows tail wagging to not affect when moving upward 
03011. LDA #FALLRATE_TAILWAGMAX 
03012. STA <Title_ObjYVel,X 
03013.  
03014. PRG024_B053: 
03015. JSR Title_MLYAccel ; Apply Y velocity 
03016.  
03017. LDA <Title_YPosHi,X ; Get the most significant byte of the Y position 
03018. BEQ PRG024_B060 ; If = 0, jump to PRG024_B060 
03019.  
03020. ; Otherwise, forces Y velocity to $20 (?) 
03021. LDA #$20  
03022. STA <Title_ObjYVel,X 
03023. BNE PRG024_B070 ; Jump (technically always) to PRG024_B070 (RTS) 
03024.  
03025. PRG024_B060: 
03026. LDA <Title_ObjY,X 
03027. CMP #160 
03028. BLT PRG024_B070 ; If Object Y is less than 160, jump to PRG024_B070 (RTS) 
03029.  
03030. ; This prevents the objects from falling beneath the 160 line on the title screen (pseudo-detection of "solid" floor) 
03031. LDA #160 
03032. STA <Title_ObjY,X ; Prevent object Y from being >= 160 
03033.  
03034. ; Zero out the Y velocity and change 
03035. LDA #$00  
03036. STA <Title_ObjYVelChng,X 
03037. STA <Title_ObjYVel,X  
03038.  
03039. PRG024_B070: 
03040. RTS ; Return 
03041.  
03042.  
03043. ; Title_AddVel_toPos 
03044. ; 
03045. ; This adds the X or Y velocity to an extended precision X or Y position storage 
03046. ; to enable the velocity to operate as a 4.4 fixed point value, with 
03047. ; a 20.4 bit X position coordinate... 
03048. Title_AddVel_toPos: 
03049. ; X is 0-7, objects X velocity 
03050. ; X is 8-15, objects Y velocity 
03051.  
03052. ; Going to perform a faux 16-bit shift 4 bits to the left on the X velocity 
03053.  
03054. LDA <Title_ObjXVel,X ; Get velocity of Mario/Luigi 
03055. PHA ; Save it 
03056.  
03057. ; Produce the lower half 
03058. ASL A 
03059. ASL A 
03060. ASL A 
03061. ASL A 
03062. STA <Temp_Var12 ; Temp_Var12 = velocity << 4 (multiplied by 16) 
03063.  
03064. LDY #$00 ; Y = 0 
03065. PLA ; Restore A (as velocity) 
03066.  
03067. ; Produce the upper half 
03068. LSR A 
03069. LSR A 
03070. LSR A 
03071. LSR A 
03072. CMP #$08  
03073. BLT PRG024_B088 ; If (velocity >> 4) < 8, jump to PRG024_B088 (detects a negative source value, because there's on ASR type instruction) 
03074.  
03075. ; (velocity >> 4) >= 8 ... (velocity is negative) 
03076. DEY ; Y-- (Y = -1) 
03077. ORA #$f0 ; Simulates carrying the negative sign bit across the value, like an ASR instruction would 
03078.  
03079. PRG024_B088:  
03080. STA <Temp_Var11 ; Store resultant value into Temp_Var11 
03081.  
03082. ; Register 'Y' also contains an additional level of high bits  
03083. ; (i.e. is zero if this is positive, $FF if negative, carrying the sign across) 
03084. STY <Temp_Var13 ; Y -> Temp_Var13 
03085.  
03086. ; So essentially what happened at this point is that the X velocity 
03087. ; has become a 24-bit value, shifted up 4 bits from its original 
03088. ; [Temp_Var13][Temp_Var11][Temp_Var12] = XVel << 4 
03089.  
03090. ; Title_XPosFrac works as an fractional accumulator 
03091. LDA <Title_XPosFrac,X 
03092. ADD <Temp_Var12 
03093. STA <Title_XPosFrac,X ; Title_XPosFrac += Temp_Var12 
03094.  
03095. ; ... which, as it overflows, provides a carry into the "whole" part 
03096. LDA <Title_ObjX,X 
03097. ADC <Temp_Var11  
03098. STA <Title_ObjX,X ; Title_ObjX += Temp_Var11 + Carry 
03099.  
03100. ; ... and if that overflows, the carry goes into the "high" part... 
03101. LDA <Title_XPosHi,X  
03102. ADC <Temp_Var13  
03103. STA <Title_XPosHi,X ; Further precision of the X position stored here 
03104.  
03105. RTS ; Return... 
03106.  
03107.  
03108. ; Title_MLYAccel 
03109. ; 
03110. ; Figures out Mario/Luigi's Y acceleration and applies it (including "gravity", and max fall rate) 
03111. Title_MLYAccel: 
03112. LDA <Title_ObjYVel,X 
03113. BMI Title_ApplyYVel ; If Y velocity is negative, jump to Title_ApplyYVel 
03114.  
03115. CMP #FALLRATE_MAX 
03116. BLS Title_ApplyYVel ; If Y velocity is less than FALLRATE_MAX, jump to Title_ApplyYVel 
03117.  
03118. ; Prevent Y velocity from being greater than FALLRATE_MAX 
03119. ; This defines the maximum fall speed! 
03120. LDA #FALLRATE_MAX  
03121. STA <Title_ObjYVel,X 
03122.  
03123. Title_ApplyYVel: 
03124.  
03125. ; NOTE: The "minor" objects also use code starting HERE (they have different fall/max rates) 
03126.  
03127. TXA ; X (object index) -> A 
03128. PHA ; Save A 
03129.  
03130. ; The index gets an offset added to it; this allows reuse of the velocity 
03131. ; precision adding function as X or Y velocity... relies on all pertinent values 
03132. ; to be exactly the same bytes apart... 
03133. ADD #(Title_ObjYVel - Title_ObjXVel) 
03134. TAX ; X = (object index) + 8 
03135.  
03136. JSR Title_AddVel_toPos ; Apply Y velocity 
03137.  
03138. PLA ; Restore A 
03139. TAX ; Restore X back to the index value 
03140.  
03141. RTS ; Return 
03142.  
03143. PRG024_B0B8: 
03144. .byte $07, $06, $05, $04, $03, $02, $01, $01, $01 
03145.  
03146. ; Title_AnimateMarioLuigi 
03147. ; 
03148. ; This lengthy routine is what translates movement hints and velocities 
03149. ; into animations for our favorite little plumbers... 
03150. Title_AnimateMarioLuigi: 
03151. ; Input object is assumed to be 0 (Mario) or 1 (Luigi) 
03152.  
03153. ; Absolute value of this object's X velocity 
03154. LDA <Title_ObjXVel,X 
03155. BPL PRG024_B0CA ; If X velocity is positive, jump to PRG024_B0CA 
03156.  
03157. ; Otherwise, negate it 
03158. NEG 
03159. PRG024_B0CA: 
03160.  
03161. ; Shift velocity down 3 times (divide by 8) 
03162. LSR A 
03163. LSR A 
03164. LSR A 
03165. TAY ; Y = X vel absolute magnitude / 8 
03166.  
03167. ; Animation speed will change based on the velocity 
03168. INC <Title_ObjMLDirTicks,X ; Increment animation ticks 
03169. LDA <Title_ObjMLDirTicks,X ; Get it -> A 
03170. CMP PRG024_B0B8,Y ; Compare it against the value in Y 
03171. BMI PRG024_B0E7 ; If it hasn't overflowed yet, jump down to PRG024_B0E7 
03172.  
03173. ; Animation ticks meet or exceed the value in Y! 
03174.  
03175. LDA #$00 
03176. STA <Title_ObjMLDirTicks,X ; Reset the ticks 
03177.  
03178. INC <Title_ObjMLAnimFrame,X ; Increment the frame 
03179.  
03180. ; Cap the frame 0-3 
03181. LDA <Title_ObjMLAnimFrame,X 
03182. CMP #$04  
03183. BMI PRG024_B0E7  
03184. LDA #$00  
03185. STA <Title_ObjMLAnimFrame,X 
03186.  
03187. PRG024_B0E7: 
03188. LDA <Title_ObjMLDir,X 
03189. AND #$03  
03190. BNE PRG024_B0F5 ; If Mario/Luigi is moving left or right, jump to PRG024_B0F5 
03191.  
03192. LDA <Title_ObjXVel,X 
03193. BNE PRG024_B0F5 ; If X velocity <> 0, jump to PRG024_B0F5 
03194.  
03195. ; If Title_ObjMLDir & 3 = 0 and x velocity = 0, force frame to 2 (standing) 
03196. LDA #$02 
03197. STA <Title_ObjMLAnimFrame,X  
03198.  
03199. PRG024_B0F5: 
03200.  
03201. ; Store flags value into Temp_Var1 
03202. LDA <Title_ObjMLFlags,X 
03203. STA <Temp_Var1 
03204.  
03205. LDA <Title_ObjMLDir,X 
03206. AND #$03 
03207. BEQ PRG024_B109 
03208.  
03209. ; If animation is 1, 2, or 3... 
03210. LDY #$00  
03211. AND #$02  
03212. BNE PRG024_B107 ; If it's specifically 2, jump to PRG024_B107 
03213.  
03214. LDY #SPR_HFLIP ; Otherwise, Y = SPR_HFLIP 
03215.  
03216. PRG024_B107: 
03217. STY <Title_ObjMLFlags,X ; Update flags value 
03218.  
03219. PRG024_B109: 
03220. LDA <Title_ObjMLFlags,X  
03221. EOR <Temp_Var1  
03222. STA <Temp_Var1 ; Store only the difference in flags -> Temp_Var1 
03223.  
03224. ; Mario/Luigi's current power offsets their default frame value (+4 for each power level) 
03225. LDA <Title_ObjMLPower,X 
03226. ASL A  
03227. ASL A  
03228. ORA <Title_ObjMLAnimFrame,X 
03229.  
03230. TAY ; frame -> Y 
03231. LDA Title_ObjMLWalkSprite,Y ; Get the proper sprite frame (actual system sprite drawer) 
03232. STA <Title_ObjMLSprite,X ; Make this the next sprite to display 
03233.  
03234. LDA <Title_ObjXVel,X  
03235. ADD #$01  
03236. CMP #$03  
03237. BLT PRG024_B135 ; If X Vel + 1 < 3, jump to PRG024_B135 
03238.  
03239. ; If the directions conflict, do skid 
03240. LDA <Title_ObjMLMoveDir,X 
03241. AND <Title_ObjMLDir,X  
03242. BEQ PRG024_B135 ; If Title_ObjMLMoveDir & Title_ObjMLDir = 0 (moving one way, facing the other), jump to PRG024_B135 (no skid) 
03243.  
03244. ; Use the skid frame! 
03245. LDY <Title_ObjMLPower,X ; Y = power level 
03246. BEQ PRG024_B130 ; If Title_ObjMLPower = 0 (small), jump to PRG024_B130 
03247. LDY #$01 ; Otherwise, Y = 1 (same skid for Big or Leaf Raccoon) 
03248. PRG024_B130: 
03249. LDA Title_ObjMLSkidSprite,Y ; Get the skid sprite 
03250. STA <Title_ObjMLSprite,X ; Make this the next sprite to display 
03251.  
03252. PRG024_B135: 
03253.  
03254. LDA <Title_ObjMLDir,X 
03255. AND #$04  
03256. BEQ PRG024_B156 ; If the direction is not downward, jump to PRG024_B156 
03257.  
03258. ; Direction downward, i.e. need to duck!Title_DrawMarioLuigi 
03259. LDY <Title_ObjMLPower,X  
03260. LDA Title_ObjMLDuckSprite,Y ; Get appropriate sprite by power level 
03261. STA <Title_ObjMLSprite,X ; Make this the next sprite to display 
03262.  
03263. LDA <Title_ObjMLQueue,X 
03264. AND #$04  
03265. BEQ PRG024_B156 ; If not time for Luigi's rebound off Mario, jump to PRG024_B156 
03266.  
03267. ; This does Luigi's rebound off Mario 
03268.  
03269. ; In short, Y is 0 if Luigi, 1 if Mario (opposite the usual order) 
03270. LDY #$00 ; Y = 0 
03271. TXA ; A = X (player index, 0/1) 
03272. BNE PRG024_B14E ; If player index is not zero, jump to PRG024_B14E 
03273. INY ; Otherwise increment Y 
03274. PRG024_B14E: 
03275.  
03276. LDA #-96 ; Luigi's bounce velocity 
03277. STA Title_ObjYVelChng,Y ; Store the change in velocity 
03278. STA Title_ObjYVel,Y ; And set the velocity 
03279.  
03280. PRG024_B156: 
03281. LDA <Title_ObjMLDir,X  
03282. AND #$08  
03283. BEQ PRG024_B160 ; If the direction is not upward, jump to PRG024_B160 
03284.  
03285. ; Direction upward, look upward 
03286. LDA #$17 ; The "looking upward" sprite 
03287. STA <Title_ObjMLSprite,X ; Make this the next sprite to display 
03288.  
03289. PRG024_B160: 
03290. LDA <Title_ObjYVelChng,X 
03291. BEQ PRG024_B19A ; If no change in Y velocity, jump to PRG024_B19A 
03292. LDA <Title_ObjMLPower,X  
03293. BEQ PRG024_B19A ; If power level = 0 (small), jump to PRG024_B19A 
03294.  
03295. CMP #$02 
03296. BNE PRG024_B190 ; If not leaf raccoon, jump to PRG024_B190 
03297.  
03298. ; Leaf raccoon with change in Y velocity... 
03299.  
03300. LDA #$15 ; Sprite to display (fist pump upward, leaf raccoon version) 
03301.  
03302. LDY <Title_ObjYVel,X 
03303. BMI PRG024_B198 ; If Y velocity is negative, jump to PRG024_B198 
03304.  
03305. LDA <Title_ObjMLTailTick,X 
03306. BEQ PRG024_B17B ; If tail tick = 0, jump to PRG024_B17B 
03307.  
03308. DEC <Title_ObjMLTailTick,X ; Decrement tail tick 
03309. JMP PRG024_B185 ; Jump to PRG024_B185... 
03310.  
03311. PRG024_B17B: 
03312. ; Tail ticker has hit zero! 
03313.  
03314. LDA <Title_ObjMLDir,X 
03315. AND #$80  
03316. BEQ PRG024_B185 ; If not wagging tail, jump to PRG024_B185 
03317.  
03318. LDA #10 
03319. STA <Title_ObjMLTailTick,X ; Title_ObjMLTailTick = 10 
03320.  
03321. PRG024_B185: 
03322. ; Y = Title_ObjMLTailTick / 4 
03323. LDA <Title_ObjMLTailTick,X 
03324. LSR A  
03325. LSR A  
03326. TAY 
03327.  
03328. LDA Title_ObjMLTailWagSprite,Y ; Get proper tail wag frame as the next frame to display 
03329. JMP PRG024_B198 ; Jump to PRG024_B198 
03330.  
03331. PRG024_B190: 
03332. ; Change in Y velocity, NOT leaf raccoon 
03333.  
03334. LDA #$14 ; Sprite to display (fist pump upward, non-leaf raccoon version) 
03335.  
03336. LDY <Title_ObjYVel,X  
03337. BMI PRG024_B198 ; If Y velocity < 0, jump to PRG024_B198 (i.e. do the fist pump) 
03338.  
03339. LDA #$00 ; Otherwise, do the first walk frame (fall frame) 
03340.  
03341. PRG024_B198: 
03342. STA <Title_ObjMLSprite,X ; Make whatever 'A' turned out to be the next frame to display! 
03343.  
03344. PRG024_B19A: 
03345. ; No change in Y velocity, or power level is 0 (small) 
03346.  
03347. LDA <Title_ObjMLKickTick,X 
03348. BEQ PRG024_B1A4 ; If not currently "kicking", jump to PRG024_B1A4 
03349.  
03350. DEC <Title_ObjMLKickTick,X ; Decrement the kick tick 
03351.  
03352. LDA #$0d ; Kick sprite 
03353. STA <Title_ObjMLSprite,X ; Make this the next sprite to display 
03354.  
03355. PRG024_B1A4: 
03356. LDA <Title_ObjMLBonkTick,X  
03357. BEQ PRG024_B1AE ; If not being "bonked", jump to PRG024_B1AE 
03358.  
03359. DEC <Title_ObjMLBonkTick,X ; Decrement bonk ticks 
03360.  
03361. LDA #$16 ; Bonk sprite 
03362. STA <Title_ObjMLSprite,X ; Make this the next sprite to display 
03363.  
03364. PRG024_B1AE: 
03365. TXA  
03366. BNE PRG024_B1C9 ; If Luigi, jump to PRG024_B1C9 
03367.  
03368. ; Only Mario gets to do the "power down" animation... 
03369. LDA <Title_ObjMPowerDown 
03370. BEQ PRG024_B1C9 ; If not doing the animation, jump to PRG024_B1C9 
03371.  
03372. ; Use Title_ObjMPowerDown / 4 to determine the appropriate sprite 
03373. LSR A 
03374. LSR A 
03375. TAY 
03376. LDA Title_ObjMarioPowerDown,Y 
03377. STA <Title_ObjMLSprite ; Make this the next sprite to display 
03378.  
03379. ; Mario's power level winds up at 0 (small) if the shrinkage sprite is at $11 
03380. ; Probably just so the right patterns are loaded is all... 
03381. LDY #$00 ; Power level 0 (small) 
03382. CMP #$11  
03383. BEQ PRG024_B1C5  
03384. LDY #$01 ; Power level 1 (Big)  
03385.  
03386. PRG024_B1C5: 
03387. STY <Title_ObjMLPower ; Change power level 
03388. DEC <Title_ObjMPowerDown ; Decrement the power down counter 
03389.  
03390. PRG024_B1C9: 
03391. LDA <Title_ObjMLHold,X  
03392. BNE PRG024_B1D5 ; If holding something, jump to PRG024_B1D5 
03393.  
03394. ; Activates the "hold" 
03395. LDA <Title_ObjMLQueue,X 
03396. AND #$20  
03397. BEQ PRG024_B204 ; If not time to begin carrying, jump to PRGO24_B204 
03398.  
03399. STA <Title_ObjMLHold,X ; Start carrying! 
03400.  
03401. PRG024_B1D5: 
03402.  
03403. ; Gets frame -> Y, unless no Y velocity change, in which case Y = 0 
03404. LDY <Title_ObjMLAnimFrame,X  
03405. LDA <Title_ObjYVelChng,X 
03406. BEQ PRG024_B1DD  
03407. LDY #$00  
03408. PRG024_B1DD: 
03409. LDA Title_ObjMLCarrySprite,Y ; Holding something, change frame to appropriate "carry" frame alternate 
03410. STA <Title_ObjMLSprite,X ; Make this the next sprite to display 
03411.  
03412. LDA <Temp_Var1 ; Get sprite flags (stored LONG ago...) 
03413. BEQ PRG024_B1EA ; If zero, jump to PRG024_B1EA 
03414.  
03415. LDA #$08  
03416. STA <Title_ObjMLBonkTick,X ; Title_ObjMLBonkTick = 8 
03417.  
03418. PRG024_B1EA: 
03419. LDA <Title_ObjMLBonkTick,X 
03420. BEQ PRG024_B1F4 
03421. DEC <Title_ObjMLBonkTick,X ; Decrement bonk ticks 
03422.  
03423. LDA #$0a ; Face-forward sprite frame 
03424. STA <Title_ObjMLSprite,X ; Make this the next sprite frame to display 
03425.  
03426. PRG024_B1F4: 
03427. LDA <Title_ObjMLQueue,X  
03428. AND #$40  
03429. BEQ PRG024_B204 ; If not doing clear carrying/bonk, do kick, jump to PRG024_B204 
03430.  
03431. ; Clear carrying/bonk, do kick 
03432.  
03433. LDA #$00  
03434. STA <Title_ObjMLHold,X ; Clear the carrying flag 
03435. STA <Title_ObjMLBonkTick,X ; Clear the bonk tick 
03436.  
03437. LDA #10 
03438. STA <Title_ObjMLKickTick,X ; Title_ObjMLKickTick = 10 
03439.  
03440. PRG024_B204: 
03441. RTS ; Return 
03442.  
03443.  
03444. ; Defines offsets of 16, 8, or 0 for sprite while building 
03445. Title_SpriteOffX: 
03446. .byte 16, 8, 0 
03447.  
03448. ; Per-power level offset to the VROM page 
03449. Title_SpriteVROMPwrOff: 
03450. .byte $50 ; 0 Small 
03451. .byte $54 ; 1 Big 
03452. .byte $00 ; 2 Leaf Raccoon 
03453.  
03454. ; Title_DrawMarioLuigi 
03455. ; 
03456. ; Not literally "draw", of course, but set up their hardware 
03457. ; sprites in Sprite_RAM to be "drawn"... 
03458. Title_DrawMarioLuigi: 
03459. ; Input object is assumed to be 0 (Mario) or 1 (Luigi) 
03460.  
03461. LDY <Title_ObjMLSprite,X ; Get the sprite to display 
03462. LDA Title_SpriteVROMPage,Y ; Get appropriate VROM page for this sprite index 
03463.  
03464. ; VROM pages 0 - 3 are power-up based and an offset is added depending on the bro's power levels 
03465. CMP #$04 
03466. BGE PRG024_B21E ; If VROM page >= 4, jump to PRG024_B21E 
03467.  
03468. STA <Temp_Var1 ; Store VROM Page in Temp_Var1 
03469. LDY <Title_ObjMLPower,X ; Power level -> Y 
03470. LDA Title_SpriteVROMPwrOff,Y ; Get VROM page offset for this power level 
03471. ADD <Temp_Var1 ; Add Temp_Var1 
03472.  
03473. PRG024_B21E: 
03474. STA PatTable_BankSel+2,X ; Set this VROM page (first quarter of sprite VROM) 
03475.  
03476. LDA #$00  
03477. STA <Temp_Var12 ; Clear Temp_Var12 
03478.  
03479. LDA <Title_ObjMLPower,X  
03480. BNE PRG024_B232 ; If power level > 0 (small), jump to PRG024_B232 
03481.  
03482. LDA <Title_ObjMLDir,X  
03483. AND #$10  
03484. BEQ PRG024_B232 ; If Title_ObjMLDir does not want to set sprite priority bit, jump to PRG024_B232 
03485.  
03486. ; This will set BG priority over the sprite 
03487. ASL A ; AND $10 means we're $10 before, and $20 after 
03488. STA <Temp_Var12 ; Temp_Var12 = $20 (sprite priority bit) 
03489.  
03490. PRG024_B232:  
03491. ; Store Y coordinate -> <Temp_Var15 
03492. LDA <Title_ObjY,X 
03493. STA <Temp_Var15  
03494.  
03495. ; Store X coordinate -> <Temp_Var16 
03496. LDA <Title_ObjX,X 
03497. STA <Temp_Var16 
03498.  
03499. ; Store flags -> Temp_Var14  
03500. LDA <Title_ObjMLFlags,X  
03501. STA <Temp_Var14  
03502.  
03503. ; Store Title_ObjMLSprVis -> Temp_Var13 
03504. LDA <Title_ObjMLSprVis,X 
03505. STA <Temp_Var13  
03506.  
03507. LDY <Title_ObjMLSprite,X ; Get the sprite index again 
03508. LDA Title_SpritePatternIndex,Y ; Get the appropriate sprite tile index (CHECKME?)  
03509. STA <Temp_Var1 ; Store into Temp_Var1 
03510.  
03511. LDA <Title_ObjMLSprRAMOff,X ; Get Mario/Luigi's sprite RAM offset 
03512. PHA ; Save 'A' (Title_ObjMLSprRAMOff) 
03513.  
03514. TAX ; X = Title_ObjMLSprRAMOff 
03515. LDY #$02 ; Y = 2 
03516.  
03517. ; Loop begin... 
03518. PRG024_B24F: 
03519. TYA ; A = 2 (loop counter, Mario/Luigi are 2-3 sprites across [top vs bottom]) 
03520. PHA ; Save 'A'  
03521.  
03522. LDY <Temp_Var1 ; Y = sprite tile index 
03523.  
03524. LDA Title_SpritePattern,Y ; Get tile for this sprite index 
03525. STA Sprite_RAM+$0D,X ; Set pattern number of sprite 
03526.  
03527. LDA Title_SpritePattern + 3,Y ; Get next tile for this sprite index 
03528. STA Sprite_RAM+$01,X ; Set pattern number of adjacent sprite 
03529.  
03530. PLA ; Restore 'A' 
03531. TAY ; Y = A (amounts to sprite offset of 0 @ 2, 8 @ 1, 16 @ 0) 
03532.  
03533. LDA <Temp_Var14 ; Get flags value 
03534. AND #%11000000 ; Only caring about the horizontal / vertical flip 
03535. ORA <Title_CurMLIndex ; Set appropriate palette by using the index value, which works out 
03536. ORA <Temp_Var12 ; 0 or $20 (choosing priority) 
03537.  
03538. ; Apply same "byte 2" to both sprites 
03539. STA Sprite_RAM+$02,X  
03540. STA Sprite_RAM+$0E,X  
03541.  
03542. ; Only set the Y coordinates if this part of the sprite is visible (as determined by Title_MLDetermineSpriteVis) 
03543. ; If the carry is set by the shift, we know NOT to draw this "sliver" of the sprite 
03544. ASL <Temp_Var13 ; Shift Title_ObjMLSprVis value left (updates Temp_Var13) 
03545. BCS PRG024_B27E ; If bit 7 was set, jump to PRG024_B27E 
03546.  
03547. ; Optionally skipped part... 
03548.  
03549. LDA <Temp_Var15 ; Get Y coordinate 
03550. STA Sprite_RAM+$0C,X ; Set Y coordinate of sprite 
03551. ADD #16 
03552. STA Sprite_RAM,X ; Set Y coordinate of adjacent sprite, 16 pixels beneath the one above 
03553.  
03554. PRG024_B27E: 
03555.  
03556. LDA <Temp_Var16 ; Get X coordinate 
03557. ADD Title_SpriteOffX,Y ; Add offset of 16, 8, or 0 as appropriate by 'Y' 
03558. STA Sprite_RAM+$03,X ; Store X coordinate 
03559. STA Sprite_RAM+$0F,X ; Store X coordinate 
03560.  
03561. INX 
03562. INX 
03563. INX 
03564. INX ; X += 4 
03565.  
03566. INC <Temp_Var1 ; Increment the sprite tile index 
03567. DEY ; Decrement Y 
03568. BPL PRG024_B24F ; As long as Y >= 0, loop 
03569.  
03570. PLA ; Restore 'A' (Title_ObjMLSprRAMOff) 
03571. TAX ; X = A 
03572.  
03573. LDA <Temp_Var14 ; Get flags 
03574. AND #%01000000  
03575. BEQ PRG024_B2C3 ; If not horizontally flipped, jump to PRG024_B2C3 
03576.  
03577. ; This mirrors the sprite layout horizontally 
03578.  
03579. ; Reverse pattern index 
03580. LDA Sprite_RAM+$01,X 
03581. PHA  
03582. LDA Sprite_RAM+$05,X 
03583. STA Sprite_RAM+$01,X 
03584. PLA  
03585. STA Sprite_RAM+$05,X 
03586.  
03587. ; Reverse X coordinates 
03588. LDA Sprite_RAM+$0B,X 
03589. ADD #-24 
03590. STA Sprite_RAM+$0B,X 
03591. STA Sprite_RAM+$17,X 
03592.  
03593. LDA Sprite_RAM+$D,X 
03594. PHA  
03595. LDA Sprite_RAM+$11,X 
03596. STA Sprite_RAM+$D,X 
03597. PLA  
03598. STA Sprite_RAM+$11,X 
03599.  
03600. PRG024_B2C3: 
03601. LDA Sprite_RAM+$01,X 
03602. CMP Sprite_RAM+$05,X 
03603. BNE PRG024_B2DE ; If the first and second patterns are NOT the same, jump to PRG024_B2DE 
03604.  
03605. ; When the first and second patterns are the same, this is assumed to be a "mirrored" sprite 
03606. ; (Think the "going down pipe" or "tail swing" face-forward frames) 
03607.  
03608. LDA Sprite_RAM+$0E,X ; Take attributes of this sprite 
03609. AND #%10111111 ; Keep everything EXCEPT the horizontal flip bit 
03610. STA Sprite_RAM+$02,X ; Update both top  
03611. STA Sprite_RAM+$0E,X ; ... and bottom 
03612.  
03613. ORA #%01000000 ; Set the horizontal flip 
03614. STA Sprite_RAM+$06,X ; Update the other side 
03615. STA Sprite_RAM+$12,X ; Ditto 
03616.  
03617. PRG024_B2DE: 
03618. LDY <Title_CurMLIndex ; Y = Mario [0] or Luigi [1] 
03619. LDA Title_ObjMLSprite,Y ; Get their current sprite index 
03620. CMP #$0d  
03621. BNE PRG024_B307 ; If current sprite is not $0D (kicking outward), jump to PRG024_B307 
03622.  
03623. ; The kicking sprite needs one of the sprites in front for the outward foot! 
03624. LDA Sprite_RAM,X  
03625. STA Sprite_RAM+$14,X ; Match the Y coordinate 
03626.  
03627. ; Facing left, foot is to the left 
03628. LDA #-8 ; A = -8 
03629.  
03630. ; This refers to whether Mario / Luigi is horizontally flipped, but seems wrong? 
03631. ; Should only check if NOT h-flipped? 
03632.  
03633. LDY <Temp_Var14 ; Y = Flags 
03634. BEQ PRG024_B2F6 ; If flags = 0 (?? this is unlikely?), jump to PRG024_B2F6 
03635.  
03636. ; Facing right, foot is to the right 
03637. LDA #16 ; A = 16 
03638.  
03639. PRG024_B2F6: 
03640. ADD Sprite_RAM+$0F,X ; Apply X offset 
03641. STA Sprite_RAM+$17,X ; Duplicate result 
03642.  
03643. LDA #$1b ; Foot pattern 
03644. STA Sprite_RAM+$15,X ; Set it 
03645.  
03646. ; Duplicate attribute settings 
03647. LDA Sprite_RAM+$0E,X 
03648. STA Sprite_RAM+$16,X 
03649.  
03650. PRG024_B307: 
03651. LDY #$05 ; Y = 5 (loop through all five sprites for Mario/Luigi) 
03652.  
03653. PRG024_B309: 
03654. LDA Sprite_RAM+$01,X ; Get pattern 
03655. CMP #$f1  
03656. BNE PRG024_B317 ; If pattern is not $F1, jump to PRG024_B317 
03657.  
03658. ; Pattern $F1 is used as a disable: 
03659. LDA #$f8  
03660. STA Sprite_RAM,X ; Forces this sprite's Y into oblivion, making it invisible 
03661. BNE PRG024_B324 ; Jump (technically always) to PRG024_B324 
03662.  
03663. PRG024_B317: 
03664. LDA <Title_CurMLIndex  
03665. BEQ PRG024_B324 ; If Mario, jump to PRG024_B324 
03666.  
03667. ; Otherwise, add $40 (Luigi is using second VROM bank) 
03668. LDA Sprite_RAM+$01,X 
03669. ADD #$40 
03670. STA Sprite_RAM+$01,X 
03671.  
03672. PRG024_B324: 
03673. INX 
03674. INX 
03675. INX 
03676. INX ; X += 4 (next sprite) 
03677. DEY ; Y-- 
03678. BPL PRG024_B309 ; Loop while Y >= 0 
03679.  
03680.  
03681. LDX <Title_CurMLIndex ; Leaving with 'X' set to what it entered with! 
03682. RTS ; Return 
03683.  
03684.  
03685. ; XOff and XHiOff are basically 16-bit values when put together 
03686.  
03687. Title_MLSpriteVis_XHiOff: 
03688. .byte 0, 0, 0 ; Not H-Flipped 
03689. .byte 0, 0, $FF ; H-Flipped ($FF represents a full set of sign bits, for the corresponding '-8' in XOff) 
03690.  
03691. Title_MLSpriteVis_XOff: 
03692. .byte 0, 8, 16 ; Not H-Flipped 
03693. .byte 0, 8, -8 ; H-Flipped 
03694.  
03695. Title_MLSpriteVis_BitVal: 
03696. ; Bit vals to mark which slivers NOT to display 
03697. .byte $80, $40, $20 ; Not H-Flipped 
03698. .byte $80, $40, $20 ; H-Flipped 
03699.  
03700. ; Title_MLDetermineSpriteVis 
03701. ; 
03702. ; This function determines which "slivers" of the Player sprite are invisible, by checking if they 
03703. ; cross screen boundaries (which will make them invisible), to prevent sprites "wrapping" around 
03704. ; the screen, due to the limit of the 'X' part of the sprite coordinate... 
03705. Title_MLDetermineSpriteVis: 
03706. LDA #$00 ; A = 0 
03707. STA <Title_ObjMLSprVis,X ; Clear Title_ObjMLSprVis 
03708.  
03709. LDY #$02 ; Y = 2 (not H-flipped) 
03710.  
03711. LDA <Title_ObjMLFlags,X ; Get flags -> 'A' 
03712. AND #SPR_HFLIP 
03713. BEQ PRG024_B34E ; If not flipped horizontally, jump to PRG024_B34E 
03714.  
03715. LDY #$05 ; Y = 5 (H-flipped) 
03716.  
03717. ; This will loop 5, 4, 3 (H-flipped) OR 2, 1, 0 (not H-flipped) 
03718. PRG024_B34E: 
03719.  
03720. ; 16-bit + 16-bit add here [Title_XPosHi][Title_ObjX] += [XHiOff][XOff] 
03721. LDA <Title_ObjX,X ; Get object's X position 
03722. ADD Title_MLSpriteVis_XOff,Y ; A += Title_MLSpriteVis_XOff[Y] 
03723. LDA <Title_XPosHi,X ; Get object's "high" part of the X value 
03724. ADC Title_MLSpriteVis_XHiOff,Y ; A += Title_MLSpriteVis_XHiOff[Y], with carry from previous op 
03725.  
03726. BEQ PRG024_B362 ; If the X pos high value added with the Title_MLSpriteVis_XHiOff[Y] value is zero, jump to PRG024_B362 
03727.  
03728. ; Otherwise, set a bit 
03729. LDA <Title_ObjMLSprVis,X 
03730. ORA Title_MLSpriteVis_BitVal,Y  
03731. STA <Title_ObjMLSprVis,X ; Title_ObjMLSprVis |= Title_MLSpriteVis_BitVal[Y] 
03732.  
03733. PRG024_B362: 
03734. DEY ; Y-- 
03735. BMI PRG024_B369 ; If Y < 0, jump to PRG024_B369 (RTS) 
03736.  
03737. CPY #$02  
03738. BNE PRG024_B34E ; If Y <> 2, jump to PRG024_B34E 
03739.  
03740. PRG024_B369: 
03741. RTS ; Return 
03742.  
03743.  
03744. ; Patterns of the "poof" sprites, per frame of poofing 
03745. Title_Poof_Patterns: .byte $87, $85, $83, $81 
03746.  
03747. ; Title_MarioDoPoof 
03748. ;  
03749. ; Handles doing Mario's (only) "poof" effect after catching the leaf 
03750. Title_MarioDoPoof: 
03751. ; X is index of Mario/Luigi 
03752.  
03753. TXA ; X -> A 
03754. BNE PRG024_B3C2 ; If index is not zero (i.e. Luigi), jump to PRG024_B3C2 (RTS) 
03755.  
03756. ; Mario only! 
03757.  
03758. LDA Title_MarioPoof 
03759. BEQ PRG024_B3C2 ; If the power-up "poof" effect is not occurring, jump to PRG024_B3C2 (RTS) 
03760.  
03761. DEC Title_MarioPoof ; Title_MarioPoof-- 
03762.  
03763. AND #%1100 
03764. LSR A  
03765. LSR A  
03766. TAY ; Y is now only bits 2 and 3 from Title_MarioPoof (provides 4 frames) 
03767.  
03768. ; Get pattern -> Temp_Var2 
03769. LDA Title_Poof_Patterns,Y 
03770. STA <Temp_Var2 
03771.  
03772. LDY <Title_ObjMLSprRAMOff ; Get the offset into Sprite_RAM for Mario 
03773.  
03774. LDA #%11000000 
03775. STA <Temp_Var1 ; Sprite attributes in Temp_Var1 (H and V flip right now) 
03776.  
03777. PRG024_B389: 
03778. LDA <Title_ObjY ; Get Mario's Y 
03779. ADD #$08 ; +8 
03780. STA Sprite_RAM,Y ; Store as sprite's Y 
03781.  
03782. LDA <Temp_Var2  
03783. STA Sprite_RAM+$01,Y ; Store poof pattern into sprite 
03784.  
03785. LDA <Temp_Var1 
03786. STA Sprite_RAM+$02,Y ; Store current attributes 
03787.  
03788. LDA <Title_ObjX  
03789. STA Sprite_RAM+$03,Y ; Store sprite X coordinate 
03790.  
03791. LDA <Temp_Var1 
03792. AND #$f0  
03793. BEQ PRG024_B3AF ; If the upper 4 bits of the attribute are zero, jump to PRG024_B3AF 
03794.  
03795. ; Otherwise, add 8 to the sprite's X 
03796. LDA Sprite_RAM+$03,Y 
03797. ADD #$08  
03798. STA Sprite_RAM+$03,Y 
03799.  
03800. PRG024_B3AF: 
03801. INY 
03802. INY 
03803. INY 
03804. INY ; Y += 4 (go to next sprite) 
03805.  
03806. LDA <Temp_Var1  
03807. SUB #$c0  
03808. STA <Temp_Var1 ; Temp_Var1 -= $C0 
03809. BCS PRG024_B389 ; Loop once... 
03810.  
03811. ; Ensure that there's no active velocity being applied! 
03812. LDA #$00 
03813. STA <Title_ObjYVel 
03814. STA <Title_ObjXVel 
03815.  
03816. PRG024_B3C2: 
03817. RTS ; Return 
03818.  
03819.  
03820. Title_UpdateOtherObjs: 
03821. LDX #$05 ; X = 5 (for the 6 title screen objects) 
03822.  
03823. PRG024_B3C5: 
03824. LDA <Title_ObjStates,X 
03825. BEQ PRG024_B3D6 ; If object state = 0 (inactive), jump to PRG024_B3D6 
03826.  
03827. CMP #$01 
03828. BNE PRG024_B3D3 ; If object state <> 1, jump to PRG024_B3D3 
03829.  
03830. JSR Title_UpdateObjState1 ; Perform state 1 duty of this object 
03831. JMP PRG024_B3D6 ; Jump to PRG024_B3D6 
03832.  
03833. PRG024_B3D3: 
03834. ; Object state > 1 
03835. JSR Title_UpdateObj ; Perform post-state 1 duty of this object 
03836.  
03837. PRG024_B3D6: 
03838. LDA Title_ObjVar,X 
03839. BEQ PRG024_B3DE ; If this object's ObjVar = 0, jump to PRG024_B3DE 
03840. DEC Title_ObjVar,X ; Otherwise, decrement it 
03841.  
03842. PRG024_B3DE: 
03843. DEX ; X-- (next object) 
03844. BPL PRG024_B3C5 ; If X >= 0, jump to PRG024_B3C5 
03845.  
03846. RTS ; Return... 
03847.  
03848. ; Starting X coordinates for the different map objects 
03849. Title_ObjStartX: 
03850. .byte $D0 ; 0 = Starman 
03851. .byte $20 ; 1 = Mushroom 
03852. .byte $60 ; 2 = Super Leaf 
03853. .byte $43 ; 3 = Goomba 
03854. .byte $B0 ; 4 = Buzzy Beatle 
03855. .byte $78 ; 5 = Koopa shell 
03856.  
03857. Title_UpdateObjState1: 
03858. ; X is the title screen object index, 0-5 
03859.  
03860. ; Store object's starting X coordinate 
03861. LDA Title_ObjStartX,X 
03862. STA <Title_ObjX+2,X 
03863.  
03864. ; All object's start at Y pos = 0 
03865. LDA #$00  
03866. STA <Title_ObjY+2,X 
03867.  
03868. ; Clear the object's velocities and state values 
03869. LDA #$00 
03870. STA <Title_ObjXVel+2,X 
03871. STA <Title_ObjYVel+2,X 
03872. INC <Title_ObjStates,X 
03873.  
03874. TXA ; A = X (object index) 
03875. JSR DynJump ; Jump dynamically based on object's index 
03876.  
03877. ; THESE MUST FOLLOW DynJump FOR THE DYNAMIC JUMP TO WORK!! 
03878. .word Title_ObjS1_None ; 0 - Starman 
03879. .word Title_ObjS1_None ; 1 - Mushroom 
03880. .word Title_ObjS1_Leaf ; 2 - Super leaf 
03881. .word Title_ObjS1_Goomba ; 3 - Goomba  
03882. .word Title_ObjS1_None ; 4 - Buzzy Beatle 
03883. .word Title_ObjS1_None ; 5 - Koopa shell 
03884.  
03885. Title_ObjS1_None: 
03886. RTS 
03887.  
03888. Title_ObjS1_Leaf: 
03889.  
03890. ; Clear velocity (again?) and Title_ObjVar2 (used as swing determination) 
03891. LDA #$00  
03892. STA <Title_ObjXVel+2,X 
03893. STA Title_ObjVar2,X  
03894.  
03895. LDA #$10 
03896. STA Title_ObjVar,X ; Title_ObjVar = $10 
03897.  
03898. LDA #$04  
03899. STA <Title_ObjYVel+2,X ; Leaf's Y velocity = 4 
03900.  
03901. RTS ; Return 
03902.  
03903. Title_ObjS1_Goomba: 
03904.  
03905. ; Title_ObjVar2 is used as a tick counter delaying the start to the goomba's move 
03906. LDA #185  
03907. STA Title_ObjVar2,X ; Title_ObjVar2 = 185 
03908.  
03909. RTS ; Return 
03910.  
03911. Title_UpdateObj: 
03912. TXA ; 'X' is the object index, but DynJump uses 'A' 
03913. JSR DynJump ; Dynamically jump... 
03914.  
03915. ; THESE MUST FOLLOW DynJump FOR THE DYNAMIC JUMP TO WORK!! 
03916. .word Title_DoStarman 
03917. .word Title_DoMushroom 
03918. .word Title_DoLeaf  
03919. .word Title_DoGoomba 
03920. .word Title_DoBuzzyBeatle 
03921. .word Title_DoKoopaShell  
03922.  
03923. Title_DoStarman: 
03924. JSR Title_ObjCommonXYVel ; Handle velocity standard 
03925. BNE PRG024_B43E ; If object did not fall below line 176, jump to PRG024_B43E 
03926.  
03927. ; Otherwise... 
03928. LDA #$20 
03929. STA <Title_ObjXVel+2,X ; X velocity set to $20 (initial bounce, bounces away) 
03930. LDA #-80 
03931. STA <Title_ObjYVel+2,X ; Y velocity set to -80 (bounce) 
03932.  
03933. PRG024_B43E: 
03934. JSR Title_ObjDraw ; Draw the starman! 
03935. JMP Title_ObjCommonFinale ; Do common finale code 
03936.  
03937. Title_DoMushroom: 
03938. JSR Title_ObjCommonXYVel ; Handle velocity standard 
03939. BNE PRG024_B44D ; If didn't hit ground, jump to PRG024_B44D 
03940.  
03941. ; Otherwise begin moving after hitting ground 
03942. LDA #$f0  
03943. STA <Title_ObjXVel+2,X 
03944.  
03945. PRG024_B44D: 
03946. JSR Title_ObjDraw ; Draw the mushroom! 
03947. JMP Title_ObjCommonFinale ; Do common finale code 
03948.  
03949. Title_Leaf_XVelAdj: .byte 2, -2 ; X velocity applied to leaf 
03950. Title_Leaf_XVelLimit: .byte 32, -32 ; X velocity limits for leaf to swing the other way 
03951. Title_Leaf_YVel: .byte 10, -10, 8 ; Y velocities assigned for leaf swinging 
03952.  
03953. Title_DoLeaf: 
03954. LDA Title_ObjVar,X 
03955. BEQ PRG024_B472 ; If = 0, jump to PRG024_B472 
03956.  
03957. JSR Title_ApplyYVelFall ; Apply Y velocities 
03958.  
03959. INC <Title_ObjYVel+2,X ; YVel++ 
03960.  
03961. LDA <Title_ObjYVel+2,X 
03962. CMP #$00  
03963. BEQ PRG024_B46D ; If YVel = 0, jump to PRG024_B46D 
03964. JMP PRG024_B49B ; Otherwise, jump to PRG024_B49B 
03965.  
03966. PRG024_B46D: 
03967. ; YVel = 0 
03968.  
03969. ; Title_ObjVar is never actually used, just cleared?? 
03970. LDA #$00 
03971. STA Title_ObjVar,X ; Clear Title_ObjVar 
03972.  
03973. PRG024_B472: 
03974.  
03975. ; Bit 0 of Title_ObjVar2 determines the current "swing" direction of the leaf 
03976. LDA Title_ObjVar2,X 
03977. AND #$01 ; Only using 0/1 
03978. TAY ; Y = A 
03979.  
03980. ; XVel += Title_Leaf_XVelAdj[Y] 
03981. LDA <Title_ObjXVel+2,X 
03982. ADD Title_Leaf_XVelAdj,Y 
03983. STA <Title_ObjXVel+2,X 
03984.  
03985. CMP Title_Leaf_XVelLimit,Y 
03986. BNE PRG024_B488 ; If not equal to Title_Leaf_XVelLimit[Y], jump to PRG024_B488 
03987.  
03988. INC Title_ObjVar2,X ; Title_ObjVar2++ (just perpetually adds and loops, but only bit 0 is used) 
03989.  
03990. PRG024_B488: 
03991. LDA <Title_ObjXVel+2,X 
03992. BPL PRG024_B48D ; If XVel >= 0, jump to PRG024_B48D 
03993.  
03994. INY ; Y++ (1 or 2) 
03995.  
03996. PRG024_B48D: 
03997. LDA Title_Leaf_YVel,Y 
03998. ADD #$06  
03999. STA <Title_ObjYVel+2,X ; YVel = Title_Leaf_YVel[Y] + 6 
04000.  
04001. JSR Title_ObjXVelApply ; Apply X Velocity 
04002. JSR Title_ApplyYVelFall ; Apply Y Velocity 
04003.  
04004. PRG024_B49B: 
04005. LDA #SPR_HFLIP ; A = SPR_HFLIP 
04006. LDY <Title_ObjXVel+2,X ; Y = XVel 
04007. BEQ PRG024_B4A7 ; If XVel = 0, jump to PRG024_B4A7 
04008.  
04009. BPL PRG024_B4A5 ; If X velocity > 0, jump to PRG024_B4A5 
04010. LDA #$00 ; A = 0 
04011.  
04012. PRG024_B4A5: 
04013. STA <Title_ObjFlags,X 
04014.  
04015. PRG024_B4A7: 
04016. JSR Title_ObjDraw ; Draw the leaf! 
04017.  
04018. LDA <Title_ObjY+2,X 
04019. AND #$f0 ; Only considering the most significant bits 
04020. CMP #$50 
04021. BNE PRG024_B4BF ; If the Y position is not in the vicinity of $50, jump to PRG024_B4BF 
04022.  
04023. ; When the leaf hits a certain Y level, the title screen assumes they've connected 
04024. ; and gives it to him; no actual object detection is performed... 
04025.  
04026. LDA #$00  
04027. STA <Title_ObjStates,X ; Object state = 0 (clear) 
04028.  
04029. LDA #$13  
04030. STA Title_MarioPoof ; Title_MarioPoof = $13  
04031.  
04032. LDA #$02 
04033. STA <Title_ObjMLPower ; Mario is now leaf raccoon! 
04034.  
04035. PRG024_B4BF: 
04036. RTS ; Return 
04037.  
04038.  
04039. Title_DoGoomba: 
04040. JSR Title_ObjCommonXYVel ; Handle velocity standard 
04041. BNE PRG024_B500 ; If Goomba hasn't hit the floor yet, jump to PRG024_B500 
04042.  
04043. ; Title_ObjVar2 is used as a tick counter 
04044. LDA Title_ObjVar2,X 
04045. BEQ PRG024_B4D0 ; If Title_ObjVar2 = 0, jump to PRG024_B4D0 
04046.  
04047. ; Otherwise, still waiting for the ticks to run out so the goomba can move... 
04048. DEC Title_ObjVar2,X ; Title_ObjVar2-- 
04049. JMP Title_ObjDraw ; Just draw... 
04050.  
04051. PRG024_B4D0: 
04052. LDA <Title_ObjX+2,X 
04053. CMP #$30  
04054. BGE PRG024_B4FC ; If goomba is still to the right of X = $30, jump to PRG024_B4FC 
04055.  
04056.  
04057. ; Goomba has hit its "death" position! 
04058. LDA Title_ObjVar,X  
04059. BNE PRG024_B4E0 ; If Title_ObjVar <> 0, jump to PRG024_B4E0 
04060.  
04061.  
04062. ; Title_ObjVar is used as a counter for the goomba's death... 
04063. ; Otherwise, load Title_ObjVar with $10 
04064. LDA #$10  
04065. STA Title_ObjVar,X ; Title_ObjVar = $10 
04066.  
04067. PRG024_B4E0:  
04068. CMP #$01  
04069. BNE PRG024_B4E8 ; If Title_ObjVar <> 1, jump to PRG024_B4E8 
04070.  
04071. ; Title_ObjVar = 1... 
04072. LDA #$00  
04073. STA <Title_ObjStates,X ; Set state = 0 (remove) 
04074.  
04075. PRG024_B4E8: 
04076.  
04077. ; Basically if goomba has crossed his death point and hasn't  
04078. ; stopped moving yet, it's about to die... 
04079. LDA <Title_ObjXVel+2,X 
04080. BEQ PRG024_B4F4 ; If X Velocity = 0, jump to PRG024_B4F4 
04081.  
04082. ; Mario's "stomping" on the goomba 
04083. LDA #$00  
04084. STA <Title_ObjXVel+2,X ; GOOMBA'S X velocity = 0 
04085. LDA #-48 
04086. STA <Title_ObjYVel ; MARIO's Y velocity = -48 
04087.  
04088. PRG024_B4F4: 
04089. LDA #$01  
04090. STA Title_ObjFrame,X ; ObjFrame = 1 (use "squished" frame) 
04091.  
04092. JMP Title_ObjDraw ; Draw goomba... 
04093.  
04094. PRG024_B4FC: 
04095. LDA #-8 
04096. STA <Title_ObjXVel+2,X ; Goomba X Velocity = -8 (march left) 
04097.  
04098. PRG024_B500: 
04099. LDA <Counter_1  
04100. AND #$08 ; Only interested in a tic counter firing every 8th tick 
04101. ASL A  
04102. ASL A  
04103. ASL A ; Shift the value up 3 (makes $00, $40) 
04104. STA <Title_ObjFlags,X ; Set the object flags (Goomba's "walk" is horizontal flipping of his sprite) 
04105. JMP Title_ObjDraw ; Draw goomba... 
04106.  
04107.  
04108. Title_DoBuzzyBeatle: 
04109.  
04110. ; Title_ObjVar2 is used as a flag to indicate the buzzy was hit whe non-zero 
04111. LDA Title_ObjVar2,X  
04112. BNE PRG024_B51D ; If <> 0, jump to PRG024_B51D 
04113.  
04114. LDA <Title_ObjX+2,X ; Buzzy beatle 
04115. SUB <Title_ObjX+7 ; Koopa shell 
04116. CMP #16  
04117. BGE PRG024_B543 ; If the distance between the buzzy beatle and koopa shell is >= 16, jump to PRG024_B543 
04118.  
04119. INC Title_ObjVar2,X ; Otherwise, Title_ObjVar2 = 1 
04120.  
04121. PRG024_B51D: 
04122. ; Buzzy beatle shell was hit 
04123.  
04124. LDA <Title_ObjXVel+2,X 
04125. BNE PRG024_B52D ; If X velocity is non-zero, jump to PRG024_B52D 
04126.  
04127. LDA #16  
04128. STA <Title_ObjXVel+2,X ; X velocity = 16 
04129.  
04130. LDA #-64 
04131. STA <Title_ObjYVel+2,X ; Y velocity = -64 
04132.  
04133. LDA #$80  
04134. STA <Title_ObjFlags,X ; Vertically flipped 
04135.  
04136. PRG024_B52D: 
04137. ; Buzzy beatle shell is flying away... 
04138.  
04139. ; Y velocity += FALL_OBJECT ("gravity") 
04140. LDA <Title_ObjYVel+2,X 
04141. ADD #FALL_OBJECT 
04142. STA <Title_ObjYVel+2,X 
04143.  
04144. ; X/Y velocities 
04145. JSR Title_ObjXVelApply  
04146. JSR Title_ApplyYVelFall  
04147.  
04148. LDA <Title_YPosHi+2,X 
04149. BEQ PRG024_B553 ; If "high" part of Y position is zero, jump to PRG024_B553 
04150.  
04151. ; Otherwise, set state = 0 (remove) 
04152. LDA #$00 
04153. STA <Title_ObjStates,X 
04154. RTS ; Return 
04155.  
04156.  
04157. PRG024_B543: 
04158. JSR Title_ObjCommonXYVel ; Handle velocity standard 
04159. BNE PRG024_B553 ; If buzzy beatle shell hasn't hit the floor yet, jump to PRG024_B553 
04160.  
04161. LDA #$20  
04162. SUB <Title_ObjYVel+2,X  
04163. BLT PRG024_B551 ; As long as y velocity is less than $20, jump to PRG024_B551 
04164.  
04165. LDA #$00 ; Set Y velocity to zero 
04166.  
04167. PRG024_B551: 
04168. STA <Title_ObjYVel+2,X ; Update Y Vel 
04169.  
04170. PRG024_B553: 
04171. JMP Title_ObjDraw ; Draw buzzy beatle shell... 
04172.  
04173.  
04174. Title_DoKoopaShell: 
04175. LDA <Title_ObjStates,X 
04176. SUB #$02  
04177. JSR DynJump ; Jump based on state - 2 (because state 0 is "removed", state 1 is init, so we're at least in state 2) 
04178.  
04179. ; THESE MUST FOLLOW DynJump FOR THE DYNAMIC JUMP TO WORK!! 
04180. .word KS_BonkMario_HitFloor ; 0 - Bonks Mario in the head, hits the floor 
04181. .word KS_Kick_LuigiCatch ; 1 - Mario kicks the shell, and Luigi catches it 
04182. .word KS_LuigiKick_MarioCatch ; 2 - Luigi kicks the shell, Mario catches it 
04183. .word KS_MarioCarry_KickWrapAround ; 3 - Mario holds the shell, kicks it out, shell wraps around screen 
04184. .word KS_HitMario ; 4 - Hit Mario, causing him to power down 
04185.  
04186. KS_BonkMario_HitFloor: 
04187. JSR Title_ObjCommonXYVel 
04188. BNE PRG024_B575 ; If koopa shell hasn't hit the floor yet, jump to PRG024_B575 
04189.  
04190. INC <Title_ObjStates,X ; Go to next state 
04191.  
04192. LDA #$00  
04193. STA <Title_ObjXVel+2,X ; X velocity = 0 
04194. BEQ PRG024_B589 ; Jump (technically always) to PRG024_B589 
04195.  
04196. PRG024_B575: 
04197. LDA <Title_ObjY+2,X 
04198. CMP #144 
04199. BLT PRG024_B589 ; If koopa shell Y position is less than $90, jump to PRG024_B589 
04200.  
04201. ; Shell Y pos >= 144... (shell bonks Mario on the head) 
04202.  
04203. LDA <Title_ObjXVel+2,X 
04204. BNE PRG024_B589 ; If the X velocity is not zero, jump to PRG024_B589 
04205.  
04206. LDA #$e8  
04207. STA <Title_ObjXVel+2,X ; XVel = $E8 
04208. STA <Title_ObjYVel+2,X ; YVel = $E8 
04209.  
04210. LDA #$10 
04211. STA <Title_ObjMLBonkTick ; Title_ObjMLBonkTick = $10 (Mario got bonked on the head) 
04212.  
04213. PRG024_B589: 
04214. JMP KS_SpinAnimAndDraw ; Shell common end code.. 
04215.  
04216.  
04217. KS_Kick_LuigiCatch: 
04218. JSR Title_ObjCommonXYVel ; Handle velocity standard 
04219.  
04220. LDA <Title_ObjMLQueue 
04221. AND #$10  
04222. BEQ PRG024_B59D ; If Title_ObjMLQueue bit 4 was not set (kick shell), jump to PRG024_B59D 
04223.  
04224. LDA #10  
04225. STA <Title_ObjMLKickTick ; Title_ObjMLKickTick = 10 (puts his foot out!) 
04226. LDA #$30  
04227. STA <Title_ObjXVel+2,X ; X velocity = $30 
04228.  
04229. PRG024_B59D: 
04230. LDA <Title_XPosHi+2,X  
04231. BEQ PRG024_B5A5 ; If the "high" part of the X position is zero, jump to PRG024_B5A5 
04232.  
04233. ; Otherwise, X Velocity = 0 (stop shell) 
04234. LDA #$00  
04235. STA <Title_ObjXVel+2,X 
04236.  
04237. PRG024_B5A5: 
04238. LDA <Title_ObjMLHold+1 
04239. BEQ PRG024_B5AB ; If Luigi is not holding the shell, jump to PRG024_B5AB 
04240.  
04241. ; Otherwise... 
04242. INC <Title_ObjStates,X ; Next state... 
04243.  
04244. PRG024_B5AB: 
04245. JMP KS_SpinAnimAndDraw ; Shell common end code.. 
04246.  
04247.  
04248. KS_LuigiKick_MarioCatch: 
04249. LDA <Title_ObjMLHold+1 
04250. BEQ PRG024_B5BB ; If Luigi is NOT holding the shell, jump to PRG024_B5BB 
04251.  
04252. LDA #-48 
04253. STA <Title_ObjXVel+2,X ; X Velocity = -48 
04254. LDY #$01 ; Luigi carries the shell 
04255. JMP KS_ShellCarry ; Do KS_ShellCarry 
04256.  
04257. PRG024_B5BB: 
04258. ; Luigi is not holding the shell... 
04259.  
04260. JSR Title_ObjCommonXYVel ; Handle velocity standard 
04261.  
04262. LDA <Title_ObjX+2,X 
04263. CMP #56 
04264. BGE PRG024_B5D0 ; If the shell's X position is >= 56, jump to PRG024_B5D0 
04265.  
04266. LDA <Title_ObjXVel+2,X 
04267. BEQ PRG024_B5D0 ; If the shell's X velocity is zero, jump to PRG024_B5D0 
04268.  
04269. LDA #$00  
04270. STA <Title_ObjXVel+2,X ; Shell's X velocity = 0 
04271. LDA #-48 
04272. STA <Title_ObjYVel ; MARIO's Y velocity = -48 
04273.  
04274. PRG024_B5D0: 
04275. LDA <Title_ObjMLHold 
04276. BEQ PRG024_B5D6 ; If Mario is not holding it, jump to PRG024_B5D6 
04277.  
04278. INC <Title_ObjStates,X ; Next state.. 
04279.  
04280. PRG024_B5D6: 
04281. JMP KS_SpinAnimAndDraw ; Shell common end code... 
04282.  
04283.  
04284. KS_MarioCarry_KickWrapAround: 
04285. LDA <Title_ObjMLHold 
04286. BEQ PRG024_B5E2 ; If Mario is NOT holding the shell, jump to PRG024_B5E2 
04287.  
04288. LDY #$00 ; Mario carries the shell 
04289. JMP KS_ShellCarry ; Do KS_ShellCarry 
04290.  
04291. PRG024_B5E2: 
04292. JSR Title_ObjCommonXYVel ; Handle velocity standard 
04293.  
04294. LDA #48 
04295. STA <Title_ObjXVel+2,X ; X velocity = 48 
04296.  
04297. LDA <Title_XPosHi+2,X  
04298. BEQ PRG024_B5FD ; If "high" part of X position is zero, jump to PRG024_B5FD 
04299.  
04300. ; Otherwise, shell's X position (including "high") amount to -16 (wrap around the screen!) 
04301. LDA #$ff  
04302. STA <Title_XPosHi+2,X  
04303. LDA #-16 
04304. STA <Title_ObjX+2,X 
04305.  
04306. LDA #48 
04307. STA Title_ObjVar,X ; Title_ObjVar = 48 (just puts in a delay until actually checking if Mario was hit) 
04308.  
04309. INC <Title_ObjStates,X ; Next state... 
04310. RTS ; Return! 
04311.  
04312.  
04313. PRG024_B5FD: 
04314. JMP KS_SpinAnimAndDraw ; Shell common end code... 
04315.  
04316. KS_HitMario: 
04317. LDA Title_ObjVar,X 
04318. BNE PRG024_B627 ; If ObjVar <> 0, jump to PRG024_B627 
04319.  
04320. LDA <Title_ObjMPowerDown 
04321. BNE PRG024_B621 ; If Mario is powering down, jump to  
04322.  
04323. JSR Title_ObjCommonXYVel ; Handle velocity standard 
04324.  
04325. LDA <Title_XPosHi+2,X  
04326. BNE PRG024_B621 ; If shell's X "high" part is non-zero, jump to PRG024_B621 
04327.  
04328. LDA <Title_ObjMLPower  
04329. BEQ PRG024_B621 ; If Mario's power level is 0 (small), jump to PRG024_B621 
04330.  
04331. LDA <Title_ObjX 
04332. SUB <Title_ObjX+2,X 
04333. CMP #16 
04334. BGE PRG024_B621 ; If the shell greater than 16 pixels away from Mario, jump to PRG024_B621 
04335.  
04336. LDA #44 
04337. STA <Title_ObjMPowerDown ; Title_ObjMPowerDown = 44 (power down Mario!) 
04338.  
04339. PRG024_B621: 
04340. JSR Title_ObjCommonFinale ; Do common finale code 
04341. JSR KS_SpinAnimAndDraw ; Shell common end code... 
04342.  
04343. PRG024_B627: 
04344. RTS ; Return 
04345.  
04346. KS_SpinAnimAndDraw: 
04347. LDA <Title_ObjXVel+2,X 
04348. BEQ PRG024_B642 ; If shell's X velocity = 0, jump to PRG024_B642 
04349.  
04350. LDA <Title_ObjMPowerDown 
04351. BNE PRG024_B642 ; If Mario is currently powering down, jump to PRG024_B642 
04352.  
04353. ; Otherwise, shell is moving, do spin! 
04354. LDA <Counter_1 
04355. AND #$06 ; A = Counter_1 & 6 
04356. PHA ; Save 'A' 
04357.  
04358. LSR A ; Shift right 1 (0 - 3) 
04359. STA Title_ObjFrame,X ; Store as frame 
04360. PLA ; Retore 'A' 
04361.  
04362. AND #$04 ; Just bit 2... 
04363. ASL A  
04364. ASL A  
04365. ASL A  
04366. ASL A ; Becomes 0 or $40 (horizontal flip) 
04367. STA <Title_ObjFlags,X ; Store as flag 
04368.  
04369. PRG024_B642: 
04370. JMP Title_ObjDraw ; Draw objects and don't come back  
04371.  
04372. KS_Carry_Xoff: 
04373. .byte -12, -10, -6, -2, 2, 6, 10, 12 ; When carrier not horizontally flipped 
04374. .byte 12, 10, 6, 2, -2, -6, -10, -12 ; When carrier is horizontally flipped 
04375.  
04376. KS_ShellCarry: 
04377. ; 'Y' specifies the "carrier" (0 = Mario, 1 = Luigi) 
04378.  
04379. ; Koopa shell's X and XHi coordinate is same as carrier's  
04380. LDA Title_ObjX,Y 
04381. STA <Title_ObjX+2,X  
04382. LDA Title_XPosHi,Y 
04383. STA <Title_XPosHi+2,X 
04384.  
04385. ; Koopa shell's Y position = carrier's Y + 13 
04386. LDA Title_ObjY,Y 
04387. ADD #13 
04388. STA <Title_ObjY+2,X 
04389.  
04390. LDA Title_ObjMLFlags,Y ; Get carrier's flags (specifically, we're only checking "zero" or "non-zero", even more specifically, "(not) horizontally flipped") 
04391.  
04392. PHP ; Save processor status (so it's not effected by the "bonk" load) 
04393. LDA Title_ObjMLBonkTick,Y ; Get bonk ticks 
04394. PLP ; Restore processor status 
04395.  
04396. PHA ; Save 'A' (bonk ticks) 
04397. BEQ PRG024_B675 ; If flags = 0, jump to PRG024_B675 
04398.  
04399. ADD #$08 ; Otherwise, add 8 to the "bonk ticks" (use reversed values from KS_Carry_Xoff) 
04400.  
04401. PRG024_B675: 
04402. TAY ; Y = bonk ticks (+8) 
04403. LDA KS_Carry_Xoff,Y ; Get KS_Carry_Xoff[Y] 
04404. BPL PRG024_B67D ; If not negative, jump to PRG024_B67D 
04405.  
04406. DEC <Title_XPosHi+2,X ; Otherwise, shell's "high" X position-- (put to the left of Mario) 
04407.  
04408. PRG024_B67D: 
04409. ADD <Title_ObjX+2,X  
04410. STA <Title_ObjX+2,X ; Add X offset to shell's X 
04411. BCC PRG024_B686 ; If it hasn't overflowed, jump to PRG024_B686 
04412.  
04413. ; Otherwise, "high" X position increments 
04414. INC <Title_XPosHi+2,X  
04415.  
04416. PRG024_B686: 
04417. PLA ; Restore 'A' (bonk ticks) 
04418. BNE PRG024_B68C ; If bonk ticks are non-zero, jump to PRG024_B68C 
04419. JMP Title_ObjDraw ; Draw shell... 
04420.  
04421. PRG024_B68C: 
04422. LDA #$00  
04423. JMP PRG024_B6F1 ; Hijacks Title_ObjDraw, using sprite zero instead! (for display priority) 
04424.  
04425. ; Title_ObjCommonXYVel 
04426. ; 
04427. ; A common, reusable function for objects which applies their gravity 
04428. ; and X/Y velocities, and prevents them from going below YPos 176 
04429. Title_ObjCommonXYVel: 
04430.  
04431. ; Add FALL_OBJECT to this object's Y velocity 
04432. LDA <Title_ObjYVel+2,X 
04433. ADD #FALL_OBJECT 
04434. STA <Title_ObjYVel+2,X 
04435.  
04436. JSR Title_ApplyYVelFall ; Update and apply Y velocity 
04437. JSR Title_ObjXVelApply ; Apply X velocity 
04438.  
04439. ; Prevents Y position from falling beneath 176 
04440. LDA <Title_ObjY+2,X 
04441. AND #$f0  
04442. CMP #176 
04443. BNE PRG024_B6A8  
04444.  
04445. STA <Title_ObjY+2,X 
04446.  
04447. PRG024_B6A8: 
04448. RTS ; Return 
04449.  
04450. ; For both of these, the first value is used if the object is off to the right, 
04451. ; otherwise the second value for when they are off to the left 
04452. Title_ObjXLimit: .byte -16, 48 ; Limits for how far off the side of the screen they can go 
04453. Title_ObjXLimitHi: .byte $FF, $00 ; Respective 16-bit sign extensions 
04454.  
04455.  
04456. ; Common finale for minor objects 
04457. Title_ObjCommonFinale: 
04458.  
04459. LDY #$00 ; Y = 0 
04460. LDA <Title_XPosHi+2,X ; A = "high" part of the X position of this object 
04461. BEQ PRG024_B6C7 ; If its zero, jump to PRG024_B6C7 
04462. BPL PRG024_B6B6 ; If it is > 0 (off the right side), jump to PRG024_B6B6 
04463.  
04464. INY ; If it is < 0 (off the left side), Y = 1 
04465.  
04466. PRG024_B6B6: 
04467. ; There is a "high" part of the X coordinate in use... 
04468.  
04469. LDA <Title_ObjX+2,X ; Get the X coordinate 
04470. ADD Title_ObjXLimit,Y ; Add an appropriate extreme value 
04471.  
04472. ; 16-bit propogation 
04473. LDA <Title_XPosHi+2,X  
04474. ADC Title_ObjXLimitHi,Y 
04475.  
04476. BEQ PRG024_B6C7 ; If there hasn't been an overflow, jump to PRG024_B6C7 
04477.  
04478. ; Otherwise, set this object's state to zero (removing it)  
04479. LDA #$00  
04480. STA <Title_ObjStates,X 
04481.  
04482. PRG024_B6C7: 
04483. RTS ; Return 
04484.  
04485. ; Showing "default" usage per object, but Title_ObjFrane can alter which one is used 
04486. Title_ObjPatterns: 
04487. .byte $F9, $F9 ; 0 = Starman 
04488. .byte $F5, $F5 ; 1 = Mushroom 
04489. .byte $F1, $F3 ; 2 = Super Leaf 
04490. .byte $FB, $FD ; 3 = Goomba 
04491. .byte $FF, $FF  
04492. .byte $DD, $DD ; 4 = Buzzy Beatle 
04493. .byte $D5, $D5 ; 5 = Koopa shell 
04494.  
04495. ; Auxillary patterns (accessed by "Title_ObjFrame" values) 
04496. .byte $D7, $D9 
04497. .byte $DB, $DB 
04498. .byte $D7, $D9 
04499.  
04500. ; Each of these tables contains one value per object index (0-5) 
04501. Title_ObjPatOff: .byte $00, $02, $04, $06, $0A, $0C ; Root offset per object for Title_ObjPatterns 
04502. Title_ObjSprRAMOff: .byte $40, $48, $50, $68, $60, $58 ; Offset into Sprite_RAM per object 
04503. Title_ObjPal: .byte $03, $00, $00, $02, $02, $03 ; Paletter per object 
04504.  
04505. ; Title_ObjDraw 
04506. ; 
04507. ; Not literally "draw", of course, but set up their hardware 
04508. ; sprites in Sprite_RAM to be "drawn"... 
04509. Title_ObjDraw: 
04510. LDA Title_ObjSprRAMOff,X ; Get the offset into Sprite_RAM 
04511.  
04512. PRG024_B6F1: 
04513. PHA ; Save this value 
04514.  
04515. LDA Title_ObjPal,X  
04516. STA <Temp_Var3 ; Temp_Var3 = this object's palette index 
04517.  
04518. LDA Title_ObjFrame,X 
04519. ASL A  
04520. ADD Title_ObjPatOff,X ; Use the pattern specified in Title_ObjPatOff + 2 * Title_ObjFrame 
04521. TAY ; Y = A (the pattern value) 
04522.  
04523. ; Temp_Var1 and Temp_Var2 hold the first and second pattern value for this object 
04524. LDA Title_ObjPatterns,Y  
04525. STA <Temp_Var1  
04526. LDA Title_ObjPatterns+1,Y 
04527. STA <Temp_Var2  
04528.  
04529. PLA ; Restore 'A' (Sprite_RAM offset) 
04530. TAY ; Y = A 
04531.  
04532. ; Set the Y position of the object to its first/second sprites 
04533. LDA <Title_ObjY+2,X 
04534. STA Sprite_RAM,Y 
04535. STA Sprite_RAM+$04,Y 
04536.  
04537. ; Set the X position of object to its first/second sprites (8 pixels apart) 
04538. LDA <Title_ObjX+2,X 
04539. STA Sprite_RAM+$03,Y 
04540. ADD #$08  
04541. STA Sprite_RAM+$07,Y 
04542.  
04543. ; Store the attributes for both sprites 
04544. LDA <Temp_Var3 ; Get the selected palette value 
04545. ORA <Title_ObjFlags,X ; Apply the other flags 
04546. STA Sprite_RAM+$02,Y 
04547. STA Sprite_RAM+$06,Y 
04548.  
04549. LDA <Temp_Var1 ; Get first pattern value of this object 
04550. PHA ; Save 'A' 
04551. STA Sprite_RAM+$01,Y ; Store pattern for first sprite 
04552.  
04553. LDA <Temp_Var2 ; Get second pattern value of this object 
04554. STA Sprite_RAM+$05,Y ; Store pattern for second sprite 
04555.  
04556. LDA <Title_ObjFlags,X 
04557. BEQ PRG024_B742 ; If this object's flags value = 0, jump to PRG024_B742 
04558.  
04559. ; Otherwise, reverse the patterns 
04560. ; NOTE: This is making the assumption that the only value stored in ObjFlags 
04561. ; is one to horizontally flip the sprite!! 
04562. LDA <Temp_Var2  
04563. STA Sprite_RAM+$01,Y 
04564. LDA <Temp_Var1  
04565. STA Sprite_RAM+$05,Y 
04566.  
04567. PRG024_B742: 
04568. PLA ; Restore 'A' (first pattern) 
04569. CMP <Temp_Var2 
04570. BNE PRG024_B754 ; If it's not the same as the second pattern, jump to PRG024_B754 
04571.  
04572. ; Otherwise, flip the sprites 
04573. LDA Sprite_RAM+$02,Y 
04574. AND #$bf ; Keep everything but the horizontal flip flag  
04575. STA Sprite_RAM+$02,Y 
04576.  
04577. ORA #SPR_HFLIP ; Apply the horizontal flip flag 
04578. STA Sprite_RAM+$06,Y 
04579.  
04580. PRG024_B754: 
04581. ; NOTE: The 1P/2P menu koopas hijack code here to take advantage of disabling their sprites! 
04582.  
04583. LDA <Title_XPosHi+2,X 
04584. BEQ PRG024_B75D ; If the "high" part of the X coordinate is zero, jump to PRG024_B75D 
04585.  
04586. ; Otherwise, disable the first sprite sprite by setting its Y value out of range 
04587. LDA #$f8  
04588. STA Sprite_RAM,Y 
04589.  
04590. PRG024_B75D: 
04591.  
04592. ; Take the object's X coordinate, add 8, and if there's been a carry OR the "high" part  
04593. ; of the X coordinate is otherwise non-zero, disable the second half of the sprite 
04594. LDA <Title_ObjX+2,X 
04595. ADD #$08  
04596. LDA #$00  
04597. ADC <Title_XPosHi+2,X 
04598. BEQ PRG024_B76D  
04599.  
04600. ; Disable the second sprite 
04601. LDA #$f8  
04602. STA Sprite_RAM+$04,Y 
04603.  
04604. PRG024_B76D: 
04605. RTS ; Return 
04606.  
04607.  
04608. Title_ObjXVelApply:  
04609. INX  
04610. INX ; X += 2 (going to use A Mario/Luigi included function, which uses a larger index span... objects start at index 2) 
04611.  
04612. JSR Title_AddVel_toPos ; Apply X velocity as is 
04613.  
04614. DEX  
04615. DEX ; X -= 2 (restoring objects to their local index) 
04616. RTS ; Return 
04617.  
04618.  
04619. Title_ApplyYVelFall: 
04620. ; X is 0-5, an index to one of the "minor" objects 
04621.  
04622. LDA <Title_ObjYVel+2,X 
04623. BMI PRG024_B782 ; If object's Y velocity < 0, jump to PRG024_B782 
04624.  
04625. CMP #FALLRATE_OBJECTMAX 
04626. BLS PRG024_B782 ; If object's Y velocity < FALLRATE_OBJECTMAX, jump to PRG024_B782 
04627.  
04628. ; Prevent objects from falling faster than FALLRATE_OBJECTMAX  
04629. LDA #$60 
04630. STA <Title_ObjYVel+2,X 
04631.  
04632. PRG024_B782: 
04633. INX  
04634. INX ; X += 2 (going to use A Mario/Luigi included function, which uses a larger index span... objects start at index 2) 
04635.  
04636. JSR Title_ApplyYVel ; Apply Y velocity 
04637.  
04638. DEX  
04639. DEX ; X -= 2 (restoring objects to their local index) 
04640. RTS ; Return 
04641.  
04642. Title_Menu_Koopa_SpriteRAMOff: .byte $00, $20, $40, $60 ; Offsets into Sprite_RAM per menu koopa 
04643.  
04644. Title_Menu_UpdateKoopas: 
04645. JSR PRG024_SpriteClear ; Clear all sprites 
04646.  
04647. LDX #$03 
04648.  
04649. PRG024_B793: 
04650. LDA <Title_ObjStates,X 
04651. BEQ PRG024_B7A4 ; If this object's state = 0, jump to PRG024_B7A4 
04652.  
04653. CMP #$01  
04654. BNE PRG024_B7A1 ; If this object's state <> 1, jump to PRG024_B7A1 
04655.  
04656. ; State 1: Initialize this koopa 
04657. JSR Title_Menu_InitKoopa 
04658. JMP PRG024_B7A4 ; Jump down to PRG024_B7A4 
04659.  
04660. PRG024_B7A1: 
04661. ; Other states: Just update! 
04662. JSR Title_Menu_UpdateKoopa 
04663.  
04664. PRG024_B7A4: 
04665. DEX ; X-- 
04666. BPL PRG024_B793 ; If X >= 0, loop! 
04667.  
04668. RTS ; Return 
04669.  
04670.  
04671. ; Title_Menu_InitKoopa 
04672. ; 
04673. ; Initializes the data for one of the 1P/2P koopas 
04674. ; that march along (with the one fast straggler) 
04675. Title_Menu_InitKoopa: 
04676. INC <Title_ObjStates,X ; Increment this object's state 
04677.  
04678. ; Set this object's XHi / X position to -16 
04679. LDA #$ff 
04680. STA <Title_XPosHi+2,X 
04681. LDA #-16 
04682. STA <Title_ObjX+2,X 
04683.  
04684. LDA #8 ; Most of the menu koopas run at X Velocity 8 
04685. CPX #$03 
04686. BNE PRG024_B7BA ; If X <> 3 (the straggler koopa), jump to PRG024_B7BA 
04687.  
04688. LDA #18 ; The straggler koopa runs at X velocity 18 
04689.  
04690. PRG024_B7BA: 
04691. STA <Title_ObjXVel+2,X ; Set this koopa's velocity 
04692. RTS ; Return 
04693.  
04694.  
04695. ; Y offsets per sprite of the koopa 
04696. Title_Menu_Koopa_SprYOff: 
04697. .byte -32, -16, 0 
04698.  
04699. ; This defines an X coordinate per-menu koopa of when to signal the 
04700. ; next koopa (unless zero, which means "never", used for the straggler) 
04701. ; Hence, $90 is "late" for the straggler 
04702. Title_Menu_Koopa_SignalX: 
04703. .byte $20, $20, $90, $00 
04704.  
04705. ; Attributes set per frame of koopa 
04706. Title_Menu_Koopa_Attr: 
04707. .byte $42, $43, $42 ; First sprite of koopas 
04708. .byte $42, $42, $42 ; Second sprite of koopas 
04709.  
04710. ; Patterns set first sprite per frame of koopa 
04711. Title_Menu_Koopa_Patterns1: 
04712. .byte $B1, $E5, $E9 ; First frame of koopas 
04713. .byte $B1, $E5, $EF ; Second frame of koopas 
04714.  
04715. ; Patterns set second sprite per frame of koopa 
04716. Title_Menu_Koopa_Patterns2: 
04717. .byte $E1, $E3, $E7 ; First frame of koopas 
04718. .byte $E1, $EB, $ED ; Second frame of koopas 
04719.  
04720.  
04721. ; Title_Menu_UpdateKoopa 
04722. ; 
04723. ; Updates and "draws" the menu koopas 
04724. Title_Menu_UpdateKoopa: 
04725. JSR Title_ObjXVelApply ; Koopas only need X velocity! 
04726. JSR Title_ObjCommonFinale ; Do common finale code 
04727.  
04728. LDA <Title_XPosHi+2,X 
04729. BNE PRG024_B7F1 ; If the "high" part of the koopa's X position is zero, jump to PRG024_B7F1 
04730.  
04731. ; This signals the next menu koopa to come marching in when the current leader 
04732. ; hits a particular coordinate to do so... 
04733. LDA Title_Menu_Koopa_SignalX,X 
04734. BEQ PRG024_B7F1 ; If Title_Menu_Koopa_SignalX[X] = 0, jump to PRG024_B7F1 (do nothing) 
04735.  
04736. CMP <Title_ObjX+2,X 
04737. BGE PRG024_B7F1 ; If Title_Menu_Koopa_SignalX[X] >= the koopa's X position, jump to PRG024_B7F1 
04738.  
04739. INX ; Next koopa 
04740.  
04741. LDA <Title_ObjStates,X  
04742. BNE PRG024_B7F0 ; If this koopa's state <> 0, jump to PRG024_B7F0 (only signal once!) 
04743.  
04744. INC <Title_ObjStates,X ; Move next koopa to next state 
04745.  
04746. PRG024_B7F0: 
04747. DEX ; Back to this koopa 
04748.  
04749. PRG024_B7F1: 
04750. LDA <Counter_1 
04751. LSR A  
04752. LSR A ; A = Counter_1 >> 2 
04753.  
04754. CPX #$03  
04755. BEQ PRG024_B7FA ; If we're on the straggler koopa, jump to PRG024_B7FA 
04756.  
04757. LSR A ; Otherwise, shift one more time... (slightly slower than the straggler)  
04758.  
04759. PRG024_B7FA: 
04760. AND #$01 ; Only looking for 0/1 pattern 
04761. BEQ PRG024_B800 ; If 0, jump to PRG024_B800 
04762. LDA #$03 ; Otherwise, change to 3 (thus 0 or 3) 
04763.  
04764. PRG024_B800: 
04765. STA Title_ObjFrame,X ; Set frame as 0 or 3 
04766.  
04767. STX <Temp_Var3 ; Store koopa index into Temp_Var3 
04768.  
04769. LDA <Title_ObjX+2,X  
04770. STA <Temp_Var1 ; Store koopa X pos into Temp_Var1 
04771.  
04772. LDA Title_ObjFrame,X 
04773. STA <Temp_Var2 ; Store koopa frame into Temp_Var2 
04774.  
04775. LDY Title_Menu_Koopa_SpriteRAMOff,X ; Get Sprite_RAM offset for this koopa -> 'Y' 
04776.  
04777. LDX #$02 ; X = 2 (sprites to build) 
04778.  
04779. PRG024_B813: 
04780. LDA #186 ; A = 186 
04781. ADD Title_Menu_Koopa_SprYOff,X ; A += Title_Menu_Koopa_SprYOff[X] 
04782. STA Sprite_RAM,Y ; Store Y coordinate into first sprite 
04783. STA Sprite_RAM+$04,Y ; Store Y coordinate into second sprite 
04784.  
04785. TXA ; A = X (sprite to build loop counter) 
04786. PHA ; Save 'A' 
04787.  
04788. ADD <Temp_Var2 ; Add the frame (0 or 3) to 'A' 
04789. TAX ; X = A 
04790.  
04791. ; Setup the patterns 
04792. LDA Title_Menu_Koopa_Patterns1,X ; Get first pattern for this koopa 
04793. STA Sprite_RAM+$01,Y ; Store pattern value 
04794. LDA Title_Menu_Koopa_Patterns2,X ; Get second pattern for this koopa 
04795. STA Sprite_RAM+$05,Y ; Store pattern value 
04796.  
04797. LDX <Temp_Var3 ; X = koopa index 
04798. JSR PRG024_B754 ; Disable first and/or second sprite if off-screen 
04799.  
04800. PLA ; Restore 'A' (sprite to build loop counter) 
04801. TAX ; X = A 
04802.  
04803. ; Attributes set per sprite of koopa 
04804. LDA Title_Menu_Koopa_Attr,X 
04805. STA Sprite_RAM+$02,Y  
04806. LDA Title_Menu_Koopa_Attr+3,X 
04807. STA Sprite_RAM+$06,Y  
04808.  
04809. LDA <Temp_Var1 
04810. STA Sprite_RAM+$03,Y ; Store X position for first sprite of the koopa 
04811.  
04812. ADD #$08 ; Sprite X += 8 
04813. STA Sprite_RAM+$07,Y ; Store X position for second sprite of the koopa 
04814.  
04815. TYA  
04816. ADD #$08  
04817. TAY ; Y += 8 (next two sprites over) 
04818.  
04819. DEX ; X-- 
04820. BPL PRG024_B813 ; If X >= 0, loop! 
04821.  
04822. LDX <Temp_Var3 ; Restore koopa index to 'X' 
04823. RTS ; Return..! 
04824.  
04825.  
04826. Rescue_Princess: 
04827. ; NOTE: Debug menu jump to princess rescue jumps here 
04828.  
04829. ; Princess housing block graphics 
04830. LDA #$5c 
04831. STA PatTable_BankSel 
04832.  
04833. ; Princess housing background graphics 
04834. LDA #$5e 
04835. STA PatTable_BankSel+1 
04836.  
04837. JSR Reset_PPU_Clear_Nametables 
04838.  
04839. ; Disable display 
04840. LDA #$00 
04841. STA PPU_CTL1 
04842. STA PPU_CTL2 
04843.  
04844. ; Disable raster effects 
04845. LDA #$80 
04846. STA Raster_Effect 
04847.  
04848. ; Clears RAM $00-$F5 
04849. LDX #$f5 ; X = $F5 
04850. PRG024_B876: 
04851. LDA #$00 
04852. STA <Temp_Var1,X 
04853.  
04854. DEX ; X-- 
04855. BNE PRG024_B876 ; While X <> 0, loop! 
04856.  
04857. ; Scroll at lowest point 
04858. LDA #$ef 
04859. STA <Vert_Scroll 
04860.  
04861. LDA #%00101000 ; use 8x16 sprites, sprites use PT2 (NOTE: No VBlank trigger!) 
04862. STA PPU_CTL1  
04863. STA <PPU_CTL1_Copy ; Keep PPU_CTL1_Copy in sync! 
04864.  
04865. ; Entry $55 of Video_Upd_Table2 
04866. LDA #$55 
04867. ASL A 
04868. TAY 
04869.  
04870. ; Load base address of graphics 
04871. LDA Video_Upd_Table2,Y 
04872. STA <Video_Upd_AddrL  
04873. LDA Video_Upd_Table2+1,Y 
04874. STA <Video_Upd_AddrH  
04875.  
04876. JSR Video_Misc_Updates2 ; Load those graphics! 
04877.  
04878. LDA #%10101000 ; In addition to anything else specified by PPU_CTL1_Mod, Generate VBlank Resets, use 8x16 sprites, sprites use PT2 
04879. STA PPU_CTL1 ; Set above settings 
04880. STA <PPU_CTL1_Copy ; Keep PPU_CTL1_Copy in sync! 
04881.  
04882. PRG024_B8A0: 
04883. JSR GraphicsBuf_Prep_And_WaitVSyn2 ; VSync 
04884.  
04885. JSR Ending_ChamberScene ; Do the Princess Chamber scene, up through the Fade Out 
04886.  
04887. LDA <Ending_State 
04888. CMP #$07 
04889. BNE PRG024_B8A0 ; If Princess Chamber scene is still going on, loop! 
04890.  
04891. JMP Ending_Credits ; Jump to credits 
04892.  
04893.  
04894. Ending_ChamberScene: 
04895. JSR PRG024_SpriteClear ; Clear sprites 
04896.  
04897. LDA #$10  
04898. STA <Title_ObjMLSprRAMOff ; Mario's sprite RAM starts at Sprite_RAM + $10 
04899.  
04900. LDA #$28  
04901. STA <Title_ObjMLSprRAMOff+1 ; Princess's sprite RAM starts at Sprite_RAM + $28 
04902.  
04903. LDX #$02 ; X = 2 
04904. PRG024_B8BC: 
04905. LDA <Ending_Timer,X 
04906. BEQ PRG024_B8C2 ; If this ending timer = 0, jump to PRG024_B8C2 
04907.  
04908. DEC <Ending_Timer,X ; Otherwise, decrement it 
04909.  
04910. PRG024_B8C2: 
04911. DEX ; X-- 
04912. BPL PRG024_B8BC ; While X >= 0, loop 
04913.  
04914. JSR Ending_DoChamberScene ; Perform actions for the Princess's Chamber 
04915.  
04916. ; Title_CurMLIndex = 0 
04917. LDX #$00 
04918. STX <Title_CurMLIndex 
04919.  
04920. JSR Title_DrawMarioLuigi ; Draws Mario officially, but may be modified after this to Luigi 
04921.  
04922. LDA Player_Current 
04923. BEQ PRG024_B8E6 ; If Player is Mario, jump to PRG024_B8E6 
04924.  
04925. ; Luigi only... 
04926.  
04927. ; This is meant to colorize the Player as Luigi, but I think the loop condition is wrong 
04928. ; Seems to work anyway. Sort of a Schroedinbug without the fact that it will stop working 
04929. ; just because I pointed it out... 
04930. LDY #$24 ; Y = $24 
04931. PRG024_B8D6: 
04932. ; Use the Luigi palette 
04933. LDA Sprite_RAM+$02,Y 
04934. ORA #SPR_PAL2 
04935. STA Sprite_RAM+$02,Y 
04936.  
04937. ; Y -= 4 (previous sprite) 
04938. DEY 
04939. DEY 
04940. DEY 
04941. DEY 
04942.  
04943. CMP <Title_ObjMLSprRAMOff ; I think this is a mistake! Will compare to the attribute value! 
04944. BPL PRG024_B8D6 ; While ??, loop 
04945.  
04946. PRG024_B8E6: 
04947.  
04948. ; Title_CurMLIndex = 1 
04949. INX ; X = 1 
04950. STX <Title_CurMLIndex 
04951.  
04952. JSR Title_DrawMarioLuigi ; Actually draws the Princess 
04953.  
04954. RTS ; Return 
04955.  
04956. Ending_DoChamberScene: 
04957. LDA <Ending_State 
04958. JSR DynJump 
04959.  
04960. ; THESE MUST FOLLOW DynJump FOR THE DYNAMIC JUMP TO WORK!! 
04961. .word Ending_Init ; 0: Prepare the Princess chamber scene 
04962. .word Ending_FadeIn ; 1: Fade in 
04963. .word Ending_MarioAppears ; 2: Mario appears, music starts 
04964. .word Ending_LightsOn ; 3: Lights come on, Princess stands up 
04965. .word Ending_WalkToCenter ; 4: Mario and Princess walk to the center 
04966. .word Ending_PrincessSpeech ; 5: Princess's departing message 
04967. .word Ending_FadeOut ; 6: Fade out 
04968.  
04969. Ending_Init: 
04970. ; Set Mario's X 
04971. LDA #32 
04972. STA <Title_ObjX 
04973.  
04974. ; Set Princess's X 
04975. LDA #200 
04976. STA <Title_ObjX+1 
04977.  
04978. ; Set both Y = 160 
04979. LDA #160 
04980. STA <Title_ObjY 
04981. STA <Title_ObjY+1 
04982.  
04983. ; Mario standing 
04984. LDA #$18 
04985. STA <Title_ObjMLSprite 
04986.  
04987. ; Princess sobbing 
04988. LDA #$19 
04989. STA <Title_ObjMLSprite+1 
04990.  
04991. ; Mario turned to face, Princess turned away 
04992. LDA #SPR_HFLIP 
04993. STA <Title_ObjMLFlags 
04994. STA <Title_ObjMLFlags+1 
04995.  
04996. ; Super Mario 
04997. LDA #$01 
04998. STA <Title_ObjMLPower 
04999.  
05000. ; Set first ending timer to $0F 
05001. LDA #$0f 
05002. STA <Ending_Timer 
05003.  
05004. INC <Ending_State ; Ending_State = 1 
05005.  
05006. ; Initialize the princess speech dialog box 
05007.  
05008. ; EndText_CPos = 0 
05009. LDA #$00 
05010. STA <EndText_CPos 
05011.  
05012. ; EndText_VH = $29 
05013. LDA #$29 
05014. STA <EndText_VH 
05015.  
05016. ; EndText_VL = $48 
05017. LDA #$48 
05018. STA <EndText_VL 
05019.  
05020. RTS ; Return 
05021.  
05022. Ending_FadeIn: 
05023. LDA <Ending_Timer 
05024. BNE PRG024_B93D ; If the first ending timer has not expired, jump to PRG024_B93D 
05025.  
05026. INC <Ending_State ; Ending_State = 2 
05027.  
05028. ; Set first ending timer to $30 
05029. LDY #$30 
05030. STY <Ending_Timer 
05031.  
05032. PRG024_B93D: 
05033.  
05034.  
05035. ; Ending timer was init'ed to $F (15) so ... 
05036. LSR A 
05037. LSR A ; Ending timer / 4 
05038. ADD #$56 ; ... run command scripts $59, $58, $57, $56 (the "fade in" effect) 
05039.  
05040. STA Graphics_Queue ; Execute appropriate scripe 
05041.  
05042. RTS ; Return 
05043.  
05044. Ending_MarioAppears: 
05045. LDA <Ending_Timer 
05046. CMP #$01 
05047. BNE PRG024_B959 ; If ending timer does not have one tick left, jump to PRG024_B959 
05048.  
05049. ; Mario standing there 
05050. LDA #$02 
05051. STA <Title_ObjMLSprite 
05052.  
05053. ; Set ending timer 2 = $80 
05054. LDA #$80 
05055. STA <Ending_Timer+1 
05056.  
05057. ; Play finale music 
05058. LDA #MUS2A_ENDING 
05059. STA Sound_QMusic2 
05060.  
05061. PRG024_B959: 
05062. LDA <Ending_Timer+1 
05063. CMP #$01 
05064. BNE PRG024_B965 ; If second ending timer does not have one tick left, jump to PRG024_B965 
05065.  
05066. ; Set first ending timer = $13 
05067. LDA #$13 
05068. STA <Ending_Timer 
05069.  
05070. INC <Ending_State ; Ending_State = 3 
05071.  
05072. PRG024_B965: 
05073. RTS ; Return 
05074.  
05075. ; The "lights on" effect palette levels 
05076. Ending_LightsOnPalSet: 
05077. .byte $0F, $35, $30, $3B 
05078. .byte $0F, $23, $35, $3B 
05079. .byte $0F, $11, $3C, $3B 
05080. .byte $0F, $1C, $2C, $3B 
05081. .byte $0F, $0C, $1C, $3B 
05082.  
05083. Ending_LightsOn: 
05084. LDA <Ending_Timer 
05085. BEQ PRG024_B9BB ; If ending timer has expired, jump to PRG024_B9BB 
05086.  
05087. ; Second ending timer = $30 
05088. LDY #$30 
05089. STY <Ending_Timer+1 
05090.  
05091. AND #%00001100 
05092. TAY ; Y = 0, 4, 8, 12 (Ending_LightsOnPalSet level offset) 
05093.  
05094. LDX Graphics_BufCnt ; X = current graphics buffer count 
05095. TXA 
05096. ADD #$07 
05097. STA Graphics_BufCnt ; Make room for 7 bytes 
05098.  
05099. ; VRAM High/Low (for palette) 
05100. LDA #$3f 
05101. STA Graphics_Buffer,X 
05102. LDA #$04 
05103. STA Graphics_Buffer+1,X 
05104.  
05105. ; Run length of 4 
05106. LDA #$04 
05107. STA Graphics_Buffer+2,X 
05108.  
05109. ; Terminator 
05110. LDA #$00 
05111. STA Graphics_Buffer+7,X 
05112.  
05113. ; The four palette colors for the "lights on" effect 
05114. LDA Ending_LightsOnPalSet,Y 
05115. STA Graphics_Buffer+3,X 
05116. LDA Ending_LightsOnPalSet+1,Y 
05117. STA Graphics_Buffer+4,X 
05118. LDA Ending_LightsOnPalSet+2,Y 
05119. STA Graphics_Buffer+5,X 
05120. LDA Ending_LightsOnPalSet+3,Y 
05121. STA Graphics_Buffer+6,X 
05122.  
05123. PRG024_B9BB: 
05124. LDA <Ending_Timer+1 
05125. BNE PRG024_B9C9 ; If second ending timer has not expired, jump to PRG024_B9C9 (RTS) 
05126.  
05127. INC <Ending_State ; Ending_State = 4 
05128.  
05129. ; First ending timer = $80 
05130. LDA #$80 
05131. STA <Ending_Timer 
05132.  
05133. ; Princess stands up 
05134. LDA #$1a 
05135. STA <Title_ObjMLSprite+1 
05136.  
05137. PRG024_B9C9: 
05138. RTS ; Return 
05139.  
05140.  
05141. Ending_WalkToCenter: 
05142. LDA <Ending_Timer 
05143. BEQ PRG024_B9D7 ; If first ending timer has not expired, jump to PRG024_B9D7 
05144.  
05145. CMP #$60 
05146. BGE PRG024_B9D6 ; If ending timer >= $60, jump to PRG024_B9D6 (RTS) 
05147.  
05148. ; Princess turns around 
05149. LDA #$00 
05150. STA <Title_ObjMLFlags+1 
05151.  
05152. PRG024_B9D6: 
05153. RTS ; Return 
05154.  
05155. PRG024_B9D7: 
05156. LDA <Title_ObjX 
05157. CMP #104 
05158. BLT PRG024_B9EC ; If Mario's X < 104, jump to PRG024_B9EC 
05159.  
05160. ; Mario stands 
05161. LDA #$02 
05162. STA <Title_ObjMLSprite 
05163.  
05164. ; Princess stands 
05165. LDA #$1a 
05166. STA <Title_ObjMLSprite+1 
05167.  
05168. INC <Ending_State ; Ending_State = 5 
05169.  
05170. ; First Ending Timer = $B0 
05171. LDA #$b0 
05172. STA <Ending_Timer 
05173.  
05174. RTS ; Return 
05175.  
05176. PRG024_B9EC: 
05177.  
05178. ; Second ending timer = $50 
05179. LDA #$50 
05180. STA <Ending_Timer+1 
05181.  
05182. ; Mario steps to the right 
05183. INC <Title_ObjX 
05184.  
05185. ; Princess steps to the left 
05186. DEC <Title_ObjX+1 
05187.  
05188. LDA <Counter_1 
05189. AND #%00001100 
05190. LSR A 
05191. LSR A 
05192. TAY ; Y = 0 to 3 
05193.  
05194. ; Set Mario's walk frame 
05195. LDA Title_ObjMLWalkSprite+4,Y 
05196. STA <Title_ObjMLSprite  
05197.  
05198. ; Set Princess's walk frame 
05199. LDA Title_ObjMLWalkSprite+12,Y 
05200. STA <Title_ObjMLSprite+1 
05201.  
05202. RTS ; Return 
05203.  
05204.  
05205. Ending_PrincessSpeech: 
05206. LDA <Ending_Timer 
05207. BNE PRG024_BA0D ; If timer not expired, jump to PRG024_BA0D (RTS) 
05208.  
05209. JMP PRG024_BA2B ; Otherwise, jump to PRG024_BA2B 
05210.  
05211. PRG024_BA0D: 
05212. RTS ; Return 
05213.  
05214.  
05215. Ending_FadeOut: 
05216. LDA <Ending_Timer 
05217. BNE PRG024_BA19 ; If first ending timer has not expired, jump to PRG024_BA19 
05218.  
05219. LDA <Ending_Timer+1 
05220. BNE PRG024_BA18 ; If second ending timer has not expired, jump to PRG024_BA18 (RTS) 
05221.  
05222. INC <Ending_State ; Ending_State = 7 
05223.  
05224. PRG024_BA18: 
05225. RTS ; Return 
05226.  
05227. PRG024_BA19: 
05228.  
05229. ; Ending timer was init'ed to $F (15) so ... 
05230. LSR A 
05231. LSR A ; Ending timer / 4 
05232. STA <Temp_Var1 ; Temp_Var1 = 0 to 3 
05233.  
05234. ; Execute $5A, $59, $58, $57 (fade out) 
05235. LDA #$5a 
05236. SUB <Temp_Var1 
05237. STA Graphics_Queue 
05238.  
05239. ; Second ending timer = $10 
05240. LDA #$10 
05241. STA Ending_Timer+1 
05242.  
05243. RTS ; Return 
05244.  
05245. PRG024_BA2B: 
05246. LDA <EndText_State 
05247. JSR DynJump 
05248.  
05249. ; THESE MUST FOLLOW DynJump FOR THE DYNAMIC JUMP TO WORK!! 
05250. .word EndText_DrawDiagBox ; 0: Draw the dialog box 
05251. .word EndText_DoPrincessText ; 1: Do the text 
05252. .word EndText_Wait ; 2: Waits for timer to expire, then advances Ending_State 
05253.  
05254.  
05255. PDiagBox_R1: .byte $94, $90, $90, $90, $90, $90, $90, $90, $90, $90, $90, $90, $90, $90, $90, $90, $96 
05256. PDiagBox_R2: .byte $92, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $FE, $93 
05257. PDiagBox_R3: .byte $95, $91, $91, $91, $91, $91, $91, $91, $91, $91, $91, $91, $91, $91, $91, $91, $97 
05258.  
05259. PDiagBox_RowOffs: 
05260. .byte (PDiagBox_R1 - PDiagBox_R1), (PDiagBox_R2 - PDiagBox_R1), (PDiagBox_R2 - PDiagBox_R1), (PDiagBox_R2 - PDiagBox_R1) 
05261. .byte (PDiagBox_R2 - PDiagBox_R1), (PDiagBox_R2 - PDiagBox_R1), (PDiagBox_R2 - PDiagBox_R1), (PDiagBox_R3 - PDiagBox_R1) 
05262. PDiagBox_RowOffs_End 
05263.  
05264.  
05265. EndText_DrawDiagBox: 
05266.  
05267. LDX Graphics_BufCnt ; X = buffer count 
05268.  
05269. ; Set current VRAM address  
05270. LDA <EndText_VH 
05271. STA Graphics_Buffer,X 
05272. LDA <EndText_VL  
05273. STA Graphics_Buffer+1,X 
05274.  
05275. ADD #$20 ; 32 bytes to next row 
05276. STA <EndText_VL 
05277. BCC PRG024_BA87 
05278. INC <EndText_VH ; Apply carry 
05279. PRG024_BA87: 
05280. LDA #(PDiagBox_R2 - PDiagBox_R1) ; run count per row 
05281. STA Graphics_Buffer+2,X 
05282. STA <Temp_Var1 ; -> Temp_Var1 
05283.  
05284. LDY <EndText_CPos ; Y = current dialog box row 
05285. LDA PDiagBox_RowOffs,Y 
05286. TAY ; Y = offset to this row index 
05287.  
05288. PRG024_BA94: 
05289. ; Store next pattern in dialog box 
05290. LDA PDiagBox_R1,Y 
05291. STA Graphics_Buffer+3,X 
05292.  
05293. INY ; Y++ (next pattern for dialog box) 
05294. INX ; X++ (next index in graphics buffer) 
05295.  
05296. DEC <Temp_Var1 ; Temp_Var1-- 
05297. BNE PRG024_BA94 ; While Temp_Var1 > 0, loop! 
05298.  
05299. ; Insert terminator 
05300. LDA #$00 
05301. STA Graphics_Buffer+3,X 
05302.  
05303. ; X += 3 
05304. INX 
05305. INX 
05306. INX 
05307. STX Graphics_BufCnt 
05308.  
05309. INC <EndText_CPos ; Next row 
05310.  
05311. LDA <EndText_CPos 
05312. CMP #(PDiagBox_RowOffs_End - PDiagBox_RowOffs) 
05313. BLT PRG024_BAC8 ; If rows to go, jump to PRG024_BAC8 (RTS) 
05314.  
05315. LDY #$00 ; Y = 0 
05316.  
05317. ; This basically just amounts to a zero; kind of strange? 
05318. LDA PRG024_BB23,Y 
05319. STA <EndText_CPos 
05320.  
05321. ; EndText_VH = $92 
05322. LDA #$29 
05323. STA <EndText_VH 
05324.  
05325. ; EndText_VL = $69 
05326. LDA #$69 
05327. STA <EndText_VL 
05328.  
05329. ; EndText_Timer = $10 
05330. LDA #$10 
05331. STA <EndText_Timer 
05332.  
05333. INC <EndText_State ; EndText_State = 1 
05334.  
05335. PRG024_BAC8: 
05336. RTS ; Return 
05337.  
05338. ; English: "Thank you. But" / "our Princess is" / "in another" / "castle!...Just" / "kidding! Ha ha" / "ha! Bye bye." 
05339. EndText: 
05340.  
05341. ; T h a n k y o u . B u t 
05342. .byte $C3, $D7, $D0, $DD, $DA, $FE, $8C, $DE, $CE, $E9, $FE, $B1, $CE, $CD, $FE 
05343.  
05344. ; o u r P r i n c e s s i s  
05345. .byte $DE, $CE, $CB, $FE, $BF, $CB, $D8, $DD, $D2, $D4, $CC, $CC, $FE, $D8, $CC 
05346.  
05347. ; i n a n o t h e r  
05348. .byte $D8, $DD, $FE, $D0, $DD, $DE, $CD, $D7, $D4, $CB, $FE, $FE, $FE, $FE, $FE 
05349.  
05350. ; c a s t l e ! . . . J u s t 
05351. .byte $D2, $D0, $CC, $CD, $DB, $D4, $EA, $E9, $E9, $E9, $B9, $CE, $CC, $CD, $FE 
05352.  
05353. ; k i d d i n g ! H a h a  
05354. .byte $DA, $D8, $D3, $D3, $D8, $DD, $D6, $EA, $FE, $B7, $D0, $FE, $D7, $D0, $FE 
05355.  
05356. ; h a ! B y e b y e . 
05357. .byte $D7, $D0, $EA, $FE, $B1, $8C, $D4, $FE, $D1, $8C, $D4, $E9, $FE, $FE, $FE 
05358.  
05359. PRG024_BB23: 
05360. ; Terminator 
05361. .byte $00 
05362.  
05363. EndText_DoPrincessText: 
05364. LDA <EndText_Timer 
05365. BNE PRG024_BB70 ; If the timer is not expired, jump to PRG024_BB70 (RTS) 
05366.  
05367. LDX Graphics_BufCnt ; X = current graphics buffer count 
05368.  
05369. LDY <EndText_CPos ; Y = dialog message character position 
05370.  
05371. ; Insert one character into graphics buffer 
05372. LDA <EndText_VH 
05373. STA Graphics_Buffer,X ; address high 
05374. LDA #$01  
05375. STA Graphics_Buffer+2,X ; run length 
05376. LDA EndText,Y 
05377. STA Graphics_Buffer+3,X ; Next character from Princess speech 
05378. LDA #$00 
05379. STA Graphics_Buffer+4,X ; terminator 
05380.  
05381. ; Update Graphics_BufCnt 
05382. TXA 
05383. ADD #$04 
05384. STA Graphics_BufCnt 
05385.  
05386. ; VRAM low address 
05387. LDA <EndText_VL 
05388. STA Graphics_Buffer+1,X 
05389.  
05390. INC <EndText_CPos ; Next character in message 
05391. INC <EndText_VL ; Next VRAM byte 
05392.  
05393. AND #$1f ; Get current column 
05394. CMP #$17 
05395. BNE PRG024_BB6C ; If we're not in column 23, jump to PRG024_BB6C 
05396.  
05397. ; Line break! 
05398.  
05399. LDA <EndText_VL  
05400. ADC #$10 ; Add enough bytes to get to next row 
05401. STA <EndText_VL  
05402. BCC PRG024_BB62 
05403. INC <EndText_VH ; Apply carry 
05404. PRG024_BB62: 
05405.  
05406. CMP #$29 
05407. BNE PRG024_BB6C ; If we haven't reached the last character, jump to PRG024_BB6C 
05408.  
05409. INC <EndText_State ; EndText_State = 2 
05410.  
05411. ; Second ending timer = $4A 
05412. LDA #$4a 
05413. STA <Ending_Timer+1 
05414.  
05415. PRG024_BB6C: 
05416.  
05417. ; First ending timer = $0B 
05418. LDA #$0b 
05419. STA <Ending_Timer 
05420.  
05421. PRG024_BB70: 
05422. RTS ; Return 
05423.  
05424.  
05425. EndText_Wait: 
05426. LDA <Ending_Timer+1 
05427. BNE PRG024_BB7B ; If second ending timer has not expired, jump to PRG024_BB7B (RTS) 
05428.  
05429. ; First ending timer = $0F 
05430. LDA #$0f 
05431. STA <Ending_Timer 
05432.  
05433. INC <Ending_State ; Ending_State = 6 
05434.  
05435. PRG024_BB7B: 
05436. RTS ; Return 
05437.  
05438. Ending_Credits: 
05439. ; Debug menu credits jump here 
05440.  
05441. ; Curtain and floor top 
05442. LDA #$7c 
05443. STA PatTable_BankSel 
05444.  
05445. ; Rest of floor 
05446. LDA #$76 
05447. STA PatTable_BankSel+1 
05448.  
05449. ; Disable display 
05450. LDA #$00 
05451. STA PPU_CTL2 
05452.  
05453. ; Clear everything 
05454. JSR Sprite_RAM_Clear 
05455. JSR Reset_PPU_Clear_Nametables 
05456.  
05457. ; Stop Update_Select activity temporarily 
05458. LDA #$01 
05459. STA UpdSel_Disable 
05460.  
05461. ; Raster_Effect = $20 (Title/Ending style) 
05462. LDA #$20 
05463. STA Raster_Effect 
05464.  
05465. ; Clears a lot of page 0 RAM 
05466. LDX #$f4 ; X = $F4 
05467. PRG024_BB9D: 
05468. LDA #$00 
05469. STA <Temp_Var1,X 
05470.  
05471. PRG024_BBA1: 
05472. DEX ; X-- 
05473.  
05474. ; Range between $6B-$75 is not cleared ... mainly protecting sound engine I think 
05475.  
05476. CPX #Music_Base_L 
05477. BLT PRG024_BBAA ; If X < Music_Base_L, jump to PRG024_BBAA 
05478.  
05479. CPX #World_Map_Y 
05480. BLT PRG024_BBA1 ; If X < World_Map_Y, jump to PRG024_BBA1 
05481.  
05482. PRG024_BBAA: 
05483. CPX #-1 
05484. BNE PRG024_BB9D ; While X >= 0, loop! 
05485.  
05486. ; This clears some of the title screen area memory 
05487. LDX #$15 ; X = $15 
05488. PRG024_BBB0: 
05489. LDA #$00 
05490. STA Title_MLAccelCnt,X 
05491.  
05492. DEX ; X-- 
05493. BPL PRG024_BBB0 ; While X >= 0, loop 
05494.  
05495. JSR Title_Display_Curtain ; Put up the curtain! 
05496.  
05497. ; Push in the Checkerboard floor 
05498. LDA #$23 
05499. ASL A 
05500. TAY 
05501. LDA Video_Upd_Table2,Y 
05502. STA <Video_Upd_AddrL 
05503. LDA Video_Upd_Table2+1,Y 
05504. STA <Video_Upd_AddrH 
05505. JSR Video_Misc_Updates2 
05506.  
05507. ; Set scroll at lowest point (technically, curtain fully raised) 
05508. LDA #$ef 
05509. STA <Vert_Scroll 
05510.  
05511. ; Clip sprites/BG, show sprites/BG, and enable intensity 
05512. LDA #%00011110 
05513. STA <PPU_CTL2_Copy 
05514.  
05515. ; Resume Update_Select activity 
05516. LDA #$00 
05517. STA UpdSel_Disable 
05518.  
05519. ; Curtain extension 
05520. LDA #$24 
05521. STA Graphics_Queue 
05522.  
05523. JSR GraphicsBuf_Prep_And_WaitVSyn2 
05524.  
05525.  
05526. ; This will push graphics command sets $5C, $5D, and $5E 
05527.  
05528. ; Title_EventGrafX = $5C 
05529. LDA #$5c 
05530. STA <Title_EventGrafX  
05531.  
05532. ; Title_Ticker = 5 
05533. LDA #$05 
05534. STA <Title_Ticker 
05535. PRG024_BBE9: 
05536. JSR GraphicsBuf_Prep_And_WaitVSyn2 ; Push out graphics or just VSync 
05537.  
05538. DEC <Title_Ticker 
05539. BPL PRG024_BBE9 ; If Title_Ticker >= 0, loop! 
05540.  
05541. ; Title_Ticker = 3 
05542. LDA #$03 
05543. STA <Title_Ticker 
05544.  
05545. ; Queue next event 
05546. LDA <Title_EventGrafX 
05547. STA Graphics_Queue 
05548.  
05549. INC <Title_EventGrafX ; Title_EventGrafX++ 
05550.  
05551. LDA <Title_EventGrafX 
05552. CMP #$5f 
05553. BNE PRG024_BBE9 ; While Title_EventGrafX <> $5F, loop! 
05554.  
05555. ; Ending2_TimerH = $F 
05556. LDA #$0f 
05557. STA <Ending2_TimerH 
05558.  
05559. ; Ending2_TimerL = $16 
05560. LDA #$16 
05561. STA <Ending2_TimerL 
05562.  
05563. ; Commit the dynamic graphics buffer 
05564. LDA #$00 
05565. STA <Title_EventGrafX 
05566.  
05567. PRG024_BC0D: 
05568. JSR GraphicsBuf_Prep_And_WaitVSyn2 
05569.  
05570. LDA <Title_EventGrafX 
05571. BNE PRG024_BC21 ; If Title_EventGrafX <> 0 (curtain at the bottom), jump to PRG024_BC21 
05572.  
05573. ; Lowering curtain 
05574. LDA <Vert_Scroll 
05575. SUB #$01 
05576. STA <Vert_Scroll 
05577.  
05578. CMP #$3f 
05579. BNE PRG024_BC21 ; If Vert_Scroll <> $3F (curtain all the way down), jump to PRG024_BC21 
05580.  
05581. INC <Title_EventGrafX ; Title_EventGrafX = 1 (flags curtain at the bottom) 
05582.  
05583. PRG024_BC21: 
05584.  
05585. ; Ending2_TimerL-- 
05586. LDA <Ending2_TimerL 
05587. SUB #$01 
05588. STA <Ending2_TimerL 
05589. BCS PRG024_BC0D ; If Ending2_TimerL didn't underflow, loop 
05590.  
05591. ; Ending2_TimerL = $16 
05592. LDA #$16 
05593. STA <Ending2_TimerL 
05594.  
05595. DEC <Ending2_TimerH ; Ending2_TimerH-- 
05596. BPL PRG024_BC0D ; While Ending2_TimerH >= 0, loop 
05597.  
05598. PRG024_BC32: 
05599. JSR GraphicsBuf_Prep_And_WaitVSyn2 ; Probably mainly for VSync 
05600.  
05601. JSR Ending2_DoEndPic ; Update and draw end picture per world 
05602.  
05603. LDA <Ending2_CurWorld 
05604. CMP #$08 
05605. BNE PRG024_BC32 ; While Ending2_CurWorld <> 8, loop! 
05606.  
05607. ; Ending2_CurWorld = 0 
05608. LDA #$00 
05609. STA <Ending2_CurWorld 
05610.  
05611. LDY #$44 ; Y = $44 (all sprites used in ending) 
05612. PRG024_BC44: 
05613.  
05614. ; Clear this sprite 
05615. LDA #$f8 
05616. STA Sprite_RAM,Y 
05617.  
05618. ; Y -= 4 (previous sprite) 
05619. DEY 
05620. DEY 
05621. DEY 
05622. DEY 
05623.  
05624. BPL PRG024_BC44 ; While Y >= 0, loop 
05625.  
05626. PRG024_BC4F: 
05627. JSR GraphicsBuf_Prep_And_WaitVSyn2 ; V Sync  
05628.  
05629. DEC <Vert_Scroll ; Vert_Scroll-- (lowering curtain for finale) 
05630.  
05631. LDA <Vert_Scroll 
05632. CMP #$3f 
05633. BNE PRG024_BC4F ; While curtain not completely lowered, loop! 
05634.  
05635. ; Title_Ticker = $55 
05636. LDA #$55 
05637. STA <Title_Ticker 
05638.  
05639. PRG024_BC5E: 
05640. JSR GraphicsBuf_Prep_And_WaitVSyn2 ; Vsync 
05641.  
05642. DEC <Title_Ticker ; Title_Ticker-- 
05643. BPL PRG024_BC5E ; While Title_Ticker >= 0, loop 
05644.  
05645. ; Load graphics for "THE END" 
05646. LDA #$1b 
05647. STA PatTable_BankSel+5 
05648.  
05649. ; Copy in sprite bytes to form THE END 
05650. LDY #(Ending2_THEEND_End - Ending2_THEEND - 1) 
05651. PRG024_BC6C: 
05652. LDA Ending2_THEEND,Y 
05653. STA Sprite_RAM,Y 
05654.  
05655. DEY ; Y-- 
05656. BPL PRG024_BC6C ; While Y >= 0, loop 
05657.  
05658. ; Title_Ticker = 3 
05659. LDA #$03 
05660. STA <Title_Ticker 
05661.  
05662. ; Title_EventGrafX = 3 (going to cycle through all palettes for THE END to fade in) 
05663. LDA #$03 
05664. STA <Title_EventGrafX 
05665.  
05666. ; Graphics_Queue = $5B 
05667. LDA #$5b 
05668. STA Graphics_Queue 
05669.  
05670. PRG024_BC82: 
05671. JSR GraphicsBuf_Prep_And_WaitVSyn2 ; V Sync 
05672.  
05673. DEC <Title_Ticker ; Title_Ticker-- 
05674. BNE PRG024_BC82 ; While Title_Ticker <> 0, loop 
05675.  
05676. DEC <Title_EventGrafX ; Title_EventGrafX-- 
05677. BMI PRG024_BCAE ; If Title_EventGrafX < 0, jump to PRG024_BCAE 
05678.  
05679. ; Title_Ticker = 3 
05680. LDA #$03 
05681. STA <Title_Ticker 
05682.  
05683. ; Set attribute on all THE END sprites 
05684. LDA <Title_EventGrafX 
05685. STA Sprite_RAM+$02 
05686. STA Sprite_RAM+$06 
05687. STA Sprite_RAM+$0A 
05688. STA Sprite_RAM+$0E 
05689. STA Sprite_RAM+$12 
05690. STA Sprite_RAM+$16 
05691. STA Sprite_RAM+$1A 
05692. STA Sprite_RAM+$1E 
05693.  
05694. JMP PRG024_BC82 ; Jump to PRG024_BC82 (loop) 
05695.  
05696. PRG024_BCAE: 
05697. JSR GraphicsBuf_Prep_And_WaitVSyn2 ; V Sync 
05698.  
05699. LDA <Pad_Input  
05700. AND #PAD_START 
05701. BEQ PRG024_BCAE ; While Player has not pressed START, loop 
05702.  
05703. ; Stop music 
05704. LDA #MUS1_STOPMUSIC 
05705. STA Sound_QMusic1 
05706.  
05707. JSR GraphicsBuf_Prep_And_WaitVSyn2 ; V Sync 
05708.  
05709. ; Disable display 
05710. LDA #$00 
05711. STA PPU_CTL2 
05712. STA PPU_CTL1 
05713.  
05714. ; Map_Unused7992 = 0 (used only in dead code it seems) 
05715. LDA #$00 
05716. STA Map_Unused7992 
05717.  
05718. ; Temp_Var1 = 0 
05719. LDY #$00 
05720. STY <Temp_Var1 
05721.  
05722. ; Temp_Var2 = $7F 
05723. LDA #$7f 
05724. STA <Temp_Var2 
05725.  
05726. ; Clearing RAM $7FFF through $6000 
05727. PRG024_BCD4: 
05728. LDA #$00 
05729. STA [Temp_Var1],Y 
05730.  
05731. DEY ; Y-- 
05732. BNE PRG024_BCD4 ; While Y <> 0 (come full circle), loop 
05733.  
05734. DEC <Temp_Var2 ; Temp_Var2-- (previous page of RAM) 
05735.  
05736. LDA <Temp_Var2 
05737. CMP #$5f 
05738. BNE PRG024_BCD4 ; While Temp_Var2 <> $5F, loop 
05739.  
05740.  
05741. ; P-Wings for everybody! 
05742. LDX #$01 ; X = 1 
05743. LDY #(Inventory_Cards - Inventory_Items - 1) 
05744. PRG024_BCE7: 
05745.  
05746. LDA #(Inventory_Cards - Inventory_Items - 1) 
05747. STA <Temp_Var1 
05748.  
05749. LDA #$08 ; A = 8 (P-Wing) 
05750. PRG024_BCED: 
05751. STA Inventory_Items,Y ; Here's another P-Wing 
05752.  
05753. DEY ; Y-- 
05754.  
05755. DEC <Temp_Var1 ; Temp_Var1-- 
05756. BPL PRG024_BCED ; While Temp_Var1 >= 0, loop 
05757.  
05758. DEX ; X-- 
05759. BMI PRG024_BD01 ; If X < 0, jump to PRG024_BD01 
05760.  
05761. LDA #(Inventory_Cards - Inventory_Items - 1) 
05762. ADD #(Inventory_Items2 - Inventory_Items) 
05763.  
05764. TAY ; Reset 'Y' 
05765. JMP PRG024_BCE7 ; Loop 
05766.  
05767. PRG024_BD01: 
05768.  
05769.  
05770. ; Clear $07FF - $0000, excluding $01xx 
05771. LDY #$07 
05772. JSR Clear_RAM_thru_ZeroPage 
05773.  
05774. ; Reset_Latch = $5A (magic value that prevents reset vector from being run) 
05775. LDA #$5a 
05776. STA Reset_Latch 
05777.  
05778. ; N-Spade appears every 80,000 points, but the leading zero is fake, so 8000 
05779.  
05780. ; Middle byte of the N-Spade score 
05781. LDA #HIGH(8000) 
05782. STA Map_NSpade_NextScore+1 
05783.  
05784. ; Lowest byte of the N-Spade score 
05785. LDA #LOW(8000) 
05786. STA Map_NSpade_NextScore+2 
05787.  
05788. ; If they jumped a little earlier, they could've included the N-Spade score init, strangely 
05789. JMP PRG030_845A ; Jump to PRG030_845A 
05790.  
05791. ; THE END sprites 
05792. Ending2_THEEND: 
05793. .byte $60, $F1, $03, $60 
05794. .byte $60, $F3, $03, $68 
05795. .byte $60, $F5, $03, $70 
05796. .byte $60, $F7, $03, $78 
05797. .byte $60, $F9, $03, $80 
05798. .byte $60, $FB, $03, $88 
05799. .byte $60, $FD, $03, $90 
05800. .byte $60, $FF, $03, $98 
05801. Ending2_THEEND_End 
05802.  
05803. Do_Ending2_IntCmd: 
05804. DEC <Ending2_IntCmd ; Ending2_IntCmd-- (because it is zero based, and zero is "Do nothing") 
05805. LDA <Ending2_IntCmd 
05806. JSR DynJump 
05807.  
05808. ; THESE MUST FOLLOW DynJump FOR THE DYNAMIC JUMP TO WORK!! 
05809. .word Ending2_ClearScreen 
05810. .word Ending2_CommitPicture 
05811.  
05812. Ending2_DoEndPic: 
05813. ; Ending2_IntCmd = 0 (disable interrupt routine command) 
05814. LDA #$00 
05815. STA <Ending2_IntCmd 
05816.  
05817. LDA <Ending2_PicState 
05818. JSR DynJump 
05819.  
05820. ; THESE MUST FOLLOW DynJump FOR THE DYNAMIC JUMP TO WORK!! 
05821. .word Ending2_CurtainRaise ; 0: Raise the curtain back up 
05822. .word Ending2_PrepClear ; 1: Prepare for screen clear 
05823. .word Ending2_SetFlag1 ; 2: Sets Ending2_IntCmd = 1 and waits for interrupt context (which will call Do_Ending2_IntCmd) 
05824. .word Ending2_PrepEndPic ; 3: Load up the Ending_CmdBuffer, set starting VRAM address for world end picture 
05825. .word Ending2_SetFlag2 ; 4: Sets Ending2_IntCmd = 2 and waits for interrupt context (which will call Do_Ending2_IntCmd) 
05826. .word Ending2_SeriesQueue ; 5: Queue a series of Graphics_Command (Ending2_QueueCmd++ until Ending2_QCmdEnd) 
05827. .word Ending2_AddSprites ; 6: Add sprites that are part of the end picture 
05828. .word Ending2_FadeIn ; 7: Fade in the palette 
05829. .word Ending2_Wait ; 8: Wait on current world picture 
05830. .word Ending2_FadeOut ; 9: Fade out the palette 
05831.  
05832. Ending2_CurtainRaise: 
05833. LDY #$01 ; Y = 1 (two stabs at curtain being fully raised) 
05834. PRG024_BD62: 
05835. INC <Vert_Scroll ; Vert_Scroll++ (raising the curtain) 
05836.  
05837. LDA <Vert_Scroll 
05838. CMP #$ef 
05839. BEQ PRG024_BD6E ; If curtain is fully raised, jump to PRG024_BD6E 
05840.  
05841. DEY ; Y-- 
05842. BPL PRG024_BD62 ; While Y >= 0, loop 
05843.  
05844. RTS ; Return 
05845.  
05846. PRG024_BD6E: 
05847. INC <Ending2_PicState ; Ending2_PicState = 1 
05848. RTS ; Return 
05849.  
05850. Ending2_PrepClear: 
05851. ; Set Ending2_PicVRAMH/L 
05852. LDA #$28 
05853. STA <Ending2_PicVRAMH 
05854. LDA #$60 
05855. STA <Ending2_PicVRAML 
05856.  
05857. ; Ending2_ClearLen = $14 
05858. LDA #$14 
05859. STA <Ending2_ClearLen 
05860.  
05861. ; Ending2_ClearPat = $5C 
05862. LDA #$5c 
05863. STA <Ending2_ClearPat 
05864.  
05865. INC <Ending2_PicState ; Ending2_PicState = 2 
05866.  
05867. RTS ; Return 
05868.  
05869. Ending2_SetFlag1: 
05870. ; Ending2_IntCmd = 1 
05871. LDA #$01 
05872. STA <Ending2_IntCmd 
05873.  
05874. RTS ; Return 
05875.  
05876.  
05877. Ending2_ClearScreen: 
05878. LDA <Ending2_PicVRAMH 
05879. CMP #$2b 
05880. BEQ PRG024_BDBB ; If Ending2_PicVRAMH = $2b, jump to Ending2_PicVRAMH 
05881.  
05882. LDA PPU_STAT 
05883.  
05884. ; Set VRAM Address to Ending2_PicVRAMH/L 
05885. LDA <Ending2_PicVRAMH 
05886. STA PPU_VRAM_ADDR 
05887. LDA <Ending2_PicVRAML 
05888. STA PPU_VRAM_ADDR 
05889.  
05890. LDY #$1f ; Y = $1F 
05891. LDA <Ending2_ClearPat ; Get the clearing pattern 
05892. PRG024_BDA0: 
05893. STA PPU_VRAM_DATA ; Store pattern 
05894.  
05895. DEY ; Y-- 
05896. BPL PRG024_BDA0 ; While Y >= 0, loop 
05897.  
05898. DEC <Ending2_ClearLen ; Ending2_ClearLen-- 
05899. BPL PRG024_BDB7 ; If Ending2_ClearLen >= 0, jump to PRG024_BDB7 
05900.  
05901. ; Set Ending2_PicVRAMH  
05902. LDA #$2b 
05903. STA <Ending2_PicVRAMH 
05904. LDA #$c8 
05905. STA <Ending2_PicVRAML 
05906.  
05907. ; Ending2_ClearLen = 4 
05908. LDA #$04 
05909. STA <Ending2_ClearLen 
05910.  
05911. RTS ; Return 
05912.  
05913. PRG024_BDB7: 
05914. JSR Ending2_PicVRAM_NextLineWrap 
05915.  
05916. RTS ; Return 
05917.  
05918. PRG024_BDBB: 
05919. LDA PPU_STAT 
05920.  
05921. ; Set VRAM Address to Ending2_PicVRAMH/L 
05922. LDA <Ending2_PicVRAMH 
05923. STA PPU_VRAM_ADDR 
05924. LDA <Ending2_PicVRAML 
05925. STA PPU_VRAM_ADDR 
05926.  
05927. LDY #$07 ; Y = $07 
05928. LDA #$aa ; Pattern $AA 
05929. PRG024_BDCC: 
05930. STA PPU_VRAM_DATA ; Store pattern 
05931.  
05932. DEY ; Y-- 
05933. BPL PRG024_BDCC ; While Y >= 0, loop 
05934.  
05935. DEC <Ending2_ClearLen ; Ending2_ClearLen---- 
05936. BPL PRG024_BDD8 ; If Ending2_ClearLen >= 0, jump to PRG024_BDD8 
05937.  
05938. INC <Ending2_PicState ; Ending2_PicState++ 
05939.  
05940. PRG024_BDD8: 
05941.  
05942. ; Ending2_PicVRAML += 8 
05943. LDA <Ending2_PicVRAML 
05944. ADD #$08 
05945. STA <Ending2_PicVRAML 
05946.  
05947. RTS ; Return 
05948.  
05949. Ending2_PrepEndPic: 
05950. LDY <Ending2_CurWorld ; Y = current world we're depicting 
05951.  
05952. ; Temp_Var2/1 hold the address to the end world picture 
05953. LDA EndPicByWorld_H,Y 
05954. STA <Temp_Var2 
05955. LDA EndPicByWorld_L,Y 
05956. STA <Temp_Var1 
05957.  
05958. LDY #$00 ; Y = 0 (EndPic command index) 
05959. LDX #$00 ; X = 0 (Ending_CmdBuffer index) 
05960. PRG024_BDF0: 
05961. ; Next command byte -> Temp_Var16 
05962. LDA [Temp_Var1],Y 
05963. STA <Temp_Var16  
05964.  
05965. AND #$80 
05966. BEQ PRG024_BE02 ; If bit 7 is NOT set, jump to PRG024_BE02 
05967.  
05968. ; Bit 7 set... 
05969.  
05970. ; Clear bit 7 
05971. LDA <Temp_Var16 
05972. AND #$7f 
05973. STA <Temp_Var16 
05974.  
05975. ; Store byte into buffer 
05976. STA Ending_CmdBuffer,X 
05977. INX ; X++ (next buffer byte) 
05978.  
05979. PRG024_BE02: 
05980.  
05981. ; Bit 7 not set (or just continued) 
05982.  
05983. ; Store byte into buffer 
05984. LDA <Temp_Var16  
05985. STA Ending_CmdBuffer,X 
05986. INX ; X++ (next buffer byte) 
05987.  
05988. INY ; Y++ (next EndPic command byte) 
05989.  
05990. CPX #$c1 
05991. BLT PRG024_BDF0 ; While buffer index < $C1, loop! 
05992.  
05993. ; Buffer filled... 
05994.  
05995. LDY <Ending2_CurWorld ; Y = current world we're depicting 
05996.  
05997. ; Set starting VRAM address 
05998. LDA EndPic_VRAMStart_H,Y 
05999. STA <Ending2_PicVRAMH 
06000. LDA EndPic_VRAMStart_L,Y 
06001. STA <Ending2_PicVRAML 
06002.  
06003. INC <Ending2_PicState ; Ending2_PicState = 4 
06004.  
06005. ; Ending2_ClearLen = $B 
06006. LDA #$0b 
06007. STA <Ending2_ClearLen 
06008.  
06009. ; Ending2_QCmdEnd = 0 
06010. LDA #$00 
06011. STA <Ending2_QCmdEnd 
06012.  
06013. RTS ; Return 
06014.  
06015. Ending2_SetFlag2: 
06016. ; Ending2_IntCmd = 2 
06017. LDA #$02 
06018. STA <Ending2_IntCmd 
06019.  
06020. RTS ; Return 
06021.  
06022.  
06023. PRG024_BE29: 
06024. .byte $2A, $2E, $32, $36, $3A, $3E, $44, $49 
06025. PRG024_BE31: 
06026. .byte $2D, $31, $35, $39, $3D, $43, $48, $4C 
06027.  
06028. Ending2_CommitPicture: 
06029. LDA PPU_STAT  
06030.  
06031. ; Set VRAM Address to Ending2_PicVRAMH/L 
06032. LDA <Ending2_PicVRAMH 
06033. STA PPU_VRAM_ADDR 
06034. LDA <Ending2_PicVRAML 
06035. STA PPU_VRAM_ADDR 
06036.  
06037. LDX #$0f ; X = 4 
06038. LDY <Ending2_QCmdEnd ; Y = Ending2_QCmdEnd 
06039. PRG024_BE4A: 
06040.  
06041. ; Buffer -> PPU_VRAM_DATA 
06042. LDA Ending_CmdBuffer,Y 
06043. STA PPU_VRAM_DATA 
06044.  
06045. INY ; Y++ 
06046. DEX ; X-- 
06047. BPL PRG024_BE4A ; While X >= 0, loop 
06048.  
06049. STY <Ending2_QCmdEnd ; Update Ending2_QCmdEnd 
06050.  
06051. JSR Ending2_PicVRAM_NextLineWrap ; Next line 
06052.  
06053. DEC <Ending2_ClearLen ; Ending2_ClearLen-- 
06054. BPL PRG024_BE6B ; If Ending2_ClearLen >= 0, jump to PRG024_BE6B (RTS) 
06055.  
06056. INC <Ending2_PicState ; Ending2_PicState++ 
06057.  
06058. LDX <Ending2_CurWorld ; X = current world we're depicting 
06059.  
06060. LDA PRG024_BE29,X 
06061. STA <Ending2_QueueCmd 
06062.  
06063. LDA PRG024_BE31,X 
06064. STA <Ending2_QCmdEnd 
06065.  
06066. PRG024_BE6B: 
06067. RTS ; Return 
06068.  
06069. Ending2_SeriesQueue: 
06070. ; Execute next command 
06071. LDA <Ending2_QueueCmd 
06072. STA <Graphics_Queue 
06073.  
06074. CMP <Ending2_QCmdEnd 
06075. BNE PRG024_BE76 ; If this is not the last series command to execute, jump to PRG024_BE76 
06076.  
06077. ; Last command executed! 
06078. INC <Ending2_PicState ; Ending2_PicState = 6 
06079.  
06080. PRG024_BE76: 
06081. INC <Ending2_QueueCmd ; Ending2_QueueCmd++ 
06082.  
06083. RTS ; Return 
06084.  
06085. Ending2_AddSprites: 
06086.  
06087. ; Clear ending sprites 
06088. LDA #$f8 
06089. STA Sprite_RAM+$24 
06090. STA Sprite_RAM+$28 
06091. STA Sprite_RAM+$2C 
06092. STA Sprite_RAM+$30 
06093. STA Sprite_RAM+$34 
06094. STA Sprite_RAM+$38 
06095. STA Sprite_RAM+$3C 
06096. STA Sprite_RAM+$40 
06097. STA Sprite_RAM+$44 
06098.  
06099. LDY <Ending2_CurWorld ; Y = current world we're depicting 
06100.  
06101. ; Load pattern tables required for this world picture sprites 
06102. LDA Ending2_EndPicPatTable2,Y 
06103. STA PatTable_BankSel+2 
06104. LDA Ending2_EndPicPatTable3,Y 
06105. STA PatTable_BankSel+3 
06106. LDA Ending2_EndPicPatTable4,Y 
06107. STA PatTable_BankSel+4 
06108. LDA Ending2_EndPicPatTable5,Y 
06109. STA PatTable_BankSel+5 
06110.  
06111. ; Load starting address for sprite list 
06112. LDA Ending2_EndPicSpriteListH,Y 
06113. STA <Temp_Var2 
06114. LDA Ending2_EndPicSpriteListL,Y 
06115. STA <Temp_Var1 
06116.  
06117. ; Load length of sprite list 
06118. LDA Ending2_EndPicSpriteListLen,Y 
06119. TAY 
06120.  
06121. ; Copy sprite data in 
06122. PRG024_BEBE: 
06123. LDA [Temp_Var1],Y 
06124. STA Sprite_RAM,Y 
06125.  
06126. DEY ; Y-- 
06127. BPL PRG024_BEBE ; While Y >= 0, loop 
06128.  
06129. INC <Ending2_PicState ; Ending2_PicState = 7 
06130.  
06131. ; Ending2_FadeTimer = 3 
06132. LDA #$03 
06133. STA <Ending2_FadeTimer 
06134.  
06135. ; Ending2_QueueCmd = $26 
06136. LDA #$26 
06137. STA <Ending2_QueueCmd 
06138.  
06139. RTS ; Return 
06140.  
06141.  
06142. Ending2_FadeIn: 
06143. DEC <Ending2_FadeTimer ; Ending2_FadeTimer-- 
06144. BPL PRG024_BEFB ; If Ending2_FadeTimer >= 0, jump to PRG024_BEFB (RTS) 
06145.  
06146. ; Reload Ending2_FadeTimer = 3 
06147. LDA #$03 
06148. STA <Ending2_FadeTimer 
06149.  
06150. ; Queue graphics command 
06151. LDA <Ending2_QueueCmd 
06152. STA Graphics_Queue 
06153.  
06154. CMP #$2a 
06155. BNE PRG024_BEF9 ; If Ending2_QueueCmd <> $2A, jump to PRG024_BEF9 
06156.  
06157. INC <Ending2_PicState ; Ending2_PicState = 8 
06158.  
06159. ; Queue the full palette (fade in is common) 
06160. LDA <Ending2_CurWorld ; A = current world we're depicting 
06161. ADD #$4d 
06162. STA Graphics_Queue 
06163.  
06164. ; Ending2_TimerH = $F 
06165. LDA #$0f 
06166. STA <Ending2_TimerH 
06167.  
06168. ; Ending2_TimerL = $16 
06169. LDA #$16 
06170. STA <Ending2_TimerL 
06171.  
06172. ; Ending2_QueueCmd = $06 
06173. LDA #(Ending2_FadeOutQs_End - Ending2_FadeOutQs - 1) 
06174. STA <Ending2_QueueCmd 
06175.  
06176. RTS ; Return 
06177.  
06178. PRG024_BEF9: 
06179. INC <Ending2_QueueCmd ; Ending2_QueueCmd++ 
06180.  
06181. PRG024_BEFB: 
06182. RTS ; Return 
06183.  
06184. Ending2_Wait: 
06185. ; Ending2_TimerL-- 
06186. LDA <Ending2_TimerL 
06187. SUB #$01 
06188. STA <Ending2_TimerL 
06189. BCS PRG024_BF13 ; If Ending2_TimerL >= 0, jump to PRG024_BF13 (RTS) 
06190.  
06191. ; Ending2_TimerL = $16 
06192. LDA #$16 
06193. STA <Ending2_TimerL 
06194.  
06195. DEC <Ending2_TimerH ; Ending2_TimerH-- 
06196. BPL PRG024_BF13 ; If Ending2_TimerH >= 0, jump to PRG024_BF13 (RTS) 
06197.  
06198. INC <Ending2_PicState ; Ending2_PicState = 9 
06199.  
06200. ; Ending2_FadeTimer = 3 
06201. LDA #$03 
06202. STA <Ending2_FadeTimer 
06203.  
06204. PRG024_BF13: 
06205. RTS ; Return 
06206.  
06207. ; Fade out command queues 
06208. Ending2_FadeOutQs: 
06209. .byte $25, $26, $27, $28, $28, $28, $28 
06210. Ending2_FadeOutQs_End 
06211.  
06212. Ending2_FadeOut: 
06213. DEC <Ending2_FadeTimer 
06214. BPL PRG024_BF37 ; If Ending2_FadeTimer >= 0, jump to PRG024_BF37 (RTS) 
06215.  
06216. ; Ending2_FadeTimer = 3 
06217. LDA #$03 
06218. STA <Ending2_FadeTimer 
06219.  
06220. LDX <Ending2_QueueCmd ; X = Ending2_QueueCmd (current index) 
06221.  
06222. ; Queue next fade command 
06223. LDA Ending2_FadeOutQs,X 
06224. STA Graphics_Queue 
06225.  
06226. CMP #$25 
06227. BNE PRG024_BF35 ; If current queue command <> $25, jump to PRG024_BF35 
06228.  
06229. ; Restart ending picture generation 
06230. LDA #$01 
06231. STA <Ending2_PicState ; Ending2_PicState = 1 
06232.  
06233. INC <Ending2_CurWorld ; Ending2_CurWorld++ (display next world in series) 
06234.  
06235. PRG024_BF35: 
06236. DEC <Ending2_QueueCmd ; Ending2_QueueCmd-- 
06237.  
06238. PRG024_BF37: 
06239. RTS ; Return 
06240.  
06241.  
06242. ; FIXME: Anybody want to claim this?? 
06243. ; Seems to be called by dead code, would advance to next row or wrap around; maybe a clearing routine? 
06244. Ending2_PicVRAM_NextLineWrap: 
06245.  
06246. ; Add 32 to VRAM address for next row 
06247. LDA <Ending2_PicVRAML 
06248. ADD #32 
06249. STA <Ending2_PicVRAML 
06250. LDA <Ending2_PicVRAMH 
06251. ADC #$00 
06252. STA <Ending2_PicVRAMH 
06253.  
06254. CMP #$28 
06255. BGE PRG024_BF5D ; If VRAM High address >= $28, jump to PRG024_BF5D (RTS) 
06256.  
06257. CMP #$23 
06258. BLT PRG024_BF5D ; If VRAM High address < $23, jump to PRG024_BF5D (RTS) 
06259.  
06260. LDA <Ending2_PicVRAML 
06261. CMP #$c0 
06262. BLT PRG024_BF5D ; If VRAM Low address < $C0, jump to PRG024_BF5D (RTS) 
06263.  
06264. ; This will wrap the VRAM address to the top (???) 
06265.  
06266. ; Ending2_PicVRAMH = $28 
06267. LDA #$28 
06268. STA <Ending2_PicVRAMH 
06269.  
06270. ; Column on top row 
06271. LDA <Ending2_PicVRAML 
06272. AND #$1f 
06273. STA <Ending2_PicVRAML 
06274.  
06275. PRG024_BF5D: 
06276. RTS ; Return 
06277.  
06278. ; PatTable_BankSel+X values (sprite pattern tables) loaded per "world" of ending picture 
06279. Ending2_EndPicPatTable2: .byte $57, $53, $51, $00, $43, $02, $44, $54 
06280. Ending2_EndPicPatTable3: .byte $00, $04, $00, $76, $76, $76, $04, $76 
06281. Ending2_EndPicPatTable4: .byte $57, $4E, $1A, $1A, $00, $0B, $00, $00 
06282. Ending2_EndPicPatTable5: .byte $4F, $4F, $00, $00, $4F, $4F, $4F, $00 
06283.  
06284. ; Split address, parallel tables for the starting address of the end picture sprite lists for each world 
06285. Ending2_EndPicSpriteListH:  
06286. .byte HIGH(Ending2_EndPicSprites1) 
06287. .byte HIGH(Ending2_EndPicSprites2) 
06288. .byte HIGH(Ending2_EndPicSprites3) 
06289. .byte HIGH(Ending2_EndPicSprites4) 
06290. .byte HIGH(Ending2_EndPicSprites5) 
06291. .byte HIGH(Ending2_EndPicSprites6) 
06292. .byte HIGH(Ending2_EndPicSprites7) 
06293. .byte HIGH(Ending2_EndPicSprites8) 
06294.  
06295. Ending2_EndPicSpriteListL: 
06296. .byte LOW(Ending2_EndPicSprites1) 
06297. .byte LOW(Ending2_EndPicSprites2) 
06298. .byte LOW(Ending2_EndPicSprites3) 
06299. .byte LOW(Ending2_EndPicSprites4) 
06300. .byte LOW(Ending2_EndPicSprites5) 
06301. .byte LOW(Ending2_EndPicSprites6) 
06302. .byte LOW(Ending2_EndPicSprites7) 
06303. .byte LOW(Ending2_EndPicSprites8) 
06304.  
06305. ; Length of the sprite list per world - 1 (or last index, if you prefer) 
06306. Ending2_EndPicSpriteListLen:  
06307. .byte (Ending2_EndPicSprites1_End - Ending2_EndPicSprites1 - 1) 
06308. .byte (Ending2_EndPicSprites2_End - Ending2_EndPicSprites2 - 1) 
06309. .byte (Ending2_EndPicSprites3_End - Ending2_EndPicSprites3 - 1) 
06310. .byte (Ending2_EndPicSprites4_End - Ending2_EndPicSprites4 - 1) 
06311. .byte (Ending2_EndPicSprites5_End - Ending2_EndPicSprites5 - 1) 
06312. .byte (Ending2_EndPicSprites6_End - Ending2_EndPicSprites6 - 1) 
06313. .byte (Ending2_EndPicSprites7_End - Ending2_EndPicSprites7 - 1) 
06314. .byte (Ending2_EndPicSprites8_End - Ending2_EndPicSprites8 - 1) 
06315.  
06316. Ending2_EndPicSprites1: 
06317. .byte $81, $19, $00, $B0 
06318. .byte $81, $1B, $00, $B8 
06319. .byte $91, $1D, $00, $B0 
06320. .byte $91, $21, $00, $B8 
06321. .byte $B1, $EB, $01, $B8 
06322. .byte $B1, $EB, $41, $C0 
06323. .byte $B1, $D9, $01, $80 
06324. .byte $B1, $DB, $41, $88 
06325. .byte $B1, $D9, $01, $90 
06326. .byte $B1, $DB, $41, $98 
06327. Ending2_EndPicSprites1_End 
06328.  
06329. Ending2_EndPicSprites2: 
06330. .byte $79, $1B, $40, $38 
06331. .byte $79, $19, $40, $40 
06332. .byte $99, $67, $01, $50 
06333. .byte $B1, $65, $01, $70 
06334. .byte $A9, $85, $01, $88 
06335. .byte $A9, $87, $01, $90 
06336. .byte $B9, $A5, $01, $88 
06337. .byte $B9, $A7, $01, $90 
06338. .byte $91, $8D, $02, $A8 
06339. .byte $91, $8F, $02, $B0 
06340. .byte $99, $B1, $02, $D0 
06341. .byte $99, $B3, $02, $D8 
06342. .byte $A9, $B5, $02, $D0 
06343. .byte $A9, $B7, $02, $D8 
06344. Ending2_EndPicSprites2_End 
06345.  
06346. Ending2_EndPicSprites3: 
06347. .byte $3F, $B1, $01, $30 
06348. .byte $3F, $B1, $41, $38 
06349. .byte $47, $B5 
06350.  
06351. ; List continued in PRG025 
06352.  
06353.  
06354.  
06355.