shithub: pokecrystal

Download patch

ref: a613ed915c32d3befec54a98dae98e21649e19ce
parent: 3713b71d9e3f3f1bc099d4704910cb9c1d172dcf
author: pikalaxalt <PikalaxALT@gmail.com>
date: Wed May 4 18:34:09 EDT 2016

HDMA transfer functions

--- a/battle/core.asm
+++ b/battle/core.asm
@@ -9429,7 +9429,7 @@
 	ld [rSVBK], a
 
 	ld hl, wDecompressScratch
-	ld bc, wBackupAttrMap - wDecompressScratch
+	ld bc, wScratchAttrMap - wDecompressScratch
 	ld a, " "
 	call ByteFill
 
--- a/engine/battle_start.asm
+++ b/engine/battle_start.asm
@@ -56,7 +56,7 @@
 	ld a, [wLinkMode]
 	cp LINK_MOBILE
 	jr z, .mobile
-	callba Function6454
+	callba ReanchorBGMap_NoOAMUpdate
 	call UpdateSprites
 	call DelayFrame
 	call .NonMobile_LoadPokeballTiles
--- a/engine/events_3.asm
+++ b/engine/events_3.asm
@@ -45,7 +45,7 @@
 	ld [wLandmarkSignTimer], a
 	call LoadMapNameSignGFX
 	call InitMapNameFrame
-	callba Function104303
+	callba HDMATransfer_OnlyTopFourRows
 	ret
 
 .dont_do_map_sign
@@ -113,7 +113,7 @@
 	jr nz, .skip2
 	call InitMapNameFrame
 	call PlaceMapNameCenterAlign
-	callba Function104303
+	callba HDMATransfer_OnlyTopFourRows
 .skip2
 	ld a, $80
 	ld a, $70
--- a/engine/map_objects.asm
+++ b/engine/map_objects.asm
@@ -2209,7 +2209,7 @@
 	xor a
 .loop
 	ld [hMapObjectIndexBuffer], a
-	call GetObjectSprite
+	call DoesObjectHaveASprite
 	jr z, .ok
 	call Function565c
 .ok
@@ -2260,7 +2260,7 @@
 	cp NUM_OBJECT_STRUCTS
 	ret nc
 	call GetObjectStruct
-	call GetObjectSprite
+	call DoesObjectHaveASprite
 	ret z
 	call Function5673
 	ret
@@ -2363,7 +2363,7 @@
 ; 56cd
 
 Function56cd: ; 56cd
-	ld a, [wFollowNotExactPersonX]
+	ld a, [wPlayerBGMapOffsetX]
 	ld d, a
 	ld hl, OBJECT_SPRITE_X_OFFSET
 	add hl, bc
@@ -2392,7 +2392,7 @@
 	sub $20
 .ok3
 	ld [hUsedSpriteIndex], a
-	ld a, [wFollowNotExactPersonY]
+	ld a, [wPlayerBGMapOffsetY]
 	ld e, a
 	ld hl, OBJECT_SPRITE_Y_OFFSET
 	add hl, bc
@@ -2489,7 +2489,7 @@
 	xor a
 .loop
 	ld [hMapObjectIndexBuffer], a
-	call GetObjectSprite
+	call DoesObjectHaveASprite
 	jr z, .next
 	call Function437b
 .next
@@ -2662,7 +2662,7 @@
 	xor a
 .loop
 	push af
-	call GetObjectSprite
+	call DoesObjectHaveASprite
 	jr z, .next
 	ld hl, OBJECT_FLAGS2
 	add hl, bc
@@ -2707,7 +2707,7 @@
 	xor a
 .loop
 	push af
-	call GetObjectSprite
+	call DoesObjectHaveASprite
 	jr z, .next
 	ld hl, OBJECT_FLAGS2
 	add hl, bc
@@ -2817,19 +2817,19 @@
 	ret
 ; 5958
 
-Function5958: ; 5958
+ApplyBGMapAnchorToObjects: ; 5958
 	push hl
 	push de
 	push bc
-	ld a, [wFollowNotExactPersonX]
+	ld a, [wPlayerBGMapOffsetX]
 	ld d, a
-	ld a, [wFollowNotExactPersonY]
+	ld a, [wPlayerBGMapOffsetY]
 	ld e, a
 	ld bc, ObjectStructs
 	ld a, NUM_OBJECT_STRUCTS
 .loop
 	push af
-	call GetObjectSprite
+	call DoesObjectHaveASprite
 	jr z, .skip
 	ld hl, OBJECT_SPRITE_X
 	add hl, bc
@@ -2850,8 +2850,8 @@
 	dec a
 	jr nz, .loop
 	xor a
-	ld [wFollowNotExactPersonX], a
-	ld [wFollowNotExactPersonY], a
+	ld [wPlayerBGMapOffsetX], a
+	ld [wPlayerBGMapOffsetY], a
 	pop bc
 	pop de
 	pop hl
@@ -2881,7 +2881,7 @@
 	ld hl, wMovementPointer
 .loop
 	push hl
-	call GetObjectSprite
+	call DoesObjectHaveASprite
 	jr z, .skip
 	ld hl, OBJECT_FACING_STEP
 	add hl, bc
@@ -2986,7 +2986,7 @@
 	add [hl]
 	add 8
 	ld e, a
-	ld a, [wFollowNotExactPersonX]
+	ld a, [wPlayerBGMapOffsetX]
 	add e
 	ld [hFFBF], a
 	ld hl, OBJECT_SPRITE_Y
@@ -2997,7 +2997,7 @@
 	add [hl]
 	add 12
 	ld e, a
-	ld a, [wFollowNotExactPersonY]
+	ld a, [wPlayerBGMapOffsetY]
 	add e
 	ld [hFFC0], a
 	ld hl, OBJECT_FACING_STEP
