data/full_repos/permissive/14124747/MusicHero.v
1: b'%Error: data/full_repos/permissive/14124747/MusicHero.v:86: Cannot find file containing module: \'songdata\'\nsongdata bram(.clk(clk), .addr(targetnote), .data(notedata));\n^~~~~~~~\n        ... Looked in:\n             data/full_repos/permissive/14124747,data/full_repos/permissive/14124747/songdata\n             data/full_repos/permissive/14124747,data/full_repos/permissive/14124747/songdata.v\n             data/full_repos/permissive/14124747,data/full_repos/permissive/14124747/songdata.sv\n             songdata\n             songdata.v\n             songdata.sv\n             obj_dir/songdata\n             obj_dir/songdata.v\n             obj_dir/songdata.sv\n%Error: data/full_repos/permissive/14124747/MusicHero.v:126: Cannot find file containing module: \'vga_controller_640_60\'\nvga_controller_640_60 vga(.rst(1\'b0), .pixel_clk(clk_half), .HS(hs), .VS(vs), .hcount(hcount), .vcount(vcount), .blank(blank));\n^~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/14124747/MusicHero.v:132: Cannot find file containing module: \'PS2control\'\nPS2control guitar1(.clk(guitarclock), .keys(PSkeys1), .outclk(PSclk1), .command(PScommand1), .attention(PSattention1), .data(PSdata1));\n^~~~~~~~~~\n%Error: data/full_repos/permissive/14124747/MusicHero.v:133: Cannot find file containing module: \'PS2control\'\nPS2control guitar2(.clk(guitarclock), .keys(PSkeys2), .outclk(PSclk2), .command(PScommand2), .attention(PSattention2), .data(PSdata2));\n^~~~~~~~~~\n%Error: data/full_repos/permissive/14124747/MusicHero.v:145: Cannot find file containing module: \'PWM_audio\'\nPWM_audio PWM_audio_module(.clk_in(clk), .play(started), .PWM_in(pwm_input), .audio_out(audio_output));\n^~~~~~~~~\n%Error: data/full_repos/permissive/14124747/MusicHero.v:151: Cannot find file containing module: \'sram_interface\'\nsram_interface RAM_module(.rst(1\'b0), .clk(clk_half), .addr(address), .dout(indata), .rdy(memrdy), \n^~~~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/14124747/MusicHero.v:211: Operator ADD expects 12 bits on the RHS, but RHS\'s VARREF \'started\' generates 1 bits.\n                                                                   : ... In instance MusicHero\n pwmcount = pwmcount + started;\n                     ^\n                ... Use "/* verilator lint_off WIDTH */" and lint_on around source to disable this message.\n%Warning-WIDTH: data/full_repos/permissive/14124747/MusicHero.v:271: Operator ADD expects 32 bits on the RHS, but RHS\'s VARREF \'started\' generates 1 bits.\n                                                                   : ... In instance MusicHero\n count = count + started;\n               ^\n%Warning-WIDTH: data/full_repos/permissive/14124747/MusicHero.v:355: Operator ASSIGN expects 13 bits on the Assign RHS, but Assign RHS\'s ADD generates 32 or 16 bits.\n                                                                   : ... In instance MusicHero\n  targetnote = beatcount+7;  \n             ^\n%Warning-WIDTH: data/full_repos/permissive/14124747/MusicHero.v:358: Operator DIV expects 32 or 11 bits on the LHS, but LHS\'s VARREF \'pixelcount\' generates 9 bits.\n                                                                   : ... In instance MusicHero\n  fline = fretstart+pixelcount/2;\n                              ^\n%Warning-WIDTH: data/full_repos/permissive/14124747/MusicHero.v:379: Operator ADD expects 11 bits on the RHS, but RHS\'s VARREF \'fcount\' generates 8 bits.\n                                                                   : ... In instance MusicHero\n  fline = fline + fcount;\n                ^\n%Warning-WIDTH: data/full_repos/permissive/14124747/MusicHero.v:376: Operator DIV expects 32 or 11 bits on the LHS, but LHS\'s VARREF \'fcount\' generates 8 bits.\n                                                                   : ... In instance MusicHero\n if (vcount > fline + (fcount)/2) begin \n                              ^\n%Warning-WIDTH: data/full_repos/permissive/14124747/MusicHero.v:385: Operator EQ expects 16 bits on the LHS, but LHS\'s VARREF \'targetnote\' generates 13 bits.\n                                                                   : ... In instance MusicHero\n if (targetnote == beatcount && pixelcount < 7)\n                ^~\n%Warning-WIDTH: data/full_repos/permissive/14124747/MusicHero.v:391: Operator EQ expects 32 or 16 bits on the LHS, but LHS\'s VARREF \'targetnote\' generates 13 bits.\n                                                                   : ... In instance MusicHero\n end else if (targetnote == beatcount-1) begin\n                         ^~\n%Warning-WIDTH: data/full_repos/permissive/14124747/MusicHero.v:388: Operator EQ expects 16 bits on the LHS, but LHS\'s VARREF \'targetnote\' generates 13 bits.\n                                                                   : ... In instance MusicHero\n if (targetnote == beatcount) begin\n                ^~\n%Warning-WIDTH: data/full_repos/permissive/14124747/MusicHero.v:436: Operator SUB expects 11 bits on the RHS, but RHS\'s VARREF \'ncount\' generates 4 bits.\n                                                                   : ... In instance MusicHero\n    if (vcount > fline-ncount && vcount < fline+ncount && shownote1) begin  \n                      ^\n%Warning-WIDTH: data/full_repos/permissive/14124747/MusicHero.v:436: Operator ADD expects 11 bits on the RHS, but RHS\'s VARREF \'ncount\' generates 4 bits.\n                                                                   : ... In instance MusicHero\n    if (vcount > fline-ncount && vcount < fline+ncount && shownote1) begin  \n                                               ^\n%Warning-WIDTH: data/full_repos/permissive/14124747/MusicHero.v:538: Operator SUB expects 11 bits on the RHS, but RHS\'s VARREF \'ncount\' generates 4 bits.\n                                                                   : ... In instance MusicHero\n    if (vcount > fline-ncount && vcount < fline+ncount && shownote2) begin  \n                      ^\n%Warning-WIDTH: data/full_repos/permissive/14124747/MusicHero.v:538: Operator ADD expects 11 bits on the RHS, but RHS\'s VARREF \'ncount\' generates 4 bits.\n                                                                   : ... In instance MusicHero\n    if (vcount > fline-ncount && vcount < fline+ncount && shownote2) begin  \n                                               ^\n%Error: Exiting due to 6 error(s), 13 warning(s)\n'
module MusicHero(clk, hs, vs, rgb, LEDout, audio_output,
					  PSdata1, PSclk1, PScommand1, PSattention1, PSkeys1, 
					  PSdata2, PSclk2, PScommand2, PSattention2, PSkeys2, 
					  ram_address, ram_data, indata, memrdy, ram_clk, ram_adv, ram_cre, ram_ce, ram_oe, ram_we, ram_lb, ram_ub);

