data/full_repos/permissive/20688874/extra_credit/spare/build2/ee577bHw2q1a.v
data/verilator_xmls/cffd8705-60f5-4691-8ddd-d95e078e50bc.xml
module fsmVendingMachine(disp_Q,disp_D,disp_N,disp_P,done,
	money,price,start,clk,reset);
	

	output reg disp_Q,disp_D,disp_N,disp_P,done;
	

	input [6:0] money,price;
	input start,clk,reset;
	

	


	

	reg [3:0] state, nextstate;
	reg [6:0] change;

	reg flagDone;
	



	parameter Sinitial = 4'b0000;

	parameter Squarter = 4'b0001;

	parameter Sdime = 4'b0010;

	parameter Snickel = 4'b0011;

	parameter Spenny = 4'b0100;

	parameter Sfinal = 4'b0101;

	parameter SquarterTemp = 4'b0110;

	parameter SdimeTemp = 4'b0111;

	parameter SnickelTemp = 4'b1000;

	parameter SpennyTemp = 4'b1001;
	
	

	always @(posedge clk)
	begin

		if (reset)

			state <= Sinitial;
		else

			state <= nextstate;
	end
	
	

	always @(*)
	begin
		case (state)
			Sinitial:
				begin
					if(money < price)
					begin
						change = money;
					end
					else
					begin
						change = money - price;
					end
					
					
					if (start & (change == 0))
					begin
						$display($time, " << Go to State $0.00 >>",change);
						nextstate <= Sfinal;
					end
					else if (start & (change >= 7'd25))
					begin
						$display($time, " << Go to State $0.25 >>",change);
						nextstate <= Squarter;
					end
					else if (start & (change >= 7'd10))
					begin
						$display($time, " << Go to State $0.10 >>",change);
						nextstate <= Sdime;
					end
					else if (start & (change >= 7'd5))
					begin
						$display($time, " << Go to State $0.05 >>",change);
						nextstate <= Snickel;
					end
					else if (start & (change >= 7'd1))
					begin
						$display($time, " << Go to State $0.01 >>",change);
						nextstate <= Spenny;
					end
					else
					begin
						nextstate <= Sfinal;
					end
				end
			Squarter:
				begin
					$display($time, " << Reached State $0.25 >>", change);
					change = change - 7'd25;
					$display(" << New change for $0.25 >>", change);
					if (change >= 7'd25)
					begin
						nextstate <= SquarterTemp;
					end
					else if (change >= 7'd10)
					begin
						nextstate <= Sdime;
					end
					else if (change >= 7'd5)
					begin
						nextstate <= Snickel;
					end
					else if (change >= 7'd1)
					begin
						nextstate <= Spenny;
					end
					else
					begin

						nextstate <= Sfinal;
					end
				end
			Sdime:
				begin
					$display($time, " << Reached State $0.10 >>", change);
					change = change - 7'd10;
					$display(" << New change for $0.10 >>", change);
					if (change >= 7'd25)
					begin
						nextstate <= Squarter; 
					end
					else if (change >= 7'd10)
					begin
						$display(" << Return to the Dime state >>", change);
						nextstate <= SdimeTemp;
					end
					else if (change >= 7'd5)
					begin
						nextstate <= Snickel;
					end
					else if (change >= 7'd1)
					begin
						nextstate <= Spenny;
					end
					else
					begin

						nextstate <= Sfinal;
					end
				end
			Snickel:
				begin
					$display($time, " << Reached State $0.05 >>", change);
					change = change - 7'd5;
					$display(" << New change for $0.05 >>", change);
					if (change >= 7'd25)
					begin
						nextstate <= Squarter;
					end
					else if (change >= 7'd10)
					begin
						nextstate <= Sdime;
					end
					else if (change >= 7'd5)
					begin
						nextstate <= SnickelTemp;
					end
					else if (change >= 7'd1)
					begin
						nextstate <= Spenny;
					end
					else
					begin

						nextstate <= Sfinal;
					end
				end
			Spenny:
				begin
					$display($time, " << Reached State $0.01 >>",change);
					change = change - 7'd1;
					$display(" << New change for $0.01 >>", change);
					if (change >= 7'd25)
					begin
						nextstate <= Squarter;
					end
					else if (change >= 7'd10)
					begin
						nextstate <= Sdime;
					end
					else if (change >= 7'd5)
					begin
						nextstate <= Snickel;
					end
					else if (change >= 7'd1)
					begin
						$display(" << Change for additional $0.01 >>", change);
						nextstate <= SpennyTemp;
						$display(" << Changed ==> >>", change);
					end
					else if (change == 0)
					begin

						$display(" << No More Change >>", change);
						nextstate <= Sfinal;
					end

				end
			Sfinal:
				begin
					$display($time, " << Reached State $0.00 >>",change);
					
					if ((change < 7'd5) & (change > 0)) 
					begin
						$display($time, " << Go to State Penny >>",change);
						nextstate <= Spenny;
					end
					else
					begin
						if (start)
						begin
							$display($time, " << Go to Initial State >>",change);
							nextstate <= Sinitial;
						end
						else
						begin
							$display($time, " << Remain at Next State >>",change);
							nextstate <= Sfinal;
						end
					end
				end
				
			SquarterTemp:
				begin
					$display($time, " << Reached Temp State $0.25 >>",change);
					nextstate <= Squarter;
				end
			SdimeTemp:
				begin
					$display($time, " << Reached Temp State $0.10 >>",change);
					nextstate <= Sdime;
				end
			SnickelTemp:
				begin
					$display($time, " << Reached Temp State $0.05 >>",change);
					nextstate <= Snickel;
				end
			SpennyTemp:
				begin
					$display($time, " << Reached Temp State $0.01 >>",change);
					nextstate <= Spenny;
				end
				
			default:
				begin
					nextstate <= Sinitial;
				end
		endcase
	end
	
	

	always @(state)
	begin
		case(state)
			Sinitial:
				begin
					disp_Q <= 0;
					disp_D <= 0;
					disp_N <= 0;
					disp_P <= 0;
					done <= 0;
				end
			Squarter:
				begin
					disp_Q <= 1;
					disp_D <= 0;
					disp_N <= 0;
					disp_P <= 0;
					done <= 0;
				end
			Sdime:
				begin
					disp_Q <= 0;
					disp_D <= 1;
					disp_N <= 0;
					disp_P <= 0;
					done <= 0;
				end
			Snickel:
				begin
					disp_Q <= 0;
					disp_D <= 0;
					disp_N <= 1;
					disp_P <= 0;
					done <= 0;
				end
			Spenny:
				begin
					disp_Q <= 0;
					disp_D <= 0;
					disp_N <= 0;
					disp_P <= 1;
					done <= 0;
				end
			Sfinal:
				begin
					disp_Q <= 0;
					disp_D <= 0;
					disp_N <= 0;
					disp_P <= 0;
					done <= 1;
				end
				
			SquarterTemp:
				begin
					disp_Q <= 0;
					disp_D <= 0;
					disp_N <= 0;
					disp_P <= 0;
					done <= 0;
				end
			SdimeTemp:
				begin
					disp_Q <= 0;
					disp_D <= 0;
					disp_N <= 0;
					disp_P <= 0;
					done <= 0;
				end
			SnickelTemp:
				begin
					disp_Q <= 0;
					disp_D <= 0;
					disp_N <= 0;
					disp_P <= 0;
					done <= 0;
				end
			SpennyTemp:
				begin
					disp_Q <= 0;
					disp_D <= 0;
					disp_N <= 0;
					disp_P <= 0;
					done <= 0;
				end
				
			default:
				begin
					disp_Q <= 0;
					disp_D <= 0;
					disp_N <= 0;
					disp_P <= 0;
					done <= 1;
				end
		endcase
	end
	
endmodule
module fsmVendingMachine(disp_Q,disp_D,disp_N,disp_P,done,
	money,price,start,clk,reset);

	

	output reg disp_Q,disp_D,disp_N,disp_P,done;
	

	input [6:0] money,price;
	input start,clk,reset;
	

	


	

	reg [3:0] state, nextstate;
	reg [6:0] change;

	reg flagDone;
	



	parameter Sinitial = 4'b0000;

	parameter Squarter = 4'b0001;

	parameter Sdime = 4'b0010;

	parameter Snickel = 4'b0011;

	parameter Spenny = 4'b0100;

	parameter Sfinal = 4'b0101;

	parameter SquarterTemp = 4'b0110;

	parameter SdimeTemp = 4'b0111;

	parameter SnickelTemp = 4'b1000;

	parameter SpennyTemp = 4'b1001;
	
	

	always @(posedge clk)
	begin

		if (reset)

			state <= Sinitial;
		else

			state <= nextstate;
	end
	
	

	always @(*)
	begin
		case (state)
			Sinitial:
				begin
					if(money < price)
					begin
						change = money;
					end
					else
					begin
						change = money - price;
					end
					
					
					if (start & (change == 0))
					begin
						$display($time, " << Go to State $0.00 >>",change);
						nextstate <= Sfinal;
					end
					else if (start & (change >= 7'd25))
					begin
						$display($time, " << Go to State $0.25 >>",change);
						nextstate <= Squarter;
					end
					else if (start & (change >= 7'd10))
					begin
						$display($time, " << Go to State $0.10 >>",change);
						nextstate <= Sdime;
					end
					else if (start & (change >= 7'd5))
					begin
						$display($time, " << Go to State $0.05 >>",change);
						nextstate <= Snickel;
					end
					else if (start & (change >= 7'd1))
					begin
						$display($time, " << Go to State $0.01 >>",change);
						nextstate <= Spenny;
					end
					else
					begin
						nextstate <= Sfinal;
					end
				end
			Squarter:
				begin
					$display($time, " << Reached State $0.25 >>", change);
					change = change - 7'd25;
					$display(" << New change for $0.25 >>", change);
					if (change >= 7'd25)
					begin
						nextstate <= SquarterTemp;
					end
					else if (change >= 7'd10)
					begin
						nextstate <= Sdime;
					end
					else if (change >= 7'd5)
					begin
						nextstate <= Snickel;
					end
					else if (change >= 7'd1)
					begin
						nextstate <= Spenny;
					end
					else
					begin

						nextstate <= Sfinal;
					end
				end
			Sdime:
				begin
					$display($time, " << Reached State $0.10 >>", change);
					change = change - 7'd10;
					$display(" << New change for $0.10 >>", change);
					if (change >= 7'd25)
					begin
						nextstate <= Squarter; 
					end
					else if (change >= 7'd10)
					begin
						$display(" << Return to the Dime state >>", change);
						nextstate <= SdimeTemp;
					end
					else if (change >= 7'd5)
					begin
						nextstate <= Snickel;
					end
					else if (change >= 7'd1)
					begin
						nextstate <= Spenny;
					end
					else
					begin

						nextstate <= Sfinal;
					end
				end
			Snickel:
				begin
					$display($time, " << Reached State $0.05 >>", change);
					change = change - 7'd5;
					$display(" << New change for $0.05 >>", change);
					if (change >= 7'd25)
					begin
						nextstate <= Squarter;
					end
					else if (change >= 7'd10)
					begin
						nextstate <= Sdime;
					end
					else if (change >= 7'd5)
					begin
						nextstate <= SnickelTemp;
					end
					else if (change >= 7'd1)
					begin
						nextstate <= Spenny;
					end
					else
					begin

						nextstate <= Sfinal;
					end
				end
			Spenny:
				begin
					$display($time, " << Reached State $0.01 >>",change);
					change = change - 7'd1;
					$display(" << New change for $0.01 >>", change);
					if (change >= 7'd25)
					begin
						nextstate <= Squarter;
					end
					else if (change >= 7'd10)
					begin
						nextstate <= Sdime;
					end
					else if (change >= 7'd5)
					begin
						nextstate <= Snickel;
					end
					else if (change >= 7'd1)
					begin
						$display(" << Change for additional $0.01 >>", change);
						nextstate <= SpennyTemp;
						$display(" << Changed ==> >>", change);
					end
					else if (change == 0)
					begin

						$display(" << No More Change >>", change);
						nextstate <= Sfinal;
					end

				end
			Sfinal:
				begin
					$display($time, " << Reached State $0.00 >>",change);
					
					if ((change < 7'd5) & (change > 0)) 
					begin
						$display($time, " << Go to State Penny >>",change);
						nextstate <= Spenny;
					end
					else
					begin
						if (start)
						begin
							$display($time, " << Go to Initial State >>",change);
							nextstate <= Sinitial;
						end
						else
						begin
							$display($time, " << Remain at Next State >>",change);
							nextstate <= Sfinal;
						end
					end
				end
				
			SquarterTemp:
				begin
					$display($time, " << Reached Temp State $0.25 >>",change);
					nextstate <= Squarter;
				end
			SdimeTemp:
				begin
					$display($time, " << Reached Temp State $0.10 >>",change);
					nextstate <= Sdime;
				end
			SnickelTemp:
				begin
					$display($time, " << Reached Temp State $0.05 >>",change);
					nextstate <= Snickel;
				end
			SpennyTemp:
				begin
					$display($time, " << Reached Temp State $0.01 >>",change);
					nextstate <= Spenny;
				end
				
			default:
				begin
					nextstate <= Sinitial;
				end
		endcase
	end
	
	

	always @(state)
	begin
		case(state)
			Sinitial:
				begin
					disp_Q <= 0;
					disp_D <= 0;
					disp_N <= 0;
					disp_P <= 0;
					done <= 0;
				end
			Squarter:
				begin
					disp_Q <= 1;
					disp_D <= 0;
					disp_N <= 0;
					disp_P <= 0;
					done <= 0;
				end
			Sdime:
				begin
					disp_Q <= 0;
					disp_D <= 1;
					disp_N <= 0;
					disp_P <= 0;
					done <= 0;
				end
			Snickel:
				begin
					disp_Q <= 0;
					disp_D <= 0;
					disp_N <= 1;
					disp_P <= 0;
					done <= 0;
				end
			Spenny:
				begin
					disp_Q <= 0;
					disp_D <= 0;
					disp_N <= 0;
					disp_P <= 1;
					done <= 0;
				end
			Sfinal:
				begin
					disp_Q <= 0;
					disp_D <= 0;
					disp_N <= 0;
					disp_P <= 0;
					done <= 1;
				end
				
			SquarterTemp:
				begin
					disp_Q <= 0;
					disp_D <= 0;
					disp_N <= 0;
					disp_P <= 0;
					done <= 0;
				end
			SdimeTemp:
				begin
					disp_Q <= 0;
					disp_D <= 0;
					disp_N <= 0;
					disp_P <= 0;
					done <= 0;
				end
			SnickelTemp:
				begin
					disp_Q <= 0;
					disp_D <= 0;
					disp_N <= 0;
					disp_P <= 0;
					done <= 0;
				end
			SpennyTemp:
				begin
					disp_Q <= 0;
					disp_D <= 0;
					disp_N <= 0;
					disp_P <= 0;
					done <= 0;
				end
				
			default:
				begin
					disp_Q <= 0;
					disp_D <= 0;
					disp_N <= 0;
					disp_P <= 0;
					done <= 1;
				end
		endcase
	end
	
endmodule