Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------------------------------------------------------------------------------
- -- Company:
- -- Engineer:
- --
- -- Create Date: 20:23:40 10/11/2014
- -- Design Name:
- -- Module Name: BackgroundRenderer - Behavioral
- -- Project Name:
- -- Target Devices:
- -- Tool versions:
- -- Description:
- --
- -- Dependencies:
- --
- -- Revision:
- -- Revision 0.01 - File Created
- -- Additional Comments:
- --
- ----------------------------------------------------------------------------------
- library IEEE;
- use IEEE.STD_LOGIC_1164.ALL;
- -- Uncomment the following library declaration if using
- -- arithmetic functions with Signed or Unsigned values
- use IEEE.NUMERIC_STD.ALL;
- -- Uncomment the following library declaration if instantiating
- -- any Xilinx primitives in this code.
- --library UNISIM;
- --use UNISIM.VComponents.all;
- use work.Types.all;
- entity BackgroundRenderer is
- Port (
- --Shader priority chain
- ripple_out : out STD_LOGIC;
- ripple_in : in STD_LOGIC;
- data_out : out STD_LOGIC_VECTOR (7 downto 0);
- data_in : in STD_LOGIC_VECTOR (7 downto 0);
- --Clocks etc
- posx : in integer range 0 to 319;
- posy : in integer range 0 to 239;
- vertical_reset: in STD_LOGIC;
- clk_phase : in integer range 0 to 15;
- clk : in STD_LOGIC;
- --Shader control interface
- ioadr : in STD_LOGIC_VECTOR(7 downto 0);
- iodata_in : in STD_LOGIC_VECTOR(7 downto 0);
- iodata_out : out STD_LOGIC_VECTOR(7 downto 0);
- iord, iowr : in STD_LOGIC;
- iobusy : out STD_LOGIC;
- --SRAM interface
- mem_adr : out STD_LOGIC_VECTOR (18 downto 0);
- mem_data : inout STD_LOGIC_VECTOR (7 downto 0);
- mem_oe, mem_we : out STD_LOGIC
- );
- end BackgroundRenderer;
- architecture Behavioral of BackgroundRenderer is
- signal my_data: STD_LOGIC_VECTOR (7 downto 0);
- signal my_data_available : STD_LOGIC := '0';
- signal isIoBusy, isIoDone : STD_LOGIC := '0';
- --Shader control registers
- signal ctrlRegs : logic_vector8_arr (7 downto 0);
- constant a_offset_x_lsb : integer := 0;
- constant a_offset_x_msb : integer := 1;
- constant a_offset_y_lsb : integer := 2;
- constant a_offset_y_msb : integer := 3;
- constant a_transp_color : integer := 4;
- constant a_sram_adr_lsb : integer := 5;
- constant a_sram_adr_msb : integer := 6;
- begin
- iobusy <= isIoBusy;
- process is
- variable ioAccessLatch : STD_LOGIC := '0';
- begin
- wait until rising_edge(clk);
- if clk_phase = 15 then
- my_data <= "00000000";
- my_data_available <= '0';
- mem_oe <= '1';
- mem_we <= '1';
- for i in ctrlRegs'length-1 downto 0 loop
- ctrlRegs(i) <= "00000000";
- end loop;
- isIoBusy <= '1';
- isIoDone <= '0';
- iodata_out <= "00000000";
- ioAccessLatch := '0';
- elsif clk_phase = 1 then
- --Perform SRAM read
- mem_adr <= std_logic_vector(to_unsigned(posy, 9)) & std_logic_vector(to_unsigned(posx, 10));
- mem_data <= "ZZZZZZZZ";
- mem_oe <= '0';
- ioAccessLatch := iord or iowr;
- elsif clk_phase = 4 then
- --Get SRAM data
- mem_oe <= '1';
- my_data <= mem_data;
- my_data_available <= '1';
- --Perform I/O SRAM access
- if (ioAccessLatch = '1') and (isIoDone = '0') then
- if ioadr(7) = '1' then
- mem_adr <= ctrlRegs(a_sram_adr_msb)(3 downto 0) & ctrlRegs(a_sram_adr_lsb) & ioadr(6 downto 0);
- if iowr = '1' then
- mem_data <= iodata_in;
- mem_oe <= '1';
- elsif iord = '1' then
- mem_data <= "ZZZZZZZZ";
- mem_oe <= '0';
- end if;
- end if;
- end if;
- elsif clk_phase = 6 then
- --Perform I/O SRAM write
- if (iowr = '1') and (ioadr(7) = '1') and (isIoDone = '0') and (ioAccessLatch = '1') then
- mem_we <= '0';
- end if;
- elsif clk_phase = 7 then
- --Finish I/O SRAM access
- mem_we <= '1';
- mem_oe <= '1';
- if (ioAccessLatch = '1') and (isIoDone = '0') then
- if iord = '1' then
- if ioadr(7) = '1' then
- iodata_out <= mem_data;
- else
- iodata_out <= ctrlRegs(to_integer(unsigned(ioadr(2 downto 0))));
- end if;
- elsif iowr = '1' then
- if ioadr(7) = '1' then
- --We already performed that write
- else
- ctrlRegs(to_integer(unsigned(ioadr(2 downto 0)))) <= iodata_in;
- end if;
- end if;
- isIoDone <= '1';
- end if;
- end if;
- if clk_phase /= 15 then
- if (isIoBusy = '0') and (iord = '0') and (iowr = '0') then
- isIoDone <= '0';
- end if;
- if ((iord = '1') or (iowr = '1')) and (isIoDone = '0') then
- isIoBusy <= '1';
- else
- isIoBusy <= '0';
- end if;
- end if;
- end process;
- ripple_out <= ripple_in or my_data_available;
- data_out <= data_in when (ripple_in='1' or my_data_available='0') else my_data;
- end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment