-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGPU.sv
More file actions
300 lines (275 loc) · 4.79 KB
/
Copy pathGPU.sv
File metadata and controls
300 lines (275 loc) · 4.79 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
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
module GPU_old (
// 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,
input logic [63:0] Instruction,
input logic AddInstruction,
output logic[2:0] InstructionsRemaining
);
logic PixelClock;
logic [63:0] Instructions [7:0];
logic [2:0] NE,NP;
logic [63:0] CInstruction;
logic [4:0] CRed,CGreen,CBlue;
logic [2:0] COP;
logic Clear;
logic [9:0] CXS,CXE;
logic [8:0] CYS,CYE;
assign InstructionsRemaining=NE-NP;
assign CRed=CInstruction[63:59];
assign CGreen=CInstruction[58:54];
assign CBlue=CInstruction[53:49];
assign Clear=CInstruction[48];
assign COP=CInstruction[47:45];
assign CXS=CInstruction[44:35];
assign CYS=CInstruction[34:26];
assign CXE=CInstruction[25:16];
assign CYE=CInstruction[15:7];
always_ff@(posedge Clock)
begin
if(AddInstruction)
begin
if(NE+1!=NP)
begin
NE<=NE+1;
Instructions[NE]=Instruction;
end
end
end
always_ff@(posedge Clock)
begin
if(~Finished)
begin
if(Initialized)
begin
if(GPUTime)
begin
if(~Clear)
begin
if(GPUX<639)
begin
GPUX<=GPUX+1;
end
else
begin
GPUX<=0;
if(GPUY<479)
begin
GPUY<=GPUY+1;
end
else
begin
Finished<=1;
end
end
end
else
begin
case(COP)
3'b000:
begin
if(GPUY<CYE)
GPUY<=GPUY+1;
else
Finished<=1;
end
3'b001:
begin
if(GPUX<CXE)
GPUX<=GPUX+1;
else
Finished<=1;
end
3'b010:
begin
if(GPUX<CXE)
begin
GPUX<=GPUX+1;
end
else
begin
if(GPUY<CYE)
begin
GPUY<=GPUY+1;
GPUX<=CXS;
end
else
begin
Finished<=1;
end
end
end
default:Finished<=1;
endcase
end
end
end
else
begin
Initialized<=1;
if(Clear)
begin
GPUX<=CXS;
GPUY<=CYS;
end
else
begin
GPUX<=0;
GPUY<=0;
end
end
end
else
begin
if(NE!=NP)
begin
CInstruction=Instructions[NP];
NP<=NP+1;
Finished<=0;
Initialized<=0;
end
end
end
//VGA Controller
logic [9:0] col,line;
logic [19:0] PixelAddress;
assign PixelAddress[19]=0;
assign PixelAddress[18:9]=col[9:0];
assign PixelAddress[8:0]=line[8:0];
//RAM signals
assign RAMCE=0;
assign RAMLB=0;
assign RAMHB=0;
//GPU Controller
logic[19:0] GPUAddress;
logic[15:0] GPUData;
logic GPUWE;
logic [9:0] GPUX,GPUY;
assign GPUAddress[19]=0;
assign GPUAddress[18:9]=GPUX[9:0];
assign GPUAddress[8:0]=GPUY[8:0];
assign GPUData[15:11]=CRed;
assign GPUData[10:6]=CGreen;
assign GPUData[5:0]=CBlue;
assign GPUWE=~(~Finished&&Initialized&&GPUTime);
logic Finished;
logic Initialized;
logic GPUTime;
assign GPUTime=~((col<640 && line<480)||col>798);
always_comb
begin
if(~GPUTime)
begin
RAMAddress[19]<=0;
RAMAddress[18:0]<=PixelAddress;
RAMData<=16'bzzzzzzzzzzzzzzzz;
RAMOE<=0;
RAMWE<=1;
end
else
begin
RAMAddress<=GPUAddress;
RAMData<=GPUData;
RAMOE<=1;
RAMWE<=GPUWE;
end
end
assign hsync=~(col>=656 && col<752);
assign vsync=~(line>=491 && line<493);
assign Sync=1;
assign Blank=(col<640 && line<480);
assign PxClock=PixelClock;
always_ff @(negedge Clock,negedge Reset)
begin
if(~Reset)
begin
red<=0;
green<=0;
blue<=0;
end
else
begin
if(~PixelClock)
begin
if (col<640 && line<480)
begin
red[7:3]<=RAMData[15:11];
red[2:0]<=3'b111;
green[7:3]<=RAMData[10:6];
green[2:0]<=3'b000;
blue[7:3]<=RAMData[5:0];
blue[2:0]<=3'b000;
end
end
end
end
always_ff @(posedge Clock,negedge Reset) //PixelClock
begin
if(~Reset)
begin
PixelClock<=0;
end
else
begin
PixelClock<=~PixelClock;
end
end
always_ff @(posedge Clock,negedge Reset) //Columns
begin
if(~Reset)
begin
col<=0;
end
else
begin
if (PixelClock)
begin
if(col<799)
col<=col+1;
else
col<=0;
end
end
end
always_ff @(posedge Clock,negedge Reset) //lines
begin
if(~Reset)
begin
line<=0;
end
else
begin
if (PixelClock)
begin
if(col==799) begin
if(line==523)
line<=0;
else
line<=line+1;
end
end
end
end
endmodule