shithub: pokecrystal

Download patch

ref: 33d7ef72fef045198f0ab472332e6472a54a034f
parent: 3a2dbb5289e745dfb5f26844148c0981f14e8fcf
parent: 608d0d86e47b09f1c1ddbcf3b9c51e0ac628d7ed
author: Bryan Bishop <[email protected]>
date: Mon Sep 9 12:00:05 EDT 2013

Merge branch 'yenatch/split-predefs-specials-stds' into fix-split-predefs-specials-stds

https://github.com/kanzure/pokecrystal/pull/198

--- /dev/null
+++ b/common/copy2.asm
@@ -1,0 +1,134 @@
+CopyBytes: ; 0x3026
+; copy bc bytes from hl to de
+	inc b  ; we bail the moment b hits 0, so include the last run
+	inc c  ; same thing; include last byte
+	jr .HandleLoop
+.CopyByte
+	ld a, [hli]
+	ld [de], a
+	inc de
+.HandleLoop
+	dec c
+	jr nz, .CopyByte
+	dec b
+	jr nz, .CopyByte
+	ret
+
+SwapBytes: ; 0x3034
+; swap bc bytes between hl and de
+.Loop
+	; stash [hl] away on the stack
+	ld a, [hl]
+	push af
+
+	; copy a byte from [de] to [hl]
+	ld a, [de]
+	ld [hli], a
+
+	; retrieve the previous value of [hl]; put it in [de]
+	pop af
+	ld [de], a
+	inc de
+
+	; handle loop stuff
+	dec bc
+	ld a, b
+	or c
+	jr nz, .Loop
+	ret
+
+ByteFill: ; 0x3041
+; fill bc bytes with the value of a, starting at hl
+	inc b  ; we bail the moment b hits 0, so include the last run
+	inc c  ; same thing; include last byte
+	jr .HandleLoop
+.PutByte
+	ld [hli], a
+.HandleLoop
+	dec c
+	jr nz, .PutByte
+	dec b
+	jr nz, .PutByte
+	ret
+
+GetFarByte: ; 0x304d
+; retrieve a single byte from a:hl, and return it in a.
+	; bankswitch to new bank
+	ld [hBuffer], a
+	ld a, [hROMBank]
+	push af
+	ld a, [hBuffer]
+	rst Bankswitch
+
+	; get byte from new bank
+	ld a, [hl]
+	ld [hBuffer], a
+
+	; bankswitch to previous bank
+	pop af
+	rst Bankswitch
+
+	; return retrieved value in a
+	ld a, [hBuffer]
+	ret
+
+GetFarHalfword: ; 0x305d
+; retrieve a halfword from a:hl, and return it in hl.
+	; bankswitch to new bank
+	ld [hBuffer], a
+	ld a, [hROMBank]
+	push af
+	ld a, [hBuffer]
+	rst Bankswitch
+
+	; get halfword from new bank, put it in hl
+	ld a, [hli]
+	ld h, [hl]
+	ld l, a
+
+	; bankswitch to previous bank and return
+	pop af
+	rst Bankswitch
+	ret
+; 0x306b
+
+FarCopyWRAM: ; 306b
+	ld [hBuffer], a
+	ld a, [rSVBK]
+	push af
+	ld a, [hBuffer]
+	ld [rSVBK], a
+	call CopyBytes
+	pop af
+	ld [rSVBK], a
+	ret
+; 307b
+
+GetFarWRAMByte: ; 307b
+	ld [hBuffer], a
+	ld a, [rSVBK]
+	push af
+	ld a, [hBuffer]
+	ld [rSVBK], a
+	ld a, [hl]
+	ld [hBuffer], a
+	pop af
+	ld [rSVBK], a
+	ld a, [hBuffer]
+	ret
+; 308d
+
+GetFarWRAMWord: ; 308d
+	ld [hBuffer], a
+	ld a, [rSVBK]
+	push af
+	ld a, [hBuffer]
+	ld [rSVBK], a
+	ld a, [hli]
+	ld h, [hl]
+	ld l, a
+	pop af
+	ld [rSVBK], a
+	ret
+; 309d
+
--- /dev/null
+++ b/common/math.asm
@@ -1,0 +1,76 @@
+SimpleMultiply: ; 3105
+; Return a * c.
+	and a
+	ret z
+
+	push bc
+	ld b, a
+	xor a
+.loop
+	add c
+	dec b
+	jr nz, .loop
+	pop bc
+	ret
+; 3110
+
+
+SimpleDivide: ; 3110
+; Divide a by c. Return quotient b and remainder a.
+	ld b, 0
+.loop
+	inc b
+	sub c
+	jr nc, .loop
+	dec b
+	add c
+	ret
+; 3119
+
+
+Multiply: ; 3119
+; Multiply hMultiplicand (3 bytes) by hMultiplier. Result in hProduct.
+; All values are big endian.
+	push hl
+	push bc
+
+	callab _Multiply
+
+	pop bc
+	pop hl
+	ret
+; 3124
+
+
+Divide: ; 3124
+; Divide hDividend length b (max 4 bytes) by hDivisor. Result in hQuotient.
+; All values are big endian.
+	push hl
+	push de
+	push bc
+	ld a, [hROMBank]
+	push af
+	ld a, BANK(_Divide)
+	rst Bankswitch
+
+	call _Divide
+
+	pop af
+	rst Bankswitch
+	pop bc
+	pop de
+	pop hl
+	ret
+; 3136
+
+
+SubtractSigned: ; 3136
+; Return a - b, sign in carry.
+	sub b
+	ret nc
+	cpl
+	add 1
+	scf
+	ret
+; 313d
+
--- /dev/null
+++ b/event/name_rater.asm
@@ -1,0 +1,236 @@
+NameRater: ; fb6ed
+	ld hl, UnknownText_0xfb80f
+	call PrintText
+	call Function1dcf
+	jp c, .asm_fb77e
+	ld hl, UnknownText_0xfb814
+	call PrintText
+	callba Function50000
+	jr c, .asm_fb77e
+	ld a, [CurPartySpecies]
+	cp EGG
+	jr z, .asm_fb783
+	call GetCurNick
+	call Functionfb78a
+	jr c, .asm_fb779
+	ld hl, UnknownText_0xfb819
+	call PrintText
+	call Function1dcf
+	jr c, .asm_fb77e
+	ld hl, UnknownText_0xfb81e
+	call PrintText
+	xor a
+	ld [MonType], a
+	ld a, [CurPartySpecies]
+	ld [$d265], a
+	ld [CurSpecies], a
+	call GetBaseData
+	ld b, 0
+	ld de, StringBuffer2
+	callba Function116b7
+	call Functionfb7be
+	ld hl, UnknownText_0xfb837
+	jr c, .asm_fb76c
+	call Functionfb7d3
+	ld hl, UnknownText_0xfb837
+	jr c, .asm_fb76c
+	ld hl, PartyMon1Nickname
+	ld bc, $000b
+	ld a, [CurPartyMon]
+	call AddNTimes
+	ld e, l
+	ld d, h
+	ld hl, StringBuffer2
+	ld bc, $000b
+	call CopyBytes
+	ld hl, UnknownText_0xfb823
+
+.asm_fb76c
+	push hl
+	call GetCurNick
+	ld hl, UnknownText_0xfb83c
+	call PrintText
+	pop hl
+	jr .asm_fb786
+
+.asm_fb779
+	ld hl, UnknownText_0xfb82d
+	jr .asm_fb786
+
+.asm_fb77e
+	ld hl, UnknownText_0xfb828
+	jr .asm_fb786
+
+.asm_fb783
+	ld hl, UnknownText_0xfb832
+
+.asm_fb786
+	call PrintText
+	ret
+; fb78a
+
+Functionfb78a: ; fb78a
+	ld hl, PartyMon1OT
+	ld bc, $000b
+	ld a, [CurPartyMon]
+	call AddNTimes
+	ld de, PlayerName
+	ld c, $b
+	call .asm_fb7b1
+	jr c, .asm_fb7bc
+	ld hl, PartyMon1ID
+	ld bc, PartyMon2 - PartyMon1
+	ld a, [CurPartyMon]
+	call AddNTimes
+	ld de, PlayerID
+	ld c, $2
+.asm_fb7b1
+	ld a, [de]
+	cp [hl]
+	jr nz, .asm_fb7bc
+	inc hl
+	inc de
+	dec c
+	jr nz, .asm_fb7b1
+	and a
+	ret
+
+.asm_fb7bc
+	scf
+	ret
+; fb7be
+
+Functionfb7be: ; fb7be
+	ld hl, StringBuffer2
+	ld c, 10
+.asm_fb7c3
+	ld a, [hli]
+	cp "@"
+	jr z, .asm_fb7cf
+	cp " "
+	jr nz, .asm_fb7d1
+	dec c
+	jr nz, .asm_fb7c3
+
+.asm_fb7cf
+	scf
+	ret
+
+.asm_fb7d1
+	and a
+	ret
+; fb7d3
+
+Functionfb7d3: ; fb7d3
+	ld hl, PartyMon1Nickname
+	ld bc, $000b
+	ld a, [CurPartyMon]
+	call AddNTimes
+	push hl
+	call Functionfb802
+	ld b, c
+	ld hl, StringBuffer2
+	call Functionfb802
+	pop hl
+	ld a, c
+	cp b
+	jr nz, .asm_fb7fe
+	ld de, StringBuffer2
+.asm_fb7f2
+	ld a, [de]
+	cp "@"
+	jr z, .asm_fb800
+	cp [hl]
+	jr nz, .asm_fb7fe
+	inc hl
+	inc de
+	jr .asm_fb7f2
+
+.asm_fb7fe
+	and a
+	ret
+
+.asm_fb800
+	scf
+	ret
+; fb802
+
+Functionfb802: ; fb802
+	ld c, 0
+.asm_fb804
+	ld a, [hli]
+	cp "@"
+	ret z
+	inc c
+	ld a, c
+	cp 10
+	jr nz, .asm_fb804
+	ret
+; fb80f
+
+UnknownText_0xfb80f: ; 0xfb80f
+	; Hello, hello! I'm the NAME RATER.
+	; I rate the names of #MON.
+	; Would you like me to rate names?
+	text_jump UnknownText_0x1c0043, BANK(UnknownText_0x1c0043)
+	db "@"
+; 0xfb814
+
+UnknownText_0xfb814: ; 0xfb814
+	; Which #MON's nickname should I rate for you?
+	text_jump UnknownText_0x1c00a0, BANK(UnknownText_0x1c00a0)
+	db "@"
+; 0xfb819
+
+UnknownText_0xfb819: ; 0xfb819
+	; Hm… @ … That's a fairly decent name.
+	; But, how about a slightly better nickname?
+	; Want me to give it a better name?
+	text_jump UnknownText_0x1c00cd, BANK(UnknownText_0x1c00cd)
+	db "@"
+; 0xfb81e
+
+UnknownText_0xfb81e: ; 0xfb81e
+	; All right. What name should we give it, then?
+	text_jump UnknownText_0x1c0142, BANK(UnknownText_0x1c0142)
+	db "@"
+; 0xfb823
+
+UnknownText_0xfb823: ; 0xfb823
+	; That's a better name than before! Well done!
+	text_jump UnknownText_0x1c0171, BANK(UnknownText_0x1c0171)
+	db "@"
+; 0xfb828
+
+UnknownText_0xfb828: ; 0xfb828
+	; OK, then. Come again sometime.
+	text_jump UnknownText_0x1c019e, BANK(UnknownText_0x1c019e)
+	db "@"
+; 0xfb82d
+
+UnknownText_0xfb82d: ; 0xfb82d
+	; Hm… @ ? What a great name! It's perfect.
+	; Treat @ with loving care.
+	text_jump UnknownText_0x1c01be, BANK(UnknownText_0x1c01be)
+	db "@"
+; 0xfb832
+
+UnknownText_0xfb832: ; 0xfb832
+	; Whoa… That's just an EGG.
+	text_jump UnknownText_0x1c0208, BANK(UnknownText_0x1c0208)
+	db "@"
+; 0xfb837
+
+UnknownText_0xfb837: ; 0xfb837
+	; It might look the same as before,
+	; but this new name is much better! Well done!
+	text_jump UnknownText_0x1c0222, BANK(UnknownText_0x1c0222)
+	db "@"
+; 0xfb83c
+
+UnknownText_0xfb83c: ; 0xfb83c
+	; All right. This #MON is now named @ .
+	text_jump UnknownText_0x1c0272, BANK(UnknownText_0x1c0272)
+	db "@"
+; 0xfb841
+
--- a/main.asm
+++ b/main.asm
@@ -474,15 +474,14 @@
 
 
 INCLUDE "common/menu.asm"
