forked from Spartibartfast/4550-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvga_controller.v
More file actions
269 lines (241 loc) · 6.36 KB
/
vga_controller.v
File metadata and controls
269 lines (241 loc) · 6.36 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
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
// VGA controller
// This will draw a 10x10 board onto the screen, with a ribbion on the top,
// Blue on the Ribbion is Player 1, Red on the Ribbion is Player 2.
// There will be a black buffer around the board, and then the 10x10 board itself.
// The Board colours are as follows:
// RED GREEN BLUE
// Blue - Water 0 0 1
// Black - Ship 0 0 0
// Red - Hit 1 0 0
// White - Miss 1 1 1
// 800x600 Horizontal Refresh: 60Hz
// Vertical Refresh: 37.87kHz
// Pixel Frequency: 40.0MHz
module VGA_CONTROLLER (
clock50, // 640x480 @ 25.175MHz Pixel Clock
// 800x600 @ 40.0MHz pixel clock
A, B, C, D, E, F, G, H, I, J,
playerTurn,
vga_red,
vga_green,
vga_blue,
vga_hor_sync,
vga_ver_sync
);
input clock50;
// 800 x 600 resolution...
parameter HORIZONTAL_DISPLAY = 800;
parameter VERTICAL_DISPLAY = 600;
// has a blanking time of:
//Resolution (pixels) (https://eewiki.net/pages/viewpage.action?pageId=15925278)
// Resolution freq pixel disp front sync back
// clock porch pulse porch
// 800x600 60 40 800 40 128 88 h_sync polarity: p ??
// 600 1 4 23 v_sync polarity: p ??
// Timing = disp + front porth + sync pulse + back porch
parameter HORIZONTAL_TIMING = 1056;
parameter VERTICAL_TIMING = 628;
parameter HORIZONTAL_RETRACE = 120;
parameter VERTICAL_RETRACE = 6;
// Board stuff
// the 10x10 battleship board! 48x48 pixel boxes
// Blue - Water
// Grey - Ship
// Red - Hit
// White - Miss
// 00 - water, 01 - ship
// 10 - miss, 11 - hit
// Each two bit section indicates a thingy to draw
input playerTurn;
input [19:0] A;
input [19:0] B;
input [19:0] C;
input [19:0] D;
input [19:0] E;
input [19:0] F;
input [19:0] G;
input [19:0] H;
input [19:0] I;
input [19:0] J;
reg [19:0] empty_pattern = 20'b00000000000000000000;
reg [19:0] tempLetter;
reg can_draw = 0;
// VGA stuff
integer boardLevel;
integer i;
integer k = 10;
output [2:0] vga_red;
output [2:0] vga_green;
output [2:0] vga_blue;
output vga_hor_sync;
output vga_ver_sync;
reg red;
reg green;
reg blue;
reg display;
reg [8:0] colour;
wire board = ( pixel_x[9:3] == 0 ) ||
( pixel_x[9:3] == 79 ) ||
( pixel_y[8:3] == 0 ) ||
( pixel_y[8:3] == 59 );
reg [2:0] t_red;
reg [2:0] t_green;
reg [2:0] t_blue;
reg t_hor;
reg t_ver;
reg [1:0] tempVal;
reg [9:0] pixel_x = 0;
reg [9:0] pixel_y = 0;
always @ ( posedge clock50 )
begin
// pixel_x & _y are used to generate the horizontal sync and the
// vertical sync
if ( pixel_x >= HORIZONTAL_DISPLAY ) // roughy 30us 767
begin
// Go to begining of Horizontal, and go down a level of vertical
pixel_x <= 0;
pixel_y <= pixel_y + 1;
end
else
begin
pixel_x <= pixel_x + 1;
end
//if ( pixel_y >= VERTICAL_TIMING )
// begin
// pixel_y <= 0;
// end
// Horizontal and Vertical Sync
//t_hor <= ( pixel_x[9:4] == 45 ); // 6'h2D
//t_ver <= ( pixel_y == VERTICAL_DISPLAY ); // 500???
//t_hor <= ( pixel_x < HORIZONTAL_DISPLAY );
//t_ver <= ( pixel_y < VERTICAL_DISPLAY );
t_hor <= ( pixel_x < HORIZONTAL_TIMING );
t_ver <= ( pixel_y < VERTICAL_TIMING );
if ( display == 0 )
display <= ( pixel_x == HORIZONTAL_DISPLAY ) && ( pixel_y < VERTICAL_DISPLAY );
else
display <= !( pixel_x == HORIZONTAL_TIMING ); //&& !( pixel_y < VERTICAL_TIMING );
end // end vga sync logic
always @ ( posedge clock50 )
begin
// maybe just if statements checking the pixel_y for a certain pixel count to draw the
// the next letter? Every 48 pixels down draw another letter...
// very low level hard coded values... starting at 96 and going down too 576.
// Then pixel_x can just go across each letter and deal with it from 20 to 500 or something.
// Choose a letter to draw
if ( pixel_y > 0 && pixel_y < 96 )
begin
// Banner
can_draw = 0;
colour = playerTurn == 1'b0 ? 9'b111111111 : 9'b000000000;
boardLevel = 99;
end
else if ( pixel_y > 96 && pixel_y <= 144 )
begin
// A
can_draw = 1;
boardLevel = 1;
end
else if ( pixel_y > 144 && pixel_y <= 192 )
begin
// B
can_draw = 1;
boardLevel = 2;
end
else if ( pixel_y > 192 && pixel_y <= 240 )
begin
// C
can_draw = 1;
boardLevel = 3;
end
else if ( pixel_y > 240 && pixel_y <= 288 )
begin
// D
can_draw = 1;
boardLevel = 4;
end
else if ( pixel_y > 288 && pixel_y <= 336 )
begin
// E
can_draw = 1;
boardLevel = 5;
end
else if ( pixel_y > 336 && pixel_y <= 384 )
begin
// F
can_draw = 1;
boardLevel = 6;
end
else if ( pixel_y > 384 && pixel_y <= 432 )
begin
// G
can_draw = 1;
boardLevel = 7;
end
else if ( pixel_y > 432 && pixel_y <= 528 )
begin
// H
can_draw = 1;
boardLevel = 8;
end
else if ( pixel_y > 528 && pixel_y <= 576 )
begin
// I
can_draw = 1;
boardLevel = 9;
end
else if ( pixel_y > 576 && pixel_y <= 624 )
begin
// J
can_draw = 1;
boardLevel = 10;
end
case ( boardLevel )
1: tempLetter <= A;
2: tempLetter <= B;
3: tempLetter <= C;
4: tempLetter <= D;
5: tempLetter <= E;
6: tempLetter <= F;
7: tempLetter <= G;
8: tempLetter <= H;
9: tempLetter <= I;
10: tempLetter <= J;
99: tempLetter <= empty_pattern;
endcase
case ( k )
10: tempVal = tempLetter[19:18];
9: tempVal = tempLetter[17:16];
8: tempVal = tempLetter[15:14];
7: tempVal = tempLetter[13:12];
6: tempVal = tempLetter[11:10];
5: tempVal = tempLetter[9:8];
4: tempVal = tempLetter[7:6];
3: tempVal = tempLetter[5:4];
2: tempVal = tempLetter[3:2];
1: tempVal = tempLetter[1:0];
endcase
case ( tempVal )
2'b00: colour = 9'b000000111; // water
2'b01: colour = 9'b000000000; // ship
2'b10: colour = 9'b111111111; // miss
2'b11: colour = 9'b111000000; // hit
endcase
if ( ( pixel_x % 48 == 0 ) && ( can_draw == 1 ) )
begin
k = k - 1;
if ( k < 1 )
begin
k = 10;
end
end
t_red <= colour[8:6];
t_green <= colour[5:3];
t_blue <= colour[2:0];
end // end board logic
assign vga_hor_sync = ~t_hor;
assign vga_ver_sync = ~t_ver;
assign vga_red = t_red; //& display;
assign vga_green = t_green; //& display;
assign vga_blue = t_blue; //& display;
endmodule