input clk;
output hs;
output vs;
output [7:0] rgb;
input PSdata1;
output PSclk1;
output PScommand1;
output PSattention1;
output [7:0] PSkeys1;
input PSdata2;
output PSclk2;
output PScommand2;
output PSattention2;
output [7:0] PSkeys2;








output [7:0] LEDout;
output audio_output;

output [23:1] ram_address;
reg    [23:0] address;
inout  [15:0] ram_data;
output [15:0] indata;
output memrdy;
output ram_clk;
output ram_adv;
output ram_cre;
output ram_ce;
output ram_oe;
output ram_we;
output ram_lb;
output ram_ub;

reg [7:0] LEDout;
reg [7:0] rgb;


parameter bpm = 346;
parameter vpb = 64;
parameter fretstart = 60;
parameter hitlength = 360;
parameter fretlength = 420;

wire [9:0] notedata;
reg [9:0] hitdata;
reg [12:0] targetnote;


songdata bram(.clk(clk), .addr(targetnote), .data(notedata));

reg [1:0] hitnote1;
reg [1:0] hitnote2;
reg [4:0] streak1;
reg [4:0] streak2;
reg [12:0] points1;
reg [12:0] points2;
reg shownote1;
reg shownote2;


reg [31:0] count;
reg [8:0] pixelcount;
reg [15:0] beatcount;

reg [3:0] ncount;
reg [8:0] ncounter; 
reg [7:0] fcount;
reg [8:0] fcounter;
reg [10:0] fline;
reg [15:0] bcount;


