shithub: pokecrystal

Download patch

ref: c635e30777ba57e3fd4249862fd562936d0d47bd
parent: 8a439dbd0509d37c8d29e340a6544b3c09be4a72
author: PikalaxALT <PikalaxALT@gmail.com>
date: Mon Dec 14 06:12:18 EST 2015

map setup and warps

--- a/battle/core.asm
+++ b/battle/core.asm
@@ -1889,26 +1889,26 @@
 .ok
 	inc hl
 	ld a, [hl]
-	ld [wd1ec], a
+	ld [Buffer3], a
 	sub c
 	ld [hld], a
-	ld [wd1ee], a
+	ld [Buffer5], a
 	ld a, [hl]
-	ld [wd1ed], a
+	ld [Buffer4], a
 	sbc b
 	ld [hl], a
-	ld [wd1ef], a
+	ld [Buffer6], a
 	ret nc
 
-	ld a, [wd1ec]
+	ld a, [Buffer3]
 	ld c, a
-	ld a, [wd1ed]
+	ld a, [Buffer4]
 	ld b, a
 	xor a
 	ld [hli], a
 	ld [hl], a
-	ld [wd1ee], a
-	ld [wd1ef], a
+	ld [Buffer5], a
+	ld [Buffer6], a
 	ret
 ; 3cc76
 
@@ -4508,13 +4508,13 @@
 .go
 	push bc
 	ld a, [de]
-	ld [wd1ec], a
+	ld [Buffer3], a
 	add a
 	ld c, a
 	dec de
 	ld a, [de]
 	inc de
-	ld [wd1ed], a
+	ld [Buffer4], a
 	adc a
 	ld b, a
 	ld a, b
@@ -4539,12 +4539,12 @@
 	ld [Buffer1], a
 	ld a, [de]
 	add c
-	ld [wd1ee], a
+	ld [Buffer5], a
 	ld c, a
 	dec de
 	ld a, [de]
 	adc $0
-	ld [wd1ef], a
+	ld [Buffer6], a
 	ld b, a
 	ld a, [hld]
 	cp c
@@ -4552,15 +4552,15 @@
 	sbc b
 	jr nc, .okay
 	ld a, [hli]
-	ld [wd1ef], a
+	ld [Buffer6], a
 	ld a, [hl]
-	ld [wd1ee], a
+	ld [Buffer5], a
 
 .okay
-	ld a, [wd1ef]
+	ld a, [Buffer6]
 	ld [de], a
 	inc de
-	ld a, [wd1ee]
+	ld a, [Buffer5]
 	ld [de], a
 	ld a, [hBattleTurn]
 	ld [wd10a], a
--- a/constants/map_setup_constants.asm
+++ b/constants/map_setup_constants.asm
@@ -61,4 +61,4 @@
 	const map_keep_palettes       ; 2b
 	const map_text_scroll_off     ; 2c
 	const map_stop_script         ; 2d
-map_end_setup_script EQU -1
+map_end EQU -1
--- a/constants/misc_constants.asm
+++ b/constants/misc_constants.asm
@@ -93,6 +93,8 @@
 
 BG_MAP_WIDTH  EQU 32
 BG_MAP_HEIGHT EQU 32
+WMISC_WIDTH   EQU 6 * 4
+WMISC_HEIGHT  EQU 5 * 4
 
 TILE_WIDTH EQU 8
 
--- a/data/sprite_engine.asm
+++ b/data/sprite_engine.asm
@@ -36,7 +36,7 @@
 	dw Unknown_8d87d ; 22
 	dw Unknown_8d880 ; 23
 	dw Unknown_8d883 ; 24
-	dw Unknown_8d890 ; 25
+	dw Unknown_8d890 ; 25 headbutt
 	dw Unknown_8d899 ; 26
 	dw Unknown_8d89c ; 27
 	dw Unknown_8d89f ; 28
@@ -238,7 +238,7 @@
                 db $58, $09
                 db $5a, $0a
                 db  -2
-Unknown_8d890: 	db $50, $02
+Unknown_8d890: 	db $50, $02 ; center
                 db $5b, $02
                 db $50, $02
                 db $5b, $42
