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

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