shithub: pokecrystal

Download patch

ref: 1f3091903752841a00f86141543ec5f42c992ec7
parent: baf50317d355b1dcc65eef10cbf750f8567be340
parent: 9755ff375a7e80b978d9cd32052a6cf2cc7c45cf
author: Bryan Bishop <[email protected]>
date: Wed May 28 15:51:41 EDT 2014

Merge pull request #253 from yenatch/master

Clean up music and battle interfaces in home.asm.

--- a/constants/misc_constants.asm
+++ b/constants/misc_constants.asm
@@ -2,6 +2,7 @@
 ; name length
 PLAYER_NAME_LENGTH EQU 8
 PKMN_NAME_LENGTH EQU 11
+NAME_LENGTH EQU 11
 
 ; boxes
 NUM_BOXES EQU 14
--- a/engine/scripting.asm
+++ b/engine/scripting.asm
@@ -461,11 +461,11 @@
 ; script command 0x4e
 
 	call YesNoBox
-	ld a, $0
+	ld a, 0
 	jr c, .asm_96ef6 ; 0x96ef2 $2
-	ld a, $1
+	ld a, 1
 .asm_96ef6
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	ret
 ; 0x96efa
 
@@ -500,10 +500,10 @@
 
 	call GetScriptByte
 	and a
-	jr nz, .asm_96f1f ; 0x96f1a $3
-	ld a, [$c2dd]
-.asm_96f1f
-	ld [$d108], a
+	jr nz, .ok
+	ld a, [ScriptVar]
+.ok
+	ld [CurPartySpecies], a
 	callba Function244e3
 	ret
 ; 0x96f29
@@ -522,10 +522,10 @@
 	ld hl, Function1d81
 	rst FarCall
 	ld a, [$cfa9]
-	jr nc, .asm_96f3d ; 0x96f3a $1
+	jr nc, .ok
 	xor a
-.asm_96f3d
-	ld [$c2dd], a
+.ok
+	ld [ScriptVar], a
 	ret
 ; 0x96f41
 
@@ -536,10 +536,10 @@
 	ld hl, Function202a
 	rst FarCall
 	ld a, [$cf88]
-	jr nc, .asm_96f4e ; 0x96f4b $1
+	jr nc, .ok
 	xor a
-.asm_96f4e
-	ld [$c2dd], a
+.ok
+	ld [ScriptVar], a
 	ret
 ; 0x96f52
 
@@ -607,21 +607,21 @@
 
 	call GetScriptByte
 	cp $ff
-	jr nz, .asm_96f98 ; 0x96f93 $3
-	ld a, [$c2dd]
-.asm_96f98
-	ld [$d106], a
+	jr nz, .ok
+	ld a, [ScriptVar]
+.ok
+	ld [CurItem], a
 	call GetScriptByte
-	call Unknown_0x9769e
+	call Function9769e
 	ld a, [de]
 	ld [$d10c], a
-	ld hl, $d892
+	ld hl, NumItems
 	call ReceiveItem
 	ld a, $1
-	jr c, .asm_96fb0 ; 0x96fad $1
+	jr c, .ok2
 	xor a
-.asm_96fb0
-	ld [$c2dd], a
+.ok2
+	ld [ScriptVar], a
 	call CurItemName
 	ld de, StringBuffer1
 	ld a, $1
@@ -745,7 +745,7 @@
 ;     floor_list_pointer (PointerLabelParam)
 
 	xor a
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	call GetScriptByte
 	ld e, a
 	call GetScriptByte
@@ -755,7 +755,7 @@
 	callba Function1342d
 	ret c
 	ld a, $1
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	ret
 ; 0x97099
 
@@ -812,7 +812,7 @@
 	call GetScriptByte
 	ld a, $2
 .asm_970db
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	ret
 ; 0x970df
 
@@ -895,7 +895,7 @@
 ;     action (SingleByteParam)
 
 	xor a
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	ld hl, $d041
 	ld e, [hl]
 	inc hl
@@ -907,7 +907,7 @@
 	and a
 	ret z
 	ld a, $1
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	ret
 ; 0x9714c
 
@@ -943,12 +943,12 @@
 ; script command 0x67
 
 	ld a, $1
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	ld a, [$d04d]
 	and a
 	ret nz
 	xor a
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	ret
 ; 0x9717a
 
@@ -964,7 +964,7 @@
 Script_playmapmusic: ; 0x97185
 ; script command 0x82
 
-	call Function3cdf
+	call PlayMapMusic
 	ret
 ; 0x97189
 
@@ -973,7 +973,7 @@
 ; parameters:
 ;     music_pointer (MultiByteParam)
 
-	ld de, $0000
+	ld de, MUSIC_NONE
 	call PlayMusic
 	xor a
 	ld [$c2a7], a
@@ -993,9 +993,9 @@
 ;     fadetime (SingleByteParam)
 
 	call GetScriptByte
-	ld [$c2a9], a
+	ld [MusicFadeID], a
 	call GetScriptByte
-	ld [$c2aa], a
+	ld [MusicFadeID + 1], a
 	call GetScriptByte
 	and $7f
 	ld [$c2a7], a
@@ -1041,13 +1041,13 @@
 	pop af
 	and a
 	jr nz, .asm_971df ; 0x971da $3
-	ld a, [$c2dd]
+	ld a, [ScriptVar]
 .asm_971df
 	call Function37ce
 	ret
 ; 0x971e3
 
-Unknown_0x971e3: ; 0x971e3
+Function971e3: ; 0x971e3
 	and a
 	ret z
 	cp $fe
@@ -1062,7 +1062,7 @@
 ;     person (SingleByteParam)
 
 	call GetScriptByte
-	call Unknown_0x971e3
+	call Function971e3
 	ld [$ffe0], a
 	ret
 ; 0x971f3
@@ -1074,7 +1074,7 @@
 ;     data (MovementPointerLabelParam)
 
 	call GetScriptByte
-	call Unknown_0x971e3
+	call Function971e3
 	ld c, a
 ; 971fa
 
@@ -1084,7 +1084,7 @@
 	callba Function585c
 	pop bc
 	push bc
-	call Unknown_0x97221
+	call Function97221
 	pop bc
 	call GetScriptByte
 	ld l, a
@@ -1100,7 +1100,7 @@
 	ret
 ; 0x97221
 
-Unknown_0x97221: ; 0x97221
+Function97221: ; 0x97221
 	callba Function5897
 	ret
 ; 0x97228
@@ -1131,7 +1131,7 @@
 	ld e, a
 	ld a, [$ffe0]
 	ld d, a
-	call Unknown_0x9728b
+	call Function9728b
 	ret
 ; 0x97248
 
@@ -1142,7 +1142,7 @@
 ;     person2 (SingleByteParam)
 
 	call GetScriptByte
-	call Unknown_0x971e3
+	call Function971e3
 	cp $fe
 	jr c, .asm_97254 ; 0x97250 $2
 	ld a, [$ffe0]
@@ -1149,7 +1149,7 @@
 .asm_97254
 	ld e, a
 	call GetScriptByte
-	call Unknown_0x971e3
+	call Function971e3
 	cp $fe
 	jr nz, .asm_97261 ; 0x9725d $2
 	ld a, [$ffe0]
@@ -1164,7 +1164,7 @@
 	add a
 	ld e, a
 	ld d, c
-	call Unknown_0x9728b
+	call Function9728b
 	ret
 ; 0x97274
 
@@ -1175,7 +1175,7 @@
 ;     facing (SingleByteParam)
 
 	call GetScriptByte
-	call Unknown_0x971e3
+	call Function971e3
 	cp $fe
 	jr nz, .asm_97280 ; 0x9727c $2
 	ld a, [$ffe0]
@@ -1185,11 +1185,11 @@
 	add a
 	add a
 	ld e, a
-	call Unknown_0x9728b
+	call Function9728b
 	ret
 ; 0x9728b
 
-Unknown_0x9728b: ; 0x9728b
+Function9728b: ; 0x9728b
 	ld a, d
 	push de
 	call Function18de
@@ -1211,7 +1211,7 @@
 	ld hl, $d0ed
 	bit 6, [hl]
 	jr nz, .asm_972b5 ; 0x972b0 $3
-	call Unknown_0x972bc
+	call Function972bc
 .asm_972b5
 	call Function1ad2
 	ret
@@ -1221,7 +1221,7 @@
 	ret
 ; 0x972bc
 
-Unknown_0x972bc: ; 0x972bc
+Function972bc: ; 0x972bc
 	call Function217a
 	ld hl, TileMap
 	ld bc, $0168
@@ -1257,11 +1257,11 @@
 ;     person (SingleByteParam)
 
 	call GetScriptByte
-	call Unknown_0x971e3
+	call Function971e3
 	call Function1956
 	ld a, [$ffaf]
 	ld b, $0
-	call Unknown_0x9730b
+	call Function9730b
 	ret
 ; 0x972ee
 
@@ -1271,7 +1271,7 @@
 ;     person (SingleByteParam)
 
 	call GetScriptByte
-	call Unknown_0x971e3
+	call Function971e3
 	cp $fe
 	jr nz, .asm_972fa ; 0x972f6 $2
 	ld a, [$ffe0]
@@ -1279,12 +1279,12 @@
 	call Function199f
 	ld a, [$ffaf]
 	ld b, $1
-	call Unknown_0x9730b
+	call Function9730b
 	callba Function5920
 	ret
 ; 0x9730b
 
-Unknown_0x9730b: ; 0x9730b
+Function9730b: ; 0x9730b
 	push bc
 	call GetMapObject
 	ld hl, $000c
@@ -1312,10 +1312,10 @@
 ;     person1 (SingleByteParam)
 
 	call GetScriptByte
-	call Unknown_0x971e3
+	call Function971e3
 	ld b, a
 	call GetScriptByte
-	call Unknown_0x971e3
+	call Function971e3
 	ld c, a
 	callba Function5803
 	ret
@@ -1336,7 +1336,7 @@
 ;     y (SingleByteParam)
 
 	call GetScriptByte
-	call Unknown_0x971e3
+	call Function971e3
 	ld b, a
 	call GetScriptByte
 	add $4
@@ -1354,7 +1354,7 @@
 ;     person (SingleByteParam)
 
 	call GetScriptByte
-	call Unknown_0x971e3
+	call Function971e3
 	cp $fe
 	jr nz, .asm_97367 ; 0x97363 $2
 	ld a, [$ffe0]
@@ -1371,10 +1371,10 @@
 ;     person1 (SingleByteParam)
 
 	call GetScriptByte
-	call Unknown_0x971e3
+	call Function971e3
 	ld b, a
 	call GetScriptByte
-	call Unknown_0x971e3
+	call Function971e3
 	ld c, a
 	callba Function839e
 	ret
@@ -1388,7 +1388,7 @@
 	call GetScriptByte
 	cp $ff
 	jr nz, .asm_9738e ; 0x97389 $3
-	ld a, [$c2dd]
+	ld a, [ScriptVar]
 .asm_9738e
 	ld c, a
 	callba Function1442f
@@ -1403,9 +1403,9 @@
 ;     time (DecimalParam)
 
 	call GetScriptByte
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	call GetScriptByte
-	call Unknown_0x971e3
+	call Function971e3
 	cp $fe
 	jr z, .asm_973a8 ; 0x973a4 $2
 	ld [$ffe0], a
@@ -1473,7 +1473,7 @@
 	ld a, $19
 	ld [$d22e], a
 	ld a, $5
-	ld [$d143], a
+	ld [CurPartyLevel], a
 	ret
 ; 0x973fb
 
@@ -1508,7 +1508,7 @@
 	call GetScriptByte
 	ld [$d22e], a
 	call GetScriptByte
-	ld [$d143], a
+	ld [CurPartyLevel], a
 	ret
 ; 0x97424
 
@@ -1535,7 +1535,7 @@
 	call Predef
 	ld a, [$d0ee]
 	and $3f
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	ret
 ; 0x97447
 
@@ -1663,7 +1663,7 @@
 	ret
 ; 0x974f3
 
-Unknown_0x974f3:: ; 0x974f3
+Function974f3:: ; 0x974f3
 	ld a, [ScriptBank]
 	or $80
 	ld [ScriptBank], a
@@ -1720,7 +1720,7 @@
 ; parameters:
 ;     pointer (ScriptPointerLabelParam)
 
-	ld a, [$c2dd]
+	ld a, [ScriptVar]
 	and a
 	jp nz, SkipTwoScriptBytes
 	jp Script_2jump