--- /dev/null
+++ b/engine/anim_hp_bar.asm
@@ -1,0 +1,430 @@
+_AnimateHPBar: ; d627
+	call Functiond65f
+	jr c, .do_player
+	call Functiond670
+.enemy_loop
+	push bc
+	push hl
+	call Functiond6e2
+	pop hl
+	pop bc
+	push af
+	push bc
+	push hl
+	call Functiond730
+	call Functiond7c9
+	pop hl
+	pop bc
+	pop af
+	jr nc, .enemy_loop
+	ret
+
+.do_player
+	call Functiond670
+.player_loop
+	push bc
+	push hl
+	call Functiond6f5
+	pop hl
+	pop bc
+	ret c
+	push af
+	push bc
+	push hl
+	call Functiond749
+	call Functiond7c9
+	pop hl
+	pop bc
+	pop af
+	jr nc, .player_loop
+	ret
+; d65f
+
+Functiond65f: ; d65f
+	ld a, [Buffer2]
+	and a
+	jr nz, .player
+	ld a, [Buffer1]
+	cp 6 * 8
+	jr nc, .player
+	and a
+	ret
+
+.player
+	scf
+	ret
+; d670
+
+Functiond670: ; d670
+; Buffer1-2: Max HP
+; Buffer3-4: Old HP
+; Buffer5-6: New HP
+	push hl
+	ld hl, Buffer1
+	ld a, [hli]
+	ld e, a
+	ld a, [hli]
+	ld d, a
+	ld a, [hli]
+	ld c, a
+	ld a, [hli]
+	ld b, a
+	pop hl
+	call ComputeHPBarPixels
+	ld a, e
+	ld [wd1f1], a
+
+	ld a, [Buffer5]
+	ld c, a
+	ld a, [Buffer6]
+	ld b, a
+	ld a, [Buffer1]
+	ld e, a
+	ld a, [Buffer2]
+	ld d, a
+	call ComputeHPBarPixels
+	ld a, e
+	ld [wd1f2], a
+
+	push hl
+	ld hl, Buffer3
+	ld a, [hli]
+	ld c, a
+	ld a, [hli]
+	ld b, a
+	ld a, [hli]
+	ld e, a
+	ld a, [hli]
+	ld d, a
+	pop hl
+	ld a, e
+	sub c
+	ld e, a
+	ld a, d
+	sbc b
+	ld d, a
+	jr c, .asm_d6c1
+	ld a, [Buffer3]
+	ld [wd1f5], a
+	ld a, [Buffer5]
+	ld [wd1f6], a
+	ld bc, 1
+	jr .asm_d6d9
+
+.asm_d6c1
+	ld a, [Buffer3]
+	ld [wd1f6], a
+	ld a, [Buffer5]
+	ld [wd1f5], a
+	ld a, e
+	xor $ff
+	inc a
+	ld e, a
+	ld a, d
+	xor $ff
+	ld d, a
+	ld bc, rIE
+.asm_d6d9
+	ld a, d
+	ld [wd1f3], a
+	ld a, e
+	ld [wd1f4], a
+	ret
+; d6e2
+
+Functiond6e2: ; d6e2
+	ld hl, wd1f1
+	ld a, [wd1f2]
+	cp [hl]
+	jr nz, .asm_d6ed
+	scf
+	ret
+
+.asm_d6ed
+	ld a, c
+	add [hl]
+	ld [hl], a
+	call Functiond839
+	and a
+	ret
+; d6f5
+
+Functiond6f5: ; d6f5
+.asm_d6f5
+	ld hl, Buffer3
+	ld a, [hli]
+	ld e, a
+	ld a, [hli]
+	ld d, a
+	ld a, e
+	cp [hl]
+	jr nz, .asm_d707
+	inc hl
+	ld a, d
+	cp [hl]
+	jr nz, .asm_d707
+	scf
+	ret
+
+.asm_d707
+	ld l, e
+	ld h, d
+	add hl, bc
+	ld a, l
+	ld [Buffer3], a
+	ld a, h
+	ld [wd1ed], a
+	push hl
+	push de
+	push bc
+	ld hl, Buffer1
+	ld a, [hli]
+	ld e, a
+	ld a, [hli]
+	ld d, a
+	ld a, [hli]
+	ld c, a
+	ld a, [hli]
+	ld b, a
+	call ComputeHPBarPixels
+	pop bc
+	pop de
+	pop hl
+	ld a, e
+	ld hl, wd1f1
+	cp [hl]
+	jr z, .asm_d6f5
+	ld [hl], a
+	and a
+	ret
+; d730
+
+Functiond730: ; d730
+	call Functiond784
+	ld d, $6
+	ld a, [wd10a]
+	and $1
+	ld b, a
+	ld a, [wd1f1]
+	ld e, a
+	ld c, a
+	push de
+	call Functiond771
+	pop de
+	call Functiond7b4
+	ret
+; d749
+
+Functiond749: ; d749
+	call Functiond784
+	ld a, [Buffer3]
+	ld c, a
+	ld a, [wd1ed]
+	ld b, a
+	ld a, [Buffer1]
+	ld e, a
+	ld a, [Buffer2]
+	ld d, a
+	call ComputeHPBarPixels
+	ld c, e
+	ld d, $6
+	ld a, [wd10a]
+	and $1
+	ld b, a
+	push de
+	call Functiond771
+	pop de
+	call Functiond7b4
+	ret
+; d771
+
+Functiond771: ; d771
+	ld a, [wd10a]
+	cp $2
+	jr nz, .skip
+	ld a, $28
+	add l
+	ld l, a
+	ld a, $0
+	adc h
+	ld h, a
+.skip
+	call DrawBattleHPBar
+	ret
+; d784
+
+Functiond784: ; d784
+	ld a, [wd10a]
+	and a
+	ret z
+	cp $1
+	jr z, .load_15
+	ld de, $16
+	jr .loaded_de
+
+.load_15
+	ld de, $15
+.loaded_de
+	push hl
+	add hl, de
+	ld a, " "
+rept 2
+	ld [hli], a
+endr
+	ld [hld], a
+	dec hl
+	ld a, [Buffer3]
+	ld [StringBuffer2 + 1], a
+	ld a, [wd1ed]
+	ld [StringBuffer2], a
+	ld de, StringBuffer2
+	lb bc, 2, 3
+	call PrintNum
+	pop hl
+	ret
+; d7b4
+
+Functiond7b4: ; d7b4
+	ld a, [hCGB]
+	and a
+	ret z
+	ld hl, wd1f0
+	call SetHPPal
+	ld a, [wd1f0]
+	ld c, a
+	callba Function8c43
+	ret
+; d7c9
+
+Functiond7c9: ; d7c9
+	ld a, [hCGB]
+	and a
+	jr nz, .cgb
+	call DelayFrame
+	call DelayFrame
+	ret
+
+.cgb
+	ld a, [wd10a]
+	and a
+	jr z, .load_0
+	cp $1
+	jr z, .load_1
+	ld a, [CurPartyMon]
+	cp $3
+	jr nc, .c_is_1
+	ld c, $0
+	jr .c_is_0
+
+.c_is_1
+	ld c, $1
+.c_is_0
+	push af
+	cp $2
+	jr z, .skip_delay
+	cp $5
+	jr z, .skip_delay
+	ld a, $2
+	ld [hBGMapMode], a
+	ld a, c
+	ld [hBGMapThird], a
+	call DelayFrame
+.skip_delay
+	ld a, $1
+	ld [hBGMapMode], a
+	ld a, c
+	ld [hBGMapThird], a
+	call DelayFrame
+	pop af
+	cp $2
+	jr z, .two_frames
+	cp $5
+	jr z, .two_frames
+	ret
+
+.two_frames
+	inc c
+	ld a, $2
+	ld [hBGMapMode], a
+	ld a, c
+	ld [hBGMapThird], a
+	call DelayFrame
+	ld a, $1
+	ld [hBGMapMode], a
+	ld a, c
+	ld [hBGMapThird], a
+	call DelayFrame
+	ret
+
+.load_0
+	ld c, $0
+	jr .finish
+
+.load_1
+	ld c, $1
+.finish
+	call DelayFrame
+	ld a, c
+	ld [hBGMapThird], a
+	call DelayFrame
+	ret
+; d839
+
+Functiond839: ; d839
+	ld a, [Buffer1]
+	ld c, a
+	ld b, 0
+	ld hl, 0
+	ld a, [wd1f1]
+	cp 6 * 8
+	jr nc, .coppy_buffer
+	and a
+	jr z, .return_zero
+	call AddNTimes
+	ld b, 0
+.loop
+	ld a, l
+	sub 6 * 8
+	ld l, a
+	ld a, h
+	sbc $0
+	ld h, a
+	jr c, .done
+	inc b
+	jr .loop
+
+.done
+	push bc
+	ld bc, $80
+	add hl, bc
+	pop bc
+	ld a, l
+	sub 6 * 8
+	ld l, a
+	ld a, h
+	sbc $0
+	ld h, a
+	jr c, .no_carry
+	inc b
+.no_carry
+	ld a, [wd1f5]
+	cp b
+	jr nc, .finish
+	ld a, [wd1f6]
+	cp b
+	jr c, .finish
+	ld a, b
+.finish
+	ld [Buffer3], a
+	ret
+
+.return_zero
+	xor a
+	ld [Buffer3], a
+	ret
+
+.coppy_buffer
+	ld a, [Buffer1]
+	ld [Buffer3], a
+	ret
+; d88c
--- a/engine/battle_start.asm
+++ b/engine/battle_start.asm
@@ -264,8 +264,8 @@
 	ret
 
 .DoFlashAnimation: ; 8c3b3 (23:43b3)
-	ld a, [wd847]
-	cp -1
+	ld a, [wTimeOfDayPalset]
+	cp %11111111 ; dark cave
 	jr z, .done
 	ld hl, wcf64
 	ld a, [hl]
--- a/engine/link.asm
+++ b/engine/link.asm
@@ -2349,7 +2349,7 @@
 	ld a, [ScriptVar]
 	and a
 	jr z, .asm_29e08
-	ld bc, rIE
+	ld bc, -1
 .asm_29de0
 	dec bc
 	ld a, b
--- a/engine/map_objects.asm
+++ b/engine/map_objects.asm
@@ -3040,7 +3040,7 @@
 	ld [wd04e], a
 	ld [PlayerObjectStepFrame], a
 	call Function57bc
-	callba CheckWarpCollision
+	callba CheckWarpFacingDown
 	call c, SpawnInFacingDown
 	call SpawnInCustomFacing
 	ret
--- a/engine/map_setup.asm
+++ b/engine/map_setup.asm
@@ -33,11 +33,9 @@
 
 MapSetupScript_Teleport: ; 1538f
 	db map_prolong_sprites
-
 MapSetupScript_Fly: ; 15390
 	db map_fade_out_palettes
 	db map_keep_roam
-
 MapSetupScript_Warp: ; 15392
 	db map_lcd_off
 	db map_sound_off
@@ -61,7 +59,7 @@
 	db map_fade_in_palettes
 	db map_animations_on
 	db map_wildmons
-	db map_end_setup_script
+	db map_end
 
 MapSetupScript_BadWarp: ; 153a9
 	db map_load_spawn
@@ -85,7 +83,7 @@
 	db map_fade_in_palettes
 	db map_animations_on
 	db map_wildmons
-	db map_end_setup_script
+	db map_end
 
 MapSetupScript_Connection: ; 153bf
 	db map_animations_off
@@ -104,14 +102,12 @@
 	db map_wildmons
 	db map_update_roam
 	db map_animations_on
-	db map_end_setup_script
+	db map_end
 
 MapSetupScript_Fall: ; 153d0
 	db map_prolong_sprites
-
 MapSetupScript_Door: ; 153d1
 	db map_fade_out_palettes
-
 MapSetupScript_Train: ; 153d2
 	db map_load_warp
 	db map_attributes
@@ -133,7 +129,7 @@
 	db map_animations_on
 	db map_wildmons
 	db map_update_roam
-	db map_end_setup_script
+	db map_end
 
 MapSetupScript_ReloadMap: ; 153e7
 	db map_fade
@@ -151,7 +147,7 @@
 	db map_fade_in_palettes
 	db map_animations_on
 	db map_wildmons
-	db map_end_setup_script
+	db map_end
 
 MapSetupScript_LinkReturn: ; 153f7
 	db map_fade
