data/full_repos/permissive/51795816/sim/tb/blackjack_tb.v
1: b'%Warning-STMTDLY: data/full_repos/permissive/51795816/sim/tb/blackjack_tb.v:35: Unsupported: Ignoring delay on this delayed statement.\n  #5 CLK = !CLK;\n  ^\n                  ... Use "/* verilator lint_off STMTDLY */" and lint_on around source to disable this message.\n%Error: data/full_repos/permissive/51795816/sim/tb/blackjack_tb.v:61: Unsupported: wait statements\n    wait (CLK == 1\'b0);                    \n    ^~~~\n%Warning-STMTDLY: data/full_repos/permissive/51795816/sim/tb/blackjack_tb.v:62: Unsupported: Ignoring delay on this delayed statement.\n    #100 RESET = 1\'b1;                     \n    ^\n%Warning-STMTDLY: data/full_repos/permissive/51795816/sim/tb/blackjack_tb.v:63: Unsupported: Ignoring delay on this delayed statement.\n    #10 RESET = 1\'b0;                      \n    ^\n%Warning-STMTDLY: data/full_repos/permissive/51795816/sim/tb/blackjack_tb.v:64: Unsupported: Ignoring delay on this delayed statement.\n    #ATRASO_INICIAL;                       \n    ^\n%Warning-STMTDLY: data/full_repos/permissive/51795816/sim/tb/blackjack_tb.v:70: Unsupported: Ignoring delay on this delayed statement.\n        #5 CARD = DATA_GAME(game, i);           \n        ^\n%Warning-STMTDLY: data/full_repos/permissive/51795816/sim/tb/blackjack_tb.v:75: Unsupported: Ignoring delay on this delayed statement.\n        #5;                                \n        ^\n%Warning-STMTDLY: data/full_repos/permissive/51795816/sim/tb/blackjack_tb.v:83: Unsupported: Ignoring delay on this delayed statement.\n        #30 HIT = 1\'b1;                    \n        ^\n%Warning-STMTDLY: data/full_repos/permissive/51795816/sim/tb/blackjack_tb.v:84: Unsupported: Ignoring delay on this delayed statement.\n        #5  CARD = DATA_GAME(game, i);     \n        ^\n%Warning-STMTDLY: data/full_repos/permissive/51795816/sim/tb/blackjack_tb.v:87: Unsupported: Ignoring delay on this delayed statement.\n        #5 HIT = 1\'b0;                     \n        ^\n%Warning-STMTDLY: data/full_repos/permissive/51795816/sim/tb/blackjack_tb.v:89: Unsupported: Ignoring delay on this delayed statement.\n    #30 STAY = 1\'b1;                       \n    ^\n%Warning-STMTDLY: data/full_repos/permissive/51795816/sim/tb/blackjack_tb.v:93: Unsupported: Ignoring delay on this delayed statement.\n #20\n ^\n%Error: data/full_repos/permissive/51795816/sim/tb/blackjack_tb.v:97: syntax error, unexpected \'@\'\n        @(DHIT or DSTAY);\n        ^\n%Warning-STMTDLY: data/full_repos/permissive/51795816/sim/tb/blackjack_tb.v:103: Unsupported: Ignoring delay on this delayed statement.\n            #10;                               \n            ^\n%Warning-STMTDLY: data/full_repos/permissive/51795816/sim/tb/blackjack_tb.v:108: Unsupported: Ignoring delay on this delayed statement.\n    #30                                  \n    ^\n%Warning-STMTDLY: data/full_repos/permissive/51795816/sim/tb/blackjack_tb.v:121: Unsupported: Ignoring delay on this delayed statement.\n  # 100 $finish;\n  ^\n%Error: Exiting due to 2 error(s), 14 warning(s)\n        ... See the manual and https://verilator.org for more assistance.\n'
module blackjack_tb;

parameter ATRASO_INICIAL = 5;

reg CLK, RESET, STAY, HIT;
reg [3:0] CARD;
wire WIN, LOSE, TIE, DHIT, DSTAY;

