shithub: pokecrystal

Download patch

ref: e44640b0088dad5856d7a6f60ad930779931b251
parent: 01bd8ac94cc11c086167a2a2d8e7b335f033deca
author: Remy Oukaour <remy.oukaour@gmail.com>
date: Fri Dec 15 16:22:26 EST 2017

Move more main.asm code into individual files

--- a/constants/battle_tower_constants.asm
+++ b/constants/battle_tower_constants.asm
@@ -20,8 +20,8 @@
 	const BATTLETOWERACTION_11 ; store 0 in 5:aa8d
 	const BATTLETOWERACTION_12 ; store 1 in 5:aa8d
 	const BATTLETOWERACTION_13 ; check 5:aa8d
-	const BATTLETOWERACTION_14 ; if save file is yours: bit 0, [s1_be4f]
-	const BATTLETOWERACTION_15 ; set 0, [s1_be4f]
+	const BATTLETOWERACTION_14 ; if save file is yours: bit 0, [sBattleTowerSaveFileFlags]
+	const BATTLETOWERACTION_15 ; set 0, [sBattleTowerSaveFileFlags]
 	const BATTLETOWERACTION_16 ; update time in SRAM bank 5
 	const BATTLETOWERACTION_17 ; check time in SRAM bank 5
 	const BATTLETOWERACTION_LEVEL_CHECK
--- a/constants/misc_constants.asm
+++ b/constants/misc_constants.asm
@@ -65,6 +65,11 @@
 HMENURETURN_ASM    EQU %11111111
 
 
+; save file corruption check values
+SAVE_CHECK_VALUE_1 EQU 99
+SAVE_CHECK_VALUE_2 EQU 127
+
+
 ; time of day boundaries
 MORN_HOUR EQU 4  ; 4 AM
 DAY_HOUR  EQU 10 ; 10 AM
--- /dev/null
+++ b/engine/empty_sram.asm
@@ -1,0 +1,19 @@
+EmptyAllSRAMBanks: ; 4cf1f
+	ld a, $0
+	call .EmptyBank
+	ld a, $1
+	call .EmptyBank
+	ld a, $2
+	call .EmptyBank
+	ld a, $3
+	call .EmptyBank
+	ret
+
+.EmptyBank: ; 4cf34
+	call GetSRAMBank
+	ld hl, SRAM_Begin
+	ld bc, SRAM_End - SRAM_Begin
+	xor a
+	call ByteFill
+	call CloseSRAM
+	ret
--- a/engine/healmachineanim.asm
+++ /dev/null
@@ -1,265 +1,0 @@
-HealMachineAnim: ; 12324
-	; If you have no Pokemon, don't change the buffer.  This can lead to some glitchy effects if you have no Pokemon.
-	ld a, [PartyCount]
-	and a
-	ret z
-	; The location of the healing machine relative to the player is stored in ScriptVar.
-	; 0: Up and left (Pokemon Center)
-	; 1: Left (Elm's Lab)
-	; 2: Up (Hall of Fame)
-	ld a, [ScriptVar]
-	ld [Buffer1], a
-	ld a, [rOBP1]
-	ld [Buffer2], a
-	call .DoJumptableFunctions
-	ld a, [Buffer2]
-	call DmgToCgbObjPal1
-	ret
-; 1233e
-
-.DoJumptableFunctions: ; 1233e
-	xor a
-	ld [Buffer3], a
-.jumpable_loop
-	ld a, [Buffer1]
-	ld e, a
-	ld d, 0
-	ld hl, .Pointers
-	add hl, de
-	add hl, de
-	ld a, [hli]
-	ld h, [hl]
-	ld l, a
-	ld a, [Buffer3]
-	ld e, a
-	inc a
-	ld [Buffer3], a
-	add hl, de
-	ld a, [hl]
-	cp 5
-	jr z, .finish
-	ld hl, .Jumptable
-	rst JumpTable
-	jr .jumpable_loop
-
-.finish
-	ret
-; 12365
-
-.Pointers: ; 12365
-	dw .Pokecenter
-	dw .ElmLab
-	dw .HallOfFame
-; 1236b
-
-.Pokecenter: ; 1236b
-	db 0, 1, 3, 5
-.ElmLab: ; 1236f
-	db 0, 1, 3, 5
-.HallOfFame: ; 12373
-	db 0, 2, 4, 5
-; 12377
-
-.Jumptable: ; 12377
-	dw .LoadGFX
-	dw .PC_LoadBallsOntoMachine
-	dw .HOF_LoadBallsOntoMachine
-	dw .PlayHealMusic
-	dw .HOF_PlaySFX
-	dw .dummy_5 ; never encountered
-; 12383
-
-.LoadGFX: ; 12383
-	call .LoadPalettes
-	ld de, .HealMachineGFX
-	ld hl, VTiles0 tile $7c
-	lb bc, BANK(.HealMachineGFX), $2
-	call Request2bpp
-	ret
-; 12393
-
-.PC_LoadBallsOntoMachine: ; 12393
-	ld hl, Sprites + $80
-	ld de, .PC_ElmsLab_OAM
-	call .PlaceHealingMachineTile
-	call .PlaceHealingMachineTile
-	jr .LoadBallsOntoMachine
-
-.HOF_LoadBallsOntoMachine: ; 123a1
-	ld hl, Sprites + $80
-	ld de, .HOF_OAM
-
-.LoadBallsOntoMachine: ; 123a7
-	ld a, [PartyCount]
-	ld b, a
-.party_loop
-	call .PlaceHealingMachineTile
-	push de
-	ld de, SFX_SECOND_PART_OF_ITEMFINDER
-	call PlaySFX
-	pop de
-	ld c, 30
-	call DelayFrames
-	dec b
-	jr nz, .party_loop
-	ret
-; 123bf
-
-.PlayHealMusic: ; 123bf
-	ld de, MUSIC_HEAL
-	call PlayMusic
-	jp .FlashPalettes8Times
-; 123c8
-
-.HOF_PlaySFX: ; 123c8
-	ld de, SFX_GAME_FREAK_LOGO_GS
-	call PlaySFX
-	call .FlashPalettes8Times
-	call WaitSFX
-	ld de, SFX_BOOT_PC
-	call PlaySFX
-	ret
-; 123db
-
-.dummy_5 ; 123db
-	ret
-; 123dc
-
-.PC_ElmsLab_OAM: ; 123dc
-	dsprite   4, 0,   4, 2, $7c, $16
-	dsprite   4, 0,   4, 6, $7c, $16
-	dsprite   4, 6,   4, 0, $7d, $16
-	dsprite   4, 6,   5, 0, $7d, $36 ; xflip
-	dsprite   5, 3,   4, 0, $7d, $16
-	dsprite   5, 3,   5, 0, $7d, $36 ; xflip
-	dsprite   6, 0,   4, 0, $7d, $16
-	dsprite   6, 0,   5, 0, $7d, $36 ; xflip
-; 123fc
-
-.HealMachineGFX: ; 123fc
-INCBIN "gfx/overworld/heal_machine.2bpp"
-; 1241c
-
-.HOF_OAM: ; 1241c
-	dsprite   7, 4,  10, 1, $7d, $16
-	dsprite   7, 4,  10, 6, $7d, $16
-	dsprite   7, 3,   9, 5, $7d, $16
-	dsprite   7, 3,  11, 2, $7d, $16
-	dsprite   7, 1,   9, 1, $7d, $16
-	dsprite   7, 1,  11, 5, $7d, $16
-; 12434
-
-.LoadPalettes: ; 12434
-	call IsCGB
-	jr nz, .cgb
-	ld a, %11100000
-	ld [rOBP1], a
-	ret
-
-.cgb
-	ld hl, .palettes
-	ld de, OBPals + 8 * 6
-	ld bc, 8
-	ld a, $5
-	call FarCopyWRAM
-	ld a, $1
-	ld [hCGBPalUpdate], a
-	ret
-; 12451
-
-.palettes ; 12451
-	RGB 31, 31, 31
-	RGB 31, 19, 10
-	RGB 31, 07, 01
-	RGB 00, 00, 00
-; 12459
-
-.FlashPalettes8Times: ; 12459
-	ld c, $8
-.palette_loop
-	push bc
-	call .FlashPalettes
-	ld c, 10
-	call DelayFrames
-	pop bc
-	dec c
-	jr nz, .palette_loop
-	ret
-; 12469
-
-.FlashPalettes: ; 12469
-	call IsCGB
-	jr nz, .go
-	ld a, [rOBP1]
-	xor %00101000
-	ld [rOBP1], a
-	ret
-
-.go
-	ld a, [rSVBK]
-	push af
-	ld a, $5
-	ld [rSVBK], a
-
-	ld hl, OBPals + 8 * 6
-	ld a, [hli]
-	ld e, a
-	ld a, [hli]
-	ld d, a
-	push de
-	ld c, $3
-.palette_loop_2
-	ld a, [hli]
-	ld e, a
-	ld a, [hld]
-	ld d, a
-	dec hl
-	ld a, d
-	ld [hld], a
-	ld a, e
-	ld [hli], a
-	inc hl
-	inc hl
-	inc hl
-	dec c
-	jr nz, .palette_loop_2
-	pop de
-	dec hl
-	ld a, d
-	ld [hld], a
-	ld a, e
-	ld [hl], a
-
-	pop af
-	ld [rSVBK], a
-	ld a, $1
-	ld [hCGBPalUpdate], a
-	ret
-; 124a3
-
-.PlaceHealingMachineTile: ; 124a3
-	push bc
-	ld a, [Buffer1]
-	bcpixel 2, 4
-	cp $1 ; ElmsLab
-	jr z, .okay
-	bcpixel 0, 0
-
-.okay
-	ld a, [de]
-	add c
-	inc de
-	ld [hli], a
-	ld a, [de]
-	add b
-	inc de
-	ld [hli], a
-	ld a, [de]
-	inc de
-	ld [hli], a
-	ld a, [de]
-	inc de
-	ld [hli], a
-	pop bc
-	ret
-; 124c1
--- /dev/null
+++ b/engine/init_hof_credits.asm
@@ -1,0 +1,79 @@
+InitDisplayForHallOfFame: ; 4e881
+	call ClearBGPalettes
+	call ClearTileMap
+	call ClearSprites
+	call DisableLCD
+	call LoadStandardFont
+	call LoadFontsBattleExtra
+	hlbgcoord 0, 0
+	ld bc, VBGMap1 - VBGMap0
+	ld a, " "
+	call ByteFill
+	hlcoord 0, 0, AttrMap
+	ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
+	xor a
+	call ByteFill
+	xor a
+	ld [hSCY], a
+	ld [hSCX], a
+	call EnableLCD
+	ld hl, .SavingRecordDontTurnOff
+	call PrintText
+	call WaitBGMap2
+	call SetPalettes
+	ret
+
+.SavingRecordDontTurnOff: ; 0x4e8bd
+	; SAVING RECORD… DON'T TURN OFF!
+	text_jump UnknownText_0x1bd39e
+	db "@"
+
+InitDisplayForRedCredits: ; 4e8c2
+	call ClearBGPalettes
+	call ClearTileMap
+	call ClearSprites
+	call DisableLCD
+	call LoadStandardFont
+	call LoadFontsBattleExtra
+	hlbgcoord 0, 0
+	ld bc, VBGMap1 - VBGMap0
+	ld a, " "
+	call ByteFill
+	hlcoord 0, 0, AttrMap
+	ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
+	xor a
+	call ByteFill
+	ld hl, UnknBGPals
+	ld c, 4 tiles
+.load_white_palettes
+	ld a, (palred 31 + palgreen 31 + palblue 31) % $100
+	ld [hli], a
+	ld a, (palred 31 + palgreen 31 + palblue 31) / $100
+	ld [hli], a
+	dec c
+	jr nz, .load_white_palettes
+	xor a
+	ld [hSCY], a
+	ld [hSCX], a
+	call EnableLCD
+	call WaitBGMap2
+	call SetPalettes
+	ret
+
+ResetDisplayBetweenHallOfFameMons: ; 4e906
+	ld a, [rSVBK]
+	push af
+	ld a, $6
+	ld [rSVBK], a
+	ld hl, wDecompressScratch
+	ld bc, wScratchAttrMap - wDecompressScratch
+	ld a, " "
+	call ByteFill
+	hlbgcoord 0, 0
+	ld de, wDecompressScratch
+	ld b, 0
+	ld c, 4 tiles
+	call Request2bpp
+	pop af
+	ld [rSVBK], a
+	ret
--- /dev/null
+++ b/engine/init_list.asm
@@ -1,0 +1,54 @@
+InitList: ; 50db9
+	ld a, [wInitListType]
+
+	cp INIT_ENEMYOT_LIST
+	jr nz, .check_party_ot_name
+	ld hl, OTPartyCount
+	ld de, OTPartyMonOT
+	ld a, ENEMY_OT_NAME
+	jr .done
+
+.check_party_ot_name
+	cp INIT_PLAYEROT_LIST
+	jr nz, .check_mon_name
+	ld hl, PartyCount
+	ld de, PartyMonOT
+	ld a, PARTY_OT_NAME
+	jr .done
+
+.check_mon_name
+	cp INIT_MON_LIST
+	jr nz, .check_item_name
+	ld hl, CurMart
+	ld de, PokemonNames
+	ld a, PKMN_NAME
+	jr .done
+
+.check_item_name
+	cp INIT_BAG_ITEM_LIST
+	jr nz, .check_ob_item_name
+	ld hl, NumItems
+	ld de, ItemNames
+	ld a, ITEM_NAME
+	jr .done
+
+.check_ob_item_name
+	ld hl, CurMart
+	ld de, ItemNames
+	ld a, ITEM_NAME
+.done
+	ld [wNamedObjectTypeBuffer], a
+	ld a, l
+	ld [wListPointer], a
+	ld a, h
+	ld [wListPointer + 1], a
+	ld a, e
+	ld [wUnusedD102], a
+	ld a, d
+	ld [wUnusedD102 + 1], a
+	ld bc, ItemAttributes
+	ld a, c
+	ld [wItemAttributesPtr], a
+	ld a, b
+	ld [wItemAttributesPtr + 1], a
+	ret
--- a/engine/link.asm
+++ b/engine/link.asm
@@ -2581,3 +2581,14 @@
 ; unreferenced
 INCBIN "gfx/trade/unused_gen_1_border_tiles.2bpp"
 ; 29fe4
+
+Function29fe4: ; unreferenced
+	ld a, BANK(sPartyMail)
+	call GetSRAMBank
+	ld d, $0
+	ld b, CHECK_FLAG
+	predef FlagPredef
+	call CloseSRAM
+	ld a, c
+	and a
+	ret
--- /dev/null
+++ b/engine/mystery_gift.asm
@@ -1,0 +1,1735 @@
+DoMysteryGift: ; 1048ba (41:48ba)
+	call ClearTileMap
+	call ClearSprites
+	call WaitBGMap
+	call InitMysteryGiftLayout
+	hlcoord 3, 8
+	ld de, .String_PressAToLink_BToCancel
+	call PlaceString
+	call WaitBGMap
+	callba PrepMysteryGiftDataToSend
+	call MysteryGift_ClearTrainerData
+	ld a, $2
+	ld [wca01], a
+	ld a, $14
+	ld [wca02], a
+	ld a, [rIE]
+	push af
+
+	call Function104a95
+
+	ld d, a
+	xor a
+	ld [rIF], a
+	pop af
+	ld [rIE], a
+	push de
+	call ClearTileMap
+	call EnableLCD
+	call WaitBGMap
+	ld b, SCGB_DIPLOMA
+	call GetSGBLayout
+	call SetPalettes
+	pop de
+	hlcoord 2, 8
+	ld a, d
+	ld de, .Text_LinkCanceled ; Link has been canceled
+	cp $10
+	jp z, .LinkCanceled
+	cp $6c
+	jp nz, .CommunicationError
+	ld a, [wc900]
+	cp 3
+	jr z, .skip_checks
+	call .CheckAlreadyGotFiveGiftsToday
+	ld hl, .Text_MaxFiveGifts ; Only 5 gifts a day
+	jp nc, .PrintTextAndExit
+	call .CheckAlreadyGotAGiftFromThatPerson
+	ld hl, .Text_MaxOneGiftPerPerson ; Only one gift a day per person
+	jp c, .PrintTextAndExit
+.skip_checks
+	ld a, [wMysteryGiftPlayerBackupItem]
+	and a
+	jp nz, .GiftWaiting
+	ld a, [wMysteryGiftPartnerBackupItem]
+	and a
+	jp nz, .FriendNotReady
+	ld a, [wc900]
+	cp 3
+	jr z, .skip_append_save
+	call .AddMysteryGiftPartnerID
+	ld a, [wc900]
+	cp 4
+	jr z, .skip_append_save
+	call .SaveMysteryGiftTrainerName
+	callba RestoreMobileEventIndex
+	callba TrainerRankings_MysteryGift
+	callba BackupMobileEventIndex
+.skip_append_save
+	ld a, [wMysteryGiftPartnerSentDeco]
+	and a
+	jr z, .item
+	ld a, [wMysteryGiftPartnerWhichDeco]
+	ld c, a
+	callba MysteryGiftGetDecoration
+	push bc
+	call MysteryGift_CheckAndSetDecorationAlreadyReceived
+	pop bc
+	jr nz, .item
+	callab GetDecorationName_c
+	ld h, d
+	ld l, e
+	ld de, StringBuffer1
+	ld bc, ITEM_NAME_LENGTH
+	call CopyBytes
+	ld hl, .Text_SentToHome ; sent decoration to home
+	jr .PrintTextAndExit
+
+.item
+	call GetMysteryGiftBank
+	ld a, [wMysteryGiftPartnerWhichItem]
+	ld c, a
+	callba MysteryGiftGetItemHeldEffect
+	ld a, c
+	ld [sBackupMysteryGiftItem], a
+	ld [wNamedObjectIndexBuffer], a
+	call CloseSRAM
+	call GetItemName
+	ld hl, .Text_Sent ; sent item
+	jr .PrintTextAndExit
+
+.LinkCanceled: ; 1049af (41:49af)
+	ld hl, .Text_LinkCanceled ; Link has been canceled
+	jr .PrintTextAndExit
+
+.CommunicationError: ; 1049b4 (41:49b4)
+	ld hl, .Text_CommunicationError ; Communication error
+	call PrintText
+	jp DoMysteryGift
+
+.GiftWaiting: ; 1049bd (41:49bd)
+	ld hl, .Text_ReceiveGiftAtCounter ; receive gift at counter
+	jr .PrintTextAndExit
+
+.FriendNotReady: ; 1049c2 (41:49c2)
+	ld hl, .Text_FriendNotReady ; friend not ready
+
+.PrintTextAndExit: ; 1049c5 (41:49c5)
+	call PrintText
+	ld a, $e3
+	ld [rLCDC], a
+	ret
+; 1049cd (41:49cd)
+
+.String_PressAToLink_BToCancel: ; 1049cd
+	db   "Press A to"
+	next "link IR-Device"
+	next "Press B to"
+	next "cancel it."
+	db   "@"
+; 1049fd
+
+.Text_LinkCanceled: ; 1049fd
+	text_jump UnknownText_0x1c0436
+	db "@"
+; 104a02
+
+.Text_CommunicationError: ; 104a02
+	text_jump UnknownText_0x1c0454
+	db "@"
+; 104a07
+
+.Text_ReceiveGiftAtCounter: ; 104a07
+	text_jump UnknownText_0x1c046a
+	db "@"
+; 104a0c
+
+.Text_FriendNotReady: ; 104a0c
+	text_jump UnknownText_0x1c048e
+	db "@"
+; 104a11
+
+.Text_MaxFiveGifts: ; 104a11
+	text_jump UnknownText_0x1c04a7
+	db "@"
+; 104a16
+
+.Text_MaxOneGiftPerPerson: ; 104a16
+	text_jump UnknownText_0x1c04c6
+	db "@"
+; 104a1b
+
+.Text_Sent: ; 104a1b
+	text_jump UnknownText_0x1c04e9
+	db "@"
+; 104a20
+
+.Text_SentToHome: ; 104a20
+	text_jump UnknownText_0x1c04fa
+	db "@"
+; 104a25
+
+.CheckAlreadyGotFiveGiftsToday: ; 104a25 (41:4a25)
+	call GetMysteryGiftBank
+	ld a, [sNumDailyMysteryGiftPartnerIDs]
+	cp $5
+	jp CloseSRAM
+
+.CheckAlreadyGotAGiftFromThatPerson: ; 104a30 (41:4a30)
+	call GetMysteryGiftBank
+	ld a, [wMysteryGiftPartnerID]
+	ld b, a
+	ld a, [wMysteryGiftPartnerID + 1]
+	ld c, a
+	ld a, [sNumDailyMysteryGiftPartnerIDs]
+	ld d, a
+	ld hl, sDailyMysteryGiftPartnerIDs
+.loop
+	ld a, d
+	and a
+	jr z, .No
+	ld a, [hli]
+	cp b
+	jr nz, .skip
+	ld a, [hl]
+	cp c
+	jr z, .Yes
+.skip
+	inc hl
+	dec d
+	jr .loop
+.Yes:
+	scf
+.No:
+	jp CloseSRAM
+
+.AddMysteryGiftPartnerID: ; 104a56 (41:4a56)
+	call GetMysteryGiftBank
+	ld hl, sNumDailyMysteryGiftPartnerIDs
+	ld a, [hl]
+	inc [hl]
+	ld hl, sDailyMysteryGiftPartnerIDs ; inc hl
+	ld e, a
+	ld d, $0
+	add hl, de
+	add hl, de
+	ld a, [wMysteryGiftPartnerID]
+	ld [hli], a
+	ld a, [wMysteryGiftPartnerID + 1]
+	ld [hl], a
+	jp CloseSRAM
+
+.SaveMysteryGiftTrainerName: ; 104a71 (41:4a71)
+	call GetMysteryGiftBank
+	ld a, $1
+	ld [sMysteryGiftTrainerHouseFlag], a
+	ld hl, wMysteryGiftPartnerName
+	ld de, sMysteryGiftPartnerName
+	ld bc, NAME_LENGTH
+	call CopyBytes
+	ld a, $1
+	ld [de], a
+	inc de
+	ld hl, wMysteryGiftTrainerData
+	ld bc, (1 + 1 + NUM_MOVES) * PARTY_LENGTH + 2
+	call CopyBytes
+	jp CloseSRAM
+
+Function104a95: ; 104a95 (41:4a95)
+	di
+	callba ClearChannels
+	call Function104d5e
+
+.loop2
+	call Function104d96
+	call Function104ddd
+	ld a, [hMGStatusFlags]
+	cp $10
+	jp z, Function104bd0
+	cp $6c
+	jr nz, .loop2
+
+	ld a, [hPrintNum9]
+	cp $2
+	jr z, Function104b22
+	ld hl, hPrintNum1
+	ld b, $1
+	call Function104d56
+	jr nz, .ly_loop
+	call Function104b49
+	jp nz, Function104bd0
+	jr Function104b0a
+	; Delay frame
+.ly_loop
+	ld a, [rLY]
+	cp $90
+	jr c, .ly_loop
+	ld c, rRP % $100
+	ld a, $c0
+	ld [$ff00+c], a
+	ld b, 240 ; This might have been intended as a 4-second timeout buffer.
+	          ; However, it is reset with each frame.
+.loop3
+	push bc
+	call MysteryGift_ReadJoypad
+
+	ld b, $2
+	ld c, rRP % $100
+	; Delay frame
+.ly_loop2
+	ld a, [$ff00+c]
+	and b
+	ld b, a
+	ld a, [rLY]
+	cp $90
+	jr nc, .ly_loop2
+.ly_loop3
+	ld a, [$ff00+c]
+	and b
+	ld b, a
+	ld a, [rLY]
+	cp $90
+	jr c, .ly_loop3
+
+	ld a, b
+	pop bc
+	dec b
+	jr z, .loop2 ; we never jump here
+	or a
+	jr nz, .loop2
+	; Check if we've pressed the B button
+	ld a, [hMGJoypadReleased]
+	bit B_BUTTON_F, a
+	jr z, .loop3
+	ld a, $10
+	ld [hMGStatusFlags], a
+	jp Function104bd0
+
+Function104b04: ; 104b04 (41:4b04)
+	call Function104b40
+	jp nz, Function104bd0
+Function104b0a: ; 104b0a (41:4b0a)
+	call Function104d38
+	jp nz, Function104bd0
+	call Function104b88
+	jp nz, Function104bd0
+	call Function104d43
+	jp nz, Function104bd0
+	call Function105033
+	jp Function104bd0
+
+Function104b22: ; 104b22 (41:4b22)
+	call Function104b88
+	jp nz, Function104bd0
+	call Function104d43
+	jp nz, Function104bd0
+	call Function104b40
+	jp nz, Function104bd0
+	call Function104d38
+	jp nz, Function104bd0
+	call Function10502e
+	jp Function104bd0
+
+Function104b40: ; 104b40 (41:4b40)
+	ld hl, hPrintNum1
+	ld b, $1
+	call Function104d56
+	ret nz
+
+Function104b49: ; 104b49 (41:4b49)
+	call Function105033
+	ld a, [hMGStatusFlags]
+	cp $6c
+	ret nz
+	ld a, [hPrintNum1]
+	cp $96
+	jp nz, Function104d32
+	ld a, $90
+	ld [hPrintNum1], a
+	call Function104d38
+	ret nz
+	ld hl, hPrintNum1
+	ld b, $1
+	call Function104d4e
+	ret nz
+	call Function10502e
+	ld a, [hMGStatusFlags]
+	cp $6c
+	ret nz
+	call Function104d43
+	ret nz
+	ld hl, wMysteryGiftTrainerData
+	ld a, [wca02]
+	ld b, a
+	call Function104d56
+	ret nz
+	call Function105033
+	ld a, [hMGStatusFlags]
+	cp $6c
+	ret
+
+Function104b88: ; 104b88 (41:4b88)
+	ld a, $96
+	ld [hPrintNum1], a
+	ld hl, hPrintNum1
+	ld b, $1
+	call Function104d4e
+	ret nz
+	call Function10502e
+	ld a, [hMGStatusFlags]
+	cp $6c
+	ret nz
+	call Function104d43
+	ret nz
+	ld hl, hPrintNum1
+	ld b, $1
+	call Function104d56
+	ret nz
+	call Function105033
+	ld a, [hMGStatusFlags]
+	cp $6c
+	ret nz
+	ld a, [hPrintNum1]
+	cp $90
+	jp nz, Function104d32
+	call Function104d38
+	ret nz
+	ld hl, OverworldMap
+	ld a, [wca02]
+	ld b, a
+	call Function104d4e
+	ret nz
+	call Function10502e
+	ld a, [hMGStatusFlags]
+	cp $6c
+	ret
+
+Function104bd0: ; 104bd0 (41:4bd0)
+	nop
+	ld a, [hMGStatusFlags]
+	cp $10
+	jr z, .quit
+	cp $6c
+	jr nz, .quit
+	ld hl, wca01
+	dec [hl]
+	jr z, .quit
+	ld hl, wMysteryGiftTrainerData
+	ld de, wMysteryGiftPartnerData
+	ld bc, wMysteryGiftPartnerDataEnd - wMysteryGiftPartnerData
+	call CopyBytes
+	ld a, [wMysteryGiftTrainerData]
+	cp $3
+	jr nc, .quit
+	callba StagePartyDataForMysteryGift
+	call MysteryGift_ClearTrainerData
+	ld a, $26
+	ld [wca02], a
+	ld a, [hPrintNum9]
+	cp $2
+	jr z, .asm_104c10
+	call Function104d43
+	jr nz, Function104bd0
+	jp Function104b04
+
+.asm_104c10
+	call Function104d38
+	jr nz, Function104bd0
+	jp Function104b22
+
+.quit
+	ld a, [hMGStatusFlags]
+	push af
+	call Function104da0
+	xor a
+	ld [rIF], a
+	ld a, [rIE]
+	or $1
+	ld [rIE], a
+	ei
+	call DelayFrame
+	pop af
+	ret
+
+Function104c2d: ; 104c2d (41:4c2d)
+	di
+	callba ClearChannels
+	call Function104d5e
+.asm_104c37
+	call Function104d96
+	call Function104ddd
+	ld a, [hMGStatusFlags]
+	cp $10
+	jp z, Function104d1c
+	cp $6c
+	jr nz, .asm_104c37
+	ld a, [hPrintNum9]
+	cp $2
+	jr z, .asm_104c6c
+	call Function104c8a
+	jp nz, Function104d1c
+	call Function104d38
+	jp nz, Function104d1c
+	call Function104cd2
+	jp nz, Function104d1c
+	call Function104d43
+	jp nz, Function104d1c
+	call Function105033
+	jp Function104d1c
+.asm_104c6c
+	call Function104cd2
+	jp nz, Function104d1c
+	call Function104d43
+	jp nz, Function104d1c
+	call Function104c8a
+	jp nz, Function104d1c
+	call Function104d38
+	jp nz, Function104d1c
+	call Function10502e
+	jp Function104d1c
+
+Function104c8a: ; 104c8a (41:4c8a)
+	ld hl, hPrintNum1
+	ld b, $1
+	call Function104d56
+	ret nz
+	call Function105033
+	ld a, [hMGStatusFlags]
+	cp $6c
+	ret nz
+	ld a, [hPrintNum1]
+	cp $3c
+	jp nz, Function104d32
+	swap a
+	ld [hPrintNum1], a
+	call Function104d38
+	ret nz
+	ld hl, hPrintNum1
+	ld b, $1
+	call Function104d4e
+	ret nz
+	call Function10502e
+	ld a, [hMGStatusFlags]
+	cp $6c
+	ret nz
+	call Function104d43
+	ret nz
+	ld hl, wMysteryGiftTrainerData
+	ld a, [wca02]
+	ld b, a
+	call Function104d56
+	ret nz
+	call Function105033
+	ld a, [hMGStatusFlags]
+	cp $6c
+	ret
+
+Function104cd2: ; 104cd2 (41:4cd2)
+	ld a, $3c
+	ld [hPrintNum1], a
+	ld hl, hPrintNum1
+	ld b, $1
+	call Function104d4e
+	ret nz
+	call Function10502e
+	ld a, [hMGStatusFlags]
+	cp $6c
+	ret nz
+	call Function104d43
+	ret nz
+	ld hl, hPrintNum1
+	ld b, $1
+	call Function104d56
+	ret nz
+	call Function105033
+	ld a, [hMGStatusFlags]
+	cp $6c
+	ret nz
+	ld a, [hPrintNum1]
+	swap a
+	cp $3c
+	jp nz, Function104d32
+	call Function104d38
+	ret nz
+	ld hl, OverworldMap
+	ld a, [wca02]
+	ld b, a
+	call Function104d4e
+	ret nz
+	call Function10502e
+	ld a, [hMGStatusFlags]
+	cp $6c
+	ret
+
+Function104d1c: ; 104d1c (41:4d1c)
+	nop
+	ld a, [hMGStatusFlags]
+	push af
+	call Function104da0
+	xor a
+	ld [rIF], a
+	ld a, [rIE]
+	or $1
+	ld [rIE], a
+	ei
+	call DelayFrame
+	pop af
+	ret
+
+Function104d32: ; 104d32 (41:4d32)
+	ld a, $80
+	ld [hMGStatusFlags], a
+	and a
+	ret
+
+Function104d38: ; 104d38 (41:4d38)
+	call Function104d96
+	call Function104e46
+	ld a, [hMGStatusFlags]
+	cp $6c
+	ret
+
+Function104d43: ; 104d43 (41:4d43)
+	call Function104d96
+	call Function104dfe
+	ld a, [hMGStatusFlags]
+	cp $6c
+	ret
+
+Function104d4e: ; 104d4e (41:4d4e)
+	call Function104e93
+	ld a, [hMGStatusFlags]
+	cp $6c
+	ret
+
+Function104d56: ; 104d56 (41:4d56)
+	call Function104f57
+	ld a, [hMGStatusFlags]
+	cp $6c
+	ret
+
+Function104d5e: ; 104d5e (41:4d5e)
+	call Function104d74
+	ld a, $4
+	ld [rIE], a
+	xor a
+	ld [rIF], a
+	call Function104d96
+	xor a
+	ld b, a
+.asm_104d6d
+	inc a
+	jr nz, .asm_104d6d
+	inc b
+	jr nz, .asm_104d6d
+	ret
+
+Function104d74: ; 104d74 (41:4d74)
+	xor a
+	ld [rTAC], a
+	ld a, $fe
+	ld [rTMA], a
+	ld [rTIMA], a
+	ld a, $2
+	ld [rTAC], a
+	or $4
+	ld [rTAC], a
+	ret
+
+Function104d86: ; 104d86 (41:4d86)
+	xor a
+	ld [rTAC], a
+	ld [rTMA], a
+	ld [rTIMA], a
+	ld a, $2
+	ld [rTAC], a
+	or $4
+	ld [rTAC], a
+	ret
+
+Function104d96: ; 104d96 (41:4d96)
+	ld a, $c0
+	call Function104e8c
+	ld a, $1
+	ld [hPrintNum9], a
+	ret
+
+Function104da0: ; 104da0 (41:4da0)
+	xor a
+	call Function104e8c
+	ld a, $2
+	ld [rTAC], a
+	ret
+
+Function104da9: ; 104da9 (41:4da9)
+	inc d
+	ret z
+	xor a
+	ld [rIF], a
+	halt
+	ld a, [$ff00+c]
+	bit 1, a
+	jr z, Function104da9
+	or a
+	ret
+
+Function104db7: ; 104db7 (41:4db7)
+	inc d
+	ret z
+	xor a
+	ld [rIF], a
+	halt
+	ld a, [$ff00+c]
+	bit 1, a
+	jr nz, Function104db7
+	or a
+	ret
+
+Function104dc5: ; 104dc5 (41:4dc5)
+	ld a, $c1
+	ld [$ff00+c], a
+.wait
+	dec d
+	ret z
+	xor a
+	ld [rIF], a
+	halt
+	jr .wait
+
+Function104dd1: ; 104dd1 (41:4dd1)
+	ld a, $c0
+	ld [$ff00+c], a
+.wait
+	dec d
+	ret z
+	xor a
+	ld [rIF], a
+	halt
+	jr .wait
+
+Function104ddd: ; 104ddd (41:4ddd)
+	ld d, $0
+	ld e, d
+	ld a, $1
+	ld [hPrintNum9], a
+.loop
+	call MysteryGift_ReadJoypad
+	ld b, $2
+	ld c, rRP % $100
+	ld a, [hMGJoypadReleased]
+	bit B_BUTTON_F, a
+	jr z, .next
+	ld a, $10
+	ld [hMGStatusFlags], a
+	ret
+
+.next
+	bit 0, a
+	jr nz, Function104e3a
+	ld a, [$ff00+c]
+	and b
+	jr nz, .loop
+
+Function104dfe: ; 104dfe (41:4dfe)
+	ld c, rRP % $100
+	ld d, $0
+	ld e, d
+	call Function104db7
+	jp z, Function104f42
+	ld d, e
+	call Function104da9
+	jp z, Function104f42
+	call Function104db7
+	jp z, Function104f42
+	call Function104da9
+	jp z, Function104f42
+	ld a, $6c
+	ld [hMGStatusFlags], a
+	ld d, $3d
+	call Function104dd1
+	ld d, $5
+	call Function104dc5
+	ld d, $15
+	call Function104dd1
+	ld d, $5
+	call Function104dc5
+	ld d, $5
+	call Function104dd1
+	ret
+
+Function104e3a: ; 104e3a (41:4e3a)
+	; Wait a random amount of time
+	call Random
+	ld e, a
+	and $f
+	ld d, a
+.loop
+	dec de
+	ld a, d
+	or e
+	jr nz, .loop
+Function104e46: ; 104e46 (41:4e46)
+	ld a, $2
+	ld [hPrintNum9], a
+	ld c, rRP % $100
+	ld d, $0
+	ld e, d
+	ld d, $3d
+	call Function104dd1
+	ld d, $5
+	call Function104dc5
+	ld d, $15
+	call Function104dd1
+	ld d, $5
+	call Function104dc5
+	ld d, $5
+	call Function104dd1
+	ld d, e
+	call Function104db7
+	jp z, Function104f42
+	ld d, e
+	call Function104da9
+	jp z, Function104f42
+	call Function104db7
+	jp z, Function104f42
+	call Function104da9
+	jp z, Function104f42
+	ld d, $3d
+	call Function104dd1
+	ld a, $6c
+	ld [hMGStatusFlags], a
+	ret
+
+Function104e8c: ; 104e8c (41:4e8c)
+	ld [rRP], a
+	ld a, $ff
+	ld [hMGStatusFlags], a
+	ret
+
+Function104e93: ; 104e93 (41:4e93)
+	xor a
+	ld [hPrintNum5], a
+	ld [hPrintNum6], a
+	push hl
+	push bc
+	ld c, rRP % $100
+	ld d, $3d
+	call Function104dd1
+	ld hl, hPrintNum2
+	ld a, $5a
+	ld [hli], a
+	ld [hl], b
+	dec hl
+	ld b, $2
+	call Function104ed6
+	pop bc
+	pop hl
+	call Function104ed6
+	ld a, [hPrintNum5]
+	ld [hPrintNum2], a
+	ld a, [hPrintNum6]
+	ld [hPrintNum3], a
+	push hl
+	ld hl, hPrintNum2
+	ld b, $2
+	call Function104ed6
+	ld hl, hMGStatusFlags
+	ld b, $1
+	call Function104faf
+	ld a, [hPrintNum2]
+	ld [hPrintNum5], a
+	ld a, [hPrintNum3]
+	ld [hPrintNum6], a
+	pop hl
+	ret
+
+Function104ed6: ; 104ed6 (41:4ed6)
+	ld c, rRP % $100
+	ld d, $5
+	call Function104dd1
+	ld d, $5
+	call Function104dc5
+	ld d, $15
+	call Function104dd1
+	ld a, b
+	cpl
+	ld b, a
+	ld a, $f4
+	ld [rTMA], a
+.asm_104eee
+	inc b
+	jr z, .asm_104f2e
+	ld a, $8
+	ld [hPrintNum4], a
+	ld a, [hli]
+	ld e, a
+	ld a, [hPrintNum5]
+	add e
+	ld [hPrintNum5], a
+	ld a, [hPrintNum6]
+	adc $0
+	ld [hPrintNum6], a
+.asm_104f02
+	xor a
+	ld [rIF], a
+	halt
+	ld a, $c1
+	ld [rRP], a
+	ld d, $1
+	ld a, e
+	rlca
+	ld e, a
+	jr nc, .asm_104f13
+	inc d
+.asm_104f13
+	ld a, [rTIMA]
+	cp $f8
+	jr c, .asm_104f13
+	ld a, $c0
+	ld [rRP], a
+	dec d
+	jr z, .asm_104f25
+	xor a
+	ld [rIF], a
+	halt
+.asm_104f25
+	ld a, [hPrintNum4]
+	dec a
+	jr z, .asm_104eee
+	ld [hPrintNum4], a
+	jr .asm_104f02
+.asm_104f2e
+	ld a, $fe
+	ld [rTMA], a
+	xor a
+	ld [rIF], a
+	halt
+	ld d, $5
+	call Function104dc5
+	ld d, $11
+	call Function104dd1
+	ret
+
+Function104f42: ; 104f42 (41:4f42)
+	ld a, [hMGStatusFlags]
+	or $2
+	ld [hMGStatusFlags], a
+	ret
+
+Function104f49: ; 104f49 (41:4f49)
+	ld a, [hMGStatusFlags]
+	or $1
+	ld [hMGStatusFlags], a
+	ret
+
+Function104f50: ; 104f50 (41:4f50)
+	ld a, [hMGStatusFlags]
+	or $80
+	ld [hMGStatusFlags], a
+	ret
+
+Function104f57: ; 104f57 (41:4f57)
+	xor a
+	ld [hPrintNum5], a
+	ld [hPrintNum6], a
+	push bc
+	push hl
+	ld hl, hPrintNum2
+	ld b, $2
+	call Function104faf
+	ld a, [hPrintNum3]
+	ld [hPrintNum8], a
+	ld b, a
+	pop hl
+	pop af
+	cp b
+	jp c, Function104f50
+	ld a, [hPrintNum2]
+	cp $5a
+	jp nz, Function104f50
+	call Function104faf
+	ld a, [hPrintNum5]
+	ld d, a
+	ld a, [hPrintNum6]
+	ld e, a
+	push hl
+	push de
+	ld hl, hPrintNum2
+	ld b, $2
+	call Function104faf
+	pop de
+	ld hl, hPrintNum2
+	ld a, [hli]
+	xor d
+	ld b, a
+	ld a, [hl]
+	xor e
+	or b
+	call nz, Function104f49
+	push de
+	ld d, $3d
+	call Function104dd1
+	ld hl, hMGStatusFlags
+	ld b, $1
+	call Function104ed6
+	pop de
+	pop hl
+	ld a, d
+	ld [hPrintNum5], a
+	ld a, e
+	ld [hPrintNum6], a
+	ret
+
+Function104faf: ; 104faf (41:4faf)
+	ld c, rRP % $100
+	ld d, $0
+	call Function104db7
+	jp z, Function104f42
+	ld d, $0
+	call Function104da9
+	jp z, Function104f42
+	ld d, $0
+	call Function104db7
+	jp z, Function104f42
+	ld a, b
+	cpl
+	ld b, a
+	xor a
+	ld [hMGJoypadPressed + 2], a
+	call Function104d86
+.asm_104fd2
+	inc b
+	jr z, .asm_10501a
+	ld a, $8
+	ld [hPrintNum4], a
+.asm_104fd9
+	ld d, $0
+.asm_104fdb
+	inc d
+	jr z, .asm_104fe5
+	ld a, [$ff00+c]
+	bit 1, a
+	jr z, .asm_104fdb
+	ld d, $0
+.asm_104fe5
+	inc d
+	jr z, .asm_104fed
+	ld a, [$ff00+c]
+	bit 1, a
+	jr nz, .asm_104fe5
+.asm_104fed
+	ld a, [hMGJoypadPressed + 2]
+	ld d, a
+	ld a, [rTIMA]
+	ld [hMGJoypadPressed + 2], a
+	sub d
+	cp $12
+	jr c, .asm_104ffd
+	set 0, e
+	jr .asm_104fff
+.asm_104ffd
+	res 0, e
+.asm_104fff
+	ld a, [hPrintNum4]
+	dec a
+	ld [hPrintNum4], a
+	jr z, .asm_10500b
+	ld a, e
+	rlca
+	ld e, a
+	jr .asm_104fd9
+.asm_10500b
+	ld a, e
+	ld [hli], a
+	ld a, [hPrintNum5]
+	add e
+	ld [hPrintNum5], a
+	ld a, [hPrintNum6]
+	adc $0
+	ld [hPrintNum6], a
+	jr .asm_104fd2
+.asm_10501a
+	call Function104d74
+	xor a
+	ld [rIF], a
+	ld d, $0
+	call Function104da9
+	jp z, Function104f42
+	ld d, $10
+	call Function104dd1
+	ret
+
+Function10502e: ; 10502e (41:502e)
+	ld b, $0
+	jp Function104e93
+
+Function105033: ; 105033 (41:5033)
+	ld b, $0
+	jp Function104f57
+
+MysteryGift_ReadJoypad: ; 105038 (41:5038)
+; We can only get four inputs at a time.
+; We take d-pad first for no particular reason.
+	ld a, R_DPAD
+	ld [rJOYP], a
+; Read twice to give the request time to take.
+	ld a, [rJOYP]
+	ld a, [rJOYP]
+
+; The Joypad register output is in the lo nybble (inversed).
+; We make the hi nybble of our new container d-pad input.
+	cpl
+	and $f
+	swap a
+
+; We'll keep this in b for now.
+	ld b, a
+
+; Buttons make 8 total inputs (A, B, Select, Start).
+; We can fit this into one byte.
+	ld a, R_BUTTONS
+	ld [rJOYP], a
+; Wait for input to stabilize.
+rept 6
+	ld a, [rJOYP]
+endr
+; Buttons take the lo nybble.
+	cpl
+	and $f
+	or b
+	ld c, a
+; To get the delta we xor the last frame's input with the new one.
+	ld a, [hMGJoypadPressed]
+	xor c
+; Released this frame:
+	and c
+	ld [hMGJoypadReleased], a
+; Pressed this frame:
+	ld a, c
+	ld [hMGJoypadPressed], a
+	ld a, $30
+; Reset the joypad register since we're done with it.
+	ld [rJOYP], a
+	ret
+
+MysteryGift_CheckAndSetDecorationAlreadyReceived: ; 105069 (41:5069)
+	call GetMysteryGiftBank
+	ld d, $0
+	ld b, CHECK_FLAG
+	ld hl, sMysteryGiftDecorationsReceived
+	predef_id FlagPredef
+	push hl
+	push bc
+	call Predef
+	call CloseSRAM
+	ld a, c
+	and a
+	pop bc
+	pop hl
+	ret nz
+	call GetMysteryGiftBank
+	ld b, SET_FLAG
+	predef FlagPredef
+	call CloseSRAM
+	xor a
+	ret
+
+MysteryGift_CopyReceivedDecosToPC: ; 105091 (41:5091)
+	call GetMysteryGiftBank
+	ld c, $0
+.loop
+	push bc
+	ld d, $0
+	ld b, CHECK_FLAG
+	ld hl, sMysteryGiftDecorationsReceived
+	predef FlagPredef
+	ld a, c
+	and a
+	pop bc
+	jr z, .skip
+	push bc
+	callab SetSpecificDecorationFlag
+	pop bc
+.skip
+	inc c
+	ld a, c
+	cp Trophys - DecorationIDs
+	jr c, .loop
+	jp CloseSRAM
+
+Special_UnlockMysteryGift: ; 1050b9
+	call GetMysteryGiftBank
+	ld hl, sMysteryGiftUnlocked
+	ld a, [hl]
+	inc a
+	jr nz, .ok
+	ld [hld], a
+	ld [hl], a
+.ok
+	jp CloseSRAM
+; 1050c8
+
+Function1050c8: ; 1050c8
+	call GetMysteryGiftBank
+	ld a, [sNumDailyMysteryGiftPartnerIDs]
+	cp $ff
+	jr z, .okay
+	xor a
+	ld [sNumDailyMysteryGiftPartnerIDs], a
+.okay
+	jp CloseSRAM
+; 1050d9
+
+
+BackupMysteryGift: ; 1050d9
+	call GetMysteryGiftBank
+	ld hl, sMysteryGiftItem
+	ld de, sBackupMysteryGiftItem
+	ld a, [hli]
+	ld [de], a
+	inc de
+	ld a, [hl]
+	ld [de], a
+	jp CloseSRAM
+; 1050ea
+
+
+RestoreMysteryGift: ; 1050ea (41:50ea)
+	call GetMysteryGiftBank
+	ld hl, sBackupMysteryGiftItem
+	ld de, sMysteryGiftItem
+	ld a, [hli]
+	ld [de], a
+	inc de
+	ld a, [hl]
+	ld [de], a
+	jp CloseSRAM
+
+MysteryGift_ClearTrainerData: ; 1050fb (41:50fb)
+	ld hl, wMysteryGiftTrainerData
+	xor a
+	ld b, wMysteryGiftTrainerDataEnd - wMysteryGiftTrainerData
+.loop
+	ld [hli], a
+	dec b
+	jr nz, .loop
+	ret
+
+
+GetMysteryGiftBank: ; 105106
+	ld a, BANK(sBackupMysteryGiftItem)
+	jp GetSRAMBank
+; 10510b
+
+
+StagePartyDataForMysteryGift: ; 10510b (41:510b)
+; You will be sending this data to your mystery gift partner.
+; Structure is the same as a trainer with species and moves
+; defined.
+	ld a, BANK(sPokemonData)
+	call GetSRAMBank
+	ld de, wMysteryGiftStaging
+	ld bc, sPokemonData + PartyMons - wPokemonData
+	ld hl, sPokemonData + PartySpecies - wPokemonData
+.loop
+	ld a, [hli]
+	cp -1
+	jr z, .party_end
+	cp EGG
+	jr z, .next
+	push hl
+	; copy level
+	ld hl, MON_LEVEL
+	add hl, bc
+	ld a, [hl]
+	ld [de], a
+	inc de
+	; copy species
+	ld hl, MON_SPECIES
+	add hl, bc
+	ld a, [hl]
+	ld [de], a
+	inc de
+	; copy moves
+	ld hl, MON_MOVES
+	add hl, bc
+	push bc
+	ld bc, NUM_MOVES
+	call CopyBytes
+	pop bc
+	pop hl
+.next
+	push hl
+	ld hl, PARTYMON_STRUCT_LENGTH
+	add hl, bc
+	ld b, h
+	ld c, l
+	pop hl
+	jr .loop
+.party_end
+	ld a, -1
+	ld [de], a
+	ld a, $26
+	ld [wca00], a
+	jp CloseSRAM
+
+InitMysteryGiftLayout: ; 105153 (41:5153)
+	call ClearBGPalettes
+	call DisableLCD
+	ld hl, MysteryGiftGFX
+	ld de, VTiles2 tile $00
+	ld a, BANK(MysteryGiftGFX)
+	ld bc, MysteryGiftGFXEnd - MysteryGiftGFX
+	call FarCopyBytes
+	hlcoord 0, 0
+	ld a, $42
+	ld bc, SCREEN_HEIGHT * SCREEN_WIDTH
+	call ByteFill
+	hlcoord 3, 7
+	lb bc, 9, 15
+	call ClearBox
+	hlcoord 0, 0
+	ld a, $0
+	ld [hli], a
+	inc a
+	ld [hl], a
+	hlcoord 0, 1
+	inc a
+	ld [hli], a
+	inc a
+	ld [hl], a
+	hlcoord 7, 1
+	ld a, $12
+	call .Load5GFX
+	hlcoord 2, 2
+	ld a, $17
+	call .Load16GFX
+	hlcoord 2, 3
+	ld a, $27
+	call .Load16GFX
+	hlcoord 9, 4
+	ld a, $37
+	ld [hli], a
+	inc a
+	ld [hl], a
+	hlcoord 1, 2
+	ld [hl], $4
+	hlcoord 1, 3
+	ld a, $5
+	call .Load14Column
+	ld a, $9
+	hlcoord 18, 5
+	call .Load11Column
+	hlcoord 2, 5
+	ld a, $b
+	call .Load16Row
+	hlcoord 2, 16
+	ld a, $7
+	call .Load16Row
+	hlcoord 2, 5
+	ld a, $d
+	call .Load5GFX
+	hlcoord 7, 5
+	ld [hl], $c
+	hlcoord 18, 5
+	ld [hl], $a
+	hlcoord 18, 16
+	ld [hl], $8
+	hlcoord 1, 16
+	ld [hl], $6
+	hlcoord 2, 6
+	ld a, $3a
+	call .Load16Row
+	hlcoord 2, 15
+	ld a, $40
+	call .Load16Row
+	hlcoord 2, 6
+	ld a, $3c
+	call .Load9Column
+	hlcoord 17, 6
+	ld a, $3e
+	call .Load9Column
+	hlcoord 2, 6
+	ld [hl], $39
+	hlcoord 17, 6
+	ld [hl], $3b
+	hlcoord 2, 15
+	ld [hl], $3f
+	hlcoord 17, 15
+	ld [hl], $41
+	call EnableLCD
+	call WaitBGMap
+	ld b, SCGB_MYSTERY_GIFT
+	call GetSGBLayout
+	call SetPalettes
+	ret
+
+.Load5GFX: ; 10522e (41:522e)
+	ld b,  5
+	jr .gfx_loop
+; 105232 (41:5232)
+
+.Load6GFX: ; unreferenced
+	ld b,  6
+	jr .gfx_loop
+
+.Load16GFX: ; 105236 (41:5236)
+	ld b, 16
+
+.gfx_loop ; 105238 (41:5238)
+	ld [hli], a
+	inc a
+	dec b
+	jr nz, .gfx_loop
+	ret
+
+.Load9Column: ; 10523e (41:523e)
+	ld b,  9
+	jr .col_loop
+
+.Load11Column: ; 105242 (41:5242)
+	ld b, 11
+	jr .col_loop
+
+.Load14Column: ; 105246 (41:5246)
+	ld b, 14
+
+.col_loop ; 105248 (41:5248)
+	ld [hl], a
+	ld de, SCREEN_WIDTH
+	add hl, de
+	dec b
+	jr nz, .col_loop
+	ret
+
+.Load16Row: ; 105251 (41:5251)
+	ld b, 16
+.row_loop
+	ld [hli], a
+	dec b
+	jr nz, .row_loop
+	ret
+
+MysteryGiftGFX: ; 105258
+INCBIN "gfx/mystery_gift/mystery_gift.2bpp"
+MysteryGiftGFXEnd:
+
+Function105688: ; 105688 (41:5688)
+	call ClearTileMap
+	call ClearSprites
+	call WaitBGMap
+	call Function1057d7
+	hlcoord 3, 8
+	ld de, String_10572e
+	call PlaceString
+	call WaitBGMap
+	call Function10578c
+	call MysteryGift_ClearTrainerData
+	ld a, $24
+	ld [wca02], a
+	ld a, [rIE]
+	push af
+	call Function104c2d
+	ld d, a
+	xor a
+	ld [rIF], a
+	pop af
+	ld [rIE], a
+	ld a, d
+	cp $10
+	jp z, Function105712
+	cp $6c
+	jp nz, Function10571a
+	call Function1056eb
+	ld c, 60
+	call DelayFrames
+	call Function105777
+	ld hl, Text_ReceivedCard
+	call PrintText
+	ld de, wMysteryGiftTrainerData
+	callba Function8ac70
+	ld a, c
+	ld [wd265], a
+	ld hl, Text_CardNotRegistered
+	jr c, asm_105726
+	ld hl, Text_ListedCardAsNumber
+	jr asm_105726
+
+Function1056eb: ; 1056eb (41:56eb)
+	ld c, $10
+.asm_1056ed
+	ld hl, Sprites
+	ld b, $8
+.asm_1056f2
+	dec [hl]
+rept 4
+	inc hl
+endr
+	dec b
+	jr nz, .asm_1056f2
+	ld hl, Sprites + $20
+	ld b, $8
+.asm_1056ff
+	inc [hl]
+rept 4
+	inc hl
+endr
+	dec b
+	jr nz, .asm_1056ff
+	dec c
+	ret z
+	push bc
+	ld c, 4
+	call DelayFrames
+	pop bc
+	jr .asm_1056ed
+
+Function105712: ; 105712 (41:5712)
+	call Function105777
+	ld hl, Text_MGLinkCanceled
+	jr asm_105726
+
+Function10571a: ; 10571a (41:571a)
+	call Function105777
+	ld hl, Text_MGCommError
+	call PrintText
+	jp Function105688
+
+asm_105726: ; 105726 (41:5726)
+	call PrintText
+	ld a, $e3
+	ld [rLCDC], a
+	ret
+; 10572e (41:572e)
+
+String_10572e: ; 10572e
+	db   "エーボタン¯おすと"
+	next "つうしん<PKMN>おこなわれるよ!"
+	next "ビーボタン¯おすと"
+	next "つうしん¯ちゅうし します"
+	db   "@"
+
+; 10575e
+
+Text_ReceivedCard: ; 10575e
+	text_jump UnknownText_0x1c051a
+	db "@"
+
+Text_ListedCardAsNumber: ; 105763
+	text_jump UnknownText_0x1c0531
+	db "@"
+
+Text_CardNotRegistered: ; 105768
+	text_jump UnknownText_0x1c0555
+	db "@"
+
+Text_MGLinkCanceled: ; 10576d
+	text_jump UnknownText_0x1c0573
+	db "@"
+
+Text_MGCommError: ; 105772
+	text_jump UnknownText_0x1c0591
+	db "@"
+; 105777
+
+Function105777: ; 105777 (41:5777)
+	call ClearSprites
+	call ClearTileMap
+	call EnableLCD
+	call WaitBGMap
+	ld b, SCGB_DIPLOMA
+	call GetSGBLayout
+	call SetPalettes
+	ret
+
+Function10578c: ; 10578c (41:578c)
+	ld de, OverworldMap
+	ld a, BANK(sPlayerData)
+	call GetSRAMBank
+	ld hl, sPlayerData + PlayerName - wPlayerData
+	ld bc, NAME_LENGTH
+	call CopyBytes
+	ld hl, sPlayerData + PlayerID - wPlayerData
+	ld bc, 2
+	call CopyBytes
+	ld hl, sPlayerData + wSecretID - wPlayerData
+	ld bc, 2
+	call CopyBytes
+	call CloseSRAM
+	ld a, BANK(sCrystalData)
+	call GetSRAMBank
+	ld a, [sCrystalData + 0]
+	ld [de], a
+	inc de
+	ld a, $4
+	call GetSRAMBank
+	ld hl, $a603
+	ld bc, $8
+	call CopyBytes
+	ld hl, $a007
+	ld bc, $c
+	call CopyBytes
+	call CloseSRAM
+	ret
+
+Function1057d7: ; 1057d7 (41:57d7)
+	call ClearBGPalettes
+	call DisableLCD
+	ld hl, MysteryGiftJP_GFX
+	ld de, VTiles2 tile $00
+	ld a, BANK(MysteryGiftJP_GFX)
+	lb bc, 4, 0
+	call FarCopyBytes
+	ld hl, MysteryGiftJP_GFX + $400
+	ld de, VTiles0 tile $00
+	ld a, BANK(MysteryGiftJP_GFX)
+	ld bc, $80
+	call FarCopyBytes
+	hlcoord 0, 0
+	ld a, $3f
+	ld bc, SCREEN_HEIGHT * SCREEN_WIDTH
+	call ByteFill
+	hlcoord 3, 7
+	lb bc, 9, 15
+	call ClearBox
+	hlcoord 0, 0
+	ld a, $0
+	ld [hli], a
+	inc a
+	ld [hl], a
+	hlcoord 0, 1
+	inc a
+	ld [hli], a
+	inc a
+	ld [hl], a
+	hlcoord 4, 2
+	ld a, $13
+	call .Load11Row
+	hlcoord 4, 3
+	ld a, $1e
+	call .Load12Row
+	hlcoord 4, 4
+	ld a, $2a
+	call .Load12Row
+	hlcoord 1, 2
+	ld [hl], $4
+	hlcoord 1, 3
+	ld a, $5
+	call .Load14Column
+	ld a, $9
+	hlcoord 18, 5
+	call .Load11Column
+	hlcoord 2, 5
+	ld a, $b
+	call .Load16Row
+	hlcoord 2, 16
+	ld a, $7
+	call .Load16Row
+	hlcoord 2, 5
+	ld a, $d
+	call .Load6Row
+	hlcoord 8, 5
+	ld [hl], $c
+	hlcoord 18, 5
+	ld [hl], $a
+	hlcoord 18, 16
+	ld [hl], $8
+	hlcoord 1, 16
+	ld [hl], $6
+	hlcoord 2, 6
+	ld a, $37
+	call .Load16Row
+	hlcoord 2, 15
+	ld a, $3d
+	call .Load16Row
+	hlcoord 2, 6
+	ld a, $39
+	call .Load9Column
+	hlcoord 17, 6
+	ld a, $3b
+	call .Load9Column
+	hlcoord 2, 6
+	ld [hl], $36
+	hlcoord 17, 6
+	ld [hl], $38
+	hlcoord 2, 15
+	ld [hl], $3c
+	hlcoord 17, 15
+	ld [hl], $3e
+	ld de, Sprites
+	ld hl, .OAM_data
+	ld bc, $40
+	call CopyBytes
+	call EnableLCD
+	call WaitBGMap
+	ld b, $2
+	callba GetMysteryGift_MobileAdapterLayout
+	jp SetPalettes
+
+.Load6Row: ; 1058c6 (41:58c6)
+	ld b,  6
+	jr .row_loop
+
+.Load11Row: ; 1058ca (41:58ca)
+	ld b, 11
+	jr .row_loop
+
+.Load12Row: ; 1058ce (41:58ce)
+	ld b, 12
+
+.row_loop ; 1058d0 (41:58d0)
+	ld [hli], a
+	inc a
+	dec b
+	jr nz, .row_loop
+	ret
+
+.Load9Column: ; 1058d6 (41:58d6)
+	ld b,  9
+	jr .column_loop
+
+.Load11Column: ; 1058da (41:58da)
+	ld b, 11
+	jr .column_loop
+
+.Load14Column: ; 1058de (41:58de)
+	ld b, 14
+
+.column_loop ; 1058e0 (41:58e0)
+	ld [hl], a
+	ld de, SCREEN_WIDTH
+	add hl, de
+	dec b
+	jr nz, .column_loop
+	ret
+
+.Load16Row: ; 1058e9 (41:58e9)
+	ld b, 16
+.row_loop_no_inc
+	ld [hli], a
+	dec b
+	jr nz, .row_loop_no_inc
+	ret
+; 1058f0 (41:58f0)
+
+.OAM_data: ; 1058f0
+	dsprite  2, 1,  6, 4, $00, $00
+	dsprite  2, 1,  7, 4, $01, $00
+	dsprite  2, 1,  8, 4, $02, $00
+	dsprite  2, 1,  9, 4, $03, $00
+	dsprite  3, 1,  6, 4, $04, $00
+	dsprite  3, 1,  7, 4, $05, $00
+	dsprite  3, 1,  8, 4, $06, $00
+	dsprite  3, 1,  9, 4, $07, $00
+	dsprite  0, 1, 11, 4, $00, $00
+	dsprite  0, 1, 12, 4, $01, $00
+	dsprite  0, 1, 13, 4, $02, $00
+	dsprite  0, 1, 14, 4, $03, $00
+	dsprite  1, 1, 11, 4, $04, $00
+	dsprite  1, 1, 12, 4, $05, $00
+	dsprite  1, 1, 13, 4, $06, $00
+	dsprite  1, 1, 14, 4, $07, $00
+
+; japanese mystery gift gfx
+MysteryGiftJP_GFX: ; 105930
+INCBIN "gfx/mystery_gift/mystery_gift_jp.2bpp"
--- /dev/null
+++ b/engine/mystery_gift_2.asm
@@ -1,0 +1,152 @@
+PrepMysteryGiftDataToSend: ; 2c642 (b:4642)
+	ld de, wMysteryGiftStaging
+	ld a, $1
+	ld [de], a
+	inc de ; wc801
+	ld a, BANK(sGameData)
+	call GetSRAMBank
+	ld hl, sPlayerData + PlayerID - wPlayerData
+	ld a, [hli]
+	ld [de], a
+	ld b, a
+	inc de ; wc802
+	ld a, [hl]
+	ld [de], a
+	ld c, a
+	inc de ; wc803
+	push bc
+	ld hl, sPlayerData + PlayerName - wPlayerData
+	ld bc, NAME_LENGTH
+	call CopyBytes
+	push de ; wc80e
+	ld hl, sPokemonData + PokedexCaught - wPokemonData
+	ld b, EndPokedexCaught - PokedexCaught
+	call CountSetBits
+	pop de
+	pop bc
+	ld a, [wd265]
+	ld [de], a
+	inc de ; wc80f
+	call CloseSRAM
+	call Random
+	and $1
+	ld [de], a
+	inc de ; wc810
+	call .RandomSample
+	ld [de], a
+	inc de ; wc811
+	ld a, c
+	ld c, b
+	ld b, a
+	call .RandomSample
+	ld [de], a
+	inc de ; wc812
+	ld a, BANK(sBackupMysteryGiftItem)
+	call GetSRAMBank
+	ld a, [sBackupMysteryGiftItem]
+	ld [de], a
+	inc de
+	ld a, [sBackupMysteryGiftItem + 1]
+	ld [de], a
+	ld a, $14
+	ld [wca00], a
+	call CloseSRAM
+	ld hl, wMysteryGiftStaging
+	ld de, wMysteryGiftPlayerData
+	ld bc, wMysteryGiftPlayerDataEnd - wMysteryGiftPlayerData
+	jp CopyBytes
+
+.RandomSample: ; 2c6ac (b:46ac)
+	push de
+	call Random
+	cp $19 ; 10 percent
+	jr c, .tenpercent
+	call Random
+	and $7
+	ld d, a
+	rl d
+	ld e, $80
+.loop
+	rlc e
+	dec a
+	jr nz, .loop
+	ld a, e
+	and c
+	jr z, .skip
+	ld a, $1
+.skip
+	add d
+	jr .done
+
+.tenpercent
+	call Random
+	cp $32 ; 20 percent
+	jr c, .twopercent
+	call Random
+	and $3
+	ld d, a
+	rl d
+	ld e, $80
+.loop2
+	rlc e
+	dec a
+	jr nz, .loop2
+	ld a, e
+	and b
+	jr z, .skip2
+	ld a, $1
+.skip2
+	add d
+	add $10
+	jr .done
+
+.twopercent
+	call Random
+	cp $32 ; 50 ; 20 percent
+	jr c, .pointfourpercent
+	ld a, b
+	swap a
+	and $7
+	add $18
+	jr .done
+
+.pointfourpercent
+	ld a, b
+	and $80
+	ld a, $20
+	jr z, .done
+	ld a, $21
+
+.done
+	pop de
+	ret
+
+MysteryGiftGetItemHeldEffect: ; 2c708 (b:4708)
+	ld a, c
+	cp MysteryGiftItemsEnd - MysteryGiftItems
+	jr nc, MysteryGiftFallbackItem
+	ld hl, MysteryGiftItems
+	ld b, 0
+	add hl, bc
+	ld c, [hl]
+	ret
+
+MysteryGiftGetDecoration: ; 2c715 (b:4715)
+	ld a, c
+	cp MysteryGiftDecosEnd - MysteryGiftDecos
+	jr nc, MysteryGiftFallbackItem
+	ld hl, MysteryGiftDecos
+	ld b, 0
+	add hl, bc
+	ld c, [hl]
+	ret
+
+MysteryGiftFallbackItem: ; 2c722 (b:4722)
+	ld c, DECO_POLKADOT_BED ; GREAT_BALL
+	ret
+; 2c725 (b:4725)
+
+
+INCLUDE "data/mystery_gift/items.asm"
+
+INCLUDE "data/mystery_gift/decos.asm"
--- a/engine/mysterygift.asm
+++ /dev/null
@@ -1,1735 +1,0 @@
-DoMysteryGift: ; 1048ba (41:48ba)
-	call ClearTileMap
-	call ClearSprites
-	call WaitBGMap
-	call InitMysteryGiftLayout
-	hlcoord 3, 8
-	ld de, .String_PressAToLink_BToCancel
-	call PlaceString
-	call WaitBGMap
-	callba PrepMysteryGiftDataToSend
-	call MysteryGift_ClearTrainerData
-	ld a, $2
-	ld [wca01], a
-	ld a, $14
-	ld [wca02], a
-	ld a, [rIE]
-	push af
-
-	call Function104a95
-
-	ld d, a
-	xor a
-	ld [rIF], a
-	pop af
-	ld [rIE], a
-	push de
-	call ClearTileMap
-	call EnableLCD
-	call WaitBGMap
-	ld b, SCGB_DIPLOMA
-	call GetSGBLayout
-	call SetPalettes
-	pop de
-	hlcoord 2, 8
-	ld a, d
-	ld de, .Text_LinkCanceled ; Link has been canceled
-	cp $10
-	jp z, .LinkCanceled
-	cp $6c
-	jp nz, .CommunicationError
-	ld a, [wc900]
-	cp 3
-	jr z, .skip_checks
-	call .CheckAlreadyGotFiveGiftsToday
-	ld hl, .Text_MaxFiveGifts ; Only 5 gifts a day
-	jp nc, .PrintTextAndExit
-	call .CheckAlreadyGotAGiftFromThatPerson
-	ld hl, .Text_MaxOneGiftPerPerson ; Only one gift a day per person
-	jp c, .PrintTextAndExit
-.skip_checks
-	ld a, [wMysteryGiftPlayerBackupItem]
-	and a
-	jp nz, .GiftWaiting
-	ld a, [wMysteryGiftPartnerBackupItem]
-	and a
-	jp nz, .FriendNotReady
-	ld a, [wc900]
-	cp 3
-	jr z, .skip_append_save
-	call .AddMysteryGiftPartnerID
-	ld a, [wc900]
-	cp 4
-	jr z, .skip_append_save
-	call .SaveMysteryGiftTrainerName
-	callba RestoreMobileEventIndex
-	callba TrainerRankings_MysteryGift
-	callba BackupMobileEventIndex
-.skip_append_save
-	ld a, [wMysteryGiftPartnerSentDeco]
-	and a
-	jr z, .item
-	ld a, [wMysteryGiftPartnerWhichDeco]
-	ld c, a
-	callba MysteryGiftGetDecoration
-	push bc
-	call MysteryGift_CheckAndSetDecorationAlreadyReceived
-	pop bc
-	jr nz, .item
-	callab GetDecorationName_c
-	ld h, d
-	ld l, e
-	ld de, StringBuffer1
-	ld bc, ITEM_NAME_LENGTH
-	call CopyBytes
-	ld hl, .Text_SentToHome ; sent decoration to home
-	jr .PrintTextAndExit
-
-.item
-	call GetMysteryGiftBank
-	ld a, [wMysteryGiftPartnerWhichItem]
-	ld c, a
-	callba MysteryGiftGetItemHeldEffect
-	ld a, c
-	ld [sBackupMysteryGiftItem], a
-	ld [wNamedObjectIndexBuffer], a
-	call CloseSRAM
-	call GetItemName
-	ld hl, .Text_Sent ; sent item
-	jr .PrintTextAndExit
-
-.LinkCanceled: ; 1049af (41:49af)
-	ld hl, .Text_LinkCanceled ; Link has been canceled
-	jr .PrintTextAndExit
-
-.CommunicationError: ; 1049b4 (41:49b4)
-	ld hl, .Text_CommunicationError ; Communication error
-	call PrintText
-	jp DoMysteryGift
-
-.GiftWaiting: ; 1049bd (41:49bd)
-	ld hl, .Text_ReceiveGiftAtCounter ; receive gift at counter
-	jr .PrintTextAndExit
-
-.FriendNotReady: ; 1049c2 (41:49c2)
-	ld hl, .Text_FriendNotReady ; friend not ready
-
-.PrintTextAndExit: ; 1049c5 (41:49c5)
-	call PrintText
-	ld a, $e3
-	ld [rLCDC], a
-	ret
-; 1049cd (41:49cd)
-
-.String_PressAToLink_BToCancel: ; 1049cd
-	db   "Press A to"
-	next "link IR-Device"
-	next "Press B to"
-	next "cancel it."
-	db   "@"
-; 1049fd
-
-.Text_LinkCanceled: ; 1049fd
-	text_jump UnknownText_0x1c0436
-	db "@"
-; 104a02
-
-.Text_CommunicationError: ; 104a02
-	text_jump UnknownText_0x1c0454
-	db "@"
-; 104a07
-
-.Text_ReceiveGiftAtCounter: ; 104a07
-	text_jump UnknownText_0x1c046a
-	db "@"
-; 104a0c
-
-.Text_FriendNotReady: ; 104a0c
-	text_jump UnknownText_0x1c048e
-	db "@"
-; 104a11
-
-.Text_MaxFiveGifts: ; 104a11
-	text_jump UnknownText_0x1c04a7
-	db "@"
-; 104a16
-
-.Text_MaxOneGiftPerPerson: ; 104a16
-	text_jump UnknownText_0x1c04c6
-	db "@"
-; 104a1b
-
-.Text_Sent: ; 104a1b
-	text_jump UnknownText_0x1c04e9
-	db "@"
-; 104a20
-
-.Text_SentToHome: ; 104a20
-	text_jump UnknownText_0x1c04fa
-	db "@"
-; 104a25
-
-.CheckAlreadyGotFiveGiftsToday: ; 104a25 (41:4a25)
-	call GetMysteryGiftBank
-	ld a, [sNumDailyMysteryGiftPartnerIDs]
-	cp $5
-	jp CloseSRAM
-
-.CheckAlreadyGotAGiftFromThatPerson: ; 104a30 (41:4a30)
-	call GetMysteryGiftBank
-	ld a, [wMysteryGiftPartnerID]
-	ld b, a
-	ld a, [wMysteryGiftPartnerID + 1]
-	ld c, a
-	ld a, [sNumDailyMysteryGiftPartnerIDs]
-	ld d, a
-	ld hl, sDailyMysteryGiftPartnerIDs
-.loop
-	ld a, d
-	and a
-	jr z, .No
-	ld a, [hli]
-	cp b
-	jr nz, .skip
-	ld a, [hl]
-	cp c
-	jr z, .Yes
-.skip
-	inc hl
-	dec d
-	jr .loop
-.Yes:
-	scf
-.No:
-	jp CloseSRAM
-
-.AddMysteryGiftPartnerID: ; 104a56 (41:4a56)
-	call GetMysteryGiftBank
-	ld hl, sNumDailyMysteryGiftPartnerIDs
-	ld a, [hl]
-	inc [hl]
-	ld hl, sDailyMysteryGiftPartnerIDs ; inc hl
-	ld e, a
-	ld d, $0
-	add hl, de
-	add hl, de
-	ld a, [wMysteryGiftPartnerID]
-	ld [hli], a
-	ld a, [wMysteryGiftPartnerID + 1]
-	ld [hl], a
-	jp CloseSRAM
-
-.SaveMysteryGiftTrainerName: ; 104a71 (41:4a71)
-	call GetMysteryGiftBank
-	ld a, $1
-	ld [sMysteryGiftTrainerHouseFlag], a
-	ld hl, wMysteryGiftPartnerName
-	ld de, sMysteryGiftPartnerName
-	ld bc, NAME_LENGTH
-	call CopyBytes
-	ld a, $1
-	ld [de], a
-	inc de
-	ld hl, wMysteryGiftTrainerData
-	ld bc, (1 + 1 + NUM_MOVES) * PARTY_LENGTH + 2
-	call CopyBytes
-	jp CloseSRAM
-
-Function104a95: ; 104a95 (41:4a95)
-	di
-	callba ClearChannels
-	call Function104d5e
-
-.loop2
-	call Function104d96
-	call Function104ddd
-	ld a, [hMGStatusFlags]
-	cp $10
-	jp z, Function104bd0
-	cp $6c
-	jr nz, .loop2
-
-	ld a, [hPrintNum9]
-	cp $2
-	jr z, Function104b22
-	ld hl, hPrintNum1
-	ld b, $1
-	call Function104d56
-	jr nz, .ly_loop
-	call Function104b49
-	jp nz, Function104bd0
-	jr Function104b0a
-	; Delay frame
-.ly_loop
-	ld a, [rLY]
-	cp $90
-	jr c, .ly_loop
-	ld c, rRP % $100
-	ld a, $c0
-	ld [$ff00+c], a
-	ld b, 240 ; This might have been intended as a 4-second timeout buffer.
-	          ; However, it is reset with each frame.
-.loop3
-	push bc
-	call MysteryGift_ReadJoypad
-
-	ld b, $2
-	ld c, rRP % $100
-	; Delay frame
-.ly_loop2
-	ld a, [$ff00+c]
-	and b
-	ld b, a
-	ld a, [rLY]
-	cp $90
-	jr nc, .ly_loop2
-.ly_loop3
-	ld a, [$ff00+c]
-	and b
-	ld b, a
-	ld a, [rLY]
-	cp $90
-	jr c, .ly_loop3
-
-	ld a, b
-	pop bc
-	dec b
-	jr z, .loop2 ; we never jump here
-	or a
-	jr nz, .loop2
-	; Check if we've pressed the B button
-	ld a, [hMGJoypadReleased]
-	bit B_BUTTON_F, a
-	jr z, .loop3
-	ld a, $10
-	ld [hMGStatusFlags], a
-	jp Function104bd0
-
-Function104b04: ; 104b04 (41:4b04)
-	call Function104b40
-	jp nz, Function104bd0
-Function104b0a: ; 104b0a (41:4b0a)
-	call Function104d38
-	jp nz, Function104bd0
-	call Function104b88
-	jp nz, Function104bd0
-	call Function104d43
-	jp nz, Function104bd0
-	call Function105033
-	jp Function104bd0
-
-Function104b22: ; 104b22 (41:4b22)
-	call Function104b88
-	jp nz, Function104bd0
-	call Function104d43
-	jp nz, Function104bd0
-	call Function104b40
-	jp nz, Function104bd0
-	call Function104d38
-	jp nz, Function104bd0
-	call Function10502e
-	jp Function104bd0
-
-Function104b40: ; 104b40 (41:4b40)
-	ld hl, hPrintNum1
-	ld b, $1
-	call Function104d56
-	ret nz
-
-Function104b49: ; 104b49 (41:4b49)
-	call Function105033
-	ld a, [hMGStatusFlags]
-	cp $6c
-	ret nz
-	ld a, [hPrintNum1]
-	cp $96
-	jp nz, Function104d32
-	ld a, $90
-	ld [hPrintNum1], a
-	call Function104d38
-	ret nz
-	ld hl, hPrintNum1
-	ld b, $1
-	call Function104d4e
-	ret nz
-	call Function10502e
-	ld a, [hMGStatusFlags]
-	cp $6c
-	ret nz
-	call Function104d43
-	ret nz
-	ld hl, wMysteryGiftTrainerData
-	ld a, [wca02]
-	ld b, a
-	call Function104d56
-	ret nz
-	call Function105033
-	ld a, [hMGStatusFlags]
-	cp $6c
-	ret
-
-Function104b88: ; 104b88 (41:4b88)
-	ld a, $96
-	ld [hPrintNum1], a
-	ld hl, hPrintNum1
-	ld b, $1
-	call Function104d4e
-	ret nz
-	call Function10502e
-	ld a, [hMGStatusFlags]
-	cp $6c
-	ret nz
-	call Function104d43
-	ret nz
-	ld hl, hPrintNum1
-	ld b, $1
-	call Function104d56
-	ret nz
-	call Function105033
-	ld a, [hMGStatusFlags]
-	cp $6c
-	ret nz
-	ld a, [hPrintNum1]
-	cp $90
-	jp nz, Function104d32
-	call Function104d38
-	ret nz
-	ld hl, OverworldMap
-	ld a, [wca02]
-	ld b, a
-	call Function104d4e
-	ret nz
-	call Function10502e
-	ld a, [hMGStatusFlags]
-	cp $6c
-	ret
-
-Function104bd0: ; 104bd0 (41:4bd0)
-	nop
-	ld a, [hMGStatusFlags]
-	cp $10
-	jr z, .quit
-	cp $6c
-	jr nz, .quit
-	ld hl, wca01
-	dec [hl]
-	jr z, .quit
-	ld hl, wMysteryGiftTrainerData
-	ld de, wMysteryGiftPartnerData
-	ld bc, wMysteryGiftPartnerDataEnd - wMysteryGiftPartnerData
-	call CopyBytes
-	ld a, [wMysteryGiftTrainerData]
-	cp $3
-	jr nc, .quit
-	callba StagePartyDataForMysteryGift
-	call MysteryGift_ClearTrainerData
-	ld a, $26
-	ld [wca02], a
-	ld a, [hPrintNum9]
-	cp $2
-	jr z, .asm_104c10
-	call Function104d43
-	jr nz, Function104bd0
-	jp Function104b04
-
-.asm_104c10
-	call Function104d38
-	jr nz, Function104bd0
-	jp Function104b22
-
-.quit
-	ld a, [hMGStatusFlags]
-	push af
-	call Function104da0
-	xor a
-	ld [rIF], a
-	ld a, [rIE]
-	or $1
-	ld [rIE], a
-	ei
-	call DelayFrame
-	pop af
-	ret
-
-Function104c2d: ; 104c2d (41:4c2d)
-	di
-	callba ClearChannels
-	call Function104d5e
-.asm_104c37
-	call Function104d96
-	call Function104ddd
-	ld a, [hMGStatusFlags]
-	cp $10
-	jp z, Function104d1c
-	cp $6c
-	jr nz, .asm_104c37
-	ld a, [hPrintNum9]
-	cp $2
-	jr z, .asm_104c6c
-	call Function104c8a
-	jp nz, Function104d1c
-	call Function104d38
-	jp nz, Function104d1c
-	call Function104cd2
-	jp nz, Function104d1c
-	call Function104d43
-	jp nz, Function104d1c
-	call Function105033
-	jp Function104d1c
-.asm_104c6c
-	call Function104cd2
-	jp nz, Function104d1c
-	call Function104d43
-	jp nz, Function104d1c
-	call Function104c8a
-	jp nz, Function104d1c
-	call Function104d38
-	jp nz, Function104d1c
-	call Function10502e
-	jp Function104d1c
-
-Function104c8a: ; 104c8a (41:4c8a)
-	ld hl, hPrintNum1
-	ld b, $1
-	call Function104d56
-	ret nz
-	call Function105033
-	ld a, [hMGStatusFlags]
-	cp $6c
-	ret nz
-	ld a, [hPrintNum1]
-	cp $3c
-	jp nz, Function104d32
-	swap a
-	ld [hPrintNum1], a
-	call Function104d38
-	ret nz
-	ld hl, hPrintNum1
-	ld b, $1
-	call Function104d4e
-	ret nz
-	call Function10502e
-	ld a, [hMGStatusFlags]
-	cp $6c
-	ret nz
-	call Function104d43
-	ret nz
-	ld hl, wMysteryGiftTrainerData
-	ld a, [wca02]
-	ld b, a
-	call Function104d56
-	ret nz
-	call Function105033
-	ld a, [hMGStatusFlags]
-	cp $6c
-	ret
-
-Function104cd2: ; 104cd2 (41:4cd2)
-	ld a, $3c
-	ld [hPrintNum1], a
-	ld hl, hPrintNum1
-	ld b, $1
-	call Function104d4e
-	ret nz
-	call Function10502e
-	ld a, [hMGStatusFlags]
-	cp $6c
-	ret nz
-	call Function104d43
-	ret nz
-	ld hl, hPrintNum1
-	ld b, $1
-	call Function104d56
-	ret nz
-	call Function105033
-	ld a, [hMGStatusFlags]
-	cp $6c
-	ret nz
-	ld a, [hPrintNum1]
-	swap a
-	cp $3c
-	jp nz, Function104d32
-	call Function104d38
-	ret nz
-	ld hl, OverworldMap
-	ld a, [wca02]
-	ld b, a
-	call Function104d4e
-	ret nz
-	call Function10502e
-	ld a, [hMGStatusFlags]
-	cp $6c
-	ret
-
-Function104d1c: ; 104d1c (41:4d1c)
-	nop
-	ld a, [hMGStatusFlags]
-	push af
-	call Function104da0
-	xor a
-	ld [rIF], a
-	ld a, [rIE]
-	or $1
-	ld [rIE], a
-	ei
-	call DelayFrame
-	pop af
-	ret
-
-Function104d32: ; 104d32 (41:4d32)
-	ld a, $80
-	ld [hMGStatusFlags], a
-	and a
-	ret
-
-Function104d38: ; 104d38 (41:4d38)
-	call Function104d96
-	call Function104e46
-	ld a, [hMGStatusFlags]
-	cp $6c
-	ret
-
-Function104d43: ; 104d43 (41:4d43)
-	call Function104d96
-	call Function104dfe
-	ld a, [hMGStatusFlags]
-	cp $6c
-	ret
-
-Function104d4e: ; 104d4e (41:4d4e)
-	call Function104e93
-	ld a, [hMGStatusFlags]
-	cp $6c
-	ret
-
-Function104d56: ; 104d56 (41:4d56)
-	call Function104f57
-	ld a, [hMGStatusFlags]
-	cp $6c
-	ret
-
-Function104d5e: ; 104d5e (41:4d5e)
-	call Function104d74
-	ld a, $4
-	ld [rIE], a
-	xor a
-	ld [rIF], a
-	call Function104d96
-	xor a
-	ld b, a
-.asm_104d6d
-	inc a
-	jr nz, .asm_104d6d
-	inc b
-	jr nz, .asm_104d6d
-	ret
-
-Function104d74: ; 104d74 (41:4d74)
-	xor a
-	ld [rTAC], a
-	ld a, $fe
-	ld [rTMA], a
-	ld [rTIMA], a
-	ld a, $2
-	ld [rTAC], a
-	or $4
-	ld [rTAC], a
-	ret
-
-Function104d86: ; 104d86 (41:4d86)
-	xor a
-	ld [rTAC], a
-	ld [rTMA], a
-	ld [rTIMA], a
-	ld a, $2
-	ld [rTAC], a
-	or $4
-	ld [rTAC], a
-	ret
-
-Function104d96: ; 104d96 (41:4d96)
-	ld a, $c0
-	call Function104e8c
-	ld a, $1
-	ld [hPrintNum9], a
-	ret
-
-Function104da0: ; 104da0 (41:4da0)
-	xor a
-	call Function104e8c
-	ld a, $2
-	ld [rTAC], a
-	ret
-
-Function104da9: ; 104da9 (41:4da9)
-	inc d
-	ret z
-	xor a
-	ld [rIF], a
-	halt
-	ld a, [$ff00+c]
-	bit 1, a
-	jr z, Function104da9
-	or a
-	ret
-
-Function104db7: ; 104db7 (41:4db7)
-	inc d
-	ret z
-	xor a
-	ld [rIF], a
-	halt
-	ld a, [$ff00+c]
-	bit 1, a
-	jr nz, Function104db7
-	or a
-	ret
-
-Function104dc5: ; 104dc5 (41:4dc5)
-	ld a, $c1
-	ld [$ff00+c], a
-.wait
-	dec d
-	ret z
-	xor a
-	ld [rIF], a
-	halt
-	jr .wait
-
-Function104dd1: ; 104dd1 (41:4dd1)
-	ld a, $c0
-	ld [$ff00+c], a
-.wait
-	dec d
-	ret z
-	xor a
-	ld [rIF], a
-	halt
-	jr .wait
-
-Function104ddd: ; 104ddd (41:4ddd)
-	ld d, $0
-	ld e, d
-	ld a, $1
-	ld [hPrintNum9], a
-.loop
-	call MysteryGift_ReadJoypad
-	ld b, $2
-	ld c, rRP % $100
-	ld a, [hMGJoypadReleased]
-	bit B_BUTTON_F, a
-	jr z, .next
-	ld a, $10
-	ld [hMGStatusFlags], a
-	ret
-
-.next
-	bit 0, a
-	jr nz, Function104e3a
-	ld a, [$ff00+c]
-	and b
-	jr nz, .loop
-
-Function104dfe: ; 104dfe (41:4dfe)
-	ld c, rRP % $100
-	ld d, $0
-	ld e, d
-	call Function104db7
-	jp z, Function104f42
-	ld d, e
-	call Function104da9
-	jp z, Function104f42
-	call Function104db7
-	jp z, Function104f42
-	call Function104da9
-	jp z, Function104f42
-	ld a, $6c
-	ld [hMGStatusFlags], a
-	ld d, $3d
-	call Function104dd1
-	ld d, $5
-	call Function104dc5
-	ld d, $15
-	call Function104dd1
-	ld d, $5
-	call Function104dc5
-	ld d, $5
-	call Function104dd1
-	ret
-
-Function104e3a: ; 104e3a (41:4e3a)
-	; Wait a random amount of time
-	call Random
-	ld e, a
-	and $f
-	ld d, a
-.loop
-	dec de
-	ld a, d
-	or e
-	jr nz, .loop
-Function104e46: ; 104e46 (41:4e46)
-	ld a, $2
-	ld [hPrintNum9], a
-	ld c, rRP % $100
-	ld d, $0
-	ld e, d
-	ld d, $3d
-	call Function104dd1
-	ld d, $5
-	call Function104dc5
-	ld d, $15
-	call Function104dd1
-	ld d, $5
-	call Function104dc5
-	ld d, $5
-	call Function104dd1
-	ld d, e
-	call Function104db7
-	jp z, Function104f42
-	ld d, e
-	call Function104da9
-	jp z, Function104f42
-	call Function104db7
-	jp z, Function104f42
-	call Function104da9
-	jp z, Function104f42
-	ld d, $3d
-	call Function104dd1
-	ld a, $6c
-	ld [hMGStatusFlags], a
-	ret
-
-Function104e8c: ; 104e8c (41:4e8c)
-	ld [rRP], a
-	ld a, $ff
-	ld [hMGStatusFlags], a
-	ret
-
-Function104e93: ; 104e93 (41:4e93)
-	xor a
-	ld [hPrintNum5], a
-	ld [hPrintNum6], a
-	push hl
-	push bc
-	ld c, rRP % $100
-	ld d, $3d
-	call Function104dd1
-	ld hl, hPrintNum2
-	ld a, $5a
-	ld [hli], a
-	ld [hl], b
-	dec hl
-	ld b, $2
-	call Function104ed6
-	pop bc
-	pop hl
-	call Function104ed6
-	ld a, [hPrintNum5]
-	ld [hPrintNum2], a
-	ld a, [hPrintNum6]
-	ld [hPrintNum3], a
-	push hl
-	ld hl, hPrintNum2
-	ld b, $2
-	call Function104ed6
-	ld hl, hMGStatusFlags
-	ld b, $1
-	call Function104faf
-	ld a, [hPrintNum2]
-	ld [hPrintNum5], a
-	ld a, [hPrintNum3]
-	ld [hPrintNum6], a
-	pop hl
-	ret
-
-Function104ed6: ; 104ed6 (41:4ed6)
-	ld c, rRP % $100
-	ld d, $5
-	call Function104dd1
-	ld d, $5
-	call Function104dc5
-	ld d, $15
-	call Function104dd1
-	ld a, b
-	cpl
-	ld b, a
-	ld a, $f4
-	ld [rTMA], a
-.asm_104eee
-	inc b
-	jr z, .asm_104f2e
-	ld a, $8
-	ld [hPrintNum4], a
-	ld a, [hli]
-	ld e, a
-	ld a, [hPrintNum5]
-	add e
-	ld [hPrintNum5], a
-	ld a, [hPrintNum6]
-	adc $0
-	ld [hPrintNum6], a
-.asm_104f02
-	xor a
-	ld [rIF], a
-	halt
-	ld a, $c1
-	ld [rRP], a
-	ld d, $1
-	ld a, e
-	rlca
-	ld e, a
-	jr nc, .asm_104f13
-	inc d
-.asm_104f13
-	ld a, [rTIMA]
-	cp $f8
-	jr c, .asm_104f13
-	ld a, $c0
-	ld [rRP], a
-	dec d
-	jr z, .asm_104f25
-	xor a
-	ld [rIF], a
-	halt
-.asm_104f25
-	ld a, [hPrintNum4]
-	dec a
-	jr z, .asm_104eee
-	ld [hPrintNum4], a
-	jr .asm_104f02
-.asm_104f2e
-	ld a, $fe
-	ld [rTMA], a
-	xor a
-	ld [rIF], a
-	halt
-	ld d, $5
-	call Function104dc5
-	ld d, $11
-	call Function104dd1
-	ret
-
-Function104f42: ; 104f42 (41:4f42)
-	ld a, [hMGStatusFlags]
-	or $2
-	ld [hMGStatusFlags], a
-	ret
-
-Function104f49: ; 104f49 (41:4f49)
-	ld a, [hMGStatusFlags]
-	or $1
-	ld [hMGStatusFlags], a
-	ret
-
-Function104f50: ; 104f50 (41:4f50)
-	ld a, [hMGStatusFlags]
-	or $80
-	ld [hMGStatusFlags], a
-	ret
-
-Function104f57: ; 104f57 (41:4f57)
-	xor a
-	ld [hPrintNum5], a
-	ld [hPrintNum6], a
-	push bc
-	push hl
-	ld hl, hPrintNum2
-	ld b, $2
-	call Function104faf
-	ld a, [hPrintNum3]
-	ld [hPrintNum8], a
-	ld b, a
-	pop hl
-	pop af
-	cp b
-	jp c, Function104f50
-	ld a, [hPrintNum2]
-	cp $5a
-	jp nz, Function104f50
-	call Function104faf
-	ld a, [hPrintNum5]
-	ld d, a
-	ld a, [hPrintNum6]
-	ld e, a
-	push hl
-	push de
-	ld hl, hPrintNum2
-	ld b, $2
-	call Function104faf
-	pop de
-	ld hl, hPrintNum2
-	ld a, [hli]
-	xor d
-	ld b, a
-	ld a, [hl]
-	xor e
-	or b
-	call nz, Function104f49
-	push de
-	ld d, $3d
-	call Function104dd1
-	ld hl, hMGStatusFlags
-	ld b, $1
-	call Function104ed6
-	pop de
-	pop hl
-	ld a, d
-	ld [hPrintNum5], a
-	ld a, e
-	ld [hPrintNum6], a
-	ret
-
-Function104faf: ; 104faf (41:4faf)
-	ld c, rRP % $100
-	ld d, $0
-	call Function104db7
-	jp z, Function104f42
-	ld d, $0
-	call Function104da9
-	jp z, Function104f42
-	ld d, $0
-	call Function104db7
-	jp z, Function104f42
-	ld a, b
-	cpl
-	ld b, a
-	xor a
-	ld [hMGJoypadPressed + 2], a
-	call Function104d86
-.asm_104fd2
-	inc b
-	jr z, .asm_10501a
-	ld a, $8
-	ld [hPrintNum4], a
-.asm_104fd9
-	ld d, $0
-.asm_104fdb
-	inc d
-	jr z, .asm_104fe5
-	ld a, [$ff00+c]
-	bit 1, a
-	jr z, .asm_104fdb
-	ld d, $0
-.asm_104fe5
-	inc d
-	jr z, .asm_104fed
-	ld a, [$ff00+c]
-	bit 1, a
-	jr nz, .asm_104fe5
-.asm_104fed
-	ld a, [hMGJoypadPressed + 2]
-	ld d, a
-	ld a, [rTIMA]
-	ld [hMGJoypadPressed + 2], a
-	sub d
-	cp $12
-	jr c, .asm_104ffd
-	set 0, e
-	jr .asm_104fff
-.asm_104ffd
-	res 0, e
-.asm_104fff
-	ld a, [hPrintNum4]
-	dec a
-	ld [hPrintNum4], a
-	jr z, .asm_10500b
-	ld a, e
-	rlca
-	ld e, a
-	jr .asm_104fd9
-.asm_10500b
-	ld a, e
-	ld [hli], a
-	ld a, [hPrintNum5]
-	add e
-	ld [hPrintNum5], a
-	ld a, [hPrintNum6]
-	adc $0
-	ld [hPrintNum6], a
-	jr .asm_104fd2
-.asm_10501a
-	call Function104d74
-	xor a
-	ld [rIF], a
-	ld d, $0
-	call Function104da9
-	jp z, Function104f42
-	ld d, $10
-	call Function104dd1
-	ret
-
-Function10502e: ; 10502e (41:502e)
-	ld b, $0
-	jp Function104e93
-
-Function105033: ; 105033 (41:5033)
-	ld b, $0
-	jp Function104f57
-
-MysteryGift_ReadJoypad: ; 105038 (41:5038)
-; We can only get four inputs at a time.
-; We take d-pad first for no particular reason.
-	ld a, R_DPAD
-	ld [rJOYP], a
-; Read twice to give the request time to take.
-	ld a, [rJOYP]
-	ld a, [rJOYP]
-
-; The Joypad register output is in the lo nybble (inversed).
-; We make the hi nybble of our new container d-pad input.
-	cpl
-	and $f
-	swap a
-
-; We'll keep this in b for now.
-	ld b, a
-
-; Buttons make 8 total inputs (A, B, Select, Start).
-; We can fit this into one byte.
-	ld a, R_BUTTONS
-	ld [rJOYP], a
-; Wait for input to stabilize.
-rept 6
-	ld a, [rJOYP]
-endr
-; Buttons take the lo nybble.
-	cpl
-	and $f
-	or b
-	ld c, a
-; To get the delta we xor the last frame's input with the new one.
-	ld a, [hMGJoypadPressed]
-	xor c
-; Released this frame:
-	and c
-	ld [hMGJoypadReleased], a
-; Pressed this frame:
-	ld a, c
-	ld [hMGJoypadPressed], a
-	ld a, $30
-; Reset the joypad register since we're done with it.
-	ld [rJOYP], a
-	ret
-
-MysteryGift_CheckAndSetDecorationAlreadyReceived: ; 105069 (41:5069)
-	call GetMysteryGiftBank
-	ld d, $0
-	ld b, CHECK_FLAG
-	ld hl, sMysteryGiftDecorationsReceived
-	predef_id FlagPredef
-	push hl
-	push bc
-	call Predef
-	call CloseSRAM
-	ld a, c
-	and a
-	pop bc
-	pop hl
-	ret nz
-	call GetMysteryGiftBank
-	ld b, SET_FLAG
-	predef FlagPredef
-	call CloseSRAM
-	xor a
-	ret
-
-MysteryGift_CopyReceivedDecosToPC: ; 105091 (41:5091)
-	call GetMysteryGiftBank
-	ld c, $0
-.loop
-	push bc
-	ld d, $0
-	ld b, CHECK_FLAG
-	ld hl, sMysteryGiftDecorationsReceived
-	predef FlagPredef
-	ld a, c
-	and a
-	pop bc
-	jr z, .skip
-	push bc
-	callab SetSpecificDecorationFlag
-	pop bc
-.skip
-	inc c
-	ld a, c
-	cp Trophys - DecorationIDs
-	jr c, .loop
-	jp CloseSRAM
-
-Special_UnlockMysteryGift: ; 1050b9
-	call GetMysteryGiftBank
-	ld hl, sMysteryGiftUnlocked
-	ld a, [hl]
-	inc a
-	jr nz, .ok
-	ld [hld], a
-	ld [hl], a
-.ok
-	jp CloseSRAM
-; 1050c8
-
-Function1050c8: ; 1050c8
-	call GetMysteryGiftBank
-	ld a, [sNumDailyMysteryGiftPartnerIDs]
-	cp $ff
-	jr z, .okay
-	xor a
-	ld [sNumDailyMysteryGiftPartnerIDs], a
-.okay
-	jp CloseSRAM
-; 1050d9
-
-
-BackupMysteryGift: ; 1050d9
-	call GetMysteryGiftBank
-	ld hl, sMysteryGiftItem
-	ld de, sBackupMysteryGiftItem
-	ld a, [hli]
-	ld [de], a
-	inc de
-	ld a, [hl]
-	ld [de], a
-	jp CloseSRAM
-; 1050ea
-
-
-RestoreMysteryGift: ; 1050ea (41:50ea)
-	call GetMysteryGiftBank
-	ld hl, sBackupMysteryGiftItem
-	ld de, sMysteryGiftItem
-	ld a, [hli]
-	ld [de], a
-	inc de
-	ld a, [hl]
-	ld [de], a
-	jp CloseSRAM
-
-MysteryGift_ClearTrainerData: ; 1050fb (41:50fb)
-	ld hl, wMysteryGiftTrainerData
-	xor a
-	ld b, wMysteryGiftTrainerDataEnd - wMysteryGiftTrainerData
-.loop
-	ld [hli], a
-	dec b
-	jr nz, .loop
-	ret
-
-
-GetMysteryGiftBank: ; 105106
-	ld a, BANK(sBackupMysteryGiftItem)
-	jp GetSRAMBank
-; 10510b
-
-
-StagePartyDataForMysteryGift: ; 10510b (41:510b)
-; You will be sending this data to your mystery gift partner.
-; Structure is the same as a trainer with species and moves
-; defined.
-	ld a, BANK(sPokemonData)
-	call GetSRAMBank
-	ld de, wMysteryGiftStaging
-	ld bc, sPokemonData + PartyMons - wPokemonData
-	ld hl, sPokemonData + PartySpecies - wPokemonData
-.loop
-	ld a, [hli]
-	cp -1
-	jr z, .party_end
-	cp EGG
-	jr z, .next
-	push hl
-	; copy level
-	ld hl, MON_LEVEL
-	add hl, bc
-	ld a, [hl]
-	ld [de], a
-	inc de
-	; copy species
-	ld hl, MON_SPECIES
-	add hl, bc
-	ld a, [hl]
-	ld [de], a
-	inc de
-	; copy moves
-	ld hl, MON_MOVES
-	add hl, bc
-	push bc
-	ld bc, NUM_MOVES
-	call CopyBytes
-	pop bc
-	pop hl
-.next
-	push hl
-	ld hl, PARTYMON_STRUCT_LENGTH
-	add hl, bc
-	ld b, h
-	ld c, l
-	pop hl
-	jr .loop
-.party_end
-	ld a, -1
-	ld [de], a
-	ld a, $26
-	ld [wca00], a
-	jp CloseSRAM
-
-InitMysteryGiftLayout: ; 105153 (41:5153)
-	call ClearBGPalettes
-	call DisableLCD
-	ld hl, MysteryGiftGFX
-	ld de, VTiles2 tile $00
-	ld a, BANK(MysteryGiftGFX)
-	ld bc, MysteryGiftGFXEnd - MysteryGiftGFX
-	call FarCopyBytes
-	hlcoord 0, 0
-	ld a, $42
-	ld bc, SCREEN_HEIGHT * SCREEN_WIDTH
-	call ByteFill
-	hlcoord 3, 7
-	lb bc, 9, 15
-	call ClearBox
-	hlcoord 0, 0
-	ld a, $0
-	ld [hli], a
-	inc a
-	ld [hl], a
-	hlcoord 0, 1
-	inc a
-	ld [hli], a
-	inc a
-	ld [hl], a
-	hlcoord 7, 1
-	ld a, $12
-	call .Load5GFX
-	hlcoord 2, 2
-	ld a, $17
-	call .Load16GFX
-	hlcoord 2, 3
-	ld a, $27
-	call .Load16GFX
-	hlcoord 9, 4
-	ld a, $37
-	ld [hli], a
-	inc a
-	ld [hl], a
-	hlcoord 1, 2
-	ld [hl], $4
-	hlcoord 1, 3
-	ld a, $5
-	call .Load14Column
-	ld a, $9
-	hlcoord 18, 5
-	call .Load11Column
-	hlcoord 2, 5
-	ld a, $b
-	call .Load16Row
-	hlcoord 2, 16
-	ld a, $7
-	call .Load16Row
-	hlcoord 2, 5
-	ld a, $d
-	call .Load5GFX
-	hlcoord 7, 5
-	ld [hl], $c
-	hlcoord 18, 5
-	ld [hl], $a
-	hlcoord 18, 16
-	ld [hl], $8
-	hlcoord 1, 16
-	ld [hl], $6
-	hlcoord 2, 6
-	ld a, $3a
-	call .Load16Row
-	hlcoord 2, 15
-	ld a, $40
-	call .Load16Row
-	hlcoord 2, 6
-	ld a, $3c
-	call .Load9Column
-	hlcoord 17, 6
-	ld a, $3e
-	call .Load9Column
-	hlcoord 2, 6
-	ld [hl], $39
-	hlcoord 17, 6
-	ld [hl], $3b
-	hlcoord 2, 15
-	ld [hl], $3f
-	hlcoord 17, 15
-	ld [hl], $41
-	call EnableLCD
-	call WaitBGMap
-	ld b, SCGB_MYSTERY_GIFT
-	call GetSGBLayout
-	call SetPalettes
-	ret
-
-.Load5GFX: ; 10522e (41:522e)
-	ld b,  5
-	jr .gfx_loop
-; 105232 (41:5232)
-
-.Load6GFX: ; unreferenced
-	ld b,  6
-	jr .gfx_loop
-
-.Load16GFX: ; 105236 (41:5236)
-	ld b, 16
-
-.gfx_loop ; 105238 (41:5238)
-	ld [hli], a
-	inc a
-	dec b
-	jr nz, .gfx_loop
-	ret
-
-.Load9Column: ; 10523e (41:523e)
-	ld b,  9
-	jr .col_loop
-
-.Load11Column: ; 105242 (41:5242)
-	ld b, 11
-	jr .col_loop
-
-.Load14Column: ; 105246 (41:5246)
-	ld b, 14
-
-.col_loop ; 105248 (41:5248)
-	ld [hl], a
-	ld de, SCREEN_WIDTH
-	add hl, de
-	dec b
-	jr nz, .col_loop
-	ret
-
-.Load16Row: ; 105251 (41:5251)
-	ld b, 16
-.row_loop
-	ld [hli], a
-	dec b
-	jr nz, .row_loop
-	ret
-
-MysteryGiftGFX: ; 105258
-INCBIN "gfx/mystery_gift/mystery_gift.2bpp"
-MysteryGiftGFXEnd:
-
-Function105688: ; 105688 (41:5688)
-	call ClearTileMap
-	call ClearSprites
-	call WaitBGMap
-	call Function1057d7
-	hlcoord 3, 8
-	ld de, String_10572e
-	call PlaceString
-	call WaitBGMap
-	call Function10578c
-	call MysteryGift_ClearTrainerData
-	ld a, $24
-	ld [wca02], a
-	ld a, [rIE]
-	push af
-	call Function104c2d
-	ld d, a
-	xor a
-	ld [rIF], a
-	pop af
-	ld [rIE], a
-	ld a, d
-	cp $10
-	jp z, Function105712
-	cp $6c
-	jp nz, Function10571a
-	call Function1056eb
-	ld c, 60
-	call DelayFrames
-	call Function105777
-	ld hl, Text_ReceivedCard
-	call PrintText
-	ld de, wMysteryGiftTrainerData
-	callba Function8ac70
-	ld a, c
-	ld [wd265], a
-	ld hl, Text_CardNotRegistered
-	jr c, asm_105726
-	ld hl, Text_ListedCardAsNumber
-	jr asm_105726
-
-Function1056eb: ; 1056eb (41:56eb)
-	ld c, $10
-.asm_1056ed
-	ld hl, Sprites
-	ld b, $8
-.asm_1056f2
-	dec [hl]
-rept 4
-	inc hl
-endr
-	dec b
-	jr nz, .asm_1056f2
-	ld hl, Sprites + $20
-	ld b, $8
-.asm_1056ff
-	inc [hl]
-rept 4
-	inc hl
-endr
-	dec b
-	jr nz, .asm_1056ff
-	dec c
-	ret z
-	push bc
-	ld c, 4
-	call DelayFrames
-	pop bc
-	jr .asm_1056ed
-
-Function105712: ; 105712 (41:5712)
-	call Function105777
-	ld hl, Text_MGLinkCanceled
-	jr asm_105726
-
-Function10571a: ; 10571a (41:571a)
-	call Function105777
-	ld hl, Text_MGCommError
-	call PrintText
-	jp Function105688
-
-asm_105726: ; 105726 (41:5726)
-	call PrintText
-	ld a, $e3
-	ld [rLCDC], a
-	ret
-; 10572e (41:572e)
-
-String_10572e: ; 10572e
-	db   "エーボタン¯おすと"
-	next "つうしん<PKMN>おこなわれるよ!"
-	next "ビーボタン¯おすと"
-	next "つうしん¯ちゅうし します"
-	db   "@"
-
-; 10575e
-
-Text_ReceivedCard: ; 10575e
-	text_jump UnknownText_0x1c051a
-	db "@"
-
-Text_ListedCardAsNumber: ; 105763
-	text_jump UnknownText_0x1c0531
-	db "@"
-
-Text_CardNotRegistered: ; 105768
-	text_jump UnknownText_0x1c0555
-	db "@"
-
-Text_MGLinkCanceled: ; 10576d
-	text_jump UnknownText_0x1c0573
-	db "@"
-
-Text_MGCommError: ; 105772
-	text_jump UnknownText_0x1c0591
-	db "@"
-; 105777
-
-Function105777: ; 105777 (41:5777)
-	call ClearSprites
-	call ClearTileMap
-	call EnableLCD
-	call WaitBGMap
-	ld b, SCGB_DIPLOMA
-	call GetSGBLayout
-	call SetPalettes
-	ret
-
-Function10578c: ; 10578c (41:578c)
-	ld de, OverworldMap
-	ld a, BANK(sPlayerData)
-	call GetSRAMBank
-	ld hl, sPlayerData + PlayerName - wPlayerData
-	ld bc, NAME_LENGTH
-	call CopyBytes
-	ld hl, sPlayerData + PlayerID - wPlayerData
-	ld bc, 2
-	call CopyBytes
-	ld hl, sPlayerData + wSecretID - wPlayerData
-	ld bc, 2
-	call CopyBytes
-	call CloseSRAM
-	ld a, BANK(sCrystalData)
-	call GetSRAMBank
-	ld a, [sCrystalData + 0]
-	ld [de], a
-	inc de
-	ld a, $4
-	call GetSRAMBank
-	ld hl, $a603
-	ld bc, $8
-	call CopyBytes
-	ld hl, $a007
-	ld bc, $c
-	call CopyBytes
-	call CloseSRAM
-	ret
-
-Function1057d7: ; 1057d7 (41:57d7)
-	call ClearBGPalettes
-	call DisableLCD
-	ld hl, MysteryGiftJP_GFX
-	ld de, VTiles2 tile $00
-	ld a, BANK(MysteryGiftJP_GFX)
-	lb bc, 4, 0
-	call FarCopyBytes
-	ld hl, MysteryGiftJP_GFX + $400
-	ld de, VTiles0 tile $00
-	ld a, BANK(MysteryGiftJP_GFX)
-	ld bc, $80
-	call FarCopyBytes
-	hlcoord 0, 0
-	ld a, $3f
-	ld bc, SCREEN_HEIGHT * SCREEN_WIDTH
-	call ByteFill
-	hlcoord 3, 7
-	lb bc, 9, 15
-	call ClearBox
-	hlcoord 0, 0
-	ld a, $0
-	ld [hli], a
-	inc a
-	ld [hl], a
-	hlcoord 0, 1
-	inc a
-	ld [hli], a
-	inc a
-	ld [hl], a
-	hlcoord 4, 2
-	ld a, $13
-	call .Load11Row
-	hlcoord 4, 3
-	ld a, $1e
-	call .Load12Row
-	hlcoord 4, 4
-	ld a, $2a
-	call .Load12Row
-	hlcoord 1, 2
-	ld [hl], $4
-	hlcoord 1, 3
-	ld a, $5
-	call .Load14Column
-	ld a, $9
-	hlcoord 18, 5
-	call .Load11Column
-	hlcoord 2, 5
-	ld a, $b
-	call .Load16Row
-	hlcoord 2, 16
-	ld a, $7
-	call .Load16Row
-	hlcoord 2, 5
-	ld a, $d
-	call .Load6Row
-	hlcoord 8, 5
-	ld [hl], $c
-	hlcoord 18, 5
-	ld [hl], $a
-	hlcoord 18, 16
-	ld [hl], $8
-	hlcoord 1, 16
-	ld [hl], $6
-	hlcoord 2, 6
-	ld a, $37
-	call .Load16Row
-	hlcoord 2, 15
-	ld a, $3d
-	call .Load16Row
-	hlcoord 2, 6
-	ld a, $39
-	call .Load9Column
-	hlcoord 17, 6
-	ld a, $3b
-	call .Load9Column
-	hlcoord 2, 6
-	ld [hl], $36
-	hlcoord 17, 6
-	ld [hl], $38
-	hlcoord 2, 15
-	ld [hl], $3c
-	hlcoord 17, 15
-	ld [hl], $3e
-	ld de, Sprites
-	ld hl, .OAM_data
-	ld bc, $40
-	call CopyBytes
-	call EnableLCD
-	call WaitBGMap
-	ld b, $2
-	callba GetMysteryGift_MobileAdapterLayout
-	jp SetPalettes
-
-.Load6Row: ; 1058c6 (41:58c6)
-	ld b,  6
-	jr .row_loop
-
-.Load11Row: ; 1058ca (41:58ca)
-	ld b, 11
-	jr .row_loop
-
-.Load12Row: ; 1058ce (41:58ce)
-	ld b, 12
-
-.row_loop ; 1058d0 (41:58d0)
-	ld [hli], a
-	inc a
-	dec b
-	jr nz, .row_loop
-	ret
-
-.Load9Column: ; 1058d6 (41:58d6)
-	ld b,  9
-	jr .column_loop
-
-.Load11Column: ; 1058da (41:58da)
-	ld b, 11
-	jr .column_loop
-
-.Load14Column: ; 1058de (41:58de)
-	ld b, 14
-
-.column_loop ; 1058e0 (41:58e0)
-	ld [hl], a
-	ld de, SCREEN_WIDTH
-	add hl, de
-	dec b
-	jr nz, .column_loop
-	ret
-
-.Load16Row: ; 1058e9 (41:58e9)
-	ld b, 16
-.row_loop_no_inc
-	ld [hli], a
-	dec b
-	jr nz, .row_loop_no_inc
-	ret
-; 1058f0 (41:58f0)
-
-.OAM_data: ; 1058f0
-	dsprite  2, 1,  6, 4, $00, $00
-	dsprite  2, 1,  7, 4, $01, $00
-	dsprite  2, 1,  8, 4, $02, $00
-	dsprite  2, 1,  9, 4, $03, $00
-	dsprite  3, 1,  6, 4, $04, $00
-	dsprite  3, 1,  7, 4, $05, $00
-	dsprite  3, 1,  8, 4, $06, $00
-	dsprite  3, 1,  9, 4, $07, $00
-	dsprite  0, 1, 11, 4, $00, $00
-	dsprite  0, 1, 12, 4, $01, $00
-	dsprite  0, 1, 13, 4, $02, $00
-	dsprite  0, 1, 14, 4, $03, $00
-	dsprite  1, 1, 11, 4, $04, $00
-	dsprite  1, 1, 12, 4, $05, $00
-	dsprite  1, 1, 13, 4, $06, $00
-	dsprite  1, 1, 14, 4, $07, $00
-
-; japanese mystery gift gfx
-MysteryGiftJP_GFX: ; 105930
-INCBIN "gfx/mystery_gift/mystery_gift_jp.2bpp"
--- a/engine/mysterygift2.asm
+++ /dev/null
@@ -1,152 +1,0 @@
-PrepMysteryGiftDataToSend: ; 2c642 (b:4642)
-	ld de, wMysteryGiftStaging
-	ld a, $1
-	ld [de], a
-	inc de ; wc801
-	ld a, BANK(sGameData)
-	call GetSRAMBank
-	ld hl, sPlayerData + PlayerID - wPlayerData
-	ld a, [hli]
-	ld [de], a
-	ld b, a
-	inc de ; wc802
-	ld a, [hl]
-	ld [de], a
-	ld c, a
-	inc de ; wc803
-	push bc
-	ld hl, sPlayerData + PlayerName - wPlayerData
-	ld bc, NAME_LENGTH
-	call CopyBytes
-	push de ; wc80e
-	ld hl, sPokemonData + PokedexCaught - wPokemonData
-	ld b, EndPokedexCaught - PokedexCaught
-	call CountSetBits
-	pop de
-	pop bc
-	ld a, [wd265]
-	ld [de], a
-	inc de ; wc80f
-	call CloseSRAM
-	call Random
-	and $1
-	ld [de], a
-	inc de ; wc810
-	call .RandomSample
-	ld [de], a
-	inc de ; wc811
-	ld a, c
-	ld c, b
-	ld b, a
-	call .RandomSample
-	ld [de], a
-	inc de ; wc812
-	ld a, BANK(sBackupMysteryGiftItem)
-	call GetSRAMBank
-	ld a, [sBackupMysteryGiftItem]
-	ld [de], a
-	inc de
-	ld a, [sBackupMysteryGiftItem + 1]
-	ld [de], a
-	ld a, $14
-	ld [wca00], a
-	call CloseSRAM
-	ld hl, wMysteryGiftStaging
-	ld de, wMysteryGiftPlayerData
-	ld bc, wMysteryGiftPlayerDataEnd - wMysteryGiftPlayerData
-	jp CopyBytes
-
-.RandomSample: ; 2c6ac (b:46ac)
-	push de
-	call Random
-	cp $19 ; 10 percent
-	jr c, .tenpercent
-	call Random
-	and $7
-	ld d, a
-	rl d
-	ld e, $80
-.loop
-	rlc e
-	dec a
-	jr nz, .loop
-	ld a, e
-	and c
-	jr z, .skip
-	ld a, $1
-.skip
-	add d
-	jr .done
-
-.tenpercent
-	call Random
-	cp $32 ; 20 percent
-	jr c, .twopercent
-	call Random
-	and $3
-	ld d, a
-	rl d
-	ld e, $80
-.loop2
-	rlc e
-	dec a
-	jr nz, .loop2
-	ld a, e
-	and b
-	jr z, .skip2
-	ld a, $1
-.skip2
-	add d
-	add $10
-	jr .done
-
-.twopercent
-	call Random
-	cp $32 ; 50 ; 20 percent
-	jr c, .pointfourpercent
-	ld a, b
-	swap a
-	and $7
-	add $18
-	jr .done
-
-.pointfourpercent
-	ld a, b
-	and $80
-	ld a, $20
-	jr z, .done
-	ld a, $21
-
-.done
-	pop de
-	ret
-
-MysteryGiftGetItemHeldEffect: ; 2c708 (b:4708)
-	ld a, c
-	cp MysteryGiftItemsEnd - MysteryGiftItems
-	jr nc, MysteryGiftFallbackItem
-	ld hl, MysteryGiftItems
-	ld b, 0
-	add hl, bc
-	ld c, [hl]
-	ret
-
-MysteryGiftGetDecoration: ; 2c715 (b:4715)
-	ld a, c
-	cp MysteryGiftDecosEnd - MysteryGiftDecos
-	jr nc, MysteryGiftFallbackItem
-	ld hl, MysteryGiftDecos
-	ld b, 0
-	add hl, bc
-	ld c, [hl]
-	ret
-
-MysteryGiftFallbackItem: ; 2c722 (b:4722)
-	ld c, DECO_POLKADOT_BED ; GREAT_BALL
-	ret
-; 2c725 (b:4725)
-
-
-INCLUDE "data/mystery_gift/items.asm"
-
-INCLUDE "data/mystery_gift/decos.asm"
--- /dev/null
+++ b/engine/pack_f.asm
@@ -1,0 +1,20 @@
+DrawKrisPackGFX: ; 48e81
+	ld hl, PackFGFXPointers
+	add hl, de
+	add hl, de
+	ld a, [hli]
+	ld e, a
+	ld d, [hl]
+	ld hl, VTiles2 tile $50
+	lb bc, BANK(PackFGFX), 15
+	call Request2bpp
+	ret
+
+PackFGFXPointers: ; 48e93
+	dw PackFGFX + (15 tiles) * 1
+	dw PackFGFX + (15 tiles) * 3
+	dw PackFGFX + (15 tiles) * 0
+	dw PackFGFX + (15 tiles) * 2
+
+PackFGFX: ; 48e9b
+INCBIN "gfx/pack/pack_f.2bpp"
--- /dev/null
+++ b/engine/place_graphics.asm
@@ -1,0 +1,56 @@
+PlaceGraphic: ; 2ef6e
+; Fill wBoxAlignment-aligned box width b height c
+; with iterating tile starting from hGraphicStartTile at hl.
+; Predef $13
+
+	ld de, SCREEN_WIDTH
+
+	ld a, [wBoxAlignment]
+	and a
+	jr nz, .right
+
+	ld a, [hGraphicStartTile]
+.x1
+	push bc
+	push hl
+
+.y1
+	ld [hl], a
+	add hl, de
+	inc a
+	dec c
+	jr nz, .y1
+
+	pop hl
+	inc hl
+	pop bc
+	dec b
+	jr nz, .x1
+	ret
+
+.right
+; Right-aligned.
+	push bc
+	ld b, 0
+	dec c
+	add hl, bc
+	pop bc
+
+	ld a, [hGraphicStartTile]
+.x2
+	push bc
+	push hl
+
+.y2
+	ld [hl], a
+	add hl, de
+	inc a
+	dec c
+	jr nz, .y2
+
+	pop hl
+	dec hl
+	pop bc
+	dec b
+	jr nz, .x2
+	ret
--- /dev/null
+++ b/engine/pokegear_2.asm
@@ -1,0 +1,25 @@
+TownMap_ConvertLineBreakCharacters: ; 1de2c5
+	ld hl, StringBuffer1
+.loop
+	ld a, [hl]
+	cp "@"
+	jr z, .end
+	cp "%"
+	jr z, .line_break
+	cp "¯"
+	jr z, .line_break
+	inc hl
+	jr .loop
+
+.line_break
+	ld [hl], "<LNBRK>"
+
+.end
+	ld de, StringBuffer1
+	hlcoord 9, 0
+	call PlaceString
+	ret
+
+
+PokegearGFX: ; 1de2e4
+INCBIN "gfx/pokegear/pokegear.2bpp.lz"
--- /dev/null
+++ b/engine/printhoursmins.asm
@@ -1,0 +1,64 @@
+Function1dd6a9: ; 1dd6a9
+; XXX
+	ld a, b
+	ld b, c
+	ld c, a
+	push bc
+	push de
+	ld hl, sp+$2
+	ld d, h
+	ld e, l
+	pop hl
+	lb bc, PRINTNUM_LEADINGZEROS | 2, 5
+	call PrintNum
+	pop bc
+	ret
+
+PrintHoursMins ; 1dd6bb (77:56bb)
+; Hours in b, minutes in c
+	ld a, b
+	cp 12
+	push af
+	jr c, .AM
+	jr z, .PM
+	sub 12
+	jr .PM
+.AM:
+	or a
+	jr nz, .PM
+	ld a, 12
+.PM:
+	ld b, a
+; Crazy stuff happening with the stack
+	push bc
+	ld hl, sp+$1
+	push de
+	push hl
+	pop de
+	pop hl
+	ld [hl], " "
+	lb bc, 1, 2
+	call PrintNum
+	ld [hl], ":"
+	inc hl
+	ld d, h
+	ld e, l
+	ld hl, sp+$0
+	push de
+	push hl
+	pop de
+	pop hl
+	lb bc, PRINTNUM_LEADINGZEROS | 1, 2
+	call PrintNum
+	pop bc
+	ld de, String_AM
+	pop af
+	jr c, .place_am_pm
+	ld de, String_PM
+.place_am_pm
+	inc hl
+	call PlaceString
+	ret
+
+String_AM: db "AM@" ; 1dd6fc
+String_PM: db "PM@" ; 1dd6ff
--- a/engine/save.asm
+++ b/engine/save.asm
@@ -500,12 +500,12 @@
 ; 14da9
 
 ValidateSave: ; 14da9
-	ld a, BANK(s1_a008)
+	ld a, BANK(sCheckValue1) ; BANK(sCheckValue2)
 	call GetSRAMBank
-	ld a, 99
-	ld [s1_a008], a
-	ld a, " "
-	ld [s1_ad0f], a
+	ld a, SAVE_CHECK_VALUE_1
+	ld [sCheckValue1], a
+	ld a, SAVE_CHECK_VALUE_2
+	ld [sCheckValue2], a
 	jp CloseSRAM
 ; 14dbb
 
@@ -568,12 +568,12 @@
 ; 14e2d
 
 ValidateBackupSave: ; 14e2d
-	ld a, BANK(s0_b208)
+	ld a, BANK(sBackupCheckValue1) ; BANK(sBackupCheckValue2)
 	call GetSRAMBank
-	ld a, 99
-	ld [s0_b208], a
-	ld a, " "
-	ld [s0_bf0f], a
+	ld a, SAVE_CHECK_VALUE_1
+	ld [sBackupCheckValue1], a
+	ld a, SAVE_CHECK_VALUE_2
+	ld [sBackupCheckValue2], a
 	call CloseSRAM
 	ret
 ; 14e40
@@ -731,13 +731,13 @@
 
 
 CheckPrimarySaveFile: ; 14f84
-	ld a, BANK(s1_a008)
+	ld a, BANK(sCheckValue1) ; BANK(sCheckValue2)
 	call GetSRAMBank
-	ld a, [s1_a008]
-	cp 99
+	ld a, [sCheckValue1]
+	cp SAVE_CHECK_VALUE_1
 	jr nz, .nope
-	ld a, [s1_ad0f]
-	cp " "
+	ld a, [sCheckValue2]
+	cp SAVE_CHECK_VALUE_2
 	jr nz, .nope
 	ld hl, sOptions
 	ld de, Options
@@ -753,13 +753,13 @@
 ; 14faf
 
 CheckBackupSaveFile: ; 14faf
-	ld a, BANK(s0_b208)
+	ld a, BANK(sBackupCheckValue1) ; BANK(sBackupCheckValue2)
 	call GetSRAMBank
-	ld a, [s0_b208]
-	cp 99
+	ld a, [sBackupCheckValue1]
+	cp SAVE_CHECK_VALUE_1
 	jr nz, .nope
-	ld a, [s0_bf0f]
-	cp " "
+	ld a, [sBackupCheckValue2]
+	cp SAVE_CHECK_VALUE_2
 	jr nz, .nope
 	ld hl, sBackupOptions
 	ld de, Options
--- /dev/null
+++ b/engine/select_menu.asm
@@ -1,0 +1,189 @@
+SelectMenu:: ; 13327
+
+	call CheckRegisteredItem
+	jr c, .NotRegistered
+	jp UseRegisteredItem
+
+.NotRegistered:
+	call OpenText
+	ld b, BANK(ItemMayBeRegisteredText)
+	ld hl, ItemMayBeRegisteredText
+	call MapTextbox
+	call WaitButton
+	jp CloseText
+; 13340
+
+
+ItemMayBeRegisteredText: ; 13340
+	text_jump UnknownText_0x1c1cf3
+	db "@"
+; 13345
+
+
+CheckRegisteredItem: ; 13345
+
+	ld a, [WhichRegisteredItem]
+	and a
+	jr z, .NoRegisteredItem
+	and REGISTERED_POCKET
+	rlca
+	rlca
+	ld hl, .Pockets
+	rst JumpTable
+	ret
+
+.Pockets:
+	dw .CheckItem
+	dw .CheckBall
+	dw .CheckKeyItem
+	dw .CheckTMHM
+
+.CheckItem:
+	ld hl, NumItems
+	call .CheckRegisteredNo
+	jr c, .NoRegisteredItem
+	inc hl
+	ld e, a
+	ld d, 0
+	add hl, de
+	add hl, de
+	call .IsSameItem
+	jr c, .NoRegisteredItem
+	and a
+	ret
+
+.CheckKeyItem:
+	ld a, [RegisteredItem]
+	ld hl, KeyItems
+	ld de, 1
+	call IsInArray
+	jr nc, .NoRegisteredItem
+	ld a, [RegisteredItem]
+	ld [CurItem], a
+	and a
+	ret
+
+.CheckBall:
+	ld hl, NumBalls
+	call .CheckRegisteredNo
+	jr nc, .NoRegisteredItem
+	inc hl
+	ld e, a
+	ld d, 0
+	add hl, de
+	add hl, de
+	call .IsSameItem
+	jr c, .NoRegisteredItem
+	ret
+
+.CheckTMHM:
+	jr .NoRegisteredItem
+
+.NoRegisteredItem:
+	xor a
+	ld [WhichRegisteredItem], a
+	ld [RegisteredItem], a
+	scf
+	ret
+; 133a6
+
+
+.CheckRegisteredNo: ; 133a6
+	ld a, [WhichRegisteredItem]
+	and REGISTERED_NUMBER
+	dec a
+	cp [hl]
+	jr nc, .NotEnoughItems
+	ld [CurItemQuantity], a
+	and a
+	ret
+
+.NotEnoughItems:
+	scf
+	ret
+; 133b6
+
+
+.IsSameItem: ; 133b6
+	ld a, [RegisteredItem]
+	cp [hl]
+	jr nz, .NotSameItem
+	ld [CurItem], a
+	and a
+	ret
+
+.NotSameItem:
+	scf
+	ret
+; 133c3
+
+
+UseRegisteredItem: ; 133c3
+
+	callba CheckItemMenu
+	ld a, [wItemAttributeParamBuffer]
+	ld hl, .SwitchTo
+	rst JumpTable
+	ret
+
+.SwitchTo:
+	dw .CantUse
+	dw .NoFunction
+	dw .NoFunction
+	dw .NoFunction
+	dw .Current
+	dw .Party
+	dw .Overworld
+; 133df
+
+.NoFunction: ; 133df
+	call OpenText
+	call CantUseItem
+	call CloseText
+	and a
+	ret
+; 133ea
+
+.Current: ; 133ea
+	call OpenText
+	call DoItemEffect
+	call CloseText
+	and a
+	ret
+; 133f5
+
+.Party: ; 133f5
+	call RefreshScreen
+	call FadeToMenu
+	call DoItemEffect
+	call CloseSubmenu
+	call CloseText
+	and a
+	ret
+; 13406
+
+.Overworld: ; 13406
+	call RefreshScreen
+	ld a, 1
+	ld [wUsingItemWithSelect], a
+	call DoItemEffect
+	xor a
+	ld [wUsingItemWithSelect], a
+	ld a, [wItemEffectSucceeded]
+	cp 1
+	jr nz, ._cantuse
+	scf
+	ld a, HMENURETURN_SCRIPT
+	ld [hMenuReturn], a
+	ret
+; 13422
+
+.CantUse: ; 13422
+	call RefreshScreen
+
+._cantuse
+	call CantUseItem
+	call CloseText
+	and a
+	ret
+; 1342d
--- a/engine/selectmenu.asm
+++ /dev/null
@@ -1,189 +1,0 @@
-SelectMenu:: ; 13327
-
-	call CheckRegisteredItem
-	jr c, .NotRegistered
-	jp UseRegisteredItem
-
-.NotRegistered:
-	call OpenText
-	ld b, BANK(ItemMayBeRegisteredText)
-	ld hl, ItemMayBeRegisteredText
-	call MapTextbox
-	call WaitButton
-	jp CloseText
-; 13340
-
-
-ItemMayBeRegisteredText: ; 13340
-	text_jump UnknownText_0x1c1cf3
-	db "@"
-; 13345
-
-
-CheckRegisteredItem: ; 13345
-
-	ld a, [WhichRegisteredItem]
-	and a
-	jr z, .NoRegisteredItem
-	and REGISTERED_POCKET
-	rlca
-	rlca
-	ld hl, .Pockets
-	rst JumpTable
-	ret
-
-.Pockets:
-	dw .CheckItem
-	dw .CheckBall
-	dw .CheckKeyItem
-	dw .CheckTMHM
-
-.CheckItem:
-	ld hl, NumItems
-	call .CheckRegisteredNo
-	jr c, .NoRegisteredItem
-	inc hl
-	ld e, a
-	ld d, 0
-	add hl, de
-	add hl, de
-	call .IsSameItem
-	jr c, .NoRegisteredItem
-	and a
-	ret
-
-.CheckKeyItem:
-	ld a, [RegisteredItem]
-	ld hl, KeyItems
-	ld de, 1
-	call IsInArray
-	jr nc, .NoRegisteredItem
-	ld a, [RegisteredItem]
-	ld [CurItem], a
-	and a
-	ret
-
-.CheckBall:
-	ld hl, NumBalls
-	call .CheckRegisteredNo
-	jr nc, .NoRegisteredItem
-	inc hl
-	ld e, a
-	ld d, 0
-	add hl, de
-	add hl, de
-	call .IsSameItem
-	jr c, .NoRegisteredItem
-	ret
-
-.CheckTMHM:
-	jr .NoRegisteredItem
-
-.NoRegisteredItem:
-	xor a
-	ld [WhichRegisteredItem], a
-	ld [RegisteredItem], a
-	scf
-	ret
-; 133a6
-
-
-.CheckRegisteredNo: ; 133a6
-	ld a, [WhichRegisteredItem]
-	and REGISTERED_NUMBER
-	dec a
-	cp [hl]
-	jr nc, .NotEnoughItems
-	ld [CurItemQuantity], a
-	and a
-	ret
-
-.NotEnoughItems:
-	scf
-	ret
-; 133b6
-
-
-.IsSameItem: ; 133b6
-	ld a, [RegisteredItem]
-	cp [hl]
-	jr nz, .NotSameItem
-	ld [CurItem], a
-	and a
-	ret
-
-.NotSameItem:
-	scf
-	ret
-; 133c3
-
-
-UseRegisteredItem: ; 133c3
-
-	callba CheckItemMenu
-	ld a, [wItemAttributeParamBuffer]
-	ld hl, .SwitchTo
-	rst JumpTable
-	ret
-
-.SwitchTo:
-	dw .CantUse
-	dw .NoFunction
-	dw .NoFunction
-	dw .NoFunction
-	dw .Current
-	dw .Party
-	dw .Overworld
-; 133df
-
-.NoFunction: ; 133df
-	call OpenText
-	call CantUseItem
-	call CloseText
-	and a
-	ret
-; 133ea
-
-.Current: ; 133ea
-	call OpenText
-	call DoItemEffect
-	call CloseText
-	and a
-	ret
-; 133f5
-
-.Party: ; 133f5
-	call RefreshScreen
-	call FadeToMenu
-	call DoItemEffect
-	call CloseSubmenu
-	call CloseText
-	and a
-	ret
-; 13406
-
-.Overworld: ; 13406
-	call RefreshScreen
-	ld a, 1
-	ld [wUsingItemWithSelect], a
-	call DoItemEffect
-	xor a
-	ld [wUsingItemWithSelect], a
-	ld a, [wItemEffectSucceeded]
-	cp 1
-	jr nz, ._cantuse
-	scf
-	ld a, HMENURETURN_SCRIPT
-	ld [hMenuReturn], a
-	ret
-; 13422
-
-.CantUse: ; 13422
-	call RefreshScreen
-
-._cantuse
-	call CantUseItem
-	call CloseText
-	and a
-	ret
-; 1342d
--- /dev/null
+++ b/engine/start_menu.asm
@@ -1,0 +1,1974 @@
+StartMenu:: ; 125cd
+
+	call ClearWindowData
+
+	ld de, SFX_MENU
+	call PlaySFX
+
+	callba ReanchorBGMap_NoOAMUpdate
+
+	ld hl, StatusFlags2
+	bit 2, [hl] ; bug catching contest
+	ld hl, .MenuDataHeader
+	jr z, .GotMenuData
+	ld hl, .ContestMenuDataHeader
+.GotMenuData:
+
+	call LoadMenuDataHeader
+	call .SetUpMenuItems
+	ld a, [wBattleMenuCursorBuffer]
+	ld [wMenuCursorBuffer], a
+	call .DrawMenuAccount_
+	call DrawVariableLengthMenuBox
+	call .DrawBugContestStatusBox
+	call SafeUpdateSprites
+	call _OpenAndCloseMenu_HDMATransferTileMapAndAttrMap
+	callba LoadFonts_NoOAMUpdate
+	call .DrawBugContestStatus
+	call UpdateTimePals
+	jr .Select
+
+.Reopen:
+	call UpdateSprites
+	call UpdateTimePals
+	call .SetUpMenuItems
+	ld a, [wBattleMenuCursorBuffer]
+	ld [wMenuCursorBuffer], a
+
+.Select:
+	call .GetInput
+	jr c, .Exit
+	call .DrawMenuAccount
+	ld a, [wMenuCursorBuffer]
+	ld [wBattleMenuCursorBuffer], a
+	call PlayClickSFX
+	call PlaceHollowCursor
+	call .OpenMenu
+
+; Menu items have different return functions.
+; For example, saving exits the menu.
+	ld hl, .MenuReturns
+	ld e, a
+	ld d, 0
+	add hl, de
+	add hl, de
+	ld a, [hli]
+	ld h, [hl]
+	ld l, a
+	jp hl
+
+.MenuReturns:
+	dw .Reopen
+	dw .Exit
+	dw .ExitMenuCallFuncCloseText
+	dw .ExitMenuRunScriptCloseText
+	dw .ExitMenuRunScript
+	dw .ReturnEnd
+	dw .ReturnRedraw
+
+.Exit:
+	ld a, [hOAMUpdate]
+	push af
+	ld a, 1
+	ld [hOAMUpdate], a
+	call LoadFontsExtra
+	pop af
+	ld [hOAMUpdate], a
+.ReturnEnd:
+	call ExitMenu
+.ReturnEnd2:
+	call CloseText
+	call UpdateTimePals
+	ret
+
+.GetInput:
+; Return carry on exit, and no-carry on selection.
+	xor a
+	ld [hBGMapMode], a
+	call .DrawMenuAccount
+	call SetUpMenu
+	ld a, $ff
+	ld [MenuSelection], a
+.loop
+	call .PrintMenuAccount
+	call GetScrollingMenuJoypad
+	ld a, [wMenuJoypad]
+	cp B_BUTTON
+	jr z, .b
+	cp A_BUTTON
+	jr z, .a
+	jr .loop
+.a
+	call PlayClickSFX
+	and a
+	ret
+.b
+	scf
+	ret
+; 12691
+
+.ExitMenuRunScript: ; 12691
+	call ExitMenu
+	ld a, HMENURETURN_SCRIPT
+	ld [hMenuReturn], a
+	ret
+; 12699
+
+.ExitMenuRunScriptCloseText: ; 12699
+	call ExitMenu
+	ld a, HMENURETURN_SCRIPT
+	ld [hMenuReturn], a
+	jr .ReturnEnd2
+; 126a2
+
+.ExitMenuCallFuncCloseText: ; 126a2
+	call ExitMenu
+	ld hl, wQueuedScriptAddr
+	ld a, [hli]
+	ld h, [hl]
+	ld l, a
+	ld a, [wQueuedScriptBank]
+	rst FarCall
+	jr .ReturnEnd2
+; 126b1
+
+.ReturnRedraw: ; 126b1
+	call .Clear
+	jp .Reopen
+; 126b7
+
+.Clear: ; 126b7
+	call ClearBGPalettes
+	call Call_ExitMenu
+	call ReloadTilesetAndPalettes
+	call .DrawMenuAccount_
+	call DrawVariableLengthMenuBox
+	call .DrawBugContestStatus
+	call UpdateSprites
+	call ret_d90
+	call FinishExitMenu
+	ret
+; 126d3
+
+
+.MenuDataHeader:
+	db $40 ; tile backup
+	db 0, 10 ; start coords
+	db 17, 19 ; end coords
+	dw .MenuData
+	db 1 ; default selection
+
+.ContestMenuDataHeader:
+	db $40 ; tile backup
+	db 2, 10 ; start coords
+	db 17, 19 ; end coords
+	dw .MenuData
+	db 1 ; default selection
+
+.MenuData:
+	db %10101000 ; x padding, wrap around, start can close
+	dn 0, 0 ; rows, columns
+	dw MenuItemsList
+	dw .MenuString
+	dw .Items
+
+.Items:
+	dw StartMenu_Pokedex,  .PokedexString,  .PokedexDesc
+	dw StartMenu_Pokemon,  .PartyString,    .PartyDesc
+	dw StartMenu_Pack,     .PackString,     .PackDesc
+	dw StartMenu_Status,   .StatusString,   .StatusDesc
+	dw StartMenu_Save,     .SaveString,     .SaveDesc
+	dw StartMenu_Option,   .OptionString,   .OptionDesc
+	dw StartMenu_Exit,     .ExitString,     .ExitDesc
+	dw StartMenu_Pokegear, .PokegearString, .PokegearDesc
+	dw StartMenu_Quit,     .QuitString,     .QuitDesc
+
+.PokedexString: 	db "#DEX@"
+.PartyString:   	db "#MON@"
+.PackString:    	db "PACK@"
+.StatusString:  	db "<PLAYER>@"
+.SaveString:    	db "SAVE@"
+.OptionString:  	db "OPTION@"
+.ExitString:    	db "EXIT@"
+.PokegearString:	db $24, "GEAR@"
+.QuitString:    	db "QUIT@"
+
+.PokedexDesc:  db   "#MON"
+	next "database@"
+
+.PartyDesc:    db   "Party ", $4a
+	next "status@"
+
+.PackDesc:     db   "Contains"
+	next "items@"
+
+.PokegearDesc: db   "Trainer's"
+	next "key device@"
+
+.StatusDesc:   db   "Your own"
+	next "status@"
+
+.SaveDesc:     db   "Save your"
+	next "progress@"
+
+.OptionDesc:   db   "Change"
+	next "settings@"
+
+.ExitDesc:     db   "Close this"
+	next "menu@"
+
+.QuitDesc:     db   "Quit and"
+	next "be judged.@"
+
+
+.OpenMenu: ; 127e5
+	ld a, [MenuSelection]
+	call .GetMenuAccountTextPointer
+	ld a, [hli]
+	ld h, [hl]
+	ld l, a
+	jp hl
+; 127ef
+
+.MenuString: ; 127ef
+	push de
+	ld a, [MenuSelection]
+	call .GetMenuAccountTextPointer
+	inc hl
+	inc hl
+	ld a, [hli]
+	ld d, [hl]
+	ld e, a
+	pop hl
+	call PlaceString
+	ret
+; 12800
+
+.MenuDesc: ; 12800
+	push de
+	ld a, [MenuSelection]
+	cp $ff
+	jr z, .none
+	call .GetMenuAccountTextPointer
+rept 4
+	inc hl
+endr
+	ld a, [hli]
+	ld d, [hl]
+	ld e, a
+	pop hl
+	call PlaceString
+	ret
+.none
+	pop de
+	ret
+; 12819
+
+
+.GetMenuAccountTextPointer: ; 12819
+	ld e, a
+	ld d, 0
+	ld hl, wMenuData2PointerTableAddr
+	ld a, [hli]
+	ld h, [hl]
+	ld l, a
+rept 6
+	add hl, de
+endr
+	ret
+; 12829
+
+
+.SetUpMenuItems: ; 12829
+	xor a
+	ld [wWhichIndexSet], a
+	call .FillMenuList
+
+	ld hl, StatusFlags
+	bit 0, [hl]
+	jr z, .no_pokedex
+	ld a, 0 ; pokedex
+	call .AppendMenuList
+.no_pokedex
+
+	ld a, [PartyCount]
+	and a
+	jr z, .no_pokemon
+	ld a, 1 ; pokemon
+	call .AppendMenuList
+.no_pokemon
+
+	ld a, [wLinkMode]
+	and a
+	jr nz, .no_pack
+	ld hl, StatusFlags2
+	bit 2, [hl] ; bug catching contest
+	jr nz, .no_pack
+	ld a, 2 ; pack
+	call .AppendMenuList
+.no_pack
+
+	ld hl, wPokegearFlags
+	bit 7, [hl]
+	jr z, .no_pokegear
+	ld a, 7 ; pokegear
+	call .AppendMenuList
+.no_pokegear
+
+	ld a, 3 ; status
+	call .AppendMenuList
+
+	ld a, [wLinkMode]
+	and a
+	jr nz, .no_save
+	ld hl, StatusFlags2
+	bit 2, [hl] ; bug catching contest
+	ld a, 8 ; quit
+	jr nz, .write
+	ld a, 4 ; save
+.write
+	call .AppendMenuList
+.no_save
+
+	ld a, 5 ; option
+	call .AppendMenuList
+	ld a, 6 ; exit
+	call .AppendMenuList
+	ld a, c
+	ld [MenuItemsList], a
+	ret
+; 1288d
+
+
+.FillMenuList: ; 1288d
+	xor a
+	ld hl, MenuItemsList
+	ld [hli], a
+	ld a, -1
+	ld bc, MenuItemsListEnd - (MenuItemsList + 1)
+	call ByteFill
+	ld de, MenuItemsList + 1
+	ld c, 0
+	ret
+; 128a0
+
+.AppendMenuList: ; 128a0
+	ld [de], a
+	inc de
+	inc c
+	ret
+; 128a4
+
+.DrawMenuAccount_: ; 128a4
+	jp .DrawMenuAccount
+; 128a7
+
+.PrintMenuAccount: ; 128a7
+	call .IsMenuAccountOn
+	ret z
+	call .DrawMenuAccount
+	decoord 0, 14
+	jp .MenuDesc
+; 128b4
+
+.DrawMenuAccount: ; 128b4
+	call .IsMenuAccountOn
+	ret z
+	hlcoord 0, 13
+	lb bc, 5, 10
+	call ClearBox
+	hlcoord 0, 13
+	ld b, 3
+	ld c, 8
+	jp TextBoxPalette
+; 128cb
+
+.IsMenuAccountOn: ; 128cb
+	ld a, [Options2]
+	and 1
+	ret
+; 128d1
+
+.DrawBugContestStatusBox: ; 128d1
+	ld hl, StatusFlags2
+	bit 2, [hl] ; bug catching contest
+	ret z
+	callba StartMenu_DrawBugContestStatusBox
+	ret
+; 128de
+
+.DrawBugContestStatus: ; 128de
+	ld hl, StatusFlags2
+	bit 2, [hl] ; bug catching contest
+	jr nz, .contest
+	ret
+.contest
+	callba StartMenu_PrintBugContestStatus
+	ret
+; 128ed
+
+
+StartMenu_Exit: ; 128ed
+; Exit the menu.
+
+	ld a, 1
+	ret
+; 128f0
+
+
+StartMenu_Quit: ; 128f0
+; Retire from the bug catching contest.
+
+	ld hl, .EndTheContestText
+	call StartMenuYesNo
+	jr c, .DontEndContest
+	ld a, BANK(BugCatchingContestReturnToGateScript)
+	ld hl, BugCatchingContestReturnToGateScript
+	call FarQueueScript
+	ld a, 4
+	ret
+
+.DontEndContest:
+	ld a, 0
+	ret
+
+.EndTheContestText:
+	text_jump UnknownText_0x1c1a6c
+	db "@"
+; 1290b
+
+
+StartMenu_Save: ; 1290b
+; Save the game.
+
+	call BufferScreen
+	callba SaveMenu
+	jr nc, .asm_12919
+	ld a, 0
+	ret
+.asm_12919
+	ld a, 1
+	ret
+; 1291c
+
+
+StartMenu_Option: ; 1291c
+; Game options.
+
+	call FadeToMenu
+	callba OptionsMenu
+	ld a, 6
+	ret
+; 12928
+
+
+StartMenu_Status: ; 12928
+; Player status.
+
+	call FadeToMenu
+	callba TrainerCard
+	call CloseSubmenu
+	ld a, 0
+	ret
+; 12937
+
+
+StartMenu_Pokedex: ; 12937
+
+	ld a, [PartyCount]
+	and a
+	jr z, .asm_12949
+
+	call FadeToMenu
+	callba Pokedex
+	call CloseSubmenu
+
+.asm_12949
+	ld a, 0
+	ret
+; 1294c
+
+
+StartMenu_Pokegear: ; 1294c
+
+	call FadeToMenu
+	callba PokeGear
+	call CloseSubmenu
+	ld a, 0
+	ret
+; 1295b
+
+
+StartMenu_Pack: ; 1295b
+
+	call FadeToMenu
+	callba Pack
+	ld a, [wcf66]
+	and a
+	jr nz, .used_item
+	call CloseSubmenu
+	ld a, 0
+	ret
+
+.used_item
+	call ExitAllMenus
+	ld a, 4
+	ret
+; 12976
+
+
+StartMenu_Pokemon: ; 12976
+
+	ld a, [PartyCount]
+	and a
+	jr z, .return
+
+	call FadeToMenu
+
+.choosemenu
+	xor a
+	ld [PartyMenuActionText], a ; Choose a POKéMON.
+	call ClearBGPalettes
+
+.menu
+	callba LoadPartyMenuGFX
+	callba InitPartyMenuWithCancel
+	callba InitPartyMenuGFX
+
+.menunoreload
+	callba WritePartyMenuTilemap
+	callba PrintPartyMenuText
+	call WaitBGMap
+	call SetPalettes ; load regular palettes?
+	call DelayFrame
+	callba PartyMenuSelect
+	jr c, .return ; if cancelled or pressed B
+
+	call PokemonActionSubmenu
+	cp 3
+	jr z, .menu
+	cp 0
+	jr z, .choosemenu
+	cp 1
+	jr z, .menunoreload
+	cp 2
+	jr z, .quit
+
+.return
+	call CloseSubmenu
+	ld a, 0
+	ret
+
+.quit
+	ld a, b
+	push af
+	call ExitAllMenus
+	pop af
+	ret
+; 129d5
+
+HasNoItems: ; 129d5
+	ld a, [NumItems]
+	and a
+	ret nz
+	ld a, [NumKeyItems]
+	and a
+	ret nz
+	ld a, [NumBalls]
+	and a
+	ret nz
+	ld hl, TMsHMs
+	ld b, NUM_TMS + NUM_HMS
+.loop
+	ld a, [hli]
+	and a
+	jr nz, .done
+	dec b
+	jr nz, .loop
+	scf
+	ret
+.done
+	and a
+	ret
+
+TossItemFromPC: ; 129f4
+	push de
+	call PartyMonItemName
+	callba _CheckTossableItem
+	ld a, [wItemAttributeParamBuffer]
+	and a
+	jr nz, .key_item
+	ld hl, .TossHowMany
+	call MenuTextBox
+	callba SelectQuantityToToss
+	push af
+	call CloseWindow
+	call ExitMenu
+	pop af
+	jr c, .quit
+	ld hl, .ConfirmToss
+	call MenuTextBox
+	call YesNoBox
+	push af
+	call ExitMenu
+	pop af
+	jr c, .quit
+	pop hl
+	ld a, [CurItemQuantity]
+	call TossItem
+	call PartyMonItemName
+	ld hl, .TossedThisMany
+	call MenuTextBox
+	call ExitMenu
+	and a
+	ret
+
+.key_item
+	call .CantToss
+.quit
+	pop hl
+	scf
+	ret
+
+.TossHowMany:
+	; Toss out how many @ (S)?
+	text_jump UnknownText_0x1c1a90
+	db "@"
+
+.ConfirmToss:
+	; Throw away @ @ (S)?
+	text_jump UnknownText_0x1c1aad
+	db "@"
+
+.TossedThisMany:
+	; Discarded @ (S).
+	text_jump UnknownText_0x1c1aca
+	db "@"
+
+.CantToss:
+	ld hl, .TooImportantToToss
+	call MenuTextBoxBackup
+	ret
+
+.TooImportantToToss:
+	; That's too impor- tant to toss out!
+	text_jump UnknownText_0x1c1adf
+	db "@"
+; 0x12a60
+
+CantUseItem: ; 12a60
+	ld hl, CantUseItemText
+	call MenuTextBoxWaitButton
+	ret
+; 12a67
+
+CantUseItemText: ; 12a67
+	text_jump UnknownText_0x1c1b03
+	db "@"
+; 12a6c
+
+
+PartyMonItemName: ; 12a6c
+	ld a, [CurItem]
+	ld [wd265], a
+	call GetItemName
+	call CopyName1
+	ret
+; 12a79
+
+
+CancelPokemonAction: ; 12a79
+	callba InitPartyMenuWithCancel
+	callba UnfreezeMonIcons
+	ld a, 1
+	ret
+; 12a88
+
+
+PokemonActionSubmenu: ; 12a88
+	hlcoord 1, 15
+	lb bc, 2, 18
+	call ClearBox
+	callba MonSubmenu
+	call GetCurNick
+	ld a, [MenuSelection]
+	ld hl, .Actions
+	ld de, 3
+	call IsInArray
+	jr nc, .nothing
+
+	inc hl
+	ld a, [hli]
+	ld h, [hl]
+	ld l, a
+	jp hl
+
+.nothing
+	ld a, 0
+	ret
+
+.Actions:
+	dbw MONMENU_CUT,        MonMenu_Cut ; Cut
+	dbw MONMENU_FLY,        MonMenu_Fly ; Fly
+	dbw MONMENU_SURF,       MonMenu_Surf ; Surf
+	dbw MONMENU_STRENGTH,   MonMenu_Strength ; Strength
+	dbw MONMENU_FLASH,      MonMenu_Flash ; Flash
+	dbw MONMENU_WHIRLPOOL,  MonMenu_Whirlpool ; Whirlpool
+	dbw MONMENU_DIG,        MonMenu_Dig ; Dig
+	dbw MONMENU_TELEPORT,   MonMenu_Teleport ; Teleport
+	dbw MONMENU_SOFTBOILED, MonMenu_Softboiled_MilkDrink ; Softboiled
+	dbw MONMENU_MILKDRINK,  MonMenu_Softboiled_MilkDrink ; MilkDrink
+	dbw MONMENU_HEADBUTT,   MonMenu_Headbutt ; Headbutt
+	dbw MONMENU_WATERFALL,  MonMenu_Waterfall ; Waterfall
+	dbw MONMENU_ROCKSMASH,  MonMenu_RockSmash ; RockSmash
+	dbw MONMENU_SWEETSCENT, MonMenu_SweetScent ; SweetScent
+	dbw MONMENU_STATS,      OpenPartyStats
+	dbw MONMENU_SWITCH,     SwitchPartyMons
+	dbw MONMENU_ITEM,       GiveTakePartyMonItem
+	dbw MONMENU_CANCEL,     CancelPokemonAction
+	dbw MONMENU_MOVE,       ManagePokemonMoves ; move
+	dbw MONMENU_MAIL,       MonMailAction ; mail
+; 12aec
+
+
+SwitchPartyMons: ; 12aec
+
+; Don't try if there's nothing to switch!
+	ld a, [PartyCount]
+	cp 2
+	jr c, .DontSwitch
+
+	ld a, [CurPartyMon]
+	inc a
+	ld [wSwitchMon], a
+
+	callba HoldSwitchmonIcon
+	callba InitPartyMenuNoCancel
+
+	ld a, PARTYMENUACTION_MOVE
+	ld [PartyMenuActionText], a
+	callba WritePartyMenuTilemap
+	callba PrintPartyMenuText
+
+	hlcoord 0, 1
+	ld bc, 20 * 2
+	ld a, [wSwitchMon]
+	dec a
+	call AddNTimes
+	ld [hl], "▷"
+	call WaitBGMap
+	call SetPalettes
+	call DelayFrame
+
+	callba PartyMenuSelect
+	bit 1, b
+	jr c, .DontSwitch
+
+	callba _SwitchPartyMons
+
+	xor a
+	ld [PartyMenuActionText], a
+
+	callba LoadPartyMenuGFX
+	callba InitPartyMenuWithCancel
+	callba InitPartyMenuGFX
+
+	ld a, 1
+	ret
+
+.DontSwitch:
+	xor a
+	ld [PartyMenuActionText], a
+	call CancelPokemonAction
+	ret
+; 12b60
+
+
+GiveTakePartyMonItem: ; 12b60
+
+; Eggs can't hold items!
+	ld a, [CurPartySpecies]
+	cp EGG
+	jr z, .cancel
+
+	ld hl, GiveTakeItemMenuData
+	call LoadMenuDataHeader
+	call VerticalMenu
+	call ExitMenu
+	jr c, .cancel
+
+	call GetCurNick
+	ld hl, StringBuffer1
+	ld de, wMonOrItemNameBuffer
+	ld bc, PKMN_NAME_LENGTH
+	call CopyBytes
+	ld a, [wMenuCursorY]
+	cp 1
+	jr nz, .take
+
+	call LoadStandardMenuDataHeader
+	call ClearPalettes
+	call .GiveItem
+	call ClearPalettes
+	call LoadFontsBattleExtra
+	call ExitMenu
+	ld a, 0
+	ret
+
+.take
+	call TakePartyItem
+	ld a, 3
+	ret
+
+.cancel
+	ld a, 3
+	ret
+; 12ba9
+
+
+.GiveItem:
+
+	callba DepositSellInitPackBuffers
+
+.loop
+	callba DepositSellPack
+
+	ld a, [wcf66]
+	and a
+	jr z, .quit
+
+	ld a, [wcf65]
+	cp 2
+	jr z, .next
+
+	call CheckTossableItem
+	ld a, [wItemAttributeParamBuffer]
+	and a
+	jr nz, .next
+
+	call TryGiveItemToPartymon
+	jr .quit
+
+.next
+	ld hl, CantBeHeldText
+	call MenuTextBoxBackup
+	jr .loop
+
+.quit
+	ret
+; 12bd9
+
+
+TryGiveItemToPartymon: ; 12bd9
+
+	call SpeechTextBox
+	call PartyMonItemName
+	call GetPartyItemLocation
+	ld a, [hl]
+	and a
+	jr z, .give_item_to_mon
+
+	push hl
+	ld d, a
+	callba ItemIsMail
+	pop hl
+	jr c, .please_remove_mail
+	ld a, [hl]
+	jr .already_holding_item
+
+.give_item_to_mon
+	call GiveItemToPokemon
+	ld hl, MadeHoldText
+	call MenuTextBoxBackup
+	call GivePartyItem
+	ret
+
+.please_remove_mail
+	ld hl, PleaseRemoveMailText
+	call MenuTextBoxBackup
+	ret
+
+.already_holding_item
+	ld [wd265], a
+	call GetItemName
+	ld hl, SwitchAlreadyHoldingText
+	call StartMenuYesNo
+	jr c, .abort
+
+	call GiveItemToPokemon
+	ld a, [wd265]
+	push af
+	ld a, [CurItem]
+	ld [wd265], a
+	pop af
+	ld [CurItem], a
+	call ReceiveItemFromPokemon
+	jr nc, .bag_full
+
+	ld hl, TookAndMadeHoldText
+	call MenuTextBoxBackup
+	ld a, [wd265]
+	ld [CurItem], a
+	call GivePartyItem
+	ret
+
+.bag_full
+	ld a, [wd265]
+	ld [CurItem], a
+	call ReceiveItemFromPokemon
+	ld hl, ItemStorageIsFullText
+	call MenuTextBoxBackup
+
+.abort
+	ret
+; 12c4c
+
+
+GivePartyItem: ; 12c4c
+
+	call GetPartyItemLocation
+	ld a, [CurItem]
+	ld [hl], a
+	ld d, a
+	callba ItemIsMail
+	jr nc, .done
+	call ComposeMailMessage
+
+.done
+	ret
+; 12c60
+
+
+TakePartyItem: ; 12c60
+
+	call SpeechTextBox
+	call GetPartyItemLocation
+	ld a, [hl]
+	and a
+	jr z, .asm_12c8c
+
+	ld [CurItem], a
+	call ReceiveItemFromPokemon
+	jr nc, .asm_12c94
+
+	callba ItemIsMail
+	call GetPartyItemLocation
+	ld a, [hl]
+	ld [wd265], a
+	ld [hl], NO_ITEM
+	call GetItemName
+	ld hl, TookFromText
+	call MenuTextBoxBackup
+	jr .asm_12c9a
+
+.asm_12c8c
+	ld hl, IsntHoldingAnythingText
+	call MenuTextBoxBackup
+	jr .asm_12c9a
+
+.asm_12c94
+	ld hl, ItemStorageIsFullText
+	call MenuTextBoxBackup
+
+.asm_12c9a
+	ret
+; 12c9b
+
+
+GiveTakeItemMenuData: ; 12c9b
+	db %01010000
+	db 12, 12 ; start coords
+	db 17, 19 ; end coords
+	dw .Items
+	db 1 ; default option
+
+.Items:
+	db %10000000 ; x padding
+	db 2 ; # items
+	db "GIVE@"
+	db "TAKE@"
+; 12caf
+
+
+TookAndMadeHoldText: ; 12caf
+	text_jump UnknownText_0x1c1b2c
+	db "@"
+; 12cb4
+
+MadeHoldText: ; 12cb4
+	text_jump UnknownText_0x1c1b57
+	db "@"
+; 12cb9
+
+PleaseRemoveMailText: ; 12cb9
+	text_jump UnknownText_0x1c1b6f
+	db "@"
+; 12cbe
+
+IsntHoldingAnythingText: ; 12cbe
+	text_jump UnknownText_0x1c1b8e
+	db "@"
+; 12cc3
+
+ItemStorageIsFullText: ; 12cc3
+	text_jump UnknownText_0x1c1baa
+	db "@"
+; 12cc8
+
+TookFromText: ; 12cc8
+	text_jump UnknownText_0x1c1bc4
+	db "@"
+; 12ccd
+
+SwitchAlreadyHoldingText: ; 12ccd
+	text_jump UnknownText_0x1c1bdc
+	db "@"
+; 12cd2
+
+CantBeHeldText: ; 12cd2
+	text_jump UnknownText_0x1c1c09
+	db "@"
+; 12cd7
+
+
+GetPartyItemLocation: ; 12cd7
+	push af
+	ld a, MON_ITEM
+	call GetPartyParamLocation
+	pop af
+	ret
+; 12cdf
+
+
+ReceiveItemFromPokemon: ; 12cdf
+	ld a, $1
+	ld [wItemQuantityChangeBuffer], a
+	ld hl, NumItems
+	jp ReceiveItem
+; 12cea
+
+
+GiveItemToPokemon: ; 12cea (4:6cea)
+	ld a, $1
+	ld [wItemQuantityChangeBuffer], a
+	ld hl, NumItems
+	jp TossItem
+
+StartMenuYesNo: ; 12cf5
+	call MenuTextBox
+	call YesNoBox
+	jp ExitMenu
+; 12cfe
+
+
+ComposeMailMessage: ; 12cfe (4:6cfe)
+	ld de, wTempMailMessage
+	callba _ComposeMailMessage
+	ld hl, PlayerName
+	ld de, wTempMailAuthor
+	ld bc, NAME_LENGTH - 1
+	call CopyBytes
+	ld hl, PlayerID
+	ld bc, 2
+	call CopyBytes
+	ld a, [CurPartySpecies]
+	ld [de], a
+	inc de
+	ld a, [CurItem]
+	ld [de], a
+	ld a, [CurPartyMon]
+	ld hl, sPartyMail
+	ld bc, MAIL_STRUCT_LENGTH
+	call AddNTimes
+	ld d, h
+	ld e, l
+	ld hl, wTempMail
+	ld bc, MAIL_STRUCT_LENGTH
+	ld a, BANK(sPartyMail)
+	call GetSRAMBank
+	call CopyBytes
+	call CloseSRAM
+	ret
+
+MonMailAction: ; 12d45
+; If in the time capsule or trade center,
+; selecting the mail only allows you to
+; read the mail.
+	ld a, [wLinkMode]
+	cp LINK_TIMECAPSULE
+	jr z, .read
+	cp LINK_TRADECENTER
+	jr z, .read
+
+; Show the READ/TAKE/QUIT menu.
+	ld hl, .MenuDataHeader
+	call LoadMenuDataHeader
+	call VerticalMenu
+	call ExitMenu
+
+; Interpret the menu.
+	jp c, .done
+	ld a, [wMenuCursorY]
+	cp $1
+	jr z, .read
+	cp $2
+	jr z, .take
+	jp .done
+
+.read
+	callba ReadPartyMonMail
+	ld a, $0
+	ret
+
+.take
+	ld hl, .sendmailtopctext
+	call StartMenuYesNo
+	jr c, .RemoveMailToBag
+	ld a, [CurPartyMon]
+	ld b, a
+	callba SendMailToPC
+	jr c, .MailboxFull
+	ld hl, .sentmailtopctext
+	call MenuTextBoxBackup
+	jr .done
+
+.MailboxFull:
+	ld hl, .mailboxfulltext
+	call MenuTextBoxBackup
+	jr .done
+
+.RemoveMailToBag:
+	ld hl, .mailwilllosemessagetext
+	call StartMenuYesNo
+	jr c, .done
+	call GetPartyItemLocation
+	ld a, [hl]
+	ld [CurItem], a
+	call ReceiveItemFromPokemon
+	jr nc, .BagIsFull
+	call GetPartyItemLocation
+	ld [hl], $0
+	call GetCurNick
+	ld hl, .tookmailfrommontext
+	call MenuTextBoxBackup
+	jr .done
+
+.BagIsFull:
+	ld hl, .bagfulltext
+	call MenuTextBoxBackup
+	jr .done
+
+.done
+	ld a, $3
+	ret
+; 12dc9
+
+
+.MenuDataHeader:
+	db $40 ; flags
+	db 10, 12 ; start coords
+	db 17, 19 ; end coords
+	dw .MenuData2
+	db 1 ; default option
+; 0x12dd1
+
+.MenuData2:
+	db $80 ; flags
+	db 3 ; items
+	db "READ@"
+	db "TAKE@"
+	db "QUIT@"
+; 0x12de2
+
+
+.mailwilllosemessagetext
+; The MAIL will lose its message. OK?
+	text_jump UnknownText_0x1c1c22
+	db "@"
+; 0x12de7
+
+.tookmailfrommontext
+; MAIL detached from <POKEMON>.
+	text_jump UnknownText_0x1c1c47
+	db "@"
+; 0x12dec
+
+.bagfulltext
+; There's no space for removing MAIL.
+	text_jump UnknownText_0x1c1c62
+	db "@"
+; 0x12df1
+
+.sendmailtopctext
+; Send the removed MAIL to your PC?
+	text_jump UnknownText_0x1c1c86
+	db "@"
+; 0x12df6
+
+.mailboxfulltext
+; Your PC's MAILBOX is full.
+	text_jump UnknownText_0x1c1ca9
+	db "@"
+; 0x12dfb
+
+.sentmailtopctext
+; The MAIL was sent to your PC.
+	text_jump UnknownText_0x1c1cc4
+	db "@"
+; 0x12e00
+
+
+OpenPartyStats: ; 12e00
+	call LoadStandardMenuDataHeader
+	call ClearSprites
+; PartyMon
+	xor a
+	ld [MonType], a
+	call LowVolume
+	predef StatsScreenInit
+	call MaxVolume
+	call Call_ExitMenu
+	ld a, 0
+	ret
+; 12e1b
+
+
+MonMenu_Cut: ; 12e1b
+	callba CutFunction
+	ld a, [wFieldMoveSucceeded]
+	cp $1
+	jr nz, .Fail
+	ld b, $4
+	ld a, $2
+	ret
+
+.Fail:
+	ld a, $3
+	ret
+; 12e30
+
+
+MonMenu_Fly: ; 12e30
+	callba FlyFunction
+	ld a, [wFieldMoveSucceeded]
+	cp $2
+	jr z, .Fail
+	cp $0
+	jr z, .Error
+	callba TrainerRankings_Fly
+	ld b, $4
+	ld a, $2
+	ret
+
+.Fail:
+	ld a, $3
+	ret
+
+.Error:
+	ld a, $0
+	ret
+
+.Unused:
+	ld a, $1
+	ret
+; 12e55
+
+MonMenu_Flash: ; 12e55
+	callba OWFlash
+	ld a, [wFieldMoveSucceeded]
+	cp $1
+	jr nz, .Fail
+	ld b, $4
+	ld a, $2
+	ret
+
+.Fail:
+	ld a, $3
+	ret
+; 12e6a
+
+MonMenu_Strength: ; 12e6a
+	callba StrengthFunction
+	ld a, [wFieldMoveSucceeded]
+	cp $1
+	jr nz, .Fail
+	ld b, $4
+	ld a, $2
+	ret
+
+.Fail:
+	ld a, $3
+	ret
+; 12e7f
+
+MonMenu_Whirlpool: ; 12e7f
+	callba WhirlpoolFunction
+	ld a, [wFieldMoveSucceeded]
+	cp $1
+	jr nz, .Fail
+	ld b, $4
+	ld a, $2
+	ret
+
+.Fail:
+	ld a, $3
+	ret
+; 12e94
+
+MonMenu_Waterfall: ; 12e94
+	callba WaterfallFunction
+	ld a, [wFieldMoveSucceeded]
+	cp $1
+	jr nz, .Fail
+	ld b, $4
+	ld a, $2
+	ret
+
+.Fail:
+	ld a, $3
+	ret
+; 12ea9
+
+MonMenu_Teleport: ; 12ea9
+	callba TeleportFunction
+	ld a, [wFieldMoveSucceeded]
+	and a
+	jr z, .Fail
+	ld b, $4
+	ld a, $2
+	ret
+
+.Fail:
+	ld a, $3
+	ret
+; 12ebd
+
+MonMenu_Surf: ; 12ebd
+	callba SurfFunction
+	ld a, [wFieldMoveSucceeded]
+	and a
+	jr z, .Fail
+	ld b, $4
+	ld a, $2
+	ret
+
+.Fail:
+	ld a, $3
+	ret
+; 12ed1
+
+MonMenu_Dig: ; 12ed1
+	callba DigFunction
+	ld a, [wFieldMoveSucceeded]
+	cp $1
+	jr nz, .Fail
+	ld b, $4
+	ld a, $2
+	ret
+
+.Fail:
+	ld a, $3
+	ret
+; 12ee6
+
+MonMenu_Softboiled_MilkDrink: ; 12ee6
+	call .CheckMonHasEnoughHP
+	jr nc, .NotEnoughHP
+	callba Softboiled_MilkDrinkFunction
+	jr .finish
+
+.NotEnoughHP:
+	ld hl, .Text_NotEnoughHP
+	call PrintText
+
+.finish
+	xor a
+	ld [PartyMenuActionText], a
+	ld a, $3
+	ret
+; 12f00
+
+.Text_NotEnoughHP:
+	; Not enough HP!
+	text_jump UnknownText_0x1c1ce3
+	db "@"
+; 0x12f05
+
+.CheckMonHasEnoughHP:
+; Need to have at least (MaxHP / 5) HP left.
+	ld a, MON_MAXHP
+	call GetPartyParamLocation
+	ld a, [hli]
+	ld [hDividend + 0], a
+	ld a, [hl]
+	ld [hDividend + 1], a
+	ld a, 5
+	ld [hDivisor], a
+	ld b, 2
+	call Divide
+	ld a, MON_HP + 1
+	call GetPartyParamLocation
+	ld a, [hQuotient + 2]
+	sub [hl]
+	dec hl
+	ld a, [hQuotient + 1]
+	sbc [hl]
+	ret
+; 12f26
+
+MonMenu_Headbutt: ; 12f26
+	callba HeadbuttFunction
+	ld a, [wFieldMoveSucceeded]
+	cp $1
+	jr nz, .Fail
+	ld b, $4
+	ld a, $2
+	ret
+
+.Fail:
+	ld a, $3
+	ret
+; 12f3b
+
+MonMenu_RockSmash: ; 12f3b
+	callba RockSmashFunction
+	ld a, [wFieldMoveSucceeded]
+	cp $1
+	jr nz, .Fail
+	ld b, $4
+	ld a, $2
+	ret
+
+.Fail:
+	ld a, $3
+	ret
+; 12f50
+
+MonMenu_SweetScent: ; 12f50
+	callba SweetScentFromMenu
+	ld b, $4
+	ld a, $2
+	ret
+; 12f5b
+
+ChooseMoveToDelete: ; 12f5b
+	ld hl, Options
+	ld a, [hl]
+	push af
+	set NO_TEXT_SCROLL, [hl]
+	call LoadFontsBattleExtra
+	call .ChooseMoveToDelete
+	pop bc
+	ld a, b
+	ld [Options], a
+	push af
+	call ClearBGPalettes
+	pop af
+	ret
+; 12f73
+
+.ChooseMoveToDelete
+	call SetUpMoveScreenBG
+	ld de, DeleteMoveScreenAttrs
+	call SetMenuAttributes
+	call SetUpMoveList
+	ld hl, w2DMenuFlags1
+	set 6, [hl]
+	jr .enter_loop
+
+.loop
+	call ScrollingMenuJoypad
+	bit B_BUTTON_F, a
+	jp nz, .b_button
+	bit A_BUTTON_F, a
+	jp nz, .a_button
+
+.enter_loop
+	call PrepareToPlaceMoveData
+	call PlaceMoveData
+	jp .loop
+; 12f9c
+
+.a_button
+	and a
+	jr .finish
+
+.b_button
+	scf
+
+.finish
+	push af
+	xor a
+	ld [wSwitchMon], a
+	ld hl, w2DMenuFlags1
+	res 6, [hl]
+	call ClearSprites
+	call ClearTileMap
+	pop af
+	ret
+; 12fb2
+
+DeleteMoveScreenAttrs: ; 12fb2
+	db 3, 1
+	db 3, 1
+	db $40, $00
+	dn 2, 0
+	db D_UP | D_DOWN | A_BUTTON | B_BUTTON
+; 12fba
+
+ManagePokemonMoves: ; 12fba
+	ld a, [CurPartySpecies]
+	cp EGG
+	jr z, .egg
+	ld hl, Options
+	ld a, [hl]
+	push af
+	set NO_TEXT_SCROLL, [hl]
+	call MoveScreenLoop
+	pop af
+	ld [Options], a
+	call ClearBGPalettes
+
+.egg
+	ld a, $0
+	ret
+; 12fd5
+
+MoveScreenLoop: ; 12fd5
+	ld a, [CurPartyMon]
+	inc a
+	ld [wPartyMenuCursor], a
+	call SetUpMoveScreenBG
+	call Function132d3
+	ld de, MoveScreenAttributes
+	call SetMenuAttributes
+.loop
+	call SetUpMoveList
+	ld hl, w2DMenuFlags1
+	set 6, [hl]
+	jr .skip_joy
+
+.joy_loop
+	call ScrollingMenuJoypad
+	bit 1, a
+	jp nz, .b_button
+	bit 0, a
+	jp nz, .a_button
+	bit 4, a
+	jp nz, .d_right
+	bit 5, a
+	jp nz, .d_left
+
+.skip_joy
+	call PrepareToPlaceMoveData
+	ld a, [wMoveSwapBuffer]
+	and a
+	jr nz, .moving_move
+	call PlaceMoveData
+	jp .joy_loop
+
+.moving_move
+	ld a, " "
+	hlcoord 1, 11
+	ld bc, 5
+	call ByteFill
+	hlcoord 1, 12
+	lb bc, 5, SCREEN_WIDTH - 2
+	call ClearBox
+	hlcoord 1, 12
+	ld de, String_1316b
+	call PlaceString
+	jp .joy_loop
+.b_button
+	call PlayClickSFX
+	call WaitSFX
+	ld a, [wMoveSwapBuffer]
+	and a
+	jp z, .exit
+
+	ld a, [wMoveSwapBuffer]
+	ld [wMenuCursorY], a
+	xor a
+	ld [wMoveSwapBuffer], a
+	hlcoord 1, 2
+	lb bc, 8, SCREEN_WIDTH - 2
+	call ClearBox
+	jp .loop
+; 1305b
+
+.d_right
+	ld a, [wMoveSwapBuffer]
+	and a
+	jp nz, .joy_loop
+
+	ld a, [CurPartyMon]
+	ld b, a
+	push bc
+	call .cycle_right
+	pop bc
+	ld a, [CurPartyMon]
+	cp b
+	jp z, .joy_loop
+	jp MoveScreenLoop
+
+.d_left
+	ld a, [wMoveSwapBuffer]
+	and a
+	jp nz, .joy_loop
+	ld a, [CurPartyMon]
+	ld b, a
+	push bc
+	call .cycle_left
+	pop bc
+	ld a, [CurPartyMon]
+	cp b
+	jp z, .joy_loop
+	jp MoveScreenLoop
+
+.cycle_right
+	ld a, [CurPartyMon]
+	inc a
+	ld [CurPartyMon], a
+	ld c, a
+	ld b, 0
+	ld hl, PartySpecies
+	add hl, bc
+	ld a, [hl]
+	cp -1
+	jr z, .cycle_left
+	cp EGG
+	ret nz
+	jr .cycle_right
+
+.cycle_left
+	ld a, [CurPartyMon]
+	and a
+	ret z
+.cycle_left_loop
+	ld a, [CurPartyMon]
+	dec a
+	ld [CurPartyMon], a
+	ld c, a
+	ld b, 0
+	ld hl, PartySpecies
+	add hl, bc
+	ld a, [hl]
+	cp EGG
+	ret nz
+	ld a, [CurPartyMon]
+	and a
+	jr z, .cycle_right
+	jr .cycle_left_loop
+; 130c6
+
+.a_button
+	call PlayClickSFX
+	call WaitSFX
+	ld a, [wMoveSwapBuffer]
+	and a
+	jr nz, .place_move
+	ld a, [wMenuCursorY]
+	ld [wMoveSwapBuffer], a
+	call PlaceHollowCursor
+	jp .moving_move
+
+.place_move
+	ld hl, PartyMon1Moves
+	ld bc, PARTYMON_STRUCT_LENGTH
+	ld a, [CurPartyMon]
+	call AddNTimes
+	push hl
+	call .copy_move
+	pop hl
+	ld bc, $15
+	add hl, bc
+	call .copy_move
+	ld a, [wBattleMode]
+	jr z, .swap_moves
+	ld hl, BattleMonMoves
+	ld bc, $20
+	ld a, [CurPartyMon]
+	call AddNTimes
+	push hl
+	call .copy_move
+	pop hl
+	ld bc, 6
+	add hl, bc
+	call .copy_move
+
+.swap_moves
+	ld de, SFX_SWITCH_POKEMON
+	call PlaySFX
+	call WaitSFX
+	ld de, SFX_SWITCH_POKEMON
+	call PlaySFX
+	call WaitSFX
+	hlcoord 1, 2
+	lb bc, 8, 18
+	call ClearBox
+	hlcoord 10, 10
+	lb bc, 1, 9
+	call ClearBox
+	jp .loop
+; 1313a
+
+.copy_move
+	push hl
+	ld a, [wMenuCursorY]
+	dec a
+	ld c, a
+	ld b, $0
+	add hl, bc
+	ld d, h
+	ld e, l
+	pop hl
+	ld a, [wMoveSwapBuffer]
+	dec a
+	ld c, a
+	ld b, $0
+	add hl, bc
+	ld a, [de]
+	ld b, [hl]
+	ld [hl], a
+	ld a, b
+	ld [de], a
+	ret
+; 13154
+
+.exit
+	xor a
+	ld [wMoveSwapBuffer], a
+	ld hl, w2DMenuFlags1
+	res 6, [hl]
+	call ClearSprites
+	jp ClearTileMap
+; 13163
+
+MoveScreenAttributes: ; 13163
+	db 3, 1
+	db 3, 1
+	db $40, $00
+	dn 2, 0
+	db D_UP | D_DOWN | D_LEFT | D_RIGHT | A_BUTTON | B_BUTTON
+; 1316b
+
+String_1316b: ; 1316b
+	db "Where?@"
+; 13172
+
+SetUpMoveScreenBG: ; 13172
+	call ClearBGPalettes
+	call ClearTileMap
+	call ClearSprites
+	xor a
+	ld [hBGMapMode], a
+	callba LoadStatsScreenPageTilesGFX
+	callba ClearSpriteAnims2
+	ld a, [CurPartyMon]
+	ld e, a
+	ld d, $0
+	ld hl, PartySpecies
+	add hl, de
+	ld a, [hl]
+	ld [wd265], a
+	ld e, $2
+	callba LoadMenuMonIcon
+	hlcoord 0, 1
+	ld b, 9
+	ld c, 18
+	call TextBox
+	hlcoord 0, 11
+	ld b, 5
+	ld c, 18
+	call TextBox
+	hlcoord 2, 0
+	lb bc, 2, 3
+	call ClearBox
+	xor a
+	ld [MonType], a
+	ld hl, PartyMonNicknames
+	ld a, [CurPartyMon]
+	call GetNick
+	hlcoord 5, 1
+	call PlaceString
+	push bc
+	callba CopyPkmnToTempMon
+	pop hl
+	call PrintLevel
+	ld hl, PlayerHPPal
+	call SetHPPal
+	ld b, SCGB_MOVE_LIST
+	call GetSGBLayout
+	hlcoord 16, 0
+	lb bc, 1, 3
+	jp ClearBox
+; 131ef
+
+SetUpMoveList: ; 131ef
+	xor a
+	ld [hBGMapMode], a
+	ld [wMoveSwapBuffer], a
+	ld [MonType], a
+	predef CopyPkmnToTempMon
+	ld hl, TempMonMoves
+	ld de, wListMoves_MoveIndicesBuffer
+	ld bc, NUM_MOVES
+	call CopyBytes
+	ld a, SCREEN_WIDTH * 2
+	ld [Buffer1], a
+	hlcoord 2, 3
+	predef ListMoves
+	hlcoord 10, 4
+	predef ListMovePP
+	call WaitBGMap
+	call SetPalettes
+	ld a, [wNumMoves]
+	inc a
+	ld [w2DMenuNumRows], a
+	hlcoord 0, 11
+	ld b, 5
+	ld c, 18
+	jp TextBox
+; 13235
+
+PrepareToPlaceMoveData: ; 13235
+	ld hl, PartyMon1Moves
+	ld bc, PARTYMON_STRUCT_LENGTH
+	ld a, [CurPartyMon]
+	call AddNTimes
+	ld a, [wMenuCursorY]
+	dec a
+	ld c, a
+	ld b, $0
+	add hl, bc
+	ld a, [hl]
+	ld [CurMove], a
+	hlcoord 1, 12
+	lb bc, 5, 18
+	jp ClearBox
+; 13256
+
+PlaceMoveData: ; 13256
+	xor a
+	ld [hBGMapMode], a
+	hlcoord 0, 10
+	ld de, String_132ba
+	call PlaceString
+	hlcoord 0, 11
+	ld de, String_132c2
+	call PlaceString
+	hlcoord 12, 12
+	ld de, String_132ca
+	call PlaceString
+	ld a, [CurMove]
+	ld b, a
+	hlcoord 2, 12
+	predef PrintMoveType
+	ld a, [CurMove]
+	dec a
+	ld hl, Moves + MOVE_POWER
+	ld bc, MOVE_LENGTH
+	call AddNTimes
+	ld a, BANK(Moves)
+	call GetFarByte
+	hlcoord 16, 12
+	cp 2
+	jr c, .no_power
+	ld [wd265], a
+	ld de, wd265
+	lb bc, 1, 3
+	call PrintNum
+	jr .description
+
+.no_power
+	ld de, String_132cf
+	call PlaceString
+
+.description
+	hlcoord 1, 14
+	predef PrintMoveDesc
+	ld a, $1
+	ld [hBGMapMode], a
+	ret
+; 132ba
+
+String_132ba: ; 132ba
+	db "┌─────┐@"
+; 132c2
+String_132c2: ; 132c2
+	db "│TYPE/└@"
+; 132ca
+String_132ca: ; 132ca
+	db "ATK/@"
+; 132cf
+String_132cf: ; 132cf
+	db "---@"
+; 132d3
+
+Function132d3: ; 132d3
+	call Function132da
+	call Function132fe
+	ret
+; 132da
+
+Function132da: ; 132da
+	ld a, [CurPartyMon]
+	and a
+	ret z
+	ld c, a
+	ld e, a
+	ld d, 0
+	ld hl, PartyCount
+	add hl, de
+.loop
+	ld a, [hl]
+	and a
+	jr z, .prev
+	cp EGG
+	jr z, .prev
+	cp NUM_POKEMON + 1
+	jr c, .legal
+
+.prev
+	dec hl
+	dec c
+	jr nz, .loop
+	ret
+
+.legal
+	hlcoord 16, 0
+	ld [hl], "◀"
+	ret
+; 132fe
+
+Function132fe: ; 132fe
+	ld a, [CurPartyMon]
+	inc a
+	ld c, a
+	ld a, [PartyCount]
+	cp c
+	ret z
+	ld e, c
+	ld d, 0
+	ld hl, PartySpecies
+	add hl, de
+.loop
+	ld a, [hl]
+	cp -1
+	ret z
+	and a
+	jr z, .next
+	cp EGG
+	jr z, .next
+	cp NUM_POKEMON + 1
+	jr c, .legal
+
+.next
+	inc hl
+	jr .loop
+
+.legal
+	hlcoord 18, 0
+	ld [hl], "▶"
+	ret
+; 13327
--- a/engine/startmenu.asm
+++ /dev/null
@@ -1,1974 +1,0 @@
-StartMenu:: ; 125cd
-
-	call ClearWindowData
-
-	ld de, SFX_MENU
-	call PlaySFX
-
-	callba ReanchorBGMap_NoOAMUpdate
-
-	ld hl, StatusFlags2
-	bit 2, [hl] ; bug catching contest
-	ld hl, .MenuDataHeader
-	jr z, .GotMenuData
-	ld hl, .ContestMenuDataHeader
-.GotMenuData:
-
-	call LoadMenuDataHeader
-	call .SetUpMenuItems
-	ld a, [wBattleMenuCursorBuffer]
-	ld [wMenuCursorBuffer], a
-	call .DrawMenuAccount_
-	call DrawVariableLengthMenuBox
-	call .DrawBugContestStatusBox
-	call SafeUpdateSprites
-	call _OpenAndCloseMenu_HDMATransferTileMapAndAttrMap
-	callba LoadFonts_NoOAMUpdate
-	call .DrawBugContestStatus
-	call UpdateTimePals
-	jr .Select
-
-.Reopen:
-	call UpdateSprites
-	call UpdateTimePals
-	call .SetUpMenuItems
-	ld a, [wBattleMenuCursorBuffer]
-	ld [wMenuCursorBuffer], a
-
-.Select:
-	call .GetInput
-	jr c, .Exit
-	call .DrawMenuAccount
-	ld a, [wMenuCursorBuffer]
-	ld [wBattleMenuCursorBuffer], a
-	call PlayClickSFX
-	call PlaceHollowCursor
-	call .OpenMenu
-
-; Menu items have different return functions.
-; For example, saving exits the menu.
-	ld hl, .MenuReturns
-	ld e, a
-	ld d, 0
-	add hl, de
-	add hl, de
-	ld a, [hli]
-	ld h, [hl]
-	ld l, a
-	jp hl
-
-.MenuReturns:
-	dw .Reopen
-	dw .Exit
-	dw .ExitMenuCallFuncCloseText
-	dw .ExitMenuRunScriptCloseText
-	dw .ExitMenuRunScript
-	dw .ReturnEnd
-	dw .ReturnRedraw
-
-.Exit:
-	ld a, [hOAMUpdate]
-	push af
-	ld a, 1
-	ld [hOAMUpdate], a
-	call LoadFontsExtra
-	pop af
-	ld [hOAMUpdate], a
-.ReturnEnd:
-	call ExitMenu
-.ReturnEnd2:
-	call CloseText
-	call UpdateTimePals
-	ret
-
-.GetInput:
-; Return carry on exit, and no-carry on selection.
-	xor a
-	ld [hBGMapMode], a
-	call .DrawMenuAccount
-	call SetUpMenu
-	ld a, $ff
-	ld [MenuSelection], a
-.loop
-	call .PrintMenuAccount
-	call GetScrollingMenuJoypad
-	ld a, [wMenuJoypad]
-	cp B_BUTTON
-	jr z, .b
-	cp A_BUTTON
-	jr z, .a
-	jr .loop
-.a
-	call PlayClickSFX
-	and a
-	ret
-.b
-	scf
-	ret
-; 12691
-
-.ExitMenuRunScript: ; 12691
-	call ExitMenu
-	ld a, HMENURETURN_SCRIPT
-	ld [hMenuReturn], a
-	ret
-; 12699
-
-.ExitMenuRunScriptCloseText: ; 12699
-	call ExitMenu
-	ld a, HMENURETURN_SCRIPT
-	ld [hMenuReturn], a
-	jr .ReturnEnd2
-; 126a2
-
-.ExitMenuCallFuncCloseText: ; 126a2
-	call ExitMenu
-	ld hl, wQueuedScriptAddr
-	ld a, [hli]
-	ld h, [hl]
-	ld l, a
-	ld a, [wQueuedScriptBank]
-	rst FarCall
-	jr .ReturnEnd2
-; 126b1
-
-.ReturnRedraw: ; 126b1
-	call .Clear
-	jp .Reopen
-; 126b7
-
-.Clear: ; 126b7
-	call ClearBGPalettes
-	call Call_ExitMenu
-	call ReloadTilesetAndPalettes
-	call .DrawMenuAccount_
-	call DrawVariableLengthMenuBox
-	call .DrawBugContestStatus
-	call UpdateSprites
-	call ret_d90
-	call FinishExitMenu
-	ret
-; 126d3
-
-
-.MenuDataHeader:
-	db $40 ; tile backup
-	db 0, 10 ; start coords
-	db 17, 19 ; end coords
-	dw .MenuData
-	db 1 ; default selection
-
-.ContestMenuDataHeader:
-	db $40 ; tile backup
-	db 2, 10 ; start coords
-	db 17, 19 ; end coords
-	dw .MenuData
-	db 1 ; default selection
-
-.MenuData:
-	db %10101000 ; x padding, wrap around, start can close
-	dn 0, 0 ; rows, columns
-	dw MenuItemsList
-	dw .MenuString
-	dw .Items
-
-.Items:
-	dw StartMenu_Pokedex,  .PokedexString,  .PokedexDesc
-	dw StartMenu_Pokemon,  .PartyString,    .PartyDesc
-	dw StartMenu_Pack,     .PackString,     .PackDesc
-	dw StartMenu_Status,   .StatusString,   .StatusDesc
-	dw StartMenu_Save,     .SaveString,     .SaveDesc
-	dw StartMenu_Option,   .OptionString,   .OptionDesc
-	dw StartMenu_Exit,     .ExitString,     .ExitDesc
-	dw StartMenu_Pokegear, .PokegearString, .PokegearDesc
-	dw StartMenu_Quit,     .QuitString,     .QuitDesc
-
-.PokedexString: 	db "#DEX@"
-.PartyString:   	db "#MON@"
-.PackString:    	db "PACK@"
-.StatusString:  	db "<PLAYER>@"
-.SaveString:    	db "SAVE@"
-.OptionString:  	db "OPTION@"
-.ExitString:    	db "EXIT@"
-.PokegearString:	db $24, "GEAR@"
-.QuitString:    	db "QUIT@"
-
-.PokedexDesc:  db   "#MON"
-	next "database@"
-
-.PartyDesc:    db   "Party ", $4a
-	next "status@"
-
-.PackDesc:     db   "Contains"
-	next "items@"
-
-.PokegearDesc: db   "Trainer's"
-	next "key device@"
-
-.StatusDesc:   db   "Your own"
-	next "status@"
-
-.SaveDesc:     db   "Save your"
-	next "progress@"
-
-.OptionDesc:   db   "Change"
-	next "settings@"
-
-.ExitDesc:     db   "Close this"
-	next "menu@"
-
-.QuitDesc:     db   "Quit and"
-	next "be judged.@"
-
-
-.OpenMenu: ; 127e5
-	ld a, [MenuSelection]
-	call .GetMenuAccountTextPointer
-	ld a, [hli]
-	ld h, [hl]
-	ld l, a
-	jp hl
-; 127ef
-
-.MenuString: ; 127ef
-	push de
-	ld a, [MenuSelection]
-	call .GetMenuAccountTextPointer
-	inc hl
-	inc hl
-	ld a, [hli]
-	ld d, [hl]
-	ld e, a
-	pop hl
-	call PlaceString
-	ret
-; 12800
-
-.MenuDesc: ; 12800
-	push de
-	ld a, [MenuSelection]
-	cp $ff
-	jr z, .none
-	call .GetMenuAccountTextPointer
-rept 4
-	inc hl
-endr
-	ld a, [hli]
-	ld d, [hl]
-	ld e, a
-	pop hl
-	call PlaceString
-	ret
-.none
-	pop de
-	ret
-; 12819
-
-
-.GetMenuAccountTextPointer: ; 12819
-	ld e, a
-	ld d, 0
-	ld hl, wMenuData2PointerTableAddr
-	ld a, [hli]
-	ld h, [hl]
-	ld l, a
-rept 6
-	add hl, de
-endr
-	ret
-; 12829
-
-
-.SetUpMenuItems: ; 12829
-	xor a
-	ld [wWhichIndexSet], a
-	call .FillMenuList
-
-	ld hl, StatusFlags
-	bit 0, [hl]
-	jr z, .no_pokedex
-	ld a, 0 ; pokedex
-	call .AppendMenuList
-.no_pokedex
-
-	ld a, [PartyCount]
-	and a
-	jr z, .no_pokemon
-	ld a, 1 ; pokemon
-	call .AppendMenuList
-.no_pokemon
-
-	ld a, [wLinkMode]
-	and a
-	jr nz, .no_pack
-	ld hl, StatusFlags2
-	bit 2, [hl] ; bug catching contest
-	jr nz, .no_pack
-	ld a, 2 ; pack
-	call .AppendMenuList
-.no_pack
-
-	ld hl, wPokegearFlags
-	bit 7, [hl]
-	jr z, .no_pokegear
-	ld a, 7 ; pokegear
-	call .AppendMenuList
-.no_pokegear
-
-	ld a, 3 ; status
-	call .AppendMenuList
-
-	ld a, [wLinkMode]
-	and a
-	jr nz, .no_save
-	ld hl, StatusFlags2
-	bit 2, [hl] ; bug catching contest
-	ld a, 8 ; quit
-	jr nz, .write
-	ld a, 4 ; save
-.write
-	call .AppendMenuList
-.no_save
-
-	ld a, 5 ; option
-	call .AppendMenuList
-	ld a, 6 ; exit
-	call .AppendMenuList
-	ld a, c
-	ld [MenuItemsList], a
-	ret
-; 1288d
-
-
-.FillMenuList: ; 1288d
-	xor a
-	ld hl, MenuItemsList
-	ld [hli], a
-	ld a, -1
-	ld bc, MenuItemsListEnd - (MenuItemsList + 1)
-	call ByteFill
-	ld de, MenuItemsList + 1
-	ld c, 0
-	ret
-; 128a0
-
-.AppendMenuList: ; 128a0
-	ld [de], a
-	inc de
-	inc c
-	ret
-; 128a4
-
-.DrawMenuAccount_: ; 128a4
-	jp .DrawMenuAccount
-; 128a7
-
-.PrintMenuAccount: ; 128a7
-	call .IsMenuAccountOn
-	ret z
-	call .DrawMenuAccount
-	decoord 0, 14
-	jp .MenuDesc
-; 128b4
-
-.DrawMenuAccount: ; 128b4
-	call .IsMenuAccountOn
-	ret z
-	hlcoord 0, 13
-	lb bc, 5, 10
-	call ClearBox
-	hlcoord 0, 13
-	ld b, 3
-	ld c, 8
-	jp TextBoxPalette
-; 128cb
-
-.IsMenuAccountOn: ; 128cb
-	ld a, [Options2]
-	and 1
-	ret
-; 128d1
-
-.DrawBugContestStatusBox: ; 128d1
-	ld hl, StatusFlags2
-	bit 2, [hl] ; bug catching contest
-	ret z
-	callba StartMenu_DrawBugContestStatusBox
-	ret
-; 128de
-
-.DrawBugContestStatus: ; 128de
-	ld hl, StatusFlags2
-	bit 2, [hl] ; bug catching contest
-	jr nz, .contest
-	ret
-.contest
-	callba StartMenu_PrintBugContestStatus
-	ret
-; 128ed
-
-
-StartMenu_Exit: ; 128ed
-; Exit the menu.
-
-	ld a, 1
-	ret
-; 128f0
-
-
-StartMenu_Quit: ; 128f0
-; Retire from the bug catching contest.
-
-	ld hl, .EndTheContestText
-	call StartMenuYesNo
-	jr c, .DontEndContest
-	ld a, BANK(BugCatchingContestReturnToGateScript)
-	ld hl, BugCatchingContestReturnToGateScript
-	call FarQueueScript
-	ld a, 4
-	ret
-
-.DontEndContest:
-	ld a, 0
-	ret
-
-.EndTheContestText:
-	text_jump UnknownText_0x1c1a6c
-	db "@"
-; 1290b
-
-
-StartMenu_Save: ; 1290b
-; Save the game.
-
-	call BufferScreen
-	callba SaveMenu
-	jr nc, .asm_12919
-	ld a, 0
-	ret
-.asm_12919
-	ld a, 1
-	ret
-; 1291c
-
-
-StartMenu_Option: ; 1291c
-; Game options.
-
-	call FadeToMenu
-	callba OptionsMenu
-	ld a, 6
-	ret
-; 12928
-
-
-StartMenu_Status: ; 12928
-; Player status.
-
-	call FadeToMenu
-	callba TrainerCard
-	call CloseSubmenu
-	ld a, 0
-	ret
-; 12937
-
-
-StartMenu_Pokedex: ; 12937
-
-	ld a, [PartyCount]
-	and a
-	jr z, .asm_12949
-
-	call FadeToMenu
-	callba Pokedex
-	call CloseSubmenu
-
-.asm_12949
-	ld a, 0
-	ret
-; 1294c
-
-
-StartMenu_Pokegear: ; 1294c
-
-	call FadeToMenu
-	callba PokeGear
-	call CloseSubmenu
-	ld a, 0
-	ret
-; 1295b
-
-
-StartMenu_Pack: ; 1295b
-
-	call FadeToMenu
-	callba Pack
-	ld a, [wcf66]
-	and a
-	jr nz, .used_item
-	call CloseSubmenu
-	ld a, 0
-	ret
-
-.used_item
-	call ExitAllMenus
-	ld a, 4
-	ret
-; 12976
-
-
-StartMenu_Pokemon: ; 12976
-
-	ld a, [PartyCount]
-	and a
-	jr z, .return
-
-	call FadeToMenu
-
-.choosemenu
-	xor a
-	ld [PartyMenuActionText], a ; Choose a POKéMON.
-	call ClearBGPalettes
-
-.menu
-	callba LoadPartyMenuGFX
-	callba InitPartyMenuWithCancel
-	callba InitPartyMenuGFX
-
-.menunoreload
-	callba WritePartyMenuTilemap
-	callba PrintPartyMenuText
-	call WaitBGMap
-	call SetPalettes ; load regular palettes?
-	call DelayFrame
-	callba PartyMenuSelect
-	jr c, .return ; if cancelled or pressed B
-
-	call PokemonActionSubmenu
-	cp 3
-	jr z, .menu
-	cp 0
-	jr z, .choosemenu
-	cp 1
-	jr z, .menunoreload
-	cp 2
-	jr z, .quit
-
-.return
-	call CloseSubmenu
-	ld a, 0
-	ret
-
-.quit
-	ld a, b
-	push af
-	call ExitAllMenus
-	pop af
-	ret
-; 129d5
-
-HasNoItems: ; 129d5
-	ld a, [NumItems]
-	and a
-	ret nz
-	ld a, [NumKeyItems]
-	and a
-	ret nz
-	ld a, [NumBalls]
-	and a
-	ret nz
-	ld hl, TMsHMs
-	ld b, NUM_TMS + NUM_HMS
-.loop
-	ld a, [hli]
-	and a
-	jr nz, .done
-	dec b
-	jr nz, .loop
-	scf
-	ret
-.done
-	and a
-	ret
-
-TossItemFromPC: ; 129f4
-	push de
-	call PartyMonItemName
-	callba _CheckTossableItem
-	ld a, [wItemAttributeParamBuffer]
-	and a
-	jr nz, .key_item
-	ld hl, .TossHowMany
-	call MenuTextBox
-	callba SelectQuantityToToss
-	push af
-	call CloseWindow
-	call ExitMenu
-	pop af
-	jr c, .quit
-	ld hl, .ConfirmToss
-	call MenuTextBox
-	call YesNoBox
-	push af
-	call ExitMenu
-	pop af
-	jr c, .quit
-	pop hl
-	ld a, [CurItemQuantity]
-	call TossItem
-	call PartyMonItemName
-	ld hl, .TossedThisMany
-	call MenuTextBox
-	call ExitMenu
-	and a
-	ret
-
-.key_item
-	call .CantToss
-.quit
-	pop hl
-	scf
-	ret
-
-.TossHowMany:
-	; Toss out how many @ (S)?
-	text_jump UnknownText_0x1c1a90
-	db "@"
-
-.ConfirmToss:
-	; Throw away @ @ (S)?
-	text_jump UnknownText_0x1c1aad
-	db "@"
-
-.TossedThisMany:
-	; Discarded @ (S).
-	text_jump UnknownText_0x1c1aca
-	db "@"
-
-.CantToss:
-	ld hl, .TooImportantToToss
-	call MenuTextBoxBackup
-	ret
-
-.TooImportantToToss:
-	; That's too impor- tant to toss out!
-	text_jump UnknownText_0x1c1adf
-	db "@"
-; 0x12a60
-
-CantUseItem: ; 12a60
-	ld hl, CantUseItemText
-	call MenuTextBoxWaitButton
-	ret
-; 12a67
-
-CantUseItemText: ; 12a67
-	text_jump UnknownText_0x1c1b03
-	db "@"
-; 12a6c
-
-
-PartyMonItemName: ; 12a6c
-	ld a, [CurItem]
-	ld [wd265], a
-	call GetItemName
-	call CopyName1
-	ret
-; 12a79
-
-
-CancelPokemonAction: ; 12a79
-	callba InitPartyMenuWithCancel
-	callba UnfreezeMonIcons
-	ld a, 1
-	ret
-; 12a88
-
-
-PokemonActionSubmenu: ; 12a88
-	hlcoord 1, 15
-	lb bc, 2, 18
-	call ClearBox
-	callba MonSubmenu
-	call GetCurNick
-	ld a, [MenuSelection]
-	ld hl, .Actions
-	ld de, 3
-	call IsInArray
-	jr nc, .nothing
-
-	inc hl
-	ld a, [hli]
-	ld h, [hl]
-	ld l, a
-	jp hl
-
-.nothing
-	ld a, 0
-	ret
-
-.Actions:
-	dbw MONMENU_CUT,        MonMenu_Cut ; Cut
-	dbw MONMENU_FLY,        MonMenu_Fly ; Fly
-	dbw MONMENU_SURF,       MonMenu_Surf ; Surf
-	dbw MONMENU_STRENGTH,   MonMenu_Strength ; Strength
-	dbw MONMENU_FLASH,      MonMenu_Flash ; Flash
-	dbw MONMENU_WHIRLPOOL,  MonMenu_Whirlpool ; Whirlpool
-	dbw MONMENU_DIG,        MonMenu_Dig ; Dig
-	dbw MONMENU_TELEPORT,   MonMenu_Teleport ; Teleport
-	dbw MONMENU_SOFTBOILED, MonMenu_Softboiled_MilkDrink ; Softboiled
-	dbw MONMENU_MILKDRINK,  MonMenu_Softboiled_MilkDrink ; MilkDrink
-	dbw MONMENU_HEADBUTT,   MonMenu_Headbutt ; Headbutt
-	dbw MONMENU_WATERFALL,  MonMenu_Waterfall ; Waterfall
-	dbw MONMENU_ROCKSMASH,  MonMenu_RockSmash ; RockSmash
-	dbw MONMENU_SWEETSCENT, MonMenu_SweetScent ; SweetScent
-	dbw MONMENU_STATS,      OpenPartyStats
-	dbw MONMENU_SWITCH,     SwitchPartyMons
-	dbw MONMENU_ITEM,       GiveTakePartyMonItem
-	dbw MONMENU_CANCEL,     CancelPokemonAction
-	dbw MONMENU_MOVE,       ManagePokemonMoves ; move
-	dbw MONMENU_MAIL,       MonMailAction ; mail
-; 12aec
-
-
-SwitchPartyMons: ; 12aec
-
-; Don't try if there's nothing to switch!
-	ld a, [PartyCount]
-	cp 2
-	jr c, .DontSwitch
-
-	ld a, [CurPartyMon]
-	inc a
-	ld [wSwitchMon], a
-
-	callba HoldSwitchmonIcon
-	callba InitPartyMenuNoCancel
-
-	ld a, PARTYMENUACTION_MOVE
-	ld [PartyMenuActionText], a
-	callba WritePartyMenuTilemap
-	callba PrintPartyMenuText
-
-	hlcoord 0, 1
-	ld bc, 20 * 2
-	ld a, [wSwitchMon]
-	dec a
-	call AddNTimes
-	ld [hl], "▷"
-	call WaitBGMap
-	call SetPalettes
-	call DelayFrame
-
-	callba PartyMenuSelect
-	bit 1, b
-	jr c, .DontSwitch
-
-	callba _SwitchPartyMons
-
-	xor a
-	ld [PartyMenuActionText], a
-
-	callba LoadPartyMenuGFX
-	callba InitPartyMenuWithCancel
-	callba InitPartyMenuGFX
-
-	ld a, 1
-	ret
-
-.DontSwitch:
-	xor a
-	ld [PartyMenuActionText], a
-	call CancelPokemonAction
-	ret
-; 12b60
-
-
-GiveTakePartyMonItem: ; 12b60
-
-; Eggs can't hold items!
-	ld a, [CurPartySpecies]
-	cp EGG
-	jr z, .cancel
-
-	ld hl, GiveTakeItemMenuData
-	call LoadMenuDataHeader
-	call VerticalMenu
-	call ExitMenu
-	jr c, .cancel
-
-	call GetCurNick
-	ld hl, StringBuffer1
-	ld de, wMonOrItemNameBuffer
-	ld bc, PKMN_NAME_LENGTH
-	call CopyBytes
-	ld a, [wMenuCursorY]
-	cp 1
-	jr nz, .take
-
-	call LoadStandardMenuDataHeader
-	call ClearPalettes
-	call .GiveItem
-	call ClearPalettes
-	call LoadFontsBattleExtra
-	call ExitMenu
-	ld a, 0
-	ret
-
-.take
-	call TakePartyItem
-	ld a, 3
-	ret
-
-.cancel
-	ld a, 3
-	ret
-; 12ba9
-
-
-.GiveItem:
-
-	callba DepositSellInitPackBuffers
-
-.loop
-	callba DepositSellPack
-
-	ld a, [wcf66]
-	and a
-	jr z, .quit
-
-	ld a, [wcf65]
-	cp 2
-	jr z, .next
-
-	call CheckTossableItem
-	ld a, [wItemAttributeParamBuffer]
-	and a
-	jr nz, .next
-
-	call TryGiveItemToPartymon
-	jr .quit
-
-.next
-	ld hl, CantBeHeldText
-	call MenuTextBoxBackup
-	jr .loop
-
-.quit
-	ret
-; 12bd9
-
-
-TryGiveItemToPartymon: ; 12bd9
-
-	call SpeechTextBox
-	call PartyMonItemName
-	call GetPartyItemLocation
-	ld a, [hl]
-	and a
-	jr z, .give_item_to_mon
-
-	push hl
-	ld d, a
-	callba ItemIsMail
-	pop hl
-	jr c, .please_remove_mail
-	ld a, [hl]
-	jr .already_holding_item
-
-.give_item_to_mon
-	call GiveItemToPokemon
-	ld hl, MadeHoldText
-	call MenuTextBoxBackup
-	call GivePartyItem
-	ret
-
-.please_remove_mail
-	ld hl, PleaseRemoveMailText
-	call MenuTextBoxBackup
-	ret
-
-.already_holding_item
-	ld [wd265], a
-	call GetItemName
-	ld hl, SwitchAlreadyHoldingText
-	call StartMenuYesNo
-	jr c, .abort
-
-	call GiveItemToPokemon
-	ld a, [wd265]
-	push af
-	ld a, [CurItem]
-	ld [wd265], a
-	pop af
-	ld [CurItem], a
-	call ReceiveItemFromPokemon
-	jr nc, .bag_full
-
-	ld hl, TookAndMadeHoldText
-	call MenuTextBoxBackup
-	ld a, [wd265]
-	ld [CurItem], a
-	call GivePartyItem
-	ret
-
-.bag_full
-	ld a, [wd265]
-	ld [CurItem], a
-	call ReceiveItemFromPokemon
-	ld hl, ItemStorageIsFullText
-	call MenuTextBoxBackup
-
-.abort
-	ret
-; 12c4c
-
-
-GivePartyItem: ; 12c4c
-
-	call GetPartyItemLocation
-	ld a, [CurItem]
-	ld [hl], a
-	ld d, a
-	callba ItemIsMail
-	jr nc, .done
-	call ComposeMailMessage
-
-.done
-	ret
-; 12c60
-
-
-TakePartyItem: ; 12c60
-
-	call SpeechTextBox
-	call GetPartyItemLocation
-	ld a, [hl]
-	and a
-	jr z, .asm_12c8c
-
-	ld [CurItem], a
-	call ReceiveItemFromPokemon
-	jr nc, .asm_12c94
-
-	callba ItemIsMail
-	call GetPartyItemLocation
-	ld a, [hl]
-	ld [wd265], a
-	ld [hl], NO_ITEM
-	call GetItemName
-	ld hl, TookFromText
-	call MenuTextBoxBackup
-	jr .asm_12c9a
-
-.asm_12c8c
-	ld hl, IsntHoldingAnythingText
-	call MenuTextBoxBackup
-	jr .asm_12c9a
-
-.asm_12c94
-	ld hl, ItemStorageIsFullText
-	call MenuTextBoxBackup
-
-.asm_12c9a
-	ret
-; 12c9b
-
-
-GiveTakeItemMenuData: ; 12c9b
-	db %01010000
-	db 12, 12 ; start coords
-	db 17, 19 ; end coords
-	dw .Items
-	db 1 ; default option
-
-.Items:
-	db %10000000 ; x padding
-	db 2 ; # items
-	db "GIVE@"
-	db "TAKE@"
-; 12caf
-
-
-TookAndMadeHoldText: ; 12caf
-	text_jump UnknownText_0x1c1b2c
-	db "@"
-; 12cb4
-
-MadeHoldText: ; 12cb4
-	text_jump UnknownText_0x1c1b57
-	db "@"
-; 12cb9
-
-PleaseRemoveMailText: ; 12cb9
-	text_jump UnknownText_0x1c1b6f
-	db "@"
-; 12cbe
-
-IsntHoldingAnythingText: ; 12cbe
-	text_jump UnknownText_0x1c1b8e
-	db "@"
-; 12cc3
-
-ItemStorageIsFullText: ; 12cc3
-	text_jump UnknownText_0x1c1baa
-	db "@"
-; 12cc8
-
-TookFromText: ; 12cc8
-	text_jump UnknownText_0x1c1bc4
-	db "@"
-; 12ccd
-
-SwitchAlreadyHoldingText: ; 12ccd
-	text_jump UnknownText_0x1c1bdc
-	db "@"
-; 12cd2
-
-CantBeHeldText: ; 12cd2
-	text_jump UnknownText_0x1c1c09
-	db "@"
-; 12cd7
-
-
-GetPartyItemLocation: ; 12cd7
-	push af
-	ld a, MON_ITEM
-	call GetPartyParamLocation
-	pop af
-	ret
-; 12cdf
-
-
-ReceiveItemFromPokemon: ; 12cdf
-	ld a, $1
-	ld [wItemQuantityChangeBuffer], a
-	ld hl, NumItems
-	jp ReceiveItem
-; 12cea
-
-
-GiveItemToPokemon: ; 12cea (4:6cea)
-	ld a, $1
-	ld [wItemQuantityChangeBuffer], a
-	ld hl, NumItems
-	jp TossItem
-
-StartMenuYesNo: ; 12cf5
-	call MenuTextBox
-	call YesNoBox
-	jp ExitMenu
-; 12cfe
-
-
-ComposeMailMessage: ; 12cfe (4:6cfe)
-	ld de, wTempMailMessage
-	callba _ComposeMailMessage
-	ld hl, PlayerName
-	ld de, wTempMailAuthor
-	ld bc, NAME_LENGTH - 1
-	call CopyBytes
-	ld hl, PlayerID
-	ld bc, 2
-	call CopyBytes
-	ld a, [CurPartySpecies]
-	ld [de], a
-	inc de
-	ld a, [CurItem]
-	ld [de], a
-	ld a, [CurPartyMon]
-	ld hl, sPartyMail
-	ld bc, MAIL_STRUCT_LENGTH
-	call AddNTimes
-	ld d, h
-	ld e, l
-	ld hl, wTempMail
-	ld bc, MAIL_STRUCT_LENGTH
-	ld a, BANK(sPartyMail)
-	call GetSRAMBank
-	call CopyBytes
-	call CloseSRAM
-	ret
-
-MonMailAction: ; 12d45
-; If in the time capsule or trade center,
-; selecting the mail only allows you to
-; read the mail.
-	ld a, [wLinkMode]
-	cp LINK_TIMECAPSULE
-	jr z, .read
-	cp LINK_TRADECENTER
-	jr z, .read
-
-; Show the READ/TAKE/QUIT menu.
-	ld hl, .MenuDataHeader
-	call LoadMenuDataHeader
-	call VerticalMenu
-	call ExitMenu
-
-; Interpret the menu.
-	jp c, .done
-	ld a, [wMenuCursorY]
-	cp $1
-	jr z, .read
-	cp $2
-	jr z, .take
-	jp .done
-
-.read
-	callba ReadPartyMonMail
-	ld a, $0
-	ret
-
-.take
-	ld hl, .sendmailtopctext
-	call StartMenuYesNo
-	jr c, .RemoveMailToBag
-	ld a, [CurPartyMon]
-	ld b, a
-	callba SendMailToPC
-	jr c, .MailboxFull
-	ld hl, .sentmailtopctext
-	call MenuTextBoxBackup
-	jr .done
-
-.MailboxFull:
-	ld hl, .mailboxfulltext
-	call MenuTextBoxBackup
-	jr .done
-
-.RemoveMailToBag:
-	ld hl, .mailwilllosemessagetext
-	call StartMenuYesNo
-	jr c, .done
-	call GetPartyItemLocation
-	ld a, [hl]
-	ld [CurItem], a
-	call ReceiveItemFromPokemon
-	jr nc, .BagIsFull
-	call GetPartyItemLocation
-	ld [hl], $0
-	call GetCurNick
-	ld hl, .tookmailfrommontext
-	call MenuTextBoxBackup
-	jr .done
-
-.BagIsFull:
-	ld hl, .bagfulltext
-	call MenuTextBoxBackup
-	jr .done
-
-.done
-	ld a, $3
-	ret
-; 12dc9
-
-
-.MenuDataHeader:
-	db $40 ; flags
-	db 10, 12 ; start coords
-	db 17, 19 ; end coords
-	dw .MenuData2
-	db 1 ; default option
-; 0x12dd1
-
-.MenuData2:
-	db $80 ; flags
-	db 3 ; items
-	db "READ@"
-	db "TAKE@"
-	db "QUIT@"
-; 0x12de2
-
-
-.mailwilllosemessagetext
-; The MAIL will lose its message. OK?
-	text_jump UnknownText_0x1c1c22
-	db "@"
-; 0x12de7
-
-.tookmailfrommontext
-; MAIL detached from <POKEMON>.
-	text_jump UnknownText_0x1c1c47
-	db "@"
-; 0x12dec
-
-.bagfulltext
-; There's no space for removing MAIL.
-	text_jump UnknownText_0x1c1c62
-	db "@"
-; 0x12df1
-
-.sendmailtopctext
-; Send the removed MAIL to your PC?
-	text_jump UnknownText_0x1c1c86
-	db "@"
-; 0x12df6
-
-.mailboxfulltext
-; Your PC's MAILBOX is full.
-	text_jump UnknownText_0x1c1ca9
-	db "@"
-; 0x12dfb
-
-.sentmailtopctext
-; The MAIL was sent to your PC.
-	text_jump UnknownText_0x1c1cc4
-	db "@"
-; 0x12e00
-
-
-OpenPartyStats: ; 12e00
-	call LoadStandardMenuDataHeader
-	call ClearSprites
-; PartyMon
-	xor a
-	ld [MonType], a
-	call LowVolume
-	predef StatsScreenInit
-	call MaxVolume
-	call Call_ExitMenu
-	ld a, 0
-	ret
-; 12e1b
-
-
-MonMenu_Cut: ; 12e1b
-	callba CutFunction
-	ld a, [wFieldMoveSucceeded]
-	cp $1
-	jr nz, .Fail
-	ld b, $4
-	ld a, $2
-	ret
-
-.Fail:
-	ld a, $3
-	ret
-; 12e30
-
-
-MonMenu_Fly: ; 12e30
-	callba FlyFunction
-	ld a, [wFieldMoveSucceeded]
-	cp $2
-	jr z, .Fail
-	cp $0
-	jr z, .Error
-	callba TrainerRankings_Fly
-	ld b, $4
-	ld a, $2
-	ret
-
-.Fail:
-	ld a, $3
-	ret
-
-.Error:
-	ld a, $0
-	ret
-
-.Unused:
-	ld a, $1
-	ret
-; 12e55
-
-MonMenu_Flash: ; 12e55
-	callba OWFlash
-	ld a, [wFieldMoveSucceeded]
-	cp $1
-	jr nz, .Fail
-	ld b, $4
-	ld a, $2
-	ret
-
-.Fail:
-	ld a, $3
-	ret
-; 12e6a
-
-MonMenu_Strength: ; 12e6a
-	callba StrengthFunction
-	ld a, [wFieldMoveSucceeded]
-	cp $1
-	jr nz, .Fail
-	ld b, $4
-	ld a, $2
-	ret
-
-.Fail:
-	ld a, $3
-	ret
-; 12e7f
-
-MonMenu_Whirlpool: ; 12e7f
-	callba WhirlpoolFunction
-	ld a, [wFieldMoveSucceeded]
-	cp $1
-	jr nz, .Fail
-	ld b, $4
-	ld a, $2
-	ret
-
-.Fail:
-	ld a, $3
-	ret
-; 12e94
-
-MonMenu_Waterfall: ; 12e94
-	callba WaterfallFunction
-	ld a, [wFieldMoveSucceeded]
-	cp $1
-	jr nz, .Fail
-	ld b, $4
-	ld a, $2
-	ret
-
-.Fail:
-	ld a, $3
-	ret
-; 12ea9
-
-MonMenu_Teleport: ; 12ea9
-	callba TeleportFunction
-	ld a, [wFieldMoveSucceeded]
-	and a
-	jr z, .Fail
-	ld b, $4
-	ld a, $2
-	ret
-
-.Fail:
-	ld a, $3
-	ret
-; 12ebd
-
-MonMenu_Surf: ; 12ebd
-	callba SurfFunction
-	ld a, [wFieldMoveSucceeded]
-	and a
-	jr z, .Fail
-	ld b, $4
-	ld a, $2
-	ret
-
-.Fail:
-	ld a, $3
-	ret
-; 12ed1
-
-MonMenu_Dig: ; 12ed1
-	callba DigFunction
-	ld a, [wFieldMoveSucceeded]
-	cp $1
-	jr nz, .Fail
-	ld b, $4
-	ld a, $2
-	ret
-
-.Fail:
-	ld a, $3
-	ret
-; 12ee6
-
-MonMenu_Softboiled_MilkDrink: ; 12ee6
-	call .CheckMonHasEnoughHP
-	jr nc, .NotEnoughHP
-	callba Softboiled_MilkDrinkFunction
-	jr .finish
-
-.NotEnoughHP:
-	ld hl, .Text_NotEnoughHP
-	call PrintText
-
-.finish
-	xor a
-	ld [PartyMenuActionText], a
-	ld a, $3
-	ret
-; 12f00
-
-.Text_NotEnoughHP:
-	; Not enough HP!
-	text_jump UnknownText_0x1c1ce3
-	db "@"
-; 0x12f05
-
-.CheckMonHasEnoughHP:
-; Need to have at least (MaxHP / 5) HP left.
-	ld a, MON_MAXHP
-	call GetPartyParamLocation
-	ld a, [hli]
-	ld [hDividend + 0], a
-	ld a, [hl]
-	ld [hDividend + 1], a
-	ld a, 5
-	ld [hDivisor], a
-	ld b, 2
-	call Divide
-	ld a, MON_HP + 1
-	call GetPartyParamLocation
-	ld a, [hQuotient + 2]
-	sub [hl]
-	dec hl
-	ld a, [hQuotient + 1]
-	sbc [hl]
-	ret
-; 12f26
-
-MonMenu_Headbutt: ; 12f26
-	callba HeadbuttFunction
-	ld a, [wFieldMoveSucceeded]
-	cp $1
-	jr nz, .Fail
-	ld b, $4
-	ld a, $2
-	ret
-
-.Fail:
-	ld a, $3
-	ret
-; 12f3b
-
-MonMenu_RockSmash: ; 12f3b
-	callba RockSmashFunction
-	ld a, [wFieldMoveSucceeded]
-	cp $1
-	jr nz, .Fail
-	ld b, $4
-	ld a, $2
-	ret
-
-.Fail:
-	ld a, $3
-	ret
-; 12f50
-
-MonMenu_SweetScent: ; 12f50
-	callba SweetScentFromMenu
-	ld b, $4
-	ld a, $2
-	ret
-; 12f5b
-
-ChooseMoveToDelete: ; 12f5b
-	ld hl, Options
-	ld a, [hl]
-	push af
-	set NO_TEXT_SCROLL, [hl]
-	call LoadFontsBattleExtra
-	call .ChooseMoveToDelete
-	pop bc
-	ld a, b
-	ld [Options], a
-	push af
-	call ClearBGPalettes
-	pop af
-	ret
-; 12f73
-
-.ChooseMoveToDelete
-	call SetUpMoveScreenBG
-	ld de, DeleteMoveScreenAttrs
-	call SetMenuAttributes
-	call SetUpMoveList
-	ld hl, w2DMenuFlags1
-	set 6, [hl]
-	jr .enter_loop
-
-.loop
-	call ScrollingMenuJoypad
-	bit B_BUTTON_F, a
-	jp nz, .b_button
-	bit A_BUTTON_F, a
-	jp nz, .a_button
-
-.enter_loop
-	call PrepareToPlaceMoveData
-	call PlaceMoveData
-	jp .loop
-; 12f9c
-
-.a_button
-	and a
-	jr .finish
-
-.b_button
-	scf
-
-.finish
-	push af
-	xor a
-	ld [wSwitchMon], a
-	ld hl, w2DMenuFlags1
-	res 6, [hl]
-	call ClearSprites
-	call ClearTileMap
-	pop af
-	ret
-; 12fb2
-
-DeleteMoveScreenAttrs: ; 12fb2
-	db 3, 1
-	db 3, 1
-	db $40, $00
-	dn 2, 0
-	db D_UP | D_DOWN | A_BUTTON | B_BUTTON
-; 12fba
-
-ManagePokemonMoves: ; 12fba
-	ld a, [CurPartySpecies]
-	cp EGG
-	jr z, .egg
-	ld hl, Options
-	ld a, [hl]
-	push af
-	set NO_TEXT_SCROLL, [hl]
-	call MoveScreenLoop
-	pop af
-	ld [Options], a
-	call ClearBGPalettes
-
-.egg
-	ld a, $0
-	ret
-; 12fd5
-
-MoveScreenLoop: ; 12fd5
-	ld a, [CurPartyMon]
-	inc a
-	ld [wPartyMenuCursor], a
-	call SetUpMoveScreenBG
-	call Function132d3
-	ld de, MoveScreenAttributes
-	call SetMenuAttributes
-.loop
-	call SetUpMoveList
-	ld hl, w2DMenuFlags1
-	set 6, [hl]
-	jr .skip_joy
-
-.joy_loop
-	call ScrollingMenuJoypad
-	bit 1, a
-	jp nz, .b_button
-	bit 0, a
-	jp nz, .a_button
-	bit 4, a
-	jp nz, .d_right
-	bit 5, a
-	jp nz, .d_left
-
-.skip_joy
-	call PrepareToPlaceMoveData
-	ld a, [wMoveSwapBuffer]
-	and a
-	jr nz, .moving_move
-	call PlaceMoveData
-	jp .joy_loop
-
-.moving_move
-	ld a, " "
-	hlcoord 1, 11
-	ld bc, 5
-	call ByteFill
-	hlcoord 1, 12
-	lb bc, 5, SCREEN_WIDTH - 2
-	call ClearBox
-	hlcoord 1, 12
-	ld de, String_1316b
-	call PlaceString
-	jp .joy_loop
-.b_button
-	call PlayClickSFX
-	call WaitSFX
-	ld a, [wMoveSwapBuffer]
-	and a
-	jp z, .exit
-
-	ld a, [wMoveSwapBuffer]
-	ld [wMenuCursorY], a
-	xor a
-	ld [wMoveSwapBuffer], a
-	hlcoord 1, 2
-	lb bc, 8, SCREEN_WIDTH - 2
-	call ClearBox
-	jp .loop
-; 1305b
-
-.d_right
-	ld a, [wMoveSwapBuffer]
-	and a
-	jp nz, .joy_loop
-
-	ld a, [CurPartyMon]
-	ld b, a
-	push bc
-	call .cycle_right
-	pop bc
-	ld a, [CurPartyMon]
-	cp b
-	jp z, .joy_loop
-	jp MoveScreenLoop
-
-.d_left
-	ld a, [wMoveSwapBuffer]
-	and a
-	jp nz, .joy_loop
-	ld a, [CurPartyMon]
-	ld b, a
-	push bc
-	call .cycle_left
-	pop bc
-	ld a, [CurPartyMon]
-	cp b
-	jp z, .joy_loop
-	jp MoveScreenLoop
-
-.cycle_right
-	ld a, [CurPartyMon]
-	inc a
-	ld [CurPartyMon], a
-	ld c, a
-	ld b, 0
-	ld hl, PartySpecies
-	add hl, bc
-	ld a, [hl]
-	cp -1
-	jr z, .cycle_left
-	cp EGG
-	ret nz
-	jr .cycle_right
-
-.cycle_left
-	ld a, [CurPartyMon]
-	and a
-	ret z
-.cycle_left_loop
-	ld a, [CurPartyMon]
-	dec a
-	ld [CurPartyMon], a
-	ld c, a
-	ld b, 0
-	ld hl, PartySpecies
-	add hl, bc
-	ld a, [hl]
-	cp EGG
-	ret nz
-	ld a, [CurPartyMon]
-	and a
-	jr z, .cycle_right
-	jr .cycle_left_loop
-; 130c6
-
-.a_button
-	call PlayClickSFX
-	call WaitSFX
-	ld a, [wMoveSwapBuffer]
-	and a
-	jr nz, .place_move
-	ld a, [wMenuCursorY]
-	ld [wMoveSwapBuffer], a
-	call PlaceHollowCursor
-	jp .moving_move
-
-.place_move
-	ld hl, PartyMon1Moves
-	ld bc, PARTYMON_STRUCT_LENGTH
-	ld a, [CurPartyMon]
-	call AddNTimes
-	push hl
-	call .copy_move
-	pop hl
-	ld bc, $15
-	add hl, bc
-	call .copy_move
-	ld a, [wBattleMode]
-	jr z, .swap_moves
-	ld hl, BattleMonMoves
-	ld bc, $20
-	ld a, [CurPartyMon]
-	call AddNTimes
-	push hl
-	call .copy_move
-	pop hl
-	ld bc, 6
-	add hl, bc
-	call .copy_move
-
-.swap_moves
-	ld de, SFX_SWITCH_POKEMON
-	call PlaySFX
-	call WaitSFX
-	ld de, SFX_SWITCH_POKEMON
-	call PlaySFX
-	call WaitSFX
-	hlcoord 1, 2
-	lb bc, 8, 18
-	call ClearBox
-	hlcoord 10, 10
-	lb bc, 1, 9
-	call ClearBox
-	jp .loop
-; 1313a
-
-.copy_move
-	push hl
-	ld a, [wMenuCursorY]
-	dec a
-	ld c, a
-	ld b, $0
-	add hl, bc
-	ld d, h
-	ld e, l
-	pop hl
-	ld a, [wMoveSwapBuffer]
-	dec a
-	ld c, a
-	ld b, $0
-	add hl, bc
-	ld a, [de]
-	ld b, [hl]
-	ld [hl], a
-	ld a, b
-	ld [de], a
-	ret
-; 13154
-
-.exit
-	xor a
-	ld [wMoveSwapBuffer], a
-	ld hl, w2DMenuFlags1
-	res 6, [hl]
-	call ClearSprites
-	jp ClearTileMap
-; 13163
-
-MoveScreenAttributes: ; 13163
-	db 3, 1
-	db 3, 1
-	db $40, $00
-	dn 2, 0
-	db D_UP | D_DOWN | D_LEFT | D_RIGHT | A_BUTTON | B_BUTTON
-; 1316b
-
-String_1316b: ; 1316b
-	db "Where?@"
-; 13172
-
-SetUpMoveScreenBG: ; 13172
-	call ClearBGPalettes
-	call ClearTileMap
-	call ClearSprites
-	xor a
-	ld [hBGMapMode], a
-	callba LoadStatsScreenPageTilesGFX
-	callba ClearSpriteAnims2
-	ld a, [CurPartyMon]
-	ld e, a
-	ld d, $0
-	ld hl, PartySpecies
-	add hl, de
-	ld a, [hl]
-	ld [wd265], a
-	ld e, $2
-	callba LoadMenuMonIcon
-	hlcoord 0, 1
-	ld b, 9
-	ld c, 18
-	call TextBox
-	hlcoord 0, 11
-	ld b, 5
-	ld c, 18
-	call TextBox
-	hlcoord 2, 0
-	lb bc, 2, 3
-	call ClearBox
-	xor a
-	ld [MonType], a
-	ld hl, PartyMonNicknames
-	ld a, [CurPartyMon]
-	call GetNick
-	hlcoord 5, 1
-	call PlaceString
-	push bc
-	callba CopyPkmnToTempMon
-	pop hl
-	call PrintLevel
-	ld hl, PlayerHPPal
-	call SetHPPal
-	ld b, SCGB_MOVE_LIST
-	call GetSGBLayout
-	hlcoord 16, 0
-	lb bc, 1, 3
-	jp ClearBox
-; 131ef
-
-SetUpMoveList: ; 131ef
-	xor a
-	ld [hBGMapMode], a
-	ld [wMoveSwapBuffer], a
-	ld [MonType], a
-	predef CopyPkmnToTempMon
-	ld hl, TempMonMoves
-	ld de, wListMoves_MoveIndicesBuffer
-	ld bc, NUM_MOVES
-	call CopyBytes
-	ld a, SCREEN_WIDTH * 2
-	ld [Buffer1], a
-	hlcoord 2, 3
-	predef ListMoves
-	hlcoord 10, 4
-	predef ListMovePP
-	call WaitBGMap
-	call SetPalettes
-	ld a, [wNumMoves]
-	inc a
-	ld [w2DMenuNumRows], a
-	hlcoord 0, 11
-	ld b, 5
-	ld c, 18
-	jp TextBox
-; 13235
-
-PrepareToPlaceMoveData: ; 13235
-	ld hl, PartyMon1Moves
-	ld bc, PARTYMON_STRUCT_LENGTH
-	ld a, [CurPartyMon]
-	call AddNTimes
-	ld a, [wMenuCursorY]
-	dec a
-	ld c, a
-	ld b, $0
-	add hl, bc
-	ld a, [hl]
-	ld [CurMove], a
-	hlcoord 1, 12
-	lb bc, 5, 18
-	jp ClearBox
-; 13256
-
-PlaceMoveData: ; 13256
-	xor a
-	ld [hBGMapMode], a
-	hlcoord 0, 10
-	ld de, String_132ba
-	call PlaceString
-	hlcoord 0, 11
-	ld de, String_132c2
-	call PlaceString
-	hlcoord 12, 12
-	ld de, String_132ca
-	call PlaceString
-	ld a, [CurMove]
-	ld b, a
-	hlcoord 2, 12
-	predef PrintMoveType
-	ld a, [CurMove]
-	dec a
-	ld hl, Moves + MOVE_POWER
-	ld bc, MOVE_LENGTH
-	call AddNTimes
-	ld a, BANK(Moves)
-	call GetFarByte
-	hlcoord 16, 12
-	cp 2
-	jr c, .no_power
-	ld [wd265], a
-	ld de, wd265
-	lb bc, 1, 3
-	call PrintNum
-	jr .description
-
-.no_power
-	ld de, String_132cf
-	call PlaceString
-
-.description
-	hlcoord 1, 14
-	predef PrintMoveDesc
-	ld a, $1
-	ld [hBGMapMode], a
-	ret
-; 132ba
-
-String_132ba: ; 132ba
-	db "┌─────┐@"
-; 132c2
-String_132c2: ; 132c2
-	db "│TYPE/└@"
-; 132ca
-String_132ca: ; 132ca
-	db "ATK/@"
-; 132cf
-String_132cf: ; 132cf
-	db "---@"
-; 132d3
-
-Function132d3: ; 132d3
-	call Function132da
-	call Function132fe
-	ret
-; 132da
-
-Function132da: ; 132da
-	ld a, [CurPartyMon]
-	and a
-	ret z
-	ld c, a
-	ld e, a
-	ld d, 0
-	ld hl, PartyCount
-	add hl, de
-.loop
-	ld a, [hl]
-	and a
-	jr z, .prev
-	cp EGG
-	jr z, .prev
-	cp NUM_POKEMON + 1
-	jr c, .legal
-
-.prev
-	dec hl
-	dec c
-	jr nz, .loop
-	ret
-
-.legal
-	hlcoord 16, 0
-	ld [hl], "◀"
-	ret
-; 132fe
-
-Function132fe: ; 132fe
-	ld a, [CurPartyMon]
-	inc a
-	ld c, a
-	ld a, [PartyCount]
-	cp c
-	ret z
-	ld e, c
-	ld d, 0
-	ld hl, PartySpecies
-	add hl, de
-.loop
-	ld a, [hl]
-	cp -1
-	ret z
-	and a
-	jr z, .next
-	cp EGG
-	jr z, .next
-	cp NUM_POKEMON + 1
-	jr c, .legal
-
-.next
-	inc hl
-	jr .loop
-
-.legal
-	hlcoord 18, 0
-	ld [hl], "▶"
-	ret
-; 13327
--- /dev/null
+++ b/engine/switch_party_mons.asm
@@ -1,0 +1,145 @@
+_SwitchPartyMons:
+	ld a, [wd0e3]
+	dec a
+	ld [Buffer3], a
+	ld b, a
+	ld a, [wMenuCursorY]
+	dec a
+	ld [Buffer2], a
+	cp b
+	jr z, .skip
+	call .SwapMonAndMail
+	ld a, [Buffer3]
+	call .ClearSprite
+	ld a, [Buffer2]
+	call .ClearSprite
+.skip
+	ret
+
+.ClearSprite: ; 50f34 (14:4f34)
+	push af
+	hlcoord 0, 1
+	ld bc, 2 * SCREEN_WIDTH
+	call AddNTimes
+	ld bc, 2 * SCREEN_WIDTH
+	ld a, " "
+	call ByteFill
+	pop af
+	ld hl, Sprites
+	ld bc, $10
+	call AddNTimes
+	ld de, $4
+	ld c, $4
+.gfx_loop
+	ld [hl], $a0
+	add hl, de
+	dec c
+	jr nz, .gfx_loop
+	ld de, SFX_SWITCH_POKEMON
+	call WaitPlaySFX
+	ret
+
+.SwapMonAndMail: ; 50f62 (14:4f62)
+	push hl
+	push de
+	push bc
+	ld bc, PartySpecies
+	ld a, [Buffer2]
+	ld l, a
+	ld h, $0
+	add hl, bc
+	ld d, h
+	ld e, l
+	ld a, [Buffer3]
+	ld l, a
+	ld h, $0
+	add hl, bc
+	ld a, [hl]
+	push af
+	ld a, [de]
+	ld [hl], a
+	pop af
+	ld [de], a
+	ld a, [Buffer2]
+	ld hl, PartyMon1Species
+	ld bc, PARTYMON_STRUCT_LENGTH
+	call AddNTimes
+	push hl
+	ld de, wd002
+	ld bc, PARTYMON_STRUCT_LENGTH
+	call CopyBytes
+	ld a, [Buffer3]
+	ld hl, PartyMon1
+	ld bc, PARTYMON_STRUCT_LENGTH
+	call AddNTimes
+	pop de
+	push hl
+	ld bc, PARTYMON_STRUCT_LENGTH
+	call CopyBytes
+	pop de
+	ld hl, wd002
+	ld bc, PARTYMON_STRUCT_LENGTH
+	call CopyBytes
+	ld a, [Buffer2]
+	ld hl, PartyMonOT
+	call SkipNames
+	push hl
+	call .CopyNameTowd002
+	ld a, [Buffer3]
+	ld hl, PartyMonOT
+	call SkipNames
+	pop de
+	push hl
+	call .CopyName
+	pop de
+	ld hl, wd002
+	call .CopyName
+	ld hl, PartyMonNicknames
+	ld a, [Buffer2]
+	call SkipNames
+	push hl
+	call .CopyNameTowd002
+	ld hl, PartyMonNicknames
+	ld a, [Buffer3]
+	call SkipNames
+	pop de
+	push hl
+	call .CopyName
+	pop de
+	ld hl, wd002
+	call .CopyName
+	ld hl, sPartyMail
+	ld a, [Buffer2]
+	ld bc, MAIL_STRUCT_LENGTH
+	call AddNTimes
+	push hl
+	ld de, wd002
+	ld bc, MAIL_STRUCT_LENGTH
+	ld a, BANK(sPartyMail)
+	call GetSRAMBank
+	call CopyBytes
+	ld hl, sPartyMail
+	ld a, [Buffer3]
+	ld bc, MAIL_STRUCT_LENGTH
+	call AddNTimes
+	pop de
+	push hl
+	ld bc, MAIL_STRUCT_LENGTH
+	call CopyBytes
+	pop de
+	ld hl, wd002
+	ld bc, MAIL_STRUCT_LENGTH
+	call CopyBytes
+	call CloseSRAM
+	pop bc
+	pop de
+	pop hl
+	ret
+
+.CopyNameTowd002: ; 51036 (14:5036)
+	ld de, wd002
+
+.CopyName: ; 51039 (14:5039)
+	ld bc, NAME_LENGTH
+	call CopyBytes
+	ret
--- /dev/null
+++ b/engine/tempmon.asm
@@ -1,0 +1,127 @@
+CopyPkmnToTempMon: ; 5084a
+; gets the BaseData of a Pkmn
+; and copys the PkmnStructure to TempMon
+
+	ld a, [CurPartyMon]
+	ld e, a
+	call GetPkmnSpecies
+	ld a, [CurPartySpecies]
+	ld [CurSpecies], a
+	call GetBaseData
+
+	ld a, [MonType]
+	ld hl, PartyMon1Species
+	ld bc, PARTYMON_STRUCT_LENGTH
+	and a
+	jr z, .copywholestruct
+	ld hl, OTPartyMon1Species
+	ld bc, PARTYMON_STRUCT_LENGTH
+	cp OTPARTYMON
+	jr z, .copywholestruct
+	ld bc, BOXMON_STRUCT_LENGTH
+	callab CopyBoxmonToTempMon
+	jr .done
+
+.copywholestruct
+	ld a, [CurPartyMon]
+	call AddNTimes
+	ld de, TempMon
+	ld bc, PARTYMON_STRUCT_LENGTH
+	call CopyBytes
+
+.done
+	ret
+
+CalcwBufferMonStats: ; 5088b
+	ld bc, wBufferMon
+	jr _TempMonStatsCalculation
+
+CalcTempmonStats: ; 50890
+	ld bc, TempMon
+_TempMonStatsCalculation: ; 50893
+	ld hl, MON_LEVEL
+	add hl, bc
+	ld a, [hl]
+	ld [CurPartyLevel], a
+	ld hl, MON_MAXHP
+	add hl, bc
+	ld d, h
+	ld e, l
+	ld hl, MON_STAT_EXP - 1
+	add hl, bc
+	push bc
+	ld b, $1
+	predef CalcPkmnStats
+	pop bc
+	ld hl, MON_HP
+	add hl, bc
+	ld d, h
+	ld e, l
+	ld a, [CurPartySpecies]
+	cp EGG
+	jr nz, .not_egg
+	xor a
+	ld [de], a
+	inc de
+	ld [de], a
+	jr .zero_status
+
+.not_egg
+	push bc
+	ld hl, MON_MAXHP
+	add hl, bc
+	ld bc, 2
+	call CopyBytes
+	pop bc
+
+.zero_status
+	ld hl, MON_STATUS
+	add hl, bc
+	xor a
+	ld [hli], a
+	ld [hl], a
+	ret
+
+GetPkmnSpecies: ; 508d5
+; [MonType] has the type of the Pkmn
+; e = Nr. of Pkmn (i.e. [CurPartyMon])
+
+	ld a, [MonType]
+	and a ; PARTYMON
+	jr z, .partymon
+	cp OTPARTYMON
+	jr z, .otpartymon
+	cp BOXMON
+	jr z, .boxmon
+	cp TEMPMON
+	jr z, .breedmon
+	; WILDMON
+
+.partymon
+	ld hl, PartySpecies
+	jr .done
+
+.otpartymon
+	ld hl, OTPartySpecies
+	jr .done
+
+.boxmon
+	ld a, BANK(sBoxSpecies)
+	call GetSRAMBank
+	ld hl, sBoxSpecies
+	call .done
+	call CloseSRAM
+	ret
+
+.breedmon
+	ld a, [wBreedMon1Species]
+	jr .done2
+
+.done
+	ld d, 0
+	add hl, de
+	ld a, [hl]
+
+.done2
+	ld [CurPartySpecies], a
+	ret
--- /dev/null
+++ b/event/buena_menu.asm
@@ -1,0 +1,58 @@
+AskRememberPassword: ; 4ae12
+	call .DoMenu
+	ld a, $0
+	jr c, .okay
+	ld a, $1
+
+.okay
+	ld [ScriptVar], a
+	ret
+
+.DoMenu: ; 4ae1f
+	lb bc, 14, 7
+	push bc
+	ld hl, YesNoMenuDataHeader
+	call CopyMenuDataHeader
+	pop bc
+	ld a, b
+	ld [wMenuBorderLeftCoord], a
+	add $5
+	ld [wMenuBorderRightCoord], a
+	ld a, c
+	ld [wMenuBorderTopCoord], a
+	add $4
+	ld [wMenuBorderBottomCoord], a
+	call PushWindow
+	call VerticalMenu
+	push af
+	ld c, 15
+	call DelayFrames
+	call Buena_ExitMenu
+	pop af
+	jr c, .refused
+	ld a, [wMenuCursorY]
+	cp $2
+	jr z, .refused
+	and a
+	ret
+
+.refused
+	ld a, $2
+	ld [wMenuCursorY], a
+	scf
+	ret
+
+Buena_ExitMenu: ; 4ae5e
+	ld a, [hOAMUpdate]
+	push af
+	call ExitMenu
+	call UpdateSprites
+	xor a
+	ld [hOAMUpdate], a
+	call DelayFrame
+	ld a, $1
+	ld [hOAMUpdate], a
+	call ApplyTilemap
+	pop af
+	ld [hOAMUpdate], a
+	ret
--- a/event/bug_contest.asm
+++ /dev/null
@@ -1,43 +1,0 @@
-Special_GiveParkBalls: ; 135db
-	xor a
-	ld [wContestMon], a
-	ld a, 20
-	ld [wParkBallsRemaining], a
-	callba StartBugContestTimer
-	ret
-
-BugCatchingContestBattleScript:: ; 0x135eb
-	writecode VAR_BATTLETYPE, BATTLETYPE_CONTEST
-	randomwildmon
-	startbattle
-	reloadmapafterbattle
-	copybytetovar wParkBallsRemaining
-	iffalse BugCatchingContestOutOfBallsScript
-	end
-
-BugCatchingContestOverScript:: ; 0x135f8
-	playsound SFX_ELEVATOR_END
-	opentext
-	writetext BugCatchingContestText_BeeepTimesUp
-	waitbutton
-	jump BugCatchingContestReturnToGateScript
-
-BugCatchingContestOutOfBallsScript: ; 0x13603
-	playsound SFX_ELEVATOR_END
-	opentext
-	writetext BugCatchingContestText_ContestIsOver
-	waitbutton
-
-BugCatchingContestReturnToGateScript: ; 0x1360b
-	closetext
-	jumpstd bugcontestresultswarp
-
-BugCatchingContestText_BeeepTimesUp: ; 0x1360f
-	; ANNOUNCER: BEEEP! Time's up!
-	text_jump UnknownText_0x1bd2ca
-	db "@"
-
-BugCatchingContestText_ContestIsOver: ; 0x13614
-	; ANNOUNCER: The Contest is over!
-	text_jump UnknownText_0x1bd2e7
-	db "@"
--- /dev/null
+++ b/event/bug_contest/caught_mon.asm
@@ -1,0 +1,38 @@
+BugContest_SetCaughtContestMon: ; e6ce
+	ld a, [wContestMon]
+	and a
+	jr z, .firstcatch
+	ld [wd265], a
+	callba DisplayAlreadyCaughtText
+	callba DisplayCaughtContestMonStats
+	lb bc, 14, 7
+	call PlaceYesNoBox
+	ret c
+
+.firstcatch
+	call .generatestats
+	ld a, [TempEnemyMonSpecies]
+	ld [wd265], a
+	call GetPokemonName
+	ld hl, .caughttext
+	call PrintText
+	ret
+
+.generatestats ; e6fd
+	ld a, [TempEnemyMonSpecies]
+	ld [CurSpecies], a
+	ld [CurPartySpecies], a
+	call GetBaseData
+	xor a
+	ld bc, PARTYMON_STRUCT_LENGTH
+	ld hl, wContestMon
+	call ByteFill
+	xor a
+	ld [MonType], a
+	ld hl, wContestMon
+	jp GeneratePartyMonStats
+
+.caughttext ; 0xe71d
+	; Caught @ !
+	text_jump UnknownText_0x1c10c0
+	db "@"
--- /dev/null
+++ b/event/bug_contest/contest.asm
@@ -1,0 +1,43 @@
+Special_GiveParkBalls: ; 135db
+	xor a
+	ld [wContestMon], a
+	ld a, 20
+	ld [wParkBallsRemaining], a
+	callba StartBugContestTimer
+	ret
+
+BugCatchingContestBattleScript:: ; 0x135eb
+	writecode VAR_BATTLETYPE, BATTLETYPE_CONTEST
+	randomwildmon
+	startbattle
+	reloadmapafterbattle
+	copybytetovar wParkBallsRemaining
+	iffalse BugCatchingContestOutOfBallsScript
+	end
+
+BugCatchingContestOverScript:: ; 0x135f8
+	playsound SFX_ELEVATOR_END
+	opentext
+	writetext BugCatchingContestText_BeeepTimesUp
+	waitbutton
+	jump BugCatchingContestReturnToGateScript
+
+BugCatchingContestOutOfBallsScript: ; 0x13603
+	playsound SFX_ELEVATOR_END
+	opentext
+	writetext BugCatchingContestText_ContestIsOver
+	waitbutton
+
+BugCatchingContestReturnToGateScript: ; 0x1360b
+	closetext
+	jumpstd bugcontestresultswarp
+
+BugCatchingContestText_BeeepTimesUp: ; 0x1360f
+	; ANNOUNCER: BEEEP! Time's up!
+	text_jump UnknownText_0x1bd2ca
+	db "@"
+
+BugCatchingContestText_ContestIsOver: ; 0x13614
+	; ANNOUNCER: The Contest is over!
+	text_jump UnknownText_0x1bd2e7
+	db "@"
--- /dev/null
+++ b/event/bug_contest/contest_2.asm
@@ -1,0 +1,133 @@
+Special_SelectRandomBugContestContestants: ; 139a8
+; Select five random people to participate in the current contest.
+
+; First we have to make sure that any old data is cleared away.
+	ld c, 10 ; Number of people to choose from.
+	ld hl, BugCatchingContestantEventFlagTable
+.loop1
+	push bc
+	push hl
+	ld e, [hl]
+	inc hl
+	ld d, [hl]
+	ld b, RESET_FLAG
+	call EventFlagAction
+	pop hl
+	inc hl
+	inc hl
+	pop bc
+	dec c
+	jr nz, .loop1
+
+; Now that that's out of the way, we can get on to the good stuff.
+	ld c, 5
+.loop2
+	push bc
+.next
+; Choose a flag at uniform random to be set.
+	call Random
+	cp 250
+	jr nc, .next
+	ld c, 25
+	call SimpleDivide
+	ld e, b
+	ld d, 0
+	ld hl, BugCatchingContestantEventFlagTable
+	add hl, de
+	add hl, de
+	ld e, [hl]
+	inc hl
+	ld d, [hl]
+	push de
+; If we've already set it, it doesn't count.
+	ld b, CHECK_FLAG
+	call EventFlagAction
+	pop de
+	ld a, c
+	and a
+	jr nz, .next
+; Set the flag.  This will cause that sprite to not be visible in the contest.
+	ld b, SET_FLAG
+	call EventFlagAction
+	pop bc
+; Check if we're done.  If so, return.  Otherwise, choose the next victim.
+	dec c
+	jr nz, .loop2
+	ret
+; 139ed
+
+Special_CheckBugContestContestantFlag: ; 139ed
+; Checks the flag of the Bug Catching Contestant whose index is loaded in a.
+
+; Bug: If a >= 10 when this is called, it will read beyond the table.
+
+	ld hl, BugCatchingContestantEventFlagTable
+	ld e, a
+	ld d, 0
+	add hl, de
+	add hl, de
+	ld e, [hl]
+	inc hl
+	ld d, [hl]
+	ld b, CHECK_FLAG
+	call EventFlagAction
+	ret
+; 139fe
+
+BugCatchingContestantEventFlagTable: ; 139fe
+	dw EVENT_BUG_CATCHING_CONTESTANT_1A
+	dw EVENT_BUG_CATCHING_CONTESTANT_2A
+	dw EVENT_BUG_CATCHING_CONTESTANT_3A
+	dw EVENT_BUG_CATCHING_CONTESTANT_4A
+	dw EVENT_BUG_CATCHING_CONTESTANT_5A
+	dw EVENT_BUG_CATCHING_CONTESTANT_6A
+	dw EVENT_BUG_CATCHING_CONTESTANT_7A
+	dw EVENT_BUG_CATCHING_CONTESTANT_8A
+	dw EVENT_BUG_CATCHING_CONTESTANT_9A
+	dw EVENT_BUG_CATCHING_CONTESTANT_10A
+; 13a12
+
+ContestDropOffMons: ; 13a12
+	ld hl, PartyMon1HP
+	ld a, [hli]
+	or [hl]
+	jr z, .fainted
+; Mask the rest of your party by setting the count to 1...
+	ld hl, PartyCount
+	ld a, 1
+	ld [hli], a
+	inc hl
+; ... backing up the second mon index somewhere...
+	ld a, [hl]
+	ld [wBugContestSecondPartySpecies], a
+; ... and replacing it with the terminator byte
+	ld [hl], $ff
+	xor a
+	ld [ScriptVar], a
+	ret
+
+.fainted
+	ld a, $1
+	ld [ScriptVar], a
+	ret
+; 13a31
+
+ContestReturnMons: ; 13a31
+; Restore the species of the second mon.
+	ld hl, PartySpecies + 1
+	ld a, [wBugContestSecondPartySpecies]
+	ld [hl], a
+; Restore the party count, which must be recomputed.
+	ld b, $1
+.loop
+	ld a, [hli]
+	cp -1
+	jr z, .done
+	inc b
+	jr .loop
+
+.done
+	ld a, b
+	ld [PartyCount], a
+	ret
+; 13a47
--- /dev/null
+++ b/event/bug_contest/display_stats.asm
@@ -1,0 +1,107 @@
+DisplayCaughtContestMonStats: ; cc000
+	call ClearBGPalettes
+	call ClearTileMap
+	call ClearSprites
+	call LoadFontsBattleExtra
+
+	ld hl, Options
+	ld a, [hl]
+	push af
+	set 4, [hl]
+
+	hlcoord 0, 0
+	ld b, 4
+	ld c, 13
+	call TextBox
+
+	hlcoord 0, 6
+	ld b, 4
+	ld c, 13
+	call TextBox
+
+	hlcoord 2, 0
+	ld de, .Stock
+	call PlaceString
+
+	hlcoord 2, 6
+	ld de, .This
+	call PlaceString
+
+	hlcoord 5, 4
+	ld de, .Health
+	call PlaceString
+
+	hlcoord 5, 10
+	ld de, .Health
+	call PlaceString
+
+	ld a, [wContestMon]
+	ld [wd265], a
+	call GetPokemonName
+	ld de, StringBuffer1
+	hlcoord 1, 2
+	call PlaceString
+
+	ld h, b
+	ld l, c
+	ld a, [wContestMonLevel]
+	ld [TempMonLevel], a
+	call PrintLevel
+
+	ld de, EnemyMonNick
+	hlcoord 1, 8
+	call PlaceString
+
+	ld h, b
+	ld l, c
+	ld a, [EnemyMonLevel]
+	ld [TempMonLevel], a
+	call PrintLevel
+
+	hlcoord 11, 4
+	ld de, wContestMonMaxHP
+	lb bc, 2, 3
+	call PrintNum
+
+	hlcoord 11, 10
+	ld de, EnemyMonMaxHP
+	call PrintNum
+
+	ld hl, SwitchMonText
+	call PrintText
+
+	pop af
+	ld [Options], a
+
+	call WaitBGMap
+	ld b, SCGB_DIPLOMA
+	call GetSGBLayout
+	call SetPalettes
+	ret
+
+.Health:
+	db "HEALTH@"
+.Stock:
+	db " STOCK ", $4a, " @"
+.This:
+	db " THIS ", $4a, "  @"
+
+SwitchMonText: ; cc0c2
+	; Switch #MON?
+	text_jump UnknownText_0x1c10cf
+	db "@"
+
+DisplayAlreadyCaughtText: ; cc0c7
+	call GetPokemonName
+	ld hl, .AlreadyCaughtText
+	jp PrintText
+
+.AlreadyCaughtText: ; 0xcc0d0
+	; You already caught a @ .
+	text_jump UnknownText_0x1c10dd
+	db "@"
+
+Predef2F:
+Predef38:
+Predef39: ; cc0d5
+	ret
--- /dev/null
+++ b/event/bug_contest/judging.asm
@@ -1,0 +1,395 @@
+_BugContestJudging: ; 1369d
+	call ContestScore
+	callba TrainerRankings_BugContestScore
+	call BugContest_JudgeContestants
+	ld a, [wBugContestThirdPlacePersonID]
+	call LoadContestantName
+	ld a, [wBugContestThirdPlaceMon]
+	ld [wNamedObjectIndexBuffer], a
+	call GetPokemonName
+	ld hl, BugContest_ThirdPlaceText
+	call PrintText
+	ld a, [wBugContestSecondPlacePersonID]
+	call LoadContestantName
+	ld a, [wBugContestSecondPlaceMon]
+	ld [wNamedObjectIndexBuffer], a
+	call GetPokemonName
+	ld hl, BugContest_SecondPlaceText
+	call PrintText
+	ld a, [wBugContestFirstPlacePersonID]
+	call LoadContestantName
+	ld a, [wBugContestFirstPlaceMon]
+	ld [wNamedObjectIndexBuffer], a
+	call GetPokemonName
+	ld hl, BugContest_FirstPlaceText
+	call PrintText
+	jp BugContest_GetPlayersResult
+; 136eb
+
+BugContest_FirstPlaceText: ; 0x136eb
+	text_jump ContestJudging_FirstPlaceText
+	start_asm
+	ld de, SFX_1ST_PLACE
+	call PlaySFX
+	call WaitSFX
+	ld hl, BugContest_FirstPlaceScoreText
+	ret
+; 136fd
+
+BugContest_FirstPlaceScoreText: ; 0x136fd
+	; The winning score was @  points!
+	text_jump ContestJudging_FirstPlaceScoreText
+	db "@"
+; 0x13702
+
+BugContest_SecondPlaceText: ; 0x13702
+	; Placing second was @ , who caught a @ !@ @
+	text_jump ContestJudging_SecondPlaceText
+	start_asm
+	ld de, SFX_2ND_PLACE
+	call PlaySFX
+	call WaitSFX
+	ld hl, BugContest_SecondPlaceScoreText
+	ret
+; 13714
+
+BugContest_SecondPlaceScoreText: ; 0x13714
+	; The score was @  points!
+	text_jump ContestJudging_SecondPlaceScoreText
+	db "@"
+; 0x13719
+
+BugContest_ThirdPlaceText: ; 0x13719
+	; Placing third was @ , who caught a @ !@ @
+	text_jump ContestJudging_ThirdPlaceText
+	start_asm
+	ld de, SFX_3RD_PLACE
+	call PlaySFX
+	call WaitSFX
+	ld hl, BugContest_ThirdPlaceScoreText
+	ret
+; 1372b
+
+BugContest_ThirdPlaceScoreText: ; 0x1372b
+	; The score was @  points!
+	text_jump ContestJudging_ThirdPlaceScoreText
+	db "@"
+; 0x13730
+
+LoadContestantName: ; 13730
+
+; If a = 0, get your name.
+	dec a
+	jr z, .player
+; Find the pointer for the trainer class of the Bug Catching Contestant whose ID is in a.
+	ld c, a
+	ld b, 0
+	ld hl, BugContestantPointers
+	add hl, bc
+	add hl, bc
+	ld a, [hli]
+	ld h, [hl]
+	ld l, a
+; Copy the Trainer Class to c.
+	ld a, [hli]
+	ld c, a
+; Save hl and bc for later.
+	push hl
+	push bc
+; Get the Trainer Class name and copy it into wBugContestWinnerName.
+	callab GetTrainerClassName
+	ld hl, StringBuffer1
+	ld de, wBugContestWinnerName
+	ld bc, TRAINER_CLASS_NAME_LENGTH
+	call CopyBytes
+	ld hl, wBugContestWinnerName
+; Delete the trailing terminator and replace it with a space.
+.next
+	ld a, [hli]
+	cp "@"
+	jr nz, .next
+	dec hl
+	ld [hl], " "
+	inc hl
+	ld d, h
+	ld e, l
+; Restore the Trainer Class ID and Trainer ID pointer.  Save de for later.
+	pop bc
+	pop hl
+	push de
+; Get the name of the trainer with class c and ID b.
+	ld a, [hl]
+	ld b, a
+	callab GetTrainerName
+; Append the name to wBugContestWinnerName.
+	ld hl, StringBuffer1
+	pop de
+	ld bc, NAME_LENGTH - 1
+	jp CopyBytes
+
+.player
+	ld hl, PlayerName
+	ld de, wBugContestWinnerName
+	ld bc, NAME_LENGTH
+	jp CopyBytes
+; 13783
+
+
+INCLUDE "data/bug_contest_winners.asm"
+; 13807
+
+
+BugContest_GetPlayersResult: ; 13807
+	ld hl, wBugContestThirdPlacePersonID
+	ld de, -4
+	ld b, 3
+.loop
+	ld a, [hl]
+	cp 1 ; Player
+	jr z, .done
+	add hl, de
+	dec b
+	jr nz, .loop
+
+.done
+	ret
+; 13819
+
+BugContest_JudgeContestants: ; 13819
+	call ClearContestResults
+	call ComputeAIContestantScores
+	ld hl, wBugContestTempPersonID
+	ld a, 1 ; Player
+	ld [hli], a
+	ld a, [wContestMon]
+	ld [hli], a
+	ld a, [hProduct]
+	ld [hli], a
+	ld a, [hProduct + 1]
+	ld [hl], a
+	call DetermineContestWinners
+	ret
+; 13833
+
+ClearContestResults: ; 13833
+	ld hl, wBugContestResults
+	ld b, wBugContestWinnersEnd - wBugContestResults
+	xor a
+.loop
+	ld [hli], a
+	dec b
+	jr nz, .loop
+	ret
+; 1383e
+
+DetermineContestWinners: ; 1383e
+	ld de, wBugContestTempScore
+	ld hl, wBugContestFirstPlaceScore
+	ld c, 2
+	call StringCmp
+	jr c, .not_first_place
+	ld hl, wBugContestSecondPlacePersonID
+	ld de, wBugContestThirdPlacePersonID
+	ld bc, 4
+	call CopyBytes
+	ld hl, wBugContestFirstPlacePersonID
+	ld de, wBugContestSecondPlacePersonID
+	ld bc, 4
+	call CopyBytes
+	ld hl, wBugContestFirstPlacePersonID
+	call CopyTempContestant
+	jr .done
+
+.not_first_place
+	ld de, wBugContestTempScore
+	ld hl, wBugContestSecondPlaceScore
+	ld c, 2
+	call StringCmp
+	jr c, .not_second_place
+	ld hl, wBugContestSecondPlacePersonID
+	ld de, wBugContestThirdPlacePersonID
+	ld bc, 4
+	call CopyBytes
+	ld hl, wBugContestSecondPlacePersonID
+	call CopyTempContestant
+	jr .done
+
+.not_second_place
+	ld de, wBugContestTempScore
+	ld hl, wBugContestThirdPlaceScore
+	ld c, 2
+	call StringCmp
+	jr c, .done
+	ld hl, wBugContestThirdPlacePersonID
+	call CopyTempContestant
+
+.done
+	ret
+; 138a0
+
+CopyTempContestant: ; 138a0
+; Could've just called CopyBytes.
+	ld de, wBugContestTempPersonID
+rept 3
+	ld a, [de]
+	inc de
+	ld [hli], a
+endr
+	ld a, [de]
+	inc de
+	ld [hl], a
+	ret
+; 138b0
+
+ComputeAIContestantScores: ; 138b0
+	ld e, 0
+.loop
+	push de
+	call Special_CheckBugContestContestantFlag
+	pop de
+	jr nz, .done
+	ld a, e
+	inc a
+	inc a
+	ld [wBugContestTempPersonID], a
+	dec a
+	ld c, a
+	ld b, 0
+	ld hl, BugContestantPointers
+	add hl, bc
+	add hl, bc
+	ld a, [hli]
+	ld h, [hl]
+	ld l, a
+	inc hl
+	inc hl
+.loop2
+	call Random
+	and 3
+	cp 3
+	jr z, .loop2
+	ld c, a
+	ld b, 0
+	add hl, bc
+	add hl, bc
+	add hl, bc
+	ld a, [hli]
+	ld [wBugContestTempMon], a
+	ld a, [hli]
+	ld h, [hl]
+	ld l, a
+	call Random
+	and 7
+	ld c, a
+	ld b, 0
+	add hl, bc
+	ld a, h
+	ld [wBugContestTempScore], a
+	ld a, l
+	ld [wBugContestTempScore + 1], a
+	push de
+	call DetermineContestWinners
+	pop de
+
+.done
+	inc e
+	ld a, e
+	cp 10
+	jr nz, .loop
+	ret
+; 13900
+
+ContestScore: ; 13900
+; Determine the player's score in the Bug Catching Contest.
+
+	xor a
+	ld [hProduct], a
+	ld [hMultiplicand], a
+
+	ld a, [wContestMonSpecies] ; Species
+	and a
+	jr z, .done
+
+	; Tally the following:
+
+	; Max HP * 4
+	ld a, [wContestMonMaxHP + 1]
+	call .AddContestStat
+	ld a, [wContestMonMaxHP + 1]
+	call .AddContestStat
+	ld a, [wContestMonMaxHP + 1]
+	call .AddContestStat
+	ld a, [wContestMonMaxHP + 1]
+	call .AddContestStat
+
+	; Stats
+	ld a, [wContestMonAttack  + 1]
+	call .AddContestStat
+	ld a, [wContestMonDefense + 1]
+	call .AddContestStat
+	ld a, [wContestMonSpeed   + 1]
+	call .AddContestStat
+	ld a, [wContestMonSpclAtk + 1]
+	call .AddContestStat
+	ld a, [wContestMonSpclDef + 1]
+	call .AddContestStat
+
+	; DVs
+	ld a, [wContestMonDVs + 0]
+	ld b, a
+	and 2
+	add a
+	add a
+	ld c, a
+
+	swap b
+	ld a, b
+	and 2
+	add a
+	add c
+	ld d, a
+
+	ld a, [wContestMonDVs + 1]
+	ld b, a
+	and 2
+	ld c, a
+
+	swap b
+	ld a, b
+	and 2
+	srl a
+	add c
+	add c
+	add d
+	add d
+
+	call .AddContestStat
+
+	; Remaining HP / 8
+	ld a, [wContestMonHP + 1]
+	srl a
+	srl a
+	srl a
+	call .AddContestStat
+
+	; Whether it's holding an item
+	ld a, [wContestMonItem]
+	and a
+	jr z, .done
+
+	ld a, 1
+	call .AddContestStat
+
+.done
+	ret
+; 1397f
+
+.AddContestStat: ; 1397f
+	ld hl, hMultiplicand
+	add [hl]
+	ld [hl], a
+	ret nc
+	dec hl
+	inc [hl]
+	ret
+; 13988
--- a/event/bug_contest_2.asm
+++ /dev/null
@@ -1,133 +1,0 @@
-Special_SelectRandomBugContestContestants: ; 139a8
-; Select five random people to participate in the current contest.
-
-; First we have to make sure that any old data is cleared away.
-	ld c, 10 ; Number of people to choose from.
-	ld hl, BugCatchingContestantEventFlagTable
-.loop1
-	push bc
-	push hl
-	ld e, [hl]
-	inc hl
-	ld d, [hl]
-	ld b, RESET_FLAG
-	call EventFlagAction
-	pop hl
-	inc hl
-	inc hl
-	pop bc
-	dec c
-	jr nz, .loop1
-
-; Now that that's out of the way, we can get on to the good stuff.
-	ld c, 5
-.loop2
-	push bc
-.next
-; Choose a flag at uniform random to be set.
-	call Random
-	cp 250
-	jr nc, .next
-	ld c, 25
-	call SimpleDivide
-	ld e, b
-	ld d, 0
-	ld hl, BugCatchingContestantEventFlagTable
-	add hl, de
-	add hl, de
-	ld e, [hl]
-	inc hl
-	ld d, [hl]
-	push de
-; If we've already set it, it doesn't count.
-	ld b, CHECK_FLAG
-	call EventFlagAction
-	pop de
-	ld a, c
-	and a
-	jr nz, .next
-; Set the flag.  This will cause that sprite to not be visible in the contest.
-	ld b, SET_FLAG
-	call EventFlagAction
-	pop bc
-; Check if we're done.  If so, return.  Otherwise, choose the next victim.
-	dec c
-	jr nz, .loop2
-	ret
-; 139ed
-
-Special_CheckBugContestContestantFlag: ; 139ed
-; Checks the flag of the Bug Catching Contestant whose index is loaded in a.
-
-; Bug: If a >= 10 when this is called, it will read beyond the table.
-
-	ld hl, BugCatchingContestantEventFlagTable
-	ld e, a
-	ld d, 0
-	add hl, de
-	add hl, de
-	ld e, [hl]
-	inc hl
-	ld d, [hl]
-	ld b, CHECK_FLAG
-	call EventFlagAction
-	ret
-; 139fe
-
-BugCatchingContestantEventFlagTable: ; 139fe
-	dw EVENT_BUG_CATCHING_CONTESTANT_1A
-	dw EVENT_BUG_CATCHING_CONTESTANT_2A
-	dw EVENT_BUG_CATCHING_CONTESTANT_3A
-	dw EVENT_BUG_CATCHING_CONTESTANT_4A
-	dw EVENT_BUG_CATCHING_CONTESTANT_5A
-	dw EVENT_BUG_CATCHING_CONTESTANT_6A
-	dw EVENT_BUG_CATCHING_CONTESTANT_7A
-	dw EVENT_BUG_CATCHING_CONTESTANT_8A
-	dw EVENT_BUG_CATCHING_CONTESTANT_9A
-	dw EVENT_BUG_CATCHING_CONTESTANT_10A
-; 13a12
-
-ContestDropOffMons: ; 13a12
-	ld hl, PartyMon1HP
-	ld a, [hli]
-	or [hl]
-	jr z, .fainted
-; Mask the rest of your party by setting the count to 1...
-	ld hl, PartyCount
-	ld a, 1
-	ld [hli], a
-	inc hl
-; ... backing up the second mon index somewhere...
-	ld a, [hl]
-	ld [wBugContestSecondPartySpecies], a
-; ... and replacing it with the terminator byte
-	ld [hl], $ff
-	xor a
-	ld [ScriptVar], a
-	ret
-
-.fainted
-	ld a, $1
-	ld [ScriptVar], a
-	ret
-; 13a31
-
-ContestReturnMons: ; 13a31
-; Restore the species of the second mon.
-	ld hl, PartySpecies + 1
-	ld a, [wBugContestSecondPartySpecies]
-	ld [hl], a
-; Restore the party count, which must be recomputed.
-	ld b, $1
-.loop
-	ld a, [hli]
-	cp -1
-	jr z, .done
-	inc b
-	jr .loop
-
-.done
-	ld a, b
-	ld [PartyCount], a
-	ret
-; 13a47
--- a/event/bug_contest_judging.asm
+++ /dev/null
@@ -1,395 +1,0 @@
-_BugContestJudging: ; 1369d
-	call ContestScore
-	callba TrainerRankings_BugContestScore
-	call BugContest_JudgeContestants
-	ld a, [wBugContestThirdPlacePersonID]
-	call LoadContestantName
-	ld a, [wBugContestThirdPlaceMon]
-	ld [wNamedObjectIndexBuffer], a
-	call GetPokemonName
-	ld hl, BugContest_ThirdPlaceText
-	call PrintText
-	ld a, [wBugContestSecondPlacePersonID]
-	call LoadContestantName
-	ld a, [wBugContestSecondPlaceMon]
-	ld [wNamedObjectIndexBuffer], a
-	call GetPokemonName
-	ld hl, BugContest_SecondPlaceText
-	call PrintText
-	ld a, [wBugContestFirstPlacePersonID]
-	call LoadContestantName
-	ld a, [wBugContestFirstPlaceMon]
-	ld [wNamedObjectIndexBuffer], a
-	call GetPokemonName
-	ld hl, BugContest_FirstPlaceText
-	call PrintText
-	jp BugContest_GetPlayersResult
-; 136eb
-
-BugContest_FirstPlaceText: ; 0x136eb
-	text_jump ContestJudging_FirstPlaceText
-	start_asm
-	ld de, SFX_1ST_PLACE
-	call PlaySFX
-	call WaitSFX
-	ld hl, BugContest_FirstPlaceScoreText
-	ret
-; 136fd
-
-BugContest_FirstPlaceScoreText: ; 0x136fd
-	; The winning score was @  points!
-	text_jump ContestJudging_FirstPlaceScoreText
-	db "@"
-; 0x13702
-
-BugContest_SecondPlaceText: ; 0x13702
-	; Placing second was @ , who caught a @ !@ @
-	text_jump ContestJudging_SecondPlaceText
-	start_asm
-	ld de, SFX_2ND_PLACE
-	call PlaySFX
-	call WaitSFX
-	ld hl, BugContest_SecondPlaceScoreText
-	ret
-; 13714
-
-BugContest_SecondPlaceScoreText: ; 0x13714
-	; The score was @  points!
-	text_jump ContestJudging_SecondPlaceScoreText
-	db "@"
-; 0x13719
-
-BugContest_ThirdPlaceText: ; 0x13719
-	; Placing third was @ , who caught a @ !@ @
-	text_jump ContestJudging_ThirdPlaceText
-	start_asm
-	ld de, SFX_3RD_PLACE
-	call PlaySFX
-	call WaitSFX
-	ld hl, BugContest_ThirdPlaceScoreText
-	ret
-; 1372b
-
-BugContest_ThirdPlaceScoreText: ; 0x1372b
-	; The score was @  points!
-	text_jump ContestJudging_ThirdPlaceScoreText
-	db "@"
-; 0x13730
-
-LoadContestantName: ; 13730
-
-; If a = 0, get your name.
-	dec a
-	jr z, .player
-; Find the pointer for the trainer class of the Bug Catching Contestant whose ID is in a.
-	ld c, a
-	ld b, 0
-	ld hl, BugContestantPointers
-	add hl, bc
-	add hl, bc
-	ld a, [hli]
-	ld h, [hl]
-	ld l, a
-; Copy the Trainer Class to c.
-	ld a, [hli]
-	ld c, a
-; Save hl and bc for later.
-	push hl
-	push bc
-; Get the Trainer Class name and copy it into wBugContestWinnerName.
-	callab GetTrainerClassName
-	ld hl, StringBuffer1
-	ld de, wBugContestWinnerName
-	ld bc, TRAINER_CLASS_NAME_LENGTH
-	call CopyBytes
-	ld hl, wBugContestWinnerName
-; Delete the trailing terminator and replace it with a space.
-.next
-	ld a, [hli]
-	cp "@"
-	jr nz, .next
-	dec hl
-	ld [hl], " "
-	inc hl
-	ld d, h
-	ld e, l
-; Restore the Trainer Class ID and Trainer ID pointer.  Save de for later.
-	pop bc
-	pop hl
-	push de
-; Get the name of the trainer with class c and ID b.
-	ld a, [hl]
-	ld b, a
-	callab GetTrainerName
-; Append the name to wBugContestWinnerName.
-	ld hl, StringBuffer1
-	pop de
-	ld bc, NAME_LENGTH - 1
-	jp CopyBytes
-
-.player
-	ld hl, PlayerName
-	ld de, wBugContestWinnerName
-	ld bc, NAME_LENGTH
-	jp CopyBytes
-; 13783
-
-
-INCLUDE "data/bug_contest_winners.asm"
-; 13807
-
-
-BugContest_GetPlayersResult: ; 13807
-	ld hl, wBugContestThirdPlacePersonID
-	ld de, -4
-	ld b, 3
-.loop
-	ld a, [hl]
-	cp 1 ; Player
-	jr z, .done
-	add hl, de
-	dec b
-	jr nz, .loop
-
-.done
-	ret
-; 13819
-
-BugContest_JudgeContestants: ; 13819
-	call ClearContestResults
-	call ComputeAIContestantScores
-	ld hl, wBugContestTempPersonID
-	ld a, 1 ; Player
-	ld [hli], a
-	ld a, [wContestMon]
-	ld [hli], a
-	ld a, [hProduct]
-	ld [hli], a
-	ld a, [hProduct + 1]
-	ld [hl], a
-	call DetermineContestWinners
-	ret
-; 13833
-
-ClearContestResults: ; 13833
-	ld hl, wBugContestResults
-	ld b, wBugContestWinnersEnd - wBugContestResults
-	xor a
-.loop
-	ld [hli], a
-	dec b
-	jr nz, .loop
-	ret
-; 1383e
-
-DetermineContestWinners: ; 1383e
-	ld de, wBugContestTempScore
-	ld hl, wBugContestFirstPlaceScore
-	ld c, 2
-	call StringCmp
-	jr c, .not_first_place
-	ld hl, wBugContestSecondPlacePersonID
-	ld de, wBugContestThirdPlacePersonID
-	ld bc, 4
-	call CopyBytes
-	ld hl, wBugContestFirstPlacePersonID
-	ld de, wBugContestSecondPlacePersonID
-	ld bc, 4
-	call CopyBytes
-	ld hl, wBugContestFirstPlacePersonID
-	call CopyTempContestant
-	jr .done
-
-.not_first_place
-	ld de, wBugContestTempScore
-	ld hl, wBugContestSecondPlaceScore
-	ld c, 2
-	call StringCmp
-	jr c, .not_second_place
-	ld hl, wBugContestSecondPlacePersonID
-	ld de, wBugContestThirdPlacePersonID
-	ld bc, 4
-	call CopyBytes
-	ld hl, wBugContestSecondPlacePersonID
-	call CopyTempContestant
-	jr .done
-
-.not_second_place
-	ld de, wBugContestTempScore
-	ld hl, wBugContestThirdPlaceScore
-	ld c, 2
-	call StringCmp
-	jr c, .done
-	ld hl, wBugContestThirdPlacePersonID
-	call CopyTempContestant
-
-.done
-	ret
-; 138a0
-
-CopyTempContestant: ; 138a0
-; Could've just called CopyBytes.
-	ld de, wBugContestTempPersonID
-rept 3
-	ld a, [de]
-	inc de
-	ld [hli], a
-endr
-	ld a, [de]
-	inc de
-	ld [hl], a
-	ret
-; 138b0
-
-ComputeAIContestantScores: ; 138b0
-	ld e, 0
-.loop
-	push de
-	call Special_CheckBugContestContestantFlag
-	pop de
-	jr nz, .done
-	ld a, e
-	inc a
-	inc a
-	ld [wBugContestTempPersonID], a
-	dec a
-	ld c, a
-	ld b, 0
-	ld hl, BugContestantPointers
-	add hl, bc
-	add hl, bc
-	ld a, [hli]
-	ld h, [hl]
-	ld l, a
-	inc hl
-	inc hl
-.loop2
-	call Random
-	and 3
-	cp 3
-	jr z, .loop2
-	ld c, a
-	ld b, 0
-	add hl, bc
-	add hl, bc
-	add hl, bc
-	ld a, [hli]
-	ld [wBugContestTempMon], a
-	ld a, [hli]
-	ld h, [hl]
-	ld l, a
-	call Random
-	and 7
-	ld c, a
-	ld b, 0
-	add hl, bc
-	ld a, h
-	ld [wBugContestTempScore], a
-	ld a, l
-	ld [wBugContestTempScore + 1], a
-	push de
-	call DetermineContestWinners
-	pop de
-
-.done
-	inc e
-	ld a, e
-	cp 10
-	jr nz, .loop
-	ret
-; 13900
-
-ContestScore: ; 13900
-; Determine the player's score in the Bug Catching Contest.
-
-	xor a
-	ld [hProduct], a
-	ld [hMultiplicand], a
-
-	ld a, [wContestMonSpecies] ; Species
-	and a
-	jr z, .done
-
-	; Tally the following:
-
-	; Max HP * 4
-	ld a, [wContestMonMaxHP + 1]
-	call .AddContestStat
-	ld a, [wContestMonMaxHP + 1]
-	call .AddContestStat
-	ld a, [wContestMonMaxHP + 1]
-	call .AddContestStat
-	ld a, [wContestMonMaxHP + 1]
-	call .AddContestStat
-
-	; Stats
-	ld a, [wContestMonAttack  + 1]
-	call .AddContestStat
-	ld a, [wContestMonDefense + 1]
-	call .AddContestStat
-	ld a, [wContestMonSpeed   + 1]
-	call .AddContestStat
-	ld a, [wContestMonSpclAtk + 1]
-	call .AddContestStat
-	ld a, [wContestMonSpclDef + 1]
-	call .AddContestStat
-
-	; DVs
-	ld a, [wContestMonDVs + 0]
-	ld b, a
-	and 2
-	add a
-	add a
-	ld c, a
-
-	swap b
-	ld a, b
-	and 2
-	add a
-	add c
-	ld d, a
-
-	ld a, [wContestMonDVs + 1]
-	ld b, a
-	and 2
-	ld c, a
-
-	swap b
-	ld a, b
-	and 2
-	srl a
-	add c
-	add c
-	add d
-	add d
-
-	call .AddContestStat
-
-	; Remaining HP / 8
-	ld a, [wContestMonHP + 1]
-	srl a
-	srl a
-	srl a
-	call .AddContestStat
-
-	; Whether it's holding an item
-	ld a, [wContestMonItem]
-	and a
-	jr z, .done
-
-	ld a, 1
-	call .AddContestStat
-
-.done
-	ret
-; 1397f
-
-.AddContestStat: ; 1397f
-	ld hl, hMultiplicand
-	add [hl]
-	ld [hl], a
-	ret nc
-	dec hl
-	inc [hl]
-	ret
-; 13988
--- a/event/bug_contest_mon_stats.asm
+++ /dev/null
@@ -1,107 +1,0 @@
-DisplayCaughtContestMonStats: ; cc000
-	call ClearBGPalettes
-	call ClearTileMap
-	call ClearSprites
-	call LoadFontsBattleExtra
-
-	ld hl, Options
-	ld a, [hl]
-	push af
-	set 4, [hl]
-
-	hlcoord 0, 0
-	ld b, 4
-	ld c, 13
-	call TextBox
-
-	hlcoord 0, 6
-	ld b, 4
-	ld c, 13
-	call TextBox
-
-	hlcoord 2, 0
-	ld de, .Stock
-	call PlaceString
-
-	hlcoord 2, 6
-	ld de, .This
-	call PlaceString
-
-	hlcoord 5, 4
-	ld de, .Health
-	call PlaceString
-
-	hlcoord 5, 10
-	ld de, .Health
-	call PlaceString
-
-	ld a, [wContestMon]
-	ld [wd265], a
-	call GetPokemonName
-	ld de, StringBuffer1
-	hlcoord 1, 2
-	call PlaceString
-
-	ld h, b
-	ld l, c
-	ld a, [wContestMonLevel]
-	ld [TempMonLevel], a
-	call PrintLevel
-
-	ld de, EnemyMonNick
-	hlcoord 1, 8
-	call PlaceString
-
-	ld h, b
-	ld l, c
-	ld a, [EnemyMonLevel]
-	ld [TempMonLevel], a
-	call PrintLevel
-
-	hlcoord 11, 4
-	ld de, wContestMonMaxHP
-	lb bc, 2, 3
-	call PrintNum
-
-	hlcoord 11, 10
-	ld de, EnemyMonMaxHP
-	call PrintNum
-
-	ld hl, SwitchMonText
-	call PrintText
-
-	pop af
-	ld [Options], a
-
-	call WaitBGMap
-	ld b, SCGB_DIPLOMA
-	call GetSGBLayout
-	call SetPalettes
-	ret
-
-.Health:
-	db "HEALTH@"
-.Stock:
-	db " STOCK ", $4a, " @"
-.This:
-	db " THIS ", $4a, "  @"
-
-SwitchMonText: ; cc0c2
-	; Switch #MON?
-	text_jump UnknownText_0x1c10cf
-	db "@"
-
-DisplayAlreadyCaughtText: ; cc0c7
-	call GetPokemonName
-	ld hl, .AlreadyCaughtText
-	jp PrintText
-
-.AlreadyCaughtText: ; 0xcc0d0
-	; You already caught a @ .
-	text_jump UnknownText_0x1c10dd
-	db "@"
-
-Predef2F:
-Predef38:
-Predef39: ; cc0d5
-	ret
--- /dev/null
+++ b/event/heal_machine_anim.asm
@@ -1,0 +1,265 @@
+HealMachineAnim: ; 12324
+	; If you have no Pokemon, don't change the buffer.  This can lead to some glitchy effects if you have no Pokemon.
+	ld a, [PartyCount]
+	and a
+	ret z
+	; The location of the healing machine relative to the player is stored in ScriptVar.
+	; 0: Up and left (Pokemon Center)
+	; 1: Left (Elm's Lab)
+	; 2: Up (Hall of Fame)
+	ld a, [ScriptVar]
+	ld [Buffer1], a
+	ld a, [rOBP1]
+	ld [Buffer2], a
+	call .DoJumptableFunctions
+	ld a, [Buffer2]
+	call DmgToCgbObjPal1
+	ret
+; 1233e
+
+.DoJumptableFunctions: ; 1233e
+	xor a
+	ld [Buffer3], a
+.jumpable_loop
+	ld a, [Buffer1]
+	ld e, a
+	ld d, 0
+	ld hl, .Pointers
+	add hl, de
+	add hl, de
+	ld a, [hli]
+	ld h, [hl]
+	ld l, a
+	ld a, [Buffer3]
+	ld e, a
+	inc a
+	ld [Buffer3], a
+	add hl, de
+	ld a, [hl]
+	cp 5
+	jr z, .finish
+	ld hl, .Jumptable
+	rst JumpTable
+	jr .jumpable_loop
+
+.finish
+	ret
+; 12365
+
+.Pointers: ; 12365
+	dw .Pokecenter
+	dw .ElmLab
+	dw .HallOfFame
+; 1236b
+
+.Pokecenter: ; 1236b
+	db 0, 1, 3, 5
+.ElmLab: ; 1236f
+	db 0, 1, 3, 5
+.HallOfFame: ; 12373
+	db 0, 2, 4, 5
+; 12377
+
+.Jumptable: ; 12377
+	dw .LoadGFX
+	dw .PC_LoadBallsOntoMachine
+	dw .HOF_LoadBallsOntoMachine
+	dw .PlayHealMusic
+	dw .HOF_PlaySFX
+	dw .dummy_5 ; never encountered
+; 12383
+
+.LoadGFX: ; 12383
+	call .LoadPalettes
+	ld de, .HealMachineGFX
+	ld hl, VTiles0 tile $7c
+	lb bc, BANK(.HealMachineGFX), $2
+	call Request2bpp
+	ret
+; 12393
+
+.PC_LoadBallsOntoMachine: ; 12393
+	ld hl, Sprites + $80
+	ld de, .PC_ElmsLab_OAM
+	call .PlaceHealingMachineTile
+	call .PlaceHealingMachineTile
+	jr .LoadBallsOntoMachine
+
+.HOF_LoadBallsOntoMachine: ; 123a1
+	ld hl, Sprites + $80
+	ld de, .HOF_OAM
+
+.LoadBallsOntoMachine: ; 123a7
+	ld a, [PartyCount]
+	ld b, a
+.party_loop
+	call .PlaceHealingMachineTile
+	push de
+	ld de, SFX_SECOND_PART_OF_ITEMFINDER
+	call PlaySFX
+	pop de
+	ld c, 30
+	call DelayFrames
+	dec b
+	jr nz, .party_loop
+	ret
+; 123bf
+
+.PlayHealMusic: ; 123bf
+	ld de, MUSIC_HEAL
+	call PlayMusic
+	jp .FlashPalettes8Times
+; 123c8
+
+.HOF_PlaySFX: ; 123c8
+	ld de, SFX_GAME_FREAK_LOGO_GS
+	call PlaySFX
+	call .FlashPalettes8Times
+	call WaitSFX
+	ld de, SFX_BOOT_PC
+	call PlaySFX
+	ret
+; 123db
+
+.dummy_5 ; 123db
+	ret
+; 123dc
+
+.PC_ElmsLab_OAM: ; 123dc
+	dsprite   4, 0,   4, 2, $7c, $16
+	dsprite   4, 0,   4, 6, $7c, $16
+	dsprite   4, 6,   4, 0, $7d, $16
+	dsprite   4, 6,   5, 0, $7d, $36 ; xflip
+	dsprite   5, 3,   4, 0, $7d, $16
+	dsprite   5, 3,   5, 0, $7d, $36 ; xflip
+	dsprite   6, 0,   4, 0, $7d, $16
+	dsprite   6, 0,   5, 0, $7d, $36 ; xflip
+; 123fc
+
+.HealMachineGFX: ; 123fc
+INCBIN "gfx/overworld/heal_machine.2bpp"
+; 1241c
+
+.HOF_OAM: ; 1241c
+	dsprite   7, 4,  10, 1, $7d, $16
+	dsprite   7, 4,  10, 6, $7d, $16
+	dsprite   7, 3,   9, 5, $7d, $16
+	dsprite   7, 3,  11, 2, $7d, $16
+	dsprite   7, 1,   9, 1, $7d, $16
+	dsprite   7, 1,  11, 5, $7d, $16
+; 12434
+
+.LoadPalettes: ; 12434
+	call IsCGB
+	jr nz, .cgb
+	ld a, %11100000
+	ld [rOBP1], a
+	ret
+
+.cgb
+	ld hl, .palettes
+	ld de, OBPals + 8 * 6
+	ld bc, 8
+	ld a, $5
+	call FarCopyWRAM
+	ld a, $1
+	ld [hCGBPalUpdate], a
+	ret
+; 12451
+
+.palettes ; 12451
+	RGB 31, 31, 31
+	RGB 31, 19, 10
+	RGB 31, 07, 01
+	RGB 00, 00, 00
+; 12459
+
+.FlashPalettes8Times: ; 12459
+	ld c, $8
+.palette_loop
+	push bc
+	call .FlashPalettes
+	ld c, 10
+	call DelayFrames
+	pop bc
+	dec c
+	jr nz, .palette_loop
+	ret
+; 12469
+
+.FlashPalettes: ; 12469
+	call IsCGB
+	jr nz, .go
+	ld a, [rOBP1]
+	xor %00101000
+	ld [rOBP1], a
+	ret
+
+.go
+	ld a, [rSVBK]
+	push af
+	ld a, $5
+	ld [rSVBK], a
+
+	ld hl, OBPals + 8 * 6
+	ld a, [hli]
+	ld e, a
+	ld a, [hli]
+	ld d, a
+	push de
+	ld c, $3
+.palette_loop_2
+	ld a, [hli]
+	ld e, a
+	ld a, [hld]
+	ld d, a
+	dec hl
+	ld a, d
+	ld [hld], a
+	ld a, e
+	ld [hli], a
+	inc hl
+	inc hl
+	inc hl
+	dec c
+	jr nz, .palette_loop_2
+	pop de
+	dec hl
+	ld a, d
+	ld [hld], a
+	ld a, e
+	ld [hl], a
+
+	pop af
+	ld [rSVBK], a
+	ld a, $1
+	ld [hCGBPalUpdate], a
+	ret
+; 124a3
+
+.PlaceHealingMachineTile: ; 124a3
+	push bc
+	ld a, [Buffer1]
+	bcpixel 2, 4
+	cp $1 ; ElmsLab
+	jr z, .okay
+	bcpixel 0, 0
+
+.okay
+	ld a, [de]
+	add c
+	inc de
+	ld [hli], a
+	ld a, [de]
+	add b
+	inc de
+	ld [hli], a
+	ld a, [de]
+	inc de
+	ld [hli], a
+	ld a, [de]
+	inc de
+	ld [hli], a
+	pop bc
+	ret
+; 124c1
--- a/event/photo.asm
+++ /dev/null
@@ -1,295 +1,0 @@
-UnownPrinter: ; 16be4
-	ld a, [UnownDex]
-	and a
-	ret z
-
-	ld a, [hInMenu]
-	push af
-	ld a, $1
-	ld [hInMenu], a
-	ld a, [Options]
-	push af
-	set NO_TEXT_SCROLL, a
-	ld [Options], a
-	call ClearBGPalettes
-	call ClearTileMap
-
-	ld de, UnownDexATile
-	ld hl, VTiles1 tile $6f
-	lb bc, BANK(UnownDexBTile), 1
-	call Request1bpp
-
-	ld de, UnownDexBTile
-	ld hl, VTiles1 tile $75
-	lb bc, BANK(UnownDexBTile), 1
-	call Request1bpp
-
-	hlcoord 0, 0
-	lb bc, 3, 18
-	call TextBox
-
-	hlcoord 0, 5
-	lb bc, 7, 7
-	call TextBox
-
-	hlcoord 0, 14
-	lb bc, 2, 18
-	call TextBox
-
-	hlcoord 1, 2
-	ld de, AlphRuinsStampString
-	call PlaceString
-
-	hlcoord 1, 16
-	ld de, UnownDexDoWhatString
-	call PlaceString
-
-	hlcoord 10, 6
-	ld de, UnownDexMenuString
-	call PlaceString
-
-	xor a
-	ld [wJumptableIndex], a
-	call .UpdateUnownFrontpic
-	call WaitBGMap
-
-	ld a, UNOWN
-	ld [CurPartySpecies], a
-	xor a
-	ld [TempMonDVs], a
-	ld [TempMonDVs + 1], a
-
-	ld b, SCGB_TRAINER_OR_MON_FRONTPIC_PALS
-	call GetSGBLayout
-	call SetPalettes
-
-.joy_loop
-	call JoyTextDelay
-
-	ld a, [hJoyPressed]
-	and B_BUTTON
-	jr nz, .pressed_b
-
-	ld a, [hJoyPressed]
-	and A_BUTTON
-	jr nz, .pressed_a
-
-	call .LeftRight
-	call DelayFrame
-	jr .joy_loop
-
-.pressed_a
-	ld a, [wJumptableIndex]
-	push af
-	callba PrintUnownStamp
-	call RestartMapMusic
-	pop af
-	ld [wJumptableIndex], a
-	jr .joy_loop
-
-.pressed_b
-	pop af
-	ld [Options], a
-	pop af
-	ld [hInMenu], a
-	call ReturnToMapFromSubmenu
-	ret
-; 16ca0
-
-.LeftRight: ; 16ca0
-	ld a, [hJoyLast]
-	and D_RIGHT
-	jr nz, .press_right
-	ld a, [hJoyLast]
-	and D_LEFT
-	jr nz, .press_left
-	ret
-
-.press_left
-	ld hl, wJumptableIndex
-	ld a, [hl]
-	and a
-	jr nz, .wrap_around_left
-	ld [hl], 26 + 1
-.wrap_around_left
-	dec [hl]
-	jr .return
-
-.press_right
-	ld hl, wJumptableIndex
-	ld a, [hl]
-	cp 26
-	jr c, .wrap_around_right
-	ld [hl], -1
-.wrap_around_right
-	inc [hl]
-
-.return
-	call .UpdateUnownFrontpic
-	ret
-; 16cc8
-
-.UpdateUnownFrontpic: ; 16cc8
-	ld a, [wJumptableIndex]
-	cp 26
-	jr z, .vacant
-	inc a
-	ld [UnownLetter], a
-	ld a, UNOWN
-	ld [CurPartySpecies], a
-	xor a
-	ld [wBoxAlignment], a
-	ld de, VTiles2
-	predef GetFrontpic
-	call .Load2bppToSRAM
-	hlcoord 1, 6
-	xor a
-	ld [hGraphicStartTile], a
-	lb bc, 7, 7
-	predef PlaceGraphic
-	ld de, VTiles2 tile $31
-	callba RotateUnownFrontpic
-	ret
-
-.Load2bppToSRAM: ; 16cff
-	ld a, [rSVBK]
-	push af
-	ld a, $6
-	ld [rSVBK], a
-
-	ld a, BANK(sScratch)
-	call GetSRAMBank
-	ld de, wDecompressScratch
-	ld hl, sScratch
-	ld a, [hROMBank]
-	ld b, a
-	ld c, $31
-	call Get2bpp
-	call CloseSRAM
-
-	pop af
-	ld [rSVBK], a
-	ret
-
-.vacant
-	hlcoord 1, 6
-	lb bc, 7, 7
-	call ClearBox
-	hlcoord 1, 9
-	ld de, UnownDexVacantString
-	call PlaceString
-	xor a
-	call GetSRAMBank
-	ld hl, sScratch
-	ld bc, $31 tiles
-	xor a
-	call ByteFill
-	ld hl, VTiles2 tile $31
-	ld de, sScratch
-	ld c, $31
-	ld a, [hROMBank]
-	ld b, a
-	call Get2bpp
-	call CloseSRAM
-	ld c, 20
-	call DelayFrames
-	ret
-; 16d57
-
-AlphRuinsStampString:
-	db " ALPH RUINS STAMP@"
-
-UnownDexDoWhatString:
-	db "Do what?@"
-
-UnownDexMenuString:
-	db   "♂ PRINT"
-	next "♀ CANCEL"
-	next "← PREVIOUS"
-	next "→ NEXT"
-	db   "@"
-
-UnownDexVacantString:
-	db "VACANT@"
-; 16d9c
-
-UnownDexATile: ; 16d9c
-INCBIN "gfx/printer/bold_a.1bpp"
-UnownDexBTile: ; 16da4
-INCBIN "gfx/printer/bold_b.1bpp"
-; 16dac
-
-PlaceUnownPrinterFrontpic: ; 16dac
-	hlcoord 0, 0
-	ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
-	ld a, " "
-	call ByteFill
-	hlcoord 7, 11
-	ld a, $31
-	ld [hGraphicStartTile], a
-	lb bc, 7, 7
-	predef PlaceGraphic
-	ret
-; 16dc7
-
-PhotoStudio: ; 16dc7
-	ld hl, .Text_AskWhichMon
-	call PrintText
-	callba SelectMonFromParty
-	jr c, .cancel
-	ld a, [CurPartySpecies]
-	cp EGG
-	jr z, .egg
-
-	ld hl, .Text_HoldStill
-	call PrintText
-	call DisableSpriteUpdates
-	callba PrintPartymon
-	call ReturnToMapWithSpeechTextbox
-	ld a, [hPrinter]
-	and a
-	jr nz, .cancel
-	ld hl, .Text_Presto
-	jr .print_text
-
-.cancel
-	ld hl, .Text_NoPicture
-	jr .print_text
-
-.egg
-	ld hl, .Text_Egg
-
-.print_text
-	call PrintText
-	ret
-; 16e04
-
-.Text_AskWhichMon: ; 0x16e04
-	; Which #MON should I photo- graph?
-	text_jump UnknownText_0x1be024
-	db "@"
-; 0x16e09
-
-.Text_HoldStill: ; 0x16e09
-	; All righty. Hold still for a bit.
-	text_jump UnknownText_0x1be047
-	db "@"
-; 0x16e0e
-
-.Text_Presto: ; 0x16e0e
-	; Presto! All done. Come again, OK?
-	text_jump UnknownText_0x1be06a
-	db "@"
-; 0x16e13
-
-.Text_NoPicture: ; 0x16e13
-	; Oh, no picture? Come again, OK?
-	text_jump UnknownText_0x1c0000
-	db "@"
-; 0x16e18
-
-.Text_Egg: ; 0x16e18
-	; An EGG? My talent is worth more…
-	text_jump UnknownText_0x1c0021
-	db "@"
-; 0x16e1d
--- /dev/null
+++ b/event/poisonstep_pals.asm
@@ -1,0 +1,48 @@
+LoadPoisonBGPals: ; cbcdd
+	call .LoadPals
+	ld a, [hCGB]
+	and a
+	ret nz
+	ret ; ????
+
+.LoadPals: ; cbce5
+	ld a, [hCGB]
+	and a
+	jr nz, .cgb
+	ld a, [TimeOfDayPal]
+	and $3
+	cp $3
+	ld a, %00000000
+	jr z, .convert_pals
+	ld a, %10101010
+
+.convert_pals
+	call DmgToCgbBGPals
+	ld c, 4
+	call DelayFrames
+	callba _UpdateTimePals
+	ret
+
+.cgb
+	ld a, [rSVBK]
+	push af
+	ld a, $5
+	ld [rSVBK], a
+	ld hl, BGPals
+	ld c, $20
+.loop
+; RGB 28, 21, 31
+	ld a, (palred 28 + palgreen 21 + palblue 31) % $100
+	ld [hli], a
+	ld a, (palred 28 + palgreen 21 + palblue 31) / $100
+	ld [hli], a
+	dec c
+	jr nz, .loop
+	pop af
+	ld [rSVBK], a
+	ld a, $1
+	ld [hCGBPalUpdate], a
+	ld c, 4
+	call DelayFrames
+	callba _UpdateTimePals
+	ret
--- /dev/null
+++ b/event/print_photo.asm
@@ -1,0 +1,61 @@
+PhotoStudio: ; 16dc7
+	ld hl, .Text_AskWhichMon
+	call PrintText
+	callba SelectMonFromParty
+	jr c, .cancel
+	ld a, [CurPartySpecies]
+	cp EGG
+	jr z, .egg
+
+	ld hl, .Text_HoldStill
+	call PrintText
+	call DisableSpriteUpdates
+	callba PrintPartymon
+	call ReturnToMapWithSpeechTextbox
+	ld a, [hPrinter]
+	and a
+	jr nz, .cancel
+	ld hl, .Text_Presto
+	jr .print_text
+
+.cancel
+	ld hl, .Text_NoPicture
+	jr .print_text
+
+.egg
+	ld hl, .Text_Egg
+
+.print_text
+	call PrintText
+	ret
+; 16e04
+
+.Text_AskWhichMon: ; 0x16e04
+	; Which #MON should I photo- graph?
+	text_jump UnknownText_0x1be024
+	db "@"
+; 0x16e09
+
+.Text_HoldStill: ; 0x16e09
+	; All righty. Hold still for a bit.
+	text_jump UnknownText_0x1be047
+	db "@"
+; 0x16e0e
+
+.Text_Presto: ; 0x16e0e
+	; Presto! All done. Come again, OK?
+	text_jump UnknownText_0x1be06a
+	db "@"
+; 0x16e13
+
+.Text_NoPicture: ; 0x16e13
+	; Oh, no picture? Come again, OK?
+	text_jump UnknownText_0x1c0000
+	db "@"
+; 0x16e18
+
+.Text_Egg: ; 0x16e18
+	; An EGG? My talent is worth more…
+	text_jump UnknownText_0x1c0021
+	db "@"
+; 0x16e1d
--- /dev/null
+++ b/event/print_unown.asm
@@ -1,0 +1,233 @@
+UnownPrinter: ; 16be4
+	ld a, [UnownDex]
+	and a
+	ret z
+
+	ld a, [hInMenu]
+	push af
+	ld a, $1
+	ld [hInMenu], a
+	ld a, [Options]
+	push af
+	set NO_TEXT_SCROLL, a
+	ld [Options], a
+	call ClearBGPalettes
+	call ClearTileMap
+
+	ld de, UnownDexATile
+	ld hl, VTiles1 tile $6f
+	lb bc, BANK(UnownDexBTile), 1
+	call Request1bpp
+
+	ld de, UnownDexBTile
+	ld hl, VTiles1 tile $75
+	lb bc, BANK(UnownDexBTile), 1
+	call Request1bpp
+
+	hlcoord 0, 0
+	lb bc, 3, 18
+	call TextBox
+
+	hlcoord 0, 5
+	lb bc, 7, 7
+	call TextBox
+
+	hlcoord 0, 14
+	lb bc, 2, 18
+	call TextBox
+
+	hlcoord 1, 2
+	ld de, AlphRuinsStampString
+	call PlaceString
+
+	hlcoord 1, 16
+	ld de, UnownDexDoWhatString
+	call PlaceString
+
+	hlcoord 10, 6
+	ld de, UnownDexMenuString
+	call PlaceString
+
+	xor a
+	ld [wJumptableIndex], a
+	call .UpdateUnownFrontpic
+	call WaitBGMap
+
+	ld a, UNOWN
+	ld [CurPartySpecies], a
+	xor a
+	ld [TempMonDVs], a
+	ld [TempMonDVs + 1], a
+
+	ld b, SCGB_TRAINER_OR_MON_FRONTPIC_PALS
+	call GetSGBLayout
+	call SetPalettes
+
+.joy_loop
+	call JoyTextDelay
+
+	ld a, [hJoyPressed]
+	and B_BUTTON
+	jr nz, .pressed_b
+
+	ld a, [hJoyPressed]
+	and A_BUTTON
+	jr nz, .pressed_a
+
+	call .LeftRight
+	call DelayFrame
+	jr .joy_loop
+
+.pressed_a
+	ld a, [wJumptableIndex]
+	push af
+	callba PrintUnownStamp
+	call RestartMapMusic
+	pop af
+	ld [wJumptableIndex], a
+	jr .joy_loop
+
+.pressed_b
+	pop af
+	ld [Options], a
+	pop af
+	ld [hInMenu], a
+	call ReturnToMapFromSubmenu
+	ret
+; 16ca0
+
+.LeftRight: ; 16ca0
+	ld a, [hJoyLast]
+	and D_RIGHT
+	jr nz, .press_right
+	ld a, [hJoyLast]
+	and D_LEFT
+	jr nz, .press_left
+	ret
+
+.press_left
+	ld hl, wJumptableIndex
+	ld a, [hl]
+	and a
+	jr nz, .wrap_around_left
+	ld [hl], 26 + 1
+.wrap_around_left
+	dec [hl]
+	jr .return
+
+.press_right
+	ld hl, wJumptableIndex
+	ld a, [hl]
+	cp 26
+	jr c, .wrap_around_right
+	ld [hl], -1
+.wrap_around_right
+	inc [hl]
+
+.return
+	call .UpdateUnownFrontpic
+	ret
+; 16cc8
+
+.UpdateUnownFrontpic: ; 16cc8
+	ld a, [wJumptableIndex]
+	cp 26
+	jr z, .vacant
+	inc a
+	ld [UnownLetter], a
+	ld a, UNOWN
+	ld [CurPartySpecies], a
+	xor a
+	ld [wBoxAlignment], a
+	ld de, VTiles2
+	predef GetFrontpic
+	call .Load2bppToSRAM
+	hlcoord 1, 6
+	xor a
+	ld [hGraphicStartTile], a
+	lb bc, 7, 7
+	predef PlaceGraphic
+	ld de, VTiles2 tile $31
+	callba RotateUnownFrontpic
+	ret
+
+.Load2bppToSRAM: ; 16cff
+	ld a, [rSVBK]
+	push af
+	ld a, $6
+	ld [rSVBK], a
+
+	ld a, BANK(sScratch)
+	call GetSRAMBank
+	ld de, wDecompressScratch
+	ld hl, sScratch
+	ld a, [hROMBank]
+	ld b, a
+	ld c, $31
+	call Get2bpp
+	call CloseSRAM
+
+	pop af
+	ld [rSVBK], a
+	ret
+
+.vacant
+	hlcoord 1, 6
+	lb bc, 7, 7
+	call ClearBox
+	hlcoord 1, 9
+	ld de, UnownDexVacantString
+	call PlaceString
+	xor a
+	call GetSRAMBank
+	ld hl, sScratch
+	ld bc, $31 tiles
+	xor a
+	call ByteFill
+	ld hl, VTiles2 tile $31
+	ld de, sScratch
+	ld c, $31
+	ld a, [hROMBank]
+	ld b, a
+	call Get2bpp
+	call CloseSRAM
+	ld c, 20
+	call DelayFrames
+	ret
+; 16d57
+
+AlphRuinsStampString:
+	db " ALPH RUINS STAMP@"
+
+UnownDexDoWhatString:
+	db "Do what?@"
+
+UnownDexMenuString:
+	db   "♂ PRINT"
+	next "♀ CANCEL"
+	next "← PREVIOUS"
+	next "→ NEXT"
+	db   "@"
+
+UnownDexVacantString:
+	db "VACANT@"
+; 16d9c
+
+UnownDexATile: ; 16d9c
+INCBIN "gfx/printer/bold_a.1bpp"
+UnownDexBTile: ; 16da4
+INCBIN "gfx/printer/bold_b.1bpp"
+; 16dac
+
+PlaceUnownPrinterFrontpic: ; 16dac
+	hlcoord 0, 0
+	ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
+	ld a, " "
+	call ByteFill
+	hlcoord 7, 11
+	ld a, $31
+	ld [hGraphicStartTile], a
+	lb bc, 7, 7
+	predef PlaceGraphic
+	ret
+; 16dc7
--- /dev/null
+++ b/event/print_unown_2.asm
@@ -1,0 +1,111 @@
+RotateUnownFrontpic: ; e0000
+; something to do with Unown printer
+	push de
+	xor a
+	call GetSRAMBank
+	ld hl, sScratch
+	ld bc, 0
+.loop
+	push bc
+	push hl
+	push bc
+	ld de, wd002
+	call .Copy
+	call .Rotate
+	ld hl, UnownPrinter_OverworldMapRectangle
+	pop bc
+	add hl, bc
+	add hl, bc
+	ld a, [hli]
+	ld e, a
+	ld d, [hl]
+	ld hl, wd012
+	call .Copy
+	pop hl
+	ld bc, $10
+	add hl, bc
+	pop bc
+	inc c
+	ld a, c
+	cp 7 * 7
+	jr c, .loop
+
+	ld hl, OverworldMap
+	ld de, sScratch
+	ld bc, 7 * 7 tiles
+	call CopyBytes
+	pop hl
+	ld de, sScratch
+	ld c, 7 * 7
+	ld a, [hROMBank]
+	ld b, a
+	call Get2bpp
+	call CloseSRAM
+	ret
+
+.Copy: ; e004e
+	ld c, $10
+.loop_copy
+	ld a, [hli]
+	ld [de], a
+	inc de
+	dec c
+	jr nz, .loop_copy
+	ret
+
+.Rotate: ; e0057
+	ld hl, wd012
+	ld e, %10000000
+	ld d, 8
+.loop_decompress
+	push hl
+	ld hl, wd002
+	call .CountSetBit
+	pop hl
+	ld a, b
+	ld [hli], a
+	push hl
+	ld hl, wd003
+	call .CountSetBit
+	pop hl
+	ld a, b
+	ld [hli], a
+	srl e
+	dec d
+	jr nz, .loop_decompress
+	ret
+
+.CountSetBit: ; e0078
+	ld b, 0
+	ld c, 8
+.loop_count
+	ld a, [hli]
+	and e
+	jr z, .clear
+	scf
+	jr .apply
+
+.clear
+	and a
+
+.apply
+	rr b
+	inc hl
+	dec c
+	jr nz, .loop_count
+	ret
+
+overworldmaprect: MACRO
+y = 0
+rept \1
+x = \1 * (\2 +- 1) + y
+rept \2
+	dw OverworldMap tile x
+x = x +- \2
+endr
+y = y + 1
+endr
+endm
+
+UnownPrinter_OverworldMapRectangle: ; e008b
+	overworldmaprect 7, 7
--- a/macros/wram.asm
+++ b/macros/wram.asm
@@ -227,7 +227,6 @@
 endm
 
 hall_of_fame: MACRO
-\1::
 \1WinCount:: db
 \1Mon1:: hof_mon \1Mon1
 \1Mon2:: hof_mon \1Mon2
--- a/main.asm
+++ b/main.asm
@@ -111,45 +111,7 @@
 	ld d, a
 	ret
 
-BugContest_SetCaughtContestMon: ; e6ce
-	ld a, [wContestMon]
-	and a
-	jr z, .firstcatch
-	ld [wd265], a
-	callba DisplayAlreadyCaughtText
-	callba DisplayCaughtContestMonStats
-	lb bc, 14, 7
-	call PlaceYesNoBox
-	ret c
-
-.firstcatch
-	call .generatestats
-	ld a, [TempEnemyMonSpecies]
-	ld [wd265], a
-	call GetPokemonName
-	ld hl, .caughttext
-	call PrintText
-	ret
-
-.generatestats ; e6fd
-	ld a, [TempEnemyMonSpecies]
-	ld [CurSpecies], a
-	ld [CurPartySpecies], a
-	call GetBaseData
-	xor a
-	ld bc, PARTYMON_STRUCT_LENGTH
-	ld hl, wContestMon
-	call ByteFill
-	xor a
-	ld [MonType], a
-	ld hl, wContestMon
-	jp GeneratePartyMonStats
-
-.caughttext ; 0xe71d
-	; Caught @ !
-	text_jump UnknownText_0x1c10c0
-	db "@"
-
+INCLUDE "event/bug_contest/caught_mon.asm"
 INCLUDE "engine/item_effects.asm"
 
 KnowsMove: ; f9ea
@@ -195,19 +157,19 @@
 	end
 
 INCLUDE "event/itemball.asm"
-INCLUDE "engine/healmachineanim.asm"
+INCLUDE "event/heal_machine_anim.asm"
 INCLUDE "event/whiteout.asm"
 INCLUDE "event/forced_movement.asm"
 INCLUDE "event/itemfinder.asm"
-INCLUDE "engine/startmenu.asm"
-INCLUDE "engine/selectmenu.asm"
+INCLUDE "engine/start_menu.asm"
+INCLUDE "engine/select_menu.asm"
 INCLUDE "event/elevator.asm"
-INCLUDE "event/bug_contest.asm"
+INCLUDE "event/bug_contest/contest.asm"
 INCLUDE "event/hidden_items.asm"
 INCLUDE "engine/collision_stdscripts.asm"
-INCLUDE "event/bug_contest_judging.asm"
+INCLUDE "event/bug_contest/judging.asm"
 INCLUDE "engine/pokerus_tick.asm"
-INCLUDE "event/bug_contest_2.asm"
+INCLUDE "event/bug_contest/contest_2.asm"
 INCLUDE "engine/unused_correct_party.asm"
 INCLUDE "engine/square_root.asm"
 
@@ -226,7 +188,8 @@
 INCLUDE "data/items/marts.asm"
 INCLUDE "event/mom.asm"
 INCLUDE "event/daycare.asm"
-INCLUDE "event/photo.asm"
+INCLUDE "event/print_unown.asm"
+INCLUDE "event/print_photo.asm"
 INCLUDE "engine/breeding.asm"
 INCLUDE "tilesets/data.asm"
 
@@ -341,18 +304,6 @@
 SECTION "bankA", ROMX
 
 INCLUDE "engine/link.asm"
-
-Function29fe4: ; unreferenced
-	ld a, $0
-	call GetSRAMBank
-	ld d, $0
-	ld b, CHECK_FLAG
-	predef FlagPredef
-	call CloseSRAM
-	ld a, c
-	and a
-	ret
-
 INCLUDE "engine/wildmons.asm"
 INCLUDE "battle/link_result.asm"
 
@@ -369,70 +320,14 @@
 INCLUDE "data/trainers/trainer_class_names.asm"
 INCLUDE "battle/ai/redundant.asm"
 INCLUDE "event/move_deleter.asm"
-INCLUDE "engine/mysterygift2.asm"
+INCLUDE "engine/mystery_gift_2.asm"
 INCLUDE "engine/tmhm2.asm"
 INCLUDE "battle/moves/move_descriptions.asm"
 INCLUDE "engine/pokerus.asm"
 INCLUDE "engine/start_battle.asm"
+INCLUDE "engine/place_graphics.asm"
 
-PlaceGraphic: ; 2ef6e
-; Fill wBoxAlignment-aligned box width b height c
-; with iterating tile starting from hGraphicStartTile at hl.
-; Predef $13
 
-	ld de, SCREEN_WIDTH
-
-	ld a, [wBoxAlignment]
-	and a
-	jr nz, .right
-
-	ld a, [hGraphicStartTile]
-.x1
-	push bc
-	push hl
-
-.y1
-	ld [hl], a
-	add hl, de
-	inc a
-	dec c
-	jr nz, .y1
-
-	pop hl
-	inc hl
-	pop bc
-	dec b
-	jr nz, .x1
-	ret
-
-.right
-; Right-aligned.
-	push bc
-	ld b, 0
-	dec c
-	add hl, bc
-	pop bc
-
-	ld a, [hGraphicStartTile]
-.x2
-	push bc
-	push hl
-
-.y2
-	ld [hl], a
-	add hl, de
-	inc a
-	dec c
-	jr nz, .y2
-
-	pop hl
-	dec hl
-	pop bc
-	dec b
-	jr nz, .x2
-	ret
-
-
 SECTION "Effect Commands", ROMX
 
 INCLUDE "battle/effect_commands.asm"
@@ -474,28 +369,7 @@
 SECTION "Crystal Unique", ROMX
 
 INCLUDE "engine/init_gender.asm"
-
-DrawKrisPackGFX: ; 48e81
-	ld hl, PackFGFXPointers
-	add hl, de
-	add hl, de
-	ld a, [hli]
-	ld e, a
-	ld d, [hl]
-	ld hl, VTiles2 tile $50
-	lb bc, BANK(PackFGFX), 15
-	call Request2bpp
-	ret
-
-PackFGFXPointers: ; 48e93
-	dw PackFGFX + (15 tiles) * 1
-	dw PackFGFX + (15 tiles) * 3
-	dw PackFGFX + (15 tiles) * 0
-	dw PackFGFX + (15 tiles) * 2
-
-PackFGFX: ; 48e9b
-INCBIN "gfx/pack/pack_f.2bpp"
-
+INCLUDE "engine/pack_f.asm"
 INCLUDE "event/move_tutor.asm"
 INCLUDE "engine/crystal_colors.asm"
 INCLUDE "event/celebi.asm"
@@ -502,69 +376,10 @@
 INCLUDE "engine/main_menu.asm"
 INCLUDE "mobile/mobile_menu.asm"
 INCLUDE "engine/search.asm"
- ; mobile battle selection
 INCLUDE "mobile/mobile_12_2.asm"
+INCLUDE "event/buena_menu.asm"
 
-AskRememberPassword: ; 4ae12
-	call .DoMenu
-	ld a, $0
-	jr c, .okay
-	ld a, $1
 
-.okay
-	ld [ScriptVar], a
-	ret
-
-.DoMenu: ; 4ae1f
-	lb bc, 14, 7
-	push bc
-	ld hl, YesNoMenuDataHeader
-	call CopyMenuDataHeader
-	pop bc
-	ld a, b
-	ld [wMenuBorderLeftCoord], a
-	add $5
-	ld [wMenuBorderRightCoord], a
-	ld a, c
-	ld [wMenuBorderTopCoord], a
-	add $4
-	ld [wMenuBorderBottomCoord], a
-	call PushWindow
-	call VerticalMenu
-	push af
-	ld c, 15
-	call DelayFrames
-	call Buena_ExitMenu
-	pop af
-	jr c, .refused
-	ld a, [wMenuCursorY]
-	cp $2
-	jr z, .refused
-	and a
-	ret
-
-.refused
-	ld a, $2
-	ld [wMenuCursorY], a
-	scf
-	ret
-
-Buena_ExitMenu: ; 4ae5e
-	ld a, [hOAMUpdate]
-	push af
-	call ExitMenu
-	call UpdateSprites
-	xor a
-	ld [hOAMUpdate], a
-	call DelayFrame
-	ld a, $1
-	ld [hOAMUpdate], a
-	call ApplyTilemap
-	pop af
-	ld [hOAMUpdate], a
-	ret
-
-
 SECTION "bank13", ROMX
 
 INCLUDE "engine/map_palettes.asm"
@@ -577,27 +392,8 @@
 ; 0x4ce1f
 
 INCLUDE "data/collision_permissions.asm"
+INCLUDE "engine/empty_sram.asm"
 
-EmptyAllSRAMBanks: ; 4cf1f
-	ld a, $0
-	call .EmptyBank
-	ld a, $1
-	call .EmptyBank
-	ld a, $2
-	call .EmptyBank
-	ld a, $3
-	call .EmptyBank
-	ret
-
-.EmptyBank: ; 4cf34
-	call GetSRAMBank
-	ld hl, SRAM_Begin
-	ld bc, SRAM_End - SRAM_Begin
-	xor a
-	call ByteFill
-	call CloseSRAM
-	ret
-
 SaveMenu_LoadEDTile: ; 4cf45 (13:4f45)
 	ld a, [hCGB]
 	and a
@@ -677,18 +473,18 @@
 	ret
 
 CheckSave:: ; 4cffe
-	ld a, BANK(s1_a008)
+	ld a, BANK(sCheckValue1) ; BANK(sCheckValue2)
 	call GetSRAMBank
-	ld a, [s1_a008]
+	ld a, [sCheckValue1]
 	ld b, a
-	ld a, [s1_ad0f]
+	ld a, [sCheckValue2]
 	ld c, a
 	call CloseSRAM
 	ld a, b
-	cp 99
+	cp SAVE_CHECK_VALUE_1
 	jr nz, .ok
 	ld a, c
-	cp " "
+	cp SAVE_CHECK_VALUE_2
 	jr nz, .ok
 	ld c, $1
 	ret
@@ -1060,133 +856,8 @@
 INCLUDE "engine/stats_screen.asm"
 INCLUDE "event/catch_tutorial.asm"
 INCLUDE "engine/evolution_animation.asm"
-
-InitDisplayForHallOfFame: ; 4e881
-	call ClearBGPalettes
-	call ClearTileMap
-	call ClearSprites
-	call DisableLCD
-	call LoadStandardFont
-	call LoadFontsBattleExtra
-	hlbgcoord 0, 0
-	ld bc, VBGMap1 - VBGMap0
-	ld a, " "
-	call ByteFill
-	hlcoord 0, 0, AttrMap
-	ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
-	xor a
-	call ByteFill
-	xor a
-	ld [hSCY], a
-	ld [hSCX], a
-	call EnableLCD
-	ld hl, .SavingRecordDontTurnOff
-	call PrintText
-	call WaitBGMap2
-	call SetPalettes
-	ret
-
-.SavingRecordDontTurnOff: ; 0x4e8bd
-	; SAVING RECORD… DON'T TURN OFF!
-	text_jump UnknownText_0x1bd39e
-	db "@"
-
-InitDisplayForRedCredits: ; 4e8c2
-	call ClearBGPalettes
-	call ClearTileMap
-	call ClearSprites
-	call DisableLCD
-	call LoadStandardFont
-	call LoadFontsBattleExtra
-	hlbgcoord 0, 0
-	ld bc, VBGMap1 - VBGMap0
-	ld a, " "
-	call ByteFill
-	hlcoord 0, 0, AttrMap
-	ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
-	xor a
-	call ByteFill
-	ld hl, UnknBGPals
-	ld c, 4 tiles
-.load_white_palettes
-	ld a, (palred 31 + palgreen 31 + palblue 31) % $100
-	ld [hli], a
-	ld a, (palred 31 + palgreen 31 + palblue 31) / $100
-	ld [hli], a
-	dec c
-	jr nz, .load_white_palettes
-	xor a
-	ld [hSCY], a
-	ld [hSCX], a
-	call EnableLCD
-	call WaitBGMap2
-	call SetPalettes
-	ret
-
-ResetDisplayBetweenHallOfFameMons: ; 4e906
-	ld a, [rSVBK]
-	push af
-	ld a, $6
-	ld [rSVBK], a
-	ld hl, wDecompressScratch
-	ld bc, wScratchAttrMap - wDecompressScratch
-	ld a, " "
-	call ByteFill
-	hlbgcoord 0, 0
-	ld de, wDecompressScratch
-	ld b, 0
-	ld c, 4 tiles
-	call Request2bpp
-	pop af
-	ld [rSVBK], a
-	ret
-
-GetMobileOTTrainerClass: ; mobile function
-	ld h, b
-	ld l, c
-	call .GetMobileOTTrainerClass
-	ld c, a
-	ret
-
-.GetMobileOTTrainerClass: ; 4e930
-	ld a, [hli]
-	xor [hl]
-	ld c, a
-	jr z, .skip_male_trainers
-	srl c
-	srl c
-.male_trainer_loop
-	srl c
-	ld a, c
-	cp MaleTrainersEnd - MaleTrainers - 1
-	jr nc, .male_trainer_loop
-	inc c
-
-.skip_male_trainers
-	ld a, [de]
-	cp $1
-	ld hl, MaleTrainers
-	jr nz, .finished
-
-	ld hl, FemaleTrainers
-	ld a, c
-	and a
-	jr z, .finished
-
-.female_trainer_loop
-	srl c
-	ld a, c
-	cp FemaleTrainersEnd - FemaleTrainers - 1
-	jr nc, .female_trainer_loop
-	inc c
-
-.finished
-	ld b, $0
-	add hl, bc
-	ld a, [hl]
-	ret
-
-INCLUDE "data/trainers/gendered_trainers.asm"
+INCLUDE "engine/init_hof_credits.asm"
+INCLUDE "mobile/get_trainer_class.asm"
 INCLUDE "battle/sliding_intro.asm"
 
 Mobile_PrintOpponentBattleMessage: ; 4ea0a
@@ -1281,342 +952,13 @@
 INCLUDE "event/card_key.asm"
 INCLUDE "event/basement_key.asm"
 INCLUDE "event/sacred_ash.asm"
-
-CopyPkmnToTempMon: ; 5084a
-; gets the BaseData of a Pkmn
-; and copys the PkmnStructure to TempMon
-
-	ld a, [CurPartyMon]
-	ld e, a
-	call GetPkmnSpecies
-	ld a, [CurPartySpecies]
-	ld [CurSpecies], a
-	call GetBaseData
-
-	ld a, [MonType]
-	ld hl, PartyMon1Species
-	ld bc, PARTYMON_STRUCT_LENGTH
-	and a
-	jr z, .copywholestruct
-	ld hl, OTPartyMon1Species
-	ld bc, PARTYMON_STRUCT_LENGTH
-	cp OTPARTYMON
-	jr z, .copywholestruct
-	ld bc, BOXMON_STRUCT_LENGTH
-	callab CopyBoxmonToTempMon
-	jr .done
-
-.copywholestruct
-	ld a, [CurPartyMon]
-	call AddNTimes
-	ld de, TempMon
-	ld bc, PARTYMON_STRUCT_LENGTH
-	call CopyBytes
-
-.done
-	ret
-
-CalcwBufferMonStats: ; 5088b
-	ld bc, wBufferMon
-	jr _TempMonStatsCalculation
-
-CalcTempmonStats: ; 50890
-	ld bc, TempMon
-_TempMonStatsCalculation: ; 50893
-	ld hl, MON_LEVEL
-	add hl, bc
-	ld a, [hl]
-	ld [CurPartyLevel], a
-	ld hl, MON_MAXHP
-	add hl, bc
-	ld d, h
-	ld e, l
-	ld hl, MON_STAT_EXP - 1
-	add hl, bc
-	push bc
-	ld b, $1
-	predef CalcPkmnStats
-	pop bc
-	ld hl, MON_HP
-	add hl, bc
-	ld d, h
-	ld e, l
-	ld a, [CurPartySpecies]
-	cp EGG
-	jr nz, .not_egg
-	xor a
-	ld [de], a
-	inc de
-	ld [de], a
-	jr .zero_status
-
-.not_egg
-	push bc
-	ld hl, MON_MAXHP
-	add hl, bc
-	ld bc, 2
-	call CopyBytes
-	pop bc
-
-.zero_status
-	ld hl, MON_STATUS
-	add hl, bc
-	xor a
-	ld [hli], a
-	ld [hl], a
-	ret
-
-GetPkmnSpecies: ; 508d5
-; [MonType] has the type of the Pkmn
-; e = Nr. of Pkmn (i.e. [CurPartyMon])
-
-	ld a, [MonType]
-	and a ; PARTYMON
-	jr z, .partymon
-	cp OTPARTYMON
-	jr z, .otpartymon
-	cp BOXMON
-	jr z, .boxmon
-	cp TEMPMON
-	jr z, .breedmon
-	; WILDMON
-
-.partymon
-	ld hl, PartySpecies
-	jr .done
-
-.otpartymon
-	ld hl, OTPartySpecies
-	jr .done
-
-.boxmon
-	ld a, BANK(sBoxSpecies)
-	call GetSRAMBank
-	ld hl, sBoxSpecies
-	call .done
-	call CloseSRAM
-	ret
-
-.breedmon
-	ld a, [wBreedMon1Species]
-	jr .done2
-
-.done
-	ld d, 0
-	add hl, de
-	ld a, [hl]
-
-.done2
-	ld [CurPartySpecies], a
-	ret
-
+INCLUDE "engine/tempmon.asm"
 INCLUDE "text/types.asm"
 INCLUDE "text/unused_gen_1_trainers.asm"
 INCLUDE "engine/mon_stats.asm"
-
-InitList: ; 50db9
-	ld a, [wInitListType]
-
-	cp INIT_ENEMYOT_LIST
-	jr nz, .check_party_ot_name
-	ld hl, OTPartyCount
-	ld de, OTPartyMonOT
-	ld a, ENEMY_OT_NAME
-	jr .done
-
-.check_party_ot_name
-	cp INIT_PLAYEROT_LIST
-	jr nz, .check_mon_name
-	ld hl, PartyCount
-	ld de, PartyMonOT
-	ld a, PARTY_OT_NAME
-	jr .done
-
-.check_mon_name
-	cp INIT_MON_LIST
-	jr nz, .check_item_name
-	ld hl, CurMart
-	ld de, PokemonNames
-	ld a, PKMN_NAME
-	jr .done
-
-.check_item_name
-	cp INIT_BAG_ITEM_LIST
-	jr nz, .check_ob_item_name
-	ld hl, NumItems
-	ld de, ItemNames
-	ld a, ITEM_NAME
-	jr .done
-
-.check_ob_item_name
-	ld hl, CurMart
-	ld de, ItemNames
-	ld a, ITEM_NAME
-.done
-	ld [wNamedObjectTypeBuffer], a ; d265
-	ld a, l
-	ld [wListPointer], a
-	ld a, h
-	ld [wListPointer + 1], a
-	ld a, e
-	ld [wUnusedD102], a
-	ld a, d
-	ld [wUnusedD102 + 1], a
-	ld bc, ItemAttributes ; ParseEnemyAction, HandleMapTimeAndJoypad, Music_LakeOfRage_Ch3, String_11a7c1 $67c1
-	ld a, c
-	ld [wItemAttributesPtr], a
-	ld a, b
-	ld [wItemAttributesPtr + 1], a
-	ret
-
+INCLUDE "engine/init_list.asm"
 INCLUDE "engine/experience.asm"
-
-_SwitchPartyMons:
-	ld a, [wd0e3]
-	dec a
-	ld [Buffer3], a
-	ld b, a
-	ld a, [wMenuCursorY]
-	dec a
-	ld [Buffer2], a
-	cp b
-	jr z, .skip
-	call .SwapMonAndMail
-	ld a, [Buffer3]
-	call .ClearSprite
-	ld a, [Buffer2]
-	call .ClearSprite
-.skip
-	ret
-
-.ClearSprite: ; 50f34 (14:4f34)
-	push af
-	hlcoord 0, 1
-	ld bc, 2 * SCREEN_WIDTH
-	call AddNTimes
-	ld bc, 2 * SCREEN_WIDTH
-	ld a, " "
-	call ByteFill
-	pop af
-	ld hl, Sprites
-	ld bc, $10
-	call AddNTimes
-	ld de, $4
-	ld c, $4
-.gfx_loop
-	ld [hl], $a0
-	add hl, de
-	dec c
-	jr nz, .gfx_loop
-	ld de, SFX_SWITCH_POKEMON
-	call WaitPlaySFX
-	ret
-
-.SwapMonAndMail: ; 50f62 (14:4f62)
-	push hl
-	push de
-	push bc
-	ld bc, PartySpecies
-	ld a, [Buffer2]
-	ld l, a
-	ld h, $0
-	add hl, bc
-	ld d, h
-	ld e, l
-	ld a, [Buffer3]
-	ld l, a
-	ld h, $0
-	add hl, bc
-	ld a, [hl]
-	push af
-	ld a, [de]
-	ld [hl], a
-	pop af
-	ld [de], a
-	ld a, [Buffer2]
-	ld hl, PartyMon1Species
-	ld bc, PARTYMON_STRUCT_LENGTH
-	call AddNTimes
-	push hl
-	ld de, wd002
-	ld bc, PARTYMON_STRUCT_LENGTH
-	call CopyBytes
-	ld a, [Buffer3]
-	ld hl, PartyMon1
-	ld bc, PARTYMON_STRUCT_LENGTH
-	call AddNTimes
-	pop de
-	push hl
-	ld bc, PARTYMON_STRUCT_LENGTH
-	call CopyBytes
-	pop de
-	ld hl, wd002
-	ld bc, PARTYMON_STRUCT_LENGTH
-	call CopyBytes
-	ld a, [Buffer2]
-	ld hl, PartyMonOT
-	call SkipNames
-	push hl
-	call .CopyNameTowd002
-	ld a, [Buffer3]
-	ld hl, PartyMonOT
-	call SkipNames
-	pop de
-	push hl
-	call .CopyName
-	pop de
-	ld hl, wd002
-	call .CopyName
-	ld hl, PartyMonNicknames
-	ld a, [Buffer2]
-	call SkipNames
-	push hl
-	call .CopyNameTowd002
-	ld hl, PartyMonNicknames
-	ld a, [Buffer3]
-	call SkipNames
-	pop de
-	push hl
-	call .CopyName
-	pop de
-	ld hl, wd002
-	call .CopyName
-	ld hl, sPartyMail
-	ld a, [Buffer2]
-	ld bc, MAIL_STRUCT_LENGTH
-	call AddNTimes
-	push hl
-	ld de, wd002
-	ld bc, MAIL_STRUCT_LENGTH
-	ld a, BANK(sPartyMail)
-	call GetSRAMBank
-	call CopyBytes
-	ld hl, sPartyMail
-	ld a, [Buffer3]
-	ld bc, MAIL_STRUCT_LENGTH
-	call AddNTimes
-	pop de
-	push hl
-	ld bc, MAIL_STRUCT_LENGTH
-	call CopyBytes
-	pop de
-	ld hl, wd002
-	ld bc, MAIL_STRUCT_LENGTH
-	call CopyBytes
-	call CloseSRAM
-	pop bc
-	pop de
-	pop hl
-	ret
-
-.CopyNameTowd002: ; 51036 (14:5036)
-	ld de, wd002
-
-.CopyName: ; 51039 (14:5039)
-	ld bc, NAME_LENGTH
-	call CopyBytes
-	ret
-
+INCLUDE "engine/switch_party_mons.asm"
 INCLUDE "gfx/load_pics.asm"
 INCLUDE "engine/move_mon_wo_mail.asm"
 INCLUDE "data/pokemon/base_stats.asm"
@@ -1744,56 +1086,8 @@
 
 INCLUDE "battle/bg_effects.asm"
 INCLUDE "battle/anims.asm"
+INCLUDE "event/poisonstep_pals.asm"
 
-LoadPoisonBGPals: ; cbcdd
-	call .LoadPals
-	ld a, [hCGB]
-	and a
-	ret nz
-	ret ; ????
-
-.LoadPals: ; cbce5
-	ld a, [hCGB]
-	and a
-	jr nz, .cgb
-	ld a, [TimeOfDayPal]
-	and $3
-	cp $3
-	ld a, %00000000
-	jr z, .convert_pals
-	ld a, %10101010
-
-.convert_pals
-	call DmgToCgbBGPals
-	ld c, 4
-	call DelayFrames
-	callba _UpdateTimePals
-	ret
-
-.cgb
-	ld a, [rSVBK]
-	push af
-	ld a, $5
-	ld [rSVBK], a
-	ld hl, BGPals
-	ld c, $20
-.loop
-; RGB 28, 21, 31
-	ld a, (palred 28 + palgreen 21 + palblue 31) % $100
-	ld [hli], a
-	ld a, (palred 28 + palgreen 21 + palblue 31) / $100
-	ld [hli], a
-	dec c
-	jr nz, .loop
-	pop af
-	ld [rSVBK], a
-	ld a, $1
-	ld [hCGBPalUpdate], a
-	ld c, 4
-	call DelayFrames
-	callba _UpdateTimePals
-	ret
-
 TheEndGFX:: ; cbd2e
 INCBIN "gfx/credits/theend.2bpp"
 
@@ -1800,7 +1094,7 @@
 
 SECTION "bank33", ROMX
 
-INCLUDE "event/bug_contest_mon_stats.asm"
+INCLUDE "event/bug_contest/display_stats.asm"
 INCLUDE "battle/anim_commands.asm"
 INCLUDE "battle/anim_objects.asm"
 
@@ -1843,118 +1137,8 @@
 
 SECTION "bank38", ROMX
 
-RotateUnownFrontpic: ; e0000
-; something to do with Unown printer
-	push de
-	xor a
-	call GetSRAMBank
-	ld hl, sScratch
-	ld bc, 0
-.loop
-	push bc
-	push hl
-	push bc
-	ld de, wd002
-	call .Copy
-	call .Rotate
-	ld hl, UnownPrinter_OverworldMapRectangle
-	pop bc
-	add hl, bc
-	add hl, bc
-	ld a, [hli]
-	ld e, a
-	ld d, [hl]
-	ld hl, wd012
-	call .Copy
-	pop hl
-	ld bc, $10
-	add hl, bc
-	pop bc
-	inc c
-	ld a, c
-	cp 7 * 7
-	jr c, .loop
+INCLUDE "event/print_unown_2.asm"
 
-	ld hl, OverworldMap
-	ld de, sScratch
-	ld bc, 7 * 7 tiles
-	call CopyBytes
-	pop hl
-	ld de, sScratch
-	ld c, 7 * 7
-	ld a, [hROMBank]
-	ld b, a
-	call Get2bpp
-	call CloseSRAM
-	ret
-
-.Copy: ; e004e
-	ld c, $10
-.loop_copy
-	ld a, [hli]
-	ld [de], a
-	inc de
-	dec c
-	jr nz, .loop_copy
-	ret
-
-.Rotate: ; e0057
-	ld hl, wd012
-	ld e, %10000000
-	ld d, 8
-.loop_decompress
-	push hl
-	ld hl, wd002
-	call .CountSetBit
-	pop hl
-	ld a, b
-	ld [hli], a
-	push hl
-	ld hl, wd003
-	call .CountSetBit
-	pop hl
-	ld a, b
-	ld [hli], a
-	srl e
-	dec d
-	jr nz, .loop_decompress
-	ret
-
-.CountSetBit: ; e0078
-	ld b, 0
-	ld c, 8
-.loop_count
-	ld a, [hli]
-	and e
-	jr z, .clear
-	scf
-	jr .apply
-
-.clear
-	and a
-
-.apply
-	rr b
-	inc hl
-	dec c
-	jr nz, .loop_count
-	ret
-
-overworldmaprect: MACRO
-y = 0
-rept \1
-x = \1 * (\2 +- 1) + y
-rept \2
-	dw OverworldMap tile x
-x = x +- \2
-endr
-y = y + 1
-endr
-endm
-
-UnownPrinter_OverworldMapRectangle: ; e008b
-	overworldmaprect 7, 7
-
 Unknown_e00ed:
 ; Graphics for an unused Game Corner
 ; game were meant to be here.
@@ -2009,7 +1193,7 @@
 INCLUDE "engine/dma_transfer.asm"
 INCLUDE "gfx/emotes.asm"
 INCLUDE "engine/warp_connection.asm"
-INCLUDE "engine/mysterygift.asm"
+INCLUDE "engine/mystery_gift.asm"
 INCLUDE "battle/used_move_text.asm"
 INCLUDE "mobile/mobile_41.asm"
 INCLUDE "gfx/overworld_font.asm"
@@ -2113,100 +1297,11 @@
 
 SECTION "bank77_2", ROMX
 
-Function1dd6a9: ; 1dd6a9
-; XXX
-	ld a, b
-	ld b, c
-	ld c, a
-	push bc
-	push de
-	ld hl, sp+$2
-	ld d, h
-	ld e, l
-	pop hl
-	lb bc, PRINTNUM_LEADINGZEROS | 2, 5
-	call PrintNum
-	pop bc
-	ret
-
-PrintHoursMins ; 1dd6bb (77:56bb)
-; Hours in b, minutes in c
-	ld a, b
-	cp 12
-	push af
-	jr c, .AM
-	jr z, .PM
-	sub 12
-	jr .PM
-.AM:
-	or a
-	jr nz, .PM
-	ld a, 12
-.PM:
-	ld b, a
-; Crazy stuff happening with the stack
-	push bc
-	ld hl, sp+$1
-	push de
-	push hl
-	pop de
-	pop hl
-	ld [hl], " "
-	lb bc, 1, 2
-	call PrintNum
-	ld [hl], ":"
-	inc hl
-	ld d, h
-	ld e, l
-	ld hl, sp+$0
-	push de
-	push hl
-	pop de
-	pop hl
-	lb bc, PRINTNUM_LEADINGZEROS | 1, 2
-	call PrintNum
-	pop bc
-	ld de, String_AM
-	pop af
-	jr c, .place_am_pm
-	ld de, String_PM
-.place_am_pm
-	inc hl
-	call PlaceString
-	ret
-
-String_AM: db "AM@" ; 1dd6fc
-String_PM: db "PM@" ; 1dd6ff
-
+INCLUDE "engine/printhoursmins.asm"
 INCLUDE "engine/diploma.asm"
 INCLUDE "engine/pokedex_3.asm"
 INCLUDE "event/catch_tutorial_input.asm"
-
-TownMap_ConvertLineBreakCharacters: ; 1de2c5
-	ld hl, StringBuffer1
-.loop
-	ld a, [hl]
-	cp "@"
-	jr z, .end
-	cp "%"
-	jr z, .line_break
-	cp "¯"
-	jr z, .line_break
-	inc hl
-	jr .loop
-
-.line_break
-	ld [hl], "<LNBRK>"
-
-.end
-	ld de, StringBuffer1
-	hlcoord 9, 0
-	call PlaceString
-	ret
-
-PokegearGFX: ; 1de2e4
-INCBIN "gfx/pokegear/pokegear.2bpp.lz"
-
+INCLUDE "engine/pokegear_2.asm"
 INCLUDE "engine/european_mail.asm"
 
 
--- a/maps/BattleTower1F.asm
+++ b/maps/BattleTower1F.asm
@@ -60,7 +60,7 @@
 	opentext
 	writetext Text_BattleTowerWelcomesYou
 	buttonsound
-	writebyte BATTLETOWERACTION_CHECK_EXPLANATION_READ ; if new save file: bit 1, [s1_be4f]
+	writebyte BATTLETOWERACTION_CHECK_EXPLANATION_READ ; if new save file: bit 1, [sBattleTowerSaveFileFlags]
 	special BattleTowerAction
 	if_not_equal $0, Script_Menu_ChallengeExplanationCancel
 	jump Script_BattleTowerIntroductionYesNo
@@ -85,7 +85,7 @@
 	special Special_TryQuickSave
 	iffalse Script_Menu_ChallengeExplanationCancel
 	dotrigger $1
-	writebyte BATTLETOWERACTION_SET_EXPLANATION_READ ; set 1, [s1_be4f]
+	writebyte BATTLETOWERACTION_SET_EXPLANATION_READ ; set 1, [sBattleTowerSaveFileFlags]
 	special BattleTowerAction
 	special BattleTowerRoomMenu
 	if_equal $a, Script_Menu_ChallengeExplanationCancel
--- a/mobile/battle_tower_5c.asm
+++ b/mobile/battle_tower_5c.asm
@@ -1079,9 +1079,9 @@
 	and a
 	ret z
 
-	ld a, BANK(s1_be4f)
+	ld a, BANK(sBattleTowerSaveFileFlags)
 	call GetSRAMBank
-	ld a, [s1_be4f]
+	ld a, [sBattleTowerSaveFileFlags]
 	and $2
 	ld [ScriptVar], a
 	call CloseSRAM
@@ -1097,11 +1097,11 @@
 	ret
 
 BattleTowerAction_SetExplanationRead: ; 170788 (5c:4788) BattleTowerAction $01
-	ld a, BANK(s1_be4f)
+	ld a, BANK(sBattleTowerSaveFileFlags)
 	call GetSRAMBank
-	ld a, [s1_be4f]
+	ld a, [sBattleTowerSaveFileFlags]
 	or $2
-	ld [s1_be4f], a
+	ld [sBattleTowerSaveFileFlags], a
 	call CloseSRAM
 	ret
 
@@ -1583,9 +1583,9 @@
 	and a
 	ret z
 
-	ld a, BANK(s1_be4f)
+	ld a, BANK(sBattleTowerSaveFileFlags)
 	call GetSRAMBank
-	ld a, [s1_be4f]
+	ld a, [sBattleTowerSaveFileFlags]
 	and $1
 	ld [ScriptVar], a
 	call CloseSRAM
@@ -1592,11 +1592,11 @@
 	ret
 
 Function170ad7: ; 170ad7 (5c:4ad7) BattleTowerAction $15
-	ld a, BANK(s1_be4f)
+	ld a, BANK(sBattleTowerSaveFileFlags)
 	call GetSRAMBank
-	ld a, [s1_be4f]
+	ld a, [sBattleTowerSaveFileFlags]
 	or $1
-	ld [s1_be4f], a
+	ld [sBattleTowerSaveFileFlags], a
 	call CloseSRAM
 	ret
 
--- /dev/null
+++ b/mobile/get_trainer_class.asm
@@ -1,0 +1,46 @@
+GetMobileOTTrainerClass: ; mobile function
+	ld h, b
+	ld l, c
+	call .GetMobileOTTrainerClass
+	ld c, a
+	ret
+
+.GetMobileOTTrainerClass: ; 4e930
+	ld a, [hli]
+	xor [hl]
+	ld c, a
+	jr z, .skip_male_trainers
+	srl c
+	srl c
+.male_trainer_loop
+	srl c
+	ld a, c
+	cp MaleTrainersEnd - MaleTrainers - 1
+	jr nc, .male_trainer_loop
+	inc c
+
+.skip_male_trainers
+	ld a, [de]
+	cp $1
+	ld hl, MaleTrainers
+	jr nz, .finished
+
+	ld hl, FemaleTrainers
+	ld a, c
+	and a
+	jr z, .finished
+
+.female_trainer_loop
+	srl c
+	ld a, c
+	cp FemaleTrainersEnd - FemaleTrainers - 1
+	jr nc, .female_trainer_loop
+	inc c
+
+.finished
+	ld b, $0
+	add hl, bc
+	ld a, [hl]
+	ret
+
+INCLUDE "data/trainers/gendered_trainers.asm"
--- a/sram.asm
+++ b/sram.asm
@@ -1,9 +1,11 @@
 SRAM_Begin EQU $a000
 SRAM_End   EQU $c000
+
 GLOBAL SRAM_Begin, SRAM_End
 
 
 SECTION "Scratch", SRAM
+
 sScratch::
 
 
@@ -11,12 +13,12 @@
 
 ; a600
 sPartyMail::
-sPartyMon1Mail::       mailmsg sPartyMon1Mail
-sPartyMon2Mail::       mailmsg sPartyMon2Mail
-sPartyMon3Mail::       mailmsg sPartyMon3Mail
-sPartyMon4Mail::       mailmsg sPartyMon4Mail
-sPartyMon5Mail::       mailmsg sPartyMon5Mail
-sPartyMon6Mail::       mailmsg sPartyMon6Mail
+sPartyMon1Mail:: mailmsg sPartyMon1Mail
+sPartyMon2Mail:: mailmsg sPartyMon2Mail
+sPartyMon3Mail:: mailmsg sPartyMon3Mail
+sPartyMon4Mail:: mailmsg sPartyMon4Mail
+sPartyMon5Mail:: mailmsg sPartyMon5Mail
+sPartyMon6Mail:: mailmsg sPartyMon6Mail
 
 ; a71a
 sPartyMailBackup::
@@ -28,45 +30,45 @@
 sPartyMon6MailBackup:: mailmsg sPartyMon6MailBackup
 
 ; a834
-sMailboxCount:: ds 1
+sMailboxCount:: db
 sMailbox::
-sMailbox1::            mailmsg sMailbox1
-sMailbox2::            mailmsg sMailbox2
-sMailbox3::            mailmsg sMailbox3
-sMailbox4::            mailmsg sMailbox4
-sMailbox5::            mailmsg sMailbox5
-sMailbox6::            mailmsg sMailbox6
-sMailbox7::            mailmsg sMailbox7
-sMailbox8::            mailmsg sMailbox8
-sMailbox9::            mailmsg sMailbox9
-sMailbox10::           mailmsg sMailbox10
+sMailbox1::  mailmsg sMailbox1
+sMailbox2::  mailmsg sMailbox2
+sMailbox3::  mailmsg sMailbox3
+sMailbox4::  mailmsg sMailbox4
+sMailbox5::  mailmsg sMailbox5
+sMailbox6::  mailmsg sMailbox6
+sMailbox7::  mailmsg sMailbox7
+sMailbox8::  mailmsg sMailbox8
+sMailbox9::  mailmsg sMailbox9
+sMailbox10:: mailmsg sMailbox10
 
 ; aa0b
-sMailboxCountBackup:: ds 1
+sMailboxCountBackup:: db
 sMailboxBackup::
-sMailbox1Backup::      mailmsg sMailbox1Backup
-sMailbox2Backup::      mailmsg sMailbox2Backup
-sMailbox3Backup::      mailmsg sMailbox3Backup
-sMailbox4Backup::      mailmsg sMailbox4Backup
-sMailbox5Backup::      mailmsg sMailbox5Backup
-sMailbox6Backup::      mailmsg sMailbox6Backup
-sMailbox7Backup::      mailmsg sMailbox7Backup
-sMailbox8Backup::      mailmsg sMailbox8Backup
-sMailbox9Backup::      mailmsg sMailbox9Backup
-sMailbox10Backup::     mailmsg sMailbox10Backup
+sMailbox1Backup::  mailmsg sMailbox1Backup
+sMailbox2Backup::  mailmsg sMailbox2Backup
+sMailbox3Backup::  mailmsg sMailbox3Backup
+sMailbox4Backup::  mailmsg sMailbox4Backup
+sMailbox5Backup::  mailmsg sMailbox5Backup
+sMailbox6Backup::  mailmsg sMailbox6Backup
+sMailbox7Backup::  mailmsg sMailbox7Backup
+sMailbox8Backup::  mailmsg sMailbox8Backup
+sMailbox9Backup::  mailmsg sMailbox9Backup
+sMailbox10Backup:: mailmsg sMailbox10Backup
 
 ; abe2
-sMysteryGiftItem:: ds 1
-sMysteryGiftUnlocked:: ds 1
-sBackupMysteryGiftItem:: ds 1
-sNumDailyMysteryGiftPartnerIDs:: ds 1
+sMysteryGiftItem:: db
+sMysteryGiftUnlocked:: db
+sBackupMysteryGiftItem:: db
+sNumDailyMysteryGiftPartnerIDs:: db
 sDailyMysteryGiftPartnerIDs:: ds 5 * 2 ; maximum 5 per day, 2 bytes per ID
 sMysteryGiftDecorationsReceived:: flag_array NUM_NON_TROPHY_DECOS
 	ds 4
-sMysteryGiftTimer:: ds 1
-sMysteryGiftTimerStartDay:: ds 1
+sMysteryGiftTimer:: db
+sMysteryGiftTimerStartDay:: db
 	ds 1
-sMysteryGiftTrainerHouseFlag:: ds 1
+sMysteryGiftTrainerHouseFlag:: db
 sMysteryGiftPartnerName:: ds NAME_LENGTH
 s0_ac09:: ds 1
 sMysteryGiftTrainer:: ds (1 + 1 + NUM_MOVES) * PARTY_LENGTH + 2 ; ac0a
@@ -75,13 +77,15 @@
 	ds $30
 
 sRTCStatusFlags:: ds 8
-sLuckyNumberDay:: ds 1
-sLuckyIDNumber:: ds 2
+sLuckyNumberDay:: db
+sLuckyIDNumber::  dw
 
+
 SECTION "Backup Save", SRAM
+
 sBackupOptions:: ds OptionsEnd - Options
 
-s0_b208:: ds 1 ; loaded with 99, used to check save corruption
+sBackupCheckValue1:: db ; loaded with SAVE_CHECK_VALUE_1, used to check save corruption
 
 sBackupGameData:: ; b209
 sBackupPlayerData::  ds wPlayerDataEnd - wPlayerData
@@ -93,16 +97,18 @@
 	ds $18a
 ; bf0d
 
-sBackupChecksum:: ds 2
-s0_bf0f:: ds 1 ; loaded with 0x7f, used to check save corruption
-sStackTop:: ds 2
+sBackupChecksum:: dw
 
+sBackupCheckValue2:: db ; loaded with SAVE_CHECK_VALUE_2, used to check save corruption
 
+sStackTop:: dw
+
+
 SECTION "Save", SRAM
 
 sOptions:: ds OptionsEnd - Options
 
-s1_a008:: ds 1 ; loaded with 99, used to check save corruption
+sCheckValue1:: db ; loaded with SAVE_CHECK_VALUE_1, used to check save corruption
 
 sGameData:: ; a009
 sPlayerData::  ds wPlayerDataEnd - wPlayerData
@@ -114,22 +120,28 @@
 	ds $18a
 ; ad0d
 
-sChecksum::   ds 2
-s1_ad0f::     ds 1 ; loaded with 0x7f, used to check save corruption
+sChecksum:: dw
 
+sCheckValue2:: db ; loaded with SAVE_CHECK_VALUE_2, used to check save corruption
+
+
 SECTION "Active Box", SRAM
+
 ; ad10
 	box sBox
 ; b160
 
 	ds $f4
+
+
 SECTION "Link Battle Data", SRAM
+
 sLinkBattleResults:: ds $c
 
-sLinkBattleStats:: ; b260
-sLinkBattleWins::   ds 2
-sLinkBattleLosses:: ds 2 ; b262
-sLinkBattleDraws::  ds 2 ; b264
+sLinkBattleStats::
+sLinkBattleWins::   dw ; b260
+sLinkBattleLosses:: dw ; b262
+sLinkBattleDraws::  dw ; b264
 
 sLinkBattleRecord::
 sLinkBattleRecord1:: link_battle_record sLinkBattleRecord1
@@ -139,88 +151,80 @@
 sLinkBattleRecord5:: link_battle_record sLinkBattleRecord5
 sLinkBattleStatsEnd::
 
+
 SECTION "SRAM Hall of Fame", SRAM
-sHallOfFame:: ; b2c0
-; temporary until I can find a way to macrofy it
-	hall_of_fame sHallOfFame01
-	hall_of_fame sHallOfFame02
-	hall_of_fame sHallOfFame03
-	hall_of_fame sHallOfFame04
-	hall_of_fame sHallOfFame05
-	hall_of_fame sHallOfFame06
-	hall_of_fame sHallOfFame07
-	hall_of_fame sHallOfFame08
-	hall_of_fame sHallOfFame09
-	hall_of_fame sHallOfFame10
-	hall_of_fame sHallOfFame11
-	hall_of_fame sHallOfFame12
-	hall_of_fame sHallOfFame13
-	hall_of_fame sHallOfFame14
-	hall_of_fame sHallOfFame15
-	hall_of_fame sHallOfFame16
-	hall_of_fame sHallOfFame17
-	hall_of_fame sHallOfFame18
-	hall_of_fame sHallOfFame19
-	hall_of_fame sHallOfFame20
-	hall_of_fame sHallOfFame21
-	hall_of_fame sHallOfFame22
-	hall_of_fame sHallOfFame23
-	hall_of_fame sHallOfFame24
-	hall_of_fame sHallOfFame25
-	hall_of_fame sHallOfFame26
-	hall_of_fame sHallOfFame27
-	hall_of_fame sHallOfFame28
-	hall_of_fame sHallOfFame29
-	hall_of_fame sHallOfFame30
 
-; x = 1
-; rept NUM_HOF_TEAMS
-; ; PRINTT("{x}\n")
-; if STRLEN({x}) == 2
-	; PRINTT(STRSUB({x},2,1))
-	; hall_of_fame STRCAT("sHallOfFame0", STRSUB({x},2,1))
-; else
-	; PRINTT(STRSUB({x},2,2))
-	; hall_of_fame STRCAT("sHallOfFame", STRSUB({x},2,2))
-; endc
-; x = x + 1
-; endr
+sHallOfFame:: ; b2c0
+sHallOfFame01:: hall_of_fame sHallOfFame01
+sHallOfFame02:: hall_of_fame sHallOfFame02
+sHallOfFame03:: hall_of_fame sHallOfFame03
+sHallOfFame04:: hall_of_fame sHallOfFame04
+sHallOfFame05:: hall_of_fame sHallOfFame05
+sHallOfFame06:: hall_of_fame sHallOfFame06
+sHallOfFame07:: hall_of_fame sHallOfFame07
+sHallOfFame08:: hall_of_fame sHallOfFame08
+sHallOfFame09:: hall_of_fame sHallOfFame09
+sHallOfFame10:: hall_of_fame sHallOfFame10
+sHallOfFame11:: hall_of_fame sHallOfFame11
+sHallOfFame12:: hall_of_fame sHallOfFame12
+sHallOfFame13:: hall_of_fame sHallOfFame13
+sHallOfFame14:: hall_of_fame sHallOfFame14
+sHallOfFame15:: hall_of_fame sHallOfFame15
+sHallOfFame16:: hall_of_fame sHallOfFame16
+sHallOfFame17:: hall_of_fame sHallOfFame17
+sHallOfFame18:: hall_of_fame sHallOfFame18
+sHallOfFame19:: hall_of_fame sHallOfFame19
+sHallOfFame20:: hall_of_fame sHallOfFame20
+sHallOfFame21:: hall_of_fame sHallOfFame21
+sHallOfFame22:: hall_of_fame sHallOfFame22
+sHallOfFame23:: hall_of_fame sHallOfFame23
+sHallOfFame24:: hall_of_fame sHallOfFame24
+sHallOfFame25:: hall_of_fame sHallOfFame25
+sHallOfFame26:: hall_of_fame sHallOfFame26
+sHallOfFame27:: hall_of_fame sHallOfFame27
+sHallOfFame28:: hall_of_fame sHallOfFame28
+sHallOfFame29:: hall_of_fame sHallOfFame29
+sHallOfFame30:: hall_of_fame sHallOfFame30
 sHallOfFameEnd::
 
+
 SECTION "SRAM Crystal Data", SRAM
-sMobileEventIndex:: ds 1 ; be3c
 
-sCrystalData::
-	ds wCrystalDataEnd - wCrystalData
-sMobileEventIndexBackup:: ds 1
+sMobileEventIndex:: db ; be3c
 
+sCrystalData:: ds wCrystalDataEnd - wCrystalData
+sMobileEventIndexBackup:: db
+
+
 SECTION "SRAM Battle Tower", SRAM
-; data of the BattleTower must be in SRAM because you can save and leave between battles
-sBattleTowerChallengeState:: ds 1
+
+; Battle Tower data must be in SRAM because you can save and leave between battles
+sBattleTowerChallengeState::
 ; 0: normal
 ; 2: battle tower
+	db
 
 sBattleTower:: ; be46
-sNrOfBeatenBattleTowerTrainers:: ds 1
-sBTChoiceOfLevelGroup:: ds 1
-; The 7 trainers of the BattleTower are saved here, so nobody appears more than once
-sBTTrainers:: ; sbe48
-	ds 7
-s1_be4f:: ds 1
-sBattleTowerReward:: ds 1
-; Pkmn of previous trainer
+sNrOfBeatenBattleTowerTrainers:: db
+sBTChoiceOfLevelGroup:: db
+; Battle Tower trainers are saved here, so nobody appears more than once
+sBTTrainers:: ds BATTLETOWER_NROFTRAINERS ; sbe48
+sBattleTowerSaveFileFlags:: db
+sBattleTowerReward:: db
+
+; team of previous trainer
 sBTPkmnOfTrainers:: ; 0xbe51
-sBTPkmnPrevTrainer1::
-	ds 1
-sBTPkmnPrevTrainer2:: ds 1
-sBTPkmnPrevTrainer3:: ds 1
-; Pkmn of preprevious trainer
-sBTPkmnPrevPrevTrainer1:: ds 1
-sBTPkmnPrevPrevTrainer2:: ds 1
-sBTPkmnPrevPrevTrainer3:: ds 1
+sBTPkmnPrevTrainer1:: db
+sBTPkmnPrevTrainer2:: db
+sBTPkmnPrevTrainer3:: db
+; team of preprevious trainer
+sBTPkmnPrevPrevTrainer1:: db
+sBTPkmnPrevPrevTrainer2:: db
+sBTPkmnPrevPrevTrainer3:: db
 
 
 SECTION "Boxes 1-7",  SRAM, BANK [2]
+
 	box sBox1
 	box sBox2
 	box sBox3
@@ -229,7 +233,9 @@
 	box sBox6
 	box sBox7
 
+
 SECTION "Boxes 8-14", SRAM
+
 	box sBox8
 	box sBox9
 	box sBox10
@@ -239,7 +245,8 @@
 	box sBox14
 
 SECTION "SRAM Mobile", SRAM, BANK [5]
-ds 1 ; Former location for sMobileEventIndex, moved to 1:BE3C in English
+
+	ds 1 ; former location for sMobileEventIndex, moved to 1:BE3C in English
 sTrainerRankings:: ; a001
 sTrainerRankingGameTimeHOF:: ds 4
 sTrainerRankingStepCountHOF:: ds 4
@@ -285,9 +292,11 @@
 sTrainerRankingBugContestScore:: ds 2
 sTrainerRankingsChecksum:: ds 2
 sTrainerRankingsEnd:: ; a083
+
 ds 1 ; Former location for sMobileEventIndexBackup, moved to 1:BE44 in English
 sTrainerRankingsBackup:: ds sTrainerRankingsEnd - sTrainerRankings
 
 ds $945
 ; aa4b
+
 sMobileLoginPassword:: ds MOBILE_LOGIN_PASSWORD_LENGTH
--- a/wram.asm
+++ b/wram.asm
@@ -349,7 +349,7 @@
 
 NEXTU ; c608
 ; hall of fame temp struct
-	hall_of_fame wHallOfFameTemp
+wHallOfFameTemp:: hall_of_fame wHallOfFameTemp
 
 NEXTU ; c608
 ; timeset temp storage
@@ -2838,14 +2838,13 @@
 UNION ; d742
 w3_d742:: battle_tower_struct w3_d742
 ; d822
-
 NEXTU ; d742
 	ds $be
-
 wBTChoiceOfLvlGroup::
 w3_d800:: ; ds BG_MAP_WIDTH * SCREEN_HEIGHT ($240)
 	ds $69
 ENDU ; d869
+
 w3_d869:: ds $17
 w3_d880:: ds 1
 w3_d881:: ds 1
@@ -2860,7 +2859,6 @@
 w3_d8a2:: ds 1
 w3_d8a3:: ds $19d
 w3_da40:: ds $1c0
-
 w3_dc00:: ds SCREEN_WIDTH * SCREEN_HEIGHT
 w3_dd68:: ds SCREEN_WIDTH * SCREEN_HEIGHT
 	ds $11c