-
Notifications
You must be signed in to change notification settings - Fork 2
/
display_petscii_charset_anim.asm
481 lines (445 loc) · 7.76 KB
/
display_petscii_charset_anim.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
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
.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 src_screenram = $2800
.const src_colorram = $2c00
.const animations = $3000
.const fade_pass_address = $ac00
.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_src_screen_lo = zp_start + 2
.const zp_src_screen_hi = zp_start + 3
.const zp_src_d800_lo = zp_start + 4
.const zp_src_d800_hi = zp_start + 5
.const zp_anim_start = $08
.const zp_anim_lo = zp_anim_start + 0
.const zp_anim_hi = zp_anim_start + 1
.const zp_char_lo = zp_anim_start + 2
.const zp_char_hi = zp_anim_start + 3
.const zp_d800_lo = zp_anim_start + 4
.const zp_d800_hi = zp_anim_start + 5
.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 = * "charset_case"
charset_case:
.byte 0 // 0 = uppercase, 1 = lowercase
.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++) {
lda src_screenram+(i*$100),x
sta screenram+(i*$100),x
lda #0
sta colorram+(i*$100),x
}
inx
bne !-
jsr vblank
:setBank(screenram)
lda charset_case
asl
clc
adc #toD018(screenram, $1000)
sta $d018
lda #$c8
sta $d016
lda #$1b
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 $d020
ldx src_colorram+1001
lda t_color_fade,x
sta $d021
!: 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
jsr anim_init
// optional wait before anim start
ldy wait_seconds
beq loop_anim
!waitloop:
ldx #50
!: jsr vblank
dex
bne !-
dey
bne !waitloop-
loop_anim:
ldx frame_delay
!loop: //jsr vblank
lda #$e0
!: cmp $d012
bne !-
!: cmp $d012
beq !-
dex
bne !loop-
.if (DEBUG) inc $d020
jsr anim_play
.if (DEBUG) dec $d020
lda $dc01
cmp #$ef
bne loop_anim
jmp 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_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_d800_lo
inc zp_d800_lo
bne !+
inc zp_src_d800_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 = * "anim_play"
anim_play:
next_chunk:
ldy #0
lax (zp_anim_lo),y
bne plot_chunk // #$00 = end of frame
inc zp_anim_lo
bne !+
inc zp_anim_hi
!:
lda (zp_anim_lo),y
cmp #$ff // #$ff = end of all frames
bne !skip+
.pc = * "anim_init"
anim_init:
lda #<anim_frames
sta zp_anim_lo
lda #>anim_frames
sta zp_anim_hi
!skip: rts
plot_chunk:
//tax // x = number of chars in chunk
iny
lda (zp_anim_lo),y
sta zp_char_lo
sta zp_d800_lo
iny
lda (zp_anim_lo),y
clc
adc #>screenram
sta zp_char_hi
adc #>(colorram - screenram)
sta zp_d800_hi
lda zp_anim_lo
adc #3
sta zp_anim_lo
bcc !+
inc zp_anim_hi
clc
!:
plot_next_char:
ldy #1
lda (zp_anim_lo),y
dey
sta (zp_d800_lo),y
lda (zp_anim_lo),y
sta (zp_char_lo),y
inc zp_anim_lo
bne !+
inc zp_anim_hi
!:
inc zp_anim_lo
bne !+
inc zp_anim_hi
!:
inc zp_char_lo
inc zp_d800_lo
bne !+
inc zp_char_hi
inc zp_d800_hi
!:
dex
bne plot_next_char
beq next_chunk
// ------------------------------
.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 "charset_bitmap" virtual
charset_bitmap:
.fill $800, 0
// ------------------------------
.pc = animations "anim_frames" virtual
anim_frames:
.byte 0,$ff
// ------------------------------
.pc = fade_pass_address "fade_pass" virtual
fade_pass:
/*
.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 $d800+i
lda t_color_fade,x
sta $d800+i
}
rts