This repository was archived by the owner on Oct 10, 2024. It is now read-only.
forked from markovav-official/Game2048_FPGA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptionalProject.sv.bak
More file actions
203 lines (192 loc) · 5.74 KB
/
OptionalProject.sv.bak
File metadata and controls
203 lines (192 loc) · 5.74 KB
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
module OptionalProject (clk, vga_h_sync, vga_v_sync, vga_R, vga_G, vga_B);
input clk;
output vga_h_sync, vga_v_sync, vga_R, vga_G, vga_B;
wire inDisplayArea;
wire [9:0] CounterX;
wire [8:0] CounterY;
wire [4:0] values;
hvsync_generator syncgen(.clk(clk), .hsync (vga_h_sync), .vsync (vga_v_sync), .display_on(inDisplayArea), .hpos(CounterX), .vpos(CounterY));
reg vga_R, vga_G, vga_B;
always @(posedge clk)
begin
if (~inDisplayArea)
begin
vga_R <= 1'b0;
vga_G <= 1'b0;
vga_B <= 1'b0;
end
else if (checkIsGrid(CounterX, CounterY))
begin
vga_R <= 1'b1;
vga_G <= 1'b1;
vga_B <= 1'b1;
end
else if (checkIsDigit(CounterX, CounterY))
begin
vga_R <= 1'b0;
vga_G <= 1'b1;
vga_B <= 1'b0;
end
else if (checkIsInGrid(CounterX, CounterY))
begin
vga_R <= 1'b0;
vga_G <= 1'b0;
vga_B <= 1'b0;
end
else
begin
vga_R <= 1'b0;
vga_G <= 1'b1;
vga_B <= 1'b1;
end
end
function checkIsGrid;
input wire [9:0] x;
input wire [8:0] y;
integer cordX;
integer cordY;
reg temp;
begin
temp = 1'b0;
cordX = CounterX;
cordY = CounterY;
if (cordX >= 121 && cordX <= 535 && cordY >= 41 && cordY <= 43 ||
cordX >= 121 && cordX <= 535 && cordY >= 144 && cordY <= 146 ||
cordX >= 121 && cordX <= 535 && cordY >= 247 && cordY <= 249 ||
cordX >= 121 && cordX <= 535 && cordY >= 350 && cordY <= 352 ||
cordX >= 121 && cordX <= 535 && cordY >= 453 && cordY <= 455)
temp = 1'b1;
if (cordX >= 121 && cordX <= 123 && cordY >= 41 && cordY <= 455 ||
cordX >= 224 && cordX <= 226 && cordY >= 41 && cordY <= 455 ||
cordX >= 327 && cordX <= 329 && cordY >= 41 && cordY <= 455 ||
cordX >= 430 && cordX <= 432 && cordY >= 41 && cordY <= 455 ||
cordX >= 533 && cordX <= 535 && cordY >= 41 && cordY <= 455)
temp = 1'b1;
checkIsGrid = temp;
end
endfunction
function checkIsInGrid;
input wire [9:0] x;
input wire [8:0] y;
integer cordX;
integer cordY;
reg temp;
begin
temp = 1'b0;
cordX = CounterX;
cordY = CounterY;
if (cordX >= 121 && cordX <= 535 && cordY >= 41 && cordY <= 455)
temp = 1'b1;
checkIsInGrid = temp;
end
endfunction
function automatic [4:0] checkCell;
input wire [9:0] x;
input wire [8:0] y;
integer temp;
integer cordX;
integer cordY;
begin
temp = 16;
cordX = CounterX;
cordY = CounterY;
if (cordX >= 124 && cordX <= 223 && cordY >= 44 && cordY <= 143)
temp = 0;
if (cordX >= 227 && cordX <= 326 && cordY >= 44 && cordY <= 143)
temp = 1;
if (cordX >= 330 && cordX <= 429 && cordY >= 44 && cordY <= 143)
temp = 2;
if (cordX >= 433 && cordX <= 532 && cordY >= 44 && cordY <= 143)
temp = 3;
if (cordX >= 124 && cordX <= 223 && cordY >= 147 && cordY <= 246)
temp = 4;
if (cordX >= 227 && cordX <= 326 && cordY >= 147 && cordY <= 246)
temp = 5;
if (cordX >= 330 && cordX <= 429 && cordY >= 147 && cordY <= 246)
temp = 6;
if (cordX >= 433 && cordX <= 532 && cordY >= 147 && cordY <= 246)
temp = 7;
if (cordX >= 124 && cordX <= 223 && cordY >= 250 && cordY <= 349)
temp = 8;
if (cordX >= 227 && cordX <= 326 && cordY >= 250 && cordY <= 349)
temp = 9;
if (cordX >= 330 && cordX <= 429 && cordY >= 250 && cordY <= 349)
temp = 10;
if (cordX >= 433 && cordX <= 532 && cordY >= 250 && cordY <= 349)
temp = 11;
if (cordX >= 124 && cordX <= 223 && cordY >= 353 && cordY <= 452)
temp = 12;
if (cordX >= 227 && cordX <= 326 && cordY >= 353 && cordY <= 452)
temp = 13;
if (cordX >= 330 && cordX <= 429 && cordY >= 353 && cordY <= 452)
temp = 14;
if (cordX >= 433 && cordX <= 532 && cordY >= 353 && cordY <= 452)
temp = 15;
checkCell = temp;
end
endfunction
function checkIsDigit;
input wire [9:0] x;
input wire [8:0] y;
integer cordX;
integer cordY;
integer curCell;
integer tempX;
integer tempY;
reg temp;
begin
temp = 1'b0;
cordX = CounterX;
cordY = CounterY;
curCell = checkCell(CounterX, CounterY);
if (curCell < 16)
begin
if (curCell % 4 == 0) tempX = cordX - 124;
else if (curCell % 4 == 1) tempX = cordX - 227;
else if (curCell % 4 == 2) tempX = cordX - 330;
else if (curCell % 4 == 3) tempX = cordX - 433;
if (curCell < 4) tempY = cordY - 44;
else if (curCell < 8) tempY = cordY - 147;
else if (curCell < 12) tempY = cordY - 250;
else if (curCell < 16) tempY = cordY - 353;
values[0] = 2;
if (values[curCell] == 2)
begin
if (tempY >= 8 && tempY <= 10 && tempX >= 23 && tempX <= 73)
temp = 1'b1;
if (tempY >= 48 && tempY <= 50 && tempX >= 23 && tempX <= 73)
temp = 1'b1;
if (tempY >= 88 && tempY <= 90 && tempX >= 23 && tempX <= 75)
temp = 1'b1;
if (tempY >= 8 && tempY <= 50 && tempX >= 73 && tempX <= 75)
temp = 1'b1;
if (tempY >= 48 && tempY <= 88 && tempX >= 23 && tempX <= 25)
temp = 1'b1;
end
else if (values[curCell] == 4)
begin
if (tempY >= 48 && tempY <= 50 && tempX >= 23 && tempX <= 73)
temp = 1'b1;
if (tempY >= 8 && tempY <= 90 && tempX >= 73 && tempX <= 75)
temp = 1'b1;
if (tempY >= 8 && tempY <= 48 && tempX >= 23 && tempX <= 25)
temp = 1'b1;
end
else if (values[curCell] == 8)
begin
if (tempY >= 8 && tempY <= 10 && tempX >= 23 && tempX <= 73)
temp = 1'b1;
if (tempY >= 48 && tempY <= 50 && tempX >= 23 && tempX <= 73)
temp = 1'b1;
if (tempY >= 88 && tempY <= 90 && tempX >= 23 && tempX <= 75)
temp = 1'b1;
if (tempY >= 8 && tempY <= 90 && tempX >= 73 && tempX <= 75)
temp = 1'b1;
if (tempY >= 8 && tempY <= 90 && tempX >= 23 && tempX <= 25)
temp = 1'b1;
end
end
checkIsDigit = temp;
end
endfunction
endmodule