VS. Duck Hunt zapper not responding properly [SOLVED]

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

User avatar
zeroone
Posts: 939
Joined: Mon Dec 29, 2014 1:46 pm
Location: New York, NY
Contact:

VS. Duck Hunt zapper not responding properly [SOLVED]

Post 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?
Last edited by zeroone on Tue Jun 28, 2016 5:54 pm, edited 1 time in total.
User avatar
Quietust
Posts: 1918
Joined: Sun Sep 19, 2004 10:59 pm
Contact:

Re: VS. Duck Hunt zapper not responding properly

Post 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).
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.
User avatar
zeroone
Posts: 939
Joined: Mon Dec 29, 2014 1:46 pm
Location: New York, NY
Contact:

Re: VS. Duck Hunt zapper not responding properly

Post 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.
User avatar
Memblers
Site Admin
Posts: 4044
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Re: VS. Duck Hunt zapper not responding properly

Post 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.
User avatar
Quietust
Posts: 1918
Joined: Sun Sep 19, 2004 10:59 pm
Contact:

Re: VS. Duck Hunt zapper not responding properly

Post 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.
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.
User avatar
zeroone
Posts: 939
Joined: Mon Dec 29, 2014 1:46 pm
Location: New York, NY
Contact:

Re: VS. Duck Hunt zapper not responding properly

Post by zeroone »

@Quietust Is there any way to test the VS. Zapper in Nintendulator? It reports Mapper 099 as unsupported, but source suggests otherwise.
User avatar
zeroone
Posts: 939
Joined: Mon Dec 29, 2014 1:46 pm
Location: New York, NY
Contact:

Re: VS. Duck Hunt zapper not responding properly

Post 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.
User avatar
Quietust
Posts: 1918
Joined: Sun Sep 19, 2004 10:59 pm
Contact:

Re: VS. Duck Hunt zapper not responding properly

Post 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.
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.
User avatar
Dwedit
Posts: 4922
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: VS. Duck Hunt zapper not responding properly

Post by Dwedit »

Or maybe the mapper DLLs got overwritten with DLLs from another emulator. I know that NESten uses the same filenames for mappers.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
User avatar
zeroone
Posts: 939
Joined: Mon Dec 29, 2014 1:46 pm
Location: New York, NY
Contact:

Re: VS. Duck Hunt zapper not responding properly

Post 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?
2600
Posts: 96
Joined: Tue Aug 07, 2007 10:28 am

Re: VS. Duck Hunt zapper not responding properly

Post by 2600 »

What is your zapper implementation?

Do you have it assigned to the correct port?
User avatar
zeroone
Posts: 939
Joined: Mon Dec 29, 2014 1:46 pm
Location: New York, NY
Contact:

Re: VS. Duck Hunt zapper not responding properly

Post 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.
User avatar
Quietust
Posts: 1918
Joined: Sun Sep 19, 2004 10:59 pm
Contact:

Re: VS. Duck Hunt zapper not responding properly

Post 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.
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.
User avatar
zeroone
Posts: 939
Joined: Mon Dec 29, 2014 1:46 pm
Location: New York, NY
Contact:

Re: VS. Duck Hunt zapper not responding properly

Post 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.
User avatar
zeroone
Posts: 939
Joined: Mon Dec 29, 2014 1:46 pm
Location: New York, NY
Contact:

Re: VS. Duck Hunt zapper not responding properly

Post 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;
	}
}
Post Reply