reg [4:0] vPlayerHand, vDealerHand;
reg [3:0] i, game;

BlackJackFSM DUV (
  .clock(CLK),
  .reset(RESET),
  .stay(STAY),
  .hit(HIT),
  .card(CARD),
  .win(WIN),
  .lose(LOSE),
  .tie(TIE),
  .dhit(DHIT),
  .dstay(DSTAY) 	);

always
  #5 CLK = !CLK;

initial
begin
  CLK = 1'b1;
  RESET = 1'b0;
  STAY = 1'b0;
  HIT = 1'b0;
  CARD = 4'b0000;
end




initial
begin


  for (game = 0; game < 10; game = game + 1)
  begin

    vPlayerHand = 0;
    vDealerHand = 0;
    CARD = 4'b0000;
    HIT = 1'b1;
    STAY = 1'b0;
    wait (CLK == 1'b0);
    #100 RESET = 1'b1;
    #10 RESET = 1'b0;
    #ATRASO_INICIAL;


    HIT = 1'b1;
    for ( i = 0 ; i < 4 ; i = i + 1 )
    begin
        #5 CARD = DATA_GAME(game, i);
        if (i % 2 == 0)
          vPlayerHand = vPlayerHand + CARD;
        else
          vDealerHand = vDealerHand + CARD;
        #5;
    end
    HIT = 1'b0;


    i = 4;
    while (DATA_GAME(game, i) != 0)
    begin
        #30 HIT = 1'b1;
        #5  CARD = DATA_GAME(game, i);
        vPlayerHand = vPlayerHand + CARD;
        i = i + 1;
        #5 HIT = 1'b0;
    end
    #30 STAY = 1'b1;


    i = i + 1;
	#20
    CARD = DATA_GAME(game, i);
    while (DSTAY == 1'b0)
    begin
        @(DHIT or DSTAY);
        if (DHIT == 1'b1)
        begin
            vDealerHand = vDealerHand + CARD;
            i = i + 1;
            CARD = DATA_GAME(game, i);
            #10;
        end
    end


    #30
    if ({WIN,LOSE,TIE} == EXPECTED(game))
    begin
        case ({WIN,LOSE,TIE})
            3'b100:  $display("%d: Player wins!!! Test OK",game+1);
            3'b010:  $display("%d: Player lose!!! Test OK",game+1);
            3'b001:  $display("%d: Game drawn...  Test OK",game+1);
            default: $display("%d: Error!!!!!!!!!!!!!!!!!",game+1);
        endcase
    end
    else $display("Hard rapa is sweet but isn't soft. Fix the code.");

  end
  # 100 $finish;
end





function [3:0] DATA_GAME;
input [3:0] ROW;
input [3:0] COL;
begin
    case (ROW)

      0:  case (COL)

            0: DATA_GAME = 1;
            1: DATA_GAME = 9;
            2: DATA_GAME = 1;
            3: DATA_GAME = 9;

            4: DATA_GAME = 1;
            5: DATA_GAME = 1;
            6: DATA_GAME = 2;
            7: DATA_GAME = 2;
            8: DATA_GAME = 2;
            9: DATA_GAME = 2;
            10: DATA_GAME = 3;
            11: DATA_GAME = 3;
            12: DATA_GAME = 3;
            13: DATA_GAME = 0;

            14: DATA_GAME = 0;
            15: DATA_GAME = 0;
          endcase


      1:  case (COL)

            0: DATA_GAME = 9;
            1: DATA_GAME = 1;
            2: DATA_GAME = 9;
            3: DATA_GAME = 1;

            4: DATA_GAME = 0;

            5: DATA_GAME = 2;
            6: DATA_GAME = 1;
            7: DATA_GAME = 2;
            8: DATA_GAME = 1;
            9: DATA_GAME = 2;
            10: DATA_GAME = 2;
            11: DATA_GAME = 3;
            12: DATA_GAME = 6;
            13: DATA_GAME = 0;
            14: DATA_GAME = 0;
            15: DATA_GAME = 0;
          endcase


      2:  case (COL)

            0: DATA_GAME = 10;
            1: DATA_GAME = 3;
            2: DATA_GAME = 10;
            3: DATA_GAME = 3;

            4: DATA_GAME = 0;

            5: DATA_GAME = 2;
            6: DATA_GAME = 4;
            7: DATA_GAME = 3;
            8: DATA_GAME = 1;
            9: DATA_GAME = 1;
            10: DATA_GAME = 0;
            11: DATA_GAME = 0;
            12: DATA_GAME = 0;
            13: DATA_GAME = 0;
            14: DATA_GAME = 0;
            15: DATA_GAME = 0;
          endcase


      3:  case (COL)

            0: DATA_GAME = 3;
            1: DATA_GAME = 10;
            2: DATA_GAME = 3;
            3: DATA_GAME = 4;

            4: DATA_GAME = 2;
            5: DATA_GAME = 2;
            6: DATA_GAME = 4;
            7: DATA_GAME = 3;
            8: DATA_GAME = 0;

            9: DATA_GAME = 2;
            10: DATA_GAME = 4;
            11: DATA_GAME = 0;
            12: DATA_GAME = 0;
            13: DATA_GAME = 0;
            14: DATA_GAME = 0;
            15: DATA_GAME = 0;
          endcase


      4:  case (COL)

            0: DATA_GAME = 10;
            1: DATA_GAME = 11;
            2: DATA_GAME = 11;
            3: DATA_GAME = 11;

            4: DATA_GAME = 0;
            5: DATA_GAME = 0;
            6: DATA_GAME = 0;
            7: DATA_GAME = 0;
            8: DATA_GAME = 0;
            9: DATA_GAME = 0;
            10: DATA_GAME = 0;
            11: DATA_GAME = 0;
            12: DATA_GAME = 0;
            13: DATA_GAME = 0;
            14: DATA_GAME = 0;
            15: DATA_GAME = 0;
          endcase


      5:  case (COL)

            0: DATA_GAME = 5;
            1: DATA_GAME = 3;
            2: DATA_GAME = 5;
            3: DATA_GAME = 4;

            4: DATA_GAME = 2;
            5: DATA_GAME = 4;
            6: DATA_GAME = 1;
            7: DATA_GAME = 2;
            8: DATA_GAME = 0;

            9: DATA_GAME = 1;
            10: DATA_GAME = 1;
            11: DATA_GAME = 1;
            12: DATA_GAME = 3;
            13: DATA_GAME = 3;
            14: DATA_GAME = 9;
            15: DATA_GAME = 0;
          endcase


      6:  case (COL)

            0: DATA_GAME = 11;
            1: DATA_GAME = 10;
            2: DATA_GAME = 11;
            3: DATA_GAME = 11;

            4: DATA_GAME = 0;
            5: DATA_GAME = 0;
            6: DATA_GAME = 0;
            7: DATA_GAME = 0;
            8: DATA_GAME = 0;
            9: DATA_GAME = 0;
            10: DATA_GAME = 0;
            11: DATA_GAME = 0;
            12: DATA_GAME = 0;
            13: DATA_GAME = 0;
            14: DATA_GAME = 0;
            15: DATA_GAME = 0;
          endcase


      7:  case (COL)

            0: DATA_GAME = 5;
            1: DATA_GAME = 3;
            2: DATA_GAME = 5;
            3: DATA_GAME = 4;

            4: DATA_GAME = 7;
            5: DATA_GAME = 10;
            6: DATA_GAME = 0;
            7: DATA_GAME = 0;
            8: DATA_GAME = 0;
            9: DATA_GAME = 0;
            10: DATA_GAME = 0;
            11: DATA_GAME = 0;
            12: DATA_GAME = 0;
            13: DATA_GAME = 0;
            14: DATA_GAME = 0;
            15: DATA_GAME = 0;
          endcase


      8:  case (COL)

            0: DATA_GAME = 11;
            1: DATA_GAME = 10;
            2: DATA_GAME = 10;
            3: DATA_GAME = 11;

            4: DATA_GAME = 0;
            5: DATA_GAME = 0;
            6: DATA_GAME = 0;
            7: DATA_GAME = 0;
            8: DATA_GAME = 0;
            9: DATA_GAME = 0;
            10: DATA_GAME = 0;
            11: DATA_GAME = 0;
            12: DATA_GAME = 0;
            13: DATA_GAME = 0;
            14: DATA_GAME = 0;
            15: DATA_GAME = 0;
          endcase


      9:  case (COL)

            0: DATA_GAME = 9;
            1: DATA_GAME = 7;
            2: DATA_GAME = 8;
            3: DATA_GAME = 9;

            4: DATA_GAME = 0;

            5: DATA_GAME = 1;
            6: DATA_GAME = 0;
            7: DATA_GAME = 0;
            8: DATA_GAME = 0;
            9: DATA_GAME = 0;
            10: DATA_GAME = 0;
            11: DATA_GAME = 0;
            12: DATA_GAME = 0;
            13: DATA_GAME = 0;
            14: DATA_GAME = 0;
            15: DATA_GAME = 0;
          endcase
    endcase
end
endfunction





function [2:0] EXPECTED;
input [3:0] game;
begin
    case (game)
      0: EXPECTED = 3'b100;
      1: EXPECTED = 3'b010;
      2: EXPECTED = 3'b100;
      3: EXPECTED = 3'b010;
      4: EXPECTED = 3'b100;
      5: EXPECTED = 3'b100;
      6: EXPECTED = 3'b010;
      7: EXPECTED = 3'b010;
      8: EXPECTED = 3'b001;
      9: EXPECTED = 3'b001;
      default: EXPECTED = 3'b001;
    endcase
end
endfunction





initial
begin
  vPlayerHand = 0;
  vDealerHand = 0;


end

endmodule
module blackjack_tb;


parameter ATRASO_INICIAL = 5;

reg CLK, RESET, STAY, HIT;
reg [3:0] CARD;
wire WIN, LOSE, TIE, DHIT, DSTAY;

reg [4:0] vPlayerHand, vDealerHand;
reg [3:0] i, game;

BlackJackFSM DUV (
  .clock(CLK),
  .reset(RESET),
  .stay(STAY),
  .hit(HIT),
  .card(CARD),
  .win(WIN),
  .lose(LOSE),
  .tie(TIE),
  .dhit(DHIT),
  .dstay(DSTAY) 	);

always
  #5 CLK = !CLK;

initial
begin
  CLK = 1'b1;
  RESET = 1'b0;
  STAY = 1'b0;
  HIT = 1'b0;
  CARD = 4'b0000;
end




initial
begin


  for (game = 0; game < 10; game = game + 1)
  begin

    vPlayerHand = 0;
    vDealerHand = 0;
    CARD = 4'b0000;
    HIT = 1'b1;
    STAY = 1'b0;
    wait (CLK == 1'b0);
    #100 RESET = 1'b1;
    #10 RESET = 1'b0;
    #ATRASO_INICIAL;


    HIT = 1'b1;
    for ( i = 0 ; i < 4 ; i = i + 1 )
    begin
        #5 CARD = DATA_GAME(game, i);
        if (i % 2 == 0)
          vPlayerHand = vPlayerHand + CARD;
        else
          vDealerHand = vDealerHand + CARD;
        #5;
    end
    HIT = 1'b0;


    i = 4;
    while (DATA_GAME(game, i) != 0)
    begin
        #30 HIT = 1'b1;
        #5  CARD = DATA_GAME(game, i);
        vPlayerHand = vPlayerHand + CARD;
        i = i + 1;
        #5 HIT = 1'b0;
    end
    #30 STAY = 1'b1;


    i = i + 1;
	#20
    CARD = DATA_GAME(game, i);
    while (DSTAY == 1'b0)
    begin
        @(DHIT or DSTAY);
        if (DHIT == 1'b1)
        begin
            vDealerHand = vDealerHand + CARD;
            i = i + 1;
            CARD = DATA_GAME(game, i);
            #10;
        end
    end


    #30
    if ({WIN,LOSE,TIE} == EXPECTED(game))
    begin
        case ({WIN,LOSE,TIE})
            3'b100:  $display("%d: Player wins!!! Test OK",game+1);
            3'b010:  $display("%d: Player lose!!! Test OK",game+1);
            3'b001:  $display("%d: Game drawn...  Test OK",game+1);
            default: $display("%d: Error!!!!!!!!!!!!!!!!!",game+1);
        endcase
    end
    else $display("Hard rapa is sweet but isn't soft. Fix the code.");

  end
  # 100 $finish;
end





function [3:0] DATA_GAME;
input [3:0] ROW;
input [3:0] COL;
begin
    case (ROW)

      0:  case (COL)

            0: DATA_GAME = 1;
            1: DATA_GAME = 9;
            2: DATA_GAME = 1;
            3: DATA_GAME = 9;

            4: DATA_GAME = 1;
            5: DATA_GAME = 1;
            6: DATA_GAME = 2;
            7: DATA_GAME = 2;
            8: DATA_GAME = 2;
            9: DATA_GAME = 2;
            10: DATA_GAME = 3;
            11: DATA_GAME = 3;
            12: DATA_GAME = 3;
            13: DATA_GAME = 0;

            14: DATA_GAME = 0;
            15: DATA_GAME = 0;
          endcase


      1:  case (COL)

            0: DATA_GAME = 9;
            1: DATA_GAME = 1;
            2: DATA_GAME = 9;
            3: DATA_GAME = 1;

            4: DATA_GAME = 0;

            5: DATA_GAME = 2;
            6: DATA_GAME = 1;
            7: DATA_GAME = 2;
            8: DATA_GAME = 1;
            9: DATA_GAME = 2;
            10: DATA_GAME = 2;
            11: DATA_GAME = 3;
            12: DATA_GAME = 6;
            13: DATA_GAME = 0;
            14: DATA_GAME = 0;
            15: DATA_GAME = 0;
          endcase


      2:  case (COL)

            0: DATA_GAME = 10;
            1: DATA_GAME = 3;
            2: DATA_GAME = 10;
            3: DATA_GAME = 3;

            4: DATA_GAME = 0;

            5: DATA_GAME = 2;
            6: DATA_GAME = 4;
            7: DATA_GAME = 3;
            8: DATA_GAME = 1;
            9: DATA_GAME = 1;
            10: DATA_GAME = 0;
            11: DATA_GAME = 0;
            12: DATA_GAME = 0;
            13: DATA_GAME = 0;
            14: DATA_GAME = 0;
            15: DATA_GAME = 0;
          endcase


      3:  case (COL)

            0: DATA_GAME = 3;
            1: DATA_GAME = 10;
            2: DATA_GAME = 3;
            3: DATA_GAME = 4;

            4: DATA_GAME = 2;
            5: DATA_GAME = 2;
            6: DATA_GAME = 4;
            7: DATA_GAME = 3;
            8: DATA_GAME = 0;

            9: DATA_GAME = 2;
            10: DATA_GAME = 4;
            11: DATA_GAME = 0;
            12: DATA_GAME = 0;
            13: DATA_GAME = 0;
            14: DATA_GAME = 0;
            15: DATA_GAME = 0;
          endcase


      4:  case (COL)

            0: DATA_GAME = 10;
            1: DATA_GAME = 11;
            2: DATA_GAME = 11;
            3: DATA_GAME = 11;

            4: DATA_GAME = 0;
            5: DATA_GAME = 0;
            6: DATA_GAME = 0;
            7: DATA_GAME = 0;
            8: DATA_GAME = 0;
            9: DATA_GAME = 0;
            10: DATA_GAME = 0;
            11: DATA_GAME = 0;
            12: DATA_GAME = 0;
            13: DATA_GAME = 0;
            14: DATA_GAME = 0;
            15: DATA_GAME = 0;
          endcase


      5:  case (COL)

            0: DATA_GAME = 5;
            1: DATA_GAME = 3;
            2: DATA_GAME = 5;
            3: DATA_GAME = 4;

            4: DATA_GAME = 2;
            5: DATA_GAME = 4;
            6: DATA_GAME = 1;
            7: DATA_GAME = 2;
            8: DATA_GAME = 0;

            9: DATA_GAME = 1;
            10: DATA_GAME = 1;
            11: DATA_GAME = 1;
            12: DATA_GAME = 3;
            13: DATA_GAME = 3;
            14: DATA_GAME = 9;
            15: DATA_GAME = 0;
          endcase


      6:  case (COL)

            0: DATA_GAME = 11;
            1: DATA_GAME = 10;
            2: DATA_GAME = 11;
            3: DATA_GAME = 11;

            4: DATA_GAME = 0;
            5: DATA_GAME = 0;
            6: DATA_GAME = 0;
            7: DATA_GAME = 0;
            8: DATA_GAME = 0;
            9: DATA_GAME = 0;
            10: DATA_GAME = 0;
            11: DATA_GAME = 0;
            12: DATA_GAME = 0;
            13: DATA_GAME = 0;
            14: DATA_GAME = 0;
            15: DATA_GAME = 0;
          endcase


      7:  case (COL)

            0: DATA_GAME = 5;
            1: DATA_GAME = 3;
            2: DATA_GAME = 5;
            3: DATA_GAME = 4;

            4: DATA_GAME = 7;
            5: DATA_GAME = 10;
            6: DATA_GAME = 0;
            7: DATA_GAME = 0;
            8: DATA_GAME = 0;
            9: DATA_GAME = 0;
            10: DATA_GAME = 0;
            11: DATA_GAME = 0;
            12: DATA_GAME = 0;
            13: DATA_GAME = 0;
            14: DATA_GAME = 0;
            15: DATA_GAME = 0;
          endcase


      8:  case (COL)

            0: DATA_GAME = 11;
            1: DATA_GAME = 10;
            2: DATA_GAME = 10;
            3: DATA_GAME = 11;

            4: DATA_GAME = 0;
            5: DATA_GAME = 0;
            6: DATA_GAME = 0;
            7: DATA_GAME = 0;
            8: DATA_GAME = 0;
            9: DATA_GAME = 0;
            10: DATA_GAME = 0;
            11: DATA_GAME = 0;
            12: DATA_GAME = 0;
            13: DATA_GAME = 0;
            14: DATA_GAME = 0;
            15: DATA_GAME = 0;
          endcase


      9:  case (COL)

            0: DATA_GAME = 9;
            1: DATA_GAME = 7;
            2: DATA_GAME = 8;
            3: DATA_GAME = 9;

            4: DATA_GAME = 0;

            5: DATA_GAME = 1;
            6: DATA_GAME = 0;
            7: DATA_GAME = 0;
            8: DATA_GAME = 0;
            9: DATA_GAME = 0;
            10: DATA_GAME = 0;
            11: DATA_GAME = 0;
            12: DATA_GAME = 0;
            13: DATA_GAME = 0;
            14: DATA_GAME = 0;
            15: DATA_GAME = 0;
          endcase
    endcase
end
endfunction





function [2:0] EXPECTED;
input [3:0] game;
begin
    case (game)
      0: EXPECTED = 3'b100;
      1: EXPECTED = 3'b010;
      2: EXPECTED = 3'b100;
      3: EXPECTED = 3'b010;
      4: EXPECTED = 3'b100;
      5: EXPECTED = 3'b100;
      6: EXPECTED = 3'b010;
      7: EXPECTED = 3'b010;
      8: EXPECTED = 3'b001;
      9: EXPECTED = 3'b001;
      default: EXPECTED = 3'b001;
    endcase
end
endfunction





initial
begin
  vPlayerHand = 0;
  vDealerHand = 0;


end

endmodule