snake-vhdl/sources_snake/updateSnake.vhd
2022-01-03 13:35:59 +01:00

209 lines
7.4 KiB
VHDL

----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 12/15/2021 02:06:27 PM
-- Design Name:
-- Module Name: updateSnake - Behavioral
-- Project Name:
-- Target Devices:
-- Tool Versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
use IEEE.NUMERIC_STD.ALL;
library ourTypes;
use ourTypes.types.all;
-- Uncomment the following library declaration if instantiating
-- any Xilinx leaf cells in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity updateSnake is
generic ( dataSize : integer);
Port (
clk : in std_logic;
reset : in std_logic;
address : out unsigned(SNAKE_ADDRESS_SIZE-1 downto 0);
data : out std_logic_vector(dataSize-1 downto 0);
writeEnable : out std_logic := '1';
matAddress : out unsigned(SNAKE_ADDRESS_SIZE-1 downto 0);
matData : out std_logic_vector(SNAKE_ADDRESS_SIZE-1 downto 0);
matWriteEnable : out std_logic := '1'
);
end updateSnake;
architecture Behavioral of updateSnake is
signal index : unsigned(SNAKE_ADDRESS_SIZE-1 downto 0) := to_unsigned(0,SNAKE_ADDRESS_SIZE);
signal currentSnake : pos;
signal matDataL : unsigned(SNAKE_ADDRESS_SIZE-1 downto 0);
begin
process(clk,reset,index) --process de reset
begin
if(clk'event and clk = '1') then
if(reset = '0') then --il faut qu'on ai le reset sur la clk car il controle indirectement l'entrée de la RAM
index <= to_unsigned(0,SNAKE_ADDRESS_SIZE);
writeEnable <= '1';
matWriteEnable <= '1';
else
index <= index + 1;
if(index = MAX_SNAKE-1) then
index <= to_unsigned(0,SNAKE_ADDRESS_SIZE);
writeEnable <= '0';
matWriteEnable <= '0';
end if;
end if;
end if;
--currentSnake.X <= to_unsigned(8+(to_integer(index) rem 40)*16,10);
--currentSnake.Y <= to_unsigned(8+to_integer(index/40)*16,9);
--currentSnake.dirX <= to_signed(-1,2);--to_signed(to_integer(index rem 3)-1,2);
--currentSnake.dirY <= to_signed(0,2);--to_signed(to_integer((index+1) rem 3)-1,2);
--case to_integer(index) is
-- when 0 => currentSnake.isDefined <= '1';
-- when 1 => currentSnake.isDefined <= '1';
-- when 2 => currentSnake.isDefined <= '1';
-- when 3 => currentSnake.isDefined <= '1';
-- when others => currentSnake.isDefined <= '0';
--end case;
--matAddress <= to_unsigned(to_integer(index),SNAKE_ADDRESS_SIZE);
--matData <= to_unsigned(to_integer(index),SNAKE_ADDRESS_SIZE);
if(index = 0) then
currentSnake.X <= to_unsigned(8,10);
currentSnake.Y <= to_unsigned(8,9);
currentSnake.dirX <= to_signed(0,2);
currentSnake.dirY <= to_signed(1,2);
currentSnake.isDefined <= '1';
elsif(index = 1) then
currentSnake.X <= to_unsigned(24,10);
currentSnake.Y <= to_unsigned(8,9);
currentSnake.dirX <= to_signed(-1,2);
currentSnake.dirY <= to_signed(0,2);
currentSnake.isDefined <= '1';
elsif(index = 2) then
currentSnake.X <= to_unsigned(24,10);
currentSnake.Y <= to_unsigned(24,9);
currentSnake.dirX <= to_signed(0,2);
currentSnake.dirY <= to_signed(-1,2);
currentSnake.isDefined <= '1';
elsif(index = 3) then
currentSnake.X <= to_unsigned(24,10);
currentSnake.Y <= to_unsigned(40,9);
currentSnake.dirX <= to_signed(0,2);
currentSnake.dirY <= to_signed(-1,2);
currentSnake.isDefined <= '1';
elsif(index = 4) then
currentSnake.X <= to_unsigned(40,10);
currentSnake.Y <= to_unsigned(40,9);
currentSnake.dirX <= to_signed(-1,2);
currentSnake.dirY <= to_signed(0,2);
currentSnake.isDefined <= '1';
elsif(index = 5) then
currentSnake.X <= to_unsigned(56,10);
currentSnake.Y <= to_unsigned(40,9);
currentSnake.dirX <= to_signed(0,2);
currentSnake.dirY <= to_signed(-1,2);
currentSnake.isDefined <= '1';
elsif(index = 6) then
currentSnake.X <= to_unsigned(56,10);
currentSnake.Y <= to_unsigned(56,9);
currentSnake.dirX <= to_signed(0,2);
currentSnake.dirY <= to_signed(-1,2);
currentSnake.isDefined <= '1';
elsif(index = 7) then
currentSnake.X <= to_unsigned(40,10);
currentSnake.Y <= to_unsigned(56,9);
currentSnake.dirX <= to_signed(1,2);
currentSnake.dirY <= to_signed(0,2);
currentSnake.isDefined <= '1';
elsif(index = 8) then
currentSnake.X <= to_unsigned(24,10);
currentSnake.Y <= to_unsigned(56,9);
currentSnake.dirX <= to_signed(1,2);
currentSnake.dirY <= to_signed(0,2);
currentSnake.isDefined <= '1';
elsif(index = 9) then
currentSnake.X <= to_unsigned(24,10);
currentSnake.Y <= to_unsigned(72,9);
currentSnake.dirX <= to_signed(0,2);
currentSnake.dirY <= to_signed(-1,2);
currentSnake.isDefined <= '1';
elsif(index = 10) then
currentSnake.X <= to_unsigned(24,10);
currentSnake.Y <= to_unsigned(88,9);
currentSnake.dirX <= to_signed(0,2);
currentSnake.dirY <= to_signed(-1,2);
currentSnake.isDefined <= '1';
elsif(index = 11) then
currentSnake.X <= to_unsigned(40,10);
currentSnake.Y <= to_unsigned(88,9);
currentSnake.dirX <= to_signed(-1,2);
currentSnake.dirY <= to_signed(0,2);
currentSnake.isDefined <= '1';
elsif(index = 12) then
currentSnake.X <= to_unsigned(40,10);
currentSnake.Y <= to_unsigned(72,9);
currentSnake.dirX <= to_signed(0,2);
currentSnake.dirY <= to_signed(1,2);
currentSnake.isDefined <= '1';
else
currentSnake.X <= to_unsigned(0,10);
currentSnake.Y <= to_unsigned(0,9);
currentSnake.dirX <= to_signed(0,2);
currentSnake.dirY <= to_signed(0,2);
currentSnake.isDefined <= '0';
end if;
case to_integer(index) is
when 0 => matDataL <= to_unsigned(0,SNAKE_ADDRESS_SIZE);
when 1 => matDataL <= to_unsigned(1,SNAKE_ADDRESS_SIZE);
when 41 => matDataL <= to_unsigned(2,SNAKE_ADDRESS_SIZE);
when 81 => matDataL <= to_unsigned(3,SNAKE_ADDRESS_SIZE);
when 82 => matDataL <= to_unsigned(4,SNAKE_ADDRESS_SIZE);
when 83 => matDataL <= to_unsigned(5,SNAKE_ADDRESS_SIZE);
when 123 => matDataL <= to_unsigned(6,SNAKE_ADDRESS_SIZE);
when 122 => matDataL <= to_unsigned(7,SNAKE_ADDRESS_SIZE);
when 121 => matDataL <= to_unsigned(8,SNAKE_ADDRESS_SIZE);
when 161 => matDataL <= to_unsigned(9,SNAKE_ADDRESS_SIZE);
when 201 => matDataL <= to_unsigned(10,SNAKE_ADDRESS_SIZE);
when 202 => matDataL <= to_unsigned(11,SNAKE_ADDRESS_SIZE);
when 162 => matDataL <= to_unsigned(12,SNAKE_ADDRESS_SIZE);
when others => matDataL <= to_unsigned(100,SNAKE_ADDRESS_SIZE);
end case;
matAddress <= index;
end process;
data <= to_stdlogicvector(currentSnake);
matData <= std_logic_vector(matDataL);
address <= index;
end Behavioral;