@@ -1731,7 +1731,7 @@
 ; parameters:
 ;     pointer (ScriptPointerLabelParam)
 
-	ld a, [$c2dd]
+	ld a, [ScriptVar]
 	and a
 	jp nz, Script_2jump
 	jp SkipTwoScriptBytes
@@ -1744,7 +1744,7 @@
 ;     pointer (ScriptPointerLabelParam)
 
 	call GetScriptByte
-	ld hl, $c2dd
+	ld hl, ScriptVar
 	cp [hl]
 	jr z, Script_2jump ; 0x97547 $b5
 	jr SkipTwoScriptBytes ; 0x97549 $4b
@@ -1757,7 +1757,7 @@
 ;     pointer (ScriptPointerLabelParam)
 
 	call GetScriptByte
-	ld hl, $c2dd
+	ld hl, ScriptVar
 	cp [hl]
 	jr nz, Script_2jump ; 0x97552 $aa
 	jr SkipTwoScriptBytes ; 0x97554 $40
@@ -1769,7 +1769,7 @@
 ;     byte (SingleByteParam)
 ;     pointer (ScriptPointerLabelParam)
 
-	ld a, [$c2dd]
+	ld a, [ScriptVar]
 	ld b, a
 	call GetScriptByte
 	cp b
@@ -1785,7 +1785,7 @@
 
 	call GetScriptByte
 	ld b, a
-	ld a, [$c2dd]
+	ld a, [ScriptVar]
 	cp b
 	jr c, Script_2jump ; 0x9756a $92
 	jr SkipTwoScriptBytes ; 0x9756c $28
@@ -1866,11 +1866,11 @@
 
 	call Function211b
 	jr z, .asm_975cb ; 0x975c5 $4
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	ret
 .asm_975cb
 	ld a, $ff
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	ret
 ; 0x975d1
 
@@ -1889,11 +1889,11 @@
 	or e
 	jr z, .asm_975e5 ; 0x975de $5
 	ld a, [de]
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	ret
 .asm_975e5
 	ld a, $ff
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	ret
 ; 0x975eb
 
@@ -1943,7 +1943,7 @@
 	call GetScriptByte
 	ld h, a
 	ld a, [hl]
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	ret
 ; 0x97616
 
@@ -1956,7 +1956,7 @@
 	ld l, a
 	call GetScriptByte
 	ld h, a
-	ld a, [$c2dd]
+	ld a, [ScriptVar]
 	ld [hl], a
 	ret
 ; 0x97623
@@ -1982,7 +1982,7 @@
 ;     value (SingleByteParam)
 
 	call GetScriptByte
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	ret
 ; 0x97637
 
@@ -1992,7 +1992,7 @@
 ;     value (SingleByteParam)
 
 	call GetScriptByte
-	ld hl, $c2dd
+	ld hl, ScriptVar
 	add [hl]
 	ld [hl], a
 	ret
@@ -2004,11 +2004,11 @@
 ;     input (SingleByteParam)
 
 	call GetScriptByte
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	and a
 	ret z
 	ld c, a
-	call Unknown_0x97673
+	call Function97673
 	and a
 	jr z, .asm_9765f ; 0x9764d $10
 	ld b, a
@@ -2030,15 +2030,15 @@
 	ld a, [$ffe1]
 .asm_97666
 	push af
-	ld a, [$c2dd]
+	ld a, [ScriptVar]
 	ld c, a
 	pop af
 	call SimpleDivide
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	ret
 ; 0x97673
 
-Unknown_0x97673: ; 0x97673
+Function97673: ; 0x97673
 	xor a
 	ld b, a
 	sub c
@@ -2057,9 +2057,9 @@
 ;     variable_id (SingleByteParam)
 
 	call GetScriptByte
-	call Unknown_0x9769e
+	call Function9769e
 	ld a, [de]
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	ret
 ; 0x97688
 
@@ -2069,8 +2069,8 @@
 ;     variable_id (SingleByteParam)
 
 	call GetScriptByte
-	call Unknown_0x9769e
-	ld a, [$c2dd]
+	call Function9769e
+	ld a, [ScriptVar]
 	ld [de], a
 	ret
 ; 0x97693
@@ -2082,13 +2082,13 @@
 ;     value (SingleByteParam)
 
 	call GetScriptByte
-	call Unknown_0x9769e
+	call Function9769e
 	call GetScriptByte
 	ld [de], a
 	ret
 ; 0x9769e
 
-Unknown_0x9769e: ; 0x9769e
+Function9769e: ; 0x9769e
 	ld c, a
 	callba Function80648
 	ret
@@ -2098,7 +2098,7 @@
 ; script command 0x18
 
 	ld a, [Version]
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	ret
 ; 0x976ad
 
@@ -2115,7 +2115,7 @@
 	call GetScriptByte
 	and a
 	jr nz, .asm_976b7 ; 0x976b2 $3
-	ld a, [$c2dd]
+	ld a, [ScriptVar]
 .asm_976b7
 	ld [$d265], a
 	call GetPokemonName
@@ -2146,7 +2146,7 @@
 	call GetScriptByte
 	and a
 	jr nz, .asm_976de ; 0x976d9 $3
-	ld a, [$c2dd]
+	ld a, [ScriptVar]
 .asm_976de
 	ld [$d265], a
 	call GetItemName
@@ -2228,8 +2228,8 @@
 ;     account (SingleByteParam)
 ;     memory (SingleByteParam)
 
-	call Unknown_0x97771
-	call Unknown_0x97861
+	call Function97771
+	call Function97861
 	ld hl, StringBuffer1
 	ld bc, $4306
 	call PrintNum
@@ -2242,7 +2242,7 @@
 ; parameters:
 ;     memory (SingleByteParam)
 
-	call Unknown_0x97771
+	call Function97771
 	ld hl, StringBuffer1
 	ld de, Coins
 	ld bc, $4206
@@ -2256,8 +2256,8 @@
 ; parameters:
 ;     memory (SingleByteParam)
 
-	call Unknown_0x97771
-	ld de, $c2dd
+	call Function97771
+	ld de, ScriptVar
 	ld hl, StringBuffer1
 	ld bc, $4103
 	call PrintNum
@@ -2265,7 +2265,7 @@
 	jp Unknown_976c0
 ; 0x97771
 
-Unknown_0x97771: ; 0x97771
+Function97771: ; 0x97771
 	ld hl, StringBuffer1
 	ld bc, $000b
 	ld a, "@"
@@ -2337,20 +2337,20 @@
 	call GetScriptByte
 	cp $ff
 	jr nz, .asm_977d4 ; 0x977cf $3
-	ld a, [$c2dd]
+	ld a, [ScriptVar]
 .asm_977d4
-	ld [$d106], a
+	ld [CurItem], a
 	call GetScriptByte
 	ld [$d10c], a
-	ld hl, $d892
+	ld hl, NumItems
 	call ReceiveItem
 	jr nc, .asm_977eb ; 0x977e3 $6
 	ld a, $1
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	ret
 .asm_977eb
 	xor a
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	ret
 ; 0x977f0
 
@@ -2361,18 +2361,18 @@
 ;     quantity (DecimalParam)
 
 	xor a
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	call GetScriptByte
-	ld [$d106], a
+	ld [CurItem], a
 	call GetScriptByte
 	ld [$d10c], a
 	ld a, $ff
 	ld [$d107], a
-	ld hl, $d892
+	ld hl, NumItems
 	call TossItem
 	ret nc
 	ld a, $1
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	ret
 ; 0x97812
 
@@ -2382,14 +2382,14 @@
 ;     item (ItemLabelByte)
 
 	xor a
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	call GetScriptByte
-	ld [$d106], a
-	ld hl, $d892
+	ld [CurItem], a
+	ld hl, NumItems
 	call CheckItem
 	ret nc
-	ld a, $1
-	ld [$c2dd], a
+	ld a, 1
+	ld [ScriptVar], a
 	ret
 ; 0x97829
 
@@ -2399,8 +2399,8 @@
 ;     account (SingleByteParam)
 ;     money (MoneyByteParam)
 
-	call Unknown_0x97861
-	call Unknown_0x9786d
+	call Function97861
+	call Function9786d
 	callba Function15fd7
 	ret
 ; 0x97836
@@ -2411,8 +2411,8 @@
 ;     account (SingleByteParam)
 ;     money (MoneyByteParam)
 
-	call Unknown_0x97861
-	call Unknown_0x9786d
+	call Function97861
+	call Function9786d
 	callba Function15ffa
 	ret
 ; 0x97843
@@ -2423,27 +2423,27 @@
 ;     account (SingleByteParam)
 ;     money (MoneyByteParam)
 
-	call Unknown_0x97861
-	call Unknown_0x9786d
+	call Function97861
+	call Function9786d
 	callba Function1600b
 ; 0x9784f
 
 Unknown_9784f: ; 0x9784f
-	jr c, .asm_9785b ; 0x9784f $a
-	jr z, .asm_97857 ; 0x97851 $4
-	ld a, $0
-	jr .asm_9785d ; 0x97855 $6
-.asm_97857
-	ld a, $1
-	jr .asm_9785d ; 0x97859 $2
-.asm_9785b
-	ld a, $2
-.asm_9785d
-	ld [$c2dd], a
+	jr c, .two
+	jr z, .one
+	ld a, 0
+	jr .done
+.one
+	ld a, 1
+	jr .done
+.two
+	ld a, 2
+.done
+	ld [ScriptVar], a
 	ret
 ; 0x97861
 
-Unknown_0x97861: ; 0x97861
+Function97861: ; 0x97861
 	call GetScriptByte
 	and a
 	ld de, $d84e
@@ -2452,7 +2452,7 @@
 	ret
 ; 0x9786d
 
-Unknown_0x9786d: ; 0x9786d
+Function9786d: ; 0x9786d
 	ld bc, $ffc3
 	push bc
 	call GetScriptByte
@@ -2512,13 +2512,13 @@
 ;     time (SingleByteParam)
 
 	xor a
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	callba Functionc000
 	call GetScriptByte
 	and c
 	ret z
 	ld a, $1
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	ret
 ; 0x978c3
 
@@ -2528,14 +2528,14 @@
 ;     pkmn (PokemonParam)
 
 	xor a
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	call GetScriptByte
-	ld hl, $dcd8
-	ld de, $0001
+	ld hl, PartySpecies
+	ld de, 1
 	call IsInArray
 	ret nc
-	ld a, $1
-	ld [$c2dd], a
+	ld a, 1
+	ld [ScriptVar], a
 	ret
 ; 0x978da
 
@@ -2545,13 +2545,13 @@
 ;     person (SingleByteParam)
 
 	xor a
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	call GetScriptByte
 	ld c, a
 	callba Function90000
 	ret nc
 	ld a, $1
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	ret
 ; 0x978ef
 
@@ -2561,13 +2561,13 @@
 ;     person (SingleByteParam)
 
 	xor a
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	call GetScriptByte
 	ld c, a
 	callba Function9000f
 	ret nc
 	ld a, $1
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	ret
 ; 0x97904
 
@@ -2577,13 +2577,13 @@
 ;     person (SingleByteParam)
 
 	xor a
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	call GetScriptByte
 	ld c, a
 	callba Function90019
 	ret nc
 	ld a, $1
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	ret
 ; 0x97919
 
@@ -2604,10 +2604,10 @@
 
 	ld a, [$dc31]
 	and a
-	jr z, .asm_9792e ; 0x9792a $2
-	ld a, $1
-.asm_9792e
-	ld [$c2dd], a
+	jr z, .ok
+	ld a, 1
+.ok
+	ld [ScriptVar], a
 	ret
 ; 0x97932
 
@@ -2622,15 +2622,15 @@
 ;     pkmn_nickname (MultiByteParam)
 
 	call GetScriptByte
-	ld [$d108], a
+	ld [CurPartySpecies], a
 	call GetScriptByte
-	ld [$d143], a
+	ld [CurPartyLevel], a
 	call GetScriptByte
-	ld [$d106], a
+	ld [CurItem], a
 	call GetScriptByte
 	and a
 	ld b, a
-	jr z, .asm_9795d ; 0x97949 $12
+	jr z, .ok
 	ld hl, ScriptPos
 	ld e, [hl]
 	inc hl
@@ -2639,10 +2639,10 @@
 	call GetScriptByte
 	call GetScriptByte
 	call GetScriptByte
