Understanding how the Zapper works
Moderator: Moderators
-
- Posts: 6
- Joined: Wed Dec 15, 2021 1:13 pm
Understanding how the Zapper works
I was looking at the wiki page for the zapper and had some questions. Using a Tomee Light Gun I noticed that is only does light detection when the trigger is pulled. Is this how the original nes gun works?
For your standard game logic, how does the actual timing work? My current understand is something like this:
1) I pull the trigger
2) It goes dark for 1 full frame (so 33.3 ms?)
3) The next frame it flashes a white detection square (this varies by game it could be the whole screen going white)
4) If there is a second detection box (i.e. a second duck in duck hunt) it flashes that the 3rd frame after the trigger detection is detected
5) some games do a 4 frame fade out where the hit box is first full white, then 3 following frames of increasingly dark hit detection.
6) The capacitor of the light gun is charged on trigger pull and drains through the light detection circuit. This effectively creates a 100ms detection time period which would be just enough for 3 frames of detection.
Am I on the right path here?
For your standard game logic, how does the actual timing work? My current understand is something like this:
1) I pull the trigger
2) It goes dark for 1 full frame (so 33.3 ms?)
3) The next frame it flashes a white detection square (this varies by game it could be the whole screen going white)
4) If there is a second detection box (i.e. a second duck in duck hunt) it flashes that the 3rd frame after the trigger detection is detected
5) some games do a 4 frame fade out where the hit box is first full white, then 3 following frames of increasingly dark hit detection.
6) The capacitor of the light gun is charged on trigger pull and drains through the light detection circuit. This effectively creates a 100ms detection time period which would be just enough for 3 frames of detection.
Am I on the right path here?
Re: Understanding how the Zapper works
The original zapper always knows whether it's pointing at the screen - it reports if it sees light at the exact moment you ask it, so it's continuously alternating between "I don't currently see the electron beam in the CRT" and "I do see it".
Tepples wrote several demonstrations that take advantage of this: https://github.com/pinobatch/zap-ruder
Tepples wrote several demonstrations that take advantage of this: https://github.com/pinobatch/zap-ruder
-
- Posts: 6
- Joined: Wed Dec 15, 2021 1:13 pm
Re: Understanding how the Zapper works
Interesting, I'll try and build it to see if I'm actually reading the Tomee light gun correctly, or if I've got something wonky going on. I suspect that the fact this only detects light when the trigger is pulled is a deliberate choice. It's a "modern" light gun and they tried to make it compatible with LCDs, which it works in detecting light from an LCD, yes, but there's still the timing issue obviously.lidnariq wrote: ↑Wed Dec 15, 2021 3:49 pm The original zapper always knows whether it's pointing at the screen - it reports if it sees light at the exact moment you ask it, so it's continuously alternating between "I don't currently see the electron beam in the CRT" and "I do see it".
Tepples wrote several demonstrations that take advantage of this: https://github.com/pinobatch/zap-ruder
Re: Understanding how the Zapper works
Minor nitpick: the NTSC NES runs at 60 frames per second, so one frame is only 16.67ms, so a typical "trigger pull" event with two targets would only take 50ms total.
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.
P.S. If you don't get this note, let me know and I'll write you another.
-
- Posts: 6
- Joined: Wed Dec 15, 2021 1:13 pm
Re: Understanding how the Zapper works
oh, of course! It's interlaced, one frame = half the scan lines, 2 frames = one full picture. Thanks for that catch. What about PAL? is that 54 Hz?
Re: Understanding how the Zapper works
Almost nothing about early video game consoles is interlaced, and modern TVs deinterlacing their outputs results in icky "weave" artifacts.
NES, almost all SNES, almost all Genesis, SMS, almost all TG16, most N64 games, many PS1 games are all just 240p60Hz.
PAL consoles from the same era are similarly all "just" 288p50Hz.
NES, almost all SNES, almost all Genesis, SMS, almost all TG16, most N64 games, many PS1 games are all just 240p60Hz.
PAL consoles from the same era are similarly all "just" 288p50Hz.
- rainwarrior
- Posts: 8732
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: Understanding how the Zapper works
In my tests with that Gun, I found that the light detection is reported for about 1/2 a second from onset. It has nothing to do with the trigger, and I think it just has a highpass filter so that it looks for a sudden brightening to report. (i.e. trying to filter out the ambient light level of the room.)lifewithmatthew wrote: ↑Wed Dec 15, 2021 2:52 pmI was looking at the wiki page for the zapper and had some questions. Using a Tomee Light Gun I noticed that is only does light detection when the trigger is pulled. Is this how the original nes gun works?
Here's some test ROMs I wrote to help myself see what zapper hardware was doing:
zapper test ROMs
-
- Posts: 6
- Joined: Wed Dec 15, 2021 1:13 pm
Re: Understanding how the Zapper works
I did notice an odd delay between the trigger pull and the interrupt being triggered in my testing, I thought it was a delay in my computer but it being on the hardware side does make some sense. As for the sequence I wrote out in the first post, do you know if that is accurate?rainwarrior wrote: ↑Wed Dec 15, 2021 8:19 pmIn my tests with that Gun, I found that the light detection is reported for about 1/2 a second from onset. It has nothing to do with the trigger, and I think it just has a highpass filter so that it looks for a sudden brightening to report. (i.e. trying to filter out the ambient light level of the room.)lifewithmatthew wrote: ↑Wed Dec 15, 2021 2:52 pmI was looking at the wiki page for the zapper and had some questions. Using a Tomee Light Gun I noticed that is only does light detection when the trigger is pulled. Is this how the original nes gun works?
Here's some test ROMs I wrote to help myself see what zapper hardware was doing:
zapper test ROMs
- rainwarrior
- Posts: 8732
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: Understanding how the Zapper works
Your first post seemed to be describing functions of the games, not the gun. The gun is a little simpler:
Light report
The gun reports a 1 if it sees brightness (over some signal threshold), 0 if not.
For the original gun, the brightness input has a high frequency highpass filter (somewhere around the ~15khz CRT scanline frequency), so it only "sees" brightness if it rapidly changes from dark to light at high frequencies.
For the tomee gun, the highpass filter is much, much lower frequency (~0.5hz?), so it will see not just fast changes, but also much slower ones (e.g. 30 or 60hz LCD framerate). The highpass makes it so that it eventually considers whatever you're pointing at as "dark" so that it can adjust to whatever room you're in. This means pointing it at solid brightness will only signal for a short period of time (<1 second?).
This is different than the original gun which will signal on and off more instantaneously as the scanlines pass by, but also won't respond to things that aren't a CRT or otherwise high frequency change (e.g. CF bulbs, or a momentary switch-on of an LED).
Light is reported at all times, not just when the trigger is held.
Trigger report
The original gun reports the trigger when held to a certain threshold (you can feel an engagement click) and then when pulled in all the way it releases with a loud BANG and the trigger won't report again until you release it and pull again. The actual signal this generates is "noisy" with a lot of potential for bounce, so games seem to do something to ignore the trigger for a few frames after it first signals, so that it doesn't rapid-fire by accident.
The tomee gun reports the trigger continuously when held, and then off when released. Very simple switch.
Light report
The gun reports a 1 if it sees brightness (over some signal threshold), 0 if not.
For the original gun, the brightness input has a high frequency highpass filter (somewhere around the ~15khz CRT scanline frequency), so it only "sees" brightness if it rapidly changes from dark to light at high frequencies.
For the tomee gun, the highpass filter is much, much lower frequency (~0.5hz?), so it will see not just fast changes, but also much slower ones (e.g. 30 or 60hz LCD framerate). The highpass makes it so that it eventually considers whatever you're pointing at as "dark" so that it can adjust to whatever room you're in. This means pointing it at solid brightness will only signal for a short period of time (<1 second?).
This is different than the original gun which will signal on and off more instantaneously as the scanlines pass by, but also won't respond to things that aren't a CRT or otherwise high frequency change (e.g. CF bulbs, or a momentary switch-on of an LED).
Light is reported at all times, not just when the trigger is held.
Trigger report
The original gun reports the trigger when held to a certain threshold (you can feel an engagement click) and then when pulled in all the way it releases with a loud BANG and the trigger won't report again until you release it and pull again. The actual signal this generates is "noisy" with a lot of potential for bounce, so games seem to do something to ignore the trigger for a few frames after it first signals, so that it doesn't rapid-fire by accident.
The tomee gun reports the trigger continuously when held, and then off when released. Very simple switch.
-
- Posts: 6
- Joined: Wed Dec 15, 2021 1:13 pm
Re: Understanding how the Zapper works
Is that an accurate description of how the games function? Also thank you for the explanation of the hardware, that's very helpful!rainwarrior wrote: ↑Thu Dec 16, 2021 5:29 pm Your first post seemed to be describing functions of the games, not the gun. The gun is a little simpler:
- rainwarrior
- Posts: 8732
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: Understanding how the Zapper works
It's been years since I looked at it, but I remember Duck Hunt doing something like this:
- 0. Trigger signal from gun.
- 1. One frame of black. Polls light sensor for the whole frame to make sure it reads as dark the whole time. If it reads light during this frame, it assumes it's not pointed at the TV.
- 2. One frame for each duck target rectangle. Polls light sensor for the whole frame, if any light is detected during this frame, it counts as a hit.
- 3. A few frames of ignoring the trigger.
-
- Posts: 1510
- Joined: Thu May 19, 2005 11:30 am
Re: Understanding how the Zapper works
Duck Hunt's Zapper reading code is easy. Operation Wolf's on the other hand is difficult.
Re: Understanding how the Zapper works
Fun fact, the Famicom Kousenjuu gun works like a double-action revolver and the hammer is pulled back when the trigger is pulled until this certain threshold (the engagement click on the Zapper) when the hammer is suddenly released and the falling edge of the trigger happens (which most games registers as a shot).rainwarrior wrote: ↑Thu Dec 16, 2021 5:29 pm The original gun reports the trigger when held to a certain threshold (you can feel an engagement click) and then when pulled in all the way it releases with a loud BANG and the trigger won't report again until you release it and pull again.
The Bandai Hyper Shot however does not seem to work like this but works more like a simple pushbutton. Space Shadow, the one game using this gun, uses full automatic fire so there is no need for this engagement click and release mechanism. I guess this means if you use it in another Zapper game, the shot won't happen until you release the trigger and it therefore works poorly for any other game than Space Shadow.
-
- Posts: 6
- Joined: Wed Dec 15, 2021 1:13 pm
Re: Understanding how the Zapper works
By any chance is there an FDS version of the zapper testing program? I have an FDS stick I could load an FDS rom onto or a UROM cart I could flash a UROM mapped game, but I noticed that the zapper program used NROM.
Re: Understanding how the Zapper works
I don't have an FDS on which to test. What I do have is a PowerPak that takes UNROM, and it's fairly straightforward to hack Zap Ruder or any other NROM-128 or NROM-256 game to use UNROM. I also have 240p Test Suite, which contains a subset of the Zapper test and is built for UNROM.