How do TV-Based Video Game Guns Work?
mark juncosa asks: "It is a mystery to me how Nintendo's Duck Hunt gun works. I have thought about it for a long time and have not been able to come up with any kind of good solution." Come to think of it, I wouldn't mind knowing this one myself. On a guess, I'd say that the system is entirely active and all the work being done by the gun and the TV remaining the display device that it always has been. Am I close? Or completely off base?
It was explained to me like this:
The stuff on the screen flash faster than the eye can pick up, and in a unique patern per section of a grid on a screen. When you pull the trigger, it registers the flash patern of the part of the screen that the gun is aimed at. The gun then sends the info about which section of the screen it "hit" back to the console system, which then reflects said "hit" on the screen.
This explanation made sense to me... I'm sure there's a whitepaper somewhere explaining it much better than I can.
I asked myself(and a friend) the same question about how TV video game guns work.In short neither of us kow, but my suspicision after thinking about it was that perhaps there is some invisible or near invisible pattern os seris of patterns embedded in the images, which the gun can "see" and deduce its position from.
Duck Hunt is actually one of the simpler variations on the theme. The arcade games (Virtua Cop, The Lost World, etc) have a more impressive system. In Duck Hunt, when you pull the trigger, the targets (ducks) are replaced with solid white squares and a black background. (This is assuming you mean the original Duck Hunt and not some more recent release of which I'm unaware.) The gun then acts as a light detector, and the game measures the light input on the gun at that instant and judges whether you hit or not. If the game is particularly clever, it will have a full frame of black before and/or after the frame with the white squares to measure the difference between the two. This reduces the chance of false triggering.
The smarter guns are probably rather more sensitive and well focused. It's possible to detect which part of the screen the gun is pointing at by causing the gun to trigger a latch on a raster beam counter when it reaches a certain light threshold. At the end of frame, read the value out of the raster beam counter register, and that provides your gun coordinates. If the gun is not pointing at the screen, then the register will not have latched, and the value will be some unreasonably high value. Alternatively, if the gun is pointing at some bright object other than the screen, then the latch will trigger immediately, and you will get a zero result in your register.
This second "precise" mode means that you must output a minimum level of light at all points on your screen that you wish to be able to target. If the light output at any point on the screen falls below your trigger threshold, then the register will not be latched when the gun is pointing at that part of the screen, and it will look as though the gun is not pointing at the screen at all.
I suppose I should take a little side-track into television theory here, just in case. Your screen is painted by an electron beam in a left to right and top to bottom manner, like the way English text is written. When the electron beam hits the phosphorous coating inside the glass, the phosphorous glows momentarily, emitting a characteristic spectrum of light (primarily red, green, or blue in the case of a colour monitor). This glow is actually quite brief, and if you saw the light output level of any particular point on the screen expressed as a graph, you'd wonder why the screen doesn't look like it's flashing. A trick of the eye and mind, known as Persistence of Vision, causes the image to look solid. In fact it is not solid, but flashing rapidly and unevenly, and this is what allows a light-sensor to be used to detect your aim. Other display technologies, such as LCD displays, may not be amenable to this kind of technique, depending on whether they use a measurable form of display refreshing.
As a side note, the late lamented Amiga actually had the required hardware to support this behaviour for the purposes of using a light pen, so I'm not making this up entirely. The Amiga also had the necessary raster beam counter register and latching facility, of course, although it only resolved to the equivalent of "lo-res" pixels. I never saw an actual device that utilised this hardware, unfortunately.
proof, n. A demonstration that a conclusion is implied by certain premises and axioms.
Well, first of all, you can see, if you shoot the gun, that the display flashes white squares where possible targets are. I haven't played for ages, maybe I should break out my nintendo. Now, the problem of detecting a hit is simple, based on the white-square-flash. It's a matter of contrasting colors. :)
But that brings up a good point. I was thinking perhaps that the color of light might be used to detect which out of several possible targets was hit. But you have to think about this, they had to make the nintendo/gun to work on the widest range of technologies possible. I don't think they would have gone with the raster-timing method, for the simple reason of LCD screens. I don't know if lcd screens were OUT then, but they had to be thinking about possible technologies for which this wouldn't work.
That brings up another point: You can easily change the colors on your television set. The set can be black/white or color, and especially if it's color, you could make that nice pearly "white" show up as greenish, bluish, or reddish. So it has to be done by contrasting colors.
Ah, idea just occurred. You pull the trigger, the game flashes black, whites out _ONE_ location of an object, blacks that, lights the second, blacks that, etc. All the while reading input from the gun. If the gun can detect simple contrasting colors, this'll work. Furthermore, the chances of shooting at a light and hitting it at the right instant (think 60 hz bulbs, or different, people) makes it unlikely to register a hit. And if it does? So what. Easy win. D'oh. Play fair, dorks
i'm pretty sure they work like this: you have a gun with a light detector behind a lens that is focused on (ideally) one pixel on the screen. when you pull the trigger the next frame to be shown by the console is a blank white one. the frame is drawn top left to bottom right and takes a well defined amount of time to complete, for each line, and for each frame. the console simply measures the time between the pixel the lens is focused on going from black to white (when the white frame is drawn). this can then be used to calculate where in the drawing process the screen was when the detector in the gun picked up the frame being drawn. e.g. if it takes 64us to draw a line and white is picked up by the gun after 160us then the tv was half way through drawing the third line down (2x64us + 32us). this is why the screen flashes white every time you pull the trigger! i know my timings may be a little off (not including blanking and flyback) but they should give you an idea..?
Actually, it seems I already had my nintendo out to play dr. mario, you know, when you get nostalgic for the old 8bit days ;) So, I dug up my gun and gave it a try. I saw that yes, the white squares do flash. I tried fiddling with my controls to no avail, I can't confuse it. I guess my tv set's not fancy enough ;) And by the way, you CAN select which game you want with the first-player controller and your gun in the second controller slot. So it's not calibrating. ;)
I couldn't fool it with average incandescent lights (and by the way, I was wrong, incandescents are the ones that don't blink, fluorescents do, but I imagine it has to do with the color.)
So, I set out to scientifically (?) test the theory that it flashes each target in succession. I figured that if I blinked fast enough, I could catch it when just one was lit and the other wasn't, and that would prove my theory that the target hit is decided by lighting each seperately. If I _COULDN'T_ see only one square, though, that wouldn't mean I was wrong, it would mean I hadn't proven the hypothesis.
It took several tries, but I _DID_ manage to have my eyes open at one point just long enough to see only one square. Only once, mind you, but I think that that, coupled with the fact that this is the simplest and "most portable" solution, means I'm probably right. Ideas? How many of you are going to go try this now?
In a normal tv-screen there is an electron beam sweeping the screen starting from the top left corner progressing to the right and after reaching the end of the line moving down to the next one. On a normal tv-screen this is done for every line on the screen exactly 50 times / second(60 if you live in us).
Now, when the electron beam hits the phosphorous coating on the screen it flashes briefly. Having this done 50(60) times per second creates an illusion of a continuosly lighted surface.
It is these brief flashes that your gun tracks and dutifully reports to the computer. Computer, responsible for drawing the picture, is always aware of the pixel it is currently drawing(at least most of the video game hardware is built with this feature) and can extract the location the electron beam is pointing when it receives a signal from the gun. And if you happen to be pressing the trigger then maybe something should happen at that location.
This technology is rather limited though. For instance, it doesn't work on lcd's (maybe by varying the intensity of pixels thus simulating the effect of the electron beam lighting up individual pixels, don't know of anyone actually trying this though). I can also imagine this thing having a hard time with 100hz tv's that are getting more popular in europe. Then again, how many of us actually use a cheapo game console on a tv that doesn't comply to the normal requirements.
For what is is worth, my brother and I used to cheat at Duck Hunt by taping the game, then hooking up another monitor and playing the tape back until we found where we had shot. Using freeze frame, you could then play the game on the original monitor and hit everytime.
It has been a long time, but I seem to remember that when you shot, the screen would go black and the ducks would show up as white blocks. Anyone with a Nintendo, a VCR, and too much time on their hands could easily verify this...
I know I could get the gun x,y, but I had to flash the whole screen white, then call this code. There was also some variation between samples. (about 5 pixels in both axis)
I think the code did some stuff with the vertical retrace flag. I also believe the code did the vertical by counting from the vertical retrace, and the hardware did the horizontal, maybe with a phased locked loop watching the raster. If I still had all that stuff, I'd get a hardware dude at work to analyse it with a cro etc.
BTW It was a Sega 'light phaser' with some custom box the game company (diecom) made. A very cool looking gun!
Comment removed based on user account deletion