--- a/engine/menu.asm
+++ b/engine/menu.asm
@@ -296,7 +296,7 @@
 	call Place2DMenuCursor
 .loop
 	call Move2DMenuCursor
-	call Function10402d ; BUG: This function is in another bank.
+	call HDMATransferTileMapToWRAMBank3 ; BUG: This function is in another bank.
 	                    ; Pointer in current bank (9) is bogus.
 	call .loop2
 	jr nc, .done
--- a/engine/npc_movement.asm
+++ b/engine/npc_movement.asm
@@ -320,7 +320,7 @@
 	xor a
 .loop
 	ld [hObjectStructIndexBuffer], a
-	call GetObjectSprite
+	call DoesObjectHaveASprite
 	jr z, .next
 
 	ld hl, OBJECT_FLAGS1
@@ -490,7 +490,7 @@
 	xor a
 .loop
 	ld [hObjectStructIndexBuffer], a
-	call GetObjectSprite
+	call DoesObjectHaveASprite
 	jr z, .next
 	ld hl, OBJECT_MOVEMENTTYPE
 	add hl, bc
--- a/engine/player_object.asm
+++ b/engine/player_object.asm
@@ -474,7 +474,7 @@
 	sub [hl]
 	and $f
 	swap a
-	ld hl, wFollowNotExactPersonY
+	ld hl, wPlayerBGMapOffsetY
 	sub [hl]
 	ld hl, OBJECT_SPRITE_Y
 	add hl, de
@@ -492,7 +492,7 @@
 	sub [hl]
 	and $f
 	swap a
-	ld hl, wFollowNotExactPersonX
+	ld hl, wPlayerBGMapOffsetX
 	sub [hl]
 	ld hl, OBJECT_SPRITE_X
 	add hl, de
@@ -660,7 +660,7 @@
 	sub [hl]
 	and $f
 	swap a
-	ld hl, wFollowNotExactPersonX
+	ld hl, wPlayerBGMapOffsetX
 	sub [hl]
 	ld hl, OBJECT_SPRITE_X
 	add hl, de
@@ -673,7 +673,7 @@
 	sub [hl]
 	and $f
 	swap a
-	ld hl, wFollowNotExactPersonY
+	ld hl, wPlayerBGMapOffsetY
 	sub [hl]
 	ld hl, OBJECT_SPRITE_Y
 	add hl, de
--- a/engine/player_step.asm
+++ b/engine/player_step.asm
@@ -26,12 +26,12 @@
 	ld d, a
 	ld a, [wPlayerStepVectorY]
 	ld e, a
-	ld a, [wFollowNotExactPersonX]
+	ld a, [wPlayerBGMapOffsetX]
 	sub d
-	ld [wFollowNotExactPersonX], a
-	ld a, [wFollowNotExactPersonY]
+	ld [wPlayerBGMapOffsetX], a
+	ld a, [wPlayerBGMapOffsetY]
 	sub e
-	ld [wFollowNotExactPersonY], a
+	ld [wPlayerBGMapOffsetY], a
 	ret
 
 ScrollScreen:: ; d4d2 (3:54d2)
--- a/engine/scripting.asm
+++ b/engine/scripting.asm
@@ -3054,7 +3054,7 @@
 Script_closetext: ; 97b2f
 ; script command 0x49
 
-	call Function2e20
+	call _OpenAndCloseMenu_HDMATransferTileMapAndAttrMap
 	call CloseText
 	ret
 ; 97b36
--- a/engine/startmenu.asm
+++ b/engine/startmenu.asm
@@ -5,7 +5,7 @@
 	ld de, SFX_MENU
 	call PlaySFX
 
-	callba Function6454
+	callba ReanchorBGMap_NoOAMUpdate
 
 	ld hl, StatusFlags2
 	bit 2, [hl] ; bug catching contest
@@ -22,8 +22,8 @@
 	call MenuFunc_1e7f
 	call .DrawBugContestStatusBox
 	call Function2e31
-	call Function2e20
-	callba Function64bf
+	call _OpenAndCloseMenu_HDMATransferTileMapAndAttrMap
+	callba LoadFonts_NoOAMUpdate
 	call .DrawBugContestStatus
 	call UpdateTimePals
 	jr .Select
--- a/engine/stats_screen.asm
+++ b/engine/stats_screen.asm
@@ -129,7 +129,7 @@
 .finish
 	ld hl, wcf64
 	res 5, [hl]
-	callba Function10402d
+	callba HDMATransferTileMapToWRAMBank3
 	ret
 
 StatsScreen_SetJumptableIndex: ; 4dd62 (13:5d62)
@@ -149,7 +149,7 @@
 	res 6, [hl]
 	call ClearBGPalettes
 	call ClearTileMap
-	callba Function10402d
+	callba HDMATransferTileMapToWRAMBank3
 	call StatsScreen_CopyToTempMon
 	ld a, [CurPartySpecies]
 	cp EGG
@@ -1014,7 +1014,7 @@
 	call DelayFrame
 	hlcoord 0, 0
 	call PrepMonFrontpic
-	callba Function10402d
+	callba HDMATransferTileMapToWRAMBank3
 	call StatsScreen_AnimateEgg
 
 	ld a, [TempMonHappiness]
--- a/engine/warp_connection.asm
+++ b/engine/warp_connection.asm
@@ -250,7 +250,7 @@
 	ld [wBGMapAnchor], a
 	ld [hSCY], a
 	ld [hSCX], a
-	callba Function5958
+	callba ApplyBGMapAnchorToObjects
 	ld a, [rVBK]
 	push af
 	ld a, $1
