-
Notifications
You must be signed in to change notification settings - Fork 0
/
apu_sfx.asm
516 lines (469 loc) · 9.92 KB
/
apu_sfx.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
512
513
514
515
516
; zp vars
;sfx_phase_next_counter
; counters to mask other channel audio
;sfx_pu1_counter
;sfx_pu2_counter
;sfx_noi_counter
; table offsets for update subroutines
;sfx_pu2_update_type
;sfx_noi_update_type
; these should only use Pulse 2 and Noise channels
; unless its a non-music moment (like player death)
sfx_test_delegator: subroutine
; a = sound effect id
clc
adc #sfx_test_jump_table_offset
jmp jump_to_subroutine
; sound test 00
sfx_pewpew: subroutine
lda sfx_pu2_counter
bne .no
; pulse 2
lda #%10001111
sta $4004
lda #%10000010
sta $4005
lda rng0
and #$3f
ora #$08
sta $4006
lda #%00010000
sta $4007
lda #0
sta apu_pu2_counter
sta sfx_pu2_update_type
.no
rts
; sound test 01
sfx_player_damage: subroutine
; noise
lda rng0
and #$8f
ora #$0c
sta apu_cache+$e
lda #$10
sta apu_noi_counter
lda #$01
sta apu_noi_envelope
lda #$10
sta sfx_noi_counter
rts
; sound test 02
sfx_player_death: subroutine
; setup pulse 1
lda #%10001111
sta $4000
lda #%10000111
sta $4001
lda #$fc
sta $4002
lda #%00001010
sta $4003
; setup pulse 2
lda #%10001111
sta $4004
lda #%10000111
sta $4005
lda #$fb
sta $4006
lda #%00001001
sta $4007
; setup noise handler
lda #$01
sta sfx_noi_update_type
lda #$00
sta sfx_pu2_update_type
lda #$00
sta sfx_temp00 ; volume
lda #$80
sta sfx_temp01 ; pitch
;sta sfx_noi_counter
rts
sfx_player_death_update: subroutine
lda sfx_temp00 ; vol
lsr
lsr
lsr
lsr
and #%00010000
sta apu_cache+$c
lda sfx_temp01 ; pitch
lsr
lsr
lsr
sta apu_cache+$e
inc sfx_temp01 ; pitch
inc sfx_temp00 ; vol
inc sfx_temp00 ; vol
bne .dont_kill_player_death_sound
lda #$10
sta apu_cache+$c
lda #$00
sta sfx_noi_update_type
.dont_kill_player_death_sound
rts
; sound test 03
sfx_kick:
sfx_enemy_damage: subroutine
lda sfx_pu2_counter
bne .no
; pulse 2
lda #%10001111
sta $4004
lda #%10000010
sta $4005
lda rng0
sta $4006
lda #%00010001
sta $4007
lda #$08
sta sfx_pu2_counter
lda #0
sta sfx_pu2_update_type
.no
rts
; sound test 04
sfx_enemy_death: subroutine
lda #%00011111
sta apu_cache+$c
lda #$0f
sta apu_cache+$e
lda #$01
sta apu_noi_envelope
lda #$02
sta sfx_noi_update_type
lda #$10
sta apu_noi_counter
sta sfx_noi_counter
rts
sfx_enemy_death_update: subroutine
lda apu_cache+$c
sta apu_cache+$e
and #%00001111
beq sfx_noi_update_clear
rts
sfx_noi_update_clear: subroutine
lda #%00010000
sta apu_cache+$c
lda #$00
sta sfx_noi_update_type
rts
; sound test 05
sfx_powerup_hit: subroutine
lda #$82
sta apu_cache+$e
lda #$20
sta apu_noi_counter
lda #$03
sta apu_noi_envelope
lda #$16
sta sfx_noi_counter
rts
; sound test 06
sfx_powerup_bomb: subroutine
lda #44
sta bomb_counter
sta sfx_noi_counter
lda #$04
sta sfx_noi_update_type
rts
sfx_powerup_bomb_update: subroutine
lda #%00011111
sta apu_cache+$c
lda bomb_counter
and #%00001111
ora #%00000011
sta apu_cache+$e
; set powerup counter
lda bomb_counter
beq sfx_noi_update_clear
rts
; sound test 07
sfx_powerup_mushroom: subroutine
; set powerup counter
lda #$7f
sta shroom_counter
; slow pu2 sweep up
lda #%10001111
sta $4004
lda #%10101010
sta $4005
lda audio_root_tone
tax
lda periodTableLo,x
sta $4006
lda periodTableHi,x
ora #%01000000
sta $4007
lda #$10
sta sfx_pu2_counter
rts
; sound test 08
sfx_powerup_mask: subroutine
; fast pu2 sweep up
lda #%10001111
sta $4004
lda #%11111001
sta $4005
lda rng0
and #$3f
ora #$08
sta $4006
lda #%00010100
sta $4007
lda #$10
sta sfx_pu2_counter
rts
; sound test 09
sfx_powerup_1up: subroutine
; imperial jingle
; root note -- x - x x X
lda #$00
sta sfx_temp00
lda #$05
sta sfx_pu2_update_type
rts
sfx_powerup_1up_update: subroutine
lda sfx_temp00
beq .trigger_lower_note
cmp #$10
beq .trigger_lower_note
cmp #$18
beq .trigger_lower_note
cmp #$20
beq .trigger_higher_note
bne .done
.trigger_lower_note
lda audio_root_tone
clc
adc #$18
bne .trigger_note
.trigger_higher_note
lda #$00
sta sfx_pu2_update_type
lda audio_root_tone
clc
adc #$24
.trigger_note
tax
lda #%10000011
sta $4004
lda #$00
sta $4005
lda periodTableLo,x
sta $4006
lda periodTableHi,x
ora #%01000000
sta $4007
lda #$10
sta sfx_pu2_counter
.done
inc sfx_temp00
rts
; sound test 0a
sfx_powerup_battery_25: subroutine
lda #$08
sta sfx_temp00 ; counter
bne sfx_powerup_battery_set_update_type
; sound test 0b
sfx_powerup_battery_50: subroutine
lda #$04
sta sfx_temp00 ; counter
bne sfx_powerup_battery_set_update_type
; sound test 0c
sfx_powerup_battery_100: subroutine
lda #$00
sta sfx_temp00 ; counter
sfx_powerup_battery_set_update_type:
lda #$03
sta sfx_pu2_update_type
rts
sfx_powerup_battery_arp:
.byte #$18, #$1c, #$1f, #$24
sfx_powerup_battery_update: subroutine
lda sfx_temp00
and #%00000011
bne .dont_trigger
lda sfx_temp00
lsr
lsr
cmp #$04
beq .end_sound
tax
lda audio_root_tone
clc
adc sfx_powerup_battery_arp,x
tax
lda #%10000011
sta $4004
lda #$00
sta $4005
lda periodTableLo,x
sta $4006
lda periodTableHi,x
ora #%01000000
sta $4007
lda #$10
sta sfx_pu2_counter
.dont_trigger
inc sfx_temp00 ; counter
rts
.end_sound
lda #$00
sta sfx_pu2_update_type
rts
; sound test 0d
sfx_shoot_dart: subroutine
; pulse 1
lda #%00001111
sta $4000
lda #%10000011
sta $4001
lda rng0
and #$3f
ora #$08
sta $4002
lda #%00001000
sta $4003
lda #$10
sta sfx_pu1_counter
rts
; sound test 0e
sfx_shoot_bullet: subroutine
lda #%00011111
sta apu_cache+$c
lda wtf
and #$03
clc
adc #$09
sta apu_cache+$e
lda #$03
sta apu_noi_envelope
lda #$20
sta apu_noi_counter
rts
; sound test 0f
sfx_rng_chord: subroutine
; used hardware enevelope was 1 second
; ~ 64 frame fade
; triangle cuts off at 32 frames
; setup pulse 1 + 2
lda #$40
sta apu_pu1_counter
sta apu_pu2_counter
lda #$00
sta apu_pu1_envelope
sta apu_pu2_envelope
; pulse 1 pitch
lda rng0
and #%00001111
clc
adc #$10
tax
ldy #$02
jsr apu_set_pitch
; pulse 2 pitch
lda rng1
and #%00001111
clc
adc #$08
tax
ldy #$06
jsr apu_set_pitch
; setup triangle
lda #$20
sta apu_tri_counter
lda rng2
and #%00001111
clc
adc #$08
tax
ldy #$0a
jsr apu_set_pitch
rts
; sound test 10
sfx_phase_next: subroutine
lda #$00
sta sfx_phase_next_counter
lda #$06
sta sfx_pu2_update_type
rts
sfx_phase_next_update: subroutine
lda sfx_phase_next_counter
beq .trigger_first
cmp #$04
beq .trigger_last
bne .done
.trigger_first
lda #$40
sta apu_pu2_counter
lda #$20
sta sfx_pu2_counter
lda #2
sta apu_pu2_envelope
lda audio_root_tone
clc
adc #24 ; two octaves
tax
ldy #6
jsr apu_set_pitch
bne .done
.trigger_last
lda #$40
sta apu_pu1_counter
sta apu_pu2_counter
lda #$20
sta sfx_pu2_counter
lda #2
sta apu_pu1_envelope
sta apu_pu2_envelope
lda audio_root_tone
clc
adc #31 ; two octaves + 5th
tax
ldy #2
jsr apu_set_pitch
ldy #6
jsr apu_set_pitch
inc apu_cache+6
inc apu_cache+6
inc apu_cache+6
; trigger next phase and kill sfx
lda #$00
sta sfx_pu2_update_type
.done
inc sfx_phase_next_counter
rts
; sound test 11
sfx_snare: subroutine
lda #$a
sta apu_cache+$e
lda #$06
sta apu_noi_counter
lda #$05
sta apu_noi_envelope
rts
; sound test 12
sfx_hat: subroutine
lda sfx_noi_counter
bne .no
lda apu_rng1
and #3
sta apu_cache+$e
lda #$e
sta apu_noi_counter
lda #$04
sta apu_noi_envelope
.no
rts
; sound test 13
sfx_ghost_snare: subroutine
lda rng2
and #$01
adc #$0b
sta apu_cache+$e
lda #$04
sta apu_noi_counter
lda #$05
sta apu_noi_envelope
rts