diff --git a/patches/ips/extra_setup.ips b/patches/ips/extra_setup.ips new file mode 100644 index 000000000..bbc0dfaca Binary files /dev/null and b/patches/ips/extra_setup.ips differ diff --git a/patches/ips/hazard_markers.ips b/patches/ips/hazard_markers.ips index 8abafe56f..5bffe24a0 100644 Binary files a/patches/ips/hazard_markers.ips and b/patches/ips/hazard_markers.ips differ diff --git a/patches/src/extra_setup.asm b/patches/src/extra_setup.asm new file mode 100644 index 000000000..7d812314a --- /dev/null +++ b/patches/src/extra_setup.asm @@ -0,0 +1,45 @@ +lorom + +incsrc "constants.asm" + + +!bank_b8_free_space_start = $B88000 +!bank_b8_free_space_end = $B88100 + +!bank_8f_free_space_start = $8FFE80 +!bank_8f_free_space_end = $8FFF00 + + +; hook extra setup ASM to run right before normal setup ASM +; (careful: escape.asm hijacks the instruction after this) +org $8FE893 + jsr run_extra_setup_asm_wrapper + +org !bank_b8_free_space_start + +run_extra_setup_asm: + ; get extra setup ASM pointer to run in bank B5 (using pointer in room state almost completely unused by vanilla, only for X-ray override in BT Room in escape) + ldx $07bb ; x <- room state pointer + lda $8F0010,x + tax ; x <- extra room data pointer + lda $B80001,x ; a <- [extra room data pointer + 1] + beq .skip + sta $1F68 ; write setup ASM pointer temporarily to $1F68, so we can jump to it with JSR. (Is there a less awkward way to do this?) + ldx #$0000 + jsr ($1F68, x) + +.skip: + ; run hi-jacked instructions + ldx $07BB + lda $0018,x + rtl + +assert pc() <= !bank_b8_free_space_end + +org !bank_8f_free_space_start + +run_extra_setup_asm_wrapper: + jsl run_extra_setup_asm + rts + +assert pc() <= !bank_8f_free_space_end \ No newline at end of file diff --git a/patches/src/hazard_markers.asm b/patches/src/hazard_markers.asm index 7a44cbcab..0651d5f93 100644 --- a/patches/src/hazard_markers.asm +++ b/patches/src/hazard_markers.asm @@ -4,58 +4,19 @@ incsrc "constants.asm" !bank_84_free_space_start = $84F800 ; must match address in patch.rs !bank_84_free_space_end = $84F900 -!bank_8f_free_space_start = $8FFE80 -!bank_8f_free_space_end = $8FFF00 -!bank_b8_free_space_start = $B88000 -!bank_b8_free_space_end = $B88100 !hazard_tilemap_size = #$0020 org $82E845 jsl load_hazard_tilemap_initial_hook - rep 3 : nop + nop #3 ; hook door transition org $82EB20 jsl reload_hazard_tiles nop : nop -; hook extra setup ASM to run right before normal setup ASM -; (careful: escape.asm hijacks the instruction after this) -org $8FE893 - jsr run_extra_setup_asm_wrapper - -org !bank_b8_free_space_start - -run_extra_setup_asm: - ; get extra setup ASM pointer to run in bank B5 (using pointer in room state almost completely unused by vanilla, only for X-ray override in BT Room in escape) - ldx $07bb ; x <- room state pointer - lda $8F0010,x - tax ; x <- extra room data pointer - lda $B80001,x ; a <- [extra room data pointer + 1] - beq .skip - sta $1F68 ; write setup ASM pointer temporarily to $1F68, so we can jump to it with JSR. (Is there a less awkward way to do this?) - ldx #$0000 - jsr ($1F68, x) - -.skip: - ; run hi-jacked instructions - ldx $07BB - lda $0018,x - rtl - -warnpc !bank_b8_free_space_end - -org !bank_8f_free_space_start - -run_extra_setup_asm_wrapper: - jsl run_extra_setup_asm - rts - -warnpc !bank_8f_free_space_end - - org !bank_84_free_space_start ; These PLMs definitions must go here first, as they are referenced in patch.rs @@ -158,4 +119,4 @@ elevator_hazard_with_scroll_draw: dw $0002, $00E5, $34E5 ; use special air block type, to preserve scroll PLM dw $0000 -warnpc !bank_84_free_space_end \ No newline at end of file +assert pc() <= !bank_84_free_space_end \ No newline at end of file diff --git a/rust/maprando/src/patch.rs b/rust/maprando/src/patch.rs index 24bfe09f6..ddbb01f47 100644 --- a/rust/maprando/src/patch.rs +++ b/rust/maprando/src/patch.rs @@ -483,6 +483,7 @@ impl Patcher<'_> { "fix_kraid_hud", "fix_kraid_door", "boss_exit", + "extra_setup", "load_plms_early", "spin_lock", "fix_transition_bad_tiles",