--- a/gfx/pics/animation.asm
+++ b/gfx/pics/animation.asm
@@ -99,7 +99,7 @@
 .loop
 	call SetUpPokeAnim
 	push af
-	callba Function10402d
+	callba HDMATransferTileMapToWRAMBank3
 	pop af
 	jr nc, .loop
 	ret
@@ -288,9 +288,9 @@
 	ld a, $2
 	ld [rSVBK], a
 	call Functiond04bd
-	callba Function10402d
+	callba HDMATransferTileMapToWRAMBank3
 	call Functiond0536
-	callba Function104047
+	callba HDMATransferAttrMapToWRAMBank3
 	pop af
 	ld [rSVBK], a
 	ret
@@ -880,7 +880,7 @@
 	xor a
 	ld [hBGMapMode], a
 	call Functiond051b
-	callba Function104047
+	callba HDMATransferAttrMapToWRAMBank3
 	pop af
 	ld [rSVBK], a
 	ret
--- a/home.asm
+++ b/home.asm
@@ -570,7 +570,7 @@
 ; 323f
 
 ; XXX
-	callba Function104000
+	callba HDMATransferAttrMapAndTileMapToWRAMBank3
 	ret
 ; 3246
 
--- a/home/map_objects.asm
+++ b/home/map_objects.asm
@@ -636,7 +636,7 @@
 	ret
 ; 1af1
 
-GetObjectSprite:: ; 1af1
+DoesObjectHaveASprite:: ; 1af1
 	ld hl, OBJECT_SPRITE
 	add hl, bc
 	ld a, [hl]
--- a/home/window.asm
+++ b/home/window.asm
@@ -3,12 +3,12 @@
 	call ClearWindowData
 	ld a, [hROMBank]
 	push af
-	ld a, BANK(Function6454) ; and BANK(Function64bf)
+	ld a, BANK(ReanchorBGMap_NoOAMUpdate) ; and BANK(LoadFonts_NoOAMUpdate)
 	rst Bankswitch
 
-	call Function6454
-	call Function2e20
-	call Function64bf
+	call ReanchorBGMap_NoOAMUpdate
+	call _OpenAndCloseMenu_HDMATransferTileMapAndAttrMap
+	call LoadFonts_NoOAMUpdate
 
 	pop af
 	rst Bankswitch
@@ -36,7 +36,7 @@
 	xor a
 	ld [hBGMapMode], a
 	call OverworldTextModeSwitch
-	call Function2e20
+	call _OpenAndCloseMenu_HDMATransferTileMapAndAttrMap
 	xor a
 	ld [hBGMapMode], a
 	call Function2e31
@@ -52,13 +52,13 @@
 	call ClearWindowData
 	ld a, [hROMBank]
 	push af
-	ld a, BANK(Function6454) ; and BANK(Function64bf)
+	ld a, BANK(ReanchorBGMap_NoOAMUpdate) ; and BANK(LoadFonts_NoOAMUpdate)
 	rst Bankswitch
 
-	call Function6454 ; clear bgmap
+	call ReanchorBGMap_NoOAMUpdate ; clear bgmap
 	call SpeechTextBox
-	call Function2e20 ; anchor bgmap
-	call Function64bf ; load font
+	call _OpenAndCloseMenu_HDMATransferTileMapAndAttrMap ; anchor bgmap
+	call LoadFonts_NoOAMUpdate ; load font
 	pop af
 	rst Bankswitch
 
@@ -65,13 +65,13 @@
 	ret
 ; 2e20
 
-Function2e20:: ; 2e20
+_OpenAndCloseMenu_HDMATransferTileMapAndAttrMap:: ; 2e20
 	ld a, [hOAMUpdate]
 	push af
 	ld a, $1
 	ld [hOAMUpdate], a
 
-	callba Function104110
+	callba OpenAndCloseMenu_HDMATransferTileMapAndAttrMap
 
 	pop af
 	ld [hOAMUpdate], a
--- a/main.asm
+++ b/main.asm
@@ -53,7 +53,7 @@
 
 INCLUDE "engine/intro_menu.asm"
 
-Function6454:: ; 6454
+ReanchorBGMap_NoOAMUpdate:: ; 6454
 	call DelayFrame
 	ld a, [hOAMUpdate]
 	push af
@@ -64,8 +64,9 @@
 	push af
 	xor a
 	ld [hBGMapMode], a
-	call .Function6473
 
+	call .ReanchorBGMap
+
 	pop af
 	ld [hBGMapMode], a
 	pop af
@@ -74,7 +75,7 @@
 	set 6, [hl]
 	ret
 
-.Function6473:
+.ReanchorBGMap:
 	xor a
 	ld [hFFC6], a
 	ld [hBGMapMode], a
@@ -82,8 +83,8 @@
 	ld [hWY], a
 	call OverworldTextModeSwitch
 	ld a, VBGMap1 / $100
-	call .Function64b9
-	call Function2e20
+	call .LoadBGMapAddrIntoHRAM
+	call _OpenAndCloseMenu_HDMATransferTileMapAndAttrMap
 	callba LoadOW_BGPal7
 	callba ApplyPals
 	ld a, $1
@@ -91,9 +92,9 @@
 	xor a
 	ld [hBGMapMode], a
 	ld [hWY], a
-	callba Function64db ; no need to farcall
+	callba HDMATransfer_FillBGMap0WithTile60 ; no need to farcall
 	ld a, VBGMap0 / $100
-	call .Function64b9
+	call .LoadBGMapAddrIntoHRAM
 	xor a
 	ld [wBGMapAnchor], a
 	ld a, VBGMap0 / $100
@@ -101,28 +102,28 @@
 	xor a
 	ld [hSCX], a
 	ld [hSCY], a
