-
Notifications
You must be signed in to change notification settings - Fork 2
/
display_mc_charset.asm
286 lines (266 loc) · 4.48 KB
/
display_mc_charset.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
.const DEBUG = false
.const GENDEBUG = false
.const MUSICDEBUG = false
.const LOOP = false
.const fade_speed = 2
.const steps = 16
.const charset = $2000
.const screenram = $2800
.const colorram = $d800
.const colorram_src = $2c00
.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
.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
sta $d022
sta $d023
sta $d024
!loop:
.for (var i=0; i<4; i++) {
sta colorram+i*$100,y
}
iny
bne !loop-
// 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
ldx #0
!:
.for (var i=0; i<4; i++) {
lda colorram_src+i*$100,x
and #%00001000
sta colorram+i*$100,x
}
inx
bne !-
:setBank(charset)
lda #toD018(screenram, charset)
sta $d018
lda #$d8
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 !-
ldy #3
!: ldx colorram_src+$3e8,y
lda t_color_fade,x
sta $d020,y
dey
bpl !-
dec smc_yval+1
lda smc_yval+1
cmp #$ff
beq !done+
cmp #(steps/2)-1
bne fade_loop
ldx #0
!:
.for (var i=0; i<4; i++) {
lda colorram_src+i*$100,x
sta colorram+i*$100,x
}
inx
bne !-
lda #$ef
!: cmp $dc01
bne !-
jsr vblank
ldx #0
.for (var i=0; i<4; i++) {
!:
lda colorram_src+i*$100,x
and #%00001000
sta colorram+i*$100,x
inx
bne !-
}
beq fade_loop
!done:
.if (LOOP) {
lda #$ef
!: cmp $dc01
bne !-
jsr reset_phase
lda #steps-1
sta smc_yval + 1
jmp 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_phase_col_tables"
generate_phase_col_tables:
!next_step:
// 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
// clc 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 = * "reset_phase"
reset_phase:
.if (LOOP) {
lda #<t_fadepercol
sta smc_fadepercol1 + 1
sta 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 = charset "charset" virtual
.fill $800,0
// ------------------------------