-
Notifications
You must be signed in to change notification settings - Fork 2
/
carloadcode.src
497 lines (441 loc) · 7.42 KB
/
carloadcode.src
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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
; carloadcode - load .car file into The!Cart/Freezer2011 RAM
;
; Copyright (C) 2013-2016 Matthias Reichl <hias@horus.com>
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
.LOCAL
.if .def THECART
.include "thecart.inc"
.else
.if .def FREEZER
.include "freezer.inc"
.else
.error "either THECART or FREEZER must be set!"
.endif
.endif
; print EOL terminated text
.macro PRT0 ; arg: label
LDX #<%1
LDY #>%1
JSR PRTCOD
.endm
CARBUF = BASE
; print text on screen / channel 0
; in: X=adr lo, Y=adr hi
PRTCOD STX $344
STY $345
LDA #9
STA $342
LDA #127
STA $348
LDX #0
STX $349
JMP $E456
LOADCAR
; set memtop to $A000, init graphics 0 screen
LDA #$A0
STA 106
JSR GR0
; detect cart (returns only if thecart found)
.if .def THECART
JSR TCDETECT
.endif
.if .def FREEZER
JSR FDETECT
.endif
; setup INIADR to catch premature EOF
LDA #<TCEOF
STA 738
LDA #>TCEOF
STA 739
LDX XREG
; skip over 'R', 'T' and first 3 mode bytes
LDY #5
JSR TCSKIP
; read mode
JSR GETBYT
; check for valid mode (returns only if mode found)
STX XREG
JSR TCCKMOD
LDX XREG
; skip over checksum and 4 unused bytes
LDY #8
JSR TCSKIP
; load loop
?LDCARLP
JSR LDCAR8K
DEC TCBLK
BNE ?LDCARLP
; now start the cartridge
INC $42
; use write protected RAM
.if .def THECART
LDA #TC_CFG_SRC
STA TC_CFG
; bank 0
LDA #0
STA TC_BANKLO
STA TC_BANKHI
LDA TCMOD
STA TC_MODE
; check for mode specific init stuff
CMP #TC_MODE_OSS
BNE RUNC1
STA OSSBANK1
RUNC1 CMP #TC_MODE_SDX64
BNE RUNC2
STA SDX64_BANKCTL
RUNC2 CMP #TC_MODE_DIAMOND64
BNE RUNC3
STA DIAMOND64_BANKCTL
RUNC3 CMP #TC_MODE_EXPRESS64
BNE RUNC4
STA EXPRESS64_BANKCTL
RUNC4 CMP #TC_MODE_SIC
BNE RUNC5
LDX #0
STX SIC_BANKCTL
RUNC5
STA TC_LOCKCFG
JMP $E477
.endif
.if .def FREEZER
LDA #CE_CFG_SRC
STA CE_CFG
LDA #CE_TEMP_RAM_BANK
STA CE_BANK
LDA TCMOD
STA CE_MODE
; check for mode specific init stuff
CMP #CE_MODE_OSS
BNE RUNC1
STA OSSBANK1
RUNC1
JMP $E477
.endif
.if .def THECART
; check if thecart is present
TCDETECT
INC $42
LDA #TC_MODE_8K
STA TC_MODE
LDA #TC_CFG_WE
STA TC_CFG
LDA #0
STA TC_BANKLO
STA TC_BANKHI
; enable autoselect mode
LDA #$AA
STA $AAAA
LDA #$55
STA $A555
LDA #$90
STA $AAAA
; check manufacturer id
LDA $A000
CMP #$01
BNE ?TCDETNO
; check device id
LDA $A002
CMP #$7E
BNE ?TCDETNO
LDA $A01E
CMP #$01
BNE ?TCDETNO
LDA $A01C
CMP #$28 ; 01
BEQ ?TCDETOK
CMP #$23
BEQ ?TCDETOK
CMP #$22
BEQ ?TCDETOK
CMP #$21
BNE ?TCDETNO
?TCDETOK
; OK, found the!cart
; disable autoselect mode and set RAM mode
LDA #$F0
STA $A000
LDA #TC_CFG_WE+TC_CFG_SRC
STA TC_CFG
LDA #0
STA TC_ENABLE
DEC $42
RTS
; no cart detected
?TCDETNO
LDA #$F0
STA $A000
LDA #TC_MODE_OFF
STA TC_MODE
LDA #0
STA TC_CFG
STA TC_ENABLE
DEC $42
PRT0 TNOTCDET
?CELP JMP ?CELP
.endif
.if .def FREEZER
FDETECT
; check if freezer is present
INC $42
; set 8k writable RAM mode
LDA #CE_CFG_WE+CE_CFG_SRC
STA CE_CFG
LDA #CE_MODE_8K
STA CE_MODE
LDA #CE_TEMP_RAM_BANK
STA CE_BANK
LDA #CE_SDX_OFF
STA CE_SDX
LDX #0
LDY #1
STX CE_ENABLE
; check if we have the RAM bank present
LDA $A000
STY CE_ENABLE
EOR #$FF
STA $A000
CMP $A000
BNE ?FDETNO
STX CE_ENABLE
CMP $A000
BEQ ?FDETNO
; everything's fine!
DEC $42
RTS
?FDETNO
STX CE_ENABLE
STX CE_CFG
LDA #CE_MODE_OFF
STA CE_MODE
DEC $42
PRT0 TNOFDET
?CELP JMP ?CELP
.endif
TCEOF PRT0 TEOF
JMP ?CELP
; skip over Y bytes
TCSKIP JSR GETBYT
DEY
BNE TCSKIP
RTS
; check for valid mode in A
TCCKMOD STA TCMOD
LDX #0
?TCCKLP LDA CMODTAB,X
BEQ ?TCCKNO ; end of table
CMP TCMOD
BEQ ?TCCK1
INX
INX
INX
BNE ?TCCKLP ; always
?TCCKNO PRT0 TINVMOD
JMP ?CELP
?TCCK1 LDA CMODTAB+1,X
STA TCMOD
LDA CMODTAB+2,X
STA TCBLK
PRT0 TLOADCAR
.if .def THECART
LDA TCMOD
CMP #TC_MODE_ATARIMAX8
BNE ?TCCK2
PRT0 TAMWARN
.endif
?TCCK2 RTS
; load 8k block into thecart
LDCAR8K
; setup address and len for loading
LDA #<CARBUF
STA ADR
LDA #>CARBUF
STA ADR+1
LDA #0
STA BLEN
LDA #$20
STA BLEN+1
LDY #0
?MLOOP CPX BYTES
BNE ?NRRD
?DORD JSR RREAD
LDA BLEN+1
CMP #2
BCC ?NRRD
LDA BYTES
CMP SECBYTE
BNE ?NRRD
; use fast copy routine in case of a full (125/253 bytes) sector
TYA
CLC
ADC ADR
STA ADR
BCC ?NI01
INC ADR+1
?NI01 LDY SECBYTE
DEY
?COP4 LDA BUF,Y
STA (ADR),Y
DEY
LDA BUF,Y
STA (ADR),Y
DEY
LDA BUF,Y
STA (ADR),Y
DEY
LDA BUF,Y
STA (ADR),Y
DEY
BNE ?COP4
LDA BUF,Y
STA (ADR),Y
CLC
LDA ADR
ADC SECBYTE
STA ADR
BCC ?NI02
INC ADR+1
?NI02 SEC
LDA BLEN
BNE ?NEN1
INC BLEN+1
?NEN1 SBC SECBYTE
STA BLEN
BNE ?NEN2
DEC BLEN+1
?NEN2 BCS ?ND01
DEC BLEN+1
?ND01 JMP ?DORD
?NRRD LDA BUF,X
INX
STA (ADR),Y
DEC BLEN
BNE ?ADPLUS
DEC BLEN+1
BEQ ?ENDBLK
?ADPLUS INY
BNE ?MLOOP
INC ADR+1
BNE ?MLOOP
?ENDBLK
; now copy 8k block into thecart ram
STX XREG
INC $42
.if .def THECART
LDA #1
STA TC_ENABLE
.endif
.if .def FREEZER
LDA #1
STA CE_ENABLE
.endif
LDA #>CARBUF
STA ?CCSRC+2
LDA #$A0
STA ?CCDST+2
LDY #0
LDX #$20
?CCLP
?CCSRC LDA CARBUF,Y
?CCDST STA $A000,Y
INY
BNE ?CCLP
INC ?CCSRC+2
INC ?CCDST+2
DEX
BNE ?CCLP
; next bank
.if .def THECART
INC TC_BANKLO
LDA #0
STA TC_ENABLE
.endif
.if .def FREEZER
INC CE_BANK
LDA #0
STA CE_ENABLE
.endif
DEC $42
LDX XREG
RTS
.if .def THECART
TNOTCDET
.BYTE "The!Cart not present", 155
.endif
.if .def FREEZER
TNOFDET
.BYTE "Turbo Freezer 2011 not present", 155
.endif
TINVMOD
.BYTE "Unsupported cartridge mode", 155
TLOADCAR
.if .def THECART
.BYTE "Loading CAR into The!Cart RAM",155
.endif
.if .def FREEZER
.BYTE "Loading CAR into Freezer RAM",155
.endif
TAMWARN
.BYTE "Only first 512k will be loaded!",155
TEOF
.BYTE "premature end of file!",155
.if .def THECART
; car mode to thecart mode mapping:
; car mode, thecart mode, number of 8k blocks
CMODTAB
.BYTE 1, TC_MODE_8K, 1
.BYTE 2, TC_MODE_16K, 2
.BYTE 8, TC_MODE_WILLIAMS64, 8
.BYTE 9, TC_MODE_EXPRESS64, 8
.BYTE 10, TC_MODE_DIAMOND64, 8
.BYTE 11, TC_MODE_SDX64, 8
.BYTE 12, TC_MODE_XEGS_32, 4
.BYTE 13, TC_MODE_XEGS_64, 8
.BYTE 14, TC_MODE_XEGS_128, 16
.BYTE 15, TC_MODE_OSS, 2
.BYTE 17, TC_MODE_ATRAX128, 16
.BYTE 23, TC_MODE_XEGS_256, 32
.BYTE 24, TC_MODE_XEGS_512, 64
.BYTE 26, TC_MODE_MEGA_16, 2
.BYTE 27, TC_MODE_MEGA_32, 4
.BYTE 28, TC_MODE_MEGA_64, 8
.BYTE 29, TC_MODE_MEGA_128, 16
.BYTE 30, TC_MODE_MEGA_256, 32
.BYTE 31, TC_MODE_MEGA_512, 64
.BYTE 33, TC_MODE_SXEGS_32, 4
.BYTE 34, TC_MODE_SXEGS_64, 8
.BYTE 35, TC_MODE_SXEGS_128, 16
.BYTE 36, TC_MODE_SXEGS_256, 32
.BYTE 37, TC_MODE_SXEGS_512, 64
.BYTE 40, TC_MODE_BLIZZARD, 2
.BYTE 41, TC_MODE_ATARIMAX1, 16
.BYTE 42, TC_MODE_ATARIMAX8, 64 ; only first 512k loaded!
.BYTE 56, TC_MODE_SIC, 64
.BYTE 0,0,0
.endif
.if .def FREEZER
; car mode to thecart mode mapping:
; car mode, freezer mode, number of 8k blocks
CMODTAB
.BYTE 1, CE_MODE_8K, 1
.BYTE 2, CE_MODE_16K, 2
.BYTE 15, CE_MODE_OSS, 2
.BYTE 0,0,0
.endif
; thecart mode
TCMOD .BYTE 0
; number of 8k blocks to load
TCBLK .BYTE 0