-
 INCLUDE "common/handshake.asm"
-
 INCLUDE "common/game_time.asm"
-
 INCLUDE "common/map.asm"
 
 
 Function2d43: ; 2d43
+; Inexplicably empty.
+; Seen in PredefPointers.
 	nop
 	nop
 	nop
@@ -504,7 +503,6 @@
 
 
 INCLUDE "common/farcall.asm"
-
 INCLUDE "common/predef.asm"
 
 
@@ -624,7 +622,7 @@
 	bit 1, a
 	ret z
 	ld a, [hJoyDown]
-	bit 1, a
+	bit A_BUTTON, a
 	ret
 ; 2ec6
 
@@ -640,7 +638,6 @@
 	ret
 ; 2ecb
 
-
 Function2ecb: ; 2ecb
 	push hl
 	ld hl, $c2cc
@@ -718,9 +715,7 @@
 
 
 INCLUDE "common/item.asm"
-
 INCLUDE "common/random.asm"
-
 INCLUDE "common/sram.asm"
 
 
@@ -764,140 +759,10 @@
 	ret
 ; 3026
 
-CopyBytes: ; 0x3026
-; copy bc bytes from hl to de
-	inc b  ; we bail the moment b hits 0, so include the last run
-	inc c  ; same thing; include last byte
-	jr .HandleLoop
-.CopyByte
-	ld a, [hli]
-	ld [de], a
-	inc de
-.HandleLoop
-	dec c
-	jr nz, .CopyByte
-	dec b
-	jr nz, .CopyByte
-	ret
 
-SwapBytes: ; 0x3034
-; swap bc bytes between hl and de
-.Loop
-	; stash [hl] away on the stack
-	ld a, [hl]
-	push af
+INCLUDE "common/copy2.asm"
 
-	; copy a byte from [de] to [hl]
-	ld a, [de]
-	ld [hli], a
 
-	; retrieve the previous value of [hl]; put it in [de]
-	pop af
-	ld [de], a
-
-	; handle loop stuff
-	inc de
-	dec bc
-	ld a, b
-	or c
-	jr nz, .Loop
-	ret
-
-ByteFill: ; 0x3041
-; fill bc bytes with the value of a, starting at hl
-	inc b  ; we bail the moment b hits 0, so include the last run
-	inc c  ; same thing; include last byte
-	jr .HandleLoop
-.PutByte
-	ld [hli], a
-.HandleLoop
-	dec c
-	jr nz, .PutByte
-	dec b
-	jr nz, .PutByte
-	ret
-
-GetFarByte: ; 0x304d
-; retrieve a single byte from a:hl, and return it in a.
-	; bankswitch to new bank
-	ld [hBuffer], a
-	ld a, [hROMBank]
-	push af
-	ld a, [hBuffer]
-	rst Bankswitch
-
-	; get byte from new bank
-	ld a, [hl]
-	ld [hBuffer], a
-
-	; bankswitch to previous bank
-	pop af
-	rst Bankswitch
-
-	; return retrieved value in a
-	ld a, [hBuffer]
-	ret
-
-GetFarHalfword: ; 0x305d
-; retrieve a halfword from a:hl, and return it in hl.
-	; bankswitch to new bank
-	ld [hBuffer], a
-	ld a, [hROMBank]
-	push af
-	ld a, [hBuffer]
-	rst Bankswitch
-
-	; get halfword from new bank, put it in hl
-	ld a, [hli]
-	ld h, [hl]
-	ld l, a
-
-	; bankswitch to previous bank and return
-	pop af
-	rst Bankswitch
-	ret
-; 0x306b
-
-Function306b: ; 306b
-	ld [hBuffer], a
-	ld a, [rSVBK]
-	push af
-	ld a, [hBuffer]
-	ld [rSVBK], a
-	call CopyBytes
-	pop af
-	ld [rSVBK], a
-	ret
-; 307b
-
-Function307b: ; 307b
-	ld [hBuffer], a
-	ld a, [rSVBK]
-	push af
-	ld a, [hBuffer]
-	ld [rSVBK], a
-	ld a, [hl]
-	ld [hBuffer], a
-	pop af
-	ld [rSVBK], a
-	ld a, [hBuffer]
-	ret
-; 308d
-
-Function308d: ; 308d
-	ld [hBuffer], a
-	ld a, [rSVBK]
-	push af
-	ld a, [hBuffer]
-	ld [rSVBK], a
-	ld a, [hli]
-	ld h, [hl]
-	ld l, a
-	pop af
-	ld [rSVBK], a
-	ret
-; 309d
-
 Function309d: ; 309d
 	ld a, [rSVBK]
 	push af
@@ -996,83 +861,9 @@
 ; 0x3105
 
 
-SimpleMultiply: ; 3105
-; Return a * c.
-	and a
-	ret z
+INCLUDE "common/math.asm"
 
-	push bc
-	ld b, a
-	xor a
-.loop
-	add c
-	dec b
-	jr nz, .loop
-	pop bc
-	ret
-; 3110
 
-
-SimpleDivide: ; 3110
-; Divide a by c. Return quotient b and remainder a.
-	ld b, 0
-.loop
-	inc b
-	sub c
-	jr nc, .loop
-	dec b
-	add c
-	ret
-; 3119
-
-
-Multiply: ; 3119
-; Multiply hMultiplicand (3 bytes) by hMultiplier. Result in hProduct.
-; All values are big endian.
-	push hl
-	push bc
-
-	callab _Multiply
-
-	pop bc
-	pop hl
-	ret
-; 3124
-
-
-Divide: ; 3124
-; Divide hDividend length b (max 4 bytes) by hDivisor. Result in hQuotient.
-; All values are big endian.
-	push hl
-	push de
-	push bc
-	ld a, [hROMBank]
-	push af
-	ld a, BANK(_Divide)
-	rst Bankswitch
-
-	call _Divide
-
-	pop af
-	rst Bankswitch
-	pop bc
-	pop de
-	pop hl
-	ret
-; 3136
-
-
-SubtractSigned: ; 3136
-; Return a - b, sign in carry.
-	sub b
-	ret nc
-	cpl
-	add 1
-	scf
-	ret
-; 313d
-
-
 PrintLetterDelay: ; 313d
 ; wait some frames before printing the next letter
 ; the text speed setting in Options is actually a frame count
@@ -1159,6 +950,7 @@
 	ret
 ; 318c
 
+
 CopyDataUntil: ; 318c
 ; Copies [hl, bc) to [de, bc - hl).
 ; In other words, the source data is from hl up to but not including bc,
@@ -1175,12 +967,15 @@
 	ret
 ; 0x3198
 
+
 PrintNum: ; 3198
 	ld a, [hROMBank]
 	push af
 	ld a, BANK(_PrintNum)
 	rst Bankswitch
+
 	call _PrintNum
+
 	pop af
 	rst Bankswitch
 	ret
@@ -1190,18 +985,18 @@
 Function31a4: ; 31a4
 	ld a, [hROMBank]
 	push af
-	ld a, $41
+	ld a, BANK(Function1061ef)
 	rst Bankswitch
 
-	call $61ef
+	call Function1061ef
+
 	pop af
 	rst Bankswitch
-
 	ret
 ; 31b0
 
 
-Function31b0: ; 31b0
+FarPrintText: ; 31b0
 	ld [hBuffer], a
 	ld a, [hROMBank]
 	push af
@@ -1209,13 +1004,14 @@
 	rst Bankswitch
 
 	call PrintText
+
 	pop af
 	rst Bankswitch
-
 	ret
 ; 31be
 
-Function31be: ; 31be
+
+CallPointerAt: ; 31be
 	ld a, [hROMBank]
 	push af
 	ld a, [hli]
@@ -1233,10 +1029,13 @@
 	ret
 ; 31cd
 
+
 Function31cd: ; 31cd
+; Push pointer hl in the current bank to $d0e8.
 	ld a, [hROMBank]
 
 Function31cf: ; 31cf
+; Push pointer a:hl to $d0e8.
 	ld [$d0e8], a
 	ld a, l
 	ld [$d0e9], a
@@ -1300,15 +1099,15 @@
 	ld a, [hCGB]
 	and a
 	jr z, .asm_320e
-	ld a, $2
+	ld a, 2
 	ld [hBGMapMode], a
-	ld c, $4
+	ld c, 4
 	call DelayFrames
 
 .asm_320e
-	ld a, $1
+	ld a, 1
 	ld [hBGMapMode], a
-	ld c, $4
+	ld c, 4
 	call DelayFrames
 	ret
 ; 0x3218
@@ -1325,9 +1124,11 @@
 	ld a, [hCGB]
 	and a
 	jr z, .asm_322e
+
 	ld a, [$c2ce]
 	cp 0
 	jr z, .asm_322e
+
 	ld a, 1
 	ld [hBGMapMode], a
 	jr Function323d
@@ -1476,20 +1277,21 @@
 	ret
 	
 .cgb
-; Save WRAM bank
 	ld a, [rSVBK]
 	push af
-; WRAM bank 5
+
 	ld a, 5
 	ld [rSVBK], a
+
 ; Fill BGPals and OBPals with $ffff (white)
 	ld hl, BGPals
-	ld bc, $0080
+	ld bc, $80
 	ld a, $ff
 	call ByteFill
-; Restore WRAM bank
+
 	pop af
 	ld [rSVBK], a
+
 ; Request palette update
 	ld a, 1
 	ld [hCGBPalUpdate], a
@@ -1496,6 +1298,7 @@
 	ret
 ; 333e
 
+
 ClearSGB: ; 333e
 	ld b, $ff
 GetSGBLayout: ; 3340
@@ -1569,9 +1372,9 @@
 
 GetWeekday: ; 3376
 	ld a, [CurDay]
-.loop
+.mod
 	sub 7
-	jr nc, .loop
+	jr nc, .mod
 	add 7
 	ret
 ; 3380
@@ -1580,39 +1383,38 @@
 SetSeenAndCaughtMon: ; 3380
 	push af
 	ld c, a
-	ld hl, PokedexSeen
-	ld b, 1
-	call GetWramFlag
+	ld hl, PokedexCaught
+	ld b, SET_FLAG
+	call PokedexFlagAction
 	pop af
 	; fallthrough
 ; 338b
 
-SetCaughtMon: ; 338b
+SetSeenMon: ; 338b
 	ld c, a
-	ld hl, PokedexCaught
-	ld b, 1
-	jr GetWramFlag
+	ld hl, PokedexSeen
+	ld b, SET_FLAG
+	jr PokedexFlagAction
 ; 3393
 
-CheckSeenMon: ; 3393
+CheckCaughtMon: ; 3393
 	ld c, a