@@ -170,7 +166,7 @@
 	db map_animations_on
 	db map_wildmons
 	db map_text_scroll_off
-	db map_end_setup_script
+	db map_end
 
 MapSetupScript_Continue: ; 15408
 	db map_lcd_off
@@ -190,12 +186,12 @@
 	db map_fade_in_palettes
 	db map_animations_on
 	db map_wildmons
-	db map_end_setup_script
+	db map_end
 
 MapSetupScript_Submenu: ; 1541a
 	db map_load_blocks
 	db map_connection_blocks
-	db map_end_setup_script
+	db map_end
 
 
 ReadMapSetupScript: ; 1541d
--- a/engine/party_menu.asm
+++ b/engine/party_menu.asm
@@ -190,7 +190,7 @@
 	ld d, a
 	ld a, [hli]
 	ld e, a
-	predef DrawPartyMenuHPBar
+	predef ComputeHPBarPixels
 	ret
 ; 50138
 
--- a/engine/predef.asm
+++ b/engine/predef.asm
@@ -34,7 +34,7 @@
 	add_predef Predef1
 	add_predef HealParty
 	add_predef FlagPredef
-	add_predef DrawPartyMenuHPBar
+	add_predef ComputeHPBarPixels
 	add_predef FillPP
 	add_predef TryAddMonToParty
 	add_predef AddTempmonToParty
--- a/engine/sprite_anims.asm
+++ b/engine/sprite_anims.asm
@@ -16,7 +16,7 @@
 
 .Jumptable: ; 8d25b (23:525b)
 	jumptable_start
-	jumptable .zero        ; town map
+	jumptable .zero        ; null
 	jumptable .one         ; bouncing mon icon
 	jumptable .two         ; bouncing mon icon, selected
 	jumptable .three       ; bouncing mon icon, menu open
--- a/engine/sprites.asm
+++ b/engine/sprites.asm
@@ -585,7 +585,7 @@
 	db SPRITE_ANIM_FRAMESET_1D, SPRITE_ANIM_SEQ_17, $00 ; 18 flying leaves
 	db SPRITE_ANIM_FRAMESET_1F, SPRITE_ANIM_SEQ_00, $00 ; 19
 	db SPRITE_ANIM_FRAMESET_24, SPRITE_ANIM_SEQ_19, $00 ; 1a
-	db SPRITE_ANIM_FRAMESET_25, SPRITE_ANIM_SEQ_00, $00 ; 1b
+	db SPRITE_ANIM_FRAMESET_25, SPRITE_ANIM_SEQ_00, $00 ; 1b headbutt
 	db SPRITE_ANIM_FRAMESET_20, SPRITE_ANIM_SEQ_13, $00 ; 1c
 	db SPRITE_ANIM_FRAMESET_26, SPRITE_ANIM_SEQ_1A, $00 ; 1d
 	db SPRITE_ANIM_FRAMESET_2D, SPRITE_ANIM_SEQ_00, $00 ; 1e
--- a/engine/startmenu.asm
+++ b/engine/startmenu.asm
@@ -1280,7 +1280,7 @@
 ; 12e55
 
 MonMenu_Flash: ; 12e55
-	callba Functionc8ac
+	callba OWFlash
 	ld a, [wFieldMoveSucceeded]
 	cp $1
 	jr nz, .Fail
--- a/engine/stats_screen.asm
+++ b/engine/stats_screen.asm
@@ -407,7 +407,7 @@
 	ld a, [hli]
 	ld d, a
 	ld e, [hl]
-	callba DrawPartyMenuHPBar
+	callba ComputeHPBarPixels
 	ld hl, wcda1
 	call SetHPPal
 	ld b, SCGB_03
--- a/engine/timeofdaypals.asm
+++ b/engine/timeofdaypals.asm
@@ -1,4 +1,4 @@
-Function8c001:: ; 8c001
+UpdateTimeOfDayPal:: ; 8c001
 	call UpdateTime
 	ld a, [TimeOfDay]
 	ld [CurTimeOfDay], a
@@ -12,7 +12,7 @@
 ; return carry if pals are changed
 
 ; forced pals?
-	ld hl, wd846
+	ld hl, wTimeOfDayPalFlags
 	bit 7, [hl]
 	jr nz, .dontchange
 
@@ -198,7 +198,7 @@
 	db (\1 << 6) | (\2 << 4) | (\3 << 2) | \4
 ENDM
 
-Function8c0e5: ; 8c0e5
+ReplaceTimeOfDayPals: ; 8c0e5
 	ld hl, .BrightnessLevels
 	ld a, [wc2d0]
 	cp $4 ; Dark cave, needs Flash
@@ -210,18 +210,20 @@
 	adc h
 	ld h, a
 	ld a, [hl]
-	ld [wd847], a
+	ld [wTimeOfDayPalset], a
 	ret
+
 .DarkCave
 	ld a, [StatusFlags]
-	bit 2, a
+	bit 2, a ; Flash
 	jr nz, .UsedFlash
-	ld a, $ff ; 3, 3, 3, 3
-	ld [wd847], a
+	ld a, %11111111 ; 3, 3, 3, 3
+	ld [wTimeOfDayPalset], a
 	ret
+
 .UsedFlash
-	ld a, $aa ; 2, 2, 2, 2
-	ld [wd847], a
+	ld a, %10101010 ; 2, 2, 2, 2
+	ld [wTimeOfDayPalset], a
 	ret
 ; 8c10f (23:410f)
 
@@ -257,12 +259,12 @@
 	dw .DarknessPalette
 
 .MorningPalette
-	ld a, [wd847]
+	ld a, [wTimeOfDayPalset]
 	and %00000011 ; 0
 	ret
 
 .DayPalette
-	ld a, [wd847]
+	ld a, [wTimeOfDayPalset]
 	and %00001100 ; 1
 	srl a
 	srl a
@@ -269,13 +271,13 @@
 	ret
 
 .NitePalette
-	ld a, [wd847]
+	ld a, [wTimeOfDayPalset]
 	and %00110000 ; 2
 	swap a
 	ret
 
 .DarknessPalette
-	ld a, [wd847]
+	ld a, [wTimeOfDayPalset]
 	and %11000000 ; 3
 	rlca
 	rlca
--- a/engine/warp_connection.asm
+++ b/engine/warp_connection.asm
@@ -237,8 +237,8 @@
 	res 6, [hl]
 	ld a, $1
 	ld [wSpriteUpdatesEnabled], a
-	callba Function8c0e5
-	callba Function8c001
+	callba ReplaceTimeOfDayPals
+	callba UpdateTimeOfDayPal
 	call OverworldTextModeSwitch
 	call Function104770
 	call Function1047a3
--- a/event/field_moves.asm
+++ b/event/field_moves.asm
@@ -9,12 +9,12 @@
 BlindingFlash: ; 8c7e1
 	callba FadeOutPalettes
 	ld hl, StatusFlags
-	set 2, [hl]
-	callba Function8c0e5
-	callba Function8c001
+	set 2, [hl] ; Flash
+	callba ReplaceTimeOfDayPals
+	callba UpdateTimeOfDayPal
 	ld b, SCGB_09
 	call GetSGBLayout
-	callba Function49409
+	callba LoadOW_BGPal7
 	callba FadeInPalettes
 	ret
 ; 8c80a
@@ -32,13 +32,13 @@
 	call Cut_Headbutt_GetPixelFacing
 	ld a, SPRITE_ANIM_INDEX_1B
 	call _InitSpriteAnimStruct
-	ld hl, $3
+	ld hl, SPRITEANIMSTRUCT_TILE_ID
 	add hl, bc
 	ld [hl], $84
 	ld a, 36 * 4
 	ld [wCurrSpriteOAMAddr], a
 	callba DoNextFrameForAllSprites
-	call GetHeadbuttTreeRelativeLocation
+	call HideHeadbuttTree
 	ld a, $20
 	ld [wcf64], a
 	call WaitSFX
@@ -78,7 +78,7 @@
 INCBIN "gfx/unknown/08c893.2bpp"
 ; 8c913
 
-GetHeadbuttTreeRelativeLocation: ; 8c913
+HideHeadbuttTree: ; 8c913
 	xor a
 	ld [hBGMapMode], a
 	ld a, [PlayerDirection]