-	call Function5958
+	call ApplyBGMapAnchorToObjects
 	ret
 
-.Function64b9: ; 64b9
+.LoadBGMapAddrIntoHRAM: ; 64b9
 	ld [hBGMapAddress + 1], a
 	xor a
 	ld [hBGMapAddress], a
 	ret
 
-Function64bf:: ; 64bf
+LoadFonts_NoOAMUpdate:: ; 64bf
 	ld a, [hOAMUpdate]
 	push af
 	ld a, $1
 	ld [hOAMUpdate], a
 
-	call .Function64cd
+	call .LoadGFX
 
 	pop af
 	ld [hOAMUpdate], a
 	ret
 
-.Function64cd:
+.LoadGFX:
 	call LoadFontsExtra
 	ld a, $90
 	ld [hWY], a
@@ -130,7 +131,7 @@
 	call LoadStandardFont
 	ret
 
-Function64db: ; 64db
+HDMATransfer_FillBGMap0WithTile60: ; 64db
 	ld a, [rSVBK]
 	push af
 	ld a, $6
@@ -138,7 +139,7 @@
 
 	ld a, $60
 	ld hl, wDecompressScratch
-	ld bc, wBackupAttrMap - wDecompressScratch
+	ld bc, wScratchAttrMap - wDecompressScratch
 	call ByteFill
 	ld a, wDecompressScratch / $100
 	ld [rHDMA1], a
@@ -3354,7 +3355,7 @@
 	ld a, $6
 	ld [rSVBK], a
 	ld hl, wDecompressScratch
-	ld bc, wBackupAttrMap - wDecompressScratch
+	ld bc, wScratchAttrMap - wDecompressScratch
 	ld a, " "
 	call ByteFill
 	hlbgcoord 0, 0
--- a/misc/crystal_misc.asm
+++ b/misc/crystal_misc.asm
@@ -47,7 +47,7 @@
 	call Function17aba0
 	callba Function106464
 	call Function17ac0c
-	callba Function104000
+	callba HDMATransferAttrMapAndTileMapToWRAMBank3
 	call Function17abcf
 	callba LoadOW_BGPal7
 	callba Function49420
@@ -169,7 +169,7 @@
 	bit 7, [hl]
 	res 7, [hl]
 	jr nz, .asm_17a79f
-	callba Function10402d
+	callba HDMATransferTileMapToWRAMBank3
 	ret
 
 .asm_17a79f
--- a/misc/gfx_41.asm
+++ b/misc/gfx_41.asm
@@ -1,52 +1,52 @@
-Function104000:: ; 104000
+HDMATransferAttrMapAndTileMapToWRAMBank3:: ; 104000
 	ld hl, .Function
 	jp CallInSafeGFXMode
 
 .Function:
 	decoord 0, 0, AttrMap
-	ld hl, wBackupAttrMap
+	ld hl, wScratchAttrMap
 	call CutAndPasteAttrMap
 	decoord 0, 0
-	ld hl, wDecompressScratch
+	ld hl, wScratchTileMap
 	call CutAndPasteTilemap
 	ld a, $0
 	ld [rVBK], a
-	ld hl, wDecompressScratch
-	call Function10419d
+	ld hl, wScratchTileMap
+	call HDMATransferToWRAMBank3
 	ld a, $1
 	ld [rVBK], a
-	ld hl, wBackupAttrMap
-	call Function10419d
+	ld hl, wScratchAttrMap
+	call HDMATransferToWRAMBank3
 	ret
 ; 10402d
 
-Function10402d:: ; 10402d
+HDMATransferTileMapToWRAMBank3:: ; 10402d
 	ld hl, .Function
 	jp CallInSafeGFXMode
 
 .Function:
 	decoord 0, 0
-	ld hl, wDecompressScratch
+	ld hl, wScratchTileMap
 	call CutAndPasteTilemap
 	ld a, $0
 	ld [rVBK], a
-	ld hl, wDecompressScratch
-	call Function10419d
+	ld hl, wScratchTileMap
+	call HDMATransferToWRAMBank3
 	ret
 ; 104047
 
-Function104047: ; 104047
+HDMATransferAttrMapToWRAMBank3: ; 104047
 	ld hl, .Function
 	jp CallInSafeGFXMode
 
 .Function:
 	decoord 0, 0, AttrMap
-	ld hl, wBackupAttrMap
+	ld hl, wScratchAttrMap
 	call CutAndPasteAttrMap
 	ld a, $1
 	ld [rVBK], a
-	ld hl, wBackupAttrMap
-	call Function10419d
+	ld hl, wScratchAttrMap
+	call HDMATransferToWRAMBank3
 	ret
 ; 104061
 
@@ -56,29 +56,31 @@
 
 .Function:
 	decoord 0, 0, AttrMap
-	ld hl, wBackupAttrMap
+	ld hl, wScratchAttrMap
 	call CutAndPasteAttrMap
 	decoord 0, 0
-	ld hl, wDecompressScratch
+	ld hl, wScratchTileMap
 	call CutAndPasteTilemap
 	call DelayFrame
+
 	di
 	ld a, [rVBK]
 	push af
 	ld a, $1
 	ld [rVBK], a
-	ld hl, wBackupAttrMap
-	call Function1041ad
+	ld hl, wScratchAttrMap
+	call HDMATransfer_Wait127Scanlines_toBGMap
 	ld a, $0
 	ld [rVBK], a
-	ld hl, wDecompressScratch
-	call Function1041ad
+	ld hl, wScratchTileMap
+	call HDMATransfer_Wait127Scanlines_toBGMap
 	pop af
 	ld [rVBK], a
 	ei
+
 	ret
 
