Subversion Repositories pentevo

Rev

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

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