-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwalls.v
78 lines (64 loc) · 1.63 KB
/
walls.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
// Used for drawing, moving and updating of walls
module walls(
input clk,
input update,
input [5:0]data,
output wire hold,
output wire [5:0]data_addr,
input [2:0]quadrant_collision,
input [9:0]radius_collision,
input [2:0]quadrant,
input [9:0]radius,
input reset,
input [1:0]difficulty,
output reg [2:0]quadrant_out,
output reg visible,
output reg island,
output reg visible_collision
);
reg [5:0]walls[0:127];
reg [11:-2]center;
reg [6:0]write_ptr;
wire [11:0]offset = center[11:0] + radius;
wire [11:0]offset_collision = center[11:0] + radius_collision;
integer i;
always @(posedge clk) begin
if(reset) begin
center <= 14'd6144;
end else if(update) begin
case(difficulty)
2'd0: center <= center + 14'd6;
2'd1: center <= center + 14'd9;
2'd2: center <= center + 14'd12;
2'd3: center <= center + 14'd15;
endcase
end
end
always @(posedge clk) begin
quadrant_out <= quadrant;
if(radius < 10'd28) begin
visible <= 1'b0;
visible_collision <= 1'b0;
island <= 1'b1;
end else if(radius < 10'd32) begin
visible <= 1'b1;
visible_collision <= 1'b0;
island <= 1'b0;
end else begin
visible <= walls[offset[11:5]][quadrant+:1];
visible_collision <= walls[offset_collision[11:5]][quadrant_collision+:1];
island <= 1'b0;
end
end
assign data_addr = write_ptr[5:0];
assign hold = write_ptr[5:0]!=6'd0 || (write_ptr==7'b0000000 && center[11]) || (write_ptr==7'b1000000 && !center[11]);
always @(posedge clk) begin
if(reset) begin
write_ptr <= 7'b1000000;
for (i=0; i<128; i=i+1) walls[i] <= 6'b000000;
end else if(hold) begin
walls[write_ptr] <= data;
write_ptr <= write_ptr + 7'd1;
end
end
endmodule