home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 4: The Falcon Archive / nf_archive_four_v1.0.iso / ARCHIVE / WORK / MSX / MEGPL116.ZIP / MGPL-116 / AMIGA / AMGDSPIT.ASM next >
Assembly Source File  |  1995-08-24  |  11KB  |  497 lines

  1. ;***********************************************************************
  2. ;***********                                         ***********
  3. ;***********                                         ***********
  4. ;***********              Amiga DSP Replay                 ***********
  5. ;***********               Under Interrupt                 ***********
  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.  
  55. ; Interrupt Routine that plays the sound with the SSI
  56.  
  57.         org        p:$40
  58.  
  59. Spl_Out    jset        #<2,X:<<SSISR,Right_Out    ; detect the second transfer
  60.  
  61. Left_Out    movep    Y:(r7),X:<<TX
  62.         rti
  63. Right_Out    movep    X:(r7)+,X:<<TX
  64.         rti
  65.  
  66. ;
  67. ; It Begins here :
  68. ;
  69.  
  70. Start    movep    #1,X:<<PBC            ; Port B in Host
  71.         movep    #$1f8,X:<<PCC            ; Port C in SSI
  72.         movep    #$4100,X:<<CRA            ; 1 voice 16 bits Stereo
  73.         movep    #$5800,X:<<CRB            ; enable X-mit IT
  74.         movep    #$3800,X:<<IPR            ; SSI at IPL 3
  75.                                     ; and Host at IPL 2
  76.         bset        #<HCIE,X:<<HCR            ; enable Host Command ITs
  77.  
  78. ; Initialisation of Registers
  79.  
  80.         move        #-1,m0
  81.         move        #1400-1,m7
  82.         move        m0,m1
  83.         move        m0,m2
  84.         move        m0,m3
  85.         move        m0,m4
  86.         move        m0,m5
  87.  
  88. ; Verify the connexion with the 030
  89.  
  90. Conct_Get    jclr        #<HRDF,X:<<HSR,Conct_Get
  91.         movep    X:<<HRX,x0
  92.  
  93. Conct_Snd    jclr        #<HTDE,X:<<HSR,Conct_Snd
  94.         movep    #12345678,X:<<HTX
  95.  
  96. ; Enable interrupts (IPL0) and waits
  97.         move        #Sample_Buffer,r7
  98.         andi        #<%11111100,mr
  99. Loop        jmp        <Loop
  100.  
  101. ;
  102. ; Sound-Tracker Routine in Host Command
  103. ;
  104.  
  105. SoundTrack_Rout
  106.         jsr        <Save_Registers_And_Host
  107.  
  108.         move        #<Length,r0
  109.  
  110.         move        X:<Old_Adr,x0            ; Number of Samples
  111.         move        x0,X:<Calc_Adr            ; to calculate = Current Pos
  112.         move        r7,a                    ; - Old Position
  113.         sub        x0,a            r7,X:Old_Adr
  114.         jpl        <Length_Ok
  115.         move        #>1400,x0                ; Warning Modulo !
  116.         add        x0,a
  117. Length_Ok    move        a,X:(r0)+                ; Sample Length
  118.  
  119. Get_MVolL    jclr        #<HRDF,X:<<HSR,Get_MVolL
  120.         movep    X:<<HRX,X:(r0)+        ; Left Master Volume
  121. Get_MVolR    jclr        #<HRDF,X:<<HSR,Get_MVolR
  122.         movep    X:<<HRX,X:(r0)+        ; Right Master Volume
  123.  
  124. ; Gets the number of Voices
  125.  
  126. Get_NbV    jclr        #<HRDF,X:<<HSR,Get_NbV
  127.         movep    X:<<HRX,y0
  128.         tfr        y0,b
  129.         lsr        b        #>1,a
  130.  
  131.         andi        #<$fe,ccr                ; Cancel Carry Bit
  132.         Rep        #<24
  133.         div        y0,a                    ; a0 = 1 / Nb Voices
  134.         move        a0,X:(r0)
  135.  
  136. ; Clears the sample-buffer before mixing
  137.         clr        a        X:Calc_Adr,r6
  138.         move        m7,m6
  139.  
  140.         move        X:Length,x0
  141.         Do        x0,Clear_Sample
  142.         move        a,L:(r6)+
  143. Clear_Sample
  144.  
  145. ; Mix All Voices
  146.         move        #Voices_Frac,r1
  147.  
  148.         Do        b,Mix_All_Voices_Loop
  149.  
  150.         jsr        <Request
  151.         jsr        <Receive_Volume
  152.         tst        a
  153.         jeq        <Next_Voice_L
  154.         jsr        <Receive_Frequency
  155.         jsr        <Receive_X_Samples
  156.         jsr        <Mix_Voice_Left
  157.  
  158. Next_Voice_L
  159.         lua        (r1)+,r1
  160.  
  161.         jsr        <Request
  162.         jsr        <Receive_Volume
  163.         tst        a
  164.         jeq        <Next_Voice_R
  165.         jsr        <Receive_Frequency
  166.         jsr        <Receive_Y_Samples
  167.         jsr        <Mix_Voice_Right
  168.         
  169. Next_Voice_R
  170.         lua        (r1)+,r1
  171. Mix_All_Voices_Loop
  172.  
  173. ; It's Finished for this time
  174. Send_End    jclr        #<HTDE,X:<<HSR,Send_End
  175.         movep    #0,X:<<HTX
  176.  
  177.         jsr        <Restore_Registers_And_Host
  178.         rti
  179.  
  180.  
  181. ; Calls the 030
  182. Request    jclr        #<HTDE,X:<<HSR,Request
  183.         movep    #-1,X:<<HTX
  184.         rts
  185.  
  186. ; Receives the Sample Volume
  187. Receive_Volume
  188.         move        #Voice_Volume,r0
  189.         jclr        #<HRDF,X:<<HSR,Receive_Volume
  190.         movep    X:<<HRX,a
  191.         move        a,X:(r0)+                ; Sample Volume
  192.         rts
  193.  
  194. ; Receives the sample frequency
  195. Receive_Frequency
  196.         jclr        #<HRDF,X:<<HSR,Receive_Frequency
  197.         movep    X:<<HRX,x0                ; Sample Frequency
  198.         move        X:<Length,b
  199.         lsl        b
  200.         clr        b            b,x1
  201.         move        X:(r1),b0                    ; Frac Part
  202.         mac        x0,x1,b        x0,X:(r0)
  203. Send_Length
  204.         jclr        #<HTDE,X:<<HSR,Send_Length    ; Length of Sample
  205.         movep    b,X:<<HTX                    ; played in this frame
  206.         rts
  207.  
  208. ; Routine that mixes a new voice on the left channel
  209.  
  210. Mix_Voice_Left
  211.         move        #Sample,r0
  212.         move        X:<Calc_Adr,r6        ; Adress
  213.  
  214.         move        X:<Voice_Volume,x0
  215.         move        X:<Master_Vol_L,x1
  216.         mpy        x0,x1,a    X:<Nb_Voices,x1
  217.         move        a0,x0
  218.         mpyr        x0,x1,a
  219.         lsl        a
  220.         move        a,x1                ; Volume
  221.  
  222.         move        #>2,y0
  223.         move        X:<Voice_Freq,y1    ; Frequence
  224.         move        r0,b
  225.         move        X:(r1),b0            ; Frac
  226.  
  227.         Do        X:<Length,Mix_Voice_Left_Loop
  228.  
  229.         mac        y0,y1,b        Y:(r6),a        X:(r0),x0
  230.         mac        x0,x1,a        b,r0
  231.         move                    a,Y:(r6)+
  232.  
  233. Mix_Voice_Left_Loop
  234.         move        b0,X:(r1)            ; Frac
  235.         rts
  236.  
  237. ; Routine that mixes a new voice on the right channel
  238.  
  239. Mix_Voice_Right
  240.         move        #Sample,r0
  241.         move        X:<Calc_Adr,r6        ; Adress
  242.  
  243.         move        X:<Voice_Volume,y0
  244.         move        X:<Master_Vol_R,y1
  245.         mpy        y0,y1,a    X:<Nb_Voices,y1
  246.         move        a0,y0
  247.         mpyr        y0,y1,a
  248.         lsl        a
  249.         move        a,y1                ; Volume
  250.  
  251.         move        #>2,x0
  252.         move        X:<Voice_Freq,x1    ; Frequence
  253.         move        r0,a
  254.         move        X:(r1),a0            ; Frac
  255.  
  256.         Do        X:<Length,Mix_Voice_Right_Loop
  257.  
  258.         mac        x0,x1,a        X:(r6),b        Y:(r0),y0
  259.         mac        y0,y1,b        a,r0
  260.         move                    b,X:(r6)+
  261.  
  262. Mix_Voice_Right_Loop
  263.         move        a0,X:(r1)            ; Frac
  264.         rts
  265.  
  266. ; Routines that receive 8 bits samples in X/Y memory
  267.  
  268. Receive_X_Samples
  269.         move        #Sample+1,r0
  270.         move        #3,n0
  271.         move        #>$ff0000,x1
  272.         move        #>$000080,y0
  273.         move        #>$008000,y1
  274.  
  275.         move        #>1,a
  276.         addr        a,b
  277.         Do        b,Receive_X_Loop_8
  278. Receive_X_Sample_8
  279.         jclr        #<HRDF,X:<<HSR,Receive_X_Sample_8
  280.         movep    X:<<HRX,x0
  281.         mpy        y0,x0,a
  282.         mpy        y1,x0,a        a0,b
  283.         and        x1,b            a0,X:(r0)-
  284.         move        b,X:(r0)+n0
  285. Receive_X_Loop_8
  286.         rts
  287.  
  288. Receive_Y_Samples
  289.         move        #Sample+1,r0
  290.         move        #3,n0
  291.         move        #>$ff0000,x1
  292.         move        #>$000080,y0
  293.         move        #>$008000,y1
  294.  
  295.         move        #>1,a
  296.         addr        a,b
  297.         Do        b,Receive_Y_Loop_8
  298. Receive_Y_Sample_8
  299.         jclr        #<HRDF,X:<<HSR,Receive_Y_Sample_8
  300.         movep    X:<<HRX,x0
  301.         mpy        y0,x0,a
  302.         mpy        y1,x0,a        a0,b
  303.         and        x1,b            a0,Y:(r0)-
  304.         move        b,Y:(r0)+n0
  305. Receive_Y_Loop_8
  306.         rts
  307.  
  308. ;
  309. ; Save what was on the Host Port before interrupt
  310. ;
  311.  
  312. Save_Registers_And_Host
  313.         move        r0,X:Save_r0
  314.         move        #Save_Registers,r0
  315.         nop
  316.         move        r1,X:(r0)+
  317.         move        r2,X:(r0)+
  318.         move        r3,X:(r0)+
  319.         move        r4,X:(r0)+
  320.         move        r5,X:(r0)+
  321.         move        r6,X:(r0)+
  322.         move        m6,X:(r0)+
  323.         move        x0,X:(r0)+
  324.         move        x1,X:(r0)+
  325.         move        y0,X:(r0)+
  326.         move        y1,X:(r0)+
  327.         move        a0,X:(r0)+
  328.         move        a1,X:(r0)+
  329.         move        a2,X:(r0)+
  330.         move        b0,X:(r0)+
  331.         move        b1,X:(r0)+
  332.         move        b2,X:(r0)
  333.  
  334. ; On sauve tout ce que le 030 avait envoyé au DSP avant
  335.  
  336.         move        #Save_Host1,r0
  337.         move        #>'030',x0
  338.  
  339. Save_Host_030_To_DSP
  340.         jclr        #<HRDF,X:<<HSR,Save_Host_030_To_DSP
  341.         movep    X:<<HRX,a
  342.         move        a,X:(r0)+
  343.         cmp        x0,a
  344.         jne        <Save_Host_030_To_DSP
  345.  
  346. ; On signale la fin des données que le DSP avait envoyées au 030
  347.  
  348. Send_Host    jclr        #<HTDE,X:<<HSR,Send_Host
  349.         movep    #>'DSP',X:<<HTX
  350.  
  351. ; On sauve tout ce que le DSP avait envoyé au 030 avant
  352.  
  353.         move        #Save_Host2,r0
  354.         move        #>'DSP',x0
  355.  
  356. Save_Host_DSP_To_030
  357.         jclr        #<HRDF,X:<<HSR,Save_Host_DSP_To_030
  358.         movep    X:<<HRX,a
  359.         move        a,X:(r0)+
  360.         cmp        x0,a
  361.         jne        <Save_Host_DSP_To_030
  362.  
  363. ; On envoie tout ce que le 030 avait envoyé au DSP avant
  364.  
  365.         move        #Save_Host1,r0
  366.         move        #>'030',x0
  367.  
  368. Restore_Host_030_To_DSP
  369.         jclr        #<HTDE,X:<<HSR,Restore_Host_030_To_DSP
  370.         move        X:(r0)+,a
  371.         movep    a,X:<<HTX
  372.         cmp        x0,a
  373.         jne        <Restore_Host_030_To_DSP
  374.         rts
  375.  
  376. ;
  377. ; Restore Host Port
  378. ;
  379.  
  380. ; On envoie tout ce que le DSP avait envoyé au 030 avant
  381.  
  382. Restore_Registers_And_Host
  383.         move        #Save_Host2,r0
  384.         move        #>'DSP',x0
  385.  
  386. Restore_Host_DSP_To_030
  387.         move        X:(r0)+,a
  388.         cmp        x0,a
  389.         jeq        <Restore_Host_End
  390. Restore_Wait
  391.         jclr        #<HTDE,X:<<HSR,Restore_Wait
  392.         movep    a,X:<<HTX
  393.         jmp        <Restore_Host_DSP_To_030
  394.  
  395. Restore_Host_End
  396.         move        #Save_Registers,r0
  397.         nop
  398.         move        X:(r0)+,r1
  399.         move        X:(r0)+,r2
  400.         move        X:(r0)+,r3
  401.         move        X:(r0)+,r4
  402.         move        X:(r0)+,r5
  403.         move        X:(r0)+,r6
  404.         move        X:(r0)+,m6
  405.         move        X:(r0)+,x0
  406.         move        X:(r0)+,x1
  407.         move        X:(r0)+,y0
  408.         move        X:(r0)+,y1
  409.         move        X:(r0)+,a0
  410.         move        X:(r0)+,a1
  411.         move        X:(r0)+,a2
  412.         move        X:(r0)+,b0
  413.         move        X:(r0)+,b1
  414.         move        X:(r0),b2
  415.  
  416.         move        X:Save_r0,r0
  417.         rts
  418.  
  419. ;
  420. ; P56 Binary Program Loader in Host Command
  421. ;
  422.  
  423. P56_Loader
  424.         jclr        #<HTDE,X:<<HSR,P56_Loader
  425.         movep    #'P56',X:<<HTX
  426.  
  427.         move        #P56_Loader_Host_Receive,r1    ; Routine Reception Host
  428.         movec    #<0,sp                    ; Pile a zero
  429.  
  430. P56_Loader_Next_Section
  431.         jsr        (r1)                        ; Type de Memoire
  432.         tfr        x0,b        x0,n0
  433.         tst        b        #Memory_Type,r0    ; Si négatif,
  434.         jmi        <0                        ; Execute Programme
  435.         movem    P:(r0+n0),r2                ; Routine de Reception
  436.         jsr        (r1)
  437.         move        x0,r0                    ; Adresse de Depart
  438.         jsr        (r1)                        ; Nombre de Blocs
  439.  
  440.         Do        x0,P56_Loader_Receive_Section
  441.         jsr        (r1)                        ; Recoit Bloc
  442.         jsr        (r2)                        ; Stocke-le
  443.         nop
  444. P56_Loader_Receive_Section
  445.         jmp        <P56_Loader_Next_Section
  446.  
  447. P56_Loader_Host_Receive
  448.         jclr        #<HRDF,X:<<HSR,P56_Loader_Host_Receive
  449.         movep    X:<<HRX,x0
  450.         rts
  451.  
  452. P56_Loader_P_Receive
  453.         movem    x0,P:(r0)+
  454.         rts
  455. P56_Loader_X_Receive
  456.         move        x0,X:(r0)+
  457.         rts
  458. P56_Loader_Y_Receive
  459.         move        x0,Y:(r0)+
  460.         rts
  461.  
  462. Memory_Type
  463.         DC        P56_Loader_P_Receive
  464.         DC        P56_Loader_X_Receive
  465.         DC        P56_Loader_Y_Receive
  466.  
  467. External_Code_Begin
  468.  
  469. ; Data Zone
  470.  
  471.             org        X:0
  472.  
  473. Save_Host1    DS        3
  474. Save_Host2    DS        3
  475. Save_r0        DS        1
  476. Save_Registers    DS        17
  477.  
  478. Old_Adr        DC        Sample_Buffer
  479. Calc_Adr        DS        1
  480. Length        DS        1
  481. Master_Vol_R    DS        1
  482. Master_Vol_L    DS        1
  483. Nb_Voices        DS        1
  484. Voice_Volume    DS        1
  485. Voice_Freq    DS        1
  486. Voices_Frac    DS        32
  487.  
  488.             org        L:7*2048-680
  489.  
  490. Sample        DS        672
  491.  
  492.             org        L:7*2048
  493.  
  494. Sample_Buffer    DS        1400            ; for 32.78 KHz
  495.  
  496.             END
  497.