-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpixelGenGfx.vhd
420 lines (242 loc) · 12.8 KB
/
pixelGenGfx.vhd
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
library ieee;
use ieee.std_logic_1164.all;
use IEEE.std_logic_arith.all;
use IEEE.std_logic_unsigned.all;
use ieee.numeric_std.all;
entity pixelGenGfx is
port(
reset: in std_logic;
pggClock: in std_logic;
pggR: out std_logic_vector( 7 downto 0 );
pggG: out std_logic_vector( 7 downto 0 );
pggB: out std_logic_vector( 7 downto 0 );
--gfx buffer ram
gfxBufRamDOut: in std_logic_vector( 31 downto 0 );
gfxBufRamRdA: out std_logic_vector( 8 downto 0 );
--2 dma requests
pggDMARequest: out std_logic_vector( 1 downto 0 );
--sync gen outputs
pgVSync: in std_logic;
pgHSync: in std_logic;
pgDe: in std_logic;
pgXCount: in std_logic_vector( 11 downto 0 );
pgYCount: in std_logic_vector( 11 downto 0 );
pgDeX: in std_logic;
pgDeY: in std_logic;
pgPreFetchLine: in std_logic;
pgFetchEnable: in std_logic;
-- 00 : 320x240x16
-- 01 : 640x480x16
pgVideoMode: in std_logic_vector( 1 downto 0 )
);
end pixelGenGfx;
architecture behavior of pixelGenGfx is
type pggState_T is ( m1pre0, m1pre1, m1pre2, m1pre3, m1pre4, m1pre5, m1pre6, m1p0, m1p1, m1p2, m1p3, m1post0, m1post1, m1post2, m1post3, m1hblank,
m2pre0, m2pre1, m2pre2, m2pre3, m2pre4, m2pre5, m2pre6, m2p0, m2p1, m2hblank
);
signal pggState: pggState_T;
signal pggGfxBufAddressCounter: std_logic_vector( 8 downto 0 );
signal pggLineCounter: std_logic_vector( 1 downto 0 );
signal pggPixelData: std_logic_vector( 31 downto 0 );
begin
main: process( all )
begin
if rising_edge( pggClock ) then
if reset = '1' then
pggState <= m1pre0;
pggGfxBufAddressCounter <= ( others => '0' );
pggLineCounter <= ( others => '0' );
pggPixelData <= ( others => '0' );
pggDMARequest <= ( others => '0' );
else
case pggState is
----------------------------------------------
--mode 1: 320x240x16
--wait for fetch enable
--7 prefetch states to match 8 clock cycles between fetch enable and display enable
when m1pre0 =>
pggR <= ( others => '0' );
pggG <= ( others => '0' );
pggB <= ( others => '0' );
--pass dma request for first displayed line
if pgPreFetchLine = '1' then
--fill lower line
pggDMARequest <= "01";
--clear line counter for doubling lo-res lines
pggLineCounter <= ( others => '0' );
else
pggDMARequest <= "00";
end if;
if pgFetchEnable = '1' then
--pre fetch first data
--reset line buf address counter
pggGfxBufAddressCounter <= ( others => '0' );
pggState <= m1pre1;
end if;
--switch mode if necesary
if pgVideoMode = "01" then
pggState <= m2pre0;
end if;
when m1pre1 =>
gfxBufRamRdA <= pggLineCounter( 1 ) & pggGfxBufAddressCounter( 7 downto 0 );
pggState <= m1pre2;
when m1pre2 =>
--dma requests
if pggLineCounter( 0 ) = '0' then
if pggLineCounter( 1 ) = '0' then
--display lower buffer half, fill upper
pggDMARequest <= "10";
else
--display upper buffer half, fill lower
pggDMARequest <= "01";
end if;
end if;
pggState <= m1pre3;
when m1pre3 =>
pggPixelData <= gfxBufRamDOut;
pggGfxBufAddressCounter <= pggGfxBufAddressCounter + 1;
pggState <= m1pre4;
when m1pre4 =>
--clear dma request
pggDMARequest <= ( others => '0' );
pggState <= m1pre5;
when m1pre5 =>
pggState <= m1pre6;
when m1pre6 =>
pggState <= m1p0;
when m1p0 =>
pggR <= pggPixelData( 15 downto 11 ) & "000";
pggG <= pggPixelData( 10 downto 5 ) & "00";
pggB <= pggPixelData( 4 downto 0 ) & "000";
gfxBufRamRdA <= pggLineCounter( 1 ) & pggGfxBufAddressCounter( 7 downto 0 );
pggState <= m1p1;
when m1p1 =>
pggGfxBufAddressCounter <= pggGfxBufAddressCounter + 1;
pggState <= m1p2;
when m1p2 =>
pggR <= pggPixelData( 31 downto 27 ) & "000";
pggG <= pggPixelData( 26 downto 21 ) & "00";
pggB <= pggPixelData( 20 downto 16 ) & "000";
pggState <= m1p3;
when m1p3 =>
pggPixelData <= gfxBufRamDOut;
if pgFetchEnable = '1' then
pggState <= m1p0;
else
pggState <= m1post0;
end if;
when m1post0 =>
-- RiscV
pggR <= pggPixelData( 15 downto 11 ) & "000";
pggG <= pggPixelData( 10 downto 5 ) & "00";
pggB <= pggPixelData( 4 downto 0 ) & "000";
pggState <= m1post1;
when m1post1 =>
pggState <= m1post2;
when m1post2 =>
-- RiscV
pggR <= pggPixelData( 31 downto 27 ) & "000";
pggG <= pggPixelData( 26 downto 21 ) & "00";
pggB <= pggPixelData( 20 downto 16 ) & "000";
pggState <= m1post3;
when m1post3 =>
pggState <= m1hblank;
when m1hblank =>
--inc line counter
pggLineCounter <= pggLineCounter + 1;
pggR <= ( others => '0' );
pggG <= ( others => '0' );
pggB <= ( others => '0' );
pggState <= m1pre0;
----------------------------------------------
--mode 2: 640x480x16
--wait for fetch enable
--7 prefetch states to match 8 clock cycles between fetch enable and display enable
when m2pre0 =>
pggR <= ( others => '0' );
pggG <= ( others => '0' );
pggB <= ( others => '0' );
--pass dma request for first displayed line
if pgPreFetchLine = '1' then
--fill lower line
pggDMARequest <= "01";
else
pggDMARequest <= "00";
end if;
--reset line buf address counter
pggGfxBufAddressCounter <= ( others => '0' );
if pgFetchEnable = '1' then
--pre fetch first data
pggState <= m2pre1;
end if;
--switch mode if necesary
if pgVideoMode = "00" then
pggState <= m1pre0;
end if;
when m2pre1 =>
gfxBufRamRdA <= pggGfxBufAddressCounter;
pggGfxBufAddressCounter <= pggGfxBufAddressCounter + 1;
pggState <= m2pre2;
when m2pre2 =>
--dma requests
--display lower buffer half, fill upper
pggDMARequest <= "10";
pggState <= m2pre3;
when m2pre3 =>
pggPixelData <= gfxBufRamDOut;
gfxBufRamRdA <= pggGfxBufAddressCounter;
pggState <= m2pre4;
when m2pre4 =>
--clear dma request
pggDMARequest <= ( others => '0' );
pggState <= m2pre5;
when m2pre5 =>
pggState <= m2pre6;
when m2pre6 =>
pggState <= m2p0;
when m2p0 =>
-- RISCV
pggR <= pggPixelData( 15 downto 11 ) & "000";
pggG <= pggPixelData( 10 downto 5 ) & "00";
pggB <= pggPixelData( 4 downto 0 ) & "000";
-- MC68K
-- pggR <= pggPixelData( 31 downto 27 ) & "000";
-- pggG <= pggPixelData( 26 downto 21 ) & "00";
-- pggB <= pggPixelData( 20 downto 16 ) & "000";
--display higher buffer half, fill lower
--middle acreen is 48 + 640 / 2 = 368 - 1 px
--adjust this when video timings changed
if pgXCount( 11 downto 1 ) = "00010110111" then
--fetch lowe buffer part
pggDMARequest <= "01";
--switch data fetch address to higher buffer part
pggGfxBufAddressCounter <= "100000001";
gfxBufRamRdA <= "100000000";
else
gfxBufRamRdA <= pggGfxBufAddressCounter;
pggGfxBufAddressCounter <= pggGfxBufAddressCounter + 1;
pggDMARequest <= "00";
end if;
pggState <= m2p1;
when m2p1 =>
pggR <= pggPixelData( 31 downto 27 ) & "000";
pggG <= pggPixelData( 26 downto 21 ) & "00";
pggB <= pggPixelData( 20 downto 16 ) & "000";
pggPixelData <= gfxBufRamDOut;
if pgDeX = '1' then
pggState <= m2p0;
else
pggState <= m2hblank;
end if;
when m2hblank =>
pggR <= ( others => '0' );
pggG <= ( others => '0' );
pggB <= ( others => '0' );
pggState <= m2pre0;
when others =>
pggState <= m1pre0;
end case;
end if;
end if;
end process;
end behavior;