library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity marquee is
    port (SW : in std_logic_vector(9 downto 0);
          HEX0 : out std_logic_vector(6 downto 0);
          HEX1 : out std_logic_vector(6 downto 0);
          HEX2 : out std_logic_vector(6 downto 0);
          HEX3 : out std_logic_vector(6 downto 0);
          HEX4 : out std_logic_vector(6 downto 0);
          HEX5 : out std_logic_vector(6 downto 0));
end entity;

architecture rtl of marquee is
    subtype segments is std_logic_vector(6 downto 0);
    type display_bank is array (0 to 5) of segments;
    signal display : display_bank;

    function decode(letter : std_logic_vector(1 downto 0)) return segments is
    begin
        case letter is
            when "00" => return "0100001"; -- d
            when "01" => return "0000110"; -- E
            when "10" => return "1111001"; -- 1
            when others => return "1111111"; -- blank
        end case;
    end function;
begin
    lane : for digit in 0 to 5 generate
        type word_type is array (0 to 5) of std_logic_vector(1 downto 0);
        constant word : word_type := ("10", "01", "00", "11", "11", "11");
        signal rotation : integer range 0 to 7;
        signal source_index : integer range 0 to 5;
    begin
        rotation <= to_integer(unsigned(SW(9 downto 7)));
        source_index <= digit; -- TODO: include the rotation setting.
        display(digit) <= decode(word(source_index)) when rotation < 6 else "1111111";
    end generate;

    HEX0 <= display(0);
    HEX1 <= display(1);
    HEX2 <= display(2);
    HEX3 <= display(3);
    HEX4 <= display(4);
    HEX5 <= display(5);
end architecture;
