-
Notifications
You must be signed in to change notification settings - Fork 2
/
display_koala.asm
428 lines (399 loc) · 6.88 KB
/
display_koala.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
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
.const DEBUG = false
.const GENDEBUG = false
.const MUSICDEBUG = false
.const LOOP = false
.const PERFRAME = false
.const fade_speed = 1
.const steps = 16
.const bitmap = $2000
.const screenram = $0400
.const colorram = $d800
.const fade_pass_address = $4800
.const src_screenram = $4000
.const src_colorram = $4400
.const zp_start = $0334 // displaycode will be shorter if this is <$f9, but we prefer zeropage-less code to allow most sids to play.
.const zp_screen_lo = zp_start + 0
.const zp_screen_hi = zp_start + 1
.const zp_d800_lo = zp_start + 2
.const zp_d800_hi = zp_start + 3
.const zp_src_screen_lo = zp_start + 4
.const zp_src_screen_hi = zp_start + 5
.const zp_src_d800_lo = zp_start + 6
.const zp_src_d800_hi = zp_start + 7
.import source "lib.asm"
.pc = $0801 "basic upstart"
.byte <basicend, >basicend, <year(), >year(), $9e
.text toIntString(start)
.text " PNG2PRG " + versionString()
basicend:
.byte 0, 0, 0
.pc = $0819 "music_startsong"
music_startsong:
.byte 0
.pc = * "music_init"
music_init:
jmp rrts
.pc = * "music_play"
music_play:
jmp rrts
.pc = * "frame_delay"
frame_delay:
.byte 0
.pc = * "wait_seconds"
wait_seconds:
.byte 0
.pc = basicsys() "start"
start:
sei
jsr $e544
lda #$35
sta $01
ldy #7
!loop:
ldx #fade_speed
!: jsr vblank
dex
bne !-
lda $d020
and #$0f
tax
lda t_easyfade,x
sta $d020
lda $d021
and #$0f
tax
lda t_easyfade,x
sta $d021
dey
bne !loop-
sta $d011
// default pal 50 hz: $4cc7
lda #$c7
sta $dc04
lda #$4c
sta $dc05
lax music_startsong
tay
jsr music_init
lda #<irq
sta $fffe
lda #>irq
sta $ffff
lda #$80
!: cmp $d012
bne !-
.if (MUSICDEBUG) {
ldx #5
!: dex
bne !-
}
lda #%00010001
sta $dc0e
cli
jsr generate_fade_pass
lax #0
!:
.for (var i=0; i<4; i++) {
sta screenram+(i*$100),x
sta colorram+(i*$100),x
}
inx
bne !-
ldy #4
ldx #$e8
!:
smc_koalasrc_col:
lda koala_source+$2328+$300,x
smc_src_col:
sta src_colorram+$300,x
dex
cpx #$ff
bne !-
dec smc_koalasrc_col+2
dec smc_src_col+2
dey
bne !-
ldy #4
ldx #$e8
!:
smc_koalasrc_screen:
lda koala_source+$1f40+$300,x
smc_src_screen:
sta src_screenram+$300,x
dex
cpx #$ff
bne !-
dec smc_koalasrc_screen+2
dec smc_src_screen+2
dey
bne !-
jsr vblank
:setBank(bitmap)
lda #toD018(screenram, bitmap)
sta $d018
lda #$d8
sta $d016
lda #$3b
sta $d011
.pc = * "fade_loop"
fade_loop:
smc_yval: ldy #steps-1
.if (DEBUG) inc $d020
jsr generate_phase_col_tables
.if (DEBUG) dec $d020
ldx #fade_speed
!: jsr vblank
dex
bne !-
.if (PERFRAME) {
lda #$ef
!: cmp $dc01
bne !-
!: cmp $dc01
beq !-
}
ldx src_colorram+1000
lda t_color_fade,x
sta $d021
lda src_colorram+1000
lsr
lsr
lsr
lsr
tax
lda t_color_fade,x
sta $d020
!: lda $d012
cmp #$70
bcc !-
cmp #$90
bcs !-
.if (DEBUG) dec $d020
jsr fade_pass
.if (DEBUG) inc $d020
dec smc_yval+1
lda smc_yval+1
cmp #$ff
beq !done+
cmp #(steps/2)-1
bne fade_loop
!: lda $dc01
cmp #$ef
bne !-
beq fade_loop
!done:
.if (LOOP) {
lda #$ef
!: cmp $dc01
bne !-
// reset phase
lda #<t_fadepercol
sta smc_fadepercol1 + 1
sta smc_fadepercol2 + 1
lda #steps-1
sta smc_yval + 1
bne fade_loop
} else {
sei
lda #$37
sta $01
jsr vblank
lda #0
sta $d011
sta $d418
jmp $fce2
}
.pc = * "vblank"
vblank:
:vblank()
rrts: rts
// --------------------------------
.pc = * "irq"
irq:
pha
txa
pha
tya
pha
.if (MUSICDEBUG) dec $d020
jsr music_play
.if (MUSICDEBUG) inc $d020
lda $dc0d
pla
tay
pla
tax
pla
rti
// --------------------------------
.pc = * "generate_fade_pass"
generate_fade_pass:
lda #<screenram
sta zp_screen_lo
sta zp_d800_lo
sta zp_src_screen_lo
sta zp_src_d800_lo
lda #>screenram
sta zp_screen_hi
lda #>colorram
sta zp_d800_hi
lda #>src_screenram
sta zp_src_screen_hi
lda #>src_colorram
sta zp_src_d800_hi
lax #$00
tay
!loop:
lda #$ae // ldx zp_src_screen_lo
jsr store_byte
lda zp_src_screen_lo
jsr store_byte
lda zp_src_screen_hi
jsr store_byte
lda #$bd // lda t_color_fade,x
jsr store_byte
lda #<t_color_fade
jsr store_byte
lda #>t_color_fade
jsr store_byte
lda #$8d // sta screen_lo
jsr store_byte
lda zp_screen_lo
jsr store_byte
lda zp_screen_hi
jsr store_byte
lda #$ae // ldx zp_src_d800_lo
jsr store_byte
lda zp_src_d800_lo
jsr store_byte
lda zp_src_d800_hi
jsr store_byte
lda #$bd // lda t_color_fade,x
jsr store_byte
lda #<t_color_fade
jsr store_byte
lda #>t_color_fade
jsr store_byte
lda #$8d // sta d800_lo
jsr store_byte
lda zp_d800_lo
jsr store_byte
lda zp_d800_hi
jsr store_byte
inc zp_src_screen_lo
inc zp_src_d800_lo
inc zp_screen_lo
inc zp_d800_lo
bne !+
inc zp_src_screen_hi
inc zp_src_d800_hi
inc zp_screen_hi
inc zp_d800_hi
!:
cpx #$e7
bne not_last
cpy #$03
beq !done+
not_last:
.if (zp_start < $f9) {
inx
bne !loop-
iny
bne !loop-
} else {
inx
beq !+
jmploop:
jmp !loop-
!:
iny
bne jmploop
}
!done:
lda #$60 // rts
store_byte:
sta fade_pass
.if (GENDEBUG) sta $d020
inc store_byte+1
bne !+
inc store_byte+2
!: rts
// --------------------------------
.pc = * "generate_phase_col_tables"
generate_phase_col_tables:
//lda #<t_color_fade
//sta smc_totpercol + 1
!loop:
// start with color 0
ldx #0
!:
// y points to hi-nibble of color x
ldy t_col2index,x // y = 0, $10, $20, .., $f0
smc_fadepercol1:
lda t_fadepercol
asl
asl
asl
asl
smc_fadepercol2:
ora t_fadepercol,y
smc_totpercol:
sta t_color_fade
.if (GENDEBUG) sta $d020
inc smc_totpercol + 1
inx
cpx #$10
bcc !-
lda smc_fadepercol1 + 1
// sec not needed, carry is always set
adc #$0f
sta smc_fadepercol1 + 1
bcc !loop-
// prepare code for next phase
inc smc_fadepercol1 + 1
inc smc_fadepercol2 + 1
rts
// ------------------------------
.pc = * "t_col2index"
t_col2index:
.fill $10, i*$10
// ------------------------------
.pc = * "t_easyfade"
t_easyfade:
.byte $00,$0d,$09,$0c,$02,$08,$00,$0f
.byte $02,$00,$08,$09,$04,$03,$04,$05
// ------------------------------
.align $100
.pc = * "t_fadepercol"
t_fadepercol:
:colorfade_table()
// ------------------------------
// ------------------------------
.align $100
.pc = * "t_color_fade"
t_color_fade:
.fill $100, 0
// ------------------------------
.pc = bitmap "koala_source" virtual
koala_source:
.fill $2711, 0
// ------------------------------
.pc = fade_pass_address "fade_pass" virtual
fade_pass:
/*
.C:4800 AE 00 04 LDX $0400
.C:4803 BD 00 09 LDA $0900,X
.C:4806 8D 00 04 STA $0400
.C:4809 AE 00 D8 LDX $D800
.C:480c BD 00 09 LDA $0900,X
.C:480f 8D 00 D8 STA $D800
*/
.for (var i=0; i<1000; i++) {
ldx $0400+i
lda t_color_fade,x
sta $0400+i
ldx $d800+i
lda t_color_fade,x
sta $d800+i
}
rts