data/full_repos/permissive/128426084/src/sources_1/new/tiff_writer.v
[Errno 2] No such file or directory: 'preprocess.output'
1: b'%Error: data/full_repos/permissive/128426084/src/sources_1/new/tiff_writer.v:59: Unsupported: Use $fwrite with %b format instead: $fwriteb\n      $fwriteb(file_ptr, "%c", data);\n      ^~~~~~~~\n%Error: data/full_repos/permissive/128426084/src/sources_1/new/tiff_writer.v:394: syntax error, unexpected \'@\'\n    @(posedge go) CLOSE_FILE;\n    ^\n%Error: Exiting due to 2 error(s)\n        ... See the manual and https://verilator.org for more assistance.\n'
module tiff_writer (
  input wire pclk_mirror,
  input wire [7:0] r,
  input wire [7:0] g,
  input wire [7:0] b,
  input wire go,
  input wire [15:0] xdim,
  input wire [15:0] ydim
  );

  integer file_ptr;
  integer file_open;
  integer frame_number = 0;

  task OPEN_FILE;
    input [7:0] number;
    reg [7:0] temp;
    reg [12*8:1] file_name;
    reg [7:0] ascii_hun;
    reg [7:0] ascii_ten;
    reg [7:0] ascii_one;
  begin
    temp = (number / 1 ) % 10;
    ascii_one = 8'h30 + temp;
    temp = (number / 10) % 10;
    ascii_ten = 8'h30 + temp;
    temp = (number / 100) % 10;
    ascii_hun = 8'h30 + temp;
    file_name = {"frame", ascii_hun, ascii_ten, ascii_one, ".tif"};
    file_ptr = $fopen(file_name, "wb"); 
    file_open = 1;
  end
  endtask

  task CLOSE_FILE;
  begin
    $fclose(file_ptr);
    file_open = 0;
  end
  endtask

  task WRITE_BYTE;
    input [7:0] data;
  begin
      $fwriteb(file_ptr, "%c", data);
  end
  endtask

  task WRITE_HEADER;
    input [15:0] whxdim;
    input [15:0] whydim;
    integer numbytes;
  begin






    numbytes = whxdim * whydim * 3;







    WRITE_BYTE(8'h4d);
    WRITE_BYTE(8'h4d);




    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h2a);






    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h10);





    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);






    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h0c);




    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h04);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(xdim[15:8]);
    WRITE_BYTE(xdim[ 7:0]);




    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h04);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(ydim[15:8]);
    WRITE_BYTE(ydim[ 7:0]);




    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h02);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h03);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h03);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'hb8);




    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h03);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h03);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);




    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h06);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h03);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h02);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);




    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h11);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h04);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'hc0);




    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h15);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h03);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h03);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);




    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h16);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h04);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(ydim[15:8]);
    WRITE_BYTE(ydim[ 7:0]);




    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h17);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h04);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h01);
    WRITE_BYTE(numbytes[31:24]);
    WRITE_BYTE(numbytes[23:16]);
    WRITE_BYTE(numbytes[15: 8]);
    WRITE_BYTE(numbytes[ 7: 0]);




    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h1a);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h05);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'ha8);




    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h1b);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h05);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'hb0);




    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h28);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h03);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h02);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);






    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);





    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);






    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h4b);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h01);






    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h4b);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h01);






    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h08);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h08);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h08);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h08);

  end
  endtask

  reg go_delayed = 0;
  always @(go) go_delayed <= #1 go;

  always @(negedge pclk_mirror)
  begin
    if (file_open == 1)
    begin
      WRITE_BYTE(r);
      WRITE_BYTE(g);
      WRITE_BYTE(b);
    end
  end

  always @(posedge go_delayed)
  begin
    OPEN_FILE(frame_number);
    WRITE_HEADER(xdim, ydim);
    $display("Info: tiff_writer started frame %d",frame_number);
    @(posedge go) CLOSE_FILE;
    $display("Info: tiff writer finished frame %d",frame_number);
    frame_number = frame_number + 1;
  end

endmodule
module tiff_writer (
  input wire pclk_mirror,
  input wire [7:0] r,
  input wire [7:0] g,
  input wire [7:0] b,
  input wire go,
  input wire [15:0] xdim,
  input wire [15:0] ydim
  );


  integer file_ptr;
  integer file_open;
  integer frame_number = 0;

  task OPEN_FILE;
    input [7:0] number;
    reg [7:0] temp;
    reg [12*8:1] file_name;
    reg [7:0] ascii_hun;
    reg [7:0] ascii_ten;
    reg [7:0] ascii_one;
  begin
    temp = (number / 1 ) % 10;
    ascii_one = 8'h30 + temp;
    temp = (number / 10) % 10;
    ascii_ten = 8'h30 + temp;
    temp = (number / 100) % 10;
    ascii_hun = 8'h30 + temp;
    file_name = {"frame", ascii_hun, ascii_ten, ascii_one, ".tif"};
    file_ptr = $fopen(file_name, "wb"); 
    file_open = 1;
  end
  endtask

  task CLOSE_FILE;
  begin
    $fclose(file_ptr);
    file_open = 0;
  end
  endtask

  task WRITE_BYTE;
    input [7:0] data;
  begin
      $fwriteb(file_ptr, "%c", data);
  end
  endtask

  task WRITE_HEADER;
    input [15:0] whxdim;
    input [15:0] whydim;
    integer numbytes;
  begin






    numbytes = whxdim * whydim * 3;







    WRITE_BYTE(8'h4d);
    WRITE_BYTE(8'h4d);




    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h2a);






    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h10);





    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);






    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h0c);




    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h04);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(xdim[15:8]);
    WRITE_BYTE(xdim[ 7:0]);




    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h04);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(ydim[15:8]);
    WRITE_BYTE(ydim[ 7:0]);




    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h02);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h03);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h03);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'hb8);




    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h03);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h03);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);




    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h06);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h03);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h02);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);




    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h11);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h04);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'hc0);




    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h15);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h03);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h03);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);




    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h16);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h04);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(ydim[15:8]);
    WRITE_BYTE(ydim[ 7:0]);




    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h17);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h04);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h01);
    WRITE_BYTE(numbytes[31:24]);
    WRITE_BYTE(numbytes[23:16]);
    WRITE_BYTE(numbytes[15: 8]);
    WRITE_BYTE(numbytes[ 7: 0]);




    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h1a);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h05);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'ha8);




    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h1b);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h05);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'hb0);




    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h28);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h03);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h01);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h02);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);






    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);





    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);






    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h4b);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h01);






    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h4b);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h01);






    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h08);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h08);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h08);
    WRITE_BYTE(8'h00);
    WRITE_BYTE(8'h08);

  end
  endtask

  reg go_delayed = 0;
  always @(go) go_delayed <= #1 go;

  always @(negedge pclk_mirror)
  begin
    if (file_open == 1)
    begin
      WRITE_BYTE(r);
      WRITE_BYTE(g);
      WRITE_BYTE(b);
    end
  end

  always @(posedge go_delayed)
  begin
    OPEN_FILE(frame_number);
    WRITE_HEADER(xdim, ydim);
    $display("Info: tiff_writer started frame %d",frame_number);
    @(posedge go) CLOSE_FILE;
    $display("Info: tiff writer finished frame %d",frame_number);
    frame_number = frame_number + 1;
  end

endmodule