Subversion Repositories pentevo

Rev

Rev 608 | 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. // vertical blank, sync and window. H is period of horizontal sync;
  6. // from the last non-blanked line:
  7. // 3H is pre-blank,
  8. // 2.xxH is vertical sync (slightly more than 2H, all hsync edges preserved)
  9. // vblank is total of 25H
  10.  
  11. module video_sync_v(
  12.  
  13.         input  wire        clk,
  14.  
  15.         input  wire        hsync_start, // synchronizing signal
  16.         input  wire        line_start,  // to end vsync some time after hsync has ended
  17.  
  18.         input  wire        hint_start,
  19.  
  20.  
  21.  
  22.         // atm video mode input
  23.         input  wire        mode_atm_n_pent,
  24.  
  25.         input  wire        mode_60hz,
  26.  
  27.  
  28.         output reg         vblank,
  29.         output reg         vsync,
  30.  
  31.         output reg         int_start, // one-shot positive pulse marking beginning of INT for Z80
  32.  
  33.         output reg         vpix // vertical picture marker: active when there is line with pixels in it, not just a border. changes with hsync edge
  34. );
  35.  
  36.  
  37.  
  38.  
  39.  
  40.         localparam VBLNK_BEG = 9'd00;
  41.         localparam VSYNC_BEG = 9'd08;
  42.         localparam VSYNC_END = 9'd11;
  43.         localparam VBLNK_END = 9'd32;
  44.  
  45.         localparam INT_BEG = 9'd0;
  46.  
  47.         // pentagon (x192)
  48.         localparam VPIX_BEG_PENT = 9'd080;
  49.         localparam VPIX_END_PENT = 9'd272;
  50.  
  51.         // ATM (x200)
  52.         localparam VPIX_BEG_ATM = 9'd076;
  53.         localparam VPIX_END_ATM = 9'd276;
  54.  
  55.         localparam VPERIOD = 9'd320; // pentagono foreva!
  56.  
  57.         // ntsc
  58.         localparam VSYNC60_BEG = 9'd04;
  59.         localparam VSYNC60_END = 9'd07;
  60.         localparam VBLNK60_END = 9'd22;
  61.         // pentagon (x192)
  62.         localparam VPIX60_BEG_PENT = 9'd046;
  63.         localparam VPIX60_END_PENT = 9'd238;
  64.         // ATM (x200)
  65.         localparam VPIX60_BEG_ATM = 9'd042;
  66.         localparam VPIX60_END_ATM = 9'd242;
  67.         //
  68.         localparam VPERIOD60 = 9'd262;
  69.  
  70.         reg [8:0] vcount;
  71.         reg mode60;
  72.  
  73.  
  74.  
  75.  
  76.         initial
  77.         begin
  78.                 vcount = 9'd0;
  79.                 vsync = 1'b0;
  80.                 vblank = 1'b0;
  81.                 vpix = 1'b0;
  82.                 int_start = 1'b0;
  83.         end
  84.  
  85.         always @(posedge clk) if( hsync_start )
  86.         begin
  87.                 if( vcount==((mode60?VPERIOD60:VPERIOD)-9'd1) )
  88.                 begin
  89.                         vcount <= 9'd0;
  90.                         mode60 <= mode_60hz;
  91.                 end
  92.                 else
  93.                         vcount <= vcount + 9'd1;
  94.         end
  95.  
  96.  
  97.  
  98.         always @(posedge clk) if( hsync_start )
  99.         begin
  100.                 if( vcount==VBLNK_BEG )
  101.                         vblank <= 1'b1;
  102.                 else if( vcount==(mode60?VBLNK60_END:VBLNK_END) )
  103.                         vblank <= 1'b0;
  104.         end
  105.  
  106.  
  107.         always @(posedge clk)
  108.         begin
  109.                 if( (vcount==(mode60?VSYNC60_BEG:VSYNC_BEG)) && hsync_start )
  110.                         vsync <= 1'b1;
  111.                 else if( (vcount==(mode60?VSYNC60_END:VSYNC_END)) && line_start  )
  112.                         vsync <= 1'b0;
  113.         end
  114.  
  115.  
  116.         always @(posedge clk)
  117.         begin
  118.                 if( (vcount==INT_BEG) && hint_start )
  119.                         int_start <= 1'b1;
  120.                 else
  121.                         int_start <= 1'b0;
  122.         end
  123.  
  124.  
  125.  
  126.         always @(posedge clk) if( hsync_start )
  127.         begin
  128.                 if( vcount==(mode60?(mode_atm_n_pent ? VPIX60_BEG_ATM : VPIX60_BEG_PENT):(mode_atm_n_pent ? VPIX_BEG_ATM : VPIX_BEG_PENT)) )
  129.                         vpix <= 1'b1;
  130.                 else if( vcount==(mode60?(mode_atm_n_pent ? VPIX60_END_ATM : VPIX60_END_PENT):(mode_atm_n_pent ? VPIX_END_ATM : VPIX_END_PENT)) )
  131.                         vpix <= 1'b0;
  132.         end
  133.  
  134.  
  135. endmodule
  136.  
  137.