1; GEOS KERNAL by Berkeley Softworks
2; reverse engineered by Maciej Witkowiak, Michael Steil
3;
4; Panic
5
6.include "const.inc"
7.include "geossym.inc"
8.include "geosmac.inc"
9.include "config.inc"
10.include "gkernal.inc"
11
12.segment "panic1"
13
14.import DoDlgBox
15.import Ddec
16.import EnterDeskTop
17
18; syscall
19.global _Panic
20
21.ifdef gateway
22_Panic:
23	; On the gateWay KERNAL, the "Panic" syscall points to
24	; the EnterDesktop implementation. The BRK vector still
25	; points here though.
26	;
27	; This seems to deal with swapping the disk driver from
28	; and to the REU, triggered by the RESTORE key.
29	sei
30	pha
31	txa
32	pha
33	tya
34	pha
35	lda CPU_DATA
36	pha
37	ldx StackPtr
38	bne @1
39	tsx
40@1:	txs
41	stx StackPtr
42	ldx #0
43@2:	dex
44	bne @2
45	jsr SwapMemory
46	jmp DISK_BASE
47
48; ??? no entry?
49	ldx StackPtr
50	txs
51	jsr SwapMemory
52	stx StackPtr
53	LoadW NMI_VECTOR, _Panic
54	PopB CPU_DATA
55	pla
56	tay
57	pla
58	tax
59	pla
60	rti
61
62SwapRegs:
63	ldx #6
64@1:	lda r0,x
65	tay
66	lda SwapRAMArgs,x
67	sta r0,x
68	tya
69	sta SwapRAMArgs,x
70	dex
71	bpl @1
72	rts
73
74SwapMemory:
75	jsr SwapRegs
76	jsr SwapRAM
77	jsr SwapRegs
78	inx
79	rts
80
81SwapRAMArgs:
82	.word DISK_BASE ; CBM addr
83	.word $c000     ; REU addr
84	.word 0         ; count
85	.byte 0         ; REU bank
86
87	.byte 0, 0 ; XXX
88
89StackPtr:
90	.byte 0
91
92	.byte 0, 0, 0 ; PADDING
93
94.else
95;---------------------------------------------------------------
96; Panic                                                   $C2C2
97;
98; Pass:      nothing
99; Return:    does not return
100;---------------------------------------------------------------
101_Panic:
102.ifdef wheels
103	sec
104	pla
105	sbc #2
106	tay
107	pla
108	sbc #0
109.else
110.ifdef bsw128
111	pla
112	pla
113	pla
114	pla
115	pla
116	pla
117	pla
118	pla
119.endif
120	PopW r0
121.ifdef bsw128
122	ldx #r0
123	jsr Ddec
124	ldx #r0
125	jsr Ddec
126.else
127	SubVW 2, r0
128.endif
129	lda r0H
130.endif
131	ldx #0
132	jsr @1
133.ifdef wheels
134	tya
135.else
136	lda r0L
137.endif
138	jsr @1
139	LoadW r0, _PanicDB_DT
140	jsr DoDlgBox
141.ifdef wheels
142	jmp EnterDeskTop
143.endif
144@1:
145.if 0 ; XXX X16: removed for size, has to be enabled again!
146	pha
147	lsr
148	lsr
149	lsr
150	lsr
151	jsr @2
152	inx
153	pla
154	and #%00001111
155	jsr @2
156	inx
157	rts
158@2:	cmp #10
159	bcs @3
160	addv '0'
161	bne @4
162@3:	addv '0'+7
163@4:	sta _PanicAddr,x
164.endif
165	rts
166
167.segment "panic2"
168
169_PanicDB_DT:
170	.byte DEF_DB_POS | 1
171	.byte DBTXTSTR, TXT_LN_X, TXT_LN_1_Y
172	.word _PanicDB_Str
173.ifdef wheels
174	.byte DBSYSOPV
175.endif
176	.byte NULL
177
178.segment "panic3"
179
180_PanicDB_Str:
181	.byte BOLDON
182.ifdef wheels_size
183	.byte "Error near "
184.else
185	.byte "System error near "
186.endif
187.endif
188
189	.byte "$"
190_PanicAddr:
191	.byte "xxxx"
192	.byte NULL
193