home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Sound / DeliTrackerII / Bonus / PlayAY100.lha / PlayAY / dev / src / ZXAYSTRC.S < prev   
Text File  |  1996-09-12  |  8KB  |  387 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    initsound
  16.     bsr    interrupt
  17.     rts
  18.  
  19. song    dc.b    0,1,2,3
  20.     dc.w    50814
  21.     dc.w    0
  22.     dc.b    0;,0
  23.     incbin    zxt:/archive/megamixcomp.001
  24.     endc
  25.  
  26. * STRC (SoundTracker Raxoft Compiler) AY Player for
  27. * SoundTracker songs compiled by my compiler/compressor
  28.  
  29. * 1 Initial version
  30.  
  31.     STRUCTURE    STRC_Song,0
  32.     UBYTE    strc_assignA    ;0-3 specifies, what amiga channel will be
  33.     UBYTE    strc_assignB    ;assigned to each ay channel (A-C, noise)
  34.     UBYTE    strc_assignC
  35.     UBYTE    strc_assignN
  36.     UWORD    strc_getabs    ;start of data in ZX ram
  37.     WORD    strc_fadeoffset    ;precise fade specification
  38.     UWORD    strc_fadelen    ;how long to fade (not supported by DT so far)
  39.                 ;set to zero for neverending song
  40.     ;and so on...
  41.  
  42. ; The Player itself.
  43.  
  44. dd
  45.     AYPLAYERHEADER    STRC
  46.     dc.b    12+1        ;custom ayfreq transpose
  47.     ifeq    DEBUG
  48. AYbase    ds.l    1        ;where ay registers should be "outed"
  49.     else
  50. AYbase    dc.l    ay        ;where ay registers should be "outed"
  51.     endc
  52.     ifeq    DEBUG
  53. AYass    ds.l    1        ;where ay channel assignment should be copied
  54.     else
  55. AYass    dc.l    ay
  56.     endc
  57. AYfreq    ds.l    1        ;from where we take AY frequencies
  58.     dc.w    0        ;initplayer
  59.     dc.w    0        ;endplayer
  60.     dc.w    initsound-*
  61.     dc.w    0        ;endsound
  62.     dc.w    interrupt-*
  63.     dc.w    nextpatt-*
  64.     dc.w    prevpatt-*
  65.     dc.b    'SoundTracker (1.1) (Raxoft Compiler) 1.2',0
  66.     dc.b    '(C) 1990 Patrik Rak - Raxoft',0
  67.     dc.b    '(C) 1994-96 Patrik Rak - Raxoft',0
  68.     even
  69.  
  70. initsound    moveq    #0,d1            ;clear variables
  71.     lea    vars,a1
  72.     moveq    #(data-vars)/2-1,d0
  73. .fill    move.w    d1,(a1)+
  74.     dbra    d0,.fill
  75.  
  76.     move.l    AYass(pc),a2        ;feed PlayAY
  77.     move.l    (a0)+,(a2)        ;with channel assignement
  78.  
  79.     move.w    (a0)+,d1        ;get getabs (upper word is zero)!!
  80.  
  81.     move.w    (a0)+,d2        ;gate fadeoffset
  82.  
  83.     move.w    (a0)+,songfade-data(a1)    ;store fadelen
  84.  
  85.     moveq    #0,d0
  86.     move.b    (a0),d0            ;delay
  87.     move.w    (a0),d3
  88.     and.w    #$ff,d3
  89.     mulu    d0,d3            ;pattlen in VBIs...
  90.  
  91.     moveq    #envtab,d0
  92.     add.l    a0,d0
  93.     move.l    d0,(a1)+    ;data
  94.     sub.l    d1,a0
  95.     move.l    a0,(a1)+    ;getabsset
  96.     move.w    #$0101,(a1)+    ;curdelay & curpattlen
  97.     moveq    #posbeg-envtab,d1
  98.     add.l    d1,d0
  99.     move.l    d0,(a1)+        ;position
  100.  
  101.     move.w    d3,(a1)+    ;vbipattlen
  102.     move.w    d2,(a1)+    ;fadeofset
  103.  
  104.     move.l    d0,a0
  105. .count    add.w    d3,d2
  106.     addq.l    #7,a0
  107.     tst.b    1(a0)
  108.     bne.b    .count
  109.     move.w    d2,(a1)        ;songlen
  110.     rts
  111.  
  112. nextpatt    lea    position,a1
  113.     move.l    (a1),a0
  114.     tst.b    1(a0)
  115.     bne.b    patterns        ;no next pattern
  116.     rts
  117.  
  118. prevpatt    lea    position,a1
  119.     move.l    (a1),a0
  120.     subq.l    #7,a0
  121.     subq.l    #7,a0
  122.     moveq    #posbeg-xy,d0
  123.     add.l    data-position(a1),d0
  124.     cmp.l    d0,a0
  125.     bcc.b    patterns
  126.     move.l    d0,a0
  127. patterns    move.w    #$101,-2(a1)
  128.     move.l    a0,(a1)+
  129.     move.w    (a1)+,d3
  130.     move.w    (a1)+,d2
  131.     tst.w    (a1)
  132.     bne.b    initsound\.count
  133.     rts
  134.  
  135. interrupt    lea    ay,a6    ;base
  136.     lea    data-ay(a6),a0
  137.     move.l    (a0)+,a5    ;data
  138.     move.l    (a0)+,d7    ;getabsset
  139.     moveq    #0,d6        ;use d6 as obsl1 in original
  140.     subq.b    #1,(a0)
  141.     bne.b    .samenote
  142.     moveq    #-1,d6        ;signal new tones
  143.     move.b    delay-xy(a5),(a0)+
  144.     subq.b    #1,(a0)
  145.     bne.b    .samenote
  146.     move.b    pattlen-xy(a5),(a0)+
  147.     move.l    (a0),a0
  148.     tst.b    1(a0)
  149.     bne.b    .notend
  150.     lea    posbeg-xy(a5),a0
  151. .notend    bsr.b    getabs
  152.     move.l    d0,ch1-ay(a6)
  153.     bsr.b    getabs
  154.     move.l    d0,ch2-ay(a6)
  155.     bsr.b    getabs
  156.     move.l    d0,ch3-ay(a6)
  157.     move.b    (a0)+,transpose+1-ay(a6)
  158.     move.l    a0,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.  
  190. getabs    moveq    #0,d0        
  191.     move.b    (a0)+,d1
  192.     move.b    (a0)+,d0
  193.     lsl.w    #8,d0
  194.     move.b    d1,d0
  195.     add.l    d7,d0
  196.     rts
  197.  
  198. gettab    move.l    d2,d0    ;because tables are even
  199. gettab2    move.w    (a0,d0.w),d0
  200.     ror    #8,d0
  201.     add.l    d7,d0
  202.     move.l    d0,a0
  203.     add    d3,a0
  204.     rts
  205.  
  206. ;a2 channel, a3 freq, a4 volume, d5 how much rotate strobe
  207.  
  208. obsluha    tst    d6        ;new tones?
  209.     beq.b    .same
  210.     bsr.w    newtone
  211.     bra.b    .cont
  212. .same    bsr.w    sametone
  213. .cont    moveq    #0,d2
  214.     move.b    smp(a2),d2    ;sample number
  215.     add.w    d2,d2
  216.     lea    tonetab-xy(a5,d2),a0
  217.     bsr.b    getabs
  218.     move.l    d0,a0
  219.     moveq    #0,d3
  220.     move.b    pos(a2),d3
  221.     add    d3,a0
  222.     add    d3,a0
  223.     move.b    (a0)+,d1
  224.     move.b    (a0),d4
  225.     lsl.w    #8,d4
  226.     move.b    d1,d4
  227.  
  228.     add.w    d4,d4    ;can be negative...
  229.     add.w    d4,d4
  230.     add.w    d4,d4
  231.  
  232.     moveq    #0,d0
  233.     move.b    orn(a2),d0
  234.     add.w    d0,d0
  235.     lea    orntab-xy(a5),a0
  236.     bsr.b    gettab2
  237.     move.w    transpose-ay(a6),d0
  238.     add.b    (a0),d0
  239.     add.b    tone(a2),d0
  240.     add.w    d0,d0
  241.     move.l    AYfreq(pc),a0
  242.     add.w    d0,a0
  243.     add.w    (a0),d4
  244.     move.w    d4,(a3)        ;freq
  245.  
  246.     move.l    a5,a0        ;lea envtab-xy(a5),a0
  247.     bsr.b    gettab
  248.     move.b    (a0),d4
  249.     beq.b    .envel0
  250.     lea    noistab-xy(a5),a0
  251.     bsr.b    gettab
  252.     move.b    (a0),d3
  253.     move.b    d3,d2
  254.     moveq    #-2,d0        ;strobe for tone on
  255.     add.b    d2,d2        ;noise off?
  256.     bcs.b    .nonoise
  257.     moveq    #-10,d0        ;strobe for tone and noise on
  258.     and.b    #31,d3
  259.     move.b    d3,noise-ay(a6)    ;noise
  260. .nonoise    add.b    d2,d2
  261.     bcc.b    .toneon
  262.     addq.b    #1,d0        ;turn the tone off
  263. .toneon    rol.b    d5,d0
  264.     and.b    d0,strobe-ay(a6)
  265.     and.b    #16,(a4)    ;keep just previous env on flag!!!
  266.     or.b    d4,(a4)        ;vol
  267. .envel0    rts
  268.  
  269. newtone    move.l    (a2),a0
  270.     moveq    #0,d0
  271.     move.b    (a0)+,d0
  272.     bmi.b    silentqm
  273.     move.b    d0,tone(a2)
  274.     move.b    (a0)+,d0
  275.     move.b    (a0)+,d2
  276.     move.l    a0,(a2)
  277.     
  278.     moveq    #15,d1
  279.     and.b    d0,d1
  280.     lea    smpmem(a2),a0
  281.     lsr.b    #4,d0
  282.     bne.b    .newsmpl
  283.     move.b    (a0),d0
  284. .newsmpl    move.b    d0,(a0)+
  285.     move.b    d0,(a0)+
  286.     clr.b    (a0)+            ;pos
  287.     move.b    #32,(a0)+
  288.     add    d0,d0
  289.     lea    smpltab-xy(a5,d0.w),a1
  290.     move.w    (a1),(a0)        ;even table
  291.  
  292.     moveq    #%01111101,d0
  293.     btst    d1,d0
  294.     bne.b    .exit
  295.     clr.b    orn(a2)
  296.     clr.b    (a4)
  297.     cmp.b    #1,d1
  298.     beq.b    .exit
  299.     cmp.b    #15,d1
  300.     bne.b    .env
  301.     and    d1,d2
  302.     move.b    d2,orn(a2)
  303.     rts
  304. .env    move.b    #16,(a4)
  305.     move.b    d1,envtype-ay(a6)
  306.     move.b    d2,envfreq-ay(a6)    ;fill only lower byte
  307. .exit    rts
  308.  
  309. silentqm    move.l    a0,(a2)
  310.     addq.b    #1,d0
  311.     bne.b    sametone
  312.     clr.b    smpmem(a2)
  313. silent    clr.b    smp(a2)
  314.     clr.b    (a4)
  315.     ;rts    ;to behave exactly as original I omit this logical rts
  316.  
  317. sametone    addq.b    #1,pos(a2)
  318.     and.b    #31,pos(a2)
  319.     subq.b    #1,len(a2)
  320.     bne.b    .exit
  321.     move.b    rpos(a2),d0
  322.     beq.b    silent
  323.     subq.b    #1,d0
  324.     move.b    d0,pos(a2)
  325.     move.b    rlen(a2),len(a2)
  326. .exit    rts
  327.  
  328.     section    variables,bss
  329. vars
  330. ay
  331. freqa    ds.w    1
  332. freqb    ds.w    1
  333. freqc    ds.w    1
  334. noise    ds.b    1
  335. strobe    ds.b    1
  336. vola    ds.b    1
  337. volb    ds.b    1
  338. volc    ds.b    1
  339. envtype    ds.b    1        ;note that these two
  340. envfreq    ds.w    1        ;lines are swapped!!!
  341.  
  342.     rsreset
  343. strm    rs.l    1        ;Position in pattern stream
  344. tone    rs.b    1        ;Current tone
  345. orn    rs.b    1        ;Ornament number (tone slides)
  346. smpmem    rs.b    1        ;sample nr (same as smp, but this remains intact)
  347. smp    rs.b    1        ;Current sample nr (freq slides, env & noise)
  348. pos    rs.b    1        ;Position in sample/ornament
  349. len    rs.b    1        ;Sample/orn length remaining to loop test
  350. rpos    rs.b    1        ;If, then where start repeating sample/orn
  351. rlen    rs.b    1        ;What len use when looping
  352. ;following three are maintained directly in this conversion
  353. ;ctrl    rs.b    1        ;Partial tone noise strobe
  354. ;freq    rs.w    1        ;Freq calculated for this channel
  355. ;vol    rs.b    1        ;Volume for this channel
  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. getabsset    ds.l    1        ;ZX Ram base
  364.  
  365. curdelay    ds.b    1
  366. curpattlen    ds.b    1
  367. position    ds.l    1
  368. vbipattlen    ds.w    1
  369. fadeoffset    ds.w    1
  370. songlen    ds.w    1
  371. songfade    ds.w    1
  372. transpose    ds.w    1
  373. varsend
  374. varslen    equ    *-vars
  375.  
  376.     rsreset
  377. delay    rs.b    1    ;how long each note sounds (VBIs)
  378. pattlen    rs.b    1    ;how many notes in each pattern
  379. tonetab    rs.w    16    ;ptrs to seq of freq slides
  380. orntab    rs.w    16    ;ptrs to seq of tone slides
  381. xy    rs.b    0
  382. envtab    rs.w    16    ;ptrs to seq of volume values
  383. noistab    rs.w    16    ;ptrs to seq of noise values + tone&noise mask
  384. smpltab    rs.w    16    ;table of rpos and rlen s
  385. posbeg    rs.b    0
  386.  
  387.