@@ -113,6 +113,9 @@
 ; 8c940
 
 OWCutAnimation: ; 8c940
+	; Animation index in e
+	; 0: Split tree in half
+	; 1: Mow the lawn
 	ld a, e
 	and $1
 	ld [wJumptableIndex], a
--- a/home/map.asm
+++ b/home/map.asm
@@ -114,9 +114,9 @@
 	ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
 	call ByteFill
 
-	ld a, BANK(Function4d15b)
+	ld a, BANK(_LoadMapPart)
 	rst Bankswitch
-	call Function4d15b
+	call _LoadMapPart
 
 	pop af
 	rst Bankswitch
@@ -124,22 +124,24 @@
 ; 2198
 
 LoadMetatiles:: ; 2198
-; de <- wOverworldMapAnchor
+	; de <- wOverworldMapAnchor
 	ld a, [wOverworldMapAnchor]
 	ld e, a
 	ld a, [wOverworldMapAnchor + 1]
 	ld d, a
 	ld hl, wMisc
-	ld b, 5 ; SCREEN_WIDTH / 4
+	ld b, WMISC_HEIGHT / 4 ; 5
 
-.loop
+.row
 	push de
 	push hl
-	ld c, 6 ; SCREEN_HEIGHT / 3
+	ld c, WMISC_WIDTH / 4 ; 6
 
-.loop2
+.col
 	push de
 	push hl
+	; Load the current map block.
+	; If the current map block is a border block, load the border block.
 	ld a, [de]
 	and a
 	jr nz, .ok
@@ -146,16 +148,16 @@
 	ld a, [MapBorderBlock]
 
 .ok
+	; Load the current wMisc address into de.
 	ld e, l
 	ld d, h
-; double a, load hl <- a, multiply hl by 8
+	; Set hl to the address of the current metatile data ([TilesetBlocksAddress] + (a) tiles).
 	add a
 	ld l, a
 	ld h, 0
 rept 3
-	add hl,hl
+	add hl, hl
 endr
-; hl <- hl + [TilesetBlocksAddress]
 	ld a, [TilesetBlocksAddress]
 	add l
 	ld l, a
@@ -163,28 +165,26 @@
 	adc h
 	ld h, a
 
+	; copy the 4x4 metatile
 rept 3
-; copy 4 bytes from hl to de
 rept 4
 	ld a, [hli]
 	ld [de], a
 	inc de
 endr
-; next row
 	ld a, e
-	add SCREEN_WIDTH
+	add WMISC_WIDTH - 4
 	ld e, a
 	jr nc, .next\@
 	inc d
 .next\@
 endr
-; copy 4 more bytes from hl to de
 rept 4
 	ld a, [hli]
 	ld [de], a
 	inc de
 endr
-
+	; Next metatile
 	pop hl
 	ld de, 4
 	add hl, de
@@ -191,9 +191,10 @@
 	pop de
 	inc de
 	dec c
-	jp nz, .loop2
+	jp nz, .col
+	; Next metarow
 	pop hl
-	ld de, $60
+	ld de, WMISC_WIDTH * 4
 	add hl, de
 	pop de
 	ld a, [MapWidth]
@@ -202,10 +203,9 @@
 	ld e, a
 	jr nc, .ok2
 	inc d
-
 .ok2
 	dec b
-	jp nz, .loop
+	jp nz, .row
 	ret
 ; 222a
 
@@ -223,7 +223,7 @@
 	ret nc
 
 	push bc
-	callba Function149af
+	callba CheckDirectionalWarp
 	pop bc
 	ret nc
 
@@ -232,8 +232,6 @@
 	ret
 ; 224a
 
-
-
 WarpCheck:: ; 224a
 	call GetDestinationWarpNumber
 	ret nc
@@ -242,7 +240,7 @@
 ; 2252
 
 GetDestinationWarpNumber:: ; 2252
-	callba Function1499a
+	callba CheckWarpCollision
 	ret nc
 
 	ld a, [hROMBank]
@@ -366,8 +364,6 @@
 	ret
 ; 22ee
 
-
-
 CheckOutdoorMap:: ; 22ee
 	cp ROUTE
 	ret z
@@ -395,7 +391,6 @@
 	ret
 ; 2309
 
-
 LoadMapAttributes:: ; 2309
 	call CopyMapHeaders
 	call SwitchToMapScriptHeaderBank
@@ -503,7 +498,6 @@
 	ret
 ; 23a3
 
-
 GetMapConnection:: ; 23a3
 ; Load map connection struct at hl into de.
 	ld c, SouthMapConnection - NorthMapConnection
@@ -516,7 +510,6 @@
 	ret
 ; 23ac
 
-
 ReadMapTriggers:: ; 23ac
 	ld a, [hli] ; trigger count
 	ld c, a
@@ -749,8 +742,6 @@
 	ret
 ; 24e4
 
-
-
 ChangeMap:: ; 24e4
 	ld a, [hROMBank]
 	push af
@@ -801,8 +792,6 @@
 	ret
 ; 2524
 
-
-
 FillMapConnections:: ; 2524
 
 ; North
@@ -901,7 +890,6 @@
 	ret
 ; 25d3
 
-
 FillNorthConnectionStrip::
 FillSouthConnectionStrip:: ; 25d3
 
@@ -938,7 +926,6 @@
 	ret
 ; 25f6
 
-
 FillWestConnectionStrip::
 FillEastConnectionStrip:: ; 25f6
 
@@ -983,7 +970,6 @@
 	ret
 ; 261f
 
-
 CallScript:: ; 261f
 ; Call a script at a:hl.
 
@@ -1138,7 +1124,6 @@
 	ret
 ; 26d4
 
-
 GetScriptByte:: ; 0x26d4
 ; Return byte at ScriptBank:ScriptPos in a.
 
@@ -1170,7 +1155,6 @@
 	ret
 ; 0x26ef
 
-
 ObjectEvent:: ; 0x26ef
 	jumptextfaceplayer ObjectEventText
 ; 0x26f2
@@ -1180,7 +1164,6 @@
 	db "@"
 ; 0x26f7
 
-
 BGEvent:: ; 26f7
 	jumptext BGEventText
 ; 26fa
@@ -1190,7 +1173,6 @@
 	db "@"
 ; 26ff
 
-
 CoordinatesEvent:: ; 26ff
 	jumptext CoordinatesEventText
 ; 2702
@@ -1200,7 +1182,6 @@
 	db "@"
 ; 2707
 
-
 CheckObjectMask:: ; 2707
 	ld a, [hMapObjectIndexBuffer]
 	ld e, a
@@ -1231,7 +1212,6 @@
 	ret
 ; 272a
 
-
 ScrollMapDown:: ; 272a
 	hlcoord 0, 0
 	ld de, BGMapBuffer
@@ -1472,7 +1452,7 @@
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
-	ld de, XCoord + 1
+	ld de, wScreenSave
 	ld c, $5
 	ld b, $6
 .asm_2886
@@ -1501,9 +1481,9 @@
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
-	ld de, XCoord + 1
+	ld de, wScreenSave
 	ld a, [MapWidth]
-	add $6
+	add 6
 	ld [hMapObjectIndexBuffer], a
 	ld a, [wPlayerStepDirection]
 	and a
@@ -1517,7 +1497,7 @@
 	ret
 
 .up
-	ld de, wdcbf
+	ld de, wScreenSave + 6
 	ld a, [hMapObjectIndexBuffer]
 	ld c, a
 	ld b, $0
@@ -1525,27 +1505,24 @@
 	jr .vertical
 
 .down
-	ld de, XCoord + 1
-
+	ld de, wScreenSave
 .vertical
-	ld b, $6
-	ld c, $4
-	jr Function28f7
+	ld b, 6
+	ld c, 4
+	jr SaveScreen_LoadNeighbor
 
 .left
-	ld de, XCoord + 2
+	ld de, wScreenSave + 1
 	inc hl
 	jr .horizontal
 
 .right
-	ld de, XCoord + 1
-
+	ld de, wScreenSave
 .horizontal
-	ld b, $5
-	ld c, $5
-	jr Function28f7
+	ld b, 5
+	ld c, 5
+	jr SaveScreen_LoadNeighbor
 
