-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.vhd
187 lines (155 loc) · 4.38 KB
/
main.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
library UNISIM;
use UNISIM.VComponents.all;
entity main is
port (
papilio_clk : in STD_LOGIC;
hsync : out STD_LOGIC;
vsync : out STD_LOGIC;
red : out STD_LOGIC_VECTOR(3 downto 0);
green : out STD_LOGIC_VECTOR(3 downto 0);
blue : out STD_LOGIC_VECTOR(3 downto 0));
end main;
architecture Behavioral of main is
component clock is
port (
papilio_clk : in std_logic;
gpu_clk : out std_logic;
vga_clk : out std_logic);
end component;
component gpu is
port (
matrix : in STD_LOGIC_VECTOR ((16*18-1) downto 0);
p_we : in STD_LOGIC;
p_i : in STD_LOGIC_VECTOR ( 8 downto 0);
p_x : in STD_LOGIC_VECTOR (17 downto 0);
p_y : in STD_LOGIC_VECTOR (17 downto 0);
p_z : in STD_LOGIC_VECTOR (17 downto 0);
t_we : in STD_LOGIC;
t_i : in STD_LOGIC_VECTOR ( 8 downto 0);
t_a : in STD_LOGIC_VECTOR ( 8 downto 0);
t_b : in STD_LOGIC_VECTOR ( 8 downto 0);
t_c : in STD_LOGIC_VECTOR ( 8 downto 0);
t_d : in STD_LOGIC_VECTOR ( 8 downto 0);
gpu_clk : in STD_LOGIC;
reset : in STD_LOGIC;
line_start : in STD_LOGIC;
y : in STD_LOGIC_VECTOR ( 9 downto 0);
pixel_clk : in STD_LOGIC;
x : in STD_LOGIC_VECTOR ( 9 downto 0);
color : out STD_LOGIC_VECTOR ( 8 downto 0));
end component;
-- component test_proj_matrix is
-- port ( coefs : out STD_LOGIC_VECTOR ((16*18-1) downto 0));
-- end component;
component proj_matrices is
port (
clk : in STD_LOGIC;
vbl : in STD_LOGIC;
coefs : out STD_LOGIC_VECTOR ((16*18-1) downto 0));
end component;
signal gpu_clk : std_logic;
signal vga_clk : std_logic;
signal matrix : STD_LOGIC_VECTOR((16*18-1) downto 0);
signal reset : STD_LOGIC := '1';
signal line_start : STD_LOGIC;
signal y : unsigned(9 downto 0) := "0000000000";
signal p_i : STD_LOGIC_VECTOR ( 8 downto 0);
signal p_x : STD_LOGIC_VECTOR (17 downto 0);
signal p_y : STD_LOGIC_VECTOR (17 downto 0);
signal p_z : STD_LOGIC_VECTOR (17 downto 0);
signal t_i : STD_LOGIC_VECTOR ( 8 downto 0);
signal t_a : STD_LOGIC_VECTOR ( 8 downto 0);
signal t_b : STD_LOGIC_VECTOR ( 8 downto 0);
signal t_c : STD_LOGIC_VECTOR ( 8 downto 0);
signal t_d : STD_LOGIC_VECTOR ( 8 downto 0);
signal vcount : unsigned(9 downto 0) := "0111011111"; -- 479
signal hcount : unsigned(9 downto 0) := (others=>'0');
signal ram_o : std_logic_vector(8 downto 0);
begin
clock_inst: clock
port map (
papilio_clk => papilio_clk,
gpu_clk => gpu_clk,
vga_clk => vga_clk);
gpu_inst: gpu
port map (
matrix => matrix,
p_we => '0',
p_i => p_i,
p_x => p_x,
p_y => p_y,
p_z => p_z,
t_we => '0',
t_i => t_i,
t_a => t_a,
t_b => t_b,
t_c => t_c,
t_d => t_d,
gpu_clk => gpu_clk,
reset => reset,
line_start => line_start,
y => std_logic_vector(y),
pixel_clk => vga_clk,
x => "0"&std_logic_vector(hcount(9 downto 1)),
color => ram_o);
-- test_proj_matrix_inst : test_proj_matrix
-- port map (coefs => matrix);
proj_matrices_inst : proj_matrices
port map (
clk => vga_clk,
vbl => reset,
coefs => matrix);
process (vga_clk)
begin
if rising_edge(vga_clk) then
if hcount=799 then
hcount <= (others=>'0');
if vcount=524 then
vcount <= (others=>'0');
else
vcount <= vcount+1;
end if;
else
hcount <= hcount+1;
end if;
end if;
end process;
-- visible 640 clk
-- front porch 16
-- sync 96
-- back porch 48
hsync <= '0' when hcount>=640+16 and hcount<640+16+96 else '1';
vsync <= '0' when vcount>=480+10 and vcount<480+10+2 else '1';
process (vga_clk)
begin
if rising_edge(vga_clk) then
if hcount=799 and vcount(0)='1' then
if vcount<479 then
y <= y+1;
reset <= '0';
line_start <= '1';
elsif vcount=479 then
y <= "1110000000";
reset <= '1';
line_start <= '0';
else
y <= "1110000000";
reset <= '0';
line_start <= '0';
end if;
else
reset <= '0';
line_start <= '0';
end if;
end if;
end process;
red(3 downto 1) <= ram_o(8 downto 6) when hcount<640 and vcount<480 else (others=>'0');
green(3 downto 1) <= ram_o(5 downto 3) when hcount<640 and vcount<480 else (others=>'0');
blue(3 downto 1) <= ram_o(2 downto 0) when hcount<640 and vcount<480 else (others=>'0');
red(0) <= '0';
green(0) <= '0';
blue(0) <= '0';
end Behavioral;