------------------------------------------------------------------------------- library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- entity command_mapper is Port ( rst: in std_logic; -- reset busy: in std_logic; -- sincronizacao scan_code:in std_logic_vector(7 downto 0); -- keyboard scan code ascii : out std_logic_vector(7 downto 0); cursor_pos: out std_logic_vector(10 downto 0) -- posicao do cursor ); end command_mapper; ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- architecture Behavioral of command_mapper is signal posx: natural range 4 to 35 := 4; -- coluna signal posy: natural range 4 to 25 := 4; -- linha begin ------------------------------------------------------------------------------- process(scan_code, busy) begin if busy /= '1' then case scan_code is --Digitos when x"45" => ascii <= x"30"; when x"16" => ascii <= x"31"; when x"1E" => ascii <= x"32"; when x"26" => ascii <= x"33"; when x"25" => ascii <= x"34"; when x"2E" => ascii <= x"35"; when x"36" => ascii <= x"36"; when x"3D" => ascii <= x"37"; when x"3E" => ascii <= x"38"; when x"46" => ascii <= x"39"; --Caracteres when x"1C" => ascii <=x"41"; --A when x"32" => ascii <=x"42"; --B when x"21" => ascii <=x"43"; --C when x"23" => ascii <=x"44"; --D when x"24" => ascii <=x"45"; --E when x"2B" => ascii <=x"46"; --F when x"34" => ascii <=x"47"; --G when x"33" => ascii <=x"48"; --H when x"43" => ascii <=x"49"; --I when x"3B" => ascii <=x"4A"; --J when x"42" => ascii <=x"4B"; --K when x"4B" => ascii <=x"4C"; --L when x"3A" => ascii <=x"4D"; --M when x"31" => ascii <=x"4E"; --N when x"44" => ascii <=x"4F"; --O when x"4D" => ascii <=x"50"; --P when x"15" => ascii <=x"51"; --Q when x"2D" => ascii <=x"52"; --R when x"1B" => ascii <=x"53"; --S when x"2C" => ascii <=x"54"; --T when x"3C" => ascii <=x"55"; --U when x"2A" => ascii <=x"56"; --V when x"1D" => ascii <=x"57"; --W when x"22" => ascii <=x"58"; --X when x"35" => ascii <=x"59"; --Y when x"1A" => ascii <=x"5A"; --Z --Movimentacao -- escreve um espaço no ecra e muda a posicao do cursor, -- conforme space ou backspace when x"66" => ascii <= x"20"; -- BACKSPACE when x"29" => ascii <= x"20"; -- SPACE when others => null; end case; end if; end process; ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- cursor_pos <= conv_std_logic_vector(posx+posy*39,11); ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- process(busy, scan_code, rst) begin if rst='0' then posx <= 4; posy <= 4; elsif falling_edge(busy) then case scan_code is when x"16" => posx <= posx+1; -- Digitos when x"1E" => posx <= posx+1; when x"26" => posx <= posx+1; when x"25" => posx <= posx+1; when x"2E" => posx <= posx+1; when x"36" => posx <= posx+1; when x"3D" => posx <= posx+1; when x"3E" => posx <= posx+1; when x"46" => posx <= posx+1; when x"45" => posx <= posx+1; when x"29" => posx <= posx+1; -- SPACE when x"66" => posx <= posx-1; -- BACKSPACE when x"1C" => posx <= posx+1; --A when x"32" => posx <= posx+1; --B when x"21" => posx <= posx+1; --C when x"23" => posx <= posx+1; --D when x"24" => posx <= posx+1; --E when x"2B" => posx <= posx+1; --F when x"34" => posx <= posx+1; --G when x"33" => posx <= posx+1; --H when x"43" => posx <= posx+1; --I when x"3B" => posx <= posx+1; --J when x"42" => posx <= posx+1; --K when x"4B" => posx <= posx+1; --L when x"3A" => posx <= posx+1; --M when x"31" => posx <= posx+1; --N when x"44" => posx <= posx+1; --O when x"4D" => posx <= posx+1; --P when x"15" => posx <= posx+1; --Q when x"2D" => posx <= posx+1; --R when x"1B" => posx <= posx+1; --S when x"2C" => posx <= posx+1; --T when x"3C" => posx <= posx+1; --U when x"2A" => posx <= posx+1; --V when x"1D" => posx <= posx+1; --W when x"22" => posx <= posx+1; --X when x"35" => posx <= posx+1; --Y when x"1A" => posx <= posx+1; --Z when others => null; end case; if posx=35 then posx <= 4; posy <= posy+1; elsif posy=25 then posy <= 25; -- se esta a apagar e esta no inicio de uma linha: elsif (posx=4 and scan_code=x"66" and posy>4) then posy <= posy-1; posx <= 35; -- dar a volta se chegar ao fim da janela: elsif (posx=35 and posy=25) then posx <= 4; posy <= 4; end if; end if; end process; ------------------------------------------------------------------------------- end Behavioral;