Page 1 of 3

VS. Duck Hunt zapper not responding properly [SOLVED]

Posted: Fri Jun 17, 2016 7:10 am
by zeroone
I am attempting to add VS. Zapper support to my emulator by following the description on the wiki (the VS. Zapper is strobed and serialized like a standard controller). But, it is only partially working. In VS. Duck Hunt, when the trigger is pulled on the single player select screen, it generates a fully black frame, then a fully white frame and finally another fully black screen. Debugging reveals that during the black frames, it reads from the controller port once per scanline, presumably examining the light sensor bit. However, during the white frame, it does not read from the controller port at all. Debugging also shows that during the white frame, the light sensor is active for 26 scanlines. But, since the game is simply not reading from the controller port during the white frame, it fails to get detected.

I tried various combinations of trigger pull times and light sensor active times without success.

Could this somehow be related to the VS. palettes? VS. Duck Hunt uses a palette that is almost identical to the standard NES palette. However, is something strange done to generate the fully colored frames? Could the black and white frames be reversed in color or something?

Re: VS. Duck Hunt zapper not responding properly

Posted: Sat Jun 18, 2016 6:57 am
by Quietust
The Vs Zapper's light sense bit is inverted compared to the standard Zapper (or "normal" from a neutral standpoint) - 1 when sensing light, 0 otherwise. If you were using the same behavior as the normal Zapper, the game probably decided that you weren't pointing at the screen and thus didn't bother checking it during the white frame (though it would've also stopped reading during the "dark" frame after the very first scanline).

Re: VS. Duck Hunt zapper not responding properly

Posted: Sat Jun 18, 2016 8:41 pm
by zeroone
Quietust wrote:The Vs Zapper's light sense bit is inverted compared to the standard Zapper (or "normal" from a neutral standpoint) - 1 when sensing light, 0 otherwise. If you were using the same behavior as the normal Zapper, the game probably decided that you weren't pointing at the screen and thus didn't bother checking it during the white frame (though it would've also stopped reading during the "dark" frame after the very first scanline).
Thanks for the suggestion, but my implementation is already doing that per the information on the wiki. The cause of the issue is something else.

Re: VS. Duck Hunt zapper not responding properly

Posted: Sun Jun 19, 2016 1:00 am
by Memblers
I don't know how it's detected exactly, but the gun manual for the VS says that games are supposed to trigger an alarm if it thinks the gun has been removed/stolen/vandalized. Maybe the game thinks something is wrong and is getting into a state where it doesn't check for hits anymore? Just a guess. I would think you'd hear an audible alarm if that was the case, but I don't know, it must depend on how each game handles it.

Re: VS. Duck Hunt zapper not responding properly

Posted: Sun Jun 19, 2016 6:26 am
by Quietust
Memblers wrote:I don't know how it's detected exactly, but the gun manual for the VS says that games are supposed to trigger an alarm if it thinks the gun has been removed/stolen/vandalized. Maybe the game thinks something is wrong and is getting into a state where it doesn't check for hits anymore? Just a guess. I would think you'd hear an audible alarm if that was the case, but I don't know, it must depend on how each game handles it.
You definitely do hear an alarm in Duck Hunt when that happens - if the gun isn't connected on startup, it plays about 2 notes of the title screen tune before emitting a loud beep, and disconnecting it at any point during gameplay has a similar effect. Hogan's Alley is the same way.

Re: VS. Duck Hunt zapper not responding properly

Posted: Tue Jun 21, 2016 11:15 am
by zeroone
@Quietust Is there any way to test the VS. Zapper in Nintendulator? It reports Mapper 099 as unsupported, but source suggests otherwise.

Re: VS. Duck Hunt zapper not responding properly

Posted: Wed Jun 22, 2016 7:58 am
by zeroone
I really can't figure out what is going wrong with my VS. Zapper implementation. I'm willing to run whatever test anyone can suggestion. I'm out of ideas. Thanks.

Re: VS. Duck Hunt zapper not responding properly

Posted: Thu Jun 23, 2016 4:41 am
by Quietust
zeroone wrote:@Quietust Is there any way to test the VS. Zapper in Nintendulator? It reports Mapper 099 as unsupported, but source suggests otherwise.
Either you're running a very old version (0.975, despite being "unstable", is what you actually want to be running), or you somehow extracted the archive without subfolders and it can't find the mapper DLLs.

Re: VS. Duck Hunt zapper not responding properly

