fill.rdstall
8.69 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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
// $Id: fill.rdstall,v 1.1 2002/05/21 23:55:43 berndt Exp $
`timescale 1ns/1ns
module ms_driver;
//`include "reality.vh"
`include "ms.vh"
//must add: .pipe_busy(pipe_busy)
wire clock;
wire reset_l;
//wire [55:0] other_modes;
//wire [55:0] color_image;
//wire [25:0] z_image; //z_base
//wire [55:0] tex_image;
//wire [1:0] cbus_select;
//wire [2:0] cbus_command;
//wire [31:0] fill_color;
//wire [7:0] blend_color;
//wire [8:6] noise;
//wire [17:0] span_z; //rdpwdepthin
//wire [7:0] span_r, span_g, span_b; //rdpwredin etc
//wire [2:0] span_a; //rdpwalphain
//wire [7:0] pixel_a; //ccalpha
reg [9:0] count1; //counter for startspant0 delay vs. spanbufmt
reg [9:0] count; //nonstallable counter for run time
reg cbus_read_enable; // to be added to ms
reg cbus_write_enable;
reg [1:0] cbus_select; // to be added to ms
reg [2:0] cbus_command; // to be added to ms
reg grant; //dma grant
reg start; //dma data valid
reg finish; //dma read last cycle
reg read_grant; // to be added to ms
reg dma_write_enable; //tristate dma data out enable
reg dma_read_enable;
reg strobe_sync_full;
reg freeze;
reg unfreeze;
reg [55:0] other_modes;
//reg other_modes[54:54]; //dithrgben
//reg other_modes[53:52]; //cycle_type
//reg other_modes[47:47]; //load_tlut_en
//reg other_modes[6:6]; //image_read_en
//reg other_modes[5:5]; //z_update_en
//reg other_modes[4:4]; //z_compare_en
//reg other_modes[1:1]; //dithalphaen
//reg other_modes[0:0]; //alphacompen
reg [55:0] color_image;
//reg color_image[25:0]; //color_base
//reg color_image[52:51]; //color_size
//reg color_image[55:53]; //color_format
reg [25:0] z_image; //z_base
reg [55:0] tex_image;
//reg tex_image[25:0]; //tex_base
//reg tex_image[52:51]; //tex_size
//reg tex_image[55:53]; //tex_format
reg [31:0] fill_color;
reg [7:0] blend_color; //blendalpha
reg [8:6] noise; //noise
reg startspant0;
reg [19:0] nextspanxi;
reg [11:0] nextspanxf;
reg [11:0] nextspancount;
reg nextspanxdec;
reg load_en;
reg spanbufmt;
reg [17:0] span_z; //rdpwdepthin
reg [7:0] span_r, span_g, span_b; //rdpwredin etc
reg [2:0] span_a; //rdpwalphain
reg span_color_we; //rdpcolorwen
reg [7:0] pixel_a; //ccalpha
reg gclock_en;
reg gclock;
//later: figure out how to set tristate bus (weak pullup/down's?)
//inouts:
wire [31:0] cbus_data;
wire [63:0] dbus_data;
wire [7:0] ebus_data;
wire [63:0] copy_load;
wire [7:0] mem_r;
wire [7:0] mem_g;
wire [7:0] mem_b;
wire [2:0] mem_a;
wire [17:0] mem_z;
ms ms ( .clock(clock), .gclock(gclock), .reset_l(reset_l),
.cbus_read_enable(cbus_read_enable), .cbus_select(cbus_select),
.cbus_command(cbus_command), .cbus_write_enable(cbus_write_enable),
.grant(grant), .start(start), .finish(finish),
.read_grant(read_grant), .dma_read_enable(dma_read_enable),
.dma_write_enable(dma_write_enable), .stb_sync_full(strobe_sync_full),
.freeze_gclk(freeze), .unfreeze_gclk(unfreeze),
.cycle_type(other_modes[53:52]), .image_read_en(other_modes[6]),
.z_update_en(other_modes[5]), .z_compare_en(other_modes[4]),
.color_base(color_image[25:0]), .color_size(color_image[52:51]),
.color_format(color_image[55:53]),
.z_base(z_image[25:0]),
.tex_base(tex_image[25:0]), .tex_size(tex_image[52:51]),
.tex_format(tex_image[55:53]),
.load_tlut_en(other_modes[47]), .fillcolor(fill_color[31:0]),
.alphacompen(other_modes[0]), .dithalphaen(other_modes[1]),
.blendalpha(blend_color[7:0]), .noise(noise[8:6]),
.startspant0(startspant0),
.nextspanxi(nextspanxi), .nextspanxf(nextspanxf),
.nextspancount(nextspancount), .nextspanxdec(nextspanxdec),
.load_en(load_en), .spanbufmt(spanbufmt),
.rdpwdepthin(span_z), .rdpwredin(span_r), .rdpwgreenin(span_g),
.rdpwbluein(span_b), .rdpwalphain(span_a),
.rdpcolorwen(span_color_we), .ccalpha(pixel_a[7:0]),
.dithrgben(other_modes[54]),
.cbus_data(cbus_data), .dbus_data(dbus_data), .ebus_data(ebus_data),
.copy_load(copy_load),
.load_dv(load_dv), .rel_sync_full(rel_sync_full),
.stopgclock(stopgclock), .rdramreq(rdramreq), .rdramrw(rdramrw),
.pipe_busy(pipe_busy), .read_request(read_request),
.spanbufrd(spanbufrd),
.rdprred(mem_r), .rdprgreen(mem_g), .rdprblue(mem_b),
.rdpralpha(mem_a), .rdprdepthd(mem_z));
cg cg(clock, reset_l);
always @(gclock_en or clock) begin
gclock <= clock & gclock_en;
end
always @(negedge clock or negedge reset_l) begin
if (!reset_l) begin
gclock_en <= high;
end
else if (reset_l & !clock) begin
gclock_en <= !stopgclock;
end
else begin
gclock_en <= gclock_en;
end
end
always @(posedge clock or negedge reset_l) begin
if (!reset_l) begin
cbus_select <= low;
cbus_command <= low;
cbus_read_enable <= low;
cbus_write_enable <= low;
grant <= high;
start <= high;
finish <= low;
read_grant <= low;
dma_write_enable <= high;
dma_read_enable <= low;
strobe_sync_full <= low;
freeze <= low;
unfreeze <= low;
other_modes[54:54] <= low;
other_modes[53:52] <= 2'h3; //1cy, 2cy, copy, fill
other_modes[47:47] <= low; //load_tlut_en
other_modes[6:6] <= low; //image_read_en
other_modes[5:5] <= low;
other_modes[4:4] <= low;
other_modes[1:1] <= low;
other_modes[0:0] <= low;
color_image[25:0] <= 26'h1000;
color_image[52:51] <= 2'h1; //4,8,16,32b
color_image[55:53] <= 3'h4; //rgba,yuv,ci,ia,I
z_image <= 26'h1000;
tex_image[25:0] <= 26'h1000;
tex_image[52:51] <= 2'h1; //4,8,16,32b
tex_image[55:53] <= 3'h4; //rgba,yuv,ci,ia,I
fill_color <= 32'hdeadbeef;
blend_color <= low;
noise <= low;
load_en <= low;
span_z <= low;
span_r <= low;
span_g <= low;
span_b <= low;
span_a <= low;
span_color_we <= low;
pixel_a <= low;
// nextspanxi <= 20'h100;
// nextspanxf <= 12'h200;
// nextspanxdec <= low;
// nextspancount <= 12'h100;
startspant0 <= low;
count1 <= low;
count <= low;
spanbufmt <= high;
end
else if (reset_l) begin
// nextspanxi <= 20'h100;
// nextspanxf <= 12'h200;
// nextspanxdec <= low;
// nextspancount <= 12'h100;
if (count1 == 1) begin
spanbufmt <= #5 low;
nextspanxi <= #5 20'h1ff;
nextspanxf <= #5 12'h1ff;
nextspanxdec <= #5 low;
nextspancount <= #5 12'h0;
color_image[52:51] <= #5 2'h1; //4,8,16,32b
end
else if (count1 == 10) begin
spanbufmt <= #5 low;
nextspanxi <= #5 20'h1ff;
nextspanxf <= #5 12'h1ff;
nextspanxdec <= #5 low;
nextspancount <= #5 12'h0;
color_image[52:51] <= #5 2'h2; //4,8,16,32b
end
else if (count1 == 19) begin
spanbufmt <= #5 low;
nextspanxi <= #5 20'h241;
nextspanxf <= #5 12'h241;
nextspanxdec <= #5 low;
nextspancount <= #5 12'h0;
color_image[52:51] <= #5 2'h3; //4,8,16,32b
end
else if (count1 == 28) begin
spanbufmt <= #5 low;
nextspanxi <= #5 20'h290;
nextspanxf <= #5 12'h2d0;
nextspanxdec <= #5 low;
nextspancount <= #5 12'h40;
color_image[52:51] <= #5 2'h1; //4,8,16,32b
end
else if (count1 == 37) begin
spanbufmt <= #5 low;
nextspanxi <= #5 20'h1ff;
nextspanxf <= #5 12'h300;
nextspanxdec <= #5 low;
nextspancount <= #5 12'h101;
color_image[52:51] <= #5 2'h1; //4,8,16,32b
end
else if (count1 == 71) begin
spanbufmt <= #5 low;
nextspanxi <= #5 20'h377;
nextspanxf <= #5 12'h601;
nextspanxdec <= #5 low;
nextspancount <= #5 12'h28a;
color_image[52:51] <= #5 2'h1; //4,8,16,32b
end
else if (count1 == 170) begin
// spanbufmt <= #5 low;
nextspanxi <= #5 20'h133;
nextspanxf <= #5 12'h175;
nextspanxdec <= #5 low;
nextspancount <= #5 12'h42;
color_image[52:51] <= #5 2'h2; //4,8,16,32b
end
else begin
spanbufmt <= #5 high;
nextspanxi <= #5 nextspanxi;
nextspanxf <= #5 nextspanxf;
nextspanxdec <= #5 nextspanxdec;
nextspancount <= #5 nextspancount;
end
if (!stopgclock) begin
startspant0 <= #5 ((count1 == 10'd5) || (count1 == 10'd14) ||
(count1 == 10'd23) || (count1 == 10'd32) ||
(count1 == 10'd41) || (count1 == 10'd75) ||
(count1 == 10'd160));
end
else begin
startspant0 <= startspant0;
end
//hack to get rdctxt stall not forever
if (count == 10'd238) begin
spanbufmt <= #5 low;
nextspanxi <= #5 20'h133;
nextspanxf <= #5 12'h175;
nextspanxdec <= #5 low;
nextspancount <= #5 12'h42;
color_image[52:51] <= #5 2'h2; //4,8,16,32b
end
count <= count + 1;
if (!stopgclock) begin
count1 <= count1 + 1;
end
else begin
count1 <= #5 count1;
end
if (count == 300) begin
$finish;
end
end
end
endmodule //