shithub: pokecrystal

Download patch

ref: 9180362211cf465c52798124baa5c5c06ba1d332
parent: 9bb584798e0b54a5f953665288165af86524a47c
author: Remy Oukaour <remy.oukaour@gmail.com>
date: Mon Jan 15 06:06:17 EST 2018

Move code out of gfx/ (close #474)

--- a/charmap.asm
+++ b/charmap.asm
@@ -80,7 +80,7 @@
 
 ; Actual characters (from other graphics files)
 
-	; needed for _LoadFontsExtra1 (see gfx/font.asm)
+	; needed for _LoadFontsExtra1 (see engine/load_font.asm)
 	charmap "<BLACK>",   $60 ; gfx/font/black_arrow.2bpp
 	charmap "▲",         $61 ; gfx/font/up_arrow.png
 	charmap "<PHONE>",   $62 ; gfx/font/phone_icon.2bpp
--- a/docs/design_flaws.md
+++ b/docs/design_flaws.md
@@ -24,7 +24,7 @@
 ENDM
 ```
 
-The offset is translated into a correct bank by `FixPicBank` in [gfx/load_pics.asm](/gfx/load_pics.asm):
+The offset is translated into a correct bank by `FixPicBank` in [engine/load_pics.asm](/engine/load_pics.asm):
 
 ```asm
 FixPicBank: ; 511c5
@@ -106,7 +106,7 @@
 	"Pics 2"
 ```
 
-Two routines in [gfx/load_pics.asm](/gfx/load_pics.asm) make this assumption; `GetFrontpicPointer`:
+Two routines in [engine/load_pics.asm](/engine/load_pics.asm) make this assumption; `GetFrontpicPointer`:
 
 ```asm
 	ld a, [CurPartySpecies]
--- /dev/null
+++ b/engine/events/loadfishinggfx.asm
@@ -1,0 +1,46 @@
+LoadFishingGFX: ; b84b3
+	ld a, [rVBK]
+	push af
+	ld a, $1
+	ld [rVBK], a
+
+	ld de, FishingGFX
+	ld a, [wPlayerGender]
+	bit 0, a
+	jr z, .got_gender
+	ld de, KrisFishingGFX
+.got_gender
+
+	ld hl, vTiles0 tile $02
+	call .LoadGFX
+	ld hl, vTiles0 tile $06
+	call .LoadGFX
+	ld hl, vTiles0 tile $0a
+	call .LoadGFX
+	ld hl, vTiles1 tile $7c
+	call .LoadGFX
+
+	pop af
+	ld [rVBK], a
+	ret
+; b84e3
+
+.LoadGFX: ; b84e3
+	lb bc, BANK(FishingGFX), 2
+	push de
+	call Get2bpp
+	pop de
+	ld hl, 2 tiles
+	add hl, de
+	ld d, h
+	ld e, l
+	ret
+; b84f2
+
+FishingGFX: ; b84f2
+INCBIN "gfx/overworld/chris_fish.2bpp"
+; b8582
+
+KrisFishingGFX: ; b8582
+INCBIN "gfx/overworld/kris_fish.2bpp"
+; b8612
--- /dev/null
+++ b/engine/load_font.asm
@@ -1,0 +1,156 @@
+INCLUDE "gfx/font.asm"
+
+; This and the following two functions are unreferenced.
+; Debug, perhaps?
+Unreferenced_fb434:
+	db 0
+
+Unreferenced_Functionfb435: ; 4b435
+	ld a, [Unreferenced_fb434]
+	and a
+	jp nz, Get1bpp_2
+	jp Get1bpp
+; fb43f
+
+Unreferenced_Functionfb43f: ; fb43f
+	ld a, [Unreferenced_fb434]
+	and a
+	jp nz, Get2bpp_2
+	jp Get2bpp
+; End unreferenced block
+; fb449
+
+_LoadStandardFont:: ; fb449
+	ld de, Font
+	ld hl, vTiles1
+	lb bc, BANK(Font), 128 ; "A" to "9"
+	ld a, [rLCDC]
+	bit rLCDC_ENABLE, a
+	jp z, Copy1bpp
+
+	ld de, Font
+	ld hl, vTiles1
+	lb bc, BANK(Font), 32 ; "A" to "]"
+	call Get1bpp_2
+	ld de, Font + 32 * LEN_1BPP_TILE
+	ld hl, vTiles1 tile $20
+	lb bc, BANK(Font), 32 ; "a" to $bf
+	call Get1bpp_2
+	ld de, Font + 64 * LEN_1BPP_TILE
+	ld hl, vTiles1 tile $40
+	lb bc, BANK(Font), 32 ; "Ä" to "←"
+	call Get1bpp_2
+	ld de, Font + 96 * LEN_1BPP_TILE
+	ld hl, vTiles1 tile $60
+	lb bc, BANK(Font), 32 ; "'" to "9"
+	call Get1bpp_2
+	ret
+; fb48a
+
+_LoadFontsExtra1:: ; fb48a
+	ld de, FontsExtra_SolidBlackGFX
+	ld hl, vTiles2 tile "<BLACK>" ; $60
+	lb bc, BANK(FontsExtra_SolidBlackGFX), 1
+	call Get1bpp_2
+	ld de, PokegearPhoneIconGFX
+	ld hl, vTiles2 tile "<PHONE>" ; $62
+	lb bc, BANK(PokegearPhoneIconGFX), 1
+	call Get2bpp_2
+	ld de, FontExtra tile 3
+	ld hl, vTiles2 tile "<BOLD_D>"
+	lb bc, BANK(FontExtra), 22 ; "<BOLD_D>" to "ぉ"
+	call Get2bpp_2
+	jr LoadFrame
+; fb4b0
+
+_LoadFontsExtra2:: ; fb4b0
+	ld de, FontsExtra2_UpArrowGFX
+	ld hl, vTiles2 tile "▲" ; $61
+	ld b, BANK(FontsExtra2_UpArrowGFX)
+	ld c, 1
+	call Get2bpp_2
+	ret
+; fb4be
+
+_LoadFontsBattleExtra:: ; fb4be
+	ld de, FontBattleExtra
+	ld hl, vTiles2 tile $60
+	lb bc, BANK(FontBattleExtra), 25
+	call Get2bpp_2
+	jr LoadFrame
+; fb4cc
+
+LoadFrame: ; fb4cc
+	ld a, [TextBoxFrame]
+	maskbits NUM_FRAMES +- 1
+	ld bc, 6 * LEN_1BPP_TILE
+	ld hl, Frames
+	call AddNTimes
+	ld d, h
+	ld e, l
+	ld hl, vTiles2 tile "┌" ; $79
+	lb bc, BANK(Frames), 6 ; "┌" to "┘"
+	call Get1bpp_2
+	ld hl, vTiles2 tile " " ; $7f
+	ld de, TextBoxSpaceGFX
+	lb bc, BANK(TextBoxSpaceGFX), 1
+	call Get1bpp_2
+	ret
+; fb4f2
+
+LoadBattleFontsHPBar: ; fb4f2
+	ld de, FontBattleExtra
+	ld hl, vTiles2 tile $60
+	lb bc, BANK(FontBattleExtra), 12
+	call Get2bpp_2
+	ld hl, vTiles2 tile $70
+	ld de, FontBattleExtra tile 16
+	lb bc, BANK(FontBattleExtra), 3 ; "<ど>" to "『"
+	call Get2bpp_2
+	call LoadFrame
+
+LoadHPBar: ; fb50d
+	ld de, EnemyHPBarBorderGFX
+	ld hl, vTiles2 tile $6c
+	lb bc, BANK(EnemyHPBarBorderGFX), 4
+	call Get1bpp_2
+	ld de, HPExpBarBorderGFX
+	ld hl, vTiles2 tile $73
+	lb bc, BANK(HPExpBarBorderGFX), 6
+	call Get1bpp_2
+	ld de, ExpBarGFX
+	ld hl, vTiles2 tile $55
+	lb bc, BANK(ExpBarGFX), 9
+	call Get2bpp_2
+	ld de, MobilePhoneTilesGFX tile 7 ; mobile phone icon
+	ld hl, vTiles2 tile $5e
+	lb bc, BANK(MobilePhoneTilesGFX), 2
+	call Get2bpp_2
+	ret
+; fb53e
+
+StatsScreen_LoadFont: ; fb53e
+	call _LoadFontsBattleExtra
+	ld de, EnemyHPBarBorderGFX
+	ld hl, vTiles2 tile $6c
+	lb bc, BANK(EnemyHPBarBorderGFX), 4
+	call Get1bpp_2
+	ld de, HPExpBarBorderGFX
+	ld hl, vTiles2 tile $78
+	lb bc, BANK(HPExpBarBorderGFX), 1
+	call Get1bpp_2
+	ld de, HPExpBarBorderGFX + 3 * LEN_1BPP_TILE
+	ld hl, vTiles2 tile $76
+	lb bc, BANK(HPExpBarBorderGFX), 2
+	call Get1bpp_2
+	ld de, ExpBarGFX
+	ld hl, vTiles2 tile $55
+	lb bc, BANK(ExpBarGFX), 8
+	call Get2bpp_2
+LoadStatsScreenPageTilesGFX: ; fb571
+	ld de, StatsScreenPageTilesGFX
+	ld hl, vTiles2 tile $31
+	lb bc, BANK(StatsScreenPageTilesGFX), 17
+	call Get2bpp_2
+	ret
+; fb57e
--- /dev/null
+++ b/engine/load_pics.asm
@@ -1,0 +1,494 @@
+Predef_GetUnownLetter: ; 51040
+; Return Unown letter in UnownLetter based on DVs at hl
+
+; Take the middle 2 bits of each DV and place them in order:
+;	atk  def  spd  spc
+;	.ww..xx.  .yy..zz.
+
+	; atk
+	ld a, [hl]
+	and %01100000
+	sla a
+	ld b, a
+	; def
+	ld a, [hli]
+	and %00000110
+	swap a
+	srl a
+	or b
+	ld b, a
+
+	; spd
+	ld a, [hl]
+	and %01100000
+	swap a
+	sla a
+	or b
+	ld b, a
+	; spc
+	ld a, [hl]
+	and %00000110
+	srl a
+	or b
+
+; Divide by 10 to get 0-25
+	ld [hDividend + 3], a
+	xor a
+	ld [hDividend], a
+	ld [hDividend + 1], a
+	ld [hDividend + 2], a
+	ld a, 10
+	ld [hDivisor], a
+	ld b, 4
+	call Divide
+
+; Increment to get 1-26
+	ld a, [hQuotient + 2]
+	inc a
+	ld [UnownLetter], a
+	ret
+
+Predef_GetMonFrontpic: ; 51077
+	ld a, [CurPartySpecies]
+	ld [CurSpecies], a
+	call IsAPokemon
+	ret c
+	ld a, [rSVBK]
+	push af
+	call _GetFrontpic
+	pop af
+	ld [rSVBK], a
+	ret
+
+Predef_GetAnimatedFrontpic: ; 5108b
+	ld a, [CurPartySpecies]
+	ld [CurSpecies], a
+	call IsAPokemon
+	ret c
+	ld a, [rSVBK]
+	push af
+	xor a
+	ld [hBGMapMode], a
+	call _GetFrontpic
+	call GetAnimatedFrontpic
+	pop af
+	ld [rSVBK], a
+	ret
+
+_GetFrontpic: ; 510a5
+	push de
+	call GetBaseData
+	ld a, [BasePicSize]
+	and $f
+	ld b, a
+	push bc
+	call GetFrontpicPointer
+	ld a, BANK(wDecompressEnemyFrontpic)
+	ld [rSVBK], a
+	ld a, b
+	ld de, wDecompressEnemyFrontpic
+	call FarDecompress
+	pop bc
+	ld hl, wDecompressScratch
+	ld de, wDecompressEnemyFrontpic
+	call PadFrontpic
+	pop hl
+	push hl
+	ld de, wDecompressScratch
+	ld c, 7 * 7
+	ld a, [hROMBank]
+	ld b, a
+	call Get2bpp
+	pop hl
+	ret
+
+GetFrontpicPointer: ; 510d7
+GLOBAL PokemonPicPointers, UnownPicPointers
+
+	ld a, [CurPartySpecies]
+	cp UNOWN
+	jr z, .unown
+	ld a, [CurPartySpecies]
+	ld d, BANK(PokemonPicPointers)
+	jr .ok
+
+.unown
+	ld a, [UnownLetter]
+	ld d, BANK(UnownPicPointers)
+
+.ok
+	ld hl, PokemonPicPointers ; UnownPicPointers
+	dec a
+	ld bc, 6
+	call AddNTimes
+	ld a, d
+	call GetFarByte
+	call FixPicBank
+	push af
+	inc hl
+	ld a, d
+	call GetFarHalfword
+	pop bc
+	ret
+
+GetAnimatedFrontpic: ; 51103
+	ld a, BANK(vTiles3)
+	ld [rVBK], a
+	push hl
+	ld de, wDecompressScratch
+	ld c, 7 * 7
+	ld a, [hROMBank]
+	ld b, a
+	call Get2bpp
+	pop hl
+	ld de, 7 * 7 tiles
+	add hl, de
+	push hl
+	ld a, BANK(BasePicSize)
+	ld hl, BasePicSize
+	call GetFarWRAMByte
+	pop hl
+	and $f
+	ld de, wDecompressEnemyFrontpic + 5 * 5 tiles
+	ld c, 5 * 5
+	cp 5
+	jr z, .got_dims
+	ld de, wDecompressEnemyFrontpic + 6 * 6 tiles
+	ld c, 6 * 6
+	cp 6
+	jr z, .got_dims
+	ld de, wDecompressEnemyFrontpic + 7 * 7 tiles
+	ld c, 7 * 7
+.got_dims
+
+	push hl
+	push bc
+	call LoadFrontpicTiles
+	pop bc
+	pop hl
+	ld de, wDecompressScratch
+	ld a, [hROMBank]
+	ld b, a
+	call Get2bpp
+	xor a
+	ld [rVBK], a
+	ret
+
+LoadFrontpicTiles: ; 5114f
+	ld hl, wDecompressScratch
+	swap c
+	ld a, c
+	and $f
+	ld b, a
+	ld a, c
+	and $f0
+	ld c, a
+	push bc
+	call LoadFrontpic
+	pop bc
+.loop
+	push bc
+	ld c, 0
+	call LoadFrontpic
+	pop bc
+	dec b
+	jr nz, .loop
+	ret
+
+Predef_GetMonBackpic: ; 5116c
+	ld a, [CurPartySpecies]
+	call IsAPokemon
+	ret c
+
+	ld a, [CurPartySpecies]
+	ld b, a
+	ld a, [UnownLetter]
+	ld c, a
+	ld a, [rSVBK]
+	push af
+	ld a, BANK(wDecompressScratch)
+	ld [rSVBK], a
+	push de
+
+	; These are assumed to be at the same
+	; address in their respective banks.
+	GLOBAL PokemonPicPointers,  UnownPicPointers
+	ld hl, PokemonPicPointers ; UnownPicPointers
+	ld a, b
+	ld d, BANK(PokemonPicPointers)
+	cp UNOWN
+	jr nz, .ok
+	ld a, c
+	ld d, BANK(UnownPicPointers)
+.ok
+	dec a
+	ld bc, 6
+	call AddNTimes
+	ld bc, 3
+	add hl, bc
+	ld a, d
+	call GetFarByte
+	call FixPicBank
+	push af
+	inc hl
+	ld a, d
+	call GetFarHalfword
+	ld de, wDecompressScratch
+	pop af
+	call FarDecompress
+	ld hl, wDecompressScratch
+	ld c, 6 * 6
+	call FixBackpicAlignment
+	pop hl
+	ld de, wDecompressScratch
+	ld a, [hROMBank]
+	ld b, a
+	call Get2bpp
+	pop af
+	ld [rSVBK], a
+	ret
+
+FixPicBank: ; 511c5
+; This is a thing for some reason.
+
+PICS_FIX EQU $36
+GLOBAL PICS_FIX
+
+	push hl
+	push bc
+	sub BANK(Pics_1) - PICS_FIX
+	ld c, a
+	ld b, 0
+	ld hl, .PicsBanks
+	add hl, bc
+	ld a, [hl]
+	pop bc
+	pop hl
+	ret
+
+.PicsBanks: ; 511d4
+	db BANK(Pics_1) + 0
+	db BANK(Pics_1) + 1
+	db BANK(Pics_1) + 2
+	db BANK(Pics_1) + 3
+	db BANK(Pics_1) + 4
+	db BANK(Pics_1) + 5
+	db BANK(Pics_1) + 6
+	db BANK(Pics_1) + 7
+	db BANK(Pics_1) + 8
+	db BANK(Pics_1) + 9
+	db BANK(Pics_1) + 10
+	db BANK(Pics_1) + 11
+	db BANK(Pics_1) + 12
+	db BANK(Pics_1) + 13
+	db BANK(Pics_1) + 14
+	db BANK(Pics_1) + 15
+	db BANK(Pics_1) + 16
+	db BANK(Pics_1) + 17
+	db BANK(Pics_1) + 18
+	db BANK(Pics_1) + 19
+	db BANK(Pics_1) + 20
+	db BANK(Pics_1) + 21
+	db BANK(Pics_1) + 22
+	db BANK(Pics_1) + 23
+
+Function511ec: ; 511ec
+	ld a, c
+	push de
+	ld hl, PokemonPicPointers
+	dec a
+	ld bc, 6
+	call AddNTimes
+	ld a, BANK(PokemonPicPointers)
+	call GetFarByte
+	call FixPicBank
+	push af
+	inc hl
+	ld a, BANK(PokemonPicPointers)
+	call GetFarHalfword
+	pop af
+	pop de
+	call FarDecompress
+	ret
+
+Predef_GetTrainerPic: ; 5120d
+	ld a, [TrainerClass]
+	and a
+	ret z
+	cp NUM_TRAINER_CLASSES
+	ret nc
+	call WaitBGMap
+	xor a
+	ld [hBGMapMode], a
+	ld hl, TrainerPicPointers
+	ld a, [TrainerClass]
+	dec a
+	ld bc, 3
+	call AddNTimes
+	ld a, [rSVBK]
+	push af
+	ld a, BANK(wDecompressScratch)
+	ld [rSVBK], a
+	push de
+	ld a, BANK(TrainerPicPointers)
+	call GetFarByte
+	call FixPicBank
+	push af
+	inc hl
+	ld a, BANK(TrainerPicPointers)
+	call GetFarHalfword
+	pop af
+	ld de, wDecompressScratch
+	call FarDecompress
+	pop hl
+	ld de, wDecompressScratch
+	ld c, 7 * 7
+	ld a, [hROMBank]
+	ld b, a
+	call Get2bpp
+	pop af
+	ld [rSVBK], a
+	call WaitBGMap
+	ld a, $1
+	ld [hBGMapMode], a
+	ret
+
+Predef_Decompress: ; 5125d
+; Decompress lz data from b:hl to scratch space at 6:d000, then copy it to address de.
+
+	ld a, [rSVBK]
+	push af
+	ld a, BANK(wDecompressScratch)
+	ld [rSVBK], a
+
+	push de
+	push bc
+	ld a, b
+	ld de, wDecompressScratch
+	call FarDecompress
+	pop bc
+	ld de, wDecompressScratch
+	pop hl
+	ld a, [hROMBank]
+	ld b, a
+	call Get2bpp
+
+	pop af
+	ld [rSVBK], a
+	ret
+
+FixBackpicAlignment: ; 5127c
+	push de
+	push bc
+	ld a, [wBoxAlignment]
+	and a
+	jr z, .keep_dims
+	ld a, c
+	cp 7 * 7
+	ld de, 7 * 7 tiles
+	jr z, .got_dims
+	cp 6 * 6
+	ld de, 6 * 6 tiles
+	jr z, .got_dims
+	ld de, 5 * 5 tiles
+
+.got_dims
+	ld a, [hl]
+	ld b, 0
+	ld c, 8
+.loop
+	rra
+	rl b
+	dec c
+	jr nz, .loop
+	ld a, b
+	ld [hli], a
+	dec de
+	ld a, e
+	or d
+	jr nz, .got_dims
+
+.keep_dims
+	pop bc
+	pop de
+	ret
+
+PadFrontpic: ; 512ab
+	ld a, b
+	cp 6
+	jr z, .six
+	cp 5
+	jr z, .five
+
+.seven_loop
+	ld c, $70
+	call LoadFrontpic
+	dec b
+	jr nz, .seven_loop
+	ret
+
+.six
+	ld c, $70
+	xor a
+	call .Fill
+.six_loop
+	ld c, $10
+	xor a
+	call .Fill
+	ld c, $60
+	call LoadFrontpic
+	dec b
+	jr nz, .six_loop
+	ret
+
+.five
+	ld c, $70
+	xor a
+	call .Fill
+.five_loop
+	ld c, $20
+	xor a
+	call .Fill
+	ld c, $50
+	call LoadFrontpic
+	dec b
+	jr nz, .five_loop
+	ld c, $70
+	xor a
+	call .Fill
+	ret
+
+.Fill:
+	ld [hli], a
+	dec c
+	jr nz, .Fill
+	ret
+
+LoadFrontpic: ; 512f2
+	ld a, [wBoxAlignment]
+	and a
+	jr nz, .x_flip
+.left_loop
+	ld a, [de]
+	inc de
+	ld [hli], a
+	dec c
+	jr nz, .left_loop
+	ret
+
+.x_flip
+	push bc
+.right_loop
+	ld a, [de]
+	inc de
+	ld b, a
+	xor a
+rept 8
+	rr b
+	rla
+endr
+	ld [hli], a
+	dec c
+	jr nz, .right_loop
+	pop bc
+	ret
--- /dev/null
+++ b/engine/routines/loadoverworldfont.asm
@@ -1,0 +1,17 @@
+LoadOverworldFont:: ; 106594
+	ld de, .OverworldFontGFX
+	ld hl, vTiles1
+	lb bc, BANK(.OverworldFontGFX), $80
+	call Get2bpp
+	ld de, .OverworldFontSpaceGFX
+	ld hl, vTiles2 tile " "
+	lb bc, BANK(.OverworldFontSpaceGFX), 1
+	call Get2bpp
+	ret
+; 1065ad
+
+.OverworldFontGFX:
+INCBIN "gfx/font/overworld.2bpp"
+
+.OverworldFontSpaceGFX:
+INCBIN "gfx/font/overworld_space.2bpp"
--- a/gfx/fishing.asm
+++ /dev/null
@@ -1,46 +1,0 @@
-LoadFishingGFX: ; b84b3
-	ld a, [rVBK]
-	push af
-	ld a, $1
-	ld [rVBK], a
-
-	ld de, FishingGFX
-	ld a, [wPlayerGender]
-	bit 0, a
-	jr z, .got_gender
-	ld de, KrisFishingGFX
-.got_gender
-
-	ld hl, vTiles0 tile $02
-	call .LoadGFX
-	ld hl, vTiles0 tile $06
-	call .LoadGFX
-	ld hl, vTiles0 tile $0a
-	call .LoadGFX
-	ld hl, vTiles1 tile $7c
-	call .LoadGFX
-
-	pop af
-	ld [rVBK], a
-	ret
-; b84e3
-
-.LoadGFX: ; b84e3
-	lb bc, BANK(FishingGFX), 2
-	push de
-	call Get2bpp
-	pop de
-	ld hl, 2 tiles
-	add hl, de
-	ld d, h
-	ld e, l
-	ret
-; b84f2
-
-FishingGFX: ; b84f2
-INCBIN "gfx/overworld/chris_fish.2bpp"
-; b8582
-
-KrisFishingGFX: ; b8582
-INCBIN "gfx/overworld/kris_fish.2bpp"
-; b8612
--- a/gfx/font.asm
+++ b/gfx/font.asm
@@ -80,158 +80,3 @@
 Footprints: ; f9434
 INCLUDE "gfx/footprints.asm"
 ; fb434
-
-; This and the following two functions are unreferenced.
-; Debug, perhaps?
-Unreferenced_fb434:
-	db 0
-
-Unreferenced_Functionfb435: ; 4b435
-	ld a, [Unreferenced_fb434]
-	and a
-	jp nz, Get1bpp_2
-	jp Get1bpp
-; fb43f
-
-Unreferenced_Functionfb43f: ; fb43f
-	ld a, [Unreferenced_fb434]
-	and a
-	jp nz, Get2bpp_2
-	jp Get2bpp
-; End unreferenced block
-; fb449
-
-_LoadStandardFont:: ; fb449
-	ld de, Font
-	ld hl, vTiles1
-	lb bc, BANK(Font), 128 ; "A" to "9"
-	ld a, [rLCDC]
-	bit rLCDC_ENABLE, a
-	jp z, Copy1bpp
-
-	ld de, Font
-	ld hl, vTiles1
-	lb bc, BANK(Font), 32 ; "A" to "]"
-	call Get1bpp_2
-	ld de, Font + 32 * LEN_1BPP_TILE
-	ld hl, vTiles1 tile $20
-	lb bc, BANK(Font), 32 ; "a" to $bf
-	call Get1bpp_2
-	ld de, Font + 64 * LEN_1BPP_TILE
-	ld hl, vTiles1 tile $40
-	lb bc, BANK(Font), 32 ; "Ä" to "←"
-	call Get1bpp_2
-	ld de, Font + 96 * LEN_1BPP_TILE
-	ld hl, vTiles1 tile $60
-	lb bc, BANK(Font), 32 ; "'" to "9"
-	call Get1bpp_2
-	ret
-; fb48a
-
-_LoadFontsExtra1:: ; fb48a
-	ld de, FontsExtra_SolidBlackGFX
-	ld hl, vTiles2 tile "<BLACK>" ; $60
-	lb bc, BANK(FontsExtra_SolidBlackGFX), 1
-	call Get1bpp_2
-	ld de, PokegearPhoneIconGFX
-	ld hl, vTiles2 tile "<PHONE>" ; $62
-	lb bc, BANK(PokegearPhoneIconGFX), 1
-	call Get2bpp_2
-	ld de, FontExtra tile 3
-	ld hl, vTiles2 tile "<BOLD_D>"
-	lb bc, BANK(FontExtra), 22 ; "<BOLD_D>" to "ぉ"
-	call Get2bpp_2
-	jr LoadFrame
-; fb4b0
-
-_LoadFontsExtra2:: ; fb4b0
-	ld de, FontsExtra2_UpArrowGFX
-	ld hl, vTiles2 tile "▲" ; $61
-	ld b, BANK(FontsExtra2_UpArrowGFX)
-	ld c, 1
-	call Get2bpp_2
-	ret
-; fb4be
-
-_LoadFontsBattleExtra:: ; fb4be
-	ld de, FontBattleExtra
-	ld hl, vTiles2 tile $60
-	lb bc, BANK(FontBattleExtra), 25
-	call Get2bpp_2
-	jr LoadFrame
-; fb4cc
-
-LoadFrame: ; fb4cc
-	ld a, [TextBoxFrame]
-	maskbits NUM_FRAMES +- 1
-	ld bc, 6 * LEN_1BPP_TILE
-	ld hl, Frames
-	call AddNTimes
-	ld d, h
-	ld e, l
-	ld hl, vTiles2 tile "┌" ; $79
-	lb bc, BANK(Frames), 6 ; "┌" to "┘"
-	call Get1bpp_2
-	ld hl, vTiles2 tile " " ; $7f
-	ld de, TextBoxSpaceGFX
-	lb bc, BANK(TextBoxSpaceGFX), 1
-	call Get1bpp_2
-	ret
-; fb4f2
-
-LoadBattleFontsHPBar: ; fb4f2
-	ld de, FontBattleExtra
-	ld hl, vTiles2 tile $60
-	lb bc, BANK(FontBattleExtra), 12
-	call Get2bpp_2
-	ld hl, vTiles2 tile $70
-	ld de, FontBattleExtra tile 16
-	lb bc, BANK(FontBattleExtra), 3 ; "<ど>" to "『"
-	call Get2bpp_2
-	call LoadFrame
-
-LoadHPBar: ; fb50d
-	ld de, EnemyHPBarBorderGFX
-	ld hl, vTiles2 tile $6c
-	lb bc, BANK(EnemyHPBarBorderGFX), 4
-	call Get1bpp_2
-	ld de, HPExpBarBorderGFX
-	ld hl, vTiles2 tile $73
-	lb bc, BANK(HPExpBarBorderGFX), 6
-	call Get1bpp_2
-	ld de, ExpBarGFX
-	ld hl, vTiles2 tile $55
-	lb bc, BANK(ExpBarGFX), 9
-	call Get2bpp_2
-	ld de, MobilePhoneTilesGFX tile 7 ; mobile phone icon
-	ld hl, vTiles2 tile $5e
-	lb bc, BANK(MobilePhoneTilesGFX), 2
-	call Get2bpp_2
-	ret
-; fb53e
-
-StatsScreen_LoadFont: ; fb53e
-	call _LoadFontsBattleExtra
-	ld de, EnemyHPBarBorderGFX
-	ld hl, vTiles2 tile $6c
-	lb bc, BANK(EnemyHPBarBorderGFX), 4
-	call Get1bpp_2
-	ld de, HPExpBarBorderGFX
-	ld hl, vTiles2 tile $78
-	lb bc, BANK(HPExpBarBorderGFX), 1
-	call Get1bpp_2
-	ld de, HPExpBarBorderGFX + 3 * LEN_1BPP_TILE
-	ld hl, vTiles2 tile $76
-	lb bc, BANK(HPExpBarBorderGFX), 2
-	call Get1bpp_2
-	ld de, ExpBarGFX
-	ld hl, vTiles2 tile $55
-	lb bc, BANK(ExpBarGFX), 8
-	call Get2bpp_2
-LoadStatsScreenPageTilesGFX: ; fb571
-	ld de, StatsScreenPageTilesGFX
-	ld hl, vTiles2 tile $31
-	lb bc, BANK(StatsScreenPageTilesGFX), 17
-	call Get2bpp_2
-	ret
-; fb57e
--- a/gfx/load_pics.asm
+++ /dev/null
@@ -1,494 +1,0 @@
-Predef_GetUnownLetter: ; 51040
-; Return Unown letter in UnownLetter based on DVs at hl
-
-; Take the middle 2 bits of each DV and place them in order:
-;	atk  def  spd  spc
-;	.ww..xx.  .yy..zz.
-
-	; atk
-	ld a, [hl]
-	and %01100000
-	sla a
-	ld b, a
-	; def
-	ld a, [hli]
-	and %00000110
-	swap a
-	srl a
-	or b
-	ld b, a
-
-	; spd
-	ld a, [hl]
-	and %01100000
-	swap a
-	sla a
-	or b
-	ld b, a
-	; spc
-	ld a, [hl]
-	and %00000110
-	srl a
-	or b
-
-; Divide by 10 to get 0-25
-	ld [hDividend + 3], a
-	xor a
-	ld [hDividend], a
-	ld [hDividend + 1], a
-	ld [hDividend + 2], a
-	ld a, 10
-	ld [hDivisor], a
-	ld b, 4
-	call Divide
-
-; Increment to get 1-26
-	ld a, [hQuotient + 2]
-	inc a
-	ld [UnownLetter], a
-	ret
-
-Predef_GetMonFrontpic: ; 51077
-	ld a, [CurPartySpecies]
-	ld [CurSpecies], a
-	call IsAPokemon
-	ret c
-	ld a, [rSVBK]
-	push af
-	call _GetFrontpic
-	pop af
-	ld [rSVBK], a
-	ret
-
-Predef_GetAnimatedFrontpic: ; 5108b
-	ld a, [CurPartySpecies]
-	ld [CurSpecies], a
-	call IsAPokemon
-	ret c
-	ld a, [rSVBK]
-	push af
-	xor a
-	ld [hBGMapMode], a
-	call _GetFrontpic
-	call GetAnimatedFrontpic
-	pop af
-	ld [rSVBK], a
-	ret
-
-_GetFrontpic: ; 510a5
-	push de
-	call GetBaseData
-	ld a, [BasePicSize]
-	and $f
-	ld b, a
-	push bc
-	call GetFrontpicPointer
-	ld a, BANK(wDecompressEnemyFrontpic)
-	ld [rSVBK], a
-	ld a, b
-	ld de, wDecompressEnemyFrontpic
-	call FarDecompress
-	pop bc
-	ld hl, wDecompressScratch
-	ld de, wDecompressEnemyFrontpic
-	call PadFrontpic
-	pop hl
-	push hl
-	ld de, wDecompressScratch
-	ld c, 7 * 7
-	ld a, [hROMBank]
-	ld b, a
-	call Get2bpp
-	pop hl
-	ret
-
-GetFrontpicPointer: ; 510d7
-GLOBAL PokemonPicPointers, UnownPicPointers
-
-	ld a, [CurPartySpecies]
-	cp UNOWN
-	jr z, .unown
-	ld a, [CurPartySpecies]
-	ld d, BANK(PokemonPicPointers)
-	jr .ok
-
-.unown
-	ld a, [UnownLetter]
-	ld d, BANK(UnownPicPointers)
-
-.ok
-	ld hl, PokemonPicPointers ; UnownPicPointers
-	dec a
-	ld bc, 6
-	call AddNTimes
-	ld a, d
-	call GetFarByte
-	call FixPicBank
-	push af
-	inc hl
-	ld a, d
-	call GetFarHalfword
-	pop bc
-	ret
-
-GetAnimatedFrontpic: ; 51103
-	ld a, BANK(vTiles3)
-	ld [rVBK], a
-	push hl
-	ld de, wDecompressScratch
-	ld c, 7 * 7
-	ld a, [hROMBank]
-	ld b, a
-	call Get2bpp
-	pop hl
-	ld de, 7 * 7 tiles
-	add hl, de
-	push hl
-	ld a, BANK(BasePicSize)
-	ld hl, BasePicSize
-	call GetFarWRAMByte
-	pop hl
-	and $f
-	ld de, wDecompressEnemyFrontpic + 5 * 5 tiles
-	ld c, 5 * 5
-	cp 5
-	jr z, .got_dims
-	ld de, wDecompressEnemyFrontpic + 6 * 6 tiles
-	ld c, 6 * 6
-	cp 6
-	jr z, .got_dims
-	ld de, wDecompressEnemyFrontpic + 7 * 7 tiles
-	ld c, 7 * 7
-.got_dims
-
-	push hl
-	push bc
-	call LoadFrontpicTiles
-	pop bc
-	pop hl
-	ld de, wDecompressScratch
-	ld a, [hROMBank]
-	ld b, a
-	call Get2bpp
-	xor a
-	ld [rVBK], a
-	ret
-
-LoadFrontpicTiles: ; 5114f
-	ld hl, wDecompressScratch
-	swap c
-	ld a, c
-	and $f
-	ld b, a
-	ld a, c
-	and $f0
-	ld c, a
-	push bc
-	call LoadFrontpic
-	pop bc
-.loop
-	push bc
-	ld c, 0
-	call LoadFrontpic
-	pop bc
-	dec b
-	jr nz, .loop
-	ret
-
-Predef_GetMonBackpic: ; 5116c
-	ld a, [CurPartySpecies]
-	call IsAPokemon
-	ret c
-
-	ld a, [CurPartySpecies]
-	ld b, a
-	ld a, [UnownLetter]
-	ld c, a
-	ld a, [rSVBK]
-	push af
-	ld a, BANK(wDecompressScratch)
-	ld [rSVBK], a
-	push de
-
-	; These are assumed to be at the same
-	; address in their respective banks.
-	GLOBAL PokemonPicPointers,  UnownPicPointers
-	ld hl, PokemonPicPointers ; UnownPicPointers
-	ld a, b
-	ld d, BANK(PokemonPicPointers)
-	cp UNOWN
-	jr nz, .ok
-	ld a, c
-	ld d, BANK(UnownPicPointers)
-.ok
-	dec a
-	ld bc, 6
-	call AddNTimes
-	ld bc, 3
-	add hl, bc
-	ld a, d
-	call GetFarByte
-	call FixPicBank
-	push af
-	inc hl
-	ld a, d
-	call GetFarHalfword
-	ld de, wDecompressScratch
-	pop af
-	call FarDecompress
-	ld hl, wDecompressScratch
-	ld c, 6 * 6
-	call FixBackpicAlignment
-	pop hl
-	ld de, wDecompressScratch
-	ld a, [hROMBank]
-	ld b, a
-	call Get2bpp
-	pop af
-	ld [rSVBK], a
-	ret
-
-FixPicBank: ; 511c5
-; This is a thing for some reason.
-
-PICS_FIX EQU $36
-GLOBAL PICS_FIX
-
-	push hl
-	push bc
-	sub BANK(Pics_1) - PICS_FIX
-	ld c, a
-	ld b, 0
-	ld hl, .PicsBanks
-	add hl, bc
-	ld a, [hl]
-	pop bc
-	pop hl
-	ret
-
-.PicsBanks: ; 511d4
-	db BANK(Pics_1) + 0
-	db BANK(Pics_1) + 1
-	db BANK(Pics_1) + 2
-	db BANK(Pics_1) + 3
-	db BANK(Pics_1) + 4
-	db BANK(Pics_1) + 5
-	db BANK(Pics_1) + 6
-	db BANK(Pics_1) + 7
-	db BANK(Pics_1) + 8
-	db BANK(Pics_1) + 9
-	db BANK(Pics_1) + 10
-	db BANK(Pics_1) + 11
-	db BANK(Pics_1) + 12
-	db BANK(Pics_1) + 13
-	db BANK(Pics_1) + 14
-	db BANK(Pics_1) + 15
-	db BANK(Pics_1) + 16
-	db BANK(Pics_1) + 17
-	db BANK(Pics_1) + 18
-	db BANK(Pics_1) + 19
-	db BANK(Pics_1) + 20
-	db BANK(Pics_1) + 21
-	db BANK(Pics_1) + 22
-	db BANK(Pics_1) + 23
-
-Function511ec: ; 511ec
-	ld a, c
-	push de
-	ld hl, PokemonPicPointers
-	dec a
-	ld bc, 6
-	call AddNTimes
-	ld a, BANK(PokemonPicPointers)
-	call GetFarByte
-	call FixPicBank
-	push af
-	inc hl
-	ld a, BANK(PokemonPicPointers)
-	call GetFarHalfword
-	pop af
-	pop de
-	call FarDecompress
-	ret
-
-Predef_GetTrainerPic: ; 5120d
-	ld a, [TrainerClass]
-	and a
-	ret z
-	cp NUM_TRAINER_CLASSES
-	ret nc
-	call WaitBGMap
-	xor a
-	ld [hBGMapMode], a
-	ld hl, TrainerPicPointers
-	ld a, [TrainerClass]
-	dec a
-	ld bc, 3
-	call AddNTimes
-	ld a, [rSVBK]
-	push af
-	ld a, BANK(wDecompressScratch)
-	ld [rSVBK], a
-	push de
-	ld a, BANK(TrainerPicPointers)
-	call GetFarByte
-	call FixPicBank
-	push af
-	inc hl
-	ld a, BANK(TrainerPicPointers)
-	call GetFarHalfword
-	pop af
-	ld de, wDecompressScratch
-	call FarDecompress
-	pop hl
-	ld de, wDecompressScratch
-	ld c, 7 * 7
-	ld a, [hROMBank]
-	ld b, a
-	call Get2bpp
-	pop af
-	ld [rSVBK], a
-	call WaitBGMap
-	ld a, $1
-	ld [hBGMapMode], a
-	ret
-
-Predef_Decompress: ; 5125d
-; Decompress lz data from b:hl to scratch space at 6:d000, then copy it to address de.
-
-	ld a, [rSVBK]
-	push af
-	ld a, BANK(wDecompressScratch)
-	ld [rSVBK], a
-
-	push de
-	push bc
-	ld a, b
-	ld de, wDecompressScratch
-	call FarDecompress
-	pop bc
-	ld de, wDecompressScratch
-	pop hl
-	ld a, [hROMBank]
-	ld b, a
-	call Get2bpp
-
-	pop af
-	ld [rSVBK], a
-	ret
-
-FixBackpicAlignment: ; 5127c
-	push de
-	push bc
-	ld a, [wBoxAlignment]
-	and a
-	jr z, .keep_dims
-	ld a, c
-	cp 7 * 7
-	ld de, 7 * 7 tiles
-	jr z, .got_dims
-	cp 6 * 6
-	ld de, 6 * 6 tiles
-	jr z, .got_dims
-	ld de, 5 * 5 tiles
-
-.got_dims
-	ld a, [hl]
-	ld b, $0
-	ld c, $8
-.loop
-	rra
-	rl b
-	dec c
-	jr nz, .loop
-	ld a, b
-	ld [hli], a
-	dec de
-	ld a, e
-	or d
-	jr nz, .got_dims
-
-.keep_dims
-	pop bc
-	pop de
-	ret
-
-PadFrontpic: ; 512ab
-	ld a, b
-	cp 6
-	jr z, .six
-	cp 5
-	jr z, .five
-
-.seven_loop
-	ld c, $70
-	call LoadFrontpic
-	dec b
-	jr nz, .seven_loop
-	ret
-
-.six
-	ld c, $70
-	xor a
-	call .Fill
-.six_loop
-	ld c, $10
-	xor a
-	call .Fill
-	ld c, $60
-	call LoadFrontpic
-	dec b
-	jr nz, .six_loop
-	ret
-
-.five
-	ld c, $70
-	xor a
-	call .Fill
-.five_loop
-	ld c, $20
-	xor a
-	call .Fill
-	ld c, $50
-	call LoadFrontpic
-	dec b
-	jr nz, .five_loop
-	ld c, $70
-	xor a
-	call .Fill
-	ret
-
-.Fill:
-	ld [hli], a
-	dec c
-	jr nz, .Fill
-	ret
-
-LoadFrontpic: ; 512f2
-	ld a, [wBoxAlignment]
-	and a
-	jr nz, .x_flip
-.left_loop
-	ld a, [de]
-	inc de
-	ld [hli], a
-	dec c
-	jr nz, .left_loop
-	ret
-
-.x_flip
-	push bc
-.right_loop
-	ld a, [de]
-	inc de
-	ld b, a
-	xor a
-	rept 8
-	rr b
-	rla
-	endr
-	ld [hli], a
-	dec c
-	jr nz, .right_loop
-	pop bc
-	ret
--- a/gfx/overworld_font.asm
+++ /dev/null
@@ -1,17 +1,0 @@
-LoadOverworldFont:: ; 106594
-	ld de, .OverworldFontGFX
-	ld hl, vTiles1
-	lb bc, BANK(.OverworldFontGFX), $80
-	call Get2bpp
-	ld de, .OverworldFontSpaceGFX
-	ld hl, vTiles2 tile " "
-	lb bc, BANK(.OverworldFontSpaceGFX), 1
-	call Get2bpp
-	ret
-; 1065ad
-
-.OverworldFontGFX:
-INCBIN "gfx/font/overworld.2bpp"
-
-.OverworldFontSpaceGFX:
-INCBIN "gfx/font/overworld_space.2bpp"
--- a/main.asm
+++ b/main.asm
@@ -258,7 +258,7 @@
 INCLUDE "engine/routines/initlist.asm"
 INCLUDE "engine/experience.asm"
 INCLUDE "engine/routines/switchpartymons.asm"
-INCLUDE "gfx/load_pics.asm"
+INCLUDE "engine/load_pics.asm"
 INCLUDE "engine/move_mon_wo_mail.asm"
 INCLUDE "data/pokemon/base_stats.asm"
 INCLUDE "data/pokemon/names.asm"
@@ -355,7 +355,7 @@
 INCLUDE "engine/events/map_name_sign.asm"
 INCLUDE "engine/events/checkforhiddenitems.asm"
 INCLUDE "engine/events/treemons.asm"
-INCLUDE "gfx/fishing.asm"
+INCLUDE "engine/events/loadfishinggfx.asm"
 INCLUDE "engine/radio.asm"
 INCLUDE "engine/mail_2.asm"
 
@@ -447,7 +447,7 @@
 
 SECTION "bank3E", ROMX
 
-INCLUDE "gfx/font.asm"
+INCLUDE "engine/load_font.asm"
 INCLUDE "engine/time_capsule.asm"
 INCLUDE "engine/events/name_rater.asm"
 INCLUDE "engine/routines/playslowcry.asm"
@@ -477,7 +477,7 @@
 INCLUDE "engine/mystery_gift.asm"
 INCLUDE "engine/battle/used_move_text.asm"
 INCLUDE "mobile/mobile_41.asm"
-INCLUDE "gfx/overworld_font.asm"
+INCLUDE "engine/routines/loadoverworldfont.asm"
 
 
 SECTION "Mobile 42", ROMX