data/full_repos/permissive/175316557/system.v
1: b'%Warning-MULTITOP: data/full_repos/permissive/175316557/system.v:93: Multiple top level modules\n                                                                   : ... Suggest see manual; fix the duplicates, or use --top-module to select top.\n                   ... Use "/* verilator lint_off MULTITOP */" and lint_on around source to disable this message.\n                                                                   : ... Top module \'game_levels\'\nmodule game_levels(\n       ^~~~~~~~~~~\n                                                                   : ... Top module \'level_handler\'\n    module level_handler(\n           ^~~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/175316557/system.v:291: Operator ASSIGNDLY expects 5 bits on the Assign RHS, but Assign RHS\'s CONST \'8\'h0\' generates 8 bits.\n                                                                 : ... In instance level_handler\n        cur_x <= 8\'b00000000;\n              ^~\n%Warning-WIDTH: data/full_repos/permissive/175316557/system.v:290: Operator EQ expects 8 bits on the LHS, but LHS\'s VARREF \'cur_x\' generates 5 bits.\n                                                                 : ... In instance level_handler\n      if (cur_x == 8\'d19) begin\n                ^~\n%Warning-WIDTH: data/full_repos/permissive/175316557/system.v:24: Operator NEQ expects 3 bits on the LHS, but LHS\'s VARREF \'keycode\' generates 1 bits.\n                                                                : ... In instance game_levels\nassign wkeypressed = (keycode != 3\'b000);\n                              ^~\n%Error: Exiting due to 4 warning(s)\n'
module level_handler(
        input clock,
        input ld_loading,
        input [2:0] keycode,
        input [3:0] ld_level_num,
        input reset_n,
        output reg begin_draw,
		  output reg w_level_complete,
        output [7:0] position_x,
        output [6:0] position_y,
        output reg [3:0] sprite_id
    );


reg [2:0] level [0:299];

reg [2:0] level1 [0:299];
initial begin
	$readmemb("level1.mem", level1);
end

reg [2:0] level2 [0:299];
initial begin
	$readmemb("level2.mem", level2);
end
reg [2:0] level3 [0:299];
initial begin
	$readmemb("level3.mem", level3);
end

reg [2:0] level4 [0:299];
initial begin
	$readmemb("level4.mem", level4);
end


reg [3:0] player_y;
reg [4:0] player_x;
reg [3:0] cur_y;
reg [4:0] cur_x;