-Function104099: ; 104099
+Mobile_ReloadMapPart: ; 104099
 	ld hl, ReloadMapPart ; useless
 	ld hl, .Function
 	jp CallInSafeGFXMode
@@ -85,34 +87,36 @@
 
 .Function:
 	decoord 0, 0, AttrMap
-	ld hl, wBackupAttrMap
+	ld hl, wScratchAttrMap
 	call CutAndPasteAttrMap
 	decoord 0, 0
-	ld hl, wDecompressScratch
+	ld hl, wScratchTileMap
 	call CutAndPasteTilemap
 	call DelayFrame
+
 	di
 	ld a, [rVBK]
 	push af
 	ld a, $1
 	ld [rVBK], a
-	ld hl, wBackupAttrMap
-	call Function1041c1
+	ld hl, wScratchAttrMap
+	call HDMATransfer_NoDI
 	ld a, $0
 	ld [rVBK], a
-	ld hl, wDecompressScratch
-	call Function1041c1
+	ld hl, wScratchTileMap
+	call HDMATransfer_NoDI
 	pop af
 	ld [rVBK], a
 	ei
+
 	ret
 ; 1040d4
 
-Function1040d4: ; 1040d4
-	ld hl, .Function
+; XXX
+	ld hl, .unreferenced_1040da
 	jp CallInSafeGFXMode
 
-.Function:
+.unreferenced_1040da
 	ld a, $1
 	ld [rVBK], a
 	ld a, $3
@@ -132,31 +136,34 @@
 	ret
 ; 1040fb
 
-Function1040fb: ; 1040fb
-	ld hl, .Function
+; XXX
+	ld hl, .unreferenced_104101
 	jp CallInSafeGFXMode
 
-.Function:
+.unreferenced_104101
 	ld a, $1
 	ld [rVBK], a
 	ld a, $3
 	ld [rSVBK], a
 	ld hl, w3_d800
-	call Function10419d
+	call HDMATransferToWRAMBank3
 	ret
 ; 104110
 
-Function104110:: ; 104110
+OpenAndCloseMenu_HDMATransferTileMapAndAttrMap:: ; 104110
 ; OpenText
 	ld hl, .Function
 	jp CallInSafeGFXMode
 
 .Function:
+	; Transfer AttrMap and Tilemap to BGMap
+	; Fill vBGAttrs with $00
+	; Fill vBGTiles with " "
 	decoord 0, 0, AttrMap
-	ld hl, wBackupAttrMap
+	ld hl, wScratchAttrMap
 	call CutAndPasteAttrMap
 	decoord 0, 0
-	ld hl, wDecompressScratch
+	ld hl, wScratchTileMap
 	call CutAndPasteTilemap
 	call DelayFrame
 
@@ -165,12 +172,12 @@
 	push af
 	ld a, $1
 	ld [rVBK], a
-	ld hl, wBackupAttrMap
-	call Function1041b7
+	ld hl, wScratchAttrMap
+	call HDMATransfer_Wait123Scanlines_toBGMap
 	ld a, $0
 	ld [rVBK], a
-	ld hl, wDecompressScratch
-	call Function1041b7
+	ld hl, wScratchTileMap
+	call HDMATransfer_Wait123Scanlines_toBGMap
 	pop af
 	ld [rVBK], a
 	ei
@@ -177,26 +184,30 @@
 	ret
 ; 104148
 
-Function104148: ; 104148 (41:4148)
+Mobile_OpenAndCloseMenu_HDMATransferTileMapAndAttrMap: ; 104148 (41:4148)
 	ld hl, .Function
 	jp CallInSafeGFXMode
 
 .Function:
+	; Transfer AttrMap and Tilemap to BGMap
+	; Fill vBGAttrs with $00
+	; Fill vBGTiles with $ff
 	decoord 0, 0, AttrMap
-	ld hl, wBackupAttrMap
+	ld hl, wScratchAttrMap
 	call CutAndPasteAttrMap
 	ld c, $ff
 	decoord 0, 0
-	ld hl, wDecompressScratch
+	ld hl, wScratchTileMap
 	call CutAndPasteMap
+
 	ld a, $1
 	ld [rVBK], a
-	ld hl, wBackupAttrMap
-	call Function1041ad
+	ld hl, wScratchAttrMap
+	call HDMATransfer_Wait127Scanlines_toBGMap
 	ld a, $0
 	ld [rVBK], a
-	ld hl, wDecompressScratch
-	call Function1041ad
+	ld hl, wScratchTileMap
+	call HDMATransfer_Wait127Scanlines_toBGMap
 	ret
 ; 104177
 
@@ -233,8 +244,8 @@
 ; 10419d
 
 
-Function10419d: ; 10419d (41:419d)
-	call Function10424e
+HDMATransferToWRAMBank3: ; 10419d (41:419d)
+	call _LoadHDMAParameters
 	ld a, $23
 	ld [hDMATransfer], a
 
@@ -246,37 +257,47 @@
 	jr nz, .loop
 	ret
 
-Function1041ad: ; 1041ad (41:41ad)
+HDMATransfer_Wait127Scanlines_toBGMap: ; 1041ad (41:41ad)
+; HDMA transfer from hl to [hBGMapAddress]
+; hBGMapAddress -> de
+; 2 * SCREEN_HEIGHT -> c
 	ld a, [hBGMapAddress + 1]
 	ld d, a
 	ld a, [hBGMapAddress]
 	ld e, a
-	ld c, $24
-	jr Function104209
+	ld c, 2 * SCREEN_HEIGHT
+	jr HDMATransfer_Wait127Scanlines
 
-Function1041b7: ; 1041b7 (41:41b7)
+HDMATransfer_Wait123Scanlines_toBGMap: ; 1041b7 (41:41b7)
+; HDMA transfer from hl to [hBGMapAddress]
 ; hBGMapAddress -> de
