data/full_repos/permissive/143453443/src/Sound.v
1: b'%Warning-WIDTH: data/full_repos/permissive/143453443/src/Sound.v:18: Operator DIV expects 26 bits on the RHS, but RHS\'s CONST \'15\'h64\' generates 15 bits.\n                                                                   : ... In instance Sound\nlocalparam ticks100Hz = 26\'d40000000 / 15\'d100 / 8\'d2;\n                                     ^\n                ... Use "/* verilator lint_off WIDTH */" and lint_on around source to disable this message.\n%Warning-WIDTH: data/full_repos/permissive/143453443/src/Sound.v:18: Operator DIV expects 26 bits on the RHS, but RHS\'s CONST \'8\'h2\' generates 8 bits.\n                                                                   : ... In instance Sound\nlocalparam ticks100Hz = 26\'d40000000 / 15\'d100 / 8\'d2;\n                                               ^\n%Warning-WIDTH: data/full_repos/permissive/143453443/src/Sound.v:19: Operator DIV expects 26 bits on the RHS, but RHS\'s CONST \'15\'h2ee\' generates 15 bits.\n                                                                   : ... In instance Sound\nlocalparam ticks750Hz = 26\'d40000000 / 15\'d750 / 8\'d2;\n                                     ^\n%Warning-WIDTH: data/full_repos/permissive/143453443/src/Sound.v:19: Operator DIV expects 26 bits on the RHS, but RHS\'s CONST \'8\'h2\' generates 8 bits.\n                                                                   : ... In instance Sound\nlocalparam ticks750Hz = 26\'d40000000 / 15\'d750 / 8\'d2;\n                                               ^\n%Warning-WIDTH: data/full_repos/permissive/143453443/src/Sound.v:20: Operator DIV expects 26 bits on the RHS, but RHS\'s CONST \'15\'h3e8\' generates 15 bits.\n                                                                   : ... In instance Sound\nlocalparam ticks1kHz = 26\'d40000000 / 15\'d1000 / 8\'d2;\n                                    ^\n%Warning-WIDTH: data/full_repos/permissive/143453443/src/Sound.v:20: Operator DIV expects 26 bits on the RHS, but RHS\'s CONST \'8\'h2\' generates 8 bits.\n                                                                   : ... In instance Sound\nlocalparam ticks1kHz = 26\'d40000000 / 15\'d1000 / 8\'d2;\n                                               ^\n%Error: Exiting due to 6 warning(s)\n'
module Sound(
	input pixelClock,
	input vSyncStart,
	input collisionBallScreenLeft,
	input collisionBallScreenRight,
	input collisionBallScreenTop,
	input collisionBallScreenBottom,
	input collisionBallPlayerPaddle,
	input collisionBallComputerPaddle,
	output reg SPEAKER
);

reg [25:0] count = 0;
reg [25:0] ticksPerHz;
reg [15:0] durationFrames = 0;


localparam ticks100Hz = 26'd40000000 / 15'd100 / 8'd2;
localparam ticks750Hz = 26'd40000000 / 15'd750 / 8'd2;
localparam ticks1kHz = 26'd40000000 / 15'd1000 / 8'd2;

always @(posedge pixelClock)
begin
	count <= count + 1'b1;

	if (vSyncStart)
		begin
			if (collisionBallScreenLeft | collisionBallScreenRight)
				begin
					count <= 0;
					ticksPerHz <= ticks100Hz;
					durationFrames <= 60;
				end
			else
				if (durationFrames == 0)
					begin
						if (collisionBallScreenTop | collisionBallScreenBottom)
							begin
								count <= 0;
								ticksPerHz <= ticks750Hz;
								durationFrames <= 2;
							end

						if (collisionBallPlayerPaddle | collisionBallComputerPaddle)
							begin
								count <= 0;
								ticksPerHz <= ticks1kHz;
								durationFrames <= 2;
							end
					end
				else
					durationFrames <= durationFrames - 1'b1;
		end

	if (durationFrames > 0 & count >= ticksPerHz)
		begin
			SPEAKER <= ~SPEAKER;
			count <= 0;
		end
end

endmodule
module Sound(
	input pixelClock,
	input vSyncStart,
	input collisionBallScreenLeft,
	input collisionBallScreenRight,
	input collisionBallScreenTop,
	input collisionBallScreenBottom,
	input collisionBallPlayerPaddle,
	input collisionBallComputerPaddle,
	output reg SPEAKER
);


reg [25:0] count = 0;
reg [25:0] ticksPerHz;
reg [15:0] durationFrames = 0;


localparam ticks100Hz = 26'd40000000 / 15'd100 / 8'd2;
localparam ticks750Hz = 26'd40000000 / 15'd750 / 8'd2;
localparam ticks1kHz = 26'd40000000 / 15'd1000 / 8'd2;

always @(posedge pixelClock)
begin
	count <= count + 1'b1;

	if (vSyncStart)
		begin
			if (collisionBallScreenLeft | collisionBallScreenRight)
				begin
					count <= 0;
					ticksPerHz <= ticks100Hz;
					durationFrames <= 60;
				end
			else
				if (durationFrames == 0)
					begin
						if (collisionBallScreenTop | collisionBallScreenBottom)
							begin
								count <= 0;
								ticksPerHz <= ticks750Hz;
								durationFrames <= 2;
							end

						if (collisionBallPlayerPaddle | collisionBallComputerPaddle)
							begin
								count <= 0;
								ticksPerHz <= ticks1kHz;
								durationFrames <= 2;
							end
					end
				else
					durationFrames <= durationFrames - 1'b1;
		end

	if (durationFrames > 0 & count >= ticksPerHz)
		begin
			SPEAKER <= ~SPEAKER;
			count <= 0;
		end
end

endmodule