home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 4: The Falcon Archive / nf_archive_four_v1.0.iso / ARCHIVE / WORK / MSX / MEGPL116.ZIP / MGPL-116 / AMIGA / AMIGA030.S < prev    next >
Text File  |  1995-09-17  |  44KB  |  1,733 lines

  1. ***********************************************************************
  2. ***********                                        ***********
  3. ***********                                        ***********
  4. ***********       Amiga 4 Interlaced Voices 030 Replay        ***********
  5. ***********                                        ***********
  6. ***********                                        ***********
  7. ***********          By Simplet / FATAL DESIGN            ***********
  8. ***********                                        ***********
  9. ***********************************************************************
  10.  
  11.         Section    TEXT
  12.  
  13. Freq_No        equ        1
  14. Freq_Replay    equ        25175000/256/2/(Freq_No+1)
  15.  
  16. CPU_Time        equ        0
  17.  
  18.         XDef        MGTK_Init_Module_Samples
  19.         XDef        MGTK_Save_Sound,MGTK_Init_Sound,MGTK_Restore_Sound
  20.         XDef        MGTK_Play_Music,MGTK_Pause_Music,MGTK_Stop_Music
  21.         XDef        MGTK_Play_Position,MGTK_Previous_Position
  22.         XDef        MGTK_Next_Position,MGTK_Clear_Voices
  23.         XDef        MGTK_Voices,MGTK_Restart_Loop,MGTK_Restart_Done
  24.  
  25. ***********************************************************************
  26. ***********                    Macros                ***********
  27. ***********************************************************************
  28.  
  29. WaitDSPToSend    Macro
  30. WaitDSPS\@    btst.b    #1,$ffffa202.w            ; Attend que le DSP
  31.             beq.s    WaitDSPS\@            ; puisse recevoir
  32.             EndM
  33.  
  34. WaitDSPToGet    Macro
  35. WaitDSPG\@    btst.b    #0,$ffffa202.w            ; Attend que le DSP
  36.             beq.s    WaitDSPG\@            ; ait envoyé une donnée
  37.             EndM
  38.  
  39. SaveColor        Macro
  40.             Ifne        CPU_Time
  41.                 move.l    $ffff9800.w,-(sp)
  42.             EndC
  43.             EndM
  44.  
  45. RestoreColor    Macro
  46.             Ifne        CPU_Time
  47.                 move.l    (sp)+,$ffff9800.w
  48.             EndC
  49.             EndM
  50.  
  51. CPUTimeColor    Macro
  52.             Ifne        CPU_Time
  53.                 move.l    \1,$ffff9800.w
  54.             EndC
  55.             EndM
  56.  
  57. ***********************************************************************
  58. ***********                Structures                ***********
  59. ***********************************************************************
  60.  
  61.                 RsReset
  62.  
  63. Amiga_Name        rs.b        22
  64. Amiga_Length        rs.w        1    * Taille codée en words
  65. Amiga_Fine_Tune    rs.b        1    * de 0 à 15  =  0 à 7 et -8 à -1
  66. Amiga_Volume        rs.b        1    * de 0 à 64
  67. Amiga_Repeat_Start    rs.w        1
  68. Amiga_Repeat_Length    rs.w        1
  69.  
  70. Amiga_Size        rs.b        1    * 30 octets
  71.  
  72.  
  73.                 RsReset
  74.  
  75. Voice_Sample_Start            rs.l        1
  76. Voice_Sample_Offset            rs.l        1
  77. Voice_Sample_Position        rs.l        1
  78. Voice_Sample_Length            rs.l        1
  79. Voice_Sample_Loop_Length        rs.l        1
  80. Voice_Sample_Volume            rs.w        1
  81. Voice_Sample_Period            rs.w        1
  82. Voice_Sample_Fine_Tune        rs.w        1
  83. Voice_Sample_Frac            rs.w        1
  84.  
  85. Voice_Start                rs.l        1
  86. Voice_Volume                rs.w        1
  87. Voice_Period                rs.w        1
  88. Voice_Wanted_Period            rs.w        1
  89.  
  90. Voice_Note                rs.w        1
  91. Voice_Sample                rs.b        1
  92. Voice_Command                rs.b        1
  93. Voice_Parameters            rs.b        1
  94.  
  95. Voice_Tone_Port_Direction    rs.b        1
  96. Voice_Tone_Port_Speed        rs.b        1
  97. Voice_Glissando_Control        rs.b        1
  98. Voice_Vibrato_Command        rs.b        1
  99. Voice_Vibrato_Position        rs.b        1
  100. Voice_Vibrato_Control        rs.b        1
  101. Voice_Tremolo_Command        rs.b        1
  102. Voice_Tremolo_Position        rs.b        1
  103. Voice_Tremolo_Control        rs.b        1
  104.  
  105. Voice_Size                rs.b        1
  106.  
  107. ***********************************************************************
  108. ***********                                        ***********
  109. ***********    Routines de gestion de Base du Replay :        ***********
  110. ***********                                        ***********
  111. ***********    Jouer/arrêter le module, Position            ***********
  112. ***********    précédente/suivante, Saut à une Position    ***********
  113. ***********                                        ***********
  114. ***********************************************************************
  115.  
  116. ; Jouer le module
  117.  
  118. MGTK_Play_Music
  119.         movem.l    d3-d7/a2-a6,-(sp)
  120.  
  121.         move.b    #125,MGTK_Music_Tempo
  122.         move.b    #6,MGTK_Music_Speed    
  123.         move.b    #6,MGTK_Music_Counter
  124.  
  125.         bsr        MGTK_Search_Values_for_Tempo
  126.  
  127.         move.w    #0,MGTK_Music_Position
  128.         move.w    #-1,MGTK_Pattern_Position
  129.         sf        MGTK_Pattern_Loop_Flag
  130.         clr.w    MGTK_Pattern_Loop_Counter
  131.         clr.w    MGTK_Pattern_Loop_Position
  132.         sf        MGTK_Pattern_Break_Flag
  133.         clr.w    MGTK_Pattern_Break_Position
  134.         sf        MGTK_Position_Jump_Flag
  135.         clr.w    MGTK_Position_Jump_Position
  136.         clr.b    MGTK_Pattern_Delay_Time
  137.  
  138.         bsr        MGTKClearVoices
  139.  
  140.         sf        MGTK_Replay_Paused
  141.         sf        MGTK_Replay_Stopped
  142.  
  143.         movem.l    (sp)+,d3-d7/a2-a6
  144.         bra        MGTK_Init_IT
  145.  
  146. ;
  147. ; Met la Musique en Pause
  148. ;
  149. MGTK_Pause_Music
  150.         tst.b    MGTK_Replay_Stopped(pc)
  151.         bne.s    MGTK_Pause_Music_Ret
  152.         tst.b    MGTK_Replay_Paused(pc)
  153.         seq        MGTK_Replay_Paused
  154.         tst.b    MGTK_Replay_Paused(pc)
  155.         bne        MGTK_Stop_IT
  156.         bra        MGTK_Init_IT
  157. MGTK_Pause_Music_Ret
  158.         rts
  159. ;
  160. ; Stoppe la musique
  161. ;
  162. MGTK_Stop_Music
  163.         sf        MGTK_Replay_Paused
  164.         st        MGTK_Replay_Stopped
  165.         bra        MGTK_Stop_IT
  166.  
  167. ; Sauter à une position particulière
  168. ; En Entrée :
  169. ; d0.w = Numéro de la position
  170.  
  171. MGTK_Play_Position
  172.         cmp.w    MGTK_Music_Length(pc),d0
  173.         blo.s    MGTK_Play_Position_Ok
  174.         moveq.l    #0,d0
  175. MGTK_Play_Position_Ok
  176.         move.w    d0,MGTK_Position_Jump_Position
  177.         st        MGTK_Position_Jump_Flag
  178.         rts
  179.  
  180. ;
  181. ; Position précédente
  182. ;
  183. MGTK_Previous_Position
  184.         move.w    MGTK_Music_Position(pc),d0
  185.         beq.s    MGTK_Previous_Position_Skip
  186.         subq.w    #1,d0
  187. MGTK_Previous_Position_Skip
  188.         move.w    d0,MGTK_Position_Jump_Position
  189.         st        MGTK_Position_Jump_Flag
  190.         rts
  191. ;
  192. ; Position suivante
  193. ;
  194. MGTK_Next_Position
  195.         move.w    MGTK_Music_Position(pc),d0
  196.         cmp.w    MGTK_Music_Length,d0
  197.         beq.s    MGTK_Next_Position_Skip
  198.         addq.w    #1,d0
  199. MGTK_Next_Position_Skip
  200.         move.w    d0,MGTK_Position_Jump_Position
  201.         st        MGTK_Position_Jump_Flag
  202.         rts
  203.  
  204. ;
  205. ; Remet les voies à zéro
  206. ;
  207. MGTK_Clear_Voices
  208.         movem.l    d3-d4/d7/a5-a6,-(sp)
  209.         bsr.s    MGTKClearVoices
  210.         movem.l    (sp)+,d3-d4/d7/a5-a6
  211.         rts
  212.                 
  213. MGTKClearVoices
  214.         move.w    #1234,d4
  215.  
  216.         lea.l    MGTK_Voices(pc),a6
  217.         moveq.l    #4-1,d7
  218.  
  219. MGTK_Clear_A_Voice
  220.         clr.l    (a6)+
  221.         clr.l    (a6)+
  222.         clr.l    (a6)+
  223.         clr.l    (a6)+
  224.         clr.l    (a6)+
  225.         clr.w    (a6)+
  226.         move.w    d4,(a6)+
  227.         clr.w    (a6)+
  228.         clr.w    (a6)+
  229.  
  230.         clr.l    (a6)+
  231.         clr.w    (a6)+
  232.         move.w    d4,(a6)+
  233.         clr.w    (a6)+
  234.  
  235.         clr.l    (a6)+
  236.         clr.l    (a6)+
  237.         clr.l    (a6)+
  238.         clr.w    (a6)+
  239.         dbra        d7,MGTK_Clear_A_Voice
  240.         rts
  241.  
  242. ***********************************************************************
  243. ***********    Initialisations du Module et des Samples    ***********
  244. ***********************************************************************
  245.  
  246. ; En Entrée :
  247. ; a0 = Adresse du Module
  248. ; a1 = Adresse de la fin de la zone de Travail (WorkSpace)
  249. ;
  250. ; En Sortie :
  251. ; d0 = 0 si tout c'est bien passé
  252. ;     -3 si pas assez de place pour préparer des Samples
  253.  
  254. MGTK_Init_Module_Samples
  255.         movem.l    d3-d7/a2-a6,-(sp)
  256.  
  257.         sf        MGTK_Replay_Paused
  258.         st        MGTK_Replay_Stopped
  259.  
  260.         move.l    a0,MGTK_Module_Adr
  261.         move.l    a1,MGTK_WorkSpace_Adr
  262.  
  263.         lea.l    20+31*30+2(a0),a5        ; Par défaut
  264.         lea.l    4+128(a5),a6            ; Type
  265.         moveq.l    #31,d0                ; 31 instruments
  266.         moveq.l    #64,d2                ; 64 lignes par pattern
  267.         sf        MGTK_Old_Module
  268.  
  269.         move.l    $438(a0),d3            ; ModFile Chunk
  270.  
  271.         cmp.l    #'M.K.',d3
  272.         beq.s    MGTK_Format_Ok
  273.         cmp.l    #'M!K!',d3
  274.         beq.s    MGTK_Format_Ok
  275.         cmp.l    #'M&K&',d3
  276.         beq.s    MGTK_Format_Ok
  277.         cmp.l    #'FA04',d3
  278.         beq.s    MGTK_Format_Digital
  279.         cmp.l    #'FLT4',d3
  280.         beq.s    MGTK_Format_Ok
  281.         cmp.l    #'RASP',d3
  282.         beq.s    MGTK_Format_Ok
  283.  
  284. ; Si rien de spécial alors c'est un ancien module 15 instruments
  285.         lea.l    20+15*30+2(a0),a5
  286.         lea.l    128(a5),a6
  287.         moveq.l    #15,d0
  288.         st        MGTK_Old_Module
  289.         bra.s    MGTK_Format_Ok
  290.  
  291. MGTK_Format_Digital
  292.         move.w    (a6)+,d2
  293.         addq.l    #2,a6
  294.  
  295. MGTK_Format_Ok
  296.         move.l    a5,MGTK_Sequence_Adr    ; Adresse de la séquence
  297.         move.l    a6,MGTK_Patterns_Adr    ; Adresse des patterns
  298.         move.w    d0,MGTK_Nb_Samples        ; Nombre d'instruments
  299.         move.w    d2,MGTK_Pattern_Length
  300.  
  301.         moveq.l    #4*4,d1
  302.         move.w    d1,MGTK_Line_Size        ; Taille d'une 'ligne'
  303.         mulu.w    d2,d1
  304.         move.w    d1,MGTK_Pattern_Size    ; Taille d'un pattern
  305.  
  306.         move.b    -2(a5),d0
  307.         move.w    d0,MGTK_Music_Length    ; Longueur du module
  308.         move.b    -1(a5),d2
  309.         cmp.b    d0,d2                ; le Restart
  310.         blo.s    MGTK_Restart_Ok        ; est-il cohérent ?
  311.         moveq.l    #0,d2                ; si non, Restart = 0
  312. MGTK_Restart_Ok
  313.         move.w    d2,MGTK_Music_Restart
  314.  
  315.         moveq.l    #128-1,d0                ; Parcours la séquence
  316.         moveq.l    #0,d1                ; jusqu'à la dernière
  317. MGTK_Sequence_Loop                        ; position
  318.         move.b    (a5)+,d2                ; No Pattern
  319.         cmp.b    d1,d2                ; Plus grand
  320.         blo.s    MGTK_Seq_No_Max        ; que le maximum ?
  321.         move.b    d2,d1                ; alors Nouveau maximum
  322. MGTK_Seq_No_Max
  323.         dbra        d0,MGTK_Sequence_Loop
  324.  
  325.         addq.w    #1,d1                ; Nombre de patterns
  326.         mulu.w    MGTK_Pattern_Size(pc),d1    ; Taille totale
  327.  
  328.         movea.l    MGTK_Patterns_Adr(pc),a1    ; Adresse du début
  329.         lea.l    (a1,d1.l),a1            ; Des samples
  330.  
  331.         lea.l    20(a0),a2                ; Pointe sur Infos Samples
  332.         moveq.l    #0,d1
  333.         move.w    MGTK_Nb_Samples(pc),d7
  334.         subq.w    #1,d7
  335.  
  336. MGTK_Total_Length
  337.         moveq.l    #0,d3                ; Longueur
  338.         move.w    Amiga_Length(a2),d3        ; du sample
  339.         add.l    d3,d3                ; * 2 car stocké en words
  340.         add.l    d3,d1                ; Ajoute au total
  341.         lea.l    Amiga_Size(a2),a2        ; Instrument suivant
  342.         dbra        d7,MGTK_Total_Length    ; Calcule longueur totale
  343.  
  344.  
  345. ; Recopie les samples à la fin de la zone de travail temporaire
  346. ; pour justement pouvoir travailler dessus, les préparer au bouclage
  347.  
  348.         movea.l    MGTK_WorkSpace_Adr(pc),a4
  349.         lea.l    (a1,d1.l),a3            ; Adresse fin des samples
  350. MGTK_Move_Samples
  351.         move.w    -(a3),-(a4)
  352.         subq.l    #2,d1
  353.         bne.s    MGTK_Move_Samples
  354.  
  355. ; Maintenant, on bosse sur les samples
  356.         lea.l    20(a0),a0                ; Pointe sur 1er Sample
  357.         lea.l    MGTK_Samples_Adr(pc),a2    ; Adresse des samples
  358.  
  359.         move.w    MGTK_Nb_Samples(pc),d7
  360.         subq.w    #1,d7
  361.  
  362. MGTK_Init_Samples
  363.         clr.l    (a2)+                    ; Adresse Nulle par défaut
  364.         move.w    Amiga_Length(a0),d3            ; Longueur Nulle ?
  365.         beq.s    MGTK_Init_Next_Sample        ; Alors pas d'instrument
  366.  
  367.         move.l    a1,-4(a2)                    ; Sinon Note Adresse
  368.  
  369.         move.w    Amiga_Repeat_Length(a0),d5    ; Longueur de Boucle
  370.         cmp.w    #1,d5                    ; supérieure à 1 ?
  371.         bhi.s    MGTK_Repeat_Length            ; Alors il y a bouclage
  372.  
  373. MGTK_No_Repeat_Length
  374.         subq.w    #1,d3
  375. MGTK_Copy_Sample_Loop
  376.         move.w    (a4)+,(a1)+                ; Recopie simplement
  377.         dbra        d3,MGTK_Copy_Sample_Loop        ; le sample
  378.  
  379.         move.w    #672/4-1,d0
  380. MGTK_Clear_End_Sample_Loop                    ; et met du vide après
  381.         clr.l    (a1)+                    ; car ne boucle pas
  382.         dbra        d0,MGTK_Clear_End_Sample_Loop
  383.  
  384.         clr.w    Amiga_Repeat_Start(a0)
  385.         clr.w    Amiga_Repeat_Length(a0)
  386.         bra.s    MGTK_Init_Next_Sample
  387.  
  388.  
  389. MGTK_Repeat_Length
  390.         move.w    Amiga_Repeat_Start(a0),d4    ; Début de boucle ?
  391.         beq.s    MGTK_No_Repeat_Start        ; Si Non, Jump
  392.  
  393.         move.w    d4,d0
  394.         subq.w    #1,d0
  395. MGTK_Copy_Sample_Start
  396.         move.w    (a4)+,(a1)+                ; Recopie la partie
  397.         dbra        d0,MGTK_Copy_Sample_Start    ; avant la boucle
  398.  
  399. MGTK_No_Repeat_Start
  400.         movea.l    a1,a3                    ; Note début de Boucle
  401.         move.w    d5,d0                    ; Longueur de la Boucle
  402.         subq.w    #1,d0
  403. MGTK_Copy_First_Loop
  404.         move.w    (a4)+,(a1)+                ; Recopie la boucle
  405.         dbra        d0,MGTK_Copy_First_Loop        ; une première fois
  406.  
  407.         move.w    #672/2-1,d0
  408. MGTK_Make_Loop_Buffer
  409.         move.w    (a3)+,(a1)+                ; Fait le buffer
  410.         dbra        d0,MGTK_Make_Loop_Buffer        ; de bouclage
  411.  
  412.         sub.w    d5,d3
  413.         sub.w    d4,d3                ; Saute la partie après
  414.         lea.l    (a4,d3.w*2),a4            ; la boucle qui ne sert à rien
  415.  
  416.         add.w    d5,d4
  417.         move.w    d4,Amiga_Length(a0)
  418.         move.w    d5,Amiga_Repeat_Length(a0)
  419.  
  420. MGTK_Init_Next_Sample
  421.         cmpa.l    a4,a1
  422.         bhi.s    MGTK_Init_Samples_Error
  423.  
  424.         lea.l    Amiga_Size(a0),a0
  425.         dbra        d7,MGTK_Init_Samples
  426.  
  427.         move.l    a1,MGTK_Module_End_Adr
  428.  
  429.         bsr        MGTKClearVoices
  430.  
  431.         lea.l    MGTK_Volume_Table+65*256(pc),a0
  432.         moveq.l    #65-1,d7
  433. MGTK_Make_Volume_Table
  434.         move.w    #256-1,d6
  435. MGTK_Make_Volume_Table_Loop
  436.         move.w    d6,d0
  437.         ext.w    d0
  438.         muls.w    d7,d0
  439.         asr.w    #6,d0
  440.         move.b    d0,-(a0)
  441.         dbra        d6,MGTK_Make_Volume_Table_Loop
  442.         dbra        d7,MGTK_Make_Volume_Table
  443.  
  444.         movem.l    (sp)+,d3-d7/a2-a6
  445.         moveq.l    #0,d0
  446.         rts
  447.  
  448. MGTK_Init_Samples_Error
  449.         movem.l    (sp)+,d3-d7/a2-a6
  450.         moveq.l    #-3,d0
  451.         rts
  452.  
  453. ***********************************************************************
  454. ***********        Initialisations Système Sonore        ***********
  455. ***********************************************************************
  456.  
  457. MGTK_Init_Sound
  458.         pea.l    (a2)
  459.         pea.l    MGTKInitSound(pc)
  460.         move.w    #38,-(sp)            ; Supexec
  461.         trap        #14                ; XBios
  462.         addq.l    #6,sp
  463.         movea.l    (sp)+,a2
  464.         rts
  465. MGTKInitSound
  466. * Sélectionne Interruption Timer A en PlayBack
  467.         move.b    #%0100,$ffff8900.w
  468. * Stoppe le DMA et sélectionne registres en PlayBack
  469.         clr.b    $ffff8901.w
  470. * Une seule piste et DAC sur piste 0
  471.         clr.b    $ffff8920.w
  472. * 8 bits Stereo
  473.         clr.b    $ffff8921.w
  474. * Source DMA-Play sur Horloge Interne 25.175 MHz, Handshaking Off
  475.         move.w    #%0001,$ffff8930.w
  476. * Destination DAC connecté sur source DMA-Play, Handshaking Off
  477.         move.w    #%0000111111111111,$ffff8932.w
  478. * Fréquence
  479.         move.b    #Freq_No,$ffff8935.w
  480. * Seulement Matrice et pas le PSG-Yamaha
  481.         move.b    #%10,$ffff8937.w
  482.         rts
  483.  
  484. MGTK_Save_Sound
  485.         pea.l    (a2)
  486.         pea.l    MGTKSaveSound(pc)
  487.         move.w    #38,-(sp)            ; Supexec
  488.         trap        #14                ; XBios
  489.         addq.l    #6,sp
  490.         movea.l    (sp)+,a2
  491.         rts
  492. MGTKSaveSound
  493.         lea.l    MGTK_Old_Sound_System(pc),a0
  494.         move.w    $ffff8900.w,(a0)+        ; Interruptions, Son DMA
  495.         bclr.b    #7,$ffff8901.w            ; Registres PlayBack
  496.         move.b    $ffff8903.w,(a0)+        ; Start - High
  497.         move.b    $ffff8905.w,(a0)+        ; Start - Med
  498.         move.b    $ffff8907.w,(a0)+        ; Start - Low
  499.         move.b    $ffff890f.w,(a0)+        ; End - High
  500.         move.b    $ffff8911.w,(a0)+        ; End - Med
  501.         move.b    $ffff8913.w,(a0)+        ; End - Low
  502.         bset.b    #7,$ffff8901.w            ; Registres Record
  503.         move.b    $ffff8903.w,(a0)+        ; Start - High
  504.         move.b    $ffff8905.w,(a0)+        ; Start - Med
  505.         move.b    $ffff8907.w,(a0)+        ; Start - Low
  506.         move.b    $ffff890f.w,(a0)+        ; End - High
  507.         move.b    $ffff8911.w,(a0)+        ; End - Med
  508.         move.b    $ffff8913.w,(a0)+        ; End - Low
  509.  
  510.         move.w    $ffff8920.w,(a0)+        ; Nb Voies, 8/16, Mono/Stereo
  511.         move.w    $ffff8930.w,(a0)+        ; Matrice : Sources
  512.         move.w    $ffff8932.w,(a0)+        ; Matrice : Destinations
  513.         move.w    $ffff8934.w,(a0)+        ; Prescales d'horloge
  514.         move.w    $ffff8936.w,(a0)+        ; Nb Voies Record,source ADDERIN
  515.         move.w    $ffff8938.w,(a0)+        ; Source ADC + Volumes entrées
  516.         move.w    $ffff893a.w,(a0)+        ; Volumes de Sortie
  517.         rts
  518.  
  519. MGTK_Restore_Sound
  520.         pea.l    (a2)
  521.         pea.l    MGTKRestoreSound(pc)
  522.         move.w    #38,-(sp)            ; Supexec
  523.         trap        #14                ; XBios
  524.         addq.l    #6,sp
  525.         movea.l    (sp)+,a2
  526.         rts
  527. MGTKRestoreSound
  528.         lea.l    MGTK_Old_Sound_System(pc),a0
  529.         move.w    (a0)+,d0
  530.         bclr.b    #7,$ffff8901.w            ; Registres PlayBack
  531.         move.b    (a0)+,$ffff8903.w        ; Start - High
  532.         move.b    (a0)+,$ffff8905.w        ; Start - Med
  533.         move.b    (a0)+,$ffff8907.w        ; Start - Low
  534.         move.b    (a0)+,$ffff890f.w        ; End - High
  535.         move.b    (a0)+,$ffff8911.w        ; End - Med
  536.         move.b    (a0)+,$ffff8913.w        ; End - Low
  537.         bset.b    #7,$ffff8901.w            ; Registres Record
  538.         move.b    (a0)+,$ffff8903.w        ; Start - High
  539.         move.b    (a0)+,$ffff8905.w        ; Start - Med
  540.         move.b    (a0)+,$ffff8907.w        ; Start - Low
  541.         move.b    (a0)+,$ffff890f.w        ; End - High
  542.         move.b    (a0)+,$ffff8911.w        ; End - Med
  543.         move.b    (a0)+,$ffff8913.w        ; End - Low
  544.         move.w    d0,$ffff8900.w            ; Interruptions, Son DMA
  545.  
  546.         move.w    (a0)+,$ffff8920.w        ; Nb Voies, 8/16, Mono/Stereo
  547.         move.w    (a0)+,$ffff8930.w        ; Matrice : Sources
  548.         move.w    (a0)+,$ffff8932.w        ; Matrice : Destinations
  549.         move.w    (a0)+,$ffff8934.w        ; Prescales d'horloge
  550.         move.w    (a0)+,$ffff8936.w        ; Nb Voies Record,source ADDERIN
  551.         move.w    (a0)+,$ffff8938.w        ; Source ADC + Volumes entrées
  552.         move.w    (a0)+,$ffff893a.w        ; Volumes de Sortie
  553.  
  554.         move.b    #$80+$14,$ffffa201.w    ; Efface Buffer Sample DSP
  555.         rts
  556.  
  557. ***********************************************************************
  558. ***********        Sauvegardes système sonore            ***********
  559. ***********************************************************************
  560.  
  561. MGTK_Old_Sound_System
  562.             ds.w        1            ; Interruptions, Son DMA
  563.             ds.b        3            ; Playback Start
  564.             ds.b        3            ; Playback End
  565.             ds.b        3            ; Record Start
  566.             ds.b        3            ; Record End
  567.             ds.w        1            ; Nb Voies, 8/16, Mono/Stereo
  568.             ds.w        1            ; Matrice : Sources
  569.             ds.w        1            ; Matrice : Destinations
  570.             ds.w        1            ; Prescales d'horloge
  571.             ds.w        1            ; Nb Voies Record,source ADDERIN
  572.             ds.w        1            ; Source ADC + Volumes entrées
  573.             ds.w        1            ; Volumes de Sortie
  574.  
  575. ***********************************************************************
  576. ***********           Controle des Interruptions            ***********
  577. ***********************************************************************
  578.  
  579. ; Installe l'interruption Timer A du Player
  580. ; Et Active le DMA
  581.  
  582. MGTK_Init_IT
  583.         pea.l    (a2)
  584.         pea.l    MGTK_Replay_Timer(pc)        ; Adresse Vecteur
  585.         moveq.l    #0,d0
  586.         move.w    #1,-(sp)                    ; 1 interruption
  587.         move.w    #8,-(sp)                    ; Mode Event Count
  588.         clr.w    -(sp)                    ; Timer No 0
  589.         move.w    #31,-(sp)                    ; Xbtimer
  590.         trap        #14                        ; XBios
  591.         lea.l    12(sp),sp
  592.         pea.l    MGTKInitDMA(pc)
  593.         move.w    #38,-(sp)                    ; Supexec
  594.         trap        #14                        ; XBios
  595.         addq.l    #6,sp
  596.         movea.l    (sp)+,a2
  597.         rts
  598. MGTKInitDMA
  599.         move.l    MGTK_Adr_Buffer1(pc),d0
  600.         move.l    d0,d1
  601.         addq.l    #8,d1
  602. * Début du Sample
  603.         move.b    d0,$ffff8907.w
  604.         lsr.w    #8,d0
  605.         move.l    d0,$ffff8902.w
  606. * Fin du Sample
  607.         move.b    d1,$ffff8913.w
  608.         lsr.w    #8,d1
  609.         move.l    d1,$ffff890e.w
  610. * Lance Lecture DMA Bouclée
  611.         move.b    #%11,$ffff8901.w
  612.         rts
  613.  
  614. ; Enlève l'interruption Timer A du Player
  615. ; Et Stoppe le DMA
  616.  
  617. MGTK_Stop_IT
  618.         pea.l    (a2)
  619.         clr.l    -(sp)
  620.         clr.l    -(sp)                    ; Stoppe le
  621.         clr.w    -(sp)                    ; Timer A
  622.         move.w    #31,-(sp)                    ; Xbtimer
  623.         trap        #14                        ; XBios
  624.         lea.l    12(sp),sp
  625.         pea.l    MGTKStopDMA(pc)
  626.         move.w    #38,-(sp)                    ; Supexec
  627.         trap        #14                        ; XBios
  628.         addq.l    #6,sp
  629.         movea.l    (sp)+,a2
  630.         rts
  631. MGTKStopDMA
  632.         clr.b    $ffff8901.w
  633.         rts
  634.  
  635. ***********************************************************************
  636. ***********       Interruptions du Replay Soundtracker        ***********
  637. ***********************************************************************
  638.  
  639. MGTK_Replay_Timer
  640.         move.w    #$2300,sr
  641.         bclr.b    #5,$fffffa0f.w            ; à Cause du mode SEI
  642.  
  643.         SaveColor
  644.         CPUTimeColor        #$dd550088
  645.         movem.l    d0-d7/a0-a6,-(sp)
  646.  
  647.         move.l    MGTK_Adr_Buffer2(pc),d0
  648.         move.l    MGTK_Adr_Buffer1(pc),MGTK_Adr_Buffer2
  649.         move.l    d0,MGTK_Adr_Buffer1
  650.  
  651.         moveq.l    #0,d1
  652.         move.w    MGTK_IT_Nb_Samples(pc),d1
  653.         lsl.w    #2,d1
  654.         add.l    d0,d1
  655.  
  656. * Début du Sample
  657.         move.b    d0,$ffff8907.w
  658.         lsr.w    #8,d0
  659.         move.l    d0,$ffff8902.w
  660.  
  661. * Fin du Sample
  662.         move.b    d1,$ffff8913.w
  663.         lsr.w    #8,d1
  664.         move.l    d1,$ffff890e.w
  665.  
  666. * Relance le DMA
  667.         move.b    #%11,$ffff8901.w
  668.  
  669. * Calcule Voie 1 à Gauche et 2 à Droite
  670.         lea.l    MGTK_Voices(pc),a5
  671.         lea.l    Voice_Size(a5),a6
  672.         movea.l    MGTK_Adr_Buffer1(pc),a0
  673.         bsr.s    MGTK_Calc_Voices
  674. * Calcule Voie 4 à Gauche et 3 à Droite
  675.         lea.l    3*Voice_Size(a5),a5
  676.         lea.l    -Voice_Size(a5),a6
  677.         movea.l    MGTK_Adr_Buffer1(pc),a0
  678.         addq.l    #2,a0
  679.         bsr.s    MGTK_Calc_Voices
  680.  
  681.         CPUTimeColor        #$99990099
  682.         bsr        MGTK_Play_Patterns
  683.  
  684.         movem.l    (sp)+,d0-d7/a0-a6
  685.         RestoreColor
  686.         rte
  687.  
  688. * Rééchantillone deux voies
  689.  
  690. MGTK_Calc_Voices
  691.         movea.l    Voice_Sample_Position(a5),a1
  692.         move.l    Voice_Sample_Start(a5),d0
  693.         bne.s    MGTK_Spl_Adr_Ok1
  694.         move.l    #MGTK_Empty_Buffer,d0
  695.         clr.l    Voice_Sample_Position(a5)
  696.         suba.w    a1,a1
  697. MGTK_Spl_Adr_Ok1
  698.         adda.l    d0,a1
  699.         movea.l    Voice_Sample_Position(a6),a3
  700.         move.l    Voice_Sample_Start(a6),d0
  701.         bne.s    MGTK_Spl_Adr_Ok2
  702.         move.l    #MGTK_Empty_Buffer,d0
  703.         clr.l    Voice_Sample_Position(a6)
  704.         suba.w    a3,a3
  705. MGTK_Spl_Adr_Ok2
  706.         adda.l    d0,a3
  707.  
  708.         move.w    Voice_Sample_Volume(a5),d0
  709.         lsl.l    #8,d0
  710.         lea.l    (MGTK_Volume_Table,pc,d0.w),a2
  711.         move.w    Voice_Sample_Volume(a6),d0
  712.         lsl.l    #8,d0
  713.         lea.l    (MGTK_Volume_Table,pc,d0.w),a4
  714.  
  715.         move.l    #$10000*428/Freq_Replay*8363,d0
  716.         move.l    d0,d2
  717.         moveq.l    #0,d5
  718.         move.w    Voice_Sample_Period(a5),d5
  719.         divu.l    d5,d0
  720.         move.w    Voice_Sample_Period(a6),d5
  721.         divu.l    d5,d2
  722.         move.w    d0,d6
  723.         move.w    d2,d0
  724.         move.w    d6,d2
  725.         swap.w    d0
  726.         swap.w    d2
  727.         moveq.l    #0,d1
  728.         move.w    Voice_Sample_Frac(a6),d1
  729.         swap.w    d1
  730.         moveq.l    #0,d3
  731.         move.w    Voice_Sample_Frac(a5),d3
  732.         swap.w    d3
  733.  
  734.         moveq.l    #0,d4
  735.         moveq.l    #0,d5
  736.         move.w    MGTK_IT_Nb_Samples(pc),d7
  737.         subq.w    #1,d7
  738. MGTK_Calc_Loop
  739.         move.b    (a1,d1.w),d4
  740.         addx.l    d0,d1
  741.         move.b    (a3,d3.w),d5
  742.         move.w    (a2,d4.w),d6
  743.         addx.l    d2,d3
  744.         move.b    (a4,d5.w),d6
  745.         move.w    d6,(a0)
  746.         addq.l    #4,a0
  747.         dbra        d7,MGTK_Calc_Loop
  748.  
  749.         swap.w    d1
  750.         move.w    d1,Voice_Sample_Frac(a6)
  751.         clr.w    d1
  752.         swap.w    d1
  753.         add.l    Voice_Sample_Position(a5),d1
  754.  
  755.         move.l    Voice_Sample_Loop_Length(a5),d0
  756.         bne.s    MGTK_Replay_Loop1
  757.  
  758. MGTK_Replay_No_Loop1
  759.         cmp.l    Voice_Sample_Length(a5),d1    ; A-t'on dépassé la fin
  760.         blo.s    MGTK_Replay_Pos_Ok1            ; du Sample ?
  761.  
  762.         clr.l    Voice_Sample_Start(a5)        ; Oui, alors sample
  763.         bra.s    MGTK_Replay_Pos_Ok1            ; désactivé
  764.  
  765. MGTK_Replay_Loop1
  766.         cmp.l    Voice_Sample_Length(a5),d1    ; A-t'on dépassé la
  767.         blo.s    MGTK_Replay_Pos_Ok1            ; fin de la boucle ?
  768.  
  769.         sub.l    d0,d1                    ; Si oui, reboucle
  770.         bra.s    MGTK_Replay_Loop1            ; tant qu'il faut
  771.  
  772. MGTK_Replay_Pos_Ok1
  773.         move.l    d1,Voice_Sample_Position(a5)    ; Nouvelle position
  774.  
  775.         swap.w    d3
  776.         move.w    d3,Voice_Sample_Frac(a5)
  777.         clr.w    d3
  778.         swap.w    d3
  779.         add.l    Voice_Sample_Position(a6),d3
  780.  
  781.         move.l    Voice_Sample_Loop_Length(a6),d0
  782.         bne.s    MGTK_Replay_Loop2
  783.  
  784. MGTK_Replay_No_Loop2
  785.         cmp.l    Voice_Sample_Length(a6),d3    ; A-t'on dépassé la fin
  786.         blo.s    MGTK_Replay_Pos_Ok2            ; du Sample ?
  787.  
  788.         clr.l    Voice_Sample_Start(a6)        ; Oui, alors sample
  789.         bra.s    MGTK_Replay_Pos_Ok2            ; désactivé
  790.  
  791. MGTK_Replay_Loop2
  792.         cmp.l    Voice_Sample_Length(a6),d3    ; A-t'on dépassé la
  793.         blo.s    MGTK_Replay_Pos_Ok2            ; fin de la boucle ?
  794.  
  795.         sub.l    d0,d3                    ; Si oui, reboucle
  796.         bra.s    MGTK_Replay_Loop2            ; tant qu'il faut
  797.  
  798. MGTK_Replay_Pos_Ok2
  799.         move.l    d3,Voice_Sample_Position(a6)    ; Nouvelle position
  800.         rts
  801.  
  802. MGTK_Adr_Buffer1
  803.         dc.l        MGTK_Buffer1
  804. MGTK_Adr_Buffer2
  805.         dc.l        MGTK_Buffer2
  806.  
  807. ***********************************************************************
  808. ***********            Gestion du Soundtrack            ***********
  809. ***********************************************************************
  810.  
  811. MGTK_Play_Patterns
  812.         addq.b    #1,MGTK_Music_Counter
  813.         move.b    MGTK_Music_Counter(pc),d0
  814.         cmp.b    MGTK_Music_Speed(pc),d0
  815.         blo        MGTK_No_New_Note
  816.  
  817.         clr.b    MGTK_Music_Counter
  818.  
  819.         tst.b    MGTK_Pattern_Break_Flag(pc)
  820.         bne.s    MGTK_New_Pattern
  821.  
  822.         tst.b    MGTK_Pattern_Delay_Time(pc)
  823.         beq.s    MGTK_No_Pattern_Delay
  824.  
  825.         subq.b    #1,MGTK_Pattern_Delay_Time
  826.         bra        MGTK_No_New_Note
  827.  
  828. MGTK_No_Pattern_Delay
  829.         tst.b    MGTK_Pattern_Loop_Flag(pc)
  830.         beq.s    MGTK_No_Pattern_Loop
  831.  
  832.         move.w    MGTK_Pattern_Loop_Position(pc),MGTK_Pattern_Position
  833.         sf        MGTK_Pattern_Loop_Flag
  834.         bra        MGTK_New_Notes
  835.  
  836. MGTK_No_Pattern_Loop
  837.         tst.b    MGTK_Position_Jump_Flag(pc)
  838.         beq.s    MGTK_New_Line
  839.  
  840.         move.w    MGTK_Position_Jump_Position(pc),d0
  841.         sf        MGTK_Position_Jump_Flag
  842.         clr.w    MGTK_Pattern_Break_Position
  843.         bra.s    MGTK_New_Position
  844.  
  845. MGTK_New_Line
  846.         addq.w    #1,MGTK_Pattern_Position
  847.         move.w    MGTK_Pattern_Position(pc),d0
  848.         cmp.w    MGTK_Pattern_Length(pc),d0
  849.         blo.s    MGTK_New_Notes
  850.  
  851. MGTK_New_Pattern
  852.         move.w    MGTK_Music_Position(pc),d0
  853.         addq.w    #1,d0
  854.  
  855. MGTK_New_Position
  856.         move.w    MGTK_Pattern_Break_Position(pc),MGTK_Pattern_Position
  857.         clr.w    MGTK_Pattern_Break_Position
  858.         sf        MGTK_Pattern_Break_Flag
  859.  
  860.         cmp.w    MGTK_Music_Length(pc),d0
  861.         blo.s    MGTK_No_Restart
  862.  
  863.         move.w    MGTK_Music_Restart(pc),d0
  864.         bne.s    MGTK_No_Restart_Tempo
  865.  
  866.         move.b    #125,MGTK_Music_Tempo
  867.         move.b    #6,MGTK_Music_Speed
  868.         bsr        MGTK_Search_Values_for_Tempo
  869.  
  870. MGTK_No_Restart_Tempo
  871.         tst.b    MGTK_Restart_Loop(pc)
  872.         bne.s    MGTK_No_Restart
  873.  
  874.         st        MGTK_Restart_Done
  875.         sf        MGTK_Replay_Paused
  876.         st        MGTK_Replay_Stopped
  877.         clr.b    $ffff8901.w            ; Stoppe DMA PlayBack
  878.         clr.b    $fffffa19.w            ; Coupe Timer
  879.         bclr.b    #5,$fffffa07.w            ; Désautorise Timer
  880.         bclr.b    #5,$fffffa13.w            ; DéMaske Timer
  881.  
  882. MGTK_No_Restart
  883.         move.w    d0,MGTK_Music_Position
  884.  
  885. MGTK_New_Notes
  886.         movea.l    MGTK_Module_Adr(pc),a5
  887.         adda.w    #20,a5                ; Pointe sur infos samples
  888.         movea.l    MGTK_Sequence_Adr(pc),a0
  889.         move.w    MGTK_Music_Position(pc),d1
  890.         moveq.l    #0,d0
  891.         move.b    (a0,d1.w),d0
  892.         mulu.w    MGTK_Pattern_Size(pc),d0
  893.         movea.l    MGTK_Patterns_Adr(pc),a4
  894.         adda.l    d0,a4                ; Pointe sur le Pattern
  895.         move.w    MGTK_Pattern_Position(pc),d0
  896.         mulu.w    MGTK_Line_Size(pc),d0
  897.         adda.w    d0,a4                ; Pointe sur la Bonne Ligne
  898.  
  899.         lea.l    MGTK_Voices(pc),a6
  900.         moveq.l    #4-1,d7
  901. MGTK_New_Notes_Loop
  902.         bsr.s    MGTK_Play_Voice
  903.  
  904.         lea.l    Voice_Size(a6),a6
  905.         dbra        d7,MGTK_New_Notes_Loop
  906.         rts
  907.  
  908.  
  909. MGTK_No_New_Note
  910.         lea.l    MGTK_Voices(pc),a6
  911.         moveq.l    #4-1,d7
  912. MGTK_No_New_Note_Loop
  913.  
  914.         moveq.l    #0,d0
  915.         move.b    Voice_Command(a6),d0
  916.         jsr        ([Jump_Table_2,d0.w*4])
  917.  
  918.         lea.l    Voice_Size(a6),a6
  919.         dbra        d7,MGTK_No_New_Note_Loop
  920.         rts
  921.  
  922.  
  923. MGTK_Play_Voice
  924.         move.w    (a4)+,d1
  925.         move.b    (a4)+,d2
  926.         move.b    (a4)+,Voice_Parameters(a6)
  927.  
  928.         move.w    d1,d0
  929.         and.w    #$0fff,d0
  930.         move.w    d0,Voice_Note(a6)
  931.         and.w    #$f000,d1
  932.         lsr.w    #8,d1
  933.         move.b    d2,d0
  934.         lsr.b    #4,d0
  935.         add.b    d1,d0
  936.         move.b    d0,Voice_Sample(a6)
  937.         and.b    #$0f,d2
  938.         move.b    d2,Voice_Command(a6)
  939.  
  940. MGTK_Check_Sample
  941.         moveq.l    #0,d2
  942.         move.b    Voice_Sample(a6),d2
  943.         beq.s    MGTK_No_New_Sample
  944.  
  945.         subq.w    #1,d2
  946.         lea.l    MGTK_Samples_Adr(pc),a1
  947.         move.l    (a1,d2.w*4),Voice_Start(a6)
  948.         clr.l    Voice_Sample_Offset(a6)
  949.         mulu.w    #Amiga_Size,d2
  950.         moveq.l    #0,d0
  951.         move.w    Amiga_Length(a5,d2.w),d0
  952.         lsl.l    d0
  953.         move.l    d0,Voice_Sample_Length(a6)
  954.         move.w    Amiga_Repeat_Length(a5,d2.w),d0
  955.         lsl.l    d0
  956.         move.l    d0,Voice_Sample_Loop_Length(a6)
  957.         moveq.l    #0,d0
  958.         move.b    Amiga_Volume(a5,d2.w),d0
  959.         move.w    d0,Voice_Volume(a6)
  960.         move.w    d0,Voice_Sample_Volume(a6)
  961.         move.b    Amiga_Fine_Tune(a5,d2.w),d0
  962.         and.w    #$0f,d0
  963.         mulu.w    #12*3*2,d0
  964.         move.w    d0,Voice_Sample_Fine_Tune(a6)
  965.  
  966. MGTK_No_New_Sample
  967.         tst.w    Voice_Note(a6)
  968.         beq        MGTK_Check_Efx_1
  969.  
  970. MGTK_Check_Efx_0
  971.         move.w    Voice_Command(a6),d0
  972.         and.w    #$0ff0,d0
  973.         cmp.w    #$0e50,d0
  974.         beq.s    MGTK_Do_Set_Fine_Tune
  975.  
  976.         move.b    Voice_Command(a6),d0
  977.         subq.b    #3,d0                ; 3 = Tone Portamento
  978.         beq        MGTK_Set_Tone_Portamento
  979.         subq.b    #2,d0                ; 5 = Tone Porta + Vol Slide
  980.         beq        MGTK_Set_Tone_Portamento
  981.         subq.b    #4,d0                ; 9 = Sample Offset
  982.         bne.s    MGTK_Set_Period
  983.  
  984.         bsr        MGTK_Sample_Offset
  985.         bra.s    MGTK_Set_Period
  986.  
  987. MGTK_Do_Set_Fine_Tune
  988.         bsr        MGTK_Set_Fine_Tune
  989.  
  990. MGTK_Set_Period
  991.         lea.l    MGTK_Period_Table(pc),a0
  992.         move.w    Voice_Note(a6),d0
  993.         bsr        MGTK_Find_Period
  994.         adda.w    Voice_Sample_Fine_Tune(a6),a0
  995.         move.w    (a0),Voice_Period(a6)
  996.  
  997.         move.w    Voice_Command(a6),d0
  998.         and.w    #$0ff0,d0
  999.         cmp.w    #$0ed0,d0
  1000.         bne.s    MGTK_No_Note_Delay
  1001.         move.b    Voice_Parameters(a6),d0
  1002.         and.b    #$0f,d0
  1003.         beq.s    MGTK_No_Note_Delay
  1004.         rts
  1005.  
  1006. MGTK_No_Note_Delay
  1007.         move.w    Voice_Period(a6),Voice_Sample_Period(a6)
  1008.         move.l    Voice_Start(a6),Voice_Sample_Start(a6)
  1009.         move.l    Voice_Sample_Offset(a6),Voice_Sample_Position(a6)
  1010.  
  1011.         btst.b    #2,Voice_Vibrato_Control(a6)
  1012.         bne.s    MGTK_Vibrato_No_Reset
  1013.         clr.b    Voice_Vibrato_Position(a6)
  1014. MGTK_Vibrato_No_Reset
  1015.  
  1016.         btst.b    #2,Voice_Tremolo_Control(a6)
  1017.         bne.s    MGTK_Tremolo_No_Reset
  1018.         clr.b    Voice_Tremolo_Position(a6)
  1019. MGTK_Tremolo_No_Reset
  1020.  
  1021.  
  1022. MGTK_Check_Efx_1
  1023.         moveq.l    #0,d0
  1024.         move.b    Voice_Command(a6),d0
  1025.         jmp        ([Jump_Table_1,d0.w*4])
  1026.  
  1027. Jump_Table_1
  1028.         dc.l        MGTK_Period_Nop,MGTK_Period_Nop
  1029.         dc.l        MGTK_Period_Nop,MGTK_Period_Nop
  1030.         dc.l        MGTK_Period_Nop,MGTK_Period_Nop
  1031.         dc.l        MGTK_Period_Nop,MGTK_Period_Nop
  1032.         dc.l        MGTK_Period_Nop,MGTK_Period_Nop
  1033.         dc.l        MGTK_Period_Nop,MGTK_Position_Jump
  1034.         dc.l        MGTK_Volume_Change,MGTK_Pattern_Break
  1035.         dc.l        MGTK_E_Commands_1,MGTK_Set_Speed
  1036.  
  1037. MGTK_E_Commands_1
  1038.         move.b    Voice_Parameters(a6),d0
  1039.         and.w    #$f0,d0
  1040.         lsr.w    #4,d0
  1041.         jmp        ([Jump_Table_E1,d0.w*4])
  1042.  
  1043. Jump_Table_E1
  1044.         dc.l        MGTK_Return,MGTK_Fine_Portamento_Up
  1045.         dc.l        MGTK_Fine_Portamento_Down,MGTK_Set_Glissando_Control
  1046.         dc.l        MGTK_Set_Vibrato_Control,MGTK_Return
  1047.         dc.l        MGTK_Pattern_Loop,MGTK_Set_Tremolo_Control
  1048.         dc.l        MGTK_Return,MGTK_Retrig_Note
  1049.         dc.l        MGTK_Volume_Fine_Up,MGTK_Volume_Slide_Down
  1050.         dc.l        MGTK_Note_Cut,MGTK_Return
  1051.         dc.l        MGTK_Pattern_Delay,MGTK_Return
  1052.  
  1053. Jump_Table_2
  1054.         dc.l        MGTK_Arpeggio,MGTK_Portamento_Up
  1055.         dc.l        MGTK_Portamento_Down,MGTK_Tone_Portamento
  1056.         dc.l        Mt_Vibrato,MGTK_Tone_Portamento_Plus_Volume_Slide
  1057.         dc.l        MGTK_Vibrato_Plus_Volume_Slide,Mt_Tremolo
  1058.         dc.l        MGTK_Return,MGTK_Return
  1059.         dc.l        MGTK_Volume_Slide,MGTK_Return
  1060.         dc.l        MGTK_Return,MGTK_Return
  1061.         dc.l        MGTK_E_Commands_2,MGTK_Return
  1062.  
  1063. MGTK_E_Commands_2
  1064.         move.b    Voice_Parameters(a6),d0
  1065.         and.w    #$f0,d0
  1066.         lsr.w    #4,d0
  1067.         jmp        ([Jump_Table_E2,d0.w*4])
  1068.  
  1069. Jump_Table_E2
  1070.         dc.l        MGTK_Return,MGTK_Return
  1071.         dc.l        MGTK_Return,MGTK_Return
  1072.         dc.l        MGTK_Return,MGTK_Return
  1073.         dc.l        MGTK_Return,MGTK_Return
  1074.         dc.l        MGTK_Return,MGTK_Retrig_Note
  1075.         dc.l        MGTK_Return,MGTK_Return
  1076.         dc.l        MGTK_Note_Cut,MGTK_Note_Delay
  1077.         dc.l        MGTK_Return,MGTK_Return
  1078.  
  1079.  
  1080. MGTK_Find_Period
  1081.         cmp.w    12*2(a0),d0
  1082.         bhs.s    MGTK_Do_Find_Period
  1083.         lea.l    12*2(a0),a0
  1084.         cmp.w    12*2(a0),d0
  1085.         bhs.s    MGTK_Do_Find_Period
  1086.         lea.l    12*2(a0),a0
  1087.  
  1088. MGTK_Do_Find_Period
  1089.         moveq.l    #12-1,d3
  1090. MGTK_Find_Period_Loop
  1091.         cmp.w    (a0)+,d0
  1092.         dbhs        d3,MGTK_Find_Period_Loop
  1093.         blo.s    MGTK_Period_Found
  1094.         subq.l    #2,a0
  1095. MGTK_Period_Found
  1096.         rts
  1097.  
  1098.  
  1099. MGTK_Period_Nop
  1100.         move.w    Voice_Period(a6),Voice_Sample_Period(a6)
  1101.  
  1102. MGTK_Return
  1103.         rts
  1104.  
  1105. MGTK_Arpeggio_Table
  1106.         dc.b        0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0
  1107.         dc.b        1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1
  1108.  
  1109. MGTK_Arpeggio
  1110.         move.b    Voice_Parameters(a6),d1
  1111.         beq.s    MGTK_Period_Nop
  1112.  
  1113.         moveq.l    #0,d0
  1114.         move.b    MGTK_Music_Counter(pc),d0
  1115.         move.b    MGTK_Arpeggio_Table(pc,d0.w),d0
  1116.         beq.s    MGTK_Period_Nop
  1117.         subq.b    #2,d0
  1118.         beq.s    MGTK_Arpeggio_2
  1119.  
  1120. MGTK_Arpeggio_1
  1121.         lsr.w    #4,d1
  1122. MGTK_Arpeggio_2
  1123.         and.w    #$f,d1
  1124.  
  1125.         lea.l    MGTK_Period_Table(pc),a0
  1126.         adda.w    Voice_Sample_Fine_Tune(a6),a0
  1127.         move.w    Voice_Period(a6),d0
  1128.         bsr.s    MGTK_Find_Period
  1129.         move.w    (a0,d1.w*2),Voice_Sample_Period(a6)
  1130.         rts
  1131.  
  1132.  
  1133. MGTK_Portamento_Up
  1134.         moveq.l    #0,d0
  1135.         move.b    Voice_Parameters(a6),d0
  1136.  
  1137. MGTK_Portamento_Up2
  1138.         sub.w    d0,Voice_Period(a6)
  1139.         move.w    Voice_Period(a6),d0
  1140.         cmp.w    #113,d0
  1141.         bhi.s    MGTK_Portamento_Up_Ok
  1142.         move.w    #113,Voice_Period(a6)
  1143.  
  1144. MGTK_Portamento_Up_Ok
  1145.         move.w    Voice_Period(a6),Voice_Sample_Period(a6)
  1146.         rts
  1147.  
  1148.  
  1149. MGTK_Portamento_Down
  1150.         moveq.l    #0,d0
  1151.         move.b    Voice_Parameters(a6),d0
  1152. MGTK_Portamento_Down2
  1153.         add.w    d0,Voice_Period(a6)
  1154.         move.w    Voice_Period(a6),d0
  1155.         cmp.w    #856,d0
  1156.         blo.s    MGTK_Portamento_Down_Ok
  1157.         move.w    #856,Voice_Period(a6)
  1158.  
  1159. MGTK_Portamento_Down_Ok
  1160.         move.w    Voice_Period(a6),Voice_Sample_Period(a6)
  1161.         rts
  1162.  
  1163.  
  1164. MGTK_Set_Tone_Portamento
  1165.         lea.l    MGTK_Period_Table(pc),a0
  1166.         move.w    Voice_Note(a6),d0
  1167.         bsr        MGTK_Find_Period
  1168.         adda.w    Voice_Sample_Fine_Tune(a6),a0
  1169.         move.w    (a0),d0
  1170.  
  1171.         move.w    d0,Voice_Wanted_Period(a6)
  1172.         move.w    Voice_Period(a6),d1
  1173.         sf        Voice_Tone_Port_Direction(a6)
  1174.         cmp.w    d1,d0
  1175.         beq.s    MGTK_Clear_Tone_Portamento
  1176.         bge        MGTK_Period_Nop
  1177.         st        Voice_Tone_Port_Direction(a6)
  1178.         rts
  1179.  
  1180. MGTK_Clear_Tone_Portamento
  1181.         clr.w    Voice_Wanted_Period(a6)
  1182.         rts
  1183.  
  1184. MGTK_Tone_Portamento
  1185.         move.b    Voice_Parameters(a6),d0
  1186.         beq.s    MGTK_Tone_Portamento_No_Change
  1187.         move.b    d0,Voice_Tone_Port_Speed(a6)
  1188.         clr.b    Voice_Parameters(a6)
  1189.  
  1190. MGTK_Tone_Portamento_No_Change
  1191.         tst.w    Voice_Wanted_Period(a6)
  1192.         beq        MGTK_Period_Nop
  1193.         moveq.l    #0,d0
  1194.         move.b    Voice_Tone_Port_Speed(a6),d0
  1195.         tst.b    Voice_Tone_Port_Direction(a6)
  1196.         bne.s    MGTK_Tone_Portamento_Up
  1197.  
  1198. MGTK_Tone_Portamento_Down
  1199.         add.w    d0,Voice_Period(a6)
  1200.         move.w    Voice_Wanted_Period(a6),d0
  1201.         cmp.w    Voice_Period(a6),d0
  1202.         bgt.s    MGTK_Tone_Portamento_Set_Period
  1203.         move.w    Voice_Wanted_Period(a6),Voice_Period(a6)
  1204.         clr.w    Voice_Wanted_Period(a6)
  1205.         bra.s    MGTK_Tone_Portamento_Set_Period
  1206.  
  1207. MGTK_Tone_Portamento_Up
  1208.         sub.w    d0,Voice_Period(a6)
  1209.         move.w    Voice_Wanted_Period(a6),d0
  1210.         cmp.w    Voice_Period(a6),d0
  1211.         blt.s    MGTK_Tone_Portamento_Set_Period
  1212.         move.w    Voice_Wanted_Period(a6),Voice_Period(a6)
  1213.         clr.w    Voice_Wanted_Period(a6)
  1214.  
  1215.  
  1216. MGTK_Tone_Portamento_Set_Period
  1217.         move.w    Voice_Period(a6),d0
  1218.         tst.b    Voice_Glissando_Control(a6)
  1219.         beq.s    MGTK_Glissando_Skip
  1220.  
  1221.         lea.l    MGTK_Period_Table(pc),a0
  1222.         adda.w    Voice_Sample_Fine_Tune(a6),a0
  1223.         bsr        MGTK_Find_Period
  1224.         move.w    (a0),d0
  1225.  
  1226. MGTK_Glissando_Skip
  1227.         move.w    d0,Voice_Sample_Period(a6)
  1228.         rts
  1229.  
  1230.  
  1231. Mt_Vibrato
  1232.         move.b    Voice_Parameters(a6),d0
  1233.         beq.s    Mt_Vibrato2
  1234.         move.b    Voice_Vibrato_Command(a6),d2
  1235.         and.b    #$0f,d0
  1236.         beq.s    Mt_VibSkip
  1237.         and.b    #$f0,d2
  1238.         or.b        d0,d2
  1239. Mt_VibSkip
  1240.         move.b    Voice_Parameters(a6),d0
  1241.         and.b    #$f0,d0
  1242.         beq.s    Mt_vibskip2
  1243.         and.b    #$0f,d2
  1244.         or.b        d0,d2
  1245. Mt_vibskip2
  1246.         move.b    d2,Voice_Vibrato_Command(a6)
  1247. Mt_Vibrato2
  1248.         move.b    Voice_Vibrato_Position(a6),d0
  1249.         lea.l    MGTK_Sinus_Table(pc),a3
  1250.         lsr.w    #2,d0
  1251.         and.w    #$001f,d0
  1252.         moveq.l    #0,d2
  1253.         move.b    Voice_Vibrato_Control(a6),d2
  1254.         and.b    #$3,d2
  1255.         beq.s    Mt_Vib_Sine
  1256.         lsl.b    #3,d0
  1257.         cmp.b    #1,d2
  1258.         beq.s    Mt_Vib_RampDown
  1259.         move.b    #255,d2
  1260.         bra.s    Mt_Vib_Set
  1261. Mt_Vib_RampDown
  1262.         tst.b    Voice_Vibrato_Position(a6)
  1263.         bpl.s    Mt_Vib_RampDown2
  1264.         move.b    #255,d2
  1265.         sub.b    d0,d2
  1266.         bra.s    Mt_Vib_Set
  1267. Mt_Vib_RampDown2
  1268.         move.b    d0,d2
  1269.         bra.s    Mt_Vib_Set
  1270. Mt_Vib_Sine
  1271.         move.b    (a3,d0.w),d2
  1272. Mt_Vib_Set
  1273.         move.b    Voice_Vibrato_Command(a6),d0
  1274.         and.w    #15,d0
  1275.         mulu.w    d0,d2
  1276.         lsr.w    #7,d2
  1277.         move.w    Voice_Period(a6),d0
  1278.         tst.b    Voice_Vibrato_Position(a6)
  1279.         bmi.s    Mt_VibratoNeg
  1280.         add.w    d2,d0
  1281.         bra.s    Mt_Vibrato3
  1282. Mt_VibratoNeg
  1283.         sub.w    d2,d0
  1284. Mt_Vibrato3
  1285.         move.w    d0,Voice_Sample_Period(a6)
  1286.         move.b    Voice_Vibrato_Command(a6),d0
  1287.         lsr.w    #2,d0
  1288.         and.w    #$003c,d0
  1289.         add.b    d0,Voice_Vibrato_Position(a6)
  1290.         rts
  1291.  
  1292. MGTK_Tone_Portamento_Plus_Volume_Slide
  1293.         bsr        MGTK_Tone_Portamento_No_Change
  1294.         bra        MGTK_Volume_Slide
  1295.  
  1296.  
  1297. MGTK_Vibrato_Plus_Volume_Slide
  1298.         bsr.s    Mt_Vibrato2
  1299.         bra        MGTK_Volume_Slide
  1300.  
  1301. Mt_Tremolo
  1302.         move.b    Voice_Parameters(a6),d0
  1303.         beq.s    Mt_Tremolo2
  1304.         move.b    Voice_Tremolo_Command(a6),d2
  1305.         and.b    #$0f,d0
  1306.         beq.s    Mt_treskip
  1307.         and.b    #$f0,d2
  1308.         or.b        d0,d2
  1309. Mt_treskip
  1310.         move.b    Voice_Parameters(a6),d0
  1311.         and.b    #$f0,d0
  1312.         beq.s    Mt_treskip2
  1313.         and.b    #$0f,d2
  1314.         or.b        d0,d2
  1315. Mt_treskip2
  1316.         move.b    d2,Voice_Tremolo_Command(a6)
  1317. Mt_Tremolo2
  1318.         move.b    Voice_Tremolo_Position(a6),d0
  1319.         lea.l    MGTK_Sinus_Table(pc),a3
  1320.         lsr.w    #2,d0
  1321.         and.w    #$001f,d0
  1322.         moveq.l    #0,d2
  1323.         move.b    Voice_Tremolo_Control(a6),d2
  1324.         and.b    #$3,d2
  1325.         beq.s    Mt_tre_sine
  1326.         lsl.b    #3,d0
  1327.         cmp.b    #1,d2
  1328.         beq.s    Mt_tre_rampdown
  1329.         move.b    #255,d2
  1330.         bra.s    Mt_tre_set
  1331. Mt_tre_rampdown
  1332.         tst.b    Voice_Tremolo_Position(a6)
  1333.         bpl.s    Mt_tre_rampdown2
  1334.         move.b    #255,d2
  1335.         sub.b    d0,d2
  1336.         bra.s    Mt_tre_set
  1337. Mt_tre_rampdown2
  1338.         move.b    d0,d2
  1339.         bra.s    Mt_tre_set
  1340. Mt_tre_sine
  1341.         move.b    (a3,d0.w),d2
  1342. Mt_tre_set
  1343.         move.b    Voice_Tremolo_Command(a6),d0
  1344.         and.w    #15,d0
  1345.         mulu.w    d0,d2
  1346.         lsr.w    #6,d2
  1347.         moveq.l    #0,d0
  1348.         move.w    Voice_Volume(a6),d0
  1349.         tst.b    Voice_Tremolo_Position(a6)
  1350.         bmi.s    Mt_TremoloNeg
  1351.         add.w    d2,d0
  1352.         bra.s    Mt_Tremolo3
  1353. Mt_TremoloNeg
  1354.         sub.w    d2,d0
  1355. Mt_Tremolo3
  1356.         bpl.s    Mt_TremoloSkip
  1357.         clr.w    d0
  1358. Mt_TremoloSkip
  1359.         cmp.w    #$40,d0
  1360.         bls.s    Mt_TremoloOk
  1361.         move.w    #$40,d0
  1362. Mt_TremoloOk
  1363.         move.w    d0,Voice_Sample_Volume(a6)
  1364.         move.b    Voice_Tremolo_Command(a6),d0
  1365.         lsr.w    #2,d0
  1366.         and.w    #$003c,d0
  1367.         add.b    d0,Voice_Tremolo_Position(a6)
  1368.         bra        MGTK_Period_Nop
  1369.  
  1370.  
  1371. MGTK_Sample_Offset
  1372.         move.l    Voice_Sample_Offset(a6),d0
  1373.         moveq.l    #0,d1
  1374.         move.b    Voice_Parameters(a6),d1
  1375.         beq.s    MGTK_Sample_Offset_No_New
  1376.  
  1377.         lsl.w    #8,d1
  1378.         move.l    d1,d0
  1379. MGTK_Sample_Offset_No_New
  1380.  
  1381.         add.l    Voice_Sample_Offset(a6),d0
  1382.         cmp.l    Voice_Sample_Length(a6),d0
  1383.         ble.s    MGTK_Sample_Offset_Ok
  1384.         move.l    Voice_Sample_Length(a6),d0
  1385. MGTK_Sample_Offset_Ok
  1386.         move.l    Voice_Start(a6),Voice_Sample_Start(a6)
  1387.         move.l    d0,Voice_Sample_Offset(a6)
  1388.         move.l    d0,Voice_Sample_Position(a6)
  1389.         rts
  1390.  
  1391.  
  1392. MGTK_Volume_Slide
  1393.         moveq.l    #0,d0
  1394.         move.b    Voice_Parameters(a6),d0
  1395.         lsr.w    #4,d0
  1396.         beq.s    MGTK_Volume_Slide_Down
  1397.  
  1398. MGTK_Volume_Slide_Up
  1399.         add.w    d0,Voice_Volume(a6)
  1400.         cmp.w    #$40,Voice_Volume(a6)
  1401.         ble.s    MGTK_Volume_Slide_Up_Ok
  1402.         move.w    #$40,Voice_Volume(a6)
  1403.  
  1404. MGTK_Volume_Slide_Up_Ok
  1405.         move.w    Voice_Volume(a6),Voice_Sample_Volume(a6)
  1406.         bra        MGTK_Period_Nop
  1407.  
  1408.  
  1409. MGTK_Volume_Slide_Down
  1410.         move.b    Voice_Parameters(a6),d0
  1411.         and.w    #$0f,d0
  1412.  
  1413. MGTK_Volume_Slide_Down2
  1414.         sub.w    d0,Voice_Volume(a6)
  1415.         bpl.s    MGTK_Volume_Slide_Down_Ok
  1416.         clr.w    Voice_Volume(a6)
  1417.  
  1418. MGTK_Volume_Slide_Down_Ok
  1419.         move.w    Voice_Volume(a6),Voice_Sample_Volume(a6)
  1420.         bra        MGTK_Period_Nop
  1421.  
  1422.  
  1423. MGTK_Position_Jump
  1424.         moveq.l    #0,d0
  1425.         move.b    Voice_Parameters(a6),d0
  1426.  
  1427.         move.w    d0,MGTK_Position_Jump_Position
  1428.         st        MGTK_Position_Jump_Flag
  1429.         rts
  1430.  
  1431.  
  1432. MGTK_Volume_Change
  1433.         moveq.l    #0,d0
  1434.         move.b    Voice_Parameters(a6),d0
  1435.         cmp.b    #$40,d0
  1436.         ble.s    MGTK_Volume_Change_Ok
  1437.         moveq.l    #$40,d0
  1438.  
  1439. MGTK_Volume_Change_Ok
  1440.         move.w    d0,Voice_Volume(a6)
  1441.         move.w    d0,Voice_Sample_Volume(a6)
  1442.         rts
  1443.  
  1444.  
  1445. MGTK_Pattern_Break
  1446.         moveq.l    #0,d0
  1447.  
  1448.         tst.b    MGTK_Old_Module(pc)
  1449.         bne.s    MGTK_Pattern_Break_Ok
  1450.  
  1451.         move.b    Voice_Parameters(a6),d0
  1452.  
  1453.         move.w    d0,d2            ; Codage en BCD
  1454.         lsr.w    #4,d0            ; premier chiffre
  1455.         mulu.w    #10,d0            ; les dizaines
  1456.         and.w    #$0f,d2            ; deuxième chiffre
  1457.         add.w    d2,d0            ; les unités
  1458.  
  1459.         cmp.w    MGTK_Pattern_Length(pc),d0
  1460.         blo.s    MGTK_Pattern_Break_Ok
  1461.         moveq.l    #0,d0
  1462.     
  1463. MGTK_Pattern_Break_Ok
  1464.         move.w    d0,MGTK_Pattern_Break_Position
  1465.         st        MGTK_Pattern_Break_Flag
  1466.         rts
  1467.  
  1468.  
  1469. MGTK_Set_Speed
  1470.         moveq.l    #0,d0
  1471.         move.b    Voice_Parameters(a6),d0
  1472.         beq.s    MGTK_End
  1473.         cmp.b    #32,d0
  1474.         bhi.s    MGTK_Set_Tempo
  1475.         move.b    d0,MGTK_Music_Speed
  1476. MGTK_End    rts
  1477.  
  1478. MGTK_Set_Tempo
  1479.         move.b    d0,MGTK_Music_Tempo
  1480.  
  1481. MGTK_Search_Values_for_Tempo
  1482.         movem.l    d0-d1,-(sp)
  1483.         moveq.l    #0,d0
  1484.         move.b    MGTK_Music_Tempo(pc),d0
  1485.  
  1486.         move.l    #Freq_Replay*125/50,d1        
  1487.         divu.w    d0,d1                    ; / Tempo
  1488.         move.w    d1,MGTK_IT_Nb_Samples        ; = Nb Samples / Tick
  1489.         movem.l    (sp)+,d0-d1
  1490.         rts
  1491.  
  1492. MGTK_Fine_Portamento_Up
  1493.         move.b    Voice_Parameters(a6),d0
  1494.         and.w    #$0f,d0
  1495.         bra        MGTK_Portamento_Up2
  1496.  
  1497. MGTK_Fine_Portamento_Down
  1498.         move.b    Voice_Parameters(a6),d0
  1499.         and.w    #$0f,d0
  1500.         bra        MGTK_Portamento_Down2
  1501.  
  1502.  
  1503. MGTK_Set_Glissando_Control
  1504.         move.b    Voice_Parameters(a6),Voice_Glissando_Control(a6)
  1505.         rts
  1506.  
  1507. MGTK_Set_Vibrato_Control
  1508.         move.b    Voice_Parameters(a6),Voice_Vibrato_Control(a6)
  1509.         rts
  1510.  
  1511. MGTK_Set_Fine_Tune
  1512.         move.b    Voice_Parameters(a6),d0
  1513.         and.w    #$0f,d0
  1514.         mulu.w    #12*3*2,d0
  1515.         move.w    d0,Voice_Sample_Fine_Tune(a6)
  1516.         rts
  1517.  
  1518. MGTK_Pattern_Loop
  1519.         move.b    Voice_Parameters(a6),d0
  1520.         and.w    #$0f,d0
  1521.         beq.s    MGTK_Set_Loop_Position
  1522.  
  1523.         tst.w    MGTK_Pattern_Loop_Counter(pc)
  1524.         beq.s    MGTK_Set_Loop_Counter
  1525.  
  1526.         subq.w    #1,MGTK_Pattern_Loop_Counter
  1527.         beq        MGTK_Return
  1528.  
  1529. MGTK_Do_Loop    
  1530.         st        MGTK_Pattern_Loop_Flag
  1531.         rts
  1532. MGTK_Set_Loop_Counter
  1533.         move.w    d0,MGTK_Pattern_Loop_Counter
  1534.         bra.s    MGTK_Do_Loop
  1535. MGTK_Set_Loop_Position
  1536.         move.w    MGTK_Pattern_Position(pc),MGTK_Pattern_Loop_Position
  1537.         rts
  1538.  
  1539.  
  1540. MGTK_Set_Tremolo_Control
  1541.         move.b    Voice_Parameters(a6),Voice_Tremolo_Control(a6)
  1542.         rts
  1543.  
  1544.  
  1545. MGTK_Retrig_Note
  1546.         move.b    Voice_Parameters(a6),d0
  1547.         and.w    #$0f,d0
  1548.         beq.s    MGTK_No_Retrig_Note
  1549.  
  1550.         moveq.l    #0,d1
  1551.         move.b    MGTK_Music_Counter(pc),d1
  1552.         bne.s    MGTK_Retrig_Note_Skip
  1553.  
  1554.         tst.w    Voice_Note(a6)
  1555.         bne.s    MGTK_No_Retrig_Note
  1556.  
  1557. MGTK_Retrig_Note_Skip
  1558.         divu.w    d0,d1
  1559.         swap.w    d1
  1560.         tst.w    d1
  1561.         bne.s    MGTK_No_Retrig_Note
  1562.  
  1563.         move.w    Voice_Period(a6),Voice_Sample_Period(a6)
  1564.         move.l    Voice_Sample_Offset(a6),Voice_Sample_Position(a6)
  1565.  
  1566. MGTK_No_Retrig_Note
  1567.         rts
  1568.  
  1569.  
  1570. MGTK_Volume_Fine_Up
  1571.         move.b    Voice_Parameters(a6),d0
  1572.         and.w    #$0f,d0
  1573.         bra        MGTK_Volume_Slide_Up
  1574.  
  1575.  
  1576. MGTK_Note_Cut
  1577.         move.b    Voice_Parameters(a6),d0
  1578.         and.b    #$0f,d0
  1579.         cmp.b    MGTK_Music_Counter(pc),d0
  1580.         bne        MGTK_Return
  1581.         clr.w    Voice_Volume(a6)
  1582.         clr.w    Voice_Sample_Volume(a6)
  1583.         rts
  1584.  
  1585. MGTK_Note_Delay
  1586.         move.b    Voice_Parameters(a6),d0
  1587.         and.b    #$0f,d0
  1588.         cmp.b    MGTK_Music_Counter(pc),d0
  1589.         bne        MGTK_Return
  1590.         tst.w    Voice_Note(a6)
  1591.         beq        MGTK_Return
  1592.  
  1593.         move.w    Voice_Period(a6),Voice_Sample_Period(a6)
  1594.         move.l    Voice_Start(a6),Voice_Sample_Start(a6)
  1595.         move.l    Voice_Sample_Offset(a6),Voice_Sample_Position(a6)
  1596.         rts
  1597.  
  1598.  
  1599. MGTK_Pattern_Delay
  1600.         tst.b    MGTK_Pattern_Delay_Time(pc)
  1601.         bne        MGTK_Return
  1602.         move.b    Voice_Parameters(a6),d0
  1603.         and.b    #$0f,d0
  1604.         move.b    d0,MGTK_Pattern_Delay_Time
  1605.         rts
  1606.  
  1607. ***********************************************************************
  1608. ***********               Tables diverses                ***********
  1609. ***********************************************************************
  1610.  
  1611. MGTK_Sinus_Table    
  1612.         dc.b        0,24,49,74,97,120,141,161,180,197,212,224
  1613.         dc.b        235,244,250,253,255,253,250,244,235,224
  1614.         dc.b        212,197,180,161,141,120,97,74,49,24
  1615.  
  1616. MGTK_Period_Table
  1617. ; Tuning 0, Normal
  1618.         dc.w        856,808,762,720,678,640,604,570,538,508,480,453
  1619.         dc.w        428,404,381,360,339,320,302,285,269,254,240,226
  1620.         dc.w        214,202,190,180,170,160,151,143,135,127,120,113
  1621. ; Tuning 1
  1622.         dc.w        850,802,757,715,674,637,601,567,535,505,477,450
  1623.         dc.w        425,401,379,357,337,318,300,284,268,253,239,225
  1624.         dc.w        213,201,189,179,169,159,150,142,134,126,119,113
  1625. ; Tuning 2
  1626.         dc.w        844,796,752,709,670,632,597,563,532,502,474,447
  1627.         dc.w        422,398,376,355,335,316,298,282,266,251,237,224
  1628.         dc.w        211,199,188,177,167,158,149,141,133,125,118,112
  1629. ; Tuning 3
  1630.         dc.w        838,791,746,704,665,628,592,559,528,498,470,444
  1631.         dc.w        419,395,373,352,332,314,296,280,264,249,235,222
  1632.         dc.w        209,198,187,176,166,157,148,140,132,125,118,111
  1633. ; Tuning 4
  1634.         dc.w        832,785,741,699,660,623,588,555,524,495,467,441
  1635.         dc.w        416,392,370,350,330,312,294,278,262,247,233,220
  1636.         dc.w        208,196,185,175,165,156,147,139,131,124,117,110
  1637. ; Tuning 5
  1638.         dc.w        826,779,736,694,655,619,584,551,520,491,463,437
  1639.         dc.w        413,390,368,347,328,309,292,276,260,245,232,219
  1640.         dc.w        206,195,184,174,164,155,146,138,130,123,116,109
  1641. ; Tuning 6
  1642.         dc.w        820,774,730,689,651,614,580,547,516,487,460,434
  1643.         dc.w        410,387,365,345,325,307,290,274,258,244,230,217
  1644.         dc.w        205,193,183,172,163,154,145,137,129,122,115,109
  1645. ; Tuning 7
  1646.         dc.w        814,768,725,684,646,610,575,543,513,484,457,431
  1647.         dc.w        407,384,363,342,323,305,288,272,256,242,228,216
  1648.         dc.w        204,192,181,171,161,152,144,136,128,121,114,108
  1649. ; Tuning -8
  1650.         dc.w        907,856,808,762,720,678,640,604,570,538,508,480
  1651.         dc.w        453,428,404,381,360,339,320,302,285,269,254,240
  1652.         dc.w        226,214,202,190,180,170,160,151,143,135,127,120
  1653. ; Tuning -7
  1654.         dc.w        900,850,802,757,715,675,636,601,567,535,505,477
  1655.         dc.w        450,425,401,379,357,337,318,300,284,268,253,238
  1656.         dc.w        225,212,200,189,179,169,159,150,142,134,126,119
  1657. ; Tuning -6
  1658.         dc.w        894,844,796,752,709,670,632,597,563,532,502,474
  1659.         dc.w        447,422,398,376,355,335,316,298,282,266,251,237
  1660.         dc.w        223,211,199,188,177,167,158,149,141,133,125,118
  1661. ; Tuning -5
  1662.         dc.w        887,838,791,746,704,665,628,592,559,528,498,470
  1663.         dc.w        444,419,395,373,352,332,314,296,280,264,249,235
  1664.         dc.w        222,209,198,187,176,166,157,148,140,132,125,118
  1665. ; Tuning -4
  1666.         dc.w        881,832,785,741,699,660,623,588,555,524,494,467
  1667.         dc.w        441,416,392,370,350,330,312,294,278,262,247,233
  1668.         dc.w        220,208,196,185,175,165,156,147,139,131,123,117
  1669. ; Tuning -3
  1670.         dc.w        875,826,779,736,694,655,619,584,551,520,491,463
  1671.         dc.w        437,413,390,368,347,328,309,292,276,260,245,232
  1672.         dc.w        219,206,195,184,174,164,155,146,138,130,123,116
  1673. ; Tuning -2
  1674.         dc.w        868,820,774,730,689,651,614,580,547,516,487,460
  1675.         dc.w        434,410,387,365,345,325,307,290,274,258,244,230
  1676.         dc.w        217,205,193,183,172,163,154,145,137,129,122,115
  1677. ; Tuning -1
  1678.         dc.w        862,814,768,725,684,646,610,575,543,513,484,457
  1679.         dc.w        431,407,384,363,342,323,305,288,272,256,242,228
  1680.         dc.w        216,203,192,181,171,161,152,144,136,128,121,114
  1681.  
  1682. ***********************************************************************
  1683. ***********            Variables diverses                ***********
  1684. ***********************************************************************
  1685.  
  1686. MGTK_Module_Adr            ds.l        1
  1687. MGTK_WorkSpace_Adr            ds.l        1
  1688. MGTK_Module_End_Adr            ds.l        1
  1689.  
  1690. MGTK_Nb_Samples            ds.w        1
  1691.  
  1692. MGTK_Sequence_Adr            ds.l        1
  1693. MGTK_Patterns_Adr            ds.l        1
  1694. MGTK_Samples_Adr            ds.l        31
  1695. MGTK_Line_Size                ds.w        1
  1696. MGTK_Pattern_Size            ds.w        1
  1697.  
  1698. MGTK_Music_Position            ds.w        1
  1699. MGTK_Music_Length            ds.w        1
  1700. MGTK_Music_Restart            ds.w        1
  1701. MGTK_Music_Tempo            ds.b        1
  1702. MGTK_Music_Speed            ds.b        1
  1703. MGTK_Music_Counter            ds.b        1
  1704.  
  1705. MGTK_Restart_Loop            ds.b        1
  1706. MGTK_Restart_Done            ds.b        1
  1707. MGTK_Replay_Paused            ds.b        1
  1708. MGTK_Replay_Stopped            ds.b        1
  1709.                         ds.b        1
  1710. MGTK_IT_Nb_Samples            ds.w        1
  1711.  
  1712. MGTK_Pattern_Position        ds.w        1
  1713. MGTK_Pattern_Length            ds.w        1
  1714.  
  1715. MGTK_Pattern_Loop_Counter    ds.w        1
  1716. MGTK_Pattern_Loop_Position    ds.w        1
  1717. MGTK_Pattern_Break_Position    ds.w        1
  1718. MGTK_Position_Jump_Position    ds.w        1
  1719. MGTK_Position_Jump_Flag        ds.b        1
  1720. MGTK_Pattern_Loop_Flag        ds.b        1
  1721. MGTK_Pattern_Break_Flag        ds.b        1
  1722. MGTK_Pattern_Delay_Time        ds.b        1
  1723.  
  1724. MGTK_Old_Module            ds.b        1
  1725.  
  1726.                         Even
  1727. MGTK_Voices                ds.b        4*Voice_Size
  1728.  
  1729. MGTK_Volume_Table            ds.b        65*256
  1730. MGTK_Buffer1                ds.l        1922        ; Maxi Tempo 32
  1731. MGTK_Buffer2                ds.l        1922
  1732. MGTK_Empty_Buffer            ds.b        672        ; Maxi 4*8363 Hz
  1733.