Lethal Weapon (Ch) [U][!].unf zapper support

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:

Lethal Weapon (Ch) [U][!].unf zapper support

Post by zeroone »

The unlicensed game Lethal Weapon (Ch) [!].unf works in FCEUX and Nestopia; however, the Zapper support only works accurately in FCEUX. Both react to the Zapper trigger. But, Nestopia seems to register the hits only 20% of the time.

Since there is no wiki page on mapper UNL-TF1201, I used the FCEUX source as a guide to add a mapper to my emulator. Interestingly, the result behaves likes Nestopia. This suggests that the Zapper implementation in FCEUX is different from the wiki description. Anyone have any idea on how I can improve my Zapper implementation to enable this game to function? Lethal Weapon (Ch) [!].unf actually looks like a really awesome Zapper game worth supporting.
User avatar
koitsu
Posts: 4201
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: Lethal Weapon (Ch) [U][!].unf zapper support

Post by koitsu »

Random Q: do other zapper-based games work fine for you (ex. Bayou Billy, Duck Hunt, Freedom Force, Operation Wolf (I intentionally picked games from 4 different companies))?
User avatar
rainwarrior
Posts: 8735
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Lethal Weapon (Ch) [U][!].unf zapper support

Post by rainwarrior »

Just curious, how do you implement the trigger bit? Do you fill it with the state of the mouse button, or do you make it turn off a few frames after a click?

The real zapper trigger generates a trigger-on signal only for a few frames after you pull it, doesn't matter how long you hold it down. There's also a lot of noise/bounce on this action so you might get spurious trigger-off frames in the middle; many games have some sort of software de-bounce filter to deal with this, which might interact poorly with your implementation, depending on how you did it.

FCEUX doesn't track the position of the mouse except when you click the mouse for some reason, which is kind of a poor way to do it (I have no idea why it isn't tracking all the time), but games in general don't try to read the light sensor except in response to a zap anyway.
User avatar
zeroone
Posts: 939
Joined: Mon Dec 29, 2014 1:46 pm
Location: New York, NY
Contact:

Re: Lethal Weapon (Ch) [U][!].unf zapper support

Post by zeroone »

koitsu wrote:Random Q: do other zapper-based games work fine for you (ex. Bayou Billy, Duck Hunt, Freedom Force, Operation Wolf (I intentionally picked games from 4 different companies))?
Yes. Thanks for the suggestion and I just tested those games to confirm. I can hit those targets with the click of a mouse.
rainwarrior wrote:Just curious, how do you implement the trigger bit? Do you fill it with the state of the mouse button, or do you make it turn off a few frames after a click?

The real zapper trigger generates a trigger-on signal only for a few frames after you pull it, doesn't matter how long you hold it down. There's also a lot of noise/bounce on this action so you might get spurious trigger-off frames in the middle; many games have some sort of software de-bounce filter to deal with this, which might interact poorly with your implementation, depending on how you did it.

FCEUX doesn't track the position of the mouse except when you click the mouse for some reason, which is kind of a poor way to do it (I have no idea why it isn't tracking all the time), but games in general don't try to read the light sensor except in response to a zap anyway.
For NTSC, my emulator keeps the sensor active for 26 scanlines and the trigger is active for 6 frames regardless of how long the mouse button is held.

I experimenting with those values, but it did not seem to have a significant effect. FCEUX appears to be doing something special.
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: Lethal Weapon (Ch) [U][!].unf zapper support

Post by lidnariq »

rainwarrior wrote:There's also a lot of noise/bounce on this action so you might get spurious trigger-off frames in the middle
There should be no contact bounce in the zapper.

Obviously, I can't speak to clones, but the first-party Zapper has the following circuit for the trigger:

Code: Select all

+5V -- 10kΩ -+      
             |      
401X.4 ------+-//--+---+
                   |   |
                 10µF  trigger
                   |   |
Gnd -----------//--+---+
The on resistance of the trigger switch is more or less 0; when triggered it basically discharges the capacitor entirely and immediately.