-.asm_9795d
+.ok
 	callba Functione277
 	ld a, b
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	ret
 ; 0x97968
 
@@ -2653,16 +2653,16 @@
 ;     level (DecimalParam)
 
 	xor a
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	ld [$cf5f], a
 	call GetScriptByte
-	ld [$d108], a
+	ld [CurPartySpecies], a
 	call GetScriptByte
-	ld [$d143], a
+	ld [CurPartyLevel], a
 	callba Functiondf8c
 	ret nc
 	ld a, $2
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	ret
 ; 0x97988
 
@@ -2710,7 +2710,7 @@
 	jr z, .asm_979b7 ; 0x979b3 $2
 	ld a, $1
 .asm_979b7
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	ret
 ; 0x979bb
 
@@ -2724,7 +2724,7 @@
 	call GetScriptByte
 	ld d, a
 	ld b, $1
-	call Unknown_0x979ee
+	call Function979ee
 	ret
 ; 0x979c9
 
@@ -2738,7 +2738,7 @@
 	call GetScriptByte
 	ld d, a
 	ld b, $0
-	call Unknown_0x979ee
+	call Function979ee
 	ret
 ; 0x979d7
 
@@ -2752,17 +2752,17 @@
 	call GetScriptByte
 	ld d, a
 	ld b, $2
-	call Unknown_0x979ee
+	call Function979ee
 	ld a, c
 	and a
 	jr z, .asm_979ea ; 0x979e6 $2
 	ld a, $1
 .asm_979ea
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	ret
 ; 0x979ee
 
-Unknown_0x979ee: ; 0x979ee
+Function979ee: ; 0x979ee
 	callba EngineFlagAction
 	ret
 ; 0x979f5
@@ -2911,13 +2911,13 @@
 ;     byte (SingleByteParam)
 
 	xor a
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	call GetScriptByte
 	ld b, a
 	callba Function97e5c
 	ret c
 	ld a, $1
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	ret
 ; 0x97ab3
 
@@ -2978,7 +2978,7 @@
 	ret
 ; 0x97b01
 
-Unknown_0x97b01: ; 0x97b01
+Function97b01: ; 0x97b01
 	callba Function966d0
 	ret
 ; 0x97b08
@@ -3227,7 +3227,7 @@
 
 	callba Function4cffe
 	ld a, c
-	ld [$c2dd], a
+	ld [ScriptVar], a
 	ret
 ; 0x97c20
 
--- a/home.asm
+++ b/home.asm
@@ -57,6 +57,7 @@
 
 
 Function2e4e:: ; 2e4e
+; Unreferenced.
 	scf
 	ret
 ; 2e50
@@ -70,11 +71,10 @@
 	bit 1, a
 	ret z
 	ld a, [hJoyDown]
-	bit A_BUTTON, a
+	bit 1, a ; B_BUTTON
 	ret
 ; 2ec6
 
-
 Function2ec6:: ; 2ec6
 	xor a
 	ret
@@ -219,7 +219,7 @@
 	ld [rSVBK], a
 	ld hl, TileMap
 	ld de, $d000
-	ld bc, 360
+	ld bc, TileMapEnd - TileMap
 	call CopyBytes
 	pop af
 	ld [rSVBK], a
@@ -242,7 +242,7 @@
 	ld [rSVBK], a
 	ld hl, $d000
 	ld de, TileMap
-	ld bc, 360
+	ld bc, TileMapEnd - TileMap
 	call CopyBytes
 	pop af
 	ld [rSVBK], a
@@ -289,8 +289,8 @@
 ; 30f4
 
 SkipNames:: ; 0x30f4
-; skips n names where n = a
-	ld bc, $000b ; name length
+; Skip a names.
+	ld bc, NAME_LENGTH
 	and a
 	ret z
 .loop
@@ -301,7 +301,7 @@
 ; 0x30fe
 
 AddNTimes:: ; 0x30fe
-; adds bc n times where n = a
+; Add bc * a to hl.
 	and a
 	ret z
 .loop
@@ -400,7 +400,7 @@
 
 
 CopyDataUntil:: ; 318c
-; Copy [hl .. bc) to [de .. de + bc - hl).
+; Copy [hl .. bc) to de.
 
 ; In other words, the source data is
 ; from hl up to but not including bc,
@@ -550,13 +550,14 @@
 Function3200:: ; 0x3200
 	ld a, [hCGB]
 	and a
-	jr z, .asm_320e
+	jr z, .bg0
+
 	ld a, 2
 	ld [hBGMapMode], a
 	ld c, 4
 	call DelayFrames
 
-.asm_320e
+.bg0
 	ld a, 1
 	ld [hBGMapMode], a
 	ld c, 4
@@ -575,17 +576,17 @@
 Function321c:: ; 321c
 	ld a, [hCGB]
 	and a
-	jr z, .asm_322e
+	jr z, .dmg
 
 	ld a, [$c2ce]
 	cp 0
-	jr z, .asm_322e
+	jr z, .dmg
 
 	ld a, 1
 	ld [hBGMapMode], a
 	jr Function323d
 
-.asm_322e
+.dmg
 	ld a, 1
 	ld [hBGMapMode], a
 	ld c, 4
@@ -616,10 +617,11 @@
 	push af
 	xor a
 	ld [$ffde], a
-.asm_3252
+.wait
 	ld a, [rLY]
 	cp $7f
-	jr c, .asm_3252 ; 3256 $fa
+	jr c, .wait
+
 	di
 	ld a, $1
 	ld [rVBK], a
@@ -629,11 +631,12 @@
 	ld [rVBK], a
 	ld hl, TileMap
 	call Function327b
-.asm_326d
+.wait2
 	ld a, [rLY]
 	cp $7f
-	jr c, .asm_326d ; 3271 $fa
+	jr c, .wait2
 	ei
+
 	pop af
 	ld [$ffde], a
 	pop af
@@ -651,10 +654,10 @@
 	ld [$ffd3], a
 	ld b, $2
 	ld c, $41
-.asm_328c
-	pop de
 
-rept 9
+.loop
+rept 10
+	pop de
 .loop\@
 	ld a, [$ff00+c]
 	and b
@@ -663,27 +666,18 @@
 	inc l
 	ld [hl], d
 	inc l
-	pop de
 endr
 
-.asm_32de
-	ld a, [$ff00+c]
-	and b
-	jr nz, .asm_32de
-	ld [hl], e
-	inc l
-	ld [hl], d
-	inc l
-
 	ld de, $000c
 	add hl, de
 	ld a, [$ffd3]
 	dec a
 	ld [$ffd3], a
-	jr nz, .asm_328c
+	jr nz, .loop
+
 	ld a, [hSPBuffer]
 	ld l, a
-	ld a, [$ffda]
+	ld a, [hSPBuffer + 1]
 	ld h, a
 	ld sp, hl
 	ret
@@ -2077,342 +2071,9 @@
 ; 3945
 
 
-UserPartyAttr:: ; 3945
-	push af
-	ld a, [hBattleTurn]
-	and a
-	jr nz, .asm_394e
-	pop af
-	jr BattlePartyAttr
-.asm_394e
-	pop af
-	jr OTPartyAttr
-; 3951
+INCLUDE "home/battle.asm"
 
 
-OpponentPartyAttr:: ; 3951
-	push af
-	ld a, [hBattleTurn]
-	and a
-	jr z, .asm_395a
-	pop af
-	jr BattlePartyAttr
-.asm_395a
-	pop af
-	jr OTPartyAttr
-; 395d
-
-
-BattlePartyAttr:: ; 395d
-; Get attribute a from the active BattleMon's party struct.
-	push bc
-	ld c, a
-	ld b, 0
-	ld hl, PartyMons
-	add hl, bc
-	ld a, [CurBattleMon]
-	call GetPartyLocation
-	pop bc
-	ret
-; 396d
-
-
-OTPartyAttr:: ; 396d
-; Get attribute a from the active EnemyMon's party struct.
-	push bc
-	ld c, a
-	ld b, 0
-	ld hl, OTPartyMon1Species
-	add hl, bc
-	ld a, [CurOTMon]
-	call GetPartyLocation
-	pop bc
-	ret
-; 397d
-
-
-ResetDamage:: ; 397d
-	xor a
-	ld [CurDamage], a
-	ld [CurDamage + 1], a
-	ret
-; 3985
-
-SetPlayerTurn:: ; 3985
-	xor a
-	ld [hBattleTurn], a
-	ret
-; 3989
-
-SetEnemyTurn:: ; 3989
-	ld a, 1
-	ld [hBattleTurn], a
-	ret
-; 398e
-
-
-UpdateOpponentInParty:: ; 398e
-	ld a, [hBattleTurn]
-	and a
-	jr z, UpdateEnemyMonInParty
-	jr UpdateBattleMonInParty
-; 3995
-
-UpdateUserInParty:: ; 3995
-	ld a, [hBattleTurn]
-	and a
-	jr z, UpdateBattleMonInParty
-	jr UpdateEnemyMonInParty
-; 399c
-
-UpdateBattleMonInParty:: ; 399c
-; Update level, status, current HP
-
-	ld a, [CurBattleMon]
-
-Function399f:: ; 399f
-	ld hl, PartyMon1Level
-	call GetPartyLocation
-
-	ld d, h
-	ld e, l
-	ld hl, BattleMonLevel
-	ld bc, BattleMonMaxHP - BattleMonLevel
-	jp CopyBytes
-; 39b0
-
-UpdateEnemyMonInParty:: ; 39b0
-; Update level, status, current HP
-
-; No wildmons.
-	ld a, [IsInBattle]
-	dec a
-	ret z
-
-	ld a, [CurOTMon]
-	ld hl, OTPartyMon1Level
-	call GetPartyLocation
-
-	ld d, h
-	ld e, l
-	ld hl, EnemyMonLevel
-	ld bc, EnemyMonMaxHP - EnemyMonLevel
-	jp CopyBytes
-; 39c9
-
-
-RefreshBattleHuds:: ; 39c9
-	call UpdateBattleHuds
-	ld c, 3
-	call DelayFrames
-	jp WaitBGMap
-; 39d4
-
-UpdateBattleHuds:: ; 39d4
-	callba Function3df48
-	callba Function3e036
-	ret
-; 39e1
-
-
-GetBattleVar:: ; 39e1
-; Preserves hl.
-	push hl
-	call _GetBattleVar
-	pop hl
-	ret
-; 39e7
-
-_GetBattleVar:: ; 39e7
-; Get variable from pair a, depending on whose turn it is.
-; There are 21 variable pairs.
-
-	push bc
-
-	ld hl, .battlevarpairs
-	ld c, a
-	ld b, 0
-	add hl, bc
-	add hl, bc
-
-	ld a, [hli]
-	ld h, [hl]
-	ld l, a
-
-; Enemy turn uses the second byte instead.
-; This lets battle variable calls be side-neutral.
-	ld a, [hBattleTurn]
-	and a
-	jr z, .getvar
-	inc hl
-	
-.getvar
-; var id
-	ld a, [hl]
-	ld c, a
-	ld b, 0
-
-	ld hl, .vars
-	add hl, bc
-	add hl, bc
-
-	ld a, [hli]
-	ld h, [hl]
-	ld l, a
-	
-	ld a, [hl]
-	
-	pop bc
-	ret
-
-
-.battlevarpairs
-	dw .substatus1, .substatus2, .substatus3, .substatus4, .substatus5
-	dw .substatus1opp, .substatus2opp, .substatus3opp, .substatus4opp, .substatus5opp
-	dw .status, .statusopp, .animation, .effect, .power, .type
-	dw .curmove, .lastcounter, .lastcounteropp, .lastmove, .lastmoveopp
-
-
-	const_def
-	const PLAYER_SUBSTATUS_1
-	const ENEMY_SUBSTATUS_1
-	const PLAYER_SUBSTATUS_2
-	const ENEMY_SUBSTATUS_2
-	const PLAYER_SUBSTATUS_3
-	const ENEMY_SUBSTATUS_3
-	const PLAYER_SUBSTATUS_4
-	const ENEMY_SUBSTATUS_4
-	const PLAYER_SUBSTATUS_5
-	const ENEMY_SUBSTATUS_5
-	const PLAYER_STATUS
-	const ENEMY_STATUS
-	const PLAYER_MOVE_ANIMATION
-	const ENEMY_MOVE_ANIMATION
-	const PLAYER_MOVE_EFFECT
-	const ENEMY_MOVE_EFFECT
-	const PLAYER_MOVE_POWER
-	const ENEMY_MOVE_POWER
-	const PLAYER_MOVE_TYPE
-	const ENEMY_MOVE_TYPE
-	const PLAYER_CUR_MOVE
-	const ENEMY_CUR_MOVE
-	const PLAYER_COUNTER_MOVE
-	const ENEMY_COUNTER_MOVE
-	const PLAYER_LAST_MOVE
-	const ENEMY_LAST_MOVE
-
-
-;                       player                     enemy
-.substatus1     db PLAYER_SUBSTATUS_1,    ENEMY_SUBSTATUS_1
-.substatus1opp  db ENEMY_SUBSTATUS_1,     PLAYER_SUBSTATUS_1
-.substatus2     db PLAYER_SUBSTATUS_2,    ENEMY_SUBSTATUS_2
-.substatus2opp  db ENEMY_SUBSTATUS_2,     PLAYER_SUBSTATUS_2
-.substatus3     db PLAYER_SUBSTATUS_3,    ENEMY_SUBSTATUS_3
-.substatus3opp  db ENEMY_SUBSTATUS_3,     PLAYER_SUBSTATUS_3
-.substatus4     db PLAYER_SUBSTATUS_4,    ENEMY_SUBSTATUS_4
-.substatus4opp  db ENEMY_SUBSTATUS_4,     PLAYER_SUBSTATUS_4
-.substatus5     db PLAYER_SUBSTATUS_5,    ENEMY_SUBSTATUS_5
-.substatus5opp  db ENEMY_SUBSTATUS_5,     PLAYER_SUBSTATUS_5
-.status         db PLAYER_STATUS,         ENEMY_STATUS
-.statusopp      db ENEMY_STATUS,          PLAYER_STATUS
-.animation      db PLAYER_MOVE_ANIMATION, ENEMY_MOVE_ANIMATION
-.effect         db PLAYER_MOVE_EFFECT,    ENEMY_MOVE_EFFECT
-.power          db PLAYER_MOVE_POWER,     ENEMY_MOVE_POWER
-.type           db PLAYER_MOVE_TYPE,      ENEMY_MOVE_TYPE
-.curmove        db PLAYER_CUR_MOVE,       ENEMY_CUR_MOVE
-.lastcounter    db PLAYER_COUNTER_MOVE,   ENEMY_COUNTER_MOVE
-.lastcounteropp db ENEMY_COUNTER_MOVE,    PLAYER_COUNTER_MOVE
-.lastmove       db PLAYER_LAST_MOVE,      ENEMY_LAST_MOVE
-.lastmoveopp    db ENEMY_LAST_MOVE,       PLAYER_LAST_MOVE
-
-.vars
-	dw PlayerSubStatus1,     EnemySubStatus1
-	dw PlayerSubStatus2,     EnemySubStatus2
-	dw PlayerSubStatus3,     EnemySubStatus3
-	dw PlayerSubStatus4,     EnemySubStatus4
-	dw PlayerSubStatus5,     EnemySubStatus5
-	dw BattleMonStatus,      EnemyMonStatus
-	dw PlayerMoveAnimation,  EnemyMoveAnimation
-	dw PlayerMoveEffect,     EnemyMoveEffect
-	dw PlayerMovePower,      EnemyMovePower
-	dw PlayerMoveType,       EnemyMoveType
-	dw CurPlayerMove,        CurEnemyMove
-	dw LastEnemyCounterMove, LastPlayerCounterMove
-	dw LastPlayerMove,       LastEnemyMove
-; 3a90
-
-
-Function3a90:: ; 3a90
-	inc hl
-	ld a, [hROMBank]
-	push af
-	ld a, [hli]
-	ld e, a
-	ld a, [hli]
-	ld d, a
-	ld a, [hli]
-	ld [hROMBank], a
-	ld [MBC3RomBank], a
-	ld a, e
-	ld l, a
-	ld a, d
-	ld h, a
-	ld de, $d00c
-	ld bc, $0028
-	call CopyBytes
-	pop af
-	ld [hROMBank], a
-	ld [MBC3RomBank], a
-	ret
-; 3ab2
-
-
-MobileTextBorder:: ; 3ab2
-; For mobile link battles only.
-	ld a, [InLinkBattle]
-	cp 4
-	ret c
-; Draw a cell phone icon at the top right corner of the border.
-	ld hl, $c5a3 ; TileMap(19,12)
-	ld [hl], $5e ; cell phone top
-	ld hl, $c5b7 ; TileMap(19,13)
-	ld [hl], $5f ; cell phone bottom
-	ret
-; 3ac3
-
-
-BattleTextBox:: ; 3ac3
-; Open a textbox and print text at hl.
-	push hl
-	call SpeechTextBox
-	call MobileTextBorder
-	call Function1ad2
-	call Function321c
-	pop hl
-	call PrintTextBoxText
-	ret
-; 3ad5
-
-
-StdBattleTextBox:: ; 3ad5
-; Open a textbox and print battle text at 20:hl.
-
-GLOBAL BattleText
-
-	ld a, [hROMBank]
-	push af
-
-	ld a, BANK(BattleText)
-	rst Bankswitch
-
-	call BattleTextBox
-
-	pop af
-	rst Bankswitch
-	ret
-; 3ae1
-
-
 Function3ae1:: ; 3ae1
 
 GLOBAL BattleAnimations
