home *** CD-ROM | disk | FTP | other *** search
/ Fujiology Archive / fujiology_archive_v1_0.iso / !FALCON / ABSTRACT / MEGPL116.ZIP / MGPL-116 / REPLAY / MGT-PLAY.S < prev    next >
Text File  |  1995-09-17  |  69KB  |  2,768 lines

  1. ***********************************************************************
  2. ***********                                        ***********
  3. ***********                                        ***********
  4. ***********          DSP-Replay MegaTracker v1.1            ***********
  5. ***********                16/09/1995                ***********
  6. ***********                                        ***********
  7. ***********                                        ***********
  8. ***********          Par Simplet / FATAL DESIGN            ***********
  9. ***********                                        ***********
  10. ***********************************************************************
  11.  
  12. CPU_Time        equ        1        ; Display CPU-Time taken by the Replay
  13. DSP_Buffer    equ        2048        ; DSP Sample Buffer Size
  14.  
  15.         XDef        MGTK_Init_Module_Samples,MGTK_Init_DSP
  16.         XDef        MGTK_Save_Sound,MGTK_Init_Sound,MGTK_Restore_Sound
  17.         XDef        MGTK_Set_Replay_Frequency
  18.         XDef        MGTK_Play_Music,MGTK_Pause_Music,MGTK_Stop_Music
  19.         XDef        MGTK_Previous_Music,MGTK_Next_Music
  20.         XDef        MGTK_Play_Position,MGTK_Previous_Position
  21.         XDef        MGTK_Next_Position,MGTK_Clear_Voices
  22.         XDef        MGTK_Play_FX_Module,MGTK_Play_FX_Sample
  23.         XDef        MGTK_FX_Voices,MGTK_Voices
  24.         XDef        MGTK_Restart_Loop,MGTK_Restart_Done
  25.         XDef        MGTK_Replay_Satured,MGTK_Replay_Problem
  26.         XDef        MGTK_Replay_In_Service,MGTK_Global_Volume
  27.         XDef        MGTK_Master_Volume_Left,MGTK_Master_Volume_Right
  28.  
  29. ***********************************************************************
  30. ***********                    Macros                ***********
  31. ***********************************************************************
  32.  
  33. WaitDSPToSend    Macro
  34. WaitDSPS\@    btst.b    #1,$ffffa202.w            ; Attend que le DSP
  35.             beq.s    WaitDSPS\@            ; puisse recevoir
  36.             EndM
  37.  
  38. WaitDSPToGet    Macro
  39. WaitDSPG\@    btst.b    #0,$ffffa202.w            ; Attend que le DSP
  40.             beq.s    WaitDSPG\@            ; ait envoyé une donnée
  41.             EndM
  42.  
  43. SaveColor        Macro
  44.             Ifne        CPU_Time
  45.                 move.l    $ffff9800.w,-(sp)
  46.             EndC
  47.             EndM
  48.  
  49. RestoreColor    Macro
  50.             Ifne        CPU_Time
  51.                 move.l    (sp)+,$ffff9800.w
  52.             EndC
  53.             EndM
  54.  
  55. CPUTimeColor    Macro
  56.             Ifne        CPU_Time
  57.                 move.l    \1,$ffff9800.w
  58.             EndC
  59.             EndM
  60.  
  61. ***********************************************************************
  62. ***********                Structures                ***********
  63. ***********************************************************************
  64.  
  65.                     RsReset
  66.  
  67. Sample_Name            rs.b        32    * 32 caractères
  68.  
  69. Sample_Start            rs.l        1    * Adresse début du Sample
  70. Sample_Length            rs.l        1    * Taille du sample en unités
  71. Sample_Loop_Start        rs.l        1    * Offset début Boucle en unités
  72. Sample_Loop_Length        rs.l        1    * Taille de la Boucle en unités
  73. Sample_Buffer_Length    rs.l        1    * Taille Minimale du Buffer en unités
  74. Sample_End_Length        rs.l        1    * Taille de la fin du sample après le buffer
  75.  
  76. Sample_Base            rs.l        1    * Fréquence de Replay pour le DO-4
  77. Sample_Volume            rs.w        1    * Volume par défaut de 0 à 1024
  78. Sample_Panoramic        rs.b        2    * Volumes Gauche et Droit de 0 à 255
  79.                                 * par défaut, 0 si y'en a pas
  80. Sample_Attributes        rs.b        1    * bits 0 et 1 : Loop Mode -->
  81.                                 *  0 = Loop Off,    1 = Forward Loop
  82.                                 *  2 = Ping-Pong Loop, 3 réservé
  83.                                 * bit 2 --> 0 = 8 bits,  1 = 16 bits
  84.                                 * bit 3 --> 0 = Mono,    1 = Stereo
  85.  
  86. Sample_Fine_Tune        rs.b        1    * de 0 à 15  =  0 à 7 et -8 à -1
  87.  
  88.                     rs.b        1    * Inutilisé
  89. Sample_Drum_Note        rs.b        1    * Informations stockées
  90. Sample_Drum_Volume        rs.b        1    * par le Tracker
  91. Sample_Drum_Command        rs.b        1    * pour le mode
  92. Sample_Drum_Parameter    rs.w        1    * Drum Edit
  93.  
  94. Sample_Midi_Note        rs.l        1    * Note au format MIDI
  95. Sample_Reserved        rs.l        1    * 4 octets Réservés
  96.  
  97. Sample_Size            rs.b        0    * 80 octets
  98.  
  99.                     RsReset
  100.  
  101. Voice_Sample_Start            rs.l        1
  102. Voice_Sample_Offset            rs.l        1
  103. Voice_Sample_Position        rs.l        1
  104. Voice_Sample_Length            rs.l        1
  105. Voice_Sample_Loop_Length        rs.l        1
  106. Voice_Sample_End_Length        rs.l        1
  107. Voice_Sample_Base            rs.l        1
  108. Voice_Sample_Volume            rs.w        1
  109. Voice_Sample_Period            rs.l        1
  110. Voice_Sample_Fine_Tune        rs.w        1
  111.                         rs.b        1
  112. Voice_Sample_Attributes        rs.b        1
  113. Voice_Left_Volume            rs.b        1
  114. Voice_Right_Volume            rs.b        1
  115.  
  116. Voice_Start                rs.l        1
  117. Voice_Length                rs.l        1
  118. Voice_Loop_Length            rs.l        1
  119. Voice_End_Length            rs.l        1
  120. Voice_Base                rs.l        1
  121. Voice_Volume                rs.w        1
  122. Voice_Period                rs.l        1
  123. Voice_Attributes            rs.b        1
  124.                         rs.b        1
  125.  
  126. Voice_Note                rs.b        1
  127. Voice_Sample                rs.b        1
  128. Voice_Vol_Command            rs.b        1
  129. Voice_Command                rs.b        1
  130. Voice_Parameter1            rs.b        1
  131. Voice_Parameter2            rs.b        1
  132.  
  133. Voice_Tone_Port_Period        rs.l        1
  134. Voice_Tone_Port_Speed        rs.l        1
  135. Voice_Tone_Port_Direction    rs.b        1
  136. Voice_Glissando_Control        rs.b        1
  137. Voice_Vibrato_Waveform        rs.b        1
  138. Voice_Vibrato_Speed            rs.b        1
  139. Voice_Vibrato_Depth            rs.w        1
  140. Voice_Vibrato_Position        rs.b        1
  141. Voice_Tremolo_Waveform        rs.b        1
  142. Voice_Tremolo_Depth            rs.w        1
  143. Voice_Tremolo_Speed            rs.b        1
  144. Voice_Tremolo_Position        rs.b        1
  145.  
  146. Voice_Size                rs.b        0
  147.  
  148. ***********************************************************************
  149. ***********                                        ***********
  150. ***********    Routines de gestion de Base du Replay :        ***********
  151. ***********                                        ***********
  152. ***********    Fixer Fréquence de Replay                ***********
  153. ***********    Jouer/arrêter une musique, Position/Musique    ***********
  154. ***********    précédente/suivante, Saut à une Position    ***********
  155. ***********    Et gestion de samples supplémentaires (FX)    ***********
  156. ***********                                        ***********
  157. ***********************************************************************
  158.  
  159.             Section    TEXT
  160.  
  161. ; Fixer la fréquence de Replay
  162. ; En Entrée :
  163. ; d0.w = Valeur du diviseur d'Horloge
  164. ;    1 : 49170 Hz, 2 : 32780 Hz, 3 : 24585 Hz, 4 : 19668 Hz
  165. ;    5 : 16380 Hz, 7 : 12292 Hz, 9 : 9834 Hz, 11 : 8195 Hz
  166.  
  167. MGTK_Set_Replay_Frequency
  168.         move.w    d0,MGTK_Frequency_Divider
  169.         move.l    #25175000/256+1,d1
  170.         addq.w    #1,d0
  171.         divu.w    d0,d1
  172.         move.w    d1,MGTK_Replay_Frequency
  173.         rts
  174.  
  175. ; Jouer une musique
  176. ; En Entrée :
  177. ; d0.w = Numéro de la musique à jouer
  178.  
  179. MGTK_Play_Music
  180.         movem.l    d3-d7/a2-a6,-(sp)
  181.  
  182.         tst.w    d0
  183.         bpl.s    MGTK_Play_Music_1
  184.         moveq.l    #0,d0
  185. MGTK_Play_Music_1
  186.         cmp.w    MGTK_Nb_Musics(pc),d0
  187.         blo.s    MGTK_Play_Music_2
  188.         move.w    MGTK_Nb_Musics(pc),d0
  189.         subq.w    #1,d0
  190. MGTK_Play_Music_2
  191.  
  192.         move.w    MGTK_Nb_Voices(pc),d1
  193.         add.w    d1,d1
  194.         add.w    #46,d1
  195.         mulu.w    d1,d0
  196.         lea.l    ([MGTK_Musics_Adr,pc],d0.w,32.w),a0
  197.  
  198.         move.l    (a0)+,a1
  199.         adda.l    MGTK_Module_Adr(pc),a1
  200.         move.l    a1,MGTK_Sequence_Adr
  201.         move.w    (a0)+,MGTK_Music_Length
  202.         move.w    (a0)+,MGTK_Music_Restart
  203.         move.b    (a0)+,d0
  204.         move.b    (a0)+,d1
  205.         move.w    (a0)+,MGTK_Global_Volume
  206.         move.b    (a0)+,MGTK_Master_Volume_Left
  207.         move.b    (a0)+,MGTK_Master_Volume_Right
  208.  
  209.         move.b    d0,MGTK_Initial_Tempo
  210.         move.b    d0,MGTK_Music_Tempo
  211.         move.b    d1,MGTK_Initial_Speed
  212.         move.b    d1,MGTK_Music_Speed    
  213.         move.b    d1,MGTK_Music_Counter
  214.  
  215.         bsr        MGTK_Search_Values_for_Tempo
  216.  
  217.         move.w    MGTK_Nb_Voices(pc),d7
  218.         lea.l    MGTK_Voices(pc),a6
  219.         subq.w    #1,d7
  220. MGTK_Play_Music_Panoramics
  221.         move.w    (a0)+,Voice_Left_Volume(a6)
  222.         lea.l    Voice_Size(a6),a6
  223.         dbra        d7,MGTK_Play_Music_Panoramics
  224.  
  225.         move.w    #-1,MGTK_Music_Position
  226.         move.w    #-2,MGTK_Pattern_Position
  227.         sf        MGTK_Pattern_Loop_Flag
  228.         clr.w    MGTK_Pattern_Loop_Counter
  229.         clr.w    MGTK_Pattern_Loop_Position
  230.         sf        MGTK_Pattern_Break_Flag
  231.         clr.w    MGTK_Pattern_Break_Position
  232.         sf        MGTK_Position_Jump_Flag
  233.         clr.w    MGTK_Position_Jump_Position
  234.         clr.b    MGTK_Pattern_Delay_Time
  235.  
  236.         bsr        MGTKClearVoices
  237.  
  238.         sf        MGTK_Replay_In_Service
  239.         sf        MGTK_Replay_Problem
  240.         clr.w    MGTK_Replay_Satured
  241.  
  242.         sf        MGTK_Replay_Paused
  243.         sf        MGTK_Replay_Stopped
  244.  
  245.         movem.l    (sp)+,d3-d7/a2-a6
  246.         bra        MGTK_Init_IT
  247.  
  248. ;
  249. ; Met la Musique en Pause
  250. ;
  251. MGTK_Pause_Music
  252.         tst.b    MGTK_Replay_Stopped(pc)
  253.         bne.s    MGTK_Pause_Music_Ret
  254.         tst.b    MGTK_Replay_Paused(pc)
  255.         seq        MGTK_Replay_Paused
  256.         tst.b    MGTK_Replay_Paused(pc)
  257.         bne        MGTK_Stop_IT
  258.         bra        MGTK_Init_IT
  259. MGTK_Pause_Music_Ret
  260.         rts
  261. ;
  262. ; Stoppe la musique
  263. ;
  264. MGTK_Stop_Music
  265.         sf        MGTK_Replay_Paused
  266.         st        MGTK_Replay_Stopped
  267.         bra        MGTK_Stop_IT
  268.  
  269. ; Sauter à une position particulière
  270. ; En Entrée :
  271. ; d0.w = Numéro de la position
  272.  
  273. MGTK_Play_Position
  274.         cmp.w    MGTK_Music_Length(pc),d0
  275.         blo.s    MGTK_Play_Position_Ok
  276.         moveq.l    #0,d0
  277. MGTK_Play_Position_Ok
  278.         move.w    d0,MGTK_Position_Jump_Position
  279.         st        MGTK_Position_Jump_Flag
  280.         rts
  281. ;
  282. ; Gestion des effets spéciaux
  283. ;
  284. MGTK_Play_FX_Module
  285. MGTK_Play_FX_Sample
  286.         rts
  287.  
  288. ;
  289. ; Position précédente
  290. ;
  291. MGTK_Previous_Position
  292.         move.w    MGTK_Music_Position(pc),d0
  293.         beq.s    MGTK_Previous_Position_Skip
  294.         subq.w    #1,d0
  295. MGTK_Previous_Position_Skip
  296.         move.w    d0,MGTK_Position_Jump_Position
  297.         st        MGTK_Position_Jump_Flag
  298.         rts
  299. ;
  300. ; Position suivante
  301. ;
  302. MGTK_Next_Position
  303.         move.w    MGTK_Music_Position(pc),d0
  304.         cmp.w    MGTK_Music_Length,d0
  305.         beq.s    MGTK_Next_Position_Skip
  306.         addq.w    #1,d0
  307. MGTK_Next_Position_Skip
  308.         move.w    d0,MGTK_Position_Jump_Position
  309.         st        MGTK_Position_Jump_Flag
  310.         rts
  311. ;
  312. ; Musique précédente
  313. ;
  314. MGTK_Previous_Music
  315.         move.w    MGTK_Music(pc),d0
  316.         subq.w    #1,d0
  317.         bra        MGTK_Play_Music
  318. ;
  319. ; Musique suivante
  320. ;
  321. MGTK_Next_Music
  322.         move.w    MGTK_Music(pc),d0
  323.         addq.w    #1,d0
  324.         bra        MGTK_Play_Music
  325.  
  326. ;
  327. ; Remet les voies à zéro
  328. ;
  329. MGTK_Clear_Voices
  330.         movem.l    d3-d4/d7/a6,-(sp)
  331.         bsr.s    MGTKClearVoices
  332.         movem.l    (sp)+,d3-d4/d7/a6
  333.         rts
  334.                 
  335. MGTKClearVoices
  336.         move.l    #8363,d3
  337.         move.l    #256*1700,d4
  338.  
  339.         lea.l    MGTK_FX_Voices(pc),a6
  340.         moveq.l    #34-1,d7
  341.  
  342. MGTK_Clear_A_Voice
  343.         clr.l    (a6)+
  344.         clr.l    (a6)+
  345.         clr.l    (a6)+
  346.         clr.l    (a6)+
  347.         clr.l    (a6)+
  348.         clr.l    (a6)+
  349.         move.l    d3,(a6)+
  350.         clr.w    (a6)+
  351.         move.l    d4,(a6)+
  352.         clr.w    (a6)+
  353.         clr.w    (a6)+
  354.         addq.l    #2,a6
  355.  
  356.         clr.l    (a6)+
  357.         clr.l    (a6)+
  358.         clr.l    (a6)+
  359.         clr.l    (a6)+
  360.         move.l    d3,(a6)+
  361.         clr.w    (a6)+
  362.         move.l    d4,(a6)+
  363.         clr.w    (a6)+
  364.  
  365.         clr.w    (a6)+
  366.         clr.l    (a6)+
  367.  
  368.         clr.l    (a6)+
  369.         clr.l    (a6)+
  370.         clr.l    (a6)+
  371.         clr.l    (a6)+
  372.         clr.l    (a6)+
  373.         dbra        d7,MGTK_Clear_A_Voice
  374.         rts
  375.  
  376. ***********************************************************************
  377. ***********    Initialisations du Module et des Samples    ***********
  378. ***********************************************************************
  379.  
  380. ; En Entrée :
  381. ; a0 = Adresse du Module
  382. ; a1 = Adresse de la fin de la zone de Travail (WorkSpace)
  383. ;
  384. ; En Sortie :
  385. ; d0 = 0 si tout c'est bien passé
  386. ;     -1 si problème de format
  387. ;     -2 si workspace trop petite pour décompactage pistes
  388. ;     -3 si pas assez de place pour préparer des Samples
  389. ;     -4 si pas de samples dans ce module (Song seulement)
  390.  
  391. MGTK_Init_Module_Samples
  392.         movem.l    d3-d7/a2-a6,-(sp)
  393.  
  394.         sf        MGTK_Replay_Paused
  395.         st        MGTK_Replay_Stopped
  396.  
  397.         movea.l    a0,a6
  398.         move.l    a6,MGTK_Module_Adr
  399.         movea.l    a1,a5
  400.         move.l    a5,MGTK_WorkSpace_Adr
  401.  
  402. ; On vérifie le format du Module
  403.         move.l    (a0)+,d0
  404.         lsr.l    #8,d0
  405.         cmp.l    #'MGT',d0
  406.         bne        MGTK_Init_Format_Error
  407.         cmp.l    #'©MCS',(a0)+
  408.         bne        MGTK_Init_Format_Error
  409.  
  410. ; Initialise les variables concernant les nombre et adresse de Structures
  411.         lea.l    MGTK_Nb_Voices(pc),a1
  412.         move.w    (a0)+,(a1)+            ; Nb Voices
  413.         move.w    (a0)+,(a1)+            ; Nb Musics
  414.         addq.l    #4,a0
  415.         move.w    (a0)+,(a1)+            ; Nb Tracks
  416.         move.w    (a0)+,d0
  417.         beq        MGTK_Init_No_Sample_Error
  418.         move.w    d0,(a1)+                ; Nb Samples
  419.  
  420.         addq.l    #6,a0                ; Attributs Inutilisés et 4 octets Réservés
  421.  
  422.         moveq.l    #6-1,d7
  423. MGTK_Init_Module_Adresses
  424.         move.l    (a0)+,d0                ; Offset Section
  425.         add.l    a6,d0                ; + Adresse Module
  426.         move.l    d0,(a1)+                ; = Adresse Section
  427.         dbra        d7,MGTK_Init_Module_Adresses
  428.  
  429.         move.l    (a0)+,(a1)+            ; Samples Length
  430.         move.l    (a0)+,(a1)+            ; Tailles Pistes Dépackées
  431.  
  432. ; On cherche à savoir si on a assez de place pour dépacker les pistes
  433.         move.l    ([MGTK_Tracks_Ptr,pc]),d0    ; Offset 1ère Piste
  434.         add.l    MGTK_Samples_Length(pc),d0    ; + Taille Samples
  435.         add.l    MGTK_Tracks_Length(pc),d0    ; + Pistes dépackées
  436.  
  437.         move.l    a5,d1                ; WorkSpace-Module Begin
  438.         sub.l    a6,d1                ; Taille maximale disponible
  439.  
  440.         cmp.l    d1,d0                ; Module Trop Grand ?
  441.         bgt        MGTK_Init_Module_Error
  442.  
  443. ; Calcul Taille du Bloc Pistes+Samples à déplacer à la fin de la WorkSpace
  444.         movea.l    MGTK_Samples_Data_Adr(pc),a0    ; Adresse 1er sample
  445.         adda.l    MGTK_Samples_Length(pc),a0    ; + Taille Samples
  446.  
  447.         move.l    a0,d0                    ; Fin module
  448.         sub.l    ([MGTK_Tracks_Ptr,pc]),d0    ; - Offset 1ère Piste
  449.         sub.l    a6,d0                    ; - début module
  450.  
  451.         movea.l    a5,a1                ; WorkSpace End
  452.         suba.l    d0,a5                ; Adresse du Bloc d'arrivée
  453.  
  454. MGTK_Init_Move
  455.         move.l    -(a0),-(a1)
  456.         move.l    -(a0),-(a1)
  457.         subq.l    #8,d0
  458.         bpl.s    MGTK_Init_Move
  459.  
  460. ; Maintenant on dépacke les Pistes
  461.  
  462.         movea.l    MGTK_Tracks_Ptr(pc),a0    ; Pointeurs de Pistes
  463.         lea.l    ([a0],a6.l),a1            ; Adresse 1ère Piste
  464.  
  465.         movea.l    a5,a4
  466.         suba.l    (a0),a4
  467.         
  468.         move.w    MGTK_Nb_Tracks(pc),d7
  469.         subq.w    #1,d7
  470. MGTK_Depack_Tracks
  471.         lea.l    ([a0],a4.l),a2        ; Prend Adresse Piste Packée
  472.         move.l    a1,(a0)+            ; Remplace par Adresse Piste Dépackée
  473.  
  474.         move.w    (a2)+,d6
  475.         move.w    d6,(a1)+                ; Nb Lignes Piste
  476.         moveq.l    #0,d5
  477.  
  478. MGTK_Depack_A_Track
  479.         move.b    (a2)+,d0
  480.         move.b    d0,d1
  481.         and.w    #$3,d1                ; Nb Lignes vides
  482.         beq.s    MGTK_Depack_Track_No_Empty_Line
  483.  
  484.         add.w    d1,d5
  485.         subq.w    #1,d1
  486.  
  487. MGTK_Depack_Track_Empty_Line
  488.         clr.l    (a1)+
  489.         clr.w    (a1)+
  490.         dbra        d1,MGTK_Depack_Track_Empty_Line
  491.  
  492. MGTK_Depack_Track_No_Empty_Line
  493.         lsr.b    #2,d0
  494.         moveq.l    #6-1,d2
  495. MGTK_Depack_Track_Note
  496.         moveq.l    #0,d1
  497.         lsr.b    d0
  498.         bcc.s    MGTK_Depack_Track_No_Byte
  499.         move.b    (a2)+,d1
  500. MGTK_Depack_Track_No_Byte
  501.         move.b    d1,(a1)+
  502.         dbra        d2,MGTK_Depack_Track_Note
  503.  
  504.         addq.w    #1,d5
  505.         cmp.w    d6,d5
  506.         blo.s    MGTK_Depack_A_Track
  507.  
  508.         dbra        d7,MGTK_Depack_Tracks
  509.  
  510. ; On prépare les samples au bouclage...
  511.  
  512.         movea.l    MGTK_WorkSpace_Adr(pc),a4
  513.         suba.l    MGTK_Samples_Length(pc),a4
  514.         suba.l    MGTK_Samples_Data_Adr(pc),a4
  515.         adda.l    a6,a4
  516.  
  517.         movea.l    MGTK_Samples_Infos_Adr(pc),a3
  518.         move.w    MGTK_Nb_Samples(pc),d7
  519.         subq.w    #1,d7
  520.  
  521. MGTK_Init_Samples
  522.         lea.l    ([Sample_Start,a3],a4.l),a0    ; Adresse Sample
  523.  
  524.         clr.l    Sample_Start(a3)            ; Pas de sample par défaut
  525.  
  526.         move.l    Sample_Length(a3),d6        ; Si longueur nulle
  527.         beq        MGTK_Init_Next_Sample        ; passe au suivant
  528.  
  529.         move.l    a1,d0                    ; On veut
  530.         addq.l    #1,d0                    ; adresse
  531.         and.b    #$fe,d0                    ; paire
  532.         move.l    d0,a1
  533.         move.l    a1,Sample_Start(a3)            ; Stocke Nouvelle Adresse
  534.  
  535.         move.l    Sample_Loop_Start(a3),d2        ; Début de Boucle
  536.         move.l    Sample_Loop_Length(a3),d3    ; Longueur de Boucle
  537.         move.l    Sample_Buffer_Length(a3),d4    ; Taille du Buffer
  538.         move.l    Sample_End_Length(a3),d5        ; Taille Fin Sample
  539.  
  540.         btst.b    #2,Sample_Attributes(a3)
  541.         beq.s    MGTK_Sample_8_Bits_1
  542.         lsl.l    d2
  543.         lsl.l    d3
  544.         lsl.l    d4
  545.         lsl.l    d5
  546.         lsl.l    d6
  547. MGTK_Sample_8_Bits_1
  548.         btst.b    #3,Sample_Attributes(a3)
  549.         beq.s    MGTK_Sample_Mono_1
  550.         lsl.l    d2
  551.         lsl.l    d3
  552.         lsl.l    d4
  553.         lsl.l    d5
  554.         lsl.l    d6
  555. MGTK_Sample_Mono_1
  556.  
  557.         move.l    d6,d0
  558.         bftst    Sample_Attributes(a3){6:2}
  559.         beq.s    MGTK_No_Loop                ; Sample bouclé ?
  560.  
  561.         move.l    d2,d0
  562.         add.l    d3,d0                    ; Fin de Boucle
  563.         move.l    d0,d6                    ; New Sample Length
  564. MGTK_Loop_Start
  565.         move.b    (a0)+,(a1)+                ; Recopie le sample
  566.         subq.l    #1,d0                    ; jusqu'à la fin
  567.         bne.s    MGTK_Loop_Start            ; de la boucle
  568.  
  569.         movea.l    a1,a2                    ; Adresse du 
  570.         suba.l    d3,a2                    ; Début de la Boucle
  571.         moveq.l    #0,d1                    ; Longueur de la Boucle
  572.  
  573. MGTK_Make_Loop
  574.         cmp.l    d4,d1                    ; Taille minimale
  575.         bhs.s    MGTK_Loop_Made                ; Ateinte ?
  576.  
  577.         move.l    d3,d0                    ; Longueur de la Boucle
  578. MGTK_MakeLoop
  579.         move.b    (a2)+,(a1)+                ; Recopie
  580.         subq.l    #1,d0                    ; encore
  581.         bne.s    MGTK_MakeLoop                ; la Boucle
  582.  
  583.         add.l    d3,d1
  584.         bra.s    MGTK_Make_Loop
  585.  
  586. MGTK_Loop_Made
  587.         move.l    d5,d0                    ; La Fin du Sample
  588.         beq.s    MGTK_End_Buffer
  589.  
  590. MGTK_No_Loop
  591.         move.b    (a0)+,(a1)+                ; Recopie
  592.         subq.l    #1,d0                    ; le sample
  593.         bne.s    MGTK_No_Loop                ; bêtement
  594.  
  595. MGTK_End_Buffer
  596.         clr.l    (a1)+                    ; Et met
  597.         clr.l    (a1)+                    ; du vide
  598.         subq.l    #8,d4                    ; après
  599.         bpl.s    MGTK_End_Buffer
  600.  
  601.         cmpa.l    a0,a1
  602.         bhi.s    MGTK_Init_Samples_Error
  603.  
  604.         btst.b    #2,Sample_Attributes(a3)
  605.         beq.s    MGTK_Sample_8_Bits_2
  606.         lsr.l    d6
  607. MGTK_Sample_8_Bits_2
  608.         btst.b    #3,Sample_Attributes(a3)
  609.         beq.s    MGTK_Sample_Mono_2
  610.         lsr.l    d6
  611. MGTK_Sample_Mono_2
  612.         move.l    d6,Sample_Length(a3)
  613.  
  614. MGTK_Init_Next_Sample
  615.         lea.l    Sample_Size(a3),a3            ; Sample suivant
  616.         dbra        d7,MGTK_Init_Samples
  617.  
  618.         move.l    a1,MGTK_Module_End_Adr
  619.  
  620.         bsr        MGTKClearVoices
  621.         movem.l    (sp)+,d3-d7/a2-a6
  622.         moveq.l    #0,d0
  623.         rts
  624.  
  625. MGTK_Init_No_Sample_Error
  626.         movem.l    (sp)+,d3-d7/a2-a6
  627.         moveq.l    #-4,d0
  628.         rts
  629. MGTK_Init_Samples_Error
  630.         movem.l    (sp)+,d3-d7/a2-a6
  631.         moveq.l    #-3,d0
  632.         rts
  633. MGTK_Init_Module_Error
  634.         movem.l    (sp)+,d3-d7/a2-a6
  635.         moveq.l    #-2,d0
  636.         rts
  637. MGTK_Init_Format_Error
  638.         movem.l    (sp)+,d3-d7/a2-a6
  639.         moveq.l    #-1,d0
  640.         rts
  641.  
  642. ***********************************************************************
  643. ***********               Initialisation DSP            ***********
  644. ***********************************************************************
  645.  
  646. ; Charge le Loader et Replay DSP et vérifie son fonctionnement
  647. ; En Sortie:
  648. ; d0 = 0 si tout c'est bien passé
  649. ;     -1 si le programme DSP n'a pu être chargé
  650.  
  651. MGTK_Init_DSP
  652.         pea.l    (a2)
  653.         pea.l    MGTKInitDSP(pc)
  654.         move.w    #38,-(sp)            ; Supexec
  655.         trap        #14                ; XBios
  656.         addq.l    #6,sp
  657.         movea.l    (sp)+,a2
  658.         move.l    MGTK_DSP_Ok(pc),d0
  659.         rts
  660. MGTKInitDSP
  661.         move.w    #113,-(sp)            ; DSP_RequestUniqueAbility
  662.         trap        #14                    ; XBios
  663.         addq.l    #2,sp
  664.  
  665.         move.w    d0,-(sp)                ; No Ability
  666.         pea.l    MGTK_DSP_Replay_Size.w    ; Longueur en Mots DSP
  667.         pea.l    MGTK_DSP_Replay_Code(pc)    ; Adresse du code binaire
  668.         move.w    #109,-(sp)            ; Dsp_ExecProg
  669.         trap        #14                    ; XBios
  670.         lea.l    12(sp),sp
  671.  
  672. MGTK_Connect
  673.         move.l    #87654321,$ffffa204.w
  674.         moveq.l    #0,d0
  675.  
  676. MGTK_Connect_Get
  677.         btst.b    #0,$ffffa202.w
  678.         bne.s    MGTK_DSP_Test
  679.         addq.l    #1,d0
  680.         cmp.l    #100000,d0
  681.         beq.s    MGTK_DSP_Error
  682.         bra.s    MGTK_Connect_Get
  683.  
  684. MGTK_DSP_Test
  685.         move.l    $ffffa204.w,d0
  686.         cmp.l    #12345678,d0
  687.  
  688.         move.l    #0,MGTK_DSP_Ok
  689.         rts
  690.  
  691. MGTK_DSP_Error
  692.         move.l    #-1,MGTK_DSP_Ok
  693.         rts
  694.  
  695. MGTK_DSP_Ok
  696.         ds.l        1
  697.  
  698. ***********************************************************************
  699. ***********        Initialisations Système Sonore        ***********
  700. ***********************************************************************
  701.  
  702. MGTK_Init_Sound
  703.         pea.l    (a2)
  704.         pea.l    MGTKInitSound(pc)
  705.         move.w    #38,-(sp)            ; Supexec
  706.         trap        #14                ; XBios
  707.         addq.l    #6,sp
  708.         movea.l    (sp)+,a2
  709.         rts
  710. MGTKInitSound
  711. * Stoppe la lecture DMA au cas où...
  712.         clr.b    $ffff8901.w
  713.  
  714. * DAC sur piste 0 (quartet fort)
  715.         move.b    #$0f,$ffff8920.w
  716.  
  717.  
  718. * Source External Input sur Horloge Interne 25.175 MHz, Handshaking Off
  719. * Source ADC Input sur Horloge Interne 25.175 MHz, Handshaking Off
  720.         move.b    #%00010001,$ffff8930.w
  721.  
  722. * Source DSP-Xmit sur Horloge Interne 25.175 MHz, DSP Tristated, Handshaking Off
  723. * Source DMA-Play sur Horloge Interne 25.175 MHz
  724.         move.b    #%00010001,$ffff8931.w
  725.  
  726. * Destination External Output connectée à Source DSP-Xmit, Handshaking Off
  727. * Destination DAC Output connecté à DSP-Xmit, Handshaking Off
  728.         move.b    #%00110011,$ffff8932.w
  729. * Destination DMA Record connectée à Source DSP-Xmit, Handshaking Off
  730. * Destination DSP-Rec connecté à DMA-Play, Handshaking Off, Tristated
  731.         move.b    #%00010011,$ffff8933.w
  732.  
  733. * Seulement Matrice et pas le PSG-Yamaha
  734.         move.b    #%10,$ffff8937.w
  735.         rts
  736.  
  737. MGTK_Save_Sound
  738.         pea.l    (a2)
  739.         pea.l    MGTKSaveSound(pc)
  740.         move.w    #38,-(sp)            ; Supexec
  741.         trap        #14                ; XBios
  742.         addq.l    #6,sp
  743.         movea.l    (sp)+,a2
  744.         rts
  745. MGTKSaveSound
  746.         lea.l    MGTK_Old_Sound_System(pc),a0
  747.         move.w    $ffff8900.w,(a0)+        ; Interruptions, Son DMA
  748.         bclr.b    #7,$ffff8901.w            ; Registres PlayBack
  749.         move.b    $ffff8903.w,(a0)+        ; Start - High
  750.         move.b    $ffff8905.w,(a0)+        ; Start - Med
  751.         move.b    $ffff8907.w,(a0)+        ; Start - Low
  752.         move.b    $ffff890f.w,(a0)+        ; End - High
  753.         move.b    $ffff8911.w,(a0)+        ; End - Med
  754.         move.b    $ffff8913.w,(a0)+        ; End - Low
  755.         bset.b    #7,$ffff8901.w            ; Registres Record
  756.         move.b    $ffff8903.w,(a0)+        ; Start - High
  757.         move.b    $ffff8905.w,(a0)+        ; Start - Med
  758.         move.b    $ffff8907.w,(a0)+        ; Start - Low
  759.         move.b    $ffff890f.w,(a0)+        ; End - High
  760.         move.b    $ffff8911.w,(a0)+        ; End - Med
  761.         move.b    $ffff8913.w,(a0)+        ; End - Low
  762.  
  763.         move.w    $ffff8920.w,(a0)+        ; Nb Voies, 8/16, Mono/Stereo
  764.         move.w    $ffff8930.w,(a0)+        ; Matrice : Sources
  765.         move.w    $ffff8932.w,(a0)+        ; Matrice : Destinations
  766.         move.w    $ffff8934.w,(a0)+        ; Prescales d'horloge
  767.         move.w    $ffff8936.w,(a0)+        ; Nb Voies Record,source ADDERIN
  768.         move.w    $ffff8938.w,(a0)+        ; Source ADC + Volumes entrées
  769.         move.w    $ffff893a.w,(a0)+        ; Volumes de Sortie
  770.         rts
  771.  
  772. MGTK_Restore_Sound
  773.         pea.l    (a2)
  774.         pea.l    MGTKRestoreSound(pc)
  775.         move.w    #38,-(sp)            ; Supexec
  776.         trap        #14                ; XBios
  777.         addq.l    #6,sp
  778.         movea.l    (sp)+,a2
  779.         rts
  780. MGTKRestoreSound
  781.         lea.l    MGTK_Old_Sound_System(pc),a0
  782.         move.w    (a0)+,d0
  783.         bclr.b    #7,$ffff8901.w            ; Registres PlayBack
  784.         move.b    (a0)+,$ffff8903.w        ; Start - High
  785.         move.b    (a0)+,$ffff8905.w        ; Start - Med
  786.         move.b    (a0)+,$ffff8907.w        ; Start - Low
  787.         move.b    (a0)+,$ffff890f.w        ; End - High
  788.         move.b    (a0)+,$ffff8911.w        ; End - Med
  789.         move.b    (a0)+,$ffff8913.w        ; End - Low
  790.         bset.b    #7,$ffff8901.w            ; Registres Record
  791.         move.b    (a0)+,$ffff8903.w        ; Start - High
  792.         move.b    (a0)+,$ffff8905.w        ; Start - Med
  793.         move.b    (a0)+,$ffff8907.w        ; Start - Low
  794.         move.b    (a0)+,$ffff890f.w        ; End - High
  795.         move.b    (a0)+,$ffff8911.w        ; End - Med
  796.         move.b    (a0)+,$ffff8913.w        ; End - Low
  797.         move.w    d0,$ffff8900.w            ; Interruptions, Son DMA
  798.  
  799.         move.w    (a0)+,$ffff8920.w        ; Nb Voies, 8/16, Mono/Stereo
  800.         move.w    (a0)+,$ffff8930.w        ; Matrice : Sources
  801.         move.w    (a0)+,$ffff8932.w        ; Matrice : Destinations
  802.         move.w    (a0)+,$ffff8934.w        ; Prescales d'horloge
  803.         move.w    (a0)+,$ffff8936.w        ; Nb Voies Record,source ADDERIN
  804.         move.w    (a0)+,$ffff8938.w        ; Source ADC + Volumes entrées
  805.         move.w    (a0)+,$ffff893a.w        ; Volumes de Sortie
  806.  
  807.         move.b    #$80+$14,$ffffa201.w    ; Efface Buffer Sample DSP
  808.         rts
  809.  
  810. ***********************************************************************
  811. ***********        Sauvegardes système sonore            ***********
  812. ***********************************************************************
  813.  
  814. MGTK_Old_Sound_System
  815.             ds.w        1            ; Interruptions, Son DMA
  816.             ds.b        3            ; Playback Start
  817.             ds.b        3            ; Playback End
  818.             ds.b        3            ; Record Start
  819.             ds.b        3            ; Record End
  820.             ds.w        1            ; Nb Voies, 8/16, Mono/Stereo
  821.             ds.w        1            ; Matrice : Sources
  822.             ds.w        1            ; Matrice : Destinations
  823.             ds.w        1            ; Prescales d'horloge
  824.             ds.w        1            ; Nb Voies Record,source ADDERIN
  825.             ds.w        1            ; Source ADC + Volumes entrées
  826.             ds.w        1            ; Volumes de Sortie
  827.  
  828. ***********************************************************************
  829. ***********           Controle des Interruptions            ***********
  830. ***********************************************************************
  831.  
  832. ; Installe l'interruption Timer A du Player
  833. ; Connecte le DSP à la matrice sonore
  834.  
  835. MGTK_Init_IT
  836.         pea.l    (a2)
  837.         pea.l    MGTK_Replay_Timer(pc)        ; Adresse Vecteur
  838.         moveq.l    #0,d0
  839.         move.b    MGTK_IT_Timer_Data(pc),d0
  840.         move.w    d0,-(sp)
  841.         move.b    MGTK_IT_Timer_Control(pc),d0
  842.         move.w    d0,-(sp)
  843.         clr.w    -(sp)                    ; Timer No 0
  844.         move.w    #31,-(sp)                    ; Xbtimer
  845.         trap        #14                        ; XBios
  846.         lea.l    12(sp),sp
  847.         pea.l    MGTKDSPSoundOn(pc)
  848.         move.w    #38,-(sp)                    ; Supexec
  849.         trap        #14                        ; XBios
  850.         addq.l    #6,sp
  851.         movea.l    (sp)+,a2
  852.         rts
  853. MGTKDSPSoundOn
  854.         bset.b    #7,$ffff8931.w                ; DSP Enabled
  855.         rts
  856.  
  857. ; Enlève l'interruption Timer A du Player
  858. ; Déconnecte le DSP de la matrice sonore
  859.  
  860. MGTK_Stop_IT
  861.         pea.l    (a2)
  862.         clr.l    -(sp)
  863.         clr.l    -(sp)                    ; Stoppe le
  864.         clr.w    -(sp)                    ; Timer A
  865.         move.w    #31,-(sp)                    ; Xbtimer
  866.         trap        #14                        ; XBios
  867.         lea.l    12(sp),sp
  868.         pea.l    MGTKDSPSoundOff(pc)
  869.         move.w    #38,-(sp)                    ; Supexec
  870.         trap        #14                        ; XBios
  871.         addq.l    #6,sp
  872.         movea.l    (sp)+,a2
  873.         rts
  874. MGTKDSPSoundOff
  875.         bclr.b    #7,$ffff8931.w                ; DSP Tristated
  876.         rts
  877.  
  878. ***********************************************************************
  879. ***********       Interruptions du Replay Soundtracker        ***********
  880. ***********************************************************************
  881.  
  882. MGTK_Replay_Timer
  883.         move.w    #$2700,sr
  884.  
  885.         move.b    MGTK_IT_Timer_Data(pc),$fffffa1f.w
  886.         move.b    MGTK_IT_Timer_Control(pc),$fffffa19.w
  887.  
  888. MGTK_Replay_IT
  889.         tst.b    MGTK_Replay_In_Service(pc)
  890.         beq.s    MGTK_Replay_Not_Satured
  891.  
  892.         addq.w    #1,MGTK_Replay_Satured
  893.         bclr.b    #5,$fffffa0f.w            ; à Cause du mode SEI
  894.         rte
  895.  
  896. MGTK_Replay_Not_Satured
  897. ; Signale au DSP qu'on veut causer à la routine Soundtracker
  898.         move.b    #$80+$13,$ffffa201.w    ; Host User 0, adresse $26
  899.  
  900.         SaveColor
  901.         CPUTimeColor        #$dd550088
  902.         movem.l    d0/a6,-(sp)
  903.         lea.l    $ffffa204.w,a6            ; Port Host
  904.  
  905. ; DSP es-tu là ?
  906.         move.l    (a6),d0
  907.         cmp.l    #'MGT',d0
  908.         beq.s    MGTK_Replay_No_Problem
  909.  
  910.         st        MGTK_Replay_Problem
  911.         bra.s    MGTK_Replay_Ret
  912.  
  913. MGTK_Replay_No_Problem
  914.         st        MGTK_Replay_In_Service
  915.  
  916. ; Envoie Master Volumes
  917.         clr.w    (a6)
  918.         move.w    MGTK_Master_Volume_Left(pc),2(a6)
  919.  
  920. ; Envoie Global Volume
  921.         move.w    MGTK_Global_Volume(pc),2(a6)
  922.  
  923. ; Envoie le Nombre de Voies pour le mixage (sans les 2 voies FX)
  924.         move.w    MGTK_Nb_Voices(pc),2(a6)
  925.  
  926. ; Prépare le pointeur sur les voies
  927.         move.l    #MGTK_FX_Voices,MGTK_Voices_Ptr
  928.  
  929. ; Autorise interruption de réception en provenance du DSP
  930.         move.l    #MGTK_Replay_Voices,$3fc.w
  931.         move.b    #$ff,-1(a6)            ; $ffffa203.w
  932.         bset.b    #0,-4(a6)                ; $ffffa200.w
  933.  
  934. MGTK_Replay_Ret
  935.         movem.l    (sp)+,d0/a6
  936.         RestoreColor
  937.         bclr.b    #5,$fffffa0f.w            ; à Cause du mode SEI
  938.         rte
  939.  
  940. ;
  941. ; Mixage des Pistes une par une
  942. ;
  943. MGTK_Replay_Voices
  944.         SaveColor
  945.         CPUTimeColor        #0
  946.         movem.l    d0-d3/a0/a5/a6,-(sp)
  947.  
  948.         lea.l    $ffffa204.w,a6
  949.         bclr.b    #0,-4(a6)            ; Inhibe Interruption Recéption
  950.  
  951.         move.w    #$2300,sr
  952.  
  953. MGTK_Replay_Get
  954.         move.w    2(a6),d0            ; Flag Nouvelle voie
  955.         beq        MGTK_Replay_No_More_Voices
  956.  
  957.         movea.l    MGTK_Voices_Ptr(pc),a5    ; Pointe sur la voie courante
  958.         add.l    #Voice_Size,MGTK_Voices_Ptr
  959.  
  960. ; Envoie les infos sur la voie
  961. ; d'abord la voie est-elle active ?
  962.  
  963.         tst.l    Voice_Sample_Start(a5)
  964.         bne.s    MGTK_Replay_Sample_Ok
  965.  
  966. MGTK_Replay_No_Voice
  967.         clr.l    (a6)
  968.         WaitDSPToGet
  969.         bra.s    MGTK_Replay_Get
  970.  
  971. MGTK_Replay_Sample_Ok
  972.         move.w    Voice_Left_Volume(a5),d0
  973.         beq.s    MGTK_Replay_No_Voice
  974.  
  975. ; Envoie Panoramique + Attributs
  976.         move.b    Voice_Sample_Attributes(a5),d3
  977.         move.w    d3,(a6)
  978.         move.w    d0,2(a6)
  979.  
  980. ; Envoie Volume
  981.         moveq.l    #0,d2
  982.         move.w    Voice_Sample_Volume(a5),d2
  983.         move.l    d2,(a6)
  984.  
  985. ; Envoie fréquence relative
  986. ; Explication du calcul :
  987. ; Fréquence de replay d'une note =
  988. ; Base du DO-4 * Periode du DO-4 / Periode de la Note
  989. ; Nous on veut le rapport avec la fréquence de Replay donc / Freq_Replay
  990. ; et résultat à virgule prémultiplié par $800000 pour le DSP
  991.  
  992.         move.l    #428/2,d1
  993.         moveq.l    #0,d0            ; d1:d0=$800000*(428*256)
  994.         move.w    MGTK_Replay_Frequency(pc),d2
  995.         divu.l    d2,d1:d0
  996.         mulu.l    Voice_Sample_Base(a5),d1:d0
  997.         divu.l    Voice_Sample_Period(a5),d1:d0
  998.  
  999.         move.l    #$800000*70/100,d1    ; 70% replay freq
  1000.  
  1001.         btst        #3,d3            ; Stereo ?
  1002.         bne.s    MGTK_Replay_Max_Freq
  1003.  
  1004.         tst.b    Voice_Left_Volume(a5)
  1005.         beq.s    MGTK_Replay_Mono_Panoramic
  1006.         tst.b    Voice_Right_Volume(a5)
  1007.         bne.s    MGTK_Replay_Max_Freq
  1008.  
  1009. MGTK_Replay_Mono_Panoramic
  1010.         move.l    #$800000*80/100,d1    ; 80% replay freq
  1011.  
  1012.         btst        #2,d3            ; 16 bits ?
  1013.         bne.s    MGTK_Replay_Max_Freq
  1014.  
  1015.         move.l    #$800000*90/100,d1    ; 90% replay freq
  1016.  
  1017. MGTK_Replay_Max_Freq
  1018.         cmp.l    d1,d0
  1019.         bhi        MGTK_Replay_030_Voice
  1020.  
  1021.         lsr.l    d0
  1022.         move.l    d0,(a6)
  1023.  
  1024. ;
  1025. ; Si la fréquence du sample est inférieure à xx% de la fréquence de replay
  1026. ;
  1027.  
  1028. ; Recoie longueur du sample jouée dans cette frame
  1029.         WaitDSPToGet
  1030.         move.l    (a6),d0
  1031.  
  1032.         movea.l    Voice_Sample_Start(a5),a0    ; Adresse Sample
  1033.         move.l    Voice_Sample_Position(a5),d1    ; Position
  1034.         move.l    d1,d2                    ; Courante
  1035.         add.l    d0,d2                    ; Position d'arrivée
  1036.  
  1037.         move.b    Voice_Sample_Attributes(a5),d3
  1038.         and.b    #%11,d3                    ; Type de Bouclage
  1039.         bne.s    MGTK_Replay_Loop
  1040.  
  1041. MGTK_Replay_No_Loop
  1042.         move.l    Voice_Sample_Length(a5),d3    ; Pas de Boucle
  1043.         add.l    Voice_Sample_End_Length(a5),d3
  1044.         cmp.l    d3,d2                    ; A-t'on dépassé la fin
  1045.         blt.s    MGTK_Replay_Pos_Ok            ; du Sample ?
  1046.  
  1047.         clr.l    Voice_Sample_Start(a5)        ; Oui, alors sample
  1048.         bra.s    MGTK_Replay_Pos_Ok            ; désactivé
  1049.  
  1050. MGTK_Replay_Loop
  1051.         cmp.l    Voice_Sample_Length(a5),d2    ; A-t'on dépassé la
  1052.         blt.s    MGTK_Replay_Pos_Ok            ; fin de la boucle
  1053.  
  1054.         sub.l    Voice_Sample_Loop_Length(a5),d2    ; Si oui, reboucle
  1055.         bra.s    MGTK_Replay_Loop
  1056.  
  1057. MGTK_Replay_Pos_Ok
  1058.         move.l    d2,Voice_Sample_Position(a5)    ; Nouvelle position
  1059.  
  1060.         btst.b    #2,Voice_Sample_Attributes(a5)
  1061.         bne.s    MGTK_Replay_16_Bits_Sample
  1062.  
  1063.         btst.b    #3,Voice_Sample_Attributes(a5)
  1064.         bne.s    MGTK_Replay_16_Bits_Mono_Sample
  1065.  
  1066. MGTK_Replay_8_Bits_Mono_Sample
  1067.         lea.l    (a0,d1.l),a0
  1068.         lsr.w    d0                    ; Envoi par paquet de deux
  1069.         bra.s    MGTK_Replay_Send_Sample
  1070.  
  1071. MGTK_Replay_16_Bits_Sample
  1072.         btst.b    #3,Voice_Sample_Attributes(a5)
  1073.         beq.s    MGTK_Replay_16_Bits_Mono_Sample
  1074.  
  1075. MGTK_Replay_16_Bits_Stereo_Sample
  1076.         lea.l    (a0,d1.l*2),a0
  1077.         lsl.w    d0
  1078.         addq.w    #1,d0
  1079.         
  1080. MGTK_Replay_16_Bits_Mono_Sample
  1081.         lea.l    (a0,d1.l*2),a0
  1082.  
  1083. MGTK_Replay_Send_Sample
  1084.         CPUTimeColor        #$dd550088
  1085.         addq.l    #2,a6                ; Port Host en word
  1086.  
  1087. MGTK_Send_Samples
  1088.         move.w    (a0)+,(a6)
  1089. MGTK_Send_Samples_Jump
  1090.         dbra        d0,MGTK_Send_Samples
  1091.  
  1092. ; Autorise interruption de réception en provenance du DSP
  1093.         bset.b    #0,-6(a6)                ; $ffffa200.w
  1094.  
  1095.         movem.l    (sp)+,d0-d3/a0/a5/a6
  1096.         RestoreColor
  1097.         rte
  1098.  
  1099. ;
  1100. ; Si la fréquence du sample est supérieure à xx% de la fréquence de replay
  1101. ;
  1102.  
  1103. MGTK_Replay_030_Voice
  1104.         clr.l    (a6)
  1105.  
  1106.         lsr.l    #7,d0                ; Freq_relative * 65536
  1107.         swap.w    d0                    ; Virgule poids fort
  1108.  
  1109.         movea.l    Voice_Sample_Start(a5),a0    ; Adresse Sample
  1110.         move.l    Voice_Sample_Position(a5),d2    ; Position Courante
  1111.  
  1112.         btst.b    #2,Voice_Sample_Attributes(a5)
  1113.         bne.s    MGTK_Replay_030_16_Bits_Sample
  1114.  
  1115.         btst.b    #3,Voice_Sample_Attributes(a5)
  1116.         bne.s    MGTK_Replay_030_Word_Sample
  1117.  
  1118. MGTK_Replay_030_8_Bits_Mono_Sample
  1119.         lea.l    (a0,d2.l),a0
  1120.         addq.l    #2,a6
  1121.         move.w    (a6),d1                ; Nb de Packets à envoyer - 1
  1122.         moveq.l    #0,d2
  1123.         lsr.w    d1
  1124.         bcc.s    MGTK_Replay_030_Send_8_Bits_Mono_Sample_Odd
  1125.  
  1126. MGTK_Replay_030_Send_8_Bits_Mono_Sample_Loop
  1127.         move.w    (a0,d2.w),d3
  1128.         addx.l    d0,d2
  1129.         move.b    (a0,d2.w),d3
  1130.         addx.l    d0,d2
  1131.         move.w    d3,(a6)
  1132. MGTK_Replay_030_Send_8_Bits_Mono_Sample_Odd
  1133.         move.w    (a0,d2.w),d3
  1134.         addx.l    d0,d2
  1135.         move.b    (a0,d2.w),d3
  1136.         addx.l    d0,d2
  1137.         move.w    d3,(a6)
  1138.         dbra        d1,MGTK_Replay_030_Send_8_Bits_Mono_Sample_Loop
  1139.         bra.s    MGTK_Replay_030_Check_Loop
  1140.  
  1141.  
  1142. MGTK_Replay_030_16_Bits_Sample
  1143.         btst.b    #3,Voice_Sample_Attributes(a5)
  1144.         beq.s    MGTK_Replay_030_Word_Sample
  1145.  
  1146. MGTK_Replay_030_16_Bits_Stereo_Sample
  1147.         lea.l    (a0,d2.l*4),a0
  1148.         addq.l    #2,a6
  1149.         move.w    (a6),d1                ; Nb de Packets à envoyer - 1
  1150.         moveq.l    #0,d2
  1151.  
  1152.         move.l    a5,-(sp)
  1153.         movea.l    a0,a5
  1154.  
  1155.         lsr.w    d1
  1156.         bcc.s    MGTK_Replay_030_16_Bits_Stereo_Sample_Odd
  1157.  
  1158. MGTK_Replay_030_16_Bits_Stereo_Sample_Loop
  1159.         move.w    (a5)+,(a6)
  1160.         addx.l    d0,d2
  1161.         move.w    (a5),(a6)
  1162.         lea.l    (a0,d2.w*4),a5
  1163. MGTK_Replay_030_16_Bits_Stereo_Sample_Odd
  1164.         move.w    (a5)+,(a6)
  1165.         addx.l    d0,d2
  1166.         move.w    (a5),(a6)
  1167.         lea.l    (a0,d2.w*4),a5
  1168.         dbra        d1,MGTK_Replay_030_16_Bits_Stereo_Sample_Loop
  1169.  
  1170.         movea.l    (sp)+,a5
  1171.         bra.s    MGTK_Replay_030_Check_Loop
  1172.  
  1173.         
  1174. MGTK_Replay_030_Word_Sample
  1175.         lea.l    (a0,d2.l*2),a0
  1176.         addq.l    #2,a6
  1177.         move.w    (a6),d1                ; Nb de Packets à envoyer - 1
  1178.         moveq.l    #0,d2
  1179.  
  1180.         lsr.w    d1
  1181.         bcs.s    MGTK_Replay_030_Word_Sample_Even
  1182.         move.w    (a0,d2.w*2),(a6)
  1183.         addx.l    d0,d2
  1184.         subq.w    #1,d1
  1185. MGTK_Replay_030_Word_Sample_Even
  1186.         lsr.w    d1
  1187.         bcc.s    MGTK_Replay_030_Word_Sample_Not_Four
  1188.  
  1189. MGTK_Replay_030_Word_Sample_Loop
  1190.         move.w    (a0,d2.w*2),(a6)
  1191.         addx.l    d0,d2
  1192.         move.w    (a0,d2.w*2),(a6)
  1193.         addx.l    d0,d2
  1194. MGTK_Replay_030_Word_Sample_Not_Four
  1195.         move.w    (a0,d2.w*2),(a6)
  1196.         addx.l    d0,d2
  1197.         move.w    (a0,d2.w*2),(a6)
  1198.         addx.l    d0,d2
  1199.         dbra        d1,MGTK_Replay_030_Word_Sample_Loop
  1200.  
  1201.  
  1202. MGTK_Replay_030_Check_Loop
  1203.         and.l    #$ffff,d2
  1204.         add.l    Voice_Sample_Position(a5),d2
  1205.  
  1206.         move.b    Voice_Sample_Attributes(a5),d3
  1207.         and.b    #%11,d3                    ; Type de Bouclage
  1208.         bne.s    MGTK_Replay_030_Loop
  1209.  
  1210. MGTK_Replay_030_No_Loop
  1211.         move.l    Voice_Sample_Length(a5),d3    ; Pas de Boucle
  1212.         add.l    Voice_Sample_End_Length(a5),d3
  1213.         cmp.l    d3,d2                    ; A-t'on dépassé la fin
  1214.         blt.s    MGTK_Replay_030_Pos_Ok        ; du Sample ?
  1215.  
  1216.         clr.l    Voice_Sample_Start(a5)        ; Oui, alors sample
  1217.         bra.s    MGTK_Replay_030_Pos_Ok        ; désactivé
  1218.  
  1219. MGTK_Replay_030_Loop
  1220.         cmp.l    Voice_Sample_Length(a5),d2    ; A-t'on dépassé la
  1221.         blt.s    MGTK_Replay_030_Pos_Ok        ; fin de la boucle
  1222.  
  1223.         sub.l    Voice_Sample_Loop_Length(a5),d2    ; Si oui, reboucle
  1224.         bra.s    MGTK_Replay_030_Loop
  1225.  
  1226. MGTK_Replay_030_Pos_Ok
  1227.         move.l    d2,Voice_Sample_Position(a5)    ; Nouvelle position
  1228.  
  1229.         subq.l    #2,a6                    ; Port Host en long
  1230.         bra        MGTK_Replay_Get
  1231.  
  1232. ;
  1233. ; Plus d'autres voies
  1234. ;
  1235.  
  1236. MGTK_Replay_No_More_Voices
  1237.         move.b    MGTK_Frequency_Divider+1(pc),$ffff8935.w
  1238.         sf        MGTK_Replay_In_Service
  1239.  
  1240. ; S'occupe de la partition
  1241.         move.w    MGTK_IT_Counter(pc),d0
  1242.         addq.w    #1,d0
  1243.         move.w    d0,MGTK_IT_Counter
  1244.         cmp.w    MGTK_IT_Number(pc),d0
  1245.         blo.s    MGTK_Replay_Not_Patterns
  1246.  
  1247.         CPUTimeColor        #$99990099
  1248.  
  1249.         clr.w    MGTK_IT_Counter
  1250.         movem.l    d4-d7/a1-a4,-(sp)
  1251.         bsr.s    MGTK_Play_Patterns
  1252.         movem.l    (sp)+,d4-d7/a1-a4
  1253.  
  1254. MGTK_Replay_Not_Patterns
  1255.         movem.l    (sp)+,d0-d3/a0/a5/a6
  1256.         RestoreColor
  1257.         rte
  1258.  
  1259. MGTK_Voices_Ptr
  1260.         ds.l        1
  1261.  
  1262. ***********************************************************************
  1263. ***********                Gestion Patterns            ***********
  1264. ***********************************************************************
  1265.  
  1266. MGTK_Play_Patterns
  1267.         addq.b    #1,MGTK_Music_Counter
  1268.         move.b    MGTK_Music_Counter(pc),d0
  1269.         cmp.b    MGTK_Music_Speed(pc),d0
  1270.         blo        MGTK_No_New_Note
  1271.  
  1272.         clr.b    MGTK_Music_Counter
  1273.  
  1274.         tst.b    MGTK_Pattern_Break_Flag(pc)
  1275.         bne.s    MGTK_New_Pattern
  1276.  
  1277.         tst.b    MGTK_Pattern_Delay_Time(pc)
  1278.         beq.s    MGTK_No_Pattern_Delay
  1279.  
  1280.         subq.b    #1,MGTK_Pattern_Delay_Time
  1281.         bra        MGTK_No_New_Note
  1282.  
  1283. MGTK_No_Pattern_Delay
  1284.         tst.b    MGTK_Pattern_Loop_Flag(pc)
  1285.         beq.s    MGTK_No_Pattern_Loop
  1286.  
  1287.         move.w    MGTK_Pattern_Loop_Position(pc),MGTK_Pattern_Position
  1288.         sf        MGTK_Pattern_Loop_Flag
  1289.         bra        MGTK_New_Notes
  1290.  
  1291. MGTK_No_Pattern_Loop
  1292.         tst.b    MGTK_Position_Jump_Flag(pc)
  1293.         beq.s    MGTK_New_Line
  1294.  
  1295.         move.w    MGTK_Position_Jump_Position(pc),d0
  1296.         sf        MGTK_Position_Jump_Flag
  1297.         clr.w    MGTK_Pattern_Break_Position
  1298.         bra.s    MGTK_New_Position
  1299.  
  1300. MGTK_New_Line
  1301.         addq.w    #1,MGTK_Pattern_Position
  1302.         move.w    MGTK_Pattern_Position(pc),d0
  1303.         cmp.w    MGTK_Pattern_Length(pc),d0
  1304.         blo.s    MGTK_New_Notes
  1305.  
  1306. MGTK_New_Pattern
  1307.         move.w    MGTK_Music_Position(pc),d0
  1308.         addq.w    #1,d0
  1309.  
  1310. MGTK_New_Position
  1311.         move.w    MGTK_Pattern_Break_Position(pc),MGTK_Pattern_Position
  1312.         clr.w    MGTK_Pattern_Break_Position
  1313.         sf        MGTK_Pattern_Break_Flag
  1314.  
  1315.         cmp.w    MGTK_Music_Length(pc),d0
  1316.         blo.s    MGTK_No_Restart
  1317.  
  1318.         move.w    MGTK_Music_Restart(pc),d0
  1319.         bne.s    MGTK_No_Restart_Tempo
  1320.  
  1321.         move.b    MGTK_Initial_Speed(pc),MGTK_Music_Speed
  1322.         move.b    MGTK_Initial_Tempo(pc),MGTK_Music_Tempo
  1323.         bsr        MGTK_Search_Values_for_Tempo
  1324.  
  1325. MGTK_No_Restart_Tempo
  1326.         tst.b    MGTK_Restart_Loop(pc)
  1327.         bne.s    MGTK_No_Restart
  1328.  
  1329.         st        MGTK_Restart_Done
  1330.         sf        MGTK_Replay_Paused
  1331.         st        MGTK_Replay_Stopped
  1332.         clr.b    $fffffa19.w            ; Coupe Timer
  1333.         bclr.b    #5,$fffffa07.w            ; Désautorise Timer
  1334.         bclr.b    #5,$fffffa13.w            ; DéMaske Timer
  1335.         bclr.b    #7,$ffff8931.w            ; DSP Tristated
  1336.  
  1337. MGTK_No_Restart
  1338.         move.w    d0,MGTK_Music_Position
  1339.  
  1340. MGTK_New_Notes
  1341.         movea.l    MGTK_Sequence_Adr(pc),a0
  1342.         move.w    MGTK_Music_Position(pc),d0
  1343.         move.w    MGTK_Nb_Voices(pc),d1
  1344.         add.w    d1,d1
  1345.         addq.w    #2,d1                    ; Pattern Length
  1346.         mulu.w    (a0,d0.w*2),d1
  1347. ; Pointe sur numéros pistes
  1348.         lea.l    ([MGTK_Patterns_Adr,pc],d1.l),a4
  1349.         move.w    (a4)+,MGTK_Pattern_Length
  1350.  
  1351.         lea.l    MGTK_Voices(pc),a6
  1352.         move.w    MGTK_Nb_Voices(pc),d7
  1353.         subq.w    #1,d7
  1354. MGTK_New_Notes_Loop
  1355.         bsr.s    MGTK_Play_Voice
  1356.  
  1357.         lea.l    Voice_Size(a6),a6
  1358.         dbra        d7,MGTK_New_Notes_Loop
  1359.         rts
  1360.  
  1361.  
  1362. MGTK_Play_Voice
  1363.         lea.l    MGTK_Track_0(pc),a0
  1364.         move.w    (a4)+,d0
  1365.         subq.w    #1,d0
  1366.         bmi.s    MGTK_Play_Track
  1367.  
  1368.         movea.l    ([MGTK_Tracks_Ptr,pc],d0.w*4),a0
  1369.         move.w    MGTK_Pattern_Position(pc),d0
  1370.         mulu.w    #6,d0
  1371.         addq.w    #2,d0                ; Track Length
  1372.         adda.w    d0,a0
  1373.  
  1374. MGTK_Play_Track
  1375.         move.b    (a0)+,Voice_Note(a6)
  1376.         move.b    (a0)+,Voice_Sample(a6)
  1377.         move.b    (a0)+,Voice_Vol_Command(a6)
  1378.         move.b    (a0)+,Voice_Command(a6)
  1379.         move.w    (a0),Voice_Parameter1(a6)
  1380.  
  1381. MGTK_Check_Sample
  1382.         moveq.l    #0,d2
  1383.         move.b    Voice_Sample(a6),d2
  1384.         beq.s    MGTK_Check_Efx_Volume
  1385.  
  1386.         subq.w    #1,d2
  1387.         mulu.w    #Sample_Size,d2
  1388.         lea.l    ([MGTK_Samples_Infos_Adr,pc],d2.w),a3
  1389.         move.l    Sample_Start(a3),Voice_Start(a6)
  1390.         move.l    Sample_Length(a3),Voice_Length(a6)
  1391.         move.l    Sample_Loop_Length(a3),Voice_Loop_Length(a6)
  1392.         move.l    Sample_End_Length(a3),Voice_End_Length(a6)
  1393.         clr.l    Voice_Sample_Offset(a6)
  1394.         move.l    Sample_Base(a3),Voice_Base(a6)
  1395.         move.b    Sample_Attributes(a3),Voice_Attributes(a6)
  1396.         move.w    Sample_Volume(a3),Voice_Volume(a6)
  1397.         move.w    Sample_Volume(a3),Voice_Sample_Volume(a6)
  1398.         move.w    Sample_Panoramic(a3),d0
  1399.         beq.s    MGTK_Check_Sample_No_Panoramic
  1400.         move.w    d0,Voice_Left_Volume(a6)
  1401. MGTK_Check_Sample_No_Panoramic
  1402.         moveq.l    #0,d0
  1403.         move.b    Sample_Fine_Tune(a3),d0
  1404.         mulu.w    #12*8*4,d0
  1405.         move.w    d0,Voice_Sample_Fine_Tune(a6)
  1406.  
  1407. MGTK_Check_Efx_Volume
  1408.         moveq.l    #0,d0
  1409.         move.b    Voice_Vol_Command(a6),d0
  1410.         beq.s    MGTK_Check_Efx_0
  1411.  
  1412.         move.w    d0,d1
  1413.         and.b    #$0f,d0
  1414.         lsr.b    #4,d1
  1415.         cmp.b    #$6,d1                ; Pas de slide
  1416.         beq.s    MGTK_Check_Efx_0
  1417.         cmp.b    #$7,d1                ; au 1er tick
  1418.         beq.s    MGTK_Check_Efx_0
  1419.         cmp.b    #$f,d1
  1420.         beq        MGTK_Vol_Set_Tone_Portamento
  1421.  
  1422.         jsr        ([Jump_Table_Vol,pc,d1.w*4])
  1423.  
  1424. MGTK_Check_Efx_0
  1425.         moveq.l    #0,d0
  1426.         move.b    Voice_Command(a6),d0
  1427.         jsr        ([Jump_Table_0,pc,d0.w*4])
  1428.  
  1429. MGTK_Check_Note
  1430.         moveq.l    #0,d0
  1431.         move.b    Voice_Note(a6),d0
  1432.         beq.s    MGTK_Check_Efx_1
  1433.  
  1434.         sub.b    #12,d0
  1435.         lea.l    MGTK_Periods_Table(pc),a0
  1436.         adda.w    Voice_Sample_Fine_Tune(a6),a0
  1437.         move.l    (a0,d0.w*4),Voice_Period(a6)
  1438.  
  1439.         cmp.b    #$1d,Voice_Command(a6)
  1440.         bne.s    MGTK_No_Note_Delay
  1441.         tst.b    Voice_Parameter1(a6)
  1442.         beq.s    MGTK_No_Note_Delay
  1443.         rts
  1444.  
  1445. MGTK_No_Note_Delay
  1446.         move.l    Voice_Start(a6),Voice_Sample_Start(a6)
  1447.         move.l    Voice_Length(a6),Voice_Sample_Length(a6)
  1448.         move.l    Voice_Loop_Length(a6),Voice_Sample_Loop_Length(a6)
  1449.         move.l    Voice_End_Length(a6),Voice_Sample_End_Length(a6)
  1450.         move.l    Voice_Sample_Offset(a6),Voice_Sample_Position(a6)
  1451.         move.l    Voice_Base(a6),Voice_Sample_Base(a6)
  1452.         move.b    Voice_Attributes(a6),Voice_Sample_Attributes(a6)
  1453.         move.l    Voice_Period(a6),Voice_Sample_Period(a6)
  1454.  
  1455.         btst.b    #2,Voice_Vibrato_Waveform(a6)
  1456.         bne.s    MGTK_Vibrato_No_Reset
  1457.         clr.b    Voice_Vibrato_Position(a6)
  1458. MGTK_Vibrato_No_Reset
  1459.  
  1460.         btst.b    #2,Voice_Tremolo_Waveform(a6)
  1461.         bne.s    MGTK_Tremolo_No_Reset
  1462.         clr.b    Voice_Tremolo_Position(a6)
  1463. MGTK_Tremolo_No_Reset
  1464.  
  1465. MGTK_Check_Efx_1
  1466.         moveq.l    #0,d0
  1467.         move.b    Voice_Command(a6),d0
  1468.         jmp        ([Jump_Table_1,pc,d0.w*4])
  1469.  
  1470.  
  1471. MGTK_No_New_Note
  1472.         lea.l    MGTK_Voices(pc),a6
  1473.         move.w    MGTK_Nb_Voices(pc),d7
  1474.         subq.w    #1,d7
  1475. MGTK_No_New_Note_Loop
  1476.  
  1477.         moveq.l    #0,d0        
  1478.         move.b    Voice_Vol_Command(a6),d0
  1479.         beq.s    MGTK_Check_Efx_2
  1480.  
  1481.         move.w    d0,d1
  1482.         and.b    #$0f,d0
  1483.         lsr.b    #4,d1
  1484.         jsr        ([Jump_Table_Vol,pc,d1.w*4])
  1485.  
  1486. MGTK_Check_Efx_2
  1487.         moveq.l    #0,d0
  1488.         move.b    Voice_Command(a6),d0
  1489.         jsr        ([Jump_Table_2,pc,d0.w*4])
  1490.  
  1491.         lea.l    Voice_Size(a6),a6
  1492.         dbra        d7,MGTK_No_New_Note_Loop
  1493.         rts
  1494.  
  1495.  
  1496. Jump_Table_Vol
  1497.         dc.l        MGTK_Return,MGTK_Vol_Change
  1498.         dc.l        MGTK_Vol_Change,MGTK_Vol_Change
  1499.         dc.l        MGTK_Vol_Change,MGTK_Vol_Maxi
  1500.         dc.l        MGTK_Vol_Slide_Down,MGTK_Vol_Slide_Up
  1501.         dc.l        MGTK_Vol_Fine_Slide_Down,MGTK_Vol_Fine_Slide_Up
  1502.         dc.l        MGTK_Vol_Set_Vibrato_Speed,MGTK_Vol_Vibrato
  1503.         dc.l        MGTK_Vol_Set_Panoramic,MGTK_Vol_Pan_Slide_Left
  1504.         dc.l        MGTK_Vol_Pan_Slide_Right,MGTK_Tone_Portamento_No_Change
  1505.  
  1506. MGTK_Vol_Change
  1507.         move.b    Voice_Vol_Command(a6),d0
  1508.         sub.b    #$10,d0
  1509.         lsl.w    #4,d0
  1510.         move.w    d0,Voice_Volume(a6)
  1511.         move.w    d0,Voice_Sample_Volume(a6)
  1512.         clr.b    Voice_Vol_Command(a6)
  1513.         rts
  1514.  
  1515. MGTK_Vol_Maxi
  1516.         move.w    #$400,Voice_Volume(a6)
  1517.         move.w    #$400,Voice_Sample_Volume(a6)
  1518.         clr.b    Voice_Vol_Command(a6)
  1519.         rts
  1520.  
  1521. MGTK_Vol_Slide_Down
  1522.         lsl.w    #4,d0
  1523.         sub.w    d0,Voice_Volume(a6)
  1524.         bpl.s    MGTK_Vol_Slide_Down_Ok
  1525.  
  1526.         clr.w    Voice_Volume(a6)
  1527.         clr.b    Voice_Vol_Command(a6)
  1528.  
  1529. MGTK_Vol_Slide_Down_Ok
  1530.         move.w    Voice_Volume(a6),Voice_Sample_Volume(a6)
  1531.         rts
  1532.  
  1533. MGTK_Vol_Slide_Up
  1534.         lsl.w    #4,d0
  1535.         add.w    d0,Voice_Volume(a6)
  1536.         cmp.w    #$400,Voice_Volume(a6)
  1537.         ble.s    MGTK_Vol_Slide_Up_Ok
  1538.  
  1539.         move.w    #$400,Voice_Volume(a6)
  1540.         clr.b    Voice_Vol_Command(a6)
  1541.  
  1542. MGTK_Vol_Slide_Up_Ok
  1543.         move.w    Voice_Volume(a6),Voice_Sample_Volume(a6)
  1544.         rts
  1545.  
  1546.  
  1547. MGTK_Vol_Fine_Slide_Down
  1548.         lsl.w    #4,d0
  1549.         sub.w    d0,Voice_Volume(a6)
  1550.         bpl.s    MGTK_Vol_Fine_Slide_Down_Ok
  1551.         clr.w    Voice_Volume(a6)
  1552.  
  1553. MGTK_Vol_Fine_Slide_Down_Ok
  1554.         move.w    Voice_Volume(a6),Voice_Sample_Volume(a6)
  1555.         clr.b    Voice_Vol_Command(a6)
  1556.         rts
  1557.  
  1558. MGTK_Vol_Fine_Slide_Up
  1559.         lsl.w    #4,d0
  1560.         add.w    d0,Voice_Volume(a6)
  1561.         cmp.w    #$400,Voice_Volume(a6)
  1562.         ble.s    MGTK_Vol_Fine_Slide_Up_Ok
  1563.         move.w    #$400,Voice_Volume(a6)
  1564.  
  1565. MGTK_Vol_Fine_Slide_Up_Ok
  1566.         move.w    Voice_Volume(a6),Voice_Sample_Volume(a6)
  1567.         clr.b    Voice_Vol_Command(a6)
  1568.         rts
  1569.  
  1570.  
  1571. MGTK_Vol_Set_Vibrato_Speed
  1572.         move.b    d0,Voice_Vibrato_Speed(a6)
  1573.         clr.b    Voice_Vol_Command(a6)
  1574.         rts
  1575.  
  1576. MGTK_Vol_Vibrato
  1577.         lsl.w    #8,d0
  1578.         beq        MGTK_Vibrato_2
  1579.         move.w    d0,Voice_Vibrato_Depth(a6)
  1580.         bra        MGTK_Vibrato_2
  1581.  
  1582.  
  1583. MGTK_Vol_Set_Panoramic
  1584.         move.w    (MGTK_Panoramics_Table,pc,d0.w*2),Voice_Left_Volume(a6)
  1585.         clr.b    Voice_Vol_Command(a6)
  1586.         rts
  1587.  
  1588.  
  1589. MGTK_Vol_Pan_Slide_Left
  1590.         move.b    Voice_Left_Volume(a6),d1
  1591.         add.w    d0,d1
  1592.         cmp.w    #$ff,d1
  1593.         ble.s    MGTK_Vol_Pan_Slide_Left_1
  1594.         move.w    #$ff,d1
  1595. MGTK_Vol_Pan_Slide_Left_1
  1596.         move.b    d1,Voice_Left_Volume(a6)
  1597.  
  1598.         move.b    Voice_Right_Volume(a6),d1
  1599.         sub.w    d0,d1
  1600.         bpl.s    MGTK_Vol_Pan_Slide_Left_2
  1601.         moveq.l    #0,d1
  1602. MGTK_Vol_Pan_Slide_Left_2
  1603.         move.b    d1,Voice_Right_Volume(a6)
  1604.         rts
  1605.  
  1606. MGTK_Vol_Pan_Slide_Right
  1607.         move.b    Voice_Left_Volume(a6),d1
  1608.         sub.w    d0,d1
  1609.         bpl.s    MGTK_Vol_Pan_Slide_Right_1
  1610.         moveq.l    #0,d1
  1611. MGTK_Vol_Pan_Slide_Right_1
  1612.         move.b    d1,Voice_Left_Volume(a6)
  1613.  
  1614.         move.b    Voice_Right_Volume(a6),d1
  1615.         add.w    d0,d1
  1616.         cmp.w    #$ff,d1
  1617.         ble.s    MGTK_Vol_Pan_Slide_Right_2
  1618.         moveq.l    #-1,d1
  1619. MGTK_Vol_Pan_Slide_Right_2
  1620.         move.b    d1,Voice_Right_Volume(a6)
  1621.         rts
  1622.  
  1623.  
  1624. MGTK_Vol_Set_Tone_Portamento
  1625.         lsl.w    #8,d0
  1626.         move.l    d0,Voice_Tone_Port_Speed(a6)
  1627.  
  1628.         moveq.l    #0,d0
  1629.         move.b    Voice_Note(a6),d0
  1630.         beq.s    MGTK_Vol_Set_Tone_Portamento_Ret
  1631.         sub.w    #12,d0
  1632.         lea.l    MGTK_Periods_Table(pc),a0
  1633.         adda.w    Voice_Sample_Fine_Tune(a6),a0
  1634.         move.l    (a0,d0.w*4),d0
  1635.  
  1636.         move.l    d0,Voice_Tone_Port_Period(a6)
  1637.         move.l    Voice_Period(a6),d1
  1638.         sf        Voice_Tone_Port_Direction(a6)
  1639.         cmp.l    d1,d0
  1640.         beq.s    MGTK_Vol_Clear_Tone_Portamento
  1641.         bge.s    MGTK_Vol_Set_Tone_Portamento_Ret
  1642.         st        Voice_Tone_Port_Direction(a6)
  1643.  
  1644. MGTK_Vol_Set_Tone_Portamento_Ret
  1645.         rts
  1646.  
  1647. MGTK_Vol_Clear_Tone_Portamento
  1648.         clr.l    Voice_Tone_Port_Period(a6)
  1649.         rts
  1650.  
  1651. Jump_Table_0
  1652.         dc.l        MGTK_Return,MGTK_Return
  1653.         dc.l        MGTK_Return,MGTK_Set_Tone_Portamento
  1654.         dc.l        MGTK_Return,MGTK_Set_Tone_Portamento
  1655.         dc.l        MGTK_Return,MGTK_Return
  1656.         dc.l        MGTK_Return,MGTK_Sample_Offset
  1657.         dc.l        MGTK_Return,MGTK_Return
  1658.         dc.l        MGTK_Return,MGTK_Return
  1659.         dc.l        MGTK_Return,MGTK_Return
  1660.  
  1661.         dc.l        MGTK_Return,MGTK_Return
  1662.         dc.l        MGTK_Return,MGTK_Return
  1663.         dc.l        MGTK_Return,MGTK_Return
  1664.         dc.l        MGTK_Return,MGTK_Return
  1665.         dc.l        MGTK_Return,MGTK_Return
  1666.         dc.l        MGTK_Return,MGTK_Return
  1667.         dc.l        MGTK_Return,MGTK_Note_Delay
  1668.         dc.l        MGTK_Return,MGTK_Return
  1669.  
  1670.         dc.l        MGTK_Return,MGTK_Return
  1671.         dc.l        MGTK_Return,MGTK_Return
  1672.         dc.l        MGTK_Return,MGTK_Return
  1673.         dc.l        MGTK_Return,MGTK_Return
  1674.         dc.l        MGTK_Return,MGTK_Return
  1675.         dc.l        MGTK_Return,MGTK_Return
  1676.         dc.l        MGTK_Return,MGTK_Return
  1677.         dc.l        MGTK_Return,MGTK_Return
  1678.  
  1679.         dc.l        MGTK_Return,MGTK_Return
  1680.         dc.l        MGTK_Return,MGTK_Return
  1681.         dc.l        MGTK_Return,MGTK_Return
  1682.         dc.l        MGTK_Return,MGTK_Return
  1683.         dc.l        MGTK_Return,MGTK_Return
  1684.         dc.l        MGTK_Return,MGTK_Return
  1685.         dc.l        MGTK_Return,MGTK_Return
  1686.         dc.l        MGTK_Return,MGTK_Return
  1687.  
  1688. Jump_Table_1
  1689.         dc.l        MGTK_Period_Nop,MGTK_Period_Nop
  1690.         dc.l        MGTK_Period_Nop,MGTK_Period_Nop
  1691.         dc.l        MGTK_Period_Nop,MGTK_Period_Nop
  1692.         dc.l        MGTK_Period_Nop,MGTK_Period_Nop
  1693.         dc.l        MGTK_Panning,MGTK_Period_Nop
  1694.         dc.l        MGTK_Period_Nop,MGTK_Position_Jump
  1695.         dc.l        MGTK_Volume_Change,MGTK_Pattern_Break
  1696.         dc.l        MGTK_Period_Nop,MGTK_Set_Speed_Tempo
  1697.  
  1698.         dc.l        MGTK_Return,MGTK_Portamento_Up
  1699.         dc.l        MGTK_Portamento_Down,MGTK_Set_Glissando_Control
  1700.         dc.l        MGTK_Set_Vibrato_Waveform,MGTK_Return
  1701.         dc.l        MGTK_Pattern_Loop,MGTK_Set_Tremolo_Waveform
  1702.         dc.l        MGTK_Set_Panoramic,MGTK_Note_Retrig_Plus_Volume_Slide
  1703.         dc.l        MGTK_Fine_Volume_Slide_Up,MGTK_Fine_Volume_Slide_Down
  1704.         dc.l        MGTK_Note_Cut,MGTK_Return
  1705.         dc.l        MGTK_Pattern_Delay,MGTK_Return
  1706.  
  1707.         dc.l        MGTK_Arpeggio3,MGTK_Period_Nop
  1708.         dc.l        MGTK_Arpeggio5,MGTK_Period_Nop
  1709.         dc.l        MGTK_Note_Slide,MGTK_Period_Nop
  1710.         dc.l        MGTK_Period_Nop,MGTK_Period_Nop
  1711.         dc.l        MGTK_Period_Nop,MGTK_Period_Nop
  1712.         dc.l        MGTK_Period_Nop,MGTK_Period_Nop
  1713.         dc.l        MGTK_Period_Nop,MGTK_Period_Nop
  1714.         dc.l        MGTK_Period_Nop,MGTK_Period_Nop
  1715.  
  1716.         dc.l        MGTK_Set_Master_Volume,MGTK_Set_Global_Volume
  1717.         dc.l        MGTK_Period_Nop,MGTK_Global_Volume_Slide
  1718.         dc.l        MGTK_Set_Stereo,MGTK_Period_Nop
  1719.         dc.l        MGTK_Stereo_Slide,MGTK_Set_Base
  1720.         dc.l        MGTK_Release_Sample,MGTK_Period_Nop
  1721.         dc.l        MGTK_Period_Nop,MGTK_Period_Nop
  1722.         dc.l        MGTK_Period_Nop,MGTK_Period_Nop
  1723.         dc.l        MGTK_Period_Nop,MGTK_Period_Nop
  1724.  
  1725. Jump_Table_2
  1726.         dc.l        MGTK_Arpeggio,MGTK_Portamento_Up
  1727.         dc.l        MGTK_Portamento_Down,MGTK_Tone_Portamento
  1728.         dc.l        MGTK_Vibrato,MGTK_Tone_Portamento_Plus_Volume_Slide
  1729.         dc.l        MGTK_Vibrato_Plus_Volume_Slide,MGTK_Tremolo
  1730.         dc.l        MGTK_Return,MGTK_Return
  1731.         dc.l        MGTK_Volume_Slide,MGTK_Return
  1732.         dc.l        MGTK_Return,MGTK_Return
  1733.         dc.l        MGTK_Return,MGTK_Return
  1734.  
  1735.         dc.l        MGTK_Return,MGTK_Return
  1736.         dc.l        MGTK_Return,MGTK_Return
  1737.         dc.l        MGTK_Return,MGTK_Return
  1738.         dc.l        MGTK_Return,MGTK_Return
  1739.         dc.l        MGTK_Return,MGTK_Note_Retrig_Plus_Volume_Slide
  1740.         dc.l        MGTK_Return,MGTK_Return
  1741.         dc.l        MGTK_Note_Cut,MGTK_Note_Delay
  1742.         dc.l        MGTK_Return,MGTK_Return
  1743.  
  1744.         dc.l        MGTK_Arpeggio3,MGTK_Arpeggio4
  1745.         dc.l        MGTK_Arpeggio5,MGTK_Note_Slide
  1746.         dc.l        MGTK_Return,MGTK_Tremor
  1747.         dc.l        MGTK_Return,MGTK_Return
  1748.         dc.l        MGTK_Return,MGTK_Return
  1749.         dc.l        MGTK_Return,MGTK_Return
  1750.         dc.l        MGTK_Return,MGTK_Return
  1751.         dc.l        MGTK_Return,MGTK_Return
  1752.  
  1753.         dc.l        MGTK_Period_Nop,MGTK_Period_Nop
  1754.         dc.l        MGTK_Global_Volume_Slide,MGTK_Period_Nop
  1755.         dc.l        MGTK_Period_Nop,MGTK_Stereo_Slide
  1756.         dc.l        MGTK_Period_Nop,MGTK_Period_Nop
  1757.         dc.l        MGTK_Period_Nop,MGTK_Period_Nop
  1758.         dc.l        MGTK_Period_Nop,MGTK_Period_Nop
  1759.         dc.l        MGTK_Period_Nop,MGTK_Period_Nop
  1760.         dc.l        MGTK_Period_Nop,MGTK_Period_Nop
  1761.  
  1762.  
  1763. MGTK_Find_Period
  1764.         cmp.l    12*4(a0),d0
  1765.         bhs.s    MGTK_Do_Find_Period
  1766.         lea.l    12*4(a0),a0
  1767.         cmp.l    12*4(a0),d0
  1768.         bhs.s    MGTK_Do_Find_Period
  1769.         lea.l    12*4(a0),a0
  1770.         cmp.l    12*4(a0),d0
  1771.         bhs.s    MGTK_Do_Find_Period
  1772.         lea.l    12*4(a0),a0
  1773.         cmp.l    12*4(a0),d0
  1774.         bhs.s    MGTK_Do_Find_Period
  1775.         lea.l    12*4(a0),a0
  1776.         cmp.l    12*4(a0),d0
  1777.         bhs.s    MGTK_Do_Find_Period
  1778.         lea.l    12*4(a0),a0
  1779.         cmp.l    12*4(a0),d0
  1780.         bhs.s    MGTK_Do_Find_Period
  1781.         lea.l    12*4(a0),a0
  1782.         cmp.l    12*4(a0),d0
  1783.         bhs.s    MGTK_Do_Find_Period
  1784.         lea.l    12*4(a0),a0
  1785.  
  1786. MGTK_Do_Find_Period
  1787.         moveq.l    #12-1,d3
  1788. MGTK_Find_Period_Loop
  1789.         cmp.l    (a0)+,d0
  1790.         dbhs        d3,MGTK_Find_Period_Loop
  1791.         blo.s    MGTK_Period_Found
  1792.         subq.l    #4,a0
  1793. MGTK_Period_Found
  1794.         rts
  1795.  
  1796. MGTK_Period_Nop
  1797.         move.b    Voice_Vol_Command(a6),d0
  1798.         lsr.b    #4,d0
  1799.         cmp.b    #$b,d0        ; Vibrato
  1800.         beq.s    MGTK_Return
  1801.         cmp.b    #$f,d0        ; Tone Portamento
  1802.         beq.s    MGTK_Return
  1803.  
  1804.         move.l    Voice_Period(a6),Voice_Sample_Period(a6)
  1805. MGTK_Return
  1806.         rts
  1807.  
  1808.  
  1809. MGTK_Arpeggio
  1810.         move.w    Voice_Parameter1(a6),d1
  1811.         beq.s    MGTK_Period_Nop
  1812.  
  1813. MGTK_Arpeggio_0
  1814.         moveq.l    #0,d0
  1815.         move.b    MGTK_Music_Counter(pc),d0
  1816.  
  1817.         tst.b    d1
  1818.         beq.s    MGTK_Normal_Arpeggio
  1819.  
  1820.         add.w    #MGTK_Arpeggio_Table_5-MGTK_Arpeggio_Table_3,d0
  1821.  
  1822. MGTK_Normal_Arpeggio
  1823.         move.b    MGTK_Arpeggio_Table_3(pc,d0.w),d0
  1824.         beq.s    MGTK_Period_Nop
  1825.         subq.b    #2,d0
  1826.         beq.s    MGTK_Arpeggio_2
  1827.         subq.b    #1,d0
  1828.         beq.s    MGTK_Arpeggio_3
  1829.         subq.b    #1,d0
  1830.         beq.s    MGTK_Arpeggio_4
  1831.  
  1832. MGTK_Arpeggio_1
  1833.         lsr.w    #4,d1
  1834. MGTK_Arpeggio_2
  1835.         lsr.w    #4,d1
  1836. MGTK_Arpeggio_3
  1837.         lsr.w    #4,d1
  1838. MGTK_Arpeggio_4
  1839.         and.w    #$f,d1
  1840.  
  1841.         lea.l    MGTK_Periods_Table(pc),a0
  1842.         adda.w    Voice_Sample_Fine_Tune(a6),a0
  1843.         move.l    Voice_Period(a6),d0
  1844.         bsr        MGTK_Find_Period
  1845.         move.l    (a0,d1.w*4),Voice_Sample_Period(a6)
  1846.         rts
  1847.  
  1848. MGTK_Arpeggio_Table_3
  1849.         Rept        (256+3-1)/3
  1850.         dc.b        0,1,2
  1851.         EndR
  1852.  
  1853. MGTK_Arpeggio_Table_5
  1854.         Rept        (256+5-1)/5
  1855.         dc.b        0,1,2,3,4
  1856.         EndR
  1857.  
  1858.  
  1859. MGTK_Portamento_Up
  1860.         moveq.l    #0,d0
  1861.         move.w    Voice_Parameter1(a6),d0
  1862.         sub.l    d0,Voice_Period(a6)
  1863.         move.l    Voice_Period(a6),d0
  1864.         cmp.l    #$1af1,d0
  1865.         bhi.s    MGTK_Portamento_Up_Ok
  1866.         move.l    #$1af1,Voice_Period(a6)
  1867.  
  1868. MGTK_Portamento_Up_Ok
  1869.         move.l    Voice_Period(a6),Voice_Sample_Period(a6)
  1870.         rts
  1871.  
  1872.  
  1873. MGTK_Portamento_Down
  1874.         moveq.l    #0,d0
  1875.         move.w    Voice_Parameter1(a6),d0
  1876.         add.l    d0,Voice_Period(a6)
  1877.         move.l    Voice_Period(a6),d0
  1878.         cmp.l    #$1c5734,d0
  1879.         blo.s    MGTK_Portamento_Down_Ok
  1880.         move.l    #$1c5734,Voice_Period(a6)
  1881.  
  1882. MGTK_Portamento_Down_Ok
  1883.         move.l    Voice_Period(a6),Voice_Sample_Period(a6)
  1884.         rts
  1885.  
  1886.  
  1887. MGTK_Set_Tone_Portamento
  1888.         moveq.l    #0,d0
  1889.         move.b    Voice_Note(a6),d0
  1890.         beq.s    MGTK_Set_Tone_Portamento_Ret
  1891.         sub.w    #12,d0
  1892.         lea.l    MGTK_Periods_Table(pc),a0
  1893.         adda.w    Voice_Sample_Fine_Tune(a6),a0
  1894.         move.l    (a0,d0.w*4),d0
  1895.  
  1896.         move.l    d0,Voice_Tone_Port_Period(a6)
  1897.         move.l    Voice_Period(a6),d1
  1898.         sf        Voice_Tone_Port_Direction(a6)
  1899.         cmp.l    d1,d0
  1900.         beq.s    MGTK_Clear_Tone_Portamento
  1901.         bge.s    MGTK_Set_Tone_Portamento_Ret
  1902.         st        Voice_Tone_Port_Direction(a6)
  1903.  
  1904. MGTK_Set_Tone_Portamento_Ret
  1905.         addq.l    #4,sp
  1906.         rts
  1907.  
  1908. MGTK_Clear_Tone_Portamento
  1909.         clr.l    Voice_Tone_Port_Period(a6)
  1910.         addq.l    #4,sp
  1911.         rts
  1912.  
  1913. MGTK_Tone_Portamento
  1914.         moveq.l    #0,d0
  1915.         move.w    Voice_Parameter1(a6),d0
  1916.         beq.s    MGTK_Tone_Portamento_No_Change
  1917.         move.l    d0,Voice_Tone_Port_Speed(a6)
  1918.         clr.w    Voice_Parameter1(a6)
  1919.  
  1920. MGTK_Tone_Portamento_No_Change
  1921.         tst.l    Voice_Tone_Port_Period(a6)
  1922.         beq        MGTK_Period_Nop
  1923.         move.l    Voice_Tone_Port_Speed(a6),d0
  1924.         tst.b    Voice_Tone_Port_Direction(a6)
  1925.         bne.s    MGTK_Tone_Portamento_Up
  1926.  
  1927. MGTK_Tone_Portamento_Down
  1928.         add.l    d0,Voice_Period(a6)
  1929.         move.l    Voice_Tone_Port_Period(a6),d0
  1930.         cmp.l    Voice_Period(a6),d0
  1931.         bgt.s    MGTK_Tone_Portamento_Set_Period
  1932.         move.l    Voice_Tone_Port_Period(a6),Voice_Period(a6)
  1933.         clr.l    Voice_Tone_Port_Period(a6)
  1934.         bra.s    MGTK_Tone_Portamento_Set_Period
  1935.  
  1936. MGTK_Tone_Portamento_Up
  1937.         sub.l    d0,Voice_Period(a6)
  1938.         move.l    Voice_Tone_Port_Period(a6),d0
  1939.         cmp.l    Voice_Period(a6),d0
  1940.         blt.s    MGTK_Tone_Portamento_Set_Period
  1941.         move.l    Voice_Tone_Port_Period(a6),Voice_Period(a6)
  1942.         clr.l    Voice_Tone_Port_Period(a6)
  1943.  
  1944.  
  1945. MGTK_Tone_Portamento_Set_Period
  1946.         move.l    Voice_Period(a6),d0
  1947.         tst.b    Voice_Glissando_Control(a6)
  1948.         beq.s    MGTK_Glissando_Skip
  1949.  
  1950.         lea.l    MGTK_Periods_Table(pc),a0
  1951.         adda.w    Voice_Sample_Fine_Tune(a6),a0
  1952.         bsr        MGTK_Find_Period
  1953.         move.l    (a0),d0
  1954.  
  1955. MGTK_Glissando_Skip
  1956.         move.l    d0,Voice_Sample_Period(a6)
  1957.         rts
  1958.  
  1959.  
  1960. MGTK_Vibrato
  1961.         move.b    Voice_Parameter1(a6),d0
  1962.         lsr.b    #4,d0
  1963.         beq.s    MGTK_Vibrato_1
  1964.         move.b    d0,Voice_Vibrato_Speed(a6)
  1965. MGTK_Vibrato_1
  1966.         move.w    Voice_Parameter1(a6),d0
  1967.         and.w    #$0fff,d0
  1968.         beq.s    MGTK_Vibrato_2
  1969.         move.w    d0,Voice_Vibrato_Depth(a6)
  1970. MGTK_Vibrato_2
  1971.  
  1972.         lea.l    MGTK_Sinus_Table(pc),a3
  1973.         move.b    Voice_Vibrato_Position(a6),d0
  1974.         lsr.b    #2,d0
  1975.         and.w    #$001f,d0
  1976.         moveq.l    #0,d2
  1977.         move.b    Voice_Vibrato_Waveform(a6),d2
  1978.         and.b    #3,d2
  1979.         beq.s    MGTK_Vibrato_Sinus
  1980.  
  1981.         lsl.b    #3,d0
  1982.         cmp.b    #1,d2
  1983.         beq.s    MGTK_Vibrato_Ramp_Down
  1984.         move.b    #255,d2
  1985.         bra.s    MGTK_Vibrato_Set
  1986.  
  1987. MGTK_Vibrato_Ramp_Down
  1988.         tst.b    Voice_Vibrato_Position(a6)
  1989.         bpl.s    MGTK_Vibrato_Ramp_Down_2
  1990.         move.b    #255,d2
  1991.         sub.b    d0,d2
  1992.         bra.s    MGTK_Vibrato_Set
  1993. MGTK_Vibrato_Ramp_Down_2
  1994.         move.b    d0,d2
  1995.         bra.s    MGTK_Vibrato_Set
  1996.  
  1997. MGTK_Vibrato_Sinus
  1998.         move.b    (a3,d0.w),d2
  1999. MGTK_Vibrato_Set
  2000.         move.w    Voice_Vibrato_Depth(a6),d0
  2001.         mulu.w    d0,d2
  2002.         lsr.l    #7,d2
  2003.         move.l    Voice_Period(a6),d0
  2004.         tst.b    Voice_Vibrato_Position(a6)
  2005.         bmi.s    MGTK_Vibrato_Neg
  2006.         add.l    d2,d0
  2007.         bra.s    MGTK_Vibrato_3
  2008. MGTK_Vibrato_Neg
  2009.         sub.l    d2,d0
  2010. MGTK_Vibrato_3
  2011.         move.l    d0,Voice_Sample_Period(a6)
  2012.  
  2013.         move.b    Voice_Vibrato_Speed(a6),d0
  2014.         lsl.b    #2,d0
  2015.         add.b    d0,Voice_Vibrato_Position(a6)
  2016.         rts
  2017.  
  2018.  
  2019. MGTK_Tone_Portamento_Plus_Volume_Slide
  2020.         bsr        MGTK_Tone_Portamento_No_Change
  2021.         bra        MGTK_Volume_Slide
  2022.  
  2023.  
  2024. MGTK_Vibrato_Plus_Volume_Slide
  2025.         bsr.s    MGTK_Vibrato_2
  2026.         bra        MGTK_Volume_Slide
  2027.  
  2028.  
  2029. MGTK_Tremolo
  2030.         move.b    Voice_Parameter1(a6),d0
  2031.         lsr.b    #4,d0
  2032.         beq.s    MGTK_Tremolo_1
  2033.         move.b    d0,Voice_Tremolo_Speed(a6)
  2034. MGTK_Tremolo_1
  2035.         move.w    Voice_Parameter1(a6),d0
  2036.         and.w    #$0fff,d0
  2037.         beq.s    MGTK_Tremolo_2
  2038.         move.w    d0,Voice_Tremolo_Depth(a6)
  2039. MGTK_Tremolo_2
  2040.  
  2041.         lea.l    MGTK_Sinus_Table(pc),a3
  2042.         move.b    Voice_Tremolo_Position(a6),d0
  2043.         lsr.b    #2,d0
  2044.         and.w    #$001f,d0
  2045.         moveq.l    #0,d2
  2046.         move.b    Voice_Tremolo_Waveform(a6),d2
  2047.         and.b    #3,d2
  2048.         beq.s    MGTK_Tremolo_Sinus
  2049.  
  2050.         lsl.b    #3,d0
  2051.         cmp.b    #1,d2
  2052.         beq.s    MGTK_Tremolo_Ramp_Down
  2053.         move.b    #255,d2
  2054.         bra.s    MGTK_Tremolo_Set
  2055.  
  2056. MGTK_Tremolo_Ramp_Down
  2057.         tst.b    Voice_Tremolo_Position(a6)
  2058.         bpl.s    MGTK_Tremolo_Ramp_Down_2
  2059.         move.b    #255,d2
  2060.         sub.b    d0,d2
  2061.         bra.s    MGTK_Tremolo_Set
  2062. MGTK_Tremolo_Ramp_Down_2
  2063.         move.b    d0,d2
  2064.         bra.s    MGTK_Tremolo_Set
  2065.  
  2066. MGTK_Tremolo_Sinus
  2067.         move.b    (a3,d0.w),d2
  2068. MGTK_Tremolo_Set
  2069.         move.w    Voice_Tremolo_Depth(a6),d0
  2070.         mulu.w    d0,d2
  2071.         lsr.l    #6,d2
  2072.         move.w    Voice_Volume(a6),d0
  2073.         tst.b    Voice_Tremolo_Position(a6)
  2074.         bmi.s    MGTK_Tremolo_Neg
  2075.         add.w    d2,d0
  2076.         bra.s    MGTK_Tremolo_3
  2077. MGTK_Tremolo_Neg
  2078.         sub.w    d2,d0
  2079.         bmi.s    MGTK_Tremolo_Nul
  2080. MGTK_Tremolo_3
  2081.         cmp.w    #$400,d0
  2082.         ble.s    MGTK_Tremolo_Ok
  2083.         move.w    #$400,d0
  2084.         bra.s    MGTK_Tremolo_Ok
  2085. MGTK_Tremolo_Nul
  2086.         moveq.l    #0,d0
  2087. MGTK_Tremolo_Ok
  2088.         move.w    d0,Voice_Sample_Volume(a6)
  2089.  
  2090.         move.b    Voice_Tremolo_Speed(a6),d0
  2091.         lsl.b    #2,d0
  2092.         add.b    d0,Voice_Tremolo_Position(a6)
  2093.         bra        MGTK_Period_Nop
  2094.  
  2095.  
  2096. MGTK_Panning
  2097.         move.b    Voice_Parameter1(a6),d0
  2098.         move.b    d0,Voice_Right_Volume(a6)
  2099.         moveq.l    #-1,d1
  2100.         sub.b    d0,d1
  2101.         move.b    d1,Voice_Left_Volume(a6)
  2102.         rts
  2103.  
  2104.  
  2105. MGTK_Sample_Offset
  2106.         move.l    Voice_Sample_Offset(a6),d0
  2107.         moveq.l    #0,d1
  2108.         move.w    Voice_Parameter1(a6),d1
  2109.         beq.s    MGTK_Sample_Offset_No_New
  2110.  
  2111.         lsl.l    #4,d1
  2112.         move.l    d1,d0
  2113. MGTK_Sample_Offset_No_New
  2114.  
  2115.         add.l    Voice_Sample_Offset(a6),d0
  2116.         cmp.l    Voice_Sample_Length(a6),d0
  2117.         ble.s    MGTK_Sample_Offset_Ok
  2118.         move.l    Voice_Sample_Length(a6),d0
  2119. MGTK_Sample_Offset_Ok
  2120.         move.l    Voice_Start(a6),Voice_Sample_Start(a6)
  2121.         move.l    d0,Voice_Sample_Offset(a6)
  2122.         move.l    d0,Voice_Sample_Position(a6)
  2123.         rts
  2124.  
  2125.  
  2126. MGTK_Volume_Slide
  2127.         moveq.l    #0,d0
  2128.         move.b    Voice_Parameter1(a6),d0
  2129.         beq.s    MGTK_Volume_Slide_Down
  2130.  
  2131. MGTK_Volume_Slide_Up
  2132.         add.w    d0,Voice_Volume(a6)
  2133.         cmp.w    #$400,Voice_Volume(a6)
  2134.         ble.s    MGTK_Volume_Slide_Up_Ok
  2135.         move.w    #$400,Voice_Volume(a6)
  2136.  
  2137. MGTK_Volume_Slide_Up_Ok
  2138.         move.w    Voice_Volume(a6),Voice_Sample_Volume(a6)
  2139.         rts
  2140.  
  2141.  
  2142. MGTK_Volume_Slide_Down
  2143.         move.b    Voice_Parameter2(a6),d0
  2144.         sub.w    d0,Voice_Volume(a6)
  2145.         bpl.s    MGTK_Volume_Slide_Down_Ok
  2146.         clr.w    Voice_Volume(a6)
  2147.  
  2148. MGTK_Volume_Slide_Down_Ok
  2149.         move.w    Voice_Volume(a6),Voice_Sample_Volume(a6)
  2150.         rts
  2151.  
  2152.  
  2153. MGTK_Position_Jump
  2154. *        tst.b    Skip_Position_Jump
  2155. *        beq.s    MGTK_Position_Jump_Not_Skipped
  2156. *        rts
  2157. *
  2158. MGTK_Position_Jump_Not_Skipped
  2159.         move.w    Voice_Parameter1(a6),d0
  2160.  
  2161.         cmp.w    MGTK_Music_Length(pc),d0
  2162.         blo.s    MGTK_Position_Jump_Ok
  2163.         moveq.l    #0,d0
  2164.     
  2165. MGTK_Position_Jump_Ok
  2166.         move.w    d0,MGTK_Position_Jump_Position
  2167.         st        MGTK_Position_Jump_Flag
  2168.         rts
  2169.  
  2170.  
  2171. MGTK_Volume_Change
  2172.         move.w    Voice_Parameter1(a6),d0
  2173.         cmp.w    #$400,d0
  2174.         ble.s    MGTK_Volume_Change_Ok
  2175.         move.w    #$400,d0
  2176.  
  2177. MGTK_Volume_Change_Ok
  2178.         move.w    d0,Voice_Volume(a6)
  2179.         move.w    d0,Voice_Sample_Volume(a6)
  2180.         rts
  2181.  
  2182.  
  2183. MGTK_Pattern_Break
  2184.         move.w    Voice_Parameter1(a6),d0
  2185.  
  2186.         cmp.w    MGTK_Pattern_Length(pc),d0
  2187.         blo.s    MGTK_Pattern_Break_Ok
  2188.         moveq.l    #0,d0
  2189.     
  2190. MGTK_Pattern_Break_Ok
  2191.         move.w    d0,MGTK_Pattern_Break_Position
  2192.         st        MGTK_Pattern_Break_Flag
  2193.         rts
  2194.  
  2195.  
  2196. MGTK_Set_Speed_Tempo
  2197.         move.b    Voice_Parameter1(a6),d0
  2198.         beq.s    MGTK_No_Speed
  2199.         move.b    d0,MGTK_Music_Speed
  2200.  
  2201. MGTK_No_Speed
  2202. *        tst.b    Skip_Tempos
  2203. *        beq.s    MGTK_Tempos_Not_Skipped
  2204. *        rts
  2205. *
  2206. MGTK_Tempos_Not_Skipped
  2207.         moveq.l    #0,d0
  2208.         move.b    Voice_Parameter2(a6),d0
  2209.         bne.s    MGTK_Tempo_Ok
  2210.         rts
  2211.  
  2212. MGTK_Tempo_Ok
  2213.         move.b    d0,MGTK_Music_Tempo
  2214.  
  2215. MGTK_Search_Values_for_Tempo
  2216.         movem.l    d0-d3,-(sp)
  2217.         moveq.l    #0,d0
  2218.         move.b    MGTK_Music_Tempo(pc),d0
  2219.  
  2220.         moveq.l    #125,d1                    ; 125
  2221.         mulu.w    MGTK_Replay_Frequency(pc),d1    ; * Frequence Replay
  2222.         divu.l    #50,d1                    ; / 50
  2223.         divu.l    d0,d1                    ; / Tempo
  2224.         moveq.l    #0,d3                    ; = Nb Samples / Tick
  2225. MGTK_Search_Length_Loop
  2226.         addq.b    #1,d3                    ; Cherche en
  2227.         move.l    d1,d2                    ; combien de fois
  2228.         divu.w    d3,d2                    ; on peut traiter
  2229.         cmp.w    #DSP_Buffer/2,d2            ; un 'tick'
  2230.         bhi.s    MGTK_Search_Length_Loop
  2231.  
  2232.         move.w    d3,MGTK_IT_Number
  2233.  
  2234. MGTK_Search_MFP_Divider
  2235.         mulu.w    d3,d0                    ; Tempo*Nb ITs
  2236.         mulu.w    #50*256,d0                ; *50/125*256
  2237.         divu.l    #125,d0                    ; = Freq Cherchée * 256
  2238.  
  2239.         move.l    #2457600/200*256,d2            ; Freq Base MFP
  2240.         move.l    d2,d3                    ; / Prediviseur 200
  2241.         divu.l    d0,d2                    ; / Freq donne Diviseur
  2242.  
  2243.         move.b    #7,MGTK_IT_Timer_Control
  2244.         move.b    d2,MGTK_IT_Timer_Data
  2245.         movem.l    (sp)+,d0-d3
  2246.         rts
  2247.  
  2248.  
  2249. MGTK_Set_Glissando_Control
  2250.         move.b    Voice_Parameter1(a6),Voice_Glissando_Control(a6)
  2251.         rts
  2252.  
  2253.  
  2254. MGTK_Set_Vibrato_Waveform
  2255.         move.b    Voice_Parameter1(a6),Voice_Vibrato_Waveform(a6)
  2256.         rts
  2257.  
  2258.  
  2259. MGTK_Set_Fine_Tune
  2260.         move.b    Voice_Parameter1(a6),d0
  2261.         and.w    #$0f,d0
  2262.         mulu.w    #12*8*4,d0
  2263.         move.w    d0,Voice_Sample_Fine_Tune(a6)
  2264.         rts
  2265.  
  2266.  
  2267. MGTK_Pattern_Loop
  2268.         move.w    Voice_Parameter1(a6),d0
  2269.         beq.s    MGTK_Set_Loop_Position
  2270.  
  2271.         tst.w    MGTK_Pattern_Loop_Counter(pc)
  2272.         beq.s    MGTK_Set_Loop_Counter
  2273.  
  2274.         subq.w    #1,MGTK_Pattern_Loop_Counter
  2275.         beq        MGTK_Return
  2276.  
  2277. MGTK_Do_Loop    
  2278.         st        MGTK_Pattern_Loop_Flag
  2279.         rts
  2280. MGTK_Set_Loop_Counter
  2281.         move.w    d0,MGTK_Pattern_Loop_Counter
  2282.         bra.s    MGTK_Do_Loop
  2283. MGTK_Set_Loop_Position
  2284.         move.w    MGTK_Pattern_Position(pc),MGTK_Pattern_Loop_Position
  2285.         rts
  2286.  
  2287.  
  2288. MGTK_Set_Tremolo_Waveform
  2289.         move.b    Voice_Parameter1(a6),Voice_Tremolo_Waveform(a6)
  2290.         rts
  2291.  
  2292.  
  2293. MGTK_Set_Panoramic
  2294.         move.b    Voice_Parameter1(a6),d0
  2295.         and.w    #$0f,d0
  2296.         move.w    (MGTK_Panoramics_Table,pc,d0.w*2),Voice_Left_Volume(a6)
  2297.         rts
  2298.  
  2299.  
  2300. MGTK_Note_Retrig_Plus_Volume_Slide
  2301.         moveq.l    #0,d0
  2302.         move.b    Voice_Parameter1(a6),d0
  2303.         beq.s    MGTK_No_Note_Retrig_Plus_Volume_Slide
  2304.  
  2305.         moveq.l    #0,d1
  2306.         move.b    MGTK_Music_Counter(pc),d1
  2307.         bne.s    MGTK_Note_Retrig_Plus_Volume_Slide_Skip
  2308.  
  2309.         tst.b    Voice_Note(a6)
  2310.         bne.s    MGTK_No_Note_Retrig_Plus_Volume_Slide
  2311.  
  2312. MGTK_Note_Retrig_Plus_Volume_Slide_Skip
  2313.         divu.w    d0,d1
  2314.         swap.w    d1
  2315.         tst.w    d1
  2316.         bne.s    MGTK_No_Note_Retrig_Plus_Volume_Slide
  2317.  
  2318.         move.l    Voice_Period(a6),Voice_Sample_Period(a6)
  2319.         move.l    Voice_Start(a6),Voice_Sample_Start(a6)
  2320.         move.l    Voice_Sample_Offset(a6),Voice_Sample_Position(a6)
  2321.  
  2322.         move.b    Voice_Parameter2(a6),d1
  2323.         beq.s    MGTK_No_Note_Retrig_Plus_Volume_Slide
  2324.  
  2325.         move.w    Voice_Volume(a6),d0
  2326.         and.w    #$f,d1
  2327.         jsr        ([MGTK_NRPVS_Table,pc,d1.w*4])
  2328.  
  2329. MGTK_No_Note_Retrig_Plus_Volume_Slide
  2330.         rts
  2331.  
  2332. MGTK_NRPVS_M100
  2333.         sub.w    #$80,d0
  2334. MGTK_NRPVS_M80
  2335.         sub.w    #$40,d0
  2336. MGTK_NRPVS_M40
  2337.         sub.w    #$20,d0
  2338. MGTK_NRPVS_M20
  2339.         sub.w    #$10,d0
  2340. MGTK_NRPVS_M10
  2341.         sub.w    #$10,d0
  2342.         bpl.s    MGTK_NRPVS_Ok
  2343.         clr.w    Voice_Volume(a6)
  2344.         clr.w    Voice_Sample_Volume(a6)
  2345.         rts
  2346.  
  2347. MGTK_NRPVS_2_3
  2348.         add.w    d0,d0
  2349.         divu.w    #3,d0
  2350.         bra.s    MGTK_NRPVS_Ok
  2351.  
  2352. MGTK_NRPVS_1_2
  2353.         lsr.w    d0
  2354.         bra.s    MGTK_NRPVS_Ok
  2355.  
  2356. MGTK_NRPVS_P100
  2357.         add.w    #$80,d0
  2358. MGTK_NRPVS_P80
  2359.         add.w    #$40,d0
  2360. MGTK_NRPVS_P40
  2361.         add.w    #$20,d0
  2362. MGTK_NRPVS_P20
  2363.         add.w    #$10,d0
  2364. MGTK_NRPVS_P10
  2365.         add.w    #$10,d0
  2366.         add.w    #$100,d0
  2367.         cmp.w    #$400,d0
  2368.         ble.s    MGTK_NRPVS_Ok
  2369.         move.w    #$400,d0
  2370. MGTK_NRPVS_Ok
  2371.         move.w    d0,Voice_Volume(a6)
  2372.         move.w    d0,Voice_Sample_Volume(a6)
  2373.         rts
  2374.  
  2375. MGTK_NRPVS_3_2
  2376.         move.w    d0,d1
  2377.         lsr.w    d1
  2378.         add.w    d1,d0
  2379.         bra.s    MGTK_NRPVS_Ok
  2380.  
  2381. MGTK_NRPVS_2
  2382.         add.w    d0,d0
  2383.         bra.s    MGTK_NRPVS_Ok
  2384.  
  2385. MGTK_NRPVS_Table
  2386.         dc.l        MGTK_Return,MGTK_NRPVS_M10,MGTK_NRPVS_M20,MGTK_NRPVS_M40
  2387.         dc.l        MGTK_NRPVS_M80,MGTK_NRPVS_M100,MGTK_NRPVS_2_3,MGTK_NRPVS_1_2
  2388.         dc.l        MGTK_Return,MGTK_NRPVS_P10,MGTK_NRPVS_P20,MGTK_NRPVS_P40
  2389.         dc.l        MGTK_NRPVS_P80,MGTK_NRPVS_P100,MGTK_NRPVS_3_2,MGTK_NRPVS_2
  2390.  
  2391.  
  2392.  
  2393. MGTK_Fine_Volume_Slide_Up
  2394.         move.w    Voice_Parameter1(a6),d0
  2395.         add.w    d0,Voice_Volume(a6)
  2396.         cmp.w    #$400,Voice_Volume(a6)
  2397.         ble.s    MGTK_Fine_Volume_Slide_Up_Ok
  2398.         move.w    #$400,Voice_Volume(a6)
  2399.  
  2400. MGTK_Fine_Volume_Slide_Up_Ok
  2401.         move.w    Voice_Volume(a6),Voice_Sample_Volume(a6)
  2402.         bra        MGTK_Period_Nop
  2403.  
  2404.  
  2405. MGTK_Fine_Volume_Slide_Down
  2406.         move.w    Voice_Parameter1(a6),d0
  2407.         sub.w    d0,Voice_Volume(a6)
  2408.         bpl.s    MGTK_Fine_Volume_Slide_Down_Ok
  2409.         clr.w    Voice_Volume(a6)
  2410.  
  2411. MGTK_Fine_Volume_Slide_Down_Ok
  2412.         move.w    Voice_Volume(a6),Voice_Sample_Volume(a6)
  2413.         bra        MGTK_Period_Nop
  2414.  
  2415.  
  2416. MGTK_Note_Cut
  2417.         move.b    Voice_Parameter1(a6),d0
  2418.         cmp.b    MGTK_Music_Counter(pc),d0
  2419.         bne        MGTK_Period_Nop
  2420.  
  2421.         clr.w    Voice_Volume(a6)
  2422.         clr.w    Voice_Sample_Volume(a6)
  2423.         rts
  2424.  
  2425.  
  2426. MGTK_Note_Delay
  2427.         move.b    Voice_Parameter1(a6),d0
  2428.         cmp.b    MGTK_Music_Counter(pc),d0
  2429.         bne        MGTK_Period_Nop
  2430.         tst.b    Voice_Note(a6)
  2431.         beq        MGTK_Period_Nop
  2432.  
  2433.         move.l    Voice_Start(a6),Voice_Sample_Start(a6)
  2434.         move.l    Voice_Length(a6),Voice_Sample_Length(a6)
  2435.         move.l    Voice_Loop_Length(a6),Voice_Sample_Loop_Length(a6)
  2436.         move.l    Voice_End_Length(a6),Voice_Sample_End_Length(a6)
  2437.         move.l    Voice_Sample_Offset(a6),Voice_Sample_Position(a6)
  2438.         move.l    Voice_Base(a6),Voice_Sample_Base(a6)
  2439.         move.b    Voice_Attributes(a6),Voice_Sample_Attributes(a6)
  2440.         move.l    Voice_Period(a6),Voice_Sample_Period(a6)
  2441.         rts
  2442.  
  2443.  
  2444. MGTK_Pattern_Delay
  2445.         tst.b    MGTK_Pattern_Delay_Time(pc)
  2446.         bne        MGTK_Return
  2447.  
  2448.         move.b    Voice_Parameter1(a6),MGTK_Pattern_Delay_Time
  2449.         rts
  2450.  
  2451.  
  2452. MGTK_Arpeggio3
  2453.         move.b    Voice_Parameter1(a6),d1
  2454.         beq        MGTK_Period_Nop
  2455.  
  2456.         moveq.l    #0,d0
  2457.         move.b    MGTK_Music_Counter(pc),d0
  2458.  
  2459.         move.b    MGTK_Arpeggio3_Table(pc,d0.w),d0
  2460.         beq        MGTK_Period_Nop
  2461.         bpl.s    MGTK_Arpeggio3_Plus
  2462.  
  2463.         lsr.b    #4,d1
  2464.         neg.b    d1
  2465.         ext.w    d1
  2466. MGTK_Arpeggio3_Plus
  2467.         and.w    #$0f,d1
  2468.  
  2469.         lea.l    MGTK_Periods_Table(pc),a0
  2470.         adda.w    Voice_Sample_Fine_Tune(a6),a0
  2471.         move.l    Voice_Period(a6),d0
  2472.         bsr        MGTK_Find_Period
  2473.         move.l    (a0,d1.w*4),Voice_Sample_Period(a6)
  2474.         rts
  2475.  
  2476. MGTK_Arpeggio3_Table
  2477.         Rept        (256+3-1)/3
  2478.         dc.b        -1,0,1
  2479.         EndR
  2480.  
  2481.  
  2482. MGTK_Arpeggio4
  2483.         move.b    Voice_Parameter1(a6),d1
  2484.         beq        MGTK_Period_Nop
  2485.  
  2486.         moveq.l    #0,d0
  2487.         move.b    MGTK_Music_Counter(pc),d0
  2488.  
  2489.         move.b    MGTK_Arpeggio4_Table(pc,d0.w),d0
  2490.         beq        MGTK_Period_Nop
  2491.         bpl.s    MGTK_Arpeggio4_Plus
  2492.  
  2493.         lsr.b    #4,d1
  2494.         neg.b    d1
  2495.         ext.w    d1
  2496. MGTK_Arpeggio4_Plus
  2497.         and.w    #$0f,d1
  2498.  
  2499.         lea.l    MGTK_Periods_Table(pc),a0
  2500.         adda.w    Voice_Sample_Fine_Tune(a6),a0
  2501.         move.l    Voice_Period(a6),d0
  2502.         bsr        MGTK_Find_Period
  2503.         move.l    (a0,d1.w*4),Voice_Sample_Period(a6)
  2504.         rts
  2505.  
  2506. MGTK_Arpeggio4_Table
  2507.         Rept        256/4
  2508.         dc.b        0,1,0,-1
  2509.         EndR
  2510.  
  2511.  
  2512. MGTK_Arpeggio5
  2513.         move.b    Voice_Parameter1(a6),d1
  2514.         beq        MGTK_Period_Nop
  2515.  
  2516.         moveq.l    #0,d0
  2517.         move.b    MGTK_Music_Counter(pc),d0
  2518.  
  2519.         move.b    MGTK_Arpeggio5_Table(pc,d0.w),d0
  2520.         beq        MGTK_Period_Nop
  2521.  
  2522.         and.w    #$0f,d1
  2523.  
  2524.         lea.l    MGTK_Periods_Table(pc),a0
  2525.         adda.w    Voice_Sample_Fine_Tune(a6),a0
  2526.         move.l    Voice_Period(a6),d0
  2527.         bsr        MGTK_Find_Period
  2528.         move.l    (a0,d1.w*4),Voice_Sample_Period(a6)
  2529.         rts
  2530.  
  2531. MGTK_Arpeggio5_Table
  2532.         Rept        (256+3-1)/3
  2533.         dc.b        1,1,0
  2534.         EndR
  2535.  
  2536.  
  2537. MGTK_Note_Slide
  2538.         moveq.l    #0,d1
  2539.         move.b    Voice_Parameter1(a6),d1
  2540.         bne.s    MGTK_Note_Slide_Up
  2541.  
  2542. MGTK_Note_Slide_Down
  2543.         sub.b    Voice_Parameter2(a6),d1
  2544.  
  2545. MGTK_Note_Slide_Up
  2546.         lea.l    MGTK_Periods_Table(pc),a0
  2547.         adda.w    Voice_Sample_Fine_Tune(a6),a0
  2548.         move.l    Voice_Period(a6),d0
  2549.         bsr        MGTK_Find_Period
  2550.         move.l    (a0,d1.w*4),Voice_Period(a6)
  2551.         move.l    (a0,d1.w*4),Voice_Sample_Period(a6)
  2552.         rts
  2553.  
  2554.  
  2555. MGTK_Tremor
  2556.         moveq.l    #0,d0
  2557.         move.b    Voice_Parameter1(a6),d0
  2558.         add.b    Voice_Parameter2(a6),d0
  2559.         beq        MGTK_Return
  2560.         moveq.l    #0,d1
  2561.         move.b    MGTK_Music_Counter(pc),d1
  2562.         divu.w    d0,d1
  2563.         swap.w    d1
  2564.         cmp.b    Voice_Parameter1(a6),d1
  2565.         bhi.s    MGTK_Tremor_Off
  2566.  
  2567. MGTK_Tremor_On
  2568.         move.w    Voice_Volume(a6),Voice_Sample_Volume(a6)
  2569.         rts
  2570.  
  2571. MGTK_Tremor_Off
  2572.         clr.w    Voice_Sample_Volume(a6)
  2573.         rts
  2574.  
  2575.  
  2576. MGTK_Set_Master_Volume
  2577.         move.b    Voice_Parameter1(a6),MGTK_Master_Volume_Left
  2578.         move.b    Voice_Parameter2(a6),MGTK_Master_Volume_Right
  2579.         rts
  2580.  
  2581.  
  2582. MGTK_Set_Global_Volume
  2583.         move.w    Voice_Parameter1(a6),MGTK_Global_Volume
  2584.         rts
  2585.  
  2586.  
  2587. MGTK_Global_Volume_Slide
  2588.         move.w    MGTK_Global_Volume(pc),d1
  2589.         moveq.l    #0,d0
  2590.         move.b    Voice_Parameter1(a6),d0
  2591.         beq.s    MGTK_Global_Volume_Slide_Down
  2592.  
  2593. MGTK_Global_Volume_Slide_Up
  2594.         add.w    d0,d1
  2595.         cmp.w    #$400,d1
  2596.         ble.s    MGTK_Global_Volume_Slide_Ok
  2597.  
  2598.         move.w    #$400,MGTK_Global_Volume
  2599.         rts
  2600.  
  2601. MGTK_Global_Volume_Slide_Down
  2602.         move.b    Voice_Parameter2(a6),d0
  2603.         sub.w    d0,d1
  2604.         bpl.s    MGTK_Global_Volume_Slide_Ok
  2605.         moveq.l    #0,d1
  2606. MGTK_Global_Volume_Slide_Ok
  2607.         move.w    d1,MGTK_Global_Volume
  2608.         rts
  2609.  
  2610.  
  2611. MGTK_Set_Base
  2612.         moveq.l    #0,d0
  2613.         move.w    Voice_Parameter1(a6),d0
  2614.         cmp.w    #50066,d0
  2615.         ble.s    MGTK_Set_Base_1
  2616.         move.l    #50066,Voice_Sample_Base(a6)
  2617.         rts
  2618. MGTK_Set_Base_1
  2619.         cmp.w    #1000,d0
  2620.         bhi.s    MGTK_Set_Base_2
  2621.         move.w    #1000,d0
  2622. MGTK_Set_Base_2
  2623.         move.l    d0,Voice_Sample_Base(a6)
  2624.         rts
  2625.  
  2626.  
  2627. MGTK_Set_Stereo
  2628.         move.w    Voice_Parameter1(a6),Voice_Left_Volume(a6)
  2629.         rts
  2630.  
  2631.  
  2632. MGTK_Stereo_Slide
  2633.         moveq.l    #0,d0
  2634.         move.b    Voice_Left_Volume(a6),d0
  2635.         move.b    Voice_Parameter1(a6),d1
  2636.         ext.w    d1
  2637.         add.w    d1,d0
  2638.         bpl.s    MGTK_Stereo_Slide_Left_1
  2639.         moveq.l    #0,d0
  2640.         bra.s    MGTK_Stereo_Slide_Left_2
  2641. MGTK_Stereo_Slide_Left_1
  2642.         cmp.w    #$00ff,d0
  2643.         ble.s    MGTK_Stereo_Slide_Left_2
  2644.         moveq.l    #-1,d0
  2645. MGTK_Stereo_Slide_Left_2
  2646.         move.b    d0,Voice_Left_Volume(a6)
  2647.  
  2648.         moveq.l    #0,d0
  2649.         move.b    Voice_Right_Volume(a6),d0
  2650.         move.b    Voice_Parameter2(a6),d1
  2651.         ext.w    d1
  2652.         add.w    d1,d0
  2653.         bpl.s    MGTK_Stereo_Slide_Right_1
  2654.         moveq.l    #0,d0
  2655.         bra.s    MGTK_Stereo_Slide_Right_2
  2656. MGTK_Stereo_Slide_Right_1
  2657.         cmp.w    #$00ff,d0
  2658.         ble.s    MGTK_Stereo_Slide_Right_2
  2659.         moveq.l    #-1,d0
  2660. MGTK_Stereo_Slide_Right_2
  2661.         move.b    d0,Voice_Left_Volume(a6)
  2662.         rts
  2663.  
  2664.  
  2665. MGTK_Release_Sample
  2666.         and.b    #%11111100,Voice_Sample_Attributes(a6)
  2667.         rts
  2668.  
  2669. ***********************************************************************
  2670. ***********               Tables diverses                ***********
  2671. ***********************************************************************
  2672.  
  2673. MGTK_Panoramics_Table
  2674.         dc.w        $ff00,$ee11,$dd22,$cc33,$bb44,$aa55,$9966,$8080
  2675.         dc.w        $8080,$6699,$55aa,$44bb,$33cc,$22dd,$11ee,$00ff
  2676.  
  2677. MGTK_Sinus_Table    
  2678.         dc.b        0,24,49,74,97,120,141,161,180,197,212,224
  2679.         dc.b        235,244,250,253,255,253,250,244,235,224
  2680.         dc.b        212,197,180,161,141,120,97,74,49,24
  2681.  
  2682. ; Table des périodes pour chacune des 12 notes des 7 octaves pour
  2683. ; les fine tune 0 à 7 et -8 à -1
  2684.  
  2685. MGTK_Periods_Table        IncBin    'PERIODS.TAB'
  2686.  
  2687. ; Piste 0 = piste vide
  2688.  
  2689. MGTK_Track_0            dcb.b    6,0
  2690.  
  2691. ***********************************************************************
  2692. ***********                Replay DSP                ***********
  2693. ***********************************************************************
  2694.  
  2695. MGTK_DSP_Replay_Code
  2696.         IncBin    'MGT-PLAY.P56'
  2697. MGTK_DSP_Replay_Size    equ        (*-MGTK_DSP_Replay_Code)/3
  2698.         Even
  2699.  
  2700. ***********************************************************************
  2701. ***********            Variables diverses                ***********
  2702. ***********************************************************************
  2703.  
  2704. MGTK_Module_Adr            ds.l        1
  2705. MGTK_WorkSpace_Adr            ds.l        1
  2706. MGTK_Module_End_Adr            ds.l        1
  2707.  
  2708. MGTK_Nb_Voices                ds.w        1
  2709. MGTK_Nb_Musics                ds.w        1
  2710. MGTK_Nb_Tracks                ds.w        1
  2711. MGTK_Nb_Samples            ds.w        1
  2712.  
  2713. MGTK_Musics_Adr            ds.l        1
  2714. MGTK_Sequences_Adr            ds.l        1
  2715. MGTK_Samples_Infos_Adr        ds.l        1
  2716. MGTK_Patterns_Adr            ds.l        1
  2717. MGTK_Tracks_Ptr            ds.l        1
  2718. MGTK_Samples_Data_Adr        ds.l        1
  2719. MGTK_Samples_Length            ds.l        1
  2720. MGTK_Tracks_Length            ds.l        1
  2721.  
  2722. MGTK_Sequence_Adr            ds.w        1
  2723. MGTK_Music                ds.w        1
  2724. MGTK_Music_Position            ds.w        1
  2725. MGTK_Music_Length            ds.w        1
  2726. MGTK_Music_Restart            ds.w        1
  2727. MGTK_Initial_Tempo            ds.b        1
  2728. MGTK_Initial_Speed            ds.b        1
  2729. MGTK_Music_Tempo            ds.b        1
  2730. MGTK_Music_Speed            ds.b        1
  2731. MGTK_Music_Counter            ds.b        1
  2732.                         ds.b        1
  2733.  
  2734. MGTK_Restart_Loop            ds.b        1
  2735. MGTK_Restart_Done            ds.b        1
  2736. MGTK_Replay_Paused            ds.b        1
  2737. MGTK_Replay_Stopped            ds.b        1
  2738. MGTK_IT_Timer_Control        ds.b        1
  2739. MGTK_IT_Timer_Data            ds.b        1
  2740. MGTK_IT_Number                ds.w        1
  2741. MGTK_IT_Counter            ds.w        1
  2742. MGTK_Frequency_Divider        ds.w        1
  2743. MGTK_Replay_Frequency        ds.w        1
  2744.  
  2745. MGTK_Replay_Satured            ds.w        1
  2746. MGTK_Replay_Problem            ds.b        1
  2747. MGTK_Replay_In_Service        ds.b        1
  2748.  
  2749. MGTK_Global_Volume            ds.w        1
  2750. MGTK_Master_Volume_Left        ds.b        1
  2751. MGTK_Master_Volume_Right        ds.b        1
  2752.  
  2753. MGTK_Pattern_Position        ds.w        1
  2754. MGTK_Pattern_Length            ds.w        1
  2755.  
  2756. MGTK_Pattern_Loop_Counter    ds.w        1
  2757. MGTK_Pattern_Loop_Position    ds.w        1
  2758. MGTK_Pattern_Break_Position    ds.w        1
  2759. MGTK_Position_Jump_Position    ds.w        1
  2760. MGTK_Position_Jump_Flag        ds.b        1
  2761. MGTK_Pattern_Loop_Flag        ds.b        1
  2762. MGTK_Pattern_Break_Flag        ds.b        1
  2763. MGTK_Pattern_Delay_Time        ds.b        1
  2764.  
  2765.                         Even
  2766. MGTK_FX_Voices                ds.b        2*Voice_Size
  2767. MGTK_Voices                ds.b        32*Voice_Size
  2768.