-
Notifications
You must be signed in to change notification settings - Fork 0
/
apu_song.asm
511 lines (476 loc) · 9.6 KB
/
apu_song.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
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
song_rng_chord EQM $00
song_sick_dingle EQM $01
song_in_game EQM $02
song_boss_intro EQM $03
song_boss_fight EQM $04
song_game_over EQM $05
song_end_bad EQM $06
song_end_ok EQM $07
song_end_good EQM $08
song_update: subroutine
lda options_music_on
bne .music_on
rts
.music_on
lda audio_song_id
clc
adc #song_update_jump_table_offset
jmp jump_to_subroutine
song_start: subroutine
; a = song id
sta audio_song_id
bne .not_rng_chords
jsr sfx_rng_chord
rts
.not_rng_chords
lda #$01
sta options_music_on
cmp audio_song_id
bne .normal
; sick dingle music init
lda #$70
sta audio_frame_counter
lda #$02
sta audio_root_tone
lda #$04
sta audio_pattern_pos
lda #$30
sta apu_rng1
lda #$44
sta apu_rng0
rts
.normal
lda #0
sta audio_frame_counter
sta audio_root_tone
sta audio_pattern_pos
jsr apu_rng_reset
rts
song_stop: subroutine
lda #$00
sta options_music_on
rts
song_unstop: subroutine
lda #$01
sta options_music_on
rts
song_01_lda_note: subroutine
; x = note offset
; returns note id in a
lda apu_temp
beq .octoscale
.majorpentscale
lda majpentscale,x
rts
.octoscale
lda octoscale,x
rts
; sick dingle
song_01: subroutine
lda #$11
clc
adc audio_frame_counter
sta audio_frame_counter
bcc .do_nothing
lda #$0a
sta audio_frame_counter
lda audio_pattern_pos
bne .trigger_note
; change the note
lda #$08
sta audio_pattern_pos
.update_root_note
lda apu_rng1
and #%00000111
tax
jsr song_01_lda_note
sta audio_root_tone
.trigger_note
; pulse 1
lda apu_rng1
and #%0000001
bne .no_pulse_lead
lda #$20
sta apu_pu1_counter
lda #$00
sta apu_pu1_envelope
lda apu_rng0
and #%00000111
clc
adc audio_root_tone
tax
jsr song_01_lda_note
clc
adc #12
tax
ldy #$02
jsr apu_set_pitch
.no_pulse_lead
; pulse 2
lda sfx_pu2_counter
bne .no_pulse_rhythm
lda #$04
and apu_rng1
bit audio_pattern_pos
beq .no_pulse_rhythm
lda #$10
sta apu_pu2_counter
lda #$00
sta apu_pu2_envelope
ldx audio_root_tone
jsr song_01_lda_note
clc
adc #24
tax
ldy #$06
jsr apu_set_pitch
.no_pulse_rhythm
; triangle
lda #$03
sta apu_tri_counter
lda audio_root_tone
clc
adc #$18
tax
ldy #$0a
jsr apu_set_pitch
dec audio_pattern_pos
.do_nothing
lda #$00
sta apu_temp
rts
; in game
song_02: subroutine
lda wtf
and #$07
beq .do_this_shit
rts
.do_this_shit
; options screen decrease player health
lda state_render_addr
cmp #state_render_jump_table_offset+1
bne .not_menu_screens
dec player_health
.not_menu_screens
; triangle
lda audio_pattern_pos
eor rng1
and #7
beq .no_triangle
; change note length based on health?
lda player_health
eor #$ff
lsr
lsr
lsr
lsr
lsr
adc #$02
;lda #$05 ; original length
sta apu_tri_counter
lda audio_root_tone
clc
adc #24
sta apu_temp
lda audio_pattern_pos
and #1
bne .no_octave
lda apu_temp
adc #12
sta apu_temp
.no_octave
ldx apu_temp
lda octoscale,x
ldy #$0a
jsr apu_set_pitch
.no_triangle
; pulse lead
; lda sfx_pu1_counter
; bne .no_pulse_lead
; lda sfx_pu2_counter
; bne .no_pulse_lead
; lda apu_rng0
; and #$01
;bne .no_pulse_lead
; lda apu_rng1
; and #%00000001
; beq .no_pulse_lead
; lda #$0e
; sta apu_pu1_counter
; lda #$0c
; sta apu_pu2_counter
; lda #$05
; sta apu_pu1_envelope
; sta apu_pu2_envelope
; lda apu_rng0
; and #%00000111
; clc
; adc audio_root_tone
; tax
; lda octoscale,x
; clc
; adc #24
; tax
; ldy #$02
; jsr apu_set_pitch
; txa
; adc #19
; tax
; ldy #$06
; jsr apu_set_pitch
;.no_pulse_lead
; kick
lda audio_pattern_pos
bne .no_kick
jsr sfx_kick
.no_kick
; check for sfx noise
lda sfx_noi_counter
bne .no_noise
; hats
lda apu_rng0
and #6
beq .no_hat
jsr sfx_hat
.no_hat
; ghost snare
lda rng0
and #$c
bne .no_g_snare
jsr sfx_ghost_snare
.no_g_snare
; snare
lda audio_pattern_pos
cmp #6
bne .no_snare
.do_snare
jsr sfx_snare
.no_snare
.no_noise
; next tic
inc audio_pattern_pos
lda audio_pattern_pos
cmp #12
bne .done
lda apu_rng0
and #$07
sta audio_root_tone
lda #0
sta audio_pattern_pos
inc audio_frame_counter
lda #24
cmp audio_frame_counter
bne .done
jsr apu_rng_reset
lda #0
sta audio_frame_counter
.done
rts
; boss intro
song_03: subroutine
lda wtf
and #$07
bne .done
lda audio_pattern_pos
cmp #$08
bne .next_step
jsr song_stop
rts
.next_step
inc audio_pattern_pos
lda #0
sta apu_pu1_envelope
sta apu_pu2_envelope
lda #$40
sta apu_pu1_counter
sta apu_pu2_counter
sta apu_tri_counter
.set_pitch
inc audio_root_tone
lda audio_root_tone
clc
adc #4
sta apu_temp
tax
lda octoscale,x
adc #12
tax
ldy #2
jsr apu_set_pitch
lda apu_temp
adc #15
tax
ldy #6
jsr apu_set_pitch
ldy #10
jsr apu_set_pitch
; set noise
lda #$f
sbc audio_pattern_pos
sta apu_cache+$e
lda #$00
sta apu_noi_envelope
lda #$40
sta apu_noi_counter
.done
rts
; boss fight
song_04: subroutine
lda audio_frame_counter
cmp #5
beq .do_all_the_stuff
jmp .done
.do_all_the_stuff
lda #0
sta audio_frame_counter
inc audio_pattern_pos
lda audio_pattern_pos
cmp #18
bne .dont_loop
.do_loop
; TENSION ANTI_MELODY
lda audio_pattern_num
and #$04
bne .root_raise
.root_lower
inc audio_root_tone
bne .root_done
.root_raise
dec audio_root_tone
.root_done
lda #0
sta audio_pattern_pos
inc audio_pattern_num
.dont_loop
; KICK (pulse 2)
lda audio_pattern_pos
bne .no_kick
jsr sfx_kick
.no_kick
; SNARE
lda audio_pattern_pos
cmp #10
beq .snare
lda rng0
and #7
beq .snare
bne .no_snare
.snare
jsr sfx_snare
.no_snare
; TENSION ANTI_MELODY (pulse 1)
lda sfx_pu1_counter
bne .no_melody
lda #5
sta apu_pu1_envelope
lda #$05
sta apu_pu1_counter
ldx audio_root_tone
lda apu_rng1
lsr
and #$08
beq .change_root
txa
bne .stay_root
.change_root
lda apu_rng0
and #$07
sta temp00
txa
adc temp00
.stay_root
clc
adc #36
tax
ldy #$02
jsr apu_set_pitch
.no_melody
; BASSLINE
ldx audio_pattern_pos
ldy song_04_length,x
beq .done
; chance of staccato
lda apu_rng0
and #$0c
bne .full_length
ldy #$02
.full_length
sty apu_tri_counter
lda song_04_pitch,x
clc
adc #24
sta apu_temp
lda audio_pattern_num
and #4
lsr
adc apu_temp
tax
ldy #10
jsr apu_set_pitch
; hats in unison with bassline
jsr sfx_hat
; we're done
.done
inc audio_frame_counter
rts
song_04_pitch:
byte 12,0,17,0,0,12,12,0,17,0,0,15,0,0,13,0,0,12
song_04_length:
byte 18,0,10,0,0, 3,18,0,10,0,0, 8,0,0, 8,0,0, 3
; game over
song_05: subroutine
lda audio_frame_counter
cmp #$ff
bne .do_normal
lda #$00
sta ppu_mask_emph
rts
.do_normal
jsr apu_bend_down
jsr apu_bend_down
lda audio_frame_counter
cmp #$70
beq .do_chord
cmp #$40
beq .do_chord
cmp #$30
beq .do_chord
cmp #$10
beq .do_chord
lda audio_frame_counter
bne .done
jsr sfx_snare
.do_chord
jsr sfx_rng_chord
jsr ppu_mess_emph
inc ppu_mask_emph
.done
inc audio_frame_counter
rts
; ending bad
song_06: subroutine
; rng chord about every 2 seconds (bends down)
jsr apu_bend_down
jsr apu_bend_down
lda audio_frame_counter
and #$7d
bne .no_chord
jsr sfx_rng_chord
.no_chord
inc audio_frame_counter
rts
; ending ok
song_07: subroutine
; sick dingle but different seed and bends down
jsr apu_bend_down
jsr song_01
rts
; ending good
song_08: subroutine
inc apu_temp
jsr song_01
rts
WHOOPS:
jsr WaitSync
jsr WaitSync
jmp apu_init