@@ -2464,6 +2125,7 @@
 ; 3b0c
 
 Function3b0c:: ; 3b0c
+
 	ld a, [hLCDStatCustom]
 	and a
 	ret z
@@ -2486,14 +2148,17 @@
 
 
 Function3b2a:: ; 3b2a
+
 	ld [$c3b8], a
 	ld a, [hROMBank]
 	push af
+
 	ld a, BANK(Function8cfd6)
 	rst Bankswitch
-
 	ld a, [$c3b8]
+
 	call Function8cfd6
+
 	pop af
 	rst Bankswitch
 
@@ -2502,14 +2167,17 @@
 
 
 Function3b3c:: ; 3b3c
+
 	ld [$c3b8], a
 	ld a, [hROMBank]
 	push af
+
 	ld a, BANK(Function8d120)
 	rst Bankswitch
-
 	ld a, [$c3b8]
+
 	call Function8d120
+
 	pop af
 	rst Bankswitch
 
@@ -2517,591 +2185,11 @@
 ; 3b4e
 
 
-SoundRestart:: ; 3b4e
+INCLUDE "home/audio.asm"
 
-	push hl
-	push de
-	push bc
-	push af
 
-	ld a, [hROMBank]
-	push af
-	ld a, BANK(_SoundRestart)
-	ld [hROMBank], a
-	ld [MBC3RomBank], a
-
-	call _SoundRestart
-
-	pop af
-	ld [hROMBank], a
-	ld [MBC3RomBank], a
-
-	pop af
-	pop bc
-	pop de
-	pop hl
-	ret
-; 3b6a
-
-
-UpdateSound:: ; 3b6a
-
-	push hl
-	push de
-	push bc
-	push af
-
-	ld a, [hROMBank]
-	push af
-	ld a, BANK(_UpdateSound)
-	ld [hROMBank], a
-	ld [MBC3RomBank], a
-
-	call _UpdateSound
-
-	pop af
-	ld [hROMBank], a
-	ld [MBC3RomBank], a
-
-	pop af
-	pop bc
-	pop de
-	pop hl
-	ret
-; 3b86
-
-
-_LoadMusicByte:: ; 3b86
-; CurMusicByte = [a:de]
-GLOBAL LoadMusicByte
-
-	ld [hROMBank], a
-	ld [MBC3RomBank], a
-
-	ld a, [de]
-	ld [CurMusicByte], a
-	ld a, BANK(LoadMusicByte)
-
-	ld [hROMBank], a
-	ld [MBC3RomBank], a
-	ret
-; 3b97
-
-
-PlayMusic:: ; 3b97
-; Play music de.
-
-	push hl
-	push de
-	push bc
-	push af
-
-	ld a, [hROMBank]
-	push af
-	ld a, BANK(_PlayMusic) ; and BANK(_SoundRestart)
-	ld [hROMBank], a
-	ld [MBC3RomBank], a
-
-	ld a, e
-	and a
-	jr z, .nomusic
-
-	call _PlayMusic
-	jr .end
-
-.nomusic
-	call _SoundRestart
-
-.end
-	pop af
-	ld [hROMBank], a
-	ld [MBC3RomBank], a
-	pop af
-	pop bc
-	pop de
-	pop hl
-	ret
-; 3bbc
-
-
-PlayMusic2:: ; 3bbc
-; Stop playing music, then play music de.
-
-	push hl
-	push de
-	push bc
-	push af
-
-	ld a, [hROMBank]
-	push af
-	ld a, BANK(_PlayMusic)
-	ld [hROMBank], a
-	ld [MBC3RomBank], a
-
-	push de
-	ld de, MUSIC_NONE
-	call _PlayMusic
-	call DelayFrame
-	pop de
-	call _PlayMusic
-
-	pop af
-	ld [hROMBank], a
-	ld [MBC3RomBank], a
-
-	pop af
-	pop bc
-	pop de
-	pop hl
-	ret
-
-; 3be3
-
-
-PlayCryHeader:: ; 3be3
-; Play a cry given parameters in header de
-
-	push hl
-	push de
-	push bc
-	push af
-
-; Save current bank
-	ld a, [hROMBank]
-	push af
-
-; Cry headers are stuck in one bank.
-	ld a, BANK(CryHeaders)
-	ld [hROMBank], a
-	ld [MBC3RomBank], a
-
-; Each header is 6 bytes long:
-	ld hl, CryHeaders
-	add hl, de
-	add hl, de
-	add hl, de
-	add hl, de
-	add hl, de
-	add hl, de
-
-	ld e, [hl]
-	inc hl
-	ld d, [hl]
-	inc hl
-
-	ld a, [hli]
-	ld [CryPitch], a
-	ld a, [hli]
-	ld [CryEcho], a
-	ld a, [hli]
-	ld [CryLength], a
-	ld a, [hl]
-	ld [CryLength+1], a
-
-	ld a, BANK(PlayCry)
-	ld [hROMBank], a
-	ld [MBC3RomBank], a
-
-	call PlayCry
-
-	pop af
-	ld [hROMBank], a
-	ld [MBC3RomBank], a
-	
-	pop af
-	pop bc
-	pop de
-	pop hl
-	ret
-; 3c23
-
-
-PlaySFX:: ; 3c23
-; Play sound effect de.
-; Sound effects are ordered by priority (lowest to highest)
-
-	push hl
-	push de
-	push bc
-	push af
-
-; Is something already playing?
-	call CheckSFX
-	jr nc, .play
-; Does it have priority?
-	ld a, [CurSFX]
-	cp e
-	jr c, .quit
-
-.play
-	ld a, [hROMBank]
-	push af
-	ld a, BANK(_PlaySFX)
-	ld [hROMBank], a
-	ld [MBC3RomBank], a ; bankswitch
-
-	ld a, e
-	ld [CurSFX], a
-	call _PlaySFX
-
-	pop af
-	ld [hROMBank], a
-	ld [MBC3RomBank], a ; bankswitch
-.quit
-	pop af
-	pop bc
-	pop de
-	pop hl
-	ret
-; 3c4e
-
-
-WaitPlaySFX:: ; 3c4e
-	call WaitSFX
-	call PlaySFX
-	ret
-; 3c55
-
-
-WaitSFX:: ; 3c55
-; infinite loop until sfx is done playing
-
-	push hl
-	
-.loop
-	; ch5 on?
-	ld hl, Channel5 + Channel1Flags - Channel1
-	bit 0, [hl]
-	jr nz, .loop
-	; ch6 on?
-	ld hl, Channel6 + Channel1Flags - Channel1
-	bit 0, [hl]
-	jr nz, .loop
-	; ch7 on?
-	ld hl, Channel7 + Channel1Flags - Channel1
-	bit 0, [hl]
-	jr nz, .loop
-	; ch8 on?
-	ld hl, Channel8 + Channel1Flags - Channel1
-	bit 0, [hl]
-	jr nz, .loop
-	
-	pop hl
-	ret
-; 3c74
-
-Function3c74:: ; 3c74
-	push hl
-	ld hl, $c1cc
-	bit 0, [hl]
-	jr nz, .asm_3c94
-	ld hl, $c1fe
-	bit 0, [hl]
-	jr nz, .asm_3c94
-	ld hl, $c230
-	bit 0, [hl]
-	jr nz, .asm_3c94
-	ld hl, $c262
-	bit 0, [hl]
-	jr nz, .asm_3c94
-	pop hl
-	scf
-	ret
-
-.asm_3c94
-	pop hl
-	and a
-	ret
-; 3c97
-
-MaxVolume:: ; 3c97
-	ld a, $77 ; max
-	ld [Volume], a
-	ret
-; 3c9d
-
-LowVolume:: ; 3c9d
-	ld a, $33 ; 40%
-	ld [Volume], a
-	ret
-; 3ca3
-
-VolumeOff:: ; 3ca3
-	xor a
-	ld [Volume], a
-	ret
-; 3ca8
-
-Function3ca8:: ; 3ca8
-	ld a, $4
-	ld [MusicFade], a
-	ret
-; 3cae
-
-Function3cae:: ; 3cae
-	ld a, $84
-	ld [MusicFade], a
-	ret
-; 3cb4
-
-Function3cb4:: ; 3cb4
-.asm_3cb4
-	and a
-	ret z
-	dec a
-	call UpdateSound
-	jr .asm_3cb4
-; 3cbc
-
-Function3cbc:: ; 3cbc
-	push hl
-	push de
-	push bc
-	push af
-	call Function3d97
-	ld a, [CurMusic]
-	cp e
-	jr z, .asm_3cda
-	ld a, $8
-	ld [MusicFade], a
-	ld a, e
-	ld [MusicFadeIDLo], a
-	ld a, d
-	ld [MusicFadeIDHi], a
-	ld a, e
-	ld [CurMusic], a
-
-.asm_3cda
-	pop af
-	pop bc
-	pop de
-	pop hl
-	ret
-; 3cdf
-
-Function3cdf:: ; 3cdf
-	push hl
-	push de
-	push bc
-	push af
-	call Function3d97
-	ld a, [CurMusic]
-	cp e
-	jr z, .asm_3cfe
-	push de
-	ld de, MUSIC_NONE
-	call PlayMusic
-	call DelayFrame
-	pop de
-	ld a, e
-	ld [CurMusic], a
-	call PlayMusic
-
-.asm_3cfe
-	pop af
-	pop bc
-	pop de
-	pop hl
-	ret
-; 3d03
-
-Function3d03:: ; 3d03
-	push hl
-	push de
-	push bc
-	push af
-	xor a
-	ld [$c2c1], a
-	ld de, MUSIC_BICYCLE
-	ld a, [PlayerState]
-	cp $1
-	jr z, .asm_3d18
-	call Function3d97
-.asm_3d18
-	push de
-	ld de, MUSIC_NONE
-	call PlayMusic
-	call DelayFrame
-	pop de
-	ld a, e
-	ld [CurMusic], a
-	call PlayMusic
-	pop af
-	pop bc
-	pop de
-	pop hl
-	ret
-; 3d2f
-
-Function3d2f:: ; 3d2f
-	ld a, [$c2c1]
-	and a
-	jr z, Function3d47
-	xor a
-	ld [CurMusic], a
-	ld de, MUSIC_NONE
-	call PlayMusic
-	call DelayFrame
-	xor a
-	ld [$c2c1], a
-	ret
-; 3d47
-
-Function3d47:: ; 3d47
-	push hl
-	push de
-	push bc
-	push af
-	ld de, MUSIC_NONE
-	call PlayMusic
-	call DelayFrame
-	ld a, [CurMusic]
-	ld e, a
-	ld d, 0
-	call PlayMusic
-	pop af
-	pop bc
-	pop de
-	pop hl
-	ret
-; 3d62
-
-Function3d62:: ; 3d62
-	ld a, [PlayerState]
-	cp $4
-	jr z, .asm_3d7b
-	cp $8
-	jr z, .asm_3d7b
-	ld a, [StatusFlags2]
-	bit 2, a
-	jr nz, .asm_3d80
-.asm_3d74
-	and a
-	ret
-
-	ld de, $0013
-	scf
-	ret
-
-.asm_3d7b
-	ld de, $0021
-	scf
-	ret
-
-.asm_3d80
-	ld a, [MapGroup]
-	cp $a
-	jr nz, .asm_3d74
-	ld a, [MapNumber]
-	cp $f
-	jr z, .asm_3d92
-	cp $11
-	jr nz, .asm_3d74
-
-.asm_3d92
-	ld de, $0058
-	scf
-	ret
-; 3d97
-
-Function3d97:: ; 3d97
-	call Function3d62
-	ret c
-	call Function2cbd
-	ret
-; 3d9f
-
-Function3d9f:: ; 3d9f
-	ld a, $20
-	ld [$c498], a
-	ld [$c49c], a
-	ld a, $50
-	ld [$c499], a
-	ld a, $58
-	ld [$c49d], a
-	xor a
-	ld [$c49b], a
-	ld [$c49f], a
-	ld a, [$c296]
-	cp $64
-	jr nc, .asm_3dd5
-	add $1
-	daa
-	ld b, a
-	swap a
-	and $f
-	add $f6
-	ld [$c49a], a
-	ld a, b
-	and $f
-	add $f6
-	ld [$c49e], a
-	ret
-
-.asm_3dd5
-	ld a, $ff
-	ld [$c49a], a
-	ld [$c49e], a
-	ret
-; 3dde
-
-CheckSFX:: ; 3dde
-; returns carry if sfx channels are active
-	ld a, [$c1cc] ; 1
-	bit 0, a
-	jr nz, .quit
-	ld a, [$c1fe] ; 2
-	bit 0, a
-	jr nz, .quit
-	ld a, [$c230] ; 3
-	bit 0, a
-	jr nz, .quit
-	ld a, [$c262] ; 4
-	bit 0, a
-	jr nz, .quit
-	and a
-	ret
-.quit
-	scf
-	ret
-; 3dfe
-
-Function3dfe:: ; 3dfe
-	xor a
-	ld [$c1cc], a
-	ld [SoundInput], a
-	ld [rNR10], a
-	ld [rNR11], a
-	ld [rNR12], a
-	ld [rNR13], a
-	ld [rNR14], a
-	ret
-; 3e10
-
-
-ChannelsOff:: ; 3e10
-; Quickly turn off music channels
-	xor a
-	ld [Channel1Flags], a
-	ld [$c136], a
-	ld [$c168], a
-	ld [$c19a], a
-	ld [SoundInput], a
-	ret
-; 3e21
-
-SFXChannelsOff:: ; 3e21
-; Quickly turn off sound effect channels
-	xor a
-	ld [$c1cc], a
-	ld [$c1fe], a
-	ld [$c230], a
-	ld [$c262], a
-	ld [SoundInput], a
-	ret
-; 3e32
-
 Function3e32:: ; 3e32
