-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvga_display.v.bak
368 lines (338 loc) · 12 KB
/
vga_display.v.bak
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
// Part 2 skeleton
module gameTest
(
CLOCK_50, // On Board 50 MHz
KEY,
SW,
VGA_CLK, // VGA Clock
VGA_HS, // VGA H_SYNC
VGA_VS, // VGA V_SYNC
VGA_BLANK_N, // VGA BLANK
VGA_SYNC_N, // VGA SYNC
VGA_R, // VGA Red[9:0]
VGA_G, // VGA Green[9:0]
VGA_B // VGA Blue[9:0]
);
input CLOCK_50; // 50 MHz
input [9:0] SW;
input [3:0] KEY;
output VGA_CLK; // VGA Clock
output VGA_HS; // VGA H_SYNC
output VGA_VS; // VGA V_SYNC
output VGA_BLANK_N; // VGA BLANK
output VGA_SYNC_N; // VGA SYNC
output [9:0] VGA_R; // VGA Red[9:0]
output [9:0] VGA_G; // VGA Green[9:0]
output [9:0] VGA_B; // VGA Blue[9:0]
wire [6:0] x2;
wire resetn;
wire [2:0] colour;
wire [6:0] x;
wire [6:0] y;
assign resetn = SW[9];
assign x = {1'b0, x2};
// Create an Instance of a VGA controller - there can be only one!
// Define the number of colours as well as the initial background
// image file (.MIF) for the controller.
vga_adapter VGA(
.resetn(resetn),
.clock(CLOCK_50),
.colour(colour),
.x(x),
.y(y),
.plot(1'b1),
/* Signals for the DAC to drive the monitor. */
.VGA_R(VGA_R),
.VGA_G(VGA_G),
.VGA_B(VGA_B),
.VGA_HS(VGA_HS),
.VGA_VS(VGA_VS),
.VGA_BLANK(VGA_BLANK_N),
.VGA_SYNC(VGA_SYNC_N),
.VGA_CLK(VGA_CLK));
defparam VGA.RESOLUTION = "160x120";
defparam VGA.MONOCHROME = "FALSE";
defparam VGA.BITS_PER_COLOUR_CHANNEL = 1;
defparam VGA.BACKGROUND_IMAGE = "background.mif";
// Put your code here. Your code should produce signals x,y,colour and writeEn/plot
// for the VGA controller, in addition to any other functionality your design may require.
// Instansiate datapath
datapath d0(
.clk(CLOCK_50),
.resetn(resetn),
.track1(SW[0]),
.track2(SW[1]),
.track3(SW[2]),
.track4(SW[3]),
.key1(KEY[3]),
.key2(KEY[2]),
.key3(KEY[1]),
.key4(KEY[0]),
.x(x2),
.y(y),
.color(colour)
);
endmodule
module datapath(
input clk,
input resetn,
input track1,
input track2,
input track3,
input track4,
input key1,
input key2,
input key3,
input key4,
output reg [6:0] x,
output reg [6:0] y,
output reg [2:0] color
);
reg [6:0] x1 = 7'd0;
reg [6:0] y1 = 7'd0;
reg [6:0] x2 = 7'd20;
reg [6:0] y2 = 7'd0;
reg [6:0] x3 = 7'd40;
reg [6:0] y3 = 7'd0;
reg [6:0] x4 = 7'd60;
reg [6:0] y4 = 7'd0;
reg [6:0] x_state = 7'd0;
reg [6:0] y_state = 7'd0;
reg [6:0] x2_state = 7'd0;
reg [6:0] y2_state = 7'd0;
reg [6:0] x3_state = 7'd0;
reg [6:0] y3_state = 7'd0;
reg [6:0] x4_state = 7'd0;
reg [6:0] y4_state = 7'd0;
reg [27:0] counter = 28'd0;
reg track1_state = 0;
reg track2_state = 0;
reg track3_state = 0;
reg track4_state = 0;
reg [6:0] y_up = 7'd80;
reg [6:0] y_down = 7'd100;
reg [6:0] score = 7'd0;
always@(posedge clk) begin
if(resetn) begin
x_state <= 7'd0;
y_state <= 7'd0;
counter <= 28'd0;
score <= 7'd0;
end
else begin
// Game Counter
if (counter < 28'd1000514) begin
// Checking for pulse for each track
if (track1)
track1_state <= 1;
if (track2)
track2_state <= 1;
if (track3)
track3_state <= 1;
if (track4)
track4_state <= 1;
// Stopping tracks when pulse is not sent
if (!track1_state)
y_state <= 7'd0;
if (!track2_state)
y2_state <= 7'd0;
if (!track3_state)
y3_state <= 7'd0;
if (!track4_state)
y4_state <= 7'd0;
// Pressing Notes
if (!key1 && y1 <= y_up && y1 >= y_down) begin
score <= score + 1;
track1_state <= 0;
end
if (!key2 && y2 <= y_up && y2 >= y_down) begin
score <= score + 1;
track2_state <= 0;
end
if (!key3 && y3 <= y_up && y3 >= y_down) begin
score <= score + 1;
track3_state <= 0;
end
if (!key4 && y4 <= y_up && y4 >= y_down) begin
score <= score + 1;
track4_state <= 0;
end
// Reseting tracks when they hit the bottom of the screen
if (y1 == 104)
track1_state <= 0;
if (y2 == 104)
track2_state <= 0;
if (y3 == 104)
track3_state <= 0;
if (y4 == 104)
track4_state <= 0;
// DRAW
// First Track (Drawing)
if (counter < 28'd128) begin
x <= x1;
y <= y1;
color <= 3'b100;
if (counter != 28'd0)
x1 <= x1 + 7'd1;
if (x1 == 7'd15) begin
y1 <= y1 + 7'd1;
x1 <= 7'd0;
end
end
// First Track (Resetin the states)
if (counter == 28'd129) begin
y1 <= y_state;
x1 <= 7'd0;
end
// Second Track (Drawing)
if (counter < 28'd256 && counter >= 28'd129) begin
x <= x2;
y <= y2;
color <= 3'b110;
if (counter != 28'd128)
x2 <= x2 + 7'd1;
if (x2 == 7'd35) begin
y2 <= y2 + 7'd1;
x2 <= 7'd20;
end
end
// Second Track (Resetin the states)
if (counter == 28'd256) begin
y2 <= y2_state;
x2 <= 7'd20;
end
// Third Track (Drawing)
if (counter < 28'd384 && counter >= 28'd256) begin
x <= x3;
y <= y3;
color <= 3'b111;
if (counter != 28'd256)
x3 <= x3 + 7'd1;
if (x3 == 7'd55) begin
y3 <= y3 + 7'd1;
x3 <= 7'd40;
end
end
// Third Track (Reseting the states)
if (counter == 28'd384) begin
y3 <= y3_state;
x3 <= 7'd40;
end
// Fourth Track (Drawing)
if (counter < 28'd512 && counter >= 28'd384) begin
x <= x4;
y <= y4;
color <= 3'b011;
if (counter != 28'd384)
x4 <= x4 + 7'd1;
if (x4 == 7'd75) begin
y4 <= y4 + 7'd1;
x4 <= 7'd60;
end
end
// Fourth Track (Resetin the states)
if (counter == 28'd512) begin
y4 <= y4_state;
x4 <= 7'd60;
end
// DELETE
if (counter >= 28'd1000000) begin
// First Track (Deleting)
if (counter < 28'd1000128) begin
x <= x1;
y <= y1;
color <= 3'b000;
if (counter != 28'd1000000)
x1 <= x1 + 7'd1;
if (x1 == 7'd15) begin
y1 <= y1 + 7'd1;
x1 <= 7'd0;
end
end
// First Track (Changing the states)
if (counter == 28'd1000128) begin
x_state <= x_state + 7'd1;
y_state <= y_state + 7'd1;
end
// First Track (Resetin the states)
if (counter == 28'd1000129) begin
y1 <= y_state;
x1 <= 7'd0;
end
// Second Track (Deleting)
if (counter < 28'd1000256 && counter >= 28'd1000128) begin
x <= x2;
y <= y2;
color <= 3'b000;
if (counter != 28'd1000128)
x2 <= x2 + 7'd1;
if (x2 == 7'd35) begin
y2 <= y2 + 7'd1;
x2 <= 7'd20;
end
end
// Second Track (Changing the states)
if (counter == 28'd1000256) begin
x2_state <= x2_state + 7'd1;
y2_state <= y2_state + 7'd1;
end
// Second Track (Resetin the states)
if (counter == 28'd1000257) begin
y2 <= y2_state;
x2 <= 7'd20;
end
// Third Track (Deleting)
if (counter < 28'd1000384 && counter >= 28'd1000256) begin
x <= x3;
y <= y3;
color <= 3'b000;
if (counter != 28'd1000256)
x3 <= x3 + 7'd1;
if (x3 == 7'd55) begin
y3 <= y3 + 7'd1;
x3 <= 7'd40;
end
end
// Third Track (Changing the states)
if (counter == 28'd1000384) begin
x3_state <= x3_state + 7'd1;
y3_state <= y3_state + 7'd1;
end
// Third Track (Resetin the states)
if (counter == 28'd1000385) begin
y3 <= y3_state;
x3 <= 7'd40;
end
// Fourth Track (Deleting)
if (counter < 28'd1000512 && counter >= 28'd1000384) begin
x <= x4;
y <= y4;
color <= 3'b000;
if (counter != 28'd1000384)
x4 <= x4 + 7'd1;
if (x4 == 7'd75) begin
y4 <= y4 + 7'd1;
x4 <= 7'd60;
end
end
// Fourth Track (Changing the states)
if (counter == 28'd1000512) begin
x4_state <= x4_state + 7'd1;
y4_state <= y4_state + 7'd1;
end
// Fourth Track (Resetin the states)
if (counter == 28'd1000513) begin
y4 <= y4_state;
x4 <= 7'd60;
end
end
// Counter going up
counter = counter + 28'd1;
end
// Reset the counter
else begin
counter <= 28'd0;
end
end
end
endmodule