-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGPUModule.sv.bak
More file actions
104 lines (92 loc) · 2.55 KB
/
Copy pathGPUModule.sv.bak
File metadata and controls
104 lines (92 loc) · 2.55 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
module GPU{
// Synchronization
input logic Clock,
input logic Reset,
// VGA In-Out
output logic hsync,
output logic vsync,
output logic[7:0] red,
output logic[7:0] green,
output logic[7:0] blue,
output logic PxClock,
output logic Blank,
output logic Sync,
// Video RAM Access
output logic[19:0] RAMAddress,
inout logic[15:0] RAMData,
output logic RAMHB,
output logic RAMLB,
output logic RAMOE,
output logic RAMWE,
output logic RAMCE,
// Bus Interface
input logic [32:0] BusAddress,
inout logic [32:0] BusData,
input logic DataRead,
input logic DataWrite
};
// VGA timings https://timetoexplore.net/blog/video-timings-vga-720p-1080p
localparam HS_STA = 16; // horizontal sync start
localparam HS_END = 16 + 96; // horizontal sync end
localparam HA_STA = 16 + 96 + 48; // horizontal active pixel start
localparam VS_STA = 480 + 10; // vertical sync start
localparam VS_END = 480 + 10 + 2; // vertical sync end
localparam VA_END = 480; // vertical active pixel end
localparam LINE = 800; // complete line (pixels)
localparam SCREEN = 525; // complete screen (lines)
reg [9:0] h_count; // line position
reg [9:0] v_count; // screen position
logic Active,
ReadTime,
WriteTime,
PixelClock;
logic RedOut,
GreenOut,
BlueOut,
RedNext,
GreenNext;
// generate sync signals (active low for 640x480)
assign hsync = ~((h_count >= HS_STA) & (h_count < HS_END));
assign vsync = ~((v_count >= VS_STA) & (v_count < VS_END));
// keep x and y bound within the active pixels
assign o_x = (h_count < HA_STA) ? 0 : (h_count - HA_STA);
assign o_y = (v_count >= VA_END) ? (VA_END - 1) : (v_count);
// blanking: high within the blanking period
assign Blank = ((h_count < HA_STA) | (v_count > VA_END - 1));
// active: high during active pixel drawing
assign Active = ~((h_count < HA_STA) | (v_count > VA_END - 1));
assign ReadTime = (h_count > HA_STA - 1) & (v_count < VA_END -1);
assign WriteTime = ~ReadTime;
always_comb
begin
//RAM signals
RAMCE=0;
RAMLB=0;
RAMHB=0;
end
always_ff @ (posedge Clock)
begin
PixelClock=~PixelClock;
end
always_ff @ (posedge Clock)
begin
if (Reset) // reset to start of frame
begin
h_count <= 0;
v_count <= 0;
end
if (i_pix_stb) // once per pixel
begin
if (h_count == LINE) // end of line
begin
h_count <= 0;
v_count <= v_count + 1;
end
else
h_count <= h_count + 1;
if (v_count == SCREEN) // end of screen
v_count <= 0;
end
end
end
endmodule