-
Notifications
You must be signed in to change notification settings - Fork 0
/
palette.asm
320 lines (283 loc) · 6.31 KB
/
palette.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
palette_cache EQU $e7
;Palette00: ; 25 bytes
; hex 0f ;screen color
; hex 022830 ;background 0
; hex 071624 ;background 1
; hex 02113c ;background 2
; hex 0b1a3b ;background 3
; hex 192939 ;sprite 0 ; rudy
; hex 132130 ;sprite 1; old birb palete
; ;hex 051637 ; chomps
;hex 122130 ; vamp eyes & bats
;hex 071727 ;sprite 2
; hex 150037 ; vamp head/face
; hex 013530 ;sprite 3 ; starglasses ; crossbones
; bg 0 - stars bg_tiles 1 / title screen
; bg 1 - stars bg_tiles 2
; bg 2 - n/a (bg enemies haha)
; bg 3 - dashboard / options screen
; spr 0 - player
; spr 1 - enemy / darts
; spr 2 - enemy / stars sprites 1
; spr 3 - enemy / powerups / stars sprite 2
; level palettes
; spr 1, 2 and 3
; boss palettes
; spr 1 and 2
palette_table:
; #00 end bad
byte #$0f, #$30, #$27
; #03 end ok
byte #$0f, #$10, #$30
; #06 end good
byte #$0a, #$37, #$27
; #09 end alien
byte #$3c, #$1c, #$24
; #12 intro bg
byte #$0c, #$30, #$3c
; #15 intro alien
byte #$04, #$1b, #$37
; #18 title screen
byte #$02, #$27, #$34
; #21 level 0 palettes (and attract mode)
hex 13 21 30
hex 07 17 27
hex 01 35 30
; #30 level 1 palettes
hex 06 16 38
hex 0b 18 39
hex 08 32 20
; #39 level 2 palettes
hex 0c 2d 32
hex 13 25 37
hex 09 27 10
; #48 level 3 palettes
hex 2d 10 30
hex 12 23 37
hex 07 17 27
; #57 boss
; moufs palettes
hex 04 16 20
hex 02 07 38
; #63 boss
; vamp+bats palettes
hex 15 2d 37
hex 02 11 30
; #69 boss
; scarab palettes
hex 0c 27 37
hex 03 1a 39
; #75 boss
; swordtner palettes
hex 07 17 3d
hex 11 2d 31
; #81 bookbinder
hex 0f 00 37
palette_level_offset_table:
byte #21, #30, #39, #48
palette_boss_offset_table:
byte #57, #63, #69, #75
palette_load:
; x = palette table offset
; y = pal ram offset
; loads 1 set of 3 colors
; not used to write to main bg color
lda #$02
sta temp00
.loader_loop
lda palette_table,x
sta pal_uni_bg+1,y
inx
iny
dec temp00
bpl .loader_loop
rts
palette_next_rainbow_color: subroutine
; a = current and return color
sta temp00
inc temp00
lda temp00
and #$0f
cmp #$0d
bpl .wrap
lda temp00
rts
.wrap
lda temp00
sec
sbc #$0c
rts
bomb_bg_animation_table:
.byte $0f,$07,$06,$05,$16,$26,$27,$28,$37,$38,$30
palette_update: subroutine
; shroom
lda shroom_counter
beq .no_shroom_effect
lda wtf
and #$03
bne .no_shroom_effect
ldy #$0e
.shroom_loop
lda pal_bg_3_1,y
jsr palette_next_rainbow_color
sta pal_bg_3_1,y
dey
bpl .shroom_loop
.no_shroom_effect
; fade in
lda state_fade_in
beq .dont_fade_in
jmp palette_fade_in_update
.dont_fade_in
; fade out
lda state_fade_out
beq .dont_fade_out
jmp palette_fade_out_update
.dont_fade_out
; fade from white
lda state_from_white
beq .dont_fade_from_white
jmp palette_fade_from_white_update
.dont_fade_from_white
; bomb
lda bomb_counter
beq .normal_bg
lsr
lsr
tax
lda bomb_bg_animation_table,x
sta pal_uni_bg
.normal_bg
; do normal
ldy #25
.loop
lda pal_uni_bg,y
sta palette_cache,y
dey
bpl .loop
rts
palette_state_reset:
lda #$00
sta state_fade_in
sta state_fade_out
sta state_from_white
rts
palette_fade_in_init: subroutine
; make sure we're not already fading out
lda state_fade_out
bne .init_skip
.init_fade
lda #$00
sta pal_fade_c ; frame counter
lda #$ff
sta state_fade_in
.init_skip
rts
palette_fade_in_update: subroutine
lda pal_fade_c
and #%00110000
eor #%00110000
sta pal_fade_offset
ldx #23
.loop
lda pal_uni_bg,x
sec
sbc pal_fade_offset
bpl .dont_set_black
lda #$0f
.dont_set_black
sta palette_cache,x
dex
bpl .loop
lda pal_fade_c
clc
adc #$03
cmp #$40
bcc .fade_mode_not_done
jsr palette_state_reset
.fade_mode_not_done
sta pal_fade_c
rts
; fade out leads to forced tansition and new state
palette_fade_out_init: subroutine
; a = init callback index
sta pal_fade_target
; make sure we're not already fading out
lda state_fade_out
bne .init_skip
.init_fade
lda #$10
sta pal_fade_c ; frame counter
lda #$ff
sta state_fade_out
.init_skip
rts
palette_fade_out_update: subroutine
lda pal_fade_c
and #%11110000
sta pal_fade_offset
ldx #25
.loop
lda pal_uni_bg,x
sec
sbc pal_fade_offset
bcs .no_reset
lda #$0f
.no_reset
sta palette_cache,x
dex
bpl .loop
lda pal_fade_c
clc
adc #$03
cmp #$60
bcc .fade_mode_not_done
jsr palette_state_reset
lda pal_fade_target
jmp jump_to_subroutine
.fade_mode_not_done
sta pal_fade_c
rts
palette_fade_from_white_update: subroutine
lda pal_fade_c
and #%11110000
sta pal_fade_offset
ldx #23
.loop
lda pal_uni_bg,x
clc
adc pal_fade_offset
cmp #$3f
bcc .dont_set_white
lda #$30
.dont_set_white
sta palette_cache,x
dex
bpl .loop
dec pal_fade_c
dec pal_fade_c
dec pal_fade_c
bpl .fade_mode_not_done
jsr palette_state_reset
.fade_mode_not_done
rts
; 12 + 32 x 7 = 236 cycles
palette_render: subroutine
PPU_SETADDR $3f00
ldx #0
ldy #8
.loop
lda palette_cache
sta PPU_DATA
inx
lda palette_cache,x
sta PPU_DATA
inx
lda palette_cache,x
sta PPU_DATA
inx
lda palette_cache,x
sta PPU_DATA
dey
bne .loop
rts