-
 LoadNeighboringBlockData:: ; 28e3
 	ld hl, wOverworldMapAnchor
 	ld a, [hli]
@@ -1552,26 +1529,26 @@
 	ld h, [hl]
 	ld l, a
 	ld a, [MapWidth]
-	add $6
+	add 6
 	ld [hConnectionStripLength], a
-	ld de, XCoord + 1
-	ld b, $6
-	ld c, $5
+	ld de, wScreenSave
+	ld b, 6
+	ld c, 5
 
-Function28f7:: ; 28f7
-.loop1
+SaveScreen_LoadNeighbor:: ; 28f7
+.row
 	push bc
 	push hl
 	push de
-.loop2
+.col
 	ld a, [de]
 	inc de
 	ld [hli], a
 	dec b
-	jr nz, .loop2
+	jr nz, .col
 	pop de
 	ld a, e
-	add $6
+	add 6
 	ld e, a
 	jr nc, .okay
 	inc d
@@ -1580,11 +1557,11 @@
 	pop hl
 	ld a, [hConnectionStripLength]
 	ld c, a
-	ld b, $0
+	ld b, 0
 	add hl, bc
 	pop bc
 	dec c
-	jr nz, .loop1
+	jr nz, .row
 	ret
 ; 2914
 
@@ -1746,7 +1723,6 @@
 	ret
 ; 2a07
 
-
 GetFacingTileCoord:: ; 2a07
 ; Return map coordinates in (d, e) and tile id in a
 ; of the tile the player is facing.
@@ -1793,7 +1769,6 @@
 	dw TileRight
 ; 2a3c
 
-
 GetCoordTile:: ; 2a3c
 ; Get the collision byte for tile d, e
 	call GetBlockLocation
@@ -1861,7 +1836,6 @@
 	ret
 ; 2a8b
 
-
 CheckFacingSign:: ; 2a8b
 	call GetFacingTileCoord
 ; Load facing into b.
@@ -2002,7 +1976,6 @@
 	ret
 ; 2b29
 
-
 FadeToMenu:: ; 2b29
 	xor a
 	ld [hBGMapMode], a
@@ -2013,7 +1986,6 @@
 	ret
 ; 2b3c
 
-
 CloseSubmenu:: ; 2b3c
 	call ClearBGPalettes
 	call Function2bae
@@ -2032,7 +2004,7 @@
 Function2b5c:: ; 2b5c
 	ld b, SCGB_09
 	call GetSGBLayout
-	callba Function49409
+	callba LoadOW_BGPal7
 	call WaitBGMap2
 	callba FadeInPalettes
 	call EnableSpriteUpdates
@@ -2039,7 +2011,6 @@
 	ret
 ; 2b74
 
-
 Function2b74:: ; 0x2b74
 	push af
 	ld a, $1
@@ -2056,7 +2027,7 @@
 	call WaitBGMap2
 	ld b, SCGB_09
 	call GetSGBLayout
-	callba Function49409
+	callba LoadOW_BGPal7
 	call UpdateTimePals
 	call DelayFrame
 	ld a, $1
@@ -2078,7 +2049,7 @@
 	ld a, [MapNumber]
 	ld c, a
 	call SwitchToAnyMapBank
-	callba Function8c001
+	callba UpdateTimeOfDayPal
 	call OverworldTextModeSwitch
 	call LoadTileset
 	ld a, 9
@@ -2090,7 +2061,6 @@
 	ret
 ; 2be5
 
-
 GetMapHeaderPointer:: ; 2be5
 	ld a, [MapGroup]
 	ld b, a
@@ -2167,7 +2137,6 @@
 	ret
 ; 0x2c1c
 
-
 SwitchToMapBank:: ; 2c1c
 	ld a, [MapGroup]
 	ld b, a
@@ -2181,7 +2150,6 @@
 	ret
 ; 2c29
 
-
 GetMapBank:: ; 2c29
 	ld a, [MapGroup]
 	ld b, a
@@ -2223,7 +2191,6 @@
 	rst Bankswitch
 	ret
 ; 2c57
-
 
 GetMapScriptHeaderBank:: ; 2c57
 	ld a, [MapScriptHeaderBank]
--- a/lib/mobile/main.asm
+++ b/lib/mobile/main.asm
@@ -2697,7 +2697,7 @@
 	dec hl
 
 .asm_1111ee
-	ld bc, rIE
+	ld bc, -1
 .asm_1111f1
 	ld a, [hli]
 	inc bc
--- a/main.asm
+++ b/main.asm
@@ -89,7 +89,7 @@
 	ld a, VBGMap1 / $100
 	call Function64b9
 	call Function2e20
-	callba Function49409
+	callba LoadOW_BGPal7
 	callba Function96a4
 	ld a, $1
 	ld [hCGBPalUpdate], a
@@ -2078,7 +2078,8 @@
 	ret
 ; c699
 
-DrawPartyMenuHPBar: ; c699
+ComputeHPBarPixels: ; c699
+; bc * (6 * 8) / de
 	ld a, b
 	or c
 	jr z, .zero
@@ -2089,12 +2090,14 @@
 	ld [hMultiplicand + 1], a
 	ld a, c
 	ld [hMultiplicand + 2], a
-	ld a, $30
+	ld a, 6 * 8
 	ld [hMultiplier], a
 	call Multiply
+	; We need de to be under 256 because hDivisor is only 1 byte.
 	ld a, d
 	and a
 	jr z, .divide
+	; divide de and hProduct by 4
 	srl d
 	rr e
 	srl d
@@ -2109,11 +2112,10 @@
 	ld [hDividend + 3], a
 	ld a, b
 	ld [hDividend + 2], a
-
 .divide
 	ld a, e
 	ld [hDivisor], a
-	ld b, $4
+	ld b, 4
 	call Divide
 	ld a, [hQuotient + 2]
 	ld e, a
@@ -2120,11 +2122,11 @@
 	pop hl
 	and a
 	ret nz
-	ld e, $1
+	ld e, 1
 	ret
 
 .zero
-	ld e, $0
+	ld e, 0
 	ret
 ; c6e0
 
@@ -2193,13 +2195,13 @@
 ; Display "Badge required" text and return carry if the badge is not owned
 	call CheckEngineFlag
 	ret nc
-	ld hl, BadgeRequiredText
+	ld hl, .BadgeRequiredText
 	call MenuTextBoxBackup ; push text to queue
 	scf
 	ret
 ; c73d
 
-BadgeRequiredText: ; c73d
+.BadgeRequiredText: ; c73d
 	; Sorry! A new BADGE
 	; is required.
 	text_jump _BadgeRequiredText
@@ -2252,12 +2254,13 @@
 ; c779
 
 FieldMoveFailed: ; c779
-	ld hl, UnknownText_0xc780
+	ld hl, .CantUseHere
 	call MenuTextBoxBackup
 	ret
 ; c780
 
-UnknownText_0xc780: ; 0xc780
+.CantUseHere: ; 0xc780
+	; Can't use that here.
 	text_jump UnknownText_0x1c05c8
 	db "@"
 ; 0xc785
@@ -2274,9 +2277,10 @@
 ; c796
 
 .Jumptable: ; c796 (3:4796)
-	dw .CheckAble
-	dw .DoCut
-	dw .FailCut
+	jumptable_start
+	jumptable .CheckAble
+	jumptable .DoCut
+	jumptable .FailCut
 
 .CheckAble: ; c79c (3:479c)
 	ld de, ENGINE_HIVEBADGE
@@ -2286,9 +2290,11 @@
 	jr c, .nothingtocut
 	ld a, $1
 	ret
+
 .nohivebadge
 	ld a, $80
 	ret
+
 .nothingtocut
 	ld a, $2
 	ret
@@ -2300,18 +2306,18 @@
 	ret
 
 .FailCut: ; c7bb (3:47bb)
-	ld hl, UnknownText_0xc7c9
+	ld hl, Text_NothingToCut
 	call MenuTextBoxBackup
 	ld a, $80
 	ret
 
-UnknownText_0xc7c4: ; 0xc7c4
+Text_UsedCut: ; 0xc7c4
 	; used CUT!
 	text_jump UnknownText_0x1c05dd
 	db "@"
 ; 0xc7c9
 
