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

entity word_rotator 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);
          LEDR : out std_logic_vector(9 downto 0));
end entity;

architecture rtl of word_rotator is
    subtype segments is std_logic_vector(6 downto 0);
    type display_bank is array (0 to 3) 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
    LEDR <= SW;
    lane : for digit in 0 to 3 generate
        signal source_index : integer range 0 to 3;
    begin
        source_index <= digit; -- TODO: include the rotation setting.
        display(digit) <= decode(SW(2*source_index + 1 downto 2*source_index));
    end generate;

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