-; $24 -> c
+; 2 * SCREEN_HEIGHT -> c
 ; $7b --> b
 	ld a, [hBGMapAddress + 1]
 	ld d, a
 	ld a, [hBGMapAddress]
 	ld e, a
-	ld c, $24
-	jr asm_104205
+	ld c, 2 * SCREEN_HEIGHT
+	jr HDMATransfer_Wait123Scanlines
 ; 1041c1 (41:41c1)
 
-Function1041c1: ; 1041c1
+HDMATransfer_NoDI: ; 1041c1
+; HDMA transfer from hl to [hBGMapAddress]
+; [hBGMapAddress] --> de
+; 2 * SCREEN_HEIGHT --> c
 	ld a, [hBGMapAddress + 1]
 	ld d, a
 	ld a, [hBGMapAddress]
 	ld e, a
-	ld c, $24
+	ld c, 2 * SCREEN_HEIGHT
+
+	; [rHDMA1, rHDMA2] = hl & $fff0
 	ld a, h
 	ld [rHDMA1], a
 	ld a, l
 	and $f0
 	ld [rHDMA2], a
+	; [rHDMA3, rHDMA4] = de & $1ff0
 	ld a, d
 	and $1f
 	ld [rHDMA3], a
@@ -283,23 +304,29 @@
 	ld a, e
 	and $f0
 	ld [rHDMA4], a
+	; b = c | %10000000
 	ld a, c
 	dec c
 	or $80
 	ld b, a
+	; d = $7f - c + 1
 	ld a, $7f
 	sub c
 	ld d, a
+	; while [rLY] >= d: pass
 .loop1
 	ld a, [rLY]
 	cp d
 	jr nc, .loop1
+	; while not [rSTAT] & 3: pass
 .loop2
 	ld a, [rSTAT]
 	and $3
 	jr z, .loop2
+	; load the 5th byte of HDMA
 	ld a, b
 	ld [rHDMA5], a
+	; wait until rLY advances (c + 1) times
 	ld a, [rLY]
 	inc c
 	ld hl, rLY
@@ -314,20 +341,22 @@
 	ret
 ; 104205
 
-asm_104205:
+HDMATransfer_Wait123Scanlines:
 	ld b, $7b
-	jr asm_10420b
+	jr _continue_HDMATransfer
 
 
-Function104209:
-; LY magic
+HDMATransfer_Wait127Scanlines:
 	ld b, $7f
-asm_10420b:
+_continue_HDMATransfer:
+; a lot of waiting around for hardware registers
+	; [rHDMA1, rHDMA2] = hl & $fff0
 	ld a, h
 	ld [rHDMA1], a
 	ld a, l
 	and $f0 ; high nybble
 	ld [rHDMA2], a
+	; [rHDMA3, rHDMA4] = de & $1ff0
 	ld a, d
 	and $1f ; lower 5 bits
 	ld [rHDMA3], a
@@ -334,13 +363,16 @@
 	ld a, e
 	and $f0 ; high nybble
 	ld [rHDMA4], a
+	; e = c | %10000000
 	ld a, c
 	dec c
-	or $80 ; set 7, a
+	or $80
 	ld e, a
+	; d = b - c + 1
 	ld a, b
 	sub c
 	ld d, a
+	; while [rLY] >= d: pass
 .ly_loop
 	ld a, [rLY]
 	cp d
@@ -347,16 +379,20 @@
 	jr nc, .ly_loop
 
 	di
+	; while [rSTAT] & 3: pass
 .rstat_loop_1
 	ld a, [rSTAT]
 	and $3
 	jr nz, .rstat_loop_1
+	; while not [rSTAT] & 3: pass
 .rstat_loop_2
 	ld a, [rSTAT]
 	and $3
 	jr z, .rstat_loop_2
+	; load the 5th byte of HDMA
 	ld a, e
 	ld [rHDMA5], a
+	; wait until rLY advances (c + 1) times
 	ld a, [rLY]
 	inc c
 	ld hl, rLY
@@ -374,7 +410,7 @@
 ; 10424e
 
 
-Function10424e: ; 10424e (41:424e)
+_LoadHDMAParameters: ; 10424e (41:424e)
 	ld a, h
 	ld [rHDMA1], a
 	ld a, l
@@ -415,7 +451,7 @@
 
 ; load the original value of c into hl 12 times
 	ld a, [hMapObjectIndexBuffer]
-	ld b, 12
+	ld b, BG_MAP_WIDTH - SCREEN_WIDTH
 .loop3
 	ld [hli], a
 	dec b
@@ -441,7 +477,7 @@
 	push bc
 	push hl
 
-	; Copy c tiles of the 2bpp from b:de to wDecompressScratch
+	; Copy c tiles of the 2bpp from b:de to wScratchTileMap
 	ld a, b ; bank
 	ld l, c ; number of tiles
 	ld h, $0
@@ -452,7 +488,7 @@
 	ld c, l
 	ld h, d ; address
 	ld l, e
-	ld de, wDecompressScratch
+	ld de, wScratchTileMap
 	call FarCopyBytes
 
 	pop hl
@@ -464,8 +500,8 @@
 
 	ld d, h
 	ld e, l
-	ld hl, wDecompressScratch
-	call Function104209
+	ld hl, wScratchTileMap
+	call HDMATransfer_Wait127Scanlines
 
 	; restore the previous bank
 	pop af
@@ -519,7 +555,7 @@
 	ld b, h
 	ld h, d
 	ld l, e
-	ld de, wDecompressScratch
+	ld de, wScratchTileMap
 	call FarCopyBytesDouble_DoubleBankSwitch
 
 	pop hl