+; Mobile
 	cp $2
 	ld [$c988], a
 	ld a, l
@@ -3109,6 +2197,7 @@
 	ld a, h
 	ld [$c987], a
 	jr nz, .asm_3e4f
+
 	ld [$c982], a
 	ld a, l
 	ld [$c981], a
@@ -3130,7 +2219,6 @@
 	jp Function110030
 ; 3e60
 
-
 Function3e60:: ; 3e60
 	ld [$c986], a
 	ld a, l
@@ -3137,6 +2225,7 @@
 	ld [$c987], a
 	ld a, h
 	ld [$c988], a
+
 	pop bc
 	ld a, b
 	ld [$c981], a
@@ -3151,7 +2240,6 @@
 	ld a, [$c986]
 	ret
 ; 3e80
-
 
 Function3e80:: ; 3e80
 	ld a, [hROMBank]
--- /dev/null
+++ b/home/audio.asm
@@ -1,0 +1,598 @@
+; Audio interfaces.
+
+SoundRestart:: ; 3b4e
+
+	push hl
+	push de
+	push bc
+	push af
+
+	ld a, [hROMBank]
+	push af
+	ld a, BANK(_SoundRestart)
+	ld [hROMBank], a
+	ld [MBC3RomBank], a
+
+	call _SoundRestart
+
+	pop af
+	ld [hROMBank], a
+	ld [MBC3RomBank], a
+
+	pop af
+	pop bc
+	pop de
+	pop hl
+	ret
+; 3b6a
+
+
+UpdateSound:: ; 3b6a
+
+	push hl
+	push de
+	push bc
+	push af
+
+	ld a, [hROMBank]
+	push af
+	ld a, BANK(_UpdateSound)
+	ld [hROMBank], a
+	ld [MBC3RomBank], a
+
+	call _UpdateSound
+
+	pop af
+	ld [hROMBank], a
+	ld [MBC3RomBank], a
+
+	pop af
+	pop bc
+	pop de
+	pop hl
+	ret
+; 3b86
+
+
+_LoadMusicByte:: ; 3b86
+; CurMusicByte = [a:de]
+GLOBAL LoadMusicByte
+
+	ld [hROMBank], a
+	ld [MBC3RomBank], a
+
+	ld a, [de]
+	ld [CurMusicByte], a
+	ld a, BANK(LoadMusicByte)
+
+	ld [hROMBank], a
+	ld [MBC3RomBank], a
+	ret
+; 3b97
+
+
+PlayMusic:: ; 3b97
+; Play music de.
+
+	push hl
+	push de
+	push bc
+	push af
+
+	ld a, [hROMBank]
+	push af
+	ld a, BANK(_PlayMusic) ; and BANK(_SoundRestart)
+	ld [hROMBank], a
+	ld [MBC3RomBank], a
+
+	ld a, e
+	and a
+	jr z, .nomusic
+
+	call _PlayMusic
+	jr .end
+
+.nomusic
+	call _SoundRestart
+
+.end
+	pop af
+	ld [hROMBank], a
+	ld [MBC3RomBank], a
+	pop af
+	pop bc
+	pop de
+	pop hl
+	ret
+; 3bbc
+
+
+PlayMusic2:: ; 3bbc
+; Stop playing music, then play music de.
+
+	push hl
+	push de
+	push bc
+	push af
+
+	ld a, [hROMBank]
+	push af
+	ld a, BANK(_PlayMusic)
+	ld [hROMBank], a
+	ld [MBC3RomBank], a
+
+	push de
+	ld de, MUSIC_NONE
+	call _PlayMusic
+	call DelayFrame
+	pop de
+	call _PlayMusic
+
+	pop af
+	ld [hROMBank], a
+	ld [MBC3RomBank], a
+
+	pop af
+	pop bc
+	pop de
+	pop hl
+	ret
+
+; 3be3
+
+
+PlayCryHeader:: ; 3be3
+; Play a cry given parameters at header de
+
+	push hl
+	push de
+	push bc
+	push af
+
+	ld a, [hROMBank]
+	push af
+
+	; Cry headers are stuck in one bank.
+	ld a, BANK(CryHeaders)
+	ld [hROMBank], a
+	ld [MBC3RomBank], a
+
+	ld hl, CryHeaders
+	add hl, de
+	add hl, de
+	add hl, de
+	add hl, de
+	add hl, de
+	add hl, de
+
+	ld e, [hl]
+	inc hl
+	ld d, [hl]
+	inc hl
+
+	ld a, [hli]
+	ld [CryPitch], a
+	ld a, [hli]
+	ld [CryEcho], a
+	ld a, [hli]
+	ld [CryLength], a
+	ld a, [hl]
+	ld [CryLength + 1], a
+
+	ld a, BANK(PlayCry)
+	ld [hROMBank], a
+	ld [MBC3RomBank], a
+
+	call PlayCry
+
+	pop af
+	ld [hROMBank], a
+	ld [MBC3RomBank], a
+	
+	pop af
+	pop bc
+	pop de
+	pop hl
+	ret
+; 3c23
+
+
+PlaySFX:: ; 3c23
+; Play sound effect de.
+; Sound effects are ordered by priority (lowest to highest)
+
+	push hl
+	push de
+	push bc
+	push af
+
+	; Is something already playing?
+	call CheckSFX
+	jr nc, .play
+
+	; Does it have priority?
+	ld a, [CurSFX]
+	cp e
+	jr c, .done
+
+.play
+	ld a, [hROMBank]
+	push af
+	ld a, BANK(_PlaySFX)
+	ld [hROMBank], a
+	ld [MBC3RomBank], a
+
+	ld a, e
+	ld [CurSFX], a
+	call _PlaySFX
+
+	pop af
+	ld [hROMBank], a
+	ld [MBC3RomBank], a
+
+.done
+	pop af
+	pop bc
+	pop de
+	pop hl
+	ret
+; 3c4e
+
+
+WaitPlaySFX:: ; 3c4e
+	call WaitSFX
+	call PlaySFX
+	ret
+; 3c55
+
+
+WaitSFX:: ; 3c55
+; infinite loop until sfx is done playing
+
+	push hl
+	
+.wait
+	ld hl, Channel5Flags
+	bit 0, [hl]
+	jr nz, .wait
+	ld hl, Channel6Flags
+	bit 0, [hl]
+	jr nz, .wait
+	ld hl, Channel7Flags
+	bit 0, [hl]
+	jr nz, .wait
+	ld hl, Channel8Flags
+	bit 0, [hl]
+	jr nz, .wait
+	
+	pop hl
+	ret
+; 3c74
+
+IsSFXPlaying:: ; 3c74
+; Return carry if no sound effect is playing.
+; The inverse of CheckSFX.
+	push hl
+
+	ld hl, Channel5Flags
+	bit 0, [hl]
+	jr nz, .playing
+	ld hl, Channel6Flags
+	bit 0, [hl]
+	jr nz, .playing
+	ld hl, Channel7Flags
+	bit 0, [hl]
+	jr nz, .playing
+	ld hl, Channel8Flags
+	bit 0, [hl]
+	jr nz, .playing
+
+	pop hl
+	scf
+	ret
+
+.playing
+	pop hl
+	and a
+	ret
+; 3c97
+
+MaxVolume:: ; 3c97
+	ld a, $77 ; max
+	ld [Volume], a
+	ret
+; 3c9d
+
+LowVolume:: ; 3c9d
+	ld a, $33 ; 40%
+	ld [Volume], a
+	ret
+; 3ca3
+
+VolumeOff:: ; 3ca3
+	xor a
+	ld [Volume], a
+	ret
+; 3ca8
+
+Function3ca8:: ; 3ca8
+	ld a, 4
+	ld [MusicFade], a
+	ret
+; 3cae
+
+Function3cae:: ; 3cae
+	ld a, 4 | 1 << 7
+	ld [MusicFade], a
+	ret
+; 3cb4
+
+SkipMusic:: ; 3cb4
+; Skip a frames of music.
+	and a
+	ret z
+	dec a
+	call UpdateSound
+	jr SkipMusic
+; 3cbc
+
+FadeToMapMusic:: ; 3cbc
+	push hl
+	push de
+	push bc
+	push af
+
+	call GetMapMusic
+	ld a, [wMapMusic]
+	cp e
+	jr z, .done
+
+	ld a, 8
+	ld [MusicFade], a
+	ld a, e
+	ld [MusicFadeIDLo], a
+	ld a, d
+	ld [MusicFadeIDHi], a
+	ld a, e
+	ld [wMapMusic], a
+
+.done
+	pop af
+	pop bc
+	pop de
+	pop hl
+	ret
+; 3cdf
+
+PlayMapMusic:: ; 3cdf
+	push hl
+	push de
+	push bc
+	push af
+
+	call GetMapMusic
+	ld a, [wMapMusic]
+	cp e
+	jr z, .done
+
+	push de
+	ld de, MUSIC_NONE
+	call PlayMusic
+	call DelayFrame
+	pop de
+	ld a, e
+	ld [wMapMusic], a
+	call PlayMusic
+
+.done
+	pop af
+	pop bc
+	pop de
+	pop hl
+	ret
+; 3d03
+
+EnterMapMusic:: ; 3d03
+	push hl
+	push de
+	push bc
+	push af
+
+	xor a
+	ld [$c2c1], a
+	ld de, MUSIC_BICYCLE
+	ld a, [PlayerState]
+	cp PLAYER_BIKE
+	jr z, .play
+	call GetMapMusic
+.play
+	push de
+	ld de, MUSIC_NONE
+	call PlayMusic
+	call DelayFrame
+	pop de
+
+	ld a, e
+	ld [wMapMusic], a
+	call PlayMusic
+
+	pop af
+	pop bc
+	pop de
+	pop hl
+	ret
+; 3d2f
+
+Function3d2f:: ; 3d2f
+	ld a, [$c2c1]
+	and a
+	jr z, RestartMapMusic
+	xor a
+	ld [wMapMusic], a
+	ld de, MUSIC_NONE
+	call PlayMusic
+	call DelayFrame
+	xor a
+	ld [$c2c1], a
+	ret
+; 3d47
+
+RestartMapMusic:: ; 3d47
+	push hl
+	push de
+	push bc
+	push af
+	ld de, MUSIC_NONE
+	call PlayMusic
+	call DelayFrame
+	ld a, [wMapMusic]
+	ld e, a
+	ld d, 0
+	call PlayMusic
+	pop af
+	pop bc
+	pop de
+	pop hl
+	ret
+; 3d62
+
+SpecialMapMusic:: ; 3d62
+	ld a, [PlayerState]
+	cp PLAYER_SURF
+	jr z, .surf
+	cp PLAYER_SURF_PIKA
+	jr z, .surf
+
+	ld a, [StatusFlags2]
+	bit 2, a
+	jr nz, .contest
+
+.no
+	and a
+	ret
+
+.bike
+	ld de, MUSIC_BICYCLE
+	scf
+	ret
+
+.surf
+	ld de, MUSIC_SURF
+	scf
+	ret
+
+.contest
+	ld a, [MapGroup]
+	cp GROUP_ROUTE_35_NATIONAL_PARK_GATE
+	jr nz, .no
+	ld a, [MapNumber]
+	cp MAP_ROUTE_35_NATIONAL_PARK_GATE
+	jr z, .ranking
+	cp MAP_ROUTE_36_NATIONAL_PARK_GATE
+	jr nz, .no
+
+.ranking
+	ld de, MUSIC_BUG_CATCHING_CONTEST_RANKING
+	scf
+	ret
+; 3d97
+
+GetMapMusic:: ; 3d97
+	call SpecialMapMusic
+	ret c
+	call GetMapHeaderMusic
+	ret
+; 3d9f
+
+Function3d9f:: ; 3d9f
+; Places a BCD number at the
+; upper center of the screen.
+; Unreferenced.
+	ld a, $20
+	ld [$c498], a
+	ld [$c49c], a
+	ld a, $50
+	ld [$c499], a
+	ld a, $58
+	ld [$c49d], a
+	xor a
+	ld [$c49b], a
+	ld [$c49f], a
+	ld a, [$c296]
+	cp $64
+	jr nc, .max
+	add 1
+	daa
+	ld b, a
+	swap a
+	and $f
+	add "0"
+	ld [$c49a], a
+	ld a, b
+	and $f
+	add "0"
+	ld [$c49e], a
+	ret
+
+.max
+	ld a, "9"
+	ld [$c49a], a
+	ld [$c49e], a
+	ret
+; 3dde
+
+CheckSFX:: ; 3dde
+; Return carry if any SFX channels are active.
+	ld a, [Channel5Flags]
+	bit 0, a
+	jr nz, .playing
+	ld a, [Channel6Flags]
+	bit 0, a
+	jr nz, .playing
+	ld a, [Channel7Flags]
+	bit 0, a
+	jr nz, .playing
+	ld a, [Channel8Flags]
+	bit 0, a
+	jr nz, .playing
+	and a
+	ret
+.playing
+	scf
+	ret
+; 3dfe
+
+Function3dfe:: ; 3dfe
+	xor a
+	ld [$c1cc], a
+	ld [SoundInput], a
+	ld [rNR10], a
+	ld [rNR11], a
+	ld [rNR12], a
+	ld [rNR13], a
+	ld [rNR14], a
+	ret
+; 3e10
+
+
+ChannelsOff:: ; 3e10
+; Quickly turn off music channels
+	xor a
+	ld [Channel1Flags], a
+	ld [Channel2Flags], a
+	ld [Channel3Flags], a
+	ld [Channel4Flags], a
+	ld [SoundInput], a
+	ret
+; 3e21
+
+SFXChannelsOff:: ; 3e21
+; Quickly turn off sound effect channels
+	xor a
+	ld [Channel5Flags], a
+	ld [Channel6Flags], a
+	ld [Channel7Flags], a
+	ld [Channel8Flags], a
+	ld [SoundInput], a
+	ret
+; 3e32
--- /dev/null
+++ b/home/battle.asm
@@ -1,0 +1,337 @@
+UserPartyAttr:: ; 3945
+	push af
+	ld a, [hBattleTurn]
+	and a
+	jr nz, .ot
+	pop af
+	jr BattlePartyAttr
+.ot
+	pop af
+	jr OTPartyAttr
+; 3951
+
+
+OpponentPartyAttr:: ; 3951
+	push af
+	ld a, [hBattleTurn]
+	and a
+	jr z, .ot
+	pop af
+	jr BattlePartyAttr
+.ot
+	pop af
+	jr OTPartyAttr
+; 395d
+
+
+BattlePartyAttr:: ; 395d
+; Get attribute a from the active BattleMon's party struct.
+	push bc
+	ld c, a
+	ld b, 0
+	ld hl, PartyMons
+	add hl, bc
+	ld a, [CurBattleMon]
+	call GetPartyLocation
+	pop bc
+	ret
+; 396d
+
+
+OTPartyAttr:: ; 396d
+; Get attribute a from the active EnemyMon's party struct.
+	push bc
+	ld c, a
+	ld b, 0
+	ld hl, OTPartyMon1Species
+	add hl, bc
+	ld a, [CurOTMon]
+	call GetPartyLocation
+	pop bc
+	ret
+; 397d
+
+
+ResetDamage:: ; 397d
+	xor a
+	ld [CurDamage], a
+	ld [CurDamage + 1], a
+	ret
+; 3985
+
+SetPlayerTurn:: ; 3985
+	xor a
+	ld [hBattleTurn], a
+	ret
+; 3989
+
+SetEnemyTurn:: ; 3989
+	ld a, 1
+	ld [hBattleTurn], a
+	ret
+; 398e
+
+
+UpdateOpponentInParty:: ; 398e
+	ld a, [hBattleTurn]
+	and a
+	jr z, UpdateEnemyMonInParty
+	jr UpdateBattleMonInParty
+; 3995
+
+UpdateUserInParty:: ; 3995
+	ld a, [hBattleTurn]
+	and a
+	jr z, UpdateBattleMonInParty
+	jr UpdateEnemyMonInParty
+; 399c
+
+UpdateBattleMonInParty:: ; 399c
+; Update level, status, current HP
+
+	ld a, [CurBattleMon]
+
+Function399f:: ; 399f
+	ld hl, PartyMon1Level
+	call GetPartyLocation
+
+	ld d, h
+	ld e, l
+	ld hl, BattleMonLevel
+	ld bc, BattleMonMaxHP - BattleMonLevel
+	jp CopyBytes
+; 39b0
+
+UpdateEnemyMonInParty:: ; 39b0
+; Update level, status, current HP
+
+; No wildmons.
+	ld a, [IsInBattle]
+	dec a
+	ret z
+
+	ld a, [CurOTMon]
+	ld hl, OTPartyMon1Level
+	call GetPartyLocation
+
+	ld d, h
+	ld e, l
+	ld hl, EnemyMonLevel
+	ld bc, EnemyMonMaxHP - EnemyMonLevel
+	jp CopyBytes
+; 39c9
+
+
+RefreshBattleHuds:: ; 39c9
+	call UpdateBattleHuds
+	ld c, 3
+	call DelayFrames
+	jp WaitBGMap
+; 39d4
+
+UpdateBattleHuds:: ; 39d4
+	callba Function3df48
+	callba Function3e036
+	ret
+; 39e1
+
+
+GetBattleVar:: ; 39e1
+; Preserves hl.
+	push hl
+	call _GetBattleVar
+	pop hl
+	ret
+; 39e7
+
+_GetBattleVar:: ; 39e7
+; Get variable from pair a, depending on whose turn it is.
+; There are 21 variable pairs.
+
+	push bc
+
+	ld hl, .battlevarpairs
+	ld c, a
+	ld b, 0
+	add hl, bc
+	add hl, bc
+
+	ld a, [hli]
+	ld h, [hl]
+	ld l, a
+
+; Enemy turn uses the second byte instead.
+; This lets battle variable calls be side-neutral.
+	ld a, [hBattleTurn]
+	and a
+	jr z, .getvar
+	inc hl
+	
+.getvar
+; var id
+	ld a, [hl]
+	ld c, a
+	ld b, 0
+
+	ld hl, .vars
+	add hl, bc
+	add hl, bc
+
+	ld a, [hli]
+	ld h, [hl]
+	ld l, a
+	
+	ld a, [hl]
+	
+	pop bc
+	ret
+
+.battlevarpairs
+	dw .substatus1, .substatus2, .substatus3, .substatus4, .substatus5
+	dw .substatus1opp, .substatus2opp, .substatus3opp, .substatus4opp, .substatus5opp
+	dw .status, .statusopp, .animation, .effect, .power, .type
+	dw .curmove, .lastcounter, .lastcounteropp, .lastmove, .lastmoveopp
+
+	const_def
+	const PLAYER_SUBSTATUS_1
+	const ENEMY_SUBSTATUS_1
+	const PLAYER_SUBSTATUS_2
+	const ENEMY_SUBSTATUS_2
+	const PLAYER_SUBSTATUS_3
+	const ENEMY_SUBSTATUS_3
+	const PLAYER_SUBSTATUS_4
+	const ENEMY_SUBSTATUS_4
+	const PLAYER_SUBSTATUS_5
+	const ENEMY_SUBSTATUS_5
+	const PLAYER_STATUS
+	const ENEMY_STATUS
+	const PLAYER_MOVE_ANIMATION
+	const ENEMY_MOVE_ANIMATION
+	const PLAYER_MOVE_EFFECT
+	const ENEMY_MOVE_EFFECT
+	const PLAYER_MOVE_POWER
+	const ENEMY_MOVE_POWER
+	const PLAYER_MOVE_TYPE
+	const ENEMY_MOVE_TYPE
+	const PLAYER_CUR_MOVE
+	const ENEMY_CUR_MOVE
+	const PLAYER_COUNTER_MOVE
+	const ENEMY_COUNTER_MOVE
+	const PLAYER_LAST_MOVE
+	const ENEMY_LAST_MOVE
+
+;                       player                     enemy
+.substatus1     db PLAYER_SUBSTATUS_1,    ENEMY_SUBSTATUS_1
+.substatus1opp  db ENEMY_SUBSTATUS_1,     PLAYER_SUBSTATUS_1
+.substatus2     db PLAYER_SUBSTATUS_2,    ENEMY_SUBSTATUS_2
+.substatus2opp  db ENEMY_SUBSTATUS_2,     PLAYER_SUBSTATUS_2
+.substatus3     db PLAYER_SUBSTATUS_3,    ENEMY_SUBSTATUS_3
+.substatus3opp  db ENEMY_SUBSTATUS_3,     PLAYER_SUBSTATUS_3
+.substatus4     db PLAYER_SUBSTATUS_4,    ENEMY_SUBSTATUS_4
+.substatus4opp  db ENEMY_SUBSTATUS_4,     PLAYER_SUBSTATUS_4
+.substatus5     db PLAYER_SUBSTATUS_5,    ENEMY_SUBSTATUS_5
+.substatus5opp  db ENEMY_SUBSTATUS_5,     PLAYER_SUBSTATUS_5
+.status         db PLAYER_STATUS,         ENEMY_STATUS
+.statusopp      db ENEMY_STATUS,          PLAYER_STATUS
+.animation      db PLAYER_MOVE_ANIMATION, ENEMY_MOVE_ANIMATION
+.effect         db PLAYER_MOVE_EFFECT,    ENEMY_MOVE_EFFECT
+.power          db PLAYER_MOVE_POWER,     ENEMY_MOVE_POWER
+.type           db PLAYER_MOVE_TYPE,      ENEMY_MOVE_TYPE
+.curmove        db PLAYER_CUR_MOVE,       ENEMY_CUR_MOVE
+.lastcounter    db PLAYER_COUNTER_MOVE,   ENEMY_COUNTER_MOVE
+.lastcounteropp db ENEMY_COUNTER_MOVE,    PLAYER_COUNTER_MOVE
+.lastmove       db PLAYER_LAST_MOVE,      ENEMY_LAST_MOVE
+.lastmoveopp    db ENEMY_LAST_MOVE,       PLAYER_LAST_MOVE
+
+.vars
+	dw PlayerSubStatus1,     EnemySubStatus1
+	dw PlayerSubStatus2,     EnemySubStatus2
+	dw PlayerSubStatus3,     EnemySubStatus3
+	dw PlayerSubStatus4,     EnemySubStatus4
+	dw PlayerSubStatus5,     EnemySubStatus5
+	dw BattleMonStatus,      EnemyMonStatus
+	dw PlayerMoveAnimation,  EnemyMoveAnimation
+	dw PlayerMoveEffect,     EnemyMoveEffect
+	dw PlayerMovePower,      EnemyMovePower
+	dw PlayerMoveType,       EnemyMoveType
+	dw CurPlayerMove,        CurEnemyMove
+	dw LastEnemyCounterMove, LastPlayerCounterMove
+	dw LastPlayerMove,       LastEnemyMove
+; 3a90
+
+
+Function3a90:: ; 3a90
+	inc hl
+	ld a, [hROMBank]
+	push af
+	ld a, [hli]
+	ld e, a
+	ld a, [hli]
+	ld d, a
+	ld a, [hli]
+	ld [hROMBank], a
+	ld [MBC3RomBank], a
+	ld a, e
+	ld l, a
+	ld a, d
+	ld h, a
+	ld de, $d00c
+	ld bc, $0028
+	call CopyBytes
+	pop af
+	ld [hROMBank], a
+	ld [MBC3RomBank], a
+	ret
+; 3ab2
+
+
+MobileTextBorder:: ; 3ab2
+
+CELL_PHONE_TOP    EQU $5e
+CELL_PHONE_BOTTOM EQU $5f
+
+	; For mobile link battles only.
+	ld a, [InLinkBattle]
+	cp 4
+	ret c
+
+	; Draw a cell phone icon at the
+	; top right corner of the border.
+	hlcoord 19, 12
+	ld [hl], CELL_PHONE_TOP
+	hlcoord 19, 13
+	ld [hl], CELL_PHONE_BOTTOM
+	ret
+; 3ac3
+
+
+BattleTextBox:: ; 3ac3
+; Open a textbox and print text at hl.
+	push hl
+	call SpeechTextBox
+	call MobileTextBorder
+	call Function1ad2
+	call Function321c
+	pop hl
+	call PrintTextBoxText
+	ret
+; 3ad5
+
+
+StdBattleTextBox:: ; 3ad5
+; Open a textbox and print battle text at 20:hl.
+
+GLOBAL BattleText
+
+	ld a, [hROMBank]
+	push af
+
+	ld a, BANK(BattleText)
+	rst Bankswitch
+
+	call BattleTextBox
+
+	pop af
+	rst Bankswitch
+	ret
+; 3ae1
--- a/home/init.asm
+++ b/home/init.asm
@@ -172,7 +172,7 @@
 
 	call SoundRestart
 	xor a
