-
Notifications
You must be signed in to change notification settings - Fork 3
/
sfx.gas
509 lines (420 loc) · 9.36 KB
/
sfx.gas
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
.long
.dc.l codeend-_sfx_start
_sfx_start::
.dsp
.org $f1b140
_internalbuffer = $f1b800
INTERNALQUADS = 256
EXTERNALQUADS = 512
S_LE .ccdef $14 ; PL
U_LE .ccdef $04 ; CC
S_GT .ccdef $18 ; MI
U_GT .ccdef $08 ; CS
S_LT .ccdef $15 ; PL+NE
U_LT .ccdef $05 ; CC+NE
FP .equr r14
scratch .equr r10
scratch2 .equr r11
RETURNVALUE .equr r29
RETURNPOINT .equr r28
MATH_A .equr r27
MATH_B .equr r26
MATH_C .equr r25
MATH_RTS .equr r24
MATH_SIGN .equr r23
movei #codestart,scratch
jump T,(scratch)
nop
;===========================================================================
;
_ClearInternalBuffer:
;
;===========================================================================
movei #_internalbuffer,r0
move r0,r1
move r1,r2
move r2,r3
addq #4,r1
addq #8,r2
addq #12,r3
movei #INTERNALQUADS,r4
moveq #0,r5
clearloop:
store r5,(r0)
addq #16,r0
store r5,(r1)
addq #16,r1
store r5,(r2)
addq #16,r2
store r5,(r3)
subq #1,r4
addqt #16,r3
jr NE,clearloop
nop
jump T,(RETURNPOINT)
nop
;===========================================================================
;
_S_WriteOutSamples:
;
;===========================================================================
sw_source .equr r16
sw_samples .equr r17
sw_dest .equr r18
sw_sample .equr r19
sw_combined .equr r20
sw_zero .equr r21
sw_looppoint .equr r22
sw_mask .equr r23
.extern _sfxsample
load (FP),sw_samples
shlq #2,sw_samples ; in quads
moveq #0,sw_zero
movei #$ffff,sw_mask
movei #_sfxsample,scratch2
load (scratch2),scratch
move scratch,sw_dest
add sw_samples,scratch
add sw_samples,scratch ; 11khz sfx are doubled for 22khz isr
store scratch,(scratch2) ; sfxtime += samples*2
shlq #1,sw_dest
movei #$1fff,scratch
and scratch,sw_dest
movei #$1f0000,scratch
add scratch,sw_dest ; sw_dest = externbuffer[sfxtime*2]
movei #_internalbuffer,sw_source
movei #satloop,sw_looppoint
load (sw_source),sw_sample ; delay slotted
satloop:
store sw_zero,(sw_source)
addq #4,sw_source
sharq #8,sw_sample
sat16s sw_sample
and sw_mask,sw_sample
; double samples for 22 khz isr
move sw_sample,sw_combined
shlq #16,sw_combined
add sw_sample,sw_combined
store sw_combined,(sw_dest)
addqmod #4,sw_dest
subq #1,sw_samples
jump NE,(sw_looppoint)
load (sw_source),sw_sample ; delay slot
jump T,(RETURNPOINT)
nop
;============================================================================
;PaintChannel (unsigned *samples, int *dest, int count, int volume)
_PaintChannel:
;============================================================================
pc_source .equr r0
pc_channel .equr r1
pc_count .equr r3
pc_volume .equr r4
pc_const128 .equr r6
pc_looppoint_p .equr r7
pc_1 .equr r8
pc_2 .equr r9
pc_3 .equr r10
pc_4 .equr r11
pc_1a .equr r17
pc_2a .equr r18
pc_3a .equr r19
pc_4a .equr r20
pc_samples .equr r25
load (FP),pc_source
load (FP+1),pc_channel
load (FP+2),pc_count
load (FP+3),pc_volume
movei #looppoint,pc_looppoint_p
movei #128,pc_const128
load (pc_source),pc_samples
movei #unpack,pc_1
jump T,(pc_1)
addq #4,pc_source
looppoint:
sub pc_const128,pc_1a
imult pc_volume,pc_1a
sub pc_const128,pc_2a
imult pc_volume,pc_2a
sub pc_const128,pc_3a
imult pc_volume,pc_3a
sub pc_const128,pc_4a
imult pc_volume,pc_4a
load (pc_channel),pc_1
addq #4,pc_channel
load (pc_channel),pc_2
addq #4,pc_channel
load (pc_channel),pc_3
addq #4,pc_channel
load (pc_channel),pc_4
subq #12,pc_channel
add pc_1a,pc_1
add pc_2a,pc_2
add pc_3a,pc_3
add pc_4a,pc_4
store pc_1,(pc_channel)
addq #4,pc_channel
store pc_2,(pc_channel)
addq #4,pc_channel
store pc_3,(pc_channel)
addq #4,pc_channel
store pc_4,(pc_channel)
addq #4,pc_channel
; unpack next block of samples
unpack:
move pc_samples,pc_4a ; start using samples
load (pc_source),pc_samples ; start next sample load
addq #4,pc_source
move pc_4a,pc_1a
shrq #24,pc_1a
move pc_4a,pc_2a
shlq #8,pc_2a
shrq #24,pc_2a
move pc_4a,pc_3a
shlq #16,pc_3a
shrq #24,pc_3a
shlq #24,pc_4a
shrq #24,pc_4a
subq #1,pc_count
jump PL,(pc_looppoint_p)
nop
jump T,(RETURNPOINT)
nop
codestart:
; unfuckdsp output -- add loads before external dsp stores
;====================
_MixSfx::
;3 dag registers 7 register variables
;localoffset:16 regoffset:20 argoffset:64
;====================
movei #64,scratch
sub scratch,FP
movei #_ClearInternalBuffer,r0
store r28,(FP+5) ; push ;(RETURNPOINT)
store r21,(FP+6) ; push ;(count)
store r20,(FP+7) ; push ;(stopquad)
store r19,(FP+8) ; push ;(startquad)
store r18,(FP+9) ; push ;(mixcount)
store r17,(FP+10) ; push ;(mixstop)
store r16,(FP+11) ; push ;(mixstart)
movei #L60,RETURNPOINT
jump T,(r0)
store r15,(FP+12) ; delay slot push ;(channel)
L60:
load (FP+6),r21 ; pop ;(count)
load (FP+7),r20 ; pop ;(stopquad)
load (FP+8),r19 ; pop ;(startquad)
load (FP+9),r18 ; pop ;(mixcount)
load (FP+10),r17 ; pop ;(mixstop)
load (FP+11),r16 ; pop ;(mixstart)
load (FP+12),r15 ; pop ;(channel)
load (FP+5), RETURNPOINT ; pop
move FP,r0
addq #16,r0 ; &samplequad
movei #_samplecount,r1
load (r1),r1
sharq #3,r1
load (r0),r30 ; FUCKING dsp!
or r30,r30 ; FUCKING dsp!
store r1,(r0)
movei #_finalquad,r1
load (r1),r2
move r2,r19 ;(startquad)
load (r0),r0
movei #512,r2
add r2,r0
load (r1),r30 ; FUCKING dsp!
or r30,r30 ; FUCKING dsp!
store r0,(r1)
load (r1),r0
sub r19,r0 ;(startquad)
cmp r0,r2
movei #L42,scratch
jump CC,(scratch)
nop
movei #_finalquad,r0
load (r0),r0
movei #512,r1
sub r1,r0
move r0,r19 ;(startquad)
L42:
movei #_sfxsample,r0
move r19,r1 ;(startquad)
shlq #3,r1
load (r0),r30 ; FUCKING dsp!
or r30,r30 ; FUCKING dsp!
store r1,(r0)
movei #L45,r0
jump T,(r0)
nop
L44:
movei #_finalquad,r0
load (r0),r0
sub r19,r0 ;(startquad)
move r0,r21 ;(count)
movei #256,r0
cmp r21,r0 ;(count)
movei #L47,scratch
jump PL,(scratch)
nop
movei #256,r0
move r0,r21 ;(count)
L47:
move r21,r0 ;(count)
move r19,r1 ;(startquad)
add r0,r1
move r1,r20 ;(stopquad)
movei #_sfxchannels,r0
move r0,r15 ;(channel)
movei #L52,r0
jump T,(r0)
nop
L49:
move r15,r0 ;(channel)
addq #4,r0
load (r0),r0
move r0,r16 ;(mixstart)
cmp r16,r19 ;(mixstart)(startquad)
movei #L54,scratch
jump EQ,(scratch)
nop
jump CS,(scratch)
nop
move r19,r16 ;(startquad)(mixstart)
L54:
move r15,r0 ;(channel)
addq #8,r0
load (r0),r0
move r0,r17 ;(mixstop)
cmp r17,r20 ;(mixstop)(stopquad)
movei #L56,scratch
jump CC,(scratch)
nop
move r20,r17 ;(stopquad)(mixstop)
L56:
move r17,r0 ;(mixstop)
sub r16,r0 ;(mixstart)
move r0,r18 ;(mixcount)
moveq #1,r0
cmp r18,r0 ;(mixcount)
movei #L58,scratch
jump EQ,(scratch)
nop
jump MI,(scratch)
nop
movei #L50,r0
jump T,(r0)
nop
L58:
move r15,r0 ;(channel)
addq #4,r0
load (r0),r0
move r16,r1 ;(mixstart)
sub r0,r1
movei #-2,r0
sh r0,r1
load (r15),r2 ;(channel)
add r2,r1
store r1,(FP) ; arg[]
move r16,r1 ;(mixstart)
sub r19,r1 ;(startquad)
shlq #3,r1
sh r0,r1
movei #_internalbuffer,r0
add r0,r1
or r1,scratch ; scoreboard bug
store r1,(FP+1) ; arg[]
or r18,scratch ; scoreboard bug ;(mixcount)
store r18,(FP+2) ; arg[] ;(mixcount)
move r15,r0 ;(channel)
addq #12,r0
load (r0),r0
or r0,scratch ; scoreboard bug
store r0,(FP+3) ; arg[]
movei #_PaintChannel,r0
store r28,(FP+5) ; push ;(RETURNPOINT)
store r21,(FP+6) ; push ;(count)
store r20,(FP+7) ; push ;(stopquad)
store r19,(FP+8) ; push ;(startquad)
store r18,(FP+9) ; push ;(mixcount)
store r17,(FP+10) ; push ;(mixstop)
store r16,(FP+11) ; push ;(mixstart)
movei #L61,RETURNPOINT
jump T,(r0)
store r15,(FP+12) ; delay slot push ;(channel)
L61:
load (FP+6),r21 ; pop ;(count)
load (FP+7),r20 ; pop ;(stopquad)
load (FP+8),r19 ; pop ;(startquad)
load (FP+9),r18 ; pop ;(mixcount)
load (FP+10),r17 ; pop ;(mixstop)
load (FP+11),r16 ; pop ;(mixstart)
load (FP+12),r15 ; pop ;(channel)
load (FP+5), RETURNPOINT ; pop
L50:
move r15,r0 ;(channel)
addq #24,r0
move r0,r15 ;(channel)
L52:
move r15,r0 ;(channel)
movei #_sfxchannels+96,r1
cmp r0,r1
movei #L49,scratch
jump U_LT,(scratch)
nop
store r21,(FP) ; arg[] ;(count)
movei #_S_WriteOutSamples,r0
store r28,(FP+5) ; push ;(RETURNPOINT)
store r21,(FP+6) ; push ;(count)
store r20,(FP+7) ; push ;(stopquad)
store r19,(FP+8) ; push ;(startquad)
store r18,(FP+9) ; push ;(mixcount)
store r17,(FP+10) ; push ;(mixstop)
store r16,(FP+11) ; push ;(mixstart)
movei #L62,RETURNPOINT
jump T,(r0)
store r15,(FP+12) ; delay slot push ;(channel)
L62:
load (FP+6),r21 ; pop ;(count)
load (FP+7),r20 ; pop ;(stopquad)
load (FP+8),r19 ; pop ;(startquad)
load (FP+9),r18 ; pop ;(mixcount)
load (FP+10),r17 ; pop ;(mixstop)
load (FP+11),r16 ; pop ;(mixstart)
load (FP+12),r15 ; pop ;(channel)
load (FP+5), RETURNPOINT ; pop
move r20,r19 ;(stopquad)(startquad)
L45:
movei #_finalquad,r0
load (r0),r0
cmp r19,r0 ;(startquad)
movei #L44,scratch
jump U_LT,(scratch)
nop
movei #_soundtics,r0
movei #_samplecount,r1
load (r1),r1
movei #_soundstarttics,r2
load (r2),r2
sub r2,r1
load (r0),r30 ; FUCKING dsp!
or r30,r30 ; FUCKING dsp!
store r1,(r0)
L41:
movei #64,scratch
jump T,(RETURNPOINT)
add scratch,FP ; delay slot
;=======================
.extern _ClearInternalBuffer
.extern _PaintChannel
.extern _internalbuffer
.extern _samplecount
.extern _sfxsample
.extern _soundstarttics
.extern _soundtics
.extern _finalquad
.extern _sfxchannels
.extern _S_WriteOutSamples
.phrase
.68000
codeend: