package types is
  type type4 is ('X', '0', '1', 'Z');
  type x01z_vector is array (natural range <>) of type4;
end types;

use work.types.all;
entity address_decode is
  generic (RANGE_LEFT : integer := 0;
           RANGE_RIGHT : integer := 7);
  port (ADDRESS8 : in bit_vector (RANGE_LEFT to RANGE_RIGHT);
        CHECK : in x01z_vector(5 downto 0);
        SEL : out bit);
end address_decode;

architecture behav of address_decode is
begin
  process (ADDRESS8, CHECK)
    variable I : integer;
  begin
    SEL <= '1';
    I := 0;
    while I < 6 loop
      if (CHECK(5-i) /= 'X') then
        if (CHECK (5-i) = '0' and ADDRESS8(RANGE_LEFT+I) /= '0') then
          SEL <= '0';
        end if;
        if (CHECK (5-i) = '1' and ADDRESS8(RANGE_LEFT+I) /= '1') then
          SEL <= '0';
        end if;
        if (CHECK (5-i) = 'Z') then
          SEL <= '0';
        end if;
      end if;
      I := I + 1;
    end loop;
  end process;
end behav;