-	ld hl, PokedexSeen
-	ld b, 2
-	jr GetWramFlag
+	ld hl, PokedexCaught
+	ld b, CHECK_FLAG
+	jr PokedexFlagAction
 ; 339b
 
-CheckCaughtMon: ; 339b
+CheckSeenMon: ; 339b
 	ld c, a
-	ld hl, PokedexCaught
-	ld b, 2
+	ld hl, PokedexSeen
+	ld b, CHECK_FLAG
 	; fallthrough
 ; 33a1
 
-GetWramFlag: ; 33a1
+PokedexFlagAction: ; 33a1
 	ld d, 0
 	ld a, PREDEF_FLAG
 	call Predef
-
 	ld a, c
 	and a
 	ret
@@ -2386,7 +2188,7 @@
 	ld h, [hl]
 	ld l, a
 	call GetMapEventBank
-	call Function31b0
+	call FarPrintText
 	call WaitBGMap
 	call Functiona80
 	ret
@@ -8809,7 +8611,7 @@
 	bit 0, a
 	ret z
 	push hl
-	ld hl, PokedexSeen
+	ld hl, PokedexCaught
 	ld b, $20
 	call CountSetBits
 	pop hl
@@ -12186,7 +11988,7 @@
 	dwb Function6508, BANK(Function6508)
 	dwb Function747a, BANK(Function747a)
 	dwb Functionc658, BANK(Functionc658)
-	dwb Function4d7c1, BANK(Function4d7c1)
+	dwb FlagPredef, BANK(FlagPredef)
 	dwb Functionc699, BANK(Functionc699)
 	dwb FillPP, BANK(FillPP)
 	dwb Functiond88c, BANK(Functiond88c)
@@ -12261,41 +12063,9 @@
 ; 864c
 
 
-Function864c: ; 864c
-; LoadSGBLayout
-	call Function8d55
-	jp nz, Function8d59
-	ld a, b
-	cp $ff
-	jr nz, .asm_865a
-	ld a, [SGBPredef]
+INCLUDE "predef/sgb.asm"
 
-.asm_865a
-	cp $fc
-	jp z, Function8ade
-	ld l, a
-	ld h, 0
-	add hl, hl
-	ld de, $466f
-	add hl, de
-	ld a, [hli]
-	ld h, [hl]
-	ld l, a
-	ld de, Function8a60
-	push de
-	jp [hl]
-; 866f
 
-INCBIN "baserom.gbc", $866f, $8a60 - $866f
-
-Function8a60: ; 8a60
-	push de
-	call Function9809
-	pop hl
-	jp Function9809
-; 8a68
-
-
 CheckShininess: ; 8a68
 ; Check if a mon is shiny by DVs at bc.
 ; Return carry if shiny.
@@ -12338,7 +12108,7 @@
 
 CheckContestMon: ; 8a88
 ; Check a mon's DVs at hl in the bug catching contest.
-; Return shiny if its DVs are good enough to place in the contest.
+; Return carry if its DVs are good enough to place in the contest.
 
 ; Attack
 	ld a, [hl]
@@ -12434,18 +12204,18 @@
 ; 8b07
 
 Function8b07: ; 8b07
-	call Function8d55
+	call CheckCGB
 	ret z
 	ld hl, $4b2f
 	ld de, $d000
 	ld bc, $0008
 	ld a, $5
-	call Function306b
+	call FarCopyWRAM
 	ld hl, $4b37
 	ld de, MartPointer
 	ld bc, $0008
 	ld a, $5
-	call Function306b
+	call FarCopyWRAM
 	call Function96a4
 	ld a, $1
 	ld [hCGBPalUpdate], a
@@ -12480,7 +12250,7 @@
 	add hl, bc
 	ld bc, $0004
 	ld a, $5
-	call Function306b
+	call FarCopyWRAM
 	ld a, $1
 	ld [hCGBPalUpdate], a
 	ret
@@ -12515,7 +12285,7 @@
 	add hl, hl
 	ld de, $4d05
 	add hl, de
-	call Function8d55
+	call CheckCGB
 	jr nz, .asm_8cf0
 	push hl
 	ld hl, $5ce6
@@ -12543,7 +12313,7 @@
 	ld de, $d000
 	ld bc, $0008
 	ld a, $5
-	call Function306b
+	call FarCopyWRAM
 	call Function96a4
 	call Function9699
 	call Function96b3
@@ -12553,233 +12323,12 @@
 INCBIN "baserom.gbc", $8d05, $8d55 - $8d05
 
 
-Function8d55: ; 8d55
-	ld a, [hCGB]
-	and a
-	ret
-; 8d59
+INCLUDE "predef/cgb.asm"
 
-Function8d59: ; 8d59
-	ld a, b
-	cp $ff
-	jr nz, .asm_8d61
-	ld a, [SGBPredef]
 
-.asm_8d61
-	cp $fc
-	jp z, Function96f3
-	call Function9673
-	ld l, a
-	ld h, $0
-	add hl, hl
-	ld de, $4d7a
-	add hl, de
-	ld a, [hli]
-	ld h, [hl]
-	ld l, a
-	ld de, Function8d79
-	push de
-	jp [hl]
-; 8d79
+INCBIN "baserom.gbc", $95e0, $9610 - $95e0
 
-Function8d79: ; 8d79
-	ret
-; 8d7a
 
-INCBIN "baserom.gbc", $8d7a, $8db8 - $8d7a
-
-Function8db8: ; 8db8
-	ld hl, $5c67
-	ld de, $d000
-	ld c, $4
-	call $5615
-	ld hl, $5c67
-	ld de, $d020
-	ld c, $4
-	call $5615
-	ld hl, $5c67
-	ld de, MartPointer
-	ld c, $2
-	call $5615
-	jr .asm_8e23
-
-	ld de, $d000
-	call Function9729
-	push hl
-	call Function9643
-	call Function973a
-	push hl
-	call Function9643
-	ld a, [EnemyHPPal]
-	ld l, a
-	ld h, $0
-	add hl, hl
-	add hl, hl
-	ld bc, $68be
-	add hl, bc
-	call Function9643
-	ld a, [PlayerHPPal]
-	ld l, a
-	ld h, $0
-	add hl, hl
-	add hl, hl
-	ld bc, $68be
-	add hl, bc
-	call Function9643
-	ld hl, $68ca
-	call Function9643
-	ld de, MartPointer
-	pop hl
-	call Function9643
-	pop hl
-	call Function9643
-	ld a, $1
-	ld [SGBPredef], a
-	call Function96a4
-
-.asm_8e23
-	call Function8e85
-	ld hl, AttrMap
-	ld bc, $0168
-	ld a, $2
-	call ByteFill
-	ld hl, $ce29
-	ld bc, $080a
-	ld a, $0
-	call Function9663
-	ld hl, $cde3
-	ld bc, $070a
-	ld a, $1
-	call Function9663
-	ld hl, AttrMap
-	ld bc, $040a
-	ld a, $2
-	call Function9663
-	ld hl, $ce6f
-	ld bc, $050a
-	ld a, $3
-	call Function9663
-	ld hl, $cebf
-	ld bc, $0109
-	ld a, $4
-	call Function9663
-	ld hl, $cec9
-	ld bc, $0078
-	ld a, $7
-	call ByteFill
-	ld hl, $579c
-	ld de, $d050
-	ld bc, $0030
-	ld a, $5
-	call Function306b
-	call Function96b3
-	ret
-; 8e85
-
-
-Function8e85: ; 8e85
-	ld a, $40
-	ld hl, $4dc0
-	rst FarCall
-	ld hl, $7311
-	jr nc, .asm_8e93
-	ld hl, $7309
-
-.asm_8e93
-	ld de, $d038
-	ld bc, $0008
-	ld a, $5
-	call Function306b
-	ret
-; 8e9f
-
-Function8e9f: ; 8e9f
-	callba Function100dc0
-	ld hl, $7311
-	jr nc, .asm_8ead
-	ld hl, $7309
-
-.asm_8ead
-	ld de, $d000
-	ld bc, $0008
-	ld a, $5
-	call Function306b
-	ret
-; 8eb9
-
-Function8eb9: ; 8eb9
-	ld a, [PlayerGender]
-	bit 0, a
-	jr z, .asm_8ec5
-	ld hl, $7759
-	jr .asm_8ec8
-
-.asm_8ec5
-	ld hl, $7729
-
-.asm_8ec8
-	ld de, $d000
-	ld bc, $0030
-	ld a, $5
-	call Function306b
-	call Function96a4
-	ld a, $1
-	ld [hCGBPalUpdate], a
-	ret
-; 8edb
-
-Function8edb: ; 8edb
-	ld de, $d000
-	ld a, [$cda1]
-	ld l, a
-	ld h, $0
-	add hl, hl
-	add hl, hl
-	ld bc, $68be
-	add hl, bc
-	call Function9643
-	ld a, [CurPartySpecies]
-	ld bc, TempMonDVs
-	call Function974b
-	call Function9643
-	ld hl, $68ca
-	call Function9643
-	ld hl, $4f52
-	ld de, $d018
-	ld bc, $0018
-	ld a, $5
-	call Function306b
-	call Function9699
-	ld hl, AttrMap
-	ld bc, $0814
-	ld a, $1
-	call Function9663
-	ld hl, $cf23
-	ld bc, $000a
-	ld a, $2
-	call ByteFill
-	ld hl, $ce4a
-	ld bc, $0202
-	ld a, $3
-	call Function9663
-	ld hl, $ce4c
-	ld bc, $0202
-	ld a, $4
-	call Function9663
-	ld hl, $ce4e
-	ld bc, $0202
-	ld a, $5
-	call Function9663
-	call Function96b3
-	call Function96a4
-	ld a, $1
-	ld [hCGBPalUpdate], a
-	ret
-; 8f52
-
-INCBIN "baserom.gbc", $8f52, $9610 - $8f52
-
-
 Function9610: ; 9610
 	ld de, $d000
 	ld c, $4
@@ -12917,7 +12466,7 @@
 	ld de, $d080
 	ld bc, $0080
 	ld a, $5
-	call Function306b
+	call FarCopyWRAM
 	ret
 ; 96b3
 
@@ -12999,7 +12548,7 @@
 	ld de, MartPointer
 	ld bc, $0010
 	ld a, $5
-	call Function306b
+	call FarCopyWRAM
 	ret
 ; 9729
 
@@ -13046,6 +12595,8 @@
 	and a
 	jp nz, Function97f9
 	ld a, [TrainerClass]
+
+Function976b: ; 976b
 	ld l, a
 	ld h, $0
 	add hl, hl
@@ -13055,8 +12606,13 @@
 	ret
 ; 9775
 
-INCBIN "baserom.gbc", $9775, $97ee - $9775
+Function9775: ; 9775
+	call Function97ee
+	ret
+; 9779
 
+INCBIN "baserom.gbc", $9779, $97ee - $9779
+
 Function97ee: ; 97ee
 	ld l, a
 	ld h, $0
@@ -13137,7 +12693,7 @@
 ; 9853
 
 Function9853: ; 9853
-	call Function8d55
+	call CheckCGB
 	ret nz
 	di
 	ld a, [$cfbe]
@@ -13170,7 +12726,7 @@
 
 
 Function9890: ; 9890
-	call Function8d55
+	call CheckCGB
 	ret z
 	ld a, $1
 	ld [rVBK], a
@@ -13473,8 +13029,107 @@
 TrainerPalettes:
 INCLUDE "gfx/trainers/palette_pointers.asm"
 
