$[border.style=solid,width=1,radius=6 $[border.color=0000,width=12 @jcm@wafrn.jcm.re asked:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity my_code is
generic(
WIDTH : integer := 640;
HEIGHT : integer := 480;
CONSOLE_COLUMNS : integer := WIDTH / 8;
CONSOLE_ROWS : integer := HEIGHT / 8
);
port(
clk : in std_logic;
rst : in std_logic;
px : in integer range 0 to WIDTH - 1;
py : in integer range 0 to HEIGHT - 1;
hsync : in std_logic;
vsync : in std_logic;
col : in integer range 0 to CONSOLE_COLUMNS - 1;
row : in integer range 0 to CONSOLE_ROWS - 1;
char : out integer range 0 to 127 := 0;
foreground_color : out std_logic_vector(23 downto 0) := (others => '0');
background_color : out std_logic_vector(23 downto 0) := (others => '1');
uart_data : out std_logic_vector(7 downto 0) := (others => '0');
uart_ready : in std_logic;
uart_valid : out std_logic := '0'
);
end my_code;
architecture rtl of my_code is
constant IMAGE_WIDTH : integer := 117;
constant IMAGE_HEIGHT : integer := 52;
type image_type is array (0 to IMAGE_HEIGHT-1) of std_logic_vector(0 to IMAGE_WIDTH-1);
constant image : image_type := (
"000000000111111111111111111111111111111111111111111111000000000000000000011111111111111111111111111111111100000000000",
"000000000111111111111111111111111111111111111111111111000000000000000000111111111111111111111111111111111111100000000",
"000000000111111111111111111111111111111111111111111111000000000000000001111111111111111111111111111111111111111000000",
"000000000111111111111111111111111111111111111111111111100000000000000011111111111111111111111111111111111111111110000",
"000000001111111111111111111111111111111111111111111111100000000000000011111111111111111111111111111111111111111111000",
"000000001111111111111111111111111111111111111111111111100000000000000111111111111111111111111111111111111111111111100",
"000000001111111111111111111111111111111111111111111111110000000000001111111111111111111111111111111111111111111111110",
"000000001111111111110000000111111111111111111111111111110000000000011111111111111111111111110000000111111111111111111",
"000000011111111111110000000000111111111111111111111111110000000000011111111111111111111111110000000000111111111111111",
"000000011111111111110000000000011111111111111111111111111000000000111111111111111111111111110000000000011111111111111",
"000000011111111111100000000000001111111111111111111111111000000001111111111111011111111111100000000000001111111111111",
"000000011111111111100000000000000111111111111011111111111000000011111111111110011111111111100000000000000111111111111",
"000000111111111111100000000000000111111111111011111111111100000111111111111100111111111111100000000000000111111111111",
"000000111111111111100000000000000111111111111011111111111100000111111111111000111111111111100000000000000111111111111",
"000000111111111111000000000000001111111111111001111111111100001111111111110000111111111111100000000000001111111111111",
"000000111111111111000000000000001111111111111001111111111110011111111111110000111111111111000000000000001111111111111",
"000001111111111111000000000000001111111111110001111111111110111111111111100000111111111111000000000000001111111111111",
"000001111111111111000000000000011111111111110000111111111110111111111111000001111111111111000000000000011111111111110",
"000001111111111111000000000000111111111111110000111111111111111111111110000001111111111111000000000000111111111111110",
"000001111111111110000000000001111111111111100000111111111111111111111100000001111111111110000000000001111111111111100",
"000001111111111110000000000111111111111111000000011111111111111111111000000001111111111110000000000111111111111111000",
"000011111111111110000000111111111111111110000000011111111111111111110000000011111111111110000000111111111111111110000",
"000011111111111111111111111111111111111100000000011111111111111111100000000011111111111111111111111111111111111100000",
"000011111111111111111111111111111111111000000000001111111111111111100000000011111111111111111111111111111111111000000",
"000011111111111111111111111111111111110000000000001111111111111111000000000011111111111111111111111111111111110000000",
"000111111111111111111111111111111111000000000000000111111111111110000000000111111111111111111111111111111111000000000",
"000111111111111111111111111111111100000000000000000111111111111100000000000111111111111111111111111111111100000000000",
"000111111111111111111111111111100000000000000000000111111111111000000000000111111111111111111111111111100000000000000",
"000111111111111111111111111100000000000000000000000011111111110000000000000111111111111111111111111100000000000000000",
"000111111111111111111100000000000000000000000000000011111111100000000000000111111111111111111100000000000000000000000",
"000000000000000000000000000000000000000000000000000011111111100000000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000001111111000000000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000001111110000000000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000001111100000000000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000111000000000000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000110000000000000000000000000000000000000000000000000000000000000",
"000000000000000000000000000001111111111111111111111111111111111111111111111111111000000000000000000000000000000000000",
"000000000000000000011111111111111111111111111111111111111111111111111111111111111111111111100000000000000000000000000",
"000000000000111111111111111111111111111111111111111111111111111111111111111111111111111111111111110000000000000000000",
"000000011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100000000000000",
"000011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110000000000",
"011111111111111111111110011111001111111001111111000000011111111100000011111111100000001111111111111111111111100000000",
"111111111111111111111110011111001111111001111111001111001111111100111111111111001111100111111111111111111111110000000",
"111111111111111111111111001110011111111001111111001111100111111100111111111110011111110011111111111111111111111000000",
"111111111111111111111111101100111111111001111111001111100111111100000011111110011111110011111111111111111111111000000",
"111111111111111111111111100101111111111001111111001111100111111100111111111110011111110011111111111111111111110000000",
"011111111111111111111111110001111111111001111111001111001111111100111111111111001111100111111111111111111111100000000",
"000011111111111111111111111011111111111001111111000000011111111100000011111111100000001111111111111111111110000000000",
"000000011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100000000000000",
"000000000000111111111111111111111111111111111111111111111111111111111111111111111111111111111111110000000000000000000",
"000000000000000000011111111111111111111111111111111111111111111111111111111111111111111111110000000000000000000000000",
"000000000000000000000000000001111111111111111111111111111111111111111111111111111100000000000000000000000000000000000"
);
constant SPEED : integer := 8;
signal position_x : integer range -SPEED to WIDTH + SPEED := 0;
signal position_y : integer range -SPEED to HEIGHT + SPEED := 0;
signal random_bit : std_logic := '0';
signal color : std_logic_vector(23 downto 0) := x"FFFFFF";
signal trans_color : std_logic_vector(23 downto 0) := x"FFFFFF";
component OSCG is
generic (
DIV : integer := 128
);
port (
OSC : out std_logic
);
end component;
type rgb_key_array_t is array (0 to 4) of std_logic_vector(23 downto 0);
constant rgb_key_array : rgb_key_array_t := (x"5bcffa", x"f5abb9", x"ffffff", x"f5abb9", x"5bcffa");
begin
char <= 0;
background_color <= trans_color when image((py - position_y)/2)((px - position_x)/2) = '1' and
px >= position_x and px < position_x + IMAGE_WIDTH2 and
py >= position_y and py < position_y + IMAGE_HEIGHT2
else (not trans_color);
trans_color <= rgb_key_array((py / (HEIGHT / 5)) mod 5);
foreground_color <= (others => '1');
rng : OSCG port map (
OSC => random_bit
);
process(clk)
variable old_vsync : std_logic := '0';
variable speed_x : integer range -SPEED to SPEED := SPEED;
variable speed_y : integer range -SPEED to SPEED := SPEED;
begin
if rising_edge(clk) then
if vsync = '0' and old_vsync = '1' then
if position_x + speed_x + IMAGE_WIDTH2 >= WIDTH then
speed_x := -SPEED;
position_x <= WIDTH - IMAGE_WIDTH2 - 1;
color <= color(22 downto 0) & random_bit;
elsif position_x + speed_x < 0 then
speed_x := SPEED;
position_x <= 0;
color <= color(22 downto 0) & random_bit;
else
position_x <= position_x + speed_x;
end if;
if position_y + speed_y + IMAGE_HEIGHT2 >= HEIGHT then
speed_y := -SPEED;
position_y <= HEIGHT - IMAGE_HEIGHT2 - 1;
color <= color(22 downto 0) & random_bit;
elsif position_y + speed_y < 0 then
speed_y := SPEED;
position_y <= 0;
color <= color(22 downto 0) & random_bit;
else
position_y <= position_y + speed_y;
end if;
end if;
old_vsync := vsync;
end if;
end process;
end architecture;]]
Success!
UART Output
UtilizationCellUsedAvailableUsageDCCA2563.6%EHXPLLL1250.0%MULT18X18D1283.6%TRELLIS_COMB1253242885.2%TRELLIS_FF152242880.6%TRELLIS_IO111975.6%
TimingClockAchievedConstraint$glbnet$clkp36.02 MHz25 MHz$glbnet$clkt361.01 MHz250 MHz
Code
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity my_code is
generic(
WIDTH : integer := 640;
HEIGHT : integer := 480;
CONSOLE_COLUMNS : integer := WIDTH / 8;
CONSOLE_ROWS : integer := HEIGHT / 8
);
port(
clk : in std_logic;
rst : in std_logic;
px : in integer range 0 to WIDTH - 1;
py : in integer range 0 to HEIGHT - 1;
hsync : in std_logic;
vsync : in std_logic;
col : in integer range 0 to CONSOLE_COLUMNS - 1;
row : in integer range 0 to CONSOLE_ROWS - 1;
char : out integer range 0 to 127 := 0;
foreground_color : out std_logic_vector(23 downto 0) := (others => '0');
background_color : out std_logic_vector(23 downto 0) := (others => '1');
uart_data : out std_logic_vector(7 downto 0) := (others => '0');
uart_ready : in std_logic;
uart_valid : out std_logic := '0'
);
end my_code;
architecture rtl of my_code is
constant IMAGE_WIDTH : integer := 117;
constant IMAGE_HEIGHT : integer := 52;
type image_type is array (0 to IMAGE_HEIGHT-1) of std_logic_vector(0 to IMAGE_WIDTH-1);
constant image : image_type := (
"000000000111111111111111111111111111111111111111111111000000000000000000011111111111111111111111111111111100000000000",
"000000000111111111111111111111111111111111111111111111000000000000000000111111111111111111111111111111111111100000000",
"000000000111111111111111111111111111111111111111111111000000000000000001111111111111111111111111111111111111111000000",
"000000000111111111111111111111111111111111111111111111100000000000000011111111111111111111111111111111111111111110000",
"000000001111111111111111111111111111111111111111111111100000000000000011111111111111111111111111111111111111111111000",
"000000001111111111111111111111111111111111111111111111100000000000000111111111111111111111111111111111111111111111100",
"000000001111111111111111111111111111111111111111111111110000000000001111111111111111111111111111111111111111111111110",
"000000001111111111110000000111111111111111111111111111110000000000011111111111111111111111110000000111111111111111111",
"000000011111111111110000000000111111111111111111111111110000000000011111111111111111111111110000000000111111111111111",
"000000011111111111110000000000011111111111111111111111111000000000111111111111111111111111110000000000011111111111111",
"000000011111111111100000000000001111111111111111111111111000000001111111111111011111111111100000000000001111111111111",
"000000011111111111100000000000000111111111111011111111111000000011111111111110011111111111100000000000000111111111111",
"000000111111111111100000000000000111111111111011111111111100000111111111111100111111111111100000000000000111111111111",
"000000111111111111100000000000000111111111111011111111111100000111111111111000111111111111100000000000000111111111111",
"000000111111111111000000000000001111111111111001111111111100001111111111110000111111111111100000000000001111111111111",
"000000111111111111000000000000001111111111111001111111111110011111111111110000111111111111000000000000001111111111111",
"000001111111111111000000000000001111111111110001111111111110111111111111100000111111111111000000000000001111111111111",
"000001111111111111000000000000011111111111110000111111111110111111111111000001111111111111000000000000011111111111110",
"000001111111111111000000000000111111111111110000111111111111111111111110000001111111111111000000000000111111111111110",
"000001111111111110000000000001111111111111100000111111111111111111111100000001111111111110000000000001111111111111100",
"000001111111111110000000000111111111111111000000011111111111111111111000000001111111111110000000000111111111111111000",
"000011111111111110000000111111111111111110000000011111111111111111110000000011111111111110000000111111111111111110000",
"000011111111111111111111111111111111111100000000011111111111111111100000000011111111111111111111111111111111111100000",
"000011111111111111111111111111111111111000000000001111111111111111100000000011111111111111111111111111111111111000000",
"000011111111111111111111111111111111110000000000001111111111111111000000000011111111111111111111111111111111110000000",
"000111111111111111111111111111111111000000000000000111111111111110000000000111111111111111111111111111111111000000000",
"000111111111111111111111111111111100000000000000000111111111111100000000000111111111111111111111111111111100000000000",
"000111111111111111111111111111100000000000000000000111111111111000000000000111111111111111111111111111100000000000000",
"000111111111111111111111111100000000000000000000000011111111110000000000000111111111111111111111111100000000000000000",
"000111111111111111111100000000000000000000000000000011111111100000000000000111111111111111111100000000000000000000000",
"000000000000000000000000000000000000000000000000000011111111100000000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000001111111000000000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000001111110000000000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000001111100000000000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000111000000000000000000000000000000000000000000000000000000000000",
"000000000000000000000000000000000000000000000000000000110000000000000000000000000000000000000000000000000000000000000",
"000000000000000000000000000001111111111111111111111111111111111111111111111111111000000000000000000000000000000000000",
"000000000000000000011111111111111111111111111111111111111111111111111111111111111111111111100000000000000000000000000",
"000000000000111111111111111111111111111111111111111111111111111111111111111111111111111111111111110000000000000000000",
"000000011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100000000000000",
"000011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110000000000",
"011111111111111111111110011111001111111001111111000000011111111100000011111111100000001111111111111111111111100000000",
"111111111111111111111110011111001111111001111111001111001111111100111111111111001111100111111111111111111111110000000",
"111111111111111111111111001110011111111001111111001111100111111100111111111110011111110011111111111111111111111000000",
"111111111111111111111111101100111111111001111111001111100111111100000011111110011111110011111111111111111111111000000",
"111111111111111111111111100101111111111001111111001111100111111100111111111110011111110011111111111111111111110000000",
"011111111111111111111111110001111111111001111111001111001111111100111111111111001111100111111111111111111111100000000",
"000011111111111111111111111011111111111001111111000000011111111100000011111111100000001111111111111111111110000000000",
"000000011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100000000000000",
"000000000000111111111111111111111111111111111111111111111111111111111111111111111111111111111111110000000000000000000",
"000000000000000000011111111111111111111111111111111111111111111111111111111111111111111111110000000000000000000000000",
"000000000000000000000000000001111111111111111111111111111111111111111111111111111100000000000000000000000000000000000"
);
constant SPEED : integer := 8;
signal position_x : integer range -SPEED to WIDTH + SPEED := 0;
signal position_y : integer range -SPEED to HEIGHT + SPEED := 0;
signal random_bit : std_logic := '0';
signal color : std_logic_vector(23 downto 0) := x"FFFFFF";
signal trans_color : std_logic_vector(23 downto 0) := x"FFFFFF";
component OSCG is
generic (
DIV : integer := 128
);
port (
OSC : out std_logic
);
end component;
type rgb_key_array_t is array (0 to 4) of std_logic_vector(23 downto 0);
constant rgb_key_array : rgb_key_array_t := (x"5bcffa", x"f5abb9", x"ffffff", x"f5abb9", x"5bcffa");
begin
char <= 0;
background_color <= trans_color when image((py - position_y)/2)((px - position_x)/2) = '1' and
px >= position_x and px < position_x + IMAGE_WIDTH*2 and
py >= position_y and py < position_y + IMAGE_HEIGHT*2
else (not trans_color);
trans_color <= rgb_key_array((py / (HEIGHT / 5)) mod 5);
foreground_color <= (others => '1');
rng : OSCG port map (
OSC => random_bit
);
process(clk)
variable old_vsync : std_logic := '0';
variable speed_x : integer range -SPEED to SPEED := SPEED;
variable speed_y : integer range -SPEED to SPEED := SPEED;
begin
if rising_edge(clk) then
if vsync = '0' and old_vsync = '1' then
if position_x + speed_x + IMAGE_WIDTH*2 >= WIDTH then
speed_x := -SPEED;
position_x <= WIDTH - IMAGE_WIDTH*2 - 1;
color <= color(22 downto 0) & random_bit;
elsif position_x + speed_x < 0 then
speed_x := SPEED;
position_x <= 0;
color <= color(22 downto 0) & random_bit;
else
position_x <= position_x + speed_x;
end if;
if position_y + speed_y + IMAGE_HEIGHT*2 >= HEIGHT then
speed_y := -SPEED;
position_y <= HEIGHT - IMAGE_HEIGHT*2 - 1;
color <= color(22 downto 0) & random_bit;
elsif position_y + speed_y < 0 then
speed_y := SPEED;
position_y <= 0;
color <= color(22 downto 0) & random_bit;
else
position_y <= position_y + speed_y;
end if;
end if;
old_vsync := vsync;
end if;
end process;
end architecture;
#FPGA # Icepi Zero #HDL #VHDL