The 10kΩ resistor inside the console, combined with the 10µF capacitor inside the zapper, makes a time constant of 0.1 seconds; the properties of the 74'368 in the console(¹) mean that once the trigger has been released it should then take somewhere around one time constant after the trigger has been released to read as +5V (i.e. 0, '368 is inverting), or approximately 6 frames on NTSC decks.


¹: Phillips 74HC family VIL = 30-47% of Vdd @ Vdd = 4.5-6V ; VIH = 53%-70% of Vdd @ Vdd = 4.5-6V ; one time constant ≔ 63%
Last edited by lidnariq on Thu Jun 02, 2016 4:53 pm, edited 1 time in total.
User avatar
zeroone
Posts: 939
Joined: Mon Dec 29, 2014 1:46 pm
Location: New York, NY
Contact:

Re: Lethal Weapon (Ch) [U][!].unf zapper support

Post by zeroone »

lidnariq wrote:The on resistance of the trigger switch is more or less 0; when triggered it basically discharges the capacitor entirely and immediately.

The 10kΩ resistor inside the console, combined with the 10µF capacitor inside the zapper, makes a time constant of 0.1 seconds; the properties of the 74'368 in the console(¹) mean that once the trigger has been released it should then take somewhere around one time constant after the trigger has been released to read as +5V (i.e. 0, '368 is inverting), or approximately 6 frames on NTSC decks.
That's exactly what my emulator does and it ends up behaving like Nestopia instead of FCEUX.
User avatar
Quietust
Posts: 1920
Joined: Sun Sep 19, 2004 10:59 pm
Contact:

Re: Lethal Weapon (Ch) [U][!].unf zapper support

Post by Quietust »

rainwarrior wrote:The real zapper trigger generates a trigger-on signal only for a few frames after you pull it, doesn't matter how long you hold it down.
No it doesn't - I have a real Zapper (one of the orange ones), and if you pull the trigger slowly until it makes a soft click it sends trigger-on as long as you hold it there, but if you pull it the rest of the way it will click much more loudly and clear the trigger signal. It's sort of like a double-action revolver, where the trigger-on signal corresponds to the hammer being pulled back all the way.
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.
User avatar
rainwarrior
Posts: 8735
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Lethal Weapon (Ch) [U][!].unf zapper support

Post by rainwarrior »

lidnariq wrote:
rainwarrior wrote:There's also a lot of noise/bounce on this action so you might get spurious trigger-off frames in the middle
There should be no contact bounce in the zapper.
Maybe "bounce" is an incorrect way to describe it, but I think the problem is seen on the leading edge of engagement if you pull the trigger slowly, or wiggle on the point of engagement.

Maybe the blips are 6 frames, my testing wasn't rigorous. I could write a ROM to measure it better...

