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 / AMIGADSP.S < prev    next >
Text File  |  1995-09-17  |  51KB  |  1,955 lines

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