---------------------------------------------------------------------------------- -- Company: -- Engineer: -- -- Create Date: 30.11.2021 10:35:30 -- Design Name: -- Module Name: Gene_Snake - Behavioral -- Project Name: -- Target Devices: -- Tool Versions: -- Description: -- -- Dependencies: -- -- Revision: -- Revision 0.01 - File Created -- Additional Comments: -- ---------------------------------------------------------------------------------- -- a faire: -- - faire bouger le snake -- - ajouter une clk 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; -- Uncomment the following library declaration if instantiating -- any Xilinx leaf cells in this code. --library UNISIM; --use UNISIM.VComponents.all; entity Gene_Snake is Port ( X : in unsigned (9 downto 0); Y : in unsigned (8 downto 0); up : in std_logic; down : in std_logic; left : in std_logic; right : in std_logic; reset: in std_logic; snakePresent : out std_logic); end Gene_Snake; architecture Behavioral of Gene_Snake is type coord is array(0 to 39, 0 to 29) of unsigned(10 downto 0); type direction is (haut, bas, gauche, droite); type pos is record X: unsigned(9 downto 0); Y: unsigned(8 downto 0); dir: direction; isDefined: std_logic; end record; type listSnake is array(0 to 1200) of pos; signal mat: coord; signal snake: listSnake; signal snakeHere: std_logic; begin process(X,Y,mat,reset, snake) variable ref : unsigned(10 downto 0); variable position : pos; begin if(reset='0') then -- snake <= (others=>(to_unsigned(1023,10),to_unsigned(511,10))); for i in 0 to snake'length-1 loop if(i<100) then snake(i).X <= to_unsigned(0,10); snake(i).Y <= to_unsigned(0,9); snake(i).isDefined <= '1'; else snake(i).X <= to_unsigned(1023,10); snake(i).Y <= to_unsigned(511,9); snake(i).isDefined <= '0'; end if; end loop; for x in 0 to 39 loop for y in 0 to 29 loop mat(x,y) <= to_unsigned(y*40+x,11); end loop; end loop; end if; ref := mat(to_integer(X/16),to_integer(Y/16)); position := snake(to_integer(ref)); if(position.isDefined = '0') then snakeHere <= '0'; else snakeHere <= '1'; end if; end process; snakePresent <= snakeHere; end Behavioral;