-
Notifications
You must be signed in to change notification settings - Fork 1
/
#vga-small.vhd#
141 lines (117 loc) · 3.33 KB
/
#vga-small.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
library ieee;
use ieee.std_logic_1164.all;
-- use IEEE.STD_LOGIC_UNSIGNED.all;
use IEEE.NUMERIC_STD.all;
entity mod_m_counter is
generic(
N : integer := 7; -- number of bits
M : integer := 80 -- mod-M
);
port (
q : out std_logic_vector((N-1) downto 0);
wrap : out std_logic;
clear : in std_logic;
clock : in std_logic);
end mod_m_counter;
architecture Behav of mod_m_counter is
signal tmp : std_logic_vector((N-1) downto 0) := (others => '0');
begin
process(clock, clear)
begin
if (rising_edge(clock)) then
if (clear = '1') then
tmp <= (others => '0');
else
if unsigned(tmp) = M then -- binary 80
tmp <= (others => '0'); -- equivalent to "0000000"
wrap <= '1';
else
tmp <= std_logic_vector(unsigned(tmp) + 1);
wrap <= '0';
end if;
end if;
end if;
end process;
q <= tmp;
end Behav;
---------------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
-- use IEEE.STD_LOGIC_UNSIGNED.all;
use IEEE.NUMERIC_STD.all;
entity shiftreg is
generic(
N : integer := 9 -- number of bits
);
port (
q : out std_logic;
load : in std_logic;
input : in std_logic_vector((N-1) downto 0);
clock : in std_logic);
end shiftreg;
architecture Behavioral of shiftreg is
signal latch : std_logic_vector((N-1) downto 0);
signal tmp_out : std_logic;
begin
process (clock, input, load)
begin
if (rising_edge(clock)) then
if(load = '1') then
latch <= input;
else
latch((N-1) downto 0) <= latch((N-2) downto 0) & '0';
end if;
end if;
end process;
q <= latch(N-1);
end Behavioral;
---------------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
-- use IEEE.STD_LOGIC_UNSIGNED.all;
use IEEE.NUMERIC_STD.all;
entity attr_selector is
port (
input : in std_logic;
outR : out std_logic_vector(1 downto 0);
outG : out std_logic_vector(1 downto 0);
outB : out std_logic_vector(1 downto 0);
disp_enable : in std_logic;
load : in std_logic;
fg : in std_logic_vector(5 downto 0);
bg : in std_logic_vector(5 downto 0);
flashing : in std_logic;
flashclk : in std_logic;
clock : in std_logic;
blanking : in std_logic
);
end attr_selector;
architecture Behavioral of attr_selector is
signal fg_latch : std_logic_vector(5 downto 0);
signal bg_latch : std_logic_vector(5 downto 0);
signal result : std_logic_vector(5 downto 0);
signal flash_latch : std_logic;
begin
process (clock, input, load)
begin
if (rising_edge(clock)) then
if(load = '1') then
fg_latch <= fg;
bg_latch <= bg;
flash_latch <= flashing;
end if;
if (disp_enable = '0') then
result <= "000000";
else
if (input = '0' or (flashclk and flash_latch) = '1') then
result <= bg_latch;
else
result <= fg_latch;
end if;
end if;
end if;
end process;
outR <= result(5 downto 4);
outG <= result(3 downto 2);
outB <= result(1 downto 0);
end Behavioral;