home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 28 / amigaformatcd28.iso / -screenplay- / otherstuff / adoomppc_src / doomsound.library.060.s < prev    next >
Text File  |  1998-04-23  |  51KB  |  2,406 lines

  1. ;------------------------------------------------------------------------
  2. ; Sound Library for DOOM - by Joseph Fenton
  3. ;
  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
  24. ;
  25. ;------------------------------------------------------------------------
  26.  
  27.  
  28. _custom        equ    $DFF000
  29.  
  30. ;------------------------------------------------------------------------
  31.  
  32.         include    devpac:system.gs    ; all includes/LVOs
  33.  
  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"
  44. ;
  45. ;CALLSYS        macro
  46. ;        jsr    (_LVO\1,a6)
  47. ;        endm
  48. ;
  49. ;CALLDOS        macro
  50. ;        movea.l    (_DOSBase,pc),a6
  51. ;        jsr    (_LVO\1,a6)
  52. ;        endm
  53.  
  54.         output    ram:doomsound.library.060
  55.  
  56. ;------------------------------------------------------------------------
  57.  
  58. VERSION        equ 37            ;Version #
  59. REVISION    equ 0            ;revision of the version
  60.  
  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
  67.  
  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
  79.  
  80. OUTPUT_DATE    MACRO
  81.         dc.b ' (29.3.98)'
  82.         ENDM
  83.  
  84.  
  85. ;--------------------------------------------------------------------
  86. ; in case of idiots
  87.  
  88.         moveq    #0,d0
  89.         rts
  90.  
  91. ;--------------------------------------------------------------------
  92. ; standard library header
  93.  
  94.  
  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
  105.  
  106.  
  107. Name        dc.b    'doomsound.library',0
  108.         even
  109.  
  110. IDString    dc.b    'doomsound.library '
  111.         OUTPUT_VER
  112.         OUTPUT_DATE
  113.         dc.b    ' ©1998 by Joe Fenton.',0
  114.         even
  115.  
  116.  
  117.         CNOP    0,4
  118.  
  119. Init        dc.l    LIB_SIZE
  120.         dc.l    FuncTable
  121.         dc.l    DataTable
  122.         dc.l    InitRoutine
  123.  
  124.  
  125. FuncTable    dc.l    OpenLib        ; -6
  126.         dc.l    CloseLib    ; -12
  127.         dc.l    Expunge        ; -18
  128.         dc.l    Reserved    ; -24
  129.  
  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
  135.  
  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
  144.  
  145.         dc.l    -1
  146.  
  147.  
  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
  155.  
  156.  
  157. ;--------------------------------------
  158. ; A0 = library segment list
  159. ; A6 = ExecBase
  160. ; D0 = library pointer
  161. ;
  162. ; D0 -> library base or NULL
  163.  
  164.         CNOP    0,16
  165.  
  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
  170.  
  171.         bsr    InitServer        ;setup sound server
  172.         bne.b    .err
  173.  
  174.         move.l    a5,d0            ;success ...
  175.         movea.l    (a7)+,a5
  176.         rts
  177.  
  178. .err        moveq    #0,d0            ;error
  179.         movea.l    (a7)+,a5
  180.         rts
  181.  
  182.  
  183. ;--------------------------------------
  184.  
  185.         CNOP    0,16
  186.  
  187. OpenLib        addq.w    #1,LIB_OPENCNT(a6)
  188.         move.l    a6,d0
  189.         rts
  190.  
  191.  
  192. ;--------------------------------------
  193. ; this library is auto-expunging
  194.  
  195.         CNOP    0,16
  196.  
  197. CloseLib    subq.w    #1,LIB_OPENCNT(a6)
  198.         beq.b    Expunge
  199. ;still open
  200.         moveq    #0,d0            ;no seglist
  201.         rts
  202.  
  203.  
  204. ;--------------------------------------
  205. ; A6 = library base
  206. ;
  207. ; D0 -> seglist or NULL
  208.  
  209.         CNOP    0,16
  210.  
  211. Expunge        tst.w    LIB_OPENCNT(a6)        ;library still open?
  212.         bne    .LibStillOpen        ;yes
  213.  
  214.         bsr    ExitServer        ;cleanup sound server
  215.  
  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
  223.  
  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
  232.         rts
  233.  
  234.  
  235. .LibStillOpen    moveq    #0,d0            ;no seglist
  236.         rts
  237.  
  238.  
  239. ;--------------------------------------
  240.  
  241.         CNOP    0,4
  242.  
  243. Reserved    moveq.l #0,d0
  244.         rts
  245.  
  246.  
  247. EndCode:
  248.  
  249. ;--------------------------------------------------------------------
  250.  
  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
  255.  
  256. ;--------------------------------------------------------------------
  257.  
  258.         CNOP    0,16
  259.  
  260. InitServer    movem.l    d1-d7/a0-a6,-(a7)
  261.         movea.l    _ExecBase,a6
  262.  
  263.         moveq    #0,d0
  264.         lea    DOSName,a1
  265.         CALLSYS    OpenLibrary
  266.         move.l    d0,_DOSBase
  267.         beq    .err            ; couldn't open dos.library
  268.  
  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
  279.  
  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
  287.  
  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
  300.  
  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
  309.  
  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
  317.  
  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
  328.  
  329.         movea.l    AudioIO,a1
  330.         move.w    #ADCMD_LOCK,IO_COMMAND(a1)
  331.         CALLSYS    SendIO
  332.  
  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
  338.  
  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)
  343.  
  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)
  348.  
  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)
  353.  
  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)
  358.  
  359.         moveq    #INTB_AUD0,d0
  360.         lea    AInt0,a1
  361.         CALLSYS    SetIntVector
  362.         move.l    d0,OldAInt0
  363.  
  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
  380.  
  381.         clr.b    mus_playing
  382.         clr.b    mus_looping
  383.  
  384.         clr.l    MusDelay        ; MusDelay = 0
  385.         clr.l    VoiceAvail        ; all voices available
  386.  
  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
  393.  
  394.         movem.l    (a7)+,d1-d7/a0-a6
  395.         moveq    #0,d0        ; okay
  396.         rts
  397.  
  398. .err4        movea.l    AudioIO,a1
  399.         CALLSYS    CloseDevice
  400.  
  401. .err3        movea.l    AudioIO,a0
  402.         CALLSYS    DeleteIORequest
  403.  
  404. .err2        movea.l    AudioPort,a0
  405.         CALLSYS    DeleteMsgPort
  406.  
  407. .err1        movea.l    LookupMem,a1
  408.         CALLSYS    FreeVec
  409.  
  410. .err0        movea.l    _DOSBase,a1
  411.         CALLSYS    CloseLibrary
  412.  
  413. .err        movem.l    (a7)+,d1-d7/a0-a6
  414.         moveq    #-1,d0        ; error
  415.         rts
  416.  
  417. ;--------------------------------------
  418.  
  419.         CNOP    0,16
  420.  
  421. ExitServer    movem.l    d1-d7/a0-a6,-(a7)
  422.  
  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
  427.  
  428.         moveq    #INTB_AUD0,d0
  429.         movea.l    OldAInt0,a1
  430.         movea.l    _ExecBase,a6
  431.         CALLSYS    SetIntVector
  432.  
  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)
  438.  
  439.         movea.l    _ExecBase,a6
  440.  
  441.         movea.l    AudioIO,a1
  442.         CALLSYS    CloseDevice
  443.  
  444.         movea.l    AudioIO,a0
  445.         CALLSYS    DeleteIORequest
  446.  
  447.         movea.l    AudioPort,a0
  448.         CALLSYS    DeleteMsgPort
  449.  
  450.         movea.l    LookupMem,a1
  451.         CALLSYS    FreeVec
  452.  
  453.         movea.l    _DOSBase,a1
  454.         CALLSYS    CloseLibrary
  455.  
  456.         movem.l    (a7)+,d1-d7/a0-a6
  457.         moveq    #0,d0
  458.         rts
  459.  
  460. ;--------------------------------------
  461.  
  462.         CNOP    0,16
  463.  
  464. Sfx_SetVol    move.w    d0,sfx_volume
  465.         rts
  466.  
  467. ;--------------------------------------
  468.  
  469.         CNOP    0,16
  470.  
  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)
  485.  
  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)
  496.  
  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)
  507.  
  508.         move.b    #$81,vc_Flags(a1)
  509.         movem.l    (a7)+,d0-d4/a0-a2
  510.         rts
  511.  
  512. ;--------------------------------------
  513.  
  514.         CNOP    0,16
  515.  
  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)
  523.  
  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)
  534.  
  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)
  545.  
  546.         movem.l    (a7)+,d0-d4/a0-a2
  547.         rts
  548.  
  549. ;--------------------------------------
  550.  
  551.         CNOP    0,16
  552.  
  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
  558.         rts
  559.  
  560. ;--------------------------------------
  561.  
  562.         CNOP    0,16
  563.  
  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
  573.         rts
  574.  
  575. ;--------------------------------------
  576.  
  577.         CNOP    0,16
  578.  
  579. Mus_SetVol    move.w    d0,mus_volume
  580.         rts
  581.  
  582. ;--------------------------------------
  583.  
  584.         CNOP    0,16
  585.  
  586. Mus_Register    movem.l    d1-d7/a0-a6,-(sp)
  587.         bsr    Mus_Unregister
  588.  
  589.         move.l    a0,MUSMemPtr
  590.  
  591.         cmpi.l    #$4D55531A,(a0)        ; "MUS",26
  592.         bne    .err0            ; not a mus file
  593.  
  594.         move.l    MUSMemPtr,MusPtr
  595.  
  596.         bsr    TestMUSFile
  597.         beq    .err0
  598.  
  599.         move.l    InstrFile,d1
  600.         move.l    #MODE_OLDFILE,d2
  601.         CALLDOS    Open
  602.         move.l    d0,InstrHandle
  603.         beq    .err0
  604.  
  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
  611.  
  612.         movea.l    a0,a2
  613.         movea.l    MusPtr,a3
  614.  
  615.         move.w    #255,d0
  616.         lea    Instruments,a0
  617. .setinstr    move.l    #QuietInst,(a0)+
  618.         dbra    d0,.setinstr
  619.  
  620.         move.w    $C(a3),d4        ; instrCnt
  621.         ror.w    #8,d4
  622.         subq.w    #1,d4            ; for dbra
  623.  
  624.         lea    $10(a3),a3        ; instruments[]
  625.  
  626. .instrloop    moveq    #14,d0
  627.         movea.l    a2,a0
  628.         bsr    AllocPooled
  629.  
  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?)
  635.  
  636.         lea    Instruments,a0
  637.         move.l    d0,(a0,d2.w*4)
  638.         beq    .err2
  639.  
  640.         movea.l    d0,a4            ; instrument record
  641.  
  642.         bftst    (validInstr){d2:1}
  643.         beq    .next            ; no instrument
  644.  
  645.         move.l    InstrHandle,d1
  646.         lsl.l    #2,d2
  647.         moveq    #OFFSET_BEGINNING,d3
  648.         CALLDOS    Seek
  649.  
  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
  656.  
  657.         move.l    InstrHandle,d1
  658.         move.l    (a4),d2
  659.         moveq    #OFFSET_BEGINNING,d3
  660.         CALLSYS    Seek
  661.  
  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
  668.  
  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
  675.  
  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
  683.  
  684.         move.b    #1,in_Flags(a4)
  685. .next        dbra    d4,.instrloop
  686.  
  687.         move.l    InstrHandle,d1
  688.         CALLDOS    Close
  689.         clr.l    InstrHandle
  690.  
  691.         moveq    #1,d0            ; return handle=1
  692.         movem.l    (sp)+,d1-d7/a0-a6
  693.         rts
  694.  
  695. .err2        movea.l    InstrPool,a0
  696.         bsr    DeletePool
  697.         clr.l    InstrPool
  698.  
  699. .err1        move.l    InstrHandle,d1
  700.         CALLDOS    Close
  701.         clr.l    InstrHandle
  702.  
  703. .err0        moveq    #0,d0            ; return handle=0
  704.         movem.l    (sp)+,d1-d7/a0-a6
  705.         rts
  706.  
  707. ;--------------------------------------
  708.  
  709.         CNOP    0,16
  710.  
  711. Mus_Unregister    movem.l    d0-d7/a0-a6,-(a7)
  712.         bsr    Mus_Stop
  713.  
  714.         clr.l    MUSMemPtr
  715.         clr.l    MUSMemSize
  716.  
  717.         tst.l    InstrPool
  718.         beq.b    .1
  719.         movea.l    InstrPool,a0
  720.         bsr    DeletePool
  721.         clr.l    InstrPool
  722.  
  723. .1        movem.l    (a7)+,d0-d7/a0-a6
  724.         rts
  725.  
  726. ;--------------------------------------
  727.  
  728.         CNOP    0,16
  729.  
  730. Mus_Play    move.b    d1,mus_looping
  731.         move.b    #2,mus_playing        ; 2 = play from start
  732.         rts
  733.  
  734. ;--------------------------------------
  735.  
  736.         CNOP    0,16
  737.  
  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
  743.  
  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
  760.  
  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
  777.  
  778.         clr.b    mus_looping
  779.         clr.l    MusDelay        ; MusDelay = 0
  780.         clr.l    VoiceAvail        ; all voices available
  781.         rts
  782.  
  783. ;--------------------------------------
  784.  
  785.         CNOP    0,16
  786.  
  787. Mus_Pause    clr.b    mus_playing        ; 0 = not playing
  788.         rts
  789.  
  790. ;--------------------------------------
  791.  
  792.         CNOP    0,16
  793.  
  794. Mus_Resume    move.b    #1,mus_playing        ; 1 = play
  795.         rts
  796.  
  797. ;--------------------------------------
  798.  
  799.         CNOP    0,16
  800.  
  801. Mus_Done    moveq    #0,d0
  802.         move.b    mus_playing,d0
  803.         rts
  804.  
  805. ;------------------------------------------------------------------------
  806.  
  807.         CNOP    0,16
  808.  
  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
  821.  
  822.         move.l    d0,d3
  823.         move.l    d3,MUSMemSize
  824.  
  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
  844.         rts
  845.  
  846. .fail        moveq    #0,d0            ; yikes!
  847.         rts
  848.  
  849. ;------------------------------------------------------------------------
  850.  
  851.         cnop    0,16
  852.  
  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
  858.  
  859.         lea    _custom,a0
  860.         move.w    #$0780,intreq(a0)    ; clear int requests
  861.  
  862.         tst.b    mus_playing
  863.         bgt.b    .domus
  864.         beq.b    .musoff
  865.         addq.b    #1,mus_playing        ; now off
  866.  
  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)
  871.  
  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)
  876.  
  877.         bra    .dosfx
  878.  
  879. .domus        cmpi.b    #2,mus_playing
  880.         bne.b    .musnxt
  881.         subq.b    #1,mus_playing
  882.  
  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
  889.  
  890. .musnxt        subq.l    #1,MusDelay
  891.         bpl.b    .fillmus
  892.  
  893.         bsr    NextEvent
  894.  
  895. .fillmus    lea    Voice0,a0        ; music voices
  896.         movea.l    chip_buffer,a2
  897.         bsr    FillBuffer
  898.  
  899.         lea    _custom,a0
  900.  
  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)
  906.  
  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)
  912.  
  913. .dosfx        lea    Voice16,a0        ; sound effect voices
  914.         movea.l    chip_buffer,a2
  915.         lea    256(a2),a2
  916.         bsr    FillBuffer
  917.  
  918.         lea    _custom,a0
  919.  
  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)
  926.  
  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)
  932.  
  933. .exit        movem.l    (a7)+,d2-d7/a2-a6
  934.         moveq    #0,d0
  935.         rts
  936.  
  937. ;------------------------------------------------------------------------
  938.  
  939.         CNOP    0,16
  940.  
  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
  949.  
  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
  958.  
  959. .next        move.l    vc_Next(a0),d0        ; next voice
  960.         bne.b    .chkvoice
  961.  
  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
  970.  
  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
  978.         rts
  979.  
  980. .chkvoice    movea.l    d0,a0
  981. .1stvoice    btst    #0,vc_Flags(a0)
  982.         beq.b    .next            ; not enabled
  983.  
  984. ;------------------
  985. ; do voice
  986.         btst    #7,vc_Flags(a0)
  987.         bne    .5            ; sfx
  988.  
  989.         btst    #1,vc_Flags(a0)
  990.         beq.b    .1            ; not releasing
  991.  
  992.         tst.l    vc_LtVol(a0)
  993.         beq.b    .0
  994.         subi.l    #256,vc_LtVol(a0)
  995.  
  996. .0        tst.l    vc_RtVol(a0)
  997.         beq.b    .1
  998.         subi.l    #256,vc_RtVol(a0)
  999.  
  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
  1006.  
  1007.         clr.b    vc_Flags(a0)        ; voice off
  1008.         bra    .next
  1009.  
  1010. .2        lea    tempAudio,a1        ; left buffer
  1011.         movea.l    vol_lookup,a5
  1012.  
  1013.         movem.l    vc_Index(a0),d1-d4    ; index,step,loop,length
  1014.  
  1015.         movea.l    vc_Channel(a0),a3
  1016.         move.l    ch_Pitch(a3),d0
  1017. ;        muls.l    d0,d5:d2
  1018. ;        move.w    d5,d2
  1019. ;        swap    d2
  1020.         fmove.l    d2,fp0
  1021.         fmul.l    d0,fp0
  1022.         fmul.s    #1.525878906E-5,fp0    ; / 65536
  1023.         fmove.l    fp0,d2
  1024.         add.l    vc_Step(a0),d2        ; final sample rate
  1025.  
  1026.         movea.l    vc_Wave(a0),a3        ; sample data
  1027.  
  1028.         moveq    #79,d5            ; 80 samples
  1029. .floop        move.l    d1,d0
  1030.         swap    d0
  1031.         move.b    (a3,d0.w),d6        ; sample
  1032.         move.b    d6,d7
  1033.         move.b    (a5,d6.l),d6        ; convert
  1034.         move.b    (a5,d7.l),d7        ; convert
  1035.         asr.b    #2,d6
  1036.         asr.b    #2,d7
  1037.         add.b    d6,(a1)+        ; left sample
  1038.         add.b    d7,127(a1)        ; right sample
  1039.  
  1040.         add.l    d2,d1
  1041.         cmp.l    d4,d1
  1042.         blo.b    .3
  1043.         sub.l    d4,d1
  1044.         add.l    d3,d1
  1045.         tst.l    d3
  1046.         beq.b    .4            ; no looping
  1047. .3        dbra    d5,.floop
  1048.         bra.b    .done            ; done with voice
  1049.  
  1050. ; ran out of data
  1051. .4        clr.b    vc_Flags(a0)        ; voice off
  1052.  
  1053. .done        move.l    d1,vc_Index(a0)
  1054.         bra    .next
  1055.  
  1056. ; do sfx voice
  1057.  
  1058. .5        move.l    vc_LtVol(a0),d6
  1059.         move.l    vc_RtVol(a0),d7
  1060.  
  1061.         lea    tempAudio,a1        ; left buffer
  1062.         movea.l    vol_lookup,a5
  1063.  
  1064.         movem.l    vc_Index(a0),d1-d4    ; index,step,loop,length
  1065.  
  1066.         move.l    vc_Step(a0),d2        ; sample rate
  1067.         lsr.l    #8,d2
  1068.  
  1069.         movea.l    vc_Wave(a0),a3        ; sample data
  1070.  
  1071.         moveq    #79,d5            ; 80 samples
  1072. .sfloop        move.l    d1,d0
  1073.         lsr.l    #8,d0
  1074.         move.b    (a3,d0.l),d6        ; sample
  1075.         move.b    d6,d7
  1076.         move.b    (a5,d6.l),d6        ; convert
  1077.         move.b    (a5,d7.l),d7        ; convert
  1078.         asr.b    #2,d6
  1079.         asr.b    #2,d7
  1080.         add.b    d6,(a1)+        ; left sample
  1081.         add.b    d7,127(a1)        ; right sample
  1082.  
  1083.         add.l    d2,d1
  1084.         cmp.l    d4,d1
  1085.         bhs.b    .4            ; ran out of data
  1086.         dbra    d5,.sfloop
  1087.         bra    .done            ; done with voice
  1088.  
  1089. ;------------------------------------------------------------------------
  1090.  
  1091.         CNOP    0,16
  1092.  
  1093. NextEvent    movea.l    MusIndex,a1
  1094.  
  1095. .0        move.b    (a1)+,d0        ; get next event
  1096.         move.b    d0,d1
  1097.         lsr.b    #3,d1
  1098.         andi.w    #$E,d1            ; d1 = event type * 2
  1099.         lea    EventTable,a0
  1100.         move.w    (a0,d1.w),d1
  1101.         jsr    (a0,d1.w)        ; do event
  1102.         tst.b    d0
  1103.         bpl.b    .0            ; more events
  1104.  
  1105.         moveq    #0,d1            ; time = 0
  1106. .1        move.b    (a1)+,d0        ; get byte
  1107.         bpl.b    .2
  1108.  
  1109.         andi.w    #$7F,d0            ; kill sign bit
  1110.         or.b    d0,d1            ; time = time + 7 bits
  1111.         lsl.l    #7,d1            ; * 128
  1112.         bra.b    .1            ; get next 7 bits
  1113.  
  1114. .2        or.b    d0,d1            ; time = time + last 7 bits
  1115.         subq.l    #1,d1            ; delay = time - 1
  1116.         bmi.b    .0            ; (no delay)
  1117.  
  1118.         move.l    d1,MusDelay        ; store delay
  1119.         move.l    a1,MusIndex        ; store index
  1120.         rts
  1121.  
  1122. ;------------------------------------------------------------------------
  1123.  
  1124. Release        moveq    #15,d1
  1125.         and.b    d0,d1            ; d1 = channel
  1126.  
  1127.         lea    Channels,a0
  1128.         movea.l    (a0,d1.w*4),a0        ; channel record
  1129.         movea.l    ch_Map(a0),a0        ; channel map
  1130.  
  1131.         move.b    (a1)+,d1        ; note #
  1132.         moveq    #0,d2
  1133.         move.b    (a0,d1.w),d2        ; voice #
  1134.         beq.b    .exit            ; no mapping
  1135.  
  1136.         clr.b    (a0,d1.w)        ; clear mapping
  1137.         move.l    VoiceAvail,d3
  1138.         bclr    d2,d3            ; voice free for use
  1139.         move.l    d3,VoiceAvail
  1140.  
  1141.         lea    Voices,a0
  1142.         movea.l    (a0,d2.w*4),a0        ; voice
  1143.         bset    #1,vc_Flags(a0)        ; do release
  1144.  
  1145. .exit        rts
  1146.  
  1147. ;------------------------------------------------------------------------
  1148.  
  1149. PlayNote    moveq    #15,d1
  1150.         and.b    d0,d1            ; d1 = channel
  1151.  
  1152.         lea    Channels,a0
  1153.         movea.l    (a0,d1.w*4),a2        ; channel record
  1154.         movea.l    ch_Map(a2),a0        ; channel map
  1155.  
  1156.         moveq    #-1,d2            ; no volume change
  1157.         move.b    (a1)+,d1        ; note #
  1158.         bclr    #7,d1
  1159.         beq.b    .getvc            ; no volume
  1160.  
  1161.         moveq    #0,d2
  1162.         move.b    (a1)+,d2        ; volume
  1163.  
  1164. .getvc        moveq    #0,d3
  1165.         move.l    VoiceAvail,d4
  1166. .vloop        bset    d3,d4
  1167.         beq.b    .foundfree
  1168.         addq.b    #1,d3
  1169.         cmpi.b    #16,d3
  1170.         bne.b    .vloop
  1171. ; no free voices
  1172.         rts
  1173.  
  1174.  
  1175. .foundfree    move.b    d3,(a0,d1.w)        ; voice mapping
  1176.         move.l    d4,VoiceAvail
  1177.  
  1178.         lea    Voices,a0
  1179.         movea.l    (a0,d3.w*4),a3        ; voice
  1180.  
  1181.         tst.b    d2
  1182.         bmi.b    .skip
  1183.  
  1184. ; new channel volume
  1185.  
  1186.         move.b    d2,ch_Vol(a2)
  1187.         moveq    #0,d3
  1188.         move.b    ch_Pan(a2),d3
  1189.         addq.w    #1,d3        ; sep += 1
  1190.         move.w    d2,d4
  1191.         muls.w    d3,d4
  1192.         muls.w    d3,d4
  1193.         clr.w    d4
  1194.         swap    d4
  1195.         neg.w    d4
  1196.         add.w    d2,d4        ; ltvol = vol - vol * (sep+1)^2 / 256^2
  1197.         lsl.l    #8,d4
  1198.         move.l    d4,ch_LtVol(a2)
  1199.  
  1200.         subi.l    #257,d3        ; sep -= 257
  1201.         move.w    d2,d4
  1202.         muls.w    d3,d4
  1203.         muls.w    d3,d4
  1204.         clr.w    d4
  1205.         swap    d4
  1206.         neg.w    d4
  1207.         add.w    d2,d4        ; rtvol = vol - vol * (sep-257)^2 / 256^2
  1208.         lsl.l    #8,d4
  1209.         move.l    d4,ch_RtVol(a2)
  1210.  
  1211. .skip        move.l    ch_LtVol(a2),vc_LtVol(a3)
  1212.         move.l    ch_RtVol(a2),vc_RtVol(a3)
  1213.  
  1214.         moveq    #15,d2
  1215.         and.b    d0,d2
  1216.         cmpi.b    #15,d2
  1217.         beq.b    .percussion
  1218.  
  1219.         move.l    ch_Instr(a2),a4        ; instrument record
  1220.  
  1221.         lea    NoteTable,a0
  1222.         moveq    #72,d2            ; one octave above middle c
  1223.         sub.b    in_Base(a4),d2
  1224.         add.b    d1,d2
  1225.         move.l    (a0,d2.w*4),vc_Step(a3)    ; step value for note
  1226.  
  1227.         clr.l    vc_Index(a3)
  1228.  
  1229.         move.l    a2,vc_Channel(a3)    ; back link (for pitch wheel)
  1230.  
  1231.         move.l    in_Wave(a4),vc_Wave(a3)
  1232.         move.l    in_Loop(a4),vc_Loop(a3)
  1233.         move.l    in_Length(a4),vc_Length(a3)
  1234.         move.b    in_Flags(a4),vc_Flags(a3)
  1235. .exit        rts
  1236.  
  1237. ; for the percussion channel, the note played sets the percussion instrument
  1238.  
  1239. .percussion    move.l    #65536,vc_Step(a3)    ; sample rate always 1.0
  1240.  
  1241.         clr.l    vc_Index(a3)
  1242.  
  1243.         move.l    a2,vc_Channel(a3)    ; back link
  1244.  
  1245.         addi.b    #100,d1            ; percussion instruments
  1246.  
  1247.         lea    Instruments,a0
  1248.         move.l    (a0,d1.w*4),a0        ; instrument record
  1249.         move.l    in_Wave(a0),vc_Wave(a3)
  1250.         move.l    in_Loop(a0),vc_Loop(a3)
  1251.         move.l    in_Length(a0),vc_Length(a3)
  1252.         move.b    in_Flags(a0),vc_Flags(a3)
  1253.         rts
  1254.  
  1255. ;------------------------------------------------------------------------
  1256.  
  1257. Pitch        moveq    #15,d1
  1258.         and.b    d0,d1            ; d1 = channel
  1259.  
  1260.         lea    Channels,a0
  1261.         movea.l    (a0,d1.w*4),a2        ; channel record
  1262.  
  1263.         moveq    #0,d1
  1264.         move.b    (a1)+,d1        ; pitch wheel setting
  1265.         lea    PitchTable,a0
  1266.         move.l    (a0,d1.w*4),ch_Pitch(a2)
  1267.         rts
  1268.  
  1269. ;------------------------------------------------------------------------
  1270.  
  1271. Tempo        addq.l    #1,a1            ; skip value
  1272.         rts
  1273.  
  1274. ;------------------------------------------------------------------------
  1275.  
  1276. ChangeCtrl    moveq    #15,d1
  1277.         and.b    d0,d1            ; d1 = channel
  1278.  
  1279.         lea    Channels,a0
  1280.         movea.l    (a0,d1.w*4),a2        ; channel
  1281.  
  1282.         move.b    (a1)+,d1        ; get controller
  1283.  
  1284.         moveq    #0,d2
  1285.         move.b    (a1)+,d2        ; value
  1286.  
  1287.         tst.b    d1
  1288.         bne.b    .1
  1289.  
  1290. ; set channel instrument
  1291.  
  1292.         lea    Instruments,a0
  1293.         move.l    (a0,d2.w*4),ch_Instr(a2)
  1294.         bne.b    .0
  1295.         move.l    #QuietInst,ch_Instr(a2)
  1296. .0        rts
  1297.  
  1298. .1        cmpi.b    #3,d1            ; volume?
  1299.         bne.b    .2
  1300.  
  1301. ; set channel volume
  1302.  
  1303.         move.b    d2,ch_Vol(a2)
  1304.         moveq    #0,d3
  1305.         move.b    ch_Pan(a2),d3
  1306.         addq.w    #1,d3        ; sep += 1
  1307.         move.w    d2,d4
  1308.         muls.w    d3,d4
  1309.         muls.w    d3,d4
  1310.         clr.w    d4
  1311.         swap    d4
  1312.         neg.w    d4
  1313.         add.w    d2,d4        ; ltvol = vol - vol * (sep+1)^2 / 256^2
  1314.         lsl.l    #8,d4
  1315.         move.l    d4,ch_LtVol(a2)
  1316.  
  1317.         subi.w    #257,d3        ; sep -= 257
  1318.         move.w    d2,d4
  1319.         muls.w    d3,d4
  1320.         muls.w    d3,d4
  1321.         clr.w    d4
  1322.         swap    d4
  1323.         neg.w    d4
  1324.         add.w    d2,d4        ; rtvol = vol - vol * (sep-257)^2 / 256^2
  1325.         lsl.l    #8,d4
  1326.         move.l    d4,ch_RtVol(a2)
  1327.         rts
  1328.  
  1329. .2        cmpi.b    #4,d1            ; pan?
  1330.         bne.b    .exit
  1331.  
  1332. ; set channel pan
  1333.  
  1334.         add.b    d2,d2        ; pan -> sep
  1335.         move.b    d2,ch_Pan(a2)
  1336.         move.b    ch_Vol(a2),d2
  1337.         moveq    #0,d3
  1338.         move.b    ch_Pan(a2),d3
  1339.         addq.w    #1,d3        ; sep += 1
  1340.         move.w    d2,d4
  1341.         muls.w    d3,d4
  1342.         muls.w    d3,d4
  1343.         clr.w    d4
  1344.         swap    d4
  1345.         neg.w    d4
  1346.         add.w    d2,d4        ; ltvol = vol - vol * (sep+1)^2 / 256^2
  1347.         lsl.l    #8,d4
  1348.         move.l    d4,ch_LtVol(a2)
  1349.  
  1350.         subi.w    #257,d3        ; sep -= 257
  1351.         move.w    d2,d4
  1352.         muls.w    d3,d4
  1353.         muls.w    d3,d4
  1354.         clr.w    d4
  1355.         swap    d4
  1356.         neg.w    d4
  1357.         add.w    d2,d4        ; rtvol = vol - vol * (sep-257)^2 / 256^2
  1358.         lsl.l    #8,d4
  1359.         move.l    d4,ch_RtVol(a2)
  1360. .exit        rts
  1361.  
  1362. ;------------------------------------------------------------------------
  1363.  
  1364. NoEvent        rts
  1365.  
  1366. ;------------------------------------------------------------------------
  1367.  
  1368. EndScore    tst.b    mus_looping        ; loop?
  1369.         bne    .loop
  1370.  
  1371.         move.l    #QuietInst,Channel0
  1372.         move.l    #QuietInst,Channel1
  1373.         move.l    #QuietInst,Channel2
  1374.         move.l    #QuietInst,Channel3
  1375.         move.l    #QuietInst,Channel4
  1376.         move.l    #QuietInst,Channel5
  1377.         move.l    #QuietInst,Channel6
  1378.         move.l    #QuietInst,Channel7
  1379.         move.l    #QuietInst,Channel8
  1380.         move.l    #QuietInst,Channel9
  1381.         move.l    #QuietInst,Channel10
  1382.         move.l    #QuietInst,Channel11
  1383.         move.l    #QuietInst,Channel12
  1384.         move.l    #QuietInst,Channel13
  1385.         move.l    #QuietInst,Channel14
  1386.         move.l    #QuietInst,Channel15
  1387.  
  1388.         clr.b    Voice0+vc_Flags        ; disable voices
  1389.         clr.b    Voice1+vc_Flags
  1390.         clr.b    Voice2+vc_Flags
  1391.         clr.b    Voice3+vc_Flags
  1392.         clr.b    Voice4+vc_Flags
  1393.         clr.b    Voice5+vc_Flags
  1394.         clr.b    Voice6+vc_Flags
  1395.         clr.b    Voice7+vc_Flags
  1396.         clr.b    Voice8+vc_Flags
  1397.         clr.b    Voice9+vc_Flags
  1398.         clr.b    Voice10+vc_Flags
  1399.         clr.b    Voice11+vc_Flags
  1400.         clr.b    Voice12+vc_Flags
  1401.         clr.b    Voice13+vc_Flags
  1402.         clr.b    Voice14+vc_Flags
  1403.         clr.b    Voice15+vc_Flags
  1404.  
  1405.         clr.l    MusDelay        ; MusDelay = 0
  1406.         clr.l    VoiceAvail        ; all voices available
  1407.         clr.b    mus_playing
  1408.         addq.l    #4,a7            ; pop NextEvent
  1409.         rts
  1410.  
  1411. .loop        movea.l    MusPtr,a1
  1412.         moveq    #0,d1
  1413.         move.w    6(a1),d1        ; score start
  1414.         ror.w    #8,d1
  1415.         adda.l    d1,a1            ; a1 = start
  1416.         rts
  1417.  
  1418. ;------------------------------------------------------------------------
  1419.         cnop    0,4
  1420.  
  1421. EventTable    dc.w    Release-EventTable
  1422.         dc.w    PlayNote-EventTable
  1423.         dc.w    Pitch-EventTable
  1424.         dc.w    Tempo-EventTable
  1425.         dc.w    ChangeCtrl-EventTable
  1426.         dc.w    NoEvent-EventTable
  1427.         dc.w    EndScore-EventTable
  1428.         dc.w    NoEvent-EventTable
  1429.  
  1430. ;------------------------------------------------------------------------
  1431. ;--------------------------------------------------------------------
  1432.  
  1433.         cnop    0,4
  1434.  
  1435. CreatePool    movea.l    _ExecBase,a1
  1436.         cmpi.w    #39,LIB_VERSION(a1)
  1437.         blt.b    .nopools        ; change to bra for debugging
  1438.  
  1439.         move.l    a6,-(sp)
  1440.         movea.l    a1,a6
  1441.         CALLSYS    CreatePool
  1442.         movea.l    (sp)+,a6
  1443.         rts
  1444.  
  1445. .nopools    movem.l    d2-d7/a2-a6,-(sp)
  1446.         move.l    d0,d4            ; memory attributes
  1447.         move.l    d1,d3            ; amount to allocate when low
  1448.         move.l    d2,d5            ; size of when not to use pool
  1449.  
  1450.         exg.l    d0,d1            ; swap flags and size
  1451.         movea.l    a1,a6
  1452.         CALLSYS    AllocMem        ; get first block
  1453.         movea.l    d0,a0
  1454.         tst.l    d0
  1455.         beq.b    .exit            ; no memory!
  1456.  
  1457.         movem.l    d3-d5,(a0)        ; puddleSize, Flags,Threshold
  1458.         clr.l    12(a0)            ; no next block
  1459.         lea    24(a0),a1        ; first free location here
  1460.         move.l    a1,16(a0)
  1461.         subi.l    #24,d3            ; for header info
  1462.         move.l    d3,20(a0)        ; amount free in this block
  1463.  
  1464. .exit        movem.l    (sp)+,d2-d7/a2-a6
  1465.         rts
  1466.  
  1467.         cnop    0,4
  1468.  
  1469. DeletePool    movea.l    _ExecBase,a1
  1470.         cmpi.w    #39,LIB_VERSION(a1)
  1471.         blt.b    .nopools        ; change to bra for debugging
  1472.  
  1473.         move.l    a6,-(sp)
  1474.         movea.l    a1,a6
  1475.         CALLSYS    DeletePool
  1476.         movea.l    (sp)+,a6
  1477.         rts
  1478.  
  1479. .nopools    movem.l    d2-d7/a2-a6,-(sp)
  1480.         move.l    a0,d2            ; first block
  1481.         beq.b    .exit            ; safety check
  1482.  
  1483.         movea.l    a1,a6
  1484.  
  1485. .loop        movea.l    d2,a1            ; pointer to block
  1486.         move.l    (a1),d0            ; size of block
  1487.         move.l    12(a1),d2        ; next block
  1488.         CALLSYS    FreeMem
  1489.         tst.l    d2
  1490.         bne.b    .loop
  1491.  
  1492. .exit        movem.l    (sp)+,d2-d7/a2-a6
  1493.         rts
  1494.  
  1495.         cnop    0,4
  1496.  
  1497. AllocPooled    movea.l    _ExecBase,a1
  1498.         cmpi.w    #39,LIB_VERSION(a1)
  1499.         blt.b    .nopools        ; change to bra for debugging
  1500.  
  1501.         move.l    a6,-(sp)
  1502.         movea.l    a1,a6
  1503.         CALLSYS    AllocPooled
  1504.         movea.l    (sp)+,a6
  1505.         rts
  1506.  
  1507. .nopools    movem.l    d2-d7/a2-a6,-(sp)
  1508.         move.l    a0,d2
  1509.         beq.b    .exit            ; safety check
  1510.  
  1511.         addq.l    #3,d0
  1512.         andi.b    #$FC,d0            ; long align size
  1513.  
  1514.         movea.l    a1,a6
  1515.  
  1516.         cmp.l    8(a0),d0        ; check threshold
  1517.         blt.b    .chkpuddles        ; allocate from puddles
  1518.  
  1519.         addi.l    #24,d0            ; for header
  1520.         move.l    d0,d3            ; save size
  1521.         move.l    4(a0),d1        ; mem attrs
  1522.         CALLSYS    AllocMem
  1523.         movea.l    d0,a0
  1524.         tst.l    d0
  1525.         beq.b    .exit            ; no memory
  1526.  
  1527.         move.l    d3,(a0)            ; size of block
  1528.         clr.l    20(a0)            ; no free space in here
  1529.  
  1530.         movea.l    d2,a1            ; pool header
  1531.         move.l    12(a1),d1
  1532.         move.l    a0,12(a1)        ; splice in block
  1533.         move.l    d1,12(a0)        ; relink next block
  1534.         lea    24(a0),a0        ; skip over header
  1535.  
  1536. .exit        move.l    a0,d0
  1537.         movem.l    (sp)+,d2-d7/a2-a6
  1538.         rts
  1539.  
  1540.         cnop    0,4
  1541.  
  1542. .chkpuddles    cmp.l    20(a0),d0        ; check free space
  1543.         blt.b    .gotspace
  1544.  
  1545.         movea.l    12(a0),a0        ; next block
  1546.         move.l    a0,d1
  1547.         bne.b    .chkpuddles
  1548.  
  1549. ; not enough free space in existing puddles, create another
  1550.  
  1551.         move.l    d0,d6            ; save size
  1552.  
  1553.         movea.l    d2,a0            ; pool header
  1554.         movem.l    (a0),d3-d5
  1555.         movem.l    (a0),d0-d1
  1556.         CALLSYS    AllocMem        ; get block
  1557.         movea.l    d0,a0
  1558.         tst.l    d0
  1559.         beq.b    .out            ; no memory!
  1560.  
  1561.         movea.l    d2,a1            ; pool header
  1562.         movem.l    d3-d5,(a0)        ; puddleSize, Flags,Threshold
  1563.         move.l    12(a1),12(a0)        ; next block
  1564.         move.l    a0,12(a1)        ; splice in block
  1565.         lea    24(a0),a1        ; first free location here
  1566.         move.l    a1,16(a0)
  1567.         subi.l    #24,d3            ; for header info
  1568.         move.l    d3,20(a0)        ; amount free in this block
  1569.  
  1570.         move.l    d6,d0            ; restore size
  1571.  
  1572. .gotspace    sub.l    d0,20(a0)        ; sub from amount free
  1573.         bmi.b    .err            ; threshold >= puddlesize!
  1574.  
  1575.         move.l    16(a0),a1        ; free space
  1576.         add.l    d0,16(a0)        ; next free space
  1577.  
  1578.         movea.l    a1,a0
  1579.         bra.b    .out
  1580.  
  1581. .err        add.l    d0,20(a0)        ; restore free space
  1582.         moveq    #0,d0
  1583.         suba.l    a0,a0            ; no memory
  1584.  
  1585. .out        move.l    a0,d0
  1586.         movem.l    (sp)+,d2-d7/a2-a6
  1587.         rts
  1588.  
  1589. ;------------------------------------------------------------------------
  1590. ;------------------------------------------------------------------------
  1591.  
  1592.         cnop    0,4
  1593.  
  1594. MUSMemPtr    dc.l    0
  1595. MUSMemSize    dc.l    0
  1596.  
  1597. SegList        dc.l    0
  1598. _ExecBase    dc.l    0
  1599. _DOSBase    dc.l    0
  1600. LookupMem    dc.l    0
  1601. vol_lookup    dc.l    0
  1602.  
  1603. ;------------------------------------------------------------------------
  1604.  
  1605. period        dc.w    325    ; NTSC 11025 KHz
  1606. sfx_volume    dc.w    64
  1607. mus_volume    dc.w    64
  1608. mus_playing    dc.b    0
  1609. mus_looping    dc.b    0
  1610.  
  1611. ;------------------------------------------------------------------------
  1612.  
  1613.         cnop    0,4
  1614.  
  1615. AudioPort    dc.l    0
  1616. AudioIO        dc.l    0
  1617.  
  1618. AInt0        dc.l    0,0
  1619.         dc.b    NT_INTERRUPT,0        ; LN_TYPE, LN_PRI
  1620.         dc.l    AIntName        ; LN_NAME
  1621.         dc.l    0            ; IS_DATA
  1622.         dc.l    AudioINT0        ; IS_CODE
  1623.  
  1624. MusPtr        dc.l    0
  1625. MusIndex    dc.l    0
  1626. MusDelay    dc.l    0
  1627. OldAInt0    dc.l    0
  1628.  
  1629. AudioAlloc    dc.b    $0F            ; Amiga channels to allocate
  1630.  
  1631. GfxName        dc.b    'graphics.library',0
  1632. DOSName        dc.b    'dos.library',0
  1633. AudioName    dc.b    'audio.device',0
  1634. AIntName    dc.b    'DOOM Sound Server',0
  1635.  
  1636. ;--------------------------------------
  1637.  
  1638.         CNOP    0,4
  1639.  
  1640. ; bit set if voice is in use (0-15=music voices,16-31=sfx voices)
  1641.  
  1642. VoiceAvail    dc.l    0
  1643.  
  1644. chip_buffer    dc.l    chipBuffer
  1645. chip_offset    dc.l    512
  1646.  
  1647. ;--------------------------------------------------------------------
  1648.  
  1649.         CNOP    0,4
  1650.  
  1651. 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
  1652.         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
  1653.         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
  1654.         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
  1655.         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
  1656.         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
  1657.         dc.l    65536,69433,73562,77936,82570,87480,92682,98193,104032,110218,116772,123715
  1658.         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
  1659.         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
  1660.         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
  1661.         dc.l    65536*16,69433*16,73562*16,77936*16,82570*16,87480*16,92682*16,98193*16
  1662.  
  1663. ;------------------------------------------------------------------------
  1664.  
  1665. PitchTable:
  1666.  
  1667. pitch_ix    SET    128
  1668.  
  1669.         REPT    128
  1670.         dc.l    -3678*pitch_ix/64
  1671. pitch_ix    SET    pitch_ix-1
  1672.         ENDR
  1673.  
  1674.         REPT    128
  1675.         dc.l    3897*pitch_ix/64
  1676. pitch_ix    SET    pitch_ix+1
  1677.         ENDR
  1678.  
  1679. ;------------------------------------------------------------------------
  1680.  
  1681.         STRUCTURE MusChannel,0
  1682.         APTR    ch_Instr
  1683.         APTR    ch_Map
  1684.         ULONG    ch_Pitch
  1685.         APTR    ch_LtVol
  1686.         APTR    ch_RtVol
  1687.         BYTE    ch_Vol
  1688.         BYTE    ch_Pan
  1689.  
  1690.  
  1691.         CNOP    0,4
  1692.  
  1693. Channels    dc.l    Channel0,Channel1,Channel2,Channel3
  1694.         dc.l    Channel4,Channel5,Channel6,Channel7
  1695.         dc.l    Channel8,Channel9,Channel10,Channel11
  1696.         dc.l    Channel12,Channel13,Channel14,Channel15
  1697.  
  1698.  
  1699.         CNOP    0,4
  1700.  
  1701. Channel0    dc.l    0        ; instrument
  1702.         dc.l    Channel0Map    ; note to voice map
  1703.         dc.l    0        ; pitch wheel setting
  1704.         dc.l    0        ; left volume table
  1705.         dc.l    0        ; right volume table
  1706.         dc.b    0        ; volume
  1707.         dc.b    0        ; pan setting
  1708.  
  1709.         CNOP    0,4
  1710.  
  1711. Channel1    dc.l    0        ; instrument
  1712.         dc.l    Channel1Map    ; note to voice map
  1713.         dc.l    0        ; pitch wheel setting
  1714.         dc.l    0        ; left volume table
  1715.         dc.l    0        ; right volume table
  1716.         dc.b    0        ; volume
  1717.         dc.b    0        ; pan setting
  1718.  
  1719.         CNOP    0,4
  1720.  
  1721. Channel2    dc.l    0        ; instrument
  1722.         dc.l    Channel2Map    ; note to voice map
  1723.         dc.l    0        ; pitch wheel setting
  1724.         dc.l    0        ; left volume table
  1725.         dc.l    0        ; right volume table
  1726.         dc.b    0        ; volume
  1727.         dc.b    0        ; pan setting
  1728.  
  1729.         CNOP    0,4
  1730.  
  1731. Channel3    dc.l    0        ; instrument
  1732.         dc.l    Channel3Map    ; note to voice map
  1733.         dc.l    0        ; pitch wheel setting
  1734.         dc.l    0        ; left volume table
  1735.         dc.l    0        ; right volume table
  1736.         dc.b    0        ; volume
  1737.         dc.b    0        ; pan setting
  1738.  
  1739.         CNOP    0,4
  1740.  
  1741. Channel4    dc.l    0        ; instrument
  1742.         dc.l    Channel4Map    ; note to voice map
  1743.         dc.l    0        ; pitch wheel setting
  1744.         dc.l    0        ; left volume table
  1745.         dc.l    0        ; right volume table
  1746.         dc.b    0        ; volume
  1747.         dc.b    0        ; pan setting
  1748.  
  1749.         CNOP    0,4
  1750.  
  1751. Channel5    dc.l    0        ; instrument
  1752.         dc.l    Channel5Map    ; note to voice map
  1753.         dc.l    0        ; pitch wheel setting
  1754.         dc.l    0        ; left volume table
  1755.         dc.l    0        ; right volume table
  1756.         dc.b    0        ; volume
  1757.         dc.b    0        ; pan setting
  1758.  
  1759.         CNOP    0,4
  1760.  
  1761. Channel6    dc.l    0        ; instrument
  1762.         dc.l    Channel6Map    ; note to voice map
  1763.         dc.l    0        ; pitch wheel setting
  1764.         dc.l    0        ; left volume table
  1765.         dc.l    0        ; right volume table
  1766.         dc.b    0        ; volume
  1767.         dc.b    0        ; pan setting
  1768.  
  1769.         CNOP    0,4
  1770.  
  1771. Channel7    dc.l    0        ; instrument
  1772.         dc.l    Channel7Map    ; note to voice map
  1773.         dc.l    0        ; pitch wheel setting
  1774.         dc.l    0        ; left volume table
  1775.         dc.l    0        ; right volume table
  1776.         dc.b    0        ; volume
  1777.         dc.b    0        ; pan setting
  1778.  
  1779.         CNOP    0,4
  1780.  
  1781. Channel8    dc.l    0        ; instrument
  1782.         dc.l    Channel8Map    ; note to voice map
  1783.         dc.l    0        ; pitch wheel setting
  1784.         dc.l    0        ; left volume table
  1785.         dc.l    0        ; right volume table
  1786.         dc.b    0        ; volume
  1787.         dc.b    0        ; pan setting
  1788.  
  1789.         CNOP    0,4
  1790.  
  1791. Channel9    dc.l    0        ; instrument
  1792.         dc.l    Channel9Map    ; note to voice map
  1793.         dc.l    0        ; pitch wheel setting
  1794.         dc.l    0        ; left volume table
  1795.         dc.l    0        ; right volume table
  1796.         dc.b    0        ; volume
  1797.         dc.b    0        ; pan setting
  1798.  
  1799.         CNOP    0,4
  1800.  
  1801. Channel10    dc.l    0        ; instrument
  1802.         dc.l    Channel10Map    ; note to voice map
  1803.         dc.l    0        ; pitch wheel setting
  1804.         dc.l    0        ; left volume table
  1805.         dc.l    0        ; right volume table
  1806.         dc.b    0        ; volume
  1807.         dc.b    0        ; pan setting
  1808.  
  1809.         CNOP    0,4
  1810.  
  1811. Channel11    dc.l    0        ; instrument
  1812.         dc.l    Channel11Map    ; note to voice map
  1813.         dc.l    0        ; pitch wheel setting
  1814.         dc.l    0        ; left volume table
  1815.         dc.l    0        ; right volume table
  1816.         dc.b    0        ; volume
  1817.         dc.b    0        ; pan setting
  1818.  
  1819.         CNOP    0,4
  1820.  
  1821. Channel12    dc.l    0        ; instrument
  1822.         dc.l    Channel12Map    ; note to voice map
  1823.         dc.l    0        ; pitch wheel setting
  1824.         dc.l    0        ; left volume table
  1825.         dc.l    0        ; right volume table
  1826.         dc.b    0        ; volume
  1827.         dc.b    0        ; pan setting
  1828.  
  1829.         CNOP    0,4
  1830.  
  1831. Channel13    dc.l    0        ; instrument
  1832.         dc.l    Channel13Map    ; note to voice map
  1833.         dc.l    0        ; pitch wheel setting
  1834.         dc.l    0        ; left volume table
  1835.         dc.l    0        ; right volume table
  1836.         dc.b    0        ; volume
  1837.         dc.b    0        ; pan setting
  1838.  
  1839.         CNOP    0,4
  1840.  
  1841. Channel14    dc.l    0        ; instrument
  1842.         dc.l    Channel14Map    ; note to voice map
  1843.         dc.l    0        ; pitch wheel setting
  1844.         dc.l    0        ; left volume table
  1845.         dc.l    0        ; right volume table
  1846.         dc.b    0        ; volume
  1847.         dc.b    0        ; pan setting
  1848.  
  1849.         CNOP    0,4
  1850.  
  1851. Channel15    dc.l    0        ; instrument
  1852.         dc.l    Channel15Map    ; note to voice map
  1853.         dc.l    0        ; pitch wheel setting
  1854.         dc.l    0        ; left volume table
  1855.         dc.l    0        ; right volume table
  1856.         dc.b    0        ; volume
  1857.         dc.b    0        ; pan setting
  1858.  
  1859.  
  1860.         CNOP    0,4
  1861.  
  1862. Channel0Map    dcb.b    128,0
  1863. Channel1Map    dcb.b    128,0
  1864. Channel2Map    dcb.b    128,0
  1865. Channel3Map    dcb.b    128,0
  1866. Channel4Map    dcb.b    128,0
  1867. Channel5Map    dcb.b    128,0
  1868. Channel6Map    dcb.b    128,0
  1869. Channel7Map    dcb.b    128,0
  1870. Channel8Map    dcb.b    128,0
  1871. Channel9Map    dcb.b    128,0
  1872. Channel10Map    dcb.b    128,0
  1873. Channel11Map    dcb.b    128,0
  1874. Channel12Map    dcb.b    128,0
  1875. Channel13Map    dcb.b    128,0
  1876. Channel14Map    dcb.b    128,0
  1877. Channel15Map    dcb.b    128,0
  1878.  
  1879. ;--------------------------------------
  1880.  
  1881.         STRUCTURE AudioVoice,0
  1882.         APTR    vc_Next
  1883.         APTR    vc_Channel
  1884.         APTR    vc_Wave
  1885.         ULONG    vc_Index
  1886.         ULONG    vc_Step
  1887.         ULONG    vc_Loop
  1888.         ULONG    vc_Length
  1889.         APTR    vc_LtVol
  1890.         APTR    vc_RtVol
  1891.         BYTE    vc_Flags    ; b7 = SFX, b1 = RLS, b0 = EN
  1892.  
  1893.         CNOP    0,4
  1894.  
  1895. Voices        dc.l    Voice0,Voice1,Voice2,Voice3
  1896.         dc.l    Voice4,Voice5,Voice6,Voice7
  1897.         dc.l    Voice8,Voice9,Voice10,Voice11
  1898.         dc.l    Voice12,Voice13,Voice14,Voice15
  1899.  
  1900. sfxVoiceTbl    dc.l    Voice16,Voice17,Voice18,Voice19
  1901.         dc.l    Voice20,Voice21,Voice22,Voice23
  1902.         dc.l    Voice24,Voice25,Voice26,Voice27
  1903.         dc.l    Voice28,Voice29,Voice30,Voice31
  1904.  
  1905. ; Music Voices
  1906.  
  1907.         CNOP    0,4
  1908.  
  1909. Voice0        dc.l    Voice1
  1910.         dc.l    0        ; channel back-link
  1911.         dc.l    0        ; instrument wave data
  1912.         dc.l    0        ; sample index
  1913.         dc.l    0        ; sample rate
  1914.         dc.l    0        ; instrument loop point
  1915.         dc.l    0        ; instrument data length
  1916.         dc.l    0        ; left volume table
  1917.         dc.l    0        ; right volume table
  1918.         dc.b    0        ; voice flags
  1919.  
  1920.         CNOP    0,4
  1921.  
  1922. Voice1        dc.l    Voice2
  1923.         dc.l    0        ; channel back-link
  1924.         dc.l    0        ; instrument wave data
  1925.         dc.l    0        ; sample index
  1926.         dc.l    0        ; sample rate
  1927.         dc.l    0        ; instrument loop point
  1928.         dc.l    0        ; instrument data length
  1929.         dc.l    0        ; left volume table
  1930.         dc.l    0        ; right volume table
  1931.         dc.b    0        ; voice flags
  1932.  
  1933.         CNOP    0,4
  1934.  
  1935. Voice2        dc.l    Voice3
  1936.         dc.l    0        ; channel back-link
  1937.         dc.l    0        ; instrument wave data
  1938.         dc.l    0        ; sample index
  1939.         dc.l    0        ; sample rate
  1940.         dc.l    0        ; instrument loop point
  1941.         dc.l    0        ; instrument data length
  1942.         dc.l    0        ; left volume table
  1943.         dc.l    0        ; right volume table
  1944.         dc.b    0        ; voice flags
  1945.  
  1946.         CNOP    0,4
  1947.  
  1948. Voice3        dc.l    Voice4
  1949.         dc.l    0        ; channel back-link
  1950.         dc.l    0        ; instrument wave data
  1951.         dc.l    0        ; sample index
  1952.         dc.l    0        ; sample rate
  1953.         dc.l    0        ; instrument loop point
  1954.         dc.l    0        ; instrument data length
  1955.         dc.l    0        ; left volume table
  1956.         dc.l    0        ; right volume table
  1957.         dc.b    0        ; voice flags
  1958.  
  1959.         CNOP    0,4
  1960.  
  1961. Voice4        dc.l    Voice5
  1962.         dc.l    0        ; channel back-link
  1963.         dc.l    0        ; instrument wave data
  1964.         dc.l    0        ; sample index
  1965.         dc.l    0        ; sample rate
  1966.         dc.l    0        ; instrument loop point
  1967.         dc.l    0        ; instrument data length
  1968.         dc.l    0        ; left volume table
  1969.         dc.l    0        ; right volume table
  1970.         dc.b    0        ; voice flags
  1971.  
  1972.         CNOP    0,4
  1973.  
  1974. Voice5        dc.l    Voice6
  1975.         dc.l    0        ; channel back-link
  1976.         dc.l    0        ; instrument wave data
  1977.         dc.l    0        ; sample index
  1978.         dc.l    0        ; sample rate
  1979.         dc.l    0        ; instrument loop point
  1980.         dc.l    0        ; instrument data length
  1981.         dc.l    0        ; left volume table
  1982.         dc.l    0        ; right volume table
  1983.         dc.b    0        ; voice flags
  1984.  
  1985.         CNOP    0,4
  1986.  
  1987. Voice6        dc.l    Voice7
  1988.         dc.l    0        ; channel back-link
  1989.         dc.l    0        ; instrument wave data
  1990.         dc.l    0        ; sample index
  1991.         dc.l    0        ; sample rate
  1992.         dc.l    0        ; instrument loop point
  1993.         dc.l    0        ; instrument data length
  1994.         dc.l    0        ; left volume table
  1995.         dc.l    0        ; right volume table
  1996.         dc.b    0        ; voice flags
  1997.  
  1998.         CNOP    0,4
  1999.  
  2000. Voice7        dc.l    Voice8
  2001.         dc.l    0        ; channel back-link
  2002.         dc.l    0        ; instrument wave data
  2003.         dc.l    0        ; sample index
  2004.         dc.l    0        ; sample rate
  2005.         dc.l    0        ; instrument loop point
  2006.         dc.l    0        ; instrument data length
  2007.         dc.l    0        ; left volume table
  2008.         dc.l    0        ; right volume table
  2009.         dc.b    0        ; voice flags
  2010.  
  2011.         CNOP    0,4
  2012.  
  2013. Voice8        dc.l    Voice9
  2014.         dc.l    0        ; channel back-link
  2015.         dc.l    0        ; instrument wave data
  2016.         dc.l    0        ; sample index
  2017.         dc.l    0        ; sample rate
  2018.         dc.l    0        ; instrument loop point
  2019.         dc.l    0        ; instrument data length
  2020.         dc.l    0        ; left volume table
  2021.         dc.l    0        ; right volume table
  2022.         dc.b    0        ; voice flags
  2023.  
  2024.         CNOP    0,4
  2025.  
  2026. Voice9        dc.l    Voice10
  2027.         dc.l    0        ; channel back-link
  2028.         dc.l    0        ; instrument wave data
  2029.         dc.l    0        ; sample index
  2030.         dc.l    0        ; sample rate
  2031.         dc.l    0        ; instrument loop point
  2032.         dc.l    0        ; instrument data length
  2033.         dc.l    0        ; left volume table
  2034.         dc.l    0        ; right volume table
  2035.         dc.b    0        ; voice flags
  2036.  
  2037.         CNOP    0,4
  2038.  
  2039. Voice10        dc.l    Voice11
  2040.         dc.l    0        ; channel back-link
  2041.         dc.l    0        ; instrument wave data
  2042.         dc.l    0        ; sample index
  2043.         dc.l    0        ; sample rate
  2044.         dc.l    0        ; instrument loop point
  2045.         dc.l    0        ; instrument data length
  2046.         dc.l    0        ; left volume table
  2047.         dc.l    0        ; right volume table
  2048.         dc.b    0        ; voice flags
  2049.  
  2050.         CNOP    0,4
  2051.  
  2052. Voice11        dc.l    Voice12
  2053.         dc.l    0        ; channel back-link
  2054.         dc.l    0        ; instrument wave data
  2055.         dc.l    0        ; sample index
  2056.         dc.l    0        ; sample rate
  2057.         dc.l    0        ; instrument loop point
  2058.         dc.l    0        ; instrument data length
  2059.         dc.l    0        ; left volume table
  2060.         dc.l    0        ; right volume table
  2061.         dc.b    0        ; voice flags
  2062.  
  2063.         CNOP    0,4
  2064.  
  2065. Voice12        dc.l    Voice13
  2066.         dc.l    0        ; channel back-link
  2067.         dc.l    0        ; instrument wave data
  2068.         dc.l    0        ; sample index
  2069.         dc.l    0        ; sample rate
  2070.         dc.l    0        ; instrument loop point
  2071.         dc.l    0        ; instrument data length
  2072.         dc.l    0        ; left volume table
  2073.         dc.l    0        ; right volume table
  2074.         dc.b    0        ; voice flags
  2075.  
  2076.         CNOP    0,4
  2077.  
  2078. Voice13        dc.l    Voice14
  2079.         dc.l    0        ; channel back-link
  2080.         dc.l    0        ; instrument wave data
  2081.         dc.l    0        ; sample index
  2082.         dc.l    0        ; sample rate
  2083.         dc.l    0        ; instrument loop point
  2084.         dc.l    0        ; instrument data length
  2085.         dc.l    0        ; left volume table
  2086.         dc.l    0        ; right volume table
  2087.         dc.b    0        ; voice flags
  2088.  
  2089.         CNOP    0,4
  2090.  
  2091. Voice14        dc.l    Voice15
  2092.         dc.l    0        ; channel back-link
  2093.         dc.l    0        ; instrument wave data
  2094.         dc.l    0        ; sample index
  2095.         dc.l    0        ; sample rate
  2096.         dc.l    0        ; instrument loop point
  2097.         dc.l    0        ; instrument data length
  2098.         dc.l    0        ; left volume table
  2099.         dc.l    0        ; right volume table
  2100.         dc.b    0        ; voice flags
  2101.  
  2102.         CNOP    0,4
  2103.  
  2104. Voice15        dc.l    0
  2105.         dc.l    0        ; channel back-link
  2106.         dc.l    0        ; instrument wave data
  2107.         dc.l    0        ; sample index
  2108.         dc.l    0        ; sample rate
  2109.         dc.l    0        ; instrument loop point
  2110.         dc.l    0        ; instrument data length
  2111.         dc.l    0        ; left volume table
  2112.         dc.l    0        ; right volume table
  2113.         dc.b    0        ; voice flags
  2114.  
  2115. ; Sound Effect Voices
  2116.  
  2117.         CNOP    0,4
  2118.  
  2119. Voice16        dc.l    Voice17
  2120.         dc.l    0        ; channel back-link
  2121.         dc.l    0        ; instrument wave data
  2122.         dc.l    0        ; sample index
  2123.         dc.l    0        ; sample rate
  2124.         dc.l    0        ; instrument loop point
  2125.         dc.l    0        ; instrument data length
  2126.         dc.l    0        ; left volume table
  2127.         dc.l    0        ; right volume table
  2128.         dc.b    0        ; voice flags
  2129.  
  2130.         CNOP    0,4
  2131.  
  2132. Voice17        dc.l    Voice18
  2133.         dc.l    0        ; channel back-link
  2134.         dc.l    0        ; instrument wave data
  2135.         dc.l    0        ; sample index
  2136.         dc.l    0        ; sample rate
  2137.         dc.l    0        ; instrument loop point
  2138.         dc.l    0        ; instrument data length
  2139.         dc.l    0        ; left volume table
  2140.         dc.l    0        ; right volume table
  2141.         dc.b    0        ; voice flags
  2142.  
  2143.         CNOP    0,4
  2144.  
  2145. Voice18        dc.l    Voice19
  2146.         dc.l    0        ; channel back-link
  2147.         dc.l    0        ; instrument wave data
  2148.         dc.l    0        ; sample index
  2149.         dc.l    0        ; sample rate
  2150.         dc.l    0        ; instrument loop point
  2151.         dc.l    0        ; instrument data length
  2152.         dc.l    0        ; left volume table
  2153.         dc.l    0        ; right volume table
  2154.         dc.b    0        ; voice flags
  2155.  
  2156.         CNOP    0,4
  2157.  
  2158. Voice19        dc.l    Voice20
  2159.         dc.l    0        ; channel back-link
  2160.         dc.l    0        ; instrument wave data
  2161.         dc.l    0        ; sample index
  2162.         dc.l    0        ; sample rate
  2163.         dc.l    0        ; instrument loop point
  2164.         dc.l    0        ; instrument data length
  2165.         dc.l    0        ; left volume table
  2166.         dc.l    0        ; right volume table
  2167.         dc.b    0        ; voice flags
  2168.  
  2169.         CNOP    0,4
  2170.  
  2171. Voice20        dc.l    Voice21
  2172.         dc.l    0        ; channel back-link
  2173.         dc.l    0        ; instrument wave data
  2174.         dc.l    0        ; sample index
  2175.         dc.l    0        ; sample rate
  2176.         dc.l    0        ; instrument loop point
  2177.         dc.l    0        ; instrument data length
  2178.         dc.l    0        ; left volume table
  2179.         dc.l    0        ; right volume table
  2180.         dc.b    0        ; voice flags
  2181.  
  2182.         CNOP    0,4
  2183.  
  2184. Voice21        dc.l    Voice22
  2185.         dc.l    0        ; channel back-link
  2186.         dc.l    0        ; instrument wave data
  2187.         dc.l    0        ; sample index
  2188.         dc.l    0        ; sample rate
  2189.         dc.l    0        ; instrument loop point
  2190.         dc.l    0        ; instrument data length
  2191.         dc.l    0        ; left volume table
  2192.         dc.l    0        ; right volume table
  2193.         dc.b    0        ; voice flags
  2194.  
  2195.         CNOP    0,4
  2196.  
  2197. Voice22        dc.l    Voice23
  2198.         dc.l    0        ; channel back-link
  2199.         dc.l    0        ; instrument wave data
  2200.         dc.l    0        ; sample index
  2201.         dc.l    0        ; sample rate
  2202.         dc.l    0        ; instrument loop point
  2203.         dc.l    0        ; instrument data length
  2204.         dc.l    0        ; left volume table
  2205.         dc.l    0        ; right volume table
  2206.         dc.b    0        ; voice flags
  2207.  
  2208.         CNOP    0,4
  2209.  
  2210. Voice23        dc.l    Voice24
  2211.         dc.l    0        ; channel back-link
  2212.         dc.l    0        ; instrument wave data
  2213.         dc.l    0        ; sample index
  2214.         dc.l    0        ; sample rate
  2215.         dc.l    0        ; instrument loop point
  2216.         dc.l    0        ; instrument data length
  2217.         dc.l    0        ; left volume table
  2218.         dc.l    0        ; right volume table
  2219.         dc.b    0        ; voice flags
  2220.  
  2221.         CNOP    0,4
  2222.  
  2223. Voice24        dc.l    Voice25
  2224.         dc.l    0        ; channel back-link
  2225.         dc.l    0        ; instrument wave data
  2226.         dc.l    0        ; sample index
  2227.         dc.l    0        ; sample rate
  2228.         dc.l    0        ; instrument loop point
  2229.         dc.l    0        ; instrument data length
  2230.         dc.l    0        ; left volume table
  2231.         dc.l    0        ; right volume table
  2232.         dc.b    0        ; voice flags
  2233.  
  2234.         CNOP    0,4
  2235.  
  2236. Voice25        dc.l    Voice26
  2237.         dc.l    0        ; channel back-link
  2238.         dc.l    0        ; instrument wave data
  2239.         dc.l    0        ; sample index
  2240.         dc.l    0        ; sample rate
  2241.         dc.l    0        ; instrument loop point
  2242.         dc.l    0        ; instrument data length
  2243.         dc.l    0        ; left volume table
  2244.         dc.l    0        ; right volume table
  2245.         dc.b    0        ; voice flags
  2246.  
  2247.         CNOP    0,4
  2248.  
  2249. Voice26        dc.l    Voice27
  2250.         dc.l    0        ; channel back-link
  2251.         dc.l    0        ; instrument wave data
  2252.         dc.l    0        ; sample index
  2253.         dc.l    0        ; sample rate
  2254.         dc.l    0        ; instrument loop point
  2255.         dc.l    0        ; instrument data length
  2256.         dc.l    0        ; left volume table
  2257.         dc.l    0        ; right volume table
  2258.         dc.b    0        ; voice flags
  2259.  
  2260.         CNOP    0,4
  2261.  
  2262. Voice27        dc.l    Voice28
  2263.         dc.l    0        ; channel back-link
  2264.         dc.l    0        ; instrument wave data
  2265.         dc.l    0        ; sample index
  2266.         dc.l    0        ; sample rate
  2267.         dc.l    0        ; instrument loop point
  2268.         dc.l    0        ; instrument data length
  2269.         dc.l    0        ; left volume table
  2270.         dc.l    0        ; right volume table
  2271.         dc.b    0        ; voice flags
  2272.  
  2273.         CNOP    0,4
  2274.  
  2275. Voice28        dc.l    Voice29
  2276.         dc.l    0        ; channel back-link
  2277.         dc.l    0        ; instrument wave data
  2278.         dc.l    0        ; sample index
  2279.         dc.l    0        ; sample rate
  2280.         dc.l    0        ; instrument loop point
  2281.         dc.l    0        ; instrument data length
  2282.         dc.l    0        ; left volume table
  2283.         dc.l    0        ; right volume table
  2284.         dc.b    0        ; voice flags
  2285.  
  2286.         CNOP    0,4
  2287.  
  2288. Voice29        dc.l    Voice30
  2289.         dc.l    0        ; channel back-link
  2290.         dc.l    0        ; instrument wave data
  2291.         dc.l    0        ; sample index
  2292.         dc.l    0        ; sample rate
  2293.         dc.l    0        ; instrument loop point
  2294.         dc.l    0        ; instrument data length
  2295.         dc.l    0        ; left volume table
  2296.         dc.l    0        ; right volume table
  2297.         dc.b    0        ; voice flags
  2298.  
  2299.         CNOP    0,4
  2300.  
  2301. Voice30        dc.l    Voice31
  2302.         dc.l    0        ; channel back-link
  2303.         dc.l    0        ; instrument wave data
  2304.         dc.l    0        ; sample index
  2305.         dc.l    0        ; sample rate
  2306.         dc.l    0        ; instrument loop point
  2307.         dc.l    0        ; instrument data length
  2308.         dc.l    0        ; left volume table
  2309.         dc.l    0        ; right volume table
  2310.         dc.b    0        ; voice flags
  2311.  
  2312.         CNOP    0,4
  2313.  
  2314. Voice31        dc.l    0
  2315.         dc.l    0        ; channel back-link
  2316.         dc.l    0        ; instrument wave data
  2317.         dc.l    0        ; sample index
  2318.         dc.l    0        ; sample rate
  2319.         dc.l    0        ; instrument loop point
  2320.         dc.l    0        ; instrument data length
  2321.         dc.l    0        ; left volume table
  2322.         dc.l    0        ; right volume table
  2323.         dc.b    0        ; voice flags
  2324.  
  2325. ;--------------------------------------
  2326.  
  2327.         STRUCTURE InstrumentRec,0
  2328.         APTR    in_Wave
  2329.         ULONG    in_Loop
  2330.         ULONG    in_Length
  2331.         BYTE    in_Flags
  2332.         BYTE    in_Base
  2333.  
  2334.  
  2335.         CNOP    0,4
  2336.  
  2337. Instruments    dcb.l    256,0
  2338.  
  2339.         CNOP    0,4
  2340.  
  2341. QuietInst    dc.l    0
  2342.         dc.l    0
  2343.         dc.l    0
  2344.         dc.b    0
  2345.         dc.b    0
  2346.  
  2347.  
  2348.         CNOP    0,4
  2349.  
  2350. InstrHandle    dc.l    0
  2351. InstrFile    dc.l    InstrName
  2352. InstrPool    dc.l    0
  2353.  
  2354. InstrName    dc.b    'MIDI_Instruments',0
  2355.  
  2356.         CNOP    0,4
  2357.  
  2358. validInstr    dc.b    %11111111    ; (00-07) Piano
  2359.         dc.b    %11111111    ; (08-0F) Chrom Perc
  2360.         dc.b    %11111111    ; (10-17) Organ
  2361.         dc.b    %11111111    ; (18-1F) Guitar
  2362.         dc.b    %11111111    ; (20-27) Bass
  2363.         dc.b    %11111111    ; (28-2F) Strings
  2364.         dc.b    %11111111    ; (30-37) Ensemble
  2365.         dc.b    %11111111    ; (38-3F) Brass
  2366.         dc.b    %11111111    ; (40-47) Reed
  2367.         dc.b    %11111111    ; (48-4F) Pipe
  2368.         dc.b    %11111111    ; (50-57) Synth Lead
  2369.         dc.b    %11111111    ; (58-5F) Synth Pad
  2370.         dc.b    %11111111    ; (60-67) Synth Effects
  2371.         dc.b    %11111111    ; (68-6F) Ethnic
  2372.         dc.b    %11111111    ; (70-77) Percussive
  2373.         dc.b    %11111111    ; (78-7F) SFX
  2374.         dc.b    %00000001    ; (80-87) invalid,Drum
  2375.         dc.b    %11111111    ; (88-8F) Drums/Clap/Hi-Hat
  2376.         dc.b    %11111111    ; (90-97) Hi-Hats/Toms/Cymb1
  2377.         dc.b    %11111111    ; (98-9F) Cymbals/Bells/Slap
  2378.         dc.b    %11111111    ; (A0-A7) Bongos/Congas/Timb
  2379.         dc.b    %11111111    ; (A8-AF) Agogo/Whistles/Gui
  2380.         dc.b    %11111100    ; (B0-B7) Claves/Block/Trian
  2381.         dc.b    %00000000    ; (B8-BF) invalid
  2382.         dc.b    %00000000    ; (C0-C7)
  2383.         dc.b    %00000000    ; (C8-CF)
  2384.         dc.b    %00000000    ; (D0-D7)
  2385.         dc.b    %00000000    ; (D8-DF)
  2386.         dc.b    %00000000    ; (E0-E7)
  2387.         dc.b    %00000000    ; (E8-EF)
  2388.         dc.b    %00000000    ; (F0-F7)
  2389.         dc.b    %00000000    ; (F8-FF)
  2390.  
  2391. ;--------------------------------------------------------------------
  2392.         section    PlayMusChip,data_c
  2393.  
  2394. chipBuffer    dcb.b    1024,0
  2395.  
  2396. ClearBuf    dcb.b    160,0
  2397.  
  2398. ;------------------------------------------------------------------------
  2399.         section    PlayMusBSS,bss
  2400.  
  2401. tempAudio    ds.b    256
  2402.  
  2403. ;------------------------------------------------------------------------
  2404.  
  2405.         end
  2406.