@@ -531,8 +567,8 @@
 
 	ld d, h
 	ld e, l
-	ld hl, wDecompressScratch
-	call Function104209
+	ld hl, wScratchTileMap
+	call HDMATransfer_Wait127Scanlines
 
 	pop af
 	ld [rSVBK], a
@@ -539,33 +575,33 @@
 	ret
 ; 104303
 
-Function104303: ; 104303
-	ld hl, Function104309
+HDMATransfer_OnlyTopFourRows: ; 104303
+	ld hl, .Function
 	jp CallInSafeGFXMode
 ; 104309
 
-Function104309:
-	ld hl, wDecompressScratch
+.Function:
+	ld hl, wScratchTileMap
 	decoord 0, 0
-	call Function10433a
-	ld hl, wDecompressScratch + $80
+	call .Copy
+	ld hl, wScratchTileMap + $80
 	decoord 0, 0, AttrMap
-	call Function10433a
+	call .Copy
 	ld a, $1
 	ld [rVBK], a
 	ld c, $8
-	ld hl, wDecompressScratch + $80
+	ld hl, wScratchTileMap + $80
 	debgcoord 0, 0, VBGMap1
-	call Function104209
+	call HDMATransfer_Wait127Scanlines
 	ld a, $0
 	ld [rVBK], a
 	ld c, $8
-	ld hl, wDecompressScratch
+	ld hl, wScratchTileMap
 	debgcoord 0, 0, VBGMap1
-	call Function104209
+	call HDMATransfer_Wait127Scanlines
 	ret
 
-Function10433a: ; 10433a (41:433a)
+.Copy: ; 10433a (41:433a)
 	ld b, 4
 .outer_loop
 	ld c, SCREEN_WIDTH
@@ -576,7 +612,7 @@
 	dec c
 	jr nz, .inner_loop
 	ld a, l
-	add $20 - SCREEN_WIDTH
+	add BG_MAP_WIDTH - SCREEN_WIDTH
 	ld l, a
 	ld a, h
 	adc $0
--- a/misc/mobile_12.asm
+++ b/misc/mobile_12.asm
@@ -359,7 +359,7 @@
 	ld a, $29
 .asm_4833f
 	ld [wMenuScrollPosition], a
-	callba Function104148
+	callba Mobile_OpenAndCloseMenu_HDMATransferTileMapAndAttrMap
 .asm_48348
 	call ScrollingMenu
 	ld de, $629
@@ -385,7 +385,7 @@
 	ld [wd003], a
 .asm_48377
 	call Function48187
-	callba Function104148
+	callba Mobile_OpenAndCloseMenu_HDMATransferTileMapAndAttrMap
 	jp Function4840c
 
 Function48383: ; 48383 (12:4383)
--- a/misc/mobile_22.asm
+++ b/misc/mobile_22.asm
@@ -2201,7 +2201,7 @@
 	push hl
 	call Function8923c
 	call _hl_
-	callba Function104148
+	callba Mobile_OpenAndCloseMenu_HDMATransferTileMapAndAttrMap
 	pop hl
 	jr asm_89d90
 
--- a/misc/mobile_40.asm
+++ b/misc/mobile_40.asm
@@ -202,7 +202,7 @@
 	ret z
 	res 2, [hl]
 	res 6, [hl]
-	callba Function10402d
+	callba HDMATransferTileMapToWRAMBank3
 	ret
 ; 100163
 
@@ -445,12 +445,12 @@
 ; 100320
 
 Function100320: ; 100320
-	callba Function104099
+	callba Mobile_ReloadMapPart
 	ret
 ; 100327
 
 Function100327: ; 100327
-	callba Function10402d
+	callba HDMATransferTileMapToWRAMBank3
 	ret
 ; 100327
 
@@ -1821,7 +1821,7 @@
 	call Mobile_SetOverworldDelay
 	callba MobileMenuJoypad
 	push bc
-	callba Function10402d
+	callba HDMATransferTileMapToWRAMBank3
 	call Function100e2d
 	pop bc
 	jr c, .asm_100b6b
@@ -1882,7 +1882,7 @@
 	call Mobile_SetOverworldDelay
 	callba MobileMenuJoypad
 	push bc
-	callba Function10402d
+	callba HDMATransferTileMapToWRAMBank3
 	call Function100e2d
 	pop bc
 	jr c, .b_button
@@ -2016,7 +2016,7 @@
 	callba MobileMenuJoypad
 	push bc
 	callba PlaySpriteAnimations
-	callba Function10402d
+	callba HDMATransferTileMapToWRAMBank3
 	call Function100dfd
 	pop bc
 	jr c, .done
@@ -2070,7 +2070,7 @@
 	callba MobileMenuJoypad
 	push bc
 	callba PlaySpriteAnimations
-	callba Function10402d
+	callba HDMATransferTileMapToWRAMBank3
 	call Function100dfd
 	pop bc
 	jr c, .asm_100d54
@@ -3074,7 +3074,7 @@
 ; 1013d6
 
 Function1013d6: ; 1013d6
-	callba Function104000
+	callba HDMATransferAttrMapAndTileMapToWRAMBank3
 	ret
 ; 1013dd
 
@@ -5182,7 +5182,7 @@
 .asm_10225e
 	res 1, [hl]
 	res 2, [hl]
-	callba Function104099
+	callba Mobile_ReloadMapPart
 	scf
 	ret
 ; 10226a
@@ -6809,7 +6809,7 @@
 	hlcoord 0, 0, AttrMap
 	ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
 	call ByteFill
-	callba Function104000
+	callba HDMATransferAttrMapAndTileMapToWRAMBank3
 	ret
 ; 102db7
 