-INCBIN "baserom.gbc", $b1de, $b319 - $b1de
+Functionb1de: ; b1de
+	callba Function494ac
+	jr c, .asm_b230
+	ld a, [$d19a]
+	and $7
+	ld e, a
+	ld d, $0
+	ld hl, $7279
+	add hl, de
+	add hl, de
+	ld a, [hli]
+	ld h, [hl]
+	ld l, a
+	ld a, [TimeOfDayPal]
+	and $3
+	add a
+	add a
+	add a
+	ld e, a
+	ld d, $0
+	add hl, de
+	ld e, l
+	ld d, h
+	ld a, [rSVBK]
+	push af
+	ld a, $5
+	ld [rSVBK], a
+	ld hl, Unkn1Pals
+	ld b, $8
+.asm_b210
+	ld a, [de]
+	push de
+	push hl
+	ld l, a
+	ld h, $0
+	add hl, hl
+	add hl, hl
+	add hl, hl
+	ld de, MornPal
+	add hl, de
+	ld e, l
+	ld d, h
+	pop hl
+	ld c, $8
+.asm_b222
+	ld a, [de]
+	inc de
+	ld [hli], a
+	dec c
+	jr nz, .asm_b222
+	pop de
+	inc de
+	dec b
+	jr nz, .asm_b210
+	pop af
+	ld [rSVBK], a
 
+.asm_b230
+	ld a, [TimeOfDayPal]
+	and $3
+	ld bc, $0040
+	ld hl, $7469
+	call AddNTimes
+	ld de, Unkn2Pals
+	ld bc, $0040
+	ld a, $5
+	call FarCopyWRAM
+	ld a, [$d19a]
+	cp $1
+	jr z, .asm_b253
+	cp $2
+	ret nz
+
+.asm_b253
+	ld a, [MapGroup]
+	ld l, a
+	ld h, $0
+	add hl, hl
+	add hl, hl
+	add hl, hl
+	ld de, $7569
+	add hl, de
+	ld a, [TimeOfDayPal]
+	and $3
+	cp $2
+	jr c, .asm_b26d
+	inc hl
+	inc hl
+	inc hl
+	inc hl
+
+.asm_b26d
+	ld de, $d032
+	ld bc, $0004
+	ld a, $5
+	call FarCopyWRAM
+	ret
+; b279
+
+INCBIN "baserom.gbc", $b279, $b319 - $b279
+
 MornPal: ; 0xb319
 INCBIN "tilesets/morn.pal"
 ; 0xb359
@@ -13587,7 +13242,7 @@
 	dbw BANK(Function1ad2), Function1ad2
 	dbw BANK(Functione4a), Functione4a
 	dbw BANK(Functionc230), Functionc230
-	dbw BANK(Functionc252), Functionc252
+	dbw BANK(SpecialSeenMon), SpecialSeenMon
 	dbw BANK(WaitSFX),WaitSFX
 	dbw BANK(Function3cdf), Function3cdf
 	dbw BANK(Function3d47), Function3d47
@@ -13616,7 +13271,7 @@
 	dbw BANK(Functionc422), Functionc422
 	dbw BANK(Function4d9d3), Function4d9d3
 	dbw BANK(Function88018), Function88018
-	dbw BANK(Functionc2b9), Functionc2b9
+	dbw BANK(SpecialNameRater), SpecialNameRater
 	dbw BANK(Functionc2da), Functionc2da
 	dbw BANK(Function718d), Function718d
 	dbw BANK(Function71ac), Function71ac
@@ -13697,10 +13352,10 @@
 	dbw BANK(Function4a927), Function4a927
 	dbw BANK(Function90a54), Function90a54
 	dbw BANK(Function90a88), Function90a88
-	dbw BANK(Functionc224), Functionc224
+	dbw BANK(SpecialNone), SpecialNone
 ; c224
 
-Functionc224: ; c224
+SpecialNone: ; c224
 	ret
 ; c225
 
@@ -13714,7 +13369,7 @@
 Functionc230: ; c230
 	ld a, [ScriptVar]
 	dec a
-	call CheckSeenMon
+	call CheckCaughtMon
 	ret nz
 	ld a, [ScriptVar]
 	dec a
@@ -13727,10 +13382,10 @@
 	ret
 ; c252
 
-Functionc252: ; c252
+SpecialSeenMon: ; c252
 	ld a, [ScriptVar]
 	dec a
-	call SetCaughtMon
+	call SetSeenMon
 	ret
 ; c25a
 
@@ -13787,8 +13442,8 @@
 DefaultRivalName: ; 0xc2b2
 	db "SILVER@"
 
-Functionc2b9: ; c2b9
-	callba Functionfb6ed
+SpecialNameRater: ; c2b9
+	callba NameRater
 	ret
 ; c2c0
 
@@ -17215,7 +16870,7 @@
 	ld [$d265], a
 	dec a
 	push de
-	call CheckSeenMon
+	call CheckCaughtMon
 	ld a, [$d265]
 	dec a
 	call SetSeenAndCaughtMon
@@ -18121,10 +17776,10 @@
 	ld a, [CurPartySpecies]
 	dec a
 	push af
-	call CheckSeenMon
+	call CheckCaughtMon
 	pop af
 	push bc
-	call CheckCaughtMon
+	call CheckSeenMon
 	push bc
 	call Functiond88c
 	pop bc
@@ -18135,7 +17790,7 @@
 	dec a
 	ld c, a
 	ld d, $0
-	ld hl, PokedexSeen
+	ld hl, PokedexCaught
 	ld b, $0
 	ld a, $3
 	call Predef
@@ -18149,7 +17804,7 @@
 	dec a
 	ld c, a
 	ld d, $0
-	ld hl, PokedexCaught
+	ld hl, PokedexSeen
 	ld b, $0
 	ld a, $3
 	call Predef
@@ -20807,7 +20462,7 @@
 	ld de, CurMart
 	ld bc, $0008
 	ld a, $5
-	call Function306b
+	call FarCopyWRAM
 	ld a, $1
 	ld [hCGBPalUpdate], a
 	ret
@@ -30665,7 +30320,7 @@
 	ld d, h
 	ld e, l
 	ld hl, $cf98
-	jp Function31be
+	jp CallPointerAt
 ; 2486e
 
 Function2486e: ; 2486e
@@ -30673,7 +30328,7 @@
 	ld d, h
 	ld e, l
 	ld hl, $cf98
-	call Function31be
+	call CallPointerAt
 	pop hl
 	ld a, [$cf93]
 	and a
@@ -30684,7 +30339,7 @@
 	ld d, h
 	ld e, l
 	ld hl, $cf9b
-	call Function31be
+	call CallPointerAt
 
 .asm_2488a
 	ret
@@ -30737,7 +30392,7 @@
 	dec a
 	call Function248d5
 	ld hl, $cf9e
-	call Function31be
+	call CallPointerAt
 	ret
 ; 248d5
 
@@ -31774,13 +31429,13 @@
 
 Rate: ; 0x26616
 ; calculate Seen/Owned
-	ld hl, PokedexCaught
-	ld b, EndPokedexCaught - PokedexCaught
-	call CountSetBits
-	ld [DefaultFlypoint], a
 	ld hl, PokedexSeen
 	ld b, EndPokedexSeen - PokedexSeen
 	call CountSetBits
+	ld [DefaultFlypoint], a
+	ld hl, PokedexCaught
+	ld b, EndPokedexCaught - PokedexCaught
+	call CountSetBits
 	ld [$d003], a
 
 ; print appropriate rating
@@ -36179,7 +35834,7 @@
 	push bc
 	dec c
 	ld a, c
-	call CheckCaughtMon
+	call CheckSeenMon
 	pop bc
 	jr nz, .asm_2a514
 	ld de, StringBuffer1
@@ -36671,7 +36326,7 @@
 	ret nz
 	ld a, [TempEnemyMonSpecies]
 	dec a
-	call CheckSeenMon
+	call CheckCaughtMon
 	ret z
 	ld hl, $c4b5
 	ld [hl], $5d
@@ -44891,7 +44546,7 @@
 	dec a
 	ld c, a
 	ld b, 1 ; set
-	ld hl, PokedexCaught
+	ld hl, PokedexSeen
 	ld a, PREDEF_FLAG
 	call Predef
 
@@ -48183,7 +47838,7 @@
 	push hl
 	ld a, [$d265]
 	dec a
-	call CheckCaughtMon
+	call CheckSeenMon
 	pop hl
 	pop de
 	ret
@@ -49395,7 +49050,7 @@
 	call PrintNum
 	ld a, [$d265]
 	dec a
-	call CheckSeenMon
+	call CheckCaughtMon
 	pop hl
 	pop bc
 	ret z
@@ -50164,7 +49819,7 @@
 	pop de
 	ld a, $b
 	ld hl, $48ce
-	call Function31b0
+	call FarPrintText
 	jr .asm_49300
 
 .asm_492e5
@@ -50219,12 +49874,148 @@
 	ld de, $d038
 	ld bc, $0008
 	ld a, $5
-	call Function306b
+	call FarCopyWRAM
 	ret
 ; 49418
 
-INCBIN "baserom.gbc", $49418, $49797 - $49418
+INCBIN "baserom.gbc", $49418, $494ac - $49418
 
+Function494ac: ; 494ac
+	ld a, [$d199]
+	cp $15
+	jr z, .asm_494c9
+	cp $16
+	jr z, .asm_494ce
+	cp $1d
+	jr z, .asm_494d3
+	cp $5
+	jr z, .asm_494e1
+	cp $1b
+	jr z, .asm_494e6
+	cp $d
+	jr z, .asm_494eb
+	jr .asm_494f0
+
+.asm_494c9
+	call Function494f2
+	scf
+	ret
+
+.asm_494ce
+	call Function49541
+	scf
+	ret
+
+.asm_494d3
+	ld a, [$d19a]
+	and $7
+	cp $3
+	jr z, .asm_494f0
+	call Function49590
+	scf
+	ret
+
+.asm_494e1
+	call Function495df
+	scf
+	ret
+
+.asm_494e6
+	call Function4962e
+	scf
+	ret
+
+.asm_494eb
+	call Function496c5
+	scf
+	ret
+
+.asm_494f0
+	and a
+	ret
+; 494f2
+
+Function494f2: ; 494f2
+	ld a, $5
+	ld de, Unkn1Pals
+	ld hl, $5501
+	ld bc, $0040
+	call FarCopyWRAM
+	ret
+; 49501
+
+INCBIN "baserom.gbc", $49501, $49541 - $49501
+
+Function49541: ; 49541
+	ld a, $5
+	ld de, Unkn1Pals
+	ld hl, $5550
+	ld bc, $0040
+	call FarCopyWRAM
+	ret
+; 49550
+
+INCBIN "baserom.gbc", $49550, $49590 - $49550
+
+Function49590: ; 49590
+	ld a, $5
+	ld de, Unkn1Pals
+	ld hl, $559f
+	ld bc, $0040
+	call FarCopyWRAM
+	ret
+; 4959f
+
+INCBIN "baserom.gbc", $4959f, $495df - $4959f
+
+Function495df: ; 495df
+	ld a, $5
+	ld de, Unkn1Pals
+	ld hl, $55ee
+	ld bc, $0040
+	call FarCopyWRAM
+	ret
+; 495ee
+
+INCBIN "baserom.gbc", $495ee, $4962e - $495ee
+
+Function4962e: ; 4962e
+	ld a, $5
+	ld de, Unkn1Pals
+	ld hl, $563d
+	ld bc, $0040
+	call FarCopyWRAM
+	ret
+; 4963d
+
+INCBIN "baserom.gbc", $4963d, $496c5 - $4963d
+
+Function496c5: ; 496c5
+	ld a, $5
+	ld de, Unkn1Pals
+	ld hl, $567d
+	ld bc, $0040
+	call FarCopyWRAM
+	ld a, $5
+	ld de, $d020
+	ld hl, $56fe
+	ld bc, $0008
+	call FarCopyWRAM
+	ld a, $5
+	ld de, $d018
+	ld hl, $56ad
+	ld bc, $0008
+	call FarCopyWRAM
+	ld a, $5
+	ld de, $d030
+	ld hl, $56bd
+	ld bc, $0008
+	call FarCopyWRAM
+	ret
+; 496fe
+
+INCBIN "baserom.gbc", $496fe, $49797 - $496fe
+
 Function49797: ; 49797
 	ld hl, AttrMap
 	ld bc, $1002
