OpenCores
URL https://opencores.org/ocsvn/rtfbitmapcontroller/rtfbitmapcontroller/trunk

Subversion Repositories rtfbitmapcontroller

[/] [rtfbitmapcontroller/] [trunk/] [rtl/] [verilog/] [FTBitmapController.v] - Blame information for rev 22

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 21 robfinch
// ============================================================================
2
//  Bitmap Controller
3
//  - Displays a bitmap from memory.
4
//
5
//
6
//        __
7
//   \\__/ o\    (C) 2008-2017  Robert Finch, Waterloo
8
//    \  __ /    All rights reserved.
9
//     \/_//     robfinch<remove>@finitron.ca
10
//       ||
11
//
12
//
13
// This source file is free software: you can redistribute it and/or modify 
14
// it under the terms of the GNU Lesser General Public License as published 
15
// by the Free Software Foundation, either version 3 of the License, or     
16
// (at your option) any later version.                                      
17
//                                                                          
18
// This source file is distributed in the hope that it will be useful,      
19
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
20
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
21
// GNU General Public License for more details.                             
22
//                                                                          
23
// You should have received a copy of the GNU General Public License        
24
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
25
//                                                                          
26
//
27
//  The default base screen address is:
28
//              $0200000 - the second 4MiB of RAM
29
//
30
//
31
//      Verilog 1995
32
//
33
// ============================================================================
34
 
35
module FTBitmapController(
36
        rst_i,
37
        s_clk_i, s_cs_i, s_cyc_i, s_stb_i, s_ack_o, s_we_i, s_adr_i, s_dat_i, s_dat_o, irq_o,
38
        m_clk_i, m_bte_o, m_cti_o, m_cyc_o, m_stb_o, m_ack_i, m_we_o, m_sel_o, m_adr_o, m_dat_i, m_dat_o,
39 22 robfinch
        vclk, hsync, vsync, blank, rgbo, rgbPlane_o, xonoff
40 21 robfinch
);
41
parameter pIOAddress = 32'hFFDC5000;
42
parameter BM_BASE_ADDR1 = 32'h0020_0000;
43
parameter BM_BASE_ADDR2 = 32'h0028_0000;
44
parameter REG_CTRL = 10'd0;
45
parameter REG_CTRL2 = 10'd1;
46
parameter REG_HDISPLAYED = 10'd2;
47
parameter REG_VDISPLAYED = 10'd3;
48
parameter REG_PAGE1ADDR = 10'd5;
49
parameter REG_PAGE2ADDR = 10'd6;
50
parameter REG_REFDELAY = 10'd7;
51
parameter REG_MAP = 10'd8;
52
parameter REG_PX = 10'd9;
53
parameter REG_PY = 10'd10;
54
parameter REG_COLOR = 10'd11;
55
parameter REG_PCMD = 10'd12;
56
 
57
parameter BPP6 = 3'd0;
58
parameter BPP8 = 3'd1;
59
parameter BPP12 = 3'd2;
60
parameter BPP16 = 3'd3;
61
parameter BPP24 = 3'd4;
62
parameter BPP32 = 3'd5;
63
 
64
parameter OPBLACK = 4'd0;
65
parameter OPCOPY = 4'd1;
66
parameter OPINV = 4'd2;
67
parameter OPAND = 4'd4;
68
parameter OPOR = 4'd5;
69
parameter OPXOR = 4'd6;
70
parameter OPANDN = 4'd7;
71
parameter OPNAND = 4'd8;
72
parameter OPNOR = 4'd9;
73
parameter OPXNOR = 4'd10;
74
parameter OPORN = 4'd11;
75
parameter OPWHITE = 4'd15;
76
 
77
// The following parameter inserts an extra cycle of setup time for the
78
// address and write control signals if true.
79
parameter EXTRA_SUT = 1'b0; // extra setup time
80
 
81
// SYSCON
82
input rst_i;                            // system reset
83
 
84
// Peripheral IO slave port
85
input s_clk_i;
86
input s_cs_i;
87
input s_cyc_i;
88
input s_stb_i;
89
output s_ack_o;
90
input s_we_i;
91
input [11:0] s_adr_i;
92
input [31:0] s_dat_i;
93
output [31:0] s_dat_o;
94
reg [31:0] s_dat_o;
95
output irq_o;
96
 
