-
Notifications
You must be signed in to change notification settings - Fork 0
/
cartridge.asm
376 lines (318 loc) · 6.36 KB
/
cartridge.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
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
; Build customized cartridge (MAGIC DESK 64k = 8 banks, 8k each, visible at $8000-$9FFF).
; 64k are not enough to hold both the uncompressed game and uncompressed splash screen.
; Hold as much data as possible in uncompressed form.
; Splash graphics (bitmap at $4000) are stored without compression.
; Unfortunately, the C64's PLA does not provide a "CART_LOW + RAM" option which would
; be handy for decompressing from ROM directly (as the decompressor needs access to
; decompressed data).
; Consequently, we can only decompress directly to $0000-$9FFF and $C000-$CFFF.
; Other areas can be copied to (without decompressing). Of course decompressing
; to RAM, then copying to, e.g., $A000, is possible. Copying compressed data
; then uncompressing works, too.
; However, be aware that setting the MSB of $DE00 is is sticky for some
; hardware, i.e., once you disable EXROM there, the cartridge ROM is gone for
; good (until reset).
; Magic Desk CRT info
; https://codebase64.org/doku.php?id=base:crt_file_format#magic_desk_domark_hes_australia
; Available PLA configurations
; $01 GAME EXROM
; x7 1 1 Int. RAM Int. RAM BASIC ROM Int. RAM I/O Kernal ROM
; x3 1 1 Int. RAM Int. RAM BASIC ROM Int. RAM Charset ROM Kernal ROM
; x6 1 X Int. RAM Int. RAM Int. RAM Int. RAM I/O Kernal ROM
; x5 1 X Int. RAM Int. RAM Int. RAM Int. RAM I/O Int. RAM
; x0/x4 1 X Int. RAM Int. RAM Int. RAM Int. RAM Int. RAM Int. RAM
; x2 1 X Int. RAM Int. RAM Int. RAM Int. RAM Charset ROM Kernal ROM
; x1 1 X Int. RAM Int. RAM Int. RAM Int. RAM Charset ROM Int. RAM
; x7 1 0 Int. RAM Cart. Low BASIC ROM Int. RAM I/O Kernal ROM
; x3 1 0 Int. RAM Cart. Low BASIC ROM Int. RAM Charset ROM Kernal ROM
* = $0
; ********************* BANK 0
; * CRT start code and helper, LZSA decompressor,
; * compressed splash gfx screen scrmem and colmem,
; * VSF unfreezer stage 2/3, compressed $4000-$6400 data
!pseudopc $8000 {
!word cold_start
!word warm_start
!byte $c3,$c2,$cd,$38,$30
cold_start:
sei
lda #$00
sta $d020
sta $d021
lda #$0b ; disable screen
sta $d011
waitclr:
lda $d012
bne waitclr
lda $d011
bmi waitclr
ldy #0
cpy_helper:
lda start_helper+$0000,y
sta $0400,y
lda start_helper+$0100,y
sta $0500,y
lda start_helper+$0200,y
sta $0600,y
lda start_helper+$0300,y
sta $0700,y
iny
bne cpy_helper
jmp helper_entry
start_helper:
!pseudopc $0400 {
!src "decompress_faster_v1.asm"
helper_entry:
lda #<cmpr_scrmem_colmem
sta LZSA_SRC_LO
lda #>cmpr_scrmem_colmem
sta LZSA_SRC_HI
lda #0
sta LZSA_DST_LO
lda #$60
sta LZSA_DST_HI
jsr DECOMPRESS_LZSA1_FAST ; screen mem
lda #0
sta LZSA_DST_LO
lda #$d8
sta LZSA_DST_HI
jsr DECOMPRESS_LZSA1_FAST ; col mem
lda #1
sta $de00 ; switch to ROM bank 1
lda #0
sta LZSA_SRC_LO
sta LZSA_DST_LO
lda #$80
sta LZSA_SRC_HI
lda #$40
sta LZSA_DST_HI
ldx #$20
jsr justcopy
lda #$03
sta $dd02 ; enable CIA2 port A output
lda #$c2
sta $dd00 ; select VIC bank 1 ($4000-$7FFF)
lda #$80
sta $d018 ; bitmap at $4000, screen mem at $6000
lda #$18
sta $d016 ; enable multicolor mode
lda #$3b
sta $d011 ; enable graphics, enable screen
; splash is visible now - unpack (most) of GQ6 already
nop
; bank 0: $0002-$00F8, $0100-$01A0, $0200-$03FF
lda #0
sta $de00
lda #<cmpr_00_01_02
sta LZSA_SRC_LO
lda #>cmpr_00_01_02
sta LZSA_SRC_HI
lda #$02
sta LZSA_DST_LO
lda #$00
sta LZSA_DST_HI
jsr DECOMPRESS_LZSA1_FAST
lda #$00
sta LZSA_DST_LO
lda #$01
sta LZSA_DST_HI
jsr DECOMPRESS_LZSA1_FAST
lda #$00
sta LZSA_DST_LO
lda #$02
sta LZSA_DST_HI
jsr DECOMPRESS_LZSA1_FAST
skip:
; bank 2: $0801-$2FFF
lda #2
sta $de00
lda #$00
sta LZSA_SRC_LO
lda #$80
sta LZSA_SRC_HI
lda #01
sta LZSA_DST_LO
lda #$08
sta LZSA_DST_HI
jsr DECOMPRESS_LZSA1_FAST
; bank 3: $3000-$3FFF, $6400-$7FFF
lda #3
sta $de00
lda #$00
sta LZSA_SRC_LO
lda #$80
sta LZSA_SRC_HI
lda #$00
sta LZSA_DST_LO
lda #$30
sta LZSA_DST_HI
jsr DECOMPRESS_LZSA1_FAST
lda #$00
sta LZSA_DST_LO
lda #$64
sta LZSA_DST_HI
jsr DECOMPRESS_LZSA1_FAST
; bank 7: $8000-$9FFF
lda #7
sta $de00
lda #$00
sta LZSA_SRC_LO
sta LZSA_DST_LO
lda #$80
sta LZSA_SRC_HI
lda #$80
sta LZSA_DST_HI
ldx #$20
jsr justcopy
; bank 4: $A000-$BFFF
lda #4
sta $de00
lda #$00
sta LZSA_SRC_LO
sta LZSA_DST_LO
lda #$80
sta LZSA_SRC_HI
lda #$A0
sta LZSA_DST_HI
ldx #$20
jsr justcopy
; bank 5: $C000-$DFFF
lda #5
sta $de00
lda #$33
sta $01 ; disable I/O
lda #$2f
sta $00 ; set cpu port to output
lda #$00
sta LZSA_SRC_LO
sta LZSA_DST_LO
lda #$80
sta LZSA_SRC_HI
lda #$C0
sta LZSA_DST_HI
ldx #$20
jsr justcopy
lda #$37
sta $01 ; re-enable I/O
; bank 6: $E000-$FFFF
lda #6
sta $de00
lda #$00
sta LZSA_SRC_LO
sta LZSA_DST_LO
lda #$80
sta LZSA_SRC_HI
lda #$E0
sta LZSA_DST_HI
ldx #$20
jsr justcopy
; splash screen is visible, wait for key/joy2
lda #$ff
sta $dc03
lda #$00
sta $dc02
sta $dc01
waitkey:
ldx $dc00
cpx $dc00
bne waitkey
inx
beq waitkey
waitkey2:
ldx $dc00
cpx $dc00
bne waitkey2
inx
bne waitkey2
; unpack last bits and start
lda #$2b ; disable screen
sta $d011
waitclr2:
lda $d012
bne waitclr2
lda $d011
bmi waitclr2
; bank 0: $4000-$6400
lda #0
sta $de00
lda #$00
sta LZSA_DST_LO
lda #$40
sta LZSA_DST_HI
lda #<cmpr_40
sta LZSA_SRC_LO
lda #>cmpr_40
sta LZSA_SRC_HI
jsr DECOMPRESS_LZSA1_FAST
; jump to stage 2 (in bank 0)
lda #0
sta $de00
jmp stage2
warm_start:
loop:
lda #$01
sta $d020
sta $d021
jmp loop
; copy X times 256 bytes from LZSA_SRC to LZSA_DST
justcopy:
ldy #0
jcloop:
lda (lzsa_srcptr),y
sta (lzsa_dstptr),y
iny
bne jcloop
inc <lzsa_srcptr + 1
inc <lzsa_dstptr + 1
dex
bne jcloop
rts
}
cmpr_scrmem_colmem:
!binary "build/cmpr_koala_scrcol.bin"
cmpr_00_01_02:
!binary "build/cmpr_00.bin"
!binary "build/cmpr_01.bin"
!binary "build/cmpr_02.bin"
!align $ffff, $8900
stage2:
!binary "build/stage2.prg",,2
cmpr_40:
!binary "build/cmpr_40.bin"
}
; ********************* BANK 1
!align $ffff, $2000
!pseudopc $8000 {
!binary "build/koa_bitmap.bin"
}
; ********************* BANK 2
!align $ffff, $4000
!pseudopc $8000 {
!binary "build/cmpr_08.bin"
}
; ********************* BANK 3
!align $ffff, $6000
!pseudopc $8000 {
!binary "build/cmpr_30.bin"
!binary "build/cmpr_64.bin"
}
; ********************* BANK 4
!align $ffff, $8000
!pseudopc $8000 {
!binary "build/mem_a0.bin"
}
; ********************* BANK 5
!align $ffff, $A000
!pseudopc $8000 {
!binary "build/mem_c0.bin"
}
; ********************* BANK 6
!align $ffff, $C000
!pseudopc $8000 {
!binary "build/mem_e0.bin"
}
; ********************* BANK 7
!align $ffff, $E000
!pseudopc $8000 {
!binary "build/mem_80.bin"
}