-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrocket.v
204 lines (133 loc) · 3.21 KB
/
rocket.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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
module rocket#(parameter CLOCK_FREQUENCY = 50000000, fps = 24)(
input clock,
input reset,
input start,
input left,
input right,
//for draw, later animation
output wire draw,
input wire draw_done,
output wire [7:0] draw_x,
output wire [6:0] draw_y,
output [2:0] iColor,
output wire moving_rocket,
//for collision detector
output [7:0] current_x,
output [6:0] current_y,
output wire done //done meving or drawing
);
assign current_y = 7'd109;
wire go;
wire [7:0] start_x, end_x;
wire [6:0] start_y;
assign current_x = start_x;
wire signed [2:0] delta_x;
assign start_y = 7'd109;
// wrong assign current_x = draw_x;
wire move_done;
assign done = move_done;
control_rocket cr (
.clock(clock),
.start(start),
.reset(reset),
.go(go),
.start_x(start_x),
.end_x(end_x),
.left(left),
.right(right),
.delta_x(delta_x),
.move_done(move_done),
.moving_rocket(moving_rocket)
);
move_dp #(CLOCK_FREQUENCY,fps) dr (
.clock(clock),
.go(go),
.reset(reset),
.draw_done(draw_done), //from draw_box
.draw(draw), //for draw_box or animation
.start_x(start_x), //start, end, deltas from control
.start_y(start_y),
.end_x(end_x),
.end_y(start_y),
.color(3'd4), //given color of rocket
.delta_x(delta_x), .delta_y(0),
.draw_x(draw_x), //draw_x, draw_y, for draw box
.draw_y(draw_y),
.oColor(iColor), //ocolor here is icolor to draw_box
.move_done(move_done)
);
endmodule
module control_rocket(
input clock,
input start,
input reset,
output reg go,
output reg [7:0] start_x,
output reg [7:0] end_x,
output reg [7:0] current_x,
input left,
input right,
output reg signed [2:0] delta_x,
input move_done, output reg moving_rocket
);
localparam s_nothing = 3'd0, s_lw = 3'd1, s_rw = 3'd2, s_r = 3'd3, s_l = 3'd4, s_idle = 3'd5, s_wait = 3'd6;
reg [2:0] state;
wire signed [7:0] distance;
assign distance = 8'd16;
reg [7:0] p;
always@(posedge clock) begin
go <= 0;
moving_rocket<=0;
if (reset) begin
go <= 0;
delta_x <= 0;
start_x <= 8'd3;
current_x <= 8'd3;
state <= s_nothing; end
else begin
case(state)
s_nothing: begin
if (start) begin
go <= 1'b1;
state <= s_wait;
end_x <= current_x;
end
end
s_idle: begin
if (left) begin
state <= s_lw;
delta_x <= -3'd1;
end
if (right) begin
state <= s_rw;
delta_x <= 3'd1;
end
end
s_rw: begin
if (!right) begin
if (start_x + distance >= 8'd158) begin
state <= s_idle; end
else begin go <= 1'b1;
state <= s_wait;
end_x <= start_x + distance; end
end
end
s_lw: begin
if (!left) begin
if (start_x - distance < 8'd3|| start_x - distance >start_x) begin
state <= s_idle; end
else begin go <= 1'b1;
state <= s_wait;
end_x <= start_x - distance; end
end end
s_wait: begin
moving_rocket <= 1'b1;
if (move_done) begin
moving_rocket <=0;
state <= s_idle;
start_x <= end_x; current_x <= end_x; end
end
endcase
end //for else
end //for always
endmodule