From fd6f02036ee41febfd2823846f62b89f184144b4 Mon Sep 17 00:00:00 2001 From: xCrystal Date: Mon, 28 Aug 2023 13:30:13 +0200 Subject: [PATCH] Improve some innacurate function names from pokecrystal --- docs/develop/index.md | 14 +++++++-- engine/debug/color_picker.asm | 2 +- engine/events/field_moves.asm | 2 +- engine/events/overworld.asm | 4 +-- engine/events/pokecenter_pc.asm | 2 +- engine/events/pokepic.asm | 2 +- engine/gfx/dma_transfer.asm | 45 +++++++++++++++------------- engine/menus/menu.asm | 2 +- engine/menus/start_menu.asm | 2 +- engine/overworld/init_map.asm | 4 +-- engine/overworld/load_map_part.asm | 2 +- engine/overworld/player_step.asm | 8 ++--- engine/overworld/scripting.asm | 8 ++--- engine/overworld/warp_connection.asm | 2 +- engine/tilesets/map_palettes.asm | 2 +- home/map.asm | 14 ++++----- home/palettes.asm | 4 +-- home/window.asm | 20 ++++++------- 18 files changed, 76 insertions(+), 63 deletions(-) diff --git a/docs/develop/index.md b/docs/develop/index.md index 58ff77a0f..32fd6b7fa 100755 --- a/docs/develop/index.md +++ b/docs/develop/index.md @@ -14,19 +14,29 @@ - **PrintText2bpp**: SpeechTextbox2bpp + UpdateSprites + ApplyTilemap + ClearTextbox + PrintTextboxText - **MapTextbox**: ClearTextbox + redraw tile behind cursor + SafeUpdateSprites + disable OAM update + ApplyTilemap + PrintTextboxText + enable OAM update - **MenuBox**: Calls Textbox1bpp or Textbox2bpp, depending on the value at wMenuBoxUse2bppFrame, with menu location and dimensions. wMenuBoxUse2bppFrame, as part of menu data, is cleared (FALSE means 1bpp) by ClearMenuAndWindowData -- **OverworldTextModeSwitch**: LoadMapPart + SwapTextboxPalettes + +- **LoadScreenTilemap**: From the metatile-based 24x20 map in wSurroundingTiles, load the corresponding 20x18 tiles to wTilemap. Later, BackupBGMap* from ScrollMap* copies new row/column from wTilemap to wBGMapBuffer. _ScrollBGMapPalettes populates wBGMapPalBuffer based on the tiles at wBGMapBuffer. These are read during vblank by UpdateBGMapBuffer. +- **LoadScreenAttrmapPals**: Load wAttrmap palette numbers based on the tileset palettes of the current map. Called only by LoadScreenTilemapAndAttrmapPals. +- **LoadScreenTilemapAndAttrmapPals**: LoadScreenTilemap + LoadScreenAttrmapPals. Often used to reload screen after closing a text box. - **LoadFont_NoOAMUpdate**: LoadFrame + Hide Window + LoadStandardFont with OAM update disabled - **LoadOverworldFont_NoOAMUpdate**: LoadOverworldFontAndFrame + hide Window with OAM update disabled -- **OpenText1bpp**, **OpenText2bpp**: ClearMenuAndWindowData + ReanchorBGMap_NoOAMUpdate + SpeechTextbox1bpp + _OpenAndCloseMenu_HDMATransferTilemapAndAttrmap + hide Window +- **ReanchorBGMap_NoOAMUpdate**: LoadScreenTilemapAndAttrmapPals + HDMATransferTilemapAndAttrmap_OpenAndCloseMenu, then fill BG map with all black while Window is displayed, finally anchor map and objects. Followed by CopyTilemapAtOnce or by a *_HDMATransferTilemapAndAttrmap to redraw the screen. +- **OpenText1bpp**, **OpenText2bpp**: ClearMenuAndWindowData + ReanchorBGMap_NoOAMUpdate + SpeechTextbox1bpp + HDMATransferTilemapAndAttrmap_OpenAndCloseMenu + hide Window - **OpenText1bpp**: Loads 1bpp font (LoadFont_NoOAMUpdate) - **OpenText2bpp**: Doesn't load 2bpp font - **RefreshScreen**: Same as OpenText functions but doesn't call any SpeechTextbox +- **HDMATransferTilemapAndAttrmap_OverworldEffect**: Like HDMATransferTilemapAndAttrmap_OpenAndCloseMenu but with slightly different scanline timing. So it's essentially like RefreshScreen minus the anchoring part. + - **Request1bpp**, **Request2bpp**: Copy 1bpp or 2bpp tiles at a rate of TILES_PER_CYCLE (8) per frame during vblank. Wait until complete - **Copy1bpp**, **Copy2bpp**: Copy 1bpp or 2bpp tiles immediately - **Get1bpp**, **Get2bpp**: Call Copy1bpp or Copy2bpp if LCD disabled. Request1bpp or Request2bpp otherwise - **HDMATransfer1bpp**: Copy 1bpp tiles via HDMA. Maximum 16 tiles per frame - **HDMATransfer2bpp**: Copy 2bpp tiles via HDMA. No hardcoded limit. Timing considers 1 tile per hblank - **Get1bppViaHDMA**, **Get2bppViaHDMA**: Call Copy1bpp or Copy2bpp if LCD disabled. HDMATransfer1bpp or HDMATransfer2bpp otherwise + + +- **refreshscreen**: RefreshScreen +- **reloadmappart**: LoadScreenTilemapAndAttrmapPals + GetMovementPermissions + HDMATransferTilemapAndAttrmap_OverworldEffect + UpdateSprites. Similar to refreshscreen, but does not reanchor. On the other hand, it refreshes movement permissions. Often used after a block change or field move, which can affect collisions. \ No newline at end of file diff --git a/engine/debug/color_picker.asm b/engine/debug/color_picker.asm index 03f9431fe..19f486f52 100644 --- a/engine/debug/color_picker.asm +++ b/engine/debug/color_picker.asm @@ -1023,7 +1023,7 @@ TilesetColorPicker: ; unreferenced ld [wDebugTilesetCurColor], a ldh [hMapAnims], a call ClearSprites - call OverworldTextModeSwitch + call LoadScreenTilemapAndAttrmapPals call WaitBGMap2 xor a ldh [hBGMapMode], a diff --git a/engine/events/field_moves.asm b/engine/events/field_moves.asm index 4feaad827..5062937ed 100644 --- a/engine/events/field_moves.asm +++ b/engine/events/field_moves.asm @@ -58,7 +58,7 @@ ShakeHeadbuttTree: jr .loop .done - call OverworldTextModeSwitch + call LoadScreenTilemapAndAttrmapPals call WaitBGMap xor a ldh [hBGMapMode], a diff --git a/engine/events/overworld.asm b/engine/events/overworld.asm index 006d3a093..a0ffc9705 100644 --- a/engine/events/overworld.asm +++ b/engine/events/overworld.asm @@ -220,7 +220,7 @@ CutDownTreeOrGrass: ld [hl], a xor a ldh [hBGMapMode], a - call OverworldTextModeSwitch + call LoadScreenTilemapAndAttrmapPals call UpdateSprites call DelayFrame ld a, [wCutWhirlpoolAnimationType] @@ -1171,7 +1171,7 @@ DisappearWhirlpool: ld [hl], a xor a ldh [hBGMapMode], a - call OverworldTextModeSwitch + call LoadScreenTilemapAndAttrmapPals ld a, [wCutWhirlpoolAnimationType] ld e, a farcall PlayWhirlpoolSound diff --git a/engine/events/pokecenter_pc.asm b/engine/events/pokecenter_pc.asm index c5b9de90f..fcbeca0fa 100644 --- a/engine/events/pokecenter_pc.asm +++ b/engine/events/pokecenter_pc.asm @@ -212,7 +212,7 @@ _PlayersHousePC: call _PlayersPC and a jr nz, .changed_deco_tiles - call OverworldTextModeSwitch + call LoadScreenTilemapAndAttrmapPals call ApplyTilemap call UpdateSprites call PC_PlayShutdownSound diff --git a/engine/events/pokepic.asm b/engine/events/pokepic.asm index 365b8a97b..34019a08a 100644 --- a/engine/events/pokepic.asm +++ b/engine/events/pokepic.asm @@ -35,7 +35,7 @@ ClosePokepic:: call GetMemCGBLayout xor a ldh [hBGMapMode], a - call OverworldTextModeSwitch + call LoadScreenTilemapAndAttrmapPals call ApplyTilemap call UpdateSprites call LoadStandardFont diff --git a/engine/gfx/dma_transfer.asm b/engine/gfx/dma_transfer.asm index 959438cae..92e81daa5 100644 --- a/engine/gfx/dma_transfer.asm +++ b/engine/gfx/dma_transfer.asm @@ -26,11 +26,13 @@ HDMATransferAttrmapToWRAMBank3: call HDMATransferToWRAMBank3 ret -ReloadMapPart:: +HDMATransferTilemapAndAttrmap_OverworldEffect:: ld hl, .Function jp CallInSafeGFXMode .Function: + ; Pad BG attrs with $00 + ; Pad BG tiles with " " decoord 0, 0, wAttrmap ld hl, wScratchAttrmap call PadAttrmapForHDMATransfer @@ -39,31 +41,31 @@ ReloadMapPart:: call PadTilemapForHDMATransfer call DelayFrame + ; Transfer Attrmap and Tilemap to BG map di ldh a, [rVBK] push af ld a, $1 ldh [rVBK], a ld hl, wScratchAttrmap - call HDMATransfer_Wait127Scanlines_toBGMap + call HDMATransfer_EndBeforeScanline128_toBGMap ld a, $0 ldh [rVBK], a ld hl, wScratchTilemap - call HDMATransfer_Wait127Scanlines_toBGMap + call HDMATransfer_EndBeforeScanline128_toBGMap pop af ldh [rVBK], a ei ret -OpenAndCloseMenu_HDMATransferTilemapAndAttrmap:: +_HDMATransferTilemapAndAttrmap_OpenAndCloseMenu:: ld hl, .Function jp CallInSafeGFXMode .Function: - ; Transfer wAttrmap and Tilemap to BGMap - ; Fill vBGAttrs with $00 - ; Fill vBGTiles with " " + ; Pad BG attrs with $00 + ; Pad BG tiles with " " decoord 0, 0, wAttrmap ld hl, wScratchAttrmap call PadAttrmapForHDMATransfer @@ -72,17 +74,18 @@ OpenAndCloseMenu_HDMATransferTilemapAndAttrmap:: call PadTilemapForHDMATransfer call DelayFrame + ; Transfer Attrmap and Tilemap to BG map di ldh a, [rVBK] push af ld a, $1 ldh [rVBK], a ld hl, wScratchAttrmap - call HDMATransfer_Wait123Scanlines_toBGMap + call HDMATransfer_EndBeforeScanline124_toBGMap ld a, $0 ldh [rVBK], a ld hl, wScratchTilemap - call HDMATransfer_Wait123Scanlines_toBGMap + call HDMATransfer_EndBeforeScanline124_toBGMap pop af ldh [rVBK], a ei @@ -131,7 +134,7 @@ WaitDMATransfer: jr nz, .loop ret -HDMATransfer_Wait127Scanlines_toBGMap: +HDMATransfer_EndBeforeScanline128_toBGMap: ; HDMA transfer from hl to [hBGMapAddress] ; hBGMapAddress -> de ; 2 * SCREEN_HEIGHT -> c @@ -140,9 +143,9 @@ HDMATransfer_Wait127Scanlines_toBGMap: ldh a, [hBGMapAddress] ld e, a ld c, 2 * SCREEN_HEIGHT - jr HDMATransfer_Wait127Scanlines + jr HDMATransfer_EndBeforeScanline128 -HDMATransfer_Wait123Scanlines_toBGMap: +HDMATransfer_EndBeforeScanline124_toBGMap: ; HDMA transfer from hl to [hBGMapAddress] ; hBGMapAddress -> de ; 2 * SCREEN_HEIGHT -> c @@ -152,7 +155,7 @@ HDMATransfer_Wait123Scanlines_toBGMap: ldh a, [hBGMapAddress] ld e, a ld c, 2 * SCREEN_HEIGHT - jr HDMATransfer_Wait123Scanlines + jr HDMATransfer_EndBeforeScanline124 HDMATransfer_NoDI: ; HDMA transfer from hl to [hBGMapAddress] @@ -213,12 +216,12 @@ HDMATransfer_NoDI: res 7, [hl] ret -HDMATransfer_Wait123Scanlines: - ld b, $7b +HDMATransfer_EndBeforeScanline124: + ld b, 124 - 1 jr _continue_HDMATransfer -HDMATransfer_Wait127Scanlines: - ld b, $7f +HDMATransfer_EndBeforeScanline128: + ld b, 128 - 1 _continue_HDMATransfer: ; a lot of waiting around for hardware registers ; [rHDMA1, rHDMA2] = hl & $fff0 @@ -372,7 +375,7 @@ HDMATransfer2bpp:: ld d, h ld e, l ld hl, wScratchTilemap - call HDMATransfer_Wait127Scanlines + call HDMATransfer_EndBeforeScanline128 ; restore the previous bank pop af @@ -437,7 +440,7 @@ HDMATransfer1bpp:: ld d, h ld e, l ld hl, wScratchTilemap - call HDMATransfer_Wait127Scanlines + call HDMATransfer_EndBeforeScanline128 pop af ldh [rSVBK], a @@ -459,13 +462,13 @@ HDMATransfer_OnlyTopFourRows: ld c, $8 ld hl, wScratchTilemap + $80 debgcoord 0, 0, vBGMap1 - call HDMATransfer_Wait127Scanlines + call HDMATransfer_EndBeforeScanline128 ld a, $0 ldh [rVBK], a ld c, $8 ld hl, wScratchTilemap debgcoord 0, 0, vBGMap1 - call HDMATransfer_Wait127Scanlines + call HDMATransfer_EndBeforeScanline128 ret .Copy: diff --git a/engine/menus/menu.asm b/engine/menus/menu.asm index 3ca69d89e..3b0bb251a 100644 --- a/engine/menus/menu.asm +++ b/engine/menus/menu.asm @@ -624,7 +624,7 @@ RestoreOverworldMapTiles: ; unreferenced ld bc, SCREEN_WIDTH * SCREEN_HEIGHT call CopyBytes call CloseSRAM - call OverworldTextModeSwitch + call LoadScreenTilemapAndAttrmapPals xor a ; sScratch call OpenSRAM ld hl, sScratch diff --git a/engine/menus/start_menu.asm b/engine/menus/start_menu.asm index 30339c5c6..0de3b812a 100644 --- a/engine/menus/start_menu.asm +++ b/engine/menus/start_menu.asm @@ -33,7 +33,7 @@ StartMenu:: call DrawVariableLengthMenuBox call .DrawBugContestStatusBox call SafeUpdateSprites - call _OpenAndCloseMenu_HDMATransferTilemapAndAttrmap + call HDMATransferTilemapAndAttrmap_OpenAndCloseMenu farcall LoadFont_NoOAMUpdate call .DrawBugContestStatus call UpdateTimePals diff --git a/engine/overworld/init_map.asm b/engine/overworld/init_map.asm index c394f3799..e4d70651f 100644 --- a/engine/overworld/init_map.asm +++ b/engine/overworld/init_map.asm @@ -27,10 +27,10 @@ ReanchorBGMap_NoOAMUpdate:: ldh [hBGMapMode], a ld a, $90 ldh [hWY], a - call OverworldTextModeSwitch + call LoadScreenTilemapAndAttrmapPals ld a, HIGH(vBGMap1) call .LoadBGMapAddrIntoHRAM - call _OpenAndCloseMenu_HDMATransferTilemapAndAttrmap + call HDMATransferTilemapAndAttrmap_OpenAndCloseMenu farcall ApplyPals ld a, TRUE ldh [hCGBPalUpdate], a diff --git a/engine/overworld/load_map_part.asm b/engine/overworld/load_map_part.asm index 88a0b53cb..6f130f864 100644 --- a/engine/overworld/load_map_part.asm +++ b/engine/overworld/load_map_part.asm @@ -1,4 +1,4 @@ -_LoadMapPart:: +_LoadScreenTilemap:: ld hl, wSurroundingTiles ld a, [wPlayerMetatileY] and a diff --git a/engine/overworld/player_step.asm b/engine/overworld/player_step.asm index ff0eca7e2..75f4512f2 100644 --- a/engine/overworld/player_step.asm +++ b/engine/overworld/player_step.asm @@ -124,25 +124,25 @@ UpdateOverworldMap: .step_down call .ScrollOverworldMapDown - call LoadMapPart + call LoadScreenTilemap call ScrollMapDown ret .step_up call .ScrollOverworldMapUp - call LoadMapPart + call LoadScreenTilemap call ScrollMapUp ret .step_left call .ScrollOverworldMapLeft - call LoadMapPart + call LoadScreenTilemap call ScrollMapLeft ret .step_right call .ScrollOverworldMapRight - call LoadMapPart + call LoadScreenTilemap call ScrollMapRight ret diff --git a/engine/overworld/scripting.asm b/engine/overworld/scripting.asm index 5fb9c3544..956bade69 100644 --- a/engine/overworld/scripting.asm +++ b/engine/overworld/scripting.asm @@ -947,7 +947,7 @@ ApplyObjectFacing: ret .DisableTextTiles: - call LoadMapPart + call LoadScreenTilemap hlcoord 0, 0 ld bc, SCREEN_WIDTH * SCREEN_HEIGHT .loop @@ -2170,9 +2170,9 @@ Script_changeblock: Script_reloadmappart:: xor a ldh [hBGMapMode], a - call OverworldTextModeSwitch + call LoadScreenTilemapAndAttrmapPals call GetMovementPermissions - farcall ReloadMapPart + farcall HDMATransferTilemapAndAttrmap_OverworldEffect call UpdateSprites ret @@ -2212,7 +2212,7 @@ Script_writeunusedbyte: ret Script_closetext: - call _OpenAndCloseMenu_HDMATransferTilemapAndAttrmap + call HDMATransferTilemapAndAttrmap_OpenAndCloseMenu call CloseText ret diff --git a/engine/overworld/warp_connection.asm b/engine/overworld/warp_connection.asm index be5b9f509..625cbaada 100644 --- a/engine/overworld/warp_connection.asm +++ b/engine/overworld/warp_connection.asm @@ -219,7 +219,7 @@ LoadMapTimeOfDay: ld [wSpriteUpdatesEnabled], a farcall ReplaceTimeOfDayPals farcall UpdateTimeOfDayPal - call OverworldTextModeSwitch + call LoadScreenTilemapAndAttrmapPals call .ClearBGMap call .PushAttrmap ret diff --git a/engine/tilesets/map_palettes.asm b/engine/tilesets/map_palettes.asm index ff57ac83b..b45079749 100644 --- a/engine/tilesets/map_palettes.asm +++ b/engine/tilesets/map_palettes.asm @@ -1,4 +1,4 @@ -_SwapTextboxPalettes:: +_LoadScreenAttrmapPals:: hlcoord 0, 0 decoord 0, 0, wAttrmap ld b, SCREEN_HEIGHT diff --git a/home/map.asm b/home/map.asm index 26d3f6dc0..3319a2f5a 100644 --- a/home/map.asm +++ b/home/map.asm @@ -91,12 +91,12 @@ GetMapSceneID:: pop bc ret -OverworldTextModeSwitch:: - call LoadMapPart - call SwapTextboxPalettes +LoadScreenTilemapAndAttrmapPals:: + call LoadScreenTilemap + call LoadScreenAttrmapPals ret -LoadMapPart:: +LoadScreenTilemap:: ldh a, [hROMBank] push af @@ -109,9 +109,9 @@ LoadMapPart:: ld bc, SCREEN_WIDTH * SCREEN_HEIGHT call ByteFill - ld a, BANK(_LoadMapPart) + ld a, BANK(_LoadScreenTilemap) rst Bankswitch - call _LoadMapPart + call _LoadScreenTilemap pop af rst Bankswitch @@ -1952,7 +1952,7 @@ ReloadTilesetAndPalettes:: ld c, a call SwitchToAnyMapAttributesBank farcall UpdateTimeOfDayPal - call OverworldTextModeSwitch + call LoadScreenTilemapAndAttrmapPals call LoadTilesetGFX ld a, 9 call SkipMusic diff --git a/home/palettes.asm b/home/palettes.asm index 53acc70f3..34bdffe93 100644 --- a/home/palettes.asm +++ b/home/palettes.asm @@ -288,8 +288,8 @@ ReloadSpritesNoPalettes:: call DelayFrame ret -SwapTextboxPalettes:: - homecall _SwapTextboxPalettes +LoadScreenAttrmapPals:: + homecall _LoadScreenAttrmapPals ret ScrollBGMapPalettes:: diff --git a/home/window.asm b/home/window.asm index 002ce6dc1..f9320e6d7 100644 --- a/home/window.asm +++ b/home/window.asm @@ -6,7 +6,7 @@ RefreshScreen:: rst Bankswitch call ReanchorBGMap_NoOAMUpdate - call _OpenAndCloseMenu_HDMATransferTilemapAndAttrmap + call HDMATransferTilemapAndAttrmap_OpenAndCloseMenu call HideWindow_EnableLCDInt pop af @@ -22,8 +22,8 @@ CloseText:: call ClearMenuAndWindowData xor a ldh [hBGMapMode], a - call OverworldTextModeSwitch - call _OpenAndCloseMenu_HDMATransferTilemapAndAttrmap + call LoadScreenTilemapAndAttrmapPals + call HDMATransferTilemapAndAttrmap_OpenAndCloseMenu xor a ldh [hBGMapMode], a call SafeUpdateSprites @@ -46,10 +46,10 @@ OpenText2bpp:: ld a, BANK(ReanchorBGMap_NoOAMUpdate) rst Bankswitch -; assumes that the overworld 2bpp font and frame are loaded when calling this - call ReanchorBGMap_NoOAMUpdate ; clear bgmap + ; assumes that the overworld 2bpp font and frame are loaded when calling this + call ReanchorBGMap_NoOAMUpdate ; anchor bgmap call SpeechTextbox2bpp - call _OpenAndCloseMenu_HDMATransferTilemapAndAttrmap ; anchor bgmap + call HDMATransferTilemapAndAttrmap_OpenAndCloseMenu ; transfer bgmap call HideWindow_EnableLCDInt pop af @@ -64,9 +64,9 @@ OpenText1bpp:: ld a, BANK(ReanchorBGMap_NoOAMUpdate) ; aka BANK(LoadFont_NoOAMUpdate) rst Bankswitch - call ReanchorBGMap_NoOAMUpdate ; clear bgmap + call ReanchorBGMap_NoOAMUpdate ; anchor bgmap call SpeechTextbox1bpp - call _OpenAndCloseMenu_HDMATransferTilemapAndAttrmap ; anchor bgmap + call HDMATransferTilemapAndAttrmap_OpenAndCloseMenu ; transfer bgmap call LoadFont_NoOAMUpdate ; load 1bpp font and frame, hide window pop af @@ -74,13 +74,13 @@ OpenText1bpp:: ret -_OpenAndCloseMenu_HDMATransferTilemapAndAttrmap:: +HDMATransferTilemapAndAttrmap_OpenAndCloseMenu:: ldh a, [hOAMUpdate] push af ld a, $1 ldh [hOAMUpdate], a - farcall OpenAndCloseMenu_HDMATransferTilemapAndAttrmap + farcall _HDMATransferTilemapAndAttrmap_OpenAndCloseMenu pop af ldh [hOAMUpdate], a