data/full_repos/permissive/166441728/RockBand.v
 line:58: before: "."
1: b'%Warning-PINMISSING: data/full_repos/permissive/166441728/RockBand.v:212: Cell has missing pin: \'pass\'\n control control0(\n         ^~~~~~~~\n                     ... Use "/* verilator lint_off PINMISSING */" and lint_on around source to disable this message.\n%Warning-PINMISSING: data/full_repos/permissive/166441728/RockBand.v:212: Cell has missing pin: \'remove\'\n control control0(\n         ^~~~~~~~\n%Warning-PINMISSING: data/full_repos/permissive/166441728/RockBand.v:212: Cell has missing pin: \'done_remove\'\n control control0(\n         ^~~~~~~~\n%Warning-IMPLICIT: data/full_repos/permissive/166441728/RockBand.v:208: Signal definition not found, creating implicitly: \'done_score_over\'\n                                                                      : ... Suggested alternative: \'done_game_over\'\n  .done_score(done_score_over), .score_plot(score_over_plot), .final_x(x_over_score), .final_y(y_over_score), .offx(\'d167), .offy(\'d218));\n              ^~~~~~~~~~~~~~~\n%Warning-IMPLICIT: data/full_repos/permissive/166441728/RockBand.v:285: Signal definition not found, creating implicitly: \'ps2_key_pressed\'\n  .ps2_key_pressed(ps2_key_pressed));\n                   ^~~~~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:425: Operator ASSIGNW expects 4 bits on the Assign RHS, but Assign RHS\'s MODDIV generates 32 or 10 bits.\n                                                                   : ... In instance RockBand.finalscore.d_counter\n assign ones = val_counter % \'d10;\n             ^\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:426: Operator ASSIGNW expects 4 bits on the Assign RHS, but Assign RHS\'s DIV generates 32 or 10 bits.\n                                                                   : ... In instance RockBand.finalscore.d_counter\n assign tens = (val_counter % \'d100) / \'d10;\n             ^\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:427: Operator ASSIGNW expects 4 bits on the Assign RHS, but Assign RHS\'s DIV generates 32 or 10 bits.\n                                                                   : ... In instance RockBand.finalscore.d_counter\n assign hundreds = val_counter / \'d100;\n                 ^\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:1083: Operator ASSIGNW expects 11 bits on the Assign RHS, but Assign RHS\'s VARREF \'counter_y\' generates 10 bits.\n                                                                    : ... In instance RockBand.load_background0\n assign final_y = counter_y;\n                ^\n%Error: data/full_repos/permissive/166441728/RockBand.v:1085: Cannot find file containing module: \'Background_ram\'\n Background_ram b0 (.address(memory_address), .clock(clock), .data(9\'b0), .wren(1\'b0), .q(color_play));\n ^~~~~~~~~~~~~~\n        ... Looked in:\n             data/full_repos/permissive/166441728,data/full_repos/permissive/166441728/Background_ram\n             data/full_repos/permissive/166441728,data/full_repos/permissive/166441728/Background_ram.v\n             data/full_repos/permissive/166441728,data/full_repos/permissive/166441728/Background_ram.sv\n             Background_ram\n             Background_ram.v\n             Background_ram.sv\n             obj_dir/Background_ram\n             obj_dir/Background_ram.v\n             obj_dir/Background_ram.sv\n%Error: data/full_repos/permissive/166441728/RockBand.v:1086: Cannot find file containing module: \'gameover\'\n gameover g0 (.address(memory_address), .clock(clock), .q(color_end));\n ^~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:1033: Operator ASSIGNW expects 11 bits on the Assign RHS, but Assign RHS\'s VARREF \'counter_y\' generates 10 bits.\n                                                                    : ... In instance RockBand.load_over0\n assign final_y = counter_y;\n                ^\n%Error: data/full_repos/permissive/166441728/RockBand.v:1035: Cannot find file containing module: \'gameover\'\n gameover g0 (.address(memory_address), .clock(clock), .q(color_end));\n ^~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:947: Operator ASSIGNDLY expects 8 bits on the Assign RHS, but Assign RHS\'s CONST \'10\'h0\' generates 10 bits.\n                                                                   : ... In instance RockBand.note_to_ram0\n   wr <= 10\'b0;\n      ^~\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:912: Operator ADD expects 10 bits on the LHS, but LHS\'s VARREF \'memory_address\' generates 8 bits.\n                                                                   : ... In instance RockBand.load_notes0\n assign final_y = memory_address + 10\'d36;\n                                 ^\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:739: Operator ASSIGN expects 5 bits on the Assign RHS, but Assign RHS\'s CONST \'3\'h0\' generates 3 bits.\n                                                                   : ... In instance RockBand.datapath0\n initial note_count = 3\'b0;\n                    ^\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:775: Operator ASSIGNDLY expects 5 bits on the Assign RHS, but Assign RHS\'s CONST \'3\'h0\' generates 3 bits.\n                                                                   : ... In instance RockBand.datapath0\n    note_count <= 3\'b0;\n               ^~\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:453: Operator CASE expects 3 bits on the Case expression, but Case expression\'s VARREF \'current_place\' generates 2 bits.\n                                                                   : ... In instance RockBand.finalscore\n  case (current_place)\n  ^~~~\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:467: Operator ASSIGNDLY expects 4 bits on the Assign RHS, but Assign RHS\'s CONST \'3\'h0\' generates 3 bits.\n                                                                   : ... In instance RockBand.finalscore\n   current_seg <= 3\'b0;\n               ^~\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:487: Bit extraction of var[6:0] requires 3 bit index, not 4 bits.\n                                                                   : ... In instance RockBand.finalscore\n     else if (seg[current_seg] == 1 || counter_x == 10\'d4)\n                 ^\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:506: Bit extraction of var[6:0] requires 3 bit index, not 4 bits.\n                                                                   : ... In instance RockBand.finalscore\n     else if (seg[current_seg] == 1 || counter_y == 10\'d4)\n                 ^\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:525: Bit extraction of var[6:0] requires 3 bit index, not 4 bits.\n                                                                   : ... In instance RockBand.finalscore\n     else if (seg[current_seg] == 1 || counter_y == 10\'d8)\n                 ^\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:544: Bit extraction of var[6:0] requires 3 bit index, not 4 bits.\n                                                                   : ... In instance RockBand.finalscore\n     else if (seg[current_seg] == 1 || counter_x == 10\'d4)\n                 ^\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:563: Bit extraction of var[6:0] requires 3 bit index, not 4 bits.\n                                                                   : ... In instance RockBand.finalscore\n     else if (seg[current_seg] == 1 || counter_y == 10\'d8)\n                 ^\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:582: Bit extraction of var[6:0] requires 3 bit index, not 4 bits.\n                                                                   : ... In instance RockBand.finalscore\n     else if (seg[current_seg] == 1 || counter_y == 10\'d4)\n                 ^\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:601: Bit extraction of var[6:0] requires 3 bit index, not 4 bits.\n                                                                   : ... In instance RockBand.finalscore\n     else if (seg[current_seg] == 1 || counter_x == 10\'d4)\n                 ^\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:478: Operator CASE expects 4 bits on the Case Item, but Case Item\'s CONST \'3\'h0\' generates 3 bits.\n                                                                   : ... In instance RockBand.finalscore\n   case (current_seg)\n   ^~~~\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:478: Operator CASE expects 4 bits on the Case Item, but Case Item\'s CONST \'3\'h1\' generates 3 bits.\n                                                                   : ... In instance RockBand.finalscore\n   case (current_seg)\n   ^~~~\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:478: Operator CASE expects 4 bits on the Case Item, but Case Item\'s CONST \'3\'h2\' generates 3 bits.\n                                                                   : ... In instance RockBand.finalscore\n   case (current_seg)\n   ^~~~\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:478: Operator CASE expects 4 bits on the Case Item, but Case Item\'s CONST \'3\'h3\' generates 3 bits.\n                                                                   : ... In instance RockBand.finalscore\n   case (current_seg)\n   ^~~~\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:478: Operator CASE expects 4 bits on the Case Item, but Case Item\'s CONST \'3\'h4\' generates 3 bits.\n                                                                   : ... In instance RockBand.finalscore\n   case (current_seg)\n   ^~~~\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:478: Operator CASE expects 4 bits on the Case Item, but Case Item\'s CONST \'3\'h5\' generates 3 bits.\n                                                                   : ... In instance RockBand.finalscore\n   case (current_seg)\n   ^~~~\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:478: Operator CASE expects 4 bits on the Case Item, but Case Item\'s CONST \'3\'h6\' generates 3 bits.\n                                                                   : ... In instance RockBand.finalscore\n   case (current_seg)\n   ^~~~\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:618: Operator ASSIGNW expects 10 bits on the Assign RHS, but Assign RHS\'s ADD generates 32 or 11 bits.\n                                                                   : ... In instance RockBand.finalscore\n assign final_x = counter_x + current_place*12 + offx;\n                ^\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:619: Operator ASSIGNW expects 10 bits on the Assign RHS, but Assign RHS\'s ADD generates 11 bits.\n                                                                   : ... In instance RockBand.finalscore\n assign final_y = counter_y + offy;\n                ^\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:373: Operator ASSIGNDLY expects 10 bits on the Assign RHS, but Assign RHS\'s VARREF \'last_note\' generates 5 bits.\n                                                                   : ... In instance RockBand.hit_detection0\n   prev_hit <= last_note;\n            ^~\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:371: Operator NEQ expects 10 bits on the RHS, but RHS\'s VARREF \'last_note\' generates 5 bits.\n                                                                   : ... In instance RockBand.hit_detection0\n  if (last_note != 0 && prev_hit != last_note)\n                                 ^~\n%Error: data/full_repos/permissive/166441728/RockBand.v:42: Cannot find file containing module: \'vga_adapter\'\n vga_adapter VGA(\n ^~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:111: Operator ASSIGNDLY expects 9 bits on the Assign RHS, but Assign RHS\'s CONST \'3\'h0\' generates 3 bits.\n                                                                   : ... In instance RockBand\n   final_color <= 3\'b0;\n               ^~\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:117: Operator ASSIGNDLY expects 9 bits on the Assign RHS, but Assign RHS\'s CONST \'3\'h0\' generates 3 bits.\n                                                                   : ... In instance RockBand\n   final_color <= 3\'b0;\n               ^~\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:123: Operator ASSIGNDLY expects 9 bits on the Assign RHS, but Assign RHS\'s CONST \'3\'h0\' generates 3 bits.\n                                                                   : ... In instance RockBand\n   final_color <= 3\'b0;\n               ^~\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:129: Operator ASSIGNDLY expects 9 bits on the Assign RHS, but Assign RHS\'s CONST \'3\'h0\' generates 3 bits.\n                                                                   : ... In instance RockBand\n   final_color <= 3\'b0;\n               ^~\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:135: Operator ASSIGNDLY expects 9 bits on the Assign RHS, but Assign RHS\'s CONST \'3\'h0\' generates 3 bits.\n                                                                   : ... In instance RockBand\n   final_color <= 3\'b0;\n               ^~\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:173: Input port connection \'user_note\' expects 5 bits on the pin connection, but pin connection\'s VARREF \'user_note\' generates 4 bits.\n                                                                   : ... In instance RockBand\n hit_detection hit_detection0(.remove(remove), .resetn(done_draw), .clock(CLOCK_50), .user_note(user_note), \n                                                                                      ^~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:177: Output port connection \'final_x\' expects 11 bits on the pin connection, but pin connection\'s VARREF \'x_background\' generates 10 bits.\n                                                                   : ... In instance RockBand\n  .out_color(background_color), .done_erase(done_erase), .final_x(x_background), .final_y(y_background), .erase_plot(erase_plot));\n                                                          ^~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:177: Output port connection \'final_y\' expects 11 bits on the pin connection, but pin connection\'s VARREF \'y_background\' generates 10 bits.\n                                                                   : ... In instance RockBand\n  .out_color(background_color), .done_erase(done_erase), .final_x(x_background), .final_y(y_background), .erase_plot(erase_plot));\n                                                                                  ^~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:180: Output port connection \'final_x\' expects 11 bits on the pin connection, but pin connection\'s VARREF \'x_over\' generates 10 bits.\n                                                                   : ... In instance RockBand\n  .out_color(over_color), .done_erase(done_game_over), .final_x(x_over), .final_y(y_over), .erase_plot(over_plot));\n                                                        ^~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:180: Output port connection \'final_y\' expects 11 bits on the pin connection, but pin connection\'s VARREF \'y_over\' generates 10 bits.\n                                                                   : ... In instance RockBand\n  .out_color(over_color), .done_erase(done_game_over), .final_x(x_over), .final_y(y_over), .erase_plot(over_plot));\n                                                                          ^~~~~~~\n%Error: data/full_repos/permissive/166441728/RockBand.v:189: Cannot find file containing module: \'notes_display_test\'\n notes_display_test notes_display0(.clock(CLOCK_50), .data(data_in), .rdaddress(mem_address), .rden(rden), \n ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/166441728/RockBand.v:195: Cannot find file containing module: \'song1\'\n song1 song (.address(song_address), .clock(CLOCK_50), .data(4\'b0), .wren(1\'b0), .q(feed_note));\n ^~~~~\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:204: Input port connection \'correct\' expects 10 bits on the pin connection, but pin connection\'s SEL generates 3 bits.\n                                                                   : ... In instance RockBand\n load_score lhit(.correct(SW[2:0]), .display_score(display_hit), .resetn(~hit), .clock(CLOCK_50), \n                  ^~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/166441728/RockBand.v:210: Input port connection \'data\' expects 2 bits on the pin connection, but pin connection\'s SEL generates 3 bits.\n                                                                   : ... In instance RockBand\n difficulty difficulty0(.data(SW[2:0]), .out(speed));\n                         ^~~~\n%Error: data/full_repos/permissive/166441728/RockBand.v:268: Cannot find file containing module: \'PS2_Controller\'\n PS2_Controller PS2 (\n ^~~~~~~~~~~~~~\n%Error: Exiting due to 7 error(s), 46 warning(s)\n'
module RockBand
	(
		CLOCK_50,
		SW,
		KEY,
		
		PS2_CLK,
		PS2_DAT,
		
		VGA_CLK,
		VGA_HS,
		VGA_VS,
		VGA_BLANK_N,
		VGA_SYNC_N,
		VGA_R,
		VGA_G,
		VGA_B
	);

	input				CLOCK_50;
	input	[3:0]		KEY;					
	input [9:0]   	SW;
	
	inout PS2_CLK;
	inout PS2_DAT;
	
	wire resetn;
	wire writeEn;
	reg [8:0] final_color;
	reg [9:0] x;
	reg [9:0] y;
	
	output			VGA_CLK;
	output			VGA_HS;
	output			VGA_VS;
	output			VGA_BLANK_N;
	output			VGA_SYNC_N;
	output [7:0]	VGA_R;
	output [7:0]	VGA_G;
	output [7:0]	VGA_B;
	
	vga_adapter VGA(
			.resetn(resetn),
			.clock(CLOCK_50),
			.colour(final_color),
			.x(x),
			.y(y),
			.plot(writeEn),

			.VGA_R(VGA_R),
			.VGA_G(VGA_G),
			.VGA_B(VGA_B),
			.VGA_HS(VGA_HS),
			.VGA_VS(VGA_VS),
			.VGA_BLANK(VGA_BLANK_N),
			.VGA_SYNC(VGA_SYNC_N),
			.VGA_CLK(VGA_CLK));
		defparam VGA.RESOLUTION = "320x240";
		defparam VGA.MONOCHROME = "FALSE";
		defparam VGA.BITS_PER_COLOUR_CHANNEL = 3;
		defparam VGA.BACKGROUND_IMAGE = "start.mif";
			


	wire [25:0] speed;
	

	wire draw_background, erase, draw_notes, draw, feed_ram, feed, load, remove, score, correct, wrong, hit, 
		display_score, display_correct, display_wrong, display_hit, over, draw_gameover, done_game, gameover, display_last_score, over_score;

	wire erase_plot, note_plot, score_plot, correct_plot, wrong_plot, hit_plot, over_plot, score_over_plot;

	wire done_erase, done_draw, done_feed, done_new, done_remove, done_score, done_correct, done_wrong, done_hit, again, done_game_over;
	assign writeEn = (erase_plot || note_plot || score_plot || correct_plot || wrong_plot || hit_plot || over_plot || score_over_plot);
	




	
	reg [4:0] data_in;
	reg [7:0] mem_address;
	reg wren, rden; 
	
	wire [8:0] background_color, over_color;
	wire [9:0] x_background, y_background, x_note, y_note, x_score, y_score, x_correct, y_correct, x_wrong, y_wrong, x_hit, y_hit,
		x_over, y_over, x_over_score, y_over_score;
	wire [8:0] colour_in;
	
	wire [7:0] notes_address, shift_address, hit_address, song_address;
	wire [9:0] correct_num, wrong_num, all_notes;

	assign resetn = KEY[0];
	
	wire wren_note, rden_note, wren_hit, check_hit;
	wire [4:0] data_out, out_ram, feed_note, last_note;
	
	wire [3:0] user_note;
	wire start;
	
	always @(*)
	begin
		if (draw_background)
		begin
			final_color <= background_color;
			x <= x_background;
			y <= y_background;
		end
		else if (display_score)
		begin
			final_color <= 3'b0;
			x <= x_score;
			y <= y_score;
		end
		else if (display_last_score)
		begin
			final_color <= 3'b0;
			x <= x_over_score;
			y <= y_over_score;
		end
		else if (display_correct)
		begin
			final_color <= 3'b0;
			x <= x_correct;
			y <= y_correct;
		end
		else if (display_wrong)
		begin
			final_color <= 3'b0;
			x <= x_wrong;
			y <= y_wrong;
		end
		else if (display_hit)
		begin
			final_color <= 3'b0;
			x <= x_hit;
			y <= y_hit;
		end
		else if (remove)
		begin
			data_in <= 5'b0;
			mem_address <= hit_address;
			wren = wren_hit;
			rden = 1'b0;
		end
		else if (draw_notes)
		begin
			final_color <= colour_in;
			x <= x_note;
			y <= y_note;
			data_in <= 5'b0;
			mem_address <= notes_address;
			wren = 1'b0;
			rden = 1'b1;
		end
		else if (draw_gameover)
		begin
			final_color <= over_color;
			x <= x_over;
			y <= y_over;
		end
		else if (feed_ram)
		begin
			data_in <= data_out;
			mem_address <= shift_address;
			wren = wren_note;
			rden = rden_note;
		end
	end
	
	reg [2:0] difficulty_level;
	
	hit_detection hit_detection0(.remove(remove), .resetn(done_draw), .clock(CLOCK_50), .user_note(user_note), 
		.wrong(wrong_num), .correct(correct_num), .last_note(last_note), .gameover(gameover));
	
	load_background load_background0(.draw_background(draw_background), .resetn(~erase), .clock(CLOCK_50), 
		.out_color(background_color), .done_erase(done_erase), .final_x(x_background), .final_y(y_background), .erase_plot(erase_plot));
	
	load_over load_over0(.draw_background(draw_gameover), .resetn(~gameover), .clock(CLOCK_50), 
		.out_color(over_color), .done_erase(done_game_over), .final_x(x_over), .final_y(y_over), .erase_plot(over_plot));
		
	load_notes load_notes0(.start_notes(draw_notes), .resetn(~draw), .clock(CLOCK_50), .out_color(colour_in),
		.done_draw(done_draw), .final_x(x_note), .final_y(y_note), .note_plot(note_plot), 
		.memory_address(notes_address), .note(out_ram), .last_note(last_note), .remove(remove), .done_remove(done_remove));
	
	note_to_ram note_to_ram0(.resetn(~feed), .clock(CLOCK_50), .enable(feed_ram), .note_in(feed_note), .done(done_feed), 
		.mem_address(shift_address), .rden_out(rden_note), .wren_out(wren_note), .data_out(data_out), .note_ram(out_ram));
	
	notes_display_test notes_display0(.clock(CLOCK_50), .data(data_in), .rdaddress(mem_address), .rden(rden), 
		.wraddress(mem_address), .wren(wren), .q(out_ram));
		
	erase_note remove_note0 (.clock(CLOCK_50), .resetn(~remove), .mem_address(hit_address), 
		.done_remove(done_remove), .wren(wren_hit), .check_hit(check_hit), .gameover(gameover), .done_game(done_game));
		
	song1 song (.address(song_address), .clock(CLOCK_50), .data(4'b0), .wren(1'b0), .q(feed_note));
	

	load_score lscore(.correct(correct_num * 'd5), .display_score(display_score), .resetn(~score), .clock(CLOCK_50), 
		.done_score(done_score), .score_plot(score_plot), .final_x(x_score), .final_y(y_score), .offx('d6), .offy('d22));
	load_score lcorrect(.correct(correct_num / 'd2), .display_score(display_correct), .resetn(~correct), .clock(CLOCK_50), 
		.done_score(done_correct), .score_plot(correct_plot), .final_x(x_correct), .final_y(y_correct), .offx('d273), .offy('d34));
	load_score lwrong(.correct(wrong_num / 'd2), .display_score(display_wrong), .resetn(~wrong), .clock(CLOCK_50), 
		.done_score(done_wrong), .score_plot(wrong_plot), .final_x(x_wrong), .final_y(y_wrong), .offx('d273), .offy('d59));
	load_score lhit(.correct(SW[2:0]), .display_score(display_hit), .resetn(~hit), .clock(CLOCK_50), 
		.done_score(done_hit), .score_plot(hit_plot), .final_x(x_hit), .final_y(y_hit), .offx('d273), .offy('d84));
		
	load_score finalscore(.correct(correct_num * 'd5), .display_score(display_last_score), .resetn(~over_score), .clock(CLOCK_50), 
		.done_score(done_score_over), .score_plot(score_over_plot), .final_x(x_over_score), .final_y(y_over_score), .offx('d167), .offy('d218));
		
	difficulty difficulty0(.data(SW[2:0]), .out(speed));
		
	control control0(
				.clock(CLOCK_50),
				.resetn(resetn),
				.go(start),
				.done_erase(done_erase),
				.done_draw(done_draw),
				.done_feed(done_feed),
				.done_new(done_new),
				.done_score(done_score),
				.done_correct(done_correct),
				.done_wrong(done_wrong),
				.done_hit(done_hit),
				.speed(speed),
				.gameover(done_game),
				.done_game_over(done_game_over),
				
				.draw(draw),
				.erase(erase),
				.feed(feed),
				.load(load),
				.score(score),
				.correct(correct),
				.wrong(wrong),
				.hit(hit),
				.over(over),
				.again(again),
				.over_score(over_score)
				);
	
	datapath datapath0(
			.clock(CLOCK_50),
			.draw(draw),
			.erase(erase),
			.feed(feed),
			.load(load),
			.score(score),
			.correct(correct),
			.wrong(wrong),
			.hit(hit),
			.over(over),
			.over_score(over_score),
			
			.draw_gameover(draw_gameover),
			.draw_background(draw_background),
			.draw_notes(draw_notes),
			.feed_ram(feed_ram),
			.done_new(done_new),
			.display_score(display_score),
			.display_correct(display_correct),
			.display_wrong(display_wrong),
			.display_hit(display_hit),
			.display_last_score(display_last_score),
			.song_address(song_address)
			);
			
	wire		[15:0]	ps2_key_data;
	PS2_Controller PS2 (

		.CLOCK_50				(CLOCK_50),
		.reset				(~resetn),


		.PS2_CLK			(PS2_CLK),
		.PS2_DAT			(PS2_DAT),


		.received_data		(ps2_key_data),
		.received_data_en	(ps2_key_pressed)
	);
	

	
	key_fsm start_pressed(.clock(CLOCK_50), .resetn(resetn), .value(8'h1B), .on(start), .data(ps2_key_data[15:8]),
		.ps2_key_pressed(ps2_key_pressed));
	key_fsm blue_pressed(.clock(CLOCK_50), .resetn(resetn), .value(8'h05), .on(user_note[3]), .data(ps2_key_data[15:8]),
		.ps2_key_pressed(ps2_key_pressed));
	key_fsm red_pressed(.clock(CLOCK_50), .resetn(resetn), .value(8'h06), .on(user_note[2]), .data(ps2_key_data[15:8]),
		.ps2_key_pressed(ps2_key_pressed));
	key_fsm green_pressed(.clock(CLOCK_50), .resetn(resetn), .value(8'h04), .on(user_note[1]), .data(ps2_key_data[15:8]), 
		.ps2_key_pressed(ps2_key_pressed));
	key_fsm yellow_pressed(.clock(CLOCK_50), .resetn(resetn), .value(8'h0C), .on(user_note[0]), .data(ps2_key_data[15:8]), 
		.ps2_key_pressed(ps2_key_pressed));
	
endmodule
module RockBand
	(
		CLOCK_50,
		SW,
		KEY,
		
		PS2_CLK,
		PS2_DAT,
		
		VGA_CLK,
		VGA_HS,
		VGA_VS,
		VGA_BLANK_N,
		VGA_SYNC_N,
		VGA_R,
		VGA_G,
		VGA_B
	);


	input				CLOCK_50;
	input	[3:0]		KEY;					
	input [9:0]   	SW;
	
	inout PS2_CLK;
	inout PS2_DAT;
	
	wire resetn;
	wire writeEn;
	reg [8:0] final_color;
	reg [9:0] x;
	reg [9:0] y;
	
	output			VGA_CLK;
	output			VGA_HS;
	output			VGA_VS;
	output			VGA_BLANK_N;
	output			VGA_SYNC_N;
	output [7:0]	VGA_R;
	output [7:0]	VGA_G;
	output [7:0]	VGA_B;
	
	vga_adapter VGA(
			.resetn(resetn),
			.clock(CLOCK_50),
			.colour(final_color),
			.x(x),
			.y(y),
			.plot(writeEn),

			.VGA_R(VGA_R),
			.VGA_G(VGA_G),
			.VGA_B(VGA_B),
			.VGA_HS(VGA_HS),
			.VGA_VS(VGA_VS),
			.VGA_BLANK(VGA_BLANK_N),
			.VGA_SYNC(VGA_SYNC_N),
			.VGA_CLK(VGA_CLK));
		defparam VGA.RESOLUTION = "320x240";
		defparam VGA.MONOCHROME = "FALSE";
		defparam VGA.BITS_PER_COLOUR_CHANNEL = 3;
		defparam VGA.BACKGROUND_IMAGE = "start.mif";
			


	wire [25:0] speed;
	

	wire draw_background, erase, draw_notes, draw, feed_ram, feed, load, remove, score, correct, wrong, hit, 
		display_score, display_correct, display_wrong, display_hit, over, draw_gameover, done_game, gameover, display_last_score, over_score;

	wire erase_plot, note_plot, score_plot, correct_plot, wrong_plot, hit_plot, over_plot, score_over_plot;

	wire done_erase, done_draw, done_feed, done_new, done_remove, done_score, done_correct, done_wrong, done_hit, again, done_game_over;
	assign writeEn = (erase_plot || note_plot || score_plot || correct_plot || wrong_plot || hit_plot || over_plot || score_over_plot);
	




	
	reg [4:0] data_in;
	reg [7:0] mem_address;
	reg wren, rden; 
	
	wire [8:0] background_color, over_color;
	wire [9:0] x_background, y_background, x_note, y_note, x_score, y_score, x_correct, y_correct, x_wrong, y_wrong, x_hit, y_hit,
		x_over, y_over, x_over_score, y_over_score;
	wire [8:0] colour_in;
	
	wire [7:0] notes_address, shift_address, hit_address, song_address;
	wire [9:0] correct_num, wrong_num, all_notes;

	assign resetn = KEY[0];
	
	wire wren_note, rden_note, wren_hit, check_hit;
	wire [4:0] data_out, out_ram, feed_note, last_note;
	
	wire [3:0] user_note;
	wire start;
	
	always @(*)
	begin
		if (draw_background)
		begin
			final_color <= background_color;
			x <= x_background;
			y <= y_background;
		end
		else if (display_score)
		begin
			final_color <= 3'b0;
			x <= x_score;
			y <= y_score;
		end
		else if (display_last_score)
		begin
			final_color <= 3'b0;
			x <= x_over_score;
			y <= y_over_score;
		end
		else if (display_correct)
		begin
			final_color <= 3'b0;
			x <= x_correct;
			y <= y_correct;
		end
		else if (display_wrong)
		begin
			final_color <= 3'b0;
			x <= x_wrong;
			y <= y_wrong;
		end
		else if (display_hit)
		begin
			final_color <= 3'b0;
			x <= x_hit;
			y <= y_hit;
		end
		else if (remove)
		begin
			data_in <= 5'b0;
			mem_address <= hit_address;
			wren = wren_hit;
			rden = 1'b0;
		end
		else if (draw_notes)
		begin
			final_color <= colour_in;
			x <= x_note;
			y <= y_note;
			data_in <= 5'b0;
			mem_address <= notes_address;
			wren = 1'b0;
			rden = 1'b1;
		end
		else if (draw_gameover)
		begin
			final_color <= over_color;
			x <= x_over;
			y <= y_over;
		end
		else if (feed_ram)
		begin
			data_in <= data_out;
			mem_address <= shift_address;
			wren = wren_note;
			rden = rden_note;
		end
	end
	
	reg [2:0] difficulty_level;
	
	hit_detection hit_detection0(.remove(remove), .resetn(done_draw), .clock(CLOCK_50), .user_note(user_note), 
		.wrong(wrong_num), .correct(correct_num), .last_note(last_note), .gameover(gameover));
	
	load_background load_background0(.draw_background(draw_background), .resetn(~erase), .clock(CLOCK_50), 
		.out_color(background_color), .done_erase(done_erase), .final_x(x_background), .final_y(y_background), .erase_plot(erase_plot));
	
	load_over load_over0(.draw_background(draw_gameover), .resetn(~gameover), .clock(CLOCK_50), 
		.out_color(over_color), .done_erase(done_game_over), .final_x(x_over), .final_y(y_over), .erase_plot(over_plot));
		
	load_notes load_notes0(.start_notes(draw_notes), .resetn(~draw), .clock(CLOCK_50), .out_color(colour_in),
		.done_draw(done_draw), .final_x(x_note), .final_y(y_note), .note_plot(note_plot), 
		.memory_address(notes_address), .note(out_ram), .last_note(last_note), .remove(remove), .done_remove(done_remove));
	
	note_to_ram note_to_ram0(.resetn(~feed), .clock(CLOCK_50), .enable(feed_ram), .note_in(feed_note), .done(done_feed), 
		.mem_address(shift_address), .rden_out(rden_note), .wren_out(wren_note), .data_out(data_out), .note_ram(out_ram));
	
	notes_display_test notes_display0(.clock(CLOCK_50), .data(data_in), .rdaddress(mem_address), .rden(rden), 
		.wraddress(mem_address), .wren(wren), .q(out_ram));
		
	erase_note remove_note0 (.clock(CLOCK_50), .resetn(~remove), .mem_address(hit_address), 
		.done_remove(done_remove), .wren(wren_hit), .check_hit(check_hit), .gameover(gameover), .done_game(done_game));
		
	song1 song (.address(song_address), .clock(CLOCK_50), .data(4'b0), .wren(1'b0), .q(feed_note));
	

	load_score lscore(.correct(correct_num * 'd5), .display_score(display_score), .resetn(~score), .clock(CLOCK_50), 
		.done_score(done_score), .score_plot(score_plot), .final_x(x_score), .final_y(y_score), .offx('d6), .offy('d22));
	load_score lcorrect(.correct(correct_num / 'd2), .display_score(display_correct), .resetn(~correct), .clock(CLOCK_50), 
		.done_score(done_correct), .score_plot(correct_plot), .final_x(x_correct), .final_y(y_correct), .offx('d273), .offy('d34));
	load_score lwrong(.correct(wrong_num / 'd2), .display_score(display_wrong), .resetn(~wrong), .clock(CLOCK_50), 
		.done_score(done_wrong), .score_plot(wrong_plot), .final_x(x_wrong), .final_y(y_wrong), .offx('d273), .offy('d59));
	load_score lhit(.correct(SW[2:0]), .display_score(display_hit), .resetn(~hit), .clock(CLOCK_50), 
		.done_score(done_hit), .score_plot(hit_plot), .final_x(x_hit), .final_y(y_hit), .offx('d273), .offy('d84));
		
	load_score finalscore(.correct(correct_num * 'd5), .display_score(display_last_score), .resetn(~over_score), .clock(CLOCK_50), 
		.done_score(done_score_over), .score_plot(score_over_plot), .final_x(x_over_score), .final_y(y_over_score), .offx('d167), .offy('d218));
		
	difficulty difficulty0(.data(SW[2:0]), .out(speed));
		
	control control0(
				.clock(CLOCK_50),
				.resetn(resetn),
				.go(start),
				.done_erase(done_erase),
				.done_draw(done_draw),
				.done_feed(done_feed),
				.done_new(done_new),
				.done_score(done_score),
				.done_correct(done_correct),
				.done_wrong(done_wrong),
				.done_hit(done_hit),
				.speed(speed),
				.gameover(done_game),
				.done_game_over(done_game_over),
				
				.draw(draw),
				.erase(erase),
				.feed(feed),
				.load(load),
				.score(score),
				.correct(correct),
				.wrong(wrong),
				.hit(hit),
				.over(over),
				.again(again),
				.over_score(over_score)
				);
	
	datapath datapath0(
			.clock(CLOCK_50),
			.draw(draw),
			.erase(erase),
			.feed(feed),
			.load(load),
			.score(score),
			.correct(correct),
			.wrong(wrong),
			.hit(hit),
			.over(over),
			.over_score(over_score),
			
			.draw_gameover(draw_gameover),
			.draw_background(draw_background),
			.draw_notes(draw_notes),
			.feed_ram(feed_ram),
			.done_new(done_new),
			.display_score(display_score),
			.display_correct(display_correct),
			.display_wrong(display_wrong),
			.display_hit(display_hit),
			.display_last_score(display_last_score),
			.song_address(song_address)
			);
			
	wire		[15:0]	ps2_key_data;
	PS2_Controller PS2 (

		.CLOCK_50				(CLOCK_50),
		.reset				(~resetn),


		.PS2_CLK			(PS2_CLK),
		.PS2_DAT			(PS2_DAT),


		.received_data		(ps2_key_data),
		.received_data_en	(ps2_key_pressed)
	);
	

	
	key_fsm start_pressed(.clock(CLOCK_50), .resetn(resetn), .value(8'h1B), .on(start), .data(ps2_key_data[15:8]),
		.ps2_key_pressed(ps2_key_pressed));
	key_fsm blue_pressed(.clock(CLOCK_50), .resetn(resetn), .value(8'h05), .on(user_note[3]), .data(ps2_key_data[15:8]),
		.ps2_key_pressed(ps2_key_pressed));
	key_fsm red_pressed(.clock(CLOCK_50), .resetn(resetn), .value(8'h06), .on(user_note[2]), .data(ps2_key_data[15:8]),
		.ps2_key_pressed(ps2_key_pressed));
	key_fsm green_pressed(.clock(CLOCK_50), .resetn(resetn), .value(8'h04), .on(user_note[1]), .data(ps2_key_data[15:8]), 
		.ps2_key_pressed(ps2_key_pressed));
	key_fsm yellow_pressed(.clock(CLOCK_50), .resetn(resetn), .value(8'h0C), .on(user_note[0]), .data(ps2_key_data[15:8]), 
		.ps2_key_pressed(ps2_key_pressed));
	
endmodule