Subversion Repositories pentevo

Rev

Rev 896 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed | ?url?

  1. // ZX-Evo Base Configuration (c) NedoPC 2008,2009,2010,2011,2012,2013,2014
  2. //
  3. // renders fetched video data to the pixels
  4.  
  5. /*
  6.     This file is part of ZX-Evo Base Configuration firmware.
  7.  
  8.     ZX-Evo Base Configuration firmware is free software:
  9.     you can redistribute it and/or modify it under the terms of
  10.     the GNU General Public License as published by
  11.     the Free Software Foundation, either version 3 of the License, or
  12.     (at your option) any later version.
  13.  
  14.     ZX-Evo Base Configuration firmware is distributed in the hope that
  15.     it will be useful, but WITHOUT ANY WARRANTY; without even
  16.     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  17.     See the GNU General Public License for more details.
  18.  
  19.     You should have received a copy of the GNU General Public License
  20.     along with ZX-Evo Base Configuration firmware.
  21.     If not, see <http://www.gnu.org/licenses/>.
  22. */
  23.  
  24. `include "../include/tune.v"
  25.  
  26. module video_render(
  27.  
  28.         input  wire        clk, // 28 MHz clock
  29.  
  30.  
  31.         input  wire [63:0] pic_bits, // video data from fetcher
  32.  
  33.         input  wire        fetch_sync, // synchronizes pixel rendering -
  34.                                        // coincides with cbeg!!!
  35.  
  36.         input  wire        cbeg,
  37.         input  wire        post_cbeg, // pixel strobed and
  38.         input  wire        pre_cend,
  39.         input  wire        cend,      // general sync
  40.  
  41.         input  wire        int_start, // for flash gen
  42.  
  43.         input  wire [ 2:0] typos, // Y pos in text symbols
  44.  
  45.         output wire [ 3:0] pixels, // output pixels
  46.  
  47.         // ulaplus related
  48.         output wire [ 1:0] up_palsel,
  49.         output wire [ 2:0] up_paper,
  50.         output wire [ 2:0] up_ink,
  51.         output wire        up_pixel,
  52.  
  53.  
  54.         input  wire [10:0] fnt_a,
  55.         input  wire [ 7:0] fnt_d,
  56.         input  wire        fnt_wr,
  57.  
  58.  
  59.  
  60.  
  61.         input  wire        mode_atm_n_pent, // decoded modes
  62.  
  63.         input  wire        mode_zx,         //
  64.         input  wire        mode_p_16c,      //
  65.         input  wire        mode_p_hmclr,    //
  66.                                             //
  67.         input  wire        mode_a_hmclr,    //
  68.         input  wire        mode_a_16c,      //
  69.         input  wire        mode_a_text,     //
  70.  
  71.         input  wire        mode_pixf_14,    //
  72.  
  73.  
  74.         output wire [ 7:0] fontrom_readback
  75. );
  76.  
  77.  
  78.         reg [4:0] flash_ctr;
  79.         wire flash;
  80.  
  81.         initial
  82.         begin
  83.                 flash_ctr = 0;
  84.         end
  85.  
  86.         always @(posedge clk) if( int_start )
  87.         begin
  88.                 flash_ctr <= flash_ctr + 1;
  89.         end
  90.         assign flash = flash_ctr[4];
  91.  
  92.  
  93.  
  94.  
  95.  
  96.         // fetched data divided in bytes
  97.         wire [7:0] bits [0:7];
  98.  
  99.         assign bits[0] = pic_bits[ 7:0 ];
  100.         assign bits[1] = pic_bits[15:8 ];
  101.         assign bits[2] = pic_bits[23:16];
  102.         assign bits[3] = pic_bits[31:24];
  103.         assign bits[4] = pic_bits[39:32];
  104.         assign bits[5] = pic_bits[47:40];
  105.         assign bits[6] = pic_bits[55:48];
  106.         assign bits[7] = pic_bits[63:56];
  107.  
  108.  
  109.  
  110.         reg [1:0] gnum; // pixel group number
  111.         reg [2:0] pnum; // pixel number
  112.         wire [1:0] gadd;
  113.         wire [2:0] padd;
  114.         wire ginc;
  115.  
  116.         wire modes_16c;
  117.  
  118.         wire modes_zxattr;
  119.  
  120.  
  121.         wire   ena_pix;
  122.         assign ena_pix = cend | (mode_pixf_14 & post_cbeg);
  123.  
  124.  
  125.         assign modes_16c = mode_p_16c | mode_a_16c;
  126.  
  127.         assign modes_zxattr = mode_zx | mode_p_hmclr;
  128.  
  129.         assign {ginc, padd} = {1'b0, pnum} + {2'b00, modes_16c, ~modes_16c};
  130.  
  131.         always @(posedge clk) if( ena_pix )
  132.         if( fetch_sync )
  133.                 pnum <= 3'b000;
  134.         else
  135.                 pnum <= padd;
  136.  
  137.  
  138.         assign gadd = gnum + ( {modes_zxattr,~modes_zxattr} & {2{ginc}} );
  139.  
  140.         always @(posedge clk) if( ena_pix )
  141.         if( fetch_sync )
  142.                 gnum <= 2'b00;
  143.         else
  144.                 gnum <= gadd;
  145.  
  146.  
  147.  
  148.  
  149.         wire [15:0] pgroup; // pixel group
  150.         wire [7:0] pixbyte, symbyte, attrbyte;
  151.         wire [7:0] pix16_2 [0:1];
  152.         wire [3:0] pix16   [0:3];
  153.  
  154.         wire pixbit; // pixel bit, for attr modes
  155.         wire [3:0] pix0, pix1; // colors for bit=0 and bit=1, for attr modes
  156.  
  157.         wire [3:0] apix, c16pix;
  158.  
  159.  
  160.         assign pgroup = { bits[ {gnum[0], 1'b0, gnum[1]} ] ,
  161.                           bits[ {gnum[0], 1'b1, gnum[1]} ] };
  162.  
  163.         assign pixbyte  = pgroup[15:8];
  164.         assign attrbyte = pgroup[ 7:0];
  165.  
  166.  
  167.         assign pix16_2[0] = pgroup[ 7:0];
  168.         assign pix16_2[1] = pgroup[15:8];
  169.  
  170.         assign pix16[0] = { pix16_2[0][6], pix16_2[0][2:0] };
  171.         assign pix16[1] = { pix16_2[0][7], pix16_2[0][5:3] };
  172.         assign pix16[2] = { pix16_2[1][6], pix16_2[1][2:0] };
  173.         assign pix16[3] = { pix16_2[1][7], pix16_2[1][5:3] };
  174.  
  175.  
  176.         assign pixbit = mode_a_text ? symbyte[~pnum] : pixbyte[~pnum];
  177.  
  178.         assign pix0 = { (modes_zxattr ? attrbyte[6] : attrbyte[7]), attrbyte[5:3] }; // paper
  179.         assign pix1 = { attrbyte[6], attrbyte[2:0] }; // ink
  180.  
  181.  
  182.         assign apix = ( pixbit^(modes_zxattr & flash & attrbyte[7]) ) ? pix1 : pix0;
  183.  
  184.         assign c16pix = pix16[ pnum[2:1] ];
  185.  
  186.  
  187.  
  188.         assign pixels = modes_16c ? c16pix : apix;
  189.  
  190.  
  191.  
  192.         // ulaplus signals
  193.         assign up_pixel  = pixbit;
  194.         //
  195.         assign up_palsel = attrbyte[7:6];
  196.         //
  197.         assign up_paper  = attrbyte[5:3];
  198.         assign up_ink    = attrbyte[2:0];
  199.  
  200.  
  201.  
  202.  
  203.         wire rom_ena;
  204.         assign rom_ena = ena_pix & ginc;
  205.  
  206.         video_fontrom video_fontrom(
  207.  
  208.                 .clock (clk ),
  209.                 /*.enable(1'b1),*/
  210.  
  211.                 .data     (fnt_d ),
  212.                 .wraddress(fnt_a ),
  213.                 .wren     (fnt_wr),
  214.  
  215.                 .rdaddress( {pixbyte, typos} ),
  216.                 .rden     ( rom_ena          ),
  217.                 .q        ( symbyte          )
  218.         );
  219.  
  220.  
  221.         assign fontrom_readback = symbyte;
  222.  
  223.  
  224. endmodule
  225.  
  226.