97
// Video Memory Master Port
98
// Used to read memory via burst access
99
input m_clk_i;                          // system bus interface clock
100
output [1:0] m_bte_o;
101
output [2:0] m_cti_o;
102
output m_cyc_o;                 // video burst request
103
output m_stb_o;
104
output reg m_we_o;
105
output [15:0] m_sel_o;
106
input  m_ack_i;                 // vid_acknowledge from memory
107
output [31:0] m_adr_o;   // address for memory access
108
input  [127:0] m_dat_i;  // memory data input
109
output reg [127:0] m_dat_o;
110
 
111
// Video
112
input vclk;                             // Video clock 85.71 MHz
113
input hsync;                            // start/end of scan line
114
input vsync;                            // start/end of frame
115
input blank;                    // blank the output
116
output [23:0] rgbo;              // 24-bit RGB output
117
reg [23:0] rgbo;
118
output [3:0] rgbPlane_o;
119
reg [3:0] rgbPlane_o;
120
 
121
input xonoff;
122
 
123
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
124
// IO registers
125
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
126
reg m_cyc_o;
127
reg [31:0] m_adr_o;
128
 
129
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
130
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
131
wire cs = s_cyc_i & s_stb_i & s_cs_i;
132
reg ack,ack1;
133
always @(posedge s_clk_i)
134
begin
135
        ack1 <= cs;
136
        ack <= ack1 & cs;
