home *** CD-ROM | disk | FTP | other *** search
/ Merciful 3 / Merciful_Release_3.bin / software / o / octamed / octamedv6.12.lha / programmers / aura.a next >
Text File  |  1995-03-24  |  6KB  |  251 lines

  1.  
  2.         BSS
  3. ;first longword: data read pointer
  4. ;second longword: data end pointer (the last sample WORD to play)
  5. ;third longword: stereo offset pointer (# of bytes to add to get the right channel, 0 = mono)
  6. ;fourth longword: value to add (fixed rate only)
  7. ;fifth longword: remaining add offset (only lower word used)
  8. Auradata    ds.l    5
  9. owntimer    ds.w    1
  10. Aurachmode    ds.w    1
  11. Auraratemode    ds.w    1
  12.         DATA
  13. Auraperlimit    dc.w    248
  14. Aurahandler    dc.l    AuraIntHandler
  15. playing_Aura    dc.w    0
  16.  
  17.         SECTION    "text",CODE
  18.         XDEF    _InitAura,_RemAura,_PlayAura,_StopAura,_SetAuraParams
  19.  
  20. ; _InitAura (void) -- initialize sample playback system
  21. ; returns: 0 = ok, nonzero = error
  22. _InitAura
  23.         tst.w    owntimer
  24.         bne.s    rm_rts
  25.         move.l    a6,-(sp)
  26.         move.w    #$400,$dff09a    ;audio ch #3 interrupt off
  27.         move.l    $70,oldaudiointr    ;MODIFIED CODE... therefore...
  28.         movea.l    4.w,a6
  29.         jsr    -$27C(a6)        ;CacheClearU()
  30.         move.w    #1,owntimer
  31.         moveq    #0,d0
  32.         move.l    (sp)+,a6
  33.         rts
  34.  
  35. ;_RemAura (void) -- deallocate sample playback system resources
  36. _RemAura    tst.w    owntimer
  37.         beq.s    rm_rts
  38.         clr.w    owntimer
  39.         move.w    #$400,$dff09a    ;audio ch #3 interrupt off
  40.         move.l    oldaudiointr,$70
  41. rm_rts        rts
  42.  
  43. AuraSIntHandler    ;single channel playback
  44.         move.l    d0,-(sp)
  45.         move.w    $dff01e,d0
  46.         btst    #$A,d0        ;intr 3?
  47.         beq.w    jmpoldintr
  48.         move.l    a0,-(sp)
  49.         move.w    #$400,$dff09c
  50.         movea.l    Auradata,a0    ;addr...
  51.         move.w    (a0)+,$A20000    ;final...
  52.         move.w    #0,$dff0da
  53.         cmpa.l    Auradata+4,a0
  54.         bhi.s    Auraaudintr_end
  55.         move.l    a0,Auradata
  56.         move.l    (sp)+,a0
  57.         move.l    (sp)+,d0
  58.         rte
  59.  
  60. AuraIntHandler    ; plays through both channels
  61.         move.l    d0,-(sp)
  62.         move.w    $dff01e,d0
  63.         btst    #$A,d0        ;intr 3?
  64.         beq.s    jmpoldintr
  65.         move.l    a0,-(sp)
  66.         move.w    #$400,$dff09c
  67.         movea.l    Auradata,a0    ;addr...
  68.         move.w    (a0)+,$A20000    ;final...
  69.         move.l    Auradata+8,d0
  70.         move.w    -2(a0,d0.l),$A20002    ;stereo offset
  71.         move.w    #0,$dff0da
  72.         cmpa.l    Auradata+4,a0
  73.         bhi.s    Auraaudintr_end
  74.         move.l    a0,Auradata
  75.         move.l    (sp)+,a0
  76.         move.l    (sp)+,d0
  77.         rte
  78.  
  79. jmpoldintr    move.l    (sp)+,d0
  80.         dc.w    $4ef9
  81. oldaudiointr    dc.l    0
  82.  
  83. Auraaudintr_end_f
  84.         move.l    (sp)+,a1
  85. Auraaudintr_end    move.w    #$400,$dff09a
  86.         move.l    (sp)+,a0
  87.         move.l    (sp)+,d0
  88.         clr.b    playing_Aura
  89.         rte
  90.  
  91. AuraFIntHandler    ; plays through both channels, fixed output rate
  92.         move.l    d0,-(sp)
  93.         move.w    $dff01e,d0
  94.         btst    #$A,d0        ;intr 3?
  95.         beq.s    jmpoldintr
  96.         move.l    a0,-(sp)
  97.         move.l    a1,-(sp)
  98.         lea    Auradata,a1
  99.         move.w    #$400,$dff09c
  100.         movea.l    (a1),a0    ;addr...
  101.         move.w    (a0),$A20000    ;final...
  102.         move.l    8(a1),d0
  103.         move.w    0(a0,d0.l),$A20002 ;stereo offset (only mono (= 0) in V5.04 though)
  104.         moveq    #0,d0
  105.         move.w    d0,$dff0da
  106.         move.w    18(a1),d0    ;get remaining offset fraction (always < 1 [0x10000])
  107.         add.l    12(a1),d0    ;add rate value
  108.         swap    d0
  109.         adda.w    d0,a0        ;add to sample pointer
  110.         adda.w    d0,a0        ;twice, because we handle words!
  111.         swap    d0
  112.         move.w    d0,18(a1)    ;store current fraction...
  113.         cmpa.l    4(a1),a0
  114.         bhi.s    Auraaudintr_end_f
  115.         move.l    a0,(a1)
  116.         move.l    (sp)+,a1
  117.         move.l    (sp)+,a0
  118.         move.l    (sp)+,d0
  119.         rte
  120.  
  121. AuraSFIntHandler ; plays through single channel, fixed output rate
  122.         move.l    d0,-(sp)
  123.         move.w    $dff01e,d0
  124.         btst    #$A,d0        ;intr 3?
  125.         beq.w    jmpoldintr
  126.         move.l    a0,-(sp)
  127.         move.l    a1,-(sp)
  128.         lea    Auradata,a1
  129.         move.w    #$400,$dff09c
  130.         movea.l    (a1),a0    ;addr...
  131.         move.w    (a0),$A20000    ;final...
  132.         moveq    #0,d0
  133.         move.w    d0,$dff0da
  134.         move.w    18(a1),d0    ;get remaining offset fraction (always < 1 [0x10000])
  135.         add.l    12(a1),d0    ;add rate value
  136.         swap    d0
  137.         adda.w    d0,a0        ;add to sample pointer
  138.         adda.w    d0,a0        ;twice, because we handle words!
  139.         swap    d0
  140.         move.w    d0,18(a1)    ;store current fraction...
  141.         cmpa.l    4(a1),a0
  142.         bhi.w    Auraaudintr_end_f
  143.         move.l    a0,(a1)
  144.         move.l    (sp)+,a1
  145.         move.l    (sp)+,a0
  146.         move.l    (sp)+,d0
  147.         rte
  148.  
  149. ;_PlayAura -- Play Aura sample, input registers:
  150. ;    A0 = sample (struct Soitin *)
  151. ;    D0 = sample start offset (in WORDs)
  152. ;    D1 = sample period (UWORD)
  153. ;    D2 = sample end offset (i.e. offs to first word NOT to play) (0 = play until end)
  154.  
  155. _PlayAura    tst.w    owntimer
  156.         beq.w    playAura_exit
  157.         addq.l    #6,a0        ;skip header
  158.         add.l    d0,d0        ;words to bytes
  159.         add.l    a0,d0        ;d0 = sample start
  160.         move.l    d0,Auradata
  161.         btst    #5,-1(a0)    ;STEREO?
  162.         bne.s    pmd_stereo
  163.         moveq    #0,d0
  164.         bra.s    pmd_setstereo
  165. pmd_stereo    move.l    a0,d0
  166.         add.l    -6(a0),d0    ;add sample length...
  167. pmd_setstereo    move.l    d0,Auradata+8    ;store stereo offset
  168.         tst.l    d2
  169.         bne.s    pmd_givenend
  170.         move.l    -6(a0),d0    ;get length
  171.         bra.s    pmd_setend
  172. pmd_givenend    move.l    d2,d0
  173.         add.l    d0,d0
  174. pmd_setend    lea    -2(a0,d0.l),a0    ;ptr to last WORD
  175.         move.l    a0,Auradata+4
  176.         moveq    #0,d0
  177.         move.w    Auraperlimit,d0
  178.         tst.w    Auraratemode
  179.         bne.s    pmd_fixedrate
  180.         cmp.w    d0,d1
  181.         bhi.s    playAura_noovf
  182.         move.w    d0,d1
  183. playAura_noovf
  184.         lsr.w    #1,d1
  185.         move.l    Aurahandler,$70
  186.         lea    $dff000,a0
  187.         move.w    #$8400,$9a(a0)    ;INTENA
  188.         move.w    #$0380,$9a(a0)
  189.         move.w    d1,$d6(a0)
  190.         move.w    #0,$d8(a0)
  191.         move.w    #$8400,$9c(a0)    ;INTREQ
  192.         st    playing_Aura
  193. playAura_exit    rts
  194.  
  195. ;    calculations for fixed playback rate...
  196. pmd_fixedrate
  197. ; multiply playback period by 16384...
  198.         swap    d0
  199.         lsr.l    #2,d0
  200. ; divide by note period...
  201.         divu    d1,d0
  202. ; clear upper word and multiply by 4
  203.         swap    d0
  204.         clr.w    d0
  205.         swap    d0
  206.         add.l    d0,d0
  207.         add.l    d0,d0
  208. ; now we have a rate multiplier...
  209.         move.l    d0,Auradata+12
  210.         clr.l    Auradata+16
  211.         move.w    Auraperlimit,d1
  212.         bra.s    playAura_noovf    ;set timer to run at maximum rate
  213.  
  214. ; _StopAura - may only trash A1!
  215. _StopAura    tst.w    owntimer
  216.         beq.s    stopAura_exit
  217.         clr.b    playing_Aura
  218.         move.w    #$400,$dff09a    ;audio 3 INTENA = 0
  219. stopAura_exit    rts
  220.  
  221. SetHandlerAddr    tst.w    Aurachmode
  222.         beq.s    sha_dual
  223.         tst.w    Auraratemode
  224.         beq.s    sha_s_var
  225.         lea    AuraSFIntHandler(pc),a0
  226.         bra.s    sha_set
  227. sha_s_var    lea    AuraSIntHandler(pc),a0
  228.         bra.s    sha_set
  229. sha_dual    tst.w    Auraratemode
  230.         beq.s    sha_d_var
  231.         lea    AuraFIntHandler(pc),a0
  232.         bra.s    sha_set
  233. sha_d_var    lea    AuraIntHandler(pc),a0
  234. sha_set        move.l    a0,Aurahandler
  235.         rts
  236.  
  237. ; SetAuraParams:
  238. ; D0 = flags:
  239. ;    bit 0:    0 = normal stereo/mono mode
  240. ;        1 = use only one channel (no stereo, slightly faster)
  241. ;    bit 1:    0 = use variable output rate
  242. ;        1 = locked output rate at max. period
  243. ; D1 = max. period
  244. _SetAuraParams:
  245.         move.w    d1,Auraratemode
  246.         btst    #0,d0
  247.         sne    Aurachmode+1
  248.         btst    #1,d0
  249.         sne    Auraratemode+1
  250.         rts
  251.