From 88465686cf64103effcf08ec9be276283d1f68c7 Mon Sep 17 00:00:00 2001 From: Rangi Date: Wed, 30 Jan 2019 18:59:48 -0500 Subject: [PATCH 1/6] Remove the nested UNION within battle WRAM --- engine/games/unown_puzzle.asm | 4 +-- pokecrystal.link | 2 +- wram.asm | 50 +++++++++++++++++++---------------- 3 files changed, 30 insertions(+), 26 deletions(-) diff --git a/engine/games/unown_puzzle.asm b/engine/games/unown_puzzle.asm index f6bbd18d2..4dfebb9b0 100644 --- a/engine/games/unown_puzzle.asm +++ b/engine/games/unown_puzzle.asm @@ -14,8 +14,8 @@ _UnownPuzzle: xor a ldh [hBGMapMode], a call DisableLCD - ld hl, wc608 ; includes wPuzzlePieces - ld bc, wc7e8 - wc608 + ld hl, wUnownPuzzle ; includes wPuzzlePieces + ld bc, wUnownPuzzleEnd - wUnownPuzzle xor a call ByteFill ld hl, UnownPuzzleCursorGFX diff --git a/pokecrystal.link b/pokecrystal.link index 4c5e69c2c..ccef50b37 100644 --- a/pokecrystal.link +++ b/pokecrystal.link @@ -319,7 +319,7 @@ WRAM0 align 8 "Sprites" "Tilemap" - "Battle" + "Miscellaneous" "Overworld Map" "Video" WRAMX 1 diff --git a/wram.asm b/wram.asm index 9eccd7bad..5fe54b7b4 100644 --- a/wram.asm +++ b/wram.asm @@ -354,7 +354,7 @@ wTileMap:: ; c4a0 wTileMapEnd:: -SECTION "Battle", WRAM0 +SECTION "Miscellaneous", WRAM0 UNION ; c608 ; unidentified uses @@ -578,9 +578,6 @@ wPlayerAtkLevel:: db ; c6cc wPlayerDefLevel:: db ; c6cd wPlayerSpdLevel:: db ; c6ce wPlayerSAtkLevel:: db ; c6cf - -UNION ; c6d0 -; finish battle RAM wPlayerSDefLevel:: db ; c6d0 wPlayerAccLevel:: db ; c6d1 wPlayerEvaLevel:: db ; c6d2 @@ -739,12 +736,11 @@ wSomeoneIsRampaging:: db ; c73b wPlayerJustGotFrozen:: db ; c73c wEnemyJustGotFrozen:: db ; c73d wBattleEnd:: -; Battle RAM -; c741 -NEXTU ; c6d0 +NEXTU ; c608 ; trade -wTrademons:: + ds 200 +wTrademons:: ; c6d0 wPlayerTrademon:: trademon wPlayerTrademon wOTTrademon:: trademon wOTTrademon wTrademonsEnd:: @@ -754,8 +750,9 @@ wLinkPlayer2Name:: ds NAME_LENGTH wLinkTradeSendmonSpecies:: db wLinkTradeGetmonSpecies:: db -NEXTU ; c6d0 +NEXTU ; c608 ; naming screen + ds 200 wNamingScreenDestinationPointer:: dw ; c6d0 wNamingScreenCurNameLength:: db ; c6d2 wNamingScreenMaxNameLength:: db ; c6d3 @@ -764,8 +761,9 @@ wNamingScreenCursorObjectPointer:: dw ; c6d5 wNamingScreenLastCharacter:: db ; c6d7 wNamingScreenStringEntryCoord:: dw ; c6d8 -NEXTU ; c6d0 +NEXTU ; c608 ; pokegear + ds 200 wPokegearPhoneLoadNameBuffer:: db ; c6d0 wPokegearPhoneCursorPosition:: db ; c6d1 wPokegearPhoneScrollPosition:: db ; c6d2 @@ -778,9 +776,10 @@ wPokegearRadioChannelBank:: db ; c6d9 wPokegearRadioChannelAddr:: dw ; c6da wPokegearRadioMusicPlaying:: db ; c6dc -NEXTU ; c6d0 +NEXTU ; c608 ; slot machine -wSlots:: + ds 200 +wSlots:: ; c6d0 wReel1:: slot_reel wReel1 wReel2:: slot_reel wReel2 wReel3:: slot_reel wReel3 @@ -803,9 +802,10 @@ wSlotsDataEnd:: ds 28 wSlotsEnd:: -NEXTU ; c6d0 +NEXTU ; c608 ; card flip -wCardFlip:: + ds 200 +wCardFlip:: ; c6d0 wDeck:: ds 24 wDeckEnd:: ; c6e8 @@ -815,9 +815,10 @@ wDiscardPile:: ds 24 wDiscardPileEnd:: wCardFlipEnd:: -NEXTU ; c6d0 +NEXTU ; c608 ; dummy game -wDummyGame:: + ds 200 +wDummyGame:: ; c6d0 wDummyGameCards:: ds 9 * 5 wDummyGameCardsEnd:: wDummyGameLastCardPicked:: db ; c6fd @@ -831,15 +832,18 @@ wDummyGameCounter:: db ; c708 wDummyGameNumCardsMatched:: db ; c709 wDummyGameEnd:: -NEXTU ; c6d0 +NEXTU ; c608 ; unown puzzle -wUnownPuzzle:: +wUnownPuzzle:: ; c608 + ds 200 wPuzzlePieces:: ds 6 * 6 -wUnownPuzzleEnd:: + ds 244 +wUnownPuzzleEnd:: ; c7e8 -NEXTU ; c6d0 +NEXTU ; c608 ; pokedex -wPokedexDataStart:: + ds 200 +wPokedexDataStart:: ; c6d0 wPokedexOrder:: ds $100 ; >= NUM_POKEMON wPokedexOrderEnd:: wDexListingScrollOffset:: db ; offset of the first displayed entry from the start @@ -871,8 +875,9 @@ wPokedexDataEnd:: ds 1 endc ds 2 -NEXTU ; c6d0 +NEXTU ; c608 ; mobile data + ds 200 wc6d0:: ds 56 wc708:: db wc709:: db @@ -896,7 +901,6 @@ wc7d2:: ds 1 wc7d3:: ds 1 wc7d4:: ds 1 ENDU ; c7e8 -ENDU ; c7e8 wc7e8:: ds 24 wc7e8_End:: From 2fca32b6c8742c4accaf05a8bfc0377b59a76c6e Mon Sep 17 00:00:00 2001 From: Rangi Date: Wed, 30 Jan 2019 19:43:01 -0500 Subject: [PATCH 2/6] Explain the c608 union size --- wram.asm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/wram.asm b/wram.asm index 5fe54b7b4..22941c5c5 100644 --- a/wram.asm +++ b/wram.asm @@ -364,14 +364,18 @@ wc642:: ds 5 wc647:: ds 33 wc668:: ds 32 wc688:: ds 2 -wc68a:: ds 350 +wc68a:: ds 4 NEXTU ; c608 ; surrounding tiles +; This buffer determines the size for the rest of the union; +; it uses exactly 480 bytes. wSurroundingTiles:: ds SURROUNDING_WIDTH * SURROUNDING_HEIGHT NEXTU ; c608 ; box save buffer +; SaveBoxAddress uses this buffer in three steps because it +; needs more space than is available. wBoxPartialData:: ds 480 wBoxPartialDataEnd:: From 60cdc65293705a0ce484167117c7c4505200ffbb Mon Sep 17 00:00:00 2001 From: Rangi Date: Wed, 30 Jan 2019 19:46:45 -0500 Subject: [PATCH 3/6] wc7e8 -> wUnusedC7E8 (similar to wUnusedD102) --- engine/overworld/warp_connection.asm | 2 +- home/map.asm | 6 +++--- wram.asm | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/engine/overworld/warp_connection.asm b/engine/overworld/warp_connection.asm index b39d424a7..2630ad913 100644 --- a/engine/overworld/warp_connection.asm +++ b/engine/overworld/warp_connection.asm @@ -1,6 +1,6 @@ HandleNewMap: - call Clearwc7e8 + call ClearUnusedC7E8 call ResetMapBufferEventFlags call ResetFlashIfOutOfCave call GetCurrentMapSceneID diff --git a/home/map.asm b/home/map.asm index 5cd658727..9af673f3d 100644 --- a/home/map.asm +++ b/home/map.asm @@ -1,8 +1,8 @@ ; Functions dealing with rendering and interacting with maps. -Clearwc7e8:: - ld hl, wc7e8 - ld bc, wc7e8_End - wc7e8 +ClearUnusedC7E8:: + ld hl, wUnusedC7E8 + ld bc, wUnusedC7E8End - wUnusedC7E8 ld a, 0 call ByteFill ret diff --git a/wram.asm b/wram.asm index 22941c5c5..33a543617 100644 --- a/wram.asm +++ b/wram.asm @@ -906,8 +906,8 @@ wc7d3:: ds 1 wc7d4:: ds 1 ENDU ; c7e8 -wc7e8:: ds 24 -wc7e8_End:: +wUnusedC7E8:: ds 24 +wUnusedC7E8End:: SECTION "Overworld Map", WRAM0 From 6cbdd245fc9332b083435476165ef86800550a08 Mon Sep 17 00:00:00 2001 From: Rangi Date: Wed, 6 Feb 2019 23:52:50 -0500 Subject: [PATCH 4/6] $8 = HIGH(vTiles1 - vTiles0) --- engine/overworld/overworld.asm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/overworld/overworld.asm b/engine/overworld/overworld.asm index ab9770ee5..e47645f2c 100644 --- a/engine/overworld/overworld.asm +++ b/engine/overworld/overworld.asm @@ -594,7 +594,7 @@ endr jr c, .done ld a, h - add $8 + add HIGH(vTiles1 - vTiles0) ld h, a call .CopyToVram From 32c34a36191aa4e80bbaba90463e9c07576cedd3 Mon Sep 17 00:00:00 2001 From: Rangi Date: Fri, 8 Feb 2019 15:38:31 -0500 Subject: [PATCH 5/6] Separate the 200-byte c608-to-c6d0 union and the 280-byte c6d0-to-c7e8 union --- engine/rtc/timeset.asm | 2 +- wram.asm | 271 +++++++++++++++++++++-------------------- 2 files changed, 138 insertions(+), 135 deletions(-) diff --git a/engine/rtc/timeset.asm b/engine/rtc/timeset.asm index 366dd2460..3275d313a 100644 --- a/engine/rtc/timeset.asm +++ b/engine/rtc/timeset.asm @@ -44,7 +44,7 @@ InitClock: ld hl, Text_WokeUpOak call PrintText ld hl, wTimeSetBuffer - ld bc, 50 + ld bc, wTimeSetBufferEnd - wTimeSetBuffer xor a call ByteFill ld a, 10 ; default hour = 10 AM diff --git a/wram.asm b/wram.asm index 33a543617..5b0be6064 100644 --- a/wram.asm +++ b/wram.asm @@ -357,16 +357,6 @@ wTileMapEnd:: SECTION "Miscellaneous", WRAM0 UNION ; c608 -; unidentified uses -wc608:: ds 53 -wc63d:: ds 5 -wc642:: ds 5 -wc647:: ds 33 -wc668:: ds 32 -wc688:: ds 2 -wc68a:: ds 4 - -NEXTU ; c608 ; surrounding tiles ; This buffer determines the size for the rest of the union; ; it uses exactly 480 bytes. @@ -375,37 +365,14 @@ wSurroundingTiles:: ds SURROUNDING_WIDTH * SURROUNDING_HEIGHT NEXTU ; c608 ; box save buffer ; SaveBoxAddress uses this buffer in three steps because it -; needs more space than is available. +; needs more space than the buffer can hold. wBoxPartialData:: ds 480 wBoxPartialDataEnd:: -NEXTU ; c608 -; odd egg -wOddEgg:: party_struct wOddEgg -wOddEggName:: ds MON_NAME_LENGTH -wOddEggOTName:: ds NAME_LENGTH - NEXTU ; c608 ; battle tower temp struct wBT_OTTemp:: battle_tower_struct wBT_OTTemp -NEXTU ; c608 -; hall of fame temp struct -wHallOfFameTemp:: hall_of_fame wHallOfFameTemp - -NEXTU ; c608 -; timeset temp storage -wTimeSetBuffer:: - ds 20 -wInitHourBuffer:: db ; c61c - ds 9 -wInitMinuteBuffer:: db ; c626 - -NEXTU ; c608 -; link engine data -wLink_c608:: ds 10 -wc612:: ds 10 - NEXTU ; c608 ; battle data wBattle:: @@ -741,112 +708,58 @@ wPlayerJustGotFrozen:: db ; c73c wEnemyJustGotFrozen:: db ; c73d wBattleEnd:: -NEXTU ; c608 -; trade - ds 200 -wTrademons:: ; c6d0 -wPlayerTrademon:: trademon wPlayerTrademon -wOTTrademon:: trademon wOTTrademon -wTrademonsEnd:: -wTradeAnimAddress:: dw -wLinkPlayer1Name:: ds NAME_LENGTH -wLinkPlayer2Name:: ds NAME_LENGTH -wLinkTradeSendmonSpecies:: db -wLinkTradeGetmonSpecies:: db - -NEXTU ; c608 -; naming screen - ds 200 -wNamingScreenDestinationPointer:: dw ; c6d0 -wNamingScreenCurNameLength:: db ; c6d2 -wNamingScreenMaxNameLength:: db ; c6d3 -wNamingScreenType:: db ; c6d4 -wNamingScreenCursorObjectPointer:: dw ; c6d5 -wNamingScreenLastCharacter:: db ; c6d7 -wNamingScreenStringEntryCoord:: dw ; c6d8 - -NEXTU ; c608 -; pokegear - ds 200 -wPokegearPhoneLoadNameBuffer:: db ; c6d0 -wPokegearPhoneCursorPosition:: db ; c6d1 -wPokegearPhoneScrollPosition:: db ; c6d2 -wPokegearPhoneSelectedPerson:: db ; c6d3 -wPokegearPhoneSubmenuCursor:: db ; c6d4 -wPokegearMapCursorObjectPointer:: dw ; c6d5 -wPokegearMapCursorLandmark:: db ; c6d7 -wPokegearMapPlayerIconLandmark:: db ; c6d8 -wPokegearRadioChannelBank:: db ; c6d9 -wPokegearRadioChannelAddr:: dw ; c6da -wPokegearRadioMusicPlaying:: db ; c6dc - -NEXTU ; c608 -; slot machine - ds 200 -wSlots:: ; c6d0 -wReel1:: slot_reel wReel1 -wReel2:: slot_reel wReel2 -wReel3:: slot_reel wReel3 -; c700 -wReel1Stopped:: ds 3 -wReel2Stopped:: ds 3 -wReel3Stopped:: ds 3 -wSlotBias:: db -wSlotBet:: db -wFirstTwoReelsMatching:: db -wFirstTwoReelsMatchingSevens:: db -wSlotMatched:: db -wCurReelStopped:: ds 3 -wPayout:: dw -wCurReelXCoord:: db -wCurReelYCoord:: db - ds 2 -wSlotBuildingMatch:: db -wSlotsDataEnd:: - ds 28 -wSlotsEnd:: - -NEXTU ; c608 -; card flip - ds 200 -wCardFlip:: ; c6d0 -wDeck:: ds 24 -wDeckEnd:: -; c6e8 -wCardFlipNumCardsPlayed:: db -wCardFlipFaceUpCard:: db -wDiscardPile:: ds 24 -wDiscardPileEnd:: -wCardFlipEnd:: - -NEXTU ; c608 -; dummy game - ds 200 -wDummyGame:: ; c6d0 -wDummyGameCards:: ds 9 * 5 -wDummyGameCardsEnd:: -wDummyGameLastCardPicked:: db ; c6fd -wDummyGameCard1:: db ; c6fe -wDummyGameCard2:: db ; c6ff -wDummyGameCard1Location:: db ; c700 -wDummyGameCard2Location:: db ; c701 -wDummyGameNumberTriesRemaining:: db ; c702 -wDummyGameLastMatches:: ds 5 ; c703 -wDummyGameCounter:: db ; c708 -wDummyGameNumCardsMatched:: db ; c709 -wDummyGameEnd:: - NEXTU ; c608 ; unown puzzle -wUnownPuzzle:: ; c608 +wUnownPuzzle:: ds 200 wPuzzlePieces:: ds 6 * 6 ds 244 -wUnownPuzzleEnd:: ; c7e8 +wUnownPuzzleEnd:: NEXTU ; c608 + +; This union spans 200 bytes from c608 to c6d0. +UNION ; c608 +; timeset temp storage +wTimeSetBuffer:: + ds 20 +wInitHourBuffer:: db ; c61c + ds 9 +wInitMinuteBuffer:: db ; c626 + ds 19 +wTimeSetBufferEnd:: + +NEXTU ; c608 +; hall of fame temp struct +wHallOfFameTemp:: hall_of_fame wHallOfFameTemp + +NEXTU ; c608 +; link engine data +wLink_c608:: ds 10 +wc612:: ds 10 + +NEXTU ; c608 +; odd egg +wOddEgg:: party_struct wOddEgg +wOddEggName:: ds MON_NAME_LENGTH +wOddEggOTName:: ds NAME_LENGTH + +NEXTU ; c608 +; mobile data +wc608:: ds 53 +wc63d:: ds 5 +wc642:: ds 5 +wc647:: ds 33 +wc668:: ds 32 +wc688:: ds 2 +wc68a:: ds 4 + ds 66 + +ENDU ; c6d0 + +; This union spans 280 bytes from c6d0 to c7e8. +UNION ; c6d0 ; pokedex - ds 200 wPokedexDataStart:: ; c6d0 wPokedexOrder:: ds $100 ; >= NUM_POKEMON wPokedexOrderEnd:: @@ -879,9 +792,97 @@ wPokedexDataEnd:: ds 1 endc ds 2 -NEXTU ; c608 +NEXTU ; c6d0 +; pokegear +wPokegearPhoneLoadNameBuffer:: db ; c6d0 +wPokegearPhoneCursorPosition:: db ; c6d1 +wPokegearPhoneScrollPosition:: db ; c6d2 +wPokegearPhoneSelectedPerson:: db ; c6d3 +wPokegearPhoneSubmenuCursor:: db ; c6d4 +wPokegearMapCursorObjectPointer:: dw ; c6d5 +wPokegearMapCursorLandmark:: db ; c6d7 +wPokegearMapPlayerIconLandmark:: db ; c6d8 +wPokegearRadioChannelBank:: db ; c6d9 +wPokegearRadioChannelAddr:: dw ; c6da +wPokegearRadioMusicPlaying:: db ; c6dc + +NEXTU ; c6d0 +; trade +wTrademons:: ; c6d0 +wPlayerTrademon:: trademon wPlayerTrademon +wOTTrademon:: trademon wOTTrademon +wTrademonsEnd:: +wTradeAnimAddress:: dw +wLinkPlayer1Name:: ds NAME_LENGTH +wLinkPlayer2Name:: ds NAME_LENGTH +wLinkTradeSendmonSpecies:: db +wLinkTradeGetmonSpecies:: db + +NEXTU ; c6d0 +; naming screen +wNamingScreenDestinationPointer:: dw ; c6d0 +wNamingScreenCurNameLength:: db ; c6d2 +wNamingScreenMaxNameLength:: db ; c6d3 +wNamingScreenType:: db ; c6d4 +wNamingScreenCursorObjectPointer:: dw ; c6d5 +wNamingScreenLastCharacter:: db ; c6d7 +wNamingScreenStringEntryCoord:: dw ; c6d8 + +NEXTU ; c6d0 +; slot machine +wSlots:: ; c6d0 +wReel1:: slot_reel wReel1 +wReel2:: slot_reel wReel2 +wReel3:: slot_reel wReel3 +; c700 +wReel1Stopped:: ds 3 +wReel2Stopped:: ds 3 +wReel3Stopped:: ds 3 +wSlotBias:: db +wSlotBet:: db +wFirstTwoReelsMatching:: db +wFirstTwoReelsMatchingSevens:: db +wSlotMatched:: db +wCurReelStopped:: ds 3 +wPayout:: dw +wCurReelXCoord:: db +wCurReelYCoord:: db + ds 2 +wSlotBuildingMatch:: db +wSlotsDataEnd:: + ds 28 +wSlotsEnd:: + +NEXTU ; c6d0 +; card flip +wCardFlip:: ; c6d0 +wDeck:: ds 24 +wDeckEnd:: +; c6e8 +wCardFlipNumCardsPlayed:: db +wCardFlipFaceUpCard:: db +wDiscardPile:: ds 24 +wDiscardPileEnd:: +wCardFlipEnd:: + +NEXTU ; c6d0 +; dummy game +wDummyGame:: ; c6d0 +wDummyGameCards:: ds 9 * 5 +wDummyGameCardsEnd:: +wDummyGameLastCardPicked:: db ; c6fd +wDummyGameCard1:: db ; c6fe +wDummyGameCard2:: db ; c6ff +wDummyGameCard1Location:: db ; c700 +wDummyGameCard2Location:: db ; c701 +wDummyGameNumberTriesRemaining:: db ; c702 +wDummyGameLastMatches:: ds 5 ; c703 +wDummyGameCounter:: db ; c708 +wDummyGameNumCardsMatched:: db ; c709 +wDummyGameEnd:: + +NEXTU ; c6d0 ; mobile data - ds 200 wc6d0:: ds 56 wc708:: db wc709:: db @@ -906,6 +907,8 @@ wc7d3:: ds 1 wc7d4:: ds 1 ENDU ; c7e8 +ENDU ; c7e8 + wUnusedC7E8:: ds 24 wUnusedC7E8End:: From 349664ec15995b40151378bbfc405930d47a3c5c Mon Sep 17 00:00:00 2001 From: Rangi Date: Fri, 8 Feb 2019 15:40:32 -0500 Subject: [PATCH 6/6] Clarify outer union's size --- wram.asm | 1 + 1 file changed, 1 insertion(+) diff --git a/wram.asm b/wram.asm index 5b0be6064..7b1d26cb4 100644 --- a/wram.asm +++ b/wram.asm @@ -356,6 +356,7 @@ wTileMapEnd:: SECTION "Miscellaneous", WRAM0 +; This union spans 480 bytes from c608 to c7e8. UNION ; c608 ; surrounding tiles ; This buffer determines the size for the rest of the union;