@@ -50282,7 +50073,7 @@
 	ld de, $d010
 	ld bc, $0030
 	ld a, $5
-	call Function306b
+	call FarCopyWRAM
 	callba Function96a4
 	ret
 ; 49826
@@ -52833,57 +52624,73 @@
 Tilesets:
 INCLUDE "tilesets/tileset_headers.asm"
 
-Function4d7c1: ; 4d7c1
+
+FlagPredef: ; 4d7c1
+; Perform action b on flag c in flag array hl.
+; If checking a flag, check flag array d:hl unless d is 0.
+
+; For longer flag arrays, see FlagAction.
+
 	push hl
 	push bc
+
+; Divide by 8 to get the byte we want.
 	push bc
 	srl c
 	srl c
 	srl c
-	ld b, $0
+	ld b, 0
 	add hl, bc
 	pop bc
+
+; Which bit we want from the byte
 	ld a, c
-	and $7
+	and 7
 	ld c, a
-	ld a, $1
-	jr z, .asm_4d7da
-.asm_4d7d6
+
+; Shift left until we can mask the bit
+	ld a, 1
+	jr z, .shifted
+.shift
 	add a
 	dec c
-	jr nz, .asm_4d7d6
-
-.asm_4d7da
+	jr nz, .shift
+.shifted
 	ld c, a
+
+; What are we doing to this flag?
 	dec b
-	jr z, .asm_4d7e7
+	jr z, .set ; 1
 	dec b
-	jr z, .asm_4d7ec
+	jr z, .check ; 2
+
+.reset
 	ld a, c
 	cpl
 	and [hl]
 	ld [hl], a
-	jr .asm_4d7f9
+	jr .done
 
-.asm_4d7e7
+.set
 	ld a, [hl]
 	or c
 	ld [hl], a
-	jr .asm_4d7f9
+	jr .done
 
-.asm_4d7ec
+.check
 	ld a, d
-	cp $0
-	jr nz, .asm_4d7f5
+	cp 0
+	jr nz, .farcheck
+
 	ld a, [hl]
 	and c
-	jr .asm_4d7f9
+	jr .done
 
-.asm_4d7f5
+.farcheck
 	call GetFarByte
 	and c
 
-.asm_4d7f9
+.done
 	pop bc
 	pop hl
 	ld c, a
@@ -54331,7 +54138,7 @@
 	ld de, $cd53
 	ld bc, $000c
 	ld a, $5
-	call Function306b
+	call FarCopyWRAM
 	ld a, [rSVBK]
 	push af
 	ld a, $1
@@ -54353,7 +54160,7 @@
 Function4ea44: ; 4ea44
 	ld a, $0
 	ld hl, InLinkBattle
-	call Function307b
+	call GetFarWRAMByte
 	cp $4
 	jr z, .asm_4ea59
 	ld a, [Options]
@@ -54380,7 +54187,7 @@
 .asm_4ea72
 	ld a, $5
 	ld hl, $dc00
-	call Function307b
+	call GetFarWRAMByte
 	bit 0, a
 	jr z, .asm_4ea80
 	and a
@@ -57145,7 +56952,7 @@
 	push hl
 	ld a, $1
 	ld hl, BasePicSize
-	call Function307b
+	call GetFarWRAMByte
 	pop hl
 	and $f
 	ld de, $d990
@@ -71119,11 +70926,11 @@
 	ld [$d16e], a
 	ld a, $1
 	ld hl, CurPartySpecies
-	call Function307b
+	call GetFarWRAMByte
 	ld [$d16b], a
 	ld a, $1
 	ld hl, UnownLetter
-	call Function307b
+	call GetFarWRAMByte
 	ld [$d16c], a
 	call Functiond065c
 	ld [$d16d], a
@@ -74073,178 +73880,10 @@
 
 INCBIN "baserom.gbc", $fb656, $fb6ed - $fb656
 
-Functionfb6ed: ; fb6ed
-	ld hl, $780f
-	call PrintText
-	call Function1dcf
-	jp c, .asm_fb77e
-	ld hl, $7814
-	call PrintText
-	callba Function50000
-	jr c, .asm_fb77e
-	ld a, [CurPartySpecies]
-	cp $fd
-	jr z, .asm_fb783
-	call GetCurNick
-	call Functionfb78a
-	jr c, .asm_fb779
-	ld hl, $7819
-	call PrintText
-	call Function1dcf
-	jr c, .asm_fb77e
-	ld hl, $781e
-	call PrintText
-	xor a
-	ld [MonType], a
-	ld a, [CurPartySpecies]
-	ld [$d265], a
-	ld [CurSpecies], a
-	call GetBaseData
-	ld b, $0
-	ld de, StringBuffer2
-	callba Function116b7
-	call Functionfb7be
-	ld hl, $7837
-	jr c, .asm_fb76c
-	call Functionfb7d3
-	ld hl, $7837
-	jr c, .asm_fb76c
-	ld hl, PartyMon1Nickname
-	ld bc, $000b
-	ld a, [CurPartyMon]
-	call AddNTimes
-	ld e, l
-	ld d, h
-	ld hl, StringBuffer2
-	ld bc, $000b
-	call CopyBytes
-	ld hl, $7823
 
-.asm_fb76c
-	push hl
-	call GetCurNick
-	ld hl, $783c
-	call PrintText
-	pop hl
-	jr .asm_fb786
+INCLUDE "event/name_rater.asm"
 
-.asm_fb779
-	ld hl, $782d
-	jr .asm_fb786
 
-.asm_fb77e
-	ld hl, $7828
-	jr .asm_fb786
-
-.asm_fb783
-	ld hl, $7832
-
-.asm_fb786
-	call PrintText
-	ret
-; fb78a
-
-Functionfb78a: ; fb78a
-	ld hl, PartyMon1OT
-	ld bc, $000b
-	ld a, [CurPartyMon]
-	call AddNTimes
-	ld de, PlayerName
-	ld c, $b
-	call .asm_fb7b1
-	jr c, .asm_fb7bc
-	ld hl, PartyMon1ID
-	ld bc, $0030
-	ld a, [CurPartyMon]
-	call AddNTimes
-	ld de, PlayerID
-	ld c, $2
-.asm_fb7b1
-	ld a, [de]
-	cp [hl]
-	jr nz, .asm_fb7bc
-	inc hl
-	inc de
-	dec c
-	jr nz, .asm_fb7b1
-	and a
-	ret
-
-.asm_fb7bc
-	scf
-	ret
-; fb7be
-
-Functionfb7be: ; fb7be
-	ld hl, StringBuffer2
-	ld c, $a
-.asm_fb7c3
-	ld a, [hli]
-	cp $50
-	jr z, .asm_fb7cf
-	cp $7f
-	jr nz, .asm_fb7d1
-	dec c
-	jr nz, .asm_fb7c3
-
-.asm_fb7cf
-	scf
-	ret
-
-.asm_fb7d1
-	and a
-	ret
-; fb7d3
-
-Functionfb7d3: ; fb7d3
-	ld hl, PartyMon1Nickname
-	ld bc, $000b
-	ld a, [CurPartyMon]
-	call AddNTimes
-	push hl
-	call Functionfb802
-	ld b, c
-	ld hl, StringBuffer2
-	call Functionfb802
-	pop hl
-	ld a, c
-	cp b
-	jr nz, .asm_fb7fe
-	ld de, StringBuffer2
-.asm_fb7f2
-	ld a, [de]
-	cp $50
-	jr z, .asm_fb800
-	cp [hl]
-	jr nz, .asm_fb7fe
-	inc hl
-	inc de
-	jr .asm_fb7f2
-
-.asm_fb7fe
-	and a
-	ret
-
-.asm_fb800
-	scf
-	ret
-; fb802
-
-Functionfb802: ; fb802
-	ld c, $0
-.asm_fb804
-	ld a, [hli]
-	cp $50
-	ret z
-	inc c
-	ld a, c
-	cp $a
-	jr nz, .asm_fb804
-	ret
-; fb80f
-
-INCBIN "baserom.gbc", $fb80f, $fb841 - $fb80f
-
 Functionfb841: ; fb841
 	ld a, [ScriptVar]
 	call Function37f3
@@ -76824,7 +76463,7 @@
 	ld de, $d000
 	ld bc, $0054
 	ld a, $3
-	call Function306b
+	call FarCopyWRAM
 	ret
 ; 1003ab
 
@@ -76836,7 +76475,7 @@
 	ld de, $d080
 	ld bc, $0054
 	ld a, $3
-	call Function306b
+	call FarCopyWRAM
 	ret
 ; 1003c9
 
@@ -76845,7 +76484,7 @@
 	ld de, $ccb4
 	ld bc, $0054
 	ld a, $3
-	call Function306b
+	call FarCopyWRAM
 	ret
 ; 1003d8
 
@@ -77489,7 +77128,7 @@
 Function1009a5: ; 1009a5
 	ld bc, $0168
 	ld a, $3
-	call Function306b
+	call FarCopyWRAM
 	ret
 ; 1009ae
 
@@ -78542,7 +78181,7 @@
 	ld de, EnemyMoveAnimation
 	ld bc, $0026
 	ld a, $5
-	call Function306b
+	call FarCopyWRAM
 	ld de, EnemyMoveEffect
 	ret
 ; 10219f
@@ -83464,7 +83103,7 @@
 	ld hl, rSVBK
 	ld e, $1
 	ld [hl], e
-	call CheckCaughtMon
+	call CheckSeenMon
 	ld hl, rSVBK
 	ld e, $5
 	ld [hl], e
