-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathled_controller.sv
221 lines (214 loc) · 7.35 KB
/
led_controller.sv
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
module led_controller(clock, number,player,select, RedPixels, reset, leds);
input logic player, clock, select, reset; //player 0 = x; player 1 = O;
input logic [3:0] number;
output logic [15:0] [15:0] RedPixels;
output logic [6:0] leds;
logic [1:0] out0, out1, out2, out3, out4, out5, out6, out7, out8;
cell_module c0 (.clock, .reset, .player, .select(select & number == 0), .out(out0));
cell_module c1 (.clock, .reset, .player, .select(select & number == 1), .out(out1));
cell_module c2 (.clock, .reset, .player, .select(select & number == 2), .out(out2));
cell_module c3 (.clock, .reset, .player, .select(select & number == 3), .out(out3));
cell_module c4 (.clock, .reset, .player, .select(select & number == 4), .out(out4));
cell_module c5 (.clock, .reset, .player, .select(select & number == 5), .out(out5));
cell_module c6 (.clock, .reset, .player, .select(select & number == 6), .out(out6));
cell_module c7 (.clock, .reset, .player, .select(select & number == 7), .out(out7));
cell_module c8 (.clock, .reset, .player, .select(select & number == 8), .out(out8));
// logic [3:0] top_row = ;
// logic [3:0] middle_row = out3+out4+out5;
// logic [3:0] bottom_row = out6+out7+out8;
// logic [3:0] left_col = out0+out3+out6;
// logic [3:0] middle_col = out1+out4+out7;
// logic [3:0] right_col = out2+out5+out8;
// logic [3:0] lr_diag = out0+out4+out8;
// logic [3:0] rl_diag = out2+out4+out6;
winner w ( out0, out1, out2, out3, out4, out5, out6, out7, out8, leds);
always_comb
if (reset)
begin
RedPixels = '0;
end
else begin
case (number)
0:begin
if (out0 == 1) begin
RedPixels[1] |= (16'b0100100000000000);
RedPixels[2] |= (16'b0011000000000000);
RedPixels[3] |= (16'b0011000000000000);
RedPixels[4] |= (16'b0100100000000000);
end
else if (out0==2) begin
RedPixels[1] |= (16'b0011000000000000);
RedPixels[2] |= (16'b0100100000000000);
RedPixels[3] |= (16'b0100100000000000);
RedPixels[4] |= (16'b0011000000000000);
end
else begin
RedPixels[1] &= (16'b1000011111111111);
RedPixels[2] &= (16'b1000011111111111);
RedPixels[3] &= (16'b1000011111111111);
RedPixels[4] &= (16'b1000011111111111);
end
end
1:begin
if (out1 == 1) begin
RedPixels[1] |= (16'b0000001001000000);
RedPixels[2] |= (16'b0000000110000000);
RedPixels[3] |= (16'b0000000110000000);
RedPixels[4] |= (16'b0000001001000000);
end
else if (out1==2) begin
RedPixels[1] |= (16'b0000000110000000);
RedPixels[2] |= (16'b0000001001000000);
RedPixels[3] |= (16'b0000001001000000);
RedPixels[4] |= (16'b0000000110000000);
end
else begin
RedPixels[1] &= (16'b1111110000111111);
RedPixels[2] &= (16'b1111110000111111);
RedPixels[3] &= (16'b1111110000111111);
RedPixels[4] &= (16'b1111110000111111);
end
end
2:begin
if (out2==1) begin
RedPixels[1] |= (16'b0000000000010010);
RedPixels[2] |= (16'b0000000000001100);
RedPixels[3] |= (16'b0000000000001100);
RedPixels[4] |= (16'b0000000000010010);
end
else if (out2==2) begin
RedPixels[1] |= (16'b0000000000001100);
RedPixels[2] |= (16'b0000000000010010);
RedPixels[3] |= (16'b0000000000010010);
RedPixels[4] |= (16'b0000000000001100);
end
else begin
RedPixels[1] &= (16'b1111111111100001);
RedPixels[2] &= (16'b1111111111100001);
RedPixels[3] &= (16'b1111111111100001);
RedPixels[4] &= (16'b1111111111100001);
end
end
3:begin
if (out3==1) begin
RedPixels[6] |= (16'b0100100000000000);
RedPixels[7] |= (16'b0011000000000000);
RedPixels[8] |= (16'b0011000000000000);
RedPixels[9] |= (16'b0100100000000000);
end
else if (out3==2) begin
RedPixels[6] |= (16'b0011000000000000);
RedPixels[7] |= (16'b0100100000000000);
RedPixels[8] |= (16'b0100100000000000);
RedPixels[9] |= (16'b0011000000000000);
end
else begin
RedPixels[6] &= (16'b1000011111111111);
RedPixels[7] &= (16'b1000011111111111);
RedPixels[8] &= (16'b1000011111111111);
RedPixels[9] &= (16'b1000011111111111);
end
end
4:begin
if (out4==1) begin
RedPixels[6] |= (16'b0000001001000000);
RedPixels[7] |= (16'b0000000110000000);
RedPixels[8] |= (16'b0000000110000000);
RedPixels[9] |= (16'b0000001001000000);
end
else if (out4==2) begin
RedPixels[6] |= (16'b0000000110000000);
RedPixels[7] |= (16'b0000001001000000);
RedPixels[8] |= (16'b0000001001000000);
RedPixels[9] |= (16'b0000000110000000);
end
else begin
RedPixels[6] &= (16'b1111110000111111);
RedPixels[7] &= (16'b1111110000111111);
RedPixels[8] &= (16'b1111110000111111);
RedPixels[9] &= (16'b1111110000111111);
end
end
5:begin
if (out5==1) begin
RedPixels[6] |= (16'b0000000000010010);
RedPixels[7] |= (16'b0000000000001100);
RedPixels[8] |= (16'b0000000000001100);
RedPixels[9] |= (16'b0000000000010010);
end
else if (out5 == 2) begin
RedPixels[6] |= (16'b0000000000001100);
RedPixels[7] |= (16'b0000000000010010);
RedPixels[8] |= (16'b0000000000010010);
RedPixels[9] |= (16'b0000000000001100);
end
else begin
RedPixels[6] &= (16'b1111111111100001);
RedPixels[7] &= (16'b1111111111100001);
RedPixels[8] &= (16'b1111111111100001);
RedPixels[9] &= (16'b1111111111100001);
end
end
6:begin
if (out6==1) begin
RedPixels[11] |= (16'b0100100000000000);
RedPixels[12] |= (16'b0011000000000000);
RedPixels[13] |= (16'b0011000000000000);
RedPixels[14] |= (16'b0100100000000000);
end
else if (out6==2) begin
RedPixels[11] |= (16'b0011000000000000);
RedPixels[12] |= (16'b0100100000000000);
RedPixels[13] |= (16'b0100100000000000);
RedPixels[14] |= (16'b0011000000000000);
end
else begin
RedPixels[11] &= (16'b1000011111111111);
RedPixels[12] &= (16'b1000011111111111);
RedPixels[13] &= (16'b1000011111111111);
RedPixels[14] &= (16'b1000011111111111);
end
end
7:begin
if (out7==1) begin
RedPixels[11] |= (16'b0000001001000000);
RedPixels[12] |= (16'b0000000110000000);
RedPixels[13] |= (16'b0000000110000000);
RedPixels[14] |= (16'b0000001001000000);
end
else if (out7==2) begin
RedPixels[11] |= (16'b0000000110000000);
RedPixels[12] |= (16'b0000001001000000);
RedPixels[13] |= (16'b0000001001000000);
RedPixels[14] |= (16'b0000000110000000);
end
else begin
RedPixels[11] &= (16'b1111110000111111);
RedPixels[12] &= (16'b1111110000111111);
RedPixels[13] &= (16'b1111110000111111);
RedPixels[14] &= (16'b1111110000111111);
end
end
8:begin
if (out8==1) begin
RedPixels[11] |= (16'b0000000000010010);
RedPixels[12] |= (16'b0000000000001100);
RedPixels[13] |= (16'b0000000000001100);
RedPixels[14] |= (16'b0000000000010010);
end
else if (out8==2) begin
RedPixels[11] |= (16'b0000000000001100);
RedPixels[12] |= (16'b0000000000010010);
RedPixels[13] |= (16'b0000000000010010);
RedPixels[14] |= (16'b0000000000001100);
end
else begin
RedPixels[11] &= (16'b1111111111100001);
RedPixels[12] &= (16'b1111111111100001);
RedPixels[13] &= (16'b1111111111100001);
RedPixels[14] &= (16'b1111111111100001);
end
end
endcase
end
endmodule