home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / audio / MultiPlayer132sr.lha / soundplay.asm < prev    next >
Assembly Source File  |  1992-09-14  |  8KB  |  274 lines

  1. * MultiPlayer
  2. * Copyright (C) 1992 Bryan Ford
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. *
  18. * I (the author of MultiPlayer) can be contacted on the Internet at
  19. * "bryan.ford@m.cc.utah.edu".  See "Player.doc" for other addresses.
  20. *
  21. * $Id: soundplay.asm,v 4.1 92/06/21 11:15:00 BAF Exp Locker: BAF $
  22. *
  23.  
  24.  
  25.         include "exec/types.i"
  26.         include "exec/interrupts.i"
  27.         include "exec/funcdef.i"
  28.         include "exec/exec_lib.i"
  29.         include "hardware/intbits.i"
  30.         include "hardware/dmabits.i"
  31.         include "hardware/custom.i"
  32.         include "bry/macros.i"
  33.         include "player.i"
  34.  
  35.         xref    _LinkerDB
  36.  
  37.         xref    diecorrupt,diemes,intrepeat
  38.  
  39.         xref    sysbase,modmem,modsize
  40.  
  41.         xdef    soundstart
  42.  
  43.         code    text
  44.  
  45.  STRUCTURE      VHDR,0
  46.         ULONG   OneShotHiSamples
  47.         ULONG   RepeatHiSamples
  48.         ULONG   SamplesPerHiCycle
  49.         UWORD   SamplesPerSec
  50.         UBYTE   NumOctaves
  51.         UBYTE   Compression
  52.         LONG    Volume
  53.  
  54. soundstart
  55.         cmpi.l  #'FORM',(a0)            ; Make sure it's a FORM
  56.         bne     diecorrupt
  57.  
  58.         move.l  #'VHDR',d0              ; Find the header chunk
  59.         bsr     findiff
  60.         bnz     diecorrupt
  61.         move.l  a0,sndhdr(a4)
  62.         tst.b   Compression(a0)
  63.         bne     diecomp
  64.         subq.b  #1,NumOctaves(a0)
  65.         bne     dieinst
  66.  
  67.         move.l  #'BODY',d0              ; Find the body chunk
  68.         bsr     findiff
  69.         bnz     diecorrupt
  70.         move.l  a0,sndbod(a4)
  71.  
  72.         move.l  #'SEQN',d0              ; Find the sequence block, if any
  73.         clr.l   seqptr(a4)
  74.         bsr     findiff
  75.         bnz     19$
  76.         move.l  a0,seqbeg(a4)
  77.         move.l  a0,seqptr(a4)
  78.         add.l   -4(a0),a0
  79.         move.l  a0,seqend(a4)
  80. 19$
  81.         plstartret 9$
  82.  
  83.         cnop    0,4
  84.         dc.l    gmod_Jump
  85. 9$      gmodnop
  86.         gmodbra soundinit               ; StartMusic
  87.         gmodnop
  88.         gmodnop
  89.         gmodnop
  90.         gmodnop
  91.         gmodnop
  92.         gmodnop
  93.         gmodbra soundint                ; Channel0
  94.         gmodnop
  95.         gmodnop
  96.         gmodnop
  97.         gmodnop
  98.         gmodnop
  99.         gmodnop
  100.         gmodnop
  101.         gmodnop
  102.         gmodbra maker                   ; GetMakerName
  103.           move.l    #GMODHF_REPEAT,d0    ; Hook
  104.     rts
  105.  
  106. maker:
  107.         lea     soundname(a4),a0        ; GetMakerName
  108.         tst.l   seqptr(a4)
  109.         beq.s   1$
  110.         lea     soundseqname(a4),a0
  111. 1$      move.l  a0,d0
  112.         rts
  113.  
  114. soundinit:
  115.         movem.l a3/a5/a6,-(sp)
  116.         move.l  #CUSTOM,a3
  117.  
  118.         move.l  #CLOCK,d0               ; Setup the sound
  119.         move.l  sndhdr(a4),a0
  120.         divu.w  SamplesPerSec(a0),d0
  121.         bvs     diecorrupt
  122.         move.w  d0,aud0+ac_per(a3)
  123.         move.w  d0,aud1+ac_per(a3)
  124.         move.w  d0,aud2+ac_per(a3)
  125.         move.w  d0,aud3+ac_per(a3)
  126.         move.w  #64,aud0+ac_vol(a3)
  127.         move.w  #64,aud1+ac_vol(a3)
  128.         move.w  #64,aud2+ac_vol(a3)
  129.         move.w  #64,aud3+ac_vol(a3)
  130.  
  131.         move.l  modmem(a4),a0           ; Prime the pump
  132.         clr.l   (a0)
  133.         move.l  a0,playptr(a4)
  134.         moveq   #4/2,d0
  135.         move.l  d0,playrem(a4)
  136.         move.l  a3,a0
  137.         clr.l   ends(a4)
  138.         bsr     soundint
  139.  
  140.         move.w  #DMAF_SETCLR!DMAF_AUD0!DMAF_AUD1!DMAF_AUD2!DMAF_AUD3,dmacon(a3)
  141.  
  142.         movem.l (sp)+,a3/a5/a6
  143.         rts
  144.  
  145. soundint:
  146.         lea     _LinkerDB,a5
  147.  
  148.         tst.b   end1(a5)
  149.         bz.s    2$
  150.         jsr     intrepeat
  151.         clr.l   ends(a5)
  152. 2$
  153.         move.l  playptr(a5),a1          ; Play the next part of this section
  154.         move.l  playrem(a5),d0
  155.         moveq   #0,d1
  156.         bset    #14,d1
  157.         cmp.l   d0,d1
  158.         ble.s   1$
  159.         move.l  d0,d1
  160. 1$      move.l  a1,aud0+ac_ptr(a0)
  161.         move.l  a1,aud1+ac_ptr(a0)
  162.         move.l  a1,aud2+ac_ptr(a0)
  163.         move.l  a1,aud3+ac_ptr(a0)
  164.         move.w  d1,aud0+ac_len(a0)
  165.         move.w  d1,aud1+ac_len(a0)
  166.         move.w  d1,aud2+ac_len(a0)
  167.         move.w  d1,aud3+ac_len(a0)
  168.         move.b  end2(a5),end1(a5)
  169.         add.l   d1,playptr(a5)
  170.         add.l   d1,playptr(a5)
  171.         sub.l   d1,playrem(a5)
  172.         bne.s   9$
  173.  
  174.         move.b  end3(a5),end2(a5)
  175.  
  176.         move.l  sndbod(a5),a1           ; Ran out of section - get next in sequence
  177.         move.l  seqptr(a5),d0
  178.         bz      8$
  179.  
  180.         move.l  d0,a6                   ; Get ready for the next section
  181.         move.l  (a6)+,d0
  182.         add.l   d0,a1
  183.         sub.l   (a6)+,d0
  184.         neg.l   d0
  185.         lsr.l   #1,d0
  186.         move.l  a1,playptr(a5)
  187.         move.l  d0,playrem(a5)
  188.  
  189.         cmpa.l  seqend(a5),a6           ; Find the next section after that
  190.         blt.s   5$
  191.         move.l  seqbeg(a5),a6
  192.         st      end3(a5)
  193. 5$      move.l  a6,seqptr(a5)
  194.  
  195.         bra.s   9$
  196.  
  197. 8$      move.l  -4(a1),d0               ; Simple sound - just replay the whole thing
  198.         lsr.l   #1,d0
  199.         move.l  a1,playptr(a5)
  200.         move.l  d0,playrem(a5)
  201.         st      end3(a5)
  202.  
  203. 9$      move.w  #INTF_AUD0!INTF_AUD1!INTF_AUD2!INTF_AUD3,intreq(a0)
  204.  
  205.         moveq   #0,d0                   ; Keep going in the server chain
  206.         rts
  207.  
  208.  
  209. *** Find a chunk in an IFF file
  210. * d0 = Chunk type to find
  211. * Returns: a0 = Pointer to start of chunk's data, Z bit set if found
  212. findiff:
  213.         move.l  d2,-(sp)
  214.         move.l  modmem(a4),a0
  215.         moveq   #-12,d1
  216.         sub.l   d1,a0
  217.         add.l   modsize(a4),d1
  218. 1$      cmp.l   (a0),d0
  219.         beq.s   8$
  220.         move.l  4(a0),d2
  221.         btst    #0,d2
  222.         beq.s   5$
  223.         addq.l  #1,d2
  224. 5$      addq.l  #8,d2
  225.         add.l   d2,a0
  226.         sub.l   d2,d1
  227.         bhi.s   1$
  228.         bne     diecorrupt
  229.         moveq   #-1,d0
  230. 9$      movem.l (sp)+,d2/d2
  231.         rts
  232. 8$      addq.l  #8,a0
  233.         b.s     9$
  234.  
  235. *** Various ways to die
  236. diecomp:
  237.         lea     comptext(a4),a0
  238.         bra     diemes
  239.  
  240. dieinst:
  241.         lea     insttext(a4),a0
  242.         bra     diemes
  243.  
  244.         data    __MERGED
  245.  
  246. soundname       dc.b    "IFF 8SVX sound",0
  247. soundseqname    dc.b    "IFF 8SVX sequenced sound",0
  248. comptext        dc.b    "Can't play compressed sounds",0
  249. insttext        dc.b    "Can't play instruments",0
  250.  
  251.         bss     __MERGED
  252.  
  253. playptr         ds.l    1                       ; Pointer in the section we're playing
  254. playrem         ds.l    1                       ; Words remaining in this section
  255.  
  256. seqbeg          ds.l    1                       ; Sequencing stuff
  257. seqend          ds.l    1
  258. seqptr          ds.l    1
  259.  
  260. sndhdr          ds.l    1                       ; Pointer to VHDR chunk
  261. sndbod          ds.l    1                       ; Pointer to BODY chunk
  262.  
  263. *oldint         ds.l    1                       ; Old interrupt pointer
  264. *olddmac        ds.w    1                       ; Old DMACON value
  265. *oldinte        ds.w    1                       ; Old INTENA value
  266.  
  267. ends:
  268. end1            dc.b    0                       ; When this sound finishes
  269. end2            dc.b    0
  270. end3            dc.b    0
  271. end4            dc.b    0
  272.  
  273.         end
  274.