-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathsboot.xa
375 lines (342 loc) · 7.62 KB
/
sboot.xa
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
;----------------------------------------------------------------
; SBOOT
; bootloader pro SDrive
; Robert Petruzela & Radek Sterba
; Bob!k & Raster, C.P.U., 2008
;----------------------------------------------------------------
;
;- 188 bytes
;
;14.2.2008
;- optimized to use the init and run address in the boot sector
; (thanks to this, 2 bytes of the return address will not remain hanging in the stack, and in addition, the loader is 2 bytes shorter)
;- cutting off the unnecessary from the "once_and_then_next_block" part
; (saved 10 bytes)
;- 176 bytes
;- added check of the result of the loading sector, if it is not #1, reload
;- 178 bytes
;- optimization of init address 9 (save 2 bytes)
;- 176 bytes
;- 179 bytes
;
;7.6.2008
;- substitute storeX ($47) for txa,pha a pla,tax
; (saving one cell in the zero page (at the expense of the stack))
;
;08.04.2021
;- converted to XA (by kbr)
;
;30.11.2022
;- added support for basic files(thanks to Jindrich Kubec for the code from his bas2boot project)
;
;16.06.2024
;- added sio highspeed support
buffer = $f400 ;the lower byte of the buffer must be 0!
edst = $43 ;2
dst = $45 ;2
basic = $47 ;1
sc_nsector = $30a
RAMTOP = $6A
LOMEM = $80
BOOT = $09
BASICF = $03F8
PORTB = $D301
EOPEN = $EF94
BAS_CONT = $A97A
BAS_EXEC = $B755
;* = buffer+$80-(adr780-bootsector) ;XXX Does not work in XA!
* = buffer+$80-$2e ;now len $2e hardcoded
;
;This first part is in the area below $0780,
;so after the first sector is loaded into the buffer $700-$77f it will be overwritten
;
bootsector ;$72='r' (identification SD'r'ive)
.byte $72,(end-bootsector)/128+1
.word bootsector,entry
reloc_00 = bootsector+3
reloc_01 = bootsector+5
init
lda #<buffer
sta $304 ;can't be replaced by sty $304 because no init at the begining
#print <buffer <> 0 ;lower buffers are 0 !
;a=0
sta 580 ;prevent boot after reset (some programs use a jump through the reset vector (Joust))
sta $309 ;LENH
;sta basic ;mark basic(is 0 at boot)
lda #>buffer
reloc_02 = *-1
sta $305
lda #$80
sta $308 ;LENL
lda #$70 ;here is sector number $170
sta $30a ;because it increments by 1 right at the beginning
lda #$01 ;and starts at $171
sta $30b
;A=1
sta $9 ;some games need it (RASTER's invention from Xin1)
lda #$52 ;read
sta $302 ;COMMAND
rts
.byte 125 ;as if there were 125 bytes in that sector to load the next sector
;
;----------------------
;
adr780
read_next_sector
lda #$40
sta $303 ;reset status to read
txa
pha ;save X
rea1
jsr siohv ;siov
dey ;is the result of the operation 1 (ok) ? dey decrements to Y=0
bne rea1 ;is Y=0 ? not => again
pla
tax ;restore X
;Y=0 ;Y-reg is zero ( used for next sta (ns),y ), not necessary -> replaced by (ns,x)
sty index
reloc_03 = *-1
readbyte ;reading one byte from buffer and incrementing index pointer
index = *+1
lda buffer+125 ;overwritting LB, index=$7d
reloc_04 = *-1
inc index
reloc_05 = *-1
lrts
rts ;used two times, one is for return from get_next_byte
;second one is for jmp ($02e2)
;--
;
next_block
;
lda #<lrts ;init address point to rts
sta $02e2
lda #>lrts
reloc_06 = *-1
sta $02e3
;
ldx #2
nb10
jsr get_next_byte ;read destination adress
reloc_07 = *-1
sta edst,x ;edst+2 => dst and in second round edst
neu1
jsr get_next_byte
reloc_08 = *-1
sta edst+1,x ;edst+1+2 => dst+1 and in second round edst+1
neu2
and edst,x ;we are lucky, end address could not be $FFFF
cmp #$ff
beq nb10
dex
dex
bpl nb10 ;should be X==0;
bmi nb20 ;need to skip one incrementation of dst because block length is edst-dst-1
nb15
inc dst ;incrementing destination address
bne nb20
inc dst+1
nb20
jsr get_next_byte ;copy next byte from buffer to destination address
reloc_09 = *-1
ldx #1
sta (dst-1,x) ;Ughh, I know ;-)
;x=1
eofb
lda dst,x
cmp edst,x
bne nb15
dex
bpl eofb
nb30
jsr nb40 ;everytime jmp on init address, normaly is there pointer on RTS else original init
;has to be JSR here!!!
reloc_10 = *-1
jmp next_block ;go for next binary-block
reloc_11 = *-1
;--
get_next_byte ;return next byte in A-reg
lda index ;last byte in sector?
reloc_12 = *-1
cmp buffer+127
reloc_13 = *-1
bne readbyte ;no - get next byte
;
inc $30a ;feel with it from the sectors of the file
bne nxv1 ;I follow from $171 very nice
inc $30b ;he gave a sequential order without gaps or anything
nxv1
lda buffer+125
reloc_14 = *-1
ora buffer+126
reloc_15 = *-1
bne read_next_sector ;goes to the next sector
;the pointer to the next sector is null
;so let's finish
jsr nb40 ;due to init (I believe $02e2 still point to RTS)
reloc_16 = *-1
lda #0
cmp basic ;is basic?
beq basic_start
jmp ($02e0) ;jump on run address
;
;
;the next part exceeds over $800 and after implementation
;it can easily be overwritten with data (if a block is imported from $800...)
reloc .byte >buffer ;byte(0x07) for relocation adjustments
;will be changed by SDrive relocation feature
;
entry
jsr sio_high ;load sio highspeed routine
next ;once_and_then_next_block
jsr get_next_byte ;load the first sector and overwrite 0700-077f
reloc_17 = *-1
sta $02e0
jsr get_next_byte
reloc_18 = *-1
sta $02e1
and $02e0
cmp #$ff ;are they both FF?
bne chkbas ;no => go basic
sta basic ;mark no basic(0xff)
beq next ;then try the other two
chkbas lda #0
cmp basic ;XEX?
bne goon
;else thread them as basic file
lda reloc ;make sure, we are above the bootloader code
;C=1 ;and highspeed loader
adc #3
;C=0
sta reloc
lda $02e0
sta LOMEM ;store vectors
lda $02e1
reloc_20 = *-1
adc reloc ;add LOMEM offset
reloc_21 = *-1
sta LOMEM+1
ldx #2
setvect jsr get_next_byte
reloc_22 = *-1
sta LOMEM,x
jsr get_next_byte
reloc_23 = *-1
adc reloc ;add LOMEM offset
reloc_24 = *-1
inx
sta LOMEM,x
inx
cpx #14
bne setvect
lda LOMEM+2 ;fake start addr
sta buffer+10
reloc_25 = *-1
lda LOMEM+3
sta buffer+11
reloc_26 = *-1
;end addr is already at the right position
lda LOMEM+13 ;but add offset also
adc reloc
sta buffer+13
lda #10
;
goon sta index
reloc_19 = *-1
jmp next_block ;!
reloc_27 = *-1
basic_start
ldx #$ff
txs
lda #$0a
sta $c9
lda #$00
sta BOOT
sta BASICF
;turn on basic
lda #$fd
sta PORTB
;set stack
lda #>BAS_CONT
pha
lda #<BAS_CONT - 1
pha
lda #>BAS_EXEC
pha
lda #<BAS_EXEC - 1
pha
lda RAMTOP
bpl store_memt
lda #$a0
store_memt:
sta RAMTOP
jmp EOPEN
nb40
lda #3
sta $d20f
jmp ($02e2) ;jmp on init address
sio_high:
lda #$68 ;get sio routine length
sta $302
lda #$40
sta $303
lda #$2
sta $308
jsr $e459
inc $302 ;get sio routine($69)
lda #$40
sta $303
lda buffer
sta $308
lda buffer+1
sta $309
lda #<siohv ;store
sta $304
sta $30a
lda #>siohv
sta $305
sta $30b
jsr $e459
jmp init ;reset siov values
;
; relocation table 20 bytes
;
#if 0
.byte reloc_00-bootsector
.byte reloc_01-bootsector
.byte reloc_02-bootsector
.byte reloc_03-bootsector
.byte reloc_04-bootsector
.byte reloc_05-bootsector
.byte reloc_06-bootsector
.byte reloc_07-bootsector
.byte reloc_08-bootsector
.byte reloc_09-bootsector
.byte reloc_10-bootsector
.byte reloc_11-bootsector
.byte reloc_12-bootsector
.byte reloc_13-bootsector
.byte reloc_14-bootsector
.byte reloc_15-bootsector
.byte reloc_16-bootsector
.byte reloc_17-bootsector
.byte reloc_18-bootsector
.byte reloc_19-bootsector
.byte reloc_20-bootsector
.byte reloc_21-bootsector
.byte reloc_22-bootsector
.byte reloc_23-bootsector
.byte reloc_24-bootsector
.byte reloc_25-bootsector
.byte reloc_26-bootsector
.byte reloc_27-bootsector
#endif
siohv jmp $e459
end
;sio_cmd
; .byte $31,$02,$52,$40
; .word buffer
; .byte $07,$00,$80,$00
;sc_nsector * ;,a($ffff)
; org $4000
;test jmp *