-
Notifications
You must be signed in to change notification settings - Fork 1
/
gui_control.v
131 lines (96 loc) · 2.3 KB
/
gui_control.v
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
module gui_control (
input clk,
input reset,
input start,
input isDead,
output reg showTitle,
output reg drawMap,
output reg showGameOver,
output reg flashRed,
output reg plot,
output reg title_done
);
localparam
DRAW_TITLE = 4'd0,
TITLE_WAIT = 4'd1,
DRAW_MAP = 4'd2,
GAME_OVER_WAIT = 4'd3,
FLASH_RED = 4'd4,
DRAW_GAME_OVER = 4'd5,
GAME_OVER = 4'd6,
RESTART_WAIT = 4'd7;
reg [3:0] curr_state, next_state;
reg [14:0] pixel_counter;
localparam num_pixels = 32'd19119;
always @(*)
begin
case (curr_state)
DRAW_TITLE :
next_state = pixel_counter == num_pixels ? TITLE_WAIT : DRAW_TITLE;
TITLE_WAIT:
next_state = start? DRAW_MAP : TITLE_WAIT; // TODO adapt to key, space
DRAW_MAP:
next_state = pixel_counter == num_pixels? GAME_OVER_WAIT : DRAW_MAP;
GAME_OVER_WAIT:
next_state = isDead? FLASH_RED : GAME_OVER_WAIT;
FLASH_RED:
next_state = pixel_counter == num_pixels? DRAW_GAME_OVER : FLASH_RED;
DRAW_GAME_OVER:
next_state = pixel_counter == num_pixels ? GAME_OVER: DRAW_GAME_OVER;
GAME_OVER:
next_state = start ? RESTART_WAIT : GAME_OVER;
RESTART_WAIT:
next_state = start? DRAW_TITLE : RESTART_WAIT;
endcase
end
always @(*)
begin
title_done = 1'b0;
drawMap = 1'b0;
showGameOver = 1'b0;
showTitle = 1'b0;
flashRed = 1'b0;
plot = 1'b0;
case (curr_state)
DRAW_TITLE:
begin
showTitle = 1'b1;
plot = 1'b1;
end
DRAW_MAP:
begin
drawMap = 1'b1;
plot = 1'b1;
end
FLASH_RED:
begin
flashRed = 1'b1;
plot = 1'b1;
end
DRAW_GAME_OVER:
begin
showGameOver = 1'b1;
plot = 1'b1;
end
GAME_OVER_WAIT: title_done = 1'b1;
endcase
end
always @(posedge clk)
begin
if (!reset)
begin
curr_state <= DRAW_TITLE;
pixel_counter <= 0;
end
else
begin
curr_state <= next_state;
if (pixel_counter == num_pixels)
pixel_counter <= 0;
else
if (curr_state == DRAW_TITLE || curr_state == DRAW_GAME_OVER ||
curr_state == FLASH_RED || curr_state == DRAW_MAP)
pixel_counter <= pixel_counter + 1'b1;
end
end
endmodule