-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspc700.asm
908 lines (723 loc) · 14.5 KB
/
spc700.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
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
arch snes.smp
define musicData $e000 ;fixed location for music data
;I/O registers
define TEST $f0
define CTRL $f1
define ADDR $f2
define DATA $f3
define CPU0 $f4
define CPU1 $f5
define CPU2 $f6
define CPU3 $f7
define TMP0 $f8
define TMP1 $f9
define T0TG $fa
define T1TG $fb
define T2TG $fc
define T0OT $fd
define T1OT $fe
define T2OT $ff
;DSP channel registers, x0..x9, x is channel number
define DSP_VOLL $00
define DSP_VOLR $01
define DSP_PL $02
define DSP_PH $03
define DSP_SRCN $04
define DSP_ADSR1 $05
define DSP_ADSR2 $06
define DSP_GAIN $07
define DSP_ENVX $08
define DSP_OUTX $09
;DSP registers for global settings
define DSP_MVOLL $0c
define DSP_MVOLR $1c
define DSP_EVOLL $2c
define DSP_EVOLR $3c
define DSP_KON $4c
define DSP_KOF $5c
define DSP_FLG $6c
define DSP_ENDX $7c
define DSP_EFB $0d
define DSP_PMON $2d
define DSP_NON $3d
define DSP_EON $4d
define DSP_DIR $5d
define DSP_ESA $6d
define DSP_EDL $7d
define DSP_C0 $0f
define DSP_C1 $1f
define DSP_C2 $2f
define DSP_C3 $3f
define DSP_C4 $4f
define DSP_C5 $5f
define DSP_C6 $6f
define DSP_C7 $7f
;vars
define D_TEMP $00
define D_SYNC $08
define D_BUFPTR $09
define D_KON $0a
define D_KOF $0b
define D_STEREO $0c
define M_ENABLE $10 ;byte
define M_ROW $11 ;byte
define M_ORDPTR_L $12 ;word
define M_ORDPTR_H $13
define M_ORDINC $14 ;byte
define M_CHCUR0x $15 ;byte
define M_CHCURx0 $16 ;byte
define M_CHOFF $17 ;byte
define M_UPDROW $18 ;byte
define M_SPEED $19 ;byte
define M_ORDBEGIN_L {musicData}
define M_ORDBEGIN_H {musicData}+1
define M_ORDLOOP_L {musicData}+2
define M_ORDLOOP_H {musicData}+3
define M_CHANNELS {musicData}+4
define M_INITSPEED {musicData}+5
define M_PATTERNS_L {musicData}+6
define M_PATTERNS_H {musicData}+7
define M_CHSIZE $0b ;11 bytes per channel
define M_CH0 $20
define M_CH1 {M_CH0}+{M_CHSIZE}
define M_CH2 {M_CH1}+{M_CHSIZE}
define M_CH3 {M_CH2}+{M_CHSIZE}
define M_CH4 {M_CH3}+{M_CHSIZE}
define M_CH5 {M_CH4}+{M_CHSIZE}
define M_CH6 {M_CH5}+{M_CHSIZE}
define M_CH7 {M_CH6}+{M_CHSIZE}
define D_BUFFER $80
;offsets for music channel vars
define CH_FRAME $00
define CH_SPEED $01
define CH_PTR_L $02 ;word
define CH_PTR_H $03
define CH_WAIT $04 ;byte
define CH_VOL $05 ;byte
define CH_PAN $06 ;byte
define CH_NOTE $07 ;byte
define CH_VIBOFF $08 ;byte
define CH_VIBINC $09 ;byte
define CH_VIBMUL $0a ;byte
org 0
base $0200
start:
clp
ldx #0
stx {D_KON}
stx {D_KOF}
stx {D_STEREO}
stx {M_ENABLE}
dex
txs
lda {CPU0} ;read current value of cpu0, it is used as strobe
sta {D_SYNC}
jsr bufClear
setState:
ldx #0 ;initialize registers
.1:
lda initDataSeq,x
beq .2
sta {ADDR}
inx
lda initDataSeq,x
sta {DATA}
inx
bra .1
.2:
lda #(8000/100) ;8000/80=100hz
sta {T0TG}
lda #$81 ;enable timer 0 and IPL
sta {CTRL}
mainLoop:
waitForTimer:
jsr checkCommand
lda {T0OT}
beq waitForTimer
jsr updatePlayer
bra mainLoop
checkCommand:
lda {CPU0} ;wait until cpu0 is changed
cmp {D_SYNC}
bne .read
rts
.read:
sta {D_SYNC} ;remember for next time
sta {CPU0} ;confirm strobe
lda {CPU1} ;read command code
pha
and #$0f
tay ;channel for sound effect commands
pla
lsr
lsr
lsr
and #$0e
tax
jmp (cmdList,x)
cmdStereo:
lda {CPU2}
sta {D_STEREO}
rts
cmdVolume:
lda {CPU2}
ldx #{DSP_MVOLL}
stx {ADDR}
sta {DATA}
ldx #{DSP_MVOLR}
stx {ADDR}
sta {DATA}
rts
cmdMusStop:
jsr bufClear
ldx #0
stx {M_ENABLE}
.mute:
jsr keyOffBuf
inx
cpx {M_CHANNELS}
bne .mute
lda {D_KOF}
eor #$ff
and {D_KON}
sta {D_KON}
jmp keyOffApply
cmdMusPlay:
lda #1
sta {M_ENABLE}
jmp musicInit
cmdSfxPlay:
cpy {M_CHANNELS} ;don't play effects on music channels
bcs .play
rts
.play:
lda #{M_CHSIZE} ;get channel offset
mul
clc
adc #{M_CH0}
tax
lda {CPU2}
asl
tay
lda soundData,y
clc
adc #soundData&255
sta {CH_PTR_L},x
lda soundData+1,y
adc #soundData/256
sta {CH_PTR_H},x
lda #0
sta {CH_WAIT},x
sta {CH_NOTE},x
sta {CH_VIBMUL},x
sta {CH_VIBINC},x
sta {CH_FRAME},x
lda #6
sta {CH_SPEED},x
lda {CPU3}
sta {CH_PAN},x
lda #$3f
sta {CH_VOL},x
rts
cmdReload:
jmp $ffc0
;reads variables from music data (it is at fixed location)
;reset channels variables
musicInit:
ldy {M_CHANNELS} ;get order pos width from music data, it is channels+1
sty {M_ORDINC}
inc {M_ORDINC}
lda {M_ORDBEGIN_L} ;get initial order list pointer
clc
adc #{musicData}&255
sta {M_ORDPTR_L}
lda {M_ORDBEGIN_H}
adc #{musicData}/256
sta {M_ORDPTR_H}
ldx #{M_CH0} ;initialize channels vars
.set:
lda #0
sta {CH_WAIT},x
sta {CH_NOTE},x
sta {CH_VIBMUL},x
sta {CH_VIBINC},x
sta {CH_FRAME},x ;reset frame counter
sta {CH_SPEED},x ;disable channel
lda #$80
sta {CH_PAN},x
lda #$3f
sta {CH_VOL},x
txa
clc
adc #{M_CHSIZE}
tax
dey
bne .set
lda #$ff ;keyoff for all the channels
sta {D_KOF}
lda #0 ;reset frame counter
sta {D_KON}
lda {M_INITSPEED} ;set initial speed
sta {M_SPEED}
;rts ;no rts because jsr musicUpdateOrder is needed for init
;move to the next order list position
define T_CHCNT $00
updateOrder:
lda {M_CHANNELS} ;read pattern pointers into channels vars
sta {T_CHCNT}
ldy #0
lda #{M_CH0}
sta {M_CHOFF}
.read:
lda ({M_ORDPTR_L}),y
iny
asl
tax
lda {M_PATTERNS_L},x
clc
adc #{musicData}&255
pha
lda {M_PATTERNS_H},x
adc #{musicData}/256
ldx {M_CHOFF}
sta {CH_PTR_H},x
pla
sta {CH_PTR_L},x
txa
clc
adc #{M_CHSIZE}
sta {M_CHOFF}
dec {T_CHCNT}
bne .read
lda ({M_ORDPTR_L}),y;read order position length
sta {M_ROW}
iny
lda ({M_ORDPTR_L}),y;check if next position is end of the order list
cmp #$ff
bne .next
lda {M_ORDLOOP_L} ;load loop position
clc
adc #{musicData}&255
sta {M_ORDPTR_L}
lda {M_ORDLOOP_H}
adc #{musicData}/256
sta {M_ORDPTR_H}
rts
.next:
clc ;move to the next position
lda {M_ORDPTR_L}
adc {M_ORDINC}
sta {M_ORDPTR_L}
lda {M_ORDPTR_H}
adc #0
sta {M_ORDPTR_H}
rts
;run one frame of music player
updatePlayer:
jsr bufApply ;apply register writes from previous frame
jsr keyOnApply ;apply keyon from previous frame
lda #0 ;process all the channels, some of them for music, some for sound
sta {M_CHCUR0x}
sta {M_CHCURx0}
sta {M_UPDROW}
lda #{M_CH0}
sta {M_CHOFF}
.loop:
jsr updateChannel
lda {M_CHOFF}
clc
adc #{M_CHSIZE}
sta {M_CHOFF}
lda {M_CHCURx0}
clc
adc #$10
sta {M_CHCURx0}
inc {M_CHCUR0x}
lda {M_CHCUR0x}
cmp #8
bne .loop
jsr keyOffApply ;apply keyoff, it always one frame earlier
lda {M_UPDROW}
beq .noRow
dec {M_ROW}
bne .noRow
jsr updateOrder
.noRow:
rts
;update one channel
define T_PTNPTR_L $00 ;word
define T_PTNPTR_H $01
define T_CHVOLL $02
define T_CHVOLR $03
define T_PITCH_OFF_L $04
define T_PITCH_OFF_H $05
updateChannel:
ldx {M_CHOFF}
lda {M_CHCUR0x}
cmp {M_CHANNELS}
bcc .checkMus
lda {CH_SPEED},x ;if speed is 0, channel is inactive
bne .active
rts
.checkMus:
lda {M_ENABLE}
bne .active
rts
.active:
lda {CH_FRAME},x
beq .row
jmp .processVolume
.row:
lda {CH_WAIT},x
beq .noWait
dec {CH_WAIT},x
jmp .processVolume
.noWait:
lda {CH_PTR_H},x
sta {T_PTNPTR_H}
lda {CH_PTR_L},x
sta {T_PTNPTR_L}
.read:
jsr readPtnByte
tay
and #$c0
beq .empty
cmp #$40
beq .volume
cmp #$80
beq .ins
.note:
tya
cmp #$fc
bcs .effect
and #$3f ;it is a note, remember it
asl
ldx {M_CHOFF}
sta {CH_NOTE},x
lda #0
sta {CH_VIBOFF},x
ldx {M_CHCUR0x} ;keyoff and keyon
jsr keyOffBuf
jsr keyOnBuf
jmp .done
.effect:
cmp #$fc
bne .noPitch
jsr readPtnByte ;it is a pitch change without restarting note
and #$3f
asl
ldx {M_CHOFF}
sta {CH_NOTE},x
bra .done
.noPitch:
cmp #$fd
bne .noStop
ldx {M_CHCUR0x} ;it is note cut
jsr keyOffBuf
bra .done
.noStop:
cmp #$fe
bne .noPan
jsr readPtnByte ;it is pan, next byte is value
ldx {M_CHOFF}
sta {CH_PAN},x
bra .read
.noPan:
jsr readPtnByte ;it is speed, next byte is value
ldx {M_CHCUR0x}
cpx {M_CHANNELS}
bcs .setSpeed
sta {M_SPEED}
bra .read
.setSpeed:
ldx {M_CHOFF}
sta {CH_SPEED},x
cmp #0
bne .read
lda {M_CHCUR0x}
jmp keyOffBuf
.empty:
ldx {M_CHOFF}
sty {CH_WAIT},x
bra .done
.volume:
tya
and #$3f
asl
ldx {M_CHOFF}
sta {CH_VOL},x
bra .read
.ins:
tya
and #$3f
pha
lda {M_CHCURx0}
ora #{DSP_SRCN}
tax
pla
jsr bufWrite ;write instrument number
asl ;get offset for parameter tables
tax
lda vibrato+1,x ;get vibrato parameters
pha
lda vibrato,x
pha
lda adsr+1,x ;get adsr parameters
pha
lda adsr,x
pha
lda {M_CHCURx0} ;write adsr parameters
ora #{DSP_ADSR1}
tax
pla
jsr bufWrite
lda {M_CHCURx0}
ora #{DSP_ADSR2}
tax
pla
jsr bufWrite
ldx {M_CHOFF} ;write vibrato parameters
pla
sta {CH_VIBINC},x
pla
sta {CH_VIBMUL},x
jmp .read
.done:
ldx {M_CHOFF}
lda {T_PTNPTR_L}
sta {CH_PTR_L},x
lda {T_PTNPTR_H}
sta {CH_PTR_H},x
.processVolume:
lda {D_STEREO}
beq .mono
.stereo:
lda {CH_PAN},x ;calculate left volume
eor #$ff
tay
lda {CH_VOL},x
mul
sty {T_CHVOLL}
ldy {CH_PAN},x ;calculate right volume
lda {CH_VOL},x
mul
sty {T_CHVOLR}
bra .setVol
.mono:
lda {CH_VOL},x
sta {T_CHVOLL}
sta {T_CHVOLR}
.setVol:
lda {M_CHCURx0}
ora #{DSP_VOLL}
tax
lda {T_CHVOLL}
jsr bufWrite
lda {M_CHCURx0}
ora #{DSP_VOLR}
tax
lda {T_CHVOLR}
jsr bufWrite
.processPitch:
ldx {M_CHOFF}
lda {CH_VIBOFF},x
ldy {CH_VIBMUL},x
tax
lda vibratoTable,x
mul
sty {T_PITCH_OFF_L}
lda #0
sta {T_PITCH_OFF_H}
asl {T_PITCH_OFF_L}
rol {T_PITCH_OFF_H}
asl {T_PITCH_OFF_L}
rol {T_PITCH_OFF_H}
ldx {M_CHOFF}
lda {CH_NOTE},x
tax
lda divTable,x
clc
adc {T_PITCH_OFF_L}
pha
lda divTable+1,x
adc {T_PITCH_OFF_H}
pha
lda {M_CHCURx0}
ora #{DSP_PH}
tax
pla
jsr bufWrite
lda {M_CHCURx0}
ora #{DSP_PL}
tax
pla
jsr bufWrite
ldx {M_CHOFF}
lda {CH_VIBOFF},x ;advance vibrato table pointer
clc
adc {CH_VIBINC},x
sta {CH_VIBOFF},x
.processFrameRow:
lda {CH_FRAME},x
bne .noRow
lda {M_CHCUR0x}
cmp {M_CHANNELS}
bcc .processMus
lda {CH_SPEED},x
sta {CH_FRAME},x
bra .noRow
.processMus:
lda {M_SPEED}
sta {CH_FRAME},x
lda #1
sta {M_UPDROW}
.noRow:
dec {CH_FRAME},x
rts
;read one byte from pattern data
;out: A=data, Y=0
readPtnByte:
ldy #0
lda ({T_PTNPTR_L}),y
inc {T_PTNPTR_L}
bne .1
inc {T_PTNPTR_H}
.1:
rts
;clear register writes buffer, just set ptr to 0
bufClear:
str {D_BUFPTR}=#0
rts
;add register write in buffer
;in X=reg, A=value
bufWrite:
pha
txa
ldx {D_BUFPTR}
sta {D_BUFFER},x
inx
pla
sta {D_BUFFER},x
inx
stx {D_BUFPTR}
rts
;send writes from buffer and clear it
bufApply:
lda {D_BUFPTR}
beq .done
ldx #0
.loop:
lda {D_BUFFER},x
sta {ADDR}
inx
lda {D_BUFFER},x
sta {DATA}
inx
cpx {D_BUFPTR}
bne .loop
str {D_BUFPTR}=#0
.done:
rts
;set keyon for needed channel in temp variable
;in: X=channel
keyOnBuf:
lda channelMask,x
ora {D_KON}
sta {D_KON}
rts
;send keyon from temp variable
keyOnApply:
lda {D_KON}
eor #$ff
and {D_KOF}
ldx #{DSP_KOF}
stx {ADDR}
sta {DATA}
sta {D_KOF}
lda #{DSP_KON}
sta {ADDR}
lda {D_KON}
str {D_KON}=#0
sta {DATA}
rts
;set keyoff for needed channel in temp variable
;in: X=channel
keyOffBuf:
lda channelMask,x
ora {D_KOF}
sta {D_KOF}
rts
;send keyoff from temp variable
keyOffApply:
lda #{DSP_KOF}
sta {ADDR}
lda {D_KOF}
sta {DATA}
rts
cmdList:
dw cmdStereo ;0 set stereo mode, 0 or 1
dw cmdVolume ;1 set global volume, 0..127
dw cmdMusStop ;2 stops music
dw cmdMusPlay ;3 restarts music
dw cmdSfxPlay ;4 play sound effect, number 0..127 and pan 0..255
dw cmdReload ;5 call IPL
divTable:
dw $0217,$0237,$0259,$027d,$02a3,$02cb,$02f5,$0322
dw $0352,$0385,$03ba,$03f3,$042f,$046f,$04b2,$04fa
dw $0546,$0596,$05eb,$0645,$06a5,$070a,$0775,$07e6
dw $085f,$08de,$0965,$09f4,$0a8c,$0b2c,$0bd6,$0c8b
dw $0d4a,$0e14,$0eea,$0fcd,$10be,$11bd,$12cb,$13e9
dw $1518,$1659,$17ad,$1916,$1a94,$1c28,$1dd5,$1f9b
dw $217c,$237a,$2596,$27d2,$2a31,$2cb3,$2f5b,$322c
dw $3528,$3851,$3bab,$3f37,$0000,$0000,$0000,$0000
vibratoTable:
db $00,$01,$03,$04,$06,$07,$09,$0a,$0c,$0d,$0f,$11,$12,$14,$15,$17
db $18,$1a,$1b,$1d,$1e,$20,$21,$23,$24,$26,$27,$29,$2a,$2c,$2d,$2f
db $30,$32,$33,$34,$36,$37,$39,$3a,$3b,$3d,$3e,$3f,$41,$42,$43,$45
db $46,$47,$49,$4a,$4b,$4c,$4e,$4f,$50,$51,$52,$54,$55,$56,$57,$58
db $59,$5a,$5b,$5d,$5e,$5f,$60,$61,$62,$63,$64,$65,$66,$66,$67,$68
db $69,$6a,$6b,$6c,$6c,$6d,$6e,$6f,$70,$70,$71,$72,$72,$73,$74,$74
db $75,$75,$76,$77,$77,$78,$78,$79,$79,$79,$7a,$7a,$7b,$7b,$7b,$7c
db $7c,$7c,$7d,$7d,$7d,$7d,$7e,$7e,$7e,$7e,$7e,$7e,$7e,$7e,$7e,$7e
db $7f,$7e,$7e,$7e,$7e,$7e,$7e,$7e,$7e,$7e,$7e,$7d,$7d,$7d,$7d,$7c
db $7c,$7c,$7b,$7b,$7b,$7a,$7a,$79,$79,$79,$78,$78,$77,$77,$76,$75
db $75,$74,$74,$73,$72,$72,$71,$70,$70,$6f,$6e,$6d,$6c,$6c,$6b,$6a
db $69,$68,$67,$66,$66,$65,$64,$63,$62,$61,$60,$5f,$5e,$5d,$5b,$5a
db $59,$58,$57,$56,$55,$54,$52,$51,$50,$4f,$4e,$4c,$4b,$4a,$49,$47
db $46,$45,$43,$42,$41,$3f,$3e,$3d,$3b,$3a,$39,$37,$36,$34,$33,$32
db $30,$2f,$2d,$2c,$2a,$29,$27,$26,$24,$23,$21,$20,$1e,$1d,$1b,$1a
db $18,$17,$15,$14,$12,$11,$0f,$0d,$0c,$0a,$09,$07,$06,$04,$03,$01
channelMask:
db $01,$02,$04,$08,$10,$20,$40,$80
initDataSeq:
db {DSP_FLG} ,%01100000;mute, no echo
db {DSP_PMON} ,0 ;no pitch modulation
db {DSP_NON} ,0 ;no noise
db {DSP_EON} ,0 ;no echo
db {DSP_ESA} ,255 ;echo at highest page
db {DSP_EDL} ,0 ;minimal length
db {DSP_DIR} ,(dir>>8) ;address of sample dir
db {DSP_MVOLL},127 ;global volume to the max
db {DSP_MVOLR},127
db {DSP_EVOLL},0 ;echo volume to zero
db {DSP_EVOLR},0
db {DSP_FLG} ,%00100000;no mute, no echo
db {DSP_KOF} ,255 ;all keys off
db 0
;macro for samples
macro sample ptr,loop
dw {ptr}
dw {ptr}+{loop}
endmacro
macro adsr ar,dr,sl,sr
db $80|{ar}|({dr}<<4)
db {sr}|({sl}<<5)
endmacro
macro vib speed,depth
db {speed}
db {depth}
endmacro
org $0600 ;$0800 in memory
incsrc "sound\samples.asm"
soundData:
incbin "sound\sounds.bin"