home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 26 / af026.adf / PlayRoutines / replay.s < prev    next >
Text File  |  1991-07-09  |  8KB  |  347 lines

  1. *************************************************
  2. *          testprog for replay-routine
  3. *             jump        =   start
  4. *             breakpoint  =     end
  5. *************************************************
  6. org     $50000
  7. load     $50000
  8. *************************************************
  9.  
  10. START:    bsr    START_MUZAK
  11.  
  12. main:    btst    #6,$bfe001
  13.     bne.s    main
  14.  
  15.     bsr    STOP_MUZAK
  16.     clr.l    d0
  17. END:    rts
  18.  
  19.  
  20. ;©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©
  21. ;©                                              ©
  22. ;©   The Ultimate Soundtracker Replay-Routine   ©
  23. ;©         Version 27  All bugs removed         ©
  24. ;©              Update  29.03.1988              ©
  25. ;©      Written 1987/88 by Karsten Obarski      ©
  26. ;©                                              ©
  27. ;©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©©
  28.  
  29. START_MUZAK:
  30.     move.l    #data,muzakoffset    ;** get offset
  31.  
  32. init0:    move.l    muzakoffset,a0        ;** get highest used pattern
  33.     add.l    #472,a0
  34.     move.l    #128,d0
  35.     clr.l    d1
  36. init1:    move.l    d1,d2
  37.     subq.w    #1,d0
  38. init2:    move.b    (a0)+,d1
  39.     cmp.b    d2,d1
  40.     bgt    init1
  41.     dbra    d0,init2
  42.     addq.b    #1,d2
  43.  
  44. init3:    move.l    muzakoffset,a0        ;** calc samplepointers
  45.     lea.l    pointers,a1
  46.     mulu    #1024,d2
  47.     add.l    #600,d2
  48.     add.l    a0,d2
  49.     move.l    #15-1,d0
  50. init4:    move.l    d2,(a1)+
  51.     clr.l    d1
  52.     move.w    42(a0),d1
  53.     lsl.l    #1,d1
  54.     add.l    d1,d2
  55.     add.l    #30,a0
  56.     dbra    d0,init4
  57.  
  58. init5:    move.w    #$0,$dff0a8        ;** clear used values
  59.     move.w    #$0,$dff0b8
  60.     move.w    #$0,$dff0c8
  61.     move.w    #$0,$dff0d8
  62.     clr.w    timpos
  63.     clr.l    trkpos
  64.     clr.l    patpos
  65.  
  66. init6:    move.l    muzakoffset,a0        ;** initialize timer irq
  67.     move.b    470(a0),numpat+1    ;number of patterns
  68.     move.l    #240,d0
  69.     sub.b    471(a0),d0
  70.     mulu    #122,d0
  71.     move.b    #$0,$bfde00
  72.     move.b    d0,$bfd400
  73.     lsr.w    #8,d0
  74.     move.b    d0,$bfd500
  75.     move.b    #$81,$bfdd00
  76.     move.b    #$11,$bfde00
  77.     move.l    $78,lev6save
  78.     move.l    #lev6interrupt,$78
  79.     rts
  80.  
  81. STOP_MUZAK:
  82.     move.b    #$1,$bfdd00        ;** restore timer & dma
  83.     move.l    lev6save,$78
  84.     move.w    #$0,$dff0a8
  85.     move.w    #$0,$dff0b8
  86.     move.w    #$0,$dff0c8
  87.     move.w    #$0,$dff0d8
  88.     move.w    #$f,$dff096
  89.     rts
  90.  
  91. lev6interrupt:
  92.     movem.l    d0/d1,-(sp)        ;** jump
  93.     bsr    REPLAY_MUZAK
  94.     move.b    $bfdd00,d0
  95.     move.w    #$2000,$dff09c
  96.     movem.l    (sp)+,d0/d1
  97.     rte
  98.  
  99. ;------------------------------------------------
  100. ; replay-routine
  101. ;------------------------------------------------
  102.  
  103. REPLAY_MUZAK:
  104.     movem.l    d0-d7/a0-a6,-(a7)
  105.     addq.w    #1,timpos
  106.     cmp.w    #6,timpos
  107.     beq    replaystep
  108.  
  109. ;------------------------------------------------
  110. ; time left to handle effects between steps
  111. ;------------------------------------------------
  112.  
  113. chaneleffects:                ;** seek effects
  114.     lea.l    datach0,a6
  115.     cmp.b    #0,3(a6)
  116.     beq.s    ceff1
  117.     lea.l    $dff0a0,a5
  118.     bsr.s    ceff5
  119. ceff1:    lea.l    datach1,a6
  120.     cmp.b    #0,3(a6)
  121.     beq.s    ceff2
  122.     lea.l    $dff0b0,a5
  123.     bsr.s    ceff5
  124. ceff2:    lea.l    datach2,a6
  125.     cmp.b    #0,3(a6)
  126.     beq.s    ceff3
  127.     lea.l    $dff0c0,a5
  128.     bsr.s    ceff5
  129. ceff3:    lea.l    datach3,a6
  130.     cmp.b    #0,3(a6)
  131.     beq.s    ceff4
  132.     lea.l    $dff0d0,a5
  133.     bsr.s    ceff5
  134. ceff4:    movem.l    (a7)+,d0-d7/a0-a6
  135.     rts
  136. ceff5:    move.b    2(a6),d0
  137.     and.b    #$0f,d0
  138.     cmp.b    #1,d0
  139.     beq    arpreggiato
  140.     cmp.b    #2,d0
  141.     beq    pitchbend
  142.     rts
  143.  
  144. ;------------------------------------------------
  145. ; effect 1 arpreggiato
  146. ;------------------------------------------------
  147.  
  148. arpreggiato:                ;** spread by time
  149.     cmp.w    #1,timpos
  150.     beq.s    arp1
  151.     cmp.w    #2,timpos
  152.     beq.s    arp2
  153.     cmp.w    #3,timpos
  154.     beq.s    arp3
  155.     cmp.w    #4,timpos
  156.     beq.s    arp1
  157.     cmp.w    #5,timpos
  158.     beq.s    arp2
  159.     rts
  160. arp1:    clr.l    d0            ;** get higher note-values
  161.     move.b    3(a6),d0        ;   or play original
  162.     lsr.b    #4,d0
  163.     bra.s    arp4
  164. arp2:    clr.l    d0
  165.     move.b    3(a6),d0
  166.     and.b    #$0f,d0
  167.     bra.s    arp4
  168. arp3:    move.w    16(a6),d2
  169.     bra.s    arp6
  170. arp4:    lsl.w    #1,d0
  171.     clr.l    d1
  172.     move.w    16(a6),d1
  173.     lea.l    notetable,a0
  174. arp5:    move.w    (a0,d0.w),d2
  175.     cmp.w    (a0),d1
  176.     beq.s    arp6
  177.     addq.l    #2,a0
  178.     bra.s    arp5
  179. arp6:    move.w    d2,6(a5)
  180.     rts
  181.  
  182. ;------------------------------------------------
  183. ; effect 2 pitchbend
  184. ;------------------------------------------------
  185.  
  186. pitchbend:                ;** increase or decrease
  187.     clr.l    d0            ;   period every time
  188.     move.b    3(a6),d0
  189.     lsr.b    #4,d0
  190.     beq.s    pit2
  191.     add.w    d0,(a6)
  192.     move.w    (a6),6(a5)
  193.     rts
  194. pit2:    clr.l    d0
  195.     move.b    3(a6),d0
  196.     and.b    #$0f,d0
  197.     beq.s    pit3
  198.     sub.w    d0,(a6)
  199.     move.w    (a6),6(a5)
  200. pit3:    rts
  201.  
  202. ;------------------------------------------------
  203. ; handle a further step of 16tel data
  204. ;------------------------------------------------
  205.  
  206. replaystep:                ;** work next pattern-step
  207.     clr.w    timpos
  208.     move.l    muzakoffset,a0
  209.     move.l    a0,a3
  210.     add.l    #12,a3            ;ptr to soundprefs
  211.     move.l    a0,a2
  212.     add.l    #472,a2            ;ptr to pattern-table
  213.     add.l    #600,a0            ;ptr to first pattern
  214.     clr.l    d1
  215.     move.l    trkpos,d0        ;get ptr to current pattern
  216.     move.b    (a2,d0),d1
  217.     mulu    #1024,d1
  218.     add.l    patpos,d1        ;get ptr to current step
  219.     clr.w    enbits
  220.     lea.l    $dff0a0,a5        ;chanel 0
  221.     lea.l    datach0,a6
  222.     bsr    chanelhandler
  223.     lea.l    $dff0b0,a5        ;chanel 1
  224.     lea.l    datach1,a6
  225.     bsr    chanelhandler
  226.     lea.l    $dff0c0,a5        ;chanel 2
  227.     lea.l    datach2,a6
  228.     bsr    chanelhandler
  229.     lea.l    $dff0d0,a5        ;chanel 3
  230.     lea.l    datach3,a6
  231.     bsr    chanelhandler
  232.     move.l    #400,d0            ;** wait a while and set len
  233. rep1:    dbra    d0,rep1            ;   of oneshot to 1 word
  234.     move.l    #$8000,d0
  235.     or.w    enbits,d0
  236.     move.w    d0,$dff096
  237.     cmp.w    #1,datach0+14
  238.     bne.s    rep2
  239.     clr.w    datach0+14
  240.     move.w    #1,$dff0a4
  241. rep2:    cmp.w    #1,datach1+14
  242.     bne.s    rep3
  243.     clr.w    datach1+14
  244.     move.w    #1,$dff0b4
  245. rep3:    cmp.w    #1,datach2+14
  246.     bne.s    rep4
  247.     clr.w    datach2+14
  248.     move.w    #1,$dff0c4
  249. rep4:    cmp.w    #1,datach3+14
  250.     bne.s    rep5
  251.     clr.w    datach3+14
  252.     move.w    #1,$dff0d4
  253.  
  254. rep5:    add.l    #16,patpos        ;next step
  255.     cmp.l    #64*16,patpos        ;pattern finished ?
  256.     bne    rep6
  257.     clr.l    patpos
  258.     addq.l    #1,trkpos        ;next pattern in table
  259.     clr.l    d0
  260.     move.w    numpat,d0
  261.     cmp.l    trkpos,d0        ;song finished ?
  262.     bne    rep6
  263.     clr.l    trkpos
  264. rep6:    movem.l    (a7)+,d0-d7/a0-a6
  265.     rts
  266.  
  267. ;------------------------------------------------
  268. ; proof chanel for actions
  269. ;------------------------------------------------
  270.  
  271. chanelhandler:
  272.     move.l    (a0,d1.l),(a6)        ;get period & action-word
  273.     addq.l    #4,d1            ;point to next chanel
  274.     clr.l    d2
  275.     move.b    2(a6),d2        ;get nibble for soundnumber
  276.     lsr.b    #4,d2
  277.     beq    chan2            ;no soundchange !
  278.     move.l    d2,d4            ;** calc ptr to sample
  279.     lsl.l    #2,d2
  280.     mulu    #30,d4
  281.     lea.l    pointers-4,a1
  282.     move.l    0(a1,d2.l),04(a6)    ;store sample-address
  283.     move.w    0(a3,d4.l),08(a6)    ;store sample-len in words
  284.     move.w    2(a3,d4.l),18(a6)    ;store sample-volume
  285.     move.w    2(a3,d4.l),08(a5)    ;change chanel-volume
  286.     clr.l    d3
  287.     move.w    4(a3,d4),d3        ;** calc repeatstart
  288.     add.l    4(a6),d3
  289.     move.l    d3,10(a6)        ;store repeatstart
  290.     move.w    6(a3,d4),14(a6)        ;store repeatlength
  291.     cmp.w    #1,14(a6)
  292.     beq    chan2            ;no sustainsound !
  293.     move.l    10(a6),4(a6)        ;repstart  = sndstart
  294.     move.w    6(a3,d4),8(a6)        ;replength = sndlength
  295. chan2:    cmp.w    #0,(a6)
  296.     beq    chan4            ;no new note set !
  297.     move.w    22(a6),$dff096        ;clear dma
  298.     cmp.w    #0,14(a6)
  299.     bne    chan3            ;no oneshot-sample
  300.     move.w    #1,14(a6)        ;allow resume (later)
  301. chan3:    move.w    (a6),16(a6)        ;save note for effect
  302.     move.l    4(a6),0(a5)        ;set samplestart
  303.     move.w    8(a6),4(a5)        ;set samplelength
  304.     move.w    0(a6),6(a5)        ;set period
  305.     move.w    22(a6),d0
  306.     or.w    d0,enbits        ;store dma-bit
  307.     move.w    18(a6),20(a6)        ;volume trigger
  308. chan4:    rts
  309.  
  310. ;------------------------------------------------
  311. ; used varibles
  312. ;------------------------------------------------
  313. ;    datachx - structure    (22 bytes)
  314. ;
  315. ;    00.w    current note
  316. ;    02.b    sound-number
  317. ;    03.b    effect-number
  318. ;    04.l    soundstart
  319. ;    08.w    soundlenght in words
  320. ;    10.l    repeatstart
  321. ;    14.w    repeatlength
  322. ;    16.w    last saved note
  323. ;    18.w    volume
  324. ;    20.w    volume trigger (note on dynamic)
  325. ;    22.w    dma-bit
  326. ;------------------------------------------------
  327.  
  328. datach0:    dc.w    0,0,0,0,0,0,0,0,0,0,0,1
  329. datach1:    dc.w    0,0,0,0,0,0,0,0,0,0,0,2
  330. datach2:    dc.w    0,0,0,0,0,0,0,0,0,0,0,4
  331. datach3:    dc.w    0,0,0,0,0,0,0,0,0,0,0,8
  332. pointers:    dc.l    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  333. notetable:    dc.w    856,808,762,720,678,640,604,570
  334.         dc.w    538,508,480,453,428,404,381,360
  335.         dc.w    339,320,302,285,269,254,240,226  
  336.         dc.w    214,202,190,180,170,160,151,143
  337.         dc.w    135,127,120,113,000
  338. muzakoffset:    dc.l    0
  339. lev6save:    dc.l    0
  340. trkpos:        dc.l    0
  341. patpos:        dc.l    0
  342. numpat:        dc.w    0
  343. enbits:        dc.w    0
  344. timpos:        dc.w    0
  345. data:        blk.b    0,0
  346.  
  347.