-	ld [CurMusic], a
+	ld [wMapMusic], a
 	jp GameInit
 ; 245
 
--- a/home/map.asm
+++ b/home/map.asm
@@ -1034,7 +1034,7 @@
 ; 2674
 
 Function2674:: ; 2674
-	callba Unknown_0x974f3
+	callba Function974f3
 	ld a, [ScriptMode]
 	push af
 	ld hl, ScriptFlags
@@ -2021,8 +2021,8 @@
 	callba Function8c001
 	call Function2173
 	call Function2821
-	ld a, $9
-	call Function3cb4
+	ld a, 9
+	call SkipMusic
 	pop af
 	rst Bankswitch
 
@@ -2259,48 +2259,51 @@
 	ret
 ; 0x2cbd
 
-Function2cbd:: ; 2cbd
+GetMapHeaderMusic:: ; 2cbd
+RADIO_TOWER_MUSIC EQU 7
+
 	push hl
 	push bc
-	ld de, $0006
+	ld de, 6 ; music
 	call GetMapHeaderMember
 	ld a, c
-	cp $64
-	jr z, .asm_2cee
-	bit 7, c
-	jr nz, .asm_2cda
+	cp MUSIC_MAHOGANY_MART
+	jr z, .mahoganymart
+	bit RADIO_TOWER_MUSIC, c
+	jr nz, .radiotower
 	callba Function8b342
 	ld e, c
