summaryrefslogtreecommitdiff
path: root/src/home/farcall.asm
diff options
context:
space:
mode:
authorElectroDeoxys <ElectroDeoxys@gmail.com>2021-09-09 08:51:12 +0100
committerElectroDeoxys <ElectroDeoxys@gmail.com>2021-09-09 08:51:12 +0100
commit32b02147925566bac93bf71b002860335583574c (patch)
treed9cf016338d08022f0c0db358b356ddfb18b0e16 /src/home/farcall.asm
parente4bce9b7ee5e89f8edfd921de2379f0fa06af206 (diff)
Split home bank
Diffstat (limited to 'src/home/farcall.asm')
-rw-r--r--src/home/farcall.asm92
1 files changed, 92 insertions, 0 deletions
diff --git a/src/home/farcall.asm b/src/home/farcall.asm
new file mode 100644
index 0000000..8474ca9
--- /dev/null
+++ b/src/home/farcall.asm
@@ -0,0 +1,92 @@
+; RST18
+; this function affects the stack so that it returns to the pointer following
+; the rst call. similar to rst 28, except this always loads bank 1
+Bank1Call: ; 09ae (0:09ae)
+ push hl
+ push hl
+ push hl
+ push hl
+ push de
+ push af
+ ld hl, sp+$d
+ ld d, [hl]
+ dec hl
+ ld e, [hl]
+ dec hl
+ ld [hl], $0
+ dec hl
+ ldh a, [hBankROM]
+ ld [hld], a
+ ld [hl], HIGH(SwitchToBankAtSP)
+ dec hl
+ ld [hl], LOW(SwitchToBankAtSP)
+ dec hl
+ inc de
+ ld a, [de]
+ ld [hld], a
+ dec de
+ ld a, [de]
+ ld [hl], a
+ ld a, $1
+; fallthrough
+
+Bank1Call_FarCall_Common: ; 09ce (0:09ce)
+ call BankswitchROM
+ ld hl, sp+$d
+ inc de
+ inc de
+ ld [hl], d
+ dec hl
+ ld [hl], e
+ pop af
+ pop de
+ pop hl
+ ret
+
+; switch to the ROM bank at sp+4
+SwitchToBankAtSP: ; 9dc (0:9dc)
+ push af
+ push hl
+ ld hl, sp+$04
+ ld a, [hl]
+ call BankswitchROM
+ pop hl
+ pop af
+ inc sp
+ inc sp
+ ret
+
+; RST28
+; this function affects the stack so that it returns
+; to the three byte pointer following the rst call
+FarCall: ; 09e9 (0:09e9)
+ push hl
+ push hl
+ push hl
+ push hl
+ push de
+ push af
+ ld hl, sp+$d
+ ld d, [hl]
+ dec hl
+ ld e, [hl]
+ dec hl
+ ld [hl], $0
+ dec hl
+ ldh a, [hBankROM]
+ ld [hld], a
+ ld [hl], HIGH(SwitchToBankAtSP)
+ dec hl
+ ld [hl], LOW(SwitchToBankAtSP)
+ dec hl
+ inc de
+ inc de
+ ld a, [de]
+ ld [hld], a
+ dec de
+ ld a, [de]
+ ld [hl], a
+ dec de
+ ld a, [de]
+ inc de
+ jr Bank1Call_FarCall_Common