-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcontroller.vhd
86 lines (75 loc) · 2.31 KB
/
controller.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
library ieee;
use ieee.numeric_std.all;
use ieee.std_logic_1164.all;
use work.base_package.all;
entity controller is
port
(
CLOCK : in std_logic;
RESET_N : in std_logic;
CHANGE_SQUARE_BUTTON : in std_logic;
CHANGE_COLOR_BUTTON : in std_logic;
CONFIRM_GUESS_BUTTON : in std_logic;
SHOW_SECRET_BUTTON : in std_logic;
-- Connections with Datapath
CHANGE_SQUARE : out std_logic;
CHANGE_COLOR : out std_logic;
CONFIRM_GUESS : out std_logic;
-- Connections with View
SHOW_SECRET : out std_logic;
REDRAW : out std_logic
);
end entity;
architecture RTL of controller is
begin
process (CLOCK, RESET_N)
variable first_time : std_logic;
variable confirm_guess_old : std_logic;
variable change_square_old : std_logic;
variable change_color_old : std_logic;
variable show_secret_old : std_logic;
variable in_play : std_logic;
begin
if (RESET_N = '0') then
CHANGE_SQUARE <= '0';
CHANGE_COLOR <= '0';
CONFIRM_GUESS <= '0';
SHOW_SECRET <= '0';
REDRAW <= '0';
first_time := '1';
confirm_guess_old := '0';
change_square_old := '0';
change_color_old := '0';
show_secret_old := '0';
in_play := '0';
elsif rising_edge(CLOCK) then
CHANGE_SQUARE <= '0';
CHANGE_COLOR <= '0';
CONFIRM_GUESS <= '0';
REDRAW <= '0';
if (first_time = '1') then
first_time := '0';
REDRAW <= '1';
elsif (change_square_old = '0' and CHANGE_SQUARE_BUTTON = '1') then
CHANGE_SQUARE <= '1';
REDRAW <= '1';
in_play := '1';
elsif (change_color_old = '0' and CHANGE_COLOR_BUTTON = '1') then
CHANGE_COLOR <= '1';
REDRAW <= '1';
in_play := '1';
elsif (confirm_guess_old = '0' and CONFIRM_GUESS_BUTTON = '1') then
CONFIRM_GUESS <= '1';
REDRAW <= '1';
in_play := '1';
elsif (in_play = '1' and show_secret_old /= SHOW_SECRET_BUTTON) then
SHOW_SECRET <= SHOW_SECRET_BUTTON;
REDRAW <= '1';
show_secret_old := SHOW_SECRET_BUTTON;
end if;
change_square_old := CHANGE_SQUARE_BUTTON;
change_color_old := CHANGE_COLOR_BUTTON;
confirm_guess_old := CONFIRM_GUESS_BUTTON;
end if;
end process;
end architecture;