home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #2 / amigaacscoverdisc1998-021998.iso / games / doom / adoom / src / amiga_music.s < prev    next >
Text File  |  1998-01-08  |  41KB  |  1,884 lines

  1.         mc68020
  2.         multipass
  3.         debug    on,lattice4
  4.  
  5. ; 2 channel .MUS player
  6. ;
  7. ; Derived by Peter McGavin,
  8. ; mostly by cutting and pasting large chunks of code from Amiga .MUS player
  9. ; originally by Joseph Fenton, Microcode Solutions, jlfenton@ctaz.com
  10. ; and his brother Michael.
  11.  
  12. ; void I_InitMusic (void);
  13.  
  14. ; void I_ShutdownMusic (void);
  15.  
  16. ; void I_SetMusicVolume (int volume);    // Volume.
  17.  
  18. ; void I_PauseSong (int handle);    // PAUSE game handling.
  19.  
  20. ; void I_ResumeSong (int handle);
  21.  
  22. ; int I_RegisterSong (void *data);    // Registers a song handle to song data.
  23.  
  24. ;// Called by anything that wishes to start music.
  25. ;//  plays a song, and when the song is done,
  26. ;//  starts playing it again in an endless loop.
  27. ;// Horrible thing to do, considering.
  28. ; void I_PlaySong (int handle, int looping);
  29.  
  30. ; void I_StopSong (int handle);        // Stops a song over 3 seconds.
  31.  
  32. ; void I_UnRegisterSong (int handle);    // See above (register), then think backwards
  33.  
  34. ;------------------------------------------------------------------------
  35.         xdef    @I_InitMusic      ; Allocate audio channels and clear them.
  36.         xdef    @I_ShutdownMusic  ; Clear channels and free them.
  37.         xdef    @I_SetMusicVolume ; Do code equiv to J_VolBox.
  38.         xdef    @I_PauseSong      ; Do code equiv to DoPause.
  39.         xdef    @I_ResumeSong      ; Goes to J_PlayBox equiv code.
  40.         xdef    @I_RegisterSong      ; Do code equiv to LoadMUS; no need to actually load it
  41.                       ; as we are passed a pointer to it here.
  42.         xdef    @I_PlaySong      ; Do code equiv to J_PlayBox.
  43.         xdef    @I_StopSong      ; Do code equiv to J_StopBox.
  44.         xdef    @I_UnRegisterSong ; Do code equiv to FreeUpMUS.
  45.  
  46. ;------------------------------------------------------------------------
  47.         xref    _SysBase
  48.         xref    _DOSBase
  49.         xref    _custom
  50.         xref    _snd_MusicVolume
  51.         xref    _gametic
  52.         xref    _I_Error
  53.         xref    @M_CheckParm
  54.  
  55. ;------------------------------------------------------------------------
  56.  
  57. TICRATE        equ    35            ; see doomdef.h
  58.  
  59. CALLSYS        macro    ;FunctionName
  60.         jsr    _LVO\1(a6)
  61.         endm
  62.  
  63. CALLEXE        macro    ;FunctionName
  64.         movea.l    (_SysBase),a6
  65.         jsr    _LVO\1(a6)
  66.         endm
  67.  
  68. CALLDOS        macro    ;FunctionName
  69.         movea.l    (_DOSBase),a6
  70.         jsr    _LVO\1(a6)
  71.         endm
  72.  
  73. _LVOCreatePool    equ    -696            ; not in Macro68's autoincludes
  74. _LVODeletePool    equ    -702            ; not in Macro68's autoincludes
  75.  
  76. ;------------------------------------------------------------------------
  77. ; void I_InitMusic (void);
  78. ; Allocate audio channels and clear them.
  79.  
  80. @I_InitMusic    movem.l    d0-d7/a0-a6,-(sp)
  81.  
  82.         movea.l    #musicarg,a0
  83.         jsr    @M_CheckParm
  84.         tst.l    d0
  85.         beq    .exit
  86.  
  87.         suba.l    a1,a1            ; this task
  88.         CALLEXE FindTask
  89.         move.l    d0,AudioTask        ; set task to signal
  90.  
  91.         moveq    #0,d0
  92.         moveq    #0,d1
  93.         lea    AudioName,a0
  94.         lea    AudioIO,a1
  95.         clr.l    ioa_Length(a1)        ; don't allocate channels yet
  96.         CALLEXE OpenDevice
  97.         tst.l    d0
  98.         beq    1$
  99.  
  100.         move.l    #cantopenaud,-(sp)
  101.         jsr    _I_Error
  102.         bra    .exit
  103.  
  104. 1$        move.b    #-1,AudioOK
  105.         bsr    AllocChannels        ; allocate channels
  106. .exit
  107.         movem.l    (sp)+,d0-d7/a0-a6
  108.         rts
  109.  
  110. ;------------------------------------------------------------------------
  111. ; void I_ShutdownMusic (void);
  112. ; Clear channels and free them.
  113.  
  114. @I_ShutdownMusic
  115.         movem.l    d0-d7/a0-a6,-(sp)
  116.         tst.b    AudioOK
  117.         beq    .exit
  118.         bsr    @I_StopSong
  119.         bsr    @I_UnRegisterSong    ; kill old mus
  120.         bsr    FreeChannels
  121.         lea    AudioIO,a1
  122.         CALLEXE CloseDevice
  123.         clr.b    AudioCh
  124.         clr.b    AudioOK
  125. .exit        movem.l    (sp)+,d0-d7/a0-a6
  126.         rts
  127.  
  128. ;------------------------------------------------------------------------
  129. ; void I_SetMusicVolume (int volume);    // Volume.
  130. ; Do code equiv to J_VolBox.
  131.  
  132. @I_SetMusicVolume
  133.         movem.l    d0-d7/a0-a6,-(sp)
  134.         tst.b    AudioOK
  135.         beq    .exit
  136.  
  137.         move.l    d0,(_snd_MusicVolume)
  138.         lsl.w    #3,d0            ; * 8
  139.         move.w    d0,AudioCh2Vol
  140.         move.w    d0,AudioCh3Vol
  141. .exit        movem.l    (sp)+,d0-d7/a0-a6
  142.         rts
  143.  
  144. ;------------------------------------------------------------------------
  145. ; void I_PauseSong (int handle);    // PAUSE game handling.
  146. ; Do code equiv to DoPause.
  147.  
  148. @I_PauseSong    movem.l    d0-d7/a0-a6,-(sp)
  149.         tst.b    AudioOK
  150.         beq    .done
  151.  
  152.         btst    #1,Flags        ; file loaded?
  153.         beq.b    .done
  154.         bset    #0,MusFlag        ; stop
  155.         bclr    #2,Flags        ; playing?
  156.         beq.b    .done
  157. .stop        btst    #0,MusFlag        ; music stopped?
  158.         bne.b    .stop
  159.  
  160.         cmpi.b    #12,AudioCh        ; locked?
  161.         bne.b    .done
  162.         lea    _custom,a0        ; kill sound
  163.         moveq    #0,d0
  164.         move.w    d0,aud2+ac_vol(a0)
  165.         move.w    d0,aud3+ac_vol(a0)
  166.  
  167. .done        movem.l    (sp)+,d0-d7/a0-a6
  168.         rts
  169.  
  170. ;------------------------------------------------------------------------
  171. ; void I_ResumeSong (int handle);
  172. ; Goes to J_PlayBox equiv code.
  173.  
  174. @I_ResumeSong    movem.l    d0-d7/a0-a6,-(sp)
  175.         tst.b    AudioOK
  176.         beq    .exit
  177.  
  178.         btst    #1,Flags        ; file loaded?
  179.         beq.b    .nofile
  180.  
  181.         cmpi.b    #12,AudioCh        ; got all channels?
  182.         beq.b    .allch
  183.         bsr    AllocChannels        ; try to alloc, first
  184.         cmpi.b    #12,AudioCh        ; now?
  185.         beq.b    .allch
  186.  
  187.         move.l    #cantgetchan,-(sp)
  188.         jsr    _I_Error
  189.         bra    .exit
  190.  
  191. .allch        bset    #2,Flags        ; playing?
  192.         beq.b    .ok
  193. .nofile        rts
  194.  
  195. .ok        movea.l    MusPtr,a0
  196.         moveq    #0,d1
  197.         move.b    8(a0),d1        ; d1 = # of channels
  198.  
  199.         moveq    #0,d0
  200.         move.w    6(a0),d0        ; score start
  201.         ror.w    #8,d0
  202.         adda.l    d0,a0            ; a0 = start
  203.         bclr    #3,Flags        ; paused?
  204.         bne    .paused
  205.  
  206.         move.l    a0,MusIndex        ; MusIndex = start
  207.  
  208.         move.l    #QuietInst,Channel0
  209.         move.l    #QuietInst,Channel1
  210.         move.l    #QuietInst,Channel2
  211.         move.l    #QuietInst,Channel3
  212.         move.l    #QuietInst,Channel4
  213.         move.l    #QuietInst,Channel5
  214.         move.l    #QuietInst,Channel6
  215.         move.l    #QuietInst,Channel7
  216.         move.l    #QuietInst,Channel8
  217.         move.l    #QuietInst,Channel9
  218.         move.l    #QuietInst,Channel10
  219.         move.l    #QuietInst,Channel11
  220.         move.l    #QuietInst,Channel12
  221.         move.l    #QuietInst,Channel13
  222.         move.l    #QuietInst,Channel14
  223.         move.l    #QuietInst,Channel15
  224.  
  225.         clr.l    MusDelay        ; MusDelay = 0
  226.         clr.b    MusFlag            ; enable music
  227.         clr.l    VoiceAvail        ; all voices available
  228.  
  229.         clr.l    MyTicks            ; reset my timer
  230.  
  231. .paused        CALLEXE Disable
  232.         lea    _custom,a0
  233.         move.w    #$8200,intena(a0)    ; int enable
  234.         move.w    #$800c,dmacon(a0)    ; enable dma
  235.         bsr    AudioINT2        ; start audio
  236.         CALLSYS    Enable
  237.  
  238. .exit        movem.l    (sp)+,d0-d7/a0-a6
  239.         rts
  240.  
  241. ;------------------------------------------------------------------------
  242. ; int I_RegisterSong (void *data);    // Registers a song handle to song data.
  243. ; Do code equiv to LoadMUS; no need to actually load it
  244. ; as we are passed a pointer to it here.
  245.  
  246. @I_RegisterSong
  247.         movem.l    d0-d7/a0-a6,-(sp)
  248.         tst.b    AudioOK
  249.         beq    .done2
  250.  
  251.         move.l    a0,-(sp)        ; save data ptr
  252.  
  253.         bsr    @I_StopSong        ; stop current mus
  254.         bsr    @I_UnRegisterSong    ; kill old mus
  255.  
  256.         movea.l    (sp)+,a0
  257.         move.l    a0,MUSMemPtr
  258.  
  259.         cmpi.l    #$4D55531A,(a0)        ; "MUS",26
  260.         bne    .uerror            ; not a mus file
  261.  
  262.         move.l    MUSMemPtr(pc),MusPtr
  263.  
  264.         bsr    TestMUSFile
  265.         beq    .berror
  266.  
  267. ;--------
  268.  
  269.         move.l    InstrFile,d1
  270.         move.l    #MODE_OLDFILE,d2
  271.         CALLDOS    Open
  272.         move.l    d0,InstrHandle
  273.         beq    .midierror
  274.  
  275.         move.l    #MEMF_CLEAR,d0        ; any memory
  276.         move.l    #65536,d1        ; puddle size
  277.         move.l    #32768,d2        ; threshold size
  278.         bsr    CreatePool
  279.         move.l    a0,InstrPool        ; this was d0
  280.         beq    .merror
  281.  
  282.         movea.l    a0,a2            ; so was this
  283.         movea.l    MusPtr,a3
  284.  
  285.         move.w    #255,d0
  286.         lea    Instruments,a0
  287. .setinstr    move.l    #QuietInst,(a0)+
  288.         dbra    d0,.setinstr
  289.  
  290.         move.w    $C(a3),d4        ; instrCnt
  291.         ror.w    #8,d4
  292.         subq.w    #1,d4            ; for dbra
  293.  
  294.         lea    $10(a3),a3        ; instruments[]
  295.  
  296. .instrloop    moveq    #14,d0
  297.         movea.l    a2,a0
  298.         bsr    AllocPooled
  299.  
  300.         moveq    #0,d2
  301.         move.b    (a3)+,d2        ; instrument #
  302.         moveq    #0,d1
  303.         move.b    (a3)+,d1        ; offset to next instr. #
  304.         adda.l    d1,a3            ; skip it (whatever it is?)
  305.  
  306.         lea    Instruments,a0
  307.         move.l    d0,(a0,d2.w*4)
  308.         beq    .merror
  309.  
  310.         movea.l    d0,a4            ; instrument record
  311.  
  312.         bftst    (validInstr){d2:1}
  313.         beq    .next            ; no instrument
  314.  
  315.         move.l    InstrHandle,d1
  316.         lsl.l    #2,d2
  317.         moveq    #OFFSET_BEGINNING,d3
  318.         CALLDOS    Seek
  319.  
  320.         move.l    InstrHandle,d1
  321.         move.l    a4,d2
  322.         moveq    #4,d3
  323.         CALLSYS    Read            ; get instrument offset
  324.         addq.l    #1,d0
  325.         beq    .ferror            ; can't read file
  326.  
  327.         move.l    InstrHandle,d1
  328.         move.l    (a4),d2
  329.         moveq    #OFFSET_BEGINNING,d3
  330.         CALLSYS    Seek
  331.  
  332.         move.l    InstrHandle,d1
  333.         move.l    a4,d2
  334.         moveq    #14,d3
  335.         CALLSYS    Read            ; get instrument header
  336.         addq.l    #1,d0
  337.         beq    .ferror            ; can't read file
  338.  
  339.         move.l    in_Length(a4),d0
  340.         swap    d0
  341.         movea.l    a2,a0
  342.         bsr    AllocPooled
  343.         move.l    d0,in_Wave(a4)        ; wave data buffer
  344.         beq    .merror
  345.  
  346.         move.l    InstrHandle,d1
  347.         move.l    d0,d2
  348.         move.l    in_Length(a4),d3
  349.         swap    d3
  350.         CALLDOS    Read            ; get instrument samples
  351.         addq.l    #1,d0
  352.         beq    .ferror            ; can't read file
  353.  
  354.         move.b    #1,in_Flags(a4)
  355. .next        dbra    d4,.instrloop
  356.  
  357.         bset    #1,Flags        ; file loaded
  358.         bsr    FillEventBlocks
  359.  
  360. .done        btst    #1,Flags        ; success?
  361.         bne.b    .exit
  362.         bsr    @I_UnRegisterSong    ; kill MUS and instruments
  363.  
  364. .exit        move.l    InstrHandle,d1
  365.         beq.b    .done2
  366.         CALLDOS    Close
  367.         clr.l    InstrHandle
  368.  
  369. .done2        moveq    #1,d0            ; return handle=1
  370.         movem.l    (sp)+,d0-d7/a0-a6
  371.         rts
  372.  
  373. ;---------
  374.  
  375. .midierror    move.l    #midifileproblem,-(sp)
  376.         jsr    _I_Error
  377.         bra    .done
  378.  
  379. .ferror        move.l    #dosproblem,-(sp)
  380.         jsr    _I_Error
  381.         bra    .done
  382.  
  383. .merror        move.l    #memproblem,-(sp)
  384.         jsr    _I_Error
  385.         bra    .done
  386.  
  387. .uerror        move.l    #notmusfile,-(sp)
  388.         jsr    _I_Error
  389.         bra    .done
  390.  
  391. .berror        move.l    #damagedfile,-(sp)
  392.         jsr    _I_Error
  393.         bra    .done
  394.  
  395. ;------------------------------------------------------------------------
  396. ;// Called by anything that wishes to start music.
  397. ;//  plays a song, and when the song is done,
  398. ;//  starts playing it again in an endless loop.
  399. ;// Horrible thing to do, considering.
  400. ; void I_PlaySong (int handle, int looping);
  401. ; Do code equiv to J_PlayBox.
  402.  
  403. @I_PlaySong    movem.l    d0-d7/a0-a6,-(sp)
  404.         tst.b    AudioOK
  405.         beq    .exit
  406.  
  407.         move.l    #TICRATE*30,d0
  408.         add.l    (_gametic),d0
  409.         move.l    d0,(musicdies)
  410.  
  411.         bsr    @I_ResumeSong
  412.  
  413. .exit        movem.l    (sp)+,d0-d7/a0-a6
  414.         rts
  415.  
  416. ;------------------------------------------------------------------------
  417. ; void I_StopSong (int handle);        // Stops a song over 3 seconds.
  418. ; Do code equiv to J_StopBox.
  419.  
  420. @I_StopSong    movem.l    d0-d7/a0-a6,-(sp)
  421.  
  422.         move.l    #0,(looping)
  423.         move.l    #0,(musicdies)
  424.  
  425.         tst.b    AudioOK
  426.         beq    .exit
  427.  
  428.         bsr    @I_PauseSong
  429.         bsr    KillAllAud
  430.  
  431. .exit        movem.l    (sp)+,d0-d7/a0-a6
  432.         rts
  433.  
  434. ;------------------------------------------------------------------------
  435. ; void I_UnRegisterSong (int handle);    // See above (register), then think backwards
  436. ; Do code equiv to FreeUpMUS.
  437.  
  438. @I_UnRegisterSong
  439.         movem.l    d0-d7/a0-a6,-(sp)
  440.  
  441.         tst.b    AudioOK
  442.         beq    .free
  443.  
  444.         bclr    #1,Flags        ; still have anything?
  445.         beq.b    .free
  446.  
  447.         clr.l    MUSMemPtr
  448.         clr.l    MUSMemSize
  449.  
  450. .instr        tst.l    InstrPool
  451.         beq.b    .free
  452.  
  453.         movea.l    InstrPool,a0
  454.         bsr    DeletePool
  455.         clr.l    InstrPool
  456.  
  457. .free        movem.l    (sp)+,d0-d7/a0-a6
  458.         rts
  459.  
  460. ;------------------------------------------------------------------------
  461. ;------------------------------------------------------------------------
  462.  
  463. FillEventBlocks    lea    EventBlocks,a4
  464.         movea.l    MusPtr(pc),a0
  465.         move.w    6(a0),d0
  466.         ror.w    #8,d0
  467.         lea    (a0,d0.w),a2        ; a2 = start
  468.         movea.l    a2,a1            ; a1 = a2
  469. .loop        bsr    NextDelay
  470.         move.l    a1,d0
  471.         sub.l    a2,d0            ; d0 = ptr - start
  472.         move.w    d0,(a4)+        ; store
  473.         addq.l    #1,d1
  474.         bne.b    .loop
  475.         clr.w    (a4)            ; end of offsets
  476.         rts
  477.  
  478. NextDelay    bsr.b    MyNextEvent
  479.         cmpi.b    #6,d1            ; score end
  480.         beq.b    .dd
  481.         tst.b    d0
  482.         bpl.b    NextDelay
  483.  
  484.         moveq    #0,d1            ; time = 0
  485. .d1        move.b    (a1)+,d0        ; get byte
  486.         bpl.b    .d2
  487.         andi.w    #$7F,d0            ; kill sign bit
  488.         or.b    d0,d1            ; time = time + 7 bits
  489.         lsl.l    #7,d1            ; * 128
  490.         bra.b    .d1            ; get next 7 bits
  491. .d2        or.b    d0,d1            ; time = time + last 7 bits
  492.         rts
  493.  
  494. .dd        moveq    #-1,d1
  495.         rts
  496.  
  497. MyNextEvent    move.b    (a1)+,d0        ; d0 = event
  498.         moveq    #$70,d1
  499.         and.b    d0,d1            ; d1 = type<<4
  500.         bne.b    .e1
  501.  
  502. .e0        addq.l    #1,a1            ; + value
  503.         rts
  504.  
  505. .e1        lsr.b    #4,d1            ; d1 = type
  506.         cmpi.b    #6,d1            ; score end?
  507.         bne.b    .e2
  508.         subq.l    #1,a1
  509. .ed        rts
  510. .e2        cmpi.b    #5,d1            ; no event
  511.         beq.b    .ed
  512.         cmpi.b    #7,d1            ; no event
  513.         beq.b    .ed
  514.         cmpi.b    #1,d1            ; play
  515.         beq.b    .ep
  516.         cmpi.b    #4,d1            ; change?
  517.         bne.b    .e0
  518.         addq.l    #2,a1            ; + value1, value2
  519.         rts
  520. .ep        moveq    #0,d4
  521.         tst.b    (a1)+            ; + note
  522.         bmi.b    .e0            ; (+ volume, if b7 set)
  523.         rts
  524.  
  525.         moveq    #1,d0
  526.         rts
  527.  
  528. ;------------------------------------------------------------------------
  529.  
  530. TestMUSFile    movea.l    MusPtr(pc),a0
  531.         move.l    MUSMemSize(pc),d3    ; d3 = total file size
  532.         moveq    #0,d0
  533.         move.w    4(a0),d0
  534.         beq    .fail
  535.         ror.w    #8,d0            ; score length
  536.         moveq    #0,d1
  537.         move.w    6(a0),d1
  538.         ror.w    #8,d1            ; score start
  539.         cmpi.w    #18,d1            ; start < 18? (1 instr.)
  540.         blt    .fail
  541.         add.l    d1,d0            ; d0 = total size
  542.  
  543. ;        cmp.l    d0,d3            ; = file size?
  544. ;        bne    .fail
  545.  
  546.         move.l    d0,d3
  547.         move.l    d3,MUSMemSize
  548.  
  549.         move.w    12(a0),d2
  550.         beq.b    .fail
  551.         ror.w    #8,d2            ; d2 = instr. count
  552.         subq.w    #1,d2
  553.         lea    16(a0),a1        ; a1 = * instr. list
  554. .loop        addq.l    #1,a1            ; skip instr. value
  555.         moveq    #0,d0
  556.         move.b    (a1)+,d0        ; d0 = offset to next instr.
  557.         adda.l    d0,a1            ; skip info (?)
  558.         dbra    d2,.loop        ; next
  559.         move.l    a1,d0            ; d0 = * data following list
  560.         sub.l    a0,d0            ; - file start
  561.         cmp.l    d0,d1            ; = start?
  562.         bne.b    .fail
  563.         move.b    -1(a0,d3.l),d0        ; get last byte
  564.         lsr.b    #4,d0
  565.         cmpi.b    #6,d0            ; last byte = $6x? (end)
  566.         bne.b    .fail
  567.         moveq    #1,d0            ; file okay
  568.         rts
  569. .fail        moveq    #0,d0            ; yikes!
  570.         rts
  571.  
  572. ;------------------------------------------------------------------------
  573. ;------------------------------------------------------------------------
  574.  
  575. ; stop, clear, turn off
  576.  
  577. KillAllAud    cmpi.b    #12,AudioCh        ; locked?
  578.         bne.b    .vk
  579.  
  580.         lea    _custom,a0
  581.         move.l    #ClearBuf,aud2(a0)    ; re-init
  582.         move.w    #80,aud2+ac_len(a0)
  583.         move.w    #162,aud2+ac_per(a0)
  584.         move.l    #ClearBuf,aud3(a0)
  585.         move.w    #80,aud3+ac_len(a0)
  586.         move.w    #162,aud3+ac_per(a0)
  587.  
  588. .vk        clr.b    Voice0+vc_Flags        ; disable voices
  589.         clr.b    Voice1+vc_Flags
  590.         clr.b    Voice2+vc_Flags
  591.         clr.b    Voice3+vc_Flags
  592.         clr.b    Voice4+vc_Flags
  593.         clr.b    Voice5+vc_Flags
  594.         clr.b    Voice6+vc_Flags
  595.         clr.b    Voice7+vc_Flags
  596.         clr.b    Voice8+vc_Flags
  597.         clr.b    Voice9+vc_Flags
  598.         clr.b    Voice10+vc_Flags
  599.         clr.b    Voice11+vc_Flags
  600.         clr.b    Voice12+vc_Flags
  601.         clr.b    Voice13+vc_Flags
  602.         clr.b    Voice14+vc_Flags
  603.         clr.b    Voice15+vc_Flags
  604.  
  605.         rts
  606.  
  607. ;------------------------------------------------------------------------
  608. ;------------------------------------------------------------------------
  609.  
  610. AllocChannels    lea    AudioIO,a1
  611.         move.w    #ADCMD_ALLOCATE,IO_COMMAND(a1)
  612.         move.b    #ADIOF_NOWAIT+IOF_QUICK,IO_FLAGS(a1)
  613.         move.l    #AudioAlloc,ioa_Data(a1)
  614.         move.l    #1,ioa_Length(a1)
  615.         movea.l    IO_DEVICE(a1),a6
  616.         jsr    DEV_BEGINIO(a6)
  617.         tst.l    d0
  618.         beq    1$
  619.  
  620.         move.l    #cantgetchan,-(sp)
  621.         jsr    _I_Error
  622.         bra    .exit
  623.  
  624. 1$        lea    AudioIO,a1
  625.         move.w    #ADCMD_LOCK,IO_COMMAND(a1)
  626.         CALLEXE SendIO
  627.  
  628.         move.l    AudioIO+IO_UNIT,d0
  629.         move.b    d0,AudioCh
  630.         cmpi.b    #12,d0            ; all channels?
  631.         beq    2$
  632.  
  633.         move.l    #cantgetchan,-(sp)
  634.         jsr    _I_Error
  635.         bra    .exit
  636.  
  637. 2$        lea    _custom,a0
  638.         move.w    #$0600,intena(a0)    ; kill int enable
  639.         move.w    #$0600,intreq(a0)    ; kill request
  640.         move.w    #$00FF,adkcon(a0)    ; kill modulation
  641.         move.w    #$000C,dmacon(a0)    ; disable dma
  642.  
  643.         move.l    #ClearBuf,aud2(a0)
  644.         move.w    #80,aud2+ac_len(a0)
  645.         move.w    #162,aud2+ac_per(a0)
  646.         move.w    #0,aud2+ac_vol(a0)
  647.  
  648.         move.l    #ClearBuf,aud3(a0)
  649.         move.w    #80,aud3+ac_len(a0)
  650.         move.w    #162,aud3+ac_per(a0)
  651.         move.w    #0,aud3+ac_vol(a0)
  652.  
  653.         moveq    #INTB_AUD2,d0
  654.         lea    AInt2,a1
  655.         CALLEXE SetIntVector
  656.         move.l    d0,OldAInt2
  657.  
  658. .exit        rts
  659.  
  660. ;------------------------------------------------------------------------
  661.  
  662. FreeChannels    cmpi.b    #12,AudioCh
  663.         bne.b    .exit            ; no channels
  664.  
  665.         move.w    #$0600,intena(a0)    ; kill int enable
  666.         move.w    #$0600,intreq(a0)    ; kill request
  667.  
  668.         moveq    #INTB_AUD2,d0
  669.         movea.l    OldAInt2,a1
  670.         CALLEXE SetIntVector
  671.  
  672.         moveq    #$000c,d0
  673.         move.w    d0,_custom+dmacon    ; dma off
  674.         lea    AudioIO,a1
  675.         move.w    #ADCMD_FREE,IO_COMMAND(a1)
  676.         move.b    #IOF_QUICK,IO_FLAGS(a1)
  677.         movea.l    IO_DEVICE(a1),a6
  678.         jsr    DEV_BEGINIO(a6)
  679.         clr.l    AudioIO+IO_UNIT
  680.         clr.b    AudioCh
  681.  
  682. .exit        rts
  683.  
  684. ;--------------------------------------------------------------------
  685.  
  686.         cnop    0,16
  687.  
  688. AudioINT2    movem.l    d2-d6/a2-a4/a6,-(a7)
  689.  
  690.         btst    #0,MusFlag
  691.         beq.b    .cont
  692.  
  693.         lea    _custom,a0
  694.         move.w    #$0600,intena(a0)    ; kill int enable
  695.         move.w    #$0600,intreq(a0)    ; kill request
  696.  
  697.         clr.b    MusFlag
  698.         bra    .exit
  699.  
  700. .cont        subq.l    #1,MusDelay
  701.         bpl.b    .setaudio
  702.  
  703.         bsr    NextEvent
  704.  
  705. .setaudio    bchg    #1,MusFlag        ; switch buffers
  706.  
  707.         btst    #6,Flags        ; gadget down?
  708.         bne.b    .gad
  709.         addq.l    #1,MyTicks        ; increment my timer
  710.  
  711. .gad        lea    Voice0,a0        ; music voices
  712.         lea    AudioCh2Buf,a2
  713.         bsr    FillBuffer
  714.  
  715.         lea    _custom,a0
  716.         move.w    #INTF_AUD2,intreq(a0)
  717.  
  718.         move.l    AudioCh2Ptr,aud2(a0)
  719.         move.w    #40,aud2+ac_len(a0)        ; 80 samples
  720.         move.w    #324,aud2+ac_per(a0)        ; 11048Hz
  721.         move.w    AudioCh2Vol,aud2+ac_vol(a0)
  722.  
  723.         move.l    AudioCh2Ptr,aud3(a0)
  724.         move.w    #40,aud3+ac_len(a0)        ; 80 samples
  725.         move.w    #324,aud3+ac_per(a0)        ; 11048Hz
  726.         move.w    AudioCh2Vol,aud3+ac_vol(a0)
  727.  
  728. .exit        movem.l    (a7)+,d2-d6/a2-a4/a6
  729.         moveq    #0,d0
  730.         rts
  731.  
  732. ;------------------------------------------------------------------------
  733.  
  734.         CNOP    0,16
  735.  
  736. FillBuffer    moveq    #0,d0
  737.         btst    #1,MusFlag
  738.         beq.b    .swap
  739.         move.l    #80,d0
  740. .swap        movea.l    (a2),a4            ; chip buffer
  741.         adda.l    d0,a4
  742.         move.l    a4,4(a2)        ; AudioChxPtr
  743.  
  744.         movea.l    a4,a1
  745.         moveq    #4,d0
  746. .cloop        clr.l    (a1)+
  747.         clr.l    (a1)+
  748.         clr.l    (a1)+
  749.         clr.l    (a1)+
  750.         dbra    d0,.cloop
  751.  
  752. .next        move.l    vc_Next(a0),d0        ; next voice
  753.         bne.b    .chkvoice
  754.         rts
  755.  
  756. .chkvoice    movea.l    d0,a0
  757.         btst    #0,vc_Flags(a0)
  758.         beq.b    .next            ; not enabled
  759.  
  760.  
  761. ;------------------
  762. ; do voice
  763.  
  764.         movea.l    a4,a1
  765.  
  766.         btst    #1,vc_Flags(a0)
  767.         beq.b    .1            ; not releasing
  768.  
  769.         subq.b    #1,vc_Vol(a0)
  770.         bpl.b    .1
  771.         clr.b    vc_Vol(a0)
  772.         clr.b    vc_Flags(a0)        ; voice off
  773.         bra.b    .next
  774.  
  775. .1        move.b    vc_Vol(a0),d5
  776.         bfffo    d5{24:8},d5        ; 0-127 -> 32-24
  777.         subi.b    #24,d5            ;          8-0
  778.         addq.b    #1,d5            ; /2
  779.  
  780.         movem.l    vc_Index(a0),d1-d4    ; index,step,loop,length
  781.  
  782.         movea.l    vc_Channel(a0),a3
  783.         move.l    ch_Pitch(a3),d0
  784.         muls.l    d0,d6:d2
  785.         move.w    d6,d2
  786.         swap    d2
  787.         add.l    vc_Step(a0),d2        ; final sample rate
  788.  
  789.         movea.l    vc_Wave(a0),a3        ; sample data
  790.  
  791.         moveq    #79,d6            ; 80 samples
  792.  
  793. .floop        moveq    #0,d0
  794.         swap    d1
  795.         move.b    (a3,d1.w),d0        ; sample
  796.         swap    d1
  797.         asr.b    d5,d0
  798.         add.b    d0,(a1)+
  799.  
  800.         add.l    d2,d1
  801.         cmp.l    d4,d1
  802.         blo.b    .2
  803.         sub.l    d4,d1
  804.         add.l    d3,d1
  805.         tst.l    d3
  806.         beq.b    .3            ; no looping
  807. .2        dbra    d6,.floop
  808.         bra.b    .done            ; done with voice 1
  809.  
  810. ; ran out of data
  811. .3        clr.b    vc_Flags(a0)        ; voice off
  812.  
  813. .done        move.l    d1,vc_Index(a0)
  814.         bra    .next
  815.  
  816. ;------------------------------------------------------------------------
  817.  
  818.         CNOP    0,16
  819.  
  820. NextEvent    movea.l    MusIndex,a1
  821.  
  822. .0        move.b    (a1)+,d0        ; get next event
  823.         move.b    d0,d1
  824.         lsr.b    #3,d1
  825.         andi.w    #$E,d1            ; d1 = event type * 2
  826.         lea    EventTable,a0
  827.         move.w    (a0,d1.w),d1
  828.         jsr    (a0,d1.w)        ; do event
  829.         tst.b    d0
  830.         bpl.b    .0            ; more events
  831.  
  832.         moveq    #0,d1            ; time = 0
  833. .1        move.b    (a1)+,d0        ; get byte
  834.         bpl.b    .2
  835.  
  836.         andi.w    #$7F,d0            ; kill sign bit
  837.         or.b    d0,d1            ; time = time + 7 bits
  838.         lsl.l    #7,d1            ; * 128
  839.         bra.b    .1            ; get next 7 bits
  840.  
  841. .2        or.b    d0,d1            ; time = time + last 7 bits
  842.         subq.l    #1,d1            ; delay = time - 1
  843.         bmi.b    .0            ; (no delay)
  844.  
  845.         btst    #6,Flags        ; gadget down?
  846.         beq.b    .nogad
  847.         btst    #7,Flags
  848.         beq.b    .rev
  849.         add.l    d1,MyTicks        ; add to my timer
  850.         addq.l    #1,MyTicks        ; + 1
  851.         lsr.l    #3,d1            ; delay = delay / 8
  852.         bra.b    .nogad
  853. .rev        bsr.b    PrevBlock
  854.  
  855. .nogad        move.l    d1,MusDelay        ; store delay
  856.         move.l    a1,MusIndex        ; store index
  857.         rts
  858.  
  859. PrevBlock    move.l    PrevDelay,d0
  860.         sub.l    d0,MyTicks        ; sub previous value
  861.         addq.l    #1,d1
  862.         move.l    d1,PrevDelay
  863.         move.l    a1,d1            ; d1 = current ptr
  864.         movea.l    MusPtr(pc),a0
  865.         move.w    6(a0),d0
  866.         ror.w    #8,d0
  867.         lea    (a0,d0.w),a0        ; a0 = start
  868.         cmp.l    a0,d1            ; at start?
  869.         beq.b    .done
  870.         lea    EventBlocks,a1
  871. .loop        moveq    #0,d0
  872.         move.w    (a1)+,d0        ; offset
  873.         beq.b    .done            ; (not found)
  874.         add.l    a0,d0            ; ptr
  875.         cmp.l    d1,d0            ; = current?
  876.         bne.b    .loop
  877.         subq.l    #4,a1
  878.         cmpa.l    #EventBlocks,a1        ; 2nd block?
  879.         bls.b    .done
  880.         moveq    #0,d0
  881.         move.w    -(a1),d0        ; offset prev block
  882.         add.l    a0,d0
  883.         movea.l    d0,a1            ; ptr = prev block
  884.         moveq    #0,d1            ; delay = 0
  885.         rts
  886. .done        movea.l    a0,a1            ; ptr = start
  887.         moveq    #0,d1            ; delay = 0
  888.         clr.l    MyTicks            ; reset timer
  889.         rts
  890.  
  891. ;------------------------------------------------------------------------
  892.  
  893. Release        moveq    #15,d1
  894.         and.b    d0,d1            ; d1 = channel
  895.  
  896.         lea    Channels,a0
  897.         movea.l    (a0,d1.w*4),a0        ; channel record
  898.         movea.l    ch_Map(a0),a0        ; channel map
  899.  
  900.         move.b    (a1)+,d1        ; note #
  901.         moveq    #0,d2
  902.         move.b    (a0,d1.w),d2        ; voice #
  903.         beq.b    .exit            ; no mapping
  904.  
  905.         clr.b    (a0,d1.w)        ; clear mapping
  906.         move.l    VoiceAvail,d3
  907.         bclr    d2,d3            ; voice free for use
  908.         move.l    d3,VoiceAvail
  909.  
  910.         lea    Voices,a0
  911.         movea.l    (a0,d2.w*4),a0        ; voice
  912.         bset    #1,vc_Flags(a0)        ; do release
  913.  
  914. .exit        rts
  915.  
  916. ;------------------------------------------------------------------------
  917.  
  918. PlayNote    moveq    #15,d1
  919.         and.b    d0,d1            ; d1 = channel
  920.  
  921.         lea    Channels,a0
  922.         movea.l    (a0,d1.w*4),a2        ; channel record
  923.         movea.l    ch_Map(a2),a0        ; channel map
  924.  
  925.         moveq    #-1,d2            ; no volume change
  926.         move.b    (a1)+,d1        ; note #
  927.         bclr    #7,d1
  928.         beq.b    .getvc            ; no volume
  929.  
  930.         moveq    #0,d2
  931.         move.b    (a1)+,d2        ; volume
  932.  
  933. .getvc        moveq    #0,d3
  934.         move.l    VoiceAvail,d4
  935. .vloop        bset    d3,d4
  936.         beq.b    .foundfree
  937.         addq.b    #1,d3
  938.         cmpi.b    #16,d3
  939.         bne.b    .vloop
  940. ; no free voices
  941.         rts
  942.  
  943.  
  944. .foundfree    move.b    d3,(a0,d1.w)        ; voice mapping
  945.         move.l    d4,VoiceAvail
  946.  
  947.         lea    Voices,a0
  948.         movea.l    (a0,d3.w*4),a3        ; voice
  949.         btst    #7,vc_Flags(a3)
  950.         bne.b    .exit            ; sfx using channel
  951.  
  952.         tst.b    d2
  953.         bmi.b    .skip
  954.         move.b    d2,ch_Vol(a2)        ; new channel volume
  955. .skip        move.b    ch_Vol(a2),vc_Vol(a3)
  956.  
  957.         moveq    #15,d2
  958.         and.b    d0,d2
  959.         cmpi.b    #15,d2
  960.         beq.b    .percussion
  961.  
  962.         move.l    ch_Instr(a2),a4        ; instrument record
  963.  
  964.         lea    NoteTable,a0
  965.         moveq    #72,d2            ; middle c
  966.         sub.b    in_Base(a4),d2
  967.         add.b    d1,d2
  968.         move.l    (a0,d2.w*4),vc_Step(a3)    ; step value for note
  969.  
  970.         clr.l    vc_Index(a3)
  971.  
  972.         move.l    a2,vc_Channel(a3)    ; back link (for pitch wheel)
  973.  
  974.         move.l    in_Wave(a4),vc_Wave(a3)
  975.         move.l    in_Loop(a4),vc_Loop(a3)
  976.         move.l    in_Length(a4),vc_Length(a3)
  977.         move.b    in_Flags(a4),vc_Flags(a3)
  978. .exit        rts
  979.  
  980. ; for the percussion channel, the note played sets the percussion instrument
  981.  
  982. .percussion    move.l    #65536,vc_Step(a3)    ; sample rate always 1.0
  983.  
  984.         clr.l    vc_Index(a3)
  985.  
  986.         move.l    a2,vc_Channel(a3)    ; back link
  987.  
  988.         addi.b    #100,d1            ; percussion instruments
  989.  
  990.         lea    Instruments,a0
  991.         move.l    (a0,d1.w*4),a0        ; instrument record
  992.         move.l    in_Wave(a0),vc_Wave(a3)
  993.         move.l    in_Loop(a0),vc_Loop(a3)
  994.         move.l    in_Length(a0),vc_Length(a3)
  995.         move.b    in_Flags(a0),vc_Flags(a3)
  996.         rts
  997.  
  998. ;------------------------------------------------------------------------
  999.  
  1000. Pitch        moveq    #15,d1
  1001.         and.b    d0,d1            ; d1 = channel
  1002.  
  1003.         lea    Channels,a0
  1004.         movea.l    (a0,d1.w*4),a2        ; channel record
  1005.  
  1006.         moveq    #0,d1
  1007.         move.b    (a1)+,d1        ; pitch wheel setting
  1008.         lea    PitchTable,a0
  1009.         move.l    (a0,d1.w*4),ch_Pitch(a2)
  1010.         rts
  1011.  
  1012. ;------------------------------------------------------------------------
  1013.  
  1014. Tempo        addq.l    #1,a1            ; skip value
  1015.         rts
  1016.  
  1017. ;------------------------------------------------------------------------
  1018.  
  1019. ChangeCtrl    moveq    #15,d1
  1020.         and.b    d0,d1            ; d1 = channel
  1021.  
  1022.         lea    Channels,a0
  1023.         movea.l    (a0,d1.w*4),a2        ; channel
  1024.  
  1025.         move.b    (a1)+,d1        ; get controller
  1026.  
  1027.         moveq    #0,d2
  1028.         move.b    (a1)+,d2        ; value
  1029.  
  1030.         tst.b    d1
  1031.         bne.b    .1
  1032.  
  1033. ; set channel instrument
  1034.  
  1035.         lea    Instruments,a0
  1036.         move.l    (a0,d2.w*4),ch_Instr(a2)
  1037.         bne.b    .0
  1038.         move.l    #QuietInst,ch_Instr(a2)
  1039. .0        rts
  1040.  
  1041. .1        cmpi.b    #3,d1            ; volume?
  1042.         bne.b    .2
  1043.  
  1044. ; set channel volume
  1045.  
  1046.         move.b    d2,ch_Vol(a2)
  1047.         rts
  1048.  
  1049. .2        cmpi.b    #4,d1            ; pan?
  1050.         bne.b    .exit
  1051.  
  1052. ; set channel pan
  1053.  
  1054.         move.b    d2,ch_Pan(a2)
  1055. .exit        rts
  1056.  
  1057. ;------------------------------------------------------------------------
  1058.  
  1059. NoEvent        rts
  1060.  
  1061. ;------------------------------------------------------------------------
  1062.  
  1063. EndScore    btst    #4,Flags        ; loop?
  1064.         beq.b    .loop
  1065.  
  1066.         lea    _custom,a0
  1067.         move.w    #$0600,intena(a0)    ; kill int enable
  1068.         move.w    #$0600,intreq(a0)    ; kill request
  1069.         clr.b    MusFlag            ; clear mus flag
  1070.         bclr    #2,Flags        ; kill playing flag
  1071.         moveq    #0,d0
  1072.         move.w    d0,aud2+ac_vol(a0)    ; kill old audio
  1073.         move.w    d0,aud3+ac_vol(a0)
  1074.         bsr    KillAllAud
  1075.         addq.l    #8,a7            ; pop NextEvent, AudioInt
  1076.         movem.l    (a7)+,d2-d6/a2-a4/a6    ; return from interrupt
  1077.         moveq    #0,d0
  1078.         rts
  1079.  
  1080. .loop        movea.l    MusPtr,a1
  1081.         moveq    #0,d1
  1082.         move.w    6(a1),d1        ; score start
  1083.         ror.w    #8,d1
  1084.         adda.l    d1,a1            ; a1 = start
  1085.  
  1086.         clr.l    MyTicks            ; reset my timer
  1087.         rts
  1088.  
  1089. ;------------------------------------------------------------------------
  1090. ;--------------------------------------------------------------------
  1091.  
  1092.         cnop    0,4
  1093.  
  1094. CreatePool    movea.l    _SysBase,a1
  1095.         cmpi.w    #39,LIB_VERSION(a1)
  1096.         blt.b    .nopools        ; change to bra for debugging
  1097.  
  1098.         move.l    a6,-(sp)
  1099.         movea.l    a1,a6
  1100.         CALLSYS    CreatePool
  1101.         movea.l    (sp)+,a6
  1102.         rts
  1103.  
  1104. .nopools    movem.l    d2-d7/a2-a6,-(sp)
  1105.         move.l    d0,d4            ; memory attributes
  1106.         move.l    d1,d3            ; amount to allocate when low
  1107.         move.l    d2,d5            ; size of when not to use pool
  1108.  
  1109.         exg.l    d0,d1            ; swap flags and size
  1110.         movea.l    a1,a6
  1111.         CALLSYS    AllocMem        ; get first block
  1112.         movea.l    d0,a0
  1113.         tst.l    d0
  1114.         beq.b    .exit            ; no memory!
  1115.  
  1116.         movem.l    d3-d5,(a0)        ; puddleSize, Flags,Threshold
  1117.         clr.l    12(a0)            ; no next block
  1118.         lea    24(a0),a1        ; first free location here
  1119.         move.l    a1,16(a0)
  1120.         subi.l    #24,d3            ; for header info
  1121.         move.l    d3,20(a0)        ; amount free in this block
  1122.  
  1123. .exit        movem.l    (sp)+,d2-d7/a2-a6
  1124.         rts
  1125.  
  1126.         cnop    0,4
  1127.  
  1128. DeletePool    movea.l    _SysBase,a1
  1129.         cmpi.w    #39,LIB_VERSION(a1)
  1130.         blt.b    .nopools        ; change to bra for debugging
  1131.  
  1132.         move.l    a6,-(sp)
  1133.         movea.l    a1,a6
  1134.         CALLSYS    DeletePool
  1135.         movea.l    (sp)+,a6
  1136.         rts
  1137.  
  1138. .nopools    movem.l    d2-d7/a2-a6,-(sp)
  1139.         move.l    a0,d2            ; first block
  1140.         beq.b    .exit            ; safety check
  1141.  
  1142.         movea.l    a1,a6
  1143.  
  1144. .loop        movea.l    d2,a1            ; pointer to block
  1145.         move.l    (a1),d0            ; size of block
  1146.         move.l    12(a1),d2        ; next block
  1147.         CALLSYS    FreeMem
  1148.         tst.l    d2
  1149.         bne.b    .loop
  1150.  
  1151. .exit        movem.l    (sp)+,d2-d7/a2-a6
  1152.         rts
  1153.  
  1154.         cnop    0,4
  1155.  
  1156. AllocPooled    movea.l    _SysBase,a1
  1157.         cmpi.w    #39,LIB_VERSION(a1)
  1158.         blt.b    .nopools        ; change to bra for debugging
  1159.  
  1160.         move.l    a6,-(sp)
  1161.         movea.l    a1,a6
  1162.         CALLSYS    AllocPooled
  1163.         movea.l    (sp)+,a6
  1164.         rts
  1165.  
  1166. .nopools    movem.l    d2-d7/a2-a6,-(sp)
  1167.         move.l    a0,d2
  1168.         beq.b    .exit            ; safety check
  1169.  
  1170.         addq.l    #3,d0
  1171.         andi.b    #$FC,d0            ; long align size
  1172.  
  1173.         movea.l    a1,a6
  1174.  
  1175.         cmp.l    8(a0),d0        ; check threshold
  1176.         blt.b    .chkpuddles        ; allocate from puddles
  1177.  
  1178.         addi.l    #24,d0            ; for header
  1179.         move.l    d0,d3            ; save size
  1180.         move.l    4(a0),d1        ; mem attrs
  1181.         CALLSYS    AllocMem
  1182.         movea.l    d0,a0
  1183.         tst.l    d0
  1184.         beq.b    .exit            ; no memory
  1185.  
  1186.         move.l    d3,(a0)            ; size of block
  1187.         clr.l    20(a0)            ; no free space in here
  1188.  
  1189.         movea.l    d2,a1            ; pool header
  1190.         move.l    12(a1),d1
  1191.         move.l    a0,12(a1)        ; splice in block
  1192.         move.l    d1,12(a0)        ; relink next block
  1193.         lea    24(a0),a0        ; skip over header
  1194.  
  1195. .exit        move.l    a0,d0
  1196.         movem.l    (sp)+,d2-d7/a2-a6
  1197.         rts
  1198.  
  1199.         cnop    0,4
  1200.  
  1201. .chkpuddles    cmp.l    20(a0),d0        ; check free space
  1202.         blt.b    .gotspace
  1203.  
  1204.         movea.l    12(a0),a0        ; next block
  1205.         move.l    a0,d1
  1206.         bne.b    .chkpuddles
  1207.  
  1208. ; not enough free space in existing puddles, create another
  1209.  
  1210.         move.l    d0,d6            ; save size
  1211.  
  1212.         movea.l    d2,a0            ; pool header
  1213.         movem.l    (a0),d3-d5
  1214.         movem.l    (a0),d0-d1
  1215.         CALLSYS    AllocMem        ; get block
  1216.         movea.l    d0,a0
  1217.         tst.l    d0
  1218.         beq.b    .out            ; no memory!
  1219.  
  1220.         movea.l    d2,a1            ; pool header
  1221.         movem.l    d3-d5,(a0)        ; puddleSize, Flags,Threshold
  1222.         move.l    12(a1),12(a0)        ; next block
  1223.         move.l    a0,12(a1)        ; splice in block
  1224.         lea    24(a0),a1        ; first free location here
  1225.         move.l    a1,16(a0)
  1226.         subi.l    #24,d3            ; for header info
  1227.         move.l    d3,20(a0)        ; amount free in this block
  1228.  
  1229.         move.l    d6,d0            ; restore size
  1230.  
  1231. .gotspace    sub.l    d0,20(a0)        ; sub from amount free
  1232.         bmi.b    .err            ; threshold >= puddlesize!
  1233.  
  1234.         move.l    16(a0),a1        ; free space
  1235.         add.l    d0,16(a0)        ; next free space
  1236.  
  1237.         movea.l    a1,a0
  1238.         bra.b    .out
  1239.  
  1240. .err        add.l    d0,20(a0)        ; restore free space
  1241.         moveq    #0,d0
  1242.         suba.l    a0,a0            ; no memory
  1243.  
  1244. .out        move.l    a0,d0
  1245.         movem.l    (sp)+,d2-d7/a2-a6
  1246.         rts
  1247.  
  1248. ;------------------------------------------------------------------------
  1249. ;------------------------------------------------------------------------
  1250. ;------------------------------------------------------------------------
  1251. ;------------------------------------------------------------------------
  1252.  
  1253. MUSMemPtr    dc.l    0
  1254. MUSMemSize    dc.l    0
  1255.  
  1256. ;------------------------------------------------------------------------
  1257.  
  1258. midifileproblem    dc.b    "Error opening MIDI_Instruments file!",0
  1259.  
  1260. dosproblem    dc.b    "Error reading MIDI_Instruments file!",0
  1261.  
  1262. memproblem    dc.b    "Not enough memory for music!",0
  1263.  
  1264. notmusfile    dc.b    "Music lump in WAD file is not .MUS format!",0
  1265.  
  1266. damagedfile    dc.b    "Damaged MIDI_Instruments or WAD file!",0
  1267.  
  1268. cantopenaud    dc.b    "Can't open audio.device for music!",0
  1269.  
  1270. cantgetchan    dc.b    "Can't allocate channels for music!",0
  1271.  
  1272.         cnop    0,4
  1273.  
  1274. ;------------------------------------------------------------------------
  1275. ; bit 0 = close, bit 1 = file loaded, bit 2 = playing, bit 3 = paused
  1276. ; bit 4 = loop, bit 5 = attention, bit 6 = gadget down, bit 7 = rev/FF
  1277. Flags        dc.b    0
  1278. Flags2        dc.b    0            ; backup of Flags
  1279.  
  1280. ; bit 0,1 = dotick
  1281. Flags3        dc.b    0
  1282.  
  1283. ;------------------------------------------------------------------------
  1284.         cnop 0,4
  1285.  
  1286. EventTable    dc.w    Release-EventTable
  1287.         dc.w    PlayNote-EventTable
  1288.         dc.w    Pitch-EventTable
  1289.         dc.w    Tempo-EventTable
  1290.         dc.w    ChangeCtrl-EventTable
  1291.         dc.w    NoEvent-EventTable
  1292.         dc.w    EndScore-EventTable
  1293.         dc.w    NoEvent-EventTable
  1294.  
  1295. ;------------------------------------------------------------------------
  1296.  
  1297.         cnop    0,4
  1298.  
  1299. looping        dc.l    0
  1300. musicdies    dc.l    -1
  1301.  
  1302. MyTicks        dc.l    0
  1303.  
  1304. PrevDelay    dc.l    0
  1305.  
  1306. AudioPort    dc.l    0,0
  1307.         dc.b    NT_MSGPORT,0        ; LN_TYPE, LN_PRI
  1308.         dc.l    0            ; LN_NAME
  1309.         dc.b    PA_SIGNAL        ; mp_Flags
  1310.         dc.b    0            ; mp_SigBit
  1311. AudioTask    dc.l    0            ; mp_SigTask
  1312. .1        dc.l    .2
  1313. .2        dc.l    0
  1314.         dc.l    .1
  1315.  
  1316.         cnop    0,4
  1317.  
  1318. AudioIO        dc.l    0,0
  1319.         dc.b    NT_REPLYMSG,0        ; LN_TYPE, LN_PRI
  1320.         dc.l    0            ; LN_NAME
  1321.         dc.l    AudioPort        ; mn_ReplyPort
  1322.         dc.w    68            ; mn_Length
  1323.         dc.l    0            ; IO_DEVICE
  1324.         dc.l    0            ; IO_UNIT
  1325.         dc.w    0            ; IO_COMMAND
  1326.         dc.b    0            ; IO_FLAGS
  1327.         dc.b    0            ; IO_ERROR
  1328.         dc.w    0            ; ioa_AllocKey
  1329.         dc.l    0            ; ioa_Data
  1330.         dc.l    0            ; ioa_Length
  1331.         dc.w    0            ; ioa_Period
  1332.         dc.w    0            ; ioa_Volume
  1333.         dc.w    0            ; ioa_Cycles
  1334.         dc.l    0,0            ; ioa_WriteMsg
  1335.         dc.b    0,0
  1336.         dc.l    0
  1337.         dc.l    0
  1338.         dc.w    0
  1339.  
  1340.         cnop    0,4
  1341.  
  1342. AInt2        dc.l    0,0
  1343.         dc.b    NT_INTERRUPT,0        ; LN_TYPE, LN_PRI
  1344.         dc.l    TPortName        ; LN_NAME
  1345.         dc.l    0            ; IS_DATA
  1346.         dc.l    AudioINT2        ; IS_CODE
  1347.  
  1348. MusPtr        dc.l    0
  1349. MusIndex    dc.l    0
  1350. MusDelay    dc.l    0
  1351. OldAInt2    dc.l    0
  1352.  
  1353. AudioAlloc    dc.b    $0c            ; Amiga channels to allocate
  1354.  
  1355. AudioName    dc.b    'audio.device',0
  1356. TPortName    dc.b    'ADoom-MUS',0
  1357. AudioOK        dc.b    0
  1358. AudioCh        dc.b    0
  1359. musicarg    dc.b    "-music",0
  1360.  
  1361. ;--------------------------------------
  1362.  
  1363.         CNOP    0,4
  1364.  
  1365. ; bit set if voice is in use (0-15=music voices,16-31=sfx voices)
  1366.  
  1367. VoiceAvail    dc.l    0
  1368.  
  1369.  
  1370. ; bit 0 = stop processing, bit 1 = buffer indicator
  1371.  
  1372. MusFlag        dc.b    0
  1373.  
  1374. ;--------------------------------------------------------------------
  1375.  
  1376.         CNOP    0,4
  1377.  
  1378. 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
  1379.         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
  1380.         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
  1381.         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
  1382.         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
  1383.         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
  1384.         dc.l    65536,69433,73562,77936,82570,87480,92682,98193,104032,110218,116772,123715
  1385.         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
  1386.         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
  1387.         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
  1388.         dc.l    65536*16,69433*16,73562*16,77936*16,82570*16,87480*16,92682*16,98193*16
  1389.  
  1390. ;------------------------------------------------------------------------
  1391.  
  1392. PitchTable:
  1393.  
  1394. pitch_ix    SET    128
  1395.  
  1396.         REPT    128
  1397.         dc.l    -3678*pitch_ix/64
  1398. pitch_ix    SET    pitch_ix-1
  1399.         ENDR
  1400.  
  1401.         REPT    128
  1402.         dc.l    3897*pitch_ix/64
  1403. pitch_ix    SET    pitch_ix+1
  1404.         ENDR
  1405.  
  1406. ;------------------------------------------------------------------------
  1407.  
  1408.         CNOP    0,4
  1409.  
  1410. AudioCh2Buf    dc.l    chipbuffer2
  1411. AudioCh2Ptr    dc.l    chipbuffer2
  1412. AudioCh2Vol    dc.w    64
  1413.  
  1414.         CNOP    0,4
  1415.  
  1416. AudioCh3Buf    dc.l    chipbuffer3
  1417. AudioCh3Ptr    dc.l    chipbuffer3
  1418. AudioCh3Vol    dc.w    64
  1419.  
  1420. ;------------------------------------------------------------------------
  1421.  
  1422.         STRUCTURE MusChannel,0
  1423.         APTR    ch_Instr
  1424.         APTR    ch_Map
  1425.         ULONG    ch_Pitch
  1426.         BYTE    ch_Vol
  1427.         BYTE    ch_Pan
  1428.  
  1429.  
  1430.         CNOP    0,4
  1431.  
  1432. Channels    dc.l    Channel0,Channel1,Channel2,Channel3
  1433.         dc.l    Channel4,Channel5,Channel6,Channel7
  1434.         dc.l    Channel8,Channel9,Channel10,Channel11
  1435.         dc.l    Channel12,Channel13,Channel14,Channel15
  1436.  
  1437.  
  1438.         CNOP    0,4
  1439.  
  1440. Channel0    dc.l    0        ; instrument
  1441.         dc.l    Channel0Map    ; note to voice map
  1442.         dc.l    0        ; pitch wheel setting
  1443.         dc.b    0        ; volume
  1444.         dc.b    0        ; pan setting
  1445.  
  1446.         CNOP    0,4
  1447.  
  1448. Channel1    dc.l    0        ; instrument
  1449.         dc.l    Channel1Map    ; note to voice map
  1450.         dc.l    0        ; pitch wheel setting
  1451.         dc.b    0        ; volume
  1452.         dc.b    0        ; pan setting
  1453.  
  1454.         CNOP    0,4
  1455.  
  1456. Channel2    dc.l    0        ; instrument
  1457.         dc.l    Channel2Map    ; note to voice map
  1458.         dc.l    0        ; pitch wheel setting
  1459.         dc.b    0        ; volume
  1460.         dc.b    0        ; pan setting
  1461.  
  1462.         CNOP    0,4
  1463.  
  1464. Channel3    dc.l    0        ; instrument
  1465.         dc.l    Channel3Map    ; note to voice map
  1466.         dc.l    0        ; pitch wheel setting
  1467.         dc.b    0        ; volume
  1468.         dc.b    0        ; pan setting
  1469.  
  1470.         CNOP    0,4
  1471.  
  1472. Channel4    dc.l    0        ; instrument
  1473.         dc.l    Channel4Map    ; note to voice map
  1474.         dc.l    0        ; pitch wheel setting
  1475.         dc.b    0        ; volume
  1476.         dc.b    0        ; pan setting
  1477.  
  1478.         CNOP    0,4
  1479.  
  1480. Channel5    dc.l    0        ; instrument
  1481.         dc.l    Channel5Map    ; note to voice map
  1482.         dc.l    0        ; pitch wheel setting
  1483.         dc.b    0        ; volume
  1484.         dc.b    0        ; pan setting
  1485.  
  1486.         CNOP    0,4
  1487.  
  1488. Channel6    dc.l    0        ; instrument
  1489.         dc.l    Channel6Map    ; note to voice map
  1490.         dc.l    0        ; pitch wheel setting
  1491.         dc.b    0        ; volume
  1492.         dc.b    0        ; pan setting
  1493.  
  1494.         CNOP    0,4
  1495.  
  1496. Channel7    dc.l    0        ; instrument
  1497.         dc.l    Channel7Map    ; note to voice map
  1498.         dc.l    0        ; pitch wheel setting
  1499.         dc.b    0        ; volume
  1500.         dc.b    0        ; pan setting
  1501.  
  1502.         CNOP    0,4
  1503.  
  1504. Channel8    dc.l    0        ; instrument
  1505.         dc.l    Channel8Map    ; note to voice map
  1506.         dc.l    0        ; pitch wheel setting
  1507.         dc.b    0        ; volume
  1508.         dc.b    0        ; pan setting
  1509.  
  1510.         CNOP    0,4
  1511.  
  1512. Channel9    dc.l    0        ; instrument
  1513.         dc.l    Channel9Map    ; note to voice map
  1514.         dc.l    0        ; pitch wheel setting
  1515.         dc.b    0        ; volume
  1516.         dc.b    0        ; pan setting
  1517.  
  1518.         CNOP    0,4
  1519.  
  1520. Channel10    dc.l    0        ; instrument
  1521.         dc.l    Channel10Map    ; note to voice map
  1522.         dc.l    0        ; pitch wheel setting
  1523.         dc.b    0        ; volume
  1524.         dc.b    0        ; pan setting
  1525.  
  1526.         CNOP    0,4
  1527.  
  1528. Channel11    dc.l    0        ; instrument
  1529.         dc.l    Channel11Map    ; note to voice map
  1530.         dc.l    0        ; pitch wheel setting
  1531.         dc.b    0        ; volume
  1532.         dc.b    0        ; pan setting
  1533.  
  1534.         CNOP    0,4
  1535.  
  1536. Channel12    dc.l    0        ; instrument
  1537.         dc.l    Channel12Map    ; note to voice map
  1538.         dc.l    0        ; pitch wheel setting
  1539.         dc.b    0        ; volume
  1540.         dc.b    0        ; pan setting
  1541.  
  1542.         CNOP    0,4
  1543.  
  1544. Channel13    dc.l    0        ; instrument
  1545.         dc.l    Channel13Map    ; note to voice map
  1546.         dc.l    0        ; pitch wheel setting
  1547.         dc.b    0        ; volume
  1548.         dc.b    0        ; pan setting
  1549.  
  1550.         CNOP    0,4
  1551.  
  1552. Channel14    dc.l    0        ; instrument
  1553.         dc.l    Channel14Map    ; note to voice map
  1554.         dc.l    0        ; pitch wheel setting
  1555.         dc.b    0        ; volume
  1556.         dc.b    0        ; pan setting
  1557.  
  1558.         CNOP    0,4
  1559.  
  1560. Channel15    dc.l    0        ; instrument
  1561.         dc.l    Channel15Map    ; note to voice map
  1562.         dc.l    0        ; pitch wheel setting
  1563.         dc.b    0        ; volume
  1564.         dc.b    0        ; pan setting
  1565.  
  1566.  
  1567.         CNOP    0,4
  1568.  
  1569. Channel0Map    dcb.b    128,0
  1570. Channel1Map    dcb.b    128,0
  1571. Channel2Map    dcb.b    128,0
  1572. Channel3Map    dcb.b    128,0
  1573. Channel4Map    dcb.b    128,0
  1574. Channel5Map    dcb.b    128,0
  1575. Channel6Map    dcb.b    128,0
  1576. Channel7Map    dcb.b    128,0
  1577. Channel8Map    dcb.b    128,0
  1578. Channel9Map    dcb.b    128,0
  1579. Channel10Map    dcb.b    128,0
  1580. Channel11Map    dcb.b    128,0
  1581. Channel12Map    dcb.b    128,0
  1582. Channel13Map    dcb.b    128,0
  1583. Channel14Map    dcb.b    128,0
  1584. Channel15Map    dcb.b    128,0
  1585.  
  1586. ;--------------------------------------
  1587.  
  1588.         STRUCTURE AudioVoice,0
  1589.         APTR    vc_Next
  1590.         APTR    vc_Channel
  1591.         APTR    vc_Wave
  1592.         ULONG    vc_Index
  1593.         ULONG    vc_Step
  1594.         ULONG    vc_Loop
  1595.         ULONG    vc_Length
  1596.         BYTE    vc_Vol
  1597.         BYTE    vc_Flags    ; b7 = SFX, b1 = RLS, b0 = EN
  1598.  
  1599.         CNOP    0,4
  1600.  
  1601. Voices        dc.l    Voice0,Voice1,Voice2,Voice3
  1602.         dc.l    Voice4,Voice5,Voice6,Voice7
  1603.         dc.l    Voice8,Voice9,Voice10,Voice11
  1604.         dc.l    Voice12,Voice13,Voice14,Voice15
  1605.  
  1606.         CNOP    0,4
  1607.  
  1608. Voice0        dc.l    Voice1
  1609.         dc.l    0        ; channel back-link
  1610.         dc.l    0        ; instrument wave data
  1611.         dc.l    0        ; sample index
  1612.         dc.l    0        ; sample rate
  1613.         dc.l    0        ; instrument loop point
  1614.         dc.l    0        ; instrument data length
  1615.         dc.b    0        ; voice volume scale
  1616.         dc.b    0        ; voice flags
  1617.  
  1618.         CNOP    0,4
  1619.  
  1620. Voice1        dc.l    Voice2
  1621.         dc.l    0        ; channel back-link
  1622.         dc.l    0        ; instrument wave data
  1623.         dc.l    0        ; sample index
  1624.         dc.l    0        ; sample rate
  1625.         dc.l    0        ; instrument loop point
  1626.         dc.l    0        ; instrument data length
  1627.         dc.b    0        ; voice volume scale
  1628.         dc.b    0        ; voice flags
  1629.  
  1630.         CNOP    0,4
  1631.  
  1632. Voice2        dc.l    Voice3
  1633.         dc.l    0        ; channel back-link
  1634.         dc.l    0        ; instrument wave data
  1635.         dc.l    0        ; sample index
  1636.         dc.l    0        ; sample rate
  1637.         dc.l    0        ; instrument loop point
  1638.         dc.l    0        ; instrument data length
  1639.         dc.b    0        ; voice volume scale
  1640.         dc.b    0        ; voice flags
  1641.  
  1642.         CNOP    0,4
  1643.  
  1644. Voice3        dc.l    Voice4
  1645.         dc.l    0        ; channel back-link
  1646.         dc.l    0        ; instrument wave data
  1647.         dc.l    0        ; sample index
  1648.         dc.l    0        ; sample rate
  1649.         dc.l    0        ; instrument loop point
  1650.         dc.l    0        ; instrument data length
  1651.         dc.b    0        ; voice volume scale
  1652.         dc.b    0        ; voice flags
  1653.  
  1654.         CNOP    0,4
  1655.  
  1656. Voice4        dc.l    Voice5
  1657.         dc.l    0        ; channel back-link
  1658.         dc.l    0        ; instrument wave data
  1659.         dc.l    0        ; sample index
  1660.         dc.l    0        ; sample rate
  1661.         dc.l    0        ; instrument loop point
  1662.         dc.l    0        ; instrument data length
  1663.         dc.b    0        ; voice volume scale
  1664.         dc.b    0        ; voice flags
  1665.  
  1666.         CNOP    0,4
  1667.  
  1668. Voice5        dc.l    Voice6
  1669.         dc.l    0        ; channel back-link
  1670.         dc.l    0        ; instrument wave data
  1671.         dc.l    0        ; sample index
  1672.         dc.l    0        ; sample rate
  1673.         dc.l    0        ; instrument loop point
  1674.         dc.l    0        ; instrument data length
  1675.         dc.b    0        ; voice volume scale
  1676.         dc.b    0        ; voice flags
  1677.  
  1678.         CNOP    0,4
  1679.  
  1680. Voice6        dc.l    Voice7
  1681.         dc.l    0        ; channel back-link
  1682.         dc.l    0        ; instrument wave data
  1683.         dc.l    0        ; sample index
  1684.         dc.l    0        ; sample rate
  1685.         dc.l    0        ; instrument loop point
  1686.         dc.l    0        ; instrument data length
  1687.         dc.b    0        ; voice volume scale
  1688.         dc.b    0        ; voice flags
  1689.  
  1690.         CNOP    0,4
  1691.  
  1692. Voice7        dc.l    Voice8
  1693.         dc.l    0        ; channel back-link
  1694.         dc.l    0        ; instrument wave data
  1695.         dc.l    0        ; sample index
  1696.         dc.l    0        ; sample rate
  1697.         dc.l    0        ; instrument loop point
  1698.         dc.l    0        ; instrument data length
  1699.         dc.b    0        ; voice volume scale
  1700.         dc.b    0        ; voice flags
  1701.  
  1702.         CNOP    0,4
  1703.  
  1704. Voice8        dc.l    Voice9
  1705.         dc.l    0        ; channel back-link
  1706.         dc.l    0        ; instrument wave data
  1707.         dc.l    0        ; sample index
  1708.         dc.l    0        ; sample rate
  1709.         dc.l    0        ; instrument loop point
  1710.         dc.l    0        ; instrument data length
  1711.         dc.b    0        ; voice volume scale
  1712.         dc.b    0        ; voice flags
  1713.  
  1714.         CNOP    0,4
  1715.  
  1716. Voice9        dc.l    Voice10
  1717.         dc.l    0        ; channel back-link
  1718.         dc.l    0        ; instrument wave data
  1719.         dc.l    0        ; sample index
  1720.         dc.l    0        ; sample rate
  1721.         dc.l    0        ; instrument loop point
  1722.         dc.l    0        ; instrument data length
  1723.         dc.b    0        ; voice volume scale
  1724.         dc.b    0        ; voice flags
  1725.  
  1726.         CNOP    0,4
  1727.  
  1728. Voice10        dc.l    Voice11
  1729.         dc.l    0        ; channel back-link
  1730.         dc.l    0        ; instrument wave data
  1731.         dc.l    0        ; sample index
  1732.         dc.l    0        ; sample rate
  1733.         dc.l    0        ; instrument loop point
  1734.         dc.l    0        ; instrument data length
  1735.         dc.b    0        ; voice volume scale
  1736.         dc.b    0        ; voice flags
  1737.  
  1738.         CNOP    0,4
  1739.  
  1740. Voice11        dc.l    Voice12
  1741.         dc.l    0        ; channel back-link
  1742.         dc.l    0        ; instrument wave data
  1743.         dc.l    0        ; sample index
  1744.         dc.l    0        ; sample rate
  1745.         dc.l    0        ; instrument loop point
  1746.         dc.l    0        ; instrument data length
  1747.         dc.b    0        ; voice volume scale
  1748.         dc.b    0        ; voice flags
  1749.  
  1750.         CNOP    0,4
  1751.  
  1752. Voice12        dc.l    Voice13
  1753.         dc.l    0        ; channel back-link
  1754.         dc.l    0        ; instrument wave data
  1755.         dc.l    0        ; sample index
  1756.         dc.l    0        ; sample rate
  1757.         dc.l    0        ; instrument loop point
  1758.         dc.l    0        ; instrument data length
  1759.         dc.b    0        ; voice volume scale
  1760.         dc.b    0        ; voice flags
  1761.  
  1762.         CNOP    0,4
  1763.  
  1764. Voice13        dc.l    Voice14
  1765.         dc.l    0        ; channel back-link
  1766.         dc.l    0        ; instrument wave data
  1767.         dc.l    0        ; sample index
  1768.         dc.l    0        ; sample rate
  1769.         dc.l    0        ; instrument loop point
  1770.         dc.l    0        ; instrument data length
  1771.         dc.b    0        ; voice volume scale
  1772.         dc.b    0        ; voice flags
  1773.  
  1774.         CNOP    0,4
  1775.  
  1776. Voice14        dc.l    Voice15
  1777.         dc.l    0        ; channel back-link
  1778.         dc.l    0        ; instrument wave data
  1779.         dc.l    0        ; sample index
  1780.         dc.l    0        ; sample rate
  1781.         dc.l    0        ; instrument loop point
  1782.         dc.l    0        ; instrument data length
  1783.         dc.b    0        ; voice volume scale
  1784.         dc.b    0        ; voice flags
  1785.  
  1786.         CNOP    0,4
  1787.  
  1788. Voice15        dc.l    0
  1789.         dc.l    0        ; channel back-link
  1790.         dc.l    0        ; instrument wave data
  1791.         dc.l    0        ; sample index
  1792.         dc.l    0        ; sample rate
  1793.         dc.l    0        ; instrument loop point
  1794.         dc.l    0        ; instrument data length
  1795.         dc.b    0        ; voice volume scale
  1796.         dc.b    0        ; voice flags
  1797.  
  1798. ;--------------------------------------
  1799.  
  1800.         STRUCTURE InstrumentRec,0
  1801.         APTR    in_Wave
  1802.         ULONG    in_Loop
  1803.         ULONG    in_Length
  1804.         BYTE    in_Flags
  1805.         BYTE    in_Base
  1806.  
  1807.  
  1808.         CNOP    0,4
  1809.  
  1810. Instruments    dcb.l    256,0
  1811.  
  1812.         CNOP    0,4
  1813.  
  1814. QuietInst    dc.l    0
  1815.         dc.l    0
  1816.         dc.l    0
  1817.         dc.b    0
  1818.         dc.b    0
  1819.  
  1820.  
  1821.         CNOP    0,4
  1822.  
  1823. InstrHandle    dc.l    0
  1824. InstrFile    dc.l    InstrName
  1825. InstrPool    dc.l    0
  1826.  
  1827. InstrName    dc.b    'PROGDIR:MIDI_Instruments',0
  1828.  
  1829.         CNOP    0,4
  1830.  
  1831. validInstr    dc.b    %11111111    ; (00-07) Piano
  1832.         dc.b    %11111111    ; (08-0F) Chrom Perc
  1833.         dc.b    %11111111    ; (10-17) Organ
  1834.         dc.b    %11111111    ; (18-1F) Guitar
  1835.         dc.b    %11111111    ; (20-27) Bass
  1836.         dc.b    %11111111    ; (28-2F) Strings
  1837.         dc.b    %11111111    ; (30-37) Ensemble
  1838.         dc.b    %11111111    ; (38-3F) Brass
  1839.         dc.b    %11111111    ; (40-47) Reed
  1840.         dc.b    %11111111    ; (48-4F) Pipe
  1841.         dc.b    %11111111    ; (50-57) Synth Lead
  1842.         dc.b    %11111111    ; (58-5F) Synth Pad
  1843.         dc.b    %11111111    ; (60-67) Synth Effects
  1844.         dc.b    %11111111    ; (68-6F) Ethnic
  1845.         dc.b    %11111111    ; (70-77) Percussive
  1846.         dc.b    %11111111    ; (78-7F) SFX
  1847.         dc.b    %00000001    ; (80-87) invalid,Drum
  1848.         dc.b    %11111111    ; (88-8F) Drums/Clap/Hi-Hat
  1849.         dc.b    %11111111    ; (90-97) Hi-Hats/Toms/Cymb1
  1850.         dc.b    %11111111    ; (98-9F) Cymbals/Bells/Slap
  1851.         dc.b    %11111111    ; (A0-A7) Bongos/Congas/Timb
  1852.         dc.b    %11111111    ; (A8-AF) Agogo/Whistles/Gui
  1853.         dc.b    %11111100    ; (B0-B7) Claves/Block/Trian
  1854.         dc.b    %00000000    ; (B8-BF) invalid
  1855.         dc.b    %00000000    ; (C0-C7)
  1856.         dc.b    %00000000    ; (C8-CF)
  1857.         dc.b    %00000000    ; (D0-D7)
  1858.         dc.b    %00000000    ; (D8-DF)
  1859.         dc.b    %00000000    ; (E0-E7)
  1860.         dc.b    %00000000    ; (E8-EF)
  1861.         dc.b    %00000000    ; (F0-F7)
  1862.         dc.b    %00000000    ; (F8-FF)
  1863.  
  1864. ;--------------------------------------------------------------------
  1865.         section    PlayMusChip,data_c
  1866.  
  1867. ClearBuf    dcb.b    160,0
  1868.  
  1869.  
  1870. chipbuffer2    dcb.b    320,0
  1871. chipbuffer3    dcb.b    320,0
  1872.  
  1873. ;------------------------------------------------------------------------
  1874.         section    PlayMusBSS,bss
  1875.  
  1876. EventBlocks    ds.w    32768
  1877.  
  1878.  
  1879. tempAudio    ds.b    160
  1880.  
  1881. ;------------------------------------------------------------------------
  1882.  
  1883.         end
  1884.