From b2f7a14b6629afe67476708638ccc1639becac69 Mon Sep 17 00:00:00 2001 From: nn <53490794+nn357@users.noreply.github.com> Date: Sat, 21 Feb 2026 01:51:35 +0900 Subject: [PATCH] update error message formatting and rom / ram documentation move checksum self check variables to a place they are not likely to get clobbered update bank / ram usage notes update ram clearing method for more performance. change ram clear method cannot math clear ram via dma (leave our variables in place) --- patches/ips/self_check.ips | Bin 2579 -> 2720 bytes patches/rom_map/Bank 8B.txt | 3 +- patches/rom_map/RAM.txt | 3 +- patches/rom_map/vanilla_hooks.txt | 4 +- patches/src/self_check.asm | 108 ++++++++++++++++++++---------- 5 files changed, 80 insertions(+), 38 deletions(-) diff --git a/patches/ips/self_check.ips b/patches/ips/self_check.ips index 8acb40168746640416031902d23eaca040902f34..ce89d922ffe6f6c35f2b31d7a31335ca5990d7a4 100644 GIT binary patch delta 295 zcmbO%vOsi#h*2klmXE}~SHuAZ6LT)($s5_uZT#EDD%_)xuh6JasgR{mqQK8kq)@KV zzIg`QbVe&=+!E-?EzH{Xil=ssky-kiB^)guLvsK@H{R?KxP)>|^yO%CVy zB@d)$^aDi>DRlJ%Rjt;j`sL%%3{ol84m%({uLocKAN~T^W5Q`Z^ zusF|YRGibKIHy^0rD-p#^GfDkHs_U$z1&VK9eNuTfn12(0g&7un4Hh%7S@TO49p4+ hKUse|Fo@5Yz`C-50c6{2kP}uiF!TdmmEh{{1^_H%fC&Hq delta 155 zcmZ1=I$30bh_nTR@X7{;ex_gbult#Q)vsh==x6;^&tPKC`Ec?9#&erR7~5Dy`5C$t z@)a5tDiyL6N));k_!){6$~UiNo6e}wyM=WDRhA>Tdh&`%g3V`q*4mxg30Zi3z%K~-2fU^KfC|{ diff --git a/patches/rom_map/Bank 8B.txt b/patches/rom_map/Bank 8B.txt index 0592e9e216..311745e6a0 100644 --- a/patches/rom_map/Bank 8B.txt +++ b/patches/rom_map/Bank 8B.txt @@ -1,4 +1,5 @@ 0000 - F75F: used by vanilla game F760 - F770: used by `escape_items.asm` for adjusting item percent calculation F770 - F900: used by `credits.asm` -F900 - F940: used by `escape.asm` for adjusting item percent calculation \ No newline at end of file +F900 - F940: used by `escape.asm` for adjusting item percent calculation +F940 - F960: used by 'self-check.asm' \ No newline at end of file diff --git a/patches/rom_map/RAM.txt b/patches/rom_map/RAM.txt index 9b4919b17f..83db30ced9 100644 --- a/patches/rom_map/RAM.txt +++ b/patches/rom_map/RAM.txt @@ -1,5 +1,7 @@ $95: temporary variable (unused debug location) - used by extended messageboxes, safe to use outside message boxes. $9B: decompression.asm +$0336 - $033A - self_check.asm [rom checksum calucation] +$033B - $033F - free $09EC: number of disabled ETanks (saved to SRAM) $0A1A: previous reserve health (reserve_hud.asm) $1F5B: map area (like $079F) @@ -56,5 +58,4 @@ $7EFE90-$7EFE92: $7EFE92-$7EFE94: Saved special Samus palette type (applicable if flash suit is stored) $7EFE94-7EFF00: [FREE] (save slot-specific data to be copied to SRAM) $7EFF00-7F0000: [FREE] -$7ff800-7ff805: self_check.asm $7fffe8: scroll speed (credits.asm) \ No newline at end of file diff --git a/patches/rom_map/vanilla_hooks.txt b/patches/rom_map/vanilla_hooks.txt index f406e1ba17..2947852671 100644 --- a/patches/rom_map/vanilla_hooks.txt +++ b/patches/rom_map/vanilla_hooks.txt @@ -77,9 +77,8 @@ $809668 - reserve_hud.asm $8095a1 - samus_tiles_optim_animated_tiles_fix.asm $80a0d5 - samus_tiles_optim_animated_tiles_fix.asm $809416 - samus_tiles_optim_animated_tiles_fix.asm -$808438 - self_check.asm $808340 - self_check.asm -$80b437 - self_check.asm +$808489 - self_check.asm $808000 - sram_check_disable.asm $808455 - stats.asm $809589 - stats.asm @@ -704,6 +703,7 @@ $8a8000 - hud_expansion_opaque.asm $8a8000 - ultra_low_qol_hud_expansion_opaque.asm [BANK 8B] +$8b9155 - self_check.asm $8b9976 - credits.asm $8b999b - credits.asm $8b99e5 - credits.asm diff --git a/patches/src/self_check.asm b/patches/src/self_check.asm index 27fa26e3e4..5500034164 100644 --- a/patches/src/self_check.asm +++ b/patches/src/self_check.asm @@ -11,40 +11,30 @@ arch snes.cpu lorom +!bank_8b_free_space_start = $8bf940 +!bank_8b_free_space_end = $8bf960 + !bank_80_free_space_start = $80BC37 !bank_80_free_space_end = $80C437 -!sram_msg_end = $80BC37 - -!bank = $7ffa02 -!offset = $7ffa03 -!checksum = $7ffa05 - - -; bootloop burns 4 frames during bootup, our init code fits exactly here and avoids a jump. - -;$80:8438 E2 30 SEP #$30 -;$80:843A A2 04 LDX #$04 ;\ -; ;| -;$80:843C AD 12 42 LDA $4212 ;| -;$80:843F 10 FB BPL $FB [$843C] ;| -; ;} Wait the remainder of this frame and 3 more frames -;$80:8441 AD 12 42 LDA $4212 ;| -;$80:8444 30 FB BMI $FB [$8441] ;| -;$80:8446 CA DEX ;| -;$80:8447 D0 F3 BNE $F3 [$843C] ;/ -;$80:8449 C2 30 REP #$30 -;$80:844B A2 FE 1F LDX #$1FFE - -org $808438 - lda #$0080 - sta !bank - xba - sta !offset - lda #$0000 - sta !checksum -assert pc() <= $80844B ; lets not overwrite the next instruction. +!chksum_fail_msg_start = $80B437 +!chksum_fail_msg_end = $80BC37 + +!bank = $7e0336 +!offset = $7e0337 +!checksum = $7e0339 +; hook the common boot section clear bank $7e routine and replace with one that won't clobber our checksum variables (already in use by this time) +;$80:8489 C2 30 REP #$30 <- starting here +;$80:84B1 E2 30 SEP #$30 +;$80:84B3 9C 00 42 STZ $4200 <-- jumping back to here (the new clear sram routine calls sep #$30 so it leaves the routine in that state negating +; the need for it again at 84b1.. it 84b3 is overwritten by nop in stats.asm but code returns to the vanilla location incase stats.asm ever changes. + + +org $808489 + jmp clear_7e_safe + nop #39 + ; Hook the wait-for-NMI idle loop: ;$80:8340 8D B4 05 STA $05B4 [$7E:05B4] ;} NMI request flag = 1 @@ -205,11 +195,45 @@ endfor .crash bra .crash -print pc +clear_7e_safe: ;replaces the stock clear bank 7e unrolled stz routine on boot but does not clear the checksum locations. +; dma clear (relies on rom header 80:0002 being vanilla 0000) + sep #$30 + lda #$08 + sta $4300 + lda #$80 + sta $4301 + lda #$02 + sta $4302 + lda #$80 + sta $4303 + lda #$80 + sta $4304 + stz $2181 + stz $2182 + stz $2183 + lda #$35 + sta $4305 + lda #$03 + sta $4306 + lda #$01 + sta $420B + lda #$40 + sta $2181 + lda #$03 + sta $2182 + stz $2183 + lda #$C0 + sta $4305 + lda #$FC + sta $4306 + lda #$01 + sta $420B + jmp $84B3 ; return to next instruction in common boot sequence. + assert pc() <= !bank_80_free_space_end table "tables/menu.tbl",RTL -org $80B437 ; replace the stock SRAM error with our own . +org !chksum_fail_msg_start ; replace the stock SRAM error with our own . dw " " dw " " @@ -236,7 +260,7 @@ dw " " dw " - 3RD PARTY ROM PATCHING TOOLS " dw " NOT FIXING ROM CHECKSUM " dw " " -dw " - SD2SNES (FXPAK) INGAME HOOKS " +dw " - SD2SNES:FXPAK IN-GAME HOOKS " dw " " dw " " dw " " @@ -244,4 +268,20 @@ dw " " dw " " dw " " -assert pc() <= !sram_msg_end \ No newline at end of file +assert pc() <= !chksum_fail_msg_end + +org $8b9155 ;$8B:9155 9C 90 05 STZ $0590 [$7E:0590] ; OAM stack pointer = 0 + jsr init_chksum_variables + +org !bank_8b_free_space_start +init_chksum_variables: + stz $0590 ; hijacked instruction + lda #$0080 + sta !bank + xba + sta !offset + lda #$0000 + sta !checksum + rts + +assert pc() <= !bank_8b_free_space_end