-
Notifications
You must be signed in to change notification settings - Fork 0
/
square_logic.v
68 lines (60 loc) · 1.48 KB
/
square_logic.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
module square_logic(
input clk,
input rst_n,
input [9:0] x,
input [9:0] x2,
output reg[9:0] vga_x,
output reg[9:0] vga_y,
output reg[9:0] vga_x2,
output reg[9:0] vga_y2
);
reg [31:0] cnt;
reg x_direct;
reg y_direct;
wire move_en;
parameter T_10ms = 500_000;
parameter side = 40;
parameter block = 40;
parameter stick = 75;
parameter vga_xdis = 800;
parameter vga_ydis = 600;
parameter y = 462;
parameter y2 = 136;
always @ (posedge clk, negedge rst_n) begin
if(rst_n == 1'b0)
cnt<=32'd0;
else if(cnt < T_10ms - 1)
cnt<=cnt + 32'd1;
else
cnt<=32'd0;
end
assign move_en = (cnt == T_10ms - 1)? 1'b1:1'b0;
always @ (posedge clk, negedge rst_n) begin
if(rst_n == 1'b0)begin
vga_x<=10'd379;
vga_y<=10'd420;
end
else if(move_en == 1'b1)begin
if((vga_x>=x2-10'd40 && vga_x<(x2+10'd115) && vga_y == y2) || vga_y == 1'b0) begin
vga_x<=x+17;
vga_y<=10'd420;
end
else
vga_y<=vga_y - 10'd1;
end
end
always @ (posedge clk, negedge rst_n) begin
if(rst_n == 1'b0)begin
vga_x2<=10'd379;
vga_y2<=10'd140;
end
else if(move_en == 1'b1)begin
if((vga_x2>=x-10'd40 && vga_x2<(x+10'd115) && vga_y2 == y-side) || vga_y2 == vga_ydis-side) begin
vga_x2<=x2+17;
vga_y2<=10'd140;
end
else
vga_y2<=vga_y2 + 10'd1;
end
end
endmodule