Subversion Repositories pentevo

Rev

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

  1. // ZX-Evo Base Configuration (c) NedoPC 2008,2009,2010,2011,2012,2013,2014
  2. //
  3. // mix up border and pixels, add palette and blanks
  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_palframe(
  27.  
  28.         input  wire        clk, // 28MHz clock
  29.  
  30.  
  31.         input  wire        hpix,
  32.         input  wire        vpix,
  33.  
  34.         input  wire        hblank,
  35.         input  wire        vblank,
  36.  
  37.         input  wire        hsync_start,
  38.         input  wire        vsync,
  39.  
  40.         input  wire [ 3:0] pixels,
  41.         input  wire [ 3:0] border,
  42.  
  43.         // ulaplus related
  44.         input  wire [ 1:0] up_palsel,
  45.         input  wire [ 2:0] up_paper,
  46.         input  wire [ 2:0] up_ink,
  47.         input  wire        up_pixel,
  48.  
  49.         input  wire        up_ena,
  50.         input  wire        up_palwr,
  51.         input  wire [ 5:0] up_paladdr,
  52.         input  wire [ 7:0] up_paldata,
  53.  
  54.         input  wire        atm_palwr,
  55.         input  wire [ 5:0] atm_paldata,
  56.  
  57.  
  58.         output wire [ 5:0] palcolor, // just for palette readback
  59.  
  60.         output wire [ 5:0] color
  61. );
  62.         reg [7:0] palette_read;
  63.  
  64.         wire [ 3:0] zxcolor;
  65.         wire [ 5:0] up_color;
  66.         wire [ 8:0] palette_color;
  67.  
  68.         reg vsync_r;
  69.         reg [1:0] ctr_14;
  70.         reg ctr_h;
  71.         reg ctr_v;
  72.  
  73.         assign zxcolor = (hpix&vpix) ? pixels : border;
  74.  
  75.         assign up_color = (hpix&vpix) ? {up_palsel,~up_pixel,up_pixel?up_ink:up_paper} : {3'd0,border[2:0]};
  76.  
  77.         assign palette_color = up_ena ? {3'b100,up_color} : {5'd0,zxcolor};
  78.  
  79.  
  80.         // palette
  81.         reg [7:0] palette [0:511]; // let quartus instantiate it as RAM
  82.  
  83.         always @(posedge clk)
  84.         begin
  85.                 if( atm_palwr || up_palwr )
  86.                 begin : palette_write
  87.                         reg [8:0] pal_addr;
  88.                         pal_addr = atm_palwr ? { 5'd0, zxcolor } : { 3'b100, up_paladdr };
  89.  
  90.                         palette[pal_addr] <= atm_palwr ? {atm_paldata[3:2],1'b0,atm_paldata[5:4],1'b0,atm_paldata[1:0]} : up_paldata;
  91.                 end
  92.  
  93.                 palette_read <= palette[palette_color];
  94.         end
  95.  
  96.  
  97.         assign palcolor = {palette_read[4:3],palette_read[7:6], palette_read[1:0]};
  98.  
  99.  
  100.  
  101.  
  102.         // make 3bit palette
  103.         always @(posedge clk)
  104.                 vsync_r <= vsync;
  105.         //
  106.         wire vsync_start = vsync && !vsync_r;
  107.         //
  108.         initial ctr_14 = 2'b00;
  109.         always @(posedge clk)
  110.                 ctr_14 <= ctr_14+2'b01;
  111.         //
  112.         initial ctr_h = 1'b0;
  113.         always @(posedge clk) if( hsync_start )
  114.                 ctr_h <= ~ctr_h;
  115.         //
  116.         initial ctr_v = 1'b0;
  117.         always @(posedge clk) if( vsync_start )
  118.                 ctr_v <= ~ctr_v;
  119.  
  120.  
  121.         wire plus1 = ctr_14[1] ^ ctr_h ^ ctr_v;
  122.  
  123.  
  124.  
  125.         wire [1:0] red;
  126.         wire [1:0] grn;
  127.         wire [1:0] blu;
  128.  
  129.         video_palframe_mk3bit red_color
  130.         (
  131.                 .plus1    (plus1            ),
  132.                 .color_in (palette_read[7:5]),
  133.                 .color_out(red              )
  134.         );
  135.         //
  136.         video_palframe_mk3bit grn_color
  137.         (
  138.                 .plus1    (plus1            ),
  139.                 .color_in (palette_read[4:2]),
  140.                 .color_out(grn              )
  141.         );
  142.         //
  143.         assign blu = palette_read[1:0];
  144.  
  145.         assign color = (hblank | vblank) ? 6'd0 : {grn,red,blu};
  146.  
  147.  
  148. endmodule
  149.  
  150. module video_palframe_mk3bit
  151. (
  152.         input  wire       plus1,
  153.  
  154.         input  wire [2:0] color_in,
  155.         output reg  [1:0] color_out
  156. );
  157.  
  158.         always @*
  159.         case( color_in )
  160.                 3'b000:  color_out <= 2'b00;
  161.                 3'b001:  color_out <= plus1 ? 2'b01 : 2'b00;
  162.                 3'b010:  color_out <= 2'b01;
  163.                 3'b011:  color_out <= plus1 ? 2'b10 : 2'b01;
  164.                 3'b100:  color_out <= 2'b10;
  165.                 3'b101:  color_out <= plus1 ? 2'b11 : 2'b10;
  166.                 default: color_out <= 2'b11;
  167.         endcase
  168.  
  169. endmodule
  170.  
  171.