Guest User

Untitled

a guest
Oct 21st, 2014
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 4.75 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date:    20:23:40 10/11/2014
  6. -- Design Name:
  7. -- Module Name:    BackgroundRenderer - Behavioral
  8. -- Project Name:
  9. -- Target Devices:
  10. -- Tool versions:
  11. -- Description:
  12. --
  13. -- Dependencies:
  14. --
  15. -- Revision:
  16. -- Revision 0.01 - File Created
  17. -- Additional Comments:
  18. --
  19. ----------------------------------------------------------------------------------
  20. library IEEE;
  21. use IEEE.STD_LOGIC_1164.ALL;
  22.  
  23. -- Uncomment the following library declaration if using
  24. -- arithmetic functions with Signed or Unsigned values
  25. use IEEE.NUMERIC_STD.ALL;
  26.  
  27. -- Uncomment the following library declaration if instantiating
  28. -- any Xilinx primitives in this code.
  29. --library UNISIM;
  30. --use UNISIM.VComponents.all;
  31.  
  32. use work.Types.all;
  33.  
  34.  
  35. entity BackgroundRenderer is
  36.     Port (
  37.               --Shader priority chain
  38.               ripple_out : out  STD_LOGIC;
  39.               ripple_in : in STD_LOGIC;
  40.            data_out : out  STD_LOGIC_VECTOR (7 downto 0);
  41.               data_in : in STD_LOGIC_VECTOR (7 downto 0);
  42.              
  43.               --Clocks etc
  44.            posx : in  integer range 0 to 319;
  45.            posy : in  integer range 0 to 239;
  46.               vertical_reset: in STD_LOGIC;
  47.               clk_phase : in integer range 0 to 15;
  48.               clk : in STD_LOGIC;
  49.              
  50.               --Shader control interface
  51.               ioadr : in STD_LOGIC_VECTOR(7 downto 0);
  52.               iodata_in : in STD_LOGIC_VECTOR(7 downto 0);
  53.               iodata_out : out STD_LOGIC_VECTOR(7 downto 0);
  54.               iord, iowr : in STD_LOGIC;
  55.               iobusy : out STD_LOGIC;
  56.              
  57.               --SRAM interface
  58.               mem_adr : out STD_LOGIC_VECTOR (18 downto 0);
  59.               mem_data : inout STD_LOGIC_VECTOR (7 downto 0);
  60.               mem_oe, mem_we : out STD_LOGIC
  61.               );
  62. end BackgroundRenderer;
  63.  
  64. architecture Behavioral of BackgroundRenderer is
  65.     signal my_data: STD_LOGIC_VECTOR (7 downto 0);
  66.     signal my_data_available : STD_LOGIC := '0';
  67.     signal isIoBusy, isIoDone : STD_LOGIC := '0';
  68.    
  69.     --Shader control registers
  70.     signal ctrlRegs : logic_vector8_arr (7 downto 0);
  71.     constant a_offset_x_lsb : integer := 0;
  72.     constant a_offset_x_msb : integer := 1;
  73.     constant a_offset_y_lsb : integer := 2;
  74.     constant a_offset_y_msb : integer := 3;
  75.     constant a_transp_color : integer := 4;
  76.     constant a_sram_adr_lsb : integer := 5;
  77.     constant a_sram_adr_msb : integer := 6;
  78. begin
  79.     iobusy <= isIoBusy;
  80.    
  81.    
  82.     process is
  83.         variable ioAccessLatch : STD_LOGIC := '0';
  84.     begin
  85.         wait until rising_edge(clk);
  86.        
  87.        
  88.         if clk_phase = 15 then
  89.             my_data <= "00000000";
  90.             my_data_available <= '0';
  91.             mem_oe <= '1';
  92.             mem_we <= '1';
  93.            
  94.             for i in ctrlRegs'length-1 downto 0 loop
  95.                 ctrlRegs(i) <= "00000000";
  96.             end loop;
  97.            
  98.             isIoBusy <= '1';
  99.             isIoDone <= '0';
  100.             iodata_out <= "00000000";
  101.             ioAccessLatch := '0';
  102.            
  103.         elsif clk_phase = 1 then
  104.             --Perform SRAM read
  105.             mem_adr <= std_logic_vector(to_unsigned(posy, 9)) & std_logic_vector(to_unsigned(posx, 10));
  106.             mem_data <= "ZZZZZZZZ";
  107.             mem_oe <= '0';
  108.            
  109.             ioAccessLatch := iord or iowr;
  110.            
  111.         elsif clk_phase = 4 then
  112.             --Get SRAM data
  113.             mem_oe <= '1';
  114.             my_data <= mem_data;
  115.             my_data_available <= '1';
  116.            
  117.             --Perform I/O SRAM access
  118.             if (ioAccessLatch = '1') and (isIoDone = '0') then
  119.                 if ioadr(7) = '1' then
  120.                     mem_adr <= ctrlRegs(a_sram_adr_msb)(3 downto 0) & ctrlRegs(a_sram_adr_lsb) & ioadr(6 downto 0);
  121.                     if iowr = '1' then
  122.                         mem_data <= iodata_in;
  123.                         mem_oe <= '1';
  124.                     elsif iord = '1' then
  125.                         mem_data <= "ZZZZZZZZ";
  126.                         mem_oe <= '0';
  127.                     end if;
  128.                 end if;
  129.             end if;
  130.            
  131.         elsif clk_phase = 6 then
  132.             --Perform I/O SRAM write
  133.             if (iowr = '1') and (ioadr(7) = '1') and (isIoDone = '0') and (ioAccessLatch = '1') then
  134.                 mem_we <= '0';
  135.             end if;
  136.            
  137.         elsif clk_phase = 7 then
  138.             --Finish I/O SRAM access
  139.             mem_we <= '1';
  140.             mem_oe <= '1';
  141.            
  142.             if (ioAccessLatch = '1') and (isIoDone = '0') then
  143.                 if iord = '1' then
  144.                     if ioadr(7) = '1' then
  145.                         iodata_out <= mem_data;
  146.                     else
  147.                         iodata_out <= ctrlRegs(to_integer(unsigned(ioadr(2 downto 0))));
  148.                     end if;
  149.                 elsif iowr = '1' then
  150.                     if ioadr(7) = '1' then
  151.                         --We already performed that write
  152.                     else
  153.                         ctrlRegs(to_integer(unsigned(ioadr(2 downto 0)))) <= iodata_in;
  154.                     end if;
  155.                 end if;
  156.                 isIoDone <= '1';
  157.             end if;
  158.            
  159.         end if;
  160.        
  161.         if clk_phase /= 15 then
  162.             if (isIoBusy = '0') and (iord = '0') and (iowr = '0') then
  163.                 isIoDone <= '0';
  164.             end if;
  165.            
  166.             if ((iord = '1') or (iowr = '1')) and (isIoDone = '0') then
  167.                 isIoBusy <= '1';
  168.             else
  169.                 isIoBusy <= '0';
  170.             end if;
  171.         end if;
  172.        
  173.     end process;
  174.    
  175.     ripple_out <= ripple_in or my_data_available;
  176.     data_out <= data_in when (ripple_in='1' or my_data_available='0') else my_data;
  177.    
  178.    
  179. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment