1 |
6 |
tantos |
--
|
2 |
|
|
-- File: vga_core_v2.vhd
|
3 |
|
|
--
|
4 |
|
|
-- (c) Copyright Andras Tantos <andras_tantos@yahoo.com> 2001/04/26
|
5 |
|
|
-- This code is distributed under the terms and conditions of the GNU General Public Lince.
|
6 |
|
|
--
|
7 |
|
|
-- vga_core_v2: A WB compatible monitor controller core with version2 features.
|
8 |
|
|
|
9 |
|
|
library IEEE;
|
10 |
|
|
use IEEE.std_logic_1164.all;
|
11 |
|
|
|
12 |
|
|
library wb_vga;
|
13 |
|
|
use wb_vga.all;
|
14 |
|
|
|
15 |
|
|
library wb_tk;
|
16 |
|
|
use wb_tk.all;
|
17 |
|
|
use wb_tk.technology.all;
|
18 |
|
|
|
19 |
|
|
entity vga_core_v2 is
|
20 |
|
|
generic (
|
21 |
|
|
v_dat_width: positive := 16;
|
22 |
|
|
v_adr_width : positive := 20;
|
23 |
|
|
cpu_dat_width: positive := 16;
|
24 |
|
|
cpu_adr_width: positive := 11;
|
25 |
|
|
fifo_size: positive := 256;
|
26 |
|
|
accel_size: positive := 9;
|
27 |
|
|
v_pal_size: positive := 8;
|
28 |
|
|
v_pal_width: positive := 16
|
29 |
|
|
);
|
30 |
|
|
port (
|
31 |
|
|
clk_i: in std_logic;
|
32 |
|
|
clk_en: in std_logic := '1';
|
33 |
|
|
rst_i: in std_logic := '0';
|
34 |
|
|
|
35 |
|
|
-- CPU bus interface
|
36 |
|
|
dat_i: in std_logic_vector (cpu_dat_width-1 downto 0);
|
37 |
|
|
dat_oi: in std_logic_vector (cpu_dat_width-1 downto 0);
|
38 |
|
|
dat_o: out std_logic_vector (cpu_dat_width-1 downto 0);
|
39 |
|
|
cyc_i: in std_logic;
|
40 |
|
|
ack_o: out std_logic;
|
41 |
|
|
ack_oi: in std_logic;
|
42 |
|
|
err_o: out std_logic;
|
43 |
|
|
err_oi: in std_logic;
|
44 |
|
|
we_i: in std_logic;
|
45 |
|
|
accel_stb_i: in std_logic;
|
46 |
|
|
pal_stb_i: in std_logic;
|
47 |
|
|
reg_stb_i: in std_logic;
|
48 |
|
|
adr_i: in std_logic_vector (cpu_adr_width-1 downto 0);
|
49 |
|
|
sel_i: in std_logic_vector ((cpu_dat_width/8)-1 downto 0) := (others => '1');
|
50 |
|
|
|
51 |
|
|
-- video memory interface
|
52 |
|
|
v_adr_o: out std_logic_vector (v_adr_width-1 downto 0);
|
53 |
|
|
v_sel_o: out std_logic_vector ((v_dat_width/8)-1 downto 0);
|
54 |
|
|
v_dat_i: in std_logic_vector (v_dat_width-1 downto 0);
|
55 |
|
|
v_dat_o: out std_logic_vector (v_dat_width-1 downto 0);
|
56 |
|
|
v_cyc_o: out std_logic;
|
57 |
|
|
v_ack_i: in std_logic;
|
58 |
|
|
v_we_o: out std_logic;
|
59 |
|
|
v_stb_o: out std_logic;
|
60 |
|
|
|
61 |
|
|
-- sync blank and video signal outputs
|
62 |
|
|
h_sync: out std_logic;
|
63 |
|
|
h_blank: out std_logic;
|
64 |
|
|
v_sync: out std_logic;
|
65 |
|
|
v_blank: out std_logic;
|
66 |
|
|
h_tc: out std_logic;
|
67 |
|
|
v_tc: out std_logic;
|
68 |
|
|
blank: out std_logic;
|
69 |
|
|
video_out: out std_logic_vector (v_pal_size-1 downto 0); -- video output binary signal (unused bits are forced to 0)
|
70 |
|
|
true_color_out: out std_logic_vector (v_pal_width-1 downto 0) -- true-color video output
|
71 |
|
|
);
|
72 |
|
|
end vga_core_v2;
|
73 |
|
|
|
74 |
|
|
architecture vga_core_v2 of vga_core_v2 is
|
75 |
|
|
component vga_core
|
76 |
|
|
generic (
|
77 |
|
|
v_dat_width: positive := v_dat_width;
|
78 |
|
|
v_adr_width : positive := v_adr_width;
|
79 |
|
|
cpu_dat_width: positive := cpu_dat_width;
|
80 |
|
|
cpu_adr_width: positive := v_adr_width-bus_resize2adr_bits(cpu_dat_width,v_dat_width);
|
81 |
|
|
reg_adr_width: positive := cpu_adr_width;
|
82 |
|
|
fifo_size: positive := fifo_size
|
83 |
|
|
);
|
84 |
|
|
port (
|
85 |
|
|
clk_i: in std_logic;
|
86 |
|
|
clk_en: in std_logic := '1';
|
87 |
|
|
rst_i: in std_logic := '0';
|
88 |
|
|
|
89 |
|
|
-- CPU memory bus interface
|
90 |
|
|
vmem_cyc_i: in std_logic;
|
91 |
|
|
vmem_we_i: in std_logic;
|
92 |
|
|
vmem_stb_i: in std_logic; -- selects video memory
|
93 |
|
|
vmem_ack_o: out std_logic;
|
94 |
|
|
vmem_ack_oi: in std_logic;
|
95 |
|
|
vmem_adr_i: in std_logic_vector (cpu_adr_width-1 downto 0);
|
96 |
|
|
vmem_sel_i: in std_logic_vector ((cpu_dat_width/8)-1 downto 0) := (others => '1');
|
97 |
|
|
vmem_dat_i: in std_logic_vector (cpu_dat_width-1 downto 0);
|
98 |
|
|
vmem_dat_oi: in std_logic_vector (cpu_dat_width-1 downto 0);
|
99 |
|
|
vmem_dat_o: out std_logic_vector (cpu_dat_width-1 downto 0);
|
100 |
|
|
|
101 |
|
|
-- CPU register bus interface
|
102 |
|
|
reg_cyc_i: in std_logic;
|
103 |
|
|
reg_we_i: in std_logic;
|
104 |
|
|
reg_stb_i: in std_logic; -- selects configuration registers
|
105 |
|
|
reg_ack_o: out std_logic;
|
106 |
|
|
reg_ack_oi: in std_logic;
|
107 |
|
|
reg_adr_i: in std_logic_vector (reg_adr_width-1 downto 0);
|
108 |
|
|
reg_sel_i: in std_logic_vector ((cpu_dat_width/8)-1 downto 0) := (others => '1');
|
109 |
|
|
reg_dat_i: in std_logic_vector (cpu_dat_width-1 downto 0);
|
110 |
|
|
reg_dat_oi: in std_logic_vector (cpu_dat_width-1 downto 0);
|
111 |
|
|
reg_dat_o: out std_logic_vector (cpu_dat_width-1 downto 0);
|
112 |
|
|
|
113 |
|
|
-- video memory interface
|
114 |
|
|
v_adr_o: out std_logic_vector (v_adr_width-1 downto 0);
|
115 |
|
|
v_sel_o: out std_logic_vector ((v_dat_width/8)-1 downto 0);
|
116 |
|
|
v_dat_i: in std_logic_vector (v_dat_width-1 downto 0);
|
117 |
|
|
v_dat_o: out std_logic_vector (v_dat_width-1 downto 0);
|
118 |
|
|
v_cyc_o: out std_logic;
|
119 |
|
|
v_ack_i: in std_logic;
|
120 |
|
|
v_we_o: out std_logic;
|
121 |
|
|
v_stb_o: out std_logic;
|
122 |
|
|
|
123 |
|
|
-- sync blank and video signal outputs
|
124 |
|
|
h_sync: out std_logic;
|
125 |
|
|
h_blank: out std_logic;
|
126 |
|
|
v_sync: out std_logic;
|
127 |
|
|
v_blank: out std_logic;
|
128 |
|
|
h_tc: out std_logic;
|
129 |
|
|
v_tc: out std_logic;
|
130 |
|
|
blank: out std_logic;
|
131 |
|
|
video_out: out std_logic_vector (7 downto 0) -- video output binary signal (unused bits are forced to 0)
|
132 |
|
|
);
|
133 |
|
|
end component;
|
134 |
|
|
|
135 |
|
|
component accel is
|
136 |
|
|
generic (
|
137 |
|
|
accel_size: positive := accel_size;
|
138 |
|
|
video_addr_width: positive := v_adr_width-bus_resize2adr_bits(cpu_dat_width,v_dat_width);
|
139 |
|
|
data_width: positive := cpu_dat_width
|
140 |
|
|
);
|
141 |
|
|
port (
|
142 |
|
|
clk_i: in std_logic;
|
143 |
|
|
rst_i: in std_logic := '0';
|
144 |
|
|
|
145 |
|
|
-- Slave interface to the CPU side
|
146 |
|
|
we_i: in std_logic;
|
147 |
|
|
cyc_i: in std_logic;
|
148 |
|
|
cur_stb_i: in std_logic;
|
149 |
|
|
ext_stb_i: in std_logic;
|
150 |
|
|
acc_stb_i: in std_logic;
|
151 |
|
|
mem_stb_i: in std_logic;
|
152 |
|
|
|
153 |
|
|
sel_i: in std_logic_vector ((data_width/8)-1 downto 0) := (others => '1');
|
154 |
|
|
adr_i: in std_logic_vector(accel_size-1 downto 0);
|
155 |
|
|
dat_i: in std_logic_vector(data_width-1 downto 0);
|
156 |
|
|
dat_o: out std_logic_vector(data_width-1 downto 0);
|
157 |
|
|
dat_oi: in std_logic_vector(data_width-1 downto 0);
|
158 |
|
|
|
159 |
|
|
ack_o: out std_logic;
|
160 |
|
|
ack_oi: in std_logic;
|
161 |
|
|
|
162 |
|
|
-- Master interface to the video memory side.
|
163 |
|
|
v_we_o: out std_logic;
|
164 |
|
|
v_cyc_o: out std_logic;
|
165 |
|
|
v_stb_o: out std_logic;
|
166 |
|
|
|
167 |
|
|
v_adr_o: out std_logic_vector (video_addr_width-1 downto 0);
|
168 |
|
|
v_sel_o: out std_logic_vector ((data_width/8)-1 downto 0);
|
169 |
|
|
v_dat_o: out std_logic_vector (data_width-1 downto 0);
|
170 |
|
|
v_dat_i: in std_logic_vector (data_width-1 downto 0);
|
171 |
|
|
|
172 |
|
|
v_ack_i: in std_logic
|
173 |
|
|
);
|
174 |
|
|
end component;
|
175 |
|
|
|
176 |
|
|
component wb_pal_ram is
|
177 |
|
|
generic (
|
178 |
|
|
cpu_dat_width: positive := cpu_dat_width;
|
179 |
|
|
cpu_adr_width: positive := v_pal_size-bus_resize2adr_bits(cpu_dat_width,v_dat_width);
|
180 |
|
|
v_dat_width: positive := v_pal_width;
|
181 |
|
|
v_adr_width: positive := v_pal_size
|
182 |
|
|
);
|
183 |
|
|
port (
|
184 |
|
|
-- Wishbone interface to CPU (write-only support)
|
185 |
|
|
clk_i: in std_logic;
|
186 |
|
|
rst_i: in std_logic := '0';
|
187 |
|
|
adr_i: in std_logic_vector (cpu_adr_width-1 downto 0);
|
188 |
|
|
dat_i: in std_logic_vector (cpu_dat_width-1 downto 0);
|
189 |
|
|
dat_oi: in std_logic_vector (cpu_dat_width-1 downto 0) := (others => '-');
|
190 |
|
|
dat_o: out std_logic_vector (cpu_dat_width-1 downto 0);
|
191 |
|
|
cyc_i: in std_logic;
|
192 |
|
|
ack_o: out std_logic;
|
193 |
|
|
ack_oi: in std_logic := '-';
|
194 |
|
|
err_o: out std_logic;
|
195 |
|
|
err_oi: in std_logic := '-';
|
196 |
|
|
we_i: in std_logic;
|
197 |
|
|
stb_i: in std_logic;
|
198 |
|
|
-- Interface to the video output
|
199 |
|
|
blank: in std_logic;
|
200 |
|
|
v_dat_i: in std_logic_vector(v_adr_width-1 downto 0);
|
201 |
|
|
v_dat_o: out std_logic_vector(v_dat_width-1 downto 0)
|
202 |
|
|
);
|
203 |
|
|
end component;
|
204 |
|
|
|
205 |
|
|
-- register select signals
|
206 |
|
|
signal vga_reg_stb: std_logic;
|
207 |
|
|
signal cur_stb: std_logic;
|
208 |
|
|
signal ext_stb: std_logic;
|
209 |
|
|
-- accelerator select signals
|
210 |
|
|
signal acc_stb: std_logic;
|
211 |
|
|
signal mem_stb: std_logic;
|
212 |
|
|
|
213 |
|
|
signal vga_dat_o: std_logic_vector(cpu_dat_width-1 downto 0);
|
214 |
|
|
signal vga_ack_o: std_logic;
|
215 |
|
|
|
216 |
|
|
signal vreg_dat_o: std_logic_vector(cpu_dat_width-1 downto 0);
|
217 |
|
|
signal vreg_ack_o: std_logic;
|
218 |
|
|
signal accel_dat_o: std_logic_vector(cpu_dat_width-1 downto 0);
|
219 |
|
|
signal accel_ack_o: std_logic;
|
220 |
|
|
signal pal_dat_o: std_logic_vector(cpu_dat_width-1 downto 0);
|
221 |
|
|
signal pal_ack_o: std_logic;
|
222 |
|
|
|
223 |
|
|
signal i_video_out: std_logic_vector (v_pal_size-1 downto 0);
|
224 |
|
|
signal i_blank: std_logic;
|
225 |
|
|
signal vmem_stb: std_logic;
|
226 |
|
|
|
227 |
|
|
signal vm_cyc: std_logic;
|
228 |
|
|
signal vm_we: std_logic;
|
229 |
|
|
signal vm_stb: std_logic;
|
230 |
|
|
signal vm_ack: std_logic;
|
231 |
|
|
signal vm_adr: std_logic_vector(v_adr_width-bus_resize2adr_bits(cpu_dat_width,v_dat_width)-1 downto 0);
|
232 |
|
|
signal vm_sel: std_logic_vector(cpu_dat_width/8-1 downto 0);
|
233 |
|
|
signal vm_dat_i: std_logic_vector(cpu_dat_width-1 downto 0);
|
234 |
|
|
signal vm_dat_o: std_logic_vector(cpu_dat_width-1 downto 0);
|
235 |
|
|
|
236 |
|
|
constant vga_reg_size: integer := size2bits((32*8)/cpu_dat_width)-1;
|
237 |
|
|
begin
|
238 |
|
|
core : vga_core
|
239 |
|
|
port map (
|
240 |
|
|
clk_i => clk_i,
|
241 |
|
|
clk_en => clk_en,
|
242 |
|
|
rst_i => rst_i,
|
243 |
|
|
-- CPU bus interface
|
244 |
|
|
vmem_cyc_i => vm_cyc,
|
245 |
|
|
vmem_we_i => vm_we,
|
246 |
|
|
vmem_stb_i => vm_stb,
|
247 |
|
|
vmem_ack_o => vm_ack,
|
248 |
|
|
vmem_ack_oi => '1',
|
249 |
|
|
vmem_adr_i => vm_adr,
|
250 |
|
|
vmem_sel_i => vm_sel,
|
251 |
|
|
vmem_dat_i => vm_dat_i,
|
252 |
|
|
vmem_dat_oi => (cpu_dat_width-1 downto 0 => '-'),
|
253 |
|
|
vmem_dat_o => vm_dat_o,
|
254 |
|
|
|
255 |
|
|
-- CPU register bus interface
|
256 |
|
|
reg_cyc_i => cyc_i,
|
257 |
|
|
reg_we_i => we_i,
|
258 |
|
|
reg_stb_i => vga_reg_stb,
|
259 |
|
|
reg_ack_o => vreg_ack_o,
|
260 |
|
|
reg_ack_oi => ack_oi,
|
261 |
|
|
reg_adr_i => adr_i,
|
262 |
|
|
reg_sel_i => sel_i,
|
263 |
|
|
reg_dat_i => dat_i,
|
264 |
|
|
reg_dat_oi => dat_oi,
|
265 |
|
|
reg_dat_o => vreg_dat_o,
|
266 |
|
|
|
267 |
|
|
|
268 |
|
|
-- video memory interface
|
269 |
|
|
v_adr_o => v_adr_o,
|
270 |
|
|
v_sel_o => v_sel_o,
|
271 |
|
|
v_dat_i => v_dat_i,
|
272 |
|
|
v_dat_o => v_dat_o,
|
273 |
|
|
v_cyc_o => v_cyc_o,
|
274 |
|
|
v_ack_i => v_ack_i,
|
275 |
|
|
v_we_o => v_we_o,
|
276 |
|
|
v_stb_o => v_stb_o,
|
277 |
|
|
|
278 |
|
|
h_sync => h_sync,
|
279 |
|
|
h_blank => h_blank,
|
280 |
|
|
v_sync => v_sync,
|
281 |
|
|
v_blank => v_blank,
|
282 |
|
|
h_tc => h_tc,
|
283 |
|
|
v_tc => v_tc,
|
284 |
|
|
blank => i_blank,
|
285 |
|
|
video_out => i_video_out
|
286 |
|
|
);
|
287 |
|
|
|
288 |
|
|
acc: accel
|
289 |
|
|
port map (
|
290 |
|
|
clk_i => clk_i,
|
291 |
|
|
rst_i => rst_i,
|
292 |
|
|
|
293 |
|
|
-- Slave interface to the CPU side
|
294 |
|
|
we_i => we_i,
|
295 |
|
|
cyc_i => cyc_i,
|
296 |
|
|
cur_stb_i => cur_stb,
|
297 |
|
|
ext_stb_i => ext_stb,
|
298 |
|
|
acc_stb_i => acc_stb,
|
299 |
|
|
mem_stb_i => mem_stb,
|
300 |
|
|
|
301 |
|
|
sel_i => sel_i,
|
302 |
|
|
adr_i => adr_i(accel_size-1 downto 0),
|
303 |
|
|
dat_i => dat_i,
|
304 |
|
|
dat_o => accel_dat_o,
|
305 |
|
|
dat_oi => vreg_dat_o,
|
306 |
|
|
|
307 |
|
|
ack_o => accel_ack_o,
|
308 |
|
|
ack_oi => vreg_ack_o,
|
309 |
|
|
|
310 |
|
|
-- Master interface to the video memory side.
|
311 |
|
|
v_we_o => vm_we,
|
312 |
|
|
v_cyc_o => vm_cyc,
|
313 |
|
|
v_stb_o => vm_stb,
|
314 |
|
|
|
315 |
|
|
v_adr_o => vm_adr,
|
316 |
|
|
v_sel_o => vm_sel,
|
317 |
|
|
v_dat_o => vm_dat_i,
|
318 |
|
|
v_dat_i => vm_dat_o,
|
319 |
|
|
|
320 |
|
|
v_ack_i => vm_ack
|
321 |
|
|
);
|
322 |
|
|
|
323 |
|
|
palette: wb_pal_ram
|
324 |
|
|
port map (
|
325 |
|
|
clk_i => clk_i,
|
326 |
|
|
rst_i => rst_i,
|
327 |
|
|
adr_i => adr_i(v_pal_size-bus_resize2adr_bits(cpu_dat_width,v_dat_width)-1 downto 0),
|
328 |
|
|
dat_i => dat_i,
|
329 |
|
|
dat_oi => accel_dat_o,
|
330 |
|
|
dat_o => dat_o,
|
331 |
|
|
cyc_i => cyc_i,
|
332 |
|
|
ack_o => ack_o,
|
333 |
|
|
ack_oi => accel_ack_o,
|
334 |
|
|
err_o => err_o,
|
335 |
|
|
err_oi => err_oi,
|
336 |
|
|
we_i => we_i,
|
337 |
|
|
stb_i => pal_stb_i,
|
338 |
|
|
-- Interface to the video output
|
339 |
|
|
blank => i_blank,
|
340 |
|
|
v_dat_i => i_video_out,
|
341 |
|
|
v_dat_o => true_color_out
|
342 |
|
|
);
|
343 |
|
|
video_out <= i_video_out;
|
344 |
|
|
blank <= i_blank;
|
345 |
|
|
|
346 |
|
|
reg_addr_decoder: process is
|
347 |
|
|
begin
|
348 |
|
|
wait on reg_stb_i, adr_i;
|
349 |
|
|
|
350 |
|
|
vga_reg_stb <= '0';
|
351 |
|
|
cur_stb <= '0';
|
352 |
|
|
ext_stb <= '0';
|
353 |
|
|
|
354 |
|
|
if (reg_stb_i = '1') then
|
355 |
|
|
case (adr_i(vga_reg_size)) is
|
356 |
|
|
when '0' => vga_reg_stb <= '1';
|
357 |
|
|
when '1' =>
|
358 |
|
|
if (adr_i(vga_reg_size-2) = '1') then
|
359 |
|
|
case (adr_i(vga_reg_size-3)) is
|
360 |
|
|
when '0' => cur_stb <= '1';
|
361 |
|
|
when '1' => ext_stb <= '1';
|
362 |
|
|
when others =>
|
363 |
|
|
end case;
|
364 |
|
|
end if;
|
365 |
|
|
when others =>
|
366 |
|
|
end case;
|
367 |
|
|
end if;
|
368 |
|
|
end process;
|
369 |
|
|
|
370 |
|
|
accel_addr_decoder: process is
|
371 |
|
|
begin
|
372 |
|
|
wait on accel_stb_i, adr_i;
|
373 |
|
|
|
374 |
|
|
acc_stb <= '0';
|
375 |
|
|
mem_stb <= '0';
|
376 |
|
|
|
377 |
|
|
if (accel_stb_i = '1') then
|
378 |
|
|
case (adr_i(accel_size)) is
|
379 |
|
|
when '0' => acc_stb <= '1';
|
380 |
|
|
when '1' => mem_stb <= '1';
|
381 |
|
|
when others =>
|
382 |
|
|
end case;
|
383 |
|
|
end if;
|
384 |
|
|
end process;
|
385 |
|
|
|
386 |
|
|
end vga_core_v2;
|