library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;

entity sram_mux is
  
  port (
    ppu_active  : in std_logic;
    v_read  :  in std_logic;
    v_write :  in std_logic;
    cpu_read : in std_logic;
    cpu_write : in std_logic;
    v_data : in std_logic_vector(7 downto 0);
    cpu_data : in std_logic_vector(7 downto 0);
    --writing_2007 :in std_logic;
    sram_addr_cpu  : in std_logic_vector(15 downto 0);
    sram_addr_ppu  : in std_logic_vector(13 downto 0);
    sram_data_out : out std_logic_vector(15 downto 0);
    sram_read : out std_logic;
    sram_write : out std_logic;
    sram_addr : out std_logic_vector(17 downto 0));
end sram_mux;

architecture behavior of sram_mux is

--signal sram_addr_temp : std_logic_vector(17 downto 0);
  
begin  -- behavior


--         if ppu_active = '1' or sram_addr_cpu = "0010000000000111" then
--           sram_addr_temp = "0000" & sram_addr_ppu;
--         else
--           sram_addr_temp = "1000" & sram_addr_cpu;
--         end if;
--       end if;
--     end process;

--     sram_addr <= sram_addr_temp;
--     sram_data_out <= "00000000" & v_data;

  sram_addr <= "0000" & sram_addr_ppu when ppu_active = '1' or sram_addr_cpu = "0010000000000111" else
               "10" & sram_addr_cpu;

  sram_read <= v_read when ppu_active = '1' or sram_addr_cpu = "0010000000000111" else
               cpu_read;

  sram_write <= v_write when ppu_active = '1' or sram_addr_cpu = "0010000000000111" else
                cpu_write;

  sram_data_out <= "00000000" & v_data when ppu_active = '1' or sram_addr_cpu = "0010000000000111" else
                   "00000000" & cpu_data;
  
end behavior;
  
