home *** CD-ROM | disk | FTP | other *** search
/ Falcon 030 Power 2 / F030_POWER2.iso / ST_STE / MAGS / ICTARI04.ARJ / ictari.04 / C / SOURCE.SEQ / BASIC / STOSSSSS.S < prev   
Text File  |  1997-09-17  |  8KB  |  345 lines

  1. ***********************************************************************
  2. *                                                                     *
  3. *              STE BASIC MC SOURCE FOR Sample Music                   *
  4. *                                                                     *
  5. *                   by © Ian Hancock, September 1992                  *
  6. *                                                                     *
  7. ***********************************************************************
  8.  
  9. * system equates
  10.  
  11. gemdos        equ    $01
  12. print_line    equ    $09
  13. super        equ    $20
  14. gettime        equ    $2C
  15. vbl_queue        equ    $456
  16.  
  17. snd_cntl_DMA        equ    $FF8901
  18. snd_start_hi_DMA    equ    $FF8903
  19. snd_start_mid_DMA    equ    $FF8905
  20. snd_start_lo_DMA    equ    $FF8907
  21. snd_end_hi_DMA        equ    $FF890F
  22. snd_end_mid_DMA    equ    $FF8911
  23. snd_end_lo_DMA        equ    $FF8913
  24. snd_mode_DMA        equ    $FF8921
  25.  
  26. *variable equates
  27.  
  28. sam_start        equ    0
  29. items        equ    4
  30. sequence2        equ    8
  31. vbl_current    equ    12
  32. time            equ    16
  33. memo            equ    20
  34. seqperm        equ    24
  35.  
  36. sample_length    equ    0
  37. sample_end    equ    4
  38. sample_start    equ    8
  39. playmode        equ    12
  40. type            equ    16
  41. frequency        equ    20
  42. stereo_mono    equ    24
  43.  
  44.  
  45. * main program
  46. *************************************************************************
  47. sequence        ds.l    $01    *current address in seq. either play or record
  48. finish        ds.l    $01  *holds address of finish variable
  49. *finish conts 1=norm,2=loop,0=stop
  50. keeploop        ds.l    $01    *holds address of loop variable counts down
  51. mix            ds.l    $01    *current mix address
  52. samples_list    ds.l    $18    *sample start addresses
  53.     even
  54.  
  55. start
  56.     movem.l    d0-d2/a0-a3,-(sp)
  57. * set up play params
  58.     lea        program(pc),a3
  59.  
  60.     move.l    sequence(pc),a0
  61.     clr.w    d0
  62.     move.b    19(a0),d0        *no. of items (-1)
  63.     move.l    a0,a1
  64.     add.l    #96,a0        *point to first sam
  65.     add.l    #24,a1        *point tosam length list
  66.     lea        samples_list(pc),a2
  67.     move.l    a2,sam_start(a3)
  68.     
  69. sam_filler
  70.     move.l    (a1)+,d1        *next length inc.
  71.     move.l    a0,(a2)+        
  72.     add.l    d1,a0
  73.     dbf.w    d0,sam_filler
  74.         
  75.     move.l    mix(pc),d0
  76.     cmpi.l    #0,d0
  77.     beq        useall
  78.  
  79.     add.l    #24,d0
  80.     move.l    d0,a0
  81.  
  82. useall
  83.     move.l    a0,sequence2(a3)    *sequence start address    
  84.     move.l    a0,seqperm(a3)
  85.     
  86.     move.w    (a0),d0            *get first elapse time in d0
  87.     move.w    d0,memo(a3)        *put first elapse time in memo
  88.     subq.w    #1,d0            *put actual timer 1 count behind elapse
  89.     move.w    d0,time(a3)        *store in timer
  90.     
  91. * go (install the interupt)
  92.     move.l    #1,-(sp)            *pass 1 via stack to install
  93.     jsr        Vbl_Install(pc)    *EDIT vbl II
  94.     addq.l    #4,sp            *stack correction
  95. * it auto de-stalls
  96.     movem.l    (sp)+,d0-d2/a0-a3
  97.     rts
  98.  
  99. *************************************************************************
  100. STOP
  101. *Remove current vbl
  102.     move.l    a3,-(sp)
  103.     lea        program(pc),a3
  104.  
  105. * enter super
  106. *    clr.l    -(SP)
  107. *    move.w    #super,-(SP)
  108. *    trap        #gemdos
  109. *    addq.l    #$06,SP
  110. *    move.l    D0,-(SP)
  111.  
  112.     move.l    vbl_current(a3),a1    *removes last vbl installed
  113.     move.l    #0,(a1)            *by my prog. puts 0 in list
  114.  
  115. * set DMA sound, stop
  116.     move.b    #0,snd_cntl_DMA
  117.  
  118. * exit supervisor mode
  119. *    move.w    #super,-(SP)
  120. *    trap        #gemdos
  121. *    addq.w    #$06,SP
  122.  
  123.     move.l    (sp)+,a3
  124.     rts
  125. *************************************************************************
  126.  
  127. *Install V_blank counter for RECORD
  128.  
  129. Vbl_Install
  130.     movem.l    d2/a3,-(sp)        *store d2
  131.     lea        program(pc),a3
  132.  
  133. * enter super
  134. *    clr.l    -(SP)
  135. *    move.w    #super,-(SP)
  136. *    trap        #gemdos
  137. *    addq.l    #$06,SP
  138. *    move.l    D0,-(SP)
  139.  
  140. * find a space in queue
  141.     move.l    vbl_queue,a0
  142.     move.w    #7,d0
  143.     
  144. find_entry
  145.     tst.l    (a0)+
  146.     beq.s    entry_found
  147.     dbra        d0,find_entry
  148.     bra.s    quit
  149.     
  150. entry_found
  151.     lea        vbl_EDIT(pc),a1
  152.     move.l    a1,-(a0)            *put address from a1 in list
  153.     move.l    a0,vbl_current(a3)    *remember position in list
  154.  
  155. quit    
  156. * exit supervisor mode
  157. *    move.w    #super,-(SP)
  158. *    trap        #gemdos
  159. *    addq.w    #$06,SP
  160.  
  161.     movem.l    (sp)+,d2/a3    *restore d2
  162.     rts
  163. *************************************************************************
  164. * vbl routine II for edit and playback
  165. vbl_EDIT
  166.     movem.l    a3/a4,-(sp)
  167.     lea        program(pc),a3
  168.     lea        samplepback(pc),a4
  169.  
  170.     move.w    time(a3),d0    *put time in d0
  171.     addq.w    #1,d0        *add 1
  172.     move.w    d0,time(a3)    *replace new time
  173.     move.w    memo(a3),d1
  174.     cmp.w    d0,d1        *if elapse time is reached
  175.     bls        next_samp    *get next sample
  176.     movem.l    (sp)+,a3/a4
  177.     rts
  178.     
  179. next_samp
  180.     move.l    sequence2(a3),a0    *get current seq. addr.
  181.     add.l    #4,a0            *increment by a long word
  182.     move.l    a0,sequence2(a3)    *replace new position
  183.     move.w    (a0),memo(a3)        *set new elapse time
  184.     move.w    2(a0),d0            *put sample no in d0
  185.  
  186. *get_samp
  187.     move.l    sam_start(a3),a0        *get address of list
  188.     and.l    #$ffff,d0            *mask high word
  189.     lsl.l    #2,d0            * x4 for offset
  190.     add.l    d0,a0            *add offset to get address from list
  191.     lsr.l    #2,d0            * /2 return to original value
  192.     move.l    (a0),a0            *put samp. start address in a0
  193.  
  194. * get length
  195.     move.l    26(a0),sample_length(a4)    *offsets from a0 for AVR header
  196.     
  197. * get stereo or mono (0=mono and ffff= stereo. in playback s=0 and m=1)
  198.     move.w    12(a0),d2
  199.     move.b    #1,stereo_mono(a4)
  200.     cmpi.w    #0,d2
  201.     beq        mono
  202.     move.b    #0,stereo_mono(a4)
  203. mono    
  204.  
  205. * get unsigned or signed (un=0 and sn=ffff. in play un=1 and sn=0)
  206.     move.w    16(a0),d2
  207.     move.b    #1,type(a4)
  208.     cmpi.w    #0,d2
  209.     beq        unsigned
  210.     move.b    #0,type(a4)
  211. unsigned
  212.  
  213. * get loopy. (0=no and ffff=yes. in play 1=no and 3=yes)
  214.     move.w    18(a0),d2
  215.     move.b    #1,playmode(a4)
  216.     cmpi.w    #0,d2
  217.     beq        noloop
  218.     move.b    #3,playmode(a4)
  219. noloop
  220.  
  221. * get frequency (25600= 25.6khz in play = 2)
  222.     move.l    22(a0),d2
  223.     move.b    #3,frequency(a4)
  224.     cmp.w    #$c800,d2
  225.     beq        got_it
  226.     move.b    #2,frequency(a4)
  227.     cmp.w    #$6400,d2
  228.     beq        got_it
  229.     move.b    #1,frequency(a4)
  230.     cmp.w    #$30fa,d2
  231.     beq        got_it
  232.     move.b    #0,frequency(a4)
  233. got_it
  234.  
  235.     add.l    #128,a0        *set a0 past AVR header (raw sample follows)
  236.     move.l    a0,sample_start(a4)    * set start address
  237.     
  238. *play sample
  239. * do it
  240.     move.l    sample_start(a4),D0
  241.     add.l    sample_length(a4),D0
  242.     move.l    D0,sample_end(a4)
  243.  
  244. * write to sound DMA hardware
  245.     clr.b    snd_cntl_DMA
  246.  
  247. * set  sampling freq and stereo/mono
  248.     move.b    stereo_mono(a4),d0
  249.     lsl.b    #$7,d0
  250.     or.b        frequency(a4),d0
  251.     move.b    d0,snd_mode_DMA
  252.  
  253. * set start sample location
  254.     move.l    sample_start(a4),D0
  255.     move.b    D0,snd_start_lo_DMA
  256.     lsr.l    #$08,D0
  257.     move.b    D0,snd_start_mid_DMA
  258.     lsr.l    #$08,D0
  259.     move.b    D0,snd_start_hi_DMA
  260.  
  261. * set end sample location
  262.     move.l    sample_end(a4),D0
  263.     move.b    D0,snd_end_lo_DMA
  264.     lsr.l    #$08,D0
  265.     move.b    D0,snd_end_mid_DMA
  266.     lsr.l    #$08,D0
  267.     move.b    D0,snd_end_hi_DMA
  268.  
  269. * start DMA sound, repeating at end
  270.     move.b    playmode(a4),snd_cntl_DMA
  271.  
  272. *rts
  273.     move.l    finish(pc),a0        *play finished
  274.     add.l    #1,(a0)
  275.  
  276.     cmpi.w    #$ffff,memo(a3)    *if = ffff
  277.     beq        finishedit        *then seq finished
  278.     movem.l    (sp)+,a3/a4
  279.     rts
  280.  
  281. finishedit
  282.     move.l    keeploop(pc),a0    *looping variable address
  283.     move.l    (a0),d0            *0 if not looping
  284.     subq.l    #1,d0            *decrem loop no
  285.  
  286.     cmpi.l    #0,d0            *if not 0 then loop
  287.     beq        stopped
  288.     cmpi.l    #$ffffffff,d0        *if was 0 now 1 then forever
  289.     bne        notforever
  290.     
  291.     addq.l    #1,d0            *sorted. make forever 0 again
  292.  
  293. notforever
  294.     move.l    d0,(a0)            *store new count down
  295.  
  296.     move.l    seqperm(a3),a0
  297.     move.l    a0,sequence2(a3)    *reset seq start position    
  298.  
  299.     move.w    (a0),d0            *get first elapse time in d0
  300.     move.w    d0,memo(a3)        *put first elapse time in memo
  301.     subq.w    #1,d0            *put actual timer 1 count behind elapse
  302.     move.w    d0,time(a3)        *store in timer
  303.  
  304.     move.l    finish(pc),a0        *play finished flag reset
  305.     move.l    #1,(a0)
  306.  
  307.     movem.l    (sp)+,a3/a4
  308.     rts    
  309.  
  310. stopped
  311.     move.l    vbl_current(a3),a1    * vbl EDIT list pos. to a1
  312.     move.l    #0,(a1)            *de-install by putting 0 in list
  313.  
  314.     cmp.b    #3,snd_cntl_DMA
  315.     bne        not_loopy
  316.     
  317.     move.b    #0,snd_cntl_DMA
  318.     
  319. not_loopy
  320.     move.l    finish(pc),a0        *play finished
  321.     move.l    #0,(a0)
  322.     movem.l    (sp)+,a3/a4
  323.     rts    
  324. *************************************************************************
  325. * program variables
  326.  
  327. program        ds.l    $01    *address of (list containing sample st. address')
  328.     ds.l    $01    *number of samples stored (-1) ie. 0= 1 sample
  329.     ds.l    $01    *current address in seq. either play or record
  330.     ds.l    $01    *address in vbl queue of last addition to the list
  331.     ds.l    $01    *counter used by interupts
  332.     ds.l    $01    *next time elapse memory.
  333.     ds.l    $01    *seqperm holder
  334.     
  335. * variables for sample playback
  336. samplepback    ds.l    $01    *obvious
  337.     ds.l    $01    * "
  338.     ds.l    $01    * "
  339.     ds.l    $01    *0=off,1=once,3=looped
  340.     ds.l    $01    *0=signed,1=unsigned
  341.     ds.l    $01    *0=6khz,1=12khz,2=25khz,3=51khz
  342.     ds.l    $01    *1/0 for mono or stereo
  343.  
  344.     end    
  345.