-UnknownText_0xc7c9: ; 0xc7c9
+Text_NothingToCut: ; 0xc7c9
 	; There's nothing to CUT here.
 	text_jump UnknownText_0x1c05ec
 	db "@"
@@ -2318,6 +2324,7 @@
 ; 0xc7ce
 
 CheckMapForSomethingToCut: ; c7ce
+	; Does the collision data of the facing tile permit cutting?
 	call GetFacingTileCoord
 	ld c, a
 	push de
@@ -2324,21 +2331,26 @@
 	callba CheckCutCollision
 	pop de
 	jr nc, .fail
+	; Get the location of the current block in OverworldMap.
 	call GetBlockLocation
 	ld c, [hl]
+	; See if that block contains something that can be cut.
 	push hl
 	ld hl, CutTreeBlockPointers
 	call CheckOverworldTileArrays
 	pop hl
 	jr nc, .fail
+	; Back up the OverworldMap address to Buffer3
 	ld a, l
-	ld [wd1ec], a
+	ld [Buffer3], a
 	ld a, h
-	ld [wd1ed], a
+	ld [Buffer4], a
+	; Back up the replacement tile to Buffer5
 	ld a, b
-	ld [wd1ee], a
+	ld [Buffer5], a
+	; Back up the animation index to Buffer6
 	ld a, c
-	ld [wd1ef], a
+	ld [Buffer6], a
 	xor a
 	ret
 
@@ -2353,7 +2365,7 @@
 
 Script_Cut: ; 0xc802
 	callasm GetPartyNick
-	writetext UnknownText_0xc7c4
+	writetext Text_UsedCut
 	reloadmappart
 	callasm CutDownTreeOrGrass
 	closetext
@@ -2361,11 +2373,11 @@
 ; 0xc810
 
 CutDownTreeOrGrass: ; c810
-	ld hl, wd1ec
+	ld hl, Buffer3 ; OverworldMapTile
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
-	ld a, [wd1ee]
+	ld a, [Buffer5] ; ReplacementTile
 	ld [hl], a
 	xor a
 	ld [hBGMapMode], a
@@ -2372,7 +2384,7 @@
 	call OverworldTextModeSwitch
 	call UpdateSprites
 	call DelayFrame
-	ld a, [wd1ef]
+	ld a, [Buffer6] ; Animation type
 	ld e, a
 	callba OWCutAnimation
 	call BufferScreen
@@ -2384,6 +2396,12 @@
 ; c840
 
 CheckOverworldTileArrays: ; c840
+	; Input: c contains the tile you're facing
+	; Output: Replacement tile in b and effect on wild encounters in c, plus carry set.
+	;         Carry is not set if the facing tile cannot be replaced, or if the tileset
+	;         does not contain a tile you can replace.
+
+	; Dictionary lookup for pointer to tile replacement table
 	push bc
 	ld a, [wTileset]
 	ld de, 3
@@ -2390,16 +2408,20 @@
 	call IsInArray
 	pop bc
 	jr nc, .nope
+	; Load the pointer
 	inc hl
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
+	; Look up the tile you're facing
 	ld de, 3
 	ld a, c
 	call IsInArray
 	jr nc, .nope
+	; Load the replacement to b
 	inc hl
 	ld b, [hl]
+	; Load the animation type parameter to c
 	inc hl
 	ld c, [hl]
 	scf
@@ -2412,16 +2434,16 @@
 
 CutTreeBlockPointers: ; c862
 ; Which tileset are we in?
-	dbw TILESET_JOHTO_1, .one
-	dbw TILESET_JOHTO_2, .two
-	dbw TILESET_KANTO, .three
-	dbw TILESET_PARK, .twentyfive
-	dbw TILESET_ILEX_FOREST, .thirtyone
+	dbw TILESET_JOHTO_1, .johto1
+	dbw TILESET_JOHTO_2, .johto2
+	dbw TILESET_KANTO, .kanto
+	dbw TILESET_PARK, .park
+	dbw TILESET_ILEX_FOREST, .ilex
 	db -1
 ; c872
 
-.one: ; Johto OW
-; Which meta tile are we facing, which should we replace it with, and does it affect encounters?
+.johto1: ; Johto OW
+; Which meta tile are we facing, which should we replace it with, and which animation?
 	db $03, $02, $01 ; grass
 	db $5b, $3c, $00 ; tree
 	db $5f, $3d, $00 ; tree
@@ -2430,12 +2452,12 @@
 	db -1
 ; c882
 
-.two: ; Goldenrod area
+.johto2: ; Goldenrod area
 	db $03, $02, $01 ; grass
 	db -1
 ; c886
 
-.three: ; Kanto OW
+.kanto: ; Kanto OW
 	db $0b, $0a, $01 ; grass
 	db $32, $6d, $00 ; tree
 	db $33, $6c, $00 ; tree
@@ -2445,35 +2467,35 @@
 	db -1
 ; c899
 
-.twentyfive: ; National Park
+.park: ; National Park
 	db $13, $03, $01 ; grass
 	db $03, $04, $01 ; grass
 	db -1
 ; c8a0
 
-.thirtyone: ; Ilex Forest
+.ilex: ; Ilex Forest
 	db $0f, $17, $00
 	db -1
 ; c8a4
 
 WhirlpoolBlockPointers: ; c8a4
-	dbw TILESET_JOHTO_1, .one
+	dbw TILESET_JOHTO_1, .johto
 	db -1
 ; c8a8
 
-.one: ; c8a8
+.johto: ; c8a8
 	db $07, $36, $00
 	db -1
 ; c8ac
 
-Functionc8ac: ; c8ac
-	call Functionc8b5
+OWFlash: ; c8ac
+	call .CheckUseFlash
 	and $7f
 	ld [wd0ec], a
 	ret
 ; c8b5
 
-Functionc8b5: ; c8b5
+.CheckUseFlash: ; c8b5
 ; Flash
 	ld de, ENGINE_ZEPHYRBADGE
 	callba CheckBadge
@@ -2482,10 +2504,9 @@
 	callba SpecialAerodactylChamber
 	pop hl
 	jr c, .useflash
-	ld a, [wd847]
-	cp -1
+	ld a, [wTimeOfDayPalset]
+	cp %11111111 ; 3, 3, 3, 3
 	jr nz, .notadarkcave
-
 .useflash
 	call UseFlash
 	ld a, $81
@@ -2522,11 +2543,11 @@
 	ld de, SFX_FLASH
 	call PlaySFX
 	call WaitSFX
-	ld hl, UnknownText_0xc908
+	ld hl, .BlankText
 	ret
 ; c908
 
-UnknownText_0xc908: ; 0xc908
+.BlankText: ; 0xc908
 	db "@"
 ; 0xc909
 
@@ -3268,7 +3289,7 @@
 	ld hl, PartySpecies
 	add hl, de
 	ld a, [hl]
-	ld [wd1ef], a
+	ld [Buffer6], a
 	call GetPartyNick
 	ret
 ; cd29
@@ -3280,7 +3301,7 @@
 Script_UsedStrength: ; 0xcd2d
 	callasm Functioncd12
 	writetext UnknownText_0xcd41
-	copybytetovar wd1ef
+	copybytetovar Buffer6
 	cry 0
 	pause 3
 	writetext UnknownText_0xcd46
@@ -3438,13 +3459,13 @@
 	pop hl
 	jr nc, .failed
 	ld a, l
-	ld [wd1ec], a
+	ld [Buffer3], a
 	ld a, h
-	ld [wd1ed], a
+	ld [Buffer4], a
 	ld a, b
-	ld [wd1ee], a
+	ld [Buffer5], a
 	ld a, c
-	ld [wd1ef], a
+	ld [Buffer6], a
 	xor a
 	ret
 
@@ -3467,16 +3488,16 @@
 ; 0xce1d
 
 DisappearWhirlpool: ; ce1d
-	ld hl, wd1ec
+	ld hl, Buffer3
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
-	ld a, [wd1ee]
+	ld a, [Buffer5]
 	ld [hl], a
 	xor a
 	ld [hBGMapMode], a
 	call OverworldTextModeSwitch
-	ld a, [wd1ef]
+	ld a, [Buffer6]
 	ld e, a
 	callba PlayWhirlpoolSound
 	call BufferScreen
