data/full_repos/permissive/48192473/rtl/sound_controller_modules/SoundControllerChannel1.v
1: b'%Warning-WIDTH: data/full_repos/permissive/48192473/rtl/sound_controller_modules/SoundControllerChannel1.v:76: Operator SUB expects 32 or 20 bits on the RHS, but RHS\'s SEL generates 6 bits.\n                                                                                                             : ... In instance SoundCtrlChannel1\n   rLengthCounter  <= 64-iNR11[5:0];   \n                        ^\n                ... Use "/* verilator lint_off WIDTH */" and lint_on around source to disable this message.\n%Warning-WIDTH: data/full_repos/permissive/48192473/rtl/sound_controller_modules/SoundControllerChannel1.v:81: Operator ASSIGNDLY expects 19 bits on the Assign RHS, but Assign RHS\'s SEL generates 3 bits.\n                                                                                                             : ... In instance SoundCtrlChannel1\n   rStepTime  <= iNR12[2:0];\n              ^~\n%Warning-WIDTH: data/full_repos/permissive/48192473/rtl/sound_controller_modules/SoundControllerChannel1.v:82: Operator ASSIGNDLY expects 19 bits on the Assign RHS, but Assign RHS\'s SEL generates 3 bits.\n                                                                                                             : ... In instance SoundCtrlChannel1\n   rStepCounter  <= iNR12[2:0];  \n                 ^~\n%Warning-WIDTH: data/full_repos/permissive/48192473/rtl/sound_controller_modules/SoundControllerChannel1.v:88: Operator ASSIGNDLY expects 11 bits on the Assign RHS, but Assign RHS\'s SUB generates 32 or 12 bits.\n                                                                                                             : ... In instance SoundCtrlChannel1\n   rSoundFrequency[10:0] <= 2048-{iNR14[2:0],iNR13[7:0]};\n                         ^~\n%Warning-WIDTH: data/full_repos/permissive/48192473/rtl/sound_controller_modules/SoundControllerChannel1.v:89: Operator ASSIGNDLY expects 11 bits on the Assign RHS, but Assign RHS\'s SUB generates 32 or 12 bits.\n                                                                                                             : ... In instance SoundCtrlChannel1\n   rSoundFrequencyCounter[10:0] <= 2048-{iNR14[2:0],iNR13[7:0]}; \n                                ^~\n%Warning-WIDTH: data/full_repos/permissive/48192473/rtl/sound_controller_modules/SoundControllerChannel1.v:97: Operator ASSIGNDLY expects 18 bits on the Assign RHS, but Assign RHS\'s SEL generates 3 bits.\n                                                                                                             : ... In instance SoundCtrlChannel1\n   rSweepCounter <= iNR10[6:4];\n                 ^~\n%Warning-WIDTH: data/full_repos/permissive/48192473/rtl/sound_controller_modules/SoundControllerChannel1.v:136: Operator SHIFTR expects 12 bits on the LHS, but LHS\'s VARREF \'rSoundFrequency\' generates 11 bits.\n                                                                                                              : ... In instance SoundCtrlChannel1\n    rSoundFrequencyNew <= rSoundFrequency + (rSoundFrequency >> rSweepShifts);\n                                                             ^~\n%Warning-WIDTH: data/full_repos/permissive/48192473/rtl/sound_controller_modules/SoundControllerChannel1.v:139: Operator SHIFTR expects 12 bits on the LHS, but LHS\'s VARREF \'rSoundFrequency\' generates 11 bits.\n                                                                                                              : ... In instance SoundCtrlChannel1\n    rSoundFrequencyNew <= rSoundFrequency - (rSoundFrequency >> rSweepShifts);   \n                                                             ^~\n%Warning-WIDTH: data/full_repos/permissive/48192473/rtl/sound_controller_modules/SoundControllerChannel1.v:148: Operator ASSIGNDLY expects 11 bits on the Assign RHS, but Assign RHS\'s VARREF \'rSoundFrequencyNew\' generates 12 bits.\n                                                                                                              : ... In instance SoundCtrlChannel1\n    rSoundFrequency <= rSoundFrequencyNew;\n                    ^~\n%Warning-WIDTH: data/full_repos/permissive/48192473/rtl/sound_controller_modules/SoundControllerChannel1.v:150: Operator ASSIGNDLY expects 18 bits on the Assign RHS, but Assign RHS\'s VARREF \'rSweepTime\' generates 3 bits.\n                                                                                                              : ... In instance SoundCtrlChannel1\n   rSweepCounter <= rSweepTime;\n                 ^~\n%Warning-WIDTH: data/full_repos/permissive/48192473/rtl/sound_controller_modules/SoundControllerChannel1.v:161: Operator SUB expects 32 or 20 bits on the RHS, but RHS\'s VARREF \'rLength\' generates 6 bits.\n                                                                                                              : ... In instance SoundCtrlChannel1\n   rLengthCounter <= 64-rLength;\n                       ^\n%Error: Exiting due to 11 warning(s)\n'
module SoundCtrlChannel1
  (
    input wire		iClock,
    input wire		iReset,
    input wire		iOsc64,
	input wire		iOsc256,
	input wire 		iOsc128,
    input wire		iOsc262k,

    input wire [7:0] iNR10,
    input wire [7:0] iNR11,
    input wire [7:0] iNR12,
    input wire [7:0] iNR13,
    input wire [7:0] iNR14,            

    output reg [4:0]	oOut,
    output wire oOnFlag    
  );


 	reg [2:0] rSweepShifts;
 	reg rSweepMode;
 	reg [2:0] rSweepTime;
 	reg [17:0] rSweepCounter;
	reg [11:0] rSoundFrequencyNew;


	reg [5:0] rLength;
 	reg [19:0] rLengthCounter;	
	reg [1:0] rDutyCycle;
	reg rTimedMode;
 	reg rLengthComplete;

	reg rTone;
	reg [10:0] rSoundFrequency;
	reg [10:0] rSoundFrequencyCounter;


	reg [3:0] rStep;
	reg [18:0] rStepTime;
	reg [18:0] rStepCounter;
	reg [3:0] rInitialValue;
	reg rEvelopeMode;

 	wire [4:0] up_value, down_value;


	always @(posedge iClock) begin
		if (iReset || iNR14[7]) begin

			rLength 		<= iNR11[5:0];
			rLengthCounter 	<= 64-iNR11[5:0];
			rLengthComplete <= 0;
			rDutyCycle		<= iNR11[7:6];
			rTimedMode <= iNR14[6];

			rStepTime		<= iNR12[2:0];
			rStepCounter 	<= iNR12[2:0];
			rEvelopeMode	<= iNR12[3];
			rInitialValue	<= iNR12[7:4];
			rStep 			<= iNR12[7:4];

			rTone 			<= 0;
			rSoundFrequency[10:0] <= 2048-{iNR14[2:0],iNR13[7:0]};
			rSoundFrequencyCounter[10:0] <= 2048-{iNR14[2:0],iNR13[7:0]}; 

			rSoundFrequencyNew <= 2048-{iNR14[2:0],iNR13[7:0]};


			rSweepShifts <= iNR10[2:0];
			rSweepMode <= iNR10[3];
			rSweepTime <= iNR10[6:4];
			rSweepCounter <= iNR10[6:4];

		end
	end


  	always @(posedge iOsc64) begin
  		if (rStepTime != 0) begin
	  		if (rStepCounter ==1 ) begin
	  			rStepCounter <= rStepTime;
				if(rEvelopeMode) begin
					rStep <= ((rStep == 4'hF) ? rStep : rStep+1);
				end
				else begin
					rStep <= ((rStep == 4'h0) ? rStep : rStep-1);
				end
	  		end
	  		else begin
	  			rStepCounter <= rStepCounter-1;
	  		end  	
	  	end
	end


	always @(posedge iOsc262k) begin
		if (rSoundFrequencyCounter ==0) begin
			rSoundFrequencyCounter <= rSoundFrequency;
			rTone <= ~rTone;
		end
		else begin
			rSoundFrequencyCounter <= rSoundFrequencyCounter-1;
		end
	end


	always @(posedge iOsc128) begin

		if (rSweepCounter ==1 && rSweepShifts != 0 && rSweepTime > 0) begin
			if (rSweepMode) begin
				rSoundFrequencyNew <= rSoundFrequency + (rSoundFrequency >> rSweepShifts);
			end
			else begin
				rSoundFrequencyNew <= rSoundFrequency - (rSoundFrequency >> rSweepShifts);			
			end
		end

		if (rSweepCounter ==0 && rSweepTime > 0) begin
			if (rSoundFrequencyNew == 1 && rSoundFrequency == 1) begin
				rLengthComplete = 1'b1 ;
			end
			else if (rSoundFrequencyNew <= 2047) begin
				rSoundFrequency <= rSoundFrequencyNew;
			end
			rSweepCounter <= rSweepTime;
		end
		
		else begin
			rSweepCounter = rSweepCounter-1;
		end
	end


	always @(posedge iOsc256) begin
		if (rLengthCounter == 0) begin
			rLengthCounter <= 64-rLength;
			rLengthComplete <= (rTimedMode || rLengthComplete);
		end
		else begin
			rLengthCounter <= rLengthCounter-1;
		end
	end


	assign up_value = 5'd15 + rStep;
	assign down_value = 5'd15 - rStep;

	always @(posedge iClock) begin
		if (rLengthComplete) begin
			oOut[4:0] <= 5'd15;
		end
		else begin
			if (rTone) begin
				oOut[4:0] <= up_value[4:0];
			end
			else begin
				oOut[4:0] <= down_value[4:0];
			end
		end
	end

assign oOnFlag = rLengthComplete;
 
endmodule
module SoundCtrlChannel1
  (
    input wire		iClock,
    input wire		iReset,
    input wire		iOsc64,
	input wire		iOsc256,
	input wire 		iOsc128,
    input wire		iOsc262k,

    input wire [7:0] iNR10,
    input wire [7:0] iNR11,
    input wire [7:0] iNR12,
    input wire [7:0] iNR13,
    input wire [7:0] iNR14,            

    output reg [4:0]	oOut,
    output wire oOnFlag    
  );



 	reg [2:0] rSweepShifts;
 	reg rSweepMode;
 	reg [2:0] rSweepTime;
 	reg [17:0] rSweepCounter;
	reg [11:0] rSoundFrequencyNew;


	reg [5:0] rLength;
 	reg [19:0] rLengthCounter;	
	reg [1:0] rDutyCycle;
	reg rTimedMode;
 	reg rLengthComplete;

	reg rTone;
	reg [10:0] rSoundFrequency;
	reg [10:0] rSoundFrequencyCounter;


	reg [3:0] rStep;
	reg [18:0] rStepTime;
	reg [18:0] rStepCounter;
	reg [3:0] rInitialValue;
	reg rEvelopeMode;

 	wire [4:0] up_value, down_value;


	always @(posedge iClock) begin
		if (iReset || iNR14[7]) begin

			rLength 		<= iNR11[5:0];
			rLengthCounter 	<= 64-iNR11[5:0];
			rLengthComplete <= 0;
			rDutyCycle		<= iNR11[7:6];
			rTimedMode <= iNR14[6];

			rStepTime		<= iNR12[2:0];
			rStepCounter 	<= iNR12[2:0];
			rEvelopeMode	<= iNR12[3];
			rInitialValue	<= iNR12[7:4];
			rStep 			<= iNR12[7:4];

			rTone 			<= 0;
			rSoundFrequency[10:0] <= 2048-{iNR14[2:0],iNR13[7:0]};
			rSoundFrequencyCounter[10:0] <= 2048-{iNR14[2:0],iNR13[7:0]}; 

			rSoundFrequencyNew <= 2048-{iNR14[2:0],iNR13[7:0]};


			rSweepShifts <= iNR10[2:0];
			rSweepMode <= iNR10[3];
			rSweepTime <= iNR10[6:4];
			rSweepCounter <= iNR10[6:4];

		end
	end


  	always @(posedge iOsc64) begin
  		if (rStepTime != 0) begin
	  		if (rStepCounter ==1 ) begin
	  			rStepCounter <= rStepTime;
				if(rEvelopeMode) begin
					rStep <= ((rStep == 4'hF) ? rStep : rStep+1);
				end
				else begin
					rStep <= ((rStep == 4'h0) ? rStep : rStep-1);
				end
	  		end
	  		else begin
	  			rStepCounter <= rStepCounter-1;
	  		end  	
	  	end
	end


	always @(posedge iOsc262k) begin
		if (rSoundFrequencyCounter ==0) begin
			rSoundFrequencyCounter <= rSoundFrequency;
			rTone <= ~rTone;
		end
		else begin
			rSoundFrequencyCounter <= rSoundFrequencyCounter-1;
		end
	end


	always @(posedge iOsc128) begin

		if (rSweepCounter ==1 && rSweepShifts != 0 && rSweepTime > 0) begin
			if (rSweepMode) begin
				rSoundFrequencyNew <= rSoundFrequency + (rSoundFrequency >> rSweepShifts);
			end
			else begin
				rSoundFrequencyNew <= rSoundFrequency - (rSoundFrequency >> rSweepShifts);			
			end
		end

		if (rSweepCounter ==0 && rSweepTime > 0) begin
			if (rSoundFrequencyNew == 1 && rSoundFrequency == 1) begin
				rLengthComplete = 1'b1 ;
			end
			else if (rSoundFrequencyNew <= 2047) begin
				rSoundFrequency <= rSoundFrequencyNew;
			end
			rSweepCounter <= rSweepTime;
		end
		
		else begin
			rSweepCounter = rSweepCounter-1;
		end
	end


	always @(posedge iOsc256) begin
		if (rLengthCounter == 0) begin
			rLengthCounter <= 64-rLength;
			rLengthComplete <= (rTimedMode || rLengthComplete);
		end
		else begin
			rLengthCounter <= rLengthCounter-1;
		end
	end


	assign up_value = 5'd15 + rStep;
	assign down_value = 5'd15 - rStep;

	always @(posedge iClock) begin
		if (rLengthComplete) begin
			oOut[4:0] <= 5'd15;
		end
		else begin
			if (rTone) begin
				oOut[4:0] <= up_value[4:0];
			end
			else begin
				oOut[4:0] <= down_value[4:0];
			end
		end
	end

assign oOnFlag = rLengthComplete;
 
endmodule