67 lines
2.4 KiB
VHDL
67 lines
2.4 KiB
VHDL
library ieee;
|
|
use ieee.std_logic_1164.all;
|
|
use ieee.numeric_std.all;
|
|
|
|
package types is
|
|
constant MAX_SNAKE : integer := 1200;
|
|
constant SNAKE_ADDRESS_SIZE : integer :=11;
|
|
|
|
constant SPRITES_ADDRESS_SIZE : integer := 8;
|
|
constant SPRITES_DATA_LENGTH : integer := 256;
|
|
constant SPRITES_DATA_SIZE : integer := 24;
|
|
|
|
type coord is array(0 to 39, 0 to 29) of unsigned(SNAKE_ADDRESS_SIZE-1 downto 0);
|
|
type pos is record
|
|
X: unsigned(9 downto 0);
|
|
Y: unsigned(8 downto 0);
|
|
dirX: signed(1 downto 0);
|
|
dirY: signed(1 downto 0);
|
|
isDefined: std_logic;
|
|
end record;
|
|
function to_stdlogicvector(snake : pos) return std_logic_vector;
|
|
function to_pos(input : std_logic_vector) return pos;
|
|
|
|
type color is record
|
|
R : STD_LOGIC_VECTOR (4 downto 0);
|
|
G : STD_LOGIC_VECTOR (5 downto 0);
|
|
B : STD_LOGIC_VECTOR (4 downto 0);
|
|
end record;
|
|
function to_color(input : std_logic_vector) return color;
|
|
end package;
|
|
|
|
package body types is
|
|
function to_stdlogicvector(snake : pos) return std_logic_vector is
|
|
--variable sortie : std_logic_vector(pos.X'length+pos.Y'length+pos.dirX'length+pos.dirY'length downto 0);
|
|
begin
|
|
return std_logic_vector(std_logic_vector(snake.X) & std_logic_vector(snake.Y) & std_logic_vector(snake.dirX) & std_logic_vector(snake.dirY) & snake.isDefined);
|
|
end to_stdlogicvector;
|
|
|
|
function to_pos(input : std_logic_vector) return pos is
|
|
variable sortie : pos;
|
|
variable offset : integer;
|
|
begin
|
|
--si on trouve une facon plus simple de deserialiser je suis preneur
|
|
offset := 0;
|
|
sortie.isDefined := input(0);
|
|
offset := offset+1;
|
|
sortie.dirY := signed(input(offset+pos.dirY'length-1 downto offset));
|
|
offset := offset+pos.dirY'length;
|
|
sortie.dirX := signed(input(offset+pos.dirX'length-1 downto offset));
|
|
offset := offset+pos.dirX'length;
|
|
sortie.Y := unsigned(input(offset+pos.Y'length-1 downto offset));
|
|
offset := offset+pos.Y'length;
|
|
sortie.X := unsigned(input(offset+pos.X'length-1 downto offset));
|
|
return sortie;
|
|
end to_pos;
|
|
|
|
function to_color(input : std_logic_vector) return color is
|
|
variable sortie : color;
|
|
begin
|
|
sortie.R := input(23 downto 19);
|
|
sortie.G := input(18 downto 13);
|
|
sortie.B := input(12 downto 8);
|
|
--sortie.A := input(7 downto 0);
|
|
return sortie;
|
|
end to_color;
|
|
end package body;
|