-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvga.vhd
127 lines (106 loc) · 2.73 KB
/
vga.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 00:21:58 09/12/2018
-- Design Name:
-- Module Name: vga - 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;
use IEEE.STD_LOGIC_UNSIGNED.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 primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity vga is
Port ( clk : in STD_LOGIC;
color_sel : in STD_LOGIC_VECTOR(2 downto 0);
vxpos : out integer;
vypos : out integer;
vsync : out STD_LOGIC;
hsync : out STD_LOGIC;
vblue : out STD_LOGIC;
vgreen : out STD_LOGIC;
vred : out STD_LOGIC);
end vga;
architecture Behavioral of vga is
signal s_vsync : std_logic;
signal s_vcount : std_logic_vector(19 downto 0);
signal s_hsync : std_logic;
signal s_hcount : std_logic_vector(10 downto 0);
signal s_blue : std_logic;
signal s_green : std_logic;
signal s_red : std_logic;
signal s_color : std_logic_vector(2 downto 0);
signal s_enable : std_logic;
signal x_pos : integer range 0 to 800;
signal y_pos : integer range 0 to 600;
begin
process(clk)
begin
if clk'event and clk = '1' then
s_hcount <= s_hcount + 1;
if s_hcount >= x"58" and s_hcount < x"378" then
s_enable <= '1';
x_pos <= x_pos + 1;
else
s_enable <= '0';
end if;
if s_hcount >= x"3a0" then
s_hsync <= '1';
end if;
if s_hcount >= x"41f" then
s_hsync <= '0';
s_hcount <= (others => '0');
x_pos <= 0;
end if;
if s_enable = '1' and y_pos < x"258" and x_pos < x"320" then
s_color <= color_sel;
else
s_color <= "000";
end if;
s_red <= s_color(2);
s_green <= s_color(1);
s_blue <= s_color(0);
end if;
end process;
process(s_hsync)
begin
if s_hsync'event and s_hsync = '1' then
s_vcount <= s_vcount + 1;
if s_vcount >= x"17" and s_vcount < x"26f" then
y_pos <= y_pos + 1;
end if;
if s_vcount >= x"26f" then
s_vsync <= '1';
end if;
if s_vcount >= x"273" then
s_vsync <= '0';
s_vcount <= (others => '0');
y_pos <= 0;
end if;
end if;
end process;
vsync <= s_vsync;
hsync <= s_hsync;
vblue <= s_blue;
vgreen <= s_green;
vred <= s_red;
vxpos <= x_pos;
vypos <= y_pos;
end Behavioral;