aboutsummaryrefslogtreecommitdiff
path: root/src/vga/vga.v
blob: da9de58b9cf48913e0027e18b182c79ad84b75df (plain)
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
module vga(
	input wire clk,
	output wire hsync,
	output wire vsync,
	output wire r,
	output wire g,
	output wire b
);

reg[9:0] hcnt;
reg[9:0] vcnt;
reg div;
reg hpulse;
reg vpulse;

wire linedone = hcnt == (800-1);
wire screendone = vcnt == (525-1);

always @(posedge clk)
	div <= div + 1;

always @(posedge div) begin
if(linedone) begin
	hcnt <= 0;
	vcnt <= vcnt + 1;
end
else
	hcnt <= hcnt + 1;
if(screendone)
	vcnt <= 0;
end

always @(posedge div) begin
	hpulse <= hcnt[9:4] == 0;
	vpulse <= vcnt == 0;
end

assign hsync = ~hpulse;
assign vsync = ~vpulse;
assign r = vcnt[3] | hcnt & 1;
assign g = vcnt[3] | hcnt & 1;
assign b = vcnt[3] | hcnt & 1;

endmodule