;;; $8000: Reset: hardware init and main loop ;;;
;; Entered from the emulation-mode RESET vector. Quiets the SNES (IRQ/NMI/DMA/HDMA off, APU ports cleared,
;; force blank),
;; switches to native 16-bit mode, builds the OAM-clear routine in RAM at $7F8000, uploads the SPC700 engine
;; and samples,
;; clears RAM and then runs the main loop forever.
;; Main loop: wait until NMI sets [$10], count a frame in [$13], run the current game mode (GetGameMode),
;; clear [$10], repeat.
;; Quirk: the RAM routine is generated code: LDA #$F0 followed by 128 STA $0201+4n (every sprite's Y = $F0,
;; off-screen) and an RTL.
$00:8000 78 SEI ; Disable IRQs
$00:8001 9C 00 42 STZ $4200 ; Disable NMI, IRQ timers and joypad auto-read
$00:8004 9C 0C 42 STZ $420C ; Disable HDMA
$00:8007 9C 0B 42 STZ $420B ; Disable DMA
$00:800A 9C 40 21 STZ $2140 ; \
$00:800D 9C 41 21 STZ $2141 ; |
$00:8010 9C 42 21 STZ $2142 ; } Clear APU I/O ports $2140-$2143 (silences the SPC700)
$00:8013 9C 43 21 STZ $2143 ; /
$00:8016 A9 80 LDA #$80 ; \
$00:8018 8D 00 21 STA $2100 ; / Force blank (screen off, brightness 0)
$00:801B 18 CLC ; \
$00:801C FB XCE ; / Leave 6502 emulation mode (native mode)
$00:801D C2 38 REP #$38 ; Binary mode; A, X and Y 16-bit
$00:801F A9 00 00 LDA #$0000 ; \
$00:8022 5B TCD ; / Direct page = $0000 (so [$xx] is WRAM $7E:00xx)
$00:8023 A9 FF 01 LDA #$01FF ; \
$00:8026 1B TCS ; / Stack pointer = $01FF
$00:8027 A9 A9 F0 LDA #$F0A9 ; A = $F0A9: little-endian bytes A9 F0 = opcode LDA #$F0
$00:802A 8F 00 80 7F STA $7F8000 ; Start of RAM routine $7F8000: LDA #$F0
$00:802E A2 7D 01 LDX #$017D ; X = $017D: offset of the last generated STA (3 bytes each, 128 of them)
$00:8031 A0 FD 03 LDY #$03FD ; Y = $03FD: OAM Y-coordinate address of the last sprite ($0201 + 4*127)
$00:8034 A9 8D 00 LDA #$008D ; A = $008D: opcode of STA absolute
$00:8037 9F 02 80 7F STA $7F8002,X ; Write the STA opcode (the extra 00 is overwritten next)
$00:803B 98 TYA ; A = OAM address for this STA
$00:803C 9F 03 80 7F STA $7F8003,X ; Write the STA operand: address of this sprite's Y byte
$00:8040 38 SEC ; \
$00:8041 E9 04 00 SBC #$0004 ; } Next OAM Y address: Y = Y - 4
$00:8044 A8 TAY ; /
$00:8045 CA DEX ; \
$00:8046 CA DEX ; } X -= 3: previous generated instruction
$00:8047 CA DEX ; /
$00:8048 10 EA BPL $EA [$8034] ; Loop for all 128 sprites
$00:804A E2 30 SEP #$30 ; A, X and Y 8-bit
$00:804C A9 6B LDA #$6B ; A = $6B: opcode of RTL
$00:804E 8F 82 81 7F STA $7F8182 ; End the RAM routine with RTL at $7F8182
$00:8052 20 E8 80 JSR $80E8 ; Upload the SPC700 engine (UploadSPCEngine)
$00:8055 9C 00 01 STZ $0100 ; Game mode = 0 (load Nintendo Presents)
$00:8058 9C 09 01 STZ $0109 ; Clear [$0109] (level number / intro level flag)
$00:805B 20 4E 8A JSR $8A4E ; Clear $0000-$00FF and $0200-$1FFF and the stripe image buffer (ClearStack)
$00:805E 20 FD 80 JSR $80FD ; Upload sample data to the SPC700 (UploadSamples)
$00:8061 20 50 92 JSR $9250 ; Set up HDMA channel 7 (window effect) and clear its table ($9250)
$00:8064 A9 03 LDA #$03 ; \
$00:8066 8D 01 21 STA $2101 ; / OBJ tiles at VRAM $6000, 8x8 and 16x16 sprite sizes
$00:8069 E6 10 INC $10 ; [$10] = 1: skip the NMI wait on the first pass
$00:806B A5 10 LDA $10 ; \
$00:806D F0 FC BEQ $FC [$806B] ; / Spin until NMI sets [$10] (frame ready)
$00:806F 58 CLI ; Enable IRQs
$00:8070 E6 13 INC $13 ; Count a frame: [$13]++
$00:8072 20 22 93 JSR $9322 ; Run the current game mode (GetGameMode)
$00:8075 64 10 STZ $10 ; \
$00:8077 80 F2 BRA $F2 [$806B] ; / [$10] = 0: this frame's game logic is done, wait for the next NMI
; SPC Upload information is here: http://romhack.wikia.com/wiki/Spc700.rom and http://romhacking.net/docs/197/
;;; $8079: Upload data blocks to SPC700 (SPC700UploadLoop) ;;;
;; Sends one or more blocks to the SPC700 through APU ports $2140-$2143 using the IPL boot ROM transfer
;; protocol.
;; Block format at [$00]: 16-bit length, 16-bit SPC700 destination address, then the data bytes. A block of
;; length 0 ends the
;; transfer; its address is where the SPC700 starts running.
;; Parameters: [$00]-[$02]: 24-bit ROM address of the first block.
;; Returns: APU ports cleared; processor flags preserved.
$00:8079 08 PHP ; Save processor flags
$00:807A C2 30 REP #$30 ; A, X and Y 16-bit
$00:807C A0 00 00 LDY #$0000 ; Y = 0: offset into the data at [$00]
$00:807F A9 AA BB LDA #$BBAA ; \
$00:8082 CD 40 21 CMP $2140 ; } Wait for the SPC700 IPL ROM to signal ready ($BBAA on ports 0/1)
$00:8085 D0 FB BNE $FB [$8082] ; /
$00:8087 E2 20 SEP #$20 ; A 8-bit
$00:8089 A9 CC LDA #$CC ; A = $CC: IPL start-transfer command
$00:808B 80 26 BRA $26 [$80B3] ; Send the command and the block header (first block)
$00:808D B7 00 LDA [$00],Y ; Fetch the first data byte of the block
$00:808F C8 INY ; Advance the data offset
$00:8090 EB XBA ; Park the byte in the high half of A
$00:8091 A9 00 LDA #$00 ; Transfer counter = 0 for the first byte
$00:8093 80 0B BRA $0B [$80A0] ; Send it
$00:8095 EB XBA ; \
$00:8096 B7 00 LDA [$00],Y ; |
$00:8098 C8 INY ; } Next data byte goes in B, transfer counter in A
$00:8099 EB XBA ; /
$00:809A CD 40 21 CMP $2140 ; \
$00:809D D0 FB BNE $FB [$809A] ; / Wait until the SPC700 echoes the previous counter on port 0
$00:809F 1A INC A ; Counter + 1
$00:80A0 C2 20 REP #$20 ; \
$00:80A2 8D 40 21 STA $2140 ; } Port 0 = counter, port 1 = data byte (one 16-bit write)
$00:80A5 E2 20 SEP #$20 ; /
$00:80A7 CA DEX ; \
$00:80A8 D0 EB BNE $D0 [$8095] ; / Repeat for all bytes of the block (X = byte count)
$00:80AA CD 40 21 CMP $2140 ; \
$00:80AD D0 FB BNE $FB [$80AA] ; / Wait until the SPC700 echoes the last counter
$00:80AF 69 03 ADC #$03 ; \
$00:80B1 F0 FC BEQ $FC [$80AF] ; / Next block command = counter + 4 (CMP leaves carry set), never 0
$00:80B3 48 PHA ; Save the command byte
$00:80B4 C2 20 REP #$20 ; A 16-bit
$00:80B6 B7 00 LDA [$00],Y ; A = block length
$00:80B8 C8 INY ; \
$00:80B9 C8 INY ; / Skip the length word
$00:80BA AA TAX ; X = block length
$00:80BB B7 00 LDA [$00],Y ; A = block destination address in SPC700 RAM
$00:80BD C8 INY ; \
$00:80BE C8 INY ; / Skip the address word
$00:80BF 8D 42 21 STA $2142 ; Send the address to ports 2/3
$00:80C2 E2 20 SEP #$20 ; A 8-bit
$00:80C4 E0 01 00 CPX #$0001 ; Carry = 1 if the block has data (length >= 1)
$00:80C7 A9 00 LDA #$00 ; \
$00:80C9 2A ROL ; } Port 1 = 1 for a data block, 0 for the end block (SPC700 starts running)
$00:80CA 8D 41 21 STA $2141 ; /
$00:80CD 69 7F ADC #$7F ; V = 1 if the block had data (A = 1 overflows when adding $7F)
$00:80CF 68 PLA ; \
$00:80D0 8D 40 21 STA $2140 ; |
$00:80D3 CD 40 21 CMP $2140 ; } Send the command byte on port 0 and wait for the SPC700 to echo it
$00:80D6 D0 FB BNE $FB [$80D3] ; /
$00:80D8 70 B3 BVS $B3 [$808D] ; Block had data: go send it ($00808D); otherwise finish
$00:80DA 9C 40 21 STZ $2140 ; \
$00:80DD 9C 41 21 STZ $2141 ; |
$00:80E0 9C 42 21 STZ $2142 ; } Clear APU ports 0-3 (end the transfer)
$00:80E3 9C 43 21 STZ $2143 ; /
$00:80E6 28 PLP ; Restore processor flags
$00:80E7 60 RTS ; Unused stub: A = 0 (loads zero, no effect here)
;;; $80E8: Upload SPC700 engine (UploadSPCEngine) ;;;
;; Points [$00] at $0E:8000 (SPC700 engine and its initial data) and falls through into UploadDataToSPC.
$00:80E8 A9 00 LDA #$00 ; \
$00:80EA 8D 00 00 STA $0000 ; |
$00:80ED A9 80 LDA #$80 ; |
$00:80EF 8D 01 00 STA $0001 ; |
$00:80F2 A9 0E LDA #$0E ; } [$00] = $0E8000 (SPC700 engine and initial data)
$00:80F4 8D 02 00 STA $0002 ; /
;;; $80F7: Upload data with IRQs disabled (UploadDataToSPC) ;;;
;; Wraps SPC700UploadLoop in SEI/CLI because the handshake is timing sensitive.
;; Parameters: [$00]-[$02]: 24-bit ROM address of the data. Note: always leaves IRQs enabled (CLI).
$00:80F7 78 SEI ; Disable IRQs: the handshake is timing sensitive
$00:80F8 20 79 80 JSR $8079 ; Upload the data blocks at [$00]
$00:80FB 58 CLI ; Enable IRQs
$00:80FC 60 RTS ; Return
;;; $80FD: Upload sample data to SPC700 (UploadSamples) ;;;
;; Points [$00] at $0F:8000 (BRR sample pointers and data) and uploads it via StrtSPCMscUpld.
$00:80FD A9 00 LDA #$00 ; \
$00:80FF 8D 00 00 STA $0000 ; |
$00:8102 A9 80 LDA #$80 ; |
$00:8104 8D 01 00 STA $0001 ; |
$00:8107 A9 0F LDA #$0F ; } [$00] = $0F8000 (sample pointers and BRR data)
$00:8109 8D 02 00 STA $0002 ; /
$00:810C 80 0F BRA $0F [$811D] ; Upload it (StrtSPCMscUpld)
;;; $810E: Upload music bank 1 (title, overworld) (UploadMusicBank1) ;;;
;; Points [$00] at $0E:98B1 and falls through into StrtSPCMscUpld. Called when the title screen and the
;; overworld are loaded.
;; Called by:
;; $00:96C3: Cutscene, ending and game mode code (castle scenes, credits, game over) (CutsceneCastlePal)
;; $00:A0B3: Game mode 0C: load overworld (LoadMapGameMode)
$00:810E A9 B1 LDA #$B1 ; \
$00:8110 8D 00 00 STA $0000 ; |
$00:8113 A9 98 LDA #$98 ; |
$00:8115 8D 01 00 STA $0001 ; |
$00:8118 A9 0E LDA #$0E ; } [$00] = $0E98B1 (music bank 1: title and overworld)
$00:811A 8D 02 00 STA $0002 ; /
;;; $811D: Request and run SPC700 upload (StrtSPCMscUpld) ;;;
;; Common tail of the sample and music uploads. Writes $FF to APU port 1 (probably asks the running SPC700
;; engine to jump back
;; to its IPL loader), uploads the blocks at [$00], then falls into SPC700ZeroLoop to clear the ports.
;; Parameters: [$00]-[$02]: 24-bit ROM address of the data.
$00:811D A9 FF LDA #$FF ; \
$00:811F 8D 41 21 STA $2141 ; / Port 1 = $FF: ask the SPC700 engine to accept an upload (probably jumps to the IPL)
$00:8122 20 F7 80 JSR $80F7 ; Upload the data blocks at [$00] (UploadDataToSPC)
$00:8125 A2 03 LDX #$03 ; X = 3: clear four ports and mirrors
;;; $8127: Clear APU ports and sound mirrors (SPC700ZeroLoop) ;;;
;; Clears APU I/O ports $2140-$2143 and the RAM mirrors $1DF9-$1E00 (sound requests and last-sent music value
;; $1DFF).
;; $008134 (entry point from the Mario Start game mode): uploads the level music bank only when [$1425] is
;; non-zero, [$0109] = $E9,
;; or [$0109], [$141A] and [$141D] are all zero; otherwise returns without uploading.
$00:8127 9E 40 21 STZ $2140,X ; Clear APU port X ($2140-$2143)
$00:812A 9E F9 1D STZ $1DF9,X ; Clear sound mirror $1DF9+X
$00:812D 9E FD 1D STZ $1DFD,X ; Clear $1DFD+X (mirrors $1DFD-$1E00, includes last music value $1DFF)
$00:8130 CA DEX ; \
$00:8131 10 F4 BPL SPC700ZeroLoop ; / X--, loop for X = 3..0
$00:8133 60 RTS ; Return
$00:8134 AD 25 14 LDA $1425 ; Entry from the Mario Start game mode: [$1425] (probably bonus game flag)
$00:8137 D0 0F BNE UploadMusicBank2 ; Non-zero: upload level music
$00:8139 AD 09 01 LDA $0109 ; A = [$0109] (level-load flag)
$00:813C C9 E9 CMP #$E9 ; [$0109] = $E9 (special value)?
$00:813E F0 08 BEQ UploadMusicBank2 ; Yes: upload level music
$00:8140 0D 1A 14 ORA $141A ; \
$00:8143 0D 1D 14 ORA $141D ; } Skip the upload if [$0109], [$141A] or [$141D] is non-zero (probably music already loaded)
$00:8146 D0 EB BNE $008133 ; /
;;; $8148: Upload music bank 2 (levels) (UploadMusicBank2) ;;;
;; Points [$00] at $0E:AED6 (level music) and jumps to StrtSPCMscUpld.
$00:8148 A9 D6 LDA #$D6 ; \
$00:814A 8D 00 00 STA $0000 ; |
$00:814D A9 AE LDA #$AE ; |
$00:814F 8D 01 00 STA $0001 ; |
$00:8152 A9 0E LDA #$0E ; } [$00] = $0EAED6 (music bank 2: level music)
$00:8154 8D 02 00 STA $0002 ; /
$00:8157 80 C4 BRA StrtSPCMscUpld ; Upload it (StrtSPCMscUpld)
;;; $8159: Upload music bank 3 (ending) (UploadMusicBank3) ;;;
;; Points [$00] at $03:E400 (ending/credits music) and jumps to StrtSPCMscUpld.
;; Called by:
;; $00:94A0: Cutscene, ending and game mode code (castle scenes, credits, game over) (CutsceneCastlePal)
$00:8159 A9 00 LDA #$00 ; \
$00:815B 8D 00 00 STA $0000 ; |
$00:815E A9 E4 LDA #$E4 ; |
$00:8160 8D 01 00 STA $0001 ; |
$00:8163 A9 03 LDA #$03 ; } [$00] = $03E400 (music bank 3: ending music)
$00:8165 8D 02 00 STA $0002 ; /
$00:8168 80 B3 BRA StrtSPCMscUpld ; Upload it (StrtSPCMscUpld)
;;; $816A: NMI handler: sound, PPU mirrors, DMA (NMIStart) ;;;
;; Runs once per frame at the start of V-blank. Saves registers, delivers queued music/SFX requests to the
;; SPC700, forces blank,
;; copies the window/color-math mirrors [$41]-[$44] to the PPU, then does all VRAM/CGRAM/OAM DMA and reads the
;; controllers.
;; Lag detection: [$10] is cleared by the main loop when it finishes a frame. If [$10] is still non-zero on
;; entry the game logic
;; overran the frame (lag), so the heavy DMA work is skipped and only scroll registers are updated.
;; [$0D9B] (special level mode): bit 7 set sends control to the Mode 7 boss room path at $0082C4. Falls into
;; NMINotSpecialLv.
$00:816A 78 SEI ; Disable IRQs
$00:816B 08 PHP ; Save processor flags
$00:816C C2 30 REP #$30 ; A, X and Y 16-bit
$00:816E 48 PHA ; \
$00:816F DA PHX ; |
$00:8170 5A PHY ; } Save A, X, Y and the data bank
$00:8171 8B PHB ; /
$00:8172 4B PHK ; \
$00:8173 AB PLB ; / Data bank = program bank ($00)
$00:8174 E2 30 SEP #$30 ; A, X and Y 8-bit
$00:8176 AD 10 42 LDA $4210 ; Acknowledge NMI (read RDNMI)
$00:8179 AD FB 1D LDA $1DFB ; \
$00:817C D0 08 BNE $008186 ; / Music request pending in [$1DFB]? Then go send it
$00:817E AC 42 21 LDY $2142 ; \
$00:8181 CC FF 1D CPY $1DFF ; } Y = APU port 2; if it differs from last sent music value [$1DFF], skip to SFX
$00:8184 D0 09 BNE $00818F ; /
$00:8186 8D 42 21 STA $2142 ; \
$00:8189 8D FF 1D STA $1DFF ; } Port 2 = request (or 0 once echoed), remember it in [$1DFF], clear [$1DFB]
$00:818C 9C FB 1D STZ $1DFB ; /
$00:818F AD F9 1D LDA $1DF9 ; \
$00:8192 8D 40 21 STA $2140 ; / APU port 0 = [$1DF9] (sound effect request)
$00:8195 AD FA 1D LDA $1DFA ; \
$00:8198 8D 41 21 STA $2141 ; / APU port 1 = [$1DFA] (sound effect request)
$00:819B AD FC 1D LDA $1DFC ; \
$00:819E 8D 43 21 STA $2143 ; / APU port 3 = [$1DFC] (sound effect request)
$00:81A1 9C F9 1D STZ $1DF9 ; \
$00:81A4 9C FA 1D STZ $1DFA ; } Clear the three sound effect mirrors
$00:81A7 9C FC 1D STZ $1DFC ; /
$00:81AA A9 80 LDA #$80 ; \
$00:81AC 8D 00 21 STA $2100 ; / Force blank while VRAM, CGRAM and OAM are updated
$00:81AF 9C 0C 42 STZ $420C ; Disable HDMA (re-enabled from [$0D9F] at the end of NMI)
$00:81B2 A5 41 LDA $41 ; \
$00:81B4 8D 23 21 STA $2123 ; / W12SEL = [$41] (BG1/BG2 window mask)
$00:81B7 A5 42 LDA $42 ; \
$00:81B9 8D 24 21 STA $2124 ; / W34SEL = [$42] (BG3/BG4 window mask)
$00:81BC A5 43 LDA $43 ; \
$00:81BE 8D 25 21 STA $2125 ; / WOBJSEL = [$43] (OBJ/color window mask)
$00:81C1 A5 44 LDA $44 ; \
$00:81C3 8D 30 21 STA $2130 ; / CGWSEL = [$44] (color math control)
$00:81C6 AD 9B 0D LDA $0D9B ; \
$00:81C9 10 03 BPL $0081CE ; / [$0D9B] bit 7 clear: normal NMI path
$00:81CB 4C C4 82 JMP $0082C4 ; Bit 7 set: Mode 7 boss room path ($0082C4)
; |
; V It seems a lot of this- for at least x350 bytes- is the very basic handling of lag, levels, exceptions on levels, updating mirrors, etc
$00:81CE A5 40 LDA $40 ; \
$00:81D0 29 FB AND #$FB ; } CGADSUB = [$40] without bit 2: BG3 (status bar) exempt from color math
$00:81D2 8D 31 21 STA $2131 ; /
$00:81D5 A9 09 LDA #$09 ; \
$00:81D7 8D 05 21 STA $2105 ; / BGMODE = $09: Mode 1, BG3 priority, 8x8 tiles
$00:81DA A5 10 LDA $10 ; \
$00:81DC F0 09 BEQ $0081E7 ; / [$10] = 0: main loop finished, no lag, take the full path
$00:81DE AD 9B 0D LDA $0D9B ; \
$00:81E1 4A LSR ; } Lag frame: if [$0D9B] >> 1 = 0 (normal level) just update scroll
$00:81E2 F0 62 BEQ NMINotSpecialLv ; /
$00:81E4 4C 7A 82 JMP $00827A ; Lag frame, other mode: skip to IRQ setup ($00827A)
$00:81E7 E6 10 INC $10 ; Mark the frame handled: [$10]++
$00:81E9 20 88 A4 JSR $00A488 ; DMA queued palette data to CGRAM (MoreDMA)
$00:81EC AD 9B 0D LDA $0D9B ; \
$00:81EF 4A LSR ; } [$0D9B] >> 1 non-zero: other mode, go to $008222
$00:81F0 D0 30 BNE $008222 ; /
$00:81F2 B0 03 BCS $0081F7 ; [$0D9B] bit 0 set: no status bar
$00:81F4 20 AC 8D JSR DrawStatusBar ; Update the status bar (DrawStatusBar)
$00:81F7 AD C6 13 LDA $13C6 ; \
$00:81FA C9 08 CMP #$08 ; } Cutscene [$13C6] = 8 (credits)? If not, go to $008209
$00:81FC D0 0B BNE $008209 ; /
$00:81FE AD FE 1F LDA $1FFE ; \
$00:8201 F0 17 BEQ $00821A ; / Credits: only reload if [$1FFE] is set, else go to $00821A
$00:8203 22 67 95 0C JSL $9567 ; Credits: reload graphics/palette for the new background ($9567)
$00:8207 80 11 BRA $00821A ; Continue at $00821A
$00:8209 22 AD 87 00 JSL $87AD ; Upload pending layer 1 tilemap update to VRAM ($87AD)
$00:820D AD 3A 14 LDA $143A ; \
$00:8210 F0 05 BEQ $05 [$8217] ; / [$143A] = 0 (no Mario Start! graphics): go to $008217
$00:8212 20 C2 A7 JSR $A7C2 ; DMA the Mario Start! graphics ($A7C2)
$00:8215 80 26 BRA $00823D ; Continue at $00823D
$00:8217 20 90 A3 JSR $00A390 ; DMA queued tile rows to VRAM ($A390)
$00:821A 20 36 A4 JSR $00A436 ; DMA 2 x $C0 bytes of tiles to VRAM $64A0/$65A0 if [$1935] is set ($A436)
$00:821D 20 00 A3 JSR MarioGFXDMA ; DMA Mario's graphics and palette (MarioGFXDMA)
$00:8220 80 1B BRA $00823D ; Continue at $00823D
$00:8222 AD D9 13 LDA $13D9 ; \
$00:8225 C9 0A CMP #$0A ; } Overworld process [$13D9] = $0A? If not, go to $008237
$00:8227 D0 0E BNE $008237 ; /
$00:8229 AC E8 1D LDY $1DE8 ; \
$00:822C 88 DEY ; |
$00:822D 88 DEY ; |
$00:822E C0 04 CPY #$04 ; } Y = [$1DE8] - 2; if Y >= 4 go to $008237
$00:8230 B0 05 BCS $008237 ; /
$00:8232 20 29 A5 JSR $00A529 ; DMA large tile blocks to VRAM, indexed by Y ($A529)
$00:8235 80 0C BRA $008243 ; Skip the other DMA, go to the controller read ($008243)
$00:8237 20 E3 A4 JSR $00A4E3 ; DMA $0160 bytes from $00:0AF6 to VRAM $0750 and poke palette colors ($A4E3)
$00:823A 20 00 A3 JSR MarioGFXDMA ; DMA Mario's graphics and palette (MarioGFXDMA)
$00:823D 20 D2 85 JSR LoadScrnImage ; Upload the stripe image selected by [$12] (LoadScrnImage)
$00:8240 20 49 84 JSR DoSomeSpriteDMA ; DMA the OAM buffer to OAM (DoSomeSpriteDMA)
$00:8243 20 50 86 JSR ControllerUpdate ; Read the controllers (ControllerUpdate)
;;; $8246: NMI tail: scroll, IRQ setup, Mode 7 path (NMINotSpecialLv) ;;;
;; $008246: writes BG1 and BG2 scroll from the RAM mirrors, then (normal levels) arms the status bar IRQ at
;; $008292, zeroes BG3 scroll,
;; restores brightness [$0DAE] and HDMA enable [$0D9F] and returns with RTI.
;; $0082C4: NMI path for Mode 7 boss rooms ([$0D9B] bit 7): same DMA work, then Mode 7 center and matrix
;; registers from [$2A]-[$35].
;; $00835C: chooses the IRQ scanline for those rooms ($24, or $2D for some bosses).
$00:8246 A5 1A LDA RAM_ScreenBndryXLo ; \
$00:8248 8D 0D 21 STA $210D ; |
$00:824B A5 1B LDA RAM_ScreenBndryXHi ; } BG1 H-scroll = [$1A]/[$1B] (screen boundary X)
$00:824D 8D 0D 21 STA $210D ; /
$00:8250 A5 1C LDA RAM_ScreenBndryYLo ; \
$00:8252 18 CLC ; |
$00:8253 6D 88 18 ADC RAM_Layer1DispYLo ; |
$00:8256 8D 0E 21 STA $210E ; |
$00:8259 A5 1D LDA RAM_ScreenBndryYHi ; |
$00:825B 6D 89 18 ADC RAM_Layer1DispYHi ; } BG1 V-scroll = [$1C]/[$1D] + [$1888] (layer 1 Y displacement)
$00:825E 8D 0E 21 STA $210E ; /
$00:8261 A5 1E LDA $1E ; \
$00:8263 8D 0F 21 STA $210F ; |
$00:8266 A5 1F LDA $1F ; } BG2 H-scroll = [$1E]/[$1F]
$00:8268 8D 0F 21 STA $210F ; /
$00:826B A5 20 LDA $20 ; \
$00:826D 8D 10 21 STA $2110 ; |
$00:8270 A5 21 LDA $21 ; } BG2 V-scroll = [$20]/[$21]
$00:8272 8D 10 21 STA $2110 ; /
$00:8275 AD 9B 0D LDA $0D9B ; \
$00:8278 F0 18 BEQ $008292 ; / [$0D9B] = 0 (normal level): arm the status bar IRQ ($008292)
$00:827A A9 81 LDA #$81 ; A = $81: NMI and joypad on, IRQ off
$00:827C AC C6 13 LDY $13C6 ; \
$00:827F C0 08 CPY #$08 ; } Cutscene [$13C6] != 8 (not credits): write NMITIMEN at $0082A1
$00:8281 D0 1E BNE $0082A1 ; /
$00:8283 AC AE 0D LDY $0DAE ; \
$00:8286 8C 00 21 STY $2100 ; / Credits: brightness = [$0DAE]
$00:8289 AC 9F 0D LDY $0D9F ; \
$00:828C 8C 0C 42 STY $420C ; / Credits: HDMA enable = [$0D9F]
$00:828F 4C 8C 83 JMP IRQNMIEnding ; Finish through IRQNMIEnding
$00:8292 A0 24 LDY.B #$24 ; Y = $24: scanline of the status bar IRQ split
$00:8294 AD 11 42 LDA.W $4211 ; Acknowledge any pending IRQ (read TIMEUP)
$00:8297 8C 09 42 STY.W $4209 ; V-count timer low = Y
$00:829A 9C 0A 42 STZ.W $420A ; V-count timer high = 0
$00:829D 64 11 STZ $11 ; IRQ stage [$11] = 0
$00:829F A9 A1 LDA.B #$A1 ; A = $A1: NMI, V-count IRQ and joypad auto-read
$00:82A1 8D 00 42 STA.W $4200 ; NMITIMEN = A
$00:82A4 9C 11 21 STZ.W $2111 ; \
$00:82A7 9C 11 21 STZ.W $2111 ; |
$00:82AA 9C 12 21 STZ.W $2112 ; } BG3 H and V scroll = 0 (status bar does not scroll)
$00:82AD 9C 12 21 STZ.W $2112 ; /
$00:82B0 AD AE 0D LDA.W $0DAE ; \
$00:82B3 8D 00 21 STA.W $2100 ; / INIDISP = [$0DAE]: brightness, ends force blank
$00:82B6 AD 9F 0D LDA.W $0D9F ; \
$00:82B9 8D 0C 42 STA.W $420C ; / HDMA channel enable = [$0D9F]
$00:82BC C2 30 REP #$30 ; \
$00:82BE AB PLB ; |
$00:82BF 7A PLY ; |
$00:82C0 FA PLX ; |
$00:82C1 68 PLA ; } Restore registers and flags
$00:82C2 28 PLP ; /
$00:82C3 40 RTI ; Return from NMI
$00:82C4 A5 10 LDA $10 ; \
$00:82C6 D0 2F BNE $82F7 ; / Lag frame ([$10] != 0): skip the DMA work, go to $0082F7
$00:82C8 E6 10 INC $10 ; Mark the frame handled: [$10]++
$00:82CA AD 3A 14 LDA.W $143A ; \
$00:82CD F0 05 BEQ $82D4 ; / [$143A] = 0 (no Mario Start! graphics): go to $0082D4
$00:82CF 20 C2 A7 JSR.W $A7C2 ; DMA the Mario Start! graphics ($A7C2)
$00:82D2 80 14 BRA $82E8 ; Continue at $0082E8
$00:82D4 20 36 A4 JSR.W $A436 ; DMA tiles to VRAM $64A0/$65A0 if [$1935] is set ($A436)
$00:82D7 20 00 A3 JSR.W MarioGFXDMA ; DMA Mario's graphics and palette (MarioGFXDMA)
$00:82DA 2C 9B 0D BIT.W $0D9B ; \
$00:82DD 50 09 BVC $82E8 ; / [$0D9B] bit 6 clear (Iggy/Larry): skip boss tile animation
$00:82DF 20 A9 98 JSR.W $98A9 ; Animate boss room tiles by DMA ($98A9)
$00:82E2 AD 9B 0D LDA.W $0D9B ; \
$00:82E5 4A LSR ; } [$0D9B] bit 0 set: skip the status bar, go to $0082EB
$00:82E6 B0 03 BCS $82EB ; /
$00:82E8 20 AC 8D JSR.W DrawStatusBar ; Update the status bar (DrawStatusBar)
$00:82EB 20 88 A4 JSR.W MoreDMA ; DMA queued palette data to CGRAM (MoreDMA)
$00:82EE 20 D2 85 JSR.W LoadScrnImage ; Upload the stripe image selected by [$12] (LoadScrnImage)
$00:82F1 20 49 84 JSR.W DoSomeSpriteDMA ; DMA the OAM buffer to OAM (DoSomeSpriteDMA)
$00:82F4 20 50 86 JSR.W ControllerUpdate ; Read the controllers (ControllerUpdate)
$00:82F7 A9 09 LDA.B #$09 ; \
$00:82F9 8D 05 21 STA.W $2105 ; / BGMODE = $09: Mode 1, BG3 priority (for the status bar region)
$00:82FC A5 2A LDA $2A ; \
$00:82FE 18 CLC ; |
$00:82FF 69 80 ADC.B #$80 ; |
$00:8301 8D 1F 21 STA.W $211F ; |
$00:8304 A5 2B LDA $2B ; |
$00:8306 69 00 ADC.B #$00 ; } Mode 7 center X = [$2A]/[$2B] + $0080
$00:8308 8D 1F 21 STA.W $211F ; /
$00:830B A5 2C LDA $2C ; \
$00:830D 18 CLC ; |
$00:830E 69 80 ADC.B #$80 ; |
$00:8310 8D 20 21 STA.W $2120 ; |
$00:8313 A5 2D LDA $2D ; |
$00:8315 69 00 ADC.B #$00 ; } Mode 7 center Y = [$2C]/[$2D] + $0080
$00:8317 8D 20 21 STA.W $2120 ; /
$00:831A A5 2E LDA $2E ; \
$00:831C 8D 1B 21 STA.W $211B ; |
$00:831F A5 2F LDA $2F ; } Mode 7 matrix A = [$2E]/[$2F]
$00:8321 8D 1B 21 STA.W $211B ; /
$00:8324 A5 30 LDA $30 ; \
$00:8326 8D 1C 21 STA.W $211C ; |
$00:8329 A5 31 LDA $31 ; } Mode 7 matrix B = [$30]/[$31]
$00:832B 8D 1C 21 STA.W $211C ; /
$00:832E A5 32 LDA $32 ; \
$00:8330 8D 1D 21 STA.W $211D ; |
$00:8333 A5 33 LDA $33 ; } Mode 7 matrix C = [$32]/[$33]
$00:8335 8D 1D 21 STA.W $211D ; /
$00:8338 A5 34 LDA $34 ; \
$00:833A 8D 1E 21 STA.W $211E ; |
$00:833D A5 35 LDA $35 ; } Mode 7 matrix D = [$34]/[$35]
$00:833F 8D 1E 21 STA.W $211E ; /
$00:8342 20 16 84 JSR.W SETL1SCROLL ; Set BG1 base addresses and scroll (SETL1SCROLL)
$00:8345 AD 9B 0D LDA.W $0D9B ; \
$00:8348 4A LSR ; } [$0D9B] bit 0 clear: go to the IRQ setup at $00835C
$00:8349 90 11 BCC $835C ; /
$00:834B AD AE 0D LDA.W $0DAE ; \
$00:834E 8D 00 21 STA.W $2100 ; / INIDISP = [$0DAE]: brightness
$00:8351 AD 9F 0D LDA.W $0D9F ; \
$00:8354 8D 0C 42 STA.W $420C ; / HDMA channel enable = [$0D9F]
$00:8357 A9 81 LDA.B #$81 ; \
$00:8359 4C F3 83 JMP.W $83F3 ; / A = $81 (no IRQ), go set up Mode 7 at $0083F3
$00:835C A0 24 LDY.B #$24 ; Y = $24: default IRQ scanline
$00:835E 2C 9B 0D BIT.W $0D9B ; \
$00:8361 50 0E BVC $8371 ; / [$0D9B] bit 6 clear (Iggy/Larry): keep line $24
$00:8363 AD FC 13 LDA.W $13FC ; \
$00:8366 0A ASL ; |
$00:8367 AA TAX ; |
$00:8368 BD E8 F8 LDA.W $F8E8,X ; |
$00:836B C9 2A CMP.B #$2A ; } Look up [$13FC] in $F8E8; keep $24 unless the entry is $2A
$00:836D D0 02 BNE $8371 ; /
$00:836F A0 2D LDY.B #$2D ; Y = $2D: later IRQ scanline for this boss
$00:8371 4C 94 82 JMP.W $8294 ; Program the V-count IRQ at line Y ($008294)
;;; $8374: IRQ vector entry (IRQHandler) ;;;
;; Masks further IRQs and falls into IRQStart.
$00:8374 78 SEI ; Mask further IRQs
;;; $8375: IRQ: save registers, check timer (IRQStart) ;;;
;; Saves state, acknowledges the IRQ via $4211 and ignores it unless the V-count timer fired. Bit 7 of [$0D9B]
;; set sends control
;; to the Mode 7 boss room IRQ code at $0083BA. Otherwise falls into IRQNMIEnding.
$00:8375 08 PHP ; Save processor flags
$00:8376 C2 30 REP #$30 ; A, X and Y 16-bit
$00:8378 48 PHA ; \
$00:8379 DA PHX ; |
$00:837A 5A PHY ; } Save A, X, Y and the data bank
$00:837B 8B PHB ; /
$00:837C 4B PHK ; \
$00:837D AB PLB ; / Data bank = program bank ($00)
$00:837E E2 30 SEP #$30 ; A, X and Y 8-bit
$00:8380 AD 11 42 LDA.W $4211 ; Read TIMEUP: acknowledges the IRQ, bit 7 = V-count timer fired
$00:8383 10 2D BPL $83B2 ; Timer did not fire: just restore registers and return
$00:8385 A9 81 LDA.B #$81 ; A = $81: NMI and joypad on, IRQ off
$00:8387 AC 9B 0D LDY.W $0D9B ; Y = [$0D9B] (special level mode)
$00:838A 30 2E BMI $83BA ; Bit 7 set (Mode 7 boss room): go to $0083BA
;;; $838C: IRQ: set BG3 scroll and screen mode (IRQNMIEnding) ;;;
;; Status bar raster split. Writes NMITIMEN from A, waits for H-blank, then sets BG3 scroll from [$22]-[$25],
;; BGMODE from [$3E]
;; and CGADSUB from [$40] for the part of the screen below the status bar. Restores registers and falls into
;; the RTI.
;; Parameters: A = value for NMITIMEN ($4200).
;; Called by:
;; $00:828F: NMI tail: scroll, IRQ setup, Mode 7 path (NMINotSpecialLv)
$00:838C 8D 00 42 STA.W $4200 ; NMITIMEN = A
$00:838F A0 1F LDY.B #$1F ; Y = $1F: delay count
$00:8391 20 3B 84 JSR.W WaitForHBlank ; Wait for H-blank (WaitForHBlank)
$00:8394 A5 22 LDA $22 ; \
$00:8396 8D 11 21 STA.W $2111 ; |
$00:8399 A5 23 LDA $23 ; } BG3 H-scroll = [$22]/[$23]
$00:839B 8D 11 21 STA.W $2111 ; /
$00:839E A5 24 LDA $24 ; \
$00:83A0 8D 12 21 STA.W $2112 ; |
$00:83A3 A5 25 LDA $25 ; } BG3 V-scroll = [$24]/[$25]
$00:83A5 8D 12 21 STA.W $2112 ; /
$00:83A8 A5 3E LDA $3E ; \
$00:83AA 8D 05 21 STA.W $2105 ; / BGMODE = [$3E] (the level's screen mode)
$00:83AD A5 40 LDA $40 ; \
$00:83AF 8D 31 21 STA.W $2131 ; / CGADSUB = [$40] (color math now includes BG3)
$00:83B2 C2 30 REP #$30 ; \
$00:83B4 AB PLB ; |
$00:83B5 7A PLY ; |
$00:83B6 FA PLX ; |
$00:83B7 68 PLA ; } Restore registers and flags
$00:83B8 28 PLP ; /
;;; $83B9: IRQ return and Mode 7 boss splits (EmptyHandler) ;;;
;; $0083B9: the RTI that ends every IRQ.
;; $0083BA: IRQ path for Mode 7 boss rooms. Iggy/Larry ([$0D9B] bit 6 clear) use a single split that switches
;; to Mode 7 below the
;; status bar. Others use two stages counted in [$11]: stage 0 programs a second V-count IRQ at line $AE -
;; [$1888] and enters Mode 7;
;; stage 1 restores the Mode 1 layer 1 settings below it.
$00:83B9 40 RTI ; Return from interrupt
$00:83BA 2C 9B 0D BIT.W $0D9B ; \
$00:83BD 50 24 BVC $83E3 ; / [$0D9B] bit 6 clear (Iggy/Larry): single split, go to $0083E3
$00:83BF A4 11 LDY $11 ; \
$00:83C1 F0 0D BEQ $83D0 ; / [$11] = 0 (first stage): go to $0083D0
$00:83C3 8D 00 42 STA.W $4200 ; Second stage: NMITIMEN = $81, no more IRQs
$00:83C6 A0 14 LDY.B #$14 ; Y = $14: delay count
$00:83C8 20 3B 84 JSR.W WaitForHBlank ; Wait for H-blank (WaitForHBlank)
$00:83CB 20 16 84 JSR.W SETL1SCROLL ; Restore BG1 base addresses and scroll (SETL1SCROLL)
$00:83CE 80 D8 BRA $83A8 ; Restore BGMODE and CGADSUB, then exit ($0083A8)
$00:83D0 E6 11 INC $11 ; IRQ stage [$11] = 1
$00:83D2 AD 11 42 LDA.W $4211 ; Acknowledge any pending IRQ
$00:83D5 A9 AE LDA.B #$AE ; \
$00:83D7 38 SEC ; |
$00:83D8 ED 88 18 SBC.W RAM_Layer1DispYLo ; } V-count timer low = $AE - [$1888] (second split near the bottom)
$00:83DB 8D 09 42 STA.W $4209 ; /
$00:83DE 9C 0A 42 STZ.W $420A ; V-count timer high = 0
$00:83E1 A9 A1 LDA.B #$A1 ; A = $A1: NMI, V-count IRQ and joypad auto-read
$00:83E3 AC 93 14 LDY.W $1493 ; \
$00:83E6 F0 0B BEQ $83F3 ; / [$1493] (end-of-level timer) = 0: go to $0083F3
$00:83E8 AC 95 14 LDY.W $1495 ; \
$00:83EB C0 40 CPY.B #$40 ; } [$1495] < $40: go to $0083F3
$00:83ED 90 04 BCC $83F3 ; /
$00:83EF A9 81 LDA.B #$81 ; A = $81: no more IRQs
$00:83F1 80 99 BRA IRQNMIEnding ; Exit through IRQNMIEnding (skips the Mode 7 switch)
$00:83F3 8D 00 42 STA.W $4200 ; NMITIMEN = A
$00:83F6 20 39 84 JSR.W $8439 ; Wait for H-blank ($8439, Y = $20)
$00:83F9 EA NOP ; \
$00:83FA EA NOP ; / Padding NOPs (probably a removed JSL)
$00:83FB A9 07 LDA.B #$07 ; \
$00:83FD 8D 05 21 STA.W $2105 ; / BGMODE = $07: Mode 7
$00:8400 A5 3A LDA $3A ; \
$00:8402 8D 0D 21 STA.W $210D ; |
$00:8405 A5 3B LDA $3B ; } BG1 H-scroll = [$3A]/[$3B] (Mode 7 scroll)
$00:8407 8D 0D 21 STA.W $210D ; /
$00:840A A5 3C LDA $3C ; \
$00:840C 8D 0E 21 STA.W $210E ; |
$00:840F A5 3D LDA $3D ; } BG1 V-scroll = [$3C]/[$3D] (Mode 7 scroll)
$00:8411 8D 0E 21 STA.W $210E ; /
$00:8414 80 9C BRA $83B2 ; Restore registers and return ($0083B2)
;;; $8416: Set BG1 base addresses and scroll (SETL1SCROLL) ;;;
;; Sets BG1 tilemap to VRAM $5800 (64x32), BG1 tiles to VRAM $7000, and BG1 scroll to [$1A]/[$1B] horizontally
;; and
;; [$1C] + [$1888] / [$1D] vertically. Used by the Mode 7 boss room code to restore Mode 1 BG1 around the Mode
;; 7 region.
;; $008439 (last line here) is the Y = $20 entry point of WaitForHBlank.
;; Called by:
;; $00:8342: NMI tail: scroll, IRQ setup, Mode 7 path (NMINotSpecialLv)
;; $00:83CB: IRQ return and Mode 7 boss splits (EmptyHandler)
$00:8416 A9 59 LDA.B #$59 ; \
$00:8418 8D 07 21 STA.W $2107 ; / BG1 tilemap = VRAM $5800, 64x32
$00:841B A9 07 LDA.B #$07 ; \
$00:841D 8D 0B 21 STA.W $210B ; / BG1 tiles = VRAM $7000, BG2 tiles = VRAM $0000
$00:8420 A5 1A LDA RAM_ScreenBndryXLo ; \
$00:8422 8D 0D 21 STA.W $210D ; |
$00:8425 A5 1B LDA RAM_ScreenBndryXHi ; } BG1 H-scroll = [$1A]/[$1B]
$00:8427 8D 0D 21 STA.W $210D ; /
$00:842A A5 1C LDA RAM_ScreenBndryYLo ; \
$00:842C 18 CLC ; |
$00:842D 6D 88 18 ADC.W RAM_Layer1DispYLo ; } BG1 V-scroll low = [$1C] + [$1888]
$00:8430 8D 0E 21 STA.W $210E ; /
$00:8433 A5 1D LDA RAM_ScreenBndryYHi ; \
$00:8435 8D 0E 21 STA.W $210E ; / BG1 V-scroll high = [$1D]
$00:8438 60 RTS ; Return
$00:8439 A0 20 LDY.B #$20 ; Y = $20: delay count (entry point for WaitForHBlank)
;;; $843B: Wait for H-blank, then delay (WaitForHBlank) ;;;
;; Polls HVBJOY ($4212) bit 6. If already in H-blank, retries with Y = $20 (overwriting Y); once H-blank
;; begins, burns Y loop
;; iterations (DEY/BNE, 5 cycles each) so the caller's PPU writes land at a consistent point in the scanline.
;; Parameters: Y: delay loop count (entry at $008439 uses $20).
;; Called by:
;; $00:8391: IRQ: set BG3 scroll and screen mode (IRQNMIEnding)
;; $00:83C8: IRQ return and Mode 7 boss splits (EmptyHandler)
$00:843B 2C 12 42 BIT.W $4212 ; Read HVBJOY; V flag = bit 6 (H-blank)
$00:843E 70 F9 BVS $8439 ; Already in H-blank: restart with Y = $20
$00:8440 2C 12 42 BIT.W $4212 ; Read HVBJOY
$00:8443 50 FB BVC $8440 ; Not in H-blank yet: keep polling
$00:8445 88 DEY ; \
$00:8446 D0 FD BNE $8445 ; / Delay: loop until Y = 0
$00:8448 60 RTS ; Return
;;; $8449: DMA OAM buffer to OAM (DoSomeSpriteDMA) ;;;
;; Copies the $0220-byte OAM shadow buffer at $00:0200 to OAM using DMA channel 0, then sets OAM address to
;; [$3F]
;; with priority rotation on, so the sprite at that index has highest priority.
;; Called by:
;; $00:8240: NMI handler: sound, PPU mirrors, DMA (NMIStart)
;; $00:82F1: NMI tail: scroll, IRQ setup, Mode 7 path (NMINotSpecialLv)
;; $00:8646: Upload stripe image to VRAM (LoadScrnImage)
$00:8449 9C 00 43 STZ.W $4300 ; DMA channel 0: mode 0 (single register write)
$00:844C C2 20 REP #$20 ; A 16-bit
$00:844E 9C 02 21 STZ.W $2102 ; OAM address = 0
$00:8451 A9 04 00 LDA.W #$0004 ; \
$00:8454 8D 01 43 STA.W $4301 ; / B-bus register = $04 (OAMDATA)
$00:8457 A9 02 00 LDA.W #$0002 ; \
$00:845A 8D 03 43 STA.W $4303 ; / Source address = $00:0200 (OAM shadow buffer)
$00:845D A9 20 02 LDA.W #$0220 ; \
$00:8460 8D 05 43 STA.W $4305 ; / Byte count = $0220 (whole OAM)
$00:8463 A0 01 LDY.B #$01 ; \
$00:8465 8C 0B 42 STY.W $420B ; / Start DMA channel 0
$00:8468 E2 20 SEP #$20 ; A 8-bit
$00:846A A9 80 LDA.B #$80 ; \
$00:846C 8D 03 21 STA.W $2103 ; / OAMADDH = $80: sprite priority rotation on
$00:846F A5 3F LDA $3F ; \
$00:8471 8D 02 21 STA.W $2102 ; / OAMADDL = [$3F]: sets which sprite has highest priority
$00:8474 60 RTS ; Return
;;; $8475..848D: Table: OAM size table offsets ;;;
;; Offsets into the $0420 table for $8494: 8 per step, read with an 8-bit index Y = 0,2,4..$1E. Odd
;; bytes are zero padding.
$00:8475 .db $00,$00,$08,$00,$10,$00,$18,$00 ; $00-$06: offsets $00, $08, $10, $18
$00:847D .db $20,$00,$28,$00,$30,$00,$38,$00 ; $08-$0E: offsets $20, $28, $30, $38
$00:8485 .db $40,$00,$48,$00,$50,$00,$58,$00 ; $10-$16: offsets $40, $48, $50, $58
$00:848D .db $60,$00,$68,$00,$70,$00,$78 ; $18-$1E: offsets $60, $68, $70, $78
;;; $8494: Pack OAM size bits into high table ;;;
;; Packs the one-byte-per-sprite size/X-high table at $0420-$049F (values 0-3) into the 2-bits-per-sprite OAM
;; high table at
;; $0400-$041F: byte = s3<<6 | s2<<4 | s1<<2 | s0, four sprites per byte. 16 iterations of two output bytes
;; each.
;; $0084C8: long-call wrapper (RTL) that sets the data bank to $00 and runs LoadScrnImage; called from bank
;; $0C.
;; Called by:
;; $00:91E6: Mario Start text and level setup helpers
;; $00:9554: Cutscene, ending and game mode code (castle scenes, credits, game over) (CutsceneCastlePal)
;; $00:955B: Cutscene, ending and game mode code (castle scenes, credits, game over) (CutsceneCastlePal)
;; $00:95B9: Cutscene, ending and game mode code (castle scenes, credits, game over) (CutsceneCastlePal)
;; $00:963A: Cutscene, ending and game mode code (castle scenes, credits, game over) (CutsceneCastlePal)
;; $00:9683: Cutscene, ending and game mode code (castle scenes, credits, game over) (CutsceneCastlePal)
;; $00:97B9: Game mode 11: Mario Start, level music (MarioStartGameMode)
;; $00:A16D: Game mode 0C: load overworld (LoadMapGameMode)
;; $00:A1CB: Clear RAM; game mode 0E: overworld (Clear_1A_13D3)
;; $00:A2F0: Game mode 14: in level (InLevelGameMode)
;; $00:A5F3: Game mode 12: prepare level (GM04Load)
$00:8494 A0 1E LDY.B #$1E ; Y = $1E: index of the last two output bytes
$00:8496 BE 75 84 LDX.W $8475,Y ; X = 4*Y: offset of this group of 8 sprites in $0420 (8-bit index)
$00:8499 BD 23 04 LDA.W $0423,X ; \
$00:849C 0A ASL ; |
$00:849D 0A ASL ; |
$00:849E 1D 22 04 ORA.W $0422,X ; |
$00:84A1 0A ASL ; |
$00:84A2 0A ASL ; |
$00:84A3 1D 21 04 ORA.W $0421,X ; |
$00:84A6 0A ASL ; |
$00:84A7 0A ASL ; } A = [$0420+X..$0423+X] packed 2 bits each, entry X in bits 0-1
$00:84A8 1D 20 04 ORA.W $0420,X ; /
$00:84AB 99 00 04 STA.W $0400,Y ; Store in OAM high table byte [$0400+Y]
$00:84AE BD 27 04 LDA.W $0427,X ; \
$00:84B1 0A ASL ; |
$00:84B2 0A ASL ; |
$00:84B3 1D 26 04 ORA.W $0426,X ; |
$00:84B6 0A ASL ; |
$00:84B7 0A ASL ; |
$00:84B8 1D 25 04 ORA.W $0425,X ; |
$00:84BB 0A ASL ; |
$00:84BC 0A ASL ; } A = [$0424+X..$0427+X] packed 2 bits each, entry X+4 in bits 0-1
$00:84BD 1D 24 04 ORA.W $0424,X ; /
$00:84C0 99 01 04 STA.W $0401,Y ; Store in OAM high table byte [$0401+Y]
$00:84C3 88 DEY ; \
$00:84C4 88 DEY ; } Y -= 2; loop for all 16 pairs
$00:84C5 10 CF BPL $8496 ; /
$00:84C7 60 RTS ; Return
$00:84C8 8B PHB ; \
$00:84C9 4B PHK ; } Data bank = program bank (old bank saved)
$00:84CA AB PLB ; /
$00:84CB 20 D2 85 JSR.W LoadScrnImage ; Upload the stripe image selected by [$12] (LoadScrnImage)
$00:84CE AB PLB ; Restore the data bank
$00:84CF 6B RTL ; Return long
;;; $84D0: Pointer table: stripe images (ImagePointers) ;;;
;; 3-byte pointers (16-bit address, bank), indexed by [$12] (byte offset = image number * 3). Each points to a
;; stripe image: a list
;; of VRAM upload records read by LoadScrnImage. Entry $00 is the runtime buffer at $7F:837D that the game
;; fills itself.
;; Cutscene text numbering is inferred from the pointer order (each text line is $35 bytes after the next).
$00:84D0 7D 83 7F .dw $837D .db $7F ; $00 - RAM stripe buffer at $7F:837D, filled by the game at runtime (default)
$00:84D3 75 B3 05 .dw $B375 .db :$DATA_05B375 ; $03 - Title screen
$00:84D6 00 A4 04 .dw $A400 .db :$DATA_04A400 ; $06 - Overworld border
$00:84D9 FF B0 05 .dw $B0FF .db :$DATA_05B0FF ; $09 - (purpose unknown)
$00:84DC 1C B9 05 .dw $B91C .db :$DATA_05B91C ; $0C - CONTINUE/END
$00:84DF 00 B8 0C .dw $B800 .db :$DATA_0CB800 ; $0F - (purpose unknown)
$00:84E2 72 B8 05 .dw $B872 .db :$DATA_05B872 ; $12 - 1 PLAYER GAME / 2 PLAYER GAME
$00:84E5 9F 81 04 .dw $819F .db :$DATA_04819F ; $15 - Overworld scroll arrows
$00:84E8 E0 81 04 .dw $81E0 .db :$DATA_0481E0 ; $18 - Remove overworld scroll arrows
$00:84EB 99 F4 04 .dw $F499 .db :$DATA_04F499 ; $1B - (purpose unknown)
$00:84EE C7 B8 05 .dw $B8C7 .db :$DATA_05B8C7 ; $1E - CONTINUE AND SAVE
$00:84F1 F1 BF 0C .dw $BFF1 .db :$DATA_0CBFF1 ; $21 - Empty image (only the $FF end marker at $0C:BFF1)
$00:84F4 C3 BF 0C .dw $BFC3 .db :$DATA_0CBFC3 ; $24 - Cutscene 1 text: line 7
$00:84F7 8E BF 0C .dw $BF8E .db :$DATA_0CBF8E ; $27 - Cutscene 1 text: line 6
$00:84FA 59 BF 0C .dw $BF59 .db :$DATA_0CBF59 ; $2A - Cutscene 1 text: line 5
$00:84FD 24 BF 0C .dw $BF24 .db :$DATA_0CBF24 ; $2D - Cutscene 1 text: line 4
$00:8500 EF BE 0C .dw $BEEF .db :$DATA_0CBEEF ; $30 - Cutscene 1 text: line 3
$00:8503 BA BE 0C .dw $BEBA .db :$DATA_0CBEBA ; $33 - Cutscene 1 text: line 2
$00:8506 85 BE 0C .dw $BE85 .db :$DATA_0CBE85 ; $36 - Cutscene 1 text: line 1
$00:8509 65 C1 0C .dw $C165 .db :$DATA_0CC165 ; $39 - Cutscene 2 text: line 8
$00:850C 30 C1 0C .dw $C130 .db :$DATA_0CC130 ; $3C - Cutscene 2 text: line 7
$00:850F FB C0 0C .dw $C0FB .db :$DATA_0CC0FB ; $3F - Cutscene 2 text: line 6
$00:8512 C6 C0 0C .dw $C0C6 .db :$DATA_0CC0C6 ; $42 - Cutscene 2 text: line 5
$00:8515 91 C0 0C .dw $C091 .db :$DATA_0CC091 ; $45 - Cutscene 2 text: line 4
$00:8518 5C C0 0C .dw $C05C .db :$DATA_0CC05C ; $48 - Cutscene 2 text: line 3
$00:851B 27 C0 0C .dw $C027 .db :$DATA_0CC027 ; $4B - Cutscene 2 text: line 2
$00:851E F2 BF 0C .dw $BFF2 .db :$DATA_0CBFF2 ; $4E - Cutscene 2 text: line 1
$00:8521 F1 BF 0C .dw $BFF1 .db :$DATA_0CBFF1 ; $51 - Empty image (only the $FF end marker at $0C:BFF1)
$00:8524 CE C2 0C .dw $C2CE .db :$DATA_0CC2CE ; $54 - Cutscene 3 text: line 7
$00:8527 99 C2 0C .dw $C299 .db :$DATA_0CC299 ; $57 - Cutscene 3 text: line 6
$00:852A 64 C2 0C .dw $C264 .db :$DATA_0CC264 ; $5A - Cutscene 3 text: line 5
$00:852D 2F C2 0C .dw $C22F .db :$DATA_0CC22F ; $5D - Cutscene 3 text: line 4
$00:8530 FA C1 0C .dw $C1FA .db :$DATA_0CC1FA ; $60 - Cutscene 3 text: line 3
$00:8533 C5 C1 0C .dw $C1C5 .db :$DATA_0CC1C5 ; $63 - Cutscene 3 text: line 2
$00:8536 90 C1 0C .dw $C190 .db :$DATA_0CC190 ; $66 - Cutscene 3 text: line 1
$00:8539 6C C4 0C .dw $C46C .db :$DATA_0CC46C ; $69 - Cutscene 4 text: line 8
$00:853C 37 C4 0C .dw $C437 .db :$DATA_0CC437 ; $6C - Cutscene 4 text: line 7
$00:853F 02 C4 0C .dw $C402 .db :$DATA_0CC402 ; $6F - Cutscene 4 text: line 6
$00:8542 CD C3 0C .dw $C3CD .db :$DATA_0CC3CD ; $72 - Cutscene 4 text: line 5
$00:8545 98 C3 0C .dw $C398 .db :$DATA_0CC398 ; $75 - Cutscene 4 text: line 4
$00:8548 63 C3 0C .dw $C363 .db :$DATA_0CC363 ; $78 - Cutscene 4 text: line 3
$00:854B 2E C3 0C .dw $C32E .db :$DATA_0CC32E ; $7B - Cutscene 4 text: line 2
$00:854E F9 C2 0C .dw $C2F9 .db :$DATA_0CC2F9 ; $7E - Cutscene 4 text: line 1
$00:8551 F1 BF 0C .dw $BFF1 .db :$DATA_0CBFF1 ; $81 - Empty image (only the $FF end marker at $0C:BFF1)
$00:8554 DD C5 0C .dw $C5DD .db :$DATA_0CC5DD ; $84 - Cutscene 5 text: line 7
$00:8557 A8 C5 0C .dw $C5A8 .db :$DATA_0CC5A8 ; $87 - Cutscene 5 text: line 6
$00:855A 73 C5 0C .dw $C573 .db :$DATA_0CC573 ; $8A - Cutscene 5 text: line 5
$00:855D 3E C5 0C .dw $C53E .db :$DATA_0CC53E ; $8D - Cutscene 5 text: line 4
$00:8560 09 C5 0C .dw $C509 .db :$DATA_0CC509 ; $90 - Cutscene 5 text: line 3
$00:8563 D4 C4 0C .dw $C4D4 .db :$DATA_0CC4D4 ; $93 - Cutscene 5 text: line 2
$00:8566 9F C4 0C .dw $C49F .db :$DATA_0CC49F ; $96 - Cutscene 5 text: line 1
$00:8569 85 C7 0C .dw $C785 .db :$DATA_0CC785 ; $99 - Cutscene 6 text: line 8
$00:856C 50 C7 0C .dw $C750 .db :$DATA_0CC750 ; $9C - Cutscene 6 text: line 7
$00:856F 1B C7 0C .dw $C71B .db :$DATA_0CC71B ; $9F - Cutscene 6 text: line 6
$00:8572 E6 C6 0C .dw $C6E6 .db :$DATA_0CC6E6 ; $A2 - Cutscene 6 text: line 5
$00:8575 B1 C6 0C .dw $C6B1 .db :$DATA_0CC6B1 ; $A5 - Cutscene 6 text: line 4
$00:8578 7C C6 0C .dw $C67C .db :$DATA_0CC67C ; $A8 - Cutscene 6 text: line 3
$00:857B 47 C6 0C .dw $C647 .db :$DATA_0CC647 ; $AB - Cutscene 6 text: line 2
$00:857E 12 C6 0C .dw $C612 .db :$DATA_0CC612 ; $AE - Cutscene 6 text: line 1
$00:8581 2D C9 0C .dw $C92D .db :$DATA_0CC92D ; $B1 - Cutscene 7 text: line 8
$00:8584 F8 C8 0C .dw $C8F8 .db :$DATA_0CC8F8 ; $B4 - Cutscene 7 text: line 7
$00:8587 C3 C8 0C .dw $C8C3 .db :$DATA_0CC8C3 ; $B7 - Cutscene 7 text: line 6
$00:858A 8E C8 0C .dw $C88E .db :$DATA_0CC88E ; $BA - Cutscene 7 text: line 5
$00:858D 59 C8 0C .dw $C859 .db :$DATA_0CC859 ; $BD - Cutscene 7 text: line 4
$00:8590 24 C8 0C .dw $C824 .db :$DATA_0CC824 ; $C0 - Cutscene 7 text: line 3
$00:8593 EF C7 0C .dw $C7EF .db :$DATA_0CC7EF ; $C3 - Cutscene 7 text: line 2
$00:8596 BA C7 0C .dw $C7BA .db :$DATA_0CC7BA ; $C6 - Cutscene 7 text: line 1
$00:8599 56 BA 0C .dw $BA56 .db :$DATA_0CBA56 ; $C9 - Cutscene border, cave ground
$00:859C B9 BB 0C .dw $BBB9 .db :$DATA_0CBBB9 ; $CC - (purpose unknown)
$00:859F BF B9 0C .dw $B9BF .db :$DATA_0CB9BF ; $CF - (purpose unknown)
$00:85A2 80 93 0C .dw $9380 .db :$DATA_0C9380 ; $D2 - (purpose unknown)
$00:85A5 36 B6 0C .dw $B636 .db :$DATA_0CB636 ; $D5 - Ending: THE END
$00:85A8 00 F3 0D .dw $F300 .db :$DATA_0DF300 ; $D8 - Ending: Enemies: Lakitu
$00:85AB 2D F4 0D .dw $F42D .db :$DATA_0DF42D ; $DB - Ending: Enemies: Hammer Bro.
$00:85AE 72 F5 0D .dw $F572 .db :$DATA_0DF572 ; $DE - Ending: Enemies: Pokey
$00:85B1 6B F6 0D .dw $F66B .db :$DATA_0DF66B ; $E1 - Ending: Enemies: Rex
$00:85B4 42 F7 0D .dw $F742 .db :$DATA_0DF742 ; $E4 - Ending: Enemies: Dino-Rhino
$00:85B7 37 F8 0D .dw $F837 .db :$DATA_0DF837 ; $E7 - Ending: Enemies: Blargg
$00:85BA FA F8 0D .dw $F8FA .db :$DATA_0DF8FA ; $EA - Ending: Enemies: Urchin
$00:85BD CD F9 0D .dw $F9CD .db :$DATA_0DF9CD ; $ED - Ending: Enemies: Boo
$00:85C0 98 FA 0D .dw $FA98 .db :$DATA_0DFA98 ; $F0 - Ending: Enemies: Dry Bones
$00:85C3 73 FB 0D .dw $FB73 .db :$DATA_0DFB73 ; $F3 - Ending: Enemies: Grinder
$00:85C6 58 FC 0D .dw $FC58 .db :$DATA_0DFC58 ; $F6 - Ending: Enemies: Reznor
$00:85C9 D5 FC 0D .dw $FCD5 .db :$DATA_0DFCD5 ; $F9 - Ending: Enemies: Mechakoopa
$00:85CC 5C FD 0D .dw $FD5C .db :$DATA_0DFD5C ; $FC - Ending: Enemies: Bowser
$00:85CF 02 BD 0C .dw $BD02 .db :$DATA_0CBD02 ; $FF - (purpose unknown)
;;; $85D2: Upload stripe image to VRAM (LoadScrnImage) ;;;
;; Loads the 24-bit pointer for image [$12] from ImagePointers into [$00] and uploads it with $871E.
;; Runs every NMI.
;; If [$12] = 0 (the RAM buffer at $7F:837D) the buffer is emptied afterwards: write index $7F:837B = 0, first
;; byte = $FF.
;; [$12] is cleared so that an image is only loaded once.
;; Image record format (parsed by $871E): VRAM address high, low, then a word (bit 7 = vertical
;; increment, bit 6 = RLE, low
;; 14 bits = byte count - 1), then the data. A record whose first byte has bit 7 set ends the image.
;; $0085FA (separate routine, called at the start of most game modes): turns off NMI/IRQ/HDMA and the screen
;; (TurnOffIO), fills the
;; BG3 tilemap (VRAM $5000-$5FFF) with tile $FC / attributes $38, hides all sprites via $7F8000 and DMAs OAM.
;; Called by:
;; $00:823D: NMI handler: sound, PPU mirrors, DMA (NMIStart)
;; $00:82EE: NMI tail: scroll, IRQ setup, Mode 7 path (NMINotSpecialLv)
;; $00:84CB: Pack OAM size bits into high table
;; $00:949D: Cutscene, ending and game mode code (castle scenes, credits, game over) (CutsceneCastlePal)
;; $00:94BC: Cutscene, ending and game mode code (castle scenes, credits, game over) (CutsceneCastlePal)
;; $00:94C3: Cutscene, ending and game mode code (castle scenes, credits, game over) (CutsceneCastlePal)
;; $00:9618: Cutscene, ending and game mode code (castle scenes, credits, game over) (CutsceneCastlePal)
;; $00:967C: Cutscene, ending and game mode code (castle scenes, credits, game over) (CutsceneCastlePal)
;; $00:9A10: Boss room tile animation and Mode 7 setup
;; $00:9A9B: Detect connected controllers into [$0DA0] (SetUp0DA0GM4)
;; $00:A157: Game mode 0C: load overworld (LoadMapGameMode)
;; $00:A15E: Game mode 0C: load overworld (LoadMapGameMode)
;; ... and 1 more
$00:85D2 A4 12 LDY $12 ; Y = [$12]: byte offset into ImagePointers (image number * 3)
$00:85D4 B9 D0 84 LDA.W ImagePointers,Y ; \
$00:85D7 85 00 STA $00 ; / [$00] = pointer low byte
$00:85D9 B9 D1 84 LDA.W ImagePointers+1,Y ; \
$00:85DC 85 01 STA $01 ; / [$01] = pointer high byte
$00:85DE B9 D2 84 LDA.W ImagePointers+2,Y ; \
$00:85E1 85 02 STA $02 ; / [$02] = pointer bank
$00:85E3 20 1E 87 JSR.W $871E ; Upload the stripe image to VRAM ($871E)
$00:85E6 A5 12 LDA $12 ; \
$00:85E8 D0 0D BNE $85F7 ; / [$12] != 0: not the RAM buffer, go to $0085F7
$00:85EA 8F 7B 83 7F STA.L $7F837B ; RAM buffer write index low ($7F:837B) = 0
$00:85EE 8F 7C 83 7F STA.L $7F837C ; RAM buffer write index high ($7F:837C) = 0
$00:85F2 3A DEC A ; A = $FF: end-of-image marker
$00:85F3 8F 7D 83 7F STA.L $7F837D ; First byte of the RAM buffer = $FF (buffer empty)
$00:85F7 64 12 STZ $12 ; [$12] = 0: do not reload the same image next frame
$00:85F9 60 RTS ; Return
$00:85FA 20 7D 93 JSR.W TurnOffIO ; Turn off NMI/IRQ, HDMA and the screen (TurnOffIO)
$00:85FD A9 FC LDA.B #$FC ; \
$00:85FF 85 00 STA $00 ; / [$00] = $FC: tile number used as the fill byte
$00:8601 9C 15 21 STZ.W $2115 ; VMAIN = 0: VRAM address increments after low-byte writes
$00:8604 9C 16 21 STZ.W $2116 ; \
$00:8607 A9 50 LDA.B #$50 ; } VRAM address = $5000 (BG3 tilemap)
$00:8609 8D 17 21 STA.W $2117 ; /
$00:860C A2 06 LDX.B #$06 ; \
$00:860E BD 49 86 LDA.W $8649,X ; |
$00:8611 9D 10 43 STA.W $4310,X ; } Copy 7 bytes of DMA setup from $8649 to $4310-$4316
$00:8614 CA DEX ; |
$00:8615 10 F7 BPL $860E ; /
$00:8617 A0 02 LDY.B #$02 ; \
$00:8619 8C 0B 42 STY.W $420B ; / Start DMA channel 1: fill VRAM low bytes with [$00] ($1000 bytes)
$00:861C A9 38 LDA.B #$38 ; \
$00:861E 85 00 STA $00 ; / [$00] = $38: fill byte for the high bytes (palette 6, priority)
$00:8620 A9 80 LDA.B #$80 ; \
$00:8622 8D 15 21 STA.W $2115 ; / VMAIN = $80: VRAM address increments after high-byte writes
$00:8625 9C 16 21 STZ.W $2116 ; \
$00:8628 A9 50 LDA.B #$50 ; } VRAM address = $5000 (BG3 tilemap)
$00:862A 8D 17 21 STA.W $2117 ; /
$00:862D A2 06 LDX.B #$06 ; \
$00:862F BD 49 86 LDA.W $8649,X ; |
$00:8632 9D 10 43 STA.W $4310,X ; } Copy 7 bytes of DMA setup from $8649 to $4310-$4316
$00:8635 CA DEX ; |
$00:8636 10 F7 BPL $862F ; /
$00:8638 A9 19 LDA.B #$19 ; \
$00:863A 8D 11 43 STA.W $4311 ; / DMA destination = $2119 (VRAM high bytes)
$00:863D 8C 0B 42 STY.W $420B ; Start DMA channel 1: fill VRAM high bytes with [$00]
$00:8640 64 3F STZ $3F ; [$3F] = 0 (OAM priority index)
$00:8642 22 00 80 7F JSL.L RAM_7F8000 ; Move all sprites off-screen (RAM routine at $7F8000)
$00:8646 4C 49 84 JMP.W DoSomeSpriteDMA ; Upload OAM and return (DoSomeSpriteDMA)
;;; $8649..8649: Table: DMA setup for BG3 clear ;;;
;; 7 bytes copied to $4310-$4316: DMAP $08 (fixed source, 1 register), B-bus $18, source $00:0000, size $1000.
$00:8649 .db $08,$18,$00,$00,$00,$00,$10 ; DMAP $08 (fixed source), B-bus $18, source $00:0000, size $1000
;;; $8650: Read joypads, update input bytes (ControllerUpdate) ;;;
;; Reads both joypads from the auto-read registers $4218-$421B and keeps held and newly pressed bits for each
;; in $0DA2-$0DAD.
;; Then copies one pad's bits to the input bytes: [$15] held byetUDLR, [$16] pressed byetUDLR, [$17] held
;; AXLR, [$18] pressed AXLR.
;; A and B (and X and Y) are merged into bits 7 and 6 of [$15] and [$16]. The pad is [$0DA0] if non-negative,
;; else the current player [$0DB3].
;; $0086C7 (separate routine, called at $009A67): sets the size bytes of sprites 0-99 ($0420-$0483) to $02 and
;; hides sprites 100-127.
;; Called by:
;; $00:8243: NMI handler: sound, PPU mirrors, DMA (NMIStart)
;; $00:82F4: NMI tail: scroll, IRQ setup, Mode 7 path (NMINotSpecialLv)
$00:8650 AD 18 42 LDA.W $4218 ; Joypad 1 auto-read low byte: A, X, L, R in bits 7-4
$00:8653 29 F0 AND.B #$F0 ; Keep only the four button bits
$00:8655 8D A4 0D STA.W $0DA4 ; [$0DA4] = joypad 1 A/X/L/R held
$00:8658 A8 TAY ; Y = held bits
$00:8659 4D AC 0D EOR.W $0DAC ; \
$00:865C 2D A4 0D AND.W $0DA4 ; |
$00:865F 8D A8 0D STA.W $0DA8 ; / [$0DA8] = joypad 1 A/X/L/R newly pressed this frame ((old EOR new) AND new)
$00:8662 8C AC 0D STY.W $0DAC ; [$0DAC] = held bits, remembered for next frame
$00:8665 AD 19 42 LDA.W $4219 ; Joypad 1 auto-read high byte: B, Y, Select, Start, Up, Down, Left, Right
$00:8668 8D A2 0D STA.W $0DA2 ; [$0DA2] = joypad 1 B/Y/Sel/Start/D-pad held
$00:866B A8 TAY ; Y = held bits
$00:866C 4D AA 0D EOR.W $0DAA ; \
$00:866F 2D A2 0D AND.W $0DA2 ; |
$00:8672 8D A6 0D STA.W RAM_OWControllerA ; / [$0DA6] (RAM_OWControllerA) = joypad 1 byte 1 newly pressed
$00:8675 8C AA 0D STY.W $0DAA ; [$0DAA] = held bits, remembered for next frame
$00:8678 AD 1A 42 LDA.W $421A ; Joypad 2 auto-read low byte: A, X, L, R
$00:867B 29 F0 AND.B #$F0 ; Keep only the four button bits
$00:867D 8D A5 0D STA.W $0DA5 ; [$0DA5] = joypad 2 A/X/L/R held
$00:8680 A8 TAY ; Y = held bits
$00:8681 4D AD 0D EOR.W $0DAD ; \
$00:8684 2D A5 0D AND.W $0DA5 ; |
$00:8687 8D A9 0D STA.W $0DA9 ; / [$0DA9] = joypad 2 A/X/L/R newly pressed
$00:868A 8C AD 0D STY.W $0DAD ; [$0DAD] = held bits, remembered for next frame
$00:868D AD 1B 42 LDA.W $421B ; Joypad 2 auto-read high byte
$00:8690 8D A3 0D STA.W $0DA3 ; [$0DA3] = joypad 2 byte 1 held
$00:8693 A8 TAY ; Y = held bits
$00:8694 4D AB 0D EOR.W $0DAB ; \
$00:8697 2D A3 0D AND.W $0DA3 ; |
$00:869A 8D A7 0D STA.W $0DA7 ; / [$0DA7] = joypad 2 byte 1 newly pressed
$00:869D 8C AB 0D STY.W $0DAB ; [$0DAB] = held bits, remembered for next frame
$00:86A0 AE A0 0D LDX.W $0DA0 ; X = [$0DA0]: controller to use (0 = joypad 1, 1 = joypad 2)
$00:86A3 10 03 BPL $86A8 ; Non-negative: use it
$00:86A5 AE B3 0D LDX.W $0DB3 ; Negative: use the current player [$0DB3] (0 Mario, 1 Luigi)
$00:86A8 BD A4 0D LDA.W $0DA4,X ; \
$00:86AB 29 C0 AND.B #$C0 ; |
$00:86AD 1D A2 0D ORA.W $0DA2,X ; |
$00:86B0 85 15 STA RAM_ControllerA ; / [$15] = byte 1 held (B/Y/Sel/Start/D-pad) with A merged into bit 7 and X into bit 6
$00:86B2 BD A4 0D LDA.W $0DA4,X ; A = AXLR held
$00:86B5 85 17 STA RAM_ControllerB ; [$17] = A/X/L/R held
$00:86B7 BD A8 0D LDA.W $0DA8,X ; \
$00:86BA 29 40 AND.B #$40 ; |
$00:86BC 1D A6 0D ORA.W RAM_OWControllerA,X ; |
$00:86BF 85 16 STA $16 ; / [$16] = byte 1 newly pressed, with X press merged into bit 6
$00:86C1 BD A8 0D LDA.W $0DA8,X ; \
$00:86C4 85 18 STA $18 ; / [$18] = A/X/L/R newly pressed
$00:86C6 60 RTS ; Return
$00:86C7 C2 30 REP #$30 ; A, X and Y 16-bit
$00:86C9 A2 62 00 LDX.W #$0062 ; X = $0062: last word offset of the sprite size table fill
$00:86CC A9 02 02 LDA.W #$0202 ; A = $0202: size bit set (large) and X bit 8 clear for two sprites
$00:86CF 9D 20 04 STA.W $0420,X ; Size/X-high bytes of two sprites at $0420+X
$00:86D2 CA DEX ; \
$00:86D3 CA DEX ; / X -= 2
$00:86D4 10 F9 BPL $86CF ; Loop for $0420-$0483 (sprites 0-99)
$00:86D6 E2 30 SEP #$30 ; A, X and Y 8-bit
$00:86D8 A9 F0 LDA.B #$F0 ; A = $F0: off-screen Y position
$00:86DA 22 2E 81 7F JSL.L RAM_7F812E ; Run the tail of the generated routine at $7F8000: sprites 100-127 get Y = $F0
$00:86DE 60 RTS ; Return
;;; JSL trampoline
;;; precondition that A, X, Y are 8-bit registers
;;; takes A = index/2 to table
;;; destroys RAM $00..$03
;;; preserves X, Y, RAM $04..$0f
;;;
;;; [Usage]
;;; JSL ExecutePtr
;;; .db $nn, $mm ; jump $mmnn if A == 0
;;; .db $nn, $mm ; jump $mmnn if A == 1
;;; .db $nn, $mm ; jump $mmnn if A == 2
;;; ...
;;; [Alternative]
;;; JMP (MyTable,X)
;;; MyTable:
;;; .db $nn, $mm ; jump $mmnn if X == 0
;;; .db $nn, $mm ; jump $mmnn if X == 2
;;; .db $nn, $mm ; jump $mmnn if X == 4
;;; ...
;;;
;;; Jumps to an address in a table. The accumulator A selects the address.
;;;
;;; ExecutePtr is a trampoline, not a subroutine. This trampoline never returns. The JSL pushes the
;;; long address of the table minus 1; this trampoline pulls it to find the table.
;;;
;;; JMP (MyTable,X) is better than JSL ExecutePtr in new code. The trampoline might be a port from
;;; the 6502 (the processor in the NES). The only JMP instructions of the 6502 were JMP $mmnn and
;;; JMP ($mmnn); there was no JMP ($mmnn,X). The base hack of SMW was Super Mario Bros. 3 (NES); I
;;; wonder if a search for "7a 84 00 0a a8" would find the trampoline in SMB3. When the hackers at
;;; Nintendo ported code from SMB3 to the 65816, a port of the trampoline would have been easier
;;; than a replacement of the trampoline with JMP (MyTable,X).
;;;
;;; $86DF: JSL trampoline: 16-bit pointer table (ExecutePtr) ;;;
;; Jumps to the A-th 16-bit pointer of the table that follows the JSL. Never returns to the caller; the target
;; returns instead.
;; Parameters: A: table index. 8-bit A, X, Y. Destroys [$00]-[$03]; Y is preserved.
;; Called by:
;; $00:9325: Run current game mode (GetGameMode)
;; $00:9B89: Game mode 09: erase file menu
;; $00:BFC5: Generate Map16 tile at block position (GenerateTile)
;; $00:C595: Per-frame Mario state: keyhole, timers, animation
;; $01:8133: Run sprite by status (HandleSprite)
;; $01:8179: Initialize sprite (CallSpriteInit)
;; $01:85C8: Dispatch sprite main routine (CallSpriteMain)
;; $01:AEB9: Thwomp main (Thwomp)
;; $01:BDE6: Magikoopa main (Magikoopa)
;; $01:C550: Run power-up action (NoItem)
;; $01:CE0E: Morton, Roy and Ludwig main routine (WallKoopaKids)
;; $01:CE61: Pointer table: wall Koopa Kid main states (MortonPtrs1)
;; ... and 54 more
$00:86DF 84 03 STY $03 ; Save Y in [$03] (the stack holds the return address)
;;
;; JSL ExecutePtr pushes return address - 1 to the stack. The stack grows down,
;; so we pull the low byte, then the high byte, then the bank byte.
;;
$00:86E1 7A PLY ; \
$00:86E2 84 00 STY $00 ; / [$00] = low byte of the pushed return address (table address - 1)
$00:86E4 C2 30 REP #$30 ; A, X and Y 16-bit
$00:86E6 29 FF 00 AND.W #$00FF ; Clear the high byte of the index
$00:86E9 0A ASL ; \
$00:86EA A8 TAY ; / Y = index * 2 (2-byte table entries)
$00:86EB 68 PLA ; \
$00:86EC 85 01 STA $01 ; / [$01]-[$02] = high and bank bytes of the table address - 1
$00:86EE C8 INY ; Y += 1: the pushed address points one byte before the table
$00:86EF B7 00 LDA [$00],Y ; \
$00:86F1 85 00 STA $00 ; / [$00]-[$01] = table entry (16-bit target address)
$00:86F3 E2 30 SEP #$30 ; A, X and Y 8-bit
$00:86F5 A4 03 LDY $03 ; Restore Y
$00:86F7 DC 00 00 JMP [$0000] ; Jump to the target (same bank as the table)
;;; JSL trampoline
;;; precondition that A, X, Y are 8-bit registers
;;; takes A = index/3 to table
;;; destroys RAM $00..$05
;;; preserves X, Y, RAM $06..$0f
;;;
;;; [Usage]
;;; JSL ExecutePtrLong
;;; .db $nn, $mm, $kk ; jump $kkmmnn if A == 0
;;; .db $nn, $mm, $kk ; jump $kkmmnn if A == 1
;;; .db $nn, $mm, $kk ; jump $kkmmnn if A == 2
;;; ...
;;;
;;; Jumps to a long address in a table. This variant of ExecutePtr uses 24-bit addresses instead of
;;; of 16-bit addresses. See above comments for ExecutePtr. This trampoline has no equivalent JMP
;;; instruction, so you might use JSL ExecutePtrLong in new code.
;;;
;;; $86FA: Long pointer trampoline and VRAM uploaders (ExecutePtrLong) ;;;
;; $0086FA: ExecutePtrLong, like ExecutePtr but with 24-bit table entries (A * 3). Destroys [$00]-[$05].
;; $00871E (JSR): uploads a stripe image to VRAM with DMA channel 1. Parameters: [$00]-[$01] address and A =
;; bank of the image.
;; Records: VRAM address high, low, then a word (bit 7 vertical, bit 6 RLE, low 14 bits = byte count - 1),
;; then the data; ends at a first byte with bit 7 set.
;; RLE records repeat 2 bytes (tile, properties) in two DMA passes. Quirk: pass 2 uses a 2-register DMA mode
;; from $2119, so it probably also writes $211A.
;; $0087AD (JSL): uploads the layer 1 buffer ([$1BE4]/[$1BE5] = VRAM address, data at $1BE6-$1CE5) and layer 2
;; buffer ([$1CE6]/[$1CE7], $1CE8-$1DE7).
;; Horizontal layers get 2 tile columns (each in 2 DMAs across the two vertical screens), vertical layers 2
;; tile rows. Clears the flags [$1BE4], [$1CE6].
;; Called by:
;; $04:8579: Find warp and run overworld process
;; $05:881F: Map16 pointer bases and tile range setup (MAP16AppTable)
;; $05:8888: Pointer table: layer 1 loader by level mode (PtrsLong058823)
;; $05:88F1: Pointer table: layer 2 loader by level mode (PtrsLong05888C)
;; $05:895A: Pointer table: layer 1 loader for initial load (PtrsLong0588F5)
;; $05:DAFB: Load level: pointers, start position, layout (PtrsLong05D778)
;; $0C:A1DA: Draw banner; dispatch scene substate
;; $0D:A10B: Load extended object
;; $0D:A41A: Load standard object by tileset (PtrsLong0DA40C)
;; $0D:A451: Normal tileset: dispatch standard object (PtrsLong0DA448)
;; $0D:AB4C: Objects: horizontal pipe, bullet shooter, slope dispatch
;; $0D:C196: Castle tileset object dispatch
;; ... and 8 more
$00:86FA 84 05 STY $05 ; Save Y in [$05]
$00:86FC 7A PLY ; \
$00:86FD 84 02 STY $02 ; / [$02] = low byte of the pushed return address (table address - 1)
$00:86FF C2 30 REP #$30 ; A, X and Y 16-bit
$00:8701 29 FF 00 AND.W #$00FF ; Clear the high byte of the index
$00:8704 85 03 STA $03 ; [$03] = index
$00:8706 0A ASL ; \
;; carry flag is clear ; | 3-byte addresses}
$00:8707 65 03 ADC $03 ; |
$00:8709 A8 TAY ; / Y = index * 3 (3-byte table entries; ASL leaves carry clear)
$00:870A 68 PLA ; \
$00:870B 85 03 STA $03 ; / [$03]-[$04] = high and bank bytes of the table address - 1
$00:870D C8 INY ; Y += 1: the pushed address points one byte before the table
$00:870E B7 02 LDA [$02],Y ; \
$00:8710 85 00 STA $00 ; / [$00] = low byte of the target
$00:8712 C8 INY ; \
$00:8713 B7 02 LDA [$02],Y ; |
$00:8715 85 01 STA $01 ; / [$01]-[$02] = high and bank bytes of the target
$00:8717 E2 30 SEP #$30 ; A, X and Y 8-bit
$00:8719 A4 05 LDY $05 ; Restore Y
$00:871B DC 00 00 JMP [$0000] ; Jump to the 24-bit target
$00:871E C2 10 REP #$10 ; X and Y 16-bit (A stays 8-bit)
$00:8720 8D 14 43 STA.W $4314 ; DMA channel 1 source bank = A (bank of the image)
$00:8723 A0 00 00 LDY.W #$0000 ; Y = 0: offset into the image
$00:8726 B7 00 LDA [$00],Y ; Next record: first byte = VRAM address high
$00:8728 10 03 BPL $872D ; Bit 7 clear: parse the record
$00:872A E2 30 SEP #$30 ; End marker: A, X and Y 8-bit
$00:872C 60 RTS ; Return
$00:872D 85 04 STA $04 ; [$04] = VRAM address high
$00:872F C8 INY ; Next byte
$00:8730 B7 00 LDA [$00],Y ; Second byte = VRAM address low
$00:8732 85 03 STA $03 ; [$03] = VRAM address low
$00:8734 C8 INY ; Next byte
$00:8735 B7 00 LDA [$00],Y ; Third byte: bit 7 = vertical, bit 6 = RLE, low 6 bits = count high
$00:8737 64 07 STZ $07 ; \
$00:8739 0A ASL ; |
$00:873A 26 07 ROL $07 ; / [$07] = bit 7 of the third byte (1 = step down a column)
$00:873C A9 18 LDA.B #$18 ; \
$00:873E 8D 11 43 STA.W $4311 ; / DMA B-bus register = $2118 (VRAM data low)
$00:8741 B7 00 LDA [$00],Y ; Re-read the third byte
$00:8743 29 40 AND.B #$40 ; \
$00:8745 4A LSR ; |
$00:8746 4A LSR ; |
$00:8747 4A LSR ; |
$00:8748 85 05 STA $05 ; / [$05] = $08 if RLE (bit 6) else 0: DMA 'fixed source' flag
$00:874A 64 06 STZ $06 ; [$06] = 0 (so [$05] is a clean 16-bit flag)
$00:874C 09 01 ORA.B #$01 ; \
$00:874E 8D 10 43 STA.W $4310 ; / DMAP = 1 (two registers), or 9 (fixed source) for RLE
$00:8751 C2 20 REP #$20 ; A 16-bit
$00:8753 A5 03 LDA $03 ; \
$00:8755 8D 16 21 STA.W $2116 ; / VRAM address = [$03]-[$04]
$00:8758 B7 00 LDA [$00],Y ; \
$00:875A EB XBA ; |
$00:875B 29 FF 3F AND.W #$3FFF ; |
$00:875E AA TAX ; |
$00:875F E8 INX ; / X = (((third byte & $3F) << 8) | fourth byte) + 1 = byte count
$00:8760 C8 INY ; \
$00:8761 C8 INY ; / Y += 2: skip to the data
$00:8762 98 TYA ; \
$00:8763 18 CLC ; |
$00:8764 65 00 ADC $00 ; |
$00:8766 8D 12 43 STA.W $4312 ; / DMA source address = [$00] + Y (start of the data)
$00:8769 8E 15 43 STX.W $4315 ; DMA byte count = X
$00:876C A5 05 LDA $05 ; A = RLE flag
$00:876E F0 25 BEQ $8795 ; Not RLE: go to the upload at $008795
$00:8770 E2 20 SEP #$20 ; RLE: A 8-bit
$00:8772 A5 07 LDA $07 ; \
$00:8774 8D 15 21 STA.W $2115 ; / VMAIN = direction bit only: step after low byte writes (RLE pass 1)
$00:8777 A9 02 LDA.B #$02 ; \
$00:8779 8D 0B 42 STA.W $420B ; / RLE pass 1: repeat the first data byte into the low bytes
$00:877C A9 19 LDA.B #$19 ; \
$00:877E 8D 11 43 STA.W $4311 ; / DMA B-bus register = $2119 (VRAM data high) for pass 2
$00:8781 C2 21 REP #$21 ; A 16-bit, carry clear
$00:8783 A5 03 LDA $03 ; \
$00:8785 8D 16 21 STA.W $2116 ; / Restart at the same VRAM address
$00:8788 98 TYA ; \
$00:8789 65 00 ADC $00 ; |
$00:878B 1A INC A ; |
$00:878C 8D 12 43 STA.W $4312 ; / DMA source = [$00] + Y + 1 (the second data byte)
$00:878F 8E 15 43 STX.W $4315 ; Same byte count
$00:8792 A2 02 00 LDX.W #$0002 ; X = 2: an RLE record has 2 data bytes
$00:8795 86 03 STX $03 ; \
$00:8797 98 TYA ; |
$00:8798 18 CLC ; |
$00:8799 65 03 ADC $03 ; |
$00:879B A8 TAY ; / Y += X: step past the data (byte count, or 2 for RLE)
$00:879C E2 20 SEP #$20 ; A 8-bit
$00:879E A5 07 LDA $07 ; \
$00:87A0 09 80 ORA.B #$80 ; |
$00:87A2 8D 15 21 STA.W $2115 ; / VMAIN = $80 | direction: step after high byte writes
$00:87A5 A9 02 LDA.B #$02 ; \
$00:87A7 8D 0B 42 STA.W $420B ; / Run DMA channel 1: copy the data, or RLE pass 2 (high bytes)
$00:87AA 4C 26 87 JMP.W $8726 ; Next record
$00:87AD E2 30 SEP #$30 ; A, X and Y 8-bit
$00:87AF AD E4 1B LDA.W $1BE4 ; [$1BE4] = VRAM address high of the pending layer 1 update (0 = none)
$00:87B2 D0 03 BNE $87B7 ; Pending: continue
$00:87B4 4C DD 88 JMP.W $88DD ; None: skip to layer 2 ($0088DD)
$00:87B7 A5 5B LDA RAM_IsVerticalLvl ; A = [$5B] level orientation flags
$00:87B9 29 01 AND.B #$01 ; Bit 0: layer 1 is vertical
$00:87BB F0 03 BEQ $87C0 ; Horizontal: go to $0087C0
$00:87BD 4C 49 88 JMP.W $8849 ; Vertical: go to $008849
$00:87C0 A0 81 LDY.B #$81 ; \
$00:87C2 8C 15 21 STY.W $2115 ; / VMAIN = $81: step 32 words after each high byte (write down a column)
$00:87C5 AD E5 1B LDA.W $1BE5 ; \
$00:87C8 8D 16 21 STA.W $2116 ; |
$00:87CB AD E4 1B LDA.W $1BE4 ; |
$00:87CE 8D 17 21 STA.W $2117 ; / VRAM address = [$1BE4] (high) : [$1BE5] (low)
$00:87D1 A2 06 LDX.B #$06 ; \
$00:87D3 BD 16 8A LDA.W $8A16,X ; |
$00:87D6 9D 10 43 STA.W $4310,X ; |
$00:87D9 CA DEX ; |
$00:87DA 10 F7 BPL $87D3 ; / Copy 7 DMA setup bytes to $4310-$4316: $8A16 (source $1BE6, $40 bytes)
$00:87DC A9 02 LDA.B #$02 ; \
$00:87DE 8D 0B 42 STA.W $420B ; / Run DMA channel 1: left tile column, upper screen (32 words)
$00:87E1 8C 15 21 STY.W $2115 ; VMAIN = $81 again (Y)
$00:87E4 AD E5 1B LDA.W $1BE5 ; \
$00:87E7 8D 16 21 STA.W $2116 ; / VRAM address low = [$1BE5]
$00:87EA AD E4 1B LDA.W $1BE4 ; \
$00:87ED 18 CLC ; |
$00:87EE 69 08 ADC.B #$08 ; |
$00:87F0 8D 17 21 STA.W $2117 ; / VRAM address high = [$1BE4] + 8 (screen below, +$0800 words)
$00:87F3 A2 06 LDX.B #$06 ; \
$00:87F5 BD 1D 8A LDA.W $8A1D,X ; |
$00:87F8 9D 10 43 STA.W $4310,X ; |
$00:87FB CA DEX ; |
$00:87FC 10 F7 BPL $87F5 ; / Copy 7 DMA setup bytes to $4310-$4316: $8A1D (source $1C26, $2C bytes)
$00:87FE A9 02 LDA.B #$02 ; \
$00:8800 8D 0B 42 STA.W $420B ; / Run DMA channel 1: left tile column, lower screen (22 words)
$00:8803 8C 15 21 STY.W $2115 ; VMAIN = $81 again (Y)
$00:8806 AD E5 1B LDA.W $1BE5 ; \
$00:8809 1A INC A ; |
$00:880A 8D 16 21 STA.W $2116 ; / VRAM address low = [$1BE5] + 1 (right tile column)
$00:880D AD E4 1B LDA.W $1BE4 ; \
$00:8810 8D 17 21 STA.W $2117 ; / VRAM address high = [$1BE4]
$00:8813 A2 06 LDX.B #$06 ; \
$00:8815 BD 24 8A LDA.W $8A24,X ; |
$00:8818 9D 10 43 STA.W $4310,X ; |
$00:881B CA DEX ; |
$00:881C 10 F7 BPL $8815 ; / Copy 7 DMA setup bytes to $4310-$4316: $8A24 (source $1C66, $40 bytes)
$00:881E A9 02 LDA.B #$02 ; \
$00:8820 8D 0B 42 STA.W $420B ; / Run DMA channel 1: right tile column, upper screen
$00:8823 8C 15 21 STY.W $2115 ; VMAIN = $81 again (Y)
$00:8826 AD E5 1B LDA.W $1BE5 ; \
$00:8829 1A INC A ; |
$00:882A 8D 16 21 STA.W $2116 ; / VRAM address low = [$1BE5] + 1
$00:882D AD E4 1B LDA.W $1BE4 ; \
$00:8830 18 CLC ; |
$00:8831 69 08 ADC.B #$08 ; |
$00:8833 8D 17 21 STA.W $2117 ; / VRAM address high = [$1BE4] + 8
$00:8836 A2 06 LDX.B #$06 ; \
$00:8838 BD 2B 8A LDA.W $8A2B,X ; |
$00:883B 9D 10 43 STA.W $4310,X ; |
$00:883E CA DEX ; |
$00:883F 10 F7 BPL $8838 ; / Copy 7 DMA setup bytes to $4310-$4316: $8A2B (source $1CA6, $2C bytes)
$00:8841 A9 02 LDA.B #$02 ; \
$00:8843 8D 0B 42 STA.W $420B ; / Run DMA channel 1: right tile column, lower screen
$00:8846 4C DD 88 JMP.W $88DD ; Go to layer 2 ($0088DD)
$00:8849 A0 80 LDY.B #$80 ; \
$00:884B 8C 15 21 STY.W $2115 ; / VMAIN = $80: step 1 word after each high byte (write along a row)
$00:884E AD E5 1B LDA.W $1BE5 ; \
$00:8851 8D 16 21 STA.W $2116 ; / VRAM address low = [$1BE5]
$00:8854 AD E4 1B LDA.W $1BE4 ; \
$00:8857 8D 17 21 STA.W $2117 ; / VRAM address high = [$1BE4]
$00:885A A2 06 LDX.B #$06 ; \
$00:885C BD 16 8A LDA.W $8A16,X ; |
$00:885F 9D 10 43 STA.W $4310,X ; |
$00:8862 CA DEX ; |
$00:8863 10 F7 BPL $885C ; / Copy 7 DMA setup bytes to $4310-$4316: $8A16 (source $1BE6, $40 bytes)
$00:8865 A9 02 LDA.B #$02 ; \
$00:8867 8D 0B 42 STA.W $420B ; / Run DMA channel 1: first tile row, left screen (32 words)
$00:886A 8C 15 21 STY.W $2115 ; VMAIN = $80 again (Y)
$00:886D AD E5 1B LDA.W $1BE5 ; \
$00:8870 8D 16 21 STA.W $2116 ; / VRAM address low = [$1BE5]
$00:8873 AD E4 1B LDA.W $1BE4 ; \
$00:8876 18 CLC ; |
$00:8877 69 04 ADC.B #$04 ; |
$00:8879 8D 17 21 STA.W $2117 ; / VRAM address high = [$1BE4] + 4 (screen to the right, +$0400 words)
$00:887C A2 06 LDX.B #$06 ; \
$00:887E BD 1D 8A LDA.W $8A1D,X ; |
$00:8881 9D 10 43 STA.W $4310,X ; |
$00:8884 CA DEX ; |
$00:8885 10 F7 BPL $887E ; / Copy 7 DMA setup bytes to $4310-$4316: $8A1D (source $1C26)
$00:8887 A9 40 LDA.B #$40 ; \
$00:8889 8D 15 43 STA.W $4315 ; / DMA byte count = $40 (this row half is a full 32 words)
$00:888C A9 02 LDA.B #$02 ; \
$00:888E 8D 0B 42 STA.W $420B ; / Run DMA channel 1: first tile row, right screen
$00:8891 8C 15 21 STY.W $2115 ; VMAIN = $80 again (Y)
$00:8894 AD E5 1B LDA.W $1BE5 ; \
$00:8897 18 CLC ; |
$00:8898 69 20 ADC.B #$20 ; |
$00:889A 8D 16 21 STA.W $2116 ; / VRAM address low = [$1BE5] + $20 (next tile row)
$00:889D AD E4 1B LDA.W $1BE4 ; \
$00:88A0 8D 17 21 STA.W $2117 ; / VRAM address high = [$1BE4]
$00:88A3 A2 06 LDX.B #$06 ; \
$00:88A5 BD 24 8A LDA.W $8A24,X ; |
$00:88A8 9D 10 43 STA.W $4310,X ; |
$00:88AB CA DEX ; |
$00:88AC 10 F7 BPL $88A5 ; / Copy 7 DMA setup bytes to $4310-$4316: $8A24 (source $1C66, $40 bytes)
$00:88AE A9 02 LDA.B #$02 ; \
$00:88B0 8D 0B 42 STA.W $420B ; / Run DMA channel 1: second tile row, left screen
$00:88B3 8C 15 21 STY.W $2115 ; VMAIN = $80 again (Y)
$00:88B6 AD E5 1B LDA.W $1BE5 ; \
$00:88B9 18 CLC ; |
$00:88BA 69 20 ADC.B #$20 ; |
$00:88BC 8D 16 21 STA.W $2116 ; / VRAM address low = [$1BE5] + $20
$00:88BF AD E4 1B LDA.W $1BE4 ; \
$00:88C2 18 CLC ; |
$00:88C3 69 04 ADC.B #$04 ; |
$00:88C5 8D 17 21 STA.W $2117 ; / VRAM address high = [$1BE4] + 4
$00:88C8 A2 06 LDX.B #$06 ; \
$00:88CA BD 2B 8A LDA.W $8A2B,X ; |
$00:88CD 9D 10 43 STA.W $4310,X ; |
$00:88D0 CA DEX ; |
$00:88D1 10 F7 BPL $88CA ; / Copy 7 DMA setup bytes to $4310-$4316: $8A2B (source $1CA6)
$00:88D3 A9 40 LDA.B #$40 ; \
$00:88D5 8D 15 43 STA.W $4315 ; / DMA byte count = $40
$00:88D8 A9 02 LDA.B #$02 ; \
$00:88DA 8D 0B 42 STA.W $420B ; / Run DMA channel 1: second tile row, right screen
$00:88DD A9 00 LDA.B #$00 ; \
$00:88DF 8D E4 1B STA.W $1BE4 ; / [$1BE4] = 0: layer 1 update done
$00:88E2 AD E6 1C LDA.W $1CE6 ; [$1CE6] = VRAM address high of the pending layer 2 update (0 = none)
$00:88E5 D0 03 BNE $88EA ; Pending: continue
$00:88E7 4C 10 8A JMP.W $8A10 ; None: go to the end ($008A10)
$00:88EA A5 5B LDA RAM_IsVerticalLvl ; A = [$5B] level orientation flags
$00:88EC 29 02 AND.B #$02 ; Bit 1: layer 2 is vertical
$00:88EE F0 03 BEQ $88F3 ; Horizontal: go to $0088F3
$00:88F0 4C 7C 89 JMP.W $897C ; Vertical: go to $00897C
$00:88F3 A0 81 LDY.B #$81 ; \
$00:88F5 8C 15 21 STY.W $2115 ; / VMAIN = $81: write down a column
$00:88F8 AD E7 1C LDA.W $1CE7 ; \
$00:88FB 8D 16 21 STA.W $2116 ; |
$00:88FE AD E6 1C LDA.W $1CE6 ; |
$00:8901 8D 17 21 STA.W $2117 ; / VRAM address = [$1CE6] (high) : [$1CE7] (low)
$00:8904 A2 06 LDX.B #$06 ; \
$00:8906 BD 32 8A LDA.W $8A32,X ; |
$00:8909 9D 10 43 STA.W $4310,X ; |
$00:890C CA DEX ; |
$00:890D 10 F7 BPL $8906 ; / Copy 7 DMA setup bytes to $4310-$4316: $8A32 (source $1CE8, $40 bytes)
$00:890F A9 02 LDA.B #$02 ; \
$00:8911 8D 0B 42 STA.W $420B ; / Run DMA channel 1: left tile column, upper screen
$00:8914 8C 15 21 STY.W $2115 ; VMAIN = $81 again (Y)
$00:8917 AD E7 1C LDA.W $1CE7 ; \
$00:891A 8D 16 21 STA.W $2116 ; / VRAM address low = [$1CE7]
$00:891D AD E6 1C LDA.W $1CE6 ; \
$00:8920 18 CLC ; |
$00:8921 69 08 ADC.B #$08 ; |
$00:8923 8D 17 21 STA.W $2117 ; / VRAM address high = [$1CE6] + 8
$00:8926 A2 06 LDX.B #$06 ; \
$00:8928 BD 39 8A LDA.W $8A39,X ; |
$00:892B 9D 10 43 STA.W $4310,X ; |
$00:892E CA DEX ; |
$00:892F 10 F7 BPL $8928 ; / Copy 7 DMA setup bytes to $4310-$4316: $8A39 (source $1D28, $2C bytes)
$00:8931 A9 02 LDA.B #$02 ; \
$00:8933 8D 0B 42 STA.W $420B ; / Run DMA channel 1: left tile column, lower screen
$00:8936 8C 15 21 STY.W $2115 ; VMAIN = $81 again (Y)
$00:8939 AD E7 1C LDA.W $1CE7 ; \
$00:893C 1A INC A ; |
$00:893D 8D 16 21 STA.W $2116 ; / VRAM address low = [$1CE7] + 1 (right tile column)
$00:8940 AD E6 1C LDA.W $1CE6 ; \
$00:8943 8D 17 21 STA.W $2117 ; / VRAM address high = [$1CE6]
$00:8946 A2 06 LDX.B #$06 ; \
$00:8948 BD 40 8A LDA.W $8A40,X ; |
$00:894B 9D 10 43 STA.W $4310,X ; |
$00:894E CA DEX ; |
$00:894F 10 F7 BPL $8948 ; / Copy 7 DMA setup bytes to $4310-$4316: $8A40 (source $1D68, $40 bytes)
$00:8951 A9 02 LDA.B #$02 ; \
$00:8953 8D 0B 42 STA.W $420B ; / Run DMA channel 1: right tile column, upper screen
$00:8956 8C 15 21 STY.W $2115 ; VMAIN = $81 again (Y)
$00:8959 AD E7 1C LDA.W $1CE7 ; \
$00:895C 1A INC A ; |
$00:895D 8D 16 21 STA.W $2116 ; / VRAM address low = [$1CE7] + 1
$00:8960 AD E6 1C LDA.W $1CE6 ; \
$00:8963 18 CLC ; |
$00:8964 69 08 ADC.B #$08 ; |
$00:8966 8D 17 21 STA.W $2117 ; / VRAM address high = [$1CE6] + 8
$00:8969 A2 06 LDX.B #$06 ; \
$00:896B BD 47 8A LDA.W $8A47,X ; |
$00:896E 9D 10 43 STA.W $4310,X ; |
$00:8971 CA DEX ; |
$00:8972 10 F7 BPL $896B ; / Copy 7 DMA setup bytes to $4310-$4316: $8A47 (source $1DA8, $2C bytes)
$00:8974 A9 02 LDA.B #$02 ; \
$00:8976 8D 0B 42 STA.W $420B ; / Run DMA channel 1: right tile column, lower screen
$00:8979 4C 10 8A JMP.W $8A10 ; Go to the end ($008A10)
$00:897C A0 80 LDY.B #$80 ; \
$00:897E 8C 15 21 STY.W $2115 ; / VMAIN = $80: write along a row
$00:8981 AD E7 1C LDA.W $1CE7 ; \
$00:8984 8D 16 21 STA.W $2116 ; / VRAM address low = [$1CE7]
$00:8987 AD E6 1C LDA.W $1CE6 ; \
$00:898A 8D 17 21 STA.W $2117 ; / VRAM address high = [$1CE6]
$00:898D A2 06 LDX.B #$06 ; \
$00:898F BD 32 8A LDA.W $8A32,X ; |
$00:8992 9D 10 43 STA.W $4310,X ; |
$00:8995 CA DEX ; |
$00:8996 10 F7 BPL $898F ; / Copy 7 DMA setup bytes to $4310-$4316: $8A32 (source $1CE8, $40 bytes)
$00:8998 A9 02 LDA.B #$02 ; \
$00:899A 8D 0B 42 STA.W $420B ; / Run DMA channel 1: first tile row, left screen
$00:899D 8C 15 21 STY.W $2115 ; VMAIN = $80 again (Y)
$00:89A0 AD E7 1C LDA.W $1CE7 ; \
$00:89A3 8D 16 21 STA.W $2116 ; / VRAM address low = [$1CE7]
$00:89A6 AD E6 1C LDA.W $1CE6 ; \
$00:89A9 18 CLC ; |
$00:89AA 69 04 ADC.B #$04 ; |
$00:89AC 8D 17 21 STA.W $2117 ; / VRAM address high = [$1CE6] + 4 (screen to the right)
$00:89AF A2 06 LDX.B #$06 ; \
$00:89B1 BD 39 8A LDA.W $8A39,X ; |
$00:89B4 9D 10 43 STA.W $4310,X ; |
$00:89B7 CA DEX ; |
$00:89B8 10 F7 BPL $89B1 ; / Copy 7 DMA setup bytes to $4310-$4316: $8A39 (source $1D28)
$00:89BA A9 40 LDA.B #$40 ; \
$00:89BC 8D 15 43 STA.W $4315 ; / DMA byte count = $40
$00:89BF A9 02 LDA.B #$02 ; \
$00:89C1 8D 0B 42 STA.W $420B ; / Run DMA channel 1: first tile row, right screen
$00:89C4 8C 15 21 STY.W $2115 ; VMAIN = $80 again (Y)
$00:89C7 AD E7 1C LDA.W $1CE7 ; \
$00:89CA 18 CLC ; |
$00:89CB 69 20 ADC.B #$20 ; |
$00:89CD 8D 16 21 STA.W $2116 ; / VRAM address low = [$1CE7] + $20 (next tile row)
$00:89D0 AD E6 1C LDA.W $1CE6 ; \
$00:89D3 8D 17 21 STA.W $2117 ; / VRAM address high = [$1CE6]
$00:89D6 A2 06 LDX.B #$06 ; \
$00:89D8 BD 40 8A LDA.W $8A40,X ; |
$00:89DB 9D 10 43 STA.W $4310,X ; |
$00:89DE CA DEX ; |
$00:89DF 10 F7 BPL $89D8 ; / Copy 7 DMA setup bytes to $4310-$4316: $8A40 (source $1D68, $40 bytes)
$00:89E1 A9 02 LDA.B #$02 ; \
$00:89E3 8D 0B 42 STA.W $420B ; / Run DMA channel 1: second tile row, left screen
$00:89E6 8C 15 21 STY.W $2115 ; VMAIN = $80 again (Y)
$00:89E9 AD E7 1C LDA.W $1CE7 ; \
$00:89EC 18 CLC ; |
$00:89ED 69 20 ADC.B #$20 ; |
$00:89EF 8D 16 21 STA.W $2116 ; / VRAM address low = [$1CE7] + $20
$00:89F2 AD E6 1C LDA.W $1CE6 ; \
$00:89F5 18 CLC ; |
$00:89F6 69 04 ADC.B #$04 ; |
$00:89F8 8D 17 21 STA.W $2117 ; / VRAM address high = [$1CE6] + 4
$00:89FB A2 06 LDX.B #$06 ; \
$00:89FD BD 47 8A LDA.W $8A47,X ; |
$00:8A00 9D 10 43 STA.W $4310,X ; |
$00:8A03 CA DEX ; |
$00:8A04 10 F7 BPL $89FD ; / Copy 7 DMA setup bytes to $4310-$4316: $8A47 (source $1DA8)
$00:8A06 A9 40 LDA.B #$40 ; \
$00:8A08 8D 15 43 STA.W $4315 ; / DMA byte count = $40
$00:8A0B A9 02 LDA.B #$02 ; \
$00:8A0D 8D 0B 42 STA.W $420B ; / Run DMA channel 1: second tile row, right screen
$00:8A10 A9 00 LDA.B #$00 ; \
$00:8A12 8D E6 1C STA.W $1CE6 ; / [$1CE6] = 0: layer 2 update done
$00:8A15 6B RTL ; Return long
;;; $8A16..8A47: Table: DMA setups for tilemap updates ;;;
;; Eight 7-byte DMA channel 1 setups (DMAP 1, B-bus $18, source $00:xxxx, size) copied by the routine at
;; $0087AD.
$00:8A16 .db $01,$18,$E6,$1B,$00,$40,$00 ; Layer 1 part 1: DMAP 1, B-bus $18, source $00:1BE6, $0040 bytes
$00:8A1D .db $01,$18,$26,$1C,$00,$2C,$00 ; Layer 1 part 2: source $00:1C26, $002C bytes
$00:8A24 .db $01,$18,$66,$1C,$00,$40,$00 ; Layer 1 part 3: source $00:1C66, $0040 bytes
$00:8A2B .db $01,$18,$A6,$1C,$00,$2C,$00 ; Layer 1 part 4: source $00:1CA6, $002C bytes
$00:8A32 .db $01,$18,$E8,$1C,$00,$40,$00 ; Layer 2 part 1: source $00:1CE8, $0040 bytes
$00:8A39 .db $01,$18,$28,$1D,$00,$2C,$00 ; Layer 2 part 2: source $00:1D28, $002C bytes
$00:8A40 .db $01,$18,$68,$1D,$00,$40,$00 ; Layer 2 part 3: source $00:1D68, $0040 bytes
$00:8A47 .db $01,$18,$A8,$1D,$00,$2C,$00 ; Layer 2 part 4: source $00:1DA8, $002C bytes
;;; $8A4E: Clear RAM except the stack page (ClearStack) ;;;
;; Clears $0000-$00FF and $0200-$1FFF (the stack page $0100-$01FF is skipped, despite the label), empties the
;; stripe image buffer at $7F:837B/837D
;; and clears [$0681]. Called at reset and from the game mode loaders.
;; Called by:
;; $00:96B1: Cutscene, ending and game mode code (castle scenes, credits, game over) (CutsceneCastlePal)
$00:8A4E C2 30 REP #$30 ; A, X and Y 16-bit
$00:8A50 A2 FE 1F LDX.W #$1FFE ; X = $1FFE: top word of the RAM to clear
$00:8A53 74 00 STZ $00,X ; Clear the word at $0000+X
$00:8A55 CA DEX ; \
$00:8A56 CA DEX ; / X -= 2
$00:8A57 E0 FF 01 CPX.W #$01FF ; \
$00:8A5A 10 05 BPL $8A61 ; / X >= $01FF: go to the end test at $008A61
$00:8A5C E0 00 01 CPX.W #$0100 ; \
$00:8A5F 10 F4 BPL $8A55 ; / $0100 <= X < $01FF (the stack page): skip it without clearing
$00:8A61 E0 FE FF CPX.W #$FFFE ; \
$00:8A64 D0 ED BNE $8A53 ; / Loop until X wraps below 0
$00:8A66 A9 00 00 LDA.W #$0000 ; \
$00:8A69 8F 7B 83 7F STA.L $7F837B ; / $7F:837B = 0: stripe image buffer write index
$00:8A6D 9C 81 06 STZ.W $0681 ; [$0681] = 0: probably empties the queued palette upload
$00:8A70 E2 30 SEP #$30 ; A, X and Y 8-bit
$00:8A72 A9 FF LDA.B #$FF ; \
$00:8A74 8F 7D 83 7F STA.L $7F837D ; / $7F:837D = $FF: stripe image buffer starts with the end marker
$00:8A78 60 RTS ; Return
;;; $8A79: Reset PPU layer addresses and effects (SetUpScreen) ;;;
;; Resets SETINI and mosaic, sets the BG1/BG2/BG3 tilemap sizes and addresses and the chr bases, clears the
;; window masks and logic (and their RAM mirrors
;; [$41]-[$43]), sets the color math mirror [$44] = $02 and the Mode 7 screen-over mode.
;; Called by:
;; $00:9394: Game mode 00: load Nintendo Presents (NintendoTile)
;; $00:946E: Cutscene, ending and game mode code (castle scenes, credits, game over) (CutsceneCastlePal)
;; $00:95C7: Cutscene, ending and game mode code (castle scenes, credits, game over) (CutsceneCastlePal)
;; $00:9643: Cutscene, ending and game mode code (castle scenes, credits, game over) (CutsceneCastlePal)
;; $00:A0B6: Game mode 0C: load overworld (LoadMapGameMode)
;; $00:A5A5: Game mode 12: prepare level (GM04Load)
$00:8A79 9C 33 21 STZ.W $2133 ; SETINI = 0: no interlace, no pseudo-hires, no overscan
$00:8A7C 9C 06 21 STZ.W $2106 ; MOSAIC = 0: mosaic off
$00:8A7F A9 23 LDA.B #$23 ; \
$00:8A81 8D 07 21 STA.W $2107 ; / BG1 tilemap at VRAM $2000, 64x64
$00:8A84 A9 33 LDA.B #$33 ; \
$00:8A86 8D 08 21 STA.W $2108 ; / BG2 tilemap at VRAM $3000, 64x64
$00:8A89 A9 53 LDA.B #$53 ; \
$00:8A8B 8D 09 21 STA.W $2109 ; / BG3 tilemap at VRAM $5000, 64x64
$00:8A8E A9 00 LDA.B #$00 ; \
$00:8A90 8D 0B 21 STA.W $210B ; / BG1 and BG2 tile data at VRAM $0000
$00:8A93 A9 04 LDA.B #$04 ; \
$00:8A95 8D 0C 21 STA.W $210C ; / BG3 tile data at VRAM $4000, BG4 at $0000
$00:8A98 64 41 STZ $41 ; [$41] = 0: BG1/BG2 window mask mirror
$00:8A9A 64 42 STZ $42 ; [$42] = 0: BG3/BG4 window mask mirror
$00:8A9C 64 43 STZ $43 ; [$43] = 0: OBJ/color window mask mirror
$00:8A9E 9C 2A 21 STZ.W $212A ; BG window logic = 0
$00:8AA1 9C 2B 21 STZ.W $212B ; OBJ/color window logic = 0
$00:8AA4 9C 2E 21 STZ.W $212E ; No window masking on the main screen
$00:8AA7 9C 2F 21 STZ.W $212F ; No window masking on the sub screen
$00:8AAA A9 02 LDA.B #$02 ; \
$00:8AAC 85 44 STA $44 ; / [$44] = $02: color math mirror (CGWSEL), probably adds the subscreen
$00:8AAE A9 80 LDA.B #$80 ; \
$00:8AB0 8D 1A 21 STA.W $211A ; / M7SEL = $80: Mode 7 area outside the map transparent, no flipping
$00:8AB3 60 RTS ; Return
;;; $8AB4..8ACC: Table: sine index adjustments ;;;
;; Used by the Mode 7 matrix routine: indexed by quadrant * 2. The EOR/addend pair turns an in-quadrant offset
;; into $100 - offset in odd quadrants.
$00:8AB4 .db $00,$00,$FE,$00,$00,$00,$FE,$00 ; Per-quadrant EOR mask for the sine index: $0000, $00FE, $0000, $00FE
$00:8ABC .db $00,$00,$02,$00,$00,$00,$02,$00 ; Per-quadrant addend: $0000, $0002, $0000, $0002 (with the EOR: $100 - index in odd quadrants)
$00:8AC4 .db $00,$00,$00,$01,$FF,$FF,$00,$10 ; Unreferenced bytes, purpose unclear
$00:8ACC .db $F0
; |
; V Mode 7 Stuff.. updating M7 mirrors, etc
;;; $8ACD: Calculate Mode 7 rotation matrix ;;;
;; Builds the Mode 7 matrix from the rotation angle [$36] and the scales [$38] and [$39]: A [$2E] = cos *
;; [$38], B [$30] = sin * [$38],
;; C [$32] = -sin * [$39], D [$34] = cos * [$39]. Values are 8.8 fixed point (a scale of $20 gives $0100).
;; Called by the Mode 7 boss room code.
;; $008AE8: computes [$30] and [$2E] for scale [$00]. $008B2B: A = (sine table entry X * [$00]) / 32 using the
;; hardware multiplier.
;; Called by:
;; $00:985D: Game mode 11: Mario Start, level music (MarioStartGameMode)
;; $00:987D: Mode 7 boss room: per-frame update
$00:8ACD A5 39 LDA $39 ; \
$00:8ACF 85 00 STA $00 ; / [$00] = [$39]: scale for the matrix C and D entries
$00:8AD1 C2 30 REP #$30 ; A, X and Y 16-bit
$00:8AD3 20 E8 8A JSR.W $8AE8 ; [$30] = sin * [$00], [$2E] = cos * [$00]
$00:8AD6 A5 38 LDA $38 ; \
$00:8AD8 85 00 STA $00 ; / [$00] = [$38]: scale for the matrix A and B entries
$00:8ADA C2 30 REP #$30 ; A, X and Y 16-bit
$00:8ADC A5 2E LDA $2E ; \
$00:8ADE 85 34 STA $34 ; / [$34] (matrix D) = [$2E] = cos * [$39]
$00:8AE0 A5 30 LDA $30 ; \
$00:8AE2 49 FF FF EOR.W #$FFFF ; |
$00:8AE5 1A INC A ; |
$00:8AE6 85 32 STA $32 ; / [$32] (matrix C) = -[$30] = -sin * [$39]; then fall into the second pass
$00:8AE8 A5 36 LDA $36 ; A = [$36]: rotation angle ($0200 = full turn)
$00:8AEA 0A ASL ; A = angle * 2
$00:8AEB 48 PHA ; Save angle * 2
$00:8AEC EB XBA ; \
$00:8AED 29 03 00 AND.W #$0003 ; |
$00:8AF0 0A ASL ; |
$00:8AF1 A8 TAY ; / Y = quadrant * 2 (angle bits 7-8)
$00:8AF2 68 PLA ; A = angle * 2
$00:8AF3 29 FE 00 AND.W #$00FE ; A = (angle & $7F) * 2: byte offset in the quadrant
$00:8AF6 59 B4 8A EOR.W $8AB4,Y ; \
$00:8AF9 18 CLC ; |
$00:8AFA 79 BC 8A ADC.W $8ABC,Y ; / A = sine table offset: as is in even quadrants, $100 - offset in odd ones
$00:8AFD AA TAX ; X = sine table offset
$00:8AFE 20 2B 8B JSR.W $8B2B ; A = |sin| * [$00] / 32
$00:8B01 C0 04 00 CPY.W #$0004 ; \
$00:8B04 90 04 BCC $8B0A ; |
$00:8B06 49 FF FF EOR.W #$FFFF ; |
$00:8B09 1A INC A ; / Negate when angle >= $100 (quadrants 2-3): sine is negative there
$00:8B0A 85 30 STA $30 ; [$30] = sin(angle) * scale (matrix B)
$00:8B0C 8A TXA ; \
$00:8B0D 49 FE 00 EOR.W #$00FE ; |
$00:8B10 18 CLC ; |
$00:8B11 69 02 00 ADC.W #$0002 ; |
$00:8B14 29 FF 01 AND.W #$01FF ; |
$00:8B17 AA TAX ; / X = $100 - X (wrapped to 9 bits): table offset of the cosine
$00:8B18 20 2B 8B JSR.W $8B2B ; A = |cos| * [$00] / 32
$00:8B1B 88 DEY ; \
$00:8B1C 88 DEY ; |
$00:8B1D C0 04 00 CPY.W #$0004 ; |
$00:8B20 B0 04 BCS $8B26 ; |
$00:8B22 49 FF FF EOR.W #$FFFF ; |
$00:8B25 1A INC A ; / Negate for angles $080-$17F (quadrants 1-2): cosine is negative there
$00:8B26 85 2E STA $2E ; [$2E] = cos(angle) * scale (matrix A)
$00:8B28 E2 30 SEP #$30 ; A, X and Y 8-bit
$00:8B2A 60 RTS ; Return
$00:8B2B E2 20 SEP #$20 ; A 8-bit
$00:8B2D BD 58 8B LDA.W $8B58,X ; \
$00:8B30 F0 02 BEQ $8B34 ; |
$00:8B32 A5 00 LDA $00 ; |
$00:8B34 85 01 STA $01 ; / [$01] = [$00] if the table entry is $0100, else 0 (high byte of the product)
$00:8B36 BD 57 8B LDA.W $8B57,X ; \
$00:8B39 8D 02 42 STA.W $4202 ; / Multiplicand = low byte of the table entry
$00:8B3C A5 00 LDA $00 ; \
$00:8B3E 8D 03 42 STA.W $4203 ; / Multiplier = scale [$00]; starts the hardware multiply
$00:8B41 EA NOP ; \
$00:8B42 EA NOP ; |
$00:8B43 EA NOP ; |
$00:8B44 EA NOP ; / Wait for the multiplication
$00:8B45 AD 17 42 LDA.W $4217 ; \
$00:8B48 18 CLC ; |
$00:8B49 65 01 ADC $01 ; |
$00:8B4B EB XBA ; / High byte = product high byte + [$01]
$00:8B4C AD 16 42 LDA.W $4216 ; Low byte of the product
$00:8B4F C2 20 REP #$20 ; A 16-bit
$00:8B51 4A LSR ; \
$00:8B52 4A LSR ; |
$00:8B53 4A LSR ; |
$00:8B54 4A LSR ; |
$00:8B55 4A LSR ; / A = A / 32 (entry * scale / 32; a scale of $20 gives sin * $100)
$00:8B56 60 RTS ; Return
;;; $8B57..8C88: Table: sine values, then unused tilemap words ;;;
;; 129 little-endian words: sin(0..90 degrees) * $100, ending at $0100. The 20 tilemap words after it
;; ($8C59-$8C80) are not referenced by anything
;; I found. The last 8 bytes are the item box top row used by GM04DoDMA.
$00:8B57 .db $00 ; Sine table: 129 words, entry n = sin(n * 90/128 degrees) * $100 (low byte first)
$00:8B58 .db $00,$03,$00,$06,$00,$09,$00,$0C
$00:8B60 .db $00,$0F,$00,$12,$00,$15,$00,$19
$00:8B68 .db $00,$1C,$00,$1F,$00,$22,$00,$25
$00:8B70 .db $00,$28,$00,$2B,$00,$2E,$00,$31
$00:8B78 .db $00,$35,$00,$38,$00,$3B,$00,$3E
$00:8B80 .db $00,$41,$00,$44,$00,$47,$00,$4A
$00:8B88 .db $00,$4D,$00,$50,$00,$53,$00,$56
$00:8B90 .db $00,$59,$00,$5C,$00,$5F,$00,$61
$00:8B98 .db $00,$64,$00,$67,$00,$6A,$00,$6D
$00:8BA0 .db $00,$70,$00,$73,$00,$75,$00,$78
$00:8BA8 .db $00,$7B,$00,$7E,$00,$80,$00,$83
$00:8BB0 .db $00,$86,$00,$88,$00,$8B,$00,$8E
$00:8BB8 .db $00,$90,$00,$93,$00,$95,$00,$98
$00:8BC0 .db $00,$9B,$00,$9D,$00,$9F,$00,$A2
$00:8BC8 .db $00,$A4,$00,$A7,$00,$A9,$00,$AB
$00:8BD0 .db $00,$AE,$00,$B0,$00,$B2,$00,$B5
$00:8BD8 .db $00,$B7,$00,$B9,$00,$BB,$00,$BD
$00:8BE0 .db $00,$BF,$00,$C1,$00,$C3,$00,$C5
$00:8BE8 .db $00,$C7,$00,$C9,$00,$CB,$00,$CD
$00:8BF0 .db $00,$CF,$00,$D1,$00,$D3,$00,$D4
$00:8BF8 .db $00,$D6,$00,$D8,$00,$D9,$00,$DB
$00:8C00 .db $00,$DD,$00,$DE,$00,$E0,$00,$E1
$00:8C08 .db $00,$E3,$00,$E4,$00,$E6,$00,$E7
$00:8C10 .db $00,$E8,$00,$EA,$00,$EB,$00,$EC
$00:8C18 .db $00,$ED,$00,$EE,$00,$EF,$00,$F1
$00:8C20 .db $00,$F2,$00,$F3,$00,$F4,$00,$F4
$00:8C28 .db $00,$F5,$00,$F6,$00,$F7,$00,$F8
$00:8C30 .db $00,$F9,$00,$F9,$00,$FA,$00,$FB
$00:8C38 .db $00,$FB,$00,$FC,$00,$FC,$00,$FD
$00:8C40 .db $00,$FD,$00,$FE,$00,$FE,$00,$FE
$00:8C48 .db $00,$FF,$00,$FF,$00,$FF,$00,$FF
$00:8C50 .db $00,$FF,$00,$FF,$00,$FF,$00,$00
$00:8C58 .db $01,$B7,$3C,$B7,$BC,$B8,$3C,$B9 ; High byte of the last entry ($0100 = sin 90 degrees), then 20 unreferenced tilemap words
$00:8C60 .db $3C,$BA,$3C,$BB,$3C,$BA,$3C,$BA
$00:8C68 .db $BC,$BC,$3C,$BD,$3C,$BE,$3C,$BF
$00:8C70 .db $3C,$C0,$3C,$B7,$BC,$C1,$3C,$B9
$00:8C78 .db $3C,$C2,$3C,$C2,$BC,$B7,$3C,$C0
$00:8C80 .db $FC,$3A,$38,$3B,$38,$3B,$38,$3A ; Last byte of those words; then item box top row (4 words, DMA source $8C81)
$00:8C88 .db $78 ; End of the item box top row (X-flipped corner)
;;; $8C89..8CF9: Table: initial status bar tilemap ;;;
;; Tile/property words for the BG3 status bar: line 1 (28 words), line 2 (27 words) and the item box bottom
;; row (4 words). Uploaded by GM04DoDMA,
;; which also copies the tile numbers to the RAM mirror at $0EF9.
$00:8C89 .db $30,$28,$31,$28,$32,$28,$33,$28 ; Line 1 (VRAM $5042), words 0-3: tiles $30-$33, probably the MARIO label
$00:8C91 .db $34,$28,$FC,$38,$FC,$3C,$FC,$3C ; Words 4-7: tile $34, then blanks (tile $FC)
$00:8C99 .db $FC,$3C,$FC,$3C,$FC,$38,$FC,$38 ; Words 8-11: blanks
$00:8CA1 .db $4A,$38,$FC,$38,$FC,$38,$4A,$78 ; Words 12-15: item box left border ($4A), 2 blanks, right border ($4A, X-flipped)
$00:8CA9 .db $FC,$38,$3D,$3C,$3E,$3C,$3F,$3C ; Words 16-19: blank, tiles $3D-$3F (probably the TIME label)
$00:8CB1 .db $FC,$38,$FC,$38,$FC,$38,$2E,$3C ; Words 20-23: blanks, tile $2E
$00:8CB9 .db $26,$38,$FC,$38,$FC,$38,$00,$38 ; Words 24-27: tile $26, 2 blanks, digit 0
$00:8CC1 .db $26,$38,$FC,$38,$00,$38,$FC,$38 ; Line 2 (VRAM $5063), words 0-3: tile $26, blank, digit 0, blank
$00:8CC9 .db $FC,$38,$FC,$38,$64,$28,$26,$38 ; Words 4-7: blanks, tile $64, tile $26
$00:8CD1 .db $FC,$38,$FC,$38,$FC,$38,$4A,$38 ; Words 8-11: blanks, item box left border
$00:8CD9 .db $FC,$38,$FC,$38,$4A,$78,$FC,$38 ; Words 12-15: blanks, item box right border, blank
$00:8CE1 .db $FE,$3C,$FE,$3C,$00,$3C,$FC,$38 ; Words 16-19: $FE, $FE, digit 0 (timer digits), blank
$00:8CE9 .db $FC,$38,$FC,$38,$FC,$38,$FC,$38 ; Words 20-23: blanks
$00:8CF1 .db $FC,$38,$FC,$38,$00,$38,$3A,$B8 ; Words 24-26: blank, blank, digit 0; then item box bottom row at $8CF7
$00:8CF9 .db $3B,$B8,$3B,$B8,$3A,$F8 ; End of the item box bottom row (Y-flipped tiles)
;;; $8CFF: Upload initial status bar to VRAM (GM04DoDMA) ;;;
;; Writes the item box top, status bar lines 1 and 2 and the item box bottom into the BG3 tilemap with DMA
;; channel 1, copies the 55 tile numbers to the
;; mirror at $0EF9 (used by DrawStatusBar) and sets the timer frame countdown [$0F30] = $28.
;; Called by:
;; $00:985A: Game mode 11: Mario Start, level music (MarioStartGameMode)
;; $00:A5A8: Game mode 12: prepare level (GM04Load)
$00:8CFF A9 80 LDA.B #$80 ; \
$00:8D01 8D 15 21 STA.W $2115 ; / VMAIN = $80: step after high byte writes
$00:8D04 A9 2E LDA.B #$2E ; \
$00:8D06 8D 16 21 STA.W $2116 ; |
$00:8D09 A9 50 LDA.B #$50 ; |
$00:8D0B 8D 17 21 STA.W $2117 ; / VRAM address = $502E (BG3 row 1, column 14: item box top)
$00:8D0E A2 06 LDX.B #$06 ; \
$00:8D10 BD 90 8D LDA.W $8D90,X ; |
$00:8D13 9D 10 43 STA.W $4310,X ; |
$00:8D16 CA DEX ; |
$00:8D17 10 F7 BPL $8D10 ; / Copy 7 DMA setup bytes to $4310-$4316: $8D90 (source $00:8C81, 8 bytes)
$00:8D19 A9 02 LDA.B #$02 ; \
$00:8D1B 8D 0B 42 STA.W $420B ; / Run DMA channel 1: item box top row
$00:8D1E A9 80 LDA.B #$80 ; \
$00:8D20 8D 15 21 STA.W $2115 ; / VMAIN = $80
$00:8D23 A9 42 LDA.B #$42 ; \
$00:8D25 8D 16 21 STA.W $2116 ; |
$00:8D28 A9 50 LDA.B #$50 ; |
$00:8D2A 8D 17 21 STA.W $2117 ; / VRAM address = $5042 (BG3 row 2, column 2: status bar line 1)
$00:8D2D A2 06 LDX.B #$06 ; \
$00:8D2F BD 97 8D LDA.W $8D97,X ; |
$00:8D32 9D 10 43 STA.W $4310,X ; |
$00:8D35 CA DEX ; |
$00:8D36 10 F7 BPL $8D2F ; / Copy 7 DMA setup bytes to $4310-$4316: $8D97 (source $00:8C89, $38 bytes)
$00:8D38 A9 02 LDA.B #$02 ; \
$00:8D3A 8D 0B 42 STA.W $420B ; / Run DMA channel 1: status bar line 1 (28 words)
$00:8D3D A9 80 LDA.B #$80 ; \
$00:8D3F 8D 15 21 STA.W $2115 ; / VMAIN = $80
$00:8D42 A9 63 LDA.B #$63 ; \
$00:8D44 8D 16 21 STA.W $2116 ; |
$00:8D47 A9 50 LDA.B #$50 ; |
$00:8D49 8D 17 21 STA.W $2117 ; / VRAM address = $5063 (BG3 row 3, column 3: status bar line 2)
$00:8D4C A2 06 LDX.B #$06 ; \
$00:8D4E BD 9E 8D LDA.W $8D9E,X ; |
$00:8D51 9D 10 43 STA.W $4310,X ; |
$00:8D54 CA DEX ; |
$00:8D55 10 F7 BPL $8D4E ; / Copy 7 DMA setup bytes to $4310-$4316: $8D9E (source $00:8CC1, $36 bytes)
$00:8D57 A9 02 LDA.B #$02 ; \
$00:8D59 8D 0B 42 STA.W $420B ; / Run DMA channel 1: status bar line 2 (27 words)
$00:8D5C A9 80 LDA.B #$80 ; \
$00:8D5E 8D 15 21 STA.W $2115 ; / VMAIN = $80
$00:8D61 A9 8E LDA.B #$8E ; \
$00:8D63 8D 16 21 STA.W $2116 ; |
$00:8D66 A9 50 LDA.B #$50 ; |
$00:8D68 8D 17 21 STA.W $2117 ; / VRAM address = $508E (BG3 row 4, column 14: item box bottom)
$00:8D6B A2 06 LDX.B #$06 ; \
$00:8D6D BD A5 8D LDA.W $8DA5,X ; |
$00:8D70 9D 10 43 STA.W $4310,X ; |
$00:8D73 CA DEX ; |
$00:8D74 10 F7 BPL $8D6D ; / Copy 7 DMA setup bytes to $4310-$4316: $8DA5 (source $00:8CF7, 8 bytes)
$00:8D76 A9 02 LDA.B #$02 ; \
$00:8D78 8D 0B 42 STA.W $420B ; / Run DMA channel 1: item box bottom row
$00:8D7B A2 36 LDX.B #$36 ; X = $36: 55 tile numbers to copy
$00:8D7D A0 6C LDY.B #$6C ; Y = $6C: byte offset of the last tilemap word
$00:8D7F B9 89 8C LDA.W $8C89,Y ; Tile number of word Y/2 (the attribute bytes are skipped)
$00:8D82 9D F9 0E STA.W $0EF9,X ; Status bar tile mirror $0EF9+X (line 1 at $0EF9, line 2 at $0F15)
$00:8D85 88 DEY ; \
$00:8D86 88 DEY ; / Y -= 2
$00:8D87 CA DEX ; X--
$00:8D88 10 F5 BPL $8D7F ; Loop for all 55 tiles
$00:8D8A A9 28 LDA.B #$28 ; \
$00:8D8C 8D 30 0F STA.W $0F30 ; / [$0F30] = $28: frame countdown for the level timer
$00:8D8F 60 RTS ; Return
;;; $8D90..8DA5: Table: DMA setups for status bar init ;;;
;; Four 7-byte DMA channel 1 setups (DMAP 1, B-bus $18) used by GM04DoDMA.
$00:8D90 .db $01,$18,$81,$8C,$00,$08,$00 ; DMAP 1, B-bus $18, source $00:8C81, $0008 bytes (item box top)
$00:8D97 .db $01,$18,$89,$8C,$00,$38,$00 ; DMAP 1, B-bus $18, source $00:8C89, $0038 bytes (line 1)
$00:8D9E .db $01,$18,$C1,$8C,$00,$36,$00 ; DMAP 1, B-bus $18, source $00:8CC1, $0036 bytes (line 2)
$00:8DA5 .db $01,$18,$F7,$8C,$00,$08,$00 ; DMAP 1, B-bus $18, source $00:8CF7, $0008 bytes (item box bottom)
;;; $8DAC: Upload status bar tile numbers (DrawStatusBar) ;;;
;; DMAs the tile number mirrors $0EF9 (28 bytes) and $0F15 (27 bytes) to the low bytes of the BG3 tilemap at
;; $5042 and $5063.
;; Called every NMI. The properties are set once by GM04DoDMA.
;; Called by:
;; $00:81F4: NMI handler: sound, PPU mirrors, DMA (NMIStart)
;; $00:82E8: NMI tail: scroll, IRQ setup, Mode 7 path (NMINotSpecialLv)
$00:8DAC 9C 15 21 STZ.W $2115 ; VMAIN = 0: step after low byte writes (only tile numbers are written)
$00:8DAF A9 42 LDA.B #$42 ; \
$00:8DB1 8D 16 21 STA.W $2116 ; |
$00:8DB4 A9 50 LDA.B #$50 ; |
$00:8DB6 8D 17 21 STA.W $2117 ; / VRAM address = $5042 (status bar line 1)
$00:8DB9 A2 06 LDX.B #$06 ; \
$00:8DBB BD E7 8D LDA.W DMAdata_StBr1,X ; |
$00:8DBE 9D 10 43 STA.W $4310,X ; |
$00:8DC1 CA DEX ; |
$00:8DC2 10 F7 BPL $8DBB ; / Copy 7 DMA setup bytes to $4310-$4316: DMAdata_StBr1 (source $00:0EF9, 28 bytes)
$00:8DC4 A9 02 LDA.B #$02 ; \
$00:8DC6 8D 0B 42 STA.W $420B ; / Run DMA channel 1: line 1 tile numbers
$00:8DC9 9C 15 21 STZ.W $2115 ; VMAIN = 0
$00:8DCC A9 63 LDA.B #$63 ; \
$00:8DCE 8D 16 21 STA.W $2116 ; |
$00:8DD1 A9 50 LDA.B #$50 ; |
$00:8DD3 8D 17 21 STA.W $2117 ; / VRAM address = $5063 (status bar line 2)
$00:8DD6 A2 06 LDX.B #$06 ; \
$00:8DD8 BD EE 8D LDA.W DMAdata_StBr2,X ; |
$00:8DDB 9D 10 43 STA.W $4310,X ; |
$00:8DDE CA DEX ; |
$00:8DDF 10 F7 BPL $8DD8 ; / Copy 7 DMA setup bytes to $4310-$4316: DMAdata_StBr2 (source $00:0F15, 27 bytes)
$00:8DE1 A9 02 LDA.B #$02 ; \
$00:8DE3 8D 0B 42 STA.W $420B ; / Run DMA channel 1: line 2 tile numbers
$00:8DE6 60 RTS ; Return
;;; $8DE7: Table: DMA setup, status bar line 1 (DMAdata_StBr1) ;;;
;; 7 bytes for DrawStatusBar: DMAP 0, B-bus $18, source $00:0EF9, $001C bytes.
$00:8DE7 .db $00,$18,$F9,$0E,$00,$1C,$00 ; DMAP 0, B-bus $18 (VRAM data low), source $00:0EF9, $001C bytes
;;; $8DEE: Status bar: update counters and tiles (DMAdata_StBr2) ;;;
;; Data first: DMA setup for status bar row 2 (source [$0F15], 27 bytes to VRAM), LUIGI name tiles, item box
;; tile and palette tables, big bonus star digit tiles.
;; Code at $008E1A (called once per frame): runs the level timer (a tick every ~40 frames, hurry-up music at
;; 099, KillMario at 000), clamps scores to 999,999,
;; builds the score, time, coin, lives and bonus star digit tiles in the row buffers [$0EF9] (row 1) and
;; [$0F15] (row 2), adds pending coins
;; ([$13CC]) one per frame with a 1-up at 100, starts the bonus game at 100 bonus stars, swaps MARIO for LUIGI
;; and draws the item box and Yoshi coin icons.
;; The tiles are DMAed to VRAM by DrawStatusBar. Tile $FC is the blank tile used to hide leading zeros.
$00:8DEE .db $00,$18,$15,$0F,$00,$1B,$00 ; DMA setup for status bar row 2: DMAP $00, B-bus $18 (VRAM), source $00:0F15, size $001B
$00:8DF5 .db $40,$41,$42,$43 ; Status bar tiles of the name LUIGI: $40-$44 ($44 is also the first byte of the next row)
$00:8DF9 .db $44,$24,$26,$48,$0E ; Item box tile by item [$0DC2]: 1 mushroom $24, 2 fire flower $26, 3 star $48, 4 cape $0E
$00:8DFE .db $00,$02,$04 ; Item box star palette bits cycle: $00, $02, $04, then $02 (first byte of next table)
$00:8E01 .db $02,$08,$0A,$00,$04 ; Item box palette bits by item: 1 mushroom $08, 2 flower $0A, 3 star (cycles), 4 cape $04
$00:8E06 .db $B7 ; Big bonus star digit tiles, (top, bottom) per digit 0-9. Digit 0 top = $B7
$00:8E07 .db $C3,$B8,$B9,$BA,$BB,$BA,$BF,$BC ; 0 bottom $C3; 1 = $B8/$B9; 2 = $BA/$BB; 3 = $BA/$BF; 4 top = $BC
$00:8E0F .db $BD,$BE,$BF,$C0,$C3,$C1,$B9,$C2 ; 4 bottom $BD; 5 = $BE/$BF; 6 = $C0/$C3; 7 = $C1/$B9; 8 top = $C2
$00:8E17 .db $C4,$B7,$C5 ; 8 bottom $C4; 9 = $B7/$C5
; Yay status bar stuff. Down here, X is commonly used as a "step counter" type thing as well as a index to the tile to handle. Just to put that out there.
$00:8E1A AD 93 14 LDA.W $1493 ; \
$00:8E1D 05 9D ORA RAM_SpritesLocked ; |
$00:8E1F D0 4E BNE $8E6F ; / Level ending ([$1493]) or sprites locked ([$9D]): freeze the timer
$00:8E21 AD 9B 0D LDA.W $0D9B ; \
$00:8E24 C9 C1 CMP.B #$C1 ; |
$00:8E26 F0 47 BEQ $8E6F ; / Bowser fight ([$0D9B] = $C1): the timer does not run
$00:8E28 CE 30 0F DEC.W $0F30 ; \
$00:8E2B 10 42 BPL $8E6F ; / [$0F30]-- (frames per clock tick); still >= 0: skip the tick
$00:8E2D A9 28 LDA.B #$28 ; \
$00:8E2F 8D 30 0F STA.W $0F30 ; / [$0F30] = $28: next clock tick in about 40 frames
$00:8E32 AD 31 0F LDA.W $0F31 ; \
$00:8E35 0D 32 0F ORA.W $0F32 ; |
$00:8E38 0D 33 0F ORA.W $0F33 ; |
$00:8E3B F0 32 BEQ $8E6F ; / Time is already 000: nothing to count down
$00:8E3D A2 02 LDX.B #$02 ; X = 2: start with the ones digit [$0F33]
$00:8E3F DE 31 0F DEC.W $0F31,X ; \
$00:8E42 10 08 BPL $8E4C ; |
$00:8E44 A9 09 LDA.B #$09 ; |
$00:8E46 9D 31 0F STA.W $0F31,X ; |
$00:8E49 CA DEX ; |
$00:8E4A 10 F3 BPL $8E3F ; / Decrement the time digits [$0F31]-[$0F33] (hundreds, tens, ones) with borrow (0 becomes 9)
$00:8E4C AD 31 0F LDA.W $0F31 ; \
$00:8E4F D0 0F BNE $8E60 ; |
$00:8E51 AD 32 0F LDA.W $0F32 ; |
$00:8E54 2D 33 0F AND.W $0F33 ; |
$00:8E57 C9 09 CMP.B #$09 ; |
$00:8E59 D0 05 BNE $8E60 ; / Only continue if the time just became 099 (hundreds 0, tens AND ones = 9)
$00:8E5B A9 FF LDA.B #$FF ; A = $FF
$00:8E5D 8D F9 1D STA.W $1DF9 ; Sound request [$1DF9] = $FF: hurry up (music speeds up)
$00:8E60 AD 31 0F LDA.W $0F31 ; \
$00:8E63 0D 32 0F ORA.W $0F32 ; |
$00:8E66 0D 33 0F ORA.W $0F33 ; |
$00:8E69 D0 04 BNE $8E6F ; / Any digit non-zero: time is not up yet
$00:8E6B 22 06 F6 00 JSL.L KillMario ; Time is 000: kill Mario (KillMario)
$00:8E6F AD 31 0F LDA.W $0F31 ; \
$00:8E72 8D 25 0F STA.W $0F25 ; |
$00:8E75 AD 32 0F LDA.W $0F32 ; |
$00:8E78 8D 26 0F STA.W $0F26 ; |
$00:8E7B AD 33 0F LDA.W $0F33 ; |
$00:8E7E 8D 27 0F STA.W $0F27 ; / Copy the time digits [$0F31]-[$0F33] to the status bar tiles [$0F25]-[$0F27]
$00:8E81 A2 10 LDX.B #$10 ; X = $10: offset of the timer tiles in the row 2 buffer ([$0F15] + X)
$00:8E83 A0 00 LDY.B #$00 ; Y = 0: time digit index
$00:8E85 B9 31 0F LDA.W $0F31,Y ; Time digit [$0F31+Y]
$00:8E88 D0 0B BNE $8E95 ; Non-zero: stop blanking leading zeros
$00:8E8A A9 FC LDA.B #$FC ; \
$00:8E8C 9D 15 0F STA.W $0F15,X ; / Leading zero: replace the tile with a blank ($FC)
$00:8E8F C8 INY ; \
$00:8E90 E8 INX ; |
$00:8E91 C0 02 CPY.B #$02 ; |
$00:8E93 D0 F0 BNE $8E85 ; / Next digit; only the hundreds and tens places can be blanked (Y < 2)
$00:8E95 A2 03 LDX.B #$03 ; X = 3: Luigi's score first, then Mario's (3-byte scores at [$0F34] and [$0F37])
$00:8E97 BD 36 0F LDA.W $0F36,X ; \
$00:8E9A 85 00 STA $00 ; |
$00:8E9C 64 01 STZ $01 ; / [$00]-[$01] = high byte of the score, as a 16-bit value
$00:8E9E C2 20 REP #$20 ; A 16-bit
$00:8EA0 BD 34 0F LDA.W $0F34,X ; \
$00:8EA3 38 SEC ; |
$00:8EA4 E9 3F 42 SBC.W #$423F ; |
$00:8EA7 A5 00 LDA $00 ; |
$00:8EA9 E9 0F 00 SBC.W #$000F ; |
$00:8EAC 90 11 BCC $8EBF ; / 24-bit compare: score - $0F423F (999,999); below the cap: skip
$00:8EAE E2 20 SEP #$20 ; A 8-bit
$00:8EB0 A9 0F LDA.B #$0F ; \
$00:8EB2 9D 36 0F STA.W $0F36,X ; |
$00:8EB5 A9 42 LDA.B #$42 ; |
$00:8EB7 9D 35 0F STA.W $0F35,X ; |
$00:8EBA A9 3F LDA.B #$3F ; |
$00:8EBC 9D 34 0F STA.W $0F34,X ; / Clamp the score to $0F423F (999,999)
$00:8EBF E2 20 SEP #$20 ; A 8-bit
$00:8EC1 CA DEX ; \
$00:8EC2 CA DEX ; |
$00:8EC3 CA DEX ; / X -= 3: previous player's score
$00:8EC4 10 D1 BPL $8E97 ; Loop for Luigi (X = 3), then Mario (X = 0)
$00:8EC6 AD 36 0F LDA.W $0F36 ; \
$00:8EC9 85 00 STA $00 ; |
$00:8ECB 64 01 STZ $01 ; |
$00:8ECD AD 35 0F LDA.W $0F35 ; |
$00:8ED0 85 03 STA $03 ; |
$00:8ED2 AD 34 0F LDA.W $0F34 ; |
$00:8ED5 85 02 STA $02 ; / 32-bit value: [$00]-[$01] = high word, [$02]-[$03] = low word = Mario's score
$00:8ED7 A2 14 LDX.B #$14 ; X = $14: score tiles start at [$0F15 + $14] = $0F29
$00:8ED9 A0 00 LDY.B #$00 ; Y = 0: start with the 100,000s place
$00:8EDB 20 12 90 JSR.W $9012 ; Convert to six digit tiles at [$0F29]-[$0F2E] ($9012)
$00:8EDE A2 00 LDX.B #$00 ; X = 0: first score digit
$00:8EE0 BD 29 0F LDA.W $0F29,X ; Score digit tile [$0F29+X]
$00:8EE3 D0 0A BNE $8EEF ; Non-zero: stop blanking
$00:8EE5 A9 FC LDA.B #$FC ; \
$00:8EE7 9D 29 0F STA.W $0F29,X ; / Leading zero: blank tile ($FC)
$00:8EEA E8 INX ; \
$00:8EEB E0 06 CPX.B #$06 ; |
$00:8EED D0 F1 BNE $8EE0 ; / Next digit, up to all six (a static 0 follows the score on screen)
$00:8EEF AD B3 0D LDA.W $0DB3 ; \
$00:8EF2 F0 29 BEQ $8F1D ; / Current player [$0DB3] = 0 (Mario): his score is already shown
$00:8EF4 AD 39 0F LDA.W $0F39 ; \
$00:8EF7 85 00 STA $00 ; |
$00:8EF9 64 01 STZ $01 ; |
$00:8EFB AD 38 0F LDA.W $0F38 ; |
$00:8EFE 85 03 STA $03 ; |
$00:8F00 AD 37 0F LDA.W $0F37 ; |
$00:8F03 85 02 STA $02 ; / Same setup with Luigi's score ([$0F37]-[$0F39])
$00:8F05 A2 14 LDX.B #$14 ; X = $14: score tiles start at $0F29
$00:8F07 A0 00 LDY.B #$00 ; Y = 0: start with the 100,000s place
$00:8F09 20 12 90 JSR.W $9012 ; Convert Luigi's score to digit tiles, replacing Mario's ($9012)
$00:8F0C A2 00 LDX.B #$00 ; X = 0: first score digit
$00:8F0E BD 29 0F LDA.W $0F29,X ; Score digit tile [$0F29+X]
$00:8F11 D0 0A BNE $8F1D ; Non-zero: stop blanking
$00:8F13 A9 FC LDA.B #$FC ; \
$00:8F15 9D 29 0F STA.W $0F29,X ; / Leading zero: blank tile ($FC)
$00:8F18 E8 INX ; \
$00:8F19 E0 06 CPX.B #$06 ; |
$00:8F1B D0 F1 BNE $8F0E ; / Next digit
$00:8F1D AD CC 13 LDA.W $13CC ; \
$00:8F20 F0 19 BEQ $8F3B ; / [$13CC] (pending coins) = 0: skip the coin counting
$00:8F22 CE CC 13 DEC.W $13CC ; [$13CC]-- (one coin is added per frame)
$00:8F25 EE BF 0D INC.W RAM_StatusCoins ; Status bar coin counter += 1
$00:8F28 AD BF 0D LDA.W RAM_StatusCoins ; \
$00:8F2B C9 64 CMP.B #$64 ; |
$00:8F2D 90 0C BCC $8F3B ; / Fewer than 100 coins: skip the extra life
$00:8F2F EE E4 18 INC.W $18E4 ; [$18E4]++: give an extra life
$00:8F32 AD BF 0D LDA.W RAM_StatusCoins ; \
$00:8F35 38 SEC ; |
$00:8F36 E9 64 SBC.B #$64 ; |
$00:8F38 8D BF 0D STA.W RAM_StatusCoins ; / Coins -= 100
$00:8F3B AD BE 0D LDA.W RAM_StatusLives ; \
$00:8F3E 30 09 BMI $8F49 ; / Lives negative (game over state): skip
$00:8F40 C9 62 CMP.B #$62 ; \
$00:8F42 90 05 BCC $8F49 ; / Lives below $62: skip the clamp
$00:8F44 A9 62 LDA.B #$62 ; \
$00:8F46 8D BE 0D STA.W RAM_StatusLives ; / Clamp lives to $62 (shown as 99)
$00:8F49 AD BE 0D LDA.W RAM_StatusLives ; \
$00:8F4C 1A INC A ; |
$00:8F4D 20 45 90 JSR.W HexToDec ; / HexToDec of lives + 1 (the displayed number): X = tens, A = ones
$00:8F50 9B TXY ; \
$00:8F51 D0 02 BNE $8F55 ; / Y = tens digit (also sets Z)
$00:8F53 A2 FC LDX.B #$FC ; Tens digit 0: use the blank tile $FC
$00:8F55 8E 16 0F STX.W $0F16 ; \
$00:8F58 8D 17 0F STA.W $0F17 ; / Status bar lives: tens [$0F16], ones [$0F17]
$00:8F5B AE B3 0D LDX.W $0DB3 ; X = current player [$0DB3]
$00:8F5E BD 48 0F LDA.W $0F48,X ; A = this player's bonus stars [$0F48+X]
$00:8F61 C9 64 CMP.B #$64 ; \
$00:8F63 90 0E BCC $8F73 ; / Fewer than 100 bonus stars: skip
$00:8F65 A9 FF LDA.B #$FF ; \
$00:8F67 8D 25 14 STA.W $1425 ; / [$1425] = $FF: play the bonus game when the level ends
$00:8F6A BD 48 0F LDA.W $0F48,X ; \
$00:8F6D 38 SEC ; |
$00:8F6E E9 64 SBC.B #$64 ; |
$00:8F70 9D 48 0F STA.W $0F48,X ; / Bonus stars -= 100
$00:8F73 AD BF 0D LDA.W RAM_StatusCoins ; \
$00:8F76 20 45 90 JSR.W HexToDec ; / HexToDec of the coin counter: X = tens, A = ones
$00:8F79 9B TXY ; \
$00:8F7A D0 02 BNE $8F7E ; / Y = tens digit (also sets Z)
$00:8F7C A2 FC LDX.B #$FC ; Tens digit 0: use the blank tile $FC
$00:8F7E 8D 14 0F STA.W $0F14 ; \
$00:8F81 8E 13 0F STX.W $0F13 ; / Status bar coins: ones [$0F14], tens [$0F13]
$00:8F84 E2 20 SEP #$20 ; A 8-bit
$00:8F86 AE B3 0D LDX.W $0DB3 ; X = current player [$0DB3]
$00:8F89 64 00 STZ $00 ; \
$00:8F8B 64 01 STZ $01 ; |
$00:8F8D 64 03 STZ $03 ; / [$00], [$01], [$03] = 0: clear the high bytes of the 32-bit input
$00:8F8F BD 48 0F LDA.W $0F48,X ; \
$00:8F92 85 02 STA $02 ; / [$02] = this player's bonus stars
$00:8F94 A2 09 LDX.B #$09 ; X = 9: digit tiles at [$0F15 + 9] = $0F1E
$00:8F96 A0 10 LDY.B #$10 ; Y = $10: start at the 10s place
$00:8F98 20 51 90 JSR.W $9051 ; Convert to two digit tiles [$0F1E], [$0F1F] ($9051)
$00:8F9B A2 00 LDX.B #$00 ; X = 0: tens digit
$00:8F9D BD 1E 0F LDA.W $0F1E,X ; Digit tile [$0F1E+X]
$00:8FA0 D0 0D BNE $8FAF ; Non-zero: go draw the big digits
$00:8FA2 A9 FC LDA.B #$FC ; \
$00:8FA4 9D 1E 0F STA.W $0F1E,X ; |
$00:8FA7 9D 03 0F STA.W $0F03,X ; / Tens digit 0: blank both halves, [$0F1E] and [$0F03] = $FC
$00:8FAA E8 INX ; \
$00:8FAB E0 01 CPX.B #$01 ; |
$00:8FAD D0 EE BNE $8F9D ; / X = 1: fall through and draw only the ones digit
$00:8FAF BD 1E 0F LDA.W $0F1E,X ; \
$00:8FB2 0A ASL ; |
$00:8FB3 A8 TAY ; |
$00:8FB4 B9 06 8E LDA.W $8E06,Y ; |
$00:8FB7 9D 03 0F STA.W $0F03,X ; |
$00:8FBA B9 07 8E LDA.W $8E07,Y ; |
$00:8FBD 9D 1E 0F STA.W $0F1E,X ; / Big digit: top [$0F03+X] and bottom [$0F1E+X] tiles from the table at $8E06
$00:8FC0 E8 INX ; \
$00:8FC1 E0 02 CPX.B #$02 ; |
$00:8FC3 D0 EA BNE $8FAF ; / Next digit until X = 2
$00:8FC5 20 79 90 JSR.W $9079 ; Draw the item box sprite ($9079)
$00:8FC8 AD B3 0D LDA.W $0DB3 ; \
$00:8FCB F0 0B BEQ $8FD8 ; / Mario ([$0DB3] = 0): keep the name MARIO
$00:8FCD A2 04 LDX.B #$04 ; X = 4: five name tiles
$00:8FCF BD F5 8D LDA.W $8DF5,X ; \
$00:8FD2 9D F9 0E STA.W $0EF9,X ; |
$00:8FD5 CA DEX ; |
$00:8FD6 10 F7 BPL $8FCF ; / Copy the LUIGI tiles from $8DF5 to [$0EF9]-[$0EFD]
$00:8FD8 AD 22 14 LDA.W $1422 ; \
$00:8FDB C9 05 CMP.B #$05 ; |
$00:8FDD 90 02 BCC $8FE1 ; / Fewer than 5 Yoshi coins ([$1422]): use the count
$00:8FDF A9 00 LDA.B #$00 ; 5 or more: count = 0 (no icons)
$00:8FE1 3A DEC A ; \
$00:8FE2 85 00 STA $00 ; / [$00] = count - 1: slot X shows a coin while [$00] is not negative
$00:8FE4 A2 00 LDX.B #$00 ; X = 0: first Yoshi coin slot
$00:8FE6 A0 FC LDY.B #$FC ; Y = $FC: blank tile
$00:8FE8 A5 00 LDA $00 ; \
$00:8FEA 30 02 BMI $8FEE ; |
$00:8FEC A0 2E LDY.B #$2E ; / [$00] negative: blank; otherwise Y = $2E (Yoshi coin tile)
$00:8FEE 98 TYA ; \
$00:8FEF 9D FF 0E STA.W $0EFF,X ; / Store the tile in the row 1 buffer [$0EFF+X]
$00:8FF2 C6 00 DEC $00 ; \
$00:8FF4 E8 INX ; |
$00:8FF5 E0 04 CPX.B #$04 ; |
$00:8FF7 D0 ED BNE $8FE6 ; / [$00]--, next slot, four slots in total
$00:8FF9 60 RTS ; Return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;6-digit HexToDec. Mainly to display the 6-digit (7-digits if you include the rightmost static 0) score counter.
;;Technically, this is 32-bit (using 2 16-bit subtraction for the low word and high word), however, up to 999,999
;;can be displayed correctly.
;;
;;SMW's score is stored internally as a 6-digit number, but is displayed as a 7-digit number with the last digit "0" being static
;;and not being part of this number (123456 would be displayed as "1234560"). To avoid confusion I refer this 6-digit number
;;as "InternalScore"
;;
;;How this works, explained using variables and formulas:
;; n = the digit place value, n=0 is 1s place, n=1 = 10s place, n=2 is the 100s place..., n=5 is the 100,000s place.
;; D[n] = array of digits (also the number of successful subtractions). For example, if InternalScore = $1E240 (123456 in decimal), then:
;; D[0] = 6 (1s place)
;; D[1] = 5 (10s place)
;; D[2] = 4 (...)
;; D[3] = 3
;; D[4] = 2
;; D[5] = 1 (100,000s)
;;SMW converts this number to BCD like this:
;; 1) Start at the leftmost digit (start with n=5)
;; 2) Set D[n] = 0. Meaning this digit will start at 0.
;; 3) Subtract this number by [10^n]
;; 4) If the difference do not go below 0, use this difference as the next minuend, increment D[n] by 1, go to step 3 and continue.
;; 5) If the difference did go below 0, decrement n by 1, and use the same minuend.
;; 6) If n >= 0, go to step 2 and continue.
;;
;;Example: $1E240 (123456)
;;Process digit 5 (subtract by $186A0 (100000) repeatedly):
;;$1E240 (123456, NumbOfSubtracts=0) ->
;; $5BA0 ( 23456, NumbOfSubtracts=1, less than 100000), so digit 5 = 1
;;
;;Process digit 4 (subtract by $2710 (10000) repeatedly):
;; $5BA0 (23456, NumbOfSubtracts=0) ->
;; $3490 (13456, NumbOfSubtracts=1) ->
;; $D80 ( 3456, NumbOfSubtracts=2, less than 10000), so digit 4 = 2
;;
;;Process digit 3 (subtract by $3E8 (1000) repeatedly):
;; $D80 (3456, NumbOfSubtracts=0) ->
;; $998 (2456, NumbOfSubtracts=1) ->
;; $5B0 (1456, NumbOfSubtracts=2) ->
;; $1C8 ( 456, NumbOfSubtracts=3, less than 1000), so digit 3 = 3
;;
;;Process digit 2 (subtract by $64 (100) repeatedly):
;; $1C8 (456, NumbOfSubtracts=0) ->
;; $164 (356, NumbOfSubtracts=1) ->
;; $100 (256, NumbOfSubtracts=2) ->
;; $9C (156, NumbOfSubtracts=3) ->
;; $38 ( 56, NumbOfSubtracts=4, less than 100), so digit 2 = 4
;;
;;Process digit 1 (subtract by $A (10) repeatedly):
;; $38 (56, NumbOfSubtracts=0) ->
;; $2E (46, NumbOfSubtracts=1) ->
;; $24 (36, NumbOfSubtracts=2) ->
;; $1A (26, NumbOfSubtracts=3) ->
;; $10 (16, NumbOfSubtracts=4) ->
; $6 ( 6, NumbOfSubtracts=5, less than 10), so digit 1 = 5
;;
;;Process digit 0 (subtract by $1 (1) repeatedly):
;; $6 (6, NumbOfSubtracts=0) ->
;; $5 (5, NumbOfSubtracts=1) ->
;; $4 (4, NumbOfSubtracts=2) ->
;; $3 (3, NumbOfSubtracts=3) ->
;; $2 (2, NumbOfSubtracts=4) ->
;; $1 (1, NumbOfSubtracts=5) ->
;; $0 (0, NumbOfSubtracts=6, less than 1), so digit 0 = 6
;;
;;In summary, this is the "left-to-right" version of this: https://en.wikipedia.org/wiki/Positional_notation#Base_conversion
;;Which in that link, you divide by 10 (using euclidean division; Q and R) repeatedly and each time, the remainder is the
;;digit of the result (starting at the ones place), while the quotient is the next dividend to be divided by 10 and repeats.
;;
;; Using the same example above via the right-to-left method:
;; $1E240/10 = Q: $3039, R: 6 (1s)
;; $3039/10 = Q: $4D2, R: 5 (10s)
;; $4D2/10 = Q: $7B, R: 4 (100s)
;; $7B/10 = Q: $C R: 3 (1,000s)
;; $C/10 = Q: $1 R: 2 (10,000s)
;; $1/10 = Q: $0 R: 1 (100,000s)
;; ...
;;
;;This method handles the 100,000s place first, and works its towards the 1s place. Instead of dividing by 10^n where n
;;increases (you divided by 10 repeatedly, which is x/(10^n)), you divide by 10^n as n decreases. SMW (nor the SNES) does not have a
;;32-bit division routine/register, so repeated subtraction is used to emulate the euclidean division (Q = number of successful
;;subtraction, R: Number to be subtracted by lower powers of ten). Each remainder in the loop after it cannot subtract is then
;;reused to subtract by 10^(n-1), therefore this entire hexdec is one big long division.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; $8FFA..8FFC: Table: powers of ten for decimal conversion ;;;
;; Six 32-bit entries (high word, low word): 100,000, 10,000, 1,000, 100, 10, 1. Used with Y = 4 * entry by
;; the routines at $009012 and $009051.
$00:8FFA dw $0001 ; Powers of ten, 32-bit: 100,000 high word $0001 (entries are 4 bytes: high, low)
$00:8FFC dw $86A0 ; 100,000 low word $86A0 (followed by 10,000, 1,000, 100, 10 and 1)
; dw $0000 ;>10,000s (high word) ;>Index_008FFA = $04 Index_008FFC = $02
; dw $2710 ;>10,000s (low word) ;>Index_008FFA = $06 Index_008FFC = $04
; dw $0000 ;>1,000s (high word) ;>Index_008FFA = $08 Index_008FFC = $06
; dw $03E8 ;>1,000s (low word) ;>Index_008FFA = $0A Index_008FFC = $08
; dw $0000 ;>100s (high word) ;>Index_008FFA = $0C Index_008FFC = $0A
; dw $0064 ;>100s (low word) ;>Index_008FFA = $0E Index_008FFC = $0C
; dw $0000 ;>10s (high word) ;>Index_008FFA = $10 Index_008FFC = $0E
; dw $000A ;>10s (low word) ;>Index_008FFA = $12 Index_008FFC = $10
; dw $0000 ;>1s (high word) ;>Index_008FFA = $14 Index_008FFC = $12
; dw $0001 ;>1s (low word) ;>Index_008FFA = $16 Index_008FFC = $14
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Here:
;;*$00-$01: High word (word = 2 bytes; 16-bit) of subtrahend that shouldn't underflow
;;*$02-$03: Low word of subtrahend that shouldn't underflow
;;*$04-$05: High word of subtrahend that can underflow (use as a preview if the next subtraction underflows)
;;*$06-$07: Low word of subtrahend that can underflow (use as a preview if the next subtraction underflows)
;;*STZ.W $0F15,X is D[n] = 0 before each digit processing
;;*INC.W $0F15 is D[n] being incremented of how many times you can subtract without going in the negatives.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; $9012: Convert 32-bit value to six decimal digit tiles ;;;
;; Counts how many times each power of ten can be subtracted from the 32-bit value, one tile per digit (left
;; to right).
;; Parameters: [$00]-[$01] high word, [$02]-[$03] low word of the value; X = offset into the tile buffer
;; [$0F15]; Y = 0 (start at 100,000s).
;; Returns: digit tiles at [$0F15+X]...; the value variables are destroyed.
;; Called by:
;; $00:8EDB: Status bar: update counters and tiles (DMAdata_StBr2)
;; $00:8F09: Status bar: update counters and tiles (DMAdata_StBr2)
$00:9012 E2 20 SEP #$20 ; A 8-bit
$00:9014 9E 15 0F STZ.W $0F15,X ; Digit tile [$0F15+X] = 0
$00:9017 C2 20 REP #$20 ; A 16-bit
$00:9019 A5 02 LDA $02 ; \
$00:901B 38 SEC ; |
$00:901C F9 FC 8F SBC.W $8FFC,Y ; |
$00:901F 85 06 STA $06 ; / [$06] = [$02] - low word of 10^n (SBC $8FFC,Y)
$00:9021 A5 00 LDA $00 ; \
$00:9023 F9 FA 8F SBC.W $8FFA,Y ; |
$00:9026 85 04 STA $04 ; / [$04] = [$00] - high word of 10^n - borrow (SBC $8FFA,Y)
$00:9028 90 0F BCC $9039 ; Borrow (value < 10^n): this digit is finished
$00:902A A5 06 LDA $06 ; \
$00:902C 85 02 STA $02 ; |
$00:902E A5 04 LDA $04 ; |
$00:9030 85 00 STA $00 ; / Value = difference
$00:9032 E2 20 SEP #$20 ; A 8-bit
$00:9034 FE 15 0F INC.W $0F15,X ; Digit tile [$0F15+X]++ (counts the successful subtractions)
$00:9037 80 DE BRA $9017 ; Subtract again
$00:9039 E8 INX ; Next digit tile: X++
$00:903A C8 INY ; \
$00:903B C8 INY ; |
$00:903C C8 INY ; |
$00:903D C8 INY ; / Y += 4: next power of ten
$00:903E C0 18 CPY.B #$18 ; \
$00:9040 D0 D0 BNE $9012 ; / Y = $18 (past the ones place)? No: next digit
$00:9042 E2 20 SEP #$20 ; A 8-bit
$00:9044 60 RTS ; Return
;This is the 8-bit Hex->Dec, ideal for 2-digit counters.
;you could make this 3-digits by calling this routine again
;after writing the 1s and 10s by taking the X, TXA it, then
;call this, and then A should now be the hundreds digit (0-2)
;with Y always 0 (up to 0255).
;;; $9045: Hex to decimal and item box drawing (HexToDec) ;;;
;; $009045: converts A (0-99) to decimal by repeated subtraction. Returns: X = tens, A = ones.
;; $009051: 16-bit version of the routine above, used for the bonus star counter. Parameters: [$02] value, X =
;; tile offset ([$0F15+X]), Y = 4 * first power of ten (Y = $10 gives two digits).
;; $009079: draws the item box sprite (reserve item [$0DC2]) at X = $78, Y = $0F as a 16x16 sprite; the star
;; flashes through palettes. Hides OAM slot 0 in Mode 7 boss rooms.
;; Called by:
;; $00:8F4D: Status bar: update counters and tiles (DMAdata_StBr2)
;; $00:8F76: Status bar: update counters and tiles (DMAdata_StBr2)
;; $00:974C: Game mode 11: Mario Start, level music (MarioStartGameMode)
;; $00:9D76: Game mode 08: file select, mode 0A: players
$00:9045 A2 00 LDX.B #$00 ; X = 0: tens counter
$00:9047 C9 0A CMP.B #$0A ; \
$00:9049 90 05 BCC $9050 ; / A < 10: done, A = ones digit
$00:904B E9 0A SBC.B #$0A ; \
$00:904D E8 INX ; |
$00:904E 80 F7 BRA $9047 ; / A -= 10; X++; repeat
$00:9050 60 RTS ; Return: A = ones, X = tens
;Bonus stars Hex->Dec. I do not know why Nintendo decided to use this
;same Hex->Dec as the score since bonus stars are never to display 3-digits.
;Routine starts with Y=$10, X=$09.
$00:9051 E2 20 SEP #$20 ; A 8-bit
$00:9053 9E 15 0F STZ.W $0F15,X ; Digit tile [$0F15+X] = 0
$00:9056 C2 20 REP #$20 ; A 16-bit
$00:9058 A5 02 LDA $02 ; \
$00:905A 38 SEC ; |
$00:905B F9 FC 8F SBC.W $8FFC,Y ; |
$00:905E 85 06 STA $06 ; / [$06] = [$02] - low word of 10^n
$00:9060 90 0B BCC $906D ; Borrow: this digit is finished
$00:9062 A5 06 LDA $06 ; \
$00:9064 85 02 STA $02 ; / Value = difference
$00:9066 E2 20 SEP #$20 ; A 8-bit
$00:9068 FE 15 0F INC.W $0F15,X ; Digit tile [$0F15+X]++
$00:906B 80 E9 BRA $9056 ; Subtract again
$00:906D E8 INX ; Next digit tile: X++
$00:906E C8 INY ; \
$00:906F C8 INY ; |
$00:9070 C8 INY ; |
$00:9071 C8 INY ; / Y += 4: next power of ten
$00:9072 C0 18 CPY.B #$18 ; \
$00:9074 D0 DB BNE $9051 ; / Until Y = $18 (past the ones place)
$00:9076 E2 20 SEP #$20 ; A 8-bit
$00:9078 60 RTS ; Return
$00:9079 A0 E0 LDY.B #$E0 ; Y = $E0: OAM offset of the item box sprite
$00:907B 2C 9B 0D BIT.W $0D9B ; V = [$0D9B] bit 6 (Mode 7 boss room)
$00:907E 50 0E BVC $908E ; Not a boss room: keep Y = $E0
$00:9080 A0 00 LDY.B #$00 ; Boss room: use OAM slot 0
$00:9082 AD 9B 0D LDA.W $0D9B ; \
$00:9085 C9 C1 CMP.B #$C1 ; |
$00:9087 F0 05 BEQ $908E ; / Bowser ([$0D9B] = $C1): leave slot 0 alone
$00:9089 A9 F0 LDA.B #$F0 ; \
$00:908B 99 01 02 STA.W OAM_ExtendedDispY,Y ; / Hide the sprite in slot 0 (Y = $F0), it is only shown when the box holds an item
$00:908E 84 01 STY $01 ; [$01] = OAM offset of the item box sprite
$00:9090 AC C2 0D LDY.W $0DC2 ; \
$00:9093 F0 3B BEQ $90D0 ; / Y = item box item [$0DC2]; 0 = empty: return
$00:9095 B9 01 8E LDA.W $8E01,Y ; \
$00:9098 85 00 STA $00 ; / [$00] = palette bits for this item ($8E01)
$00:909A C0 03 CPY.B #$03 ; \
$00:909C D0 0D BNE $90AB ; / Not the star: keep it
$00:909E A5 13 LDA RAM_FrameCounter ; \
$00:90A0 4A LSR ; |
$00:90A1 29 03 AND.B #$03 ; |
$00:90A3 5A PHY ; |
$00:90A4 A8 TAY ; |
$00:90A5 B9 FE 8D LDA.W $8DFE,Y ; |
$00:90A8 7A PLY ; |
$00:90A9 85 00 STA $00 ; / Star: palette bits cycle through $8DFE every 2 frames ([$13] >> 1 AND 3)
$00:90AB A4 01 LDY $01 ; Y = OAM offset
$00:90AD A9 78 LDA.B #$78 ; \
$00:90AF 99 00 02 STA.W OAM_ExtendedDispX,Y ; / Sprite X = $78
$00:90B2 A9 0F LDA.B #$0F ; \
$00:90B4 99 01 02 STA.W OAM_ExtendedDispY,Y ; / Sprite Y = $0F
$00:90B7 A9 30 LDA.B #$30 ; \
$00:90B9 05 00 ORA $00 ; |
$00:90BB 99 03 02 STA.W OAM_ExtendedProp,Y ; / Properties = $30 (priority 3) | palette bits [$00]
$00:90BE AE C2 0D LDX.W $0DC2 ; \
$00:90C1 BD F9 8D LDA.W $8DF9,X ; |
$00:90C4 99 02 02 STA.W OAM_ExtendedTile,Y ; / Tile = $8DF9[item]
$00:90C7 98 TYA ; \
$00:90C8 4A LSR ; |
$00:90C9 4A LSR ; |
$00:90CA A8 TAY ; |
$00:90CB A9 02 LDA.B #$02 ; |
$00:90CD 99 20 04 STA.W $0420,Y ; / OAM size table [$0420 + OAM offset / 4] = 2: 16x16 sprite, X bit 8 clear
$00:90D0 60 RTS ; Return
;;; $90D1..9101: Table: text sprite tiles, upper half ;;;
;; Indexed by text column ($91E9). Probably the letters of the Mario Start! / bonus game messages; $FF =
;; blank column.
$00:90D1 .db $00,$FF,$4D,$4C,$03,$4D,$5D,$FF ; Tile numbers of the upper sprite of each text column; $FF = blank column
$00:90D9 .db $03,$00,$4C,$03,$04,$15,$00,$02
$00:90E1 .db $00,$4A,$4E,$FF,$4C,$4B,$4A,$03
$00:90E9 .db $5F,$05,$04,$03,$02,$00,$FF,$01
$00:90F1 .db $4A,$5F,$05,$04,$00,$4D,$5D,$03
$00:90F9 .db $02,$01,$00,$FF,$5B,$14,$5F,$01
$00:9101 .db $5E,$FF,$FF,$FF
;;; $9105..9135: Table: text sprite tiles, lower half ;;;
;; Same indexes as $90D1; tile of the sprite drawn 8 pixels below the upper one.
$00:9105 .db $10,$FF,$00,$5C,$13,$00,$5D,$FF ; Tile numbers of the lower sprite of each text column
$00:910D .db $03,$00,$5C,$13,$14,$15,$00,$12
$00:9115 .db $00,$03,$5E,$FF,$5C,$4B,$5A,$03
$00:911D .db $5F,$05,$14,$13,$12,$10,$FF,$11
$00:9125 .db $03,$5F,$05,$14,$00,$00,$5D,$03
$00:912D .db $12,$11,$10,$FF,$5B,$01,$5F,$01
$00:9135 .db $5E,$FF,$FF,$FF
;;; $9139..9169: Table: text sprite properties, upper half ;;;
$00:9139 .db $34,$00,$34,$34,$34,$34,$30,$00 ; Properties of the upper sprite of each text column
$00:9141 .db $34,$34,$34,$34,$74,$34,$34,$34
$00:9149 .db $34,$34,$34,$00,$34,$34,$34,$34
$00:9151 .db $34,$34,$34,$34,$34,$34,$00,$34
$00:9159 .db $34,$34,$34,$34,$34,$34,$34,$34
$00:9161 .db $34,$34,$34,$34,$34,$34,$34,$34
$00:9169 .db $34
;;; $916A..919A: Table: text sprite properties, lower half ;;;
;; Mostly the upper values with the Y flip bit set, so the lower sprite looks like a mirrored copy of the
;; upper one (probably a reflection).
$00:916A .db $34,$00,$B4,$34,$34,$B4,$F0,$00 ; Properties of the lower sprite of each text column (Y flip set in most)
$00:9172 .db $B4,$B4,$34,$34,$74,$B4,$B4,$34
$00:917A .db $B4,$B4,$34,$00,$34,$B4,$34,$B4
$00:9182 .db $B4,$B4,$34,$34,$34,$34,$00,$34
$00:918A .db $B4,$B4,$B4,$34,$B4,$B4,$B4,$B4
$00:9192 .db $34,$34,$34,$34,$F4,$B4,$F4,$B4
$00:919A .db $B4
;;; $919B: Mario Start text and level setup helpers ;;;
;; $00919B: during Mario animation $0A runs the Mario animation handler; otherwise sets [$0DC0] = $1E when
;; [$141A] is 0 (purpose unclear).
;; $0091B1: draws the "Mario Start!" / "Luigi Start!" text (or the bonus game text when [$1425] is set, which
;; also zeroes the timer) as 14 columns of two sprites.
;; $0091E9: draws one text column from the tables at $0090D1-$00916A at X position [$00] and steps [$00] left
;; by 8.
;; Called by:
;; $00:A5F0: Game mode 12: prepare level (GM04Load)
$00:919B A5 71 LDA RAM_MarioAnimation ; \
$00:919D C9 0A CMP.B #$0A ; |
$00:919F D0 05 BNE $91A6 ; / Mario animation [$71] != $0A: continue below
$00:91A1 20 93 C5 JSR.W $C593 ; Run the Mario animation routine for [$71] ($C593)
$00:91A4 80 0A BRA $91B0 ; Return
$00:91A6 AD 1A 14 LDA.W $141A ; \
$00:91A9 D0 05 BNE $91B0 ; / [$141A] != 0: return
$00:91AB A9 1E LDA.B #$1E ; \
$00:91AD 8D C0 0D STA.W $0DC0 ; / [$0DC0] = $1E (purpose unclear)
$00:91B0 60 RTS ; Return
$00:91B1 20 2D A8 JSR.W $A82D ; Prepare the text graphics in RAM ($A82D), probably the Mario Start! font
$00:91B4 A2 00 LDX.B #$00 ; X = 0: index of the first text column
$00:91B6 A9 B0 LDA.B #$B0 ; A = $B0: X position of the first (rightmost) column
$00:91B8 AC 25 14 LDY.W $1425 ; \
$00:91BB F0 0D BEQ $91CA ; / [$1425] = 0: normal text, skip the bonus game setup
$00:91BD 9C 31 0F STZ.W $0F31 ; \
$00:91C0 9C 32 0F STZ.W $0F32 ; |
$00:91C3 9C 33 0F STZ.W $0F33 ; / Bonus game: time = 000
$00:91C6 A2 26 LDX.B #$26 ; X = $26: start index of the bonus game text
$00:91C8 A9 A4 LDA.B #$A4 ; A = $A4: X position of its first column
$00:91CA 85 00 STA $00 ; \
$00:91CC 64 01 STZ $01 ; / [$00]-[$01] = X position of the current column (16-bit)
$00:91CE A0 70 LDY.B #$70 ; Y = $70: OAM offset of the first column (counts down by 8)
$00:91D0 20 E9 91 JSR.W $91E9 ; Draw one text column (two sprites) ($91E9)
$00:91D3 E8 INX ; Next column index: X++
$00:91D4 E0 08 CPX.B #$08 ; \
$00:91D6 D0 07 BNE $91DF ; / X != 8: keep going
$00:91D8 AD B3 0D LDA.W $0DB3 ; \
$00:91DB F0 02 BEQ $91DF ; / Mario ([$0DB3] = 0): continue with the same indexes
$00:91DD A2 0E LDX.B #$0E ; Luigi: jump to index $0E, which probably holds the LUIGI letters
$00:91DF 98 TYA ; \
$00:91E0 38 SEC ; |
$00:91E1 E9 08 SBC.B #$08 ; |
$00:91E3 A8 TAY ; / Y -= 8: OAM offset of the next column
$00:91E4 D0 EA BNE $91D0 ; Loop for all 14 columns
$00:91E6 4C 94 84 JMP.W $8494 ; Pack the OAM size bits and return ($8494)
$00:91E9 BD 39 91 LDA.W $9139,X ; \
$00:91EC 99 0B 03 STA.W OAM_Tile3Prop,Y ; / Upper sprite properties = $9139[X]
$00:91EF BD 6A 91 LDA.W $916A,X ; \
$00:91F2 99 0F 03 STA.W OAM_Tile4Prop,Y ; / Lower sprite properties = $916A[X]
$00:91F5 A5 00 LDA $00 ; \
$00:91F7 99 08 03 STA.W OAM_Tile3DispX,Y ; |
$00:91FA 99 0C 03 STA.W OAM_Tile4DispX,Y ; / X position of both sprites = [$00]
$00:91FD 38 SEC ; \
$00:91FE E9 08 SBC.B #$08 ; |
$00:9200 85 00 STA $00 ; |
$00:9202 B0 02 BCS $9206 ; |
$00:9204 C6 01 DEC $01 ; / [$00]-[$01] -= 8 (16-bit): next column is 8 pixels to the left
$00:9206 5A PHY ; Save Y
$00:9207 98 TYA ; \
$00:9208 4A LSR ; |
$00:9209 4A LSR ; |
$00:920A A8 TAY ; / Y = OAM offset / 4
$00:920B A5 01 LDA $01 ; \
$00:920D 29 01 AND.B #$01 ; |
$00:920F 99 62 04 STA.W $0462,Y ; |
$00:9212 99 63 04 STA.W $0463,Y ; / X bit 8 ([$01] bit 0) into the OAM size table for both sprites ($0462 and $0463 + Y)
$00:9215 7A PLY ; Restore Y
$00:9216 BD D1 90 LDA.W $90D1,X ; \
$00:9219 30 13 BMI $922E ; / Upper tile = $90D1[X]; bit 7 set = blank column, return
$00:921B 99 0A 03 STA.W OAM_Tile3,Y ; Upper sprite tile
$00:921E BD 05 91 LDA.W $9105,X ; \
$00:9221 99 0E 03 STA.W OAM_Tile4,Y ; / Lower sprite tile = $9105[X]
$00:9224 A9 68 LDA.B #$68 ; \
$00:9226 99 09 03 STA.W OAM_Tile3DispY,Y ; / Upper sprite Y = $68
$00:9229 A9 70 LDA.B #$70 ; \
$00:922B 99 0D 03 STA.W OAM_Tile4DispY,Y ; / Lower sprite Y = $70
$00:922E 60 RTS ; Return
; | |
; V This code is kinda finishing and finalizing showing the Nitendo Presents. V
;;; $922F: Set CGRAM color 0 to black by DMA (NintenDMAINIT) ;;;
;; Clears the palette mirror word [$0703] and DMAs it into CGRAM color 0 with channel 2. Used at the Nintendo
;; Presents screen and the ending.
;; Called by:
;; $00:93E0: Game mode 00: load Nintendo Presents (NintendoTile)
;; $00:94DD: Cutscene, ending and game mode code (castle scenes, credits, game over) (CutsceneCastlePal)
;; $00:9612: Cutscene, ending and game mode code (castle scenes, credits, game over) (CutsceneCastlePal)
;; $00:9675: Cutscene, ending and game mode code (castle scenes, credits, game over) (CutsceneCastlePal)
;; $00:9AA1: Detect connected controllers into [$0DA0] (SetUp0DA0GM4)
;; $00:A150: Game mode 0C: load overworld (LoadMapGameMode)
;; $00:A5CF: Game mode 12: prepare level (GM04Load)
$00:922F 9C 03 07 STZ.W $0703 ; \
$00:9232 9C 04 07 STZ.W $0704 ; / Palette mirror word [$0703] = $0000 (black)
$00:9235 9C 21 21 STZ.W $2121 ; CGRAM address = 0
$00:9238 A2 06 LDX.B #$06 ; X = 6: seven bytes of DMA setup
$00:923A BD 49 92 LDA.W $9249,X ; \
$00:923D 9D 20 43 STA.W $4320,X ; |
$00:9240 CA DEX ; |
$00:9241 10 F7 BPL $923A ; / Copy $9249 to DMA channel 2 registers $4320-$4326
$00:9243 A9 04 LDA.B #$04 ; \
$00:9245 8D 0B 42 STA.W $420B ; / Start DMA channel 2: copy [$0703] to CGRAM color 0
$00:9248 60 RTS ; Return
;;; $9249..9249: Table: DMA setup for black backdrop ;;;
$00:9249 .db $00,$22,$03,$07,$00,$00,$02 ; DMAP $00, B-bus $22 (CGDATA), source $00:0703, size $0002
;;; $9250: Init HDMA window effect (channel 7) ;;;
;; Sets up HDMA channel 7 to write the window registers WH0/WH1 from an indirect table, disables all HDMA
;; ([$0D9F] = 0) and fills the window table
;; at $04A0-$065F (224 lines of left, right) with left = $FF, right = $00 so no screen area is inside the
;; window.
;; $009260 is the entry used to just disable HDMA, $009263 clears the table only.
$00:9250 A2 04 LDX.B #$04 ; X = 4: five bytes of HDMA channel 7 setup
$00:9252 BD 77 92 LDA.W $9277,X ; \
$00:9255 9D 70 43 STA.W $4370,X ; |
$00:9258 CA DEX ; |
$00:9259 10 F7 BPL $9252 ; / Copy $9277 to $4370-$4374: indirect window table at $00:927C
$00:925B A9 00 LDA.B #$00 ; \
$00:925D 8D 77 43 STA.W $4377 ; / HDMA channel 7 indirect bank $4377 = $00
$00:9260 9C 9F 0D STZ.W $0D9F ; Disable all HDMA channels ([$0D9F] = 0)
$00:9263 C2 10 REP #$10 ; Index 16-bit
$00:9265 A2 BE 01 LDX.W #$01BE ; X = $01BE: offset of the last of 224 line entries
$00:9268 A9 FF LDA.B #$FF ; A = $FF
$00:926A 9D A0 04 STA.W $04A0,X ; \
$00:926D 9E A1 04 STZ.W $04A1,X ; |
$00:9270 CA DEX ; |
$00:9271 CA DEX ; |
$00:9272 10 F6 BPL $926A ; / Window table at $04A0-$065F: every line left = $FF, right = $00 (empty window)
$00:9274 E2 10 SEP #$10 ; \
$00:9276 60 RTS ; / Index 8-bit and return
;;; $9277..927F: HDMA setup and table: window effect ;;;
$00:9277 .db $41,$26,$7C,$92,$00,$F0,$A0,$04 ; HDMA channel 7: DMAP $41 (indirect, two registers), B-bus $26 (WH0/WH1), table $00:927C
$00:927F .db $F0,$80,$05,$00 ; Table end: $F0 = 112 lines from $0580, then $00 (the entry at $00927C is $F0 = 112 lines from $04A0)
;;; $9283: Window HDMA: enable fully covered window ;;;
;; Clears the window table, then (unless [$0D9B] bit 0 is set) fills the last line with a window covering the
;; whole line and enables channel 7.
;; Called by:
;; $00:9A1C: Boss room tile animation and Mode 7 setup
$00:9283 20 63 92 JSR.W $9263 ; Clear the window table ($9263)
$00:9286 AD 9B 0D LDA.W $0D9B ; \
$00:9289 4A LSR ; |
$00:928A B0 14 BCS $92A0 ; / [$0D9B] bit 0 set: skip opening the window, just enable HDMA ($0092A0)
$00:928C C2 10 REP #$10 ; Index 16-bit
$00:928E A2 BE 01 LDX.W #$01BE ; X = $01BE: last line entry
;;; $9291: Fill window table lines, set up scroll HDMA (WindowHDMAenable) ;;;
;; $009291: loop that writes left = $00, right = $FF entries from offset X upwards to the end of the window
;; table, then enables HDMA channel 7 ([$0D9F] = $80).
;; $0092A8: clears the table and opens the last 20 lines through the loop above.
;; $0092B2: used in the ending (game mode $23). Sets up HDMA channels 5-7 to write BG1, BG2 and BG3 horizontal
;; scroll per scanline from tables at $04A0, $04AA, $04B4
;; (10 bytes each: 88-line segments with the scroll words taken from [$1A], [$1E], [$22] and [$1462]...);
;; enables channels 5-7 ([$0D9F] = $E0).
$00:9291 9E A0 04 STZ.W $04A0,X ; Left edge of this line = $00
$00:9294 A9 FF LDA.B #$FF ; \
$00:9296 9D A1 04 STA.W $04A1,X ; / Right edge = $FF: the line is fully covered by the window
$00:9299 E8 INX ; \
$00:929A E8 INX ; / X += 2: next line
$00:929B E0 C0 01 CPX.W #$01C0 ; \
$00:929E 90 F1 BCC WindowHDMAenable ; / Loop until X >= $01C0
$00:92A0 A9 80 LDA.B #$80 ; \
$00:92A2 8D 9F 0D STA.W $0D9F ; / Enable HDMA channel 7 only ([$0D9F] = $80)
$00:92A5 E2 10 SEP #$10 ; Index 8-bit
$00:92A7 60 RTS ; Return
$00:92A8 20 63 92 JSR.W $9263 ; Clear the window table ($9263)
$00:92AB C2 10 REP #$10 ; Index 16-bit
$00:92AD A2 98 01 LDX.W #$0198 ; X = $0198: line 204, so the last 20 lines are opened
$00:92B0 80 DF BRA WindowHDMAenable ; Fill them with the fully covered window above
$00:92B2 A9 58 LDA.B #$58 ; A = $58: line count (88 lines) of the first segment of each table
$00:92B4 8D A0 04 STA.W $04A0 ; \
$00:92B7 8D AA 04 STA.W $04AA ; |
$00:92BA 8D B4 04 STA.W $04B4 ; / First byte of the tables at $04A0, $04AA and $04B4 = $58
$00:92BD 9C A9 04 STZ.W $04A9 ; \
$00:92C0 9C B3 04 STZ.W $04B3 ; |
$00:92C3 9C BD 04 STZ.W $04BD ; / Last byte of each 10-byte table = 0 (end of HDMA table)
$00:92C6 A2 04 LDX.B #$04 ; X = 4: five setup bytes per channel
$00:92C8 BD 13 93 LDA.W $9313,X ; \
$00:92CB 9D 50 43 STA.W $4350,X ; / Channel 5 setup byte X from $9313
$00:92CE BD 18 93 LDA.W $9318,X ; \
$00:92D1 9D 60 43 STA.W $4360,X ; / Channel 6 setup byte X from $9318
$00:92D4 BD 1D 93 LDA.W $931D,X ; \
$00:92D7 9D 70 43 STA.W $4370,X ; / Channel 7 setup byte X from $931D
$00:92DA CA DEX ; X--
$00:92DB 10 EB BPL $92C8 ; Loop for all five bytes
$00:92DD A9 00 LDA.B #$00 ; \
$00:92DF 8D 57 43 STA.W $4357 ; |
$00:92E2 8D 67 43 STA.W $4367 ; |
$00:92E5 8D 77 43 STA.W $4377 ; / Indirect banks of channels 5-7 ($4357, $4367, $4377) = $00 (unused in direct mode)
$00:92E8 A9 E0 LDA.B #$E0 ; \
$00:92EA 8D 9F 0D STA.W $0D9F ; / Enable HDMA channels 5, 6 and 7 ([$0D9F] = $E0)
$00:92ED C2 30 REP #$30 ; A and index 16-bit
$00:92EF A0 08 00 LDY.W #$0008 ; Y = 8: offset of BG3's scroll ([$1A] + 8 = [$22])
$00:92F2 A2 14 00 LDX.W #$0014 ; X = $14: offset of the BG3 table ($04B4 - $04A0)
$00:92F5 B9 1A 00 LDA.W RAM_ScreenBndryXLo,Y ; \
$00:92F8 9D A1 04 STA.W $04A1,X ; |
$00:92FB 9D A4 04 STA.W $04A4,X ; / Segments 1 and 2 scroll = [$1A+Y] (BG1 [$1A], BG2 [$1E], BG3 [$22] horizontal scroll)
$00:92FE B9 62 14 LDA.W $1462,Y ; \
$00:9301 9D A7 04 STA.W $04A7,X ; / Segment 3 scroll = [$1462+Y]
$00:9304 8A TXA ; \
$00:9305 38 SEC ; |
$00:9306 E9 0A 00 SBC.W #$000A ; |
$00:9309 AA TAX ; / X -= $0A: previous 10-byte table
$00:930A 88 DEY ; \
$00:930B 88 DEY ; |
$00:930C 88 DEY ; |
$00:930D 88 DEY ; / Y -= 4: previous layer
$00:930E 10 E5 BPL $92F5 ; Loop for the three layers
$00:9310 E2 30 SEP #$30 ; A and index 8-bit
$00:9312 60 RTS ; Return
;;; $9313..931D: Table: HDMA setup for BG scroll channels ;;;
;; Five bytes per channel (DMAP, B-bus, table address low and high, bank) for channels 5, 6 and 7.
$00:9313 .db $02,$0D,$A0,$04,$00 ; HDMA channel 5: DMAP $02, B-bus $0D (BG1HOFS), table $00:04A0
$00:9318 .db $02,$0F,$AA,$04,$00 ; HDMA channel 6: DMAP $02, B-bus $0F (BG2HOFS), table $00:04AA
$00:931D .db $02,$11,$B4,$04,$00 ; HDMA channel 7: DMAP $02, B-bus $11 (BG3HOFS), table $00:04B4
;;; $9322: Run current game mode (GetGameMode) ;;;
;; Jumps to the routine for the game mode in [$0100] using the pointer table that follows the JSL
;; (ExecutePtr).
$00:9322 AD 00 01 LDA.W RAM_GameMode ; A = game mode [$0100]
$00:9325 22 DF 86 00 JSL.L ExecutePtr ; Run the routine from the pointer table below (ExecutePtr)
;;; $9329: Pointer table: game modes (Ptrs009329) ;;;
;; One 16-bit pointer per game mode ($00-$29), indexed by [$0100]. Names inferred from the code; several are
;; marked as uncertain.
$00:9329 91 93 .dw $9391 ; 00 - Load Nintendo Presents
$00:932B 0F 94 .dw $940F ; 01 - Nintendo Presents screen
$00:932D 6F 9F .dw $9F6F ; 02 - Fade to title screen
$00:932F AE 96 .dw $96AE ; 03 - Load title screen
$00:9331 8B 9A .dw $9A8B ; 04 - Prepare title screen
$00:9333 6F 9F .dw $9F6F ; 05 - Title screen: fade in
$00:9335 1B 94 .dw $941B ; 06 - Title screen: circle effect
$00:9337 64 9C .dw GAMEMODE_07 ; 07 - Title screen
$00:9339 D1 9C .dw $9CD1 ; 08 - File select screen
$00:933B 1A 9B .dw $9B1A ; 09 - File erase screen
$00:933D FA 9D .dw $9DFA ; 0A - Player select screen
$00:933F 6F 9F .dw $9F6F ; 0B - Fade out of title screen or level
$00:9341 87 A0 .dw LoadMapGameMode ; 0C - Load overworld
$00:9343 6F 9F .dw $9F6F ; 0D - Fade into overworld
$00:9345 BE A1 .dw $A1BE ; 0E - On overworld
$00:9347 37 9F .dw TmpFade ; 0F - Fade to level
$00:9349 8E 96 .dw $968E ; 10 - Delay between overworld and Mario Start
$00:934B D5 96 .dw MarioStartGameMode ; 11 - Mario Start screen
$00:934D 9C A5 .dw GM04Load ; 12 - Prepare level
$00:934F 37 9F .dw TmpFade ; 13 - Fade into level
$00:9351 DA A1 .dw InLevelGameMode ; 14 - In level
$00:9353 6F 9F .dw $9F6F ; 15 - Fade to game over
$00:9355 50 97 .dw $9750 ; 16 - Fade some more (game over)
$00:9357 59 97 .dw $9759 ; 17 - Game over
$00:9359 6F 9F .dw $9F6F ; 18 - Credits/cutscene: fade
$00:935B 68 94 .dw $9468 ; 19 - Credits/cutscene
$00:935D 6F 9F .dw $9F6F ; 1A - Credits/cutscene: fade
$00:935F FD 94 .dw $94FD ; 1B - Ending
$00:9361 6F 9F .dw $9F6F ; 1C - Fade to Yoshi's house
$00:9363 83 95 .dw $9583 ; 1D - Load/prepare Yoshi's house
$00:9365 6F 9F .dw $9F6F ; 1E - Fade into Yoshi's house
$00:9367 AB 95 .dw $95AB ; 1F - Yoshi's house in the ending
$00:9369 6F 9F .dw $9F6F ; 20 - Fade to enemy parade
$00:936B BC 95 .dw $95BC ; 21 - Load enemy parade (part 1)
$00:936D 6F 9F .dw $9F6F ; 22 - Fade (enemy parade)
$00:936F C1 95 .dw $95C1 ; 23 - Load enemy parade (part 2)
$00:9371 6F 9F .dw $9F6F ; 24 - Fade into enemy parade
$00:9373 2C 96 .dw $962C ; 25 - Enemy parade
$00:9375 6F 9F .dw $9F6F ; 26 - Fade to THE END
$00:9377 3D 96 .dw $963D ; 27 - Load THE END
$00:9379 7C 9F .dw $9F7C ; 28 - Fade into THE END
$00:937B 8D 96 .dw $968D ; 29 - END (return)
;;; $937D: Turn off NMI, IRQ, HDMA and screen (TurnOffIO) ;;;
;; NMITIMEN = 0, HDMA off, force blank. Called from the start of most game modes.
;; Called by:
;; $00:85FA: Upload stripe image to VRAM (LoadScrnImage)
;; $00:959B: Cutscene, ending and game mode code (castle scenes, credits, game over) (CutsceneCastlePal)
;; $00:A087: Game mode 0C: load overworld (LoadMapGameMode)
$00:937D 9C 00 42 STZ.W $4200 ; Disable NMI, IRQs and joypad auto-read
$00:9380 9C 0C 42 STZ.W $420C ; Disable all HDMA channels
$00:9383 A9 80 LDA.B #$80 ; \
$00:9385 8D 00 21 STA.W $2100 ; / INIDISP = $80: force blank
$00:9388 60 RTS ; Return
;;; $9389: Table: Nintendo logo sprite X positions (NintendoPos) ;;;
$00:9389 .db $60,$70,$80,$90 ; X positions of the four Nintendo logo sprites
;;; $938D: Game mode 00: load Nintendo Presents (NintendoTile) ;;;
;; First the logo tile table. Code: clears the screen, loads graphics and palette, builds four 16x16 logo
;; sprites at Y = $70 (X from NintendoPos,
;; tiles from this table), starts the [$1DF5] timer at $40, sets full brightness, makes the backdrop black and
;; moves on to game mode 01.
$00:938D .db $02,$04,$06,$08 ; Tiles of the four Nintendo logo sprites ($02, $04, $06, $08)
; | |
; V This loads the "Nintendo Presents" and handles it. V
$00:9391 20 FA 85 JSR.W $85FA ; Turn off I/O, clear BG3 and hide sprites ($85FA)
$00:9394 20 79 8A JSR.W SetUpScreen ; Reset the BG layer addresses and screen settings (SetUpScreen)
$00:9397 20 93 A9 JSR.W $A993 ; Load the graphics for this screen ($A993)
$00:939A A0 0C LDY.B #$0C ; Y = $0C: OAM offset of sprite 3
$00:939C A2 03 LDX.B #$03 ; X = 3: four logo sprites
$00:939E BD 89 93 LDA.W NintendoPos,X ; \
$00:93A1 99 00 02 STA.W OAM_ExtendedDispX,Y ; / Sprite X = NintendoPos[X]
$00:93A4 A9 70 LDA.B #$70 ; \
$00:93A6 99 01 02 STA.W OAM_ExtendedDispY,Y ; / Sprite Y = $70
$00:93A9 BD 8D 93 LDA.W NintendoTile,X ; \
$00:93AC 99 02 02 STA.W OAM_ExtendedTile,Y ; / Sprite tile = NintendoTile[X]
$00:93AF A9 30 LDA.B #$30 ; \
$00:93B1 99 03 02 STA.W OAM_ExtendedProp,Y ; / Properties = $30 (priority 3, palette 0)
$00:93B4 88 DEY ; \
$00:93B5 88 DEY ; |
$00:93B6 88 DEY ; |
$00:93B7 88 DEY ; / Y -= 4: previous OAM slot
$00:93B8 CA DEX ; X--
$00:93B9 10 E3 BPL $939E ; Loop for the four sprites
$00:93BB A9 AA LDA.B #$AA ; \
$00:93BD 8D 00 04 STA.W $0400 ; / OAM size bits of sprites 0-3 = $AA: all four are 16x16
$00:93C0 A9 01 LDA.B #$01 ; \
$00:93C2 8D FC 1D STA.W $1DFC ; / Sound request [$1DFC] = 1 (the logo jingle, probably)
$00:93C5 A9 40 LDA.B #$40 ; \
$00:93C7 8D F5 1D STA.W $1DF5 ; / [$1DF5] = $40: frames the screen stays up
$00:93CA A9 0F LDA.B #$0F ; \
$00:93CC 8D AE 0D STA.W $0DAE ; / Brightness [$0DAE] = $0F (full)
$00:93CF A9 01 LDA.B #$01 ; \
$00:93D1 8D AF 0D STA.W $0DAF ; / [$0DAF] = 1: mosaic fade direction (probably fading in)
$00:93D4 9C 2E 19 STZ.W $192E ; Sprite palette setting [$192E] = 0
$00:93D7 20 ED AB JSR.W LoadPalette ; Load the palettes (LoadPalette)
$00:93DA 9C 01 07 STZ.W $0701 ; \
$00:93DD 9C 02 07 STZ.W $0702 ; / Backdrop color mirror [$0701] = $0000 (black)
$00:93E0 20 2F 92 JSR.W NintenDMAINIT ; Set CGRAM color 0 to black by DMA (NintenDMAINIT)
$00:93E3 9C 92 1B STZ.W $1B92 ; [$1B92] = 0: menu cursor position
$00:93E6 A2 10 LDX.B #$10 ; X = $10: main screen shows sprites only
$00:93E8 A0 04 LDY.B #$04 ; Y = $04: sub screen shows BG3
$00:93EA A9 01 LDA.B #$01 ; \
$00:93EC 8D 9B 0D STA.W $0D9B ; / [$0D9B] = 1: special level mode (bit 0 = no status bar)
$00:93EF A9 20 LDA.B #$20 ; A = $20: CGADSUB value
$00:93F1 20 FD 93 JSR.W ScreenSettings ; Apply the screen settings (ScreenSettings)
$00:93F4 EE 00 01 INC.W RAM_GameMode ; Game mode = 1 (Nintendo Presents screen); falls into Mode04Finish
;;; $93F7: Enable NMI and joypad, return (Mode04Finish) ;;;
;; Reached by falling through from the game mode increment at $0093F4. Writes NMITIMEN = $81.
;; Called by:
;; $00:9749: Game mode 11: Mario Start, level music (MarioStartGameMode)
;; $00:9AC5: Detect connected controllers into [$0DA0] (SetUp0DA0GM4)
;; $00:A0AD: Game mode 0C: load overworld (LoadMapGameMode)
$00:93F7 A9 81 LDA.B #$81 ; \
$00:93F9 8D 00 42 STA.W $4200 ; / NMITIMEN = $81: NMI and joypad auto-read on, no IRQs
$00:93FC 60 RTS ; Return
;;; $93FD: Set screen layers; game modes 01 and 06 (ScreenSettings) ;;;
;; $0093FD: sets CGADSUB (A, also mirrored in [$40]), main screen layers (X), sub screen layers (Y) and clears
;; the window mask designation. Returns.
;; $00940F (game mode 01): counts [$1DF5] down, then decompresses Mario graphics and goes to game mode 02.
;; $00941B (game mode 06): title screen circle effect. Each frame the circle size [$1433] grows by 4 until $F0
;; and is drawn into the window HDMA table (centre $80,$70);
;; pressing a button jumps to the final size $EC and finishes title screen setup.
;; Called by:
;; $00:93F1: Game mode 00: load Nintendo Presents (NintendoTile)
;; $00:A11D: Game mode 0C: load overworld (LoadMapGameMode)
$00:93FD 8D 31 21 STA.W $2131 ; \
$00:9400 85 40 STA $40 ; / CGADSUB ($2131) and its mirror [$40] = A
$00:9402 8E 2C 21 STX.W $212C ; Main screen designation ($212C) = X
$00:9405 8C 2D 21 STY.W $212D ; Sub screen designation ($212D) = Y
$00:9408 9C 2E 21 STZ.W $212E ; \
$00:940B 9C 2F 21 STZ.W $212F ; / Window mask designation for main and sub screen ($212E, $212F) = 0
$00:940E 60 RTS ; Return
$00:940F CE F5 1D DEC.W $1DF5 ; [$1DF5]--: Nintendo Presents timer
$00:9412 D0 06 BNE $941A ; Not zero yet: return
$00:9414 20 88 B8 JSR.W $B888 ; Decompress Mario's graphics to $7E:2000 and prepare them ($B888)
$00:9417 EE 00 01 INC.W RAM_GameMode ; Game mode += 1 (also used as a common exit by other modes)
$00:941A 60 RTS ; Return
; |
; V part of the "prepare title screen" code?
$00:941B 20 74 9A JSR.W SetUp0DA0GM4 ; Choose which controller is used (SetUp0DA0GM4)
$00:941E 20 BE 9C JSR.W $9CBE ; Check for button presses; Z = none ($9CBE)
$00:9421 F0 0B BEQ $942E ; No button pressed: go on with the circle ($00942E)
$00:9423 A9 EC LDA.B #$EC ; A = $EC: final circle size
$00:9425 20 40 94 JSR.W $9440 ; Store it and draw the circle ($9440)
$00:9428 EE 00 01 INC.W RAM_GameMode ; Game mode += 1
$00:942B 4C 9F 9C JMP.W $9C9F ; Finish title screen setup and return ($9C9F)
$00:942E CE F5 1D DEC.W $1DF5 ; [$1DF5]-- (title timer, also the demo controller timer)
$00:9431 D0 E7 BNE $941A ; Not zero: return
$00:9433 EE F5 1D INC.W $1DF5 ; Undo the decrement
$00:9436 AD 33 14 LDA.W $1433 ; \
$00:9439 18 CLC ; |
$00:943A 69 04 ADC.B #$04 ; |
$00:943C C9 F0 CMP.B #$F0 ; |
$00:943E B0 D7 BCS $9417 ; / Circle size [$1433] + 4; if >= $F0 the effect is done: next game mode
$00:9440 8D 33 14 STA.W $1433 ; Store the new circle size in [$1433]
$00:9443 20 61 CA JSR.W $CA61 ; Point [$04] and [$06] at the circle data $CB12 ($CA61)
$00:9446 A9 80 LDA.B #$80 ; \
$00:9448 85 00 STA $00 ; |
$00:944A A9 70 LDA.B #$70 ; |
$00:944C 85 01 STA $01 ; / Circle centre: [$00] = $80 (X), [$01] = $70 (Y)
$00:944E 4C 88 CA JMP.W $CA88 ; Draw the circle into the window HDMA table and return ($CA88)
;;; $9451: Table: cutscene background settings (CutsceneBgColor) ;;;
;; Indexed by cutscene number - 1; value goes to [$192F] when a cutscene is loaded.
$00:9451 .db $02,$00,$04,$01,$00,$06,$04 ; Cutscene 1-7 background color setting for [$192F] (indexed by cutscene number - 1)
;;; $9458: Cutscene, ending and game mode code (castle scenes, credits, game over) (CutsceneCastlePal) ;;;
;; Table data, then the game mode routines for modes 03, 10, 11, 16, 17, 19, 1B, 1D, 1F, 21, 23, 25 and 27
;; plus helpers.
;; $009458/$009460: palette and border image tables indexed by cutscene number [$13C6]. $009468: mode 19 (load
;; castle cutscene or credits).
;; $0094FD: mode 1B (cutscene frame; mode 19 also runs it once). $00955E: decompress GFX file $2F and copy
;; $0200 words to VRAM $4600.
;; $009583/$0095BC/$0095C1/$00962C/$00963D: ending modes (Yoshi's House, enemy parade, THE END). $009622:
;; shared tail setting main/sub screen and advancing the mode.
;; $00968E: mode 10. $0096AE: mode 03 (load title screen; falls into the mode 11 body). $00974C: JSL wrapper
;; for HexToDec.
;; $009750: mode 16. $009759: mode 17 (game over). Quirk: many ending routines have unresolved purposes (calls
;; into bank $0C).
$00:9458 .db $03,$06,$05,$06,$03,$03,$06,$06 ; Castle palette for each cutscene, indexed by [$13C6] (entry 0 unused)
$00:9460 .db $03,$FF,$FF,$C9,$0F,$FF,$CC,$C9 ; Stripe image number for each cutscene's border graphics, indexed by [$13C6]
$00:9468 20 FA 85 JSR.W $85FA ; Turn off NMI/IRQ/HDMA and screen, clear BG3 and sprites ($85FA)
$00:946B 20 A6 A1 JSR.W Clear_1A_13D3 ; Clear layer scroll positions and [$13D3] (Clear_1A_13D3)
$00:946E 20 79 8A JSR.W SetUpScreen ; Set up the screen (SetUpScreen)
$00:9471 AE C6 13 LDX.W $13C6 ; X = cutscene number [$13C6] (1-7 castle scenes, 8 = credits)
$00:9474 A9 18 LDA.B #$18 ; \
$00:9476 8D 31 19 STA.W $1931 ; / Tileset [$1931] = $18 (cutscene castle)
$00:9479 A9 14 LDA.B #$14 ; \
$00:947B 8D 2B 19 STA.W $192B ; / Sprite GFX set [$192B] = $14
$00:947E BD 50 94 LDA.W CutsceneBgColor-1,X ; \
$00:9481 8D 2F 19 STA.W $192F ; |
$00:9484 BD 58 94 LDA.W CutsceneCastlePal,X ; } Background color setting [$192F] and castle palette [$1930] for this cutscene
$00:9487 8D 30 19 STA.W $1930 ; /
$00:948A 9C 2E 19 STZ.W $192E ; Sprite palette setting [$192E] = 0
$00:948D A9 01 LDA.B #$01 ; \
$00:948F 8D 2D 19 STA.W $192D ; / FG palette setting [$192D] = 1 (brown/cream)
$00:9492 E0 08 CPX.B #$08 ; \
$00:9494 D0 1C BNE $94B2 ; / Not the credits (cutscene 8)? Then go load a castle scene
$00:9496 20 5E 95 JSR.W $955E ; Decompress GFX file $2F and copy $0200 words to VRAM $4600 ($955E)
$00:9499 A9 D2 LDA.B #$D2 ; \
$00:949B 85 12 STA $12 ; / Stripe image $D2 (credits background)
$00:949D 20 D2 85 JSR.W LoadScrnImage ; Upload the stripe image (LoadScrnImage)
$00:94A0 20 59 81 JSR.W UploadMusicBank3 ; Upload music bank 3 (ending music)
$00:94A3 22 DD 93 0C JSL.L $93DD ; Credits setup in bank $0C ($93DD)
$00:94A7 20 60 92 JSR.W $9260 ; Clear all HDMA ($9260)
$00:94AA EE 31 19 INC.W $1931 ; \
$00:94AD EE 2B 19 INC.W $192B ; / Credits use the next tileset [$1931] and sprite GFX set [$192B]
$00:94B0 80 25 BRA $94D7 ; Continue at $0094D7
$00:94B2 A9 15 LDA.B #$15 ; \
$00:94B4 8D FB 1D STA.W $1DFB ; / Music request [$1DFB] = $15 (cutscene music)
$00:94B7 BD 60 94 LDA.W $9460,X ; \
$00:94BA 85 12 STA $12 ; } Upload this cutscene's border stripe image from $009460[X]
$00:94BC 20 D2 85 JSR.W LoadScrnImage ; /
$00:94BF A9 CF LDA.B #$CF ; \
$00:94C1 85 12 STA $12 ; } Upload stripe image $CF as well
$00:94C3 20 D2 85 JSR.W LoadScrnImage ; /
$00:94C6 C2 20 REP #$20 ; A 16-bit
$00:94C8 A9 90 00 LDA.W #$0090 ; \
$00:94CB 85 94 STA RAM_MarioXPos ; |
$00:94CD A9 58 00 LDA.W #$0058 ; } Mario position = ($0090, $0058)
$00:94D0 85 96 STA RAM_MarioYPos ; /
$00:94D2 E2 20 SEP #$20 ; A 8-bit
$00:94D4 EE 8F 14 INC.W $148F ; [$148F]++ (Mario carrying flag; purpose here unclear)
$00:94D7 20 DA A9 JSR.W UploadSpriteGFX ; Upload sprite graphics set [$192B] (UploadSpriteGFX)
$00:94DA 20 ED AB JSR.W LoadPalette ; Load the palettes (LoadPalette)
$00:94DD 20 2F 92 JSR.W $922F ; Set up the CGRAM DMA for the palette buffer ($922F)
$00:94E0 A2 0B LDX.B #$0B ; \
$00:94E2 74 1A STZ RAM_ScreenBndryXLo,X ; |
$00:94E4 CA DEX ; } Clear layer positions [$1A]-[$25]: every layer scrolled to 0
$00:94E5 10 FB BPL $94E2 ; /
$00:94E7 A9 20 LDA.B #$20 ; \
$00:94E9 85 64 STA $64 ; / [$64] = $20: sprite priority bits for the scene
$00:94EB 20 35 A6 JSR.W $A635 ; Adjust music for active power-ups ($A635)
$00:94EE 64 76 STZ RAM_MarioDirection ; Mario faces right
$00:94F0 64 72 STZ RAM_IsFlying ; Mario is not flying
$00:94F2 22 B1 CE 00 JSL.L $CEB1 ; Mario init routine in bank $00 ($CEB1)
$00:94F6 A2 17 LDX.B #$17 ; X = $17: main screen BG1, BG2, BG3, OBJ
$00:94F8 A0 00 LDY.B #$00 ; Y = 0: no sub screen layers
$00:94FA 20 22 96 JSR.W $9622 ; Apply screen settings, BGMODE mirror and advance game mode ($9622)
$00:94FD 22 00 80 7F JSL.L RAM_7F8000 ; Game mode 1B entry: move all sprites off-screen
$00:9501 AD C6 13 LDA.W $13C6 ; \
$00:9504 C9 08 CMP.B #$08 ; / Credits ([$13C6] = 8)?
$00:9506 F0 4F BEQ $9557 ; Yes: go to the credits scene code
$00:9508 A5 17 LDA RAM_ControllerB ; \
$00:950A 29 00 AND.B #$00 ; } Debug check: [$17] AND $00 can never equal $30
$00:950C C9 30 CMP.B #$30 ; /
$00:950E D0 19 BNE $9529 ; So always go to the normal scene
$00:9510 A5 15 LDA RAM_ControllerA ; \
$00:9512 29 08 AND.B #$08 ; / Unused. Debug: Up on D-pad advances to the next cutscene
$00:9514 F0 0D BEQ $9523 ; Unused.
$00:9516 AD C6 13 LDA.W $13C6 ; \
$00:9519 1A INC A ; } Unused. [$13C6] + 1, wrap to 1 after 8
$00:951A C9 09 CMP.B #$09 ; /
$00:951C 90 02 BCC $9520 ; Unused.
$00:951E A9 01 LDA.B #$01 ; Unused.
$00:9520 8D C6 13 STA.W $13C6 ; Unused. Store the new cutscene number
$00:9523 A9 18 LDA.B #$18 ; \
$00:9525 8D 00 01 STA.W RAM_GameMode ; / Unused. Game mode = $18 (reload the cutscene)
$00:9528 60 RTS ; Unused. Return
$00:9529 22 7E C9 0C JSL.L $C97E ; Castle scene setup in bank $0C ($C97E)
$00:952D C2 20 REP #$20 ; A 16-bit
$00:952F A5 1A LDA RAM_ScreenBndryXLo ; \
$00:9531 48 PHA ; |
$00:9532 A5 1C LDA RAM_ScreenBndryYLo ; } Save layer 1 position on the stack
$00:9534 48 PHA ; /
$00:9535 A5 1E LDA $1E ; \
$00:9537 85 1A STA RAM_ScreenBndryXLo ; |
$00:9539 A5 20 LDA $20 ; } Layer 1 position = layer 2 position (for Mario/castle update)
$00:953B 85 1C STA RAM_ScreenBndryYLo ; /
$00:953D E2 20 SEP #$20 ; A 8-bit
$00:953F 22 BD E2 00 JSL.L $E2BD ; Run the Mario/sprite update ($E2BD)
$00:9543 C2 20 REP #$20 ; A 16-bit
$00:9545 68 PLA ; \
$00:9546 85 1C STA RAM_ScreenBndryYLo ; |
$00:9548 68 PLA ; } Restore layer 1 position
$00:9549 85 1A STA RAM_ScreenBndryXLo ; /
$00:954B E2 20 SEP #$20 ; A 8-bit
$00:954D A9 0C LDA.B #$0C ; \
$00:954F 85 71 STA RAM_MarioAnimation ; / Mario animation [$71] = $0C (castle entrance)
$00:9551 20 7E C4 JSR.W $C47E ; Update Mario for this animation ($C47E)
$00:9554 4C 94 84 JMP.W $8494 ; Pack OAM size bits and return
$00:9557 22 8D 93 0C JSL.L $938D ; Credits scene code in bank $0C ($938D)
$00:955B 4C 94 84 JMP.W $8494 ; Pack OAM size bits and return
$00:955E A0 2F LDY.B #$2F ; Y = $2F: GFX file number
$00:9560 22 28 BA 00 JSL.L $BA28 ; Decompress that GFX file, [$00] points to the data ($BA28)
$00:9564 A9 80 LDA.B #$80 ; \
$00:9566 8D 15 21 STA.W $2115 ; / VMAIN = $80: increment after high-byte writes
$00:9569 C2 30 REP #$30 ; A, X, Y 16-bit
$00:956B A9 00 46 LDA.W #$4600 ; \
$00:956E 8D 16 21 STA.W $2116 ; / VRAM address = $4600
$00:9571 A2 00 02 LDX.W #$0200 ; X = $0200 words
$00:9574 A7 00 LDA [$00] ; \
$00:9576 8D 18 21 STA.W $2118 ; / Write the word at [[$00]] to VRAM
$00:9579 E6 00 INC $00 ; [$00] += 2
$00:957B E6 00 INC $00 ; (second INC of the 16-bit pointer)
$00:957D CA DEX ; Count words
$00:957E D0 F4 BNE $9574 ; Loop until all $0200 words are copied
$00:9580 E2 30 SEP #$30 ; A, X, Y 8-bit
$00:9582 60 RTS ; Return
; |
; These routines need a lot of context to figure out V
$00:9583 EE C6 13 INC.W $13C6 ; Game mode 1D: [$13C6]++ (next ending step)
$00:9586 A9 28 LDA.B #$28 ; A = $28
$00:9588 A0 01 LDY.B #$01 ; Y = 1
$00:958A 20 CF 96 JSR.W $96CF ; Set [$0109] = $28 and [$1F11] = 1 ($96CF)
$00:958D CE 00 01 DEC.W RAM_GameMode ; Game mode--, so GM04Load's mode increment is undone
$00:9590 A9 16 LDA.B #$16 ; \
$00:9592 8D 2B 19 STA.W $192B ; / Sprite GFX set [$192B] = $16
$00:9595 20 9C A5 JSR.W GM04Load ; Load the level (GM04Load)
$00:9598 CE 00 01 DEC.W RAM_GameMode ; Game mode-- again
$00:959B 20 7D 93 JSR.W TurnOffIO ; Turn off NMI/IRQ/HDMA and screen (TurnOffIO)
$00:959E 20 FA 85 JSR.W $85FA ; Clear BG3 and sprites ($85FA)
$00:95A1 20 93 A9 JSR.W $A993 ; Clear VRAM $4000 and load graphics ($A993)
$00:95A4 22 C9 A3 0C JSL.L $A3C9 ; Yoshi's House ending setup in bank $0C ($A3C9)
$00:95A8 20 1E 96 JSR.W $961E ; Apply screen settings and advance game mode ($961E)
$00:95AB 22 00 80 7F JSL.L RAM_7F8000 ; Game mode 1F entry: move all sprites off-screen
$00:95AF 22 9A 93 0C JSL.L $939A ; Yoshi's House ending per-frame code in bank $0C ($939A)
$00:95B3 E6 14 INC RAM_FrameCounterB ; Frame counter B [$14]++
$00:95B5 22 39 BB 05 JSL.L $BB39 ; Per-frame level update in bank $05 ($BB39)
$00:95B9 4C 94 84 JMP.W $8494 ; Pack OAM size bits and return
$00:95BC 22 AD 93 0C JSL.L $93AD ; Game mode 21 (enemy parade ending): bank $0C code ($93AD)
$00:95C0 60 RTS ; Return
$00:95C1 20 FA 85 JSR.W $85FA ; Game mode 23: clear BG3 and sprites ($85FA)
$00:95C4 20 A6 A1 JSR.W Clear_1A_13D3 ; Clear layer positions (Clear_1A_13D3)
$00:95C7 20 79 8A JSR.W SetUpScreen ; Set up the screen (SetUpScreen)
$00:95CA 22 8C AD 0C JSL.L $AD8C ; Ending enemy scene setup in bank $0C ($AD8C)
$00:95CE 22 1E 80 05 JSL.L $801E ; Level data load in bank $05 ($801E)
$00:95D2 AD E9 1D LDA.W $1DE9 ; A = [$1DE9] (ending scene number)
$00:95D5 C9 0A CMP.B #$0A ; Scene $0A?
$00:95D7 D0 07 BNE $95E0 ; No: check for scene $0C
$00:95D9 A9 13 LDA.B #$13 ; \
$00:95DB 8D 2B 19 STA.W $192B ; / Sprite GFX set [$192B] = $13
$00:95DE 80 09 BRA $95E9 ; Continue at $0095E9
$00:95E0 C9 0C CMP.B #$0C ; Scene $0C?
$00:95E2 D0 05 BNE $95E9 ; No: keep the default sprite GFX set
$00:95E4 A9 17 LDA.B #$17 ; \
$00:95E6 8D 2B 19 STA.W $192B ; / Sprite GFX set [$192B] = $17
$00:95E9 20 DA A9 JSR.W UploadSpriteGFX ; Upload sprite graphics (UploadSpriteGFX)
$00:95EC 20 ED AB JSR.W LoadPalette ; Load the palettes (LoadPalette)
$00:95EF 22 9E 80 05 JSL.L $809E ; Level setup in bank $05 ($809E)
$00:95F3 20 F9 A5 JSR.W $A5F9 ; $A5F9
$00:95F6 22 F6 AD 0C JSL.L $ADF6 ; Ending enemy scene code in bank $0C ($ADF6)
$00:95FA AD E9 1D LDA.W $1DE9 ; A = [$1DE9]
$00:95FD C9 0C CMP.B #$0C ; Scene $0C?
$00:95FF D0 11 BNE $9612 ; No: skip the palette copy
$00:9601 A2 0B LDX.B #$0B ; X = $0B: 12 bytes
$00:9603 BD C0 B3 LDA.W BowserEndPalette,X ; \
$00:9606 9D 07 08 STA.W $0807,X ; / Copy BowserEndPalette to palette buffer $0807 (scene $0C only)
$00:9609 BD CC B3 LDA.W $B3CC,X ; \
$00:960C 9D 27 08 STA.W $0827,X ; / Copy $B3CC to palette buffer $0827
$00:960F CA DEX ; Next byte
$00:9610 10 F1 BPL $9603 ; Loop for 12 bytes
$00:9612 20 2F 92 JSR.W $922F ; Set up the CGRAM DMA for the palette buffer ($922F)
$00:9615 20 B2 92 JSR.W $92B2 ; Reset the HDMA window tables ($92B2)
$00:9618 20 D2 85 JSR.W LoadScrnImage ; Upload the stripe image (LoadScrnImage)
$00:961B 20 2C 96 JSR.W $962C ; Run one frame of the enemy scene ($962C)
$00:961E A2 15 LDX.B #$15 ; X = $15: main screen BG1, BG3, OBJ
$00:9620 A0 02 LDY.B #$02 ; Y = 2: sub screen BG2
$00:9622 20 29 9F JSR.W KeepModeActive ; [$0DB1] = 1 (KeepModeActive)
$00:9625 A9 09 LDA.B #$09 ; \
$00:9627 85 3E STA $3E ; / BGMODE mirror [$3E] = $09
$00:9629 4C EA 93 JMP.W $93EA ; Apply screen settings and advance game mode ($0093EA)
$00:962C 9C 84 0D STZ.W $0D84 ; Game mode 25 (enemy parade): [$0D84] = 0
$00:962F 20 ED 92 JSR.W $92ED ; Copy layer positions to the HDMA tables ($92ED)
$00:9632 22 00 80 7F JSL.L RAM_7F8000 ; Move all sprites off-screen
$00:9636 22 A5 93 0C JSL.L $93A5 ; Enemy scene per-frame code in bank $0C ($93A5)
$00:963A 4C 94 84 JMP.W $8494 ; Pack OAM size bits and return
$00:963D 20 FA 85 JSR.W $85FA ; Game mode 27: clear BG3 and sprites ($85FA)
$00:9640 20 A6 A1 JSR.W Clear_1A_13D3 ; Clear layer positions (Clear_1A_13D3)
$00:9643 20 79 8A JSR.W SetUpScreen ; Set up the screen (SetUpScreen)
$00:9646 20 5E 95 JSR.W $955E ; Decompress GFX file $2F into VRAM $4600 ($955E)
$00:9649 A9 19 LDA.B #$19 ; \
$00:964B 8D 2B 19 STA.W $192B ; / Sprite GFX set [$192B] = $19
$00:964E A9 03 LDA.B #$03 ; \
$00:9650 8D 2F 19 STA.W $192F ; / Background color setting [$192F] = 3
$00:9653 A9 03 LDA.B #$03 ; \
$00:9655 8D 30 19 STA.W $1930 ; / FG palette setting [$1930] = 3
$00:9658 20 DA A9 JSR.W UploadSpriteGFX ; Upload sprite graphics (UploadSpriteGFX)
$00:965B 20 ED AB JSR.W LoadPalette ; Load the palettes (LoadPalette)
$00:965E A2 0B LDX.B #$0B ; X = $0B: 12 bytes
$00:9660 BD 0E B7 LDA.W TheEndPalettes,X ; \
$00:9663 9D A7 08 STA.W $08A7,X ; / Copy TheEndPalettes to palette buffer $08A7
$00:9666 BD 1A B7 LDA.W $B71A,X ; \
$00:9669 9D C7 08 STA.W $08C7,X ; / Copy $B71A to palette buffer $08C7
$00:966C BD 26 B7 LDA.W $B726,X ; \
$00:966F 9D E7 08 STA.W $08E7,X ; / Copy $B726 to palette buffer $08E7
$00:9672 CA DEX ; Next byte
$00:9673 10 EB BPL $9660 ; Loop for 12 bytes
$00:9675 20 2F 92 JSR.W $922F ; Set up the CGRAM DMA for the palette buffer ($922F)
$00:9678 A9 D5 LDA.B #$D5 ; \
$00:967A 85 12 STA $12 ; / Stripe image $D5 (THE END)
$00:967C 20 D2 85 JSR.W LoadScrnImage ; Upload the stripe image (LoadScrnImage)
$00:967F 22 DF AA 0C JSL.L $AADF ; THE END scene setup in bank $0C ($AADF)
$00:9683 20 94 84 JSR.W $8494 ; Pack OAM size bits
$00:9686 A2 14 LDX.B #$14 ; X = $14: main screen BG3, OBJ
$00:9688 A0 00 LDY.B #$00 ; Y = 0: no sub screen layers
$00:968A 4C 22 96 JMP.W $9622 ; Apply screen settings and advance game mode
$00:968D 60 RTS ; Return (game mode 29: END)
$00:968E 20 FA 85 JSR.W $85FA ; Game mode 10: clear BG3 and sprites ($85FA)
$00:9691 AD 25 14 LDA.W $1425 ; A = [$1425] (bonus game flag, probably)
$00:9694 D0 12 BNE $96A8 ; Non-zero: run $91B1
$00:9696 AD 1A 14 LDA.W $141A ; \
$00:9699 0D 1D 14 ORA.W $141D ; } A = [$141A] | [$141D] | [$0109]
$00:969C 0D 09 01 ORA.W $0109 ; /
$00:969F D0 0A BNE $96AB ; Any non-zero: skip to the common setup
$00:96A1 AD C1 13 LDA.W $13C1 ; \
$00:96A4 C9 56 CMP.B #$56 ; / [$13C1] (overworld tile, probably) = $56?
$00:96A6 F0 03 BEQ $96AB ; Yes: skip to the common setup
$00:96A8 20 B1 91 JSR.W $91B1 ; Set up the Mario Start/bonus screen sprites ($91B1)
$00:96AB 4C CA 93 JMP.W $93CA ; Set brightness, load palette, advance game mode ($93CA)
$00:96AE 9C 00 42 STZ.W $4200 ; Game mode 03: disable NMI, IRQ and joypad reading
$00:96B1 20 4E 8A JSR.W ClearStack ; Clear RAM (ClearStack)
$00:96B4 A2 07 LDX.B #$07 ; X = 7
$00:96B6 A9 FF LDA.B #$FF ; A = $FF
$00:96B8 9D 01 01 STA.W $0101,X ; Set [$0101]-[$0108] = $FF
$00:96BB CA DEX ; Next byte
$00:96BC 10 FA BPL $96B8 ; Loop for 8 bytes
$00:96BE AD 09 01 LDA.W $0109 ; A = [$0109]
$00:96C1 D0 08 BNE $96CB ; Non-zero: skip the music upload
$00:96C3 20 0E 81 JSR.W UploadMusicBank1 ; Upload music bank 1 (UploadMusicBank1)
$00:96C6 A9 01 LDA.B #$01 ; \
$00:96C8 8D FB 1D STA.W $1DFB ; / Music request [$1DFB] = 1 (title screen music)
$00:96CB A9 EB LDA.B #$EB ; A = $EB
$00:96CD A0 00 LDY.B #$00 ; Y = 0
$00:96CF 8D 09 01 STA.W $0109 ; [$0109] = A (level load override)
$00:96D2 8C 11 1F STY.W $1F11 ; [$1F11] = Y (current submap)
;;; $96D5: Game mode 11: Mario Start, level music (MarioStartGameMode) ;;;
;; Entered at $0096D5. Disables NMI, clears buttons, optionally shows the Mario Start message, resets
;; overworld processing, copies layer positions,
;; loads the level data ($801E), picks the level music request ([$1DFB]/[$0DDA]), blacks the screen and
;; advances the game mode.
;; $0097BC: Mode 7 boss room setup (called from level load): sets up screen, sprite GFX, window masks and
;; Mario for the boss room; $009801 is the non-bit-6 variant.
$00:96D5 9C 00 42 STZ.W $4200 ; Game mode 11: disable NMI, IRQ and joypad reading
$00:96D8 20 2D F6 JSR.W NoButtons ; Clear the controller inputs (NoButtons)
$00:96DB AD 1A 14 LDA.W $141A ; \
$00:96DE D0 09 BNE $96E9 ; / [$141A] non-zero: skip showing the Mario Start message
$00:96E0 AD 1D 14 LDA.W $141D ; \
$00:96E3 F0 04 BEQ $96E9 ; / [$141D] zero: skip showing the message
$00:96E5 22 09 DC 04 JSL.L $DC09 ; Mario Start message setup in bank $04 ($DC09)
$00:96E9 9C D5 13 STZ.W $13D5 ; [$13D5] = 0
$00:96EC 9C D9 13 STZ.W $13D9 ; [$13D9] = 0: stop overworld processing
$00:96EF A9 50 LDA.B #$50 ; \
$00:96F1 8D D6 13 STA.W $13D6 ; / [$13D6] = $50
$00:96F4 22 96 D7 05 JSL.L $D796 ; Level/overworld setup in bank $05 ($D796)
$00:96F8 A2 07 LDX.B #$07 ; X = 7
$00:96FA B5 1A LDA RAM_ScreenBndryXLo,X ; \
$00:96FC 9D 62 14 STA.W $1462,X ; / Copy layer positions [$1A]-[$21] to $1462-$1469 (previous positions)
$00:96FF CA DEX ; Next byte
$00:9700 10 F8 BPL $96FA ; Loop for 8 bytes
$00:9702 20 34 81 JSR.W $8134 ; Upload level music bank if needed ($8134)
$00:9705 20 35 A6 JSR.W $A635 ; Adjust music for active power-ups ($A635)
$00:9708 A9 20 LDA.B #$20 ; \
$00:970A 85 5E STA $5E ; / [$5E] = $20
$00:970C 20 96 A7 JSR.W $A796 ; $A796
$00:970F EE 04 14 INC.W $1404 ; [$1404]++ (layer 1 vertical scroll flag)
$00:9712 22 DB F6 00 JSL.L $F6DB ; Handle screen scrolling ($F6DB)
$00:9716 22 1E 80 05 JSL.L $801E ; Level data load in bank $05 ($801E)
$00:971A AD 09 01 LDA.W $0109 ; \
$00:971D F0 09 BEQ $9728 ; / [$0109] = 0: skip to the music check
$00:971F C9 E9 CMP.B #$E9 ; \
$00:9721 D0 1D BNE $9740 ; / [$0109] != $E9 (intro level): skip the music setup
$00:9723 A9 13 LDA.B #$13 ; \
$00:9725 8D DA 0D STA.W $0DDA ; / Music number [$0DDA] = $13 (intro level)
$00:9728 AD DA 0D LDA.W $0DDA ; A = [$0DDA] (level music number)
$00:972B C9 40 CMP.B #$40 ; Bit 6 / value >= $40: music already requested
$00:972D B0 0C BCS $973B ; Skip the request
$00:972F AC 9B 0D LDY.W $0D9B ; Y = [$0D9B] (special level mode)
$00:9732 C0 C1 CPY.B #$C1 ; \
$00:9734 D0 02 BNE $9738 ; / Y = $C1 (Bowser fight)?
$00:9736 A9 16 LDA.B #$16 ; Yes: music = $16
$00:9738 8D FB 1D STA.W $1DFB ; Music request [$1DFB] = A
$00:973B 29 BF AND.B #$BF ; \
$00:973D 8D DA 0D STA.W $0DDA ; / Remove bit 6 from the music number and store it in [$0DDA]
$00:9740 9C AE 0D STZ.W $0DAE ; Brightness mirror [$0DAE] = 0 (black)
$00:9743 9C AF 0D STZ.W $0DAF ; Mosaic mirror [$0DAF] = 0
$00:9746 EE 00 01 INC.W RAM_GameMode ; Advance the game mode
$00:9749 4C F7 93 JMP.W Mode04Finish ; Enable NMI and joypad and return (Mode04Finish)
$00:974C 20 45 90 JSR.W HexToDec ; Convert A to decimal digits (HexToDec)
$00:974F 6B RTL ; Return long (JSL entry for other banks)
$00:9750 20 FA 85 JSR.W $85FA ; Game mode 16: clear BG3 and sprites ($85FA)
$00:9753 20 2D A8 JSR.W $A82D ; $A82D (loads graphics file $0F, probably the game over graphics)
$00:9756 4C CA 93 JMP.W $93CA ; Set brightness, load palette, advance mode ($93CA)
$00:9759 22 00 80 7F JSL.L RAM_7F8000 ; Game mode 17 (game over): move all sprites off-screen
$00:975D AD 3C 14 LDA.W $143C ; A = [$143C] (animation position)
$00:9760 D0 29 BNE $978B ; Non-zero: still animating, go to $00978B
$00:9762 CE 3D 14 DEC.W $143D ; [$143D]-- (wait timer)
$00:9765 D0 27 BNE $978E ; Not yet zero: draw the animation
$00:9767 AD BE 0D LDA.W RAM_StatusLives ; \
$00:976A 10 1C BPL $9788 ; / Lives of the current player >= 0: go on to the next mode
$00:976C 9C C1 0D STZ.W RAM_OWHasYoshi ; Remove Yoshi from the overworld
$00:976F AD B4 0D LDA.W RAM_PlayerLives ; \
$00:9772 0D B5 0D ORA.W $0DB5 ; / Lives of Mario and Luigi both negative?
$00:9775 10 11 BPL $9788 ; No: go on to the next mode
$00:9777 A2 0C LDX.B #$0C ; X = $0C
$00:9779 9E 2F 1F STZ.W $1F2F,X ; Clear [$1F2F+X] (overworld progress data, probably)
$00:977C 9E 06 00 STZ.W $0006,X ; Clear [$0006+X]
$00:977F 9E EE 1F STZ.W $1FEE,X ; Clear [$1FEE+X]
$00:9782 CA DEX ; Next
$00:9783 10 F4 BPL $9779 ; Loop for 13 bytes
$00:9785 EE C9 13 INC.W $13C9 ; [$13C9]++ (both players out of lives, probably)
$00:9788 4C 62 9E JMP.W $9E62 ; Leave the game over mode ($9E62)
$00:978B 38 SEC ; \
$00:978C E9 04 SBC.B #$04 ; / A -= 4 (move the animation)
$00:978E 8D 3C 14 STA.W $143C ; [$143C] = A
$00:9791 18 CLC ; \
$00:9792 69 A0 ADC.B #$A0 ; } [$00] = [$143C] + $A0 (X position of the first tile)
$00:9794 85 00 STA $00 ; /
$00:9796 26 01 ROL $01 ; [$01] = carry (high byte)
$00:9798 AE 3B 14 LDX.W $143B ; X = [$143B] (tile index)
$00:979B A0 48 LDY.B #$48 ; Y = $48: OAM offset, counts down by 8
$00:979D C0 28 CPY.B #$28 ; Y = $28?
$00:979F D0 0D BNE $97AE ; No: use the position from above
$00:97A1 A9 78 LDA.B #$78 ; \
$00:97A3 38 SEC ; |
$00:97A4 ED 3C 14 SBC.W $143C ; |
$00:97A7 85 00 STA $00 ; |
$00:97A9 2A ROL ; |
$00:97AA 49 01 EOR.B #$01 ; } Mirrored position: [$00] = $78 - [$143C], [$01] = high byte XOR 1
$00:97AC 85 01 STA $01 ; /
$00:97AE 20 E9 91 JSR.W $91E9 ; Draw a pair of tiles in OAM ($91E9)
$00:97B1 E8 INX ; Next tile index
$00:97B2 98 TYA ; \
$00:97B3 38 SEC ; |
$00:97B4 E9 08 SBC.B #$08 ; } Y -= 8
$00:97B6 A8 TAY ; /
$00:97B7 D0 E4 BNE $979D ; Loop until Y = 0
$00:97B9 4C 94 84 JMP.W $8494 ; Pack OAM size bits and return
$00:97BC A9 0F LDA.B #$0F ; Mode 7 boss room init: A = $0F
$00:97BE 8D AE 0D STA.W $0DAE ; Brightness mirror [$0DAE] = $0F (full)
$00:97C1 9C B0 0D STZ.W $0DB0 ; Mosaic size [$0DB0] = 0
$00:97C4 20 5B 9F JSR.W GM++Mosaic ; Run mosaic (GM++Mosaic)
$00:97C7 A9 20 LDA.B #$20 ; A = $20
$00:97C9 85 38 STA $38 ; Mode 7 scaling [$38] = $20
$00:97CB 85 39 STA $39 ; Mode 7 scaling [$39] = $20
$00:97CD 9C 88 18 STZ.W RAM_Layer1DispYLo ; Layer 1 Y displacement [$1888] = 0
$00:97D0 20 FA 85 JSR.W $85FA ; Clear BG3 and sprites ($85FA)
$00:97D3 A9 FF LDA.B #$FF ; \
$00:97D5 8D 31 19 STA.W $1931 ; / Tileset [$1931] = $FF
$00:97D8 22 58 D9 03 JSL.L $D958 ; Boss room setup in bank $03 ($D958)
$00:97DC 2C 9B 0D BIT.W $0D9B ; Test [$0D9B] bits 7 and 6
$00:97DF 50 20 BVC $9801 ; Bit 6 clear (Iggy/Larry): go to $009801
$00:97E1 20 25 99 JSR.W $9925 ; Set up the Mode 7 boss room ($9925)
$00:97E4 AC FC 13 LDY.W $13FC ; Y = [$13FC] (boss number)
$00:97E7 C0 03 CPY.B #$03 ; Boss < 3?
$00:97E9 90 06 BCC $97F1 ; Yes: go to $0097F1
$00:97EB D0 4E BNE $983B ; Boss > 3: go to $00983B
$00:97ED A9 18 LDA.B #$18 ; Boss 3: sprite GFX set = $18
$00:97EF 80 0B BRA $97FC ; Go to $0097FC
$00:97F1 A9 03 LDA.B #$03 ; \
$00:97F3 8D F9 13 STA.W RAM_IsBehindScenery ; / [$13F9] (behind scenery flag) = 3
$00:97F6 A9 C8 LDA.B #$C8 ; \
$00:97F8 85 3F STA $3F ; / [$3F] = $C8 (OAM priority index)
$00:97FA A9 12 LDA.B #$12 ; Sprite GFX set = $12
$00:97FC CE 31 19 DEC.W $1931 ; Tileset [$1931]-- ($FE)
$00:97FF 80 3C BRA $983D ; Go to $00983D
$00:9801 20 D9 AD JSR.W $ADD9 ; Load palette and colors ($ADD9)
$00:9804 20 A8 92 JSR.W $92A8 ; Set up the HDMA window tables ($92A8)
$00:9807 A2 50 LDX.B #$50 ; X = $50
$00:9809 20 3D 9A JSR.W $9A3D ; Fill 16 tiles with $05 at $7EC800+X ($9A3D)
$00:980C C2 20 REP #$20 ; A 16-bit
$00:980E A9 50 00 LDA.W #$0050 ; \
$00:9811 85 94 STA RAM_MarioXPos ; / Mario X position = $0050
$00:9813 A9 D0 FF LDA.W #$FFD0 ; \
$00:9816 85 96 STA RAM_MarioYPos ; / Mario Y position = $FFD0
$00:9818 64 1A STZ RAM_ScreenBndryXLo ; Layer 1 X position = 0
$00:981A 9C 62 14 STZ.W $1462 ; Mirror of layer 1 X = 0
$00:981D A9 90 FF LDA.W #$FF90 ; \
$00:9820 85 1C STA RAM_ScreenBndryYLo ; / Layer 1 Y position = $FF90
$00:9822 8D 64 14 STA.W $1464 ; Mirror of layer 1 Y = $FF90
$00:9825 A9 80 00 LDA.W #$0080 ; \
$00:9828 85 2A STA $2A ; / Mode 7 center X [$2A] = $0080
$00:982A A9 50 00 LDA.W #$0050 ; \
$00:982D 85 2C STA $2C ; / Mode 7 center Y [$2C] = $0050
$00:982F A9 80 00 LDA.W #$0080 ; \
$00:9832 85 3A STA $3A ; / Mode 7 scroll X [$3A] = $0080
$00:9834 A9 10 00 LDA.W #$0010 ; \
$00:9837 85 3C STA $3C ; / Mode 7 scroll Y [$3C] = $0010
$00:9839 E2 20 SEP #$20 ; A 8-bit
$00:983B A9 13 LDA.B #$13 ; Sprite GFX set = $13
$00:983D 8D 2B 19 STA.W $192B ; [$192B] = A (sprite GFX set)
$00:9840 20 DA A9 JSR.W UploadSpriteGFX ; Upload sprite graphics (UploadSpriteGFX)
$00:9843 A9 11 LDA.B #$11 ; \
$00:9845 8D 2E 21 STA.W $212E ; / TMW ($212E) = $11: window applies to BG1 and OBJ on the main screen
$00:9848 9C 2D 21 STZ.W $212D ; TSD ($212D) = 0: no sub screen layers
$00:984B 9C 2F 21 STZ.W $212F ; TSW ($212F) = 0
$00:984E A9 02 LDA.B #$02 ; \
$00:9850 85 41 STA $41 ; / Window mask mirror [$41] = $02
$00:9852 A9 32 LDA.B #$32 ; \
$00:9854 85 43 STA $43 ; / Window mask mirror [$43] = $32
$00:9856 A9 20 LDA.B #$20 ; \
$00:9858 85 44 STA $44 ; / Color math mirror [$44] = $20
$00:985A 20 FF 8C JSR.W GM04DoDMA ; Upload level graphics via DMA (GM04DoDMA)
$00:985D 20 CD 8A JSR.W $8ACD ; Build the Mode 7 matrix from the scaling ($8ACD)
$00:9860 22 BD E2 00 JSL.L $E2BD ; Run the Mario/sprite update ($E2BD)
$00:9864 20 F3 A2 JSR.W $A2F3 ; $A2F3
$00:9867 20 93 C5 JSR.W $C593 ; $C593
$00:986A 64 7D STZ RAM_MarioSpeedY ; Mario Y speed = 0
$00:986C 22 8C 80 01 JSL.L $808C ; Sprite engine call in bank $01 ($808C)
$00:9870 22 00 80 7F JSL.L RAM_7F8000 ; Move all sprites off-screen
$00:9874 60 RTS ; Return
;;; $9875..9875: Unused data (8 bytes) ;;;
$00:9875 .db $01,$00,$FF,$FF,$40,$00,$C0,$01 ; Unused data (8 bytes)
;;; $987D: Mode 7 boss room: per-frame update ;;;
;; Builds the Mode 7 matrix and runs the boss room code in bank $03 (bit 6 clear) or $9A52 (bit 6 set)
;; of [$0D9B].
;; Called by:
;; $00:A28F: Game mode 14: in level (InLevelGameMode)
$00:987D 20 CD 8A JSR.W $8ACD ; Mode 7 boss room per-frame: build the matrix ($8ACD)
$00:9880 2C 9B 0D BIT.W $0D9B ; Test [$0D9B] bit 6
$00:9883 50 03 BVC $9888 ; Bit 6 clear: go to $009888
$00:9885 4C 52 9A JMP.W $9A52 ; Bit 6 set: boss room frame code ($9A52)
$00:9888 22 00 80 7F JSL.L RAM_7F8000 ; Move all sprites off-screen
$00:988C 22 C6 C0 03 JSL.L $C0C6 ; Boss room code in bank $03 ($C0C6)
$00:9890 60 RTS ; Return
;;; $9891..98A1: Table: VRAM addresses for boss room tile updates ;;;
;; Word VRAM addresses used by $0098A9 (indexed by Y = 0..$16, two bytes each).
$00:9891 .db $9E,$12,$1E,$12,$9E,$11,$1E,$11 ; VRAM addresses for the boss room tile updates ($1E12, $119E, ...)
$00:9899 .db $1E,$16,$9E,$15,$1E,$15,$9E,$14 ; (table continued)
$00:98A1 .db $1E,$14,$9E,$13,$1E,$13,$9E,$16 ; (table continued)
;;; $98A9: Boss room tile animation and Mode 7 setup ;;;
;; $0098A9: called from NMI when [$0D9B] bit 6 is set. Animated tile DMA ([$14] selects the frame, VRAM $7800)
;; unless bit 0 is set,
;; then DMAs 4 or 8 byte chunks from $7E:C680 to the VRAM addresses in the table at $009891.
;; $009925: sets up the Mode 7 boss room (Mario position, scroll, stripe image of the room, floor tiles).
;; $009A1F/$009A3D: fill floor map16 tiles.
;; Called by:
;; $00:82DF: NMI tail: scroll, IRQ setup, Mode 7 path (NMINotSpecialLv)
$00:98A9 AD 9B 0D LDA.W $0D9B ; A = [$0D9B]
$00:98AC 4A LSR ; Bit 0 into carry
$00:98AD B0 32 BCS $98E1 ; Set: skip the animated tiles
$00:98AF A5 14 LDA RAM_FrameCounterB ; \
$00:98B1 4A LSR ; |
$00:98B2 4A LSR ; |
$00:98B3 29 06 AND.B #$06 ; } X = ([$14] >> 2) AND 6: animation frame * 2
$00:98B5 AA TAX ; /
$00:98B6 C2 20 REP #$20 ; A 16-bit
$00:98B8 A0 80 LDY.B #$80 ; \
$00:98BA 8C 15 21 STY.W $2115 ; / VMAIN = $80
$00:98BD A9 01 18 LDA.W #$1801 ; \
$00:98C0 8D 20 43 STA.W $4320 ; / DMA ch 2: mode 1 to $2118/$2119
$00:98C3 A9 00 78 LDA.W #$7800 ; \
$00:98C6 8D 16 21 STA.W $2116 ; / VRAM address = $7800
$00:98C9 BF 39 BA 05 LDA.L $BA39,X ; \
$00:98CD 8D 22 43 STA.W $4322 ; / DMA source = $BA39[X]
$00:98D0 A0 7E LDY.B #$7E ; \
$00:98D2 8C 24 43 STY.W $4324 ; / DMA source bank = $7E
$00:98D5 A9 80 00 LDA.W #$0080 ; \
$00:98D8 8D 25 43 STA.W $4325 ; / DMA size = $80
$00:98DB A0 04 LDY.B #$04 ; \
$00:98DD 8C 0B 42 STY.W $420B ; / Start DMA channel 2
$00:98E0 18 CLC ; Clear carry
$00:98E1 C2 20 REP #$20 ; A 16-bit
$00:98E3 A9 04 00 LDA.W #$0004 ; A = 4: bytes per update
$00:98E6 A0 06 LDY.B #$06 ; Y = 6: table offset of the last entry
$00:98E8 90 05 BCC $98EF ; Carry clear: keep these values
$00:98EA A9 08 00 LDA.W #$0008 ; A = 8
$00:98ED A0 16 LDY.B #$16 ; Y = $16
$00:98EF 85 00 STA $00 ; [$00] = bytes per update
$00:98F1 A9 80 C6 LDA.W #$C680 ; \
$00:98F4 85 02 STA $02 ; / [$02] = source address $C680 (bank $7E)
$00:98F6 9C 15 21 STZ.W $2115 ; VMAIN = 0: increment after low-byte writes
$00:98F9 A9 00 18 LDA.W #$1800 ; \
$00:98FC 8D 20 43 STA.W $4320 ; / DMA ch 2: mode 0 to $2118
$00:98FF A2 7E LDX.B #$7E ; \
$00:9901 8E 24 43 STX.W $4324 ; / DMA source bank = $7E
$00:9904 A2 04 LDX.B #$04 ; X = 4: channel 2 trigger
$00:9906 B9 91 98 LDA.W $9891,Y ; \
$00:9909 8D 16 21 STA.W $2116 ; / VRAM address = $9891[Y]
$00:990C A5 02 LDA $02 ; \
$00:990E 8D 22 43 STA.W $4322 ; / DMA source = [$02]
$00:9911 18 CLC ; \
$00:9912 65 00 ADC $00 ; } [$02] += [$00]
$00:9914 85 02 STA $02 ; /
$00:9916 A5 00 LDA $00 ; \
$00:9918 8D 25 43 STA.W $4325 ; / DMA size = [$00]
$00:991B 8E 0B 42 STX.W $420B ; Start DMA channel 2
$00:991E 88 DEY ; Y -= 2
$00:991F 88 DEY ; (second DEY)
$00:9920 10 E4 BPL $9906 ; Loop until Y is negative
$00:9922 E2 20 SEP #$20 ; A 8-bit
$00:9924 60 RTS ; Return
$00:9925 64 97 STZ RAM_MarioYPosHi ; Mode 7 boss room: Mario Y high byte = 0
$00:9927 C2 20 REP #$20 ; A 16-bit
$00:9929 A9 20 00 LDA.W #$0020 ; \
$00:992C 85 94 STA RAM_MarioXPos ; / Mario X position = $0020
$00:992E 64 1A STZ RAM_ScreenBndryXLo ; Layer 1 X position = 0
$00:9930 9C 62 14 STZ.W $1462 ; Mirror of layer 1 X = 0
$00:9933 64 1C STZ RAM_ScreenBndryYLo ; Layer 1 Y position = 0
$00:9935 9C 64 14 STZ.W $1464 ; Mirror of layer 1 Y = 0
$00:9938 A9 80 00 LDA.W #$0080 ; \
$00:993B 85 2A STA $2A ; / Mode 7 center X [$2A] = $0080
$00:993D A9 A0 00 LDA.W #$00A0 ; \
$00:9940 85 2C STA $2C ; / Mode 7 center Y [$2C] = $00A0
$00:9942 E2 20 SEP #$20 ; A 8-bit
$00:9944 20 15 AE JSR.W $AE15 ; $AE15
$00:9947 22 8C 80 01 JSL.L $808C ; Sprite engine call in bank $01 ($808C)
$00:994B AD 9B 0D LDA.W $0D9B ; A = [$0D9B]
$00:994E 4A LSR ; Bit 0 into carry
$00:994F A2 C0 LDX.B #$C0 ; X = $C0
$00:9951 A9 A0 LDA.B #$A0 ; A = $A0
$00:9953 90 06 BCC $995B ; Bit 0 clear: build the room tilemap
$00:9955 9C 11 14 STZ.W $1411 ; [$1411] = 0 (layer 1 horizontal scroll flag, probably)
$00:9958 4C 17 9A JMP.W $9A17 ; Go set Mario Y and fill tiles
$00:995B C2 30 REP #$30 ; A, X, Y 16-bit
$00:995D AD FC 13 LDA.W $13FC ; \
$00:9960 29 FF 00 AND.W #$00FF ; / A = [$13FC] (boss number)
$00:9963 0A ASL ; \
$00:9964 AA TAX ; / X = boss number * 2
$00:9965 A0 C0 02 LDY.W #$02C0 ; Y = $02C0
$00:9968 BD E8 F8 LDA.W $F8E8,X ; A = $F8E8[X]
$00:996B 10 03 BPL $9970 ; Positive: keep Y
$00:996D A0 80 FB LDY.W #$FB80 ; Negative: Y = $FB80
$00:9970 C9 12 00 CMP.W #$0012 ; \
$00:9973 D0 03 BNE $9978 ; / Entry $12?
$00:9975 A0 20 03 LDY.W #$0320 ; Yes: Y = $0320
$00:9978 84 00 STY $00 ; [$00] = Y (row spacing)
$00:997A A2 00 00 LDX.W #$0000 ; X = 0: offset in the stripe image buffer
$00:997D A9 5A C0 LDA.W #$C05A ; A = $C05A: VRAM address of the first record
$00:9980 9F 7D 83 7F STA.L $7F837D,X ; Stripe record 1 header at $7F:837D+X
$00:9984 EB XBA ; Swap to the high byte
$00:9985 18 CLC ; \
$00:9986 69 80 00 ADC.W #$0080 ; / VRAM address += $80
$00:9989 EB XBA ; Swap back
$00:998A 9F 01 84 7F STA.L $7F8401,X ; Stripe record 2 header at $7F:8401+X
$00:998E EB XBA ; Swap
$00:998F 38 SEC ; \
$00:9990 E5 00 SBC $00 ; / VRAM address -= [$00]
$00:9992 EB XBA ; Swap back
$00:9993 9F 85 84 7F STA.L $7F8485,X ; Stripe record 3 header at $7F:8485+X
$00:9997 A9 00 7F LDA.W #$7F00 ; A = $7F00: size word, 16 bytes (RLE off)
$00:999A 9F 7F 83 7F STA.L $7F837F,X ; Record 1 size
$00:999E 9F 03 84 7F STA.L $7F8403,X ; Record 2 size
$00:99A2 9F 87 84 7F STA.L $7F8487,X ; Record 3 size
$00:99A6 A0 10 00 LDY.W #$0010 ; Y = $10: 16 columns
$00:99A9 A9 A2 38 LDA.W #$38A2 ; A = $38A2: BG3 tile and attributes
$00:99AC 9F 81 83 7F STA.L $7F8381,X ; Record 1 tile 0
$00:99B0 1A INC A ; Next tile number
$00:99B1 9F 83 83 7F STA.L $7F8383,X ; Record 1 tile 1
$00:99B5 A9 B2 38 LDA.W #$38B2 ; A = $38B2
$00:99B8 9F C1 83 7F STA.L $7F83C1,X ; Record 1 tile 2 (second row)
$00:99BC 1A INC A ; Next tile number
$00:99BD 9F C3 83 7F STA.L $7F83C3,X ; Record 1 tile 3
$00:99C1 A9 80 2C LDA.W #$2C80 ; A = $2C80
$00:99C4 9F 05 84 7F STA.L $7F8405,X ; Record 2 tile 0
$00:99C8 1A INC A ; Next tile number
$00:99C9 9F 07 84 7F STA.L $7F8407,X ; Record 2 tile 1
$00:99CD 1A INC A ; Next tile number
$00:99CE 9F 45 84 7F STA.L $7F8445,X ; Record 2 tile 2
$00:99D2 1A INC A ; Next tile number
$00:99D3 9F 47 84 7F STA.L $7F8447,X ; Record 2 tile 3
$00:99D7 A9 A0 28 LDA.W #$28A0 ; A = $28A0
$00:99DA 9F 89 84 7F STA.L $7F8489,X ; Record 3 tile 0
$00:99DE 1A INC A ; Next tile number
$00:99DF 9F 8B 84 7F STA.L $7F848B,X ; Record 3 tile 1
$00:99E3 A9 B0 28 LDA.W #$28B0 ; A = $28B0
$00:99E6 9F C9 84 7F STA.L $7F84C9,X ; Record 3 tile 2
$00:99EA 1A INC A ; Next tile number
$00:99EB 9F CB 84 7F STA.L $7F84CB,X ; Record 3 tile 3
$00:99EF E8 INX ; \
$00:99F0 E8 INX ; |
$00:99F1 E8 INX ; } X += 4: next column
$00:99F2 E8 INX ; /
$00:99F3 88 DEY ; Count columns
$00:99F4 D0 B3 BNE $99A9 ; Loop for 16 columns
$00:99F6 8A TXA ; \
$00:99F7 18 CLC ; |
$00:99F8 69 4C 01 ADC.W #$014C ; } X += $014C: next group of records
$00:99FB AA TAX ; /
$00:99FC A9 5E C0 LDA.W #$C05E ; A = $C05E: VRAM address of the next group
$00:99FF E0 18 03 CPX.W #$0318 ; X < $0318?
$00:9A02 B0 03 BCS $9A07 ; Done: terminate the buffer
$00:9A04 4C 80 99 JMP.W $9980 ; No: build the next group
$00:9A07 A9 FF 00 LDA.W #$00FF ; \
$00:9A0A 9F 7D 83 7F STA.L $7F837D,X ; / Stripe image end marker in the buffer
$00:9A0E E2 30 SEP #$30 ; A, X, Y 8-bit
$00:9A10 20 D2 85 JSR.W LoadScrnImage ; Upload the stripe image (LoadScrnImage)
$00:9A13 A2 B0 LDX.B #$B0 ; X = $B0
$00:9A15 A9 90 LDA.B #$90 ; A = $90
$00:9A17 85 96 STA RAM_MarioYPos ; Mario Y position = A
$00:9A19 20 1F 9A JSR.W $9A1F ; Fill the floor tiles ($9A1F)
$00:9A1C 4C 83 92 JMP.W $9283 ; Set up the window HDMA ($9283)
$00:9A1F A0 10 LDY.B #$10 ; Y = $10: 16 tiles
$00:9A21 A9 32 LDA.B #$32 ; A = $32 (tile number)
$00:9A23 9F 00 C8 7E STA.L $7EC800,X ; Tile at $7EC800+X
$00:9A27 9F B0 C9 7E STA.L $7EC9B0,X ; Same tile $01B0 further on
$00:9A2B 9F 00 C8 7F STA.L $7FC800,X ; Same tile in the high table $7FC800+X
$00:9A2F 9F B0 C9 7F STA.L $7FC9B0,X ; Same in the high table $01B0 further on
$00:9A33 E8 INX ; Next tile
$00:9A34 88 DEY ; Count tiles
$00:9A35 D0 EC BNE $9A23 ; Loop for 16 tiles
$00:9A37 E0 C0 CPX.B #$C0 ; X = $C0?
$00:9A39 D0 12 BNE $9A4D ; No: done
$00:9A3B A2 D0 LDX.B #$D0 ; X = $D0
$00:9A3D A0 10 LDY.B #$10 ; Y = $10: 16 tiles
$00:9A3F A9 05 LDA.B #$05 ; A = $05 (tile number)
$00:9A41 9F 00 C8 7E STA.L $7EC800,X ; Tile at $7EC800+X
$00:9A45 9F B0 C9 7E STA.L $7EC9B0,X ; Same tile $01B0 further on
$00:9A49 E8 INX ; Next tile
$00:9A4A 88 DEY ; Count tiles
$00:9A4B D0 F4 BNE $9A41 ; Loop for 16 tiles
$00:9A4D 60 RTS ; Return
;;; $9A4E..9A4E: Unused data (4 bytes) ;;;
$00:9A4E .db $FF,$01,$18,$30 ; Unused data (4 bytes)
;;; $9A52: Boss room frame code (bit 6 set) ;;;
;; Scroll, run boss room code (banks $05 and $02) except for boss 4, otherwise just hide the sprites.
;; Called by:
;; $00:9885: Mode 7 boss room: per-frame update
$00:9A52 AD 9B 0D LDA.W $0D9B ; Mode 7 boss room frame code: A = [$0D9B]
$00:9A55 4A LSR ; Bit 0 into carry
$00:9A56 B0 17 BCS $9A6F ; Set: just hide the sprites
$00:9A58 22 DB F6 00 JSL.L $F6DB ; Handle screen scrolling ($F6DB)
$00:9A5C 22 00 BC 05 JSL.L $BC00 ; Boss room code in bank $05 ($BC00)
$00:9A60 AD FC 13 LDA.W $13FC ; A = [$13FC] (boss number)
$00:9A63 C9 04 CMP.B #$04 ; Boss 4?
$00:9A65 F0 08 BEQ $9A6F ; Yes: just hide the sprites
$00:9A67 20 C7 86 JSR.W $86C7 ; $86C7
$00:9A6A 22 7D 82 02 JSL.L $827D ; Sprite code in bank $02 ($827D)
$00:9A6E 60 RTS ; Return
$00:9A6F 22 00 80 7F JSL.L RAM_7F8000 ; Move all sprites off-screen
$00:9A73 60 RTS ; Return
;;; $9A74: Detect connected controllers into [$0DA0] (SetUp0DA0GM4) ;;;
;; Reads $4016/$4017 after auto-read. [$0DA0] = 0 or 1 (the only connected controller), or bit 7 set if both
;; are connected (use the current player's).
;; $009A8B: game mode 04 (prepare title screen): level load, stripe image $03, window and color math mirrors,
;; title circle HDMA.
;; Called by:
;; $00:941B: Set screen layers; game modes 01 and 06 (ScreenSettings)
;; $00:9A8B: Detect connected controllers into [$0DA0] (SetUp0DA0GM4)
;; $00:9ACC: Menu cursor handler
;; $00:9C64: Game mode 07: title screen and demo (GAMEMODE_07)
;; $00:A1BE: Clear RAM; game mode 0E: overworld (Clear_1A_13D3)
$00:9A74 AD 16 40 LDA.W $4016 ; Read controller 1 data line: bit 0 = connected
$00:9A77 4A LSR ; Bit 0 into carry
$00:9A78 AD 17 40 LDA.W $4017 ; Read controller 2 data line
$00:9A7B 2A ROL ; Controller 2 bit in bit 1, controller 1 bit in bit 0
$00:9A7C 29 03 AND.B #$03 ; Bit 0 = controller 1 connected, bit 1 = controller 2 connected
$00:9A7E F0 07 BEQ $9A87 ; None connected: use controller 1 data (index 0)
$00:9A80 C9 03 CMP.B #$03 ; \
$00:9A82 D0 02 BNE $9A86 ; / Both connected?
$00:9A84 09 80 ORA.B #$80 ; Both connected: set bit 7 (use the current player's controller)
$00:9A86 3A DEC A ; Index of the controller to use: 0 = controller 1, 1 = controller 2
$00:9A87 8D A0 0D STA.W $0DA0 ; [$0DA0] = index (negative = current player)
$00:9A8A 60 RTS ; Return
$00:9A8B 20 74 9A JSR.W SetUp0DA0GM4 ; Game mode 04: set up [$0DA0] (SetUp0DA0GM4)
$00:9A8E 20 9C A5 JSR.W GM04Load ; Load the level (GM04Load)
$00:9A91 9C 31 0F STZ.W $0F31 ; Level timer [$0F31] = 0
$00:9A94 20 FA 85 JSR.W $85FA ; Clear BG3 and sprites ($85FA)
$00:9A97 A9 03 LDA.B #$03 ; \
$00:9A99 85 12 STA $12 ; / Stripe image $03 (title screen)
$00:9A9B 20 D2 85 JSR.W LoadScrnImage ; Upload the stripe image (LoadScrnImage)
$00:9A9E 20 A6 AD JSR.W $ADA6 ; $ADA6
$00:9AA1 20 2F 92 JSR.W $922F ; Set up the CGRAM DMA for the palette buffer ($922F)
$00:9AA4 22 75 F6 04 JSL.L $F675 ; Title screen code in bank $04 ($F675)
$00:9AA8 A9 01 LDA.B #$01 ; \
$00:9AAA 8D 9B 0D STA.W $0D9B ; / Special level mode [$0D9B] = 1
$00:9AAD A9 33 LDA.B #$33 ; \
$00:9AAF 85 41 STA $41 ; / Window mask mirror [$41] = $33
$00:9AB1 A9 00 LDA.B #$00 ; \
$00:9AB3 85 42 STA $42 ; / Window mask mirror [$42] = $00
$00:9AB5 A9 23 LDA.B #$23 ; \
$00:9AB7 85 43 STA $43 ; / Window mask mirror [$43] = $23
$00:9AB9 A9 12 LDA.B #$12 ; \
$00:9ABB 85 44 STA $44 ; / Color math mirror [$44] = $12
$00:9ABD 20 43 94 JSR.W $9443 ; Set up the title circle HDMA ($9443)
$00:9AC0 A9 10 LDA.B #$10 ; \
$00:9AC2 8D F5 1D STA.W $1DF5 ; / [$1DF5] = $10 (purpose unclear)
$00:9AC5 4C F7 93 JMP.W Mode04Finish ; Enable NMI and joypad and return (Mode04Finish)
;;; $9AC8..9AC8: Table: menu cursor movement ;;;
;; +1 (Down), -1 (Up), -1 (both).
$00:9AC8 .db $01,$FF,$FF ; Cursor movement: +1 for Down, -1 for Up, -1 for both
;;; $9ACB: Menu cursor handler ;;;
;; Reads D-pad, Select and A/B/Start, moves cursor [$1B92] within [$8A] entries (wraps), plays sounds via
;; [$1DFC].
;; Quirk: returns twice (pops the caller's return address) unless B, Start or A is pressed.
;; Parameters: Y: cursor graphics parameter passed to $9E82.
;; Called by:
;; $00:9CDD: Game mode 08: file select, mode 0A: players
;; $00:9E0A: Game mode 08: file select, mode 0A: players
$00:9ACB 5A PHY ; Menu cursor handler: save Y (cursor graphics parameter)
$00:9ACC 20 74 9A JSR.W SetUp0DA0GM4 ; Read the controller setup (SetUp0DA0GM4)
$00:9ACF 7A PLY ; Restore Y
$00:9AD0 EE 91 1B INC.W $1B91 ; [$1B91]++ (cursor blink counter)
$00:9AD3 20 82 9E JSR.W $9E82 ; Draw the cursor ($9E82)
$00:9AD6 AE 92 1B LDX.W $1B92 ; X = [$1B92] (current cursor position)
$00:9AD9 A5 16 LDA $16 ; \
$00:9ADB 29 90 AND.B #$90 ; / New B or Start press ([$16] AND $90)?
$00:9ADD D0 04 BNE $9AE3 ; Yes: confirm
$00:9ADF A5 18 LDA $18 ; A = [$18] (new A press)
$00:9AE1 10 07 BPL $9AEA ; Not pressed: go handle the D-pad
$00:9AE3 A9 01 LDA.B #$01 ; \
$00:9AE5 8D FC 1D STA.W $1DFC ; / Sound request [$1DFC] = 1 (confirm)
$00:9AE8 80 27 BRA $9B11 ; Go reset the cursor position
$00:9AEA 68 PLA ; Pop the return address: skip the caller's confirm code
$00:9AEB 68 PLA ; (second PLA)
$00:9AEC A5 16 LDA $16 ; \
$00:9AEE 29 20 AND.B #$20 ; / A = new presses ([$16]) AND $20 (Select)
$00:9AF0 4A LSR ; Shift Select into the Down bit
$00:9AF1 4A LSR ; (shift)
$00:9AF2 4A LSR ; (shift)
$00:9AF3 05 16 ORA $16 ; Combine with the D-pad bits
$00:9AF5 29 0C AND.B #$0C ; Keep Down ($04) and Up ($08)
$00:9AF7 F0 1D BEQ $9B16 ; Neither pressed: return to the caller's caller
$00:9AF9 A0 06 LDY.B #$06 ; \
$00:9AFB 8C FC 1D STY.W $1DFC ; / Sound request [$1DFC] = 6 (cursor move)
$00:9AFE 9C 91 1B STZ.W $1B91 ; Reset the blink counter
$00:9B01 4A LSR ; Shift the direction bits
$00:9B02 4A LSR ; (shift)
$00:9B03 A8 TAY ; Y = 1 (Down), 2 (Up) or 3 (both)
$00:9B04 8A TXA ; A = old cursor position
$00:9B05 79 C7 9A ADC.W $9AC8-1,Y ; Add the movement from $9AC8-1[Y]
$00:9B08 10 03 BPL $9B0D ; Not negative: check the upper limit
$00:9B0A A5 8A LDA $8A ; Negative: wrap to the last entry, [$8A] - 1
$00:9B0C 3A DEC A ; (decrement)
$00:9B0D C5 8A CMP $8A ; New position < [$8A] (number of entries)?
$00:9B0F 90 02 BCC $9B13 ; Yes: keep it
$00:9B11 A9 00 LDA.B #$00 ; Position = 0 (wrap to the first entry, or reset after confirm)
$00:9B13 8D 92 1B STA.W $1B92 ; [$1B92] = new cursor position
$00:9B16 60 RTS ; Return
;;; $9B17..9B17: Unused data (3 bytes) ;;;
$00:9B17 .db $04,$02,$01 ; Unused data (3 bytes)
;;; $9B1A: Game mode 09: erase file menu ;;;
;; Game mode 09. Draws the ERASE DATA screen on top of the file select. The cursor chooses files (marking them
;; in [$0DDE], bit 2 = file 0,
;; bit 0 = file 2) or END. On END, all marked files are cleared from both SRAM copies. Y or X cancels back to
;; file select.
;; $009B80: long-call wrapper (called from the overworld in bank $04) that runs the CONTINUE/END menu for
;; state [$13C9] - 1.
$00:9B1A C2 20 REP #$20 ; \
$00:9B1C A9 C9 39 LDA.W #$39C9 ; |
$00:9B1F A0 60 LDY.B #$60 ; } BG color = $39C9, CGADSUB = $60 ($9D30)
$00:9B21 20 30 9D JSR.W $9D30 ; /
$00:9B24 A5 16 LDA $16 ; A = buttons just pressed on controller 1 ([$16])
$00:9B26 05 18 ORA $18 ; Or in controller 2's ([$18])
$00:9B28 29 40 AND.B #$40 ; Keep bit 6 (Y on pad 1, X on pad 2): the cancel buttons
$00:9B2A F0 0C BEQ $9B38 ; Not pressed: go handle the menu
$00:9B2C CE 00 01 DEC.W RAM_GameMode ; \
$00:9B2F CE 00 01 DEC.W RAM_GameMode ; / Game mode -= 2 (back to file select; $9CB0 increments once)
$00:9B32 20 11 9B JSR.W $9B11 ; Cursor position [$1B92] = 0 ($9B11)
$00:9B35 4C B0 9C JMP.W $9CB0 ; Rebuild the file select screen and move on
$00:9B38 A0 08 LDY.B #$08 ; Y = 8: 4 menu entries (3 files + END)
$00:9B3A 20 D0 9A JSR.W $9AD0 ; Move the cursor / wait for a selection (returns X = entry only on selection)
$00:9B3D E0 03 CPX.B #$03 ; Entry 3 (END) selected?
$00:9B3F D0 2C BNE $9B6D ; No: a file was toggled, go mark it
$00:9B41 A0 02 LDY.B #$02 ; Y = 2: start with file 2, loop down to file 0
$00:9B43 4E DE 0D LSR.W $0DDE ; Shift marked-for-erase bits [$0DDE]; carry = this file is marked
$00:9B46 90 1F BCC $9B67 ; Not marked: next file
$00:9B48 5A PHY ; Save file number
$00:9B49 B9 CB 9C LDA.W $9CCB,Y ; A = high byte of this file's SRAM offset
$00:9B4C EB XBA ; Move it to the high half of A
$00:9B4D B9 CE 9C LDA.W $9CCE,Y ; A = low byte of the offset
$00:9B50 C2 10 REP #$10 ; Index registers 16-bit
$00:9B52 AA TAX ; X = SRAM offset of the file
$00:9B53 A0 8F 00 LDY.W #$008F ; Y = $008F: bytes per file slot
$00:9B56 A9 00 LDA.B #$00 ; Fill value = 0
$00:9B58 9F 00 00 70 STA.L $700000,X ; Clear a byte of the primary copy at $70:0000+X
$00:9B5C 9F AD 01 70 STA.L $7001AD,X ; Clear the same byte of the backup copy ($1AD bytes later)
$00:9B60 E8 INX ; Next byte
$00:9B61 88 DEY ; Count down
$00:9B62 D0 F4 BNE $9B58 ; Repeat for the whole slot
$00:9B64 E2 10 SEP #$10 ; Index registers 8-bit
$00:9B66 7A PLY ; Restore file number
$00:9B67 88 DEY ; Next file
$00:9B68 10 D9 BPL $9B43 ; Loop for files 2, 1, 0
$00:9B6A 4C 89 9C JMP.W $9C89 ; Erase done: game mode = 2 (back to the title screen)
$00:9B6D 8E 92 1B STX.W $1B92 ; Cursor position [$1B92] = file
$00:9B70 BD 17 9B LDA.W $9B17,X ; A = bit for this file ($04, $02, $01)
$00:9B73 0D DE 0D ORA.W $0DDE ; \
$00:9B76 8D DE 0D STA.W $0DDE ; / [$0DDE] |= file bit (file is marked for erasing)
$00:9B79 85 05 STA $05 ; Pass the marked bits to the tilemap code in [$05]
$00:9B7B A2 00 LDX.B #$00 ; X = 0: erase-menu stripe data offset
$00:9B7D 4C 3C 9D JMP.W $9D3C ; Rebuild the menu tilemap (marked files show EMPTY)
$00:9B80 8B PHB ; \
$00:9B81 4B PHK ; } Data bank = $00 (wrapper for the long call from bank $04)
$00:9B82 AB PLB ; /
$00:9B83 20 88 9B JSR.W $9B88 ; Run the Continue/End game over menu
$00:9B86 AB PLB ; Restore data bank
$00:9B87 6B RTL ; Return long
$00:9B88 3A DEC A ; A = [$13C9] - 1 (menu state)
$00:9B89 22 DF 86 00 JSL.L ExecutePtr ; Run the routine for the state (ExecutePtr)
;;; $9B8D: Pointer table: Continue/End menu, save prompt (Ptrs009B8D) ;;;
;; $009B8D: pointers for [$13C9] = 1 (draw CONTINUE/END) and 2 (run the menu: CONTINUE resets lives, END
;; returns to the title).
;; $009BA8: wrapper for the overworld save prompt; entry 0 saves the game with the jingle ($1DF9 = 5), then
;; closes the prompt.
;; $009BC9: save game routine. Copies $8D bytes from $1F49 to the file's SRAM slot at $70:xxxx plus a 16-bit
;; checksum ($5A5A - sum),
;; and writes the same to the backup copy $1AD bytes later. Parameters: [$010A] = file number.
;; $009C13: closes the message box ([$1B87]++, [$1B88]++) and clears the stripe buffer with image $1B.
$00:9B8D 91 9B .dw $9B91 ; State 1: show the CONTINUE/END text
$00:9B8F 9A 9B .dw $9B9A ; State 2: run the menu
$00:9B91 A0 0C LDY.B #$0C ; Y = $0C: stripe image CONTINUE/END
$00:9B93 20 29 9D JSR.W $9D29 ; Show it (clears the RAM stripe buffer, [$12] = Y)
$00:9B96 EE C9 13 INC.W $13C9 ; [$13C9]++: next state, the menu itself
$00:9B99 60 RTS ; Return
$00:9B9A A0 00 LDY.B #$00 ; Y = 0: menu of 2 entries (CONTINUE, END)
$00:9B9C 20 D0 9A JSR.W $9AD0 ; Move the cursor (returns only when an entry is chosen)
$00:9B9F 8A TXA ; A = chosen entry
$00:9BA0 D0 03 BNE $9BA5 ; END: go to the title screen
$00:9BA2 4C 17 9E JMP.W $9E17 ; CONTINUE: reset the player data and go on
$00:9BA5 4C 89 9C JMP.W $9C89 ; Game mode = 2 (title screen)
$00:9BA8 8B PHB ; \
$00:9BA9 4B PHK ; } Data bank = $00 (wrapper for the long call from bank $04)
$00:9BAA AB PLB ; /
$00:9BAB 20 B0 9B JSR.W $9BB0 ; Run the save prompt
$00:9BAE AB PLB ; Restore data bank
$00:9BAF 6B RTL ; Return long
$00:9BB0 A0 06 LDY.B #$06 ; Y = 6: menu of 2 entries (save / don't save)
$00:9BB2 20 D0 9A JSR.W $9AD0 ; Move the cursor (returns only when an entry is chosen)
$00:9BB5 8A TXA ; A = chosen entry
$00:9BB6 D0 0C BNE $9BC4 ; Second entry: skip saving
$00:9BB8 9C FC 1D STZ.W $1DFC ; Clear the sound request port $1DFC
$00:9BBB A9 05 LDA.B #$05 ; Sound effect $05 ...
$00:9BBD 8D F9 1D STA.W $1DF9 ; ... on $1DF9 (save game jingle)
$00:9BC0 22 C9 9B 00 JSL.L $9BC9 ; Write the current game to SRAM
$00:9BC4 22 13 9C 00 JSL.L $9C13 ; Close the prompt ($9C13)
$00:9BC8 60 RTS ; Return
;V Save game routine
$00:9BC9 8B PHB ; \
$00:9BCA 4B PHK ; } Data bank = $00
$00:9BCB AB PLB ; /
$00:9BCC AE 0A 01 LDX.W $010A ; X = save file number ([$010A])
$00:9BCF BD CB 9C LDA.W $9CCB,X ; A = high byte of this file's SRAM offset (0, 0, 1)
$00:9BD2 EB XBA ; Move it to the high half of A
$00:9BD3 BD CE 9C LDA.W $9CCE,X ; A = low byte of the offset (00, 8F, 1E)
$00:9BD6 C2 10 REP #$10 ; Index registers 16-bit
$00:9BD8 AA TAX ; X = SRAM offset of the file
$00:9BD9 A0 00 00 LDY.W #$0000 ; Y = 0: index into the save data in RAM
$00:9BDC 84 8A STY $8A ; Checksum sum [$8A] = 0
$00:9BDE B9 49 1F LDA.W $1F49,Y ; A = byte of the save data at $1F49+Y
$00:9BE1 9F 00 00 70 STA.L $700000,X ; Write it to SRAM $70:0000+X
$00:9BE5 18 CLC ; \
$00:9BE6 65 8A ADC $8A ; } [$8A] += A (16-bit running sum)
$00:9BE8 85 8A STA $8A ; /
$00:9BEA 90 02 BCC $9BEE ; \
$00:9BEC E6 8B INC $8B ; / Add the carry into [$8B]
$00:9BEE E8 INX ; Next SRAM byte
$00:9BEF C8 INY ; Next RAM byte
$00:9BF0 C0 8D 00 CPY.W #$008D ; All $8D bytes copied?
$00:9BF3 90 E9 BCC $9BDE ; No: loop
$00:9BF5 C2 20 REP #$20 ; A 16-bit
$00:9BF7 A9 5A 5A LDA.W #$5A5A ; A = $5A5A
$00:9BFA 38 SEC ; Set carry
$00:9BFB E5 8A SBC $8A ; A = $5A5A - sum: the checksum word
$00:9BFD 9F 00 00 70 STA.L $700000,X ; Store it after the data (offset $8D)
$00:9C01 E0 AD 01 CPX.W #$01AD ; X >= $01AD? (the backup copy was just written)
$00:9C04 B0 09 BCS $9C0F ; Yes: finished
$00:9C06 8A TXA ; A = X
$00:9C07 69 20 01 ADC.W #$0120 ; A += $0120 (carry is clear): X = offset of the backup copy ($1AD above the primary)
$00:9C0A AA TAX ; X = backup copy offset
$00:9C0B E2 20 SEP #$20 ; A 8-bit
$00:9C0D 80 CA BRA $9BD9 ; Write the second copy
$00:9C0F E2 30 SEP #$30 ; A, X and Y 8-bit
$00:9C11 AB PLB ; Restore data bank
$00:9C12 6B RTL ; Return long
$00:9C13 EE 87 1B INC.W $1B87 ; [$1B87]++ (overworld message box state: advance)
$00:9C16 EE 88 1B INC.W $1B88 ; [$1B88]++ (message box expanding flag)
$00:9C19 A0 1B LDY.B #$1B ; Y = $1B: stripe image (replaces the prompt)
;;; $9C1B: Tail of CODE_009C13 (JSR $9D29) (Instr009C1B) ;;;
;; These bytes are the opcodes for JSR $9D29 (show stripe image Y) listed as data; the RTL after them returns
;; from $9C13.
$00:9C1B .db $20,$29,$9D ; Opcode bytes for JSR $9D29 (disassembled as data)
$00:9C1E 6B RTL ; Return long
;;; $9C1F: Title demo: first buttons byte (IntroControlData) ;;;
;; Buttons for demo segment 0 (Y + Right); the segment's duration is in ItrCntrlrSqnc.
$00:9C1F .db $41 ; Demo script: controller 1 buttons for the first segment (Y + Right)
;;; $9C20: Title screen demo input script (ItrCntrlrSqnc) ;;;
;; Recorded controller input for the title screen demo (Mario plays the intro level by himself). Buttons and
;; times alternate: the first
;; buttons byte is at $009C1F, then time, buttons, time, ... Buttons use the format of [$15] (B Y Select Start
;; Up Down Left Right).
;; $FF as buttons ends the demo.
$00:9C20 .db $0F,$C1,$30,$00,$10,$42,$20,$41 ; Time/buttons alternate: [time, buttons] pairs, first time $0F
$00:9C28 .db $70,$81,$11,$00,$80,$82,$0C,$00 ; Demo script, continued
$00:9C30 .db $30,$C1,$30,$41,$60,$C1,$10,$00 ; Demo script, continued
$00:9C38 .db $40,$01,$30,$E1,$01,$00,$60,$41 ; Demo script, continued
$00:9C40 .db $4E,$80,$10,$00,$30,$41,$58,$00 ; Demo script, continued
$00:9C48 .db $20,$60,$01,$00,$30,$60,$01,$00 ; Demo script, continued
$00:9C50 .db $30,$60,$01,$00,$30,$60,$01,$00 ; Demo script, continued
$00:9C58 .db $30,$60,$01,$00,$30,$41,$1A,$C1 ; Demo script, continued
$00:9C60 .db $30,$00,$30,$FF ; Demo script end: buttons $FF finishes the demo
;;; $9C64: Game mode 07: title screen and demo (GAMEMODE_07) ;;;
;; Runs the title screen. A press of B, Y, Select, Start, A or X ($9CBE) leaves for the file select
;; (game mode 08).
;; Otherwise the scripted input from ItrCntrlrSqnc is fed to the controller mirrors and the level engine runs
;; the demo.
;; When the script ends the game mode is set to 2 and the title screen restarts. $009C89 is shared as 'go to
;; game mode 2'.
;; $009CBE: Returns: Z = clear if no button is pressed.
$00:9C64 20 74 9A JSR.W SetUp0DA0GM4 ; Check which controllers are connected (SetUp0DA0GM4)
$00:9C67 20 BE 9C JSR.W $9CBE ; Any of the buttons B, Y, Select, Start, A, X pressed? (Z = no)
$00:9C6A D0 33 BNE $9C9F ; Yes: leave the title screen
$00:9C6C 20 2D F6 JSR.W NoButtons ; Clear the controller mirrors ([$15]-[$18])
$00:9C6F AE F4 1D LDX.W $1DF4 ; X = offset into the demo script [$1DF4]
$00:9C72 CE F5 1D DEC.W $1DF5 ; Demo time left [$1DF5]--
$00:9C75 D0 0B BNE $9C82 ; Not elapsed: keep the current buttons
$00:9C77 BD 20 9C LDA.W ItrCntrlrSqnc,X ; A = time of the next segment
$00:9C7A 8D F5 1D STA.W $1DF5 ; [$1DF5] = it
$00:9C7D E8 INX ; \
$00:9C7E E8 INX ; / X += 2: next segment
$00:9C7F 8E F4 1D STX.W $1DF4 ; Save the script offset
$00:9C82 BD 1D 9C LDA.W ADDR_009C1D,X ; A = buttons of the current segment
$00:9C85 C9 FF CMP.B #$FF ; $FF is the end marker
$00:9C87 D0 06 BNE $9C8F ; Not the end: apply the buttons
$00:9C89 A0 02 LDY.B #$02 ; Y = 2
$00:9C8B 8C 00 01 STY.W RAM_GameMode ; Game mode = 2 (fade to title screen again, demo restarts)
$00:9C8E 60 RTS ; Return
$00:9C8F 29 DF AND.B #$DF ; Clear bit 5 (Select)
$00:9C91 85 15 STA RAM_ControllerA ; Controller 1 held buttons [$15] = A
$00:9C93 DD 1D 9C CMP.W ADDR_009C1D,X ; Compare with the table value
$00:9C96 D0 02 BNE $9C9A ; Differs (Select was set): keep A
$00:9C98 29 9F AND.B #$9F ; Clear bits 6-5 (Y, Select) for the just-pressed copy
$00:9C9A 85 16 STA $16 ; Controller 1 just pressed [$16] = A
$00:9C9C 4C DA A1 JMP.W InLevelGameMode ; Run the level (demo plays on screen)
$00:9C9F 22 00 80 7F JSL.L RAM_7F8000 ; Hide all sprites (RAM routine at $7F8000)
$00:9CA3 A9 04 LDA.B #$04 ; A = $04
$00:9CA5 8D 2C 21 STA.W $212C ; Main screen = BG3 only
$00:9CA8 A9 13 LDA.B #$13 ; A = $13
$00:9CAA 8D 2D 21 STA.W $212D ; Sub screen = BG1, BG2 and sprites
$00:9CAD 9C 9F 0D STZ.W $0D9F ; Disable all HDMA
$00:9CB0 A9 E9 LDA.B #$E9 ; A = $E9
$00:9CB2 8D 09 01 STA.W $0109 ; [$0109] = $E9 (intro level flag; $E9 - $24 = $C5)
$00:9CB5 20 06 9F JSR.W CODE_WRITEOW ; Initialize new save data (CODE_WRITEOW)
$00:9CB8 20 38 9D JSR.W $9D38 ; Draw the file select tilemap ($9D38)
$00:9CBB 4C 17 94 JMP.W $9417 ; Game mode++ and return
$00:9CBE A5 17 LDA RAM_ControllerB ; A = controller 1 byte 2 ([$17], A X L R)
$00:9CC0 29 C0 AND.B #$C0 ; Keep A and X
$00:9CC2 D0 06 BNE $9CCA ; Pressed: return NZ
$00:9CC4 A5 15 LDA RAM_ControllerA ; A = controller 1 byte 1 ([$15], B Y Select Start D-pad)
$00:9CC6 29 F0 AND.B #$F0 ; Keep B, Y, Select, Start
$00:9CC8 D0 00 BNE $9CCA ; Pressed: return NZ (BNE to the next instruction either way)
$00:9CCA 60 RTS ; Return (Z = no button pressed)
;;; $9CCB..9CCE: Table: SRAM offsets of save files ;;;
;; High and low bytes of the SRAM offset of each of the 3 save files ($0000, $008F, $011E; $8F bytes each).
;; The backup copy is $1AD bytes after.
$00:9CCB .db $00,$00,$01 ; SRAM offset high bytes of the 3 save files
$00:9CCE .db $00,$8F,$1E ; SRAM offset low bytes (offsets $0000, $008F, $011E)
;;; $9CD1: Game mode 08: file select, mode 0A: players ;;;
;; $009CD1: file select (game mode 08). Selecting ERASE DATA goes to game mode 09. Selecting a file checks its
;; checksum, repairs the
;; other copy from the good one, loads the file into $1F49-$1FD5 and goes to the player select (game mode 0A).
;; $009D38: copies the file menu tilemap into the stripe buffer and prints each file's exit count. $009DB5:
;; verifies a file's checksum
;; (sum of $8D bytes + stored word = $5A5A) with fallback to the backup copy; returns Z set when valid, X =
;; offset of the valid copy.
;; $009DFA: game mode 0A: 1 PLAYER / 2 PLAYER; $009E17 resets lives, powerups and score for a new game and
;; goes to game mode $0B.
$00:9CD1 C2 20 REP #$20 ; \
$00:9CD3 A9 93 73 LDA.W #$7393 ; |
$00:9CD6 A0 20 LDY.B #$20 ; } BG color = $7393, CGADSUB = $20 ($9D30)
$00:9CD8 20 30 9D JSR.W $9D30 ; /
$00:9CDB A0 02 LDY.B #$02 ; \
$00:9CDD 20 CB 9A JSR.W $9ACB ; / Menu with 4 entries (Y = 2); returns only when one is chosen
$00:9CE0 EE 00 01 INC.W RAM_GameMode ; Game mode++ (09, erase file, unless a file is picked)
$00:9CE3 E0 03 CPX.B #$03 ; \
$00:9CE5 D0 08 BNE $9CEF ; / Branch unless entry 3 (ERASE DATA) was chosen
$00:9CE7 9C DE 0D STZ.W $0DDE ; No files marked for erasing yet ([$0DDE] = 0)
$00:9CEA A2 00 LDX.B #$00 ; \
$00:9CEC 4C 3A 9D JMP.W $9D3A ; / Show the erase data menu (stripe data offset 0)
$00:9CEF 8E 0A 01 STX.W $010A ; Save file number [$010A] = chosen file
$00:9CF2 20 B5 9D JSR.W $9DB5 ; Verify the checksum ($9DB5); X = valid copy, Y = other copy
$00:9CF5 D0 2B BNE $9D22 ; Bad data or empty file: start a new game
$00:9CF7 DA PHX ; Save X (offset of the valid copy)
$00:9CF8 9C 09 01 STZ.W $0109 ; [$0109] = 0: no intro level
$00:9CFB A9 8F LDA.B #$8F ; A = $8F: bytes per file slot
$00:9CFD 85 00 STA $00 ; Counter [$00] = $8F
$00:9CFF BF 00 00 70 LDA.L $700000,X ; A = byte of the valid copy
$00:9D03 DA PHX ; Save X
$00:9D04 BB TYX ; X = Y (offset of the other copy)
$00:9D05 9F 00 00 70 STA.L $700000,X ; Write the byte there
$00:9D09 FA PLX ; Restore X
$00:9D0A E8 INX ; Next source byte
$00:9D0B C8 INY ; Next destination byte
$00:9D0C C6 00 DEC $00 ; Count down
$00:9D0E D0 EF BNE $9CFF ; Loop: both copies now identical
$00:9D10 FA PLX ; X = offset of the valid copy
$00:9D11 A0 00 00 LDY.W #$0000 ; Y = 0
$00:9D14 BF 00 00 70 LDA.L $700000,X ; A = byte of the save file
$00:9D18 99 49 1F STA.W $1F49,Y ; Copy to the working save data $1F49+Y
$00:9D1B E8 INX ; Next source byte
$00:9D1C C8 INY ; Next destination byte
$00:9D1D C0 8D 00 CPY.W #$008D ; All $8D bytes copied?
$00:9D20 90 F2 BCC $9D14 ; No: loop
$00:9D22 E2 10 SEP #$10 ; Index registers 8-bit
$00:9D24 A0 12 LDY.B #$12 ; \
$00:9D26 EE 00 01 INC.W RAM_GameMode ; / Y = $12 (stripe image: 1 PLAYER GAME / 2 PLAYER GAME); game mode++ (0A)
$00:9D29 84 12 STY $12 ; Stripe image [$12] = Y
$00:9D2B A2 00 LDX.B #$00 ; X = 0: empty the RAM stripe buffer
$00:9D2D 4C D4 9E JMP.W $9ED4 ; Reset the buffer and return
$00:9D30 8D 01 07 STA.W $0701 ; BG color (CGRAM mirror $0701) = A
$00:9D33 84 40 STY $40 ; CGADSUB mirror [$40] = Y
$00:9D35 E2 20 SEP #$20 ; A 8-bit
$00:9D37 60 RTS ; Return
$00:9D38 A2 CB LDX.B #$CB ; X = $CB: offset of the file select menu in $B6FE
$00:9D3A 64 05 STZ $05 ; No files treated as empty
$00:9D3C C2 10 REP #$10 ; Index registers 16-bit
$00:9D3E A0 00 00 LDY.W #$0000 ; Y = 0: write index into the stripe buffer
$00:9D41 BF FE B6 05 LDA.L $B6FE,X ; A = menu tilemap data, X = read index
$00:9D45 DA PHX ; Save X
$00:9D46 BB TYX ; X = Y (write index)
$00:9D47 9F 7D 83 7F STA.L $7F837D,X ; Store in the RAM stripe buffer $7F:837D
$00:9D4B FA PLX ; Restore X
$00:9D4C E8 INX ; Next source byte
$00:9D4D C8 INY ; Next buffer byte
$00:9D4E C0 CC 00 CPY.W #$00CC ; Copied $CC bytes?
$00:9D51 D0 EE BNE $9D41 ; No: loop
$00:9D53 E2 10 SEP #$10 ; Index registers 8-bit
$00:9D55 A9 84 LDA.B #$84 ; A = $84
$00:9D57 85 00 STA $00 ; [$00] = $84: buffer offset of file 2's exits count (the last entry)
$00:9D59 A2 02 LDX.B #$02 ; \
$00:9D5B 86 04 STX $04 ; / File counter [$04] = 2 (files 2, 1, 0)
$00:9D5D 46 05 LSR $05 ; \
$00:9D5F B0 45 BCS $9DA6 ; / Next bit of [$05]; 1 = file is empty, keep the EMPTY text
$00:9D61 20 B5 9D JSR.W $9DB5 ; Verify the checksum of file X ($9DB5)
$00:9D64 D0 40 BNE $9DA6 ; Invalid: keep the EMPTY text
$00:9D66 BF 8C 00 70 LDA.L $70008C,X ; A = number of exits completed in this file
$00:9D6A E2 10 SEP #$10 ; Index registers 8-bit
$00:9D6C C9 60 CMP.B #$60 ; \
$00:9D6E 90 06 BCC $9D76 ; / Exits < 96: print as number
$00:9D70 A0 87 LDY.B #$87 ; \
$00:9D72 A9 88 LDA.B #$88 ; / Exits = 96: two tiles $87 and $88 (the 96 graphic)
$00:9D74 80 04 BRA $9D7A ; Skip the decimal conversion
$00:9D76 20 45 90 JSR.W HexToDec ; A = ones, X = tens (HexToDec)
$00:9D79 9B TXY ; Y = tens
$00:9D7A A6 00 LDX $00 ; X = buffer offset of this file's entry
$00:9D7C 9F 81 83 7F STA.L $7F8381,X ; Store the ones tile
$00:9D80 98 TYA ; \
$00:9D81 D0 02 BNE $9D85 ; / Tens digit zero? Then use a blank tile
$00:9D83 A0 FC LDY.B #$FC ; Y = $FC: blank tile
$00:9D85 98 TYA ; A = tens tile
$00:9D86 9F 7F 83 7F STA.L $7F837F,X ; Store the tens tile
$00:9D8A A9 38 LDA.B #$38 ; A = $38: tile properties (palette, priority)
$00:9D8C 9F 80 83 7F STA.L $7F8380,X ; \
$00:9D90 9F 82 83 7F STA.L $7F8382,X ; / Set the properties of both digit tiles
$00:9D94 C2 20 REP #$20 ; A 16-bit
$00:9D96 A0 03 LDY.B #$03 ; Y = 3: three more tiles
$00:9D98 A9 FC 38 LDA.W #$38FC ; A = blank tile with properties $38
$00:9D9B 9F 83 83 7F STA.L $7F8383,X ; Overwrite the rest of the word EMPTY
$00:9D9F E8 INX ; Next tile
$00:9DA0 E8 INX ; (2 bytes per tile)
$00:9DA1 88 DEY ; Count down
$00:9DA2 D0 F4 BNE $9D98 ; Loop
$00:9DA4 E2 20 SEP #$20 ; A 8-bit
$00:9DA6 E2 10 SEP #$10 ; Index registers 8-bit
$00:9DA8 A5 00 LDA $00 ; \
$00:9DAA 38 SEC ; } Buffer offset [$00] -= $24 (size of one file entry)
$00:9DAB E9 24 SBC.B #$24 ; /
$00:9DAD 85 00 STA $00 ; Save it
$00:9DAF A6 04 LDX $04 ; \
$00:9DB1 CA DEX ; } File counter - 1; repeat until file 0 is done
$00:9DB2 10 A7 BPL $9D5B ; /
$00:9DB4 60 RTS ; Return
$00:9DB5 BD CB 9C LDA.W $9CCB,X ; A = high byte of file X's SRAM offset
$00:9DB8 EB XBA ; Move it to the high half of A
$00:9DB9 BD CE 9C LDA.W $9CCE,X ; A = low byte of the offset
$00:9DBC C2 30 REP #$30 ; A, X and Y 16-bit
$00:9DBE AA TAX ; X = SRAM offset of the primary copy
$00:9DBF 18 CLC ; Clear carry
$00:9DC0 69 AD 01 ADC.W #$01AD ; A += $01AD
$00:9DC3 A8 TAY ; Y = offset of the backup copy
$00:9DC4 DA PHX ; Push X
$00:9DC5 5A PHY ; Push Y
$00:9DC6 BF 8D 00 70 LDA.L $70008D,X ; A = stored checksum word at offset $8D
$00:9DCA 85 8A STA $8A ; [$8A] = it
$00:9DCC E2 20 SEP #$20 ; A 8-bit
$00:9DCE A0 8D 00 LDY.W #$008D ; Y = $8D: data bytes to sum
$00:9DD1 BF 00 00 70 LDA.L $700000,X ; A = byte of the save data
$00:9DD5 18 CLC ; \
$00:9DD6 65 8A ADC $8A ; } [$8A] += A (16-bit, carry below)
$00:9DD8 85 8A STA $8A ; /
$00:9DDA 90 02 BCC $9DDE ; \
$00:9DDC E6 8B INC $8B ; / Add the carry into [$8B]
$00:9DDE E8 INX ; Next byte
$00:9DDF 88 DEY ; Count down
$00:9DE0 D0 EF BNE $9DD1 ; Loop
$00:9DE2 C2 20 REP #$20 ; A 16-bit
$00:9DE4 7A PLY ; Restore Y
$00:9DE5 FA PLX ; Restore X
$00:9DE6 A5 8A LDA $8A ; A = checksum + sum of data
$00:9DE8 C9 5A 5A CMP.W #$5A5A ; Valid when it equals $5A5A
$00:9DEB F0 0A BEQ $9DF7 ; Valid: Z set, return
$00:9DED E0 AC 01 CPX.W #$01AC ; Already checked the backup copy?
$00:9DF0 B0 05 BCS $9DF7 ; Yes: return with Z clear (invalid)
$00:9DF2 DA PHX ; \
$00:9DF3 BB TYX ; } Swap X and Y: now try the backup copy
$00:9DF4 7A PLY ; /
$00:9DF5 80 CD BRA $9DC4 ; Checksum the backup copy
$00:9DF7 E2 20 SEP #$20 ; A 8-bit
$00:9DF9 60 RTS ; Return (Z = valid, X = offset of the valid copy)
$00:9DFA A5 16 LDA $16 ; A = buttons just pressed on controller 1
$00:9DFC 05 18 ORA $18 ; Or in controller 2's
$00:9DFE 29 40 AND.B #$40 ; Bit 6 (Y or X): back
$00:9E00 F0 06 BEQ $9E08 ; Not pressed: run the menu
$00:9E02 CE 00 01 DEC.W RAM_GameMode ; Game mode-- (to 09)
$00:9E05 4C 2C 9B JMP.W $9B2C ; Go back to file select (decrements once more)
$00:9E08 A0 04 LDY.B #$04 ; Y = 4: menu of 2 entries (1 PLAYER, 2 PLAYER)
$00:9E0A 20 CB 9A JSR.W $9ACB ; Move the cursor (returns only when chosen)
$00:9E0D 8E B2 0D STX.W $0DB2 ; [$0DB2] = X: number of players - 1
$00:9E10 20 95 A1 JSR.W ConfMapFromSave ; Load the overworld data from the save file
$00:9E13 22 AD DA 04 JSL.L $DAAD ; Initialize the overworld from the save ($DAAD)
$00:9E17 A9 80 LDA.B #$80 ; A = $80
$00:9E19 8D FB 1D STA.W $1DFB ; Music request [$1DFB] = $80 (fade out the music)
$00:9E1C A9 FF LDA.B #$FF ; A = $FF
$00:9E1E 8D B5 0D STA.W $0DB5 ; [$0DB5] = $FF
$00:9E21 AE B2 0D LDX.W $0DB2 ; X = number of players - 1
$00:9E24 A9 04 LDA.B #$04 ; A = 4 (lives stored minus one: start with 5 lives)
$00:9E26 9D B4 0D STA.W RAM_PlayerLives,X ; Player X's lives = 4
$00:9E29 CA DEX ; Next player
$00:9E2A 10 FA BPL $9E26 ; Loop for all players
$00:9E2C 8D BE 0D STA.W RAM_StatusLives ; Status bar lives = 4
$00:9E2F 9C BF 0D STZ.W RAM_StatusCoins ; Coins on the status bar = 0
$00:9E32 9C C1 0D STZ.W RAM_OWHasYoshi ; Mario has no Yoshi on the overworld
$00:9E35 64 19 STZ RAM_MarioPowerUp ; Mario's powerup = small
$00:9E37 9C C2 0D STZ.W $0DC2 ; Reserve item = none
$00:9E3A 9C C9 13 STZ.W $13C9 ; [$13C9] = 0: not in the CONTINUE/END menu
$00:9E3D C2 20 REP #$20 ; A 16-bit
$00:9E3F 9C B6 0D STZ.W RAM_PlayerCoins ; Both players' coins = 0
$00:9E42 9C B8 0D STZ.W RAM_PlayerPowerUp ; Both players' powerups = small
$00:9E45 9C BA 0D STZ.W RAM_PlyrYoshiColor ; Both players' Yoshi colors = 0
$00:9E48 9C C2 0D STZ.W $0DC2 ; Both players' reserve items = none
$00:9E4B 9C 48 0F STZ.W $0F48 ; Clear [$0F48] (probably bonus star counters)
$00:9E4E 9C 34 0F STZ.W $0F34 ; Player 1 score low word = 0
$00:9E51 9C 37 0F STZ.W $0F37 ; Player 2 score low word = 0
$00:9E54 E2 20 SEP #$20 ; A 8-bit
$00:9E56 9C 36 0F STZ.W $0F36 ; Player 1 score high byte = 0
$00:9E59 9C 39 0F STZ.W $0F39 ; Player 2 score high byte = 0
$00:9E5C 9C D5 0D STZ.W $0DD5 ; [$0DD5] = 0 (level exit type)
$00:9E5F 9C B3 0D STZ.W $0DB3 ; Current player = Mario
$00:9E62 20 29 9F JSR.W KeepModeActive ; Fade delay counter [$0DB1] = 1
$00:9E65 A0 0B LDY.B #$0B ; Y = $0B
$00:9E67 4C 8B 9C JMP.W $9C8B ; Game mode = $0B (fade out of the title screen)
;;; $9E6A..9E72: Table: menu entry counts ;;;
;; Number of entries for each menu type (index = Y passed to the cursor routine): 2, 4, 2, 2, 4.
$00:9E6A .db $02,$00,$04,$00,$02,$00,$02,$00 ; Entry counts: 2, 4, 2, 2, 4 (index = menu type * 2)
$00:9E72 .db $04,$00 ; (last menu type: 4 entries)
;;; $9E74..9E7C: Table: menu cursor VRAM addresses ;;;
;; VRAM address (BG3 tilemap) of the first cursor tile of each menu type; the following entries are $40 (one
;; tile row) apart.
$00:9E74 .db $CB,$51,$E8,$51,$08,$52,$C4,$51 ; VRAM address of the first cursor tile per menu type: $51CB, $51E8, $5208, $51C4, $51E5
$00:9E7C .db $E5,$51 ; (last menu type: $51E5)
;;; $9E7E..9E7E: Table: cursor position bit masks ;;;
$00:9E7E .db $01,$02,$04,$08 ; Bit for cursor position 0-3 (1, 2, 4, 8)
;;; $9E82: Draw blinking menu cursor ;;;
;; Writes one stripe record per menu entry (cursor tile $2E or blank). The cursor blinks using [$1B91];
;; position is [$1B92].
;; Parameters: Y: menu type (0, 2, 4, 6, 8).
;; Called by:
;; $00:9AD3: Menu cursor handler
$00:9E82 AE 92 1B LDX.W $1B92 ; X = cursor position [$1B92]
$00:9E85 BD 7E 9E LDA.W $9E7E,X ; A = bit mask for that position
$00:9E88 AA TAX ; X = mask
$00:9E89 AD 91 1B LDA.W $1B91 ; A = blink counter [$1B91]
$00:9E8C 49 1F EOR.B #$1F ; Invert the low bits
$00:9E8E 29 18 AND.B #$18 ; Bits 3-4: blink phase
$00:9E90 D0 02 BNE $9E94 ; Cursor visible in this phase
$00:9E92 A2 00 LDX.B #$00 ; Hidden: no entry gets the cursor (X = 0)
$00:9E94 86 00 STX $00 ; [$00] = cursor bit mask
$00:9E96 AF 7B 83 7F LDA.L $7F837B ; A = stripe buffer write index
$00:9E9A AA TAX ; X = write index
$00:9E9B C2 20 REP #$20 ; A 16-bit
$00:9E9D B9 6A 9E LDA.W $9E6A,Y ; A = number of menu entries
$00:9EA0 85 8A STA $8A ; \
$00:9EA2 85 02 STA $02 ; / [$8A] = [$02] = entry counter
$00:9EA4 B9 74 9E LDA.W $9E74,Y ; A = VRAM address of the entry's cursor tile
$00:9EA7 EB XBA ; Swap to big-endian for the stripe image header
$00:9EA8 9F 7D 83 7F STA.L $7F837D,X ; Write the VRAM address into the buffer
$00:9EAC EB XBA ; Back to little-endian
$00:9EAD 18 CLC ; \
$00:9EAE 69 40 00 ADC.W #$0040 ; } Next entry's VRAM address = this + $40 (pushed for later, never used)
$00:9EB1 48 PHA ; /
$00:9EB2 A9 00 01 LDA.W #$0100 ; A = $0100: record length word (one tile)
$00:9EB5 9F 7F 83 7F STA.L $7F837F,X ; Write it into the buffer
$00:9EB9 A9 FC 38 LDA.W #$38FC ; A = blank tile with properties $38
$00:9EBC 46 00 LSR $00 ; Shift the mask; carry = this entry has the cursor
$00:9EBE 90 03 BCC $9EC3 ; No cursor: use the blank tile
$00:9EC0 A9 2E 3D LDA.W #$3D2E ; A = cursor tile $2E with properties $3D
$00:9EC3 9F 81 83 7F STA.L $7F8381,X ; Write the tile into the buffer
$00:9EC7 68 PLA ; Discard the pushed address
$00:9EC8 E8 INX ; \
$00:9EC9 E8 INX ; |
$00:9ECA E8 INX ; |
$00:9ECB E8 INX ; |
$00:9ECC E8 INX ; } Write index += 6 (one record)
$00:9ECD E8 INX ; /
$00:9ECE C6 02 DEC $02 ; Next entry
$00:9ED0 D0 D5 BNE $9EA7 ; Loop
$00:9ED2 E2 20 SEP #$20 ; A 8-bit
$00:9ED4 8A TXA ; A = write index
$00:9ED5 8F 7B 83 7F STA.L $7F837B ; Save it as the new buffer index ($7F:837B)
$00:9ED9 A9 FF LDA.B #$FF ; A = $FF: end marker
$00:9EDB 9F 7D 83 7F STA.L $7F837D,X ; Terminate the stripe image
$00:9EDF 60 RTS ; Return
;;; $9EE0: Table: new game save data entries (TBL_009EE0) ;;;
;; Pairs of (offset into the save data, value) written by CODE_WRITEOW: offset $28 = 3, $4D = 1, $52 = 1, $53
;; = 1, $5B = 8, $5C = 2,
;; $57 = 4, $30 = 1. The first offset is at TBL_009EE0 and the first value at $9EE1.
$00:9EE0 .db $28 ; Offset into the save data of the first byte
$00:9EE1 .db $03,$4D,$01,$52,$01,$53,$01,$5B ; Value, then (offset, value) pairs: $4D=1, $52=1, $53=1, $5B=8, $5C=2, $57=4, $30=1
$00:9EE9 .db $08,$5C,$02,$57,$04,$30,$01 ; (offset, value) pairs, continued
;;; $9EF0: Table: new game overworld state (TBL_009EF0) ;;;
;; 22 initial bytes written to the save data copy of $1F11-$1F26 (Mario and Luigi submap, positions, etc).
$00:9EF0 .db $01,$01,$02,$00,$02,$00,$68,$00 ; Initial overworld state for $1F11-$1F26 (submaps, positions): 22 bytes
$00:9EF8 .db $78,$00,$68,$00,$78,$00,$06,$00 ; Initial overworld state, continued
$00:9F00 .db $07,$00,$06,$00,$07,$00 ; Initial overworld state, last bytes
;;; $9F06: Initialize new save file data (CODE_WRITEOW) ;;;
;; Clears the working save data $1F49-$1FD5 and writes the defaults from TBL_009EE0 and TBL_009EF0.
;; Called by:
;; $00:9CB5: Game mode 07: title screen and demo (GAMEMODE_07)
$00:9F06 A2 8D LDX.B #$8D ; X = $8D: size of the save data
$00:9F08 9E 48 1F STZ.W $1F48,X ; Clear a byte of $1F49-$1FD5
$00:9F0B CA DEX ; Next byte
$00:9F0C D0 FA BNE $9F08 ; Loop
$00:9F0E A2 0E LDX.B #$0E ; X = $0E: last pair
$00:9F10 BC E0 9E LDY.W TBL_009EE0,X ; Y = offset into the save data
$00:9F13 BD E1 9E LDA.W $9EE1,X ; A = value to write
$00:9F16 99 49 1F STA.W $1F49,Y ; Save data[Y] = value
$00:9F19 CA DEX ; \
$00:9F1A CA DEX ; / Next pair (X -= 2)
$00:9F1B 10 F3 BPL $9F10 ; Loop
$00:9F1D A2 15 LDX.B #$15 ; X = $15: bytes of the initial map state
$00:9F1F BD F0 9E LDA.W TBL_009EF0,X ; A = initial map state byte
$00:9F22 9D B8 1F STA.W $1FB8,X ; Store at $1FB8+X (save data copy of $1F11-$1F26)
$00:9F25 CA DEX ; Next byte
$00:9F26 10 F7 BPL $9F1F ; Loop
$00:9F28 60 RTS ; Return
;;; $9F29: Set fade step delay (KeepModeActive) ;;;
;; Sets the fade delay counter [$0DB1] to 1. $009F2B sets it to A.
;; Called by:
;; $00:9622: Cutscene, ending and game mode code (castle scenes, credits, game over) (CutsceneCastlePal)
;; $00:9E62: Game mode 08: file select, mode 0A: players
;; $00:9F3C: Game modes 0F/13: fade with mosaic (TmpFade)
;; $00:9F74: Advance game mode, apply mosaic; fade (GM++Mosaic)
;; $00:A176: Game mode 0C: load overworld (LoadMapGameMode)
;; $00:A5D2: Game mode 12: prepare level (GM04Load)
$00:9F29 A9 01 LDA.B #$01 ; A = 1
$00:9F2B 8D B1 0D STA.W $0DB1 ; Fade delay counter [$0DB1] = A
$00:9F2E 60 RTS ; Return
;;; $9F2F..9F33: Table: fade step values ;;;
;; Indexed by fade direction ([$0DAF]). $009F2F: brightness step (+1, -1). $009F31: mosaic size step (-$10,
;; +$10).
;; $009F33: brightness that ends the fade ($0F, $00); two further entries ($00, $F0) look unused.
$00:9F2F .db $01,$FF ; Brightness step per fade: +1 (fade in), -1 (fade out)
$00:9F31 .db $F0,$10 ; Mosaic size step: -$10 (fade in), +$10 (fade out)
$00:9F33 .db $0F,$00,$00,$F0 ; Final brightness: $0F (in), $00 (out); other two entries unused
;;; $9F37: Game modes 0F/13: fade with mosaic (TmpFade) ;;;
;; Fades brightness [$0DAE] and mosaic size [$0DB0] by one step every other frame. When the final brightness
;; is reached the game
;; mode is incremented and the direction [$0DAF] is flipped. Mosaic is applied to BG1 and BG2.
$00:9F37 CE B1 0D DEC.W $0DB1 ; Fade delay counter [$0DB1]--
$00:9F3A 10 32 BPL $9F6E ; Still positive: wait another frame
$00:9F3C 20 29 9F JSR.W KeepModeActive ; Delay counter = 1: step every other frame
$00:9F3F AC AF 0D LDY.W $0DAF ; Y = fade direction [$0DAF] (0 = in, 1 = out)
$00:9F42 AD B0 0D LDA.W $0DB0 ; A = mosaic size [$0DB0]
$00:9F45 18 CLC ; \
$00:9F46 79 31 9F ADC.W $9F31,Y ; / Mosaic size += step (high nibble = size)
$00:9F49 8D B0 0D STA.W $0DB0 ; Save it
$00:9F4C AD AE 0D LDA.W $0DAE ; A = brightness [$0DAE]
$00:9F4F 18 CLC ; \
$00:9F50 79 2F 9F ADC.W $9F2F,Y ; / Brightness += step (+1 or -1)
$00:9F53 8D AE 0D STA.W $0DAE ; Save it
$00:9F56 D9 33 9F CMP.W $9F33,Y ; Reached the final brightness?
$00:9F59 D0 0B BNE $9F66 ; No: update mosaic and return
;;; $9F5B: Advance game mode, apply mosaic; fade (GM++Mosaic) ;;;
;; $009F5B: game mode++, flip the fade direction, set MOSAIC. $009F6F: fade step without mosaic (brightness
;; only) used by many game
;; modes. $009F7C: slower fade (delay 8) used for the ending fade.
;; Called by:
;; $00:97C4: Game mode 11: Mario Start, level music (MarioStartGameMode)
$00:9F5B EE 00 01 INC.W RAM_GameMode ; Fade finished: game mode++
$00:9F5E AD AF 0D LDA.W $0DAF ; \
$00:9F61 49 01 EOR.B #$01 ; } Flip the fade direction [$0DAF] ^= 1
$00:9F63 8D AF 0D STA.W $0DAF ; /
$00:9F66 A9 03 LDA.B #$03 ; \
$00:9F68 0D B0 0D ORA.W $0DB0 ; / A = $03 | mosaic size: mosaic on BG1 and BG2
$00:9F6B 8D 06 21 STA.W $2106 ; MOSAIC = A
$00:9F6E 60 RTS ; Return
$00:9F6F CE B1 0D DEC.W $0DB1 ; Fade delay counter [$0DB1]--
$00:9F72 10 FA BPL $9F6E ; Still positive: return
$00:9F74 20 29 9F JSR.W KeepModeActive ; Delay counter = 1
$00:9F77 AC AF 0D LDY.W $0DAF ; Y = fade direction [$0DAF]
$00:9F7A 80 D0 BRA $9F4C ; Do the fade step (brightness only, shares TmpFade code)
$00:9F7C CE B1 0D DEC.W $0DB1 ; Fade delay counter [$0DB1]--
$00:9F7F 10 ED BPL $9F6E ; Still positive: return
$00:9F81 A9 08 LDA.B #$08 ; A = 8
$00:9F83 20 2B 9F JSR.W $9F2B ; Fade delay counter = 8 (slow fade)
$00:9F86 80 EF BRA $9F77 ; Do the fade step
;;; $9F88..9FB0: Table: layer 3 setup per tileset ;;;
;; 16 tilesets x 3 bytes (layer 3 type 1-3). Positive: effect value for [$1403]. $80: copy palette, $81: image
;; with BG3 scroll, $C0: none.
$00:9F88 .db $01,$02,$C0,$01,$80,$81,$01,$02 ; Layer 3 setup per tileset, 3 bytes each (layer 3 type 1-3); tileset 0, 1, 2...
$00:9F90 .db $C0,$01,$02,$81,$01,$02,$80,$01 ; Layer 3 setup table, continued (positive = effect, $80/$81/$C0 = static image)
$00:9F98 .db $02,$81,$01,$02,$81,$01,$02,$C0 ; Layer 3 setup table, continued (positive = effect, $80/$81/$C0 = static image)
$00:9FA0 .db $01,$02,$C0,$01,$02,$81,$01,$02 ; Layer 3 setup table, continued (positive = effect, $80/$81/$C0 = static image)
$00:9FA8 .db $80,$01,$02,$80,$01,$02,$80,$01 ; Layer 3 setup table, continued (positive = effect, $80/$81/$C0 = static image)
$00:9FB0 .db $02,$81,$01,$02,$81,$01,$02,$80 ; Layer 3 setup table, continued (positive = effect, $80/$81/$C0 = static image)
;;; $9FB8: Set up layer 3 (BG3) for the level ;;;
;; Looks up the layer 3 setup in $9F88 for tileset [$1931] and type [$1BE3], sets BG3 scroll, color math
;; and uploads the
;; layer 3 image through Layer3Ptr. Called when a level is loaded.
;; Called by:
;; $00:A5C3: Game mode 12: prepare level (GM04Load)
$00:9FB8 AD 31 19 LDA.W $1931 ; \
$00:9FBB 0A ASL ; |
$00:9FBC 18 CLC ; |
$00:9FBD 6D 31 19 ADC.W $1931 ; } [$00] = tileset [$1931] * 3
$00:9FC0 85 00 STA $00 ; /
$00:9FC2 AD E3 1B LDA.W $1BE3 ; A = layer 3 type [$1BE3] (0 = none)
$00:9FC5 F0 4B BEQ $A012 ; None: go to $00A012 (BG3 scroll $D0, no image)
$00:9FC7 3A DEC A ; \
$00:9FC8 18 CLC ; } A = (type - 1) + tileset * 3
$00:9FC9 65 00 ADC $00 ; /
$00:9FCB AA TAX ; X = table index
$00:9FCC BD 88 9F LDA.W $9F88,X ; A = layer 3 setup for this tileset and type
$00:9FCF 30 19 BMI $9FEA ; Bit 7 set: static image, go to $009FEA
$00:9FD1 8D 03 14 STA.W $1403 ; [$1403] = layer 3 effect value (1 or 2)
$00:9FD4 4A LSR ; A >>= 1, Z = effect value was 1
$00:9FD5 08 PHP ; Save the flags
$00:9FD6 20 45 A0 JSR.W $A045 ; Clear layer 3 tilemap RAM and set the vertical flag ($A045)
$00:9FD9 A9 70 LDA.B #$70 ; BG3 Y scroll = $70
$00:9FDB 28 PLP ; Restore flags
$00:9FDC F0 02 BEQ $9FE0 ; Effect 1: keep $70
$00:9FDE A9 40 LDA.B #$40 ; Effect 2: BG3 Y scroll = $40
$00:9FE0 85 24 STA $24 ; BG3 vertical scroll low [$24] = A
$00:9FE2 64 25 STZ $25 ; High byte [$25] = 0
$00:9FE4 22 72 BC 05 JSL.L $BC72 ; Initialize the layer 3 effect ($BC72)
$00:9FE8 80 31 BRA $A01B ; Skip the image upload code, go to $00A01B
$00:9FEA 0A ASL ; A <<= 1: bit 7 -> carry, $C0 -> $80, $80 -> $00, $81 -> $02
$00:9FEB 30 25 BMI $A012 ; $C0: handled like no layer 3 (go to $00A012)
$00:9FED F0 18 BEQ $A007 ; $80: copy palette colors
$00:9FEF AD 31 19 LDA.W $1931 ; A = tileset
$00:9FF2 C9 01 CMP.B #$01 ; Tileset 1 (castle)?
$00:9FF4 F0 04 BEQ $9FFA ; Yes: scroll BG3 with BG1
$00:9FF6 C9 03 CMP.B #$03 ; Tileset 3 (underground)?
$00:9FF8 D0 25 BNE $A01F ; No: just load the image
$00:9FFA C2 20 REP #$20 ; A 16-bit
$00:9FFC A5 1A LDA RAM_ScreenBndryXLo ; A = layer 1 X position
$00:9FFE 4A LSR ; A / 2
$00:9FFF 85 22 STA $22 ; BG3 horizontal scroll [$22] = layer 1 X / 2
;;; $A001: Layer 3 setup, continued; clear L3 RAM (in1Remember) ;;;
;; $00A001-$00A044: second half of the layer 3 setup (palette copy for type $80, BG3 scroll, image upload).
;; $00A045: clears $B0 bytes of every $100-byte block of $7E:E400-$7E:FAFF and sets bit 7 of
;; [RAM_IsVerticalLvl].
; You can get somewhere quick by pressing ctrl+f and typing in the address.
$00:A001 E2 20 SEP #$20 ; A 8-bit
$00:A003 A9 C0 LDA.B #$C0 ; A = $C0
$00:A005 80 10 BRA $A017 ; BG3 vertical scroll = $C0 (skip to the store)
$00:A007 A2 07 LDX.B #$07 ; X = 7
$00:A009 BD 6C B6 LDA.W $B66C,X ; A = palette byte from $B66C
$00:A00C 9D 1B 07 STA.W $071B,X ; Store in the CGRAM mirror $071B+X
$00:A00F CA DEX ; Next byte
$00:A010 10 F7 BPL $A009 ; Loop
$00:A012 EE D5 13 INC.W $13D5 ; [$13D5]++ (no animated layer 3 flag)
$00:A015 A9 D0 LDA.B #$D0 ; A = $D0
$00:A017 85 24 STA $24 ; BG3 vertical scroll low [$24] = A
$00:A019 64 25 STZ $25 ; High byte [$25] = 0
$00:A01B A9 04 LDA.B #$04 ; A = $04
$00:A01D 14 40 TRB $40 ; CGADSUB: BG3 not in color math ([$40] bit 2 cleared)
$00:A01F AD E3 1B LDA.W $1BE3 ; A = layer 3 type
$00:A022 F0 20 BEQ $A044 ; None: return
$00:A024 3A DEC A ; \
$00:A025 18 CLC ; } A = type - 1 + tileset * 3
$00:A026 65 00 ADC $00 ; /
$00:A028 85 01 STA $01 ; [$01] = it
$00:A02A 0A ASL ; \
$00:A02B 18 CLC ; } A = A * 3 (3-byte pointers)
$00:A02C 65 01 ADC $01 ; /
$00:A02E AA TAX ; X = offset into Layer3Ptr
$00:A02F BF 00 90 05 LDA.L Layer3Ptr,X ; Pointer low byte
$00:A033 85 00 STA $00 ; [$00] = it
$00:A035 BF 01 90 05 LDA.L Layer3Ptr+1,X ; Pointer high byte
$00:A039 85 01 STA $01 ; [$01] = it
$00:A03B BF 02 90 05 LDA.L Layer3Ptr+2,X ; Pointer bank
$00:A03F 85 02 STA $02 ; [$02] = it
$00:A041 20 1E 87 JSR.W $871E ; Upload the layer 3 image (stripe image) to VRAM
$00:A044 60 RTS ; Return
$00:A045 C2 30 REP #$30 ; A, X and Y 16-bit
$00:A047 A2 00 01 LDX.W #$0100 ; X = $0100: start offset
$00:A04A A0 58 00 LDY.W #$0058 ; Y = $58: words to clear per block
$00:A04D A9 00 00 LDA.W #$0000 ; A = 0
$00:A050 9F 00 E3 7E STA.L $7EE300,X ; Clear a word at $7E:E300+X
$00:A054 E8 INX ; X += 2 (next word)
$00:A055 E8 INX ; (second INX)
$00:A056 88 DEY ; Count down
$00:A057 D0 F7 BNE $A050 ; Loop for $B0 bytes
$00:A059 8A TXA ; \
$00:A05A 18 CLC ; } X += $0100: next block (stride $100)
$00:A05B 69 00 01 ADC.W #$0100 ; /
$00:A05E AA TAX ; X = it
$00:A05F E0 00 1B CPX.W #$1B00 ; X reached $1B00?
$00:A062 90 E6 BCC $A04A ; No: clear the next block
$00:A064 E2 30 SEP #$30 ; A, X and Y 8-bit
$00:A066 A9 80 LDA.B #$80 ; A = $80
$00:A068 04 5B TSB RAM_IsVerticalLvl ; Set bit 7 of [RAM_IsVerticalLvl]
$00:A06A 60 RTS ; Return
;;; $A06B..A073: Table: overworld X start per submap ;;;
;; Layer 1 X position for each overworld submap 0-6, indexed by submap * 2.
$00:A06B .db $00,$00,$EF,$FF,$EF,$FF,$EF,$FF ; Layer 1 X start of each overworld submap: 0000, FFEF x3, 00F0 x3
$00:A073 .db $F0,$00,$F0,$00,$F0,$00 ; (submaps 4-6: $00F0)
;;; $A079..A081: Table: overworld Y start per submap ;;;
;; Layer 1 Y position for each overworld submap 0-6, indexed by submap * 2.
$00:A079 .db $00,$00,$D8,$FF,$80,$00,$28,$01 ; Layer 1 Y start per submap: 0000, FFD8, 0080, 0128, FFD8, 0080, 0128
$00:A081 .db $D8,$FF,$80,$00,$28,$01 ; (submaps 4-6, continued)
;;; New labels (not in original all.log):
;;; $A087 => LoadMapGameMode
;;; $A195 => ConfMapFromSave
;;; JSR subroutine
;;; Implements game mode $0C, load the world map (the overworld).
;;;
;;; 00A087:
;;; $A087: Game mode 0C: load overworld (LoadMapGameMode) ;;;
;; Loads the overworld. If [$0109] is non-zero the map is skipped and the game goes straight to Mario Start
;; (game mode $10).
;; Otherwise it uploads graphics and palettes, saves the player's lives, powerup, coins, Yoshi and reserve
;; item, handles the game over
;; case (reload saved data, CONTINUE/END or title screen), and positions the map for the current player's
;; submap.
$00:A087 20 7D 93 JSR.W TurnOffIO ; Disable NMI, HDMA and the screen
$00:A08A AD 9C 1B LDA.W $1B9C ; A = [$1B9C] (overworld event flag?)
$00:A08D F0 04 BEQ $A093 ; Zero: skip
$00:A08F 22 3B 85 04 JSL.L $853B ; Run the overworld routine $853B
$00:A093 20 A6 A1 JSR.W Clear_1A_13D3 ; Clear [$1A]-[$D7] and $13D3-$1BA1
$00:A096 AD 09 01 LDA.W $0109 ; A = [$0109]
$00:A099 F0 15 BEQ $A0B0 ; Zero: enter the overworld normally
;; | only runs if using RAM $0109 to bypass the world map
;; V
$00:A09B A9 B0 LDA.B #$B0 ; A = $B0
$00:A09D 8D F5 1D STA.W $1DF5 ; [$1DF5] = $B0 (delay timer)
$00:A0A0 9C 11 1F STZ.W $1F11 ; Mario's submap [$1F11] = 0
$00:A0A3 A9 F0 LDA.B #$F0 ; A = $F0
$00:A0A5 8D B0 0D STA.W $0DB0 ; [$0DB0] = $F0 (mosaic size: start of fade)
$00:A0A8 A9 10 LDA.B #$10 ; A = $10
$00:A0AA 8D 00 01 STA.W RAM_GameMode ; Game mode = $10 (skip the map, straight to Mario Start)
$00:A0AD 4C F7 93 JMP.W Mode04Finish ; Enable NMI and return
;; | runs if entering the world map
;; | (after opening save, completing level, or dying)
;; V
$00:A0B0 20 FA 85 JSR.W $85FA ; Clear BG3 and sprites ($85FA)
$00:A0B3 20 0E 81 JSR.W UploadMusicBank1 ; Upload music bank 1 (overworld music)
$00:A0B6 20 79 8A JSR.W SetUpScreen ; Set up the PPU registers (SetUpScreen)
$00:A0B9 9C DA 0D STZ.W $0DDA ; [$0DDA] = 0: no music request pending
$00:A0BC AE B3 0D LDX.W $0DB3 ; X = current player (0 Mario, 1 Luigi)
$00:A0BF AD BE 0D LDA.W RAM_StatusLives ; A = lives on the status bar
$00:A0C2 10 03 BPL $A0C7 ; \
$00:A0C4 EE 87 1B INC.W $1B87 ; / Negative lives: [$1B87]++ to trigger the game over message
$00:A0C7 9D B4 0D STA.W RAM_PlayerLives,X ; Save lives for the current player
$00:A0CA A5 19 LDA RAM_MarioPowerUp ; A = Mario powerup
$00:A0CC 9D B8 0D STA.W RAM_PlayerPowerUp,X ; Save for the current player
$00:A0CF AD BF 0D LDA.W RAM_StatusCoins ; A = coins
$00:A0D2 9D B6 0D STA.W RAM_PlayerCoins,X ; Save for the current player
$00:A0D5 AD C1 0D LDA.W RAM_OWHasYoshi ; A = player has Yoshi on the map?
$00:A0D8 F0 03 BEQ $A0DD ; No: Yoshi color 0
$00:A0DA AD C7 13 LDA.W RAM_YoshiColor ; Yes: A = Yoshi color
$00:A0DD 9D BA 0D STA.W RAM_PlyrYoshiColor,X ; Save Yoshi color for the current player
$00:A0E0 AD C2 0D LDA.W $0DC2 ; A = reserve item
$00:A0E3 9D BC 0D STA.W $0DBC,X ; Save for the current player
$00:A0E6 A9 03 LDA.B #$03 ; A = $03
$00:A0E8 85 44 STA $44 ; Color window settings [$44] = $03
$00:A0EA A9 30 LDA.B #$30 ; A = $30: CGADSUB for the normal case
$00:A0EC A2 15 LDX.B #$15 ; X = $15: main screen layers (BG1, BG3, sprites)
$00:A0EE AC C9 13 LDY.W $13C9 ; Y = [$13C9] (CONTINUE/END flag)
$00:A0F1 F0 28 BEQ $A11B ; Not returning after a game over: skip ahead
;; | runs if returning to world map after Game Over
;; V
$00:A0F3 20 95 A1 JSR.W ConfMapFromSave ; Revert to the saved overworld data
$00:A0F6 AD 2E 1F LDA.W $1F2E ; A = number of exits cleared
$00:A0F9 D0 06 BNE $A101 ; Non-zero: show the CONTINUE/END menu
$00:A0FB 20 89 9C JSR.W $9C89 ; No exits: set game mode 2 (title)
$00:A0FE 4C F4 93 JMP.W $93F4 ; Game mode++ and exit
$00:A101 22 AD DA 04 JSL.L $DAAD ; Initialize the overworld from the save ($DAAD)
$00:A105 C2 20 REP #$20 ; A 16-bit
$00:A107 A9 8C 31 LDA.W #$318C ; A = $318C
$00:A10A 8D 01 07 STA.W $0701 ; BG color = $318C (darker background)
$00:A10D E2 20 SEP #$20 ; A 8-bit
$00:A10F A9 30 LDA.B #$30 ; A = $30
$00:A111 85 43 STA $43 ; Window mask settings [$43] = $30
$00:A113 A9 20 LDA.B #$20 ; A = $20
$00:A115 85 44 STA $44 ; Color math window [$44] = $20
$00:A117 A9 B3 LDA.B #$B3 ; A = $B3: CGADSUB
$00:A119 A2 17 LDX.B #$17 ; X = $17: main screen layers
;; fall through
;; | If continuing after Game Over: A = $B3, X = $17
;; V If came here by skipping ahead: A = $30, X = $15
$00:A11B A0 02 LDY.B #$02 ; Y = 2: sub screen layers (BG2)
$00:A11D 20 FD 93 JSR.W ScreenSettings ; Set CGADSUB, main and sub screens (ScreenSettings)
$00:A120 8E 2E 21 STX.W $212E ; Main screen window mask = X
$00:A123 8C 2F 21 STY.W $212F ; Sub screen window mask = Y
$00:A126 22 09 DC 04 JSL.L $DC09 ; Load all overworld layers ($DC09)
$00:A12A AE B3 0D LDX.W $0DB3 ; X = current player
$00:A12D BD 11 1F LDA.W $1F11,X ; A = submap of the current player
$00:A130 0A ASL ; A * 2
$00:A131 AA TAX ; X = word index
$00:A132 C2 20 REP #$20 ; A 16-bit
$00:A134 BD 6B A0 LDA.W $A06B,X ; A = X start position of the submap
$00:A137 85 1A STA RAM_ScreenBndryXLo ; \
$00:A139 85 1E STA $1E ; / Layer 1 X [$1A] = layer 2 X [$1E] = A
$00:A13B BD 79 A0 LDA.W $A079,X ; A = Y start position of the submap
$00:A13E 85 1C STA RAM_ScreenBndryYLo ; \
$00:A140 85 20 STA $20 ; / Layer 1 Y [$1C] = layer 2 Y [$20] = A
$00:A142 E2 20 SEP #$20 ; A 8-bit
$00:A144 20 DA A9 JSR.W UploadSpriteGFX ; Upload sprite graphics (UploadSpriteGFX)
$00:A147 A0 14 LDY.B #$14 ; Y = $14: graphics file number
$00:A149 22 28 BA 00 JSL.L $BA28 ; Decompress that graphics file ($BA28)
$00:A14D 20 25 AD JSR.W $AD25 ; Load the overworld palettes ($AD25)
$00:A150 20 2F 92 JSR.W $922F ; Set up the window HDMA ($922F)
$00:A153 A9 06 LDA.B #$06 ; \
$00:A155 85 12 STA $12 ; / Stripe image $06: overworld border
$00:A157 20 D2 85 JSR.W LoadScrnImage ; Upload it (LoadScrnImage)
$00:A15A 22 F2 DB 05 JSL.L $DBF2 ; Build more tilemap data in the stripe buffer ($DBF2)
$00:A15E 20 D2 85 JSR.W LoadScrnImage ; Upload it (LoadScrnImage)
$00:A161 22 91 8D 04 JSL.L $8D91 ; Overworld sprite / path setup ($8D91)
$00:A165 22 E9 D6 04 JSL.L $D6E9 ; Overworld setup ($D6E9)
$00:A169 A9 F0 LDA.B #$F0 ; A = $F0
$00:A16B 85 3F STA $3F ; OAM priority index [$3F] = $F0
$00:A16D 20 94 84 JSR.W $8494 ; Pack the OAM size bits ($8494)
$00:A170 20 D2 85 JSR.W LoadScrnImage ; Upload the stripe image (LoadScrnImage)
$00:A173 9C D9 13 STZ.W $13D9 ; [$13D9] = 0 (overworld process: normal)
$00:A176 20 29 9F JSR.W KeepModeActive ; Fade delay counter = 1
$00:A179 A9 02 LDA.B #$02 ; A = 2
$00:A17B 8D 9B 0D STA.W $0D9B ; [$0D9B] = 2 (special level mode: overworld)
$00:A17E C2 10 REP #$10 ; Index 16-bit
$00:A180 A2 BE 01 LDX.W #$01BE ; X = $01BE
$00:A183 A9 FF LDA.B #$FF ; A = $FF
$00:A185 9E A0 04 STZ.W $04A0,X ; Clear [$04A0+X] (probably resets a sprite table)
$00:A188 9D A1 04 STA.W $04A1,X ; [$04A1+X] = $FF
$00:A18B CA DEX ; X--
$00:A18C CA DEX ; X--
$00:A18D 10 F6 BPL $A185 ; Loop
$00:A18F 20 A0 92 JSR.W $92A0 ; Enable HDMA channel 7 ($92A0)
$00:A192 4C F4 93 JMP.W $93F4 ; Game mode++ and exit
;;; JSR subroutine
;;;
;;; Configures the world map. Sets the level settings (RAM $7e1ea2..$7e1f01),
;;; event flags (RAM $7e1f02..$7e1f10), and Mario and Luigi (RAM $7e1f11..$7e1f26),
;;; switch place status (RAM $7e1f27..$7e1f2a), unknown (RAM $7e1f2b..$7e1f2d) and
;;; number of exits (RAM $7e1f2e),
;;; by loading everything from the open save file (RAM $7e1f49..$7e1fd5).
;;;
;;; 00A195:
;;; $A195: Copy save data to overworld state (ConfMapFromSave) ;;;
;; Copies $8D bytes from $1F49-$1FD5 (save data in RAM) to $1EA2-$1F2E (live overworld data).
;; Called by:
;; $00:9E10: Game mode 08: file select, mode 0A: players
;; $00:A0F3: Game mode 0C: load overworld (LoadMapGameMode)
$00:A195 C2 10 REP #$10 ; Index registers 16-bit
$00:A197 A2 8C 00 LDX.W #$008C ; X = $8C: 141 bytes
$00:A19A BD 49 1F LDA.W $1F49,X ; A = save data byte at $1F49+X
$00:A19D 9D A2 1E STA.W $1EA2,X ; Copy to the live table $1EA2+X
$00:A1A0 CA DEX ; Next byte
$00:A1A1 10 F7 BPL $A19A ; Loop
$00:A1A3 E2 10 SEP #$10 ; Index registers 8-bit
$00:A1A5 60 RTS ; Return
;;; $A1A6: Clear RAM; game mode 0E: overworld (Clear_1A_13D3) ;;;
;; $00A1A6: clears [$1A]-[$D7] and $13D3-$1BA1.
;; $00A1BE: game mode 0E: runs the overworld each frame (SetUp0DA0GM4, hides sprites, GameMode_0E_Prim in bank
;; $04, packs OAM size bits).
;; Called by:
;; $00:946B: Cutscene, ending and game mode code (castle scenes, credits, game over) (CutsceneCastlePal)
;; $00:95C4: Cutscene, ending and game mode code (castle scenes, credits, game over) (CutsceneCastlePal)
;; $00:9640: Cutscene, ending and game mode code (castle scenes, credits, game over) (CutsceneCastlePal)
;; $00:A093: Game mode 0C: load overworld (LoadMapGameMode)
$00:A1A6 C2 10 REP #$10 ; Index registers 16-bit
$00:A1A8 E2 20 SEP #$20 ; A 8-bit
$00:A1AA A2 BD 00 LDX.W #$00BD ; X = $BD
$00:A1AD 74 1A STZ RAM_ScreenBndryXLo,X ; Clear [$1A+X]
$00:A1AF CA DEX ; Next
$00:A1B0 10 FB BPL $A1AD ; Loop: clears [$1A]-[$D7]
$00:A1B2 A2 CE 07 LDX.W #$07CE ; X = $07CE
$00:A1B5 9E D3 13 STZ.W $13D3,X ; Clear $13D3+X
$00:A1B8 CA DEX ; Next
$00:A1B9 10 FA BPL $A1B5 ; Loop: clears $13D3-$1BA1
$00:A1BB E2 10 SEP #$10 ; Index registers 8-bit
$00:A1BD 60 RTS ; Return
$00:A1BE 20 74 9A JSR.W SetUp0DA0GM4 ; Check controllers (SetUp0DA0GM4)
$00:A1C1 E6 14 INC RAM_FrameCounterB ; Frame counter B [$14]++
$00:A1C3 22 00 80 7F JSL.L RAM_7F8000 ; Hide all sprites
$00:A1C7 22 41 82 04 JSL.L GameMode_0E_Prim ; Run the overworld (GameMode_0E_Prim, bank $04)
$00:A1CB 4C 94 84 JMP.W $8494 ; Pack OAM size bits and return
;;; $A1CE: Table: ground shake Y offset (low) (GrndShakeDispYLo) ;;;
$00:A1CE .db $FE,$00,$02,$00 ; Ground shake Y offsets (low): -2, 0, +2, 0
;;; $A1D2: Table: ground shake Y offset (high); unknown (GrndShakeDispYHi) ;;;
;; $00A1D2: high bytes of the ground shake offsets. $00A1D6: unknown 4 byte table ($12, $22, $12, $02).
$00:A1D2 .db $FF,$00,$00,$00 ; Ground shake Y offsets (high): $FF, 0, 0, 0
$00:A1D6 .db $12,$22,$12,$02 ; Unknown table: $12, $22, $12, $02
;;; $A1DA: Game mode 14: in level (InLevelGameMode) ;;;
;; Runs once per frame while playing a level. Runs the message box instead if one is open; handles bonus game
;; ending input lock, the pause toggle (Start),
;; and leaving the level with Select (only for levels already beaten). When not paused: sprites off-screen,
;; scroll, layer updates, animated tiles,
;; ground shake, status bar, Mario, sprites, then OAM size packing.
;; Quirk: $00A249-$00A259 and $00A274-$00A27B are unreachable debug code (slow motion, beat level with
;; Select).
;; $00A2F3: copies Mario's X/Y position to [$D1]/[$D3] (previous-frame position).
;; Called by:
;; $00:9C9C: Game mode 07: title screen and demo (GAMEMODE_07)
$00:A1DA AD 26 14 LDA.W $1426 ; \
$00:A1DD F0 05 BEQ $A1E4 ; / If a message box is open ([$1426] != 0), run it and return
$00:A1DF 22 0C B1 05 JSL.L $B10C ; Run the message box routine ($B10C)
$00:A1E3 60 RTS ; Return (no game logic while the message box is up)
$00:A1E4 AD 25 14 LDA.W $1425 ; \
$00:A1E7 F0 17 BEQ $A200 ; / [$1425] = 0 (not in the bonus game): skip the bonus game checks
$00:A1E9 AD AB 14 LDA.W $14AB ; \
$00:A1EC F0 12 BEQ $A200 ; / [$14AB] = 0: bonus game timer not running, skip
$00:A1EE C9 40 CMP.B #$40 ; \
$00:A1F0 B0 0E BCS $A200 ; / [$14AB] >= $40: plenty of time left, skip
$00:A1F2 20 2D F6 JSR.W NoButtons ; Clear controller input (NoButtons)
$00:A1F5 C9 1C CMP.B #$1C ; \
$00:A1F7 B0 07 BCS $A200 ; / [$14AB] >= $1C: not yet time for the end pose, skip
$00:A1F9 20 31 CA JSR.W SetMarioPeaceImg ; Set Mario's peace sign pose (SetMarioPeaceImg)
$00:A1FC A9 0D LDA.B #$0D ; \
$00:A1FE 85 71 STA RAM_MarioAnimation ; / Mario animation = $0D (probably an unintended, glitchy animation value)
$00:A200 05 71 ORA RAM_MarioAnimation ; \
$00:A202 0D 93 14 ORA.W $1493 ; } A = [Mario animation] | [$1493]; if both 0 (nothing special going on) skip
$00:A205 F0 0A BEQ $A211 ; /
$00:A207 A9 04 LDA.B #$04 ; \
$00:A209 14 15 TRB RAM_ControllerA ; / Mario is busy: ignore Down held ([$15] bit 2)
$00:A20B A9 40 LDA.B #$40 ; \
$00:A20D 14 16 TRB $16 ; } Also ignore Y just pressed ([$16] bit 6) and X just pressed ([$18] bit 6)
$00:A20F 14 18 TRB $18 ; /
$00:A211 AD D3 13 LDA.W $13D3 ; \
$00:A214 F0 05 BEQ $A21B ; / [$13D3] (pause delay) = 0: pausing allowed, else skip to the next check
$00:A216 CE D3 13 DEC.W $13D3 ; \
$00:A219 80 27 BRA $A242 ; / Delay running: [$13D3]--, skip the pause check
$00:A21B A5 16 LDA $16 ; \
$00:A21D 29 10 AND.B #$10 ; } Start not just pressed ([$16] bit 4 clear): skip the pause check
$00:A21F F0 21 BEQ $A242 ; /
$00:A221 AD 93 14 LDA.W $1493 ; \
$00:A224 D0 1C BNE $A242 ; / [$1493] != 0 (level is ending): skip
$00:A226 A5 71 LDA RAM_MarioAnimation ; \
$00:A228 C9 09 CMP.B #$09 ; } Mario animation >= 9 (death, level end, ...): skip
$00:A22A B0 16 BCS $A242 ; /
$00:A22C A9 3C LDA.B #$3C ; \
$00:A22E 8D D3 13 STA.W $13D3 ; / Pause delay [$13D3] = $3C frames
$00:A231 A0 12 LDY.B #$12 ; Y = $12 (sound effect: unpause)
$00:A233 AD D4 13 LDA.W $13D4 ; \
$00:A236 49 01 EOR.B #$01 ; } Toggle pause flag [$13D4]
$00:A238 8D D4 13 STA.W $13D4 ; /
$00:A23B F0 02 BEQ $A23F ; Now 0 (unpaused): keep Y = $12
$00:A23D A0 11 LDY.B #$11 ; Y = $11 (sound effect: pause)
$00:A23F 8C F9 1D STY.W $1DF9 ; Play the pause/unpause sound ([$1DF9])
$00:A242 AD D4 13 LDA.W $13D4 ; \
$00:A245 F0 43 BEQ $A28A ; / [$13D4] = 0 (not paused): run the game logic at $00A28A
$00:A247 80 12 BRA $A25B ; Paused: go handle Select (exit level)
$00:A249 2C A7 0D BIT.W $0DA7 ; \
$00:A24C 70 0B BVS $A259 ; / Unused debug slow motion: [$0DA7] bit 6 set runs the frame normally
$00:A24E AD A3 0D LDA.W $0DA3 ; \
$00:A251 10 08 BPL $A25B ; / Unused: [$0DA3] bit 7 clear: stay paused
$00:A253 A5 13 LDA RAM_FrameCounter ; \
$00:A255 29 0F AND.B #$0F ; } Unused: otherwise run game logic only every 16th frame
$00:A257 D0 02 BNE $A25B ; /
$00:A259 80 2F BRA $A28A ; Unused: run this frame's game logic
$00:A25B A5 15 LDA RAM_ControllerA ; \
$00:A25D 29 20 AND.B #$20 ; } Select not held ([$15] bit 5 clear): return
$00:A25F F0 28 BEQ $A289 ; /
$00:A261 AC BF 13 LDY.W $13BF ; \
$00:A264 B9 A2 1E LDA.W $1EA2,Y ; } Y = translevel [$13BF]; [$1EA2+Y] bit 7 clear (level not beaten yet): can't exit, return
$00:A267 10 20 BPL $A289 ; /
$00:A269 AD D5 0D LDA.W $0DD5 ; \
$00:A26C F0 02 BEQ $A270 ; / [$0DD5] = 0: no exit set yet, continue
$00:A26E 10 19 BPL $A289 ; Exit already set (positive value): return
$00:A270 A9 80 LDA.B #$80 ; A = $80: exit type for leaving with Select
$00:A272 80 0A BRA $A27E ; Skip the unused debug code
$00:A274 A9 01 LDA.B #$01 ; Unused debug: A = 1 (normal exit)
$00:A276 24 15 BIT RAM_ControllerA ; \
$00:A278 10 01 BPL $A27B ; / Unused debug: if B is held ([$15] bit 7)
$00:A27A 1A INC A ; Unused debug: A = 2 (secret exit)
$00:A27B 8D CE 13 STA.W $13CE ; Unused debug: [$13CE] = A (probably the midway flag)
$00:A27E 8D D5 0D STA.W $0DD5 ; [$0DD5] = exit type (level ends via Select)
$00:A281 EE E9 1D INC.W $1DE9 ; [$1DE9]++ (general transition counter, probably)
$00:A284 A9 0B LDA.B #$0B ; \
$00:A286 8D 00 01 STA.W RAM_GameMode ; / Game mode = $0B (fade out, back to the overworld)
$00:A289 60 RTS ; Return
$00:A28A AD 9B 0D LDA.W $0D9B ; \
$00:A28D 10 06 BPL $A295 ; / [$0D9B] bit 7 clear (normal level): go to $00A295
$00:A28F 20 7D 98 JSR.W $987D ; Mode 7 boss room: run the boss room frame code ($987D)
$00:A292 4C A9 A2 JMP.W $A2A9 ; Skip the normal level code, continue at $00A2A9
$00:A295 22 00 80 7F JSL.L RAM_7F8000 ; Move all sprites off-screen (RAM routine $7F8000)
$00:A299 22 DB F6 00 JSL.L $F6DB ; Handle screen scrolling ($F6DB)
$00:A29D 22 00 BC 05 JSL.L $BC00 ; Scroll the background layers ($BC00)
$00:A2A1 22 F1 86 05 JSL.L $86F1 ; Load map16 columns/rows as the screen scrolls ($86F1)
$00:A2A5 22 39 BB 05 JSL.L $BB39 ; Build the animated tile graphics for this frame ($BB39)
$00:A2A9 A5 1C LDA RAM_ScreenBndryYLo ; \
$00:A2AB 48 PHA ; |
$00:A2AC A5 1D LDA RAM_ScreenBndryYHi ; } Save the layer 1 Y scroll position on the stack
$00:A2AE 48 PHA ; /
$00:A2AF 9C 88 18 STZ.W RAM_Layer1DispYLo ; \
$00:A2B2 9C 89 18 STZ.W RAM_Layer1DispYHi ; / Layer 1 Y displacement [$1888] = 0
$00:A2B5 AD 87 18 LDA.W RAM_ShakeGrndTimer ; \
$00:A2B8 F0 1B BEQ $A2D5 ; / Shake ground timer [$1887] = 0: no shaking
$00:A2BA CE 87 18 DEC.W RAM_ShakeGrndTimer ; [$1887]--
$00:A2BD 29 03 AND.B #$03 ; \
$00:A2BF A8 TAY ; / Y = [$1887] & 3: index into the shake tables
$00:A2C0 B9 CE A1 LDA.W GrndShakeDispYLo,Y ; A = GrndShakeDispYLo[Y] ($FE, 0, 2, 0)
$00:A2C3 8D 88 18 STA.W RAM_Layer1DispYLo ; [$1888] = displacement low byte
$00:A2C6 18 CLC ; \
$00:A2C7 65 1C ADC RAM_ScreenBndryYLo ; } Layer 1 Y scroll low += displacement low
$00:A2C9 85 1C STA RAM_ScreenBndryYLo ; /
$00:A2CB B9 D2 A1 LDA.W GrndShakeDispYHi,Y ; A = GrndShakeDispYHi[Y]
$00:A2CE 8D 89 18 STA.W RAM_Layer1DispYHi ; [$1889] = displacement high byte
$00:A2D1 65 1D ADC RAM_ScreenBndryYHi ; \
$00:A2D3 85 1D STA RAM_ScreenBndryYHi ; / Layer 1 Y scroll high += displacement high (+ carry)
$00:A2D5 20 1A 8E JSR.W $8E1A ; Update the status bar ($8E1A)
$00:A2D8 22 BD E2 00 JSL.L $E2BD ; Draw Mario into OAM ($E2BD)
$00:A2DC 20 F3 A2 JSR.W $A2F3 ; Remember Mario's position for next frame
$00:A2DF 20 7E C4 JSR.W $C47E ; Run Mario: movement and interaction ($C47E)
$00:A2E2 22 8C 80 01 JSL.L $808C ; Run sprites ($808C)
$00:A2E6 22 B1 8A 02 JSL.L $8AB1 ; Run extended sprites and other misc objects ($8AB1, probably)
$00:A2EA 68 PLA ; \
$00:A2EB 85 1D STA RAM_ScreenBndryYHi ; |
$00:A2ED 68 PLA ; } Restore the layer 1 Y scroll saved above (high, then low)
$00:A2EE 85 1C STA RAM_ScreenBndryYLo ; /
$00:A2F0 4C 94 84 JMP.W $8494 ; Pack the OAM size bits and return ($8494)
$00:A2F3 C2 20 REP #$20 ; A 16-bit
$00:A2F5 A5 94 LDA RAM_MarioXPos ; \
$00:A2F7 85 D1 STA $D1 ; |
$00:A2F9 A5 96 LDA RAM_MarioYPos ; } [$D1] = Mario X position, [$D3] = Mario Y position (previous-frame copies)
$00:A2FB 85 D3 STA $D3 ; /
$00:A2FD E2 20 SEP #$20 ; A 8-bit
$00:A2FF 60 RTS ; Return
;;; $A300: DMA Mario graphics and palette (MarioGFXDMA) ;;;
;; NMI-time upload. If [$0D84] != 0, DMAs 10 colors from [$0D82] to CGRAM $86 (Mario's palette). Then DMAs one
;; tile from $7E:[$0D99] to VRAM $67F0, and Mario's
;; top row tiles (pointers at [$0D85]) to VRAM $6000 and bottom row (pointers at [$0D8F]) to $6100, $40 bytes
;; each, looping while X < [$0D84]. Uses DMA channel 2.
;; $00A390: DMAs up to three $80-byte animated tile blocks queued in [$0D76]-[$0D80], then falls into the
;; animated palette color write.
;; $00A41A: writes one animated color (A = CGRAM index, [$00] = set offset) from MorePalettes, stepped by
;; [$14] bits 2-4.
;; $00A436: if [$1935] is set, clears it and DMAs $C0 bytes from $0BF6 and $0CB6 to VRAM $64A0 and $65A0.
;; Called by:
;; $00:821D: NMI handler: sound, PPU mirrors, DMA (NMIStart)
;; $00:823A: NMI handler: sound, PPU mirrors, DMA (NMIStart)
;; $00:82D7: NMI tail: scroll, IRQ setup, Mode 7 path (NMINotSpecialLv)
$00:A300 C2 20 REP #$20 ; A 16-bit
$00:A302 A2 04 LDX.B #$04 ; X = 4: enable bit for DMA channel 2
$00:A304 AC 84 0D LDY.W $0D84 ; \
$00:A307 F0 1F BEQ $A328 ; / [$0D84] = 0: no Mario palette to upload, skip to $00A328
$00:A309 A0 86 LDY.B #$86 ; \
$00:A30B 8C 21 21 STY.W $2121 ; / CGRAM address = $86 (Mario's palette: palette 8, colors 6-F)
$00:A30E A9 00 22 LDA.W #$2200 ; \
$00:A311 8D 20 43 STA.W $4320 ; / DMA channel 2: write to CGDATA ($2122), 1 register
$00:A314 AD 82 0D LDA.W $0D82 ; \
$00:A317 8D 22 43 STA.W $4322 ; |
$00:A31A A0 00 LDY.B #$00 ; } Source = [$0D82], bank $00 (Mario's palette)
$00:A31C 8C 24 43 STY.W $4324 ; /
$00:A31F A9 14 00 LDA.W #$0014 ; \
$00:A322 8D 25 43 STA.W $4325 ; / Size = $14 bytes (10 colors)
$00:A325 8E 0B 42 STX.W $420B ; Start DMA: upload Mario's palette
$00:A328 A0 80 LDY.B #$80 ; \
$00:A32A 8C 15 21 STY.W $2115 ; / VMAIN = $80: VRAM address increments after high-byte writes
$00:A32D A9 01 18 LDA.W #$1801 ; \
$00:A330 8D 20 43 STA.W $4320 ; / DMA channel 2: write to VMDATA ($2118/$2119), 2 registers
$00:A333 A9 F0 67 LDA.W #$67F0 ; \
$00:A336 8D 16 21 STA.W $2116 ; / VRAM address = $67F0 (tile $7F of the sprite graphics)
$00:A339 AD 99 0D LDA.W $0D99 ; \
$00:A33C 8D 22 43 STA.W $4322 ; |
$00:A33F A0 7E LDY.B #$7E ; } Source = [$0D99] in bank $7E
$00:A341 8C 24 43 STY.W $4324 ; /
$00:A344 A9 20 00 LDA.W #$0020 ; \
$00:A347 8D 25 43 STA.W $4325 ; / Size = $20 bytes (one 8x8 4bpp tile)
$00:A34A 8E 0B 42 STX.W $420B ; Start DMA: one extra Mario tile
$00:A34D A9 00 60 LDA.W #$6000 ; \
$00:A350 8D 16 21 STA.W $2116 ; / VRAM address = $6000 (top row of Mario's tiles)
$00:A353 A2 00 LDX.B #$00 ; X = 0: index into the pointer lists
$00:A355 BD 85 0D LDA.W $0D85,X ; \
$00:A358 8D 22 43 STA.W $4322 ; / Source = [$0D85+X] (pointer to the next pair of tiles)
$00:A35B A9 40 00 LDA.W #$0040 ; \
$00:A35E 8D 25 43 STA.W $4325 ; / Size = $40 bytes (two 8x8 tiles)
$00:A361 A0 04 LDY.B #$04 ; \
$00:A363 8C 0B 42 STY.W $420B ; / Start DMA channel 2
$00:A366 E8 INX ; \
$00:A367 E8 INX ; / X += 2
$00:A368 EC 84 0D CPX.W $0D84 ; \
$00:A36B 90 E8 BCC $A355 ; / Repeat while X < [$0D84]
$00:A36D A9 00 61 LDA.W #$6100 ; \
$00:A370 8D 16 21 STA.W $2116 ; / VRAM address = $6100 (bottom row of Mario's tiles)
$00:A373 A2 00 LDX.B #$00 ; X = 0
$00:A375 BD 8F 0D LDA.W $0D8F,X ; \
$00:A378 8D 22 43 STA.W $4322 ; / Source = [$0D8F+X] (pointer to the next pair of tiles)
$00:A37B A9 40 00 LDA.W #$0040 ; \
$00:A37E 8D 25 43 STA.W $4325 ; / Size = $40 bytes
$00:A381 A0 04 LDY.B #$04 ; \
$00:A383 8C 0B 42 STY.W $420B ; / Start DMA channel 2
$00:A386 E8 INX ; \
$00:A387 E8 INX ; / X += 2
$00:A388 EC 84 0D CPX.W $0D84 ; \
$00:A38B 90 E8 BCC $A375 ; / Repeat while X < [$0D84]
$00:A38D E2 20 SEP #$20 ; A 8-bit
$00:A38F 60 RTS ; Return
$00:A390 C2 20 REP #$20 ; A 16-bit (queued animated tile DMA)
$00:A392 A0 80 LDY.B #$80 ; \
$00:A394 8C 15 21 STY.W $2115 ; / VMAIN = $80: increment after high-byte writes
$00:A397 A9 01 18 LDA.W #$1801 ; \
$00:A39A 8D 20 43 STA.W $4320 ; / DMA channel 2: write to VMDATA, 2 registers
$00:A39D A0 7E LDY.B #$7E ; \
$00:A39F 8C 24 43 STY.W $4324 ; / Source bank = $7E
$00:A3A2 A2 04 LDX.B #$04 ; X = 4: DMA channel 2 enable bit
$00:A3A4 AD 80 0D LDA.W $0D80 ; \
$00:A3A7 F0 12 BEQ $A3BB ; / [$0D80] = VRAM destination of tile block 1; 0 = none, skip
$00:A3A9 8D 16 21 STA.W $2116 ; VRAM address = [$0D80]
$00:A3AC AD 7A 0D LDA.W $0D7A ; Source = [$0D7A]
$00:A3AF 8D 22 43 STA.W $4322 ; A Address (Low Byte)
$00:A3B2 A9 80 00 LDA.W #$0080 ; \
$00:A3B5 8D 25 43 STA.W $4325 ; / Size = $80 bytes
$00:A3B8 8E 0B 42 STX.W $420B ; Start DMA
$00:A3BB AD 7E 0D LDA.W $0D7E ; \
$00:A3BE F0 12 BEQ $A3D2 ; / [$0D7E] = VRAM destination of tile block 2; 0 = none, skip
$00:A3C0 8D 16 21 STA.W $2116 ; VRAM address = [$0D7E]
$00:A3C3 AD 78 0D LDA.W $0D78 ; Source = [$0D78]
$00:A3C6 8D 22 43 STA.W $4322 ; A Address (Low Byte)
$00:A3C9 A9 80 00 LDA.W #$0080 ; \
$00:A3CC 8D 25 43 STA.W $4325 ; / Size = $80 bytes
$00:A3CF 8E 0B 42 STX.W $420B ; Start DMA
$00:A3D2 AD 7C 0D LDA.W $0D7C ; \
$00:A3D5 F0 41 BEQ $A418 ; / [$0D7C] = VRAM destination of tile block 3; 0 = none, skip to palette
$00:A3D7 8D 16 21 STA.W $2116 ; VRAM address = [$0D7C]
$00:A3DA C9 00 08 CMP.W #$0800 ; \
$00:A3DD F0 11 BEQ $A3F0 ; / Destination = $0800: special case, go to $00A3F0
$00:A3DF AD 76 0D LDA.W $0D76 ; Source = [$0D76]
$00:A3E2 8D 22 43 STA.W $4322 ; A Address (Low Byte)
$00:A3E5 A9 80 00 LDA.W #$0080 ; \
$00:A3E8 8D 25 43 STA.W $4325 ; / Size = $80 bytes
$00:A3EB 8E 0B 42 STX.W $420B ; Start DMA
$00:A3EE 80 28 BRA $A418 ; Done with the tile blocks, go to the palette animation
$00:A3F0 AD 76 0D LDA.W $0D76 ; Special case: source = [$0D76]
$00:A3F3 8D 22 43 STA.W $4322 ; A Address (Low Byte)
$00:A3F6 A9 40 00 LDA.W #$0040 ; \
$00:A3F9 8D 25 43 STA.W $4325 ; / Size = $40 bytes
$00:A3FC 8E 0B 42 STX.W $420B ; Start DMA: first half to VRAM $0800
$00:A3FF A9 00 09 LDA.W #$0900 ; \
$00:A402 8D 16 21 STA.W $2116 ; / VRAM address = $0900
$00:A405 AD 76 0D LDA.W $0D76 ; \
$00:A408 18 CLC ; } Source = [$0D76] + $40 (second half)
$00:A409 69 40 00 ADC.W #$0040 ; /
$00:A40C 8D 22 43 STA.W $4322 ; A Address (Low Byte)
$00:A40F A9 40 00 LDA.W #$0040 ; \
$00:A412 8D 25 43 STA.W $4325 ; / Size = $40 bytes
$00:A415 8E 0B 42 STX.W $420B ; Start DMA
$00:A418 E2 20 SEP #$20 ; A 8-bit
$00:A41A A9 64 LDA.B #$64 ; \
$00:A41C 64 00 STZ $00 ; } CGRAM address = $64 and offset [$00] = 0: animated palette color
$00:A41E 8D 21 21 STA.W $2121 ; /
$00:A421 A5 14 LDA RAM_FrameCounterB ; \
$00:A423 29 1C AND.B #$1C ; |
$00:A425 4A LSR ; } Y = ([$14] & $1C) / 2 + [$00]: index of this frame's color (8 frames, 2 bytes each)
$00:A426 65 00 ADC $00 ; /
$00:A428 A8 TAY ; Y = animation step
$00:A429 B9 0C B6 LDA.W MorePalettes,Y ; Write the color low byte from MorePalettes[Y]
$00:A42C 8D 22 21 STA.W $2122 ; Data for CG-RAM Write
$00:A42F B9 0D B6 LDA.W $B60D,Y ; Write the color high byte from $B60D[Y]
$00:A432 8D 22 21 STA.W $2122 ; Data for CG-RAM Write
$00:A435 60 RTS ; Return
$00:A436 AD 35 19 LDA.W $1935 ; A = flag [$1935]: upload extra tile rows?
$00:A439 F0 43 BEQ $A47E ; Flag clear: return
$00:A43B 9C 35 19 STZ.W $1935 ; Clear the flag
$00:A43E C2 20 REP #$20 ; A 16-bit
$00:A440 A0 80 LDY.B #$80 ; \
$00:A442 8C 15 21 STY.W $2115 ; / VMAIN = $80
$00:A445 A9 A0 64 LDA.W #$64A0 ; \
$00:A448 8D 16 21 STA.W $2116 ; / VRAM address = $64A0
$00:A44B A9 01 18 LDA.W #$1801 ; \
$00:A44E 8D 20 43 STA.W $4320 ; / DMA channel 2: write to VMDATA, 2 registers
$00:A451 A9 F6 0B LDA.W #$0BF6 ; \
$00:A454 8D 22 43 STA.W $4322 ; |
$00:A457 A0 00 LDY.B #$00 ; } Source = $00:0BF6
$00:A459 8C 24 43 STY.W $4324 ; /
$00:A45C A9 C0 00 LDA.W #$00C0 ; \
$00:A45F 8D 25 43 STA.W $4325 ; / Size = $C0 bytes
$00:A462 A2 04 LDX.B #$04 ; \
$00:A464 8E 0B 42 STX.W $420B ; / X = 4: start DMA channel 2
$00:A467 A9 A0 65 LDA.W #$65A0 ; \
$00:A46A 8D 16 21 STA.W $2116 ; / VRAM address = $65A0
$00:A46D A9 B6 0C LDA.W #$0CB6 ; Source = $00:0CB6
$00:A470 8D 22 43 STA.W $4322 ; A Address (Low Byte)
$00:A473 A9 C0 00 LDA.W #$00C0 ; \
$00:A476 8D 25 43 STA.W $4325 ; / Size = $C0 bytes
$00:A479 8E 0B 42 STX.W $420B ; Start DMA
$00:A47C E2 20 SEP #$20 ; A 8-bit
$00:A47E 60 RTS ; Return
;;; $A47F..A481: Table: palette buffer pointers ;;;
;; 3 bytes per entry (low, high, bank), indexed by [$0680] = 0, 3, 6: $00:0682, $00:0905, $00:0703.
$00:A47F .db $82 ; [$0680] = 0: low byte of $00:0682
$00:A480 .db $06 ; High byte of the buffer address
$00:A481 .db $00,$05,$09,$00,$03,$07,$00 ; Bank $00; then entry [$0680] = 3: $00:0905, entry 6: $00:0703 (3 bytes each)
;;; $A488: Upload queued palette records to CGRAM (MoreDMA) ;;;
;; Reads records at the buffer selected by [$0680]: length, CGRAM address, then colors; DMAs each to CGRAM
;; (channel 2) until a length of 0.
;; Then sets the fixed color via $AE47 and clears [$0680] (and [$0681]/[$0682] for buffer 0).
;; $00A4E3: DMA $0160 bytes from $00:0AF6 to VRAM $0750, then (unless [$13D9] = $0A) writes animated colors
;; $6D and $7D.
;; Called by:
;; $00:82EB: NMI tail: scroll, IRQ setup, Mode 7 path (NMINotSpecialLv)
$00:A488 AC 80 06 LDY.W $0680 ; Y = [$0680]: which palette buffer to upload (0, 3 or 6)
$00:A48B BE 81 A4 LDX.W $A481,Y ; X = bank of the buffer
$00:A48E 86 02 STX $02 ; [$02] = bank
$00:A490 64 01 STZ $01 ; [$01] = 0
$00:A492 64 00 STZ $00 ; [$00] = 0: pointer [$00] = bank:0000, so [$00],Y reads bank:Y
$00:A494 64 04 STZ $04 ; [$04] = 0
$00:A496 B9 80 A4 LDA.W $A480,Y ; A = high byte of the buffer address
$00:A499 EB XBA ; Move it to the high half of A
$00:A49A B9 7F A4 LDA.W $A47F,Y ; A = low byte of the buffer address
$00:A49D C2 10 REP #$10 ; Index registers 16-bit
$00:A49F A8 TAY ; Y = address of the buffer
$00:A4A0 B7 00 LDA [$00],Y ; A = length of the next record (bytes of colors)
$00:A4A2 F0 2B BEQ $A4CF ; Length 0: end of the list, go to $00A4CF
$00:A4A4 8E 24 43 STX.W $4324 ; DMA channel 2 source bank
$00:A4A7 8D 25 43 STA.W $4325 ; Size low = length
$00:A4AA 85 03 STA $03 ; [$03] = length
$00:A4AC 9C 26 43 STZ.W $4326 ; Size high = 0
$00:A4AF C8 INY ; Y++
$00:A4B0 B7 00 LDA [$00],Y ; A = CGRAM start address of the record
$00:A4B2 8D 21 21 STA.W $2121 ; Set the CGRAM address
$00:A4B5 C2 20 REP #$20 ; A 16-bit
$00:A4B7 A9 00 22 LDA.W #$2200 ; \
$00:A4BA 8D 20 43 STA.W $4320 ; / DMA channel 2: write to CGDATA, 1 register
$00:A4BD C8 INY ; \
$00:A4BE 98 TYA ; } Source = address of the color data (just after the 2-byte header)
$00:A4BF 8D 22 43 STA.W $4322 ; /
$00:A4C2 18 CLC ; \
$00:A4C3 65 03 ADC $03 ; } Y += length: next record
$00:A4C5 A8 TAY ; /
$00:A4C6 E2 20 SEP #$20 ; A 8-bit
$00:A4C8 A9 04 LDA.B #$04 ; \
$00:A4CA 8D 0B 42 STA.W $420B ; / Start DMA channel 2: upload the colors
$00:A4CD 80 D1 BRA $A4A0 ; Next record
$00:A4CF E2 10 SEP #$10 ; Index registers 8-bit
$00:A4D1 20 47 AE JSR.W $AE47 ; Set the fixed color from the backdrop color ($AE47)
$00:A4D4 AD 80 06 LDA.W $0680 ; \
$00:A4D7 D0 06 BNE $A4DF ; / [$0680] != 0: skip clearing buffer 0
$00:A4D9 9C 81 06 STZ.W $0681 ; Buffer 0: clear [$0681] (probably the write index)
$00:A4DC 9C 82 06 STZ.W $0682 ; Clear [$0682], the first record length (empty list)
$00:A4DF 9C 80 06 STZ.W $0680 ; [$0680] = 0: nothing more to upload
$00:A4E2 60 RTS ; Return
$00:A4E3 C2 10 REP #$10 ; Index registers 16-bit (overworld/other-mode DMA)
$00:A4E5 A9 80 LDA.B #$80 ; \
$00:A4E7 8D 15 21 STA.W $2115 ; / VMAIN = $80
$00:A4EA A0 50 07 LDY.W #$0750 ; \
$00:A4ED 8C 16 21 STY.W $2116 ; / VRAM address = $0750
$00:A4F0 A0 01 18 LDY.W #$1801 ; \
$00:A4F3 8C 20 43 STY.W $4320 ; / DMA channel 2: write to VMDATA, 2 registers
$00:A4F6 A0 F6 0A LDY.W #$0AF6 ; \
$00:A4F9 8C 22 43 STY.W $4322 ; } Source = $00:0AF6
$00:A4FC 9C 24 43 STZ.W $4324 ; /
$00:A4FF A0 60 01 LDY.W #$0160 ; \
$00:A502 8C 25 43 STY.W $4325 ; / Size = $0160 bytes
$00:A505 A9 04 LDA.B #$04 ; \
$00:A507 8D 0B 42 STA.W $420B ; / Start DMA channel 2
$00:A50A E2 10 SEP #$10 ; Index registers 8-bit
$00:A50C AD D9 13 LDA.W $13D9 ; \
$00:A50F C9 0A CMP.B #$0A ; } [$13D9] = $0A? (overworld process, probably): skip the palette animation
$00:A511 F0 CF BEQ $A4E2 ; /
$00:A513 A9 6D LDA.B #$6D ; A = $6D: CGRAM color to animate
$00:A515 20 1C A4 JSR.W $A41C ; Animate that color from set 0 ($A41C)
$00:A518 A9 10 LDA.B #$10 ; Offset = $10 (second set of animation colors)
$00:A51A 85 00 STA $00 ; Store it in [$00]
$00:A51C A9 7D LDA.B #$7D ; A = $7D: CGRAM color to animate
$00:A51E 4C 1E A4 JMP.W $A41E ; Animate that color (continues at $A41E, then returns)
;;; $A521..A525: Table: tilemap page offsets ;;;
;; Two 4-byte tables indexed by Y: VRAM high byte steps ($00, $04, $08, $0C) and source high byte steps ($00,
;; $08, $10, $18).
$00:A521 .db $00,$04,$08,$0C ; $00 - offsets $00, $04, $08, $0C (VRAM high byte steps for each page)
$00:A525 .db $00,$08,$10,$18 ; $00 - offsets $00, $08, $10, $18 (source high byte steps, $800 bytes per page)
;;; $A529: DMA tilemap pages to VRAM ;;;
;; Probably overworld. Y = page index (0-3). DMAs $0800 bytes from $7F:4000 (or $7F:6000 if the player's
;; submap [$1F11+x] is non-zero) + $800 * Y to VRAM $3000 + $400 * Y,
;; then $0800 bytes from $7E:E400 to VRAM $2000 + $400 * Y. Uses DMA channel 1.
;; Parameters: Y: page index.
$00:A529 A9 80 LDA.B #$80 ; \
$00:A52B 8D 15 21 STA.W $2115 ; / VMAIN = $80
$00:A52E 9C 16 21 STZ.W $2116 ; VRAM address low = 0
$00:A531 A9 30 LDA.B #$30 ; \
$00:A533 18 CLC ; |
$00:A534 79 21 A5 ADC.W $A521,Y ; } VRAM address high = $30 + $A521[Y]: destination page $3000, $3400, ...
$00:A537 8D 17 21 STA.W $2117 ; /
$00:A53A A2 06 LDX.B #$06 ; X = 6: copy 7 bytes of DMA setup
$00:A53C BD 86 A5 LDA.W $A586,X ; Read a setup byte from $A586
$00:A53F 9D 10 43 STA.W $4310,X ; Write it to $4310-$4316 (DMA channel 1)
$00:A542 CA DEX ; X--
$00:A543 10 F7 BPL $A53C ; Loop until X < 0
$00:A545 AD D6 0D LDA.W $0DD6 ; A = [$0DD6] / 4 = player index (probably)
$00:A548 4A LSR ; A >>= 1
$00:A549 4A LSR ; A >>= 1 (done)
$00:A54A AA TAX ; X = index
$00:A54B BD 11 1F LDA.W $1F11,X ; A = [$1F11+X]: submap the player is on
$00:A54E F0 05 BEQ $A555 ; Submap 0: keep source $7F:4000
$00:A550 A9 60 LDA.B #$60 ; Other submap: source high byte = $60 ($7F:6000)
$00:A552 8D 13 43 STA.W $4313 ; Write it to the A-bus high byte
$00:A555 AD 13 43 LDA.W $4313 ; Read back the source high byte
$00:A558 18 CLC ; Prepare to add the page offset
$00:A559 79 25 A5 ADC.W $A525,Y ; Add $A525[Y]: source advances $800 bytes per page
$00:A55C 8D 13 43 STA.W $4313 ; Store the source high byte
$00:A55F A9 02 LDA.B #$02 ; A = 2: DMA channel 1 enable bit
$00:A561 8D 0B 42 STA.W $420B ; Start DMA: $800 bytes to VRAM (tilemap page)
$00:A564 A9 80 LDA.B #$80 ; \
$00:A566 8D 15 21 STA.W $2115 ; / VMAIN = $80
$00:A569 9C 16 21 STZ.W $2116 ; VRAM address low = 0
$00:A56C A9 20 LDA.B #$20 ; \
$00:A56E 18 CLC ; |
$00:A56F 79 21 A5 ADC.W $A521,Y ; } VRAM address high = $20 + $A521[Y]
$00:A572 8D 17 21 STA.W $2117 ; /
$00:A575 A2 06 LDX.B #$06 ; X = 6: copy 7 bytes of DMA setup
$00:A577 BD 8D A5 LDA.W $A58D,X ; Read a setup byte from $A58D
$00:A57A 9D 10 43 STA.W $4310,X ; Write it to $4310-$4316
$00:A57D CA DEX ; X--
$00:A57E 10 F7 BPL $A577 ; Loop until X < 0
$00:A580 A9 02 LDA.B #$02 ; A = 2: DMA channel 1 enable bit
$00:A582 8D 0B 42 STA.W $420B ; Start DMA: $800 bytes from $7E:E400 to VRAM (second tilemap page)
$00:A585 60 RTS ; Return
;;; $A586..A58D: Table: DMA setup for tilemap pages ;;;
;; Two 7-byte blocks copied to $4310-$4316: DMAP $01, B-bus $18, source $7F:4000 / $7E:E400, size $0800.
$00:A586 .db $01,$18,$00,$40,$7F,$00,$08 ; DMAP $01, B-bus $18, source $7F:4000, size $0800
$00:A58D .db $01,$18,$00,$E4,$7E,$00,$08 ; DMAP $01, B-bus $18, source $7E:E400, size $0800
;;; $A594: Long wrapper for CODE_00AD25 ;;;
;; Sets the data bank to $00, runs $AD25 and returns with RTL. Called from bank $04.
;; Called by:
;; $04:DBAE: Submap switch states and iris effect (Ptrs04DAF8)
$00:A594 8B PHB ; Save the data bank
$00:A595 4B PHK ; Push the program bank
$00:A596 AB PLB ; Data bank = $00
$00:A597 20 25 AD JSR.W $AD25 ; Run $AD25
$00:A59A AB PLB ; Restore the data bank
$00:A59B 6B RTL ; Return long (called from bank $04)
;;; $A59C: Game mode 12: prepare level (GM04Load) ;;;
;; Turns off the screen and I/O, loads the level ($809E), uploads sprite graphics and palettes, sets up
;; the scroll and tile animation,
;; draws Mario, copies the palette mirror $0703 to $0905 ($01F0 bytes), then increments the game mode (to $13,
;; fade into level).
;; Boss rooms ([$0D9B] bit 7) use $97BC instead of the normal graphics/palette setup.
;; $00A5F9: pre-runs 8 steps of tile animation ($BB39 + $A390) so tiles are ready at the first
;; frame.
;; Called by:
;; $00:9595: Cutscene, ending and game mode code (castle scenes, credits, game over) (CutsceneCastlePal)
;; $00:9A8E: Detect connected controllers into [$0DA0] (SetUp0DA0GM4)
$00:A59C 20 FA 85 JSR.W $85FA ; Turn off NMI/IRQ, HDMA and the screen ($85FA)
$00:A59F 20 2D F6 JSR.W NoButtons ; Clear controller input (NoButtons)
$00:A5A2 9C 3A 14 STZ.W $143A ; [$143A] = 0: no Mario Start! graphics to upload
$00:A5A5 20 79 8A JSR.W SetUpScreen ; Reset screen settings (SetUpScreen)
$00:A5A8 20 FF 8C JSR.W GM04DoDMA ; Initial VRAM DMA (GM04DoDMA)
$00:A5AB 22 9E 80 05 JSL.L $809E ; Load the level ($809E)
$00:A5AF AD 9B 0D LDA.W $0D9B ; \
$00:A5B2 10 05 BPL $A5B9 ; / [$0D9B] bit 7 clear: normal level, go to $00A5B9
$00:A5B4 20 BC 97 JSR.W $97BC ; Mode 7 boss room: set up the room ($97BC)
$00:A5B7 80 16 BRA $A5CF ; Skip the normal level setup
$00:A5B9 20 DA A9 JSR.W UploadSpriteGFX ; Upload sprite graphics (UploadSpriteGFX)
$00:A5BC 20 ED AB JSR.W LoadPalette ; Load the palettes (LoadPalette)
$00:A5BF 22 8A BE 05 JSL.L $BE8A ; Initialize the layer 2/3 scroll variables ($BE8A)
$00:A5C3 20 B8 9F JSR.W $9FB8 ; Tileset-dependent setup ($9FB8, uses tileset [$1931])
$00:A5C6 20 F9 A5 JSR.W $A5F9 ; Pre-run 8 frames of tile animation ($A5F9)
$00:A5C9 20 60 92 JSR.W $9260 ; Disable HDMA and clear the window HDMA table ($9260)
$00:A5CC 20 60 98 JSR.W $9860 ; Draw Mario into OAM ($9860)
$00:A5CF 20 2F 92 JSR.W $922F ; Make the first two palette bytes black and DMA them to CGRAM ($922F)
$00:A5D2 20 29 9F JSR.W KeepModeActive ; Enable NMI and joypad (KeepModeActive)
$00:A5D5 20 1A 8E JSR.W $8E1A ; Update the status bar ($8E1A)
$00:A5D8 C2 30 REP #$30 ; A, X and Y 16-bit
$00:A5DA 8B PHB ; Save the data bank
$00:A5DB A2 03 07 LDX.W #$0703 ; X = $0703: source (palette mirror)
$00:A5DE A0 05 09 LDY.W #$0905 ; Y = $0905: destination
$00:A5E1 A9 EF 01 LDA.W #$01EF ; A = $01EF: copy $01F0 bytes
$00:A5E4 54 00 00 MVN $00,$00 ; Copy the palette mirror to $0905 (block move)
$00:A5E7 AB PLB ; Restore the data bank
$00:A5E8 AE 01 07 LDX.W $0701 ; X = [$0701] (backdrop color)
$00:A5EB 8E 03 09 STX.W $0903 ; Store it at [$0903] (backdrop color of the copy)
$00:A5EE E2 30 SEP #$30 ; A, X and Y 8-bit
$00:A5F0 20 9B 91 JSR.W $919B ; Castle entry animation or, if [$141A] = 0, coins to collect [$0DC0] = 30 ($919B)
$00:A5F3 20 94 84 JSR.W $8494 ; Pack the OAM size bits ($8494)
$00:A5F6 4C F4 93 JMP.W $93F4 ; Game mode++ (to $13, fading into the level)
$00:A5F9 A9 E7 LDA.B #$E7 ; \
$00:A5FB 14 14 TRB RAM_FrameCounterB ; / Clear bits 0-2 and 5-7 of the frame counter [$14] (keep bits 3-4)
$00:A5FD 22 39 BB 05 JSL.L $BB39 ; Build animated tile graphics for the current step ($BB39)
$00:A601 20 90 A3 JSR.W $A390 ; DMA the queued animated tiles to VRAM ($A390)
$00:A604 E6 14 INC RAM_FrameCounterB ; [$14]++
$00:A606 A5 14 LDA RAM_FrameCounterB ; A = [$14]
;;; $A608: Instruction: AND #$07 (Instr00A608) ;;;
;; An AND #$07 encoded as .db $29,$07; part of the loop in $A5F9 (8 iterations).
$00:A608 .db $29,$07 ; A &= 7 (instruction stored as data)
$00:A60A D0 F1 BNE $A5FD ; Not yet 8 steps: repeat from $00A5FD
$00:A60C 60 RTS ; Return
;;; $A60D..A619: Data: unreferenced, purpose unclear ;;;
$00:A60D .db $00,$01,$01,$01 ; Unreferenced data, purpose unclear
$00:A611 .db $0D,$00,$F3,$FF,$FE,$FF,$FE,$FF ; Unreferenced data, purpose unclear
$00:A619 .db $00,$00,$00,$00 ; Unreferenced data, purpose unclear
;;; $A61D..A62D: Data: unreferenced, purpose unclear ;;;
$00:A61D .db $0A,$00,$00,$00,$1A,$1A,$0A,$0A ; Unreferenced data, purpose unclear
$00:A625 .db $00,$80,$40,$00,$01,$02,$40,$00 ; Unreferenced data, purpose unclear
$00:A62D .db $40,$00,$00,$00,$00,$02,$00,$00 ; Unreferenced data, purpose unclear
;;; $A635: Level start setup, Mario Start! graphics ;;;
;; $00A635: level start reset. Cancels POW/star timers (forcing normal music), clears Mario and level state,
;; then positions Mario for the
;; level entrance type [$192A] (start in the air, from a pipe, water level, keyhole, Yoshi Wings bonus).
;; Several parts are guesses.
;; $00A796: initializes layer 2 vertical scroll offset [$1417] from [$1414], [$1C], [$20], and [$142A] =
;; $0080.
;; $00A7C2: DMAs the buffer at $7F:977B to VRAM $6000, $6100, $64A0 and $65A0 ($C0 bytes each) for the Mario
;; Start! graphics.
;; $00A82D: builds those tiles: decompresses GFX file $0F, converts 24 tiles from 3bpp to 4bpp into $7F:977B
;; (+$30 offset if [$1425]),
;; also converts 12 tiles of file 0 into $0BF6, sets [$143A] and [$1935] so NMI DMAs them.
;; Called by:
;; $00:94EB: Cutscene, ending and game mode code (castle scenes, credits, game over) (CutsceneCastlePal)
;; $00:9705: Game mode 11: Mario Start, level music (MarioStartGameMode)
$00:A635 AD AD 14 LDA.W RAM_BluePowTimer ; \
$00:A638 0D AE 14 ORA.W RAM_SilverPowTimer ; |
$00:A63B 0D 0C 19 ORA.W $190C ; } Blue POW, silver POW or [$190C] timer active: go to A64A
$00:A63E D0 0A BNE $A64A ; /
$00:A640 AD 90 14 LDA.W $1490 ; \
$00:A643 F0 1B BEQ $A660 ; / No star power ([$1490] = 0): skip to A660
$00:A645 AD DA 0D LDA.W $0DDA ; \
$00:A648 10 05 BPL $A64F ; / [$0DDA] bit 7 clear: go to A64F
$00:A64A AD DA 0D LDA.W $0DDA ; \
$00:A64D 29 7F AND.B #$7F ; |
$00:A64F 09 40 ORA.B #$40 ; } [$0DDA] = ([$0DDA] & $7F) | $40 (back to normal music, bit 6 set)
$00:A651 8D DA 0D STA.W $0DDA ; /
$00:A654 9C AD 14 STZ.W RAM_BluePowTimer ; Cancel blue POW timer
$00:A657 9C AE 14 STZ.W RAM_SilverPowTimer ; Cancel silver POW timer
$00:A65A 9C 0C 19 STZ.W $190C ; Cancel [$190C] timer
$00:A65D 9C 90 14 STZ.W $1490 ; Cancel star power timer
$00:A660 AD F4 13 LDA.W $13F4 ; \
$00:A663 0D F5 13 ORA.W $13F5 ; |
$00:A666 0D F6 13 ORA.W $13F6 ; |
$00:A669 0D F7 13 ORA.W $13F7 ; |
$00:A66C 0D F8 13 ORA.W $13F8 ; } A = [$13F4] | [$13F5] | [$13F6] | [$13F7] | [$13F8]; all zero: go to A674
$00:A66F F0 03 BEQ $A674 ; /
$00:A671 8D 1B 14 STA.W $141B ; [$141B] = that non-zero value (probably a persistent level effect flag)
$00:A674 A2 23 LDX.B #$23 ; \
$00:A676 74 70 STZ $70,X ; |
$00:A678 CA DEX ; } Clear [$71]-[$93] (Mario animation, pipe info and other state)
$00:A679 D0 FB BNE $A676 ; /
$00:A67B A2 37 LDX.B #$37 ; \
$00:A67D 9E D9 13 STZ.W $13D9,X ; |
$00:A680 CA DEX ; } Clear [$13DA]-[$1410] (more per-level state)
$00:A681 D0 FA BNE $A67D ; /
$00:A683 0E CB 13 ASL.W $13CB ; [$13CB] <<= 1 (purpose unclear)
$00:A686 9C 9A 14 STZ.W RAM_KickImgTimer ; Clear kick image timer
$00:A689 9C 98 14 STZ.W RAM_PickUpImgTimer ; Clear pick-up image timer
$00:A68C 9C 95 14 STZ.W $1495 ; Clear [$1495]
$00:A68F 9C 19 14 STZ.W RAM_YoshiInPipe ; Clear Yoshi-in-pipe flag [$1419]
$00:A692 A0 01 LDY.B #$01 ; Y = 1 (Mario facing right, used below)
$00:A694 AE 31 19 LDX.W $1931 ; \
$00:A697 E0 10 CPX.B #$10 ; } Tileset [$1931] >= $10: go to A6CC
$00:A699 B0 31 BCS $A6CC ; /
$00:A69B BD 25 A6 LDA.W $A625,X ; A = $A625[tileset] (per-tileset flag byte)
$00:A69E 4A LSR ; \
$00:A69F F0 2B BEQ $A6CC ; / Only bit 0 or nothing set: go to A6CC
$00:A6A1 AD 1D 14 LDA.W $141D ; \
$00:A6A4 0D 1A 14 ORA.W $141A ; |
$00:A6A7 0D 1F 14 ORA.W $141F ; } [$141D] | [$141A] | [$141F] non-zero: go to A6CC
$00:A6AA D0 20 BNE $A6CC ; /
$00:A6AC AD CF 13 LDA.W $13CF ; \
$00:A6AF F0 05 BEQ $A6B6 ; / [$13CF] = 0: go to A6B6
$00:A6B1 20 0A C9 JSR.W $C90A ; [$13CF] set: [$1B9B] = 1 and play sound $03 on [$1DFA] ($C90A)
$00:A6B4 80 16 BRA $A6CC ; Go to A6CC
$00:A6B6 64 72 STZ RAM_IsFlying ; Mario not in the air: [$72] = 0
$00:A6B8 84 76 STY RAM_MarioDirection ; Mario faces right: [$76] = 1
$00:A6BA 84 89 STY $89 ; [$89] = 1
$00:A6BC A2 0A LDX.B #$0A ; X = $0A: Mario animation
$00:A6BE A0 00 LDY.B #$00 ; Y = 0: animation timer
$00:A6C0 AD C1 0D LDA.W RAM_OWHasYoshi ; \
$00:A6C3 F0 02 BEQ $A6C7 ; / Overworld Yoshi flag [$0DC1] clear: go to A6C7
$00:A6C5 A0 0F LDY.B #$0F ; Y = $0F: animation timer when Yoshi came along
$00:A6C7 86 71 STX RAM_MarioAnimation ; Mario animation [$71] = X
$00:A6C9 84 88 STY $88 ; Animation timer [$88] = Y
$00:A6CB 60 RTS ; Return
$00:A6CC A5 1C LDA RAM_ScreenBndryYLo ; \
$00:A6CE C9 C0 CMP.B #$C0 ; |
$00:A6D0 F0 03 BEQ $A6D5 ; } [$13F1]++ unless layer 1 Y [$1C] = $C0 (probably a scroll-related counter)
$00:A6D2 EE F1 13 INC.W $13F1 ; /
$00:A6D5 AD 2A 19 LDA.W $192A ; A = [$192A] (level entrance type, probably from the level header)
$00:A6D8 F0 06 BEQ $A6E0 ; 0: go to A6E0
$00:A6DA C9 05 CMP.B #$05 ; \
$00:A6DC D0 38 BNE $A716 ; / Not 5: go to A716
$00:A6DE 66 86 ROR $86 ; Carry is set here, so bit 7 of [$86] is set (probably the slippery/ice flag)
$00:A6E0 84 76 STY RAM_MarioDirection ; Mario faces right: [$76] = 1
$00:A6E2 A9 24 LDA.B #$24 ; \
$00:A6E4 85 72 STA RAM_IsFlying ; / [$72] = $24 (Mario starts in the air, probably falling in)
$00:A6E6 64 9D STZ RAM_SpritesLocked ; Unlock sprites: [$9D] = 0
$00:A6E8 AD 34 14 LDA.W $1434 ; \
$00:A6EB F0 17 BEQ $A704 ; / [$1434] (keyhole animation timer) = 0: go to A704
$00:A6ED AD DA 0D LDA.W $0DDA ; \
$00:A6F0 09 7F ORA.B #$7F ; } [$0DDA] |= $7F
$00:A6F2 8D DA 0D STA.W $0DDA ; /
$00:A6F5 A5 94 LDA RAM_MarioXPos ; \
$00:A6F7 09 04 ORA.B #$04 ; } [$1436] = Mario X low | 4 (keyhole X position)
$00:A6F9 8D 36 14 STA.W RAM_KeyHolePos1 ; /
$00:A6FC A5 96 LDA RAM_MarioYPos ; \
$00:A6FE 18 CLC ; |
$00:A6FF 69 10 ADC.B #$10 ; } [$1438] = Mario Y low + $10 (keyhole Y position)
$00:A701 8D 38 14 STA.W RAM_KeyHolePos2 ; /
$00:A704 AD 95 1B LDA.W $1B95 ; \
$00:A707 F0 0C BEQ $A715 ; / [$1B95] (Yoshi Wings bonus flag) = 0: return
$00:A709 A9 08 LDA.B #$08 ; \
$00:A70B 85 71 STA RAM_MarioAnimation ; / Mario animation [$71] = 8 (rise off screen, Yoshi Wings bonus)
$00:A70D A9 A0 LDA.B #$A0 ; \
$00:A70F 85 96 STA RAM_MarioYPos ; / Mario Y position low = $A0
$00:A711 A9 90 LDA.B #$90 ; \
$00:A713 85 7D STA RAM_MarioSpeedY ; / Mario Y speed = $90 (upward)
$00:A715 60 RTS ; Return
$00:A716 C9 06 CMP.B #$06 ; \
$00:A718 90 26 BCC $A740 ; / Entrance type < 6 (1-4): go to A740
$00:A71A D0 18 BNE $A734 ; Entrance type > 6: go to A734
$00:A71C 84 76 STY RAM_MarioDirection ; Mario faces right: [$76] = 1
$00:A71E 8C DF 13 STY.W $13DF ; [$13DF] = 1
$00:A721 A9 FF LDA.B #$FF ; \
$00:A723 8D 19 14 STA.W RAM_YoshiInPipe ; / Yoshi-in-pipe [$1419] = $FF
$00:A726 A9 08 LDA.B #$08 ; \
$00:A728 04 94 TSB RAM_MarioXPos ; / Mario X position low |= 8
$00:A72A A9 02 LDA.B #$02 ; \
$00:A72C 04 96 TSB RAM_MarioYPos ; / Mario Y position low |= 2
$00:A72E A2 07 LDX.B #$07 ; X = 7: Mario animation
$00:A730 A0 20 LDY.B #$20 ; Y = $20: animation timer
$00:A732 80 93 BRA $A6C7 ; Go set [$71] = X, [$88] = Y (A6C7)
$00:A734 84 85 STY RAM_IsWaterLevel ; Water level flag [$85] = 1
$00:A736 AD CF 13 LDA.W $13CF ; \
$00:A739 0D 34 14 ORA.W $1434 ; } [$13CF] | [$1434] non-zero: go to A6E0
$00:A73C D0 A2 BNE $A6E0 ; /
$00:A73E A9 04 LDA.B #$04 ; A = 4: treat as entrance type 4
$00:A740 18 CLC ; \
$00:A741 69 03 ADC.B #$03 ; } [$89] = A + 3
$00:A743 85 89 STA $89 ; /
$00:A745 A8 TAY ; Y = [$89]
$00:A746 4A LSR ; \
$00:A747 3A DEC A ; } [$1419] = ([$89] >> 1) - 1
$00:A748 8D 19 14 STA.W RAM_YoshiInPipe ; /
$00:A74B B9 09 A6 LDA.W ADDR_00A609,Y ; A = ADDR_00A609[Y] (direction byte)
$00:A74E 85 76 STA RAM_MarioDirection ; Mario direction [$76] = A
$00:A750 A2 05 LDX.B #$05 ; X = 5: Mario animation
$00:A752 C0 06 CPY.B #$06 ; \
$00:A754 90 12 BCC $A768 ; / [$89] < 6: go to A768
$00:A756 A9 08 LDA.B #$08 ; \
$00:A758 04 94 TSB RAM_MarioXPos ; / Mario X position low |= 8
$00:A75A A2 06 LDX.B #$06 ; X = 6: Mario animation
$00:A75C C0 07 CPY.B #$07 ; \
$00:A75E A0 1E LDY.B #$1E ; } [$89] < 7: Y = $1E and go to A76A
$00:A760 90 08 BCC $A76A ; /
$00:A762 A0 0F LDY.B #$0F ; Y = $0F
$00:A764 A5 19 LDA RAM_MarioPowerUp ; \
$00:A766 F0 02 BEQ $A76A ; / Mario small ([$19] = 0): keep Y = $0F, go to A76A
$00:A768 A0 1C LDY.B #$1C ; Y = $1C
$00:A76A 84 7D STY RAM_MarioSpeedY ; Mario Y speed [$7D] = Y
$00:A76C 20 C7 A6 JSR.W $A6C7 ; Set [$71] = X, [$88] = Y (A6C7)
$00:A76F AD 7A 18 LDA.W RAM_OnYoshi ; \
$00:A772 F0 21 BEQ $A795 ; / Not on Yoshi ([$187A] = 0): return
$00:A774 A6 89 LDX $89 ; X = [$89]
$00:A776 A5 88 LDA $88 ; \
$00:A778 18 CLC ; |
$00:A779 7D 1D A6 ADC.W $A61D,X ; } [$88] += $A61D[X] (longer animation on Yoshi)
$00:A77C 85 88 STA $88 ; /
$00:A77E 8A TXA ; \
$00:A77F 0A ASL ; } X = [$89] * 2
$00:A780 AA TAX ; /
$00:A781 C2 20 REP #$20 ; A 16-bit
$00:A783 A5 94 LDA RAM_MarioXPos ; \
$00:A785 18 CLC ; |
$00:A786 7D 09 A6 ADC.W ADDR_00A609,X ; } Mario X position += ADDR_00A609[X] (16-bit offset)
$00:A789 85 94 STA RAM_MarioXPos ; /
$00:A78B A5 96 LDA RAM_MarioYPos ; \
$00:A78D 18 CLC ; |
$00:A78E 7D 11 A6 ADC.W $A611,X ; } Mario Y position += $A611[X] (16-bit offset)
$00:A791 85 96 STA RAM_MarioYPos ; /
$00:A793 E2 20 SEP #$20 ; A 8-bit
$00:A795 60 RTS ; Return
$00:A796 C2 20 REP #$20 ; A 16-bit
$00:A798 AC 14 14 LDY.W $1414 ; Y = [$1414] (probably layer 2 vertical scroll mode)
$00:A79B F0 1C BEQ $A7B9 ; 0: go to A7B9
$00:A79D 88 DEY ; \
$00:A79E D0 07 BNE $A7A7 ; / Mode != 1: go to A7A7
$00:A7A0 A5 20 LDA $20 ; \
$00:A7A2 38 SEC ; } A = [$20] - [$1C] (layer 2 Y minus layer 1 Y)
$00:A7A3 E5 1C SBC RAM_ScreenBndryYLo ; /
$00:A7A5 80 0F BRA $A7B6 ; Go to A7B6
$00:A7A7 A5 1C LDA RAM_ScreenBndryYLo ; A = [$1C]
$00:A7A9 4A LSR ; A = [$1C] / 2
$00:A7AA 88 DEY ; \
$00:A7AB F0 02 BEQ $A7AF ; / Mode 2: skip the extra shifts
$00:A7AD 4A LSR ; \
$00:A7AE 4A LSR ; / Mode 3+: A = [$1C] / 8
$00:A7AF 49 FF FF EOR.W #$FFFF ; \
$00:A7B2 1A INC A ; |
$00:A7B3 18 CLC ; } A = [$20] - A
$00:A7B4 65 20 ADC $20 ; /
$00:A7B6 8D 17 14 STA.W $1417 ; [$1417] = A (initial layer 2 Y offset, probably)
$00:A7B9 A9 80 00 LDA.W #$0080 ; \
$00:A7BC 8D 2A 14 STA.W $142A ; / [$142A] = $0080: initial position of the static camera region
$00:A7BF E2 20 SEP #$20 ; A 8-bit
$00:A7C1 60 RTS ; Return
$00:A7C2 C2 20 REP #$20 ; A 16-bit
$00:A7C4 A2 80 LDX.B #$80 ; \
$00:A7C6 8E 15 21 STX.W $2115 ; / VMAIN = $80: increment after high-byte writes
$00:A7C9 A9 00 60 LDA.W #$6000 ; \
$00:A7CC 8D 16 21 STA.W $2116 ; / VRAM address = $6000
$00:A7CF A9 01 18 LDA.W #$1801 ; \
$00:A7D2 8D 20 43 STA.W $4320 ; / DMA 2: mode 1 (two registers), B-bus $18 (VRAM data)
$00:A7D5 A9 7B 97 LDA.W #$977B ; \
$00:A7D8 8D 22 43 STA.W $4322 ; / DMA 2 source address = $xx:977B
$00:A7DB A2 7F LDX.B #$7F ; \
$00:A7DD 8E 24 43 STX.W $4324 ; / DMA 2 source bank = $7F
$00:A7E0 A9 C0 00 LDA.W #$00C0 ; \
$00:A7E3 8D 25 43 STA.W $4325 ; / DMA 2 size = $00C0 bytes
$00:A7E6 A2 04 LDX.B #$04 ; \
$00:A7E8 8E 0B 42 STX.W $420B ; / X = 4: DMA channel 2 enable bit
$00:A7EB A9 00 61 LDA.W #$6100 ; \
$00:A7EE 8D 16 21 STA.W $2116 ; / VRAM address = $6100
$00:A7F1 A9 3B 98 LDA.W #$983B ; \
$00:A7F4 8D 22 43 STA.W $4322 ; / DMA 2 source address = $983B
$00:A7F7 A9 C0 00 LDA.W #$00C0 ; \
$00:A7FA 8D 25 43 STA.W $4325 ; / DMA 2 size = $00C0 bytes
$00:A7FD 8E 0B 42 STX.W $420B ; Start DMA channel 2
$00:A800 A9 A0 64 LDA.W #$64A0 ; \
$00:A803 8D 16 21 STA.W $2116 ; / VRAM address = $64A0
$00:A806 A9 FB 98 LDA.W #$98FB ; \
$00:A809 8D 22 43 STA.W $4322 ; / DMA 2 source address = $98FB
$00:A80C A9 C0 00 LDA.W #$00C0 ; \
$00:A80F 8D 25 43 STA.W $4325 ; / DMA 2 size = $00C0 bytes
$00:A812 8E 0B 42 STX.W $420B ; Start DMA channel 2
$00:A815 A9 A0 65 LDA.W #$65A0 ; \
$00:A818 8D 16 21 STA.W $2116 ; / VRAM address = $65A0
$00:A81B A9 BB 99 LDA.W #$99BB ; \
$00:A81E 8D 22 43 STA.W $4322 ; / DMA 2 source address = $99BB
$00:A821 A9 C0 00 LDA.W #$00C0 ; \
$00:A824 8D 25 43 STA.W $4325 ; / DMA 2 size = $00C0 bytes
$00:A827 8E 0B 42 STX.W $420B ; Start DMA channel 2
$00:A82A E2 20 SEP #$20 ; A 8-bit
$00:A82C 60 RTS ; Return
$00:A82D A0 0F LDY.B #$0F ; Y = $0F: GFX file number
$00:A82F 22 28 BA 00 JSL.L $BA28 ; Decompress GFX file Y to $7E:AD00, [$00] = pointer ($BA28)
$00:A833 AD 25 14 LDA.W $1425 ; A = [$1425]
$00:A836 C2 30 REP #$30 ; A, X and Y 16-bit
$00:A838 F0 08 BEQ $A842 ; Zero: go to A842
$00:A83A A5 00 LDA $00 ; \
$00:A83C 18 CLC ; |
$00:A83D 69 30 00 ADC.W #$0030 ; } [$00] += $30 (use the alternate set of tiles)
$00:A840 85 00 STA $00 ; /
$00:A842 A2 00 00 LDX.W #$0000 ; X = 0: output offset in the buffer
$00:A845 A0 08 00 LDY.W #$0008 ; Y = 8: rows per plane group
$00:A848 A7 00 LDA [$00] ; A = bitplanes 0 and 1 of one tile row
$00:A84A 9F 7B 97 7F STA.L $7F977B,X ; Store to buffer at $7F:977B+X
$00:A84E E8 INX ; \
$00:A84F E8 INX ; / X += 2
$00:A850 E6 00 INC $00 ; \
$00:A852 E6 00 INC $00 ; / [$00] += 2
$00:A854 88 DEY ; \
$00:A855 D0 F1 BNE $A848 ; / Loop for 8 rows
$00:A857 A0 08 00 LDY.W #$0008 ; Y = 8 rows
$00:A85A A7 00 LDA [$00] ; \
$00:A85C 29 FF 00 AND.W #$00FF ; / A = bitplane 2 byte of one row, plane 3 = 0 (3bpp to 4bpp)
$00:A85F 9F 7B 97 7F STA.L $7F977B,X ; Store to buffer at $7F:977B+X
$00:A863 E8 INX ; \
$00:A864 E8 INX ; / X += 2
$00:A865 E6 00 INC $00 ; [$00]++
$00:A867 88 DEY ; \
$00:A868 D0 F0 BNE $A85A ; / Loop for 8 rows
$00:A86A E0 00 03 CPX.W #$0300 ; \
$00:A86D 90 D6 BCC $A845 ; / Loop until X = $0300 (24 tiles converted)
$00:A86F E2 30 SEP #$30 ; A, X and Y 8-bit
$00:A871 A0 00 LDY.B #$00 ; Y = 0: GFX file number
$00:A873 22 28 BA 00 JSL.L $BA28 ; Decompress GFX file 0 ($BA28)
$00:A877 C2 30 REP #$30 ; A, X and Y 16-bit
$00:A879 A9 F0 B3 LDA.W #$B3F0 ; \
$00:A87C 85 00 STA $00 ; / [$00] = $B3F0
$00:A87E A9 B3 7E LDA.W #$7EB3 ; \
$00:A881 85 01 STA $01 ; / [$01] = $7EB3, so [$00] = $7E:B3F0 (offset $06F0 in the decompressed buffer)
$00:A883 A2 00 00 LDX.W #$0000 ; X = 0: output offset
$00:A886 A0 08 00 LDY.W #$0008 ; Y = 8 rows
$00:A889 A7 00 LDA [$00] ; A = bitplanes 0 and 1 of one tile row
$00:A88B 9D F6 0B STA.W $0BF6,X ; Store to buffer at $0BF6+X
$00:A88E E8 INX ; \
$00:A88F E8 INX ; / X += 2
$00:A890 E6 00 INC $00 ; \
$00:A892 E6 00 INC $00 ; / [$00] += 2
$00:A894 88 DEY ; \
$00:A895 D0 F2 BNE $A889 ; / Loop for 8 rows
$00:A897 A0 08 00 LDY.W #$0008 ; Y = 8 rows
$00:A89A A7 00 LDA [$00] ; \
$00:A89C 29 FF 00 AND.W #$00FF ; / A = bitplane 2 byte of one row, plane 3 = 0
$00:A89F 9D F6 0B STA.W $0BF6,X ; Store to buffer at $0BF6+X
$00:A8A2 E8 INX ; \
$00:A8A3 E8 INX ; / X += 2
$00:A8A4 E6 00 INC $00 ; [$00]++
$00:A8A6 88 DEY ; \
$00:A8A7 D0 F1 BNE $A89A ; / Loop for 8 rows
$00:A8A9 E0 C0 00 CPX.W #$00C0 ; \
$00:A8AC D0 05 BNE $A8B3 ; |
$00:A8AE A9 70 B5 LDA.W #$B570 ; } X = $C0 (halfway): [$00] = $B570, continue from there
$00:A8B1 85 00 STA $00 ; /
$00:A8B3 E0 80 01 CPX.W #$0180 ; \
$00:A8B6 90 CE BCC $A886 ; / Loop until X = $0180 (12 tiles converted)
$00:A8B8 E2 30 SEP #$30 ; A, X and Y 8-bit
$00:A8BA A9 01 LDA.B #$01 ; \
$00:A8BC 8D 3A 14 STA.W $143A ; / [$143A] = 1: Mario Start! graphics wait for DMA
$00:A8BF 8D 35 19 STA.W $1935 ; [$1935] = 1: tiles at $0BF6 wait for DMA to VRAM $64A0/$65A0
$00:A8C2 60 RTS ; Return
;;; $A8C3: Table: sprite GFX file lists (SPRITEGFXLIST) ;;;
;; 4 GFX file numbers per entry, indexed by [$192B] * 4. The first file goes to VRAM $6000, the last to $7800.
$00:A8C3 .db $00,$01,$13,$02,$00,$01,$12,$03 ; Sprite GFX list Forest ($00), Castle ($01) - 4 files each
$00:A8CB .db $00,$01,$13,$05,$00,$01,$13,$04 ; Sprite GFX list Mushroom ($02), Underground ($03) - 4 files each
$00:A8D3 .db $00,$01,$13,$06,$00,$01,$13,$09 ; Sprite GFX list Water ($04), Pokey ($05) - 4 files each
$00:A8DB .db $00,$01,$13,$04,$00,$01,$06,$11 ; Sprite GFX list Underground 2 ($06), Ghost House ($07) - 4 files each
$00:A8E3 .db $00,$01,$13,$20,$00,$01,$13,$0F ; Sprite GFX list Banzai Bill ($08), Yoshi's House ($09) - 4 files each
$00:A8EB .db $00,$01,$13,$23,$00,$01,$0D,$14 ; Sprite GFX list Dino-Rhino ($0A), Switch Palace ($0B) - 4 files each
$00:A8F3 .db $00,$01,$24,$0E,$00,$01,$0A,$22 ; Sprite GFX list Mechakoopa ($0C), Wendy/Lemmy ($0D) - 4 files each
$00:A8FB .db $00,$01,$13,$0E,$00,$01,$13,$14 ; Sprite GFX list Ninji ($0E), Unused ($0F) - 4 files each
$00:A903 .db $00,$00,$00,$08,$10,$0F,$1C,$1D ; Sprite GFX list $10, $11 - 4 files each
$00:A90B .db $00,$01,$24,$22,$00,$01,$25,$22 ; Sprite GFX list $12, $13 - 4 files each
$00:A913 .db $00,$22,$13,$2D,$00,$01,$0F,$22 ; Sprite GFX list $14, $15 - 4 files each
$00:A91B .db $00,$26,$2E,$22,$21,$0B,$25,$0A ; Sprite GFX list $16, $17 - 4 files each
$00:A923 .db $00,$0D,$24,$22,$2C,$30,$2D,$0E ; Sprite GFX list $18, $19 - 4 files each
;;; $A92B: Table: tileset GFX lists, raw GFX upload (OBJECTGFXLIST) ;;;
;; 4 GFX file numbers per tileset, indexed by [$1931] * 4. The first file goes to VRAM $0000, the last to
;; $1800.
;; $00A993: uploads GFX files $28-$2B uncompressed (1024 words each) to VRAM $4000 and file 0 to $6000 via
;; UploadGFXFile.
$00:A92B .db $14,$17,$19,$15,$14,$17,$1B,$18 ; Tileset GFX list Normal 1 ($00), Castle 1 ($01) - 4 files each
$00:A933 .db $14,$17,$1B,$16,$14,$17,$0C,$1A ; Tileset GFX list Rope 1 ($02), Underground 1 ($03) - 4 files each
$00:A93B .db $14,$17,$1B,$08,$14,$17,$0C,$07 ; Tileset GFX list Switch Palace 1 ($04), Ghost House 1 ($05) - 4 files each
$00:A943 .db $14,$17,$0C,$16,$14,$17,$1B,$15 ; Tileset GFX list Rope 2 ($06), Normal 2 ($07) - 4 files each
$00:A94B .db $14,$17,$19,$16,$14,$17,$0D,$1A ; Tileset GFX list Rope 3 ($08), Underground 2 ($09) - 4 files each
$00:A953 .db $14,$17,$1B,$08,$14,$17,$1B,$18 ; Tileset GFX list Switch Palace 2 ($0A), Castle 2 ($0B) - 4 files each
$00:A95B .db $14,$17,$19,$1F,$14,$17,$0D,$07 ; Tileset GFX list Cloud/Forest ($0C), Ghost House 2 ($0D) - 4 files each
$00:A963 .db $14,$17,$19,$1A,$14,$17,$14,$14 ; Tileset GFX list Underground 2 ($0E), $0F - 4 files each
$00:A96B .db $0E,$0F,$17,$17,$1C,$1D,$08,$1E ; Tileset GFX list $10, $11 - 4 files each
$00:A973 .db $1C,$1D,$08,$1E,$1C,$1D,$08,$1E ; Tileset GFX list $12, $13 - 4 files each
$00:A97B .db $1C,$1D,$08,$1E,$1C,$1D,$08,$1E ; Tileset GFX list $14, $15 - 4 files each
$00:A983 .db $1C,$1D,$08,$1E,$1C,$1D,$08,$1E ; Tileset GFX list $16, $17 - 4 files each
$00:A98B .db $14,$17,$19,$2C,$19,$17,$1B,$18 ; Tileset GFX list $18, $19 - 4 files each
$00:A993 9C 16 21 STZ.W $2116 ; \
$00:A996 A9 40 LDA.B #$40 ; } VRAM address = $4000
$00:A998 8D 17 21 STA.W $2117 ; /
$00:A99B A9 03 LDA.B #$03 ; \
$00:A99D 85 0F STA $0F ; / [$0F] = 3: four files
$00:A99F A9 28 LDA.B #$28 ; \
$00:A9A1 85 0E STA $0E ; / [$0E] = $28: first GFX file number
$00:A9A3 A5 0E LDA $0E ; \
$00:A9A5 A8 TAY ; / Y = [$0E]
$00:A9A6 22 28 BA 00 JSL.L $BA28 ; Decompress GFX file Y, [$00] = pointer ($BA28)
$00:A9AA C2 30 REP #$30 ; A, X and Y 16-bit
$00:A9AC A2 FF 03 LDX.W #$03FF ; X = $03FF: 1024 words
$00:A9AF A0 00 00 LDY.W #$0000 ; Y = 0
$00:A9B2 B7 00 LDA [$00],Y ; A = next word of the decompressed data
$00:A9B4 8D 18 21 STA.W $2118 ; Write it straight to VRAM (no 4bpp conversion)
$00:A9B7 C8 INY ; \
$00:A9B8 C8 INY ; / Y += 2
$00:A9B9 CA DEX ; \
$00:A9BA 10 F6 BPL $A9B2 ; / Loop for 1024 words
$00:A9BC E2 30 SEP #$30 ; A, X and Y 8-bit
$00:A9BE E6 0E INC $0E ; Next file number
$00:A9C0 C6 0F DEC $0F ; \
$00:A9C2 10 DF BPL $A9A3 ; / Loop for 4 files ($28-$2B)
$00:A9C4 9C 16 21 STZ.W $2116 ; \
$00:A9C7 A9 60 LDA.B #$60 ; } VRAM address = $6000
$00:A9C9 8D 17 21 STA.W $2117 ; /
$00:A9CC A0 00 LDY.B #$00 ; Y = 0: GFX file 0
$00:A9CE 20 6B AA JSR.W UploadGFXFile ; Convert and upload file 0 (UploadGFXFile)
$00:A9D1 60 RTS ; Return
;;; $A9D2..A9D6: Table: VRAM slot addresses for GFX upload ;;;
;; $A9D2: sprite slots, $A9D6: FG/BG slots. High byte of the VRAM word address, one per slot.
$00:A9D2 .db $78,$70,$68,$60 ; VRAM word address high bytes for sprite GFX slots 0-3 ($78, $70, $68, $60)
$00:A9D6 .db $18,$10,$08,$00 ; VRAM word address high bytes for FG/BG GFX slots 0-3 ($18, $10, $08, $00)
;;; $A9DA: Upload sprite and tileset GFX to VRAM (UploadSpriteGFX) ;;;
;; Loads the 4 sprite GFX files for list [$192B] into VRAM $6000-$7FFF, then the 4 FG/BG files for tileset
;; [$1931] into $0000-$1FFF.
;; [$0101]-[$0104] and [$0105]-[$0108] remember the file in each slot, so a slot whose file is unchanged is
;; not re-uploaded.
;; Parameters: [$192B]: sprite GFX list. [$1931]: tileset.
;; Called by:
;; $00:94D7: Cutscene, ending and game mode code (castle scenes, credits, game over) (CutsceneCastlePal)
;; $00:95E9: Cutscene, ending and game mode code (castle scenes, credits, game over) (CutsceneCastlePal)
;; $00:9658: Cutscene, ending and game mode code (castle scenes, credits, game over) (CutsceneCastlePal)
;; $00:9840: Game mode 11: Mario Start, level music (MarioStartGameMode)
;; $00:A144: Game mode 0C: load overworld (LoadMapGameMode)
;; $00:A5B9: Game mode 12: prepare level (GM04Load)
$00:A9DA A9 80 LDA.B #$80 ; \
$00:A9DC 8D 15 21 STA.W $2115 ; / VMAIN = $80: increment after high-byte writes
$00:A9DF A2 03 LDX.B #$03 ; X = 3
$00:A9E1 AD 2B 19 LDA.W $192B ; A = [$192B] (sprite GFX list index)
$00:A9E4 0A ASL ; \
$00:A9E5 0A ASL ; } Y = [$192B] * 4 (four files per entry)
$00:A9E6 A8 TAY ; /
$00:A9E7 B9 C3 A8 LDA.W SPRITEGFXLIST,Y ; A = SPRITEGFXLIST[Y]
$00:A9EA 95 04 STA $04,X ; [$04+X] = file number (first list entry ends up in [$07])
$00:A9EC C8 INY ; Next list byte
$00:A9ED CA DEX ; X--
$00:A9EE 10 F7 BPL $A9E7 ; Loop for 4 files
$00:A9F0 A9 03 LDA.B #$03 ; \
$00:A9F2 85 0F STA $0F ; / [$0F] = 3: slot counter
;;; $A9F4: Sprite GFX: upload loop over 4 slots (GFXTransferLoop) ;;;
;; Slot 3 down to 0: set the VRAM address from $A9D2 and upload the file unless it is already loaded.
$00:A9F4 A6 0F LDX $0F ; X = [$0F]: slot number
$00:A9F6 9C 16 21 STZ.W $2116 ; VRAM address low = 0
$00:A9F9 BD D2 A9 LDA.W $A9D2,X ; \
$00:A9FC 8D 17 21 STA.W $2117 ; / VRAM address high = $A9D2[X] (slot base $60-$78)
$00:A9FF B4 04 LDY $04,X ; Y = file number for this slot
$00:AA01 BD 01 01 LDA.W $0101,X ; \
$00:AA04 D5 04 CMP $04,X ; } File already in this slot ([$0101+X]): skip the upload
$00:AA06 F0 03 BEQ Don'tUploadSpr ; /
$00:AA08 20 6B AA JSR.W UploadGFXFile ; Convert and upload GFX file Y (UploadGFXFile)
;;; $AA0B: Sprite GFX: next slot (Don'tUploadSpr) ;;;
$00:AA0B C6 0F DEC $0F ; \
$00:AA0D 10 E5 BPL GFXTransferLoop ; / Next slot: [$0F]--
$00:AA0F A2 03 LDX.B #$03 ; X = 3
;;; $AA11: Remember loaded sprite GFX files (UpdtCrrntSpritGFX) ;;;
;; Copies [$04]-[$07] to [$0101]-[$0104].
$00:AA11 B5 04 LDA $04,X ; \
$00:AA13 9D 01 01 STA.W $0101,X ; |
$00:AA16 CA DEX ; } [$0101+X] = [$04+X] (remember which sprite GFX is loaded)
$00:AA17 10 F8 BPL UpdtCrrntSpritGFX ; /
$00:AA19 AD 31 19 LDA.W $1931 ; A = tileset [$1931]
$00:AA1C C9 FE CMP.B #$FE ; \
$00:AA1E B0 3B BCS SetallFGBG80 ; / Tileset >= $FE: go to SetallFGBG80
$00:AA20 A2 03 LDX.B #$03 ; X = 3
$00:AA22 AD 31 19 LDA.W $1931 ; \
$00:AA25 0A ASL ; |
$00:AA26 0A ASL ; } Y = tileset * 4 (four files per entry)
$00:AA27 A8 TAY ; /
;;; $AA28: FG/BG GFX: pick files and upload (PrepLoadFGBG) ;;;
;; Tileset >= $FE goes to SetallFGBG80. Otherwise copies the 4 files of OBJECTGFXLIST for the tileset to
;; [$04]-[$07] and uploads each changed slot.
$00:AA28 B9 2B A9 LDA.W OBJECTGFXLIST,Y ; A = OBJECTGFXLIST[Y]
$00:AA2B 95 04 STA $04,X ; [$04+X] = file number (first list entry ends up in [$07])
$00:AA2D C8 INY ; Next list byte
$00:AA2E CA DEX ; X--
$00:AA2F 10 F7 BPL PrepLoadFGBG ; Loop for 4 files
$00:AA31 A9 03 LDA.B #$03 ; \
$00:AA33 85 0F STA $0F ; / [$0F] = 3: slot counter
$00:AA35 A6 0F LDX $0F ; X = [$0F]: slot number
$00:AA37 9C 16 21 STZ.W $2116 ; VRAM address low = 0
$00:AA3A BD D6 A9 LDA.W $A9D6,X ; \
$00:AA3D 8D 17 21 STA.W $2117 ; / VRAM address high = $A9D6[X] (slot base $00-$18)
$00:AA40 B4 04 LDY $04,X ; Y = file number for this slot
$00:AA42 BD 05 01 LDA.W $0105,X ; \
$00:AA45 D5 04 CMP $04,X ; } File already in this slot ([$0105+X]): skip the upload
$00:AA47 F0 03 BEQ NoUploadFGBG ; /
$00:AA49 20 6B AA JSR.W UploadGFXFile ; Convert and upload GFX file Y (UploadGFXFile)
;;; $AA4C: FG/BG GFX: next slot (NoUploadFGBG) ;;;
$00:AA4C C6 0F DEC $0F ; \
$00:AA4E 10 E5 BPL $AA35 ; / Next slot: [$0F]--; loop for 4 slots
$00:AA50 A2 03 LDX.B #$03 ; X = 3
;;; $AA52: Remember loaded FG/BG GFX files (UpdateCurrentFGBG) ;;;
;; Copies [$04]-[$07] to [$0105]-[$0108].
$00:AA52 B5 04 LDA $04,X ; \
$00:AA54 9D 05 01 STA.W $0105,X ; |
$00:AA57 CA DEX ; } [$0105+X] = [$04+X] (remember which FG/BG GFX is loaded)
$00:AA58 10 F8 BPL UpdateCurrentFGBG ; /
$00:AA5A 60 RTS ; Return
;;; $AA5B: Tileset $FE/$FF: Mode 7 upload, empty slots (SetallFGBG80) ;;;
;; Tileset $FF uploads the Mode 7 tile graphics ($AB42). Both then mark all FG/BG slots as empty ($80).
$00:AA5B F0 03 BEQ NoUpdateVRAM80 ; Tileset = $FE: skip the Mode 7 upload
$00:AA5D 20 42 AB JSR.W $AB42 ; Tileset = $FF: upload the 3-bit packed Mode 7 tiles (file $27)
;;; $AA60: Mark all FG/BG slots empty (NoUpdateVRAM80) ;;;
$00:AA60 A2 03 LDX.B #$03 ; X = 3
$00:AA62 A9 80 LDA.B #$80 ; A = $80: not a real file number, so every FG/BG slot reloads next time
;;; $AA64: Store $80 in FG/BG slot table (Store80) ;;;
$00:AA64 9D 05 01 STA.W $0105,X ; [$0105+X] = $80
$00:AA67 CA DEX ; \
$00:AA68 10 FA BPL Store80 ; / Loop for 4 slots
$00:AA6A 60 RTS ; Return
;;; $AA6B: Decompress GFX file and start upload (UploadGFXFile) ;;;
;; Decompresses file Y into the $7E:AD00 buffer. For file 1, if the Special World is completed ([$1EEB] bit 7)
;; file $31 replaces it.
;; Then picks the 3bpp to 4bpp conversion mode (see below). Parameters: Y = GFX file number; VRAM address
;; already set.
;; Called by:
;; $00:A9CE: Table: tileset GFX lists, raw GFX upload (OBJECTGFXLIST)
;; $00:AA08: Sprite GFX: upload loop over 4 slots (GFXTransferLoop)
;; $00:AA49: FG/BG GFX: pick files and upload (PrepLoadFGBG)
$00:AA6B 22 28 BA 00 JSL.L $BA28 ; Decompress GFX file Y to $7E:AD00, [$00] = pointer ($BA28)
$00:AA6F C0 01 CPY.B #$01 ; \
$00:AA71 D0 0D BNE SkipSpecial ; / File != 1: go to SkipSpecial
$00:AA73 AD EB 1E LDA.W $1EEB ; \
$00:AA76 10 08 BPL SkipSpecial ; / [$1EEB] bit 7 clear (Special World not completed): go to SkipSpecial
$00:AA78 A0 31 LDY.B #$31 ; Y = $31
$00:AA7A 22 28 BA 00 JSL.L $BA28 ; Decompress GFX file $31 instead (post-Special World graphics)
$00:AA7E A0 01 LDY.B #$01 ; Y = 1 again (conversion below treats it as file 1)
;;; $AA80: Choose 3bpp conversion mode (SkipSpecial) ;;;
;; File $1E, or file 8 in tilesets >= $11, goes to the full conversion; every other file continues at $00AA99.
$00:AA80 C2 20 REP #$20 ; A 16-bit
$00:AA82 A9 00 00 LDA.W #$0000 ; A = 0
$00:AA85 AE 31 19 LDX.W $1931 ; X = tileset [$1931]
$00:AA88 E0 11 CPX.B #$11 ; \
$00:AA8A 90 04 BCC $AA90 ; / Tileset < $11: go to AA90
$00:AA8C C0 08 CPY.B #$08 ; \
$00:AA8E F0 06 BEQ JumpTo_____ ; / File 8 (tileset >= $11): go to JumpTo_____
$00:AA90 C0 1E CPY.B #$1E ; \
$00:AA92 F0 02 BEQ JumpTo_____ ; / File $1E: go to JumpTo_____
$00:AA94 D0 03 BNE $AA99 ; Otherwise go to AA99 (always taken)
;;; $AA96: Convert 3bpp GFX to 4bpp, upload to VRAM (JumpTo_____) ;;;
;; Converts 128 tiles of 24 bytes (3bpp) to 4bpp while writing them to VRAM. Plane 3 is the mask [$0A] AND
;; (plane 0 | 1 | 2) of each row.
;; Files other than 1 and $17: plane 3 empty. Files 1 and $17: plane 3 filled only for tiles $6E-$6F and
;; $7E-$7F.
$00:AA96 4C 02 AB JMP.W FilterSomeRAM ; Full conversion: plane 3 = OR of planes 0-2 (FilterSomeRAM)
$00:AA99 85 0A STA $0A ; [$0A] = 0: plane 3 mask empty (plain 3bpp to 4bpp)
$00:AA9B A9 FF FF LDA.W #$FFFF ; A = $FFFF
$00:AA9E C0 01 CPY.B #$01 ; \
$00:AAA0 F0 07 BEQ $AAA9 ; / File 1: keep $FFFF
$00:AAA2 C0 17 CPY.B #$17 ; \
$00:AAA4 F0 03 BEQ $AAA9 ; / File $17: keep $FFFF
$00:AAA6 A9 00 00 LDA.W #$0000 ; Other files: A = 0
$00:AAA9 8D BC 1B STA.W $1BBC ; [$1BBC] = $FFFF for files 1 and $17, else 0
$00:AAAC A0 7F LDY.B #$7F ; Y = $7F: tile counter (128 tiles)
$00:AAAE AD BC 1B LDA.W $1BBC ; \
$00:AAB1 F0 1A BEQ $AACD ; / [$1BBC] = 0: go to AACD (mask stays empty)
$00:AAB3 C0 7E CPY.B #$7E ; \
$00:AAB5 90 07 BCC $AABE ; / Tile < $7E: go to AABE
$00:AAB7 A9 00 FF LDA.W #$FF00 ; \
$00:AABA 85 0A STA $0A ; / [$0A] = $FF00: plane 3 = OR of planes 0-2
$00:AABC D0 0F BNE $AACD ; Go to AACD
$00:AABE C0 6E CPY.B #$6E ; \
$00:AAC0 90 06 BCC $AAC8 ; / Tile < $6E: go to AAC8
$00:AAC2 C0 70 CPY.B #$70 ; \
$00:AAC4 B0 02 BCS $AAC8 ; / Tile >= $70: go to AAC8
$00:AAC6 90 EF BCC $AAB7 ; Tile $6E-$6F: go to AAB7
$00:AAC8 A9 00 00 LDA.W #$0000 ; \
$00:AACB 85 0A STA $0A ; / [$0A] = 0: plane 3 empty
$00:AACD A2 07 LDX.B #$07 ; X = 7: 8 rows
$00:AACF A7 00 LDA [$00] ; A = bitplanes 0 and 1 of this row
$00:AAD1 8D 18 21 STA.W $2118 ; Write them to VRAM
$00:AAD4 EB XBA ; \
$00:AAD5 07 00 ORA [$00] ; } [$1BB2+X] = plane 0 | plane 1 of this row (both bytes)
$00:AAD7 9D B2 1B STA.W $1BB2,X ; /
$00:AADA E6 00 INC $00 ; \
$00:AADC E6 00 INC $00 ; / [$00] += 2
$00:AADE CA DEX ; \
$00:AADF 10 EE BPL $AACF ; / Loop for 8 rows
$00:AAE1 A2 07 LDX.B #$07 ; X = 7: 8 rows
$00:AAE3 A7 00 LDA [$00] ; \
$00:AAE5 29 FF 00 AND.W #$00FF ; } [$0C] = bitplane 2 byte of this row
$00:AAE8 85 0C STA $0C ; /
$00:AAEA A7 00 LDA [$00] ; \
$00:AAEC EB XBA ; |
$00:AAED 1D B2 1B ORA.W $1BB2,X ; |
$00:AAF0 25 0A AND $0A ; |
$00:AAF2 05 0C ORA $0C ; } Write plane 2 (low) and plane 3 = (plane 2 | [$1BB2+X]) & [$0A] (high) to VRAM
$00:AAF4 8D 18 21 STA.W $2118 ; /
$00:AAF7 E6 00 INC $00 ; [$00]++
$00:AAF9 CA DEX ; \
$00:AAFA 10 E7 BPL $AAE3 ; / Loop for 8 rows
$00:AAFC 88 DEY ; \
$00:AAFD 10 AF BPL $AAAE ; / Next tile: loop for 128 tiles
$00:AAFF E2 20 SEP #$20 ; A 8-bit
$00:AB01 60 RTS ; Return
;;; $AB02: Full 3bpp to 4bpp conversion setup (FilterSomeRAM) ;;;
;; Sets mask [$0A] = $FF00 (plane 3 = OR of planes 0-2) for all 128 tiles and falls into the loop.
;; Called by:
;; $00:AA96: Convert 3bpp GFX to 4bpp, upload to VRAM (JumpTo_____)
$00:AB02 A9 00 FF LDA.W #$FF00 ; \
$00:AB05 85 0A STA $0A ; / [$0A] = $FF00: plane 3 = OR of planes 0-2 for every tile
$00:AB07 A0 7F LDY.B #$7F ; Y = $7F: tile counter (128 tiles)
;;; $AB09: 3bpp to 4bpp: tile loop start (Upload????ToVRAM) ;;;
;; Starts with a compare and branch that do nothing.
$00:AB09 C0 08 CPY.B #$08 ; \
$00:AB0B B0 00 BCS $AB0D ; / Useless compare, the branch goes to the next instruction
$00:AB0D A2 07 LDX.B #$07 ; X = 7: 8 rows
;;; $AB0F: 3bpp to 4bpp: planes 0-1 of a tile (AddressWrite1) ;;;
;; Writes 8 rows of plane 0/1 words to VRAM and keeps each row's plane 0 | plane 1 in [$1BB2+X].
$00:AB0F A7 00 LDA [$00] ; A = bitplanes 0 and 1 of this row
$00:AB11 8D 18 21 STA.W $2118 ; Write them to VRAM
$00:AB14 EB XBA ; \
$00:AB15 07 00 ORA [$00] ; } [$1BB2+X] = plane 0 | plane 1 of this row (both bytes)
$00:AB17 9D B2 1B STA.W $1BB2,X ; /
$00:AB1A E6 00 INC $00 ; \
$00:AB1C E6 00 INC $00 ; / [$00] += 2
$00:AB1E CA DEX ; \
$00:AB1F 10 EE BPL AddressWrite1 ; / Loop for 8 rows
$00:AB21 A2 07 LDX.B #$07 ; X = 7: 8 rows
;;; $AB23: 3bpp to 4bpp: planes 2-3; Mode 7 upload (AddressWrite2) ;;;
;; Writes the plane 2/3 words of the tile's 8 rows, then loops to the next tile.
;; $00AB42: uploads GFX file $27 as Mode 7 tile graphics. The file is packed 3 bits per pixel; each pixel is
;; written to the VRAM high byte
;; ($2119, Mode 7 tile data lives there), 8192 pixels, then another $2000 high bytes are cleared. $00ABC4
;; extracts 3 bits into [$04].
$00:AB23 A7 00 LDA [$00] ; \
$00:AB25 29 FF 00 AND.W #$00FF ; } [$0C] = bitplane 2 byte of this row
$00:AB28 85 0C STA $0C ; /
$00:AB2A A7 00 LDA [$00] ; \
$00:AB2C EB XBA ; |
$00:AB2D 1D B2 1B ORA.W $1BB2,X ; |
$00:AB30 25 0A AND $0A ; |
$00:AB32 05 0C ORA $0C ; } Write plane 2 (low) and plane 3 = (plane 2 | [$1BB2+X]) & [$0A] (high) to VRAM
$00:AB34 8D 18 21 STA.W $2118 ; /
$00:AB37 E6 00 INC $00 ; [$00]++
$00:AB39 CA DEX ; \
$00:AB3A 10 E7 BPL AddressWrite2 ; / Loop for 8 rows
$00:AB3C 88 DEY ; \
$00:AB3D 10 CA BPL Upload????ToVRAM ; / Next tile: loop for 128 tiles
$00:AB3F E2 20 SEP #$20 ; A 8-bit
$00:AB41 60 RTS ; Return
$00:AB42 A0 27 LDY.B #$27 ; Y = $27: GFX file number
$00:AB44 22 28 BA 00 JSL.L $BA28 ; Decompress GFX file $27, [$00] = pointer ($BA28)
$00:AB48 C2 10 REP #$10 ; X and Y 16-bit
$00:AB4A A0 00 00 LDY.W #$0000 ; Y = 0: source offset
$00:AB4D A2 FF 03 LDX.W #$03FF ; X = $03FF: 1024 groups of 3 bytes (8 pixels each)
$00:AB50 B7 00 LDA [$00],Y ; \
$00:AB52 85 0F STA $0F ; / [$0F] = next source byte
$00:AB54 20 C4 AB JSR.W $ABC4 ; [$04] = top 3 bits of [$0F] (pixel 0)
$00:AB57 A5 04 LDA $04 ; \
$00:AB59 8D 19 21 STA.W $2119 ; / Write pixel 0 to the VRAM high byte
$00:AB5C 20 C4 AB JSR.W $ABC4 ; Pixel 1: next 3 bits
$00:AB5F A5 04 LDA $04 ; \
$00:AB61 8D 19 21 STA.W $2119 ; / Write pixel 1 to the VRAM high byte
$00:AB64 64 04 STZ $04 ; \
$00:AB66 26 0F ROL $0F ; |
$00:AB68 26 04 ROL $04 ; |
$00:AB6A 26 0F ROL $0F ; } [$04] = last 2 bits of byte 0 (pixel 2 takes 1 more bit from byte 1)
$00:AB6C 26 04 ROL $04 ; /
$00:AB6E C8 INY ; Next source byte
$00:AB6F B7 00 LDA [$00],Y ; \
$00:AB71 85 0F STA $0F ; / [$0F] = byte 1
$00:AB73 26 0F ROL $0F ; \
$00:AB75 26 04 ROL $04 ; / Shift in 1 bit from byte 1: pixel 2 complete
$00:AB77 A5 04 LDA $04 ; \
$00:AB79 8D 19 21 STA.W $2119 ; / Write pixel 2 to the VRAM high byte
$00:AB7C 20 C4 AB JSR.W $ABC4 ; Pixel 3: next 3 bits
$00:AB7F A5 04 LDA $04 ; \
$00:AB81 8D 19 21 STA.W $2119 ; / Write pixel 3 to the VRAM high byte
$00:AB84 20 C4 AB JSR.W $ABC4 ; Pixel 4: next 3 bits
$00:AB87 A5 04 LDA $04 ; \
$00:AB89 8D 19 21 STA.W $2119 ; / Write pixel 4 to the VRAM high byte
$00:AB8C 64 04 STZ $04 ; \
$00:AB8E 26 0F ROL $0F ; } [$04] = last bit of byte 1 (pixel 5 takes 2 more bits from byte 2)
$00:AB90 26 04 ROL $04 ; /
$00:AB92 C8 INY ; Next source byte
$00:AB93 B7 00 LDA [$00],Y ; \
$00:AB95 85 0F STA $0F ; / [$0F] = byte 2
$00:AB97 26 0F ROL $0F ; \
$00:AB99 26 04 ROL $04 ; |
$00:AB9B 26 0F ROL $0F ; } Shift in 2 bits from byte 2: pixel 5 complete
$00:AB9D 26 04 ROL $04 ; /
$00:AB9F A5 04 LDA $04 ; \
$00:ABA1 8D 19 21 STA.W $2119 ; / Write pixel 5 to the VRAM high byte
$00:ABA4 20 C4 AB JSR.W $ABC4 ; Pixel 6: next 3 bits
$00:ABA7 A5 04 LDA $04 ; \
$00:ABA9 8D 19 21 STA.W $2119 ; / Write pixel 6 to the VRAM high byte
$00:ABAC 20 C4 AB JSR.W $ABC4 ; Pixel 7: next 3 bits
$00:ABAF A5 04 LDA $04 ; \
$00:ABB1 8D 19 21 STA.W $2119 ; / Write pixel 7 to the VRAM high byte
$00:ABB4 C8 INY ; Next source byte
$00:ABB5 CA DEX ; \
$00:ABB6 10 98 BPL $AB50 ; / Loop for 1024 groups
$00:ABB8 A2 00 20 LDX.W #$2000 ; X = $2000: bytes to clear
$00:ABBB 9C 19 21 STZ.W $2119 ; Write 0 to the VRAM high byte
$00:ABBE CA DEX ; \
$00:ABBF D0 FA BNE $ABBB ; / Loop $2000 times (clears the next 128 Mode 7 tiles)
$00:ABC1 E2 10 SEP #$10 ; X and Y 8-bit
$00:ABC3 60 RTS ; Return
$00:ABC4 64 04 STZ $04 ; \
$00:ABC6 26 0F ROL $0F ; |
$00:ABC8 26 04 ROL $04 ; |
$00:ABCA 26 0F ROL $0F ; |
$00:ABCC 26 04 ROL $04 ; |
$00:ABCE 26 0F ROL $0F ; } [$04] = top 3 bits of [$0F], shifted out of it
$00:ABD0 26 04 ROL $04 ; /
$00:ABD2 60 RTS ; Return
;;; $ABD3..ABDB: Table: palette set offsets (step $18) ;;;
$00:ABD3 .db $00,$18,$30,$48,$60,$78,$90,$A8 ; Offsets of 12-color palette sets in a table (step $18), used by LoadPalette
$00:ABDB .db $00,$14,$28,$3C ; Offsets with step $14 (not referenced in this bank, purpose unknown)
;;; $ABDF..ABE7: Table: 16-bit offsets (step $38) ;;;
;; Used at $AD44.
$00:ABDF .db $00,$00,$38,$00,$70,$00,$A8,$00 ; 16-bit offsets, step $38 (used at $AD44)
$00:ABE7 .db $E0,$00,$18,$01,$50,$01 ; 16-bit offsets (continued)
;;; $ABED: Load level palettes into buffer (LoadPalette) ;;;
;; Fills the palette buffer at $0703 (backdrop at $0701) for the current level: fixed colors, then the palette
;; sets chosen by [$192D] (FG), [$192E] (sprite),
;; [$1930] (BG) and the backdrop color [$192F]. Uses LoadColors ($00 = source, $04 = buffer offset, $06 =
;; colors-1, $08 = palettes-1).
;; Called by:
;; $00:93D7: Game mode 00: load Nintendo Presents (NintendoTile)
;; $00:94DA: Cutscene, ending and game mode code (castle scenes, credits, game over) (CutsceneCastlePal)
;; $00:95EC: Cutscene, ending and game mode code (castle scenes, credits, game over) (CutsceneCastlePal)
;; $00:965B: Cutscene, ending and game mode code (castle scenes, credits, game over) (CutsceneCastlePal)
;; $00:A5BC: Game mode 12: prepare level (GM04Load)
;; $00:ADD9: Load overworld, title and boss room palettes
;; $00:AE1F: Load overworld, title and boss room palettes
$00:ABED C2 30 REP #$30 ; A, X and Y 16-bit
$00:ABEF A9 DD 7F LDA.W #$7FDD ; \
$00:ABF2 85 04 STA $04 ; |
$00:ABF4 A2 02 00 LDX.W #$0002 ; } Color 1 of every BG palette 0-7 = $7FDD
$00:ABF7 20 ED AC JSR.W LoadCol8Pal ; /
$00:ABFA A9 FF 7F LDA.W #$7FFF ; \
$00:ABFD 85 04 STA $04 ; |
$00:ABFF A2 02 01 LDX.W #$0102 ; } Color 1 of every sprite palette 0-7 = $7FFF
$00:AC02 20 ED AC JSR.W LoadCol8Pal ; /
$00:AC05 A9 70 B1 LDA.W #$B170 ; \
$00:AC08 85 00 STA $00 ; |
$00:AC0A A9 10 00 LDA.W #$0010 ; |
$00:AC0D 85 04 STA $04 ; |
$00:AC0F A9 07 00 LDA.W #$0007 ; |
$00:AC12 85 06 STA $06 ; |
$00:AC14 A9 01 00 LDA.W #$0001 ; |
$00:AC17 85 08 STA $08 ; } Colors 8-15 of BG palettes 0-1 from $00:B170 (layer 3 palettes)
$00:AC19 20 FF AC JSR.W LoadColors ; /
$00:AC1C A9 50 B2 LDA.W #$B250 ; \
$00:AC1F 85 00 STA $00 ; |
$00:AC21 A9 84 00 LDA.W #$0084 ; |
$00:AC24 85 04 STA $04 ; |
$00:AC26 A9 05 00 LDA.W #$0005 ; |
$00:AC29 85 06 STA $06 ; |
$00:AC2B A9 09 00 LDA.W #$0009 ; |
$00:AC2E 85 08 STA $08 ; } Colors 2-7 of palettes 4-D from $00:B250 (shared BG and sprite colors)
$00:AC30 20 FF AC JSR.W LoadColors ; /
$00:AC33 AD 2F 19 LDA.W $192F ; \
$00:AC36 29 0F 00 AND.W #$000F ; |
$00:AC39 0A ASL ; |
$00:AC3A A8 TAY ; |
$00:AC3B B9 A0 B0 LDA.W Palettes?,Y ; } [$0701] = Palettes?[([$192F] & $F) * 2] (backdrop color)
$00:AC3E 8D 01 07 STA.W $0701 ; /
$00:AC41 A9 90 B1 LDA.W #$B190 ; \
$00:AC44 85 00 STA $00 ; / [$00] = $B190: base of the FG palette sets
$00:AC46 AD 2D 19 LDA.W $192D ; \
$00:AC49 29 0F 00 AND.W #$000F ; |
$00:AC4C A8 TAY ; |
$00:AC4D B9 D3 AB LDA.W $ABD3,Y ; |
$00:AC50 29 FF 00 AND.W #$00FF ; |
$00:AC53 18 CLC ; |
$00:AC54 65 00 ADC $00 ; } [$00] += $ABD3[[$192D] & $F] (selected FG palette set)
$00:AC56 85 00 STA $00 ; /
$00:AC58 A9 44 00 LDA.W #$0044 ; \
$00:AC5B 85 04 STA $04 ; |
$00:AC5D A9 05 00 LDA.W #$0005 ; |
$00:AC60 85 06 STA $06 ; |
$00:AC62 A9 01 00 LDA.W #$0001 ; |
$00:AC65 85 08 STA $08 ; } Colors 2-7 of BG palettes 2-3 from [$00]
$00:AC67 20 FF AC JSR.W LoadColors ; /
$00:AC6A A9 18 B3 LDA.W #$B318 ; \
$00:AC6D 85 00 STA $00 ; / [$00] = $B318: base of the sprite palette sets
$00:AC6F AD 2E 19 LDA.W $192E ; \
$00:AC72 29 0F 00 AND.W #$000F ; |
$00:AC75 A8 TAY ; |
$00:AC76 B9 D3 AB LDA.W $ABD3,Y ; |
$00:AC79 29 FF 00 AND.W #$00FF ; |
$00:AC7C 18 CLC ; |
$00:AC7D 65 00 ADC $00 ; } [$00] += $ABD3[[$192E] & $F] (selected sprite palette set)
$00:AC7F 85 00 STA $00 ; /
$00:AC81 A9 C4 01 LDA.W #$01C4 ; \
$00:AC84 85 04 STA $04 ; |
$00:AC86 A9 05 00 LDA.W #$0005 ; |
$00:AC89 85 06 STA $06 ; |
$00:AC8B A9 01 00 LDA.W #$0001 ; |
$00:AC8E 85 08 STA $08 ; } Colors 2-7 of sprite palettes 6-7 (E-F) from [$00]
$00:AC90 20 FF AC JSR.W LoadColors ; /
$00:AC93 A9 B0 B0 LDA.W #$B0B0 ; \
$00:AC96 85 00 STA $00 ; / [$00] = $B0B0: base of the BG palette sets
$00:AC98 AD 30 19 LDA.W $1930 ; \
$00:AC9B 29 0F 00 AND.W #$000F ; |
$00:AC9E A8 TAY ; |
$00:AC9F B9 D3 AB LDA.W $ABD3,Y ; |
$00:ACA2 29 FF 00 AND.W #$00FF ; |
$00:ACA5 18 CLC ; |
$00:ACA6 65 00 ADC $00 ; } [$00] += $ABD3[[$1930] & $F] (selected BG palette set)
$00:ACA8 85 00 STA $00 ; /
$00:ACAA A9 04 00 LDA.W #$0004 ; \
$00:ACAD 85 04 STA $04 ; |
$00:ACAF A9 05 00 LDA.W #$0005 ; |
$00:ACB2 85 06 STA $06 ; |
$00:ACB4 A9 01 00 LDA.W #$0001 ; |
$00:ACB7 85 08 STA $08 ; } Colors 2-7 of BG palettes 0-1 from [$00]
$00:ACB9 20 FF AC JSR.W LoadColors ; /
$00:ACBC A9 74 B6 LDA.W #$B674 ; \
$00:ACBF 85 00 STA $00 ; |
$00:ACC1 A9 52 00 LDA.W #$0052 ; |
$00:ACC4 85 04 STA $04 ; |
$00:ACC6 A9 06 00 LDA.W #$0006 ; |
$00:ACC9 85 06 STA $06 ; |
$00:ACCB A9 02 00 LDA.W #$0002 ; |
$00:ACCE 85 08 STA $08 ; } Colors 9-F of BG palettes 2-4 from $00:B674
$00:ACD0 20 FF AC JSR.W LoadColors ; /
$00:ACD3 A9 74 B6 LDA.W #$B674 ; \
$00:ACD6 85 00 STA $00 ; |
$00:ACD8 A9 32 01 LDA.W #$0132 ; |
$00:ACDB 85 04 STA $04 ; |
$00:ACDD A9 06 00 LDA.W #$0006 ; |
$00:ACE0 85 06 STA $06 ; |
$00:ACE2 A9 02 00 LDA.W #$0002 ; |
$00:ACE5 85 08 STA $08 ; } Colors 9-F of sprite palettes 1-3 from $00:B674
$00:ACE7 20 FF AC JSR.W LoadColors ; /
$00:ACEA E2 30 SEP #$30 ; A, X and Y 8-bit
$00:ACEC 60 RTS ; Return
;;; $ACED: Set one color in 8 palettes (LoadCol8Pal) ;;;
;; Writes [$04] to the buffer at $0703+X, then every $20 bytes. Parameters: X = buffer offset, [$04] = color.
;; Called by:
;; $00:ABF7: Load level palettes into buffer (LoadPalette)
;; $00:AC02: Load level palettes into buffer (LoadPalette)
$00:ACED A0 07 00 LDY.W #$0007 ; Y = 7: 8 palettes
$00:ACF0 A5 04 LDA $04 ; A = color value [$04]
$00:ACF2 9D 03 07 STA.W $0703,X ; Store in the palette buffer at $0703+X
$00:ACF5 8A TXA ; \
$00:ACF6 18 CLC ; |
$00:ACF7 69 20 00 ADC.W #$0020 ; } X += $20 (next palette)
$00:ACFA AA TAX ; /
$00:ACFB 88 DEY ; \
$00:ACFC 10 F2 BPL $ACF0 ; / Loop for 8 palettes
$00:ACFE 60 RTS ; Return
;;; $ACFF: Load rows of colors into palette buffer (LoadColors) ;;;
;; Copies rows of colors from ROM into the palette buffer at $0703 (the CGRAM mirror).
;; Each row is [$06]+1 colors; after every row the buffer offset advances by $20 (the next 16-color palette).
;; Parameters: [$00]: source address (bank $00); [$04]: buffer byte offset (color number * 2); [$06]: colors
;; per row - 1; [$08]: rows - 1.
;; Called with A, X and Y 16-bit. [$00] is left pointing after the last color read.
;; Called by:
;; $00:AC19: Load level palettes into buffer (LoadPalette)
;; $00:AC30: Load level palettes into buffer (LoadPalette)
;; $00:AC67: Load level palettes into buffer (LoadPalette)
;; $00:AC90: Load level palettes into buffer (LoadPalette)
;; $00:ACB9: Load level palettes into buffer (LoadPalette)
;; $00:ACD0: Load level palettes into buffer (LoadPalette)
;; $00:ACE7: Load level palettes into buffer (LoadPalette)
;; $00:AD5B: Load overworld, title and boss room palettes
;; $00:AD72: Load overworld, title and boss room palettes
;; $00:AD89: Load overworld, title and boss room palettes
;; $00:ADA0: Load overworld, title and boss room palettes
;; $00:ADBC: Load overworld, title and boss room palettes
;; ... and 4 more
$00:ACFF A6 04 LDX $04 ; X = [$04]: byte offset into the palette buffer $0703 (color number * 2)
$00:AD01 A4 06 LDY $06 ; Y = [$06]: colors per row - 1
$00:AD03 B2 00 LDA ($00) ; A = next color (BGR555) from the source at [$00]
$00:AD05 9D 03 07 STA.W $0703,X ; Store it in the palette buffer
$00:AD08 E6 00 INC $00 ; \
$00:AD0A E6 00 INC $00 ; / [$00] += 2: next source color
$00:AD0C E8 INX ; \
$00:AD0D E8 INX ; / X += 2: next buffer slot
$00:AD0E 88 DEY ; \
$00:AD0F 10 F2 BPL $AD03 ; / Y--, repeat until Y < 0 (one row of colors)
$00:AD11 A5 04 LDA $04 ; \
$00:AD13 18 CLC ; |
$00:AD14 69 20 00 ADC.W #$0020 ; } A = [$04] + $20: start of the next palette row (16 colors on)
$00:AD17 85 04 STA $04 ; /
$00:AD19 C6 08 DEC $08 ; \
$00:AD1B 10 E2 BPL LoadColors ; / [$08]--, repeat for the next row while [$08] >= 0
$00:AD1D 60 RTS ; Return
;;; $AD1E..AD1E: Table: overworld palette set by map ;;;
;; Indexed by ([$1931] & $0F) - 1; gives the overworld palette set number (0-5) used by $AD25.
$00:AD1E .db $01,$00,$03,$04,$03,$05,$02 ; Palette set number by map: index = ([$1931] & $0F) - 1
;;; $AD25: Load overworld, title and boss room palettes ;;;
;; $00AD25: overworld palettes. Picks a layer palette set from [$1931] (base $B3D8, or $B732 if bit 7 of
;; [$1EEB] is set) and loads it,
;; then loads the shared overworld colors from $B528, $B57C and $B5EC.
;; $00ADA6: title screen palettes (colors 8-F of palettes 0 and 1).
;; $00ADD9: palettes for the Mode 7 boss rooms with [$0D9B] bit 6 clear (Iggy/Larry). $00AE15: same for the
;; other Mode 7 boss rooms.
;; All four routines return in 8-bit mode.
;; Called by:
;; $00:A14D: Game mode 0C: load overworld (LoadMapGameMode)
;; $00:A597: Long wrapper for CODE_00AD25
$00:AD25 C2 30 REP #$30 ; A, X and Y 16-bit
$00:AD27 A0 D8 B3 LDY.W #$B3D8 ; Y = $B3D8: normal overworld palette sets
$00:AD2A AD EA 1E LDA.W $1EEA ; A = [$1EEA] (16-bit load, so N = bit 7 of [$1EEB])
$00:AD2D 10 03 BPL $AD32 ; Bit clear: keep the normal sets
$00:AD2F A0 32 B7 LDY.W #$B732 ; Bit set: alternate sets at $B732 (probably post-game colors)
$00:AD32 84 00 STY $00 ; [$00] = base address of the palette sets
$00:AD34 AD 31 19 LDA.W $1931 ; A = [$1931]
$00:AD37 29 0F 00 AND.W #$000F ; Low nibble
$00:AD3A 3A DEC A ; Minus 1
$00:AD3B A8 TAY ; Y = index into $AD1E
$00:AD3C B9 1E AD LDA.W $AD1E,Y ; A = palette set number for this map
$00:AD3F 29 FF 00 AND.W #$00FF ; Keep the low byte
$00:AD42 0A ASL ; \
$00:AD43 A8 TAY ; / Y = set number * 2
$00:AD44 B9 DF AB LDA.W $ABDF,Y ; A = set number * $38 (size of one set: 4 palettes x 7 colors)
$00:AD47 18 CLC ; \
$00:AD48 65 00 ADC $00 ; |
$00:AD4A 85 00 STA $00 ; / [$00] += A: source = start of the chosen set
$00:AD4C A9 82 00 LDA.W #$0082 ; \
$00:AD4F 85 04 STA $04 ; |
$00:AD51 A9 06 00 LDA.W #$0006 ; |
$00:AD54 85 06 STA $06 ; |
$00:AD56 A9 03 00 LDA.W #$0003 ; } [$04] = $82, [$06] = 6, [$08] = 3: palettes 4-7, colors 1-7
$00:AD59 85 08 STA $08 ; /
$00:AD5B 20 FF AC JSR.W LoadColors ; Load the colors (LoadColors)
$00:AD5E A9 28 B5 LDA.W #$B528 ; \
$00:AD61 85 00 STA $00 ; |
$00:AD63 A9 52 00 LDA.W #$0052 ; |
$00:AD66 85 04 STA $04 ; |
$00:AD68 A9 06 00 LDA.W #$0006 ; |
$00:AD6B 85 06 STA $06 ; |
$00:AD6D A9 05 00 LDA.W #$0005 ; } Source $B528, [$04] = $52, [$06] = 6, [$08] = 5: palettes 2-7, colors 9-F
$00:AD70 85 08 STA $08 ; /
$00:AD72 20 FF AC JSR.W LoadColors ; Load the colors (LoadColors)
$00:AD75 A9 7C B5 LDA.W #$B57C ; \
$00:AD78 85 00 STA $00 ; |
$00:AD7A A9 02 01 LDA.W #$0102 ; |
$00:AD7D 85 04 STA $04 ; |
$00:AD7F A9 06 00 LDA.W #$0006 ; |
$00:AD82 85 06 STA $06 ; |
$00:AD84 A9 07 00 LDA.W #$0007 ; } Source $B57C, [$04] = $102, [$06] = 6, [$08] = 7: palettes 8-F, colors 1-7
$00:AD87 85 08 STA $08 ; /
$00:AD89 20 FF AC JSR.W LoadColors ; Load the colors (LoadColors)
$00:AD8C A9 EC B5 LDA.W #$B5EC ; \
$00:AD8F 85 00 STA $00 ; |
$00:AD91 A9 10 00 LDA.W #$0010 ; |
$00:AD94 85 04 STA $04 ; |
$00:AD96 A9 07 00 LDA.W #$0007 ; |
$00:AD99 85 06 STA $06 ; |
$00:AD9B A9 01 00 LDA.W #$0001 ; } Source $B5EC, [$04] = $10, [$06] = 7, [$08] = 1: palettes 0-1, colors 8-F
$00:AD9E 85 08 STA $08 ; /
$00:ADA0 20 FF AC JSR.W LoadColors ; Load the colors (LoadColors)
$00:ADA3 E2 30 SEP #$30 ; A, X and Y 8-bit
$00:ADA5 60 RTS ; Return
$00:ADA6 C2 30 REP #$30 ; A, X and Y 16-bit
$00:ADA8 A9 3C B6 LDA.W #$B63C ; \
$00:ADAB 85 00 STA $00 ; |
$00:ADAD A9 10 00 LDA.W #$0010 ; |
$00:ADB0 85 04 STA $04 ; |
$00:ADB2 A9 07 00 LDA.W #$0007 ; |
$00:ADB5 85 06 STA $06 ; |
$00:ADB7 A9 00 00 LDA.W #$0000 ; } Source $B63C, [$04] = $10, [$06] = 7, [$08] = 0: palette 0, colors 8-F
$00:ADBA 85 08 STA $08 ; /
$00:ADBC 20 FF AC JSR.W LoadColors ; Load the colors (LoadColors)
$00:ADBF A9 2C B6 LDA.W #$B62C ; \
$00:ADC2 85 00 STA $00 ; |
$00:ADC4 A9 30 00 LDA.W #$0030 ; |
$00:ADC7 85 04 STA $04 ; |
$00:ADC9 A9 07 00 LDA.W #$0007 ; |
$00:ADCC 85 06 STA $06 ; |
$00:ADCE A9 00 00 LDA.W #$0000 ; } Source $B62C, [$04] = $30, [$06] = 7, [$08] = 0: palette 1, colors 8-F
$00:ADD1 85 08 STA $08 ; /
$00:ADD3 20 FF AC JSR.W LoadColors ; Load the colors (LoadColors)
$00:ADD6 E2 30 SEP #$30 ; A, X and Y 8-bit
$00:ADD8 60 RTS ; Return
$00:ADD9 20 ED AB JSR.W LoadPalette ; Load the standard palettes (LoadPalette)
$00:ADDC C2 30 REP #$30 ; A, X and Y 16-bit
$00:ADDE A9 17 00 LDA.W #$0017 ; \
$00:ADE1 8D 01 07 STA.W $0701 ; / Backdrop color [$0701] = $0017 (very dark red)
$00:ADE4 A9 70 B1 LDA.W #$B170 ; \
$00:ADE7 85 00 STA $00 ; |
$00:ADE9 A9 10 00 LDA.W #$0010 ; |
$00:ADEC 85 04 STA $04 ; |
$00:ADEE A9 07 00 LDA.W #$0007 ; |
$00:ADF1 85 06 STA $06 ; |
$00:ADF3 A9 01 00 LDA.W #$0001 ; } Source $B170, [$04] = $10, [$06] = 7, [$08] = 1: palettes 0-1, colors 8-F
$00:ADF6 85 08 STA $08 ; /
$00:ADF8 20 FF AC JSR.W LoadColors ; Load the colors (LoadColors)
$00:ADFB A9 5C B6 LDA.W #$B65C ; \
$00:ADFE 85 00 STA $00 ; |
$00:AE00 A9 00 00 LDA.W #$0000 ; |
$00:AE03 85 04 STA $04 ; |
$00:AE05 A9 07 00 LDA.W #$0007 ; |
$00:AE08 85 06 STA $06 ; |
$00:AE0A A9 00 00 LDA.W #$0000 ; } Source $B65C, [$04] = 0, [$06] = 7, [$08] = 0: palette 0, colors 0-7
$00:AE0D 85 08 STA $08 ; /
$00:AE0F 20 FF AC JSR.W LoadColors ; Load the colors (LoadColors)
$00:AE12 E2 30 SEP #$30 ; A, X and Y 8-bit
$00:AE14 60 RTS ; Return
; |
; V Init palette for special levels?
$00:AE15 A9 02 LDA.B #$02 ; \
$00:AE17 8D 2E 19 STA.W $192E ; / Sprite palette set [$192E] = 2
$00:AE1A A9 07 LDA.B #$07 ; \
$00:AE1C 8D 2D 19 STA.W $192D ; / Foreground palette set [$192D] = 7
$00:AE1F 20 ED AB JSR.W LoadPalette ; Load the standard palettes (LoadPalette)
$00:AE22 C2 30 REP #$30 ; A, X and Y 16-bit
$00:AE24 A9 17 00 LDA.W #$0017 ; \
$00:AE27 8D 01 07 STA.W $0701 ; / Backdrop color [$0701] = $0017 (very dark red)
$00:AE2A A9 F4 B5 LDA.W #$B5F4 ; \
$00:AE2D 85 00 STA $00 ; |
$00:AE2F A9 18 00 LDA.W #$0018 ; |
$00:AE32 85 04 STA $04 ; |
$00:AE34 A9 03 00 LDA.W #$0003 ; |
$00:AE37 85 06 STA $06 ; |
$00:AE39 64 08 STZ $08 ; / Source $B5F4, [$04] = $18, [$06] = 3, [$08] = 0: palette 0, colors C-F
$00:AE3B 20 FF AC JSR.W LoadColors ; Load the colors (LoadColors)
$00:AE3E E2 30 SEP #$30 ; A, X and Y 8-bit
$00:AE40 60 RTS ; Return
;;; $AE41..AE44: Tables: color channel shifts and COLDATA bits ;;;
;; $AE41: shift counts 0, 5, 10. $AE44: COLDATA plane bits $20, $40, $80. Used by $AE47.
$00:AE41 .db $00,$05,$0A ; Shift counts: red 0, green 5, blue 10
$00:AE44 .db $20,$40,$80 ; COLDATA channel select bits: $20 red, $40 green, $80 blue
;;; $AE47: Set fixed color from backdrop color ;;;
;; Writes the backdrop color [$0701] to the PPU fixed color (COLDATA $2132), one channel at a time (blue,
;; green, red).
;; Called at the end of MoreDMA so that color math against the fixed color matches the backdrop.
;; Called by:
;; $00:A4D1: Upload queued palette records to CGRAM (MoreDMA)
$00:AE47 A2 02 LDX.B #$02 ; X = 2: blue first, then green, then red
$00:AE49 C2 20 REP #$20 ; A 16-bit
$00:AE4B AD 01 07 LDA.W $0701 ; A = backdrop color [$0701] (BGR555)
$00:AE4E BC 41 AE LDY.W $AE41,X ; Y = bit shift of this channel (0, 5 or 10)
$00:AE51 88 DEY ; \
$00:AE52 30 03 BMI $AE57 ; |
$00:AE54 4A LSR ; |
$00:AE55 80 FA BRA $AE51 ; / A >>= Y: move the channel down to bits 0-4
$00:AE57 E2 20 SEP #$20 ; A 8-bit
$00:AE59 29 1F AND.B #$1F ; Keep the 5-bit channel value
$00:AE5B 1D 44 AE ORA.W $AE44,X ; Add the channel select bit
$00:AE5E 8D 32 21 STA.W $2132 ; COLDATA: set that channel of the fixed color
$00:AE61 CA DEX ; \
$00:AE62 10 E5 BPL $AE49 ; / Next channel, X = 2..0
$00:AE64 60 RTS ; Return
;;; $AE65..AEEF: Tables: color masks, fade steps and dither masks ;;;
;; Used by the level end palette fade ($AFC0). Masks and -1/+1 steps are per color channel (red, green,
;; blue).
;; $AE77: for each 5-bit channel value, two 16-bit masks whose set bits total the value: the channel
;; loses 1 on each step
;; whose bit is set, so a channel of value v reaches 0 after the 32 steps.
$00:AE65 .db $1F,$00,$E0,$03,$00,$7C ; Channel field masks: $001F red, $03E0 green, $7C00 blue
$00:AE6B .db $FF,$FF,$E0,$FF,$00,$FC ; Step -1 in each channel field: $FFFF, $FFE0, $FC00
$00:AE71 .db $01,$00,$20,$00,$00,$04 ; Step +1 in each channel field: $0001, $0020, $0400
$00:AE77 .db $00,$00,$00,$00,$01,$00,$00,$00 ; Dither masks, channel values 0 and 1 (2 words each, value bits set in total)
$00:AE7F .db $00,$80,$00,$80,$20,$80,$00,$04 ; Dither masks, channel values 2 and 3 (2 words each, value bits set in total)
$00:AE87 .db $80,$80,$80,$80,$08,$82,$40,$10 ; Dither masks, channel values 4 and 5 (2 words each, value bits set in total)
$00:AE8F .db $20,$84,$20,$84,$44,$88,$10,$22 ; Dither masks, channel values 6 and 7 (2 words each, value bits set in total)
$00:AE97 .db $88,$88,$88,$88,$22,$91,$88,$44 ; Dither masks, channel values 8 and 9 (2 words each, value bits set in total)
$00:AE9F .db $48,$92,$48,$92,$92,$A4,$24,$49 ; Dither masks, channel values 10 and 11 (2 words each, value bits set in total)
$00:AEA7 .db $A4,$A4,$A4,$A4,$49,$A9,$94,$52 ; Dither masks, channel values 12 and 13 (2 words each, value bits set in total)
$00:AEAF .db $AA,$AA,$94,$52,$AA,$AA,$54,$55 ; Dither masks, channel values 14 and 15 (2 words each, value bits set in total)
$00:AEB7 .db $AA,$AA,$AA,$AA,$AA,$D5,$AA,$AA ; Dither masks, channel values 16 and 17 (2 words each, value bits set in total)
$00:AEBF .db $AA,$D5,$AA,$D5,$B5,$D6,$6A,$AD ; Dither masks, channel values 18 and 19 (2 words each, value bits set in total)
$00:AEC7 .db $DA,$DA,$DA,$DA,$6D,$DB,$DA,$B6 ; Dither masks, channel values 20 and 21 (2 words each, value bits set in total)
$00:AECF .db $B6,$ED,$B6,$ED,$DD,$EE,$76,$BB ; Dither masks, channel values 22 and 23 (2 words each, value bits set in total)
$00:AED7 .db $EE,$EE,$EE,$EE,$BB,$F7,$EE,$DD ; Dither masks, channel values 24 and 25 (2 words each, value bits set in total)
$00:AEDF .db $DE,$FB,$DE,$FB,$F7,$FD,$BE,$EF ; Dither masks, channel values 26 and 27 (2 words each, value bits set in total)
$00:AEE7 .db $FE,$FE,$FE,$FE,$DF,$FF,$FE,$FB ; Dither masks, channel values 28 and 29 (2 words each, value bits set in total)
$00:AEEF .db $FE,$FF,$FE,$FF,$FF,$FF,$FE,$FF ; Dither masks, channel values 30 and 31 (2 words each, value bits set in total)
;;; $AEF7..AF0F: Table: dither step bit masks ;;;
;; 16 one-hot words ($8000 down to $0001) selecting which bit of the dither masks applies on each fade step.
$00:AEF7 .db $00,$80,$00,$40,$00,$20,$00,$10 ; One-hot masks for step index 0-3: bits 15 down to 12
$00:AEFF .db $00,$08,$00,$04,$00,$02,$00,$01 ; One-hot masks for step index 4-7: bits 11 down to 8
$00:AF07 .db $80,$00,$40,$00,$20,$00,$10,$00 ; One-hot masks for step index 8-11: bits 7 down to 4
$00:AF0F .db $08,$00,$04,$00,$02,$00,$01,$00 ; One-hot masks for step index 12-15: bits 3 down to 0
;;; $AF17: Level end dithered palette fade ;;;
;; $00AF17: per-frame level end handler. Counts [$1493] down every other frame (stops at 1). Below $A0 it also
;; forces Mode 1 with BG3 out of color math
;; and runs the level end sequence ($CBFF). $00AF35: every 4th frame, while [$1495] < $40, fades
;; palettes 0-7 (colors 1-7), palette 0 colors D-F
;; and the backdrop by one dithered step. Results go into the CGRAM DMA list at $0905 and [$0680] = 3 queues
;; the upload.
;; $00AFA3: advances [$1495] by 2 and builds the dither masks [$0C]/[$0E] from the old value.
;; $00AFC0: one dither step. Parameters: A: original color; [$02]: working color; [$0C], [$0E]: masks.
;; Returns: [$04]: new color.
;; If [$1493] bit 7 is set each step is +1 instead of -1 (purpose unclear).
;; Called by:
;; $00:C96B: Mario animation A: scripted walk, level end (EnterCastleAni)
$00:AF17 AC 93 14 LDY.W $1493 ; Y = [$1493] (level end timer)
$00:AF1A A5 13 LDA RAM_FrameCounter ; \
$00:AF1C 4A LSR ; |
$00:AF1D 90 06 BCC $AF25 ; / Skip the decrement on even frames
$00:AF1F 88 DEY ; \
$00:AF20 F0 03 BEQ $AF25 ; |
$00:AF22 8C 93 14 STY.W $1493 ; / Y--, stored back unless it would hit 0 (timer stops at 1)
$00:AF25 C0 A0 CPY.B #$A0 ; \
$00:AF27 B0 0C BCS $AF35 ; / Timer >= $A0: skip the screen mode change
$00:AF29 A9 04 LDA.B #$04 ; \
$00:AF2B 14 40 TRB $40 ; / Clear bit 2 of [$40] (CGADSUB mirror): BG3 out of color math
$00:AF2D A9 09 LDA.B #$09 ; \
$00:AF2F 85 3E STA $3E ; / [$3E] = $09 (BGMODE mirror): Mode 1, BG3 on top
$00:AF31 22 FF CB 05 JSL.L $CBFF ; Run the level end sequence code ($CBFF, probably the Course Clear screen)
$00:AF35 A5 13 LDA RAM_FrameCounter ; \
$00:AF37 29 03 AND.B #$03 ; |
$00:AF39 D0 67 BNE $AFA2 ; / Only continue every 4th frame
$00:AF3B AD 95 14 LDA.W $1495 ; \
$00:AF3E C9 40 CMP.B #$40 ; |
$00:AF40 B0 60 BCS $AFA2 ; / Return once the fade step [$1495] has reached $40
$00:AF42 20 A3 AF JSR.W $AFA3 ; Advance [$1495] by 2 and build the dither masks [$0C], [$0E]
$00:AF45 A9 FE 01 LDA.W #$01FE ; \
$00:AF48 8D 05 09 STA.W $0905 ; / DMA list header at $0905: $FE bytes of colors starting at color 1
$00:AF4B A2 EE 00 LDX.W #$00EE ; X = $EE: offset of palette 7 color 7
$00:AF4E A9 07 00 LDA.W #$0007 ; \
$00:AF51 85 00 STA $00 ; / [$00] = 7 colors per palette (colors 7 down to 1)
$00:AF53 BD 05 09 LDA.W $0905,X ; \
$00:AF56 85 02 STA $02 ; / [$02] = working color from the DMA list
$00:AF58 BD 03 07 LDA.W $0703,X ; A = original color from the palette buffer (picks the dither pattern)
$00:AF5B 20 C0 AF JSR.W $AFC0 ; Dither one step; new color in [$04] ($AFC0)
$00:AF5E A5 04 LDA $04 ; \
$00:AF60 9D 05 09 STA.W $0905,X ; / Store the new color in the DMA list
$00:AF63 CA DEX ; \
$00:AF64 CA DEX ; / X -= 2: previous color
$00:AF65 C6 00 DEC $00 ; \
$00:AF67 D0 EA BNE $AF53 ; / Repeat for 7 colors
$00:AF69 8A TXA ; \
$00:AF6A 38 SEC ; |
$00:AF6B E9 12 00 SBC.W #$0012 ; } X -= $12: skip color 0 and go to the previous palette
$00:AF6E AA TAX ; |
$00:AF6F 10 DD BPL $AF4E ; / Repeat for palettes 7 down to 0
$00:AF71 A2 04 00 LDX.W #$0004 ; X = 4: three colors (palette 0 colors F, E, D)
$00:AF74 BD 1F 09 LDA.W $091F,X ; \
$00:AF77 85 02 STA $02 ; / [$02] = working color
$00:AF79 BD 1D 07 LDA.W $071D,X ; A = original color
$00:AF7C 20 C0 AF JSR.W $AFC0 ; Dither one step ($AFC0)
$00:AF7F A5 04 LDA $04 ; \
$00:AF81 9D 1F 09 STA.W $091F,X ; / Store the new color in the DMA list
$00:AF84 CA DEX ; \
$00:AF85 CA DEX ; |
$00:AF86 10 EC BPL $AF74 ; / Next color, X = 4, 2, 0
$00:AF88 AD 01 07 LDA.W $0701 ; \
$00:AF8B 85 02 STA $02 ; / [$02] = working backdrop color [$0701]
$00:AF8D AD 03 09 LDA.W $0903 ; A = original backdrop color (copy at [$0903])
$00:AF90 20 C0 AF JSR.W $AFC0 ; Dither one step ($AFC0)
$00:AF93 A5 04 LDA $04 ; \
$00:AF95 8D 01 07 STA.W $0701 ; / [$0701] = new backdrop color
$00:AF98 E2 30 SEP #$30 ; A, X and Y 8-bit
$00:AF9A 9C 05 0A STZ.W $0A05 ; End of the DMA list: [$0A05] = 0
$00:AF9D A9 03 LDA.B #$03 ; \
$00:AF9F 8D 80 06 STA.W $0680 ; / [$0680] = 3: upload the list at $0905 to CGRAM in NMI (MoreDMA)
$00:AFA2 60 RTS ; Return
$00:AFA3 A8 TAY ; Y = A = current step [$1495]
$00:AFA4 1A INC A ; \
$00:AFA5 1A INC A ; |
$00:AFA6 8D 95 14 STA.W $1495 ; / [$1495] = step + 2
$00:AFA9 98 TYA ; A = step
$00:AFAA 4A LSR ; \
$00:AFAB 4A LSR ; |
$00:AFAC 4A LSR ; |
$00:AFAD 4A LSR ; / A = step >> 4
$00:AFAE C2 30 REP #$30 ; A, X and Y 16-bit
$00:AFB0 29 02 00 AND.W #$0002 ; \
$00:AFB3 85 0C STA $0C ; / [$0C] = 2 if step bit 5 is set (second word of each dither entry), else 0
$00:AFB5 98 TYA ; \
$00:AFB6 29 1E 00 AND.W #$001E ; |
$00:AFB9 A8 TAY ; / Y = step & $1E: word index
$00:AFBA B9 F7 AE LDA.W $AEF7,Y ; \
$00:AFBD 85 0E STA $0E ; / [$0E] = one-hot mask: the dither bit that applies this step
$00:AFBF 60 RTS ; Return
$00:AFC0 85 0A STA $0A ; [$0A] = original color
$00:AFC2 29 1F 00 AND.W #$001F ; \
$00:AFC5 0A ASL ; |
$00:AFC6 0A ASL ; |
$00:AFC7 85 06 STA $06 ; / [$06] = red * 4
$00:AFC9 A5 0A LDA $0A ; \
$00:AFCB 29 E0 03 AND.W #$03E0 ; |
$00:AFCE 4A LSR ; |
$00:AFCF 4A LSR ; |
$00:AFD0 4A LSR ; |
$00:AFD1 85 08 STA $08 ; / [$08] = green * 4
$00:AFD3 A5 0B LDA $0B ; \
$00:AFD5 29 7C 00 AND.W #$007C ; |
$00:AFD8 85 0A STA $0A ; / [$0A] = blue * 4 (bits 10-14 of the color)
$00:AFDA 64 04 STZ $04 ; [$04] = 0: result color
$00:AFDC A0 04 00 LDY.W #$0004 ; Y = 4: channel index (blue, then green, then red)
$00:AFDF 5A PHY ; Save the channel index
$00:AFE0 B9 06 00 LDA.W $0006,Y ; \
$00:AFE3 05 0C ORA $0C ; |
$00:AFE5 A8 TAY ; / Y = channel value * 4 | [$0C]: offset into the dither table
$00:AFE6 B9 77 AE LDA.W $AE77,Y ; A = dither mask word for this channel value
$00:AFE9 7A PLY ; Y = channel index again
$00:AFEA 25 0E AND $0E ; Test this step's bit
$00:AFEC F0 0B BEQ $AFF9 ; Bit clear: this channel keeps its working value
$00:AFEE B9 6B AE LDA.W $AE6B,Y ; A = -1 in this channel's field
$00:AFF1 2C 93 14 BIT.W $1493 ; \
$00:AFF4 10 03 BPL $AFF9 ; / [$1493] bit 7 clear: keep the -1 step
$00:AFF6 B9 71 AE LDA.W $AE71,Y ; [$1493] bit 7 set: A = +1 in this channel's field (brightens, purpose unclear)
$00:AFF9 18 CLC ; Clear carry
$00:AFFA 65 02 ADC $02 ; A = working color + step (A = 0 if no step)
$00:AFFC 39 65 AE AND.W $AE65,Y ; Keep only this channel's field
$00:AFFF 04 04 TSB $04 ; Merge it into the result [$04]
;;; $B001: Finish pose: add offsets, store frame (Remember) ;;;
;; Parameters: A = walk frame, X = |X speed|.
;; Stores the walk frame in [$13DB], adds the pose offset [$13DE] (+7 carrying an item, +4 when fast), then
;; handles the 45 degree
;; slope poses. Entries at $D01A (A = final pose) and $D003 are jumped to from the code above.
; You can get somewhere quick by pressing ctrl+f and typing in the address.
$00:B001 88 DEY ; \
$00:B002 88 DEY ; |
$00:B003 10 DA BPL $AFDF ; / Next channel, Y = 4, 2, 0
$00:B005 60 RTS ; Return
$00:B006 8B PHB ; \
$00:B007 4B PHK ; |
$00:B008 AB PLB ; / Data bank = $00
$00:B009 20 A3 AF JSR.W $AFA3 ; Advance [$1495] and build the dither masks (A = old step)
$00:B00C A2 6E 00 LDX.W #$006E ; X = $6E
$00:B00F A0 08 00 LDY.W #$0008 ; Y = 8 colors per group
$00:B012 BD 07 09 LDA.W $0907,X ; \
$00:B015 85 02 STA $02 ; / [$02] = working color [$0907+X]
$00:B017 BD 83 07 LDA.W $0783,X ; A = source color [$0783+X] (picks the dither pattern)
$00:B01A 5A PHY ; Save the counter
$00:B01B 20 C0 AF JSR.W $AFC0 ; Dither one step ($AFC0)
$00:B01E 7A PLY ; Restore the counter
$00:B01F A5 04 LDA $04 ; \
$00:B021 9D 07 09 STA.W $0907,X ; / Store the new color at [$0907+X]
$00:B024 BD 83 07 LDA.W $0783,X ; \
$00:B027 38 SEC ; |
$00:B028 E5 04 SBC $04 ; |
$00:B02A 9D 79 09 STA.W $0979,X ; / [$0979+X] = source color - new color
$00:B02D CA DEX ; \
$00:B02E CA DEX ; / X -= 2
$00:B02F 88 DEY ; \
$00:B030 D0 E0 BNE $B012 ; / Repeat for 8 colors
$00:B032 8A TXA ; \
$00:B033 38 SEC ; |
$00:B034 E9 10 00 SBC.W #$0010 ; } X -= $10: skip the next 8 colors
$00:B037 AA TAX ; |
$00:B038 10 D5 BPL $B00F ; / Repeat while X >= 0 (4 groups)
$00:B03A E2 30 SEP #$30 ; A, X and Y 8-bit
$00:B03C AB PLB ; Restore the data bank
$00:B03D 6B RTL ; Return long
$00:B03E 20 35 AF JSR.W $AF35 ; Fade one step: background palettes ($AF35)
$00:B041 AD 80 06 LDA.W $0680 ; \
$00:B044 C9 03 CMP.B #$03 ; |
$00:B046 D0 48 BNE $B090 ; / Only if a step was just done ([$0680] = 3)
$00:B048 A9 00 LDA.B #$00 ; \
$00:B04A 85 02 STA $02 ; / [$02] = 0: bank of the pointer in [$00]
$00:B04C C2 30 REP #$30 ; A, X and Y 16-bit
$00:B04E AD 82 0D LDA.W $0D82 ; \
$00:B051 85 00 STA $00 ; / [$00] = [$0D82]: pointer to the player's palette
$00:B053 A0 14 00 LDY.W #$0014 ; Y = $14: copy 11 words
$00:B056 B7 00 LDA [$00],Y ; \
$00:B058 99 11 0A STA.W $0A11,Y ; / Copy a word of the player's palette into the second DMA list
$00:B05B 88 DEY ; \
$00:B05C 88 DEY ; |
$00:B05D 10 F7 BPL $B056 ; / Next word, Y = $14..0
$00:B05F A9 EE 81 LDA.W #$81EE ; \
$00:B062 8D 05 0A STA.W $0A05 ; / Second list header at $0A05: $EE bytes of colors from color $81
$00:B065 A2 CE 00 LDX.W #$00CE ; X = $CE: offset of palette F color 7
$00:B068 A9 07 00 LDA.W #$0007 ; \
$00:B06B 85 00 STA $00 ; / [$00] = 7 colors per palette
$00:B06D BD 25 0A LDA.W $0A25,X ; \
$00:B070 85 02 STA $02 ; / [$02] = working color from the second list
$00:B072 BD 23 08 LDA.W $0823,X ; A = original color from the palette buffer
$00:B075 20 C0 AF JSR.W $AFC0 ; Dither one step ($AFC0)
$00:B078 A5 04 LDA $04 ; \
$00:B07A 9D 25 0A STA.W $0A25,X ; / Store the new color in the second list
$00:B07D CA DEX ; \
$00:B07E CA DEX ; / X -= 2
$00:B07F C6 00 DEC $00 ; \
$00:B081 D0 EA BNE $B06D ; / Repeat for 7 colors
$00:B083 8A TXA ; \
$00:B084 38 SEC ; |
$00:B085 E9 12 00 SBC.W #$0012 ; } X -= $12: skip color 0 and go to the previous palette
$00:B088 AA TAX ; |
$00:B089 10 DD BPL $B068 ; / Repeat for palettes F down to 9
$00:B08B E2 30 SEP #$30 ; A, X and Y 8-bit
$00:B08D 9C F5 0A STZ.W $0AF5 ; End of the second list: [$0AF5] = 0
$00:B090 60 RTS ; Return
;;; $B091..B099: Padding ($FF) ;;;
$00:B091 .db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
$00:B099 .db $FF,$FF,$FF,$FF,$FF,$FF,$FF
;;; $B0A0: Palette data: backdrop, BG, FG and sprite sets (Palettes?) ;;;
;; $B0A0: backdrop colors ([$192F]). $B0B0: 8 background palette sets of 24 bytes ([$1930]), colors 2-7 of
;; palettes 0-1.
;; $B170: layer 3 colors 8-F of palettes 0-1. $B190: 8 foreground palette sets ([$192D]), colors 2-7 of
;; palettes 2-3.
;; $B250: colors 2-7 of palettes 4-D. $B2C8: unclear. $B318: 8 sprite palette sets ([$192E]), colors 2-7 of
;; sprite palettes 6-7.
;; All loaded by LoadPalette ($00ABED); offsets come from $ABD3 (set * $18). Colors are BGR555.
$00:B0A0 .db $9F,$5B,$FB,$6F,$80,$5D,$00,$00 ; Backdrop colors 0-3: indexed by [$192F] (word), later entries overlap the next table
$00:B0A8 .db $22,$1D,$C3,$24,$93,$73,$FF,$7F ; Backdrop colors 4-7
$00:B0B0 .db $49,$3A,$8B,$42,$CD,$4A,$0F,$53 ; BG set 0 P0 c2-5
$00:B0B8 .db $51,$5B,$93,$63,$FF,$7F,$00,$00 ; BG set 0 P0 c6-7; BG set 0 P1 c2-3
$00:B0C0 .db $20,$7F,$80,$7F,$E0,$7F,$E0,$7F ; BG set 0 P1 c4-7
$00:B0C8 .db $42,$39,$08,$52,$CE,$6A,$12,$63 ; BG set 1 P0 c2-5
$00:B0D0 .db $55,$6B,$98,$73,$42,$39,$08,$52 ; BG set 1 P0 c6-7; BG set 1 P1 c2-3
$00:B0D8 .db $CE,$6A,$42,$39,$08,$52,$CE,$6A ; BG set 1 P1 c4-7
$00:B0E0 .db $D6,$4E,$18,$57,$5A,$5F,$9C,$67 ; BG set 2 P0 c2-5
$00:B0E8 .db $DE,$6F,$FF,$77,$FF,$7F,$00,$00 ; BG set 2 P0 c6-7; BG set 2 P1 c2-3
$00:B0F0 .db $20,$7F,$80,$7F,$E0,$7F,$E0,$7F ; BG set 2 P1 c4-7
$00:B0F8 .db $A3,$20,$48,$31,$AC,$3D,$CE,$39 ; BG set 3 P0 c2-5
$00:B100 .db $32,$3E,$B6,$4A,$A2,$20,$25,$2D ; BG set 3 P0 c6-7; BG set 3 P1 c2-3
$00:B108 .db $68,$35,$8A,$35,$E4,$24,$52,$4A ; BG set 3 P1 c4-7
$00:B110 .db $C8,$50,$CC,$59,$6D,$52,$EB,$58 ; BG set 4 P0 c2-5
$00:B118 .db $4C,$65,$D0,$5A,$80,$5D,$39,$7F ; BG set 4 P0 c6-7; BG set 4 P1 c2-3
$00:B120 .db $93,$7E,$A8,$65,$48,$56,$28,$57 ; BG set 4 P1 c4-7
$00:B128 .db $62,$14,$46,$35,$A9,$45,$0D,$52 ; BG set 5 P0 c2-5
$00:B130 .db $B1,$62,$77,$7B,$00,$00,$1E,$7B ; BG set 5 P0 c6-7; BG set 5 P1 c2-3
$00:B138 .db $9F,$7B,$99,$7F,$F6,$7F,$FC,$7F ; BG set 5 P1 c4-7
$00:B140 .db $00,$00,$C5,$24,$49,$2D,$AD,$2D ; BG set 6 P0 c2-5
$00:B148 .db $53,$22,$18,$3F,$60,$10,$81,$18 ; BG set 6 P0 c6-7; BG set 6 P1 c2-3
$00:B150 .db $A3,$1C,$E4,$1C,$09,$29,$4B,$25 ; BG set 6 P1 c4-7
$00:B158 .db $60,$09,$A4,$01,$E8,$01,$2C,$02 ; BG set 7 P0 c2-5
$00:B160 .db $91,$02,$F5,$02,$FF,$7F,$00,$00 ; BG set 7 P0 c6-7; BG set 7 P1 c2-3
$00:B168 .db $E0,$7E,$20,$7F,$80,$7F,$E0,$7F ; BG set 7 P1 c4-7
$00:B170 .db $93,$73,$00,$00,$FB,$0C,$EB,$2F ; Layer 3 P0 c8-cB (palettes 0-1, colors 8-F)
$00:B178 .db $93,$73,$00,$00,$DD,$7F,$7F,$2D ; Layer 3 P0 cC-F
$00:B180 .db $93,$73,$00,$00,$AB,$7A,$FF,$7F ; Layer 3 P1 c8-B
$00:B188 .db $93,$73,$00,$00,$9B,$1E,$7F,$3B ; Layer 3 P1 cC-F
$00:B190 .db $00,$00,$AF,$0D,$79,$2E,$E0,$25 ; FG set 0 P2 c2-5
$00:B198 .db $1C,$2B,$20,$03,$00,$00,$6B,$2D ; FG set 0 P2 c6-7; FG set 0 P3 c2-3
$00:B1A0 .db $EF,$3D,$73,$4E,$18,$63,$9C,$73 ; FG set 0 P3 c4-7
$00:B1A8 .db $00,$00,$E9,$00,$0D,$22,$8E,$05 ; FG set 1 P2 c2-5
$00:B1B0 .db $33,$1A,$B7,$32,$00,$00,$E0,$2D ; FG set 1 P2 c6-7; FG set 1 P3 c2-3
$00:B1B8 .db $E0,$52,$7F,$15,$5F,$32,$3F,$4B ; FG set 1 P3 c4-7
$00:B1C0 .db $00,$00,$C8,$59,$CE,$72,$CB,$39 ; FG set 2 P2 c2-5
$00:B1C8 .db $30,$3E,$B3,$4A,$00,$00,$16,$00 ; FG set 2 P2 c6-7; FG set 2 P3 c2-3
$00:B1D0 .db $1B,$00,$5F,$01,$1F,$02,$1F,$03 ; FG set 2 P3 c4-7
$00:B1D8 .db $00,$00,$EC,$49,$4F,$52,$B2,$5A ; FG set 3 P2 c2-5
$00:B1E0 .db $15,$67,$DB,$7F,$00,$00,$16,$00 ; FG set 3 P2 c6-7; FG set 3 P3 c2-3
$00:B1E8 .db $1B,$00,$5F,$01,$1F,$02,$1F,$03 ; FG set 3 P3 c4-7
$00:B1F0 .db $00,$00,$C9,$08,$4E,$19,$D3,$29 ; FG set 4 P2 c2-5
$00:B1F8 .db $78,$3E,$1D,$53,$00,$00,$C8,$14 ; FG set 4 P2 c6-7; FG set 4 P3 c2-3
$00:B200 .db $09,$1D,$6C,$29,$CF,$35,$32,$42 ; FG set 4 P3 c4-7
$00:B208 .db $EF,$55,$B5,$6E,$F7,$76,$39,$7F ; FG set 5 P2 c2-5
$00:B210 .db $7B,$7F,$BD,$7F,$00,$00,$C9,$2C ; FG set 5 P2 c6-7; FG set 5 P3 c2-3
$00:B218 .db $4E,$41,$D3,$55,$78,$6E,$1D,$7F ; FG set 5 P3 c4-7
$00:B220 .db $00,$00,$E9,$01,$AC,$02,$2F,$03 ; FG set 6 P2 c2-5
$00:B228 .db $99,$03,$FE,$53,$00,$00,$00,$00 ; FG set 6 P2 c6-7; FG set 6 P3 c2-3
$00:B230 .db $00,$00,$8F,$3C,$D8,$61,$7F,$7E ; FG set 6 P3 c4-7
$00:B238 .db $00,$00,$C5,$24,$49,$2D,$AD,$2D ; FG set 7 P2 c2-5
$00:B240 .db $53,$22,$18,$3F,$00,$00,$16,$00 ; FG set 7 P2 c6-7; FG set 7 P3 c2-3
$00:B248 .db $1B,$00,$5F,$01,$1F,$02,$1F,$03 ; FG set 7 P3 c4-7
$00:B250 .db $CE,$39,$00,$00,$18,$63,$34,$7F ; P4 c2-5
$00:B258 .db $95,$7F,$F8,$7F,$00,$00,$B7,$32 ; P4 c6-7; P5 c2-3
$00:B260 .db $FB,$67,$00,$02,$20,$03,$E0,$03 ; P5 c4-7
$00:B268 .db $00,$00,$71,$0D,$3F,$7C,$9B,$1E ; P6 c2-5
$00:B270 .db $7F,$13,$FF,$03,$00,$00,$17,$28 ; P6 c6-7; P7 c2-3
$00:B278 .db $1F,$40,$29,$45,$AD,$59,$10,$66 ; P7 c4-7
$00:B280 .db $00,$00,$71,$0D,$9B,$1E,$7F,$3B ; P8 c2-5
$00:B288 .db $FF,$7F,$FF,$7F,$00,$00,$CE,$39 ; P8 c6-7; P9 c2-3
$00:B290 .db $94,$52,$18,$63,$9C,$73,$5F,$2C ; P9 c4-7
$00:B298 .db $00,$00,$FF,$01,$1F,$03,$FF,$03 ; P10 c2-5
$00:B2A0 .db $B7,$00,$3F,$02,$00,$00,$08,$6D ; P10 c6-7; P11 c2-3
$00:B2A8 .db $AD,$6D,$31,$7E,$B7,$00,$3F,$02 ; P11 c4-7
$00:B2B0 .db $00,$00,$11,$00,$17,$00,$1F,$00 ; P12 c2-5
$00:B2B8 .db $B7,$00,$3F,$02,$00,$00,$E0,$01 ; P12 c6-7; P13 c2-3
$00:B2C0 .db $E0,$02,$E0,$03,$B7,$00,$3F,$02 ; P13 c4-7
$00:B2C8 .db $5F,$63,$1D,$58,$0A,$00,$1F,$39 ; Purpose unclear: 80 bytes, maybe 4 sets of 10 colors
$00:B2D0 .db $C4,$44,$08,$4E,$70,$67,$B6,$30
$00:B2D8 .db $DF,$35,$FF,$03,$3F,$4F,$1D,$58
$00:B2E0 .db $40,$11,$E0,$3F,$07,$3C,$AE,$7C
$00:B2E8 .db $B3,$7D,$00,$2F,$5F,$16,$FF,$03
$00:B2F0 .db $5F,$63,$1D,$58,$29,$25,$FF,$7F
$00:B2F8 .db $08,$00,$17,$00,$1F,$00,$7B,$57
$00:B300 .db $DF,$0D,$FF,$03,$1F,$3B,$1D,$58
$00:B308 .db $29,$25,$FF,$7F,$40,$11,$E0,$01
$00:B310 .db $E0,$02,$7B,$57,$DF,$0D,$FF,$03
$00:B318 .db $00,$00,$C5,$24,$49,$2D,$AD,$2D ; Sprite set 0 sprite P6 c2-5
$00:B320 .db $53,$22,$18,$3F,$23,$25,$C4,$35 ; Sprite set 0 sprite P6 c6-7; Sprite set 0 sprite P7 c2-3
$00:B328 .db $25,$3E,$86,$46,$E7,$4E,$1F,$40 ; Sprite set 0 sprite P7 c4-7
$00:B330 .db $00,$00,$C6,$41,$54,$73,$FA,$7F ; Sprite set 1 sprite P6 c2-5
$00:B338 .db $FD,$7F,$08,$6D,$00,$00,$34,$34 ; Sprite set 1 sprite P6 c6-7; Sprite set 1 sprite P7 c2-3
$00:B340 .db $3A,$44,$9F,$65,$16,$01,$7F,$02 ; Sprite set 1 sprite P7 c4-7
$00:B348 .db $00,$00,$C5,$24,$49,$2D,$AD,$2D ; Sprite set 2 sprite P6 c2-5
$00:B350 .db $53,$22,$18,$3F,$00,$00,$AE,$2D ; Sprite set 2 sprite P6 c6-7; Sprite set 2 sprite P7 c2-3
$00:B358 .db $32,$3E,$B6,$4A,$F9,$52,$F3,$2C ; Sprite set 2 sprite P7 c4-7
$00:B360 .db $00,$00,$6B,$51,$6D,$4E,$B3,$4F ; Sprite set 3 sprite P6 c2-5
$00:B368 .db $BF,$30,$1D,$37,$32,$2E,$0D,$4A ; Sprite set 3 sprite P6 c6-7; Sprite set 3 sprite P7 c2-3
$00:B370 .db $88,$10,$4A,$21,$6D,$29,$CF,$3D ; Sprite set 3 sprite P7 c4-7
$00:B378 .db $00,$00,$40,$29,$E0,$3D,$80,$52 ; Sprite set 4 sprite P6 c2-5
$00:B380 .db $B7,$00,$3F,$02,$00,$00,$CE,$39 ; Sprite set 4 sprite P6 c6-7; Sprite set 4 sprite P7 c2-3
$00:B388 .db $94,$52,$18,$63,$B7,$00,$3F,$02 ; Sprite set 4 sprite P7 c4-7
$00:B390 .db $00,$00,$70,$7E,$D3,$7E,$36,$7F ; Sprite set 5 sprite P6 c2-5
$00:B398 .db $99,$7F,$1F,$40,$00,$00,$CE,$39 ; Sprite set 5 sprite P6 c6-7; Sprite set 5 sprite P7 c2-3
$00:B3A0 .db $94,$52,$18,$63,$9C,$73,$5F,$2C ; Sprite set 5 sprite P7 c4-7
$00:B3A8 .db $00,$00,$DF,$4E,$DE,$5A,$BD,$66 ; Sprite set 6 sprite P6 c2-5
$00:B3B0 .db $7C,$72,$1F,$40,$00,$00,$F5,$7F ; Sprite set 6 sprite P6 c6-7; Sprite set 6 sprite P7 c2-3
$00:B3B8 .db $F7,$7F,$F9,$7F,$FC,$7F,$FF,$7F ; Sprite set 6 sprite P7 c4-7
;;; $B3C0: Palette data: Bowser ending, overworld, shared (BowserEndPalette) ;;;
;; $B3C0: last sprite palette set, also copied to palettes 5 and 6 for the Bowser ending. $B3D8: 6 overworld
;; sets of 56 bytes (palettes 4-7, colors 1-7).
;; $B528: overworld colors 9-F of palettes 2-7. $B57C: overworld colors 1-7 of palettes 8-F. $B5EC: colors 8-F
;; of palettes 0-1.
;; $B5DE: also a table of words read by bank 03 (ending).
$00:B3C0 .db $00,$00,$FB,$63,$0C,$03,$0B,$02 ; Sprite set 7 sprite P6 c2-c5; this and $B3CC are also the Bowser ending palettes 5 and 6
$00:B3C8 .db $35,$15,$5F,$1A ; Sprite set 7 sprite P6 c6-c7
$00:B3CC .db $00,$00,$34,$34,$3A,$44,$9F,$65 ; Sprite set 7 sprite P7 c2-c5
$00:B3D4 .db $16,$01,$7F,$02,$00,$00,$28,$12 ; Sprite set 7 sprite P7 c6-c7; Overworld set 0 P4 c1-c2 start at $B3D8
$00:B3DC .db $A8,$12,$48,$13,$7B,$32,$BF,$5B ; Overworld set 0 P4 c3-6
$00:B3E4 .db $60,$7D,$00,$00,$DE,$7B,$48,$13 ; Overworld set 0 P4 c7; Overworld set 0 P5 c1-3
$00:B3EC .db $60,$7D,$7B,$32,$BF,$37,$7F,$2D ; Overworld set 0 P5 c4-7
$00:B3F4 .db $00,$00,$68,$32,$E8,$32,$48,$13 ; Overworld set 0 P6 c1-4
$00:B3FC .db $FF,$5E,$7F,$6F,$60,$7D,$00,$00 ; Overworld set 0 P6 c5-7; Overworld set 0 P7 c1
$00:B404 .db $DE,$7B,$3B,$57,$A0,$7E,$F6,$01 ; Overworld set 0 P7 c2-5
$00:B40C .db $A8,$12,$48,$13,$00,$00,$28,$12 ; Overworld set 0 P7 c6-7; Overworld set 1 P4 c1-2
$00:B414 .db $A8,$12,$48,$13,$7B,$32,$BF,$5B ; Overworld set 1 P4 c3-6
$00:B41C .db $28,$7E,$00,$00,$DE,$7B,$48,$13 ; Overworld set 1 P4 c7; Overworld set 1 P5 c1-3
$00:B424 .db $28,$7E,$7B,$32,$BF,$37,$FF,$03 ; Overworld set 1 P5 c4-7
$00:B42C .db $00,$00,$12,$32,$75,$3E,$3B,$57 ; Overworld set 1 P6 c1-4
$00:B434 .db $7B,$32,$BF,$5B,$28,$7E,$00,$00 ; Overworld set 1 P6 c5-7; Overworld set 1 P7 c1
$00:B43C .db $DE,$7B,$3B,$57,$28,$7E,$7B,$32 ; Overworld set 1 P7 c2-5
$00:B444 .db $C4,$38,$48,$13,$C7,$2C,$F0,$69 ; Overworld set 1 P7 c6-7; Overworld set 2 P4 c1-2
$00:B44C .db $B2,$66,$D5,$67,$34,$66,$DE,$53 ; Overworld set 2 P4 c3-6
$00:B454 .db $FF,$7F,$C7,$2C,$60,$45,$80,$66 ; Overworld set 2 P4 c7; Overworld set 2 P5 c1-3
$00:B45C .db $F7,$7F,$1F,$03,$7F,$03,$FF,$47 ; Overworld set 2 P5 c4-7
$00:B464 .db $2C,$41,$F0,$69,$B2,$66,$D5,$67 ; Overworld set 2 P6 c1-4
$00:B46C .db $1F,$00,$FF,$7F,$C7,$2C,$C7,$2C ; Overworld set 2 P6 c5-7; Overworld set 2 P7 c1
$00:B474 .db $F0,$69,$B2,$66,$D5,$67,$2C,$41 ; Overworld set 2 P7 c2-5
$00:B47C .db $D5,$3A,$9C,$5B,$00,$00,$EC,$49 ; Overworld set 2 P7 c6-7; Overworld set 3 P4 c1-2
$00:B484 .db $2E,$56,$F1,$62,$26,$31,$BF,$5B ; Overworld set 3 P4 c3-6
$00:B48C .db $00,$00,$00,$00,$DE,$7B,$95,$57 ; Overworld set 3 P4 c7; Overworld set 3 P5 c1-3
$00:B494 .db $28,$7E,$26,$31,$BF,$37,$7F,$2D ; Overworld set 3 P5 c4-7
$00:B49C .db $00,$00,$26,$31,$89,$3D,$EC,$49 ; Overworld set 3 P6 c1-4
$00:B4A4 .db $26,$31,$BF,$5B,$28,$7E,$00,$00 ; Overworld set 3 P6 c5-7; Overworld set 3 P7 c1
$00:B4AC .db $DE,$7B,$3B,$57,$C6,$32,$26,$31 ; Overworld set 3 P7 c2-5
$00:B4B4 .db $7F,$03,$7F,$03,$00,$00,$05,$1A ; Overworld set 3 P7 c6-7; Overworld set 4 P4 c1-2
$00:B4BC .db $C5,$0A,$EF,$22,$75,$1A,$59,$43 ; Overworld set 4 P4 c3-6
$00:B4C4 .db $60,$7D,$00,$00,$39,$77,$EF,$22 ; Overworld set 4 P4 c7; Overworld set 4 P5 c1-3
$00:B4CC .db $60,$7D,$18,$1E,$5C,$37,$09,$7E ; Overworld set 4 P5 c4-7
$00:B4D4 .db $00,$00,$60,$36,$20,$4B,$EF,$22 ; Overworld set 4 P6 c1-4
$00:B4DC .db $5A,$4E,$3A,$53,$60,$7D,$00,$00 ; Overworld set 4 P6 c5-7; Overworld set 4 P7 c1
$00:B4E4 .db $7B,$32,$EF,$22,$19,$21,$F6,$01 ; Overworld set 4 P7 c2-5
$00:B4EC .db $E6,$2D,$A8,$36,$C7,$2C,$F0,$69 ; Overworld set 4 P7 c6-7; Overworld set 5 P4 c1-2
$00:B4F4 .db $00,$00,$00,$00,$34,$66,$F9,$7F ; Overworld set 5 P4 c3-6
$00:B4FC .db $FF,$7F,$00,$00,$60,$45,$80,$66 ; Overworld set 5 P4 c7; Overworld set 5 P5 c1-3
$00:B504 .db $F7,$7F,$1F,$03,$7F,$03,$FF,$47 ; Overworld set 5 P5 c4-7
$00:B50C .db $2C,$41,$F0,$69,$B2,$66,$D5,$67 ; Overworld set 5 P6 c1-4
$00:B514 .db $1F,$00,$FF,$7F,$C7,$2C,$C7,$2C ; Overworld set 5 P6 c5-7; Overworld set 5 P7 c1
$00:B51C .db $F0,$69,$B2,$66,$D5,$67,$2C,$41 ; Overworld set 5 P7 c2-5
$00:B524 .db $D5,$3A,$9C,$5B,$00,$00,$E7,$2C ; Overworld set 5 P7 c6-7; Overworld P2 c9-A
$00:B52C .db $6B,$3D,$EF,$4D,$73,$5E,$F7,$6E ; Overworld P2 cB-E
$00:B534 .db $FF,$7F,$F1,$7F,$BF,$01,$00,$7E ; Overworld P2 cF; Overworld P3 c9-B
$00:B53C .db $BF,$03,$E0,$03,$FC,$7F,$FF,$7F ; Overworld P3 cC-F
$00:B544 .db $00,$00,$4F,$19,$78,$3E,$3E,$57 ; Overworld P4 c9-C
$00:B54C .db $20,$7E,$E0,$7E,$E0,$7F,$00,$00 ; Overworld P4 cD-F; Overworld P5 c9
$00:B554 .db $31,$52,$F6,$66,$9C,$7B,$85,$16 ; Overworld P5 cA-D
$00:B55C .db $4B,$2F,$F1,$47,$00,$00,$4F,$19 ; Overworld P5 cE-F; Overworld P6 c9-A
$00:B564 .db $78,$3E,$3E,$57,$FF,$03,$DE,$7B ; Overworld P6 cB-E
$00:B56C .db $1F,$7C,$00,$00,$4F,$19,$78,$3E ; Overworld P6 cF; Overworld P7 c9-B
$00:B574 .db $3E,$57,$7F,$2D,$4B,$2F,$F1,$47 ; Overworld P7 cC-F
$00:B57C .db $FF,$7F,$00,$00,$71,$0D,$7F,$03 ; Overworld sprite P8 c1-4
$00:B584 .db $FF,$4F,$3F,$4F,$E0,$7F,$FF,$7F ; Overworld sprite P8 c5-7; Overworld sprite P9 c1
$00:B58C .db $00,$00,$E0,$01,$AD,$7D,$80,$03 ; Overworld sprite P9 c2-5
$00:B594 .db $B7,$00,$3F,$02,$FF,$7F,$00,$00 ; Overworld sprite P9 c6-7; Overworld sprite PA c1-2
$00:B59C .db $16,$00,$1F,$00,$08,$6D,$DD,$2D ; Overworld sprite PA c3-6
$00:B5A4 .db $5F,$63,$FF,$7F,$00,$00,$80,$02 ; Overworld sprite PA c7; Overworld sprite PB c1-3
$00:B5AC .db $E0,$03,$08,$6D,$1A,$26,$3B,$57 ; Overworld sprite PB c4-7
$00:B5B4 .db $FF,$7F,$00,$00,$E0,$7E,$20,$7F ; Overworld sprite PC c1-4
$00:B5BC .db $80,$7F,$E0,$7F,$E0,$7F,$FF,$7F ; Overworld sprite PC c5-7; Overworld sprite PD c1
$00:B5C4 .db $00,$00,$E0,$7E,$20,$7F,$80,$7F ; Overworld sprite PD c2-5
$00:B5CC .db $E0,$7F,$E0,$7F,$00,$00,$1B,$00 ; Overworld sprite PD c6-7; Overworld sprite PE c1-2
$00:B5D4 .db $2D,$46,$F3,$5E,$85,$16,$4B,$2F ; Overworld sprite PE c3-6
$00:B5DC .db $F1,$47 ; Overworld sprite PE c7
$00:B5DE .db $00,$00,$E7,$2C,$6B,$3D,$EF,$4D ; Overworld sprite PF c1-c4, grayscale; also read as words by bank 03 at $03:E02D
$00:B5E6 .db $73,$5E,$F7,$6E,$FF,$7F,$93,$73 ; Overworld sprite PF c5-7; Overworld P0 c8
$00:B5EE .db $00,$00,$FF,$03,$3B,$57,$93,$73 ; Overworld P0 c9-C
$00:B5F6 .db $75,$3E,$12,$32,$AF,$25,$93,$73 ; Overworld P0 cD-F; Overworld P1 c8
$00:B5FE .db $3B,$57,$FF,$7F,$00,$00,$93,$73 ; Overworld P1 c9-C
$00:B606 .db $00,$00,$3B,$57,$6C,$7E ; Overworld P1 cD-F
;;; $B60C: Palette data: animated color, title, ending (MorePalettes) ;;;
;; $B60C: 8-color cycle written to CGRAM color $64 every frame ($A41C), indexed by [$14] & $1C.
;; $B62C-$B65B: title screen and boss room colors.
;; $B66C/$B674: small shared palettes. $B69E: 8 entries of 7 colors used by bank 03 (ending) via $DFC4.
$00:B60C .db $DF ; $B60C: Block shine animation: 8 colors for CGRAM color $64, one per 4 frames
$00:B60D .db $02,$5F,$03,$FF,$27,$FF,$5F,$FF ; (continued) Block shine animation: 8 colors for CGRAM color $64, one per 4 frames
$00:B615 .db $73,$FF,$5F,$FF,$27,$5F,$03,$BF ; $B61C: Second 8-color cycle (no reference found)
$00:B61D .db $01,$1F,$00,$1B,$00,$18,$00,$18 ; (continued) Second 8-color cycle (no reference found)
$00:B625 .db $00,$1B,$00,$1F,$00,$BF,$01,$7F ; $B62C: Title screen: palette 1 colors 8-F
$00:B62D .db $43,$00,$00,$60,$7F,$3F,$17,$7F ; (continued) Title screen: palette 1 colors 8-F
$00:B635 .db $43,$00,$00,$FF,$1C,$20,$03,$7F ; $B63C: Title screen: palette 0 colors 8-F
$00:B63D .db $43,$00,$00,$20,$03,$60,$7F,$7F ; (continued) Title screen: palette 0 colors 8-F
$00:B645 .db $43,$BF,$5B,$7B,$32,$E7,$08,$00 ; $B64C: Blue-green gradient, 8 colors (no direct reference found)
$00:B64D .db $7E,$20,$7E,$A0,$7E,$E0,$7E,$20 ; (continued) Blue-green gradient, 8 colors (no direct reference found)
$00:B655 .db $7F,$80,$7F,$E0,$7F,$E0,$7F,$00 ; $B65C: Iggy/Larry room: palette 0 colors 0-7
$00:B65D .db $00,$E0,$1C,$E8,$3D,$F0,$5E,$F8 ; (continued) Iggy/Larry room: palette 0 colors 0-7
$00:B665 .db $7F,$FF,$7F,$85,$16,$4B,$2F ; (continued) Iggy/Larry room: palette 0 colors 0-7
$00:B66C .db $93,$73,$00,$00,$71,$0D,$9B,$1E ; $B66C: 4 colors copied to palette 0 colors C-F by $A007
$00:B674 .db $FF,$7F,$00,$00,$20,$03,$16,$00 ; $B674: Colors 9-F of 3 palettes (palettes 2-4 and sprite palettes 1-3)
$00:B67C .db $1F,$00,$7F,$01,$9F,$02,$FF,$7F ; (continued) Colors 9-F of 3 palettes (palettes 2-4 and sprite palettes 1-3)
$00:B684 .db $00,$00,$20,$03,$7D,$34,$1E,$55 ; (continued) Colors 9-F of 3 palettes (palettes 2-4 and sprite palettes 1-3)
$00:B68C .db $FF,$65,$1F,$7B,$FF,$7F,$00,$00 ; (continued) Colors 9-F of 3 palettes (palettes 2-4 and sprite palettes 1-3)
$00:B694 .db $20,$03,$80,$03,$F1,$1F,$F9,$03 ; (continued) Colors 9-F of 3 palettes (palettes 2-4 and sprite palettes 1-3)
$00:B69C .db $FF,$4F ; (continued) Colors 9-F of 3 palettes (palettes 2-4 and sprite palettes 1-3)
$00:B69E .db $FF,$7F,$C0,$18,$FB,$63,$0C,$03 ; $B69E: Ending palette entry 0: 7 colors
$00:B6A6 .db $0B,$02,$35,$15,$5F,$1A,$9B,$77 ; $B6AC: Ending palette entry 1: 7 colors
$00:B6AE .db $60,$18,$97,$5B,$A8,$02,$A7,$01 ; (continued) Ending palette entry 1: 7 colors
$00:B6B6 .db $D1,$0C,$FB,$11,$37,$6F,$00,$18 ; $B6BA: Ending palette entry 2: 7 colors
$00:B6BE .db $33,$53,$45,$02,$43,$01,$6E,$04 ; (continued) Ending palette entry 2: 7 colors
$00:B6C6 .db $97,$09,$D3,$66,$00,$10,$CF,$4A ; $B6C8: Ending palette entry 3: 7 colors
$00:B6CE .db $E1,$01,$E0,$00,$0A,$00,$33,$01 ; (continued) Ending palette entry 3: 7 colors
$00:B6D6 .db $6F,$5E,$00,$00,$6B,$42,$80,$01 ; $B6D6: Ending palette entry 4: 7 colors
$00:B6DE .db $80,$00,$06,$00,$CF,$00,$0B,$56 ; $B6E4: Ending palette entry 5: 7 colors
$00:B6E6 .db $00,$00,$07,$3A,$20,$01,$20,$00 ; (continued) Ending palette entry 5: 7 colors
$00:B6EE .db $02,$00,$6B,$00,$A7,$4D,$00,$00 ; $B6F2: Ending palette entry 6: 7 colors
$00:B6F6 .db $A3,$31,$C0,$00,$00,$00,$00,$00 ; (continued) Ending palette entry 6: 7 colors
$00:B6FE .db $07,$00,$43,$45,$00,$00,$40,$29 ; $B700: Ending palette entry 7: 7 colors
$00:B706 .db $60,$00,$00,$00,$00,$00,$03,$00 ; (continued) Ending palette entry 7: 7 colors
;;; $B70E: Ending palettes and GFX decompression (TheEndPalettes) ;;;
;; Starts with palette data (15-bit BGR words): three 12-byte sets copied to $08A7/$08C7/$08E7 by the title
;; screen code, followed by more color words.
;; $B888 (called once from game mode 00): decompresses Mario graphics (GFX32 at $08:BFC0) to $7E:2000,
;; expands each 24-byte 3bpp tile
;; to a 32-byte 4bpp tile in place going backwards (bitplane 3 = 0, result ends at $7E:AD00), then
;; decompresses the stream at $08:8000 to $7E:2000.
;; $B8DE: LZ2 decompressor. Parameters: [$8A]-[$8C] = source, [$00]-[$02] = destination. Commands: top 3
;; bits = type, low 5 bits = length - 1;
;; types 0 copy, 1 byte fill, 2 word fill, 3 incrementing fill, 4 copy earlier output (16-bit offset, high
;; byte first); 111 = long form (10-bit length); $FF ends.
$00:B70E .db $C4,$44,$20,$03,$DF,$4A,$00,$02 ; Palette 1, colors 0-3 (15-bit BGR words); first 12 bytes copied to $08A7 (palette buffer)
$00:B716 .db $3B,$01,$08,$4E ; Palette 1, colors 4-5
$00:B71A .db $C4,$44,$1F,$39,$DF,$4A,$74,$28 ; Palette 2, colors 0-3; 12 bytes copied to $08C7 (palette buffer)
$00:B722 .db $3F,$01,$08,$4E ; Palette 2, colors 4-5
$00:B726 .db $D2,$28,$1E,$55,$5F,$63,$1F,$7B ; Palette 3, colors 0-3; 12 bytes copied to $08E7 (palette buffer)
$00:B72E .db $FB,$01,$DE,$02,$00,$00,$33,$15 ; Palette 3, colors 4-5, then more color words with no named reference
$00:B736 .db $B7,$25,$3B,$36,$AF,$25,$BF,$5B
$00:B73E .db $C6,$5A,$00,$00,$DE,$7B,$3B,$36
$00:B746 .db $C6,$5A,$AF,$25,$BF,$37,$7F,$2D
$00:B74E .db $00,$00,$33,$15,$B7,$25,$3B,$36
$00:B756 .db $FF,$5E,$7F,$6F,$C6,$5A,$00,$00
$00:B75E .db $DE,$7B,$3B,$57,$C6,$5A,$AF,$25
$00:B766 .db $A8,$12,$48,$13,$00,$00,$B7,$25
$00:B76E .db $3B,$36,$BF,$46,$AF,$25,$5F,$5B
$00:B776 .db $C6,$5A,$00,$00,$DE,$7B,$BF,$46
$00:B77E .db $C6,$5A,$AF,$25,$BF,$37,$FF,$03
$00:B786 .db $00,$00,$85,$16,$4B,$2F,$F1,$47
$00:B78E .db $AF,$25,$5F,$5B,$C6,$5A,$00,$00
$00:B796 .db $DE,$7B,$3B,$57,$C6,$5A,$AF,$25
$00:B79E .db $C4,$38,$48,$13,$E7,$1C,$F3,$19
$00:B7A6 .db $B9,$32,$7F,$4B,$10,$76,$B9,$2E
$00:B7AE .db $FF,$7F,$E7,$1C,$60,$45,$80,$66
$00:B7B6 .db $F7,$7F,$1F,$03,$7F,$03,$FF,$47
$00:B7BE .db $E7,$1C,$F3,$19,$B9,$32,$7F,$4B
$00:B7C6 .db $1F,$00,$FF,$7F,$E7,$1C,$E7,$1C
$00:B7CE .db $F3,$19,$B9,$32,$7F,$4B,$C6,$58
$00:B7D6 .db $D5,$3A,$9C,$5B,$00,$00,$6D,$1D
$00:B7DE .db $D0,$29,$33,$36,$6B,$2D,$F9,$4E
$00:B7E6 .db $00,$00,$00,$00,$DE,$7B,$33,$36
$00:B7EE .db $82,$30,$6B,$2D,$BF,$37,$7F,$2D
$00:B7F6 .db $00,$00,$A7,$00,$2B,$15,$8E,$21
$00:B7FE .db $6B,$2D,$F9,$4E,$82,$30,$00,$00
$00:B806 .db $DE,$7B,$F9,$4E,$82,$30,$6B,$2D
$00:B80E .db $82,$30,$48,$13,$00,$00,$71,$21
$00:B816 .db $F5,$31,$79,$32,$F6,$41,$3B,$57
$00:B81E .db $60,$7D,$00,$00,$39,$77,$79,$32
$00:B826 .db $60,$7D,$18,$1E,$5C,$37,$09,$7E
$00:B82E .db $00,$00,$60,$36,$20,$4B,$EF,$22
$00:B836 .db $7A,$52,$3A,$53,$60,$7D,$00,$00
$00:B83E .db $8E,$21,$79,$32,$19,$21,$75,$3E
$00:B846 .db $35,$11,$98,$1D,$C7,$2C,$F0,$69
$00:B84E .db $00,$00,$00,$00,$34,$66,$F9,$7F
$00:B856 .db $FF,$7F,$00,$00,$60,$45,$80,$66
$00:B85E .db $F7,$7F,$1F,$03,$7F,$03,$FF,$47
$00:B866 .db $2C,$41,$F0,$69,$B2,$66,$D5,$67
$00:B86E .db $1F,$00,$FF,$7F,$C7,$2C,$C7,$2C
$00:B876 .db $F0,$69,$B2,$66,$D5,$67,$2C,$41
$00:B87E .db $D5,$3A,$9C,$5B,$C0,$BF,$08,$00 ; Last color words; then bytes C0 BF 08 = unreferenced pointer $08:BFC0 (GFX32)
$00:B886 .db $80,$08 ; 00 80 08 (continued): unreferenced pointer $08:8000
$00:B888 C2 10 REP #$10 ; Index 16-bit
$00:B88A A0 C0 BF LDY.W #$BFC0 ; \
$00:B88D 84 8A STY $8A ; |
$00:B88F A9 08 LDA.B #$08 ; } $8A-$8C = $08:BFC0: compressed Mario graphics (GFX32)
$00:B891 85 8C STA $8C ; /
$00:B893 A0 00 20 LDY.W #$2000 ; \
$00:B896 84 00 STY $00 ; |
$00:B898 A9 7E LDA.B #$7E ; } $00-$02 = $7E:2000: decompression destination
$00:B89A 85 02 STA $02 ; /
$00:B89C 20 DE B8 JSR.W $B8DE ; Decompress it (LZ2) to $7E:2000
$00:B89F A9 7E LDA.B #$7E ; \
$00:B8A1 85 8F STA $8F ; |
$00:B8A3 C2 30 REP #$30 ; |
$00:B8A5 A9 FE AC LDA.W #$ACFE ; } $8D-$8F = $7E:ACFE: write pointer for the 4bpp copy, filled backwards
$00:B8A8 85 8D STA $8D ; /
$00:B8AA A2 FF 23 LDX.W #$23FF ; X = $23FF: last byte of the $2400-byte 3bpp data (384 tiles of 24 bytes)
$00:B8AD A0 08 00 LDY.W #$0008 ; Y = 8 rows of bitplane 2
$00:B8B0 BF 00 20 7E LDA.L $7E2000,X ; \
$00:B8B4 29 FF 00 AND.W #$00FF ; } Bitplane 2 byte of a row becomes a word (bitplane 3 = 0), stored at [$8D]
$00:B8B7 87 8D STA [$8D] ; /
$00:B8B9 CA DEX ; \
$00:B8BA C6 8D DEC $8D ; } X--; $8D -= 2
$00:B8BC C6 8D DEC $8D ; /
$00:B8BE 88 DEY ; \
$00:B8BF D0 EF BNE $B8B0 ; / Repeat for 8 rows
$00:B8C1 A0 08 00 LDY.W #$0008 ; Y = 8 rows of bitplanes 0/1
$00:B8C4 CA DEX ; X-- (X now points at the high byte of the next word)
$00:B8C5 BF 00 20 7E LDA.L $7E2000,X ; A = bitplane 0/1 word of one row
$00:B8C9 87 8D STA [$8D] ; Store it at [$8D]
$00:B8CB CA DEX ; \
$00:B8CC 30 09 BMI $B8D7 ; / X--; all tiles done when X < 0
$00:B8CE C6 8D DEC $8D ; \
$00:B8D0 C6 8D DEC $8D ; / $8D -= 2
$00:B8D2 88 DEY ; \
$00:B8D3 D0 EF BNE $B8C4 ; / Repeat for 8 rows
$00:B8D5 80 D6 BRA $B8AD ; Next tile: back to the bitplane 2 loop
$00:B8D7 A9 00 80 LDA.W #$8000 ; \
$00:B8DA 85 8A STA $8A ; / $8A = $8000: next stream is at $08:8000 (bank in $8C unchanged)
$00:B8DC E2 20 SEP #$20 ; A 8-bit; falls into the decompressor (probably GFX33, left at $7E:2000)
$00:B8DE C2 10 REP #$10 ; Index 16-bit (LZ2 decompressor: source [$8A], destination [$00])
$00:B8E0 A0 00 00 LDY.W #$0000 ; Y = 0: output offset into [$00]
$00:B8E3 20 83 B9 JSR.W ReadByte ; Read the next command byte (ReadByte)
$00:B8E6 C9 FF CMP.B #$FF ; \
$00:B8E8 D0 03 BNE $B8ED ; / Command $FF: end of data
$00:B8EA E2 10 SEP #$10 ; Index 8-bit
$00:B8EC 60 RTS ; Return
$00:B8ED 85 8F STA $8F ; Remember the command byte in [$8F]
$00:B8EF 29 E0 AND.B #$E0 ; \
$00:B8F1 C9 E0 CMP.B #$E0 ; } Bits 7-5 = 111: long command with a 10-bit length, go to $00B8FF
$00:B8F3 F0 0A BEQ $B8FF ; /
$00:B8F5 48 PHA ; Push command type (bits 7-5 in place)
$00:B8F6 A5 8F LDA $8F ; \
$00:B8F8 C2 20 REP #$20 ; } A = length - 1 = bits 4-0 of the command
$00:B8FA 29 1F 00 AND.W #$001F ; /
$00:B8FD 80 12 BRA $B911 ; Go to $00B911
$00:B8FF A5 8F LDA $8F ; \
$00:B901 0A ASL ; |
$00:B902 0A ASL ; |
$00:B903 0A ASL ; } Long command: type = bits 4-2, moved to bits 7-5
$00:B904 29 E0 AND.B #$E0 ; /
$00:B906 48 PHA ; Push command type
$00:B907 A5 8F LDA $8F ; \
$00:B909 29 03 AND.B #$03 ; } Bits 1-0 = high bits of length - 1, parked in B
$00:B90B EB XBA ; /
$00:B90C 20 83 B9 JSR.W ReadByte ; Read the low byte of length - 1
$00:B90F C2 20 REP #$20 ; A 16-bit: A = length - 1
$00:B911 1A INC A ; A = length
$00:B912 85 8D STA $8D ; $8D = byte count
$00:B914 E2 20 SEP #$20 ; A 8-bit
$00:B916 68 PLA ; Pull the command type
$00:B917 F0 17 BEQ $B930 ; Type 000: direct copy
$00:B919 30 4B BMI $B966 ; Type 1xx: copy from earlier output
$00:B91B 0A ASL ; \
$00:B91C 10 21 BPL $B93F ; / Type 001: byte fill
$00:B91E 0A ASL ; \
$00:B91F 10 2B BPL $B94C ; / Type 010: word fill
$00:B921 20 83 B9 JSR.W ReadByte ; Type 011 (incrementing fill): read the start value
$00:B924 A6 8D LDX $8D ; X = count
$00:B926 97 00 STA [$00],Y ; Store the value in the output
$00:B928 1A INC A ; Value++
$00:B929 C8 INY ; Output offset++
$00:B92A CA DEX ; \
$00:B92B D0 F9 BNE $B926 ; / Repeat count times
$00:B92D 4C E3 B8 JMP.W $B8E3 ; Next command
$00:B930 20 83 B9 JSR.W ReadByte ; Direct copy: read a byte
$00:B933 97 00 STA [$00],Y ; Store it in the output
$00:B935 C8 INY ; Output offset++
$00:B936 A6 8D LDX $8D ; \
$00:B938 CA DEX ; } $8D = count - 1
$00:B939 86 8D STX $8D ; /
$00:B93B D0 F3 BNE $B930 ; Repeat until the count is 0
$00:B93D 80 A4 BRA $B8E3 ; Next command
$00:B93F 20 83 B9 JSR.W ReadByte ; Byte fill: read the fill value
$00:B942 A6 8D LDX $8D ; X = count
$00:B944 97 00 STA [$00],Y ; Store the value in the output
$00:B946 C8 INY ; Output offset++
$00:B947 CA DEX ; \
$00:B948 D0 FA BNE $B944 ; / Repeat count times
$00:B94A 80 97 BRA $B8E3 ; Next command
$00:B94C 20 83 B9 JSR.W ReadByte ; Word fill: read the first fill byte
$00:B94F EB XBA ; Park it in B
$00:B950 20 83 B9 JSR.W ReadByte ; Read the second fill byte
$00:B953 A6 8D LDX $8D ; X = count
$00:B955 EB XBA ; A = first byte
$00:B956 97 00 STA [$00],Y ; Store it in the output
$00:B958 C8 INY ; Output offset++
$00:B959 CA DEX ; \
$00:B95A F0 07 BEQ $B963 ; / Count exhausted: next command ($00B963)
$00:B95C EB XBA ; A = second byte
$00:B95D 97 00 STA [$00],Y ; Store it in the output
$00:B95F C8 INY ; Output offset++
$00:B960 CA DEX ; \
$00:B961 D0 F2 BNE $B955 ; / Alternate the two bytes until count is 0
$00:B963 4C E3 B8 JMP.W $B8E3 ; Next command
$00:B966 20 83 B9 JSR.W ReadByte ; \
$00:B969 EB XBA ; |
$00:B96A 20 83 B9 JSR.W ReadByte ; } X = source offset in the output (16-bit, high byte stored first)
$00:B96D AA TAX ; /
$00:B96E 5A PHY ; \
$00:B96F 9B TXY ; |
$00:B970 B7 00 LDA [$00],Y ; |
$00:B972 BB TYX ; } A = output[X], Y preserved
$00:B973 7A PLY ; /
$00:B974 97 00 STA [$00],Y ; Append it to the output
$00:B976 C8 INY ; Output offset++
$00:B977 E8 INX ; Source offset++
$00:B978 C2 20 REP #$20 ; \
$00:B97A C6 8D DEC $8D ; } $8D-- (count, 16-bit)
$00:B97C E2 20 SEP #$20 ; /
$00:B97E D0 EE BNE $B96E ; Repeat until the count is 0
$00:B980 4C E3 B8 JMP.W $B8E3 ; Next command
;;; $B983: Read byte from 24-bit source pointer (ReadByte) ;;;
;; Returns the byte at [$8A] in A and advances the pointer, moving to $8000 of the next bank when it wraps.
;; Parameters: [$8A]-[$8C]: 24-bit source pointer. Returns: A = byte; X is clobbered; A and X sizes are the
;; caller's.
;; Called by:
;; $00:B8E3: Ending palettes and GFX decompression (TheEndPalettes)
;; $00:B90C: Ending palettes and GFX decompression (TheEndPalettes)
;; $00:B921: Ending palettes and GFX decompression (TheEndPalettes)
;; $00:B930: Ending palettes and GFX decompression (TheEndPalettes)
;; $00:B93F: Ending palettes and GFX decompression (TheEndPalettes)
;; $00:B94C: Ending palettes and GFX decompression (TheEndPalettes)
;; $00:B950: Ending palettes and GFX decompression (TheEndPalettes)
;; $00:B966: Ending palettes and GFX decompression (TheEndPalettes)
;; $00:B96A: Ending palettes and GFX decompression (TheEndPalettes)
$00:B983 A7 8A LDA [$8A] ; A = byte at the 24-bit source pointer [$8A]
$00:B985 A6 8A LDX $8A ; \
$00:B987 E8 INX ; / X = pointer + 1
$00:B988 D0 05 BNE $B98F ; No wrap: go store the pointer
$00:B98A A2 00 80 LDX.W #$8000 ; \
$00:B98D E6 8C INC $8C ; / Pointer wrapped past $FFFF: restart at $8000 of the next bank
$00:B98F 86 8A STX $8A ; Store the advanced pointer
$00:B991 60 RTS ; Return (A = byte, X clobbered)
;;; $B992..B9C2: Table: GFX file address, low byte ;;;
;; Indexed by GFX file number $00-$31; with the next two tables forms the 24-bit ROM address of each
;; compressed file.
$00:B992 .db $F9,$31,$BB,$52,$7D,$63,$6C,$10 ; GFX file $00-$07: ROM address, low byte
$00:B99A .db $57,$A1,$15,$9C,$63,$D2,$CB,$E5 ; GFX file $08-$0F: ROM address, low byte
$00:B9A2 .db $1E,$AF,$BD,$10,$48,$E8,$74,$B4 ; GFX file $10-$17: ROM address, low byte
$00:B9AA .db $AD,$E4,$80,$66,$7E,$88,$7F,$43 ; GFX file $18-$1F: ROM address, low byte
$00:B9B2 .db $A1,$65,$CD,$CA,$E5,$B5,$21,$44 ; GFX file $20-$27: ROM address, low byte
$00:B9BA .db $6C,$A3,$7B,$F0,$B9,$06,$36,$85 ; GFX file $28-$2F: ROM address, low byte
$00:B9C2 .db $BB,$00 ; GFX file $30-$31: ROM address, low byte
;;; $B9C4..B9F4: Table: GFX file address, high byte ;;;
$00:B9C4 .db $D9,$E2,$EC,$F5,$FF,$89,$93,$9D ; GFX file $00-$07: ROM address, high byte
$00:B9CC .db $A6,$AF,$BA,$C3,$CD,$D5,$DD,$E6 ; GFX file $08-$0F: ROM address, high byte
$00:B9D4 .db $EF,$F7,$FF,$89,$93,$9A,$A3,$A9 ; GFX file $10-$17: ROM address, high byte
$00:B9DC .db $B2,$BB,$C3,$CC,$D4,$DC,$E6,$EE ; GFX file $18-$1F: ROM address, high byte
$00:B9E4 .db $F6,$FF,$88,$91,$9A,$A3,$AE,$B7 ; GFX file $20-$27: ROM address, high byte
$00:B9EC .db $C0,$C6,$CB,$D0,$D7,$E0,$E9,$F1 ; GFX file $28-$2F: ROM address, high byte
$00:B9F4 .db $F3,$F8 ; GFX file $30-$31: ROM address, high byte
;;; $B9F6..BA26: Table: GFX file bank ;;;
$00:B9F6 .db $08,$08,$08,$08,$08,$09,$09,$09 ; GFX file $00-$07: ROM bank
$00:B9FE .db $09,$09,$09,$09,$09,$09,$09,$09 ; GFX file $08-$0F: ROM bank
$00:BA06 .db $09,$09,$09,$0A,$0A,$0A,$0A,$0A ; GFX file $10-$17: ROM bank
$00:BA0E .db $0A,$0A,$0A,$0A,$0A,$0A,$0A,$0A ; GFX file $18-$1F: ROM bank
$00:BA16 .db $0A,$0A,$0B,$0B,$0B,$0B,$0B,$0B ; GFX file $20-$27: ROM bank
$00:BA1E .db $0B,$0B,$0B,$0B,$0B,$0B,$0B,$0B ; GFX file $28-$2F: ROM bank
$00:BA26 .db $0B,$0B ; GFX file $30-$31: ROM bank
;;; $BA28: Decompress GFX file to buffer ;;;
;; Looks up the ROM address of GFX file Y and decompresses it to the GFX buffer at $7E:AD00 using the LZ2
;; decompressor.
;; Parameters: Y: GFX file number ($00-$31). Returns: Y and the data bank preserved; RTL.
;; Called by:
;; $00:9560: Cutscene, ending and game mode code (castle scenes, credits, game over) (CutsceneCastlePal)
;; $00:A149: Game mode 0C: load overworld (LoadMapGameMode)
;; $00:A82F: Level start setup, Mario Start! graphics
;; $00:A873: Level start setup, Mario Start! graphics
;; $00:A9A6: Table: tileset GFX lists, raw GFX upload (OBJECTGFXLIST)
;; $00:AA6B: Decompress GFX file and start upload (UploadGFXFile)
;; $00:AA7A: Decompress GFX file and start upload (UploadGFXFile)
;; $00:AB44: 3bpp to 4bpp: planes 2-3; Mode 7 upload (AddressWrite2)
;; $03:DDC8: Mode 7 boss graphics and palette setup (KoopaPalPtrHi)
$00:BA28 8B PHB ; Save the data bank
$00:BA29 5A PHY ; Save Y (GFX file number)
$00:BA2A 4B PHK ; \
$00:BA2B AB PLB ; / Data bank = $00
$00:BA2C B9 92 B9 LDA.W $B992,Y ; \
$00:BA2F 85 8A STA $8A ; |
$00:BA31 B9 C4 B9 LDA.W $B9C4,Y ; |
$00:BA34 85 8B STA $8B ; |
$00:BA36 B9 F6 B9 LDA.W $B9F6,Y ; } $8A-$8C = ROM address of GFX file Y (from the three tables)
$00:BA39 85 8C STA $8C ; /
$00:BA3B A9 00 LDA.B #$00 ; \
$00:BA3D 85 00 STA $00 ; |
$00:BA3F A9 AD LDA.B #$AD ; |
$00:BA41 85 01 STA $01 ; |
$00:BA43 A9 7E LDA.B #$7E ; } $00-$02 = $7E:AD00 (GFX buffer)
$00:BA45 85 02 STA $02 ; /
$00:BA47 20 DE B8 JSR.W $B8DE ; Decompress the file to the buffer (LZ2)
$00:BA4A 7A PLY ; Restore Y
$00:BA4B AB PLB ; Restore the data bank
$00:BA4C 6B RTL ; Return long
;;; $BA4D..BA5D: Unused. Padding ($FF bytes) ;;;
$00:BA4D .db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
$00:BA55 .db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
$00:BA5D .db $FF,$FF,$FF
;;; $BA60..BA68: Table: layer 1 horizontal screen offsets, low byte ;;;
;; Low byte of the Map16 offset of screen n (n * $1B0). Together with $BA9C: $C800 + n * $1B0. Used by
;; the level loading code in banks 01, 02 and 00.
$00:BA60 .db $00,$B0,$60,$10,$C0,$70,$20,$D0 ; Screens $00-$07: layer 1 horizontal, offset low byte (n * $1B0)
$00:BA68 .db $80,$30,$E0,$90,$40,$F0,$A0,$50 ; Screens $08-$0F: layer 1 horizontal, offset low byte (n * $1B0)
;;; $BA70..BA78: Table: layer 2 horizontal screen offsets, low byte ;;;
;; Same low bytes as $BA60, for layer 2 (high bytes in $BAAC: $E300 + n * $1B0).
$00:BA70 .db $00,$B0,$60,$10,$C0,$70,$20,$D0 ; Screens $00-$07: layer 2 horizontal, offset low byte (n * $1B0)
$00:BA78 .db $80,$30,$E0,$90,$40,$F0,$A0,$50 ; Screens $08-$0F: layer 2 horizontal, offset low byte (n * $1B0)
;;; $BA80..BA88: Table: layer 1 vertical screen offsets, low byte ;;;
;; All zero: vertical screens are $0200 bytes (high bytes in $BABC).
$00:BA80 .db $00,$00,$00,$00,$00,$00,$00,$00 ; Screens $00-$07: layer 1 vertical, offset low byte (n * $200, always 0)
$00:BA88 .db $00,$00,$00,$00,$00,$00 ; Screens $08-$0D: layer 1 vertical, offset low byte (n * $200, always 0)
;;; $BA8E..BA96: Table: layer 2 vertical screen offsets, low byte ;;;
;; All zero (high bytes in $BACA).
$00:BA8E .db $00,$00,$00,$00,$00,$00,$00,$00 ; Screens $00-$07: layer 2 vertical, offset low byte (always 0)
$00:BA96 .db $00,$00,$00,$00,$00,$00 ; Screens $08-$0D: layer 2 vertical, offset low byte (always 0)
;;; $BA9C..BAA4: Table: layer 1 horizontal screen offsets, high byte ;;;
$00:BA9C .db $C8,$C9,$CB,$CD,$CE,$D0,$D2,$D3 ; Screens $00-$07: layer 1 horizontal, offset high byte ($C800 + n * $1B0)
$00:BAA4 .db $D5,$D7,$D8,$DA,$DC,$DD,$DF,$E1 ; Screens $08-$0F: layer 1 horizontal, offset high byte ($C800 + n * $1B0)
;;; $BAAC..BAB4: Table: layer 2 horizontal screen offsets, high byte ;;;
$00:BAAC .db $E3,$E4,$E6,$E8,$E9,$EB,$ED,$EE ; Screens $00-$07: layer 2 horizontal, offset high byte ($E300 + n * $1B0)
$00:BAB4 .db $F0,$F2,$F3,$F5,$F7,$F8,$FA,$FC ; Screens $08-$0F: layer 2 horizontal, offset high byte ($E300 + n * $1B0)
;;; $BABC..BAC4: Table: layer 1 vertical screen offsets, high byte ;;;
$00:BABC .db $C8,$CA,$CC,$CE,$D0,$D2,$D4,$D6 ; Screens $00-$07: layer 1 vertical, offset high byte ($C800 + n * $200)
$00:BAC4 .db $D8,$DA,$DC,$DE,$E0,$E2 ; Screens $08-$0D: layer 1 vertical, offset high byte ($C800 + n * $200)
;;; $BACA..BAD2: Table: layer 2 vertical screen offsets, high byte ;;;
$00:BACA .db $E4,$E6,$E8,$EA,$EC,$EE,$F0,$F2 ; Screens $00-$07: layer 2 vertical, offset high byte ($E400 + n * $200)
$00:BAD2 .db $F4,$F6,$F8,$FA,$FC,$FE ; Screens $08-$0D: layer 2 vertical, offset high byte ($E400 + n * $200)
;;; $BAD8..BB00: Table: screen addresses, layer 1 horizontal bank $7E ;;;
;; 24-bit address of the Map16 data of each screen (low byte table). Horizontal screens are $1B0 bytes (16x27
;; blocks), vertical $0200 (16x32).
$00:BAD8 .db $00,$C8,$7E,$B0,$C9,$7E,$60,$CB ; Entries 00-02 of screen address table (bank $7E): screen n = layer 1 horizontal, $C800 + n * $1B0 (3 bytes: low, high, bank)
$00:BAE0 .db $7E,$10,$CD,$7E,$C0,$CE,$7E,$70 ; Entries 02-05 of screen address table (bank $7E): screen n = layer 1 horizontal, $C800 + n * $1B0 (3 bytes: low, high, bank)
$00:BAE8 .db $D0,$7E,$20,$D2,$7E,$D0,$D3,$7E ; Entries 05-07 of screen address table (bank $7E): screen n = layer 1 horizontal, $C800 + n * $1B0 (3 bytes: low, high, bank)
$00:BAF0 .db $80,$D5,$7E,$30,$D7,$7E,$E0,$D8 ; Entries 08-0A of screen address table (bank $7E): screen n = layer 1 horizontal, $C800 + n * $1B0 (3 bytes: low, high, bank)
$00:BAF8 .db $7E,$90,$DA,$7E,$40,$DC,$7E,$F0 ; Entries 0A-0D of screen address table (bank $7E): screen n = layer 1 horizontal, $C800 + n * $1B0 (3 bytes: low, high, bank)
$00:BB00 .db $DD,$7E,$A0,$DF,$7E,$50,$E1,$7E ; Entries 0D-0F of screen address table (bank $7E): screen n = layer 1 horizontal, $C800 + n * $1B0 (3 bytes: low, high, bank)
;;; $BB08..BB30: Table: screen addresses, layer 2 horizontal bank $7E ;;;
;; 24-bit address of the Map16 data of each screen (low byte table). Horizontal screens are $1B0 bytes (16x27
;; blocks), vertical $0200 (16x32).
$00:BB08 .db $00,$E3,$7E,$B0,$E4,$7E,$60,$E6 ; Entries 00-02 of screen address table (bank $7E): screen n = layer 2 horizontal, $E300 + n * $1B0 (3 bytes: low, high, bank)
$00:BB10 .db $7E,$10,$E8,$7E,$C0,$E9,$7E,$70 ; Entries 02-05 of screen address table (bank $7E): screen n = layer 2 horizontal, $E300 + n * $1B0 (3 bytes: low, high, bank)
$00:BB18 .db $EB,$7E,$20,$ED,$7E,$D0,$EE,$7E ; Entries 05-07 of screen address table (bank $7E): screen n = layer 2 horizontal, $E300 + n * $1B0 (3 bytes: low, high, bank)
$00:BB20 .db $80,$F0,$7E,$30,$F2,$7E,$E0,$F3 ; Entries 08-0A of screen address table (bank $7E): screen n = layer 2 horizontal, $E300 + n * $1B0 (3 bytes: low, high, bank)
$00:BB28 .db $7E,$90,$F5,$7E,$40,$F7,$7E,$F0 ; Entries 0A-0D of screen address table (bank $7E): screen n = layer 2 horizontal, $E300 + n * $1B0 (3 bytes: low, high, bank)
$00:BB30 .db $F8,$7E,$A0,$FA,$7E,$50,$FC,$7E ; Entries 0D-0F of screen address table (bank $7E): screen n = layer 2 horizontal, $E300 + n * $1B0 (3 bytes: low, high, bank)
;;; $BB38..BB60: Table: screen addresses, layer 1 vertical bank $7E ;;;
;; 24-bit address of the Map16 data of each screen (low byte table). Horizontal screens are $1B0 bytes (16x27
;; blocks), vertical $0200 (16x32).
$00:BB38 .db $00,$C8,$7E,$00,$CA,$7E,$00,$CC ; Entries 00-02 of screen address table (bank $7E): screen n = layer 1 vertical, $C800 + n * $200 (3 bytes: low, high, bank)
$00:BB40 .db $7E,$00,$CE,$7E,$00,$D0,$7E,$00 ; Entries 02-05 of screen address table (bank $7E): screen n = layer 1 vertical, $C800 + n * $200 (3 bytes: low, high, bank)
$00:BB48 .db $D2,$7E,$00,$D4,$7E,$00,$D6,$7E ; Entries 05-07 of screen address table (bank $7E): screen n = layer 1 vertical, $C800 + n * $200 (3 bytes: low, high, bank)
$00:BB50 .db $00,$D8,$7E,$00,$DA,$7E,$00,$DC ; Entries 08-0A of screen address table (bank $7E): screen n = layer 1 vertical, $C800 + n * $200 (3 bytes: low, high, bank)
$00:BB58 .db $7E,$00,$DE,$7E,$00,$E0,$7E,$00 ; Entries 0A-0D of screen address table (bank $7E): screen n = layer 1 vertical, $C800 + n * $200 (3 bytes: low, high, bank)
$00:BB60 .db $E2,$7E ; Entries 0D-0D of screen address table (bank $7E): screen n = layer 1 vertical, $C800 + n * $200 (3 bytes: low, high, bank)
;;; $BB62..BB8A: Table: screen addresses, layer 2 horizontal bank $7E ;;;
;; 24-bit address of the Map16 data of each screen (low byte table). Horizontal screens are $1B0 bytes (16x27
;; blocks), vertical $0200 (16x32).
$00:BB62 .db $00,$E3,$7E,$B0,$E4,$7E,$60,$E6 ; Entries 00-02 of screen address table (bank $7E): screen n = layer 2 horizontal, $E300 + n * $1B0 (3 bytes: low, high, bank)
$00:BB6A .db $7E,$10,$E8,$7E,$C0,$E9,$7E,$70 ; Entries 02-05 of screen address table (bank $7E): screen n = layer 2 horizontal, $E300 + n * $1B0 (3 bytes: low, high, bank)
$00:BB72 .db $EB,$7E,$20,$ED,$7E,$D0,$EE,$7E ; Entries 05-07 of screen address table (bank $7E): screen n = layer 2 horizontal, $E300 + n * $1B0 (3 bytes: low, high, bank)
$00:BB7A .db $80,$F0,$7E,$30,$F2,$7E,$E0,$F3 ; Entries 08-0A of screen address table (bank $7E): screen n = layer 2 horizontal, $E300 + n * $1B0 (3 bytes: low, high, bank)
$00:BB82 .db $7E,$90,$F5,$7E,$40,$F7,$7E,$F0 ; Entries 0A-0D of screen address table (bank $7E): screen n = layer 2 horizontal, $E300 + n * $1B0 (3 bytes: low, high, bank)
$00:BB8A .db $F8,$7E,$A0,$FA,$7E,$50,$FC,$7E ; Entries 0D-0F of screen address table (bank $7E): screen n = layer 2 horizontal, $E300 + n * $1B0 (3 bytes: low, high, bank)
;;; $BB92..BBBA: Table: screen addresses, layer 1 horizontal bank $7E ;;;
;; 24-bit address of the Map16 data of each screen (low byte table). Horizontal screens are $1B0 bytes (16x27
;; blocks), vertical $0200 (16x32).
$00:BB92 .db $00,$C8,$7E,$B0,$C9,$7E,$60,$CB ; Entries 00-02 of screen address table (bank $7E): screen n = layer 1 horizontal, $C800 + n * $1B0 (3 bytes: low, high, bank)
$00:BB9A .db $7E,$10,$CD,$7E,$C0,$CE,$7E,$70 ; Entries 02-05 of screen address table (bank $7E): screen n = layer 1 horizontal, $C800 + n * $1B0 (3 bytes: low, high, bank)
$00:BBA2 .db $D0,$7E,$20,$D2,$7E,$D0,$D3,$7E ; Entries 05-07 of screen address table (bank $7E): screen n = layer 1 horizontal, $C800 + n * $1B0 (3 bytes: low, high, bank)
$00:BBAA .db $80,$D5,$7E,$30,$D7,$7E,$E0,$D8 ; Entries 08-0A of screen address table (bank $7E): screen n = layer 1 horizontal, $C800 + n * $1B0 (3 bytes: low, high, bank)
$00:BBB2 .db $7E,$90,$DA,$7E,$40,$DC,$7E,$F0 ; Entries 0A-0D of screen address table (bank $7E): screen n = layer 1 horizontal, $C800 + n * $1B0 (3 bytes: low, high, bank)
$00:BBBA .db $DD,$7E,$A0,$DF,$7E,$50,$E1,$7E ; Entries 0D-0F of screen address table (bank $7E): screen n = layer 1 horizontal, $C800 + n * $1B0 (3 bytes: low, high, bank)
;;; $BBC2..BBEA: Table: screen addresses, layer 2 vertical bank $7E ;;;
;; 24-bit address of the Map16 data of each screen (low byte table). Horizontal screens are $1B0 bytes (16x27
;; blocks), vertical $0200 (16x32).
$00:BBC2 .db $00,$E4,$7E,$00,$E6,$7E,$00,$E8 ; Entries 00-02 of screen address table (bank $7E): screen n = layer 2 vertical, $E400 + n * $200 (3 bytes: low, high, bank)
$00:BBCA .db $7E,$00,$EA,$7E,$00,$EC,$7E,$00 ; Entries 02-05 of screen address table (bank $7E): screen n = layer 2 vertical, $E400 + n * $200 (3 bytes: low, high, bank)
$00:BBD2 .db $EE,$7E,$00,$F0,$7E,$00,$F2,$7E ; Entries 05-07 of screen address table (bank $7E): screen n = layer 2 vertical, $E400 + n * $200 (3 bytes: low, high, bank)
$00:BBDA .db $00,$F4,$7E,$00,$F6,$7E,$00,$F8 ; Entries 08-0A of screen address table (bank $7E): screen n = layer 2 vertical, $E400 + n * $200 (3 bytes: low, high, bank)
$00:BBE2 .db $7E,$00,$FA,$7E,$00,$FC,$7E,$00 ; Entries 0A-0D of screen address table (bank $7E): screen n = layer 2 vertical, $E400 + n * $200 (3 bytes: low, high, bank)
$00:BBEA .db $FE,$7E ; Entries 0D-0D of screen address table (bank $7E): screen n = layer 2 vertical, $E400 + n * $200 (3 bytes: low, high, bank)
;;; $BBEC..BC14: Table: screen addresses, layer 1 vertical bank $7E ;;;
;; 24-bit address of the Map16 data of each screen (low byte table). Horizontal screens are $1B0 bytes (16x27
;; blocks), vertical $0200 (16x32).
$00:BBEC .db $00,$C8,$7E,$00,$CA,$7E,$00,$CC ; Entries 00-02 of screen address table (bank $7E): screen n = layer 1 vertical, $C800 + n * $200 (3 bytes: low, high, bank)
$00:BBF4 .db $7E,$00,$CE,$7E,$00,$D0,$7E,$00 ; Entries 02-05 of screen address table (bank $7E): screen n = layer 1 vertical, $C800 + n * $200 (3 bytes: low, high, bank)
$00:BBFC .db $D2,$7E,$00,$D4,$7E,$00,$D6,$7E ; Entries 05-07 of screen address table (bank $7E): screen n = layer 1 vertical, $C800 + n * $200 (3 bytes: low, high, bank)
$00:BC04 .db $00,$D8,$7E,$00,$DA,$7E,$00,$DC ; Entries 08-0A of screen address table (bank $7E): screen n = layer 1 vertical, $C800 + n * $200 (3 bytes: low, high, bank)
$00:BC0C .db $7E,$00,$DE,$7E,$00,$E0,$7E,$00 ; Entries 0A-0D of screen address table (bank $7E): screen n = layer 1 vertical, $C800 + n * $200 (3 bytes: low, high, bank)
$00:BC14 .db $E2,$7E ; Entries 0D-0D of screen address table (bank $7E): screen n = layer 1 vertical, $C800 + n * $200 (3 bytes: low, high, bank)
;;; $BC16..BC3E: Table: screen addresses, layer 2 vertical bank $7E ;;;
;; 24-bit address of the Map16 data of each screen (low byte table). Horizontal screens are $1B0 bytes (16x27
;; blocks), vertical $0200 (16x32).
$00:BC16 .db $00,$E4,$7E,$00,$E6,$7E,$00,$E8 ; Entries 00-02 of screen address table (bank $7E): screen n = layer 2 vertical, $E400 + n * $200 (3 bytes: low, high, bank)
$00:BC1E .db $7E,$00,$EA,$7E,$00,$EC,$7E,$00 ; Entries 02-05 of screen address table (bank $7E): screen n = layer 2 vertical, $E400 + n * $200 (3 bytes: low, high, bank)
$00:BC26 .db $EE,$7E,$00,$F0,$7E,$00,$F2,$7E ; Entries 05-07 of screen address table (bank $7E): screen n = layer 2 vertical, $E400 + n * $200 (3 bytes: low, high, bank)
$00:BC2E .db $00,$F4,$7E,$00,$F6,$7E,$00,$F8 ; Entries 08-0A of screen address table (bank $7E): screen n = layer 2 vertical, $E400 + n * $200 (3 bytes: low, high, bank)
$00:BC36 .db $7E,$00,$FA,$7E,$00,$FC,$7E,$00 ; Entries 0A-0D of screen address table (bank $7E): screen n = layer 2 vertical, $E400 + n * $200 (3 bytes: low, high, bank)
$00:BC3E .db $FE,$7E ; Entries 0D-0D of screen address table (bank $7E): screen n = layer 2 vertical, $E400 + n * $200 (3 bytes: low, high, bank)
;;; $BC40..BC68: Table: screen addresses, layer 1 horizontal bank $7F ;;;
;; 24-bit address of the Map16 data of each screen (high byte / page table, same offsets). Horizontal screens
;; are $1B0 bytes (16x27 blocks), vertical $0200 (16x32).
$00:BC40 .db $00,$C8,$7F,$B0,$C9,$7F,$60,$CB ; Entries 00-02 of screen address table (bank $7F): screen n = layer 1 horizontal, $C800 + n * $1B0 (3 bytes: low, high, bank)
$00:BC48 .db $7F,$10,$CD,$7F,$C0,$CE,$7F,$70 ; Entries 02-05 of screen address table (bank $7F): screen n = layer 1 horizontal, $C800 + n * $1B0 (3 bytes: low, high, bank)
$00:BC50 .db $D0,$7F,$20,$D2,$7F,$D0,$D3,$7F ; Entries 05-07 of screen address table (bank $7F): screen n = layer 1 horizontal, $C800 + n * $1B0 (3 bytes: low, high, bank)
$00:BC58 .db $80,$D5,$7F,$30,$D7,$7F,$E0,$D8 ; Entries 08-0A of screen address table (bank $7F): screen n = layer 1 horizontal, $C800 + n * $1B0 (3 bytes: low, high, bank)
$00:BC60 .db $7F,$90,$DA,$7F,$40,$DC,$7F,$F0 ; Entries 0A-0D of screen address table (bank $7F): screen n = layer 1 horizontal, $C800 + n * $1B0 (3 bytes: low, high, bank)
$00:BC68 .db $DD,$7F,$A0,$DF,$7F,$50,$E1,$7F ; Entries 0D-0F of screen address table (bank $7F): screen n = layer 1 horizontal, $C800 + n * $1B0 (3 bytes: low, high, bank)
;;; $BC70..BC98: Table: screen addresses, layer 2 horizontal bank $7F ;;;
;; 24-bit address of the Map16 data of each screen (high byte / page table, same offsets). Horizontal screens
;; are $1B0 bytes (16x27 blocks), vertical $0200 (16x32).
$00:BC70 .db $00,$E3,$7F,$B0,$E4,$7F,$60,$E6 ; Entries 00-02 of screen address table (bank $7F): screen n = layer 2 horizontal, $E300 + n * $1B0 (3 bytes: low, high, bank)
$00:BC78 .db $7F,$10,$E8,$7F,$C0,$E9,$7F,$70 ; Entries 02-05 of screen address table (bank $7F): screen n = layer 2 horizontal, $E300 + n * $1B0 (3 bytes: low, high, bank)
$00:BC80 .db $EB,$7F,$20,$ED,$7F,$D0,$EE,$7F ; Entries 05-07 of screen address table (bank $7F): screen n = layer 2 horizontal, $E300 + n * $1B0 (3 bytes: low, high, bank)
$00:BC88 .db $80,$F0,$7F,$30,$F2,$7F,$E0,$F3 ; Entries 08-0A of screen address table (bank $7F): screen n = layer 2 horizontal, $E300 + n * $1B0 (3 bytes: low, high, bank)
$00:BC90 .db $7F,$90,$F5,$7F,$40,$F7,$7F,$F0 ; Entries 0A-0D of screen address table (bank $7F): screen n = layer 2 horizontal, $E300 + n * $1B0 (3 bytes: low, high, bank)
$00:BC98 .db $F8,$7F,$A0,$FA,$7F,$50,$FC,$7F ; Entries 0D-0F of screen address table (bank $7F): screen n = layer 2 horizontal, $E300 + n * $1B0 (3 bytes: low, high, bank)
;;; $BCA0..BCC8: Table: screen addresses, layer 1 vertical bank $7F ;;;
;; 24-bit address of the Map16 data of each screen (high byte / page table, same offsets). Horizontal screens
;; are $1B0 bytes (16x27 blocks), vertical $0200 (16x32).
$00:BCA0 .db $00,$C8,$7F,$00,$CA,$7F,$00,$CC ; Entries 00-02 of screen address table (bank $7F): screen n = layer 1 vertical, $C800 + n * $200 (3 bytes: low, high, bank)
$00:BCA8 .db $7F,$00,$CE,$7F,$00,$D0,$7F,$00 ; Entries 02-05 of screen address table (bank $7F): screen n = layer 1 vertical, $C800 + n * $200 (3 bytes: low, high, bank)
$00:BCB0 .db $D2,$7F,$00,$D4,$7F,$00,$D6,$7F ; Entries 05-07 of screen address table (bank $7F): screen n = layer 1 vertical, $C800 + n * $200 (3 bytes: low, high, bank)
$00:BCB8 .db $00,$D8,$7F,$00,$DA,$7F,$00,$DC ; Entries 08-0A of screen address table (bank $7F): screen n = layer 1 vertical, $C800 + n * $200 (3 bytes: low, high, bank)
$00:BCC0 .db $7F,$00,$DE,$7F,$00,$E0,$7F,$00 ; Entries 0A-0D of screen address table (bank $7F): screen n = layer 1 vertical, $C800 + n * $200 (3 bytes: low, high, bank)
$00:BCC8 .db $E2,$7F ; Entries 0D-0D of screen address table (bank $7F): screen n = layer 1 vertical, $C800 + n * $200 (3 bytes: low, high, bank)
;;; $BCCA..BCF2: Table: screen addresses, layer 2 horizontal bank $7F ;;;
;; 24-bit address of the Map16 data of each screen (high byte / page table, same offsets). Horizontal screens
;; are $1B0 bytes (16x27 blocks), vertical $0200 (16x32).
$00:BCCA .db $00,$E3,$7F,$B0,$E4,$7F,$60,$E6 ; Entries 00-02 of screen address table (bank $7F): screen n = layer 2 horizontal, $E300 + n * $1B0 (3 bytes: low, high, bank)
$00:BCD2 .db $7F,$10,$E8,$7F,$C0,$E9,$7F,$70 ; Entries 02-05 of screen address table (bank $7F): screen n = layer 2 horizontal, $E300 + n * $1B0 (3 bytes: low, high, bank)
$00:BCDA .db $EB,$7F,$20,$ED,$7F,$D0,$EE,$7F ; Entries 05-07 of screen address table (bank $7F): screen n = layer 2 horizontal, $E300 + n * $1B0 (3 bytes: low, high, bank)
$00:BCE2 .db $80,$F0,$7F,$30,$F2,$7F,$E0,$F3 ; Entries 08-0A of screen address table (bank $7F): screen n = layer 2 horizontal, $E300 + n * $1B0 (3 bytes: low, high, bank)
$00:BCEA .db $7F,$90,$F5,$7F,$40,$F7,$7F,$F0 ; Entries 0A-0D of screen address table (bank $7F): screen n = layer 2 horizontal, $E300 + n * $1B0 (3 bytes: low, high, bank)
$00:BCF2 .db $F8,$7F,$A0,$FA,$7F,$50,$FC,$7F ; Entries 0D-0F of screen address table (bank $7F): screen n = layer 2 horizontal, $E300 + n * $1B0 (3 bytes: low, high, bank)
;;; $BCFA..BD22: Table: screen addresses, layer 1 horizontal bank $7F ;;;
;; 24-bit address of the Map16 data of each screen (high byte / page table, same offsets). Horizontal screens
;; are $1B0 bytes (16x27 blocks), vertical $0200 (16x32).
$00:BCFA .db $00,$C8,$7F,$B0,$C9,$7F,$60,$CB ; Entries 00-02 of screen address table (bank $7F): screen n = layer 1 horizontal, $C800 + n * $1B0 (3 bytes: low, high, bank)
$00:BD02 .db $7F,$10,$CD,$7F,$C0,$CE,$7F,$70 ; Entries 02-05 of screen address table (bank $7F): screen n = layer 1 horizontal, $C800 + n * $1B0 (3 bytes: low, high, bank)
$00:BD0A .db $D0,$7F,$20,$D2,$7F,$D0,$D3,$7F ; Entries 05-07 of screen address table (bank $7F): screen n = layer 1 horizontal, $C800 + n * $1B0 (3 bytes: low, high, bank)
$00:BD12 .db $80,$D5,$7F,$30,$D7,$7F,$E0,$D8 ; Entries 08-0A of screen address table (bank $7F): screen n = layer 1 horizontal, $C800 + n * $1B0 (3 bytes: low, high, bank)
$00:BD1A .db $7F,$90,$DA,$7F,$40,$DC,$7F,$F0 ; Entries 0A-0D of screen address table (bank $7F): screen n = layer 1 horizontal, $C800 + n * $1B0 (3 bytes: low, high, bank)
$00:BD22 .db $DD,$7F,$A0,$DF,$7F,$50,$E1,$7F ; Entries 0D-0F of screen address table (bank $7F): screen n = layer 1 horizontal, $C800 + n * $1B0 (3 bytes: low, high, bank)
;;; $BD2A..BD52: Table: screen addresses, layer 2 vertical bank $7F ;;;
;; 24-bit address of the Map16 data of each screen (high byte / page table, same offsets). Horizontal screens
;; are $1B0 bytes (16x27 blocks), vertical $0200 (16x32).
$00:BD2A .db $00,$E4,$7F,$00,$E6,$7F,$00,$E8 ; Entries 00-02 of screen address table (bank $7F): screen n = layer 2 vertical, $E400 + n * $200 (3 bytes: low, high, bank)
$00:BD32 .db $7F,$00,$EA,$7F,$00,$EC,$7F,$00 ; Entries 02-05 of screen address table (bank $7F): screen n = layer 2 vertical, $E400 + n * $200 (3 bytes: low, high, bank)
$00:BD3A .db $EE,$7F,$00,$F0,$7F,$00,$F2,$7F ; Entries 05-07 of screen address table (bank $7F): screen n = layer 2 vertical, $E400 + n * $200 (3 bytes: low, high, bank)
$00:BD42 .db $00,$F4,$7F,$00,$F6,$7F,$00,$F8 ; Entries 08-0A of screen address table (bank $7F): screen n = layer 2 vertical, $E400 + n * $200 (3 bytes: low, high, bank)
$00:BD4A .db $7F,$00,$FA,$7F,$00,$FC,$7F,$00 ; Entries 0A-0D of screen address table (bank $7F): screen n = layer 2 vertical, $E400 + n * $200 (3 bytes: low, high, bank)
$00:BD52 .db $FE,$7F ; Entries 0D-0D of screen address table (bank $7F): screen n = layer 2 vertical, $E400 + n * $200 (3 bytes: low, high, bank)
;;; $BD54..BD7C: Table: screen addresses, layer 1 vertical bank $7F ;;;
;; 24-bit address of the Map16 data of each screen (high byte / page table, same offsets). Horizontal screens
;; are $1B0 bytes (16x27 blocks), vertical $0200 (16x32).
$00:BD54 .db $00,$C8,$7F,$00,$CA,$7F,$00,$CC ; Entries 00-02 of screen address table (bank $7F): screen n = layer 1 vertical, $C800 + n * $200 (3 bytes: low, high, bank)
$00:BD5C .db $7F,$00,$CE,$7F,$00,$D0,$7F,$00 ; Entries 02-05 of screen address table (bank $7F): screen n = layer 1 vertical, $C800 + n * $200 (3 bytes: low, high, bank)
$00:BD64 .db $D2,$7F,$00,$D4,$7F,$00,$D6,$7F ; Entries 05-07 of screen address table (bank $7F): screen n = layer 1 vertical, $C800 + n * $200 (3 bytes: low, high, bank)
$00:BD6C .db $00,$D8,$7F,$00,$DA,$7F,$00,$DC ; Entries 08-0A of screen address table (bank $7F): screen n = layer 1 vertical, $C800 + n * $200 (3 bytes: low, high, bank)
$00:BD74 .db $7F,$00,$DE,$7F,$00,$E0,$7F,$00 ; Entries 0A-0D of screen address table (bank $7F): screen n = layer 1 vertical, $C800 + n * $200 (3 bytes: low, high, bank)
$00:BD7C .db $E2,$7F ; Entries 0D-0D of screen address table (bank $7F): screen n = layer 1 vertical, $C800 + n * $200 (3 bytes: low, high, bank)
;;; $BD7E..BDA6: Table: screen addresses, layer 2 vertical bank $7F ;;;
;; 24-bit address of the Map16 data of each screen (high byte / page table, same offsets). Horizontal screens
;; are $1B0 bytes (16x27 blocks), vertical $0200 (16x32).
$00:BD7E .db $00,$E4,$7F,$00,$E6,$7F,$00,$E8 ; Entries 00-02 of screen address table (bank $7F): screen n = layer 2 vertical, $E400 + n * $200 (3 bytes: low, high, bank)
$00:BD86 .db $7F,$00,$EA,$7F,$00,$EC,$7F,$00 ; Entries 02-05 of screen address table (bank $7F): screen n = layer 2 vertical, $E400 + n * $200 (3 bytes: low, high, bank)
$00:BD8E .db $EE,$7F,$00,$F0,$7F,$00,$F2,$7F ; Entries 05-07 of screen address table (bank $7F): screen n = layer 2 vertical, $E400 + n * $200 (3 bytes: low, high, bank)
$00:BD96 .db $00,$F4,$7F,$00,$F6,$7F,$00,$F8 ; Entries 08-0A of screen address table (bank $7F): screen n = layer 2 vertical, $E400 + n * $200 (3 bytes: low, high, bank)
$00:BD9E .db $7F,$00,$FA,$7F,$00,$FC,$7F,$00 ; Entries 0A-0D of screen address table (bank $7F): screen n = layer 2 vertical, $E400 + n * $200 (3 bytes: low, high, bank)
$00:BDA6 .db $FE,$7F ; Entries 0D-0D of screen address table (bank $7F): screen n = layer 2 vertical, $E400 + n * $200 (3 bytes: low, high, bank)
;;; $BDA8: Pointer table: layer 1 screens, bank $7E (Ptrs00BDA8) ;;;
;; Indexed by level mode [$1925] * 2: points to the screen address table for layer 1 (bank $7E Map16 low
;; bytes). 0 = mode not used.
$00:BDA8 D8 BA .dw $BAD8 ; Level mode $00: layer 1 horizontal (bank $7E)
$00:BDAA D8 BA .dw $BAD8 ; Level mode $01: layer 1 horizontal (bank $7E)
$00:BDAC D8 BA .dw $BAD8 ; Level mode $02: layer 1 horizontal (bank $7E)
$00:BDAE 38 BB .dw $BB38 ; Level mode $03: layer 1 vertical (bank $7E)
$00:BDB0 38 BB .dw $BB38 ; Level mode $04: layer 1 vertical (bank $7E)
$00:BDB2 92 BB .dw $BB92 ; Level mode $05: layer 1 horizontal (bank $7E)
$00:BDB4 92 BB .dw $BB92 ; Level mode $06: layer 1 horizontal (bank $7E)
$00:BDB6 EC BB .dw $BBEC ; Level mode $07: layer 1 vertical (bank $7E)
$00:BDB8 EC BB .dw $BBEC ; Level mode $08: layer 1 vertical (bank $7E)
$00:BDBA 00 00 .dw $0000 ; Level mode $09: not used
$00:BDBC EC BB .dw $BBEC ; Level mode $0A: layer 1 vertical (bank $7E)
$00:BDBE 00 00 .dw $0000 ; Level mode $0B: not used
$00:BDC0 D8 BA .dw $BAD8 ; Level mode $0C: layer 1 horizontal (bank $7E)
$00:BDC2 EC BB .dw $BBEC ; Level mode $0D: layer 1 vertical (bank $7E)
$00:BDC4 D8 BA .dw $BAD8 ; Level mode $0E: layer 1 horizontal (bank $7E)
$00:BDC6 D8 BA .dw $BAD8 ; Level mode $0F: layer 1 horizontal (bank $7E)
$00:BDC8 00 00 .dw $0000 ; Level mode $10: not used
$00:BDCA D8 BA .dw $BAD8 ; Level mode $11: layer 1 horizontal (bank $7E)
$00:BDCC 00 00 .dw $0000 ; Level mode $12: not used
$00:BDCE 00 00 .dw $0000 ; Level mode $13: not used
$00:BDD0 00 00 .dw $0000 ; Level mode $14: not used
$00:BDD2 00 00 .dw $0000 ; Level mode $15: not used
$00:BDD4 00 00 .dw $0000 ; Level mode $16: not used
$00:BDD6 00 00 .dw $0000 ; Level mode $17: not used
$00:BDD8 00 00 .dw $0000 ; Level mode $18: not used
$00:BDDA 00 00 .dw $0000 ; Level mode $19: not used
$00:BDDC 00 00 .dw $0000 ; Level mode $1A: not used
$00:BDDE 00 00 .dw $0000 ; Level mode $1B: not used
$00:BDE0 00 00 .dw $0000 ; Level mode $1C: not used
$00:BDE2 00 00 .dw $0000 ; Level mode $1D: not used
$00:BDE4 D8 BA .dw $BAD8 ; Level mode $1E: layer 1 horizontal (bank $7E)
$00:BDE6 D8 BA .dw $BAD8 ; Level mode $1F: layer 1 horizontal (bank $7E)
;;; $BDE8: Pointer table: layer 2 screens, bank $7E (Ptrs00BDE8) ;;;
;; Same as Ptrs00BDA8 for layer 2.
$00:BDE8 08 BB .dw $BB08 ; Level mode $00: layer 2 horizontal (bank $7E)
$00:BDEA 08 BB .dw $BB08 ; Level mode $01: layer 2 horizontal (bank $7E)
$00:BDEC 08 BB .dw $BB08 ; Level mode $02: layer 2 horizontal (bank $7E)
$00:BDEE 62 BB .dw $BB62 ; Level mode $03: layer 2 horizontal (bank $7E)
$00:BDF0 62 BB .dw $BB62 ; Level mode $04: layer 2 horizontal (bank $7E)
$00:BDF2 C2 BB .dw $BBC2 ; Level mode $05: layer 2 vertical (bank $7E)
$00:BDF4 C2 BB .dw $BBC2 ; Level mode $06: layer 2 vertical (bank $7E)
$00:BDF6 16 BC .dw $BC16 ; Level mode $07: layer 2 vertical (bank $7E)
$00:BDF8 16 BC .dw $BC16 ; Level mode $08: layer 2 vertical (bank $7E)
$00:BDFA 00 00 .dw $0000 ; Level mode $09: not used
$00:BDFC 16 BC .dw $BC16 ; Level mode $0A: layer 2 vertical (bank $7E)
$00:BDFE 00 00 .dw $0000 ; Level mode $0B: not used
$00:BE00 08 BB .dw $BB08 ; Level mode $0C: layer 2 horizontal (bank $7E)
$00:BE02 16 BC .dw $BC16 ; Level mode $0D: layer 2 vertical (bank $7E)
$00:BE04 08 BB .dw $BB08 ; Level mode $0E: layer 2 horizontal (bank $7E)
$00:BE06 08 BB .dw $BB08 ; Level mode $0F: layer 2 horizontal (bank $7E)
$00:BE08 00 00 .dw $0000 ; Level mode $10: not used
$00:BE0A 08 BB .dw $BB08 ; Level mode $11: layer 2 horizontal (bank $7E)
$00:BE0C 00 00 .dw $0000 ; Level mode $12: not used
$00:BE0E 00 00 .dw $0000 ; Level mode $13: not used
$00:BE10 00 00 .dw $0000 ; Level mode $14: not used
$00:BE12 00 00 .dw $0000 ; Level mode $15: not used
$00:BE14 00 00 .dw $0000 ; Level mode $16: not used
$00:BE16 00 00 .dw $0000 ; Level mode $17: not used
$00:BE18 00 00 .dw $0000 ; Level mode $18: not used
$00:BE1A 00 00 .dw $0000 ; Level mode $19: not used
$00:BE1C 00 00 .dw $0000 ; Level mode $1A: not used
$00:BE1E 00 00 .dw $0000 ; Level mode $1B: not used
$00:BE20 00 00 .dw $0000 ; Level mode $1C: not used
$00:BE22 00 00 .dw $0000 ; Level mode $1D: not used
$00:BE24 08 BB .dw $BB08 ; Level mode $1E: layer 2 horizontal (bank $7E)
$00:BE26 08 BB .dw $BB08 ; Level mode $1F: layer 2 horizontal (bank $7E)
;;; $BE28: Pointer table: layer 1 screens, bank $7F (Ptrs00BE28) ;;;
;; Same as Ptrs00BDA8 for the bank $7F (Map16 high byte / page) data of layer 1.
$00:BE28 40 BC .dw $BC40 ; Level mode $00: layer 1 horizontal (bank $7F)
$00:BE2A 40 BC .dw $BC40 ; Level mode $01: layer 1 horizontal (bank $7F)
$00:BE2C 40 BC .dw $BC40 ; Level mode $02: layer 1 horizontal (bank $7F)
$00:BE2E A0 BC .dw $BCA0 ; Level mode $03: layer 1 vertical (bank $7F)
$00:BE30 A0 BC .dw $BCA0 ; Level mode $04: layer 1 vertical (bank $7F)
$00:BE32 FA BC .dw $BCFA ; Level mode $05: layer 1 horizontal (bank $7F)
$00:BE34 FA BC .dw $BCFA ; Level mode $06: layer 1 horizontal (bank $7F)
$00:BE36 54 BD .dw $BD54 ; Level mode $07: layer 1 vertical (bank $7F)
$00:BE38 54 BD .dw $BD54 ; Level mode $08: layer 1 vertical (bank $7F)
$00:BE3A 00 00 .dw $0000 ; Level mode $09: not used
$00:BE3C 54 BD .dw $BD54 ; Level mode $0A: layer 1 vertical (bank $7F)
$00:BE3E 00 00 .dw $0000 ; Level mode $0B: not used
$00:BE40 40 BC .dw $BC40 ; Level mode $0C: layer 1 horizontal (bank $7F)
$00:BE42 54 BD .dw $BD54 ; Level mode $0D: layer 1 vertical (bank $7F)
$00:BE44 40 BC .dw $BC40 ; Level mode $0E: layer 1 horizontal (bank $7F)
$00:BE46 40 BC .dw $BC40 ; Level mode $0F: layer 1 horizontal (bank $7F)
$00:BE48 00 00 .dw $0000 ; Level mode $10: not used
$00:BE4A 40 BC .dw $BC40 ; Level mode $11: layer 1 horizontal (bank $7F)
$00:BE4C 00 00 .dw $0000 ; Level mode $12: not used
$00:BE4E 00 00 .dw $0000 ; Level mode $13: not used
$00:BE50 00 00 .dw $0000 ; Level mode $14: not used
$00:BE52 00 00 .dw $0000 ; Level mode $15: not used
$00:BE54 00 00 .dw $0000 ; Level mode $16: not used
$00:BE56 00 00 .dw $0000 ; Level mode $17: not used
$00:BE58 00 00 .dw $0000 ; Level mode $18: not used
$00:BE5A 00 00 .dw $0000 ; Level mode $19: not used
$00:BE5C 00 00 .dw $0000 ; Level mode $1A: not used
$00:BE5E 00 00 .dw $0000 ; Level mode $1B: not used
$00:BE60 00 00 .dw $0000 ; Level mode $1C: not used
$00:BE62 00 00 .dw $0000 ; Level mode $1D: not used
$00:BE64 40 BC .dw $BC40 ; Level mode $1E: layer 1 horizontal (bank $7F)
$00:BE66 40 BC .dw $BC40 ; Level mode $1F: layer 1 horizontal (bank $7F)
;;; $BE68: Pointer table: layer 2 screens, bank $7F (Ptrs00BE68) ;;;
;; Same as Ptrs00BDA8 for the bank $7F data of layer 2.
$00:BE68 70 BC .dw $BC70 ; Level mode $00: layer 2 horizontal (bank $7F)
$00:BE6A 70 BC .dw $BC70 ; Level mode $01: layer 2 horizontal (bank $7F)
$00:BE6C 70 BC .dw $BC70 ; Level mode $02: layer 2 horizontal (bank $7F)
$00:BE6E CA BC .dw $BCCA ; Level mode $03: layer 2 horizontal (bank $7F)
$00:BE70 CA BC .dw $BCCA ; Level mode $04: layer 2 horizontal (bank $7F)
$00:BE72 2A BD .dw $BD2A ; Level mode $05: layer 2 vertical (bank $7F)
$00:BE74 2A BD .dw $BD2A ; Level mode $06: layer 2 vertical (bank $7F)
$00:BE76 7E BD .dw $BD7E ; Level mode $07: layer 2 vertical (bank $7F)
$00:BE78 7E BD .dw $BD7E ; Level mode $08: layer 2 vertical (bank $7F)
$00:BE7A 00 00 .dw $0000 ; Level mode $09: not used
$00:BE7C 7E BD .dw $BD7E ; Level mode $0A: layer 2 vertical (bank $7F)
$00:BE7E 00 00 .dw $0000 ; Level mode $0B: not used
$00:BE80 70 BC .dw $BC70 ; Level mode $0C: layer 2 horizontal (bank $7F)
$00:BE82 7E BD .dw $BD7E ; Level mode $0D: layer 2 vertical (bank $7F)
$00:BE84 70 BC .dw $BC70 ; Level mode $0E: layer 2 horizontal (bank $7F)
$00:BE86 70 BC .dw $BC70 ; Level mode $0F: layer 2 horizontal (bank $7F)
$00:BE88 00 00 .dw $0000 ; Level mode $10: not used
$00:BE8A 70 BC .dw $BC70 ; Level mode $11: layer 2 horizontal (bank $7F)
$00:BE8C 00 00 .dw $0000 ; Level mode $12: not used
$00:BE8E 00 00 .dw $0000 ; Level mode $13: not used
$00:BE90 00 00 .dw $0000 ; Level mode $14: not used
$00:BE92 00 00 .dw $0000 ; Level mode $15: not used
$00:BE94 00 00 .dw $0000 ; Level mode $16: not used
$00:BE96 00 00 .dw $0000 ; Level mode $17: not used
$00:BE98 00 00 .dw $0000 ; Level mode $18: not used
$00:BE9A 00 00 .dw $0000 ; Level mode $19: not used
$00:BE9C 00 00 .dw $0000 ; Level mode $1A: not used
$00:BE9E 00 00 .dw $0000 ; Level mode $1B: not used
$00:BEA0 00 00 .dw $0000 ; Level mode $1C: not used
$00:BEA2 00 00 .dw $0000 ; Level mode $1D: not used
$00:BEA4 70 BC .dw $BC70 ; Level mode $1E: layer 2 horizontal (bank $7F)
$00:BEA6 70 BC .dw $BC70 ; Level mode $1F: layer 2 horizontal (bank $7F)
;;; $BEA8: Pointer table: layer pointer tables, bank $7E (LoadBlkPtrs) ;;;
;; Indexed by layer * 2: Ptrs00BDA8 (layer 1), Ptrs00BDE8 (layer 2).
$00:BEA8 A8 BD .dw Ptrs00BDA8 ; Layer 1: pointer table for bank $7E screens (Ptrs00BDA8)
$00:BEAA E8 BD .dw Ptrs00BDE8 ; Layer 2: pointer table for bank $7E screens (Ptrs00BDE8)
;;; $BEAC: Pointer table: layer pointer tables, bank $7F (LoadBlkTable2) ;;;
;; Indexed by layer * 2: Ptrs00BE28 (layer 1), Ptrs00BE68 (layer 2). Used by the level loader in bank 05.
$00:BEAC 28 BE .dw Ptrs00BE28 ; Layer 1: pointer table for bank $7F screens (Ptrs00BE28)
$00:BEAE 68 BE .dw Ptrs00BE68 ; Layer 2: pointer table for bank $7F screens (Ptrs00BE68)
;;; $BEB0: Generate Map16 tile at block position (GenerateTile) ;;;
;; Called with JSL to turn a block into another tile (e.g. a hit block becoming a used block, or a vine/coin
;; spot). Parameters: [$9C]: block to generate (0 = none),
;; [$98]/[$99] block Y, [$9A]/[$9B] block X, [$1933] layer. Finds the Map16 buffer of the screen, computes the
;; VRAM position in $04-$07 and the reference
;; scroll position in $08/$0A, then dispatches through TileGenerationPtr with A = block - 1. Does nothing if
;; the position is outside the level ($0200+).
;; Quirk: PHK/PER builds a fake JSL return address so ExecutePtr reads TileGenerationPtr as its table.
;; Called by:
;; $00:F25C: Block interaction: hurt tiles, bounce blocks, coins
;; $00:F285: Block interaction: hurt tiles, bounce blocks, coins
;; $00:F2D1: Block interaction: hurt tiles, bounce blocks, coins
;; $00:F36F: Block interaction: hurt tiles, bounce blocks, coins
;; $01:BCB5: Spawn sprite from the magic (StoreSpriteNum)
;; $01:C1E9: Growing vine (GrowingVine)
;; $01:E33F: Monty Mole states and routines (Ptrs01E2D8)
;; $02:8784: Break turn block (BreakTurnBlock)
;; $02:87E8: Find bounce sprite slot (FindTurningBlkSlot)
;; $02:91E8: Generate block at bounce sprite position (TileFromBounceSpr1)
;; $02:B9B8: Block and sprite helpers: berries and silver coins (GenTileFromSpr0)
;; $02:BB06: Block and sprite helpers: berries and silver coins (GenTileFromSpr0)
;; ... and 10 more
$00:BEB0 08 PHP ; Save flags
$00:BEB1 C2 30 REP #$30 ; A, X and Y 16-bit
$00:BEB3 DA PHX ; Save X
$00:BEB4 A5 9C LDA RAM_BlockBlock ; \
$00:BEB6 29 FF 00 AND.W #$00FF ; } Block to generate [$9C] = 0: nothing to do, exit
$00:BEB9 D0 03 BNE $BEBE ; /
$00:BEBB 4C B9 BF JMP.W $BFB9 ; Exit
$00:BEBE A5 9A LDA RAM_BlockXLo ; A = block X position
$00:BEC0 85 0C STA $0C ; $0C = X position
$00:BEC2 A5 98 LDA RAM_BlockYLo ; A = block Y position
$00:BEC4 85 0E STA $0E ; $0E = Y position
$00:BEC6 A9 00 00 LDA.W #$0000 ; A = 0 (clears the high byte)
$00:BEC9 E2 20 SEP #$20 ; A 8-bit
$00:BECB A5 5B LDA RAM_IsVerticalLvl ; \
$00:BECD 85 09 STA $09 ; / $09 = vertical level flags ($5B)
$00:BECF AD 33 19 LDA.W $1933 ; \
$00:BED2 F0 02 BEQ $BED6 ; / Layer 1: keep bit 0; layer 2 ([$1933] != 0): use bit 1 instead
$00:BED4 46 09 LSR $09 ; $09 >>= 1
$00:BED6 A4 0E LDY $0E ; Y = Y position (horizontal level: position across the level)
$00:BED8 A5 09 LDA $09 ; \
$00:BEDA 29 01 AND.B #$01 ; } Horizontal layer: go to $00BEEC
$00:BEDC F0 0E BEQ $BEEC ; /
$00:BEDE A5 9B LDA RAM_BlockXHi ; \
$00:BEE0 85 00 STA $00 ; |
$00:BEE2 A5 99 LDA RAM_BlockYHi ; |
$00:BEE4 85 9B STA RAM_BlockXHi ; |
$00:BEE6 A5 00 LDA $00 ; } Vertical layer: swap the X and Y high bytes
$00:BEE8 85 99 STA RAM_BlockYHi ; /
$00:BEEA A4 0C LDY $0C ; Y = X position (the coordinate across a vertical level)
$00:BEEC C0 00 02 CPY.W #$0200 ; \
$00:BEEF B0 CA BCS $BEBB ; / Coordinate across the level >= $0200: outside the level, exit
$00:BEF1 AD 33 19 LDA.W $1933 ; \
$00:BEF4 0A ASL ; } X = [$1933] * 2 (layer index)
$00:BEF5 AA TAX ; /
$00:BEF6 BF A8 BE 00 LDA.L LoadBlkPtrs,X ; \
$00:BEFA 85 65 STA $65 ; / $65 = low byte of pointer from LoadBlkPtrs[layer]
$00:BEFC BF A9 BE 00 LDA.L LoadBlkPtrs+1,X ; \
$00:BF00 85 66 STA $66 ; / $66 = high byte of that pointer
$00:BF02 64 67 STZ $67 ; $67 = 0: bank $00
$00:BF04 AD 25 19 LDA.W $1925 ; \
$00:BF07 0A ASL ; } Y = level mode [$1925] * 2
$00:BF08 A8 TAY ; /
$00:BF09 B7 65 LDA [$65],Y ; \
$00:BF0B 85 04 STA $04 ; / $04 = low byte of the screen table address for this mode
$00:BF0D C8 INY ; Y++
$00:BF0E B7 65 LDA [$65],Y ; \
$00:BF10 85 05 STA $05 ; / $05 = high byte of the screen table address
$00:BF12 64 06 STZ $06 ; $06 = 0: bank $00
$00:BF14 A5 9B LDA RAM_BlockXHi ; \
$00:BF16 85 07 STA $07 ; / $07 = block X high byte (screen number)
$00:BF18 0A ASL ; \
$00:BF19 18 CLC ; } A = screen number * 3 (3-byte entries)
$00:BF1A 65 07 ADC $07 ; /
$00:BF1C A8 TAY ; Y = offset into the screen table
$00:BF1D B7 04 LDA [$04],Y ; \
$00:BF1F 85 6B STA $6B ; } $6B/$6E = low byte of this screen's Map16 address
$00:BF21 85 6E STA $6E ; /
$00:BF23 C8 INY ; Y++
$00:BF24 B7 04 LDA [$04],Y ; \
$00:BF26 85 6C STA $6C ; } $6C/$6F = high byte of this screen's Map16 address
$00:BF28 85 6F STA $6F ; /
$00:BF2A A9 7E LDA.B #$7E ; \
$00:BF2C 85 6D STA $6D ; / $6D = $7E: $6B-$6D points at the Map16 low byte
$00:BF2E 1A INC A ; \
$00:BF2F 85 70 STA $70 ; / $70 = $7F: $6E-$70 points at the Map16 high byte (page) table
$00:BF31 A5 09 LDA $09 ; \
$00:BF33 29 01 AND.B #$01 ; } Horizontal layer: go to $00BF41
$00:BF35 F0 0A BEQ $BF41 ; /
$00:BF37 A5 99 LDA RAM_BlockYHi ; \
$00:BF39 4A LSR ; / Vertical layer: carry = bit 0 of block Y high byte
$00:BF3A A5 9B LDA RAM_BlockXHi ; \
$00:BF3C 29 01 AND.B #$01 ; / A = bit 0 of block X high byte
$00:BF3E 4C 46 BF JMP.W $BF46 ; Go to $00BF46
$00:BF41 A5 9B LDA RAM_BlockXHi ; \
$00:BF43 4A LSR ; / Horizontal layer: carry = bit 0 of block X high byte
$00:BF44 A5 99 LDA RAM_BlockYHi ; A = block Y high byte
$00:BF46 2A ROL ; \
$00:BF47 0A ASL ; } A = (two screen page bits) * 4
$00:BF48 0A ASL ; /
$00:BF49 09 20 ORA.B #$20 ; Add $20: base of the VRAM tilemap high byte (probably BG1 at $2000)
$00:BF4B 85 04 STA $04 ; $04 = tilemap page
$00:BF4D E0 00 00 CPX.W #$0000 ; \
$00:BF50 F0 05 BEQ $BF57 ; / Layer 1 (X = 0): keep $20
$00:BF52 18 CLC ; \
$00:BF53 69 10 ADC.B #$10 ; } Layer 2: add $10 to the page
$00:BF55 85 04 STA $04 ; /
$00:BF57 A5 98 LDA RAM_BlockYLo ; \
$00:BF59 29 F0 AND.B #$F0 ; |
$00:BF5B 18 CLC ; |
$00:BF5C 0A ASL ; } A = (block Y & $F0) * 4: tilemap row offset (64 words per 16 pixel row)
$00:BF5D 2A ROL ; /
$00:BF5E 85 05 STA $05 ; $05 = row offset low part
$00:BF60 2A ROL ; \
$00:BF61 29 03 AND.B #$03 ; } A = row offset overflow bits | page
$00:BF63 05 04 ORA $04 ; /
$00:BF65 85 06 STA $06 ; $06 = VRAM address high byte of the tile
$00:BF67 A5 9A LDA RAM_BlockXLo ; \
$00:BF69 29 F0 AND.B #$F0 ; |
$00:BF6B 4A LSR ; |
$00:BF6C 4A LSR ; } A = (block X & $F0) / 8: column offset in words
$00:BF6D 4A LSR ; /
$00:BF6E 85 04 STA $04 ; $04 = column offset
$00:BF70 A5 05 LDA $05 ; \
$00:BF72 29 C0 AND.B #$C0 ; } Combine with the row bits
$00:BF74 05 04 ORA $04 ; /
$00:BF76 85 07 STA $07 ; $07 = VRAM address low byte of the tile
$00:BF78 C2 20 REP #$20 ; A 16-bit
$00:BF7A A5 09 LDA $09 ; \
$00:BF7C 29 01 00 AND.W #$0001 ; } Vertical layer: go to $00BF9B
$00:BF7F D0 1A BNE $BF9B ; /
$00:BF81 A5 1A LDA RAM_ScreenBndryXLo ; \
$00:BF83 38 SEC ; |
$00:BF84 E9 80 00 SBC.W #$0080 ; } X = layer 1 screen boundary X - $80
$00:BF87 AA TAX ; /
$00:BF88 A4 1C LDY RAM_ScreenBndryYLo ; Y = layer 1 screen boundary Y
$00:BF8A AD 33 19 LDA.W $1933 ; \
$00:BF8D F0 23 BEQ $BFB2 ; / Layer 1: go to $00BFB2
$00:BF8F A6 1E LDX $1E ; Layer 2: X = layer 2 scroll X
$00:BF91 A5 20 LDA $20 ; \
$00:BF93 38 SEC ; |
$00:BF94 E9 80 00 SBC.W #$0080 ; } Y = layer 2 scroll Y - $80
$00:BF97 A8 TAY ; /
$00:BF98 4C B2 BF JMP.W $BFB2 ; Go to $00BFB2
$00:BF9B A6 1A LDX RAM_ScreenBndryXLo ; Vertical layer 1: X = screen boundary X
$00:BF9D A5 1C LDA RAM_ScreenBndryYLo ; \
$00:BF9F 38 SEC ; |
$00:BFA0 E9 80 00 SBC.W #$0080 ; } Y = screen boundary Y - $80
$00:BFA3 A8 TAY ; /
$00:BFA4 AD 33 19 LDA.W $1933 ; \
$00:BFA7 F0 09 BEQ $BFB2 ; / Layer 1: go to $00BFB2
$00:BFA9 A5 1E LDA $1E ; \
$00:BFAB 38 SEC ; |
$00:BFAC E9 80 00 SBC.W #$0080 ; } Layer 2: X = layer 2 scroll X - $80
$00:BFAF AA TAX ; /
$00:BFB0 A4 20 LDY $20 ; Y = layer 2 scroll Y
$00:BFB2 86 08 STX $08 ; $08 = reference X position
$00:BFB4 84 0A STY $0A ; $0A = reference Y position
$00:BFB6 20 BC BF JSR.W $BFBC ; Run the handler for this block ($BFBC)
$00:BFB9 FA PLX ; Restore X
$00:BFBA 28 PLP ; Restore flags
$00:BFBB 6B RTL ; Return long
$00:BFBC E2 30 SEP #$30 ; A and index 8-bit
$00:BFBE A5 9C LDA RAM_BlockBlock ; \
$00:BFC0 3A DEC A ; / A = block number - 1: index into TileGenerationPtr
$00:BFC1 4B PHK ; \
$00:BFC2 62 03 00 PER $0003 ; / Push a fake JSL return address so the pointer table follows (at TileGenerationPtr)
$00:BFC5 5C DF 86 00 JMP.L ExecutePtr ; Jump to the handler selected by A (ExecutePtr)
;;; $BFC9: Pointer table: tile generation handlers (TileGenerationPtr) ;;;
;; Indexed by block number - 1 ($01-$1B). Handlers $C074/00C077/00C0C4/00C0C1/00C1AC/00C334/00C3D1 place
;; the new tile and queue its drawing.
$00:BFC9 74 C0 .dw $C074 ; Block $01: empty space (flags the spot in $19F8 first)
$00:BFCB 77 C0 .dw $C077 ; Block $02: empty space
$00:BFCD 77 C0 .dw $C077 ; Block $03: vine
$00:BFCF 77 C0 .dw $C077 ; Block $04: tree background (for berries)
$00:BFD1 77 C0 .dw $C077 ; Block $05: always turning block
$00:BFD3 77 C0 .dw $C077 ; Block $06: coin
$00:BFD5 77 C0 .dw $C077 ; Block $07: mushroom scale base
$00:BFD7 77 C0 .dw $C077 ; Block $08: mole hole
$00:BFD9 C4 C0 .dw $C0C4 ; Block $09: invisible solid block
$00:BFDB C4 C0 .dw $C0C4 ; Block $0A: multiple coin turn block
$00:BFDD C4 C0 .dw $C0C4 ; Block $0B: multiple coin ? block
$00:BFDF C4 C0 .dw $C0C4 ; Block $0C: turn block
$00:BFE1 C4 C0 .dw $C0C4 ; Block $0D: used block
$00:BFE3 C4 C0 .dw $C0C4 ; Block $0E: music block
$00:BFE5 C4 C0 .dw $C0C4 ; Block $0F: music block variant
$00:BFE7 C4 C0 .dw $C0C4 ; Block $10: all-way music block
$00:BFE9 C4 C0 .dw $C0C4 ; Block $11: sideways turn block
$00:BFEB C4 C0 .dw $C0C4 ; Block $12: translucent block
$00:BFED C4 C0 .dw $C0C4 ; Block $13: ON/OFF block
$00:BFEF C4 C0 .dw $C0C4 ; Block $14: side of pipe, left
$00:BFF1 C4 C0 .dw $C0C4 ; Block $15: side of pipe, right
$00:BFF3 C1 C0 .dw $C0C1 ; Block $16: used block variant
$00:BFF5 C1 C0 .dw $C0C1 ; Block $17: O block from the 1-up game
$00:BFF7 AC C1 .dw $C1AC ; Block $18: invisible block containing wings
$00:BFF9 34 C3 .dw $C334 ; Block $19: cage
$00:BFFB 34 C3 .dw $C334 ; Block $1A: cage
$00:BFFD D1 C3 .dw $C3D1 ; Block $1B: purpose unknown
$00:BFFF .db $00,$00,$80,$00,$00,$01 ; Words $0000, $0080, $0100: offsets into the $19F8 table, indexed by [$13BE] & $0F
$00:C005 .db $80,$40,$20,$10,$08,$04,$02,$01 ; Bit masks, bit 7 first: bit for the column within a 128 pixel span
$00:C00D C2 30 REP #$30 ; A, X and Y 16-bit
$00:C00F A5 9A LDA RAM_BlockXLo ; \
$00:C011 29 00 FF AND.W #$FF00 ; |
$00:C014 4A LSR ; |
$00:C015 4A LSR ; |
$00:C016 4A LSR ; |
$00:C017 4A LSR ; |
$00:C018 4A LSR ; |
$00:C019 4A LSR ; } $04 = (block X & $FF00) / 64: screen number * 4
$00:C01A 85 04 STA $04 ; /
$00:C01C A5 9A LDA RAM_BlockXLo ; \
$00:C01E 29 80 00 AND.W #$0080 ; |
$00:C021 4A LSR ; |
$00:C022 4A LSR ; |
$00:C023 4A LSR ; |
$00:C024 4A LSR ; |
$00:C025 4A LSR ; |
$00:C026 4A LSR ; |
$00:C027 4A LSR ; |
$00:C028 05 04 ORA $04 ; } $04 |= (block X & $80) / 128: left or right half of the screen
$00:C02A 85 04 STA $04 ; /
$00:C02C A5 98 LDA RAM_BlockYLo ; \
$00:C02E 29 00 01 AND.W #$0100 ; } Block Y bit 8 set?
$00:C031 F0 07 BEQ $C03A ; /
$00:C033 A5 04 LDA $04 ; \
$00:C035 09 02 00 ORA.W #$0002 ; } $04 |= 2: lower half of the level
$00:C038 85 04 STA $04 ; /
$00:C03A AD BE 13 LDA.W $13BE ; \
$00:C03D 29 0F 00 AND.W #$000F ; |
$00:C040 0A ASL ; } X = ([$13BE] & $0F) * 2
$00:C041 AA TAX ; /
$00:C042 BF FF BF 00 LDA.L $BFFF,X ; \
$00:C046 18 CLC ; |
$00:C047 65 04 ADC $04 ; } $04 += word from $BFFF
$00:C049 85 04 STA $04 ; /
$00:C04B A8 TAY ; Y = byte index into the $19F8 bit table
$00:C04C A5 9A LDA RAM_BlockXLo ; \
$00:C04E 29 70 00 AND.W #$0070 ; |
$00:C051 4A LSR ; |
$00:C052 4A LSR ; |
$00:C053 4A LSR ; |
$00:C054 4A LSR ; } X = (block X & $70) / 16: column within the 128 pixel span
$00:C055 AA TAX ; /
$00:C056 E2 20 SEP #$20 ; A 8-bit
$00:C058 B9 F8 19 LDA.W $19F8,Y ; A = current bits
$00:C05B 1F 05 C0 00 ORA.L $C005,X ; Set the bit for this column ($C005)
$00:C05F 99 F8 19 STA.W $19F8,Y ; Store the bits back: marks this spot in the $19F8 table (probably "tile was changed")
$00:C062 60 RTS ; Return
;;; $C063..C063: Unused. Bit masks to clear one bit ;;;
$00:C063 .db $7F,$BF,$DF,$EF,$F7,$FB,$FD,$FE ; Unused: masks that clear one bit (inverse of $C005)
;;; $C06B: Table: Map16 tile per generated block, page 0 (TileToGeneratePg0) ;;;
;; Indexed by block number $00-$08: the Map16 tile ($25 empty, $06 vine, $49 tree background, $48, $2B coin,
;; $A2, $C6 mole hole).
;; Followed by $C074 (flags the spot in $19F8, then falls into) $C077: places the tile for blocks
;; $01-$08 and continues at $C0FB.
$00:C06B .db $25,$25,$25,$06,$49,$48,$2B,$A2 ; Map16 tile for block $00-$07: $25 empty, $25, $25, $06 vine, $49 tree bg, $48, $2B coin, $A2
$00:C073 .db $C6 ; Map16 tile for block $08: $C6 (mole hole)
$00:C074 20 0D C0 JSR.W $C00D ; Blocks $01: flag the spot in $19F8 ($C00D), then fall through
$00:C077 C2 30 REP #$30 ; A, X and Y 16-bit
$00:C079 A5 98 LDA RAM_BlockYLo ; \
$00:C07B 29 F0 01 AND.W #$01F0 ; } $04 = (block Y & $01F0): row offset in the Map16 screen (16 bytes per row)
$00:C07E 85 04 STA $04 ; /
$00:C080 A5 9A LDA RAM_BlockXLo ; \
$00:C082 4A LSR ; |
$00:C083 4A LSR ; |
$00:C084 4A LSR ; |
$00:C085 4A LSR ; |
$00:C086 29 0F 00 AND.W #$000F ; } A = (block X / 16) & $0F | row offset
$00:C089 05 04 ORA $04 ; /
$00:C08B A8 TAY ; Y = index of the tile within the screen's Map16 data
$00:C08C A5 9C LDA RAM_BlockBlock ; \
$00:C08E 29 FF 00 AND.W #$00FF ; } X = block number (index into TileToGeneratePg0)
$00:C091 AA TAX ; /
$00:C092 E2 20 SEP #$20 ; A 8-bit
$00:C094 B7 6E LDA [$6E],Y ; \
$00:C096 29 FE AND.B #$FE ; } Clear bit 0 of the Map16 high byte ($6E): use page 0
$00:C098 97 6E STA [$6E],Y ; /
$00:C09A BF 6B C0 00 LDA.L TileToGeneratePg0,X ; \
$00:C09E 97 6B STA [$6B],Y ; / Store the Map16 tile for this block at [$6B],Y
$00:C0A0 C2 20 REP #$20 ; \
$00:C0A2 29 FF 00 AND.W #$00FF ; |
$00:C0A5 0A ASL ; } Y = tile number * 2
$00:C0A6 A8 TAY ; /
$00:C0A7 4C FB C0 JMP.W $C0FB ; Continue at $C0FB (draws the tile)
;;; $C0AA..C0AA: Unused. Bit mask table (duplicate) ;;;
$00:C0AA .db $80,$40,$20,$10,$08,$04,$02,$01 ; Unused: duplicate of the bit mask table at $C005
;;; $C0B2: Generate Map16 tiles: page 1 and wings block (TileToGeneratePg1) ;;;
;; Block generation (tile generated by a sprite or block action, block number in [$9C]). The first routine
;; handles blocks $09-$17: it
;; looks up the Map16 tile number in the table, writes it into the level Map16 map at ([$6B]),Y / ([$6E],Y bit
;; 0 = page 1) and queues a
;; stripe image update for the 16x16 block when the block is inside the visible area ([$08]/[$0C] horizontal,
;; [$0A]/[$0E] vertical).
;; The tail at $00C0FB is shared with the page 0 routine. Records are appended to the buffer at $7F:837D
;; (write index $7F:837B).
;; $00C1AC: block $18 (invisible block containing wings): sets this block and the one below to Map16 tile $25
;; and queues vertical records.
$00:C0B2 .db $52,$1B,$23,$1E,$32,$13,$15,$16 ; Map16 tiles $152,$11B,$123,$11E,$132,$113,$115,$116 for blocks $09-$10 (page 1)
$00:C0BA .db $2B,$2C,$12,$68,$69,$32,$5E ; Map16 tiles $12B,$12C,$112,$168,$169,$132,$15E for blocks $11-$17 (page 1)
$00:C0C1 20 0D C0 JSR.W $C00D ; Mark the block in the generated-tile bitmap ($19F8) ($C00D)
$00:C0C4 C2 30 REP #$30 ; A, X and Y 16-bit
$00:C0C6 A5 98 LDA RAM_BlockYLo ; \
$00:C0C8 29 F0 01 AND.W #$01F0 ; |
$00:C0CB 85 04 STA $04 ; |
$00:C0CD A5 9A LDA RAM_BlockXLo ; |
$00:C0CF 4A LSR ; |
$00:C0D0 4A LSR ; |
$00:C0D1 4A LSR ; |
$00:C0D2 4A LSR ; |
$00:C0D3 29 0F 00 AND.W #$000F ; } $04 = (BlockY & $1F0) | ((BlockX >> 4) & $0F): block offset in the Map16 page
$00:C0D6 05 04 ORA $04 ; /
$00:C0D8 A8 TAY ; Y = offset of the block in the Map16 tables
$00:C0D9 A5 9C LDA RAM_BlockBlock ; \
$00:C0DB 38 SEC ; |
$00:C0DC E9 09 00 SBC.W #$0009 ; |
$00:C0DF 29 FF 00 AND.W #$00FF ; } X = [$9C] - 9: index into TileToGeneratePg1
$00:C0E2 AA TAX ; /
$00:C0E3 E2 20 SEP #$20 ; A 8-bit
$00:C0E5 B7 6E LDA [$6E],Y ; \
$00:C0E7 09 01 ORA.B #$01 ; } Set bit 0 of the Map16 high byte: tile is in page 1 ($100-$1FF)
$00:C0E9 97 6E STA [$6E],Y ; /
$00:C0EB BF B2 C0 00 LDA.L TileToGeneratePg1,X ; \
$00:C0EF 97 6B STA [$6B],Y ; / Map16 low byte = TileToGeneratePg1[X]
$00:C0F1 C2 20 REP #$20 ; A 16-bit
$00:C0F3 29 FF 00 AND.W #$00FF ; \
$00:C0F6 09 00 01 ORA.W #$0100 ; |
$00:C0F9 0A ASL ; } Y = ($100 | tile) * 2: index into the Map16 tile pointer table at $0FBE
$00:C0FA A8 TAY ; /
$00:C0FB A5 5B LDA RAM_IsVerticalLvl ; \
$00:C0FD 85 00 STA $00 ; } $00 = [$5B] (vertical level flags)
$00:C0FF AD 33 19 LDA.W $1933 ; /
$00:C102 F0 02 BEQ $C106 ; Layer 1 being processed: keep bit 0
$00:C104 46 00 LSR $00 ; Layer 2 ([$1933] != 0): use bit 1 (layer 2 vertical flag)
$00:C106 A5 00 LDA $00 ; A = vertical-level flag of the current layer
$00:C108 29 01 00 AND.W #$0001 ; Keep only bit 0
$00:C10B D0 1A BNE $C127 ; Vertical level: go to the vertical range check ($00C127)
$00:C10D A5 08 LDA $08 ; \
$00:C10F 29 F0 FF AND.W #$FFF0 ; / A = [$08] & $FFF0: left edge of the view minus $80, 16-pixel aligned
$00:C112 30 06 BMI $C11A ; Negative: skip the first compare
$00:C114 C5 0C CMP $0C ; Compare with [$0C] (block X position, set by the caller)
$00:C116 F0 26 BEQ $C13E ; Equal: block is at the left edge, draw it
$00:C118 B0 0A BCS $C124 ; Left edge > block: block is left of the view, skip
$00:C11A 18 CLC ; \
$00:C11B 69 00 02 ADC.W #$0200 ; / A += $200: right edge of the area that gets drawn
$00:C11E C5 0C CMP $0C ; Compare with [$0C]
$00:C120 F0 02 BEQ $C124 ; Equal: just past the right edge, skip
$00:C122 B0 1A BCS $C13E ; Block inside the window: build the VRAM update
$00:C124 4C AB C1 JMP.W $C1AB ; Off screen: return without a VRAM update
$00:C127 A5 0A LDA $0A ; \
$00:C129 29 F0 FF AND.W #$FFF0 ; / Same range check for vertical levels: A = [$0A] & $FFF0
$00:C12C 30 06 BMI $C134 ; Negative: skip the first compare
$00:C12E C5 0E CMP $0E ; Compare with [$0E] (block Y position, set by the caller)
$00:C130 F0 0C BEQ $C13E ; Equal: draw it
$00:C132 B0 77 BCS $C1AB ; View edge > block: skip
$00:C134 18 CLC ; \
$00:C135 69 00 02 ADC.W #$0200 ; / A += $200
$00:C138 C5 0E CMP $0E ; Compare with [$0E]
$00:C13A F0 6F BEQ $C1AB ; Equal: skip
$00:C13C 90 6D BCC $C1AB ; A < [$0E]: skip; otherwise fall into the VRAM update
$00:C13E AF 7B 83 7F LDA.L $7F837B ; \
$00:C142 AA TAX ; / X = write index into the stripe image buffer at $7F:837D
$00:C143 E2 20 SEP #$20 ; A 8-bit
$00:C145 A5 06 LDA $06 ; \
$00:C147 9F 7D 83 7F STA.L $7F837D,X ; } Records 1 and 2: VRAM address high = [$06]
$00:C14B 9F 85 83 7F STA.L $7F8385,X ; /
$00:C14F A5 07 LDA $07 ; \
$00:C151 9F 7E 83 7F STA.L $7F837E,X ; |
$00:C155 18 CLC ; |
$00:C156 69 20 ADC.B #$20 ; } Record address low: [$07] for record 1, [$07] + $20 (next tile row) for record 2
$00:C158 9F 86 83 7F STA.L $7F8386,X ; /
$00:C15C A9 00 LDA.B #$00 ; \
$00:C15E 9F 7F 83 7F STA.L $7F837F,X ; } Records 1 and 2: flags = 0 (horizontal, no RLE)
$00:C162 9F 87 83 7F STA.L $7F8387,X ; /
$00:C166 A9 03 LDA.B #$03 ; \
$00:C168 9F 80 83 7F STA.L $7F8380,X ; } Records 1 and 2: length $03 = 4 bytes (2 tiles) each
$00:C16C 9F 88 83 7F STA.L $7F8388,X ; /
$00:C170 A9 FF LDA.B #$FF ; \
$00:C172 9F 8D 83 7F STA.L $7F838D,X ; / End marker $FF after the second record
$00:C176 A9 0D LDA.B #$0D ; A = $0D: bank of the Map16 tile data
$00:C178 85 06 STA $06 ; [$06] = $0D (VRAM address in [$06] is no longer needed)
$00:C17A C2 20 REP #$20 ; A 16-bit
$00:C17C B9 BE 0F LDA.W $0FBE,Y ; \
$00:C17F 85 04 STA $04 ; / [$04] = pointer to the tile's 8 bytes of tile words (table at $0FBE)
$00:C181 A0 00 00 LDY.W #$0000 ; Y = 0
$00:C184 B7 04 LDA [$04],Y ; \
$00:C186 9F 81 83 7F STA.L $7F8381,X ; / Record 1, first tile = word 0
$00:C18A C8 INY ; \
$00:C18B C8 INY ; |
$00:C18C B7 04 LDA [$04],Y ; } Record 2, first tile = word 1
$00:C18E 9F 89 83 7F STA.L $7F8389,X ; /
$00:C192 C8 INY ; \
$00:C193 C8 INY ; |
$00:C194 B7 04 LDA [$04],Y ; } Record 1, second tile = word 2
$00:C196 9F 83 83 7F STA.L $7F8383,X ; /
$00:C19A C8 INY ; \
$00:C19B C8 INY ; |
$00:C19C B7 04 LDA [$04],Y ; } Record 2, second tile = word 3
$00:C19E 9F 8B 83 7F STA.L $7F838B,X ; /
$00:C1A2 8A TXA ; \
$00:C1A3 18 CLC ; |
$00:C1A4 69 10 00 ADC.W #$0010 ; } Advance the buffer write index by $10 (two records plus the $FF byte)
$00:C1A7 8F 7B 83 7F STA.L $7F837B ; /
$00:C1AB 60 RTS ; Return
$00:C1AC 20 0D C0 JSR.W $C00D ; Mark the block in the generated-tile bitmap ($C00D)
$00:C1AF C2 30 REP #$30 ; A, X and Y 16-bit
$00:C1B1 A5 98 LDA RAM_BlockYLo ; \
$00:C1B3 29 F0 01 AND.W #$01F0 ; |
$00:C1B6 85 04 STA $04 ; |
$00:C1B8 A5 9A LDA RAM_BlockXLo ; |
$00:C1BA 4A LSR ; |
$00:C1BB 4A LSR ; |
$00:C1BC 4A LSR ; |
$00:C1BD 4A LSR ; |
$00:C1BE 29 0F 00 AND.W #$000F ; } $04 = (BlockY & $1F0) | ((BlockX >> 4) & $0F): block offset in the Map16 page
$00:C1C1 05 04 ORA $04 ; /
$00:C1C3 A8 TAY ; Y = offset of the block
$00:C1C4 E2 20 SEP #$20 ; A 8-bit
$00:C1C6 A9 25 LDA.B #$25 ; \
$00:C1C8 97 6B STA [$6B],Y ; / Map16 tile of this block = $25 (empty)
$00:C1CA C2 20 REP #$20 ; A 16-bit
$00:C1CC 98 TYA ; \
$00:C1CD 18 CLC ; |
$00:C1CE 69 10 00 ADC.W #$0010 ; } Y += $10: the block below
$00:C1D1 A8 TAY ; /
$00:C1D2 E2 20 SEP #$20 ; A 8-bit
$00:C1D4 A9 25 LDA.B #$25 ; \
$00:C1D6 97 6B STA [$6B],Y ; / Map16 tile of the block below = $25 (empty)
$00:C1D8 C2 20 REP #$20 ; A 16-bit
$00:C1DA 29 FF 00 AND.W #$00FF ; \
$00:C1DD 0A ASL ; } Y = $25 * 2: index into the Map16 tile pointer table
$00:C1DE A8 TAY ; /
$00:C1DF A5 5B LDA RAM_IsVerticalLvl ; \
$00:C1E1 85 00 STA $00 ; } $00 = [$5B] (vertical level flags)
$00:C1E3 AD 33 19 LDA.W $1933 ; /
$00:C1E6 F0 02 BEQ $C1EA ; Layer 1: keep bit 0
$00:C1E8 46 00 LSR $00 ; Layer 2: use bit 1
$00:C1EA A5 00 LDA $00 ; A = vertical-level flag of the current layer
$00:C1EC 29 01 00 AND.W #$0001 ; Keep only bit 0
$00:C1EF D0 1A BNE $C20B ; Vertical level: go to $00C20B
$00:C1F1 A5 08 LDA $08 ; \
$00:C1F3 29 F0 FF AND.W #$FFF0 ; / A = [$08] & $FFF0: left edge of the view minus $80
$00:C1F6 30 06 BMI $C1FE ; Negative: skip the first compare
$00:C1F8 C5 0C CMP $0C ; Compare with [$0C] (block X)
$00:C1FA F0 26 BEQ $C222 ; Equal: draw
$00:C1FC B0 AD BCS $C1AB ; View edge > block: skip
$00:C1FE 18 CLC ; \
$00:C1FF 69 00 02 ADC.W #$0200 ; / A += $200
$00:C202 C5 0C CMP $0C ; Compare with [$0C]
$00:C204 90 A5 BCC $C1AB ; Below: skip
$00:C206 F0 A3 BEQ $C1AB ; Equal: skip
$00:C208 4C 22 C2 JMP.W $C222 ; Block inside the window: build the VRAM update
$00:C20B A5 0A LDA $0A ; \
$00:C20D 29 F0 FF AND.W #$FFF0 ; / Same range check for vertical levels: A = [$0A] & $FFF0
$00:C210 30 06 BMI $C218 ; Negative: skip the first compare
$00:C212 C5 0E CMP $0E ; Compare with [$0E] (block Y)
$00:C214 F0 0C BEQ $C222 ; Equal: draw
$00:C216 B0 93 BCS $C1AB ; View edge > block: skip
$00:C218 18 CLC ; \
$00:C219 69 00 02 ADC.W #$0200 ; / A += $200
$00:C21C C5 0E CMP $0E ; Compare with [$0E]
$00:C21E F0 8B BEQ $C1AB ; Equal: skip
$00:C220 90 89 BCC $C1AB ; Below: skip
$00:C222 AF 7B 83 7F LDA.L $7F837B ; \
$00:C226 AA TAX ; / X = write index into the stripe image buffer at $7F:837D
$00:C227 E2 20 SEP #$20 ; A 8-bit
$00:C229 A5 06 LDA $06 ; \
$00:C22B 9F 7D 83 7F STA.L $7F837D,X ; } Records 1 and 2: VRAM address high = [$06]
$00:C22F 9F 89 83 7F STA.L $7F8389,X ; /
$00:C233 A5 07 LDA $07 ; \
$00:C235 9F 7E 83 7F STA.L $7F837E,X ; |
$00:C239 1A INC A ; } Record address low: [$07] for record 1, [$07] + 1 (next tile column) for record 2
$00:C23A 9F 8A 83 7F STA.L $7F838A,X ; /
$00:C23E A9 80 LDA.B #$80 ; \
$00:C240 9F 7F 83 7F STA.L $7F837F,X ; } Records 1 and 2: flags = $80 (vertical increment)
$00:C244 9F 8B 83 7F STA.L $7F838B,X ; /
$00:C248 A9 07 LDA.B #$07 ; \
$00:C24A 9F 80 83 7F STA.L $7F8380,X ; } Records 1 and 2: length $07 = 8 bytes (4 tiles) each
$00:C24E 9F 8C 83 7F STA.L $7F838C,X ; /
$00:C252 A9 FF LDA.B #$FF ; \
$00:C254 9F 95 83 7F STA.L $7F8395,X ; / End marker $FF after the second record
$00:C258 A9 0D LDA.B #$0D ; A = $0D: bank of the Map16 tile data
$00:C25A 85 06 STA $06 ; [$06] = $0D
$00:C25C C2 20 REP #$20 ; A 16-bit
$00:C25E B9 BE 0F LDA.W $0FBE,Y ; \
$00:C261 85 04 STA $04 ; / [$04] = pointer to the tile's tile words (table at $0FBE)
$00:C263 A0 00 00 LDY.W #$0000 ; Y = 0
$00:C266 B7 04 LDA [$04],Y ; \
$00:C268 9F 81 83 7F STA.L $7F8381,X ; } Record 1, tiles 1 and 3 = word 0
$00:C26C 9F 85 83 7F STA.L $7F8385,X ; /
$00:C270 C8 INY ; \
$00:C271 C8 INY ; / Y += 2: next tile word
$00:C272 B7 04 LDA [$04],Y ; \
$00:C274 9F 8D 83 7F STA.L $7F838D,X ; } Record 2, tiles 1 and 3 = word 1
$00:C278 9F 91 83 7F STA.L $7F8391,X ; /
$00:C27C C8 INY ; \
$00:C27D C8 INY ; / Y += 2: next tile word
$00:C27E B7 04 LDA [$04],Y ; \
$00:C280 9F 83 83 7F STA.L $7F8383,X ; } Record 1, tiles 2 and 4 = word 2
$00:C284 9F 87 83 7F STA.L $7F8387,X ; /
$00:C288 C8 INY ; \
$00:C289 C8 INY ; / Y += 2: next tile word
$00:C28A B7 04 LDA [$04],Y ; \
$00:C28C 9F 8F 83 7F STA.L $7F838F,X ; } Record 2, tiles 2 and 4 = word 3
$00:C290 9F 93 83 7F STA.L $7F8393,X ; /
$00:C294 8A TXA ; \
$00:C295 18 CLC ; |
$00:C296 69 18 00 ADC.W #$0018 ; } Advance the buffer write index by $18 (two 12-byte records plus the $FF byte)
$00:C299 8F 7B 83 7F STA.L $7F837B ; /
$00:C29D 60 RTS ; Return
;;; $C29E: Cage tile data and cage/empty block generation (FlippedGateBgTiles?) ;;;
;; $00C29E: two 6x6-tile cage graphics (blocks $19 and $1A), as tile and property bytes. $00C32E: 3-byte
;; pointers to them.
;; $00C334: generates a cage: queues six horizontal 6-tile records starting one tile down and right of the
;; block.
;; $00C3D1 (block $1B): sets a 2x2 block area to Map16 tile $25 and queues four RLE records filling 4x4 tiles
;; with tile $F8, palette 6.
$00:C29E .db $99,$9C,$8B,$1C,$8B,$1C,$8B,$1C ; Cage 1 (block $19): 6x6 tile words (tile, properties), 72 bytes
$00:C2A6 .db $8B,$1C,$99,$DC,$9B,$1C,$F8,$1C ; (cage tile words, continued)
$00:C2AE .db $F8,$1C,$F8,$1C,$F8,$1C,$9B,$5C ; (cage tile words, continued)
$00:C2B6 .db $9B,$1C,$F8,$1C,$F8,$1C,$F8,$1C ; (cage tile words, continued)
$00:C2BE .db $F8,$1C,$9B,$5C,$9B,$1C,$F8,$1C ; (cage tile words, continued)
$00:C2C6 .db $F8,$1C,$F8,$1C,$F8,$1C,$9B,$5C ; (cage tile words, continued)
$00:C2CE .db $9B,$1C,$F8,$1C,$F8,$1C,$F8,$1C ; (cage tile words, continued)
$00:C2D6 .db $F8,$1C,$9B,$5C,$99,$1C,$8B,$9C ; (cage tile words, continued)
$00:C2DE .db $8B,$9C,$8B,$9C,$8B,$9C,$99,$5C ; (cage tile words, continued)
$00:C2E6 .db $BA,$9C,$AB,$1C,$AB,$1C,$AB,$1C ; Cage 2 (block $1A): 6x6 tile words (tile, properties), 72 bytes
$00:C2EE .db $AB,$1C,$BA,$DC,$AA,$1C,$82,$1C ; (cage tile words, continued)
$00:C2F6 .db $82,$1C,$82,$1C,$82,$1C,$AA,$5C ; (cage tile words, continued)
$00:C2FE .db $AA,$1C,$82,$1C,$82,$1C,$82,$1C ; (cage tile words, continued)
$00:C306 .db $82,$1C,$AA,$5C,$AA,$1C,$82,$1C ; (cage tile words, continued)
$00:C30E .db $82,$1C,$82,$1C,$82,$1C,$AA,$5C ; (cage tile words, continued)
$00:C316 .db $AA,$1C,$82,$1C,$82,$1C,$82,$1C ; (cage tile words, continued)
$00:C31E .db $82,$1C,$AA,$5C,$BA,$1C,$AB,$9C ; (cage tile words, continued)
$00:C326 .db $AB,$9C,$AB,$9C,$AB,$9C,$BA,$5C ; (cage tile words, continued)
$00:C32E .db $9E,$C2 ; Pointer to cage 1 tile words: $00:C29E
$00:C330 .db $00,$E6,$C2,$00 ; Bank byte $00; pointer to cage 2 tile words: $00:C2E6; bank byte $00
$00:C334 E6 07 INC $07 ; \
$00:C336 A5 07 LDA $07 ; |
$00:C338 18 CLC ; |
$00:C339 69 20 ADC.B #$20 ; |
$00:C33B 85 07 STA $07 ; |
$00:C33D A5 06 LDA $06 ; |
$00:C33F 69 00 ADC.B #$00 ; } VRAM address of the block + $21 (one tile row down and one tile right)
$00:C341 85 06 STA $06 ; /
$00:C343 A5 9C LDA RAM_BlockBlock ; \
$00:C345 38 SEC ; |
$00:C346 E9 19 SBC.B #$19 ; |
$00:C348 85 00 STA $00 ; |
$00:C34A 0A ASL ; |
$00:C34B 18 CLC ; |
$00:C34C 65 00 ADC $00 ; } X = ([$9C] - $19) * 3: index into the 3-byte cage pointer table
$00:C34E AA TAX ; /
$00:C34F BF 30 C3 00 LDA.L $C330,X ; A = bank byte of the cage data
$00:C353 85 04 STA $04 ; [$04] = bank
$00:C355 C2 30 REP #$30 ; A, X and Y 16-bit
$00:C357 BF 2E C3 00 LDA.L $C32E,X ; \
$00:C35B 85 02 STA $02 ; / [$02] = address of the cage tile words
$00:C35D AF 7B 83 7F LDA.L $7F837B ; \
$00:C361 AA TAX ; / X = write index into the stripe image buffer
$00:C362 A0 05 00 LDY.W #$0005 ; Y = 5: six rows
$00:C365 E2 20 SEP #$20 ; A 8-bit
$00:C367 A5 06 LDA $06 ; \
$00:C369 9F 7D 83 7F STA.L $7F837D,X ; |
$00:C36D A5 07 LDA $07 ; } Record header: VRAM address = [$06]/[$07]
$00:C36F 9F 7E 83 7F STA.L $7F837E,X ; /
$00:C373 A9 00 LDA.B #$00 ; \
$00:C375 9F 7F 83 7F STA.L $7F837F,X ; / Flags = 0 (horizontal, no RLE)
$00:C379 A9 0B LDA.B #$0B ; \
$00:C37B 9F 80 83 7F STA.L $7F8380,X ; / Length $0B = 12 bytes (6 tiles)
$00:C37F A5 07 LDA $07 ; \
$00:C381 18 CLC ; |
$00:C382 69 20 ADC.B #$20 ; |
$00:C384 85 07 STA $07 ; |
$00:C386 A5 06 LDA $06 ; |
$00:C388 69 00 ADC.B #$00 ; } VRAM address += $20: next tile row
$00:C38A 85 06 STA $06 ; /
$00:C38C C2 20 REP #$20 ; A 16-bit
$00:C38E 8A TXA ; \
$00:C38F 18 CLC ; |
$00:C390 69 10 00 ADC.W #$0010 ; } X += $10: next record (4 byte header + 12 data bytes)
$00:C393 AA TAX ; /
$00:C394 88 DEY ; Row count - 1
$00:C395 10 CE BPL $C365 ; Loop for all 6 rows
$00:C397 AF 7B 83 7F LDA.L $7F837B ; \
$00:C39B AA TAX ; / X = write index again: now fill in the data
$00:C39C A0 00 00 LDY.W #$0000 ; Y = 0: offset into the cage tile words
$00:C39F A9 05 00 LDA.W #$0005 ; \
$00:C3A2 85 00 STA $00 ; / $00 = 5: six tile words per row
$00:C3A4 B7 02 LDA [$02],Y ; \
$00:C3A6 9F 81 83 7F STA.L $7F8381,X ; / Copy one tile word into the record
$00:C3AA C8 INY ; \
$00:C3AB C8 INY ; |
$00:C3AC E8 INX ; } Source and destination += 2
$00:C3AD E8 INX ; /
$00:C3AE C6 00 DEC $00 ; \
$00:C3B0 10 F2 BPL $C3A4 ; / Loop for 6 words
$00:C3B2 8A TXA ; \
$00:C3B3 18 CLC ; |
$00:C3B4 69 04 00 ADC.W #$0004 ; } X += 4: skip the next record's header
$00:C3B7 AA TAX ; /
$00:C3B8 C0 48 00 CPY.W #$0048 ; All $48 bytes (36 words) copied?
$00:C3BB D0 E2 BNE $C39F ; No: next row
$00:C3BD A9 FF 00 LDA.W #$00FF ; \
$00:C3C0 9F 7D 83 7F STA.L $7F837D,X ; / End marker $FF after the last record
$00:C3C4 AF 7B 83 7F LDA.L $7F837B ; \
$00:C3C8 18 CLC ; |
$00:C3C9 69 60 00 ADC.W #$0060 ; } Write index += $60 (6 records of $10 bytes)
$00:C3CC 8F 7B 83 7F STA.L $7F837B ; /
$00:C3D0 60 RTS ; Return
$00:C3D1 C2 30 REP #$30 ; A, X and Y 16-bit
$00:C3D3 A5 98 LDA RAM_BlockYLo ; \
$00:C3D5 29 F0 01 AND.W #$01F0 ; |
$00:C3D8 85 04 STA $04 ; |
$00:C3DA A5 9A LDA RAM_BlockXLo ; |
$00:C3DC 4A LSR ; |
$00:C3DD 4A LSR ; |
$00:C3DE 4A LSR ; |
$00:C3DF 4A LSR ; |
$00:C3E0 29 0F 00 AND.W #$000F ; } $04 = (BlockY & $1F0) | ((BlockX >> 4) & $0F): block offset in the Map16 page
$00:C3E3 05 04 ORA $04 ; /
$00:C3E5 A8 TAY ; Y = offset of the block
$00:C3E6 AF 7B 83 7F LDA.L $7F837B ; \
$00:C3EA AA TAX ; / X = write index into the stripe image buffer
$00:C3EB E2 20 SEP #$20 ; A 8-bit
$00:C3ED A9 25 LDA.B #$25 ; \
$00:C3EF 97 6B STA [$6B],Y ; / Map16 tile of the block = $25 (empty)
$00:C3F1 C8 INY ; Y + 1: block to the right
$00:C3F2 A9 25 LDA.B #$25 ; \
$00:C3F4 97 6B STA [$6B],Y ; / Map16 tile = $25 (empty)
$00:C3F6 C2 20 REP #$20 ; A 16-bit
$00:C3F8 98 TYA ; \
$00:C3F9 18 CLC ; |
$00:C3FA 69 10 00 ADC.W #$0010 ; } Y += $10: the row below
$00:C3FD A8 TAY ; /
$00:C3FE E2 20 SEP #$20 ; A 8-bit
$00:C400 A9 25 LDA.B #$25 ; \
$00:C402 97 6B STA [$6B],Y ; / Map16 tile = $25 (empty), lower right block
$00:C404 88 DEY ; Y - 1: lower left block
$00:C405 A9 25 LDA.B #$25 ; \
$00:C407 97 6B STA [$6B],Y ; / Map16 tile = $25 (empty), lower left block
$00:C409 A0 03 00 LDY.W #$0003 ; Y = 3: four tile rows
$00:C40C A5 06 LDA $06 ; \
$00:C40E 9F 7D 83 7F STA.L $7F837D,X ; |
$00:C412 A5 07 LDA $07 ; } Record header: VRAM address = [$06]/[$07]
$00:C414 9F 7E 83 7F STA.L $7F837E,X ; /
$00:C418 A9 40 LDA.B #$40 ; \
$00:C41A 9F 7F 83 7F STA.L $7F837F,X ; / Flags = $40 (RLE)
$00:C41E A9 06 LDA.B #$06 ; \
$00:C420 9F 80 83 7F STA.L $7F8380,X ; / Length 6 = 7 bytes (probably an off-by-one: 3.5 tiles)
$00:C424 C2 20 REP #$20 ; A 16-bit
$00:C426 A9 F8 18 LDA.W #$18F8 ; \
$00:C429 9F 81 83 7F STA.L $7F8381,X ; / RLE data: tile $F8 with properties $18 (palette 6)
$00:C42D 8A TXA ; \
$00:C42E 18 CLC ; |
$00:C42F 69 06 00 ADC.W #$0006 ; } X += 6: next record
$00:C432 AA TAX ; /
$00:C433 E2 20 SEP #$20 ; A 8-bit
$00:C435 A5 07 LDA $07 ; \
$00:C437 18 CLC ; |
$00:C438 69 20 ADC.B #$20 ; |
$00:C43A 85 07 STA $07 ; |
$00:C43C A5 06 LDA $06 ; |
$00:C43E 69 00 ADC.B #$00 ; } VRAM address += $20: next tile row
$00:C440 85 06 STA $06 ; /
$00:C442 88 DEY ; Row count - 1
$00:C443 10 C7 BPL $C40C ; Loop for all 4 rows
$00:C445 A9 FF LDA.B #$FF ; \
$00:C447 9F 7D 83 7F STA.L $7F837D,X ; / End marker $FF after the last record
$00:C44B C2 20 REP #$20 ; A 16-bit
$00:C44D 8A TXA ; \
$00:C44E 8F 7B 83 7F STA.L $7F837B ; / Write index = X (past the new records)
$00:C452 60 RTS ; Return
;;; $C453..C46B: Unused: $FF fill and bit masks ;;;
$00:C453 .db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Unused: $FF fill
$00:C45B .db $FF,$FF,$FF,$FF,$FF,$80,$40,$20 ; Unused: $FF fill, then bit masks $80..$01
$00:C463 .db $10,$08,$04,$02,$01,$80,$40,$20 ; Unused: bit masks $80..$01 (repeated)
$00:C46B .db $10,$08,$04,$02,$01 ; Unused: bit masks, last row
;;; $C470..C478: Tables: keyhole window animation ;;;
;; Per keyhole phase [$1435]: target circle size ($90/$00), size step per frame (+4/-4) and WOBJSEL value
;; ($30/$33).
$00:C470 .db $90,$00,$90,$00 ; Keyhole circle target size by phase [$1435]: $90, $00, $90, $00
$00:C474 .db $04,$FC,$04,$FC ; Keyhole circle size step per frame by phase: +4, -4, +4, -4
$00:C478 .db $30,$33,$33,$30,$01,$00 ; Keyhole WOBJSEL value by phase ($30/$33); last 2 bytes ($01,$00) probably unused
;;; $C47E: Per-frame Mario state: keyhole, timers, animation ;;;
;; Called every frame from the Mario/sprite interaction code. Runs the keyhole closing animation (circle HDMA
;; window around the keyhole,
;; freezes Mario and sprites, secret exit when done), counts down the timers $1496-$14A8 each frame and
;; $14A9-$14AE every 4th frame,
;; switches music for the bonus game and the P-switch timers, then runs the current Mario animation ([$71]).
;; Select drops the item box item.
;; $00C593: runs the Mario animation routine from AnimationSeqPtr.
;; Called by:
;; $00:9551: Cutscene, ending and game mode code (castle scenes, credits, game over) (CutsceneCastlePal)
;; $00:A2DF: Game mode 14: in level (InLevelGameMode)
$00:C47E 64 78 STZ $78 ; [$78] = 0
$00:C480 AD CB 13 LDA.W $13CB ; A = [$13CB] (bit 7 = give Mario a star)
$00:C483 10 07 BPL $C48C ; Bit 7 clear: skip
$00:C485 22 80 C5 01 JSL.L $C580 ; Unreachable: start star power ($C580)
$00:C489 9C CB 13 STZ.W $13CB ; Clear [$13CB]
$00:C48C AC 34 14 LDY.W $1434 ; \
$00:C48F F0 29 BEQ $C4BA ; / Y = [$1434] (keyhole animation active); if 0 skip the keyhole code
$00:C491 8C FB 13 STY.W $13FB ; [$13FB] = Y: freeze Mario while the keyhole animation runs
$00:C494 84 9D STY RAM_SpritesLocked ; Lock sprites too
$00:C496 AE 35 14 LDX.W $1435 ; X = [$1435] (keyhole animation phase)
$00:C499 AD 33 14 LDA.W $1433 ; A = [$1433] (keyhole circle size)
$00:C49C DD 70 C4 CMP.W $C470,X ; Reached the target size for this phase?
$00:C49F D0 1B BNE $C4BC ; No: step the size ($00C4BC)
$00:C4A1 88 DEY ; Y - 1
$00:C4A2 D0 13 BNE $C4B7 ; Y still non-zero: store it and go on
$00:C4A4 EE 35 14 INC.W $1435 ; Next phase: [$1435]++
$00:C4A7 8A TXA ; \
$00:C4A8 4A LSR ; / Carry = bit 0 of the old phase
$00:C4A9 90 4D BCC $C4F8 ; Even phase: continue at $00C4F8
$00:C4AB 20 EC FC JSR.W $FCEC ; Odd phase (animation done): clear all 12 sprite slots ($FCEC)
$00:C4AE A9 02 LDA.B #$02 ; \
$00:C4B0 A0 0B LDY.B #$0B ; } Exit the level with exit type 2 (secret exit), Y = $0B ($C9FE)
$00:C4B2 20 FE C9 JSR.W $C9FE ; /
$00:C4B5 A0 00 LDY.B #$00 ; Y = 0: keyhole animation finished
$00:C4B7 8C 34 14 STY.W $1434 ; Store Y in [$1434]
$00:C4BA 80 3C BRA $C4F8 ; Continue at $00C4F8
$00:C4BC 18 CLC ; \
$00:C4BD 7D 74 C4 ADC.W $C474,X ; } [$1433] += $C474[X]: grow or shrink the circle
$00:C4C0 8D 33 14 STA.W $1433 ; /
$00:C4C3 A9 22 LDA.B #$22 ; \
$00:C4C5 85 41 STA $41 ; / [$41] = $22: window mask BG1/BG2
$00:C4C7 A9 02 LDA.B #$02 ; \
$00:C4C9 85 42 STA $42 ; / [$42] = $02: window mask BG3/BG4
$00:C4CB BD 78 C4 LDA.W $C478,X ; \
$00:C4CE 85 43 STA $43 ; / [$43] = $C478[X]: window mask OBJ/color
$00:C4D0 A9 12 LDA.B #$12 ; \
$00:C4D2 85 44 STA $44 ; / [$44] = $12: color window control
$00:C4D4 C2 20 REP #$20 ; A 16-bit
$00:C4D6 A9 93 CB LDA.W #$CB93 ; \
$00:C4D9 85 04 STA $04 ; / [$04] = $CB93: address of the circle window shape data
$00:C4DB 64 06 STZ $06 ; [$06] = 0 (bank)
$00:C4DD E2 20 SEP #$20 ; A 8-bit
$00:C4DF AD 36 14 LDA.W RAM_KeyHolePos1 ; \
$00:C4E2 38 SEC ; |
$00:C4E3 E5 1A SBC RAM_ScreenBndryXLo ; |
$00:C4E5 18 CLC ; |
$00:C4E6 69 04 ADC.B #$04 ; } [$00] = keyhole X - screen X + 4 (on-screen circle center X)
$00:C4E8 85 00 STA $00 ; /
$00:C4EA AD 38 14 LDA.W RAM_KeyHolePos2 ; \
$00:C4ED 38 SEC ; |
$00:C4EE E5 1C SBC RAM_ScreenBndryYLo ; |
$00:C4F0 18 CLC ; |
$00:C4F1 69 10 ADC.B #$10 ; } [$01] = keyhole Y - screen Y + $10 (on-screen circle center Y)
$00:C4F3 85 01 STA $01 ; /
$00:C4F5 20 88 CA JSR.W $CA88 ; Build the circle window HDMA table ($CA88)
$00:C4F8 AD FB 13 LDA.W $13FB ; A = [$13FB] (Mario frozen)
$00:C4FB F0 03 BEQ $C500 ; Not frozen: go on
$00:C4FD 4C 8F C5 JMP.W $C58F ; Frozen: skip the timers, finish at $00C58F
$00:C500 A5 9D LDA RAM_SpritesLocked ; \
$00:C502 D0 65 BNE $C569 ; / Sprites locked: skip the timers ($00C569)
$00:C504 E6 14 INC RAM_FrameCounterB ; Count a frame: [$14]++
$00:C506 A2 13 LDX.B #$13 ; X = $13
$00:C508 BD 95 14 LDA.W $1495,X ; \
$00:C50B F0 03 BEQ $C510 ; } Decrement [$1496]..[$14A8] if non-zero (every unlocked frame)
$00:C50D DE 95 14 DEC.W $1495,X ; /
$00:C510 CA DEX ; Next timer
$00:C511 D0 F5 BNE $C508 ; Loop
$00:C513 A5 14 LDA RAM_FrameCounterB ; \
$00:C515 29 03 AND.B #$03 ; } Rest runs only every 4th frame ([$14] & 3 = 0)
$00:C517 D0 50 BNE $C569 ; /
$00:C519 AD 25 14 LDA.W $1425 ; \
$00:C51C F0 15 BEQ $C533 ; / [$1425] = 0: skip the next block (probably not the bonus game)
$00:C51E AD AB 14 LDA.W $14AB ; A = [$14AB] (probably the bonus game timer)
$00:C521 C9 44 CMP.B #$44 ; $44?
$00:C523 D0 05 BNE $C52A ; No: check for 1
$00:C525 A0 14 LDY.B #$14 ; Y = $14
$00:C527 8C FB 1D STY.W $1DFB ; Change music to $14
$00:C52A C9 01 CMP.B #$01 ; Reached 1?
$00:C52C D0 05 BNE $C533 ; No
$00:C52E A0 0B LDY.B #$0B ; Y = $0B
$00:C530 8C 00 01 STY.W RAM_GameMode ; Game mode = $0B (bonus game over: fade to overworld)
$00:C533 AC AD 14 LDY.W RAM_BluePowTimer ; \
$00:C536 CC AE 14 CPY.W RAM_SilverPowTimer ; |
$00:C539 B0 03 BCS $C53E ; } Y = max([$14AD] blue P-switch timer, [$14AE] silver P-switch timer)
$00:C53B AC AE 14 LDY.W RAM_SilverPowTimer ; /
$00:C53E AD DA 0D LDA.W $0DDA ; A = [$0DDA] (level music to resume)
$00:C541 30 0C BMI $C54F ; Bit 7 set: no music restore
$00:C543 C0 01 CPY.B #$01 ; P-switch timer at 1 (about to end)?
$00:C545 D0 08 BNE $C54F ; No
$00:C547 AC 0C 19 LDY.W $190C ; Y = [$190C]
$00:C54A D0 03 BNE $C54F ; Non-zero: skip
$00:C54C 8D FB 1D STA.W $1DFB ; Resume the level music: [$1DFB] = [$0DDA]
$00:C54F C9 FF CMP.B #$FF ; [$0DDA] = $FF?
$00:C551 F0 09 BEQ $C55C ; Yes: skip the warning sound
$00:C553 C0 1E CPY.B #$1E ; P-switch timer = $1E (about to run out)?
$00:C555 D0 05 BNE $C55C ; No
$00:C557 A9 24 LDA.B #$24 ; \
$00:C559 8D FC 1D STA.W $1DFC ; / Play sound effect $24 (running-out warning)
$00:C55C A2 06 LDX.B #$06 ; X = 6
$00:C55E BD A8 14 LDA.W $14A8,X ; \
$00:C561 F0 03 BEQ $C566 ; } Decrement [$14A9]..[$14AE] (X = 6..1) if non-zero, every 4th frame
$00:C563 DE A8 14 DEC.W $14A8,X ; /
$00:C566 CA DEX ; Next timer
$00:C567 D0 F5 BNE $C55E ; Loop (includes both P-switch timers)
$00:C569 20 93 C5 JSR.W $C593 ; Run the current Mario animation ($C593)
$00:C56C A5 16 LDA $16 ; \
$00:C56E 29 20 AND.B #$20 ; } Select newly pressed? If not, skip to $00C58F
$00:C570 F0 1D BEQ $C58F ; /
$00:C572 A5 15 LDA RAM_ControllerA ; \
$00:C574 29 08 AND.B #$08 ; / A = Up held bit of [$15]
$00:C576 80 0D BRA $C585 ; Always taken (patch to BEQ to reach the debug code)
$00:C578 A5 19 LDA RAM_MarioPowerUp ; \
$00:C57A 1A INC A ; / Unreachable debug: power-up + 1
$00:C57B C9 04 CMP.B #$04 ; \
$00:C57D 90 02 BCC $C581 ; / Wrap after 3 (flower)
$00:C57F A9 00 LDA.B #$00 ; Power-up = 0
$00:C581 85 19 STA RAM_MarioPowerUp ; Store Mario's power-up
$00:C583 80 0A BRA $C58F ; Continue at $00C58F
$00:C585 8B PHB ; Save the data bank
$00:C586 A9 02 LDA.B #$02 ; \
$00:C588 48 PHA ; } Data bank = $02
$00:C589 AB PLB ; /
$00:C58A 22 08 80 02 JSL.L $8008 ; Select pressed: item box action ($8008, probably drops the reserve item)
$00:C58E AB PLB ; Restore the data bank
$00:C58F 9C 02 14 STZ.W $1402 ; [$1402] = 0
$00:C592 60 RTS ; Return
$00:C593 A5 71 LDA RAM_MarioAnimation ; A = [$71]: Mario animation number
$00:C595 22 DF 86 00 JSL.L ExecutePtr ; Run the animation routine from AnimationSeqPtr
;;; $C599: Pointer table: Mario animation routines (AnimationSeqPtr) ;;;
;; Indexed by [$71] (Mario animation number), used with ExecutePtr.
$00:C599 68 CC .dw ResetAni ; 0 - Reset: normal control
$00:C59B 29 D1 .dw PowerDownAni ; 1 - Power down (hit while big)
$00:C59D 47 D1 .dw MushroomAni ; 2 - Mushroom power up
$00:C59F 5F D1 .dw CapeAni ; 3 - Cape power up
$00:C5A1 6F D1 .dw FlowerAni ; 4 - Fire flower power up
$00:C5A3 97 D1 .dw DoorPipeAni ; 5 - Exit door or horizontal pipe
$00:C5A5 03 D2 .dw VertPipeAni ; 6 - Exit vertical pipe
$00:C5A7 87 D2 .dw PipeCannonAni ; 7 - Shot out of diagonal pipe
$00:C5A9 FD C7 .dw YoshiWingsAni ; 8 - Yoshi wings exit
$00:C5AB B6 D0 .dw MarioDeathAni ; 9 - Death
$00:C5AD 70 C8 .dw EnterCastleAni ; A - Enter castle
$00:C5AF B5 C5 .dw UnknownAniB ; B - Freeze with message box
$00:C5B1 E7 C6 .dw UnknownAniC ; C - Scripted cutscene movement
$00:C5B3 92 C5 .dw $C592 ; D - Freeze forever (just returns)
;;; $C5B5: Mario animation B: freeze with message box (UnknownAniB) ;;;
;; Clears [$13DE]/[$13ED]. If the end-of-level timer is set outside a level, leaves the level; otherwise shows
;; an expanding message box
;; ([$1B88] = 1), clears the controls and runs Mario's physics.
$00:C5B5 9C DE 13 STZ.W $13DE ; \
$00:C5B8 9C ED 13 STZ.W $13ED ; / Clear [$13DE] and [$13ED] (Mario state flags)
$00:C5BB AD 93 14 LDA.W $1493 ; \
$00:C5BE F0 0E BEQ $C5CE ; / End-of-level timer [$1493] = 0: skip to $00C5CE
$00:C5C0 22 13 AB 0C JSL.L $AB13 ; Run the end-of-level routine in bank $0C ($AB13)
$00:C5C4 AD 00 01 LDA.W RAM_GameMode ; \
$00:C5C7 C9 14 CMP.B #$14 ; } In a level (game mode $14): go to the message box code
$00:C5C9 F0 06 BEQ $C5D1 ; /
$00:C5CB 4C 5B C9 JMP.W $C95B ; Elsewhere: leave the level, normal exit ($C95B)
$00:C5CE 9C 9F 0D STZ.W $0D9F ; Turn off HDMA
$00:C5D1 A9 01 LDA.B #$01 ; \
$00:C5D3 8D 88 1B STA.W $1B88 ; / [$1B88] = 1: message box is expanding
$00:C5D6 A9 07 LDA.B #$07 ; \
$00:C5D8 8D 28 19 STA.W $1928 ; / [$1928] = 7
$00:C5DB 20 2D F6 JSR.W NoButtons ; Clear the controller mirrors (NoButtons)
$00:C5DE 4C 24 CD JMP.W $CD24 ; Run Mario's movement and physics ($CD24)
;;; $C5E1..C6D9: Data: cutscene poses and Mario movement scripts ;;;
;; $00C5E1: Mario pose numbers. $00C5E8 on: scripts for UnknownAniC, one per cutscene [$13C6] = 1-7, each a
;; list of (command, frames) pairs ending
;; in command $FF. A command without bit 5 is a controller byte; with bit 5 it is a special action. Bit 4 also
;; runs a bank $0C helper.
$00:C5E1 .db $10,$30,$31,$32,$33,$34,$0E ; Mario pose numbers for script commands $27-$2D: $10,$30-$34,$0E (index = low nibble - 7)
$00:C5E8 .db $26 ; Script data: pairs (command, duration); this is a header pair, $26/$11
$00:C5E9 .db $11,$02,$48,$00,$60,$01,$09,$80 ; Cutscene scripts: (command, frames) pairs; cutscene 1 script starts at $C5EA
$00:C5F1 .db $08,$00,$20,$04,$60,$00,$01,$FF ; Cutscene scripts: (command, frames) pairs; $FF at $C5F8 ends a script
$00:C5F9 .db $01,$02,$48,$00,$60,$41,$2C,$C1 ; Cutscene scripts: (command, frames) pairs; cutscene 2 script starts at $C5FA
$00:C601 .db $04,$27,$04,$2F,$08,$25,$01,$2F ; Cutscene scripts: (command, frames) pairs
$00:C609 .db $04,$27,$04,$00,$08,$41,$1B,$C1 ; Cutscene scripts: (command, frames) pairs
$00:C611 .db $04,$27,$04,$2F,$08,$25,$01,$2F ; Cutscene scripts: (command, frames) pairs
$00:C619 .db $04,$27,$04,$00,$04,$01,$08,$20 ; Cutscene scripts: (command, frames) pairs
$00:C621 .db $01,$01,$10,$00,$08,$41,$12,$81 ; Cutscene scripts: (command, frames) pairs
$00:C629 .db $0A,$00,$40,$82,$10,$02,$20,$00 ; Cutscene scripts: (command, frames) pairs
$00:C631 .db $30,$01,$01,$00,$50,$22,$01,$FF ; Cutscene scripts: (command, frames) pairs; $FF at $C638 ends a script
$00:C639 .db $01,$02,$48,$00,$60,$01,$09,$80 ; Cutscene scripts: (command, frames) pairs; cutscene 5 script starts at $C63A
$00:C641 .db $08,$00,$20,$04,$60,$00,$20,$10 ; Cutscene scripts: (command, frames) pairs
$00:C649 .db $20,$01,$58,$00,$2C,$31,$01,$3A ; Cutscene scripts: (command, frames) pairs
$00:C651 .db $10,$31,$01,$3A,$10,$31,$01,$3A ; Cutscene scripts: (command, frames) pairs
$00:C659 .db $20,$28,$A0,$28,$40,$29,$04,$28 ; Cutscene scripts: (command, frames) pairs
$00:C661 .db $04,$29,$04,$28,$04,$29,$04,$28 ; Cutscene scripts: (command, frames) pairs
$00:C669 .db $40,$22,$01,$FF,$01,$02,$48,$00 ; Cutscene scripts: (command, frames) pairs; cutscene 4 script starts at $C66E; $FF at $C66C ends a script
$00:C671 .db $60,$01,$09,$80,$08,$00,$20,$04 ; Cutscene scripts: (command, frames) pairs
$00:C679 .db $60,$10,$20,$31,$01,$18,$60,$31 ; Cutscene scripts: (command, frames) pairs
$00:C681 .db $01,$3B,$80,$31,$01,$3C,$40,$FF ; Cutscene scripts: (command, frames) pairs; $FF at $C688 ends a script
$00:C689 .db $01,$02,$48,$00,$60,$02,$30,$01 ; Cutscene scripts: (command, frames) pairs; cutscene 3 script starts at $C68A
$00:C691 .db $84,$00,$20,$23,$01,$01,$16,$02 ; Cutscene scripts: (command, frames) pairs
$00:C699 .db $20,$20,$01,$01,$20,$02,$20,$01 ; Cutscene scripts: (command, frames) pairs
$00:C6A1 .db $02,$00,$80,$FF,$01,$02,$48,$00 ; Cutscene scripts: (command, frames) pairs; cutscene 6 script starts at $C6A6; $FF at $C6A4 ends a script
$00:C6A9 .db $60,$02,$28,$01,$83,$00,$28,$24 ; Cutscene scripts: (command, frames) pairs
$00:C6B1 .db $01,$02,$01,$00,$FF,$00,$40,$20 ; Cutscene scripts: (command, frames) pairs
$00:C6B9 .db $01,$00,$40,$02,$60,$00,$30,$FF ; Cutscene scripts: (command, frames) pairs; $FF at $C6C0 ends a script
$00:C6C1 .db $01,$02,$48,$00,$60,$01,$4E,$00 ; Cutscene scripts: (command, frames) pairs; cutscene 7 script starts at $C6C2
$00:C6C9 .db $40,$26,$01,$00,$1E,$20,$01,$00 ; Cutscene scripts: (command, frames) pairs
$00:C6D1 .db $20,$08,$10,$20,$01,$2D,$18,$00 ; Cutscene scripts: (command, frames) pairs
$00:C6D9 .db $A0,$20,$01,$2E,$01,$FF ; Cutscene scripts: (command, frames) pairs; $FF at $C6DE ends a script
;;; $C6DF..C6DF: Table: cutscene script offsets ;;;
;; Offset added to [$8F] to find the script of cutscene [$13C6] (cutscenes 1-7 use entries 1-7).
$00:C6DF .db $01,$00,$10,$A0,$84,$50,$BC,$D8 ; Script start offset by cutscene [$13C6] (0-7)
;;; $C6E7: Mario animation C: scripted cutscene movement (UnknownAniC) ;;;
;; Plays a script from the table at $00C5E8 for cutscene [$13C6]: held buttons or special actions per command.
;; Also lands Mario at Y = $58 and
;; makes scripted hops. Purpose partly unclear (probably the post-castle cutscenes).
$00:C6E7 20 2D F6 JSR.W NoButtons ; No buttons allowed (NoButtons)
$00:C6EA 9C DE 13 STZ.W $13DE ; Clear [$13DE]
$00:C6ED 20 2D DC JSR.W $DC2D ; Process Mario's Y speed ($DC2D)
$00:C6F0 A5 7D LDA RAM_MarioSpeedY ; \
$00:C6F2 30 4B BMI $C73F ; / Moving upward: skip the landing and hop checks
$00:C6F4 A5 96 LDA RAM_MarioYPos ; \
$00:C6F6 C9 58 CMP.B #$58 ; } Mario Y >= $58 (scene ground level): land at $00C739
$00:C6F8 B0 3F BCS $C739 ; /
$00:C6FA A4 94 LDY RAM_MarioXPos ; \
$00:C6FC C0 40 CPY.B #$40 ; } Mario X < $40: skip
$00:C6FE 90 3F BCC $C73F ; /
$00:C700 C0 60 CPY.B #$60 ; \
$00:C702 90 18 BCC $C71C ; / X $40-$5F: scripted hop at $00C71C
$00:C704 A4 1C LDY RAM_ScreenBndryYLo ; \
$00:C706 F0 37 BEQ $C73F ; / X >= $60: skip if the layer is not scrolled ([$1C] = 0)
$00:C708 18 CLC ; \
$00:C709 65 1C ADC RAM_ScreenBndryYLo ; |
$00:C70B C9 1C CMP.B #$1C ; } Skip if Mario Y + [$1C] < $1C
$00:C70D 30 30 BMI $C73F ; /
$00:C70F 38 SEC ; \
$00:C710 E5 1C SBC RAM_ScreenBndryYLo ; } A = Mario Y; Y speed = $D0 (-$30)
$00:C712 A2 D0 LDX.B #$D0 ; /
$00:C714 A4 76 LDY RAM_MarioDirection ; \
$00:C716 F0 18 BEQ $C730 ; / Facing left: keep X speed
$00:C718 A0 00 LDY.B #$00 ; \
$00:C71A 80 12 BRA $C72E ; / Facing right: X speed = 0
$00:C71C C9 4C CMP.B #$4C ; \
$00:C71E 90 1F BCC $C73F ; / Mario Y < $4C: skip
$00:C720 A9 1B LDA.B #$1B ; \
$00:C722 8D FC 1D STA.W $1DFC ; / Play sound effect $1B
$00:C725 EE 3E 14 INC.W RAM_ScrollSprNum ; Next cutscene step: [$143E]++
$00:C728 A9 4C LDA.B #$4C ; \
$00:C72A A0 F4 LDY.B #$F4 ; } Hop: Y pos $4C, X speed $F4 (-$0C), Y speed $C0 (-$40)
$00:C72C A2 C0 LDX.B #$C0 ; /
$00:C72E 84 7B STY RAM_MarioSpeedX ; Mario X speed = Y
$00:C730 86 7D STX RAM_MarioSpeedY ; Mario Y speed = X
$00:C732 A2 01 LDX.B #$01 ; \
$00:C734 8E F9 1D STX.W $1DF9 ; / Play sound effect 1
$00:C737 80 04 BRA $C73D ; Continue at $00C73D
$00:C739 64 72 STZ RAM_IsFlying ; Not flying
$00:C73B A9 58 LDA.B #$58 ; A = $58
$00:C73D 85 96 STA RAM_MarioYPos ; Mario Y = A (snap to the ground)
$00:C73F AE C6 13 LDX.W $13C6 ; X = [$13C6] (cutscene number)
$00:C742 A5 8F LDA $8F ; \
$00:C744 18 CLC ; |
$00:C745 7D DF C6 ADC.W $C6DF,X ; } X = script position [$8F] + start offset for this cutscene
$00:C748 AA TAX ; /
$00:C749 A5 88 LDA $88 ; A = [$88]: frames left for the current command
$00:C74B D0 17 BNE $C764 ; Not expired: keep running the current command
$00:C74D E6 8F INC $8F ; \
$00:C74F E6 8F INC $8F ; / Script position += 2
$00:C751 E8 INX ; X += 2
$00:C752 E8 INX ; Next pair
$00:C753 BD E9 C5 LDA.W $C5E9,X ; \
$00:C756 85 88 STA $88 ; / [$88] = duration of the next command
$00:C758 BD E8 C5 LDA.W $C5E8,X ; \
$00:C75B C9 2D CMP.B #$2D ; / Command $2D?
$00:C75D D0 05 BNE $C764 ; No
$00:C75F A9 1E LDA.B #$1E ; \
$00:C761 8D F9 1D STA.W $1DF9 ; / Play sound effect $1E
$00:C764 BD E8 C5 LDA.W $C5E8,X ; \
$00:C767 C9 FF CMP.B #$FF ; / A = command; $FF = end of script
$00:C769 D0 03 BNE $C76E ; Not the end: run it
$00:C76B 4C F8 C7 JMP.W $C7F8 ; End of script: return
$00:C76E 48 PHA ; Save the command
$00:C76F 29 10 AND.B #$10 ; \
$00:C771 F0 04 BEQ $C777 ; / Bit 4 clear: skip
$00:C773 22 A4 D4 0C JSL.L $D4A4 ; Bit 4 set: run a cutscene helper in bank $0C ($D4A4)
$00:C777 68 PLA ; Restore the command
$00:C778 A8 TAY ; Y = command
$00:C779 29 20 AND.B #$20 ; \
$00:C77B D0 0C BNE $C789 ; / Bit 5 set: special command ($00C789)
$00:C77D 84 15 STY RAM_ControllerA ; Held buttons [$15] = command byte
$00:C77F 98 TYA ; A = command
$00:C780 29 BF AND.B #$BF ; \
$00:C782 85 16 STA $16 ; / Newly pressed buttons [$16] = command without bit 6 (Y button)
$00:C784 20 39 CD JSR.W $CD39 ; Run Mario's movement with these inputs ($CD39)
$00:C787 80 6D BRA $C7F6 ; Continue at $00C7F6
$00:C789 98 TYA ; \
$00:C78A 29 0F AND.B #$0F ; } Low nibble of the command >= 7: set a Mario pose ($00C7E9)
$00:C78C C9 07 CMP.B #$07 ; /
$00:C78E B0 59 BCS $C7E9 ; Pose command
$00:C790 3A DEC A ; Nibble - 1
$00:C791 10 0F BPL $C7A2 ; Nibble >= 1: next test
$00:C793 AD 98 14 LDA.W RAM_PickUpImgTimer ; Command $20: [$1498] (pick-up image timer) set?
$00:C796 F0 05 BEQ $C79D ; No
$00:C798 A9 09 LDA.B #$09 ; \
$00:C79A 8D F9 1D STA.W $1DF9 ; / Play sound effect 9
$00:C79D EE 3E 14 INC.W RAM_ScrollSprNum ; Next cutscene step: [$143E]++
$00:C7A0 80 54 BRA $C7F6 ; Done
$00:C7A2 D0 05 BNE $C7A9 ; Nibble 1?
$00:C7A4 EE 45 14 INC.W $1445 ; Command $21: [$1445]++
$00:C7A7 80 4D BRA $C7F6 ; Done
$00:C7A9 3A DEC A ; Nibble 2?
$00:C7AA D0 0A BNE $C7B6 ; No
$00:C7AC A9 0E LDA.B #$0E ; \
$00:C7AE 8D F9 1D STA.W $1DF9 ; / Command $22: play sound effect $0E
$00:C7B1 EE 46 14 INC.W $1446 ; [$1446]++
$00:C7B4 80 40 BRA $C7F6 ; Done
$00:C7B6 3A DEC A ; Nibble 3?
$00:C7B7 D0 07 BNE $C7C0 ; No
$00:C7B9 A0 88 LDY.B #$88 ; Command $23: Y = $88
$00:C7BB 8C 45 14 STY.W $1445 ; [$1445] = $88
$00:C7BE 80 36 BRA $C7F6 ; Done
$00:C7C0 3A DEC A ; Nibble 4?
$00:C7C1 D0 0B BNE $C7CE ; No
$00:C7C3 A9 38 LDA.B #$38 ; \
$00:C7C5 8D 46 14 STA.W $1446 ; / Command $24: [$1446] = $38
$00:C7C8 A9 07 LDA.B #$07 ; \
$00:C7CA 14 94 TRB RAM_MarioXPos ; / Round Mario's X position down to a multiple of 8
$00:C7CC 80 28 BRA $C7F6 ; Done
$00:C7CE 3A DEC A ; Nibble 5?
$00:C7CF D0 0E BNE $C7DF ; No
$00:C7D1 A9 09 LDA.B #$09 ; \
$00:C7D3 8D FC 1D STA.W $1DFC ; / Command $25: play sound effect 9 on port $1DFC
$00:C7D6 A9 D8 LDA.B #$D8 ; \
$00:C7D8 85 7B STA RAM_MarioSpeedX ; / Mario X speed = $D8
$00:C7DA EE 3E 14 INC.W RAM_ScrollSprNum ; Next cutscene step: [$143E]++
$00:C7DD 80 BE BRA $C79D ; Then the same increment again ($00C79D)
$00:C7DF A9 20 LDA.B #$20 ; \
$00:C7E1 8D 98 14 STA.W RAM_PickUpImgTimer ; / Command $26: [$1498] (pick-up image timer) = $20
$00:C7E4 EE 8F 14 INC.W $148F ; [$148F]++
$00:C7E7 80 0D BRA $C7F6 ; Done
$00:C7E9 A8 TAY ; Y = nibble (>= 7)
$00:C7EA B9 DA C5 LDA.W ADDR_00C5DA,Y ; \
$00:C7ED 8D E0 13 STA.W MarioFrame ; / Mario pose [$13E0] = table at $00C5E1[nibble - 7]
$00:C7F0 9C 8F 14 STZ.W $148F ; [$148F] = 0
$00:C7F3 20 E4 D7 JSR.W $D7E4 ; Update Mario's flying/cape state ($D7E4)
$00:C7F6 C6 88 DEC $88 ; Frames left for this command - 1
$00:C7F8 60 RTS ; Return
;;; $C7F9..C7F9: Table: Yoshi wings exit thresholds ;;;
$00:C7F9 .db $C0,$FF,$A0,$00 ; Yoshi wings exit: Mario Y thresholds as signed words: -$40 (leaving), $A0 (returning)
;;; $C7FD: Mario animation 8: Yoshi wings exit (YoshiWingsAni) ;;;
;; Mario flies up (Y speed -$0D per frame up to -$70) while X speed decays to 0. When he passes the threshold
;; in $C7F9[[$1B95]] the
;; level reloads (phase 0, sets [$1B95] = 2) or normal control resumes (phase 2).
$00:C7FD 20 2D F6 JSR.W NoButtons ; No buttons allowed (NoButtons)
$00:C800 A9 0B LDA.B #$0B ; \
$00:C802 85 72 STA RAM_IsFlying ; / Flying state [$72] = $0B
$00:C804 20 E4 D7 JSR.W $D7E4 ; Update Mario's flying/cape state ($D7E4)
$00:C807 A5 7D LDA RAM_MarioSpeedY ; \
$00:C809 10 04 BPL $C80F ; / Y speed >= 0: accelerate upward
$00:C80B C9 90 CMP.B #$90 ; \
$00:C80D 90 05 BCC $C814 ; / Y speed already past -$70: skip
$00:C80F 38 SEC ; \
$00:C810 E9 0D SBC.B #$0D ; } Y speed -= $0D (fly up)
$00:C812 85 7D STA RAM_MarioSpeedY ; /
$00:C814 A9 02 LDA.B #$02 ; A = 2
$00:C816 A4 7B LDY RAM_MarioSpeedX ; \
$00:C818 F0 0D BEQ $C827 ; / No X speed: skip
$00:C81A 30 02 BMI $C81E ; Moving left: add 2
$00:C81C A9 FE LDA.B #$FE ; Moving right: add -2
$00:C81E 18 CLC ; \
$00:C81F 65 7B ADC RAM_MarioSpeedX ; } X speed += A: decay toward 0
$00:C821 85 7B STA RAM_MarioSpeedX ; /
$00:C823 50 02 BVC $C827 ; No overflow: ok
$00:C825 64 7B STZ RAM_MarioSpeedX ; Unreachable: X speed = 0
$00:C827 20 2D DC JSR.W $DC2D ; Process Mario's Y speed ($DC2D)
$00:C82A C2 20 REP #$20 ; A 16-bit
$00:C82C AC 95 1B LDY.W $1B95 ; Y = [$1B95] (phase: 0 = going out, 2 = coming back)
$00:C82F A5 80 LDA $80 ; A = [$80] (Mario Y relative to the screen)
$00:C831 D9 F9 C7 CMP.W $C7F9,Y ; Compare with the phase threshold (signed)
$00:C834 E2 20 SEP #$20 ; A 8-bit
$00:C836 10 0D BPL Instr00C845 ; Above the threshold: keep flying
$00:C838 64 71 STZ RAM_MarioAnimation ; Mario animation = 0 (normal control)
$00:C83A 98 TYA ; A = phase
$00:C83B D0 08 BNE Instr00C845 ; Coming back: done ($00C845)
$00:C83D C8 INY ; \
$00:C83E C8 INY ; } Phase = 2 for the return trip
$00:C83F 8C 95 1B STY.W $1B95 ; /
$00:C842 20 73 D2 JSR.W $D273 ; Load the next level ($D273)
;;; $C845: Jump stub and demo input script (Instr00C845) ;;;
;; $00C845: JMP to the Yoshi check at the end of Mario physics ($CD8F).
;; $C848: input script for EnterCastleAni, pairs of (controller byte, frame count), $FF ends it. Bit 6
;; of a byte has a special meaning (see code).
$00:C845 .db $4C,$8F,$CD ; Jump to the Yoshi check at the end of Mario's physics ($CD8F)
$00:C848 .db $01,$5F,$00,$30,$08,$30,$00,$20 ; Demo input script, pairs: controller byte, frames (01 = right, 08 = up, 40 = Y/run)
$00:C850 .db $40,$01,$00,$30,$01,$80,$FF,$01 ; (demo input script continues)
$00:C858 .db $3F,$00,$30,$20,$01,$80,$06,$00 ; (demo input script continues)
$00:C860 .db $3A,$01,$38,$00,$30,$08,$30,$00 ; (demo input script continues)
$00:C868 .db $20,$40,$01,$00,$30,$01,$80,$FF ; (demo input script continues)
;;; $C870: Mario animation A: scripted walk, level end (EnterCastleAni) ;;;
;; Mario animation $0A (Enter Castle): Mario plays back the controller script at $C848 and the normal
;; physics run on it; any new button press, or $FF in the script, ends it and sets the next game mode.
;; $00C915: level end handler for the end-of-level timer [$1493] (goal, switch palace, cutscene triggers),
;; jumped to from ResetAni.
;; Phase 1 walks Mario right while the timer runs, then starts the iris-out; phase 2 ($C9AF) shows the
;; peace pose, closes the iris and selects the next game mode and [$0DD5] exit type.
$00:C870 9C E2 13 STZ.W $13E2 ; [$13E2] = 0
$00:C873 AE 31 19 LDX.W $1931 ; \
$00:C876 3C 25 A6 BIT.W $A625,X ; |
$00:C879 30 0E BMI $C889 ; |
$00:C87B 70 06 BVS $C883 ; } Look up flags for tileset [$1931] in $A625: bit 7 set = third routine, bit 6 set = second, else first
$00:C87D 22 7C F5 02 JSL.L $F57C ; \
$00:C881 80 0A BRA $C88D ; / Default tileset: call $F57C (probably tileset-specific GFX/music setup), then continue
$00:C883 22 8C F5 02 JSL.L $F58C ; \
$00:C887 80 04 BRA $C88D ; / Bit 6 tileset: call $F58C, then continue
$00:C889 22 84 F5 02 JSL.L $F584 ; Bit 7 tileset: call $F584
$00:C88D A6 88 LDX $88 ; X = [$88]: current offset into the input script
$00:C88F A5 16 LDA $16 ; \
$00:C891 05 18 ORA $18 ; } A = [$16] | [$18] (newly pressed buttons)
$00:C893 20 2D F6 JSR.W NoButtons ; / Clear the controller mirrors (NoButtons); N set if any new button press: skip the script
$00:C896 30 63 BMI $C8FB ; Any new press: end the animation ($C8FB)
$00:C898 9C DE 13 STZ.W $13DE ; [$13DE] = 0
$00:C89B C6 89 DEC $89 ; Frames remaining in this script step: [$89]--
$00:C89D D0 09 BNE $C8A8 ; Still counting: keep the current step
$00:C89F E8 INX ; \
$00:C8A0 E8 INX ; |
$00:C8A1 86 88 STX $88 ; } Next script step: [$88] += 2
$00:C8A3 BD 47 C8 LDA.W ADDR_00C847,X ; \
$00:C8A6 85 89 STA $89 ; / [$89] = frame count of the new step
$00:C8A8 BD 46 C8 LDA.W ADDR_00C846,X ; A = controller byte of the current step
$00:C8AB C9 FF CMP.B #$FF ; \
$00:C8AD F0 4C BEQ $C8FB ; / $FF = end of script: end the animation
$00:C8AF 29 DF AND.B #$DF ; \
$00:C8B1 85 15 STA RAM_ControllerA ; / [$15] = held buttons = byte with bit 5 cleared (bit 5 is not a controller input, used as flag)
$00:C8B3 DD 46 C8 CMP.W ADDR_00C846,X ; \
$00:C8B6 F0 04 BEQ $C8BC ; / Was bit 5 set in the script byte? If not, skip the new-press fake
$00:C8B8 A0 80 LDY.B #$80 ; \
$00:C8BA 84 18 STY $18 ; / Fake a new A-button press ([$18] = $80), i.e. jump
$00:C8BC 0A ASL ; Script bit 6 into the sign flag
$00:C8BD 10 12 BPL $C8D1 ; Clear: skip the next block
$00:C8BF 20 2D F6 JSR.W NoButtons ; Bit 6 set: clear the controller mirrors again
$00:C8C2 A0 B0 LDY.B #$B0 ; Y = $B0
$00:C8C4 AE 31 19 LDX.W $1931 ; \
$00:C8C7 3C 25 A6 BIT.W $A625,X ; |
$00:C8CA 30 02 BMI $C8CE ; } Tileset flag bit 7 clear: Y = $7F instead
$00:C8CC A0 7F LDY.B #$7F ; Y = $7F
$00:C8CE 8C D9 18 STY.W $18D9 ; [$18D9] = Y (purpose unclear)
$00:C8D1 20 2D DC JSR.W $DC2D ; Apply Mario's speed to his position ($DC2D)
$00:C8D4 A9 24 LDA.B #$24 ; \
$00:C8D6 85 72 STA RAM_IsFlying ; / Mario is in the air state $24 (pretend jumping) while walking in
$00:C8D8 A9 6F LDA.B #$6F ; A = $6F: ground Y position for Mario
$00:C8DA AC 7A 18 LDY.W RAM_OnYoshi ; \
$00:C8DD F0 02 BEQ $C8E1 ; } Riding Yoshi?
$00:C8DF A9 5F LDA.B #$5F ; Yes: ground Y = $5F (Yoshi is taller)
$00:C8E1 AE 31 19 LDX.W $1931 ; \
$00:C8E4 3C 25 A6 BIT.W $A625,X ; |
$00:C8E7 50 03 BVC $C8EC ; } Tileset flag bit 6: ground is $10 higher
$00:C8E9 38 SEC ; \
$00:C8EA E9 10 SBC.B #$10 ; / Ground Y -= $10
$00:C8EC C5 96 CMP RAM_MarioYPos ; \
$00:C8EE B0 08 BCS $C8F8 ; / Mario Y position still above (or on) the ground line: skip landing
$00:C8F0 1A INC A ; \
$00:C8F1 85 96 STA RAM_MarioYPos ; / Land: Mario Y position = ground Y + 1
$00:C8F3 64 72 STZ RAM_IsFlying ; Mario is no longer in the air
$00:C8F5 9C 0D 14 STZ.W RAM_IsSpinJump ; Not spin jumping
$00:C8F8 4C 82 CD JMP.W $CD82 ; Run the normal Mario physics from $CD82
$00:C8FB EE 1D 14 INC.W $141D ; [$141D]++ (probably flags that the walk-in finished)
$00:C8FE A9 0F LDA.B #$0F ; \
$00:C900 8D 00 01 STA.W RAM_GameMode ; / Game mode = $0F
$00:C903 E0 11 CPX.B #$11 ; \
$00:C905 90 03 BCC $C90A ; / Script offset [$88] >= $11 (longer path)?
$00:C907 EE C1 0D INC.W RAM_OWHasYoshi ; Yes: [$0DC1]++ (RAM_OWHasYoshi)
$00:C90A A9 01 LDA.B #$01 ; \
$00:C90C 8D 9B 1B STA.W $1B9B ; / [$1B9B] = 1
$00:C90F A9 03 LDA.B #$03 ; \
$00:C911 8D FA 1D STA.W $1DFA ; / Play sound effect 3 on port $1DFA
$00:C914 60 RTS ; Return
$00:C915 20 2D F6 JSR.W NoButtons ; Clear the controller mirrors: Mario ignores input at level end
$00:C918 9C C2 18 STZ.W $18C2 ; [$18C2] = 0
$00:C91B 9C DE 13 STZ.W $13DE ; [$13DE] = 0
$00:C91E 9C ED 13 STZ.W $13ED ; [$13ED] = 0 (no slope sliding)
$00:C921 A5 5B LDA RAM_IsVerticalLvl ; \
$00:C923 4A LSR ; } Vertical level?
$00:C924 B0 1E BCS $C944 ; / Yes: skip to $C944
$00:C926 AD C6 13 LDA.W $13C6 ; \
$00:C929 0D D2 13 ORA.W $13D2 ; } A = [$13C6] | [$13D2] (cutscene number | switch palace flag, probably)
$00:C92C F0 3D BEQ $C96B ; Both zero: goal tape style ending ($C96B)
$00:C92E A5 72 LDA RAM_IsFlying ; \
$00:C930 F0 03 BEQ $C935 ; } Mario in the air?
$00:C932 20 E0 CC JSR.W $CCE0 ; / Yes: run his physics ($CCE0)
$00:C935 AD D2 13 LDA.W $13D2 ; [$13D2] non-zero (probably switch palace): go to $C948
$00:C938 D0 0E BNE $C948 ; Skip the next step
$00:C93A 20 3E B0 JSR.W $B03E ; Level end processing ($B03E)
$00:C93D AD 95 14 LDA.W $1495 ; \
$00:C940 C9 40 CMP.B #$40 ; } [$1495] < $40: wait (return)
$00:C942 90 26 BCC $C96A ; /
$00:C944 22 FF CB 05 JSL.L $CBFF ; Call $CBFF (level end routine in bank 05)
$00:C948 A0 01 LDY.B #$01 ; \
$00:C94A 84 9D STY RAM_SpritesLocked ; / Lock sprites ([$9D] = 1)
$00:C94C A5 13 LDA RAM_FrameCounter ; \
$00:C94E 4A LSR ; } Every other frame:
$00:C94F 90 19 BCC $C96A ; /
$00:C951 CE 93 14 DEC.W $1493 ; [$1493]--: level end timer
$00:C954 D0 14 BNE $C96A ; Not zero yet: return
$00:C956 AD D2 13 LDA.W $13D2 ; \
$00:C959 D0 07 BNE $C962 ; } [$13D2] set?
$00:C95B A0 0B LDY.B #$0B ; Y = $0B (game mode)
$00:C95D A9 01 LDA.B #$01 ; A = 1: normal exit
$00:C95F 4C FE C9 JMP.W $C9FE ; Jump to the exit code at $C9FE
$00:C962 A9 A0 LDA.B #$A0 ; \
$00:C964 8D F5 1D STA.W $1DF5 ; / [$1DF5] = $A0
$00:C967 EE 26 14 INC.W $1426 ; [$1426]++ (show the message box)
$00:C96A 60 RTS ; Return
$00:C96B 20 17 AF JSR.W $AF17 ; Count down the level end timer, fade out BG3 ($AF17)
$00:C96E AD 99 1B LDA.W $1B99 ; \
$00:C971 D0 3C BNE $C9AF ; } [$1B99] non-zero: phase 2 ($C9AF)
$00:C973 AD 93 14 LDA.W $1493 ; \
$00:C976 C9 28 CMP.B #$28 ; } Level end timer >= $28: Mario still walks right
$00:C978 90 0A BCC $C984 ; /
$00:C97A A9 01 LDA.B #$01 ; \
$00:C97C 85 76 STA RAM_MarioDirection ; | Mario faces right
$00:C97E 85 15 STA RAM_ControllerA ; | Hold right on the controller
$00:C980 A9 05 LDA.B #$05 ; |
$00:C982 85 7B STA RAM_MarioSpeedX ; / Mario X speed = 5
$00:C984 A5 72 LDA RAM_IsFlying ; \
$00:C986 F0 03 BEQ $C98B ; } In the air?
$00:C988 20 6B D7 JSR.W $D76B ; / Yes: handle slope/ground speed ($D76B)
$00:C98B A5 7B LDA RAM_MarioSpeedX ; \
$00:C98D D0 15 BNE Instr00C9A4 ; / Mario still moving: run normal physics (Instr00C9A4)
$00:C98F 9C 11 14 STZ.W $1411 ; [$1411] = 0 (no horizontal scrolling)
$00:C992 20 3E CA JSR.W $CA3E ; Start the iris-out: [$1433] = $F0 ($CA3E)
$00:C995 EE 99 1B INC.W $1B99 ; [$1B99]++: next phase
$00:C998 A9 40 LDA.B #$40 ; \
$00:C99A 8D 92 14 STA.W $1492 ; / [$1492] = $40: pause before the end music
$00:C99D 0A ASL ; \
$00:C99E 8D 94 14 STA.W $1494 ; } [$1494] = $80
$00:C9A1 9C 95 14 STZ.W $1495 ; [$1495] = 0
;;; $C9A4: Jump to Mario physics, cutscene level list (Instr00C9A4) ;;;
;; $00C9A4: JMP to $CD24 (Mario physics). $C9A7: level numbers ([$13BF]) that start cutscenes 1-8
;; when beaten.
$00:C9A4 .db $4C,$24,$CD ; Jump to Mario's physics ($CD24)
$00:C9A7 .db $25,$07,$40,$0E,$20,$1A,$34,$32 ; Level numbers ([$13BF]) that trigger cutscenes 1-8 (read backwards, index = cutscene)
$00:C9AF 20 31 CA JSR.W SetMarioPeaceImg ; Phase 2: show Mario's peace pose (SetMarioPeaceImg)
$00:C9B2 AD 92 14 LDA.W $1492 ; \
$00:C9B5 F0 0B BEQ $C9C2 ; } [$1492] pause timer zero?
$00:C9B7 CE 92 14 DEC.W $1492 ; [$1492]--
$00:C9BA D0 05 BNE $C9C1 ; Still counting: return
$00:C9BC A9 11 LDA.B #$11 ; \
$00:C9BE 8D FB 1D STA.W $1DFB ; / Request music $11 (level clear fanfare, probably)
$00:C9C1 60 RTS ; Return
$00:C9C2 20 44 CA JSR.W $CA44 ; Shrink the iris circle by 4 ($CA44)
$00:C9C5 A9 01 LDA.B #$01 ; \
$00:C9C7 85 15 STA RAM_ControllerA ; / Hold right
$00:C9C9 20 24 CD JSR.W $CD24 ; Run Mario's physics ($CD24)
$00:C9CC AD 33 14 LDA.W $1433 ; \
$00:C9CF D0 5F BNE $CA30 ; / Iris not fully closed: return
$00:C9D1 AD 1C 14 LDA.W $141C ; \
$00:C9D4 1A INC A ; |
$00:C9D5 C9 03 CMP.B #$03 ; |
$00:C9D7 D0 06 BNE $C9DF ; } Branch unless [$141C]+1 = 3 (value 2 never occurs)
$00:C9D9 A9 01 LDA.B #$01 ; \ Unreachable
$00:C9DB 8D 11 1F STA.W $1F11 ; | Set the submap to Yoshi's Island
$00:C9DE 4A LSR ; / A = 0
$00:C9DF A0 0C LDY.B #$0C ; Y = $0C (game mode to enter: probably overworld load)
$00:C9E1 AE 25 14 LDX.W $1425 ; \
$00:C9E4 F0 12 BEQ $C9F8 ; } [$1425] non-zero?
$00:C9E6 A2 FF LDX.B #$FF ; \
$00:C9E8 8E 25 14 STX.W $1425 ; / Yes: [$1425] = $FF
$00:C9EB A2 F0 LDX.B #$F0 ; \
$00:C9ED 8E B0 0D STX.W $0DB0 ; / [$0DB0] = $F0
$00:C9F0 9C 93 14 STZ.W $1493 ; [$1493] = 0
$00:C9F3 9C DA 0D STZ.W $0DDA ; [$0DDA] = 0
$00:C9F6 A0 10 LDY.B #$10 ; Y = $10 (other game mode)
$00:C9F8 9C AE 0D STZ.W $0DAE ; Screen brightness [$0DAE] = 0
$00:C9FB 9C AF 0D STZ.W $0DAF ; [$0DAF] = 0
$00:C9FE 8D D5 0D STA.W $0DD5 ; [$0DD5] = A: exit type (1 = normal, 2 = secret)
$00:CA01 AD C6 13 LDA.W $13C6 ; \
$00:CA04 F0 1F BEQ $CA25 ; / [$13C6] = 0 (no cutscene): skip to $CA25
$00:CA06 A2 08 LDX.B #$08 ; X = 8: number of entries to search
$00:CA08 AD BF 13 LDA.W $13BF ; A = current level number [$13BF]
$00:CA0B C9 13 CMP.B #$13 ; \
$00:CA0D D0 03 BNE $CA12 ; / Level $13? No: skip
$00:CA0F EE D5 0D INC.W $0DD5 ; Yes: [$0DD5]++
$00:CA12 C9 31 CMP.B #$31 ; \
$00:CA14 F0 0A BEQ $CA20 ; / Level $31: always cutscene 8
$00:CA16 DD A6 C9 CMP.W ADDR_00C9A6,X ; \
$00:CA19 F0 05 BEQ $CA20 ; / Search the list at $C9A7 backwards
$00:CA1B CA DEX ; \
$00:CA1C D0 F8 BNE $CA16 ; / Loop for all 8 entries
$00:CA1E 80 05 BRA $CA25 ; Not found: no cutscene
$00:CA20 8E C6 13 STX.W $13C6 ; [$13C6] = X: cutscene number
$00:CA23 A0 18 LDY.B #$18 ; Y = $18: game mode (probably cutscene)
$00:CA25 8C 00 01 STY.W RAM_GameMode ; Game mode = Y
$00:CA28 EE E9 1D INC.W $1DE9 ; [$1DE9]++
$00:CA2B A9 01 LDA.B #$01 ; \
$00:CA2D 8D CE 13 STA.W $13CE ; / [$13CE] = 1
$00:CA30 60 RTS ; Return
;;; $CA31: Peace pose and iris-out effect (SetMarioPeaceImg) ;;;
;; SetMarioPeaceImg: sets Mario frame $26 (peace sign), $14 on Yoshi.
;; $00CA3E: starts the iris-out by setting [$1433] = $F0. $00CA44: each frame while [$1433] is non-zero,
;; shrinks the radius by 4 and rebuilds the circle window.
;; $00CA6D: A = radius change. Builds a per-scanline window table (left, right) at $04A0 for HDMA channel 7,
;; centered on Mario, using the table at [$04]/[$06]; sets [$0D9F] = $80.
;; Called by:
;; $00:A1F9: Game mode 14: in level (InLevelGameMode)
;; $00:C9AF: Jump to Mario physics, cutscene level list (Instr00C9A4)
$00:CA31 A9 26 LDA.B #$26 ; \
$00:CA33 AC 7A 18 LDY.W RAM_OnYoshi ; |
$00:CA36 F0 02 BEQ $CA3A ; } Mario frame = $26 (peace sign), or $14 when riding Yoshi
$00:CA38 A9 14 LDA.B #$14 ; |
$00:CA3A 8D E0 13 STA.W MarioFrame ; / Store as Mario's pose
$00:CA3D 60 RTS ; Return
$00:CA3E A9 F0 LDA.B #$F0 ; \
$00:CA40 8D 33 14 STA.W $1433 ; / Iris-out radius [$1433] = $F0
$00:CA43 60 RTS ; Return
$00:CA44 AD 33 14 LDA.W $1433 ; \
$00:CA47 D0 01 BNE $CA4A ; / Iris active? [$1433] = 0: return
$00:CA49 60 RTS ; Return (iris finished)
$00:CA4A 20 61 CA JSR.W $CA61 ; Point the table pointers at the circle table ($CA61)
$00:CA4D A9 FC LDA.B #$FC ; \
$00:CA4F 20 6D CA JSR.W $CA6D ; / Shrink the radius by 4 and rebuild the HDMA window table ($CA6D)
$00:CA52 A9 33 LDA.B #$33 ; \
$00:CA54 85 41 STA $41 ; |
$00:CA56 85 43 STA $43 ; / [$41] = [$43] = $33: window 1 on BG1, BG2, OBJ, color
$00:CA58 A9 03 LDA.B #$03 ; \
$00:CA5A 85 42 STA $42 ; / [$42] = $03
$00:CA5C A9 22 LDA.B #$22 ; \
$00:CA5E 85 44 STA $44 ; / [$44] = $22: color window = window 1 inside
$00:CA60 60 RTS ; Return
$00:CA61 C2 20 REP #$20 ; A 16-bit
$00:CA63 A9 12 CB LDA.W #$CB12 ; \
$00:CA66 85 04 STA $04 ; | [$04] = [$06] = $CB12 (circle shape table)
$00:CA68 85 06 STA $06 ; /
$00:CA6A E2 20 SEP #$20 ; A 8-bit
$00:CA6C 60 RTS ; Return
$00:CA6D 18 CLC ; \
$00:CA6E 6D 33 14 ADC.W $1433 ; |
$00:CA71 8D 33 14 STA.W $1433 ; } [$1433] += A (iris radius)
$00:CA74 A5 7E LDA $7E ; \
$00:CA76 18 CLC ; |
$00:CA77 69 08 ADC.B #$08 ; |
$00:CA79 85 00 STA $00 ; } [$00] = Mario screen X + 8: iris center X
$00:CA7B A9 18 LDA.B #$18 ; \
$00:CA7D A4 19 LDY RAM_MarioPowerUp ; |
$00:CA7F F0 02 BEQ $CA83 ; |
$00:CA81 A9 10 LDA.B #$10 ; | A = $18 (small Mario) or $10 (powered up)
$00:CA83 18 CLC ; \
$00:CA84 65 80 ADC $80 ; |
$00:CA86 85 01 STA $01 ; } [$01] = Mario screen Y + A: iris center Y
$00:CA88 C2 30 REP #$30 ; A and X/Y 16-bit
$00:CA8A 29 FF 00 AND.W #$00FF ; \
$00:CA8D 0A ASL ; |
$00:CA8E 3A DEC A ; |
$00:CA8F 0A ASL ; |
$00:CA90 A8 TAY ; } Y = (centerY * 2 - 1) * 2: HDMA table offset of the mirrored line below
$00:CA91 E2 20 SEP #$20 ; A 8-bit
$00:CA93 A2 00 00 LDX.W #$0000 ; X = 0: HDMA table offset of the top line
$00:CA96 A5 01 LDA $01 ; \
$00:CA98 CD 33 14 CMP.W $1433 ; } [$01] = vertical distance to center; inside the circle?
$00:CA9B 90 20 BCC $CABD ; / Yes: compute the window edges
$00:CA9D A9 FF LDA.B #$FF ; \
$00:CA9F 9D A0 04 STA.W $04A0,X ; | Outside the circle: window left = $FF, right = $00 (empty)
$00:CAA2 9E A1 04 STZ.W $04A1,X ; /
$00:CAA5 C0 C0 01 CPY.W #$01C0 ; \
$00:CAA8 B0 07 BCS $CAB1 ; } Mirrored line index beyond the table: skip
$00:CAAA 99 A0 04 STA.W $04A0,Y ; \
$00:CAAD 1A INC A ; |
$00:CAAE 99 A1 04 STA.W $04A1,Y ; / Same empty window on the mirrored line (left $FF, right $00)
$00:CAB1 E8 INX ; \
$00:CAB2 E8 INX ; |
$00:CAB3 88 DEY ; |
$00:CAB4 88 DEY ; / Next line: X += 2, Y -= 2
$00:CAB5 A5 01 LDA $01 ; \
$00:CAB7 F0 51 BEQ $CB0A ; / Distance 0: done
$00:CAB9 C6 01 DEC $01 ; [$01]--
$00:CABB 80 D9 BRA $CA96 ; Next line
$00:CABD 20 14 CC JSR.W $CC14 ; Compute half-widths [$02] and [$03] for distance [$01] ($CC14)
$00:CAC0 18 CLC ; \
$00:CAC1 65 00 ADC $00 ; |
$00:CAC3 90 02 BCC $CAC7 ; | Right edge = center X + [$02], clamped to $FF
$00:CAC5 A9 FF LDA.B #$FF ; |
$00:CAC7 9D A1 04 STA.W $04A1,X ; / Top line window right edge
$00:CACA A5 00 LDA $00 ; \
$00:CACC 38 SEC ; |
$00:CACD E5 02 SBC $02 ; |
$00:CACF B0 02 BCS $CAD3 ; | Left edge = center X - [$02], clamped to 0
$00:CAD1 A9 00 LDA.B #$00 ; |
$00:CAD3 9D A0 04 STA.W $04A0,X ; / Top line window left edge
$00:CAD6 C0 E0 01 CPY.W #$01E0 ; \
$00:CAD9 B0 23 BCS $CAFE ; / Mirrored line out of range: skip
$00:CADB A5 07 LDA $07 ; \
$00:CADD D0 08 BNE $CAE7 ; / High byte of [$06] is zero: use an empty window
$00:CADF A9 00 LDA.B #$00 ; \
$00:CAE1 99 A1 04 STA.W $04A1,Y ; | Left = 0, right = 0 on the mirrored line, then A = $FF
$00:CAE4 3A DEC A ; |
$00:CAE5 80 14 BRA $CAFB ; / Store the left edge
$00:CAE7 A5 03 LDA $03 ; \
$00:CAE9 65 00 ADC $00 ; |
$00:CAEB 90 02 BCC $CAEF ; | Right edge = center X + [$03], clamped to $FF
$00:CAED A9 FF LDA.B #$FF ; |
$00:CAEF 99 A1 04 STA.W $04A1,Y ; / Mirrored line window right edge
$00:CAF2 A5 00 LDA $00 ; \
$00:CAF4 38 SEC ; |
$00:CAF5 E5 03 SBC $03 ; |
$00:CAF7 B0 02 BCS $CAFB ; | Left edge = center X - [$03], clamped to 0
$00:CAF9 A9 00 LDA.B #$00 ; |
$00:CAFB 99 A0 04 STA.W $04A0,Y ; / Mirrored line window left edge
$00:CAFE E8 INX ; \
$00:CAFF E8 INX ; |
$00:CB00 88 DEY ; |
$00:CB01 88 DEY ; / Next line: X += 2, Y -= 2
$00:CB02 A5 01 LDA $01 ; \
$00:CB04 F0 04 BEQ $CB0A ; / Distance 0: done
$00:CB06 C6 01 DEC $01 ; \
$00:CB08 D0 B3 BNE $CABD ; / [$01]--, loop while non-zero
$00:CB0A A9 80 LDA.B #$80 ; \
$00:CB0C 8D 9F 0D STA.W $0D9F ; / Enable HDMA channel 7 ([$0D9F] = $80) for the window
$00:CB0F E2 10 SEP #$10 ; X and Y 8-bit
$00:CB11 60 RTS ; Return
;;; $CB12..CC12: Data: iris shape tables ;;;
;; Circle half-width table (128 entries, then $00) followed by a second shape table (probably the keyhole).
$00:CB12 .db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ; Iris circle table: 256*sqrt(1 - t^2) for t = 0..1 in 128 steps
$00:CB1A .db $FF,$FF,$FF,$FF,$FE,$FE,$FE,$FE
$00:CB22 .db $FD,$FD,$FD,$FD,$FC,$FC,$FC,$FB
$00:CB2A .db $FB,$FB,$FA,$FA,$F9,$F9,$F8,$F8
$00:CB32 .db $F7,$F7,$F6,$F6,$F5,$F5,$F4,$F3
$00:CB3A .db $F3,$F2,$F1,$F1,$F0,$EF,$EE,$EE
$00:CB42 .db $ED,$EC,$EB,$EA,$E9,$E9,$E8,$E7
$00:CB4A .db $E6,$E5,$E4,$E3,$E2,$E1,$DF,$DE
$00:CB52 .db $DD,$DC,$DB,$DA,$D8,$D7,$D6,$D5
$00:CB5A .db $D3,$D2,$D0,$CF,$CD,$CC,$CA,$C9
$00:CB62 .db $C7,$C6,$C4,$C2,$C1,$BF,$BD,$BB
$00:CB6A .db $B9,$B7,$B6,$B4,$B1,$AF,$AD,$AB
$00:CB72 .db $A9,$A7,$A4,$A2,$9F,$9D,$9A,$97
$00:CB7A .db $95,$92,$8F,$8C,$89,$86,$82,$7F
$00:CB82 .db $7B,$78,$74,$70,$6C,$67,$63,$5E
$00:CB8A .db $59,$53,$4D,$46,$3F,$37,$2D,$1F
$00:CB92 .db $00,$54,$53,$52,$52,$51,$50,$50 ; End of circle table ($00); the $54.. values after it start another (probably keyhole) shape table
$00:CB9A .db $4F,$4E,$4E,$4D,$4C,$4C,$4B,$4A
$00:CBA2 .db $4A,$4B,$48,$48,$47,$46,$46,$45
$00:CBAA .db $44,$44,$43,$42,$42,$41,$40,$40
$00:CBB2 .db $3F,$3E,$3E,$3D,$3C,$3C,$3B,$3A
$00:CBBA .db $3A,$39,$38,$38,$37,$36,$36,$35
$00:CBC2 .db $34,$34,$33,$32,$32,$31,$33,$35
$00:CBCA .db $38,$3A,$3C,$3E,$3F,$41,$43,$44
$00:CBD2 .db $45,$47,$48,$49,$4A,$4B,$4C,$4D
$00:CBDA .db $4E,$4E,$4F,$50,$50,$51,$51,$52
$00:CBE2 .db $52,$53,$53,$53,$53,$53,$53,$53
$00:CBEA .db $53,$53,$53,$53,$53,$53,$52,$52
$00:CBF2 .db $51,$51,$50,$50,$4F,$4E,$4E,$4D
$00:CBFA .db $4C,$4B,$4A,$49,$48,$47,$45,$44
$00:CC02 .db $43,$41,$3F,$3E,$3C,$3A,$38,$35
$00:CC0A .db $33,$30,$2D,$2A,$26,$23,$1E,$18
$00:CC12 .db $11,$00
;;; $CC14: Iris half-width lookup ;;;
;; Computes the half-width of the iris window at vertical distance [$01] from its center, for radius [$1433],
;; using the hardware divider and multiplier.
;; Parameters: [$01]: distance, [$04]/[$06]: shape tables. Returns: [$02] and [$03]: half-widths, A = [$02].
;; Called by:
;; $00:CABD: Peace pose and iris-out effect (SetMarioPeaceImg)
$00:CC14 5A PHY ; Save Y
$00:CC15 A5 01 LDA $01 ; \
$00:CC17 8D 05 42 STA.W $4205 ; | Hardware divide: ([$01] * 256) / radius [$1433]
$00:CC1A 9C 04 42 STZ.W $4204 ; |
$00:CC1D AD 33 14 LDA.W $1433 ; |
$00:CC20 8D 06 42 STA.W $4206 ; / (distance / radius as a fraction of 256)
$00:CC23 EA NOP ; \
$00:CC24 EA NOP ; |
$00:CC25 EA NOP ; |
$00:CC26 EA NOP ; |
$00:CC27 EA NOP ; |
$00:CC28 EA NOP ; / Wait for the divide (16 cycles)
$00:CC29 C2 20 REP #$20 ; A 16-bit
$00:CC2B AD 14 42 LDA.W $4214 ; \
$00:CC2E 4A LSR ; | Y = quotient / 2: index 0-127 into the shape table
$00:CC2F A8 TAY ; /
$00:CC30 E2 20 SEP #$20 ; A 8-bit
$00:CC32 B1 06 LDA ($06),Y ; \
$00:CC34 8D 02 42 STA.W $4202 ; | Hardware multiply: [($06) + Y] * radius
$00:CC37 AD 33 14 LDA.W $1433 ; |
$00:CC3A 8D 03 42 STA.W $4203 ; /
$00:CC3D EA NOP ; \
$00:CC3E EA NOP ; |
$00:CC3F EA NOP ; |
$00:CC40 EA NOP ; / Wait for the multiply
$00:CC41 AD 17 42 LDA.W $4217 ; \
$00:CC44 85 03 STA $03 ; / [$03] = high byte of the product (half-width from table at [$06])
$00:CC46 B1 04 LDA ($04),Y ; \
$00:CC48 8D 02 42 STA.W $4202 ; | Same with the table at [$04]
$00:CC4B AD 33 14 LDA.W $1433 ; |
$00:CC4E 8D 03 42 STA.W $4203 ; /
$00:CC51 EA NOP ; \
$00:CC52 EA NOP ; |
$00:CC53 EA NOP ; |
$00:CC54 EA NOP ; / Wait for the multiply
$00:CC55 AD 17 42 LDA.W $4217 ; \
$00:CC58 85 02 STA $02 ; / [$02] = half-width from the table at [$04]
$00:CC5A 7A PLY ; Restore Y
$00:CC5B 60 RTS ; Return
;;; $CC5C..CC64: Data: debug free roam speeds ;;;
$00:CC5C .db $00,$00,$00,$00,$02,$00,$06,$00 ; Debug free roam speeds (words): 0, 0, +2, +6, -2, -6
$00:CC64 .db $FE,$FF,$FA,$FF ; (speed table continues)
;;; $CC68: Mario animation 0: normal per-frame handling (ResetAni) ;;;
;; Mario animation 0: the normal per-frame Mario routine. Debug mode toggle (unreachable), end-of-level
;; handler, L/R scrolling, lock timer, physics dispatch (normal, boss room/keyhole, climbing, swimming,
;; flying), pipe pose and Yoshi pose.
;; Returns with the Mario frame in $13E0 set when relevant.
$00:CC68 A5 17 LDA RAM_ControllerB ; \
$00:CC6A 29 20 AND.B #$20 ; |
$00:CC6C F0 13 BEQ $CC81 ; / L button held? (else skip the debug toggle)
$00:CC6E A5 18 LDA $18 ; \
$00:CC70 C9 80 CMP.B #$80 ; |
$00:CC72 D0 0D BNE $CC81 ; / ...and A newly pressed? (else skip)
$00:CC74 EE 01 1E INC.W $1E01 ; Cycle debug mode [$1E01]: 0 -> 1 -> 2 -> 0
$00:CC77 AD 01 1E LDA.W $1E01 ; \
$00:CC7A C9 03 CMP.B #$03 ; |
$00:CC7C 90 03 BCC $CC81 ; |
$00:CC7E 9C 01 1E STZ.W $1E01 ; / Wrap to 0 after 2
$00:CC81 AD 01 1E LDA.W $1E01 ; A = debug mode [$1E01]
$00:CC84 80 35 BRA $CCBB ; Always skip the debug code (change to BEQ to enable it)
$00:CC86 4A LSR ; Unused debug code: mode 1 = fill P-meter, mode 2 = free roaming
$00:CC87 F0 2A BEQ $CCB3 ; Mode 1: fill the P-meter
$00:CC89 A9 FF LDA.B #$FF ; \
$00:CC8B 8D 97 14 STA.W $1497 ; / [$1497] = $FF: Mario invincible
$00:CC8E A5 15 LDA RAM_ControllerA ; \
$00:CC90 29 03 AND.B #$03 ; |
$00:CC92 0A ASL ; |
$00:CC93 0A ASL ; | Y = left/right buttons * 4: index into the speed table
$00:CC94 A2 00 LDX.B #$00 ; / X = 0: horizontal
$00:CC96 20 9F CC JSR.W $CC9F ; Move Mario in X
$00:CC99 A5 15 LDA RAM_ControllerA ; \
$00:CC9B 29 0C AND.B #$0C ; | Up/down buttons
$00:CC9D A2 02 LDX.B #$02 ; / X = 2: vertical
$00:CC9F 24 15 BIT RAM_ControllerA ; \
$00:CCA1 50 02 BVC $CCA5 ; | Y button held: use the faster speed
$00:CCA3 09 02 ORA.B #$02 ; / (add 2 to the index)
$00:CCA5 A8 TAY ; Y = index into the speed table
$00:CCA6 C2 20 REP #$20 ; A 16-bit
$00:CCA8 B5 94 LDA RAM_MarioXPos,X ; \
$00:CCAA 18 CLC ; |
$00:CCAB 79 5C CC ADC.W $CC5C,Y ; | Mario position (X or Y) += speed
$00:CCAE 95 94 STA RAM_MarioXPos,X ; /
$00:CCB0 E2 20 SEP #$20 ; A 8-bit
$00:CCB2 60 RTS ; Return
$00:CCB3 A9 70 LDA.B #$70 ; \
$00:CCB5 8D E4 13 STA.W $13E4 ; / P-meter [$13E4] = $70
$00:CCB8 8D 9F 14 STA.W $149F ; Take-off timer [$149F] = $70
$00:CCBB AD 93 14 LDA.W $1493 ; \
$00:CCBE F0 03 BEQ $CCC3 ; } Level end timer [$1493] running?
$00:CCC0 4C 15 C9 JMP.W $C915 ; / Yes: level end handler ($C915)
$00:CCC3 20 DD CD JSR.W $CDDD ; L/R scroll handling ($CDDD)
$00:CCC6 A5 9D LDA RAM_SpritesLocked ; \
$00:CCC8 D0 15 BNE $CCDF ; / Sprites locked: return
$00:CCCA 9C E8 13 STZ.W $13E8 ; \
$00:CCCD 9C DE 13 STZ.W $13DE ; / [$13E8] = [$13DE] = 0 (no cape interaction)
$00:CCD0 AD BD 18 LDA.W RAM_LockMarioTimer ; \
$00:CCD3 F0 0B BEQ $CCE0 ; } Mario lock timer [$18BD] zero? Yes: run physics
$00:CCD5 CE BD 18 DEC.W RAM_LockMarioTimer ; Timer--
$00:CCD8 64 7B STZ RAM_MarioSpeedX ; Mario X speed = 0
$00:CCDA A9 0F LDA.B #$0F ; \
$00:CCDC 8D E0 13 STA.W MarioFrame ; / Mario frame = $0F (entering pipe pose)
$00:CCDF 60 RTS ; Return
$00:CCE0 AD 9B 0D LDA.W $0D9B ; \
$00:CCE3 10 3F BPL $CD24 ; } [$0D9B] bit 7 clear: normal level, run Mario physics ($CD24)
$00:CCE5 4A LSR ; \
$00:CCE6 B0 3C BCS $CD24 ; / Bit 0 set: same
$00:CCE8 2C 9B 0D BIT.W $0D9B ; \
$00:CCEB 70 2F BVS $CD1C ; / Bit 6 set: skip keyhole movement
$00:CCED A5 72 LDA RAM_IsFlying ; \
$00:CCEF D0 2B BNE $CD1C ; / Mario in the air: skip keyhole movement
$00:CCF1 C2 20 REP #$20 ; A 16-bit
$00:CCF3 AD 36 14 LDA.W RAM_KeyHolePos1 ; \
$00:CCF6 85 94 STA RAM_MarioXPos ; | Mario X position = keyhole X [$1436]
$00:CCF8 AD 38 14 LDA.W RAM_KeyHolePos2 ; |
$00:CCFB 85 96 STA RAM_MarioYPos ; / Mario Y position = keyhole Y [$1438]
$00:CCFD E2 20 SEP #$20 ; A 8-bit
$00:CCFF 20 2D DC JSR.W $DC2D ; Apply Mario's speed ($DC2D)
$00:CD02 C2 20 REP #$20 ; A 16-bit
$00:CD04 A5 94 LDA RAM_MarioXPos ; \
$00:CD06 8D 36 14 STA.W RAM_KeyHolePos1 ; | Store the new X back in [$1436] and [$14B4]
$00:CD09 8D B4 14 STA.W $14B4 ; /
$00:CD0C A5 96 LDA RAM_MarioYPos ; \
$00:CD0E 29 F0 FF AND.W #$FFF0 ; |
$00:CD11 8D 38 14 STA.W RAM_KeyHolePos2 ; | Store Y (low 4 bits cleared) in [$1438] and [$14B6]
$00:CD14 8D B6 14 STA.W $14B6 ; /
$00:CD17 20 C9 F9 JSR.W $F9C9 ; Update the keyhole ($F9C9)
$00:CD1A 80 03 BRA $CD1F ; Continue at $CD1F
$00:CD1C 20 2D DC JSR.W $DC2D ; Apply Mario's speed ($DC2D)
$00:CD1F 20 F2 F8 JSR.W $F8F2 ; Boss room interaction ($F8F2)
$00:CD22 80 12 BRA $CD36 ; Skip the normal interaction
$00:CD24 A5 7D LDA RAM_MarioSpeedY ; \
$00:CD26 10 08 BPL $CD30 ; } Mario moving down (Y speed >= 0): skip
$00:CD28 A5 77 LDA RAM_MarioObjStatus ; \
$00:CD2A 29 08 AND.B #$08 ; |
$00:CD2C F0 02 BEQ $CD30 ; } Moving up: blocked above by an object ([$77] bit 3)?
$00:CD2E 64 7D STZ RAM_MarioSpeedY ; / Yes: Y speed = 0
$00:CD30 20 2D DC JSR.W $DC2D ; Apply Mario's speed to his position ($DC2D)
$00:CD33 20 2B E9 JSR.W $E92B ; Mario interaction with level objects ($E92B)
$00:CD36 20 95 F5 JSR.W $F595 ; Keep Mario inside the screen limits ($F595)
$00:CD39 9C DD 13 STZ.W RAM_ChangingDir ; [$13DD] = 0: not changing direction
$00:CD3C AC F3 13 LDY.W $13F3 ; \
$00:CD3F D0 54 BNE $CD95 ; / [$13F3] non-zero: pipe pose, $CD95
$00:CD41 AD BE 18 LDA.W $18BE ; \
$00:CD44 F0 04 BEQ $CD4A ; } [$18BE] set?
$00:CD46 A9 1F LDA.B #$1F ; \
$00:CD48 85 8B STA $8B ; / Yes: [$8B] = $1F (touching all climbable tiles)
$00:CD4A A5 74 LDA RAM_IsClimbing ; \
$00:CD4C D0 24 BNE $CD72 ; / Already climbing: continue climbing ($CD72)
$00:CD4E AD 8F 14 LDA.W $148F If mario isn't holding something or riding yoshi ; \
$00:CD51 0D 7A 18 ORA.W RAM_OnYoshi jump to the status tests to determine his physical abilities ; } Holding an item or riding Yoshi: skip the climb check
$00:CD54 D0 23 BNE $CD79 else, continue on. ; /
$00:CD56 A5 8B LDA $8B ; \
$00:CD58 29 1B AND.B #$1B ; |
$00:CD5A C9 1B CMP.B #$1B ; } Mario touching the necessary climb tiles ([$8B] & $1B = $1B)?
$00:CD5C D0 1B BNE $CD79 ; /
$00:CD5E A5 15 LDA RAM_ControllerA ; \
$00:CD60 29 0C AND.B #$0C ; } Up or down pressed?
$00:CD62 F0 15 BEQ $CD79 ; /
$00:CD64 A4 72 LDY RAM_IsFlying ; \
$00:CD66 D0 0A BNE $CD72 ; } In the air: start climbing
$00:CD68 29 08 AND.B #$08 ; \
$00:CD6A D0 06 BNE $CD72 ; / On the ground: only if up is pressed
$00:CD6C A5 8B LDA $8B ; \
$00:CD6E 29 04 AND.B #$04 ; |
$00:CD70 F0 07 BEQ $CD79 ; / Unused path: needs [$8B] bit 2, else no climb
$00:CD72 A5 8B LDA $8B ; \
$00:CD74 85 74 STA RAM_IsClimbing ; / Start climbing: [$74] = [$8B]
$00:CD76 4C 17 DB JMP.W $DB17 ; Run the climbing code ($DB17)
$00:CD79 A5 75 LDA RAM_IsSwimming ; \
$00:CD7B F0 05 BEQ $CD82 ; / Not swimming: normal ground/air physics
$00:CD7D 20 88 D9 JSR.W $D988 ; Underwater physics ($D988)
$00:CD80 80 0D BRA $CD8F ; Then the Yoshi check
$00:CD82 20 F2 D5 JSR.W $D5F2 ; Generic physics ($D5F2)
$00:CD85 20 62 D0 JSR.W $D062 ; Power-up specific physics ($D062)
$00:CD88 20 E4 D7 JSR.W $D7E4 ; Flying/cape physics ($D7E4)
$00:CD8B 22 B1 CE 00 JSL.L $CEB1 ; Update the cape image and animation timer ($CEB1)
$00:CD8F AC 7A 18 LDY.W RAM_OnYoshi ; \
$00:CD92 D0 19 BNE $CDAD ; / Riding Yoshi: set Mario's Yoshi pose ($CDAD)
$00:CD94 60 RTS ; Return
$00:CD95 A9 42 LDA.B #$42 ; \
$00:CD97 A6 19 LDX RAM_MarioPowerUp ; |
$00:CD99 F0 02 BEQ $CD9D ; | A = $42 (small) or $43 (powered up): pipe entry pose
$00:CD9B A9 43 LDA.B #$43 ; /
$00:CD9D 88 DEY ; \
$00:CD9E F0 05 BEQ $CDA5 ; / [$13F3]-- : zero reached? Use the pose in A
$00:CDA0 8C F3 13 STY.W $13F3 ; Store the counter
$00:CDA3 A9 0F LDA.B #$0F ; Frame = $0F while the counter runs
$00:CDA5 8D E0 13 STA.W MarioFrame ; Set Mario's pose
$00:CDA8 60 RTS ; Return
;;; $CDA9: Yoshi poses and L/R scrolling (OnYoshiAnimations) ;;;
;; Table of Mario poses on Yoshi, then $CDAD (picks the pose from the Yoshi tongue timer [$14A3] and
;; ducking) and $CDDD (hold L or R to scroll the screen).
$00:CDA9 .db $20,$21,$27,$28 ; Mario poses on Yoshi: $20 normal, $21, $27 tongue out, $28 tongue shorter
$00:CDAD AE A3 14 LDX.W $14A3 ; \
$00:CDB0 F0 08 BEQ $CDBA ; } [$14A3] (Yoshi tongue timer) non-zero?
$00:CDB2 A0 03 LDY.B #$03 ; \
$00:CDB4 E0 0C CPX.B #$0C ; |
$00:CDB6 B0 02 BCS $CDBA ; | Y = 3 for timer >= $0C
$00:CDB8 A0 04 LDY.B #$04 ; / Y = 4 for a shorter timer
$00:CDBA B9 A8 CD LDA.W $CDA8,Y ; A = pose from the table (index Y - 1)
$00:CDBD 88 DEY ; \
$00:CDBE D0 06 BNE $CDC6 ; } Default pose (index 0)?
$00:CDC0 A4 73 LDY RAM_IsDucking ; \
$00:CDC2 F0 02 BEQ $CDC6 ; } Ducking?
$00:CDC4 A9 1D LDA.B #$1D ; / Yes: frame $1D
$00:CDC6 8D E0 13 STA.W MarioFrame ; Set Mario's pose
$00:CDC9 AD 1E 14 LDA.W RAM_YoshiHasWings ; \
$00:CDCC C9 01 CMP.B #$01 ; } Yoshi wings flag [$141E] = 1? (never true)
$00:CDCE D0 0C BNE $CDDC ; / No: return
$00:CDD0 24 16 BIT $16 ; \ Unreachable
$00:CDD2 50 08 BVC $CDDC ; | Y button newly pressed?
$00:CDD4 A9 08 LDA.B #$08 ; |
$00:CDD6 8D DB 18 STA.W $18DB ; | [$18DB] = 8
$00:CDD9 20 A8 FE JSR.W ShootFireball ; / Shoot a fireball while on Yoshi
$00:CDDC 60 RTS ; Return
$00:CDDD AD 11 14 LDA.W $1411 ; \
$00:CDE0 F0 FA BEQ $CDDC ; / L/R screen scrolling disabled ([$1411] = 0): return
$00:CDE2 AC FE 13 LDY.W $13FE ; Y = [$13FE] (scroll direction)
$00:CDE5 AD FD 13 LDA.W $13FD ; \
$00:CDE8 85 9D STA RAM_SpritesLocked ; / Sprites locked = [$13FD]
$00:CDEA D0 60 BNE $CE4C ; Locked: continue scrolling
$00:CDEC AD 00 14 LDA.W $1400 ; \
$00:CDEF F0 05 BEQ $CDF6 ; / [$1400] (camera scroll type) = 0?
$00:CDF1 9C FE 13 STZ.W $13FE ; [$13FE] = 0
$00:CDF4 80 52 BRA $CE48 ; Cancel the L/R hold timer
$00:CDF6 A5 17 LDA RAM_ControllerB ; \
$00:CDF8 29 CF AND.B #$CF ; |
$00:CDFA 05 15 ORA RAM_ControllerA ; } Any button besides L/R pressed?
$00:CDFC D0 4B BNE $CE49 ; / Yes: cancel
$00:CDFE A5 17 LDA RAM_ControllerB ; \
$00:CE00 29 30 AND.B #$30 ; | L or R pressed?
$00:CE02 F0 45 BEQ $CE49 ; / No: cancel
$00:CE04 C9 30 CMP.B #$30 ; \
$00:CE06 F0 41 BEQ $CE49 ; / Both: cancel
;;; $CE08: L/R screen scrolling (ScrollScreen) ;;;
;; Holding L or R for $10 frames moves the static camera region [$142A] toward the left or right limit,
;; freezing sprites while it moves, with a sound effect.
$00:CE08 4A LSR ; \
$00:CE09 4A LSR ; | A = $04 for L, $02 for R
$00:CE0A 4A LSR ; /
$00:CE0B EE 01 14 INC.W $1401 ; Hold timer [$1401]++
$00:CE0E AE 01 14 LDX.W $1401 ; \
$00:CE11 E0 10 CPX.B #$10 ; } Held less than $10 frames: keep waiting
$00:CE13 90 37 BCC $CE4C ; /
$00:CE15 AA TAX ; X = A
$00:CE16 C2 20 REP #$20 ; A 16-bit
$00:CE18 AD 2A 14 LDA.W $142A ; \
$00:CE1B DD CB F6 CMP.W $F6CB,X ; } Static camera position [$142A] compared to the target for this direction
$00:CE1E E2 20 SEP #$20 ; A 8-bit
$00:CE20 F0 2A BEQ $CE4C ; Already there: skip
$00:CE22 A9 01 LDA.B #$01 ; \
$00:CE24 1C 2A 14 TRB.W $142A ; / Clear bit 0 of [$142A]
$00:CE27 EE FD 13 INC.W $13FD ; [$13FD]++: freeze sprites while the screen scrolls
$00:CE2A A9 00 LDA.B #$00 ; A = 0
$00:CE2C E0 02 CPX.B #$02 ; \
$00:CE2E D0 03 BNE $CE33 ; / R pressed (X = 2): A = last screen - 1
$00:CE30 A5 5E LDA $5E ; \
$00:CE32 3A DEC A ; / (from [$5E])
$00:CE33 C2 20 REP #$20 ; A 16-bit
$00:CE35 EB XBA ; \
$00:CE36 29 00 FF AND.W #$FF00 ; | Compare the last screen position against the screen X [$1A]
$00:CE39 C5 1A CMP RAM_ScreenBndryXLo ; |
$00:CE3B E2 20 SEP #$20 ; /
$00:CE3D F0 05 BEQ $CE44 ; Equal: already at the edge, no sound
$00:CE3F A0 0E LDY.B #$0E ; \
$00:CE41 8C FC 1D STY.W $1DFC ; / Play sound effect $0E (scroll)
$00:CE44 8A TXA ; \
$00:CE45 8D FE 13 STA.W $13FE ; / [$13FE] = scroll direction
$00:CE48 A8 TAY ; Y = direction
$00:CE49 9C 01 14 STZ.W $1401 ; Hold timer [$1401] = 0
$00:CE4C A2 00 LDX.B #$00 ; X = 0
$00:CE4E A5 76 LDA RAM_MarioDirection ; \
$00:CE50 0A ASL ; | [$13FF] = Mario direction * 2
$00:CE51 8D FF 13 STA.W $13FF ; /
$00:CE54 C2 20 REP #$20 ; A 16-bit
$00:CE56 AD 2A 14 LDA.W $142A ; \
$00:CE59 D9 CB F6 CMP.W $F6CB,Y ; } Static camera position equal to the target?
$00:CE5C F0 0F BEQ $CE6D ; / Yes: done scrolling
$00:CE5E 18 CLC ; \
$00:CE5F 79 BF F6 ADC.W $F6BF,Y ; / Move the camera region toward the target by the step in $F6BF
$00:CE62 AC FF 13 LDY.W $13FF ; Y = Mario direction * 2
$00:CE65 D9 B3 F6 CMP.W $F6B3,Y ; \
$00:CE68 D0 06 BNE $CE70 ; } Reached the limit?
$00:CE6A 8E FE 13 STX.W $13FE ; Yes: stop scrolling
$00:CE6D 8E FD 13 STX.W $13FD ; Unfreeze sprites ([$13FD] = 0)
$00:CE70 8D 2A 14 STA.W $142A ; Store the camera region position
$00:CE73 8E 00 14 STX.W $1400 ; [$1400] = 0
$00:CE76 E2 20 SEP #$20 ; A 8-bit
$00:CE78 60 RTS ; Return
;;; $CE79..CE97: Data: Mario slide poses ;;;
;; Frame numbers $2A-$2F, and the slope sliding table indexed by slope and direction.
$00:CE79 .db $2A,$2B,$2C,$2D,$2E,$2F ; Mario poses for sliding: $2A-$2F
$00:CE7F .db $2C,$2C,$2C,$2B,$2B,$2C,$2C,$2B ; Mario poses sliding on slopes, indexed by slope and direction
$00:CE87 .db $2B,$2C,$2D,$2A,$2A,$2D,$2D,$2A ; (slide poses continue)
$00:CE8F .db $2A,$2D,$2D,$2A,$2A,$2D,$2E,$2A ; (slide poses continue)
$00:CE97 .db $2A,$2E ; (slide poses end)
;;; $CE99..CEA9: Data: spin jump tables ;;;
;; $CE99: frame values, $CEA1: Mario facing during a spin jump, $CEA9: cape images.
$00:CE99 .db $00,$00,$25,$44,$00,$00,$0F,$45 ; Spin jump poses (indexed by frame counter), used with the cape code
$00:CEA1 .db $00,$00,$00,$00,$01,$01,$01,$01 ; Mario direction during a spin jump: 0 = left, 1 = right
$00:CEA9 .db $02,$07,$06,$09,$02,$07,$06,$09 ; Cape images during a spin jump
;;; $CEB1: Cape image update (air) ;;;
;; Called from ResetAni with JSL. Updates the cape image [$13DF] and its animation timer [$14A2] depending on
;; Mario being in the air, falling, swimming or running; continues in the next chunk with the spin jump code.
;; Called by:
;; $00:94F2: Cutscene, ending and game mode code (castle scenes, credits, game over) (CutsceneCastlePal)
;; $00:CD8B: Mario animation 0: normal per-frame handling (ResetAni)
;; $00:D19D: Mario animation 5: horizontal pipe (DoorPipeAni)
;; $00:DA7F: Swimming physics and controls
;; $04:85C5: Draw border icon and player map sprites (DrawOWBoarder?)
;; $0C:A75F: Ending: eggshell fragments and Yoshi helpers
$00:CEB1 AD A2 14 LDA.W $14A2 ; \
$00:CEB4 D0 60 BNE lbl14A2Not0 ; } Cape animation timer [$14A2] running: skip the update
$00:CEB6 AE DF 13 LDX.W $13DF ; X = cape image [$13DF]
$00:CEB9 A5 72 LDA RAM_IsFlying ; \
$00:CEBB F0 21 BEQ MarioAnimAir ; / On the ground: ground handling (MarioAnimAir)
$00:CEBD A0 04 LDY.B #$04 ; Y = 4: timer base in the air
$00:CEBF 24 7D BIT RAM_MarioSpeedY ; \
$00:CEC1 10 0A BPL $CECD ; / Mario falling: $CECD
$00:CEC3 C9 0C CMP.B #$0C ; \
$00:CEC5 F0 36 BEQ $CEFD ; / Run jump ($72 = $0C): $CEFD
$00:CEC7 A5 75 LDA RAM_IsSwimming ; \
$00:CEC9 D0 32 BNE $CEFD ; / Swimming: $CEFD
$00:CECB 80 17 BRA MrioNtInWtr ; Otherwise $CEE4
$00:CECD E8 INX ; \
$00:CECE E0 05 CPX.B #$05 ; |
$00:CED0 B0 04 BCS $CED6 ; | Falling: cape image + 1; if below 5 set it to 5
$00:CED2 A2 05 LDX.B #$05 ; |
$00:CED4 80 34 BRA $CF0A ; /
$00:CED6 E0 0B CPX.B #$0B ; \
$00:CED8 90 30 BCC $CF0A ; / Image < $0B: keep
$00:CEDA A2 07 LDX.B #$07 ; \
$00:CEDC 80 2C BRA $CF0A ; / Else image = 7
;;; $CEDE: Cape update: on ground (MarioAnimAir) ;;;
;; On the ground: X speed non-zero goes to the speed based timer, else Y = 8.
$00:CEDE A5 7B LDA RAM_MarioSpeedX ; \
$00:CEE0 D0 0E BNE $CEF0 ; / On the ground, moving: $CEF0
$00:CEE2 A0 08 LDY.B #$08 ; Standing still: Y = 8
;;; $CEE4: Cape update: step image down (MrioNtInWtr) ;;;
;; Decreases the cape image toward 2 and ends in the shared store of [$13DF]/[$14A2] at $CF0A.
$00:CEE4 8A TXA ; \
$00:CEE5 F0 23 BEQ $CF0A ; / Cape image zero: keep
$00:CEE7 CA DEX ; \
$00:CEE8 E0 03 CPX.B #$03 ; |
$00:CEEA 90 1E BCC $CF0A ; | Cape image - 1; if < 3 keep it
$00:CEEC A2 02 LDX.B #$02 ; |
$00:CEEE 80 1A BRA $CF0A ; / Else image = 2
$00:CEF0 10 03 BPL $CEF5 ; \
$00:CEF2 49 FF EOR.B #$FF ; | A = abs(X speed)
$00:CEF4 1A INC A ; /
$00:CEF5 4A LSR ; \
$00:CEF6 4A LSR ; |
$00:CEF7 4A LSR ; | A = speed / 8
$00:CEF8 A8 TAY ; /
$00:CEF9 B9 7C DC LDA.W $DC7C,Y ; \
$00:CEFC A8 TAY ; / Y = cape timer from $DC7C
$00:CEFD E8 INX ; \
$00:CEFE E0 03 CPX.B #$03 ; |
$00:CF00 B0 02 BCS $CF04 ; |
$00:CF02 A2 05 LDX.B #$05 ; / Cape image + 1; if < 3, image = 5
$00:CF04 E0 07 CPX.B #$07 ; \
$00:CF06 90 02 BCC $CF0A ; |
$00:CF08 A2 03 LDX.B #$03 ; / Image >= 7: image = 3
$00:CF0A 8E DF 13 STX.W $13DF ; [$13DF] = cape image
$00:CF0D 98 TYA ; \
$00:CF0E A4 75 LDY RAM_IsSwimming ; | A = timer
$00:CF10 F0 01 BEQ $CF13 ; |
$00:CF12 0A ASL ; / Doubled when swimming
$00:CF13 8D A2 14 STA.W $14A2 ; [$14A2] = timer
;;; $CF16: Choose Mario pose: spin, slide, duck, walk (lbl14A2Not0) ;;;
;; Second half of the Mario pose selector (earlier part is in the chunk before). Picks the pose number for
;; this frame and ends by
;; storing it in MarioFrame via $D01A.
;; Order: spin jump or cape spin, slope slide, ducking, fireball, kick, pick-up, face camera, then
;; walking/standing based on
;; |X speed|. Falls into MarioAnimNoAbs1.
$00:CF16 AD 0D 14 LDA.W RAM_IsSpinJump ; \
$00:CF19 0D A6 14 ORA.W $14A6 ; / Spin jump or cape spin active ([RAM_IsSpinJump] | [$14A6])?
$00:CF1C F0 30 BEQ $CF4E ; Neither: go to the normal pose selection at $CF4E
$00:CF1E 64 73 STZ RAM_IsDucking ; Not ducking
$00:CF20 A5 14 LDA RAM_FrameCounterB ; \
$00:CF22 29 06 AND.B #$06 ; |
$00:CF24 AA TAX ; |
$00:CF25 A8 TAY ; / X = Y = [RAM_FrameCounterB] & 6 (cycles through 4 spin poses)
$00:CF26 A5 72 LDA RAM_IsFlying ; \
$00:CF28 F0 05 BEQ $CF2F ; / On the ground: skip the Y adjustment
$00:CF2A A5 7D LDA RAM_MarioSpeedY ; \
$00:CF2C 30 01 BMI $CF2F ; / Moving up: skip the Y adjustment
$00:CF2E C8 INY ; Falling: Y += 1 (second cape image of the pair)
$00:CF2F B9 A9 CE LDA.W $CEA9,Y ; \
$00:CF32 8D DF 13 STA.W $13DF ; / Cape image [$13DF] = $CEA9[Y]
$00:CF35 A5 19 LDA RAM_MarioPowerUp ; A = power-up status
$00:CF37 F0 01 BEQ $CF3A ; Small Mario: leave X alone
$00:CF39 E8 INX ; Big/cape/fire: X += 1
$00:CF3A BD A1 CE LDA.W $CEA1,X ; \
$00:CF3D 85 76 STA RAM_MarioDirection ; / Mario direction = $CEA1[X] (spin makes Mario face left/right in turn)
$00:CF3F A4 19 LDY RAM_MarioPowerUp ; \
$00:CF41 C0 02 CPY.B #$02 ; |
$00:CF43 D0 03 BNE $CF48 ; |
$00:CF45 20 44 D0 JSR.W $D044 ; / Cape Mario: set the cape interaction point ($D044)
$00:CF48 BD 99 CE LDA.W $CE99,X ; \
$00:CF4B 4C 1A D0 JMP.W $D01A ; / A = $CE99[X] (spin pose), go store it as Mario's pose ($D01A)
$00:CF4E AD ED 13 LDA.W $13ED ; \
$00:CF51 F0 0F BEQ $CF62 ; |
$00:CF53 10 30 BPL $CF85 ; / [$13ED] = 0: go to $CF62; 1-$7F: use it as the pose ($CF85)
$00:CF55 AD E1 13 LDA.W $13E1 ; \
$00:CF58 4A LSR ; |
$00:CF59 4A LSR ; |
$00:CF5A 05 76 ORA RAM_MarioDirection ; |
$00:CF5C A8 TAY ; / Y = ([$13E1] >> 2) | direction (sliding on a slope)
$00:CF5D B9 7F CE LDA.W $CE7F,Y ; A = slide pose $CE7F[Y]
$00:CF60 80 23 BRA $CF85 ; Go store the pose
$00:CF62 A9 3C LDA.B #$3C ; \
$00:CF64 AC 8F 14 LDY.W $148F ; |
$00:CF67 F0 02 BEQ $CF6B ; |
$00:CF69 A9 1D LDA.B #$1D ; / A = $3C (probably ducking pose), or $1D if carrying an item ([$148F] != 0)
$00:CF6B A4 73 LDY RAM_IsDucking ; \
$00:CF6D D0 16 BNE $CF85 ; / Ducking while jumping: use that pose ($CF85)
$00:CF6F AD 9C 14 LDA.W RAM_FireballImgTimer ; \
$00:CF72 F0 0A BEQ $CF7E ; / Fireball pose timer = 0: go to $CF7E
$00:CF74 A9 3F LDA.B #$3F ; A = $3F: probably throwing-fireball pose on the ground
$00:CF76 A4 72 LDY RAM_IsFlying ; \
$00:CF78 F0 0B BEQ $CF85 ; / On the ground: use $3F
$00:CF7A A9 16 LDA.B #$16 ; \
$00:CF7C 80 07 BRA $CF85 ; / In the air: A = $16 instead, use it
$00:CF7E A9 0E LDA.B #$0E ; A = $0E: kick pose
$00:CF80 AC 9A 14 LDY.W RAM_KickImgTimer ; \
$00:CF83 F0 03 BEQ $CF88 ; / Kick timer = 0: go on to $CF88, else fall into the store
$00:CF85 4C 1A D0 JMP.W $D01A ; Use A as Mario's pose: go to $D01A
$00:CF88 A9 1D LDA.B #$1D ; A = $1D: pick-up pose
$00:CF8A AC 98 14 LDY.W RAM_PickUpImgTimer ; \
$00:CF8D D0 F6 BNE $CF85 ; / Pick-up timer non-zero: use that pose
$00:CF8F A9 0F LDA.B #$0F ; A = $0F: facing-the-camera pose
$00:CF91 AC 99 14 LDY.W RAM_FaceCamImgTimer ; \
$00:CF94 D0 EF BNE $CF85 ; / Face-camera timer non-zero: use that pose
$00:CF96 A9 00 LDA.B #$00 ; A = 0: default pose
$00:CF98 AE C2 18 LDX.W $18C2 ; X = [$18C2] (purpose unknown)
$00:CF9B D0 26 BNE MarioAnimNoAbs1 ; Non-zero: go to MarioAnimNoAbs1 (A = 0, acts as standing still)
$00:CF9D A5 72 LDA RAM_IsFlying ; \
$00:CF9F F0 16 BEQ $CFB7 ; / On the ground: go to $CFB7
$00:CFA1 AC A0 14 LDY.W $14A0 ; \
$00:CFA4 D0 16 BNE $CFBC ; / [$14A0] non-zero: go to the walk animation code ($CFBC)
$00:CFA6 AC 07 14 LDY.W $1407 ; Y = [$1407] (cape flight phase)
$00:CFA9 F0 03 BEQ $CFAE ; Zero: keep A = 0
$00:CFAB B9 78 CE LDA.W $CE78,Y ; A = table at $00CE78[Y] (cape flying pose)
$00:CFAE AC 8F 14 LDY.W $148F ; \
$00:CFB1 F0 67 BEQ $D01A ; / Not carrying anything: use A as the pose
$00:CFB3 A9 09 LDA.B #$09 ; \
$00:CFB5 80 63 BRA $D01A ; / Carrying an item in the air: pose $09
$00:CFB7 AD DD 13 LDA.W RAM_ChangingDir ; \
$00:CFBA D0 5E BNE $D01A ; / Turning around: keep pose 0
$00:CFBC A5 7B LDA RAM_MarioSpeedX ; \
$00:CFBE 10 03 BPL MarioAnimNoAbs1 ; |
$00:CFC0 49 FF EOR.B #$FF ; |
$00:CFC2 1A INC A ; / A = |Mario X speed| (also entered by JSL from DoorPipeAni)
;;; $CFC3: Walk animation frame counter (MarioAnimNoAbs1) ;;;
;; Takes A = |X speed|. If standing still, resets the walk frame (or sets 'looking up' pose offset 3 when Up
;; is held).
;; Otherwise counts the walk frame [$13DB] down whenever the animation timer [$1496] has run out and reloads
;; the timer from
;; $DC7C (shorter timer at higher speeds). Leaves the new frame in B for Remember.
$00:CFC3 AA TAX ; X = |X speed|
$00:CFC4 D0 0E BNE $CFD4 ; Moving: go to $CFD4
$00:CFC6 EB XBA ; Stash A (= 0) in B: walk frame resets to 0
$00:CFC7 A5 15 LDA RAM_ControllerA ; \
$00:CFC9 29 08 AND.B #$08 ; |
$00:CFCB F0 35 BEQ $D002 ; / Up not held: go to $D002
$00:CFCD A9 03 LDA.B #$03 ; \
$00:CFCF 8D DE 13 STA.W $13DE ; |
$00:CFD2 80 2E BRA $D002 ; / Up held: pose offset [$13DE] = 3 (looking up), go to $D002
$00:CFD4 A5 86 LDA $86 ; \
$00:CFD6 F0 0B BEQ $CFE3 ; / Level not slippery ([$86] = 0): go to $CFE3
$00:CFD8 A5 15 LDA RAM_ControllerA ; \
$00:CFDA 29 03 AND.B #$03 ; |
$00:CFDC F0 25 BEQ $D003 ; / Left/Right not held: go to $D003 (A = 0)
$00:CFDE A9 68 LDA.B #$68 ; \
$00:CFE0 8D E5 13 STA.W $13E5 ; / [$13E5] = $68: animation speed class used in slippery levels
$00:CFE3 AD DB 13 LDA.W $13DB ; A = [$13DB] (walk frame number)
$00:CFE6 AC 96 14 LDY.W $1496 ; \
$00:CFE9 D0 18 BNE $D003 ; / Animation timer [$1496] non-zero: keep the frame, go to $D003
$00:CFEB 3A DEC A ; Previous walk frame: A -= 1
$00:CFEC 10 05 BPL $CFF3 ; \
$00:CFEE A4 19 LDY RAM_MarioPowerUp ; |
$00:CFF0 B9 78 DC LDA.W NumWalkingFrames,Y ; / Underflow: wrap to NumWalkingFrames[power-up] (last frame)
$00:CFF3 EB XBA ; Stash the frame number in B
$00:CFF4 8A TXA ; \
$00:CFF5 4A LSR ; |
$00:CFF6 4A LSR ; |
$00:CFF7 4A LSR ; / A = |X speed| / 8
$00:CFF8 0D E5 13 ORA.W $13E5 ; \
$00:CFFB A8 TAY ; / Y = A | [$13E5]
$00:CFFC B9 7C DC LDA.W $DC7C,Y ; A = $DC7C[Y]: frames to show the next walk frame (shorter when faster)
$00:CFFF 8D 96 14 STA.W $1496 ; Animation timer [$1496] = A
;;; $D002: Finish pose: add offsets, store frame (Remember) ;;;
;; Parameters: A = walk frame, X = |X speed|.
;; Stores the walk frame in [$13DB], adds the pose offset [$13DE] (+7 carrying an item, +4 when fast), then
;; handles the 45 degree
;; slope poses. Entries at $D01A (A = final pose) and $D003 are jumped to from the code above.
; You can get somewhere quick by pressing ctrl+f and typing in the address.
$00:D002 EB XBA ; A = new walk frame (swap B back into A)
$00:D003 8D DB 13 STA.W $13DB ; Walk frame [$13DB] = A
$00:D006 18 CLC ; \
$00:D007 6D DE 13 ADC.W $13DE ; / A += [$13DE] (pose offset: walking, running...)
$00:D00A AC 8F 14 LDY.W $148F ; \
$00:D00D F0 05 BEQ $D014 ; |
$00:D00F 18 CLC ; |
$00:D010 69 07 ADC.B #$07 ; |
$00:D012 80 06 BRA $D01A ; / Carrying an item: A += 7, go to $D01A
$00:D014 E0 2F CPX.B #$2F ; \
$00:D016 90 02 BCC $D01A ; |
$00:D018 69 03 ADC.B #$03 ; / |X speed| >= $2F (running): A += 4 (carry is set)
$00:D01A AC E3 13 LDY.W RAM_WallWalkStatus ; \
$00:D01D F0 11 BEQ MarioAnimNo45 ; / Not on a 45 degree slope: go to MarioAnimNo45
$00:D01F 98 TYA ; \
$00:D020 29 01 AND.B #$01 ; |
$00:D022 85 76 STA RAM_MarioDirection ; / Mario direction = [RAM_WallWalkStatus] & 1
$00:D024 A9 10 LDA.B #$10 ; \
$00:D026 C0 06 CPY.B #$06 ; |
$00:D028 90 06 BCC MarioAnimNo45 ; / Status < 6: pose = $10, go store it
$00:D02A AD DB 13 LDA.W $13DB ; \
$00:D02D 18 CLC ; |
$00:D02E 69 11 ADC.B #$11 ; / Status >= 6: pose = [$13DB] + $11
;;; $D030: Store Mario pose and return (MarioAnimNo45) ;;;
;; Writes A to MarioFrame and returns (RTL), ending the pose selector.
$00:D030 8D E0 13 STA.W MarioFrame ; Mario pose [MarioFrame] = A
$00:D033 6B RTL ; Return
;;; $D034..D03C: Table: cape interaction offsets ;;;
;; Two tables of four 16-bit offsets from Mario's position, indexed by 2 * A; used by $D044 for the cape
;; hit point.
$00:D034 .db $0C,$00,$F4,$FF,$08,$00,$F8,$FF ; Cape point X offsets, 16-bit words: +$0C, -$0C, +$08, -$08
$00:D03C .db $10,$00,$10,$00,$02,$00,$02,$00 ; Cape point Y offsets, 16-bit words: $10, $10, 2, 2
;;; $D044: Cape hit point, cape spin and fireball input ;;;
;; $D044: sets the cape interaction point [$13E9]/[$13EB] from Mario's position plus a table offset.
;; $D062: called each frame; Cape Mario starts a spin ([$14A6] = $12) when Y is pressed (not ducking, on Yoshi
;; or already spinning).
;; Fire Mario shoots a fireball when Y is pressed, or alternately left and right every 16 frames while spin
;; jumping.
;; Called by:
;; $00:CF45: Choose Mario pose: spin, slide, duck, walk (lbl14A2Not0)
;; $00:DB8C: Mario climbing, tile and position tables (ClimbPunchingImgs)
$00:D044 A0 01 LDY.B #$01 ; \
$00:D046 8C E8 13 STY.W $13E8 ; / Cape interaction flag [$13E8] = 1
$00:D049 0A ASL ; \
$00:D04A A8 TAY ; / Y = A * 2 (word index)
$00:D04B C2 20 REP #$20 ; A 16-bit
$00:D04D A5 94 LDA RAM_MarioXPos ; \
$00:D04F 18 CLC ; |
$00:D050 79 34 D0 ADC.W $D034,Y ; |
$00:D053 8D E9 13 STA.W $13E9 ; / Cape interaction X [$13E9] = Mario X + $D034[Y]
$00:D056 A5 96 LDA RAM_MarioYPos ; \
$00:D058 18 CLC ; |
$00:D059 79 3C D0 ADC.W $D03C,Y ; |
$00:D05C 8D EB 13 STA.W $13EB ; / Cape interaction Y [$13EB] = Mario Y + $D03C[Y]
$00:D05F E2 20 SEP #$20 ; A 8-bit
$00:D061 60 RTS ; Return
$00:D062 A5 19 LDA RAM_MarioPowerUp ; \
$00:D064 C9 02 CMP.B #$02 ; |
$00:D066 D0 19 BNE $D081 ; / Not cape Mario: go to $D081
$00:D068 24 16 BIT $16 ; \
$00:D06A 50 41 BVC $D0AD ; / Y not newly pressed: return
$00:D06C A5 73 LDA RAM_IsDucking ; \
$00:D06E 0D 7A 18 ORA.W RAM_OnYoshi ; |
$00:D071 0D 0D 14 ORA.W RAM_IsSpinJump ; |
$00:D074 D0 37 BNE $D0AD ; / Ducking, on Yoshi or spin jumping: return
$00:D076 A9 12 LDA.B #$12 ; \
$00:D078 8D A6 14 STA.W $14A6 ; / Cape spin timer [$14A6] = $12 (start cape spin)
$00:D07B A9 04 LDA.B #$04 ; \
$00:D07D 8D FC 1D STA.W $1DFC ; / Play sound effect $04 on $1DFC
$00:D080 60 RTS ; Return
$00:D081 C9 03 CMP.B #$03 ; \
$00:D083 D0 28 BNE $D0AD ; / Not Fire Mario: return
$00:D085 A5 73 LDA RAM_IsDucking ; \
$00:D087 0D 7A 18 ORA.W RAM_OnYoshi ; |
$00:D08A D0 21 BNE $D0AD ; / Ducking or on Yoshi: return
$00:D08C 24 16 BIT $16 ; \
$00:D08E 70 1A BVS $D0AA ; / Y newly pressed: shoot a fireball ($D0AA)
$00:D090 AD 0D 14 LDA.W RAM_IsSpinJump ; \
$00:D093 F0 18 BEQ $D0AD ; / Not spin jumping: return
$00:D095 EE E2 13 INC.W $13E2 ; \
$00:D098 AD E2 13 LDA.W $13E2 ; |
$00:D09B 29 0F AND.B #$0F ; |
$00:D09D D0 0E BNE $D0AD ; / Spin jump: count frames in [$13E2], act only every 16th frame
$00:D09F A8 TAY ; Y = 0
$00:D0A0 AD E2 13 LDA.W $13E2 ; \
$00:D0A3 29 10 AND.B #$10 ; |
$00:D0A5 F0 01 BEQ $D0A8 ; |
$00:D0A7 C8 INY ; / Y = bit 4 of the counter (alternates every 16 frames)
$00:D0A8 84 76 STY RAM_MarioDirection ; Mario direction = Y (fireballs alternate left and right)
$00:D0AA 20 A8 FE JSR.W ShootFireball ; Shoot a fireball (ShootFireball)
$00:D0AD 60 RTS ; Return
;;; $D0AE..D0AE: Unused data ;;;
$00:D0AE .db $7C,$00,$80,$00,$00,$06,$00,$01 ; Unused data, purpose unknown
;;; $D0B6: Mario animation 9: death (MarioDeathAni) ;;;
;; Sets the death pose and counts down the death timer [$1496] (every 4 frames). When it expires: exits the
;; level with no event
;; ([$0DD5] = $80), loses Yoshi, takes a life and chooses Game Over, Time Up or fade to overworld.
$00:D0B6 64 19 STZ RAM_MarioPowerUp ; Power-up = 0 (small)
$00:D0B8 A9 3E LDA.B #$3E ; \
$00:D0BA 8D E0 13 STA.W MarioFrame ; / Mario pose = $3E (death pose)
$00:D0BD A5 13 LDA RAM_FrameCounter ; \
$00:D0BF 29 03 AND.B #$03 ; |
$00:D0C1 D0 03 BNE $D0C6 ; |
$00:D0C3 CE 96 14 DEC.W $1496 ; / Every 4th frame: [$1496] -= 1 (death timer)
$00:D0C6 AD 96 14 LDA.W $1496 ; \
$00:D0C9 D0 3D BNE DeathNotDone ; / Timer non-zero: go to DeathNotDone
$00:D0CB A9 80 LDA.B #$80 ; \
$00:D0CD 8D D5 0D STA.W $0DD5 ; / [$0DD5] = $80: leave the level with no exit event
$00:D0D0 AD 9B 1B LDA.W $1B9B ; \
$00:D0D3 D0 03 BNE $D0D8 ; / [$1B9B] set: skip clearing
$00:D0D5 9C C1 0D STZ.W RAM_OWHasYoshi ; Clear [RAM_OWHasYoshi] (Yoshi is lost on death)
$00:D0D8 CE BE 0D DEC.W RAM_StatusLives ; Lives -= 1
$00:D0DB 10 09 BPL DeathNotGameOver ; Lives still >= 0: go to DeathNotGameOver
$00:D0DD A9 0A LDA.B #$0A ; \
$00:D0DF 8D FB 1D STA.W $1DFB ; / Music request $0A on $1DFB (probably Game Over music)
$00:D0E2 A2 14 LDX.B #$14 ; X = $14: death message = GAME OVER
$00:D0E4 80 0F BRA DeathShowMessage ; Show the message
;;; $D0E6: Death: choose fade to overworld or Time Up (DeathNotGameOver) ;;;
;; Y = game mode $0B (fade to overworld) unless the level timer ran out, in which case X = $1D (TIME UP
;; message) is used.
$00:D0E6 A0 0B LDY.B #$0B ; Y = $0B: game mode = fade to overworld
$00:D0E8 AD 31 0F LDA.W $0F31 ; \
$00:D0EB 0D 32 0F ORA.W $0F32 ; |
$00:D0EE 0D 33 0F ORA.W $0F33 ; |
$00:D0F1 D0 11 BNE DeathNotTimeUp ; / Level time digits [$0F31]-[$0F33] non-zero: go to $D104
$00:D0F3 A2 1D LDX.B #$1D ; X = $1D: death message = TIME UP
;;; $D0F5: Death: start the message and set game mode (DeathShowMessage) ;;;
;; Parameters: X = message number ($14 GAME OVER, $1D TIME UP), Y = game mode to switch to.
;; Sets the message number, animation and timer, then game mode $15 (fade to Game Over).
$00:D0F5 8E 3B 14 STX.W $143B ; Death message [$143B] = X
$00:D0F8 A9 C0 LDA.B #$C0 ; \
$00:D0FA 8D 3C 14 STA.W $143C ; / Death message animation [$143C] = $C0
$00:D0FD A9 FF LDA.B #$FF ; \
$00:D0FF 8D 3D 14 STA.W $143D ; / Death message timer [$143D] = $FF
$00:D102 A0 15 LDY.B #$15 ; Y = $15: game mode = fade to Game Over
;;; $D104: Death: set game mode and return (DeathNotTimeUp) ;;;
;; Game mode = Y.
$00:D104 8C 00 01 STY.W RAM_GameMode ; Game mode = Y
$00:D107 60 RTS ; Return
;;; $D108: Death: Mario falls, flips pose (DeathNotDone) ;;;
;; While the death timer is < $26 Mario's X speed is zeroed, Y speed is applied and the death pose flips
;; left/right every 4 frames.
$00:D108 C9 26 CMP.B #$26 ; \
$00:D10A B0 10 BCS DeathNotDoneEnd ; / Death timer >= $26: return (Mario hangs in place first)
$00:D10C 64 7B STZ RAM_MarioSpeedX ; Mario X speed = 0
$00:D10E 20 2D DC JSR.W $DC2D ; Apply Mario Y speed ($DC2D)
$00:D111 20 2E D9 JSR.W $D92E ; Update Mario Y speed ($D92E)
$00:D114 A5 13 LDA RAM_FrameCounter ; \
$00:D116 4A LSR ; |
$00:D117 4A LSR ; |
$00:D118 29 01 AND.B #$01 ; |
$00:D11A 85 76 STA RAM_MarioDirection ; / Mario direction = bit 2 of frame counter (flips every 4 frames)
;;; $D11C: Return (DeathNotDoneEnd) ;;;
$00:D11C 60 RTS ; Return
;;; $D11D: Table: Mario poses while changing size (GrowingAniImgs) ;;;
$00:D11D .db $00,$3D,$00,$3D,$00,$3D,$46,$3D ; Pose numbers used while changing size, indexed by timer / 4
$00:D125 .db $46,$3D,$46,$3D ; (continued)
;;; $D129: Mario animation 1: power down (PowerDownAni) ;;;
;; Counts [$1496] down, showing poses from GrowingAniImgs. When it reaches 0, starts the invincibility flash
;; ([$1497] = $7F) and
;; ends the animation.
$00:D129 AD 96 14 LDA.W $1496 ; \
$00:D12C F0 12 BEQ $D140 ; / Animation timer [$1496] = 0: finished, go to $D140
$00:D12E 4A LSR ; \
$00:D12F 4A LSR ; |
$00:D130 A8 TAY ; / Y = timer / 4
$00:D131 B9 1D D1 LDA.W GrowingAniImgs,Y ; \
$00:D134 8D E0 13 STA.W MarioFrame ; / Mario pose = GrowingAniImgs[Y]
$00:D137 AD 96 14 LDA.W $1496 ; \
$00:D13A F0 03 BEQ $D13F ; / Timer = 0: return
$00:D13C CE 96 14 DEC.W $1496 ; Timer -= 1
$00:D13F 60 RTS ; Return
$00:D140 A9 7F LDA.B #$7F ; \
$00:D142 8D 97 14 STA.W $1497 ; / Invincibility flash timer [$1497] = $7F (about 2 seconds)
$00:D145 80 11 BRA $D158 ; Go end the animation and unlock sprites ($D158)
;;; $D147: Mario animation 2: mushroom power up (MushroomAni) ;;;
;; Plays the grow poses in reverse as [$1496] counts down; then power-up += 1 and the animation ends.
$00:D147 AD 96 14 LDA.W $1496 ; \
$00:D14A F0 0A BEQ $D156 ; / Timer = 0: done, go to $D156
$00:D14C 4A LSR ; \
$00:D14D 4A LSR ; |
$00:D14E 49 FF EOR.B #$FF ; |
$00:D150 1A INC A ; |
$00:D151 18 CLC ; |
$00:D152 69 0B ADC.B #$0B ; / Y = $0B - timer / 4 (poses played in reverse)
$00:D154 80 DA BRA $D130 ; Go look up the pose ($D130)
$00:D156 E6 19 INC RAM_MarioPowerUp ; Power-up += 1
$00:D158 A9 00 LDA.B #$00 ; \
$00:D15A 85 71 STA RAM_MarioAnimation ; / Mario animation [RAM_MarioAnimation] = 0 (none)
$00:D15C 64 9D STZ RAM_SpritesLocked ; Unlock sprites
$00:D15E 60 RTS ; Return
;;; $D15F: Mario animation 3: cape power up (CapeAni) ;;;
;; Hides Mario under the smoke puff. When the timer ends: small/big go to the flash code, cape/fire end the
;; animation directly.
$00:D15F A9 7F LDA.B #$7F ; \
$00:D161 85 78 STA $78 ; / [$78] = $7F: hide Mario (smoke puff)
$00:D163 CE 96 14 DEC.W $1496 ; Timer [$1496] -= 1
$00:D166 D0 F6 BNE $D15E ; Not finished: return
$00:D168 A5 19 LDA RAM_MarioPowerUp ; \
$00:D16A 4A LSR ; |
$00:D16B F0 D3 BEQ $D140 ; / Small or big Mario: go to $D140 (flash)
$00:D16D D0 E9 BNE $D158 ; Cape or fire: go to $D158 (no flash)
;;; $D16F: Mario animation 4: flower power up (FlowerAni) ;;;
;; Cancels cape flight and sliding, resets the pose, and counts down the flashing palette timer. Ends the
;; animation when it is 0.
$00:D16F AD ED 13 LDA.W $13ED ; \
$00:D172 29 80 AND.B #$80 ; |
$00:D174 0D 07 14 ORA.W $1407 ; |
$00:D177 F0 0E BEQ $D187 ; / [$13ED] bit 7 and [$1407] both clear: go to $D187
$00:D179 9C 07 14 STZ.W $1407 ; Cape flight phase [$1407] = 0
$00:D17C AD ED 13 LDA.W $13ED ; \
$00:D17F 29 7F AND.B #$7F ; |
$00:D181 8D ED 13 STA.W $13ED ; / Clear bit 7 of [$13ED]
$00:D184 9C E0 13 STZ.W MarioFrame ; Mario pose = 0
$00:D187 CE 9B 14 DEC.W RAM_FlashingPalTimer ; Flashing palette timer -= 1
$00:D18A F0 CC BEQ $D158 ; Done: go to $D158
$00:D18C 60 RTS ; Return
;;; $D18D: Table: pipe X speeds (left, right) (PipeSpeedX) ;;;
$00:D18D .db $F8,$08 ; X speed for pipe direction 0 (left), 1 (right)
;;; $D18F: Table: pipe Y speeds (PipeSpeedY) ;;;
$00:D18F .db $00,$00,$F0 ; Pipe speed bytes: $00,$00 (X speed for up/down), $F0 (Y speed, up)
$00:D192 .db $10 ; Y speed for down pipe
;;; $D193: Table: Mario hide values by pipe type (HIDEPIPESETS) ;;;
$00:D193 .db $00,$63,$1C,$00 ; Values for [$78] by pipe type, indexed [$89] / 2 + 1
;;; $D197: Mario animation 5: horizontal pipe (DoorPipeAni) ;;;
;; Ignores the controller, picks a walking pose, centers Mario on the pipe tile vertically, handles the face-
;; camera timer and hides
;; Mario while he moves through the pipe. Shares its tail with VertPipeAni ($D22D). Helper at $D1F4 ticks
;; [$14A2] and the animation timer.
$00:D197 20 2D F6 JSR.W NoButtons ; Ignore controller input (NoButtons)
$00:D19A 9C DE 13 STZ.W $13DE ; Pose offset [$13DE] = 0
$00:D19D 22 B1 CE 00 JSL.L $CEB1 ; Run the pose selection start ($CEB1)
$00:D1A1 22 BC CF 00 JSL.L $CFBC ; Pick a walking pose from the X speed (enters at $CFBC)
$00:D1A5 20 F4 D1 JSR.W $D1F4 ; Tick timers ($D1F4)
$00:D1A8 AD 7A 18 LDA.W RAM_OnYoshi ; \
$00:D1AB F0 05 BEQ $D1B2 ; / Not on Yoshi: skip
$00:D1AD A9 29 LDA.B #$29 ; \
$00:D1AF 8D E0 13 STA.W MarioFrame ; / On Yoshi: pose $29 (entering horizontal pipe)
$00:D1B2 C2 20 REP #$20 ; A 16-bit
$00:D1B4 A5 96 LDA RAM_MarioYPos ; \
$00:D1B6 38 SEC ; |
$00:D1B7 E9 08 00 SBC.W #$0008 ; |
$00:D1BA 29 F0 FF AND.W #$FFF0 ; |
$00:D1BD 09 0E 00 ORA.W #$000E ; |
$00:D1C0 85 96 STA RAM_MarioYPos ; / Mario Y = ((Y - 8) & $FFF0) | $0E (center on the pipe)
$00:D1C2 E2 20 SEP #$20 ; A 8-bit
$00:D1C4 A5 89 LDA $89 ; \
$00:D1C6 4A LSR ; |
$00:D1C7 A8 TAY ; |
$00:D1C8 C8 INY ; / Y = [$89] / 2 + 1 (pipe type index)
$00:D1C9 B9 92 D1 LDA.W $D192,Y ; A = $D192[Y]
$00:D1CC AE 8F 14 LDX.W $148F ; \
$00:D1CF F0 0A BEQ $D1DB ; / Not carrying: go to $D1DB
$00:D1D1 49 1C EOR.B #$1C ; Carrying: A ^= $1C
$00:D1D3 CE 99 14 DEC.W RAM_FaceCamImgTimer ; \
$00:D1D6 10 03 BPL $D1DB ; |
$00:D1D8 EE 99 14 INC.W RAM_FaceCamImgTimer ; / Face-camera timer -= 1, but not below 0
$00:D1DB A6 88 LDX $88 ; \
$00:D1DD E0 1D CPX.B #$1D ; |
$00:D1DF B0 0F BCS $D1F0 ; / Pipe timer [$88] >= $1D: go store A to [$78] ($D1F0)
$00:D1E1 C0 03 CPY.B #$03 ; \
$00:D1E3 90 08 BCC $D1ED ; / Y < 3: skip the Y adjustment
$00:D1E5 C2 20 REP #$20 ; A 16-bit
$00:D1E7 E6 96 INC RAM_MarioYPos ; \
$00:D1E9 E6 96 INC RAM_MarioYPos ; / Mario Y += 2
$00:D1EB E2 20 SEP #$20 ; A 8-bit
$00:D1ED B9 93 D1 LDA.W HIDEPIPESETS,Y ; A = HIDEPIPESETS[Y]
$00:D1F0 85 78 STA $78 ; [$78] = A (hide Mario for the pipe)
$00:D1F2 80 39 BRA $D22D ; Go to the shared pipe code ($D22D)
$00:D1F4 AD A2 14 LDA.W $14A2 ; \
$00:D1F7 F0 03 BEQ $D1FC ; |
$00:D1F9 CE A2 14 DEC.W $14A2 ; / Decrement [$14A2] if non-zero
$00:D1FC 4C 37 D1 JMP.W $D137 ; Go decrement the animation timer ($D137)
;;; $D1FF: Table: pipe X center targets (PipeCntrBoundryX) ;;;
$00:D1FF .db $0A,$06 ; Mario X & $F targets for centering on a pipe: direction 0 = $0A, 1 = $06
;;; $D201: Table: pipe centering speed (PipeCntringSpeed) ;;;
$00:D201 .db $FF,$01 ; X nudge per frame: -1 or +1
;;; $D203: Mario animation 6: vertical pipe (VertPipeAni) ;;;
;; Handles all pipe travel (vertical and horizontal). Centers Mario on Yoshi, sets pose, fakes X/Y held, puts
;; Mario behind scenery,
;; sets his speed from [$89] & 3 while the timer [$88] counts down, hides him when it ends, and then either
;; finishes (leaving a pipe)
;; or loads the next level (game mode $0F, entering a pipe). $D27C is unused.
$00:D203 20 2D F6 JSR.W NoButtons ; Ignore controller input (NoButtons)
$00:D206 9C DF 13 STZ.W $13DF ; Cape image [$13DF] = 0
$00:D209 A9 0F LDA.B #$0F ; \
$00:D20B AC 7A 18 LDY.W RAM_OnYoshi ; |
$00:D20E F0 1A BEQ $D22A ; / A = $0F (facing camera); not on Yoshi: use it ($D22A)
$00:D210 A2 00 LDX.B #$00 ; X = 0: nudge index
$00:D212 A4 76 LDY RAM_MarioDirection ; Y = Mario direction
$00:D214 A5 94 LDA RAM_MarioXPos ; \
$00:D216 29 0F AND.B #$0F ; |
$00:D218 D9 FF D1 CMP.W PipeCntrBoundryX,Y ; / Compare [X pos] & $F with PipeCntrBoundryX[Y]
$00:D21B F0 0B BEQ $D228 ; Equal: centered, go to $D228
$00:D21D 10 01 BPL $D220 ; At or past the target: nudge left (X = 0)
$00:D21F E8 INX ; Before the target: X = 1 (nudge right)
$00:D220 A5 94 LDA RAM_MarioXPos ; \
$00:D222 18 CLC ; |
$00:D223 7D 01 D2 ADC.W PipeCntringSpeed,X ; |
$00:D226 85 94 STA RAM_MarioXPos ; / Mario X += PipeCntringSpeed[X]
$00:D228 A9 21 LDA.B #$21 ; A = $21: pose going down a pipe on Yoshi
$00:D22A 8D E0 13 STA.W MarioFrame ; Mario pose = A
$00:D22D A9 40 LDA.B #$40 ; \
$00:D22F 85 15 STA RAM_ControllerA ; / Fake controller input: X/Y held
$00:D231 A9 02 LDA.B #$02 ; \
$00:D233 8D F9 13 STA.W RAM_IsBehindScenery ; / Behind-scenery flag = 2
$00:D236 A5 89 LDA $89 ; \
$00:D238 C9 04 CMP.B #$04 ; |
$00:D23A A4 88 LDY $88 ; |
$00:D23C F0 2A BEQ $D268 ; / C = [$89] >= 4 (leaving a pipe); Y = [$88]: timer 0: go to $D268
$00:D23E 29 03 AND.B #$03 ; \
$00:D240 A8 TAY ; / Y = [$89] & 3 (0 left, 1 right, 2 up, 3 down)
$00:D241 C6 88 DEC $88 ; Pipe timer [$88] -= 1
$00:D243 D0 09 BNE $D24E ; \
$00:D245 B0 07 BCS $D24E ; / Still counting or leaving: go to $D24E
$00:D247 A9 7F LDA.B #$7F ; \
$00:D249 85 78 STA $78 ; / [$78] = $7F: hide Mario
$00:D24B EE 05 14 INC.W $1405 ; [$1405] += 1 (probably marks the pipe entry as done)
$00:D24E A5 7B LDA RAM_MarioSpeedX ; \
$00:D250 05 7D ORA RAM_MarioSpeedY ; |
$00:D252 D0 05 BNE $D259 ; |
$00:D254 A9 04 LDA.B #$04 ; |
$00:D256 8D F9 1D STA.W $1DF9 ; / Mario not moving yet: play sound $04 on $1DF9 (pipe)
$00:D259 B9 8D D1 LDA.W PipeSpeedX,Y ; \
$00:D25C 85 7B STA RAM_MarioSpeedX ; / Mario X speed = PipeSpeedX[Y]
$00:D25E B9 8F D1 LDA.W PipeSpeedY,Y ; \
$00:D261 85 7D STA RAM_MarioSpeedY ; / Mario Y speed = PipeSpeedY[Y]
$00:D263 64 72 STZ RAM_IsFlying ; Not flying
$00:D265 4C 2D DC JMP.W $DC2D ; Apply the speed ($DC2D), return
$00:D268 90 09 BCC $D273 ; Entering a pipe: go to $D273 to load the next level
$00:D26A 9C F9 13 STZ.W RAM_IsBehindScenery ; \
$00:D26D 9C 19 14 STZ.W RAM_YoshiInPipe ; / Clear behind-scenery and Yoshi-in-pipe flags
$00:D270 4C 58 D1 JMP.W $D158 ; End the animation and unlock sprites ($D158)
$00:D273 EE 1A 14 INC.W $141A ; \
$00:D276 A9 0F LDA.B #$0F ; |
$00:D278 8D 00 01 STA.W RAM_GameMode ; / [$141A] += 1 and game mode = $0F (load level)
$00:D27B 60 RTS ; Return
$00:D27C A5 96 LDA RAM_MarioYPos ; Unused code: [$88] += Mario Y - [$D3]
$00:D27E 38 SEC ; |
$00:D27F E5 D3 SBC $D3 ; |
$00:D281 18 CLC ; |
$00:D282 65 88 ADC $88 ; |
$00:D284 85 88 STA $88 ; |
$00:D286 60 RTS ; Return
;;; $D287: Mario animation 7: shot from pipe cannon (PipeCannonAni) ;;;
;; Flies Mario out of a diagonal pipe at X speed $40, Y speed $C0 while the timer [$88] counts down. Plays a
;; sound at $18 and then
;; puts Mario in front of the scenery, unlocks sprites; finishes like leaving a pipe.
$00:D287 20 2D F6 JSR.W NoButtons ; Ignore controller input (NoButtons)
$00:D28A A9 02 LDA.B #$02 ; \
$00:D28C 8D F9 13 STA.W RAM_IsBehindScenery ; / Behind-scenery flag = 2
$00:D28F A9 0C LDA.B #$0C ; \
$00:D291 85 72 STA RAM_IsFlying ; / [RAM_IsFlying] = $0C (airborne)
$00:D293 20 8B CD JSR.W $CD8B ; Pose selection ($CD8B)
$00:D296 C6 88 DEC $88 ; Timer [$88] -= 1
$00:D298 D0 03 BNE $D29D ; Not 0: go to $D29D
$00:D29A 4C 6A D2 JMP.W $D26A ; Timer ran out: finish like leaving a pipe ($D26A)
$00:D29D A5 88 LDA $88 ; \
$00:D29F C9 18 CMP.B #$18 ; |
$00:D2A1 90 07 BCC $D2AA ; |
$00:D2A3 D0 0D BNE $D2B2 ; / Timer < $18: go to $D2AA; > $18: go to $D2B2
$00:D2A5 A9 09 LDA.B #$09 ; \
$00:D2A7 8D FC 1D STA.W $1DFC ; / Play sound effect $09 on $1DFC (probably the cannon blast)
$00:D2AA 9C F9 13 STZ.W RAM_IsBehindScenery ; \
$00:D2AD 9C 19 14 STZ.W RAM_YoshiInPipe ; |
$00:D2B0 64 9D STZ RAM_SpritesLocked ; / Behind-scenery flag = 0, Yoshi-in-pipe = 0, sprites unlocked
$00:D2B2 A9 40 LDA.B #$40 ; \
$00:D2B4 85 7B STA RAM_MarioSpeedX ; / Mario X speed = $40
$00:D2B6 A9 C0 LDA.B #$C0 ; \
$00:D2B8 85 7D STA RAM_MarioSpeedY ; / Mario Y speed = $C0 (up)
$00:D2BA 4C 2D DC JMP.W $DC2D ; Apply the speed ($DC2D)
;;; $D2BD..D2C5: Table: jump Y speed by X speed ;;;
$00:D2BD .db $B0,$B6,$AE,$B4,$AB,$B2,$A9,$B0 ; Initial jump Y speed, indexed by X speed (faster = higher jump)
$00:D2C5 .db $A6,$AE,$A4,$AB,$A1,$A9,$9F,$A6 ; (continued)
;;; $D2CD..D305: Table: X decelerations, ground and air ;;;
;; 16-bit decelerations indexed by slope state; used by the X speed code around $D78C.
$00:D2CD .db $00,$FF,$00,$01,$00,$FF,$00,$01 ; X deceleration (16-bit) used on ground/air, indexed by slope state
$00:D2D5 .db $00,$FF,$00,$01,$80,$FE,$C0,$00 ; when not holding down a button
$00:D2DD .db $40,$FF,$80,$01,$00,$FE,$40,$00
$00:D2E5 .db $C0,$FF,$00,$02,$00,$FE,$40,$00
$00:D2ED .db $00,$FE,$40,$00,$C0,$FF,$00,$02
$00:D2F5 .db $C0,$FF,$00,$02,$00,$FC,$00,$FF
$00:D2FD .db $00,$01,$00,$04,$00,$FF,$00,$01
$00:D305 .db $00,$FF,$00,$01
;;; $D309..D341: Table: X decelerations, water ;;;
;; 16-bit decelerations used instead of $D2CD when in a water level.
$00:D309 .db $E0,$FF,$20,$00,$E0,$FF,$20,$00 ; X deceleration (16-bit) used in water levels
$00:D311 .db $E0,$FF,$20,$00,$C0,$FF,$20,$00
$00:D319 .db $E0,$FF,$40,$00,$80,$FF,$20,$00
$00:D321 .db $E0,$FF,$80,$00,$80,$FF,$20,$00
$00:D329 .db $80,$FF,$20,$00,$E0,$FF,$80,$00
$00:D331 .db $E0,$FF,$80,$00,$00,$FE,$80,$FF
$00:D339 .db $80,$00,$00,$02,$00,$FF,$00,$01
$00:D341 .db $00,$FF,$00,$01
;;; $D345: Table: walk and run accelerations (MarioAccel?) ;;;
;; Mario acceleration tables (D345-D5E6). Each row is 8 bytes: four 16-bit words left walk, left run, right
;; walk, right run; rows indexed by slope/state.
;; The listing rows are offset by one byte from the real row starts.
$00:D345 .db $80 ; Walk/run accelerations start here: 4 words per row (left walk, left run, right walk, right run)
; remember little endian, (db $12,$34 = dw $3412) < = left, > = right, W = walk, R = run
;;; $D346: Table: walk and run accelerations (MarioAccel2?) ;;;
$00:D346 .db $FE,$80,$FE,$80,$01,$80,$01,$80 ;>00D346
;;; $D34E: Table: walk and run accelerations (00D34E) ;;;
$00:D34E .db $FE,$80,$FE,$80,$01,$80,$01,$80
;;; $D356: Table: walk and run accelerations (00D356) ;;;
$00:D356 .db $FE,$80,$FE,$80,$01,$80,$01,$80
;;; $D35E: Table: walk and run accelerations (00D35E) ;;;
$00:D35E .db $FE,$80,$FE,$40,$01,$40,$01,$C0
;;; $D366: Table: walk and run accelerations (00D366) ;;;
$00:D366 .db $FE,$C0,$FE,$80,$01,$80,$01,$80
;;; $D36E: Table: walk and run accelerations (00D36E) ;;;
$00:D36E .db $FE,$80,$FE,$00,$01,$00,$01,$00
;;; $D376: Table: walk and run accelerations (00D376) ;;;
$00:D376 .db $FF,$00,$FF,$80,$01,$80,$01,$80
;;; $D37E: Table: walk and run accelerations (00D37E) ;;;
$00:D37E .db $FE,$80,$FE,$00,$01,$00,$01,$80
;;; $D386: Table: walk and run accelerations (00D386) ;;;
$00:D386 .db $FE,$80,$FE,$00,$01,$00,$01,$00
;;; $D38E: Table: walk and run accelerations (00D38E) ;;;
$00:D38E .db $FF,$00,$FF,$80,$01,$80,$01,$00
;;; $D396: Table: walk and run accelerations (00D396) ;;;
$00:D396 .db $FF,$00,$FF,$80,$01,$80,$01,$00
;;; $D39E: Table: walk and run accelerations (00D39E) ;;;
$00:D39E .db $FC,$00,$FC,$00,$FD,$00,$FD,$00
;;; $D3A6: Table: walk and run accelerations (00D3A6) ;;;
$00:D3A6 .db $03,$00,$03,$00,$04,$00,$04,$00 ; Rows from $D3AD: flight accelerations
;;; $D3AE: Table: flight accelerations (00D3AE) ;;;
$00:D3AE .db $FC,$00,$FC,$00,$06,$00,$06,$00
;;; $D3B6: Table: flight accelerations (00D3B6) ;;;
$00:D3B6 .db $FA,$00,$FA,$00,$04,$00,$04,$80 ; Rows from $D3BD: sliding accelerations
;;; $D3BE: Table: sliding accelerations (00D3BE) ;;;
$00:D3BE .db $FF,$80,$00,$00,$FF,$00,$01,$80
;;; $D3C6: Table: sliding accelerations (00D3C6) ;;;
$00:D3C6 .db $FE,$80,$01,$80,$FE,$80,$FE,$80
;;; $D3CE: Table: sliding accelerations (00D3CE) ;;;
$00:D3CE .db $01,$80,$01,$80,$FE,$80,$02,$80 ; Rows from $D3D5: running decelerations
;;; $D3D6: Table: running decelerations (00D3D6) ;;;
$00:D3D6 .db $FD,$00,$FB,$80,$02,$00,$05,$80
;;; $D3DE: Table: running decelerations (00D3DE) ;;;
$00:D3DE .db $FD,$00,$FB,$80,$02,$00,$05,$80
;;; $D3E6: Table: running decelerations (00D3E6) ;;;
$00:D3E6 .db $FD,$00,$FB,$80,$02,$00,$05,$40
;;; $D3EE: Table: running decelerations (00D3EE) ;;;
$00:D3EE .db $FD,$80,$FA,$40,$02,$80,$04,$C0
;;; $D3F6: Table: running decelerations (00D3F6) ;;;
$00:D3F6 .db $FD,$80,$FB,$C0,$02,$80,$05,$00
;;; $D3FE: Table: running decelerations (00D3FE) ;;;
$00:D3FE .db $FD,$00,$FA,$00,$02,$00,$04,$00
;;; $D406: Table: running decelerations (00D406) ;;;
$00:D406 .db $FE,$00,$FC,$00,$03,$00,$06,$00
;;; $D40E: Table: running decelerations (00D40E) ;;;
$00:D40E .db $FD,$00,$FA,$00,$02,$00,$04,$00
;;; $D416: Table: running decelerations (00D416) ;;;
$00:D416 .db $FD,$00,$FA,$00,$02,$00,$04,$00
;;; $D41E: Table: running decelerations (00D41E) ;;;
$00:D41E .db $FE,$00,$FC,$00,$03,$00,$06,$00
;;; $D426: Table: running decelerations (00D426) ;;;
$00:D426 .db $FE,$00,$FC,$00,$03,$00,$06,$00
;;; $D42E: Table: running decelerations (00D42E) ;;;
$00:D42E .db $FD,$00,$FA,$00,$FD,$00,$FA,$00
;;; $D436: Table: running decelerations (00D436) ;;;
$00:D436 .db $03,$00,$06,$00,$03,$00,$06
$00:D43D .db $80,$FF,$80,$FE,$80,$00,$80,$01 ; Running accelerations in slippery levels
;;; $D445: Table: running accelerations, slippery levels (00D445) ;;;
$00:D445 .db $80,$FF,$80,$FE,$80,$00,$80,$01
;;; $D44D: Table: running accelerations, slippery levels (00D44D) ;;;
$00:D44D .db $80,$FF,$80,$FE,$80,$00,$80,$01
;;; $D455: Table: running accelerations, slippery levels (00D455) ;;;
$00:D455 .db $80,$FE,$80,$FE,$80,$00,$40,$01
;;; $D45D: Table: running accelerations, slippery levels (00D45D) ;;;
$00:D45D .db $80,$FF,$C0,$FE,$80,$01,$80,$01
;;; $D465: Table: running accelerations, slippery levels (00D465) ;;;
$00:D465 .db $80,$FE,$80,$FE,$80,$00,$00,$01
;;; $D46D: Table: running accelerations, slippery levels (00D46D) ;;;
$00:D46D .db $80,$FF,$00,$FF,$80,$01,$80,$01
;;; $D475: Table: running accelerations, slippery levels (00D475) ;;;
$00:D475 .db $80,$FE,$80,$FE,$80,$00,$00,$01
;;; $D47D: Table: running accelerations, slippery levels (00D47D) ;;;
$00:D47D .db $80,$FE,$80,$FE,$80,$00,$00,$01
;;; $D485: Table: running accelerations, slippery levels (00D485) ;;;
$00:D485 .db $80,$FF,$00,$FF,$80,$01,$80,$01
;;; $D48D: Table: running accelerations, slippery levels (00D48D) ;;;
$00:D48D .db $80,$FF,$00,$FF,$80,$01,$80,$01
;;; $D495: Table: running accelerations, slippery levels (00D495) ;;;
$00:D495 .db $00,$FC,$00,$FC,$00,$FE,$00,$FD
;;; $D49D: Table: running accelerations, slippery levels (00D49D) ;;;
$00:D49D .db $00,$03,$00,$03,$00,$04,$00,$04
;;; $D4A5: Table: running accelerations, slippery levels (00D4A5) ;;;
$00:D4A5 .db $00,$FC,$00,$FC,$80,$00,$80,$00
;;; $D4AD: Table: running accelerations, slippery levels (00D4AD) ;;;
$00:D4AD .db $80,$FF,$80,$FF,$00,$04,$00,$04
;;; $D4B5: Table: slippery slope accelerations (00D4B5) ;;;
$00:D4B5 .db $80,$FF,$80,$00,$00,$FF,$00,$01 ; Slippery slope accelerations
;;; $D4BD: Table: slippery slope accelerations (00D4BD) ;;;
$00:D4BD .db $80,$FE,$80,$01,$80,$FE,$80,$FE
;;; $D4C5: Table: slippery slope accelerations (00D4C5) ;;;
$00:D4C5 .db $80,$01,$80,$01,$80,$FE,$80,$02
;;; $D4CD: Table: running decelerations, slippery levels (00D4CD) ;;;
$00:D4CD .db $C0,$FF,$80,$FD,$40,$00,$80,$02 ; Running decelerations in slippery levels
;;; $D4D5: Table: running decelerations, slippery levels (00D4D5) ;;;
$00:D4D5 .db $C0,$FF,$80,$FD,$40,$00,$80,$02
;;; $D4DD: Table: running decelerations, slippery levels (00D4DD) ;;;
$00:D4DD .db $C0,$FF,$80,$FD,$40,$00,$80,$02
;;; $D4E5: Table: running decelerations, slippery levels (00D4E5) ;;;
$00:D4E5 .db $80,$FF,$40,$FD,$40,$00,$40,$02
;;; $D4ED: Table: running decelerations, slippery levels (00D4ED) ;;;
$00:D4ED .db $C0,$FF,$C0,$FD,$80,$00,$C0,$02
;;; $D4F5: Table: running decelerations, slippery levels (00D4F5) ;;;
$00:D4F5 .db $00,$FD,$00,$FD,$40,$00,$00,$02
;;; $D4FD: Table: running decelerations, slippery levels (00D4FD) ;;;
$00:D4FD .db $C0,$FF,$00,$FE,$00,$03,$00,$03
;;; $D505: Table: running decelerations, slippery levels (00D505) ;;;
$00:D505 .db $00,$FD,$00,$FD,$40,$00,$00,$02
;;; $D50D: Table: running decelerations, slippery levels (00D50D) ;;;
$00:D50D .db $00,$FD,$00,$FD,$40,$00,$00,$02
;;; $D515: Table: running decelerations, slippery levels (00D515) ;;;
$00:D515 .db $C0,$FF,$00,$FE,$00,$03,$00,$03
;;; $D51D: Table: running decelerations, slippery levels (00D51D) ;;;
$00:D51D .db $C0,$FF,$00,$FE,$00,$03,$00,$03
;;; $D525: Table: running decelerations, slippery levels (00D525) ;;;
$00:D525 .db $00,$FD,$00,$FD,$00,$FD,$00,$FD
;;; $D52D: Table: running decelerations, slippery levels (00D52D) ;;;
$00:D52D .db $00,$03,$00,$03,$00,$03,$00,$03
$00:D535 .db $EC,$14,$DC,$24,$DC,$24,$D0,$30 ; Maximum speeds (walk/run, left and right)
;;; $D53D: Table: maximum walk and run speeds (00D53D) ;;;
$00:D53D .db $EC,$14,$DC,$24,$DC,$24,$D0,$30
;;; $D545: Table: maximum walk and run speeds (00D545) ;;;
$00:D545 .db $EC,$14,$DC,$24,$DC,$24,$D0,$30
;;; $D54D: Table: maximum walk and run speeds (00D54D) ;;;
$00:D54D .db $E8,$12,$DC,$20,$DC,$20,$D0,$2C
;;; $D555: Table: maximum walk and run speeds (00D555) ;;;
$00:D555 .db $EE,$18,$E0,$24,$E0,$24,$D4,$30
;;; $D55D: Table: maximum walk and run speeds (00D55D) ;;;
$00:D55D .db $DC,$10,$DC,$1C,$DC,$1C,$D0,$28
;;; $D565: Table: maximum walk and run speeds (00D565) ;;;
$00:D565 .db $F0,$24,$E4,$24,$E4,$24,$D8,$30
;;; $D56D: Table: maximum walk and run speeds (00D56D) ;;;
$00:D56D .db $DC,$10,$DC,$1C,$DC,$1C,$D0,$28
;;; $D575: Table: maximum walk and run speeds (00D575) ;;;
$00:D575 .db $DC,$10,$DC,$1C,$DC,$1C,$D0,$28
;;; $D57D: Table: maximum walk and run speeds (00D57D) ;;;
$00:D57D .db $F0,$24,$E4,$24,$E4,$24,$D8,$30
;;; $D585: Table: maximum walk and run speeds (00D585) ;;;
$00:D585 .db $F0,$24,$E4,$24,$E4,$24,$D8,$30
;;; $D58D: Table: maximum walk and run speeds (00D58D) ;;;
$00:D58D .db $DC,$F0,$DC,$F8,$DC,$F8,$D0,$FC
;;; $D595: Table: maximum walk and run speeds (00D595) ;;;
$00:D595 .db $10,$24,$08,$24,$08,$24,$04,$30
;;; $D59D: Table: maximum flight speeds (00D59D) ;;;
$00:D59D .db $D0,$08,$D0,$08,$D0,$08,$D0,$08 ; Maximum flight speeds
;;; $D5A5: Table: maximum flight speeds (00D5A5) ;;;
$00:D5A5 .db $F8,$30,$F8,$30,$F8,$30,$F8,$30
;;; $D5AD: Table: maximum swim speeds (00D5AD) ;;;
$00:D5AD .db $F8,$08,$F0,$10,$F4,$04,$E8,$08 ; Maximum swim speeds
;;; $D5B5: Table: maximum slope sliding speeds (00D5B5) ;;;
$00:D5B5 .db $F0,$10,$E0,$20,$EC,$0C,$D8,$18 ; Maximum slope sliding speeds
;;; $D5BD: Table: sliding speeds, carrying item (00D5BD) ;;;
$00:D5BD .db $D8,$28,$D4,$2C,$D0,$30,$D0,$D0 ; Maximum slope sliding speeds while carrying an item
;;; $D5C5: Table: sliding speeds, carrying item (00D5C5) ;;;
$00:D5C5 .db $30,$30,$E0,$20
$00:D5C9 .db $00 ; Auto-slide speeds per slope type (no buttons held)
$00:D5CA .db $00,$00,$00,$00,$00,$00,$00,$00
;;; $D5D2: Table: auto-slide speeds on slopes (00D5D2) ;;;
$00:D5D2 .db $00,$00,$F0,$00,$10,$00,$00,$00
;;; $D5DA: Table: auto-slide speeds on slopes (00D5DA) ;;;
$00:D5DA .db $00,$00,$00,$00,$00,$00,$E0,$00
;;; $D5E2: Table: auto-slide speeds on slopes (00D5E2) ;;;
$00:D5E2 .db $20,$00,$00,$00,$00,$00,$F0,$00 ; Rows from $D5E7: speed when no buttons are held in water
;;; $D5EA: Mario X speed on ground, jump start (00D5EA) ;;;
;; Handles Mario's horizontal movement and the start of a jump. Starts a normal or spin jump when B or A is
;; pressed, sets the Y speed
;; from the X speed, turns Mario around, picks the max speed/acceleration from the slope, run state and
;; direction, and adds acceleration
;; or deceleration to Mario X speed ([$7A]/[RAM_MarioSpeedX]). Also updates the dash timer [$13E4] (P-meter).
;; Contains several tables: dash timer steps, cape-flight slope values, spin jump timer values. Part of the
;; DATA at $00D5EA is the end of the autoslide speed table.
$00:D5EA .db $F8 ; Last byte of the autoslide speed table at $00D5C9
$00:D5EB .db $FF,$FF,$02 ; Dash timer step by state: $FF = -1 (walking), $FF = -1 (run held, slow), $02 = +2 (running fast)
$00:D5EE .db $68,$70 ; Slope value [$13E1] forced while cape flying: $68 facing left, $70 facing right
$00:D5F0 .db $1C,$0C ; [$13E2] set at spin jump start: $1C facing left, $0C facing right
$00:D5F2 A5 72 LDA RAM_IsFlying ; \
$00:D5F4 F0 03 BEQ $D5F9 ; / In the air: skip the jump start checks
$00:D5F6 4C 82 D6 JMP.W $D682 ; Go to the air/slide handling
$00:D5F9 64 73 STZ RAM_IsDucking ; Not ducking (reset every frame on the ground)
$00:D5FB AD ED 13 LDA.W $13ED ; \
$00:D5FE D0 0B BNE $D60B ; / Already sliding down a slope: do not check for a new duck-slide
$00:D600 A5 15 LDA RAM_ControllerA ; \
$00:D602 29 04 AND.B #$04 ; } Down not held: skip ahead
$00:D604 F0 05 BEQ $D60B ; /
$00:D606 85 73 STA RAM_IsDucking ; Down held: [RAM_IsDucking] = 4 (non-zero, ducking)
$00:D608 9C E8 13 STZ.W $13E8 ; Cancel the cape interaction with sprites
$00:D60B AD 71 14 LDA.W $1471 ; \
$00:D60E C9 02 CMP.B #$02 ; } On a sinking platform ([$1471] = 2): skip the jump check
$00:D610 F0 0C BEQ $D61E ; /
$00:D612 A5 77 LDA RAM_MarioObjStatus ; \
$00:D614 29 08 AND.B #$08 ; } Blocked from above: skip the jump check
$00:D616 D0 06 BNE $D61E ; /
$00:D618 A5 16 LDA $16 ; \
$00:D61A 05 18 ORA $18 ; } B or A newly pressed: start a jump at $00D630
$00:D61C 30 12 BMI $D630 ; /
$00:D61E A5 73 LDA RAM_IsDucking ; \
$00:D620 F0 60 BEQ $D682 ; / Not ducking: go to the air/slide handling
$00:D622 A5 7B LDA RAM_MarioSpeedX ; \
$00:D624 F0 07 BEQ $D62D ; / Not moving horizontally: skip the slippery check
$00:D626 A5 86 LDA $86 ; \
$00:D628 D0 03 BNE $D62D ; / Slippery level: skip the skid dust
$00:D62A 20 4A FE JSR.W $FE4A ; Spawn the skid/duck-slide dust ($FE4A)
$00:D62D 4C 64 D7 JMP.W $D764 ; Skip the jump code, go to the slowdown
$00:D630 A5 7B LDA RAM_MarioSpeedX ; \
$00:D632 10 03 BPL $D637 ; |
$00:D634 49 FF EOR.B #$FF ; } A = |[Mario X speed]|
$00:D636 1A INC A ; /
$00:D637 4A LSR ; \
$00:D638 4A LSR ; |
$00:D639 29 FE AND.B #$FE ; } X = (|speed| >> 2) & $FE: even index into the jump height table
$00:D63B AA TAX ; /
$00:D63C A5 18 LDA $18 ; \
$00:D63E 10 1E BPL $D65E ; / A (newly pressed) not set: normal jump (B), go to $00D65E
$00:D640 AD 8F 14 LDA.W $148F ; \
$00:D643 D0 19 BNE $D65E ; / Carrying something: no spin jump, normal jump
$00:D645 1A INC A ; \
$00:D646 8D 0D 14 STA.W RAM_IsSpinJump ; / [RAM_IsSpinJump] = 1: start a spin jump
$00:D649 A9 04 LDA.B #$04 ; \
$00:D64B 8D FC 1D STA.W $1DFC ; / Play the spin jump sound ($04 to $1DFC)
$00:D64E A4 76 LDY RAM_MarioDirection ; \
$00:D650 B9 F0 D5 LDA.W $D5F0,Y ; } [$13E2] = fireball timer by facing direction ($1C or $0C)
$00:D653 8D E2 13 STA.W $13E2 ; /
$00:D656 AD 7A 18 LDA.W RAM_OnYoshi ; \
$00:D659 D0 27 BNE $D682 ; / On Yoshi: skip to the air handling
$00:D65B E8 INX ; X += 1: spin jump uses the next (odd) jump height entry
$00:D65C 80 05 BRA $D663 ; Skip the normal jump sound
$00:D65E A9 01 LDA.B #$01 ; \
$00:D660 8D FA 1D STA.W $1DFA ; / Play the jump sound ($01 to $1DFA)
$00:D663 BD BD D2 LDA.W $D2BD,X ; \
$00:D666 85 7D STA RAM_MarioSpeedY ; / Mario Y speed = jump height table [X]: faster = higher jump
$00:D668 A9 0B LDA.B #$0B ; A = $0B: air state 'rising'
$00:D66A AC E4 13 LDY.W $13E4 ; \
$00:D66D C0 70 CPY.B #$70 ; } Dash timer [$13E4] below $70: not at full speed
$00:D66F 90 0C BCC $D67D ; /
$00:D671 AD 9F 14 LDA.W $149F ; \
$00:D674 D0 05 BNE $D67B ; / Cape flight takeoff timer [$149F] already running: keep it
$00:D676 A9 50 LDA.B #$50 ; \
$00:D678 8D 9F 14 STA.W $149F ; / [$149F] = $50: allow cape takeoff (vertical scrolling)
$00:D67B A9 0C LDA.B #$0C ; A = $0C: air state 'jumped at full run speed'
$00:D67D 85 72 STA RAM_IsFlying ; [RAM_IsFlying] = A: Mario is in the air
$00:D67F 9C ED 13 STZ.W $13ED ; Not sliding any more
$00:D682 AD ED 13 LDA.W $13ED ; \
$00:D685 30 0B BMI $D692 ; / Sliding flag [$13ED] negative: go spawn dust and keep sliding
$00:D687 A5 15 LDA RAM_ControllerA ; \
$00:D689 29 03 AND.B #$03 ; } Left or right held: go handle turning/accelerating
$00:D68B D0 24 BNE $D6B1 ; /
$00:D68D AD ED 13 LDA.W $13ED ; \
$00:D690 F0 1C BEQ $D6AE ; / Not sliding: go to the slowdown ($00D764)
$00:D692 20 4A FE JSR.W $FE4A ; Spawn skid dust ($FE4A)
$00:D695 AD EE 13 LDA.W $13EE ; \
$00:D698 F0 14 BEQ $D6AE ; / No slope flag [$13EE]: go to the slowdown
$00:D69A 20 68 D9 JSR.W $D968 ; Update the dash timer (decrease)
$00:D69D AD E1 13 LDA.W $13E1 ; \
$00:D6A0 4A LSR ; |
$00:D6A1 4A LSR ; } Y = slope index >> 2
$00:D6A2 A8 TAY ; /
$00:D6A3 69 76 ADC.B #$76 ; \
$00:D6A5 AA TAX ; / X = Y + $76 (+ carry): slope-slide acceleration index
$00:D6A6 98 TYA ; \
$00:D6A7 4A LSR ; |
$00:D6A8 69 87 ADC.B #$87 ; } Y = (Y >> 1) + $87 (+ carry): slope-slide max speed index
$00:D6AA A8 TAY ; /
$00:D6AB 4C 42 D7 JMP.W $D742 ; Go to the speed limit/accelerate code
$00:D6AE 4C 64 D7 JMP.W $D764 ; Go to the slowdown
$00:D6B1 9C ED 13 STZ.W $13ED ; Not sliding any more
$00:D6B4 29 01 AND.B #$01 ; A = 1 if holding right, 0 if left
$00:D6B6 AC 07 14 LDY.W $1407 ; \
$00:D6B9 F0 1A BEQ $D6D5 ; / Not cape flying ([$1407] = 0): normal turning at $00D6D5
$00:D6BB C5 76 CMP RAM_MarioDirection ; \
$00:D6BD F0 04 BEQ $D6C3 ; / Held direction = facing: use it
$00:D6BF A4 16 LDY $16 ; \
$00:D6C1 10 CA BPL $D68D ; / Turning while cape flying only on a new B press, else ignore
$00:D6C3 A6 76 LDX RAM_MarioDirection ; X = facing direction
$00:D6C5 BC EE D5 LDY.W $D5EE,X ; \
$00:D6C8 8C E1 13 STY.W $13E1 ; / [$13E1] = cape flight slope value for this direction
$00:D6CB 85 01 STA $01 ; [$01] = held direction bit
$00:D6CD 0A ASL ; \
$00:D6CE 0A ASL ; |
$00:D6CF 0D E1 13 ORA.W $13E1 ; } X = direction << 2 | [$13E1]: acceleration table index
$00:D6D2 AA TAX ; /
$00:D6D3 80 3E BRA $D713 ; Skip the turn-around code
$00:D6D5 A4 76 LDY RAM_MarioDirection ; Y = facing direction
$00:D6D7 C5 76 CMP RAM_MarioDirection ; \
$00:D6D9 F0 11 BEQ $D6EC ; / Held direction = facing: no turn
$00:D6DB AC 8F 14 LDY.W $148F ; \
$00:D6DE F0 0A BEQ $D6EA ; / Not carrying anything: just turn
$00:D6E0 AC 99 14 LDY.W RAM_FaceCamImgTimer ; \
$00:D6E3 D0 07 BNE $D6EC ; / Already turning (face-camera timer running): leave it
$00:D6E5 A0 08 LDY.B #$08 ; \
$00:D6E7 8C 99 14 STY.W RAM_FaceCamImgTimer ; / Carrying: face the camera for 8 frames while turning
$00:D6EA 85 76 STA RAM_MarioDirection ; Face the held direction
$00:D6EC 85 01 STA $01 ; [$01] = held direction bit
$00:D6EE 0A ASL ; \
$00:D6EF 0A ASL ; |
$00:D6F0 0D E1 13 ORA.W $13E1 ; } X = direction << 2 | [$13E1]: acceleration table index
$00:D6F3 AA TAX ; /
$00:D6F4 A5 7B LDA RAM_MarioSpeedX ; \
$00:D6F6 F0 1B BEQ $D713 ; / Not moving: no skid check
$00:D6F8 5D 46 D3 EOR.W MarioAccel2?,X ; \
$00:D6FB 10 16 BPL $D713 ; / Speed sign differs from the acceleration direction? If not, no skid
$00:D6FD AD A1 14 LDA.W $14A1 ; \
$00:D700 D0 11 BNE $D713 ; / Already skidding ([$14A1] set): skip
$00:D702 A5 86 LDA $86 ; \
$00:D704 D0 08 BNE $D70E ; / Slippery level: no skid pose/dust
$00:D706 A9 0D LDA.B #$0D ; \
$00:D708 8D DD 13 STA.W RAM_ChangingDir ; / Show the turn-around pose ([RAM_ChangingDir] = $0D)
$00:D70B 20 4A FE JSR.W $FE4A ; Spawn skid dust ($FE4A)
$00:D70E 8A TXA ; \
$00:D70F 18 CLC ; |
$00:D710 69 90 ADC.B #$90 ; } X += $90: use the skidding acceleration entries
$00:D712 AA TAX ; /
$00:D713 A0 00 LDY.B #$00 ; Y = 0: walking
$00:D715 24 15 BIT RAM_ControllerA ; \
$00:D717 50 1E BVC $D737 ; / Dash (run) button not held: skip
$00:D719 E8 INX ; \
$00:D71A E8 INX ; } Run held: X += 2 (next acceleration set), Y = 1
$00:D71B C8 INY ; /
$00:D71C A5 7B LDA RAM_MarioSpeedX ; \
$00:D71E 10 03 BPL $D723 ; |
$00:D720 49 FF EOR.B #$FF ; } A = |speed|
$00:D722 1A INC A ; /
$00:D723 C9 23 CMP.B #$23 ; \
$00:D725 30 10 BMI $D737 ; / Below $23: not fast enough for the run state
$00:D727 A5 72 LDA RAM_IsFlying ; \
$00:D729 D0 07 BNE $D732 ; / In the air: check the air state at $00D732
$00:D72B A9 10 LDA.B #$10 ; \
$00:D72D 8D A0 14 STA.W $14A0 ; / On the ground: running animation timer [$14A0] = $10
$00:D730 80 04 BRA $D736 ; Y += 1 (go to $00D736)
$00:D732 C9 0C CMP.B #$0C ; \
$00:D734 D0 01 BNE $D737 ; / In the air state $0C (full-speed jump): Y += 1, else skip
$00:D736 C8 INY ; Y += 1: Y = 2 means running at speed
$00:D737 20 6A D9 JSR.W $D96A ; Update the dash timer, add or subtract by Y
$00:D73A 98 TYA ; \
$00:D73B 0A ASL ; |
$00:D73C 0D E1 13 ORA.W $13E1 ; |
$00:D73F 05 01 ORA $01 ; } Y = dash state << 1 | slope [$13E1] | direction [$01]: max speed index
$00:D741 A8 TAY ; /
$00:D742 A5 7B LDA RAM_MarioSpeedX ; \
$00:D744 38 SEC ; } A = speed - max speed[Y]
$00:D745 F9 35 D5 SBC.W $D535,Y ; /
$00:D748 F0 21 BEQ $D76B ; Exactly at max speed: go to the slowdown
$00:D74A 59 35 D5 EOR.W $D535,Y ; \
$00:D74D 10 1C BPL $D76B ; / Same sign as max speed: exceeding it, go to the slowdown
$00:D74F C2 20 REP #$20 ; A 16-bit
$00:D751 BD 45 D3 LDA.W MarioAccel?,X ; A = acceleration table [X] (16-bit)
$00:D754 A4 86 LDY $86 ; \
$00:D756 F0 07 BEQ $D75F ; / Not slippery: keep it
$00:D758 A4 72 LDY RAM_IsFlying ; \
$00:D75A D0 03 BNE $D75F ; } Slippery and on the ground: use the slippery accel table instead
$00:D75C BD 3D D4 LDA.W $D43D,X ; /
$00:D75F 18 CLC ; \
$00:D760 65 7A ADC $7A ; / Mario X speed (16-bit [$7A]) += acceleration
$00:D762 80 3C BRA $D7A0 ; Store it and finish
$00:D764 20 68 D9 JSR.W $D968 ; Update the dash timer (decrease)
$00:D767 A5 72 LDA RAM_IsFlying ; \
$00:D769 D0 39 BNE $D7A4 ; / In the air: return
$00:D76B AD E1 13 LDA.W $13E1 ; A = slope index [$13E1]
$00:D76E 4A LSR ; \
$00:D76F A8 TAY ; |
$00:D770 4A LSR ; } Y = slope >> 1, X = slope >> 2
$00:D771 AA TAX ; /
$00:D772 A5 7B LDA RAM_MarioSpeedX ; \
$00:D774 38 SEC ; |
$00:D775 FD CA D5 SBC.W $D5CA,X ; |
$00:D778 10 02 BPL $D77C ; |
$00:D77A C8 INY ; } A = speed - autoslide speed; Y += 2 if below it
$00:D77B C8 INY ; /
$00:D77C AD 93 14 LDA.W $1493 ; \
$00:D77F 05 72 ORA RAM_IsFlying ; / Level ending or in the air: use the normal deceleration table
$00:D781 C2 20 REP #$20 ; A 16-bit
$00:D783 D0 07 BNE $D78C ; Ending/in the air: go to $00D78C
$00:D785 B9 09 D3 LDA.W $D309,Y ; A = water deceleration table [Y]
$00:D788 24 85 BIT RAM_IsWaterLevel ; \
$00:D78A 30 03 BMI $D78F ; / In a water level: keep the water value
$00:D78C B9 CD D2 LDA.W $D2CD,Y ; A = deceleration table [Y]
$00:D78F 18 CLC ; \
$00:D790 65 7A ADC $7A ; } Mario X speed ([$7A]) += deceleration
$00:D792 85 7A STA $7A ; /
$00:D794 38 SEC ; \
$00:D795 FD C9 D5 SBC.W $D5C9,X ; |
$00:D798 59 CD D2 EOR.W $D2CD,Y ; } Reached or passed the autoslide target speed?
$00:D79B 30 05 BMI $D7A2 ; /
$00:D79D BD C9 D5 LDA.W $D5C9,X ; Yes: clamp speed to the autoslide target
$00:D7A0 85 7A STA $7A ; Store the new X speed
$00:D7A2 E2 20 SEP #$20 ; A 8-bit
$00:D7A4 60 RTS ; Return
;;; $D7A5..D7AD: Table: Y acceleration (gravity) ;;;
;; Added to Mario Y speed each frame by state; index 3+ is used by cape flight phases.
$00:D7A5 .db $06,$03,$04,$10,$F4,$01,$03,$04 ; Y acceleration (gravity) by state: $06 fall, $03 jump held, $04 float, $10, then cape phases
$00:D7AD .db $05,$06 ; Cape flight phase 5 and 6 gravity
;;; $D7AF..D7B7: Table: max fall speed ;;;
$00:D7AF .db $40,$40,$20,$40,$40,$40,$40,$40 ; Max fall speed: $40, $40, $20 (floating), rest $40
$00:D7B7 .db $40,$40
;;; $D7B9..D7C1: Table: cape and Yoshi wings float limits ;;;
$00:D7B9 .db $10,$C8,$E0,$02,$03,$03,$04,$03 ; Cape or winged Yoshi float speed limits: $10 slow fall, then rising limits
$00:D7C1 .db $02,$00,$01,$00,$00,$00,$00
;;; $D7C8..D7C8: Table: cape flight max fall speed ;;;
$00:D7C8 .db $01,$10,$30,$30,$38,$38,$40 ; Cape flight max fall speed by phase [$1407]
;;; $D7CF: Cape flight phase tables, then Mario Y speed (CapeSpeed) ;;;
;; CapeSpeed: phase step by pitch input. $00D7D4: target phase. $00D7D9: takeoff boost table.
;; Code from $00D7E4: Mario Y physics. Adds gravity, limits fall speed, handles cape takeoff and the 6 cape
;; flight phases ([$1407]),
;; and floating with cape/winged Yoshi. Pitch input is set by held direction relative to facing; dash button
;; released stops flight.
;; $00D94F: picks the takeoff boost [$1409] from the fall speed. $00D968/$00D96A: updates the dash timer
;; [$13E4], capped at $70.
$00:D7CF .db $FF,$01,$01,$FF,$FF ; Phase step for [$1407] by pitch input X: -1, +1, +1, -1, -1
$00:D7D4 .db $01,$06,$03,$01,$00 ; Phase [$1407] target by pitch input X: 1, 6, 3, 1, 0
$00:D7D9 .db $00,$00,$00,$F8,$F8,$F8,$F4,$F0 ; Cape takeoff upward boost, indexed by fall speed / 8
$00:D7E1 .db $C8,$02,$01
$00:D7E4 AC 07 14 LDY.W $1407 ; \
$00:D7E7 D0 3B BNE $D824 ; / Cape phase [$1407]: not flying yet?
$00:D7E9 A5 72 LDA RAM_IsFlying ; \
$00:D7EB F0 24 BEQ $D811 ; / On the ground: no takeoff
$00:D7ED AD 8F 14 LDA.W $148F ; \
$00:D7F0 0D 7A 18 ORA.W RAM_OnYoshi ; |
$00:D7F3 0D 0D 14 ORA.W RAM_IsSpinJump ; } Carrying, on Yoshi or spin jumping: no cape flight
$00:D7F6 D0 19 BNE $D811 ; /
$00:D7F8 AD ED 13 LDA.W $13ED ; \
$00:D7FB 30 02 BMI $D7FF ; } Sliding flag > 0: no takeoff
$00:D7FD D0 12 BNE $D811 ; /
$00:D7FF 9C ED 13 STZ.W $13ED ; Clear the sliding flag
$00:D802 A6 19 LDX RAM_MarioPowerUp ; \
$00:D804 E0 02 CPX.B #$02 ; } Only caped Mario (power-up 2) can take off
$00:D806 D0 09 BNE $D811 ; /
$00:D808 A5 7D LDA RAM_MarioSpeedY ; \
$00:D80A 30 05 BMI $D811 ; / Must be falling (speed >= 0)
$00:D80C AD 9F 14 LDA.W $149F ; \
$00:D80F D0 03 BNE $D814 ; / Cape takeoff timer [$149F] set: start cape flight at $00D814
$00:D811 4C CD D8 JMP.W $D8CD ; Normal gravity
$00:D814 64 73 STZ RAM_IsDucking ; Not ducking
$00:D816 A9 0B LDA.B #$0B ; \
$00:D818 85 72 STA RAM_IsFlying ; / [RAM_IsFlying] = $0B: rising
$00:D81A 9C 09 14 STZ.W $1409 ; [$1409] = 0: upward boost, set by the next call
$00:D81D 20 4F D9 JSR.W $D94F ; Pick the takeoff boost from the fall speed
$00:D820 A2 02 LDX.B #$02 ; \
$00:D822 80 37 BRA $D85B ; / X = 2: pitch input 'level'
$00:D824 C0 02 CPY.B #$02 ; \
$00:D826 90 03 BCC $D82B ; } Already flying: phase >= 2, refresh the boost
$00:D828 20 4F D9 JSR.W $D94F ; /
$00:D82B AE 08 14 LDX.W $1408 ; \
$00:D82E E0 04 CPX.B #$04 ; } Previous pitch input [$1408] = 4 (dash released)?
$00:D830 F0 24 BEQ $D856 ; /
$00:D832 A2 03 LDX.B #$03 ; X = 3: default pitch input
$00:D834 A4 7D LDY RAM_MarioSpeedY ; \
$00:D836 30 1E BMI $D856 ; / Rising (negative Y speed): keep X = 3
$00:D838 A5 15 LDA RAM_ControllerA ; \
$00:D83A 29 03 AND.B #$03 ; } A = held left/right bits
$00:D83C A8 TAY ; /
$00:D83D D0 0A BNE $D849 ; Direction held: go to $00D849
$00:D83F AD 07 14 LDA.W $1407 ; \
$00:D842 C9 04 CMP.B #$04 ; |
$00:D844 B0 10 BCS $D856 ; } No direction: phase >= 4 keeps X = 3, else X = 2
$00:D846 CA DEX ; /
$00:D847 80 0D BRA $D856 ; Go set the phase
$00:D849 4A LSR ; \
$00:D84A A4 76 LDY RAM_MarioDirection ; |
$00:D84C F0 02 BEQ $D850 ; |
$00:D84E 49 01 EOR.B #$01 ; } X = 0 if holding away from facing, 1 if toward it (nose up/down)
$00:D850 AA TAX ; /
$00:D851 EC 08 14 CPX.W $1408 ; \
$00:D854 D0 05 BNE $D85B ; / Pitch input unchanged: skip to timer check
$00:D856 AD A4 14 LDA.W $14A4 ; \
$00:D859 D0 23 BNE $D87E ; / Phase timer [$14A4] still running: do not change phase yet
$00:D85B 24 15 BIT RAM_ControllerA ; \
$00:D85D 70 02 BVS $D861 ; } Dash button not held: X = 4 (stop flying)
$00:D85F A2 04 LDX.B #$04 ; /
$00:D861 AD 07 14 LDA.W $1407 ; \
$00:D864 DD D4 D7 CMP.W $D7D4,X ; } Target phase reached: skip
$00:D867 F0 15 BEQ $D87E ; /
$00:D869 18 CLC ; \
$00:D86A 7D CF D7 ADC.W CapeSpeed,X ; } [$1407] += phase step[X]
$00:D86D 8D 07 14 STA.W $1407 ; /
$00:D870 A9 08 LDA.B #$08 ; A = 8: frames until the next phase change
$00:D872 AC 09 14 LDY.W $1409 ; \
$00:D875 C0 C8 CPY.B #$C8 ; |
$00:D877 D0 02 BNE $D87B ; } Boost [$1409] = $C8: faster change (2 frames)
$00:D879 A9 02 LDA.B #$02 ; /
$00:D87B 8D A4 14 STA.W $14A4 ; Set the phase timer [$14A4]
$00:D87E 8E 08 14 STX.W $1408 ; Remember the pitch input in [$1408]
$00:D881 AC 07 14 LDY.W $1407 ; \
$00:D884 F0 47 BEQ $D8CD ; / Y = phase; 0 = not cape flying: normal gravity
$00:D886 A5 7D LDA RAM_MarioSpeedY ; \
$00:D888 10 08 BPL $D892 ; / Falling: skip the upward clamp
$00:D88A C9 C8 CMP.B #$C8 ; \
$00:D88C B0 0C BCS $D89A ; } Rising faster than $C8 speed: limit it to $C8
$00:D88E A9 C8 LDA.B #$C8 ; /
$00:D890 80 08 BRA $D89A ; Go store
$00:D892 D9 C8 D7 CMP.W $D7C8,Y ; \
$00:D895 90 03 BCC $D89A ; } Clamp fall speed to max fall speed for this phase
$00:D897 B9 C8 D7 LDA.W $D7C8,Y ; /
$00:D89A 48 PHA ; Save the clamped speed
$00:D89B C0 01 CPY.B #$01 ; \
$00:D89D D0 27 BNE $D8C6 ; / Phase 1 (rising start)?
$00:D89F AE 09 14 LDX.W $1409 ; \
$00:D8A2 F0 20 BEQ $D8C4 ; / [$1409] (cape boost) is 0: skip
$00:D8A4 A5 7D LDA RAM_MarioSpeedY ; \
$00:D8A6 30 07 BMI $D8AF ; |
$00:D8A8 A9 09 LDA.B #$09 ; } Not rising yet: play the cape rise sound
$00:D8AA 8D F9 1D STA.W $1DF9 ; /
$00:D8AD 80 0A BRA $D8B9 ; Skip the boost compare
$00:D8AF CD 09 14 CMP.W $1409 ; \
$00:D8B2 B0 05 BCS $D8B9 ; / Rising faster than the boost? Then skip
$00:D8B4 86 7D STX RAM_MarioSpeedY ; \
$00:D8B6 9C 09 14 STZ.W $1409 ; / Use the boost as Y speed and clear it
$00:D8B9 A6 76 LDX RAM_MarioDirection ; \
$00:D8BB A5 7B LDA RAM_MarioSpeedX ; / X = facing, A = X speed
$00:D8BD F0 05 BEQ $D8C4 ; Standing still: no lift, use gravity index 2
$00:D8BF 5D 35 D5 EOR.W $D535,X ; \
$00:D8C2 10 02 BPL $D8C6 ; / Moving backwards: no lift
$00:D8C4 A0 02 LDY.B #$02 ; Y = 2: phase gravity index
$00:D8C6 68 PLA ; A = clamped speed
$00:D8C7 C8 INY ; \
$00:D8C8 C8 INY ; } Y += 3: index into the gravity table
$00:D8C9 C8 INY ; /
$00:D8CA 4C 48 D9 JMP.W $D948 ; Add gravity
$00:D8CD A5 72 LDA RAM_IsFlying ; \
$00:D8CF F0 57 BEQ $D928 ; / In the air? If not, go to $00D928
$00:D8D1 A2 00 LDX.B #$00 ; X = 0
$00:D8D3 AD 7A 18 LDA.W RAM_OnYoshi ; \
$00:D8D6 F0 0F BEQ $D8E7 ; / Not on Yoshi: go to $00D8E7
$00:D8D8 AD 1E 14 LDA.W RAM_YoshiHasWings ; \
$00:D8DB 4A LSR ; } Yoshi has no wings: go to $00D8E7
$00:D8DC F0 09 BEQ $D8E7 ; /
$00:D8DE A0 02 LDY.B #$02 ; \
$00:D8E0 C4 19 CPY RAM_MarioPowerUp ; |
$00:D8E2 F0 01 BEQ $D8E5 ; } X = 0 if caped, else 1 (controller byte to read)
$00:D8E4 E8 INX ; /
$00:D8E5 80 18 BRA $D8FF ; Go to the float timer
$00:D8E7 A5 19 LDA RAM_MarioPowerUp ; \
$00:D8E9 C9 02 CMP.B #$02 ; } Needs cape power-up (2)
$00:D8EB D0 3B BNE $D928 ; /
$00:D8ED A5 72 LDA RAM_IsFlying ; \
$00:D8EF C9 0C CMP.B #$0C ; } Not in air state $0C: go to $00D8FD
$00:D8F1 D0 0A BNE $D8FD ; /
$00:D8F3 A0 01 LDY.B #$01 ; \
$00:D8F5 CC 9F 14 CPY.W $149F ; } Takeoff timer [$149F] >= 2: leave it
$00:D8F8 90 05 BCC $D8FF ; /
$00:D8FA EE 9F 14 INC.W $149F ; [$149F] += 1
$00:D8FD A0 00 LDY.B #$00 ; Y = 0
$00:D8FF AD A5 14 LDA.W $14A5 ; \
$00:D902 D0 09 BNE $D90D ; / Float timer [$14A5] running: go to $00D90D
$00:D904 B5 15 LDA RAM_ControllerA,X ; \
$00:D906 10 1C BPL $D924 ; / Button not pressed: no float
$00:D908 A9 10 LDA.B #$10 ; \
$00:D90A 8D A5 14 STA.W $14A5 ; / Start float: [$14A5] = $10
$00:D90D A5 7D LDA RAM_MarioSpeedY ; \
$00:D90F 10 0A BPL $D91B ; / Y speed positive (falling)? go to $00D91B
$00:D911 BE B9 D7 LDX.W $D7B9,Y ; \
$00:D914 10 0E BPL $D924 ; / Rising: limit entry positive? then no float
$00:D916 D9 B9 D7 CMP.W $D7B9,Y ; \
$00:D919 90 09 BCC $D924 ; / Rising slower than limit: no float
$00:D91B B9 B9 D7 LDA.W $D7B9,Y ; \
$00:D91E C5 7D CMP RAM_MarioSpeedY ; |
$00:D920 F0 2A BEQ $D94C ; } Falling too fast: clamp to the float limit
$00:D922 30 28 BMI $D94C ; /
$00:D924 C0 02 CPY.B #$02 ; \
$00:D926 F0 08 BEQ $D930 ; / Y = 2 (winged Yoshi/cape): keep it
$00:D928 A0 01 LDY.B #$01 ; Y = 1: gravity index, jump held
$00:D92A A5 15 LDA RAM_ControllerA ; \
$00:D92C 30 02 BMI $D930 ; / B held: keep Y = 1
$00:D92E A0 00 LDY.B #$00 ; Y = 0: gravity index, jump not held
$00:D930 A5 7D LDA RAM_MarioSpeedY ; \
$00:D932 30 14 BMI $D948 ; / Rising: skip the fall limit
$00:D934 D9 AF D7 CMP.W $D7AF,Y ; \
$00:D937 90 03 BCC $D93C ; } Clamp Y speed to max fall speed[Y]
$00:D939 B9 AF D7 LDA.W $D7AF,Y ; /
$00:D93C A6 72 LDX RAM_IsFlying ; \
$00:D93E F0 08 BEQ $D948 ; |
$00:D940 E0 0B CPX.B #$0B ; |
$00:D942 D0 04 BNE $D948 ; |
$00:D944 A2 24 LDX.B #$24 ; } State $0B (rising) -> $24 (falling)
$00:D946 86 72 STX RAM_IsFlying ; /
$00:D948 18 CLC ; \
$00:D949 79 A5 D7 ADC.W $D7A5,Y ; } Mario Y speed += gravity[Y]
$00:D94C 85 7D STA RAM_MarioSpeedY ; /
$00:D94E 60 RTS ; Return
$00:D94F 9C 0A 14 STZ.W $140A ; [$140A] = 0
$00:D952 A5 7D LDA RAM_MarioSpeedY ; \
$00:D954 10 02 BPL $D958 ; } A = Y speed if falling, else 0
$00:D956 A9 00 LDA.B #$00 ; /
$00:D958 4A LSR ; \
$00:D959 4A LSR ; |
$00:D95A 4A LSR ; } Y = A / 8: index into the boost table
$00:D95B A8 TAY ; /
$00:D95C B9 D9 D7 LDA.W $D7D9,Y ; \
$00:D95F CD 09 14 CMP.W $1409 ; |
$00:D962 10 03 BPL $D967 ; } Keep the stronger (more negative) boost in [$1409]
$00:D964 8D 09 14 STA.W $1409 ; /
$00:D967 60 RTS ; Return
$00:D968 A0 00 LDY.B #$00 ; Y = 0: decrease the dash timer
$00:D96A AD E4 13 LDA.W $13E4 ; \
$00:D96D 18 CLC ; } [$13E4] += $D5EB[Y]
$00:D96E 79 EB D5 ADC.W $D5EB,Y ; /
$00:D971 10 02 BPL $D975 ; \
$00:D973 A9 00 LDA.B #$00 ; / Below 0: clamp to 0
$00:D975 C9 70 CMP.B #$70 ; \
$00:D977 90 03 BCC $D97C ; |
$00:D979 C8 INY ; } Reached $70: Y += 1 (full speed) and cap it
$00:D97A A9 70 LDA.B #$70 ; /
$00:D97C 8D E4 13 STA.W $13E4 ; Store the dash timer ([$13E4], the P-meter)
$00:D97F 60 RTS ; Return
;;; $D980..D984: Table: swim poses and Y speed limits ;;;
$00:D980 .db $16,$1A,$1A,$18 ; Swim pose by animation timer: $16, $1A, $1A, $18
$00:D984 .db $E8,$F8,$D0,$D0 ; Swim Y speed limit by up/down input: $E8, $F8, $D0, $D0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Swimming physics/controls
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; $D988: Swimming physics and controls ;;;
;; Mario movement in water: disables sliding, ducking, cape and spin jump. B/A paddles upward, down sinks
;; faster, the layer 3 tide
;; pushes Mario, and the horizontal speed is limited by a reduced max speed set. Also picks the swim pose and
;; cape animation.
;; $00DAA9: plays the swim sound and sets the swim animation bit.
;; Called by:
;; $00:CD7D: Mario animation 0: normal per-frame handling (ResetAni)
$00:D988 9C ED 13 STZ.W $13ED ; No slope sliding
$00:D98B 64 73 STZ RAM_IsDucking ; Not ducking
$00:D98D 9C 07 14 STZ.W $1407 ; No cape flight
$00:D990 9C 0D 14 STZ.W RAM_IsSpinJump ; No spin jump
$00:D993 A4 7D LDY RAM_MarioSpeedY ; Y = Mario Y speed
$00:D995 AD 8F 14 LDA.W $148F ; \
$00:D998 F0 51 BEQ $D9EB ; / Not carrying anything: go to $00D9EB
$00:D99A A5 72 LDA RAM_IsFlying ; \
$00:D99C D0 11 BNE $D9AF ; / In the air: skip the paddle
$00:D99E A5 16 LDA $16 ; \
$00:D9A0 05 18 ORA $18 ; } B or A newly pressed: paddle up
$00:D9A2 10 0B BPL $D9AF ; /
$00:D9A4 A9 0B LDA.B #$0B ; \
$00:D9A6 85 72 STA RAM_IsFlying ; / [RAM_IsFlying] = $0B: Mario is rising
$00:D9A8 9C ED 13 STZ.W $13ED ; No sliding
$00:D9AB A0 F0 LDY.B #$F0 ; Y = $F0: swim up speed
$00:D9AD 80 06 BRA $D9B5 ; Go to the sound and speed code
$00:D9AF A5 15 LDA RAM_ControllerA ; \
$00:D9B1 29 04 AND.B #$04 ; } Down held? If not skip
$00:D9B3 F0 08 BEQ $D9BD ; /
$00:D9B5 20 A9 DA JSR.W $DAA9 ; Play the swim sound and swim animation
$00:D9B8 98 TYA ; \
$00:D9B9 18 CLC ; |
$00:D9BA 69 08 ADC.B #$08 ; } Y += 8
$00:D9BC A8 TAY ; /
$00:D9BD C8 INY ; Y += 1: water sinks
$00:D9BE AD FA 13 LDA.W $13FA ; \
$00:D9C1 D0 09 BNE $D9CC ; / Can exit water ([$13FA])? Skip the slowdown
$00:D9C3 88 DEY ; Y -= 1
$00:D9C4 A5 14 LDA RAM_FrameCounterB ; \
$00:D9C6 29 03 AND.B #$03 ; |
$00:D9C8 D0 02 BNE $D9CC ; |
$00:D9CA 88 DEY ; } Every 4th frame: Y -= 2 more
$00:D9CB 88 DEY ; /
$00:D9CC 98 TYA ; A = new Y speed
$00:D9CD 30 08 BMI $D9D7 ; Negative: go to the upward clamp
$00:D9CF C9 10 CMP.B #$10 ; \
$00:D9D1 90 0A BCC $D9DD ; |
$00:D9D3 A9 10 LDA.B #$10 ; } Limit downward speed to $10
$00:D9D5 80 06 BRA $D9DD ; /
$00:D9D7 C9 F0 CMP.B #$F0 ; \
$00:D9D9 B0 02 BCS $D9DD ; } Limit upward speed to $F0
$00:D9DB A9 F0 LDA.B #$F0 ; /
$00:D9DD 85 7D STA RAM_MarioSpeedY ; Store Mario Y speed
$00:D9DF A0 80 LDY.B #$80 ; Y = $80: max X speed set
$00:D9E1 A5 15 LDA RAM_ControllerA ; \
$00:D9E3 29 03 AND.B #$03 ; } Left or right held: go to $00DA48
$00:D9E5 D0 61 BNE $DA48 ; /
$00:D9E7 A5 76 LDA RAM_MarioDirection ; A = facing direction
$00:D9E9 80 5B BRA $DA46 ; Go to set the max speed
$00:D9EB A5 16 LDA $16 ; \
$00:D9ED 05 18 ORA $18 ; } B or A newly pressed? If not, skip
$00:D9EF 10 1A BPL $DA0B ; /
$00:D9F1 AD FA 13 LDA.W $13FA ; \
$00:D9F4 D0 15 BNE $DA0B ; / Can exit water: skip
$00:D9F6 20 A9 DA JSR.W $DAA9 ; Play swim sound
$00:D9F9 A5 72 LDA RAM_IsFlying ; \
$00:D9FB D0 09 BNE $DA06 ; / In the air: skip
$00:D9FD A9 0B LDA.B #$0B ; \
$00:D9FF 85 72 STA RAM_IsFlying ; / [RAM_IsFlying] = $0B: Mario is rising
$00:DA01 9C ED 13 STZ.W $13ED ; No sliding
$00:DA04 A0 F0 LDY.B #$F0 ; Y = $F0
$00:DA06 98 TYA ; \
$00:DA07 38 SEC ; |
$00:DA08 E9 20 SBC.B #$20 ; } Y -= $20: stronger upward stroke
$00:DA0A A8 TAY ; /
$00:DA0B A5 14 LDA RAM_FrameCounterB ; \
$00:DA0D 29 03 AND.B #$03 ; |
$00:DA0F D0 02 BNE $DA13 ; |
$00:DA11 C8 INY ; } Every 4th frame: Y += 2
$00:DA12 C8 INY ; /
$00:DA13 A5 15 LDA RAM_ControllerA ; \
$00:DA15 29 0C AND.B #$0C ; |
$00:DA17 4A LSR ; |
$00:DA18 4A LSR ; } X = up/down held bits (0, 1, 2)
$00:DA19 AA TAX ; /
$00:DA1A 98 TYA ; A = Y
$00:DA1B 30 08 BMI $DA25 ; Negative: go to the upward limit
$00:DA1D C9 40 CMP.B #$40 ; \
$00:DA1F 90 0C BCC $DA2D ; |
$00:DA21 A9 40 LDA.B #$40 ; } Limit downward speed to $40
$00:DA23 80 08 BRA $DA2D ; /
$00:DA25 DD 84 D9 CMP.W $D984,X ; \
$00:DA28 B0 03 BCS $DA2D ; } Limit upward speed to $D984[X]
$00:DA2A BD 84 D9 LDA.W $D984,X ; /
$00:DA2D 85 7D STA RAM_MarioSpeedY ; Store Mario Y speed
$00:DA2F A5 72 LDA RAM_IsFlying ; \
$00:DA31 D0 0D BNE $DA40 ; / In the air: skip the ducking code
$00:DA33 A5 15 LDA RAM_ControllerA ; \
$00:DA35 29 04 AND.B #$04 ; } Down held and on the ground: duck
$00:DA37 F0 07 BEQ $DA40 ; /
$00:DA39 9C E8 13 STZ.W $13E8 ; Cancel cape sprite interaction
$00:DA3C E6 73 INC RAM_IsDucking ; Ducking = 1 (water)
$00:DA3E 80 29 BRA $DA69 ; Go to no-direction movement
$00:DA40 A5 15 LDA RAM_ControllerA ; \
$00:DA42 29 03 AND.B #$03 ; } Left or right held? If not, go to $00DA69
$00:DA44 F0 23 BEQ $DA69 ; /
$00:DA46 A0 78 LDY.B #$78 ; Y = $78: max speed set when walking
$00:DA48 84 00 STY $00 ; [$00] = Y
$00:DA4A 29 01 AND.B #$01 ; \
$00:DA4C 85 76 STA RAM_MarioDirection ; / Facing direction = right bit
$00:DA4E 48 PHA ; Save A
$00:DA4F 0A ASL ; \
$00:DA50 0A ASL ; } X = right bit << 2
$00:DA51 AA TAX ; /
$00:DA52 68 PLA ; Restore A
$00:DA53 05 00 ORA $00 ; A |= [$00]
$00:DA55 AC 03 14 LDY.W $1403 ; \
$00:DA58 F0 03 BEQ $DA5D ; |
$00:DA5A 18 CLC ; } Layer 3 tide ([$1403]): A += 4
$00:DA5B 69 04 ADC.B #$04 ; /
$00:DA5D A8 TAY ; Y = A: max speed index
$00:DA5E A5 72 LDA RAM_IsFlying ; \
$00:DA60 F0 02 BEQ $DA64 ; |
$00:DA62 C8 INY ; } In the air: Y += 2
$00:DA63 C8 INY ; /
$00:DA64 20 42 D7 JSR.W $D742 ; Accelerate toward the speed limit ($D742)
$00:DA67 80 13 BRA $DA7C ; Go to the common tail
$00:DA69 A0 00 LDY.B #$00 ; Y = 0
$00:DA6B BB TYX ; X = Y
$00:DA6C AD 03 14 LDA.W $1403 ; \
$00:DA6F F0 08 BEQ $DA79 ; / Layer 3 tide active?
$00:DA71 A2 1E LDX.B #$1E ; X = $1E: tide deceleration index
$00:DA73 A5 72 LDA RAM_IsFlying ; \
$00:DA75 D0 02 BNE $DA79 ; |
$00:DA77 E8 INX ; } In the air: X += 2
$00:DA78 E8 INX ; /
$00:DA79 20 72 D7 JSR.W $D772 ; Decelerate ($D772)
$00:DA7C 20 62 D0 JSR.W $D062 ; Apply air physics ($D062)
$00:DA7F 22 B1 CE 00 JSL.L $CEB1 ; Cape animation ($CEB1)
$00:DA83 AD A6 14 LDA.W $14A6 ; \
$00:DA86 D0 04 BNE $DA8C ; / Cape spin running: return
$00:DA88 A5 72 LDA RAM_IsFlying ; \
$00:DA8A D0 01 BNE $DA8D ; / In the air? If on the ground, return
$00:DA8C 60 RTS ; Return
$00:DA8D A9 18 LDA.B #$18 ; A = $18: swim pose
$00:DA8F AC 9C 14 LDY.W RAM_FireballImgTimer ; \
$00:DA92 D0 0B BNE $DA9F ; / Fireball pose running ([RAM_FireballImgTimer]): keep A
$00:DA94 AD 96 14 LDA.W $1496 ; \
$00:DA97 4A LSR ; |
$00:DA98 4A LSR ; |
$00:DA99 29 03 AND.B #$03 ; |
$00:DA9B A8 TAY ; } Swim pose from $D980 by animation timer [$1496] / 4
$00:DA9C B9 80 D9 LDA.W $D980,Y ; /
$00:DA9F AC 8F 14 LDY.W $148F ; \
$00:DAA2 F0 01 BEQ $DAA5 ; } Carrying something: A += 1 (holding pose)
$00:DAA4 1A INC A ; /
$00:DAA5 8D E0 13 STA.W MarioFrame ; Store Mario pose
$00:DAA8 60 RTS ; Return
$00:DAA9 A9 0E LDA.B #$0E ; \
$00:DAAB 8D F9 1D STA.W $1DF9 ; / Play swim sound ($0E)
$00:DAAE AD 96 14 LDA.W $1496 ; \
$00:DAB1 09 10 ORA.B #$10 ; } Set bit 4 of animation timer [$1496]: swim stroke animation
$00:DAB3 8D 96 14 STA.W $1496 ; /
$00:DAB6 60 RTS ; Return
;;; $DAB7..DAC5: Table: unclear (water/climb) ;;;
$00:DAB7 .db $10,$08,$F0,$F8 ; Data used by the climbing/water code, purpose unclear
$00:DABB .db $B0,$F0 ; Data used by the climbing/water code, purpose unclear
$00:DABD .db $00,$01,$00,$01,$01,$01,$01,$01 ; Data, purpose unclear
$00:DAC5 .db $01,$01,$01,$01,$01,$01,$01,$01 ; Data, purpose unclear
;;; $DACD..DAD5: Table: Mario pose numbers (unclear) ;;;
$00:DACD .db $22,$15,$22,$15,$21,$1F,$20,$20 ; Data, purpose unclear: Mario pose numbers
$00:DAD5 .db $20,$20,$1F,$21,$1F,$21 ; Data, purpose unclear: Mario pose numbers
;;; $DADB: Table: climbing poses (ClimbingImgs) ;;;
$00:DADB .db $15,$22 ; Climbing poses: $15, $22
;;; $DADD: Mario climbing, tile and position tables (ClimbPunchingImgs) ;;;
;; Starts with the tables and the second half of Mario's climbing code. $00DB17 (entered with a JMP from
;; $CD76): climbing a net or vine.
;; Handles the net door punch/spin ([$149D], [$1878]), jumping off with B, punching the net with A (swaps
;; sides), left/right/up/down
;; movement from the controller, and the climbing animation flip. Stops climbing by clearing [RAM_IsClimbing]
;; ($00DC00).
;; $00DC2D: moves Mario by his speed without gravity (Y speed saved in [$8A], wall running swaps the axes).
;; Calls $00DC4F once per axis.
;; $00DC4F: adds speed * 16 to the position fraction [$13DA,X], then the whole pixels (sign extended, carry
;; included) to [$94,X].
;; Parameters ($00DC4F): X = 0 for X axis, 2 for Y axis.
$00:DADD .db $1E,$23 ; $1E / $23: Mario image while punching a net: [in front, behind]
$00:DADF .db $10,$0F,$0E,$0D,$0C,$0B,$0A,$09 ; Net door spin: X speed by |[$1878]| (index 0-17)
$00:DAE7 .db $08,$07,$06,$05,$05,$05,$05,$05 ; (continued)
$00:DAEF .db $05,$05 ; (continued)
$00:DAF1 .db $20,$01,$40,$01,$2A,$01,$2A,$01 ; Net door spin: word added to X speed/fraction [$7A] by |[$1878]| * 2
$00:DAF9 .db $30,$01,$33,$01,$32,$01,$34,$01 ; (continued)
$00:DB01 .db $36,$01,$38,$01,$3A,$01,$3B,$01 ; (continued)
$00:DB09 .db $45,$01,$45,$01,$45,$01,$45,$01 ; (continued)
$00:DB11 .db $45,$01,$45,$01,$08,$F8 ; (continued; last word $F808)
$00:DB17 64 72 STZ RAM_IsFlying ; Entry (from $CD76): Mario is climbing a net or vine. Not flying
$00:DB19 64 7D STZ RAM_MarioSpeedY ; Y speed = 0
$00:DB1B 9C DF 13 STZ.W $13DF ; Cape image [$13DF] = 0
$00:DB1E 9C 0D 14 STZ.W RAM_IsSpinJump ; Not spin jumping
$00:DB21 AC 9D 14 LDY.W $149D ; Y = [$149D] (net door punch/spin timer)
$00:DB24 F0 57 BEQ $DB7D ; Zero: normal climbing, go to $00DB7D
$00:DB26 AD 78 18 LDA.W $1878 ; A = [$1878] (signed net door spin position)
$00:DB29 10 03 BPL $DB2E ; Positive: keep
$00:DB2B 49 FF EOR.B #$FF ; \
$00:DB2D 1A INC A ; / A = |A|
$00:DB2E AA TAX ; X = |[$1878]|
$00:DB2F C0 1E CPY.B #$1E ; Timer < $1E?
$00:DB31 90 12 BCC $DB45 ; Yes: skip the speed override, go to $00DB45
$00:DB33 BD DF DA LDA.W $DADF,X ; A = X speed from $DADF[|[$1878]|]
$00:DB36 2C 78 18 BIT.W $1878 ; N flag = sign of [$1878]
$00:DB39 10 03 BPL $DB3E ; Positive: keep sign
$00:DB3B 49 FF EOR.B #$FF ; \
$00:DB3D 1A INC A ; / Negate the speed for a negative position
$00:DB3E 85 7B STA RAM_MarioSpeedX ; Mario X speed = A
$00:DB40 64 7A STZ $7A ; X speed fraction ([$7A]) = 0
$00:DB42 9C DA 13 STZ.W $13DA ; X position fraction [$13DA] = 0
$00:DB45 8A TXA ; A = |[$1878]|
$00:DB46 0A ASL ; \
$00:DB47 AA TAX ; / X = |[$1878]| * 2: word index
$00:DB48 AD 78 18 LDA.W $1878 ; A = [$1878]
$00:DB4B C0 08 CPY.B #$08 ; Timer < 8?
$00:DB4D B0 02 BCS $DB51 ; No: keep
$00:DB4F 49 80 EOR.B #$80 ; Yes: invert the sign bit
$00:DB51 0A ASL ; Carry = sign: set means add the table word
$00:DB52 C2 20 REP #$20 ; A 16-bit
$00:DB54 BD F1 DA LDA.W $DAF1,X ; A = $DAF1[X]
$00:DB57 B0 04 BCS $DB5D ; Carry set: keep positive
$00:DB59 49 FF FF EOR.W #$FFFF ; \
$00:DB5C 1A INC A ; / Negate A
$00:DB5D 18 CLC ; Clear carry
$00:DB5E 65 7A ADC $7A ; A += [$7A] (X speed with fraction)
$00:DB60 85 7A STA $7A ; Store back to [$7A]/[$7B]
$00:DB62 E2 20 SEP #$20 ; A 8-bit
$00:DB64 98 TYA ; \
$00:DB65 4A LSR ; } Y = (timer >> 1) & $0E
$00:DB66 29 0E AND.B #$0E ; /
$00:DB68 0D F0 13 ORA.W $13F0 ; Y |= [$13F0] (side/facing bit)
$00:DB6B A8 TAY ; Transfer to Y
$00:DB6C B9 BD DA LDA.W $DABD,Y ; A = Mario direction from $DABD[Y]
$00:DB6F 2C 78 18 BIT.W $1878 ; N flag = sign of [$1878]
$00:DB72 30 02 BMI $DB76 ; Negative: keep direction
$00:DB74 49 01 EOR.B #$01 ; Positive: flip direction
$00:DB76 85 76 STA RAM_MarioDirection ; Mario direction = A
$00:DB78 B9 CD DA LDA.W $DACD,Y ; A = Mario image from $DACD[Y] (net punch frames)
$00:DB7B 80 15 BRA $DB92 ; Go store the image
$00:DB7D 64 7B STZ RAM_MarioSpeedX ; Not punching: X speed = 0
$00:DB7F 64 7A STZ $7A ; X speed fraction = 0
$00:DB81 AE F9 13 LDX.W RAM_IsBehindScenery ; X = [$13F9] (Mario is behind scenery: 0 front, 1 behind)
$00:DB84 AD 9E 14 LDA.W $149E ; A = [$149E] (net punch timer)
$00:DB87 F0 0D BEQ $DB96 ; Zero: not punching, go to $00DB96
$00:DB89 8A TXA ; \
$00:DB8A 1A INC A ; } A = X + 2: index for the cape/punch hitbox
$00:DB8B 1A INC A ; /
$00:DB8C 20 44 D0 JSR.W $D044 ; Set punch hitbox position ($D044)
$00:DB8F BD DD DA LDA.W ClimbPunchingImgs,X ; A = Mario image from ClimbPunchingImgs[X]
$00:DB92 8D E0 13 STA.W MarioFrame ; Mario image = A
$00:DB95 60 RTS ; Return
$00:DB96 A4 75 LDY RAM_IsSwimming ; Y = [RAM_IsSwimming] (swimming flag)
$00:DB98 24 16 BIT $16 ; N = bit 7 of [$16] (B newly pressed), V = bit 6 (A newly pressed)
$00:DB9A 10 10 BPL $DBAC ; B not pressed: go to $00DBAC
$00:DB9C A9 0B LDA.B #$0B ; \
$00:DB9E 85 72 STA RAM_IsFlying ; / [RAM_IsFlying] = $0B: air flag set (jumping off)
$00:DBA0 B9 BB DA LDA.W $DABB,Y ; \
$00:DBA3 85 7D STA RAM_MarioSpeedY ; / Mario Y speed = $DABB[Y] (jump: $B0 land, $F0 water)
$00:DBA5 A9 01 LDA.B #$01 ; \
$00:DBA7 8D FA 1D STA.W $1DFA ; / Play jump sound effect ($1DFA = 1)
$00:DBAA 80 54 BRA $DC00 ; Stop climbing: go to $00DC00
$00:DBAC 50 1C BVC $DBCA ; A not pressed: go to $00DBCA
$00:DBAE A5 74 LDA RAM_IsClimbing ; A = [RAM_IsClimbing]
$00:DBB0 10 18 BPL $DBCA ; Bit 7 clear (vine): go to $00DBCA
$00:DBB2 A9 01 LDA.B #$01 ; \
$00:DBB4 8D F9 1D STA.W $1DF9 ; / Play sound effect ($1DF9 = 1): punch the net
$00:DBB7 8E F0 13 STX.W $13F0 ; [$13F0] = X (side Mario was on)
$00:DBBA A5 94 LDA RAM_MarioXPos ; A = Mario X position low
$00:DBBC 29 08 AND.B #$08 ; \
$00:DBBE 4A LSR ; |
$00:DBBF 4A LSR ; |
$00:DBC0 4A LSR ; } A = ((X pos & 8) >> 3) ^ 1
$00:DBC1 49 01 EOR.B #$01 ; /
$00:DBC3 85 76 STA RAM_MarioDirection ; Mario direction = A (facing depends on net column)
$00:DBC5 A9 08 LDA.B #$08 ; \
$00:DBC7 8D 9E 14 STA.W $149E ; / Net punch timer [$149E] = 8
$00:DBCA BD DB DA LDA.W ClimbingImgs,X ; \
$00:DBCD 8D E0 13 STA.W MarioFrame ; / Mario image = ClimbingImgs[X] (front or behind net)
$00:DBD0 A5 15 LDA RAM_ControllerA ; \
$00:DBD2 29 03 AND.B #$03 ; |
$00:DBD4 F0 1C BEQ $DBF2 ; / Left/Right not pressed: skip to $00DBF2
$00:DBD6 4A LSR ; \
$00:DBD7 AA TAX ; / X = 0 for right, 1 for left
$00:DBD8 A5 8B LDA $8B ; A = [$8B] (climb tile flags)
$00:DBDA 29 18 AND.B #$18 ; \
$00:DBDC C9 18 CMP.B #$18 ; |
$00:DBDE F0 08 BEQ $DBE8 ; / Bits 3 and 4 both set? Yes: go move at $00DBE8
$00:DBE0 A5 74 LDA RAM_IsClimbing ; \
$00:DBE2 10 1C BPL $DC00 ; / Vine (bit 7 clear): stop climbing, go to $00DC00
$00:DBE4 E4 8C CPX $8C ; \
$00:DBE6 F0 0A BEQ $DBF2 ; / Same direction as [$8C] (blocked): go to $00DBF2
$00:DBE8 8A TXA ; \
$00:DBE9 0A ASL ; |
$00:DBEA 05 75 ORA RAM_IsSwimming ; } X = direction * 2 | swimming flag
$00:DBEC AA TAX ; /
$00:DBED BD B7 DA LDA.W $DAB7,X ; \
$00:DBF0 85 7B STA RAM_MarioSpeedX ; / X speed = $DAB7[X] ($10,$08,$F0,$F8)
$00:DBF2 A5 15 LDA RAM_ControllerA ; \
$00:DBF4 29 0C AND.B #$0C ; |
$00:DBF6 F0 1E BEQ $DC16 ; / Up/Down not pressed: go to $00DC16
$00:DBF8 29 08 AND.B #$08 ; \
$00:DBFA D0 07 BNE $DC03 ; / Up pressed: go to $00DC03
$00:DBFC 46 8B LSR $8B ; \
$00:DBFE B0 0B BCS $DC0B ; / Down: shift [$8B]; carry set: go to $00DC0B
$00:DC00 64 74 STZ RAM_IsClimbing ; Mario is not climbing
$00:DC02 60 RTS ; Return
$00:DC03 C8 INY ; \
$00:DC04 C8 INY ; / Y += 2: use the upward speeds
$00:DC05 A5 8B LDA $8B ; \
$00:DC07 29 02 AND.B #$02 ; |
$00:DC09 F0 0B BEQ $DC16 ; / [$8B] bit 1 clear: go to $00DC16
$00:DC0B A5 74 LDA RAM_IsClimbing ; A = [RAM_IsClimbing]
$00:DC0D 30 02 BMI $DC11 ; Net (bit 7): keep X speed, go to $00DC11
$00:DC0F 64 7B STZ RAM_MarioSpeedX ; Vine: X speed = 0
$00:DC11 B9 B7 DA LDA.W $DAB7,Y ; \
$00:DC14 85 7D STA RAM_MarioSpeedY ; / Mario Y speed = $DAB7[Y]
$00:DC16 05 7B ORA RAM_MarioSpeedX ; A = Y speed | X speed (also true when no key pressed)
$00:DC18 F0 12 BEQ $DC2C ; Not moving: Return
$00:DC1A AD 96 14 LDA.W $1496 ; \
$00:DC1D 09 08 ORA.B #$08 ; } [$1496] |= $08 (climb animation timer)
$00:DC1F 8D 96 14 STA.W $1496 ; /
$00:DC22 29 07 AND.B #$07 ; \
$00:DC24 D0 06 BNE $DC2C ; / Low 3 bits non-zero: Return
$00:DC26 A5 76 LDA RAM_MarioDirection ; \
$00:DC28 49 01 EOR.B #$01 ; } Flip Mario direction (climb animation)
$00:DC2A 85 76 STA RAM_MarioDirection ; /
$00:DC2C 60 RTS ; Return
$00:DC2D A5 7D LDA RAM_MarioSpeedY ; \
$00:DC2F 85 8A STA $8A ; / Save Mario Y speed in [$8A]
$00:DC31 AD E3 13 LDA.W RAM_WallWalkStatus ; \
$00:DC34 F0 0A BEQ $DC40 ; / [$13E3] (wall run status) zero: normal movement
$00:DC36 4A LSR ; Carry = bit 0 of wall run status
$00:DC37 A5 7B LDA RAM_MarioSpeedX ; A = Mario X speed
$00:DC39 90 03 BCC $DC3E ; Bit clear: keep sign
$00:DC3B 49 FF EOR.B #$FF ; \
$00:DC3D 1A INC A ; / Negate A
$00:DC3E 85 7D STA RAM_MarioSpeedY ; Wall run: Mario Y speed = +/- X speed
$00:DC40 A2 00 LDX.B #$00 ; \
$00:DC42 20 4F DC JSR.W $DC4F ; / Move X: add speed to X position (X = 0)
$00:DC45 A2 02 LDX.B #$02 ; \
$00:DC47 20 4F DC JSR.W $DC4F ; / Move Y: add speed to Y position (X = 2)
$00:DC4A A5 8A LDA $8A ; \
$00:DC4C 85 7D STA RAM_MarioSpeedY ; / Restore Mario Y speed
$00:DC4E 60 RTS ; Return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Make mario's speed move his XY position.
;X: #$00 = x speed, #$02 = Y speed.
;
;Mario's speed is handled like this:
;
;Mario's smallest amount of movement is not units of pixels, but subpixels-
;1/16 of a pixel. This is to enable the player to have more precise movement
;and have smaller-than-a-pixel movement.
;
;Therefore, his position value can be represented using fixed point binary:
; %PPPPPPPPPPPPPPPP.ssss0000
; -ssss = subpixels (i.e. %0000 = 0/16, %1111 = 15/16)
; -PPPPPPPPPPPPPPPP = Position, in pixels
; -They are stored in RAM as follows:
; -$13DA and $13DC holds the ssss0000 data.
; -$94-$97 holds the PPPPPPPPPPPPPPPP data.
; -Other than movement, most things relating to position such as hitboxes/collision
; do not check for fractional movements, only whole pixels of movement. Essentially
; taking the "floor function" of the XY position.
;
;His speed value ($7B and $7D) can be represented as this in binary:
; %SPPPssss
;
; -ssss = subpixels
; -PPP = whole pixels. When sign bit is clear, it is treated as 0000000000000PPP
; otherwise it is treated as 1111111111111PPP. Therefore increasing the data size
; and keeping the value it represents, so that it can add by mario's pixel position.
; -S = sign bit
;
;When performing math (it adds Mario's position by this value each frame),
;it first handles the ssss and using the carry bit, then PPPPPPPPPPPPPPPP without
;the CLC, like pseudo 16-bit math. For negative XY speed, this handles it using
; two's complement: https://en.wikipedia.org/wiki/Two%27s_complement
; Keep in mind for the carry and adding by negative: it assumes
; the value is unsigned (so #$FFFF + 1 would be #$0000 with carry
; being set). When ADC with carry set, it adds an additional 1, and
; zero otherwise.
;
; positive speed:
; %PPPPPPPPPPPPPPPP.ssss0000
; +%0000000000000PPP.ssss
;
; negative speed:
; %PPPPPPPPPPPPPPPP.ssss0000
; +%1111111111111PPP.ssss
;
;
;There exists multiple versions of these, but for other types of sprites:
; -For a sprite version, see $01ABD8 (SubSprYPosNoGrvty)
; -For bounce sprites, see $02B526
; -For extended sprites, see $02B560
; -For spinning coin from block, see $02B58E
; -For minor extended sprites, see $02B5C8
; -For overworld sprites, see $04FEAB
; Their code may be different because:
;-Their XY position high byte is not adjicent to their XY low byte due to using tables.
;-Main sprites also use $1491 so that platforms will move the player with it.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$00:DC4F B5 7B LDA RAM_MarioSpeedX,X ; A = speed byte ([$7B] or [$7D])
$00:DC51 0A ASL ; \
$00:DC52 0A ASL ; |
$00:DC53 0A ASL ; } A = speed * 16: new fraction bits
$00:DC54 0A ASL ; /
$00:DC55 18 CLC ; \
$00:DC56 7D DA 13 ADC.W $13DA,X ; / A += position fraction [$13DA,X]; carry = overflow
$00:DC59 9D DA 13 STA.W $13DA,X ; Store the new fraction
$00:DC5C C2 20 REP #$20 ; A 16-bit
$00:DC5E 08 PHP ; Save carry
$00:DC5F B5 7B LDA RAM_MarioSpeedX,X ; A = speed (16-bit read)
$00:DC61 4A LSR ; \
$00:DC62 4A LSR ; |
$00:DC63 4A LSR ; } A = speed >> 4 (whole pixels)
$00:DC64 4A LSR ; /
$00:DC65 29 0F 00 AND.W #$000F ; Keep the low 4 bits
$00:DC68 C9 08 00 CMP.W #$0008 ; \
$00:DC6B 90 03 BCC $DC70 ; / >= 8 (negative speed): go sign extend
$00:DC6D 09 F0 FF ORA.W #$FFF0 ; Sign extend to $FFFx
$00:DC70 28 PLP ; Restore carry
$00:DC71 75 94 ADC RAM_MarioXPos,X ; \
$00:DC73 95 94 STA RAM_MarioXPos,X ; / Position [$94,X] += A + carry
$00:DC75 E2 20 SEP #$20 ; A 8-bit
$00:DC77 60 RTS ; Return
;;; $DC78: Tables: walk animation and tile layouts (NumWalkingFrames) ;;;
;; NumWalkingFrames: frames per walk cycle by powerup. $DC7C: walk animation timer by speed (rows of 8).
;; $DCEC / DD32 / DD4E / DE32: Mario tile layout, an index per Mario image selects the first entry in
;; the X/Y offset tables used
;; by the Mario draw routine at $00E2BD (words, signed, relative to Mario's screen position).
$00:DC78 .db $01,$02,$02,$02 ; Number of walking animation frames by powerup
$00:DC7C .db $0A,$08,$06,$04,$03,$02,$01,$01 ; Walk animation timer by speed index: rows of 8, slowest to fastest
$00:DC84 .db $0A,$08,$06,$04,$03,$02,$01,$01
$00:DC8C .db $0A,$08,$06,$04,$03,$02,$01,$01
$00:DC94 .db $08,$06,$04,$03,$02,$01,$01,$01
$00:DC9C .db $08,$06,$04,$03,$02,$01,$01,$01
$00:DCA4 .db $05,$04,$03,$02,$01,$01,$01,$01
$00:DCAC .db $05,$04,$03,$02,$01,$01,$01,$01
$00:DCB4 .db $05,$04,$03,$02,$01,$01,$01,$01
$00:DCBC .db $05,$04,$03,$02,$01,$01,$01,$01
$00:DCC4 .db $05,$04,$03,$02,$01,$01,$01,$01
$00:DCCC .db $05,$04,$03,$02,$01,$01,$01,$01
$00:DCD4 .db $04,$03,$02,$01,$01,$01,$01,$01
$00:DCDC .db $04,$03,$02,$01,$01,$01,$01,$01
$00:DCE4 .db $02,$02,$02,$02,$02,$02,$02,$02
$00:DCEC .db $00,$00,$00,$00,$00,$00,$00,$00 ; Mario image to tile layout index (even index into $DD32)
$00:DCF4 .db $00,$00,$00,$00,$00,$00,$00,$00
$00:DCFC .db $02,$04,$04,$04,$0E,$08,$00,$00
$00:DD04 .db $00,$00,$00,$00,$00,$00,$08,$08
$00:DD0C .db $08,$08,$08,$08,$00,$00,$00,$00
$00:DD14 .db $0C,$10,$12,$14,$16,$18,$1A,$00
$00:DD1C .db $00,$00,$00,$00,$00,$00,$00,$00
$00:DD24 .db $00,$00,$00,$00,$00,$06,$00,$00
$00:DD2C .db $00,$00,$00,$0A,$00,$00
$00:DD32 .db $00,$08,$10,$14,$18,$1E,$24,$24 ; Mario tile layout: byte offset of first tile in the position tables (per layout, facing)
$00:DD3A .db $28,$30,$38,$3E,$44,$4A,$50,$54
$00:DD42 .db $58,$58,$5C,$60,$64,$68,$6C,$70
$00:DD4A .db $74,$78,$7C,$80
$00:DD4E .db $00,$00,$00,$00,$10,$00,$10,$00 ; Mario tile X offsets (words, signed), 2 bytes per tile
$00:DD56 .db $00,$00,$00,$00,$F8,$FF,$F8,$FF
$00:DD5E .db $0E,$00,$06,$00,$F2,$FF,$FA,$FF
$00:DD66 .db $17,$00,$07,$00,$0F,$00,$EA,$FF
$00:DD6E .db $FA,$FF,$FA,$FF,$00,$00,$00,$00
$00:DD76 .db $00,$00,$00,$00,$10,$00,$10,$00
$00:DD7E .db $00,$00,$00,$00,$F8,$FF,$F8,$FF
$00:DD86 .db $00,$00,$F8,$FF,$08,$00,$00,$00
$00:DD8E .db $08,$00,$F8,$FF,$00,$00,$00,$00
$00:DD96 .db $F8,$FF,$00,$00,$00,$00,$10,$00
$00:DD9E .db $02,$00,$00,$00,$FE,$FF,$00,$00
$00:DDA6 .db $00,$00,$00,$00,$FC,$FF,$05,$00
$00:DDAE .db $04,$00,$FB,$FF,$FB,$FF,$06,$00
$00:DDB6 .db $05,$00,$FA,$FF,$F9,$FF,$09,$00
$00:DDBE .db $07,$00,$F7,$FF,$FD,$FF,$FD,$FF
$00:DDC6 .db $03,$00,$03,$00,$FF,$FF,$07,$00
$00:DDCE .db $01,$00,$F9,$FF,$0A,$00,$F6,$FF
$00:DDD6 .db $08,$00,$F8,$FF,$08,$00,$F8,$FF
$00:DDDE .db $00,$00,$04,$00,$FC,$FF,$FE,$FF
$00:DDE6 .db $02,$00,$0B,$00,$F5,$FF,$14,$00
$00:DDEE .db $EC,$FF,$0E,$00,$F3,$FF,$08,$00
$00:DDF6 .db $F8,$FF,$0C,$00,$14,$00,$FD,$FF
$00:DDFE .db $F4,$FF,$F4,$FF,$0B,$00,$0B,$00
$00:DE06 .db $03,$00,$13,$00,$F5,$FF,$05,$00
$00:DE0E .db $F5,$FF,$09,$00,$01,$00,$01,$00
$00:DE16 .db $F7,$FF,$07,$00,$07,$00,$05,$00
$00:DE1E .db $0D,$00,$0D,$00,$FB,$FF,$FB,$FF
$00:DE26 .db $FB,$FF,$FF,$FF,$0F,$00,$01,$00
$00:DE2E .db $F9,$FF,$00,$00
$00:DE32 .db $01,$00,$11,$00,$11,$00,$19,$00 ; Mario tile Y offsets (words, signed), 2 bytes per tile
$00:DE3A .db $01,$00,$11,$00,$11,$00,$19,$00
$00:DE42 .db $0C,$00,$14,$00,$0C,$00,$14,$00
$00:DE4A .db $18,$00,$18,$00,$28,$00,$18,$00
$00:DE52 .db $18,$00,$28,$00,$06,$00,$16,$00
$00:DE5A .db $01,$00,$11,$00,$09,$00,$11,$00
$00:DE62 .db $01,$00,$11,$00,$09,$00,$11,$00
$00:DE6A .db $01,$00,$11,$00,$11,$00,$01,$00
$00:DE72 .db $11,$00,$11,$00,$01,$00,$11,$00
$00:DE7A .db $11,$00,$01,$00,$11,$00,$11,$00
$00:DE82 .db $01,$00,$11,$00,$01,$00,$11,$00
$00:DE8A .db $11,$00,$05,$00,$04,$00,$14,$00
$00:DE92 .db $04,$00,$14,$00,$0C,$00,$14,$00
$00:DE9A .db $0C,$00,$14,$00,$10,$00,$10,$00
$00:DEA2 .db $10,$00,$10,$00,$10,$00,$00,$00
$00:DEAA .db $10,$00,$00,$00,$10,$00,$00,$00
$00:DEB2 .db $10,$00,$00,$00,$0B,$00,$0B,$00
$00:DEBA .db $11,$00,$11,$00,$FF,$FF,$FF,$FF
$00:DEC2 .db $10,$00,$10,$00,$10,$00,$10,$00
$00:DECA .db $10,$00,$10,$00,$10,$00,$15,$00
$00:DED2 .db $15,$00,$25,$00,$25,$00,$04,$00
$00:DEDA .db $04,$00,$04,$00,$14,$00,$14,$00
$00:DEE2 .db $04,$00,$14,$00,$14,$00,$04,$00
$00:DEEA .db $04,$00,$14,$00,$04,$00,$04,$00
$00:DEF2 .db $14,$00,$00,$00,$08,$00,$00,$00
$00:DEFA .db $00,$00,$08,$00,$00,$00,$00,$00
$00:DF02 .db $10,$00,$18,$00,$00,$00,$10,$00
$00:DF0A .db $18,$00,$00,$00,$10,$00,$00,$00
$00:DF12 .db $10,$00,$F8,$FF
;;; $DF16: Table: tileset offset by powerup (TilesetIndex) ;;;
;; Added to Mario's image number by powerup (small, big, cape, fire) before the tile table lookups. Not used
;; for images >= $3D.
$00:DF16 .db $00,$46,$83,$46 ; Tileset index offset added to Mario frame by powerup (small, big, cape, fire)
;;; $DF1A: Table: image to 8x8 tile set (TileExpansion?) ;;;
;; Maps image (plus tileset offset) to an index into Mario8x8Tiles (4 bytes per set). Mostly 0.
$00:DF1A .db $00,$00,$00,$00,$00,$00,$00,$00 ; Mario image to first 8x8 tile set (index into Mario8x8Tiles, 4 per set)
$00:DF22 .db $00,$00,$00,$00,$00,$00,$00,$00
$00:DF2A .db $00,$00,$00,$00,$00,$00,$00,$00
$00:DF32 .db $00,$00,$00,$00,$00,$00,$00,$00
$00:DF3A .db $00,$00,$00,$00,$00,$00,$00,$00
$00:DF42 .db $00,$00,$00,$00,$00,$00,$00,$00
$00:DF4A .db $00,$00,$00,$00,$00,$00,$00,$00
$00:DF52 .db $00,$00,$00,$00,$00,$00,$00,$00
$00:DF5A .db $00,$00,$00,$28,$00,$00,$00,$00
$00:DF62 .db $00,$00,$04,$04,$04,$00,$00,$00
$00:DF6A .db $00,$00,$08,$00,$00,$00,$00,$0C
$00:DF72 .db $0C,$0C,$00,$00,$10,$10,$14,$14
$00:DF7A .db $18,$18,$00,$00,$1C,$00,$00,$00
$00:DF82 .db $00,$20,$00,$00,$00,$00,$24,$00
$00:DF8A .db $00,$00,$00,$00,$00,$00,$00,$00
$00:DF92 .db $00,$00,$00,$00,$00,$00,$00,$00
$00:DF9A .db $00,$00,$00,$00,$00,$00,$00,$04
$00:DFA2 .db $04,$04,$00,$00,$00,$00,$00,$08
$00:DFAA .db $00,$00,$00,$00,$0C,$0C,$0C,$00
$00:DFB2 .db $00,$10,$10,$14,$14,$18,$18,$00
$00:DFBA .db $00,$1C,$00,$00,$00,$00,$20,$00
$00:DFC2 .db $00,$00,$00,$24,$00,$00,$00,$00
$00:DFCA .db $00,$00,$00,$00,$00,$00,$00,$00
$00:DFD2 .db $00,$00,$00,$00,$00,$00,$00,$00
;;; $DFDA: Table: Mario OAM tile numbers (Mario8x8Tiles) ;;;
;; Sets of four tiles: 16x16 upper, 16x16 lower, two extra 8x8 tiles ($80 = not drawn). The cape set ($2C)
;; starts at $00E006.
;; Followed by $E00C and $E0CC: the upper and lower body graphic tile numbers per image, used by
;; the Mario GFX DMA code.
$00:DFDA .db $00,$02,$80,$80,$00,$02,$0C,$80 ; Mario 8x8 tile sets: 16x16 upper, 16x16 lower, two extras ($80 = unused)
$00:DFE2 .db $00,$02,$1A,$1B,$00,$02,$0D,$80
$00:DFEA .db $00,$02,$22,$23,$00,$02,$32,$33
$00:DFF2 .db $00,$02,$0A,$0B,$00,$02,$30,$31
$00:DFFA .db $00,$02,$20,$21,$00,$02,$7E,$80
$00:E002 .db $00,$02,$02,$80,$04,$7F,$4A,$5B ; Last small sets; $E006 starts the cape set ($2C): $04,$7F,$4A,$5B
$00:E00A .db $4B,$5A ; (end of Mario8x8Tiles)
$00:E00C .db $50,$50,$50,$09,$50,$50,$50,$50 ; Mario image to upper-body graphics tile (for Mario GFX DMA, [$0A])
$00:E014 .db $50,$50,$09,$2B,$50,$2D,$50,$D5
$00:E01C .db $2E,$C4,$C4,$C4,$D6,$B6,$50,$50
$00:E024 .db $50,$50,$50,$50,$50,$C5,$D7,$2A
$00:E02C .db $E0,$50,$D5,$29,$2C,$B6,$D6,$28
$00:E034 .db $E0,$E0,$C5,$C5,$C5,$C5,$C5,$C5
$00:E03C .db $5C,$5C,$50,$5A,$B6,$50,$28,$28
$00:E044 .db $C5,$D7,$28,$70,$C5,$70,$1C,$93
$00:E04C .db $C5,$C5,$0B,$85,$90,$84,$70,$70
$00:E054 .db $70,$A0,$70,$70,$70,$70,$70,$70
$00:E05C .db $A0,$74,$70,$80,$70,$84,$17,$A4
$00:E064 .db $A4,$A4,$B3,$B0,$70,$70,$70,$70
$00:E06C .db $70,$70,$70,$E2,$72,$0F,$61,$70
$00:E074 .db $63,$82,$C7,$90,$B3,$D4,$A5,$C0
$00:E07C .db $08,$54,$0C,$0E,$1B,$51,$49,$4A
$00:E084 .db $48,$4B,$4C,$5D,$5E,$5F,$E3,$90
$00:E08C .db $5F,$5F,$C5,$70,$70,$70,$A0,$70
$00:E094 .db $70,$70,$70,$70,$70,$A0,$74,$70
$00:E09C .db $80,$70,$84,$17,$A4,$A4,$A4,$B3
$00:E0A4 .db $B0,$70,$70,$70,$70,$70,$70,$70
$00:E0AC .db $E2,$72,$0F,$61,$70,$63,$82,$C7
$00:E0B4 .db $90,$B3,$D4,$A5,$C0,$08,$64,$0C
$00:E0BC .db $0E,$1B,$51,$49,$4A,$48,$4B,$4C
$00:E0C4 .db $5D,$5E,$5F,$E3,$90,$5F,$5F,$C5
$00:E0CC .db $71,$60,$60,$19,$94,$96,$96,$A2 ; Mario image to lower-body graphics tile (for Mario GFX DMA, [$0B])
$00:E0D4 .db $97,$97,$18,$3B,$B4,$3D,$A7,$E5
$00:E0DC .db $2F,$D3,$C3,$C3,$F6,$D0,$B1,$81
$00:E0E4 .db $B2,$86,$B4,$87,$A6,$D1,$F7,$3A
$00:E0EC .db $F0,$F4,$F5,$39,$3C,$C6,$E6,$38
$00:E0F4 .db $F1,$F0,$C5,$C5,$C5,$C5,$C5,$C5
$00:E0FC .db $6C,$4D,$71,$6A,$6B,$60,$38,$F1
$00:E104 .db $5B,$69,$F1,$F1,$4E,$E1,$1D,$A3
$00:E10C .db $C5,$C5,$1A,$95,$10,$07,$02,$01
$00:E114 .db $00,$02,$14,$13,$12,$30,$27,$26
$00:E11C .db $30,$03,$15,$04,$31,$07,$E7,$25
$00:E124 .db $24,$23,$62,$36,$33,$91,$34,$92
$00:E12C .db $35,$A1,$32,$F2,$73,$1F,$C0,$C1
$00:E134 .db $C2,$83,$D2,$10,$B7,$E4,$B5,$61
$00:E13C .db $0A,$55,$0D,$75,$77,$1E,$59,$59
$00:E144 .db $58,$02,$02,$6D,$6E,$6F,$F3,$68
$00:E14C .db $6F,$6F,$06,$02,$01,$00,$02,$14
$00:E154 .db $13,$12,$30,$27,$26,$30,$03,$15
$00:E15C .db $04,$31,$07,$E7,$25,$24,$23,$62
$00:E164 .db $36,$33,$91,$34,$92,$35,$A1,$32
$00:E16C .db $F2,$73,$1F,$C0,$C1,$C2,$83,$D2
$00:E174 .db $10,$B7,$E4,$B5,$61,$0A,$55,$0D
$00:E17C .db $75,$77,$1E,$59,$59,$58,$02,$02
$00:E184 .db $6D,$6E,$6F,$F3,$68,$6F,$6F,$06
;;; $E18C: Mario OAM drawing and cape data tables, draw routine (MarioPalIndex) ;;;
;; MarioPalIndex: OAM X flip bit by direction. $E18E..E266: cape tile data and layouts. $E292:
;; invincibility flash masks.
;; $E2A2: Mario/Luigi palette pointers by powerup (entries 4-7 cycle for the star). $E2B2..E2B9:
;; OAM offsets and priority.
;; $00E2BD (called with JSL from banks 01, 02, 04, 0C): Mario graphics. Handles Yoshi, star and power-up
;; palette flashing, the star
;; timer and its music restore, invincibility flicker, then writes Mario's OAM tiles (four body tiles plus up
;; to three cape tiles) and
;; ends with $F636 (Mario graphics DMA setup). $00E45D: adds one tile at OAM offset Y from tile set
;; [$06] and offsets [$05].
$00:E18C .db $00,$40 ; OAM property bits by direction: no flip, X flip
$00:E18E .db $00,$00,$00,$00,$00,$00,$00,$00 ; Mario image to index into cape tile data ($E1D4)
$00:E196 .db $00,$00,$00,$00,$00,$0D,$00,$10
$00:E19E .db $13,$22,$25,$28,$00,$16,$00,$00
$00:E1A6 .db $00,$00,$00,$00,$00,$08,$19,$1C
$00:E1AE .db $04,$1F,$10,$10,$00,$16,$10,$06
$00:E1B6 .db $04,$08,$2B,$30,$35,$3A,$3F,$43
$00:E1BE .db $00,$00,$00,$00,$00,$00,$00,$00
$00:E1C6 .db $16,$16,$00,$00,$08,$00,$00,$00
$00:E1CE .db $00,$00,$00,$10,$04,$00
$00:E1D4 .db $06 ; Cape tile data: [skip first cape tile flag]
$00:E1D5 .db $00 ; Cape tile data: cape tile set / image base ($0C)
$00:E1D6 .db $06 ; Cape tile data: layout index ($05 base)
$00:E1D7 .db $00 ; Cape tile data: value for [$0D]
$00:E1D8 .db $86,$02,$06,$03,$06,$01,$06,$CE ; Cape tile data: groups; byte for [$0E] is the third cape tile set
$00:E1E0 .db $06,$06,$40,$00,$06,$2C,$06,$06
$00:E1E8 .db $44,$0E,$86,$2C,$06,$86,$2C,$0A
$00:E1F0 .db $86,$84,$08,$06,$0A,$02,$06,$AC
$00:E1F8 .db $10,$06,$CC,$10,$06,$AE,$10,$00
$00:E200 .db $8C,$14,$80,$2E,$00,$CA,$16,$91
$00:E208 .db $2F,$00,$8E,$18,$81,$30,$00,$EB
$00:E210 .db $1A,$90,$31,$04,$ED,$1C,$82,$06
$00:E218 .db $92,$1E
$00:E21A .db $84,$86,$88,$8A,$8C,$8E,$90,$90 ; Cape tile layout: byte offset in Mario tile position tables, by (index | direction)
$00:E222 .db $92,$94,$96,$98,$9A,$9C,$9E,$A0
$00:E22A .db $A2,$A4,$A6,$A8,$AA,$B0,$B6,$BC
$00:E232 .db $C2,$C8,$CE,$D4,$DA,$DE,$E2,$E2
$00:E23A .db $0A,$0A,$84,$0A,$88,$88,$88,$88 ; Cape tile set per cape image ([$13DF]) * 4 | base
$00:E242 .db $8A,$8A,$8A,$8A,$44,$44,$44,$44
$00:E24A .db $42,$42,$42,$42,$40,$40,$40,$40
$00:E252 .db $22,$22,$22,$22,$A4,$A4,$A4,$A4
$00:E25A .db $A6,$A6,$A6,$A6,$86,$86,$86,$86
$00:E262 .db $6E,$6E,$6E,$6E
$00:E266 .db $02,$02,$02,$0C,$00,$00,$00,$00 ; Cape layout index per cape image ([$13DF]) * 4 | base
$00:E26E .db $00,$00,$00,$00,$00,$00,$00,$00
$00:E276 .db $00,$00,$00,$00,$00,$00,$00,$00
$00:E27E .db $00,$00,$00,$00,$04,$12,$04,$04
$00:E286 .db $04,$12,$04,$04,$04,$12,$04,$04
$00:E28E .db $04,$12,$04,$04
$00:E292 .db $01,$01,$01,$01,$02,$02,$02,$02 ; Invincibility flash masks, by timer / 8
$00:E29A .db $04,$04,$04,$04,$08,$08,$08,$08
$00:E2A2 .db $C8,$B2,$DC,$B2,$C8,$B2,$DC,$B2 ; Mario palette ROM pointers (bank $00): by powerup*2 + player; entries 4-7 cycle for the star
$00:E2AA .db $C8,$B2,$DC,$B2,$F0,$B2,$04,$B3 ; (continued; star cycle uses entries 4-7)
$00:E2B2 .db $10,$D4,$10,$E8 ; OAM buffer offset of Mario's tiles: in front, behind scenery
$00:E2B6 .db $08,$CC,$08 ; OAM buffer offset of the cape tiles: in front, behind scenery
$00:E2B9 .db $E0,$10,$10,$30 ; OAM property (priority) when behind scenery (index 1 = $10)
;
$00:E2BD 8B PHB ; \
$00:E2BE 4B PHK ; |
$00:E2BF AB PLB ; / Data bank = $00
$00:E2C0 A5 78 LDA $78 ; \
$00:E2C2 C9 FF CMP.B #$FF ; |
$00:E2C4 F0 04 BEQ $E2CA ; / [$78] = $FF: Mario fully hidden, skip Yoshi handling
$00:E2C6 22 70 EA 01 JSL.L $EA70 ; Handle Yoshi if Mario is riding ($EA70)
$00:E2CA AC 9B 14 LDY.W RAM_FlashingPalTimer ; Y = [RAM_FlashingPalTimer]
$00:E2CD D0 39 BNE $E308 ; Non-zero (power-up flash): go to palette cycling at $00E308
$00:E2CF AC 90 14 LDY.W $1490 ; Y = [$1490] (star timer)
$00:E2D2 F0 40 BEQ $E314 ; No star: use the normal palette
$00:E2D4 A5 78 LDA $78 ; \
$00:E2D6 C9 FF CMP.B #$FF ; |
$00:E2D8 F0 09 BEQ $E2E3 ; / Mario hidden: do not count down the star timer
$00:E2DA A5 14 LDA RAM_FrameCounterB ; \
$00:E2DC 29 03 AND.B #$03 ; |
$00:E2DE D0 03 BNE $E2E3 ; / Only every 4th frame (frame counter B)
$00:E2E0 CE 90 14 DEC.W $1490 ; Star timer--
$00:E2E3 A5 13 LDA RAM_FrameCounter ; A = frame counter
$00:E2E5 C0 1E CPY.B #$1E ; \
$00:E2E7 90 21 BCC $E30A ; / Timer < $1E: slow flashing, go to $00E30A
$00:E2E9 D0 21 BNE $E30C ; Timer > $1E: fast flashing, go to $00E30C
$00:E2EB AD DA 0D LDA.W $0DDA ; \
$00:E2EE C9 FF CMP.B #$FF ; |
$00:E2F0 F0 16 BEQ $E308 ; / Timer = $1E: [$0DDA] (level music) = $FF: no change
$00:E2F2 29 7F AND.B #$7F ; \
$00:E2F4 8D DA 0D STA.W $0DDA ; / [$0DDA] bit 7 cleared (restore level music)
$00:E2F7 AA TAX ; X = music number
$00:E2F8 AD AD 14 LDA.W RAM_BluePowTimer ; \
$00:E2FB 0D AE 14 ORA.W RAM_SilverPowTimer ; |
$00:E2FE 0D 0C 19 ORA.W $190C ; |
$00:E301 F0 02 BEQ $E305 ; / P-switch/coin timers all zero: keep music in X
$00:E303 A2 0E LDX.B #$0E ; Otherwise X = $0E (P-switch music)
$00:E305 8E FB 1D STX.W $1DFB ; Request music X
$00:E308 A5 13 LDA RAM_FrameCounter ; A = frame counter
$00:E30A 4A LSR ; \
$00:E30B 4A LSR ; / A = frame counter >> 2
$00:E30C 29 03 AND.B #$03 ; A &= 3
$00:E30E 1A INC A ; \
$00:E30F 1A INC A ; |
$00:E310 1A INC A ; } A += 4: palette entries 4-7 (star colours)
$00:E311 1A INC A ; /
$00:E312 80 06 BRA $E31A ; Go to $00E31A
$00:E314 A5 19 LDA RAM_MarioPowerUp ; \
$00:E316 0A ASL ; } A = [RAM_MarioPowerUp] * 2 | [$0DB3] (player)
$00:E317 0D B3 0D ORA.W $0DB3 ; /
$00:E31A 0A ASL ; \
$00:E31B A8 TAY ; / Y = A * 2: word index
$00:E31C C2 20 REP #$20 ; A 16-bit
$00:E31E B9 A2 E2 LDA.W $E2A2,Y ; \
$00:E321 8D 82 0D STA.W $0D82 ; / Palette pointer [$0D82] = $E2A2[Y]
$00:E324 E2 20 SEP #$20 ; A 8-bit
$00:E326 AE E0 13 LDX.W MarioFrame ; X = Mario image [MarioFrame]
$00:E329 A9 05 LDA.B #$05 ; \
$00:E32B CD E3 13 CMP.W RAM_WallWalkStatus ; |
$00:E32E B0 0E BCS $E33E ; / Wall run status <= 5: go to $00E33E
$00:E330 AD E3 13 LDA.W RAM_WallWalkStatus ; A = wall run status
$00:E333 A4 19 LDY RAM_MarioPowerUp ; \
$00:E335 F0 04 BEQ $E33B ; / Y = powerup; small: go to $00E33B
$00:E337 E0 13 CPX.B #$13 ; \
$00:E339 D0 02 BNE $E33D ; / Image $13: skip the invert
$00:E33B 49 01 EOR.B #$01 ; Invert bit 0
$00:E33D 4A LSR ; Shift right: carry for the position subtraction
$00:E33E C2 20 REP #$20 ; A 16-bit
$00:E340 A5 94 LDA RAM_MarioXPos ; \
$00:E342 E5 1A SBC RAM_ScreenBndryXLo ; |
$00:E344 85 7E STA $7E ; / [$7E] = Mario X position - screen X (X on screen)
$00:E346 AD 8B 18 LDA.W $188B ; \
$00:E349 29 FF 00 AND.W #$00FF ; |
$00:E34C 18 CLC ; |
$00:E34D 65 96 ADC RAM_MarioYPos ; / A = [$188B] + Mario Y position
$00:E34F A4 19 LDY RAM_MarioPowerUp ; \
$00:E351 C0 01 CPY.B #$01 ; |
$00:E353 A0 01 LDY.B #$01 ; |
$00:E355 B0 02 BCS $E359 ; / Y = 1; powerup >= 1: skip the adjustment
$00:E357 3A DEC A ; \
$00:E358 88 DEY ; / Small Mario: A--, Y--
$00:E359 E0 0A CPX.B #$0A ; \
$00:E35B B0 03 BCS $E360 ; |
$00:E35D CC DB 13 CPY.W $13DB ; / Image >= $0A: skip compare, else compare Y with [$13DB]
$00:E360 E5 1C SBC RAM_ScreenBndryYLo ; A -= screen Y
$00:E362 E0 1C CPX.B #$1C ; \
$00:E364 D0 03 BNE $E369 ; / Image $1C: add 1 with carry
$00:E366 69 01 00 ADC.W #$0001 ; A += 1 + carry
$00:E369 85 80 STA $80 ; [$80] = Mario Y on screen
$00:E36B E2 20 SEP #$20 ; A 8-bit
$00:E36D AD 97 14 LDA.W $1497 ; \
$00:E370 F0 13 BEQ $E385 ; / [$1497] (invincibility timer) = 0: draw normally
$00:E372 4A LSR ; \
$00:E373 4A LSR ; |
$00:E374 4A LSR ; } Y = timer >> 3
$00:E375 A8 TAY ; /
$00:E376 B9 92 E2 LDA.W $E292,Y ; \
$00:E379 2D 97 14 AND.W $1497 ; |
$00:E37C 05 9D ORA RAM_SpritesLocked ; |
$00:E37E 0D FB 13 ORA.W $13FB ; |
$00:E381 D0 02 BNE $E385 ; / Flash mask & timer, | sprites locked | frozen: non-zero draws
$00:E383 AB PLB ; \
$00:E384 6B RTL ; / Skip drawing this frame (flicker), Return
$00:E385 A9 C8 LDA.B #$C8 ; \
$00:E387 E0 43 CPX.B #$43 ; |
$00:E389 D0 02 BNE $E38D ; |
$00:E38B A9 E8 LDA.B #$E8 ; |
$00:E38D 85 04 STA $04 ; / [$04] = $C8 (tile size bits: 16x16, 16x16, 8x8, 8x8, 16x16...); $E8 for image $43
$00:E38F E0 29 CPX.B #$29 ; \
$00:E391 D0 06 BNE $E399 ; / Image $29: check powerup, else go to $00E399
$00:E393 A5 19 LDA RAM_MarioPowerUp ; \
$00:E395 D0 02 BNE $E399 ; / Not small: keep image
$00:E397 A2 20 LDX.B #$20 ; Small: X = $20 (small version of image $29)
$00:E399 BD EC DC LDA.W $DCEC,X ; \
$00:E39C 05 76 ORA RAM_MarioDirection ; |
$00:E39E A8 TAY ; / Y = $DCEC[X] | direction
$00:E39F B9 32 DD LDA.W $DD32,Y ; \
$00:E3A2 85 05 STA $05 ; / [$05] = $DD32[Y] (tile layout offset)
$00:E3A4 A4 19 LDY RAM_MarioPowerUp ; Y = powerup
$00:E3A6 AD E0 13 LDA.W MarioFrame ; \
$00:E3A9 C9 3D CMP.B #$3D ; |
$00:E3AB B0 03 BCS $E3B0 ; / Image >= $3D: no tileset offset
$00:E3AD 79 16 DF ADC.W TilesetIndex,Y ; A += TilesetIndex[powerup]
$00:E3B0 A8 TAY ; Y = image + tileset offset
$00:E3B1 B9 1A DF LDA.W TileExpansion?,Y ; \
$00:E3B4 85 06 STA $06 ; / [$06] = TileExpansion?[Y] (8x8 tile set index)
$00:E3B6 B9 0C E0 LDA.W $E00C,Y ; \
$00:E3B9 85 0A STA $0A ; / [$0A] = $E00C[Y] (upper body graphic tile)
$00:E3BB B9 CC E0 LDA.W $E0CC,Y ; \
$00:E3BE 85 0B STA $0B ; / [$0B] = $E0CC[Y] (lower body graphic tile)
$00:E3C0 A5 64 LDA $64 ; A = [$64] (Mario OAM priority property)
$00:E3C2 AE F9 13 LDX.W RAM_IsBehindScenery ; \
$00:E3C5 F0 03 BEQ $E3CA ; / X = [$13F9]; in front of scenery: keep A
$00:E3C7 BD B9 E2 LDA.W $E2B9,X ; Behind scenery: A = $E2B9[X]
$00:E3CA BC B2 E2 LDY.W $E2B2,X ; Y = OAM offset from $E2B2[X]
$00:E3CD A6 76 LDX RAM_MarioDirection ; X = direction
$00:E3CF 1D 8C E1 ORA.W MarioPalIndex,X ; A |= $E18C[X] (X flip by direction)
$00:E3D2 99 03 03 STA.W OAM_Prop,Y ; \
$00:E3D5 99 07 03 STA.W OAM_Tile2Prop,Y ; |
$00:E3D8 99 0F 03 STA.W OAM_Tile4Prop,Y ; |
$00:E3DB 99 13 03 STA.W $0313,Y ; |
$00:E3DE 99 FB 02 STA.W $02FB,Y ; |
$00:E3E1 99 FF 02 STA.W $02FF,Y ; } Set OAM properties of six of Mario's slots
$00:E3E4 A6 04 LDX $04 ; \
$00:E3E6 E0 E8 CPX.B #$E8 ; |
$00:E3E8 D0 02 BNE $E3EC ; / [$04] = $E8 (image $43): leave flip alone
$00:E3EA 49 40 EOR.B #$40 ; Otherwise toggle X flip for slot 3
$00:E3EC 99 0B 03 STA.W OAM_Tile3Prop,Y ; Store the property of slot 3
$00:E3EF 20 5D E4 JSR.W $E45D ; \
$00:E3F2 20 5D E4 JSR.W $E45D ; |
$00:E3F5 20 5D E4 JSR.W $E45D ; |
$00:E3F8 20 5D E4 JSR.W $E45D ; / Draw four body tiles ($E45D)
$00:E3FB A5 19 LDA RAM_MarioPowerUp ; \
$00:E3FD C9 02 CMP.B #$02 ; |
$00:E3FF D0 57 BNE $E458 ; / Not cape powerup: go to $00E458
$00:E401 5A PHY ; Save OAM offset
$00:E402 A9 2C LDA.B #$2C ; \
$00:E404 85 06 STA $06 ; / Cape tile set [$06] = $2C
$00:E406 AE E0 13 LDX.W MarioFrame ; X = Mario image
$00:E409 BD 8E E1 LDA.W $E18E,X ; \
$00:E40C AA TAX ; / X = $E18E[image]: cape data index
$00:E40D BD D7 E1 LDA.W $E1D7,X ; \
$00:E410 85 0D STA $0D ; / [$0D] = $E1D7[X]
$00:E412 BD D8 E1 LDA.W $E1D8,X ; \
$00:E415 85 0E STA $0E ; / [$0E] = $E1D8[X] (third cape tile set)
$00:E417 BD D5 E1 LDA.W $E1D5,X ; \
$00:E41A 85 0C STA $0C ; / [$0C] = $E1D5[X]
$00:E41C C9 04 CMP.B #$04 ; \
$00:E41E B0 12 BCS $E432 ; / [$0C] >= 4: go to $00E432
$00:E420 AD DF 13 LDA.W $13DF ; \
$00:E423 0A ASL ; |
$00:E424 0A ASL ; |
$00:E425 05 0C ORA $0C ; / Y = [$13DF] (cape image) * 4 | [$0C]
$00:E427 A8 TAY ; Transfer to Y
$00:E428 B9 3A E2 LDA.W $E23A,Y ; \
$00:E42B 85 0C STA $0C ; / [$0C] = $E23A[Y]
$00:E42D B9 66 E2 LDA.W $E266,Y ; A = $E266[Y]
$00:E430 80 03 BRA $E435 ; Go to $00E435
$00:E432 BD D6 E1 LDA.W $E1D6,X ; A = $E1D6[X]
$00:E435 05 76 ORA RAM_MarioDirection ; A |= direction
$00:E437 A8 TAY ; Y = A
$00:E438 B9 1A E2 LDA.W $E21A,Y ; \
$00:E43B 85 05 STA $05 ; / [$05] = $E21A[Y] (cape layout offset)
$00:E43D 7A PLY ; Restore OAM offset
$00:E43E BD D4 E1 LDA.W $E1D4,X ; A = $E1D4[X]
$00:E441 04 78 TSB $78 ; Set bits in tile mask [$78]
$00:E443 30 03 BMI $E448 ; Bit 7 of the data set: skip the first cape tile
$00:E445 20 5D E4 JSR.W $E45D ; Draw first cape tile
$00:E448 AE F9 13 LDX.W RAM_IsBehindScenery ; X = [$13F9]
$00:E44B BC B6 E2 LDY.W $E2B6,X ; Y = cape OAM offset $E2B6[X]
$00:E44E 20 5D E4 JSR.W $E45D ; Draw second cape tile
$00:E451 A5 0E LDA $0E ; \
$00:E453 85 06 STA $06 ; / [$06] = [$0E]: third tile set
$00:E455 20 5D E4 JSR.W $E45D ; Draw third cape tile
$00:E458 20 36 F6 JSR.W $F636 ; Set up Mario graphics DMA tile addresses ($F636)
$00:E45B AB PLB ; Restore data bank
$00:E45C 6B RTL ; Return long
$00:E45D 46 78 LSR $78 ; \
$00:E45F B0 3E BCS $E49F ; / Next bit of tile mask [$78] set: skip this tile
$00:E461 A6 06 LDX $06 ; X = [$06] (index into Mario8x8Tiles)
$00:E463 BD DA DF LDA.W Mario8x8Tiles,X ; A = tile number
$00:E466 30 37 BMI $E49F ; $80 and up: tile unused, skip
$00:E468 99 02 03 STA.W OAM_Tile,Y ; OAM tile = A
$00:E46B A6 05 LDX $05 ; X = [$05] (position table offset)
$00:E46D C2 20 REP #$20 ; A 16-bit
$00:E46F A5 80 LDA $80 ; A = [$80] (Mario Y screen position)
$00:E471 18 CLC ; Clear carry
$00:E472 7D 32 DE ADC.W $DE32,X ; A += Y offset $DE32[X]
$00:E475 48 PHA ; Save tile Y
$00:E476 18 CLC ; \
$00:E477 69 10 00 ADC.W #$0010 ; |
$00:E47A C9 00 01 CMP.W #$0100 ; / Carry set if Y + $10 >= $100 (off-screen)
$00:E47D 68 PLA ; Restore tile Y
$00:E47E E2 20 SEP #$20 ; A 8-bit
$00:E480 B0 1D BCS $E49F ; Off-screen: skip
$00:E482 99 01 03 STA.W OAM_DispY,Y ; OAM Y position = A
$00:E485 C2 20 REP #$20 ; A 16-bit
$00:E487 A5 7E LDA $7E ; A = [$7E] (Mario X screen position)
$00:E489 18 CLC ; Clear carry
$00:E48A 7D 4E DD ADC.W $DD4E,X ; A += X offset $DD4E[X]
$00:E48D 48 PHA ; Save tile X
$00:E48E 18 CLC ; \
$00:E48F 69 80 00 ADC.W #$0080 ; |
$00:E492 C9 00 02 CMP.W #$0200 ; / Carry set if X + $80 >= $200 (off-screen)
$00:E495 68 PLA ; Restore tile X
$00:E496 E2 20 SEP #$20 ; A 8-bit
$00:E498 B0 05 BCS $E49F ; Off-screen: skip
$00:E49A 99 00 03 STA.W OAM_DispX,Y ; OAM X position = A
$00:E49D EB XBA ; Swap to the high byte
$00:E49E 4A LSR ; Carry = X position bit 8
$00:E49F 08 PHP ; Save carry
$00:E4A0 98 TYA ; \
$00:E4A1 4A LSR ; |
$00:E4A2 4A LSR ; } X = Y / 4: OAM size table index
$00:E4A3 AA TAX ; /
$00:E4A4 06 04 ASL $04 ; Carry = next size bit of [$04]
$00:E4A6 2A ROL ; Rotate size bit into A
$00:E4A7 28 PLP ; Restore carry (X bit 8)
$00:E4A8 2A ROL ; Rotate X bit 8 into A
$00:E4A9 29 03 AND.B #$03 ; Keep both bits
$00:E4AB 9D 60 04 STA.W OAM_TileSize,X ; OAM size/X high table [X] = A
$00:E4AE C8 INY ; \
$00:E4AF C8 INY ; |
$00:E4B0 C8 INY ; } OAM offset Y += 4: next slot
$00:E4B1 C8 INY ; /
$00:E4B2 E6 05 INC $05 ; \
$00:E4B4 E6 05 INC $05 ; / [$05] += 2: next position entry
$00:E4B6 E6 06 INC $06 ; [$06]++: next tile
$00:E4B8 60 RTS ; Return
;;; $E4B9..E4D9: Table: slope steepness codes ;;;
$00:E4B9 .db $08,$08,$08,$08,$10,$10,$10,$10 ; Slope steepness code stored in [$13E1], by slope type
$00:E4C1 .db $18,$18,$20,$20,$28,$30,$08,$10 ; (continued)
$00:E4C9 .db $00,$00,$28,$00,$00,$00,$00,$00 ; (continued)
$00:E4D1 .db $38,$50,$48,$40,$58,$58,$60,$60 ; (continued)
$00:E4D9 .db $00
;;; $E4DA..E4FA: Table: max Y speed on slope ;;;
$00:E4DA .db $10,$10,$10,$10,$10,$10,$10,$10 ; Max Y speed on slope, by slope type
$00:E4E2 .db $20,$20,$20,$20,$30,$30,$40,$30
$00:E4EA .db $30,$30,$30,$00,$00,$00,$00,$00
$00:E4F2 .db $30,$30,$30,$30,$40,$40,$40,$40
$00:E4FA .db $00
;;; $E4FB..E51B: Table: slope launch Y speed ;;;
$00:E4FB .db $00,$00,$00,$00,$00,$00,$00,$00 ; Launch Y speed when running fast into slope, by type
$00:E503 .db $EC,$EC,$EE,$EE,$DA,$DA,$00,$00
$00:E50B .db $00,$00,$00,$00,$00,$00,$00,$00
$00:E513 .db $DA,$DA,$DA,$DA,$00,$00,$00,$00
$00:E51B .db $00
;;; $E51C..E53C: Table: slope height limit ;;;
$00:E51C .db $08,$08,$08,$08,$08,$08,$08,$08 ; Slope height limit, by type
$00:E524 .db $09,$09,$09,$09,$0B,$0B,$0B,$0B
$00:E52C .db $0B,$0B,$0B,$00,$00,$00,$00,$00
$00:E534 .db $0B,$0B,$0B,$0B,$14,$14,$14,$14
$00:E53C .db $06
;;; $E53D..E62D: Tables: slope push and step profiles ;;;
;; Slope X speed push (signed) by slope type, followed by slope step profiles, read by Mario's block
;; interaction code.
$00:E53D .db $FF,$FF,$FF,$FF,$01,$01,$01,$01 ; Slope X speed push (signed), 0 = flat, by slope type
$00:E545 .db $FE,$FE,$02,$02,$FD,$03,$FD,$03
$00:E54D .db $FD,$03,$FD,$00,$00,$00,$00,$00
$00:E555 .db $08,$08,$F8,$F8,$FC,$FC,$04,$04 ; (continued)
$00:E55D .db $00,$00,$00,$00,$00,$00,$01,$01 ; Slope step profiles (more tables follow)
$00:E565 .db $01,$01,$01,$02,$02,$02,$02,$02
$00:E56D .db $03,$03,$03,$03,$03,$04,$04,$04
$00:E575 .db $04,$04,$05,$05,$05,$05,$05,$06
$00:E57D .db $06,$06,$06,$06,$07,$07,$07,$07
$00:E585 .db $07,$08,$08,$08,$08,$08,$09,$09
$00:E58D .db $09,$09,$09,$0A,$0A,$0A,$0A,$0A
$00:E595 .db $0B,$0B,$0B,$0B,$0B,$0C,$0C,$0C
$00:E59D .db $0C,$0C,$0D,$0D,$0D,$0D,$0D,$0E
$00:E5A5 .db $0F,$10,$11,$03,$03,$04,$04,$09
$00:E5AD .db $09,$0A,$0A,$0C,$0C,$0D,$0D,$12
$00:E5B5 .db $13,$14,$15,$16,$17,$1C,$1D,$1E
$00:E5BD .db $1F,$18,$19,$1A,$1B,$08,$09,$0A
$00:E5C5 .db $0B,$0C,$0D,$00,$00,$00,$00,$00
$00:E5CD .db $01,$01,$01,$01,$01,$02,$02,$02
$00:E5D5 .db $02,$02,$03,$03,$03,$03,$03,$04
$00:E5DD .db $04,$04,$04,$04,$05,$05,$05,$05
$00:E5E5 .db $05,$06,$06,$06,$06,$06,$07,$07
$00:E5ED .db $07,$07,$07,$08,$08,$08,$08,$08
$00:E5F5 .db $09,$09,$09,$09,$09,$0A,$0A,$0A
$00:E5FD .db $0A,$0A,$0B,$0B,$0B,$0B,$0B,$0C
$00:E605 .db $0C,$0C,$0C,$0C,$0D,$0D,$0D,$0D
$00:E60D .db $0D,$0E,$0F,$10,$11,$03,$03,$04
$00:E615 .db $04,$09,$09,$0A,$0A,$0C,$0C,$0D
$00:E61D .db $0D,$0C,$0D,$0D,$0C,$16,$17,$1C
$00:E625 .db $1D,$1E,$1F,$18,$19,$1A,$1B,$08
$00:E62D .db $09,$0A,$0B,$0C,$0D
;;; $E632..E82A: Table: slope ground height ;;;
;; 16 bytes per slope type: ground height at each pixel column of the tile. Indexed by (slope type * 16) + X
;; within the tile.
$00:E632 .db $0F,$0F,$0F,$0F,$0E,$0E,$0E,$0E ; Slope ground height by (slope type * 16 + pixel column), 16 bytes per slope
$00:E63A .db $0D,$0D,$0D,$0D,$0C,$0C,$0C,$0C
$00:E642 .db $0B,$0B,$0B,$0B,$0A,$0A,$0A,$0A
$00:E64A .db $09,$09,$09,$09,$08,$08,$08,$08
$00:E652 .db $07,$07,$07,$07,$06,$06,$06,$06
$00:E65A .db $05,$05,$05,$05,$04,$04,$04,$04
$00:E662 .db $03,$03,$03,$03,$02,$02,$02,$02
$00:E66A .db $01,$01,$01,$01,$00,$00,$00,$00
$00:E672 .db $00,$00,$00,$00,$01,$01,$01,$01
$00:E67A .db $02,$02,$02,$02,$03,$03,$03,$03
$00:E682 .db $04,$04,$04,$04,$05,$05,$05,$05
$00:E68A .db $06,$06,$06,$06,$07,$07,$07,$07
$00:E692 .db $08,$08,$08,$08,$09,$09,$09,$09
$00:E69A .db $0A,$0A,$0A,$0A,$0B,$0B,$0B,$0B
$00:E6A2 .db $0C,$0C,$0C,$0C,$0D,$0D,$0D,$0D
$00:E6AA .db $0E,$0E,$0E,$0E,$0F,$0F,$0F,$0F
$00:E6B2 .db $0F,$0F,$0E,$0E,$0D,$0D,$0C,$0C
$00:E6BA .db $0B,$0B,$0A,$0A,$09,$09,$08,$08
$00:E6C2 .db $07,$07,$06,$06,$05,$05,$04,$04
$00:E6CA .db $03,$03,$02,$02,$01,$01,$00,$00
$00:E6D2 .db $00,$00,$01,$01,$02,$02,$03,$03
$00:E6DA .db $04,$04,$05,$05,$06,$06,$07,$07
$00:E6E2 .db $08,$08,$09,$09,$0A,$0A,$0B,$0B
$00:E6EA .db $0C,$0C,$0D,$0D,$0E,$0E,$0F,$0F
$00:E6F2 .db $0F,$0E,$0D,$0C,$0B,$0A,$09,$08
$00:E6FA .db $07,$06,$05,$04,$03,$02,$01,$00
$00:E702 .db $00,$01,$02,$03,$04,$05,$06,$07
$00:E70A .db $08,$09,$0A,$0B,$0C,$0D,$0E,$0F
$00:E712 .db $0F,$0E,$0D,$0C,$0B,$0A,$09,$08
$00:E71A .db $07,$06,$05,$04,$03,$02,$01,$00
$00:E722 .db $00,$01,$02,$03,$04,$05,$06,$07
$00:E72A .db $08,$09,$0A,$0B,$0C,$0D,$0E,$0F
$00:E732 .db $08,$06,$04,$03,$02,$02,$01,$01
$00:E73A .db $00,$00,$00,$00,$00,$00,$00,$00
$00:E742 .db $00,$00,$00,$00,$00,$00,$00,$00
$00:E74A .db $01,$01,$02,$02,$03,$04,$06,$08
$00:E752 .db $FF,$FE,$FD,$FC,$FB,$FA,$F9,$F8
$00:E75A .db $F7,$F6,$F5,$F4,$F3,$F2,$F1,$F0
$00:E762 .db $F0,$F1,$F2,$F3,$F4,$F5,$F6,$F7
$00:E76A .db $F8,$F9,$FA,$FB,$FC,$FD,$FE,$FF
$00:E772 .db $FF,$FF,$FE,$FE,$FD,$FD,$FC,$FC
$00:E77A .db $FB,$FB,$FA,$FA,$F9,$F9,$F8,$F8
$00:E782 .db $F7,$F7,$F6,$F6,$F5,$F5,$F4,$F4
$00:E78A .db $F3,$F3,$F2,$F2,$F1,$F1,$F0,$F0
$00:E792 .db $F0,$F0,$F1,$F1,$F2,$F2,$F3,$F3
$00:E79A .db $F4,$F4,$F5,$F5,$F6,$F6,$F7,$F7
$00:E7A2 .db $F8,$F8,$F9,$F9,$FA,$FA,$FB,$FB
$00:E7AA .db $FC,$FC,$FD,$FD,$FE,$FE,$FF,$FF
$00:E7B2 .db $0F,$0E,$0D,$0C,$0B,$0A,$09,$08
$00:E7BA .db $07,$06,$05,$04,$03,$02,$01,$00
$00:E7C2 .db $00,$01,$02,$03,$04,$05,$06,$07
$00:E7CA .db $08,$09,$0A,$0B,$0C,$0D,$0E,$0F
$00:E7D2 .db $00,$01,$02,$03,$04,$05,$06,$07
$00:E7DA .db $08,$09,$0A,$0B,$0C,$0D,$0E,$0F
$00:E7E2 .db $0F,$0E,$0D,$0C,$0B,$0A,$09,$08
$00:E7EA .db $07,$06,$05,$04,$03,$02,$01,$00
$00:E7F2 .db $10,$10,$10,$10,$10,$10,$10,$10
$00:E7FA .db $0E,$0C,$0A,$08,$06,$04,$02,$00
$00:E802 .db $0E,$0C,$0A,$08,$06,$04,$02,$00
$00:E80A .db $FE,$FC,$FA,$F8,$F6,$F4,$F2,$F0
$00:E812 .db $00,$02,$04,$06,$08,$0A,$0C,$0E
$00:E81A .db $10,$10,$10,$10,$10,$10,$10,$10
$00:E822 .db $F0,$F2,$F4,$F6,$F8,$FA,$FC,$FE
$00:E82A .db $00,$02,$04,$06,$08,$0A
;;; $E830..E898: Table: Mario collision point X offsets ;;;
;; Words, four per set; added to Mario's X position by $F44D to place the layer collision points.
$00:E830 .db $0C,$0E,$08,$00,$0E,$00,$0E,$00 ; Mario collision point X offsets (words), 4 per set
$00:E838 .db $08,$00,$05,$00,$0B,$00,$08,$00
$00:E840 .db $02,$00,$02,$00,$08,$00,$0B,$00
$00:E848 .db $05,$00,$08,$00,$0E,$00,$0E,$00
$00:E850 .db $08,$00,$05,$00,$0B,$00,$08,$00
$00:E858 .db $02,$00,$02,$00,$08,$00,$0B,$00
$00:E860 .db $05,$00,$08,$00,$0E,$00,$0E,$00
$00:E868 .db $08,$00,$05,$00,$0B,$00,$08,$00
$00:E870 .db $02,$00,$02,$00,$08,$00,$0B,$00
$00:E878 .db $05,$00,$08,$00,$0E,$00,$0E,$00
$00:E880 .db $08,$00,$05,$00,$0B,$00,$08,$00
$00:E888 .db $02,$00,$02,$00,$08,$00,$0B,$00
$00:E890 .db $05,$00,$10,$00,$20,$00,$07,$00
$00:E898 .db $00,$00,$F0,$FF
;;; $E89C..E904: Table: Mario collision point Y offsets ;;;
;; Words, four per set; added to Mario's Y position by $F44D. $E8A4 is also read at $00EBA8.
$00:E89C .db $08,$00,$18,$00,$1A,$00,$16,$00 ; Mario collision point Y offsets (words), 4 per set
$00:E8A4 .db $10,$00,$20,$00,$20,$00,$18,$00 ; Mario collision point Y offsets (words), continued; read separately
$00:E8AC .db $1A,$00,$16,$00,$10,$00,$20,$00
$00:E8B4 .db $20,$00,$12,$00,$1A,$00,$0F,$00
$00:E8BC .db $08,$00,$20,$00,$20,$00,$12,$00
$00:E8C4 .db $1A,$00,$0F,$00,$08,$00,$20,$00
$00:E8CC .db $20,$00,$1D,$00,$28,$00,$19,$00
$00:E8D4 .db $13,$00,$30,$00,$30,$00,$1D,$00
$00:E8DC .db $28,$00,$19,$00,$13,$00,$30,$00
$00:E8E4 .db $30,$00,$1A,$00,$28,$00,$16,$00
$00:E8EC .db $10,$00,$30,$00,$30,$00,$1A,$00
$00:E8F4 .db $28,$00,$16,$00,$10,$00,$30,$00
$00:E8FC .db $30,$00,$18,$00,$18,$00,$18,$00
$00:E904 .db $18,$00,$18,$00,$18,$00
;;; $E90A..E91B: Table: side blocked bits and pushes ;;;
$00:E90A .db $01,$02,$11 ; Blocked-status bits per side ($01, $02, $11)
$00:E90D .db $FF ; Word X push per side: -1, +1 (also sign table)
$00:E90E .db $FF,$01,$00
$00:E911 .db $02,$0D ; X position & $0F reference values: $02, $0D
$00:E913 .db $01,$00,$FF,$FF,$01,$00,$01,$00 ; X push words by tile ((tile - $CC) * 2): -1/0/+1
$00:E91B .db $FF,$FF,$FF,$FF
;;; $E91F..E927: Table: tile push Y offsets ;;;
;; Words by (tile - $CC) * 2: Y offsets applied to Mario every 4th frame ($EFBC, tiles $CE-$D1).
$00:E91F .db $00,$00,$00,$00,$FF,$FF,$01,$00 ; Y push words by tile ((tile - $CC) * 2)
$00:E927 .db $FF,$FF,$01,$00
;;; $E92B: Mario level collision, borders and water ;;;
;; Per-frame Mario vs level interaction. Clears the contact flags, runs the tile collision ($EADB) for
;; layer 2 (with its displacement
;; [$26]/[$28] applied to Mario) when [$5B] bit 7 is set, then for layer 1, unless [$185C] diverts to
;; $EE1D.
;; Then handles the screen edges: side exits call SubSideExit; otherwise a solid left/right border keeps Mario
;; 8 px inside, carrying him with
;; the scroll when scrolling is off. Being crushed ([$77] & $1C) or off the right edge kills Mario. Finally
;; updates swimming ([$8A] water bits):
;; entering/leaving water, splashes, bubbles, and the Up+B jump out of the water.
;; Quirk: the BEQ at $00E9CA is redundant (BPL covers it). Several [$13xx]/[$8x] flags are hedged in the line
;; comments.
;; Called by:
;; $00:CD33: Mario animation 0: normal per-frame handling (ResetAni)
;; $00:F8FA: Mario vs Mode 7 boss room platform/ceiling
$00:E92B 20 A6 EA JSR.W $EAA6 ; Reset Mario's collision and water flags ($EAA6)
$00:E92E AD 5C 18 LDA.W $185C ; \
$00:E931 F0 05 BEQ $E938 ; / [$185C] = 0: normal tile collision, go to $00E938
$00:E933 20 1D EE JSR.W $EE1D ; [$185C] set: run the alternate handler instead ($EE1D)
$00:E936 80 54 BRA $E98C ; Skip the tile collision, go to $00E98C
$00:E938 AD EF 13 LDA.W $13EF ; \
$00:E93B 85 8D STA $8D ; / [$8D] = [$13EF] (saved copy of the tile-contact flag)
$00:E93D 9C EF 13 STZ.W $13EF ; [$13EF] = 0
$00:E940 A5 72 LDA RAM_IsFlying ; \
$00:E942 85 8F STA $8F ; / [$8F] = [RAM_IsFlying] (backup of the in-air flag)
$00:E944 A5 5B LDA RAM_IsVerticalLvl ; \
$00:E946 10 30 BPL $E978 ; / Bit 7 of [$5B] clear (layer 2 not solid): go to $00E978
$00:E948 29 82 AND.B #$82 ; \
$00:E94A 85 8E STA $8E ; / [$8E] = [$5B] & $82 (level orientation bits for layer 2)
$00:E94C A9 01 LDA.B #$01 ; \
$00:E94E 8D 33 19 STA.W $1933 ; / [$1933] = 1: process layer 2
$00:E951 C2 20 REP #$20 ; A 16-bit
$00:E953 A5 94 LDA RAM_MarioXPos ; \
$00:E955 18 CLC ; |
$00:E956 65 26 ADC $26 ; |
$00:E958 85 94 STA RAM_MarioXPos ; / Mario X += [$26] (layer 2 X displacement)
$00:E95A A5 96 LDA RAM_MarioYPos ; \
$00:E95C 18 CLC ; |
$00:E95D 65 28 ADC $28 ; |
$00:E95F 85 96 STA RAM_MarioYPos ; / Mario Y += [$28] (layer 2 Y displacement)
$00:E961 E2 20 SEP #$20 ; A 8-bit
$00:E963 20 DB EA JSR.W $EADB ; Check Mario against the tiles of layer 2 ($EADB)
$00:E966 C2 20 REP #$20 ; A 16-bit
$00:E968 A5 94 LDA RAM_MarioXPos ; \
$00:E96A 38 SEC ; |
$00:E96B E5 26 SBC $26 ; |
$00:E96D 85 94 STA RAM_MarioXPos ; / Mario X -= [$26] (undo the displacement)
$00:E96F A5 96 LDA RAM_MarioYPos ; \
$00:E971 38 SEC ; |
$00:E972 E5 28 SBC $28 ; |
$00:E974 85 96 STA RAM_MarioYPos ; / Mario Y -= [$28] (undo the displacement)
$00:E976 E2 20 SEP #$20 ; A 8-bit
$00:E978 0E EF 13 ASL.W $13EF ; [$13EF] <<= 1 (probably moves the layer 2 result to bit 1)
$00:E97B A5 5B LDA RAM_IsVerticalLvl ; \
$00:E97D 29 41 AND.B #$41 ; |
$00:E97F 85 8E STA $8E ; / [$8E] = [$5B] & $41 (level orientation bits for layer 1)
$00:E981 0A ASL ; Bit 6 of [$5B] into the sign flag
$00:E982 30 08 BMI $E98C ; Bit 6 set: skip the layer 1 check, go to $00E98C
$00:E984 9C 33 19 STZ.W $1933 ; [$1933] = 0: process layer 1
$00:E987 06 8D ASL $8D ; [$8D] <<= 1 (same shift for the saved copy)
$00:E989 20 DB EA JSR.W $EADB ; Check Mario against the tiles of layer 1 ($EADB)
$00:E98C AD 96 1B LDA.W $1B96 ; \
$00:E98F F0 10 BEQ $E9A1 ; / [$1B96] = 0 (no side exit): go to the screen border check at $00E9A1
$00:E991 C2 20 REP #$20 ; A 16-bit
$00:E993 A5 7E LDA $7E ; \
$00:E995 C9 FA 00 CMP.W #$00FA ; / Compare Mario's on-screen X ([$7E]) with $FA
$00:E998 E2 20 SEP #$20 ; A 8-bit
$00:E99A 90 5F BCC $E9FB ; Below $FA (not at the right edge): go to $00E9FB
$00:E99C 22 60 B1 05 JSL.L SubSideExit ; At the edge of a side exit level: leave the level (SubSideExit)
$00:E9A0 60 RTS ; Return
$00:E9A1 A5 7E LDA $7E ; \
$00:E9A3 C9 F0 CMP.B #$F0 ; |
$00:E9A5 B0 61 BCS $EA08 ; / On-screen X >= $F0: past the right edge, go kill Mario ($00EA08)
$00:E9A7 A5 77 LDA RAM_MarioObjStatus ; \
$00:E9A9 29 03 AND.B #$03 ; |
$00:E9AB D0 4E BNE $E9FB ; / Blocked left or right ([$77] & 3): skip the border check, go to $00E9FB
$00:E9AD C2 20 REP #$20 ; A 16-bit
$00:E9AF A0 00 LDY.B #$00 ; Y = 0: test the right border first
$00:E9B1 AD 62 14 LDA.W $1462 ; \
$00:E9B4 18 CLC ; |
$00:E9B5 69 E8 00 ADC.W #$00E8 ; |
$00:E9B8 C5 94 CMP RAM_MarioXPos ; / Compare right border ([$1462] + $E8) with Mario X (16-bit)
$00:E9BA F0 0C BEQ $E9C8 ; Equal: not past the border, go to $00E9C8
$00:E9BC 30 0A BMI $E9C8 ; Border < Mario X: past the right border, go to $00E9C8
$00:E9BE C8 INY ; Y = 1: test the left border
$00:E9BF A5 94 LDA RAM_MarioXPos ; \
$00:E9C1 38 SEC ; |
$00:E9C2 E9 08 00 SBC.W #$0008 ; |
$00:E9C5 CD 62 14 CMP.W $1462 ; / Compare Mario X - 8 with [$1462] (left border)
$00:E9C8 E2 20 SEP #$20 ; A 8-bit (compare flags are kept)
$00:E9CA F0 2F BEQ $E9FB ; \
$00:E9CC 10 2D BPL $E9FB ; / Not past the border (zero or positive): go to $00E9FB (BEQ is redundant)
$00:E9CE AD 11 14 LDA.W $1411 ; \
$00:E9D1 D0 23 BNE $E9F6 ; / [$1411] (horizontal scroll enabled) non-zero: go to $00E9F6
$00:E9D3 A9 80 LDA.B #$80 ; \
$00:E9D5 04 77 TSB RAM_MarioObjStatus ; / [$77] |= $80: Mario is touching the edge of the screen
$00:E9D7 C2 20 REP #$20 ; A 16-bit
$00:E9D9 AD 46 14 LDA.W $1446 ; \
$00:E9DC 4A LSR ; |
$00:E9DD 4A LSR ; |
$00:E9DE 4A LSR ; |
$00:E9DF 4A LSR ; / A = [$1446] >> 4 (layer 1 scroll speed, in pixels)
$00:E9E0 E2 20 SEP #$20 ; A 8-bit
$00:E9E2 85 00 STA $00 ; [$00] = scroll speed
$00:E9E4 38 SEC ; \
$00:E9E5 E5 7B SBC RAM_MarioSpeedX ; |
$00:E9E7 59 0E E9 EOR.W $E90E,Y ; |
$00:E9EA 30 0A BMI $E9F6 ; / ([$00] - Mario X speed) EOR [DATA_00E90E+Y] negative: skip, go to $00E9F6
$00:E9EC A5 00 LDA $00 ; \
$00:E9EE 85 7B STA RAM_MarioSpeedX ; / Mario X speed = scroll speed (carried along with the screen)
$00:E9F0 AD 4E 14 LDA.W $144E ; \
$00:E9F3 8D DA 13 STA.W $13DA ; / [$13DA] = [$144E] (probably the fractional part of the carried speed)
$00:E9F6 B9 0A E9 LDA.W $E90A,Y ; \
$00:E9F9 04 77 TSB RAM_MarioObjStatus ; / [$77] |= [DATA_00E90A+Y]: blocked on the right ($01) or left ($02)
$00:E9FB A5 77 LDA RAM_MarioObjStatus ; \
$00:E9FD 29 1C AND.B #$1C ; |
$00:E9FF C9 1C CMP.B #$1C ; |
$00:EA01 D0 0A BNE $EA0D ; / [$77] & $1C <> $1C (not floor, ceiling and inside a block): go to $00EA0D
$00:EA03 AD 71 14 LDA.W $1471 ; \
$00:EA06 D0 05 BNE $EA0D ; / [$1471] non-zero (on a sprite platform): not crushed, go to $00EA0D
$00:EA08 20 29 F6 JSR.W $F629 ; Kill Mario: crushed or past the screen edge ($F629)
$00:EA0B 80 25 BRA $EA32 ; Then clear his X speed ($00EA32)
$00:EA0D A5 77 LDA RAM_MarioObjStatus ; \
$00:EA0F 29 03 AND.B #$03 ; |
$00:EA11 F0 21 BEQ $EA34 ; / [$77] & 3 = 0 (not blocked sideways): go to $00EA34
$00:EA13 29 02 AND.B #$02 ; \
$00:EA15 A8 TAY ; / Y = 0 if blocked on the right, 2 if blocked on the left
$00:EA16 C2 20 REP #$20 ; A 16-bit
$00:EA18 A5 94 LDA RAM_MarioXPos ; \
$00:EA1A 18 CLC ; |
$00:EA1B 79 0D E9 ADC.W $E90D,Y ; |
$00:EA1E 85 94 STA RAM_MarioXPos ; / Mario X += [DATA_00E90D+Y]: push out of the wall by 1 pixel (-1 or +1)
$00:EA20 E2 20 SEP #$20 ; A 8-bit
$00:EA22 A5 77 LDA RAM_MarioObjStatus ; \
$00:EA24 30 0E BMI $EA34 ; / [$77] bit 7 (touching the screen edge) set: go to $00EA34
$00:EA26 A9 03 LDA.B #$03 ; \
$00:EA28 8D E5 13 STA.W $13E5 ; / [$13E5] = 3 (probably the wall-push animation timer)
$00:EA2B A5 7B LDA RAM_MarioSpeedX ; \
$00:EA2D 59 0D E9 EOR.W $E90D,Y ; |
$00:EA30 10 02 BPL $EA34 ; / X speed EOR [DATA_00E90D+Y] positive (moving away from the wall): go to $00EA34
$00:EA32 64 7B STZ RAM_MarioSpeedX ; Mario X speed = 0
$00:EA34 AD F9 13 LDA.W RAM_IsBehindScenery ; \
$00:EA37 C9 01 CMP.B #$01 ; |
$00:EA39 D0 07 BNE $EA42 ; |
$00:EA3B A5 8B LDA $8B ; |
$00:EA3D D0 03 BNE $EA42 ; |
$00:EA3F 9C F9 13 STZ.W RAM_IsBehindScenery ; / If [RAM_IsBehindScenery] = 1 and [$8B] = 0 (probably no longer on a scenery tile), clear it
$00:EA42 9C FA 13 STZ.W $13FA ; [$13FA] = 0 (probably the at-water-surface flag, set again below)
$00:EA45 A5 85 LDA RAM_IsWaterLevel ; \
$00:EA47 D0 15 BNE $EA5E ; / Water level: Mario is always swimming, go to $00EA5E
$00:EA49 46 8A LSR $8A ; \
$00:EA4B 90 56 BCC $EAA3 ; / [$8A] bit 0 (touching a water tile) clear: leave the water, go to $00EAA3
$00:EA4D A5 75 LDA RAM_IsSwimming ; \
$00:EA4F D0 14 BNE $EA65 ; / Already swimming: go to $00EA65
$00:EA51 A5 7D LDA RAM_MarioSpeedY ; \
$00:EA53 30 10 BMI $EA65 ; / Moving up (Y speed negative): go to $00EA65
$00:EA55 46 8A LSR $8A ; \
$00:EA57 90 4C BCC $EAA5 ; / [$8A] bit 1 (probably fully submerged tile) clear: not in the water yet, return
$00:EA59 20 A5 FD JSR.W $FDA5 ; Spawn a water splash (probably, $FDA5)
$00:EA5C 64 7D STZ RAM_MarioSpeedY ; Mario Y speed = 0 on entering the water
$00:EA5E A9 01 LDA.B #$01 ; \
$00:EA60 85 75 STA RAM_IsSwimming ; / [RAM_IsSwimming] = 1
$00:EA62 4C 08 FD JMP.W $FD08 ; Maybe spawn an air bubble ($FD08), then return
$00:EA65 46 8A LSR $8A ; \
$00:EA67 B0 F5 BCS $EA5E ; / [$8A] bit 1 set (still submerged): go to $00EA5E
$00:EA69 A5 75 LDA RAM_IsSwimming ; \
$00:EA6B F0 38 BEQ $EAA5 ; / Not swimming: return
$00:EA6D A9 FC LDA.B #$FC ; \
$00:EA6F C5 7D CMP RAM_MarioSpeedY ; |
$00:EA71 30 02 BMI $EA75 ; |
$00:EA73 85 7D STA RAM_MarioSpeedY ; / Mario Y speed = max([Y speed], -4): limit upward speed at the surface
$00:EA75 EE FA 13 INC.W $13FA ; [$13FA]++ (probably the at-water-surface flag)
$00:EA78 A5 15 LDA RAM_ControllerA ; \
$00:EA7A 29 88 AND.B #$88 ; |
$00:EA7C C9 88 CMP.B #$88 ; |
$00:EA7E D0 E2 BNE $EA62 ; / [$15] & $88 = $88 (B and Up held)? If not, go to $00EA62
$00:EA80 A5 17 LDA RAM_ControllerB ; \
$00:EA82 10 0E BPL $EA92 ; / [$17] bit 7 (A button) clear: go to $00EA92
$00:EA84 AD 8F 14 LDA.W $148F ; \
$00:EA87 D0 09 BNE $EA92 ; / [$148F] non-zero (carrying something): go to $00EA92
$00:EA89 1A INC A ; \
$00:EA8A 8D 0D 14 STA.W RAM_IsSpinJump ; / [RAM_IsSpinJump] = 1: spin jump out of the water
$00:EA8D A9 04 LDA.B #$04 ; \
$00:EA8F 8D FC 1D STA.W $1DFC ; / Play sound effect $04 (spin jump) via [$1DFC]
$00:EA92 A5 77 LDA RAM_MarioObjStatus ; \
$00:EA94 29 08 AND.B #$08 ; |
$00:EA96 D0 CA BNE $EA62 ; / [$77] bit 3 (head blocked) set: cannot leave, go to $00EA62
$00:EA98 20 A5 FD JSR.W $FDA5 ; Spawn a water splash (probably, $FDA5)
$00:EA9B A9 0B LDA.B #$0B ; \
$00:EA9D 85 72 STA RAM_IsFlying ; / [RAM_IsFlying] = $0B (in the air)
$00:EA9F A9 AA LDA.B #$AA ; \
$00:EAA1 85 7D STA RAM_MarioSpeedY ; / Mario Y speed = $AA (-86): jump out of the water
$00:EAA3 64 75 STZ RAM_IsSwimming ; [RAM_IsSwimming] = 0
$00:EAA5 60 RTS ; Return
$00:EAA6 9C E5 13 STZ.W $13E5 ; [$13E5] = 0 (wall-push animation timer)
$00:EAA9 64 77 STZ RAM_MarioObjStatus ; Blocked status [$77] = 0
$00:EAAB 9C E1 13 STZ.W $13E1 ; [$13E1] = 0
$00:EAAE 9C EE 13 STZ.W $13EE ; [$13EE] = 0
$00:EAB1 64 8A STZ $8A ; [$8A] = 0 (water contact bits)
$00:EAB3 64 8B STZ $8B ; [$8B] = 0
$00:EAB5 9C 0E 14 STZ.W $140E ; [$140E] = 0
$00:EAB8 60 RTS ; Return
;;; $EAB9..EAD9: Data: wall-walk tables and slope tile list ;;;
;; Small tables used by $EADB: $EAB9/00EABB/00EABD (indexed by wall-walk side, purpose unclear)
;; and $EAC1,
;; a 26-byte list of tile numbers (probably slope tiles).
$00:EAB9 .db $DE,$23 ; Table: $DE, $23 (speed values indexed by wall-walk side, purpose unclear)
$00:EABB .db $20,$E0 ; Table: $20, $E0 (+32 / -32, purpose unclear)
$00:EABD .db $08,$00,$F8,$FF ; Words: +8, -8 (purpose unclear)
$00:EAC1 .db $71,$72,$76,$77,$7B,$7C,$81,$86 ; Tile numbers $71-$B3 (probably slope tiles), 26 bytes
$00:EAC9 .db $8A,$8B,$8F,$90,$94,$95,$99,$9A ; Tile numbers, continued
$00:EAD1 .db $9E,$9F,$A3,$A4,$A8,$A9,$AD,$AE ; Tile numbers, continued
$00:EAD9 .db $B2,$B3 ; Tile numbers, end (next routine at $00EADB)
;;; $EADB: Mario block and slope collision (rest) ;;;
;; Second half of Mario's tile collision. Sets up the collision points for Mario's size, then checks body,
;; side, head and feet points
;; against the Map16 tile. Page 0 tiles run effects (doors, coins), tiles $11-$6D are solid blocks, $6E-$D7
;; are slopes whose shape
;; comes from the table at [$82]. Handles wall-running ([$13E3]), floor landing, switch palace blocks, ledge
;; pushing and Mario's state on landing.
;; Parameters: [RAM_MarioXPos]/[RAM_MarioYPos]; Y = tile number from $F44D. $00EAE9: wall-run handling,
;; $00EB77: normal collision.
;; Contains helper entries: $00EFBC conveyor tiles, $00EFE8 wall-run point check, $00F005 wall-run start,
;; $00F04D slope tile test (RTL).
;; Called by:
;; $00:E963: Mario level collision, borders and water
;; $00:E989: Mario level collision, borders and water
$00:EADB A5 96 LDA RAM_MarioYPos ; \
$00:EADD 29 0F AND.B #$0F ; } [$90] = [RAM_MarioYPos] & $0F: Mario's Y offset inside the 16x16 block
$00:EADF 85 90 STA $90 ; /
$00:EAE1 AD E3 13 LDA.W RAM_WallWalkStatus ; A = wall-run status [$13E3]
$00:EAE4 D0 03 BNE $EAE9 ; Wall-running: go to EAE9
$00:EAE6 4C 77 EB JMP.W $EB77 ; Not wall-running: normal block collision at $00EB77
$00:EAE9 29 01 AND.B #$01 ; \
$00:EAEB A8 TAY ; / Y = [$13E3] & 1: wall side (0 = left, 1 = right)
$00:EAEC A5 7B LDA RAM_MarioSpeedX ; \
$00:EAEE 38 SEC ; |
$00:EAEF F9 B9 EA SBC.W $EAB9,Y ; } N = 1 if Mario's X speed has not reached the wall-run speed limit $EAB9[Y]
$00:EAF2 59 B9 EA EOR.W $EAB9,Y ; /
$00:EAF5 30 51 BMI $EB48 ; Too slow: fall off the wall
$00:EAF7 A5 72 LDA RAM_IsFlying ; \
$00:EAF9 0D 8F 14 ORA.W $148F ; |
$00:EAFC 05 73 ORA RAM_IsDucking ; } A = [RAM_IsFlying] | [$148F] | [RAM_IsDucking] | [RAM_OnYoshi]
$00:EAFE 0D 7A 18 ORA.W RAM_OnYoshi ; /
$00:EB01 D0 45 BNE $EB48 ; Any of those set: fall off the wall
$00:EB03 AD E3 13 LDA.W RAM_WallWalkStatus ; A = wall-run status
$00:EB06 C9 06 CMP.B #$06 ; Status >= 6: already running up the wall
$00:EB08 B0 18 BCS $EB22 ; Go to EB22 (wall-run collision checks)
$00:EB0A A6 90 LDX $90 ; X = [$90] (Mario Y offset inside the block)
$00:EB0C E0 08 CPX.B #$08 ; Offset < 8: not far enough into the wall yet
$00:EB0E 90 66 BCC $EB76 ; Return
$00:EB10 C9 04 CMP.B #$04 ; Status >= 4: already started, clear status (EB73)
$00:EB12 B0 5F BCS $EB73 ; Branch to EB73
$00:EB14 09 04 ORA.B #$04 ; Set bit 2: Mario has started up the wall
$00:EB16 8D E3 13 STA.W RAM_WallWalkStatus ; Store the new wall-run status
$00:EB19 A5 94 LDA RAM_MarioXPos ; \
$00:EB1B 29 F0 AND.B #$F0 ; |
$00:EB1D 09 08 ORA.B #$08 ; } Center Mario's X in the block column: [RAM_MarioXPos] = ([RAM_MarioXPos] & $F0) | 8
$00:EB1F 85 94 STA RAM_MarioXPos ; /
$00:EB21 60 RTS ; Return
$00:EB22 A2 60 LDX.B #$60 ; X = $60: collision point set for a left wall
$00:EB24 98 TYA ; A = wall side
$00:EB25 F0 02 BEQ $EB29 ; Left wall: keep X = $60
$00:EB27 A2 66 LDX.B #$66 ; X = $66: collision point set for a right wall
$00:EB29 20 E8 EF JSR.W $EFE8 ; Check this wall-run collision point (EFE8)
$00:EB2C A5 19 LDA RAM_MarioPowerUp ; A = [RAM_MarioPowerUp]
$00:EB2E D0 04 BNE $EB34 ; Big or better: check a second point
$00:EB30 E8 INX ; \
$00:EB31 E8 INX ; / Small Mario: X += 2, skip the extra point
$00:EB32 80 03 BRA $EB37 ; Skip to EB37
$00:EB34 20 E8 EF JSR.W $EFE8 ; Check the extra collision point (EFE8)
$00:EB37 20 4D F4 JSR.W $F44D ; Check the next collision point ($F44D)
$00:EB3A D0 DD BNE $EB19 ; Solid: keep Mario centered in the wall column (EB19)
$00:EB3C A9 02 LDA.B #$02 ; A = %00000010
$00:EB3E 1C E3 13 TRB.W RAM_WallWalkStatus ; Clear bit 1 of the wall-run status: wall contact lost
$00:EB41 60 RTS ; Return
$00:EB42 AD E3 13 LDA.W RAM_WallWalkStatus ; A = wall-run status (entry from $EFE8 when Mario hits a solid block)
$00:EB45 29 01 AND.B #$01 ; \
$00:EB47 A8 TAY ; / Y = wall side (0 = left, 1 = right)
$00:EB48 B9 BB EA LDA.W $EABB,Y ; A = $EABB[Y]: X speed pushing Mario away from the wall ($20 / $E0)
$00:EB4B 85 7B STA RAM_MarioSpeedX ; Mario X speed = A
$00:EB4D 98 TYA ; \
$00:EB4E 0A ASL ; } Y = Y * 2: word index
$00:EB4F A8 TAY ; /
$00:EB50 C2 20 REP #$20 ; A 16-bit
$00:EB52 A5 94 LDA RAM_MarioXPos ; A = Mario X position
$00:EB54 18 CLC ; Clear carry
$00:EB55 79 BD EA ADC.W $EABD,Y ; Add $EABD[Y] (+8 or -8): step away from the wall
$00:EB58 85 94 STA RAM_MarioXPos ; Store Mario X position
$00:EB5A A9 08 00 LDA.W #$0008 ; A = 8 (small Mario)
$00:EB5D A4 19 LDY RAM_MarioPowerUp ; Y = power-up
$00:EB5F F0 03 BEQ $EB64 ; Small: keep 8
$00:EB61 A9 10 00 LDA.W #$0010 ; A = $10 (big Mario)
$00:EB64 18 CLC ; Clear carry
$00:EB65 65 96 ADC RAM_MarioYPos ; Add Mario Y position
$00:EB67 85 96 STA RAM_MarioYPos ; Mario Y position += 8 (small) or $10 (big)
$00:EB69 E2 20 SEP #$20 ; A 8-bit
$00:EB6B A9 24 LDA.B #$24 ; \
$00:EB6D 85 72 STA RAM_IsFlying ; / In-air flag [RAM_IsFlying] = $24 (falling)
$00:EB6F A9 E0 LDA.B #$E0 ; \
$00:EB71 85 7D STA RAM_MarioSpeedY ; / Mario Y speed = $E0 (small hop off the wall)
$00:EB73 9C E3 13 STZ.W RAM_WallWalkStatus ; Clear the wall-run status [$13E3]
$00:EB76 60 RTS ; Return
$00:EB77 A2 00 LDX.B #$00 ; X = 0: collision point set for small Mario
$00:EB79 A5 19 LDA RAM_MarioPowerUp ; A = power-up
$00:EB7B F0 06 BEQ $EB83 ; Small: keep X = 0
$00:EB7D A5 73 LDA RAM_IsDucking ; A = ducking flag
$00:EB7F D0 02 BNE $EB83 ; Ducking: keep X = 0
$00:EB81 A2 18 LDX.B #$18 ; X = $18: collision point set for big Mario
$00:EB83 AD 7A 18 LDA.W RAM_OnYoshi ; A = on Yoshi flag
$00:EB86 F0 05 BEQ $EB8D ; Not on Yoshi: skip
$00:EB88 8A TXA ; \
$00:EB89 18 CLC ; |
$00:EB8A 69 30 ADC.B #$30 ; } On Yoshi: X += $30 (taller collision point set)
$00:EB8C AA TAX ; /
$00:EB8D A5 94 LDA RAM_MarioXPos ; A = Mario X position
$00:EB8F 29 0F AND.B #$0F ; A = X offset inside the block
$00:EB91 A8 TAY ; Y = X offset inside the block
$00:EB92 18 CLC ; Clear carry
$00:EB93 69 08 ADC.B #$08 ; Add 8
$00:EB95 29 0F AND.B #$0F ; Modulo 16
$00:EB97 85 92 STA $92 ; [$92] = (X offset + 8) & $0F: column used for slope height lookups
$00:EB99 64 93 STZ $93 ; [$93] = 0: Mario is in the left half of the block
$00:EB9B C0 08 CPY.B #$08 ; Compare X offset with 8
$00:EB9D 90 06 BCC $EBA5 ; Left half: skip
$00:EB9F 8A TXA ; \
$00:EBA0 69 0B ADC.B #$0B ; } Right half: X += $0C (carry set), use the right-side collision points
$00:EBA2 AA TAX ; /
$00:EBA3 E6 93 INC $93 ; [$93] = 1: Mario is in the right half of the block
$00:EBA5 A5 90 LDA $90 ; A = [$90] (Mario Y offset inside the block)
$00:EBA7 18 CLC ; Clear carry
$00:EBA8 7D A4 E8 ADC.W $E8A4,X ; Add $E8A4[X]: Y offset of this collision point
$00:EBAB 29 0F AND.B #$0F ; Modulo 16
$00:EBAD 85 91 STA $91 ; [$91] = Y offset of the collision point inside its block
$00:EBAF 20 4D F4 JSR.W $F44D ; Check the first collision point (body); Y = tile number, Z = 1 for a page 0 tile
$00:EBB2 F0 29 BEQ $EBDD ; Page 0 tile (doors, coins, water...): go to EBDD
$00:EBB4 C0 11 CPY.B #$11 ; Tile < $11: not solid
$00:EBB6 90 6C BCC $EC24 ; Skip to the next check (EC24)
$00:EBB8 C0 6E CPY.B #$6E ; Tile $11-$6D: solid block
$00:EBBA 90 0D BCC $EBC9 ; Go to EBC9
$00:EBBC 98 TYA ; A = tile number (slope tile $6E or above)
$00:EBBD 22 4D F0 00 JSL.L $F04D ; Carry = 1 if the tile is in the slope list $EAC1
$00:EBC1 90 61 BCC $EC24 ; Not in the list: skip
$00:EBC3 A9 01 LDA.B #$01 ; A = 1
$00:EBC5 04 8A TSB $8A ; Set bit 0 of [$8A] (tile contact flags, probably 'touching a wall-run slope')
$00:EBC7 80 5B BRA $EC24 ; Continue at EC24
$00:EBC9 E8 INX ; \
$00:EBCA E8 INX ; |
$00:EBCB E8 INX ; } X += 4: advance to the side collision point
$00:EBCC E8 INX ; /
$00:EBCD 98 TYA ; A = tile number
$00:EBCE A0 00 LDY.B #$00 ; Y = 0
$00:EBD0 C9 1E CMP.B #$1E ; Turn block?
$00:EBD2 F0 06 BEQ $EBDA ; Yes: Y = 0
$00:EBD4 C9 52 CMP.B #$52 ; Tile $52?
$00:EBD6 F0 02 BEQ $EBDA ; Yes: Y = 0
$00:EBD8 A0 02 LDY.B #$02 ; Other solid tile: Y = 2
$00:EBDA 4C 6F EC JMP.W $EC6F ; Handle the block hit from the side (EC6F)
$00:EBDD C0 9C CPY.B #$9C ; Page 0 tile $9C?
$00:EBDF D0 07 BNE $EBE8 ; No: go to EBE8
$00:EBE1 AD 31 19 LDA.W $1931 ; A = tileset [$1931]
$00:EBE4 C9 01 CMP.B #$01 ; Tileset 1?
$00:EBE6 F0 1E BEQ $EC06 ; Yes: treat it as a door (EC06)
$00:EBE8 C0 20 CPY.B #$20 ; Tile $20 (door)?
$00:EBEA F0 15 BEQ $EC01 ; Yes: go to EC01
$00:EBEC C0 1F CPY.B #$1F ; Tile $1F (door)?
$00:EBEE F0 0D BEQ $EBFD ; Yes: go to EBFD
$00:EBF0 AD AD 14 LDA.W RAM_BluePowTimer ; A = blue P-switch timer
$00:EBF3 F0 2C BEQ $EC21 ; Timer = 0: other page 0 tile effects (EC21)
$00:EBF5 C0 28 CPY.B #$28 ; Tile $28?
$00:EBF7 F0 08 BEQ $EC01 ; Yes: door check
$00:EBF9 C0 27 CPY.B #$27 ; Tile $27?
$00:EBFB D0 24 BNE $EC21 ; No: other page 0 tile effects (EC21)
$00:EBFD A5 19 LDA RAM_MarioPowerUp ; \
$00:EBFF D0 23 BNE $EC24 ; / Big Mario skips this tile (probably the door's upper half is checked by another point)
$00:EC01 20 43 F4 JSR.W $F443 ; \
$00:EC04 B0 1E BCS $EC24 ; / Carry = 1 if Mario's X is on the right half of the block: then no door entry
$00:EC06 A5 8F LDA $8F ; \
$00:EC08 D0 1A BNE $EC24 ; / In the air ([$8F] = backed up [RAM_IsFlying]): cannot enter
$00:EC0A A5 16 LDA $16 ; \
$00:EC0C 29 08 AND.B #$08 ; } Up not newly pressed in [$16]: do not enter
$00:EC0E F0 14 BEQ $EC24 ; /
$00:EC10 A9 0F LDA.B #$0F ; \
$00:EC12 8D FC 1D STA.W $1DFC ; / Sound effect $0F (door)
$00:EC15 20 73 D2 JSR.W $D273 ; Set up the level load for the door destination ($D273)
$00:EC18 A9 0D LDA.B #$0D ; \
$00:EC1A 85 71 STA RAM_MarioAnimation ; / Mario animation = $0D (entering door)
$00:EC1C 20 2D F6 JSR.W NoButtons ; Clear controller inputs
$00:EC1F 80 03 BRA $EC24 ; Continue at EC24
$00:EC21 20 8C F2 JSR.W $F28C ; Apply the page 0 tile effect ($F28C: invisible 1-up checkpoint tiles $6F-$72)
$00:EC24 20 4D F4 JSR.W $F44D ; Check the next collision point (side)
$00:EC27 F0 0C BEQ $EC35 ; Page 0 tile: go to EC35
$00:EC29 C0 11 CPY.B #$11 ; Tile < $11: ignore
$00:EC2B 90 0D BCC $EC3A ; Branch to EC3A
$00:EC2D C0 6E CPY.B #$6E ; Tile >= $6E (slope)?
$00:EC2F B0 09 BCS $EC3A ; Yes: ignore at this point
$00:EC31 E8 INX ; \
$00:EC32 E8 INX ; / Solid block $11-$6D: X += 2 (skip the head point)
$00:EC33 80 19 BRA $EC4E ; Handle the side collision (EC4E)
$00:EC35 A9 10 LDA.B #$10 ; A = $10
$00:EC37 20 C9 F2 JSR.W $F2C9 ; Apply the page 0 tile effect ($F2C9)
$00:EC3A 20 4D F4 JSR.W $F44D ; Check the next collision point (upper side / head)
$00:EC3D D0 07 BNE $EC46 ; Non-page-0 tile: go to EC46
$00:EC3F A9 08 LDA.B #$08 ; A = 8
$00:EC41 20 C9 F2 JSR.W $F2C9 ; Apply the page 0 tile effect ($F2C9)
$00:EC44 80 44 BRA $EC8A ; Continue with the head check at EC8A
$00:EC46 C0 11 CPY.B #$11 ; Tile < $11: ignore
$00:EC48 90 40 BCC $EC8A ; Branch to EC8A
$00:EC4A C0 6E CPY.B #$6E ; Tile >= $6E: ignore
$00:EC4C B0 3C BCS $EC8A ; Branch to EC8A
$00:EC4E A5 76 LDA RAM_MarioDirection ; A = Mario facing direction [RAM_MarioDirection]
$00:EC50 C5 93 CMP $93 ; Same as the block side [$93]?
$00:EC52 F0 0B BEQ $EC5F ; Yes: skip the tile $2E handling
$00:EC54 20 C4 F3 JSR.W $F3C4 ; $F3C4
$00:EC57 DA PHX ; Save X
$00:EC58 20 67 F2 JSR.W $F267 ; Handle tile $2E (button-triggered interaction, $F267)
$00:EC5B AC 93 16 LDY.W $1693 ; Y = current Map16 tile number
$00:EC5E FA PLX ; Restore X
$00:EC5F A9 03 LDA.B #$03 ; A = 3
$00:EC61 8D E5 13 STA.W $13E5 ; [$13E5] = 3 (probably a side-contact flag)
$00:EC64 A4 93 LDY $93 ; Y = block side [$93]
$00:EC66 A5 94 LDA RAM_MarioXPos ; A = Mario X
$00:EC68 29 0F AND.B #$0F ; A = X offset inside the block
$00:EC6A D9 11 E9 CMP.W $E911,Y ; Compare with $E911[Y] ($02 or $0D): the edge of the block
$00:EC6D F0 1B BEQ $EC8A ; Already exactly at the edge: no push-out
$00:EC6F AD 02 14 LDA.W $1402 ; A = [$1402]
$00:EC72 F0 07 BEQ $EC7B ; Zero: continue at EC7B
$00:EC74 AD 93 16 LDA.W $1693 ; A = current tile
$00:EC77 C9 52 CMP.B #$52 ; Tile $52?
$00:EC79 F0 0F BEQ $EC8A ; Yes: skip the block hit
$00:EC7B B9 0A E9 LDA.W $E90A,Y ; A = $E90A[Y]: blocked left/right status bits
$00:EC7E 04 77 TSB RAM_MarioObjStatus ; Set the blocked bits in [RAM_MarioObjStatus]
$00:EC80 29 03 AND.B #$03 ; Keep bits 0-1
$00:EC82 A8 TAY ; Y = side (1 = right, 2 = left)
$00:EC83 AD 93 16 LDA.W $1693 ; A = current Map16 tile number
$00:EC86 22 27 F1 00 JSL.L $F127 ; Trigger the block hit from the side ($F127)
$00:EC8A 20 4D F4 JSR.W $F44D ; Check the next collision point (head, for blocks hit from below)
$00:EC8D D0 22 BNE $ECB1 ; Non-page-0 tile: go to ECB1
$00:EC8F A9 02 LDA.B #$02 ; A = 2
$00:EC91 20 C2 F2 JSR.W $F2C2 ; Apply the page 0 tile effect ($F2C2)
$00:EC94 A4 7D LDY RAM_MarioSpeedY ; Y = Mario Y speed
$00:EC96 10 0B BPL $ECA3 ; Moving down: skip to ECA3
$00:EC98 AD 93 16 LDA.W $1693 ; A = current tile
$00:EC9B C9 21 CMP.B #$21 ; Tile < $21?
$00:EC9D 90 04 BCC $ECA3 ; Yes: skip to ECA3
$00:EC9F C9 25 CMP.B #$25 ; Tile < $25 ($21-$24)?
$00:ECA1 90 03 BCC $ECA6 ; Yes: go to ECA6
$00:ECA3 4C 4A ED JMP.W $ED4A ; Continue at the floor check (ED4A)
$00:ECA6 38 SEC ; Set carry
$00:ECA7 E9 04 SBC.B #$04 ; A = tile - 4
$00:ECA9 A0 00 LDY.B #$00 ; Y = 0
$00:ECAB 22 7F F1 00 JSL.L $F17F ; Block hit from below for this tile ($F17F)
$00:ECAF 80 5C BRA $ED0D ; Go to ED0D
$00:ECB1 C0 11 CPY.B #$11 ; Tile < $11?
$00:ECB3 90 EE BCC $ECA3 ; Yes: skip to ECA3
$00:ECB5 C0 6E CPY.B #$6E ; Tile < $6E (solid block)?
$00:ECB7 90 41 BCC $ECFA ; Yes: go to ECFA
$00:ECB9 C0 D8 CPY.B #$D8 ; Tile < $D8 (slope)?
$00:ECBB 90 1D BCC $ECDA ; Yes: go to ECDA
$00:ECBD C2 20 REP #$20 ; \
$00:ECBF A5 98 LDA RAM_BlockYLo ; |
$00:ECC1 18 CLC ; |
$00:ECC2 69 10 00 ADC.W #$0010 ; } Tile $D8-$FA (slope filler): look one block lower, [RAM_BlockYLo] += $10
$00:ECC5 85 98 STA RAM_BlockYLo ; /
$00:ECC7 20 61 F4 JSR.W $F461 ; Recompute the tile at the new point ($F461)
$00:ECCA F0 2C BEQ $ECF8 ; Page 0 tile: ignore (ED4A)
$00:ECCC C0 6E CPY.B #$6E ; Tile < $6E?
$00:ECCE 90 7A BCC $ED4A ; Yes: go to ED4A
$00:ECD0 C0 D8 CPY.B #$D8 ; Tile >= $D8?
$00:ECD2 B0 76 BCS $ED4A ; Yes: go to ED4A
$00:ECD4 A5 91 LDA $91 ; \
$00:ECD6 E9 0F SBC.B #$0F ; } [$91] -= $0F + (1 - carry): adjust for the lower block
$00:ECD8 85 91 STA $91 ; /
$00:ECDA 98 TYA ; \
$00:ECDB 38 SEC ; |
$00:ECDC E9 6E SBC.B #$6E ; } Y = tile - $6E: index into the slope shape table at [$82]
$00:ECDE A8 TAY ; /
$00:ECDF C2 20 REP #$20 ; A 16-bit
$00:ECE1 B7 82 LDA [$82],Y ; \
$00:ECE3 29 FF 00 AND.W #$00FF ; |
$00:ECE6 0A ASL ; |
$00:ECE7 0A ASL ; |
$00:ECE8 0A ASL ; } A = slope shape * 16
$00:ECE9 0A ASL ; /
$00:ECEA E2 20 SEP #$20 ; A 8-bit
$00:ECEC 05 92 ORA $92 ; Add the X column [$92]
$00:ECEE C2 10 REP #$10 ; Index 16-bit
$00:ECF0 A8 TAY ; Y = shape * 16 + column
$00:ECF1 B9 32 E6 LDA.W $E632,Y ; A = $E632[Y]: slope surface height at this column
$00:ECF4 E2 10 SEP #$10 ; Index 8-bit
$00:ECF6 30 17 BMI $ED0F ; Negative: go to ED0F
$00:ECF8 80 50 BRA $ED4A ; Go to ED4A
$00:ECFA A9 02 LDA.B #$02 ; A = 2
$00:ECFC 20 E9 F3 JSR.W $F3E9 ; $F3E9 (A = 2: head hits solid block)
$00:ECFF 98 TYA ; A = tile
$00:ED00 A0 00 LDY.B #$00 ; Y = 0
$00:ED02 22 27 F1 00 JSL.L $F127 ; Trigger the block hit from below ($F127)
$00:ED06 AD 93 16 LDA.W $1693 ; A = current tile
$00:ED09 C9 1E CMP.B #$1E ; Turn block?
$00:ED0B F0 2E BEQ $ED3B ; Yes: go to ED3B
$00:ED0D A9 F0 LDA.B #$F0 ; A = $F0
$00:ED0F 18 CLC ; Clear carry
$00:ED10 65 91 ADC $91 ; Add [$91] (head penetration)
$00:ED12 10 36 BPL $ED4A ; Positive: go to ED4A
$00:ED14 C9 F9 CMP.B #$F9 ; Penetration < 7 pixels?
$00:ED16 B0 10 BCS $ED28 ; No: go to ED28
$00:ED18 A4 72 LDY RAM_IsFlying ; Y = in-air flag
$00:ED1A D0 0C BNE $ED28 ; In the air: go to ED28
$00:ED1C A5 77 LDA RAM_MarioObjStatus ; \
$00:ED1E 29 FC AND.B #$FC ; |
$00:ED20 09 09 ORA.B #$09 ; } Blocked status: bit 3 and bit 0 set, bits 1-2 cleared (blocked above, pushed against wall)
$00:ED22 85 77 STA RAM_MarioObjStatus ; /
$00:ED24 64 7B STZ RAM_MarioSpeedX ; Mario X speed = 0
$00:ED26 80 13 BRA $ED3B ; Go to ED3B
$00:ED28 A4 72 LDY RAM_IsFlying ; Y = in-air flag
$00:ED2A F0 0B BEQ $ED37 ; On the ground: go to ED37
$00:ED2C 49 FF EOR.B #$FF ; \
$00:ED2E 18 CLC ; |
$00:ED2F 65 96 ADC RAM_MarioYPos ; } Mario Y position += -A - 1 (push Mario down out of the ceiling)
$00:ED31 85 96 STA RAM_MarioYPos ; /
$00:ED33 90 02 BCC $ED37 ; No carry: skip
$00:ED35 E6 97 INC RAM_MarioYPosHi ; Y position high byte++
$00:ED37 A9 08 LDA.B #$08 ; A = 8
$00:ED39 04 77 TSB RAM_MarioObjStatus ; Set bit 3 (blocked above) in [RAM_MarioObjStatus]
$00:ED3B A5 7D LDA RAM_MarioSpeedY ; A = Mario Y speed
$00:ED3D 10 0B BPL $ED4A ; Moving down: go to ED4A
$00:ED3F 64 7D STZ RAM_MarioSpeedY ; Y speed = 0 (bonk the ceiling)
$00:ED41 AD F9 1D LDA.W $1DF9 ; A = sound effect mirror [$1DF9]
$00:ED44 D0 04 BNE $ED4A ; Sound already queued: skip
$00:ED46 1A INC A ; A = 1
$00:ED47 8D F9 1D STA.W $1DF9 ; Play sound effect 1 (hit head)
$00:ED4A 20 4D F4 JSR.W $F44D ; Check the next collision point (feet, floor)
$00:ED4D D0 03 BNE $ED52 ; Non-page-0 tile: go to ED52
$00:ED4F 4C DB ED JMP.W $EDDB ; Page 0 tile: go to EDDB
$00:ED52 C0 6E CPY.B #$6E ; Tile < $6E (solid block)?
$00:ED54 B0 08 BCS $ED5E ; No: go to ED5E
$00:ED56 A9 03 LDA.B #$03 ; A = 3
$00:ED58 20 E9 F3 JSR.W $F3E9 ; $F3E9 (A = 3: stand on solid block)
$00:ED5B 4C F7 ED JMP.W $EDF7 ; Go to EDF7
$00:ED5E C0 D8 CPY.B #$D8 ; Tile < $D8 (slope)?
$00:ED60 90 24 BCC $ED86 ; Yes: go to ED86
$00:ED62 C0 FB CPY.B #$FB ; Tile < $FB?
$00:ED64 90 03 BCC $ED69 ; Yes: go to ED69
$00:ED66 4C 29 F6 JMP.W $F629 ; Tile $FB-$FF: kill Mario ($F629)
$00:ED69 C2 20 REP #$20 ; \
$00:ED6B A5 98 LDA RAM_BlockYLo ; |
$00:ED6D 38 SEC ; |
$00:ED6E E9 10 00 SBC.W #$0010 ; } Tile $D8-$FA (slope filler): look one block higher, [RAM_BlockYLo] -= $10
$00:ED71 85 98 STA RAM_BlockYLo ; /
$00:ED73 20 61 F4 JSR.W $F461 ; Recompute the tile at the new point ($F461)
$00:ED76 F0 71 BEQ $EDE9 ; Page 0 tile: go to EDE9
$00:ED78 C0 6E CPY.B #$6E ; Tile < $6E?
$00:ED7A 90 6D BCC $EDE9 ; Yes: go to EDE9
$00:ED7C C0 D8 CPY.B #$D8 ; Tile >= $D8?
$00:ED7E B0 69 BCS $EDE9 ; Yes: go to EDE9
$00:ED80 A5 90 LDA $90 ; \
$00:ED82 69 10 ADC.B #$10 ; } [$90] += $10 (Mario is one block lower relative to the slope)
$00:ED84 85 90 STA $90 ; /
$00:ED86 AD 31 19 LDA.W $1931 ; A = tileset [$1931]
$00:ED89 C9 03 CMP.B #$03 ; Tileset 3?
$00:ED8B F0 04 BEQ $ED91 ; Yes: go to ED91
$00:ED8D C9 0E CMP.B #$0E ; Tileset $0E?
$00:ED8F D0 04 BNE $ED95 ; No: go to ED95
$00:ED91 C0 D2 CPY.B #$D2 ; Tile >= $D2?
$00:ED93 B0 54 BCS $EDE9 ; Yes: no floor here (EDE9)
$00:ED95 98 TYA ; \
$00:ED96 38 SEC ; |
$00:ED97 E9 6E SBC.B #$6E ; } Y = tile - $6E
$00:ED99 A8 TAY ; /
$00:ED9A B7 82 LDA [$82],Y ; A = slope shape from the table at [$82]
$00:ED9C 48 PHA ; Save the shape
$00:ED9D C2 20 REP #$20 ; A 16-bit
$00:ED9F 29 FF 00 AND.W #$00FF ; \
$00:EDA2 0A ASL ; |
$00:EDA3 0A ASL ; |
$00:EDA4 0A ASL ; } A = shape * 16
$00:EDA5 0A ASL ; /
$00:EDA6 E2 20 SEP #$20 ; A 8-bit
$00:EDA8 05 92 ORA $92 ; Add the X column [$92]
$00:EDAA DA PHX ; Save X
$00:EDAB C2 10 REP #$10 ; Index 16-bit
$00:EDAD AA TAX ; X = shape * 16 + column
$00:EDAE A5 90 LDA $90 ; A = [$90] (Mario Y offset inside the block)
$00:EDB0 38 SEC ; Set carry
$00:EDB1 FD 32 E6 SBC.W $E632,X ; Subtract the slope surface height $E632[X]
$00:EDB4 10 03 BPL $EDB9 ; Still positive: go to EDB9
$00:EDB6 EE EF 13 INC.W $13EF ; [$13EF]++ (Mario is below the surface)
$00:EDB9 E2 10 SEP #$10 ; Index 8-bit
$00:EDBB FA PLX ; Restore X
$00:EDBC 7A PLY ; Y = slope shape (pulled from the stack)
$00:EDBD D9 1C E5 CMP.W $E51C,Y ; Compare with $E51C[Y]: maximum step height for this shape
$00:EDC0 B0 27 BCS $EDE9 ; Too deep: no landing (EDE9)
$00:EDC2 85 91 STA $91 ; [$91] = distance to push Mario up
$00:EDC4 64 90 STZ $90 ; [$90] = 0
$00:EDC6 20 05 F0 JSR.W $F005 ; Check for starting a wall-run ($F005)
$00:EDC9 C0 1C CPY.B #$1C ; Shape < $1C (real slope)?
$00:EDCB 90 08 BCC $EDD5 ; Yes: go to EDD5
$00:EDCD A9 08 LDA.B #$08 ; A = 8
$00:EDCF 8D A1 14 STA.W $14A1 ; [$14A1] = 8 (probably a landing/slide timer)
$00:EDD2 4C D1 EE JMP.W $EED1 ; Push Mario up and land (EED1)
$00:EDD5 20 BC EF JSR.W $EFBC ; Conveyor tiles $CE-$D1 ($EFBC)
$00:EDD8 4C 85 EE JMP.W $EE85 ; Continue at the landing code (EE85)
$00:EDDB C0 05 CPY.B #$05 ; Page 0 tile $05?
$00:EDDD D0 05 BNE $EDE4 ; No: go to EDE4
$00:EDDF 20 29 F6 JSR.W $F629 ; Kill Mario ($F629)
$00:EDE2 80 05 BRA $EDE9 ; Continue at EDE9
$00:EDE4 A9 04 LDA.B #$04 ; A = 4
$00:EDE6 20 C2 F2 JSR.W $F2C2 ; Apply the page 0 tile effect ($F2C2)
$00:EDE9 20 4D F4 JSR.W $F44D ; Check the next collision point (top corner)
$00:EDEC D0 05 BNE $EDF3 ; Non-page-0 tile: go to EDF3
$00:EDEE 20 09 F3 JSR.W $F309 ; Apply the page 0 tile effect ($F309: coins, etc.)
$00:EDF1 80 2A BRA $EE1D ; Go to EE1D
$00:EDF3 C0 6E CPY.B #$6E ; Tile >= $6E: go to EE1D
$00:EDF5 B0 26 BCS $EE1D ; Branch to EE1D
$00:EDF7 A5 7D LDA RAM_MarioSpeedY ; A = Mario Y speed
$00:EDF9 30 3E BMI $EE39 ; Moving up: return
$00:EDFB AD 31 19 LDA.W $1931 ; A = tileset
$00:EDFE C9 03 CMP.B #$03 ; Tileset 3?
$00:EE00 F0 04 BEQ $EE06 ; Yes: check spikes
$00:EE02 C9 0E CMP.B #$0E ; Tileset $0E?
$00:EE04 D0 0B BNE $EE11 ; No: go to EE11
$00:EE06 AC 93 16 LDY.W $1693 ; Y = current tile
$00:EE09 C0 59 CPY.B #$59 ; Tile < $59?
$00:EE0B 90 04 BCC $EE11 ; Yes: go to EE11
$00:EE0D C0 5C CPY.B #$5C ; Tile < $5C ($59-$5B, spikes)?
$00:EE0F 90 0C BCC $EE1D ; Yes: not a floor, go to EE1D
$00:EE11 A5 90 LDA $90 ; A = [$90]
$00:EE13 29 0F AND.B #$0F ; A = Y offset inside the block
$00:EE15 64 90 STZ $90 ; [$90] = 0
$00:EE17 C9 08 CMP.B #$08 ; Offset < 8?
$00:EE19 85 91 STA $91 ; [$91] = Y offset (penetration into the floor)
$00:EE1B 90 1D BCC $EE3A ; Upper half: Mario is standing on it (EE3A)
$00:EE1D AD 71 14 LDA.W $1471 ; A = [$1471] (standing on a sprite/platform)
$00:EE20 F0 0B BEQ $EE2D ; No: go to EE2D
$00:EE22 A5 7D LDA RAM_MarioSpeedY ; A = Mario Y speed
$00:EE24 30 07 BMI $EE2D ; Moving up: go to EE2D
$00:EE26 64 8E STZ $8E ; [$8E] = 0
$00:EE28 A0 20 LDY.B #$20 ; Y = $20 (flat floor shape)
$00:EE2A 4C E1 EE JMP.W $EEE1 ; Land on the platform (EEE1)
$00:EE2D A5 77 LDA RAM_MarioObjStatus ; \
$00:EE2F 29 04 AND.B #$04 ; } A = [RAM_MarioObjStatus] bit 2 (on ground) | [RAM_IsFlying]
$00:EE31 05 72 ORA RAM_IsFlying ; /
$00:EE33 D0 04 BNE $EE39 ; On the ground or already in the air: return
$00:EE35 A9 24 LDA.B #$24 ; \
$00:EE37 85 72 STA RAM_IsFlying ; / In-air flag [RAM_IsFlying] = $24 (falling)
$00:EE39 60 RTS ; Return
$00:EE3A AC 93 16 LDY.W $1693 ; Y = current tile
$00:EE3D AD 31 19 LDA.W $1931 ; A = tileset
$00:EE40 C9 02 CMP.B #$02 ; Tileset 2 (Rope 1)?
$00:EE42 F0 04 BEQ $EE48 ; Yes: rope conveyor check
$00:EE44 C9 08 CMP.B #$08 ; Tileset 8 (Rope 3)?
$00:EE46 D0 0F BNE $EE57 ; No: go to EE57
$00:EE48 98 TYA ; \
$00:EE49 38 SEC ; } A = tile - $0C
$00:EE4A E9 0C SBC.B #$0C ; /
$00:EE4C C9 02 CMP.B #$02 ; Tile $0C or $0D (rope conveyor)?
$00:EE4E B0 07 BCS $EE57 ; No: go to EE57
$00:EE50 0A ASL ; A = A * 2
$00:EE51 AA TAX ; X = word index
$00:EE52 20 CD EF JSR.W $EFCD ; Move Mario along the rope ($EFCD)
$00:EE55 80 2C BRA $EE83 ; Go to EE83
$00:EE57 20 67 F2 JSR.W $F267 ; Handle tile $2E ($F267)
$00:EE5A A0 03 LDY.B #$03 ; Y = 3
$00:EE5C AD 93 16 LDA.W $1693 ; A = current tile
$00:EE5F C9 1E CMP.B #$1E ; Turn block?
$00:EE61 D0 15 BNE $EE78 ; No: go to EE78
$00:EE63 A6 8F LDX $8F ; X = [$8F] (air flag)
$00:EE65 F0 1C BEQ $EE83 ; On the ground: go to EE83
$00:EE67 A6 19 LDX RAM_MarioPowerUp ; X = power-up
$00:EE69 F0 18 BEQ $EE83 ; Small: go to EE83
$00:EE6B AE 0D 14 LDX.W RAM_IsSpinJump ; X = spin jump flag
$00:EE6E F0 13 BEQ $EE83 ; Not spin jumping: go to EE83
$00:EE70 A9 21 LDA.B #$21 ; A = $21
$00:EE72 22 7F F1 00 JSL.L $F17F ; Break the turn block ($F17F)
$00:EE76 80 A5 BRA $EE1D ; Not landed: go to EE1D
$00:EE78 C9 32 CMP.B #$32 ; Tile $32?
$00:EE7A D0 03 BNE $EE7F ; No: go to EE7F
$00:EE7C 9C 09 19 STZ.W $1909 ; [$1909] = 0
$00:EE7F 22 20 F1 00 JSL.L $F120 ; Touch the block from above ($F120: spikes and munchers hurt)
$00:EE83 A0 20 LDY.B #$20 ; Y = $20 (flat floor shape)
$00:EE85 A5 7D LDA RAM_MarioSpeedY ; \
$00:EE87 10 06 BPL $EE8F ; / Mario moving up: layer floors are passable
$00:EE89 A5 8D LDA $8D ; \
$00:EE8B C9 02 CMP.B #$02 ; } [$8D] < 2: return
$00:EE8D 90 AA BCC $EE39 ; /
$00:EE8F AE 23 14 LDX.W $1423 ; X = [$1423] (switch palace block side)
$00:EE92 F0 3D BEQ $EED1 ; No switch: go to EED1
$00:EE94 CA DEX ; X--
$00:EE95 8A TXA ; A = X
$00:EE96 29 03 AND.B #$03 ; A = A & 3
$00:EE98 F0 10 BEQ $EEAA ; Zero: go to EEAA
$00:EE9A C9 02 CMP.B #$02 ; A >= 2?
$00:EE9C B0 33 BCS $EED1 ; Yes: go to EED1
$00:EE9E C2 20 REP #$20 ; \
$00:EEA0 A5 9A LDA RAM_BlockXLo ; |
$00:EEA2 38 SEC ; |
$00:EEA3 E9 10 00 SBC.W #$0010 ; |
$00:EEA6 85 9A STA RAM_BlockXLo ; } [RAM_BlockXLo] -= $10 (use the left block of the switch)
$00:EEA8 E2 20 SEP #$20 ; /
$00:EEAA 8A TXA ; \
$00:EEAB 4A LSR ; |
$00:EEAC 4A LSR ; } X = (X - 1) / 4: switch color index
$00:EEAD AA TAX ; /
$00:EEAE BD 27 1F LDA.W $1F27,X ; A = switch active flag [$1F27 + X]
$00:EEB1 D0 1E BNE $EED1 ; Already active: go to EED1
$00:EEB3 1A INC A ; A = 1
$00:EEB4 9D 27 1F STA.W $1F27,X ; Activate the switch block
$00:EEB7 8D D2 13 STA.W $13D2 ; [$13D2] = 1 (a switch was pressed)
$00:EEBA 5A PHY ; Save Y
$00:EEBB 8E 1E 19 STX.W $191E ; [$191E] = switch index
$00:EEBE 20 45 FA JSR.W FlatPalaceSwitch ; Activate the switch palace switch (FlatPalaceSwitch)
$00:EEC1 7A PLY ; Restore Y
$00:EEC2 A9 0C LDA.B #$0C ; \
$00:EEC4 8D FB 1D STA.W $1DFB ; / Music request $0C (switch palace jingle)
$00:EEC7 A9 FF LDA.B #$FF ; \
$00:EEC9 8D DA 0D STA.W $0DDA ; / [$0DDA] = $FF (force the level music to reload afterwards)
$00:EECC A9 08 LDA.B #$08 ; \
$00:EECE 8D 93 14 STA.W $1493 ; / [$1493] = 8 (end level timer)
$00:EED1 EE EF 13 INC.W $13EF ; [$13EF]++ (Mario was pushed out of the floor)
$00:EED4 A5 96 LDA RAM_MarioYPos ; \
$00:EED6 38 SEC ; |
$00:EED7 E5 91 SBC $91 ; } Mario Y position low -= [$91]
$00:EED9 85 96 STA RAM_MarioYPos ; /
$00:EEDB A5 97 LDA RAM_MarioYPosHi ; \
$00:EEDD E5 90 SBC $90 ; } Mario Y position high -= [$90] (with borrow)
$00:EEDF 85 97 STA RAM_MarioYPosHi ; /
$00:EEE1 B9 3D E5 LDA.W $E53D,Y ; A = $E53D[Y]: slope X direction ($FF, 0, $01)
$00:EEE4 D0 09 BNE $EEEF ; On a slope: go to EEEF
$00:EEE6 AE ED 13 LDX.W $13ED ; X = [$13ED] (slide timer)
$00:EEE9 F0 1A BEQ $EF05 ; Zero: go to EF05
$00:EEEB A6 7B LDX RAM_MarioSpeedX ; X = Mario X speed
$00:EEED F0 13 BEQ $EF02 ; Standing still: stop sliding (EF02)
$00:EEEF 8D EE 13 STA.W $13EE ; [$13EE] = slope direction
$00:EEF2 A5 15 LDA RAM_ControllerA ; A = held buttons [RAM_ControllerA]
$00:EEF4 29 04 AND.B #$04 ; Down held?
$00:EEF6 F0 0D BEQ $EF05 ; No: go to EF05
$00:EEF8 AD 8F 14 LDA.W $148F ; \
$00:EEFB 0D ED 13 ORA.W $13ED ; / A = [$148F] | [$13ED]
$00:EEFE D0 05 BNE $EF05 ; Carrying something or already sliding: go to EF05
$00:EF00 A2 1C LDX.B #$1C ; X = $1C: start sliding down the slope
$00:EF02 8E ED 13 STX.W $13ED ; [$13ED] = X
$00:EF05 BE B9 E4 LDX.W $E4B9,Y ; X = $E4B9[Y]
$00:EF08 8E E1 13 STX.W $13E1 ; [$13E1] = X (slope angle for Mario's pose)
$00:EF0B C0 1C CPY.B #$1C ; Shape >= $1C (not a slope)?
$00:EF0D B0 29 BCS $EF38 ; Yes: go to EF38
$00:EF0F A5 7B LDA RAM_MarioSpeedX ; A = Mario X speed
$00:EF11 F0 1E BEQ $EF31 ; Zero: go to EF31
$00:EF13 B9 3D E5 LDA.W $E53D,Y ; A = slope X direction
$00:EF16 F0 19 BEQ $EF31 ; Flat: go to EF31
$00:EF18 45 7B EOR RAM_MarioSpeedX ; Direction EOR X speed
$00:EF1A 10 15 BPL $EF31 ; Positive (running downhill): go to EF31
$00:EF1C 8E E5 13 STX.W $13E5 ; [$13E5] = X (running uphill)
$00:EF1F A5 7B LDA RAM_MarioSpeedX ; \
$00:EF21 10 03 BPL $EF26 ; |
$00:EF23 49 FF EOR.B #$FF ; } A = |Mario X speed|
$00:EF25 1A INC A ; /
$00:EF26 C9 28 CMP.B #$28 ; Speed < $28?
$00:EF28 90 05 BCC $EF2F ; Yes: go to EF2F
$00:EF2A B9 FB E4 LDA.W $E4FB,Y ; A = $E4FB[Y]: Y speed for running uphill fast
$00:EF2D 80 31 BRA $EF60 ; Go to EF60
$00:EF2F A0 20 LDY.B #$20 ; Y = $20 (treat as flat)
$00:EF31 A5 7D LDA RAM_MarioSpeedY ; A = Mario Y speed
$00:EF33 D9 DA E4 CMP.W $E4DA,Y ; Compare with $E4DA[Y] (maximum Y speed)
$00:EF36 90 03 BCC $EF3B ; Below the limit: go to EF3B
$00:EF38 B9 DA E4 LDA.W $E4DA,Y ; A = $E4DA[Y]
$00:EF3B A6 8E LDX $8E ; X = [$8E]
$00:EF3D 10 21 BPL $EF60 ; Positive: go to EF60
$00:EF3F EE 0E 14 INC.W $140E ; [$140E]++
$00:EF42 48 PHA ; Save A
$00:EF43 C2 20 REP #$20 ; A 16-bit
$00:EF45 AD BE 17 LDA.W $17BE ; A = [$17BE] (probably layer 2 X movement this frame)
$00:EF48 29 00 FF AND.W #$FF00 ; \
$00:EF4B 10 03 BPL $EF50 ; } A = sign-extended high byte of [$17BE]
$00:EF4D 09 FF 00 ORA.W #$00FF ; /
$00:EF50 EB XBA ; Swap bytes
$00:EF51 49 FF FF EOR.W #$FFFF ; \
$00:EF54 1A INC A ; / Negate A
$00:EF55 18 CLC ; Clear carry
$00:EF56 65 94 ADC RAM_MarioXPos ; Add Mario X position
$00:EF58 85 94 STA RAM_MarioXPos ; Store Mario X position (cancel the layer's movement)
$00:EF5A E2 20 SEP #$20 ; A 8-bit
$00:EF5C 68 PLA ; Restore A
$00:EF5D 18 CLC ; Clear carry
$00:EF5E 69 28 ADC.B #$28 ; A += $28
$00:EF60 85 7D STA RAM_MarioSpeedY ; Mario Y speed = A
$00:EF62 AA TAX ; X = A
$00:EF63 10 03 BPL $EF68 ; Positive: go to EF68
$00:EF65 EE EF 13 INC.W $13EF ; [$13EF]++
$00:EF68 9C B5 18 STZ.W $18B5 ; [$18B5] = 0
$00:EF6B 64 72 STZ RAM_IsFlying ; Not in the air
$00:EF6D 64 74 STZ RAM_IsClimbing ; Not climbing
$00:EF6F 9C 06 14 STZ.W $1406 ; [$1406] = 0
$00:EF72 9C 0D 14 STZ.W RAM_IsSpinJump ; Not spin jumping
$00:EF75 A9 04 LDA.B #$04 ; \
$00:EF77 04 77 TSB RAM_MarioObjStatus ; / Set bit 2 (on ground) in [RAM_MarioObjStatus]
$00:EF79 AC 07 14 LDY.W $1407 ; Y = [$1407] (cape flight state)
$00:EF7C D0 1B BNE $EF99 ; Non-zero: go to EF99
$00:EF7E AD 7A 18 LDA.W RAM_OnYoshi ; A = on Yoshi flag
$00:EF81 F0 12 BEQ $EF95 ; Not on Yoshi: go to EF95
$00:EF83 A5 8F LDA $8F ; A = [$8F] (was in the air)
$00:EF85 F0 0E BEQ $EF95 ; Was on the ground: go to EF95
$00:EF87 AD E7 18 LDA.W RAM_YoshiHasStomp ; A = Yoshi has stomp ability
$00:EF8A F0 09 BEQ $EF95 ; No: go to EF95
$00:EF8C 22 BF 86 02 JSL.L YoshiStompRoutine ; Run the Yoshi stomp routine (YoshiStompRoutine)
$00:EF90 A9 25 LDA.B #$25 ; \
$00:EF92 8D FC 1D STA.W $1DFC ; / Sound effect $25 (Yoshi stomp)
$00:EF95 9C 97 16 STZ.W $1697 ; [$1697] = 0 (enemy stomp chain counter)
$00:EF98 60 RTS ; Return
$00:EF99 9C 97 16 STZ.W $1697 ; [$1697] = 0 (enemy stomp chain counter)
$00:EF9C 9C 07 14 STZ.W $1407 ; [$1407] = 0 (end cape flight state)
$00:EF9F C0 05 CPY.B #$05 ; State >= 5?
$00:EFA1 B0 0B BCS CallGroundPound ; Yes: cape ground pound
$00:EFA3 A5 19 LDA RAM_MarioPowerUp ; A = power-up
$00:EFA5 C9 02 CMP.B #$02 ; Cape?
$00:EFA7 D0 04 BNE $EFAD ; No: return
$00:EFA9 38 SEC ; Set carry
$00:EFAA 6E ED 13 ROR.W $13ED ; Rotate carry into bit 7 of [$13ED]
$00:EFAD 60 RTS ; Return
;;; $EFAE: Cape ground pound on landing (CallGroundPound) ;;;
;; Called when Mario lands with [$1407] >= 5 (cape dive). If he came from the air ([$8F] non-zero) runs
;; GroundPound and plays sound $09.
$00:EFAE A5 8F LDA $8F ; A = [$8F] (was in the air)
$00:EFB0 F0 09 BEQ $EFBB ; On the ground: return
$00:EFB2 22 C1 94 02 JSL.L GroundPound ; Cape ground pound (GroundPound)
$00:EFB6 A9 09 LDA.B #$09 ; \
$00:EFB8 8D FC 1D STA.W $1DFC ; / Sound effect $09 ($1DFC: impact)
$00:EFBB 60 RTS ; Return
$00:EFBC AE 93 16 LDX.W $1693 ; X = current tile
$00:EFBF E0 CE CPX.B #$CE ; Tile < $CE?
$00:EFC1 90 24 BCC $EFE7 ; Yes: return
$00:EFC3 E0 D2 CPX.B #$D2 ; Tile >= $D2?
$00:EFC5 B0 20 BCS $EFE7 ; Yes: return
$00:EFC7 8A TXA ; \
$00:EFC8 38 SEC ; |
$00:EFC9 E9 CC SBC.B #$CC ; |
$00:EFCB 0A ASL ; } X = (tile - $CC) * 2: word index
$00:EFCC AA TAX ; /
$00:EFCD A5 13 LDA RAM_FrameCounter ; \
$00:EFCF 29 03 AND.B #$03 ; / Every 4th frame only (A = [RAM_FrameCounter] & 3)
$00:EFD1 D0 14 BNE $EFE7 ; Other frames: return
$00:EFD3 C2 20 REP #$20 ; A 16-bit
$00:EFD5 A5 94 LDA RAM_MarioXPos ; A = Mario X position
$00:EFD7 18 CLC ; Clear carry
$00:EFD8 7D 13 E9 ADC.W $E913,X ; Add $E913[X]
$00:EFDB 85 94 STA RAM_MarioXPos ; Store Mario X position
$00:EFDD A5 96 LDA RAM_MarioYPos ; A = Mario Y position
$00:EFDF 18 CLC ; Clear carry
$00:EFE0 7D 1F E9 ADC.W $E91F,X ; Add $E91F[X]
$00:EFE3 85 96 STA RAM_MarioYPos ; Store Mario Y position: Mario is carried 1 pixel
$00:EFE5 E2 20 SEP #$20 ; A 8-bit
$00:EFE7 60 RTS ; Return
$00:EFE8 20 4D F4 JSR.W $F44D ; Check the next collision point for wall-running
$00:EFEB D0 03 BNE $EFF0 ; Non-page-0 tile: go to EFF0
$00:EFED 4C 09 F3 JMP.W $F309 ; Apply the page 0 tile effect ($F309) and return
$00:EFF0 C0 11 CPY.B #$11 ; Tile < $11?
$00:EFF2 90 10 BCC $F004 ; Yes: return
$00:EFF4 C0 6E CPY.B #$6E ; Tile >= $6E?
$00:EFF6 B0 0C BCS $F004 ; Yes: return
$00:EFF8 98 TYA ; A = tile
$00:EFF9 A0 00 LDY.B #$00 ; Y = 0
$00:EFFB 22 60 F1 00 JSL.L $F160 ; Block touch ($F160)
$00:EFFF 68 PLA ; \
$00:F000 68 PLA ; / Discard the caller's return address: exit the whole routine
$00:F001 4C 42 EB JMP.W $EB42 ; Mario hit a wall: fall off it (EB42)
$00:F004 60 RTS ; Return
$00:F005 98 TYA ; \
$00:F006 38 SEC ; } A = slope shape - $0E
$00:F007 E9 0E SBC.B #$0E ; /
$00:F009 C9 02 CMP.B #$02 ; Shape $0E or $0F?
$00:F00B B0 3F BCS $F04C ; No: return
$00:F00D 49 01 EOR.B #$01 ; Flip bit 0
$00:F00F C5 76 CMP RAM_MarioDirection ; Same as Mario's facing direction?
$00:F011 D0 39 BNE $F04C ; No: return
$00:F013 AA TAX ; X = side
$00:F014 4A LSR ; Carry = side
$00:F015 A5 92 LDA $92 ; A = X column [$92]
$00:F017 90 02 BCC $F01B ; Carry clear: skip
$00:F019 49 0F EOR.B #$0F ; Mirror the column
$00:F01B C9 08 CMP.B #$08 ; Column < 8?
$00:F01D B0 2D BCS $F04C ; No: return
$00:F01F AD 7A 18 LDA.W RAM_OnYoshi ; A = on Yoshi flag
$00:F022 F0 11 BEQ $F035 ; Not on Yoshi: go to F035
$00:F024 A9 08 LDA.B #$08 ; \
$00:F026 8D FC 1D STA.W $1DFC ; / Sound effect $08
$00:F029 A9 80 LDA.B #$80 ; \
$00:F02B 85 7D STA RAM_MarioSpeedY ; / Mario Y speed = $80
$00:F02D 8D 06 14 STA.W $1406 ; [$1406] = $80
$00:F030 68 PLA ; \
$00:F031 68 PLA ; / Discard the caller's return address
$00:F032 4C 35 EE JMP.W $EE35 ; Set the in-air flag (EE35) and return
$00:F035 A5 7B LDA RAM_MarioSpeedX ; A = Mario X speed
$00:F037 38 SEC ; Set carry
$00:F038 FD B9 EA SBC.W $EAB9,X ; Subtract $EAB9[X] (wall-run speed limit)
$00:F03B 5D B9 EA EOR.W $EAB9,X ; EOR the same limit
$00:F03E 30 0C BMI $F04C ; Not fast enough: return
$00:F040 AD 8F 14 LDA.W $148F ; \
$00:F043 05 73 ORA RAM_IsDucking ; / A = [$148F] | [RAM_IsDucking]
$00:F045 D0 05 BNE $F04C ; Carrying or ducking: return
$00:F047 E8 INX ; \
$00:F048 E8 INX ; / X += 2
$00:F049 8E E3 13 STX.W RAM_WallWalkStatus ; Start wall-running: [$13E3] = 2 (left) or 3 (right)
$00:F04C 60 RTS ; Return
$00:F04D DA PHX ; Save X
$00:F04E A2 19 LDX.B #$19 ; X = $19: last of 26 slope tiles
$00:F050 DF C1 EA 00 CMP.L $EAC1,X ; Compare A with $EAC1[X]
$00:F054 F0 04 BEQ $F05A ; Match: done (carry set)
$00:F056 CA DEX ; Next entry
$00:F057 10 F7 BPL $F050 ; Loop until X < 0
$00:F059 18 CLC ; No match: carry clear
$00:F05A FA PLX ; Restore X
$00:F05B 6B RTL ; Return long
;The table below here handles what bounce block image to show when hit.
;;; $F05C..F07C: Table: bounce block sprite by block ;;;
;; Indexed by acts-like tile - $11 ($24 entries): which bounce block sprite is shown when the block is hit.
$00:F05C .db $01,$05,$01,$02,$01,$01,$00,$00 ; Entries $00-$07: bounce block sprite shown (acts-like tiles $11-$18)
$00:F064 .db $00,$00,$00,$00,$00,$06,$02,$02 ; Entries $08-$0F
$00:F06C .db $02,$02,$02,$02,$02,$02,$02,$02 ; Entries $10-$17
$00:F074 .db $02,$03,$03,$04,$02,$02,$02,$01 ; Entries $18-$1F
$00:F07C .db $01,$07,$11,$10 ; Entries $20-$23
;;; $F080..F0A0: Table: item spawned by block ;;;
;; Which power-up/sprite a block releases. Bit 7 set marks special cases: $FF uses a fixed item, others pick
;; one by block X position.
$00:F080 .db $80,$00,$00,$1E,$00,$00,$05,$09 ; Entries $00-$07: item spawned (bit 7 set = special case)
$00:F088 .db $06,$81,$0E,$0C,$14,$00,$05,$09 ; Entries $08-$0F
$00:F090 .db $06,$07,$0E,$0C,$16,$18,$1A,$1A ; Entries $10-$17
$00:F098 .db $00,$09,$00,$00,$FF,$0C,$0A,$00 ; Entries $18-$1F
$00:F0A0 .db $00,$00,$08,$02 ; Entries $20-$23
;;; $F0A4..F0C4: Table: hit directions that trigger block ;;;
;; Bit masks ANDed with $F0EC[Y]; zero means the hit direction does not activate this block.
$00:F0A4 .db $0C,$08,$0C,$08,$0C,$0F,$08,$08 ; Entries $00-$07: hit directions that trigger the block (bit mask)
$00:F0AC .db $08,$08,$08,$08,$08,$08,$08,$08 ; Entries $08-$0F
$00:F0B4 .db $08,$08,$08,$08,$08,$08,$08,$08 ; Entries $10-$17
$00:F0BC .db $08,$03,$03,$08,$08,$08,$08,$08 ; Entries $18-$1F
$00:F0C4 .db $08,$04,$08,$08 ; Entries $20-$23
;;; $F0C8..F0E8: Table: tile a block turns into ;;;
;; Value stored in $07 for the bounce block; most entries are $0D (used block).
$00:F0C8 .db $0E,$13,$0E,$0D,$0E,$10,$0D,$0D ; Entries $00-$07: tile the block turns into ($0D = used block)
$00:F0D0 .db $0D,$0D,$0A,$0D,$0D,$0C,$0D,$0D ; Entries $08-$0F
$00:F0D8 .db $0D,$0D,$0B,$0D,$0D,$16,$0D,$0D ; Entries $10-$17
$00:F0E0 .db $0D,$11,$11,$12,$0D,$0D,$0D,$0E ; Entries $18-$1F
$00:F0E8 .db $0F,$0C,$0D,$0D ; Entries $20-$23
;;; $F0EC..F0F4: Table: bit masks for block hits ;;;
;; First four bytes: hit direction masks. The rest are more masks (purpose uncertain).
$00:F0EC .db $08,$01,$02,$04,$ED,$F6,$00,$7D ; Bit masks: $08, $01, $02, $04 = hit direction 0-3, then more masks
$00:F0F4 .db $BE,$00,$6F,$B7 ; More bit masks (probably used with $13F3)
;;; $F0F8..F118: Table: block X positions and ? block contents ;;;
;; $F0F8: X low bytes of blocks regenerated as used blocks. $F100: contents of special ? blocks by
;; X position.
$00:F0F8 .db $40,$50,$00,$70,$80,$00,$A0,$B0 ; X position low bytes of 8 blocks regenerated as used blocks
$00:F100 .db $05,$09,$06,$05,$09,$06,$05,$09 ; Special ? block contents by block X position (same format as the item table)
$00:F108 .db $06,$05,$09,$06,$05,$09,$06,$05 ; Contents, cont.
$00:F110 .db $07,$0A,$10,$07,$0A,$10,$07,$0A ; Contents, cont.
$00:F118 .db $10,$07,$0A,$10,$07,$0A,$10,$07 ; Contents, cont.
;;; $F120: Block interaction: hurt tiles, bounce blocks, coins ;;;
;; Tail of the Mario-versus-tile code. Several entry points share it, all working on the touched tile number
;; (Y or A) and the hit side (Y):
;; $00F120: spikes/munchers. Tile $2F always hurts; castle spike tiles hurt in castle tilesets ($1931 = 1) and
;; some ghost house ones; skipped on Yoshi.
;; $00F160: tiles $11-$2D and $6A/$6B that can be hit from below. Looks up bounce sprite, contents and
;; replacement block, then spawns the bounce sprite.
;; Switch palace blocks keep hit flags in $13F3. $00F267: grab a turn block. $00F28C: invisible 1-up
;; checkpoint tiles ($6F-$72, must be touched in order).
;; $00F2C0: other tile classes (climbing flags, $38 pickup, 3-up moon $6E, coins, Yoshi coins).
;; $00F377/$00F38A: spawn a score sprite at Mario.
;; $00F3B2: bit array helper for the level number. $00F3C4: pipe entry check for tile $3F.
;; Parameters: Y = tile number / side as described per entry. Several parts are only hedged guesses (see line
;; comments).
;; Called by:
;; $00:EE7F: Mario block and slope collision (rest)
$00:F120 EB XBA ; Stash the tile number in the hidden half of A
$00:F121 AD 7A 18 LDA.W RAM_OnYoshi ; \
$00:F124 D0 39 BNE $F15F ; / Riding Yoshi: skip the hurt tiles ($00F15F)
$00:F126 EB XBA ; Tile number back in A
$00:F127 C9 2F CMP.B #$2F ; \
$00:F129 F0 29 BEQ $F154 ; / Tile $2F (muncher): hurt Mario ($00F154)
$00:F12B C9 59 CMP.B #$59 ; \
$00:F12D 90 15 BCC $F144 ; |
$00:F12F C9 5C CMP.B #$5C ; } Tiles < $59: go to $00F144; $59-$5B (castle spikes) continue; >= $5C: go to $00F140
$00:F131 B0 0D BCS $F140 ; /
$00:F133 EB XBA ; Stash the tile number again
$00:F134 AD 31 19 LDA.W $1931 ; \
$00:F137 C9 05 CMP.B #$05 ; } Ghost house tileset ([$1931] = 5): spikes hurt
$00:F139 F0 19 BEQ $F154 ; /
$00:F13B C9 0D CMP.B #$0D ; \
$00:F13D F0 15 BEQ $F154 ; / Ghost house 2 tileset ([$1931] = $0D): spikes hurt
$00:F13F EB XBA ; Tile number back in A
$00:F140 C9 5D CMP.B #$5D ; \
$00:F142 90 08 BCC $F14C ; / Tile $5C: go check for the castle tileset
$00:F144 C9 66 CMP.B #$66 ; \
$00:F146 90 18 BCC $F160 ; / Tiles $5D-$65 are harmless: go to $00F160
$00:F148 C9 6A CMP.B #$6A ; \
$00:F14A B0 14 BCS $F160 ; / Tiles >= $6A are harmless too: go to $00F160
$00:F14C EB XBA ; Stash the tile number
$00:F14D AD 31 19 LDA.W $1931 ; \
$00:F150 C9 01 CMP.B #$01 ; } Tiles $59-$5C and $66-$69 only hurt in tileset 1 (castle); else skip
$00:F152 D0 0B BNE $F15F ; /
$00:F154 8B PHB ; Save data bank
$00:F155 A9 01 LDA.B #$01 ; \
$00:F157 48 PHA ; } Data bank = $01
$00:F158 AB PLB ; /
$00:F159 22 B7 F5 00 JSL.L HurtMario ; Hurt Mario (HurtMario)
$00:F15D AB PLB ; Restore data bank
$00:F15E 6B RTL ; Return
$00:F15F EB XBA ; Tile number back in A
$00:F160 38 SEC ; \
$00:F161 E9 11 SBC.B #$11 ; |
$00:F163 C9 1D CMP.B #$1D ; } Entry from $00EFFB: tiles $11-$2D (tile - $11 < $1D): go to $00F17F
$00:F165 90 18 BCC $F17F ; /
$00:F167 EB XBA ; Stash tile - $11 (A = high byte)
$00:F168 DA PHX ; Save X
$00:F169 AE 31 19 LDX.W $1931 ; X = tileset number ([$1931])
$00:F16C BF 25 A6 00 LDA.L $A625,X ; A = page behaviour flags for this tileset ($A625)
$00:F170 FA PLX ; Restore X
$00:F171 29 03 AND.B #$03 ; \
$00:F173 F0 01 BEQ $F176 ; / Low 2 bits of the flags zero: also test tiles $6A/$6B ($00F176)
$00:F175 6B RTL ; Return (flags non-zero: tile does nothing)
$00:F176 EB XBA ; Tile - $11 back in A
$00:F177 E9 59 SBC.B #$59 ; \
$00:F179 C9 02 CMP.B #$02 ; } Only tiles $6A and $6B (tile - $6A < 2) continue; others return
$00:F17B B0 7B BCS $F1F8 ; /
$00:F17D 69 22 ADC.B #$22 ; Table index $22/$23 for tiles $6A/$6B
$00:F17F DA PHX ; Save X
$00:F180 48 PHA ; Save the table index
$00:F181 BB TYX ; X = Y (side of the block that was touched)
$00:F182 BF EC F0 00 LDA.L $F0EC,X ; A = bit mask for that side ($F0EC)
$00:F186 FA PLX ; X = table index
$00:F187 3F A4 F0 00 AND.L $F0A4,X ; Mask with the sides this block can be hit from ($F0A4)
$00:F18B F0 69 BEQ $F1F6 ; Cannot be hit from this side: restore X and return ($00F1F6)
$00:F18D 84 06 STY $06 ; [$06] = side that was hit
$00:F18F BF C8 F0 00 LDA.L $F0C8,X ; \
$00:F193 85 07 STA $07 ; / [$07] = block the tile turns into ($F0C8)
$00:F195 BF 5C F0 00 LDA.L $F05C,X ; \
$00:F199 85 04 STA $04 ; / [$04] = bounce sprite graphic ($F05C)
$00:F19B BF 80 F0 00 LDA.L $F080,X ; \
$00:F19F 10 19 BPL $F1BA ; / A = block contents ($F080); bit 7 clear: use it directly ($00F1BA)
$00:F1A1 C9 FF CMP.B #$FF ; \
$00:F1A3 D0 09 BNE $F1AE ; / Contents $FF: special case; other values with bit 7 set go to $00F1AE
$00:F1A5 A9 05 LDA.B #$05 ; Contents = 5 if [$0DC0] is zero
$00:F1A7 AC C0 0D LDY.W $0DC0 ; \
$00:F1AA F0 24 BEQ $F1D0 ; / [$0DC0] = 0: keep 5 ($00F1D0)
$00:F1AC 80 20 BRA $F1CE ; Otherwise use contents 6 ($00F1CE)
$00:F1AE 4A LSR ; A = contents >> 1, carry = bit 0
$00:F1AF A5 9A LDA RAM_BlockXLo ; \
$00:F1B1 6A ROR ; |
$00:F1B2 4A LSR ; |
$00:F1B3 4A LSR ; |
$00:F1B4 4A LSR ; } X = block column + 16 * (bit 0 of contents); contents vary with the block's X position
$00:F1B5 AA TAX ; /
$00:F1B6 BF 00 F1 00 LDA.L $F100,X ; A = contents from $F100 (repeating 5,9,6 pattern: position dependent)
$00:F1BA 4A LSR ; \
$00:F1BB 90 13 BCC $F1D0 ; / Shift out bit 0: clear = use A as the contents ($00F1D0)
$00:F1BD C9 03 CMP.B #$03 ; \
$00:F1BF F0 08 BEQ $F1C9 ; / Contents 3: go check the star timer ($00F1C9)
$00:F1C1 A4 19 LDY RAM_MarioPowerUp ; \
$00:F1C3 D0 0B BNE $F1D0 ; / Mario is not small: keep the value
$00:F1C5 A9 01 LDA.B #$01 ; \
$00:F1C7 80 07 BRA $F1D0 ; / Mario is small: contents = 1
$00:F1C9 AC 90 14 LDY.W $1490 ; \
$00:F1CC D0 02 BNE $F1D0 ; / Contents 3: keep it only while the star timer [$1490] is non-zero
$00:F1CE A9 06 LDA.B #$06 ; Otherwise contents = 6
$00:F1D0 85 05 STA $05 ; [$05] = contents for the bounce sprite spawner
$00:F1D2 C9 05 CMP.B #$05 ; \
$00:F1D4 D0 04 BNE $F1DA ; / Contents 5 (probably the vine)? Otherwise skip
$00:F1D6 A9 16 LDA.B #$16 ; \
$00:F1D8 85 07 STA $07 ; / Contents 5: block becomes $16 ([$07])
$00:F1DA A8 TAY ; Y = contents
$00:F1DB A9 0F LDA.B #$0F ; \
$00:F1DD 14 9A TRB RAM_BlockXLo ; } Snap the block position to the 16x16 grid (clear low nibbles)
$00:F1DF 14 98 TRB RAM_BlockYLo ; /
$00:F1E1 C0 06 CPY.B #$06 ; \
$00:F1E3 D0 07 BNE $F1EC ; / Contents 6? Otherwise spawn normally ($00F1EC)
$00:F1E5 AC 31 19 LDY.W $1931 ; \
$00:F1E8 C0 04 CPY.B #$04 ; } Contents 6 in tileset 4 (switch palace): go to $00F1F9
$00:F1EA F0 0D BEQ $F1F9 ; /
$00:F1EC 8B PHB ; Save data bank
$00:F1ED A9 02 LDA.B #$02 ; \
$00:F1EF 48 PHA ; } Data bank = $02
$00:F1F0 AB PLB ; /
$00:F1F1 22 52 87 02 JSL.L $8752 ; Spawn the bounce sprite ($8752)
$00:F1F5 AB PLB ; Restore data bank
$00:F1F6 FA PLX ; Restore X
$00:F1F7 18 CLC ; Carry clear
$00:F1F8 6B RTL ; Return
$00:F1F9 A5 99 LDA RAM_BlockYHi ; \
$00:F1FB 4A LSR ; / Carry = bit 0 of block Y high byte
$00:F1FC A5 98 LDA RAM_BlockYLo ; \
$00:F1FE 29 C0 AND.B #$C0 ; |
$00:F200 2A ROL ; |
$00:F201 2A ROL ; |
$00:F202 2A ROL ; } Y = (Y high bit 0) * 4 + Y low / $40: index of the 64 pixel row (0-7)
$00:F203 A8 TAY ; /
$00:F204 A5 9A LDA RAM_BlockXLo ; \
$00:F206 4A LSR ; |
$00:F207 4A LSR ; |
$00:F208 4A LSR ; |
$00:F209 4A LSR ; } X = block column (X low / 16)
$00:F20A AA TAX ; /
$00:F20B B9 F3 13 LDA.W $13F3,Y ; \
$00:F20E 1F EC F0 00 ORA.L $F0EC,X ; |
$00:F212 BE F3 13 LDX.W $13F3,Y ; } [$13F3 + Y] |= bit mask for X ($F0EC); X = previous value
$00:F215 99 F3 13 STA.W $13F3,Y ; /
$00:F218 C9 FF CMP.B #$FF ; \
$00:F21A D0 0A BNE $F226 ; / All bits set? Not yet: go to $00F226
$00:F21C A9 05 LDA.B #$05 ; \
$00:F21E 85 05 STA $05 ; / [$05] = 5
$00:F220 A9 17 LDA.B #$17 ; \
$00:F222 85 07 STA $07 ; / [$07] = $17: block the tile turns into
$00:F224 80 C6 BRA $F1EC ; Spawn the bounce sprite ($00F1EC)
$00:F226 AD 1B 14 LDA.W $141B ; \
$00:F229 D0 0B BNE $F236 ; / [$141B] non-zero: go straight to $00F236
$00:F22B 8A TXA ; \
$00:F22C F0 02 BEQ $F230 ; / A = 0 if no block was hit here before
$00:F22E A9 02 LDA.B #$02 ; Otherwise A = 2
$00:F230 49 03 EOR.B #$03 ; \
$00:F232 25 13 AND RAM_FrameCounter ; / A = (A xor 3) AND frame counter: probably a timing check
$00:F234 D0 EA BNE $F220 ; Non-zero: use the $17 block variant ($00F220)
$00:F236 A9 2A LDA.B #$2A ; \
$00:F238 8D FC 1D STA.W $1DFC ; / Play sound effect $2A
$00:F23B 5A PHY ; Save Y
$00:F23C 64 05 STZ $05 ; [$05] = 0 (no contents)
$00:F23E 8B PHB ; Save data bank
$00:F23F A9 02 LDA.B #$02 ; \
$00:F241 48 PHA ; } Data bank = $02
$00:F242 AB PLB ; /
$00:F243 22 52 87 02 JSL.L $8752 ; Spawn the bounce sprite ($8752)
$00:F247 AB PLB ; Restore data bank
$00:F248 7A PLY ; Restore Y
$00:F249 A2 07 LDX.B #$07 ; X = 7: loop over the eight blocks of the row group
$00:F24B B9 F3 13 LDA.W $13F3,Y ; A = hit flags [$13F3 + Y]
$00:F24E 4A LSR ; Shift the next flag bit into carry
$00:F24F B0 10 BCS $F261 ; Bit set: skip to the next block
$00:F251 48 PHA ; Save the shifted flags
$00:F252 A9 0D LDA.B #$0D ; \
$00:F254 85 9C STA RAM_BlockBlock ; / Block to generate = $0D (used block)
$00:F256 BF F8 F0 00 LDA.L $F0F8,X ; \
$00:F25A 85 9A STA RAM_BlockXLo ; / [BlockXLo] = X position of block X ($F0F8)
$00:F25C 22 B0 BE 00 JSL.L GenerateTile ; Generate the tile
$00:F260 68 PLA ; Restore the shifted flags
$00:F261 CA DEX ; Next block
$00:F262 10 EA BPL $F24E ; Loop for X = 7..0
$00:F264 4C F6 F1 JMP.W $F1F6 ; Restore X and return ($00F1F6)
$00:F267 C0 2E CPY.B #$2E ; \
$00:F269 D0 20 BNE $F28B ; / Only for tile $2E (turn block); others return
$00:F26B 24 16 BIT $16 ; \
$00:F26D 50 1C BVC $F28B ; / Return unless the Y/X button was just pressed ([$16] bit 6)
$00:F26F AD 8F 14 LDA.W $148F ; \
$00:F272 0D 7A 18 ORA.W RAM_OnYoshi ; } Return if carrying something ([$148F]) or riding Yoshi
$00:F275 D0 14 BNE $F28B ; /
$00:F277 A9 02 LDA.B #$02 ; \
$00:F279 48 PHA ; } Data bank = $02
$00:F27A AB PLB ; /
$00:F27B 22 2F 86 02 JSL.L $862F ; Try to spawn a carried throw block sprite ($862F); N set = failed
$00:F27F 30 08 BMI $F289 ; Failed: skip the tile change
$00:F281 A9 02 LDA.B #$02 ; \
$00:F283 85 9C STA RAM_BlockBlock ; } Block to generate = $02 (empty): the turn block disappears
$00:F285 22 B0 BE 00 JSL.L GenerateTile ; /
$00:F289 4B PHK ; \
$00:F28A AB PLB ; / Data bank = $00 (program bank)
$00:F28B 60 RTS ; Return
$00:F28C 98 TYA ; \
$00:F28D 38 SEC ; |
$00:F28E E9 6F SBC.B #$6F ; } Tiles $6F-$72 (invisible 1-up checkpoints): A = tile - $6F; others go to $00F2C0
$00:F290 C9 04 CMP.B #$04 ; /
$00:F292 B0 2C BCS $F2C0 ; Not a checkpoint tile: go to $00F2C0
$00:F294 CD 21 14 CMP.W $1421 ; \
$00:F297 F0 0F BEQ $F2A8 ; / Touched the one the counter expects ([$1421]): advance
$00:F299 1A INC A ; \
$00:F29A CD 21 14 CMP.W $1421 ; } Touched the one before the counter: ignore
$00:F29D F0 20 BEQ $F2BF ; /
$00:F29F AD 21 14 LDA.W $1421 ; \
$00:F2A2 C9 04 CMP.B #$04 ; } Counter already complete (>= 4): ignore
$00:F2A4 B0 19 BCS $F2BF ; /
$00:F2A6 A9 FF LDA.B #$FF ; Wrong order: A = $FF so that the counter restarts at 0
$00:F2A8 1A INC A ; Advance, or reset to 0
$00:F2A9 8D 21 14 STA.W $1421 ; Store [$1421], the checkpoint progress counter
$00:F2AC C9 04 CMP.B #$04 ; \
$00:F2AE D0 0F BNE $F2BF ; / Not yet 4: return
$00:F2B0 DA PHX ; Save X
$00:F2B1 22 D9 C2 03 JSL.L TriggerInivis1Up ; Spawn the invisible 1-up (TriggerInivis1Up)
$00:F2B5 20 B2 F3 JSR.W $F3B2 ; Y = byte index, A = bit mask for the current level number ($F3B2)
$00:F2B8 19 3C 1F ORA.W $1F3C,Y ; \
$00:F2BB 99 3C 1F STA.W $1F3C,Y ; / Set the level's flag in the bit array at [$1F3C + Y]
$00:F2BE FA PLX ; Restore X
$00:F2BF 60 RTS ; Return
$00:F2C0 A9 01 LDA.B #$01 ; A = 1
$00:F2C2 C0 06 CPY.B #$06 ; \
$00:F2C4 B0 03 BCS $F2C9 ; / Tiles $06 and up: go to $00F2C9
$00:F2C6 04 8A TSB $8A ; Tiles $00-$05: set bit 0 of [$8A]
$00:F2C8 60 RTS ; Return
$00:F2C9 C0 38 CPY.B #$38 ; \
$00:F2CB D0 21 BNE $F2EE ; / Tile $38: handle it here, everything else goes on to $00F2EE
$00:F2CD A9 02 LDA.B #$02 ; \
$00:F2CF 85 9C STA RAM_BlockBlock ; } Block to generate = $02: remove the tile
$00:F2D1 22 B0 BE 00 JSL.L GenerateTile ; /
$00:F2D5 20 5A FD JSR.W $FD5A ; Spawn a twinkle effect ($FD5A)
$00:F2D8 AD CD 13 LDA.W $13CD ; \
$00:F2DB F0 03 BEQ $F2E0 ; / [$13CD] clear: skip the next call
$00:F2DD 20 2B CA JSR.W $CA2B ; Flag set: run $CA2B
$00:F2E0 A5 19 LDA RAM_MarioPowerUp ; \
$00:F2E2 D0 04 BNE $F2E8 ; / Mario already big: no change
$00:F2E4 A9 01 LDA.B #$01 ; \
$00:F2E6 85 19 STA RAM_MarioPowerUp ; / Small Mario becomes big
$00:F2E8 A9 05 LDA.B #$05 ; \
$00:F2EA 8D F9 1D STA.W $1DF9 ; / Play sound effect $05
$00:F2ED 60 RTS ; Return
$00:F2EE C0 06 CPY.B #$06 ; \
$00:F2F0 F0 0A BEQ $F2FC ; / Tile $06: go to $00F2FC with A = 1
$00:F2F2 C0 07 CPY.B #$07 ; \
$00:F2F4 90 13 BCC $F309 ; / Tiles < $07: go to $00F309
$00:F2F6 C0 1D CPY.B #$1D ; \
$00:F2F8 B0 0F BCS $F309 ; / Tiles >= $1D: go to $00F309
$00:F2FA 09 80 ORA.B #$80 ; Tiles $07-$1C: A = $81
$00:F2FC C9 01 CMP.B #$01 ; \
$00:F2FE D0 02 BNE $F302 ; / Tile $06 (A = 1): also set bits $18
$00:F300 09 18 ORA.B #$18 ; A = $19
$00:F302 04 8B TSB $8B ; Set the flag bits in [$8B] (probably the climbing / tile-contact flags)
$00:F304 A5 93 LDA $93 ; \
$00:F306 85 8C STA $8C ; / [$8C] = [$93]
$00:F308 60 RTS ; Return
$00:F309 C0 2F CPY.B #$2F ; \
$00:F30B B0 04 BCS $F311 ; / Tiles >= $2F: go to $00F311
$00:F30D C0 2A CPY.B #$2A ; \
$00:F30F B0 1A BCS $F32B ; / Tiles $2A-$2E: go to $00F32B
$00:F311 C0 6E CPY.B #$6E ; \
$00:F313 D0 61 BNE $F376 ; / Only tile $6E (3-up moon) continues
$00:F315 A9 0F LDA.B #$0F ; \
$00:F317 22 8A F3 00 JSL.L $F38A ; / Spawn the 3-up score sprite at Mario ($F38A, A = $0F)
$00:F31B EE C5 13 INC.W $13C5 ; [$13C5]++: moon collected
$00:F31E DA PHX ; Save X
$00:F31F 20 B2 F3 JSR.W $F3B2 ; Y = byte index, A = bit mask for the current level number
$00:F322 19 EE 1F ORA.W $1FEE,Y ; \
$00:F325 99 EE 1F STA.W $1FEE,Y ; / Set the level's flag in the bit array at [$1FEE + Y] (moon collected)
$00:F328 FA PLX ; Restore X
$00:F329 80 40 BRA $F36B ; Remove the tile ($00F36B)
$00:F32B D0 05 BNE $F332 ; Not tile $2A: go to $00F332
$00:F32D AD AD 14 LDA.W RAM_BluePowTimer ; \
$00:F330 F0 44 BEQ $F376 ; / Tile $2A only counts while the blue POW timer is running
$00:F332 C0 2D CPY.B #$2D ; \
$00:F334 F0 09 BEQ $F33F ; / Tile $2D: go to $00F33F
$00:F336 90 2F BCC $F367 ; Tiles $2B-$2C: coins ($00F367)
$00:F338 A5 98 LDA RAM_BlockYLo ; \
$00:F33A 38 SEC ; |
$00:F33B E9 10 SBC.B #$10 ; } Tile $2E: move the block position up one block (other half of the Yoshi coin)
$00:F33D 85 98 STA RAM_BlockYLo ; /
$00:F33F 22 77 F3 00 JSL.L $F377 ; Spawn the escalating score sprite for Yoshi coins ($F377)
$00:F343 EE 22 14 INC.W $1422 ; \
$00:F346 AD 22 14 LDA.W $1422 ; } [$1422]++ : Yoshi coins collected in this level
$00:F349 C9 05 CMP.B #$05 ; /
$00:F34B 90 0B BCC $F358 ; Fewer than 5: skip the flag
$00:F34D DA PHX ; Save X
$00:F34E 20 B2 F3 JSR.W $F3B2 ; Y = byte index, A = bit mask for the current level number
$00:F351 19 2F 1F ORA.W $1F2F,Y ; \
$00:F354 99 2F 1F STA.W $1F2F,Y ; / 5 Yoshi coins: set the level's flag in the bit array at [$1F2F + Y]
$00:F357 FA PLX ; Restore X
$00:F358 A9 1C LDA.B #$1C ; \
$00:F35A 8D F9 1D STA.W $1DF9 ; / Play sound effect $1C
$00:F35D A9 01 LDA.B #$01 ; \
$00:F35F 22 30 B3 05 JSL.L $B330 ; / Add A = 1 coin to the coin counter ($B330)
$00:F363 A0 18 LDY.B #$18 ; Block to generate = $18
$00:F365 80 06 BRA $F36D ; Go generate it ($00F36D)
$00:F367 22 4A B3 05 JSL.L $B34A ; Coin: add 1 coin and play the coin sound ($B34A)
$00:F36B A0 01 LDY.B #$01 ; Block to generate = $01
$00:F36D 84 9C STY RAM_BlockBlock ; [BlockBlock] = Y
$00:F36F 22 B0 BE 00 JSL.L GenerateTile ; Generate the tile (GenerateTile)
$00:F373 20 5A FD JSR.W $FD5A ; Spawn a twinkle effect ($FD5A)
$00:F376 60 RTS ; Return
$00:F377 AD 20 14 LDA.W $1420 ; A = [$1420]: Yoshi coins collected in a row
$00:F37A EE 20 14 INC.W $1420 ; [$1420]++
$00:F37D 18 CLC ; \
$00:F37E 69 09 ADC.B #$09 ; } Score sprite number = count + 9, at most $0D
$00:F380 C9 0D CMP.B #$0D ; /
$00:F382 90 02 BCC $F386 ; Below the limit: use it
$00:F384 A9 0D LDA.B #$0D ; Limit: $0D
$00:F386 80 02 BRA $F38A ; Continue at $F38A
$00:F388 A9 0D LDA.B #$0D ; A = $0D (score sprite number)
$00:F38A 48 PHA ; Save the score sprite number
$00:F38B 22 34 AD 02 JSL.L $AD34 ; Find a free score sprite slot: Y = index ($AD34)
$00:F38F 68 PLA ; Restore the score sprite number
$00:F390 99 E1 16 STA.W RAM_ScoreSprNum,Y ; Score sprite number
$00:F393 A5 94 LDA RAM_MarioXPos ; \
$00:F395 99 ED 16 STA.W RAM_ScoreSprXLo,Y ; |
$00:F398 A5 95 LDA RAM_MarioXPosHi ; |
$00:F39A 99 F3 16 STA.W RAM_ScoreSprXHi,Y ; |
$00:F39D A5 96 LDA RAM_MarioYPos ; |
$00:F39F 99 E7 16 STA.W RAM_ScoreSprYLo,Y ; |
$00:F3A2 A5 97 LDA RAM_MarioYPosHi ; } Score sprite position = Mario's position
$00:F3A4 99 F9 16 STA.W RAM_ScoreSprYHi,Y ; /
$00:F3A7 A9 30 LDA.B #$30 ; \
$00:F3A9 99 FF 16 STA.W RAM_ScoreSprSpeedY,Y ; / Score sprite Y speed = $30
$00:F3AC A9 00 LDA.B #$00 ; \
$00:F3AE 99 05 17 STA.W $1705,Y ; / Score sprite table $1705 = 0 (probably a timer)
$00:F3B1 6B RTL ; Return
$00:F3B2 AD BF 13 LDA.W $13BF ; \
$00:F3B5 4A LSR ; |
$00:F3B6 4A LSR ; |
$00:F3B7 4A LSR ; } Y = [$13BF] / 8: byte index for the level number
$00:F3B8 A8 TAY ; /
$00:F3B9 AD BF 13 LDA.W $13BF ; \
$00:F3BC 29 07 AND.B #$07 ; } X = [$13BF] AND 7: bit within the byte
$00:F3BE AA TAX ; /
$00:F3BF BF 5B B3 05 LDA.L $B35B,X ; A = bit mask ($B35B: $80 >> X)
$00:F3C3 60 RTS ; Return
$00:F3C4 C0 3F CPY.B #$3F ; \
$00:F3C6 D0 AE BNE $F376 ; / Tile $3F only (probably a pipe tile); others return
$00:F3C8 A4 8F LDY $8F ; \
$00:F3CA F0 03 BEQ $F3CF ; / [$8F] zero: continue
$00:F3CC 4C 3F F4 JMP.W $F43F ; Else skip to $00F43F
$00:F3CF DA PHX ; Save X
$00:F3D0 AA TAX ; X = A (button index)
$00:F3D1 A5 94 LDA RAM_MarioXPos ; A = Mario X position
$00:F3D3 9B TXY ; Y = X, sets the zero flag from the index
$00:F3D4 F0 03 BEQ $F3D9 ; Index 0: use the position as it is
$00:F3D6 49 FF EOR.B #$FF ; \
$00:F3D8 1A INC A ; / Otherwise negate it
$00:F3D9 29 0F AND.B #$0F ; Position within the 16 pixel block
$00:F3DB 0A ASL ; \
$00:F3DC 18 CLC ; } A = 2 * that + $20: pipe entry timer
$00:F3DD 69 20 ADC.B #$20 ; /
$00:F3DF A0 05 LDY.B #$05 ; Y = 5: Mario animation for the pipe entry
$00:F3E1 80 27 BRA $F40A ; Share the code at $00F40A
;;; $F3E3..F3E3: Table: pipe entry alignment offsets ;;;
$00:F3E3 .db $0A,$FF ; Alignment offsets subtracted from [$92] for tiles $37 ($0A) and $38 ($FF)
;;; $F3E5: Pipe entry, map16 lookup at collision point (PIPE_BUTTONS) ;;;
;; PIPE_BUTTONS: controller bit needed to enter a pipe, indexed 0-3 (Left, Right, Up, Down).
;; $00F3E9: entry for tiles $37/$38 (A = button index). Checks alignment, the button in [$15], then starts the
;; pipe animation ([$71], [$1419], [$88], [$89]).
;; $00F443: carry = Mario's center is in the right half of a block. $00F44D: sets the collision point
;; [$9A]/[$98] from Mario's position plus table offset.
;; $00F465: converts the collision point to a map16 address for layer 1 or 2, horizontal or vertical level
;; ([$8E]), reads the tile low byte into [$1693]
;; and the high byte into A, then adjusts for switches via $00F545. Out of range: Y = $25 (empty), A = 0.
;; Returns: Y = [$1693], A = high byte, Z set from A.
;; $00F545: P-switch tile swapping, first part (tile $29 invisible POW block becomes $24 while the blue POW is
;; active).
$00:F3E5 .db $02,$01,$08,$04 ; Button for each pipe index: $02 Left, $01 Right, $08 Up, $04 Down
$00:F3E9 EB XBA ; Stash the button index in B
$00:F3EA 98 TYA ; \
$00:F3EB 38 SEC ; |
$00:F3EC E9 37 SBC.B #$37 ; |
$00:F3EE C9 02 CMP.B #$02 ; } Tiles $37/$38 only (Y = tile - $37); others return
$00:F3F0 B0 50 BCS $F442 ; /
$00:F3F2 A8 TAY ; Y = 0 or 1
$00:F3F3 A5 92 LDA $92 ; A = [$92]
$00:F3F5 F9 E3 F3 SBC.W $F3E3,Y ; Subtract the entry alignment offset ($F3E3)
$00:F3F8 C9 05 CMP.B #$05 ; \
$00:F3FA B0 43 BCS $F43F ; / Not within 5 of the pipe: restore Y and return ($00F43F)
$00:F3FC DA PHX ; Save X
$00:F3FD EB XBA ; \
$00:F3FE AA TAX ; / X = button index
$00:F3FF A9 20 LDA.B #$20 ; A = $20: pipe entry timer
$00:F401 AC 7A 18 LDY.W RAM_OnYoshi ; \
$00:F404 F0 02 BEQ $F408 ; / Riding Yoshi?
$00:F406 A9 30 LDA.B #$30 ; Then $30
$00:F408 A0 06 LDY.B #$06 ; Y = 6: Mario animation for the pipe entry
$00:F40A 85 88 STA $88 ; [$88] = pipe entry timer
$00:F40C A5 15 LDA RAM_ControllerA ; \
$00:F40E 3D E5 F3 AND.W PIPE_BUTTONS,X ; } Required direction button not pressed in [$15]: no pipe ($00F43E)
$00:F411 F0 2B BEQ $F43E ; /
$00:F413 85 9D STA RAM_SpritesLocked ; Lock sprites
$00:F415 29 01 AND.B #$01 ; \
$00:F417 85 76 STA RAM_MarioDirection ; / Mario faces right if the pressed button was Right
$00:F419 86 89 STX $89 ; [$89] = pipe direction index
$00:F41B 8A TXA ; \
$00:F41C 4A LSR ; } X = index / 2: 0 = horizontal, 1 = vertical
$00:F41D AA TAX ; /
$00:F41E D0 10 BNE $F430 ; Vertical pipe: skip the carry check
$00:F420 AD 8F 14 LDA.W $148F ; \
$00:F423 F0 0B BEQ $F430 ; / Horizontal pipe, carrying something ([$148F])?
$00:F425 A5 76 LDA RAM_MarioDirection ; \
$00:F427 49 01 EOR.B #$01 ; } Turn Mario around
$00:F429 85 76 STA RAM_MarioDirection ; /
$00:F42B A9 08 LDA.B #$08 ; \
$00:F42D 8D 99 14 STA.W RAM_FaceCamImgTimer ; / Face-the-camera timer = 8
$00:F430 E8 INX ; X + 1
$00:F431 8E 19 14 STX.W RAM_YoshiInPipe ; [$1419] = 1 (horizontal) or 2 (vertical): entering a pipe
$00:F434 84 71 STY RAM_MarioAnimation ; Mario animation = Y
$00:F436 20 2D F6 JSR.W NoButtons ; Clear the controller mirrors (NoButtons)
$00:F439 A9 04 LDA.B #$04 ; \
$00:F43B 8D F9 1D STA.W $1DF9 ; / Play sound effect $04 (pipe)
$00:F43E FA PLX ; Restore X
$00:F43F AC 93 16 LDY.W $1693 ; Y = [$1693]: the tile number
$00:F442 60 RTS ; Return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Player-block interaction
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$00:F443 A5 94 LDA RAM_MarioXPos ; \
$00:F445 18 CLC ; |
$00:F446 69 04 ADC.B #$04 ; |
$00:F448 29 0F AND.B #$0F ; } Carry = ((Mario X + 4) AND $0F) >= 8: Mario's center is in the right half of a block
$00:F44A C9 08 CMP.B #$08 ; /
$00:F44C 60 RTS ; Return
$00:F44D E8 INX ; \
$00:F44E E8 INX ; / X += 2
$00:F44F C2 20 REP #$20 ; A 16-bit
$00:F451 A5 94 LDA RAM_MarioXPos ; \
$00:F453 18 CLC ; |
$00:F454 7D 30 E8 ADC.W $E830,X ; } [BlockXLo] = Mario X + collision point X offset ($E830)
$00:F457 85 9A STA RAM_BlockXLo ; /
$00:F459 A5 96 LDA RAM_MarioYPos ; \
$00:F45B 18 CLC ; |
$00:F45C 7D 9C E8 ADC.W $E89C,X ; } [BlockYLo] = Mario Y + collision point Y offset ($E89C)
$00:F45F 85 98 STA RAM_BlockYLo ; /
$00:F461 20 65 F4 JSR.W $F465 ; Look up the tile at this point ($F465)
$00:F464 60 RTS ; Return
$00:F465 E2 20 SEP #$20 ; A 8-bit
$00:F467 9C 23 14 STZ.W $1423 ; [$1423] = 0: switch palace color flag
$00:F46A DA PHX ; Save X
$00:F46B A5 8E LDA $8E ; \
$00:F46D 10 03 BPL $F472 ; / [$8E] bit 7 clear: layer 1
$00:F46F 4C EC F4 JMP.W $F4EC ; Layer 2: go to $00F4EC
$00:F472 D0 32 BNE $F4A6 ; [$8E] non-zero: vertical level ($00F4A6)
$00:F474 C2 20 REP #$20 ; \
$00:F476 A5 98 LDA RAM_BlockYLo ; |
$00:F478 C9 B0 01 CMP.W #$01B0 ; } Horizontal layer 1: Y position >= $01B0 (below the level)?
$00:F47B E2 20 SEP #$20 ; /
$00:F47D B0 21 BCS $F4A0 ; Outside: no tile ($00F4A0)
$00:F47F 29 F0 AND.B #$F0 ; \
$00:F481 85 00 STA $00 ; / $00 = Y position rounded down to a block row (high nibble)
$00:F483 A6 9B LDX RAM_BlockXHi ; \
$00:F485 E4 5D CPX RAM_ScreensInLvl ; } X = screen number; outside the level: no tile
$00:F487 B0 17 BCS $F4A0 ; /
$00:F489 A5 9A LDA RAM_BlockXLo ; \
$00:F48B 4A LSR ; |
$00:F48C 4A LSR ; |
$00:F48D 4A LSR ; } Column: X position / 16
$00:F48E 4A LSR ; /
$00:F48F 05 00 ORA $00 ; Row | column: offset within the screen
$00:F491 18 CLC ; \
$00:F492 7F 60 BA 00 ADC.L $BA60,X ; } Add the screen's start offset ($BA60), low byte
$00:F496 85 00 STA $00 ; /
$00:F498 A5 99 LDA RAM_BlockYHi ; \
$00:F49A 7F 9C BA 00 ADC.L $BA9C,X ; / High byte: Y high + $BA9C
$00:F49E 80 2D BRA $F4CD ; Go to the common lookup ($00F4CD)
$00:F4A0 FA PLX ; Restore X
$00:F4A1 A0 25 LDY.B #$25 ; Y = $25: empty tile
$00:F4A3 A9 00 LDA.B #$00 ; A = 0
$00:F4A5 60 RTS ; Return
$00:F4A6 A5 9B LDA RAM_BlockXHi ; \
$00:F4A8 C9 02 CMP.B #$02 ; } Vertical layer 1: X screen >= 2: outside
$00:F4AA B0 3B BCS $F4E7 ; /
$00:F4AC A6 99 LDX RAM_BlockYHi ; \
$00:F4AE E4 5D CPX RAM_ScreensInLvl ; } Y screen >= screens in level: outside
$00:F4B0 B0 35 BCS $F4E7 ; /
$00:F4B2 A5 98 LDA RAM_BlockYLo ; \
$00:F4B4 29 F0 AND.B #$F0 ; } $00 = Y position rounded down to a block row
$00:F4B6 85 00 STA $00 ; /
$00:F4B8 A5 9A LDA RAM_BlockXLo ; \
$00:F4BA 4A LSR ; |
$00:F4BB 4A LSR ; |
$00:F4BC 4A LSR ; } Column: X position / 16
$00:F4BD 4A LSR ; /
$00:F4BE 05 00 ORA $00 ; Row | column
$00:F4C0 18 CLC ; \
$00:F4C1 7F 80 BA 00 ADC.L $BA80,X ; } Add the screen's start offset ($BA80), low byte
$00:F4C5 85 00 STA $00 ; /
$00:F4C7 A5 9B LDA RAM_BlockXHi ; \
$00:F4C9 7F BC BA 00 ADC.L $BABC,X ; / High byte: X high + $BABC
$00:F4CD 85 01 STA $01 ; [$01] = high byte of the map16 pointer
$00:F4CF A9 7E LDA.B #$7E ; \
$00:F4D1 85 02 STA $02 ; / [$02] = $7E
$00:F4D3 A7 00 LDA [$00] ; A = low byte of the map16 number
$00:F4D5 8D 93 16 STA.W $1693 ; [$1693] = tile number
$00:F4D8 E6 02 INC $02 ; [$02] = $7F: the high-byte table
$00:F4DA FA PLX ; Restore X
$00:F4DB A7 00 LDA [$00] ; A = high byte of the map16 number
$00:F4DD 22 45 F5 00 JSL.L $F545 ; Adjust the tile for active switches ($F545)
$00:F4E1 AC 93 16 LDY.W $1693 ; Y = tile number
$00:F4E4 C9 00 CMP.B #$00 ; Set the flags from A
$00:F4E6 60 RTS ; Return
$00:F4E7 FA PLX ; Restore X
$00:F4E8 A0 25 LDY.B #$25 ; Y = $25: empty tile
$00:F4EA 80 B7 BRA $F4A3 ; Return A = 0 ($00F4A3)
$00:F4EC 0A ASL ; Layer 2: shift [$8E] left
$00:F4ED D0 2C BNE $F51B ; Non-zero: vertical level ($00F51B)
$00:F4EF C2 20 REP #$20 ; \
$00:F4F1 A5 98 LDA RAM_BlockYLo ; |
$00:F4F3 C9 B0 01 CMP.W #$01B0 ; |
$00:F4F6 E2 20 SEP #$20 ; } Horizontal layer 2: Y position >= $01B0: outside
$00:F4F8 B0 ED BCS $F4E7 ; /
$00:F4FA 29 F0 AND.B #$F0 ; \
$00:F4FC 85 00 STA $00 ; / $00 = Y position rounded down to a block row
$00:F4FE A6 9B LDX RAM_BlockXHi ; \
$00:F500 E0 10 CPX.B #$10 ; } X screen >= $10: outside
$00:F502 B0 E3 BCS $F4E7 ; /
$00:F504 A5 9A LDA RAM_BlockXLo ; \
$00:F506 4A LSR ; |
$00:F507 4A LSR ; |
$00:F508 4A LSR ; } Column: X position / 16
$00:F509 4A LSR ; /
$00:F50A 05 00 ORA $00 ; Row | column
$00:F50C 18 CLC ; \
$00:F50D 7F 70 BA 00 ADC.L $BA70,X ; } Add the screen's start offset ($BA70), low byte
$00:F511 85 00 STA $00 ; /
$00:F513 A5 99 LDA RAM_BlockYHi ; \
$00:F515 7F AC BA 00 ADC.L $BAAC,X ; / High byte: Y high + $BAAC
$00:F519 80 B2 BRA $F4CD ; Go to the common lookup ($00F4CD)
$00:F51B A5 9B LDA RAM_BlockXHi ; \
$00:F51D C9 02 CMP.B #$02 ; } Vertical layer 2: X screen >= 2: outside
$00:F51F B0 C6 BCS $F4E7 ; /
$00:F521 A6 99 LDX RAM_BlockYHi ; \
$00:F523 E0 0E CPX.B #$0E ; } Y screen >= $0E: outside
$00:F525 B0 C0 BCS $F4E7 ; /
$00:F527 A5 98 LDA RAM_BlockYLo ; \
$00:F529 29 F0 AND.B #$F0 ; } $00 = Y position rounded down to a block row
$00:F52B 85 00 STA $00 ; /
$00:F52D A5 9A LDA RAM_BlockXLo ; \
$00:F52F 4A LSR ; |
$00:F530 4A LSR ; |
$00:F531 4A LSR ; } Column: X position / 16
$00:F532 4A LSR ; /
$00:F533 05 00 ORA $00 ; Row | column
$00:F535 18 CLC ; \
$00:F536 7F 8E BA 00 ADC.L $BA8E,X ; } Add the screen's start offset ($BA8E), low byte
$00:F53A 85 00 STA $00 ; /
$00:F53C A5 9B LDA RAM_BlockXHi ; \
$00:F53E 7F CA BA 00 ADC.L $BACA,X ; / High byte: X high + $BACA
$00:F542 4C CD F4 JMP.W $F4CD ; Go to the common lookup ($00F4CD)
;Various map16 behavor stuff here.
$00:F545 A8 TAY ; Y = high byte of the map16 number
$00:F546 D0 2F BNE $F577 ; Non-zero: go to $00F577
$00:F548 AC 93 16 LDY.W $1693 ; Y = tile number ([$1693])
$00:F54B C0 29 CPY.B #$29 ; \
$00:F54D D0 0B BNE PSwitchNotInvQBlk ; / Not tile $29 (invisible POW block)?
$00:F54F AC AD 14 LDY.W RAM_BluePowTimer ; \
$00:F552 F0 40 BEQ $F594 ; / Blue POW timer is zero: return
$00:F554 A9 24 LDA.B #$24 ; \
$00:F556 8D 93 16 STA.W $1693 ; / POW active: tile becomes $24
$00:F559 6B RTL ; Return
;;; $F55A: P-switch: coin and switch palace tiles (PSwitchNotInvQBlk) ;;;
;; Tile $2B (coin) goes to PSwitchCoinBrown; tiles $EC-$FB set [$1423] and become a brown block ($32); others
;; return with A = 0.
$00:F55A C0 2B CPY.B #$2B ; \
$00:F55C F0 0E BEQ PSwitchCoinBrown ; / Tile $2B (coin): go to PSwitchCoinBrown
$00:F55E 98 TYA ; \
$00:F55F 38 SEC ; |
$00:F560 E9 EC SBC.B #$EC ; |
$00:F562 C9 10 CMP.B #$10 ; } Tiles $EC-$FB only; others return with A = 0
$00:F564 B0 2C BCS $F592 ; /
$00:F566 1A INC A ; \
$00:F567 8D 23 14 STA.W $1423 ; / [$1423] = tile - $EC + 1 (switch palace color)
$00:F56A 80 05 BRA $F571 ; Make it a brown block
;;; $F56C: P-switch tile swaps and fall-off kill (PSwitchCoinBrown) ;;;
;; PSwitchCoinBrown: coin becomes a brown block ($32) while the blue POW is active.
;; $00F577: high byte non-zero: brown block becomes a coin while blue POW is active; muncher becomes a coin
;; while the silver POW is active.
;; $00F595: called each frame: stops Mario rising more than $80 pixels above the screen, kills him (or
;; finishes the level via $00C95B in special
;; levels, [$1B95]) when he is more than a screen below.
$00:F56C AC AD 14 LDY.W RAM_BluePowTimer ; \
$00:F56F F0 23 BEQ $F594 ; / POW not active: return
$00:F571 A9 32 LDA.B #$32 ; \
$00:F573 8D 93 16 STA.W $1693 ; / Tile = $32 (brown block)
$00:F576 6B RTL ; Return
$00:F577 AC 93 16 LDY.W $1693 ; Y = tile number
$00:F57A C0 32 CPY.B #$32 ; \
$00:F57C D0 06 BNE $F584 ; / Tile $32 (brown block)?
$00:F57E AC AD 14 LDY.W RAM_BluePowTimer ; \
$00:F581 D0 0A BNE $F58D ; / Blue POW active: make it a coin ($00F58D)
$00:F583 6B RTL ; Return
$00:F584 C0 2F CPY.B #$2F ; \
$00:F586 D0 0C BNE $F594 ; / Tile $2F (muncher)? No: return
$00:F588 AC AE 14 LDY.W RAM_SilverPowTimer ; \
$00:F58B F0 07 BEQ $F594 ; / Silver POW timer is zero: return
$00:F58D A0 2B LDY.B #$2B ; \
$00:F58F 8C 93 16 STY.W $1693 ; / Tile = $2B (coin)
$00:F592 A9 00 LDA.B #$00 ; A = 0
$00:F594 6B RTL ; Return
$00:F595 C2 20 REP #$20 ; A 16-bit
$00:F597 A9 80 FF LDA.W #$FF80 ; \
$00:F59A 18 CLC ; } A = Y position of screen top - $80
$00:F59B 65 1C ADC RAM_ScreenBndryYLo ; /
$00:F59D C5 96 CMP RAM_MarioYPos ; \
$00:F59F 30 02 BMI $F5A3 ; / Mario is below that line: fine
$00:F5A1 85 96 STA RAM_MarioYPos ; Clamp: Mario Y = top of screen - $80
$00:F5A3 E2 20 SEP #$20 ; A 8-bit
$00:F5A5 A5 81 LDA $81 ; \
$00:F5A7 3A DEC A ; } [$81] = 0 (Mario is not below the screen): return
$00:F5A8 30 0C BMI $F5B6 ; /
$00:F5AA AD 95 1B LDA.W $1B95 ; \
$00:F5AD F0 03 BEQ $F5B2 ; / [$1B95] zero: kill Mario
$00:F5AF 4C 5B C9 JMP.W $C95B ; Special case: finish the level instead ($00C95B)
$00:F5B2 22 0A F6 00 JSL.L $F60A ; Kill Mario without the upward speed ($F60A)
$00:F5B6 60 RTS ; Return
;;; $F5B7: Hurt Mario (HurtMario) ;;;
;; Ignored during an animation, flashing, star power or level end. Small Mario dies, cape Mario soaring loses
;; the soaring, others power down.
;; Called by:
;; $00:F159: Block interaction: hurt tiles, bounce blocks, coins
;; $01:A917: Mario-sprite contact: stomp, kick, hurt (ReturnNoContact2)
;; $01:B101: Cheep Cheep main (Fish)
;; $01:D319: Koopa Kid boss: landing, stomp, fireballs
;; $01:E604: Dry Bones/Bony Beetle: collapse, walk, hurt
;; $01:FD05: Iggy/Larry: tilting-platform Koopaling (PlatformKoopaKids)
;; $02:8CF6: Minor extended sprite 0A: Boo stream (BooStreamTiles)
;; $02:A4AE: Extended sprite: smoke puff, contact with Mario (SmokePuff)
;; $02:C815: Chuck: interact with Mario
;; $02:D4D7: Layer 3 smash: states and Mario collision (Layer3SmashPtrs)
;; $02:F296: Wiggler draw, contact and flower spawn (WigglerTiles)
;; $02:F9FA: Sumo Bro flame: contact with Mario
;; ... and 8 more
$00:F5B7 A5 71 LDA RAM_MarioAnimation ; \
$00:F5B9 D0 6D BNE $F628 ; / Return if an animation is running
$00:F5BB AD 97 14 LDA.W $1497 ; \
$00:F5BE 0D 90 14 ORA.W $1490 ; |
$00:F5C1 0D 93 14 ORA.W $1493 ; } Return if flashing ([$1497]), star ([$1490]) or level ending ([$1493])
$00:F5C4 D0 62 BNE $F628 ; /
$00:F5C6 9C E3 18 STZ.W $18E3 ; [$18E3] = 0
$00:F5C9 AD E3 13 LDA.W RAM_WallWalkStatus ; \
$00:F5CC F0 07 BEQ $F5D5 ; / Not wall-walking: skip
$00:F5CE 8B PHB ; \
$00:F5CF 4B PHK ; } Data bank = $00
$00:F5D0 AB PLB ; /
$00:F5D1 20 42 EB JSR.W $EB42 ; Stop wall-walking ($EB42)
$00:F5D4 AB PLB ; Restore data bank
$00:F5D5 A5 19 LDA RAM_MarioPowerUp ; \
$00:F5D7 F0 2D BEQ KillMario ; / Small Mario: kill him
$00:F5D9 C9 02 CMP.B #$02 ; \
$00:F5DB D0 16 BNE PowerDown ; / Not cape Mario: power down
$00:F5DD AD 07 14 LDA.W $1407 ; \
$00:F5E0 F0 11 BEQ PowerDown ; / Cape Mario that is not soaring ([$1407] = 0): power down
;;; $F5E2: Hurt: cape soaring ends (CancelSoaring) ;;;
;; Plays a sound, sets the spin jump flag and a flashing timer of $30 and clears the cape status.
$00:F5E2 A0 0F LDY.B #$0F ; \
$00:F5E4 8C F9 1D STY.W $1DF9 ; / Play sound effect $0F (soaring ends)
$00:F5E7 A9 01 LDA.B #$01 ; \
$00:F5E9 8D 0D 14 STA.W RAM_IsSpinJump ; / [RAM_IsSpinJump] = 1
$00:F5EC A9 30 LDA.B #$30 ; \
$00:F5EE 8D 97 14 STA.W $1497 ; / Flashing timer [$1497] = $30
$00:F5F1 80 2F BRA $F622 ; Common ending ($00F622)
;;; $F5F3: Hurt: shrink to small Mario (PowerDown) ;;;
;; Plays sound $04, drops the reserve item, starts animation 1, sets Mario to small and sets the hurt timer to
;; $2F.
$00:F5F3 A0 04 LDY.B #$04 ; \
$00:F5F5 8C F9 1D STY.W $1DF9 ; / Play sound effect $04 (power down)
$00:F5F8 22 08 80 02 JSL.L $8008 ; Drop the reserve item ($8008)
$00:F5FC A9 01 LDA.B #$01 ; \
$00:F5FE 85 71 STA RAM_MarioAnimation ; / Mario animation = 1 (power down)
$00:F600 64 19 STZ RAM_MarioPowerUp ; Mario power-up = 0 (small)
$00:F602 A9 2F LDA.B #$2F ; A = $2F: hurt timer
$00:F604 80 17 BRA $F61D ; Set the timers ($00F61D)
;;; $F606: Kill Mario (KillMario) ;;;
;; Mario Y speed = $90, death music, animation 9, hurt/lock timer $30, clears cape status. $00F60A is the
;; entry without the upward speed.
;; Called by:
;; $00:8E6B: Status bar: update counters and tiles (DMAdata_StBr2)
;; $00:F629: Kill Mario (KillMario)
$00:F606 A9 90 LDA.B #$90 ; \
$00:F608 85 7D STA RAM_MarioSpeedY ; / Mario Y speed = $90 (jump up)
$00:F60A A9 09 LDA.B #$09 ; \
$00:F60C 8D FB 1D STA.W $1DFB ; / Music request [$1DFB] = $09 (death)
$00:F60F A9 FF LDA.B #$FF ; \
$00:F611 8D DA 0D STA.W $0DDA ; / [$0DDA] = $FF (probably forces the music to restart)
$00:F614 A9 09 LDA.B #$09 ; \
$00:F616 85 71 STA RAM_MarioAnimation ; / Mario animation = 9 (dying)
$00:F618 9C 0D 14 STZ.W RAM_IsSpinJump ; Spin jump flag = 0
$00:F61B A9 30 LDA.B #$30 ; A = $30
$00:F61D 8D 96 14 STA.W $1496 ; [$1496] = hurt timer (A)
$00:F620 85 9D STA RAM_SpritesLocked ; Sprites locked for the same time
$00:F622 9C 07 14 STZ.W $1407 ; Cape status [$1407] = 0
$00:F625 9C 8A 18 STZ.W $188A ; [$188A] = 0
$00:F628 6B RTL ; Return
$00:F629 22 06 F6 00 JSL.L KillMario ; Kill Mario (KillMario)
;;; $F62D: Clear controller, Mario GFX DMA setup (NoButtons) ;;;
;; NoButtons: clears the controller mirrors [$15]-[$18]. $00F629 kills Mario first.
;; $00F636: builds Mario's graphics DMA list ($0D85-$0D99) from the tile words [$09]-[$0C] and sets [$0D84] =
;; $0A. Called from $E458.
;; Called by:
;; $00:96D8: Game mode 11: Mario Start, level music (MarioStartGameMode)
;; $00:9C6C: Game mode 07: title screen and demo (GAMEMODE_07)
;; $00:A1F2: Game mode 14: in level (InLevelGameMode)
;; $00:A59F: Game mode 12: prepare level (GM04Load)
;; $00:C5DB: Mario animation B: freeze with message box (UnknownAniB)
;; $00:C6E7: Mario animation C: scripted cutscene movement (UnknownAniC)
;; $00:C7FD: Mario animation 8: Yoshi wings exit (YoshiWingsAni)
;; $00:C893: Mario animation A: scripted walk, level end (EnterCastleAni)
;; $00:C8BF: Mario animation A: scripted walk, level end (EnterCastleAni)
;; $00:C915: Mario animation A: scripted walk, level end (EnterCastleAni)
;; $00:D197: Mario animation 5: horizontal pipe (DoorPipeAni)
;; $00:D203: Mario animation 6: vertical pipe (VertPipeAni)
;; ... and 3 more
$00:F62D 64 15 STZ RAM_ControllerA ; \
$00:F62F 64 16 STZ $16 ; |
$00:F631 64 17 STZ RAM_ControllerB ; } Clear the controller mirrors [$15]-[$18]
$00:F633 64 18 STZ $18 :/ ; /
$00:F635 60 RTS ; Return
$00:F636 C2 20 REP #$20 ; A 16-bit
$00:F638 A2 00 LDX.B #$00 ; X = 0 (unused)
$00:F63A A5 09 LDA $09 ; \
$00:F63C 09 00 08 ORA.W #$0800 ; |
$00:F63F C5 09 CMP $09 ; |
$00:F641 F0 01 BEQ $F644 ; } Carry = bit 11 of [$09]
$00:F643 18 CLC ; /
$00:F644 29 00 F7 AND.W #$F700 ; \
$00:F647 6A ROR ; |
$00:F648 4A LSR ; } A = ([$09] AND $F700) / 4 plus carry in bit 13, + $2000
$00:F649 69 00 20 ADC.W #$2000 ; /
$00:F64C 8D 85 0D STA.W $0D85 ; [$0D85] = DMA source for Mario graphics part 1
$00:F64F 18 CLC ; \
$00:F650 69 00 02 ADC.W #$0200 ; } [$0D8F] = [$0D85] + $0200 (second row)
$00:F653 8D 8F 0D STA.W $0D8F ; /
$00:F656 A2 00 LDX.B #$00 ; X = 0 (unused)
$00:F658 A5 0A LDA $0A ; \
$00:F65A 09 00 08 ORA.W #$0800 ; |
$00:F65D C5 0A CMP $0A ; |
$00:F65F F0 01 BEQ $F662 ; } Carry = bit 11 of [$0A]
$00:F661 18 CLC ; /
$00:F662 29 00 F7 AND.W #$F700 ; \
$00:F665 6A ROR ; |
$00:F666 4A LSR ; } A = ([$0A] AND $F700) / 4 plus carry in bit 13, + $2000
$00:F667 69 00 20 ADC.W #$2000 ; /
$00:F66A 8D 87 0D STA.W $0D87 ; [$0D87] = DMA source for Mario graphics part 2
$00:F66D 18 CLC ; \
$00:F66E 69 00 02 ADC.W #$0200 ; } [$0D91] = [$0D87] + $0200
$00:F671 8D 91 0D STA.W $0D91 ; /
$00:F674 A5 0B LDA $0B ; \
$00:F676 29 00 FF AND.W #$FF00 ; |
$00:F679 4A LSR ; |
$00:F67A 4A LSR ; |
$00:F67B 4A LSR ; } A = ([$0B] high byte) * 32 + $2000
$00:F67C 69 00 20 ADC.W #$2000 ; /
$00:F67F 8D 89 0D STA.W $0D89 ; [$0D89] = DMA source for Mario graphics part 3
$00:F682 18 CLC ; \
$00:F683 69 00 02 ADC.W #$0200 ; } [$0D93] = [$0D89] + $0200
$00:F686 8D 93 0D STA.W $0D93 ; /
$00:F689 A5 0C LDA $0C ; \
$00:F68B 29 00 FF AND.W #$FF00 ; |
$00:F68E 4A LSR ; |
$00:F68F 4A LSR ; |
$00:F690 4A LSR ; } A = ([$0C] high byte) * 32 + $2000
$00:F691 69 00 20 ADC.W #$2000 ; /
$00:F694 8D 99 0D STA.W $0D99 ; [$0D99] = DMA source for Mario graphics part 4
$00:F697 E2 20 SEP #$20 ; A 8-bit
$00:F699 A9 0A LDA.B #$0A ; \
$00:F69B 8D 84 0D STA.W $0D84 ; / [$0D84] = $0A: size of the DMA list processed by MarioGFXDMA
$00:F69E 60 RTS ; Return
;;; $F69F..F6BB: Table: vertical scroll thresholds and steps ;;;
$00:F69F .db $64,$00,$7C,$00 ; Vertical scroll: Mario screen Y: $0064 (scroll up), $007C (scroll down)
$00:F6A3 .db $00,$00,$FF,$FF ; Sign flip masks: $0000, $FFFF
$00:F6A7 .db $FD,$FF,$05,$00,$FA,$FF ; Vertical scroll step: -3 (up), +5 (down), -6 (other)
$00:F6AD .db $00,$00,$00,$00,$C0,$00 ; Vertical scroll limit: $0000, $0000, $00C0
$00:F6B3 .db $90,$00,$60,$00,$00,$00,$00,$00 ; Static camera limits: $0090, $0060, then zeros
$00:F6BB .db $00,$00,$00,$00 ; zeros (continued)
;;; $F6BF..F6C7: Table: horizontal scroll steps ;;;
$00:F6BF .db $00,$00,$FE,$FF,$02,$00,$00,$00 ; Horizontal scroll step: $0000, -2, +2 (and again)
$00:F6C7 .db $FE,$FF,$02,$00 ; -2, +2 (continued)
;;; $F6CB..F6D7: Table: static camera region values ;;;
$00:F6CB .db $00,$00,$20,$00 ; Static camera region: $0000, $0020
$00:F6CF .db $D0,$00,$00,$00,$20,$00,$D0,$00 ; Static camera values: $00D0, $0000, $0020, $00D0, $0001, $FFFF
$00:F6D7 .db $01,$00,$FF,$FF ; $0001, $FFFF (continued)
;scrolling routine:
;;; $F6DB: Scroll screen to follow Mario ;;;
;; Per-frame camera update, called via JSL from the level game modes. Builds the left/right scroll lines from
;; the dead-zone centre [$142A],
;; moves layer 1 toward Mario (horizontal and vertical), derives layer 2 scroll from it, and stores the per-
;; frame scroll deltas.
;; Writes [$1A]-[$1D] (layer 1 X/Y), [$1E]/[$20] (layer 2 X/Y), deltas [$17BC]-[$17BF], and copies the new
;; positions to [$1462]-[$1469].
;; Subroutines: $00F7F4 vertical scroll (Y = A limit), $00F8AB look-ahead adjustment. Uses tables
;; $F69F-00F6CF.
;; Called by:
;; $00:9712: Game mode 11: Mario Start, level music (MarioStartGameMode)
;; $00:9A58: Boss room frame code (bit 6 set)
;; $00:A299: Game mode 14: in level (InLevelGameMode)
$00:F6DB 8B PHB ; \
$00:F6DC 4B PHK ; } Save and set data bank = program bank ($00)
$00:F6DD AB PLB ; /
$00:F6DE C2 20 REP #$20 ; A 16-bit
$00:F6E0 AD 2A 14 LDA.W $142A ; \
$00:F6E3 38 SEC ; |
$00:F6E4 E9 0C 00 SBC.W #$000C ; } Left scroll line [$142C] = [$142A] - $0C
$00:F6E7 8D 2C 14 STA.W $142C ; /
$00:F6EA 18 CLC ; \
$00:F6EB 69 18 00 ADC.W #$0018 ; } Right scroll line [$142E] = left line + $18
$00:F6EE 8D 2E 14 STA.W $142E ; /
$00:F6F1 AD 62 14 LDA.W $1462 ; \
$00:F6F4 85 1A STA RAM_ScreenBndryXLo ; / Layer 1 X = [$1462] (previous frame position, so scrolling starts from it)
$00:F6F6 AD 64 14 LDA.W $1464 ; \
$00:F6F9 85 1C STA RAM_ScreenBndryYLo ; / Layer 1 Y = [$1464]
$00:F6FB AD 66 14 LDA.W $1466 ; \
$00:F6FE 85 1E STA $1E ; / Layer 2 X = [$1466]
$00:F700 AD 68 14 LDA.W $1468 ; \
$00:F703 85 20 STA $20 ; / Layer 2 Y = [$1468]
$00:F705 A5 5B LDA RAM_IsVerticalLvl ; \
$00:F707 4A LSR ; |
$00:F708 90 03 BCC $F70D ; } Vertical level? (bit 0 of [$5B]) If so go to $00F75C
$00:F70A 4C 5C F7 JMP.W $F75C ; /
;Horizontal level horizontal scrolling
$00:F70D A9 C0 00 LDA.W #$00C0 ; A = lowest Y the screen may scroll down to in horizontal levels
$00:F710 20 F4 F7 JSR.W $F7F4 ; Vertical scrolling
$00:F713 AC 11 14 LDY.W $1411 ; \
$00:F716 F0 42 BEQ $F75A ; / Horizontal scroll disabled ([$1411] = 0): go to layer 2 scrolling
$00:F718 A0 02 LDY.B #$02 ; Y = 2 (Mario right of the left line)
$00:F71A A5 94 LDA RAM_MarioXPos ; \
$00:F71C 38 SEC ; |
$00:F71D E5 1A SBC RAM_ScreenBndryXLo ; } [$00] = A = Mario X on screen ([94] - [$1A])
$00:F71F 85 00 STA $00 ; /
$00:F721 CD 2A 14 CMP.W $142A ; \
$00:F724 10 02 BPL $F728 ; / If Mario is right of the dead-zone centre [$142A] keep Y = 2
$00:F726 A0 00 LDY.B #$00 ; Else Y = 0 (left)
$00:F728 84 55 STY $55 ; \
$00:F72A 84 56 STY $56 ; / Scroll direction [$55] = [$56] = Y
$00:F72C 38 SEC ; \
$00:F72D F9 2C 14 SBC.W $142C,Y ; } A = distance of Mario from the left or right scroll line; zero: no scroll
$00:F730 F0 28 BEQ $F75A ; /
$00:F732 85 02 STA $02 ; [$02] = distance
$00:F734 59 A3 F6 EOR.W $F6A3,Y ; Invert by side (tables $F6A3): only scroll when Mario is beyond the line
$00:F737 10 21 BPL $F75A ; Within the dead zone: no scroll
$00:F739 20 AB F8 JSR.W $F8AB ; Look-ahead adjustment of [$02] ($00F8AB)
$00:F73C A5 02 LDA $02 ; \
$00:F73E 18 CLC ; } A = [$02] + layer 1 X
$00:F73F 65 1A ADC RAM_ScreenBndryXLo ; /
$00:F741 10 03 BPL $F746 ; Not negative: keep it
$00:F743 A9 00 00 LDA.W #$0000 ; \
$00:F746 85 1A STA RAM_ScreenBndryXLo ; / Clamp: do not scroll past the left edge (X = 0)
$00:F748 A5 5E LDA $5E ; \
$00:F74A 3A DEC A ; |
$00:F74B EB XBA ; |
$00:F74C 29 00 FF AND.W #$FF00 ; |
$00:F74F 10 03 BPL $F754 ; |
$00:F751 A9 80 00 LDA.W #$0080 ; |
$00:F754 C5 1A CMP RAM_ScreenBndryXLo ; |
$00:F756 10 02 BPL $F75A ; } Limit X to the last screen of the level ([$5E] - 1 screens, in the high byte)
$00:F758 85 1A STA RAM_ScreenBndryXLo ; /
$00:F75A 80 41 BRA $F79D ; Go to layer 2 scrolling
;Vertical Level horizontal scrolling
$00:F75C A5 5F LDA $5F ; \
$00:F75E 3A DEC A ; |
$00:F75F EB XBA ; } A = (last screen of vertical level [$5F] - 1) << 8
$00:F760 29 00 FF AND.W #$FF00 ; /
$00:F763 20 F4 F7 JSR.W $F7F4 ; Vertical scrolling
$00:F766 AC 11 14 LDY.W $1411 ; \
$00:F769 F0 32 BEQ $F79D ; / Horizontal scroll disabled: go to layer 2 scrolling
$00:F76B A0 00 LDY.B #$00 ; Y = 0 (left)
$00:F76D A5 94 LDA RAM_MarioXPos ; \
$00:F76F 38 SEC ; |
$00:F770 E5 1A SBC RAM_ScreenBndryXLo ; } [$00] = A = Mario X on screen
$00:F772 85 00 STA $00 ; /
$00:F774 CD 2A 14 CMP.W $142A ; \
$00:F777 30 02 BMI $F77B ; / Mario left of the dead-zone centre: keep Y = 0
$00:F779 A0 02 LDY.B #$02 ; Else Y = 2
$00:F77B 38 SEC ; \
$00:F77C F9 2C 14 SBC.W $142C,Y ; } [$02] = distance of Mario from the scroll line
$00:F77F 85 02 STA $02 ; /
$00:F781 59 A3 F6 EOR.W $F6A3,Y ; Invert by side
$00:F784 10 17 BPL $F79D ; Within the dead zone: no scroll
$00:F786 20 AB F8 JSR.W $F8AB ; Look-ahead adjustment ($00F8AB)
$00:F789 A5 02 LDA $02 ; \
$00:F78B 18 CLC ; } A = [$02] + layer 1 X
$00:F78C 65 1A ADC RAM_ScreenBndryXLo ; /
$00:F78E 10 03 BPL $F793 ; Not negative: keep it
$00:F790 A9 00 00 LDA.W #$0000 ; Clamp to 0 on the left
$00:F793 C9 01 01 CMP.W #$0101 ; Compare with $0101 (always less than a fixed value, so the cap is probably never hit via the branch)
$00:F796 30 03 BMI $F79B ; Branch always taken when A < $101
$00:F798 A9 00 01 LDA.W #$0100 ; Right limit = $0100
$00:F79B 85 1A STA RAM_ScreenBndryXLo ; Layer 1 X = A
;Layer 2 scrolling
$00:F79D AC 13 14 LDY.W $1413 ; \
$00:F7A0 F0 08 BEQ $F7AA ; / [$1413] = 0 (layer 2 no horizontal scroll): layer 2 X stays put
$00:F7A2 A5 1A LDA RAM_ScreenBndryXLo ; A = layer 1 X
$00:F7A4 88 DEY ; \
$00:F7A5 F0 01 BEQ $F7A8 ; / [$1413] = 1: layer 2 X = layer 1 X
$00:F7A7 4A LSR ; [$1413] = 2: layer 2 X = layer 1 X / 2
$00:F7A8 85 1E STA $1E ; Store layer 2 X
$00:F7AA AC 14 14 LDY.W $1414 ; \
$00:F7AD F0 13 BEQ $F7C2 ; / [$1414] = 0 (no vertical scroll for layer 2): leave it
$00:F7AF A5 1C LDA RAM_ScreenBndryYLo ; A = layer 1 Y
$00:F7B1 88 DEY ; \
$00:F7B2 F0 08 BEQ $F7BC ; / [$1414] = 1: layer 2 Y = layer 1 Y
$00:F7B4 4A LSR ; / 2
$00:F7B5 88 DEY ; \
$00:F7B6 F0 04 BEQ $F7BC ; / [$1414] = 2: layer 2 Y = layer 1 Y / 2
$00:F7B8 4A LSR ; \
$00:F7B9 4A LSR ; |
$00:F7BA 4A LSR ; } Else layer 2 Y = layer 1 Y / 16
$00:F7BB 4A LSR ; /
$00:F7BC 18 CLC ; \
$00:F7BD 6D 17 14 ADC.W $1417 ; / Add the layer 2 Y offset [$1417]
$00:F7C0 85 20 STA $20 ; Store layer 2 Y
$00:F7C2 E2 20 SEP #$20 ; A 8-bit
$00:F7C4 A5 1A LDA RAM_ScreenBndryXLo ; \
$00:F7C6 38 SEC ; |
$00:F7C7 ED 62 14 SBC.W $1462 ; } [$17BD] = layer 1 X scroll delta this frame
$00:F7CA 8D BD 17 STA.W $17BD ; /
$00:F7CD A5 1C LDA RAM_ScreenBndryYLo ; \
$00:F7CF 38 SEC ; |
$00:F7D0 ED 64 14 SBC.W $1464 ; } [$17BC] = layer 1 Y scroll delta this frame
$00:F7D3 8D BC 17 STA.W $17BC ; /
$00:F7D6 A5 1E LDA $1E ; \
$00:F7D8 38 SEC ; |
$00:F7D9 ED 66 14 SBC.W $1466 ; } [$17BF] = layer 2 X scroll delta (positive = scrolled left)
$00:F7DC 8D BF 17 STA.W $17BF ; /
$00:F7DF A5 20 LDA $20 ; \
$00:F7E1 38 SEC ; |
$00:F7E2 ED 68 14 SBC.W $1468 ; } [$17BE] = layer 2 Y scroll delta
$00:F7E5 8D BE 17 STA.W $17BE ; /
$00:F7E8 A2 07 LDX.B #$07 ; X = 7
$00:F7EA B5 1A LDA RAM_ScreenBndryXLo,X ; \
$00:F7EC 9D 62 14 STA.W $1462,X ; / Copy the 8 scroll position bytes [$1A]-[$21] to [$1462]-[$1469] (previous frame)
$00:F7EF CA DEX ; \
$00:F7F0 10 F8 BPL $F7EA ; / Loop for X = 7..0
$00:F7F2 AB PLB ; Restore the data bank
$00:F7F3 6B RTL ; Return long
;Vertical Scrolling
$00:F7F4 AE 12 14 LDX.W $1412 ; \
$00:F7F7 D0 01 BNE $F7FA ; / Vertical scroll disabled ([$1412] = 0): return
$00:F7F9 60 RTS ; Return
$00:F7FA 85 04 STA $04 ; [$04] = bottom limit of the screen Y (A)
$00:F7FC A0 00 LDY.B #$00 ; Y = 0 (scroll up)
$00:F7FE A5 96 LDA RAM_MarioYPos ; \
$00:F800 38 SEC ; |
$00:F801 E5 1C SBC RAM_ScreenBndryYLo ; } [$00] = A = Mario Y on screen
$00:F803 85 00 STA $00 ; /
$00:F805 C9 70 00 CMP.W #$0070 ; \
$00:F808 30 02 BMI $F80C ; / Mario above Y = $70 on screen: keep Y = 0
$00:F80A A0 02 LDY.B #$02 ; Else Y = 2 (scroll down)
$00:F80C 84 55 STY $55 ; \
$00:F80E 84 56 STY $56 ; / Scroll direction [$55] = [$56] = Y (0 up, 2 down, 4 misc)
$00:F810 38 SEC ; \
$00:F811 F9 9F F6 SBC.W $F69F,Y ; / A = Mario screen Y - $64 (up) or - $7C (down)
$00:F814 85 02 STA $02 ; [$02] = A
$00:F816 59 A3 F6 EOR.W $F6A3,Y ; Invert by direction
$00:F819 30 04 BMI $F81F ; Beyond the threshold: go on to scroll
$00:F81B A0 02 LDY.B #$02 ; Y = 2 (down)
$00:F81D 64 02 STZ $02 ; [$02] = 0 (no scroll)
$00:F81F A5 02 LDA $02 ; \
$00:F821 30 07 BMI $F82A ; / [$02] negative: go to $00F82A
$00:F823 A2 00 LDX.B #$00 ; \
$00:F825 8E 04 14 STX.W $1404 ; / Clear free vertical scroll [$1404]
$00:F828 80 59 BRA $F883 ; Go to $00F883
$00:F82A E2 20 SEP #$20 ; A 8-bit
$00:F82C AD E3 13 LDA.W RAM_WallWalkStatus ; \
$00:F82F C9 06 CMP.B #$06 ; / Wall-run status [$13E3] >= 6: go to $00F845 with A = it
$00:F831 B0 12 BCS $F845 ; Branch if wall running
$00:F833 AD 10 14 LDA.W RAM_YoshiHasWingsB ; \
$00:F836 4A LSR ; / Winged Yoshi ([$1410] >> 1)
$00:F837 0D 9F 14 ORA.W $149F ; OR fly timer [$149F]
$00:F83A 05 74 ORA RAM_IsClimbing ; OR climbing flag
$00:F83C 0D F3 13 ORA.W $13F3 ; OR P-balloon [$13F3]
$00:F83F 0D C2 18 ORA.W $18C2 ; OR riding Lakitu cloud [$18C2]
$00:F842 0D 06 14 ORA.W $1406 ; OR springboard/trampoline flag [$1406]
$00:F845 AA TAX ; X = combined flags (non-zero = keep scrolling up freely)
$00:F846 C2 20 REP #$20 ; A 16-bit
$00:F848 D0 1F BNE $F869 ; Flags set: go to $00F869
$00:F84A AE 7A 18 LDX.W RAM_OnYoshi ; \
$00:F84D F0 07 BEQ $F856 ; |
$00:F84F AE 1E 14 LDX.W RAM_YoshiHasWings ; |
$00:F852 E0 02 CPX.B #$02 ; } On Yoshi: wings [$141E] >= 2: go to $00F869
$00:F854 B0 13 BCS $F869 ; /
$00:F856 A6 75 LDX RAM_IsSwimming ; \
$00:F858 F0 04 BEQ $F85E ; |
$00:F85A A6 72 LDX RAM_IsFlying ; } Swimming: allow scroll up unless in the air ([$72]) then go to $00F869
$00:F85C D0 0B BNE $F869 ; /
$00:F85E AE 12 14 LDX.W $1412 ; \
$00:F861 CA DEX ; } [$1412] = 1: go to $00F875
$00:F862 F0 11 BEQ $F875 ; /
$00:F864 AE F1 13 LDX.W $13F1 ; \
$00:F867 D0 0C BNE $F875 ; / Vertical scroll enable flag [$13F1] set: go to $00F875
$00:F869 8E F1 13 STX.W $13F1 ; [$13F1] = X
$00:F86C AE F1 13 LDX.W $13F1 ; \
$00:F86F D0 10 BNE $F881 ; / [$13F1] non-zero: continue at $00F881
$00:F871 A0 04 LDY.B #$04 ; Y = 4 (misc scroll up)
$00:F873 80 0C BRA $F881 ; Continue at $00F881
$00:F875 AE 04 14 LDX.W $1404 ; \
$00:F878 D0 07 BNE $F881 ; / Free scroll [$1404] set: continue
$00:F87A A6 72 LDX RAM_IsFlying ; \
$00:F87C D0 2C BNE $F8AA ; / In the air: return without scrolling
$00:F87E EE 04 14 INC.W $1404 ; Enable free vertical scroll [$1404]
$00:F881 A5 02 LDA $02 ; A = [$02]
$00:F883 38 SEC ; \
$00:F884 F9 A7 F6 SBC.W $F6A7,Y ; / A - $F6A7[Y] ($FFFD up, $0005 down, $FFFA misc)
$00:F887 59 A7 F6 EOR.W $F6A7,Y ; EOR with the same value to test for overshoot
$00:F88A 0A ASL ; Shift sign into carry
$00:F88B A5 02 LDA $02 ; A = [$02]
$00:F88D B0 03 BCS $F892 ; Overshoot: use [$02]
$00:F88F B9 A7 F6 LDA.W $F6A7,Y ; Else use the table value (limit)
$00:F892 18 CLC ; Add to screen Y
$00:F893 65 1C ADC RAM_ScreenBndryYLo ;/
$00:F895 D9 AD F6 CMP.W $F6AD,Y ; Compare with the minimum Y ($0000, or $00C0 for misc)
$00:F898 10 03 BPL $F89D ; Not below it: keep
$00:F89A B9 AD F6 LDA.W $F6AD,Y ; Else clamp to the minimum
$00:F89D 85 1C STA RAM_ScreenBndryYLo ; Layer 1 Y = A
$00:F89F A5 04 LDA $04 ; \
$00:F8A1 C5 1C CMP RAM_ScreenBndryYLo ; / Past the bottom limit [$04]?
$00:F8A3 10 05 BPL $F8AA ; No: return
$00:F8A5 85 1C STA RAM_ScreenBndryYLo ; Clamp layer 1 Y to the limit
$00:F8A7 9C F1 13 STZ.W $13F1 ; Clear [$13F1] (and [$13F2], A is 16-bit)
$00:F8AA 60 RTS ; Return
$00:F8AB AC FD 13 LDY.W $13FD ; \
$00:F8AE D0 2E BNE $F8DE ; / Camera look-ahead: L/R button scroll [$13FD] active: return
$00:F8B0 E2 20 SEP #$20 ; A 8-bit
$00:F8B2 AE FF 13 LDX.W $13FF ; X = Mario facing direction [$13FF]
$00:F8B5 C2 20 REP #$20 ; A 16-bit
$00:F8B7 A0 08 LDY.B #$08 ; Y = 8
$00:F8B9 AD 2A 14 LDA.W $142A ; \
$00:F8BC DD B3 F6 CMP.W $F6B3,X ; } Compare dead-zone centre [$142A] with $F6B3[facing]
$00:F8BF 10 02 BPL $F8C3 ; /
$00:F8C1 A0 0A LDY.B #$0A ; Else Y = $0A
$00:F8C3 B9 BF F6 LDA.W $F6BF,Y ; A = $F6BF[Y]
$00:F8C6 45 02 EOR $02 ; Same sign as the distance [$02]?
$00:F8C8 10 14 BPL $F8DE ; Yes: return
$00:F8CA BD BF F6 LDA.W $F6BF,X ; A = $F6BF[X]
$00:F8CD 45 02 EOR $02 ; Same sign as [$02]?
$00:F8CF 10 0D BPL $F8DE ; Yes: return
$00:F8D1 A5 02 LDA $02 ; \
$00:F8D3 18 CLC ; } [$02] += $F6CF[Y]
$00:F8D4 79 CF F6 ADC.W $F6CF,Y ; /
$00:F8D7 F0 05 BEQ $F8DE ; Zero: return
$00:F8D9 85 02 STA $02 ; Store the adjusted distance
$00:F8DB 8C 00 14 STY.W $1400 ; [$1400] = Y (remember the look-ahead adjustment)
$00:F8DE 60 RTS ; Return
;;; $F8DF..F8E7: Table: Y tile offsets by platform tilt ;;;
$00:F8DF .db $0C,$0C,$08,$00,$20,$04,$0A,$0D ; Offsets indexed by (tilt + $48) >> 4: $0C,$0C,$08,$00,$20,$04,$0A,$0D,$0D
$00:F8E7 .db $0D
;;; $F8E8..F8F0: Table: Mario ceiling Y limit per boss room ;;;
;; 16-bit words indexed by [$13FC] * 2: $002A, $002A, $0012, $0000, $FFED. Entry $2A also enables extra checks
;; in the routine at $00F8F2.
$00:F8E8 .db $2A,$00,$2A,$00,$12,$00,$00,$00 ; $13FC = 0: Y limit $2A
$00:F8F0 .db $ED,$FF
;;; $F8F2: Mario vs Mode 7 boss room platform/ceiling ;;;
;; Called from Mario's per-frame code ($00CD1F) in Mode 7 boss rooms. If [$0D9B] bit 6 is set: clamps Mario's
;; Y to the ceiling limit
;; from $F8E8, then (for entry $2A) tests Mario against a boss-room object. If bit 6 is clear: tests
;; Mario against the tilting
;; platform ($00F9A8, using JSL $01:CC9D) and applies the slope/standing response. Semantics are inferred;
;; exact object not confirmed.
;; Called by:
;; $00:CD1F: Mario animation 0: normal per-frame handling (ResetAni)
$00:F8F2 20 A6 EA JSR.W $EAA6 ; Mario Y interaction setup ($EAA6)
$00:F8F5 2C 9B 0D BIT.W $0D9B ; Test [$0D9B] (V = bit 6)
$00:F8F8 50 54 BVC $F94E ; Bit 6 clear: go to $00F94E
$00:F8FA 20 2B E9 JSR.W $E92B ; Run $E92B
$00:F8FD AD FC 13 LDA.W $13FC ; \
$00:F900 0A ASL ; } X = [$13FC] * 2 (room index)
$00:F901 AA TAX ; /
$00:F902 DA PHX ; Save X
$00:F903 A4 7D LDY RAM_MarioSpeedY ; Y = Mario Y speed
$00:F905 10 17 BPL $F91E ; Not moving up: skip the ceiling clamp
$00:F907 C2 20 REP #$20 ; A 16-bit
$00:F909 A5 96 LDA RAM_MarioYPos ; A = Mario Y
$00:F90B DD E8 F8 CMP.W $F8E8,X ; Compare with the ceiling limit
$00:F90E 10 0E BPL $F91E ; Below the limit: skip
$00:F910 BD E8 F8 LDA.W $F8E8,X ; Mario Y = ceiling limit
$00:F913 85 96 STA RAM_MarioYPos
$00:F915 E2 20 SEP #$20 ; A 8-bit
$00:F917 64 7D STZ RAM_MarioSpeedY ; Mario Y speed = 0
$00:F919 A9 01 LDA.B #$01 ; SFX $01 (hit head)
$00:F91B 8D F9 1D STA.W $1DF9 ; / Play sound effect
$00:F91E E2 20 SEP #$20 ; A 8-bit
$00:F920 FA PLX ; Restore X
$00:F921 BD E8 F8 LDA.W $F8E8,X ; A = low byte of the limit
$00:F924 C9 2A CMP.B #$2A ; Is it $2A?
$00:F926 D0 25 BNE $F94D ; No: return
$00:F928 C2 20 REP #$20 ; A 16-bit
$00:F92A A0 00 LDY.B #$00 ; Y = 0
$00:F92C AD 17 16 LDA.W $1617 ; A = [$1617] & $FF + 1
$00:F92F 29 FF 00 AND.W #$00FF
$00:F932 1A INC A
$00:F933 C5 94 CMP RAM_MarioXPos ; Compare with Mario X
$00:F935 F0 13 BEQ $F94A ; Equal: go to $00F94A
$00:F937 30 11 BMI $F94A ; A < Mario X: go to $00F94A
$00:F939 AD 3D 15 LDA.W $153D ; A = [$153D] & $FF
$00:F93C 29 FF 00 AND.W #$00FF
$00:F93F 85 00 STA $00 ; [$00] = it
$00:F941 C8 INY ; Y = 1
$00:F942 A5 94 LDA RAM_MarioXPos ; A = Mario X + $0F
$00:F944 18 CLC
$00:F945 69 0F 00 ADC.W #$000F
$00:F948 C5 00 CMP $00 ; Compare with [$00] (result used by $E9C8)
$00:F94A 4C C8 E9 JMP.W $E9C8 ; Continue at $E9C8
$00:F94D 60 RTS ; Return
$00:F94E A0 00 LDY.B #$00 ; Y = 0
$00:F950 A5 7D LDA RAM_MarioSpeedY ; A = Mario Y speed
$00:F952 10 03 BPL $F957 ; Falling or standing: go to $00F957
$00:F954 4C 97 F9 JMP.W $F997 ; Moving up: skip to $00F997
$00:F957 20 A8 F9 JSR.W $F9A8 ; Test Mario against the platform ($00F9A8)
$00:F95A B0 06 BCS $F962 ; Carry set (touching): go to $00F962
$00:F95C 20 1D EE JSR.W $EE1D ; Not touching: $EE1D
$00:F95F 4C 97 F9 JMP.W $F997 ; Go to $00F997
$00:F962 A5 72 LDA RAM_IsFlying ; Mario in the air?
$00:F964 F0 1D BEQ $F983 ; No: go to $00F983
$00:F966 C2 20 REP #$20 ; A 16-bit
$00:F968 AD B8 14 LDA.W $14B8 ; A = [$14B8] & $FF (contact X)
$00:F96B 29 FF 00 AND.W #$00FF
$00:F96E 8D B4 14 STA.W $14B4 ; [$14B4] = A
$00:F971 8D 36 14 STA.W RAM_KeyHolePos1 ; KeyHolePos1 ([$1436]) = A
$00:F974 AD BA 14 LDA.W $14BA ; A = [$14BA] & $F0 (contact Y)
$00:F977 29 F0 00 AND.W #$00F0
$00:F97A 8D B6 14 STA.W $14B6 ; [$14B6] = A
$00:F97D 8D 38 14 STA.W RAM_KeyHolePos2 ; KeyHolePos2 ([$1438]) = A
$00:F980 20 C9 F9 JSR.W $F9C9 ; Run the mirrored test ($00F9C9)
$00:F983 A5 36 LDA $36 ; A = [$36] (platform tilt)
$00:F985 18 CLC ; + $48
$00:F986 69 48 ADC.B #$48
$00:F988 4A LSR
$00:F989 4A LSR
$00:F98A 4A LSR
$00:F98B 4A LSR
$00:F98C AA TAX ; X = (tilt + $48) >> 4
$00:F98D BC DF F8 LDY.W $F8DF,X ; Y = $F8DF[X]
$00:F990 A9 80 LDA.B #$80 ; [$8E] = $80
$00:F992 85 8E STA $8E
$00:F994 20 E1 EE JSR.W $EEE1 ; Apply slope response ($EEE1)
$00:F997 C2 20 REP #$20 ; A 16-bit
$00:F999 A5 80 LDA $80 ; A = [$80]
$00:F99B C9 AE 00 CMP.W #$00AE ; Compare with $00AE
$00:F99E E2 20 SEP #$20 ; A 8-bit
$00:F9A0 30 03 BMI $F9A5 ; Less: skip
$00:F9A2 20 29 F6 JSR.W $F629 ; Unreachable: JSR $F629
$00:F9A5 4C 8C E9 JMP.W $E98C ; Continue at $E98C
$00:F9A8 C2 20 REP #$20 ; A 16-bit
$00:F9AA A5 94 LDA RAM_MarioXPos ; \
$00:F9AC 18 CLC ; |
$00:F9AD 69 08 00 ADC.W #$0008 ; } [$14B4] = Mario X + 8
$00:F9B0 8D B4 14 STA.W $14B4 ; /
$00:F9B3 A5 96 LDA RAM_MarioYPos ; \
$00:F9B5 18 CLC ; |
$00:F9B6 69 20 00 ADC.W #$0020 ; } [$14B6] = Mario Y + $20
$00:F9B9 8D B6 14 STA.W $14B6 ; /
$00:F9BC E2 20 SEP #$20 ; A 8-bit
$00:F9BE 8B PHB ; \
$00:F9BF A9 01 LDA.B #$01 ; |
$00:F9C1 48 PHA ; } Data bank = $01
$00:F9C2 AB PLB ; /
$00:F9C3 22 9D CC 01 JSL.L $CC9D ; Platform collision test in bank 01 (carry = touching)
$00:F9C7 AB PLB ; Restore the data bank
$00:F9C8 60 RTS ; Return
$00:F9C9 A5 36 LDA $36 ; A = [$36] (tilt)
$00:F9CB 48 PHA ; Save it
$00:F9CC 49 FF FF EOR.W #$FFFF ; \
$00:F9CF 1A INC A ; } [$36] = -[$36] (mirror the tilt)
$00:F9D0 85 36 STA $36 ; /
$00:F9D2 20 BC F9 JSR.W $F9BC ; Run the platform test with the mirrored tilt ($00F9BC)
$00:F9D5 C2 20 REP #$20 ; A 16-bit
$00:F9D7 68 PLA ; Restore the tilt
$00:F9D8 85 36 STA $36 ; [$36] = original
$00:F9DA AD B8 14 LDA.W $14B8 ; A = [$14B8] & $FF
$00:F9DD 29 FF 00 AND.W #$00FF
$00:F9E0 38 SEC ; - 8
$00:F9E1 E9 08 00 SBC.W #$0008
$00:F9E4 85 94 STA RAM_MarioXPos ; Mario X = result
$00:F9E6 AD BA 14 LDA.W $14BA ; A = [$14BA] & $FF
$00:F9E9 29 FF 00 AND.W #$00FF
$00:F9EC 38 SEC ; - $20
$00:F9ED E9 20 00 SBC.W #$0020
$00:F9F0 85 96 STA RAM_MarioYPos ; Mario Y = result
$00:F9F2 E2 20 SEP #$20 ; A 8-bit
$00:F9F4 60 RTS ; Return
;;; $F9F5..FA0D: Freespace ;;;
$00:F9F5 .db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
$00:F9FD .db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
$00:FA05 .db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
$00:FA0D .db $FF,$FF,$FF
;;; $FA10: Unused clear sprites, then slope pointer setup ;;;
;; $00FA10: Unused. Clears the 12 sprite status bytes and returns (RTL).
;; $00FA19: sets up a long pointer in [$05]-[$07] ($00:E632, probably a slope steepness table), reads
;; [[$82]+A-$6E] into [$08],
;; and returns Y = (([$0A] & 15) | (value * 16 low byte)) as an index. Called from sprite code in banks 01 and
;; 02 (JSL).
;; Parameters: A = tile number ($6E-$D5 range). Returns: Y = index; [$00] = [$0C] & 15, [$01] = value * 16.
$00:FA10 A2 0B LDX.B #$0B ; \
$00:FA12 9E C8 14 STZ.W $14C8,X ; |
$00:FA15 CA DEX ; } Unused: clear the 12 sprite status bytes
$00:FA16 10 FA BPL $FA12 ; /
$00:FA18 6B RTL ; Return long
$00:FA19 A0 32 LDY.B #$32 ; \
$00:FA1B 84 05 STY $05 ; |
$00:FA1D A0 E6 LDY.B #$E6 ; |
$00:FA1F 84 06 STY $06 ; |
$00:FA21 A0 00 LDY.B #$00 ; } [$05]-[$07] = $00E632 (long pointer, probably slope data)
$00:FA23 84 07 STY $07 ; /
$00:FA25 38 SEC ; \
$00:FA26 E9 6E SBC.B #$6E ; } Y = A - $6E
$00:FA28 A8 TAY ; /
$00:FA29 B7 82 LDA [$82],Y ; A = [[$82] + Y]
$00:FA2B 85 08 STA $08 ; [$08] = A
$00:FA2D 0A ASL ; \
$00:FA2E 0A ASL ; |
$00:FA2F 0A ASL ; } A *= 16
$00:FA30 0A ASL ; /
$00:FA31 85 01 STA $01 ; [$01] = A * 16 (low byte)
$00:FA33 90 02 BCC $FA37 ; No carry: skip
$00:FA35 E6 06 INC $06 ; Carry: [$06]++ (pointer high byte)
$00:FA37 A5 0C LDA $0C ; \
$00:FA39 29 0F AND.B #$0F ; } [$00] = [$0C] & $0F
$00:FA3B 85 00 STA $00 ; /
$00:FA3D A5 0A LDA $0A ; \
$00:FA3F 29 0F AND.B #$0F ; } A = ([$0A] & $0F) | [$01]
$00:FA41 05 01 ORA $01 ; /
$00:FA43 A8 TAY ; Y = A (index)
$00:FA44 6B RTL ; Return long
;;; $FA45: Spawn Flat Palace Switch (FlatPalaceSwitch) ;;;
;; Starts the ground shake and creates the Flat Palace Switch (sprite $60) in slot 2 at the position of the
;; block Mario hit.
;; Position: X = [$9A] & $F0 (+[$9B]), Y = ([$98] & $F0) + $10 (+[$99] + carry). Sets status 8 and the timer
;; [$1540,Y] = $5F.
;; Called by:
;; $00:EEBE: Mario block and slope collision (rest)
$00:FA45 A9 20 LDA.B #$20 ; Ground shake timer = $20
$00:FA47 8D 87 18 STA.W RAM_ShakeGrndTimer ; /
$00:FA4A A0 02 LDY.B #$02 ; Y = 2: sprite slot 2
$00:FA4C A9 60 LDA.B #$60 ; Sprite number $60 (Flat Palace Switch)
$00:FA4E 99 9E 00 STA.W RAM_SpriteNum,Y ; /
$00:FA51 A9 08 LDA.B #$08 ; Status 8 (normal)
$00:FA53 99 C8 14 STA.W $14C8,Y ; /
$00:FA56 A5 9A LDA RAM_BlockXLo ; \
$00:FA58 29 F0 AND.B #$F0 ; } Sprite X low = block X [$9A] & $F0
$00:FA5A 99 E4 00 STA.W RAM_SpriteXLo,Y ; /
$00:FA5D A5 9B LDA RAM_BlockXHi ; Sprite X high = block X high [$9B]
$00:FA5F 99 E0 14 STA.W RAM_SpriteXHi,Y ; /
$00:FA62 A5 98 LDA RAM_BlockYLo ; \
$00:FA64 29 F0 AND.B #$F0 ; |
$00:FA66 18 CLC ; |
$00:FA67 69 10 ADC.B #$10 ; } Sprite Y low = ([$98] & $F0) + $10
$00:FA69 99 D8 00 STA.W RAM_SpriteYLo,Y ; /
$00:FA6C A5 99 LDA RAM_BlockYHi ; \
$00:FA6E 69 00 ADC.B #$00 ; } Sprite Y high = [$99] + carry
$00:FA70 99 D4 14 STA.W RAM_SpriteYHi,Y ; /
$00:FA73 DA PHX ; Save X
$00:FA74 BB TYX ; X = Y (sprite slot)
$00:FA75 22 D2 F7 07 JSL.L InitSpriteTables ; Initialise the sprite tables
$00:FA79 FA PLX ; Restore X
$00:FA7A A9 5F LDA.B #$5F ; Timer [$1540,Y] = $5F
$00:FA7C 99 40 15 STA.W $1540,Y ; /
$00:FA7F 60 RTS ; Return
;;; $FA80: Level end: clear effects, start sprite loop (TriggerGoalTape) ;;;
;; Clears P-balloon [$13F3], [$1891], sprite respawn timer, generator number and [$18DD], then falls into the
;; sprite loop below.
;; Called by:
;; $01:C128: Goal tape movement, check and draw
$00:FA80 9C F3 13 STZ.W $13F3 ; [$13F3] = 0 (P-balloon off)
$00:FA83 9C 91 18 STZ.W $1891 ; [$1891] = 0
$00:FA86 9C C0 18 STZ.W RAM_TimeTillRespawn ; Respawn timer = 0: do not respawn sprites
$00:FA89 9C B9 18 STZ.W RAM_GeneratorNum ; Generator number = 0
$00:FA8C 9C DD 18 STZ.W $18DD ; [$18DD] = 0
$00:FA8F A0 0B LDY.B #$0B ; Y = 11: loop over sprites
;;; $FA91: Level end: process every sprite (LvlEndSprLoopStrt) ;;;
;; Loops over sprite slots 11..0. Sprites with status < 8 are skipped. A sprite carried by Mario (status $0B)
;; becomes a powerup.
;; Goal tape, and on-screen sprites without tweaker bit $20 in [$1686], become status 6 (turn into coin).
;; Others are erased unless
;; tweaker bit 1 of [$190F] (don't erase) is set. Afterwards all 8 extended sprites are cleared.
$00:FA91 B9 C8 14 LDA.W $14C8,Y ; A = sprite status
$00:FA94 C9 08 CMP.B #$08 ; Status < 8: skip the sprite
$00:FA96 90 39 BCC LvlEndNextSprite ; /
$00:FA98 C9 0B CMP.B #$0B ; Status $0B (carried past the goal)?
$00:FA9A D0 07 BNE $FAA3 ; No: go to $00FAA3
$00:FA9C DA PHX ; Save X
$00:FA9D 20 00 FB JSR.W LvlEndPowerUp ; Turn the sprite into a powerup
$00:FAA0 FA PLX ; Restore X
$00:FAA1 80 2E BRA LvlEndNextSprite ; Next sprite
$00:FAA3 B9 9E 00 LDA.W RAM_SpriteNum,Y ; A = sprite number
$00:FAA6 C9 7B CMP.B #$7B ; Goal tape ($7B)?
$00:FAA8 F0 08 BEQ $FAB2 ; Yes: go to $00FAB2
$00:FAAA B9 A0 15 LDA.W RAM_OffscreenHorz,Y ; \
$00:FAAD 19 6C 18 ORA.W RAM_OffscreenVert,Y ; / On screen? (off-screen horizontal | vertical)
$00:FAB0 D0 13 BNE $FAC5 ; Off screen: go to $00FAC5
$00:FAB2 B9 86 16 LDA.W RAM_Tweaker1686,Y ; \
$00:FAB5 29 20 AND.B #$20 ; } Tweaker bit $20 ([$1686]: don't turn into coin) set: go to $00FAC5
$00:FAB7 D0 0C BNE $FAC5 ; /
$00:FAB9 A9 10 LDA.B #$10 ; A = $10
$00:FABB 99 40 15 STA.W $1540,Y ; Coin animation timer [$1540,Y] = $10
$00:FABE A9 06 LDA.B #$06 ; A = 6
$00:FAC0 99 C8 14 STA.W $14C8,Y ; Status 6: level end, turn into coin
$00:FAC3 80 0C BRA LvlEndNextSprite ; Next sprite
$00:FAC5 B9 0F 19 LDA.W RAM_Tweaker190F,Y ; \
$00:FAC8 29 02 AND.B #$02 ; } Tweaker bit 2 ([$190F]: don't erase) set: keep sprite
$00:FACA D0 05 BNE LvlEndNextSprite ; /
$00:FACC A9 00 LDA.B #$00 ; A = 0
$00:FACE 99 C8 14 STA.W $14C8,Y ; Erase the sprite (status 0)
;;; $FAD1: Level end: next sprite, clear extended sprites (LvlEndNextSprite) ;;;
;; Decrements the sprite index and loops; when done, clears all 8 extended sprite slots and returns (RTL).
$00:FAD1 88 DEY ; Y--: next sprite
$00:FAD2 10 BD BPL LvlEndSprLoopStrt ; Loop while Y >= 0
$00:FAD4 A0 07 LDY.B #$07 ; Y = 7: extended sprites
$00:FAD6 A9 00 LDA.B #$00 ; A = 0
$00:FAD8 99 0B 17 STA.W RAM_ExSpriteNum,Y ; Clear extended sprite number
$00:FADB 88 DEY ; Y--
$00:FADC 10 FA BPL $FAD8 ; Loop
$00:FADE 6B RTL ; Return long
;;; $FADF..FAF7: Table: powerup sprite given at level end ;;;
;; 28 sprite numbers, four groups of 7 indexed by Mario powerup/state. Group 0: normal. Group 1 (+7): carrying
;; springboard or P-switch.
;; Group 2 (+14): carrying key. Group 3 (+21): carrying baby Yoshi. $74 mushroom, $75 flower, $76 star, $77
;; feather, $E0-$FF = 1-Up variants.
$00:FADF .db $74,$74,$77,$75,$76,$E0,$F0,$74 ; Group 0: normal (powerup 0-6)
$00:FAE7 .db $74,$77,$75,$76,$E0,$F1,$F0,$F0
$00:FAEF .db $F0,$F0,$F1,$E0,$F2,$E0,$E0,$E0
$00:FAF7 .db $E0,$F1,$E0,$E4
;;; $FAFB..FAFB: Table: item box contents to match ;;;
$00:FAFB .db $FF,$74,$75,$76,$77 ; $FF,$74,$75,$76,$77: item box contents (0 = empty, 1-4) compared to the result
;;; $FB00: Level end: choose bonus powerup for carried sprite (LvlEndPowerUp) ;;;
;; Used when Mario carries a sprite past the goal. Picks an index X from Mario's powerup (or Yoshi), adds
;; 7/14/21 depending on the carried
;; sprite (springboard/P-switch, key, baby Yoshi), reads $FADF, and replaces the result by a 1-Up ($78)
;; if it equals the current
;; item box contents. Values >= $E0 become a 1-Up, with the low nibble saved in [$0F]. Parameters: Y = sprite
;; slot.
;; Called by:
;; $00:FA9D: Level end: process every sprite (LvlEndSprLoopStrt)
$00:FB00 A6 19 LDX RAM_MarioPowerUp ; X = Mario powerup
$00:FB02 AD 90 14 LDA.W $1490 ; Star timer [$1490]?
$00:FB05 F0 02 BEQ $FB09 ; Zero: skip (cleared earlier, so always skipped)
$00:FB07 A2 04 LDX.B #$04 ; Unreachable: X = 4
$00:FB09 AD 7A 18 LDA.W RAM_OnYoshi ; On Yoshi?
$00:FB0C F0 02 BEQ $FB10 ; No: skip
$00:FB0E A2 05 LDX.B #$05 ; X = 5
$00:FB10 B9 9E 00 LDA.W RAM_SpriteNum,Y ; A = carried sprite number
$00:FB13 C9 2F CMP.B #$2F ; Springboard ($2F)?
$00:FB15 F0 16 BEQ $FB2D ; Yes: X += 7
$00:FB17 C9 3E CMP.B #$3E ; P-switch ($3E)?
$00:FB19 F0 12 BEQ $FB2D ; Yes: X += 7
$00:FB1B C9 80 CMP.B #$80 ; Key ($80)?
$00:FB1D F0 09 BEQ $FB28 ; Yes: X += 14
$00:FB1F C9 2D CMP.B #$2D ; Baby Yoshi ($2D)?
$00:FB21 D0 0F BNE $FB32 ; No: go to $00FB32
$00:FB23 8A TXA ; \
$00:FB24 18 CLC ; |
$00:FB25 69 07 ADC.B #$07 ; } X += 7 (baby Yoshi: three times, +21 total)
$00:FB27 AA TAX ; /
$00:FB28 8A TXA ; \
$00:FB29 18 CLC ; |
$00:FB2A 69 07 ADC.B #$07 ; } X += 7
$00:FB2C AA TAX ; /
$00:FB2D 8A TXA ; \
$00:FB2E 18 CLC ; |
$00:FB2F 69 07 ADC.B #$07 ; } X += 7
$00:FB31 AA TAX ; /
$00:FB32 BF DF FA 00 LDA.L $FADF,X ; A = $FADF[X]
$00:FB36 AE C2 0D LDX.W $0DC2 ; X = [$0DC2] (item box)
$00:FB39 DF FB FA 00 CMP.L $FAFB,X ; Same as the item box contents?
$00:FB3D D0 02 BNE $FB41 ; No: keep
$00:FB3F A9 78 LDA.B #$78 ; Yes: use $78 (1-Up) instead
$00:FB41 64 0F STZ $0F ; [$0F] = 0
$00:FB43 C9 E0 CMP.B #$E0 ; Below $E0: normal sprite
$00:FB45 90 0E BCC LvlEndStoreSpr
$00:FB47 48 PHA ; Save A
$00:FB48 29 0F AND.B #$0F ; [$0F] = low nibble
$00:FB4A 85 0F STA $0F
$00:FB4C 68 PLA ; Restore A
$00:FB4D C9 F0 CMP.B #$F0 ; $F0 or more?
$00:FB4F A9 78 LDA.B #$78 ; A = $78 (1-Up)
$00:FB51 B0 02 BCS LvlEndStoreSpr
$00:FB53 A9 78 LDA.B #$78 ; A = $78 (1-Up)
;;; $FB55: Level end: convert sprite to bonus powerup (LvlEndStoreSpr) ;;;
;; Makes sprite slot Y the chosen powerup, re-initialises it, gives it status $0C (goal tape powerup) with an
;; upward launch, plays SFX $0C
;; and spawns a smoke sprite at its position in the first free of 4 slots.
;; Parameters: A = sprite number, Y = slot, [$0F] = extra value for [$1594,Y].
$00:FB55 99 9E 00 STA.W RAM_SpriteNum,Y ; Sprite number = A
$00:FB58 C9 76 CMP.B #$76 ; Star ($76)?
$00:FB5A D0 03 BNE $FB5F ; No: skip
$00:FB5C EE CB 13 INC.W $13CB ; [$13CB]++
$00:FB5F BB TYX ; X = Y (sprite slot)
$00:FB60 22 D2 F7 07 JSL.L InitSpriteTables ; Initialise the sprite tables
$00:FB64 A5 0F LDA $0F ; A = [$0F]
$00:FB66 99 94 15 STA.W $1594,Y ; [$1594,Y] = [$0F]
$00:FB69 A9 0C LDA.B #$0C ; A = $0C
$00:FB6B 99 C8 14 STA.W $14C8,Y ; Status $0C: goal tape powerup
$00:FB6E A9 D0 LDA.B #$D0 ; A = $D0
$00:FB70 99 AA 00 STA.W RAM_SpriteSpeedY,Y ; Sprite Y speed = $D0 (up)
$00:FB73 A9 05 LDA.B #$05 ; A = 5
$00:FB75 99 B6 00 STA.W RAM_SpriteSpeedX,Y ; Sprite X speed = 5
$00:FB78 A9 20 LDA.B #$20 ; A = $20
$00:FB7A 99 4C 15 STA.W RAM_DisableInter,Y ; Interaction disabled for $20 frames
$00:FB7D A9 0C LDA.B #$0C ; A = $0C
$00:FB7F 8D F9 1D STA.W $1DF9 ; Play SFX $0C
$00:FB82 A2 03 LDX.B #$03 ; X = 3: smoke sprite slots
$00:FB84 BD C0 17 LDA.W $17C0,X ; Slot free ([$17C0,X] = 0)?
$00:FB87 F0 04 BEQ $FB8D ; Yes: go to $00FB8D
$00:FB89 CA DEX ; X--
$00:FB8A 10 F8 BPL $FB84 ; Loop
$00:FB8C 60 RTS ; No free slot: return
$00:FB8D A9 01 LDA.B #$01 ; A = 1
$00:FB8F 9D C0 17 STA.W $17C0,X ; Smoke sprite type 1 (puff of smoke)
$00:FB92 B9 D8 00 LDA.W RAM_SpriteYLo,Y ; A = sprite Y low
$00:FB95 9D C4 17 STA.W $17C4,X ; Smoke Y = sprite Y
$00:FB98 B9 E4 00 LDA.W RAM_SpriteXLo,Y ; A = sprite X low
$00:FB9B 9D C8 17 STA.W $17C8,X ; Smoke X = sprite X
$00:FB9E A9 1B LDA.B #$1B ; A = $1B
$00:FBA0 9D CC 17 STA.W $17CC,X ; Smoke timer = $1B
$00:FBA3 60 RTS ; Return
;;; $FBA4: Table: level end smoke tiles (probably) (LvlEndSmokeTiles) ;;;
$00:FBA4 .db $66,$64,$62,$60,$E8,$EA,$EC,$EA ; Tile numbers
;;; $FBAC: Level end sprites to coins (long wrapper) (LvlEndSprCoins) ;;;
;; Sets the data bank to $00, calls LvlEndSprCoinsRt and returns with RTL. Called from the sprite status 6
;; handler in bank 01.
;; Called by:
;; $01:816D: Handle sprite at level end (status 6) (HandleSprLvlEnd)
$00:FBAC 8B PHB ; \
$00:FBAD 4B PHK ; } Save and set data bank = program bank
$00:FBAE AB PLB ; /
$00:FBAF 20 B4 FB JSR.W LvlEndSprCoinsRt ; Run the coin conversion (LvlEndSprCoinsRt)
$00:FBB2 AB PLB ; Restore the data bank
$00:FBB3 6B RTL ; Return long
;;; $FBB4: Level-end coin sprite and helpers (LvlEndSprCoinsRt) ;;;
;; Sprite routine for the coin that a sprite turns into at the end of a level: a smoke puff while [$1540,X]
;; counts down, then the coin
;; hops up, falls, awards points ([$18DD] index, +2 per coin, capped at $0D) and erases itself. Scrolls with
;; layer 1 via [$17BD].
;; Also holds unrelated spawn helpers:
;; $00FC23 (unused): runs Yoshi in from the left edge; $00FC7A: spawns a mounted Yoshi at Mario; $00FCEC:
;; erase all sprites;
;; $00FCF5: put sprite at (160,0); $00FD08: spawn swimming bubble (finds a free extended sprite slot, falls
;; into s00FD26).
;; Called by:
;; $00:FBAF: Level end sprites to coins (long wrapper) (LvlEndSprCoins)
$00:FBB4 A0 00 LDY.B #$00 ; Y = 0: high byte for sign extension
$00:FBB6 AD BD 17 LDA.W $17BD ; A = [$17BD] (layer 1 X movement this frame)
$00:FBB9 10 01 BPL $FBBC ; Positive: keep Y = 0
$00:FBBB 88 DEY ; Negative: Y = $FF
$00:FBBC 18 CLC ; \
$00:FBBD 75 E4 ADC RAM_SpriteXLo,X ; |
$00:FBBF 95 E4 STA RAM_SpriteXLo,X ; |
$00:FBC1 98 TYA ; |
$00:FBC2 7D E0 14 ADC.W RAM_SpriteXHi,X ; } } Sprite X += signed [$17BD]: coin follows layer 1 scrolling
$00:FBC5 9D E0 14 STA.W RAM_SpriteXHi,X ; /
$00:FBC8 BD 40 15 LDA.W $1540,X ; A = [$1540,X] (smoke puff timer)
$00:FBCB F0 23 BEQ $FBF0 ; Timer = 0: smoke is over, go handle the coin
$00:FBCD C9 01 CMP.B #$01 ; Timer = 1?
$00:FBCF D0 04 BNE $FBD5 ; No: skip
$00:FBD1 A9 D0 LDA.B #$D0 ; \
$00:FBD3 95 AA STA RAM_SpriteSpeedY,X ; / } Timer just hit 1: sprite Y speed = $D0 (kick the coin upward)
$00:FBD5 DA PHX ; Save sprite index
$00:FBD6 A9 04 LDA.B #$04 ; \
$00:FBD8 9D F6 15 STA.W RAM_SpritePal,X ; / } Sprite palette = 4 (palette A)
$00:FBDB 22 B2 90 01 JSL.L GenericSprGfxRt2 ; Draw a 16x16 sprite tile (GenericSprGfxRt2)
$00:FBDF BD 40 15 LDA.W $1540,X ; A = [$1540,X] (smoke timer)
$00:FBE2 4A LSR ; \
$00:FBE3 4A LSR ; / } A = timer / 4: smoke animation frame
$00:FBE4 BC EA 15 LDY.W RAM_SprOAMIndex,X ; Y = OAM index of this sprite
$00:FBE7 AA TAX ; X = animation frame
$00:FBE8 BD A4 FB LDA.W LvlEndSmokeTiles,X ; A = tile number for this frame (LvlEndSmokeTiles)
$00:FBEB 99 02 03 STA.W OAM_Tile,Y ; Override the drawn tile with the smoke tile
$00:FBEE FA PLX ; Restore sprite index
$00:FBEF 60 RTS ; Return
$00:FBF0 FE 70 15 INC.W $1570,X ; [$1570,X]++: sprite frame counter (animates the coin)
$00:FBF3 22 1A 80 01 JSL.L UpdateYPosNoGrvty ; Apply sprite speed to position, no gravity (UpdateYPosNoGrvty)
$00:FBF7 F6 AA INC RAM_SpriteSpeedY,X ; \
$00:FBF9 F6 AA INC RAM_SpriteSpeedY,X ; / } Sprite Y speed += 2 (gravity)
$00:FBFB B5 AA LDA RAM_SpriteSpeedY,X ; A = sprite Y speed
$00:FBFD C9 20 CMP.B #$20 ; Speed < $20 (still rising or slowly falling)?
$00:FBFF 30 1D BMI $FC1E ; Yes: just draw the coin
$00:FC01 22 4A B3 05 JSL.L $B34A ; Spawn glitter/sparkle effect at the sprite ($B34A)
$00:FC05 AD DD 18 LDA.W $18DD ; A = [$18DD] (next point value index)
$00:FC08 C9 0D CMP.B #$0D ; Below $0D?
$00:FC0A 90 02 BCC $FC0E ; Yes: use it as is
$00:FC0C A9 0D LDA.B #$0D ; Cap at $0D (1UP)
$00:FC0E 22 E5 AC 02 JSL.L GivePoints ; Give points for this coin (GivePoints)
$00:FC12 AD DD 18 LDA.W $18DD ; \
$00:FC15 18 CLC ; |
$00:FC16 69 02 ADC.B #$02 ; } } [$18DD] += 2: next coin is worth more
$00:FC18 8D DD 18 STA.W $18DD ; /
$00:FC1B 9E C8 14 STZ.W $14C8,X ; Erase the sprite (status = 0)
$00:FC1E 22 41 C6 01 JSL.L CoinSprGfx ; Draw the coin (CoinSprGfx)
$00:FC22 60 RTS ; Return
$00:FC23 A0 0B LDY.B #$0B ; Y = $0B: sprite slot loop
$00:FC25 B9 C8 14 LDA.W $14C8,Y ; A = sprite status of slot Y
$00:FC28 C9 08 CMP.B #$08 ; Status 8 (normal)?
$00:FC2A D0 47 BNE $FC73 ; No: next slot
$00:FC2C B9 9E 00 LDA.W RAM_SpriteNum,Y ; A = sprite number of slot Y
$00:FC2F C9 35 CMP.B #$35 ; Yoshi ($35)?
$00:FC31 D0 40 BNE $FC73 ; No: next slot
$00:FC33 A9 01 LDA.B #$01 ; \
$00:FC35 8D C1 0D STA.W RAM_OWHasYoshi ; / } [$0DC1] = 1: Yoshi is on the overworld
$00:FC38 9C 1E 14 STZ.W RAM_YoshiHasWings ; No Yoshi wings
$00:FC3B B9 F6 15 LDA.W RAM_SpritePal,Y ; \
$00:FC3E 29 F1 AND.B #$F1 ; |
$00:FC40 09 0A ORA.B #$0A ; } } Palette bits: keep bit 0, set palette 5 (A = A & $F1 | $0A)
$00:FC42 99 F6 15 STA.W RAM_SpritePal,Y ; /
$00:FC45 AD 7A 18 LDA.W RAM_OnYoshi ; Mario already on Yoshi?
$00:FC48 D0 28 BNE $FC72 ; Yes: done
$00:FC4A A5 1A LDA RAM_ScreenBndryXLo ; \
$00:FC4C 38 SEC ; |
$00:FC4D E9 10 SBC.B #$10 ; |
$00:FC4F 99 E4 00 STA.W RAM_SpriteXLo,Y ; |
$00:FC52 A5 1B LDA RAM_ScreenBndryXHi ; |
$00:FC54 E9 00 SBC.B #$00 ; } } Yoshi X = screen left edge X - $10 (just off-screen, 16-bit)
$00:FC56 99 E0 14 STA.W RAM_SpriteXHi,Y ; /
$00:FC59 A5 96 LDA RAM_MarioYPos ; \
$00:FC5B 99 D8 00 STA.W RAM_SpriteYLo,Y ; } } Yoshi Y = Mario Y
$00:FC5E A5 97 LDA RAM_MarioYPosHi ; /
$00:FC60 99 D4 14 STA.W RAM_SpriteYHi,Y ; \
$00:FC63 A9 03 LDA.B #$03 ; } } Yoshi state = 3 (running in)
$00:FC65 99 C2 00 STA.W RAM_SpriteState,Y ; /
$00:FC68 A9 00 LDA.B #$00 ; \
$00:FC6A 99 7C 15 STA.W RAM_SpriteDir,Y ; / } Yoshi direction = 0
$00:FC6D A9 10 LDA.B #$10 ; \
$00:FC6F 99 B6 00 STA.W RAM_SpriteSpeedX,Y ; / } Yoshi X speed = $10
$00:FC72 6B RTL ; Return
$00:FC73 88 DEY ; Next slot
$00:FC74 10 AF BPL $FC25 ; Loop for all 12 slots
$00:FC76 9C C1 0D STZ.W RAM_OWHasYoshi ; No Yoshi sprite found: [$0DC1] = 0
$00:FC79 6B RTL ; Return
$00:FC7A A9 02 LDA.B #$02 ; A = 2
$00:FC7C 8D FA 1D STA.W $1DFA ; Sound effect request in [$1DFA]
$00:FC7F A2 00 LDX.B #$00 ; X = 0: use slot 0 by default
$00:FC81 AD 94 1B LDA.W $1B94 ; A = [$1B94]
$00:FC84 D0 12 BNE $FC98 ; Non-zero: use slot 0
$00:FC86 A2 05 LDX.B #$05 ; X = 5: fallback slot
$00:FC88 AD 92 16 LDA.W $1692 ; A = [$1692]
$00:FC8B C9 0A CMP.B #$0A ; Equal to $0A?
$00:FC8D F0 09 BEQ $FC98 ; Yes: use slot 5
$00:FC8F 22 E4 A9 02 JSL.L FindFreeSprSlot ; Find a free sprite slot (FindFreeSprSlot)
$00:FC93 BB TYX ; X = Y (slot, or $FF if none)
$00:FC94 10 02 BPL $FC98 ; Found one: use it
$00:FC96 A2 03 LDX.B #$03 ; None free: use slot 3
$00:FC98 A9 08 LDA.B #$08 ; \
$00:FC9A 9D C8 14 STA.W $14C8,X ; / } Sprite status = 8 (normal)
$00:FC9D A9 35 LDA.B #$35 ; \
$00:FC9F 95 9E STA RAM_SpriteNum,X ; / } Sprite number = $35 (Yoshi)
$00:FCA1 A5 94 LDA RAM_MarioXPos ; \
$00:FCA3 95 E4 STA RAM_SpriteXLo,X ; |
$00:FCA5 A5 95 LDA RAM_MarioXPosHi ; } } Yoshi X = Mario X
$00:FCA7 9D E0 14 STA.W RAM_SpriteXHi,X ; /
$00:FCAA A5 96 LDA RAM_MarioYPos ; \
$00:FCAC 38 SEC ; |
$00:FCAD E9 10 SBC.B #$10 ; |
$00:FCAF 85 96 STA RAM_MarioYPos ; |
$00:FCB1 95 D8 STA RAM_SpriteYLo,X ; |
$00:FCB3 A5 97 LDA RAM_MarioYPosHi ; |
$00:FCB5 E9 00 SBC.B #$00 ; |
$00:FCB7 85 97 STA RAM_MarioYPosHi ; } } Yoshi Y = Mario Y - $10 and Mario Y -= $10 as well
$00:FCB9 9D D4 14 STA.W RAM_SpriteYHi,X ; /
$00:FCBC 22 D2 F7 07 JSL.L InitSpriteTables ; Reset all sprite tables for the new sprite (InitSpriteTables)
$00:FCC0 A9 04 LDA.B #$04 ; \
$00:FCC2 9D E2 1F STA.W $1FE2,X ; / } [$1FE2,X] = 4 (probably a Yoshi timer)
$00:FCC5 AD C7 13 LDA.W RAM_YoshiColor ; \
$00:FCC8 9D F6 15 STA.W RAM_SpritePal,X ; / } Sprite palette = Yoshi color [$13C7]
$00:FCCB AD 95 1B LDA.W $1B95 ; A = [$1B95]
$00:FCCE F0 05 BEQ $FCD5 ; Zero: keep Yoshi color
$00:FCD0 A9 06 LDA.B #$06 ; \
$00:FCD2 9D F6 15 STA.W RAM_SpritePal,X ; / } Non-zero: sprite palette = 6
$00:FCD5 EE 7A 18 INC.W RAM_OnYoshi ; Mario is on Yoshi: [$187A]++
$00:FCD8 F6 C2 INC RAM_SpriteState,X ; Sprite state++: Yoshi is mounted
$00:FCDA A5 76 LDA RAM_MarioDirection ; \
$00:FCDC 49 01 EOR.B #$01 ; } } Yoshi direction = Mario direction EOR 1
$00:FCDE 9D 7C 15 STA.W RAM_SpriteDir,X ; /
$00:FCE1 DE 0E 16 DEC.W $160E,X ; [$160E,X]-- (probably clears the Yoshi mouth/swallow slot to $FF)
$00:FCE4 E8 INX ; X++
$00:FCE5 8E DF 18 STX.W $18DF ; [$18DF] = slot + 1 (Yoshi slot index + 1)
$00:FCE8 8E E2 18 STX.W $18E2 ; [$18E2] = slot + 1
$00:FCEB 6B RTL ; Return
$00:FCEC A2 0B LDX.B #$0B ; X = $0B: all 12 sprite slots
$00:FCEE 9E C8 14 STZ.W $14C8,X ; Sprite status = 0 (erase)
$00:FCF1 CA DEX ; Next slot
$00:FCF2 10 FA BPL $FCEE ; Loop
$00:FCF4 60 RTS ; Return
$00:FCF5 A9 A0 LDA.B #$A0 ; \
$00:FCF7 95 E4 STA RAM_SpriteXLo,X ; / } Sprite X low = $A0
$00:FCF9 A9 00 LDA.B #$00 ; \
$00:FCFB 9D E0 14 STA.W RAM_SpriteXHi,X ; / } Sprite X high = 0
$00:FCFE A9 00 LDA.B #$00 ; \
$00:FD00 95 D8 STA RAM_SpriteYLo,X ; / } Sprite Y low = 0
$00:FD02 A9 00 LDA.B #$00 ; \
$00:FD04 9D D4 14 STA.W RAM_SpriteYHi,X ; / } Sprite Y high = 0
$00:FD07 6B RTL ; Return
$00:FD08 A0 3F LDY.B #$3F ; Y = $3F: spawn rate mask when swimming
$00:FD0A A5 15 LDA RAM_ControllerA ; A = controller 1 held
$00:FD0C 29 83 AND.B #$83 ; A = held & $83 (B, left, right)
$00:FD0E D0 02 BNE $FD12 ; Any pressed: keep $3F
$00:FD10 A0 7F LDY.B #$7F ; None pressed: slower rate mask $7F
$00:FD12 98 TYA ; A = rate mask
$00:FD13 25 14 AND RAM_FrameCounterB ; A = mask & [$14] (frame counter B)
$00:FD15 05 9D ORA RAM_SpritesLocked ; A |= [$9D] (sprites locked)
$00:FD17 D0 0A BNE $FD23 ; Not zero: skip this frame
$00:FD19 A2 07 LDX.B #$07 ; X = 7: search extended sprite slots
$00:FD1B BD 0B 17 LDA.W RAM_ExSpriteNum,X ; A = extended sprite number in slot X
$00:FD1E F0 06 BEQ $FD26 ; Empty slot found: go spawn the bubble
$00:FD20 CA DEX ; Next slot
$00:FD21 10 F8 BPL $FD1B ; Loop for all 8 slots
$00:FD23 60 RTS ; Return, no free slot
;;; $FD24..FD24: Table: bubble X offset by direction ;;;
$00:FD24 .db $02,$0A ; Bubble X offset: left $02, right $0A
;;; $FD26: Spawn bubble, block smoke puff ;;;
;; $00FD26: creates a water bubble (extended sprite $12) at Mario's mouth: X = Mario X + $02/$0A by direction,
;; Y = Mario Y + 4 (big, standing) or $0C (small or ducking). Parameters: X = free extended sprite slot.
;; $00FD5A: spawns a type 5 smoke puff at the block position [$98]/[$9A] (aligned to 16), unless Mario is off-
;; screen; uses layer 2 scroll if [$1933] is set.
$00:FD26 A9 12 LDA.B #$12 ; \
$00:FD28 9D 0B 17 STA.W RAM_ExSpriteNum,X ; / } Extended sprite = $12 (water bubble)
$00:FD2B A4 76 LDY RAM_MarioDirection ; Y = Mario direction
$00:FD2D A5 94 LDA RAM_MarioXPos ; \
$00:FD2F 18 CLC ; |
$00:FD30 79 24 FD ADC.W $FD24,Y ; } } Bubble X = Mario X + [$FD24+direction]
$00:FD33 9D 1F 17 STA.W RAM_ExSpriteXLo,X ; /
$00:FD36 A5 95 LDA RAM_MarioXPosHi ; \
$00:FD38 69 00 ADC.B #$00 ; } } Bubble X high with carry
$00:FD3A 9D 33 17 STA.W RAM_ExSpriteXHi,X ; /
$00:FD3D A5 19 LDA RAM_MarioPowerUp ; A = Mario power-up
$00:FD3F F0 06 BEQ $FD47 ; Small Mario: offset $0C
$00:FD41 A9 04 LDA.B #$04 ; A = 4: offset for big Mario
$00:FD43 A4 73 LDY RAM_IsDucking ; Y = ducking flag
$00:FD45 F0 02 BEQ $FD49 ; Not ducking: keep 4
$00:FD47 A9 0C LDA.B #$0C ; Offset $0C (small or ducking: mouth is lower)
$00:FD49 18 CLC ; \
$00:FD4A 65 96 ADC RAM_MarioYPos ; } } Bubble Y = Mario Y + offset
$00:FD4C 9D 15 17 STA.W RAM_ExSpriteYLo,X ; /
$00:FD4F A5 97 LDA RAM_MarioYPosHi ; \
$00:FD51 69 00 ADC.B #$00 ; } } Bubble Y high with carry
$00:FD53 9D 29 17 STA.W RAM_ExSpriteYHi,X ; /
$00:FD56 9E 6F 17 STZ.W $176F,X ; [$176F,X] = 0 (bubble timer/phase)
$00:FD59 60 RTS ; Return
$00:FD5A A5 7F LDA $7F ; A = [$7F]
$00:FD5C 05 81 ORA $81 ; A |= [$81]
$00:FD5E D0 0A BNE $FD6A ; Mario off-screen horizontally or vertically: return
$00:FD60 A0 03 LDY.B #$03 ; Y = 3: search smoke sprite slots
$00:FD62 B9 C0 17 LDA.W $17C0,Y ; A = [$17C0,Y] (smoke type)
$00:FD65 F0 04 BEQ $FD6B ; Empty slot: spawn
$00:FD67 88 DEY ; Next slot
$00:FD68 10 F8 BPL $FD62 ; Loop for slots 3..0
$00:FD6A 60 RTS ; Return, none free
$00:FD6B A9 05 LDA.B #$05 ; \
$00:FD6D 99 C0 17 STA.W $17C0,Y ; / } Smoke type = 5
$00:FD70 A5 9A LDA RAM_BlockXLo ; \
$00:FD72 29 F0 AND.B #$F0 ; } } Smoke X = block X & $F0 (aligned to tile)
$00:FD74 99 C8 17 STA.W $17C8,Y ; /
$00:FD77 A5 98 LDA RAM_BlockYLo ; \
$00:FD79 29 F0 AND.B #$F0 ; } } Smoke Y = block Y & $F0 (aligned to tile)
$00:FD7B 99 C4 17 STA.W $17C4,Y ; /
$00:FD7E AD 33 19 LDA.W $1933 ; A = [$1933] (layer 2 flag)
$00:FD81 F0 14 BEQ $FD97 ; Zero: skip layer 2 adjustment
$00:FD83 A5 9A LDA RAM_BlockXLo ; \
$00:FD85 38 SEC ; |
$00:FD86 E5 26 SBC $26 ; |
$00:FD88 29 F0 AND.B #$F0 ; |
$00:FD8A 99 C8 17 STA.W $17C8,Y ; |
$00:FD8D A5 98 LDA RAM_BlockYLo ; |
$00:FD8F 38 SEC ; |
$00:FD90 E5 28 SBC $28 ; |
$00:FD92 29 F0 AND.B #$F0 ; } } Layer 2 level: subtract layer 2 scroll [$26]/[$28] from X and Y
$00:FD94 99 C4 17 STA.W $17C4,Y ; /
$00:FD97 A9 10 LDA.B #$10 ; \
$00:FD99 99 CC 17 STA.W $17CC,Y ; / } Smoke timer = $10
$00:FD9C 60 RTS ; Return
;;; $FD9D..FDA1: Table: water splash Y offsets ;;;
$00:FD9D .db $08,$FC,$10,$04 ; Y offset: small $08
$00:FDA1 .db $00,$FF,$00,$00 ; High byte of the Y offset: small $00
;;; $FDA5: Spawn water splash and bubbles ;;;
;; Mario enters water: spawns a water splash (minor extended sprite type 7) on the surface row at Mario's
;; feet, zeroes Mario's
;; Y speed (and X speed if airborne) unless rising, then fills free extended sprite slots with water bubbles
;; (up to 4, 3 for small Mario).
;; Quirk: if Mario is not in the air the slot search is skipped and Y is the caller's Y plus 1.
;; Called by:
;; $00:EA59: Mario level collision, borders and water
;; $00:EA98: Mario level collision, borders and water
$00:FDA5 A5 72 LDA RAM_IsFlying ; A = [$72] (Mario in air)
$00:FDA7 F0 0A BEQ $FDB3 ; On ground: skip the search
$00:FDA9 A0 0B LDY.B #$0B ; Y = $0B: search minor extended sprite slots
$00:FDAB B9 F0 17 LDA.W $17F0,Y ; A = [$17F0,Y] (type)
$00:FDAE F0 04 BEQ $FDB4 ; Empty: use this slot
$00:FDB0 88 DEY ; Next slot
$00:FDB1 10 F8 BPL $FDAB ; Loop
$00:FDB3 C8 INY ; Y++ (no free slot found: wraps $FF to 0; on ground uses caller's Y + 1)
$00:FDB4 DA PHX ; Save X
$00:FDB5 A2 00 LDX.B #$00 ; X = 0
$00:FDB7 A5 19 LDA RAM_MarioPowerUp ; A = Mario power-up
$00:FDB9 F0 01 BEQ $FDBC ; Small: keep X = 0
$00:FDBB E8 INX ; X = 1 for big Mario
$00:FDBC AD 7A 18 LDA.W RAM_OnYoshi ; A = [$187A] (on Yoshi)
$00:FDBF F0 02 BEQ $FDC3 ; Not on Yoshi: keep
$00:FDC1 E8 INX ; \
$00:FDC2 E8 INX ; / } X += 2 for Yoshi
$00:FDC3 A5 96 LDA RAM_MarioYPos ; A = Mario Y low
$00:FDC5 18 CLC ; Clear carry
$00:FDC6 7D 9D FD ADC.W $FD9D,X ; A += Y offset from $FD9D[X]
$00:FDC9 08 PHP ; Save carry
$00:FDCA 29 F0 AND.B #$F0 ; \
$00:FDCC 18 CLC ; } } Align down to a 16-pixel row and add 3
$00:FDCD 69 03 ADC.B #$03 ; /
$00:FDCF 99 FC 17 STA.W $17FC,Y ; Splash Y low = A
$00:FDD2 A5 97 LDA RAM_MarioYPosHi ; \
$00:FDD4 69 00 ADC.B #$00 ; / } A = Mario Y high + carry
$00:FDD6 28 PLP ; Restore carry from the offset add
$00:FDD7 7D A1 FD ADC.W $FDA1,X ; A += Y high offset from $FDA1[X]
$00:FDDA 99 14 18 STA.W $1814,Y ; Splash Y high = A
$00:FDDD FA PLX ; Restore X
$00:FDDE A5 94 LDA RAM_MarioXPos ; \
$00:FDE0 99 08 18 STA.W $1808,Y ; / } Splash X low = Mario X low
$00:FDE3 A5 95 LDA RAM_MarioXPosHi ; \
$00:FDE5 99 EA 18 STA.W $18EA,Y ; / } Splash X high = Mario X high
$00:FDE8 A9 07 LDA.B #$07 ; \
$00:FDEA 99 F0 17 STA.W $17F0,Y ; / } Minor extended sprite type = 7 (water splash)
$00:FDED A9 00 LDA.B #$00 ; \
$00:FDEF 99 50 18 STA.W $1850,Y ; / } [$1850,Y] = 0 (splash timer/frame)
$00:FDF2 A5 7D LDA RAM_MarioSpeedY ; A = Mario Y speed
$00:FDF4 30 17 BMI $FE0D ; Rising: no bubbles, return
$00:FDF6 64 7D STZ RAM_MarioSpeedY ; Mario Y speed = 0
$00:FDF8 A4 72 LDY RAM_IsFlying ; Y = Mario in air
$00:FDFA F0 02 BEQ $FDFE ; On ground: keep X speed
$00:FDFC 64 7B STZ RAM_MarioSpeedX ; Mario X speed = 0 (airborne entry stops horizontal motion)
$00:FDFE A0 03 LDY.B #$03 ; Y = 3: bubble slots 3..0 (big Mario)
$00:FE00 A5 19 LDA RAM_MarioPowerUp ; A = Mario power-up
$00:FE02 D0 01 BNE $FE05 ; Big: keep 3 bubbles' worth (slots 0-3)
$00:FE04 88 DEY ; Small: slots 0-2
$00:FE05 B9 0B 17 LDA.W RAM_ExSpriteNum,Y ; A = extended sprite number in slot Y
$00:FE08 F0 0C BEQ $FE16 ; Empty: spawn a bubble here
$00:FE0A 88 DEY ; Next slot
$00:FE0B 10 F8 BPL $FE05 ; Loop
$00:FE0D 60 RTS ; Return
;;; $FE0E..FE12: Table: bubble offsets from Mario ;;;
$00:FE0E .db $10,$16,$13,$1C ; Bubble Y offset: slot 0 = $10
$00:FE12 .db $00,$04,$0A,$07 ; Bubble X offset: slot 0 = $00
;;; $FE16: Spawn bubble, skid smoke puff ;;;
;; $00FE16: initializes water bubble number Y (extended sprite $12) around Mario using the two offset tables.
;; $00FE4A: spawns a type 3 smoke puff at Mario's feet every 4th frame while running on the ground; if Down is
;; held it needs some speed.
;; Returns early if Mario is flying, off-screen or sprites are locked.
$00:FE16 A9 12 LDA.B #$12 ; \
$00:FE18 99 0B 17 STA.W RAM_ExSpriteNum,Y ; / } Extended sprite = $12 (water bubble)
$00:FE1B 98 TYA ; \
$00:FE1C 0A ASL ; |
$00:FE1D 0A ASL ; |
$00:FE1E 0A ASL ; |
$00:FE1F 69 F7 ADC.B #$F7 ; } } [$1765,Y] = slot * 8 - 9 (staggers the bubbles)
$00:FE21 99 65 17 STA.W $1765,Y ; /
$00:FE24 A5 96 LDA RAM_MarioYPos ; \
$00:FE26 79 0E FE ADC.W $FE0E,Y ; } } Bubble Y = Mario Y + $FE0E[Y]
$00:FE29 99 15 17 STA.W RAM_ExSpriteYLo,Y ; /
$00:FE2C A5 97 LDA RAM_MarioYPosHi ; \
$00:FE2E 69 00 ADC.B #$00 ; } } Bubble Y high with carry
$00:FE30 99 29 17 STA.W RAM_ExSpriteYHi,Y ; /
$00:FE33 A5 94 LDA RAM_MarioXPos ; \
$00:FE35 79 12 FE ADC.W $FE12,Y ; } } Bubble X = Mario X + $FE12[Y]
$00:FE38 99 1F 17 STA.W RAM_ExSpriteXLo,Y ; /
$00:FE3B A5 95 LDA RAM_MarioXPosHi ; \
$00:FE3D 69 00 ADC.B #$00 ; } } Bubble X high with carry
$00:FE3F 99 33 17 STA.W RAM_ExSpriteXHi,Y ; /
$00:FE42 A9 00 LDA.B #$00 ; \
$00:FE44 99 6F 17 STA.W $176F,Y ; / } [$176F,Y] = 0 (bubble timer/phase)
$00:FE47 4C 0A FE JMP.W $FE0A ; Continue with the next slot
$00:FE4A A5 13 LDA RAM_FrameCounter ; \
$00:FE4C 29 03 AND.B #$03 ; |
$00:FE4E 05 72 ORA RAM_IsFlying ; |
$00:FE50 05 7F ORA $7F ; |
$00:FE52 05 81 ORA $81 ; |
$00:FE54 05 9D ORA RAM_SpritesLocked ; } } Return unless: frame counter & 3 = 0, on ground, not off-screen, sprites not locked
$00:FE56 D0 19 BNE $FE71 ; /
$00:FE58 A5 15 LDA RAM_ControllerA ; \
$00:FE5A 29 04 AND.B #$04 ; / } A = held buttons & 4 (Down)
$00:FE5C F0 09 BEQ $FE67 ; Down not held: skip the speed check
$00:FE5E A5 7B LDA RAM_MarioSpeedX ; \
$00:FE60 18 CLC ; |
$00:FE61 69 08 ADC.B #$08 ; |
$00:FE63 C9 10 CMP.B #$10 ; } } Down held: return if Mario X speed is within -8..+7 (too slow)
$00:FE65 90 0A BCC $FE71 ; /
$00:FE67 A0 03 LDY.B #$03 ; Y = 3: search smoke sprite slots
$00:FE69 B9 C0 17 LDA.W $17C0,Y ; A = [$17C0,Y] (smoke type)
$00:FE6C F0 04 BEQ $FE72 ; Empty: spawn
$00:FE6E 88 DEY ; Next slot
$00:FE6F D0 F8 BNE $FE69 ; Loop for slots 3..1
$00:FE71 60 RTS ; Return, none free
$00:FE72 A9 03 LDA.B #$03 ; \
$00:FE74 99 C0 17 STA.W $17C0,Y ; / } Smoke type = 3
$00:FE77 A5 94 LDA RAM_MarioXPos ; \
$00:FE79 69 04 ADC.B #$04 ; } } Smoke X = Mario X + 4
$00:FE7B 99 C8 17 STA.W $17C8,Y ; /
$00:FE7E A5 96 LDA RAM_MarioYPos ; \
$00:FE80 69 1A ADC.B #$1A ; / } A = Mario Y + $1A
$00:FE82 DA PHX ; Save X
$00:FE83 AE 7A 18 LDX.W RAM_OnYoshi ; X = on Yoshi flag
$00:FE86 F0 02 BEQ $FE8A ; Not on Yoshi: skip
$00:FE88 69 10 ADC.B #$10 ; On Yoshi: A += $10
$00:FE8A 99 C4 17 STA.W $17C4,Y ; Smoke Y = A
$00:FE8D FA PLX ; Restore X
$00:FE8E A9 13 LDA.B #$13 ; \
$00:FE90 99 CC 17 STA.W $17CC,Y ; / } Smoke timer = $13
$00:FE93 60 RTS ; Return
;;; $FE94..FEA2: Table: fireball speed and offsets ;;;
;; FE94: fireball X speed by direction; FE96/FE9C: X offset low/high; FEA2: Y offset. Indexed by direction + 2
;; per Yoshi state.
$00:FE94 .db $FD,$03 ; Fireball X speed: left $FD (-3)
$00:FE96 .db $00,$08,$F8,$10,$F8,$10 ; Fireball X offset, direction and Yoshi variants
$00:FE9C .db $00,$00,$FF,$00,$FF,$00 ; Fireball X offset high bytes
$00:FEA2 .db $08,$08,$0C,$0C,$14,$14 ; Fireball Y offsets
;;; $FEA8: Shoot Mario fireball (ShootFireball) ;;;
;; Finds a free fireball slot (extended sprite slots 8-9) and spawns a Mario fireball (type 5) with Y speed
;; $30 and X speed +-3, positioned
;; by Mario's direction, Yoshi and [$18DC]. Plays the fireball sound and starts the shoot pose timer [$149C].
;; Followed by unused routines: $00FF07 (move Mario by layer 1 scroll delta), $00FF32 and $00FF61 (set layer 3
;; scroll [$22]/[$24] from a sprite position),
;; then $FF padding and the SNES header and vectors at $00FFC0.
;; Called by:
;; $00:CDD9: Yoshi poses and L/R scrolling (OnYoshiAnimations)
;; $00:D0AA: Cape hit point, cape spin and fireball input
$00:FEA8 A2 09 LDX.B #$09 ; X = 9: fireball slots are 8 and 9
$00:FEAA BD 0B 17 LDA.W RAM_ExSpriteNum,X ; A = extended sprite number in slot X
$00:FEAD F0 06 BEQ $FEB5 ; Empty: spawn
$00:FEAF CA DEX ; Next slot
$00:FEB0 E0 07 CPX.B #$07 ; Reached slot 7?
$00:FEB2 D0 F6 BNE $FEAA ; No: keep searching
$00:FEB4 60 RTS ; Return, both fireball slots busy
$00:FEB5 A9 06 LDA.B #$06 ; \
$00:FEB7 8D FC 1D STA.W $1DFC ; / } Sound effect: fireball
$00:FEBA A9 0A LDA.B #$0A ; \
$00:FEBC 8D 9C 14 STA.W RAM_FireballImgTimer ; / } Fireball shoot pose timer [$149C] = $0A
$00:FEBF A9 05 LDA.B #$05 ; \
$00:FEC1 9D 0B 17 STA.W RAM_ExSpriteNum,X ; / } Extended sprite = 5 (Mario fireball)
$00:FEC4 A9 30 LDA.B #$30 ; \
$00:FEC6 9D 3D 17 STA.W RAM_ExSprSpeedY,X ; / } Fireball Y speed = $30 (down)
$00:FEC9 A4 76 LDY RAM_MarioDirection ; Y = Mario direction
$00:FECB B9 94 FE LDA.W $FE94,Y ; \
$00:FECE 9D 47 17 STA.W RAM_ExSprSpeedX,X ; / } Fireball X speed = $FE94[direction]
$00:FED1 AD 7A 18 LDA.W RAM_OnYoshi ; A = on Yoshi
$00:FED4 F0 09 BEQ $FEDF ; Not on Yoshi: use index = direction
$00:FED6 C8 INY ; \
$00:FED7 C8 INY ; / } Y += 2: Yoshi table entries
$00:FED8 AD DC 18 LDA.W $18DC ; A = [$18DC]
$00:FEDB F0 02 BEQ $FEDF ; Zero: keep
$00:FEDD C8 INY ; \
$00:FEDE C8 INY ; / } Y += 2 more
$00:FEDF A5 94 LDA RAM_MarioXPos ; \
$00:FEE1 18 CLC ; |
$00:FEE2 79 96 FE ADC.W $FE96,Y ; } } Fireball X = Mario X + $FE96[Y]
$00:FEE5 9D 1F 17 STA.W RAM_ExSpriteXLo,X ; /
$00:FEE8 A5 95 LDA RAM_MarioXPosHi ; \
$00:FEEA 79 9C FE ADC.W $FE9C,Y ; } } Fireball X high = Mario X high + $FE9C[Y]
$00:FEED 9D 33 17 STA.W RAM_ExSpriteXHi,X ; /
$00:FEF0 A5 96 LDA RAM_MarioYPos ; \
$00:FEF2 18 CLC ; |
$00:FEF3 79 A2 FE ADC.W $FEA2,Y ; } } Fireball Y = Mario Y + $FEA2[Y]
$00:FEF6 9D 15 17 STA.W RAM_ExSpriteYLo,X ; /
$00:FEF9 A5 97 LDA RAM_MarioYPosHi ; \
$00:FEFB 69 00 ADC.B #$00 ; } } Fireball Y high = Mario Y high + carry
$00:FEFD 9D 29 17 STA.W RAM_ExSpriteYHi,X ; /
$00:FF00 AD F9 13 LDA.W RAM_IsBehindScenery ; \
$00:FF03 9D 79 17 STA.W $1779,X ; / } [$1779,X] = Mario behind-scenery flag
$00:FF06 60 RTS ; Return
$00:FF07 C2 20 REP #$20 ; A 16-bit
$00:FF09 AD BC 17 LDA.W $17BC ; \
$00:FF0C 29 00 FF AND.W #$FF00 ; / } A = [$17BD] sign-extended later (high byte of [$17BC] word)
$00:FF0F 10 03 BPL $FF14 ; \
$00:FF11 09 FF 00 ORA.W #$00FF ; / } Negative: fill upper byte with $FF
$00:FF14 EB XBA ; Swap: A = signed 16-bit [$17BD]
$00:FF15 18 CLC ; \
$00:FF16 65 94 ADC RAM_MarioXPos ; } } Mario X += signed [$17BD] (layer 1 X movement)
$00:FF18 85 94 STA RAM_MarioXPos ; /
$00:FF1A AD BB 17 LDA.W $17BB ; \
$00:FF1D 29 00 FF AND.W #$FF00 ; / } A = [$17BC] (layer 1 Y movement) in the high byte
$00:FF20 10 03 BPL $FF25 ; \
$00:FF22 09 FF 00 ORA.W #$00FF ; / } Negative: fill upper byte with $FF
$00:FF25 EB XBA ; Swap: A = signed 16-bit [$17BC]
$00:FF26 49 FF FF EOR.W #$FFFF ; \
$00:FF29 1A INC A ; / } A = -A
$00:FF2A 18 CLC ; \
$00:FF2B 65 96 ADC RAM_MarioYPos ; } } Mario Y += -[$17BC] (follows layer 1 Y movement)
$00:FF2D 85 96 STA RAM_MarioYPos ; /
$00:FF2F E2 20 SEP #$20 ; A 8-bit
$00:FF31 6B RTL ; Return
$00:FF32 BD E0 14 LDA.W RAM_SpriteXHi,X ; \
$00:FF35 EB XBA ; } } A = sprite X (16-bit, high byte swapped in)
$00:FF36 B5 E4 LDA RAM_SpriteXLo,X ; /
$00:FF38 C2 20 REP #$20 ; A 16-bit
$00:FF3A 38 SEC ; \
$00:FF3B E5 1A SBC RAM_ScreenBndryXLo ; } } $00 = sprite X - screen X (position on screen)
$00:FF3D 85 00 STA $00 ; /
$00:FF3F A9 30 00 LDA.W #$0030 ; \
$00:FF42 38 SEC ; |
$00:FF43 E5 00 SBC $00 ; } } $22 = $30 - $00: BG3 X scroll follows the sprite
$00:FF45 85 22 STA $22 ; /
$00:FF47 E2 20 SEP #$20 ; A 8-bit
$00:FF49 BD D4 14 LDA.W RAM_SpriteYHi,X ; \
$00:FF4C EB XBA ; } } A = sprite Y (16-bit, high byte swapped in)
$00:FF4D B5 D8 LDA RAM_SpriteYLo,X ; /
$00:FF4F C2 20 REP #$20 ; A 16-bit
$00:FF51 38 SEC ; \
$00:FF52 E5 1C SBC RAM_ScreenBndryYLo ; } } $00 = sprite Y - screen Y
$00:FF54 85 00 STA $00 ; /
$00:FF56 A9 00 01 LDA.W #$0100 ; \
$00:FF59 38 SEC ; |
$00:FF5A E5 00 SBC $00 ; } } $24 = $100 - $00: BG3 Y scroll follows the sprite
$00:FF5C 85 24 STA $24 ; /
$00:FF5E E2 20 SEP #$20 ; A 8-bit
$00:FF60 6B RTL ; Return
$00:FF61 BD E0 14 LDA.W RAM_SpriteXHi,X ; \
$00:FF64 EB XBA ; } } A = sprite X (16-bit, high byte swapped in)
$00:FF65 B5 E4 LDA RAM_SpriteXLo,X ; /
$00:FF67 C2 20 REP #$20 ; A 16-bit
$00:FF69 C9 00 FF CMP.W #$FF00 ; \
$00:FF6C 30 05 BMI $FF73 ; / } X < -256: out of range
$00:FF6E C9 00 01 CMP.W #$0100 ; \
$00:FF71 30 03 BMI $FF76 ; / } X < 256: in range, keep
$00:FF73 A9 00 01 LDA.W #$0100 ; Out of range: A = $100
$00:FF76 85 22 STA $22 ; BG3 X scroll [$22] = A
$00:FF78 E2 20 SEP #$20 ; A 8-bit
$00:FF7A BD D4 14 LDA.W RAM_SpriteYHi,X ; \
$00:FF7D EB XBA ; } } A = sprite Y (16-bit, high byte swapped in)
$00:FF7E B5 D8 LDA RAM_SpriteYLo,X ; /
$00:FF80 C2 20 REP #$20 ; A 16-bit
$00:FF82 85 00 STA $00 ; $00 = sprite Y
$00:FF84 A9 A0 00 LDA.W #$00A0 ; \
$00:FF87 38 SEC ; } } A = $A0 - sprite Y
$00:FF88 E5 00 SBC $00 ; /
$00:FF8A 18 CLC ; \
$00:FF8B 6D 88 18 ADC.W RAM_Layer1DispYLo ; / } A += layer 1 Y displacement [$1888]
$00:FF8E 85 24 STA $24 ; BG3 Y scroll [$24] = A
$00:FF90 E2 20 SEP #$20 ; A 8-bit
$00:FF92 6B RTL ; Return
$00:FF93 .db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
$00:FF9B .db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
$00:FFA3 .db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
$00:FFAB .db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
$00:FFB3 .db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
$00:FFBB .db $FF,$FF,$FF,$FF,$FF
;;; SNES header, see http://romhack.wikia.com/wiki/SNES_header
;;;
;; Name of ROM. "SUPER MARIOWORLD " in ASCII, 21 characters.
$00:FFC0 .db $53,$55,$50,$45,$52,$20,$4D,$41,$52,$49,$4F ; "SUPER MARIO"
$00:FFCB .db $57,$4F,$52,$4C,$44,$20,$20,$20,$20,$20 ; "WORLD "
$00:FFD5 .db $20 ; ROM status: slow LoROM
$00:FFD6 .db $02 ; Cartridge type: ROM with save-RAM
$00:FFD7 .db $09 ; ROM size: 512 kilobytes
$00:FFD8 .db $01 ; Save-RAM size: 2 kilobytes
$00:FFD9 .db $01 ; Country code: NTSC
$00:FFDA .db $01 ; Licensee code: Nintendo
$00:FFDB .db $00 ; Version: zero
$00:FFDC .dw $5F25 ; Checksum complement (.db $25, $5F)
$00:FFDE .dw $A0DA ; Checksum (.db $DA, A0)
$00:FFE0 .db $FF,$FF,$FF,$FF ; Technically free space
$00:FFE4 .dw $82C3 ; Native mode COP vector
$00:FFE6 .dw $FFFF ; Native mode BRK vector (change to use)
$00:FFE8 .dw $82C3 ; Native mode ABORT vector
$00:FFEA .dw $816A ; Native mode NMI vector
$00:FFEC .dw $8000 ; Never used, would be native mode RESET vector
$00:FFEE .dw $8374 ; Native mode IRQ vector
$00:FFF0 .db $FF,$FF,$FF,$FF ; Technically free space
$00:FFF4 .dw $82C3 ; Emulation mode COP vector
$00:FFF6 .dw $82C3 ; Never used, would be emulation mode BRK vector
$00:FFF8 .dw $82C3 ; Emulation mode ABORT vector
$00:FFFA .dw $82C3 ; Emulation mode NMI vector
$00:FFFC .dw $8000 ; Emulation mode RESET vector
$00:FFFE .dw $82C3 ; Emulation mode IRQ and BRK vector
; timer.BANK 1
; Most of this is just sprite initalization stuff.
;;; $80E7: Unused stub: A = 0 (StzTo6ePointer0080E7) ;;;
;; Called by:
;; $0D:A5B3: Draw single-tile extended objects
;; $0D:A6A1: Draw triangles, midway point and pointer helpers
;; $0D:A6A9: Draw triangles, midway point and pointer helpers
;; $0D:A6D8: Draw two-tile-high door
;; $0D:A6E4: Draw two-tile-high door
;; $0D:A72E: Object: big bush
;; $0D:A773: Object: small bush and bush tile adder
;; $0D:A7EE: Object: goal sign
;; $0D:A934: Rectangle objects and Map16 pointer helpers
;; $0D:ABAD: Pointer table: slope types; normal left slope (PtrsLong0DAB50)
;; $0D:AC4C: Slope object draw routines (all 8 slopes)
;; $0D:ACF5: Slope object draw routines (all 8 slopes)
;; ... and 134 more
$00:80E7 A9 00 LDA.B #$00 ; Unused stub: A = 0 (loads zero, no effect here)