From 209324ee89f6593acb090392656cce0df36a4793 Mon Sep 17 00:00:00 2001 From: robjlyons <81177492+robjlyons@users.noreply.github.com> Date: Wed, 18 Feb 2026 23:50:14 +0000 Subject: [PATCH] Use shared SRAM API for item encounter-catch flags --- engine/battle/core.asm | 15 +++++---------- engine/events/poison.asm | 32 +++----------------------------- engine/items/item_effects.asm | 13 +++++-------- 3 files changed, 13 insertions(+), 47 deletions(-) diff --git a/engine/battle/core.asm b/engine/battle/core.asm index f13ed4b7..9f45c390 100644 --- a/engine/battle/core.asm +++ b/engine/battle/core.asm @@ -1194,18 +1194,13 @@ EnsureEncounterCatchFlagsInitialized: ret EnableEncounterCatchSRAM_Battle: - ld a, $0A - ld [$0000], a ; enable SRAM - ld a, $01 - ld [$6000], a ; MBC1: RAM banking mode (harmless on others) - ld a, BANK(sMapEncounterCatchFlags) - ld [$4000], a ; select SRAM bank that holds the flags - ret + ld a, BANK(sMapEncounterCatchFlags) + call OpenSRAM + ret DisableEncounterCatchSRAM_Battle: - xor a - ld [$0000], a ; disable SRAM - ret + call CloseSRAM + ret ; asks if you want to use next mon ; stores whether you ran in C flag diff --git a/engine/events/poison.asm b/engine/events/poison.asm index 9d87b3ca..f3c66345 100644 --- a/engine/events/poison.asm +++ b/engine/events/poison.asm @@ -68,7 +68,9 @@ ApplyOutOfBattlePoisonDamage: callfar PlayPikachuSoundClip callfar_ModifyPikachuHappiness PIKAHAPPY_PSNFNT .curMonNotPlayerPikachu - call HandlePoisonFaintedMonRanAway + ld a, [wWhichPokemon] + ld [wPlayerMonNumber], a + callfar HandleFaintedPlayerMonRanAway pop de pop hl jr .restartAfterRemoval @@ -148,34 +150,6 @@ ApplyOutOfBattlePoisonDamage: ld [wOutOfBattleBlackout], a ret -PoisonFaintedMonRanAwayText: - text_far _PokemonRanAwayBadTrainingText - text_end - -HandlePoisonFaintedMonRanAway: - ld a, [wPartyCount] - cp 1 - ret z ; don't remove the final party mon to avoid invalid 0-mon party state - ld hl, wPartyMonNicks - call GetPartyMonName - ld hl, PoisonFaintedMonRanAwayText - call PrintText - xor a - ld [wRemoveMonFromBox], a - call RemovePokemon - ld a, [wPartyCount] - and a - ret z - dec a - ld b, a - ld a, [wWhichPokemon] - cp b - jr c, .done - ld a, b - ld [wWhichPokemon], a -.done - ret - Func_c4c7: ld a, [wStepCounter] and a diff --git a/engine/items/item_effects.asm b/engine/items/item_effects.asm index 1f6b4d34..3da0d25d 100644 --- a/engine/items/item_effects.asm +++ b/engine/items/item_effects.asm @@ -2669,16 +2669,13 @@ MarkWildEncounterCatchUsedItem: ret EnableEncounterCatchSRAM_Item: - ld a, $0A - ld [$0000], a ; enable SRAM - xor a - ld [$4000], a ; SRAM bank 0 - ret + ld a, BANK(sMapEncounterCatchFlags) + call OpenSRAM + ret DisableEncounterCatchSRAM_Item: - xor a - ld [$0000], a ; disable SRAM - ret + call CloseSRAM + ret NoCyclingAllowedHereText: text_far _NoCyclingAllowedHereText