data/full_repos/permissive/469312749/FINAL1/work/verilog/game_cu_4.v
1: b'%Warning-WIDTH: data/full_repos/permissive/469312749/FINAL1/work/verilog/game_cu_4.v:83: Operator ASSIGN expects 2 bits on the Assign RHS, but Assign RHS\'s CONST \'3\'h0\' generates 3 bits.\n                                                                                       : ... In instance game_cu_4\n    asel = 3\'h0;\n         ^\n                ... Use "/* verilator lint_off WIDTH */" and lint_on around source to disable this message.\n%Warning-WIDTH: data/full_repos/permissive/469312749/FINAL1/work/verilog/game_cu_4.v:84: Operator ASSIGN expects 3 bits on the Assign RHS, but Assign RHS\'s CONST \'2\'h0\' generates 2 bits.\n                                                                                       : ... In instance game_cu_4\n    bsel = 2\'h0;\n         ^\n%Warning-WIDTH: data/full_repos/permissive/469312749/FINAL1/work/verilog/game_cu_4.v:85: Operator ASSIGN expects 1 bits on the Assign RHS, but Assign RHS\'s CONST \'4\'h0\' generates 4 bits.\n                                                                                       : ... In instance game_cu_4\n    we = 4\'h0;\n       ^\n%Warning-WIDTH: data/full_repos/permissive/469312749/FINAL1/work/verilog/game_cu_4.v:89: Operator ASSIGN expects 2 bits on the Assign RHS, but Assign RHS\'s CONST \'1\'h0\' generates 1 bits.\n                                                                                       : ... In instance game_cu_4\n    wdsel = 1\'h0;\n          ^\n%Warning-WIDTH: data/full_repos/permissive/469312749/FINAL1/work/verilog/game_cu_4.v:102: Operator ASSIGN expects 6 bits on the Assign RHS, but Assign RHS\'s CONST \'4\'h4\' generates 4 bits.\n                                                                                        : ... In instance game_cu_4\n        alufn = 4\'h4;\n              ^\n%Warning-WIDTH: data/full_repos/permissive/469312749/FINAL1/work/verilog/game_cu_4.v:109: Operator ASSIGN expects 6 bits on the Assign RHS, but Assign RHS\'s CONST \'4\'h3\' generates 4 bits.\n                                                                                        : ... In instance game_cu_4\n        alufn = 4\'h3;\n              ^\n%Warning-WIDTH: data/full_repos/permissive/469312749/FINAL1/work/verilog/game_cu_4.v:114: Operator EQ expects 16 bits on the RHS, but RHS\'s CONST \'1\'h1\' generates 1 bits.\n                                                                                        : ... In instance game_cu_4\n        if (isP1 == 1\'h1) begin\n                 ^~\n%Warning-WIDTH: data/full_repos/permissive/469312749/FINAL1/work/verilog/game_cu_4.v:127: Operator EQ expects 16 bits on the RHS, but RHS\'s CONST \'1\'h1\' generates 1 bits.\n                                                                                        : ... In instance game_cu_4\n        if (tempvar1 == 1\'h1) begin\n                     ^~\n%Warning-WIDTH: data/full_repos/permissive/469312749/FINAL1/work/verilog/game_cu_4.v:170: Operator EQ expects 16 bits on the RHS, but RHS\'s CONST \'1\'h1\' generates 1 bits.\n                                                                                        : ... In instance game_cu_4\n        if (tempvar1 == 1\'h1) begin\n                     ^~\n%Warning-WIDTH: data/full_repos/permissive/469312749/FINAL1/work/verilog/game_cu_4.v:222: Operator EQ expects 16 bits on the RHS, but RHS\'s CONST \'1\'h1\' generates 1 bits.\n                                                                                        : ... In instance game_cu_4\n        if (tempvar1 == 1\'h1) begin\n                     ^~\n%Warning-WIDTH: data/full_repos/permissive/469312749/FINAL1/work/verilog/game_cu_4.v:229: Operator ASSIGN expects 6 bits on the Assign RHS, but Assign RHS\'s CONST \'4\'hb\' generates 4 bits.\n                                                                                        : ... In instance game_cu_4\n        alufn = 4\'hb;\n              ^\n%Warning-WIDTH: data/full_repos/permissive/469312749/FINAL1/work/verilog/game_cu_4.v:237: Operator ASSIGN expects 6 bits on the Assign RHS, but Assign RHS\'s CONST \'4\'h3\' generates 4 bits.\n                                                                                        : ... In instance game_cu_4\n        alufn = 4\'h3;\n              ^\n%Warning-WIDTH: data/full_repos/permissive/469312749/FINAL1/work/verilog/game_cu_4.v:242: Operator EQ expects 16 bits on the RHS, but RHS\'s CONST \'1\'h1\' generates 1 bits.\n                                                                                        : ... In instance game_cu_4\n        if (tempvar2 == 1\'h1) begin\n                     ^~\n%Warning-WIDTH: data/full_repos/permissive/469312749/FINAL1/work/verilog/game_cu_4.v:277: Operator EQ expects 16 bits on the RHS, but RHS\'s CONST \'1\'h1\' generates 1 bits.\n                                                                                        : ... In instance game_cu_4\n        if (tempvar2 == 1\'h1) begin\n                     ^~\n%Warning-WIDTH: data/full_repos/permissive/469312749/FINAL1/work/verilog/game_cu_4.v:284: Operator ASSIGN expects 6 bits on the Assign RHS, but Assign RHS\'s CONST \'4\'hb\' generates 4 bits.\n                                                                                        : ... In instance game_cu_4\n        alufn = 4\'hb;\n              ^\n%Warning-WIDTH: data/full_repos/permissive/469312749/FINAL1/work/verilog/game_cu_4.v:306: Operator ASSIGN expects 6 bits on the Assign RHS, but Assign RHS\'s CONST \'4\'h3\' generates 4 bits.\n                                                                                        : ... In instance game_cu_4\n        alufn = 4\'h3;\n              ^\n%Warning-WIDTH: data/full_repos/permissive/469312749/FINAL1/work/verilog/game_cu_4.v:324: Operator ASSIGN expects 6 bits on the Assign RHS, but Assign RHS\'s CONST \'4\'h3\' generates 4 bits.\n                                                                                        : ... In instance game_cu_4\n        alufn = 4\'h3;\n              ^\n%Warning-WIDTH: data/full_repos/permissive/469312749/FINAL1/work/verilog/game_cu_4.v:339: Operator EQ expects 16 bits on the RHS, but RHS\'s CONST \'1\'h1\' generates 1 bits.\n                                                                                        : ... In instance game_cu_4\n        if (tempvar1 == 1\'h1) begin\n                     ^~\n%Warning-WIDTH: data/full_repos/permissive/469312749/FINAL1/work/verilog/game_cu_4.v:355: Operator ASSIGN expects 6 bits on the Assign RHS, but Assign RHS\'s CONST \'4\'h3\' generates 4 bits.\n                                                                                        : ... In instance game_cu_4\n        alufn = 4\'h3;\n              ^\n%Warning-WIDTH: data/full_repos/permissive/469312749/FINAL1/work/verilog/game_cu_4.v:374: Operator ASSIGN expects 6 bits on the Assign RHS, but Assign RHS\'s CONST \'4\'h3\' generates 4 bits.\n                                                                                        : ... In instance game_cu_4\n        alufn = 4\'h3;\n              ^\n%Warning-WIDTH: data/full_repos/permissive/469312749/FINAL1/work/verilog/game_cu_4.v:392: Operator ASSIGN expects 6 bits on the Assign RHS, but Assign RHS\'s CONST \'4\'h3\' generates 4 bits.\n                                                                                        : ... In instance game_cu_4\n        alufn = 4\'h3;\n              ^\n%Warning-WIDTH: data/full_repos/permissive/469312749/FINAL1/work/verilog/game_cu_4.v:407: Operator EQ expects 16 bits on the RHS, but RHS\'s CONST \'1\'h1\' generates 1 bits.\n                                                                                        : ... In instance game_cu_4\n        if (tempvar1 == 1\'h1) begin\n                     ^~\n%Warning-WIDTH: data/full_repos/permissive/469312749/FINAL1/work/verilog/game_cu_4.v:428: Operator ASSIGN expects 6 bits on the Assign RHS, but Assign RHS\'s CONST \'4\'h4\' generates 4 bits.\n                                                                                        : ... In instance game_cu_4\n        alufn = 4\'h4;\n              ^\n%Warning-WIDTH: data/full_repos/permissive/469312749/FINAL1/work/verilog/game_cu_4.v:442: Operator EQ expects 16 bits on the RHS, but RHS\'s CONST \'1\'h1\' generates 1 bits.\n                                                                                        : ... In instance game_cu_4\n        if (tempvar1 == 1\'h1) begin\n                     ^~\n%Warning-WIDTH: data/full_repos/permissive/469312749/FINAL1/work/verilog/game_cu_4.v:456: Operator EQ expects 16 bits on the RHS, but RHS\'s CONST \'1\'h1\' generates 1 bits.\n                                                                                        : ... In instance game_cu_4\n        if (tempvar2 == 1\'h1) begin\n                     ^~\n%Warning-WIDTH: data/full_repos/permissive/469312749/FINAL1/work/verilog/game_cu_4.v:463: Operator ASSIGN expects 6 bits on the Assign RHS, but Assign RHS\'s CONST \'4\'h3\' generates 4 bits.\n                                                                                        : ... In instance game_cu_4\n        alufn = 4\'h3;\n              ^\n%Warning-WIDTH: data/full_repos/permissive/469312749/FINAL1/work/verilog/game_cu_4.v:472: Operator ASSIGN expects 6 bits on the Assign RHS, but Assign RHS\'s CONST \'4\'h3\' generates 4 bits.\n                                                                                        : ... In instance game_cu_4\n        alufn = 4\'h3;\n              ^\n%Warning-WIDTH: data/full_repos/permissive/469312749/FINAL1/work/verilog/game_cu_4.v:481: Operator ASSIGN expects 6 bits on the Assign RHS, but Assign RHS\'s CONST \'4\'h4\' generates 4 bits.\n                                                                                        : ... In instance game_cu_4\n        alufn = 4\'h4;\n              ^\n%Error: Exiting due to 28 warning(s)\n'
module game_cu_4 (
    input clk,
    input rst,
    input btn1,
    input btn2,
    input btn_reset,
    input [15:0] p1_sequence,
    input [15:0] p2_sequence,
    input [15:0] sequenceCount,
    input [15:0] isP1,
    input [15:0] tempvar1,
    input [15:0] tempvar2,
    output reg we,
    output reg [3:0] ra,
    output reg [3:0] rb,
    output reg [3:0] rc,
    output reg [1:0] asel,
    output reg [2:0] bsel,
    output reg [1:0] wdsel,
    output reg [5:0] alufn,
    output reg green_led,
    output reg red_led,
    output reg split_yes
  );
  
  
  
  localparam START_game_fsm = 6'd0;
  localparam IDLE_game_fsm = 6'd1;
  localparam PLAYER1_PRESS_game_fsm = 6'd2;
  localparam PLAYER1_PRESS_WRITE_VALUE_game_fsm = 6'd3;
  localparam PLAYER1_PRESS_ADD_TO_SEQUENCE_game_fsm = 6'd4;
  localparam PLAYER1_PRESS_INCREMENT_LOOPVAR_game_fsm = 6'd5;
  localparam PLAYER2_PRESS_game_fsm = 6'd6;
  localparam PLAYER2_PRESS_WRITE_VALUE_game_fsm = 6'd7;
  localparam PLAYER2_PRESS_ADD_TO_SEQUENCE_game_fsm = 6'd8;
  localparam PLAYER2_PRESS_INCREMENT_LOOPVAR_game_fsm = 6'd9;
  localparam INCREMENT_SEQUENCECOUNT_game_fsm = 6'd10;
  localparam CPMLEQ_SEQUENCECOUNT_1_game_fsm = 6'd11;
  localparam NOT_ISP1_game_fsm = 6'd12;
  localparam NOT_ISP1_CMP_game_fsm = 6'd13;
  localparam CMPEQ_P1SEQUENCE_P2SEQUENCE_game_fsm = 6'd14;
  localparam CMP_SEQ_ISP1_game_fsm = 6'd15;
  localparam CMP_SEQ_NOTISP1_game_fsm = 6'd16;
  localparam UPDATE_LED_GREEN_game_fsm = 6'd17;
  localparam UPDATE_LED_RED_game_fsm = 6'd18;
  localparam TURN_LED_OFF_game_fsm = 6'd19;
  localparam CPMLE_SEQUENCECOUNT_16_game_fsm = 6'd20;
  localparam CMPEQ_ISP1_0_game_fsm = 6'd21;
  localparam INCREMENT_P1_SCORE_game_fsm = 6'd22;
  localparam INCREMENT_P2_SCORE_game_fsm = 6'd23;
  localparam INCREMENT_P1_SCORE_SEG_game_fsm = 6'd24;
  localparam INCREMENT_P2_SCORE_SEG_game_fsm = 6'd25;
  localparam INCREMENT_P1_SCORE_CMP_game_fsm = 6'd26;
  localparam INCREMENT_P2_SCORE_CMP_game_fsm = 6'd27;
  localparam INCREMENT_P1_SCORE_CMP_SEG_game_fsm = 6'd28;
  localparam INCREMENT_P2_SCORE_CMP_SEG_game_fsm = 6'd29;
  localparam INCREMENT_ROUND_game_fsm = 6'd30;
  localparam INCREMENT_ROUND_SEG_game_fsm = 6'd31;
  localparam CMPLEQC_ROUND_5_game_fsm = 6'd32;
  localparam RESET_SEQUENCE_COUNT_game_fsm = 6'd33;
  localparam TURN_LED_OFF1_game_fsm = 6'd34;
  localparam CMPLEQ_P1_SCORE_P2SCORE_game_fsm = 6'd35;
  localparam CMPEQ_P1_SCORE_P2SCORE_game_fsm = 6'd36;
  localparam P1_WINNER_game_fsm = 6'd37;
  localparam P2_WINNER_game_fsm = 6'd38;
  localparam TIE_game_fsm = 6'd39;
  localparam SET_ISP1_1_game_fsm = 6'd40;
  localparam END_game_fsm = 6'd41;
  
  reg [5:0] M_game_fsm_d, M_game_fsm_q = START_game_fsm;
  
  always @* begin
    M_game_fsm_d = M_game_fsm_q;
    
    alufn = 6'h3f;
    asel = 3'h0;
    bsel = 2'h0;
    we = 4'h0;
    ra = 4'h0;
    rb = 4'h0;
    rc = 4'h0;
    wdsel = 1'h0;
    green_led = 1'h0;
    red_led = 1'h0;
    split_yes = 1'h0;
    if (rst) begin
      M_game_fsm_d = START_game_fsm;
    end
    if (btn_reset && M_game_fsm_q != START_game_fsm) begin
      M_game_fsm_d = START_game_fsm;
    end
    
    case (M_game_fsm_q)
      START_game_fsm: begin
        alufn = 4'h4;
        bsel = 3'h2;
        rc = 4'h6;
        we = 1'h1;
        M_game_fsm_d = IDLE_game_fsm;
      end
      IDLE_game_fsm: begin
        alufn = 4'h3;
        asel = 2'h0;
        ra = 4'h6;
        rc = 4'h7;
        we = 1'h1;
        if (isP1 == 1'h1) begin
          M_game_fsm_d = PLAYER1_PRESS_game_fsm;
        end else begin
          M_game_fsm_d = PLAYER2_PRESS_game_fsm;
        end
      end
      PLAYER1_PRESS_game_fsm: begin
        alufn = 6'h36;
        asel = 2'h0;
        bsel = 3'h0;
        ra = 4'h9;
        rb = 4'hb;
        rc = 4'h7;
        if (tempvar1 == 1'h1) begin
          M_game_fsm_d = PLAYER1_PRESS_WRITE_VALUE_game_fsm;
        end else begin
          M_game_fsm_d = INCREMENT_SEQUENCECOUNT_game_fsm;
        end
      end
      PLAYER1_PRESS_WRITE_VALUE_game_fsm: begin
        if (btn2) begin
          rc = 4'h9;
          we = 1'h1;
          M_game_fsm_d = PLAYER1_PRESS_ADD_TO_SEQUENCE_game_fsm;
        end else begin
          if (btn1) begin
            M_game_fsm_d = PLAYER1_PRESS_game_fsm;
          end
        end
      end
      PLAYER1_PRESS_ADD_TO_SEQUENCE_game_fsm: begin
        alufn = 6'h00;
        asel = 2'h0;
        bsel = 3'h0;
        ra = 4'h0;
        rb = 4'h9;
        rc = 4'h0;
        we = 1'h1;
        M_game_fsm_d = PLAYER1_PRESS_INCREMENT_LOOPVAR_game_fsm;
      end
      PLAYER1_PRESS_INCREMENT_LOOPVAR_game_fsm: begin
        alufn = 6'h00;
        asel = 2'h0;
        bsel = 3'h2;
        ra = 4'h9;
        rc = 4'h9;
        we = 1'h1;
        M_game_fsm_d = PLAYER1_PRESS_game_fsm;
      end
      PLAYER2_PRESS_game_fsm: begin
        alufn = 6'h36;
        asel = 2'h0;
        bsel = 3'h0;
        ra = 4'h9;
        rb = 4'h6;
        rc = 4'h7;
        if (tempvar1 == 1'h1) begin
          M_game_fsm_d = PLAYER2_PRESS_WRITE_VALUE_game_fsm;
        end else begin
          M_game_fsm_d = INCREMENT_SEQUENCECOUNT_game_fsm;
        end
      end
      PLAYER2_PRESS_WRITE_VALUE_game_fsm: begin
        if (btn2) begin
          rc = 4'h9;
          we = 1'h1;
          M_game_fsm_d = PLAYER2_PRESS_ADD_TO_SEQUENCE_game_fsm;
        end else begin
          if (btn1) begin
            M_game_fsm_d = PLAYER2_PRESS_game_fsm;
          end
        end
      end
      PLAYER2_PRESS_ADD_TO_SEQUENCE_game_fsm: begin
        alufn = 6'h00;
        asel = 2'h0;
        bsel = 3'h0;
        ra = 4'h0;
        rb = 4'h9;
        rc = 4'h0;
        we = 1'h1;
        M_game_fsm_d = PLAYER1_PRESS_INCREMENT_LOOPVAR_game_fsm;
      end
      PLAYER2_PRESS_INCREMENT_LOOPVAR_game_fsm: begin
        alufn = 6'h00;
        asel = 2'h0;
        bsel = 3'h2;
        ra = 4'h9;
        rc = 4'h9;
        we = 1'h1;
        M_game_fsm_d = PLAYER2_PRESS_game_fsm;
      end
      INCREMENT_SEQUENCECOUNT_game_fsm: begin
        alufn = 6'h00;
        asel = 2'h0;
        bsel = 3'h2;
        ra = 4'h2;
        rc = 4'h2;
        we = 1'h1;
        M_game_fsm_d = CPMLEQ_SEQUENCECOUNT_1_game_fsm;
      end
      CPMLEQ_SEQUENCECOUNT_1_game_fsm: begin
        alufn = 6'h1a;
        asel = 2'h0;
        bsel = 3'h2;
        ra = 4'h2;
        rc = 4'h7;
        we = 1'h1;
        if (tempvar1 == 1'h1) begin
          M_game_fsm_d = NOT_ISP1_game_fsm;
        end else begin
          M_game_fsm_d = CMPEQ_P1SEQUENCE_P2SEQUENCE_game_fsm;
        end
      end
      NOT_ISP1_game_fsm: begin
        alufn = 4'hb;
        asel = 2'h0;
        ra = 4'h6;
        rc = 4'h6;
        we = 1'h1;
        M_game_fsm_d = IDLE_game_fsm;
      end
      CMPEQ_P1SEQUENCE_P2SEQUENCE_game_fsm: begin
        alufn = 4'h3;
        asel = 2'h0;
        ra = 4'h6;
        rc = 4'h8;
        we = 1'h1;
        if (tempvar2 == 1'h1) begin
          M_game_fsm_d = CMP_SEQ_ISP1_game_fsm;
        end else begin
          M_game_fsm_d = CMP_SEQ_NOTISP1_game_fsm;
        end
      end
      CMP_SEQ_ISP1_game_fsm: begin
        if (p1_sequence == p2_sequence) begin
          M_game_fsm_d = UPDATE_LED_GREEN_game_fsm;
        end else begin
          M_game_fsm_d = UPDATE_LED_RED_game_fsm;
        end
      end
      CMP_SEQ_NOTISP1_game_fsm: begin
        if (p1_sequence == p2_sequence) begin
          M_game_fsm_d = UPDATE_LED_GREEN_game_fsm;
        end else begin
          M_game_fsm_d = UPDATE_LED_RED_game_fsm;
        end
      end
      UPDATE_LED_GREEN_game_fsm: begin
        green_led = 1'h1;
        M_game_fsm_d = CPMLE_SEQUENCECOUNT_16_game_fsm;
      end
      UPDATE_LED_RED_game_fsm: begin
        red_led = 1'h1;
        M_game_fsm_d = CMPEQ_ISP1_0_game_fsm;
      end
      CPMLE_SEQUENCECOUNT_16_game_fsm: begin
        alufn = 6'h36;
        asel = 2'h0;
        bsel = 3'h4;
        ra = 4'h2;
        rc = 4'h8;
        we = 1'h1;
        if (tempvar2 == 1'h1) begin
          M_game_fsm_d = NOT_ISP1_CMP_game_fsm;
        end else begin
          M_game_fsm_d = INCREMENT_P1_SCORE_game_fsm;
        end
      end
      NOT_ISP1_CMP_game_fsm: begin
        alufn = 4'hb;
        asel = 2'h0;
        ra = 4'h6;
        rc = 4'h6;
        we = 1'h1;
        M_game_fsm_d = TURN_LED_OFF_game_fsm;
      end
      TURN_LED_OFF_game_fsm: begin
        green_led = 1'h0;
        red_led = 1'h0;
        M_game_fsm_d = IDLE_game_fsm;
      end
      INCREMENT_P1_SCORE_game_fsm: begin
        alufn = 6'h00;
        asel = 2'h0;
        bsel = 3'h2;
        ra = 4'h3;
        rc = 4'h3;
        we = 1'h1;
        M_game_fsm_d = INCREMENT_P1_SCORE_SEG_game_fsm;
      end
      INCREMENT_P1_SCORE_SEG_game_fsm: begin
        alufn = 4'h3;
        asel = 2'h0;
        ra = 4'h3;
        rc = 4'ha;
        we = 1'h1;
        split_yes = 1'h1;
        M_game_fsm_d = INCREMENT_P2_SCORE_game_fsm;
      end
      INCREMENT_P2_SCORE_game_fsm: begin
        alufn = 6'h00;
        asel = 2'h0;
        bsel = 3'h2;
        ra = 4'h4;
        rc = 4'h4;
        we = 1'h1;
        M_game_fsm_d = INCREMENT_P2_SCORE_SEG_game_fsm;
      end
      INCREMENT_P2_SCORE_SEG_game_fsm: begin
        alufn = 4'h3;
        asel = 2'h0;
        ra = 4'h4;
        rc = 4'ha;
        we = 1'h1;
        split_yes = 1'h1;
        M_game_fsm_d = INCREMENT_ROUND_game_fsm;
      end
      CMPEQ_ISP1_0_game_fsm: begin
        alufn = 6'h32;
        asel = 2'h0;
        bsel = 3'h1;
        ra = 4'h6;
        rc = 4'h7;
        we = 1'h1;
        if (tempvar1 == 1'h1) begin
          M_game_fsm_d = INCREMENT_P1_SCORE_CMP_game_fsm;
        end else begin
          M_game_fsm_d = INCREMENT_P2_SCORE_CMP_game_fsm;
        end
      end
      INCREMENT_P1_SCORE_CMP_game_fsm: begin
        alufn = 6'h00;
        asel = 2'h0;
        bsel = 3'h2;
        ra = 4'h3;
        rc = 4'h3;
        we = 1'h1;
        M_game_fsm_d = INCREMENT_P1_SCORE_CMP_SEG_game_fsm;
      end
      INCREMENT_P1_SCORE_CMP_SEG_game_fsm: begin
        alufn = 4'h3;
        asel = 2'h0;
        ra = 4'h3;
        rc = 4'ha;
        we = 1'h1;
        split_yes = 1'h1;
        M_game_fsm_d = INCREMENT_ROUND_game_fsm;
      end
      INCREMENT_P2_SCORE_CMP_game_fsm: begin
        alufn = 6'h00;
        asel = 2'h0;
        bsel = 3'h2;
        ra = 4'h4;
        rc = 4'h4;
        we = 1'h1;
        split_yes = 1'h1;
        M_game_fsm_d = INCREMENT_P2_SCORE_CMP_SEG_game_fsm;
      end
      INCREMENT_P2_SCORE_CMP_SEG_game_fsm: begin
        alufn = 4'h3;
        asel = 2'h0;
        ra = 4'h4;
        rc = 4'ha;
        we = 1'h1;
        split_yes = 1'h1;
        M_game_fsm_d = INCREMENT_ROUND_game_fsm;
      end
      INCREMENT_ROUND_game_fsm: begin
        alufn = 6'h00;
        asel = 2'h0;
        bsel = 3'h2;
        ra = 4'h5;
        rc = 4'h5;
        we = 1'h1;
        M_game_fsm_d = INCREMENT_ROUND_SEG_game_fsm;
      end
      INCREMENT_ROUND_SEG_game_fsm: begin
        alufn = 4'h3;
        asel = 2'h0;
        ra = 4'h5;
        rc = 4'ha;
        we = 1'h1;
        split_yes = 1'h1;
        M_game_fsm_d = CMPLEQC_ROUND_5_game_fsm;
      end
      CMPLEQC_ROUND_5_game_fsm: begin
        alufn = 6'h36;
        asel = 2'h0;
        bsel = 3'h3;
        ra = 4'h5;
        rc = 4'h7;
        we = 1'h1;
        if (tempvar1 == 1'h1) begin
          M_game_fsm_d = RESET_SEQUENCE_COUNT_game_fsm;
        end else begin
          M_game_fsm_d = CMPLEQ_P1_SCORE_P2SCORE_game_fsm;
        end
      end
      RESET_SEQUENCE_COUNT_game_fsm: begin
        alufn = 6'h00;
        asel = 2'h0;
        bsel = 3'h1;
        ra = 4'h2;
        rc = 4'h2;
        we = 1'h1;
        M_game_fsm_d = TURN_LED_OFF1_game_fsm;
      end
      TURN_LED_OFF1_game_fsm: begin
        green_led = 1'h0;
        red_led = 1'h0;
        M_game_fsm_d = SET_ISP1_1_game_fsm;
      end
      SET_ISP1_1_game_fsm: begin
        alufn = 4'h4;
        bsel = 3'h2;
        rc = 4'h6;
        we = 1'h1;
        M_game_fsm_d = IDLE_game_fsm;
      end
      CMPLEQ_P1_SCORE_P2SCORE_game_fsm: begin
        alufn = 6'h36;
        asel = 2'h0;
        bsel = 3'h0;
        ra = 4'h3;
        rb = 4'h4;
        rc = 4'h7;
        we = 1'h1;
        if (tempvar1 == 1'h1) begin
          M_game_fsm_d = P2_WINNER_game_fsm;
        end else begin
          M_game_fsm_d = CMPEQ_P1_SCORE_P2SCORE_game_fsm;
        end
      end
      CMPEQ_P1_SCORE_P2SCORE_game_fsm: begin
        alufn = 6'h32;
        asel = 2'h0;
        bsel = 3'h0;
        ra = 4'h3;
        rb = 4'h4;
        rc = 4'h8;
        we = 1'h1;
        if (tempvar2 == 1'h1) begin
          M_game_fsm_d = TIE_game_fsm;
        end else begin
          M_game_fsm_d = P1_WINNER_game_fsm;
        end
      end
      P1_WINNER_game_fsm: begin
        alufn = 4'h3;
        asel = 2'h0;
        ra = 4'h3;
        rc = 4'ha;
        we = 1'h1;
        split_yes = 1'h1;
        M_game_fsm_d = END_game_fsm;
      end
      P2_WINNER_game_fsm: begin
        alufn = 4'h3;
        asel = 2'h0;
        ra = 4'h4;
        rc = 4'ha;
        we = 1'h1;
        split_yes = 1'h1;
        M_game_fsm_d = END_game_fsm;
      end
      TIE_game_fsm: begin
        alufn = 4'h4;
        bsel = 3'h5;
        rc = 4'ha;
        split_yes = 1'h1;
        we = 1'h1;
        M_game_fsm_d = END_game_fsm;
      end
      END_game_fsm: begin
        split_yes = 1'h0;
        green_led = 1'h0;
        red_led = 1'h0;
        M_game_fsm_d = START_game_fsm;
      end
      default: begin
        M_game_fsm_d = START_game_fsm;
      end
    endcase
  end
  
  always @(posedge clk) begin
    M_game_fsm_q <= M_game_fsm_d;
  end
  
endmodule
module game_cu_4 (
    input clk,
    input rst,
    input btn1,
    input btn2,
    input btn_reset,
    input [15:0] p1_sequence,
    input [15:0] p2_sequence,
    input [15:0] sequenceCount,
    input [15:0] isP1,
    input [15:0] tempvar1,
    input [15:0] tempvar2,
    output reg we,
    output reg [3:0] ra,
    output reg [3:0] rb,
    output reg [3:0] rc,
    output reg [1:0] asel,
    output reg [2:0] bsel,
    output reg [1:0] wdsel,
    output reg [5:0] alufn,
    output reg green_led,
    output reg red_led,
    output reg split_yes
  );

  
  
  
  localparam START_game_fsm = 6'd0;
  localparam IDLE_game_fsm = 6'd1;
  localparam PLAYER1_PRESS_game_fsm = 6'd2;
  localparam PLAYER1_PRESS_WRITE_VALUE_game_fsm = 6'd3;
  localparam PLAYER1_PRESS_ADD_TO_SEQUENCE_game_fsm = 6'd4;
  localparam PLAYER1_PRESS_INCREMENT_LOOPVAR_game_fsm = 6'd5;
  localparam PLAYER2_PRESS_game_fsm = 6'd6;
  localparam PLAYER2_PRESS_WRITE_VALUE_game_fsm = 6'd7;
  localparam PLAYER2_PRESS_ADD_TO_SEQUENCE_game_fsm = 6'd8;
  localparam PLAYER2_PRESS_INCREMENT_LOOPVAR_game_fsm = 6'd9;
  localparam INCREMENT_SEQUENCECOUNT_game_fsm = 6'd10;
  localparam CPMLEQ_SEQUENCECOUNT_1_game_fsm = 6'd11;
  localparam NOT_ISP1_game_fsm = 6'd12;
  localparam NOT_ISP1_CMP_game_fsm = 6'd13;
  localparam CMPEQ_P1SEQUENCE_P2SEQUENCE_game_fsm = 6'd14;
  localparam CMP_SEQ_ISP1_game_fsm = 6'd15;
  localparam CMP_SEQ_NOTISP1_game_fsm = 6'd16;
  localparam UPDATE_LED_GREEN_game_fsm = 6'd17;
  localparam UPDATE_LED_RED_game_fsm = 6'd18;
  localparam TURN_LED_OFF_game_fsm = 6'd19;
  localparam CPMLE_SEQUENCECOUNT_16_game_fsm = 6'd20;
  localparam CMPEQ_ISP1_0_game_fsm = 6'd21;
  localparam INCREMENT_P1_SCORE_game_fsm = 6'd22;
  localparam INCREMENT_P2_SCORE_game_fsm = 6'd23;
  localparam INCREMENT_P1_SCORE_SEG_game_fsm = 6'd24;
  localparam INCREMENT_P2_SCORE_SEG_game_fsm = 6'd25;
  localparam INCREMENT_P1_SCORE_CMP_game_fsm = 6'd26;
  localparam INCREMENT_P2_SCORE_CMP_game_fsm = 6'd27;
  localparam INCREMENT_P1_SCORE_CMP_SEG_game_fsm = 6'd28;
  localparam INCREMENT_P2_SCORE_CMP_SEG_game_fsm = 6'd29;
  localparam INCREMENT_ROUND_game_fsm = 6'd30;
  localparam INCREMENT_ROUND_SEG_game_fsm = 6'd31;
  localparam CMPLEQC_ROUND_5_game_fsm = 6'd32;
  localparam RESET_SEQUENCE_COUNT_game_fsm = 6'd33;
  localparam TURN_LED_OFF1_game_fsm = 6'd34;
  localparam CMPLEQ_P1_SCORE_P2SCORE_game_fsm = 6'd35;
  localparam CMPEQ_P1_SCORE_P2SCORE_game_fsm = 6'd36;
  localparam P1_WINNER_game_fsm = 6'd37;
  localparam P2_WINNER_game_fsm = 6'd38;
  localparam TIE_game_fsm = 6'd39;
  localparam SET_ISP1_1_game_fsm = 6'd40;
  localparam END_game_fsm = 6'd41;
  
  reg [5:0] M_game_fsm_d, M_game_fsm_q = START_game_fsm;
  
  always @* begin
    M_game_fsm_d = M_game_fsm_q;
    
    alufn = 6'h3f;
    asel = 3'h0;
    bsel = 2'h0;
    we = 4'h0;
    ra = 4'h0;
    rb = 4'h0;
    rc = 4'h0;
    wdsel = 1'h0;
    green_led = 1'h0;
    red_led = 1'h0;
    split_yes = 1'h0;
    if (rst) begin
      M_game_fsm_d = START_game_fsm;
    end
    if (btn_reset && M_game_fsm_q != START_game_fsm) begin
      M_game_fsm_d = START_game_fsm;
    end
    
    case (M_game_fsm_q)
      START_game_fsm: begin
        alufn = 4'h4;
        bsel = 3'h2;
        rc = 4'h6;
        we = 1'h1;
        M_game_fsm_d = IDLE_game_fsm;
      end
      IDLE_game_fsm: begin
        alufn = 4'h3;
        asel = 2'h0;
        ra = 4'h6;
        rc = 4'h7;
        we = 1'h1;
        if (isP1 == 1'h1) begin
          M_game_fsm_d = PLAYER1_PRESS_game_fsm;
        end else begin
          M_game_fsm_d = PLAYER2_PRESS_game_fsm;
        end
      end
      PLAYER1_PRESS_game_fsm: begin
        alufn = 6'h36;
        asel = 2'h0;
        bsel = 3'h0;
        ra = 4'h9;
        rb = 4'hb;
        rc = 4'h7;
        if (tempvar1 == 1'h1) begin
          M_game_fsm_d = PLAYER1_PRESS_WRITE_VALUE_game_fsm;
        end else begin
          M_game_fsm_d = INCREMENT_SEQUENCECOUNT_game_fsm;
        end
      end
      PLAYER1_PRESS_WRITE_VALUE_game_fsm: begin
        if (btn2) begin
          rc = 4'h9;
          we = 1'h1;
          M_game_fsm_d = PLAYER1_PRESS_ADD_TO_SEQUENCE_game_fsm;
        end else begin
          if (btn1) begin
            M_game_fsm_d = PLAYER1_PRESS_game_fsm;
          end
        end
      end
      PLAYER1_PRESS_ADD_TO_SEQUENCE_game_fsm: begin
        alufn = 6'h00;
        asel = 2'h0;
        bsel = 3'h0;
        ra = 4'h0;
        rb = 4'h9;
        rc = 4'h0;
        we = 1'h1;
        M_game_fsm_d = PLAYER1_PRESS_INCREMENT_LOOPVAR_game_fsm;
      end
      PLAYER1_PRESS_INCREMENT_LOOPVAR_game_fsm: begin
        alufn = 6'h00;
        asel = 2'h0;
        bsel = 3'h2;
        ra = 4'h9;
        rc = 4'h9;
        we = 1'h1;
        M_game_fsm_d = PLAYER1_PRESS_game_fsm;
      end
      PLAYER2_PRESS_game_fsm: begin
        alufn = 6'h36;
        asel = 2'h0;
        bsel = 3'h0;
        ra = 4'h9;
        rb = 4'h6;
        rc = 4'h7;
        if (tempvar1 == 1'h1) begin
          M_game_fsm_d = PLAYER2_PRESS_WRITE_VALUE_game_fsm;
        end else begin
          M_game_fsm_d = INCREMENT_SEQUENCECOUNT_game_fsm;
        end
      end
      PLAYER2_PRESS_WRITE_VALUE_game_fsm: begin
        if (btn2) begin
          rc = 4'h9;
          we = 1'h1;
          M_game_fsm_d = PLAYER2_PRESS_ADD_TO_SEQUENCE_game_fsm;
        end else begin
          if (btn1) begin
            M_game_fsm_d = PLAYER2_PRESS_game_fsm;
          end
        end
      end
      PLAYER2_PRESS_ADD_TO_SEQUENCE_game_fsm: begin
        alufn = 6'h00;
        asel = 2'h0;
        bsel = 3'h0;
        ra = 4'h0;
        rb = 4'h9;
        rc = 4'h0;
        we = 1'h1;
        M_game_fsm_d = PLAYER1_PRESS_INCREMENT_LOOPVAR_game_fsm;
      end
      PLAYER2_PRESS_INCREMENT_LOOPVAR_game_fsm: begin
        alufn = 6'h00;
        asel = 2'h0;
        bsel = 3'h2;
        ra = 4'h9;
        rc = 4'h9;
        we = 1'h1;
        M_game_fsm_d = PLAYER2_PRESS_game_fsm;
      end
      INCREMENT_SEQUENCECOUNT_game_fsm: begin
        alufn = 6'h00;
        asel = 2'h0;
        bsel = 3'h2;
        ra = 4'h2;
        rc = 4'h2;
        we = 1'h1;
        M_game_fsm_d = CPMLEQ_SEQUENCECOUNT_1_game_fsm;
      end
      CPMLEQ_SEQUENCECOUNT_1_game_fsm: begin
        alufn = 6'h1a;
        asel = 2'h0;
        bsel = 3'h2;
        ra = 4'h2;
        rc = 4'h7;
        we = 1'h1;
        if (tempvar1 == 1'h1) begin
          M_game_fsm_d = NOT_ISP1_game_fsm;
        end else begin
          M_game_fsm_d = CMPEQ_P1SEQUENCE_P2SEQUENCE_game_fsm;
        end
      end
      NOT_ISP1_game_fsm: begin
        alufn = 4'hb;
        asel = 2'h0;
        ra = 4'h6;
        rc = 4'h6;
        we = 1'h1;
        M_game_fsm_d = IDLE_game_fsm;
      end
      CMPEQ_P1SEQUENCE_P2SEQUENCE_game_fsm: begin
        alufn = 4'h3;
        asel = 2'h0;
        ra = 4'h6;
        rc = 4'h8;
        we = 1'h1;
        if (tempvar2 == 1'h1) begin
          M_game_fsm_d = CMP_SEQ_ISP1_game_fsm;
        end else begin
          M_game_fsm_d = CMP_SEQ_NOTISP1_game_fsm;
        end
      end
      CMP_SEQ_ISP1_game_fsm: begin
        if (p1_sequence == p2_sequence) begin
          M_game_fsm_d = UPDATE_LED_GREEN_game_fsm;
        end else begin
          M_game_fsm_d = UPDATE_LED_RED_game_fsm;
        end
      end
      CMP_SEQ_NOTISP1_game_fsm: begin
        if (p1_sequence == p2_sequence) begin
          M_game_fsm_d = UPDATE_LED_GREEN_game_fsm;
        end else begin
          M_game_fsm_d = UPDATE_LED_RED_game_fsm;
        end
      end
      UPDATE_LED_GREEN_game_fsm: begin
        green_led = 1'h1;
        M_game_fsm_d = CPMLE_SEQUENCECOUNT_16_game_fsm;
      end
      UPDATE_LED_RED_game_fsm: begin
        red_led = 1'h1;
        M_game_fsm_d = CMPEQ_ISP1_0_game_fsm;
      end
      CPMLE_SEQUENCECOUNT_16_game_fsm: begin
        alufn = 6'h36;
        asel = 2'h0;
        bsel = 3'h4;
        ra = 4'h2;
        rc = 4'h8;
        we = 1'h1;
        if (tempvar2 == 1'h1) begin
          M_game_fsm_d = NOT_ISP1_CMP_game_fsm;
        end else begin
          M_game_fsm_d = INCREMENT_P1_SCORE_game_fsm;
        end
      end
      NOT_ISP1_CMP_game_fsm: begin
        alufn = 4'hb;
        asel = 2'h0;
        ra = 4'h6;
        rc = 4'h6;
        we = 1'h1;
        M_game_fsm_d = TURN_LED_OFF_game_fsm;
      end
      TURN_LED_OFF_game_fsm: begin
        green_led = 1'h0;
        red_led = 1'h0;
        M_game_fsm_d = IDLE_game_fsm;
      end
      INCREMENT_P1_SCORE_game_fsm: begin
        alufn = 6'h00;
        asel = 2'h0;
        bsel = 3'h2;
        ra = 4'h3;
        rc = 4'h3;
        we = 1'h1;
        M_game_fsm_d = INCREMENT_P1_SCORE_SEG_game_fsm;
      end
      INCREMENT_P1_SCORE_SEG_game_fsm: begin
        alufn = 4'h3;
        asel = 2'h0;
        ra = 4'h3;
        rc = 4'ha;
        we = 1'h1;
        split_yes = 1'h1;
        M_game_fsm_d = INCREMENT_P2_SCORE_game_fsm;
      end
      INCREMENT_P2_SCORE_game_fsm: begin
        alufn = 6'h00;
        asel = 2'h0;
        bsel = 3'h2;
        ra = 4'h4;
        rc = 4'h4;
        we = 1'h1;
        M_game_fsm_d = INCREMENT_P2_SCORE_SEG_game_fsm;
      end
      INCREMENT_P2_SCORE_SEG_game_fsm: begin
        alufn = 4'h3;
        asel = 2'h0;
        ra = 4'h4;
        rc = 4'ha;
        we = 1'h1;
        split_yes = 1'h1;
        M_game_fsm_d = INCREMENT_ROUND_game_fsm;
      end
      CMPEQ_ISP1_0_game_fsm: begin
        alufn = 6'h32;
        asel = 2'h0;
        bsel = 3'h1;
        ra = 4'h6;
        rc = 4'h7;
        we = 1'h1;
        if (tempvar1 == 1'h1) begin
          M_game_fsm_d = INCREMENT_P1_SCORE_CMP_game_fsm;
        end else begin
          M_game_fsm_d = INCREMENT_P2_SCORE_CMP_game_fsm;
        end
      end
      INCREMENT_P1_SCORE_CMP_game_fsm: begin
        alufn = 6'h00;
        asel = 2'h0;
        bsel = 3'h2;
        ra = 4'h3;
        rc = 4'h3;
        we = 1'h1;
        M_game_fsm_d = INCREMENT_P1_SCORE_CMP_SEG_game_fsm;
      end
      INCREMENT_P1_SCORE_CMP_SEG_game_fsm: begin
        alufn = 4'h3;
        asel = 2'h0;
        ra = 4'h3;
        rc = 4'ha;
        we = 1'h1;
        split_yes = 1'h1;
        M_game_fsm_d = INCREMENT_ROUND_game_fsm;
      end
      INCREMENT_P2_SCORE_CMP_game_fsm: begin
        alufn = 6'h00;
        asel = 2'h0;
        bsel = 3'h2;
        ra = 4'h4;
        rc = 4'h4;
        we = 1'h1;
        split_yes = 1'h1;
        M_game_fsm_d = INCREMENT_P2_SCORE_CMP_SEG_game_fsm;
      end
      INCREMENT_P2_SCORE_CMP_SEG_game_fsm: begin
        alufn = 4'h3;
        asel = 2'h0;
        ra = 4'h4;
        rc = 4'ha;
        we = 1'h1;
        split_yes = 1'h1;
        M_game_fsm_d = INCREMENT_ROUND_game_fsm;
      end
      INCREMENT_ROUND_game_fsm: begin
        alufn = 6'h00;
        asel = 2'h0;
        bsel = 3'h2;
        ra = 4'h5;
        rc = 4'h5;
        we = 1'h1;
        M_game_fsm_d = INCREMENT_ROUND_SEG_game_fsm;
      end
      INCREMENT_ROUND_SEG_game_fsm: begin
        alufn = 4'h3;
        asel = 2'h0;
        ra = 4'h5;
        rc = 4'ha;
        we = 1'h1;
        split_yes = 1'h1;
        M_game_fsm_d = CMPLEQC_ROUND_5_game_fsm;
      end
      CMPLEQC_ROUND_5_game_fsm: begin
        alufn = 6'h36;
        asel = 2'h0;
        bsel = 3'h3;
        ra = 4'h5;
        rc = 4'h7;
        we = 1'h1;
        if (tempvar1 == 1'h1) begin
          M_game_fsm_d = RESET_SEQUENCE_COUNT_game_fsm;
        end else begin
          M_game_fsm_d = CMPLEQ_P1_SCORE_P2SCORE_game_fsm;
        end
      end
      RESET_SEQUENCE_COUNT_game_fsm: begin
        alufn = 6'h00;
        asel = 2'h0;
        bsel = 3'h1;
        ra = 4'h2;
        rc = 4'h2;
        we = 1'h1;
        M_game_fsm_d = TURN_LED_OFF1_game_fsm;
      end
      TURN_LED_OFF1_game_fsm: begin
        green_led = 1'h0;
        red_led = 1'h0;
        M_game_fsm_d = SET_ISP1_1_game_fsm;
      end
      SET_ISP1_1_game_fsm: begin
        alufn = 4'h4;
        bsel = 3'h2;
        rc = 4'h6;
        we = 1'h1;
        M_game_fsm_d = IDLE_game_fsm;
      end
      CMPLEQ_P1_SCORE_P2SCORE_game_fsm: begin
        alufn = 6'h36;
        asel = 2'h0;
        bsel = 3'h0;
        ra = 4'h3;
        rb = 4'h4;
        rc = 4'h7;
        we = 1'h1;
        if (tempvar1 == 1'h1) begin
          M_game_fsm_d = P2_WINNER_game_fsm;
        end else begin
          M_game_fsm_d = CMPEQ_P1_SCORE_P2SCORE_game_fsm;
        end
      end
      CMPEQ_P1_SCORE_P2SCORE_game_fsm: begin
        alufn = 6'h32;
        asel = 2'h0;
        bsel = 3'h0;
        ra = 4'h3;
        rb = 4'h4;
        rc = 4'h8;
        we = 1'h1;
        if (tempvar2 == 1'h1) begin
          M_game_fsm_d = TIE_game_fsm;
        end else begin
          M_game_fsm_d = P1_WINNER_game_fsm;
        end
      end
      P1_WINNER_game_fsm: begin
        alufn = 4'h3;
        asel = 2'h0;
        ra = 4'h3;
        rc = 4'ha;
        we = 1'h1;
        split_yes = 1'h1;
        M_game_fsm_d = END_game_fsm;
      end
      P2_WINNER_game_fsm: begin
        alufn = 4'h3;
        asel = 2'h0;
        ra = 4'h4;
        rc = 4'ha;
        we = 1'h1;
        split_yes = 1'h1;
        M_game_fsm_d = END_game_fsm;
      end
      TIE_game_fsm: begin
        alufn = 4'h4;
        bsel = 3'h5;
        rc = 4'ha;
        split_yes = 1'h1;
        we = 1'h1;
        M_game_fsm_d = END_game_fsm;
      end
      END_game_fsm: begin
        split_yes = 1'h0;
        green_led = 1'h0;
        red_led = 1'h0;
        M_game_fsm_d = START_game_fsm;
      end
      default: begin
        M_game_fsm_d = START_game_fsm;
      end
    endcase
  end
  
  always @(posedge clk) begin
    M_game_fsm_q <= M_game_fsm_d;
  end
  
endmodule