@@ -7390,7 +7390,7 @@
 	ld [wd1ee], a
 	call Function1034be
 	call UpdateSprites
-	callba Function104000
+	callba HDMATransferAttrMapAndTileMapToWRAMBank3
 	ld a, $01
 	ld [wd1f0], a
 	call Function10339a
@@ -7404,7 +7404,7 @@
 	call Function1033af
 	call Function10339a
 	call Function10342c
-	callba Function10402d
+	callba HDMATransferTileMapToWRAMBank3
 	ld a, [Buffer2]
 	bit 7, a
 	jr z, .asm_103362
--- a/misc/mobile_42.asm
+++ b/misc/mobile_42.asm
@@ -445,7 +445,7 @@
 .loop
 	callba PlaySpriteAnimations
 	callba SetUpPokeAnim
-	callba Function10402d
+	callba HDMATransferTileMapToWRAMBank3
 	jr nc, .loop
 	ret
 ; 1082f0
--- a/misc/mobile_45.asm
+++ b/misc/mobile_45.asm
@@ -7380,7 +7380,7 @@
 	call ClearBGPalettes
 	call ClearSprites
 	callba Function172e78
-	callba Function104000
+	callba HDMATransferAttrMapAndTileMapToWRAMBank3
 	ret
 
 ; 0x117ab4
@@ -7401,7 +7401,7 @@
 	bit 7, a
 	jr nz, .asm_117ae2
 	call Function117ae9
-	callba Function104000
+	callba HDMATransferAttrMapAndTileMapToWRAMBank3
 	jr Function117acd
 
 .asm_117ae2
--- a/misc/mobile_5f.asm
+++ b/misc/mobile_5f.asm
@@ -4647,7 +4647,7 @@
 	ld a, [wc303]
 	bit 7, a
 	jr nz, .quit
-	callba Function104000
+	callba HDMATransferAttrMapAndTileMapToWRAMBank3
 	jr .loop
 
 .quit
@@ -4716,7 +4716,7 @@
 
 Function17f5d2: ; 17f5d2
 	call Function17f5e4
-	callba Function104000
+	callba HDMATransferAttrMapAndTileMapToWRAMBank3
 	call SetPalettes
 	ld a, $1
 	ld [wc303], a
--- a/misc/mobile_menu.asm
+++ b/misc/mobile_menu.asm
@@ -280,7 +280,7 @@
 	call ClearBox
 	hlcoord 1, 14
 	call PlaceString
-	callba Function104148
+	callba Mobile_OpenAndCloseMenu_HDMATransferTileMapAndAttrMap
 	call SetPalettes
 	call StaticMenuJoypad
 	ld hl, wMenuCursorY
@@ -403,7 +403,7 @@
 	hlcoord 14, 1
 	ld de, String_4a34b
 	call PlaceString
-	callba Function104148
+	callba Mobile_OpenAndCloseMenu_HDMATransferTileMapAndAttrMap
 	call Function4a118
 	call ScrollingMenuJoypad
 	push af
@@ -432,7 +432,7 @@
 	ld b, 3
 	ld c, 4
 	call TextBox
-	callba Function104148
+	callba Mobile_OpenAndCloseMenu_HDMATransferTileMapAndAttrMap
 	ld hl, DeletePassword_YesNo_MenuDataHeader
 	call LoadMenuDataHeader
 	call VerticalMenu
@@ -455,7 +455,7 @@
 	call ExitMenu
 .quit
 	call Call_ExitMenu
-	callba Function104148
+	callba Mobile_OpenAndCloseMenu_HDMATransferTileMapAndAttrMap
 	xor a
 	ret
 ; 4a346 (12:6346)
--- a/wram.asm
+++ b/wram.asm
@@ -1504,9 +1504,9 @@
 wSeerCaughtGender:: ds 1
 	ds wSeerAction - @
 
-wBufferMonNick:: ds PKMN_NAME_LENGTH
-wBufferMonOT:: ds NAME_LENGTH
-wBufferMon:: party_struct wBufferMon
+wBufferMonNick:: ds PKMN_NAME_LENGTH ; d002
+wBufferMonOT:: ds NAME_LENGTH ; d00d
+wBufferMon:: party_struct wBufferMon ; d018
 	ds 8
 wMonOrItemNameBuffer::
 	ds wBufferMonNick - @
@@ -1820,8 +1820,8 @@
 wPrevMapNumber:: ds 1
 ; d14c
 
-wFollowNotExactPersonX:: ds 1 ; used in FollowNotExact
-wFollowNotExactPersonY:: ds 1 ; used in FollowNotExact
+wPlayerBGMapOffsetX:: ds 1 ; used in FollowNotExact; unit is pixels
+wPlayerBGMapOffsetY:: ds 1 ; used in FollowNotExact; unit is pixels
 
 ; Player movement
 wPlayerStepVectorX:: ds 1   ; d14e
@@ -2923,7 +2923,7 @@
 	ds -$22
 
 wBTChoiceOfLvlGroup::
-w3_d800:: ; ds BG_MAP_WIDTH * SCREEN_HEIGHT ($240)
+w3_d800:: ; ds BG_MAP__WIDTH * SCREEN_HEIGHT ($240)
 	ds $69
 w3_d869:: ds $17
 w3_d880:: ds 1
@@ -3049,8 +3049,10 @@
 
 SECTION "WRAM 6", WRAMX, BANK [6]
 
-wDecompressScratch:: ds $400
-wBackupAttrMap:: ds $200
+wDecompressScratch::
+wScratchTileMap::
+	ds BG_MAP_WIDTH * BG_MAP_HEIGHT
+wScratchAttrMap:: ds $200
 w6_d600:: ds $200
 w6_d800::