-	ld d, $0
-.asm_2cd7
+	ld d, 0
+.done
 	pop bc
 	pop hl
 	ret
 
-.asm_2cda
+.radiotower
 	ld a, [StatusFlags2]
 	bit 0, a
-	jr z, .asm_2ce6
-	ld de, $0056
-	jr .asm_2cd7
+	jr z, .clearedradiotower
+	ld de, MUSIC_ROCKET_OVERTURE
+	jr .done
 
-.asm_2ce6
+.clearedradiotower
+	; the rest of the byte
 	ld a, c
-	and $7f
+	and 1 << RADIO_TOWER_MUSIC - 1
 	ld e, a
-	ld d, $0
-	jr .asm_2cd7
+	ld d, 0
+	jr .done
 
-.asm_2cee
+.mahoganymart
 	ld a, [StatusFlags2]
 	bit 7, a
-	jr z, .asm_2cfa
-	ld de, $0048
-	jr .asm_2cd7
+	jr z, .clearedmahogany
+	ld de, MUSIC_ROCKET_HIDEOUT
+	jr .done
 
-.asm_2cfa
-	ld de, $0026
-	jr .asm_2cd7
+.clearedmahogany
+	ld de, MUSIC_CHERRYGROVE_CITY
+	jr .done
 ; 2cff
 
 Function2cff:: ; 2cff
--- a/main.asm
+++ b/main.asm
@@ -3747,7 +3747,7 @@
 	call DelayFrame
 	ld de, MUSIC_MAIN_MENU
 	ld a, e
-	ld [CurMusic], a
+	ld [wMapMusic], a
 	call PlayMusic
 	callba MainMenu
 	jp Function6219
@@ -7940,8 +7940,8 @@
 	dbw BANK(Functionc230), Functionc230
 	dbw BANK(SpecialSeenMon), SpecialSeenMon
 	dbw BANK(WaitSFX),WaitSFX
-	dbw BANK(Function3cdf), Function3cdf
-	dbw BANK(Function3d47), Function3d47
+	dbw BANK(PlayMapMusic), PlayMapMusic
+	dbw BANK(RestartMapMusic), RestartMapMusic
 	dbw BANK(Function12324), Function12324
 	dbw BANK(Function8379), Function8379
 	dbw BANK(Functionc25a), Functionc25a
@@ -8402,7 +8402,7 @@
 ; ScriptVar is 1 if the conditions are met, otherwise 0.
 
 ; check background music
-	ld a, [CurMusic]
+	ld a, [wMapMusic]
 	cp MUSIC_POKE_FLUTE_CHANNEL
 	jr nz, .nope
 
@@ -10774,7 +10774,7 @@
 	call MaxVolume
 	ld de, MUSIC_BICYCLE
 	ld a, e
-	ld [CurMusic], a
+	ld [wMapMusic], a
 	call PlayMusic
 	ld a, $1
 	ret
@@ -21177,13 +21177,13 @@
 	ld a, e
 	ld [$d03f], a
 	ld a, d
-	ld [MartPointer], a
+	ld [$d040], a
 	call Function1345a
 	ret
 ; 1345a
 
 Function1345a: ; 1345a
-	ld de, CurMart
+	ld de, $d0f0
 	ld bc, $0004
 	ld hl, $d03f
 	ld a, [hli]
@@ -23072,6 +23072,8 @@
 
 
 LoadSpriteGFX: ; 14306
+; Bug: b is not preserved, so
+; it's useless as a loop count.
 
 	ld hl, UsedSprites
 	ld b, $20
@@ -25882,11 +25884,11 @@
 	dbw BANK(EnableLCD), EnableLCD
 	dbw BANK(DisableLCD), DisableLCD
 	dbw BANK(SoundRestart), SoundRestart
-	dbw BANK(Function3cdf), Function3cdf
-	dbw BANK(Function3d47), Function3d47
-	dbw BANK(Function3cbc), Function3cbc
+	dbw BANK(PlayMapMusic), PlayMapMusic
+	dbw BANK(RestartMapMusic), RestartMapMusic
+	dbw BANK(FadeToMapMusic), FadeToMapMusic
 	dbw BANK(Function15574), Function15574