@@ -3816,7 +3837,7 @@
 
 .FishGotSomething: ; cff4
 	ld a, $1
-	ld [wd1ef], a
+	ld [Buffer6], a
 	ld hl, Script_GotABite
 	call QueueScript
 	ld a, $81
@@ -3825,7 +3846,7 @@
 
 .FishNoBite: ; d002
 	ld a, $2
-	ld [wd1ef], a
+	ld [Buffer6], a
 	ld hl, Script_NotEvenANibble
 	call QueueScript
 	ld a, $81
@@ -3834,7 +3855,7 @@
 
 .FailFish: ; d010
 	ld a, $0
-	ld [wd1ef], a
+	ld [Buffer6], a
 	ld hl, Script_NotEvenANibble2
 	call QueueScript
 	ld a, $81
@@ -4160,7 +4181,7 @@
 	ld [ScriptVar], a
 	call CheckMapForSomethingToCut
 	ret c
-	ld a, 1
+	ld a, TRUE
 	ld [ScriptVar], a
 	ret
 ; d1c8
@@ -5077,440 +5098,8 @@
 	inc [hl]
 	ret
 
-_AnimateHPBar: ; d627
-	call Functiond65f
-	jr c, .do_player
-	call Functiond670
-.enemy_loop
-	push bc
-	push hl
-	call Functiond6e2
-	pop hl
-	pop bc
-	push af
-	push bc
-	push hl
-	call Functiond730
-	call Functiond7c9
-	pop hl
-	pop bc
-	pop af
-	jr nc, .enemy_loop
-	ret
+INCLUDE "engine/anim_hp_bar.asm"
 
-.do_player
-	call Functiond670
-.player_loop
-	push bc
-	push hl
-	call Functiond6f5
-	pop hl
-	pop bc
-	ret c
-	push af
-	push bc
-	push hl
-	call Functiond749
-	call Functiond7c9
-	pop hl
-	pop bc
-	pop af
-	jr nc, .player_loop
-	ret
-; d65f
-
-Functiond65f: ; d65f
-	ld a, [Buffer2]
-	and a
-	jr nz, .player
-	ld a, [Buffer1]
-	cp $30
-	jr nc, .player
-	and a
-	ret
-
-.player
-	scf
-	ret
-; d670
-
-Functiond670: ; d670
-	push hl
-	ld hl, Buffer1
-	ld a, [hli]
-	ld e, a
-	ld a, [hli]
-	ld d, a
-	ld a, [hli]
-	ld c, a
-	ld a, [hli]
-	ld b, a
-	pop hl
-	call DrawPartyMenuHPBar
-	ld a, e
-	ld [wd1f1], a
-	ld a, [wd1ee]
-	ld c, a
-	ld a, [wd1ef]
-	ld b, a
-	ld a, [Buffer1]
-	ld e, a
-	ld a, [Buffer2]
-	ld d, a
-	call DrawPartyMenuHPBar
-	ld a, e
-	ld [wd1f2], a
-	push hl
-	ld hl, wd1ec
-	ld a, [hli]
-	ld c, a
-	ld a, [hli]
-	ld b, a
-	ld a, [hli]
-	ld e, a
-	ld a, [hli]
-	ld d, a
-	pop hl
-	ld a, e
-	sub c
-	ld e, a
-	ld a, d
-	sbc b
-	ld d, a
-	jr c, .asm_d6c1
-	ld a, [wd1ec]
-	ld [wd1f5], a
-	ld a, [wd1ee]
-	ld [wd1f6], a
-	ld bc, 1
-	jr .asm_d6d9
-
-.asm_d6c1
-	ld a, [wd1ec]
-	ld [wd1f6], a
-	ld a, [wd1ee]
-	ld [wd1f5], a
-	ld a, e
-	xor $ff
-	inc a
-	ld e, a
-	ld a, d
-	xor $ff
-	ld d, a
-	ld bc, rIE
-
-.asm_d6d9
-	ld a, d
-	ld [wd1f3], a
-	ld a, e
-	ld [wd1f4], a
-	ret
-; d6e2
-
-Functiond6e2: ; d6e2
-	ld hl, wd1f1
-	ld a, [wd1f2]
-	cp [hl]
-	jr nz, .asm_d6ed
-	scf
-	ret
-
-.asm_d6ed
-	ld a, c
-	add [hl]
-	ld [hl], a
-	call Functiond839
-	and a
-	ret
-; d6f5
-
-Functiond6f5: ; d6f5
-.asm_d6f5
-	ld hl, wd1ec
-	ld a, [hli]
-	ld e, a
-	ld a, [hli]
-	ld d, a
-	ld a, e
-	cp [hl]
-	jr nz, .asm_d707
-	inc hl
-	ld a, d
-	cp [hl]
-	jr nz, .asm_d707
-	scf
-	ret
-
-.asm_d707
-	ld l, e
-	ld h, d
-	add hl, bc
-	ld a, l
-	ld [wd1ec], a
-	ld a, h
-	ld [wd1ed], a
-	push hl
-	push de
-	push bc
-	ld hl, Buffer1
-	ld a, [hli]
-	ld e, a
-	ld a, [hli]
-	ld d, a
-	ld a, [hli]
-	ld c, a
-	ld a, [hli]
-	ld b, a
-	call DrawPartyMenuHPBar
-	pop bc
-	pop de
-	pop hl
-	ld a, e
-	ld hl, wd1f1
-	cp [hl]
-	jr z, .asm_d6f5
-	ld [hl], a
-	and a
-	ret
-; d730
-
-Functiond730: ; d730
-	call Functiond784
-	ld d, $6
-	ld a, [wd10a]
-	and $1
-	ld b, a
-	ld a, [wd1f1]
-	ld e, a
-	ld c, a
-	push de
-	call Functiond771
-	pop de
-	call Functiond7b4
-	ret
-; d749
-
-Functiond749: ; d749
-	call Functiond784
-	ld a, [wd1ec]
-	ld c, a
-	ld a, [wd1ed]
-	ld b, a
-	ld a, [Buffer1]
-	ld e, a
-	ld a, [Buffer2]
-	ld d, a
-	call DrawPartyMenuHPBar
-	ld c, e
-	ld d, $6
-	ld a, [wd10a]
-	and $1
-	ld b, a
-	push de
-	call Functiond771
-	pop de
-	call Functiond7b4
-	ret
-; d771
-
-Functiond771: ; d771
-	ld a, [wd10a]
-	cp $2
-	jr nz, .asm_d780
-	ld a, $28
-	add l
-	ld l, a
-	ld a, $0
-	adc h
-	ld h, a
-
-.asm_d780
-	call DrawBattleHPBar
-	ret
-; d784
-
-Functiond784: ; d784
-	ld a, [wd10a]
-	and a
-	ret z
-	cp $1
-	jr z, .load_15
-	ld de, $16
-	jr .loaded_de
-
-.load_15
-	ld de, $15
-
-.loaded_de
-	push hl
-	add hl, de
-	ld a, " "
-rept 2
-	ld [hli], a
-endr
-	ld [hld], a
-	dec hl
-	ld a, [wd1ec]
-	ld [StringBuffer2 + 1], a
-	ld a, [wd1ed]
-	ld [StringBuffer2], a
-	ld de, StringBuffer2
-	lb bc, 2, 3
-	call PrintNum
-	pop hl
-	ret
-; d7b4
-
-Functiond7b4: ; d7b4
-	ld a, [hCGB]
-	and a
-	ret z
-	ld hl, wd1f0
-	call SetHPPal
-	ld a, [wd1f0]
-	ld c, a
-	callba Function8c43
-	ret
-; d7c9
-
-Functiond7c9: ; d7c9
-	ld a, [hCGB]
-	and a
-	jr nz, .cgb
-	call DelayFrame
-	call DelayFrame
-	ret
-
-.cgb
-	ld a, [wd10a]
-	and a
-	jr z, .load_0
-	cp $1
-	jr z, .load_1
-	ld a, [CurPartyMon]
-	cp $3
-	jr nc, .c_is_1
-	ld c, $0
-	jr .c_is_0
-
-.c_is_1
-	ld c, $1
-
-.c_is_0
-	push af
-	cp $2
-	jr z, .skip_delay
-	cp $5
-	jr z, .skip_delay
-	ld a, $2
-	ld [hBGMapMode], a
-	ld a, c
-	ld [hBGMapThird], a
-	call DelayFrame
-
-.skip_delay
-	ld a, $1
-	ld [hBGMapMode], a
-	ld a, c
-	ld [hBGMapThird], a
-	call DelayFrame
-	pop af
-	cp $2
-	jr z, .two_frames
-	cp $5
-	jr z, .two_frames
-	ret
-
-.two_frames
-	inc c
-	ld a, $2
-	ld [hBGMapMode], a
-	ld a, c
-	ld [hBGMapThird], a
-	call DelayFrame
-	ld a, $1
-	ld [hBGMapMode], a
-	ld a, c
-	ld [hBGMapThird], a
-	call DelayFrame
-	ret
-
-.load_0
-	ld c, $0
-	jr .finish
-
-.load_1
-	ld c, $1
-
-.finish
-	call DelayFrame
-	ld a, c
-	ld [hBGMapThird], a
-	call DelayFrame
-	ret
-; d839
-
-Functiond839: ; d839
-	ld a, [Buffer1]
-	ld c, a
-	ld b, $0
-	ld hl, 0
-	ld a, [wd1f1]
-	cp $30
-	jr nc, .coppy_buffer
-	and a
-	jr z, .return_zero
-	call AddNTimes
-	ld b, $0
-.loop
-	ld a, l
-	sub $30
-	ld l, a
-	ld a, h
-	sbc $0
-	ld h, a
-	jr c, .done
-	inc b
-	jr .loop
-
-.done
-	push bc
-	ld bc, $80
-	add hl, bc
-	pop bc
-	ld a, l
-	sub $30
-	ld l, a
-	ld a, h
-	sbc $0
-	ld h, a
-	jr c, .no_carry
-	inc b
-
-.no_carry
-	ld a, [wd1f5]
-	cp b
-	jr nc, .finish
-	ld a, [wd1f6]
-	cp b
-	jr c, .finish
-	ld a, b
-
-.finish
-	ld [wd1ec], a
-	ret
-
-.return_zero
-	xor a
-	ld [wd1ec], a
-	ret
-
-.coppy_buffer
-	ld a, [Buffer1]
-	ld [wd1ec], a
-	ret
-; d88c
-
 TryAddMonToParty: ; d88c
 ; Check if to copy wild Pkmn or generate new Pkmn
 	; Whose is it?
