Optimize some HRAM usage

This commit is contained in:
xCrystal
2023-09-30 19:12:57 +02:00
parent 336b3e77af
commit e53ae0eac9
48 changed files with 254 additions and 258 deletions

View File

@ -72,8 +72,8 @@ DEF MONMENU_MENUOPTION EQU 1
DEF NUM_MONMENU_ITEMS EQU 8 DEF NUM_MONMENU_ITEMS EQU 8
; start/select menu return values ; start/select menu return values
DEF HMENURETURN_SCRIPT EQU %10000000 DEF MENURETURN_SCRIPT EQU %10000000
DEF HMENURETURN_ASM EQU %11111111 DEF MENURETURN_ASM EQU %11111111
; PartyMenuQualityPointers indexes (see data/party_menu_qualities.asm) ; PartyMenuQualityPointers indexes (see data/party_menu_qualities.asm)
const_def const_def

View File

@ -1,5 +1,5 @@
; Special routines can be used with the "special" map script command. ; Special routines can be used with the "special" map script command.
; They often use wScriptVar for arguments and return values. ; They often use hScriptVar for arguments and return values.
MACRO add_special MACRO add_special
\1Special:: \1Special::

View File

@ -2304,7 +2304,7 @@ This is a bug with `HaircutOrGrooming` in [engine/events/haircut.asm](https://gi
.ok .ok
inc hl inc hl
ld a, [hli] ld a, [hli]
ld [wScriptVar], a ldh [hScriptVar], a
ld c, [hl] ld c, [hl]
call ChangeHappiness call ChangeHappiness
ret ret

View File

@ -102,7 +102,7 @@ $~~~~$*Exit overworld loop*
--- ---
wMapStatus == MAPSTATUS_HANDLE: <c>the remainder of the code goes at this level</c> wMapStatus == MAPSTATUS_HANDLE: <c>the remainder of the code goes at this level</c>
> wOverworldDelay <= 2 <c>2 is *MaxOverworldDelay*</c>\ > hOverworldDelay <= 2 <c>2 is *MaxOverworldDelay*</c>\
> MapEventStatus == MAPEVENTS_ON:\ > MapEventStatus == MAPEVENTS_ON:\
>$~~~~$*Get joypad* <c>update hJoyDown, hJoyReleased, hJoyPressed</c>\ >$~~~~$*Get joypad* <c>update hJoyDown, hJoyReleased, hJoyPressed</c>\
>$~~~~$*Refresh pals* >$~~~~$*Refresh pals*
@ -295,7 +295,7 @@ wMapStatus == MAPSTATUS_HANDLE: <c>the remainder of the code goes at this level<
>> **CheckObjectEnteringVisibleRange** (wPlayerStepFlags[PLAYERSTEP_STOP_F] == TRUE) >> **CheckObjectEnteringVisibleRange** (wPlayerStepFlags[PLAYERSTEP_STOP_F] == TRUE)
> DelayFrames(wOverworldDelay) > DelayFrames(hOverworldDelay)
> <f>**HandleMapBackground**</f> <c>_UpdateSprites + ScrollScreen</c> > <f>**HandleMapBackground**</f> <c>_UpdateSprites + ScrollScreen</c>

View File

@ -70,12 +70,12 @@ Until this document is filled out, the [G/S Scripting Compendium](https://hax.ii
## `$15`: <code>setval <i>value</i></code> ## `$15`: <code>setval <i>value</i></code>
<code>[wScriptVar] = <i>value</i></code> <code>[hScriptVar] = <i>value</i></code>
## `$16`: <code>addval <i>value</i></code> ## `$16`: <code>addval <i>value</i></code>
<code>[wScriptVar] += <i>value</i></code> <code>[hScriptVar] += <i>value</i></code>
## `$17`: <code>random <i>value</i></code> ## `$17`: <code>random <i>value</i></code>
@ -86,12 +86,12 @@ Until this document is filled out, the [G/S Scripting Compendium](https://hax.ii
## `$19`: <code>readmem <i>address</i></code> ## `$19`: <code>readmem <i>address</i></code>
<code>[wScriptVar] = [<i>address</i>]</code> <code>[hScriptVar] = [<i>address</i>]</code>
## `$1A`: <code>writemem <i>address</i></code> ## `$1A`: <code>writemem <i>address</i></code>
<code>[<i>address</i>] = [wScriptVar]</code> <code>[<i>address</i>] = [hScriptVar]</code>
## `$1B`: <code>loadmem <i>address</i>, <i>value</i></code> ## `$1B`: <code>loadmem <i>address</i>, <i>value</i></code>
@ -101,12 +101,12 @@ Until this document is filled out, the [G/S Scripting Compendium](https://hax.ii
## `$1C`: <code>readvar <i>variable</i></code> ## `$1C`: <code>readvar <i>variable</i></code>
<code>[wScriptVar] = GetVarAction(<i>variable</i>)</code> <code>[hScriptVar] = GetVarAction(<i>variable</i>)</code>
## `$1D`: <code>writevar <i>variable</i></code> ## `$1D`: <code>writevar <i>variable</i></code>
<code>GetVarAction(<i>variable</i>) = [wScriptVar]</code> <code>GetVarAction(<i>variable</i>) = [hScriptVar]</code>
## `$1E`: <code>loadvar <i>variable</i>, <i>value</i></code> ## `$1E`: <code>loadvar <i>variable</i>, <i>value</i></code>
@ -216,21 +216,21 @@ Until this document is filled out, the [G/S Scripting Compendium](https://hax.ii
## `$3F`: <code>getnum <i>string_buffer</i></code> ## `$3F`: <code>getnum <i>string_buffer</i></code>
<code>GetStringBuffer(<i>string_buffer</i>) = PrintNum([wScriptVar])</code> <code>GetStringBuffer(<i>string_buffer</i>) = PrintNum([hScriptVar])</code>
## `$40`: <code>getmonname <i>string_buffer</i>, <i>mon_id</i></code> ## `$40`: <code>getmonname <i>string_buffer</i>, <i>mon_id</i></code>
<code>GetStringBuffer(<i>string_buffer</i>) = GetPokemonName(<i>mon_id</i>)</code> <code>GetStringBuffer(<i>string_buffer</i>) = GetPokemonName(<i>mon_id</i>)</code>
If <code><i>mon_id</i></code> = `USE_SCRIPT_VAR`, then it uses `[wScriptVar]` instead. If <code><i>mon_id</i></code> = `USE_SCRIPT_VAR`, then it uses `[hScriptVar]` instead.
## `$41`: <code>getitemname <i>string_buffer</i>, <i>item_id</i></code> ## `$41`: <code>getitemname <i>string_buffer</i>, <i>item_id</i></code>
<code>GetStringBuffer(<i>string_buffer</i>) = GetItemName(<i>item_id</i>)</code> <code>GetStringBuffer(<i>string_buffer</i>) = GetItemName(<i>item_id</i>)</code>
If <code><i>item_id</i></code> = `USE_SCRIPT_VAR`, then it uses `[wScriptVar]` instead. If <code><i>item_id</i></code> = `USE_SCRIPT_VAR`, then it uses `[hScriptVar]` instead.
## `$42`: <code>getcurlandmarkname <i>string_buffer</i></code> ## `$42`: <code>getcurlandmarkname <i>string_buffer</i></code>

View File

@ -193,9 +193,9 @@ BattleAnimDelayFrame:
; Like DelayFrame but wastes battery life. ; Like DelayFrame but wastes battery life.
ld a, 1 ld a, 1
ld [wVBlankOccurred], a ldh [hVBlankOccurred], a
.wait .wait
ld a, [wVBlankOccurred] ldh a, [hVBlankOccurred]
and a and a
jr nz, .wait jr nz, .wait
ret ret

View File

@ -53,11 +53,11 @@ BoardMenuScript::
done done
.SubmenuCallback: .SubmenuCallback:
; if submenu has requested a callback through hMenuReturn, ; if submenu has requested a callback through wMenuReturn,
; it has also taken care of queuing it into wQueuedScriptBank/wQueuedScriptAddr. ; it has also taken care of queuing it into wQueuedScriptBank/wQueuedScriptAddr.
readmem hMenuReturn readmem wMenuReturn
ifequal HMENURETURN_SCRIPT, .CallbackScript ifequal MENURETURN_SCRIPT, .CallbackScript
ifequal HMENURETURN_ASM, .CallbackAsm ifequal MENURETURN_ASM, .CallbackAsm
end end
.CallbackScript: .CallbackScript:
@ -68,7 +68,7 @@ BoardMenuScript::
end end
BoardMenu:: BoardMenu::
; returns the selected menu item (BOARDMENUITEM_*) in wScriptVar upon exit ; returns the selected menu item (BOARDMENUITEM_*) in hScriptVar upon exit
ld a, [wBoardMenuLastCursorPosition] ld a, [wBoardMenuLastCursorPosition]
cp NUM_BOARD_MENU_ITEMS cp NUM_BOARD_MENU_ITEMS
jr c, .ok jr c, .ok
@ -107,7 +107,7 @@ BoardMenu::
ld hl, wDisplaySecondarySprites ld hl, wDisplaySecondarySprites
res SECONDARYSPRITES_BOARD_MENU_F, [hl] res SECONDARYSPRITES_BOARD_MENU_F, [hl]
ld a, [wBoardMenuCursorPosition] ld a, [wBoardMenuCursorPosition]
ld [wScriptVar], a ldh [hScriptVar], a
ret ret
DrawBoardMenuTilesAndClearPriorityAttr: DrawBoardMenuTilesAndClearPriorityAttr:
@ -217,13 +217,13 @@ DIE_MAX_NUMBER EQU 6
ld hl, wDisplaySecondarySprites ld hl, wDisplaySecondarySprites
res SECONDARYSPRITES_DIE_ROLL_F, [hl] res SECONDARYSPRITES_DIE_ROLL_F, [hl]
xor a ; FALSE xor a ; FALSE
ld [wScriptVar], a ldh [hScriptVar], a
ret ret
.confirm_roll .confirm_roll
call UpdateSprites call UpdateSprites
ld a, TRUE ld a, TRUE
ld [wScriptVar], a ldh [hScriptVar], a
ret ret
BoardMenu_BreakDieAnimation: BoardMenu_BreakDieAnimation:
@ -341,8 +341,8 @@ BoardMenu_Party:
.quit .quit
; if quitted party menu after using field move ; if quitted party menu after using field move
call BoardMenu_CloseSubmenu call BoardMenu_CloseSubmenu
ld a, HMENURETURN_SCRIPT ld a, MENURETURN_SCRIPT
ldh [hMenuReturn], a ld [wMenuReturn], a
ret ret
BoardMenu_Pack: BoardMenu_Pack:
@ -352,8 +352,8 @@ BoardMenu_Pack:
ld a, [wPackUsedItem] ld a, [wPackUsedItem]
and a and a
ret z ret z
ld a, HMENURETURN_SCRIPT ld a, MENURETURN_SCRIPT
ldh [hMenuReturn], a ld [wMenuReturn], a
ret ret
BoardMenu_Pokegear: BoardMenu_Pokegear:
@ -363,7 +363,7 @@ BoardMenu_Pokegear:
BoardMenu_OpenSubmenu: BoardMenu_OpenSubmenu:
xor a xor a
ldh [hMenuReturn], a ld [wMenuReturn], a
ldh [hBGMapMode], a ldh [hBGMapMode], a
call LoadStandardMenuHeader call LoadStandardMenuHeader
farcall FadeOutPalettesToWhite farcall FadeOutPalettesToWhite

View File

@ -24,7 +24,7 @@ BuenasPassword:
.wrong .wrong
ld a, b ld a, b
ld [wScriptVar], a ldh [hScriptVar], a
ret ret
.MenuHeader: .MenuHeader:

View File

@ -5,7 +5,7 @@ AskRememberPassword:
ld a, $1 ld a, $1
.okay .okay
ld [wScriptVar], a ldh [hScriptVar], a
ret ret
.DoMenu: .DoMenu:

View File

@ -88,12 +88,12 @@ ContestDropOffMons:
; ... and replacing it with the terminator byte ; ... and replacing it with the terminator byte
ld [hl], -1 ld [hl], -1
xor a xor a
ld [wScriptVar], a ldh [hScriptVar], a
ret ret
.fainted .fainted
ld a, $1 ld a, $1
ld [wScriptVar], a ldh [hScriptVar], a
ret ret
ContestReturnMons: ContestReturnMons:

View File

@ -303,12 +303,12 @@ CheckCaughtCelebi:
bit BATTLERESULT_CAUGHT_CELEBI, a bit BATTLERESULT_CAUGHT_CELEBI, a
jr z, .false jr z, .false
ld a, TRUE ld a, TRUE
ld [wScriptVar], a ldh [hScriptVar], a
jr .done jr .done
.false .false
xor a ; FALSE xor a ; FALSE
ld [wScriptVar], a ldh [hScriptVar], a
.done .done
ret ret

View File

@ -413,14 +413,14 @@ DayCareManOutside:
.Load0: .Load0:
call PrintText1bpp call PrintText1bpp
xor a ; FALSE xor a ; FALSE
ld [wScriptVar], a ldh [hScriptVar], a
ret ret
.PartyFull: .PartyFull:
ld hl, .NoRoomForEggText ld hl, .NoRoomForEggText
call PrintText1bpp call PrintText1bpp
ld a, TRUE ld a, TRUE
ld [wScriptVar], a ldh [hScriptVar], a
ret ret
.FoundAnEggText: .FoundAnEggText:

View File

@ -1,9 +1,9 @@
GiveDratini: GiveDratini:
; if wScriptVar is 0 or 1, change the moveset of the last Dratini in the party. ; if hScriptVar is 0 or 1, change the moveset of the last Dratini in the party.
; 0: give it a special moveset with Extremespeed. ; 0: give it a special moveset with Extremespeed.
; 1: give it the normal moveset of a level 15 Dratini. ; 1: give it the normal moveset of a level 15 Dratini.
ld a, [wScriptVar] ldh a, [hScriptVar]
cp $2 cp $2
ret nc ret nc
ld bc, wPartyCount ld bc, wPartyCount
@ -30,7 +30,7 @@ GiveDratini:
.GiveMoveset: .GiveMoveset:
push hl push hl
ld a, [wScriptVar] ldh a, [hScriptVar]
ld hl, .Movesets ld hl, .Movesets
ld bc, .Moveset1 - .Moveset0 ld bc, .Moveset1 - .Moveset0
call AddNTimes call AddNTimes

View File

@ -50,7 +50,7 @@ CheckFruitTree:
ld b, 2 ld b, 2
call GetFruitTreeFlag call GetFruitTreeFlag
ld a, c ld a, c
ld [wScriptVar], a ldh [hScriptVar], a
ret ret
PickedFruitTree: PickedFruitTree:

View File

@ -2,14 +2,14 @@ BillsGrandfather:
farcall SelectMonFromParty farcall SelectMonFromParty
jr c, .cancel jr c, .cancel
ld a, [wCurPartySpecies] ld a, [wCurPartySpecies]
ld [wScriptVar], a ldh [hScriptVar], a
ld [wNamedObjectIndex], a ld [wNamedObjectIndex], a
call GetPokemonName call GetPokemonName
jp CopyPokemonName_Buffer1_Buffer3 jp CopyPokemonName_Buffer1_Buffer3
.cancel .cancel
xor a xor a
ld [wScriptVar], a ldh [hScriptVar], a
ret ret
OlderHaircutBrother: OlderHaircutBrother:
@ -48,19 +48,19 @@ HaircutOrGrooming:
.ok .ok
inc hl inc hl
ld a, [hli] ld a, [hli]
ld [wScriptVar], a ldh [hScriptVar], a
ld c, [hl] ld c, [hl]
call ChangeHappiness call ChangeHappiness
ret ret
.nope .nope
xor a xor a
ld [wScriptVar], a ldh [hScriptVar], a
ret ret
.egg .egg
ld a, 1 ld a, 1
ld [wScriptVar], a ldh [hScriptVar], a
ret ret
INCLUDE "data/events/happiness_probabilities.asm" INCLUDE "data/events/happiness_probabilities.asm"

View File

@ -13,7 +13,7 @@ GetFirstPokemonHappiness:
.done .done
ld [wNamedObjectIndex], a ld [wNamedObjectIndex], a
ld a, [hl] ld a, [hl]
ld [wScriptVar], a ldh [hScriptVar], a
call GetPokemonName call GetPokemonName
jp CopyPokemonName_Buffer1_Buffer3 jp CopyPokemonName_Buffer1_Buffer3
@ -26,7 +26,7 @@ CheckFirstMonIsEgg:
xor a xor a
.egg .egg
ld [wScriptVar], a ldh [hScriptVar], a
call GetPokemonName call GetPokemonName
jp CopyPokemonName_Buffer1_Buffer3 jp CopyPokemonName_Buffer1_Buffer3

View File

@ -12,11 +12,11 @@ HealMachineAnim:
ld a, [wPartyCount] ld a, [wPartyCount]
and a and a
ret z ret z
; The location of the healing machine relative to the player is stored in wScriptVar. ; The location of the healing machine relative to the player is stored in hScriptVar.
; 0: Up and left (Pokemon Center) ; 0: Up and left (Pokemon Center)
; 1: Left (Elm's Lab) ; 1: Left (Elm's Lab)
; 2: Up (Hall of Fame) ; 2: Up (Hall of Fame)
ld a, [wScriptVar] ldh a, [hScriptVar]
ld [wHealMachineAnimType], a ld [wHealMachineAnimType], a
ldh a, [rOBP1] ldh a, [rOBP1]
ld [wHealMachineTempOBP1], a ld [wHealMachineTempOBP1], a

View File

@ -30,7 +30,7 @@ SelectApricornForKurt:
ld [wMenuSelection], a ld [wMenuSelection], a
call Kurt_SelectApricorn call Kurt_SelectApricorn
ld a, c ld a, c
ld [wScriptVar], a ldh [hScriptVar], a
and a and a
jr z, .done jr z, .done
ld [wCurItem], a ld [wCurItem], a

View File

@ -1,6 +1,6 @@
CheckForLuckyNumberWinners: CheckForLuckyNumberWinners:
xor a xor a
ld [wScriptVar], a ldh [hScriptVar], a
ld [wTempByteValue], a ld [wTempByteValue], a
ld a, [wPartyCount] ld a, [wPartyCount]
and a and a
@ -79,7 +79,7 @@ CheckForLuckyNumberWinners:
cp EGG cp EGG
jr z, .SkipBoxMon jr z, .SkipBoxMon
call .CompareLuckyNumberToMonID ; sets wScriptVar and wCurPartySpecies appropriately call .CompareLuckyNumberToMonID ; sets hScriptVar and wCurPartySpecies appropriately
jr nc, .SkipBoxMon jr nc, .SkipBoxMon
ld a, TRUE ld a, TRUE
ld [wTempByteValue], a ld [wTempByteValue], a
@ -100,7 +100,7 @@ CheckForLuckyNumberWinners:
jr c, .BoxesLoop jr c, .BoxesLoop
call CloseSRAM call CloseSRAM
ld a, [wScriptVar] ldh a, [hScriptVar]
and a and a
ret z ; found nothing ret z ; found nothing
@ -167,7 +167,7 @@ CheckForLuckyNumberWinners:
.okay .okay
inc b inc b
ld a, [wScriptVar] ldh a, [hScriptVar]
and a and a
jr z, .bettermatch jr z, .bettermatch
cp b cp b
@ -176,7 +176,7 @@ CheckForLuckyNumberWinners:
.bettermatch .bettermatch
dec b dec b
ld a, b ld a, b
ld [wScriptVar], a ldh [hScriptVar], a
pop bc pop bc
ld a, b ld a, b
ld [wCurPartySpecies], a ld [wCurPartySpecies], a

View File

@ -52,22 +52,22 @@ CheckMagikarpLength:
call SkipNames call SkipNames
call CopyBytes call CopyBytes
ld a, MAGIKARPLENGTH_BEAT_RECORD ld a, MAGIKARPLENGTH_BEAT_RECORD
ld [wScriptVar], a ldh [hScriptVar], a
ret ret
.not_long_enough .not_long_enough
ld a, MAGIKARPLENGTH_TOO_SHORT ld a, MAGIKARPLENGTH_TOO_SHORT
ld [wScriptVar], a ldh [hScriptVar], a
ret ret
.declined .declined
ld a, MAGIKARPLENGTH_REFUSED ld a, MAGIKARPLENGTH_REFUSED
ld [wScriptVar], a ldh [hScriptVar], a
ret ret
.not_magikarp .not_magikarp
xor a ; MAGIKARPLENGTH_NOT_MAGIKARP xor a ; MAGIKARPLENGTH_NOT_MAGIKARP
ld [wScriptVar], a ldh [hScriptVar], a
ret ret
.MagikarpGuruMeasureText: .MagikarpGuruMeasureText:

Some files were not shown because too many files have changed in this diff Show More