Skip to content

Commit 6c1cb0e

Browse files
committed
add --sd-bootloader option. fix --no-smb2 deadlock.
1 parent e6de510 commit 6c1cb0e

File tree

6 files changed

+27
-2
lines changed

6 files changed

+27
-2
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ captures/
1212
.gdbinit
1313
*.ips
1414
ips/
15+
.venv

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ repos:
66
- id: black
77

88
- repo: https://github.com/pycqa/flake8
9-
rev: 3.9.2
9+
rev: 7.1.2
1010
hooks:
1111
- id: flake8
1212

Core/Src/main.c

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
#define BANK_1_STACK_2_ADDRESS 0x08020000
1515
#define BANK_2_ADDRESS 0x08100000
16+
#define SD_BOOTLOADER_ADDRESS 0x08032000
17+
1618
#define BOOTLOADER_MAGIC 0x544F4F42 // "BOOT"
1719
#define BOOTLOADER_MAGIC_ADDRESS ((uint32_t *)0x2001FFF8)
1820
#define BOOTLOADER_JUMP_ADDRESS ((uint32_t **)0x2001FFFC)
@@ -104,7 +106,11 @@ gamepad_t read_buttons() {
104106
#else
105107
if((gamepad & GAMEPAD_LEFT) && (gamepad & GAMEPAD_GAME)){
106108
#endif
109+
#if SD_BOOTLOADER
110+
set_bootloader(SD_BOOTLOADER_ADDRESS);
111+
#else
107112
set_bootloader(BANK_2_ADDRESS);
113+
#endif
108114
NVIC_SystemReset();
109115
}
110116

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ ifneq (,$(findstring --triple-boot, $(PATCH_PARAMS)))
8686
C_DEFS += -DTRIPLE_BOOT
8787
endif
8888

89+
ifneq (,$(findstring --sd-bootloader, $(PATCH_PARAMS)))
90+
C_DEFS += -DSD_BOOTLOADER
91+
endif
92+
8993

9094
#######################################
9195
# CFLAGS

patch.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ def main():
7878
action="store_true",
7979
help="Enable RIGHT+GAME to launch 0x08020000.",
8080
)
81+
parser.add_argument(
82+
"--sd-bootloader",
83+
action="store_true",
84+
help="Change target dual boot to 0x08032000.",
85+
)
8186
parser.add_argument(
8287
"--compression-ratio",
8388
type=float,
@@ -139,7 +144,9 @@ def main():
139144
device.internal[novel_code_start:] = patch[novel_code_start:]
140145
del patch
141146

142-
if args.extended:
147+
if args.sd_bootloader:
148+
device.internal.extend(b"\x00" * 0x12000)
149+
elif args.extended:
143150
device.internal.extend(b"\x00" * 0x20000)
144151

145152
print(Fore.BLUE)

patches/mario.py

+7
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ def argparse(self, parser):
182182
self.args.slim = True
183183
self.args.extended = True
184184
self.args.no_save = True
185+
if self.args.sd_bootloader:
186+
self.args.no_smb2 = True
185187

186188
if self.args.clock_only:
187189
self.args.slim = True
@@ -508,6 +510,11 @@ def patch(self):
508510
b"\x00" * smb2_size,
509511
)
510512
self.ext_offset -= smb2_size
513+
514+
# Replace conditional-branch with unconditional
515+
# TODO: this prevents hardlocking when selecting SMB2 from the menu,
516+
# but it's not quite right and is glitchy.
517+
self.internal.b(0x69FC, 0x6A8C)
511518
else:
512519
printe("Compressing and moving SMB2 ROM.")
513520
compressed_len = self.external.compress(smb2_addr, smb2_size)

0 commit comments

Comments
 (0)