summaryrefslogtreecommitdiff
path: root/src/home/farcall.asm
diff options
context:
space:
mode:
authorDaniel Harding <33dannye@gmail.com>2021-09-19 00:21:14 -0500
committerGitHub <noreply@github.com>2021-09-19 00:21:14 -0500
commitdf67aac83b466dadf5f74c881bf84dd9ef19bdfc (patch)
tree47501aced2d256052b8f78bc97328d5af5703add /src/home/farcall.asm
parente4bce9b7ee5e89f8edfd921de2379f0fa06af206 (diff)
parent8dee6b7a11e85d6d4b9f8ec9fb9d53a499fd37dc (diff)
Merge pull request #110 from ElectroDeoxys/master
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..1fc4ee8
--- /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:
+ 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:
+ 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:
+ 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