{ ; $80:8000..8001 [data] Skip NTSC/PAL and SRAM mapping check ; $80:8002..8003 [data] Demo recorder ; $80:8004..8005 [data] Debug mode ; $80:8006..8007 [data] Debug scrolling ; $80:8008..8009 [data] Something for the audio man ; $80:800A..8027 Load new music ; $80:8028..8058 Upload to APU ; $80:8059..80FF Send APU data ; $80:8100..8110 Increment Y (once or twice), bank overflow check ; $80:8111..8145 Random number generator ; $80:8146..818D ??? ; $80:818E..81A5 Change nth bit to address offset and mask ; $80:81A6..81BF Set boss bits in A for current area ($7E:D828,X) ; $80:81C0..81DB Clear boss bits in A for current area ($7E:D828,X) ; $80:81DC..81F9 Checks if the boss bits for the current area matches any bits in A. SEC if there's a match ; $80:81FA..8211 Marks an event as happened. Event bit # must be stored in A ; $80:8212..8232 Marks an event as not happened. Event bit # must be stored in A ; $80:8233..824E Checks if an event has happened. Event bit # must be stored in A. CLC if 0, SEC if 1 ; $80:824F..8260 Write 'supermetroid' to SRAM ($70:1FE0..1FEB) ; $80:8261..82AC Check for non-corrupt SRAM ; $80:82AD..82B8 [data] 'madadameyohn' garbage written if there's corrupt SRAM ; $80:82B9..82C4 [data] 'supermetroid' written to SRAM ; $80:82C5..82D5 Wait until the end of a VBlank ; $80:82D6..8337 Multiplies A and Y together (16-bit * 16-bit). Result in $05F1-$05F4 ; $80:8338..834A Wait for IRQ ; $80:834B..835C Enable NMI with $84 options ; $80:835D..836E Disable NMI with $84 options ; $80:836F..8381 Set force blank ; $80:8382..8394 Clear force blank ; $80:8395..83BC DMA, slot 1, 200h bytes from $7E:C000 through $2122 (CGRAM Data Write) ; $80:83BD..83CF 8-bit write Y bytes of A to $00:X ; $80:83D0..83E2 16-bit write Y bytes of A to $00:X ; $80:83E3..83F5 8-bit write Y bytes of A to $7E:X ; $80:83F6..8408 16-bit write Y bytes of A to $7E:X ; $80:8409..841B 16-bit write Y bytes of A to $7F:X ; $80:841C..8461 Boot ; $80:8462..8081 Soft reset ; $80:8482..8571 Game initialisation ; $80:8572..8572 BRK ; $80:8573..8576 Infinite loop; pointed to by misc. error handling ; $80:8577..858B Wait A many IRQs ; $80:858C..85B5 Load mirror of current area's map explored ; $80:85C6..85F5 Mirror current area's map explored ; $80:85F6..875C NTSC/PAL and SRAM mapping check ; $80:875D..8791 Initialise $4200..420D ; $80:8792..88B3 Initialise $2100..2133 ; $80:88B4..88D0 Clear high RAM ; $80:88D1..88EA Write a load of 1C2Fh ; $80:88EB..88FD Write 800h bytes of A to $7E:3000 ; $80:88FE..8910 Write 800h bytes of A to $7E:4000 ; $80:8911..8923 Write 800h bytes of A to $7E:6000 ; $80:8924..894C Handle fading out ; $80:894D..896D Handle fading in ; $80:896E..8B19 Clear unused OAM (sprites to Y=F0h), clear OAM data offset ; $80:8B1A..8B4E Clear all OAM high-x bits and sizes ; $80:8B4F..8BB9 Unpack mode 7 DMAs ; $80:8BBA..8BD2 Handle mode 7 DMAs ; $80:8BD3..8C82 Handle mode 7 DMAs continued ; $80:8C83..8CD7 Process $D0,X VRAM writes ; $80:8CD8..8DAB Execute horizontal scrolling DMAs ; $80:8DAC..8EA1 Execute vertical scrolling DMAs ; $80:8EA2..8EF3 Handle $0340,X VRAM reads ; $80:8EF4..8F0B Check for command timer ; $80:8F0C..8FA2 ??? ; $80:8FA3..8FC0 Unused. Changes music song/instruments or music track to A, with an 16-frame delay. Does not stop 0639 from lapping 063B ; $80:8FC1..8FF6 Changes music song/instruments or music track to A, with an 8-frame delay. Makes sure 0639 does not lap 063B ; $80:8FF7..9020 Changes music song/instruments or music track to A, with a Y-frame delay (minimum of 8). Does not stop 0639 from lapping 063B ; $80:9021..902A Sound library 1, $0653 = 0Fh ; $80:902B..9034 Sound library 1, $0653 = 09h ; $80:9035..903E Sound library 1, $0653 = 03h ; $80:903F..9048 Sound library 1, $0653 = 01h ; $80:9049..9050 Sound library 1, $0653 = 06h ; $80:9051..90A2 Sound library 1 ; $80:90A3..90AC Sound library 2, $0653 = 0Fh ; $80:90AD..90B6 Sound library 2, $0653 = 09h ; $80:90B7..90C0 Sound library 2, $0653 = 03h ; $80:90C1..90CA Sound library 2, $0653 = 01h ; $80:90CB..90D2 Sound library 2, $0653 = 06h ; $80:90D3..9124 Sound library 2 ; $80:9125..912E Sound library 3, $0653 = 0Fh ; $80:912F..9138 Sound library 3, $0653 = 09h ; $80:9139..9142 Sound library 3, $0653 = 03h ; $80:9143..914C Sound library 3, $0653 = 01h ; $80:914D..9154 Sound library 3, $0653 = 06h ; $80:9155..91A6 Sound library 3 ; $80:91A7..91A8 NOP : RTS ; $80:91A9..91ED Set up a (H)DMA transfer ; $80:91EE..9339 Update hardware registers ; $80:933A..9375 Update OAM & CGRAM ; $80:9376..9415 Samus' graphics -> VRAM ; $80:9416..9458 Handle misc. animations (spikes, FX1) ; $80:9459..9582 Read controller input. Also a debug branch ; $80:9583..9615 NMI ; $80:9616..9631 [data] Interrupt commands ; $80:9632..966D DMA transfer to VRAM ; $80:966E..967F Interrupt command 00h. Next interrupt command = [$A7] ; $80:9680..968A Interrupt command 02h. Disable horizontal and vertical timer interrupts ; $80:968B..96A8 Interrupt command 04h. Main gameplay, status bar drawing ; $80:96A9..96D2 Interrupt command 06h. Main gameplay, status bar drawn ; $80:96D3..96F0 Interrupt command 08h. Start of room transition, status bar drawing ; $80:96F1..9719 Interrupt command 0Ah. Start of room transition, status bar drawn ; $80:971A..9732 Interrupt command 0Ch. Draygon's room, status bar drawing ; $80:9733..9757 Interrupt command 0Eh. Draygon's room, status bar drawn ; $80:9758..9770 Interrupt command 10h. Vertical room transition, status bar drawing ; $80:9771..97A8 Interrupt command 12h. Vertical room transition, screen drawing ; $80:97A9..97C0 Interrupt command 14h. Vertical room transition, screen drawn ; $80:97C1..97D9 Interrupt command 16h. Horizontal room transition, status bar drawing ; $80:97DA..9809 Interrupt command 18h. Horizontal room transition, screen drawing ; $80:980A..9829 Interrupt command 1Ah. Horizontal room transition, screen drawn ; $80:982A..9840 Enable horizontal and vertical timer interrupts ; $80:9841..985E Enable horizontal and vertical timer interrupts now ; $80:985F..9869 Disable horizontal and vertical timer interrupts ; $80:986A..988A IRQ ; $80:988B..98CA [data] HUD tilemap - top row, never changed ; $80:98CB..998A [data] HUD tilemap - item selector background ; $80:998B..9996 [data] HUD tilemap - auto reserve ; $80:9997..99A2 [data] HUD tilemap - empty auto reserve ; $80:99A3..99AE [data] HUD tilemap - missiles ; $80:99AF..99B6 [data] HUD tilemap - super missiles ; $80:99B7..99BE [data] HUD tilemap - power bombs ; $80:99BF..99C6 [data] HUD tilemap - grapple ; $80:99C7..99CE [data] HUD tilemap - x-ray ; $80:99CF..9A0D Add missiles to HUD WRAM tilemap ; $80:9A0E..9A1D Add super missiles to HUD WRAM tilemap ; $80:9A1E..9A2D Add power bombs to HUD WRAM tilemap ; $80:9A2E..9A3D Add grapple to HUD WRAM tilemap ; $80:9A3E..9A4B Add x-ray to HUD WRAM tilemap ; $80:9A4C..9A78 Add to HUD WRAM tilemap ; $80:9A79..9B43 HUD routine when game is loading ; $80:9B44..9CCD HUD routine when game is paused/running ; $80:9CCE..9CE9 [data] Energy tank icon WRAM tilemap offsets ; $80:9CEA..9D6D Toggle HUD item highlight ; $80:9D6E..9D77 [data] Item WRAM tilemap offsets ; $80:9D78..9D97 Draw three HUD digits ; $80:9D98..9DBE Draw two HUD digits ; $80:9DBF..9DD2 [data] HUD digits tilemap values - Health ; $80:9DD3..9DE6 [data] HUD digits tilemap values - Artillery ; $80:9DE7..9DFA Process timer ; $80:9DFB..9E08 [data] Pointers to timer code ; $80:9E09..9E1B Ceres start timer ; $80:9E1C..9E2E Mother Brain start timer ; $80:9E2F..9E40 Delay timer running/movement ; $80:9E41..9E57 Run timer, delay movement ; $80:9E58..9E8B Move timer, still running ; $80:9E8C..9E92 Set timer to A_high minutes and A_low seconds ; $80:9E93..9EA8 Clear timer RAM ; $80:9EA9..9EEB Finally stop timer movement, still running ; $80:9EEC..9F6B [data] Timer centisecond decrements ; $80:9F6C..9F94 Draw timer ; $80:9F95..9FB0 Draw timer section ; $80:9FB3..9DF3 Draw timer spritemap ; $80:9FD4..9FE7 [data] Timer digits spritemap pointers ; $80:9FE8..A05F [data] Timer digits spritemaps ; $80:A060..A07A [data] Timer TIME spritemap ; $80:A07B..A12A ??? ; $80:A12B..A148 ; $80:A149..A175 ; $80:A176..A1E2 Display the viewable part of the room? ; $80:A1E3..A210 Add VRAM $4800..57FF = 0338h ; $80:A211..A23E Add VRAM $5880..677F = 184Eh ; $80:A23F..A29B VRAM $4800..4FFF = 3838h ; $80:A29C..A2F8 VRAM $5880..5FFF = 184Eh ; $80:A2F9..A339 Calculate layer 2 X position ; $80:A33A..A37A Calculate layer 2 Y position ; $80:A37B..A39F Calculate BG positions ; $80:A3A0..A3AA Updates only BG1 when scrolling, I think ; $80:A3AB..A4BA Updates BG1 and BG2 graphics when scrolling ; $80:A4BB..A527 Calculate blocks scrolled ; $80:A528..A640 Handle autoscrolling when not moving horizontally and part of the screen is has no scroll ; $80:A641..A6BA Handle scrolling when moving and triggered scrolling right ; $80:A6BB..A730 Handle scrolling when moving and triggered scrolling left ; $80:A731..A892 Handle autoscrolling when not moving vertically and part of the screen is has no scroll ; $80:A893..A935 Handle scrolling when moving and triggered scrolling down ; $80:A936..A9AB Handle scrolling when moving and triggered scrolling up ; $80:A9AC..A9D5 Debug scroll position save/loading ; $80:A9D6..ABDA Update background data column ; $80:A9DB..AB6F Update level data column ; $80:AB70..AB74 Update background data row ; $80:AB75..AD1C Update level data row ; $80:AD1D..AD2F Run to 'Fix' doors moving up; redraws top row of blocks ; $80:AD30..AD49 Follow door transition ; $80:AD4A..AD73 Door transition - right ; $80:AD74..AD9D Door transition - left ; $80:AD9E..ADC7 Door transition - down ; $80:ADC8..AE07 Door transition - up ; $80:AE08..AE0F [data] Pointers to door transition code ; $80:AE10..AE28 Save number of blocks scrolled ; $80:AE29..AE4D Update BG scroll offsets ; $80:AE4E..AE75 Follow door transition ; $80:AE76..AE7D [data] Pointers to door transition code ; $80:AE7E..AEC1 Door transition - right ; $80:AEC2..AF01 Door transition - left ; $80:AF02..AF88 Door transition - down ; $80:AF89..B031 Door transition - up ; $80:B032..B0C1 Unused. Mode 7 initialisation? ; $80:B0C2..B0FE Configure mode 7 rotation matrix ; $80:B0FF..B118 Decompression to [PC+3] ; $80:B119..B265 Decompression ; $80:B266..B270 Source bank overflow correction ; $80:B271..B436 Decompression to VRAM ; $80:B437..BC36 [data] Tilemap for failed NTSC/PAL check ; $80:BC37..C436 [data] Tilemap for failed SRAM mapping check ; $80:C437..C4B4 Load new save/elevator ; $80:C4B5..C4C4 [data] Pointers to each area's saves/elevators ; $80:C4C5..C5CE [data] Crateria saves/elevators ; $80:C5CF..C6C8 [data] Brinstar saves/elevators ; $80:C6D9..C81A [data] Norfair saves/elevators ; $80:C81B..C916 [data] Wrecked Ship saves/elevators ; $80:C917..CA2E [data] Maridia saves/elevators ; $80:CA2F..CB2A [data] Tourian saves/elevators ; $80:CB2B..CC18 [data] Ceres saves/elevators ; $80:CC19..CD06 [data] Debug saves/elevators ; $80:CD07..CD45 Set elevators as used ; $80:CD46..CD51 [data] Pointers to each area's elevator bits ; $80:CD52..CD65 [data] Crateria elevator bits ; $80:CD66..CD75 [data] Brinstar elevator bits ; $80:CD76..CD81 [data] Norfair elevator bits ; $80:CD82..CD85 [data] Maridia elevator bits ; $80:CD86..CD89 [data] Tourian elevator bits ; $80:CD8A..CD8D [data] Wrecked Ship elevator bits ; $80:CD8E..FFBF Free space ; $80:FFC0..FFFF [data] Game header } $808000 dw 0000 ; Skip NTSC/PAL and SRAM mapping check $808002 dw 0000 ; Demo recorder $808004 dw 0000 ; Debug mode $808006 dw 0000 ; Debug scrolling $808008 dw 0000 ; Something for the audio man ;;; Load new music ;;; { ;; Takes parameter (CF8000h) $80800A A3 02 LDA $02,s [$7E:1FFE] ;\ $80800C 85 04 STA $04 [$7E:0004] ;| $80800E A3 01 LDA $01,s [$7E:1FFD] ;} Return address -> $03..$05 $808010 85 03 STA $03 [$7E:0003] ;/ $808012 18 CLC ;\ $808013 69 03 00 ADC #$0003 ;} Realign return address $808016 83 01 STA $01,s [$7E:1FFD] ;/ $808018 A0 01 00 LDY #$0001 ;\ $80801B B7 03 LDA [$03],y[$80:845D] ;| $80801D 85 00 STA $00 [$7E:0000] ;| $80801F C8 INY ;} [[$03]+1] (parameter) -> $00..$02 $808020 B7 03 LDA [$03],y[$80:845E] ;| $808022 85 01 STA $01 [$7E:0001] ;/ $808024 20 28 80 JSR $8028 [$80:8028] ; More subroutining $808027 6B RTL } ;;; Upload to APU ;;; { ;; Takes a parameter in $00..$02: Long address of data $808028 AF 08 80 80 LDA $808008[$80:8008] ;\ $80802C F0 01 BEQ $01 [$802F] ;} Return if $80:8008 is set $80802D 60 RTS ;/ $80802F 08 PHP $808030 8B PHB $808031 C2 30 REP #$30 $808033 A9 FF FF LDA #$FFFF ;\ $808036 8F 17 06 00 STA $000617[$7E:0617] ;} Disable debug soft resets $80803A E2 20 SEP #$20 $80803C C2 10 REP #$10 $80803E A9 FF LDA #$FF ;\ $808040 8F 40 21 00 STA $002140[$7E:2140] ;} Send FF to APUIO0 (request APU upload) $808044 A4 00 LDY $00 [$7E:0000] ; Y = parameter short address $808046 A5 02 LDA $02 [$7E:0002] ;\ $808048 48 PHA ;} Set DB to parameter bank $808049 AB PLB ;/ $80804A C2 30 REP #$30 $80804C 20 59 80 JSR $8059 [$80:8059] ; More subroutining $80804F A9 00 00 LDA #$0000 ;\ $808052 8F 17 06 00 STA $000617[$7E:0617] ;} Enable debug soft resets $808056 AB PLB $808057 28 PLP $808058 60 RTS } ;;; Send APU data ;;; { ;; Takes parameters: Y = address of data, DB = bank of data ; Wait until APU sends AA BB through APUIO0..1 signalling it's ready for communication ; Kick = CC ; Destination address is sent through APUIO2..3 ; Send Kick through APUIO0, signalling the desination address has been sent ; Wait until APU echoes Kick back through APUIO0, signalling it's ready to receive data ; Index=0 ; Send databyte through APUIO1 ; Send Index through APUIO0, signalling to start data transfer ; Wait until API echoes Index back through APUIO0, signalling it's ready to receive next byte ; Increment Index ; Repeat until last databyte for that destination has been sent ; Increment Index (and again if reulting in 0) ; Kick = Index, signalling current datablock has finished ; Repeat until all data has been sent ; Send entry address through APUIO2..3 ; Send 00 through APUIO1, signalling data has finished transferring ; Send Kick through APUIO0 ; (Optionally wait until APU echoes Kick back through APUIO0) $808059 08 PHP $80805A C2 30 REP #$30 $80805C A9 00 30 LDA #$3000 ;\ $80805F 8F 41 06 00 STA $000641[$7E:0641] ;} Max number of attempts to read AA BB from APU registers $808063 A9 AA BB LDA #$BBAA ;\ $808066 CF 40 21 00 CMP $002140[$7E:2140] ;} If APU registers != AA BB: $80806A F0 0D BEQ $0D [$8079] ;/ $80806C AF 41 06 00 LDA $000641[$7E:0641] ;\ $808070 3A DEC A ;| $808071 8F 41 06 00 STA $000641[$7E:0641] ;} Try again until exceeded max number of attempts $808075 D0 EC BNE $EC [$8063] ;/ $808077 80 FE BRA $FE [$8077] ; If exceeded max number of attemps: crash $808079 E2 20 SEP #$20 $80807B A9 CC LDA #$CC ; Set CCh as stack variable $80807D 80 2F BRA $2F [$80AE] ; Branch to $80AE $80807F B9 00 00 LDA $0000,y[$CF:8004] ;\ $808082 20 03 81 JSR $8103 [$80:8103] ;| $808085 EB XBA ;} A = Y[4] 00 $808086 A9 00 LDA #$00 ;/ $808088 80 0F BRA $0F [$8099] ; Branch to $8099 $80808A EB XBA ;\ $80808B B9 00 00 LDA $0000,y[$CF:8005] ;| $80808E 20 03 81 JSR $8103 [$80:8103] ;} A = Y[5] xx $808091 EB XBA ;/ $808092 CF 40 21 00 CMP $002140[$7E:2140] ;\ $808096 D0 FA BNE $FA [$8092] ;} Wait until APUIO0 == value written to APUIO0 $808098 1A INC A $808099 C2 20 REP #$20 $80809B 8F 40 21 00 STA $002140[$7E:2140] ; APUIO0..1 = A $80809F E2 20 SEP #$20 $8080A1 CA DEX ; Decrement X (Y[0]) $8080A2 D0 E6 BNE $E6 [$808A] ; If X != 0: branch to $808A $8080A4 CF 40 21 00 CMP $002140[$7E:2140] ;\ $8080A8 D0 FA BNE $FA [$80A4] ;} Wait until APUIO0 == value written to APUIO0 $8080AA 69 03 ADC #$03 ; A += 3 $8080AC F0 FC BEQ $FC [$80AA] ; Ensure A != 0 $8080AE 48 PHA $8080AF C2 20 REP #$20 $8080B1 B9 00 00 LDA $0000,y[$CF:8000] ;\ $8080B4 20 00 81 JSR $8100 [$80:8100] ;} X = Y[1] Y[0], size of block I think $8080B7 AA TAX ;/ $8080B8 B9 00 00 LDA $0000,y[$CF:8002] ;\ $8080BB 20 00 81 JSR $8100 [$80:8100] ;} APUIO2..3 = Y[2..3] $8080BE 8F 42 21 00 STA $002142[$7E:2142] ;/ $8080C2 E2 20 SEP #$20 $8080C4 E0 01 00 CPX #$0001 ;\ $8080C7 A9 00 LDA #$00 ;| $8080C9 2A ROL A ;} If X != 0: set APUIO1, else clear it $8080CA 8F 41 21 00 STA $002141[$7E:2141] ;/ $8080CE 69 7F ADC #$7F ; Www...wuh? $8080D0 68 PLA ;\ $8080D1 8F 40 21 00 STA $002140[$7E:2140] ;} APUIO0 = stack variable $8080D5 DA PHX $8080D6 A2 00 10 LDX #$1000 ; Max number of attempts to read the value written to APUIO0 from APUIO0 $8080D9 CA DEX ;\ $8080DA F0 16 BEQ $16 [$80F2] ;} If exceeded maximum number of attempts: clear APUIO1..3 and return $8080DC CF 40 21 00 CMP $002140[$7E:2140] ;\ $8080E0 D0 F7 BNE $F7 [$80D9] ;} If APUIO0 != value written to APUIO0: try again $8080E2 FA PLX $8080E3 70 9A BVS $9A [$807F] ; If APIIO1 was set: branch to $807F $8080E5 E2 20 SEP #$20 $8080E7 9C 41 21 STZ $2141 [$7E:2141] ;\ $8080EA 9C 42 21 STZ $2142 [$7E:2142] ;| $8080ED 9C 43 21 STZ $2143 [$7E:2143] ;} Else: clear APUIO1..3 and return $8080F0 28 PLP ;| $8080F1 60 RTS ;/ $8080F2 E2 20 SEP #$20 $8080F4 9C 41 21 STZ $2141 $8080F7 9C 42 21 STZ $2142 $8080FA 9C 43 21 STZ $2143 $8080FD FA PLX $8080FE 28 PLP $8080FF 60 RTS } ;;; Increment Y twice, bank overflow check ;;; { ; Only increments Y once if overflows bank first time $808100 C8 INY $808101 F0 04 BEQ $04 [$8107] ; Increment Y, bank overflow check $808103 C8 INY $808104 F0 01 BEQ $01 [$8107] $808106 60 RTS $808107 E6 02 INC $02 [$7E:0002] ;\ $808109 D4 01 PEI ($01) [$D080] ;| $80810B AB PLB ;} Increment $02 and pull it into DB $80810C AB PLB ;/ $80810D A0 00 80 LDY #$8000 ; Reset to 8000h $808110 60 RTS } ;;; Random number generator ;;; { ;; Returns A: New random number ; Random number = [Low byte]*5 + (([High byte]*5)_low+1 << 16) + 17 $808111 E2 20 SEP #$20 $808113 AD E5 05 LDA $05E5 [$7E:05E5] ;\ $808116 8D 02 42 STA $4202 [$7E:4202] ;} Random number low byte $808119 A9 05 LDA #$05 ;\ $80811B 8D 03 42 STA $4203 [$7E:4203] ;} * 5 $80811E EA NOP ; Waste cycles for multiplication $80811F C2 20 REP #$20 ;\ $808121 AD 16 42 LDA $4216 [$7E:4216] ;} Push 16-bit result RN_low * 5 $808124 48 PHA ;/ $808125 E2 20 SEP #$20 $808127 AD E6 05 LDA $05E6 [$7E:05E6] ;\ $80812A 8D 02 42 STA $4202 [$7E:4202] ;} RN_high $80812D A9 05 LDA #$05 ;\ $80812F 8D 03 42 STA $4203 [$7E:4203] ;} * 5 $808132 EB XBA ;\ $808133 EA NOP ;} Waste cycles for multiplication $808134 AD 16 42 LDA $4216 [$7E:4216] ; 8-bit result RN_high * 5 $808137 38 SEC ;\ $808138 63 02 ADC $02,s [$7E:1FFB] ;} Sum with 1 to the high byte of pushed value $80813A 83 02 STA $02,s [$7E:1FFB] ;/ $80813C C2 20 REP #$20 ;\ $80813E 68 PLA ;} 16-bit result $80813F 69 11 00 ADC #$0011 ; Further add 17 $808142 8D E5 05 STA $05E5 [$7E:05E5] ; Store back to RAM $808145 6B RTL } ;;; Update held input ;;; { ;; Takes parameter in A: number of frames defining held ; Called by gamestate 0Fh (paused screen) with A=0003 ; [$8B] & ![$8F], the input pressed, but not newly: the /held/ input $808146 08 PHP $808147 8B PHB $808148 C2 30 REP #$30 $80814A DA PHX $80814B 4B PHK $80814C AB PLB $80814D 8D DD 05 STA $05DD [$7E:05DD] $808150 A5 8B LDA $8B [$7E:008B] ;\ $808152 85 12 STA $12 [$7E:0012] ;| $808154 A5 8F LDA $8F [$7E:008F] ;| $808156 14 12 TRB $12 [$7E:0012] ;| $808158 A5 12 LDA $12 [$7E:0012] ;} If held input == previous held input: $80815A CD D9 05 CMP $05D9 [$7E:05D9] ;| $80815D 8D D9 05 STA $05D9 [$7E:05D9] ; } $05D9 = held input $808160 D0 13 BNE $13 [$8175] ;/ $808162 CE DB 05 DEC $05DB [$7E:05DB] ; Decrement timer $808165 10 14 BPL $14 [$817B] ; If timer < 0: $808167 9C DB 05 STZ $05DB [$7E:05DB] ; Clear timer $80816A AE DF 05 LDX $05DF [$7E:05DF] ;\ $80816D 8E E3 05 STX $05E3 [$7E:05E3] ;} Store previous timed input $808170 8D DF 05 STA $05DF [$7E:05DF] ; Store timed input $808173 80 09 BRA $09 [$817E] $808175 AD DD 05 LDA $05DD [$7E:05DD] ;\ Else (held input != previous held input): $808178 8D DB 05 STA $05DB [$7E:05DB] ;} Store parameter to timer $80817B 9C DF 05 STZ $05DF [$7E:05DF] ; If timer >= 0: Clear timed input $80817E AD DF 05 LDA $05DF [$7E:05DF] ;\ $808181 4D E3 05 EOR $05E3 [$7E:05E3] ;| $808184 2D DF 05 AND $05DF [$7E:05DF] ;} Store newly held timed input $808187 8D E1 05 STA $05E1 [$7E:05E1] ;/ $80818A FA PLX $80818B AB PLB $80818C 28 PLP $80818D 6B RTL } ;;; Change nth bit to address offset and mask ;;; { ; $05E7 = bit (A&7), X = A>>3; bit15 is forbidden (why?) ; Most often used for testing or setting specific bits in a bit array $80818E AA TAX $80818F 10 01 BPL $01 [$8192] $808191 00 BRK $808192 9C E7 05 STZ $05E7 [$7E:05E7] $808195 48 PHA $808196 29 07 00 AND #$0007 $808199 38 SEC $80819A 2E E7 05 ROL $05E7 [$7E:05E7] $80819D 3A DEC A $80819E 10 FA BPL $FA [$819A] $8081A0 68 PLA $8081A1 4A LSR A $8081A2 4A LSR A $8081A3 4A LSR A $8081A4 AA TAX $8081A5 6B RTL } ;;; Set boss bits in A for current area ($7E:D828,X) ;;; { $8081A6 DA PHX $8081A7 5A PHY $8081A8 08 PHP $8081A9 E2 20 SEP #$20 $8081AB 8D E7 05 STA $05E7 [$7E:05E7] $8081AE AE 9F 07 LDX $079F [$7E:079F] $8081B1 BF 28 D8 7E LDA $7ED828,x[$7E:D82E] $8081B5 0D E7 05 ORA $05E7 [$7E:05E7] $8081B8 9F 28 D8 7E STA $7ED828,x[$7E:D82E] $8081BC 28 PLP $8081BD 7A PLY $8081BE FA PLX $8081BF 6B RTL } ;;; Clear boss bits in A for current area ($7E:D828,X) ;;; { $8081C0 DA PHX $8081C1 5A PHY $8081C2 08 PHP $8081C3 E2 20 SEP #$20 $8081C5 49 FF EOR #$FF $8081C7 8D E7 05 STA $05E7 [$7E:05E7] $8081CA AE 9F 07 LDX $079F [$7E:079F] $8081CD BF 28 D8 7E LDA $7ED828,x[$7E:D828] $8081D1 2D E7 05 AND $05E7 [$7E:05E7] $8081D4 9F 28 D8 7E STA $7ED828,x[$7E:D828] $8081D8 28 PLP $8081D9 7A PLY $8081DA FA PLX $8081DB 6B RTL } ;;; Checks if the boss bits for the current area matches any bits in A. SEC if there's a match ;;; { $8081DC DA PHX $8081DD 5A PHY $8081DE 08 PHP $8081DF E2 20 SEP #$20 $8081E1 8D E7 05 STA $05E7 [$7E:05E7] $8081E4 AE 9F 07 LDX $079F [$7E:079F] $8081E7 BF 28 D8 7E LDA $7ED828,x[$7E:D82E] $8081EB 2D E7 05 AND $05E7 [$7E:05E7] $8081EE D0 05 BNE $05 [$81F5] $8081F0 28 PLP $8081F1 7A PLY $8081F2 FA PLX $8081F3 18 CLC $8081F4 6B RTL $8081F5 28 PLP $8081F6 7A PLY $8081F7 FA PLX $8081F8 38 SEC $8081F9 6B RTL } ;;; Marks an event as happened. Event bit # must be stored in A ;;; { $8081FA DA PHX $8081FB 5A PHY $8081FC 08 PHP $8081FD C2 30 REP #$30 $8081FF 22 8E 81 80 JSL $80818E[$80:818E] $808203 BF 20 D8 7E LDA $7ED820,x[$7E:D820] $808207 0D E7 05 ORA $05E7 [$7E:05E7] $80820A 9F 20 D8 7E STA $7ED820,x[$7E:D820] $80820E 28 PLP $80820F 7A PLY $808210 FA PLX $808211 6B RTL } ;;; Marks an event as not happened. Event bit # must be stored in A ;;; { $808212 DA PHX $808213 5A PHY $808214 08 PHP $808215 C2 30 REP #$30 $808217 22 8E 81 80 JSL $80818E[$80:818E] $80821B AD E7 05 LDA $05E7 [$7E:05E7] $80821E 49 FF FF EOR #$FFFF $808221 8D E7 05 STA $05E7 [$7E:05E7] $808224 BF 20 D8 7E LDA $7ED820,x[$7E:D820] $808228 2D E7 05 AND $05E7 [$7E:05E7] $80822B 9F 20 D8 7E STA $7ED820,x[$7E:D820] $80822F 28 PLP $808230 7A PLY $808231 FA PLX $808232 6B RTL } ;;; Checks if an event has happened. Event bit # must be stored in A. CLC if 0, SEC if 1 ;;; { $808233 DA PHX $808234 5A PHY $808235 08 PHP $808236 C2 30 REP #$30 $808238 22 8E 81 80 JSL $80818E[$80:818E] $80823C BF 20 D8 7E LDA $7ED820,x[$7E:D821] $808240 2D E7 05 AND $05E7 [$7E:05E7] $808243 D0 05 BNE $05 [$824A] $808245 28 PLP $808246 7A PLY $808247 FA PLX $808248 18 CLC $808249 6B RTL $80824A 28 PLP $80824B 7A PLY $80824C FA PLX $80824D 38 SEC $80824E 6B RTL } ;;; Write 'supermetroid' to SRAM ($70:1FE0..1FEB) ;;; { $80824F DA PHX $808250 A2 0A 00 LDX #$000A $808253 BF B9 82 80 LDA $8082B9,x[$80:82C3] $808257 9F E0 1F 70 STA $701FE0,x[$7E:1FEA] $80825B CA DEX $80825C CA DEX $80825D 10 F4 BPL $F4 [$8253] $80825F FA PLX $808260 6B RTL } ;;; Check for non-corrupt SRAM ;;; { $808261 DA PHX $808262 A9 03 00 LDA #$0003 ;\ $808265 8D 59 1F STA $1F59 [$7E:1F59] ;} $1F59 = 3 $808268 A9 00 00 LDA #$0000 ;\ $80826B 22 85 80 81 JSL $818085[$81:8085] ;} Load SRAM slot A $80826F 90 23 BCC $23 [$8294] ; If not corrupt, branch to $8294 $808271 A9 01 00 LDA #$0001 ;\ $808274 22 85 80 81 JSL $818085[$81:8085] ;} Load SRAM slot B $808278 90 1A BCC $1A [$8294] ; If not corrupt, branch to $8294 $80827A A9 02 00 LDA #$0002 ;\ $80827D 22 85 80 81 JSL $818085[$81:8085] ;} Load SRAM slot C $808281 90 11 BCC $11 [$8294] ; If not corrupt, branch to $8294 $808283 A2 0A 00 LDX #$000A ; If all SRAM is corrupt: $808286 BF AD 82 80 LDA $8082AD,x[$80:949A] ;\ $80828A 9F E0 1F 70 STA $701FE0,x[$70:31CD] ;| $80828E CA DEX ;| $80828F CA DEX ;} Write 'madadameyohn' to SRAM ($70:1FE0..1FEB) and return $808290 10 F4 BPL $F4 [$8286] ;| $808292 FA PLX ;| $808293 6B RTL ;/ $808294 A2 0A 00 LDX #$000A $808297 BF E0 1F 70 LDA $701FE0,x[$7E:1FEA] ;\ $80829B DF B9 82 80 CMP $8082B9,x[$80:82C3] ;| $80829F D0 0A BNE $0A [$82AB] ;| ;} If $70:1FE0..1FEB == 'supermetroid': $8082A1 CA DEX ;| $8082A2 CA DEX ;| $8082A3 10 F2 BPL $F2 [$8297] ;/ $8082A5 A9 04 00 LDA #$0004 ;\ $8082A8 8D 59 1F STA $1F59 [$7E:1F59] ;} $1F59 = 4 $8082AB FA PLX $8082AC 6B RTL $8082AD dw 616D, 6164, 6164, 656D, 6F79, 6E68 ; madadameyohn $8082B9 dw 7573, 6570, 6D72, 7465, 6F72, 6469 ; supermetroid } ;;; Wait until the end of a VBlank ;;; { $8082C5 48 PHA $8082C6 08 PHP $8082C7 E2 20 SEP #$20 $8082C9 AD 12 42 LDA $4212 [$7E:4212] $8082CC 10 FB BPL $FB [$82C9] $8082CE AD 12 42 LDA $4212 [$7E:4212] $8082D1 30 FB BMI $FB [$82CE] $8082D3 28 PLP $8082D4 68 PLA $8082D5 6B RTL } ;;; Multiplies A and Y together (16-bit * 16-bit). Result in $05F1-$05F4 ;;; { ; Not accurate. Let a and c be the low bytes, b and d the high bytes: for (a + b)(c + d), the bc+ad doesn't add its carry to bd $8082D6 DA PHX $8082D7 8D E9 05 STA $05E9 [$7E:05E9] ; Let $05E9 = a + 0x100b $8082DA 8C EB 05 STY $05EB [$7E:05EB] ; Let $05EB = c + 0x100d $8082DD 9C F1 05 STZ $05F1 [$7E:05F1] ;\ $8082E0 9C F3 05 STZ $05F3 [$7E:05F3] ;} Initialise result $8082E3 E2 10 SEP #$10 ; Set indices to 8-bit $8082E5 AC EB 05 LDY $05EB [$7E:05EB] ;\ $8082E8 8C 02 42 STY $4202 [$7E:4202] ;| $8082EB AC E9 05 LDY $05E9 [$7E:05E9] ;| $8082EE 8C 03 42 STY $4203 [$7E:4203] ;| $8082F1 EA NOP ;} Result = ac $8082F2 EA NOP ;| $8082F3 EA NOP ;| $8082F4 AD 16 42 LDA $4216 [$7E:4216] ;| $8082F7 8D F1 05 STA $05F1 [$7E:05F1] ;/ $8082FA AC EA 05 LDY $05EA [$7E:05EA] ;\ $8082FD 8C 03 42 STY $4203 [$7E:4203] ;| $808300 EA NOP ;| $808301 AD F2 05 LDA $05F2 [$7E:05F2] ;} Result += 0x100bc $808304 18 CLC ;| $808305 6D 16 42 ADC $4216 [$7E:4216] ;| $808308 8D F2 05 STA $05F2 [$7E:05F2] ;/ $80830B AC EC 05 LDY $05EC [$7E:05EC] ;\ $80830E 8C 02 42 STY $4202 [$7E:4202] ;| $808311 AC E9 05 LDY $05E9 [$7E:05E9] ;| $808314 8C 03 42 STY $4203 [$7E:4203] ;| $808317 EA NOP ;} Result += 0x100ad $808318 AD F2 05 LDA $05F2 [$7E:05F2] ;| $80831B 18 CLC ;| $80831C 6D 16 42 ADC $4216 [$7E:4216] ;| $80831F 8D F2 05 STA $05F2 [$7E:05F2] ;/ $808322 AC EA 05 LDY $05EA [$7E:05EA] ;\ $808325 8C 03 42 STY $4203 [$7E:4203] ;| $808328 EA NOP ;| $808329 EA NOP ;| $80832A AD F3 05 LDA $05F3 [$7E:05F3] ;} Result += 0x10000bd $80832D 18 CLC ;| $80832E 6D 16 42 ADC $4216 [$7E:4216] ;| $808331 8D F3 05 STA $05F3 [$7E:05F3] ;/ $808334 C2 30 REP #$30 $808336 FA PLX $808337 6B RTL } ;;; Wait for IRQ ;;; { $808338 08 PHP $808339 8B PHB $80833A 4B PHK $80833B AB PLB $80833C E2 30 SEP #$30 $80833E A9 01 LDA #$01 $808340 8D B4 05 STA $05B4 [$7E:05B4] $808343 AD B4 05 LDA $05B4 [$7E:05B4] $808346 D0 FB BNE $FB [$8343] $808348 AB PLB $808349 28 PLP $80834A 6B RTL } ;;; Enable NMI with $84 options ;;; { $80834B 08 PHP $80834C 8B PHB $80834D 4B PHK $80834E AB PLB $80834F E2 20 SEP #$20 $808351 A5 84 LDA $84 [$7E:0084] $808353 09 80 ORA #$80 $808355 8D 00 42 STA $4200 [$7E:4200] $808358 85 84 STA $84 [$7E:0084] $80835A AB PLB $80835B 28 PLP $80835C 6B RTL } ;;; Disable NMI with $84 options { $80835D 08 PHP $80835E 8B PHB $80835F 4B PHK $808360 AB PLB $808361 E2 20 SEP #$20 $808363 A5 84 LDA $84 [$7E:0084] $808365 29 7F AND #$7F $808367 8D 00 42 STA $4200 [$7E:4200] $80836A 85 84 STA $84 [$7E:0084] $80836C AB PLB $80836D 28 PLP $80836E 6B RTL } ;;; Set force blank ;;; { $80836F 08 PHP $808370 8B PHB $808371 4B PHK $808372 AB PLB $808373 E2 20 SEP #$20 $808375 A5 51 LDA $51 [$7E:0051] $808377 09 80 ORA #$80 $808379 85 51 STA $51 [$7E:0051] $80837B 22 38 83 80 JSL $808338[$80:8338] $80837F AB PLB $808380 28 PLP $808381 6B RTL } ;;; Clear force blank ;;; { $808382 08 PHP $808383 8B PHB $808384 4B PHK $808385 AB PLB $808386 E2 20 SEP #$20 $808388 A5 51 LDA $51 [$7E:0051] $80838A 29 7F AND #$7F $80838C 85 51 STA $51 [$7E:0051] $80838E 22 38 83 80 JSL $808338[$80:8338] $808392 AB PLB $808393 28 PLP $808394 6B RTL } ;;; DMA, slot 1, 200h bytes from $7E:C000 through $2122 (CGRAM Data Write) ;;; { $808395 08 PHP $808396 E2 10 SEP #$10 $808398 C2 20 REP #$20 $80839A A9 00 22 LDA #$2200 $80839D 8D 10 43 STA $4310 [$7E:4310] $8083A0 A9 00 C0 LDA #$C000 $8083A3 8D 12 43 STA $4312 [$7E:4312] $8083A6 A2 7E LDX #$7E $8083A8 8E 14 43 STX $4314 [$7E:4314] $8083AB A9 00 02 LDA #$0200 $8083AE 8D 15 43 STA $4315 [$7E:4315] $8083B1 A2 00 LDX #$00 $8083B3 8E 21 21 STX $2121 [$7E:2121] $8083B6 A2 02 LDX #$02 $8083B8 8E 0B 42 STX $420B [$7E:420B] $8083BB 28 PLP $8083BC 6B RTL } ;;; 8-bit write Y bytes of A to $00:X ;;; { $8083BD 08 PHP $8083BE 8B PHB $8083BF 4B PHK $8083C0 AB PLB $8083C1 E2 20 SEP #$20 $8083C3 C2 10 REP #$10 $8083C5 9F 00 00 00 STA $000000,x[$00:11ED] $8083C9 E8 INX $8083CA 88 DEY $8083CB D0 F8 BNE $F8 [$83C5] $8083CD AB PLB $8083CE 28 PLP $8083CF 6B RTL } ;;; 16-bit write Y bytes of A to $00:X ;;; { $8083D0 08 PHP $8083D1 8B PHB $8083D2 4B PHK $8083D3 AB PLB $8083D4 C2 30 REP #$30 $8083D6 9F 00 00 00 STA $000000,x[$00:11ED] $8083DA E8 INX $8083DB E8 INX $8083DC 88 DEY $8083DD 88 DEY $8083DE D0 F6 BNE $F6 [$83D6] $8083E0 AB PLB $8083E1 28 PLP $8083E2 6B RTL } ;;; 8-bit write Y bytes of A to $7E:X ;;; { $8083E3 08 PHP $8083E4 8B PHB $8083E5 4B PHK $8083E6 AB PLB $8083E7 E2 20 SEP #$20 $8083E9 C2 10 REP #$10 $8083EB 9F 00 00 7E STA $7E0000,x[$7E:11ED] $8083EF E8 INX $8083F0 88 DEY $8083F1 D0 F8 BNE $F8 [$83EB] $8083F3 AB PLB $8083F4 28 PLP $8083F5 6B RTL } ;;; 16-bit write Y bytes of A to $7E:X ;;; { $8083F6 08 PHP $8083F7 8B PHB $8083F8 4B PHK $8083F9 AB PLB $8083FA C2 30 REP #$30 $8083FC 9F 00 00 7E STA $7E0000,x[$7E:3000] $808400 E8 INX $808401 E8 INX $808402 88 DEY $808403 88 DEY $808404 D0 F6 BNE $F6 [$83FC] $808406 AB PLB $808407 28 PLP $808408 6B RTL } ;;; 16-bit write Y bytes of A to $7F:X ;;; { $808409 08 PHP $80840A 8B PHB $80840B 4B PHK $80840C AB PLB $80840D C2 30 REP #$30 $80840F 9F 00 00 7F STA $7F0000,x[$7F:11ED] $808413 E8 INX $808414 E8 INX $808415 88 DEY $808416 88 DEY $808417 D0 F6 BNE $F6 [$840F] $808419 AB PLB $80841A 28 PLP $80841B 6B RTL } ;;; Boot ;;; { $80841C 78 SEI ; Enable interrupts $80841D 18 CLC ;\ $80841E FB XCE ;} Enable native mode $80841F 5C 23 84 80 JML $808423[$80:8423] ; Execute in bank $80 (FastROM) $808423 E2 20 SEP #$20 $808425 A9 01 LDA #$01 ;\ $808427 8D 0D 42 STA $420D [$7E:420D] ;} Enable FastROM $80842A 85 86 STA $86 [$7E:0086] ; Mirror of ROM access speed $80842C C2 30 REP #$30 $80842E A2 FF 1F LDX #$1FFF ;\ $808431 9A TXS ;} Allocate stack memory $808432 A9 00 00 LDA #$0000 ;\ $808435 5B TCD ;} Clear direct page $808436 4B PHK $808437 AB PLB $808438 E2 30 SEP #$30 $80843A A2 04 LDX #$04 ;\ ;| $80843C AD 12 42 LDA $4212 [$7E:4212] ;| $80843F 10 FB BPL $FB [$843C] ;| ;} Wait 3 frames, then for the start of VBlank $808441 AD 12 42 LDA $4212 [$7E:4212] ;| $808444 30 FB BMI $FB [$8441] ;| $808446 CA DEX ;| $808447 D0 F3 BNE $F3 [$843C] ;/ $808449 C2 30 REP #$30 $80844B A2 FE 1F LDX #$1FFE ;\ ;| $80844E 9E 00 00 STZ $0000,x[$7E:1FFE] ;| $808451 CA DEX ;} Clear $7E:0000..1FFF $808452 CA DEX ;| $808453 10 F9 BPL $F9 [$844E] ;/ $808455 22 46 91 8B JSL $8B9146[$8B:9146] ; ??? (displays Nintendo) $808459 22 0A 80 80 JSL $80800A[$80:800A] ;\ $80845D dl CF8000 ;} Music initialisation $808460 80 20 BRA $20 [$8482] } ;;; Soft reset ;;; { $808462 78 SEI ; Enable interrupts $808463 18 CLC ;\ $808464 FB XCE ;} Enable native mode $808465 C2 30 REP #$30 $808467 A2 FF 1F LDX #$1FFF ;\ $80846A 9A TXS ;} Allocate stack memory $80846B A9 00 00 LDA #$0000 ;\ $80846E 5B TCD ;} Clear direct page $80846F 4B PHK $808470 AB PLB $808471 E2 30 SEP #$30 $808473 A2 04 LDX #$04 ;\ ;| $808475 AD 12 42 LDA $4212 [$80:4212] ;| $808478 10 FB BPL $FB [$8475] ;| ;} Wait 3 frames, then for the start of VBlank $80847A AD 12 42 LDA $4212 [$80:4212] ;| $80847D 30 FB BMI $FB [$847A] ;| $80847F CA DEX ;| $808480 D0 F3 BNE $F3 [$8475] ;/ $808482 E2 20 SEP #$20 $808484 A9 8F LDA #$8F ;\ $808486 8D 00 21 STA $2100 [$7E:2100] ;} Set screen display: max brightness, force blank; triggers OAM Address Reset $808489 C2 30 REP #$30 $80848B F4 00 7E PEA $7E00 $80848E AB PLB $80848F AB PLB $808490 A2 FE 1F LDX #$1FFE $808493 9E 00 00 STZ $0000,x[$7E:1FFE] ;\ $808496 9E 00 20 STZ $2000,x[$7E:3FFE] ;| $808499 9E 00 40 STZ $4000,x[$7E:5FFE] ;| $80849C 9E 00 60 STZ $6000,x[$7E:7FFE] ;| $80849F 9E 00 80 STZ $8000,x[$7E:9FFE] ;| $8084A2 9E 00 A0 STZ $A000,x[$7E:BFFE] ;} Clear bank $7E $8084A5 9E 00 C0 STZ $C000,x[$7E:DFFE] ;| $8084A8 9E 00 E0 STZ $E000,x[$7E:FFFE] ;| $8084AB CA DEX ;| $8084AC CA DEX ;| $8084AD 10 E4 BPL $E4 [$8493] ;/ $8084AF 4B PHK $8084B0 AB PLB $8084B1 E2 30 SEP #$30 $8084B3 9C 00 42 STZ $4200 [$7E:4200] ;\ $8084B6 64 84 STZ $84 [$7E:0084] ;} Disable NMI and auto-joypad read $8084B8 A9 8F LDA #$8F ;\ $8084BA 85 51 STA $51 [$7E:0051] ;} Set screen display: max brightness, force blank $8084BC 20 5D 87 JSR $875D [$80:875D] ; Initialise $4200..420D $8084BF 20 92 87 JSR $8792 [$80:8792] ; Initialise $2100..2133 $8084C2 20 D1 88 JSR $88D1 [$80:88D1] ; Write a load of 1C2Fh $8084C5 E2 20 SEP #$20 $8084C7 9C 43 06 STZ $0643 [$7E:0643] ;\ $8084CA 9C 44 06 STZ $0644 [$7E:0644] ;| $8084CD 9C 45 06 STZ $0645 [$7E:0645] ;| $8084D0 9C 46 06 STZ $0646 [$7E:0646] ;| $8084D3 9C 47 06 STZ $0647 [$7E:0647] ;| $8084D6 9C 48 06 STZ $0648 [$7E:0648] ;| $8084D9 9C 49 06 STZ $0649 [$7E:0649] ;| $8084DC 9C 4A 06 STZ $064A [$7E:064A] ;| $8084DF 9C 4B 06 STZ $064B [$7E:064B] ;| $8084E2 9C 4D 06 STZ $064D [$7E:064D] ;} Clear a load of audio variables $8084E5 9C 4E 06 STZ $064E [$7E:064E] ;| $8084E8 9C 4F 06 STZ $064F [$7E:064F] ;| $8084EB 9C 50 06 STZ $0650 [$7E:0650] ;| $8084EE 9C 51 06 STZ $0651 [$7E:0651] ;| $8084F1 9C 52 06 STZ $0652 [$7E:0652] ;| $8084F4 9C 56 06 STZ $0656 [$7E:0656] ;| $8084F7 9C 66 06 STZ $0666 [$7E:0666] ;| $8084FA 9C 76 06 STZ $0676 [$7E:0676] ;/ $8084FD C2 20 REP #$20 $8084FF 9C 90 05 STZ $0590 [$7E:0590] ; Clear OAM index $808502 64 53 STZ $53 [$7E:0053] ; Clear ??? $808504 22 1A 8B 80 JSL $808B1A[$80:8B1A] ; Clear OAM high x bits and sizes $808508 22 6E 89 80 JSL $80896E[$80:896E] ; Cleam OAM (sprites to Y=F0h) $80850C 9C 1D 07 STZ $071D [$7E:071D] ; Clear reload Samus sprite flags $80850F 9C 1F 07 STZ $071F [$7E:071F] ;\ $808512 9C 21 07 STZ $0721 [$7E:0721] ;} Clear Samus sprite DMA data pointers $808515 22 4B 83 80 JSL $80834B[$80:834B] ; Enable NMI $808519 C2 30 REP #$30 $80851B 9C 40 21 STZ $2140 [$7E:2140] ;\ $80851E 9C 42 21 STZ $2142 [$7E:2142] ;} Clear APUIO registers $808521 E2 30 SEP #$30 $808523 A2 04 LDX #$04 $808525 AD 12 42 LDA $4212 [$7E:4212] ;\ $808528 10 FB BPL $FB [$8525] ;| ;| $80852A AD 12 42 LDA $4212 [$7E:4212] ;} Wait 3 frames, then for the start of VBlank $80852D 30 FB BMI $FB [$852A] ;| $80852F CA DEX ;| $808530 D0 F3 BNE $F3 [$8525] ;/ $808532 C2 30 REP #$30 $808534 A9 61 00 LDA #$0061 ;\ $808537 8D E5 05 STA $05E5 [$7E:05E5] ;} Seed random number with 0061h $80853A A9 00 00 LDA #$0000 ;\ $80853D 8D 3F 06 STA $063F [$7E:063F] ;| $808540 8D 29 06 STA $0629 [$7E:0629] ;| $808543 8D 2B 06 STA $062B [$7E:062B] ;| $808546 8D 2D 06 STA $062D [$7E:062D] ;| $808549 8D 2F 06 STA $062F [$7E:062F] ;} Clear command delay timers $80854C 8D 31 06 STA $0631 [$7E:0631] ;| $80854F 8D 33 06 STA $0633 [$7E:0633] ;| $808552 8D 35 06 STA $0635 [$7E:0635] ;| $808555 8D 37 06 STA $0637 [$7E:0637] ;/ $808558 AF 04 80 80 LDA $808004[$80:8004] ;\ $80855C 8D D1 05 STA $05D1 [$7E:05D1] ;} Mirror debug byte to RAM $80855F 20 F6 85 JSR $85F6 [$80:85F6] ; NTSC/PAL and SRAM mapping check $808562 C2 30 REP #$30 $808564 22 61 82 80 JSL $808261[$80:8261] ; Added a signature to the SRAM $808568 9C F5 05 STZ $05F5 [$7E:05F5] ; Enable sounds $80856B 9C 86 06 STZ $0686 [$7E:0686] ; Clear ??? $80856E 5C 3D 89 82 JML $82893D[$82:893D] ; Main game loop } $808572 00 BRK ;;; Infinite loop; pointed to by misc. error handling ;;; { $808573 5C 73 85 80 JML $808573[$80:8573] } ;;; Wait A many IRQs ;;; { $808577 08 PHP $808578 8B PHB $808579 4B PHK $80857A AB PLB $80857B E2 20 SEP #$20 $80857D 8D 1C 07 STA $071C [$82:071C] $808580 22 38 83 80 JSL $808338[$80:8338] $808584 CE 1C 07 DEC $071C [$82:071C] $808587 D0 F7 BNE $F7 [$8580] $808589 AB PLB $80858A 28 PLP $80858B 6B RTL } ;;; Load mirror of current area's map explored ;;; { $80858C 08 PHP $80858D C2 30 REP #$30 $80858F AD 9F 07 LDA $079F [$7E:079F] $808592 EB XBA $808593 AA TAX $808594 A0 00 00 LDY #$0000 $808597 BF 52 CD 7E LDA $7ECD52,x[$7E:CD52] $80859B 99 F7 07 STA $07F7,y[$7E:07F7] $80859E E8 INX $80859F E8 INX $8085A0 C8 INY $8085A1 C8 INY $8085A2 C0 00 01 CPY #$0100 $8085A5 30 F0 BMI $F0 [$8597] $8085A7 AE 9F 07 LDX $079F [$7E:079F] $8085AA BF 08 D9 7E LDA $7ED908,x[$7E:D908] $8085AE 29 FF 00 AND #$00FF $8085B1 8D 89 07 STA $0789 [$7E:0789] $8085B4 28 PLP $8085B5 6B RTL } ;;; Generic bitmasks ;;; { $8085B6 dw 0001, 0002, 0004, 0008, 0010, 0020, 0040, 0080 } ;;; Mirror current area's map explored ;;; { $8085C6 08 PHP $8085C7 C2 30 REP #$30 $8085C9 AD 9F 07 LDA $079F [$7E:079F] $8085CC EB XBA $8085CD AA TAX $8085CE A0 00 00 LDY #$0000 $8085D1 B9 F7 07 LDA $07F7,y[$7E:07F7] $8085D4 9F 52 CD 7E STA $7ECD52,x[$7E:CD52] $8085D8 E8 INX $8085D9 E8 INX $8085DA C8 INY $8085DB C8 INY $8085DC C0 00 01 CPY #$0100 $8085DF 30 F0 BMI $F0 [$85D1] $8085E1 AD 89 07 LDA $0789 [$7E:0789] $8085E4 F0 0E BEQ $0E [$85F4] $8085E6 AE 9F 07 LDX $079F [$7E:079F] $8085E9 BF 08 D9 7E LDA $7ED908,x[$7E:D908] $8085ED 09 FF 00 ORA #$00FF $8085F0 9F 08 D9 7E STA $7ED908,x[$7E:D908] $8085F4 28 PLP $8085F5 6B RTL } ;;; NTSC/PAL and SRAM mapping check ;;; { $8085F6 08 PHP $8085F7 E2 30 SEP #$30 $8085F9 AF 00 80 80 LDA $808000[$80:8000] ;\ $8085FD F0 03 BEQ $03 [$8602] ;} Return if NTSC/PAL check skip $8085FF 4C E1 86 JMP $86E1 [$80:86E1] ;/ $808602 AF D9 FF 00 LDA $00FFD9[$00:FFD9] ;\ $808606 C9 00 CMP #$00 ;} If Country code != 00 (Japan): $808608 F0 0A BEQ $0A [$8614] ;/ $80860A AD 3F 21 LDA $213F [$7E:213F] ;\ $80860D 89 10 BIT #$10 ;| $80860F F0 0A BEQ $0A [$861B] ;} If PPU set to PAL, branch to $8693 $808611 4C 93 86 JMP $8693 [$80:8693] ;/ $808614 AD 3F 21 LDA $213F [$7E:213F] ;\ $808617 89 10 BIT #$10 ;} Else if PPU set to NTSC, branch to $8693 $808619 F0 78 BEQ $78 [$8693] ;/ $80861B A9 8F LDA #$8F ;\ $80861D 8D 00 21 STA $2100 [$7E:2100] ;} Set force blank and max screen brightness $808620 9C 00 42 STZ $4200 [$7E:4200] ; Disable all interrupts $808623 A9 00 LDA #$00 ;\ $808625 8D 16 21 STA $2116 [$7E:2116] ;| $808628 A9 00 LDA #$00 ;} Clear VRAM address $80862A 8D 17 21 STA $2117 [$7E:2117] ;/ $80862D A9 80 LDA #$80 ;\ $80862F 8D 15 21 STA $2115 [$7E:2115] ;} Set normal video port control $808632 22 A9 91 80 JSL $8091A9[$80:91A9] ;\ $808636 dx 01, 01, 18, 8E8000, 4000;} Set up DMA, slot 1, 4000h bytes from $8E:8000 through $2118 (VRAM Data Write) $80863E A9 02 LDA #$02 ;\ $808640 8D 0B 42 STA $420B [$7E:420B] ;} Execute DMA $808643 A9 00 LDA #$00 ;\ $808645 8D 16 21 STA $2116 [$7E:2116] ;| $808648 A9 40 LDA #$40 ;} VRAM address = $4000 $80864A 8D 17 21 STA $2117 [$7E:2117] ;/ $80864D A9 80 LDA #$80 ;\ $80864F 8D 15 21 STA $2115 [$7E:2115] ;} Set normal video port control $808652 22 A9 91 80 JSL $8091A9[$80:91A9] ;\ $808656 dx 01, 01, 18, 80B437, 1000;} Set up DMA, slot 1, 1000h bytes from $80:B437 through $2118 (VRAM Data Write) $80865E A9 02 LDA #$02 ;\ $808660 8D 0B 42 STA $420B [$7E:420B] ;} Execute DMA $808663 9C 21 21 STZ $2121 [$7E:2121] ; Clear CGRAM address $808666 22 A9 91 80 JSL $8091A9[$80:91A9] ;\ $80866A dx 01, 00, 22, 8EE400, 0200;} Set up DMA, slot 1, 0200h bytes from $8E:E400 through $2122 (CGRAM Data Write) $808672 A9 02 LDA #$02 ;\ $808674 8D 0B 42 STA $420B [$7E:420B] ;} Execute DMA $808677 9C 31 21 STZ $2131 [$7E:2131] ; Clear colour math $80867A 9C 2D 21 STZ $212D [$7E:212D] ; Disable all subscreens $80867D A9 01 LDA #$01 ;\ $80867F 8D 2C 21 STA $212C [$7E:212C] ;} Enable only BG0 $808682 A9 0F LDA #$0F ;\ $808684 8D 00 21 STA $2100 [$7E:2100] ;} Clear force blank, (max screen brightness) $808687 A9 00 LDA #$00 ;\ $808689 8D 0B 21 STA $210B [$7E:210B] ;} Clear BG0/1 character base addresses $80868C A9 40 LDA #$40 ;\ $80868E 8D 07 21 STA $2107 [$7E:2107] ;} Set BG0 tilemap base address to $4000 $808691 80 FE BRA $FE [$8691] ; Crash $808693 C2 30 REP #$30 $808695 A2 FE 1F LDX #$1FFE ;\ ;| $808698 BF 00 00 70 LDA $700000,x[$7E:1FFE] ;| $80869C 9F 00 00 7F STA $7F0000,x[$7F:1FFE] ;} Mirror $70:0000..1FFF to $7F:0000 $8086A0 CA DEX ;| $8086A1 CA DEX ;| $8086A2 10 F4 BPL $F4 [$8698] ;/ $8086A4 A9 00 00 LDA #$0000 ;\ $8086A7 A2 FE 1F LDX #$1FFE ;| ;| $8086AA 9F 00 00 70 STA $700000,x[$7E:1FFE] ;} Clear $70:0000.1FFF $8086AE CA DEX ;| $8086AF CA DEX ;| $8086B0 10 F8 BPL $F8 [$86AA] ;/ $8086B2 A9 00 00 LDA #$0000 ;\ $8086B5 A2 FE 1F LDX #$1FFE ;| ;| $8086B8 9F 00 20 70 STA $702000,x[$7E:3FFE] ;| $8086BC 1A INC A ;} Set $70:2000..3FFF to 0..FFF $8086BD CA DEX ;| $8086BE CA DEX ;| $8086BF 10 F7 BPL $F7 [$86B8] ;/ $8086C1 A9 00 00 LDA #$0000 ;\ $8086C4 A2 FE 1F LDX #$1FFE ;| ;| $8086C7 DF 00 00 70 CMP $700000,x[$7E:1FFE] ;| $8086CB D0 16 BNE $16 [$86E3] ;} If any of $70:0000..1FFF is set, branch to $86E3 $8086CD 1A INC A ;| $8086CE CA DEX ;| $8086CF CA DEX ;| $8086D0 10 F5 BPL $F5 [$86C7] ;/ $8086D2 A2 FE 1F LDX #$1FFE ;\ ;| $8086D5 BF 00 00 7F LDA $7F0000,x[$7F:1FFE] ;| $8086D9 9F 00 00 70 STA $700000,x[$7E:1FFE] ;} Remirror 7F:0000..1FFF to $70:0000 $8086DD CA DEX ;| $8086DE CA DEX ;| $8086DF 10 F4 BPL $F4 [$86D5] ;/ $8086E1 28 PLP $8086E2 60 RTS $8086E3 E2 20 SEP #$20 $8086E5 A9 8F LDA #$8F ;\ $8086E7 8D 00 21 STA $2100 [$82:2100] ;} Set force blank and max screen brightness $8086EA 9C 00 42 STZ $4200 [$82:4200] ; Disable all interrupts $8086ED A9 00 LDA #$00 ;\ $8086EF 8D 16 21 STA $2116 [$82:2116] ;| $8086F2 A9 00 LDA #$00 ;} Clear VRAM address $8086F4 8D 17 21 STA $2117 [$82:2117] ;/ $8086F7 A9 80 LDA #$80 ;\ $8086F9 8D 15 21 STA $2115 [$82:2115] ;} Set normal video port control $8086FC 22 A9 91 80 JSL $8091A9[$80:91A9] ;\ $808700 dx 01, 01, 18, 8E8000, 4000 ;} Set up DMA, slot 1, 4000h bytes from $8E:8000 through $2118 (VRAM Data Write) $808708 A9 02 LDA #$02 ;\ $80870A 8D 0B 42 STA $420B [$82:420B] ;} Execute DMA $80870D A9 00 LDA #$00 ;\ $80870F 8D 16 21 STA $2116 [$82:2116] ;| $808712 A9 40 LDA #$40 ;} VRAM address = $4000 $808714 8D 17 21 STA $2117 [$82:2117] ;/ $808717 A9 80 LDA #$80 ;\ $808719 8D 15 21 STA $2115 [$82:2115] ;} Set normal video port control $80871C 22 A9 91 80 JSL $8091A9[$80:91A9] ;\ $808720 dx 01, 01, 18, 80BC37, 1000 ;} Set up DMA, slot 1, 1000h bytes from $80:BC37 through $2118 (VRAM Data Write) $808728 A9 02 LDA #$02 ;\ $80872A 8D 0B 42 STA $420B ;} Execute DMA $80872D 9C 21 21 STZ $2121 ; Clear CGRAM address $808730 22 A9 91 80 JSL $8091A9[$80:91A9] ;\ $808734 dx 01, 00, 22, 8EE400, 0200 ;} Set up DMA, slot 1, 0200h bytes from $8E:E400 through $2122 (CGRAM Data Write) $80873C A9 02 LDA #$02 ;\ $80873E 8D 0B 42 STA $420B [$82:420B] ;} Execute DMA $808741 9C 31 21 STZ $2131 [$82:2131] ; Clear colour math $808744 9C 2D 21 STZ $212D [$82:212D] ; Disable all subscreens $808747 A9 01 LDA #$01 ;\ $808749 8D 2C 21 STA $212C [$82:212C] ;} Enable only BG0 $80874C A9 0F LDA #$0F ;\ $80874E 8D 00 21 STA $2100 [$82:2100] ;} Clear force blank, (max screen brightness) $808751 A9 00 LDA #$00 ;\ $808753 8D 0B 21 STA $210B [$82:210B] ;} Clear BG0/1 character base addresses $808756 A9 40 LDA #$40 ;\ $808758 8D 07 21 STA $2107 [$82:2107] ;} Set BG0 tilemap base address to $4000 $80875B 80 FE BRA $FE [$875B] ; Crash } ;;; Initialise $4200..420D ;;; { $80875D A9 01 LDA #$01 ;\ $80875F 8D 00 42 STA $4200 [$7E:4200] ;} Enable auto-joypad read $808762 85 84 STA $84 [$7E:0084] ;/ $808764 9C 01 42 STZ $4201 [$7E:4201] ; Clear IO port $808767 9C 02 42 STZ $4202 [$7E:4202] ;\ $80876A 9C 03 42 STZ $4203 [$7E:4203] ;} Clear multiplication parameters $80876D 9C 04 42 STZ $4204 [$7E:4204] ;\ $808770 9C 05 42 STZ $4205 [$7E:4205] ;} Clear division parameters $808773 9C 06 42 STZ $4206 [$7E:4206] ;/ $808776 9C 07 42 STZ $4207 [$7E:4207] ;\ $808779 9C 08 42 STZ $4208 [$7E:4208] ;} Clear H timer $80877C 9C 09 42 STZ $4209 [$7E:4209] ;\ $80877F 9C 0A 42 STZ $420A [$7E:420A] ;} Clear V timer $808782 9C 0B 42 STZ $420B [$7E:420B] ; Disable all DMA $808785 9C 0C 42 STZ $420C [$7E:420C] ;\ $808788 64 85 STZ $85 [$7E:0085] ;} Disable all HDMA $80878A A9 01 LDA #$01 ;\ $80878C 8D 0D 42 STA $420D [$7E:420D] ;} Enable FastROM $80878F 85 86 STA $86 [$7E:0086] ;/ $808791 60 RTS } ;;; Initialise $2100..2133 ;;; { $808792 A9 8F LDA #$8F ;\ $808794 8D 00 21 STA $2100 [$7E:2100] ;} Set force blank and max screen brightness $808797 85 51 STA $51 [$7E:0051] ;/ $808799 A9 03 LDA #$03 ;\ $80879B 8D 01 21 STA $2101 [$7E:2101] ;} 8x8 and 16x16 sprites, character base $C000 $80879E 85 52 STA $52 [$7E:0052] ;/ $8087A0 9C 02 21 STZ $2102 [$7E:2102] ;\ $8087A3 64 53 STZ $53 [$7E:0053] ;| $8087A5 A9 80 LDA #$80 ;} Enable object priority, OAM address = $0000 $8087A7 8D 03 21 STA $2103 [$7E:2103] ;| $8087AA 85 54 STA $54 [$7E:0054] ;/ $8087AC 9C 04 21 STZ $2104 [$7E:2104] ;\ $8087AF 9C 04 21 STZ $2104 [$7E:2104] ;} Clear OAM write $8087B2 A9 09 LDA #$09 ;\ $8087B4 8D 05 21 STA $2105 [$7E:2105] ;} Set BG mode 1, BG3 at the front, all 8x8 characters $8087B7 85 55 STA $55 [$7E:0055] ;/ $8087B9 9C 06 21 STZ $2106 [$7E:2106] ;\ $8087BC 64 57 STZ $57 [$7E:0057] ;} Disable mosaic $8087BE A9 40 LDA #$40 ;\ $8087C0 8D 07 21 STA $2107 [$7E:2107] ;} BG1 tilemap base address: $4000, no mirroring $8087C3 85 58 STA $58 [$7E:0058] ;/ $8087C5 A9 44 LDA #$44 ;\ $8087C7 8D 08 21 STA $2108 [$7E:2108] ;} BG2 tilemap base address: $4400, no mirroring $8087CA 85 59 STA $59 [$7E:0059] ;/ $8087CC A9 48 LDA #$48 ;\ $8087CE 8D 09 21 STA $2109 [$7E:2109] ;} BG3 tilemap base address: $4800, no mirroring $8087D1 85 5A STA $5A [$7E:005A] ;/ $8087D3 A9 48 LDA #$48 ; -_- $8087D5 9C 0A 21 STZ $210A [$7E:210A] ;\ $8087D8 64 5C STZ $5C [$7E:005C] ;} Clear BG4 tilemap address and mirroring $8087DA A9 00 LDA #$00 ;\ $8087DC 8D 0B 21 STA $210B [$7E:210B] ;| $8087DF 85 5D STA $5D [$7E:005D] ;} BG1/BG2/BG4 character base address: $0000 $8087E1 A9 05 LDA #$05 ;} BG3 character base address: $A000 $8087E3 8D 0C 21 STA $210C [$7E:210C] ;| $8087E6 85 5E STA $5E [$7E:005E] ;/ $8087E8 9C 0D 21 STZ $210D [$7E:210D] ;\ $8087EB 9C 0D 21 STZ $210D [$7E:210D] ;| $8087EE 9C 0E 21 STZ $210E [$7E:210E] ;| $8087F1 9C 0E 21 STZ $210E [$7E:210E] ;| $8087F4 9C 0F 21 STZ $210F [$7E:210F] ;| $8087F7 9C 0F 21 STZ $210F [$7E:210F] ;| $8087FA 9C 10 21 STZ $2110 [$7E:2110] ;| $8087FD 9C 10 21 STZ $2110 [$7E:2110] ;| $808800 9C 11 21 STZ $2111 [$7E:2111] ;} Disable all scrolling $808803 9C 11 21 STZ $2111 [$7E:2111] ;| $808806 9C 12 21 STZ $2112 [$7E:2112] ;| $808809 9C 12 21 STZ $2112 [$7E:2112] ;| $80880C 9C 13 21 STZ $2113 [$7E:2113] ;| $80880F 9C 13 21 STZ $2113 [$7E:2113] ;| $808812 9C 14 21 STZ $2114 [$7E:2114] ;| $808815 9C 14 21 STZ $2114 [$7E:2114] ;/ $808818 9C 15 21 STZ $2115 [$7E:2115] ; Set up normal video port control for byte read/writes $80881B 9C 1A 21 STZ $211A [$7E:211A] ;\ $80881E 64 5F STZ $5F [$7E:005F] ;| $808820 9C 1B 21 STZ $211B [$7E:211B] ;| $808823 9C 1C 21 STZ $211C [$7E:211C] ;| $808826 9C 1D 21 STZ $211D [$7E:211D] ;} Clear mode 7 settings $808829 9C 1E 21 STZ $211E [$7E:211E] ;| $80882C 9C 1F 21 STZ $211F [$7E:211F] ;| $80882F 9C 20 21 STZ $2120 [$7E:2120] ;/ $808832 A9 00 LDA #$00 ;\ $808834 8D 23 21 STA $2123 [$7E:2123] ;| $808837 85 60 STA $60 [$7E:0060] ;| $808839 A9 00 LDA #$00 ;| $80883B 8D 24 21 STA $2124 [$7E:2124] ;} Disable all window masks $80883E 85 61 STA $61 [$7E:0061] ;| $808840 9C 25 21 STZ $2125 [$7E:2125] ;| $808843 64 62 STZ $62 [$7E:0062] ;/ $808845 A9 00 LDA #$00 ;\ $808847 8D 26 21 STA $2126 [$7E:2126] ;| $80884A 85 63 STA $63 [$7E:0063] ;| $80884C A9 F8 LDA #$F8 ;} Window 1 X: 00..248 $80884E 8D 27 21 STA $2127 [$7E:2127] ;| $808851 85 64 STA $64 [$7E:0064] ;/ $808853 9C 28 21 STZ $2128 [$7E:2128] ;\ $808856 64 65 STZ $65 [$7E:0065] ;| $808858 9C 29 21 STZ $2129 [$7E:2129] ;} No window 2 $80885B 64 66 STZ $66 [$7E:0066] ;/ $80885D 9C 2A 21 STZ $212A [$7E:212A] ;\ $808860 64 67 STZ $67 [$7E:0067] ;| $808862 9C 2B 21 STZ $212B [$7E:212B] ;} Use OR window combination $808865 64 68 STZ $68 [$7E:0068] ;/ $808867 A9 11 LDA #$11 ;\ $808869 8D 2C 21 STA $212C [$7E:212C] ;} Enable objects and BG1 $80886C 85 69 STA $69 [$7E:0069] ;/ $80886E 8D 2E 21 STA $212E [$7E:212E] ;\ $808871 85 6C STA $6C [$7E:006C] ;} Window masking affects objects and BG1 $808873 A9 02 LDA #$02 ;\ $808875 8D 2D 21 STA $212D [$7E:212D] ;} Enable BG2 on subscreen $808878 85 6B STA $6B [$7E:006B] ;/ $80887A 8D 2F 21 STA $212F [$7E:212F] ;\ $80887D 85 6D STA $6D [$7E:006D] ;} Window masking on subscreen affects BG2 $80887F A9 02 LDA #$02 ;\ $808881 8D 30 21 STA $2130 [$7E:2130] ;} Colour math: add subscreen $808884 85 6E STA $6E [$7E:006E] ;/ $808886 A9 A1 LDA #$A1 ;\ $808888 8D 31 21 STA $2131 [$7E:2131] ;} Colour math: subtract the colours, unto the backdrop and BG1 $80888B 85 71 STA $71 [$7E:0071] ;/ $80888D A9 E0 LDA #$E0 ;\ $80888F 8D 32 21 STA $2132 [$7E:2132] ;| $808892 A9 E0 LDA #$E0 ;| $808894 8D 32 21 STA $2132 [$7E:2132] ;| $808897 A9 80 LDA #$80 ;| $808899 8D 32 21 STA $2132 [$7E:2132] ;| $80889C 85 74 STA $74 [$7E:0074] ;} Colour math: fixed colour = black (eventually) $80889E A9 40 LDA #$40 ;| $8088A0 8D 32 21 STA $2132 [$7E:2132] ;| $8088A3 85 75 STA $75 [$7E:0075] ;| $8088A5 A9 20 LDA #$20 ;| $8088A7 8D 32 21 STA $2132 [$7E:2132] ;| $8088AA 85 76 STA $76 [$7E:0076] ;/ $8088AC A9 00 LDA #$00 ;\ $8088AE 8D 33 21 STA $2133 [$7E:2133] ;} Disable all special video options (interlaces, overscan, extra backgrounds) $8088B1 85 77 STA $77 [$7E:0077] ;/ $8088B3 60 RTS } ;;; Clear high RAM ;;; { $8088B4 C2 30 REP #$30 $8088B6 A9 00 00 LDA #$0000 ;\ $8088B9 A2 00 20 LDX #$2000 ;| $8088BC A0 00 E0 LDY #$E000 ;} Clear $7E:2000..FFFF $8088BF 22 F6 83 80 JSL $8083F6[$80:83F6] ;/ $8088C3 A9 00 00 LDA #$0000 ;\ $8088C6 AA TAX ;| $8088C7 A0 FE DF LDY #$DFFE ;} Clear $7F:0000..DFFD $8088CA 22 09 84 80 JSL $808409[$80:8409] ;/ $8088CE E2 30 SEP #$30 $8088D0 60 RTS } ;;; Write a load of 1C2Fh ;;; { $8088D1 C2 30 REP #$30 $8088D3 A9 2F 1C LDA #$1C2F ;\ $8088D6 22 EB 88 80 JSL $8088EB[$80:88EB] ;} $7E:3000..37FF = 1C2Fh $8088DA A9 2F 1C LDA #$1C2F ;\ $8088DD 22 FE 88 80 JSL $8088FE[$80:88FE] ;} $7E:4000..47FF = 1C2Fh $8088E1 A9 2F 1C LDA #$1C2F ;\ $8088E4 22 11 89 80 JSL $808911[$80:8911] ;} $7E:6000..67FF = 1C2Fh $8088E8 E2 30 SEP #$30 $8088EA 60 RTS } ;;; Write 800h bytes of A to $7E:3000 ;;; { $8088EB 08 PHP $8088EC 8B PHB $8088ED 4B PHK $8088EE AB PLB $8088EF C2 30 REP #$30 $8088F1 A2 00 30 LDX #$3000 $8088F4 A0 00 08 LDY #$0800 $8088F7 22 F6 83 80 JSL $8083F6[$80:83F6] $8088FB AB PLB $8088FC 28 PLP $8088FD 6B RTL } ;;; Write 800h bytes of A to $7E:4000 ;;; { $8088FE 08 PHP $8088FF 8B PHB $808900 4B PHK $808901 AB PLB $808902 C2 30 REP #$30 $808904 A2 00 40 LDX #$4000 $808907 A0 00 08 LDY #$0800 $80890A 22 F6 83 80 JSL $8083F6[$80:83F6] $80890E AB PLB $80890F 28 PLP $808910 6B RTL } ;;; Write 800h bytes of A to $7E:6000 ;;; { $808911 08 PHP $808912 8B PHB $808913 4B PHK $808914 AB PLB $808915 C2 30 REP #$30 $808917 A2 00 60 LDX #$6000 $80891A A0 00 08 LDY #$0800 $80891D 22 F6 83 80 JSL $8083F6[$80:83F6] $808921 AB PLB $808922 28 PLP $808923 6B RTL } ;;; Handle fading out ;;; { $808924 08 PHP $808925 C2 20 REP #$20 $808927 AD 25 07 LDA $0725 [$7E:0725] ;\ $80892A 3A DEC A ;} If fade length timer != 0: $80892B 30 05 BMI $05 [$8932] ;/ $80892D 8D 25 07 STA $0725 [$7E:0725] ; Decrement timer $808930 80 19 BRA $19 [$894B] ; Return $808932 AD 23 07 LDA $0723 [$7E:0723] ;\ $808935 8D 25 07 STA $0725 [$7E:0725] ;} Set next fade length timer $808938 E2 30 SEP #$30 $80893A A5 51 LDA $51 [$7E:0051] ;\ $80893C 29 0F AND #$0F ;} If screen brightness is 0: return $80893E F0 0B BEQ $0B [$894B] ;/ $808940 3A DEC A ;\ $808941 D0 06 BNE $06 [$8949] ;} If screen brightness is 1: $808943 A9 80 LDA #$80 ;\ $808945 85 51 STA $51 [$7E:0051] ;} Turn off the screen $808947 80 02 BRA $02 [$894B] $808949 85 51 STA $51 [$7E:0051] ; Else: decrement the brightness $80894B 28 PLP $80894C 6B RTL } ;;; Handle fading in ;;; { $80894D 08 PHP $80894E C2 20 REP #$20 $808950 AD 25 07 LDA $0725 [$7E:0725] ;\ $808953 3A DEC A ;} If fade length timer != 0: $808954 30 05 BMI $05 [$895B] ;/ $808956 8D 25 07 STA $0725 [$7E:0725] ; Decrement timer $808959 80 11 BRA $11 [$896C] ; Return $80895B AD 23 07 LDA $0723 [$7E:0723] ;\ $80895E 8D 25 07 STA $0725 [$7E:0725] ;} Set next fade length timer $808961 E2 30 SEP #$30 $808963 A5 51 LDA $51 [$7E:0051] ;\ $808965 1A INC A ;| $808966 29 0F AND #$0F ;} If screen brightness is not maximum: $808968 F0 02 BEQ $02 [$896C] ;/ $80896A 85 51 STA $51 [$7E:0051] ; Increment screen brightness $80896C 28 PLP $80896D 6B RTL } ;;; Clear unused OAM (sprites to Y=F0h), clear OAM data offset ;;; { ; This wouldn't have been difficult to make a loop: ; PHP : REP #$30 : LDA $0590 : CMP #$0200 : BCS DONE : ADC #$0370 : TAX : SEP #$20 : LDA #$F0 ; LOOP: : STA $00,X : INX #4 : CMP #$0571 : BNE LOOP ; DONE: : STZ $0590 : PLP : RTL $80896E 08 PHP $80896F C2 30 REP #$30 $808971 AD 90 05 LDA $0590 [$7E:0590] ;\ $808974 C9 00 02 CMP #$0200 ;} If OAM data offset < 200h: $808977 10 14 BPL $14 [$898D] ;/ $808979 4A LSR A ;\ $80897A 85 12 STA $12 [$7E:0012] ;| $80897C 4A LSR A ;| $80897D 65 12 ADC $12 [$7E:0012] ;} Set jump vector to the (OAM slot)th STA $80897F 18 CLC ;| $808980 69 92 89 ADC #$8992 ;| $808983 85 12 STA $12 [$7E:0012] ;/ $808985 A9 F0 00 LDA #$00F0 ; Value to STA = F0h $808988 E2 30 SEP #$30 $80898A 6C 12 00 JMP ($0012)[$80:8992] $80898D 9C 90 05 STZ $0590 [$7E:0590] ; Else: Clear OAM data offset and return $808990 28 PLP $808991 6B RTL $808992 8D 71 03 STA $0371 [$7E:0371] ; 00h $808995 8D 75 03 STA $0375 [$7E:0375] ; 01h $808998 8D 79 03 STA $0379 [$7E:0379] ; 02h $80899B 8D 7D 03 STA $037D [$7E:037D] ; 03h $80899E 8D 81 03 STA $0381 [$7E:0381] ; 04h $8089A1 8D 85 03 STA $0385 [$7E:0385] ; 05h $8089A4 8D 89 03 STA $0389 [$7E:0389] ; 06h $8089A7 8D 8D 03 STA $038D [$7E:038D] ; 07h $8089AA 8D 91 03 STA $0391 [$7E:0391] ; 08h $8089AD 8D 95 03 STA $0395 [$7E:0395] ; 09h $8089B0 8D 99 03 STA $0399 [$7E:0399] ; 0Ah $8089B3 8D 9D 03 STA $039D [$7E:039D] ; 0Bh $8089B6 8D A1 03 STA $03A1 [$7E:03A1] ; 0Ch $8089B9 8D A5 03 STA $03A5 [$7E:03A5] ; 0Dh $8089BC 8D A9 03 STA $03A9 [$7E:03A9] ; 0Eh $8089BF 8D AD 03 STA $03AD [$7E:03AD] ; 0Fh $8089C2 8D B1 03 STA $03B1 [$7E:03B1] ; 10h $8089C5 8D B5 03 STA $03B5 [$7E:03B5] ; 11h $8089C8 8D B9 03 STA $03B9 [$7E:03B9] ; 12h $8089CB 8D BD 03 STA $03BD [$7E:03BD] ; 13h $8089CE 8D C1 03 STA $03C1 [$7E:03C1] ; 14h $8089D1 8D C5 03 STA $03C5 [$7E:03C5] ; 15h $8089D4 8D C9 03 STA $03C9 [$7E:03C9] ; 16h $8089D7 8D CD 03 STA $03CD [$7E:03CD] ; 17h $8089DA 8D D1 03 STA $03D1 [$7E:03D1] ; 18h $8089DD 8D D5 03 STA $03D5 [$7E:03D5] ; 19h $8089E0 8D D9 03 STA $03D9 [$7E:03D9] ; 1Ah $8089E3 8D DD 03 STA $03DD [$7E:03DD] ; 1Bh $8089E6 8D E1 03 STA $03E1 [$7E:03E1] ; 1Ch $8089E9 8D E5 03 STA $03E5 [$7E:03E5] ; 1Dh $8089EC 8D E9 03 STA $03E9 [$7E:03E9] ; 1Eh $8089EF 8D ED 03 STA $03ED [$7E:03ED] ; 1Fh $8089F2 8D F1 03 STA $03F1 [$7E:03F1] ; 20h $8089F5 8D F5 03 STA $03F5 [$7E:03F5] ; 21h $8089F8 8D F9 03 STA $03F9 [$7E:03F9] ; 22h $8089FB 8D FD 03 STA $03FD [$7E:03FD] ; 23h $8089FE 8D 01 04 STA $0401 [$7E:0401] ; 24h $808A01 8D 05 04 STA $0405 [$7E:0405] ; 25h $808A04 8D 09 04 STA $0409 [$7E:0409] ; 26h $808A07 8D 0D 04 STA $040D [$7E:040D] ; 27h $808A0A 8D 11 04 STA $0411 [$7E:0411] ; 28h $808A0D 8D 15 04 STA $0415 [$7E:0415] ; 29h $808A10 8D 19 04 STA $0419 [$7E:0419] ; 2Ah $808A13 8D 1D 04 STA $041D [$7E:041D] ; 2Bh $808A16 8D 21 04 STA $0421 [$7E:0421] ; 2Ch $808A19 8D 25 04 STA $0425 [$7E:0425] ; 2Dh $808A1C 8D 29 04 STA $0429 [$7E:0429] ; 2Eh $808A1F 8D 2D 04 STA $042D [$7E:042D] ; 2Fh $808A22 8D 31 04 STA $0431 [$7E:0431] ; 30h $808A25 8D 35 04 STA $0435 [$7E:0435] ; 31h $808A28 8D 39 04 STA $0439 [$7E:0439] ; 32h $808A2B 8D 3D 04 STA $043D [$7E:043D] ; 33h $808A2E 8D 41 04 STA $0441 [$7E:0441] ; 34h $808A31 8D 45 04 STA $0445 [$7E:0445] ; 35h $808A34 8D 49 04 STA $0449 [$7E:0449] ; 36h $808A37 8D 4D 04 STA $044D [$7E:044D] ; 37h $808A3A 8D 51 04 STA $0451 [$7E:0451] ; 38h $808A3D 8D 55 04 STA $0455 [$7E:0455] ; 39h $808A40 8D 59 04 STA $0459 [$7E:0459] ; 3Ah $808A43 8D 5D 04 STA $045D [$7E:045D] ; 3Bh $808A46 8D 61 04 STA $0461 [$7E:0461] ; 3Ch $808A49 8D 65 04 STA $0465 [$7E:0465] ; 3Dh $808A4C 8D 69 04 STA $0469 [$7E:0469] ; 3Eh $808A4F 8D 6D 04 STA $046D [$7E:046D] ; 3Fh $808A52 8D 71 04 STA $0471 [$7E:0471] ; 40h $808A55 8D 75 04 STA $0475 [$7E:0475] ; 41h $808A58 8D 79 04 STA $0479 [$7E:0479] ; 42h $808A5B 8D 7D 04 STA $047D [$7E:047D] ; 43h $808A5E 8D 81 04 STA $0481 [$7E:0481] ; 44h $808A61 8D 85 04 STA $0485 [$7E:0485] ; 45h $808A64 8D 89 04 STA $0489 [$7E:0489] ; 46h $808A67 8D 8D 04 STA $048D [$7E:048D] ; 47h $808A6A 8D 91 04 STA $0491 [$7E:0491] ; 48h $808A6D 8D 95 04 STA $0495 [$7E:0495] ; 49h $808A70 8D 99 04 STA $0499 [$7E:0499] ; 4Ah $808A73 8D 9D 04 STA $049D [$7E:049D] ; 4Bh $808A76 8D A1 04 STA $04A1 [$7E:04A1] ; 4Ch $808A79 8D A5 04 STA $04A5 [$7E:04A5] ; 4Dh $808A7C 8D A9 04 STA $04A9 [$7E:04A9] ; 4Eh $808A7F 8D AD 04 STA $04AD [$7E:04AD] ; 4Fh $808A82 8D B1 04 STA $04B1 [$7E:04B1] ; 50h $808A85 8D B5 04 STA $04B5 [$7E:04B5] ; 51h $808A88 8D B9 04 STA $04B9 [$7E:04B9] ; 52h $808A8B 8D BD 04 STA $04BD [$7E:04BD] ; 53h $808A8E 8D C1 04 STA $04C1 [$7E:04C1] ; 54h $808A91 8D C5 04 STA $04C5 [$7E:04C5] ; 55h $808A94 8D C9 04 STA $04C9 [$7E:04C9] ; 56h $808A97 8D CD 04 STA $04CD [$7E:04CD] ; 57h $808A9A 8D D1 04 STA $04D1 [$7E:04D1] ; 58h $808A9D 8D D5 04 STA $04D5 [$7E:04D5] ; 59h $808AA0 8D D9 04 STA $04D9 [$7E:04D9] ; 5Ah $808AA3 8D DD 04 STA $04DD [$7E:04DD] ; 5Bh $808AA6 8D E1 04 STA $04E1 [$7E:04E1] ; 5Ch $808AA9 8D E5 04 STA $04E5 [$7E:04E5] ; 5Dh $808AAC 8D E9 04 STA $04E9 [$7E:04E9] ; 5Eh $808AAF 8D ED 04 STA $04ED [$7E:04ED] ; 5Fh $808AB2 8D F1 04 STA $04F1 [$7E:04F1] ; 60h $808AB5 8D F5 04 STA $04F5 [$7E:04F5] ; 61h $808AB8 8D F9 04 STA $04F9 [$7E:04F9] ; 62h $808ABB 8D FD 04 STA $04FD [$7E:04FD] ; 63h $808ABE 8D 01 05 STA $0501 [$7E:0501] ; 64h $808AC1 8D 05 05 STA $0505 [$7E:0505] ; 65h $808AC4 8D 09 05 STA $0509 [$7E:0509] ; 66h $808AC7 8D 0D 05 STA $050D [$7E:050D] ; 67h $808ACA 8D 11 05 STA $0511 [$7E:0511] ; 68h $808ACD 8D 15 05 STA $0515 [$7E:0515] ; 69h $808AD0 8D 19 05 STA $0519 [$7E:0519] ; 6Ah $808AD3 8D 1D 05 STA $051D [$7E:051D] ; 6Bh $808AD6 8D 21 05 STA $0521 [$7E:0521] ; 6Ch $808AD9 8D 25 05 STA $0525 [$7E:0525] ; 6Dh $808ADC 8D 29 05 STA $0529 [$7E:0529] ; 6Eh $808ADF 8D 2D 05 STA $052D [$7E:052D] ; 6Fh $808AE2 8D 31 05 STA $0531 [$7E:0531] ; 70h $808AE5 8D 35 05 STA $0535 [$7E:0535] ; 71h $808AE8 8D 39 05 STA $0539 [$7E:0539] ; 72h $808AEB 8D 3D 05 STA $053D [$7E:053D] ; 73h $808AEE 8D 41 05 STA $0541 [$7E:0541] ; 74h $808AF1 8D 45 05 STA $0545 [$7E:0545] ; 75h $808AF4 8D 49 05 STA $0549 [$7E:0549] ; 76h $808AF7 8D 4D 05 STA $054D [$7E:054D] ; 77h $808AFA 8D 51 05 STA $0551 [$7E:0551] ; 78h $808AFD 8D 55 05 STA $0555 [$7E:0555] ; 79h $808B00 8D 59 05 STA $0559 [$7E:0559] ; 7Ah $808B03 8D 5D 05 STA $055D [$7E:055D] ; 7Bh $808B06 8D 61 05 STA $0561 [$7E:0561] ; 7Ch $808B09 8D 65 05 STA $0565 [$7E:0565] ; 7Dh $808B0C 8D 69 05 STA $0569 [$7E:0569] ; 7Eh $808B0F 8D 6D 05 STA $056D [$7E:056D] ; 7Fh $808B12 9C 90 05 STZ $0590 [$7E:0590] ;\ $808B15 9C 91 05 STZ $0591 [$7E:0591] ;} Clear OAM data offset $808B18 28 PLP $808B19 6B RTL } ;;; Clear all OAM high-x bits and sizes ;;; { $808B1A 08 PHP $808B1B C2 30 REP #$30 $808B1D 9C 70 05 STZ $0570 [$7E:0570] $808B20 9C 72 05 STZ $0572 [$7E:0572] $808B23 9C 74 05 STZ $0574 [$7E:0574] $808B26 9C 76 05 STZ $0576 [$7E:0576] $808B29 9C 78 05 STZ $0578 [$7E:0578] $808B2C 9C 7A 05 STZ $057A [$7E:057A] $808B2F 9C 7C 05 STZ $057C [$7E:057C] $808B32 9C 7E 05 STZ $057E [$7E:057E] $808B35 9C 80 05 STZ $0580 [$7E:0580] $808B38 9C 82 05 STZ $0582 [$7E:0582] $808B3B 9C 84 05 STZ $0584 [$7E:0584] $808B3E 9C 86 05 STZ $0586 [$7E:0586] $808B41 9C 88 05 STZ $0588 [$7E:0588] $808B44 9C 8A 05 STZ $058A [$7E:058A] $808B47 9C 8C 05 STZ $058C [$7E:058C] $808B4A 9C 8E 05 STZ $058E [$7E:058E] $808B4D 28 PLP $808B4E 6B RTL } ;;; Unpack mode 7 DMAs ;;; { ;; Takes parameter: X = pointer to data structure $808B4F DA PHX $808B50 5A PHY $808B51 AC 34 03 LDY $0334 [$7E:0334] ; Next available slot $808B54 CA DEX ;\ ;} Test X[0] $808B55 3C 00 00 BIT $0000,x[$8B:A336] ;/ $808B58 30 31 BMI $31 [$8B8B] ; If bit7 set: branch to $8B8B $808B5A 70 06 BVS $06 [$8B62] ; Else if bit6 set: branch to $8B62 $808B5C 8C 34 03 STY $0334 [$7E:0334] ; Else store new next available slot and return $808B5F 7A PLY $808B60 FA PLX $808B61 6B RTL ; CGRAM DMA $808B62 BD 01 00 LDA $0001,x ;\ $808B65 99 D0 02 STA $02D0,y ;| $808B68 BD 03 00 LDA $0003,x ;| $808B6B 99 D2 02 STA $02D2,y ;| $808B6E BD 05 00 LDA $0005,x ;} $02D0[Y][0..6] = X[0..6] $808B71 99 D4 02 STA $02D4,y ;| $808B74 BD 07 00 LDA $0007,x ;| $808B77 29 FF 00 AND #$00FF ;| $808B7A 99 D6 02 STA $02D6,y ;/ $808B7D 8A TXA ;\ $808B7E 18 CLC ;| $808B7F 69 07 00 ADC #$0007 ;} Next X slot $808B82 AA TAX ;/ $808B83 98 TYA ;\ $808B84 18 CLC ;| $808B85 69 07 00 ADC #$0007 ;} Next Y slot $808B88 A8 TAY ;/ $808B89 80 CA BRA $CA [$8B55] ; Loop back to next test X[0] ; VRAM DMA $808B8B BD 01 00 LDA $0001,x[$8B:A337] ;\ $808B8E 99 D0 02 STA $02D0,y[$7E:02D0] ;| $808B91 BD 03 00 LDA $0003,x[$8B:A339] ;| $808B94 99 D2 02 STA $02D2,y[$7E:02D2] ;| $808B97 BD 05 00 LDA $0005,x[$8B:A33B] ;| $808B9A 99 D4 02 STA $02D4,y[$7E:02D4] ;} $02D0[Y][0..8] = X[0..8] $808B9D BD 07 00 LDA $0007,x[$8B:A33D] ;| $808BA0 99 D6 02 STA $02D6,y[$7E:02D6] ;| $808BA3 BD 09 00 LDA $0009,x[$8B:A33F] ;| $808BA6 29 FF 00 AND #$00FF ;| $808BA9 99 D8 02 STA $02D8,y[$7E:02D8] ;/ $808BAC 8A TXA ;\ $808BAD 18 CLC ;| $808BAE 69 09 00 ADC #$0009 ;} Next X slot $808BB1 AA TAX ;/ $808BB2 98 TYA ;\ $808BB3 18 CLC ;| $808BB4 69 09 00 ADC #$0009 ;} Next Y slot $808BB7 A8 TAY ;/ $808BB8 80 9B BRA $9B [$8B55] ; Loop back to test next X[0] } ;;; Handle mode 7 DMAs ;;; { $808BBA 08 PHP $808BBB C2 10 REP #$10 $808BBD AE 34 03 LDX $0334 [$7E:0334] ;\ $808BC0 F0 0F BEQ $0F [$8BD1] ;} If next available slot is clear (no unpacked data): return $808BC2 A2 D0 02 LDX #$02D0 ;\ $808BC5 22 D3 8B 80 JSL $808BD3[$80:8BD3] ;} Call this with X = first slot $808BC9 C2 20 REP #$20 $808BCB 9C D0 02 STZ $02D0 [$7E:02D0] ; Clear first slot $808BCE 9C 34 03 STZ $0334 [$7E:0334] ; Clear next available slot $808BD1 28 PLP $808BD2 6B RTL } ;;; Handle mode 7 DMAs continued ;;; { ;; Takes parameter: X = pointer to data structure $808BD3 08 PHP $808BD4 E2 20 SEP #$20 $808BD6 BD 00 00 LDA $0000,x[$7E:02D0] ;\ $808BD9 30 36 BMI $36 [$8C11] ;} If X[0] bit7 set: branch to $8C11 $808BDB 0A ASL A ;\ $808BDC 30 02 BMI $02 [$8BE0] ;} Else if bit6 set: branch to $8BE0 $808BDE 28 PLP ; Else return $808BDF 6B RTL ; CGRAM DMA $808BE0 4A LSR A ;\ $808BE1 29 1F AND #$1F ;} DMA1 control = X[0] bits 0..4 (always source->dest) $808BE3 8D 10 43 STA $4310 [$7E:4310] ;/ $808BE6 BC 01 00 LDY $0001,x ;\ $808BE9 8C 12 43 STY $4312 [$7E:4312] ;| $808BEC BD 03 00 LDA $0003,x ;} DMA1 source = X[1..3] $808BEF 8D 14 43 STA $4314 [$7E:4314] ;/ $808BF2 BC 04 00 LDY $0004,x ;\ $808BF5 8C 15 43 STY $4315 [$7E:4315] ;} DMA1 size = X[4..5] $808BF8 A9 22 LDA #$22 ;\ $808BFA 8D 11 43 STA $4311 [$7E:4311] ;} Set DMA1 dest. to $2122 (CGRAM data write) $808BFD BD 06 00 LDA $0006,x ;\ $808C00 8D 21 21 STA $2121 [$7E:2121] ;} CGRAM address = X[6] $808C03 A9 02 LDA #$02 ;\ $808C05 8D 0B 42 STA $420B [$7E:420B] ;} Execute DMA slot 1 $808C08 C2 21 REP #$21 ;\ $808C0A 8A TXA ;| $808C0B 69 07 00 ADC #$0007 ;} Next X slot $808C0E AA TAX ;/ $808C0F 80 C3 BRA $C3 [$8BD4] ; Loop back to test next X[0] ; VRAM DMAs $808C11 0A ASL A ;\ $808C12 30 37 BMI $37 [$8C4B] ;} If X[0] bit6 clear: $808C14 4A LSR A ;\ $808C15 29 1F AND #$1F ;} DMA1 control = X[0] bits 0..4 (always source->dest) $808C17 8D 10 43 STA $4310 [$7E:4310] ;/ $808C1A BC 01 00 LDY $0001,x[$7E:02D1] ;\ $808C1D 8C 12 43 STY $4312 [$7E:4312] ;| $808C20 BD 03 00 LDA $0003,x[$7E:02D3] ;} DMA1 source = X[1..3] $808C23 8D 14 43 STA $4314 [$7E:4314] ;/ $808C26 BC 04 00 LDY $0004,x[$7E:02D4] ;\ $808C29 8C 15 43 STY $4315 [$7E:4315] ;} DMA1 size = X[4..5] $808C2C A9 18 LDA #$18 ;\ $808C2E 8D 11 43 STA $4311 [$7E:4311] ;} Set DMA1 dest. to $2118 (VRAM data write low) $808C31 BC 06 00 LDY $0006,x[$7E:02D6] ;\ $808C34 8C 16 21 STY $2116 [$7E:2116] ;} VRAM address = X[6..7] $808C37 BD 08 00 LDA $0008,x[$7E:02D8] ;\ $808C3A 8D 15 21 STA $2115 [$7E:2115] ;} Video port control = X[8] $808C3D A9 02 LDA #$02 ;\ $808C3F 8D 0B 42 STA $420B [$7E:420B] ;} Execute DMA slot 1 $808C42 C2 21 REP #$21 ;\ $808C44 8A TXA ;| $808C45 69 09 00 ADC #$0009 ;} Next X slot $808C48 AA TAX ;/ $808C49 80 89 BRA $89 [$8BD4] ; Loop back to test next X[0] $808C4B 4A LSR A ;\ Else: $808C4C 29 1F AND #$1F ;} DMA1 control = X[0] bits 0..4 (always source->dest) $808C4E 8D 10 43 STA $4310 [$7E:4310] ;/ $808C51 BC 01 00 LDY $0001,x[$7E:02D1] ;\ $808C54 8C 12 43 STY $4312 [$7E:4312] ;| $808C57 BD 03 00 LDA $0003,x[$7E:02D3] ;} DMA1 source = X[1..3] $808C5A 8D 14 43 STA $4314 [$7E:4314] ;/ $808C5D BC 04 00 LDY $0004,x[$7E:02D4] ;\ $808C60 8C 15 43 STY $4315 [$7E:4315] ;} DMA1 size = X[4..5] $808C63 A9 19 LDA #$19 ;\ $808C65 8D 11 43 STA $4311 [$7E:4311] ;} Set DMA1 dest. to $2119 (VRAM data write high) $808C68 BC 06 00 LDY $0006,x[$7E:02D6] ;\ $808C6B 8C 16 21 STY $2116 [$7E:2116] ;} VRAM address = X[6..7] $808C6E BD 08 00 LDA $0008,x[$7E:02D8] ;\ $808C71 8D 15 21 STA $2115 [$7E:2115] ;} Video port control = X[8] $808C74 A9 02 LDA #$02 ;\ $808C76 8D 0B 42 STA $420B [$7E:420B] ;} Execute DMA slot 1 $808C79 C2 21 REP #$21 ;\ $808C7B 8A TXA ;| $808C7C 69 09 00 ADC #$0009 ;} Next X slot $808C7F AA TAX ;/ $808C80 4C D4 8B JMP $8BD4 [$80:8BD4] ; Loop back to test next X[0] } ;;; Process $D0,X VRAM writes ;;; { $808C83 08 PHP $808C84 C2 30 REP #$30 $808C86 AE 30 03 LDX $0330 [$7E:0330] ;\ $808C89 F0 3E BEQ $3E [$8CC9] ;} If next available slot index == 0: execute scrolling DMAs and return $808C8B 74 D0 STZ $D0,x [$7E:00D7] ; Clear next available slot size $808C8D A9 01 18 LDA #$1801 ;\ $808C90 8D 10 43 STA $4310 [$7E:4310] ;} Set 16-bit DMA, through $2018 (VRAM data write) $808C93 A0 00 00 LDY #$0000 $808C96 B9 D0 00 LDA $00D0,y[$7E:00D0] ;\ $808C99 F0 2E BEQ $2E [$8CC9] ;} If slot's size is clear: clear next available slot index, execute scrolling DMAs and return $808C9B 8D 15 43 STA $4315 [$7E:4315] ; Store to DMA size $808C9E B9 D2 00 LDA $00D2,y[$7E:00D2] ;\ $808CA1 8D 12 43 STA $4312 [$7E:4312] ;| $808CA4 B9 D3 00 LDA $00D3,y[$7E:00D3] ;} Store slot's source to DMA source $808CA7 8D 13 43 STA $4313 [$7E:4313] ;/ $808CAA A9 80 00 LDA #$0080 ; Normal video port control $808CAD B6 D5 LDX $D5,y [$7E:00D5] ;\ $808CAF 10 01 BPL $01 [$8CB2] ;} If slot's dest. is negative: $808CB1 1A INC A ; Enable 32-byte increment $808CB2 8D 15 21 STA $2115 [$7E:2115] $808CB5 8E 16 21 STX $2116 [$7E:2116] ; Store slot's dest. to VRAM address $808CB8 E2 20 SEP #$20 $808CBA A9 02 LDA #$02 ;\ $808CBC 8D 0B 42 STA $420B [$7E:420B] ;} Execute DMA $808CBF C2 20 REP #$20 $808CC1 98 TYA ;\ $808CC2 18 CLC ;| $808CC3 69 07 00 ADC #$0007 ;} Next slot $808CC6 A8 TAY ;/ $808CC7 80 CD BRA $CD [$8C96] ; Loop $808CC9 9C 30 03 STZ $0330 [$7E:0330] ; Clear next available slot index $808CCC E2 20 SEP #$20 $808CCE C2 10 REP #$10 $808CD0 20 D8 8C JSR $8CD8 [$80:8CD8] ; Execute horizontal scrolling DMAs $808CD3 20 AC 8D JSR $8DAC [$80:8DAC] ; Execute vertical scrolling DMAs $808CD6 28 PLP $808CD7 6B RTL } ;;; Execute horizontal scrolling DMAs ;;; { $808CD8 A9 81 LDA #$81 ;\ $808CDA 8D 15 21 STA $2115 [$7E:2115] ;} Enable 32-byte increment and 16-bit video port control $808CDD AD 62 09 LDA $0962 [$7E:0962] ;\ $808CE0 F0 62 BEQ $62 [$8D44] ;} If horizontal BG1 VRAM update flag: $808CE2 9C 62 09 STZ $0962 [$7E:0962] ; Clear horizontal BG1 VRAM update flag $808CE5 AC 5A 09 LDY $095A [$7E:095A] ;\ $808CE8 8C 16 21 STY $2116 [$7E:2116] ;| $808CEB A2 01 18 LDX #$1801 ;| $808CEE 8E 10 43 STX $4310 [$7E:4310] ;| $808CF1 A2 C8 C8 LDX #$C8C8 ;| $808CF4 8E 12 43 STX $4312 [$7E:4312] ;| $808CF7 A9 7E LDA #$7E ;} DMA [$0956] bytes from $7E:C8C8 horizontal scroll left tilemap to [$095A] VRAM $808CF9 8D 14 43 STA $4314 [$7E:4314] ;| $808CFC AE 56 09 LDX $0956 [$7E:0956] ;| $808CFF 8E 15 43 STX $4315 [$7E:4315] ;| $808D02 A9 02 LDA #$02 ;| $808D04 8D 0B 42 STA $420B [$7E:420B] ;/ $808D07 C8 INY ;\ $808D08 8C 16 21 STY $2116 [$7E:2116] ;| $808D0B 8E 15 43 STX $4315 [$7E:4315] ;| $808D0E A2 08 C9 LDX #$C908 ;} DMA [$0956] bytes from $7E:C908 horizontal scroll right tilemap to [$095A]+1 VRAM $808D11 8E 12 43 STX $4312 [$7E:4312] ;| $808D14 A9 02 LDA #$02 ;| $808D16 8D 0B 42 STA $420B [$7E:420B] ;/ $808D19 AE 5E 09 LDX $095E [$7E:095E] ;\ $808D1C 8E 12 43 STX $4312 [$7E:4312] ;| $808D1F AE 58 09 LDX $0958 [$7E:0958] ; \ $808D22 F0 20 BEQ $20 [$8D44] ; } If [$0958]: $808D24 8E 15 43 STX $4315 [$7E:4315] ;| $808D27 AC 5C 09 LDY $095C [$7E:095C] ;} DMA [$0958] bytes from $7E:[$095E] to [$095C] VRAM $808D2A 8C 16 21 STY $2116 [$7E:2116] ;| $808D2D A9 02 LDA #$02 ;| $808D2F 8D 0B 42 STA $420B [$7E:420B] ;/ $808D32 C8 INY ;\ $808D33 8C 16 21 STY $2116 [$7E:2116] ;| $808D36 8E 15 43 STX $4315 [$7E:4315] ;| $808D39 AE 60 09 LDX $0960 [$7E:0960] ;} DMA [$0958] bytes from $7E:[$0960] to [$095C]+1 VRAM $808D3C 8E 12 43 STX $4312 [$7E:4312] ;| $808D3F A9 02 LDA #$02 ;| $808D41 8D 0B 42 STA $420B [$7E:420B] ;/ $808D44 AD 7E 09 LDA $097E [$7E:097E] ;\ $808D47 F0 62 BEQ $62 [$8DAB] ;} [$097E]: $808D49 9C 7E 09 STZ $097E [$7E:097E] ; Clear $097E $808D4C AC 76 09 LDY $0976 [$7E:0976] ;\ $808D4F 8C 16 21 STY $2116 [$7E:2116] ;| $808D52 A2 01 18 LDX #$1801 ;| $808D55 8E 10 43 STX $4310 [$7E:4310] ;| $808D58 A2 D0 C9 LDX #$C9D0 ;| $808D5B 8E 12 43 STX $4312 [$7E:4312] ;| $808D5E A9 7E LDA #$7E ;} DMA [$0972] bytes from $7E:C9D0 to [$0976] VRAM $808D60 8D 14 43 STA $4314 [$7E:4314] ;| $808D63 AE 72 09 LDX $0972 [$7E:0972] ;| $808D66 8E 15 43 STX $4315 [$7E:4315] ;| $808D69 A9 02 LDA #$02 ;| $808D6B 8D 0B 42 STA $420B [$7E:420B] ;/ $808D6E C8 INY ;\ $808D6F 8C 16 21 STY $2116 [$7E:2116] ;| $808D72 8E 15 43 STX $4315 [$7E:4315] ;| $808D75 A2 10 CA LDX #$CA10 ;} DMA [$0972] bytes from $7E:CA10 to [$0976]+1 VRAM $808D78 8E 12 43 STX $4312 [$7E:4312] ;| $808D7B A9 02 LDA #$02 ;| $808D7D 8D 0B 42 STA $420B [$7E:420B] ;/ $808D80 AE 7A 09 LDX $097A [$7E:097A] ;\ $808D83 8E 12 43 STX $4312 [$7E:4312] ;| $808D86 AE 74 09 LDX $0974 [$7E:0974] ; \ $808D89 F0 20 BEQ $20 [$8DAB] ; } If [$0974]: $808D8B 8E 15 43 STX $4315 [$7E:4315] ;| $808D8E AC 78 09 LDY $0978 [$7E:0978] ;} DMA [$0974] bytes from $7E:[$097A] to [$0978] VRAM $808D91 8C 16 21 STY $2116 [$7E:2116] ;| $808D94 A9 02 LDA #$02 ;| $808D96 8D 0B 42 STA $420B [$7E:420B] ;/ $808D99 C8 INY ;\ $808D9A 8C 16 21 STY $2116 [$7E:2116] ;| $808D9D 8E 15 43 STX $4315 [$7E:4315] ;| $808DA0 AE 7C 09 LDX $097C [$7E:097C] ;} DMA [$0974] bytes from $7E:[$097C] to [$0978]+1 VRAM $808DA3 8E 12 43 STX $4312 [$7E:4312] ;| $808DA6 A9 02 LDA #$02 ;| $808DA8 8D 0B 42 STA $420B [$7E:420B] ;/ $808DAB 60 RTS } ;;; Execute vertical scrolling DMAs ;;; { $808DAC A9 80 LDA #$80 ;\ $808DAE 8D 15 21 STA $2115 [$7E:2115] ;} Enable 16-bit video port control $808DB1 AD 70 09 LDA $0970 [$7E:0970] ;\ $808DB4 F0 70 BEQ $70 [$8E26] ;} If vertical BG1 VRAM update flag: $808DB6 9C 70 09 STZ $0970 [$7E:0970] ; Clear vertical BG1 VRAM update flag $808DB9 AC 68 09 LDY $0968 [$7E:0968] ;\ $808DBC 8C 16 21 STY $2116 [$7E:2116] ;| $808DBF A2 01 18 LDX #$1801 ;| $808DC2 8E 10 43 STX $4310 [$7E:4310] ;| $808DC5 A2 48 C9 LDX #$C948 ;| $808DC8 8E 12 43 STX $4312 [$7E:4312] ;| $808DCB A9 7E LDA #$7E ;} DMA [$0964] bytes from $7E:C948 vertical scroll top tilemap to [$0968] VRAM $808DCD 8D 14 43 STA $4314 [$7E:4314] ;| $808DD0 AE 64 09 LDX $0964 [$7E:0964] ;| $808DD3 8E 15 43 STX $4315 [$7E:4315] ;| $808DD6 A9 02 LDA #$02 ;| $808DD8 8D 0B 42 STA $420B [$7E:420B] ;/ $808DDB C2 20 REP #$20 ;\ $808DDD 98 TYA ;| $808DDE 09 20 00 ORA #$0020 ;| $808DE1 8D 16 21 STA $2116 [$7E:2116] ;| $808DE4 E2 20 SEP #$20 ;| $808DE6 8E 15 43 STX $4315 [$7E:4315] ;} DMA [$0964] bytes from $7E:C98C vertical scroll bottom tilemap to [$0968]|20h VRAM $808DE9 A2 8C C9 LDX #$C98C ;| $808DEC 8E 12 43 STX $4312 [$7E:4312] ;| $808DEF A9 02 LDA #$02 ;| $808DF1 8D 0B 42 STA $420B [$7E:420B] ;/ $808DF4 AE 6C 09 LDX $096C [$7E:096C] ;\ $808DF7 8E 12 43 STX $4312 [$7E:4312] ;| $808DFA AE 66 09 LDX $0966 [$7E:0966] ; \ $808DFD F0 27 BEQ $27 [$8E26] ; } If [$0966]: $808DFF 8E 15 43 STX $4315 [$7E:4315] ;| $808E02 AC 6A 09 LDY $096A [$7E:096A] ;} DMA [$0966] bytes from $7E:[$096C] to [$096A] VRAM $808E05 8C 16 21 STY $2116 [$7E:2116] ;| $808E08 A9 02 LDA #$02 ;| $808E0A 8D 0B 42 STA $420B [$7E:420B] ;/ $808E0D C2 20 REP #$20 ;\ $808E0F 98 TYA ;| $808E10 09 20 00 ORA #$0020 ;| $808E13 8D 16 21 STA $2116 [$7E:2116] ;| $808E16 E2 20 SEP #$20 ;| $808E18 8E 15 43 STX $4315 [$7E:4315] ;} DMA [$0966] bytes from $7E:[$096E] to [$096A]|20h VRAM $808E1B AE 6E 09 LDX $096E [$7E:096E] ;| $808E1E 8E 12 43 STX $4312 [$7E:4312] ;| $808E21 A9 02 LDA #$02 ;| $808E23 8D 0B 42 STA $420B [$7E:420B] ;/ $808E26 AD 8C 09 LDA $098C [$7E:098C] ;\ $808E29 F0 76 BEQ $76 [$8EA1] ;} If [$098C]: $808E2B 9C 8C 09 STZ $098C [$7E:098C] ; Clear $098C $808E2E AC 84 09 LDY $0984 [$7E:0984] ;\ $808E31 8C 16 21 STY $2116 [$7E:2116] ;| $808E34 A2 01 18 LDX #$1801 ;| $808E37 8E 10 43 STX $4310 [$7E:4310] ;| $808E3A A2 50 CA LDX #$CA50 ;| $808E3D 8E 12 43 STX $4312 [$7E:4312] ;| $808E40 A9 7E LDA #$7E ;} DMA [$0980] bytes from $7E:CA50 to [$0984] VRAM $808E42 8D 14 43 STA $4314 [$7E:4314] ;| $808E45 AE 80 09 LDX $0980 [$7E:0980] ;| $808E48 8E 15 43 STX $4315 [$7E:4315] ;| $808E4B A9 02 LDA #$02 ;| $808E4D 8D 0B 42 STA $420B [$7E:420B] ;/ $808E50 C2 20 REP #$20 ;\ $808E52 98 TYA ;| $808E53 09 20 00 ORA #$0020 ;| $808E56 8D 16 21 STA $2116 [$7E:2116] ;| $808E59 E2 20 SEP #$20 ;| $808E5B 8E 15 43 STX $4315 [$7E:4315] ;} DMA [$0980] bytes from $7E:CA94 to [$0984]|20h VRAM $808E5E A2 94 CA LDX #$CA94 ;| $808E61 8E 12 43 STX $4312 [$7E:4312] ;| $808E64 A9 02 LDA #$02 ;| $808E66 8D 0B 42 STA $420B [$7E:420B] ;/ $808E69 AE 88 09 LDX $0988 [$7E:0988] ;\ $808E6C 8E 12 43 STX $4312 [$7E:4312] ;| $808E6F AE 82 09 LDX $0982 [$7E:0982] ; \ $808E72 F0 2D BEQ $2D [$8EA1] ; } If [$0982]: $808E74 8E 15 43 STX $4315 [$7E:4315] ;| $808E77 AC 86 09 LDY $0986 [$7E:0986] ;} DMA [$0982] bytes from $7E:[$0988] to [$0986] VRAM $808E7A 8C 16 21 STY $2116 [$7E:2116] ;| $808E7D A9 02 LDA #$02 ;| $808E7F 8D 0B 42 STA $420B [$7E:420B] ;/ $808E82 E2 02 SEP #$02 ;\ $808E84 F0 02 BEQ $02 [$8E88] ;} Strange unconditional jump o_O $808E86 80 FE BRA $FE [$8E86] ; Crash $808E88 C2 20 REP #$20 ;\ $808E8A 98 TYA ;| $808E8B 09 20 00 ORA #$0020 ;| $808E8E 8D 16 21 STA $2116 [$7E:2116] ;| $808E91 E2 20 SEP #$20 ;| $808E93 8E 15 43 STX $4315 [$7E:4315] ;} DMA [$0982] bytes from $7E:[$098A] to [$0986]|20h VRAM $808E96 AE 8A 09 LDX $098A [$7E:098A] ;| $808E99 8E 12 43 STX $4312 [$7E:4312] ;| $808E9C A9 02 LDA #$02 ;| $808E9E 8D 0B 42 STA $420B [$7E:420B] ;/ $808EA1 60 RTS } ;;; Handle $0340,X VRAM reads ;;; { $808EA2 08 PHP $808EA3 E2 30 SEP #$30 $808EA5 AE 60 03 LDX $0360 [$7E:0360] ;\ $808EA8 D0 02 BNE $02 [$8EAC] ;} If next available slot index is clear: return $808EAA 28 PLP $808EAB 6B RTL $808EAC 9E 40 03 STZ $0340,x[$7E:0349] ; Clear next available slot source $808EAF A2 00 LDX #$00 $808EB1 A9 80 LDA #$80 ;\ $808EB3 8D 15 21 STA $2115 [$7E:2115] ;} Set 16-bit video port control $808EB6 C2 20 REP #$20 $808EB8 BD 40 03 LDA $0340,x[$7E:0340] ;\ $808EBB F0 32 BEQ $32 [$8EEF] ;} If slot's source is clear: clear next avaiable slot index and return $808EBD 8D 16 21 STA $2116 [$7E:2116] ;\ $808EC0 AD 39 21 LDA $2139 [$7E:2139] ;} Store slot's source to VRAM address $808EC3 BD 42 03 LDA $0342,x[$7E:0342] ;\ $808EC6 8D 10 43 STA $4310 [$7E:4310] ;} Store slot's control and source offset to DMA control and source offset $808EC9 BD 44 03 LDA $0344,x[$7E:0344] ;\ $808ECC 8D 12 43 STA $4312 [$7E:4312] ;| $808ECF BD 45 03 LDA $0345,x[$7E:0345] ;} Store slot's dest. to DMA dest. $808ED2 8D 13 43 STA $4313 [$7E:4313] ;/ $808ED5 BD 47 03 LDA $0347,x[$7E:0347] ;\ $808ED8 8D 15 43 STA $4315 [$7E:4315] ;} Store slot's size to DMA size $808EDB 9C 17 43 STZ $4317 [$7E:4317] ;\ $808EDE 9C 19 43 STZ $4319 [$7E:4319] ;} Clear HDMA registers $808EE1 E2 20 SEP #$20 $808EE3 A9 02 LDA #$02 ;\ $808EE5 8D 0B 42 STA $420B [$7E:420B] ;} Execute DMA $808EE8 8A TXA ;\ $808EE9 18 CLC ;| $808EEA 69 09 ADC #$09 ;} Next slot $808EEC AA TAX ;/ $808EED 80 C7 BRA $C7 [$8EB6] ; Loop $808EEF 9C 60 03 STZ $0360 [$7E:0360] ; Clear next available slot index $808EF2 28 PLP $808EF3 6B RTL } ;;; Check for command timer ;;; { ;; Returns carry: set if there's a timer, clear if there are no timers $808EF4 08 PHP $808EF5 C2 30 REP #$30 $808EF7 DA PHX $808EF8 A2 0E 00 LDX #$000E $808EFB BD 29 06 LDA $0629,x[$7E:0637] $808EFE D0 08 BNE $08 [$8F08] $808F00 CA DEX $808F01 CA DEX $808F02 10 F7 BPL $F7 [$8EFB] $808F04 FA PLX $808F05 28 PLP $808F06 18 CLC $808F07 6B RTL $808F08 FA PLX $808F09 28 PLP $808F0A 38 SEC $808F0B 6B RTL } ;;; ;;; { ; Called by a load of message box routines $808F0C 08 PHP $808F0D C2 20 REP #$20 $808F0F CE 3F 06 DEC $063F [$7E:063F] ; Decrement current instruction delay $808F12 30 33 BMI $33 [$8F47] ; If current instruction delay > 0: return $808F14 F0 02 BEQ $02 [$8F18] ;\ $808F16 28 PLP ;| $808F17 6B RTL ;} If current instruction delay == 0: ;/ $808F18 AD 3D 06 LDA $063D [$7E:063D] ;\ $808F1B 30 45 BMI $45 [$8F62] ;} If positive value (new track index): $808F1D E2 20 SEP #$20 $808F1F 29 7F AND #$7F ;\ $808F21 8D F5 07 STA $07F5 [$7E:07F5] ;| $808F24 9C F6 07 STZ $07F6 [$7E:07F6] ;} Current track index = APUIO0 = current loaded track index = new track index & 007Fh $808F27 8D 40 21 STA $2140 [$7E:2140] ;| $808F2A 8D 4C 06 STA $064C [$7E:064C] ;/ $808F2D C2 20 REP #$20 $808F2F A9 08 00 LDA #$0008 ;\ $808F32 8D 86 06 STA $0686 [$7E:0686] ;} $0686 = 8 $808F35 AE 3B 06 LDX $063B [$7E:063B] ;\ $808F38 9E 19 06 STZ $0619,x[$7E:061B] ;} Clear new track number and instruction delay for current index $808F3B 9E 29 06 STZ $0629,x[$7E:062B] ;/ $808F3E E8 INX ;\ $808F3F E8 INX ;| $808F40 8A TXA ;} New index += 2, looping from 0Eh to 00h $808F41 29 0E 00 AND #$000E ;| $808F44 8D 3B 06 STA $063B [$7E:063B] ;/ $808F47 AE 3B 06 LDX $063B [$7E:063B] ;\ $808F4A EC 39 06 CPX $0639 [$7E:0639] ;} If current index != next available index: $808F4D F0 0E BEQ $0E [$8F5D] ;/ $808F4F BD 19 06 LDA $0619,x[$7E:0619] ;\ $808F52 8D 3D 06 STA $063D [$7E:063D] ;| $808F55 BD 29 06 LDA $0629,x[$7E:0629] ;} Use current index for current track index and instruction delay $808F58 8D 3F 06 STA $063F [$7E:063F] ;/ $808F5B 28 PLP $808F5C 6B RTL $808F5D 9C 3F 06 STZ $063F [$7E:063F] ; Clear current instruction delay $808F60 28 PLP $808F61 6B RTL $808F62 29 FF 00 AND #$00FF ;\ Else: negative [$063D] (new music/instrument index) $808F65 8D F3 07 STA $07F3 [$7E:07F3] ;} Current loaded music/instrument index = new music/instrument index & 00FFh $808F68 AA TAX $808F69 E2 20 SEP #$20 $808F6B A9 FF LDA #$FF ;\ $808F6D 8D 4C 06 STA $064C [$7E:064C] ;} Current track index = FFh $808F70 C2 20 REP #$20 $808F72 BF E1 E7 8F LDA $8FE7E1,x[$8F:E7E4] ;\ $808F76 85 00 STA $00 [$7E:0000] ;| $808F78 BF E2 E7 8F LDA $8FE7E2,x[$8F:E7E5] ;} $00..$02 = $8FE7E1[music/instrument index] $808F7C 85 01 STA $01 [$7E:0001] ;/ $808F7E 22 24 80 80 JSL $808024[$80:8024] ; Upload to APU $808F82 E2 20 SEP #$20 $808F84 9C 4C 06 STZ $064C [$7E:064C] ; Clear current track index $808F87 C2 20 REP #$20 $808F89 AE 3B 06 LDX $063B [$7E:063B] ;\ $808F8C 9E 19 06 STZ $0619,x[$7E:0619] ;} Clear new track number and instruction delay for current index $808F8F 9E 29 06 STZ $0629,x[$7E:0629] ;/ $808F92 E8 INX ;\ $808F93 E8 INX ;| $808F94 8A TXA ;} New index += 2, looping from 0Eh to 00h $808F95 29 0E 00 AND #$000E ;| $808F98 8D 3B 06 STA $063B [$7E:063B] ;/ $808F9B A9 08 00 LDA #$0008 ;\ $808F9E 8D 86 06 STA $0686 [$7E:0686] ;} $0686 = 8 $808FA1 28 PLP $808FA2 6B RTL } ;;; Unused. Changes music song/instruments or music track to A, with an 16-frame delay. Does not stop 0639 from lapping 063B ;;; { ;; Takes a parameter in A $808FA3 08 PHP $808FA4 C2 30 REP #$30 $808FA6 DA PHX $808FA7 5A PHY $808FA8 AE 39 06 LDX $0639 [$7E:0639] ;\ $808FAB 9D 19 06 STA $0619,x ;} Store A to next available track/music/instrument index $808FAE A9 10 00 LDA #$0010 ;\ $808FB1 9D 29 06 STA $0629,x ;} Next available command instruction delay = 10h $808FB4 E8 INX ;\ $808FB5 E8 INX ;| $808FB6 8A TXA ;} Next available index += 2, looping from 0Eh to 00h $808FB7 29 0E 00 AND #$000E ;| $808FBA 8D 39 06 STA $0639 [$80:0639] ;/ $808FBD 7A PLY $808FBE FA PLX $808FBF 28 PLP $808FC0 6B RTL } ;;; Changes music song/instruments or music track to A, with an 8-frame delay. Makes sure 0639 does not lap 063B ;;; { $808FC1 08 PHP $808FC2 C2 30 REP #$30 $808FC4 DA PHX $808FC5 5A PHY $808FC6 AE 98 09 LDX $0998 [$7E:0998] ;\ $808FC9 E0 28 00 CPX #$0028 ;} If game state >= 28h (demo states): return $808FCC B0 25 BCS $25 [$8FF3] ;/ $808FCE 48 PHA ;\ $808FCF AD 39 06 LDA $0639 [$7E:0639] ;| $808FD2 1A INC A ;| $808FD3 1A INC A ;| $808FD4 29 0E 00 AND #$000E ;} If next available index + 2 == next index: return $808FD7 AA TAX ;| $808FD8 68 PLA ;| $808FD9 EC 3B 06 CPX $063B [$7E:063B] ;| $808FDC F0 15 BEQ $15 [$8FF3] ;/ $808FDE AE 39 06 LDX $0639 [$7E:0639] ;\ $808FE1 9D 19 06 STA $0619,x[$7E:0619] ;} Store A to next available track/music/instrument index $808FE4 A9 08 00 LDA #$0008 ;\ $808FE7 9D 29 06 STA $0629,x[$7E:0629] ;} Next available command instruction delay = 8 $808FEA E8 INX ;\ $808FEB E8 INX ;| $808FEC 8A TXA ;} Next available index += 2, looping from 0Eh to 00h $808FED 29 0E 00 AND #$000E ;| $808FF0 8D 39 06 STA $0639 [$7E:0639] ;/ $808FF3 7A PLY $808FF4 FA PLX $808FF5 28 PLP $808FF6 6B RTL } ;;; Changes music song/instruments or music track to A, with a Y-frame delay (minimum of 8). Does not stop 0639 from lapping 063B ;;; { $808FF7 08 PHP $808FF8 C2 30 REP #$30 $808FFA DA PHX $808FFB AE 98 09 LDX $0998 [$7E:0998] ;\ $808FFE E0 28 00 CPX #$0028 ;} If game state >= 28h (demo states): return $809001 B0 1B BCS $1B [$901E] ;/ $809003 AE 39 06 LDX $0639 [$7E:0639] ;\ $809006 9D 19 06 STA $0619,x[$7E:0619] ;} Store A to next available track/music/instrument index $809009 98 TYA ;\ $80900A C9 08 00 CMP #$0008 ;} If Y-parameter < 8: $80900D B0 03 BCS $03 [$9012] ;/ $80900F A9 08 00 LDA #$0008 ; Y-parameter = 8 $809012 9D 29 06 STA $0629,x[$7E:0629] ; Next available command instruction delay = Y-parameter $809015 E8 INX ;\ $809016 E8 INX ;| $809017 8A TXA ;} Next available index += 2, looping from 0Eh to 00h $809018 29 0E 00 AND #$000E ;| $80901B 8D 39 06 STA $0639 [$7E:0639] ;/ $80901E FA PLX $80901F 28 PLP $809020 6B RTL } ;;; Sound library 1, $0653 = 0Fh ;;; { $809021 DA PHX $809022 5A PHY $809023 08 PHP $809024 E2 30 SEP #$30 $809026 EB XBA $809027 A9 0F LDA #$0F $809029 80 26 BRA $26 [$9051] } ;;; Sound library 1, $0653 = 09h ;;; { $80902B DA PHX $80902C 5A PHY $80902D 08 PHP $80902E E2 30 SEP #$30 $809030 EB XBA $809031 A9 09 LDA #$09 $809033 80 1C BRA $1C [$9051] } ;;; Sound library 1, $0653 = 03h ;;; { $809035 DA PHX $809036 5A PHY $809037 08 PHP $809038 E2 30 SEP #$30 $80903A EB XBA $80903B A9 03 LDA #$03 $80903D 80 12 BRA $12 [$9051] } ;;; Sound library 1, $0653 = 01h ;;; { $80903F DA PHX $809040 5A PHY $809041 08 PHP $809042 E2 30 SEP #$30 $809044 EB XBA $809045 A9 01 LDA #$01 $809047 80 08 BRA $08 [$9051] } ;;; Sound library 1, $0653 = 06h ;;; { $809049 DA PHX $80904A 5A PHY $80904B 08 PHP $80904C E2 30 SEP #$30 $80904E EB XBA $80904F A9 06 LDA #$06 } ;;; Sound library 1 ;;; { ;; Takes a parameter in the high byte of A: sound to queue ; $0643: Currently playing index of queued sound clips ; $0646: Current index of queued sound clips ; $0653: Maximum allowed queue number for new sound trying to play ; $0656: Queue of sound clips $809051 8D 53 06 STA $0653 [$7E:0653] $809054 AD 46 06 LDA $0646 [$7E:0646] ;\ $809057 38 SEC ;| $809058 ED 43 06 SBC $0643 [$7E:0643] ;| $80905B 29 0F AND #$0F ;} [$0646]-[$0643]&0Fh >= [$0653]: return $80905D CD 53 06 CMP $0653 [$7E:0653] ;| $809060 B0 30 BCS $30 [$9092] ;/ $809062 EB XBA $809063 C2 30 REP #$30 $809065 AE F5 05 LDX $05F5 [$7E:05F5] ;\ $809068 D0 28 BNE $28 [$9092] ;} If sounds disabled: return $80906A AE 98 09 LDX $0998 [$7E:0998] ;\ $80906D E0 28 00 CPX #$0028 ;} If game state >= 28h (demo states): return $809070 B0 20 BCS $20 [$9092] ;/ $809072 AE 92 05 LDX $0592 [$7E:0592] ;\ $809075 30 1B BMI $1B [$9092] ;} If [$0592] is negative ???: return $809077 E2 30 SEP #$30 $809079 AC 46 06 LDY $0646 [$7E:0646] ;\ $80907C BB TYX ;} X = [$0646]+1 $80907D E8 INX ;/ $80907E E0 10 CPX #$10 ;\ $809080 90 02 BCC $02 [$9084] ;} If X >= 10h: $809082 A2 00 LDX #$00 ; X = 0 $809084 EC 43 06 CPX $0643 [$7E:0643] ;\ $809087 F0 0D BEQ $0D [$9096] ;} If X != [$0643]: $809089 99 56 06 STA $0656,y[$7E:0656] ; $0656+[$0646] = A-parameter $80908C 8E 46 06 STX $0646 [$7E:0646] ; $0646 = X $80908F 9E 56 06 STZ $0656,x[$7E:0657] ; Clear $0656+X $809092 28 PLP $809093 7A PLY $809094 FA PLX $809095 6B RTL ; Else (X == [$0643]): $809096 20 A7 91 JSR $91A7 [$80:91A7] ; NOP : RTS $809099 D9 56 06 CMP $0656,y ;\ $80909C B0 F4 BCS $F4 [$9092] ;} If A-parameter < [$0656+[$0646]]: $80909E 99 56 06 STA $0656,y ; $0656+[$0646] = A-parameter $8090A1 80 EF BRA $EF [$9092] ; Return } ;;; Sound library 2, $0654 = 0Fh ;;; { $8090A3 DA PHX $8090A4 5A PHY $8090A5 08 PHP $8090A6 E2 30 SEP #$30 $8090A8 EB XBA $8090A9 A9 0F LDA #$0F $8090AB 80 26 BRA $26 [$90D3] } ;;; Sound library 2, $0654 = 09h ;;; { $8090AD DA PHX $8090AE 5A PHY $8090AF 08 PHP $8090B0 E2 30 SEP #$30 $8090B2 EB XBA $8090B3 A9 09 LDA #$09 $8090B5 80 1C BRA $1C [$90D3] } ;;; Sound library 2, $0654 = 03h ;;; { $8090B7 DA PHX $8090B8 5A PHY $8090B9 08 PHP $8090BA E2 30 SEP #$30 $8090BC EB XBA $8090BD A9 03 LDA #$03 $8090BF 80 12 BRA $12 [$90D3] } ;;; Sound library 2, $0654 = 01h ;;; { $8090C1 DA PHX $8090C2 5A PHY $8090C3 08 PHP $8090C4 E2 30 SEP #$30 $8090C6 EB XBA $8090C7 A9 01 LDA #$01 $8090C9 80 08 BRA $08 [$90D3] } ;;; Sound library 2, $0654 = 06h ;;; { $8090CB DA PHX $8090CC 5A PHY $8090CD 08 PHP $8090CE E2 30 SEP #$30 $8090D0 EB XBA $8090D1 A9 06 LDA #$06 } ;;; Sound library 2 ;;; { ;; Takes a parameter in the high byte of A: sound to queue ; $0644: Currently playing index of queued sound clips ; $0647: Current index of queued sound clips ; $0654: Maximum allowed queue number for new sound trying to play ; $0666: Queue of sound clips $8090D3 8D 54 06 STA $0654 [$7E:0654] $8090D6 AD 47 06 LDA $0647 [$7E:0647] ;\ $8090D9 38 SEC ;| $8090DA ED 44 06 SBC $0644 [$7E:0644] ;| $8090DD 29 0F AND #$0F ;} [$0647]-[$0644]&0Fh >= [$0654]: return $8090DF CD 54 06 CMP $0654 [$7E:0654] ;| $8090E2 B0 30 BCS $30 [$9114] ;/ $8090E4 EB XBA $8090E5 C2 30 REP #$30 $8090E7 AE F5 05 LDX $05F5 [$7E:05F5] ;\ $8090EA D0 28 BNE $28 [$9114] ;} If sounds disabled: return $8090EC AE 98 09 LDX $0998 [$7E:0998] ;\ $8090EF E0 28 00 CPX #$0028 ;} If game state >= 28h (demo states): return $8090F2 B0 20 BCS $20 [$9114] ;/ $8090F4 AE 92 05 LDX $0592 [$7E:0592] ;\ $8090F7 30 1B BMI $1B [$9114] ;} If [$0592] is negative ???: return $8090F9 E2 30 SEP #$30 $8090FB AC 47 06 LDY $0647 [$7E:0647] ;\ $8090FE BB TYX ;} X = [$0647]+1 $8090FF E8 INX ;\ $809100 E0 10 CPX #$10 ;} If X >= 10h: $809102 90 02 BCC $02 [$9106] ;/ $809104 A2 00 LDX #$00 ; X = 0 $809106 EC 44 06 CPX $0644 [$7E:0644] ;\ $809109 F0 0D BEQ $0D [$9118] ;} If X != [$0644]: $80910B 99 66 06 STA $0666,y[$7E:0666] ; $0666+[$0647] = A-parameter $80910E 8E 47 06 STX $0647 [$7E:0647] ; $0647 = X $809111 9E 66 06 STZ $0666,x[$7E:0667] ; Clear $0666+X $809114 28 PLP $809115 7A PLY $809116 FA PLX $809117 6B RTL ; Else (X == [$0644]): $809118 20 A7 91 JSR $91A7 [$80:91A7] ; NOP : RTS $80911B D9 66 06 CMP $0666,y ;\ $80911E B0 F4 BCS $F4 [$9114] ;} If A-parameter < [$0666+[$0647]]: $809120 99 66 06 STA $0666,y ; $0666+[$0647] = A-parameter $809123 80 EF BRA $EF [$9114] ; Return } ;;; Sound library 3, $0655 = 0Fh ;;; { $809125 DA PHX $809126 5A PHY $809127 08 PHP $809128 E2 30 SEP #$30 $80912A EB XBA $80912B A9 0F LDA #$0F $80912D 80 26 BRA $26 [$9155] } ;;; Sound library 3, $0655 = 09h ;;; { $80912F DA PHX $809130 5A PHY $809131 08 PHP $809132 E2 30 SEP #$30 $809134 EB XBA $809135 A9 09 LDA #$09 $809137 80 1C BRA $1C [$9155] } ;;; Sound library 3, $0655 = 03h ;;; { $809139 DA PHX $80913A 5A PHY $80913B 08 PHP $80913C E2 30 SEP #$30 $80913E EB XBA $80913F A9 03 LDA #$03 $809141 80 12 BRA $12 [$9155] } ;;; Sound library 3, $0655 = 01h ;;; { $809143 DA PHX $809144 5A PHY $809145 08 PHP $809146 E2 30 SEP #$30 $809148 EB XBA $809149 A9 01 LDA #$01 $80914B 80 08 BRA $08 [$9155] } ;;; Sound library 3, $0655 = 06h ;;; { $80914D DA PHX $80914E 5A PHY $80914F 08 PHP $809150 E2 30 SEP #$30 $809152 EB XBA $809153 A9 06 LDA #$06 } ;;; Sound library 3 ;;; { ;; Takes a parameter in the high byte of A: sound to queue ; $0645: Currently playing index of queued sound clips ; $0648: Current index of queued sound clips ; $0655: Maximum allowed queue number for new sound trying to play ; $0676: Queue of sound clips $809155 8D 55 06 STA $0655 [$7E:0655] $809158 AD 48 06 LDA $0648 [$7E:0648] ;\ $80915B 38 SEC ;| $80915C ED 45 06 SBC $0645 [$7E:0645] ;| $80915F 29 0F AND #$0F ;} [$0648]-[$0645]&0Fh >= [$0655]: return $809161 CD 55 06 CMP $0655 [$7E:0655] ;| $809164 B0 30 BCS $30 [$9196] ;/ $809166 EB XBA $809167 C2 30 REP #$30 $809169 AE F5 05 LDX $05F5 [$7E:05F5] ;\ $80916C D0 28 BNE $28 [$9196] ;} If sounds disabled: return $80916E AE 98 09 LDX $0998 [$7E:0998] ;\ $809171 E0 28 00 CPX #$0028 ;} If game state >= 28h (demo states): return $809174 B0 20 BCS $20 [$9196] ;/ $809176 AE 92 05 LDX $0592 [$7E:0592] ;\ $809179 30 1B BMI $1B [$9196] ;} If [$0592] is negative ???: return $80917B E2 30 SEP #$30 $80917D AC 48 06 LDY $0648 [$7E:0648] ;\ $809180 BB TYX ;} X = [$0648]+1 $809181 E8 INX ;\ $809182 E0 10 CPX #$10 ;} If X >= 10h: $809184 90 02 BCC $02 [$9188] ;/ $809186 A2 00 LDX #$00 ; X = 0 $809188 EC 45 06 CPX $0645 [$7E:0645] ;\ $80918B F0 0D BEQ $0D [$919A] ;} If X != [$0645]: $80918D 99 76 06 STA $0676,y[$7E:0676] ; $0676+[$0648] = A-parameter $809190 8E 48 06 STX $0648 [$7E:0648] ; $0648 = X $809193 9E 76 06 STZ $0676,x[$7E:0677] ; Clear $0676+X $809196 28 PLP $809197 7A PLY $809198 FA PLX $809199 6B RTL ; Else (X == [$0645]): $80919A 20 A7 91 JSR $91A7 [$80:91A7] ; NOP : RTS $80919D D9 76 06 CMP $0676,y ;\ $8091A0 B0 F4 BCS $F4 [$9196] ;} If A-parameter < [$0676+[$0648]]: $8091A2 99 76 06 STA $0676,y ; $0676+[$0648] = A-parameter $8091A5 80 EF BRA $EF [$9196] ; Return } ;;; NOP : RTS ;;; { $8091A7 EA NOP $8091A8 60 RTS } ;;; Set up a (H)DMA transfer ;;; { ;; Takes a parameter: first byte tells channel (0..7), next 7 are copied into 43x0-43x6 ; $2116 should be set before hand, if it's being used $8091A9 08 PHP $8091AA 8B PHB $8091AB C2 30 REP #$30 $8091AD A3 04 LDA $04,s [$7E:1FF9] ;\ $8091AF 48 PHA ;| $8091B0 AB PLB ;} Load data from caller bank $8091B1 AB PLB ;/ $8091B2 A3 03 LDA $03,s [$7E:1FF8] ;\ $8091B4 A8 TAY ;} Y+1 = parameter address $8091B5 B9 01 00 LDA $0001,y[$8B:92B9] ;\ $8091B8 29 FF 00 AND #$00FF ;| $8091BB AA TAX ;} X = DMA slot offset = Parameter[0] << 4 $8091BC BF E6 91 80 LDA $8091E6,x[$80:91E7] ;| (Or, ya know, ASL #4) $8091C0 29 FF 00 AND #$00FF ;/ $8091C3 AA TAX $8091C4 B9 02 00 LDA $0002,y[$8B:92BA] ;\ $8091C7 9D 00 43 STA $4300,x[$7E:4310] ;| $8091CA B9 04 00 LDA $0004,y[$8B:92BC] ;| $8091CD 9D 02 43 STA $4302,x[$7E:4312] ;| $8091D0 B9 06 00 LDA $0006,y[$8B:92BE] ;} $4300+X..$4306+X = Parameter[1..7] $8091D3 9D 04 43 STA $4304,x[$7E:4314] ;| $8091D6 B9 07 00 LDA $0007,y[$8B:92BF] ;| $8091D9 9D 05 43 STA $4305,x[$7E:4315] ;/ $8091DC 98 TYA ;\ $8091DD 18 CLC ;| $8091DE 69 08 00 ADC #$0008 ;} Fix return address $8091E1 83 03 STA $03,s [$7E:1FF8] ;/ $8091E3 AB PLB $8091E4 28 PLP $8091E5 6B RTL $8091E6 db 00, 10, 20, 30, 40, 50, 60, 70 } ;;; Update hardware registers ;;; { $8091EE A6 84 LDX $84 [$7E:0084] ;\ $8091F0 8E 00 42 STX $4200 [$7E:4200] ;} Interrupt enable flags $8091F3 A6 51 LDX $51 [$7E:0051] ;\ $8091F5 8E 00 21 STX $2100 [$7E:2100] ;} Screen display $8091F8 A6 52 LDX $52 [$7E:0052] ;\ $8091FA 8E 01 21 STX $2101 [$7E:2101] ;} Object size and chr address $8091FD A6 55 LDX $55 [$7E:0055] ;\ $8091FF 8E 05 21 STX $2105 [$7E:2105] ;} BG mode and character size $809202 A6 57 LDX $57 [$7E:0057] ;\ $809204 8E 06 21 STX $2106 [$7E:2106] ;} Screen pixelation $809207 A6 58 LDX $58 [$7E:0058] ;\ $809209 8E 07 21 STX $2107 [$7E:2107] ;} BG1 tilemap address and size $80920C A6 59 LDX $59 [$7E:0059] ;\ $80920E 8E 08 21 STX $2108 [$7E:2108] ;} BG2 tilemap address and size $809211 A6 5A LDX $5A [$7E:005A] ;\ $809213 8E 09 21 STX $2109 [$7E:2109] ;} BG3 tilemap address and size $809216 A6 5C LDX $5C [$7E:005C] ;\ $809218 8E 0A 21 STX $210A [$7E:210A] ;} BG4 tilemap address and size $80921B A6 5D LDX $5D [$7E:005D] ;\ $80921D 8E 0B 21 STX $210B [$7E:210B] ;} BG1/2 chr address $809220 A6 5E LDX $5E [$7E:005E] ;\ $809222 8E 0C 21 STX $210C [$7E:210C] ;} BG3/4 chr address $809225 A6 5F LDX $5F [$7E:005F] ;\ $809227 8E 1A 21 STX $211A [$7E:211A] ;} Mode 7 settings $80922A A6 60 LDX $60 [$7E:0060] ;\ $80922C 8E 23 21 STX $2123 [$7E:2123] ;} BG1/2 window mask settings $80922F A6 61 LDX $61 [$7E:0061] ;\ $809231 8E 24 21 STX $2124 [$7E:2124] ;} BG3/4 window mask settings $809234 A6 62 LDX $62 [$7E:0062] ;\ $809236 8E 25 21 STX $2125 [$7E:2125] ;} OBJ/color window mask settings $809239 A6 63 LDX $63 [$7E:0063] ;\ $80923B 8E 26 21 STX $2126 [$7E:2126] ;} Window 1 left position $80923E A6 64 LDX $64 [$7E:0064] ;\ $809240 8E 27 21 STX $2127 [$7E:2127] ;} Window 1 right position $809243 A6 65 LDX $65 [$7E:0065] ;\ $809245 8E 28 21 STX $2128 [$7E:2128] ;} Window 2 left position $809248 A6 66 LDX $66 [$7E:0066] ;\ $80924A 8E 29 21 STX $2129 [$7E:2129] ;} Window 2 right position $80924D A6 67 LDX $67 [$7E:0067] ;\ $80924F 8E 2A 21 STX $212A [$7E:212A] ;} BG window mask logic $809252 A6 68 LDX $68 [$7E:0068] ;\ $809254 8E 2B 21 STX $212B [$7E:212B] ;} OBJ/color window mask logic $809257 A6 69 LDX $69 [$7E:0069] ;\ $809259 86 6A STX $6A [$7E:006A] ;} Main screen designation $80925B 8E 2C 21 STX $212C [$7E:212C] ;/ $80925E A6 6C LDX $6C [$7E:006C] ;\ $809260 8E 2E 21 STX $212E [$7E:212E] ;} Main screen window mask designation $809263 A6 6B LDX $6B [$7E:006B] ;\ $809265 8E 2D 21 STX $212D [$7E:212D] ;} Subscreen designation $809268 A6 6D LDX $6D [$7E:006D] ;\ $80926A 8E 2F 21 STX $212F [$7E:212F] ;} Subscreen window mask designation $80926D A6 6F LDX $6F [$7E:006F] ;\ $80926F 8E 30 21 STX $2130 [$7E:2130] ;} Colour addition select $809272 A6 72 LDX $72 [$7E:0072] ;\ $809274 8E 31 21 STX $2131 [$7E:2131] ;} Colour math designation $809277 A6 6E LDX $6E [$7E:006E] ;\ $809279 86 70 STX $70 [$7E:0070] ;} $70 = $6E $80927B A6 71 LDX $71 [$7E:0071] ;\ $80927D 86 73 STX $73 [$7E:0073] ;} $73 = $71 $80927F A6 74 LDX $74 [$7E:0074] ;\ $809281 8E 32 21 STX $2132 [$7E:2132] ;| $809284 A6 75 LDX $75 [$7E:0075] ;| $809286 8E 32 21 STX $2132 [$7E:2132] ;} Fixed colour data $809289 A6 76 LDX $76 [$7E:0076] ;| $80928B 8E 32 21 STX $2132 [$7E:2132] ;/ $80928E A6 77 LDX $77 [$7E:0077] ;\ $809290 8E 33 21 STX $2133 [$7E:2133] ;} Screen mode / video select $809293 A6 B1 LDX $B1 [$7E:00B1] ;\ $809295 8E 0D 21 STX $210D [$7E:210D] ;| $809298 A6 B2 LDX $B2 [$7E:00B2] ;} BG1 horizontal scroll $80929A 8E 0D 21 STX $210D [$7E:210D] ;/ $80929D A6 B3 LDX $B3 [$7E:00B3] ;\ $80929F 8E 0E 21 STX $210E [$7E:210E] ;| $8092A2 A6 B4 LDX $B4 [$7E:00B4] ;} BG1 vertical scroll $8092A4 8E 0E 21 STX $210E [$7E:210E] ;/ $8092A7 A6 B5 LDX $B5 [$7E:00B5] ;\ $8092A9 8E 0F 21 STX $210F [$7E:210F] ;| $8092AC A6 B6 LDX $B6 [$7E:00B6] ;} BG2 horizontal scroll $8092AE 8E 0F 21 STX $210F [$7E:210F] ;/ $8092B1 A6 B7 LDX $B7 [$7E:00B7] ;\ $8092B3 8E 10 21 STX $2110 [$7E:2110] ;| $8092B6 A6 B8 LDX $B8 [$7E:00B8] ;} BG2 vertical scroll $8092B8 8E 10 21 STX $2110 [$7E:2110] ;/ $8092BB A6 B9 LDX $B9 [$7E:00B9] ;\ $8092BD 8E 11 21 STX $2111 [$7E:2111] ;| $8092C0 A6 BA LDX $BA [$7E:00BA] ;} BG3 horizontal scroll $8092C2 8E 11 21 STX $2111 [$7E:2111] ;/ $8092C5 A6 BB LDX $BB [$7E:00BB] ;\ $8092C7 8E 12 21 STX $2112 [$7E:2112] ;| $8092CA A6 BC LDX $BC [$7E:00BC] ;} BG3 vertical scroll $8092CC 8E 12 21 STX $2112 [$7E:2112] ;/ $8092CF A6 BD LDX $BD [$7E:00BD] ;\ $8092D1 8E 13 21 STX $2113 [$7E:2113] ;| $8092D4 A6 BE LDX $BE [$7E:00BE] ;} BG4 horizontal scroll $8092D6 8E 13 21 STX $2113 [$7E:2113] ;/ $8092D9 A6 BF LDX $BF [$7E:00BF] ;\ $8092DB 8E 14 21 STX $2114 [$7E:2114] ;| $8092DE A6 C0 LDX $C0 [$7E:00C0] ;} BG4 vertical scroll $8092E0 8E 14 21 STX $2114 [$7E:2114] ;/ $8092E3 A6 56 LDX $56 [$7E:0056] ;\ $8092E5 8E EC 07 STX $07EC [$7E:07EC] ;} $07EC = $56 $8092E8 A5 55 LDA $55 [$7E:0055] ;\ $8092EA 29 07 00 AND #$0007 ;| $8092ED C9 07 00 CMP #$0007 ;| $8092F0 F0 0B BEQ $0B [$92FD] ;| $8092F2 A5 56 LDA $56 [$7E:0056] ;} If [$55] hasn't 07h and [$56] hasn't 07h: return $8092F4 29 07 00 AND #$0007 ;| $8092F7 C9 07 00 CMP #$0007 ;| $8092FA F0 01 BEQ $01 [$92FD] ;/ $8092FC 60 RTS $8092FD A6 78 LDX $78 [$7E:0078] ;\ $8092FF 8E 1B 21 STX $211B [$7E:211B] ;| $809302 A6 79 LDX $79 [$7E:0079] ;} Mode 7 matrix A $809304 8E 1B 21 STX $211B [$7E:211B] ;/ $809307 A6 7A LDX $7A [$7E:007A] ;\ $809309 8E 1C 21 STX $211C [$7E:211C] ;| $80930C A6 7B LDX $7B [$7E:007B] ;} Mode 7 matrix B $80930E 8E 1C 21 STX $211C [$7E:211C] ;/ $809311 A6 7C LDX $7C [$7E:007C] ;\ $809313 8E 1D 21 STX $211D [$7E:211D] ;| $809316 A6 7D LDX $7D [$7E:007D] ;} Mode 7 matrix C $809318 8E 1D 21 STX $211D [$7E:211D] ;/ $80931B A6 7E LDX $7E [$7E:007E] ;\ $80931D 8E 1E 21 STX $211E [$7E:211E] ;| $809320 A6 7F LDX $7F [$7E:007F] ;} Mode 7 matrix D $809322 8E 1E 21 STX $211E [$7E:211E] ;/ $809325 A6 80 LDX $80 [$7E:0080] ;\ $809327 8E 1F 21 STX $211F [$7E:211F] ;| $80932A A6 81 LDX $81 [$7E:0081] ;} Mode 7 centre X $80932C 8E 1F 21 STX $211F [$7E:211F] ;/ $80932F A6 82 LDX $82 [$7E:0082] ;\ $809331 8E 20 21 STX $2120 [$7E:2120] ;| $809334 A6 83 LDX $83 [$7E:0083] ;} Mode 7 centre Y $809336 8E 20 21 STX $2120 [$7E:2120] ;/ $809339 60 RTS } ;;; Update OAM & CGRAM ;;; { $80933A A9 00 04 LDA #$0400 ;\ $80933D 8D 00 43 STA $4300 [$7E:4300] ;| $809340 A9 70 03 LDA #$0370 ;| $809343 8D 02 43 STA $4302 [$7E:4302] ;| $809346 A2 00 LDX #$00 ;} $0370..$058F -> OAM $809348 8E 04 43 STX $4304 [$7E:4304] ;| $80934B A9 20 02 LDA #$0220 ;| $80934E 8D 05 43 STA $4305 [$7E:4305] ;| $809351 9C 02 21 STZ $2102 [$7E:2102] ;/ $809354 A9 00 22 LDA #$2200 ;\ $809357 8D 10 43 STA $4310 [$7E:4310] ;| $80935A A9 00 C0 LDA #$C000 ;| $80935D 8D 12 43 STA $4312 [$7E:4312] ;| $809360 A2 7E LDX #$7E ;| $809362 8E 14 43 STX $4314 [$7E:4314] ;} $7EC000..$C1FF -> CGRAM $809365 A9 00 02 LDA #$0200 ;| $809368 8D 15 43 STA $4315 [$7E:4315] ;| $80936B A2 00 LDX #$00 ;| $80936D 8E 21 21 STX $2121 [$7E:2121] ;/ $809370 A2 03 LDX #$03 ;\ $809372 8E 0B 42 STX $420B [$7E:420B] ;} Execute the DMA $809375 60 RTS } ;;; Samus' graphics -> VRAM ;;; { $809376 8B PHB $809377 A2 92 LDX #$92 ;\ $809379 DA PHX ;} DB = 92h $80937A AB PLB ;/ $80937B A2 02 LDX #$02 $80937D A0 80 LDY #$80 ;\ $80937F 8C 15 21 STY $2115 [$7E:2115] ;} Set normal video port control for 16-bit $809382 AC 1D 07 LDY $071D [$7E:071D] ;\ $809385 F0 44 BEQ $44 [$93CB] ;} If Samus' top sprites need loaded to VRAM: $809387 A0 02 LDY #$02 $809389 AD 1F 07 LDA $071F [$7E:071F] ;\ $80938C 85 3C STA $3C [$7E:003C] ;} $3C = Samus' top sprites DMA pointer $80938E A9 00 60 LDA #$6000 ;\ $809391 8D 16 21 STA $2116 [$7E:2116] ;| $809394 A9 01 18 LDA #$1801 ;| $809397 8D 10 43 STA $4310 [$7E:4310] ;| $80939A B2 3C LDA ($3C) [$92:D0C5] ;| $80939C 8D 12 43 STA $4312 [$7E:4312] ;| $80939F 85 14 STA $14 [$7E:0014] ;} Set up DMA slot 1, [[$3C]+3..[$3C]+4] bytes from [[$3C]..[$3C]+2] to $6000 VRAM $8093A1 B1 3C LDA ($3C),y[$92:D0C7] ;| $8093A3 8D 14 43 STA $4314 [$7E:4314] ;| $8093A6 C8 INY ;| $8093A7 B1 3C LDA ($3C),y[$92:D0C8] ;| $8093A9 8D 15 43 STA $4315 [$7E:4315] ;/ $8093AC 18 CLC ;\ $8093AD 65 14 ADC $14 [$7E:0014] ;} $14 = DMA source + DMA size $8093AF 85 14 STA $14 [$7E:0014] ;/ $8093B1 C8 INY $8093B2 C8 INY $8093B3 8E 0B 42 STX $420B [$7E:420B] ; Execute DMA $8093B6 A9 00 61 LDA #$6100 ;\ $8093B9 8D 16 21 STA $2116 [$7E:2116] ;| $8093BC A5 14 LDA $14 [$7E:0014] ;| $8093BE 8D 12 43 STA $4312 [$7E:4312] ;| $8093C1 B1 3C LDA ($3C),y[$92:D0CA] ;} If [[$3C]+5..[$3C]+6]: DMA slot 1, [[$3C]+5..[$3C]+6] bytes from [$14..$15] to $6100 VRAM $8093C3 F0 06 BEQ $06 [$93CB] ;| $8093C5 8D 15 43 STA $4315 [$7E:4315] ;| $8093C8 8E 0B 42 STX $420B [$7E:420B] ;/ $8093CB AC 1E 07 LDY $071E [$7E:071E] ;\ $8093CE F0 44 BEQ $44 [$9414] ;} If Samus' bottom sprites need loaded to VRAM $8093D0 A0 02 LDY #$02 $8093D2 AD 21 07 LDA $0721 [$7E:0721] ;\ $8093D5 85 3C STA $3C [$7E:003C] ;} $3C = Samus' bottom sprites DMA pointer $8093D7 A9 80 60 LDA #$6080 ;\ $8093DA 8D 16 21 STA $2116 [$7E:2116] ;| $8093DD A9 01 18 LDA #$1801 ;| $8093E0 8D 10 43 STA $4310 [$7E:4310] ;| $8093E3 B2 3C LDA ($3C) [$92:D1C8] ;| $8093E5 8D 12 43 STA $4312 [$7E:4312] ;| $8093E8 85 14 STA $14 [$7E:0014] ;} Set up DMA slot 1, [[$3C]+3..[$3C]+4] bytes from [[$3C]..[$3C]+2] to $6080 VRAM $8093EA B1 3C LDA ($3C),y[$92:D1CA] ;| $8093EC 8D 14 43 STA $4314 [$7E:4314] ;| $8093EF C8 INY ;| $8093F0 B1 3C LDA ($3C),y[$92:D1CB] ;| $8093F2 8D 15 43 STA $4315 [$7E:4315] ;/ $8093F5 18 CLC ;\ $8093F6 65 14 ADC $14 [$7E:0014] ;} $14 = DMA source + DMA size $8093F8 85 14 STA $14 [$7E:0014] ;/ $8093FA C8 INY $8093FB C8 INY $8093FC 8E 0B 42 STX $420B [$7E:420B] ; Execute DMA $8093FF A9 80 61 LDA #$6180 ;\ $809402 8D 16 21 STA $2116 [$7E:2116] ;| $809405 A5 14 LDA $14 [$7E:0014] ;| $809407 8D 12 43 STA $4312 [$7E:4312] ;| $80940A B1 3C LDA ($3C),y[$92:D1CD] ;} If [[$3C]+5..[$3C]+6]: DMA slot 1, [[$3C]+5..[$3C]+6] bytes from [$14..$15] to $6180 VRAM $80940C F0 06 BEQ $06 [$9414] ;| $80940E 8D 15 43 STA $4315 [$7E:4315] ;| $809411 8E 0B 42 STX $420B [$7E:420B] ;/ $809414 AB PLB $809415 60 RTS } ;;; Handle misc. animations (spikes, FX1) ;;; { $809416 8B PHB $809417 A2 87 LDX #$87 ;\ $809419 DA PHX ;} DB = 87h $80941A AB PLB ;/ $80941B AD F1 1E LDA $1EF1 [$7E:1EF1] ;\ $80941E 10 37 BPL $37 [$9457] ;} If misc. animations disabled: return $809420 A2 0A LDX #$0A $809422 BD F5 1E LDA $1EF5,x[$7E:1EFF] ;\ $809425 F0 2C BEQ $2C [$9453] ;| $809427 BD 25 1F LDA $1F25,x[$7E:1F2F] ;} If misc. animation data pointer and graphic pointer: $80942A F0 27 BEQ $27 [$9453] ;/ $80942C 8D 02 43 STA $4302 [$7E:4302] ;\ $80942F A0 87 LDY #$87 ;| $809431 8C 04 43 STY $4304 [$7E:4304] ;| $809434 A9 01 18 LDA #$1801 ;| $809437 8D 00 43 STA $4300 [$7E:4300] ;| $80943A BD 31 1F LDA $1F31,x[$7E:1F3B] ;| $80943D 8D 05 43 STA $4305 [$7E:4305] ;} DMA slot 0, GraphicSize bytes from $87:GraphicPointer to VRAM_address VRAM $809440 BD 3D 1F LDA $1F3D,x[$7E:1F47] ;| $809443 8D 16 21 STA $2116 [$7E:2116] ;| $809446 A0 80 LDY #$80 ;| $809448 8C 15 21 STY $2115 [$7E:2115] ;| $80944B A0 01 LDY #$01 ;| $80944D 8C 0B 42 STY $420B [$7E:420B] ;/ $809450 9E 25 1F STZ $1F25,x[$7E:1F2F] ; Clear graphic pointer $809453 CA DEX ;\ $809454 CA DEX ;} Next $809455 10 CB BPL $CB [$9422] $809457 AB PLB $809458 60 RTS } ;;; Read controller input. Also a debug branch ;;; { ; I apologise for poor commenting here $809459 08 PHP $80945A E2 20 SEP #$20 $80945C AD 12 42 LDA $4212 [$7E:4212] ;\ $80945F 29 01 AND #$01 ;} Wait until Auto-Joypad read has finished $809461 D0 F9 BNE $F9 [$945C] ;/ $809463 C2 20 REP #$20 $809465 AD 18 42 LDA $4218 [$7E:4218] ; Hardware Joypad 1: BYsS^v<> AXLR0000 $809468 85 8B STA $8B [$7E:008B] ; Mirror to RAM $80946A 45 97 EOR $97 [$7E:0097] ;\ $80946C 25 8B AND $8B [$7E:008B] ;} Store newly pressed buttons to RAM $80946E 85 8F STA $8F [$7E:008F] ;/ $809470 85 93 STA $93 [$7E:0093] ; Mirror newly pressed buttons $809472 A5 8B LDA $8B [$7E:008B] ;\ $809474 F0 12 BEQ $12 [$9488] ;| $809476 C5 97 CMP $97 [$7E:0097] ;} If buttons are all newly pressed: $809478 D0 0E BNE $0E [$9488] ;/ $80947A C6 A3 DEC $A3 [$7E:00A3] ; Decrement this $80947C D0 0E BNE $0E [$948C] ; If this reached 0 (or buttons weren't all newly pressed): $80947E A5 8B LDA $8B [$7E:008B] ;\ $809480 85 93 STA $93 [$7E:0093] ;} Mirror newly pressed buttons again $809482 A5 89 LDA $89 [$7E:0089] ;\ $809484 85 A3 STA $A3 [$7E:00A3] ;} 'this' = that $809486 80 04 BRA $04 [$948C] $809488 A5 87 LDA $87 [$7E:0087] ;\ Else: $80948A 85 A3 STA $A3 [$7E:00A3] ;} 'this' = this $80948C A5 8B LDA $8B [$7E:008B] ;\ $80948E 85 97 STA $97 [$7E:0097] ;} Set next frame's previous input $809490 AD D1 05 LDA $05D1 [$7E:05D1] ;\ $809493 D0 02 BNE $02 [$9497] ;} Check for debug branch $809495 28 PLP $809496 6B RTL ; Debug branch, needs better commenting $809497 AD 1A 42 LDA $421A [$7E:421A] ; Hardware Joypad 2: BYsS^v<> AXLR0000 $80949A 85 8D STA $8D [$7E:008D] ; Mirror to RAM $80949C 45 99 EOR $99 [$7E:0099] ;\ $80949E 25 8D AND $8D [$7E:008D] ;} Store newly pressed buttons to RAM $8094A0 85 91 STA $91 [$7E:0091] ;/ $8094A2 85 95 STA $95 [$7E:0095] ; Mirror newly pressed buttons $8094A4 A5 8D LDA $8D [$7E:008D] ;\ $8094A6 F0 12 BEQ $12 [$94BA] ;| $8094A8 C5 99 CMP $99 [$7E:0099] ;} If buttons are all newly pressed: $8094AA D0 0E BNE $0E [$94BA] ;/ $8094AC C6 A5 DEC $A5 [$7E:00A5] ; Decrement this $8094AE D0 0E BNE $0E [$94BE] ; If this reached 0: $8094B0 A5 8D LDA $8D [$7E:008D] ;\ $8094B2 85 95 STA $95 [$7E:0095] ;} Mirror input $8094B4 A5 89 LDA $89 [$7E:0089] ;\ $8094B6 85 A5 STA $A5 [$7E:00A5] ;} 'this' = (a different) this $8094B8 80 04 BRA $04 [$94BE] ; (Else buttons weren't all newly pressed): $8094BA A5 87 LDA $87 [$7E:0087] ;\ $8094BC 85 A5 STA $A5 [$7E:00A5] ;} 'this' = this $8094BE A5 8D LDA $8D [$7E:008D] ;\ $8094C0 85 99 STA $99 [$7E:0099] ;} Set next frame's previous input $8094C2 AD 17 06 LDA $0617 [$7E:0617] ;\ $8094C5 D0 0D BNE $0D [$94D4] ;} If debug soft resets enabled: $8094C7 A5 8B LDA $8B [$7E:008B] ;\ $8094C9 C9 30 30 CMP #$3030 ;} If input = SsLR (player 1): $8094CC D0 06 BNE $06 [$94D4] ;/ $8094CE 9C F5 05 STZ $05F5 [$7E:05F5] ; Enable sounds $8094D1 4C 62 84 JMP $8462 [$80:8462] ; Jump to soft reset handler $8094D4 AD D1 05 LDA $05D1 [$7E:05D1] ;\ $8094D7 D0 0F BNE $0F [$94E8] ;} If Debug mode no longer set: o_O $8094D9 9C C5 05 STZ $05C5 [$7E:05C5] ;\ $8094DC 9C C7 05 STZ $05C7 [$7E:05C7] ;} Clear mirrors of player 1 newly pressed buttons $8094DF A9 EF FF LDA #$FFEF ;\ $8094E2 14 8D TRB $8D [$7E:008D] ;} Clear all player 2 input except for the button R O_o $8094E4 14 91 TRB $91 [$7E:0091] ;/ $8094E6 28 PLP $8094E7 6B RTL $8094E8 9C C5 05 STZ $05C5 [$7E:05C5] ;\ $8094EB 9C C7 05 STZ $05C7 [$7E:05C7] ;} Clear these mirrors anyway -_- $8094EE 2C CF 05 BIT $05CF [$7E:05CF] ;\ $8094F1 50 03 BVC $03 [$94F6] ;} Return if $05CF bit6 is set $8094F3 4C 81 95 JMP $9581 [$80:9581] ;/ $8094F6 A5 8B LDA $8B [$7E:008B] ;\ $8094F8 29 20 20 AND #$2020 ;| $8094FB C9 20 20 CMP #$2020 ;} If player 1 input has sL: $8094FE D0 09 BNE $09 [$9509] ;/ $809500 A5 8F LDA $8F [$7E:008F] ;\ $809502 8D C5 05 STA $05C5 [$7E:05C5] ;} Mirror player 1 newly pressed buttons $809505 64 8B STZ $8B [$7E:008B] ;\ $809507 64 8F STZ $8F [$7E:008F] ;} Clear player 1 input O_O $809509 A5 8B LDA $8B [$7E:008B] ;\ $80950B 29 10 20 AND #$2010 ;| $80950E C9 10 20 CMP #$2010 ;} If player 1 input has sR: $809511 D0 0C BNE $0C [$951F] ;/ $809513 A5 8F LDA $8F [$7E:008F] ;\ $809515 8D C7 05 STA $05C7 [$7E:05C7] ;} Mirror player 1 newly pressed buttons $809518 A9 F0 E0 LDA #$E0F0 ; -_- $80951B 64 8B STZ $8B [$7E:008B] ;\ $80951D 64 8F STZ $8F [$7E:008F] ;} Clear player 1 input O_O $80951F AD C7 05 LDA $05C7 [$7E:05C7] ;\ $809522 89 80 00 BIT #$0080 ;} If Mirror2 of ^ has A: $809525 F0 07 BEQ $07 [$952E] ;/ $809527 A5 84 LDA $84 [$7E:0084] ;\ $809529 49 30 00 EOR #$0030 ;} Toggle V-Count and H-Count interrupts $80952C 85 84 STA $84 [$7E:0084] ;/ $80952E AD C7 05 LDA $05C7 [$7E:05C7] ;\ $809531 89 00 80 BIT #$8000 ;} Branch for if Mirror2 hasn't B $809534 F0 3A BEQ $3A [$9570] ;/ $809536 AD CF 05 LDA $05CF [$7E:05CF] ;\ $809539 49 00 80 EOR #$8000 ;} Toggle $05CF bit7 (debug artillery swap) $80953C 8D CF 05 STA $05CF [$7E:05CF] ;/ $80953F 10 1D BPL $1D [$955E] ; If now set: $809541 AD C6 09 LDA $09C6 [$7E:09C6] ;\ $809544 8D C9 05 STA $05C9 [$7E:05C9] ;} Mirror Samus' missiles $809547 AD CA 09 LDA $09CA [$7E:09CA] ;\ $80954A 8D CB 05 STA $05CB [$7E:05CB] ;} Mirror Samus' super missiles $80954D AD CE 09 LDA $09CE [$7E:09CE] ;\ $809550 8D CD 05 STA $05CD [$7E:05CD] ;} Mirror Samus' power bombs $809553 9C C6 09 STZ $09C6 [$7E:09C6] ;\ $809556 9C CA 09 STZ $09CA [$7E:09CA] ;} Clear Samus' artillery $809559 9C CE 09 STZ $09CE [$7E:09CE] ;/ $80955C 80 12 BRA $12 [$9570] ; (Else, now clear:) $80955E AD C9 05 LDA $05C9 [$7E:05C9] ;\ $809561 8D C6 09 STA $09C6 [$7E:09C6] ;} Restore Samus' missiles $809564 AD CB 05 LDA $05CB [$7E:05CB] ;\ $809567 8D CA 09 STA $09CA [$7E:09CA] ;} Restore Samus' super missiles $80956A AD CD 05 LDA $05CD [$7E:05CD] ;\ $80956D 8D CE 09 STA $09CE [$7E:09CE] ;} Restore Samus' power bombs $809570 AD C7 05 LDA $05C7 [$7E:05C7] ;\ $809573 89 40 00 BIT #$0040 ;} If Mirror2 has X $809576 F0 09 BEQ $09 [$9581] ;/ $809578 AD CF 05 LDA $05CF [$7E:05CF] ;\ $80957B 49 00 20 EOR #$2000 ;} Toggle bit5 of $05CF $80957E 8D CF 05 STA $05CF [$7E:05CF] ;/ $809581 28 PLP $809582 6B RTL } ;;; NMI ;;; { $809583 C2 30 REP #$30 $809585 5C 89 95 80 JML $809589[$80:9589] ; Execute in bank $80 (FastROM) $809589 8B PHB $80958A 0B PHD $80958B 48 PHA $80958C DA PHX $80958D 5A PHY $80958E 4B PHK $80958F AB PLB $809590 A9 00 00 LDA #$0000 $809593 5B TCD $809594 E2 10 SEP #$10 $809596 AE 10 42 LDX $4210 [$7E:4210] ; Read RDNMI, resetting the NMI request signal $809599 AE B4 05 LDX $05B4 [$7E:05B4] ;\ $80959C F0 64 BEQ $64 [$9602] ;} Branch for while still processing, i.e. lag $80959E 20 3A 93 JSR $933A [$80:933A] ; Update OAM & CGRAM $8095A1 20 76 93 JSR $9376 [$80:9376] ; Samus' graphics -> VRAM $8095A4 20 16 94 JSR $9416 [$80:9416] ; Handle misc. animations (spikes, FX1) $8095A7 20 EE 91 JSR $91EE [$80:91EE] ; Update hardware registers $8095AA A2 00 LDX #$00 $8095AC BD B4 18 LDA $18B4,x[$7E:18B4] ;\ $8095AF F0 09 BEQ $09 [$95BA] ;| $8095B1 BC C0 18 LDY $18C0,x[$7E:18C0] ;| $8095B4 BD D8 18 LDA $18D8,x[$7E:18D8] ;| $8095B7 99 02 43 STA $4302,y[$7E:4322] ;| ;} Handle HDMA queue $8095BA E8 INX ;| $8095BB E8 INX ;| $8095BC E0 0C CPX #$0C ;| $8095BE D0 EC BNE $EC [$95AC] ;/ $8095C0 A6 55 LDX $55 [$7E:0055] ;\ $8095C2 E0 07 CPX #$07 ;| $8095C4 F0 06 BEQ $06 [$95CC] ;| $8095C6 A6 56 LDX $56 [$7E:0056] ;| $8095C8 E0 07 CPX #$07 ;} Handle Mode 7 if enabled $8095CA D0 04 BNE $04 [$95D0] ;| ;| $8095CC 22 BA 8B 80 JSL $808BBA[$80:8BBA] ;/ $8095D0 22 83 8C 80 JSL $808C83[$80:8C83] ; Process $D0,X VRAM writes $8095D4 22 A2 8E 80 JSL $808EA2[$80:8EA2] ; Process $340,X VRAM reads $8095D8 E2 10 SEP #$10 $8095DA C2 20 REP #$20 $8095DC A6 85 LDX $85 [$7E:0085] ;\ $8095DE 8E 0C 42 STX $420C [$7E:420C] ;} Execute HDMA $8095E1 22 59 94 80 JSL $809459[$80:9459] ; Read controller input. Also a debug branch $8095E5 A2 00 LDX #$00 ;\ $8095E7 8E B4 05 STX $05B4 [$7E:05B4] ;} Clear wait-for-NMI flag $8095EA 8E BA 05 STX $05BA [$7E:05BA] ; Clear number of occurred NMI $8095ED AE B5 05 LDX $05B5 [$7E:05B5] ;\ $8095F0 E8 INX ;} Increment 8-bit counter $8095F1 8E B5 05 STX $05B5 [$7E:05B5] ;/ $8095F4 EE B6 05 INC $05B6 [$7E:05B6] ; Increment 16-bit counter $8095F7 C2 30 REP #$30 $8095F9 EE B8 05 INC $05B8 [$7E:05B8] ; ??? H-blank related $8095FC 7A PLY $8095FD FA PLX $8095FE 68 PLA $8095FF 2B PLD $809600 AB PLB $809601 40 RTI $809602 AE BA 05 LDX $05BA [$7E:05BA] ;\ $809605 E8 INX ;} Increment number of occurred NMI (i.e. lag frames) $809606 8E BA 05 STX $05BA [$7E:05BA] ;/ $809609 AE BA 05 LDX $05BA [$7E:05BA] ; Terrible $80960C EC BB 05 CPX $05BB [$7E:05BB] ;\ $80960F 90 E6 BCC $E6 [$95F7] ;| $809611 8E BB 05 STX $05BB [$7E:05BB] ;} Most NMI occurred (i.e. largest lag) $809614 80 E1 BRA $E1 [$95F7] ;/ } ;;; Interrupt commands ;;; { $809616 dw $966E $9680 $968B $96A9 $96D3 $96F1 $971A $9733 $9758 $9771 $97A9 $97C1 $97DA $980A } ;;; DMA transfer to VRAM ;;; { ; VRAM address = 05BE, $4312..$4316 = $05C0..$05C4 ; Used for room tiles, enemy graphics, background/foreground graphics, and status bar(?) $809632 E2 20 SEP #$20 $809634 A9 80 LDA #$80 ;\ $809636 8D 00 21 STA $2100 [$7E:2100] ;} Set force blank, screen off $809639 AE BE 05 LDX $05BE [$7E:05BE] ;\ $80963C 8E 16 21 STX $2116 [$7E:2116] ;| $80963F A2 01 18 LDX #$1801 ;| $809642 8E 10 43 STX $4310 [$7E:4310] ;| $809645 AE C0 05 LDX $05C0 [$7E:05C0] ;| $809648 8E 12 43 STX $4312 [$7E:4312] ;| $80964B AD C2 05 LDA $05C2 [$7E:05C2] ;| $80964E 8D 14 43 STA $4314 [$7E:4314] ;} DMA slot 1, VRAM_UpdateSize bytes from VRAM_UpdateSource to VRAM_Address VRAM $809651 AE C3 05 LDX $05C3 [$7E:05C3] ;| $809654 8E 15 43 STX $4315 [$7E:4315] ;| $809657 A9 80 LDA #$80 ;| $809659 8D 15 21 STA $2115 [$7E:2115] ;| $80965C A9 02 LDA #$02 ;| $80965E 8D 0B 42 STA $420B [$7E:420B] ;/ $809661 A9 80 LDA #$80 ;\ $809663 1C BD 05 TRB $05BD [$7E:05BD] ;} Clear VRAM update flag $809666 A9 0F LDA #$0F ;\ $809668 8D 00 21 STA $2100 [$7E:2100] ;} Clear force blank, max brightness $80966B C2 20 REP #$20 $80966D 60 RTS } ;;; Interrupt command 00h. Next interrupt command = [$A7] ;;; { $80966E A5 A7 LDA $A7 [$7E:00A7] ;\ $809670 F0 04 BEQ $04 [$9676] ;| $809672 64 A7 STZ $A7 [$7E:00A7] ;} If [$A7]: set next interrupt command to, and clear, $A7 $809674 80 03 BRA $03 [$9679] ;} Else: set next interrupt command to 00h ;| $809676 A9 00 00 LDA #$0000 ;/ $809679 A2 00 00 LDX #$0000 $80967C A0 00 00 LDY #$0000 $80967F 60 RTS } ;;; Interrupt command 02h. Disable horizontal and vertical timer interrupts ;;; { $809680 A9 30 00 LDA #$0030 $809683 14 84 TRB $84 [$7E:0084] $809685 A9 00 00 LDA #$0000 $809688 AA TAX $809689 A8 TAY $80968A 60 RTS } ;;; Interrupt command 04h. Main gameplay, status bar drawing ;;; { $80968B E2 20 SEP #$20 $80968D A9 5A LDA #$5A ;\ $80968F 8D 09 21 STA $2109 [$7E:2109] ;} BG3 tilemap = $5800, mirrored to $5C00 $809692 9C 30 21 STZ $2130 [$7E:2130] ;\ $809695 9C 31 21 STZ $2131 [$7E:2131] ;} Disable colour math $809698 A9 04 LDA #$04 ;\ $80969A 8D 2C 21 STA $212C [$7E:212C] ;} Enable only BG3 on main screen $80969D C2 20 REP #$20 $80969F A9 06 00 LDA #$0006 ; Next interrupt command = 06h $8096A2 A0 1F 00 LDY #$001F ;\ $8096A5 A2 98 00 LDX #$0098 ;} Set interrupt to PPU processed status bar $8096A8 60 RTS } ;;; Interrupt command 06h. Main gameplay, status bar drawn ;;; { $8096A9 E2 20 SEP #$20 $8096AB A5 70 LDA $70 [$7E:0070] ;\ $8096AD 8D 30 21 STA $2130 [$7E:2130] ;} Colour math select = [$70] $8096B0 A5 73 LDA $73 [$7E:0073] ;\ $8096B2 8D 31 21 STA $2131 [$7E:2131] ;} Colour math designation = [$73] $8096B5 A5 5B LDA $5B [$7E:005B] ;\ $8096B7 8D 09 21 STA $2109 [$7E:2109] ;} BG3 tilemap VRAM address and mirroring = [$5B] $8096BA A5 6A LDA $6A [$7E:006A] ;\ $8096BC 8D 2C 21 STA $212C [$7E:212C] ;} Main screen designation = [$6A] $8096BF C2 20 REP #$20 $8096C1 A5 A7 LDA $A7 [$7E:00A7] ;\ $8096C3 F0 04 BEQ $04 [$96C9] ;| $8096C5 64 A7 STZ $A7 [$7E:00A7] ;} If [$A7]: set next interrupt command to, and clear, $A7 $8096C7 80 03 BRA $03 [$96CC] ;} Else: set next interrupt command to 04h ;| $8096C9 A9 04 00 LDA #$0004 ;/ $8096CC A0 00 00 LDY #$0000 ;\ $8096CF A2 98 00 LDX #$0098 ;} Set interrupt to PPU process the top line $8096D2 60 RTS } ;;; Interrupt command 08h. Start of room transition, status bar drawing ;;; { $8096D3 E2 20 SEP #$20 $8096D5 A9 5A LDA #$5A ;\ $8096D7 8D 09 21 STA $2109 [$7E:2109] ;} BG3 tilemap = $5800, mirrored to $5C00 $8096DA A9 04 LDA #$04 ;\ $8096DC 8D 2C 21 STA $212C [$7E:212C] ;} Enable only BG3 on main screen $8096DF 9C 30 21 STZ $2130 [$7E:2130] ;\ $8096E2 9C 31 21 STZ $2131 [$7E:2131] ;} Disable colour math $8096E5 C2 20 REP #$20 $8096E7 A9 0A 00 LDA #$000A ; Next interrupt command = 0Ah $8096EA A0 1F 00 LDY #$001F ;\ $8096ED A2 98 00 LDX #$0098 ;} Set interrupt to PPU processed status bar $8096F0 60 RTS } ;;; Interrupt command 0Ah. Start of room transition, status bar drawn ;;; { $8096F1 E2 20 SEP #$20 $8096F3 AD B3 07 LDA $07B3 [$7E:07B3] ;\ $8096F6 0D B1 07 ORA $07B1 [$7E:07B1] ;| $8096F9 89 01 BIT #$01 ;} If current or previous room's graphics bitflag has 01h: $8096FB F0 04 BEQ $04 [$9701] ;/ $8096FD A9 10 LDA #$10 ;\ $8096FF 80 02 BRA $02 [$9703] ;} Enable only objects on the main screen $809701 A9 11 LDA #$11 ; Else: Enable only BG1 and objects on the main screen $809703 8D 2C 21 STA $212C [$7E:212C] $809706 C2 20 REP #$20 $809708 A5 A7 LDA $A7 [$7E:00A7] ;\ $80970A F0 04 BEQ $04 [$9710] ;| $80970C 64 A7 STZ $A7 [$7E:00A7] ;} If [$A7]: set next interrupt command to, and clear, $A7 $80970E 80 03 BRA $03 [$9713] ;} Else: set next interrupt command to 08h ;| $809710 A9 08 00 LDA #$0008 ;/ $809713 A0 00 00 LDY #$0000 ;\ $809716 A2 98 00 LDX #$0098 ;} Set interrupt to PPU process the top line $809719 60 RTS } ;;; Interrupt command 0Ch. Draygon's room, status bar drawing ;;; { $80971A E2 20 SEP #$20 $80971C A9 04 LDA #$04 ;\ $80971E 8D 2C 21 STA $212C [$7E:212C] ;} Enable only BG3 on main screen $809721 9C 30 21 STZ $2130 [$7E:2130] ;\ $809724 9C 31 21 STZ $2131 [$7E:2131] ;} Disable colour math $809727 C2 20 REP #$20 $809729 A9 0E 00 LDA #$000E ; Next interrupt command = 0Eh $80972C A0 1F 00 LDY #$001F ;\ $80972F A2 98 00 LDX #$0098 ;} Set interrupt to PPU processed status bar $809732 60 RTS } ;;; Interrupt command 0Eh. Draygon's room, status bar drawn ;;; { $809733 E2 20 SEP #$20 $809735 A5 5B LDA $5B [$7E:005B] ;\ $809737 8D 09 21 STA $2109 [$7E:2109] ;} BG3 tilemap VRAM address and mirroring = [$5B] $80973A A5 70 LDA $70 [$7E:0070] ;\ $80973C 8D 30 21 STA $2130 [$7E:2130] ;} Colour math select = [$70] $80973F A5 73 LDA $73 [$7E:0073] ;\ $809741 8D 31 21 STA $2131 [$7E:2131] ;} Colour math designation = [$73] $809744 C2 20 REP #$20 $809746 A5 A7 LDA $A7 [$7E:00A7] ;\ $809748 F0 04 BEQ $04 [$974E] ;| $80974A 64 A7 STZ $A7 [$7E:00A7] ;} If [$A7]: set next interrupt command to, and clear, $A7 $80974C 80 03 BRA $03 [$9751] ;} Else: set next interrupt command to 0Ch ;| $80974E A9 0C 00 LDA #$000C ;/ $809751 A0 00 00 LDY #$0000 ;\ $809754 A2 98 00 LDX #$0098 ;} Set interrupt to PPU process the top line $809757 60 RTS } ;;; Interrupt command 10h. Vertical room transition, status bar drawing ;;; { $809758 E2 20 SEP #$20 $80975A A9 04 LDA #$04 ;\ $80975C 8D 2C 21 STA $212C [$7E:212C] ;} Enable only BG3 on main screen $80975F 9C 30 21 STZ $2130 [$7E:2130] ;\ $809762 9C 31 21 STZ $2131 [$7E:2131] ;} Disable colour math $809765 C2 20 REP #$20 $809767 A9 12 00 LDA #$0012 ; Next interrupt command = 12h $80976A A0 1F 00 LDY #$001F ;\ $80976D A2 98 00 LDX #$0098 ;} Set interrupt to PPU processed status bar $809770 60 RTS } ;;; Interrupt command 12h. Vertical room transition, screen drawing ;;; { $809771 E2 20 SEP #$20 $809773 AD B3 07 LDA $07B3 [$7E:07B3] ;\ $809776 0D B1 07 ORA $07B1 [$7E:07B1] ;| $809779 89 01 BIT #$01 ;} If current or previous room's graphics bitflag has 01h: $80977B F0 04 BEQ $04 [$9781] ;/ $80977D A9 10 LDA #$10 ;\ $80977F 80 02 BRA $02 [$9783] ;} Enable only objects on the main screen $809781 A9 11 LDA #$11 ; Else: Enable only BG1 and objects on the main screen $809783 8D 2C 21 STA $212C [$7E:212C] $809786 9C 30 21 STZ $2130 [$7E:2130] ;\ $809789 9C 31 21 STZ $2131 [$7E:2131] ;} Disable colour math $80978C C2 20 REP #$20 $80978E AE BC 05 LDX $05BC [$7E:05BC] ;\ $809791 10 03 BPL $03 [$9796] ;} If VRAM update: $809793 20 32 96 JSR $9632 [$80:9632] ; Update the VRAM $809796 AD 31 09 LDA $0931 [$7E:0931] ;\ $809799 30 04 BMI $04 [$979F] ;} If [$0931] is positive: $80979B 22 4E AE 80 JSL $80AE4E[$80:AE4E] ; Execute this subroutine $80979F A9 14 00 LDA #$0014 ; Next interrupt command = 14h $8097A2 A0 D8 00 LDY #$00D8 ;\ $8097A5 A2 98 00 LDX #$0098 ;} Set interrupt to PPU process the bottom line $8097A8 60 RTS } ;;; Interrupt command 14h. Vertical room transition, screen drawn ;;; { $8097A9 A5 A7 LDA $A7 [$7E:00A7] ;\ $8097AB F0 04 BEQ $04 [$97B1] ;| $8097AD 64 A7 STZ $A7 [$7E:00A7] ;} If [$A7]: set next interrupt command to, and clear, $A7 $8097AF 80 03 BRA $03 [$97B4] ;} Else: set next interrupt command to 10h ;| $8097B1 A9 10 00 LDA #$0010 ;/ $8097B4 A0 00 00 LDY #$0000 ;\ $8097B7 A2 98 00 LDX #$0098 ;} Set interrupt to PPU process the top line $8097BA 9C B4 05 STZ $05B4 [$7E:05B4] ;\ $8097BD EE B4 05 INC $05B4 [$7E:05B4] ;} Set waiting for NMI flag $8097C0 60 RTS } ;;; Interrupt command 16h. Horizontal room transition, status bar drawing ;;; { $8097C1 E2 20 SEP #$20 $8097C3 A9 04 LDA #$04 ;\ $8097C5 8D 2C 21 STA $212C [$7E:212C] ;} Enable only BG3 on main screen $8097C8 9C 30 21 STZ $2130 [$7E:2130] ;\ $8097CB 9C 31 21 STZ $2131 [$7E:2131] ;} Disable colour math $8097CE C2 20 REP #$20 $8097D0 A9 18 00 LDA #$0018 ; Next interrupt command = 18h $8097D3 A0 1F 00 LDY #$001F ;\ $8097D6 A2 98 00 LDX #$0098 ;} Set interrupt to PPU processed status bar $8097D9 60 RTS } ;;; Interrupt command 18h. Horizontal room transition, screen drawing ;;; { $8097DA E2 20 SEP #$20 $8097DC AD B3 07 LDA $07B3 [$7E:07B3] ;\ $8097DF 0D B1 07 ORA $07B1 [$7E:07B1] ;| $8097E2 89 01 BIT #$01 ;} If current or previous room's graphics bitflag has 01h: $8097E4 F0 04 BEQ $04 [$97EA] ;/ $8097E6 A9 10 LDA #$10 ;\ $8097E8 80 02 BRA $02 [$97EC] ;} Enable only objects on the main screen $8097EA A9 11 LDA #$11 ; Else: Enable only BG1 and objects on the main screen $8097EC 8D 2C 21 STA $212C [$7E:212C] $8097EF 9C 30 21 STZ $2130 [$7E:2130] ;\ $8097F2 9C 31 21 STZ $2131 [$7E:2131] ;} Disable colour math $8097F5 C2 20 REP #$20 $8097F7 AD 31 09 LDA $0931 [$7E:0931] ;\ $8097FA 30 04 BMI $04 [$9800] ;} If [$0931] is positive: $8097FC 22 4E AE 80 JSL $80AE4E[$80:AE4E] ; Execute this subroutine $809800 A9 1A 00 LDA #$001A ; Next interrupt command = 1Ah $809803 A0 A0 00 LDY #$00A0 ;\ $809806 A2 98 00 LDX #$0098 ;} Set interrupt to PPU process the bottom line of the door $809809 60 RTS } ;;; Interrupt command 1Ah. Horizontal room transition, screen drawn ;;; { $80980A AE BC 05 LDX $05BC [$7E:05BC] ;\ $80980D 10 03 BPL $03 [$9812] ;} If VRAM update: $80980F 20 32 96 JSR $9632 [$80:9632] ; Update the VRAM $809812 A5 A7 LDA $A7 [$7E:00A7] ;\ $809814 F0 04 BEQ $04 [$981A] ;| $809816 64 A7 STZ $A7 [$7E:00A7] ;} If [$A7]: set next interrupt command to, and clear, $A7 $809818 80 03 BRA $03 [$981D] ;} Else: set next interrupt command to 10h ;| $80981A A9 16 00 LDA #$0016 ;/ $80981D A0 00 00 LDY #$0000 ;\ $809820 A2 98 00 LDX #$0098 ;} Set interrupt to PPU process the top line $809823 9C B4 05 STZ $05B4 [$7E:05B4] ;\ $809826 EE B4 05 INC $05B4 [$7E:05B4] ;} Set waiting for NMI flag $809829 60 RTS } ;;; Enable horizontal and vertical timer interrupts ;;; { $80982A 08 PHP $80982B C2 30 REP #$30 $80982D A9 00 00 LDA #$0000 ;\ $809830 8D 09 42 STA $4209 [$7E:4209] ;| $809833 A9 98 00 LDA #$0098 ;} Set interrupt to PPU process the top line $809836 8D 07 42 STA $4207 [$7E:4207] ;/ $809839 A9 30 00 LDA #$0030 ;\ $80983C 04 84 TSB $84 [$7E:0084] ;} Enable horizontal and vertical interrupts $80983E 28 PLP $80983F 58 CLI $809840 6B RTL } ;;; Enable horizontal and vertical timer interrupts now ;;; { $809841 08 PHP $809842 C2 30 REP #$30 $809844 A9 00 00 LDA #$0000 ;\ $809847 8D 09 42 STA $4209 [$7E:4209] ;| $80984A A9 98 00 LDA #$0098 ;} Set interrupt to PPU process the top line $80984D 8D 07 42 STA $4207 [$7E:4207] ;/ $809850 A9 30 00 LDA #$0030 ;\ $809853 04 84 TSB $84 [$7E:0084] ;| $809855 E2 20 SEP #$20 ;} Enable horizontal and vertical interrupts now $809857 A5 84 LDA $84 [$7E:0084] ;| $809859 8D 00 42 STA $4200 [$7E:4200] ;/ $80985C 28 PLP $80985D 58 CLI $80985E 6B RTL } ;;; Disable horizontal and vertical timer interrupts ;;; { $80985F 08 PHP $809860 C2 30 REP #$30 $809862 A9 30 00 LDA #$0030 $809865 14 84 TRB $84 [$7E:0084] $809867 28 PLP $809868 78 SEI $809869 6B RTL } ;;; IRQ ;;; { $80986A C2 30 REP #$30 $80986C 5C 70 98 80 JML $809870[$80:9870] ; Execute in bank $80 (FastROM) $809870 8B PHB $809871 48 PHA $809872 DA PHX $809873 5A PHY $809874 4B PHK $809875 AB PLB $809876 AD 11 42 LDA $4211 [$7E:4211] ; Read TIMEUP, resetting the IRQ request signal $809879 A6 AB LDX $AB [$7E:00AB] ;\ $80987B FC 16 96 JSR ($9616,x)[$80:966E] ;} Execute interrupt command $80987E 85 AB STA $AB [$7E:00AB] ; Store returned A as the next interrupt command $809880 8C 09 42 STY $4209 [$7E:4209] ; Store returned Y to the vertical timer $809883 8E 07 42 STX $4207 [$7E:4207] ; Store returned X to the horizontal timer $809886 7A PLY $809887 FA PLX $809888 68 PLA $809889 AB PLB $80988A 40 RTI } ;;; HUD tilemap ;;; { ; Top row, never changed $80988B dw 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C1D, 2C1D, 2C1D, 2C1D, 2C1D, 2C1C ; Item selector background $8098CB dw 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C12, 2C12, 2C23, 2C12, 2C12, 2C1E, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2822, 2822, 2823, 2813, 2C14, 2C1E, 2C0F, 2C0B, 2C0C, 2C0D, 2C32, 2C0F, 2C09, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C0F, 2C12, 2C12, A824, 2815, 2C16, 2C1E ; Auto reserve $80998B dw 3C33, 3C46, 3C47, 3C48, BC33, BC46 ; Empty auto reserve $809997 dw 2C33, 2C46, 2C47, 2C48, AC33, AC46 ; Missiles $8099A3 dw 344B, 3449, 744B, 344C, 344A, 744C ; Super missiles $8099AF dw 3434, 7434, 3435, 7435 ; Power bombs $8099B7 dw 3436, 7436, 3437, 7437 ; Grapple $8099BF dw 3438, 7438, 3439, 7439 ; X-ray $8099C7 dw 343A, 743A, 343B, 743B } ;;; Add missiles to HUD WRAM tilemap ;;; { $8099CF 08 PHP $8099D0 8B PHB $8099D1 4B PHK $8099D2 AB PLB $8099D3 C2 30 REP #$30 $8099D5 AF 1C C6 7E LDA $7EC61C[$7E:C61C] ;\ $8099D9 29 FF 03 AND #$03FF ;| $8099DC C9 0F 00 CMP #$000F ;} If no missile tilemap: $8099DF D0 2A BNE $2A [$9A0B] ;/ $8099E1 AD A3 99 LDA $99A3 [$80:99A3] ;\ $8099E4 8F 1C C6 7E STA $7EC61C[$7E:C61C] ;| $8099E8 AD A5 99 LDA $99A5 [$80:99A5] ;| $8099EB 8F 1E C6 7E STA $7EC61E[$7E:C61E] ;} Top row of missile icon $8099EF AD A7 99 LDA $99A7 [$80:99A7] ;| $8099F2 8F 20 C6 7E STA $7EC620[$7E:C620] ;/ $8099F6 AD A9 99 LDA $99A9 [$80:99A9] ;\ $8099F9 8F 5C C6 7E STA $7EC65C[$7E:C65C] ;| $8099FD AD AB 99 LDA $99AB [$80:99AB] ;| $809A00 8F 5E C6 7E STA $7EC65E[$7E:C65E] ;} Bottom row of missile icon $809A04 AD AD 99 LDA $99AD [$80:99AD] ;| $809A07 8F 60 C6 7E STA $7EC660[$7E:C660] ;/ $809A0B AB PLB $809A0C 28 PLP $809A0D 6B RTL } ;;; Add super missiles to HUD WRAM tilemap ;;; { $809A0E 08 PHP $809A0F DA PHX $809A10 5A PHY $809A11 8B PHB $809A12 4B PHK $809A13 AB PLB $809A14 C2 30 REP #$30 $809A16 A0 AF 99 LDY #$99AF $809A19 A2 1C 00 LDX #$001C $809A1C 80 2E BRA $2E [$9A4C] } ;;; Add power bombs to HUD WRAM tilemap ;;; { $809A1E 08 PHP $809A1F DA PHX $809A20 5A PHY $809A21 8B PHB $809A22 4B PHK $809A23 AB PLB $809A24 C2 30 REP #$30 $809A26 A0 B7 99 LDY #$99B7 $809A29 A2 22 00 LDX #$0022 $809A2C 80 1E BRA $1E [$9A4C] } ;;; Add grapple to HUD WRAM tilemap ;;; { $809A2E 08 PHP $809A2F DA PHX $809A30 5A PHY $809A31 8B PHB $809A32 4B PHK $809A33 AB PLB $809A34 C2 30 REP #$30 $809A36 A0 BF 99 LDY #$99BF $809A39 A2 28 00 LDX #$0028 $809A3C 80 0E BRA $0E [$9A4C] } ;;; Add x-ray to HUD WRAM tilemap ;;; { $809A3E 08 PHP $809A3F DA PHX $809A40 5A PHY $809A41 8B PHB $809A42 4B PHK $809A43 AB PLB $809A44 C2 30 REP #$30 $809A46 A0 C7 99 LDY #$99C7 $809A49 A2 2E 00 LDX #$002E } ;;; Add to HUD WRAM tilemap ;;; { ;; Takes parameters: X = dest. offset; Y = source $809A4C BF 08 C6 7E LDA $7EC608,x[$7E:C624] ;\ $809A50 29 FF 03 AND #$03FF ;| $809A53 C9 0F 00 CMP #$000F ;} If the tilemap is blank: $809A56 D0 1C BNE $1C [$9A74] ;/ $809A58 B9 00 00 LDA $0000,y[$80:99AF] ;\ $809A5B 9F 08 C6 7E STA $7EC608,x[$7E:C624] ;| $809A5F B9 02 00 LDA $0002,y[$80:99B1] ;} Write top row $809A62 9F 0A C6 7E STA $7EC60A,x[$7E:C626] ;/ $809A66 B9 04 00 LDA $0004,y[$80:99B3] ;\ $809A69 9F 48 C6 7E STA $7EC648,x[$7E:C664] ;| $809A6D B9 06 00 LDA $0006,y[$80:99B5] ;} Write bottom row $809A70 9F 4A C6 7E STA $7EC64A,x[$7E:C666] ;/ $809A74 AB PLB $809A75 7A PLY $809A76 FA PLX $809A77 28 PLP $809A78 6B RTL } ;;; HUD routine when game is loading ;;; { $809A79 08 PHP $809A7A 8B PHB $809A7B 4B PHK $809A7C AB PLB $809A7D C2 30 REP #$30 $809A7F A9 00 58 LDA #$5800 ;\ $809A82 8D 16 21 STA $2116 [$7E:2116] ;| $809A85 A9 80 00 LDA #$0080 ;| $809A88 8D 15 21 STA $2115 [$7E:2115] ;| $809A8B 22 A9 91 80 JSL $8091A9[$80:91A9] ;} HUD top row tilemap -> VRAM $809A8F dx 01, 01, 18, 80988B, 0040;| $809A97 E2 20 SEP #$20 ;| $809A99 A9 02 LDA #$02 ;| $809A9B 8D 0B 42 STA $420B [$7E:420B] ;/ $809A9E C2 20 REP #$20 $809AA0 A2 00 00 LDX #$0000 $809AA3 BD CB 98 LDA $98CB,x[$80:98CB] ;\ $809AA6 9F 08 C6 7E STA $7EC608,x[$7E:C608] ;| $809AAA E8 INX ;| $809AAB E8 INX ;} HUD item selector background -> $7E:C608..C6C7 $809AAC E0 C0 00 CPX #$00C0 ;| $809AAF D0 F2 BNE $F2 [$9AA3] ;/ $809AB1 AD A2 09 LDA $09A2 [$7E:09A2] ;\ $809AB4 89 00 80 BIT #$8000 ;} If X-ray equipped: $809AB7 F0 04 BEQ $04 [$9ABD] ;/ $809AB9 22 3E 9A 80 JSL $809A3E ; Add to WRAM tilemap $809ABD AD A2 09 LDA $09A2 [$7E:09A2] ;\ $809AC0 89 00 40 BIT #$4000 ;} If Grapple equipped: $809AC3 F0 04 BEQ $04 [$9AC9] ;/ $809AC5 22 2E 9A 80 JSL $809A2E ; Add to WRAM tilemap $809AC9 AD C8 09 LDA $09C8 [$7E:09C8] ;\ $809ACC F0 04 BEQ $04 [$9AD2] ;} If Samus has missiles: $809ACE 22 CF 99 80 JSL $8099CF ; Add to WRAM tilemap $809AD2 AD CC 09 LDA $09CC [$7E:09CC] ;\ $809AD5 F0 04 BEQ $04 [$9ADB] ;} If Samus has super missiles: $809AD7 22 0E 9A 80 JSL $809A0E ; Add to WRAM tilemap $809ADB AD D0 09 LDA $09D0 [$7E:09D0] ;\ $809ADE F0 04 BEQ $04 [$9AE4] ;} If Samus has power bombs: $809AE0 22 1E 9A 80 JSL $809A1E ; Add to WRAM tilemap $809AE4 9C 06 0A STZ $0A06 [$7E:0A06] ;\ $809AE7 9C 08 0A STZ $0A08 [$7E:0A08] ;| $809AEA 9C 0A 0A STZ $0A0A [$7E:0A0A] ;} Clear health/artillery mirrors $809AED 9C 0C 0A STZ $0A0C [$7E:0A0C] ;| $809AF0 9C 0E 0A STZ $0A0E [$7E:0A0E] ;/ $809AF3 22 EF A8 90 JSL $90A8EF[$90:A8EF] ; Update mini-map $809AF7 A9 D3 9D LDA #$9DD3 ;\ $809AFA 85 00 STA $00 [$7E:0000] ;| $809AFC A9 80 00 LDA #$0080 ;} $00..$02 = pointer to digit tiles $809AFF 85 02 STA $02 [$7E:0002] ;/ $809B01 AD C8 09 LDA $09C8 [$7E:09C8] ;\ $809B04 F0 09 BEQ $09 [$9B0F] ;} If Samus has missiles: $809B06 AD C6 09 LDA $09C6 [$7E:09C6] ;\ $809B09 A2 94 00 LDX #$0094 ;} Draw missile count $809B0C 20 78 9D JSR $9D78 [$80:9D78] ;/ $809B0F AD CC 09 LDA $09CC [$7E:09CC] ;\ $809B12 F0 09 BEQ $09 [$9B1D] ;} If Samus has super missiles: $809B14 A2 9C 00 LDX #$009C ;\ $809B17 AD CA 09 LDA $09CA [$7E:09CA] ;} Draw super missile count $809B1A 20 98 9D JSR $9D98 [$80:9D98] ;/ $809B1D AD D0 09 LDA $09D0 [$7E:09D0] ;\ $809B20 F0 09 BEQ $09 [$9B2B] ;} If Samus has power bombs: $809B22 AD CE 09 LDA $09CE [$7E:09CE] ;\ $809B25 A2 A2 00 LDX #$00A2 ;} Draw power bomb count $809B28 20 98 9D JSR $9D98 [$80:9D98] ;/ $809B2B AD D2 09 LDA $09D2 [$7E:09D2] ;\ $809B2E A2 00 10 LDX #$1000 ;} Highlight selected HUD item $809B31 20 EA 9C JSR $9CEA [$80:9CEA] ;/ $809B34 AD 0E 0A LDA $0A0E [$7E:0A0E] ;\ $809B37 A2 00 14 LDX #$1400 ;} Unhighlight selected HUD item mirror $809B3A 20 EA 9C JSR $9CEA [$80:9CEA] ;/ $809B3D 22 44 9B 80 JSL $809B44[$80:9B44] ; Following (PLB PLP with no jump would have been better) $809B41 AB PLB $809B42 28 PLP $809B43 6B RTL } ;;; HUD routine when game is paused/running ;;; { ; Status bar routine. Handles reserve tanks, energy tanks, health, missiles, super missiles (skips 3-digit SM code), power bombs, changing items, and finally auto-unselected flashing. Then puts in an entry in the $D0 graphic table to update itself $809B44 08 PHP $809B45 8B PHB $809B46 4B PHK $809B47 AB PLB $809B48 E2 20 SEP #$20 $809B4A 64 02 STZ $02 [$7E:0002] $809B4C C2 30 REP #$30 $809B4E AD C0 09 LDA $09C0 [$7E:09C0] ;\ $809B51 C9 01 00 CMP #$0001 ;} If auto reserve tanks: $809B54 D0 35 BNE $35 [$9B8B] ;/ $809B56 A0 8B 99 LDY #$998B ; Load (yellow) auto reserve $809B59 AD D6 09 LDA $09D6 [$7E:09D6] ;\ $809B5C D0 03 BNE $03 [$9B61] ;} If zero auto reserve: $809B5E A0 97 99 LDY #$9997 ; Load (blue) empty auto reserve $809B61 B9 00 00 LDA $0000,y[$80:9997] ;\ $809B64 8F 18 C6 7E STA $7EC618[$7E:C618] ;| $809B68 B9 02 00 LDA $0002,y[$80:9999] ;| $809B6B 8F 1A C6 7E STA $7EC61A[$7E:C61A] ;| $809B6F B9 04 00 LDA $0004,y[$80:999B] ;| $809B72 8F 58 C6 7E STA $7EC658[$7E:C658] ;| $809B76 B9 06 00 LDA $0006,y[$80:999D] ;} Add auto reserve to HUD WRAM tilemap $809B79 8F 5A C6 7E STA $7EC65A[$7E:C65A] ;| $809B7D B9 08 00 LDA $0008,y[$80:999F] ;| $809B80 8F 98 C6 7E STA $7EC698[$7E:C698] ;| $809B84 B9 0A 00 LDA $000A,y[$80:99A1] ;| $809B87 8F 9A C6 7E STA $7EC69A[$7E:C69A] ;/ ; Handle Samus' health $809B8B AD C2 09 LDA $09C2 [$7E:09C2] ;\ $809B8E CD 06 0A CMP $0A06 [$7E:0A06] ;} If Samus' health hasn't changed: branch to $9BFB $809B91 F0 68 BEQ $68 [$9BFB] ;/ $809B93 8D 06 0A STA $0A06 [$7E:0A06] ; Update Samus' health mirror $809B96 AD C2 09 LDA $09C2 [$7E:09C2] ;\ $809B99 8D 04 42 STA $4204 [$7E:4204] ;| $809B9C E2 20 SEP #$20 ;| $809B9E A9 64 LDA #$64 ;| $809BA0 8D 06 42 STA $4206 [$7E:4206] ;| $809BA3 48 PHA ;| $809BA4 68 PLA ;} $14 = number of E-tanks $809BA5 48 PHA ;} $12 = non-E-tank energy $809BA6 68 PLA ;| $809BA7 C2 20 REP #$20 ;| $809BA9 AD 14 42 LDA $4214 [$7E:4214] ;| $809BAC 85 14 STA $14 [$7E:0014] ;| $809BAE AD 16 42 LDA $4216 [$7E:4216] ;| $809BB1 85 12 STA $12 [$7E:0012] ;/ $809BB3 AD C4 09 LDA $09C4 [$7E:09C4] ;\ $809BB6 8D 04 42 STA $4204 [$7E:4204] ;| $809BB9 E2 20 SEP #$20 ;| $809BBB A9 64 LDA #$64 ;| $809BBD 8D 06 42 STA $4206 [$7E:4206] ;| $809BC0 48 PHA ;| $809BC1 68 PLA ;| $809BC2 48 PHA ;} $16 = max E-tanks (+ 1) $809BC3 68 PLA ;| $809BC4 C2 30 REP #$30 ;| $809BC6 A0 00 00 LDY #$0000 ;| $809BC9 AD 14 42 LDA $4214 [$7E:4214] ;| $809BCC 1A INC A ;| $809BCD 85 16 STA $16 [$7E:0016] ;/ $809BCF C6 16 DEC $16 [$7E:0016] ;\ $809BD1 F0 1B BEQ $1B [$9BEE] ;} For each energy tank: $809BD3 A2 30 34 LDX #$3430 ;\ $809BD6 A5 14 LDA $14 [$7E:0014] ;| $809BD8 F0 05 BEQ $05 [$9BDF] ;} Determine if full or empty $809BDA C6 14 DEC $14 [$7E:0014] ;| $809BDC A2 31 28 LDX #$2831 ;/ $809BDF 8A TXA ;\ $809BE0 BE CE 9C LDX $9CCE,y[$80:9CCE] ;| $809BE3 9F 08 C6 7E STA $7EC608,x[$7E:C64A] ;| $809BE7 C8 INY ;} Add to WRAM tilemap $809BE8 C8 INY ;| $809BE9 C0 1C 00 CPY #$001C ;| $809BEC 30 E1 BMI $E1 [$9BCF] ;/ $809BEE A9 BF 9D LDA #$9DBF ;\ $809BF1 85 00 STA $00 [$7E:0000] ;} $00..$02 = pointer to other (identical) digit tiles $809BF3 A2 8C 00 LDX #$008C ;\ $809BF6 A5 12 LDA $12 [$7E:0012] ;} Draw non-E-tank energy count $809BF8 20 98 9D JSR $9D98 [$80:9D98] ;/ ; Handle Samus' missiles $809BFB A9 D3 9D LDA #$9DD3 ;\ $809BFE 85 00 STA $00 [$7E:0000] ;} $00..$02, 'swapping' digit tiles again $809C00 AD C8 09 LDA $09C8 [$7E:09C8] ;\ $809C03 F0 11 BEQ $11 [$9C16] ;| $809C05 AD C6 09 LDA $09C6 [$7E:09C6] ;} If Samus' missiles have changed: $809C08 CD 08 0A CMP $0A08 [$7E:0A08] ;| $809C0B F0 09 BEQ $09 [$9C16] ;/ $809C0D 8D 08 0A STA $0A08 [$7E:0A08] ; Update the mirror $809C10 A2 94 00 LDX #$0094 ;\ $809C13 20 78 9D JSR $9D78 [$80:9D78] ;} Draw missile count ; Handle Samus' super missiles $809C16 AD CC 09 LDA $09CC [$7E:09CC] ;\ $809C19 F0 24 BEQ $24 [$9C3F] ;| $809C1B AD CA 09 LDA $09CA [$7E:09CA] ;} If Samus' super missiles haven't changed: branch to $9C3F $809C1E CD 0A 0A CMP $0A0A [$7E:0A0A] ;| $809C21 F0 1C BEQ $1C [$9C3F] ;/ $809C23 8D 0A 0A STA $0A0A [$7E:0A0A] ; Update the mirror $809C26 A2 9C 00 LDX #$009C $809C29 AD CF 05 LDA $05CF [$7E:05CF] ;\ $809C2C 89 40 1F BIT #$1F40 ;} If [$05CF] hasn't 1F40h: $809C2F D0 08 BNE $08 [$9C39] ;/ $809C31 AD 0A 0A LDA $0A0A [$7E:0A0A] ;\ $809C34 20 98 9D JSR $9D98 [$80:9D98] ;} Draw super missile count $809C37 80 06 BRA $06 [$9C3F] $809C39 AD 0A 0A LDA $0A0A [$7E:0A0A] ;\ Else: $809C3C 20 78 9D JSR $9D78 [$80:9D78] ;} Draw super missile count (three-digit) ; Handle Samus' power bombs $809C3F AD D0 09 LDA $09D0 [$7E:09D0] ;\ $809C42 F0 11 BEQ $11 [$9C55] ;| $809C44 AD CE 09 LDA $09CE [$7E:09CE] ;} If Samus' power bombs have changed: $809C47 CD 0C 0A CMP $0A0C [$7E:0A0C] ;| $809C4A F0 09 BEQ $09 [$9C55] ;/ $809C4C 8D 0C 0A STA $0A0C [$7E:0A0C] ; Update the mirror $809C4F A2 A2 00 LDX #$00A2 ;\ $809C52 20 98 9D JSR $9D98 [$80:9D98] ;} Draw power bomb count ; Handle highlighter, can play grapple sound $809C55 AD D2 09 LDA $09D2 [$7E:09D2] ;\ $809C58 CD 0E 0A CMP $0A0E [$7E:0A0E] ;} If selected new HUD icon: $809C5B F0 39 BEQ $39 [$9C96] ;/ $809C5D A2 00 10 LDX #$1000 ;\ $809C60 20 EA 9C JSR $9CEA [$80:9CEA] ;} Highlight old item $809C63 AD 0E 0A LDA $0A0E [$7E:0A0E] ;\ $809C66 A2 00 14 LDX #$1400 ;} Unhighlight new item $809C69 20 EA 9C JSR $9CEA [$80:9CEA] ;/ $809C6C AD D2 09 LDA $09D2 [$7E:09D2] ;\ $809C6F 8D 0E 0A STA $0A0E [$7E:0A0E] ;} Update mirror $809C72 AD 1F 0A LDA $0A1F [$7E:0A1F] ;\ $809C75 29 FF 00 AND #$00FF ;| $809C78 C9 03 00 CMP #$0003 ;| $809C7B F0 19 BEQ $19 [$9C96] ;| $809C7D C9 14 00 CMP #$0014 ;| $809C80 F0 14 BEQ $14 [$9C96] ;} If Samus is not spin jumping, nor wall jumping, has started grapple beam, and time frozen: $809C82 AD 32 0D LDA $0D32 [$7E:0D32] ;| $809C85 C9 F0 C4 CMP #$C4F0 ;| $809C88 D0 0C BNE $0C [$9C96] ;| $809C8A AD 78 0A LDA $0A78 [$7E:0A78] ;| $809C8D D0 07 BNE $07 [$9C96] ;/ $809C8F A9 39 00 LDA #$0039 ;\ $809C92 22 49 90 80 JSL $809049[$80:9049] ;} Play sound library 1, $0653 = 06h, sound 39h ; Handle highlighter flash $809C96 A2 00 14 LDX #$1400 $809C99 AD B5 05 LDA $05B5 [$7E:05B5] ;\ $809C9C 89 10 00 BIT #$0010 ;} If auto-cancel animation timer has 0010h: $809C9F F0 03 BEQ $03 [$9CA4] ;/ $809CA1 A2 00 10 LDX #$1000 $809CA4 AD 04 0A LDA $0A04 [$7E:0A04] ;\ $809CA7 20 EA 9C JSR $9CEA [$80:9CEA] ;} Toggle highlight on item selected $809CAA AE 30 03 LDX $0330 [$7E:0330] ;\ $809CAD A9 C0 00 LDA #$00C0 ;| $809CB0 95 D0 STA $D0,x [$7E:00D0] ;| $809CB2 E8 INX ;| $809CB3 E8 INX ;| $809CB4 A9 08 C6 LDA #$C608 ;| $809CB7 95 D0 STA $D0,x [$7E:00D2] ;| $809CB9 E8 INX ;| $809CBA E8 INX ;} Add HUD to graphics update table $809CBB A9 7E 00 LDA #$007E ;| $809CBE 95 D0 STA $D0,x [$7E:00D4] ;| $809CC0 E8 INX ;| $809CC1 A9 20 58 LDA #$5820 ;| $809CC4 95 D0 STA $D0,x [$7E:00D5] ;| $809CC6 E8 INX ;| $809CC7 E8 INX ;| $809CC8 8E 30 03 STX $0330 [$7E:0330] ;/ $809CCB AB PLB $809CCC 28 PLP $809CCD 6B RTL } ;;; Energy tank icon WRAM tilemap offsets ;;; { $809CCE dw 0042, 0044, 0046, 0048, 004A, 004C, 004E ; Bottom (first) row $809CDC dw 0002, 0004, 0006, 0008, 000A, 000C, 000E ; Top (second) row } ;;; Toggle HUD item highlight ;;; { ;; Takes parameters: A = HUD item; X = palette ; X is either 1000h (palette 4) or 1400h (palette 5) $809CEA 8E 7C 07 STX $077C [$7E:077C] ; Store X parameter to status bar palette value $809CED 3A DEC A ;\ $809CEE 30 7D BMI $7D [$9D6D] ;} If beam: return $809CF0 0A ASL A ;\ $809CF1 A8 TAY ;} Item's WRAM tilemap offset $809CF2 BE 6E 9D LDX $9D6E,y[$80:9D6E] ;/ $809CF5 BF 08 C6 7E LDA $7EC608,x[$7E:C61C] ;\ $809CF9 C9 0F 2C CMP #$2C0F ;} If top-left icon tile: $809CFC F0 0A BEQ $0A [$9D08] ;/ $809CFE 29 FF E3 AND #$E3FF ;\ $809D01 0D 7C 07 ORA $077C [$7E:077C] ;} Change its palette to X-parameter $809D04 9F 08 C6 7E STA $7EC608,x[$7E:C61C] ;/ $809D08 BF 0A C6 7E LDA $7EC60A,x[$7E:C61E] ;\ $809D0C C9 0F 2C CMP #$2C0F ;} If top-right/middle icon tile: $809D0F F0 0A BEQ $0A [$9D1B] ;/ $809D11 29 FF E3 AND #$E3FF ;\ $809D14 0D 7C 07 ORA $077C [$7E:077C] ;} Change its palette to X-parameter $809D17 9F 0A C6 7E STA $7EC60A,x[$7E:C61E] ;/ $809D1B BF 48 C6 7E LDA $7EC648,x[$7E:C65C] ;\ $809D1F C9 0F 2C CMP #$2C0F ;} If bottom-left icon tile: $809D22 F0 0A BEQ $0A [$9D2E] ;/ $809D24 29 FF E3 AND #$E3FF ;\ $809D27 0D 7C 07 ORA $077C [$7E:077C] ;} Change its palette to X-parameter $809D2A 9F 48 C6 7E STA $7EC648,x[$7E:C65C] ;/ $809D2E BF 4A C6 7E LDA $7EC64A,x[$7E:C65E] ;\ $809D32 C9 0F 2C CMP #$2C0F ;} If bottom-right/middle icon tile: $809D35 F0 0A BEQ $0A [$9D41] ;/ $809D37 29 FF E3 AND #$E3FF ;\ $809D3A 0D 7C 07 ORA $077C [$7E:077C] ;} Change its palette to X-parameter $809D3D 9F 4A C6 7E STA $7EC64A,x[$7E:C65E] ;/ $809D41 C0 00 00 CPY #$0000 ;\ $809D44 F0 01 BEQ $01 [$9D47] ;} If not missiles: return $809D46 60 RTS ;/ $809D47 BF 0C C6 7E LDA $7EC60C,x[$7E:C620] ;\ $809D4B C9 0F 2C CMP #$2C0F ;} If top-right icon tile: $809D4E F0 0A BEQ $0A [$9D5A] ;/ $809D50 29 FF E3 AND #$E3FF ;\ $809D53 0D 7C 07 ORA $077C [$7E:077C] ;} Change its palette to X-parameter $809D56 9F 0C C6 7E STA $7EC60C,x[$7E:C620] ;/ $809D5A BF 4C C6 7E LDA $7EC64C,x[$7E:C660] ;\ $809D5E C9 0F 2C CMP #$2C0F ;} If bottom-right icon tile: $809D61 F0 0A BEQ $0A [$9D6D] ;/ $809D63 29 FF E3 AND #$E3FF ;\ $809D66 0D 7C 07 ORA $077C [$7E:077C] ;} Change its palette to X-parameter $809D69 9F 4C C6 7E STA $7EC64C,x[$7E:C660] ;/ $809D6D 60 RTS } ;;; Item WRAM tilemap offsets ;;; { $809D6E dw 0014, 001C, 0022, 0028, 002E } ;;; Draw three HUD digits ;;; { ;; Takes parameters: A = number to draw; X = WRAM tilemap offset; $00..02 = Address of digit tilemap values $809D78 8D 04 42 STA $4204 [$7E:4204] ;\ $809D7B E2 20 SEP #$20 ;| $809D7D A9 64 LDA #$64 ;| $809D7F 8D 06 42 STA $4206 [$7E:4206] ;| $809D82 48 PHA ;| $809D83 68 PLA ;| $809D84 48 PHA ;| $809D85 68 PLA ;} Draw hundreds digit: floor(A/100) $809D86 C2 20 REP #$20 ;| $809D88 AD 14 42 LDA $4214 [$7E:4214] ;| $809D8B 0A ASL A ;| $809D8C A8 TAY ;| $809D8D B7 00 LDA [$00],y[$00:9DD3] ;| $809D8F 9F 08 C6 7E STA $7EC608,x[$7E:C69C] ;/ $809D93 E8 INX ;\ $809D94 E8 INX ;} Next digit WRAM tilemap offset $809D95 AD 16 42 LDA $4216 [$7E:4216] ; Number to draw: A % 100 } ;;; Draw two HUD digits ;;; { ;; Takes parameters: A = number to draw; X = WRAM tilemap offset; $00..02 = Address of digit tilemap values $809D98 8D 04 42 STA $4204 [$7E:4204] ;\ $809D9B E2 20 SEP #$20 ;| $809D9D A9 0A LDA #$0A ;| $809D9F 8D 06 42 STA $4206 [$7E:4206] ;| $809DA2 48 PHA ;| $809DA3 68 PLA ;| $809DA4 48 PHA ;| $809DA5 68 PLA ;} Draw tens digit: floor(A/10) $809DA6 C2 20 REP #$20 ;| $809DA8 AD 14 42 LDA $4214 [$7E:4214] ;| $809DAB 0A ASL A ;| $809DAC A8 TAY ;| $809DAD B7 00 LDA [$00],y[$00:9DD1] ;| $809DAF 9F 08 C6 7E STA $7EC608,x[$7E:C694] ;/ $809DB3 AD 16 42 LDA $4216 [$7E:4216] ;\ $809DB6 0A ASL A ;| $809DB7 A8 TAY ;} Draw units digit: A % 10 $809DB8 B7 00 LDA [$00],y[$00:9DD1] ;| $809DBA 9F 0A C6 7E STA $7EC60A,x[$7E:C696] ;/ $809DBE 60 RTS } ;;; HUD digits tilemap values ;;; { ; Health $809DBF dw 2C09, 2C00, 2C01, 2C02, 2C03, 2C04, 2C05, 2C06, 2C07, 2C08 ; Artillery $809DD3 dw 2C09, 2C00, 2C01, 2C02, 2C03, 2C04, 2C05, 2C06, 2C07, 2C08 } ;;; Process timer ;;; { $809DE7 8B PHB $809DE8 4B PHK $809DE9 AB PLB $809DEA DA PHX $809DEB 5A PHY $809DEC AD 43 09 LDA $0943 [$7E:0943] $809DEF 29 FF 00 AND #$00FF $809DF2 0A ASL A $809DF3 AA TAX $809DF4 FC FB 9D JSR ($9DFB,x)[$80:9E1A] $809DF7 7A PLY $809DF8 FA PLX $809DF9 AB PLB $809DFA 6B RTL } ;;; Pointers to timer code ;;; { $809DFB dw 9E1A, 9E09, 9E1C, 9E2F, 9E41, 9E58, 9E89 } ;;; Ceres start timer ;;; { $809E09 22 93 9E 80 JSL $809E93[$80:9E93] ; Clear timer RAM $809E0D A9 00 01 LDA #$0100 ;\ $809E10 22 8C 9E 80 JSL $809E8C[$80:9E8C] ;} Set timer to 1 minute 0 seconds $809E14 A9 03 80 LDA #$8003 ;\ $809E17 8D 43 09 STA $0943 [$7E:0943] ;} Set timer to delay } ;;; Inactive timer ;;; { $809E1A 18 CLC $809E1B 60 RTS } ;;; Mother Brain start timer ;;; { $809E1C 22 93 9E 80 JSL $809E93[$80:9E93] ; Clear timer RAM $809E20 A9 00 03 LDA #$0300 ;\ $809E23 22 8C 9E 80 JSL $809E8C[$80:9E8C] ;} Set timer to 3 minutes 0 seconds $809E27 A9 03 80 LDA #$8003 ;\ $809E2A 8D 43 09 STA $0943 [$7E:0943] ;} Set timer to delay $809E2D 18 CLC $809E2E 60 RTS } ;;; Delay timer running/movement ;;; { $809E2F E2 20 SEP #$20 $809E31 EE 48 09 INC $0948 [$7E:0948] ; Increment mode timer $809E34 AD 48 09 LDA $0948 [$7E:0948] ;\ $809E37 C9 10 CMP #$10 ;} When mode timer reaches 16: $809E39 90 03 BCC $03 [$9E3E] ;/ $809E3B EE 43 09 INC $0943 [$7E:0943] ; Set timer to run $809E3E C2 21 REP #$21 $809E40 60 RTS } ;;; Run timer, delay movement ;;; { $809E41 E2 20 SEP #$20 $809E43 EE 48 09 INC $0948 [$7E:0948] ; Increment mode timer $809E46 AD 48 09 LDA $0948 [$7E:0948] ;\ $809E49 C9 60 CMP #$60 ;} When mode timer then reaches 96: $809E4B 90 06 BCC $06 [$9E53] ;/ $809E4D 9C 48 09 STZ $0948 [$7E:0948] ; Clear mode timer $809E50 EE 43 09 INC $0943 [$7E:0943] ; Set timer to move $809E53 C2 20 REP #$20 $809E55 4C A9 9E JMP $9EA9 [$80:9EA9] ; Continue at still running } ;;; Move timer, still running ;;; { $809E58 A0 00 00 LDY #$0000 $809E5B A9 E0 00 LDA #$00E0 ;\ $809E5E 18 CLC ;| $809E5F 6D 48 09 ADC $0948 [$7E:0948] ;} When timer X position + 00.E0h reaches DCh $809E62 C9 00 DC CMP #$DC00 ;| $809E65 90 04 BCC $04 [$9E6B] ;/ $809E67 C8 INY ; In place horizontally $809E68 A9 00 DC LDA #$DC00 ; Keep it there $809E6B 8D 48 09 STA $0948 [$7E:0948] ; Store new X position $809E6E A9 3F FF LDA #$FF3F ;\ $809E71 18 CLC ;| $809E72 6D 4A 09 ADC $094A [$7E:094A] ;} When timer Y position - 0.00C0h reaches 30h $809E75 C9 00 30 CMP #$3000 ;| $809E78 B0 04 BCS $04 [$9E7E] ;/ $809E7A C8 INY ; In place vertically $809E7B A9 00 30 LDA #$3000 ; Keep it there $809E7E 8D 4A 09 STA $094A [$7E:094A] ; Store new Y position $809E81 C0 02 00 CPY #$0002 ;\ $809E84 D0 03 BNE $03 [$9E89] ;} If in place: $809E86 EE 43 09 INC $0943 [$7E:0943] ; Set timer to nothing but run $809E89 4C A9 9E JMP $9EA9 [$80:9EA9] } ;;; Set timer to A_high minutes and A_low seconds ;;; { $809E8C 9C 45 09 STZ $0945 [$7E:0945] $809E8F 8D 46 09 STA $0946 [$7E:0946] $809E92 6B RTL } ;;; Clear timer RAM ;;; { $809E93 A9 00 80 LDA #$8000 ;\ $809E96 8D 48 09 STA $0948 [$7E:0948] ;| $809E99 A9 00 80 LDA #$8000 ;} Set timer to off-screen and clear mode timer $809E9C 8D 4A 09 STA $094A [$7E:094A] ;/ $809E9F 9C 45 09 STZ $0945 [$7E:0945] ;\ $809EA2 9C 46 09 STZ $0946 [$7E:0946] ;} Set timer to 0 $809EA5 9C 43 09 STZ $0943 [$7E:0943] ; Set timer to inactive $809EA8 6B RTL } ;;; Finally, stop timer movement, still running ;;; { ;; Returns carry: set if timer's zero, clear otherwise $809EA9 E2 39 SEP #$39 ; Set carry and decimal $809EAB AD B6 05 LDA $05B6 [$7E:05B6] ;\ $809EAE 29 7F AND #$7F ;| $809EB0 AA TAX ;| $809EB1 AD 45 09 LDA $0945 [$7E:0945] ;} Decrement centiseconds for current frame $809EB4 FD EC 9E SBC $9EEC,x[$80:9F42] ;| $809EB7 8D 45 09 STA $0945 [$7E:0945] ;/ $809EBA B0 24 BCS $24 [$9EE0] ; If centiseconds < 0: $809EBC AD 46 09 LDA $0946 [$7E:0946] ;\ $809EBF E9 00 SBC #$00 ;} Decrement seconds $809EC1 8D 46 09 STA $0946 [$7E:0946] ;/ $809EC4 B0 1A BCS $1A [$9EE0] ; And if seconds < 0: $809EC6 AD 47 09 LDA $0947 [$7E:0947] ;\ $809EC9 E9 00 SBC #$00 ;} Decrement minutes $809ECB 8D 47 09 STA $0947 [$7E:0947] ;/ $809ECE 90 07 BCC $07 [$9ED7] ; If minutes >= 0: $809ED0 A9 59 LDA #$59 ;\ $809ED2 8D 46 09 STA $0946 [$7E:0946] ;} Seconds = 59 $809ED5 80 09 BRA $09 [$9EE0] $809ED7 9C 45 09 STZ $0945 [$7E:0945] ;\ Else (minutes < 0): $809EDA 9C 46 09 STZ $0946 [$7E:0946] ;} Clear timer $809EDD 9C 47 09 STZ $0947 [$7E:0947] ;/ $809EE0 C2 39 REP #$39 ; Clear carry and decimal $809EE2 AD 45 09 LDA $0945 [$7E:0945] ;\ $809EE5 0D 46 09 ORA $0946 [$7E:0946] ;} If no centiseconds, seconds, nor minutes: $809EE8 D0 01 BNE $01 [$9EEB] ;/ $809EEA 38 SEC ; Set carry $809EEB 60 RTS ; Timer centisecond decrements (43 01's and 85 02's) $809EEC db 01, 02, 02, 01, 02, 02, 01, 02, 02, 01, 02, 02, 02, 01, 02, 02, 01, 02, 02, 01, 02, 02, 01, 02, 01, 02, 02, 01, 02, 02, 01, 02 $809F0C db 01, 02, 02, 01, 02, 02, 01, 02, 02, 01, 02, 02, 02, 01, 02, 02, 01, 02, 02, 01, 02, 02, 01, 02, 01, 02, 02, 01, 02, 02, 01, 02 $809F2C db 01, 02, 02, 01, 02, 02, 01, 02, 02, 01, 02, 02, 02, 01, 02, 02, 01, 02, 02, 01, 02, 02, 01, 02, 01, 02, 02, 01, 02, 02, 01, 02 $809F4C db 01, 02, 02, 01, 02, 02, 01, 02, 02, 01, 02, 02, 02, 01, 02, 02, 01, 02, 02, 01, 02, 02, 01, 02, 02, 01, 02, 02, 02, 01, 02, 02 } ;;; Draw timer ;;; { $809F6C 8B PHB $809F6D 4B PHK $809F6E AB PLB $809F6F A0 60 A0 LDY #$A060 ;\ $809F72 A9 00 00 LDA #$0000 ;} Draw TIME $809F75 20 B3 9F JSR $9FB3 [$80:9FB3] ;/ $809F78 AD 47 09 LDA $0947 [$7E:0947] ;\ $809F7B A2 E4 FF LDX #$FFE4 ;} Draw minutes $809F7E 20 95 9F JSR $9F95 [$80:9F95] ;/ $809F81 AD 46 09 LDA $0946 [$7E:0946] ;\ $809F84 A2 FC FF LDX #$FFFC ;} Draw seconds $809F87 20 95 9F JSR $9F95 [$80:9F95] ;/ $809F8A AD 45 09 LDA $0945 [$7E:0945] ;\ $809F8D A2 14 00 LDX #$0014 ;} Draw centiseconds $809F90 20 95 9F JSR $9F95 [$80:9F95] ;/ $809F93 AB PLB $809F94 6B RTL } ;;; Draw timer section ;;; { ;; Takes parameters: A = timer value; X = position offset $809F95 DA PHX $809F96 48 PHA $809F97 29 F0 00 AND #$00F0 ;\ $809F9A 4A LSR A ;| $809F9B 4A LSR A ;| $809F9C 4A LSR A ;} Y = tens digit spritemap pointer $809F9D AA TAX ;| $809F9E BC D4 9F LDY $9FD4,x[$80:9FD4] ;/ $809FA1 A3 03 LDA $03,s [$7E:1FE8] ; A = X parameter $809FA3 20 B3 9F JSR $9FB3 [$80:9FB3] ; Draw timer spritemap $809FA6 68 PLA ;\ $809FA7 29 0F 00 AND #$000F ;| $809FAA 0A ASL A ;} Y = units digit spritemap pointer $809FAB AA TAX ;| $809FAC BC D4 9F LDY $9FD4,x[$80:9FD6] ;/ $809FAF 68 PLA ;\ $809FB0 69 08 00 ADC #$0008 ;} A = X parameter + 8 } ;;; Draw timer spritemap ;;; { ;; Takes parameters: A = position offset; Y = spritemap pointer $809FB3 85 14 STA $14 [$7E:0014] $809FB5 AD 48 09 LDA $0948 [$7E:0948] ;\ $809FB8 EB XBA ;| $809FB9 29 FF 00 AND #$00FF ;| $809FBC 18 CLC ;} $14 = X position $809FBD 65 14 ADC $14 [$7E:0014] ;| $809FBF 85 14 STA $14 [$7E:0014] ;/ $809FC1 AD 4A 09 LDA $094A [$7E:094A] ;\ $809FC4 EB XBA ;| $809FC5 29 FF 00 AND #$00FF ;} $12 = Y position $809FC8 85 12 STA $12 [$7E:0012] ;/ $809FCA A9 00 0A LDA #$0A00 ;\ $809FCD 85 16 STA $16 [$7E:0016] ;} $16 = palette 2 $809FCF 22 9F 87 81 JSL $81879F[$81:879F] ; Draw spritemap $809FD3 60 RTS } ;;; Timer spritemap data ;;; { ; Timer digits spritemap pointers $809FD4 dw 9FE8, 9FF4, A000, A00C, A018, A024, A030, A03C, A048, A054 ; Timer digits spritemaps $809FE8 dx 0002, 01FC,00,3BEA, 01FC,F8,3BE0 ; 0 $809FF4 dx 0002, 01FC,00,3BEB, 01FC,F8,3BE1 ; 1 $80A000 dx 0002, 01FC,00,3BEC, 01FC,F8,3BE2 ; 2 $80A00C dx 0002, 01FC,00,3BED, 01FC,F8,3BE3 ; 3 $80A018 dx 0002, 01FC,00,3BEE, 01FC,F8,3BE4 ; 4 $80A024 dx 0002, 01FC,00,3BEF, 01FC,F8,3BE5 ; 5 $80A030 dx 0002, 01FC,00,3BF0, 01FC,F8,3BE6 ; 6 $80A03C dx 0002, 01FC,00,3BF1, 01FC,F8,3BE7 ; 7 $80A048 dx 0002, 01FC,00,3BF2, 01FC,F8,3BE8 ; 8 $80A054 dx 0002, 01FC,00,3BF3, 01FC,F8,3BE9 ; 9 ; Timer TIME spritemap $80A060 dx 0005, 01F0,F0,3BF8, 01E8,F0,3BF7, 01E0,F0,3BF6, 0008,F8,3BF5, 01F0,F8,3BF4 } ;;; ;;; { ; Called by Loading game data / Set up new game / Transition to demo $80A07B 08 PHP $80A07C 8B PHB $80A07D 4B PHK $80A07E AB PLB $80A07F C2 30 REP #$30 $80A081 78 SEI ; Enable interrupts $80A082 9C 0B 42 STZ $420B [$7E:420B] ; Disable all (H)DMA $80A085 9C E9 07 STZ $07E9 [$7E:07E9] ; Clear $07E9 $80A088 9C F3 07 STZ $07F3 [$7E:07F3] ; Clear currently loaded song/instrument index $80A08B 9C F5 07 STZ $07F5 [$7E:07F5] ; Clear currently loaded track index $80A08E 9C 43 09 STZ $0943 [$7E:0943] ; Disable timer $80A091 22 9A 8A 82 JSL $828A9A[$82:8A9A] ; Execute subroutine $82:8A9A $80A095 A9 FF FF LDA #$FFFF ;\ $80A098 8D F5 05 STA $05F5 [$7E:05F5] ;} Disable sounds $80A09B 22 5D 83 80 JSL $80835D[$80:835D] ; Disable NMI $80A09F 22 5F 98 80 JSL $80985F[$80:985F] ; Disable horizontal and vertical timer interrupts $80A0A3 22 6B E7 82 JSL $82E76B[$82:E76B] ; Execute subroutine $82:E76B $80A0A7 20 2B A1 JSR $A12B [$80:A12B] ; Execute subroutine $A12B $80A0AA 22 16 80 87 JSL $878016[$87:8016] ; Execute subroutine $87:8016 $80A0AE 22 9E 82 88 JSL $88829E[$88:829E] ; Execute subroutine $88:829E $80A0B2 22 C1 82 88 JSL $8882C1[$88:82C1] ; Execute subroutine $88:82C1 $80A0B6 22 C3 83 84 JSL $8483C3[$84:83C3] ; Delete all PLMs $80A0BA 22 16 80 86 JSL $868016[$86:8016] ; Execute subroutine $86:8016 $80A0BE 22 D8 C4 8D JSL $8DC4D8[$8D:C4D8] ; Execute subroutine $8D:C4D8 $80A0C2 22 8D AC 90 JSL $90AC8D[$90:AC8D] ; Execute subroutine $90:AC8D $80A0C6 22 39 E1 82 JSL $82E139[$82:E139] ; Execute subroutine $82:E139 $80A0CA 22 1E 8A A0 JSL $A08A1E[$A0:8A1E] ; Execute subroutine $A0:8A1E $80A0CE 22 71 E0 82 JSL $82E071[$82:E071] ; Execute subroutine $82:E071 $80A0D2 20 2B A1 JSR $A12B [$80:A12B] ; Execute subroutine $A12B $80A0D5 22 9B E0 82 JSL $82E09B[$82:E09B] ; Execute subroutine $82:E09B $80A0D9 22 13 E1 82 JSL $82E113[$82:E113] ; Execute subroutine $82:E113 $80A0DD 22 3F A2 80 JSL $80A23F[$80:A23F] ; VRAM $4800..4FFF = 3838h $80A0E1 22 D3 E7 82 JSL $82E7D3[$82:E7D3] ; Execute subroutine $82:E7D3 $80A0E5 22 82 AB 89 JSL $89AB82[$89:AB82] ; Execute subroutine $89:AB82 $80A0E9 22 7C E9 82 JSL $82E97C[$82:E97C] ; Execute subroutine $82:E97C $80A0ED 20 F9 A2 JSR $A2F9 [$80:A2F9] ; Calculates Layer 2's X scroll position (0917) based on Layer 1 (0911) and Layer 2's X scroll percent (091B) $80A0F0 20 3A A3 JSR $A33A [$80:A33A] ; Calculates Layer 2's Y scroll position (0919) based on Layer 1 (0915) and Layer 2's Y scroll percent (091C) $80A0F3 AD 17 09 LDA $0917 [$7E:0917] ;\ $80A0F6 8D 21 09 STA $0921 [$7E:0921] ;} BG2 X scroll = layer 2 X scroll position $80A0F9 AD 19 09 LDA $0919 [$7E:0919] ;\ $80A0FC 8D 23 09 STA $0923 [$7E:0923] ;} BG2 Y scroll = layer 2 Y scroll position $80A0FF 20 7B A3 JSR $A37B [$80:A37B] ; Translates Layer 1 and Layer 2 scroll positions to BG1 and BG2 scroll positions $80A102 22 76 A1 80 JSL $80A176[$80:A176] ; Display the viewable part of the room? $80A106 22 4B 83 80 JSL $80834B[$80:834B] ; Enable NMI $80A10A A5 A9 LDA $A9 [$7E:00A9] ;\ $80A10C D0 03 BNE $03 [$A111] ;} If no second optional next interrupt: $80A10E A9 04 00 LDA #$0004 ; Use 04 (main gameplay) $80A111 85 A7 STA $A7 [$7E:00A7] ; Set optional next interrupt $80A113 22 2A 98 80 JSL $80982A[$80:982A] ; Enable horizontal and vertical timer interrupts $80A117 20 2B A1 JSR $A12B [$80:A12B] ; Execute subroutine $A12B $80A11A 22 D7 83 84 JSL $8483D7[$84:83D7] ;\ $80A11E dx 08, 08, B7EB ;} Enable sounds in 20 frames, or F0 frames if on Ceres $80A122 A9 37 E7 LDA #$E737 ;\ $80A125 8D 9C 09 STA $099C [$7E:099C] ;} Pointer to next frame's room transition code = $82:E737 $80A128 AB PLB $80A129 28 PLP $80A12A 6B RTL } ;;; ;;; { ; Called by the above routine $80A12B 08 PHP $80A12C E2 30 SEP #$30 $80A12E 22 4B 83 80 JSL $80834B[$80:834B] ; Enable NMI $80A132 A2 14 LDX #$14 ; X = 20 $80A134 DA PHX $80A135 08 PHP $80A136 22 0C 8F 80 JSL $808F0C[$80:8F0C] ; ??? $80A13A 22 38 83 80 JSL $808338[$80:8338] ; Wait for IRQ $80A13E 28 PLP $80A13F FA PLX $80A140 CA DEX ; Decrement X $80A141 D0 F1 BNE $F1 [$A134] ; When X == 0: $80A143 22 5D 83 80 JSL $80835D[$80:835D] ; Disable NMI $80A147 28 PLP $80A148 60 RTS } ;;; ;;; { ; Called in gamestate 11h (unpausing, loading normal gameplay) $80A149 08 PHP $80A14A 8B PHB $80A14B 4B PHK $80A14C AB PLB $80A14D C2 30 REP #$30 $80A14F 78 SEI ; Enable interrupts $80A150 9C 0B 42 STZ $420B [$7E:420B] ; Disable all (H)DMA $80A153 22 5D 83 80 JSL $80835D[$80:835D] ; Disable NMI $80A157 22 5F 98 80 JSL $80985F[$80:985F] ; Disable horizontal and vertical timer interrupts $80A15B 22 83 E7 82 JSL $82E783[$82:E783] ; Execute subroutine $82:E783 $80A15F 22 7C E9 82 JSL $82E97C[$82:E97C] ; Execute subroutine $82:E97C $80A163 22 76 A1 80 JSL $80A176[$80:A176] ; Display the viewable part of the room? $80A167 22 32 82 84 JSL $848232[$84:8232] ; Load custom PLM graphics $80A16B 22 4B 83 80 JSL $80834B[$80:834B] ; Enable NMI $80A16F 22 2A 98 80 JSL $80982A[$80:982A] ; Enable horizontal and vertical interrupts $80A173 AB PLB $80A174 28 PLP $80A175 6B RTL } ;;; Display the viewable part of the room? ;;; { $80A176 08 PHP $80A177 E2 20 SEP #$20 $80A179 A5 58 LDA $58 [$7E:0058] ;\ $80A17B 38 SEC ;| $80A17C E5 59 SBC $59 [$7E:0059] ;| $80A17E EB XBA ;} $098E = BG1 address - BG2 address $80A17F C2 20 REP #$20 ;| $80A181 29 00 F8 AND #$F800 ;| $80A184 8D 8E 09 STA $098E [$7E:098E] ;/ $80A187 20 BB A4 JSR $A4BB [$80:A4BB] ; Calculate blocks scrolled $80A18A A2 00 00 LDX #$0000 $80A18D DA PHX $80A18E AD F7 08 LDA $08F7 [$7E:08F7] ;\ $80A191 8D 90 09 STA $0990 [$7E:0990] ;} Blocks to update X position = number of blocks layer 1 is scrolled rightwards $80A194 AD F9 08 LDA $08F9 [$7E:08F9] ;\ $80A197 8D 92 09 STA $0992 [$7E:0992] ;} Blocks to update Y position = number of blocks layer 1 is scrolled upwards $80A19A AD 07 09 LDA $0907 [$7E:0907] ;\ $80A19D 8D 94 09 STA $0994 [$7E:0994] ;} VRAM blocks to update X position = number of blocks BG1 is scrolled rightwards $80A1A0 AD 09 09 LDA $0909 [$7E:0909] ;\ $80A1A3 8D 96 09 STA $0996 [$7E:0996] ;} VRAM blocks to update Y position = number of blocks BG1 is scrolled upwards $80A1A6 20 DB A9 JSR $A9DB [$80:A9DB] ; Update level data block $80A1A9 AD 1B 09 LDA $091B [$7E:091B] ;\ $80A1AC 4A LSR A ;} If BG_Data layer 2: $80A1AD B0 1B BCS $1B [$A1CA] ;/ $80A1AF AD FB 08 LDA $08FB [$7E:08FB] ;\ $80A1B2 8D 90 09 STA $0990 [$7E:0990] ;} Blocks to update X position = number of blocks layer 2 is scrolled rightwards $80A1B5 AD FD 08 LDA $08FD [$7E:08FD] ;\ $80A1B8 8D 92 09 STA $0992 [$7E:0992] ;} Blocks to update Y position = number of blocks layer 2 is scrolled upwards $80A1BB AD 0B 09 LDA $090B [$7E:090B] ;\ $80A1BE 8D 94 09 STA $0994 [$7E:0994] ;} VRAM blocks to update X position = number of blocks BG2 is scrolled rightwards $80A1C1 AD 0D 09 LDA $090D [$7E:090D] ;\ $80A1C4 8D 96 09 STA $0996 [$7E:0996] ;} VRAM blocks to update Y position = number of blocks BG2 is scrolled upwards $80A1C7 20 D6 A9 JSR $A9D6 [$80:A9D6] ; Update background data block $80A1CA 22 83 8C 80 JSL $808C83[$80:8C83] ; Process $D0,X VRAM writes $80A1CE FA PLX $80A1CF EE F7 08 INC $08F7 [$7E:08F7] ; Increment number of blocks layer 1 is scrolled rightwards $80A1D2 EE 07 09 INC $0907 [$7E:0907] ; Increment number of blocks BG1 is scrolled rightwards $80A1D5 EE FB 08 INC $08FB [$7E:08FB] ; Increment number of blocks layer 2 is scrolled rightwards $80A1D8 EE 0B 09 INC $090B [$7E:090B] ; Increment number of blocks BG2 is scrolled rightwards $80A1DB E8 INX ;\ $80A1DC E0 11 00 CPX #$0011 ;} Repeat 16 more times $80A1DF D0 AC BNE $AC [$A18D] ;/ $80A1E1 28 PLP $80A1E2 6B RTL } ;;; Add VRAM $4800..57FF = 0338h ;;; { $80A1E3 A2 FE 0F LDX #$0FFE $80A1E6 A9 38 03 LDA #$0338 $80A1E9 9F 00 40 7E STA $7E4000,x[$7E:4002] $80A1ED CA DEX $80A1EE CA DEX $80A1EF 10 F8 BPL $F8 [$A1E9] $80A1F1 AE 30 03 LDX $0330 [$7E:0330] $80A1F4 A9 00 10 LDA #$1000 $80A1F7 95 D0 STA $D0,x $80A1F9 A9 00 40 LDA #$4000 $80A1FC 95 D2 STA $D2,x $80A1FE A9 7E 00 LDA #$007E $80A201 95 D4 STA $D4,x $80A203 A9 00 48 LDA #$4800 $80A206 95 D5 STA $D5,x $80A208 8A TXA $80A209 18 CLC $80A20A 69 07 00 ADC #$0007 $80A20D 8D 30 03 STA $0330 [$7E:0330] $80A210 6B RTL } ;;; Add VRAM $5880..677F = 184Eh ;;; { $80A211 A2 FE 0E LDX #$0EFE $80A214 A9 4E 18 LDA #$184E $80A217 9F 00 40 7E STA $7E4000,x[$7E:4EFE] $80A21B CA DEX $80A21C CA DEX $80A21D 10 F8 BPL $F8 [$A217] $80A21F AE 30 03 LDX $0330 [$7E:0330] $80A222 A9 00 0F LDA #$0F00 $80A225 95 D0 STA $D0,x [$7E:00D7] $80A227 A9 00 40 LDA #$4000 $80A22A 95 D2 STA $D2,x [$7E:00D9] $80A22C A9 7E 00 LDA #$007E $80A22F 95 D4 STA $D4,x [$7E:00DB] $80A231 A9 80 58 LDA #$5880 $80A234 95 D5 STA $D5,x [$7E:00DC] $80A236 8A TXA $80A237 18 CLC $80A238 69 07 00 ADC #$0007 $80A23B 8D 30 03 STA $0330 [$7E:0330] $80A23E 6B RTL } ;;; VRAM $4800..4FFF = 3838h ;;; { ; Looks like $A27B is supposed to be 9B A2 $80A23F 08 PHP $80A240 C2 20 REP #$20 $80A242 A9 00 48 LDA #$4800 ;\ $80A245 8D 16 21 STA $2116 [$7E:2116] ;| $80A248 A9 08 18 LDA #$1808 ;| $80A24B 8D 10 43 STA $4310 [$7E:4310] ;| $80A24E A9 9A A2 LDA #$A29A ;| $80A251 8D 12 43 STA $4312 [$7E:4312] ;| $80A254 A9 80 00 LDA #$0080 ;| $80A257 8D 14 43 STA $4314 [$7E:4314] ;} Write 38h to low bytes $80A25A A9 00 08 LDA #$0800 ;| $80A25D 8D 15 43 STA $4315 [$7E:4315] ;| $80A260 E2 20 SEP #$20 ;| $80A262 A9 00 LDA #$00 ;| $80A264 8D 15 21 STA $2115 [$7E:2115] ;| $80A267 A9 02 LDA #$02 ;| $80A269 8D 0B 42 STA $420B [$7E:420B] ;/ $80A26C C2 20 REP #$20 $80A26E A9 00 48 LDA #$4800 ;\ $80A271 8D 16 21 STA $2116 [$7E:2116] ;| $80A274 A9 08 19 LDA #$1908 ;| $80A277 8D 10 43 STA $4310 [$7E:4310] ;| $80A27A A9 9A A2 LDA #$A29A ;| $80A27D 8D 12 43 STA $4312 [$7E:4312] ;| $80A280 A9 80 00 LDA #$0080 ;| $80A283 8D 14 43 STA $4314 [$7E:4314] ;} Write 38h to high bytes $80A286 A9 00 08 LDA #$0800 ;| $80A289 8D 15 43 STA $4315 [$7E:4315] ;| $80A28C E2 20 SEP #$20 ;| $80A28E A9 80 LDA #$80 ;| $80A290 8D 15 21 STA $2115 [$7E:2115] ;| $80A293 A9 02 LDA #$02 ;| $80A295 8D 0B 42 STA $420B [$7E:420B] ;/ $80A298 28 PLP $80A299 6B RTL $80A29A db 38, 03 } ;;; VRAM $5880..5FFF = 184Eh ;;; { $80A29C 08 PHP $80A29D C2 20 REP #$20 $80A29F A9 80 58 LDA #$5880 ;\ $80A2A2 8D 16 21 STA $2116 [$7E:2116] ;| $80A2A5 A9 08 18 LDA #$1808 ;| $80A2A8 8D 10 43 STA $4310 [$7E:4310] ;| $80A2AB A9 F7 A2 LDA #$A2F7 ;| $80A2AE 8D 12 43 STA $4312 [$7E:4312] ;| $80A2B1 A9 80 00 LDA #$0080 ;| $80A2B4 8D 14 43 STA $4314 [$7E:4314] ;} Write 4Eh to low bytes $80A2B7 A9 80 07 LDA #$0780 ;| $80A2BA 8D 15 43 STA $4315 [$7E:4315] ;| $80A2BD E2 20 SEP #$20 ;| $80A2BF A9 00 LDA #$00 ;| $80A2C1 8D 15 21 STA $2115 [$7E:2115] ;| $80A2C4 A9 02 LDA #$02 ;| $80A2C6 8D 0B 42 STA $420B [$7E:420B] ;/ $80A2C9 C2 20 REP #$20 $80A2CB A9 80 58 LDA #$5880 ;\ $80A2CE 8D 16 21 STA $2116 [$7E:2116] ;| $80A2D1 A9 08 19 LDA #$1908 ;| $80A2D4 8D 10 43 STA $4310 [$7E:4310] ;| $80A2D7 A9 F8 A2 LDA #$A2F8 ;| $80A2DA 8D 12 43 STA $4312 [$7E:4312] ;| $80A2DD A9 80 00 LDA #$0080 ;| $80A2E0 8D 14 43 STA $4314 [$7E:4314] ;} Write 18h to high bytes $80A2E3 A9 80 07 LDA #$0780 ;| $80A2E6 8D 15 43 STA $4315 [$7E:4315] ;| $80A2E9 E2 20 SEP #$20 ;| $80A2EB A9 80 LDA #$80 ;| $80A2ED 8D 15 21 STA $2115 [$7E:2115] ;| $80A2F0 A9 02 LDA #$02 ;| $80A2F2 8D 0B 42 STA $420B [$7E:420B] ;/ $80A2F5 28 PLP $80A2F6 6B RTL $80A2F7 db 4E, 18 } ;;; Calculate layer 2 X position ;;; { ;; Returns carry: set if using BG_Data, clear otherwise; A: layer 2 X position ; Layer 2 X position high = Layer2Scroll X * (layer 1 X position high) ; Layer 2 X position low = Layer2Scroll X * (layer 1 X position low) / 100h ; Layer 2 X position = layer 2 X position high + layer 2 X position low $80A2F9 08 PHP $80A2FA AC 11 09 LDY $0911 [$7E:0911] ; Layer 1 X position $80A2FD E2 20 SEP #$20 ;\ $80A2FF AD 1B 09 LDA $091B [$7E:091B] ;} If Layer2Scroll X == 0: layer 2 X position = layer 1 X position $80A302 F0 2A BEQ $2A [$A32E] ;/ $80A304 C9 01 CMP #$01 ;\ $80A306 F0 2F BEQ $2F [$A337] ;} If using BG_Data: return carry set $80A308 29 FE AND #$FE ;\ $80A30A 8D 02 42 STA $4202 [$7E:4202] ;| $80A30D AD 11 09 LDA $0911 [$7E:0911] ;| $80A310 8D 03 42 STA $4203 [$7E:4203] ;| $80A313 9C 34 09 STZ $0934 [$7E:0934] ;} $0933 = Layer2Scroll X * (layer 1 X position & FFh) / 100h $80A316 48 PHA ;| $80A317 68 PLA ;| $80A318 AD 17 42 LDA $4217 [$7E:4217] ;| $80A31B 8D 33 09 STA $0933 [$7E:0933] ;/ $80A31E AD 12 09 LDA $0912 [$7E:0912] ;\ $80A321 8D 03 42 STA $4203 [$7E:4203] ;| $80A324 C2 20 REP #$20 ;| $80A326 AD 33 09 LDA $0933 [$7E:0933] ;} Layer 2 X position = [$0933] + Layer2Scroll X * (layer 1 X position / 100h) $80A329 18 CLC ;| $80A32A 6D 16 42 ADC $4216 [$7E:4216] ;| $80A32D A8 TAY ;/ $80A32E C2 20 REP #$20 $80A330 98 TYA $80A331 8D 17 09 STA $0917 [$7E:0917] ; Layer 2 X position $80A334 28 PLP ;\ $80A335 18 CLC ;} Return carry clear $80A336 60 RTS ;/ $80A337 28 PLP ;\ $80A338 38 SEC ;} Return carry set $80A339 60 RTS ;/ } ;;; Calculate layer 2 Y position ;;; { ;; Returns carry: set if using BG_Data, clear otherwise; A: layer 2 Y position ; Layer 2 Y position high = Layer2Scroll Y * (layer 1 Y position high) ; Layer 2 Y position low = Layer2Scroll Y * (layer 1 Y position low) / 100h ; Layer 2 Y position = layer 2 Y position high + layer 2 Y position low $80A33A 08 PHP $80A33B AC 15 09 LDY $0915 [$7E:0915] ; Layer 1 Y position $80A33E E2 20 SEP #$20 ;\ $80A340 AD 1C 09 LDA $091C [$7E:091C] ;} If Layer2Scroll Y == 0: layer 2 Y position = layer 1 Y position $80A343 F0 2A BEQ $2A [$A36F] ;/ $80A345 C9 01 CMP #$01 ;\ $80A347 F0 2F BEQ $2F [$A378] ;} If using BG_Data: return carry set $80A349 29 FE AND #$FE ;\ $80A34B 8D 02 42 STA $4202 [$7E:4202] ;| $80A34E AD 15 09 LDA $0915 [$7E:0915] ;| $80A351 8D 03 42 STA $4203 [$7E:4203] ;| $80A354 9C 34 09 STZ $0934 [$7E:0934] ;} $0933 = Layer2Scroll Y * (layer 1 Y position & FFh) / 100h $80A357 48 PHA ;| $80A358 68 PLA ;| $80A359 AD 17 42 LDA $4217 [$7E:4217] ;| $80A35C 8D 33 09 STA $0933 [$7E:0933] ;/ $80A35F AD 16 09 LDA $0916 [$7E:0916] ;\ $80A362 8D 03 42 STA $4203 [$7E:4203] ;| $80A365 C2 20 REP #$20 ;| $80A367 AD 33 09 LDA $0933 [$7E:0933] ;} Layer 2 Y position = [$0933] + Layer2Scroll Y * (layer 1 Y position / 100h) $80A36A 18 CLC ;| $80A36B 6D 16 42 ADC $4216 [$7E:4216] ;| $80A36E A8 TAY ;/ $80A36F C2 20 REP #$20 $80A371 98 TYA $80A372 8D 19 09 STA $0919 [$7E:0919] ; Layer 2 Y position $80A375 28 PLP ;\ $80A376 18 CLC ;} Return carry clear $80A377 60 RTS ;/ $80A378 28 PLP ;\ $80A379 38 SEC ;} Return carry set $80A37A 60 RTS ;/ } ;;; Calculate BG positions ;;; { $80A37B AD 11 09 LDA $0911 [$7E:0911] ;\ $80A37E 18 CLC ;| $80A37F 6D 1D 09 ADC $091D [$7E:091D] ;} BG1 X position = layer 1 X position + BG1 X scroll offset $80A382 85 B1 STA $B1 [$7E:00B1] ;/ $80A384 AD 15 09 LDA $0915 [$7E:0915] ;\ $80A387 18 CLC ;| $80A388 6D 1F 09 ADC $091F [$7E:091F] ;} BG1 Y position = layer 1 Y position + BG1 Y scroll offset $80A38B 85 B3 STA $B3 [$7E:00B3] ;/ $80A38D AD 17 09 LDA $0917 [$7E:0917] ;\ $80A390 18 CLC ;| $80A391 6D 21 09 ADC $0921 [$7E:0921] ;} BG2 X position = layer 2 X position + BG2 X scroll offset $80A394 85 B5 STA $B5 [$7E:00B5] ;/ $80A396 AD 19 09 LDA $0919 [$7E:0919] ;\ $80A399 18 CLC ;| $80A39A 6D 23 09 ADC $0923 [$7E:0923] ;} BG2 Y position = layer 2 Y position + BG2 Y scroll offset $80A39D 85 B7 STA $B7 [$7E:00B7] ;/ $80A39F 60 RTS } ;;; Updates only BG1 when scrolling, I think ;;; { ; Does the following routine but wihtout calculating BG positions $80A3A0 08 PHP $80A3A1 8B PHB $80A3A2 4B PHK $80A3A3 AB PLB $80A3A4 C2 30 REP #$30 $80A3A6 20 7B A3 JSR $A37B [$80:A37B] ; Calculate BG positions $80A3A9 80 34 BRA $34 [$A3DF] } ;;; Updates BG1 and BG2 graphics when scrolling ;;; { $80A3AB AD 78 0A LDA $0A78 [$7E:0A78] ;\ $80A3AE F0 01 BEQ $01 [$A3B1] ;} If time frozen: return $80A3B0 6B RTL ;/ $80A3B1 08 PHP $80A3B2 8B PHB $80A3B3 4B PHK $80A3B4 AB PLB $80A3B5 C2 30 REP #$30 $80A3B7 AD 11 09 LDA $0911 [$7E:0911] ;\ $80A3BA 18 CLC ;| $80A3BB 6D 1D 09 ADC $091D [$7E:091D] ;} BG1 X position = layer 1 X position + BG1 X scroll offset $80A3BE 85 B1 STA $B1 [$7E:00B1] ;/ $80A3C0 AD 15 09 LDA $0915 [$7E:0915] ;\ $80A3C3 18 CLC ;| $80A3C4 6D 1F 09 ADC $091F [$7E:091F] ;} BG1 Y position = layer 1 Y position + BG1 Y scroll offset $80A3C7 85 B3 STA $B3 [$7E:00B3] ;/ $80A3C9 20 F9 A2 JSR $A2F9 [$80:A2F9] ; Calculate layer 2 X position $80A3CC B0 06 BCS $06 [$A3D4] ; If used custom layer 2: $80A3CE 18 CLC ;\ $80A3CF 6D 21 09 ADC $0921 [$7E:0921] ;} BG2 X position = layer 2 X position + BG2 X scroll offset $80A3D2 85 B5 STA $B5 [$7E:00B5] ;/ $80A3D4 20 3A A3 JSR $A33A [$80:A33A] ; Calculate layer 2 Y position $80A3D7 B0 06 BCS $06 [$A3DF] ; If used custom layer 2: $80A3D9 18 CLC ;\ $80A3DA 6D 23 09 ADC $0923 [$7E:0923] ;} BG2 Y position = layer 2 Y position + BG2 Y scroll offset $80A3DD 85 B7 STA $B7 [$7E:00B7] ;/ $80A3DF C2 20 REP #$20 $80A3E1 20 BB A4 JSR $A4BB [$80:A4BB] ; Calculate blocks scrolled $80A3E4 A2 00 00 LDX #$0000 $80A3E7 AD F7 08 LDA $08F7 [$7E:08F7] ;\ $80A3EA CD FF 08 CMP $08FF [$7E:08FF] ;} If layer 1 blocks scrolled X != previous layer 1 blocks scrolled X: $80A3ED F0 27 BEQ $27 [$A416] ;/ $80A3EF 8D FF 08 STA $08FF [$7E:08FF] ; Previous layer 1 blocks scrolled X = layer 1 blocks scrolled X $80A3F2 30 03 BMI $03 [$A3F7] ;\ $80A3F4 A2 10 00 LDX #$0010 ;} If scrolled rightwards: X = 10h, else X = 0 $80A3F7 8A TXA ;\ $80A3F8 18 CLC ;| $80A3F9 6D F7 08 ADC $08F7 [$7E:08F7] ;} X position of blocks on layer to update = layer 1 blocks scrolled X + X $80A3FC 8D 90 09 STA $0990 [$7E:0990] ;/ $80A3FF 8A TXA ;\ $80A400 18 CLC ;| $80A401 6D 07 09 ADC $0907 [$7E:0907] ;} X position of blocks in BG to update = BG1 blocks scrolled X + X $80A404 8D 94 09 STA $0994 [$7E:0994] ;/ $80A407 AD F9 08 LDA $08F9 [$7E:08F9] ;\ $80A40A 8D 92 09 STA $0992 [$7E:0992] ;} Y position of blocks on layer to update = layer 1 blocks scrolled Y $80A40D AD 09 09 LDA $0909 [$7E:0909] ;\ $80A410 8D 96 09 STA $0996 [$7E:0996] ;} Y position of blocks in BG to update = BG1 blocks scrolled Y $80A413 20 DB A9 JSR $A9DB [$80:A9DB] ; Update level data block $80A416 AD 1B 09 LDA $091B [$7E:091B] ;\ $80A419 4A LSR A ;| $80A41A B0 32 BCS $32 [$A44E] ;| $80A41C A2 00 00 LDX #$0000 ;} If using custom layer 2 and $80A41F AD FB 08 LDA $08FB [$7E:08FB] ;} layer 2 blocks scrolled X != previous layer 2 blocks scrolled X: $80A422 CD 03 09 CMP $0903 [$7E:0903] ;| $80A425 F0 27 BEQ $27 [$A44E] ;/ $80A427 8D 03 09 STA $0903 [$7E:0903] ; Previous layer 2 blocks scrolled X = layer 2 blocks scrolled X $80A42A 30 03 BMI $03 [$A42F] ;\ $80A42C A2 10 00 LDX #$0010 ;} If scrolled rightwards: X = 10h, else X = 0 $80A42F 8A TXA ;\ $80A430 18 CLC ;| $80A431 6D FB 08 ADC $08FB [$7E:08FB] ;} X position of blocks on layer to update = layer 2 blocks scrolled X + X $80A434 8D 90 09 STA $0990 [$7E:0990] ;/ $80A437 8A TXA ;\ $80A438 18 CLC ;| $80A439 6D 0B 09 ADC $090B [$7E:090B] ;} X position of blocks in BG to update = BG2 blocks scrolled X + X $80A43C 8D 94 09 STA $0994 [$7E:0994] ;/ $80A43F AD FD 08 LDA $08FD [$7E:08FD] ;\ $80A442 8D 92 09 STA $0992 [$7E:0992] ;} Y position of blocks on layer to update = layer 2 blocks scrolled Y $80A445 AD 0D 09 LDA $090D [$7E:090D] ;\ $80A448 8D 96 09 STA $0996 [$7E:0996] ;} Y position of blocks in BG to update = BG2 blocks scrolled Y $80A44B 20 D6 A9 JSR $A9D6 [$80:A9D6] ; Update background data block $80A44E A2 01 00 LDX #$0001 $80A451 AD F9 08 LDA $08F9 [$7E:08F9] ;\ $80A454 CD 01 09 CMP $0901 [$7E:0901] ;} If layer 1 blocks scrolled Y != previous layer 1 blocks scrolled Y: $80A457 F0 27 BEQ $27 [$A480] ;/ $80A459 8D 01 09 STA $0901 [$7E:0901] ; Previous layer 1 blocks scrolled Y = layer 1 blocks scrolled Y $80A45C 30 03 BMI $03 [$A461] ;\ $80A45E A2 0F 00 LDX #$000F ;} If scrolled up: X = Fh, else X = 1 $80A461 8A TXA ;\ $80A462 18 CLC ;| $80A463 6D F9 08 ADC $08F9 [$7E:08F9] ;} Y position of blocks on layer to update = layer 1 blocks scrolled Y + X $80A466 8D 92 09 STA $0992 [$7E:0992] ;/ $80A469 8A TXA ;\ $80A46A 18 CLC ;| $80A46B 6D 09 09 ADC $0909 [$7E:0909] ;} Y position of blocks in BG to update = BG1 blocks scrolled Y + X $80A46E 8D 96 09 STA $0996 [$7E:0996] ;/ $80A471 AD F7 08 LDA $08F7 [$7E:08F7] ;\ $80A474 8D 90 09 STA $0990 [$7E:0990] ;} X position of blocks on layer 1 to update = layer 1 blocks scrolled X $80A477 AD 07 09 LDA $0907 [$7E:0907] ;\ $80A47A 8D 94 09 STA $0994 [$7E:0994] ;} X position of blocks in BG to update = BG1 blocks scrolled X $80A47D 20 75 AB JSR $AB75 [$80:AB75] ; Update level data row $80A480 AD 1C 09 LDA $091C [$7E:091C] ;\ $80A483 4A LSR A ;| $80A484 B0 32 BCS $32 [$A4B8] ;| $80A486 A2 01 00 LDX #$0001 ;} If using custom layer 2 and $80A489 AD FD 08 LDA $08FD [$7E:08FD] ;} layer 2 blocks scrolled Y != previous layer 2 blocks scrolled Y: $80A48C CD 05 09 CMP $0905 [$7E:0905] ;| $80A48F F0 27 BEQ $27 [$A4B8] ;/ $80A491 8D 05 09 STA $0905 [$7E:0905] ; Previous layer 2 blocks scrolled Y = layer 2 blocks scrolled Y $80A494 30 03 BMI $03 [$A499] ;\ $80A496 A2 0F 00 LDX #$000F ;} If scrolled up: X = 10h, else X = 0 $80A499 8A TXA ;\ $80A49A 18 CLC ;| $80A49B 6D FD 08 ADC $08FD [$7E:08FD] ;} Y position of blocks on layer to update = layer 2 blocks scrolled Y + X $80A49E 8D 92 09 STA $0992 [$7E:0992] ;/ $80A4A1 8A TXA ;\ $80A4A2 18 CLC ;| $80A4A3 6D 0D 09 ADC $090D [$7E:090D] ;} Y position of blocks in BG to update = BG2 blocks scrolled Y + X $80A4A6 8D 96 09 STA $0996 [$7E:0996] ;/ $80A4A9 AD FB 08 LDA $08FB [$7E:08FB] ;\ $80A4AC 8D 90 09 STA $0990 [$7E:0990] ;} X position of blocks on layer to update = layer 2 blocks scrolled X $80A4AF AD 0B 09 LDA $090B [$7E:090B] ;\ $80A4B2 8D 94 09 STA $0994 [$7E:0994] ;} X position of blocks in BG to update = BG2 blocks scrolled X $80A4B5 20 70 AB JSR $AB70 [$80:AB70] ; Update background data row $80A4B8 AB PLB $80A4B9 28 PLP $80A4BA 6B RTL } ;;; Calculate blocks scrolled ;;; { $80A4BB A5 B1 LDA $B1 [$7E:00B1] ;\ $80A4BD 4A LSR A ;| $80A4BE 4A LSR A ;| $80A4BF 4A LSR A ;} BG1 blocks scrolled X = BG1 X position >> 4 $80A4C0 4A LSR A ;| $80A4C1 8D 07 09 STA $0907 [$7E:0907] ;/ $80A4C4 A5 B5 LDA $B5 [$7E:00B5] ;\ $80A4C6 4A LSR A ;| $80A4C7 4A LSR A ;| $80A4C8 4A LSR A ;} BG2 blocks scrolled X = BG2 X position >> 4 $80A4C9 4A LSR A ;| $80A4CA 8D 0B 09 STA $090B [$7E:090B] ;/ $80A4CD AD 11 09 LDA $0911 [$7E:0911] ;\ $80A4D0 4A LSR A ;| $80A4D1 4A LSR A ;| $80A4D2 4A LSR A ;| $80A4D3 4A LSR A ;| $80A4D4 89 00 08 BIT #$0800 ;} Layer 1 blocks scrolled X = layer 1 X position ±>> 4 $80A4D7 F0 03 BEQ $03 [$A4DC] ;| $80A4D9 09 00 F0 ORA #$F000 ;| ;| $80A4DC 8D F7 08 STA $08F7 [$7E:08F7] ;/ $80A4DF AD 17 09 LDA $0917 [$7E:0917] ;\ $80A4E2 4A LSR A ;| $80A4E3 4A LSR A ;| $80A4E4 4A LSR A ;| $80A4E5 4A LSR A ;| $80A4E6 89 00 08 BIT #$0800 ;} Layer 2 blocks scrolled X = layer 2 X position ±>> 4 $80A4E9 F0 03 BEQ $03 [$A4EE] ;| $80A4EB 09 00 F0 ORA #$F000 ;| ;| $80A4EE 8D FB 08 STA $08FB [$7E:08FB] ;/ $80A4F1 A5 B3 LDA $B3 [$7E:00B3] ;\ $80A4F3 4A LSR A ;| $80A4F4 4A LSR A ;| $80A4F5 4A LSR A ;} BG1 blocks scrolled Y = BG1 Y position >> 4 $80A4F6 4A LSR A ;| $80A4F7 8D 09 09 STA $0909 [$7E:0909] ;/ $80A4FA A5 B7 LDA $B7 [$7E:00B7] ;\ $80A4FC 4A LSR A ;| $80A4FD 4A LSR A ;| $80A4FE 4A LSR A ;} BG2 blocks scrolled Y = BG2 Y position >> 4 $80A4FF 4A LSR A ;| $80A500 8D 0D 09 STA $090D [$7E:090D] ;/ $80A503 AD 15 09 LDA $0915 [$7E:0915] ;\ $80A506 4A LSR A ;| $80A507 4A LSR A ;| $80A508 4A LSR A ;| $80A509 4A LSR A ;| $80A50A 89 00 08 BIT #$0800 ;} Layer 1 blocks scrolled Y = layer 1 Y position ±>> 4 $80A50D F0 03 BEQ $03 [$A512] ;| $80A50F 09 00 F0 ORA #$F000 ;| ;| $80A512 8D F9 08 STA $08F9 [$7E:08F9] ;/ $80A515 AD 19 09 LDA $0919 [$7E:0919] ;\ $80A518 4A LSR A ;| $80A519 4A LSR A ;| $80A51A 4A LSR A ;| $80A51B 4A LSR A ;| $80A51C 89 00 08 BIT #$0800 ;} Layer 2 blocks scrolled Y = layer 2 Y position ±>> 4 $80A51F F0 03 BEQ $03 [$A524] ;| $80A521 09 00 F0 ORA #$F000 ;| ;| $80A524 8D FD 08 STA $08FD [$7E:08FD] ;/ $80A527 60 RTS } ;;; Handle autoscrolling when not moving horizontally and part of the screen is has no scroll ;;; { $80A528 08 PHP $80A529 8B PHB $80A52A E2 20 SEP #$20 $80A52C AD 78 0A LDA $0A78 [$7E:0A78] ;\ $80A52F 0D 79 0A ORA $0A79 [$7E:0A79] ;| $80A532 F0 03 BEQ $03 [$A537] ;} If time frozen: return $80A534 4C 3E A6 JMP $A63E [$80:A63E] ;/ $80A537 A9 8F LDA #$8F ;\ $80A539 48 PHA ;} DB = $8F $80A53A AB PLB ;/ $80A53B C2 30 REP #$30 $80A53D AD 11 09 LDA $0911 [$7E:0911] ;\ $80A540 8D 39 09 STA $0939 [$7E:0939] ;} $0939 = layer 1 X position $80A543 10 03 BPL $03 [$A548] ;\ $80A545 9C 11 09 STZ $0911 [$7E:0911] ;} Cap layer 1 X position to 0 $80A548 AD A9 07 LDA $07A9 [$7E:07A9] ;\ $80A54B 3A DEC A ;| $80A54C EB XBA ;| $80A54D CD 11 09 CMP $0911 [$7E:0911] ;} Cap layer 1 X position to room width $80A550 B0 03 BCS $03 [$A555] ;| $80A552 8D 11 09 STA $0911 [$7E:0911] ;/ $80A555 AD 15 09 LDA $0915 [$7E:0915] ;\ $80A558 18 CLC ;| $80A559 69 80 00 ADC #$0080 ;| $80A55C EB XBA ;| $80A55D E2 20 SEP #$20 ;| $80A55F 8D 02 42 STA $4202 [$7E:4202] ;| $80A562 AD A9 07 LDA $07A9 [$7E:07A9] ;| $80A565 8D 03 42 STA $4203 [$7E:4203] ;| $80A568 C2 20 REP #$20 ;} If layer 1 position + screen/2 down's scroll != 0: branch to $A5D9 $80A56A AD 12 09 LDA $0912 [$7E:0912] ;| $80A56D 29 FF 00 AND #$00FF ;| $80A570 18 CLC ;| $80A571 6D 16 42 ADC $4216 [$7E:4216] ;| $80A574 AA TAX ;| $80A575 BF 20 CD 7E LDA $7ECD20,x[$7E:CD20] ;| $80A579 29 FF 00 AND #$00FF ;| $80A57C D0 5B BNE $5B [$A5D9] ;/ $80A57E AD 11 09 LDA $0911 [$7E:0911] ;\ $80A581 29 00 FF AND #$FF00 ;| $80A584 18 CLC ;} $0933 = layer 1 X rounded up to next screen $80A585 69 00 01 ADC #$0100 ;| $80A588 8D 33 09 STA $0933 [$7E:0933] ;/ $80A58B AD 39 09 LDA $0939 [$7E:0939] ;\ $80A58E 18 CLC ;| $80A58F 6D A2 0D ADC $0DA2 [$7E:0DA2] ;} A = [$0939] + absolute distance moved X + 3 $80A592 69 02 00 ADC #$0002 ;/ $80A595 CD 33 09 CMP $0933 [$7E:0933] ;\ $80A598 B0 3A BCS $3A [$A5D4] ;} If A >= [$0933]: layer 1 X position = [$0933] and return $80A59A 8D 39 09 STA $0939 [$7E:0939] ; $0939 = A $80A59D AD 15 09 LDA $0915 [$7E:0915] ;\ $80A5A0 18 CLC ;| $80A5A1 69 80 00 ADC #$0080 ;| $80A5A4 EB XBA ;| $80A5A5 E2 20 SEP #$20 ;| $80A5A7 8D 02 42 STA $4202 [$7E:4202] ;| $80A5AA AD A9 07 LDA $07A9 [$7E:07A9] ;| $80A5AD 8D 03 42 STA $4203 [$7E:4203] ;| $80A5B0 C2 20 REP #$20 ;| $80A5B2 AD 3A 09 LDA $093A [$7E:093A] ;} If layer 1 position + screen/2 down + 1 screen right's scroll == 0: $80A5B5 1A INC A ;| $80A5B6 29 FF 00 AND #$00FF ;| $80A5B9 18 CLC ;| $80A5BA 6D 16 42 ADC $4216 [$7E:4216] ;| $80A5BD AA TAX ;| $80A5BE BF 20 CD 7E LDA $7ECD20,x[$7E:CD2D] ;| $80A5C2 29 FF 00 AND #$00FF ;| $80A5C5 D0 08 BNE $08 [$A5CF] ;/ $80A5C7 AD 39 09 LDA $0939 [$7E:0939] ;\ $80A5CA 29 00 FF AND #$FF00 ;} Layer 1 X position = [$0939] rounded down to next screen and return $80A5CD 80 6C BRA $6C [$A63B] ;/ $80A5CF AD 39 09 LDA $0939 [$7E:0939] ;\ $80A5D2 80 67 BRA $67 [$A63B] ;} Layer 1 X position = [$0939] and return $80A5D4 AD 33 09 LDA $0933 [$7E:0933] $80A5D7 80 62 BRA $62 [$A63B] $80A5D9 E8 INX ;\ $80A5DA BF 20 CD 7E LDA $7ECD20,x[$7E:CD21] ;| $80A5DE 29 FF 00 AND #$00FF ;} If layer 1 position + 1/2 screen down + 1 screen right's scroll != 0: return $80A5E1 D0 5B BNE $5B [$A63E] ;/ $80A5E3 AD 11 09 LDA $0911 [$7E:0911] ;\ $80A5E6 29 00 FF AND #$FF00 ;} $0933 = layer 1 X rounded down to next screen $80A5E9 8D 33 09 STA $0933 [$7E:0933] ;/ $80A5EC AD 39 09 LDA $0939 [$7E:0939] ;\ $80A5EF 38 SEC ;| $80A5F0 ED A2 0D SBC $0DA2 [$7E:0DA2] ;} A = [$0939] - absolute difference moved - 3 $80A5F3 E9 02 00 SBC #$0002 ;/ $80A5F6 CD 33 09 CMP $0933 [$7E:0933] ;\ $80A5F9 30 3D BMI $3D [$A638] ;} If A < [$0933]: layer 1 X position = [$0933] and return $80A5FB 8D 39 09 STA $0939 [$7E:0939] ; $0939 = A $80A5FE AD 15 09 LDA $0915 [$7E:0915] ;\ $80A601 18 CLC ;| $80A602 69 80 00 ADC #$0080 ;| $80A605 EB XBA ;| $80A606 E2 20 SEP #$20 ;| $80A608 8D 02 42 STA $4202 [$7E:4202] ;| $80A60B AD A9 07 LDA $07A9 [$7E:07A9] ;| $80A60E 8D 03 42 STA $4203 [$7E:4203] ;| $80A611 C2 20 REP #$20 ;} If layer 1 position + screen/2 down's scroll == 0: $80A613 AD 3A 09 LDA $093A [$7E:093A] ;| $80A616 29 FF 00 AND #$00FF ;| $80A619 18 CLC ;| $80A61A 6D 16 42 ADC $4216 [$7E:4216] ;| $80A61D AA TAX ;| $80A61E BF 20 CD 7E LDA $7ECD20,x[$7E:CD21] ;| $80A622 29 FF 00 AND #$00FF ;| $80A625 D0 0C BNE $0C [$A633] ;/ $80A627 AD 39 09 LDA $0939 [$7E:0939] ;\ $80A62A 29 00 FF AND #$FF00 ;| $80A62D 18 CLC ;} Layer 1 X position = [$0939] rounded up to next screen and return $80A62E 69 00 01 ADC #$0100 ;| $80A631 80 08 BRA $08 [$A63B] ;/ $80A633 AD 39 09 LDA $0939 [$7E:0939] ;\ $80A636 80 03 BRA $03 [$A63B] ;} Layer 1 X position = [$0939] $80A638 AD 33 09 LDA $0933 [$7E:0933] $80A63B 8D 11 09 STA $0911 [$7E:0911] $80A63E AB PLB $80A63F 28 PLP $80A640 6B RTL } ;;; Handle scrolling when moving and triggered scrolling right ;;; { $80A641 08 PHP $80A642 8B PHB $80A643 E2 20 SEP #$20 $80A645 A9 8F LDA #$8F ;\ $80A647 48 PHA ;} DB = $8F $80A648 AB PLB ;/ $80A649 C2 30 REP #$30 $80A64B AD 11 09 LDA $0911 [$7E:0911] ;\ $80A64E 8D 39 09 STA $0939 [$7E:0939] ;} $0939 = layer 1 X position $80A651 AD 0A 0B LDA $0B0A [$7E:0B0A] ;\ $80A654 CD 11 09 CMP $0911 [$7E:0911] ;| $80A657 10 09 BPL $09 [$A662] ;} Cap layer 1 X position to 'ideal' layer 1 X position $80A659 AD 0A 0B LDA $0B0A [$7E:0B0A] ;| $80A65F 9C 0F 09 STZ $090F [$7E:090F] ;/ $80A662 AD A9 07 LDA $07A9 [$7E:07A9] ;\ $80A665 3A DEC A ;| $80A666 EB XBA ;| $80A667 CD 11 09 CMP $0911 [$7E:0911] ;} Cap layer 1 X position to room width $80A66A B0 05 BCS $05 [$A671] ;| $80A66C 8D 11 09 STA $0911 [$7E:0911] ;/ $80A66F 80 47 BRA $47 [$A6B8] ; If reached cap: return $80A671 AD 15 09 LDA $0915 [$7E:0915] ;\ $80A674 18 CLC ;| $80A675 69 80 00 ADC #$0080 ;| $80A678 EB XBA ;| $80A679 E2 20 SEP #$20 ;| $80A67B 8D 02 42 STA $4202 [$7E:4202] ;| $80A67E AD A9 07 LDA $07A9 [$7E:07A9] ;| $80A681 8D 03 42 STA $4203 [$7E:4203] ;| $80A684 C2 20 REP #$20 ;} If layer 1 position + 1/2 screen down + 1 screen right's scroll != 0: return $80A686 AD 12 09 LDA $0912 [$7E:0912] ;| $80A689 29 FF 00 AND #$00FF ;| $80A68C 38 SEC ;| $80A68D 6D 16 42 ADC $4216 [$7E:4216] ;| $80A690 AA TAX ;| $80A691 BF 20 CD 7E LDA $7ECD20,x[$7E:CD21] ;| $80A695 29 FF 00 AND #$00FF ;| $80A698 D0 1E BNE $1E [$A6B8] ;/ $80A69A AD 11 09 LDA $0911 [$7E:0911] ;\ $80A69D 29 00 FF AND #$FF00 ;} $0933 = layer 1 X position rounded down to next screen $80A6A0 8D 33 09 STA $0933 [$7E:0933] ;/ $80A6A3 AD 39 09 LDA $0939 [$7E:0939] ;\ $80A6A6 38 SEC ;| $80A6A7 ED A2 0D SBC $0DA2 [$7E:0DA2] ;} A = [$0939] - absolute distance moved X - 3 $80A6AA E9 02 00 SBC #$0002 ;/ $80A6AD CD 33 09 CMP $0933 [$7E:0933] ;\ $80A6B0 10 03 BPL $03 [$A6B5] ;} If A < [$0933]: $80A6B2 AD 33 09 LDA $0933 [$7E:0933] ; Layer 1 X position = [$0933] $80A6B5 8D 11 09 STA $0911 [$7E:0911] ; Else: layer 1 X position = A $80A6B8 AB PLB $80A6B9 28 PLP $80A6BA 6B RTL } ;;; Handle scrolling when moving and triggered scrolling left ;;; { $80A6BB 08 PHP $80A6BC 8B PHB $80A6BD E2 20 SEP #$20 $80A6BF A9 8F LDA #$8F ;\ $80A6C1 48 PHA ;} DB = $8F $80A6C2 AB PLB ;/ $80A6C3 C2 30 REP #$30 $80A6C5 AD 11 09 LDA $0911 [$7E:0911] ;\ $80A6C8 8D 39 09 STA $0939 [$7E:0939] ;} $0939 = layer 1 X position $80A6CB CD 0A 0B CMP $0B0A [$7E:0B0A] ;\ $80A6CE 10 09 BPL $09 [$A6D9] ;| $80A6D0 AD 0A 0B LDA $0B0A [$7E:0B0A] ;} Cap layer 1 X position to 'ideal' layer 1 X position $80A6D3 8D 11 09 STA $0911 [$7E:0911] ;| $80A6D6 9C 0F 09 STZ $090F [$7E:090F] ;/ $80A6D9 AD 11 09 LDA $0911 [$7E:0911] ;\ $80A6DC 10 05 BPL $05 [$A6E3] ;} Cap layer 1 X position to 0 $80A6DE 9C 11 09 STZ $0911 [$7E:0911] ;/ $80A6E1 80 4B BRA $4B [$A72E] ; If reached cap: return $80A6E3 AD 15 09 LDA $0915 [$7E:0915] ;\ $80A6E6 18 CLC ;| $80A6E7 69 80 00 ADC #$0080 ;| $80A6EA EB XBA ;| $80A6EB E2 20 SEP #$20 ;| $80A6ED 8D 02 42 STA $4202 [$7E:4202] ;| $80A6F0 AD A9 07 LDA $07A9 [$7E:07A9] ;| $80A6F3 8D 03 42 STA $4203 [$7E:4203] ;| $80A6F6 C2 20 REP #$20 ;} If layer 1 position + 1/2 screen down's scroll != 0: return $80A6F8 AD 12 09 LDA $0912 [$7E:0912] ;| $80A6FB 29 FF 00 AND #$00FF ;| $80A6FE 18 CLC ;| $80A6FF 6D 16 42 ADC $4216 [$7E:4216] ;| $80A702 AA TAX ;| $80A703 BF 20 CD 7E LDA $7ECD20,x[$7E:CD20] ;| $80A707 29 FF 00 AND #$00FF ;| $80A70A D0 22 BNE $22 [$A72E] ;/ $80A70C AD 11 09 LDA $0911 [$7E:0911] ;\ $80A70F 29 00 FF AND #$FF00 ;| $80A712 18 CLC ;} $0933 = layer 1 X position rounded up to next screen $80A713 69 00 01 ADC #$0100 ;| $80A716 8D 33 09 STA $0933 [$7E:0933] ;/ $80A719 AD 39 09 LDA $0939 [$7E:0939] ;\ $80A71C 18 CLC ;| $80A71D 6D A2 0D ADC $0DA2 [$7E:0DA2] ;} A = [$0939] + absolute distance moved X + 3 $80A720 69 02 00 ADC #$0002 ;/ $80A723 CD 33 09 CMP $0933 [$7E:0933] ;\ $80A726 90 03 BCC $03 [$A72B] ;} If A >= [$0933]: $80A728 AD 33 09 LDA $0933 [$7E:0933] ; Layer 1 X position = [$0933] $80A72B 8D 11 09 STA $0911 [$7E:0911] ; Else: layer 1 X position = A $80A72E AB PLB $80A72F 28 PLP $80A730 6B RTL } ;;; Handle autoscrolling when not moving vertically and part of the screen is has no scroll ;;; { $80A731 08 PHP $80A732 8B PHB $80A733 E2 20 SEP #$20 $80A735 AD 78 0A LDA $0A78 [$7E:0A78] ;\ $80A738 0D 79 0A ORA $0A79 [$7E:0A79] ;| $80A73B F0 03 BEQ $03 [$A740] ;} If time frozen: return $80A73D 4C 90 A8 JMP $A890 [$80:A890] ;/ $80A740 A9 8F LDA #$8F ;\ $80A742 48 PHA ;} DB = $8F $80A743 AB PLB ;/ $80A744 C2 30 REP #$30 $80A746 A0 00 00 LDY #$0000 ; Y = 0 $80A749 E2 20 SEP #$20 $80A74B AD 16 09 LDA $0916 [$7E:0916] ;\ $80A74E 8D 02 42 STA $4202 [$7E:4202] ;| $80A751 AD A9 07 LDA $07A9 [$7E:07A9] ;| $80A754 8D 03 42 STA $4203 [$7E:4203] ;| $80A757 C2 20 REP #$20 ;| $80A759 AD 11 09 LDA $0911 [$7E:0911] ;| $80A75C 18 CLC ;| $80A75D 69 80 00 ADC #$0080 ;| $80A760 EB XBA ;| $80A761 29 FF 00 AND #$00FF ;} If layer 1 position + screen/2 right's scroll != 1: $80A764 18 CLC ;| $80A765 6D 16 42 ADC $4216 [$7E:4216] ;| $80A768 85 14 STA $14 [$7E:0014] ;| $80A76A AA TAX ;| $80A76B BF 20 CD 7E LDA $7ECD20,x[$7E:CD20] ;| $80A76F 29 FF 00 AND #$00FF ;| $80A772 C9 01 00 CMP #$0001 ;| $80A775 F0 03 BEQ $03 [$A77A] ;/ $80A777 A0 1F 00 LDY #$001F ; Y = 1Fh $80A77A 8C 33 09 STY $0933 [$7E:0933] ; $0933 = Y $80A77D AD 15 09 LDA $0915 [$7E:0915] ;\ $80A780 8D 39 09 STA $0939 [$7E:0939] ;} $0939 = layer 1 Y position $80A783 10 03 BPL $03 [$A788] ;\ $80A785 9C 15 09 STZ $0915 [$7E:0915] ;} Cap layer 1 Y position to 0 $80A788 AD AB 07 LDA $07AB [$7E:07AB] ;\ $80A78B 3A DEC A ;| $80A78C EB XBA ;| $80A78D 18 CLC ;| $80A78E 6D 33 09 ADC $0933 [$7E:0933] ;} Cap layer 1 Y position to room height + [$0933] $80A791 CD 15 09 CMP $0915 [$7E:0915] ;| $80A794 B0 03 BCS $03 [$A799] ;| $80A796 8D 15 09 STA $0915 [$7E:0915] ;/ $80A799 E2 20 SEP #$20 $80A79B AD 16 09 LDA $0916 [$7E:0916] ;\ $80A79E 8D 02 42 STA $4202 [$7E:4202] ;| $80A7A1 AD A9 07 LDA $07A9 [$7E:07A9] ;| $80A7A4 8D 03 42 STA $4203 [$7E:4203] ;| $80A7A7 C2 20 REP #$20 ;| $80A7A9 AD 11 09 LDA $0911 [$7E:0911] ;| $80A7AC 18 CLC ;| $80A7AD 69 80 00 ADC #$0080 ;| $80A7B0 EB XBA ;} If layer 1 position + screen/2 right's scroll != 0: branch to $A81D $80A7B1 29 FF 00 AND #$00FF ;| $80A7B4 18 CLC ;| $80A7B5 6D 16 42 ADC $4216 [$7E:4216] ;| $80A7B8 AA TAX ;| $80A7B9 BF 20 CD 7E LDA $7ECD20,x[$7E:CD20] ;| $80A7BD 29 FF 00 AND #$00FF ;| $80A7C0 D0 5B BNE $5B [$A81D] ;/ $80A7C2 AD 15 09 LDA $0915 [$7E:0915] ;\ $80A7C5 29 00 FF AND #$FF00 ;| $80A7C8 18 CLC ;} $0935 = layer 1 Y rounded up to next screen $80A7C9 69 00 01 ADC #$0100 ;| $80A7CC 8D 35 09 STA $0935 [$7E:0935] ;/ $80A7CF AD 39 09 LDA $0939 [$7E:0939] ;\ $80A7D2 18 CLC ;| $80A7D3 6D A6 0D ADC $0DA6 [$7E:0DA6] ;} A = [$0939] + absolute distance moved Y + 3 $80A7D6 69 02 00 ADC #$0002 ;/ $80A7D9 CD 35 09 CMP $0935 [$7E:0935] ;\ $80A7DC B0 3A BCS $3A [$A818] ;} If A >= [$0935]: layer 1 Y position = [$0935] and return $80A7DE 8D 39 09 STA $0939 [$7E:0939] ; $0939 = A $80A7E1 E2 20 SEP #$20 ;\ $80A7E3 AD 3A 09 LDA $093A [$7E:093A] ;| $80A7E6 1A INC A ;| $80A7E7 8D 02 42 STA $4202 [$7E:4202] ;| $80A7EA AD A9 07 LDA $07A9 [$7E:07A9] ;| $80A7ED 8D 03 42 STA $4203 [$7E:4203] ;| $80A7F0 C2 20 REP #$20 ;| $80A7F2 AD 11 09 LDA $0911 [$7E:0911] ;| $80A7F5 18 CLC ;| $80A7F6 69 80 00 ADC #$0080 ;} If layer 1 position + screen/2 right + 1 screen down's scroll == 0: $80A7F9 EB XBA ;| $80A7FA 29 FF 00 AND #$00FF ;| $80A7FD 18 CLC ;| $80A7FE 6D 16 42 ADC $4216 [$7E:4216] ;| $80A801 AA TAX ;| $80A802 BF 20 CD 7E LDA $7ECD20,x[$7E:CD23] ;| $80A806 29 FF 00 AND #$00FF ;| $80A809 D0 08 BNE $08 [$A813] ;/ $80A80B AD 39 09 LDA $0939 [$7E:0939] ;\ $80A80E 29 00 FF AND #$FF00 ;} Layer 1 Y position = [$0939] rounded down to next screen and return $80A811 80 7A BRA $7A [$A88D] ;/ $80A813 AD 39 09 LDA $0939 [$7E:0939] ;\ $80A816 80 75 BRA $75 [$A88D] ;} Layer 1 Y position = [$0939] and return $80A818 AD 35 09 LDA $0935 [$7E:0935] $80A81B 80 70 BRA $70 [$A88D] $80A81D 8A TXA ;\ $80A81E 18 CLC ;| $80A81F 6D A9 07 ADC $07A9 [$7E:07A9] ;| $80A822 AA TAX ;} If layer 1 position + 1/2 screen right + 1 screen down's scroll != 0: return $80A823 BF 20 CD 7E LDA $7ECD20,x[$7E:CD21] ;| $80A827 29 FF 00 AND #$00FF ;| $80A82A D0 64 BNE $64 [$A890] ;/ $80A82C AD 15 09 LDA $0915 [$7E:0915] ;\ $80A82F 29 00 FF AND #$FF00 ;| $80A832 18 CLC ;} $0937 = layer 1 Y position rounded down to next screen + [$0933] $80A833 6D 33 09 ADC $0933 [$7E:0933] ;| $80A836 8D 37 09 STA $0937 [$7E:0937] ;/ $80A839 CD 15 09 CMP $0915 [$7E:0915] ;\ $80A83C B0 52 BCS $52 [$A890] ;} If [$0937] >= layer 1 Y position: return $80A83E AD 39 09 LDA $0939 [$7E:0939] ;\ $80A841 38 SEC ;| $80A842 ED A6 0D SBC $0DA6 [$7E:0DA6] ;} A = [$0939] - absolute difference moved Y - 3 $80A845 E9 02 00 SBC #$0002 ;/ $80A848 CD 37 09 CMP $0937 [$7E:0937] ;\ $80A84B 30 3D BMI $3D [$A88A] ;} If A < [$0937]: layer 1 Y position = [$0937] and return $80A84D 8D 39 09 STA $0939 [$7E:0939] ; $0939 = A $80A850 E2 20 SEP #$20 ;\ $80A852 AD 3A 09 LDA $093A [$7E:093A] ;| $80A855 8D 02 42 STA $4202 [$7E:4202] ;| $80A858 AD A9 07 LDA $07A9 [$7E:07A9] ;| $80A85B 8D 03 42 STA $4203 [$7E:4203] ;| $80A85E C2 20 REP #$20 ;| $80A860 AD 11 09 LDA $0911 [$7E:0911] ;| $80A863 18 CLC ;| $80A864 69 80 00 ADC #$0080 ;} If layer 1 position + screen/2 right's scroll == 0: $80A867 EB XBA ;| $80A868 29 FF 00 AND #$00FF ;| $80A86B 18 CLC ;| $80A86C 6D 16 42 ADC $4216 [$7E:4216] ;| $80A86F AA TAX ;| $80A870 BF 20 CD 7E LDA $7ECD20,x[$7E:CD22] ;| $80A874 29 FF 00 AND #$00FF ;| $80A877 D0 0C BNE $0C [$A885] ;/ $80A879 AD 39 09 LDA $0939 [$7E:0939] ;\ $80A87C 29 00 FF AND #$FF00 ;| $80A87F 18 CLC ;} Layer 1 Y position = [$0939] rounded up to next screen and return $80A880 69 00 01 ADC #$0100 ;| $80A883 80 08 BRA $08 [$A88D] ;/ $80A885 AD 39 09 LDA $0939 [$7E:0939] ;\ $80A888 80 03 BRA $03 [$A88D] ;} Layer 1 Y position = [$0939] $80A88A AD 37 09 LDA $0937 [$7E:0937] $80A88D 8D 15 09 STA $0915 [$7E:0915] $80A890 AB PLB $80A891 28 PLP $80A892 6B RTL } ;;; Handle scrolling when moving and triggered scrolling down ;;; { $80A893 08 PHP $80A894 8B PHB $80A895 E2 20 SEP #$20 $80A897 A9 8F LDA #$8F ;\ $80A899 48 PHA ;} DB = $8F $80A89A AB PLB ;/ $80A89B C2 30 REP #$30 $80A89D AD 15 09 LDA $0915 [$7E:0915] ;\ $80A8A0 8D 39 09 STA $0939 [$7E:0939] ;} $0939 = layer 1 Y position $80A8A3 A0 00 00 LDY #$0000 ; Y = 0 $80A8A6 E2 20 SEP #$20 ;\ $80A8A8 AD 16 09 LDA $0916 [$7E:0916] ;| $80A8AB 8D 02 42 STA $4202 [$7E:4202] ;| $80A8AE AD A9 07 LDA $07A9 [$7E:07A9] ;| $80A8B1 8D 03 42 STA $4203 [$7E:4203] ;| $80A8B4 C2 20 REP #$20 ;| $80A8B6 AD 11 09 LDA $0911 [$7E:0911] ;| $80A8B9 18 CLC ;| $80A8BA 69 80 00 ADC #$0080 ;| $80A8BD EB XBA ;} If layer 1 position + 1/2 screen right's scroll != 1: return $80A8BE 29 FF 00 AND #$00FF ;| $80A8C1 18 CLC ;| $80A8C2 6D 16 42 ADC $4216 [$7E:4216] ;| $80A8C5 85 14 STA $14 [$7E:0014] ;| $80A8C7 AA TAX ;| $80A8C8 BF 20 CD 7E LDA $7ECD20,x[$7E:CD20] ;| $80A8CC 29 FF 00 AND #$00FF ;| $80A8CF C9 01 00 CMP #$0001 ;| $80A8D2 F0 03 BEQ $03 [$A8D7] ;/ $80A8D4 A0 1F 00 LDY #$001F ; Y = 1Fh $80A8D7 8C 33 09 STY $0933 [$7E:0933] ; $0933 = Y $80A8DA AD 0E 0B LDA $0B0E [$7E:0B0E] ;\ $80A8DD CD 15 09 CMP $0915 [$7E:0915] ;| $80A8E0 10 09 BPL $09 [$A8EB] ;| $80A8E2 AD 0E 0B LDA $0B0E [$7E:0B0E] ;} Cap layer 1 Y position to 'ideal' layer 1 Y position $80A8E5 8D 15 09 STA $0915 [$7E:0915] ;| $80A8E8 9C 13 09 STZ $0913 [$7E:0913] ;/ $80A8EB AD AB 07 LDA $07AB [$7E:07AB] ;\ $80A8EE 3A DEC A ;| $80A8EF EB XBA ;| $80A8F0 18 CLC ;} $0937 = room height - 1 screen + [$0933] $80A8F1 6D 33 09 ADC $0933 [$7E:0933] ;| $80A8F4 8D 37 09 STA $0937 [$7E:0937] ;/ $80A8F7 CD 15 09 CMP $0915 [$7E:0915] ;\ $80A8FA 90 22 BCC $22 [$A91E] ;} If [$0937] >= layer 1 Y position: $80A8FC A5 14 LDA $14 [$7E:0014] ;\ $80A8FE 18 CLC ;| $80A8FF 6D A9 07 ADC $07A9 [$7E:07A9] ;| $80A902 AA TAX ;| $80A903 BF 20 CD 7E LDA $7ECD20,x[$7E:CD21] ;| $80A907 29 FF 00 AND #$00FF ;| $80A90A D0 27 BNE $27 [$A933] ;} $0937 = layer 1 position + 1/2 screen right's scroll + 1 screen down != 1: return $80A90C AD 15 09 LDA $0915 [$7E:0915] ;| $80A90F 29 00 FF AND #$FF00 ;| $80A912 18 CLC ;| $80A913 6D 33 09 ADC $0933 [$7E:0933] ;| $80A916 8D 37 09 STA $0937 [$7E:0937] ;/ $80A919 CD 15 09 CMP $0915 [$7E:0915] ;\ $80A91C B0 15 BCS $15 [$A933] ;} If [$0937] < layer 1 Y postion: $80A91E AD 39 09 LDA $0939 [$7E:0939] ;\ $80A921 38 SEC ;| $80A922 ED A6 0D SBC $0DA6 [$7E:0DA6] ;} A = [$0939] - absolute distance moved Y - 3 $80A925 E9 02 00 SBC #$0002 ;/ $80A928 CD 37 09 CMP $0937 [$7E:0937] ;\ $80A92B 10 03 BPL $03 [$A930] ;} If A < [$0933]: $80A92D AD 37 09 LDA $0937 [$7E:0937] ; Layer 1 Y position = [$0933] $80A930 8D 15 09 STA $0915 [$7E:0915] $80A933 AB PLB $80A934 28 PLP $80A935 6B RTL } ;;; Handle scrolling when moving and triggered scrolling up ;;; { $80A936 08 PHP $80A937 8B PHB $80A938 E2 20 SEP #$20 $80A93A A9 8F LDA #$8F ;\ $80A93C 48 PHA ;} DB = $8F $80A93D AB PLB ;/ $80A93E C2 30 REP #$30 $80A940 AD 15 09 LDA $0915 [$7E:0915] ;\ $80A943 8D 39 09 STA $0939 [$7E:0939] ;} $0939 = layer 1 Y position $80A946 CD 0E 0B CMP $0B0E [$7E:0B0E] ;\ $80A949 10 09 BPL $09 [$A954] ;| $80A94B AD 0E 0B LDA $0B0E [$7E:0B0E] ;} Cap layer 1 Y position to 'ideal' layer 1 Y position $80A94E 8D 15 09 STA $0915 [$7E:0915] ;| $80A951 9C 13 09 STZ $0913 [$7E:0913] ;/ $80A954 AD 15 09 LDA $0915 [$7E:0915] ;\ $80A957 10 05 BPL $05 [$A95E] ;} Cap layer 1 Y position to 0 $80A959 9C 15 09 STZ $0915 [$7E:0915] ;/ $80A95C 80 4B BRA $4B [$A9A9] ; If reached cap: return $80A95E E2 20 SEP #$20 ;\ $80A960 AD 16 09 LDA $0916 [$7E:0916] ;| $80A963 8D 02 42 STA $4202 [$7E:4202] ;| $80A966 AD A9 07 LDA $07A9 [$7E:07A9] ;| $80A969 8D 03 42 STA $4203 [$7E:4203] ;| $80A96C C2 20 REP #$20 ;| $80A96E AD 11 09 LDA $0911 [$7E:0911] ;| $80A971 18 CLC ;| $80A972 69 80 00 ADC #$0080 ;} If layer 1 position + 1/2 screen right's scroll != 0: return $80A975 EB XBA ;| $80A976 29 FF 00 AND #$00FF ;| $80A979 18 CLC ;| $80A97A 6D 16 42 ADC $4216 [$7E:4216] ;| $80A97D AA TAX ;| $80A97E BF 20 CD 7E LDA $7ECD20,x[$7E:CD20] ;| $80A982 29 FF 00 AND #$00FF ;| $80A985 D0 22 BNE $22 [$A9A9] ;/ $80A987 AD 15 09 LDA $0915 [$7E:0915] ;\ $80A98A 29 00 FF AND #$FF00 ;| $80A98D 18 CLC ;} $0933 = layer 1 Y position rounded up to next screen $80A98E 69 00 01 ADC #$0100 ;| $80A991 8D 33 09 STA $0933 [$7E:0933] ;/ $80A994 AD 39 09 LDA $0939 [$7E:0939] ;\ $80A997 18 CLC ;| $80A998 6D A6 0D ADC $0DA6 [$7E:0DA6] ;} A = [$0939] + absolute distance moved X + 3 $80A99B 69 02 00 ADC #$0002 ;/ $80A99E CD 33 09 CMP $0933 [$7E:0933] ;\ $80A9A1 90 03 BCC $03 [$A9A6] ;} If A >= [$0933]: $80A9A3 AD 33 09 LDA $0933 [$7E:0933] ; Layer 1 Y position = [$0933] $80A9A6 8D 15 09 STA $0915 [$7E:0915] ; Else: layer 1 Y position = A $80A9A9 AB PLB $80A9AA 28 PLP $80A9AB 6B RTL } ;;; Debug scroll position save/loading ;;; { $80A9AC A5 91 LDA $91 [$00:0091] ;\ $80A9AE 29 40 00 AND #$0040 ;} If controller 2 newly pressed X: $80A9B1 F0 03 BEQ $03 [$A9B6] ;/ $80A9B3 EE D3 05 INC $05D3 [$82:05D3] ; Increment $05D3 $80A9B6 AD D3 05 LDA $05D3 [$82:05D3] ;\ $80A9B9 4A LSR A ;} If $05D3 set: $80A9BA 90 0D BCC $0D [$A9C9] ;/ $80A9BC AD D5 05 LDA $05D5 [$82:05D5] ;\ $80A9BF 8D 11 09 STA $0911 [$82:0911] ;} Restore X-Scroll position $80A9C2 AD D7 05 LDA $05D7 [$82:05D7] ;\ $80A9C5 8D 15 09 STA $0915 [$82:0915] ;} Restore Y-Scroll position $80A9C8 6B RTL ; (Else, $05D3 clear:) $80A9C9 AD 11 09 LDA $0911 [$82:0911] ;\ $80A9CC 8D D5 05 STA $05D5 [$82:05D5] ;} Mirror X-Scroll position $80A9CF AD 15 09 LDA $0915 [$82:0915] ;\ $80A9D2 8D D7 05 STA $05D7 [$82:05D7] ;} Mirror Y-Scroll position $80A9D5 6B RTL } ;;; Update background data column ;;; { $80A9D6 A2 1C 00 LDX #$001C ; X = 1Ch $80A9D9 80 03 BRA $03 [$A9DE] ; Branch to $A9DE } ;;; Update level data column ;;; { $80A9DB A2 00 00 LDX #$0000 ; X = 0 ; $aaaa/bbbb means $aaaa if level data and $bbbb if background data $80A9DE AD 83 07 LDA $0783 [$7E:0783] ;\ $80A9E1 F0 01 BEQ $01 [$A9E4] ;} If [$0783] == 0: return $80A9E3 60 RTS ;/ $80A9E4 08 PHP $80A9E5 E2 20 SEP #$20 ;\ $80A9E7 AD A5 07 LDA $07A5 [$7E:07A5] ;| $80A9EA 8D 02 42 STA $4202 [$7E:4202] ;| $80A9ED AD 92 09 LDA $0992 [$7E:0992] ;| $80A9F0 8D 03 42 STA $4203 [$7E:4203] ;| $80A9F3 8B PHB ;| $80A9F4 C2 30 REP #$30 ;| $80A9F6 AD 90 09 LDA $0990 [$7E:0990] ;| $80A9F9 18 CLC ;} A = offset of blocks to update in $7F $80A9FA 6D 16 42 ADC $4216 [$7E:4216] ;| $80A9FD 0A ASL A ;| $80A9FE 18 CLC ;| $80A9FF 69 02 00 ADC #$0002 ;| $80AA02 9B TXY ;| $80AA03 F0 04 BEQ $04 [$AA09] ;| $80AA05 18 CLC ;| $80AA06 69 00 96 ADC #$9600 ;/ $80AA09 85 36 STA $36 [$7E:0036] ;\ $80AA0B A9 7F 00 LDA #$007F ;} $36 = tiles to update address $80AA0E 85 38 STA $38 [$7E:0038] ;/ $80AA10 AD 96 09 LDA $0996 [$7E:0996] ;\ $80AA13 0A ASL A ;| $80AA14 0A ASL A ;} $0958/0974 = (VRAM blocks to update Y position & 0Fh) * 4 $80AA15 29 3C 00 AND #$003C ;| $80AA18 9D 58 09 STA $0958,x[$7E:0958] ;/ $80AA1B 49 3F 00 EOR #$003F ;\ $80AA1E 1A INC A ;} $0956/0972 = (10h - (VRAM blocks to update Y position & 0Fh)) * 4 $80AA1F 9D 56 09 STA $0956,x[$7E:0956] ;/ $80AA22 E2 20 SEP #$20 ;\ $80AA24 AD 96 09 LDA $0996 [$7E:0996] ;| $80AA27 29 0F AND #$0F ;| $80AA29 8D 02 42 STA $4202 [$7E:4202] ;| $80AA2C A9 40 LDA #$40 ;| $80AA2E 8D 03 42 STA $4203 [$7E:4203] ;| $80AA31 C2 20 REP #$20 ;| $80AA33 AD 94 09 LDA $0994 [$7E:0994] ;| $80AA36 29 1F 00 AND #$001F ;| $80AA39 8D 35 09 STA $0935 [$7E:0935] ; $0935 = VRAM blocks to update X position & 1Fh $80AA3C 0A ASL A ;} $0933 = VRAM blocks to update VRAM offset $80AA3D 18 CLC ;| $80AA3E 6D 16 42 ADC $4216 [$7E:4216] ;| $80AA41 8D 33 09 STA $0933 [$7E:0933] ;/ $80AA44 A9 00 50 LDA #$5000 ; A = VRAM map 1st screen base address $80AA47 AC 35 09 LDY $0935 [$7E:0935] ;\ $80AA4A C0 10 00 CPY #$0010 ;} If [$0935] >= 10h: $80AA4D 90 03 BCC $03 [$AA52] ;/ $80AA4F A9 E0 53 LDA #$53E0 ; A = VRAM map 2nd screen base address $80AA52 9B TXY ;\ $80AA53 F0 04 BEQ $04 [$AA59] ;} If X != 0: $80AA55 38 SEC ;\ $80AA56 ED 8E 09 SBC $098E [$7E:098E] ;} A -= [$098E] (probably to do with Layer2Scroll) $80AA59 8D 37 09 STA $0937 [$7E:0937] ; $0937 = A $80AA5C 18 CLC ;\ $80AA5D 6D 33 09 ADC $0933 [$7E:0933] ;} $095A/0976 = VRAM blocks to update VRAM address $80AA60 9D 5A 09 STA $095A,x[$7E:095A] ;/ $80AA63 AD 37 09 LDA $0937 [$7E:0937] ;\ $80AA66 18 CLC ;| $80AA67 6D 35 09 ADC $0935 [$7E:0935] ;} $095C/0978 = [$0937] + [0935]*2 (?) $80AA6A 6D 35 09 ADC $0935 [$7E:0935] ;| $80AA6D 9D 5C 09 STA $095C,x[$7E:095C] ;/ $80AA70 A9 C8 C8 LDA #$C8C8 ; A = new level tilemap base address $80AA73 A0 00 00 LDY #$0000 ; Y = 0 $80AA76 E0 00 00 CPX #$0000 ;\ $80AA79 F0 06 BEQ $06 [$AA81] ;} If X != 0: $80AA7B A9 D0 C9 LDA #$C9D0 ; A = new background tilemap base address $80AA7E A0 08 01 LDY #$0108 ; Y = 108h $80AA81 18 CLC ;\ $80AA82 7D 56 09 ADC $0956,x[$7E:0956] ;} A += size of VRAM update $80AA85 9D 5E 09 STA $095E,x[$7E:095E] ; $095E/097A = A $80AA88 18 CLC ;\ $80AA89 69 40 00 ADC #$0040 ;} $0960/097C = A + 40h $80AA8C 9D 60 09 STA $0960,x[$7E:0960] ;/ $80AA8F 8C 37 09 STY $0937 [$7E:0937] ; $0937 = Y $80AA92 E2 20 SEP #$20 ;\ $80AA94 A9 7E LDA #$7E ;| $80AA96 48 PHA ;} DB = $7E $80AA97 AB PLB ;| $80AA98 C2 20 REP #$20 ;/ $80AA9A DA PHX ; Push X $80AA9B A0 00 00 LDY #$0000 ; Y = 0 (nth row offset) $80AA9E A9 10 00 LDA #$0010 ;\ $80AAA1 8D 39 09 STA $0939 [$7E:0939] ;} $0939 = 10h (counter for following loop) $80AAA4 B7 36 LDA [$36],y[$7F:0002] ; A = tile to update in $7F $80AAA6 8D 3B 09 STA $093B [$7E:093B] ; $093B = A $80AAA9 29 FF 03 AND #$03FF ;\ $80AAAC 0A ASL A ;| $80AAAD 0A ASL A ;} X = tile number of block * 8 $80AAAE 0A ASL A ;| $80AAAF AA TAX ;/ $80AAB0 5A PHY ; Push Y $80AAB1 AC 37 09 LDY $0937 [$7E:0937] ; Y = [$0937] $80AAB4 AD 3B 09 LDA $093B [$7E:093B] ;\ $80AAB7 29 00 0C AND #$0C00 ;} If block has no flip: $80AABA D0 1B BNE $1B [$AAD7] ;/ $80AABC BD 00 A0 LDA $A000,x[$7E:A010] ;\ $80AABF 99 C8 C8 STA $C8C8,y[$7E:C8C8] ;} Copy top-left VRAM tile of the block $80AAC2 BD 02 A0 LDA $A002,x[$7E:A012] ;\ $80AAC5 99 08 C9 STA $C908,y[$7E:C908] ;} Copy top-right VRAM tile of the block $80AAC8 BD 04 A0 LDA $A004,x[$7E:A014] ;\ $80AACB 99 CA C8 STA $C8CA,y[$7E:C8CA] ;} Copy bottom-left VRAM tile of the block $80AACE BD 06 A0 LDA $A006,x[$7E:A016] ;\ $80AAD1 99 0A C9 STA $C90A,y[$7E:C90A] ;} Copy bottom-right VRAM tile of the block $80AAD4 4C 51 AB JMP $AB51 [$80:AB51] ; Next! $80AAD7 C9 00 04 CMP #$0400 ;\ $80AADA D0 26 BNE $26 [$AB02] ;} Else if block has only horizontal flip: $80AADC BD 02 A0 LDA $A002,x[$7E:A42A] ;\ $80AADF 49 00 40 EOR #$4000 ;| $80AAE2 99 C8 C8 STA $C8C8,y[$7E:C8E0] ;| $80AAE5 BD 00 A0 LDA $A000,x[$7E:A428] ;| $80AAE8 49 00 40 EOR #$4000 ;| $80AAEB 99 08 C9 STA $C908,y[$7E:C920] ;| $80AAEE BD 06 A0 LDA $A006,x[$7E:A42E] ;} Copy the four VRAM tiles of the block, with horizontal flip $80AAF1 49 00 40 EOR #$4000 ;| $80AAF4 99 CA C8 STA $C8CA,y[$7E:C8E2] ;| $80AAF7 BD 04 A0 LDA $A004,x[$7E:A42C] ;| $80AAFA 49 00 40 EOR #$4000 ;| $80AAFD 99 0A C9 STA $C90A,y[$7E:C922] ;/ $80AB00 80 4F BRA $4F [$AB51] ; Next! $80AB02 C9 00 08 CMP #$0800 ;\ $80AB05 D0 26 BNE $26 [$AB2D] ;} Else if block has only vertical flip: $80AB07 BD 04 A0 LDA $A004,x[$7E:A00C] ;\ $80AB0A 49 00 80 EOR #$8000 ;| $80AB0D 99 C8 C8 STA $C8C8,y[$7E:C8DC] ;| $80AB10 BD 06 A0 LDA $A006,x[$7E:A00E] ;| $80AB13 49 00 80 EOR #$8000 ;| $80AB16 99 08 C9 STA $C908,y[$7E:C91C] ;| $80AB19 BD 00 A0 LDA $A000,x[$7E:A008] ;} Copy the four VRAM tiles of the block, with vertical flip $80AB1C 49 00 80 EOR #$8000 ;| $80AB1F 99 CA C8 STA $C8CA,y[$7E:C8DE] ;| $80AB22 BD 02 A0 LDA $A002,x[$7E:A00A] ;| $80AB25 49 00 80 EOR #$8000 ;| $80AB28 99 0A C9 STA $C90A,y[$7E:C91E] ;/ $80AB2B 80 24 BRA $24 [$AB51] ; Next! $80AB2D BD 06 A0 LDA $A006,x[$7E:A52E] ;\ Else: block has horizontal and vertical flips $80AB30 49 00 C0 EOR #$C000 ;| $80AB33 99 C8 C8 STA $C8C8,y[$7E:C8E8] ;| $80AB36 BD 04 A0 LDA $A004,x[$7E:A52C] ;| $80AB39 49 00 C0 EOR #$C000 ;| $80AB3C 99 08 C9 STA $C908,y[$7E:C928] ;| $80AB3F BD 02 A0 LDA $A002,x[$7E:A52A] ;} Copy the four VRAM tiles of the block, with horizontal and vertical flips $80AB42 49 00 C0 EOR #$C000 ;| $80AB45 99 CA C8 STA $C8CA,y[$7E:C8EA] ;| $80AB48 BD 00 A0 LDA $A000,x[$7E:A528] ;| $80AB4B 49 00 C0 EOR #$C000 ;| $80AB4E 99 0A C9 STA $C90A,y[$7E:C92A] ;/ $80AB51 C8 INY ;\ $80AB52 C8 INY ;| $80AB53 C8 INY ;} $0937 += 4 $80AB54 C8 INY ;| $80AB55 8C 37 09 STY $0937 [$7E:0937] ;/ $80AB58 68 PLA ;\ $80AB59 18 CLC ;| $80AB5A 6D A5 07 ADC $07A5 [$7E:07A5] ;} Y = next row offset $80AB5D 6D A5 07 ADC $07A5 [$7E:07A5] ;| $80AB60 A8 TAY ;/ $80AB61 CE 39 09 DEC $0939 [$7E:0939] ;\ $80AB64 F0 03 BEQ $03 [$AB69] ;} If --$0939: loop back to $AAA4 $80AB66 4C A4 AA JMP $AAA4 [$80:AAA4] ; Loop for next tile $80AB69 FA PLX ; X = pulled X $80AB6A FE 62 09 INC $0962,x[$7E:0962] ; ++$0962/097E $80AB6D AB PLB $80AB6E 28 PLP $80AB6F 60 RTS } ;;; Update background data row ;;; { $80AB70 A2 1C 00 LDX #$001C ; X = 1Ch $80AB73 80 03 BRA $03 [$AB78] ; Branch to $AB78 } ;;; Update level data row ;;; { $80AB75 A2 00 00 LDX #$0000 ; X = 0 ; $aaaa/bbbb means $aaaa if BG1 and $bbbb if BG2 $80AB78 AD 83 07 LDA $0783 [$7E:0783] ;\ $80AB7B F0 01 BEQ $01 [$AB7E] ;} If [$0783] == 0: return $80AB7D 60 RTS ;/ $80AB7E 08 PHP $80AB7F E2 20 SEP #$20 ;\ $80AB81 AD A5 07 LDA $07A5 [$7E:07A5] ;| $80AB84 8D 02 42 STA $4202 [$7E:4202] ;| $80AB87 AD 92 09 LDA $0992 [$7E:0992] ;| $80AB8A 8D 03 42 STA $4203 [$7E:4203] ;| $80AB8D 8B PHB ;| $80AB8E C2 30 REP #$30 ;| $80AB90 AD 90 09 LDA $0990 [$7E:0990] ;| $80AB93 18 CLC ;} A = offset of blocks to update in $7F $80AB94 6D 16 42 ADC $4216 [$7E:4216] ;| $80AB97 0A ASL A ;| $80AB98 18 CLC ;| $80AB99 69 02 00 ADC #$0002 ;| $80AB9C 9B TXY ;| $80AB9D F0 04 BEQ $04 [$ABA3] ;| $80AB9F 18 CLC ;| $80ABA0 69 00 96 ADC #$9600 ;/ $80ABA3 85 36 STA $36 [$7E:0036] ;\ $80ABA5 A9 7F 00 LDA #$007F ;} $36 = tiles to update address $80ABA8 85 38 STA $38 [$7E:0038] ;/ $80ABAA AD 94 09 LDA $0994 [$7E:0994] ;\ $80ABAD 29 0F 00 AND #$000F ;} $0933 = VRAM blocks to update X position & 0Fh $80ABB0 8D 33 09 STA $0933 [$7E:0933] ;/ $80ABB3 A9 10 00 LDA #$0010 ;\ $80ABB6 38 SEC ;| $80ABB7 ED 33 09 SBC $0933 [$7E:0933] ;| $80ABBA 0A ASL A ;} $0964/0980 = (10h - [$0933]) * 4 $80ABBB 0A ASL A ;| $80ABBC 9D 64 09 STA $0964,x[$7E:0964] ;/ $80ABBF AD 33 09 LDA $0933 [$7E:0933] ;\ $80ABC2 1A INC A ;| $80ABC3 0A ASL A ;} $0966/0982 = [$0933] $80ABC4 0A ASL A ;| $80ABC5 9D 66 09 STA $0966,x[$7E:0966] ;/ $80ABC8 E2 20 SEP #$20 ;\ $80ABCA AD 96 09 LDA $0996 [$7E:0996] ;| $80ABCD 29 0F AND #$0F ;| $80ABCF 8D 02 42 STA $4202 [$7E:4202] ;| $80ABD2 A9 40 LDA #$40 ;| $80ABD4 8D 03 42 STA $4203 [$7E:4203] ;| $80ABD7 C2 20 REP #$20 ;| $80ABD9 AD 94 09 LDA $0994 [$7E:0994] ;| $80ABDC 29 1F 00 AND #$001F ;| $80ABDF 8D 35 09 STA $0935 [$7E:0935] ; $0935 = VRAM blocks to update X position & 1Fh $80ABE2 0A ASL A ;} $0933 = VRAM blocks to update VRAM offset $80ABE3 18 CLC ;| $80ABE4 6D 16 42 ADC $4216 [$7E:4216] ;| $80ABE7 8D 33 09 STA $0933 [$7E:0933] ;/ $80ABEA A9 00 54 LDA #$5400 ;\ $80ABED 8D 37 09 STA $0937 [$7E:0937] ;} $0937 = $5400 $80ABF0 A9 00 50 LDA #$5000 ; A = VRAM map 1st screen base address $80ABF3 AC 35 09 LDY $0935 [$7E:0935] ;\ $80ABF6 C0 10 00 CPY #$0010 ;} If [$0935] >= 10h: $80ABF9 90 09 BCC $09 [$AC04] ;/ $80ABFB A9 00 50 LDA #$5000 ;\ $80ABFE 8D 37 09 STA $0937 [$7E:0937] ;} $0937 = $5000 $80AC01 A9 E0 53 LDA #$53E0 ; A = VRAM map 2nd screen base address $80AC04 9B TXY ;\ $80AC05 F0 04 BEQ $04 [$AC0B] ;} If X: $80AC07 38 SEC ;\ $80AC08 ED 8E 09 SBC $098E [$7E:098E] ;} A -= [$098E] (probably to do with Layer2Scroll) $80AC0B 18 CLC ;\ $80AC0C 6D 33 09 ADC $0933 [$7E:0933] ;} $0968/0984 = A + [$0933] $80AC0F 9D 68 09 STA $0968,x[$7E:0968] ;/ $80AC12 AD 37 09 LDA $0937 [$7E:0937] ; A = [$0937] $80AC15 9B TXY ;\ $80AC16 F0 04 BEQ $04 [$AC1C] ;} If X: $80AC18 38 SEC ;\ $80AC19 ED 8E 09 SBC $098E [$7E:098E] ;} A -= [$098E] (probably to do with Layer2Scroll) $80AC1C 18 CLC ;\ $80AC1D 6D 16 42 ADC $4216 [$7E:4216] ;} $096A/0986 = A + (VRAM blocks to update Y position & 0Fh) * 40h $80AC20 9D 6A 09 STA $096A,x[$7E:096A] ;/ $80AC23 A9 48 C9 LDA #$C948 ; A = new level tilemap base address $80AC26 A0 00 00 LDY #$0000 ; Y = 0 $80AC29 E0 00 00 CPX #$0000 ;\ $80AC2C F0 06 BEQ $06 [$AC34] ;} If X != 0: $80AC2E A9 50 CA LDA #$CA50 ; A = new background tilemap base address $80AC31 A0 08 01 LDY #$0108 ; Y = 108h $80AC34 18 CLC ;\ $80AC35 7D 64 09 ADC $0964,x[$7E:0964] ;} A += size of VRAM update $80AC38 9D 6C 09 STA $096C,x[$7E:096C] ; $096C/0988 = A $80AC3B 18 CLC ;\ $80AC3C 69 44 00 ADC #$0044 ;} $096E/098A = A + 44h $80AC3F 9D 6E 09 STA $096E,x[$7E:096E] ;/ $80AC42 8C 37 09 STY $0937 [$7E:0937] ; $0937 = Y $80AC45 E2 20 SEP #$20 ;\ $80AC47 A9 7E LDA #$7E ;| $80AC49 48 PHA ;} DB = $7E $80AC4A AB PLB ;| $80AC4B C2 20 REP #$20 ;/ $80AC4D DA PHX ; Push X $80AC4E A0 00 00 LDY #$0000 ; Y = 0 (nth row offset) $80AC51 A9 11 00 LDA #$0011 ;\ $80AC54 8D 39 09 STA $0939 [$7E:0939] ;} $0939 = 11h (counter for following loop) $80AC57 B7 36 LDA [$36],y[$7F:0202] ; A = tile to update in $7F $80AC59 8D 3B 09 STA $093B [$7E:093B] ; $093B = A $80AC5C 29 FF 03 AND #$03FF ;\ $80AC5F 0A ASL A ;| $80AC60 0A ASL A ;} X = tile number of block * 8 $80AC61 0A ASL A ;| $80AC62 AA TAX ;/ $80AC63 5A PHY ; Push Y $80AC64 AC 37 09 LDY $0937 [$7E:0937] ; Y = [$0937] $80AC67 AD 3B 09 LDA $093B [$7E:093B] ;\ $80AC6A 29 00 0C AND #$0C00 ;} If block has no flip: $80AC6D D0 1B BNE $1B [$AC8A] ;/ $80AC6F BD 00 A0 LDA $A000,x[$7E:A158] ;\ $80AC72 99 48 C9 STA $C948,y[$7E:C948] ;} Copy top-left VRAM tile of the block $80AC75 BD 02 A0 LDA $A002,x[$7E:A15A] ;\ $80AC78 99 4A C9 STA $C94A,y[$7E:C94A] ;} Copy top-right VRAM tile of the block $80AC7B BD 04 A0 LDA $A004,x[$7E:A15C] ;\ $80AC7E 99 8C C9 STA $C98C,y[$7E:C98C] ;} Copy bottom-left VRAM tile of the block $80AC81 BD 06 A0 LDA $A006,x[$7E:A15E] ;\ $80AC84 99 8E C9 STA $C98E,y[$7E:C98E] ;} Copy bottom-right VRAM tile of the block $80AC87 4C 04 AD JMP $AD04 [$80:AD04] ; Next! $80AC8A C9 00 04 CMP #$0400 ;\ $80AC8D D0 26 BNE $26 [$ACB5] ;} Else if block has only horizontal flip: $80AC8F BD 02 A0 LDA $A002,x[$7E:A172] ;\ $80AC92 49 00 40 EOR #$4000 ;| $80AC95 99 48 C9 STA $C948,y[$7E:C954] ;| $80AC98 BD 00 A0 LDA $A000,x[$7E:A170] ;| $80AC9B 49 00 40 EOR #$4000 ;| $80AC9E 99 4A C9 STA $C94A,y[$7E:C956] ;| $80ACA1 BD 06 A0 LDA $A006,x[$7E:A176] ;} Copy the four VRAM tiles of the block, with horizontal flip $80ACA4 49 00 40 EOR #$4000 ;| $80ACA7 99 8C C9 STA $C98C,y[$7E:C998] ;| $80ACAA BD 04 A0 LDA $A004,x[$7E:A174] ;| $80ACAD 49 00 40 EOR #$4000 ;| $80ACB0 99 8E C9 STA $C98E,y[$7E:C99A] ;/ $80ACB3 80 4F BRA $4F [$AD04] ; Next! $80ACB5 C9 00 08 CMP #$0800 ;\ $80ACB8 D0 26 BNE $26 [$ACE0] ;} Else if block has only vertical flip: $80ACBA BD 04 A0 LDA $A004,x[$7E:A17C] ;\ $80ACBD 49 00 80 EOR #$8000 ;| $80ACC0 99 48 C9 STA $C948,y[$7E:C950] ;| $80ACC3 BD 06 A0 LDA $A006,x[$7E:A17E] ;| $80ACC6 49 00 80 EOR #$8000 ;| $80ACC9 99 4A C9 STA $C94A,y[$7E:C952] ;| $80ACCC BD 00 A0 LDA $A000,x[$7E:A178] ;} Copy the four VRAM tiles of the block, with vertical flip $80ACCF 49 00 80 EOR #$8000 ;| $80ACD2 99 8C C9 STA $C98C,y[$7E:C994] ;| $80ACD5 BD 02 A0 LDA $A002,x[$7E:A17A] ;| $80ACD8 49 00 80 EOR #$8000 ;| $80ACDB 99 8E C9 STA $C98E,y[$7E:C996] ;/ $80ACDE 80 24 BRA $24 [$AD04] ; Next! $80ACE0 BD 06 A0 LDA $A006,x[$7E:A00E] ;\ Else: block has horizontal and vertical flips $80ACE3 49 00 C0 EOR #$C000 ;| $80ACE6 99 48 C9 STA $C948,y[$7E:C968] ;| $80ACE9 BD 04 A0 LDA $A004,x[$7E:A00C] ;| $80ACEC 49 00 C0 EOR #$C000 ;| $80ACEF 99 4A C9 STA $C94A,y[$7E:C96A] ;| $80ACF2 BD 02 A0 LDA $A002,x[$7E:A00A] ;} Copy the four VRAM tiles of the block, with horizontal and vertical flips $80ACF5 49 00 C0 EOR #$C000 ;| $80ACF8 99 8C C9 STA $C98C,y[$7E:C9AC] ;| $80ACFB BD 00 A0 LDA $A000,x[$7E:A008] ;| $80ACFE 49 00 C0 EOR #$C000 ;| $80AD01 99 8E C9 STA $C98E,y[$7E:C9AE] ;/ $80AD04 C8 INY ;\ $80AD05 C8 INY ;| $80AD06 C8 INY ;} $0937 += 4 $80AD07 C8 INY ;| $80AD08 8C 37 09 STY $0937 [$7E:0937] ;/ $80AD0B 7A PLY ;\ $80AD0C C8 INY ;} Y = next block offset $80AD0D C8 INY ;/ $80AD0E CE 39 09 DEC $0939 [$7E:0939] ;\ $80AD11 F0 03 BEQ $03 [$AD16] ;} If --$0939: loop back to $AAA4 $80AD13 4C 57 AC JMP $AC57 [$80:AC57] ; Loop for next tile $80AD16 FA PLX ; X = pulled X $80AD17 FE 70 09 INC $0970,x[$7E:0970] ; ++$0970/098C $80AD1A AB PLB $80AD1B 28 PLP $80AD1C 60 RTS } ;;; Run to 'Fix' doors moving up; redraws top row of blocks ;;; { $80AD1D 9C 25 09 STZ $0925 [$7E:0925] ; Clear number of times screen has scrolled $80AD20 20 BB A4 JSR $A4BB [$80:A4BB] ; Calculate blocks scrolled $80AD23 20 10 AE JSR $AE10 [$80:AE10] ; Save number of blocks scrolled $80AD26 EE 01 09 INC $0901 [$7E:0901] ; Increment previous number of blocks layer 1 was scrolled vertically $80AD29 EE 05 09 INC $0905 [$7E:0905] ; Increment previous number of blocks layer 2 was scrolled vertically $80AD2C 20 89 AF JSR $AF89 [$80:AF89] ; Redraw top row of blocks $80AD2F 6B RTL } ;;; Follow door transition ;;; { $80AD30 C2 30 REP #$30 $80AD32 AD 27 09 LDA $0927 [$7E:0927] ;\ $80AD35 8D 11 09 STA $0911 [$7E:0911] ;} Layer 1 X = X position of door destination $80AD38 AD 29 09 LDA $0929 [$7E:0929] ;\ $80AD3B 8D 15 09 STA $0915 [$7E:0915] ;} Layer 1 Y = Y position of door destination $80AD3E AD 91 07 LDA $0791 [$7E:0791] ;\ $80AD41 29 03 00 AND #$0003 ;| $80AD44 0A ASL A ;} Branch to door direction dependant code $80AD45 AA TAX ;| $80AD46 FC 08 AE JSR ($AE08,x)[$80:AD4A] ;/ $80AD49 6B RTL } ;;; Door transition - right ;;; { $80AD4A 20 F9 A2 JSR $A2F9 [$80:A2F9] ; Calculate layer 2 X position $80AD4D 38 SEC ;\ $80AD4E E9 00 01 SBC #$0100 ;} Layer 2 X position -= 100h $80AD51 8D 17 09 STA $0917 [$7E:0917] ;/ $80AD54 20 3A A3 JSR $A33A [$80:A33A] ; Calculate layer 2 Y position $80AD57 AD 11 09 LDA $0911 [$7E:0911] ;\ $80AD5A 38 SEC ;| $80AD5B E9 00 01 SBC #$0100 ;} Layer 1 X position -= 100h $80AD5E 8D 11 09 STA $0911 [$7E:0911] ;/ $80AD61 20 29 AE JSR $AE29 [$80:AE29] ; Update BG scroll offsets $80AD64 20 BB A4 JSR $A4BB [$80:A4BB] ; Calculate blocks scrolled $80AD67 20 10 AE JSR $AE10 [$80:AE10] ; Save number of blocks scrolled $80AD6A CE FF 08 DEC $08FF [$7E:08FF] ; Decrement previous number of blocks layer 1 was scrolled horizontally $80AD6D CE 03 09 DEC $0903 [$7E:0903] ; Decrement previous number of blocks layer 2 was scrolled horizontally $80AD70 20 7E AE JSR $AE7E [$80:AE7E] $80AD73 60 RTS } ;;; Door transition - left ;;; { $80AD74 20 F9 A2 JSR $A2F9 [$80:A2F9] ; Calculate layer 2 X position $80AD77 18 CLC ;\ $80AD78 69 00 01 ADC #$0100 ;} Layer 2 X position += 100h $80AD7B 8D 17 09 STA $0917 [$7E:0917] ;/ $80AD7E 20 3A A3 JSR $A33A [$80:A33A] ; Calculate layer 2 Y position $80AD81 AD 11 09 LDA $0911 [$7E:0911] ;\ $80AD84 18 CLC ;| $80AD85 69 00 01 ADC #$0100 ;} Layer 1 X position -= 100h $80AD88 8D 11 09 STA $0911 [$7E:0911] ;/ $80AD8B 20 29 AE JSR $AE29 [$80:AE29] ; Update BG scroll offsets $80AD8E 20 BB A4 JSR $A4BB [$80:A4BB] ; Calculate blocks scrolled $80AD91 20 10 AE JSR $AE10 [$80:AE10] ; Save number of blocks scrolled $80AD94 EE FF 08 INC $08FF [$7E:08FF] ; Increment previous number of blocks layer 1 was scrolled horizontally $80AD97 EE 03 09 INC $0903 [$7E:0903] ; Increment previous number of blocks layer 2 was scrolled horizontally $80AD9A 20 C2 AE JSR $AEC2 [$80:AEC2] $80AD9D 60 RTS } ;;; Door transition - down ;;; { $80AD9E 20 F9 A2 JSR $A2F9 [$80:A2F9] ; Calculate layer 2 X position $80ADA1 20 3A A3 JSR $A33A [$80:A33A] ; Calculate layer 2 Y position $80ADA4 38 SEC ;\ $80ADA5 E9 E0 00 SBC #$00E0 ;} Layer 2 Y position -= E0h $80ADA8 8D 19 09 STA $0919 [$7E:0919] ;/ $80ADAB AD 15 09 LDA $0915 [$7E:0915] ;\ $80ADAE 38 SEC ;| $80ADAF E9 E0 00 SBC #$00E0 ;} Layer 1 Y position -= E0h $80ADB2 8D 15 09 STA $0915 [$7E:0915] ;/ $80ADB5 20 29 AE JSR $AE29 [$80:AE29] ; Update BG scroll offsets $80ADB8 20 BB A4 JSR $A4BB [$80:A4BB] ; Calculate blocks scrolled $80ADBB 20 10 AE JSR $AE10 [$80:AE10] ; Save number of blocks scrolled $80ADBE CE 01 09 DEC $0901 [$7E:0901] ; Decrement previous number of blocks layer 1 was scrolled vertically $80ADC1 CE 05 09 DEC $0905 [$7E:0905] ; Decrement previous number of blocks layer 2 was scrolled vertically $80ADC4 20 02 AF JSR $AF02 [$80:AF02] $80ADC7 60 RTS } ;;; Door transition - up ;;; { $80ADC8 20 F9 A2 JSR $A2F9 [$80:A2F9] ; Calculate layer 2 X position $80ADCB AD 15 09 LDA $0915 [$7E:0915] ;\ $80ADCE 48 PHA ;| $80ADCF 18 CLC ;} Use (layer 1 Y position + 1Fh) for layer 2 Y position calculation $80ADD0 69 1F 00 ADC #$001F ;| $80ADD3 8D 15 09 STA $0915 [$7E:0915] ;/ $80ADD6 20 3A A3 JSR $A33A [$80:A33A] ; Calculate layer 2 Y position $80ADD9 18 CLC ;\ $80ADDA 69 E0 00 ADC #$00E0 ;} Layer 2 Y position += E0h $80ADDD 8D 19 09 STA $0919 [$7E:0919] ;/ $80ADE0 68 PLA ;\ $80ADE1 18 CLC ;| $80ADE2 69 00 01 ADC #$0100 ;} Layer 1 Y position += 100h $80ADE5 8D 15 09 STA $0915 [$7E:0915] ;/ $80ADE8 20 29 AE JSR $AE29 [$80:AE29] ; Update BG scroll offsets $80ADEB AD 29 09 LDA $0929 [$7E:0929] ;\ $80ADEE 18 CLC ;| $80ADEF 69 20 00 ADC #$0020 ;} Y position of door destination += 20h $80ADF2 8D 29 09 STA $0929 [$7E:0929] ;/ $80ADF5 20 BB A4 JSR $A4BB [$80:A4BB] ; Calculate blocks scrolled $80ADF8 20 10 AE JSR $AE10 [$80:AE10] ; Save number of blocks scrolled $80ADFB EE 01 09 INC $0901 [$7E:0901] ; Increment previous number of blocks layer 1 was scrolled vertically $80ADFE EE 05 09 INC $0905 [$7E:0905] ; Increment previous number of blocks layer 2 was scrolled vertically $80AE01 CE 15 09 DEC $0915 [$7E:0915] ; Decrement layer 1 Y position $80AE04 20 89 AF JSR $AF89 [$80:AF89] $80AE07 60 RTS } ;;; Pointers to door transition code ;;; { $80AE08 dw AD4A, AD74, AD9E, ADC8 } ;;; Save number of blocks scrolled ;;; { $80AE10 AD F7 08 LDA $08F7 [$7E:08F7] ;\ $80AE13 8D FF 08 STA $08FF [$7E:08FF] ;} Save number of blocks layer 1 was scrolled horizontally $80AE16 AD FB 08 LDA $08FB [$7E:08FB] ;\ $80AE19 8D 03 09 STA $0903 [$7E:0903] ;} Save number of blocks layer 2 was scrolled horizontally $80AE1C AD F9 08 LDA $08F9 [$7E:08F9] ;\ $80AE1F 8D 01 09 STA $0901 [$7E:0901] ;} Save number of blocks layer 1 was scrolled vertically $80AE22 AD FD 08 LDA $08FD [$7E:08FD] ;\ $80AE25 8D 05 09 STA $0905 [$7E:0905] ;} Save number of blocks layer 2 was scrolled vertically $80AE28 60 RTS } ;;; Update BG scroll offsets ;;; { $80AE29 A5 B1 LDA $B1 [$7E:00B1] ;\ $80AE2B 38 SEC ;| $80AE2C ED 11 09 SBC $0911 [$7E:0911] ;} BG1 X scroll offset = BG1 X scroll - layer 1 X position $80AE2F 8D 1D 09 STA $091D [$7E:091D] ;/ $80AE32 A5 B3 LDA $B3 [$7E:00B3] ;\ $80AE34 38 SEC ;| $80AE35 ED 15 09 SBC $0915 [$7E:0915] ;} BG1 Y scroll offset = BG1 Y scroll - layer 1 Y position $80AE38 8D 1F 09 STA $091F [$7E:091F] ;/ $80AE3B A5 B5 LDA $B5 [$7E:00B5] ;\ $80AE3D 38 SEC ;| $80AE3E ED 11 09 SBC $0911 [$7E:0911] ;} BG2 X scroll offset = BG2 X scroll - layer 1 X position $80AE41 8D 21 09 STA $0921 [$7E:0921] ;/ $80AE44 A5 B7 LDA $B7 [$7E:00B7] ;\ $80AE46 38 SEC ;| $80AE47 ED 15 09 SBC $0915 [$7E:0915] ;} BG2 Y scroll offset = BG2 Y scroll - layer 1 Y position $80AE4A 8D 23 09 STA $0923 [$7E:0923] ;/ $80AE4D 60 RTS } ;;; Follow door transition ;;; { $80AE4E 08 PHP $80AE4F 8B PHB $80AE50 4B PHK $80AE51 AB PLB $80AE52 C2 30 REP #$30 $80AE54 AD 91 07 LDA $0791 [$7E:0791] ;\ $80AE57 29 03 00 AND #$0003 ;| $80AE5A 0A ASL A ;} Branch to door transition dependant code $80AE5B AA TAX ;| $80AE5C FC 76 AE JSR ($AE76,x)[$80:AE7E] ;/ $80AE5F 90 12 BCC $12 [$AE73] ; If carry set: $80AE61 AD 27 09 LDA $0927 [$7E:0927] ;\ $80AE64 8D 11 09 STA $0911 [$7E:0911] ;} Layer 1 X position = X position of door destination $80AE67 AD 29 09 LDA $0929 [$7E:0929] ;\ $80AE6A 8D 15 09 STA $0915 [$7E:0915] ;} Layer 1 Y position = Y position of door destination $80AE6D A9 00 80 LDA #$8000 ;\ $80AE70 0C 31 09 TSB $0931 [$7E:0931] ;} $0931 |= 8000h (or $0932 |= 80h) $80AE73 AB PLB $80AE74 28 PLP $80AE75 6B RTL } ;;; Pointers to door transition code ;;; { $80AE76 dw AE7E, AEC2, AF02, AF89 } ;;; Door transition - right ;;; { $80AE7E AE 25 09 LDX $0925 [$7E:0925] ;\ $80AE81 DA PHX ;} Save number of times screen has scrolled $80AE82 AD F8 0A LDA $0AF8 [$7E:0AF8] ;\ $80AE85 18 CLC ;| $80AE86 6D 2B 09 ADC $092B [$7E:092B] ;} Samus X sub-position += door transition sub-speed $80AE89 8D F8 0A STA $0AF8 [$7E:0AF8] ;/ $80AE8C AD F6 0A LDA $0AF6 [$7E:0AF6] ;\ $80AE8F 6D 2D 09 ADC $092D [$7E:092D] ;} Samus X position += door transition speed $80AE92 8D F6 0A STA $0AF6 [$7E:0AF6] ;/ $80AE95 8D 10 0B STA $0B10 [$7E:0B10] ; Samus previous X position = Samus X position $80AE98 AD 11 09 LDA $0911 [$7E:0911] ;\ $80AE9B 18 CLC ;| $80AE9C 69 04 00 ADC #$0004 ;} Layer 1 X position += 4 $80AE9F 8D 11 09 STA $0911 [$7E:0911] ;/ $80AEA2 AD 17 09 LDA $0917 [$7E:0917] ;\ $80AEA5 18 CLC ;| $80AEA6 69 04 00 ADC #$0004 ;} Layer 2 X position += 4 $80AEA9 8D 17 09 STA $0917 [$7E:0917] ;/ $80AEAC 22 A0 A3 80 JSL $80A3A0[$80:A3A0] ; Updates only BG1 when scrolling $80AEB0 FA PLX ;\ $80AEB1 E8 INX ;} Increment number of times screen has scrolled $80AEB2 8E 25 09 STX $0925 [$7E:0925] ;/ $80AEB5 E0 40 00 CPX #$0040 ;\ $80AEB8 D0 06 BNE $06 [$AEC0] ;} If number of times screen has scrolled == 40h: $80AEBA 22 A0 A3 80 JSL $80A3A0[$80:A3A0] ; Updates only BG1 when scrolling $80AEBE 38 SEC ; Return carry set $80AEBF 60 RTS $80AEC0 18 CLC ; Else: return carry clear $80AEC1 60 RTS } ;;; Door transition - left ;;; { $80AEC2 AE 25 09 LDX $0925 [$7E:0925] ;\ $80AEC5 DA PHX ;} Save number of times screen has scrolled $80AEC6 AD F8 0A LDA $0AF8 [$7E:0AF8] ;\ $80AEC9 38 SEC ;| $80AECA ED 2B 09 SBC $092B [$7E:092B] ;} Samus X sub-position -= door transition sub-speed $80AECD 8D F8 0A STA $0AF8 [$7E:0AF8] ;/ $80AED0 AD F6 0A LDA $0AF6 [$7E:0AF6] ;\ $80AED3 ED 2D 09 SBC $092D [$7E:092D] ;} Samus X position -= door transition speed $80AED6 8D F6 0A STA $0AF6 [$7E:0AF6] ;/ $80AED9 8D 10 0B STA $0B10 [$7E:0B10] ; Samus previous X position = Samus X position $80AEDC AD 11 09 LDA $0911 [$7E:0911] ;\ $80AEDF 38 SEC ;| $80AEE0 E9 04 00 SBC #$0004 ;} Layer 1 X position -= 4 $80AEE3 8D 11 09 STA $0911 [$7E:0911] ;/ $80AEE6 AD 17 09 LDA $0917 [$7E:0917] ;\ $80AEE9 38 SEC ;| $80AEEA E9 04 00 SBC #$0004 ;} Layer 2 X position -= 4 $80AEED 8D 17 09 STA $0917 [$7E:0917] ;/ $80AEF0 22 A0 A3 80 JSL $80A3A0[$80:A3A0] ; Updates only BG1 when scrolling $80AEF4 FA PLX ;\ $80AEF5 E8 INX ;} Increment number of times screen has scrolled $80AEF6 8E 25 09 STX $0925 [$7E:0925] ;/ $80AEF9 E0 40 00 CPX #$0040 ;\ $80AEFC D0 02 BNE $02 [$AF00] ;} If number of times screen has scrolled == 40h: $80AEFE 38 SEC ; Return carry set $80AEFF 60 RTS $80AF00 18 CLC ; Else: return carry clear $80AF01 60 RTS } ;;; Door transition - down ;;; { $80AF02 AE 25 09 LDX $0925 [$7E:0925] ;\ $80AF05 DA PHX ;} Save number of times screen has scrolled $80AF06 D0 3C BNE $3C [$AF44] ; If number of times screen has scrolled == 0: $80AF08 A5 B3 LDA $B3 [$7E:00B3] ;\ $80AF0A 48 PHA ;} Save BG1 Y scroll $80AF0B A5 B7 LDA $B7 [$7E:00B7] ;\ $80AF0D 48 PHA ;} Save BG2 Y scroll $80AF0E AD 15 09 LDA $0915 [$7E:0915] ;\ $80AF11 48 PHA ;} Save layer 1 Y position $80AF12 38 SEC ;\ $80AF13 E9 0F 00 SBC #$000F ;} Use (layer 1 Y position -= 0Fh) for below calculations $80AF16 8D 15 09 STA $0915 [$7E:0915] ;/ $80AF19 AD 19 09 LDA $0919 [$7E:0919] ;\ $80AF1C 48 PHA ;} Save layer 2 Y position $80AF1D 38 SEC ;\ $80AF1E E9 0F 00 SBC #$000F ;} Use (layer 2 Y position -= 0Fh) for below calculations $80AF21 8D 19 09 STA $0919 [$7E:0919] ;/ $80AF24 20 BB A4 JSR $A4BB [$80:A4BB] ; Calculate blocks scrolled for below calculations $80AF27 20 10 AE JSR $AE10 [$80:AE10] ; Save number of blocks scrolled $80AF2A CE 01 09 DEC $0901 [$7E:0901] ; Decrement previous number of blocks layer 1 was scrolled vertically $80AF2D CE 05 09 DEC $0905 [$7E:0905] ; Decrement previous number of blocks layer 2 was scrolled vertically $80AF30 22 A0 A3 80 JSL $80A3A0[$80:A3A0] ; Updates only BG1 when scrolling $80AF34 68 PLA ;\ $80AF35 8D 19 09 STA $0919 [$7E:0919] ;} Restore layer 2 Y position $80AF38 68 PLA ;\ $80AF39 8D 15 09 STA $0915 [$7E:0915] ;} Restore layer 1 Y position $80AF3C 68 PLA ;\ $80AF3D 85 B7 STA $B7 [$7E:00B7] ;} Restore BG2 Y scroll $80AF3F 68 PLA ;\ $80AF40 85 B3 STA $B3 [$7E:00B3] ;} Restore BG1 Y scroll $80AF42 80 33 BRA $33 [$AF77] $80AF44 E0 39 00 CPX #$0039 ;\ $80AF47 B0 2E BCS $2E [$AF77] ;} Else if number of times screen has scrolled < 39h $80AF49 AD FC 0A LDA $0AFC [$7E:0AFC] ;\ $80AF4C 18 CLC ;| $80AF4D 6D 2B 09 ADC $092B [$7E:092B] ;} Samus Y sub-position += door transition sub-speed $80AF50 8D FC 0A STA $0AFC [$7E:0AFC] ;/ $80AF53 AD FA 0A LDA $0AFA [$7E:0AFA] ;\ $80AF56 6D 2D 09 ADC $092D [$7E:092D] ;} Samus Y position += door transition speed $80AF59 8D FA 0A STA $0AFA [$7E:0AFA] ;/ $80AF5C 8D 14 0B STA $0B14 [$7E:0B14] ; Samus previous Y position = Samus Y position $80AF5F AD 15 09 LDA $0915 [$7E:0915] ;\ $80AF62 18 CLC ;| $80AF63 69 04 00 ADC #$0004 ;} Layer 1 Y position += 4 $80AF66 8D 15 09 STA $0915 [$7E:0915] ;/ $80AF69 AD 19 09 LDA $0919 [$7E:0919] ;\ $80AF6C 18 CLC ;| $80AF6D 69 04 00 ADC #$0004 ;} Layer 2 Y position += 4 $80AF70 8D 19 09 STA $0919 [$7E:0919] ;/ $80AF73 22 A0 A3 80 JSL $80A3A0[$80:A3A0] ; Updates only BG1 when scrolling $80AF77 FA PLX ;\ $80AF78 E8 INX ;} Increment number of times screen has scrolled $80AF79 8E 25 09 STX $0925 [$7E:0925] ;/ $80AF7C E0 39 00 CPX #$0039 ;\ $80AF7F 90 06 BCC $06 [$AF87] ;} If number of times screen has scrolled >= 39h: $80AF81 22 A0 A3 80 JSL $80A3A0[$80:A3A0] ; Updates only BG1 when scrolling $80AF85 38 SEC ; Return carry set $80AF86 60 RTS $80AF87 18 CLC ; Else: return carry clear $80AF88 60 RTS } ;;; Door transition - up ;;; { $80AF89 AE 25 09 LDX $0925 [$7E:0925] ;\ $80AF8C DA PHX ;} Save number of times screen has scrolled $80AF8D D0 3C BNE $3C [$AFCB] ; If number of times screen has scrolled == 0: $80AF8F A5 B3 LDA $B3 [$7E:00B3] ;\ $80AF91 48 PHA ;} Save BG1 Y scroll $80AF92 A5 B7 LDA $B7 [$7E:00B7] ;\ $80AF94 48 PHA ;} Save BG2 Y scroll $80AF95 AD 15 09 LDA $0915 [$7E:0915] ;\ $80AF98 48 PHA ;} Save layer 1 Y position $80AF99 38 SEC ;\ $80AF9A E9 10 00 SBC #$0010 ;} Use (layer 1 Y position -= 10h) for below calculations $80AF9D 8D 15 09 STA $0915 [$7E:0915] ;/ $80AFA0 AD 19 09 LDA $0919 [$7E:0919] ;\ $80AFA3 48 PHA ;} Save layer 2 Y position $80AFA4 38 SEC ;\ $80AFA5 E9 10 00 SBC #$0010 ;} Use (layer 2 Y position -= 10h) for below calculations $80AFA8 8D 19 09 STA $0919 [$7E:0919] ;/ $80AFAB 20 BB A4 JSR $A4BB [$80:A4BB] ; Calculate blocks scrolled for below calculations $80AFAE 20 10 AE JSR $AE10 [$80:AE10] ; Save number of blocks scrolled $80AFB1 EE 01 09 INC $0901 [$7E:0901] ; Increment previous number of blocks layer 1 was scrolled vertically $80AFB4 EE 05 09 INC $0905 [$7E:0905] ; Increment previous number of blocks layer 2 was scrolled vertically $80AFB7 22 A0 A3 80 JSL $80A3A0[$80:A3A0] ; Updates only BG1 when scrolling $80AFBB 68 PLA ;\ $80AFBC 8D 19 09 STA $0919 [$7E:0919] ;} Restore layer 2 Y position $80AFBF 68 PLA ;\ $80AFC0 8D 15 09 STA $0915 [$7E:0915] ;} Restore layer 1 Y position $80AFC3 68 PLA ;\ $80AFC4 85 B7 STA $B7 [$7E:00B7] ;} Restore BG2 Y scroll $80AFC6 68 PLA ;\ $80AFC7 85 B3 STA $B3 [$7E:00B3] ;} Restore BG1 Y scroll $80AFC9 80 59 BRA $59 [$B024] $80AFCB AD FC 0A LDA $0AFC [$7E:0AFC] ;\ $80AFCE 38 SEC ;| $80AFCF ED 2B 09 SBC $092B [$7E:092B] ;} Samus Y sub-position -= door transition sub-speed $80AFD2 8D FC 0A STA $0AFC [$7E:0AFC] ;/ $80AFD5 AD FA 0A LDA $0AFA [$7E:0AFA] ;\ $80AFD8 ED 2D 09 SBC $092D [$7E:092D] ;} Samus Y position -= door transition speed $80AFDB 8D FA 0A STA $0AFA [$7E:0AFA] ;/ $80AFDE 8D 14 0B STA $0B14 [$7E:0B14] ; Samus previous Y position = Samus Y position $80AFE1 AD 15 09 LDA $0915 [$7E:0915] ;\ $80AFE4 38 SEC ;| $80AFE5 E9 04 00 SBC #$0004 ;} Layer 1 Y position -= 4 $80AFE8 8D 15 09 STA $0915 [$7E:0915] ;/ $80AFEB AD 19 09 LDA $0919 [$7E:0919] ;\ $80AFEE 38 SEC ;| $80AFEF E9 04 00 SBC #$0004 ;} Layer 2 Y position -= 4 $80AFF2 8D 19 09 STA $0919 [$7E:0919] ;/ $80AFF5 E0 05 00 CPX #$0005 ;\ $80AFF8 B0 26 BCS $26 [$B020] ;} If number of times screen has scrolled < 5: $80AFFA AD 11 09 LDA $0911 [$7E:0911] ;\ $80AFFD 18 CLC ;| $80AFFE 6D 1D 09 ADC $091D [$7E:091D] ;} BG1 X scroll = layer 1 X position + BG1 X scroll offset $80B001 85 B1 STA $B1 [$7E:00B1] ;/ $80B003 AD 15 09 LDA $0915 [$7E:0915] ;\ $80B006 18 CLC ;| $80B007 6D 1F 09 ADC $091F [$7E:091F] ;} BG1 Y scroll = layer 1 Y position + BG1 Y scroll offset $80B00A 85 B3 STA $B3 [$7E:00B3] ;/ $80B00C AD 17 09 LDA $0917 [$7E:0917] ;\ $80B00F 18 CLC ;| $80B010 6D 21 09 ADC $0921 [$7E:0921] ;} BG2 X scroll = layer 2 X position + BG2 X scroll offset $80B013 85 B5 STA $B5 [$7E:00B5] ;/ $80B015 AD 19 09 LDA $0919 [$7E:0919] ;\ $80B018 18 CLC ;| $80B019 6D 23 09 ADC $0923 [$7E:0923] ;} BG2 Y scroll = layer 2 Y position + BG2 Y scroll offset $80B01C 85 B7 STA $B7 [$7E:00B7] ;/ $80B01E 80 04 BRA $04 [$B024] $80B020 22 A0 A3 80 JSL $80A3A0[$80:A3A0] ; Else: Updates only BG1 when scrolling $80B024 FA PLX ;\ $80B025 E8 INX ;} Increment number of times screen has scrolled $80B026 8E 25 09 STX $0925 [$7E:0925] ;/ $80B029 E0 39 00 CPX #$0039 ;\ $80B02C D0 02 BNE $02 [$B030] ;} If number of times screen has scrolled == 39h: $80B02E 38 SEC ; Return carry set $80B02F 60 RTS $80B030 18 CLC ; Else: return carry clear $80B031 60 RTS } ;;; Unused. Mode 7 initialisation? ;;; { ; Unused... Uses data from $98 which isn't consistent with the bank log: ; $98:8000-8303 Font 3 [Bank Split] ; $98:8304-FFFF Zebes Boom [Bank Split] $80B032 A9 01 00 LDA #$0001 ;\ $80B035 8D 83 07 STA $0783 [$7E:0783] ;} $0783 = 1 $80B038 AD 83 07 LDA $0783 [$7E:0783] ;\ $80B03B D0 02 BNE $02 [$B03F] ;| $80B03D 38 SEC ;} ...Ignore this $80B03E 6B RTL ;/ $80B03F 22 6F 83 80 JSL $80836F[$80:836F] ; Set force blank $80B043 A9 80 00 LDA #$0080 ;\ $80B046 8D 15 21 STA $2115 [$7E:2115] ;| $80B049 9C 16 21 STZ $2116 [$7E:2116] ;| $80B04C A9 00 19 LDA #$1900 ;| $80B04F 8D 10 43 STA $4310 [$7E:4310] ;| $80B052 A9 00 80 LDA #$8000 ;| $80B055 8D 12 43 STA $4312 [$7E:4312] ;| $80B058 A9 00 40 LDA #$4000 ;} $98:8000..BFFF -> VRAM[0000..3FFF] (huh?) $80B05B 8D 15 43 STA $4315 [$7E:4315] ;| $80B05E E2 20 SEP #$20 ;| $80B060 A9 98 LDA #$98 ;| $80B062 8D 14 43 STA $4314 [$7E:4314] ;| $80B065 A9 02 LDA #$02 ;| $80B067 8D 0B 42 STA $420B [$7E:420B] ;/ $80B06A 9C 15 21 STZ $2115 [$7E:2115] ;\ $80B06D 9C 16 21 STZ $2116 [$7E:2116] ;| $80B070 9C 17 21 STZ $2117 [$7E:2117] ;| $80B073 A2 00 40 LDX #$4000 ;| ;} Clear VRAM[0000..3FFF] (what?) $80B076 9C 18 21 STZ $2118 [$7E:2118] ;| $80B079 CA DEX ;| $80B07A D0 FA BNE $FA [$B076] ;/ $80B07C A0 00 00 LDY #$0000 ;\ $80B07F BB TYX ;| ;| $80B080 8C 16 21 STY $2116 [$7E:2116] ;| $80B083 5A PHY ;| $80B084 A0 20 00 LDY #$0020 ;| ;| $80B087 BF 00 C0 98 LDA $98C000,x ;| $80B08B 8D 18 21 STA $2118 [$7E:2118] ;| $80B08E E8 INX ;} $98C000[i*20h..i*20h+1Fh] -> VRAM[i*80h..i*80h+1Fh] $80B08F 88 DEY ;} For 0 <= i < 8 $80B090 D0 F5 BNE $F5 [$B087] ;| $80B092 C2 20 REP #$20 ;| $80B094 68 PLA ;| $80B095 18 CLC ;| $80B096 69 80 00 ADC #$0080 ;| $80B099 A8 TAY ;| $80B09A E2 20 SEP #$20 ;| $80B09C E0 00 04 CPX #$0400 ;| $80B09F D0 DF BNE $DF [$B080] ;/ $80B0A1 A9 07 LDA #$07 ;\ $80B0A3 85 55 STA $55 [$7E:0055] ;} Screen brightness = ~50% $80B0A5 C2 20 REP #$20 $80B0A7 A9 00 01 LDA #$0100 ;\ $80B0AA 85 78 STA $78 [$7E:0078] ;| $80B0AC 64 7A STZ $7A [$7E:007A] ;} Mode 7 matrix = identity $80B0AE 64 7C STZ $7C [$7E:007C] ;| $80B0B0 85 7E STA $7E [$7E:007E] ;/ $80B0B2 A9 80 00 LDA #$0080 ;\ $80B0B5 85 80 STA $80 [$7E:0080] ;} Set mode 7 centre to the bottom-right corner $80B0B7 85 82 STA $82 [$7E:0082] ;/ $80B0B9 9C 85 07 STZ $0785 [$7E:0785] ; $0785 = 0 $80B0BC 22 82 83 80 JSL $808382[$80:8382] ; Clear force blank $80B0C0 38 SEC $80B0C1 6B RTL } ;;; Configure mode 7 rotation matrix ;;; { ; Configure mode 7 rotation matrix, only on an 8th frame, with angle [$0785]++ $80B0C2 08 PHP $80B0C3 C2 30 REP #$30 $80B0C5 AD 83 07 LDA $0783 [$7E:0783] ;\ $80B0C8 F0 33 BEQ $33 [$B0FD] ;| $80B0CA AD B6 05 LDA $05B6 [$7E:05B6] ;} If [$0783] and frame counter hasn't 07h: $80B0CD 29 07 00 AND #$0007 ;| $80B0D0 D0 2B BNE $2B [$B0FD] ;/ $80B0D2 AD 85 07 LDA $0785 [$7E:0785] ;\ $80B0D5 29 FF 00 AND #$00FF ;| $80B0D8 0A ASL A ;| $80B0D9 AA TAX ;} Mode 7 matrix B = sin([$0785] * 2pi/100h) * 100h $80B0DA BF 43 B4 A0 LDA $A0B443,x ;| $80B0DE 85 7A STA $7A [$7E:007A] ;/ $80B0E0 49 FF FF EOR #$FFFF ;\ $80B0E3 1A INC A ;} Mode 7 matrix C = -B $80B0E4 85 7C STA $7C [$7E:007C] ;/ $80B0E6 AD 85 07 LDA $0785 [$7E:0785] ;\ $80B0E9 18 CLC ;| $80B0EA 69 40 00 ADC #$0040 ;| $80B0ED 29 FF 00 AND #$00FF ;| $80B0F0 0A ASL A ;} Mode 7 matrix A = D = cos([$0785] * 2pi/100h) * 100h $80B0F1 AA TAX ;| $80B0F2 BF 43 B4 A0 LDA $A0B443,x ;| $80B0F6 85 78 STA $78 [$7E:0078] ;| $80B0F8 85 7E STA $7E [$7E:007E] ;/ $80B0FA EE 85 07 INC $0785 [$7E:0785] ; ++$0785 $80B0FD 28 PLP $80B0FE 6B RTL } ;;; Decompression ;;; { ; Takes parameters: $47..49 = source address, dest long address ; Source may overflow bank, target may NOT $80B0FF A3 02 LDA $02,s [$7E:1FF9] ;\ $80B101 85 45 STA $45 [$7E:0045] ;| $80B103 A3 01 LDA $01,s [$7E:1FF8] ;} $44 = pointer to parameter - 1 $80B105 85 44 STA $44 [$7E:0044] ;/ $80B107 18 CLC ;\ $80B108 69 03 00 ADC #$0003 ;} Fix return address $80B10B 83 01 STA $01,s [$7E:1FF8] ;/ $80B10D A0 01 00 LDY #$0001 ;\ $80B110 B7 44 LDA [$44],y[$8B:92A1] ;| $80B112 85 4C STA $4C [$7E:004C] ;| $80B114 C8 INY ;} $4C = parameter $80B115 B7 44 LDA [$44],y[$8B:92A2] ;| $80B117 85 4D STA $4D [$7E:004D] ;/ } ;;; Decompression ;;; { ; Takes parameters: $47..49 = source address, $4C..4E = dest address $80B119 08 PHP $80B11A 8B PHB $80B11B E2 20 SEP #$20 ; 8-bit A $80B11D C2 10 REP #$10 ; 16-bit X/Y $80B11F A5 49 LDA $49 [$7E:0049] ;\ $80B121 48 PHA ;} DB = source bank $80B122 AB PLB ;/ $80B123 64 50 STZ $50 [$7E:0050] ; For checking the 20h (invert) mask when loading $4F to X in the dictionary copy methods $80B125 A0 00 00 LDY #$0000 ; Main loop $80B128 DA PHX ;\ $80B129 A6 47 LDX $47 [$7E:0047] ;| $80B12B BD 00 00 LDA $0000,x[$95:80D8] ;| $80B12E E8 INX ;| $80B12F D0 03 BNE $03 [$B134] ;} A = [source++] $80B131 20 66 B2 JSR $B266 [$80:B266] ;| ;| $80B134 86 47 STX $47 [$7E:0047] ;| $80B136 FA PLX ;/ $80B137 85 4A STA $4A [$7E:004A] ; $4A = A $80B139 C9 FF CMP #$FF ;\ $80B13B D0 03 BNE $03 [$B140] ;} If A == FFh: $80B13D AB PLB ;\ $80B13E 28 PLP ;} Return $80B13F 6B RTL ;/ $80B140 29 E0 AND #$E0 ;\ $80B142 C9 E0 CMP #$E0 ;} If A has E0h: $80B144 D0 1E BNE $1E [$B164] ;/ ; Command E0: Extended command $80B146 A5 4A LDA $4A [$7E:004A] ;\ $80B148 0A ASL A ;| $80B149 0A ASL A ;| $80B14A 0A ASL A ;} Push command-to-extend bits $80B14B 29 E0 AND #$E0 ;| $80B14D 48 PHA ;/ $80B14E A5 4A LDA $4A [$7E:004A] ;\ $80B150 29 03 AND #$03 ;} High byte of A = high bits of counter $80B152 EB XBA ;/ $80B153 DA PHX ;\ $80B154 A6 47 LDX $47 [$7E:0047] ;| $80B156 BD 00 00 LDA $0000,x[$95:818C] ;| $80B159 E8 INX ;| $80B15A D0 03 BNE $03 [$B15F] ;} A = [source++] $80B15C 20 66 B2 JSR $B266 [$80:B266] ;| ;| $80B15F 86 47 STX $47 [$7E:0047] ;| $80B161 FA PLX ;/ $80B162 80 08 BRA $08 [$B16C] ; Else (A hasn't E0h): $80B164 48 PHA ; Push command bits $80B165 A9 00 LDA #$00 ;\ $80B167 EB XBA ;} High byte of A = 0 $80B168 A5 4A LDA $4A [$7E:004A] ;\ $80B16A 29 1F AND #$1F ;} A = counter bits $80B16C AA TAX ;\ $80B16D E8 INX ;} X = counter+1 (transfer of 0 would be redundant) $80B16E 68 PLA ; A = command $80B16F C9 00 CMP #$00 ;\ $80B171 10 03 BPL $03 [$B176] ;} If A is 80h..E0h: $80B173 4C FF B1 JMP $B1FF [$80:B1FF] ; Branch to B1FF ; Command 00..60: $80B176 C9 20 CMP #$20 ;\ $80B178 F0 1F BEQ $1F [$B199] ;} If A is 20h: branch to B199 $80B17A C9 40 CMP #$40 ;\ $80B17C F0 33 BEQ $33 [$B1B1] ;} If A is 40h: branch to B1B1 $80B17E C9 60 CMP #$60 ;\ $80B180 F0 64 BEQ $64 [$B1E6] ;} If A is 60h: branch to B1E6 ; Command 00: Direct copy $80B182 DA PHX ;\ $80B183 A6 47 LDX $47 [$7E:0047] ;| $80B185 BD 00 00 LDA $0000,x[$95:80DB] ;| $80B188 E8 INX ;| $80B189 D0 03 BNE $03 [$B18E] ;} A = [source++] $80B18B 20 66 B2 JSR $B266 [$80:B266] ;| ;| $80B18E 86 47 STX $47 [$7E:0047] ;| $80B190 FA PLX ;/ $80B191 97 4C STA [$4C],y[$7F:5020] ;\ $80B193 C8 INY ;} dest++ = A $80B194 CA DEX ;\ $80B195 D0 EB BNE $EB [$B182] ;} While --counter: loop from B182 $80B197 F0 8F BEQ $8F [$B128] ; Next! ; Command 20: Byte fill $80B199 DA PHX ;\ $80B19A A6 47 LDX $47 [$7E:0047] ;| $80B19C BD 00 00 LDA $0000,x[$95:80D9] ;| $80B19F E8 INX ;| $80B1A0 D0 03 BNE $03 [$B1A5] ;} A = [source++] $80B1A2 20 66 B2 JSR $B266 [$80:B266] ;| ;| $80B1A5 86 47 STX $47 [$7E:0047] ;| $80B1A7 FA PLX ;/ $80B1A8 97 4C STA [$4C],y[$7F:5000] ;\ $80B1AA C8 INY ;} dest++ = A $80B1AB CA DEX ;\ $80B1AC D0 FA BNE $FA [$B1A8] ;} While --counter: loop from B1A8 $80B1AE 4C 28 B1 JMP $B128 [$80:B128] ; Next! ; Command 40: Word fill $80B1B1 DA PHX ;\ $80B1B2 A6 47 LDX $47 [$7E:0047] ;| $80B1B4 BD 00 00 LDA $0000,x[$95:80F3] ;| $80B1B7 E8 INX ;| $80B1B8 D0 03 BNE $03 [$B1BD] ;} A = [source++] $80B1BA 20 66 B2 JSR $B266 [$80:B266] ;| ;| $80B1BD 86 47 STX $47 [$7E:0047] ;| $80B1BF FA PLX ;/ $80B1C0 85 4A STA $4A [$7E:004A] ; $4A = A $80B1C2 DA PHX ;\ $80B1C3 A6 47 LDX $47 [$7E:0047] ;| $80B1C5 BD 00 00 LDA $0000,x[$95:80F4] ;| $80B1C8 E8 INX ;| $80B1C9 D0 03 BNE $03 [$B1CE] ;} A = [source++] $80B1CB 20 66 B2 JSR $B266 [$80:B266] ;| ;| $80B1CE 86 47 STX $47 [$7E:0047] ;| $80B1D0 FA PLX ;/ $80B1D1 85 4B STA $4B [$7E:004B] ; $4B = A $80B1D3 A5 4A LDA $4A [$7E:004A] ;\ $80B1D5 97 4C STA [$4C],y[$7F:503A] ;} dest++ = [$4A] $80B1D7 C8 INY ;/ $80B1D8 CA DEX ;\ $80B1D9 F0 08 BEQ $08 [$B1E3] ;} If --counter == 0: next! $80B1DB A5 4B LDA $4B [$7E:004B] ;\ $80B1DD 97 4C STA [$4C],y[$7F:503B] ;} dest++ = [$4B] $80B1DF C8 INY ;/ $80B1E0 CA DEX ;\ $80B1E1 D0 F0 BNE $F0 [$B1D3] ;} While --counter: loop from B1D3 $80B1E3 4C 28 B1 JMP $B128 [$80:B128] ; Next! ; Command 60: Incrementing fill $80B1E6 DA PHX ;\ $80B1E7 A6 47 LDX $47 [$7E:0047] ;| $80B1E9 BD 00 00 LDA $0000,x[$95:81BC] ;| $80B1EC E8 INX ;| $80B1ED D0 03 BNE $03 [$B1F2] ;} A = [source++] $80B1EF 20 66 B2 JSR $B266 [$80:B266] ;| ;| $80B1F2 86 47 STX $47 [$7E:0047] ;| $80B1F4 FA PLX ;/ $80B1F5 97 4C STA [$4C],y[$7F:5111] ;\ $80B1F7 1A INC A ;} dest++ = A++ $80B1F8 C8 INY ;/ $80B1F9 CA DEX ;\ $80B1FA D0 F9 BNE $F9 [$B1F5] ;} While --counter: loop from B1F5 $80B1FC 4C 28 B1 JMP $B128 [$80:B128] ; Next! ; Command 80..E0: $80B1FF C9 C0 CMP #$C0 ;\ $80B201 B0 42 BCS $42 [$B245] ;} If command >= C0h: Branch to B245 ; Command 80 and A0: Dictionary copy and inverted dictionary copy $80B203 29 20 AND #$20 ;\ $80B205 85 4F STA $4F [$7E:004F] ;} $4F = invert bit $80B207 DA PHX ;\ $80B208 A6 47 LDX $47 [$7E:0047] ;| $80B20A BD 00 00 LDA $0000,x[$95:8396] ;| $80B20D E8 INX ;| $80B20E D0 03 BNE $03 [$B213] ;} A = [source++] $80B210 20 66 B2 JSR $B266 [$80:B266] ;| ;| $80B213 86 47 STX $47 [$7E:0047] ;| $80B215 FA PLX ;/ $80B216 85 4A STA $4A [$7E:004A] ; $4A = A $80B218 DA PHX ;\ $80B219 A6 47 LDX $47 [$7E:0047] ;| $80B21B BD 00 00 LDA $0000,x[$95:8397] ;| $80B21E E8 INX ;| $80B21F D0 03 BNE $03 [$B224] ;} A = [source++] $80B221 20 66 B2 JSR $B266 [$80:B266] ;| ;| $80B224 86 47 STX $47 [$7E:0047] ;| $80B226 FA PLX ;/ $80B227 85 4B STA $4B [$7E:004B] ; $4B = A $80B229 E2 20 SEP #$20 ; 8-bit A $80B22B DA PHX $80B22C 5A PHY ;\ $80B22D A4 4A LDY $4A [$7E:004A] ;| $80B22F B7 4C LDA [$4C],y[$7F:50A0] ;| $80B231 C8 INY ;} A = [dest + [$4A++]] $80B232 84 4A STY $4A [$7E:004A] ;| $80B234 7A PLY ;/ $80B235 A6 4F LDX $4F [$7E:004F] ;\ $80B237 F0 02 BEQ $02 [$B23B] ;} If invert bit: $80B239 49 FF EOR #$FF ; Invert A $80B23B 97 4C STA [$4C],y[$7F:50E0] ;\ $80B23D C8 INY ;} dest++ = A $80B23E FA PLX ;/ $80B23F CA DEX ;\ $80B240 D0 E9 BNE $E9 [$B22B] ;} While --counter: loop from B22B $80B242 4C 28 B1 JMP $B128 [$80:B128] ; Next! ; Command C0 and E0: Sliding dictionary copy and inverted sliding dictionary copy $80B245 29 20 AND #$20 ;\ $80B247 85 4F STA $4F [$7E:004F] ;} $4F = invert bit $80B249 DA PHX ;\ $80B24A A6 47 LDX $47 [$7E:0047] ;| $80B24C BD 00 00 LDA $0000,x[$95:818A] ;| $80B24F E8 INX ;| $80B250 D0 03 BNE $03 [$B255] ;} A = [source++] $80B252 20 66 B2 JSR $B266 [$80:B266] ;| ;| $80B255 86 47 STX $47 [$7E:0047] ;| $80B257 FA PLX ;/ $80B258 85 4A STA $4A [$7E:004A] ;\ $80B25A 64 4B STZ $4B [$7E:004B] ;| $80B25C C2 20 REP #$20 ;| $80B25E 98 TYA ;} $4A..$4B = Y - A $80B25F 38 SEC ;| $80B260 E5 4A SBC $4A [$7E:004A] ;| $80B262 85 4A STA $4A [$7E:004A] ;/ $80B264 80 C3 BRA $C3 [$B229] ; Branch to B229 } ;;; Source bank overflow correction ;;; { $80B266 A2 00 80 LDX #$8000 ; Set address to 8000h $80B269 48 PHA ;\ $80B26A 8B PHB ;| $80B26B 68 PLA ;| $80B26C 1A INC A ;} Increment bank $80B26D 48 PHA ;| $80B26E AB PLB ;| $80B26F 68 PLA ;/ $80B270 60 RTS } ;;; Decompression to VRAM ;;; { ; Takes parameters: $47..49 = source address, $4C..4D and VRAM address = dest address $80B271 08 PHP $80B272 8B PHB $80B273 C2 10 REP #$10 ; 8-bit A $80B275 E2 20 SEP #$20 ; 16-bit X/Y $80B277 A5 49 LDA $49 [$7E:0049] ;\ $80B279 48 PHA ;} DB = source bank $80B27A AB PLB ;/ $80B27B 64 50 STZ $50 [$7E:0050] ; For checking the 20h (invert) mask when loading $4F to X in the dictionary copy methods $80B27D A4 4C LDY $4C [$7E:004C] ; Y = dest $80B27F DA PHX ;\ $80B280 A6 47 LDX $47 [$7E:0047] ;| $80B282 BD 00 00 LDA $0000,x[$B9:8000] ;| $80B285 E8 INX ;| $80B286 D0 03 BNE $03 [$B28B] ;} A = [source++] $80B288 20 66 B2 JSR $B266 [$80:B266] ;| ;| $80B28B 86 47 STX $47 [$7E:0047] ;| $80B28D FA PLX ;/ $80B28E 85 4A STA $4A [$7E:004A] ; $4A = A $80B290 C9 FF CMP #$FF ;\ $80B292 D0 03 BNE $03 [$B297] ;} If A == FFh: $80B294 AB PLB ;\ $80B295 28 PLP ;} Return $80B296 6B RTL ;/ $80B297 29 E0 AND #$E0 ;\ $80B299 C9 E0 CMP #$E0 ;} If A has E0h: $80B29B D0 1E BNE $1E [$B2BB] ;/ ; Command E0: Extended command $80B29D A5 4A LDA $4A [$7E:004A] ;\ $80B29F 0A ASL A ;| $80B2A0 0A ASL A ;| $80B2A1 0A ASL A ;} Push command-to-extend bits $80B2A2 29 E0 AND #$E0 ;| $80B2A4 48 PHA ;/ $80B2A5 A5 4A LDA $4A [$7E:004A] ;\ $80B2A7 29 03 AND #$03 ;} High byte of A = high bits of counter $80B2A9 EB XBA ;/ $80B2AA DA PHX ;\ $80B2AB A6 47 LDX $47 [$7E:0047] ;| $80B2AD BD 00 00 LDA $0000,x[$B9:88F3] ;| $80B2B0 E8 INX ;| $80B2B1 D0 03 BNE $03 [$B2B6] ;} A = [source++] $80B2B3 20 66 B2 JSR $B266 [$80:B266] ;| ;| $80B2B6 86 47 STX $47 [$7E:0047] ;| $80B2B8 FA PLX ;/ $80B2B9 80 08 BRA $08 [$B2C3] ; Else (A hasn't E0h): $80B2BB 48 PHA ; Push command bits $80B2BC A9 00 LDA #$00 ;\ $80B2BE EB XBA ;} High byte of A = 0 $80B2BF A5 4A LDA $4A [$7E:004A] ;\ $80B2C1 29 1F AND #$1F ;} A = counter bits $80B2C3 AA TAX ;\ $80B2C4 E8 INX ;} X = counter+1 (transfer of 0 would be redundant) $80B2C5 68 PLA ; A = command $80B2C6 C9 00 CMP #$00 ;\ $80B2C8 10 03 BPL $03 [$B2CD] ;} If A is 80h..E0h: $80B2CA 4C A0 B3 JMP $B3A0 [$80:B3A0] ; Branch to B3A0 ; Comand 00..60: $80B2CD C9 20 CMP #$20 ;\ $80B2CF F0 31 BEQ $31 [$B302] ;} If A is 20h: branch to B302 $80B2D1 C9 40 CMP #$40 ;\ $80B2D3 F0 53 BEQ $53 [$B328] ;} If A is 40h: branch to B328 $80B2D5 C9 60 CMP #$60 ;\ $80B2D7 D0 03 BNE $03 [$B2DC] ;} If A is 60h: branch to B379 $80B2D9 4C 79 B3 JMP $B379 [$80:B379] ;/ ; Command 00: Direct copy $80B2DC DA PHX ;\ $80B2DD A6 47 LDX $47 [$7E:0047] ;| $80B2DF BD 00 00 LDA $0000,x[$B9:8004] ;| $80B2E2 E8 INX ;| $80B2E3 D0 03 BNE $03 [$B2E8] ;} A = [source++] $80B2E5 20 66 B2 JSR $B266 [$80:B266] ;| ;| $80B2E8 86 47 STX $47 [$7E:0047] ;| $80B2EA FA PLX ;/ $80B2EB 48 PHA ;\ $80B2EC 98 TYA ;| $80B2ED 4A LSR A ;} If dest is even: $80B2EE 68 PLA ;| $80B2EF B0 06 BCS $06 [$B2F7] ;/ $80B2F1 8F 18 21 00 STA $002118[$7E:2118] ;\ $80B2F5 80 04 BRA $04 [$B2FB] ;} VRAM data write LSB = A $80B2F7 8F 19 21 00 STA $002119[$7E:2119] ; Else: VRAM data write MSB = A $80B2FB C8 INY ; ++dest $80B2FC CA DEX ;\ $80B2FD D0 DD BNE $DD [$B2DC] ;} If --counter: loop from B2DC $80B2FF 4C 7F B2 JMP $B27F [$80:B27F] ; Next! ; Command 20: Byte fill $80B302 DA PHX ;\ $80B303 A6 47 LDX $47 [$7E:0047] ;| $80B305 BD 00 00 LDA $0000,x[$B9:800A] ;| $80B308 E8 INX ;| $80B309 D0 03 BNE $03 [$B30E] ;} A = [source++] $80B30B 20 66 B2 JSR $B266 [$80:B266] ;| ;| $80B30E 86 47 STX $47 [$7E:0047] ;| $80B310 FA PLX ;/ $80B311 48 PHA ;\ $80B312 98 TYA ;| $80B313 4A LSR A ;} If dest is even: $80B314 68 PLA ;| $80B315 B0 06 BCS $06 [$B31D] ;/ $80B317 8F 18 21 00 STA $002118[$7E:2118] ;\ $80B31B 80 04 BRA $04 [$B321] ;} VRAM data write LSB = A $80B31D 8F 19 21 00 STA $002119[$7E:2119] ; Else: VRAM data write MSB = A $80B321 C8 INY ; ++dest $80B322 CA DEX ;\ $80B323 D0 EC BNE $EC [$B311] ;} While --counter: loop from B311 $80B325 4C 7F B2 JMP $B27F [$80:B27F] ; Next! ; Command 40: Word fill $80B328 DA PHX ;\ $80B329 A6 47 LDX $47 [$7E:0047] ;| $80B32B BD 00 00 LDA $0000,x[$B9:8001] ;| $80B32E E8 INX ;| $80B32F D0 03 BNE $03 [$B334] ;} A = [source++] $80B331 20 66 B2 JSR $B266 [$80:B266] ;| ;| $80B334 86 47 STX $47 [$7E:0047] ;| $80B336 FA PLX ;/ $80B337 85 4A STA $4A [$7E:004A] ; $4A = A $80B339 DA PHX ;\ $80B33A A6 47 LDX $47 [$7E:0047] ;| $80B33C BD 00 00 LDA $0000,x[$B9:8002] ;| $80B33F E8 INX ;| $80B340 D0 03 BNE $03 [$B345] ;} A = [source++] $80B342 20 66 B2 JSR $B266 [$80:B266] ;| ;| $80B345 86 47 STX $47 [$7E:0047] ;| $80B347 FA PLX ;/ $80B348 85 4B STA $4B [$7E:004B] ; $4B = A $80B34A A5 4A LDA $4A [$7E:004A] ; A = [$4A] $80B34C 48 PHA ;\ $80B34D 98 TYA ;| $80B34E 4A LSR A ;} If dest is even: $80B34F 68 PLA ;| $80B350 B0 06 BCS $06 [$B358] ;/ $80B352 8F 18 21 00 STA $002118[$7E:2118] ;\ $80B356 80 04 BRA $04 [$B35C] ;} VRAM data write LSB = A $80B358 8F 19 21 00 STA $002119[$7E:2119] ; Else: VRAM data write MSB = A $80B35C C8 INY ; ++dest $80B35D CA DEX ;\ $80B35E F0 16 BEQ $16 [$B376] ;} If --counter == 0: next! $80B360 A5 4B LDA $4B [$7E:004B] ; A = [$4B] $80B362 48 PHA ;\ $80B363 98 TYA ;| $80B364 4A LSR A ;} If dest is even: $80B365 68 PLA ;| $80B366 B0 06 BCS $06 [$B36E] ;/ $80B368 8F 18 21 00 STA $002118[$7E:2118] ;\ $80B36C 80 04 BRA $04 [$B372] ;} VRAM data write LSB = A $80B36E 8F 19 21 00 STA $002119[$7E:2119] ; Else: VRAM data write MSB = A $80B372 C8 INY ; ++dest $80B373 CA DEX ;\ $80B374 D0 D4 BNE $D4 [$B34A] ;} While --counter: loop from B34A $80B376 4C 7F B2 JMP $B27F [$80:B27F] ; Next! ; Command 60: Incrementing fill $80B379 DA PHX ;\ $80B37A A6 47 LDX $47 [$7E:0047] ;| $80B37C BD 00 00 LDA $0000,x[$B9:8663] ;| $80B37F E8 INX ;| $80B380 D0 03 BNE $03 [$B385] ;} A = [source++] $80B382 20 66 B2 JSR $B266 [$80:B266] ;| ;| $80B385 86 47 STX $47 [$7E:0047] ;| $80B387 FA PLX ;/ $80B388 48 PHA ;\ $80B389 98 TYA ;| $80B38A 4A LSR A ;} If dest is even: $80B38B 68 PLA ;| $80B38C B0 06 BCS $06 [$B394] ;/ $80B38E 8F 18 21 00 STA $002118[$7E:2118] ;\ $80B392 80 04 BRA $04 [$B398] ;} VRAM data write LSB = A $80B394 8F 19 21 00 STA $002119[$7E:2119] ; Else: VRAM data write MSB = A $80B398 C8 INY ; ++dest $80B399 1A INC A ; ++A $80B39A CA DEX ;\ $80B39B D0 EB BNE $EB [$B388] ;} While --counter: loop from B388 $80B39D 4C 7F B2 JMP $B27F [$80:B27F] ; Next! ; Command 80..E0 $80B3A0 C9 C0 CMP #$C0 ;\ $80B3A2 B0 72 BCS $72 [$B416] ;} If command >= C0h: Branch to B416 ; Command 80 and A0: Dictionary copy and inverted dictionary copy $80B3A4 29 20 AND #$20 ;\ $80B3A6 85 4F STA $4F [$7E:004F] ;} $4F = invert bit $80B3A8 DA PHX ;\ $80B3A9 A6 47 LDX $47 [$7E:0047] ;| $80B3AB BD 00 00 LDA $0000,x[$B9:815E] ;| $80B3AE E8 INX ;| $80B3AF D0 03 BNE $03 [$B3B4] ;} A = [source++] $80B3B1 20 66 B2 JSR $B266 [$80:B266] ;| ;| $80B3B4 86 47 STX $47 [$7E:0047] ;| $80B3B6 FA PLX ;/ $80B3B7 85 4A STA $4A [$7E:004A] ; $4A = A $80B3B9 DA PHX ;\ $80B3BA A6 47 LDX $47 [$7E:0047] ;| $80B3BC BD 00 00 LDA $0000,x[$B9:815F] ;| $80B3BF E8 INX ;| $80B3C0 D0 03 BNE $03 [$B3C5] ;} A = [source++] $80B3C2 20 66 B2 JSR $B266 [$80:B266] ;| ;| $80B3C5 86 47 STX $47 [$7E:0047] ;| $80B3C7 FA PLX ;/ $80B3C8 85 4B STA $4B [$7E:004B] ; $4B = A $80B3CA C2 20 REP #$20 ;\ $80B3CC A5 4C LDA $4C [$7E:004C] ;| $80B3CE 18 CLC ;} $4A..$4B += [dest] $80B3CF 65 4A ADC $4A [$7E:004A] ;| $80B3D1 85 4A STA $4A [$7E:004A] ;/ $80B3D3 DA PHX $80B3D4 C2 20 REP #$20 ; 16-bit A $80B3D6 A5 4A LDA $4A [$7E:004A] ;\ $80B3D8 4A LSR A ;} VRAM address = $[4A]>>1 (VRAM address is in word steps) $80B3D9 8F 16 21 00 STA $002116[$7E:2116] ;/ $80B3DD AF 39 21 00 LDA $002139[$7E:2139] ; Dummy VRAM read (prefetch glitch) $80B3E1 AF 39 21 00 LDA $002139[$7E:2139] ; A = VRAM data read $80B3E5 90 01 BCC $01 [$B3E8] ; If VRAM address was odd: $80B3E7 EB XBA ; A = A MSB $80B3E8 E6 4A INC $4A [$7E:004A] ; ++$4A $80B3EA E2 20 SEP #$20 ; 8-bit A $80B3EC A6 4F LDX $4F [$7E:004F] ;\ $80B3EE F0 02 BEQ $02 [$B3F2] ;} If invert bit: $80B3F0 49 FF EOR #$FF ; Invert A $80B3F2 48 PHA ;\ $80B3F3 C2 20 REP #$20 ;| $80B3F5 98 TYA ;| $80B3F6 4A LSR A ;} VRAM address = Y>>1 (VRAM address is in word steps) $80B3F7 8F 16 21 00 STA $002116[$7E:2116] ;| $80B3FB E2 20 SEP #$20 ;| $80B3FD 68 PLA ;/ $80B3FE 48 PHA ;\ $80B3FF 98 TYA ;| $80B400 4A LSR A ;} If dest is even: $80B401 68 PLA ;| $80B402 B0 06 BCS $06 [$B40A] ;/ $80B404 8F 18 21 00 STA $002118[$7E:2118] ;\ $80B408 80 04 BRA $04 [$B40E] ;} VRAM data write LSB = A $80B40A 8F 19 21 00 STA $002119[$7E:2119] ; Else: VRAM data write MSB = A $80B40E C8 INY ; ++dest $80B40F FA PLX ;\ $80B410 CA DEX ;} While --counter: loop from B3D3 $80B411 D0 C0 BNE $C0 [$B3D3] ;/ $80B413 4C 7F B2 JMP $B27F [$80:B27F] ; Next! $80B416 29 20 AND #$20 ;\ $80B418 85 4F STA $4F [$7E:004F] ;} $4F = invert bit $80B41A DA PHX ;\ $80B41B A6 47 LDX $47 [$7E:0047] ;| $80B41D BD 00 00 LDA $0000,x[$B9:8088] ;| $80B420 E8 INX ;| $80B421 D0 03 BNE $03 [$B426] ;} A = [source++] $80B423 20 66 B2 JSR $B266 [$80:B266] ;| ;| $80B426 86 47 STX $47 [$7E:0047] ;| $80B428 FA PLX ;/ $80B429 85 4A STA $4A [$7E:004A] ;\ $80B42B 64 4B STZ $4B [$7E:004B] ;| $80B42D C2 20 REP #$20 ;| $80B42F 98 TYA ;} $4A..$4B = Y - A $80B430 38 SEC ;| $80B431 E5 4A SBC $4A [$7E:004A] ;| $80B433 85 4A STA $4A [$7E:004A] ;/ $80B435 80 9C BRA $9C [$B3D3] ; Branch to B3D3 } ;;; Tilemap for failed NTSC/PAL check ;;; { $80B437 dw 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 007D 0071 0072 007C 000F 0070 006A 0076 006E 000F 0079 006A 0074 000F 0072 007C 000F 0077 0078 007D 000F 006D 006E 007C 0072 0070 0072 0077 006E 006D 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 002B 002D 000D 000E 000D 000F 000E 000A 0026 0022 000C 0000 0026 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 006F 0078 007B 000F 0082 0078 007E 007B 000F 003B 0010 0038 001E 003A 000F 001F 001A 0036 0011 001C 0010 0036 000F 0078 007B 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 002B 002D 000D 000E 000D 000F 0027 000E 002B 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 003B 0010 0038 001E 003A 000F 0037 001E 003B 0088 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 0077 0072 0077 007D 006E 0077 006D 0078 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F } ;;; Tilemap for failed SRAM mapping check ;;; { $80BC37 dw 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 002F 000A 000D 0027 0022 0027 000C 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 003F 001A 003A 0037 0011 0037 0030 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 0072 007D 000F 0072 007C 000F 006A 000F 007C 006E 007B 0072 0078 007E 007C 000F 006C 007B 0072 0076 006E 000F 007D 0078 000F 006C 0078 0079 0082 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 007F 0072 006D 006E 0078 000F 0070 006A 0076 006E 007C 0088 000F 000F 000F 000F 000F 000F 0061 0068 000F 007E 007C 006C 000F 0062 0063 0061 0069 0088 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 0079 0075 006E 006A 007C 006E 000F 007B 006E 006F 006E 007B 000F 007D 0078 000F 0082 0078 007E 007B 000F 0077 0072 0077 007D 006E 0077 006D 0078 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 0070 006A 0076 006E 000F 0072 0077 007C 007D 007B 007E 006C 007D 0072 0078 0077 000F 006B 0078 0078 0074 0075 006E 007D 000F 006F 0078 007B 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 006F 007E 007B 007D 0071 006E 007B 000F 0072 0077 006F 0078 007B 0076 006A 007D 0072 0078 0077 0088 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 0056 0056 0056 0056 0056 0056 0056 0056 0056 0056 0056 0056 0056 0056 0056 0056 0056 0056 0056 0056 0056 0056 0056 0056 0056 0056 0056 0056 0056 0056 0056 0056 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 0168 000F 000F 0169 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 0178 000F 000F 0179 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 008E 00C8 00D6 0106 000F 0119 018F 00F0 008D 000F 0161 016A 016B 0126 016C 017E 0180 0181 0182 0183 0184 0185 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 008F 00E4 00E6 010F 0056 0129 019F 0100 008F 0056 0171 017A 017B 0192 017C 017D 0190 0191 0192 0193 0194 0195 017F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 0051 016D 0186 0161 0187 0188 0189 018A 018B 018C 018D 018E 016D 0182 0186 00E3 0110 0183 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 0043 017D 0196 0171 0197 0198 0199 019A 019B 019C 019D 019E 017D 0192 0196 00EB 0120 0193 017F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F 000F } ;;; Load new save/elevator ;;; { $80C437 08 PHP $80C438 8B PHB $80C439 4B PHK $80C43A AB PLB $80C43B C2 30 REP #$30 $80C43D A9 01 00 LDA #$0001 ;\ $80C440 8D 75 1E STA $1E75 [$7E:1E75] ;} Set this-room's-save-station-used flag $80C443 AD 9F 07 LDA $079F [$7E:079F] ;\ $80C446 0A ASL A ;| $80C447 AA TAX ;| $80C448 AD 8B 07 LDA $078B [$7E:078B] ;| $80C44B 0A ASL A ;| $80C44C 85 12 STA $12 [$7E:0012] ;| $80C44E 0A ASL A ;| $80C44F 18 CLC ;} X = [$C4B5 + area ID * 2] + save station ID * 0Eh $80C450 65 12 ADC $12 [$7E:0012] ;| $80C452 6D 8B 07 ADC $078B [$7E:078B] ;| $80C455 0A ASL A ;| $80C456 18 CLC ;| $80C457 7D B5 C4 ADC $C4B5,x[$80:C4C1] ;| $80C45A AA TAX ;/ $80C45B BD 00 00 LDA $0000,x[$80:CB2B] ;\ $80C45E 8D 9B 07 STA $079B [$7E:079B] ;} Current MDB = [X] $80C461 BD 02 00 LDA $0002,x[$80:CB2D] ;\ $80C464 8D 8D 07 STA $078D [$7E:078D] ;} Current DDB = [X+2] $80C467 BD 04 00 LDA $0004,x[$80:CB2F] ;\ $80C46A 8D 8F 07 STA $078F [$7E:078F] ;} DoorOut index = [X+4] $80C46D BD 06 00 LDA $0006,x[$80:CB31] ;\ $80C470 8D 11 09 STA $0911 [$7E:0911] ;} Layer 1 X position = BG1 X scroll offset = [X+6] $80C473 8D 1D 09 STA $091D [$7E:091D] ;/ $80C476 BD 08 00 LDA $0008,x[$80:CB33] ;\ $80C479 8D 15 09 STA $0915 [$7E:0915] ;} Layer 1 Y position = BG1 Y scroll offset = [X+8] $80C47C 8D 1F 09 STA $091F [$7E:091F] ;/ $80C47F BD 0A 00 LDA $000A,x[$80:CB35] ;\ $80C482 18 CLC ;| $80C483 6D 15 09 ADC $0915 [$7E:0915] ;} Samus Y position = Samus previous Y position = [X+0Ah] + layer 1 Y position $80C486 8D FA 0A STA $0AFA [$7E:0AFA] ;| $80C489 8D 14 0B STA $0B14 [$7E:0B14] ;/ $80C48C AD 11 09 LDA $0911 [$7E:0911] ;\ $80C48F 18 CLC ;| $80C490 69 80 00 ADC #$0080 ;| $80C493 7D 0C 00 ADC $000C,x[$80:CB37] ;} Samus X position = Samus previous X position = [X+0Ch] + layer 1 Y position + 80h $80C496 8D F6 0A STA $0AF6 [$7E:0AF6] ;| $80C499 8D 10 0B STA $0B10 [$7E:0B10] ;/ $80C49C 64 B1 STZ $B1 [$7E:00B1] ; Clear BG1 X scroll $80C49E 64 B3 STZ $B3 [$7E:00B3] ; Clear BG1 Y scroll $80C4A0 E2 20 SEP #$20 ; 8-bit A $80C4A2 A9 8F LDA #$8F ;\ $80C4A4 48 PHA ;| $80C4A5 AB PLB ;| $80C4A6 AE 9B 07 LDX $079B [$7E:079B] ;} Area ID = current MDB area ID $80C4A9 BD 01 00 LDA $0001,x[$8F:DF46] ;| $80C4AC 8D 9F 07 STA $079F [$7E:079F] ;/ $80C4AF 9C F7 05 STZ $05F7 [$7E:05F7] ; Enable automap $80C4B2 AB PLB $80C4B3 28 PLP $80C4B4 6B RTL ; Pointers to each area's saves/elevators $80C4B5 dw C4C5, C5CF, C6D9, C81B, C917, CA2F, CB2B, CC19 ; Crateria saves/elevators ; $80C4C5 dw 91F8,896A,0000,0400,0400,0040,0000, 93D5,899A,0000,0000,0000,0098,FFE0, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 94CC,8ABA,0000,0000,0000,00A8,0000, 962A,8A42,0000,0000,0000,00A8,0000, 97B5,8B86,0000,0000,0000,0088,0000, 9938,8C22,0000,0000,0000,0088,0000, A66A,91F2,0000,0000,0100,0098,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 91F8,896A,0000,0400,0400,0040,0000, 94FD,8A7E,0000,0000,0400,0095,0000, 91F8,88FE,0000,0400,0000,0080,0000 ; Brinstar saves/elevators $80C5CF dw A184,8DF6,0000,0000,0000,0098,FFE0, A201,8D12,0000,0000,0000,0098,FFE0, A22A,8F52,0000,0000,0000,0098,FFE0, A70B,9186,0000,0000,0000,0098,0000, A734,90D2,0000,0000,0000,0098,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 9AD9,8D42,0001,0000,0200,00A8,0000, 9E9F,8E86,0000,0500,0200,00A8,0000, A322,908A,0000,0000,0200,00A8,0000, A6A1,A384,0000,0000,0000,0088,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 9AD9,8D42,0001,0000,0200,00A8,0000, A56B,91CE,0000,0000,0100,0080,0000, 9D19,8E62,0000,0300,0000,0080,0000 ; Norfair saves/elevators $80C6D9 dw AAB5,9456,0000,0000,0000,0098,0000, B0DD,959A,0000,0000,0000,0098,FFE0, B167,97DA,0000,0000,0000,0098,0000, B192,93BA,0000,0000,0000,0098,0000, B1BB,9702,0000,0000,0000,0098,FFE0, B741,9A0E,0000,0000,0000,0098,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, A7DE,92A6,0000,0000,0200,00A8,0000, AF3F,96DE,0000,0000,0000,0088,0000, B236,9846,0000,0400,0200,0088,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, A7DE,932A,0002,0000,0200,00A8,0000, A923,93EA,0001,0C00,0200,00A0,0000, B37A,995A,0000,0000,0000,00A0,0000, AA82,946E,0000,0000,0000,00B5,0000, B236,9846,0001,0500,0200,0035,0000, B283,98A6,0000,0200,0200,0000,0000, B283,983A,0000,0000,0000,0080,0000 ; Wrecked Ship saves/elevators $80C81B dw CE8A,A240,0000,0000,0000,0098,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, CA08,A1F8,0001,0000,0000,0080,0000, CC6F,A2B8,0000,0400,0000,0080,0000 ; Maridia saves/elevators $80C917 dw CED2,A354,0000,0000,0000,0098,0000, D3DF,A588,0000,0000,0000,0098,0000, D765,A744,0000,0000,0000,0098,FFE0, D81A,A7EC,0000,0000,0000,0098,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, D30B,A570,0000,0000,0200,00A8,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, D1DD,A4A4,0001,0000,0000,00D0,0000, D78F,A81C,0000,0000,0200,0080,0000, D617,A72C,0000,0300,0000,0080,0000, D48E,A648,0000,0000,0100,0080,0000 ; Tourian saves/elevators $80CA2F dw DE23,AABC,0000,0000,0000,0098,FFE0, DF1B,A99C,0000,0000,0000,0098,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, DAAE,A9A8,0000,0000,0200,00A8,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, 0000,0000,0000,0400,0400,00B0,0000, DDF3,AAA4,0000,0000,0200,0080,0000, DDF3,AA38,0000,0000,0000,0080,0000 ; Ceres saves/elevators $80CB2B dw DF45,AB58,0000,0000,0000,0048,0000, DF45,AB58,0000,0000,0000,0040,0000, DF45,AB58,0000,0000,0000,0040,0000, DF45,AB58,0000,0000,0000,0040,0000, DF45,AB58,0000,0000,0000,0040,0000, DF45,AB58,0000,0000,0000,0040,0000, DF45,AB58,0000,0000,0000,0040,0000, DF45,AB58,0000,0000,0000,0040,0000, DF45,AB58,0000,0000,0000,0040,0000, DF45,AB58,0000,0000,0000,0040,0000, DF45,AB58,0000,0000,0000,0040,0000, DF45,AB58,0000,0000,0000,0040,0000, DF45,AB58,0000,0000,0000,0040,0000, DF45,AB58,0000,0000,0000,0040,0000, DF45,AB58,0000,0000,0000,0040,0000, DF45,AB58,0000,0000,0000,0040,0000, DF45,AB58,0000,0000,0000,0040,0000 ; Debug saves/elevators $80CC19 dw E82C,ABC4,0000,0000,0000,00B0,0000, E82C,ABC4,0000,0000,0000,00B0,0000, E82C,ABC4,0000,0000,0000,00B0,0000, E82C,ABC4,0000,0000,0000,00B0,0000, E82C,ABC4,0000,0000,0000,00B0,0000, E82C,ABC4,0000,0000,0000,00B0,0000, E82C,ABC4,0000,0000,0000,00B0,0000, E82C,ABC4,0000,0000,0000,00B0,0000, E82C,ABC4,0000,0000,0000,00B0,0000, E82C,ABC4,0000,0000,0000,00B0,0000, E82C,ABC4,0000,0000,0000,00B0,0000, E82C,ABC4,0000,0000,0000,00B0,0000, E82C,ABC4,0000,0000,0000,00B0,0000, E82C,ABC4,0000,0000,0000,00B0,0000, E82C,ABC4,0000,0000,0000,00B0,0000, E82C,ABC4,0000,0000,0000,00B0,0000, E82C,ABC4,0000,0000,0000,00B0,0000 } ;;; Set elevators as used ;;; { $80CD07 08 PHP $80CD08 8B PHB $80CD09 4B PHK $80CD0A AB PLB $80CD0B C2 30 REP #$30 $80CD0D AD 9F 07 LDA $079F [$7E:079F] ;\ $80CD10 0A ASL A ;| $80CD11 AA TAX ;| $80CD12 AD 93 07 LDA $0793 [$7E:0793] ;| $80CD15 29 0F 00 AND #$000F ;| $80CD18 3A DEC A ;} Y = [$CD46 + area ID * 2] + ((door bitflag & 0Fh) - 1) * 4 $80CD19 0A ASL A ;| $80CD1A 0A ASL A ;| $80CD1B 18 CLC ;| $80CD1C 7D 46 CD ADC $CD46,x ;| $80CD1F A8 TAY ;/ $80CD20 A9 00 00 LDA #$0000 ; Clear A MSB $80CD23 E2 20 SEP #$20 ; 8-bit A $80CD25 B9 00 00 LDA $0000,y ;\ $80CD28 AA TAX ;| $80CD29 B9 01 00 LDA $0001,y ;} Set source-elevator as used $80CD2C 1F F8 D8 7E ORA $7ED8F8,x ;| $80CD30 9F F8 D8 7E STA $7ED8F8,x ;/ $80CD34 B9 02 00 LDA $0002,y ;\ $80CD37 AA TAX ;| $80CD38 B9 03 00 LDA $0003,y ;} Set dest-elevator as used $80CD3B 1F F8 D8 7E ORA $7ED8F8,x ;| $80CD3F 9F F8 D8 7E STA $7ED8F8,x ;/ $80CD43 AB PLB $80CD44 28 PLP $80CD45 6B RTL ; Pointers to each area's elevator bits $80CD46 dw CD52, CD66, CD76, CD8A, CD82, CD86 ; Adds to used elevator array: ; Crateria elevator bits $80CD52 db 01,01,09,01, 01,02,03,04, 01,04,03,02, 01,08,03,01, 01,10,0B,01 ; Brinstar elevator bits $80CD66 db 03,01,01,08, 03,02,01,04, 03,04,01,02, 03,08,05,01 ; Norfair elevator bits $80CD76 db 05,01,03,08, 05,02,05,04, 05,04,05,02 ; Maridia elevator bits $80CD82 db 09,01,01,01 ; Tourian elevator bits $80CD86 db 0B,01,01,10 ; Wrecked Ship elevator bits $80CD8A db 00,00,00,00 } ;;; Free space ;;; $80CD8E fillto $80FFC0, $FF ;;; Game header ;;; { $80FFC0 db 53, 75, 70, 65, 72, 20, 4D, 65, 74, 72, 6F, 69, 64, 20, 20, 20, 20, 20, 20, 20, 20 ; 'Super Metroid ' $80FFD5 db 30 ; ROM layout. LoROM, FastROM $80FFD6 db 02 ; Cartridge type. ROM with SRAM $80FFD7 db 0C ; ROM size byte $80FFD8 db 03 ; SRAM size byte $80FFD9 db 00 ; Country code. Japan $80FFDA db 01 ; Licensee code. Nintendo $80FFDB db 00 ; Version number $80FFDC dw 0720 ; Checksum complement $80FFDE dw F8DF ; Checksum $80FFE0 dw 8573, 8573, 8573, 8573, 8573, 9583, 8573, 986A ; Native interrupt vectors $80FFF0 dw 8573, 8573, 8573, 8573, 8573, 8573, 841C, 8573 ; Emulation interrupt vectors }