OpenCores
URL https://opencores.org/ocsvn/tcp_ip_core_w_dhcp/tcp_ip_core_w_dhcp/trunk

Subversion Repositories tcp_ip_core_w_dhcp

[/] [tcp_ip_core_w_dhcp/] [trunk/] [vga80x40.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 craighaywo
-- Hi Emacs, this is -*- mode: vhdl; -*-
2
----------------------------------------------------------------------------------------------------
3
--
4
-- Monocrome Text Mode Video Controller VHDL Macro
5
-- 80x40 characters. Pixel resolution is 640x480/60Hz
6
-- 
7
-- Copyright (c) 2007 Javier Valcarce Garca, javier.valcarce@gmail.com
8
-- $Id$
9
--
10
----------------------------------------------------------------------------------------------------
11
-- This program is free software: you can redistribute it and/or modify
12
-- it under the terms of the GNU Lesser General Public License as published by
13
-- the Free Software Foundation, either version 3 of the License, or
14
-- (at your option) any later version.
15
 
16
-- This program is distributed in the hope that it will be useful,
17
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
18
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
-- GNU Lesser General Public License for more details.
20
--
21
-- You should have received a copy of the GNU Lesser General Public License
22
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
----------------------------------------------------------------------------------------------------
24
 
25
library ieee;
26
use ieee.std_logic_1164.all;
27
use ieee.numeric_std.all;
28
 
29
entity vga80x40 is
30
  port (
31
    reset       : in  std_logic;
32
    clk25MHz    : in  std_logic;
33
    TEXT_A      : out std_logic_vector(11 downto 0); -- text buffer
34
    TEXT_D      : in  std_logic_vector(07 downto 0);
35
         FONT_A      : out std_logic_vector(11 downto 0); -- font buffer
36
         FONT_D      : in  std_logic_vector(07 downto 0);
37
         --
38
         ocrx        : in  std_logic_vector(07 downto 0); -- OUTPUT regs
39
    ocry        : in  std_logic_vector(07 downto 0);
40
    octl        : in  std_logic_vector(07 downto 0);
41
    --
42
    R           : out std_logic;
43
    G           : out std_logic;
44
    B           : out std_logic;
45
    hsync       : out std_logic;
46
    vsync       : out std_logic
47
    );
48
end vga80x40;
49
 
50
 
51
 
52
architecture rtl of vga80x40 is
53
 
54
  signal R_int : std_logic;
55
  signal G_int : std_logic;
56
  signal B_int : std_logic;
57
  signal hsync_int : std_logic;
58
  signal vsync_int : std_logic;
59
 
60
  signal blank : std_logic;
61
  signal hctr  : integer range 793 downto 0;
62
  signal vctr  : integer range 524 downto 0;
63
  -- character/pixel position on the screen
64
  signal scry  : integer range 039 downto 0;  -- chr row   < 40 (6 bits)
65
  signal scrx  : integer range 079 downto 0;  -- chr col   < 80 (7 bits)
66
  signal chry  : integer range 011 downto 0;  -- chr high  < 12 (4 bits)
67
  signal chrx  : integer range 007 downto 0;  -- chr width < 08 (3 bits)
68
 
69
  signal losr_ce : std_logic;
70
  signal losr_ld : std_logic;
71
  signal losr_do : std_logic;
72
  signal y       : std_logic;  -- character luminance pixel value (0 or 1)
73
 
74
  -- control io register
75
  signal ctl       : std_logic_vector(7 downto 0);
76
  signal vga_en    : std_logic;
77
  signal cur_en    : std_logic;
78
  signal cur_mode  : std_logic;
79
  signal cur_blink : std_logic;
80
  signal ctl_r     : std_logic;
81
  signal ctl_g     : std_logic;
82
  signal ctl_b     : std_logic;
83
 
84
  component ctrm
85
    generic (
86
      M : integer := 08);
87
    port (
88
      reset : in  std_logic;            -- asyncronous reset
89
      clk   : in  std_logic;
90
      ce    : in  std_logic;            -- enable counting
91
      rs    : in  std_logic;            -- syncronous reset
92
      do    : out integer range (M-1) downto 0
93
      );
94
  end component;
95
 
96
  component losr
97
    generic (
98
      N : integer := 04);
99
    port (
100
      reset : in  std_logic;
101
      clk   : in  std_logic;
102
      load  : in  std_logic;
103
      ce    : in  std_logic;
104
      do    : out std_logic;
105
      di    : in  std_logic_vector(N-1 downto 0));
106
  end component;
107
 
108
begin
109
 
110
-------------------------------------------------------------------------------
111
-------------------------------------------------------------------------------  
112
-- hsync generator, initialized with '1'
113
  process (reset, clk25MHz)
114
  begin
115
    if reset = '1' then
116
      hsync_int <= '1';
117
    elsif rising_edge(clk25MHz) then
118
 
119
      if (hctr > 663) and (hctr < 757) then
120
        hsync_int <= '0';
121
      else
122
        hsync_int <= '1';
123
      end if;
124
 
125
    end if;
126
  end process;
127
 
128
 
129
-------------------------------------------------------------------------------
130
-------------------------------------------------------------------------------
131
-- vsync generator, initialized with '1'
132
  process (reset, clk25MHz)
133
  begin
134
    if reset = '1' then
135
      vsync_int <= '1';
136
    elsif rising_edge(clk25MHz) then
137
      if (vctr > 499) and (vctr < 502) then
138
        vsync_int <= '0';
139
      else
140
        vsync_int <= '1';
141
      end if;
142
    end if;
143
  end process;
144
 
145
-------------------------------------------------------------------------------
146
-------------------------------------------------------------------------------  
147
-- Blank signal, 0 = no draw, 1 = visible/draw zone   
148
  blank <= '0' when (hctr > 639) or (vctr > 479) else '1';
149
 
150
-------------------------------------------------------------------------------
151
-------------------------------------------------------------------------------  
152
-- flip-flips for sync of R, G y B signal, initialized with '0'
153
  process (reset, clk25MHz)
154
  begin
155
    if reset = '1' then
156
      R <= '0';
157
      G <= '0';
158
      B <= '0';
159
    elsif rising_edge(clk25MHz) then
160
      R <= R_int;
161
      G <= G_int;
162
      B <= B_int;
163
    end if;
164
  end process;
165
 
166
 
167
-------------------------------------------------------------------------------
168
-------------------------------------------------------------------------------  
169
-------------------------------------------------------------------------------
170
-------------------------------------------------------------------------------
171
  -- Control register. Individual control signal
172
  cur_mode  <= octl(4);
173
  cur_blink <= octl(5);
174
  cur_en    <= octl(6);
175
  vga_en    <= octl(7);
176
  ctl_r     <= octl(2);
177
  ctl_g     <= octl(1);
178
  ctl_b     <= octl(0);
179
 
180
        -- counters, hctr, vctr, srcx, srcy, chrx, chry
181
        -- TODO: OPTIMIZE THIS
182
  counters : block
183
    signal hctr_ce : std_logic;
184
    signal hctr_rs : std_logic;
185
    signal vctr_ce : std_logic;
186
    signal vctr_rs : std_logic;
187
 
188
    signal chrx_ce : std_logic;
189
    signal chrx_rs : std_logic;
190
    signal chry_ce : std_logic;
191
    signal chry_rs : std_logic;
192
    signal scrx_ce : std_logic;
193
    signal scrx_rs : std_logic;
194
    signal scry_ce : std_logic;
195
    signal scry_rs : std_logic;
196
 
197
    signal hctr_639 : std_logic;
198
    signal vctr_479 : std_logic;
199
    signal chrx_007 : std_logic;
200
    signal chry_011 : std_logic;
201
    signal scrx_079 : std_logic;
202
 
203
    -- RAM read, ROM read
204
    signal ram_tmp : integer range 3200 downto 0;  --12 bits
205
    signal rom_tmp : integer range 3070 downto 0;
206
 
207
  begin
208
 
209
    U_HCTR : ctrm generic map (M => 794) port map (
210
         reset =>reset, clk=>clk25MHz, ce =>hctr_ce, rs =>hctr_rs, do => hctr);
211
 
212
    U_VCTR : ctrm generic map (M => 525) port map (reset, clk25MHz, vctr_ce, vctr_rs, vctr);
213
 
214
    hctr_ce <= '1';
215
    hctr_rs <= '1' when hctr = 793 else '0';
216
    vctr_ce <= '1' when hctr = 663 else '0';
217
    vctr_rs <= '1' when vctr = 524 else '0';
218
 
219
    U_CHRX: ctrm generic map (M => 008) port map (reset, clk25MHz, chrx_ce, chrx_rs, chrx);
220
    U_CHRY: ctrm generic map (M => 012) port map (reset, clk25MHz, chry_ce, chry_rs, chry);
221
    U_SCRX: ctrm generic map (M => 080) port map (reset, clk25MHz, scrx_ce, scrx_rs, scrx);
222
    U_SCRY: ctrm generic map (M => 040) port map (reset, clk25MHz, scry_ce, scry_rs, scry);
223
 
224
    hctr_639 <= '1' when hctr = 639 else '0';
225
    vctr_479 <= '1' when vctr = 479 else '0';
226
    chrx_007 <= '1' when chrx = 007 else '0';
227
    chry_011 <= '1' when chry = 011 else '0';
228
    scrx_079 <= '1' when scrx = 079 else '0';
229
 
230
    chrx_rs <= chrx_007 or hctr_639;
231
    chry_rs <= chry_011 or vctr_479;
232
    scrx_rs <= hctr_639;
233
    scry_rs <= vctr_479;
234
 
235
    chrx_ce <= '1' and blank;
236
    scrx_ce <= chrx_007;
237
    chry_ce <= hctr_639 and blank;
238
    scry_ce <= chry_011 and hctr_639;
239
 
240
 
241
    ram_tmp <= scry * 80 + scrx + 1 when ((scrx_079 = '0')) else
242
               scry * 80 when ((chry_011 = '0') and (scrx_079 = '1')) else
243
 
244
 
245
    TEXT_A <= std_logic_vector(TO_UNSIGNED(ram_tmp, 12));
246
 
247
    rom_tmp <= TO_INTEGER(unsigned(TEXT_D)) * 12 + chry;
248
    FONT_A <= std_logic_vector(TO_UNSIGNED(rom_tmp, 12));
249
 
250
  end block;
251
-------------------------------------------------------------------------------
252
-------------------------------------------------------------------------------
253
-------------------------------------------------------------------------------
254
 
255
  U_LOSR : losr generic map (N => 8)
256
    port map (reset, clk25MHz, losr_ld, losr_ce, losr_do, FONT_D);
257
 
258
  losr_ce <= blank;
259
  losr_ld <= '1' when (chrx = 007) else '0';
260
 
261
  -- video out, vga_en control signal enable/disable vga signal
262
  R_int <= (ctl_r and y) and blank;
263
  G_int <= (ctl_g and y) and blank;
264
  B_int <= (ctl_b and y) and blank;
265
 
266
  hsync <= hsync_int and vga_en;
267
  vsync <= vsync_int and vga_en;
268
 
269
-------------------------------------------------------------------------------
270
-------------------------------------------------------------------------------
271
-------------------------------------------------------------------------------
272
 
273
  -- Hardware Cursor
274
  hw_cursor : block
275
    signal small   : std_logic;
276
    signal curen2  : std_logic;
277
    signal slowclk : std_logic;
278
    signal curpos  : std_logic;
279
    signal yint    : std_logic;
280
    signal crx_tmp : integer range 079 downto 0;
281
    signal cry_tmp : integer range 039 downto 0;
282
    signal crx     : integer range 079 downto 0;
283
    signal cry     : integer range 039 downto 0;
284
    signal counter : unsigned(22 downto 0);
285
  begin
286
 
287
    -- slowclk for blink hardware cursor
288
    counter <= counter + 1 when rising_edge(clk25MHz);
289
         slowclk <= counter(22); --2.98Hz
290
 
291
    crx <= TO_INTEGER(unsigned(ocrx(6 downto 0)));
292
    cry <= TO_INTEGER(unsigned(ocry(5 downto 0)));
293
 
294
    --
295
    curpos <= '1' when (scry = cry) and (scrx = crx) else '0';
296
    small  <= '1' when (chry > 8)                    else '0';
297
    curen2 <= (slowclk or (not cur_blink)) and cur_en;
298
    yint   <= '1' when cur_mode = '0'                else small;
299
    y      <= (yint and curpos and curen2) xor losr_do;
300
 
301
  end block;
302
 
303
end rtl;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.