forked from aybaras/VGA-based-screensaver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
color_generator.vhd
89 lines (66 loc) · 2.06 KB
/
color_generator.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use IEEE.NUMERIC_STD.ALL;
entity color_generator is
port (
Clk : in STD_LOGIC;
Enable : in STD_LOGIC;
x : in integer range 0 to 639;
y : in integer range 0 to 479;
Video_enable : in STD_LOGIC;
color : in STD_LOGIC_VECTOR(7 downto 0);
red : out STD_LOGIC_VECTOR(2 downto 0) := "000";
green : out STD_LOGIC_VECTOR(2 downto 0) := "000";
blue : out STD_LOGIC_VECTOR(1 downto 0) := "00"
);
end color_generator;
architecture Behavioral of color_generator is
-- constant screen_width : integer := 640;
-- constant screen_height : integer := 480;
-- constant ball_width : integer := 60;
-- constant ball_height : integer := 60;
begin
counter_process : process(Enable)
variable count, square_pos : integer range 0 to 307199 := 0;
variable count2 : integer range 0 to 416799 := 0;
variable flag : boolean := true;
begin
if rising_edge(Clk) then
if Enable = '1' then
if count2 = 416799 then
count := 0;
count2 := 0;
end if;
if video_enable = '1' then
flag := true;
square_pos := x + y * 640;
-- Display the square by pushing a colorful pixel.
for h in 0 to 40 loop
if square_pos <= count and count <= square_pos + 40 then
red <= color(7) & color(3) & color(1);
green <= color(0) & color(5) & color(4);
blue <= color(6) & color(2);
flag := false;
exit;
end if;
square_pos := square_pos + 640;
end loop;
-- If flag is true, then push a black pixel.
if flag then
red <= (others => '0');
green <= (others => '0');
blue <= (others => '0');
end if;
count := count + 1;
else
red <= (others => '0');
green <= (others => '0');
blue <= (others => '0');
end if;
count2 := count2 + 1;
end if;
end if;
end process counter_process;
end Behavioral;