Subversion Repositories pentevo

Rev

Rev 973 | 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.  
  61.         input  wire        pal444_ena,
  62.  
  63.  
  64.  
  65.         output wire [ 5:0] palcolor, // just for palette readback
  66.  
  67.         output wire [ 5:0] color
  68. );
  69.         reg [11/*7*/:0] palette_read;  
  70.  
  71.         wire [ 3:0] zxcolor;
  72.         wire [ 5:0] up_color;
  73.         wire [ /*8*/7:0] palette_color;
  74.  
  75.         reg [3:0] synced_border;
  76.  
  77.         reg vsync_r;
  78.         reg [2:0/*1:0*/] ctr_14;
  79.         reg ctr_h;
  80.         //reg ctr_v;
  81.         reg [1:0] phase; //frame number
  82.  
  83.  
  84.  
  85.         always @(posedge clk)
  86.         if( border_sync )
  87.                 synced_border <= border;
  88.  
  89.         assign zxcolor = (hpix&vpix) ? pixels : (border_sync_ena ? synced_border : border);
  90.  
  91.         assign up_color = (hpix&vpix) ? {up_palsel,~up_pixel,up_pixel?up_ink:up_paper} : {3'd0,border[2:0]};
  92.  
  93.         assign palette_color = up_ena ? {/*3'b100*/2'b10,up_color} : {/*5'd0*/4'd0,zxcolor};
  94.  
  95.  
  96.         // palette
  97.         reg [/*7*/11:0] palette [0:/*511*/255]; // let quartus instantiate it as RAM
  98.  
  99.         always @(posedge clk)
  100.         begin
  101.                 if( atm_palwr || up_palwr )
  102.                 begin : palette_write
  103.                         reg [8:0] pal_addr;
  104.                         pal_addr = atm_palwr ? { 5'd0, zxcolor } : { 3'b100, up_paladdr };
  105.  
  106.                         palette[pal_addr] <= atm_palwr ?
  107.  
  108.                                              {atm_paldata[3:2],pal444_ena?atm_paldatalow[3:2]:atm_paldata[3:2],
  109.  
  110.                                               atm_paldata[5:4],pal444_ena?atm_paldatalow[5:4]:atm_paldata[5:4],
  111.  
  112.                                               atm_paldata[1:0],pal444_ena?atm_paldatalow[1:0]:atm_paldata[1:0]
  113.  
  114.                                              }
  115.  
  116.                                            : up_paldata;
  117.                 end
  118.  
  119.                 palette_read <= palette[palette_color];
  120.         end
  121.  
  122.  
  123.         assign palcolor = pal444_ena?
  124.  
  125.                           {palette_read[5:4],palette_read[9:8], palette_read[1:0]}
  126.  
  127.                          :{palette_read[7:6/*4:3*/],palette_read[11:10/*7:6*/], palette_read[3:2/*1:0*/]};
  128.  
  129.  
  130.  
  131.  
  132.         // make 3bit palette
  133.         always @(posedge clk)
  134.                 vsync_r <= vsync;
  135.         //
  136.         wire vsync_start = vsync && !vsync_r;
  137.         //
  138.         initial ctr_14 = 3'b000;
  139.         always @(posedge clk)
  140.                 ctr_14 <= ctr_14+3'b001;
  141.         //
  142.         initial ctr_h = 1'b0;
  143.         always @(posedge clk) if( hsync_start )
  144.                 ctr_h <= ~ctr_h;
  145.         //
  146.         //initial ctr_v = 1'b0;
  147.         //always @(posedge clk) if( vsync_start )
  148.         //      ctr_v <= ~ctr_v;
  149.         //
  150.  
  151.         initial phase = 2'b00;
  152.  
  153.         always @(posedge clk) if( vsync_start )
  154.  
  155.                 phase <= phase+2'b01;
  156.  
  157.  
  158.         //wire plus1 = ctr_14[1] ^ ctr_h ^ ctr_v;
  159.  
  160.  
  161.  
  162.  
  163.         wire [1:0] red;
  164.         wire [1:0] grn;
  165.         wire [1:0] blu;
  166.  
  167.  
  168.         wire bigpal_ena = up_ena | pal444_ena;
  169.  
  170.  
  171.         video_palframe_mk3bit red_color
  172.         (
  173.                 //.plus1    (plus1            ),
  174.  
  175.                 .phase    (phase),
  176.  
  177.                 .x        (ctr_14[2:1]      ),
  178.  
  179.                 .y        (ctr_h            ),
  180.  
  181.                 .color_in (palette_read[11:8/*7:5*/]),
  182.                 .color_out(red              )
  183.         );
  184.         //
  185.         video_palframe_mk3bit grn_color
  186.         (
  187.                 //.plus1    (plus1            ),
  188.                 .phase    (phase),
  189.  
  190.                 .x        (ctr_14[2:1]      ),
  191.  
  192.                 .y        (ctr_h            ),
  193.  
  194.                 .color_in (palette_read[7:4/*4:2*/]),
  195.                 .color_out(grn              )
  196.         );
  197.         //
  198.         video_palframe_mk3bit blu_color
  199.  
  200.         (
  201.  
  202.                 //.plus1    (plus1            ),
  203.  
  204.                 .phase    (phase),
  205.  
  206.                 .x        (ctr_14[2:1]      ),
  207.  
  208.                 .y        (ctr_h            ),
  209.  
  210.                 .color_in (palette_read[3:0/*4:2*/]),
  211.  
  212.                 .color_out(blu              )
  213.  
  214.         );
  215.  
  216.         //
  217.  
  218.         //assign blu = palette_read[1:0];
  219.  
  220.         assign color = (hblank | vblank) ? 6'd0 : {grn,red,blu};
  221.  
  222.  
  223. endmodule
  224.  
  225.  
  226.  
  227. module video_palframe_mk3bit
  228. (
  229.         //input  wire       plus1,
  230.         input  wire [1:0] phase,
  231.  
  232.         input  wire [1:0] x,
  233.  
  234.         input  wire       y,
  235.  
  236.  
  237.         input  wire [3:0/*2:0*/] color_in,
  238.         output reg  [1:0] color_out
  239. );
  240.  
  241.         reg [3:0] colorlevel;
  242.         reg [1:0] gridlevel;
  243.  
  244.         reg       gridy;
  245.  
  246.         reg [1:0] gridindex;
  247.  
  248.  
  249.         always @*
  250.  
  251.         begin
  252.  
  253.  
  254. //colorlevel_table[3:0] = {0,1,2,2,3, 4,5,6,6,7, 8,9,10,10,11, 12};
  255.  
  256.           case( color_in )
  257. /*              3'b000:  color_out <= 2'b00;
  258.                 3'b001:  color_out <= plus1 ? 2'b01 : 2'b00;
  259.                 3'b010:  color_out <= 2'b01;
  260.                 3'b011:  color_out <= plus1 ? 2'b10 : 2'b01;
  261.                 3'b100:  color_out <= 2'b10;
  262.                 3'b101:  color_out <= plus1 ? 2'b11 : 2'b10;
  263.  
  264.                 default: color_out <= 2'b11;
  265.  
  266.                 */
  267.  
  268.                 4'b0000: colorlevel = 4'b0000;
  269.                 4'b0001: colorlevel = 4'b0001;
  270.  
  271.                 4'b0010,
  272.  
  273.                 4'b0011: colorlevel = 4'b0010;
  274.  
  275.                 4'b0100: colorlevel = 4'b0011;
  276.  
  277.  
  278.  
  279.                 4'b0101: colorlevel = 4'b0100;
  280.  
  281.                 4'b0110: colorlevel = 4'b0101;
  282.  
  283.                 4'b0111,
  284.  
  285.                 4'b1000: colorlevel = 4'b0110;
  286.  
  287.                 4'b1001: colorlevel = 4'b0111;
  288.  
  289.  
  290.  
  291.                 4'b1010: colorlevel = 4'b1000;
  292.  
  293.                 4'b1011: colorlevel = 4'b1001;
  294.  
  295.                 4'b1100,
  296.  
  297.                 4'b1101: colorlevel = 4'b1010;
  298.  
  299.                 4'b1110: colorlevel = 4'b1011;
  300.  
  301.  
  302.  
  303.                 default: colorlevel = 4'b1100;
  304.  
  305.           endcase
  306.  
  307.  
  308.  
  309. //яюёъюы№ъє ь√ эр тїюфх ёърэфрсыхЁр, Єю яюфєЁютэш 1/4 ш 3/4 ьхцфє уыртэ√ьш єЁютэ ьш сєфєЄ ёърърЄ№ цшЁэ√ьш ышэш ьш
  310.  
  311. //Їшъёшь ¤Єю ёфтшуюь Їрч√ y яю ъёюЁє ё x[1] шьхээю фы  ¤Єшї яюфєЁютэхщ (фы  1/2 Єръющ Їшъё ёыюьрхЄ ёхЄъє)
  312.  
  313. //colorlevel_grid = {{0,2},{3,1}};
  314.  
  315.           gridy = y ^ (x[1] & colorlevel[0]);
  316.  
  317.           gridindex = {gridy+phase[1], x[0]+phase[0]};
  318.  
  319.           case(gridindex[1:0])
  320.  
  321.             2'b00: gridlevel = 2'b00;
  322.  
  323.             2'b01: gridlevel = 2'b10;
  324.  
  325.             2'b10: gridlevel = 2'b11;
  326.  
  327.             2'b11: gridlevel = 2'b01;
  328.  
  329.           endcase
  330.  
  331.        
  332.  
  333.           color_out = colorlevel[3:2] + ((colorlevel[1:0] > gridlevel[1:0]) ? 2'b01 : 2'b00);
  334.  
  335.         end
  336.  
  337. endmodule
  338.  
  339.