-
Notifications
You must be signed in to change notification settings - Fork 0
/
control.sv
executable file
·160 lines (153 loc) · 3.25 KB
/
control.sv
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/************************************************************************
Core Game control logic
Tulika Gupta and Shayna Kapadia, Spring 2019
Duck Hunt
************************************************************************/
module control (
input logic Clk,
input logic Reset,
input logic start,
input logic no_shots_left,
input logic flew_away,
input logic game_over,
input logic bird_shot,
input logic duck_ded_done,
input logic dog_start,
input logic dog_duck,
output logic new_round,
output logic reset_shots,
output logic reset_score,
output logic reset_birds,
output logic [2:0] state
);
enum logic [3:0] { Start, P1, P1_1, P2, P2_1, P2_2, P2_2_1, P2_3, P3, Done } State, Next_State;
always_ff @ (posedge Clk)
begin
if(Reset)
State <= Start;
else
State <= Next_State;
end
always_comb
begin
// Default: Next state is the same as the current state
Next_State = State;
//Default values for outputs
state = 3'b000;
new_round = 1'b0;
reset_shots = 1'b0;
reset_score = 1'b0;
reset_birds = 1'b0;
//The state definitions begin here
unique case(State)
Start:
begin
if(start)
Next_State = P1_1;
else
Next_State = Start;
end
P1: Next_State = P2;
P1_1:
begin
if(dog_start)
Next_State = P1;
else
Next_State = P1_1;
end
P2:
begin
if(no_shots_left)
Next_State = P2_1;
else if(flew_away)
Next_State = P3;
else if(bird_shot)
Next_State = P2_2;
else
Next_State = P2;
end
P2_1:
begin
if(flew_away)
Next_State = P3;
else
Next_State = P2_1;
end
P2_2:
begin
if(duck_ded_done)
Next_State = P2_3;
else
Next_State = P2_2;
end
P2_3:
if(dog_duck)
Next_State = P3;
else
Next_State = P2_3;
P3:
begin
if(game_over)
Next_State = Done;
else
Next_State = P1;
end
Done:
begin
if(start)
Next_State = Start;
else
Next_State = Done;
end
default:
Next_State = Start;
endcase
//Now, we assign outputs and set variables for these states
case(State)
Start:
begin
state = 3'b000;
reset_shots = 1'b1;
reset_score = 1'b1;
reset_birds = 1'b1;
end
P1_1:
begin
state = 3'b110;
end
P1:
begin
state = 3'b001;
new_round = 1'b1;
end
P2:
begin
state = 3'b010;
end
P2_1:
begin
state = 3'b010;
end
P2_2:
begin
state = 3'b100;
end
P2_3:
begin
state = 3'b101;
end
P3:
begin
state = 3'b010;
reset_shots = 1'b1;
end
Done:
begin
state = 3'b011;
reset_score = 1'b1;
reset_birds = 1'b1;
end
default:;
endcase
end
endmodule