home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Sound / DeliTrackerII / Bonus / PlayAY100.lha / PlayAY / dev / src / ZXAYST11.S < prev    next >
Text File  |  1996-09-12  |  7KB  |  388 lines

  1. ;---------------T
  2.  
  3. DEBUG    equ    0
  4.  
  5.     incdir    include:
  6.     include    exec/types.i
  7.     incdir    deliay:dist/dev/src/include40/
  8.     include    misc/AYPlayer.i
  9.     include    misc/mine.i
  10.     incdir    ''
  11.  
  12.     ifne    DEBUG
  13.  
  14.     lea    song(pc),a0
  15.     bsr.w    initsound
  16.     bsr.w    interrupt
  17.     rts
  18.  
  19. song    dc.b    0,1,2,3
  20.     dc.w    0
  21.     dc.b    0;,0
  22.     incbin    dh2:deliay/tmp/soundtrackersongs.003
  23.     endc
  24.  
  25. * ST11 (SoundTracker 1.1) AY Player, (C) 1995-96 Patrik Rak - Raxoft
  26.  
  27. * 1 Initial version
  28.  
  29.     STRUCTURE    ST11_Song,0
  30.     UBYTE    st11_assignA    ;0-3 specifies, what amiga channel will be
  31.     UBYTE    st11_assignB    ;assigned to each ay channel (A-C, noise)
  32.     UBYTE    st11_assignC
  33.     UBYTE    st11_assignN
  34.     WORD    st11_fadeoffset    ;precise fade specification
  35.     UWORD    st11_fadelen    ;how long to fade (not supported by DT so far)
  36.                 ;set to zero for neverending song
  37.     ;and so on...
  38.  
  39. ; The Player itself.
  40.  
  41. dd
  42.     AYPLAYERHEADER    ST11
  43.     dc.b    12+1        ;custom ayfreq transpose
  44.     ifeq    DEBUG
  45. AYbase    ds.l    1        ;where ay registers should be "outed"
  46.     else
  47. AYbase    dc.l    ay        ;where ay registers should be "outed"
  48.     endc
  49.     ifeq    DEBUG
  50. AYass    ds.l    1        ;where ay channel assignment should be copied
  51.     else
  52. AYass    dc.l    ay
  53.     endc
  54. AYfreq    ds.l    1        ;from where we take AY frequencies
  55.     dc.w    0        ;initplayer
  56.     dc.w    0        ;endplayer
  57.     dc.w    initsound-*
  58.     dc.w    0        ;endsound
  59.     dc.w    interrupt-*
  60.     dc.w    nextpatt-*
  61.     dc.w    prevpatt-*
  62.     dc.b    'SoundTracker (1.1) 1.0',0
  63.     dc.b    '(C) 19?? ?',0
  64.     dc.b    '(C) 1995-96 Patrik Rak - Raxoft',0
  65.     even
  66.  
  67. initsound    moveq    #0,d1            ;clear variables
  68.     lea    vars,a1
  69.     moveq    #(data-vars)/2-1,d0
  70. .fill    move.w    d1,(a1)+
  71.     dbra    d0,.fill
  72.  
  73.     move.l    AYass(pc),a2        ;feed PlayAY
  74.     move.l    (a0)+,(a2)        ;with channel assignement
  75.  
  76.     move.w    (a0)+,d2        ;gate fadeoffset
  77.  
  78.     move.w    (a0)+,songfade-data(a1)    ;store fadelen
  79.  
  80.     move.l    a0,(a1)+    ;data
  81.  
  82.     move.w    #$0101,(a1)+    ;curdelay & curpattlen
  83.  
  84.     addq.l    #4,a1
  85.  
  86.     move.b    #1,(a1)+
  87.     move.b    (patcount,a0),d4
  88.     addq.b    #1,d4
  89.     move.b    d4,(a1)+
  90.  
  91.     moveq    #0,d0
  92.     move.b    (delay,a0),d0            ;delay
  93.     moveq    #0,d3
  94.     move.b    (pattlen,a0),d3
  95.     mulu    d0,d3            ;pattlen in VBIs...
  96.  
  97.     move.w    d3,(a1)+    ;vbipattlen
  98.     move.w    d2,(a1)+    ;fadeofset
  99.  
  100. .count    mulu    d3,d4
  101.     add    d2,d4
  102.     move.w    d4,(a1)        ;songlen
  103.     rts
  104.  
  105.     rts
  106.  
  107.  
  108. nextpatt    lea    currpatcount,a6
  109.     moveq    #1,d0
  110.     cmp.b    (a6),d0
  111.     bne.b    dopatterns
  112.     rts
  113.  
  114. prevpatt    lea    currpatcount,a6
  115.     move.w    (a6),d0
  116.     cmp.b    (a6),d0
  117.     beq.b    return
  118.     addq.b    #2,(a6)
  119.     subq.l    #4,position-currpatcount(a6)
  120. dopatterns    move.w    #$101,curdelay-currpatcount(a6)
  121.     tst.l    songlen-currpatcount(a6)
  122.     beq.b    return
  123.     move.b    (a6),d0
  124.     subq.b    #1,d0
  125.     addq.l    #2,a6
  126.     mulu    (a6)+,d0
  127.     add    (a6)+,d0
  128.     move    d0,(a6)
  129. return    rts
  130.  
  131. interrupt    lea    ay,a6    ;base
  132.     lea    data-ay(a6),a0
  133.     move.l    (a0)+,a5    ;data
  134.     moveq    #0,d6        ;use d6 as obsl1 in original
  135.     subq.b    #1,(a0)
  136.     bne.b    .samenote
  137.     moveq    #-1,d6        ;signal new tones
  138.     move.b    delay-xy(a5),(a0)+
  139.     subq.b    #1,(a0)
  140.     bne.b    .samenote
  141.     move.b    pattlen-xy(a5),(a0)+
  142.     move.l    (a0)+,a1
  143.     subq.b    #1,(a0)+
  144.     bne.b    .notend
  145.     move.b    (a0),-(a0)
  146.     lea    patpointers-xy(a5),a1
  147. .notend    moveq    #0,d0
  148.     move.b    (a1)+,d0
  149.     mulu    #3*192,d0
  150.     lea    (patterns-3*192-xy,a5),a0
  151.     add.l    d0,a0
  152.     move.l    a0,ch1-ay(a6)
  153.     addq.l    #3,a0
  154.     move.l    a0,ch2-ay(a6)
  155.     addq.l    #3,a0
  156.     move.l    a0,ch3-ay(a6)
  157.     move.b    (a1)+,transpose+1-ay(a6)
  158.     move.l    a1,position-ay(a6)
  159. .samenote    lea    ch1-ay(a6),a2
  160.     move.l    a6,a3            ;lea    freqa-ay(a6),a3
  161.     lea    vola-ay(a6),a4
  162.     moveq    #0,d5
  163.     st    strobe-ay(a6)    ;all off
  164. .loop    bsr.b    obsluha
  165.     lea    chlen(a2),a2
  166.     addq.l    #2,a3
  167.     addq.l    #1,a4
  168.     addq.b    #1,d5
  169.     cmp.b    #3,d5
  170.     bne.b    .loop
  171.     move.l    AYbase(pc),a1
  172.     moveq    #11-1,d0
  173. .outy    move.b    (a6)+,(a1)+
  174.     dbra    d0,.outy
  175.     move.b    (a6)+,d0
  176.     beq.b    .done
  177.     move.b    (a6)+,(a1)+
  178.     move.b    (a6),(a1)+
  179.     move.b    d0,(a1)
  180. .done    lea    songlen-volc-1(a4),a0
  181.     moveq    #0,d0
  182.     tst.w    (a0)
  183.     beq.b    .exit
  184.     subq.w    #1,(a0)+
  185.     bne.b    .exit
  186.     move.w    (a0),d0
  187. .exit    rts
  188.  
  189. ;a2 channel, a3 freq, a4 volume, d5 how much rotate strobe
  190. ;a5 data, a6 ay
  191.  
  192. obsluha    tst    d6        ;new tones?
  193.     beq.b    .same
  194.     bsr.w    newtone
  195.     add.l    #3*3,(a2)        ;step to next tone
  196.     bra.b    .cont
  197. .same    bsr.w    sametone
  198. .cont    moveq    #0,d2
  199.     move.b    smp(a2),d2    ;sample number
  200.     beq.w    .envel0
  201.  
  202.     moveq    #0,d3
  203.     move.b    (pos,a2),d3
  204.     subq    #1,d2
  205.     mulu    #130,d2
  206.     move.l    a5,a0        ;lea    (samples,a5),a0
  207.     add    d2,a0
  208.     move.l    a0,d2
  209.     lea    (64,a0),a0
  210.     add    d3,a0
  211.     add    d3,a0
  212.  
  213. .cont2    move.w    (a0),d4
  214.     ror.w    #8,d4
  215.     bclr    #4+8,d4
  216.     bne.b    .noneg
  217.     neg    d4
  218. .noneg    add.w    d4,d4
  219.     add.w    d4,d4
  220.     add.w    d4,d4
  221.  
  222.  
  223.     moveq    #0,d0
  224.     move.b    orn(a2),d0
  225.     lsl    #5,d0
  226.     add    d3,d0
  227.     lea    (ornaments,a5),a0
  228.     add    d0,a0
  229.  
  230.     move.w    transpose-ay(a6),d0
  231.     add.b    (a0),d0
  232.     add.b    tone(a2),d0
  233.     add.w    d0,d0
  234.     move.l    AYfreq(pc),a0
  235.     add.w    d0,a0
  236.     add.w    (a0),d4
  237.     move.w    d4,(a3)        ;freq
  238.  
  239.     move.l    d2,a0
  240.     add    d3,a0
  241.     move.b    (a0),d4
  242.     beq.b    .envel0
  243.     lea    (32,a0),a0
  244.     move.b    (a0),d3
  245.     move.b    d3,d2
  246.     moveq    #-2,d0        ;strobe for tone on
  247.     add.b    d2,d2        ;noise off?
  248.     bcs.b    .nonoise
  249.     moveq    #-10,d0        ;strobe for tone and noise on
  250.     and.b    #31,d3
  251.     move.b    d3,noise-ay(a6)    ;noise
  252. .nonoise    add.b    d2,d2
  253.     bcc.b    .toneon
  254.     addq.b    #1,d0        ;turn the tone off
  255. .toneon    rol.b    d5,d0
  256.     and.b    d0,strobe-ay(a6)
  257.     and.b    #16,(a4)    ;keep just previous env on flag!!!
  258.     or.b    d4,(a4)        ;vol
  259. .envel0    rts
  260.  
  261. octtab    dc.b    9,11,0,2,4,5,7
  262.     even
  263.  
  264. newtone    move.l    (a2),a0
  265.     moveq    #0,d0
  266.     move.b    (a0)+,d0
  267.     move    #$f0,d1
  268.     and    d0,d1
  269.     beq.b    sametone
  270.     cmp    #$f0,d1
  271.     beq.b    silentqm
  272.     lsr    #4,d1
  273.     move.b    (octtab-1,pc,d1),d1
  274.     btst    #3,d0
  275.     beq.b    .nois
  276.     addq    #1,d1
  277. .nois    and    #7,d0
  278.     mulu    #12,d0
  279.     add    d1,d0
  280.     move.b    d0,(tone,a2)
  281.     move.b    (a0)+,d0
  282.     move.b    (a0)+,d2
  283.     
  284.     moveq    #15,d1
  285.     and.b    d0,d1
  286.     lea    smpmem(a2),a0
  287.     lsr.b    #4,d0
  288.     bne.b    .newsmpl
  289.     move.b    (a0),d0
  290. .newsmpl    move.b    d0,(a0)+
  291.     move.b    d0,(a0)+
  292.     clr.b    (a0)+
  293.     move.b    #32,(a0)+
  294.     mulu    #130,d0        ;samply jsou cislovany od 1
  295.     move.w    (-2,a5,d0),(a0)    ;takze tohle skace na zac. dalsiho
  296.  
  297.     moveq    #%01111101,d0
  298.     btst    d1,d0
  299.     bne.b    .exit
  300.     clr.b    orn(a2)
  301.     clr.b    (a4)
  302.     cmp.b    #1,d1
  303.     beq.b    .exit
  304.     cmp.b    #15,d1
  305.     bne.b    .env
  306.     and    d1,d2
  307.     move.b    d2,orn(a2)
  308.     rts
  309.  
  310. .env    move.b    #16,(a4)
  311.     move.b    d1,envtype-ay(a6)
  312.     move.b    d2,envfreq-ay(a6)    ;fill only lower byte
  313. .exit    rts
  314.  
  315. silentqm    clr.b    smpmem(a2)
  316. silent    clr.b    smp(a2)
  317.     clr.b    (a4)
  318.     ;rts
  319.  
  320. sametone    addq.b    #1,pos(a2)
  321.     and.b    #31,pos(a2)
  322.     subq.b    #1,len(a2)
  323.     bne.b    .exit
  324.     move.b    rpos(a2),d0
  325.     beq.b    silent
  326.     subq.b    #1,d0
  327.     move.b    d0,pos(a2)
  328.     move.b    rlen(a2),len(a2)
  329.     addq.b    #1,len(a2)
  330. .exit    rts
  331.  
  332.     section    variables,bss
  333. vars
  334. ay
  335. freqa    ds.w    1
  336. freqb    ds.w    1
  337. freqc    ds.w    1
  338. noise    ds.b    1
  339. strobe    ds.b    1
  340. vola    ds.b    1
  341. volb    ds.b    1
  342. volc    ds.b    1
  343. envtype    ds.b    1        ;note that these two
  344. envfreq    ds.w    1        ;lines are swapped!!!
  345.  
  346.     rsreset
  347. strm    rs.l    1        ;Position in pattern stream
  348. tone    rs.b    1        ;Current tone
  349. orn    rs.b    1        ;Ornament number (tone slides)
  350. smpmem    rs.b    1        ;sample nr (same as smp, but this remains intact)
  351. smp    rs.b    1        ;Current sample nr (freq slides, env & noise)
  352. pos    rs.b    1        ;Position in sample/ornament
  353. len    rs.b    1        ;Sample/orn length remaining to loop test
  354. rpos    rs.b    1        ;If, then where start repeating sample/orn
  355. rlen    rs.b    1        ;What len use when looping
  356. chlen    rs.b    0
  357.  
  358. ch1    ds.b    chlen
  359. ch2    ds.b    chlen
  360. ch3    ds.b    chlen
  361.  
  362. data    ds.l    1        ;song data
  363.  
  364. curdelay    ds.b    1
  365. curpattlen    ds.b    1
  366. position    ds.l    1
  367. currpatcount    ds.b    1
  368. patcountpl1    ds.b    1
  369. vbipattlen    ds.w    1
  370. fadeoffset    ds.w    1
  371. songlen    ds.w    1
  372. songfade    ds.w    1
  373. transpose    ds.w    1
  374. varsend
  375. varslen    equ    *-vars
  376.  
  377.     rsreset
  378. xy    rs.b    0
  379. samples    rs.b    15*(32*2+32+32+1+1)
  380. patpointers    rs.b    256*(1+1)
  381. patcount    rs.b    1
  382. ornaments    rs.b    16*32
  383. unknown    rs.b    32    ;(ornaments off?)
  384. delay    rs.b    1
  385. pattlen    rs.b    1
  386. patterns    rs.b    3*(64*(1+1+1));*x
  387.  
  388.