@@ -8380,7 +7969,8 @@
 
 INCLUDE "engine/overworld.asm"
 
-Function1499a:: ; 1499a
+CheckWarpCollision:: ; 1499a
+; Is this tile a warp?
 	ld a, [PlayerNextTile]
 	cp $60
 	jr z, .warp
@@ -8397,15 +7987,17 @@
 	ret
 ; 149af
 
-Function149af:: ; 149af
+CheckDirectionalWarp:: ; 149af
+; If this is a directional warp, clear carry (press the designated button to warp).
+; Else, set carry (immediate warp).
 	ld a, [PlayerNextTile]
-	cp $70
+	cp $70 ; Warp on down
 	jr z, .not_warp
-	cp $76
+	cp $76 ; Warp on left
 	jr z, .not_warp
-	cp $78
+	cp $78 ; Warp on up
 	jr z, .not_warp
-	cp $7e
+	cp $7e ; Warp on right
 	jr z, .not_warp
 	scf
 	ret
@@ -8415,7 +8007,7 @@
 	ret
 ; 149c6
 
-CheckWarpCollision: ; 149c6
+CheckWarpFacingDown: ; 149c6
 	ld de, 1
 	ld hl, .blocks
 	ld a, [PlayerNextTile]
@@ -11508,7 +11100,7 @@
 	ld a, $5 ; BANK(UnknBGPals)
 	call FarCopyWRAM
 	ld de, UnknBGPals + $38
-	ld hl, Palette_49418
+	ld hl, Palette_TextBG7
 	ld bc, $8
 	ld a, $5 ; BANK(UnknBGPals)
 	call FarCopyWRAM
@@ -11587,8 +11179,8 @@
 	RGB 00, 00, 00
 ; 49409
 
-Function49409:: ; 49409
-	ld hl, Palette_49418
+LoadOW_BGPal7:: ; 49409
+	ld hl, Palette_TextBG7
 	ld de, UnknBGPals + 8 * 7
 	ld bc, 8
 	ld a, $5
@@ -11596,7 +11188,7 @@
 	ret
 ; 49418
 
-Palette_49418: ; 49418
+Palette_TextBG7: ; 49418
 	RGB 31, 31, 31
 	RGB 08, 19, 28
 	RGB 05, 05, 16
@@ -12400,23 +11992,23 @@
 
 INCLUDE "engine/map_triggers.asm"
 
-Function4d15b:: ; 4d15b
-	ld hl, wc608
+_LoadMapPart:: ; 4d15b
+	ld hl, wMisc
 	ld a, [wMetatileStandingY]
 	and a
-	jr z, .skip
-	ld bc, $30
+	jr z, .top_row
+	ld bc, WMISC_WIDTH * 2
 	add hl, bc
 
-.skip
+.top_row
 	ld a, [wMetatileStandingX]
 	and a
-	jr z, .next_dw
+	jr z, .left_column
 rept 2
 	inc hl
 endr
 
-.next_dw
+.left_column
 	decoord 0, 0
 	ld b, SCREEN_HEIGHT
 .loop
@@ -14362,7 +13954,7 @@
 	ld c, e
 
 .asm_50b41
-	predef DrawPartyMenuHPBar
+	predef ComputeHPBarPixels
 	ld a, 6
 	ld d, a
 	ld c, a
@@ -15065,7 +14657,7 @@
 _SwitchPartyMons:
 	ld a, [wd0e3]
 	dec a
-	ld [wd1ec], a
+	ld [Buffer3], a
 	ld b, a
 	ld a, [MenuSelection2]
 	dec a
@@ -15073,7 +14665,7 @@
 	cp b
 	jr z, .skip
 	call .SwapMonAndMail
-	ld a, [wd1ec]
+	ld a, [Buffer3]
 	call .ClearSprite
 	ld a, [Buffer2] ; wd1eb (aliases: MovementType)
 	call .ClearSprite
--- a/misc/crystal_misc.asm
+++ b/misc/crystal_misc.asm
@@ -49,7 +49,7 @@
 	call Function17ac0c
 	callba Function104000
 	call Function17abcf
-	callba Function49409
+	callba LoadOW_BGPal7
 	callba Function49420
 	call SetPalettes
 	call DelayFrame
--- a/misc/mobile_40.asm
+++ b/misc/mobile_40.asm
@@ -428,7 +428,7 @@
 ; 1002ed
 
 Function1002ed: ; 1002ed
-	callba Function49409
+	callba LoadOW_BGPal7
 	callba Function96a4
 	ld a, $1
 	ld [hCGBPalUpdate], a
--- a/tilesets/animations.asm
+++ b/tilesets/animations.asm
@@ -997,7 +997,7 @@
 	cp %11100100
 	ret nz
 ; We only want to be here if we're in a dark cave.
-	ld a, [wd847]
+	ld a, [wTimeOfDayPalset]
 	cp $ff ; 3,3,3,3
 	ret nz
 
--- a/wram.asm
+++ b/wram.asm
@@ -548,7 +548,7 @@
 	hall_of_fame wHallOfFameTemp
 	ds wHallOfFameTemp - @
 
-wMisc:: ; ds $28 * 6
+wMisc:: ; ds (SCREEN_WIDTH + 4) * (SCREEN_HEIGHT + 2)
 wBattle::
 wc608::
 
@@ -2560,8 +2560,8 @@
 	ds 1
 	ds 4
 ; d846
-wd846:: ds 1
-wd847:: ds 1
+wTimeOfDayPalFlags:: ds 1
+wTimeOfDayPalset:: ds 1
 CurTimeOfDay:: ; d848
 	ds 1
 
@@ -2949,10 +2949,7 @@
 	ds 1 ; current y coordinate relative to top-left corner of current map
 XCoord:: ; dcb8
 	ds 1 ; current x coordinate relative to top-left corner of current map
-
-	ds 6
-wdcbf:: ds 1
-	ds 23
+wScreenSave:: ds 6 * 5
 
 wMapDataEnd::