-
Notifications
You must be signed in to change notification settings - Fork 0
/
laser.v
154 lines (112 loc) · 2.43 KB
/
laser.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
module laser#(parameter CLOCK_FREQUENCY=50000000, fps=24)(
input clock,
input reset,
input start,
input wire [7:0] rocket_x,
input wire [6:0] rocket_y,
output wire draw,
input wire fire,
input wire hit,
output wire destroyed,
output wire [7:0] draw_x, //should be shifyed
output wire [6:0] draw_y,
output wire [2:0] iColor,
output wire [7:0] current_x,
output wire [6:0] current_y,
input wire draw_done,
output wire reset_draw,
output wire done //move done
);
wire [7:0] start_x;
wire move_done;
assign done = move_done;
wire go;
wire [6:0] size;
assign size = 7'd10;
laser_control lc(
.clock(clock),
.reset(reset),
.start(start),
.fire(fire),
.go(go),
.destroyed(destroyed),
.rocket_y(rocket_y),
.rocket_x(rocket_x),
.start_x(start_x),
.draw_x(draw_x),
.draw_y(draw_y),
.current_x(current_x),
.current_y(current_y),
.move_done(move_done)
);
move_dp2#(CLOCK_FREQUENCY, fps) dp3 (
.clock(clock),
.go(go),
.reset(reset),
.draw_done(draw_done),
.draw(draw),
.start_x(start_x),
.start_y(7'd109-size),
.end_x(start_x),
.end_y(7'd0),
.color(3'b110),
.destroy(hit),
.destroyed(destroyed),
.delta_x(0),
.delta_y(-3'd1),
.draw_x(draw_x),
.draw_y(draw_y),
.oColor(iColor),
.move_done(move_done),
.reset_draw(reset_draw)
);
endmodule
module laser_control (
input clock,
input reset,
input start,
input wire fire,
input wire destroyed,
input wire [7:0] rocket_x,
input wire [6:0] rocket_y,
input wire [7:0] draw_x,
input wire [6:0] draw_y,
output reg go,
output reg [7:0] start_x,
output reg [7:0] current_x,//can't always be same as rocket
output reg [6:0] current_y,
input wire move_done
);
reg [1:0] state;
localparam s_nothing = 2'b00, s_wait = 2'b10, s_play = 2'b01, s_w_f = 2'b11;
always @(posedge clock) begin
go <= 0;
if (reset) begin
current_x <= 7'd8;
current_y <= 7'd109;
start_x <= 7'd8;
state <= s_nothing;
end
else begin
case(state)
s_nothing: state <= start ? s_play: s_nothing;
s_play: state <= (fire) ? s_w_f : s_play;
s_w_f: begin
if (!fire) begin
start_x <= rocket_x;
current_x <= rocket_x;
current_y <= rocket_y;
go <= 1'b1;
state <= s_wait; end
end
s_wait: begin
current_x <= draw_x;
current_y <= draw_y;
if (destroyed||move_done) begin
state <= s_play;
end
end
endcase
end
end
endmodule