1 |
2 |
sandroamt |
--------------------------------------------------------------------------------
|
2 |
|
|
---- ----
|
3 |
|
|
---- This file is part of the yaVGA project ----
|
4 |
|
|
---- http://www.opencores.org/?do=project&who=yavga ----
|
5 |
|
|
---- ----
|
6 |
|
|
---- Description ----
|
7 |
|
|
---- Implementation of yaVGA IP core ----
|
8 |
|
|
---- ----
|
9 |
|
|
---- To Do: ----
|
10 |
|
|
---- ----
|
11 |
|
|
---- ----
|
12 |
|
|
---- Author(s): ----
|
13 |
|
|
---- Sandro Amato, sdroamt@netscape.net ----
|
14 |
|
|
---- ----
|
15 |
|
|
--------------------------------------------------------------------------------
|
16 |
|
|
---- ----
|
17 |
|
|
---- Copyright (c) 2009, Sandro Amato ----
|
18 |
|
|
---- All rights reserved. ----
|
19 |
|
|
---- ----
|
20 |
|
|
---- Redistribution and use in source and binary forms, with or without ----
|
21 |
|
|
---- modification, are permitted provided that the following conditions ----
|
22 |
|
|
---- are met: ----
|
23 |
|
|
---- ----
|
24 |
|
|
---- * Redistributions of source code must retain the above ----
|
25 |
|
|
---- copyright notice, this list of conditions and the ----
|
26 |
|
|
---- following disclaimer. ----
|
27 |
|
|
---- * Redistributions in binary form must reproduce the above ----
|
28 |
|
|
---- copyright notice, this list of conditions and the ----
|
29 |
|
|
---- following disclaimer in the documentation and/or other ----
|
30 |
|
|
---- materials provided with the distribution. ----
|
31 |
|
|
---- * Neither the name of SANDRO AMATO nor the names of its ----
|
32 |
|
|
---- contributors may be used to endorse or promote products ----
|
33 |
|
|
---- derived from this software without specific prior written ----
|
34 |
|
|
---- permission. ----
|
35 |
|
|
---- ----
|
36 |
|
|
---- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ----
|
37 |
|
|
---- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ----
|
38 |
|
|
---- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS ----
|
39 |
|
|
---- FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ----
|
40 |
|
|
---- COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, ----
|
41 |
|
|
---- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, ----
|
42 |
|
|
---- BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; ----
|
43 |
|
|
---- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ----
|
44 |
|
|
---- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT ----
|
45 |
|
|
---- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ----
|
46 |
|
|
---- ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ----
|
47 |
|
|
---- POSSIBILITY OF SUCH DAMAGE. ----
|
48 |
|
|
--------------------------------------------------------------------------------
|
49 |
|
|
|
50 |
|
|
library IEEE;
|
51 |
|
|
use IEEE.STD_LOGIC_1164.all;
|
52 |
|
|
use IEEE.STD_LOGIC_ARITH.all;
|
53 |
|
|
use IEEE.STD_LOGIC_UNSIGNED.all;
|
54 |
|
|
|
55 |
24 |
sandroamt |
use work.yavga_pkg.all;
|
56 |
|
|
|
57 |
2 |
sandroamt |
---- Uncomment the following library declaration if instantiating
|
58 |
|
|
---- any Xilinx primitives in this code.
|
59 |
|
|
--library UNISIM;
|
60 |
|
|
--use UNISIM.VComponents.all;
|
61 |
|
|
|
62 |
|
|
entity vga_ctrl is
|
63 |
|
|
-- generic (
|
64 |
|
|
-- g_H_SIZE : integer := 800; -- horizontal size of input image, MAX 800
|
65 |
|
|
-- g_V_SIZE : integer := 600 -- vertical size of input image, MAX 600
|
66 |
|
|
-- );
|
67 |
|
|
|
68 |
|
|
port (
|
69 |
|
|
i_clk : in std_logic; -- must be 50MHz
|
70 |
|
|
i_reset : in std_logic;
|
71 |
|
|
|
72 |
|
|
-- vga horizontal and vertical sync
|
73 |
|
|
o_h_sync : out std_logic;
|
74 |
|
|
o_v_sync : out std_logic;
|
75 |
|
|
|
76 |
|
|
-- horizontal and vertical sync enable (allow power saving on ?VESA? Monitors)
|
77 |
|
|
i_h_sync_en : in std_logic;
|
78 |
|
|
i_v_sync_en : in std_logic;
|
79 |
|
|
|
80 |
|
|
-- vga R G B signals (1 bit for each component (8 colors))
|
81 |
|
|
o_r : out std_logic;
|
82 |
|
|
o_g : out std_logic;
|
83 |
|
|
o_b : out std_logic;
|
84 |
|
|
|
85 |
|
|
-- chars RAM memory
|
86 |
24 |
sandroamt |
i_chr_addr : in std_logic_vector(c_CHR_ADDR_BUS_W - 1 downto 0);
|
87 |
|
|
i_chr_data : in std_logic_vector(c_CHR_DATA_BUS_W - 1 downto 0);
|
88 |
|
|
o_chr_data : out std_logic_vector(c_CHR_DATA_BUS_W - 1 downto 0);
|
89 |
2 |
sandroamt |
i_chr_clk : in std_logic;
|
90 |
|
|
i_chr_en : in std_logic;
|
91 |
28 |
sandroamt |
i_chr_we : in std_logic_vector(c_CHR_WE_BUS_W - 1 downto 0);
|
92 |
2 |
sandroamt |
i_chr_rst : in std_logic;
|
93 |
|
|
|
94 |
|
|
-- waveform RAM memory
|
95 |
24 |
sandroamt |
i_wav_d : in std_logic_vector(c_WAVFRM_DATA_BUS_W - 1 downto 0);
|
96 |
2 |
sandroamt |
i_wav_we : in std_logic;
|
97 |
28 |
sandroamt |
i_wav_clk : in std_logic;
|
98 |
24 |
sandroamt |
i_wav_addr : in std_logic_vector(c_WAVFRM_ADDR_BUS_W - 1 downto 0) --;
|
99 |
2 |
sandroamt |
--o_DOA : OUT std_logic_vector(15 downto 0)
|
100 |
|
|
);
|
101 |
|
|
end vga_ctrl;
|
102 |
|
|
|
103 |
|
|
-- vga timings used
|
104 |
|
|
-- 0 TOT
|
105 |
|
|
-- ...-----------------|=============== PERIOD ==============|--...
|
106 |
|
|
-- | |
|
107 |
|
|
-- ...__ ___________________________ _______...
|
108 |
|
|
-- \_________/ \_________/
|
109 |
|
|
--
|
110 |
|
|
-- | | | | | | |
|
111 |
|
|
-- | | | | | | |
|
112 |
|
|
-- ...--|----S----|-F--|=======D=======|==B===|====S====|=F==|--...
|
113 |
|
|
-- Y R I A Y R
|
114 |
|
|
-- N O S C N O
|
115 |
|
|
-- C N P K C N
|
116 |
|
|
-- T T L P T T
|
117 |
|
|
-- I P T O I P
|
118 |
|
|
-- M O I R M O
|
119 |
|
|
-- E R M C E R
|
120 |
|
|
-- C E H C
|
121 |
|
|
-- H H
|
122 |
|
|
-- | | | | | | |
|
123 |
|
|
-- ...|---------|----|===============|======|=========|====|--...
|
124 |
|
|
-- HPx: 120 56 800 63 120 56 px (h PERIOD = 1039 px)
|
125 |
|
|
-- VLn: 6 37 600 23 6 37 ln (v PERIOD = 666 ln)
|
126 |
|
|
--
|
127 |
|
|
-- and with 50Mhz dot clock (20ns dot time):
|
128 |
|
|
-- | | | | | | |
|
129 |
|
|
-- ...|---------|----|===============|======|=========|====|--...
|
130 |
|
|
--Htime: 2.4 1.12 16 1.26 2.4 1.12 usec (h PERIOD = 20.78 usec) Hfreq 48123.195 Hz
|
131 |
|
|
--Vtime: 124.68 768.86 12468 477.94 124.68 768.68 usec (v PERIOD = 13839.48 usec) Vfreq 72.257 Hz
|
132 |
|
|
|
133 |
|
|
architecture rtl of vga_ctrl is
|
134 |
|
|
|
135 |
|
|
--
|
136 |
28 |
sandroamt |
signal s_h_count : std_logic_vector(c_H_COUNT_W - 1 downto 0); -- horizontal pixel counter
|
137 |
|
|
signal s_v_count : std_logic_vector(c_V_COUNT_W - 1 downto 0); -- verticalal line counter
|
138 |
|
|
signal s_v_count_d_4 : std_logic_vector(3 downto 0); -- verticalal line counter mod 16 (char height)
|
139 |
2 |
sandroamt |
signal s_h_sync : std_logic; -- horizontal sync trigger
|
140 |
|
|
signal s_h_sync_pulse : std_logic; -- 1-clock pulse on sync trigger
|
141 |
|
|
|
142 |
|
|
--
|
143 |
|
|
-- signals for the charmaps Block RAM component...
|
144 |
28 |
sandroamt |
signal s_charmaps_en : std_logic;
|
145 |
24 |
sandroamt |
signal s_charmaps_ADDR : std_logic_vector (c_INTCHMAP_ADDR_BUS_W - 1 downto 0);
|
146 |
|
|
signal s_charmaps_DO : std_logic_vector (c_INTCHMAP_DATA_BUS_W - 1 downto 0);
|
147 |
2 |
sandroamt |
|
148 |
|
|
--
|
149 |
|
|
-- to manage the outside display region's blanking
|
150 |
|
|
signal s_display : std_logic;
|
151 |
|
|
--
|
152 |
|
|
|
153 |
|
|
--
|
154 |
23 |
sandroamt |
-- to manage the chars ram address and the ram ascii
|
155 |
24 |
sandroamt |
signal s_chars_ram_addr : std_logic_vector(c_INTCHR_ADDR_BUS_W - 1 downto 0);
|
156 |
|
|
signal s_chars_ascii : std_logic_vector(c_INTCHR_DATA_BUS_W - 1 downto 0);
|
157 |
28 |
sandroamt |
signal s_chars_EN_r : std_logic;
|
158 |
2 |
sandroamt |
|
159 |
23 |
sandroamt |
-- to manage the waveform ram address and data
|
160 |
24 |
sandroamt |
signal s_waveform_ADDRB : std_logic_vector (c_WAVFRM_ADDR_BUS_W - 1 downto 0);
|
161 |
|
|
signal s_waveform_DOB : std_logic_vector (c_WAVFRM_DATA_BUS_W - 1 downto 0);
|
162 |
2 |
sandroamt |
|
163 |
|
|
|
164 |
|
|
-- charmaps
|
165 |
|
|
-- |------| |-----------------|
|
166 |
|
|
-- | P | | D D D D D D D D |
|
167 |
|
|
-- |======| |=================|
|
168 |
|
|
-- | 8 | | 7 6 5 4 3 2 1 0 |
|
169 |
|
|
-- |======| |=================|
|
170 |
|
|
-- | Free | | Row char pixels |
|
171 |
|
|
-- |------| |-----------------|
|
172 |
|
|
--
|
173 |
|
|
component charmaps_rom
|
174 |
|
|
port(
|
175 |
28 |
sandroamt |
i_EN : in std_logic;
|
176 |
2 |
sandroamt |
i_clock : in std_logic;
|
177 |
24 |
sandroamt |
i_ADDR : in std_logic_vector(c_INTCHMAP_ADDR_BUS_W - 1 downto 0); -- 16 x ascii code (W=8 x H=16 pixel)
|
178 |
28 |
sandroamt |
o_DO : out std_logic_vector(c_INTCHMAP_DATA_BUS_W - 1 downto 0) -- 8 bit char pixel
|
179 |
2 |
sandroamt |
);
|
180 |
|
|
end component;
|
181 |
|
|
|
182 |
|
|
|
183 |
|
|
|
184 |
|
|
-- wave form or video-line memory
|
185 |
|
|
-- |------| |-------------------------------------------|
|
186 |
|
|
-- | P P | | D D D | D D D | D D D D D D D D D D |
|
187 |
|
|
-- |======| |===========================================|
|
188 |
|
|
-- |17 16 | | 15 14 13 | 12 11 10 | 9 8 7 6 5 4 3 2 1 0 |
|
189 |
|
|
-- |======| |===========================================|
|
190 |
|
|
-- | Free | | Reserv. | R G B | vert. pos. |
|
191 |
|
|
-- |------| |-------------------------------------------|
|
192 |
|
|
--
|
193 |
|
|
component waveform_ram
|
194 |
|
|
port(
|
195 |
28 |
sandroamt |
i_DIA : in std_logic_vector(c_WAVFRM_DATA_BUS_W - 1 downto 0);
|
196 |
2 |
sandroamt |
i_WEA : in std_logic;
|
197 |
|
|
i_clockA : in std_logic;
|
198 |
28 |
sandroamt |
i_ADDRA : in std_logic_vector(c_WAVFRM_ADDR_BUS_W - 1 downto 0);
|
199 |
2 |
sandroamt |
--o_DOA : OUT std_logic_vector(15 downto 0);
|
200 |
|
|
--
|
201 |
28 |
sandroamt |
i_DIB : in std_logic_vector(c_WAVFRM_DATA_BUS_W - 1 downto 0);
|
202 |
2 |
sandroamt |
i_WEB : in std_logic;
|
203 |
|
|
i_clockB : in std_logic;
|
204 |
28 |
sandroamt |
i_ADDRB : in std_logic_vector(c_WAVFRM_ADDR_BUS_W - 1 downto 0);
|
205 |
|
|
o_DOB : out std_logic_vector(c_WAVFRM_DATA_BUS_W - 1 downto 0)
|
206 |
2 |
sandroamt |
);
|
207 |
|
|
end component;
|
208 |
|
|
|
209 |
|
|
component chars_RAM
|
210 |
|
|
port(
|
211 |
|
|
i_clock_rw : in std_logic;
|
212 |
|
|
i_EN_rw : in std_logic;
|
213 |
28 |
sandroamt |
i_WE_rw : in std_logic_vector(c_CHR_WE_BUS_W - 1 downto 0);
|
214 |
24 |
sandroamt |
i_ADDR_rw : in std_logic_vector(c_CHR_ADDR_BUS_W - 1 downto 0);
|
215 |
|
|
i_DI_rw : in std_logic_vector(c_CHR_DATA_BUS_W - 1 downto 0);
|
216 |
|
|
o_DI_rw : out std_logic_vector(c_CHR_DATA_BUS_W - 1 downto 0);
|
217 |
2 |
sandroamt |
i_SSR : in std_logic;
|
218 |
|
|
i_clock_r : in std_logic;
|
219 |
23 |
sandroamt |
i_EN_r : in std_logic;
|
220 |
24 |
sandroamt |
i_ADDR_r : in std_logic_vector(c_INTCHR_ADDR_BUS_W - 1 downto 0);
|
221 |
|
|
o_DO_r : out std_logic_vector(c_INTCHR_DATA_BUS_W - 1 downto 0)
|
222 |
2 |
sandroamt |
);
|
223 |
|
|
end component;
|
224 |
|
|
|
225 |
|
|
|
226 |
|
|
attribute U_SET : string;
|
227 |
|
|
attribute U_SET of "u0_chars_RAM" : label is "u0_chars_RAM_uset";
|
228 |
|
|
attribute U_SET of "u1_charmaps_rom" : label is "u1_charmaps_rom_uset";
|
229 |
|
|
attribute U_SET of "u2_waveform_ram" : label is "u2_waveform_ram_uset";
|
230 |
|
|
|
231 |
23 |
sandroamt |
-- to read some configuration params from the char ram
|
232 |
28 |
sandroamt |
signal s_config_time : std_logic;
|
233 |
23 |
sandroamt |
--
|
234 |
|
|
-- to manage the background and cursor colors
|
235 |
28 |
sandroamt |
signal s_cursor_color : std_logic_vector(2 downto 0) := "000";
|
236 |
|
|
signal s_bg_color : std_logic_vector(2 downto 0) := "000";
|
237 |
23 |
sandroamt |
--
|
238 |
|
|
-- to manage the cursor position
|
239 |
28 |
sandroamt |
signal s_cursor_x : std_logic_vector(c_H_COUNT_W - 1 downto 0);
|
240 |
|
|
signal s_cursor_y : std_logic_vector(c_V_COUNT_W - 1 downto 0);
|
241 |
23 |
sandroamt |
|
242 |
29 |
sandroamt |
function f_is_cursor_pixel(
|
243 |
|
|
s_h, s_v, s_cur_x, s_cur_y : std_logic_vector)
|
244 |
|
|
return boolean is
|
245 |
|
|
begin
|
246 |
|
|
return ((s_h = s_cur_x) or (s_v = s_cur_y));
|
247 |
|
|
end f_is_cursor_pixel;
|
248 |
|
|
|
249 |
|
|
function f_is_grid_pixel(
|
250 |
|
|
s_h, s_v : std_logic_vector)
|
251 |
|
|
return boolean is
|
252 |
|
|
begin
|
253 |
|
|
return (
|
254 |
|
|
(s_h(c_GRID_BIT downto 0) = c_GRID_SIZE(c_GRID_BIT downto 0)) or
|
255 |
|
|
(s_v(c_GRID_BIT downto 0) = c_GRID_SIZE(c_GRID_BIT downto 0))
|
256 |
|
|
);
|
257 |
|
|
end f_is_grid_pixel;
|
258 |
|
|
|
259 |
|
|
function f_is_waveform_pixel(
|
260 |
|
|
s_v, s_wav, s_wav_prev : std_logic_vector)
|
261 |
|
|
return boolean is
|
262 |
|
|
begin
|
263 |
|
|
return (
|
264 |
|
|
((s_v >= s_wav) and (s_v <= s_wav_prev)) or
|
265 |
|
|
((s_v <= s_wav) and (s_v >= s_wav_prev))
|
266 |
|
|
);
|
267 |
|
|
end f_is_waveform_pixel;
|
268 |
|
|
|
269 |
2 |
sandroamt |
begin
|
270 |
23 |
sandroamt |
-- read config params from ram...
|
271 |
|
|
p_config : process(i_clk)
|
272 |
|
|
begin
|
273 |
|
|
if rising_edge(i_clk) then
|
274 |
28 |
sandroamt |
case s_chars_ram_addr is
|
275 |
|
|
when c_CFG_BG_CUR_COLOR_ADDR => -- bg and curs color are on the same byte byte
|
276 |
|
|
s_config_time <= '1';
|
277 |
|
|
s_cursor_color <= s_chars_ascii(2 downto 0);
|
278 |
|
|
s_bg_color <= s_chars_ascii(5 downto 3);
|
279 |
|
|
when c_CFG_CURS_XY1 => -- xy coords spans on three bytes
|
280 |
|
|
s_config_time <= '1';
|
281 |
|
|
s_cursor_x(10 downto 6) <= s_chars_ascii(4 downto 0);
|
282 |
|
|
when c_CFG_CURS_XY2 => -- xy coords spans on three bytes
|
283 |
|
|
s_config_time <= '1';
|
284 |
|
|
s_cursor_x(5 downto 0) <= s_chars_ascii(7 downto 2);
|
285 |
|
|
s_cursor_y(9 downto 8) <= s_chars_ascii(1 downto 0);
|
286 |
|
|
when c_CFG_CURS_XY3 => -- xy coords spans on three bytes
|
287 |
|
|
s_config_time <= '1';
|
288 |
|
|
s_cursor_y(7 downto 0) <= s_chars_ascii(7 downto 0);
|
289 |
|
|
when others =>
|
290 |
|
|
s_config_time <= '0';
|
291 |
|
|
end case;
|
292 |
23 |
sandroamt |
end if;
|
293 |
|
|
end process;
|
294 |
2 |
sandroamt |
|
295 |
23 |
sandroamt |
-- enable the ram both
|
296 |
|
|
-- - during the display time
|
297 |
|
|
-- - to read configuration params
|
298 |
|
|
s_chars_EN_r <= s_display or s_config_time;
|
299 |
|
|
|
300 |
|
|
-- modify the chars_ram address
|
301 |
2 |
sandroamt |
s_chars_ram_addr <= s_v_count(9 downto 4) & s_h_count(9 downto 3);
|
302 |
|
|
u0_chars_RAM : chars_RAM port map(
|
303 |
|
|
i_clock_rw => i_chr_clk,
|
304 |
|
|
i_EN_rw => i_chr_en,
|
305 |
|
|
i_WE_rw => i_chr_we,
|
306 |
|
|
i_ADDR_rw => i_chr_addr,
|
307 |
|
|
i_DI_rw => i_chr_data,
|
308 |
|
|
o_DI_rw => o_chr_data,
|
309 |
|
|
i_SSR => i_chr_rst,
|
310 |
23 |
sandroamt |
i_clock_r => not i_clk,
|
311 |
|
|
i_EN_r => s_chars_EN_r,
|
312 |
2 |
sandroamt |
i_ADDR_r => s_chars_ram_addr,
|
313 |
|
|
o_DO_r => s_chars_ascii
|
314 |
|
|
);
|
315 |
|
|
|
316 |
|
|
|
317 |
24 |
sandroamt |
-- modify the charmaps address (each 16 s_v_count - chars are 16 pixel tall)
|
318 |
|
|
-- v----- ascii code ------v v-- vert px mod 16 --v (chars are 16 pixel tall)
|
319 |
23 |
sandroamt |
--s_charmaps_ADDR <= (s_chars_ascii(6 downto 0) & s_v_count(3 downto 0));
|
320 |
|
|
s_charmaps_ADDR <= (s_chars_ascii(6 downto 0) & s_v_count_d_4);
|
321 |
28 |
sandroamt |
s_charmaps_en <=
|
322 |
|
|
'1' when s_h_count(2 downto 0) = "111" -- each 8 h_count (chars are 8 pixel wide)
|
323 |
23 |
sandroamt |
else '0';
|
324 |
2 |
sandroamt |
|
325 |
|
|
u1_charmaps_rom : charmaps_rom port map(
|
326 |
23 |
sandroamt |
i_en => s_charmaps_en,
|
327 |
|
|
i_clock => not i_clk,
|
328 |
2 |
sandroamt |
i_ADDR => s_charmaps_ADDR,
|
329 |
|
|
o_DO => s_charmaps_DO
|
330 |
|
|
);
|
331 |
|
|
|
332 |
|
|
|
333 |
23 |
sandroamt |
-- modify the waveform address
|
334 |
|
|
s_waveform_ADDRB <= s_h_count(9 downto 0);
|
335 |
|
|
|
336 |
2 |
sandroamt |
u2_waveform_ram : waveform_ram port map(
|
337 |
|
|
i_DIA => i_wav_d,
|
338 |
|
|
i_WEA => i_wav_we,
|
339 |
23 |
sandroamt |
i_clockA => i_wav_clk,
|
340 |
2 |
sandroamt |
i_ADDRA => i_wav_addr,
|
341 |
|
|
--o_DOA => o_DOA,
|
342 |
|
|
--
|
343 |
|
|
i_DIB => "1111111111111111",
|
344 |
|
|
i_WEB => '0',
|
345 |
23 |
sandroamt |
i_clockB => not i_clk,
|
346 |
|
|
i_ADDRB => s_waveform_ADDRB,
|
347 |
2 |
sandroamt |
o_DOB => s_waveform_DOB
|
348 |
|
|
);
|
349 |
|
|
|
350 |
23 |
sandroamt |
-- generate a single clock pulse on hsync falling
|
351 |
2 |
sandroamt |
p_pulse_on_hsync_falling : process(i_clk)
|
352 |
|
|
variable v_h_sync1 : std_logic;
|
353 |
|
|
begin
|
354 |
|
|
if rising_edge(i_clk) then
|
355 |
|
|
s_h_sync_pulse <= not s_h_sync and v_h_sync1;
|
356 |
|
|
v_h_sync1 := s_h_sync;
|
357 |
|
|
end if;
|
358 |
|
|
end process;
|
359 |
|
|
|
360 |
|
|
|
361 |
|
|
-- control the reset, increment and overflow of the horizontal pixel count
|
362 |
|
|
p_H_PX_COUNT : process(i_clk) --, i_reset)
|
363 |
|
|
begin
|
364 |
|
|
if rising_edge(i_clk) then
|
365 |
|
|
if i_reset = '1' or s_h_count = c_H_PERIODpx then -- sync reset
|
366 |
|
|
s_h_count <= (others => '0');
|
367 |
|
|
else
|
368 |
|
|
s_h_count <= s_h_count + 1;
|
369 |
|
|
end if;
|
370 |
|
|
end if;
|
371 |
|
|
end process;
|
372 |
|
|
|
373 |
|
|
|
374 |
23 |
sandroamt |
-- control the reset, increment and overflow of the vertical pixel count
|
375 |
2 |
sandroamt |
p_V_LN_COUNT : process(i_clk)
|
376 |
|
|
begin
|
377 |
|
|
if rising_edge(i_clk) then
|
378 |
|
|
if i_reset = '1' or s_v_count = c_V_PERIODln then -- sync reset
|
379 |
28 |
sandroamt |
s_v_count <= (others => '0');
|
380 |
|
|
s_v_count_d_4 <= s_v_count(3 downto 0);
|
381 |
2 |
sandroamt |
elsif s_h_sync_pulse = '1' then
|
382 |
28 |
sandroamt |
s_v_count <= s_v_count + 1;
|
383 |
|
|
s_v_count_d_4 <= s_v_count(3 downto 0);
|
384 |
2 |
sandroamt |
end if;
|
385 |
|
|
end if;
|
386 |
|
|
end process;
|
387 |
|
|
|
388 |
|
|
-- set the horizontal sync high time and low time according to the constants
|
389 |
|
|
p_MGM_H_SYNC : process(i_clk) --, i_reset)
|
390 |
|
|
begin
|
391 |
|
|
if rising_edge(i_clk) then
|
392 |
|
|
if (s_h_count = c_H_DISPLAYpx + c_H_BACKPORCHpx) then
|
393 |
|
|
s_h_sync <= '0';
|
394 |
|
|
elsif (s_h_count = c_H_PERIODpx - c_H_FRONTPORCHpx) then
|
395 |
|
|
s_h_sync <= '1';
|
396 |
|
|
end if;
|
397 |
|
|
end if;
|
398 |
|
|
end process;
|
399 |
|
|
o_h_sync <= s_h_sync and i_h_sync_en;
|
400 |
|
|
|
401 |
|
|
|
402 |
23 |
sandroamt |
-- set the vertical sync high time and low time according to the constants
|
403 |
2 |
sandroamt |
p_MGM_V_SYNC : process(i_clk) --, i_reset)
|
404 |
|
|
begin
|
405 |
|
|
--if falling_edge(i_clk) then
|
406 |
|
|
if rising_edge(i_clk) then
|
407 |
|
|
if i_v_sync_en = '0' or
|
408 |
|
|
(s_v_count = (c_V_DISPLAYln + c_V_BACKPORCHln)) then
|
409 |
|
|
o_v_sync <= '0';
|
410 |
|
|
elsif (s_v_count = (c_V_PERIODln - c_V_FRONTPORCHln)) then --and (s_h_sync_pulse = '1') then
|
411 |
|
|
o_v_sync <= '1';
|
412 |
|
|
end if;
|
413 |
|
|
end if;
|
414 |
|
|
end process;
|
415 |
|
|
|
416 |
23 |
sandroamt |
|
417 |
2 |
sandroamt |
-- asserts the blaking signal (active low)
|
418 |
|
|
p_MGM_BLANK : process (i_clk) --, i_reset)
|
419 |
|
|
begin
|
420 |
|
|
if rising_edge(i_clk) then
|
421 |
|
|
-- if we are outside the visible range on the screen then tell the RAMDAC to blank
|
422 |
|
|
-- in this section by putting s_display low
|
423 |
|
|
if not (s_h_count < c_H_DISPLAYpx and s_v_count < c_V_DISPLAYln) then
|
424 |
|
|
s_display <= '0';
|
425 |
|
|
else
|
426 |
|
|
s_display <= '1';
|
427 |
|
|
end if;
|
428 |
|
|
end if;
|
429 |
|
|
end process;
|
430 |
|
|
|
431 |
|
|
|
432 |
23 |
sandroamt |
-- generates the r g b signals showing chars, grid and "cross cursor"
|
433 |
|
|
p_MGM_RGB : process (i_clk)
|
434 |
2 |
sandroamt |
variable v_previous_pixel : std_logic_vector(9 downto 0) := "0100101100";
|
435 |
|
|
begin
|
436 |
|
|
if rising_edge(i_clk) then -- not async reset
|
437 |
|
|
if i_reset = '1' then -- sync reset
|
438 |
|
|
o_r <= '0';
|
439 |
|
|
o_g <= '0';
|
440 |
|
|
o_b <= '0';
|
441 |
|
|
else
|
442 |
|
|
if s_display = '1' then -- display zone
|
443 |
|
|
if (
|
444 |
29 |
sandroamt |
f_is_cursor_pixel(s_h_count, s_v_count, s_cursor_x, s_cursor_y) or
|
445 |
|
|
f_is_grid_pixel(s_h_count, s_v_count)
|
446 |
|
|
) and (s_v_count(9) = '0') -- < 512
|
447 |
2 |
sandroamt |
then -- draw the cursor and/or WaveForm Grid references
|
448 |
23 |
sandroamt |
o_r <= s_cursor_color(2);
|
449 |
|
|
o_g <= s_cursor_color(1);
|
450 |
|
|
o_b <= s_cursor_color(0);
|
451 |
2 |
sandroamt |
elsif
|
452 |
29 |
sandroamt |
f_is_waveform_pixel(s_v_count, s_waveform_DOB(c_V_COUNT_W - 1 downto 0), v_previous_pixel)
|
453 |
2 |
sandroamt |
then -- draw the waveform pixel...
|
454 |
|
|
o_r <= s_waveform_DOB(12) or s_waveform_DOB(15); -- the "or" is only
|
455 |
|
|
o_g <= s_waveform_DOB(11) or s_waveform_DOB(14); -- to not warning
|
456 |
|
|
o_b <= s_waveform_DOB(10) or s_waveform_DOB(13); -- unused signals
|
457 |
|
|
else -- draw the background and charmaps
|
458 |
|
|
case (s_h_count(2 downto 0)) is
|
459 |
23 |
sandroamt |
when "000" => o_g <= s_charmaps_DO(7) xor s_bg_color(1);
|
460 |
|
|
when "001" => o_g <= s_charmaps_DO(6) xor s_bg_color(1);
|
461 |
|
|
when "010" => o_g <= s_charmaps_DO(5) xor s_bg_color(1);
|
462 |
|
|
when "011" => o_g <= s_charmaps_DO(4) xor s_bg_color(1);
|
463 |
|
|
when "100" => o_g <= s_charmaps_DO(3) xor s_bg_color(1);
|
464 |
|
|
when "101" => o_g <= s_charmaps_DO(2) xor s_bg_color(1);
|
465 |
|
|
when "110" => o_g <= s_charmaps_DO(1) xor s_bg_color(1);
|
466 |
|
|
when "111" => o_g <= s_charmaps_DO(0) xor s_bg_color(1);
|
467 |
2 |
sandroamt |
when others => o_g <= 'X';
|
468 |
|
|
end case;
|
469 |
23 |
sandroamt |
|
470 |
|
|
o_r <= s_bg_color(2);
|
471 |
|
|
--o_g <= s_bg_color(1);
|
472 |
|
|
o_b <= s_bg_color(0);
|
473 |
2 |
sandroamt |
end if;
|
474 |
|
|
else -- blank zone
|
475 |
|
|
-- the blanking zone
|
476 |
|
|
o_r <= '0';
|
477 |
|
|
o_g <= '0';
|
478 |
|
|
o_b <= '0';
|
479 |
|
|
end if; -- if s_display
|
480 |
|
|
v_previous_pixel := s_waveform_DOB(9 downto 0);
|
481 |
|
|
end if; -- if i_reset
|
482 |
29 |
sandroamt |
end if; -- if rising_edge(i_clk)
|
483 |
2 |
sandroamt |
end process;
|
484 |
|
|
|
485 |
|
|
end rtl;
|