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.ASM < prev    next >
Assembly Source File  |  1995-08-24  |  9KB  |  397 lines

  1. ;***********************************************************************
  2. ;***********                                         ***********
  3. ;***********                                         ***********
  4. ;***********              Amiga DSP Replay                 ***********
  5. ;***********              DSP Amiga Replay                 ***********
  6. ;***********               with P56 Loader                 ***********
  7. ;***********                                         ***********
  8. ;***********                                         ***********
  9. ;***********          By Simplet / FATAL DESIGN             ***********
  10. ;***********                                         ***********
  11. ;***********************************************************************
  12.  
  13. ; The circular sample buffer must begin to an address multiple
  14. ; of the the first power of 2 greater than its size
  15. ; If you want an 50Hz VBL/Timer as maximum frequency,
  16. ; The size must be greater than :
  17. ; 2*984 for 49.1Khz, 2*656 for 32.8KHz, 2*492 for 24.5KHz, etc...
  18.  
  19. PBC        equ        $ffe0            ; Port B Control Register
  20. PCC        equ        $ffe1            ; Port C Control register
  21. HCR        equ        $ffe8            ; Host Control Register
  22. HSR        equ        $ffe9            ; Host Status Register
  23. HRX        equ        $ffeb            ; Host Receive Register
  24. HTX        equ        $ffeb            ; Host Transmit Register
  25. CRA        equ        $ffec            ; SSI Control Register A
  26. CRB        equ        $ffed            ; SSI Control Register B
  27. SSISR    equ        $ffee            ; SSI Status Register
  28. TX        equ        $ffef            ; SSI Serial Transmit data/shift register
  29. BCR        equ        $fffe            ; Port A Bus Control Register
  30. IPR        equ        $ffff            ; Interrupt Priority Register
  31.  
  32. ;    Host Control Register Bit Flags
  33.  
  34. HCIE        equ        2                ; Host Command Interrupt Enable
  35.  
  36. ;    Host Status Register Bit Flags
  37.  
  38. HRDF        equ        0                ; Host Receive Data Full
  39. HTDE        equ        1                ; Host Transmit Data Empty
  40.  
  41.  
  42.         org        p:$0
  43.         jmp        >Start
  44.  
  45.         org        p:$10
  46.         jsr        >Spl_Out
  47.         org        p:$12
  48.         jsr        >Spl_Out
  49.  
  50.         org        p:$24
  51.         jmp        >P56_Loader
  52.         org        p:$26
  53.         jsr        >SoundTrack_Rout
  54.         org        p:$28
  55.         jsr        >Clear_Sample_Buffer
  56.  
  57. ; Interrupt Routine that plays the sound with the SSI
  58.  
  59.         org        p:$40
  60.  
  61. Spl_Out    jset        #<2,X:<<SSISR,Right_Out    ; detect the second transfer
  62.  
  63. Left_Out    movep    Y:(r7),X:<<TX
  64.         rti
  65. Right_Out    movep    X:(r7)+,X:<<TX
  66.         rti
  67.  
  68. ;
  69. ; It Begins here :
  70. ;
  71.  
  72. Start    movep    #1,X:<<PBC            ; Port B in Host
  73.         movep    #$1f8,X:<<PCC            ; Port C in SSI
  74.         movep    #$4100,X:<<CRA            ; 1 voice 16 bits Stereo
  75.         movep    #$5800,X:<<CRB            ; enable X-mit IT
  76.         movep    #$3800,X:<<IPR            ; SSI at IPL 3
  77.                                     ; and Host at IPL 2
  78.         bset        #<HCIE,X:<<HCR            ; enable Host Command ITs
  79.  
  80. ; Initialisation of Registers
  81.  
  82.         move        #-1,m0
  83.         move        #2048-1,m7
  84.         move        m0,m1
  85.         move        m0,m2
  86.         move        m0,m3
  87.         move        m0,m4
  88.         move        m0,m5
  89.         move        m7,m6
  90.  
  91. ; Clears the Sample-Buffer
  92.         jsr        <Clear_Sample_Buffer
  93.  
  94. ; Verify the connexion with the 030
  95.  
  96. Conct_Get    jclr        #<HRDF,X:<<HSR,Conct_Get
  97.         movep    X:<<HRX,x0
  98.  
  99. Conct_Snd    jclr        #<HTDE,X:<<HSR,Conct_Snd
  100.         movep    #12345678,X:<<HTX
  101.  
  102. ; Enable interrupts (IPL0) and waits
  103.         move        #Sample_Buffer,r7
  104.         andi        #<%11111100,mr
  105. Loop        jmp        <Loop
  106.  
  107. ;
  108. ; Sound-Tracker Routine in Host Command
  109. ;
  110.  
  111. SoundTrack_Rout
  112.         jclr        #<HTDE,X:<<HSR,SoundTrack_Rout
  113.         movep    #'MGT',X:<<HTX
  114.  
  115.         move        #<Length,r0
  116.  
  117.         move        X:<Old_Adr,x0            ; Number of Samples
  118.         move        x0,X:<Calc_Adr            ; to calculate = Current Pos
  119.         move        r7,a                    ; - Old Position
  120.         sub        x0,a            r7,X:Old_Adr
  121.         jpl        <Length_Ok
  122.         move        #>2048,x0                ; Warning Modulo !
  123.         add        x0,a
  124. Length_Ok    move        a,X:(r0)+                ; Sample Length
  125.  
  126. Get_MVolL    jclr        #<HRDF,X:<<HSR,Get_MVolL
  127.         movep    X:<<HRX,X:(r0)+        ; Left Master Volume
  128. Get_MVolR    jclr        #<HRDF,X:<<HSR,Get_MVolR
  129.         movep    X:<<HRX,X:(r0)+        ; Right Master Volume
  130.  
  131. ; Gets the number of Voices
  132.  
  133. Get_NbV    jclr        #<HRDF,X:<<HSR,Get_NbV
  134.         movep    X:<<HRX,y0
  135.         tfr        y0,b        #>2,a
  136.         addr        a,b        #>1,a        ; 2*b = Nb Voies + 4 voies FX
  137.  
  138.         andi        #<$fe,ccr                ; Cancel Carry Bit
  139.         Rep        #<24
  140.         div        y0,a                    ; a0 = 1 / Nb Voices
  141.         move        a0,X:(r0)
  142.  
  143. ; Clears the sample-buffer before mixing
  144.         clr        a        X:Calc_Adr,r6
  145.  
  146.         move        X:Length,x0
  147.         Do        x0,Clear_Sample
  148.         move        a,L:(r6)+
  149. Clear_Sample
  150.  
  151. ; Mix All Voices
  152.         move        #Voices_Frac,r1
  153.  
  154.         Do        b,Mix_All_Voices_Loop
  155.  
  156.         jsr        <Request
  157.         jsr        <Receive_Volume
  158.         tst        a
  159.         jeq        <Next_Voice_L
  160.         jsr        <Receive_Frequency
  161.         jsr        <Receive_X_Samples
  162.         jsr        <Mix_Voice_Left
  163.  
  164. Next_Voice_L
  165.         lua        (r1)+,r1
  166.  
  167.         jsr        <Request
  168.         jsr        <Receive_Volume
  169.         tst        a
  170.         jeq        <Next_Voice_R
  171.         jsr        <Receive_Frequency
  172.         jsr        <Receive_Y_Samples
  173.         jsr        <Mix_Voice_Right
  174.         
  175. Next_Voice_R
  176.         lua        (r1)+,r1
  177. Mix_All_Voices_Loop
  178.  
  179. ; It's Finished for this time
  180. Send_End    jclr        #<HTDE,X:<<HSR,Send_End
  181.         movep    #0,X:<<HTX
  182.         rti
  183.  
  184. ; Calls the 030
  185. Request    jclr        #<HTDE,X:<<HSR,Request
  186.         movep    #-1,X:<<HTX
  187.         rts
  188.  
  189. ; Receives the Sample Volume
  190. Receive_Volume
  191.         move        #Voice_Volume,r0
  192.         jclr        #<HRDF,X:<<HSR,Receive_Volume
  193.         movep    X:<<HRX,a
  194.         move        a,X:(r0)+                ; Sample Volume
  195.         rts
  196.  
  197. ; Receives the sample frequency
  198. Receive_Frequency
  199.         jclr        #<HRDF,X:<<HSR,Receive_Frequency
  200.         movep    X:<<HRX,x0                ; Sample Frequency
  201.         move        X:<Length,b
  202.         lsl        b
  203.         clr        b            b,x1
  204.         move        X:(r1),b0                    ; Frac Part
  205.         mac        x0,x1,b        x0,X:(r0)
  206. Send_Length
  207.         jclr        #<HTDE,X:<<HSR,Send_Length    ; Length of Sample
  208.         movep    b,X:<<HTX                    ; played in this frame
  209.         rts
  210.  
  211. ; Routine that mixes a new voice on the left channel
  212.  
  213. Mix_Voice_Left
  214.         move        #Sample,r0
  215.         move        X:<Calc_Adr,r6        ; Adress
  216.  
  217.         move        X:<Voice_Volume,x0
  218.         move        X:<Master_Vol_L,x1
  219.         mpy        x0,x1,a    X:<Nb_Voices,x1
  220.         move        a0,x0
  221.         mpyr        x0,x1,a
  222.         lsl        a
  223.         move        a,x1                ; Volume
  224.  
  225.         move        #>2,y0
  226.         move        X:<Voice_Freq,y1    ; Frequence
  227.         move        r0,b
  228.         move        X:(r1),b0            ; Frac
  229.  
  230.         Do        X:<Length,Mix_Voice_Left_Loop
  231.  
  232.         mac        y0,y1,b        Y:(r6),a        X:(r0),x0
  233.         mac        x0,x1,a        b,r0
  234.         move                    a,Y:(r6)+
  235.  
  236. Mix_Voice_Left_Loop
  237.         move        b0,X:(r1)            ; Frac
  238.         rts
  239.  
  240. ; Routine that mixes a new voice on the right channel
  241.  
  242. Mix_Voice_Right
  243.         move        #Sample,r0
  244.         move        X:<Calc_Adr,r6        ; Adress
  245.  
  246.         move        X:<Voice_Volume,y0
  247.         move        X:<Master_Vol_R,y1
  248.         mpy        y0,y1,a    X:<Nb_Voices,y1
  249.         move        a0,y0
  250.         mpyr        y0,y1,a
  251.         lsl        a
  252.         move        a,y1                ; Volume
  253.  
  254.         move        #>2,x0
  255.         move        X:<Voice_Freq,x1    ; Frequence
  256.         move        r0,a
  257.         move        X:(r1),a0            ; Frac
  258.  
  259.         Do        X:<Length,Mix_Voice_Right_Loop
  260.  
  261.         mac        x0,x1,a        X:(r6),b        Y:(r0),y0
  262.         mac        y0,y1,b        a,r0
  263.         move                    b,X:(r6)+
  264.  
  265. Mix_Voice_Right_Loop
  266.         move        a0,X:(r1)            ; Frac
  267.         rts
  268.  
  269. ; Routines that receive 8 bits samples in X/Y memory
  270.  
  271. Receive_X_Samples
  272.         move        #Sample+1,r0
  273.         move        #3,n0
  274.         move        #>$ff0000,x1
  275.         move        #>$000080,y0
  276.         move        #>$008000,y1
  277.  
  278.         move        #>1,a
  279.         addr        a,b
  280.         Do        b,Receive_X_Loop_8
  281. Receive_X_Sample_8
  282.         jclr        #<HRDF,X:<<HSR,Receive_X_Sample_8
  283.         movep    X:<<HRX,x0
  284.         mpy        y0,x0,a
  285.         mpy        y1,x0,a        a0,b
  286.         and        x1,b            a0,X:(r0)-
  287.         move        b,X:(r0)+n0
  288. Receive_X_Loop_8
  289.         rts
  290.  
  291. Receive_Y_Samples
  292.         move        #Sample+1,r0
  293.         move        #3,n0
  294.         move        #>$ff0000,x1
  295.         move        #>$000080,y0
  296.         move        #>$008000,y1
  297.  
  298.         move        #>1,a
  299.         addr        a,b
  300.         Do        b,Receive_Y_Loop_8
  301. Receive_Y_Sample_8
  302.         jclr        #<HRDF,X:<<HSR,Receive_Y_Sample_8
  303.         movep    X:<<HRX,x0
  304.         mpy        y0,x0,a
  305.         mpy        y1,x0,a        a0,b
  306.         and        x1,b            a0,Y:(r0)-
  307.         move        b,Y:(r0)+n0
  308. Receive_Y_Loop_8
  309.         rts
  310.  
  311. ;
  312. ; Clears the sample buffer
  313. ;
  314. Clear_Sample_Buffer
  315.         move        a,X:<Save_a
  316.         move        r0,X:<Save_r0
  317.         clr        a        #Sample_Buffer,r0
  318.         Do        #<2048,Clear_Sample_Buffer_Loop
  319.         move        a,L:(r0)+
  320. Clear_Sample_Buffer_Loop
  321.         move        X:<Save_a,a
  322.         move        X:<Save_r0,r0
  323.         rti
  324.  
  325. ;
  326. ; P56 Binary Program Loader in Host Command
  327. ;
  328.  
  329. P56_Loader
  330.         jclr        #<HTDE,X:<<HSR,P56_Loader
  331.         movep    #'P56',X:<<HTX
  332.  
  333.         move        #P56_Loader_Host_Receive,r1    ; Routine Reception Host
  334.         movec    #<0,sp                    ; Pile a zero
  335.  
  336. P56_Loader_Next_Section
  337.         jsr        (r1)                        ; Type de Memoire
  338.         tfr        x0,b        x0,n0
  339.         tst        b        #Memory_Type,r0    ; Si négatif,
  340.         jmi        <0                        ; Execute Programme
  341.         movem    P:(r0+n0),r2                ; Routine de Reception
  342.         jsr        (r1)
  343.         move        x0,r0                    ; Adresse de Depart
  344.         jsr        (r1)                        ; Nombre de Blocs
  345.  
  346.         Do        x0,P56_Loader_Receive_Section
  347.         jsr        (r1)                        ; Recoit Bloc
  348.         jsr        (r2)                        ; Stocke-le
  349.         nop
  350. P56_Loader_Receive_Section
  351.         jmp        <P56_Loader_Next_Section
  352.  
  353. P56_Loader_Host_Receive
  354.         jclr        #<HRDF,X:<<HSR,P56_Loader_Host_Receive
  355.         movep    X:<<HRX,x0
  356.         rts
  357.  
  358. P56_Loader_P_Receive
  359.         movem    x0,P:(r0)+
  360.         rts
  361. P56_Loader_X_Receive
  362.         move        x0,X:(r0)+
  363.         rts
  364. P56_Loader_Y_Receive
  365.         move        x0,Y:(r0)+
  366.         rts
  367.  
  368. Memory_Type
  369.         DC        P56_Loader_P_Receive
  370.         DC        P56_Loader_X_Receive
  371.         DC        P56_Loader_Y_Receive
  372.  
  373. External_Code_Begin
  374.  
  375. ; Data Zone
  376.  
  377.             org        X:0
  378.  
  379. Old_Adr        DC        Sample_Buffer
  380. Calc_Adr        DS        1
  381. Length        DS        1
  382. Master_Vol_R    DS        1
  383. Master_Vol_L    DS        1
  384. Nb_Voices        DS        1
  385. Voice_Volume    DS        1
  386. Voice_Freq    DS        1
  387. Voices_Frac    DS        4+32
  388. Save_r0        DS        1
  389. Save_a        DS        1
  390. Sample        DS        672
  391.  
  392.             org        L:6*2048
  393.  
  394. Sample_Buffer    DS        2048
  395.  
  396.             END
  397.