Subversion Repositories pentevo

Rev

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

  1. // visualize ZX picture
  2. //
  3. // here we build picture and send it sometimes to C program
  4.  
  5. module pixer
  6. (
  7.         input  wire clk,
  8.        
  9.         input  wire vsync,
  10.         input  wire hsync,
  11.  
  12.         input  wire [1:0] red,
  13.         input  wire [1:0] grn,
  14.         input  wire [1:0] blu
  15. );
  16.  
  17.  
  18.         reg r_vsync;
  19.         reg r_hsync;
  20.  
  21.         wire vbeg,hbeg;
  22.  
  23.  
  24.         integer hcount;
  25.         integer hperiod;
  26.         integer hper1,hper2;
  27.  
  28.         integer vcount;
  29.         integer vperiod;
  30.         integer vper1,vper2;
  31.  
  32.         reg clr_vcnt;
  33.  
  34.  
  35.  
  36.  
  37.  
  38.         always @(posedge clk)
  39.                 r_vsync <= vsync;
  40.  
  41.         always @(posedge clk)
  42.                 r_hsync <= hsync;
  43.  
  44.         assign vbeg = ( (!r_vsync) && vsync );
  45.         assign hbeg = ( (!r_hsync) && hsync );
  46.  
  47.  
  48.         // get horizontal period
  49.         always @(posedge clk)
  50.         if( hbeg )
  51.                 hcount <= 0;
  52.         else
  53.                 hcount <= hcount + 1;
  54.  
  55.         always @(posedge clk)
  56.         if( hbeg )
  57.         begin
  58.                 hper2 <= hper1;
  59.                 hper1 <= hcount+1;
  60.         end
  61.  
  62.  
  63.         initial hperiod=0;
  64.  
  65.         always @*
  66.         if( hper2===hper1 )
  67.                 hperiod = hper2;
  68.  
  69.  
  70.  
  71.  
  72.         // get vertical period
  73.         initial clr_vcnt = 0;
  74.        
  75.         always @(posedge clk)
  76.         begin
  77.                 if( vbeg )
  78.                         clr_vcnt=1;
  79.  
  80.                 if( hbeg )
  81.                 begin
  82.                         if( clr_vcnt )
  83.                         begin
  84.                                 clr_vcnt=0;
  85.  
  86.                                 vper2 <= vper1;
  87.                                 vper1 <= vcount+1;
  88.                                 vcount <= 0;
  89.                         end
  90.                         else
  91.                                 vcount <= vcount+1;
  92.                 end
  93.         end
  94.  
  95.  
  96.         initial vperiod = 0;
  97.  
  98.         always @*
  99.         if( vper1===vper2 )
  100.                 vperiod = vper2;
  101.  
  102.  
  103.         // display periods
  104. //      always @*
  105. //              $display("h period is %d",hperiod);
  106. //      always @*
  107. //              $display("v period is %d",vperiod);
  108.  
  109.  
  110.  
  111.         always @(posedge clk)
  112.         begin
  113.                 sndpix(hcount,vcount,{26'd0,red,grn,blu},hperiod,vperiod);
  114.         end
  115.  
  116.  
  117.  
  118.  
  119.  
  120.         import "DPI-C" task sndpix
  121.         (
  122.                 input int hcoord,
  123.                 input int vcoord,
  124.                 input int rrggbb,
  125.                 input int hperiod,
  126.                 input int vperiod
  127.         );
  128.  
  129.  
  130.  
  131.  
  132. endmodule
  133.  
  134.