library ieee;
use ieee.std_logic_1164.all;

entity history_detector is
    port (SW : in std_logic_vector(9 downto 0);
          KEY : in std_logic_vector(3 downto 0);
          LEDR : out std_logic_vector(9 downto 0));
end entity;

architecture rtl of history_detector is
    signal zeros, ones : std_logic_vector(3 downto 0);
    signal found : std_logic;
begin
    process (KEY(0))
    begin
        if rising_edge(KEY(0)) then
            if SW(0) = '0' then
                zeros <= "0000";
                ones <= "0000";
            else
                zeros <= zeros(2 downto 0) & not SW(1);
                ones <= ones(2 downto 0) & SW(1);
            end if;
        end if;
    end process;
    found <= '1' when zeros = "1111" or ones /= "0000" -- TODO: require four sampled ones.
                 else '0';
    LEDR <= found & '0' & zeros & ones;
end architecture;