assign position_x = {cur_x, 3'b000};
assign position_y = {cur_y, 3'b000};
wire [2:0] block_above;
wire [2:0] block_below;
wire [2:0] block_right;
wire [2:0] block_left;
assign block_above = level[player_x + 20 * (player_y - 1)];
assign block_below = level[player_x + 20 * (player_y + 1)];
assign block_right = level[player_x + 1 + 20 * (player_y)];
assign block_left = level[player_x - 1 + 20 * (player_y)];

wire [2:0] block_two_above;
wire [2:0] block_two_below;
wire [2:0] block_two_right;
wire [2:0] block_two_left;

assign block_two_above = level[player_x + 20 * (player_y - 2)];
assign block_two_below = level[player_x + 20 * (player_y + 2)];
assign block_two_right = level[player_x + 2 + 20 * (player_y)];
assign block_two_left = level[player_x - 2 + 20 * (player_y)];

reg [6:0] sprite_timer;
reg [8:0] grid_loc;
reg [8:0] copy_helper;
reg level_complete_helper;

always @(posedge clock)
begin

    if (!reset_n)
    begin
		  level_complete_helper <= 0;
        sprite_id <= 4'd0;
        begin_draw <= 0;
        grid_loc <= 9'b000000000;
        sprite_timer <= 7'b0000000;
        cur_x <= 0;
        cur_y <= 0;
		  player_y <= 4'b0000;
        player_x <= 5'b00000;
		  copy_helper <= 9'b000000000;
		  w_level_complete <= 0;
    end
	 else if (ld_loading)
	 begin
		  w_level_complete <= 0;
		  level_complete_helper <= 0;
	     grid_loc <= 9'b000000000;
        sprite_timer <= 7'b0000000;

		  if (copy_helper == 9'd0) begin
				begin_draw <= 1;
			end
			else if (copy_helper == 9'd1) begin
				begin_draw <= 0;
				sprite_id <= 4'd6;
				cur_x <= 1;
				cur_y <= 0;
			end
			else if (copy_helper == 9'd68) begin
				begin_draw <= 1;
			end
			else if (copy_helper == 9'd69) begin
				begin_draw <= 0;
				sprite_id <= 4'd7;
				cur_x <= 2;
			end
			else if (copy_helper == 9'd140) begin
				begin_draw <= 1;
			end
			else if (copy_helper == 9'd141) begin
				begin_draw <= 0;
				cur_x <= 3;
				sprite_id <= 4'd8 + ld_level_num;
			end
			else if (copy_helper == 9'd260) begin
				cur_x <= 0;
				cur_y <= 0;
			end
			
			
		  if(ld_level_num == 4'b0000) begin
				if (copy_helper < 9'b100101100) begin
					level[copy_helper] <= level1[copy_helper];
					copy_helper <= copy_helper + 1;
				end
				player_y <= 4'b1010;
				player_x <= 5'b01011;
			end
			else if(ld_level_num == 4'b0001) begin
				if (copy_helper < 9'b100101100) begin
					level[copy_helper] <= level2[copy_helper];
					copy_helper <= copy_helper + 1;
				end
				player_y <= 4'b0011;
				player_x <= 5'b01111;
			end
			else if(ld_level_num == 4'b0010) begin
				if (copy_helper < 9'b100101100) begin
					level[copy_helper] <= level3[copy_helper];
					copy_helper <= copy_helper + 1;
				end
				player_y <= 4'b1011;
				player_x <= 5'b01010;
			end
			else if(ld_level_num == 4'b0011) begin
				if (copy_helper < 9'b100101100) begin
					level[copy_helper] <= level4[copy_helper];
					copy_helper <= copy_helper + 1;
				end
				player_y <= 4'b1000;
				player_x <= 5'b01111;
			end
			

	 end
	 else if (~ld_loading)
	 begin
			copy_helper <= 9'b000000000;
			 if (grid_loc < 9'b100101100)
			 begin
				  if (sprite_timer == 7'b0000000)
				  begin

						if ( (cur_x == player_x) && (cur_y == player_y))
							 sprite_id <= 4'b0010;

						else if (level[grid_loc] == 3'b110)
							 sprite_id <= 4'b0101;

						else if (level[grid_loc] == 3'b101)
						begin
							level_complete_helper <= 0;
							 sprite_id <= 4'b0001;
						end

						else if (level[grid_loc][1:0] == 2'b00)
							 sprite_id <= 4'b0000;
						else if (level[grid_loc][1:0] == 2'b01)
							 sprite_id <= 4'b0011;
						else if (level[grid_loc][1:0] == 2'b10)
							 sprite_id <= 4'b0100;
						else if (level[grid_loc][1:0] == 2'b11)
							 sprite_id <= 4'b1100;
						sprite_timer <= sprite_timer + 1;
				  end
				  else if (sprite_timer == 7'b0000001) begin
						sprite_timer <= sprite_timer + 1;
						begin_draw <= 1;
				  end
				  else if (sprite_timer == 7'b0000010) begin
						sprite_timer <= sprite_timer + 1;
						begin_draw <= 0;
				  end
				  else if (sprite_timer == 7'b1000100)
				  begin
						if (cur_x == 8'd19) begin
							 cur_x <= 8'b00000000;
							 cur_y <= cur_y + 1;
						end
						else
							 cur_x <= cur_x + 1;
						sprite_timer <= 7'b0000000;
						grid_loc <= grid_loc + 1;
				  end
				  else
				  begin
						begin_draw <= 0;
						sprite_timer <= sprite_timer + 1;
				  end
					
					if (grid_loc == 9'b100101011)
						w_level_complete <= level_complete_helper;

			 end
		
			 else if ((keycode != 3'b000))
			 begin
	
				  if(keycode == 3'b001)
				  begin

						if ((block_above[2] == 0) && (block_above[1:0] != 2'b00))
						begin
							 player_y <= player_y - 1;
						end

						else if ((block_above[2] == 1) && (block_two_above[1:0] != 2'b00) && (block_two_above[2] != 1) )
						begin
							 player_y <= player_y - 1;
							 level[player_x + 20 * (player_y - 1)][2] <= 0;
							 level[player_x + 20 * (player_y - 2)][2] <= 1;
						end
				  end
		
		
				  else if(keycode == 3'b010)
				  begin

						if ((block_right[2] == 0) && (block_right[1:0] != 2'b00))
						begin
							 player_x <= player_x + 1;
						end

						else if ((block_right[2] == 1) && (block_two_right[1:0] != 2'b00) && (block_two_right[2] != 1) )
						begin
							 player_x <= player_x + 1;
							 level[player_x + 1 + 20 * (player_y)][2] <= 0;
							 level[player_x + 2 + 20 * (player_y)][2] <= 1;
						end
				  end
		
		
				  else if(keycode == 3'b011)
				  begin

						if ((block_below[2] == 0) && (block_below[1:0] != 2'b00))
						begin
							 player_y <= player_y + 1;
						end

						else if ((block_below[2] == 1) && (block_two_below[1:0] != 2'b00) && (block_two_below[2] != 1) )
						begin
							 player_y <= player_y + 1;
							 level[player_x + 20 * (player_y + 1)][2] <= 0;
							 level[player_x + 20 * (player_y + 2)][2] <= 1;
						end
				  end
		
		
				  else if(keycode == 3'b100)
				  begin

						if ((block_left[2] == 0) && (block_left[1:0] != 2'b00))
						begin
							 player_x <= player_x - 1;
						end

						else if ((block_left[2] == 1) && (block_two_left[1:0] != 2'b00) && (block_two_left[2] != 1) )
						begin
							 player_x <= player_x - 1;
							 level[player_x - 1 + 20 * (player_y)][2] <= 1'b0;
							 level[player_x - 2 + 20 * (player_y)][2] <= 1;
						end
				  end
				  grid_loc <= 9'b000000000;
				  sprite_timer <= 7'b0000000;
				  level_complete_helper <= 1;
				  cur_x <= 0;
				  cur_y <= 0;
		
			 end


     end

end

endmodule
module level_handler(
        input clock,
        input ld_loading,
        input [2:0] keycode,
        input [3:0] ld_level_num,
        input reset_n,
        output reg begin_draw,
		  output reg w_level_complete,
        output [7:0] position_x,
        output [6:0] position_y,
        output reg [3:0] sprite_id
    );



reg [2:0] level [0:299];

reg [2:0] level1 [0:299];
initial begin
	$readmemb("level1.mem", level1);
end

reg [2:0] level2 [0:299];
initial begin
	$readmemb("level2.mem", level2);
end
reg [2:0] level3 [0:299];
initial begin
	$readmemb("level3.mem", level3);
end

reg [2:0] level4 [0:299];
initial begin
	$readmemb("level4.mem", level4);
end


reg [3:0] player_y;
reg [4:0] player_x;
reg [3:0] cur_y;
reg [4:0] cur_x;

assign position_x = {cur_x, 3'b000};
assign position_y = {cur_y, 3'b000};
wire [2:0] block_above;
wire [2:0] block_below;
wire [2:0] block_right;
wire [2:0] block_left;
assign block_above = level[player_x + 20 * (player_y - 1)];
assign block_below = level[player_x + 20 * (player_y + 1)];
assign block_right = level[player_x + 1 + 20 * (player_y)];
assign block_left = level[player_x - 1 + 20 * (player_y)];

wire [2:0] block_two_above;
wire [2:0] block_two_below;
wire [2:0] block_two_right;
wire [2:0] block_two_left;

assign block_two_above = level[player_x + 20 * (player_y - 2)];
assign block_two_below = level[player_x + 20 * (player_y + 2)];
assign block_two_right = level[player_x + 2 + 20 * (player_y)];
assign block_two_left = level[player_x - 2 + 20 * (player_y)];

reg [6:0] sprite_timer;
reg [8:0] grid_loc;
reg [8:0] copy_helper;
reg level_complete_helper;

always @(posedge clock)
begin

    if (!reset_n)
    begin
		  level_complete_helper <= 0;
        sprite_id <= 4'd0;
        begin_draw <= 0;
        grid_loc <= 9'b000000000;
        sprite_timer <= 7'b0000000;
        cur_x <= 0;
        cur_y <= 0;
		  player_y <= 4'b0000;
        player_x <= 5'b00000;
		  copy_helper <= 9'b000000000;
		  w_level_complete <= 0;
    end
	 else if (ld_loading)
	 begin
		  w_level_complete <= 0;
		  level_complete_helper <= 0;
	     grid_loc <= 9'b000000000;
        sprite_timer <= 7'b0000000;

		  if (copy_helper == 9'd0) begin
				begin_draw <= 1;
			end
			else if (copy_helper == 9'd1) begin
				begin_draw <= 0;
				sprite_id <= 4'd6;
				cur_x <= 1;
				cur_y <= 0;
			end
			else if (copy_helper == 9'd68) begin
				begin_draw <= 1;
			end
			else if (copy_helper == 9'd69) begin
				begin_draw <= 0;
				sprite_id <= 4'd7;
				cur_x <= 2;
			end
			else if (copy_helper == 9'd140) begin
				begin_draw <= 1;
			end
			else if (copy_helper == 9'd141) begin
				begin_draw <= 0;
				cur_x <= 3;
				sprite_id <= 4'd8 + ld_level_num;
			end
			else if (copy_helper == 9'd260) begin
				cur_x <= 0;
				cur_y <= 0;
			end
			
			
		  if(ld_level_num == 4'b0000) begin
				if (copy_helper < 9'b100101100) begin
					level[copy_helper] <= level1[copy_helper];
					copy_helper <= copy_helper + 1;
				end
				player_y <= 4'b1010;
				player_x <= 5'b01011;
			end
			else if(ld_level_num == 4'b0001) begin
				if (copy_helper < 9'b100101100) begin
					level[copy_helper] <= level2[copy_helper];
					copy_helper <= copy_helper + 1;
				end
				player_y <= 4'b0011;
				player_x <= 5'b01111;
			end
			else if(ld_level_num == 4'b0010) begin
				if (copy_helper < 9'b100101100) begin
					level[copy_helper] <= level3[copy_helper];
					copy_helper <= copy_helper + 1;
				end
				player_y <= 4'b1011;
				player_x <= 5'b01010;
			end
			else if(ld_level_num == 4'b0011) begin
				if (copy_helper < 9'b100101100) begin
					level[copy_helper] <= level4[copy_helper];
					copy_helper <= copy_helper + 1;
				end
				player_y <= 4'b1000;
				player_x <= 5'b01111;
			end
			

	 end
	 else if (~ld_loading)
	 begin
			copy_helper <= 9'b000000000;
			 if (grid_loc < 9'b100101100)
			 begin
				  if (sprite_timer == 7'b0000000)
				  begin

						if ( (cur_x == player_x) && (cur_y == player_y))
							 sprite_id <= 4'b0010;

						else if (level[grid_loc] == 3'b110)
							 sprite_id <= 4'b0101;

						else if (level[grid_loc] == 3'b101)
						begin
							level_complete_helper <= 0;
							 sprite_id <= 4'b0001;
						end

						else if (level[grid_loc][1:0] == 2'b00)
							 sprite_id <= 4'b0000;
						else if (level[grid_loc][1:0] == 2'b01)
							 sprite_id <= 4'b0011;
						else if (level[grid_loc][1:0] == 2'b10)
							 sprite_id <= 4'b0100;
						else if (level[grid_loc][1:0] == 2'b11)
							 sprite_id <= 4'b1100;
						sprite_timer <= sprite_timer + 1;
				  end
				  else if (sprite_timer == 7'b0000001) begin
						sprite_timer <= sprite_timer + 1;
						begin_draw <= 1;
				  end
				  else if (sprite_timer == 7'b0000010) begin
						sprite_timer <= sprite_timer + 1;
						begin_draw <= 0;
				  end
				  else if (sprite_timer == 7'b1000100)
				  begin
						if (cur_x == 8'd19) begin
							 cur_x <= 8'b00000000;
							 cur_y <= cur_y + 1;
						end
						else
							 cur_x <= cur_x + 1;
						sprite_timer <= 7'b0000000;
						grid_loc <= grid_loc + 1;
				  end
				  else
				  begin
						begin_draw <= 0;
						sprite_timer <= sprite_timer + 1;
				  end
					
					if (grid_loc == 9'b100101011)
						w_level_complete <= level_complete_helper;

			 end
		
			 else if ((keycode != 3'b000))
			 begin
	
				  if(keycode == 3'b001)
				  begin

						if ((block_above[2] == 0) && (block_above[1:0] != 2'b00))
						begin
							 player_y <= player_y - 1;
						end

						else if ((block_above[2] == 1) && (block_two_above[1:0] != 2'b00) && (block_two_above[2] != 1) )
						begin
							 player_y <= player_y - 1;
							 level[player_x + 20 * (player_y - 1)][2] <= 0;
							 level[player_x + 20 * (player_y - 2)][2] <= 1;
						end
				  end
		
		
				  else if(keycode == 3'b010)
				  begin

						if ((block_right[2] == 0) && (block_right[1:0] != 2'b00))
						begin
							 player_x <= player_x + 1;
						end

						else if ((block_right[2] == 1) && (block_two_right[1:0] != 2'b00) && (block_two_right[2] != 1) )
						begin
							 player_x <= player_x + 1;
							 level[player_x + 1 + 20 * (player_y)][2] <= 0;
							 level[player_x + 2 + 20 * (player_y)][2] <= 1;
						end
				  end
		
		
				  else if(keycode == 3'b011)
				  begin

						if ((block_below[2] == 0) && (block_below[1:0] != 2'b00))
						begin
							 player_y <= player_y + 1;
						end

						else if ((block_below[2] == 1) && (block_two_below[1:0] != 2'b00) && (block_two_below[2] != 1) )
						begin
							 player_y <= player_y + 1;
							 level[player_x + 20 * (player_y + 1)][2] <= 0;
							 level[player_x + 20 * (player_y + 2)][2] <= 1;
						end
				  end
		
		
				  else if(keycode == 3'b100)
				  begin

						if ((block_left[2] == 0) && (block_left[1:0] != 2'b00))
						begin
							 player_x <= player_x - 1;
						end

						else if ((block_left[2] == 1) && (block_two_left[1:0] != 2'b00) && (block_two_left[2] != 1) )
						begin
							 player_x <= player_x - 1;
							 level[player_x - 1 + 20 * (player_y)][2] <= 1'b0;
							 level[player_x - 2 + 20 * (player_y)][2] <= 1;
						end
				  end
				  grid_loc <= 9'b000000000;
				  sprite_timer <= 7'b0000000;
				  level_complete_helper <= 1;
				  cur_x <= 0;
				  cur_y <= 0;
		
			 end


     end

end

endmodule