OpenCores
URL https://opencores.org/ocsvn/hdl-deflate/hdl-deflate/trunk

Subversion Repositories hdl-deflate

[/] [hdl-deflate/] [trunk/] [test_deflate_bench.v] - Rev 2

Compare with Previous | Blame | View Log

// File: test_deflate_bench.v
// Generated by MyHDL 0.10
// Date: Thu Dec 20 18:23:03 2018
 
 
`timescale 1ns/10ps
 
module test_deflate_bench (
    i_clk,
    o_led,
    led0_g,
    led1_b,
    led2_r
);
 
 
input i_clk;
output [3:0] o_led;
reg [3:0] o_led;
output led0_g;
reg led0_g;
output led1_b;
reg led1_b;
output led2_r;
reg led2_r;
 
reg [12:0] o_iprogress;
reg [12:0] resultlen;
reg reset;
reg [12:0] o_oprogress;
reg o_done;
reg [7:0] o_byte;
reg [2:0] i_mode;
reg [7:0] i_data;
reg [12:0] i_addr;
reg [21:0] scounter;
reg [15:0] counter;
reg [4:0] tstate;
reg [14:0] tbi;
reg wtick;
reg [5:0] resume;
reg [7:0] copy;
reg [18:0] deflate0_wleaf;
reg [9:0] deflate0_step;
reg deflate0_static;
reg [4:0] deflate0_state;
reg [8:0] deflate0_spread_i;
reg [9:0] deflate0_spread;
reg [9:0] deflate0_reverse;
reg [7:0] deflate0_orbyte;
reg [12:0] deflate0_oraddr;
reg [12:0] deflate0_offset;
reg [7:0] deflate0_obyte;
reg [7:0] deflate0_ob1;
reg [12:0] deflate0_oaddr;
reg [8:0] deflate0_numLiterals;
reg [5:0] deflate0_numDistance;
reg [8:0] deflate0_numCodeLength;
reg [2:0] deflate0_nb;
reg [4:0] deflate0_minBits;
reg [2:0] deflate0_method;
reg [4:0] deflate0_maxBits;
reg [8:0] deflate0_lwaddr;
reg [12:0] deflate0_length;
reg [18:0] deflate0_leaf;
reg [14:0] deflate0_lastToken;
reg [15:0] deflate0_ladler1;
reg [12:0] deflate0_isize;
reg [9:0] deflate0_instantMaxBit;
reg [14:0] deflate0_instantMask;
reg [8:0] deflate0_howOften;
reg deflate0_flush;
reg deflate0_final;
reg deflate0_filled;
reg [2:0] deflate0_doo;
reg deflate0_do_compress;
reg [12:0] deflate0_do;
reg [2:0] deflate0_dio;
reg [12:0] deflate0_di;
reg [4:0] deflate0_d_maxBits;
reg [9:0] deflate0_d_instantMaxBit;
reg [14:0] deflate0_d_instantMask;
reg [8:0] deflate0_cur_static;
reg signed [7:0] deflate0_cur_search;
reg deflate0_cur_next;
reg [12:0] deflate0_cur_i;
reg signed [7:0] deflate0_cur_dist;
reg [12:0] deflate0_cur_cstatic;
reg [9:0] deflate0_cur_HF1;
reg [7:0] deflate0_copy1;
reg [14:0] deflate0_code;
reg [3:0] deflate0_bits;
reg [8:0] deflate0_b_numCodeLength;
wire [31:0] deflate0_b41;
reg [7:0] deflate0_b4;
reg [7:0] deflate0_b3;
reg [7:0] deflate0_b2;
reg [7:0] deflate0_b1;
reg [15:0] deflate0_adler2;
reg [15:0] deflate0_adler1;
reg [7:0] deflate0_oram [0:8192-1];
reg [9:0] deflate0_nextCode [0:15-1];
reg [18:0] deflate0_leaves [0:512-1];
reg [7:0] deflate0_iram [0:128-1];
reg [3:0] deflate0_distanceLength [0:32-1];
reg [18:0] deflate0_d_leaves [0:128-1];
reg [8:0] deflate0_code_bits [0:288-1];
reg [3:0] deflate0_codeLength [0:290-1];
reg [8:0] deflate0_bitLengthCount [0:16-1];
 
assign deflate0_b41[32-1:24] = deflate0_b4;
assign deflate0_b41[24-1:16] = deflate0_b3;
assign deflate0_b41[16-1:8] = deflate0_b2;
assign deflate0_b41[8-1:0] = deflate0_b1;
 
task MYHDL3_adv;
    input width;
    integer width;
    integer nshift;
begin: MYHDL79_RETURN
    nshift = ((deflate0_dio + width) >>> 3);
    o_iprogress <= deflate0_di;
    deflate0_dio <= ((deflate0_dio + width) & 7);
    deflate0_di <= ($signed({1'b0, deflate0_di}) + nshift);
    if ((nshift != 0)) begin
        deflate0_filled <= 1'b0;
    end
end
endtask
 
function integer MYHDL4_get4;
    input boffset;
    input width;
begin: MYHDL80_RETURN
    if ((deflate0_nb != 4)) begin
        $write("----NB----");
        $write("\n");
        $finish;
    end
    MYHDL4_get4 = ((deflate0_b41 >>> (deflate0_dio + boffset)) & ((1 << width) - 1));
    disable MYHDL80_RETURN;
end
endfunction
 
function integer MYHDL5_get4;
    input boffset;
    input width;
    integer width;
begin: MYHDL81_RETURN
    if ((deflate0_nb != 4)) begin
        $write("----NB----");
        $write("\n");
        $finish;
    end
    MYHDL5_get4 = ((deflate0_b41 >>> (deflate0_dio + boffset)) & ((1 << width) - 1));
    disable MYHDL81_RETURN;
end
endfunction
 
task MYHDL6_adv;
    input width;
    integer width;
    integer nshift;
begin: MYHDL82_RETURN
    nshift = ((deflate0_dio + width) >>> 3);
    o_iprogress <= deflate0_di;
    deflate0_dio <= ((deflate0_dio + width) & 7);
    deflate0_di <= ($signed({1'b0, deflate0_di}) + nshift);
    if ((nshift != 0)) begin
        deflate0_filled <= 1'b0;
    end
end
endtask
 
task MYHDL7_adv;
    input width;
    integer width;
    integer nshift;
begin: MYHDL83_RETURN
    nshift = ((deflate0_dio + width) >>> 3);
    o_iprogress <= deflate0_di;
    deflate0_dio <= ((deflate0_dio + width) & 7);
    deflate0_di <= ($signed({1'b0, deflate0_di}) + nshift);
    if ((nshift != 0)) begin
        deflate0_filled <= 1'b0;
    end
end
endtask
 
function integer MYHDL8_get4;
    input boffset;
    integer boffset;
    input width;
    integer width;
begin: MYHDL84_RETURN
    if ((deflate0_nb != 4)) begin
        $write("----NB----");
        $write("\n");
        $finish;
    end
    MYHDL8_get4 = ($signed($signed({1'b0, deflate0_b41}) >>> ($signed({1'b0, deflate0_dio}) + boffset)) & ((1 << width) - 1));
    disable MYHDL84_RETURN;
end
endfunction
 
task MYHDL9_adv;
    input width;
    integer width;
    integer nshift;
begin: MYHDL85_RETURN
    nshift = $signed(($signed({1'b0, deflate0_dio}) + width) >>> 3);
    o_iprogress <= deflate0_di;
    deflate0_dio <= (($signed({1'b0, deflate0_dio}) + width) & 7);
    deflate0_di <= ($signed({1'b0, deflate0_di}) + nshift);
    if ((nshift != 0)) begin
        deflate0_filled <= 1'b0;
    end
end
endtask
 
function integer MYHDL10_put;
    input d;
    integer d;
    input width;
    integer width;
begin: MYHDL86_RETURN
    if ((width > 9)) begin
        $finish;
    end
    if (($signed({1'b0, d}) > ((1 << width) - 1))) begin
        $finish;
    end
    MYHDL10_put = ((deflate0_ob1 | (d << deflate0_doo)) & 255);
    disable MYHDL86_RETURN;
end
endfunction
 
task MYHDL11_put_adv;
    input d;
    integer d;
    input width;
    integer width;
    reg pshift;
    integer carry;
    integer doo_next;
begin: MYHDL87_RETURN
    if ((width > 9)) begin
        $finish;
    end
    if (($signed({1'b0, d}) > ((1 << width) - 1))) begin
        $finish;
    end
    pshift = ((deflate0_doo + width) > 8);
    if (pshift) begin
        carry = ($signed({1'b0, width}) - (8 - $signed({1'b0, deflate0_doo})));
        deflate0_ob1 <= $signed($signed({1'b0, d}) >>> ($signed({1'b0, width}) - carry));
    end
    else begin
        deflate0_ob1 <= (deflate0_ob1 | (d << deflate0_doo));
    end
    deflate0_do <= (deflate0_do + pshift);
    o_oprogress <= (deflate0_do + pshift);
    doo_next = ((deflate0_doo + width) & 7);
    if ((doo_next == 0)) begin
        deflate0_flush <= 1'b1;
    end
    deflate0_doo <= doo_next;
end
endtask
 
task MYHDL12_do_flush;
begin: MYHDL88_RETURN
    deflate0_flush <= 1'b0;
    deflate0_ob1 <= 0;
    o_oprogress <= (deflate0_do + 1);
    deflate0_do <= (deflate0_do + 1);
end
endtask
 
function integer MYHDL13_put;
    input [9-1:0] d;
    input [4-1:0] width;
begin: MYHDL89_RETURN
    if ((width > 9)) begin
        $finish;
    end
    if (($signed({1'b0, d}) > ((1 << width) - 1))) begin
        $finish;
    end
    MYHDL13_put = ((deflate0_ob1 | (d << deflate0_doo)) & 255);
    disable MYHDL89_RETURN;
end
endfunction
 
task MYHDL14_put_adv;
    input [9-1:0] d;
    input [4-1:0] width;
    reg pshift;
    integer carry;
    integer doo_next;
begin: MYHDL90_RETURN
    if ((width > 9)) begin
        $finish;
    end
    if (($signed({1'b0, d}) > ((1 << width) - 1))) begin
        $finish;
    end
    pshift = ((deflate0_doo + width) > 8);
    if (pshift) begin
        carry = ($signed({1'b0, width}) - (8 - $signed({1'b0, deflate0_doo})));
        deflate0_ob1 <= $signed($signed({1'b0, d}) >>> ($signed({1'b0, width}) - carry));
    end
    else begin
        deflate0_ob1 <= (deflate0_ob1 | (d << deflate0_doo));
    end
    deflate0_do <= (deflate0_do + pshift);
    o_oprogress <= (deflate0_do + pshift);
    doo_next = ((deflate0_doo + width) & 7);
    if ((doo_next == 0)) begin
        deflate0_flush <= 1'b1;
    end
    deflate0_doo <= doo_next;
end
endtask
 
task MYHDL15_do_flush;
begin: MYHDL91_RETURN
    deflate0_flush <= 1'b0;
    deflate0_ob1 <= 0;
    o_oprogress <= (deflate0_do + 1);
    deflate0_do <= (deflate0_do + 1);
end
endtask
 
function integer MYHDL16_rev_bits;
    input [13-1:0] b;
    input nb;
    integer nb;
    integer r;
begin: MYHDL92_RETURN
    if ((b >= (1 << nb))) begin
        $finish;
        $write("too few bits");
        $write("\n");
    end
    r = (((((((((((((((((b >>> 14) & 1) << 0) | (((b >>> 13) & 1) << 1)) | (((b >>> 12) & 1) << 2)) | (((b >>> 11) & 1) << 3)) | (((b >>> 10) & 1) << 4)) | (((b >>> 9) & 1) << 5)) | (((b >>> 8) & 1) << 6)) | (((b >>> 7) & 1) << 7)) | (((b >>> 6) & 1) << 8)) | (((b >>> 5) & 1) << 9)) | (((b >>> 4) & 1) << 10)) | (((b >>> 3) & 1) << 11)) | (((b >>> 2) & 1) << 12)) | (((b >>> 1) & 1) << 13)) | (((b >>> 0) & 1) << 14));
    r = r >>> (15 - $signed({1'b0, nb}));
    MYHDL16_rev_bits = r;
    disable MYHDL92_RETURN;
end
endfunction
 
function integer MYHDL17_put;
    input d;
    integer d;
    input width;
    integer width;
begin: MYHDL93_RETURN
    if ((width > 9)) begin
        $finish;
    end
    if ((d > ((1 << width) - 1))) begin
        $finish;
    end
    MYHDL17_put = (($signed({1'b0, deflate0_ob1}) | (d << $signed({1'b0, deflate0_doo}))) & 255);
    disable MYHDL93_RETURN;
end
endfunction
 
task MYHDL18_put_adv;
    input d;
    integer d;
    input width;
    integer width;
    reg pshift;
    integer carry;
    integer doo_next;
begin: MYHDL94_RETURN
    if ((width > 9)) begin
        $finish;
    end
    if ((d > ((1 << width) - 1))) begin
        $finish;
    end
    pshift = (($signed({1'b0, deflate0_doo}) + width) > 8);
    if (pshift) begin
        carry = (width - (8 - $signed({1'b0, deflate0_doo})));
        deflate0_ob1 <= $signed(d >>> (width - carry));
    end
    else begin
        deflate0_ob1 <= ($signed({1'b0, deflate0_ob1}) | (d << $signed({1'b0, deflate0_doo})));
    end
    deflate0_do <= (deflate0_do + pshift);
    o_oprogress <= (deflate0_do + pshift);
    doo_next = (($signed({1'b0, deflate0_doo}) + width) & 7);
    if ((doo_next == 0)) begin
        deflate0_flush <= 1'b1;
    end
    deflate0_doo <= doo_next;
end
endtask
 
function integer MYHDL19_put;
    input [9-1:0] d;
    input [4-1:0] width;
begin: MYHDL95_RETURN
    if ((width > 9)) begin
        $finish;
    end
    if (($signed({1'b0, d}) > ((1 << width) - 1))) begin
        $finish;
    end
    MYHDL19_put = ((deflate0_ob1 | (d << deflate0_doo)) & 255);
    disable MYHDL95_RETURN;
end
endfunction
 
task MYHDL20_put_adv;
    input [9-1:0] d;
    input [4-1:0] width;
    reg pshift;
    integer carry;
    integer doo_next;
begin: MYHDL96_RETURN
    if ((width > 9)) begin
        $finish;
    end
    if (($signed({1'b0, d}) > ((1 << width) - 1))) begin
        $finish;
    end
    pshift = ((deflate0_doo + width) > 8);
    if (pshift) begin
        carry = ($signed({1'b0, width}) - (8 - $signed({1'b0, deflate0_doo})));
        deflate0_ob1 <= $signed($signed({1'b0, d}) >>> ($signed({1'b0, width}) - carry));
    end
    else begin
        deflate0_ob1 <= (deflate0_ob1 | (d << deflate0_doo));
    end
    deflate0_do <= (deflate0_do + pshift);
    o_oprogress <= (deflate0_do + pshift);
    doo_next = ((deflate0_doo + width) & 7);
    if ((doo_next == 0)) begin
        deflate0_flush <= 1'b1;
    end
    deflate0_doo <= doo_next;
end
endtask
 
function integer MYHDL21_put;
    input [9-1:0] d;
    input [4-1:0] width;
begin: MYHDL97_RETURN
    if ((width > 9)) begin
        $finish;
    end
    if (($signed({1'b0, d}) > ((1 << width) - 1))) begin
        $finish;
    end
    MYHDL21_put = ((deflate0_ob1 | (d << deflate0_doo)) & 255);
    disable MYHDL97_RETURN;
end
endfunction
 
task MYHDL22_put_adv;
    input [9-1:0] d;
    input [4-1:0] width;
    reg pshift;
    integer carry;
    integer doo_next;
begin: MYHDL98_RETURN
    if ((width > 9)) begin
        $finish;
    end
    if (($signed({1'b0, d}) > ((1 << width) - 1))) begin
        $finish;
    end
    pshift = ((deflate0_doo + width) > 8);
    if (pshift) begin
        carry = ($signed({1'b0, width}) - (8 - $signed({1'b0, deflate0_doo})));
        deflate0_ob1 <= $signed($signed({1'b0, d}) >>> ($signed({1'b0, width}) - carry));
    end
    else begin
        deflate0_ob1 <= (deflate0_ob1 | (d << deflate0_doo));
    end
    deflate0_do <= (deflate0_do + pshift);
    o_oprogress <= (deflate0_do + pshift);
    doo_next = ((deflate0_doo + width) & 7);
    if ((doo_next == 0)) begin
        deflate0_flush <= 1'b1;
    end
    deflate0_doo <= doo_next;
end
endtask
 
function integer MYHDL31_get4;
    input boffset;
    input width;
    integer width;
begin: MYHDL99_RETURN
    if ((deflate0_nb != 4)) begin
        $write("----NB----");
        $write("\n");
        $finish;
    end
    MYHDL31_get4 = ((deflate0_b41 >>> (deflate0_dio + boffset)) & ((1 << width) - 1));
    disable MYHDL99_RETURN;
end
endfunction
 
function integer MYHDL32_get4;
    input boffset;
    input width;
    integer width;
begin: MYHDL100_RETURN
    if ((deflate0_nb != 4)) begin
        $write("----NB----");
        $write("\n");
        $finish;
    end
    MYHDL32_get4 = ((deflate0_b41 >>> (deflate0_dio + boffset)) & ((1 << width) - 1));
    disable MYHDL100_RETURN;
end
endfunction
 
function integer MYHDL33_get4;
    input boffset;
    integer boffset;
    input width;
    integer width;
begin: MYHDL101_RETURN
    if ((deflate0_nb != 4)) begin
        $write("----NB----");
        $write("\n");
        $finish;
    end
    MYHDL33_get4 = ((deflate0_b41 >>> (deflate0_dio + boffset)) & ((1 << width) - 1));
    disable MYHDL101_RETURN;
end
endfunction
 
function integer MYHDL34_get4;
    input boffset;
    integer boffset;
    input width;
    integer width;
begin: MYHDL102_RETURN
    if ((deflate0_nb != 4)) begin
        $write("----NB----");
        $write("\n");
        $finish;
    end
    MYHDL34_get4 = ((deflate0_b41 >>> (deflate0_dio + boffset)) & ((1 << width) - 1));
    disable MYHDL102_RETURN;
end
endfunction
 
function integer MYHDL35_get4;
    input boffset;
    integer boffset;
    input width;
    integer width;
begin: MYHDL103_RETURN
    if ((deflate0_nb != 4)) begin
        $write("----NB----");
        $write("\n");
        $finish;
    end
    MYHDL35_get4 = ((deflate0_b41 >>> (deflate0_dio + boffset)) & ((1 << width) - 1));
    disable MYHDL103_RETURN;
end
endfunction
 
function integer MYHDL36_get4;
    input boffset;
    integer boffset;
    input width;
    integer width;
begin: MYHDL104_RETURN
    if ((deflate0_nb != 4)) begin
        $write("----NB----");
        $write("\n");
        $finish;
    end
    MYHDL36_get4 = ((deflate0_b41 >>> (deflate0_dio + boffset)) & ((1 << width) - 1));
    disable MYHDL104_RETURN;
end
endfunction
 
task MYHDL37_adv;
    input width;
    integer width;
    integer nshift;
begin: MYHDL105_RETURN
    nshift = ((deflate0_dio + width) >>> 3);
    o_iprogress <= deflate0_di;
    deflate0_dio <= ((deflate0_dio + width) & 7);
    deflate0_di <= ($signed({1'b0, deflate0_di}) + nshift);
    if ((nshift != 0)) begin
        deflate0_filled <= 1'b0;
    end
end
endtask
 
function integer MYHDL38_get4;
    input boffset;
    input width;
    integer width;
begin: MYHDL106_RETURN
    if ((deflate0_nb != 4)) begin
        $write("----NB----");
        $write("\n");
        $finish;
    end
    MYHDL38_get4 = ((deflate0_b41 >>> (deflate0_dio + boffset)) & ((1 << width) - 1));
    disable MYHDL106_RETURN;
end
endfunction
 
task MYHDL39_adv;
    input width;
    integer width;
    integer nshift;
begin: MYHDL107_RETURN
    nshift = ((deflate0_dio + width) >>> 3);
    o_iprogress <= deflate0_di;
    deflate0_dio <= ((deflate0_dio + width) & 7);
    deflate0_di <= ($signed({1'b0, deflate0_di}) + nshift);
    if ((nshift != 0)) begin
        deflate0_filled <= 1'b0;
    end
end
endtask
 
function integer MYHDL40_get4;
    input boffset;
    input width;
    integer width;
begin: MYHDL108_RETURN
    if ((deflate0_nb != 4)) begin
        $write("----NB----");
        $write("\n");
        $finish;
    end
    MYHDL40_get4 = ((deflate0_b41 >>> (deflate0_dio + boffset)) & ((1 << width) - 1));
    disable MYHDL108_RETURN;
end
endfunction
 
function integer MYHDL41_get4;
    input boffset;
    input width;
    integer width;
begin: MYHDL109_RETURN
    if ((deflate0_nb != 4)) begin
        $write("----NB----");
        $write("\n");
        $finish;
    end
    MYHDL41_get4 = ((deflate0_b41 >>> (deflate0_dio + boffset)) & ((1 << width) - 1));
    disable MYHDL109_RETURN;
end
endfunction
 
function integer MYHDL42_get4;
    input boffset;
    input width;
    integer width;
begin: MYHDL110_RETURN
    if ((deflate0_nb != 4)) begin
        $write("----NB----");
        $write("\n");
        $finish;
    end
    MYHDL42_get4 = ((deflate0_b41 >>> (deflate0_dio + boffset)) & ((1 << width) - 1));
    disable MYHDL110_RETURN;
end
endfunction
 
task MYHDL43_adv;
    input width;
    integer width;
    integer nshift;
begin: MYHDL111_RETURN
    nshift = ((deflate0_dio + width) >>> 3);
    o_iprogress <= deflate0_di;
    deflate0_dio <= ((deflate0_dio + width) & 7);
    deflate0_di <= ($signed({1'b0, deflate0_di}) + nshift);
    if ((nshift != 0)) begin
        deflate0_filled <= 1'b0;
    end
end
endtask
 
function integer MYHDL50_rev_bits;
    input [10-1:0] b;
    input [4-1:0] nb;
    integer r;
begin: MYHDL112_RETURN
    if ((b >= (1 << nb))) begin
        $finish;
        $write("too few bits");
        $write("\n");
    end
    r = (((((((((((((((((b >>> 14) & 1) << 0) | (((b >>> 13) & 1) << 1)) | (((b >>> 12) & 1) << 2)) | (((b >>> 11) & 1) << 3)) | (((b >>> 10) & 1) << 4)) | (((b >>> 9) & 1) << 5)) | (((b >>> 8) & 1) << 6)) | (((b >>> 7) & 1) << 7)) | (((b >>> 6) & 1) << 8)) | (((b >>> 5) & 1) << 9)) | (((b >>> 4) & 1) << 10)) | (((b >>> 3) & 1) << 11)) | (((b >>> 2) & 1) << 12)) | (((b >>> 1) & 1) << 13)) | (((b >>> 0) & 1) << 14));
    r = r >>> (15 - $signed({1'b0, nb}));
    MYHDL50_rev_bits = r;
    disable MYHDL112_RETURN;
end
endfunction
 
function integer MYHDL51_makeLeaf;
    input [9-1:0] lcode;
    input [4-1:0] lbits;
begin: MYHDL113_RETURN
    if ((lcode >= (1 << 10))) begin
        $finish;
    end
    if ((lbits >= (1 << 9))) begin
        $finish;
    end
    MYHDL51_makeLeaf = ((lcode << 9) | lbits);
    disable MYHDL113_RETURN;
end
endfunction
 
function integer MYHDL52_makeLeaf;
    input [9-1:0] lcode;
    input [4-1:0] lbits;
begin: MYHDL114_RETURN
    if ((lcode >= (1 << 10))) begin
        $finish;
    end
    if ((lbits >= (1 << 9))) begin
        $finish;
    end
    MYHDL52_makeLeaf = ((lcode << 9) | lbits);
    disable MYHDL114_RETURN;
end
endfunction
 
function integer MYHDL53_makeLeaf;
    input [9-1:0] lcode;
    input [4-1:0] lbits;
begin: MYHDL115_RETURN
    if ((lcode >= (1 << 10))) begin
        $finish;
    end
    if ((lbits >= (1 << 9))) begin
        $finish;
    end
    MYHDL53_makeLeaf = ((lcode << 9) | lbits);
    disable MYHDL115_RETURN;
end
endfunction
 
function integer MYHDL54_get4;
    input boffset;
    input [5-1:0] width;
begin: MYHDL116_RETURN
    if ((deflate0_nb != 4)) begin
        $write("----NB----");
        $write("\n");
        $finish;
    end
    MYHDL54_get4 = ((deflate0_b41 >>> (deflate0_dio + boffset)) & ((1 << width) - 1));
    disable MYHDL116_RETURN;
end
endfunction
 
function integer MYHDL55_get_bits;
    input [19-1:0] aleaf;
begin: MYHDL117_RETURN
    MYHDL55_get_bits = ($signed({1'b0, aleaf}) & ((1 << 9) - 1));
    disable MYHDL117_RETURN;
end
endfunction
 
function integer MYHDL56_get_bits;
    input [19-1:0] aleaf;
begin: MYHDL118_RETURN
    MYHDL56_get_bits = ($signed({1'b0, aleaf}) & ((1 << 9) - 1));
    disable MYHDL118_RETURN;
end
endfunction
 
task MYHDL57_adv;
    input width;
    integer width;
    integer nshift;
begin: MYHDL119_RETURN
    nshift = $signed(($signed({1'b0, deflate0_dio}) + width) >>> 3);
    o_iprogress <= deflate0_di;
    deflate0_dio <= (($signed({1'b0, deflate0_dio}) + width) & 7);
    deflate0_di <= ($signed({1'b0, deflate0_di}) + nshift);
    if ((nshift != 0)) begin
        deflate0_filled <= 1'b0;
    end
end
endtask
 
function integer MYHDL58_get_code;
    input [19-1:0] aleaf;
begin: MYHDL120_RETURN
    MYHDL58_get_code = (aleaf >>> 9);
    disable MYHDL120_RETURN;
end
endfunction
 
function integer MYHDL59_get_code;
    input [19-1:0] aleaf;
begin: MYHDL121_RETURN
    MYHDL59_get_code = (aleaf >>> 9);
    disable MYHDL121_RETURN;
end
endfunction
 
function integer MYHDL60_get4;
    input boffset;
    integer boffset;
    input [5-1:0] width;
begin: MYHDL122_RETURN
    if ((deflate0_nb != 4)) begin
        $write("----NB----");
        $write("\n");
        $finish;
    end
    MYHDL60_get4 = ($signed($signed({1'b0, deflate0_b41}) >>> ($signed({1'b0, deflate0_dio}) + boffset)) & ((1 << width) - 1));
    disable MYHDL122_RETURN;
end
endfunction
 
function integer MYHDL61_get_bits;
    input [19-1:0] aleaf;
begin: MYHDL123_RETURN
    MYHDL61_get_bits = ($signed({1'b0, aleaf}) & ((1 << 9) - 1));
    disable MYHDL123_RETURN;
end
endfunction
 
function integer MYHDL62_get4;
    input boffset;
    input width;
    integer width;
begin: MYHDL124_RETURN
    if ((deflate0_nb != 4)) begin
        $write("----NB----");
        $write("\n");
        $finish;
    end
    MYHDL62_get4 = ((deflate0_b41 >>> (deflate0_dio + boffset)) & ((1 << width) - 1));
    disable MYHDL124_RETURN;
end
endfunction
 
function integer MYHDL63_get_code;
    input [19-1:0] aleaf;
begin: MYHDL125_RETURN
    MYHDL63_get_code = (aleaf >>> 9);
    disable MYHDL125_RETURN;
end
endfunction
 
function integer MYHDL64_get_bits;
    input [19-1:0] aleaf;
begin: MYHDL126_RETURN
    MYHDL64_get_bits = ($signed({1'b0, aleaf}) & ((1 << 9) - 1));
    disable MYHDL126_RETURN;
end
endfunction
 
function integer MYHDL65_get4;
    input boffset;
    integer boffset;
    input width;
    integer width;
begin: MYHDL127_RETURN
    if ((deflate0_nb != 4)) begin
        $write("----NB----");
        $write("\n");
        $finish;
    end
    MYHDL65_get4 = ($signed($signed({1'b0, deflate0_b41}) >>> ($signed({1'b0, deflate0_dio}) + boffset)) & ((1 << width) - 1));
    disable MYHDL127_RETURN;
end
endfunction
 
function integer MYHDL66_get_bits;
    input [19-1:0] aleaf;
begin: MYHDL128_RETURN
    MYHDL66_get_bits = ($signed({1'b0, aleaf}) & ((1 << 9) - 1));
    disable MYHDL128_RETURN;
end
endfunction
 
task MYHDL67_adv;
    input width;
    integer width;
    integer nshift;
begin: MYHDL129_RETURN
    nshift = $signed(($signed({1'b0, deflate0_dio}) + width) >>> 3);
    o_iprogress <= deflate0_di;
    deflate0_dio <= (($signed({1'b0, deflate0_dio}) + width) & 7);
    deflate0_di <= ($signed({1'b0, deflate0_di}) + nshift);
    if ((nshift != 0)) begin
        deflate0_filled <= 1'b0;
    end
end
endtask
 
function integer MYHDL68_get4;
    input boffset;
    input width;
    integer width;
begin: MYHDL130_RETURN
    if ((deflate0_nb != 4)) begin
        $write("----NB----");
        $write("\n");
        $finish;
    end
    MYHDL68_get4 = ((deflate0_b41 >>> (deflate0_dio + boffset)) & ((1 << width) - 1));
    disable MYHDL130_RETURN;
end
endfunction
 
function integer MYHDL69_get4;
    input boffset;
    integer boffset;
    input width;
    integer width;
begin: MYHDL131_RETURN
    if ((deflate0_nb != 4)) begin
        $write("----NB----");
        $write("\n");
        $finish;
    end
    MYHDL69_get4 = ($signed($signed({1'b0, deflate0_b41}) >>> ($signed({1'b0, deflate0_dio}) + boffset)) & ((1 << width) - 1));
    disable MYHDL131_RETURN;
end
endfunction
 
function integer MYHDL70_rev_bits;
    input b;
    integer b;
    input nb;
    integer nb;
    integer r;
begin: MYHDL132_RETURN
    if ((b >= (1 << nb))) begin
        $finish;
        $write("too few bits");
        $write("\n");
    end
    r = (((((((((((((((((b >>> 14) & 1) << 0) | (((b >>> 13) & 1) << 1)) | (((b >>> 12) & 1) << 2)) | (((b >>> 11) & 1) << 3)) | (((b >>> 10) & 1) << 4)) | (((b >>> 9) & 1) << 5)) | (((b >>> 8) & 1) << 6)) | (((b >>> 7) & 1) << 7)) | (((b >>> 6) & 1) << 8)) | (((b >>> 5) & 1) << 9)) | (((b >>> 4) & 1) << 10)) | (((b >>> 3) & 1) << 11)) | (((b >>> 2) & 1) << 12)) | (((b >>> 1) & 1) << 13)) | (((b >>> 0) & 1) << 14));
    r = r >>> (15 - $signed({1'b0, nb}));
    MYHDL70_rev_bits = r;
    disable MYHDL132_RETURN;
end
endfunction
 
function integer MYHDL71_get4;
    input boffset;
    integer boffset;
    input width;
    integer width;
begin: MYHDL133_RETURN
    if ((deflate0_nb != 4)) begin
        $write("----NB----");
        $write("\n");
        $finish;
    end
    MYHDL71_get4 = ($signed($signed({1'b0, deflate0_b41}) >>> ($signed({1'b0, deflate0_dio}) + boffset)) & ((1 << width) - 1));
    disable MYHDL133_RETURN;
end
endfunction
 
task MYHDL72_adv;
    input width;
    integer width;
    integer nshift;
begin: MYHDL134_RETURN
    nshift = $signed(($signed({1'b0, deflate0_dio}) + width) >>> 3);
    o_iprogress <= deflate0_di;
    deflate0_dio <= (($signed({1'b0, deflate0_dio}) + width) & 7);
    deflate0_di <= ($signed({1'b0, deflate0_di}) + nshift);
    if ((nshift != 0)) begin
        deflate0_filled <= 1'b0;
    end
end
endtask
 
task MYHDL73_adv;
    input width;
    integer width;
    integer nshift;
begin: MYHDL135_RETURN
    nshift = ((deflate0_dio + width) >>> 3);
    o_iprogress <= deflate0_di;
    deflate0_dio <= ((deflate0_dio + width) & 7);
    deflate0_di <= ($signed({1'b0, deflate0_di}) + nshift);
    if ((nshift != 0)) begin
        deflate0_filled <= 1'b0;
    end
end
endtask
 
 
always @(posedge i_clk) begin: TEST_DEFLATE_BENCH_DEFLATE0_IO_LOGIC
    case (i_mode)
        'h2: begin
            deflate0_iram[(i_addr & 127)] <= i_data;
            deflate0_isize <= i_addr;
        end
        'h3: begin
            o_byte <= deflate0_oram[i_addr];
        end
        default: begin
            // pass
        end
    endcase
end
 
 
always @(posedge i_clk) begin: TEST_DEFLATE_BENCH_DEFLATE0_LOGIC
    integer hm;
    integer skip;
    reg no_adv;
    integer cs_i;
    reg [4-1:0] outlen;
    reg [9-1:0] outbits;
    reg [8-1:0] bdata;
    integer adler1_next;
    integer nextdist;
    integer copydist;
    integer extra_dist;
    integer extra_bits;
    integer outcode;
    integer lencode;
    integer match;
    integer distance;
    integer stat_i;
    integer clo_i;
    integer n_adv;
    integer dbl_i;
    integer dbl;
    integer dist_i;
    integer limit;
    reg [4-1:0] j;
    integer t;
    integer hf2_i;
    reg [5-1:0] amb;
    integer ncode;
    reg [10-1:0] canonical;
    reg [4-1:0] bits_next;
    reg [15-1:0] aim;
    integer cto;
    integer mask;
    integer token;
    integer extraLength;
    integer tlength;
    integer distanceCode;
    integer moreBits;
    integer mored;
    if ((!reset)) begin
        $write("DEFLATE RESET");
        $write("\n");
        deflate0_state <= 5'b00000;
        o_done <= 1'b0;
    end
    else begin
        case (deflate0_state)
            5'b00000: begin
                case (i_mode)
                    'h4: begin
                        $write("STARTC");
                        $write("\n");
                        deflate0_do_compress <= 1'b1;
                        deflate0_method <= 1;
                        o_done <= 1'b0;
                        o_iprogress <= 0;
                        o_oprogress <= 0;
                        deflate0_di <= 0;
                        deflate0_dio <= 0;
                        deflate0_do <= 0;
                        deflate0_doo <= 0;
                        deflate0_filled <= 1'b1;
                        deflate0_cur_static <= 0;
                        deflate0_state <= 5'b01110;
                    end
                    'h5: begin
                        deflate0_do_compress <= 1'b0;
                        o_done <= 1'b0;
                        o_iprogress <= 0;
                        o_oprogress <= 0;
                        deflate0_di <= 0;
                        deflate0_dio <= 0;
                        deflate0_do <= 0;
                        deflate0_doo <= 0;
                        deflate0_filled <= 1'b1;
                        deflate0_state <= 5'b00001;
                    end
                    default: begin
                        // pass
                    end
                endcase
            end
            5'b00001: begin
                if ((!deflate0_filled)) begin
                    deflate0_filled <= 1'b1;
                end
                else if ((deflate0_nb < 4)) begin
                    // pass
                end
                else if ((deflate0_di == 0)) begin
                    if ((deflate0_b1 == 120)) begin
                        $write("deflate mode");
                        $write("\n");
                    end
                    else begin
                        $write("%h", deflate0_di);
                        $write(" ");
                        $write("%h", deflate0_dio);
                        $write(" ");
                        $write("%h", deflate0_nb);
                        $write(" ");
                        $write("%h", deflate0_b1);
                        $write(" ");
                        $write("%h", deflate0_b2);
                        $write(" ");
                        $write("%h", deflate0_b3);
                        $write(" ");
                        $write("%h", deflate0_b4);
                        $write(" ");
                        $write("%h", deflate0_isize);
                        $write("\n");
                        $finish;
                        o_done <= 1'b1;
                        deflate0_state <= 5'b00000;
                    end
                    MYHDL3_adv(16);
                end
                else begin
                    if (MYHDL4_get4(0, 1)) begin
                        $write("final");
                        $write("\n");
                        deflate0_final <= 1'b1;
                    end
                    hm = MYHDL5_get4(1, 2);
                    deflate0_method <= hm;
                    $write("method");
                    $write(" ");
                    $write("%0d", hm);
                    $write("\n");
                    case (hm)
                        'h2: begin
                            deflate0_state <= 5'b00010;
                            deflate0_numCodeLength <= 0;
                            deflate0_numLiterals <= 0;
                            deflate0_static <= 1'b0;
                            MYHDL6_adv(3);
                        end
                        'h1: begin
                            deflate0_static <= 1'b1;
                            deflate0_cur_static <= 0;
                            deflate0_state <= 5'b01110;
                            MYHDL7_adv(3);
                        end
                        'h0: begin
                            deflate0_state <= 5'b10101;
                            skip = (8 - deflate0_dio);
                            if ((skip <= 2)) begin
                                skip = (16 - deflate0_dio);
                            end
                            deflate0_length <= MYHDL8_get4(skip, 16);
                            MYHDL9_adv((skip + 16));
                            deflate0_cur_i <= 0;
                            deflate0_offset <= 7;
                        end
                        default: begin
                            deflate0_state <= 5'b00000;
                            $write("Bad method");
                            $write("\n");
                            $finish;
                        end
                    endcase
                end
            end
            5'b10110: begin
                no_adv = 0;
                if ((!deflate0_filled)) begin
                    no_adv = 1;
                    deflate0_filled <= 1'b1;
                end
                else if ((deflate0_nb < 4)) begin
                    no_adv = 1;
                    // pass
                end
                else if ((deflate0_cur_cstatic == 0)) begin
                    deflate0_flush <= 1'b0;
                    deflate0_ob1 <= 0;
                    deflate0_adler1 <= 1;
                    deflate0_adler2 <= 0;
                    deflate0_ladler1 <= 0;
                    deflate0_oaddr <= 0;
                    deflate0_obyte <= 120;
                end
                else if ((deflate0_cur_cstatic == 1)) begin
                    deflate0_oaddr <= 1;
                    deflate0_obyte <= 156;
                    deflate0_do <= 2;
                end
                else if ((deflate0_cur_cstatic == 2)) begin
                    deflate0_oaddr <= deflate0_do;
                    deflate0_obyte <= MYHDL10_put(3, 3);
                    MYHDL11_put_adv(3, 3);
                end
                else if (deflate0_flush) begin
                    $write("flush");
                    $write(" ");
                    $write("%h", deflate0_do);
                    $write(" ");
                    $write("%h", deflate0_ob1);
                    $write("\n");
                    no_adv = 1;
                    deflate0_oaddr <= deflate0_do;
                    deflate0_obyte <= deflate0_ob1;
                    MYHDL12_do_flush;
                end
                else if ((($signed({1'b0, deflate0_cur_cstatic}) - 3) > deflate0_isize)) begin
                    if ((($signed({1'b0, deflate0_cur_cstatic}) - 3) == (deflate0_isize + 1))) begin
                        $write("Put EOF");
                        $write(" ");
                        $write("%h", deflate0_do);
                        $write("\n");
                        cs_i = 256;
                        outlen = deflate0_codeLength[cs_i];
                        outbits = deflate0_code_bits[cs_i];
                        $write("EOF BITS:");
                        $write(" ");
                        $write("%0d", cs_i);
                        $write(" ");
                        $write("%h", outlen);
                        $write(" ");
                        $write("%h", outbits);
                        $write("\n");
                        deflate0_oaddr <= deflate0_do;
                        deflate0_obyte <= MYHDL13_put(outbits, outlen);
                        MYHDL14_put_adv(outbits, outlen);
                    end
                    else if ((($signed({1'b0, deflate0_cur_cstatic}) - 3) == (deflate0_isize + 2))) begin
                        $write("calc end adler");
                        $write("\n");
                        deflate0_adler2 <= ((deflate0_adler2 + deflate0_ladler1) % 65521);
                        if ((deflate0_doo != 0)) begin
                            deflate0_oaddr <= deflate0_do;
                            deflate0_obyte <= deflate0_ob1;
                            deflate0_do <= (deflate0_do + 1);
                        end
                    end
                    else if ((($signed({1'b0, deflate0_cur_cstatic}) - 3) == (deflate0_isize + 3))) begin
                        $write("c1");
                        $write("\n");
                        deflate0_oaddr <= deflate0_do;
                        deflate0_obyte <= (deflate0_adler2 >>> 8);
                        deflate0_do <= (deflate0_do + 1);
                    end
                    else if ((($signed({1'b0, deflate0_cur_cstatic}) - 3) == (deflate0_isize + 4))) begin
                        $write("c2");
                        $write("\n");
                        deflate0_oaddr <= deflate0_do;
                        deflate0_obyte <= (deflate0_adler2 & 255);
                        deflate0_do <= (deflate0_do + 1);
                    end
                    else if ((($signed({1'b0, deflate0_cur_cstatic}) - 3) == (deflate0_isize + 5))) begin
                        $write("c3");
                        $write("\n");
                        deflate0_oaddr <= deflate0_do;
                        deflate0_obyte <= (deflate0_adler1 >>> 8);
                        deflate0_do <= (deflate0_do + 1);
                    end
                    else if ((($signed({1'b0, deflate0_cur_cstatic}) - 3) == (deflate0_isize + 6))) begin
                        $write("c4");
                        $write("\n");
                        deflate0_oaddr <= deflate0_do;
                        deflate0_obyte <= (deflate0_adler1 & 255);
                    end
                    else if ((($signed({1'b0, deflate0_cur_cstatic}) - 3) == (deflate0_isize + 7))) begin
                        $write("EOF finish");
                        $write(" ");
                        $write("%h", deflate0_do);
                        $write("\n");
                        o_done <= 1'b1;
                        o_oprogress <= (deflate0_do + 1);
                        deflate0_state <= 5'b00000;
                    end
                    else begin
                        $write("%h", deflate0_cur_cstatic);
                        $write(" ");
                        $write("%h", deflate0_isize);
                        $write("\n");
                        $finish;
                    end
                end
                else begin
                    bdata = deflate0_iram[deflate0_di];
                    adler1_next = ((deflate0_adler1 + bdata) % 65521);
                    deflate0_adler1 <= adler1_next;
                    deflate0_adler2 <= ((deflate0_adler2 + deflate0_ladler1) % 65521);
                    deflate0_ladler1 <= adler1_next;
                    deflate0_state <= 5'b10111;
                    deflate0_cur_search <= (deflate0_di - 1);
                end
                if ((!no_adv)) begin
                    deflate0_cur_cstatic <= (deflate0_cur_cstatic + 1);
                end
            end
            5'b11000: begin
                if (deflate0_flush) begin
                    MYHDL15_do_flush;
                end
                else begin
                    case ((deflate0_cur_i + 1))
                        0: nextdist = 1;
                        1: nextdist = 2;
                        2: nextdist = 3;
                        3: nextdist = 4;
                        4: nextdist = 5;
                        5: nextdist = 7;
                        6: nextdist = 9;
                        7: nextdist = 13;
                        8: nextdist = 17;
                        9: nextdist = 25;
                        10: nextdist = 33;
                        11: nextdist = 49;
                        12: nextdist = 65;
                        13: nextdist = 97;
                        14: nextdist = 129;
                        15: nextdist = 193;
                        16: nextdist = 257;
                        17: nextdist = 385;
                        18: nextdist = 513;
                        19: nextdist = 769;
                        20: nextdist = 1025;
                        21: nextdist = 1537;
                        22: nextdist = 2049;
                        23: nextdist = 3073;
                        24: nextdist = 4097;
                        25: nextdist = 6145;
                        26: nextdist = 8193;
                        27: nextdist = 12289;
                        28: nextdist = 16385;
                        default: nextdist = 24577;
                    endcase
                    if ((nextdist > deflate0_cur_dist)) begin
                        case (deflate0_cur_i)
                            0: copydist = 1;
                            1: copydist = 2;
                            2: copydist = 3;
                            3: copydist = 4;
                            4: copydist = 5;
                            5: copydist = 7;
                            6: copydist = 9;
                            7: copydist = 13;
                            8: copydist = 17;
                            9: copydist = 25;
                            10: copydist = 33;
                            11: copydist = 49;
                            12: copydist = 65;
                            13: copydist = 97;
                            14: copydist = 129;
                            15: copydist = 193;
                            16: copydist = 257;
                            17: copydist = 385;
                            18: copydist = 513;
                            19: copydist = 769;
                            20: copydist = 1025;
                            21: copydist = 1537;
                            22: copydist = 2049;
                            23: copydist = 3073;
                            24: copydist = 4097;
                            25: copydist = 6145;
                            26: copydist = 8193;
                            27: copydist = 12289;
                            28: copydist = 16385;
                            default: copydist = 24577;
                        endcase
                        extra_dist = (deflate0_cur_dist - copydist);
                        case ((deflate0_cur_i / 2))
                            0: extra_bits = 0;
                            1: extra_bits = 0;
                            2: extra_bits = 1;
                            3: extra_bits = 2;
                            4: extra_bits = 3;
                            5: extra_bits = 4;
                            6: extra_bits = 5;
                            7: extra_bits = 6;
                            8: extra_bits = 7;
                            9: extra_bits = 8;
                            10: extra_bits = 9;
                            11: extra_bits = 10;
                            12: extra_bits = 11;
                            13: extra_bits = 12;
                            default: extra_bits = 13;
                        endcase
                        if ((extra_dist > ((1 << extra_bits) - 1))) begin
                            $finish;
                        end
                        outcode = (MYHDL16_rev_bits(deflate0_cur_i, 5) | (extra_dist << 5));
                        deflate0_oaddr <= deflate0_do;
                        deflate0_obyte <= MYHDL17_put(outcode, (5 + extra_bits));
                        MYHDL18_put_adv(outcode, (5 + extra_bits));
                        deflate0_cur_i <= (($signed({1'b0, deflate0_di}) - $signed({1'b0, deflate0_length})) + 1);
                        deflate0_state <= 5'b11001;
                    end
                    else begin
                        deflate0_cur_i <= (deflate0_cur_i + 1);
                    end
                end
            end
            5'b11001: begin
                if ((deflate0_cur_i < deflate0_di)) begin
                    bdata = deflate0_iram[(deflate0_cur_i & 127)];
                    adler1_next = ((deflate0_adler1 + bdata) % 65521);
                    deflate0_adler1 <= adler1_next;
                    deflate0_adler2 <= ((deflate0_adler2 + deflate0_ladler1) % 65521);
                    deflate0_ladler1 <= adler1_next;
                    deflate0_cur_i <= (deflate0_cur_i + 1);
                end
                else begin
                    deflate0_state <= 5'b10110;
                end
            end
            5'b10111: begin
                if ((!deflate0_filled)) begin
                    deflate0_filled <= 1'b1;
                end
                else if ((deflate0_nb < 4)) begin
                    // pass
                end
                else begin
                    if (((deflate0_cur_search >= 0) && (deflate0_cur_search >= ($signed({1'b0, deflate0_di}) - 32)) && ($signed({1'b0, deflate0_di}) < ($signed({1'b0, deflate0_isize}) - 3)))) begin
                        if (((deflate0_iram[(deflate0_cur_search & 127)] == deflate0_b1) && (deflate0_iram[((deflate0_cur_search + 1) & 127)] == deflate0_b2) && (deflate0_iram[((deflate0_cur_search + 2) & 127)] == deflate0_b3))) begin
                            lencode = 257;
                            match = 3;
                            if ((($signed({1'b0, deflate0_di}) < ($signed({1'b0, deflate0_isize}) - 4)) && (deflate0_iram[((deflate0_cur_search + 3) & 127)] == deflate0_b4))) begin
                                lencode = 258;
                                match = 4;
                                if ((($signed({1'b0, deflate0_di}) < ($signed({1'b0, deflate0_isize}) - 5)) && (deflate0_iram[((deflate0_cur_search + 4) & 127)] == deflate0_iram[((deflate0_di + 4) & 127)]))) begin
                                    lencode = 259;
                                    match = 5;
                                end
                            end
                            // if di < isize - 6 and                                             iram[cur_search+5 & IBS] == iram[di + 5 & IBS]:
                            //     lencode = 260
                            //     match = 6
                            //     if di < isize - 7 and                                                 iram[cur_search+6 & IBS] == iram[di + 6 & IBS]:
                            //         lencode = 261
                            //         match = 7
                            //         if di < isize - 8 and                                                     iram[cur_search+7 & IBS] == iram[di + 7 & IBS]:
                            //             lencode = 262
                            //             match = 8
                            //             if di < isize - 9 and                                                         iram[cur_search+8 & IBS] == iram[di + 8 & IBS]:
                            //                 lencode = 263
                            //                 match = 9
                            //                 if di < isize - 10 and                                                             iram[cur_search+9 & IBS] == iram[di + 9 & IBS]:
                            //                     lencode = 264
                            //                     match = 10
                            $write("found:");
                            $write(" ");
                            $write("%h", deflate0_cur_search);
                            $write(" ");
                            $write("%h", deflate0_di);
                            $write(" ");
                            $write("%h", deflate0_isize);
                            $write(" ");
                            $write("%0d", match);
                            $write("\n");
                            outlen = deflate0_codeLength[lencode];
                            outbits = deflate0_code_bits[lencode];
                            deflate0_oaddr <= deflate0_do;
                            deflate0_obyte <= MYHDL19_put(outbits, outlen);
                            MYHDL20_put_adv(outbits, outlen);
                            distance = ($signed({1'b0, deflate0_di}) - deflate0_cur_search);
                            deflate0_cur_dist <= distance;
                            deflate0_cur_i <= 0;
                            deflate0_di <= (deflate0_di + match);
                            deflate0_cur_cstatic <= ((deflate0_cur_cstatic + match) - 1);
                            deflate0_length <= match;
                            deflate0_state <= 5'b11000;
                        end
                        else begin
                            deflate0_cur_search <= (deflate0_cur_search - 1);
                        end
                    end
                    else begin
                        bdata = deflate0_iram[deflate0_di];
                        deflate0_di <= (deflate0_di + 1);
                        outlen = deflate0_codeLength[bdata];
                        outbits = deflate0_code_bits[bdata];
                        deflate0_oaddr <= deflate0_do;
                        deflate0_obyte <= MYHDL21_put(outbits, outlen);
                        MYHDL22_put_adv(outbits, outlen);
                        deflate0_state <= 5'b10110;
                    end
                end
            end
            5'b01110: begin
                for (stat_i=0; stat_i<144; stat_i=stat_i+1) begin
                    deflate0_codeLength[stat_i] <= 8;
                end
                for (stat_i=144; stat_i<256; stat_i=stat_i+1) begin
                    deflate0_codeLength[stat_i] <= 9;
                end
                for (stat_i=256; stat_i<280; stat_i=stat_i+1) begin
                    deflate0_codeLength[stat_i] <= 7;
                end
                for (stat_i=280; stat_i<288; stat_i=stat_i+1) begin
                    deflate0_codeLength[stat_i] <= 8;
                end
                deflate0_numCodeLength <= 288;
                deflate0_cur_HF1 <= 0;
                deflate0_state <= 5'b00111;
                // if cur_static < 288:
                //     if cur_static < 144:
                //         codeLength[cur_static].next = 8
                //     elif cur_static < 256:
                //         codeLength[cur_static].next = 9
                //     elif cur_static < 280:
                //         codeLength[cur_static].next = 7
                //     else:
                //         codeLength[cur_static].next = 8
                //     cur_static.next = cur_static + 1
                // else:
                //     numCodeLength.next = 288
                //     cur_HF1.next = 0
                //     state.next = d_state.HF1
            end
            5'b00010: begin
                if ((!deflate0_filled)) begin
                    deflate0_filled <= 1'b1;
                end
                else if ((deflate0_nb < 4)) begin
                    // pass
                end
                else if ((deflate0_numLiterals == 0)) begin
                    deflate0_numLiterals <= (257 + MYHDL31_get4(0, 5));
                    $write("NL:");
                    $write(" ");
                    $write("%0d", (257 + MYHDL32_get4(0, 5)));
                    $write("\n");
                    deflate0_numDistance <= (1 + MYHDL33_get4(5, 5));
                    $write("ND:");
                    $write(" ");
                    $write("%0d", (1 + MYHDL34_get4(5, 5)));
                    $write("\n");
                    deflate0_b_numCodeLength <= (4 + MYHDL35_get4(10, 4));
                    $write("NCL:");
                    $write(" ");
                    $write("%0d", (4 + MYHDL36_get4(10, 4)));
                    $write("\n");
                    deflate0_numCodeLength <= 0;
                    MYHDL37_adv(14);
                end
                else begin
                    if ((deflate0_numCodeLength < 19)) begin
                        case (deflate0_numCodeLength)
                            0: clo_i = 16;
                            1: clo_i = 17;
                            2: clo_i = 18;
                            3: clo_i = 0;
                            4: clo_i = 8;
                            5: clo_i = 7;
                            6: clo_i = 9;
                            7: clo_i = 6;
                            8: clo_i = 10;
                            9: clo_i = 5;
                            10: clo_i = 11;
                            11: clo_i = 4;
                            12: clo_i = 12;
                            13: clo_i = 3;
                            14: clo_i = 13;
                            15: clo_i = 2;
                            16: clo_i = 14;
                            17: clo_i = 1;
                            default: clo_i = 15;
                        endcase
                        if ((deflate0_numCodeLength < deflate0_b_numCodeLength)) begin
                            deflate0_codeLength[clo_i] <= MYHDL38_get4(0, 3);
                            MYHDL39_adv(3);
                        end
                        else begin
                            deflate0_codeLength[clo_i] <= 0;
                        end
                        deflate0_numCodeLength <= (deflate0_numCodeLength + 1);
                    end
                    else begin
                        deflate0_numCodeLength <= 19;
                        deflate0_cur_HF1 <= 0;
                        deflate0_state <= 5'b00111;
                    end
                end
            end
            5'b00011: begin
                if ((!deflate0_filled)) begin
                    deflate0_filled <= 1'b1;
                end
                else if ((deflate0_nb < 4)) begin
                    // pass
                end
                else if ((deflate0_numCodeLength < (deflate0_numLiterals + deflate0_numDistance))) begin
                    n_adv = 0;
                    if ((deflate0_code < 16)) begin
                        deflate0_howOften <= 1;
                        deflate0_lastToken <= deflate0_code;
                    end
                    else if ((deflate0_code == 16)) begin
                        deflate0_howOften <= (3 + MYHDL40_get4(0, 2));
                        n_adv = 2;
                    end
                    else if ((deflate0_code == 17)) begin
                        deflate0_howOften <= (3 + MYHDL41_get4(0, 3));
                        deflate0_lastToken <= 0;
                        n_adv = 3;
                    end
                    else if ((deflate0_code == 18)) begin
                        deflate0_howOften <= (11 + MYHDL42_get4(0, 7));
                        deflate0_lastToken <= 0;
                        n_adv = 7;
                    end
                    else begin
                        $finish;
                    end
                    if ((n_adv != 0)) begin
                        MYHDL43_adv(n_adv);
                    end
                    deflate0_state <= 5'b00100;
                end
                else begin
                    $write("FILL UP");
                    $write("\n");
                    for (dbl_i=0; dbl_i<32; dbl_i=dbl_i+1) begin
                        dbl = 0;
                        if (((dbl_i + $signed({1'b0, deflate0_numLiterals})) < deflate0_numCodeLength)) begin
                            dbl = deflate0_codeLength[(dbl_i + $signed({1'b0, deflate0_numLiterals}))];
                        end
                        deflate0_distanceLength[dbl_i] <= dbl;
                    end
                    deflate0_cur_i <= deflate0_numLiterals;
                    deflate0_state <= 5'b00110;
                end
            end
            default: begin
                if ((deflate0_state == 5'b00110)) begin
                    if ((deflate0_cur_i < 288)) begin
                        deflate0_codeLength[deflate0_cur_i] <= 0;
                        deflate0_cur_i <= (deflate0_cur_i + 1);
                    end
                    else begin
                        deflate0_numCodeLength <= 288;
                        deflate0_method <= 3;
                        deflate0_cur_HF1 <= 0;
                        deflate0_state <= 5'b00111;
                    end
                end
                else begin
                    case (deflate0_state)
                        5'b00101: begin
                            $write("DISTTREE");
                            $write("\n");
                            for (dist_i=0; dist_i<32; dist_i=dist_i+1) begin
                                deflate0_codeLength[dist_i] <= deflate0_distanceLength[dist_i];
                            end
                            deflate0_numCodeLength <= 32;
                            deflate0_method <= 4;
                            deflate0_cur_HF1 <= 0;
                            deflate0_state <= 5'b00111;
                        end
                        5'b00100: begin
                            if ((deflate0_howOften != 0)) begin
                                deflate0_codeLength[deflate0_numCodeLength] <= deflate0_lastToken;
                                deflate0_howOften <= (deflate0_howOften - 1);
                                deflate0_numCodeLength <= (deflate0_numCodeLength + 1);
                            end
                            else if ((deflate0_numCodeLength < (deflate0_numLiterals + deflate0_numDistance))) begin
                                deflate0_cur_next <= 0;
                                deflate0_state <= 5'b10011;
                            end
                            else begin
                                deflate0_state <= 5'b00011;
                            end
                        end
                        5'b00111: begin
                            if ((deflate0_cur_HF1 < 16)) begin
                                deflate0_bitLengthCount[deflate0_cur_HF1] <= 0;
                            end
                            if ((deflate0_cur_HF1 < 128)) begin
                                deflate0_d_leaves[deflate0_cur_HF1] <= 0;
                            end
                            if (((deflate0_method != 4) && (deflate0_cur_HF1 < 512))) begin
                                deflate0_lwaddr <= deflate0_cur_HF1;
                                deflate0_wleaf <= 0;
                            end
                            limit = 512;
                            if ((deflate0_method == 4)) begin
                                limit = 128;
                            end
                            if ((deflate0_cur_HF1 < limit)) begin
                                deflate0_cur_HF1 <= (deflate0_cur_HF1 + 1);
                            end
                            else begin
                                $write("DID HF1 INIT");
                                $write("\n");
                                deflate0_cur_i <= 0;
                                deflate0_state <= 5'b01000;
                            end
                        end
                        5'b01000: begin
                            if ((deflate0_cur_i < deflate0_numCodeLength)) begin
                                j = deflate0_codeLength[deflate0_cur_i];
                                deflate0_bitLengthCount[j] <= (deflate0_bitLengthCount[j] + 1);
                                deflate0_cur_i <= (deflate0_cur_i + 1);
                            end
                            else begin
                                deflate0_bitLengthCount[0] <= 0;
                                deflate0_state <= 5'b01001;
                                deflate0_cur_i <= 1;
                                if ((deflate0_method == 4)) begin
                                    deflate0_d_maxBits <= 0;
                                end
                                else begin
                                    deflate0_maxBits <= 0;
                                end
                                deflate0_minBits <= 15;
                            end
                        end
                        5'b01001: begin
                            if ((deflate0_cur_i <= 15)) begin
                                if ((deflate0_bitLengthCount[deflate0_cur_i] != 0)) begin
                                    if ((deflate0_cur_i < deflate0_minBits)) begin
                                        deflate0_minBits <= deflate0_cur_i;
                                    end
                                    if ((deflate0_method == 4)) begin
                                        if ((deflate0_cur_i > deflate0_d_maxBits)) begin
                                            deflate0_d_maxBits <= deflate0_cur_i;
                                        end
                                    end
                                    else begin
                                        if ((deflate0_cur_i > deflate0_maxBits)) begin
                                            deflate0_maxBits <= deflate0_cur_i;
                                        end
                                    end
                                end
                                deflate0_cur_i <= (deflate0_cur_i + 1);
                            end
                            else begin
                                $write("%h", deflate0_minBits);
                                $write(" ");
                                $write("%h", deflate0_maxBits);
                                $write("\n");
                                t = 10;
                                if ((deflate0_method == 4)) begin
                                    if ((t > deflate0_d_maxBits)) begin
                                        t = deflate0_d_maxBits;
                                    end
                                    deflate0_d_instantMaxBit <= t;
                                    deflate0_d_instantMask <= ((1 << t) - 1);
                                end
                                else begin
                                    if ((t > deflate0_maxBits)) begin
                                        t = deflate0_maxBits;
                                    end
                                    deflate0_instantMaxBit <= t;
                                    deflate0_instantMask <= ((1 << t) - 1);
                                end
                                $write("%0d", ((1 << t) - 1));
                                $write("\n");
                                deflate0_state <= 5'b01010;
                                deflate0_cur_i <= deflate0_minBits;
                                deflate0_code <= 0;
                                for (hf2_i=0; hf2_i<15; hf2_i=hf2_i+1) begin
                                    deflate0_nextCode[hf2_i] <= 0;
                                end
                                $write("to HF3");
                                $write("\n");
                            end
                        end
                        5'b01010: begin
                            amb = deflate0_maxBits;
                            if ((deflate0_method == 4)) begin
                                amb = deflate0_d_maxBits;
                            end
                            if ((deflate0_cur_i <= amb)) begin
                                ncode = ((deflate0_code + deflate0_bitLengthCount[($signed({1'b0, deflate0_cur_i}) - 1)]) << 1);
                                deflate0_code <= ncode;
                                deflate0_nextCode[deflate0_cur_i] <= ncode;
                                deflate0_cur_i <= (deflate0_cur_i + 1);
                            end
                            else begin
                                deflate0_state <= 5'b01011;
                                deflate0_cur_i <= 0;
                                deflate0_spread_i <= 0;
                                $write("to HF4");
                                $write("\n");
                            end
                        end
                        5'b01100: begin
                            canonical = deflate0_nextCode[deflate0_bits];
                            deflate0_nextCode[deflate0_bits] <= (deflate0_nextCode[deflate0_bits] + 1);
                            if ((deflate0_bits > 15)) begin
                                $finish;
                            end
                            deflate0_reverse <= MYHDL50_rev_bits(canonical, deflate0_bits);
                            deflate0_leaf <= MYHDL51_makeLeaf(deflate0_spread_i, deflate0_bits);
                            deflate0_state <= 5'b01101;
                        end
                        5'b01101: begin
                            if ((deflate0_method == 4)) begin
                                deflate0_d_leaves[deflate0_reverse] <= deflate0_leaf;
                                if ((deflate0_bits <= deflate0_d_instantMaxBit)) begin
                                    if (((deflate0_reverse + (1 << deflate0_bits)) <= deflate0_d_instantMask)) begin
                                        deflate0_step <= (1 << deflate0_bits);
                                        deflate0_spread <= (deflate0_reverse + (1 << deflate0_bits));
                                        deflate0_state <= 5'b10010;
                                    end
                                    else begin
                                        deflate0_spread_i <= (deflate0_spread_i + 1);
                                        deflate0_state <= 5'b01011;
                                    end
                                end
                                else begin
                                    deflate0_state <= 5'b01011;
                                    deflate0_spread_i <= (deflate0_spread_i + 1);
                                end
                            end
                            else begin
                                deflate0_wleaf <= deflate0_leaf;
                                deflate0_lwaddr <= deflate0_reverse;
                                deflate0_code_bits[deflate0_spread_i] <= deflate0_reverse;
                                if ((deflate0_bits <= deflate0_instantMaxBit)) begin
                                    if (((deflate0_reverse + (1 << deflate0_bits)) <= deflate0_instantMask)) begin
                                        deflate0_step <= (1 << deflate0_bits);
                                        deflate0_spread <= (deflate0_reverse + (1 << deflate0_bits));
                                        deflate0_state <= 5'b10010;
                                    end
                                    else begin
                                        deflate0_spread_i <= (deflate0_spread_i + 1);
                                        deflate0_state <= 5'b01011;
                                    end
                                end
                                else begin
                                    deflate0_spread_i <= (deflate0_spread_i + 1);
                                    deflate0_state <= 5'b01011;
                                end
                            end
                        end
                        5'b01011: begin
                            if ((deflate0_spread_i < deflate0_numCodeLength)) begin
                                bits_next = deflate0_codeLength[deflate0_spread_i];
                                if ((bits_next != 0)) begin
                                    deflate0_bits <= bits_next;
                                    deflate0_state <= 5'b01100;
                                end
                                else begin
                                    deflate0_spread_i <= (deflate0_spread_i + 1);
                                end
                            end
                            else begin
                                if (deflate0_do_compress) begin
                                    deflate0_state <= 5'b10110;
                                    deflate0_cur_cstatic <= 0;
                                end
                                else if ((deflate0_method == 3)) begin
                                    deflate0_state <= 5'b00101;
                                end
                                else if ((deflate0_method == 4)) begin
                                    $write("DEFLATE m2!");
                                    $write("\n");
                                    deflate0_state <= 5'b10011;
                                end
                                else if ((deflate0_method == 2)) begin
                                    deflate0_numCodeLength <= 0;
                                    deflate0_state <= 5'b10011;
                                end
                                else begin
                                    deflate0_state <= 5'b10011;
                                end
                                deflate0_cur_next <= 0;
                                deflate0_cur_i <= 0;
                            end
                        end
                        5'b10010: begin
                            if ((deflate0_method == 4)) begin
                                deflate0_d_leaves[deflate0_spread] <= MYHDL52_makeLeaf(deflate0_spread_i, deflate0_codeLength[deflate0_spread_i]);
                            end
                            else begin
                                deflate0_lwaddr <= deflate0_spread;
                                deflate0_wleaf <= MYHDL53_makeLeaf(deflate0_spread_i, deflate0_codeLength[deflate0_spread_i]);
                            end
                            aim = deflate0_instantMask;
                            if ((deflate0_method == 4)) begin
                                aim = deflate0_d_instantMask;
                            end
                            if (($signed({1'b0, deflate0_spread}) > ($signed({1'b0, aim}) - $signed({1'b0, deflate0_step})))) begin
                                deflate0_spread_i <= (deflate0_spread_i + 1);
                                deflate0_state <= 5'b01011;
                            end
                            else begin
                                deflate0_spread <= (deflate0_spread + deflate0_step);
                            end
                        end
                        5'b10011: begin
                            if ((!deflate0_filled)) begin
                                deflate0_filled <= 1'b1;
                            end
                            else if ((deflate0_nb < 4)) begin
                                // pass
                            end
                            else if ((deflate0_cur_next == 0)) begin
                                cto = MYHDL54_get4(0, deflate0_maxBits);
                                deflate0_cur_next <= 1;
                                mask = ((1 << deflate0_instantMaxBit) - 1);
                                deflate0_leaf <= deflate0_leaves[(cto & mask)];
                            end
                            else begin
                                if ((MYHDL55_get_bits(deflate0_leaf) < 1)) begin
                                    $write("< 1 bits: ");
                                    $write("\n");
                                    $finish;
                                end
                                MYHDL57_adv(MYHDL56_get_bits(deflate0_leaf));
                                if ((MYHDL58_get_code(deflate0_leaf) == 0)) begin
                                    $write("leaf 0");
                                    $write("\n");
                                end
                                deflate0_code <= MYHDL59_get_code(deflate0_leaf);
                                if ((deflate0_method == 2)) begin
                                    deflate0_state <= 5'b00011;
                                end
                                else begin
                                    deflate0_state <= 5'b10100;
                                end
                            end
                        end
                        5'b01111: begin
                            if ((!deflate0_filled)) begin
                                deflate0_filled <= 1'b1;
                            end
                            else if ((deflate0_nb < 4)) begin
                                // pass
                            end
                            else begin
                                token = (deflate0_code - 257);
                                case (token)
                                    0: extraLength = 0;
                                    1: extraLength = 0;
                                    2: extraLength = 0;
                                    3: extraLength = 0;
                                    4: extraLength = 0;
                                    5: extraLength = 0;
                                    6: extraLength = 0;
                                    7: extraLength = 0;
                                    8: extraLength = 1;
                                    9: extraLength = 1;
                                    10: extraLength = 1;
                                    11: extraLength = 1;
                                    12: extraLength = 2;
                                    13: extraLength = 2;
                                    14: extraLength = 2;
                                    15: extraLength = 2;
                                    16: extraLength = 3;
                                    17: extraLength = 3;
                                    18: extraLength = 3;
                                    19: extraLength = 3;
                                    20: extraLength = 4;
                                    21: extraLength = 4;
                                    22: extraLength = 4;
                                    23: extraLength = 4;
                                    24: extraLength = 5;
                                    25: extraLength = 5;
                                    26: extraLength = 5;
                                    27: extraLength = 5;
                                    default: extraLength = 0;
                                endcase
                                cto = MYHDL60_get4(extraLength, deflate0_d_maxBits);
                                mask = ((1 << deflate0_d_instantMaxBit) - 1);
                                deflate0_leaf <= deflate0_d_leaves[(cto & mask)];
                                deflate0_state <= 5'b10000;
                            end
                        end
                        5'b10000: begin
                            if ((MYHDL61_get_bits(deflate0_leaf) == 0)) begin
                                $finish;
                            end
                            token = (deflate0_code - 257);
                            case (token)
                                0: tlength = 3;
                                1: tlength = 4;
                                2: tlength = 5;
                                3: tlength = 6;
                                4: tlength = 7;
                                5: tlength = 8;
                                6: tlength = 9;
                                7: tlength = 10;
                                8: tlength = 11;
                                9: tlength = 13;
                                10: tlength = 15;
                                11: tlength = 17;
                                12: tlength = 19;
                                13: tlength = 23;
                                14: tlength = 27;
                                15: tlength = 31;
                                16: tlength = 35;
                                17: tlength = 43;
                                18: tlength = 51;
                                19: tlength = 59;
                                20: tlength = 67;
                                21: tlength = 83;
                                22: tlength = 99;
                                23: tlength = 115;
                                24: tlength = 131;
                                25: tlength = 163;
                                26: tlength = 195;
                                27: tlength = 227;
                                default: tlength = 258;
                            endcase
                            case (token)
                                0: extraLength = 0;
                                1: extraLength = 0;
                                2: extraLength = 0;
                                3: extraLength = 0;
                                4: extraLength = 0;
                                5: extraLength = 0;
                                6: extraLength = 0;
                                7: extraLength = 0;
                                8: extraLength = 1;
                                9: extraLength = 1;
                                10: extraLength = 1;
                                11: extraLength = 1;
                                12: extraLength = 2;
                                13: extraLength = 2;
                                14: extraLength = 2;
                                15: extraLength = 2;
                                16: extraLength = 3;
                                17: extraLength = 3;
                                18: extraLength = 3;
                                19: extraLength = 3;
                                20: extraLength = 4;
                                21: extraLength = 4;
                                22: extraLength = 4;
                                23: extraLength = 4;
                                24: extraLength = 5;
                                25: extraLength = 5;
                                26: extraLength = 5;
                                27: extraLength = 5;
                                default: extraLength = 0;
                            endcase
                            tlength = tlength + MYHDL62_get4(0, extraLength);
                            distanceCode = MYHDL63_get_code(deflate0_leaf);
                            case (distanceCode)
                                0: distance = 1;
                                1: distance = 2;
                                2: distance = 3;
                                3: distance = 4;
                                4: distance = 5;
                                5: distance = 7;
                                6: distance = 9;
                                7: distance = 13;
                                8: distance = 17;
                                9: distance = 25;
                                10: distance = 33;
                                11: distance = 49;
                                12: distance = 65;
                                13: distance = 97;
                                14: distance = 129;
                                15: distance = 193;
                                16: distance = 257;
                                17: distance = 385;
                                18: distance = 513;
                                19: distance = 769;
                                20: distance = 1025;
                                21: distance = 1537;
                                22: distance = 2049;
                                23: distance = 3073;
                                24: distance = 4097;
                                25: distance = 6145;
                                26: distance = 8193;
                                27: distance = 12289;
                                28: distance = 16385;
                                default: distance = 24577;
                            endcase
                            case ($signed(distanceCode >>> 1))
                                0: moreBits = 0;
                                1: moreBits = 0;
                                2: moreBits = 1;
                                3: moreBits = 2;
                                4: moreBits = 3;
                                5: moreBits = 4;
                                6: moreBits = 5;
                                7: moreBits = 6;
                                8: moreBits = 7;
                                9: moreBits = 8;
                                10: moreBits = 9;
                                11: moreBits = 10;
                                12: moreBits = 11;
                                13: moreBits = 12;
                                default: moreBits = 13;
                            endcase
                            mored = MYHDL65_get4((extraLength + MYHDL64_get_bits(deflate0_leaf)), moreBits);
                            distance = distance + mored;
                            MYHDL67_adv(((moreBits + extraLength) + MYHDL66_get_bits(deflate0_leaf)));
                            deflate0_offset <= ($signed({1'b0, deflate0_do}) - distance);
                            deflate0_length <= tlength;
                            deflate0_cur_i <= 0;
                            deflate0_oraddr <= deflate0_offset;
                            deflate0_state <= 5'b10101;
                        end
                        default: begin
                            if ((deflate0_state == 5'b10100)) begin
                                if ((!deflate0_filled)) begin
                                    deflate0_filled <= 1'b1;
                                end
                                else if ((deflate0_nb < 4)) begin
                                    // pass
                                end
                                else if (($signed({1'b0, deflate0_di}) > ($signed({1'b0, deflate0_isize}) - 3))) begin
                                    deflate0_state <= 5'b00000;
                                    o_done <= 1'b1;
                                    $write("NO EOF ");
                                    $write(" ");
                                    $write("%h", deflate0_di);
                                    $write("\n");
                                    $finish;
                                end
                                else if ((deflate0_code == 256)) begin
                                    $write("EOF:");
                                    $write(" ");
                                    $write("%h", deflate0_di);
                                    $write(" ");
                                    $write("%h", deflate0_do);
                                    $write("\n");
                                    if ((!deflate0_final)) begin
                                        deflate0_state <= 5'b00001;
                                    end
                                    else begin
                                        o_done <= 1'b1;
                                        o_oprogress <= deflate0_do;
                                        deflate0_state <= 5'b00000;
                                    end
                                end
                                else begin
                                    if ((deflate0_code < 256)) begin
                                        deflate0_oaddr <= deflate0_do;
                                        deflate0_obyte <= deflate0_code;
                                        o_oprogress <= (deflate0_do + 1);
                                        deflate0_do <= (deflate0_do + 1);
                                        deflate0_cur_next <= 0;
                                        deflate0_state <= 5'b10011;
                                    end
                                    else if ((deflate0_code == 300)) begin
                                        $finish;
                                    end
                                    else begin
                                        if (deflate0_static) begin
                                            token = (deflate0_code - 257);
                                            case (token)
                                                0: tlength = 3;
                                                1: tlength = 4;
                                                2: tlength = 5;
                                                3: tlength = 6;
                                                4: tlength = 7;
                                                5: tlength = 8;
                                                6: tlength = 9;
                                                7: tlength = 10;
                                                8: tlength = 11;
                                                9: tlength = 13;
                                                10: tlength = 15;
                                                11: tlength = 17;
                                                12: tlength = 19;
                                                13: tlength = 23;
                                                14: tlength = 27;
                                                15: tlength = 31;
                                                16: tlength = 35;
                                                17: tlength = 43;
                                                18: tlength = 51;
                                                19: tlength = 59;
                                                20: tlength = 67;
                                                21: tlength = 83;
                                                22: tlength = 99;
                                                23: tlength = 115;
                                                24: tlength = 131;
                                                25: tlength = 163;
                                                26: tlength = 195;
                                                27: tlength = 227;
                                                default: tlength = 258;
                                            endcase
                                            case (token)
                                                0: extraLength = 0;
                                                1: extraLength = 0;
                                                2: extraLength = 0;
                                                3: extraLength = 0;
                                                4: extraLength = 0;
                                                5: extraLength = 0;
                                                6: extraLength = 0;
                                                7: extraLength = 0;
                                                8: extraLength = 1;
                                                9: extraLength = 1;
                                                10: extraLength = 1;
                                                11: extraLength = 1;
                                                12: extraLength = 2;
                                                13: extraLength = 2;
                                                14: extraLength = 2;
                                                15: extraLength = 2;
                                                16: extraLength = 3;
                                                17: extraLength = 3;
                                                18: extraLength = 3;
                                                19: extraLength = 3;
                                                20: extraLength = 4;
                                                21: extraLength = 4;
                                                22: extraLength = 4;
                                                23: extraLength = 4;
                                                24: extraLength = 5;
                                                25: extraLength = 5;
                                                26: extraLength = 5;
                                                27: extraLength = 5;
                                                default: extraLength = 0;
                                            endcase
                                            tlength = tlength + MYHDL68_get4(0, extraLength);
                                            t = MYHDL69_get4(extraLength, 5);
                                            distanceCode = MYHDL70_rev_bits(t, 5);
                                            case (distanceCode)
                                                0: distance = 1;
                                                1: distance = 2;
                                                2: distance = 3;
                                                3: distance = 4;
                                                4: distance = 5;
                                                5: distance = 7;
                                                6: distance = 9;
                                                7: distance = 13;
                                                8: distance = 17;
                                                9: distance = 25;
                                                10: distance = 33;
                                                11: distance = 49;
                                                12: distance = 65;
                                                13: distance = 97;
                                                14: distance = 129;
                                                15: distance = 193;
                                                16: distance = 257;
                                                17: distance = 385;
                                                18: distance = 513;
                                                19: distance = 769;
                                                20: distance = 1025;
                                                21: distance = 1537;
                                                22: distance = 2049;
                                                23: distance = 3073;
                                                24: distance = 4097;
                                                25: distance = 6145;
                                                26: distance = 8193;
                                                27: distance = 12289;
                                                28: distance = 16385;
                                                default: distance = 24577;
                                            endcase
                                            case ($signed(distanceCode >>> 1))
                                                0: moreBits = 0;
                                                1: moreBits = 0;
                                                2: moreBits = 1;
                                                3: moreBits = 2;
                                                4: moreBits = 3;
                                                5: moreBits = 4;
                                                6: moreBits = 5;
                                                7: moreBits = 6;
                                                8: moreBits = 7;
                                                9: moreBits = 8;
                                                10: moreBits = 9;
                                                11: moreBits = 10;
                                                12: moreBits = 11;
                                                13: moreBits = 12;
                                                default: moreBits = 13;
                                            endcase
                                            distance = distance + MYHDL71_get4((extraLength + 5), moreBits);
                                            MYHDL72_adv(((extraLength + 5) + moreBits));
                                            deflate0_offset <= ($signed({1'b0, deflate0_do}) - distance);
                                            deflate0_length <= tlength;
                                            deflate0_cur_i <= 0;
                                            deflate0_oraddr <= deflate0_offset;
                                            deflate0_state <= 5'b10101;
                                        end
                                        else begin
                                            deflate0_state <= 5'b01111;
                                        end
                                    end
                                    deflate0_cur_next <= 0;
                                end
                            end
                            else begin
                                if ((deflate0_state == 5'b10101)) begin
                                    if ((!deflate0_filled)) begin
                                        deflate0_filled <= 1'b1;
                                    end
                                    else if ((deflate0_nb < 4)) begin
                                        // pass
                                    end
                                    else if ((deflate0_method == 0)) begin
                                        if ((deflate0_cur_i < deflate0_length)) begin
                                            deflate0_oaddr <= deflate0_do;
                                            deflate0_obyte <= deflate0_b3;
                                            MYHDL73_adv(8);
                                            deflate0_cur_i <= (deflate0_cur_i + 1);
                                            deflate0_do <= (deflate0_do + 1);
                                            o_oprogress <= (deflate0_do + 1);
                                        end
                                        else if ((!deflate0_final)) begin
                                            deflate0_state <= 5'b00001;
                                        end
                                        else begin
                                            o_oprogress <= deflate0_do;
                                            o_done <= 1'b1;
                                            deflate0_state <= 5'b00000;
                                        end
                                    end
                                    else if ((deflate0_cur_i < (deflate0_length + 1))) begin
                                        deflate0_oraddr <= (deflate0_offset + deflate0_cur_i);
                                        if ((deflate0_cur_i == 1)) begin
                                            deflate0_copy1 <= deflate0_orbyte;
                                        end
                                        if ((deflate0_cur_i > 1)) begin
                                            if (((deflate0_offset + deflate0_cur_i) == (deflate0_do + 1))) begin
                                                deflate0_obyte <= deflate0_copy1;
                                            end
                                            else begin
                                                deflate0_obyte <= deflate0_orbyte;
                                            end
                                            deflate0_oaddr <= deflate0_do;
                                            o_oprogress <= (deflate0_do + 1);
                                            deflate0_do <= (deflate0_do + 1);
                                        end
                                        deflate0_cur_i <= (deflate0_cur_i + 1);
                                    end
                                    else begin
                                        deflate0_oaddr <= deflate0_do;
                                        if (((deflate0_offset + deflate0_cur_i) == (deflate0_do + 1))) begin
                                            deflate0_obyte <= deflate0_copy1;
                                        end
                                        else begin
                                            deflate0_obyte <= deflate0_orbyte;
                                        end
                                        deflate0_do <= (deflate0_do + 1);
                                        o_oprogress <= (deflate0_do + 1);
                                        deflate0_cur_next <= 0;
                                        deflate0_state <= 5'b10011;
                                    end
                                end
                                else begin
                                    $write("unknown state?!");
                                    $write("\n");
                                    deflate0_state <= 5'b00000;
                                end
                            end
                        end
                    endcase
                end
            end
        endcase
    end
end
 
 
always @(posedge i_clk) begin: TEST_DEFLATE_BENCH_DEFLATE0_FILL_BUF
    if ((!reset)) begin
        $write("FILL RESET");
        $write("\n");
        deflate0_nb <= 0;
        deflate0_b1 <= 0;
        deflate0_b2 <= 0;
        deflate0_b3 <= 0;
        deflate0_b4 <= 0;
    end
    else begin
        if ((deflate0_isize < 4)) begin
            // pass
        end
        else if (((i_mode == 4) || (i_mode == 5))) begin
            deflate0_nb <= 0;
        end
        else begin
            deflate0_nb <= 4;
            deflate0_b1 <= deflate0_iram[(deflate0_di & 127)];
            deflate0_b2 <= deflate0_iram[((deflate0_di + 1) & 127)];
            deflate0_b3 <= deflate0_iram[((deflate0_di + 2) & 127)];
            deflate0_b4 <= deflate0_iram[((deflate0_di + 3) & 127)];
        end
    end
end
 
 
always @(posedge i_clk) begin: TEST_DEFLATE_BENCH_DEFLATE0_ORAMWRITE
    deflate0_oram[deflate0_oaddr] <= deflate0_obyte;
    deflate0_leaves[deflate0_lwaddr] <= deflate0_wleaf;
end
 
 
always @(posedge i_clk) begin: TEST_DEFLATE_BENCH_DEFLATE0_ORAMREAD
    deflate0_orbyte <= deflate0_oram[deflate0_oraddr];
end
 
 
always @(posedge i_clk) begin: TEST_DEFLATE_BENCH_COUNT
    if ((scounter == 0)) begin
        counter <= (counter + 1);
    end
    scounter <= (scounter + 1);
end
 
 
always @(posedge i_clk) begin: TEST_DEFLATE_BENCH_LOGIC
    integer ud1;
    integer ud2;
    if ((tstate == 5'b00000)) begin
        $write("RESET");
        $write(" ");
        $write("%h", counter);
        $write("\n");
        reset <= 0;
        led0_g <= 0;
        led1_b <= 0;
        led2_r <= 0;
        tbi <= 0;
        tstate <= 5'b00001;
    end
    else if (((22 > 2) && (scounter != 0))) begin
        // pass
    end
    else if ((tstate == 5'b00001)) begin
        if ((tbi < 1)) begin
            tbi <= (tbi + 1);
        end
        else begin
            reset <= 1;
            tstate <= 5'b00010;
            tbi <= 0;
        end
    end
    else if ((tstate == 5'b10001)) begin
        led0_g <= 1;
        led2_r <= 0;
        led1_b <= 0;
    end
    else if ((tstate == 5'b10000)) begin
        led0_g <= (!led0_g);
        led2_r <= (!led2_r);
        led1_b <= o_done;
    end
    else if ((tstate == 5'b00010)) begin
        if ((tbi < 41)) begin
            o_led <= tbi;
            led1_b <= o_done;
            led2_r <= (!led2_r);
            i_mode <= 2;
            case (tbi)
                0: i_data <= 120;
                1: i_data <= 156;
                2: i_data <= 83;
                3: i_data <= 80;
                4: i_data <= 80;
                5: i_data <= 240;
                6: i_data <= 72;
                7: i_data <= 205;
                8: i_data <= 201;
                9: i_data <= 201;
                10: i_data <= 87;
                11: i_data <= 8;
                12: i_data <= 207;
                13: i_data <= 47;
                14: i_data <= 202;
                15: i_data <= 73;
                16: i_data <= 81;
                17: i_data <= 84;
                18: i_data <= 48;
                19: i_data <= 80;
                20: i_data <= 128;
                21: i_data <= 1;
                22: i_data <= 20;
                23: i_data <= 97;
                24: i_data <= 67;
                25: i_data <= 236;
                26: i_data <= 194;
                27: i_data <= 70;
                28: i_data <= 216;
                29: i_data <= 133;
                30: i_data <= 141;
                31: i_data <= 177;
                32: i_data <= 11;
                33: i_data <= 155;
                34: i_data <= 128;
                35: i_data <= 133;
                36: i_data <= 0;
                37: i_data <= 119;
                38: i_data <= 164;
                39: i_data <= 28;
                default: i_data <= 76;
            endcase
            i_addr <= tbi;
            tbi <= (tbi + 1);
        end
        else begin
            i_mode <= 0;
            led2_r <= 0;
            tstate <= 5'b00011;
        end
    end
    else if ((tstate == 5'b00011)) begin
        i_mode <= 5;
        tstate <= 5'b00100;
    end
    else if ((tstate == 5'b00100)) begin
        led1_b <= (!led1_b);
        i_mode <= 0;
        if (((i_mode == 0) && o_done)) begin
            $write("result len");
            $write(" ");
            $write("%h", o_oprogress);
            $write("\n");
            if ((o_oprogress == 79)) begin
                tstate <= 5'b10001;
            end
            resultlen <= o_oprogress;
            tbi <= 0;
            i_addr <= 0;
            i_mode <= 3;
            wtick <= 1'b1;
            tstate <= 5'b00101;
            // if o_oprogress == 0x4F:
            //     tstate.next = tb_state.HALT
            // else:
            //     tstate.next = tb_state.FAIL
        end
    end
    else if ((tstate == 5'b00101)) begin
        led1_b <= 0;
        o_led <= tbi;
        // Note that the read can also be pipelined in a tight loop
        // without the WTICK delay, but this will not work with
        // SLOWDOWN > 1
        if (wtick) begin
            wtick <= 1'b0;
        end
        else if ((tbi < 114)) begin
            led2_r <= (!led2_r);
            case (tbi)
                0: ud1 = 32;
                1: ud1 = 32;
                2: ud1 = 32;
                3: ud1 = 72;
                4: ud1 = 101;
                5: ud1 = 108;
                6: ud1 = 108;
                7: ud1 = 111;
                8: ud1 = 32;
                9: ud1 = 87;
                10: ud1 = 111;
                11: ud1 = 114;
                12: ud1 = 108;
                13: ud1 = 100;
                14: ud1 = 33;
                15: ud1 = 32;
                16: ud1 = 48;
                17: ud1 = 32;
                18: ud1 = 32;
                19: ud1 = 32;
                20: ud1 = 32;
                21: ud1 = 32;
                22: ud1 = 32;
                23: ud1 = 32;
                24: ud1 = 32;
                25: ud1 = 32;
                26: ud1 = 72;
                27: ud1 = 101;
                28: ud1 = 108;
                29: ud1 = 108;
                30: ud1 = 111;
                31: ud1 = 32;
                32: ud1 = 87;
                33: ud1 = 111;
                34: ud1 = 114;
                35: ud1 = 108;
                36: ud1 = 100;
                37: ud1 = 33;
                38: ud1 = 32;
                39: ud1 = 49;
                40: ud1 = 32;
                41: ud1 = 32;
                42: ud1 = 32;
                43: ud1 = 32;
                44: ud1 = 32;
                45: ud1 = 32;
                46: ud1 = 32;
                47: ud1 = 32;
                48: ud1 = 32;
                49: ud1 = 72;
                50: ud1 = 101;
                51: ud1 = 108;
                52: ud1 = 108;
                53: ud1 = 111;
                54: ud1 = 32;
                55: ud1 = 87;
                56: ud1 = 111;
                57: ud1 = 114;
                58: ud1 = 108;
                59: ud1 = 100;
                60: ud1 = 33;
                61: ud1 = 32;
                62: ud1 = 50;
                63: ud1 = 32;
                64: ud1 = 32;
                65: ud1 = 32;
                66: ud1 = 32;
                67: ud1 = 32;
                68: ud1 = 32;
                69: ud1 = 32;
                70: ud1 = 32;
                71: ud1 = 32;
                72: ud1 = 72;
                73: ud1 = 101;
                74: ud1 = 108;
                75: ud1 = 108;
                76: ud1 = 111;
                77: ud1 = 32;
                78: ud1 = 87;
                79: ud1 = 111;
                80: ud1 = 114;
                81: ud1 = 108;
                82: ud1 = 100;
                83: ud1 = 33;
                84: ud1 = 32;
                85: ud1 = 51;
                86: ud1 = 32;
                87: ud1 = 32;
                88: ud1 = 32;
                89: ud1 = 32;
                90: ud1 = 32;
                91: ud1 = 32;
                92: ud1 = 32;
                93: ud1 = 32;
                94: ud1 = 32;
                95: ud1 = 72;
                96: ud1 = 101;
                97: ud1 = 108;
                98: ud1 = 108;
                99: ud1 = 111;
                100: ud1 = 32;
                101: ud1 = 87;
                102: ud1 = 111;
                103: ud1 = 114;
                104: ud1 = 108;
                105: ud1 = 100;
                106: ud1 = 33;
                107: ud1 = 32;
                108: ud1 = 52;
                109: ud1 = 32;
                110: ud1 = 32;
                111: ud1 = 32;
                112: ud1 = 32;
                default: ud1 = 32;
            endcase
            if (($signed({1'b0, o_byte}) != ud1)) begin
                i_mode <= 0;
                $write("FAIL");
                $write(" ");
                $write("%0d", 114);
                $write(" ");
                $write("%h", tbi);
                $write(" ");
                $write("%h", o_byte);
                $write(" ");
                $write("%0d", ud1);
                $write("\n");
                tstate <= 5'b10000;
                $finish;
            end
            else begin
                // pass
            end
            i_addr <= (tbi + 1);
            tbi <= (tbi + 1);
            wtick <= 1'b1;
        end
        else begin
            $write("%0d", 114);
            $write("\n");
            $write("DECOMPRESS test OK!, pausing");
            $write(" ");
            $write("%h", tbi);
            $write("\n");
            i_mode <= 0;
            tbi <= 0;
            tstate <= 5'b00110;
            resume <= 1;
        end
    end
    else if ((tstate == 5'b00110)) begin
        led2_r <= 0;
        if ((resume == 0)) begin
            $write("--------------COMPRESS-------------");
            $write("\n");
            tbi <= 0;
            led0_g <= 0;
            tstate <= 5'b00111;
        end
        else begin
            led2_r <= (!led2_r);
            resume <= (resume + 1);
        end
    end
    else if ((tstate == 5'b00111)) begin
        o_led <= tbi;
        if ((tbi < 114)) begin
            led2_r <= 0;
            led1_b <= (!led1_b);
            i_mode <= 2;
            case (tbi)
                0: i_data <= 32;
                1: i_data <= 32;
                2: i_data <= 32;
                3: i_data <= 72;
                4: i_data <= 101;
                5: i_data <= 108;
                6: i_data <= 108;
                7: i_data <= 111;
                8: i_data <= 32;
                9: i_data <= 87;
                10: i_data <= 111;
                11: i_data <= 114;
                12: i_data <= 108;
                13: i_data <= 100;
                14: i_data <= 33;
                15: i_data <= 32;
                16: i_data <= 48;
                17: i_data <= 32;
                18: i_data <= 32;
                19: i_data <= 32;
                20: i_data <= 32;
                21: i_data <= 32;
                22: i_data <= 32;
                23: i_data <= 32;
                24: i_data <= 32;
                25: i_data <= 32;
                26: i_data <= 72;
                27: i_data <= 101;
                28: i_data <= 108;
                29: i_data <= 108;
                30: i_data <= 111;
                31: i_data <= 32;
                32: i_data <= 87;
                33: i_data <= 111;
                34: i_data <= 114;
                35: i_data <= 108;
                36: i_data <= 100;
                37: i_data <= 33;
                38: i_data <= 32;
                39: i_data <= 49;
                40: i_data <= 32;
                41: i_data <= 32;
                42: i_data <= 32;
                43: i_data <= 32;
                44: i_data <= 32;
                45: i_data <= 32;
                46: i_data <= 32;
                47: i_data <= 32;
                48: i_data <= 32;
                49: i_data <= 72;
                50: i_data <= 101;
                51: i_data <= 108;
                52: i_data <= 108;
                53: i_data <= 111;
                54: i_data <= 32;
                55: i_data <= 87;
                56: i_data <= 111;
                57: i_data <= 114;
                58: i_data <= 108;
                59: i_data <= 100;
                60: i_data <= 33;
                61: i_data <= 32;
                62: i_data <= 50;
                63: i_data <= 32;
                64: i_data <= 32;
                65: i_data <= 32;
                66: i_data <= 32;
                67: i_data <= 32;
                68: i_data <= 32;
                69: i_data <= 32;
                70: i_data <= 32;
                71: i_data <= 32;
                72: i_data <= 72;
                73: i_data <= 101;
                74: i_data <= 108;
                75: i_data <= 108;
                76: i_data <= 111;
                77: i_data <= 32;
                78: i_data <= 87;
                79: i_data <= 111;
                80: i_data <= 114;
                81: i_data <= 108;
                82: i_data <= 100;
                83: i_data <= 33;
                84: i_data <= 32;
                85: i_data <= 51;
                86: i_data <= 32;
                87: i_data <= 32;
                88: i_data <= 32;
                89: i_data <= 32;
                90: i_data <= 32;
                91: i_data <= 32;
                92: i_data <= 32;
                93: i_data <= 32;
                94: i_data <= 32;
                95: i_data <= 72;
                96: i_data <= 101;
                97: i_data <= 108;
                98: i_data <= 108;
                99: i_data <= 111;
                100: i_data <= 32;
                101: i_data <= 87;
                102: i_data <= 111;
                103: i_data <= 114;
                104: i_data <= 108;
                105: i_data <= 100;
                106: i_data <= 33;
                107: i_data <= 32;
                108: i_data <= 52;
                109: i_data <= 32;
                110: i_data <= 32;
                111: i_data <= 32;
                112: i_data <= 32;
                default: i_data <= 32;
            endcase
            i_addr <= tbi;
            tbi <= (tbi + 1);
        end
        else begin
            $write("wrote bytes to compress");
            $write(" ");
            $write("%h", tbi);
            $write("\n");
            i_mode <= 0;
            tstate <= 5'b01000;
        end
    end
    else if ((tstate == 5'b01000)) begin
        i_mode <= 4;
        tstate <= 5'b01001;
    end
    else if ((tstate == 5'b01001)) begin
        led2_r <= (!led2_r);
        if ((i_mode == 4)) begin
            $write("WAIT COMPRESS");
            $write("\n");
            i_mode <= 0;
            led1_b <= 0;
        end
        else if (o_done) begin
            $write("result len");
            $write(" ");
            $write("%h", o_oprogress);
            $write("\n");
            resultlen <= o_oprogress;
            tbi <= 0;
            i_addr <= 0;
            i_mode <= 3;
            tstate <= 5'b01010;
            wtick <= 1'b1;
        end
    end
    else if ((tstate == 5'b01010)) begin
        led2_r <= 0;
        o_led <= tbi;
        if (wtick) begin
            if ((tbi > 0)) begin
                i_mode <= 2;
                i_data <= copy;
                i_addr <= (tbi - 1);
            end
            wtick <= 1'b0;
            tbi <= (tbi + 1);
        end
        else if ((tbi < resultlen)) begin
            i_mode <= 3;
            led1_b <= (!led1_b);
            i_addr <= tbi;
            copy <= o_byte;
            wtick <= 1'b1;
        end
        else begin
            $write("Compress output bytes copied to input");
            $write(" ");
            $write("%h", resultlen);
            $write(" ");
            $write("%0d", ($signed({1'b0, tbi}) - 1));
            $write("\n");
            i_mode <= 0;
            tbi <= 0;
            tstate <= 5'b01100;
        end
    end
    else if ((tstate == 5'b01100)) begin
        $write("start decompress of test compression");
        $write("\n");
        i_mode <= 5;
        tstate <= 5'b01101;
    end
    else if ((tstate == 5'b01101)) begin
        led2_r <= 0;
        led1_b <= (!led1_b);
        i_mode <= 0;
        if (((i_mode == 0) && o_done)) begin
            $write("DONE DECOMPRESS VERIFY");
            $write(" ");
            $write("%h", o_oprogress);
            $write("\n");
            tbi <= 0;
            i_addr <= 0;
            i_mode <= 3;
            wtick <= 1'b1;
            tstate <= 5'b01110;
        end
    end
    else if ((tstate == 5'b01110)) begin
        led1_b <= 0;
        led2_r <= (!led2_r);
        o_led <= tbi;
        if (wtick) begin
            wtick <= 1'b0;
        end
        else if ((tbi < 114)) begin
            case (tbi)
                0: ud2 = 32;
                1: ud2 = 32;
                2: ud2 = 32;
                3: ud2 = 72;
                4: ud2 = 101;
                5: ud2 = 108;
                6: ud2 = 108;
                7: ud2 = 111;
                8: ud2 = 32;
                9: ud2 = 87;
                10: ud2 = 111;
                11: ud2 = 114;
                12: ud2 = 108;
                13: ud2 = 100;
                14: ud2 = 33;
                15: ud2 = 32;
                16: ud2 = 48;
                17: ud2 = 32;
                18: ud2 = 32;
                19: ud2 = 32;
                20: ud2 = 32;
                21: ud2 = 32;
                22: ud2 = 32;
                23: ud2 = 32;
                24: ud2 = 32;
                25: ud2 = 32;
                26: ud2 = 72;
                27: ud2 = 101;
                28: ud2 = 108;
                29: ud2 = 108;
                30: ud2 = 111;
                31: ud2 = 32;
                32: ud2 = 87;
                33: ud2 = 111;
                34: ud2 = 114;
                35: ud2 = 108;
                36: ud2 = 100;
                37: ud2 = 33;
                38: ud2 = 32;
                39: ud2 = 49;
                40: ud2 = 32;
                41: ud2 = 32;
                42: ud2 = 32;
                43: ud2 = 32;
                44: ud2 = 32;
                45: ud2 = 32;
                46: ud2 = 32;
                47: ud2 = 32;
                48: ud2 = 32;
                49: ud2 = 72;
                50: ud2 = 101;
                51: ud2 = 108;
                52: ud2 = 108;
                53: ud2 = 111;
                54: ud2 = 32;
                55: ud2 = 87;
                56: ud2 = 111;
                57: ud2 = 114;
                58: ud2 = 108;
                59: ud2 = 100;
                60: ud2 = 33;
                61: ud2 = 32;
                62: ud2 = 50;
                63: ud2 = 32;
                64: ud2 = 32;
                65: ud2 = 32;
                66: ud2 = 32;
                67: ud2 = 32;
                68: ud2 = 32;
                69: ud2 = 32;
                70: ud2 = 32;
                71: ud2 = 32;
                72: ud2 = 72;
                73: ud2 = 101;
                74: ud2 = 108;
                75: ud2 = 108;
                76: ud2 = 111;
                77: ud2 = 32;
                78: ud2 = 87;
                79: ud2 = 111;
                80: ud2 = 114;
                81: ud2 = 108;
                82: ud2 = 100;
                83: ud2 = 33;
                84: ud2 = 32;
                85: ud2 = 51;
                86: ud2 = 32;
                87: ud2 = 32;
                88: ud2 = 32;
                89: ud2 = 32;
                90: ud2 = 32;
                91: ud2 = 32;
                92: ud2 = 32;
                93: ud2 = 32;
                94: ud2 = 32;
                95: ud2 = 72;
                96: ud2 = 101;
                97: ud2 = 108;
                98: ud2 = 108;
                99: ud2 = 111;
                100: ud2 = 32;
                101: ud2 = 87;
                102: ud2 = 111;
                103: ud2 = 114;
                104: ud2 = 108;
                105: ud2 = 100;
                106: ud2 = 33;
                107: ud2 = 32;
                108: ud2 = 52;
                109: ud2 = 32;
                110: ud2 = 32;
                111: ud2 = 32;
                112: ud2 = 32;
                default: ud2 = 32;
            endcase
            if (($signed({1'b0, o_byte}) != ud2)) begin
                tstate <= 5'b00000;
                i_mode <= 0;
                $write("FAIL");
                $write(" ");
                $write("%0d", 114);
                $write(" ");
                $write("%h", tbi);
                $write(" ");
                $write("%0d", ud2);
                $write(" ");
                $write("%h", o_byte);
                $write("\n");
                $finish;
                tstate <= 5'b10000;
            end
            tbi <= (tbi + 1);
            i_addr <= (tbi + 1);
            wtick <= 1'b1;
        end
        else begin
            $write("%0d", 114);
            $write("\n");
            $write("ALL OK!");
            $write(" ");
            $write("%h", tbi);
            $write("\n");
            led2_r <= 0;
            i_mode <= 0;
            resume <= 1;
            if ((22 <= 4)) begin
                $finish;
            end
            //                 
            tstate <= 5'b01111;
        end
    end
    else if ((tstate == 5'b01111)) begin
        if ((resume == 0)) begin
            $write("--------------RESET-------------");
            $write("\n");
            o_led <= (o_led + 1);
            tstate <= 5'b00000;
        end
        else begin
            led0_g <= (!led0_g);
            resume <= (resume + 1);
        end
    end
    // if now() > 50000:
    //     raise StopSimulation()
end
 
endmodule
 

Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.