shithub: pokered

Download patch

ref: ecf5f87019140588f3d6d609933efb46e183e74b
parent: 86a83b1046359258a261055e35172cdb93dd2a55
author: IIMarckus <[email protected]>
date: Fri Oct 29 17:20:50 EDT 2010

Expand some bankswitch routines in the home bank

hg-commit-id: 01edc4778cee


--- a/pokered.asm
+++ b/pokered.asm
@@ -1233,8 +1233,45 @@
 HiddenPrefix:
 	db $87,$8C ; "HM"
 
-INCBIN "baserom.gbc",$3040,$3A87 - $3040
+INCBIN "baserom.gbc",$3040,$35BC - $3040
+BankswitchHome: ; 35BC
+; switches to bank # in a
+; Only use this when in the home bank!
+	ld [$CF09],a
+	ld a,[$FFB8]
+	ld [$CF08],a
+	ld a,[$CF09]
+	ld [$FFB8],a
+	ld [$2000],a
+	ret
 
+BankswitchBack: ; 35CD
+; returns from BankswitchHome
+	ld a,[$CF08]
+	ld [$FFB8],a
+	ld [$2000],a
+	ret
+
+Bankswitch: ; 35D6
+; self-contained bankswitch, use this when not in the home bank
+; switches to the bank in b
+	ld a,[$FFB8]
+	push af
+	ld a,b
+	ld [$FFB8],a
+	ld [$2000],a
+	ld bc,.Return\@
+	push bc
+	jp [hl]
+.Return\@
+	pop bc
+	ld a,b
+	ld [$FFB8],a
+	ld [$2000],a
+	ret
+
+INCBIN "baserom.gbc",$35EC,$3A87 - $35EC
+
 AddNTimes: ; 3A87
 ; add bc to hl a times
 	and a
@@ -3840,7 +3877,7 @@
 	ld [$D11D],a
 	ld hl,$490E
 	ld b,$F
-	call $35D6 ; bankswitch
+	call Bankswitch
 	xor a
 	ld [$D11D],a
 	ld a,[$D12B]
@@ -3953,7 +3990,7 @@
 	ld [hl],b
 	ld hl,$7428
 	ld b,$F
-	call $35D6 ; bankswitch
+	call Bankswitch
 	pop hl
 	pop af
 	ld [hli],a