Subversion Repositories pentevo

Rev

Rev 972 | Rev 1033 | 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.         input  wire        border_sync,
  44.         input  wire        border_sync_ena,
  45.  
  46.         // ulaplus related
  47.         input  wire [ 1:0] up_palsel,
  48.         input  wire [ 2:0] up_paper,
  49.         input  wire [ 2:0] up_ink,
  50.         input  wire        up_pixel,
  51.  
  52.         input  wire        up_ena,
  53.         input  wire        up_palwr,
  54.         input  wire [ 5:0] up_paladdr,
  55.         input  wire [ 7:0] up_paldata,
  56.  
  57.         input  wire        atm_palwr,
  58.         input  wire [ 5:0] atm_paldata,
  59.         input  wire [ 5:0] atm_paldatalow,
  60.         input  wire        pal444_ena,
  61.  
  62.  
  63.         output wire [ 5:0] palcolor, // just for palette readback
  64.  
  65.         output wire [ 5:0] color
  66. );
  67.         reg [11/*7*/:0] palette_read;  
  68.  
  69.         wire [ 3:0] zxcolor;
  70.         wire [ 5:0] up_color;
  71.         wire [ /*8*/7:0] palette_color;
  72.  
  73.         reg [3:0] synced_border;
  74.  
  75.         reg vsync_r;
  76.         reg [2:0/*1:0*/] ctr_14;
  77.         reg ctr_h;
  78.         //reg ctr_v;
  79.         reg [1:0] phase; //frame number
  80.  
  81.  
  82.         always @(posedge clk)
  83.         if( border_sync )
  84.                 synced_border <= border;
  85.  
  86.         assign zxcolor = (hpix&vpix) ? pixels : (border_sync_ena ? synced_border : border);
  87.  
  88.         assign up_color = (hpix&vpix) ? {up_palsel,~up_pixel,up_pixel?up_ink:up_paper} : {3'd0,border[2:0]};
  89.  
  90.         assign palette_color = up_ena ? {/*3'b100*/2'b10,up_color} : {/*5'd0*/4'd0,zxcolor};
  91.  
  92.  
  93.         // palette
  94.         reg [/*7*/11:0] palette [0:/*511*/255]; // let quartus instantiate it as RAM
  95.  
  96.         always @(posedge clk)
  97.         begin
  98.                 if( atm_palwr || up_palwr )
  99.                 begin : palette_write
  100.                         reg [8:0] pal_addr;
  101.                         pal_addr = atm_palwr ? { 5'd0, zxcolor } : { 3'b100, up_paladdr };
  102.  
  103.                         palette[pal_addr] <= atm_palwr ?
  104.                                              {atm_paldata[3:2],pal444_ena?atm_paldatalow[3:2]:atm_paldata[3:2],
  105.                                               atm_paldata[5:4],pal444_ena?atm_paldatalow[5:4]:atm_paldata[5:4],
  106.                                               atm_paldata[1:0],pal444_ena?atm_paldatalow[1:0]:atm_paldata[1:0]
  107.                                              }
  108.                                            : up_paldata;
  109.                 end
  110.  
  111.                 palette_read <= palette[palette_color];
  112.         end
  113.  
  114.  
  115.         assign palcolor = pal444_ena?
  116.                           {palette_read[5:4],palette_read[9:8], palette_read[1:0]}
  117.                          :{palette_read[7:6/*4:3*/],palette_read[11:10/*7:6*/], palette_read[3:2/*1:0*/]};
  118.  
  119.  
  120.  
  121.  
  122.         // make 3bit palette
  123.         always @(posedge clk)
  124.                 vsync_r <= vsync;
  125.         //
  126.         wire vsync_start = vsync && !vsync_r;
  127.         //
  128.         initial ctr_14 = 3'b000;
  129.         always @(posedge clk)
  130.                 ctr_14 <= ctr_14+3'b001;
  131.         //
  132.         initial ctr_h = 1'b0;
  133.         always @(posedge clk) if( hsync_start )
  134.                 ctr_h <= ~ctr_h;
  135.         //
  136.         //initial ctr_v = 1'b0;
  137.         //always @(posedge clk) if( vsync_start )
  138.         //      ctr_v <= ~ctr_v;
  139.         //
  140.         initial phase = 2'b00;
  141.         always @(posedge clk) if( vsync_start )
  142.                 phase <= phase+2'b01;
  143.  
  144.         //wire plus1 = ctr_14[1] ^ ctr_h ^ ctr_v;
  145.  
  146.  
  147.  
  148.         wire [1:0] red;
  149.         wire [1:0] grn;
  150.         wire [1:0] blu;
  151.  
  152.         wire bigpal_ena = up_ena | pal444_ena;
  153.  
  154.         video_palframe_mk3bit red_color
  155.         (
  156.                 //.plus1    (plus1            ),
  157.                 .phase    (phase),
  158.                 .x        (ctr_14[2:1]      ),
  159.                 .y        (ctr_h            ),
  160.                 .color_in (palette_read[11:8/*7:5*/]),
  161.                 .color_out(red              )
  162.         );
  163.         //
  164.         video_palframe_mk3bit grn_color
  165.         (
  166.                 //.plus1    (plus1            ),
  167.                 .phase    (phase),
  168.                 .x        (ctr_14[2:1]      ),
  169.                 .y        (ctr_h            ),
  170.                 .color_in (palette_read[7:4/*4:2*/]),
  171.                 .color_out(grn              )
  172.         );
  173.         //
  174.         video_palframe_mk3bit blu_color
  175.         (
  176.                 //.plus1    (plus1            ),
  177.                 .phase    (phase),
  178.                 .x        (ctr_14[2:1]      ),
  179.                 .y        (ctr_h            ),
  180.                 .color_in (palette_read[3:0/*4:2*/]),
  181.                 .color_out(blu              )
  182.         );
  183.         //
  184.         //assign blu = palette_read[1:0];
  185.  
  186.         assign color = (hblank | vblank) ? 6'd0 : {grn,red,blu};
  187.  
  188.  
  189. endmodule
  190.  
  191.  
  192. module video_palframe_mk3bit
  193. (
  194.         //input  wire       plus1,
  195.         input  wire [1:0] phase,
  196.         input  wire [1:0] x,
  197.         input  wire       y,
  198.  
  199.         input  wire [3:0/*2:0*/] color_in,
  200.         output reg  [1:0] color_out
  201. );
  202. wire [3:0] colorlevel;
  203. wire [1:0] gridlevel;
  204. wire       gridy;
  205. wire [1:0] gridindex;
  206.  
  207.         always @*
  208.         begin
  209.  
  210. //colorlevel_table[3:0] = {0,1,2,2,3, 4,5,6,6,7, 8,9,10,10,11, 12};
  211.           case( color_in )
  212. /*              3'b000:  color_out <= 2'b00;
  213.                 3'b001:  color_out <= plus1 ? 2'b01 : 2'b00;
  214.                 3'b010:  color_out <= 2'b01;
  215.                 3'b011:  color_out <= plus1 ? 2'b10 : 2'b01;
  216.                 3'b100:  color_out <= 2'b10;
  217.                 3'b101:  color_out <= plus1 ? 2'b11 : 2'b10;
  218.                 default: color_out <= 2'b11;
  219.                 */
  220.                 4'b0000: colorlevel = 4'b0000;
  221.                 4'b0001: colorlevel = 4'b0001;
  222.                 4'b0010,
  223.                 4'b0011: colorlevel = 4'b0010;
  224.                 4'b0100: colorlevel = 4'b0011;
  225.  
  226.                 4'b0101: colorlevel = 4'b0100;
  227.                 4'b0110: colorlevel = 4'b0101;
  228.                 4'b0111,
  229.                 4'b1000: colorlevel = 4'b0110;
  230.                 4'b1001: colorlevel = 4'b0111;
  231.  
  232.                 4'b1010: colorlevel = 4'b1000;
  233.                 4'b1011: colorlevel = 4'b1001;
  234.                 4'b1100,
  235.                 4'b1101: colorlevel = 4'b1010;
  236.                 4'b1110: colorlevel = 4'b1011;
  237.  
  238.                 default: colorlevel = 4'b1100;
  239.           endcase
  240.  
  241. //яюёъюы№ъє ь√ эр тїюфх ёърэфрсыхЁр, Єю яюфєЁютэш 1/4 ш 3/4 ьхцфє уыртэ√ьш єЁютэ ьш сєфєЄ ёърърЄ№ цшЁэ√ьш ышэш ьш
  242. //Їшъёшь ¤Єю ёфтшуюь Їрч√ y яю ъёюЁє ё x[1] шьхээю фы  ¤Єшї яюфєЁютэхщ (фы  1/2 Єръющ Їшъё ёыюьрхЄ ёхЄъє)
  243. //colorlevel_grid = {{0,2},{3,1}};
  244.           gridy = y ^ (x[1] & colorlevel[0]);
  245.           gridindex = {gridy+phase[1], x[0]+phase[0]};
  246.           case(gridindex[1:0])
  247.             2'b00: gridlevel = 2'b00;
  248.             2'b01: gridlevel = 2'b10;
  249.             2'b10: gridlevel = 2'b11;
  250.             2'b11: gridlevel = 2'b01;
  251.           endcase
  252.        
  253.           color_out = colorlevel[3:2] + ((colorlevel[1:0] > gridlevel[1:0]) ? 2'b01 : 2'b00);
  254.         end
  255.  
  256. endmodule
  257.  
  258.