(This was seen with an original orange Nintendo zapper, I don't have a clone.)
Last edited by rainwarrior on Thu Jun 02, 2016 5:58 pm, edited 1 time in total.
User avatar
rainwarrior
Posts: 8735
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Lethal Weapon (Ch) [U][!].unf zapper support

Post by rainwarrior »

Quietust wrote:
rainwarrior wrote:The real zapper trigger generates a trigger-on signal only for a few frames after you pull it, doesn't matter how long you hold it down.
No it doesn't - I have a real Zapper (one of the orange ones), and if you pull the trigger slowly until it makes a soft click it sends trigger-on as long as you hold it there, but if you pull it the rest of the way it will click much more loudly and clear the trigger signal. It's sort of like a double-action revolver, where the trigger-on signal corresponds to the hammer being pulled back all the way.
Yeah, that's a better description. I was just trying to describe the typical case of a complete pull (the kind that FCEUX is emulating).
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: Lethal Weapon (Ch) [U][!].unf zapper support

Post by lidnariq »

Out of curiosity, zeroone, how does your implementation behave with tepples's Zap Ruder characterization tests?
User avatar
Quietust
Posts: 1920
Joined: Sun Sep 19, 2004 10:59 pm
Contact:

Re: Lethal Weapon (Ch) [U][!].unf zapper support

Post by Quietust »

I just looked at the Zapper article on the wiki, and it states it fairly well:
The official Zapper's trigger returns "pulled" while it is halfway in, and "not pulled" once it has been pulled all the way to where it goes clunk. The large capacitor (10µF) inside the Zapper when combined with the 10kΩ pullup inside the console means that it will take approximately 100ms to change to "released" after the trigger has been fully pulled.
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.
User avatar
rainwarrior
Posts: 8735
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Lethal Weapon (Ch) [U][!].unf zapper support

Post by rainwarrior »

Okay, after running a test, here's what I see happening when measuring the trigger once per frame:

1. Fast pull and hold: 3 or 4 frames of trigger. I can't produce a burst of 1s shorter than this, and they do seem to be "clean".

2. Pulling slowly, there's a little "click" point that when I reach it produces usually 1 to 3 frames of trigger when I reach it, then goes back to 0s. I can wiggle on this point to produce many short bursts of 1s.

3. Pulling a little farther, there's a point where the trigger goes full on (no click) and you can hold it there as long as you like.

4. Moving from the "hold" position, to the final BANG is clean.


Basically with slow pulls I get noise, due to that transition area between the initial small click and the point where it just holds. Particularly with loose/slower pulls I might get a frame or two of 0s in the middle of a block of 1s. If I play with the early click point I can produce single frame 1s too.


I don't know if my zapper is defective or different in some way from other zappers, but I don't have any others here to test at the moment. It's an original Nintendo orange zapper, says 1985 on the side. (Anybody could use the test ROM I linked above though.)

I analizyed Duck Hunt's trigger code a while back, and it was definitely doing software filtering to reject noise like this (but the specifics are a bit hazy at the moment; I seem to recall it waits at least 5 frames before allowing a new trigger), so it makes sense to me that this might be typical/expected behaviour.
User avatar
Quietust
Posts: 1920
Joined: Sun Sep 19, 2004 10:59 pm
Contact:

Re: Lethal Weapon (Ch) [U][!].unf zapper support

Post by Quietust »

Just tried out that test ROM with my own (orange 1985) Zapper, and your above described points 2 and 3 are extremely close together, to the point that getting the short noisy bursts is nearly impossible - for the most part, when I hear the click, it switches between constant 0 and constant 1. When I do a fast trigger pull, I get four frames worth of 1s, occasionally five.
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: Lethal Weapon (Ch) [U][!].unf zapper support

Post by lidnariq »

rainwarrior wrote:I don't know if my zapper is defective or different in some way from other zappers, but I don't have any others here to test at the moment.
Hm. So, it is an electrolytic capacitor inside the zapper there, and so probably has a typical Equivalent Series Resistance of somewhere around 10Ω, give or take.

So if you somehow manage to keep your finger right on the near edge of the make/break threshold, and you manage to intentionally/accidentally use muscle tremors to keep it making contact with a 1% duty cycle, you'll manage to keep the voltage across the capacitor in the middle of the relevant range for the 74HC368 to toggle between logic 1 and 0.

But given how much effort this takes, I have to wonder if this:
rainwarrior wrote:I analyzed Duck Hunt's trigger code a while back, and it was definitely doing software filtering to reject noise like this
is because the original famicom zapper could be missing the capacitor altogether?
User avatar
zeroone
Posts: 939
Joined: Mon Dec 29, 2014 1:46 pm
Location: New York, NY
Contact:

Re: Lethal Weapon (Ch) [U][!].unf zapper support

Post by zeroone »

I discovered something important about the problem with Lethal Weapon (Ch) [!].unf: The color of the pixel at the mouse coordinates on the frame prior to the white-silhouettes frame determines the response rather than the white-silhouette. In other words, it's reacting too early.

That explains why it hits the target only 20% of the time. It was varying based on the pixel color that I happened to click on.

It'll study this further.
Post Reply