1; GEOS KERNAL by Berkeley Softworks
2; reverse engineered by Maciej Witkowiak; Michael Steil
3;
4; Purgeable start code; first entry
5
6.include "const.inc"
7.include "geossym.inc"
8.include "geosmac.inc"
9.include "config.inc"
10.include "gkernal.inc"
11.include "inputdrv.inc"
12.include "c64.inc"
13.include "banks.inc"
14.include "kernal.inc"
15
16; main.s
17.import InitGEOEnv
18.import _DoFirstInitIO
19.import _EnterDeskTop
20
21; irq.s
22.import _IRQHandler
23.import _NMIHandler
24
25.import LdApplic
26.import GetBlock
27.import EnterDeskTop
28.import GetDirHead
29.import FirstInit
30.import i_FillRam
31.import _DoUpdateTime
32
33.import bootTr2
34.import bootSec2
35.import bootOffs
36.import bootSec
37.import bootTr
38
39.import _Rectangle
40
41.import MouseInit
42
43; used by header.s
44.global _ResetHandle
45
46.ifdef usePlus60K
47.import DetectPlus60K
48.endif
49.if .defined(useRamCart64) || .defined(useRamCart128)
50.import DetectRamCart
51.endif
52.ifdef useRamExp
53.import LoadDeskTop
54.endif
55
56.segment "start"
57
58_ResetHandle:
59	sei
60	cld
61	ldx #$FF
62	txs
63
64.if 0
65	jsr i_FillRam
66	.word $0500
67	.word dirEntryBuf
68	.byte 0
69.endif
70
71.import __drvcbdos_SIZE__, __drvcbdos_LOAD__, __drvcbdos_RUN__
72.import _i_MoveData
73
74	jsr _i_MoveData
75	.word __drvcbdos_LOAD__
76	.word __drvcbdos_RUN__
77	.word __drvcbdos_SIZE__
78
79	lda #$80
80	jsr gjsrfar
81	.word screen_set_mode
82	.byte BANK_KERNAL
83
84	jsr gjsrfar
85	.word FB_init
86	.byte BANK_KERNAL
87
88	; Disable layer 1
89	lda VERA_DC_VIDEO
90	and #$DF
91	sta VERA_DC_VIDEO
92
93	; IRQ
94	lda #1
95	sta VERA_IEN
96
97	jsr _DoUpdateTime
98
99	;
100	jsr FirstInit
101	jsr MouseInit
102	lda #currentInterleave
103	sta interleave
104
105	lda #1
106	sta numDrives
107	ldy $BA
108	sty curDrive
109	lda #DRV_TYPE ; see config.inc
110	sta curType
111	sta _driveType,y
112
113; This is the original code the cbmfiles version
114; has at $5000.
115OrigResetHandle:
116	sei
117	cld
118	ldx #$ff
119	jsr _DoFirstInitIO
120	jsr InitGEOEnv
121.ifdef usePlus60K
122	jsr DetectPlus60K
123.endif
124.if .defined(useRamCart64) || .defined(useRamCart128)
125	jsr DetectRamCart
126.endif
127
128	LoadB bootTr, DIR_TRACK
129	LoadB bootSec, 1
130
131	jsr GetDirHead
132	MoveB bootSec, r1H
133	MoveB bootTr, r1L
134	AddVB 32, bootOffs
135	bne @3
136@1:	MoveB bootSec2, r1H
137	MoveB bootTr2, r1L
138	bne @3
139	lda numDrives
140	bne @2
141	inc numDrives
142@2:	LoadW EnterDeskTop+1, _EnterDeskTop
143.ifdef useRamExp
144	jsr LoadDeskTop
145.endif
146	jmp EnterDeskTop
147
148@3:	MoveB r1H, bootSec
149	MoveB r1L, bootTr
150	LoadW r4, diskBlkBuf
151	jsr GetBlock
152	bnex @2
153	MoveB diskBlkBuf+1, bootSec2
154	MoveB diskBlkBuf, bootTr2
155@4:	ldy bootOffs
156	lda diskBlkBuf+2,y
157	beq @5
158	lda diskBlkBuf+$18,y
159	cmp #AUTO_EXEC
160	beq @6
161@5:	AddVB 32, bootOffs
162	bne @4
163	beq @1
164@6:	ldx #0
165@7:	lda diskBlkBuf+2,y
166	sta dirEntryBuf,x
167	iny
168	inx
169	cpx #30
170	bne @7
171	LoadW r9, dirEntryBuf
172	LoadW EnterDeskTop+1, _ResetHandle
173	LoadB r0L, 0
174	jsr LdApplic
175
176
177.segment "entry"
178entry:
179	.assert * = $C000, error, "GEOS entry must be at $C000"
180	jmp _ResetHandle
181
182.segment "vectors"
183	.word _NMIHandler
184	.word entry
185	.word _IRQHandler
186
187.segment "start"
188; GEOS's entry into jsrfar
189.setcpu "65c02"
190.export gjsrfar
191gjsrfar:
192.include "jsrfar.inc"
193
194