Subversion Repositories pentevo

Rev

Rev 395 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. `include "../include/tune.v"
  2.  
  3. // Pentevo project (c) NedoPC 2011
  4. //
  5. // renders fetched video data to the pixels
  6.  
  7. module video_render(
  8.  
  9.         input  wire        clk, // 28 MHz clock
  10.  
  11.  
  12.         input  wire [63:0] pic_bits, // video data from fetcher
  13.  
  14.         input  wire        fetch_sync, // synchronizes pixel rendering -
  15.                                        // coincides with cbeg!!!
  16.  
  17.         input  wire        cbeg,
  18.         input  wire        post_cbeg, // pixel strobed and
  19.         input  wire        pre_cend,
  20.         input  wire        cend,      // general sync
  21.  
  22.         input  wire        int_start, // for flash gen
  23.  
  24.         input  wire [ 2:0] typos, // Y pos in text symbols
  25.  
  26.         output wire [ 3:0] pixels, // output pixels
  27.  
  28.  
  29.  
  30.         input  wire [10:0] fnt_a,
  31.         input  wire [ 7:0] fnt_d,
  32.         input  wire        fnt_wr,
  33.  
  34.  
  35.  
  36.  
  37.         input  wire        mode_atm_n_pent, // decoded modes
  38.  
  39.         input  wire        mode_zx,         //
  40.         input  wire        mode_p_16c,      //
  41.         input  wire        mode_p_hmclr,    //
  42.                                             //
  43.         input  wire        mode_a_hmclr,    //
  44.         input  wire        mode_a_16c,      //
  45.         input  wire        mode_a_text,     //
  46.  
  47.         input  wire        mode_pixf_14     //
  48. );
  49.  
  50.  
  51.         reg [4:0] flash_ctr;
  52.         wire flash;
  53.  
  54.         initial
  55.         begin
  56.                 flash_ctr = 0;
  57.         end
  58.  
  59.         always @(posedge clk) if( int_start )
  60.         begin
  61.                 flash_ctr <= flash_ctr + 1;
  62.         end
  63.         assign flash = flash_ctr[4];
  64.  
  65.  
  66.  
  67.  
  68.  
  69.         // fetched data divided in bytes
  70.         wire [7:0] bits [0:7];
  71.  
  72.         assign bits[0] = pic_bits[ 7:0 ];
  73.         assign bits[1] = pic_bits[15:8 ];
  74.         assign bits[2] = pic_bits[23:16];
  75.         assign bits[3] = pic_bits[31:24];
  76.         assign bits[4] = pic_bits[39:32];
  77.         assign bits[5] = pic_bits[47:40];
  78.         assign bits[6] = pic_bits[55:48];
  79.         assign bits[7] = pic_bits[63:56];
  80.  
  81.  
  82.  
  83.         reg [1:0] gnum; // pixel group number
  84.         reg [2:0] pnum; // pixel number
  85.         wire [1:0] gadd;
  86.         wire [2:0] padd;
  87.         wire ginc;
  88.  
  89.         wire modes_16c;
  90.  
  91.         wire modes_zxattr;
  92.  
  93.  
  94.         wire   ena_pix;
  95.         assign ena_pix = cend | (mode_pixf_14 & post_cbeg);
  96.  
  97.  
  98.         assign modes_16c = mode_p_16c | mode_a_16c;
  99.  
  100.         assign modes_zxattr = mode_zx | mode_p_hmclr;
  101.  
  102.         assign {ginc, padd} = {1'b0, pnum} + {2'b00, modes_16c, ~modes_16c};
  103.  
  104.         always @(posedge clk) if( ena_pix )
  105.         if( fetch_sync )
  106.                 pnum <= 3'b000;
  107.         else
  108.                 pnum <= padd;
  109.  
  110.  
  111.         assign gadd = gnum + ( {modes_zxattr,~modes_zxattr} & {2{ginc}} );
  112.  
  113.         always @(posedge clk) if( ena_pix )
  114.         if( fetch_sync )
  115.                 gnum <= 2'b00;
  116.         else
  117.                 gnum <= gadd;
  118.  
  119.  
  120.  
  121.  
  122.         wire [15:0] pgroup; // pixel group
  123.         wire [7:0] pixbyte, symbyte, attrbyte;
  124.         wire [7:0] pix16_2 [0:1];
  125.         wire [3:0] pix16   [0:3];
  126.  
  127.         wire pixbit; // pixel bit, for attr modes
  128.         wire [3:0] pix0, pix1; // colors for bit=0 and bit=1, for attr modes
  129.  
  130.         wire [3:0] apix, c16pix;
  131.  
  132.  
  133.         assign pgroup = { bits[ {gnum[0], 1'b0, gnum[1]} ] ,
  134.                           bits[ {gnum[0], 1'b1, gnum[1]} ] };
  135.  
  136.         assign pixbyte  = pgroup[15:8];
  137.         assign attrbyte = pgroup[ 7:0];
  138.  
  139.  
  140.         assign pix16_2[0] = pgroup[ 7:0];
  141.         assign pix16_2[1] = pgroup[15:8];
  142.  
  143.         assign pix16[0] = { pix16_2[0][6], pix16_2[0][2:0] };
  144.         assign pix16[1] = { pix16_2[0][7], pix16_2[0][5:3] };
  145.         assign pix16[2] = { pix16_2[1][6], pix16_2[1][2:0] };
  146.         assign pix16[3] = { pix16_2[1][7], pix16_2[1][5:3] };
  147.  
  148.  
  149.         assign pixbit = mode_a_text ? symbyte[~pnum] : pixbyte[~pnum];
  150.  
  151.         assign pix0 = { (modes_zxattr ? attrbyte[6] : attrbyte[7]), attrbyte[5:3] }; // paper
  152.         assign pix1 = { attrbyte[6], attrbyte[2:0] }; // ink
  153.  
  154.  
  155.         assign apix = ( pixbit^(modes_zxattr & flash & attrbyte[7]) ) ? pix1 : pix0;
  156.  
  157.         assign c16pix = pix16[ pnum[2:1] ];
  158.  
  159.  
  160.  
  161.         assign pixels = modes_16c ? c16pix : apix;
  162.  
  163.  
  164.  
  165.  
  166.         wire rom_ena;
  167.         assign rom_ena = ena_pix & ginc;
  168.  
  169.         video_fontrom video_fontrom(
  170.  
  171.                 .clock (clk ),
  172.                 /*.enable(1'b1),*/
  173.  
  174.                 .data     (fnt_d ),
  175.                 .wraddress(fnt_a ),
  176.                 .wren     (fnt_wr),
  177.  
  178.                 .rdaddress( {pixbyte, typos} ),
  179.                 .rden     ( rom_ena          ),
  180.                 .q        ( symbyte          )
  181.         );
  182.  
  183.  
  184. endmodule
  185.  
  186.