137
end
138
assign s_ack_o = cs ? (s_we_i ? 1'b1 : ack) : 1'b0;
139
 
140
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
141
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
142
integer n;
143
reg [11:0] hDisplayed,vDisplayed;
144
reg [31:0] bm_base_addr1,bm_base_addr2;
145
reg [2:0] color_depth;
146
wire [7:0] fifo_cnt;
147
reg onoff;
148
reg [2:0] hres,vres;
149
reg greyscale;
150
reg page;
151
reg pals;                               // palette select
152
reg [11:0] hrefdelay;
153
reg [11:0] vrefdelay;
154
reg [11:0] map;     // memory access period
155
reg [11:0] mapctr;
156
reg [11:0] hctr;         // horizontal reference counter
157
wire [11:0] hctr1 = hctr - hrefdelay;
158
reg [11:0] vctr;         // vertical reference counter
159
wire [11:0] vctr1 = vctr - vrefdelay;
160
reg [31:0] baseAddr;     // base address register
161
wire [127:0] rgbo1;
162
reg [11:0] pixelRow;
163
reg [11:0] pixelCol;
164
wire [31:0] pal_wo;
165
wire [31:0] pal_o;
166
reg [11:0] px;
167
reg [11:0] py;
168
reg [1:0] pcmd,pcmd_o;
169
reg [3:0] raster_op;
170
reg [31:0] color;
171
reg [31:0] color_o;
172
reg rstcmd,rstcmd1;
173
 
174
edge_det edcs1
175
(
176
        .rst(rst_i),
177
        .clk(s_clk_i),
178
        .ce(1'b1),
179
        .i(cs),
180
        .pe(cs_edge),
181
        .ne(),
182
        .ee()
183
);
184
 
185
 
186
always @(page or bm_base_addr1 or bm_base_addr2)
187
        baseAddr = page ? bm_base_addr2 : bm_base_addr1;
188
 
189
// Color palette RAM for 8bpp modes
190
syncRam512x32_1rw1r upal1
191
(
192
        .wrst(1'b0),
193
        .wclk(s_clk_i),
194
        .wce(cs & s_adr_i[11]),
195
        .we(s_we_i),
196
        .wadr(s_adr_i[10:2]),
197
        .i(s_dat_i),
198
        .wo(pal_wo),
199
        .rrst(1'b0),
200
        .rclk(vclk),
201
        .rce(1'b1),
202
        .radr({pals,rgbo4[7:0]}),
203
        .o(pal_o)
204
);
205
 
206
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
207
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
208
always @(posedge s_clk_i)
209
if (rst_i) begin
210
        page <= 1'b0;
211
        pals <= 1'b0;
212
        hres <= 3'd4;
213
        vres <= 3'd3;
214
        hDisplayed <= 12'd340;
215
        vDisplayed <= 12'd256;
216
        onoff <= 1'b1;
217
        color_depth <= BPP16;
218
        greyscale <= 1'b0;
219
        bm_base_addr1 <= BM_BASE_ADDR1;
220
        bm_base_addr2 <= BM_BASE_ADDR2;
221
        hrefdelay <= 12'd54;//12'd218;
222
        vrefdelay <= 12'd8;//12'd27;
223
        map <= 12'd0;
224
        pcmd <= 2'b00;
225
        rstcmd1 <= 1'b0;
226
end
227
else begin
228
        rstcmd1 <= rstcmd;
229
  if (rstcmd & ~rstcmd1)
230
    pcmd <= 2'b00;
231
        if (cs_edge) begin
232
                if (s_we_i) begin
233
                        casex(s_adr_i[11:2])
234
                        REG_CTRL:
235
                                begin
236
                                        onoff <= s_dat_i[0];
237
                                        color_depth <= s_dat_i[10:8];
238
                                        greyscale <= s_dat_i[11];
239
                                        hres <= s_dat_i[18:16];
240
                                        vres <= s_dat_i[21:19];
241
                                end
242
                        REG_CTRL2:
243
                                begin
244
                                        page <= s_dat_i[16];
245
                                        pals <= s_dat_i[17];
246
                                end
247
                        REG_HDISPLAYED: hDisplayed <= s_dat_i[11:0];
248
                        REG_VDISPLAYED: vDisplayed <= s_dat_i[11:0];
249
                        REG_PAGE1ADDR:  bm_base_addr1 <= s_dat_i;
250
                        REG_PAGE2ADDR:  bm_base_addr2 <= s_dat_i;
251
                        REG_REFDELAY:
252
                                begin
253
                                        hrefdelay <= s_dat_i[11:0];
254
                                        vrefdelay <= s_dat_i[27:16];
255
                                end
256
                        REG_MAP:   map <= s_dat_i[11:0];
257
                        REG_PX:    px <= s_dat_i[11:0];
258
                        REG_PY:    py <= s_dat_i[11:0];
259
                        REG_PCMD:  begin
260
                                   pcmd <= s_dat_i[1:0];
261
                                   raster_op <= s_dat_i[19:16];
262
                                   end
263
      REG_COLOR: color <= s_dat_i;
264
      default:  ;
265
                        endcase
266
                end
267
        end
268
    casex(s_adr_i[11:2])
269
    REG_CTRL:
270
        begin
271
            s_dat_o[0] <= onoff;
272
            s_dat_o[10:8] <= color_depth;
273
            s_dat_o[11] <= greyscale;
274
            s_dat_o[18:16] <= hres;
275
            s_dat_o[21:19] <= vres;
276
        end
277
    REG_CTRL2:
278
        begin
279
            s_dat_o[16] <= page;
280
            s_dat_o[17] <= pals;
281
        end
282
    REG_HDISPLAYED:     s_dat_o <= hDisplayed;
283
    REG_VDISPLAYED:     s_dat_o <= vDisplayed;
284
    REG_PAGE1ADDR:      s_dat_o <= bm_base_addr1;
285
    REG_PAGE2ADDR:      s_dat_o <= bm_base_addr2;
286
    REG_REFDELAY:         s_dat_o <= {vrefdelay,4'h0,hrefdelay};
287
    REG_MAP:        s_dat_o <= map;
288
    REG_PX:                         s_dat_o <= px;
289
    REG_PY:                         s_dat_o <= py;
290
    REG_COLOR:      s_dat_o <= color_o;
291
    REG_PCMD:                     begin
292
                    s_dat_o <= pcmd;
293
                    end
294
    10'b1xxx_xxxx_xx:    s_dat_o <= pal_wo;
295
    default:        s_dat_o <= 32'd0;
296
    endcase
297
end
298
 
299
assign irq_o = 1'b0;
300
 
301
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
302
// Horizontal and Vertical timing reference counters
303
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
304
 
305
wire pe_hsync, pe_hsync2;
306
wire pe_vsync;
307
edge_det edh1
308
(
309
        .rst(rst_i),
310
        .clk(vclk),
311
        .ce(1'b1),
312
        .i(hsync),
313
        .pe(pe_hsync),
314
        .ne(),
315
        .ee()
316
);
317
 
318
edge_det edh2
319
(
320
        .rst(rst_i),
321
        .clk(m_clk_i),
322
        .ce(1'b1),
323
        .i(hsync),
324
        .pe(pe_hsync2),
325
        .ne(),
326
        .ee()
327
);
328
 
329
edge_det edv1
330
(
331
        .rst(rst_i),
332
        .clk(vclk),
333
        .ce(1'b1),
334
        .i(vsync),
335
        .pe(pe_vsync),
336
        .ne(),
337
        .ee()
338
);
339
 
340
reg [3:0] hc;
341
always @(posedge vclk)
342
if (rst_i)
343
        hc <= 4'd1;
344
else if (pe_hsync) begin
345
        hc <= 4'd1;
346
        pixelCol <= -hrefdelay;
347
end
348
else begin
349
        if (hc==hres) begin
350
                hc <= 4'd1;
351
                pixelCol <= pixelCol + 1;
352
        end
353
        else
354
                hc <= hc + 4'd1;
355
end
356
 
357
reg [3:0] vc;
358
always @(posedge vclk)
359
if (rst_i)
360
        vc <= 4'd1;
361
else if (pe_vsync) begin
362
        vc <= 4'd1;
363
        pixelRow <= -vrefdelay;
364
end
365
else begin
366
        if (pe_hsync) begin
367
                vc <= vc + 4'd1;
368
                if (vc==vres) begin
369
                        vc <= 4'd1;
370
                        pixelRow <= pixelRow + 1;
371
                end
372
        end
373
end
374
 
375
// Bits per pixel minus one.
376
reg [4:0] bpp;
377
always @(color_depth)
378
case(color_depth)
379
BPP6: bpp = 5;
380
BPP8:   bpp = 7;
381
BPP12:  bpp = 11;
382
BPP16:  bpp = 15;
383
BPP24:  bpp = 24;
384
BPP32:  bpp = 31;
385
endcase
386
 
387
reg [4:0] shifts;
388
always @(color_depth)
389
case(color_depth)
390
BPP6:   shifts = 5'd21;
391
BPP8:   shifts = 5'd16;
392
BPP12:  shifts = 5'd10;
393
BPP16:  shifts = 5'd8;
394
BPP24:  shifts = 5'd5;
395
BPP32:  shifts = 5'd4;
396
default:  shifts = 5'd16;
397
endcase
398
 
399
wire vFetch = pixelRow < vDisplayed;
400
wire fifo_rrst = pixelCol==12'hFFF;
401
wire fifo_wrst = pe_hsync2;
402
 
403
wire[31:0] grAddr,xyAddr;
404
reg [11:0] fetchCol;
405
wire [6:0] mb,me;
406
reg [127:0] mem_strip;
407
wire [127:0] mem_strip_o;
408
wire [31:0] mem_color;
409
 
410
gfx_CalcAddress5 u1
411
(
412
  .clk(m_clk_i),
413
        .base_address_i(baseAddr),
414
        .color_depth_i({1'b0,color_depth}),
415
        .hdisplayed_i(hDisplayed),
416
        .x_coord_i(12'b0),
417
        .y_coord_i(pixelRow),
418
        .address_o(grAddr),
419
        .mb_o(),
420
        .me_o()
421
);
422
 
423
gfx_CalcAddress5 u2
424
(
425
  .clk(m_clk_i),
426
        .base_address_i(baseAddr),
427
        .color_depth_i({1'b0,color_depth}),
428
        .hdisplayed_i(hDisplayed),
429
        .x_coord_i(px),
430
        .y_coord_i(py),
431
        .address_o(xyAddr),
432
        .mb_o(mb),
433
        .me_o(me)
434
);
435
 
436
always @(posedge m_clk_i)
437
if (pe_hsync2)
438
  mapctr <= 12'hFFE;
439
else begin
440
  if (mapctr == map)
441
    mapctr <= 12'd0;
442
  else
443
    mapctr <= mapctr + 12'd1;
444
end
445
wire memreq = mapctr==12'd0;
446
 
447
// The following bypasses loading the fifo when all the pixels from a scanline
448
// are buffered in the fifo and the pixel row doesn't change. Since the fifo
449
// pointers are reset at the beginning of a scanline, the fifo can be used like
450
// a cache.
451
wire blankEdge;
452
edge_det ed2(.rst(rst_i), .clk(m_clk_i), .ce(1'b1), .i(blank), .pe(blankEdge), .ne(), .ee() );
453
reg do_loads;
454
reg [11:0] opixelRow;
455
reg load_fifo;
456
always @(posedge m_clk_i)
457
        //load_fifo <= fifo_cnt < 10'd1000 && vFetch && onoff && xonoff && !m_cyc_o && do_loads;
458
        load_fifo <= /*fifo_cnt < 8'd224 &&*/ vFetch && onoff && xonoff && fetchCol < hDisplayed && !m_cyc_o && do_loads && memreq;
459
// The following table indicates the number of pixel that will fit into the
460
// video fifo. 
461
reg [11:0] hCmp;
462
always @(color_depth)
463
case(color_depth)
464
BPP6: hCmp = 12'd4095;
465
BPP8:   hCmp = 12'd4095;    // must be 12 bits
466
BPP12:  hCmp = 12'd2559;
467
BPP16:  hCmp = 12'd2048;
468
BPP24:  hCmp = 12'd1279;
469
BPP32:  hCmp = 12'd1024;
470
default:        hCmp = 12'd1024;
471
endcase
472
always @(posedge m_clk_i)
473
        // if hDisplayed > hCmp we always load because the fifo isn't large enough to act as a cache.
474
        if (!(hDisplayed < hCmp))
475
                do_loads <= 1'b1;
476
        // otherwise load the fifo only when the row changes to conserve memory bandwidth
477
        else if (vc==4'd1)//pixelRow != opixelRow)
478
                do_loads <= 1'b1;
479
        else if (blankEdge)
480
                do_loads <= 1'b0;
481
 
482
assign m_bte_o = 2'b00;
483
assign m_cti_o = 3'b000;
484
assign m_stb_o = 1'b1;
485
assign m_sel_o = 16'hFFFF;
486
 
487
reg [31:0] adr;
488
reg [3:0] state;
489
reg [127:0] icolor1;
490
parameter IDLE = 4'd1;
491
parameter LOADCOLOR = 4'd2;
492
parameter LOADSTRIP = 4'd3;
493
parameter STORESTRIP = 4'd4;
494
parameter ACKSTRIP = 4'd5;
495
parameter WAITLOAD = 4'd6;
496
parameter WAITRST = 4'd7;
497
parameter ICOLOR1 = 4'd8;
498
parameter ICOLOR2 = 4'd9;
499
parameter ICOLOR3 = 4'd10;
500
parameter ICOLOR4 = 4'd11;
501
parameter CYC = 4'd12;
502
parameter CYC1 = 4'd13;
503
 
504
function rastop;
505
input [3:0] op;
506
input a;
507
input b;
508
case(op)
509
OPBLACK: rastop = 1'b0;
510
OPCOPY:  rastop = b;
511
OPINV:   rastop = ~a;
512
OPAND:   rastop = a & b;
513
OPOR:    rastop = a | b;
514
OPXOR:   rastop = a ^ b;
515
OPANDN:  rastop = a & ~b;
516
OPNAND:  rastop = ~(a & b);
517
OPNOR:   rastop = ~(a | b);
518
OPXNOR:  rastop = ~(a ^ b);
519
OPORN:   rastop = a | ~b;
520
OPWHITE: rastop = 1'b1;
521
endcase
522
endfunction
523
 
524
always @(posedge m_clk_i)
525
        if (fifo_wrst)
526
                adr <= grAddr;
527
  else begin
528
    if (state==WAITLOAD && m_ack_i)
529
      adr <= adr + 32'd16;
530
  end
531
 
532
always @(posedge m_clk_i)
533
        if (fifo_wrst)
534
                fetchCol <= 12'd0;
535
  else begin
536
    if (state==WAITLOAD && m_ack_i)
537
      fetchCol <= fetchCol + shifts;
538
  end
539
 
540
always @(posedge m_clk_i)
541
if (rst_i) begin
542
        wb_nack();
543
  rstcmd <= 1'b0;
544
  state <= IDLE;
545
end
546
else begin
547
        case(state)
548
  WAITRST:
549
    if (pcmd==2'b00) begin
550
      rstcmd <= 1'b0;
551
      state <= IDLE;
552
    end
553
    else
554
      rstcmd <= 1'b1;
555
  IDLE:
556
    if (load_fifo) begin
557
      if (!EXTRA_SUT) begin
558
        m_cyc_o <= 1'b1;
559
        state <= WAITLOAD;
560
      end
561
      else
562
        state <= CYC1;
563
      m_we_o <= 1'b0;
564
      m_adr_o <= adr;
565
    end
566
    // The adr_o[5:4]==2'b11 causes the controller to wait until all four
567
    // 128 bit strips from the memory controller have been processed. Otherwise
568
    // there would be cache thrashing in the memory controller and the memory
569
    // bandwidth available would be greatly reduced. However fetches are also
570
    // allowed when loads are not active or all strips for the current scan-
571
    // line have been fetched.
572
    else if (pcmd!=2'b00 && (m_adr_o[5:4]==2'b11 || !(vFetch && onoff && xonoff && fetchCol < hDisplayed) || !do_loads)) begin
573
      m_we_o <= 1'b0;
574
      m_adr_o <= xyAddr;
575
      if (!EXTRA_SUT) begin
576
        m_cyc_o <= 1'b1;
577
        state <= LOADSTRIP;
578
      end
579
      else
580
        state <= CYC;
581
    end
582
  CYC1:
583
    begin
584
      m_cyc_o <= 1'b1;
585
      state <= WAITLOAD;
586
    end
587
  CYC:
588
    begin
589
      m_cyc_o <= 1'b1;
590
      state <= LOADSTRIP;
591
    end
592
  LOADSTRIP:
593
    if (m_ack_i) begin
594
      wb_nack();
595
      mem_strip <= m_dat_i;
596
      icolor1 <= {96'b0,color} << mb;
597
      rstcmd <= 1'b1;
598
      if (pcmd==2'b01)
599
        state <= ICOLOR3;
600
      else if (pcmd==2'b10)
601
        state <= ICOLOR2;
602
      else begin
603
        state <= WAITRST;
604
      end
605
    end
606
  // Registered inline mem2color
607
  ICOLOR3:
608
    begin
609
      color_o <= mem_strip >> mb;
610
      state <= ICOLOR4;
611
    end
612
  ICOLOR4:
613
    begin
614
      for (n = 0; n < 32; n = n + 1)
615
        color_o[n] <= (n <= bpp) ? color_o[n] : 1'b0;
616
      state <= pcmd == 2'b0 ? IDLE : WAITRST;
617
      if (pcmd==2'b00)
618
        rstcmd <= 1'b0;
619
    end
620
  // Registered inline color2mem
621
  ICOLOR2:
622
    begin
623
      for (n = 0; n < 128; n = n + 1)
624
        m_dat_o[n] <= (n >= mb && n <= me) ? rastop(raster_op, mem_strip[n], icolor1[n]) : mem_strip[n];
625
      state <= STORESTRIP;
626
    end
627
  STORESTRIP:
628
    begin
629
      m_cyc_o <= 1'b1;
630
      m_we_o <= 1'b1;
631
      state <= ACKSTRIP;
632
    end
633
  ACKSTRIP:
634
    if (m_ack_i) begin
635
      wb_nack();
636
      state <= pcmd == 2'b0 ? IDLE : WAITRST;
637
      if (pcmd==2'b00)
638
        rstcmd <= 1'b0;
639
    end
640
  WAITLOAD:
641
    if (m_ack_i) begin
642
      wb_nack();
643
      state <= IDLE;
644
    end
645
  endcase
646
end
647
 
648
task wb_nack;
649
begin
650
        m_cyc_o <= 1'b0;
651
        m_we_o <= 1'b0;
652
end
653
endtask
654
 
655
reg [11:0] pixelColD1;
656
reg [23:0] rgbo2,rgbo4;
657
reg [127:0] rgbo3;
658
reg [3:0] plane;
659
always @(posedge vclk)
660
case(color_depth)
661
BPP6:   rgbo4 <= {2'b0,rgbo3[5:0]};      // feeds into palette
662
BPP8:   rgbo4 <= rgbo3[7:0];             // feeds into palette
663
BPP12:  rgbo4 <= {rgbo3[8:6],5'b0,rgbo3[5:3],5'b0,rgbo3[2:0],5'b0};
664
BPP16:  rgbo4 <= {rgbo3[11:8],4'b0,rgbo3[7:4],4'b0,rgbo3[3:0],4'b0};
665
BPP24:  rgbo4 <= {rgbo3[20:14],1'b0,rgbo3[13:7],1'b0,rgbo3[6:0],1'b0};
666
BPP32:  rgbo4 <= rgbo3[23:0];
667
endcase
668
 
669
always @(posedge vclk)
670
case(color_depth)
671
BPP12:  plane <= {rgbo3[11:9],1'b0};
672
BPP16:  plane <= rgbo3[15:12];
673
BPP24:  plane <= rgbo3[24:21];
674
BPP32:  plane <= rgbo3[31:28];
675
default:        plane <= 4'd0;
676
endcase
677
 
678
reg rd_fifo,rd_fifo1,rd_fifo2;
679
reg de;
680
always @(posedge vclk)
681
        if (rd_fifo1)
682
                de <= ~blank;
683
 
684
always @(posedge vclk)
685
        if (onoff && xonoff && !blank) begin
686
                if (color_depth[2:1]==2'b00) begin
687
                        if (!greyscale)
688
                                rgbo <= pal_o[23:0];
689
                        else
690
                                rgbo <= {3{pal_o[7:0]}};
691
                        rgbPlane_o <= pal_o[31:28];
692
                end
693
                else begin
694
                        rgbo <= rgbo4[23:0];
695
                        rgbPlane_o <= plane;
696
                end
697
        end
698
        else begin
699
                rgbo <= 24'd0;
700
                rgbPlane_o <= 4'hF;
701
        end
702
 
703
// Before the hrefdelay expires, pixelCol will be negative, which is greater
704
// than hDisplayed as the value is unsigned. That means that fifo reading is
705
// active only during the display area 0 to hDisplayed.
706
wire shift1 = hc==hres;
707
reg [4:0] shift_cnt;
708
always @(posedge vclk)
709
if (pe_hsync)
710
        shift_cnt <= 5'd1;
711
else begin
712
        if (shift1) begin
713
                if (pixelCol==12'hFFF)
714
                        shift_cnt <= shifts;
715
                else if (!pixelCol[11]) begin
716
                        shift_cnt <= shift_cnt + 5'd1;
717
                        if (shift_cnt==shifts)
718
                                shift_cnt <= 5'd1;
719
                end
720
                else
721
                        shift_cnt <= 5'd1;
722
        end
723
end
724
 
725
wire next_strip = (shift_cnt==shifts) && (hc==hres);
726
 
727
wire vrd;
728
always @(posedge vclk) pixelColD1 <= pixelCol;
729
reg shift,shift2;
730
always @(posedge vclk) shift2 <= shift1;
731
always @(posedge vclk) shift <= shift2;
732
always @(posedge vclk) rd_fifo2 <= next_strip;
733
always @(posedge vclk) rd_fifo <= rd_fifo2;
734
always @(posedge vclk)
735
        if (rd_fifo)
736
                rgbo3 <= rgbo1;
737
        else if (shift) begin
738
                case(color_depth)
739
                BPP6:   rgbo3 <= {rgbo3[127:6]};
740
                BPP8:   rgbo3 <= {rgbo3[127:8]};
741
                BPP12:  rgbo3 <= {rgbo3[127:12]};
742
                BPP16:  rgbo3 <= {rgbo3[127:16]};
743
                BPP24:  rgbo3 <= {rgbo3[127:25]};
744
                BPP32:  rgbo3 <= {rgbo3[127:32]};
745
                endcase
746
        end
747
 
748
 
749
/* Debugging
750
wire [127:0] dat;
751
assign dat[11:0] = pixelRow[0] ? 12'hEA4 : 12'h000;
752
assign dat[23:12] = pixelRow[1] ? 12'hEA4 : 12'h000;
753
assign dat[35:24] = pixelRow[2] ? 12'hEA4 : 12'h000;
754
assign dat[47:36] = pixelRow[3] ? 12'hEA4 : 12'h000;
755
assign dat[59:48] = pixelRow[4] ? 12'hEA4 : 12'h000;
756
assign dat[71:60] = pixelRow[5] ? 12'hEA4 : 12'h000;
757
assign dat[83:72] = pixelRow[6] ? 12'hEA4 : 12'h000;
758
assign dat[95:84] = pixelRow[7] ? 12'hEA4 : 12'h000;
759
assign dat[107:96] = pixelRow[8] ? 12'hEA4 : 12'h000;
760
assign dat[119:108] = pixelRow[9] ? 12'hEA4 : 12'h000;
761
*/
762
 
763
rtfVideoFifo3 uf1
764
(
765
        .wrst(fifo_wrst),
766
        .wclk(m_clk_i),
767
        .wr(m_ack_i && state==WAITLOAD),
768
        .di(m_dat_i),
769
        .rrst(fifo_rrst),
770
        .rclk(vclk),
771
        .rd(rd_fifo),
772
        .dout(rgbo1),
773
        .cnt(fifo_cnt)
774
);
775
 
776
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.