It is currently Tue Nov 21, 2017 10:44 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Thu Jun 02, 2016 3:27 pm 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 729
Location: New York, NY
The unlicensed game Lethal Weapon (Ch) [U][!].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) [U][!].unf actually looks like a really awesome Zapper game worth supporting.


Top
 Profile  
 
PostPosted: Thu Jun 02, 2016 3:37 pm 
Offline
User avatar

Joined: Sun Sep 19, 2004 9:28 pm
Posts: 3192
Location: Mountain View, CA, USA
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))?


Top
 Profile  
 
PostPosted: Thu Jun 02, 2016 4:03 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5825
Location: Canada
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.


Top
 Profile  
 
PostPosted: Thu Jun 02, 2016 4:36 pm 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 729
Location: New York, NY
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.


Top
 Profile  
 
PostPosted: Thu Jun 02, 2016 4:50 pm 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6447
Location: UK (temporarily)
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:
+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.

Top
 Profile  
 
PostPosted: Thu Jun 02, 2016 4:53 pm 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 729
Location: New York, NY
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.


Top
 Profile  
 
PostPosted: Thu Jun 02, 2016 5:42 pm 
Offline
User avatar

Joined: Sun Sep 19, 2004 10:59 pm
Posts: 1392
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.


Top
 Profile  
 
PostPosted: Thu Jun 02, 2016 5:50 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5825
Location: Canada
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.

Top
 Profile  
 
PostPosted: Thu Jun 02, 2016 5:51 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5825
Location: Canada
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).


Top
 Profile  
 
PostPosted: Thu Jun 02, 2016 6:11 pm 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6447
Location: UK (temporarily)
Out of curiosity, zeroone, how does your implementation behave with tepples's Zap Ruder characterization tests?


Top
 Profile  
 
PostPosted: Thu Jun 02, 2016 6:12 pm 
Offline
User avatar

Joined: Sun Sep 19, 2004 10:59 pm
Posts: 1392
I just looked at the Zapper article on the wiki, and it states it fairly well:
Quote:
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.


Top
 Profile  
 
PostPosted: Thu Jun 02, 2016 6:40 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5825
Location: Canada
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.


Top
 Profile  
 
PostPosted: Thu Jun 02, 2016 7:47 pm 
Offline
User avatar

Joined: Sun Sep 19, 2004 10:59 pm
Posts: 1392
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.


Top
 Profile  
 
PostPosted: Thu Jun 02, 2016 8:26 pm 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6447
Location: UK (temporarily)
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?


Top
 Profile  
 
PostPosted: Thu Jun 02, 2016 8:32 pm 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 729
Location: New York, NY
I discovered something important about the problem with Lethal Weapon (Ch) [U][!].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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group