Subversion Repositories pentevo

Rev

Rev 467 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed | ?url?

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