Subversion Repositories pentevo

Rev

Rev 436 | 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. // generates horizontal sync, blank and video start strobe, horizontal window
  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. //
  25. // =\                  /=========||...
  26. // ==\                /==========||...
  27. // ====---     -------===========||...
  28. //    |  \   / |      |
  29. //    |   ---  |      |
  30. //    |  |   | |      |
  31. //    0  t1  | t3     t4
  32. //           t2
  33. // at 0, video ends and blank begins
  34. //    t1 = 10 clocks (@7MHz), sync begins
  35. // t2-t1 = 33 clocks
  36. // t3-t2 = 41 clocks, then video starts
  37. //
  38. // repetition period = 448 clocks
  39.  
  40. `include "../include/tune.v"
  41.  
  42. module video_sync_h(
  43.  
  44.         input  wire        clk,
  45.  
  46.         input  wire        init, // one-pulse strobe read at cend==1, initializes phase
  47.                                  // this is mainly for phasing with CPU clock 3.5/7 MHz
  48.                                  // still not used, but this may change anytime
  49.  
  50.         input  wire        cend,     // working strobes from DRAM controller (7MHz)
  51.         input  wire        pre_cend,
  52.  
  53.  
  54.         // modes inputs
  55.         input  wire        mode_atm_n_pent,
  56.         input  wire        mode_a_text,
  57.  
  58.  
  59.         output reg         hblank,
  60.         output reg         hsync,
  61.  
  62.         output reg         line_start,  // 1 video cycle prior to actual start of visible line
  63.         output reg         hsync_start, // 1 cycle prior to beginning of hsync: used in frame sync/blank generation
  64.                                         // these signals coincide with cend
  65.  
  66.         output reg         hint_start, // horizontal position of INT start, for fine tuning
  67.  
  68.         output reg         scanin_start,
  69.  
  70.         output reg         hpix, // marks gate during which pixels are outting
  71.  
  72.                                         // these signals turn on and turn off 'go' signal
  73.         output reg         fetch_start, // 18 cycles earlier than hpix, coincide with cend
  74.         output reg         fetch_end    // --//--
  75.  
  76. );
  77.  
  78.  
  79.         localparam HBLNK_BEG = 9'd00;
  80.         localparam HSYNC_BEG = 9'd10;
  81.         localparam HSYNC_END = 9'd43;
  82.         localparam HBLNK_END = 9'd88;
  83.  
  84.         // pentagon (x256)
  85.         localparam HPIX_BEG_PENT = 9'd140; // 52 cycles from line_start to pixels beginning
  86.         localparam HPIX_END_PENT = 9'd396;
  87.  
  88.         // atm (x320)
  89.         localparam HPIX_BEG_ATM = 9'd108; // 52 cycles from line_start to pixels beginning
  90.         localparam HPIX_END_ATM = 9'd428;
  91.  
  92.  
  93.         localparam FETCH_FOREGO = 9'd18; // consistent with older go_start in older fetch.v:
  94.                                          // actual data starts fetching 2 dram cycles after
  95.                                          // 'go' goes to 1, screen output starts another
  96.                                          // 16 cycles after 1st data bundle is fetched
  97.  
  98.  
  99.         localparam SCANIN_BEG = 9'd88; // when scan-doubler starts pixel storing
  100.  
  101.         localparam HINT_BEG = 9'd2;
  102.  
  103.  
  104.         localparam HPERIOD = 9'd448;
  105.  
  106.  
  107.         reg [8:0] hcount;
  108.  
  109.  
  110.         // for simulation only
  111.         //
  112.         initial
  113.         begin
  114.                 hcount = 9'd0;
  115.                 hblank = 1'b0;
  116.                 hsync = 1'b0;
  117.                 line_start = 1'b0;
  118.                 hsync_start = 1'b0;
  119.                 hpix = 1'b0;
  120.         end
  121.  
  122.  
  123.  
  124.  
  125.         always @(posedge clk) if( cend )
  126.         begin
  127.             if( init || (hcount==(HPERIOD-9'd1)) )
  128.                 hcount <= 9'd0;
  129.             else
  130.                 hcount <= hcount + 9'd1;
  131.         end
  132.  
  133.  
  134.  
  135.         always @(posedge clk) if( cend )
  136.         begin
  137.                 if( hcount==HBLNK_BEG )
  138.                         hblank <= 1'b1;
  139.                 else if( hcount==HBLNK_END )
  140.                         hblank <= 1'b0;
  141.  
  142.  
  143.                 if( hcount==HSYNC_BEG )
  144.                         hsync <= 1'b1;
  145.                 else if( hcount==HSYNC_END )
  146.                         hsync <= 1'b0;
  147.         end
  148.  
  149.  
  150.         always @(posedge clk)
  151.         begin
  152.                 if( pre_cend )
  153.                 begin
  154.                         if( hcount==HSYNC_BEG )
  155.                                 hsync_start <= 1'b1;
  156.  
  157.                         if( hcount==HBLNK_END )
  158.                                 line_start <= 1'b1;
  159.  
  160.                         if( hcount==SCANIN_BEG )
  161.                                 scanin_start <= 1'b1;
  162.  
  163.                 end
  164.                 else
  165.                 begin
  166.                         hsync_start  <= 1'b0;
  167.                         line_start   <= 1'b0;
  168.                         scanin_start <= 1'b0;
  169.                 end
  170.         end
  171.  
  172.  
  173.  
  174.         wire fetch_start_time, fetch_start_condition;
  175.         wire fetch_end_condition;
  176.  
  177.         reg [3:0] fetch_start_wait;
  178.  
  179.  
  180.         assign fetch_start_time = (mode_atm_n_pent                  ?
  181.                                   (HPIX_BEG_ATM -FETCH_FOREGO-9'd4) :
  182.                                   (HPIX_BEG_PENT-FETCH_FOREGO-9'd4) ) == hcount;
  183.  
  184.         always @(posedge clk) if( cend )
  185.                 fetch_start_wait[3:0] <= { fetch_start_wait[2:0], fetch_start_time };
  186.  
  187.         assign fetch_start_condition = mode_a_text ? fetch_start_time  : fetch_start_wait[3];
  188.  
  189.         always @(posedge clk)
  190.         if( pre_cend && fetch_start_condition )
  191.                 fetch_start <= 1'b1;
  192.         else
  193.                 fetch_start <= 1'b0;
  194.  
  195.  
  196.  
  197.  
  198.         assign fetch_end_time = (mode_atm_n_pent             ?
  199.                                 (HPIX_END_ATM -FETCH_FOREGO) :
  200.                                 (HPIX_END_PENT-FETCH_FOREGO) ) == hcount;
  201.  
  202.         always @(posedge clk)
  203.         if( pre_cend && fetch_end_time )
  204.                 fetch_end <= 1'b1;
  205.         else
  206.                 fetch_end <= 1'b0;
  207.  
  208.  
  209.  
  210.  
  211.  
  212.         always @(posedge clk)
  213.         begin
  214.                 if( pre_cend && (hcount==HINT_BEG) )
  215.                         hint_start <= 1'b1;
  216.                 else
  217.                         hint_start <= 1'b0;
  218.         end
  219.  
  220.  
  221.         always @(posedge clk) if( cend )
  222.         begin
  223.                 if( hcount==(mode_atm_n_pent ? HPIX_BEG_ATM : HPIX_BEG_PENT) )
  224.                         hpix <= 1'b1;
  225.                 else if( hcount==(mode_atm_n_pent ? HPIX_END_ATM : HPIX_END_PENT) )
  226.                         hpix <= 1'b0;
  227.         end
  228.  
  229.  
  230.  
  231.  
  232.  
  233. endmodule
  234.  
  235.