Oops.
[AROS-Contrib.git] / Games / Doom / doomsound.library.060.s
blob69e4f901748c4620a0c4982dd650551232c25257
1 ;------------------------------------------------------------------------
2 ; Sound Library for DOOM - by Joseph Fenton
4 ; Functions:
5 ; Sfx_SetVol - pass in the new sound effects volume in d0.
6 ; Sfx_Start - pass in new sound effect to play. a0 = wave,
7 ; d0 = cnum, d1 = pitch, d2 = vol, d3 = sep, d4 =
8 ; length.
9 ; Sfx_Update - pass in new settings for a sfx. a0 = data,
10 ; d0 = cnum, d1 = pitch, d2 = vol, d3 = sep.
11 ; Sfx_Stop - stop a playing sound effect. d0 = cnum.
12 ; Sfx_Done - check if sound effect playing. d0 = cnum; returns
13 ; d0 = 0 if not playing/current index if playing.
14 ; Mus_SetVol - pass in the new music volume in d0.
15 ; Mus_Register - pass in pointer to MUS data to register in
16 ; a0. Returns handle in d0.
17 ; Mus_Unregister - pass in handle to music to unregister in d0.
18 ; Mus_Play - pass in handle to music to start playing in d0,
19 ; pass the looping flag in d1.
20 ; Mus_Stop - pass in handle to music to stop playing in d0.
21 ; Mus_Pause - pass in handle to music to pause in d0.
22 ; Mus_Resume - pass in handle to music to resume in d0.
23 ; Mus_Done - return d0 = 0 if music not playing
25 ;------------------------------------------------------------------------
28 _custom equ $DFF000
30 ;------------------------------------------------------------------------
32 include devpac:system.gs ; all includes/LVOs
34 ; include "exec/exec.i"
35 ; include "exec/funcdef.i"
36 ; include "exec/exec_lib.i"
37 ; include "dos/dos.i"
38 ; include "dos/dos_lib.i"
39 ; include "graphics/gfxbase.i"
40 ; include "devices/audio.i"
41 ; include "hardware/custom.i"
42 ; include "hardware/intbits.i"
43 ; include "hardware/dmabits.i"
45 ;CALLSYS macro
46 ; jsr (_LVO\1,a6)
47 ; endm
49 ;CALLDOS macro
50 ; movea.l (_DOSBase,pc),a6
51 ; jsr (_LVO\1,a6)
52 ; endm
54 output ram:doomsound.library.060
56 ;------------------------------------------------------------------------
58 VERSION equ 37 ;Version #
59 REVISION equ 1 ;revision of the version
61 _VER equ (VERSION/10)
62 VERHIGH equ _VER|$30
63 VERLOW equ (VERSION-(_VER*10))|$30
64 _REV equ (REVISION/10)
65 REVHIGH equ _REV|$30
66 REVLOW equ (REVISION-(_REV*10))|$30
68 OUTPUT_VER MACRO
69 ifge VERHIGH-$31
70 dc.b VERHIGH
71 endc
72 dc.b VERLOW
73 dc.b '.'
74 ifge REVHIGH-$31
75 dc.b REVHIGH
76 endc
77 dc.b REVLOW
78 ENDM
80 OUTPUT_DATE MACRO
81 dc.b ' (9.4.98)'
82 ENDM
85 ;--------------------------------------------------------------------
86 ; in case of idiots
88 moveq #0,d0
89 rts
91 ;--------------------------------------------------------------------
92 ; standard library header
95 InitDescript dc.w $4AFC ;this is the magic cookie
96 dc.l InitDescript
97 dc.l EndCode ;end of code to checksum
98 dc.b RTF_AUTOINIT
99 dc.b VERSION ;version #
100 dc.b NT_LIBRARY ;node type (library)
101 dc.b 0 ;node priority
102 dc.l Name ;pointer to the library name
103 dc.l IDString ;pointer to ID string
104 dc.l Init ;pointer to initialization data
107 Name dc.b 'doomsound.library',0
108 even
110 IDString dc.b 'doomsound.library '
111 OUTPUT_VER
112 OUTPUT_DATE
113 dc.b ' ©1998 by Joe Fenton.',0
114 even
117 CNOP 0,4
119 Init dc.l LIB_SIZE
120 dc.l FuncTable
121 dc.l DataTable
122 dc.l InitRoutine
125 FuncTable dc.l OpenLib ; -6
126 dc.l CloseLib ; -12
127 dc.l Expunge ; -18
128 dc.l Reserved ; -24
130 dc.l Sfx_SetVol ; -30
131 dc.l Sfx_Start ; -36
132 dc.l Sfx_Update ; -42
133 dc.l Sfx_Stop ; -48
134 dc.l Sfx_Done ; -54
136 dc.l Mus_SetVol ; -60
137 dc.l Mus_Register ; -66
138 dc.l Mus_Unregister ; -72
139 dc.l Mus_Play ; -78
140 dc.l Mus_Stop ; -84
141 dc.l Mus_Pause ; -90
142 dc.l Mus_Resume ; -96
143 dc.l Mus_Done ; -102
145 dc.l -1
148 DataTable INITBYTE LN_TYPE,NT_LIBRARY
149 INITLONG LN_NAME,Name
150 INITBYTE LIB_FLAGS,LIBF_SUMUSED+LIBF_CHANGED
151 INITWORD LIB_VERSION,VERSION
152 INITWORD LIB_REVISION,REVISION
153 INITLONG LIB_IDSTRING,IDString
154 dc.l 0
157 ;--------------------------------------
158 ; A0 = library segment list
159 ; A6 = ExecBase
160 ; D0 = library pointer
162 ; D0 -> library base or NULL
164 CNOP 0,16
166 InitRoutine move.l a6,_ExecBase
167 move.l a5,-(a7) ;save a5
168 movea.l d0,a5 ;library base pointer
169 move.l a0,SegList ;save library seglist
171 bsr InitServer ;setup sound server
172 bne.b .err
174 move.l a5,d0 ;success ...
175 movea.l (a7)+,a5
178 .err moveq #0,d0 ;error
179 movea.l (a7)+,a5
183 ;--------------------------------------
185 CNOP 0,16
187 OpenLib addq.w #1,LIB_OPENCNT(a6)
188 move.l a6,d0
192 ;--------------------------------------
193 ; this library is auto-expunging
195 CNOP 0,16
197 CloseLib subq.w #1,LIB_OPENCNT(a6)
198 beq.b Expunge
199 ;still open
200 moveq #0,d0 ;no seglist
204 ;--------------------------------------
205 ; A6 = library base
207 ; D0 -> seglist or NULL
209 CNOP 0,16
211 Expunge tst.w LIB_OPENCNT(a6) ;library still open?
212 bne .LibStillOpen ;yes
214 bsr ExitServer ;cleanup sound server
216 IFND TESTING
217 move.l SegList,d0 ;get the seglist
218 movem.l d0/a5-a6,-(a7) ;delayed save
219 movea.l a6,a5 ;library base => A5
220 movea.l a5,a1 ;library node
221 movea.l _ExecBase,a6
222 CALLSYS Remove ;unlink msmmu.library
224 movea.l a5,a1 ;calculate lib size
225 moveq #0,d0 ;and free memory
226 move.w LIB_NEGSIZE(a5),d0 ;backward extent
227 suba.w d0,a1 ;low memory extent
228 add.w LIB_POSSIZE(a5),d0 ;forward extent
229 CALLSYS FreeMem ;give it back
230 movem.l (a7)+,d0/a5-a6 ;seglist=>D0
231 ENDC
235 .LibStillOpen moveq #0,d0 ;no seglist
239 ;--------------------------------------
241 CNOP 0,4
243 Reserved moveq.l #0,d0
247 EndCode:
249 ;--------------------------------------------------------------------
251 dc.b 'This sound library uses the Amiga audio.device and',0
252 dc.b '11KHz samples; it supports full stereo panning on',0
253 dc.b 'sound effects and music. Up to 16 sound effects and',0
254 dc.b '16 channels of music can be palying at any time.',0
256 ;--------------------------------------------------------------------
258 CNOP 0,16
260 InitServer movem.l d1-d7/a0-a6,-(a7)
261 movea.l _ExecBase,a6
263 moveq #0,d0
264 lea DOSName,a1
265 CALLSYS OpenLibrary
266 move.l d0,_DOSBase
267 beq .err ; couldn't open dos.library
269 moveq #39,d0
270 lea GfxName,a1
271 CALLSYS OpenLibrary
272 tst.l d0
273 beq.b .2 ; leave at default (NTSC)
274 move.l d0,a1
275 btst #REALLY_PALn,gb_DisplayFlags(a1)
276 beq.b .1 ; crystal is NTSC
277 move.w #322,period ; PAL sample rate
278 .1 CALLSYS CloseLibrary
280 .2 move.l #128*256,d0
281 move.l #MEMF_CLEAR+MEMF_FAST+MEMF_PUBLIC,d1
282 CALLSYS AllocVec
283 move.l d0,LookupMem
284 beq .err0 ; no memory for vol_lookup
285 move.l d0,vol_lookup
286 movea.l d0,a0
288 moveq #0,d2
289 moveq #0,d1
290 .3 move.b d1,d3
291 ext.w d3
292 muls.w d2,d3
293 divs.w #127,d3 ; i*j/127
294 move.b d3,(a0)+
295 addq.b #1,d1
296 bne.b .3
297 addq.b #1,d2
298 cmpi.b #128,d2
299 bne.b .3
301 CALLSYS CreateMsgPort
302 move.l d0,AudioPort
303 beq .err1 ; couldn't create port
304 movea.l d0,a0
305 move.l #ioa_SIZEOF,d0
306 CALLSYS CreateIORequest
307 move.l d0,AudioIO
308 beq .err2 ; couldn't create io
310 movea.l d0,a1
311 moveq #0,d0
312 moveq #0,d1
313 lea AudioName,a0
314 CALLSYS OpenDevice
315 tst.l d0
316 bne .err3 ; couldn't open audio.device
318 movea.l AudioIO,a1
319 move.w #ADCMD_ALLOCATE,IO_COMMAND(a1)
320 move.b #ADIOF_NOWAIT+IOF_QUICK,IO_FLAGS(a1)
321 move.l #AudioAlloc,ioa_Data(a1)
322 move.l #1,ioa_Length(a1)
323 movea.l IO_DEVICE(a1),a6
324 jsr DEV_BEGINIO(a6)
325 movea.l _ExecBase,a6
326 tst.l d0
327 bne .err4 ; couldn't allocate channels
329 movea.l AudioIO,a1
330 move.w #ADCMD_LOCK,IO_COMMAND(a1)
331 CALLSYS SendIO
333 lea _custom,a0
334 move.w #$0780,intena(a0) ; kill int enable
335 move.w #$0780,intreq(a0) ; kill request
336 move.w #$00FF,adkcon(a0) ; kill modulation
337 move.w #$000F,dmacon(a0) ; disable dma
339 move.l #ClearBuf,aud0(a0)
340 move.w #40,aud0+ac_len(a0)
341 move.w period,aud0+ac_per(a0)
342 move.w #0,aud0+ac_vol(a0)
344 move.l #ClearBuf,aud1(a0)
345 move.w #40,aud1+ac_len(a0)
346 move.w period,aud1+ac_per(a0)
347 move.w #0,aud1+ac_vol(a0)
349 move.l #ClearBuf,aud2(a0)
350 move.w #40,aud2+ac_len(a0)
351 move.w period,aud2+ac_per(a0)
352 move.w #0,aud2+ac_vol(a0)
354 move.l #ClearBuf,aud3(a0)
355 move.w #40,aud3+ac_len(a0)
356 move.w period,aud3+ac_per(a0)
357 move.w #0,aud3+ac_vol(a0)
359 moveq #INTB_AUD0,d0
360 lea AInt0,a1
361 CALLSYS SetIntVector
362 move.l d0,OldAInt0
364 move.l #QuietInst,Channel0
365 move.l #QuietInst,Channel1
366 move.l #QuietInst,Channel2
367 move.l #QuietInst,Channel3
368 move.l #QuietInst,Channel4
369 move.l #QuietInst,Channel5
370 move.l #QuietInst,Channel6
371 move.l #QuietInst,Channel7
372 move.l #QuietInst,Channel8
373 move.l #QuietInst,Channel9
374 move.l #QuietInst,Channel10
375 move.l #QuietInst,Channel11
376 move.l #QuietInst,Channel12
377 move.l #QuietInst,Channel13
378 move.l #QuietInst,Channel14
379 move.l #QuietInst,Channel15
381 clr.b mus_playing
382 clr.b mus_looping
384 clr.l MusDelay ; MusDelay = 0
385 clr.l VoiceAvail ; all voices available
387 CALLSYS Disable
388 lea _custom,a0
389 move.w #$8080,intena(a0) ; int enable
390 move.w #$800F,dmacon(a0) ; enable dma
391 bsr AudioINT0 ; start audio
392 CALLSYS Enable
394 movem.l (a7)+,d1-d7/a0-a6
395 moveq #0,d0 ; okay
398 .err4 movea.l AudioIO,a1
399 CALLSYS CloseDevice
401 .err3 movea.l AudioIO,a0
402 CALLSYS DeleteIORequest
404 .err2 movea.l AudioPort,a0
405 CALLSYS DeleteMsgPort
407 .err1 movea.l LookupMem,a1
408 CALLSYS FreeVec
410 .err0 movea.l _DOSBase,a1
411 CALLSYS CloseLibrary
413 .err movem.l (a7)+,d1-d7/a0-a6
414 moveq #-1,d0 ; error
417 ;--------------------------------------
419 CNOP 0,16
421 ExitServer movem.l d1-d7/a0-a6,-(a7)
423 lea _custom,a0
424 move.w #$0780,intena(a0) ; kill int enable
425 move.w #$0780,intreq(a0) ; kill request
426 move.w #$000F,dmacon(a0) ; dma off
428 moveq #INTB_AUD0,d0
429 movea.l OldAInt0,a1
430 movea.l _ExecBase,a6
431 CALLSYS SetIntVector
433 movea.l AudioIO,a1
434 move.w #ADCMD_FREE,IO_COMMAND(a1)
435 move.b #IOF_QUICK,IO_FLAGS(a1)
436 movea.l IO_DEVICE(a1),a6
437 jsr DEV_BEGINIO(a6)
439 movea.l _ExecBase,a6
441 movea.l AudioIO,a1
442 CALLSYS CloseDevice
444 movea.l AudioIO,a0
445 CALLSYS DeleteIORequest
447 movea.l AudioPort,a0
448 CALLSYS DeleteMsgPort
450 movea.l LookupMem,a1
451 CALLSYS FreeVec
453 movea.l _DOSBase,a1
454 CALLSYS CloseLibrary
456 movem.l (a7)+,d1-d7/a0-a6
457 moveq #0,d0
460 ;--------------------------------------
462 CNOP 0,16
464 Sfx_SetVol move.w d0,sfx_volume
467 ;--------------------------------------
469 CNOP 0,16
471 Sfx_Start movem.l d0-d4/a0-a2,-(a7)
472 lea sfxVoiceTbl,a1
473 movea.l (a1,d0.w*4),a1
474 lea 8(a0),a0
475 subq.l #8,d4
476 move.l a0,vc_Wave(a1)
477 clr.l vc_Index(a1)
478 swap d1
479 clr.w d1
480 divu.l #11025,d1
481 move.l d1,vc_Step(a1)
482 clr.l vc_Loop(a1)
483 lsl.l #8,d4
484 move.l d4,vc_Length(a1)
486 addq.w #1,d3 ; sep += 1
487 move.w d2,d4
488 muls.w d3,d4
489 muls.w d3,d4
490 clr.w d4
491 swap d4
492 neg.w d4
493 add.w d2,d4 ; ltvol = vol - vol * (sep+1)^2 / 256^2
494 lsl.l #8,d4
495 move.l d4,vc_LtVol(a1)
497 subi.l #257,d3 ; sep -= 257
498 move.w d2,d4
499 muls.w d3,d4
500 muls.w d3,d4
501 clr.w d4
502 swap d4
503 neg.w d4
504 add.w d2,d4 ; rtvol = vol - vol * (sep-257)^2 / 256^2
505 lsl.l #8,d4
506 move.l d4,vc_RtVol(a1)
508 move.b #$81,vc_Flags(a1)
509 movem.l (a7)+,d0-d4/a0-a2
512 ;--------------------------------------
514 CNOP 0,16
516 Sfx_Update movem.l d0-d4/a0-a2,-(a7)
517 lea sfxVoiceTbl,a1
518 movea.l (a1,d0.w*4),a1
519 swap d1
520 clr.w d1
521 divu.l #11025,d1
522 move.l d1,vc_Step(a1)
524 addq.w #1,d3 ; sep += 1
525 move.w d2,d4
526 muls.w d3,d4
527 muls.w d3,d4
528 clr.w d4
529 swap d4
530 neg.w d4
531 add.w d2,d4 ; ltvol = vol - vol * (sep+1)^2 / 256^2
532 lsl.l #8,d4
533 move.l d4,vc_LtVol(a1)
535 subi.l #257,d3 ; sep -= 257
536 move.w d2,d4
537 muls.w d3,d4
538 muls.w d3,d4
539 clr.w d4
540 swap d4
541 neg.w d4
542 add.w d2,d4 ; rtvol = vol - vol * (sep-257)^2 / 256^2
543 lsl.l #8,d4
544 move.l d4,vc_RtVol(a1)
546 movem.l (a7)+,d0-d4/a0-a2
549 ;--------------------------------------
551 CNOP 0,16
553 Sfx_Stop move.l a0,-(a7)
554 lea sfxVoiceTbl,a0
555 movea.l (a0,d0.w*4),a0
556 bclr #0,vc_Flags(a0)
557 movea.l (a7)+,a0
560 ;--------------------------------------
562 CNOP 0,16
564 Sfx_Done move.l a0,-(a7)
565 lea sfxVoiceTbl,a0
566 movea.l (a0,d0.w*4),a0
567 moveq #0,d0
568 btst #0,vc_Flags(a0)
569 beq.b .1 ; not playing
570 move.l vc_Index(a0),d0
571 addq.l #1,d0 ; for safety
572 .1 movea.l (a7)+,a0
575 ;--------------------------------------
577 CNOP 0,16
579 Mus_SetVol move.w d0,mus_volume
582 ;--------------------------------------
584 CNOP 0,16
586 Mus_Register movem.l d1-d7/a0-a6,-(sp)
587 bsr Mus_Unregister
589 move.l a0,MUSMemPtr
591 cmpi.l #$4D55531A,(a0) ; "MUS",26
592 bne .err0 ; not a mus file
594 move.l MUSMemPtr,MusPtr
596 bsr TestMUSFile
597 beq .err0
599 move.l InstrFile,d1
600 move.l #MODE_OLDFILE,d2
601 CALLDOS Open
602 move.l d0,InstrHandle
603 beq .err0
605 move.l #MEMF_CLEAR,d0 ; any memory
606 move.l #65536,d1 ; puddle size
607 move.l #32768,d2 ; threshold size
608 bsr CreatePool
609 move.l a0,InstrPool
610 beq .err1
612 movea.l a0,a2
613 movea.l MusPtr,a3
615 move.w #255,d0
616 lea Instruments,a0
617 .setinstr move.l #QuietInst,(a0)+
618 dbra d0,.setinstr
620 move.w $C(a3),d4 ; instrCnt
621 ror.w #8,d4
622 subq.w #1,d4 ; for dbra
624 lea $10(a3),a3 ; instruments[]
626 .instrloop moveq #14,d0
627 movea.l a2,a0
628 bsr AllocPooled
630 moveq #0,d2
631 move.b (a3)+,d2 ; instrument #
632 moveq #0,d1
633 move.b (a3)+,d1 ; offset to next instr. #
634 adda.l d1,a3 ; skip it (whatever it is?)
636 lea Instruments,a0
637 move.l d0,(a0,d2.w*4)
638 beq .err2
640 movea.l d0,a4 ; instrument record
642 bftst (validInstr){d2:1}
643 beq .next ; no instrument
645 move.l InstrHandle,d1
646 lsl.l #2,d2
647 moveq #OFFSET_BEGINNING,d3
648 CALLDOS Seek
650 move.l InstrHandle,d1
651 move.l a4,d2
652 moveq #4,d3
653 CALLSYS Read ; get instrument offset
654 addq.l #1,d0
655 beq .err2 ; can't read file
657 move.l InstrHandle,d1
658 move.l (a4),d2
659 moveq #OFFSET_BEGINNING,d3
660 CALLSYS Seek
662 move.l InstrHandle,d1
663 move.l a4,d2
664 moveq #14,d3
665 CALLSYS Read ; get instrument header
666 addq.l #1,d0
667 beq .err2 ; can't read file
669 move.l in_Length(a4),d0
670 swap d0
671 movea.l a2,a0
672 bsr AllocPooled
673 move.l d0,in_Wave(a4) ; wave data buffer
674 beq .err2
676 move.l InstrHandle,d1
677 move.l d0,d2
678 move.l in_Length(a4),d3
679 swap d3
680 CALLDOS Read ; get instrument samples
681 addq.l #1,d0
682 beq .err2 ; can't read file
684 move.b #1,in_Flags(a4)
685 .next dbra d4,.instrloop
687 move.l InstrHandle,d1
688 CALLDOS Close
689 clr.l InstrHandle
691 moveq #1,d0 ; return handle=1
692 movem.l (sp)+,d1-d7/a0-a6
695 .err2 movea.l InstrPool,a0
696 bsr DeletePool
697 clr.l InstrPool
699 .err1 move.l InstrHandle,d1
700 CALLDOS Close
701 clr.l InstrHandle
703 .err0 moveq #0,d0 ; return handle=0
704 movem.l (sp)+,d1-d7/a0-a6
707 ;--------------------------------------
709 CNOP 0,16
711 Mus_Unregister movem.l d0-d7/a0-a6,-(a7)
712 bsr Mus_Stop
714 clr.l MUSMemPtr
715 clr.l MUSMemSize
717 tst.l InstrPool
718 beq.b .1
719 movea.l InstrPool,a0
720 bsr DeletePool
721 clr.l InstrPool
723 .1 movem.l (a7)+,d0-d7/a0-a6
726 ;--------------------------------------
728 CNOP 0,16
730 Mus_Play move.b d1,mus_looping
731 move.b #2,mus_playing ; 2 = play from start
734 ;--------------------------------------
736 CNOP 0,16
738 Mus_Stop tst.b mus_playing
739 beq.b .2
740 st mus_playing ; -1 = stop playing
741 .1 tst.b mus_playing
742 bne.b .1
744 .2 move.l #QuietInst,Channel0
745 move.l #QuietInst,Channel1
746 move.l #QuietInst,Channel2
747 move.l #QuietInst,Channel3
748 move.l #QuietInst,Channel4
749 move.l #QuietInst,Channel5
750 move.l #QuietInst,Channel6
751 move.l #QuietInst,Channel7
752 move.l #QuietInst,Channel8
753 move.l #QuietInst,Channel9
754 move.l #QuietInst,Channel10
755 move.l #QuietInst,Channel11
756 move.l #QuietInst,Channel12
757 move.l #QuietInst,Channel13
758 move.l #QuietInst,Channel14
759 move.l #QuietInst,Channel15
761 clr.b Voice0+vc_Flags ; disable voices
762 clr.b Voice1+vc_Flags
763 clr.b Voice2+vc_Flags
764 clr.b Voice3+vc_Flags
765 clr.b Voice4+vc_Flags
766 clr.b Voice5+vc_Flags
767 clr.b Voice6+vc_Flags
768 clr.b Voice7+vc_Flags
769 clr.b Voice8+vc_Flags
770 clr.b Voice9+vc_Flags
771 clr.b Voice10+vc_Flags
772 clr.b Voice11+vc_Flags
773 clr.b Voice12+vc_Flags
774 clr.b Voice13+vc_Flags
775 clr.b Voice14+vc_Flags
776 clr.b Voice15+vc_Flags
778 clr.b mus_looping
779 clr.l MusDelay ; MusDelay = 0
780 clr.l VoiceAvail ; all voices available
783 ;--------------------------------------
785 CNOP 0,16
787 Mus_Pause clr.b mus_playing ; 0 = not playing
790 ;--------------------------------------
792 CNOP 0,16
794 Mus_Resume move.b #1,mus_playing ; 1 = play
797 ;--------------------------------------
799 CNOP 0,16
801 Mus_Done moveq #0,d0
802 move.b mus_playing,d0
805 ;------------------------------------------------------------------------
807 CNOP 0,16
809 TestMUSFile movea.l MusPtr,a0
810 move.l MUSMemSize,d3 ; d3 = total file size
811 moveq #0,d0
812 move.w 4(a0),d0
813 beq .fail
814 ror.w #8,d0 ; score length
815 moveq #0,d1
816 move.w 6(a0),d1
817 ror.w #8,d1 ; score start
818 cmpi.w #18,d1 ; start < 18? (1 instr.)
819 blt .fail
820 add.l d1,d0 ; d0 = total size
822 move.l d0,d3
823 move.l d3,MUSMemSize
825 move.w 12(a0),d2
826 beq.b .fail
827 ror.w #8,d2 ; d2 = instr. count
828 subq.w #1,d2
829 lea 16(a0),a1 ; a1 = * instr. list
830 .loop addq.l #1,a1 ; skip instr. value
831 moveq #0,d0
832 move.b (a1)+,d0 ; d0 = offset to next instr.
833 adda.l d0,a1 ; skip info (?)
834 dbra d2,.loop ; next
835 move.l a1,d0 ; d0 = * data following list
836 sub.l a0,d0 ; - file start
837 cmp.l d0,d1 ; = start?
838 bne.b .fail
839 move.b -1(a0,d3.l),d0 ; get last byte
840 lsr.b #4,d0
841 cmpi.b #6,d0 ; last byte = $6x? (end)
842 bne.b .fail
843 moveq #1,d0 ; file okay
846 .fail moveq #0,d0 ; yikes!
849 ;------------------------------------------------------------------------
851 cnop 0,16
853 AudioINT0 movem.l d2-d7/a2-a6,-(a7)
854 move.l chip_offset,d0
855 add.l d0,chip_buffer ; switch buffers
856 neg.l d0
857 move.l d0,chip_offset
859 lea _custom,a0
860 move.w #$0780,intreq(a0) ; clear int requests
862 tst.b mus_playing
863 bgt.b .domus
864 beq.b .musoff
865 addq.b #1,mus_playing ; now off
867 .musoff move.l #ClearBuf,aud3(a0)
868 move.w #40,aud3+ac_len(a0)
869 move.w period,aud3+ac_per(a0)
870 move.w #0,aud3+ac_vol(a0)
872 move.l #ClearBuf,aud2(a0)
873 move.w #40,aud2+ac_len(a0)
874 move.w period,aud2+ac_per(a0)
875 move.w #0,aud2+ac_vol(a0)
877 bra .dosfx
879 .domus cmpi.b #2,mus_playing
880 bne.b .musnxt
881 subq.b #1,mus_playing
883 movea.l MusPtr,a1
884 moveq #0,d1
885 move.w 6(a1),d1 ; score start
886 ror.w #8,d1
887 adda.l d1,a1 ; a1 = start
888 move.l a1,MusIndex ; store index
890 .musnxt subq.l #1,MusDelay
891 bpl.b .fillmus
893 bsr NextEvent
895 .fillmus lea Voice0,a0 ; music voices
896 movea.l chip_buffer,a2
897 bsr FillBuffer
899 lea _custom,a0
901 move.l chip_buffer,d0
902 move.l d0,aud3(a0) ; left mus
903 move.w #40,aud3+ac_len(a0) ; 80 samples
904 move.w period,aud3+ac_per(a0)
905 move.w mus_volume,aud3+ac_vol(a0)
907 addi.l #128,d0
908 move.l d0,aud2(a0) ; right mus
909 move.w #40,aud2+ac_len(a0) ; 80 samples
910 move.w period,aud2+ac_per(a0)
911 move.w mus_volume,aud2+ac_vol(a0)
913 .dosfx lea Voice16,a0 ; sound effect voices
914 movea.l chip_buffer,a2
915 lea 256(a2),a2
916 bsr FillBuffer
918 lea _custom,a0
920 move.l chip_buffer,d0
921 addi.l #256,d0
922 move.l d0,aud0(a0) ; left sfx
923 move.w #40,aud0+ac_len(a0) ; 80 samples
924 move.w period,aud0+ac_per(a0)
925 move.w sfx_volume,aud0+ac_vol(a0)
927 addi.l #128,d0
928 move.l d0,aud1(a0) ; right sfx
929 move.w #40,aud1+ac_len(a0) ; 80 samples
930 move.w period,aud1+ac_per(a0)
931 move.w sfx_volume,aud1+ac_vol(a0)
933 .exit movem.l (a7)+,d2-d7/a2-a6
934 moveq #0,d0
937 ;------------------------------------------------------------------------
939 CNOP 0,16
941 FillBuffer movea.l a2,a4
942 lea tempAudio,a1
943 moveq #4,d0
944 .lcloop clr.l (a1)+
945 clr.l (a1)+
946 clr.l (a1)+
947 clr.l (a1)+
948 dbra d0,.lcloop
950 lea tempAudio+128,a1
951 moveq #4,d0
952 .rcloop clr.l (a1)+
953 clr.l (a1)+
954 clr.l (a1)+
955 clr.l (a1)+
956 dbra d0,.rcloop
957 bra.b .1stvoice
959 .next move.l vc_Next(a0),d0 ; next voice
960 bne.b .chkvoice
962 lea 128(a4),a2
963 lea tempAudio,a1
964 moveq #4,d0
965 .lmloop move.l (a1)+,(a4)+
966 move.l (a1)+,(a4)+
967 move.l (a1)+,(a4)+
968 move.l (a1)+,(a4)+
969 dbra d0,.lmloop
971 lea tempAudio+128,a1
972 moveq #4,d0
973 .rmloop move.l (a1)+,(a2)+
974 move.l (a1)+,(a2)+
975 move.l (a1)+,(a2)+
976 move.l (a1)+,(a2)+
977 dbra d0,.rmloop
980 .chkvoice movea.l d0,a0
981 .1stvoice btst #0,vc_Flags(a0)
982 beq.b .next ; not enabled
984 ;------------------
985 ; do voice
986 btst #7,vc_Flags(a0)
987 bne .5 ; sfx
989 btst #1,vc_Flags(a0)
990 beq.b .1 ; not releasing
992 tst.l vc_LtVol(a0)
993 beq.b .0
994 subi.l #256,vc_LtVol(a0)
996 .0 tst.l vc_RtVol(a0)
997 beq.b .1
998 subi.l #256,vc_RtVol(a0)
1000 .1 move.l vc_LtVol(a0),d6
1001 move.l vc_RtVol(a0),d7
1002 tst.l d6
1003 bne.b .2 ; not off yet
1004 tst.l d7
1005 bne.b .2 ; not off yet
1007 clr.b vc_Flags(a0) ; voice off
1008 bra .next
1010 .2 lea tempAudio,a1 ; left buffer
1011 movea.l vol_lookup,a5
1013 movem.l vc_Index(a0),d1-d4 ; index,step,loop,length
1015 movea.l vc_Channel(a0),a3
1016 move.l ch_Pitch(a3),d0
1017 ; muls.l d0,d5:d2
1018 bsr QuadMuls
1019 move.w d5,d2
1020 swap d2
1021 add.l vc_Step(a0),d2 ; final sample rate
1023 movea.l vc_Wave(a0),a3 ; sample data
1025 moveq #79,d5 ; 80 samples
1026 .floop move.l d1,d0
1027 swap d0
1028 move.b (a3,d0.w),d6 ; sample
1029 move.b d6,d7
1030 move.b (a5,d6.l),d6 ; convert
1031 move.b (a5,d7.l),d7 ; convert
1032 asr.b #2,d6
1033 asr.b #2,d7
1034 add.b d6,(a1)+ ; left sample
1035 add.b d7,127(a1) ; right sample
1037 add.l d2,d1
1038 cmp.l d4,d1
1039 blo.b .3
1040 sub.l d4,d1
1041 add.l d3,d1
1042 tst.l d3
1043 beq.b .4 ; no looping
1044 .3 dbra d5,.floop
1045 bra.b .done ; done with voice
1047 ; ran out of data
1048 .4 clr.b vc_Flags(a0) ; voice off
1050 .done move.l d1,vc_Index(a0)
1051 bra .next
1053 ; do sfx voice
1055 .5 move.l vc_LtVol(a0),d6
1056 move.l vc_RtVol(a0),d7
1058 lea tempAudio,a1 ; left buffer
1059 movea.l vol_lookup,a5
1061 movem.l vc_Index(a0),d1-d4 ; index,step,loop,length
1063 move.l vc_Step(a0),d2 ; sample rate
1064 lsr.l #8,d2
1066 movea.l vc_Wave(a0),a3 ; sample data
1068 moveq #79,d5 ; 80 samples
1069 .sfloop move.l d1,d0
1070 lsr.l #8,d0
1071 move.b (a3,d0.l),d6 ; sample
1072 move.b d6,d7
1073 move.b (a5,d6.l),d6 ; convert
1074 move.b (a5,d7.l),d7 ; convert
1075 asr.b #2,d6
1076 asr.b #2,d7
1077 add.b d6,(a1)+ ; left sample
1078 add.b d7,127(a1) ; right sample
1080 add.l d2,d1
1081 cmp.l d4,d1
1082 bhs.b .4 ; ran out of data
1083 dbra d5,.sfloop
1084 bra .done ; done with voice
1086 ;------------------------------------------------------------------------
1088 CNOP 0,16
1090 NextEvent movea.l MusIndex,a1
1092 .0 move.b (a1)+,d0 ; get next event
1093 move.b d0,d1
1094 lsr.b #3,d1
1095 andi.w #$E,d1 ; d1 = event type * 2
1096 lea EventTable,a0
1097 move.w (a0,d1.w),d1
1098 jsr (a0,d1.w) ; do event
1099 tst.b d0
1100 bpl.b .0 ; more events
1102 moveq #0,d1 ; time = 0
1103 .1 move.b (a1)+,d0 ; get byte
1104 bpl.b .2
1106 andi.w #$7F,d0 ; kill sign bit
1107 or.b d0,d1 ; time = time + 7 bits
1108 lsl.l #7,d1 ; * 128
1109 bra.b .1 ; get next 7 bits
1111 .2 or.b d0,d1 ; time = time + last 7 bits
1112 subq.l #1,d1 ; delay = time - 1
1113 bmi.b .0 ; (no delay)
1115 move.l d1,MusDelay ; store delay
1116 move.l a1,MusIndex ; store index
1119 ;------------------------------------------------------------------------
1121 Release moveq #15,d1
1122 and.b d0,d1 ; d1 = channel
1124 lea Channels,a0
1125 movea.l (a0,d1.w*4),a0 ; channel record
1126 movea.l ch_Map(a0),a0 ; channel map
1128 move.b (a1)+,d1 ; note #
1129 moveq #0,d2
1130 move.b (a0,d1.w),d2 ; voice #
1131 beq.b .exit ; no mapping
1133 clr.b (a0,d1.w) ; clear mapping
1134 move.l VoiceAvail,d3
1135 bclr d2,d3 ; voice free for use
1136 move.l d3,VoiceAvail
1138 lea Voices,a0
1139 movea.l (a0,d2.w*4),a0 ; voice
1140 bset #1,vc_Flags(a0) ; do release
1142 .exit rts
1144 ;------------------------------------------------------------------------
1146 PlayNote moveq #15,d1
1147 and.b d0,d1 ; d1 = channel
1149 lea Channels,a0
1150 movea.l (a0,d1.w*4),a2 ; channel record
1151 movea.l ch_Map(a2),a0 ; channel map
1153 moveq #-1,d2 ; no volume change
1154 move.b (a1)+,d1 ; note #
1155 bclr #7,d1
1156 beq.b .getvc ; no volume
1158 moveq #0,d2
1159 move.b (a1)+,d2 ; volume
1161 .getvc moveq #0,d3
1162 move.l VoiceAvail,d4
1163 .vloop bset d3,d4
1164 beq.b .foundfree
1165 addq.b #1,d3
1166 cmpi.b #16,d3
1167 bne.b .vloop
1168 ; no free voices
1172 .foundfree move.b d3,(a0,d1.w) ; voice mapping
1173 move.l d4,VoiceAvail
1175 lea Voices,a0
1176 movea.l (a0,d3.w*4),a3 ; voice
1178 tst.b d2
1179 bmi.b .skip
1181 ; new channel volume
1183 move.b d2,ch_Vol(a2)
1184 moveq #0,d3
1185 move.b ch_Pan(a2),d3
1186 addq.w #1,d3 ; sep += 1
1187 move.w d2,d4
1188 muls.w d3,d4
1189 muls.w d3,d4
1190 clr.w d4
1191 swap d4
1192 neg.w d4
1193 add.w d2,d4 ; ltvol = vol - vol * (sep+1)^2 / 256^2
1194 lsl.l #8,d4
1195 move.l d4,ch_LtVol(a2)
1197 subi.l #257,d3 ; sep -= 257
1198 move.w d2,d4
1199 muls.w d3,d4
1200 muls.w d3,d4
1201 clr.w d4
1202 swap d4
1203 neg.w d4
1204 add.w d2,d4 ; rtvol = vol - vol * (sep-257)^2 / 256^2
1205 lsl.l #8,d4
1206 move.l d4,ch_RtVol(a2)
1208 .skip move.l ch_LtVol(a2),vc_LtVol(a3)
1209 move.l ch_RtVol(a2),vc_RtVol(a3)
1211 moveq #15,d2
1212 and.b d0,d2
1213 cmpi.b #15,d2
1214 beq.b .percussion
1216 move.l ch_Instr(a2),a4 ; instrument record
1218 lea NoteTable,a0
1219 moveq #72,d2 ; one octave above middle c
1220 sub.b in_Base(a4),d2
1221 add.b d1,d2
1222 move.l (a0,d2.w*4),vc_Step(a3) ; step value for note
1224 clr.l vc_Index(a3)
1226 move.l a2,vc_Channel(a3) ; back link (for pitch wheel)
1228 move.l in_Wave(a4),vc_Wave(a3)
1229 move.l in_Loop(a4),vc_Loop(a3)
1230 move.l in_Length(a4),vc_Length(a3)
1231 move.b in_Flags(a4),vc_Flags(a3)
1232 .exit rts
1234 ; for the percussion channel, the note played sets the percussion instrument
1236 .percussion move.l #65536,vc_Step(a3) ; sample rate always 1.0
1238 clr.l vc_Index(a3)
1240 move.l a2,vc_Channel(a3) ; back link
1242 addi.b #100,d1 ; percussion instruments
1244 lea Instruments,a0
1245 move.l (a0,d1.w*4),a0 ; instrument record
1246 move.l in_Wave(a0),vc_Wave(a3)
1247 move.l in_Loop(a0),vc_Loop(a3)
1248 move.l in_Length(a0),vc_Length(a3)
1249 move.b in_Flags(a0),vc_Flags(a3)
1252 ;------------------------------------------------------------------------
1254 Pitch moveq #15,d1
1255 and.b d0,d1 ; d1 = channel
1257 lea Channels,a0
1258 movea.l (a0,d1.w*4),a2 ; channel record
1260 moveq #0,d1
1261 move.b (a1)+,d1 ; pitch wheel setting
1262 lea PitchTable,a0
1263 move.l (a0,d1.w*4),ch_Pitch(a2)
1266 ;------------------------------------------------------------------------
1268 Tempo addq.l #1,a1 ; skip value
1271 ;------------------------------------------------------------------------
1273 ChangeCtrl moveq #15,d1
1274 and.b d0,d1 ; d1 = channel
1276 lea Channels,a0
1277 movea.l (a0,d1.w*4),a2 ; channel
1279 move.b (a1)+,d1 ; get controller
1281 moveq #0,d2
1282 move.b (a1)+,d2 ; value
1284 tst.b d1
1285 bne.b .1
1287 ; set channel instrument
1289 lea Instruments,a0
1290 move.l (a0,d2.w*4),ch_Instr(a2)
1291 bne.b .0
1292 move.l #QuietInst,ch_Instr(a2)
1293 .0 rts
1295 .1 cmpi.b #3,d1 ; volume?
1296 bne.b .2
1298 ; set channel volume
1300 move.b d2,ch_Vol(a2)
1301 moveq #0,d3
1302 move.b ch_Pan(a2),d3
1303 addq.w #1,d3 ; sep += 1
1304 move.w d2,d4
1305 muls.w d3,d4
1306 muls.w d3,d4
1307 clr.w d4
1308 swap d4
1309 neg.w d4
1310 add.w d2,d4 ; ltvol = vol - vol * (sep+1)^2 / 256^2
1311 lsl.l #8,d4
1312 move.l d4,ch_LtVol(a2)
1314 subi.w #257,d3 ; sep -= 257
1315 move.w d2,d4
1316 muls.w d3,d4
1317 muls.w d3,d4
1318 clr.w d4
1319 swap d4
1320 neg.w d4
1321 add.w d2,d4 ; rtvol = vol - vol * (sep-257)^2 / 256^2
1322 lsl.l #8,d4
1323 move.l d4,ch_RtVol(a2)
1326 .2 cmpi.b #4,d1 ; pan?
1327 bne.b .exit
1329 ; set channel pan
1331 add.b d2,d2 ; pan -> sep
1332 move.b d2,ch_Pan(a2)
1333 move.b ch_Vol(a2),d2
1334 moveq #0,d3
1335 move.b ch_Pan(a2),d3
1336 addq.w #1,d3 ; sep += 1
1337 move.w d2,d4
1338 muls.w d3,d4
1339 muls.w d3,d4
1340 clr.w d4
1341 swap d4
1342 neg.w d4
1343 add.w d2,d4 ; ltvol = vol - vol * (sep+1)^2 / 256^2
1344 lsl.l #8,d4
1345 move.l d4,ch_LtVol(a2)
1347 subi.w #257,d3 ; sep -= 257
1348 move.w d2,d4
1349 muls.w d3,d4
1350 muls.w d3,d4
1351 clr.w d4
1352 swap d4
1353 neg.w d4
1354 add.w d2,d4 ; rtvol = vol - vol * (sep-257)^2 / 256^2
1355 lsl.l #8,d4
1356 move.l d4,ch_RtVol(a2)
1357 .exit rts
1359 ;------------------------------------------------------------------------
1361 NoEvent rts
1363 ;------------------------------------------------------------------------
1365 EndScore tst.b mus_looping ; loop?
1366 bne .loop
1368 move.l #QuietInst,Channel0
1369 move.l #QuietInst,Channel1
1370 move.l #QuietInst,Channel2
1371 move.l #QuietInst,Channel3
1372 move.l #QuietInst,Channel4
1373 move.l #QuietInst,Channel5
1374 move.l #QuietInst,Channel6
1375 move.l #QuietInst,Channel7
1376 move.l #QuietInst,Channel8
1377 move.l #QuietInst,Channel9
1378 move.l #QuietInst,Channel10
1379 move.l #QuietInst,Channel11
1380 move.l #QuietInst,Channel12
1381 move.l #QuietInst,Channel13
1382 move.l #QuietInst,Channel14
1383 move.l #QuietInst,Channel15
1385 clr.b Voice0+vc_Flags ; disable voices
1386 clr.b Voice1+vc_Flags
1387 clr.b Voice2+vc_Flags
1388 clr.b Voice3+vc_Flags
1389 clr.b Voice4+vc_Flags
1390 clr.b Voice5+vc_Flags
1391 clr.b Voice6+vc_Flags
1392 clr.b Voice7+vc_Flags
1393 clr.b Voice8+vc_Flags
1394 clr.b Voice9+vc_Flags
1395 clr.b Voice10+vc_Flags
1396 clr.b Voice11+vc_Flags
1397 clr.b Voice12+vc_Flags
1398 clr.b Voice13+vc_Flags
1399 clr.b Voice14+vc_Flags
1400 clr.b Voice15+vc_Flags
1402 clr.l MusDelay ; MusDelay = 0
1403 clr.l VoiceAvail ; all voices available
1404 clr.b mus_playing
1405 addq.l #4,a7 ; pop NextEvent
1408 .loop movea.l MusPtr,a1
1409 moveq #0,d1
1410 move.w 6(a1),d1 ; score start
1411 ror.w #8,d1
1412 adda.l d1,a1 ; a1 = start
1415 ;------------------------------------------------------------------------
1416 cnop 0,4
1418 EventTable dc.w Release-EventTable
1419 dc.w PlayNote-EventTable
1420 dc.w Pitch-EventTable
1421 dc.w Tempo-EventTable
1422 dc.w ChangeCtrl-EventTable
1423 dc.w NoEvent-EventTable
1424 dc.w EndScore-EventTable
1425 dc.w NoEvent-EventTable
1427 ;--------------------------------------------------------------------
1429 CNOP 0,16
1431 QuadMuls exg.l d2,d1
1432 movem.l d2-d5,-(a7)
1433 move.w ccr,d5
1435 tst.l d0
1436 beq.b .zero
1437 tst.l d1
1438 beq.b .zero
1440 swap d5 ; save ccr
1441 clr.b d5
1442 tst.l d0
1443 bge.b .1
1444 neg.l d0 ; make multiplier positive
1445 ori.b #$01,d5
1446 .1 tst.l d1
1447 bge.b .2
1448 neg.l d1 ; make multiplicand positive
1449 eori.b #$01,d5
1451 .2 move.l d0,d2
1452 move.l d0,d3
1453 move.l d1,d4
1454 swap d3
1455 swap d4
1456 mulu.w d1,d0
1457 mulu.w d3,d1
1458 mulu.w d4,d2
1459 mulu.w d4,d3
1460 clr.l d4
1461 swap d0
1462 add.w d1,d0
1463 addx.l d4,d3
1464 add.w d2,d0
1465 addx.l d4,d3
1466 swap d0
1467 clr.w d1
1468 clr.w d2
1469 swap d1
1470 swap d2
1471 add.l d2,d1
1472 add.l d3,d1
1474 tst.b d5
1475 beq.b .3 ; result positive
1476 not.l d0
1477 not.l d1
1478 addq.l #$01,d0
1479 addx.l d4,d1
1481 .3 swap d5 ; prev ccr
1482 andi.b #$10,d5 ; keep X
1483 tst.l d1
1484 bpl.b .4
1485 ori.b #$08,d5 ; set N
1486 .4 move.w d5,ccr
1487 movem.l (a7)+,d2-d5
1488 exg.l d0,d5
1489 exg.l d1,d2
1490 exg.l d2,d5
1493 CNOP 0,16
1495 .zero moveq #0,d0
1496 moveq #0,d1
1497 andi.b #$10,d5 ; keep X
1498 ori.b #$04,d5 ; set Z
1499 move.w d5,ccr
1500 movem.l (a7)+,d2-d5
1501 exg.l d0,d5
1502 exg.l d1,d2
1503 exg.l d2,d5
1506 ;--------------------------------------------------------------------
1507 ;--------------------------------------------------------------------
1509 cnop 0,4
1511 CreatePool movea.l _ExecBase,a1
1512 cmpi.w #39,LIB_VERSION(a1)
1513 blt.b .nopools ; change to bra for debugging
1515 move.l a6,-(sp)
1516 movea.l a1,a6
1517 CALLSYS CreatePool
1518 movea.l (sp)+,a6
1521 .nopools movem.l d2-d7/a2-a6,-(sp)
1522 move.l d0,d4 ; memory attributes
1523 move.l d1,d3 ; amount to allocate when low
1524 move.l d2,d5 ; size of when not to use pool
1526 exg.l d0,d1 ; swap flags and size
1527 movea.l a1,a6
1528 CALLSYS AllocMem ; get first block
1529 movea.l d0,a0
1530 tst.l d0
1531 beq.b .exit ; no memory!
1533 movem.l d3-d5,(a0) ; puddleSize, Flags,Threshold
1534 clr.l 12(a0) ; no next block
1535 lea 24(a0),a1 ; first free location here
1536 move.l a1,16(a0)
1537 subi.l #24,d3 ; for header info
1538 move.l d3,20(a0) ; amount free in this block
1540 .exit movem.l (sp)+,d2-d7/a2-a6
1543 cnop 0,4
1545 DeletePool movea.l _ExecBase,a1
1546 cmpi.w #39,LIB_VERSION(a1)
1547 blt.b .nopools ; change to bra for debugging
1549 move.l a6,-(sp)
1550 movea.l a1,a6
1551 CALLSYS DeletePool
1552 movea.l (sp)+,a6
1555 .nopools movem.l d2-d7/a2-a6,-(sp)
1556 move.l a0,d2 ; first block
1557 beq.b .exit ; safety check
1559 movea.l a1,a6
1561 .loop movea.l d2,a1 ; pointer to block
1562 move.l (a1),d0 ; size of block
1563 move.l 12(a1),d2 ; next block
1564 CALLSYS FreeMem
1565 tst.l d2
1566 bne.b .loop
1568 .exit movem.l (sp)+,d2-d7/a2-a6
1571 cnop 0,4
1573 AllocPooled movea.l _ExecBase,a1
1574 cmpi.w #39,LIB_VERSION(a1)
1575 blt.b .nopools ; change to bra for debugging
1577 move.l a6,-(sp)
1578 movea.l a1,a6
1579 CALLSYS AllocPooled
1580 movea.l (sp)+,a6
1583 .nopools movem.l d2-d7/a2-a6,-(sp)
1584 move.l a0,d2
1585 beq.b .exit ; safety check
1587 addq.l #3,d0
1588 andi.b #$FC,d0 ; long align size
1590 movea.l a1,a6
1592 cmp.l 8(a0),d0 ; check threshold
1593 blt.b .chkpuddles ; allocate from puddles
1595 addi.l #24,d0 ; for header
1596 move.l d0,d3 ; save size
1597 move.l 4(a0),d1 ; mem attrs
1598 CALLSYS AllocMem
1599 movea.l d0,a0
1600 tst.l d0
1601 beq.b .exit ; no memory
1603 move.l d3,(a0) ; size of block
1604 clr.l 20(a0) ; no free space in here
1606 movea.l d2,a1 ; pool header
1607 move.l 12(a1),d1
1608 move.l a0,12(a1) ; splice in block
1609 move.l d1,12(a0) ; relink next block
1610 lea 24(a0),a0 ; skip over header
1612 .exit move.l a0,d0
1613 movem.l (sp)+,d2-d7/a2-a6
1616 cnop 0,4
1618 .chkpuddles cmp.l 20(a0),d0 ; check free space
1619 blt.b .gotspace
1621 movea.l 12(a0),a0 ; next block
1622 move.l a0,d1
1623 bne.b .chkpuddles
1625 ; not enough free space in existing puddles, create another
1627 move.l d0,d6 ; save size
1629 movea.l d2,a0 ; pool header
1630 movem.l (a0),d3-d5
1631 movem.l (a0),d0-d1
1632 CALLSYS AllocMem ; get block
1633 movea.l d0,a0
1634 tst.l d0
1635 beq.b .out ; no memory!
1637 movea.l d2,a1 ; pool header
1638 movem.l d3-d5,(a0) ; puddleSize, Flags,Threshold
1639 move.l 12(a1),12(a0) ; next block
1640 move.l a0,12(a1) ; splice in block
1641 lea 24(a0),a1 ; first free location here
1642 move.l a1,16(a0)
1643 subi.l #24,d3 ; for header info
1644 move.l d3,20(a0) ; amount free in this block
1646 move.l d6,d0 ; restore size
1648 .gotspace sub.l d0,20(a0) ; sub from amount free
1649 bmi.b .err ; threshold >= puddlesize!
1651 move.l 16(a0),a1 ; free space
1652 add.l d0,16(a0) ; next free space
1654 movea.l a1,a0
1655 bra.b .out
1657 .err add.l d0,20(a0) ; restore free space
1658 moveq #0,d0
1659 suba.l a0,a0 ; no memory
1661 .out move.l a0,d0
1662 movem.l (sp)+,d2-d7/a2-a6
1665 ;------------------------------------------------------------------------
1666 ;------------------------------------------------------------------------
1668 cnop 0,4
1670 MUSMemPtr dc.l 0
1671 MUSMemSize dc.l 0
1673 SegList dc.l 0
1674 _ExecBase dc.l 0
1675 _DOSBase dc.l 0
1676 LookupMem dc.l 0
1677 vol_lookup dc.l 0
1679 ;------------------------------------------------------------------------
1681 period dc.w 325 ; NTSC 11025 KHz
1682 sfx_volume dc.w 64
1683 mus_volume dc.w 64
1684 mus_playing dc.b 0
1685 mus_looping dc.b 0
1687 ;------------------------------------------------------------------------
1689 cnop 0,4
1691 AudioPort dc.l 0
1692 AudioIO dc.l 0
1694 AInt0 dc.l 0,0
1695 dc.b NT_INTERRUPT,0 ; LN_TYPE, LN_PRI
1696 dc.l AIntName ; LN_NAME
1697 dc.l 0 ; IS_DATA
1698 dc.l AudioINT0 ; IS_CODE
1700 MusPtr dc.l 0
1701 MusIndex dc.l 0
1702 MusDelay dc.l 0
1703 OldAInt0 dc.l 0
1705 AudioAlloc dc.b $0F ; Amiga channels to allocate
1707 GfxName dc.b 'graphics.library',0
1708 DOSName dc.b 'dos.library',0
1709 AudioName dc.b 'audio.device',0
1710 AIntName dc.b 'DOOM Sound Server',0
1712 ;--------------------------------------
1714 CNOP 0,4
1716 ; bit set if voice is in use (0-15=music voices,16-31=sfx voices)
1718 VoiceAvail dc.l 0
1720 chip_buffer dc.l chipBuffer
1721 chip_offset dc.l 512
1723 ;--------------------------------------------------------------------
1725 CNOP 0,4
1727 NoteTable dc.l 65536/64,69433/64,73562/64,77936/64,82570/64,87480/64,92682/64,98193/64,104032/64,110218/64,116772/64,123715/64
1728 dc.l 65536/32,69433/32,73562/32,77936/32,82570/32,87480/32,92682/32,98193/32,104032/32,110218/32,116772/32,123715/32
1729 dc.l 65536/16,69433/16,73562/16,77936/16,82570/16,87480/16,92682/16,98193/16,104032/16,110218/16,116772/16,123715/16
1730 dc.l 65536/8,69433/8,73562/8,77936/8,82570/8,87480/8,92682/8,98193/8,104032/8,110218/8,116772/8,123715/8
1731 dc.l 65536/4,69433/4,73562/4,77936/4,82570/4,87480/4,92682/4,98193/4,104032/4,110218/4,116772/4,123715/4
1732 dc.l 65536/2,69433/2,73562/2,77936/2,82570/2,87480/2,92682/2,98193/2,104032/2,110218/2,116772/2,123715/2
1733 dc.l 65536,69433,73562,77936,82570,87480,92682,98193,104032,110218,116772,123715
1734 dc.l 65536*2,69433*2,73562*2,77936*2,82570*2,87480*2,92682*2,98193*2,104032*2,110218*2,116772*2,123715*2
1735 dc.l 65536*4,69433*4,73562*4,77936*4,82570*4,87480*4,92682*4,98193*4,104032*4,110218*4,116772*4,123715*4
1736 dc.l 65536*8,69433*8,73562*8,77936*8,82570*8,87480*8,92682*8,98193*8,104032*8,110218*8,116772*8,123715*8
1737 dc.l 65536*16,69433*16,73562*16,77936*16,82570*16,87480*16,92682*16,98193*16
1739 ;------------------------------------------------------------------------
1741 PitchTable:
1743 pitch_ix SET 128
1745 REPT 128
1746 dc.l -3678*pitch_ix/64
1747 pitch_ix SET pitch_ix-1
1748 ENDR
1750 REPT 128
1751 dc.l 3897*pitch_ix/64
1752 pitch_ix SET pitch_ix+1
1753 ENDR
1755 ;------------------------------------------------------------------------
1757 STRUCTURE MusChannel,0
1758 APTR ch_Instr
1759 APTR ch_Map
1760 ULONG ch_Pitch
1761 APTR ch_LtVol
1762 APTR ch_RtVol
1763 BYTE ch_Vol
1764 BYTE ch_Pan
1767 CNOP 0,4
1769 Channels dc.l Channel0,Channel1,Channel2,Channel3
1770 dc.l Channel4,Channel5,Channel6,Channel7
1771 dc.l Channel8,Channel9,Channel10,Channel11
1772 dc.l Channel12,Channel13,Channel14,Channel15
1775 CNOP 0,4
1777 Channel0 dc.l 0 ; instrument
1778 dc.l Channel0Map ; note to voice map
1779 dc.l 0 ; pitch wheel setting
1780 dc.l 0 ; left volume table
1781 dc.l 0 ; right volume table
1782 dc.b 0 ; volume
1783 dc.b 0 ; pan setting
1785 CNOP 0,4
1787 Channel1 dc.l 0 ; instrument
1788 dc.l Channel1Map ; note to voice map
1789 dc.l 0 ; pitch wheel setting
1790 dc.l 0 ; left volume table
1791 dc.l 0 ; right volume table
1792 dc.b 0 ; volume
1793 dc.b 0 ; pan setting
1795 CNOP 0,4
1797 Channel2 dc.l 0 ; instrument
1798 dc.l Channel2Map ; note to voice map
1799 dc.l 0 ; pitch wheel setting
1800 dc.l 0 ; left volume table
1801 dc.l 0 ; right volume table
1802 dc.b 0 ; volume
1803 dc.b 0 ; pan setting
1805 CNOP 0,4
1807 Channel3 dc.l 0 ; instrument
1808 dc.l Channel3Map ; note to voice map
1809 dc.l 0 ; pitch wheel setting
1810 dc.l 0 ; left volume table
1811 dc.l 0 ; right volume table
1812 dc.b 0 ; volume
1813 dc.b 0 ; pan setting
1815 CNOP 0,4
1817 Channel4 dc.l 0 ; instrument
1818 dc.l Channel4Map ; note to voice map
1819 dc.l 0 ; pitch wheel setting
1820 dc.l 0 ; left volume table
1821 dc.l 0 ; right volume table
1822 dc.b 0 ; volume
1823 dc.b 0 ; pan setting
1825 CNOP 0,4
1827 Channel5 dc.l 0 ; instrument
1828 dc.l Channel5Map ; note to voice map
1829 dc.l 0 ; pitch wheel setting
1830 dc.l 0 ; left volume table
1831 dc.l 0 ; right volume table
1832 dc.b 0 ; volume
1833 dc.b 0 ; pan setting
1835 CNOP 0,4
1837 Channel6 dc.l 0 ; instrument
1838 dc.l Channel6Map ; note to voice map
1839 dc.l 0 ; pitch wheel setting
1840 dc.l 0 ; left volume table
1841 dc.l 0 ; right volume table
1842 dc.b 0 ; volume
1843 dc.b 0 ; pan setting
1845 CNOP 0,4
1847 Channel7 dc.l 0 ; instrument
1848 dc.l Channel7Map ; note to voice map
1849 dc.l 0 ; pitch wheel setting
1850 dc.l 0 ; left volume table
1851 dc.l 0 ; right volume table
1852 dc.b 0 ; volume
1853 dc.b 0 ; pan setting
1855 CNOP 0,4
1857 Channel8 dc.l 0 ; instrument
1858 dc.l Channel8Map ; note to voice map
1859 dc.l 0 ; pitch wheel setting
1860 dc.l 0 ; left volume table
1861 dc.l 0 ; right volume table
1862 dc.b 0 ; volume
1863 dc.b 0 ; pan setting
1865 CNOP 0,4
1867 Channel9 dc.l 0 ; instrument
1868 dc.l Channel9Map ; note to voice map
1869 dc.l 0 ; pitch wheel setting
1870 dc.l 0 ; left volume table
1871 dc.l 0 ; right volume table
1872 dc.b 0 ; volume
1873 dc.b 0 ; pan setting
1875 CNOP 0,4
1877 Channel10 dc.l 0 ; instrument
1878 dc.l Channel10Map ; note to voice map
1879 dc.l 0 ; pitch wheel setting
1880 dc.l 0 ; left volume table
1881 dc.l 0 ; right volume table
1882 dc.b 0 ; volume
1883 dc.b 0 ; pan setting
1885 CNOP 0,4
1887 Channel11 dc.l 0 ; instrument
1888 dc.l Channel11Map ; note to voice map
1889 dc.l 0 ; pitch wheel setting
1890 dc.l 0 ; left volume table
1891 dc.l 0 ; right volume table
1892 dc.b 0 ; volume
1893 dc.b 0 ; pan setting
1895 CNOP 0,4
1897 Channel12 dc.l 0 ; instrument
1898 dc.l Channel12Map ; note to voice map
1899 dc.l 0 ; pitch wheel setting
1900 dc.l 0 ; left volume table
1901 dc.l 0 ; right volume table
1902 dc.b 0 ; volume
1903 dc.b 0 ; pan setting
1905 CNOP 0,4
1907 Channel13 dc.l 0 ; instrument
1908 dc.l Channel13Map ; note to voice map
1909 dc.l 0 ; pitch wheel setting
1910 dc.l 0 ; left volume table
1911 dc.l 0 ; right volume table
1912 dc.b 0 ; volume
1913 dc.b 0 ; pan setting
1915 CNOP 0,4
1917 Channel14 dc.l 0 ; instrument
1918 dc.l Channel14Map ; note to voice map
1919 dc.l 0 ; pitch wheel setting
1920 dc.l 0 ; left volume table
1921 dc.l 0 ; right volume table
1922 dc.b 0 ; volume
1923 dc.b 0 ; pan setting
1925 CNOP 0,4
1927 Channel15 dc.l 0 ; instrument
1928 dc.l Channel15Map ; note to voice map
1929 dc.l 0 ; pitch wheel setting
1930 dc.l 0 ; left volume table
1931 dc.l 0 ; right volume table
1932 dc.b 0 ; volume
1933 dc.b 0 ; pan setting
1936 CNOP 0,4
1938 Channel0Map dcb.b 128,0
1939 Channel1Map dcb.b 128,0
1940 Channel2Map dcb.b 128,0
1941 Channel3Map dcb.b 128,0
1942 Channel4Map dcb.b 128,0
1943 Channel5Map dcb.b 128,0
1944 Channel6Map dcb.b 128,0
1945 Channel7Map dcb.b 128,0
1946 Channel8Map dcb.b 128,0
1947 Channel9Map dcb.b 128,0
1948 Channel10Map dcb.b 128,0
1949 Channel11Map dcb.b 128,0
1950 Channel12Map dcb.b 128,0
1951 Channel13Map dcb.b 128,0
1952 Channel14Map dcb.b 128,0
1953 Channel15Map dcb.b 128,0
1955 ;--------------------------------------
1957 STRUCTURE AudioVoice,0
1958 APTR vc_Next
1959 APTR vc_Channel
1960 APTR vc_Wave
1961 ULONG vc_Index
1962 ULONG vc_Step
1963 ULONG vc_Loop
1964 ULONG vc_Length
1965 APTR vc_LtVol
1966 APTR vc_RtVol
1967 BYTE vc_Flags ; b7 = SFX, b1 = RLS, b0 = EN
1969 CNOP 0,4
1971 Voices dc.l Voice0,Voice1,Voice2,Voice3
1972 dc.l Voice4,Voice5,Voice6,Voice7
1973 dc.l Voice8,Voice9,Voice10,Voice11
1974 dc.l Voice12,Voice13,Voice14,Voice15
1976 sfxVoiceTbl dc.l Voice16,Voice17,Voice18,Voice19
1977 dc.l Voice20,Voice21,Voice22,Voice23
1978 dc.l Voice24,Voice25,Voice26,Voice27
1979 dc.l Voice28,Voice29,Voice30,Voice31
1981 ; Music Voices
1983 CNOP 0,4
1985 Voice0 dc.l Voice1
1986 dc.l 0 ; channel back-link
1987 dc.l 0 ; instrument wave data
1988 dc.l 0 ; sample index
1989 dc.l 0 ; sample rate
1990 dc.l 0 ; instrument loop point
1991 dc.l 0 ; instrument data length
1992 dc.l 0 ; left volume table
1993 dc.l 0 ; right volume table
1994 dc.b 0 ; voice flags
1996 CNOP 0,4
1998 Voice1 dc.l Voice2
1999 dc.l 0 ; channel back-link
2000 dc.l 0 ; instrument wave data
2001 dc.l 0 ; sample index
2002 dc.l 0 ; sample rate
2003 dc.l 0 ; instrument loop point
2004 dc.l 0 ; instrument data length
2005 dc.l 0 ; left volume table
2006 dc.l 0 ; right volume table
2007 dc.b 0 ; voice flags
2009 CNOP 0,4
2011 Voice2 dc.l Voice3
2012 dc.l 0 ; channel back-link
2013 dc.l 0 ; instrument wave data
2014 dc.l 0 ; sample index
2015 dc.l 0 ; sample rate
2016 dc.l 0 ; instrument loop point
2017 dc.l 0 ; instrument data length
2018 dc.l 0 ; left volume table
2019 dc.l 0 ; right volume table
2020 dc.b 0 ; voice flags
2022 CNOP 0,4
2024 Voice3 dc.l Voice4
2025 dc.l 0 ; channel back-link
2026 dc.l 0 ; instrument wave data
2027 dc.l 0 ; sample index
2028 dc.l 0 ; sample rate
2029 dc.l 0 ; instrument loop point
2030 dc.l 0 ; instrument data length
2031 dc.l 0 ; left volume table
2032 dc.l 0 ; right volume table
2033 dc.b 0 ; voice flags
2035 CNOP 0,4
2037 Voice4 dc.l Voice5
2038 dc.l 0 ; channel back-link
2039 dc.l 0 ; instrument wave data
2040 dc.l 0 ; sample index
2041 dc.l 0 ; sample rate
2042 dc.l 0 ; instrument loop point
2043 dc.l 0 ; instrument data length
2044 dc.l 0 ; left volume table
2045 dc.l 0 ; right volume table
2046 dc.b 0 ; voice flags
2048 CNOP 0,4
2050 Voice5 dc.l Voice6
2051 dc.l 0 ; channel back-link
2052 dc.l 0 ; instrument wave data
2053 dc.l 0 ; sample index
2054 dc.l 0 ; sample rate
2055 dc.l 0 ; instrument loop point
2056 dc.l 0 ; instrument data length
2057 dc.l 0 ; left volume table
2058 dc.l 0 ; right volume table
2059 dc.b 0 ; voice flags
2061 CNOP 0,4
2063 Voice6 dc.l Voice7
2064 dc.l 0 ; channel back-link
2065 dc.l 0 ; instrument wave data
2066 dc.l 0 ; sample index
2067 dc.l 0 ; sample rate
2068 dc.l 0 ; instrument loop point
2069 dc.l 0 ; instrument data length
2070 dc.l 0 ; left volume table
2071 dc.l 0 ; right volume table
2072 dc.b 0 ; voice flags
2074 CNOP 0,4
2076 Voice7 dc.l Voice8
2077 dc.l 0 ; channel back-link
2078 dc.l 0 ; instrument wave data
2079 dc.l 0 ; sample index
2080 dc.l 0 ; sample rate
2081 dc.l 0 ; instrument loop point
2082 dc.l 0 ; instrument data length
2083 dc.l 0 ; left volume table
2084 dc.l 0 ; right volume table
2085 dc.b 0 ; voice flags
2087 CNOP 0,4
2089 Voice8 dc.l Voice9
2090 dc.l 0 ; channel back-link
2091 dc.l 0 ; instrument wave data
2092 dc.l 0 ; sample index
2093 dc.l 0 ; sample rate
2094 dc.l 0 ; instrument loop point
2095 dc.l 0 ; instrument data length
2096 dc.l 0 ; left volume table
2097 dc.l 0 ; right volume table
2098 dc.b 0 ; voice flags
2100 CNOP 0,4
2102 Voice9 dc.l Voice10
2103 dc.l 0 ; channel back-link
2104 dc.l 0 ; instrument wave data
2105 dc.l 0 ; sample index
2106 dc.l 0 ; sample rate
2107 dc.l 0 ; instrument loop point
2108 dc.l 0 ; instrument data length
2109 dc.l 0 ; left volume table
2110 dc.l 0 ; right volume table
2111 dc.b 0 ; voice flags
2113 CNOP 0,4
2115 Voice10 dc.l Voice11
2116 dc.l 0 ; channel back-link
2117 dc.l 0 ; instrument wave data
2118 dc.l 0 ; sample index
2119 dc.l 0 ; sample rate
2120 dc.l 0 ; instrument loop point
2121 dc.l 0 ; instrument data length
2122 dc.l 0 ; left volume table
2123 dc.l 0 ; right volume table
2124 dc.b 0 ; voice flags
2126 CNOP 0,4
2128 Voice11 dc.l Voice12
2129 dc.l 0 ; channel back-link
2130 dc.l 0 ; instrument wave data
2131 dc.l 0 ; sample index
2132 dc.l 0 ; sample rate
2133 dc.l 0 ; instrument loop point
2134 dc.l 0 ; instrument data length
2135 dc.l 0 ; left volume table
2136 dc.l 0 ; right volume table
2137 dc.b 0 ; voice flags
2139 CNOP 0,4
2141 Voice12 dc.l Voice13
2142 dc.l 0 ; channel back-link
2143 dc.l 0 ; instrument wave data
2144 dc.l 0 ; sample index
2145 dc.l 0 ; sample rate
2146 dc.l 0 ; instrument loop point
2147 dc.l 0 ; instrument data length
2148 dc.l 0 ; left volume table
2149 dc.l 0 ; right volume table
2150 dc.b 0 ; voice flags
2152 CNOP 0,4
2154 Voice13 dc.l Voice14
2155 dc.l 0 ; channel back-link
2156 dc.l 0 ; instrument wave data
2157 dc.l 0 ; sample index
2158 dc.l 0 ; sample rate
2159 dc.l 0 ; instrument loop point
2160 dc.l 0 ; instrument data length
2161 dc.l 0 ; left volume table
2162 dc.l 0 ; right volume table
2163 dc.b 0 ; voice flags
2165 CNOP 0,4
2167 Voice14 dc.l Voice15
2168 dc.l 0 ; channel back-link
2169 dc.l 0 ; instrument wave data
2170 dc.l 0 ; sample index
2171 dc.l 0 ; sample rate
2172 dc.l 0 ; instrument loop point
2173 dc.l 0 ; instrument data length
2174 dc.l 0 ; left volume table
2175 dc.l 0 ; right volume table
2176 dc.b 0 ; voice flags
2178 CNOP 0,4
2180 Voice15 dc.l 0
2181 dc.l 0 ; channel back-link
2182 dc.l 0 ; instrument wave data
2183 dc.l 0 ; sample index
2184 dc.l 0 ; sample rate
2185 dc.l 0 ; instrument loop point
2186 dc.l 0 ; instrument data length
2187 dc.l 0 ; left volume table
2188 dc.l 0 ; right volume table
2189 dc.b 0 ; voice flags
2191 ; Sound Effect Voices
2193 CNOP 0,4
2195 Voice16 dc.l Voice17
2196 dc.l 0 ; channel back-link
2197 dc.l 0 ; instrument wave data
2198 dc.l 0 ; sample index
2199 dc.l 0 ; sample rate
2200 dc.l 0 ; instrument loop point
2201 dc.l 0 ; instrument data length
2202 dc.l 0 ; left volume table
2203 dc.l 0 ; right volume table
2204 dc.b 0 ; voice flags
2206 CNOP 0,4
2208 Voice17 dc.l Voice18
2209 dc.l 0 ; channel back-link
2210 dc.l 0 ; instrument wave data
2211 dc.l 0 ; sample index
2212 dc.l 0 ; sample rate
2213 dc.l 0 ; instrument loop point
2214 dc.l 0 ; instrument data length
2215 dc.l 0 ; left volume table
2216 dc.l 0 ; right volume table
2217 dc.b 0 ; voice flags
2219 CNOP 0,4
2221 Voice18 dc.l Voice19
2222 dc.l 0 ; channel back-link
2223 dc.l 0 ; instrument wave data
2224 dc.l 0 ; sample index
2225 dc.l 0 ; sample rate
2226 dc.l 0 ; instrument loop point
2227 dc.l 0 ; instrument data length
2228 dc.l 0 ; left volume table
2229 dc.l 0 ; right volume table
2230 dc.b 0 ; voice flags
2232 CNOP 0,4
2234 Voice19 dc.l Voice20
2235 dc.l 0 ; channel back-link
2236 dc.l 0 ; instrument wave data
2237 dc.l 0 ; sample index
2238 dc.l 0 ; sample rate
2239 dc.l 0 ; instrument loop point
2240 dc.l 0 ; instrument data length
2241 dc.l 0 ; left volume table
2242 dc.l 0 ; right volume table
2243 dc.b 0 ; voice flags
2245 CNOP 0,4
2247 Voice20 dc.l Voice21
2248 dc.l 0 ; channel back-link
2249 dc.l 0 ; instrument wave data
2250 dc.l 0 ; sample index
2251 dc.l 0 ; sample rate
2252 dc.l 0 ; instrument loop point
2253 dc.l 0 ; instrument data length
2254 dc.l 0 ; left volume table
2255 dc.l 0 ; right volume table
2256 dc.b 0 ; voice flags
2258 CNOP 0,4
2260 Voice21 dc.l Voice22
2261 dc.l 0 ; channel back-link
2262 dc.l 0 ; instrument wave data
2263 dc.l 0 ; sample index
2264 dc.l 0 ; sample rate
2265 dc.l 0 ; instrument loop point
2266 dc.l 0 ; instrument data length
2267 dc.l 0 ; left volume table
2268 dc.l 0 ; right volume table
2269 dc.b 0 ; voice flags
2271 CNOP 0,4
2273 Voice22 dc.l Voice23
2274 dc.l 0 ; channel back-link
2275 dc.l 0 ; instrument wave data
2276 dc.l 0 ; sample index
2277 dc.l 0 ; sample rate
2278 dc.l 0 ; instrument loop point
2279 dc.l 0 ; instrument data length
2280 dc.l 0 ; left volume table
2281 dc.l 0 ; right volume table
2282 dc.b 0 ; voice flags
2284 CNOP 0,4
2286 Voice23 dc.l Voice24
2287 dc.l 0 ; channel back-link
2288 dc.l 0 ; instrument wave data
2289 dc.l 0 ; sample index
2290 dc.l 0 ; sample rate
2291 dc.l 0 ; instrument loop point
2292 dc.l 0 ; instrument data length
2293 dc.l 0 ; left volume table
2294 dc.l 0 ; right volume table
2295 dc.b 0 ; voice flags
2297 CNOP 0,4
2299 Voice24 dc.l Voice25
2300 dc.l 0 ; channel back-link
2301 dc.l 0 ; instrument wave data
2302 dc.l 0 ; sample index
2303 dc.l 0 ; sample rate
2304 dc.l 0 ; instrument loop point
2305 dc.l 0 ; instrument data length
2306 dc.l 0 ; left volume table
2307 dc.l 0 ; right volume table
2308 dc.b 0 ; voice flags
2310 CNOP 0,4
2312 Voice25 dc.l Voice26
2313 dc.l 0 ; channel back-link
2314 dc.l 0 ; instrument wave data
2315 dc.l 0 ; sample index
2316 dc.l 0 ; sample rate
2317 dc.l 0 ; instrument loop point
2318 dc.l 0 ; instrument data length
2319 dc.l 0 ; left volume table
2320 dc.l 0 ; right volume table
2321 dc.b 0 ; voice flags
2323 CNOP 0,4
2325 Voice26 dc.l Voice27
2326 dc.l 0 ; channel back-link
2327 dc.l 0 ; instrument wave data
2328 dc.l 0 ; sample index
2329 dc.l 0 ; sample rate
2330 dc.l 0 ; instrument loop point
2331 dc.l 0 ; instrument data length
2332 dc.l 0 ; left volume table
2333 dc.l 0 ; right volume table
2334 dc.b 0 ; voice flags
2336 CNOP 0,4
2338 Voice27 dc.l Voice28
2339 dc.l 0 ; channel back-link
2340 dc.l 0 ; instrument wave data
2341 dc.l 0 ; sample index
2342 dc.l 0 ; sample rate
2343 dc.l 0 ; instrument loop point
2344 dc.l 0 ; instrument data length
2345 dc.l 0 ; left volume table
2346 dc.l 0 ; right volume table
2347 dc.b 0 ; voice flags
2349 CNOP 0,4
2351 Voice28 dc.l Voice29
2352 dc.l 0 ; channel back-link
2353 dc.l 0 ; instrument wave data
2354 dc.l 0 ; sample index
2355 dc.l 0 ; sample rate
2356 dc.l 0 ; instrument loop point
2357 dc.l 0 ; instrument data length
2358 dc.l 0 ; left volume table
2359 dc.l 0 ; right volume table
2360 dc.b 0 ; voice flags
2362 CNOP 0,4
2364 Voice29 dc.l Voice30
2365 dc.l 0 ; channel back-link
2366 dc.l 0 ; instrument wave data
2367 dc.l 0 ; sample index
2368 dc.l 0 ; sample rate
2369 dc.l 0 ; instrument loop point
2370 dc.l 0 ; instrument data length
2371 dc.l 0 ; left volume table
2372 dc.l 0 ; right volume table
2373 dc.b 0 ; voice flags
2375 CNOP 0,4
2377 Voice30 dc.l Voice31
2378 dc.l 0 ; channel back-link
2379 dc.l 0 ; instrument wave data
2380 dc.l 0 ; sample index
2381 dc.l 0 ; sample rate
2382 dc.l 0 ; instrument loop point
2383 dc.l 0 ; instrument data length
2384 dc.l 0 ; left volume table
2385 dc.l 0 ; right volume table
2386 dc.b 0 ; voice flags
2388 CNOP 0,4
2390 Voice31 dc.l 0
2391 dc.l 0 ; channel back-link
2392 dc.l 0 ; instrument wave data
2393 dc.l 0 ; sample index
2394 dc.l 0 ; sample rate
2395 dc.l 0 ; instrument loop point
2396 dc.l 0 ; instrument data length
2397 dc.l 0 ; left volume table
2398 dc.l 0 ; right volume table
2399 dc.b 0 ; voice flags
2401 ;--------------------------------------
2403 STRUCTURE InstrumentRec,0
2404 APTR in_Wave
2405 ULONG in_Loop
2406 ULONG in_Length
2407 BYTE in_Flags
2408 BYTE in_Base
2411 CNOP 0,4
2413 Instruments dcb.l 256,0
2415 CNOP 0,4
2417 QuietInst dc.l 0
2418 dc.l 0
2419 dc.l 0
2420 dc.b 0
2421 dc.b 0
2424 CNOP 0,4
2426 InstrHandle dc.l 0
2427 InstrFile dc.l InstrName
2428 InstrPool dc.l 0
2430 InstrName dc.b 'MIDI_Instruments',0
2432 CNOP 0,4
2434 validInstr dc.b %11111111 ; (00-07) Piano
2435 dc.b %11111111 ; (08-0F) Chrom Perc
2436 dc.b %11111111 ; (10-17) Organ
2437 dc.b %11111111 ; (18-1F) Guitar
2438 dc.b %11111111 ; (20-27) Bass
2439 dc.b %11111111 ; (28-2F) Strings
2440 dc.b %11111111 ; (30-37) Ensemble
2441 dc.b %11111111 ; (38-3F) Brass
2442 dc.b %11111111 ; (40-47) Reed
2443 dc.b %11111111 ; (48-4F) Pipe
2444 dc.b %11111111 ; (50-57) Synth Lead
2445 dc.b %11111111 ; (58-5F) Synth Pad
2446 dc.b %11111111 ; (60-67) Synth Effects
2447 dc.b %11111111 ; (68-6F) Ethnic
2448 dc.b %11111111 ; (70-77) Percussive
2449 dc.b %11111111 ; (78-7F) SFX
2450 dc.b %00000001 ; (80-87) invalid,Drum
2451 dc.b %11111111 ; (88-8F) Drums/Clap/Hi-Hat
2452 dc.b %11111111 ; (90-97) Hi-Hats/Toms/Cymb1
2453 dc.b %11111111 ; (98-9F) Cymbals/Bells/Slap
2454 dc.b %11111111 ; (A0-A7) Bongos/Congas/Timb
2455 dc.b %11111111 ; (A8-AF) Agogo/Whistles/Gui
2456 dc.b %11111100 ; (B0-B7) Claves/Block/Trian
2457 dc.b %00000000 ; (B8-BF) invalid
2458 dc.b %00000000 ; (C0-C7)
2459 dc.b %00000000 ; (C8-CF)
2460 dc.b %00000000 ; (D0-D7)
2461 dc.b %00000000 ; (D8-DF)
2462 dc.b %00000000 ; (E0-E7)
2463 dc.b %00000000 ; (E8-EF)
2464 dc.b %00000000 ; (F0-F7)
2465 dc.b %00000000 ; (F8-FF)
2467 ;--------------------------------------------------------------------
2468 section PlayMusChip,data_c
2470 chipBuffer dcb.b 1024,0
2472 ClearBuf dcb.b 160,0
2474 ;------------------------------------------------------------------------
2475 section PlayMusBSS,bss
2477 tempAudio ds.b 256
2479 ;------------------------------------------------------------------------