-	dbw BANK(Function3d03), Function3d03
+	dbw BANK(EnterMapMusic), EnterMapMusic
 	dbw BANK(Function15587), Function15587
 	dbw BANK(Function3cae), Function3cae
 	dbw BANK(Function24cd), Function24cd
@@ -26045,8 +26047,8 @@
 ; 15567
 
 Function15567: ; 15567
-	ld a, $6
-	call Function3cb4
+	ld a, 6
+	call SkipMusic
 	ret
 ; 1556d
 
@@ -27077,7 +27079,7 @@
 	ld l, a
 	push hl
 	inc hl
-	ld bc, DefaultFlypoint
+	ld bc, $d002
 	ld de, CurMart + 1
 .asm_15c33
 	ld a, [hli]
@@ -27316,7 +27318,7 @@
 	ld a, [$d107]
 	ld e, a
 	ld d, $0
-	ld hl, MartPointer
+	ld hl, $d040
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -27357,7 +27359,7 @@
 	ld a, [$d107]
 	ld e, a
 	ld d, 0
-	ld hl, MartPointer
+	ld hl, $d040
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -29488,12 +29490,12 @@
 
 	ld de, UnownDexATile
 	ld hl, $8ef0
-	ld bc, $0501
+	lb bc, BANK(UnownDexBTile), 1
 	call Request1bpp
 
 	ld de, UnownDexBTile
 	ld hl, $8f50
-	ld bc, $0501
+	lb bc, BANK(UnownDexBTile), 1
 	call Request1bpp
 
 	ld hl, TileMap
@@ -29554,7 +29556,7 @@
 	ld a, [$cf63]
 	push af
 	callba Function84560
-	call Function3d47
+	call RestartMapMusic
 	pop af
 	ld [$cf63], a
 	jr .asm_16c6b
@@ -29969,7 +29971,7 @@
 	call Function1d6e
 	call Function16f70
 	call Function2b4d
-	call Function3d47
+	call RestartMapMusic
 	jp Function2dcf
 ; 16f70
 
@@ -40609,7 +40611,7 @@
 Function2a124:: ; 2a124
 ; Pokemon March and Ruins of Alph signal double encounter rate.
 ; Pokemon Lullaby halves encounter rate.
-	ld a, [CurMusic]
+	ld a, [wMapMusic]
 	cp MUSIC_POKEMON_MARCH
 	jr z, .asm_2a135
 	cp MUSIC_RUINS_OF_ALPH_RADIO
@@ -47388,8 +47390,8 @@
 	ld hl, PokedexSlowpokeLZ
 	ld de, VTiles0
 	call Decompress
-	ld a, $6
-	call Function3cb4
+	ld a, 6
+	call SkipMusic
 	call EnableLCD
 	ret
 
@@ -47893,7 +47895,7 @@
 	ret nz
 	ld a, [$d268]
 	and a
-	call nz, Function3d47
+	call nz, RestartMapMusic
 	ret
 ; 42414
 
@@ -49099,7 +49101,7 @@
 
 Function44806: ; 0x44806
 	xor a
-	ld [CurMart], a
+	ld [$d0f0], a
 	ld a, $1
 	ld [$d0f1], a
 .asm_4480f
@@ -49112,11 +49114,11 @@
 	call Function1ad2
 	ld a, [$d0f1]
 	ld [$cf88], a
-	ld a, [CurMart]
+	ld a, [$d0f0]
 	ld [$d0e4], a
 	call Function350c
 	ld a, [$d0e4]
-	ld [CurMart], a
+	ld [$d0f0], a
 	ld a, [$cfa9]
 	ld [$d0f1], a
 	ld a, [$cf73]
@@ -52964,7 +52966,7 @@
 MainMenu_Mobile: ; 49efc
 	call WhiteBGMap
 	ld a, MUSIC_MOBILE_ADAPTER_MENU
-	ld [CurMusic], a
+	ld [wMapMusic], a
 	ld de, MUSIC_MOBILE_ADAPTER_MENU
 	call Function4a6c5
 Function49f0a: ; 49f0a
@@ -53031,7 +53033,7 @@
 	call WhiteBGMap
 	call ClearTileMap
 	ld a, MUSIC_MAIN_MENU
-	ld [CurMusic], a
+	ld [wMapMusic], a
 	ld de, MUSIC_MAIN_MENU
 	call Function4a6c5
 	ret
@@ -57194,7 +57196,7 @@
 
 ; no known jump sources
 Function4dde6: ; 4dde6 (13:5de6)
-	call Function3c74
+	call IsSFXPlaying
 	ret nc
 	ld a, [$cf63]
 	inc a
@@ -61140,7 +61142,7 @@
 .asm_50dd8
 	cp $5
 	jr nz, .asm_50de6
-	ld hl, CurMart
+	ld hl, $d0f0
 	ld de, PokemonNames
 	ld a, $1
 	jr .asm_50dfc
@@ -61154,7 +61156,7 @@
 	jr .asm_50dfc
 
 .asm_50df4
-	ld hl, CurMart
+	ld hl, $d0f0
 	ld de, Function50000
 	ld a, $4
 
@@ -62432,7 +62434,7 @@
 	call CheckLandPermissions
 	jr c, .asm_801be
 
-	call Function80341
+	call IsNPCInFront
 	and a
 	jr z, .asm_801be
 	cp 2
@@ -62490,10 +62492,10 @@
 TrySurfStep: ; 801c0
 
 	call CheckWaterPermissions
-	ld [MartPointer], a
+	ld [$d040], a
 	jr c, .asm_801f1
 
-	call Function80341
+	call IsNPCInFront
 	ld [$d03f], a
 	and a
 	jr z, .asm_801f1
@@ -62500,7 +62502,7 @@
 	cp 2
 	jr z, .asm_801f1
 
-	ld a, [MartPointer]
+	ld a, [$d040]
 	and a
 	jr nz, .ExitWater
 
@@ -62511,7 +62513,7 @@
 
 .ExitWater
 	call WaterToLandSprite
-	call Function3cdf ; PlayMapMusic
+	call PlayMapMusic
 	ld a, STEP_WALK
 	call DoStep
 	ld a, 6
@@ -62773,7 +62775,7 @@
 ; 80341
 
 
-Function80341: ; 80341
+IsNPCInFront: ; 80341
 
 	ld a, 0
 	ld [hConnectionStripLength], a
@@ -65883,7 +65885,7 @@
 ; 84753
 
 Function84753: ; 84753
-	call Function3d47
+	call RestartMapMusic
 	ret
 ; 84757
 
@@ -69841,7 +69843,7 @@
 	call Function89240
 	ld c, $18
 	call DelayFrames
-	call Function3d47
+	call RestartMapMusic
 	ret
 ; 89d4e (22:5d4e)
 
@@ -81610,8 +81612,8 @@
 	call Function90c4e
 	callba Function8cf53
 	call Function90d32
-	ld a, $8
-	call Function3cb4
+	ld a, 8
+	call SkipMusic
 	ld a, $e3
 	ld [rLCDC], a
 	call Function90d70
@@ -82923,13 +82925,13 @@
 	cp $fe
 	jr z, .asm_914a3
 	cp $ff
-	call z, Function3d03
+	call z, EnterMapMusic
 	xor a
 	ld [$c6dc], a
 	ret
 
 .asm_914a3
-	call Function3d47
+	call RestartMapMusic
 	xor a
 	ld [$c6dc], a
 	ret
@@ -83359,7 +83361,7 @@
 	call PlayMusic
 	pop de
 	ld a, e
-	ld [CurMusic], a ; $c2c0
+	ld [wMapMusic], a
 	call PlayMusic
 	ret
 
@@ -83446,8 +83448,8 @@
 	call DisableLCD
 	call Function90c4e
 	callba Function8cf53
-	ld a, $8
-	call Function3cb4
+	ld a, 8
+	call SkipMusic
 	ld a, $e3
 	ld [rLCDC], a
 	call Function90d56
@@ -96955,8 +96957,8 @@
 	ld hl, PCSelectLZ
 	ld de, $8000
 	call Decompress
-	ld a, $6
-	call Function3cb4
+	ld a, 6
+	call SkipMusic
 	call EnableLCD
 	ret
 ; e3419 (38:7419)
@@ -97617,7 +97619,7 @@
 
 .SetMono
 	res 5, [hl]
-	call Function3d47 ;reload the music
+	call RestartMapMusic
 
 .ToggleMono
 	ld de, .Mono
@@ -97625,7 +97627,7 @@
 
 .SetStereo
 	set 5, [hl]
-	call Function3d47 ;reload the music
+	call RestartMapMusic
 
 .ToggleStereo
 	ld de, .Stereo
@@ -99934,7 +99936,7 @@
 	push af
 	ld a, $5
 	ld [rSVBK], a ; $ff00+$70
-	ld hl, CurMartEnd ; $d100 (aliases: LYOverrides)
+	ld hl, LYOverrides
 	ld bc, $90
 	xor a
 	call ByteFill
@@ -99953,7 +99955,7 @@
 	ld a, [$cf64]
 	and $1
 	jr z, .asm_e5548
-	ld hl, CurMartEnd ; $d100 (aliases: LYOverrides)
+	ld hl, LYOverrides
 	ld a, [hl]
 	inc a
 	ld bc, $5f
@@ -99965,7 +99967,7 @@
 	inc a
 	ld bc, $31
 	call ByteFill
-	ld a, [CurMartEnd] ; $d100 (aliases: LYOverrides)
+	ld a, [LYOverrides + 0]
 	ld [hSCX], a ; $ff00+$cf
 	pop af
 	ld [rSVBK], a ; $ff00+$70
@@ -101561,7 +101563,7 @@
 	ld hl, TradedForText
 	call PrintText
 
-	call Function3d47
+	call RestartMapMusic
 
 	ld a, TRADE_COMPLETE
 
@@ -112685,7 +112687,7 @@
 
 .asm_11b872
 	call Function2b3c
-	call Function3d47
+	call RestartMapMusic
 	ret
 ; 11b879
 
@@ -114152,7 +114154,7 @@
 	jr nz, .asm_11c7d0
 	ret
 .asm_11c7e9
-	ld hl, CurMartEnd ; $d100 (aliases: LYOverrides)
+	ld hl, $d100
 	ld a, [$cd26]
 	ld e, a
 	add hl, de
@@ -114186,8 +114188,8 @@
 	pop de
 	ret
 .asm_11c814
-	ld hl, BattleMonSpclDef ; $c648
-	ld a, [CreditsTimer] ; $cd22
+	ld hl, $c648
+	ld a, [$cd22]
 	ld e, a
 	ld d, $0
 	add hl, de
@@ -114336,13 +114338,13 @@
 	add [hl]
 	ld c, a
 	ld b, $0
-	ld hl, CurMartEnd ; $d100 (aliases: LYOverrides)
+	ld hl, $d100
 	add hl, bc
 	ld a, [hl]
 	jr .asm_11c911
 .asm_11c938
-	ld hl, BattleMonSpclDef ; $c648
-	ld a, [CreditsTimer] ; $cd22
+	ld hl, $c648
+	ld a, [$cd22]
 	ld e, a
 	ld d, $0
 	add hl, de
@@ -117747,7 +117749,7 @@
 	ld [rSVBK], a
 	ld de, MUSIC_MOBILE_CENTER
 	ld a, e
-	ld [CurMusic], a
+	ld [wMapMusic], a
 	ld [MusicFadeIDLo], a
 	ld a, d
 	ld [MusicFadeIDHi], a
@@ -119158,7 +119160,7 @@
 	ret z
 	ld a, $8
 	ld [MusicFade], a
-	ld a, [CurMusic]
+	ld a, [wMapMusic]
 	ld [MusicFadeIDLo], a
 	xor a
 	ld [MusicFadeIDHi], a
--- a/misc/crystal_misc.asm
+++ b/misc/crystal_misc.asm
@@ -257,7 +257,7 @@
 
 ; no known jump sources
 Function17a81a: ; 17a81a (5e:681a)
-	call Function3c74
+	call IsSFXPlaying
 	ret nc
 	ld a, [hJoyPressed] ; $ff00+$a7
 	and $3
--- a/wram.asm
+++ b/wram.asm
@@ -365,8 +365,7 @@
 CurSFX:: ; c2bf
 ; id of sfx currently playing
 	ds 1
-CurMusic:: ; c2c0
-; id of music currently playing
+wMapMusic:: ; c2c0
 	ds 1
 
 SECTION "auto",WRAM0[$c2c7]