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

  1. ************************************************************************
  2. *     Noisetracker 1.3d compressed Playroutine by United Forces/UFO    *
  3. *            to use within Delitracker and Eagleplayer                 *
  4. *                    Adaption by Buggs                                 *
  5. ************************************************************************
  6.     ;
  7. mt_speed    =0
  8. mt_songpos    =1
  9. mt_pattpos    =2
  10. mt_counter    =4
  11. mt_break    =5
  12. mt_dmacon    =6
  13. mt_samplestarts =8
  14. MT_Voice1    =132
  15. mt_voice2    =166
  16. mt_voice3    =200
  17. mt_voice4    =234
  18.  
  19. test = 0
  20.     ifne    test
  21.     bsr    mt_init
  22. wart
  23.     btst    #6,$bfe001
  24.     beq    end
  25.     move.b    $dff006,d0
  26.     cmp.b    #$ff,d0
  27.     bne    wart
  28.     bsr    mt_music
  29.     bra    wart
  30. end
  31.     bsr    mt_end
  32.     illegal
  33.     endc
  34.  
  35.     incdir    "Include:"
  36.     include "misc/EaglePlayer.i"
  37.  
  38.     PLAYERHEADER    Tags
  39.     dc.b `$VER: Noisetracker Compressed Playroutine V1.0 (Mar/12/93)`,0,0
  40. Tags
  41.     dc.l    DTP_RequestDTVersion,$ffff
  42.     dc.l    EP_PlayerVersion,4
  43.     dc.l    DTP_Volume,SetVoices
  44.     dc.l    DTP_Balance,SetVoices
  45.     dc.l    EP_Voices,SetVoices
  46.     dc.l    DTP_PlayerVersion,2
  47.     dc.l    DTP_PlayerName,_MT_Name
  48.     dc.l    DTP_Creator,MT_CName
  49.     dc.l    DTP_Check2,_MT_Check
  50.     dc.l    DTP_Interrupt,MT_Music2
  51.     dc.l    DTP_InitPlayer,InitPlay
  52.     dc.l    DTP_EndPlayer,EndPlay
  53.     dc.l    DTP_InitSound,MT_Init
  54.     dc.l    DTP_EndSound,RemSnd
  55.     dc.l    DTP_NextPatt,_MT_NextPattern
  56.     dc.l    DTP_PrevPatt,_MT_BackPattern
  57.  
  58.     dc.l    EP_GetPositionNr,_MT_GetPosNr
  59.  
  60.     dc.l    EP_Get_ModuleInfo,GetInfos
  61.  
  62. ;    dc.l    EP_SampleInit,SampleInit
  63. ;    dc.l    EP_SampleEnd,SampleEnd
  64.  
  65.     dc.l    EP_StructInit,StructInit
  66.  
  67.     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
  68.     dc.l    0
  69.  
  70.     ifeq    test
  71. mt_data:    dc.l    0
  72.     endc
  73. mt_len:        dc.l    0
  74. DTbase        dc.l    0
  75. MT_Structadr    ds.l    ups_sizeof
  76.  
  77. MT_VolVoice1    dc.w    1
  78. MT_VolVoice2    dc.w    1
  79. MT_VolVoice3    dc.w    1
  80. MT_VolVoice4    dc.w    1
  81.  
  82. *-----------------------------------------------------------------------*
  83. *        d0 Bit 0-3 = Set Voices Bit=1 Voice on            *
  84. SetVoices:    lea    MT_StructAdr+UPS_DmaCon(pc),a0
  85.         move.w    EPG_Voices(a5),(a0)                ;Voices retten
  86.         lea    MT_VolVoice1(pc),a1
  87.         move.l    EPG_Voice1Vol(a5),(a1)
  88.         move.l    EPG_Voice3Vol(a5),4(a1)
  89.  
  90.         lea    MT_StructAdr+UPS_Voice1Vol(pc),a0
  91.         lea    $dff0a0,a5
  92.         moveq    #3,d1
  93. .SetNew        moveq    #0,d0
  94.         move.w    (a0),d0
  95.         bsr.s    MT_SetVoices
  96.         moveq    #UPS_Modulo,d0
  97.         add.l    d0,a0
  98.         addq.l    #8,a5
  99.         addq.l    #8,a5
  100.         dbf    d1,.SetNew
  101.         rts
  102.  
  103. *-----------------------------------------------------------------------*
  104. MT_SetVoices:    movem.l    a0/d0,-(a7)
  105.         and.w    #$7f,d0
  106.         lea    MT_StructAdr(pc),a0
  107.         cmp.l    #$dff0a0,a5            ;Left Volume
  108.         bne.s    .NoVoice1
  109.         move.w    d0,UPS_Voice1Vol(a0)
  110.         mulu.w    MT_VolVoice1(pc),d0
  111.         bra.b    .SetIt
  112. .NoVoice1:    cmp.l    #$dff0b0,a5            ;Right Volume
  113.         bne.s    .NoVoice2
  114.         move.w    d0,UPS_Voice2Vol(a0)
  115.         mulu.w    MT_VolVoice2(pc),d0
  116.         bra.b    .SetIt
  117. .NoVoice2:    cmp.l    #$dff0c0,a5            ;Right Volume
  118.         bne.s    .NoVoice3
  119.         move.w    d0,UPS_Voice3Vol(a0)
  120.         mulu.w    MT_VolVoice3(pc),d0
  121.         bra.b    .SetIt
  122. .NoVoice3:    move.w    d0,UPS_Voice4Vol(a0)
  123.         mulu.w    MT_VolVoice4(pc),d0
  124. .SetIt:        lsr.w    #6,d0
  125.         move.w    d0,8(a5)
  126. .Return:    movem.l    (a7)+,a0/d0
  127.         rts
  128. ;========================================================================
  129. _MT_Name:    dc.b    "Noisetracker Compressed",0
  130. MT_CName:    dc.b    "United Forces/UFO,",10
  131.         dc.b    "adapted by Buggs of DEFECT",0
  132.         even
  133. ;========================================================================
  134. _MT_InfoBuffer:
  135.     dc.l    MI_Samples,0            ;4
  136.     dc.l    MI_MaxSamples,31        ;12
  137.     dc.l    MI_Length,0            ;20
  138.     dc.l    MI_Pattern,0            ;28
  139.     dc.l    MI_SongSize,0            ;36
  140.     dc.l    MI_SamplesSize,0        ;44
  141.     dc.l    MI_Calcsize,0            ;52
  142.     dc.l    MI_Unpacked,0            ;60
  143.     dc.l    MI_Unpackedsystem,MIUS_Noisetracker
  144.     dc.l    MI_Maxpattern,64
  145.     dc.l    MI_Maxlength,127
  146.     dc.l    0
  147. ;=============================================================================
  148. ;                    Get Infos (Create InfoTag-Itemliste)
  149. GetInfos:
  150.     lea    _MT_InfoBuffer(pc),a0
  151.     move.l    mt_data(pc),d0
  152.     beq.s    .nomod
  153.     move.l    d0,a1
  154.     lea    (a1),a2
  155.     moveq    #30,d0
  156.     moveq    #-1,d1        ;kleinstes Offset (SonglΣnge)
  157.     moveq    #0,d2        ;Anzahl der Samples
  158.     moveq    #0,d3        ;LΣnge der Samples
  159.     moveq    #0,d4
  160. .numsam
  161.     tst.l    (a2)
  162.     beq.s    .not
  163.     cmp.l    (a2),d1
  164.     bls.s    .not2
  165.     move.l    (A2),d1
  166. .not2
  167.     move.w    4(A2),d4
  168.     add.l    d4,d3
  169.     add.l    d4,d3
  170.     addq.l    #1,d2
  171. .not
  172.     addq.l    #8,a2
  173.     addq.l    #4,a2
  174.     dbf    d0,.numsam
  175.  
  176.     move.l    d1,36(a0)
  177.     move.l    d2,4(a0)
  178.  
  179.     move.l    d3,44(a0)    ;SamplelΣnge
  180.     move.l    d3,52(a0)    ;Calc SamplelΣnge
  181.     move.l    d3,60(a0)    ;Unpacked SamplelΣnge
  182.  
  183.     add.l    d1,52(a0)    ;Calc SonglΣnge
  184.  
  185.     moveq    #0,d0
  186.     move.b    $174(a1),d0
  187.     move.l    d0,20(a0)
  188.  
  189.     lea    $176(a1),a1
  190.     moveq    #$7f,d0
  191.     moveq    #0,d1
  192.     moveq    #0,d2
  193.  
  194. .seek    move.b    (a1)+,d1
  195.     cmp.b    d1,d2
  196.     bge.s    .nohi
  197.     move.b    d1,d2
  198. .nohi    dbf    d0,.seek
  199.     addq.w    #1,d2
  200.     move.l    d2,28(a0)
  201.  
  202.     mulu    #1024,d2
  203.     add.l    #$43c,d2
  204.     add.l    d2,60(a0)
  205. .nomod
  206.     moveq    #-1,d0
  207. Return:    rts
  208. ;=============================================================================
  209. StructInit
  210.     lea    mt_StructAdr(pc),a0
  211. Structend
  212.     rts
  213. ;=============================================================================
  214. MT_getvoice:
  215.     movem.l    d0-d1/a1,-(sp)
  216.     lea    MT_Structadr(pc),a1    ;1.Kanal
  217.     cmp.l    #$dff0a0,a5
  218.     beq.s    .yes
  219.     lea    MT_Structadr+ups_modulo(pc),a1    ;2.Kanal
  220.     cmp.l    #$dff0b0,a5
  221.     beq.s    .yes
  222.     lea    MT_Structadr+ups_modulo*2(pc),a1    ;3.Kanal
  223.     cmp.l    #$dff0c0,a5
  224.     beq.s    .yes
  225.     lea    MT_Structadr+ups_modulo*3(pc),a1    ;4.Kanal
  226. .yes
  227.     move.w    $10(a6),d0
  228.     and.w    #$fff,d0
  229.     move.w    d0,UPS_Voice1Per(a1)
  230.  
  231.     move.l    4(a6),d0        ;Sampleadresse
  232.     move.l    d0,UPS_Voice1Adr(a1)
  233.  
  234.     moveq    #0,d1
  235.     cmp.l    $a(A6),d0        ;Repeatbeginn = Sampleadresse ?
  236.     beq.s    .ok
  237.     moveq    #1,d1    ;nein,Repeat "off" setzen
  238. .ok    move.w    d1,UPS_Voice1Repeat(a1)
  239.  
  240.     move.w    8(a6),UPS_Voice1len(a1)    ;LΣnge
  241.  
  242.     movem.l    (sp)+,d0-d1/a1
  243.     rts
  244. ;=========================================================================
  245. _MT_Check:
  246.     moveq    #-1,d0
  247.     move.l    dtg_ChkData(a5),a0
  248.     lea    $174(a0),a1
  249.     moveq    #$7f,d1
  250. .check1
  251.     tst.b    (a1)+
  252.     blt.s    .fehler
  253.     dbf    d1,.check1
  254.  
  255.     move.l    $1f6(a0),d0
  256.     sub.l    #`PATT`,d0
  257. .fehler
  258.     rts
  259. ;=========================================================================
  260. InitPlay:
  261.     moveq    #0,d0
  262.     move.l    dtg_GetListData(a5),a0    ; Function
  263.     jsr    (a0)
  264.     move.l    a5,dtbase
  265.     move.l    a0,mt_data
  266.     move.l    d0,mt_len
  267.  
  268.     move.l    dtg_AudioAlloc(a5),a0
  269.     jmp    (a0)
  270. .Return:
  271.     moveq    #1,d0
  272.     rts
  273. ;=========================================================================
  274. EndPlay:
  275.     clr.l    mt_data
  276.  
  277.     move.l    dtg_AudioFree(a5),a0
  278.     jmp    (a0)
  279. ;=========================================================================
  280. RemSnd:
  281.     lea    $dff000,a0
  282.     move.w    #$F,$96(a0)            ; End Sound
  283.     moveq    #0,d0
  284.     move.w    d0,$a8(a0)
  285.     move.w    d0,$b8(a0)
  286.     move.w    d0,$c8(a0)
  287.     move.w    d0,$d8(a0)
  288.  
  289.     lea    mt_structadr(pc),a0
  290.     move.w    d0,UPS_Flags(a0)
  291.     move.l    d0,ups_voice1adr(a0)
  292.     move.l    d0,ups_voice2adr(a0)
  293.     move.l    d0,ups_voice3adr(a0)
  294.     move.l    d0,ups_voice4adr(a0)
  295.     move.w    #1,ups_enabled(a0)
  296.     rts
  297. ;=========================================================================
  298. _MT_NextPattern:
  299.     moveq    #0,d0
  300.     lea    mt_vars(pc),a4
  301.  
  302.     clr.b    mt_pattpos+1(a4)
  303.     clr.b    mt_break(a4)
  304.     addq.b    #1,mt_songpos(a4)
  305.     andi.b    #$7f,mt_songpos(a4)
  306.     move.b    mt_songpos(a4),d1
  307.  
  308.     move.l    mt_data(pc),a0
  309.     cmp.b    $174(a0),d1
  310.     bne.s    .not
  311.     move.b    $175(a0),mt_songpos(a4)    
  312.  
  313.     move.l    a2,-(sp)
  314.     move.l    dtbase(pc),a2
  315.     move.l    dtg_songend(A2),a2
  316.     jsr    (A2)
  317.     move.l    (sp)+,a2
  318.  
  319. .not    moveq    #0,d0
  320.     move.b    mt_songpos(a4),d0
  321.     bsr    setChannel
  322.     moveq    #0,d0
  323.     move.b    mt_songpos(a4),d0
  324.     rts
  325. ;=========================================================================
  326. _MT_BackPattern:
  327.     moveq    #0,d0
  328.     lea    mt_vars(pc),a4
  329.     move.l    mt_data(pc),a0
  330.  
  331.     clr.b    mt_pattpos+1(a4)
  332.     clr.b    mt_break(a4)
  333.     subq.b    #1,mt_songpos(a4)
  334.     bgt.s    .ok
  335. ;    move.b    $174(a0),mt_songpos(a4)
  336. ;    subq.b    #1,mt_songpos(a4)
  337. ;    and.b    #$7f,mt_songpos(a4)
  338.  
  339.     clr.b    mt_songpos(a4)
  340.  
  341. .ok
  342.     moveq    #0,d0
  343.     move.b    mt_songpos(a4),d0
  344.     bsr    setChannel
  345.     moveq    #0,d0
  346.     move.b    mt_songpos(a4),d0
  347.     rts
  348. ;=========================================================================
  349. _MT_GetPosNr:
  350.     moveq    #0,d0
  351.     move.b    mt_vars+mt_songpos(pc),d0
  352.     rts
  353. mt_music2:
  354.     movem.l    d1-a6,-(a7)
  355.  
  356.     lea    mt_structadr(pc),a0
  357.     move.w    #UPSB_Adr!UPSB_LEN!UPSB_Per!UPSB_Vol!UPSB_DMACON,d0
  358.  
  359.     move.w    d0,UPS_Flags(a0)
  360.     clr.w    ups_voice1per(a0)
  361.     clr.w    ups_voice2per(a0)
  362.     clr.w    ups_voice3per(a0)
  363.     clr.w    ups_voice4per(a0)
  364.     move.w    #1,ups_enabled(a0)
  365.  
  366.     bsr.w    mt_Music
  367.  
  368.     lea    mt_structadr(pc),a0
  369.     clr.w    ups_enabled(a0)
  370.     movem.l    (a7)+,d1-a6
  371.     moveq    #0,d0
  372.     rts
  373.  
  374.     ;*******************************
  375.     ;*** NOISETRACKER COMPRESSED ***
  376.     ;*** REPLAYROUTINE 1.3 D     ***
  377.     ;*** IMPROVED ON 15/03/91    ***
  378.     ;*** BY ANTICHRIST OF UFO    ***
  379.     ;*******************************
  380.  
  381. ; This routine is fully pc-relative.
  382. ; Don't change anything in mt_vars
  383. ; ('coz the offsets below won't fit anymore!).
  384.  
  385. ; Include your PACKED module at mt_data (still the same!)
  386. ; To init, jump to Offset 0
  387. ; ╗╗ Load your start position to d0.l ½½
  388. ; To play, jump to Offset 4
  389. ; To stop, jump to Offset 8
  390.  
  391.  
  392. mt_init:
  393.     lea    mt_vars(pc),a4
  394.     lea    (a4),a0
  395.     move.w    #mt_varslen-1,d0
  396. .clr
  397.     clr.b    (a0)+
  398.     dbf    d0,.clr
  399.  
  400.     move.w    #1,mt_voice1+20(a4)
  401.     move.w    #2,mt_voice2+20(a4)
  402.     move.w    #4,mt_voice3+20(a4)
  403.     move.w    #8,mt_voice4+20(a4)
  404.  
  405.     move.l    mt_data(pc),a0
  406.     move.l    a0,a1
  407.     lea    $176(a1),a1
  408.     moveq    #$7f,d0
  409.     moveq    #0,d1
  410.     moveq    #0,d2
  411.  
  412. .seek    move.b    (a1)+,d1
  413.     cmp.b    d1,d2
  414.     bge.s    .nohi
  415.     move.b    d1,d2
  416. .nohi    dbf    d0,.seek
  417.  
  418.     move.l    mt_data(pc),a0
  419.     lea    $1f6(a0),a0
  420.     lea    mt_patterns(pc),a1
  421.     move.w    #$5041,d0
  422.     move.w    #$5454,d1
  423. .getPatt
  424.     cmp.w    (a0)+,d0
  425.     bne.s    .getPatt
  426.     cmp.w    (a0)+,d1
  427.     bne.s    .getPatt
  428.     move.l    a0,(a1)+
  429.     dbf    d2,.getPatt
  430.  
  431.     lea    mt_samplestarts(a4),a1
  432.     move.l    mt_data(pc),a2
  433.     move.l    a2,d2
  434.     moveq    #31-1,d1
  435. mt_lop3:
  436.     move.l    (a2),d0
  437.     add.l    d2,d0
  438.     move.l    d0,(a1)+
  439.     lea    12(a2),a2
  440.     dbf    d1,mt_lop3
  441.  
  442.     moveq    #0,d0
  443.     bsr    setChannel
  444.  
  445. ;    bset    #1,$bfe001
  446.  
  447.     move.b    #6,mt_speed(a4)
  448.  
  449.     clr.w    $dff0a8
  450.     clr.w    $dff0b8
  451.     clr.w    $dff0c8
  452.     clr.w    $dff0d8
  453.     clr.b    mt_counter(a4)
  454.     clr.w    mt_pattpos(a4)
  455.     rts
  456.  
  457. mt_end:
  458.     clr.w    $dff0a8
  459.     clr.w    $dff0b8
  460.     clr.w    $dff0c8
  461.     clr.w    $dff0d8
  462.     move.w    #$f,$dff096
  463.     rts
  464.  
  465. mt_music:
  466.     lea    mt_vars(pc),a4
  467.     addq.b    #1,mt_counter(a4)
  468.     move.b    mt_counter(a4),D0
  469.     cmp.b    mt_speed(a4),D0
  470.     blt.s    mt_nonew
  471.     clr.b    mt_counter(a4)
  472.     bra    mt_getnew
  473.  
  474. mt_nonew:
  475.     lea    mt_voice1(a4),a6
  476.     lea    $dff0a0,a5
  477.     bsr    mt_checkcom
  478.     lea    mt_voice2(a4),a6
  479.     lea    $10(a5),a5
  480.     bsr    mt_checkcom
  481.     lea    mt_voice3(a4),a6
  482.     lea    $10(a5),a5
  483.     bsr    mt_checkcom
  484.     lea    mt_voice4(a4),a6
  485.     lea    $10(a5),a5
  486.     bsr    mt_checkcom
  487.     bra    mt_endr
  488.  
  489. mt_arpeggio:
  490.     moveq    #0,d0
  491.     move.b    mt_counter(a4),d0
  492.     divs    #3,d0
  493.     swap    d0
  494.     cmp.w    #0,d0
  495.     beq.s    mt_arp2
  496.     cmp.w    #2,d0
  497.     beq.s    mt_arp1
  498.  
  499.     moveq    #0,d0
  500.     move.b    3(a6),d0
  501.     lsr.b    #4,d0
  502.     bra.s    mt_arp3
  503. mt_arp1:
  504.     moveq    #0,d0
  505.     move.b    $3(a6),d0
  506.     and.b    #$f,d0
  507.     bra.s    mt_arp3
  508. mt_arp2:
  509.     move.w    $10(a6),d2
  510.     bra.s    mt_arp4
  511. mt_arp3:
  512.     asl.w    #1,d0
  513.     moveq    #0,d1
  514.     move.w    $10(a6),d1
  515.     lea    mt_periods(pc),a0
  516.     moveq    #$24,d7
  517. mt_arploop:
  518.     move.w    (a0,d0.w),d2
  519.     cmp.w    (a0),d1
  520.     bge.s    mt_arp4
  521.     addq.l    #2,a0
  522.     dbf    d7,mt_arploop
  523.     rts
  524. mt_arp4:move.w    d2,$6(a5)
  525.     rts
  526.  
  527. mt_getnew:
  528.     move.l    mt_data(pc),a3
  529.     clr.w    mt_dmacon(a4)
  530.     lea    $dff0a0,a5
  531.     lea    mt_voice1(a4),a6
  532.     bsr.s    mt_playvoice
  533.     lea    $10(a5),a5
  534.     lea    mt_voice2(a4),a6
  535.     bsr.s    mt_playvoice
  536.     lea    $10(a5),a5
  537.     lea    mt_voice3(a4),a6
  538.     bsr.s    mt_playvoice
  539.     lea    $10(a5),a5
  540.     lea    mt_voice4(a4),a6
  541.     bsr.s    mt_playvoice
  542.     bra    mt_setdma
  543.  
  544. mt_playvoice:
  545.     tst.w    32(a6)
  546.     beq.s    .nodelay
  547.     subq.w    #1,32(a6)
  548.     bra.s    .morevoice
  549. .nodelay
  550.     move.l    28(a6),a0
  551.     moveq    #0,d2
  552.     move.b    (a0),d2
  553.     cmpi.b    #$ff,d2
  554.     bne.s    .nocrunch
  555.     move.b    1(a0),33(a6)
  556.     addq.l    #2,28(a6)
  557.     clr.l    (a6)
  558.     bra.s    mt_playvoice
  559. .nocrunch
  560.     move.b    d2,d0
  561.     andi.b    #$3f,d2
  562.     beq.s    .noset
  563.     lsl.w    #1,d2
  564.     lea    mt_periods(pc),a1
  565.     move.w    -2(a1,d2.w),d2
  566. .noset    btst    #7,d0
  567.     beq.s    .nohisamp
  568.     bset    #12,d2
  569. .nohisamp
  570.     move.w    d2,(a6)
  571.     move.b    1(a0),2(a6)
  572.     clr.b    3(a6)
  573.     btst    #6,d0
  574.     bne.s    .nocom
  575.     move.b    2(a0),3(a6)
  576.     addq.l    #1,28(a6)
  577. .nocom    addq.l    #2,28(a6)
  578. .morevoice
  579.     moveq    #0,d2
  580.     move.b    2(a6),d2
  581.     and.b    #$f0,d2
  582.     lsr.b    #4,d2
  583.     move.b    (a6),d0
  584.     and.b    #$f0,d0
  585.     or.b    d0,d2
  586.     tst.b    d2
  587.     beq.s    mt_setregs
  588.     lea    mt_samplestarts(a4),a1
  589.     subq.l    #1,d2
  590.     move.l    d2,d4
  591.     mulu    #12,d4                
  592.     asl.l    #2,d2                
  593.     move.l    (a1,d2.l),4(a6)            
  594.     move.w    4(a3,d4.l),8(a6)        
  595.     move.w    6(a3,d4.l),18(a6)        
  596.     moveq    #0,d3
  597.     move.w    8(a3,d4.l),d3
  598.     tst.w    d3
  599.     beq.s    mt_noloop
  600.     move.l    4(a6),d2
  601.     lsl.l    #1,d3
  602.     add.l    d3,d2
  603.     move.l    d2,$a(a6)
  604.     move.w    8(a3,d4.l),d0
  605.     add.w    10(a3,d4.l),d0
  606.     move.w    d0,8(a6)
  607.     move.w    10(a3,d4.l),$e(a6)
  608.  
  609.     move.w    $12(a6),d0
  610.     bsr    mt_setvoices
  611. ;    move.w    $12(a6),$8(a5)
  612.     bra.s    mt_setregs
  613. mt_noloop:
  614.     move.l    4(a6),d2
  615.     add.l    d3,d2
  616.     move.l    d2,10(a6)
  617.     move.w    10(a3,d4.l),14(a6)
  618.  
  619.     move.w    18(a6),d0
  620.     bsr    mt_setvoices
  621. ;    move.w    18(a6),8(a5)
  622. mt_setregs:
  623.     move.w    (a6),d0
  624.     andi.w    #$fff,d0
  625.     beq    mt_checkcom2
  626.     move.b    2(a6),d0
  627.     and.b    #$F,d0
  628.     cmp.b    #$3,d0
  629.     bne.s    mt_setperiod
  630.     bsr    mt_setmyport
  631.     bsr    MT_getvoice
  632.     bra    mt_checkcom2
  633. mt_setperiod:
  634.     move.w    (a6),$10(a6)
  635.     and.w    #$fff,$10(a6)
  636.     bsr    MT_getvoice
  637.  
  638.     move.w    $14(a6),d0
  639.     move.w    d0,$dff096
  640.     clr.b    $1b(a6)
  641.  
  642.     move.l    4(a6),(a5)
  643.     move.w    8(a6),4(a5)
  644.     move.w    $10(a6),d0
  645.     and.w    #$fff,d0
  646.     move.w    d0,$6(a5)
  647.     move.w    20(a6),d0
  648.     or.w    d0,mt_dmacon(a4)
  649.     bra    mt_checkcom2
  650.  
  651. mt_setdma:
  652.     bsr    waitdma
  653.  
  654.     move.w    mt_dmacon(a4),d0
  655.     or.w    #$8000,d0
  656.     move.w    d0,$dff096
  657.  
  658.     bsr    waitdma
  659.  
  660.     lea    $dff000,a5
  661.     lea    mt_voice4(a4),a6
  662.     move.l    $a(a6),$d0(a5)
  663.     move.w    $e(a6),$d4(a5)
  664.     lea    mt_voice3(a4),a6
  665.     move.l    $a(a6),$c0(a5)
  666.     move.w    $e(a6),$c4(a5)
  667.     lea    mt_voice2(a4),a6
  668.     move.l    $a(a6),$b0(a5)
  669.     move.w    $e(a6),$b4(a5)
  670.     lea    mt_voice1(a4),a6
  671.     move.l    $a(a6),$a0(a5)
  672.     move.w    $e(a6),$a4(a5)
  673.     addq.b    #1,mt_pattpos+1(a4)
  674.     cmpi.b    #64,mt_pattpos+1(a4)
  675.     bne.s    mt_endr
  676. mt_nex:    clr.b    mt_pattpos+1(a4)
  677.     clr.b    mt_break(a4)
  678.     addq.b    #1,mt_songpos(a4)
  679.     andi.b    #$7f,mt_songpos(a4)
  680.     move.b    mt_songpos(a4),d1
  681.  
  682.     move.l    mt_data(pc),a0
  683.     cmp.b    $174(a0),d1
  684.     bne.s    .not
  685.     move.b    $175(a0),mt_songpos(a4)    
  686. .not    moveq    #0,d0
  687.     move.b    mt_songpos(a4),d0
  688.     bsr    setChannel
  689. mt_endr:
  690.     tst.b    mt_break(a4)
  691.     bne.s    mt_nex
  692.     rts
  693. waitdma
  694.     movem.l    d0/d1,-(sp)
  695.     moveq    #4,d0
  696. .wait2
  697.     move.b    $dff006,d1
  698. .wart1
  699.     cmp.b    $dff006,d1
  700.     beq.s    .wart1
  701.     dbf    d0,.wait2
  702.  
  703.     movem.l    (sp)+,d0/d1
  704.     rts
  705. mt_setmyport:
  706.     move.w    (a6),d2
  707.     and.w    #$fff,d2
  708.     move.w    d2,$18(a6)
  709.     move.w    $10(a6),d0
  710.     clr.b    $16(a6)
  711.     cmp.w    d0,d2
  712.     beq.s    mt_clrport
  713.     bge.s    mt_rt
  714.     move.b    #$1,$16(a6)
  715.     rts
  716. mt_clrport:
  717.     clr.w    $18(a6)
  718. mt_rt:    rts
  719.  
  720. mt_myport:
  721.     move.b    3(a6),d0
  722.     beq.s    mt_myslide
  723.     move.b    d0,$17(a6)
  724.     clr.b    3(a6)
  725. mt_myslide:
  726.     tst.w    $18(a6)
  727.     beq.s    mt_rt
  728.     moveq    #0,d0
  729.     move.b    $17(a6),d0
  730.     tst.b    $16(a6)
  731.     bne.s    mt_mysub
  732.     add.w    d0,$10(a6)
  733.     move.w    $18(a6),d0
  734.     cmp.w    $10(a6),d0
  735.     bgt.s    mt_myok
  736.     move.w    $18(a6),$10(a6)
  737.     clr.w    $18(a6)
  738. mt_myok:move.w    $10(a6),$6(a5)
  739.     rts
  740. mt_mysub:
  741.     sub.w    d0,$10(a6)
  742.     move.w    $18(a6),d0
  743.     cmp.w    $10(a6),d0
  744.     blt.s    mt_myok
  745.     move.w    $18(a6),$10(a6)
  746.     clr.w    $18(a6)
  747.     move.w    $10(a6),$6(a5)
  748.     rts
  749.  
  750. mt_vib:    move.b    3(a6),d0
  751.     beq.s    mt_vi
  752.     move.b    d0,$1a(a6)
  753.  
  754. mt_vi:    move.b    $1b(a6),d0
  755.     lea    mt_sin(pc),a4
  756.     lsr.w    #$2,d0
  757.     and.w    #$1f,d0
  758.     moveq    #0,d2
  759.     move.b    (a4,d0.w),d2
  760.     move.b    $1a(a6),d0
  761.     and.w    #$f,d0
  762.     mulu    d0,d2
  763.     lsr.w    #$6,d2
  764.     move.w    $10(a6),d0
  765.     tst.b    $1b(a6)
  766.     bmi.s    mt_vibmin
  767.     add.w    d2,d0
  768.     bra.s    mt_vib2
  769. mt_vibmin:
  770.     sub.w    d2,d0
  771. mt_vib2:move.w    d0,$6(a5)
  772.     move.b    $1a(a6),d0
  773.     lsr.w    #$2,d0
  774.     and.w    #$3c,d0
  775.     add.b    d0,$1b(a6)
  776.     lea    mt_vars(pc),a4
  777.     rts
  778.  
  779. mt_nop:    move.w    $10(a6),$6(a5)
  780.     rts
  781.  
  782. mt_checkcom:
  783.     move.w    2(a6),d0
  784.     and.w    #$fff,d0
  785.     beq.s    mt_nop
  786.     move.b    2(a6),d0
  787.     and.b    #$f,d0
  788.     tst.b    d0
  789.     beq    mt_arpeggio
  790.     cmp.b    #$1,d0
  791.     beq.s    mt_portup
  792.     cmp.b    #$2,d0
  793.     beq    mt_portdown
  794.     cmp.b    #$3,d0
  795.     beq    mt_myport
  796.     cmp.b    #$4,d0
  797.     beq    mt_vib
  798.     move.w    $10(a6),$6(a5)
  799.     cmp.b    #$a,d0
  800.     beq.s    mt_volslide
  801.     rts
  802.  
  803. mt_volslide:
  804.     moveq    #0,d0
  805.     move.b    $3(a6),d0
  806.     lsr.b    #4,d0
  807.     tst.b    d0
  808.     beq.s    mt_voldown
  809.     add.w    d0,$12(a6)
  810.     cmp.w    #$40,$12(a6)
  811.     bmi.s    mt_vol2
  812.     move.w    #$40,$12(a6)
  813. mt_vol2:
  814.     move.w    $12(a6),d0
  815.     bra    mt_setvoices
  816. ;    move.w    d0,$8(a5)
  817. ;    rts
  818.  
  819. mt_voldown:
  820.     moveq    #0,d0
  821.     move.b    $3(a6),d0
  822.     and.b    #$f,d0
  823.     sub.w    d0,$12(a6)
  824.     bpl.s    mt_vol3
  825.     clr.w    $12(a6)
  826. mt_vol3:
  827.     move.w    $12(a6),d0
  828.     bra    mt_setvoices
  829. ;    move.w    $12(a6),$8(a5)
  830. ;    rts
  831.  
  832. mt_portup:
  833.     moveq    #0,d0
  834.     move.b    3(a6),d0
  835.     sub.w    d0,$10(a6)
  836.     move.w    $10(a6),d0
  837.     and.w    #$fff,d0
  838.     cmp.w    #$71,d0
  839.     bpl.s    mt_por2
  840.     and.w    #$f000,$10(a6)
  841.     or.w    #$71,$10(a6)
  842. mt_por2:move.w    $10(a6),d0
  843.     and.w    #$fff,d0
  844.     move.w    d0,$6(a5)
  845.     rts
  846.  
  847. mt_portdown:
  848.     clr.w    d0
  849.     move.b    $3(a6),d0
  850.     add.w    d0,$10(a6)
  851.     move.w    $10(a6),d0
  852.     and.w    #$fff,d0
  853.     cmp.w    #$358,d0
  854.     bmi.s    mt_por3
  855.     and.w    #$f000,$10(a6)
  856.     or.w    #$358,$10(a6)
  857. mt_por3:move.w    $10(a6),d0
  858.     and.w    #$fff,d0
  859.     move.w    d0,$6(a5)
  860.     rts
  861.  
  862. mt_checkcom2:
  863.     move.b    2(a6),d0
  864.     and.b    #$f,d0
  865.     cmp.b    #$e,d0
  866.     beq.s    mt_setfilt
  867.     cmp.b    #$d,d0
  868.     beq.s    mt_pattbreak
  869.     cmp.b    #$b,d0
  870.     beq.s    mt_posjmp
  871.     cmp.b    #$c,d0
  872.     beq.s    mt_setvol
  873.     cmp.b    #$f,d0
  874.     beq.s    mt_setspeed
  875.     rts
  876.  
  877. mt_setfilt:
  878. ;    move.b    $3(a6),d0
  879. ;    and.b    #$1,d0
  880. ;    asl.b    #$1,d0
  881. ;    and.b    #$fd,$bfe001
  882. ;    or.b    d0,$bfe001
  883.     rts
  884. mt_posjmp:
  885.     move.b    3(a6),d0
  886.     subq.b    #1,d0
  887.     move.b    d0,mt_songpos(a4)
  888. mt_pattbreak:
  889.     not.b    mt_break(a4)
  890.     rts
  891. mt_setvol:
  892.     cmp.b    #$40,$3(a6)
  893.     ble.s    mt_vol4
  894.     move.b    #$40,$3(a6)
  895. mt_vol4:
  896.     move.l    d0,-(sp)
  897.     moveq    #0,d0
  898.     move.b    3(a6),d0
  899.     bsr    mt_setvoices
  900.     move.l    (sp)+,d0
  901. ;    move.b    $3(a6),$8(a5)
  902.     rts
  903.  
  904. mt_setspeed:
  905.     cmp.b    #$1f,$3(a6)
  906.     ble.s    mt_sets
  907.     move.b    #$1f,$3(a6)
  908. mt_sets:
  909.     move.b    $3(a6),d0
  910.     beq.s    mt_rts2
  911.     move.b    d0,mt_speed(a4)
  912.     clr.b    mt_counter(a4)
  913. mt_rts2:
  914.     rts
  915.  
  916. setChannel:
  917.     move.l    mt_data(pc),a0
  918.  
  919.     lea    mt_vars(pc),a4
  920.     cmp.b    $174(a0),d0
  921.     blt.s    .valid
  922.     moveq    #0,d0
  923. .valid    move.b    d0,mt_songpos(a4)
  924.  
  925.     lea    $176(a0),a0
  926.  
  927.     move.b    (a0,d0.w),d0
  928.     lsl.l    #2,d0
  929.     lea    mt_voice1(a4),a1
  930.     lea    mt_patterns(pc),a0
  931.     move.l    (a0,d0.w),a0
  932.     move.l    a0,d2
  933.     move.l    d2,d0
  934.     addq.l    #6,d0
  935.     moveq    #3,d1
  936.     bra.s    .dochan
  937. .setchannel
  938.     lea    34(a1),a1
  939.     moveq    #0,d0
  940.     move.w    (a0)+,d0
  941.     add.l    d2,d0
  942. .dochan
  943.     move.l    d0,28(a1)
  944.     clr.w    32(a1)
  945.     dbf    d1,.setchannel
  946.     rts
  947.  
  948. mt_sin:
  949.  DC.b $00,$18,$31,$4a,$61,$78,$8d,$a1,$b4,$c5,$d4,$e0,$eb,$f4,$fa,$fd
  950.  DC.b $ff,$fd,$fa,$f4,$eb,$e0,$d4,$c5,$b4,$a1,$8d,$78,$61,$4a,$31,$18
  951.  
  952. mt_periods:
  953.  DC.w $0358,$0328,$02fa,$02d0,$02a6,$0280,$025c,$023a,$021a,$01fc,$01e0
  954.  DC.w $01c5,$01ac,$0194,$017d,$0168,$0153,$0140,$012e,$011d,$010d,$00fe
  955.  DC.w $00f0,$00e2,$00d6,$00ca,$00be,$00b4,$00aa,$00a0,$0097,$008f,$0087
  956.  DC.w $007f,$0078,$0071
  957.  
  958. mt_patterns:
  959.     dcb.l    64
  960. mt_vars:            ;*** DON'T CHANGE ANYTHING BELOW ***
  961.     DC.b    6
  962.     DC.b    0
  963.     DC.w    0
  964.     DC.b    0
  965.     DC.b    0
  966.     DC.w    0
  967. ;mt_samplestarts
  968.     ds.l    $1f
  969.  
  970. ;mt_voice1
  971.     ds.w    10
  972.     DC.w    1
  973.     ds.w    3
  974.     dc.l    0        
  975.     dc.w    0        
  976.  
  977. ;mt_voice2
  978.     ds.w    10
  979.     DC.w    2
  980.     ds.w    3
  981.     dc.l    0
  982.     dc.w    0
  983.     
  984. ;mt_voice3
  985.     ds.w    10
  986.     DC.w    4
  987.     ds.w    3
  988.     dc.l    0
  989.     dc.w    0
  990.     
  991. ;mt_voice4
  992.     dcb.w    10
  993.     DC.w    8
  994.     dcb.w    3
  995.     dc.l    0
  996.     dc.w    0
  997. mt_varslen=*-mt_vars
  998.     dc.l    0
  999.  
  1000.     ifne    test
  1001. mt_data:
  1002.     dc.l    data
  1003. data
  1004.     incdir    df1:
  1005.     INCBIN    pak.agnostica
  1006.  
  1007.     endc
  1008.     end
  1009.