Posted: Thu Jun 23, 2016 5:18 am
by Dwedit
Or maybe the mapper DLLs got overwritten with DLLs from another emulator. I know that NESten uses the same filenames for mappers.

Re: VS. Duck Hunt zapper not responding properly

Posted: Thu Jun 23, 2016 7:02 am
by zeroone
Quietust wrote:
zeroone wrote:@Quietust Is there any way to test the VS. Zapper in Nintendulator? It reports Mapper 099 as unsupported, but source suggests otherwise.
Either you're running a very old version (0.975, despite being "unstable", is what you actually want to be running), or you somehow extracted the archive without subfolders and it can't find the mapper DLLs.
Version 0.975 does not appear to support Mapper 099. I re-downloaded it to be sure. I see the VS.dll in the the mappers subdirectory. It is dated 02/28/2015.

By the way, what controller does VS Duck Hunt expect in the other port?

Re: VS. Duck Hunt zapper not responding properly

Posted: Thu Jun 23, 2016 12:19 pm
by 2600
What is your zapper implementation?

Do you have it assigned to the correct port?

Re: VS. Duck Hunt zapper not responding properly

Posted: Thu Jun 23, 2016 12:32 pm
by zeroone
2600 wrote:What is your zapper implementation?

Do you have it assigned to the correct port?
I followed the description on the wiki. It provides the data serially like the gamepad. My VS Zapper implementation is an extension of my standard NES Zapper implementation that works correctly with normal Duck Hunt. In VS Duck Hunt, the player select screen flashes when the trigger is pulled, but the game fails to register the hit. Per the description earlier in the thread, the flash is actually 3 frames: full black, full white, full black. Debugging shows that it reads from the zapper port once-per-scanline only during the full black frame, ignoring when the light sensor detects the white frame. The sensor is also inactive in the black frame.

Since the trigger and the light sensor data is delivered serially from the same bit and the game does respond to the trigger, it suggests that my implementation is rigged up to deliver the data on the proper port.

I'm willing to run any experiment and collect any kind of logging that someone can suggest. This is a really strange issue.

Re: VS. Duck Hunt zapper not responding properly

Posted: Thu Jun 23, 2016 3:51 pm
by Quietust
zeroone wrote:Version 0.975 does not appear to support Mapper 099. I re-downloaded it to be sure. I see the VS.dll in the the mappers subdirectory. It is dated 02/28/2015.
Open the ROM in Nintendulator's Header Editor and make sure the "VS Unisystem" flag is set. If it's not set, that's why it doesn't work - VS.dll will only accept .NES files that have that flag set.

Re: VS. Duck Hunt zapper not responding properly

Posted: Thu Jun 23, 2016 4:24 pm
by zeroone
Quietust wrote:Open the ROM in Nintendulator's Header Editor and make sure the "VS Unisystem" flag is set. If it's not set, that's why it doesn't work - VS.dll will only accept .NES files that have that flag set.
Thanks. Setting the flag in the header enabled it to load. Nintendulator's VS UniSystem Zapper works perfectly.

Re: VS. Duck Hunt zapper not responding properly

Posted: Thu Jun 23, 2016 7:55 pm
by zeroone
@Quietust In the controller port write function below, does PPU::DrawArray contain prior frame pixel values within the region that has yet to be updated? Or, is PPU::DrawArray cleared between frames?

Code: Select all

void	StdPort_VSZapper::Write (unsigned char Val)
{
	int x = State->PosX, y = State->PosY;

	State->Strobe = Val & 1;
	if (!State->Strobe)
		return;
		
	State->Bits = 0x10;
	State->BitPtr = 0;
	if (State->Button)
		State->Bits |= 0x80;

	if ((x < 0) || (x >= 256) || (y < 0) || (y >= 240))
		return;

	if (PPU::IsRendering && PPU::OnScreen)
	{
		int X, Y;
		int WhiteCount = 0;
		for (Y = y - 8; Y < y + 8; Y++)
		{
			if (Y < 0)
				Y = 0;
			if (Y < PPU::SLnum - 32)
				continue;
			if (Y > PPU::SLnum)
				break;
			for (X = x - 8; X < x + 8; X++)
			{
				if (X < 0)
					X = 0;
				if (X > 255)
					break;
				if ((Y == PPU::SLnum) && (X >= PPU::Clockticks))
					break;
				if (GFX::ZapperHit(PPU::DrawArray[Y * 256 + X]))
					WhiteCount++;
			}
		}
		if (WhiteCount >= 64)
			State->Bits |= 0x40;
	}
}