reg [2:0] dselect;
reg [2:0] dstart;
reg [2:0] dstrum1;
reg [2:0] dstrum2;
wire select_press = (dselect[2:1] == 2'b01);
wire start_press	= (dstart[2:1] == 2'b01);
wire strum1			= (dstrum1[2:1] == 2'b01);
wire strum2			= (dstrum2[2:1] == 2'b01);
reg started;


reg clk_half;
wire blank;
wire [10:0] hcount, vcount;


vga_controller_640_60 vga(.rst(1'b0), .pixel_clk(clk_half), .HS(hs), .VS(vs), .hcount(hcount), .vcount(vcount), .blank(blank));

reg [10:0] guitarcounter;
reg guitarclock;


PS2control guitar1(.clk(guitarclock), .keys(PSkeys1), .outclk(PSclk1), .command(PScommand1), .attention(PSattention1), .data(PSdata1));
PS2control guitar2(.clk(guitarclock), .keys(PSkeys2), .outclk(PSclk2), .command(PScommand2), .attention(PSattention2), .data(PSdata2));






parameter pwmfull = 1563;
reg [11:0] pwmcount;
reg [15:0] pwm_input;


PWM_audio PWM_audio_module(.clk_in(clk), .play(started), .PWM_in(pwm_input), .audio_out(audio_output));


reg readmem;


sram_interface RAM_module(.rst(1'b0), .clk(clk_half), .addr(address), .dout(indata), .rdy(memrdy), 
								  .sram_clk(ram_clk), .sram_adv(ram_adv), .sram_cre(ram_cre), .sram_ce(ram_ce), .sram_oe(ram_oe), .sram_we(ram_we), 
								  .sram_lb(ram_lb), .sram_ub(ram_ub), .sram_data(ram_data), .sram_addr(ram_address));


initial begin
	clk_half = 0;
	beatcount = 0;
	pixelcount = vpb/2;
	bcount = 0;
	count = 0;
	started = 0;
	
	address = 0;
	readmem = 0;
	

	pwmcount = 0;
	pwm_input = 0;
	

	hitnote1 = 0;
	hitnote2 = 0;
	streak1 = 5'b00000;
	streak2 = 5'b00000;
	points1 = 0;
	points2 = 0;
	

	targetnote = 0;
	hitdata = 0;

end



always @(posedge clk) begin
	clk_half = ~clk_half;

	

	if (pwmcount == 1 && started) begin
		readmem = 1;
		address = address + 1'b1; 
	end 

	if (pwmcount > 1 && pwmcount < 11 && memrdy && readmem) begin

		readmem = 0;
		pwm_input[15:0] = indata[15:0];

		if (pwm_input[15]) begin
			pwm_input = ~pwm_input;
			pwm_input = pwm_input + 1'b1;
			pwm_input = 16'b1000000000000000 - pwm_input;
		end else begin
			pwm_input = pwm_input + 16'b1000000000000000;
		end
	end
	
	pwmcount = pwmcount + started;

	if (pwmcount > pwmfull)
		pwmcount = 0;
		

	if (select_press) begin
		address = 0;
		readmem = 0;
		pwmcount = 0;
		pwm_input = 0;
	end
	
end


always @(posedge clk_half) begin

	

	if (beatcount == 1150) begin
		started = 0;
	end
	

	guitarcounter = guitarcounter + 1;
	if (guitarcounter == 25) begin
		guitarcounter = 0;
		guitarclock = ~guitarclock;
	end
	

	LEDout[7:5] = beatcount[2:0];
	LEDout[4:0] = notedata[4:0];
	

	dstrum1[2:0] = {dstrum1[1:0], PSkeys1[2]};
	dstrum2[2:0] = {dstrum2[1:0], PSkeys2[2]};
	dstart[2:0] = {dstart[1:0], PSkeys1[1]};
	dselect[2:0] = {dselect[1:0], PSkeys1[0]};
	if (start_press && beatcount < 1136)
		started = ~started;
	if (select_press) begin
		beatcount = 0;
		pixelcount = vpb/2;
		bcount = 0;
		count = 0;
		started = 0;
		hitnote1 = 0;
		hitnote2 = 0;
		streak1 = 5'b0000;
		streak2 = 5'b0000;
		points1 = 0;
		points2 = 0;
		targetnote = 0;
		hitdata = 0;
	end
	


	count = count + started;
	if (count == 25000000*60/bpm/vpb) begin

		count = 0;
		pixelcount = pixelcount + 1;

		if (pixelcount == vpb) begin
			hitnote1[1] = hitnote1[0];
			hitnote1[0] = 0;
			hitnote2[1] = hitnote2[0];
			hitnote2[0] = 0;
			pixelcount = 0;
			beatcount = beatcount + 1;
		end
	end
	



	if (started && hitdata[4:0] != 5'b00000) begin
		if (pixelcount >= 8 && pixelcount <= 56 && !hitnote1[0]) begin

			if (PSkeys1[7:3] == hitdata[4:0] && strum1) begin
				hitnote1[0] = 1;
				if (streak1 < 15)
					streak1 = streak1 + 1;

				if (streak1 == 15)
					points1 = points1 + 4;
				else if (streak1 >= 10)
					points1 = points1 + 3;
				else if (streak1 >= 5)
					points1 = points1 + 2;
				else
					points1 = points1 + 1;
			end else	if (pixelcount == 56) begin

				streak1 = 0;
			end
		end
	end else if (started) begin
		if (strum1)
			streak1 = 0;
	end
	

	if (started && hitdata[9:5] != 5'b00000) begin
		if (pixelcount >= 8 && pixelcount <= 56 && !hitnote2[0]) begin

			if (PSkeys2[7:3] == hitdata[9:5] && strum2) begin
				hitnote2[0] = 1;
				if (streak2 < 15)
					streak2 = streak2 + 1;

				if (streak2 == 15)
					points2 = points2 + 4;
				else if (streak2 >= 10)
					points2 = points2 + 3;
				else if (streak2 >= 5)
					points2 = points2 + 2;
				else
					points2 = points2 + 1;
			end else	if (pixelcount == 56) begin

				streak2 = 0;
			end
		end
	end else if (started) begin
		if (strum2)
			streak2 = 0;
	end
	







	if (hcount == 0 && vcount == 0) begin
		ncounter = 0;
		ncount = 5;
		fcounter = 0;
		bcount = beatcount;
		targetnote = beatcount+7;

		fcount = vpb/2;
		fline = fretstart+pixelcount/2;
	end
	if (hcount == 0 && vcount > fretstart) begin
		ncounter = ncounter + 1;
		if (ncounter == fretlength/5) begin
			ncounter = 0;
			ncount = ncount + 1;
		end
	end
	if (hcount == 0 && vcount > fretstart) begin
		fcounter = fcounter + 1;
		if (fcounter == hitlength/(vpb/2)) begin
			fcounter = 0;
			fcount = fcount + 1;
			if (vcount < fline)
				fline = fline + 1;
		end
	end
	if (vcount > fline + (fcount)/2) begin
		bcount = bcount + 1;
		targetnote = targetnote - 1;
		fline = fline + fcount;
	end
	



	if (targetnote == beatcount && pixelcount < 7)
		hitdata[9:0] = notedata[9:0];
		
	if (targetnote == beatcount) begin
		shownote1 = ~hitnote1[0];
		shownote2 = ~hitnote2[0];
	end else if (targetnote == beatcount-1) begin
		shownote1 = ~hitnote1[1];
		shownote2 = ~hitnote2[1];
	end else begin
		shownote1 = 1'b1;
		shownote2 = 1'b1;
	end
		
	

	case (blank)

		1: begin
			rgb = 0;
		end

		0: begin		

			

			rgb = 8'b01001001;
			

			if (-4*(vcount - 180) <= 15*(hcount - 56) && -4*(vcount - 180) > 15*(hcount - 76) && vcount >= 60 && vcount < 375) begin

				rgb = 8'b00000000;
				if (-4*(vcount - 180) <= 15*(hcount - 57) && -4*(vcount - 180) > 15*(hcount - 75) && vcount > 60 && vcount < 374) begin
					if (vcount*10 > 3740-points1*2 || points1 > 1670)
						rgb = 8'b00010100;
					else
						rgb = 8'b01001001;
				end
			end
			

			if (-4*(vcount - 180) <= 15*(hcount - 80) && 4*(vcount - 180) > 15*(hcount - 241) && vcount >= 60) begin

				rgb = 8'b01100100;
				

				if (vcount == fline && bcount[0] == 1)
					rgb = 8'b11011011;
				if (vcount == fline && bcount[0] == 0)
					rgb = 8'b01101110;
				
				if (vcount > fline-ncount && vcount < fline+ncount && shownote1) begin

					if (-4*(vcount - 180) <= 15*(hcount - 84) && -4*(vcount - 180) > 25*(hcount - 109) && notedata[4]) begin
						rgb = 8'b00011100;
					end

					if (-4*(vcount - 180) <= 25*(hcount - 116) && -4*(vcount - 180) > 75*(hcount - 141) && notedata[3]) begin
						rgb = 8'b11100000;
					end

					if (-4*(vcount - 180) <= 75*(hcount - 148) && 4*(vcount - 180) > 75*(hcount - 173) && notedata[2]) begin
						rgb = 8'b11111100;
					end

					if (4*(vcount - 180) <= 75*(hcount - 180) && 4*(vcount - 180) > 25*(hcount - 205) && notedata[1]) begin
						rgb = 8'b00000011;
					end

					if (4*(vcount - 180) <= 25*(hcount - 212) && 4*(vcount - 180) > 15*(hcount - 237) && notedata[0]) begin
						rgb = 8'b11101100;
					end
				end
				

				if (vcount >= 435 && vcount <= 436)
					rgb = 8'b11111111;
				if (vcount >= 405 && vcount <= 406)
					rgb = 8'b11111111;
				

				if (vcount > 409 && vcount < 432) begin

					if (-4*(vcount - 180) <= 15*(hcount - 84) && -4*(vcount - 180) > 25*(hcount - 109) && PSkeys1[7])
						rgb = 8'b00011100;

					if (-4*(vcount - 180) <= 25*(hcount - 116) && -4*(vcount - 180) > 75*(hcount - 141) && PSkeys1[6])
						rgb = 8'b11100000;

					if (-4*(vcount - 180) <= 75*(hcount - 148) && 4*(vcount - 180) > 75*(hcount - 173) && PSkeys1[5])
						rgb = 8'b11111100;

					if (4*(vcount - 180) <= 75*(hcount - 180) && 4*(vcount - 180) > 25*(hcount - 205) && PSkeys1[4])
						rgb = 8'b00000011;

					if (4*(vcount - 180) <= 25*(hcount - 212) && 4*(vcount - 180) > 15*(hcount - 237) && PSkeys1[3])
						rgb = 8'b11101100;
				end
				

				if (-4*(vcount - 180) <= 15*(hcount - 80)  && -4*(vcount - 180) > 15*(hcount - 81))		rgb = 8'b11111111;
				if (-4*(vcount - 180) <= 25*(hcount - 112) && -4*(vcount - 180) > 25*(hcount - 113))	rgb = 8'b11111111;
				if (-4*(vcount - 180) <= 75*(hcount - 144) && -4*(vcount - 180) > 75*(hcount - 145))	rgb = 8'b11111111;
				if (4*(vcount - 180) <= 75*(hcount - 176)  && 4*(vcount - 180) > 75*(hcount - 177))		rgb = 8'b11111111;
				if (4*(vcount - 180) <= 25*(hcount - 208)  && 4*(vcount - 180) > 25*(hcount - 209))		rgb = 8'b11111111;
				if (4*(vcount - 180) <= 15*(hcount - 240)  && 4*(vcount - 180) > 15*(hcount - 241))		rgb = 8'b11111111;

			end
			

			if (4*(vcount - 180) <= 15*(hcount - 244) && 4*(vcount - 180) > 15*(hcount - 264) && vcount > 253 && vcount < 375) begin

				rgb = 8'b00000000;
				if (4*(vcount - 180) <= 15*(hcount - 245) && 4*(vcount - 180) > 15*(hcount - 263) && vcount > 254 && vcount < 374) begin
					if (streak1 == 15) begin
						rgb = 8'b01100011;
					end else if (streak1 >= 10) begin
						rgb = 8'b01001111;
					end else if (streak1 >= 5) begin
						rgb = 8'b00111101;
					end else
						rgb = 8'b11111101;

					if (vcount < 375-streak1*8) begin
						rgb = 8'b01001001;
					end
				end
			end
			

			if (4*(vcount - 180) <= 15*(hcount - 564) && 4*(vcount - 180) > 15*(hcount - 584) && vcount >= 60 && vcount < 375) begin

				rgb = 8'b00000000;
				if (4*(vcount - 180) <= 15*(hcount - 565) && 4*(vcount - 180) > 15*(hcount - 583) && vcount > 60 && vcount < 374) begin
					if (vcount*10 > 3740-points2*2 || points2 > 1670)
						rgb = 8'b00010100;
					else
						rgb = 8'b01001001;
				end
			end
			

			if (-4*(vcount - 180) <= 15*(hcount - 400) && 4*(vcount - 180) > 15*(hcount - 561) && vcount >= 60) begin
			

				rgb = 8'b01100100;
				

				if (vcount == fline && bcount[0] == 1)
					rgb = 8'b11011011;
				if (vcount == fline && bcount[0] == 0)
					rgb = 8'b01101110;
				
				if (vcount > fline-ncount && vcount < fline+ncount && shownote2) begin

					if (-4*(vcount - 180) <= 15*(hcount - 404) && -4*(vcount - 180) > 25*(hcount - 429) && notedata[9]) begin
						rgb = 8'b00011100;
					end

					if (-4*(vcount - 180) <= 25*(hcount - 436) && -4*(vcount - 180) > 75*(hcount - 461) && notedata[8]) begin
						rgb = 8'b11100000;
					end

					if (-4*(vcount - 180) <= 75*(hcount - 468) && 4*(vcount - 180) > 75*(hcount - 493) && notedata[7]) begin
						rgb = 8'b11111100;
					end

					if (4*(vcount - 180) <= 75*(hcount - 500) && 4*(vcount - 180) > 25*(hcount - 525) && notedata[6]) begin
						rgb = 8'b00000011;
					end

					if (4*(vcount - 180) <= 25*(hcount - 532) && 4*(vcount - 180) > 15*(hcount - 557) && notedata[5]) begin
						rgb = 8'b11101100;
					end
				end
				

				if (vcount >= 435 && vcount <= 436)
					rgb = 8'b11111111;
				if (vcount >= 405 && vcount <= 406)
					rgb = 8'b11111111;
				

				if (vcount > 409 && vcount < 432) begin

					if (-4*(vcount - 180) <= 15*(hcount - 404) && -4*(vcount - 180) > 25*(hcount - 429) && PSkeys2[7])
						rgb = 8'b00011100;

					if (-4*(vcount - 180) <= 25*(hcount - 436) && -4*(vcount - 180) > 75*(hcount - 461) && PSkeys2[6])
						rgb = 8'b11100000;

					if (-4*(vcount - 180) <= 75*(hcount - 468) && 4*(vcount - 180) > 75*(hcount - 493) && PSkeys2[5])
						rgb = 8'b11111100;

					if (4*(vcount - 180) <= 75*(hcount - 500) && 4*(vcount - 180) > 25*(hcount - 525) && PSkeys2[4])
						rgb = 8'b00000011;

					if (4*(vcount - 180) <= 25*(hcount - 532) && 4*(vcount - 180) > 15*(hcount - 557) && PSkeys2[3])
						rgb = 8'b11101100;
				end
				

				if (-4*(vcount - 180) <= 15*(hcount - 400) && -4*(vcount - 180) > 15*(hcount - 401))	rgb = 8'b11111111;
				if (-4*(vcount - 180) <= 25*(hcount - 432) && -4*(vcount - 180) > 25*(hcount - 433))	rgb = 8'b11111111;
				if (-4*(vcount - 180) <= 75*(hcount - 464) && -4*(vcount - 180) > 75*(hcount - 465))	rgb = 8'b11111111;
				if (4*(vcount - 180) <= 75*(hcount - 496) && 4*(vcount - 180) > 75*(hcount - 497))		rgb = 8'b11111111;
				if (4*(vcount - 180) <= 25*(hcount - 528) && 4*(vcount - 180) > 25*(hcount - 529))		rgb = 8'b11111111;
				if (4*(vcount - 180) <= 15*(hcount - 560) && 4*(vcount - 180) > 15*(hcount - 561))		rgb = 8'b11111111;
				
			end
			

			if (-4*(vcount - 180) <= 15*(hcount - 376) && -4*(vcount - 180) > 15*(hcount - 396) && vcount > 253 && vcount < 375) begin

				rgb = 8'b00000000;
				if (-4*(vcount - 180) <= 15*(hcount - 377) && -4*(vcount - 180) > 15*(hcount - 395) && vcount > 254 && vcount < 374) begin
					if (streak2 == 15) begin
						rgb = 8'b01100011;
					end else if (streak2 >= 10) begin
						rgb = 8'b01001111;
					end else if (streak2 >= 5) begin
						rgb = 8'b00111101;
					end else
						rgb = 8'b11111101;

					if (vcount < 375-streak2*8) begin
						rgb = 8'b01001001;
					end
				end
			end
			

			
		end

	endcase

end


endmodule
module MusicHero(clk, hs, vs, rgb, LEDout, audio_output,
					  PSdata1, PSclk1, PScommand1, PSattention1, PSkeys1, 
					  PSdata2, PSclk2, PScommand2, PSattention2, PSkeys2, 
					  ram_address, ram_data, indata, memrdy, ram_clk, ram_adv, ram_cre, ram_ce, ram_oe, ram_we, ram_lb, ram_ub);


input clk;
output hs;
output vs;
output [7:0] rgb;
input PSdata1;
output PSclk1;
output PScommand1;
output PSattention1;
output [7:0] PSkeys1;
input PSdata2;
output PSclk2;
output PScommand2;
output PSattention2;
output [7:0] PSkeys2;








output [7:0] LEDout;
output audio_output;

output [23:1] ram_address;
reg    [23:0] address;
inout  [15:0] ram_data;
output [15:0] indata;
output memrdy;
output ram_clk;
output ram_adv;
output ram_cre;
output ram_ce;
output ram_oe;
output ram_we;
output ram_lb;
output ram_ub;

reg [7:0] LEDout;
reg [7:0] rgb;


parameter bpm = 346;
parameter vpb = 64;
parameter fretstart = 60;
parameter hitlength = 360;
parameter fretlength = 420;

wire [9:0] notedata;
reg [9:0] hitdata;
reg [12:0] targetnote;


songdata bram(.clk(clk), .addr(targetnote), .data(notedata));

reg [1:0] hitnote1;
reg [1:0] hitnote2;
reg [4:0] streak1;
reg [4:0] streak2;
reg [12:0] points1;
reg [12:0] points2;
reg shownote1;
reg shownote2;


reg [31:0] count;
reg [8:0] pixelcount;
reg [15:0] beatcount;

reg [3:0] ncount;
reg [8:0] ncounter; 
reg [7:0] fcount;
reg [8:0] fcounter;
reg [10:0] fline;
reg [15:0] bcount;


reg [2:0] dselect;
reg [2:0] dstart;
reg [2:0] dstrum1;
reg [2:0] dstrum2;
wire select_press = (dselect[2:1] == 2'b01);
wire start_press	= (dstart[2:1] == 2'b01);
wire strum1			= (dstrum1[2:1] == 2'b01);
wire strum2			= (dstrum2[2:1] == 2'b01);
reg started;


reg clk_half;
wire blank;
wire [10:0] hcount, vcount;


vga_controller_640_60 vga(.rst(1'b0), .pixel_clk(clk_half), .HS(hs), .VS(vs), .hcount(hcount), .vcount(vcount), .blank(blank));

reg [10:0] guitarcounter;
reg guitarclock;


PS2control guitar1(.clk(guitarclock), .keys(PSkeys1), .outclk(PSclk1), .command(PScommand1), .attention(PSattention1), .data(PSdata1));
PS2control guitar2(.clk(guitarclock), .keys(PSkeys2), .outclk(PSclk2), .command(PScommand2), .attention(PSattention2), .data(PSdata2));






parameter pwmfull = 1563;
reg [11:0] pwmcount;
reg [15:0] pwm_input;


PWM_audio PWM_audio_module(.clk_in(clk), .play(started), .PWM_in(pwm_input), .audio_out(audio_output));


reg readmem;


sram_interface RAM_module(.rst(1'b0), .clk(clk_half), .addr(address), .dout(indata), .rdy(memrdy), 
								  .sram_clk(ram_clk), .sram_adv(ram_adv), .sram_cre(ram_cre), .sram_ce(ram_ce), .sram_oe(ram_oe), .sram_we(ram_we), 
								  .sram_lb(ram_lb), .sram_ub(ram_ub), .sram_data(ram_data), .sram_addr(ram_address));


initial begin
	clk_half = 0;
	beatcount = 0;
	pixelcount = vpb/2;
	bcount = 0;
	count = 0;
	started = 0;
	
	address = 0;
	readmem = 0;
	

	pwmcount = 0;
	pwm_input = 0;
	

	hitnote1 = 0;
	hitnote2 = 0;
	streak1 = 5'b00000;
	streak2 = 5'b00000;
	points1 = 0;
	points2 = 0;
	

	targetnote = 0;
	hitdata = 0;

end



always @(posedge clk) begin
	clk_half = ~clk_half;

	

	if (pwmcount == 1 && started) begin
		readmem = 1;
		address = address + 1'b1; 
	end 

	if (pwmcount > 1 && pwmcount < 11 && memrdy && readmem) begin

		readmem = 0;
		pwm_input[15:0] = indata[15:0];

		if (pwm_input[15]) begin
			pwm_input = ~pwm_input;
			pwm_input = pwm_input + 1'b1;
			pwm_input = 16'b1000000000000000 - pwm_input;
		end else begin
			pwm_input = pwm_input + 16'b1000000000000000;
		end
	end
	
	pwmcount = pwmcount + started;

	if (pwmcount > pwmfull)
		pwmcount = 0;
		

	if (select_press) begin
		address = 0;
		readmem = 0;
		pwmcount = 0;
		pwm_input = 0;
	end
	
end


always @(posedge clk_half) begin

	

	if (beatcount == 1150) begin
		started = 0;
	end
	

	guitarcounter = guitarcounter + 1;
	if (guitarcounter == 25) begin
		guitarcounter = 0;
		guitarclock = ~guitarclock;
	end
	

	LEDout[7:5] = beatcount[2:0];
	LEDout[4:0] = notedata[4:0];
	

	dstrum1[2:0] = {dstrum1[1:0], PSkeys1[2]};
	dstrum2[2:0] = {dstrum2[1:0], PSkeys2[2]};
	dstart[2:0] = {dstart[1:0], PSkeys1[1]};
	dselect[2:0] = {dselect[1:0], PSkeys1[0]};
	if (start_press && beatcount < 1136)
		started = ~started;
	if (select_press) begin
		beatcount = 0;
		pixelcount = vpb/2;
		bcount = 0;
		count = 0;
		started = 0;
		hitnote1 = 0;
		hitnote2 = 0;
		streak1 = 5'b0000;
		streak2 = 5'b0000;
		points1 = 0;
		points2 = 0;
		targetnote = 0;
		hitdata = 0;
	end
	


	count = count + started;
	if (count == 25000000*60/bpm/vpb) begin

		count = 0;
		pixelcount = pixelcount + 1;

		if (pixelcount == vpb) begin
			hitnote1[1] = hitnote1[0];
			hitnote1[0] = 0;
			hitnote2[1] = hitnote2[0];
			hitnote2[0] = 0;
			pixelcount = 0;
			beatcount = beatcount + 1;
		end
	end
	



	if (started && hitdata[4:0] != 5'b00000) begin
		if (pixelcount >= 8 && pixelcount <= 56 && !hitnote1[0]) begin

			if (PSkeys1[7:3] == hitdata[4:0] && strum1) begin
				hitnote1[0] = 1;
				if (streak1 < 15)
					streak1 = streak1 + 1;

				if (streak1 == 15)
					points1 = points1 + 4;
				else if (streak1 >= 10)
					points1 = points1 + 3;
				else if (streak1 >= 5)
					points1 = points1 + 2;
				else
					points1 = points1 + 1;
			end else	if (pixelcount == 56) begin

				streak1 = 0;
			end
		end
	end else if (started) begin
		if (strum1)
			streak1 = 0;
	end
	

	if (started && hitdata[9:5] != 5'b00000) begin
		if (pixelcount >= 8 && pixelcount <= 56 && !hitnote2[0]) begin

			if (PSkeys2[7:3] == hitdata[9:5] && strum2) begin
				hitnote2[0] = 1;
				if (streak2 < 15)
					streak2 = streak2 + 1;

				if (streak2 == 15)
					points2 = points2 + 4;
				else if (streak2 >= 10)
					points2 = points2 + 3;
				else if (streak2 >= 5)
					points2 = points2 + 2;
				else
					points2 = points2 + 1;
			end else	if (pixelcount == 56) begin

				streak2 = 0;
			end
		end
	end else if (started) begin
		if (strum2)
			streak2 = 0;
	end
	







	if (hcount == 0 && vcount == 0) begin
		ncounter = 0;
		ncount = 5;
		fcounter = 0;
		bcount = beatcount;
		targetnote = beatcount+7;

		fcount = vpb/2;
		fline = fretstart+pixelcount/2;
	end
	if (hcount == 0 && vcount > fretstart) begin
		ncounter = ncounter + 1;
		if (ncounter == fretlength/5) begin
			ncounter = 0;
			ncount = ncount + 1;
		end
	end
	if (hcount == 0 && vcount > fretstart) begin
		fcounter = fcounter + 1;
		if (fcounter == hitlength/(vpb/2)) begin
			fcounter = 0;
			fcount = fcount + 1;
			if (vcount < fline)
				fline = fline + 1;
		end
	end
	if (vcount > fline + (fcount)/2) begin
		bcount = bcount + 1;
		targetnote = targetnote - 1;
		fline = fline + fcount;
	end
	



	if (targetnote == beatcount && pixelcount < 7)
		hitdata[9:0] = notedata[9:0];
		
	if (targetnote == beatcount) begin
		shownote1 = ~hitnote1[0];
		shownote2 = ~hitnote2[0];
	end else if (targetnote == beatcount-1) begin
		shownote1 = ~hitnote1[1];
		shownote2 = ~hitnote2[1];
	end else begin
		shownote1 = 1'b1;
		shownote2 = 1'b1;
	end
		
	

	case (blank)

		1: begin
			rgb = 0;
		end

		0: begin		

			

			rgb = 8'b01001001;
			

			if (-4*(vcount - 180) <= 15*(hcount - 56) && -4*(vcount - 180) > 15*(hcount - 76) && vcount >= 60 && vcount < 375) begin

				rgb = 8'b00000000;
				if (-4*(vcount - 180) <= 15*(hcount - 57) && -4*(vcount - 180) > 15*(hcount - 75) && vcount > 60 && vcount < 374) begin
					if (vcount*10 > 3740-points1*2 || points1 > 1670)
						rgb = 8'b00010100;
					else
						rgb = 8'b01001001;
				end
			end
			

			if (-4*(vcount - 180) <= 15*(hcount - 80) && 4*(vcount - 180) > 15*(hcount - 241) && vcount >= 60) begin

				rgb = 8'b01100100;
				

				if (vcount == fline && bcount[0] == 1)
					rgb = 8'b11011011;
				if (vcount == fline && bcount[0] == 0)
					rgb = 8'b01101110;
				
				if (vcount > fline-ncount && vcount < fline+ncount && shownote1) begin

					if (-4*(vcount - 180) <= 15*(hcount - 84) && -4*(vcount - 180) > 25*(hcount - 109) && notedata[4]) begin
						rgb = 8'b00011100;
					end

					if (-4*(vcount - 180) <= 25*(hcount - 116) && -4*(vcount - 180) > 75*(hcount - 141) && notedata[3]) begin
						rgb = 8'b11100000;
					end

					if (-4*(vcount - 180) <= 75*(hcount - 148) && 4*(vcount - 180) > 75*(hcount - 173) && notedata[2]) begin
						rgb = 8'b11111100;
					end

					if (4*(vcount - 180) <= 75*(hcount - 180) && 4*(vcount - 180) > 25*(hcount - 205) && notedata[1]) begin
						rgb = 8'b00000011;
					end

					if (4*(vcount - 180) <= 25*(hcount - 212) && 4*(vcount - 180) > 15*(hcount - 237) && notedata[0]) begin
						rgb = 8'b11101100;
					end
				end
				

				if (vcount >= 435 && vcount <= 436)
					rgb = 8'b11111111;
				if (vcount >= 405 && vcount <= 406)
					rgb = 8'b11111111;
				

				if (vcount > 409 && vcount < 432) begin

					if (-4*(vcount - 180) <= 15*(hcount - 84) && -4*(vcount - 180) > 25*(hcount - 109) && PSkeys1[7])
						rgb = 8'b00011100;

					if (-4*(vcount - 180) <= 25*(hcount - 116) && -4*(vcount - 180) > 75*(hcount - 141) && PSkeys1[6])
						rgb = 8'b11100000;

					if (-4*(vcount - 180) <= 75*(hcount - 148) && 4*(vcount - 180) > 75*(hcount - 173) && PSkeys1[5])
						rgb = 8'b11111100;

					if (4*(vcount - 180) <= 75*(hcount - 180) && 4*(vcount - 180) > 25*(hcount - 205) && PSkeys1[4])
						rgb = 8'b00000011;

					if (4*(vcount - 180) <= 25*(hcount - 212) && 4*(vcount - 180) > 15*(hcount - 237) && PSkeys1[3])
						rgb = 8'b11101100;
				end
				

				if (-4*(vcount - 180) <= 15*(hcount - 80)  && -4*(vcount - 180) > 15*(hcount - 81))		rgb = 8'b11111111;
				if (-4*(vcount - 180) <= 25*(hcount - 112) && -4*(vcount - 180) > 25*(hcount - 113))	rgb = 8'b11111111;
				if (-4*(vcount - 180) <= 75*(hcount - 144) && -4*(vcount - 180) > 75*(hcount - 145))	rgb = 8'b11111111;
				if (4*(vcount - 180) <= 75*(hcount - 176)  && 4*(vcount - 180) > 75*(hcount - 177))		rgb = 8'b11111111;
				if (4*(vcount - 180) <= 25*(hcount - 208)  && 4*(vcount - 180) > 25*(hcount - 209))		rgb = 8'b11111111;
				if (4*(vcount - 180) <= 15*(hcount - 240)  && 4*(vcount - 180) > 15*(hcount - 241))		rgb = 8'b11111111;

			end
			

			if (4*(vcount - 180) <= 15*(hcount - 244) && 4*(vcount - 180) > 15*(hcount - 264) && vcount > 253 && vcount < 375) begin

				rgb = 8'b00000000;
				if (4*(vcount - 180) <= 15*(hcount - 245) && 4*(vcount - 180) > 15*(hcount - 263) && vcount > 254 && vcount < 374) begin
					if (streak1 == 15) begin
						rgb = 8'b01100011;
					end else if (streak1 >= 10) begin
						rgb = 8'b01001111;
					end else if (streak1 >= 5) begin
						rgb = 8'b00111101;
					end else
						rgb = 8'b11111101;

					if (vcount < 375-streak1*8) begin
						rgb = 8'b01001001;
					end
				end
			end
			

			if (4*(vcount - 180) <= 15*(hcount - 564) && 4*(vcount - 180) > 15*(hcount - 584) && vcount >= 60 && vcount < 375) begin

				rgb = 8'b00000000;
				if (4*(vcount - 180) <= 15*(hcount - 565) && 4*(vcount - 180) > 15*(hcount - 583) && vcount > 60 && vcount < 374) begin
					if (vcount*10 > 3740-points2*2 || points2 > 1670)
						rgb = 8'b00010100;
					else
						rgb = 8'b01001001;
				end
			end
			

			if (-4*(vcount - 180) <= 15*(hcount - 400) && 4*(vcount - 180) > 15*(hcount - 561) && vcount >= 60) begin
			

				rgb = 8'b01100100;
				

				if (vcount == fline && bcount[0] == 1)
					rgb = 8'b11011011;
				if (vcount == fline && bcount[0] == 0)
					rgb = 8'b01101110;
				
				if (vcount > fline-ncount && vcount < fline+ncount && shownote2) begin

					if (-4*(vcount - 180) <= 15*(hcount - 404) && -4*(vcount - 180) > 25*(hcount - 429) && notedata[9]) begin
						rgb = 8'b00011100;
					end

					if (-4*(vcount - 180) <= 25*(hcount - 436) && -4*(vcount - 180) > 75*(hcount - 461) && notedata[8]) begin
						rgb = 8'b11100000;
					end

					if (-4*(vcount - 180) <= 75*(hcount - 468) && 4*(vcount - 180) > 75*(hcount - 493) && notedata[7]) begin
						rgb = 8'b11111100;
					end

					if (4*(vcount - 180) <= 75*(hcount - 500) && 4*(vcount - 180) > 25*(hcount - 525) && notedata[6]) begin
						rgb = 8'b00000011;
					end

					if (4*(vcount - 180) <= 25*(hcount - 532) && 4*(vcount - 180) > 15*(hcount - 557) && notedata[5]) begin
						rgb = 8'b11101100;
					end
				end
				

				if (vcount >= 435 && vcount <= 436)
					rgb = 8'b11111111;
				if (vcount >= 405 && vcount <= 406)
					rgb = 8'b11111111;
				

				if (vcount > 409 && vcount < 432) begin

					if (-4*(vcount - 180) <= 15*(hcount - 404) && -4*(vcount - 180) > 25*(hcount - 429) && PSkeys2[7])
						rgb = 8'b00011100;

					if (-4*(vcount - 180) <= 25*(hcount - 436) && -4*(vcount - 180) > 75*(hcount - 461) && PSkeys2[6])
						rgb = 8'b11100000;

					if (-4*(vcount - 180) <= 75*(hcount - 468) && 4*(vcount - 180) > 75*(hcount - 493) && PSkeys2[5])
						rgb = 8'b11111100;

					if (4*(vcount - 180) <= 75*(hcount - 500) && 4*(vcount - 180) > 25*(hcount - 525) && PSkeys2[4])
						rgb = 8'b00000011;

					if (4*(vcount - 180) <= 25*(hcount - 532) && 4*(vcount - 180) > 15*(hcount - 557) && PSkeys2[3])
						rgb = 8'b11101100;
				end
				

				if (-4*(vcount - 180) <= 15*(hcount - 400) && -4*(vcount - 180) > 15*(hcount - 401))	rgb = 8'b11111111;
				if (-4*(vcount - 180) <= 25*(hcount - 432) && -4*(vcount - 180) > 25*(hcount - 433))	rgb = 8'b11111111;
				if (-4*(vcount - 180) <= 75*(hcount - 464) && -4*(vcount - 180) > 75*(hcount - 465))	rgb = 8'b11111111;
				if (4*(vcount - 180) <= 75*(hcount - 496) && 4*(vcount - 180) > 75*(hcount - 497))		rgb = 8'b11111111;
				if (4*(vcount - 180) <= 25*(hcount - 528) && 4*(vcount - 180) > 25*(hcount - 529))		rgb = 8'b11111111;
				if (4*(vcount - 180) <= 15*(hcount - 560) && 4*(vcount - 180) > 15*(hcount - 561))		rgb = 8'b11111111;
				
			end
			

			if (-4*(vcount - 180) <= 15*(hcount - 376) && -4*(vcount - 180) > 15*(hcount - 396) && vcount > 253 && vcount < 375) begin

				rgb = 8'b00000000;
				if (-4*(vcount - 180) <= 15*(hcount - 377) && -4*(vcount - 180) > 15*(hcount - 395) && vcount > 254 && vcount < 374) begin
					if (streak2 == 15) begin
						rgb = 8'b01100011;
					end else if (streak2 >= 10) begin
						rgb = 8'b01001111;
					end else if (streak2 >= 5) begin
						rgb = 8'b00111101;
					end else
						rgb = 8'b11111101;

					if (vcount < 375-streak2*8) begin
						rgb = 8'b01001001;
					end
				end
			end
			

			
		end

	endcase

end


endmodule