--- /dev/null
+++ b/predef/cgb.asm
@@ -1,0 +1,922 @@
+; Replaces the functionality of sgb.asm to work with CGB hardware.
+
+CheckCGB: ; 8d55
+	ld a, [hCGB]
+	and a
+	ret
+; 8d59
+
+Function8d59: ; 8d59
+	ld a, b
+	cp $ff
+	jr nz, .asm_8d61
+	ld a, [SGBPredef]
+
+.asm_8d61
+	cp $fc
+	jp z, Function96f3
+	call Function9673
+	ld l, a
+	ld h, 0
+	add hl, hl
+	ld de, Table8d7a
+	add hl, de
+	ld a, [hli]
+	ld h, [hl]
+	ld l, a
+	ld de, Function8d79
+	push de
+	jp [hl]
+; 8d79
+
+Function8d79: ; 8d79
+	ret
+; 8d7a
+
+Table8d7a: ; 8d7a
+	dw Function8db8
+	dw Function8ddb
+	dw Function8eb9
+	dw Function8edb
+	dw Function8f70
+	dw Function906e
+	dw Function90f8
+	dw Function9122
+	dw Function91ad
+	dw Function91c8
+	dw Function91d1
+	dw Function91e4
+	dw Function9228
+	dw Function9251
+	dw Function9373
+	dw Function93a6
+	dw Function93ba
+	dw Function9195
+	dw Function9499
+	dw Function94d0
+	dw Function93d3
+	dw Function9289
+	dw Function903e
+	dw Function8fca
+	dw Function925e
+	dw Function94fa
+	dw Function9529
+	dw Function9555
+	dw Function9578
+	dw Function9591
+	dw Function9542
+; 8db8
+
+Function8db8: ; 8db8
+	ld hl, $5c67
+	ld de, $d000
+	ld c, $4
+	call $5615
+	ld hl, $5c67
+	ld de, $d020
+	ld c, $4
+	call $5615
+	ld hl, $5c67
+	ld de, MartPointer
+	ld c, $2
+	call $5615
+	jr Function8e23
+
+Function8ddb: ; 8ddb
+	ld de, $d000
+	call Function9729
+	push hl
+	call Function9643
+	call Function973a
+	push hl
+	call Function9643
+	ld a, [EnemyHPPal]
+	ld l, a
+	ld h, $0
+	add hl, hl
+	add hl, hl
+	ld bc, $68be
+	add hl, bc
+	call Function9643
+	ld a, [PlayerHPPal]
+	ld l, a
+	ld h, $0
+	add hl, hl
+	add hl, hl
+	ld bc, $68be
+	add hl, bc
+	call Function9643
+	ld hl, $68ca
+	call Function9643
+	ld de, MartPointer
+	pop hl
+	call Function9643
+	pop hl
+	call Function9643
+	ld a, $1
+	ld [SGBPredef], a
+	call Function96a4
+
+Function8e23: ; 8e23
+	call Function8e85
+	ld hl, AttrMap
+	ld bc, $0168
+	ld a, $2
+	call ByteFill
+	ld hl, $ce29
+	ld bc, $080a
+	ld a, $0
+	call Function9663
+	ld hl, $cde3
+	ld bc, $070a
+	ld a, $1
+	call Function9663
+	ld hl, AttrMap
+	ld bc, $040a
+	ld a, $2
+	call Function9663
+	ld hl, $ce6f
+	ld bc, $050a
+	ld a, $3
+	call Function9663
+	ld hl, $cebf
+	ld bc, $0109
+	ld a, $4
+	call Function9663
+	ld hl, $cec9
+	ld bc, $0078
+	ld a, $7
+	call ByteFill
+	ld hl, $579c
+	ld de, $d050
+	ld bc, $0030
+	ld a, $5
+	call FarCopyWRAM
+	call Function96b3
+	ret
+; 8e85
+
+
+Function8e85: ; 8e85
+	ld a, $40
+	ld hl, $4dc0
+	rst FarCall
+	ld hl, $7311
+	jr nc, .asm_8e93
+	ld hl, $7309
+
+.asm_8e93
+	ld de, $d038
+	ld bc, $0008
+	ld a, $5
+	call FarCopyWRAM
+	ret
+; 8e9f
+
+Function8e9f: ; 8e9f
+	callba Function100dc0
+	ld hl, $7311
+	jr nc, .asm_8ead
+	ld hl, $7309
+
+.asm_8ead
+	ld de, $d000
+	ld bc, $0008
+	ld a, $5
+	call FarCopyWRAM
+	ret
+; 8eb9
+
+Function8eb9: ; 8eb9
+	ld a, [PlayerGender]
+	bit 0, a
+	jr z, .asm_8ec5
+	ld hl, $7759
+	jr .asm_8ec8
+
+.asm_8ec5
+	ld hl, $7729
+
+.asm_8ec8
+	ld de, $d000
+	ld bc, $0030
+	ld a, $5
+	call FarCopyWRAM
+	call Function96a4
+	ld a, $1
+	ld [hCGBPalUpdate], a
+	ret
+; 8edb
+
+Function8edb: ; 8edb
+	ld de, $d000
+	ld a, [$cda1]
+	ld l, a
+	ld h, $0
+	add hl, hl
+	add hl, hl
+	ld bc, $68be
+	add hl, bc
+	call Function9643
+	ld a, [CurPartySpecies]
+	ld bc, TempMonDVs
+	call Function974b
+	call Function9643
+	ld hl, $68ca
+	call Function9643
+	ld hl, $4f52
+	ld de, $d018
+	ld bc, $0018
+	ld a, $5
+	call FarCopyWRAM
+	call Function9699
+	ld hl, AttrMap
+	ld bc, $0814
+	ld a, $1
+	call Function9663
+	ld hl, $cf23
+	ld bc, $000a
+	ld a, $2
+	call ByteFill
+	ld hl, $ce4a
+	ld bc, $0202
+	ld a, $3
+	call Function9663
+	ld hl, $ce4c
+	ld bc, $0202
+	ld a, $4
+	call Function9663
+	ld hl, $ce4e
+	ld bc, $0202
+	ld a, $5
+	call Function9663
+	call Function96b3
+	call Function96a4
+	ld a, $1
+	ld [hCGBPalUpdate], a
+	ret
+; 8f52
+
+INCBIN "baserom.gbc", $8f52, $8f70 - $8f52
+
+Function8f70: ; 8f70
+	ld de, Unkn1Pals
+	ld a, $1d
+	call Function9625
+	call Function9630
+	ld a, [CurPartySpecies]
+	cp $ff
+	jr nz, .asm_8f8a
+	ld hl, $4fba
+	call Function9630
+	jr .asm_8f90
+
+.asm_8f8a
+	call Function9775
+	call Function9643
+
+.asm_8f90
+	call Function9699
+	ld hl, $cdee
+	ld bc, $0707
+	ld a, $1
+	call Function9663
+	call Function971a
+	ld hl, $4fc2
+	ld de, $d078
+	ld bc, $0008
+	ld a, $5
+	call FarCopyWRAM
+	call Function96b3
+	call Function96a4
+	ld a, $1
+	ld [hCGBPalUpdate], a
+	ret
+; 8fba
+
+INCBIN "baserom.gbc", $8fba, $8fca - $8fba
+
+Function8fca: ; 8fca
+	ld de, Unkn1Pals
+	ld a, $1d
+	call Function9625
+	call Function9630
+	ld a, [CurPartySpecies]
+	cp $ff
+	jr nz, .asm_8fe4
+	ld hl, $5036
+	call Function9630
+	jr .asm_8fed
+
+.asm_8fe4
+	ld bc, TempMonDVs
+	call Function974b
+	call Function9643
+
+.asm_8fed
+	call Function9699
+	ld hl, $ce2a
+	ld bc, $0707
+	ld a, $1
+	call Function9663
+	call Function971a
+	call Function96b3
+	call Function96a4
+	ld a, $1
+	ld [hCGBPalUpdate], a
+	ret
+; 9009
+
+INCBIN "baserom.gbc", $9009, $903e - $9009
+
+Function903e: ; 903e
+	ld de, Unkn1Pals
+	ld a, $1d
+	call Function9625
+	call Function9630
+	ld a, [CurPartySpecies]
+	call Function9775
+	call Function9643
+	call Function9699
+	ld hl, $ce44
+	ld bc, $0707
+	ld a, $1
+	call Function9663
+	call Function971a
+	call Function96b3
+	call Function96a4
+	ld a, $1
+	ld [hCGBPalUpdate], a
+	ret
+; 906e
+
+Function906e: ; 906e
+	ld hl, $77a9
+	ld de, Unkn1Pals
+	ld bc, $0080
+	ld a, $5
+	call FarCopyWRAM
+	call Function9699
+	ld hl, $ce01
+	ld bc, $0a03
+	ld a, $2
+	call Function9663
+	ld hl, $ce12
+	ld bc, $0a03
+	ld a, $2
+	call Function9663
+	ld hl, $ce29
+	ld bc, $0603
+	ld a, $3
+	call Function9663
+	ld hl, $ce3a
+	ld bc, $0603
+	ld a, $3
+	call Function9663
+	ld hl, $ce51
+	ld bc, $0203
+	ld a, $4
+	call Function9663
+	ld hl, $ce62
+	ld bc, $0203
+	ld a, $4
+	call Function9663
+	ld hl, $ce05
+	ld bc, $020c
+	ld a, $1
+	call Function9663
+	ld hl, $ce04
+	ld bc, $0a01
+	ld a, $1
+	call Function9663
+	ld hl, $ce11
+	ld bc, $0a01
+	ld a, $1
+	call Function9663
+	ld hl, $cec9
+	ld bc, $0078
+	ld a, $7
+	call ByteFill
+	call Function96b3
+	call Function96a4
+	ld a, $1
+	ld [hCGBPalUpdate], a
+	ret
+; 90f8
+
+Function90f8: ; 90f8
+	ld hl, $5ca7
+	call Function9610
+	call Function9699
+	ld de, Unkn2Pals
+	ld a, $3c
+	call Function9625
+	call Function9630
+	ld hl, $ce51
+	ld bc, $0c14
+	ld a, $1
+	call Function9663
+	call Function96b3
+	call Function96a4
+	ld a, $1
+	ld [hCGBPalUpdate], a
+	ret
+; 9122
+
+Function9122: ; 9122
+	ld b, $0
+	ld hl, $512d
+	add hl, bc
+	add hl, bc
+	ld a, [hli]
+	ld h, [hl]
+	ld l, a
+	jp [hl]
+; 912d
+
+INCBIN "baserom.gbc", $912d, $9195 - $912d
+
+Function9195: ; 9195
+	ld hl, $7789
+	ld de, Unkn1Pals
+	ld bc, $0028
+	ld a, $5
+	call FarCopyWRAM
+	call Function96a4
+	call Function9699
+	call Function96b3
+	ret
+; 91ad
+
+Function91ad: ; 91ad
+	ld hl, $7641
+	ld de, Unkn1Pals
+	ld bc, $0080
+	ld a, $5
+	call FarCopyWRAM
+	ld hl, $5cb7
+	call Function9610
+	call Function9699
+	call Function96b3
+	ret
+; 91c8
+
+Function91c8: ; 91c8
+	call Functionb1de
+	ld a, $9
+	ld [SGBPredef], a
+	ret
+; 91d1
+
+Function91d1: ; 91d1
+	ld hl, $5c57
+	call Function9610
+	call Function8e9f
+	call Function8e85
+	call Function971a
+	call Function96b3
+	ret
+; 91e4
+
+Function91e4: ; 91e4
+	ld de, Unkn1Pals
+	ld a, c
+	and a
+	jr z, .asm_91f5
+	ld a, $1a
+	call Function9625
+	call Function9630
+	jr .asm_921a
+
+.asm_91f5
+	ld hl, PartyMon1DVs
+	ld bc, $0030
+	ld a, [CurPartyMon]
+	call AddNTimes
+	ld c, l
+	ld b, h
+	ld a, [PlayerHPPal]
+	call Function974b
+	call Function9643
+	ld hl, $579c
+	ld de, $d050
+	ld bc, $0030
+	ld a, $5
+	call FarCopyWRAM
+
+.asm_921a
+	call Function9699
+	call Function96b3
+	call Function96a4
+	ld a, $1
+	ld [hCGBPalUpdate], a
+	ret
+; 9228
+
+Function9228: ; 9228
+	ld hl, $76f1
+	ld de, Unkn1Pals
+	ld bc, $0028
+	ld a, $5
+	call FarCopyWRAM
+	ld hl, $7719
+	ld de, Unkn2Pals
+	ld bc, $0010
+	ld a, $5
+	call FarCopyWRAM
+	ld a, $8
+	ld [SGBPredef], a
+	call Function96a4
+	ld a, $1
+	ld [hCGBPalUpdate], a
+	ret
+; 9251
+
+Function9251: ; 9251
+	ld hl, $5cb7
+	call Function9610
+	call Function9699
+	call Function96b3
+	ret
+; 925e
+
+Function925e: ; 925e
+	ld hl, $5bc7
+	call Function9610
+	ld de, Unkn2Pals
+	ld a, $4c
+	call Function9625
+	call Function9630
+	ld a, [rSVBK]
+	push af
+	ld a, $5
+	ld [rSVBK], a
+	ld hl, Unkn2Pals
+	ld a, $1f
+	ld [hli], a
+	ld a, $0
+	ld [hl], a
+	pop af
+	ld [rSVBK], a
+	call Function9699
+	call Function96b3
+	ret
+; 9289
+
+Function9289: ; 9289
+	ld de, Unkn1Pals
+	xor a
+	call Function976b
+	call Function9643
+	ld a, $1
+	call Function976b
+	call Function9643
+	ld a, $3
+	call Function976b
+	call Function9643
+	ld a, $2
+	call Function976b
+	call Function9643
+	ld a, $4
+	call Function976b
+	call Function9643
+	ld a, $7
+	call Function976b
+	call Function9643
+	ld a, $6
+	call Function976b
+	call Function9643
+	ld a, $5
+	call Function976b
+	call Function9643
+	ld a, $24
+	call Function9625
+	call Function9630
+	ld hl, AttrMap
+	ld bc, $0168
+	ld a, [PlayerGender]
+	and a
+	ld a, $1
+	jr z, .asm_92e3
+	ld a, $0
+
+.asm_92e3
+	call ByteFill
+	ld hl, $cdfb
+	ld bc, $0705
+	ld a, [PlayerGender]
+	and a
+	ld a, $0
+	jr z, .asm_92f6
+	ld a, $1
+
+.asm_92f6
+	call Function9663
+	ld hl, $cdff
+	ld [hl], $1
+	ld hl, $ceb7
+	ld bc, $0204
+	ld a, $1
+	call Function9663
+	ld hl, $cebb
+	ld bc, $0204
+	ld a, $2
+	call Function9663
+	ld hl, $cebf
+	ld bc, $0204
+	ld a, $3
+	call Function9663
+	ld hl, $cec3
+	ld bc, $0204
+	ld a, $4
+	call Function9663
+	ld hl, $cef3
+	ld bc, $0204
+	ld a, $5
+	call Function9663
+	ld hl, $cef7
+	ld bc, $0204
+	ld a, $6
+	call Function9663
+	ld hl, $cefb
+	ld bc, $0204
+	ld a, $7
+	call Function9663
+	ld a, [PlayerGender]
+	and a
+	push af
+	jr z, .asm_935d
+	ld hl, $ceff
+	ld bc, $0204
+	ld a, $1
+	call Function9663
+
+.asm_935d
+	pop af
+	ld c, $0
+	jr nz, .asm_9363
+	inc c
+
+.asm_9363
+	ld a, c
+	ld hl, $cdff
+	ld [hl], a
+	call Function96b3
+	call Function96a4
+	ld a, $1
+	ld [hCGBPalUpdate], a
+	ret
+; 9373
+
+Function9373: ; 9373
+	ld de, Unkn1Pals
+	ld a, $10
+	call Function9625
+	call Function9630
+	ld a, [PlayerHPPal]
+	ld l, a
+	ld h, $0
+	add hl, hl
+	add hl, hl
+	ld bc, $68be
+	add hl, bc
+	call Function9643
+	call Function9699
+	ld hl, $cdf8
+	ld bc, $0209
+	ld a, $1
+	call Function9663
+	call Function96b3
+	call Function96a4
+	ld a, $1
+	ld [hCGBPalUpdate], a
+	ret
+; 93a6
+
+Function93a6: ; 93a6
+	ld hl, $5c47
+	call Function9610
+	call Function9699
+	call Function96b3
+	call Function96a4
+	ld a, $1
+	ld [hCGBPalUpdate], a
+	ret
+; 93ba
+
+Function93ba: ; 93ba
+	ld de, Unkn1Pals
+	ld a, $1d
+	call Function9625
+	call Function9630
+	call Function9699
+	call Function96b3
+	call Function96a4
+	ld a, $1
+	ld [hCGBPalUpdate], a
+	ret
+; 93d3
+
+Function93d3: ; 93d3
+	ld a, [BattleType]
+	cp $3
+	jr z, .asm_93e6
+	ld a, [PlayerGender]
+	bit 0, a
+	jr z, .asm_93e6
+	ld hl, $5469
+	jr .asm_93e9
+
+.asm_93e6
+	ld hl, $5439
+
+.asm_93e9
+	ld de, Unkn1Pals
+	ld bc, $0040
+	ld a, $5
+	call FarCopyWRAM
+	call Function9699
+	ld hl, AttrMap
+	ld bc, $010a
+	ld a, $1
+	call Function9663
+	ld hl, $cde3
+	ld bc, $010a
+	ld a, $2
+	call Function9663
+	ld hl, $ce08
+	ld bc, $0901
+	ld a, $3
+	call Function9663
+	ld hl, $ce65
+	ld bc, $0305
+	ld a, $4
+	call Function9663
+	ld hl, $ce15
+	ld bc, $0305
+	ld a, $5
+	call Function9663
+	call Function96b3
+	call Function96a4
+	ld a, $1
+	ld [hCGBPalUpdate], a
+	ret
+; 9439
+
+INCBIN "baserom.gbc", $9439, $9499 - $9439
+
+Function9499: ; 9499
+	call Function91c8
+	ld de, $0014
+	ld hl, AttrMap
+	ld a, [$cf82]
+.asm_94a5
+	and a
+	jr z, .asm_94ac
+	dec a
+	add hl, de
+	jr .asm_94a5
+
+.asm_94ac
+	ld a, [$cf83]
+	ld e, a
+	ld d, $0
+	add hl, de
+	ld a, [$cf82]
+	ld b, a
+	ld a, [$cf84]
+	inc a
+	sub b
+	ld b, a
+	ld a, [$cf83]
+	ld c, a
+	ld a, [$cf85]
+	sub c
+	inc a
+	ld c, a
+	ld a, $0
+	call Function9663
+	call Function96b3
+	ret
+; 94d0
+
+Function94d0: ; 94d0
+	ld hl, $5ba7
+	call Function9610
+	call Function9699
+	ld hl, $ce29
+	ld bc, $0a14
+	ld a, $2
+	call Function9663
+	ld hl, $ce51
+	ld bc, $0614
+	ld a, $1
+	call Function9663
+	call Function96b3
+	call Function96a4
+	ld a, $1
+	ld [hCGBPalUpdate], a
+	ret
+; 94fa
+
+Function94fa: ; 94fa
+	ld de, Unkn1Pals
+	ld a, $4e
+	call Function9625
+	call Function9630
+	ld hl, $5521
+	ld de, Unkn2Pals
+	call Function9630
+	ld hl, $5521
+	ld de, $d048
+	call Function9630
+	call Function9699
+	call Function96b3
+	call Function96a4
+	ret
+; 9521
+
+INCBIN "baserom.gbc", $9521, $9529 - $9521
+
+Function9529: ; 9529
+	ld de, Unkn1Pals
+	ld a, [CurPartySpecies]
+	ld bc, TempMonDVs
+	call Function974b
+	call Function9643
+	call Function9699
+	call Function96b3
+	call Function96a4
+	ret
+; 9542
+
+Function9542: ; 9542
+	ld de, Unkn1Pals
+	ld a, [CurPartySpecies]
+	call Function9775
+	call Function9643
+	call Function9699
+	call Function96b3
+	ret
+; 9555
+
+Function9555: ; 9555
+	ld hl, $5cc7
+	call Function9610
+	ld hl, $7681
+	ld de, Unkn2Pals
+	ld bc, $0008
+	ld a, $5
+	call FarCopyWRAM
+	ld de, $d078
+	ld a, $1c
+	call Function9625
+	call Function9630
+	call Function9699
+	ret
+; 9578
+
+Function9578: ; 9578
+	ld de, Unkn1Pals
+	ld a, [CurPartySpecies]
+	ld bc, TempMonDVs
+	call Function9764
+	call Function9643
+	call Function9699
+	call Function96b3
+	call Function96a4
+	ret
+; 9591
+
+Function9591: ; 9591
+	ld hl, $55e0
+	ld de, Unkn1Pals
+	ld bc, $0010
+	ld a, $5
+	call FarCopyWRAM
+	call Function96a4
+	call Function9699
+	ld hl, $ce68
+	ld bc, $080e
+	ld a, $1
+	call Function9663
+	ld hl, $ce3e
+	ld bc, $0112
+	ld a, $1
+	call Function9663
+	ld hl, $cf1a
+	ld bc, $0112
+	ld a, $1
+	call Function9663
+	ld hl, AttrMap
+	ld bc, $1102
+	ld a, $1
+	call Function9663
+	ld hl, $ce4f
+	ld bc, $0c01
+	ld a, $1
+	call Function9663
+	call Function96b3
+	ret
+; 95e0
+
--- /dev/null
+++ b/predef/sgb.asm
@@ -1,0 +1,591 @@
+Function864c: ; 864c
+; LoadSGBLayout
+	call CheckCGB
+	jp nz, Function8d59
+
+	ld a, b
+	cp $ff
+	jr nz, .asm_865a
+	ld a, [SGBPredef]
+
+.asm_865a
+	cp $fc
+	jp z, Function8ade
+	ld l, a
+	ld h, 0
+	add hl, hl
+	ld de, Table866f
+	add hl, de
+	ld a, [hli]
+	ld h, [hl]
+	ld l, a
+	ld de, Function8a60
+	push de
+	jp [hl]
+; 866f
+
+Table866f: ; 866f
+	dw Function86ad
+	dw Function86b4
+	dw Function875c
+	dw Function8763
+	dw Function87b2
+	dw Function8852
+	dw Function8859
+	dw Function8867
+	dw Function8860
+	dw Function88b1
+	dw Function87ab
+	dw Function88cd
+	dw Function8884
+	dw Function891a
+	dw Function873c
+	dw Function8897
+	dw Function882a
+	dw Function889e
+	dw Function8928
+	dw Function8890
+	dw Function884b
+	dw Function891a
+	dw Function8823
+	dw Function87e9
+	dw Function8921
+	dw Function89a6
+	dw Function89ad
+	dw Function89d9
+	dw Function89e0
+	dw Function8860
+	dw Function8969
+; 86ad
+
+Function86ad: ; 86ad
+	ld hl, $5c66
+	ld de, $5aa6
+	ret
+; 86b4
+
+Function86b4: ; 86b4
+	ld hl, $5aa6
+	call Function9809
+	ld hl, $5ce6
+	ld de, $cda9
+	ld bc, $0010
+	call CopyBytes
+	ld a, [PlayerHPPal]
+	ld l, a
+	ld h, $0
+	add hl, hl
+	add hl, hl
+	ld de, $68be
+	add hl, de
+	ld a, [hli]
+	ld [$cdac], a
+	ld a, [hli]
+	ld [$cdad], a
+	ld a, [hli]
+	ld [$cdae], a
+	ld a, [hl]
+	ld [$cdaf], a
+	ld a, [EnemyHPPal]
+	ld l, a
+	ld h, $0
+	add hl, hl
+	add hl, hl
+	ld de, $68be
+	add hl, de
+	ld a, [hli]
+	ld [$cdb2], a
+	ld a, [hli]
+	ld [$cdb3], a
+	ld a, [hli]
+	ld [$cdb4], a
+	ld a, [hl]
+	ld [$cdb5], a
+	ld hl, $5cf6
+	ld de, $cdb9
+	ld bc, $0010
+	call CopyBytes
+	call Function9729
+	ld a, [hli]
+	ld [$cdbc], a
+	ld a, [hli]
+	ld [$cdbd], a
+	ld a, [hli]
+	ld [$cdbe], a
+	ld a, [hl]
+	ld [$cdbf], a
+	call Function973a
+	ld a, [hli]
+	ld [$cdc2], a
+	ld a, [hli]
+	ld [$cdc3], a
+	ld a, [hli]
+	ld [$cdc4], a
+	ld a, [hl]
+	ld [$cdc5], a
+	ld hl, $cda9
+	ld de, $cdb9
+	ld a, $1
+	ld [SGBPredef], a
+	ret
+; 873c
+
+Function873c: ; 873c
+	ld hl, $5bd6
+	ld de, $cda9
+	ld bc, $0010
+	call CopyBytes
+	ld hl, $cdaa
+	ld [hl], $10
+	inc hl
+	inc hl
+	ld a, [PlayerHPPal]
+	add $2f
+	ld [hl], a
+	ld hl, $cda9
+	ld de, $5ad6
+	ret
+; 875c
+
+Function875c: ; 875c
+	ld hl, $5c76
+	ld de, $5a86
+	ret
+; 8763
+
+Function8763: ; 8763
+	ld hl, $5ce6
+	ld de, $cda9
+	ld bc, $0010
+	call CopyBytes
+	ld a, [$cda1]
+	ld l, a
+	ld h, $0
+	add hl, hl
+	add hl, hl
+	ld de, $68be
+	add hl, de
+	ld a, [hli]
+	ld [$cdac], a
+	ld a, [hli]
+	ld [$cdad], a
+	ld a, [hli]
+	ld [$cdae], a
+	ld a, [hl]
+	ld [$cdaf], a
+	ld a, [CurPartySpecies]
+	ld bc, TempMonDVs
+	call Function974b
+	ld a, [hli]
+	ld [$cdb2], a
+	ld a, [hli]
+	ld [$cdb3], a
+	ld a, [hli]
+	ld [$cdb4], a
+	ld a, [hl]
+	ld [$cdb5], a
+	ld hl, $cda9
+	ld de, $5ac6
+	ret
+; 87ab
+
+Function87ab: ; 87ab
+	ld hl, $5c56
+	ld de, $cdaa
+	ret
+; 87b2
+
+Function87b2: ; 87b2
+	ld hl, $5ce6
+	ld de, $cda9
+	ld bc, $0010
+	call CopyBytes
+	ld hl, $cdac
+	ld [hl], $9f
+	inc hl
+	ld [hl], $2a
+	inc hl
+	ld [hl], $5a
+	inc hl
+	ld [hl], $19
+	ld a, [CurPartySpecies]
+	call Function9775
+	ld a, [hli]
+	ld [$cdb2], a
+	ld a, [hli]
+	ld [$cdb3], a
+	ld a, [hli]
+	ld [$cdb4], a
+	ld a, [hl]
+	ld [$cdb5], a
+	ld hl, $cda9
+	ld de, $5ae6
+	ret
+; 87e9
+
+Function87e9: ; 87e9
+	ld hl, $5ce6
+	ld de, $cda9
+	ld bc, $0010
+	call CopyBytes
+	ld hl, $cdac
+	ld [hl], $9f
+	inc hl
+	ld [hl], $2a
+	inc hl
+	ld [hl], $5a
+	inc hl
+	ld [hl], $19
+	ld a, [CurPartySpecies]
+	ld bc, TempMonDVs
+	call Function974b
+	ld a, [hli]
+	ld [$cdb2], a
+	ld a, [hli]
+	ld [$cdb3], a
+	ld a, [hli]
+	ld [$cdb4], a
+	ld a, [hl]
+	ld [$cdb5], a
+	ld hl, $cda9
+	ld de, $5ae6
+	ret
+; 8823
+
+Function8823: ; 8823
+	call Function87b2
+	ld de, $5af6
+	ret
+; 882a
+
+Function882a: ; 882a
+	ld hl, $5ce6
+	ld de, $cda9
+	ld bc, $0010
+	call CopyBytes
+	ld hl, $cdac
+	ld [hl], $9f
+	inc hl
+	ld [hl], $2a
+	inc hl
+	ld [hl], $5a
+	inc hl
+	ld [hl], $19
+	ld hl, $cda9
+	ld de, $5a86
+	ret
+; 884b
+
+Function884b: ; 884b
+	ld hl, $5c36
+	ld de, $5a86
+	ret
+; 8852
+
+Function8852: ; 8852
+	ld hl, $5c96
+	ld de, $5b06
+	ret
+; 8859
+
+Function8859: ; 8859
+	ld hl, $5ca6
+	ld de, $5b76
+	ret
+; 8860
+
+Function8860: ; 8860
+	ld hl, $5cb6
+	ld de, $5a86
+	ret
+; 8867
+
+Function8867: ; 8867
+	ld b, $0
+	ld hl, $4878
+	add hl, bc
+	add hl, bc
+	add hl, bc
+	add hl, bc
+	ld e, [hl]
+	inc hl
+	ld d, [hl]
+	inc hl
+	ld a, [hli]
+	ld h, [hl]
+	ld l, a
+	ret
+; 8878
+
+INCBIN "baserom.gbc", $8878, $8884 - $8878
+
+Function8884: ; 8884
+	ld hl, $5b96
+	ld de, $5b56
+	ld a, $8
+	ld [SGBPredef], a
+	ret
+; 8890
+
+Function8890: ; 8890
+	ld hl, $5ba6
+	ld de, $5b86
+	ret
+; 8897
+
+Function8897: ; 8897
+	ld hl, $5c46
+	ld de, $5a86
+	ret
+; 889e
+
+Function889e: ; 889e
+	ld hl, $5a86
+	ld de, PlayerLightScreenCount
+	ld bc, $0010
+	call CopyBytes
+	ld hl, $5bb6
+	ld de, $5a86
+	ret
+; 88b1
+
+Function88b1: ; 88b1
+	ld hl, $5bd6
+	ld de, $cda9
+	ld bc, $0010
+	call CopyBytes
+	call Function8a0c
+	ld hl, $cdaa
+	ld [hld], a
+	ld de, $5a86
+	ld a, $9
+	ld [SGBPredef], a
+	ret
+; 88cd
+
+Function88cd: ; 88cd
+	push bc
+	ld hl, $5ce6
+	ld de, $cda9
+	ld bc, $0010
+	call CopyBytes
+	pop bc
+	ld a, c
+	and a
+	jr z, .asm_88ef
+	ld hl, $cdac
+	ld [hl], $e7
+	inc hl
+	ld [hl], $1c
+	inc hl
+	ld [hl], $62
+	inc hl
+	ld [hl], $c
+	jr .asm_8913
+
+.asm_88ef
+	ld hl, PartyMon1DVs
+	ld bc, $0030
+	ld a, [CurPartyMon]
+	call AddNTimes
+	ld c, l
+	ld b, h
+	ld a, [PlayerHPPal]
+	call Function974b
+	ld a, [hli]
+	ld [$cdac], a
+	ld a, [hli]
+	ld [$cdad], a
+	ld a, [hli]
+	ld [$cdae], a
+	ld a, [hl]
+	ld [$cdaf], a
+
+.asm_8913
+	ld hl, $cda9
+	ld de, $5a86
+	ret
+; 891a
+
+Function891a: ; 891a
+	ld hl, $5cb6
+	ld de, $5a86
+	ret
+; 8921
+
+Function8921: ; 8921
+	ld hl, $5bc6
+	ld de, $5a86
+	ret
+; 8928
+
+Function8928: ; 8928
+	ld hl, $5bd6
+	ld de, $cda9
+	ld bc, $0010
+	call CopyBytes
+	ld hl, $5a86
+	ld de, $cdb9
+	ld bc, $0010
+	call CopyBytes
+	call Function8a0c
+	ld hl, $cdaa
+	ld [hl], a
+	ld hl, $cdac
+	ld [hl], $2e
+	ld hl, $cdbc
+	ld a, $5
+	ld [hli], a
+	ld a, [$cf83]
+	ld [hli], a
+	ld a, [$cf82]
+	ld [hli], a
+	ld a, [$cf85]
+	ld [hli], a
+	ld a, [$cf84]
+	ld [hl], a
+	ld hl, $cda9
+	ld de, $cdb9
+	ret
+; 8969
+
+Function8969: ; 8969
+	ld hl, $5ce6
+	ld de, $cda9
+	ld bc, $0010
+	call CopyBytes
+	ld a, [CurPartySpecies]
+	ld l, a
+	ld h, $0
+	add hl, hl
+	add hl, hl
+	add hl, hl
+	ld de, $68ce
+	add hl, de
+	ld a, [$cf65]
+	and $3
+	sla a
+	sla a
+	ld c, a
+	ld b, $0
+	add hl, bc
+	ld a, [hli]
+	ld [$cdac], a
+	ld a, [hli]
+	ld [$cdad], a
+	ld a, [hli]
+	ld [$cdae], a
+	ld a, [hl]
+	ld [$cdaf], a
+	ld hl, $cda9
+	ld de, $5a86
+	ret
+; 89a6
+
+Function89a6: ; 89a6
+	ld hl, $5cd6
+	ld de, $5a86
+	ret
+; 89ad
+
+Function89ad: ; 89ad
+	ld hl, $5ce6
+	ld de, $cda9
+	ld bc, $0010
+	call CopyBytes
+	ld a, [CurPartySpecies]
+	ld bc, TempMonDVs
+	call Function974b
+	ld a, [hli]
+	ld [$cdac], a
+	ld a, [hli]
+	ld [$cdad], a
+	ld a, [hli]
+	ld [$cdae], a
+	ld a, [hl]
+	ld [$cdaf], a
+	ld hl, $cda9
+	ld de, $5a86
+	ret
+; 89d9
+
+Function89d9: ; 89d9
+	ld hl, $5cc6
+	ld de, $5a86
+	ret
+; 89e0
+
+Function89e0: ; 89e0
+	ld hl, $5ce6
+	ld de, $cda9
+	ld bc, $0010
+	call CopyBytes
+	ld a, [CurPartySpecies]
+	ld bc, TempMonDVs
+	call Function9764
+	ld a, [hli]
+	ld [$cdac], a
+	ld a, [hli]
+	ld [$cdad], a
+	ld a, [hli]
+	ld [$cdae], a
+	ld a, [hl]
+	ld [$cdaf], a
+	ld hl, $cda9
+	ld de, $5a86
+	ret
+; 8a0c
+
+Function8a0c: ; 8a0c
+	ld a, [TimeOfDayPal]
+	cp $2
+	jr c, .asm_8a16
+	ld a, $19
+	ret
+
+.asm_8a16
+	ld a, [$d19a]
+	cp $2
+	jr z, .asm_8a39
+	cp $4
+	jr z, .asm_8a3c
+	cp $7
+	jr z, .asm_8a3c
+	cp $5
+	jr z, .asm_8a3f
+	cp $6
+	jr z, .asm_8a42
+	ld a, [MapGroup]
+	ld e, a
+	ld d, $0
+	ld hl, $4a45
+	add hl, de
+	ld a, [hl]
+	ret
+
+.asm_8a39
+	ld a, $0
+	ret
+
+.asm_8a3c
+	ld a, $18
+	ret
+
+.asm_8a3f
+	ld a, $6
+	ret
+
+.asm_8a42
+	ld a, $3
+	ret
+; 8a45
+
+INCBIN "baserom.gbc", $8a45, $8a60 - $8a45
+
+Function8a60: ; 8a60
+	push de
+	call Function9809
+	pop hl
+	jp Function9809
+; 8a68
+
--- a/wram.asm
+++ b/wram.asm
@@ -2026,12 +2026,12 @@
 PartyMonNicknamesEnd
 
 SECTION "Pokedex",WRAMX[$de99],BANK[1]
-PokedexSeen: ; de99
+PokedexCaught: ; de99
 	ds 32
-EndPokedexSeen:
-PokedexCaught: ; deb9
-	ds 32
 EndPokedexCaught:
+PokedexSeen: ; deb9
+	ds 32
+EndPokedexSeen:
 UnownDex: ; ded9
 	ds 26
 UnlockedUnowns: ; def3