1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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
|