-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatapath.v
190 lines (177 loc) · 4.09 KB
/
datapath.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
module datapath (
input clk,
input resetn,
input [7:0] column_in,
// Data from control.v
input ld_column,
input draw,
input [1:0] player,
// Data into control.v
output reg valid,
output reg [8:0] write_to_ram,
output reg [6:0] col_out
);
reg not_set;
reg [6:0] col_zero, col_one, col_two, col_three, col_four, col_five, col_six, col_seven;
reg [7:0] col_store;
localparam
COL_ZERO = 8'd1,
COL_ONE = 8'd2,
COL_TWO = 8'd4,
COL_THREE = 8'd8,
COL_FOUR = 8'd16,
COL_FIVE = 8'd32,
COL_SIX = 8'd64,
COL_SEVEN = 8'd128,
EIGHT = 7'd8;
always @ (posedge clk) begin
if (!resetn) begin
col_store <= 8'd0;
valid <= 1'd1;
write_to_ram <= 11'd0;
col_out <= 7'd0;
col_zero <= 7'd64;
col_one <= 7'd65;
col_two <= 7'd66;
col_three <= 7'd67;
col_four <= 7'd68;
col_five <= 7'd69;
col_six <= 7'd70;
col_seven <= 7'd71;
not_set <= 1'd1;
end else begin
if (ld_column) begin
case (column_in)
COL_ZERO : begin
if (col_zero == 7'd0) begin
valid <= 1'd0;
end else begin
col_store <= column_in;
not_set <= 1'd1;
valid <= 1'd1;
end
end COL_ONE : begin
if (col_one == 7'd1) begin
valid <= 1'd0;
end else begin
col_store <= column_in;
not_set <= 1'd1;
valid <= 1'd1;
end
end COL_TWO : begin
if (col_two == 7'd2) begin
valid <= 1'd0;
end else begin
col_store <= column_in;
not_set <= 1'd1;
valid <= 1'd1;
end
end COL_THREE : begin
if (col_three == 7'd3) begin
valid <= 1'd0;
end else begin
col_store <= column_in;
not_set <= 1'd1;
valid <= 1'd1;
end
end COL_FOUR : begin
if (col_four == 7'd4) begin
valid <= 1'd0;
end else begin
col_store <= column_in;
not_set <= 1'd1;
valid <= 1'd1;
end
end COL_FIVE : begin
if (col_five == 7'd5) begin
valid <= 1'd0;
end else begin
col_store <= column_in;
not_set <= 1'd1;
valid <= 1'd1;
end
end COL_SIX : begin
if (col_six == 7'd6) begin
valid <= 1'd0;
end else begin
col_store <= column_in;
not_set <= 1'd1;
valid <= 1'd1;
end
end COL_SEVEN : begin
if (col_seven == 7'd7) begin
valid <= 1'd0;
end else begin
col_store <= column_in;
not_set <= 1'd1;
valid <= 1'd1;
end
end default : begin
valid <= 1'd0;
end
endcase
end
if (draw) begin
case (col_store)
COL_ZERO : begin
if (not_set) begin
col_zero <= col_zero - EIGHT;
not_set <= 1'd0;
end
write_to_ram <= {col_zero, player};
col_out <= col_zero;
end COL_ONE : begin
if (not_set) begin
col_one <= col_one - EIGHT;
not_set <= 1'd0;
end
write_to_ram <= {col_one, player};
col_out <= col_one;
end COL_TWO : begin
if (not_set) begin
col_two <= col_two - EIGHT;
not_set <= 1'd0;
end
write_to_ram <= {col_two, player};
col_out <= col_two;
end COL_THREE : begin
if (not_set) begin
col_three <= col_three - EIGHT;
not_set <= 1'd0;
end
write_to_ram <= {col_three, player};
col_out <= col_three;
end COL_FOUR : begin
if (not_set) begin
col_four <= col_four - EIGHT;
not_set <= 1'd0;
end
write_to_ram <= {col_four, player};
col_out <= col_four;
end COL_FIVE : begin
if (not_set) begin
col_five <= col_five - EIGHT;
not_set <= 1'd0;
end
write_to_ram <= {col_five, player};
col_out <= col_five;
end COL_SIX : begin
if (not_set) begin
col_six <= col_six - EIGHT;
not_set <= 1'd0;
end
write_to_ram <= {col_six, player};
col_out <= col_six;
end COL_SEVEN : begin
if (not_set) begin
col_seven <= col_seven - EIGHT;
not_set <= 1'd0;
end
write_to_ram <= {col_seven, player};
col_out <= col_seven;
end
endcase
end
end
end
endmodule