home *** CD-ROM | disk | FTP | other *** search
/ YPA: Your Privacy Assured / YPA.ISO / other_goodies / music / ep154b_1.dms / ep154b_1.adf / EagleplayerDeveloper / Examples / SoundtrackerV2.6.s < prev    next >
Text File  |  1995-01-17  |  18KB  |  898 lines

  1. *********************************************************************
  2. *           Soundtracker V2.6 Playroutine (C) Mnemotron             *
  3. *            to use within Delitracker and Eagleplayer              *
  4. *                    Adaption by Buggs                              *
  5. *********************************************************************
  6.     ;
  7.     incdir    "Include:"
  8.     include "misc/EaglePlayer.i"
  9.  
  10.     SECTION    0,Code
  11.  
  12.     PLAYERHEADER    Tags
  13.  
  14.     dc.b '$VER: SoundTracker V2.6 Eagleplayer V1.0 (Mar/12/93)',0
  15.     even
  16. Tags
  17.     dc.l    DTP_RequestDTVersion,$ffff
  18.     dc.l    EP_PlayerVersion,4
  19.     dc.l    DTP_Volume,SetVoices
  20.     dc.l    DTP_Balance,SetVoices
  21.     dc.l    EP_Voices,SetVoices
  22.  
  23.     dc.l    DTP_PlayerVersion,1
  24.     dc.l    DTP_PlayerName,_MT_Name
  25.     dc.l    DTP_Creator,MT_CName
  26.     dc.l    DTP_Check2,_MT_Check
  27.     dc.l    DTP_Interrupt,MT_Music2
  28.     dc.l    DTP_InitPlayer,InitPlay
  29.     dc.l    DTP_EndPlayer,EndPlay
  30.     dc.l    DTP_InitSound,MT_Init
  31.     dc.l    DTP_EndSound,RemSnd
  32.  
  33.     dc.l    DTP_NextPatt,_MT_NextPattern
  34.     dc.l    DTP_PrevPatt,_MT_BackPattern
  35.  
  36.     dc.l    EP_GetPositionNr,_MT_GetPosNr
  37.  
  38.     dc.l    EP_Get_ModuleInfo,GetInfos
  39.  
  40.     dc.l    EP_StructInit,StructInit
  41.  
  42.     dc.l    EP_flags,EPB_Volvoices!EPB_Packable!EPB_Save!EPB_restart!EPB_songend!EPB_Volume!EPB_Balance!EPB_Voices!EPB_Analyzer!EPB_Moduleinfo!EPB_Prevpatt!EPB_Nextpatt
  43.     dc.l    0
  44. mt_len:        dc.l    0
  45. DTbase        dc.l    0
  46.  
  47. MT_Structadr    ds.l    ups_sizeof
  48.  
  49. MT_VolVoice1    dc.w    1
  50. MT_VolVoice2    dc.w    1
  51. MT_VolVoice3    dc.w    1
  52. MT_VolVoice4    dc.w    1
  53.  
  54. ;========================================================================
  55. _MT_Name:
  56.     dc.b    "Soundtracker 2.6",0
  57. MT_CName:
  58.     dc.b    "Mnemotron,",10
  59.     dc.b    "adapted by Buggs of DEFECT",0
  60.     even
  61. ;========================================================================
  62. _MT_InfoBuffer:
  63.     dc.l    MI_Samples,0            ;4
  64.     dc.l    MI_MaxSamples,31        ;12
  65.     dc.l    MI_Length,0            ;20
  66.     dc.l    MI_Pattern,0            ;28
  67.     dc.l    MI_SongSize,0            ;36
  68.     dc.l    MI_SamplesSize,0        ;44
  69.     dc.l    MI_Calcsize,0            ;52
  70.     dc.l    MI_Maxlength,127
  71.     dc.l    0
  72. ;=============================================================================
  73. ;                    Get Infos (Create InfoTag-Itemliste)
  74. GetInfos:
  75.     lea    _MT_InfoBuffer(pc),a0
  76.     move.l    _MT_data(pc),d0
  77.     beq    RETURN
  78.  
  79.     lea    (a0),a3
  80.     lea    mt_playerdata(PC),a4
  81.     move.l    mt_data(a4),a0
  82.     lea    $3b8(a0),a1
  83.     moveq    #0,d1
  84.     move.b    -2(A1),d1
  85.     move.l    d1,20(a3)    ;Songlen
  86.  
  87.     moveq    #0,d1
  88.     move.w    #$1ff,d0
  89. .mt_loop:
  90.     cmp.b    (a1,d0.w),d1
  91.     bhi.s    .mt_nothigh
  92.     move.b    (a1,d0.w),d1
  93. .mt_nothigh:
  94.     dbf    d0,.mt_loop
  95.     addq.w    #1,d1
  96.     move.l    d1,d0
  97.     asr.l    #2,d0        ;durch 4
  98.     move.l    d0,28(a3)    ;Num Patterns
  99.  
  100.     lsl.l    #8,d1
  101.     add.l    #$5bc,d1
  102.     move.l    d1,36(a3)    ;Songsize
  103.     move.l    d1,52(a3)    ;Allsize
  104.  
  105.     moveq    #$1e,d0
  106.     moveq    #0,d2        ;Sampleanzahl
  107.     moveq    #0,d3        ;SamplelΣnge in Bytes
  108. .mt_lop3:
  109.     moveq    #0,d1
  110.     move.w    42(a0),d1    ;SamplelΣnge
  111.     beq.s    .not
  112.     add.l    d1,d3
  113.     add.l    d1,d3
  114.     addq.l    #1,d2
  115. .not    add.w    #$1e,a0
  116.     dbf    d0,.mt_lop3
  117.     move.l    d2,4(a3)
  118.     move.l    d3,44(a3)
  119.     add.l    d3,52(a3)
  120.  
  121.     move.l    a3,a0
  122.     moveq    #14,d0
  123. Return:    rts
  124. ;=============================================================================
  125. StructInit
  126.     lea    mt_StructAdr(pc),a0
  127. Structend
  128.     rts
  129. ;=============================================================================
  130. MT_getvoice:
  131.     movem.l    d0-d1/a1,-(sp)
  132.     lea    MT_Structadr(pc),a1    ;1.Kanal
  133.     cmp.l    #$dff0a0,a5
  134.     beq.s    .yes
  135.     lea    MT_Structadr+ups_modulo(pc),a1    ;2.Kanal
  136.     cmp.l    #$dff0b0,a5
  137.     beq.s    .yes
  138.     lea    MT_Structadr+ups_modulo*2(pc),a1    ;3.Kanal
  139.     cmp.l    #$dff0c0,a5
  140.     beq.s    .yes
  141.     lea    MT_Structadr+ups_modulo*3(pc),a1    ;4.Kanal
  142. .yes
  143.     move.w    MT_Period(a6),d0
  144.     and.w    #$fff,d0
  145.     move.w    d0,UPS_Voice1Per(a1)
  146.  
  147.     move.l    MT_sampleadr(a6),d0        ;Sampleadresse
  148.     move.l    d0,UPS_Voice1Adr(a1)
  149.  
  150.     moveq    #0,d1
  151.     cmp.l    mt_samplerep(A6),d0        ;Repeatbeginn = Sampleadresse ?
  152.     beq.s    .ok
  153.     moveq    #1,d1    ;nein,Repeat "off" setzen
  154. .ok    move.w    d1,UPS_Voice1Repeat(a1)
  155.  
  156.     move.w    mt_samplelen(a6),UPS_Voice1len(a1)    ;LΣnge
  157.  
  158.     movem.l    (sp)+,d0-d1/a1
  159.     rts
  160. ;=========================================================================
  161. _MT_Check:
  162.     move.l    dtg_ChkData(a5),a0
  163.     move.l    $5b8(a0),d0
  164.     and.l    #$ffffff00,d0
  165.     sub.l    #`MTN`*256,d0
  166.     rts
  167. ;=========================================================================
  168. InitPlay:
  169.     moveq    #0,d0
  170.     move.l    dtg_GetListData(a5),a0    ; Function
  171.     jsr    (a0)
  172.     move.l    a5,dtbase
  173.     move.l    a0,_mt_data
  174.     move.l    d0,mt_len
  175.  
  176.     move.l    dtg_AudioAlloc(a5),a0
  177.     jmp    (a0)
  178. ;=========================================================================
  179. EndPlay:
  180.     clr.l    _mt_data
  181.  
  182.     move.l    dtg_AudioFree(a5),a0
  183.     jmp    (a0)
  184. ;=========================================================================
  185. RemSnd:
  186.     lea    $dff000,a0
  187.     move.w    #$F,$96(a0)            ; End Sound
  188.     moveq    #0,d0
  189.     move.w    d0,$a8(a0)
  190.     move.w    d0,$b8(a0)
  191.     move.w    d0,$c8(a0)
  192.     move.w    d0,$d8(a0)
  193.  
  194.     lea    mt_structadr(pc),a0
  195.     move.w    d0,UPS_Flags(a0)
  196.     move.l    d0,ups_voice1adr(a0)
  197.     move.l    d0,ups_voice2adr(a0)
  198.     move.l    d0,ups_voice3adr(a0)
  199.     move.l    d0,ups_voice4adr(a0)
  200.     move.w    #1,ups_enabled(a0)
  201.     rts
  202. ;=========================================================================
  203. *-----------------------------------------------------------------------*
  204. *        d0 Bit 0-3 = Set Voices Bit=1 Voice on            *
  205. SetVoices:    lea    MT_StructAdr+UPS_DmaCon(pc),a0
  206.         move.w    EPG_Voices(a5),(a0)                ;Voices retten
  207.         lea    MT_VolVoice1(pc),a1
  208.         move.l    EPG_Voice1Vol(a5),(a1)
  209.         move.l    EPG_Voice3Vol(a5),4(a1)
  210.  
  211.         lea    MT_StructAdr+UPS_Voice1Vol(pc),a0
  212.         lea    $dff0a0,a5
  213.         moveq    #3,d1
  214. .SetNew        moveq    #0,d0
  215.         move.w    (a0),d0
  216.         bsr.s    MT_SetVoices
  217.         moveq    #UPS_Modulo,d0
  218.         add.l    d0,a0
  219.         addq.l    #8,a5
  220.         addq.l    #8,a5
  221.         dbf    d1,.SetNew
  222.         rts
  223.  
  224. *-----------------------------------------------------------------------*
  225. MT_SetVoices:    movem.l    a0/d0,-(a7)
  226.         and.w    #$7f,d0
  227.         lea    MT_StructAdr(pc),a0
  228.         cmp.l    #$dff0a0,a5            ;Left Volume
  229.         bne.s    .NoVoice1
  230.         move.w    d0,UPS_Voice1Vol(a0)
  231.         mulu.w    MT_VolVoice1(pc),d0
  232.         bra.b    .SetIt
  233. .NoVoice1:    cmp.l    #$dff0b0,a5            ;Right Volume
  234.         bne.s    .NoVoice2
  235.         move.w    d0,UPS_Voice2Vol(a0)
  236.         mulu.w    MT_VolVoice2(pc),d0
  237.         bra.b    .SetIt
  238. .NoVoice2:    cmp.l    #$dff0c0,a5            ;Right Volume
  239.         bne.s    .NoVoice3
  240.         move.w    d0,UPS_Voice3Vol(a0)
  241.         mulu.w    MT_VolVoice3(pc),d0
  242.         bra.b    .SetIt
  243. .NoVoice3:    move.w    d0,UPS_Voice4Vol(a0)
  244.         mulu.w    MT_VolVoice4(pc),d0
  245. .SetIt:        lsr.w    #6,d0
  246.         move.w    d0,8(a5)
  247. .Return:    movem.l    (a7)+,a0/d0
  248.         rts
  249.  
  250. ;=========================================================================
  251. _MT_NextPattern:
  252.     moveq    #0,d0
  253.     lea    mt_playerdata(PC),a4
  254.     clr.w    mt_pattpos(a4)
  255.     clr.b    mt_break(a4)
  256.  
  257.     addq.b    #1,mt_songpos(a4)
  258.     andi.b    #$7f,mt_songpos(a4)
  259.     move.b    mt_songpos(a4),d1
  260.  
  261.     move.l    mt_data(a4),a0
  262.     cmp.b    $3b6(a0),d1
  263.     bne.s    .mt_endr
  264.  
  265.     clr.b    mt_songpos(a4)
  266.     move.l    a2,-(sp)
  267.     move.l    dtbase(pc),a2
  268.     move.l    dtg_songend(A2),a2
  269.     jsr    (A2)
  270.     move.l    (sp)+,a2
  271. .mt_endr:
  272.     moveq    #0,d0
  273.     move.b    mt_songpos(a4),d0
  274.     rts
  275. ;=========================================================================
  276. _MT_BackPattern:
  277.     moveq    #0,d0
  278.     lea    mt_playerdata(PC),a4
  279.     move.l    _mt_data(pc),a0
  280.  
  281.     clr.w    mt_pattpos(a4)
  282.     clr.b    mt_break(a4)
  283.     subq.b    #1,mt_songpos(a4)
  284.     bgt.s    .ok
  285.  
  286. ;    move.b    $3b6(a0),mt_songpos(a4)
  287. ;    subq.b    #1,mt_songpos(a4)
  288. ;    and.b    #$7f,mt_songpos(a4)
  289.  
  290.     clr.b    mt_songpos(a4)
  291. .ok
  292.     moveq    #0,d0
  293.     move.b    mt_songpos(a4),d0
  294.     rts
  295. ;=========================================================================
  296. _MT_GetPosNr:
  297.     moveq    #0,d0
  298.     move.b    mt_playerdata+mt_songpos(pc),d0
  299.     rts
  300. mt_music2:
  301.     movem.l    d1-a6,-(a7)
  302.  
  303.     lea    mt_structadr(pc),a0
  304.     move.w    #UPSB_Adr!UPSB_LEN!UPSB_Per!UPSB_Vol!UPSB_DMACON,d0
  305.  
  306.     move.w    d0,UPS_Flags(a0)
  307.     clr.w    ups_voice1per(a0)
  308.     clr.w    ups_voice2per(a0)
  309.     clr.w    ups_voice3per(a0)
  310.     clr.w    ups_voice4per(a0)
  311.     move.w    #1,ups_enabled(a0)
  312.  
  313.     bsr.w    mt_Music
  314.  
  315.     lea    mt_structadr(pc),a0
  316.     clr.w    ups_enabled(a0)
  317.     movem.l    (a7)+,d1-a6
  318.     moveq    #0,d0
  319.     rts
  320. **********************************************
  321. *
  322. * Soundtracker Module-Player
  323. *   for Soundtracker V2.6
  324. *
  325. * SEKA version
  326. * (Devpac: replace 'blk' with 'dcb' (sic!) )
  327. *
  328. * last change: 03-Nov-90 mtn
  329. *
  330. **********************************************
  331. * Note: mt_init has to be called up with the
  332. * address of the module in A0 !!
  333. **********************************************
  334.  
  335. * equates for voice-structure *
  336. mt_cmdperiod=0                ;period
  337. mt_cmd=2                ;instr/cmd
  338. mt_cmdpar=3                ;cmd-parameter
  339. mt_sampleadr=4                ;address of sample
  340. mt_samplelen=8                ;length of sample
  341. mt_samplerep=$a                ;address of repeat-part
  342. mt_samplerepl=$e            ;length of repeat-part
  343. mt_period=$10                ;period to play
  344. mt_volume=$12                ;volume to set
  345. mt_dmabit=$14                ;dmabit for channel
  346. mt_slidedir=$16                ;slide up/down
  347. mt_slidespeed=$17            ;speed of slide
  348. mt_slidedest=$18            ;slide to period x
  349. mt_vibamp=$1a                ;vibrato amplitude
  350. mt_vibcount=$1b                ;counter for vibrato
  351. mt_voicelen=$1c
  352.  
  353. * equates for global player data-structure *
  354. mt_data=0                ;address of module
  355. mt_pattpos=4                ;current position
  356. mt_dmacon=6                ;dma-bits
  357. mt_speedEven=8                ;current speed (even frames)
  358. mt_speedOdd=9                ; -"- (odd frames)
  359. mt_songpos=$a                ;position-counter
  360. mt_counter=$b                ;frame-counter
  361. mt_break=$c                ;flag for pattern-break
  362. mt_datalen=$e
  363.  
  364. mt_init:
  365.     movem.l    d0-d1/a0-a2/a4,-(SP)
  366.     lea    mt_playerdata(PC),a4
  367.     move.l    mt_data(a4),a0
  368.     lea    $3b8(a0),a1
  369.     moveq    #0,d1
  370.     move.w    #$1ff,d0
  371. mt_loop:
  372.     cmp.b    (a1,d0.w),d1
  373.     bhi.s    mt_nothigh
  374.     move.b    (a1,d0.w),d1
  375. mt_nothigh:
  376.     dbf    d0,mt_loop
  377.     addq.b    #1,d1
  378.  
  379.     lea    mt_samplestarts(PC),a1
  380.     lsl.l    #8,d1
  381.     lea    (a0,d1.l),a2
  382.     add.w    #$5bc,a2
  383.  
  384.     moveq    #$1e,d0
  385. mt_lop3:clr.l    (a2)
  386.     move.l    a2,(a1)+
  387.     moveq    #0,d1
  388.     move.w    42(a0),d1
  389.     add.l    d1,d1
  390.     add.l    d1,a2
  391.     add.w    #$1e,a0
  392.     dbf    d0,mt_lop3
  393.  
  394.     or.b    #2,$bfe001
  395.     move.b    #$06,mt_speedEven(a4)
  396.     move.b    #$06,mt_speedOdd(a4)
  397.     lea    mt_voice1(PC),a0
  398.     move.w    #$0001,mt_dmabit(a0)
  399.     lea    mt_voice2(PC),a0
  400.     move.w    #$0002,mt_dmabit(a0)
  401.     lea    mt_voice3(PC),a0
  402.     move.w    #$0004,mt_dmabit(a0)
  403.     lea    mt_voice4(PC),a0
  404.     move.w    #$0008,mt_dmabit(a0)
  405.     lea    $dff0a8,a0
  406.     clr.w    (a0)
  407.     clr.w    $10(a0)
  408.     clr.w    $20(a0)
  409.     clr.w    $30(a0)
  410.     clr.b    mt_songpos(a4)
  411.     clr.b    mt_counter(a4)
  412.     clr.w    mt_pattpos(a4)
  413. mt_initerror:
  414.     movem.l    (SP)+,d0-d1/a0-a2/a4
  415.     rts
  416.  
  417. mt_end:
  418.     move.l    a0,-(SP)
  419.     lea    $dff0a8,a0
  420.     clr.w    (a0)
  421.     clr.w    $10(a0)
  422.     clr.w    $20(a0)
  423.     clr.w    $30(a0)
  424.     move.w    #$f,$96-$a8(a0)
  425.     move.l    (SP)+,a0
  426.     rts
  427.  
  428. mt_music:
  429.     movem.l    d0-d5/a0-a6,-(SP)
  430.     lea    mt_playerdata(PC),a4
  431.     move.l    mt_data(a4),d0
  432.     beq    mt_playerror
  433.     move.l    d0,a0
  434.     addq.b    #1,mt_counter(a4)
  435.     move.b    mt_counter(a4),d0
  436.     move.w    mt_pattpos(a4),d1
  437.     lsr.w    #2,d1
  438.     and.w    #1,d1
  439.     move.b    mt_speedEven(a4,d1.w),d1
  440.     cmp.b    d1,d0
  441.     blt.s    mt_nonew
  442.     clr.b    mt_counter(a4)
  443.     bra    mt_getnew
  444.  
  445. mt_nonew:
  446.     lea    mt_voice1(PC),a6
  447.     lea    $dff0a0,a5
  448.     bsr    mt_checkcom
  449.     lea    mt_voice2(PC),a6
  450.     lea    $dff0b0,a5
  451.     bsr    mt_checkcom
  452.     lea    mt_voice3(PC),a6
  453.     lea    $dff0c0,a5
  454.     bsr    mt_checkcom
  455.     lea    mt_voice4(PC),a6
  456.     lea    $dff0d0,a5
  457.     bsr    mt_checkcom
  458.     bra    mt_endr
  459.  
  460. mt_arpeggio:
  461.     moveq    #0,d0
  462.     move.b    mt_counter(a4),d0
  463.     divu    #$3,d0
  464.     swap    d0
  465.     tst.w    d0
  466.     beq.s    mt_arp2
  467.     cmp.w    #2,d0
  468.     beq.s    mt_arp1
  469.  
  470.     moveq    #0,d0
  471.     move.b    mt_cmdpar(a6),d0
  472.     lsr.b    #4,d0
  473.     bra.s    mt_arp3
  474. mt_arp1:moveq    #0,d0
  475.     move.b    mt_cmdpar(a6),d0
  476.     and.b    #$f,d0
  477.     bra.s    mt_arp3
  478. mt_arp2:move.w    mt_period(a6),d2
  479.     bra.s    mt_arp4
  480. mt_arp3:add.w    d0,d0
  481.     moveq    #0,d1
  482.     move.w    mt_period(a6),d1
  483.     lea    mt_periods(PC),a0
  484.     moveq    #$24,d3
  485. mt_arploop:
  486.     move.w    (a0,d0.w),d2
  487.     cmp.w    (a0),d1
  488.     bge.s    mt_arp4
  489.     addq.l    #2,a0
  490.     dbf    d3,mt_arploop
  491.     rts
  492. mt_arp4:move.w    d2,6(a5)
  493.     rts
  494.  
  495. mt_getnew:
  496.     clr.w    mt_dmacon(a4)
  497.  
  498.     lea    $dff0a0,a5
  499.     lea    mt_voice1(pc),a6
  500.     moveq    #0,d5
  501.     bsr.s    mt_playvoice
  502.     lea    $dff0b0,a5
  503.     lea    mt_voice2(pc),a6
  504.     moveq    #1,d5
  505.     bsr.s    mt_playvoice
  506.     lea    $dff0c0,a5
  507.     lea    mt_voice3(pc),a6
  508.     moveq    #2,d5
  509.     bsr.s    mt_playvoice
  510.     lea    $dff0d0,a5
  511.     lea    mt_voice4(pc),a6
  512.     moveq    #3,d5
  513.     bsr.s    mt_playvoice
  514.     bra    mt_setdma
  515.  
  516. mt_playvoice:
  517.     move.l    mt_data(a4),a0
  518.     lea    12(a0),a3
  519.     lea    $3b8(a0),a2
  520.     lea    $5bc(a0),a0
  521.  
  522.     moveq    #0,d0
  523.     moveq    #0,d1
  524.     move.b    mt_songpos(a4),d0
  525.     lsl.w    #2,d0
  526.     add.w    d0,a2
  527.     move.b    (a2,d5.w),d1
  528.     lsl.l    #8,d1
  529.     add.w    mt_pattpos(a4),d1
  530.  
  531.     move.l    (a0,d1.l),mt_cmdperiod(a6)
  532.     addq.l    #4,d1
  533.     moveq    #0,d2
  534.     move.b    mt_cmd(a6),d2
  535.     and.b    #$f0,d2
  536.     lsr.b    #4,d2
  537.     move.b    mt_cmdperiod(a6),d0
  538.     and.b    #$f0,d0
  539.     or.b    d0,d2
  540.     tst.b    d2
  541.     beq.s    mt_setregs
  542.     moveq    #0,d3
  543.     lea    mt_samplestarts(PC),a1
  544.     move.l    d2,d4
  545.     subq.l    #$1,d2
  546.     lsl.l    #2,d2
  547.     mulu    #$1e,d4
  548.     move.l    (a1,d2.l),mt_sampleadr(a6)
  549.     move.w    (a3,d4.l),mt_samplelen(a6)
  550.     move.w    $2(a3,d4.l),mt_volume(a6)
  551.     move.w    $4(a3,d4.l),d3
  552.     tst.w    d3
  553.     beq.s    mt_noloop
  554.     move.l    mt_sampleadr(a6),d2
  555.     add.w    d3,d3
  556.     add.l    d3,d2
  557.     move.l    d2,mt_samplerep(a6)
  558.     move.w    $4(a3,d4.l),d0
  559.     add.w    $6(a3,d4.l),d0
  560.     move.w    d0,mt_samplelen(a6)
  561.     move.w    $6(a3,d4.l),mt_samplerepl(a6)
  562.  
  563.     move.w    mt_volume(a6),d0
  564. ;    move.w    d0,8(a5)
  565.     bsr    mt_setvoices
  566.  
  567.     bra.s    mt_setregs
  568. mt_noloop:
  569.     move.l    mt_sampleadr(a6),d2
  570.     add.l    d3,d2
  571.     move.l    d2,mt_samplerep(a6)
  572.     move.w    $6(a3,d4.l),mt_samplerepl(a6)
  573.  
  574.     move.w    mt_volume(a6),d0
  575. ;    move.w    d0,8(a5)
  576.     bsr    mt_setvoices
  577. mt_setregs:
  578.     move.w    mt_cmdperiod(a6),d0
  579.     and.w    #$fff,d0
  580.     beq    mt_checkcom2
  581.     move.b    mt_cmd(a6),d0
  582.     and.b    #$f,d0
  583.     cmp.b    #$3,d0
  584.     bne.s    mt_setperiod
  585.     bsr    mt_setmyport
  586.     bsr    MT_getvoice
  587.     bra    mt_checkcom2
  588. mt_setperiod:
  589.     move.w    mt_cmdperiod(a6),mt_period(a6)
  590.     and.w    #$fff,mt_period(a6)
  591.     bsr    MT_getvoice
  592.     move.w    mt_dmabit(a6),$dff096
  593.     clr.b    mt_vibcount(a6)
  594.  
  595.     move.l    mt_sampleadr(a6),(a5)
  596.     move.w    mt_samplelen(a6),4(a5)
  597.     move.w    mt_period(a6),d0
  598.     and.w    #$fff,d0
  599.     move.w    d0,6(a5)
  600.     move.w    mt_dmabit(a6),d0
  601.     or.w    d0,mt_dmacon(a4)
  602.     bra    mt_checkcom2
  603.  
  604. mt_setdma:
  605.     lea    $dff000,a5
  606.     moveq    #8,d3                ;less than this can cause trouble
  607.     bsr    mt_waitscan
  608.     move.w    mt_dmacon(a4),d0
  609.     or.w    #$8000,d0
  610.     move.w    d0,$96(a5)
  611.     moveq    #1,d3
  612.     bsr    mt_waitscan
  613.     lea    mt_voice4(pc),a6
  614.     move.l    mt_samplerep(a6),$d0(a5)
  615.     move.w    mt_samplerepl(a6),$d4(a5)
  616.     lea    mt_voice3(pc),a6
  617.     move.l    mt_samplerep(a6),$c0(a5)
  618.     move.w    mt_samplerepl(a6),$c4(a5)
  619.     lea    mt_voice2(pc),a6
  620.     move.l    mt_samplerep(a6),$b0(a5)
  621.     move.w    mt_samplerepl(a6),$b4(a5)
  622.     lea    mt_voice1(pc),a6
  623.     move.l    mt_samplerep(a6),$a0(a5)
  624.     move.w    mt_samplerepl(a6),$a4(a5)
  625.  
  626.     addq.w    #4,mt_pattpos(a4)
  627.     cmp.w    #$100,mt_pattpos(a4)
  628.     bne.w    mt_endr
  629. mt_nex:    clr.w    mt_pattpos(a4)
  630.     clr.b    mt_break(a4)
  631.  
  632.     addq.b    #1,mt_songpos(a4)
  633.     and.b    #$7f,mt_songpos(a4)
  634.     move.b    mt_songpos(a4),d1
  635.     move.l    mt_data(a4),a0
  636.     cmp.b    $3b6(a0),d1
  637.     bne.w    mt_endr
  638.     clr.b    mt_songpos(a4)
  639.  
  640.     move.l    a2,-(sp)
  641.     move.l    dtbase(pc),a2
  642.     move.l    dtg_songend(A2),a2
  643.     jsr    (A2)
  644.     move.l    (sp)+,a2
  645.  
  646. mt_endr:tst.b    mt_break(a4)
  647.     bne.s    mt_nex
  648. mt_playerror:
  649.     movem.l    (SP)+,d0-d5/a0-a6
  650.     rts
  651.  
  652. mt_waitscan:
  653.     move.b    6(a5),d1
  654. mt_scanloop:
  655.     cmp.b    6(a5),d1
  656.     beq.s    mt_scanloop
  657.     dbf    d3,mt_waitscan
  658.     rts
  659.  
  660. mt_setmyport:
  661.     move.w    mt_cmdperiod(a6),d2
  662.     and.w    #$fff,d2
  663.     move.w    d2,mt_slidedest(a6)
  664.     move.w    mt_period(a6),d0
  665.     clr.b    mt_slidedir(a6)
  666.     cmp.w    d0,d2
  667.     beq.s    mt_clrport
  668.     bge.s    mt_rt
  669.     move.b    #$1,mt_slidedir(a6)
  670.     rts
  671. mt_clrport:
  672.     clr.w    mt_slidedest(a6)
  673. mt_rt:    rts
  674.  
  675. mt_myport:
  676.     move.b    mt_cmdpar(a6),d0
  677.     beq.s    mt_myslide
  678.     move.b    d0,mt_slidespeed(a6)
  679.     clr.b    mt_cmdpar(a6)
  680. mt_myslide:
  681.     tst.w    mt_slidedest(a6)
  682.     beq.s    mt_rt
  683.     moveq    #0,d0
  684.     move.b    mt_slidespeed(a6),d0
  685.     tst.b    mt_slidedir(a6)
  686.     bne.s    mt_mysub
  687.     add.w    d0,mt_period(a6)
  688.     move.w    mt_slidedest(a6),d0
  689.     cmp.w    mt_period(a6),d0
  690.     bgt.s    mt_myok
  691.     move.w    mt_slidedest(a6),mt_period(a6)
  692.     clr.w    mt_slidedest(a6)
  693. mt_myok:move.w    mt_period(a6),$6(a5)
  694.     rts
  695. mt_mysub:
  696.     sub.w    d0,mt_period(a6)
  697.     move.w    mt_slidedest(a6),d0
  698.     cmp.w    mt_period(a6),d0
  699.     blt.s    mt_myok
  700.     move.w    mt_slidedest(a6),mt_period(a6)
  701.     clr.w    mt_slidedest(a6)
  702.     move.w    mt_period(a6),$6(a5)
  703.     rts
  704.  
  705. mt_vib:    move.b    mt_cmdpar(a6),d0
  706.     beq.s    mt_vi
  707.     move.b    d0,mt_vibamp(a6)
  708.  
  709. mt_vi:    move.b    mt_vibcount(a6),d0
  710.     lea    mt_sin(PC),a0
  711.     lsr.w    #$2,d0
  712.     and.w    #$1f,d0
  713.     moveq    #0,d2
  714.     move.b    (a0,d0.w),d2
  715.     move.b    mt_vibamp(a6),d0
  716.     and.w    #$f,d0
  717.     mulu    d0,d2
  718.     lsr.w    #$6,d2
  719.     move.w    mt_period(a6),d0
  720.     tst.b    mt_vibcount(a6)
  721.     bmi.s    mt_vibmin
  722.     add.w    d2,d0
  723.     bra.s    mt_vib2
  724. mt_vibmin:
  725.     sub.w    d2,d0
  726. mt_vib2:move.w    d0,$6(a5)
  727.     move.b    mt_vibamp(a6),d0
  728.     lsr.w    #$2,d0
  729.     and.w    #$3c,d0
  730.     add.b    d0,mt_vibcount(a6)
  731.     rts
  732.  
  733. mt_nop:    move.w    mt_period(a6),$6(a5)
  734.     rts
  735.  
  736. mt_checkcom:
  737.     move.w    mt_cmd(a6),d0
  738.     and.w    #$fff,d0
  739.     beq.s    mt_nop
  740.     move.b    mt_cmd(a6),d0
  741.     and.b    #$f,d0
  742.     tst.b    d0
  743.     beq    mt_arpeggio
  744.     cmp.b    #$1,d0
  745.     beq.s    mt_portup
  746.     cmp.b    #$2,d0
  747.     beq    mt_portdown
  748.     cmp.b    #$3,d0
  749.     beq    mt_myport
  750.     cmp.b    #$4,d0
  751.     beq    mt_vib
  752.     move.w    mt_period(a6),$6(a5)
  753.     cmp.b    #$a,d0
  754.     beq.s    mt_volslide
  755.     rts
  756.  
  757. mt_volslide:
  758.     moveq    #0,d0
  759.     move.b    mt_cmdpar(a6),d0
  760.     lsr.b    #4,d0
  761.     tst.b    d0
  762.     beq.s    mt_voldown
  763.     add.w    d0,mt_volume(a6)
  764.     cmp.w    #$40,mt_volume(a6)
  765.     bmi.s    mt_vol2
  766.     move.w    #$40,mt_volume(a6)
  767. mt_vol2:
  768.     move.w    mt_volume(a6),d0
  769.     bra    mt_setvoices
  770. ;    move.w    d0,8(a5)
  771. ;    rts
  772.  
  773. mt_voldown:
  774.     moveq    #0,d0
  775.     move.b    mt_cmdpar(a6),d0
  776.     and.b    #$f,d0
  777.     sub.w    d0,mt_volume(a6)
  778.     bpl.s    mt_vol3
  779.     clr.w    mt_volume(a6)
  780. mt_vol3:
  781.     move.w    mt_volume(a6),d0
  782.     bra    mt_setvoices
  783. ;    move.w    d0,8(a5)
  784. ;    rts
  785.  
  786. mt_portup:
  787.     moveq    #0,d0
  788.     move.b    mt_cmdpar(a6),d0
  789.     sub.w    d0,mt_period(a6)
  790.     move.w    mt_period(a6),d0
  791.     and.w    #$fff,d0
  792.     cmp.w    #$71,d0
  793.     bpl.s    mt_por2
  794.     and.w    #$f000,mt_period(a6)
  795.     or.w    #$71,mt_period(a6)
  796. mt_por2:move.w    mt_period(a6),d0
  797.     and.w    #$fff,d0
  798.     move.w    d0,$6(a5)
  799.     rts
  800.  
  801. mt_portdown:
  802.     clr.w    d0
  803.     move.b    mt_cmdpar(a6),d0
  804.     add.w    d0,mt_period(a6)
  805.     move.w    mt_period(a6),d0
  806.     and.w    #$fff,d0
  807.     cmp.w    #$358,d0
  808.     bmi.s    mt_por3
  809.     and.w    #$f000,mt_period(a6)
  810.     or.w    #$358,mt_period(a6)
  811. mt_por3:move.w    mt_period(a6),d0
  812.     and.w    #$fff,d0
  813.     move.w    d0,$6(a5)
  814.     rts
  815.  
  816. mt_checkcom2:
  817.     move.b    mt_cmd(a6),d0
  818.     and.b    #$f,d0
  819.     cmp.b    #$e,d0
  820.     beq.s    mt_setfilt
  821.     cmp.b    #$d,d0
  822.     beq.s    mt_pattbreak
  823.     cmp.b    #$b,d0
  824.     beq.s    mt_posjmp
  825.     cmp.b    #$c,d0
  826.     beq.s    mt_setvol
  827.     cmp.b    #$f,d0
  828.     beq.s    mt_setspeed
  829.     rts
  830.  
  831. mt_setfilt:
  832.     move.b    mt_cmdpar(a6),d0
  833.     and.b    #1,d0
  834.     add.b    d0,d0
  835.     and.b    #$fd,$bfe001
  836.     or.b    d0,$bfe001
  837.     rts
  838. mt_pattbreak:
  839.     st    mt_break(a4)
  840.     rts
  841. mt_posjmp:
  842.     move.b    mt_cmdpar(a6),d0
  843.     subq.b    #1,d0
  844.     move.b    d0,mt_songpos(a4)
  845.     st    mt_break(a4)
  846.     rts
  847. mt_setvol:
  848.     cmp.b    #$40,mt_cmdpar(a6)
  849.     ble.s    mt_vol4
  850.     move.b    #$40,mt_cmdpar(a6)
  851. mt_vol4:
  852.     move.b    mt_cmdpar(a6),d0
  853.     bra    mt_setvoices
  854. ;    move.w    d0,8(a5)
  855. ;    rts
  856. mt_setspeed:
  857.     move.b    mt_cmdpar(a6),d0
  858.     and.w    #$ff,d0
  859.     beq.s    mt_rts2
  860.     move.b    d0,d1
  861.     and.b    #$f0,d1
  862.     beq.s    mt_speed1
  863.     lsr.b    #4,d1
  864.     bra.s    mt_speed3
  865. mt_speed1:
  866.     move.b    d0,d1
  867. mt_speed3:
  868.     and.b    #$f,d0
  869.     bne.s    mt_speed2
  870.     move.b    d1,d0
  871. mt_speed2:
  872.     move.b    d0,mt_speedEven(a4)
  873.     move.b    d1,mt_speedOdd(a4)
  874.     clr.b    mt_counter(a4)
  875. mt_rts2:rts
  876.  
  877. mt_sin:
  878.     dc.b $00,$18,$31,$4a,$61,$78,$8d,$a1,$b4,$c5,$d4,$e0,$eb,$f4,$fa,$fd
  879.     dc.b $ff,$fd,$fa,$f4,$eb,$e0,$d4,$c5,$b4,$a1,$8d,$78,$61,$4a,$31,$18
  880.  
  881. mt_periods:
  882.     dc.w $0358,$0328,$02fa,$02d0,$02a6,$0280,$025c,$023a,$021a,$01fc,$01e0
  883.     dc.w $01c5,$01ac,$0194,$017d,$0168,$0153,$0140,$012e,$011d,$010d,$00fe
  884.     dc.w $00f0,$00e2,$00d6,$00ca,$00be,$00b4,$00aa,$00a0,$0097,$008f,$0087
  885.     dc.w $007f,$0078,$0071,$0000,$0000
  886.  
  887. mt_playerdata:
  888. _MT_data:    blk.b    mt_datalen,0
  889. mt_samplestarts:blk.l    31,0
  890. mt_voice1:    blk.b    mt_voicelen,0
  891. mt_voice2:    blk.b    mt_voicelen,0
  892. mt_voice3:    blk.b    mt_voicelen,0
  893. mt_voice4:    blk.b    mt_voicelen,0
  894.  
  895.     end
  896.  
  897.  
  898.