ref: bcc0d633e948227e68da8a264d1533771a54b5c4
parent: ea426a88794b1d216a278b54d18cefafbf7d8771
author: Rangi <remy.oukaour+rangi42@gmail.com>
date: Thu Oct 29 10:45:40 EDT 2020
Identify the remaining (non-mobile) uses of another WRAM union
--- a/data/text/common_3.asm
+++ b/data/text/common_3.asm
@@ -72,7 +72,7 @@
_LinkAskTradeForText::
text "Trade @"
- text_ram wd004
+ text_ram wBufferTrademonNick
text_start
line "for @"
text_ram wStringBuffer1
--- a/docs/bugs_and_glitches.md
+++ b/docs/bugs_and_glitches.md
@@ -560,7 +560,7 @@
```diff
.got_mon
- ld a, [wd002]
+ ld a, [wCurBeatUpPartyMon]
ld hl, wPartyMonNicknames
call GetNick
ld a, MON_HP
@@ -568,7 +568,7 @@
ld a, [hli]
or [hl]
jp z, .beatup_fail ; fainted
- ld a, [wd002]
+ ld a, [wCurBeatUpPartyMon]
ld c, a
ld a, [wCurBattleMon]
- ; BUG: this can desynchronize link battles
--- a/engine/battle/core.asm
+++ b/engine/battle/core.asm
@@ -7438,13 +7438,13 @@
jp nc, .finish
ldh a, [hProduct + 3]
- ld [wd004], a
+ ld [wExperienceGained + 2], a
push af
ldh a, [hProduct + 2]
- ld [wd003], a
+ ld [wExperienceGained + 1], a
push af
xor a
- ld [wd002], a
+ ld [wExperienceGained], a
xor a ; PARTYMON
ld [wMonType], a
predef CopyMonToTempMon
@@ -7456,10 +7456,10 @@
call CalcExpBar
push bc
ld hl, wTempMonExp + 2
- ld a, [wd004]
+ ld a, [wExperienceGained + 2]
add [hl]
ld [hld], a
- ld a, [wd003]
+ ld a, [wExperienceGained + 1]
adc [hl]
ld [hld], a
jr nc, .NoOverflow
@@ -8788,7 +8788,7 @@
.FindOpponentAndAppendRecord:
ld b, NUM_LINK_BATTLE_RECORDS
ld hl, sLinkBattleRecord1End - 1
- ld de, wd002
+ ld de, wLinkBattleRecordBuffer
.loop3
push bc
push de
@@ -8817,8 +8817,8 @@
add b
add b
ld e, a
- ld d, $0
- ld hl, wd002
+ ld d, 0
+ ld hl, wLinkBattleRecordBuffer
add hl, de
push hl
ld a, c
@@ -8825,8 +8825,8 @@
add c
add c
ld e, a
- ld d, $0
- ld hl, wd002
+ ld d, 0
+ ld hl, wLinkBattleRecordBuffer
add hl, de
ld d, h
ld e, l
@@ -8858,7 +8858,7 @@
ld hl, sLinkBattleRecord
call AddNTimes
push hl
- ld de, wd002
+ ld de, wLinkBattleRecordBuffer
ld bc, LINK_BATTLE_RECORD_LENGTH
call CopyBytes
pop hl
@@ -8872,7 +8872,7 @@
push hl
ld bc, LINK_BATTLE_RECORD_LENGTH
call CopyBytes
- ld hl, wd002
+ ld hl, wLinkBattleRecordBuffer
ld bc, LINK_BATTLE_RECORD_LENGTH
pop de
call CopyBytes
--- a/engine/battle/move_effects/beat_up.asm
+++ b/engine/battle/move_effects/beat_up.asm
@@ -14,7 +14,7 @@
call DelayFrames
xor a
ld [wPlayerRolloutCount], a
- ld [wd002], a
+ ld [wCurBeatUpPartyMon], a
ld [wBeatUpHitAtLeastOnce], a
jr .got_mon
@@ -23,10 +23,10 @@
ld b, a
ld a, [wPartyCount]
sub b
- ld [wd002], a
+ ld [wCurBeatUpPartyMon], a
.got_mon
- ld a, [wd002]
+ ld a, [wCurBeatUpPartyMon]
ld hl, wPartyMonNicknames
call GetNick
ld a, MON_HP
@@ -34,7 +34,7 @@
ld a, [hli]
or [hl]
jp z, .beatup_fail ; fainted
- ld a, [wd002]
+ ld a, [wCurBeatUpPartyMon]
ld c, a
ld a, [wCurBattleMon]
; BUG: this can desynchronize link battles
@@ -88,7 +88,7 @@
xor a
ld [wEnemyRolloutCount], a
- ld [wd002], a
+ ld [wCurBeatUpPartyMon], a
ld [wBeatUpHitAtLeastOnce], a
jr .enemy_got_mon
@@ -97,7 +97,7 @@
ld b, a
ld a, [wOTPartyCount]
sub b
- ld [wd002], a
+ ld [wCurBeatUpPartyMon], a
.enemy_got_mon
ld a, [wBattleMode]
@@ -112,7 +112,7 @@
and a
jr nz, .link_or_tower
- ld a, [wd002]
+ ld a, [wCurBeatUpPartyMon]
ld c, a
ld b, 0
ld hl, wOTPartySpecies
@@ -123,7 +123,7 @@
jr .got_enemy_nick
.link_or_tower
- ld a, [wd002]
+ ld a, [wCurBeatUpPartyMon]
ld hl, wOTPartyMonNicknames
ld bc, NAME_LENGTH
call AddNTimes
@@ -137,7 +137,7 @@
or [hl]
jp z, .beatup_fail
- ld a, [wd002]
+ ld a, [wCurBeatUpPartyMon]
ld b, a
ld a, [wCurOTMon]
cp b
@@ -217,7 +217,7 @@
ld hl, wOTPartyMon1Species
.got_species
- ld a, [wd002]
+ ld a, [wCurBeatUpPartyMon]
add hl, bc
call GetPartyLocation
pop bc
--- a/engine/events/print_unown_2.asm
+++ b/engine/events/print_unown_2.asm
@@ -65,7 +65,7 @@
ld a, b
ld [hli], a
push hl
- ld hl, wd003
+ ld hl, wPrintedUnownTileSource + 1
call .CountSetBit
pop hl
ld a, b
--- a/engine/events/prof_oaks_pc.asm
+++ b/engine/events/prof_oaks_pc.asm
@@ -36,11 +36,11 @@
ld hl, wPokedexSeen
ld b, wEndPokedexSeen - wPokedexSeen
call CountSetBits
- ld [wd002], a
+ ld [wTempPokedexSeenCount], a
ld hl, wPokedexCaught
ld b, wEndPokedexCaught - wPokedexCaught
call CountSetBits
- ld [wd003], a
+ ld [wTempPokedexCaughtCount], a
; print appropriate rating
call .UpdateRatingBuffers
@@ -47,7 +47,7 @@
ld hl, OakPCText3
call PrintText
call JoyWaitAorB
- ld a, [wd003]
+ ld a, [wTempPokedexCaughtCount]
ld hl, OakRatings
call FindOakRating
push de
@@ -57,10 +57,10 @@
.UpdateRatingBuffers:
ld hl, wStringBuffer3
- ld de, wd002
+ ld de, wTempPokedexSeenCount
call .UpdateRatingBuffer
ld hl, wStringBuffer4
- ld de, wd003
+ ld de, wTempPokedexCaughtCount
call .UpdateRatingBuffer
ret
--- a/engine/games/unown_puzzle.asm
+++ b/engine/games/unown_puzzle.asm
@@ -504,13 +504,13 @@
RedrawUnownPuzzlePieces:
call GetCurrentPuzzlePieceVTileCorner
- ld [wd002], a
+ ld [wUnownPuzzleCornerTile], a
xor a
call GetUnownPuzzleCoordData ; get pixel positions
ld a, [hli]
ld b, [hl]
ld c, a
- ld a, [wd002]
+ ld a, [wUnownPuzzleCornerTile]
cp $e0
jr z, .NoPiece
ld hl, .OAM_HoldingPiece
@@ -532,7 +532,7 @@
add c
ld [de], a ; x
inc de
- ld a, [wd002]
+ ld a, [wUnownPuzzleCornerTile]
add [hl]
ld [de], a ; tile id
inc hl
--- a/engine/items/item_effects.asm
+++ b/engine/items/item_effects.asm
@@ -2166,11 +2166,12 @@
PokeFluteEffect:
ld a, [wBattleMode]
and a
- jr nz, .dummy
-.dummy
+ jr nz, .in_battle
+ ; overworld flute code was dummied out here
+.in_battle
xor a
- ld [wd002], a
+ ld [wPokeFluteCuredSleep], a
ld b, $ff ^ SLP
@@ -2193,7 +2194,7 @@
and b
ld [hl], a
- ld a, [wd002]
+ ld a, [wPokeFluteCuredSleep]
and a
ld hl, .PlayedFluteText
jp z, PrintText
@@ -2202,8 +2203,9 @@
ld a, [wLowHealthAlarm]
and 1 << DANGER_ON_F
- jr nz, .dummy2
-.dummy2
+ jr nz, .dummy
+ ; more code was dummied out here
+.dummy
ld hl, .FluteWakeUpText
jp PrintText
@@ -2210,14 +2212,13 @@
.CureSleep:
ld de, PARTYMON_STRUCT_LENGTH
ld c, PARTY_LENGTH
-
.loop
ld a, [hl]
push af
and SLP
jr z, .not_asleep
- ld a, 1
- ld [wd002], a
+ ld a, TRUE
+ ld [wPokeFluteCuredSleep], a
.not_asleep
pop af
and b
@@ -2290,7 +2291,7 @@
RestorePPEffect:
ld a, [wCurItem]
- ld [wd002], a
+ ld [wTempRestorePPItem], a
.loop
; Party Screen opens to choose on which mon to use the Item
@@ -2299,7 +2300,7 @@
jp c, PPRestoreItem_Cancel
.loop2
- ld a, [wd002]
+ ld a, [wTempRestorePPItem]
cp MAX_ELIXER
jp z, Elixer_RestorePPofAllMoves
cp ELIXER
@@ -2306,7 +2307,7 @@
jp z, Elixer_RestorePPofAllMoves
ld hl, RaiseThePPOfWhichMoveText
- ld a, [wd002]
+ ld a, [wTempRestorePPItem]
cp PP_UP
jr z, .ppup
ld hl, RestoreThePPOfWhichMoveText
@@ -2337,7 +2338,7 @@
call CopyName1
pop hl
- ld a, [wd002]
+ ld a, [wTempRestorePPItem]
cp PP_UP
jp nz, Not_PP_Up
@@ -2486,7 +2487,7 @@
cp b
jr nc, .dont_restore
- ld a, [wd002]
+ ld a, [wTempRestorePPItem]
cp MAX_ELIXER
jr z, .restore_all
cp MAX_ETHER
--- a/engine/link/link.asm
+++ b/engine/link/link.asm
@@ -27,7 +27,7 @@
call PlaceString
call SetTradeRoomBGPals
call WaitBGMap2
- ld hl, wcf5d
+ ld hl, wLinkByteTimeout
xor a ; LOW($5000)
ld [hli], a
ld [hl], HIGH($5000)
@@ -510,6 +510,8 @@
text_end
ExchangeBytes:
+; This is similar to Serial_ExchangeBytes,
+; but without a SERIAL_PREAMBLE_BYTE check.
ld a, TRUE
ldh [hSerialIgnoringInitialData], a
.loop
@@ -520,9 +522,9 @@
ld b, a
inc hl
ld a, 48
-.delay_cycles
+.wait
dec a
- jr nz, .delay_cycles
+ jr nz, .wait
ldh a, [hSerialIgnoringInitialData]
and a
ld a, b
@@ -1423,13 +1425,13 @@
pop af
ld [wMenuCursorY], a
dec a
- ld [wd002], a
+ ld [wCurTradePartyMon], a
ld [wPlayerLinkAction], a
farcall Function16d6ce
ld a, [wOtherPlayerLinkMode]
cp $f
jp z, InitTradeMenuDisplay
- ld [wd003], a
+ ld [wCurOTTradePartyMon], a
call Function28b68
ld c, 100
call DelayFrames
@@ -1454,7 +1456,7 @@
xor a
ld [wcf57], a
ld [wOtherPlayerLinkAction], a
- ld a, [wd003]
+ ld a, [wCurOTTradePartyMon]
ld hl, wOTPartySpecies
ld c, a
ld b, 0
@@ -1610,7 +1612,7 @@
ld c, 18
call LinkTextboxAtHL
farcall Link_WaitBGMap
- ld a, [wd002]
+ ld a, [wCurTradePartyMon]
ld hl, wPartySpecies
ld c, a
ld b, 0
@@ -1619,10 +1621,10 @@
ld [wNamedObjectIndexBuffer], a
call GetPokemonName
ld hl, wStringBuffer1
- ld de, wd004
+ ld de, wBufferTrademonNick
ld bc, MON_NAME_LENGTH
call CopyBytes
- ld a, [wd003]
+ ld a, [wCurOTTradePartyMon]
ld hl, wOTPartySpecies
ld c, a
ld b, 0
@@ -1702,7 +1704,7 @@
.asm_28c7b
ld hl, sPartyMail
- ld a, [wd002]
+ ld a, [wCurTradePartyMon]
ld bc, MAIL_STRUCT_LENGTH
call AddNTimes
ld a, BANK(sPartyMail)
@@ -1711,7 +1713,7 @@
ld e, l
ld bc, MAIL_STRUCT_LENGTH
add hl, bc
- ld a, [wd002]
+ ld a, [wCurTradePartyMon]
ld c, a
.asm_28c96
inc c
@@ -1732,7 +1734,7 @@
call AddNTimes
push hl
ld hl, wc9f4
- ld a, [wd003]
+ ld a, [wCurOTTradePartyMon]
ld bc, MAIL_STRUCT_LENGTH
call AddNTimes
pop de
@@ -1743,7 +1745,7 @@
ld de, wPlayerTrademonSenderName
ld bc, NAME_LENGTH
call CopyBytes
- ld a, [wd002]
+ ld a, [wCurTradePartyMon]
ld hl, wPartySpecies
ld b, 0
ld c, a
@@ -1751,7 +1753,7 @@
ld a, [hl]
ld [wPlayerTrademonSpecies], a
push af
- ld a, [wd002]
+ ld a, [wCurTradePartyMon]
ld hl, wPartyMonOT
call SkipNames
ld de, wPlayerTrademonOTName
@@ -1758,7 +1760,7 @@
ld bc, NAME_LENGTH
call CopyBytes
ld hl, wPartyMon1ID
- ld a, [wd002]
+ ld a, [wCurTradePartyMon]
call GetPartyLocation
ld a, [hli]
ld [wPlayerTrademonID], a
@@ -1765,13 +1767,13 @@
ld a, [hl]
ld [wPlayerTrademonID + 1], a
ld hl, wPartyMon1DVs
- ld a, [wd002]
+ ld a, [wCurTradePartyMon]
call GetPartyLocation
ld a, [hli]
ld [wPlayerTrademonDVs], a
ld a, [hl]
ld [wPlayerTrademonDVs + 1], a
- ld a, [wd002]
+ ld a, [wCurTradePartyMon]
ld hl, wPartyMon1Species
call GetPartyLocation
ld b, h
@@ -1783,7 +1785,7 @@
ld de, wOTTrademonSenderName
ld bc, NAME_LENGTH
call CopyBytes
- ld a, [wd003]
+ ld a, [wCurOTTradePartyMon]
ld hl, wOTPartySpecies
ld b, 0
ld c, a
@@ -1790,7 +1792,7 @@
add hl, bc
ld a, [hl]
ld [wOTTrademonSpecies], a
- ld a, [wd003]
+ ld a, [wCurOTTradePartyMon]
ld hl, wOTPartyMonOT
call SkipNames
ld de, wOTTrademonOTName
@@ -1797,7 +1799,7 @@
ld bc, NAME_LENGTH
call CopyBytes
ld hl, wOTPartyMon1ID
- ld a, [wd003]
+ ld a, [wCurOTTradePartyMon]
call GetPartyLocation
ld a, [hli]
ld [wOTTrademonID], a
@@ -1804,13 +1806,13 @@
ld a, [hl]
ld [wOTTrademonID + 1], a
ld hl, wOTPartyMon1DVs
- ld a, [wd003]
+ ld a, [wCurOTTradePartyMon]
call GetPartyLocation
ld a, [hli]
ld [wOTTrademonDVs], a
ld a, [hl]
ld [wOTTrademonDVs + 1], a
- ld a, [wd003]
+ ld a, [wCurOTTradePartyMon]
ld hl, wOTPartyMon1Species
call GetPartyLocation
ld b, h
@@ -1818,7 +1820,7 @@
farcall GetCaughtGender
ld a, c
ld [wOTTrademonCaughtData], a
- ld a, [wd002]
+ ld a, [wCurTradePartyMon]
ld [wCurPartyMon], a
ld hl, wPartySpecies
ld b, 0
@@ -1825,7 +1827,7 @@
ld c, a
add hl, bc
ld a, [hl]
- ld [wd002], a
+ ld [wCurTradePartyMon], a
xor a ; REMOVE_PARTY
ld [wPokemonWithdrawDepositParameter], a
callfar RemoveMonFromPartyOrBox
@@ -1834,7 +1836,7 @@
ld [wCurPartyMon], a
ld a, TRUE
ld [wForceEvolution], a
- ld a, [wd003]
+ ld a, [wCurOTTradePartyMon]
push af
ld hl, wOTPartySpecies
ld b, 0
@@ -1841,7 +1843,7 @@
ld c, a
add hl, bc
ld a, [hl]
- ld [wd003], a
+ ld [wCurOTTradePartyMon], a
ld c, 100
call DelayFrames
call ClearTilemap
@@ -2248,7 +2250,7 @@
ld a, $1
ld [wPlayerLinkAction], a
ld hl, wLinkTimeoutFrames
- ld a, $3
+ ld a, 3
ld [hli], a
xor a
ld [hl], a
--- a/engine/link/time_capsule.asm
+++ b/engine/link/time_capsule.asm
@@ -1,11 +1,11 @@
; These functions seem to be related to backwards compatibility
ValidateOTTrademon:
- ld a, [wd003]
+ ld a, [wCurOTTradePartyMon]
ld hl, wOTPartyMon1Species
call GetPartyLocation
push hl
- ld a, [wd003]
+ ld a, [wCurOTTradePartyMon]
inc a
ld c, a
ld b, 0
@@ -30,7 +30,7 @@
cp LINK_TIMECAPSULE
jr nz, .normal
ld hl, wOTPartySpecies
- ld a, [wd003]
+ ld a, [wCurOTTradePartyMon]
ld c, a
ld b, 0
add hl, bc
@@ -65,11 +65,11 @@
ret
CheckAnyOtherAliveMonsForTrade:
- ld a, [wd002]
+ ld a, [wCurTradePartyMon]
ld d, a
ld a, [wPartyCount]
ld b, a
- ld c, $0
+ ld c, 0
.loop
ld a, c
cp d
@@ -87,7 +87,7 @@
inc c
dec b
jr nz, .loop
- ld a, [wd003]
+ ld a, [wCurOTTradePartyMon]
ld hl, wOTPartyMon1HP
call GetPartyLocation
ld a, [hli]
--- a/engine/overworld/decorations.asm
+++ b/engine/overworld/decorations.asm
@@ -44,7 +44,7 @@
.MenuData:
db STATICMENU_CURSOR | STATICMENU_WRAP ; flags
db 0 ; items
- dw wd002
+ dw wNumOwnedDecoCategories
dw PlaceNthMenuStrings
dw .pointers
@@ -75,7 +75,7 @@
ld a, 7
call .AppendToStringBuffer2
ld hl, wStringBuffer2
- ld de, wd002
+ ld de, wDecoNameBuffer
ld bc, ITEM_NAME_LENGTH
call CopyBytes
ret
@@ -133,10 +133,11 @@
Deco_FillTempWithMinusOne:
xor a
- ld hl, wd002
+ ld hl, wNumOwnedDecoCategories
ld [hli], a
+ assert wNumOwnedDecoCategories + 1 == wOwnedDecoCategories
ld a, -1
- ld bc, $10
+ ld bc, 16
call ByteFill
ret
@@ -161,10 +162,11 @@
ret
AppendDecoIndex:
- ld hl, wd002
+ ld hl, wNumOwnedDecoCategories
inc [hl]
+ assert wNumOwnedDecoCategories + 1 == wOwnedDecoCategories
ld e, [hl]
- ld d, $0
+ ld d, 0
add hl, de
ld [hl], a
ret
@@ -176,7 +178,7 @@
pop hl
call CheckAllDecorationFlags
pop bc
- ld a, [wd002]
+ ld a, [wNumOwnedDecoCategories]
and a
ret z
@@ -335,7 +337,7 @@
ret
PopulateDecoCategoryMenu:
- ld a, [wd002]
+ ld a, [wNumOwnedDecoCategories]
and a
jr z, .empty
cp 8
@@ -353,9 +355,10 @@
ret
.beyond_eight
- ld hl, wd002
+ ld hl, wNumOwnedDecoCategories
ld e, [hl]
dec [hl]
+ assert wNumOwnedDecoCategories + 1 == wOwnedDecoCategories
ld d, 0
add hl, de
ld [hl], -1
@@ -395,7 +398,7 @@
.NonscrollingMenuData:
db STATICMENU_CURSOR | STATICMENU_WRAP ; flags
db 0 ; items
- dw wd002
+ dw wDecoNameBuffer
dw DecorationMenuFunction
dw DecorationAttributes
@@ -409,10 +412,10 @@
db SCROLLINGMENU_DISPLAY_ARROWS ; flags
db 8, 0 ; rows, columns
db SCROLLINGMENU_ITEMS_NORMAL ; item format
- dbw 0, wd002 ; text pointer
+ dbw 0, wDecoNameBuffer ; text pointer
dba DecorationMenuFunction
- dbw 0, 0
- dbw 0, 0
+ dbw 0, NULL
+ dbw 0, NULL
GetDecorationData:
ld hl, DecorationAttributes
--- a/engine/overworld/scripting.asm
+++ b/engine/overworld/scripting.asm
@@ -1703,7 +1703,7 @@
push bc
inc hl
ld bc, MAIL_MSG_LENGTH
- ld de, wd002
+ ld de, wMonMailMessageBuffer
ld a, [wScriptBank]
call FarCopyBytes
pop bc
--- a/engine/pokemon/bills_pc.asm
+++ b/engine/pokemon/bills_pc.asm
@@ -1377,20 +1377,20 @@
jr z, .done\@
and a
jr z, .done\@
- ld [de], a
+ ld [de], a ; species
inc de
ld a, [wBillsPC_LoadedBox]
- ld [de], a
+ ld [de], a ; box number
inc de
- ld a, [wd003]
- ld [de], a
+ ld a, [wBillsPCTempListIndex]
+ ld [de], a ; list index
inc a
- ld [wd003], a
+ ld [wBillsPCTempListIndex], a
inc de
inc hl
- ld a, [wd004]
+ ld a, [wBillsPCTempBoxCount]
inc a
- ld [wd004], a
+ ld [wBillsPCTempBoxCount], a
jr .loop\@
.done\@
@@ -1399,7 +1399,7 @@
endc
ld a, -1
ld [de], a
- ld a, [wd004]
+ ld a, [wBillsPCTempBoxCount]
inc a
ld [wBillsPC_NumMonsInBox], a
ENDM
@@ -1411,8 +1411,8 @@
call ByteFill
ld de, wBillsPCPokemonList
xor a
- ld [wd003], a
- ld [wd004], a
+ ld [wBillsPCTempListIndex], a
+ ld [wBillsPCTempBoxCount], a
ld a, [wBillsPC_LoadedBox]
and a
jr z, .party
@@ -2455,7 +2455,7 @@
.Name:
ld b, NAME_BOX
- ld de, wd002
+ ld de, wBoxNameBuffer
farcall NamingScreen
call ClearTilemap
call LoadStandardFont
@@ -2465,13 +2465,13 @@
call GetBoxName
ld e, l
ld d, h
- ld hl, wd002
+ ld hl, wBoxNameBuffer
ld c, BOX_NAME_LENGTH - 1
call InitString
ld a, [wMenuSelection]
dec a
call GetBoxName
- ld de, wd002
+ ld de, wBoxNameBuffer
call CopyName2
ret
--- a/engine/pokemon/evolve.asm
+++ b/engine/pokemon/evolve.asm
@@ -512,7 +512,7 @@
ld a, [wEvolutionOldSpecies]
and a
jr z, .CheckMove
- ld a, [wd002]
+ ld a, [wPrevPartyLevel]
cp b
jr nc, .GetMove
--- a/engine/pokemon/mail.asm
+++ b/engine/pokemon/mail.asm
@@ -206,7 +206,7 @@
call AddNTimes
ld d, h
ld e, l
- ld hl, wd002
+ ld hl, wMonMailMessageBuffer
ld bc, MAIL_MSG_LENGTH + 1
ld a, BANK(sPartyMail)
call OpenSRAM
--- a/engine/pokemon/move_mon.asm
+++ b/engine/pokemon/move_mon.asm
@@ -780,7 +780,7 @@
call WaitSFX
call GetBreedMon1LevelGrowth
ld a, b
- ld [wd002], a
+ ld [wPrevPartyLevel], a
ld a, e
ld [wCurPartyLevel], a
xor a
@@ -795,12 +795,12 @@
call WaitSFX
call GetBreedMon2LevelGrowth
ld a, b
- ld [wd002], a
+ ld [wPrevPartyLevel], a
ld a, e
ld [wCurPartyLevel], a
ld a, PC_DEPOSIT
ld [wPokemonWithdrawDepositParameter], a
- jp RetrieveBreedmon
+ jp RetrieveBreedmon ; pointless
RetrieveBreedmon:
ld hl, wPartyCount
--- a/engine/pokemon/switchpartymons.asm
+++ b/engine/pokemon/switchpartymons.asm
@@ -65,7 +65,7 @@
ld bc, PARTYMON_STRUCT_LENGTH
call AddNTimes
push hl
- ld de, wd002
+ ld de, wSwitchMonBuffer
ld bc, PARTYMON_STRUCT_LENGTH
call CopyBytes
ld a, [wBuffer3]
@@ -77,7 +77,7 @@
ld bc, PARTYMON_STRUCT_LENGTH
call CopyBytes
pop de
- ld hl, wd002
+ ld hl, wSwitchMonBuffer
ld bc, PARTYMON_STRUCT_LENGTH
call CopyBytes
ld a, [wBuffer2]
@@ -84,7 +84,7 @@
ld hl, wPartyMonOT
call SkipNames
push hl
- call .CopyNameTowd002
+ call .CopyNameToSwitchMonBuffer
ld a, [wBuffer3]
ld hl, wPartyMonOT
call SkipNames
@@ -92,13 +92,13 @@
push hl
call .CopyName
pop de
- ld hl, wd002
+ ld hl, wSwitchMonBuffer
call .CopyName
ld hl, wPartyMonNicknames
ld a, [wBuffer2]
call SkipNames
push hl
- call .CopyNameTowd002
+ call .CopyNameToSwitchMonBuffer
ld hl, wPartyMonNicknames
ld a, [wBuffer3]
call SkipNames
@@ -106,7 +106,7 @@
push hl
call .CopyName
pop de
- ld hl, wd002
+ ld hl, wSwitchMonBuffer
call .CopyName
ld hl, sPartyMail
ld a, [wBuffer2]
@@ -113,7 +113,7 @@
ld bc, MAIL_STRUCT_LENGTH
call AddNTimes
push hl
- ld de, wd002
+ ld de, wSwitchMonBuffer
ld bc, MAIL_STRUCT_LENGTH
ld a, BANK(sPartyMail)
call OpenSRAM
@@ -127,7 +127,7 @@
ld bc, MAIL_STRUCT_LENGTH
call CopyBytes
pop de
- ld hl, wd002
+ ld hl, wSwitchMonBuffer
ld bc, MAIL_STRUCT_LENGTH
call CopyBytes
call CloseSRAM
@@ -136,8 +136,8 @@
pop hl
ret
-.CopyNameTowd002:
- ld de, wd002
+.CopyNameToSwitchMonBuffer:
+ ld de, wSwitchMonBuffer
.CopyName:
ld bc, NAME_LENGTH
--- a/home/init.asm
+++ b/home/init.asm
@@ -50,7 +50,7 @@
ldh [rOBP1], a
ldh [rTMA], a
ldh [rTAC], a
- ld [wUnusedInitializedToZero], a
+ ld [wBetaTitleSequenceOpeningType], a
ld a, %100 ; Start timer at 4096Hz
ldh [rTAC], a
--- a/home/movement.asm
+++ b/home/movement.asm
@@ -2,7 +2,7 @@
ld [wMovementBufferObject], a
xor a
ld [wMovementBufferCount], a
- ld a, $0 ; useless
+ ld a, $0 ; was BANK(wMovementBuffer) in G/S
ld [wUnusedMovementBufferBank], a
ld a, LOW(wMovementBuffer)
ld [wUnusedMovementBufferPointer], a
--- a/home/serial.asm
+++ b/home/serial.asm
@@ -57,13 +57,13 @@
xor a
ldh [rSB], a
+
ld a, 3
ldh [rDIV], a
-
-.wait_bit_7
+.delay_loop
ldh a, [rDIV]
bit 7, a
- jr nz, .wait_bit_7
+ jr nz, .delay_loop
ld a, (0 << rSC_ON) | (0 << rSC_CLOCK)
ldh [rSC], a
@@ -89,8 +89,9 @@
reti
Serial_ExchangeBytes::
- ld a, $1
+ ld a, TRUE
ldh [hSerialIgnoringInitialData], a
+
.loop
ld a, [hl]
ldh [hSerialSend], a
@@ -98,10 +99,12 @@
push bc
ld b, a
inc hl
- ld a, $30
+
+ ld a, 48
.wait
dec a
jr nz, .wait
+
ldh a, [hSerialIgnoringInitialData]
and a
ld a, b
@@ -124,7 +127,7 @@
ret
Serial_ExchangeByte::
-.loop
+.timeout_loop
xor a
ldh [hSerialReceivedNewData], a
ldh a, [hSerialConnectionStatus]
@@ -135,16 +138,16 @@
ld a, (1 << rSC_ON) | (1 << rSC_CLOCK)
ldh [rSC], a
.not_player_2
-.loop2
+.loop
ldh a, [hSerialReceivedNewData]
and a
- jr nz, .reset_ffca
+ jr nz, .await_new_data
ldh a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
- jr nz, .not_player_1_or_wLinkTimeoutFrames_zero
- call CheckwLinkTimeoutFramesNonzero
- jr z, .not_player_1_or_wLinkTimeoutFrames_zero
- call .delay_15_cycles
+ jr nz, .not_player_1_or_timed_out
+ call CheckLinkTimeoutFramesNonzero
+ jr z, .not_player_1_or_timed_out
+ call .ShortDelay
push hl
ld hl, wLinkTimeoutFrames + 1
inc [hl]
@@ -154,51 +157,51 @@
.no_rollover_up
pop hl
- call CheckwLinkTimeoutFramesNonzero
- jr nz, .loop2
+ call CheckLinkTimeoutFramesNonzero
+ jr nz, .loop
jp SerialDisconnected
-.not_player_1_or_wLinkTimeoutFrames_zero
+.not_player_1_or_timed_out
ldh a, [rIE]
and (1 << SERIAL) | (1 << TIMER) | (1 << LCD_STAT) | (1 << VBLANK)
cp 1 << SERIAL
- jr nz, .loop2
- ld a, [wcf5d]
+ jr nz, .loop
+ ld a, [wLinkByteTimeout]
dec a
- ld [wcf5d], a
- jr nz, .loop2
- ld a, [wcf5d + 1]
+ ld [wLinkByteTimeout], a
+ jr nz, .loop
+ ld a, [wLinkByteTimeout + 1]
dec a
- ld [wcf5d + 1], a
- jr nz, .loop2
+ ld [wLinkByteTimeout + 1], a
+ jr nz, .loop
ldh a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
- jr z, .reset_ffca
+ jr z, .await_new_data
ld a, 255
-.delay_255_cycles
+.long_delay_loop
dec a
- jr nz, .delay_255_cycles
+ jr nz, .long_delay_loop
-.reset_ffca
+.await_new_data
xor a
ldh [hSerialReceivedNewData], a
ldh a, [rIE]
and (1 << SERIAL) | (1 << TIMER) | (1 << LCD_STAT) | (1 << VBLANK)
sub 1 << SERIAL
- jr nz, .rIE_not_equal_8
+ jr nz, .non_serial_interrupts_enabled
- ; LOW($5000)
- ld [wcf5d], a
+ ; a == LOW($5000)
+ ld [wLinkByteTimeout], a
ld a, HIGH($5000)
- ld [wcf5d + 1], a
+ ld [wLinkByteTimeout + 1], a
-.rIE_not_equal_8
+.non_serial_interrupts_enabled
ldh a, [hSerialReceive]
cp SERIAL_NO_DATA_BYTE
ret nz
- call CheckwLinkTimeoutFramesNonzero
- jr z, .linkTimeoutFrames_zero
+ call CheckLinkTimeoutFramesNonzero
+ jr z, .timed_out
push hl
ld hl, wLinkTimeoutFrames + 1
ld a, [hl]
@@ -210,10 +213,10 @@
.no_rollover
pop hl
- call CheckwLinkTimeoutFramesNonzero
+ call CheckLinkTimeoutFramesNonzero
jr z, SerialDisconnected
-.linkTimeoutFrames_zero
+.timed_out
ldh a, [rIE]
and (1 << SERIAL) | (1 << TIMER) | (1 << LCD_STAT) | (1 << VBLANK)
cp 1 << SERIAL
@@ -222,16 +225,16 @@
ld a, [hl]
ldh [hSerialSend], a
call DelayFrame
- jp .loop
+ jp .timeout_loop
-.delay_15_cycles
+.ShortDelay:
ld a, 15
-.delay_cycles
+.short_delay_loop
dec a
- jr nz, .delay_cycles
+ jr nz, .short_delay_loop
ret
-CheckwLinkTimeoutFramesNonzero::
+CheckLinkTimeoutFramesNonzero::
push hl
ld hl, wLinkTimeoutFrames
ld a, [hli]
@@ -239,8 +242,10 @@
pop hl
ret
+; This sets wLinkTimeoutFrames to $ffff, since
+; a is always 0 when it is called.
SerialDisconnected::
- dec a ; a is always 0 when this is called
+ dec a
ld [wLinkTimeoutFrames], a
ld [wLinkTimeoutFrames + 1], a
ret
@@ -281,10 +286,8 @@
Serial_SyncAndExchangeNybble:: ; unreferenced
call LoadTilemapToTempTilemap
callfar PlaceWaitingText
- jp WaitLinkTransfer
+ jp WaitLinkTransfer ; pointless
-; One "giant" leap for machinekind
-
WaitLinkTransfer::
ld a, $ff
ld [wOtherPlayerLinkAction], a
@@ -291,7 +294,7 @@
.loop
call LinkTransfer
call DelayFrame
- call CheckwLinkTimeoutFramesNonzero
+ call CheckLinkTimeoutFramesNonzero
jr z, .check
push hl
ld hl, wLinkTimeoutFrames + 1
--- a/wram.asm
+++ b/wram.asm
@@ -1341,7 +1341,7 @@
wcf57:: db
ds 3
wLinkTimeoutFrames:: dw
-wcf5d:: dw
+wLinkByteTimeout:: dw
wMonType:: db
@@ -1664,13 +1664,19 @@
wGBCOnlyDecompressBuffer:: ; a $540-byte buffer that continues past this SECTION
-wUnusedInitializedToZero:: db
+wBetaTitleSequenceOpeningType::
+; This selected the title screen animation (fire/notes) in pokegold-spaceworld.
+ db
wDefaultSpawnpoint:: db
UNION
-; mail temp storage
-wTempMail:: mailmsg wTempMail
+; mon buffer
+wBufferMonNick:: ds MON_NAME_LENGTH
+wBufferMonOT:: ds NAME_LENGTH
+wBufferMon:: party_struct wBufferMon
+ ds 8
+wMonOrItemNameBuffer:: ds 22
NEXTU
; poke seer
@@ -1686,12 +1692,8 @@
wSeerCaughtGender:: db
NEXTU
-; mon buffer
-wBufferMonNick:: ds MON_NAME_LENGTH
-wBufferMonOT:: ds NAME_LENGTH
-wBufferMon:: party_struct wBufferMon
- ds 8
-wMonOrItemNameBuffer::
+; mail temp storage
+wTempMail:: mailmsg wTempMail
NEXTU
; bug-catching contest
@@ -1725,6 +1727,8 @@
wTownMapCursorObjectPointer:: dw
NEXTU
wTownMapCursorCoordinates:: dw
+wStartFlypoint:: db
+wEndFlypoint:: db
ENDU
NEXTU
@@ -1781,6 +1785,10 @@
wMobileParticipant3Nickname:: ds NAME_LENGTH_JAPANESE
NEXTU
+; battle exp gain
+wExperienceGained:: ds 3
+
+NEXTU
; earthquake data buffer
wEarthquakeMovementDataBuffer:: ds 5
@@ -1789,15 +1797,64 @@
wSwitchItemBuffer:: ds 2 ; may store 1 or 2 bytes
NEXTU
+; switching pokemon in party
+; may store NAME_LENGTH, PARTYMON_STRUCT_LENGTH, or MAIL_STRUCT_LENGTH bytes
+wSwitchMonBuffer:: ds 48
+
+NEXTU
+; giving pokemon mail
+wMonMailMessageBuffer:: ds MAIL_MSG_LENGTH + 1
+
+NEXTU
+; bill's pc
+UNION
+wBoxNameBuffer:: ds BOX_NAME_LENGTH
+NEXTU
+ ds 1
+wBillsPCTempListIndex:: db
+wBillsPCTempBoxCount:: db
+ENDU
+
+NEXTU
+; prof. oak's pc
+wTempPokedexSeenCount:: db
+wTempPokedexCaughtCount:: db
+
+NEXTU
+; player's room pc
+UNION
+wDecoNameBuffer:: ds ITEM_NAME_LENGTH
+NEXTU
+wNumOwnedDecoCategories:: db
+wOwnedDecoCategories:: ds 16
+ENDU
+
+NEXTU
+; trade
+wCurTradePartyMon:: db
+wCurOTTradePartyMon:: db
+wBufferTrademonNick:: ds MON_NAME_LENGTH
+
+NEXTU
+; link battle record data
+wLinkBattleRecordBuffer::
+wLinkBattleRecordName:: ds NAME_LENGTH
+wLinkBattleRecordWins:: dw
+wLinkBattleRecordLosses:: dw
+wLinkBattleRecordDraws:: dw
+
+NEXTU
; miscellaneous
wTempDayOfWeek::
+wPrevPartyLevel::
+wCurBeatUpPartyMon::
+wUnownPuzzleCornerTile::
+wKeepSevenBiasChance::
+wPokeFluteCuredSleep::
+wTempRestorePPItem::
wApricorns::
-wKeepSevenBiasChance:: ; used in the slots to handle the favoring of 7 symbol streaks
wSuicuneFrame::
db
- ds 2
-wStartFlypoint:: db
-wEndFlypoint:: db
NEXTU
; debug color picker
@@ -1806,21 +1863,11 @@
wDebugColorCurTMHM:: db
NEXTU
-; link battle record data
-wLinkBattleRecordName:: ds NAME_LENGTH
-wLinkBattleRecordWins:: dw
-wLinkBattleRecordLosses:: dw
-wLinkBattleRecordDraws:: dw
-
-NEXTU
-; unidentified
-wd002:: db
-wd003:: db
-wd004:: db
-
; mobile?
- ds 1
- ds 2
+wd002:: ds 1
+wd003:: ds 1
+wd004:: ds 1
+ ds 3
wd008:: ds 2
ds 6
wd010:: ds 1
@@ -1842,7 +1889,11 @@
wd033:: ds 1
wd034:: ds 2
wd036:: ds 2
- ds 6
+
+NEXTU
+; Every previous NEXTU takes up 60 or fewer bytes,
+; except the initial "mon buffer" UNION.
+ ds 60
UNION
; trainer data