1 | library IEEE;
|
2 | use IEEE.STD_LOGIC_1164.ALL;
|
3 | use IEEE.NUMERIC_STD.ALL;
|
4 | use IEEE.STD_LOGIC_UNSIGNED.ALL;
|
5 |
|
6 | entity vga_text is
|
7 | port(
|
8 | clock : in std_logic;
|
9 |
|
10 | hsync : out std_logic;
|
11 | vsync : out std_logic;
|
12 | red : OUT STD_LOGIC_VECTOR(3 downto 0);
|
13 | green : OUT STD_LOGIC_VECTOR(3 downto 0);
|
14 | blue : OUT STD_LOGIC_VECTOR(3 downto 0)
|
15 | );
|
16 | end vga_text;
|
17 |
|
18 | architecture behavioral of vga_text is
|
19 |
|
20 | signal offs : std_logic_vector (6 downto 0);
|
21 | signal counterx : std_logic_vector (9 downto 0);
|
22 | signal countery : std_logic_vector (9 downto 0);
|
23 | signal basis : std_logic_vector (11 downto 0);
|
24 |
|
25 | signal counterxmaxed : std_logic;
|
26 | signal counterymaxed : std_logic;
|
27 | signal h_enable : std_logic;
|
28 | signal v_enable : std_logic;
|
29 | signal vid_enable : std_logic;
|
30 | signal pixel : std_logic;
|
31 | signal clk25 : std_logic;
|
32 |
|
33 | signal charlin : std_logic_vector (11 downto 0);
|
34 | signal dat : std_logic_vector (7 downto 0);
|
35 |
|
36 | signal char : std_logic_vector (7 downto 0);
|
37 | signal dat_w : std_logic_vector (7 downto 0);
|
38 | signal zpos : std_logic_vector (11 downto 0);
|
39 | signal wr_addr : std_logic_vector (11 downto 0);
|
40 | signal we : std_logic;
|
41 |
|
42 | component ram port(
|
43 | clk25 : in std_logic;
|
44 | we : in std_logic;
|
45 | wr_addr : in std_logic_vector (11 downto 0);
|
46 | rd_addr : in std_logic_vector (11 downto 0);
|
47 | d : in std_logic_vector (7 downto 0);
|
48 | q : out std_logic_vector (7 downto 0)
|
49 | );
|
50 | end component;
|
51 |
|
52 | component rom port(
|
53 | clk25 : in std_logic;
|
54 | addr_a : in std_logic_vector (11 downto 0);
|
55 | q_a : out std_logic_vector (7 downto 0)
|
56 | );
|
57 | end component;
|
58 |
|
59 | begin
|
60 | io1 : ram port map(
|
61 | clk25 => clk25,
|
62 | we => we,
|
63 | rd_addr => zpos,
|
64 | wr_addr => wr_addr,
|
65 | q => char,
|
66 | d => dat_w
|
67 | );
|
68 |
|
69 | io2 : rom port map(
|
70 | clk25 => clk25,
|
71 | addr_a => charlin,
|
72 | q_a => dat
|
73 | );
|
74 |
|
75 | clk25 <= not clk25 when rising_edge(clock);
|
76 |
|
77 | process
|
78 | begin
|
79 | wait until rising_edge(clk25);
|
80 | if counterxmaxed ='1' then
|
81 | counterx <= "0000000000";
|
82 | else
|
83 | counterx <= counterx + "0000000001";
|
84 | if dat(to_integer(unsigned(counterx(2 downto 0)))) = '0' then
|
85 | pixel<='0';
|
86 | else
|
87 | pixel<='1';
|
88 | end if;
|
89 | end if;
|
90 |
|
91 | if counterxmaxed ='1' then
|
92 | if counterymaxed ='1' then
|
93 | countery <= "0000000000";
|
94 | else
|
95 | countery<= countery + "0000000001";
|
96 | end if;
|
97 | end if ;
|
98 |
|
99 | if counterx (2 downto 0)="000" then
|
100 | if counterx ="0000000000" and countery ="0000000000" then
|
101 | basis <= "000000000000";
|
102 | elsif counterx ="0000000000" and countery(3 downto 0) ="0000" then
|
103 | basis<= basis + "000001010000";
|
104 | end if;
|
105 | end if;
|
106 |
|
107 | offs <= counterx(9 downto 3);
|
108 | zpos <= basis + offs;
|
109 | end process;
|
110 |
|
111 | process
|
112 | begin
|
113 | wait until rising_edge(clk25);
|
114 | if vid_enable ='1' and pixel='1' then
|
115 | red <="1111";
|
116 | green<="1111";
|
117 | blue <="1111";
|
118 | else
|
119 | red <="0000";
|
120 | green<="0000";
|
121 | blue <="0000";
|
122 | end if;
|
123 | end process;
|
124 |
|
125 | counterxmaxed <='1' when counterx = "1100100000" else '0';
|
126 | counterymaxed <='1' when countery = "1000001101" else '0';
|
127 |
|
128 | hsync <='1' when counterx < "1010001111" or counterx > "1011101111" else '0';
|
129 | vsync <='1' when countery < "0111101001" or countery > "0111101011" else '0';
|
130 |
|
131 | h_enable <= '1' when counterx > "0000000100" and counterx < "1010000000" else '0';
|
132 | v_enable <= '1' when countery < "0111100000" else '0';
|
133 | vid_enable <= '1' when h_enable = '1' and v_enable = '1' else '0';
|
134 |
|
135 | charlin <= std_logic_vector(to_unsigned(to_integer(unsigned(char)) + to_integer(unsigned(countery(3 downto 1))),12));
|
136 |
|
137 | end behavioral;
|