This repository has been archived by the owner on Sep 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathErrorHandler.asm
214 lines (188 loc) · 3.09 KB
/
ErrorHandler.asm
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
; ================================================================
; Error handler
; TO USE: Include this file anywhere in the Home bank then add a
; call to ErrorHandler to RST_38
; ================================================================
ErrorHandler:
; store stack pointer
inc sp
inc sp
ld [tempSP],sp
push hl
push af
; store AF
pop hl
ld a,h
ldh [tempAF],a
ld a,l
ldh [tempAF+1],a
; store BC
ld a,b
ldh [tempBC],a
ld a,c
ldh [tempBC+1],a
; store DE
ld a,d
ldh [tempDE],a
ld a,e
ldh [tempDE+1],a
; store HL
pop hl
ld a,h
ldh [tempHL],a
ld a,l
ldh [tempHL+1],a
; store PC
pop hl ; hl = old program counter
ld a,h
ldh [tempPC],a
ld a,l
ldh [tempPC+1],a
; store IF
ldh a,[rIF]
ldh [tempIF],a
; store IE
ldh a,[rIE]
ldh [tempIE],a
.wait ; wait for VBlank before disabling the LCD
ldh a,[rLY]
cp $90
jr nz,.wait
; Note that it probably isn't a good idea to use halt to wait for VBlank
; because interrupts may not be enabled when an error occurs.
xor a
ldh [rLCDC],a ; disable LCD
.nowait
xor a
ldh [rSCX],a
ldh [rSCY],a
call ClearVRAM
CopyTileset1BPP DebugFont,0,97
ld hl,ErrorHandlerTilemap
call LoadMapText
ld a,%11100100 ; DMG default palette
ldh [rBGP],a
ld hl,Pal_Grayscale
xor a
call LoadBGPalLine ; GBC default palette
DrawRegisterValues:
ld de,tempAF
ld hl,$9965
ld a,[de]
inc de
call DrawHex
ld a,[de]
inc de
call DrawHex
ld hl,$996f
ld a,[de]
inc de
call DrawHex
ld a,[de]
inc de
call DrawHex
ld hl,$9985
ld a,[de]
inc de
call DrawHex
ld a,[de]
inc de
call DrawHex
ld hl,$998f
ld a,[de]
inc de
call DrawHex
ld a,[de]
inc de
call DrawHex
inc de
inc de
ld hl,$99af
ld a,[de]
inc de
call DrawHex
ld a,[de]
inc de
call DrawHex
ld hl,$99a5
ld a,[tempSP+1]
call DrawHex
ld a,[tempSP]
call DrawHex
; TODO: Draw IF and IE
ld a,[rIF]
ld b,a
ld hl,$99c8
call DrawBin
ld a,[rIE]
ld b,a
ld hl,$99e8
call DrawBin
ld a,%10010001
ldh [rLCDC],a
ErrorHandler_loop:
call CheckInput
ld a,[sys_btnPress]
bit btnStart,a
jr z,.continue
ld a,[GBAFlag]
ld b,a
ld a,[GBCFlag]
jp ProgramStart
.continue
halt
jr ErrorHandler_loop
DrawBin:
bit 7,b
call nz,.draw1
call z,.draw0
bit 6,b
call nz,.draw1
call z,.draw0
bit 5,b
call nz,.draw1
call z,.draw0
bit 4,b
call nz,.draw1
call z,.draw0
bit 3,b
call nz,.draw1
call z,.draw0
bit 2,b
call nz,.draw1
call z,.draw0
bit 1,b
call nz,.draw1
call z,.draw0
bit 0,b
call nz,.draw1
ret nz
.draw0
ld a,"0" - 32
ld [hl+],a
ret
.draw1
ld a,"1" - 32
ld [hl+],a
ret
ErrorHandlerTilemap:
; ####################
db " - ERROR - "
db " "
db "A fatal error has "
db "occured and the game"
db "cannot continue. "
db "Contact this e-mail "
db "address to report "
db "this error: "
db " [email protected] "
db " "
db "Registers: "
db " AF=$???? BC=$???? "
db " DE=$???? HL=$???? "
db " SP=$???? PC=$???? "
db " IF=%XXXXXXXX "
db " IE=%XXXXXXXX "
db " Press Start for "
db " stack dump "
; ####################