How light pen and light gun works
When the photocell senses the "beam" scanning across the face of the screen, a signal is sent to the CRT controller (chip) which causes it to record the current X,Y position of the video signal that *it* is generating. Depending on sophistication desired, the software can capture the limits of this "region" (i.e. which scan lines register a "hit" and which positions on each scan line) and then determine the "center" of that region.
On your typical tv set the electron gun (in the CRT) scans across the screen (phospor) one line at a time. It starts at the upper left corner of the screen then draws going to the right. When it gets to the right the electron gun turns off goes down one line and turns on and draws the next line. It does this until it gets to the bottom of the screen. Where it goes back to the top and starts over again. These are called raster lines.
Well when the electron beam hits the phosphor it glows brightly and slowly dims until it is struck again by the electron beam. Our eyes don't really notice this bright and dimming because they do not refresh that fast. You can see the bright/dim effect if you record the picture on the tv with a camcorder. Since the TV and the Camcorder refresh at about the same frequency you will see a bright group of lines that roll up the screen.
Since the Video Chip in the computer has to create the video signal it knows where it is currently drawing the curent raster line. The light pen when pointed to the screen detects this bright/dim effect and when the light goes from dim to bright it sends a signal pulse to the video chip. The video chip sets a latch which feeds 2 numbers, usually X location, Y location, into a memory location associated with the video card/chip. The computer program then looks at the numbers in the memory location. And can tell where the light pen is pointed on the screen by the two numbers.
Some light pens are more sensitive than others. They are usually just a Photo receptor cell with a pinpoint lens and a schmitt-trigger flip flop chip.
Some video cards had light pen plugins on them. For example CGA and EGA cards had a light pen connector in them with following pinout:
1 Light Pen Input [-] 2 no pin 3 Light Pen Switch [-] 4 +5V output 5 +12V output
I have not seen or heard of one on a VGA or higher video card. Not a high demand item, but there are probably ones out there.
The sensitivity of the nintendo gun is probably to low/slow to work at the higher scan rates of the tipical computer monitor. TV scan rates are pretty slow compaired to the computer ones. So if you find a video card that has the light pen plugin you will probably have to use their light pen.
Circuit inside the light pen
Here is a typical basic circuit inside light pens:
+5V | | resistor | +----->schmitt------->to display controller | trigger | photodiode | | groundThis circuit generates a pulse when the electron beam hits the pixels under the photodiode light detector. The electronics inside the graphics card display contoller then latches the current values in the X and Y conter to the light pen registers (those registers were in PC CGA and EGA cards nut not in modern VGA cards).
The button in light pen is just a button wired between the button input and ground.
How does phosphor persistence affect light pen operation
The persistance of the phosphor is overcome by its fast attack characteristic which gives a useful response. Back in the 60's and 70's many computer terminals used light pens, and they used just this principle. You can check it out for yourself by holding a biased photodiode up to a TV screen and observing its output on an oscilloscope.
Simple light gun scheme used in first video games
Most modern video game light pens work in the same way as the light pen. The only exception is that the gun is some distance away from the screen and the optics inside light pen make sure that the photodetector "sees" only a small part of the video screen.
On old games where all you need is a simple 'hit/miss' indication, some of the video games really cut the corners. Sometimes you can see that during the bright flash, the target areas go completely dark. Dark isn't totally dark, they probably get some output. However, I would guess that it would be a lot easier to tell the difference between bright and dark decay curves than it is monitor every line, pixel by pixel.
Light guns and modern PCs
Many people have asked in many forums is is possible to convert old video game light pen or light gun to a PC. Quite propably this is possible if you put enough electronics and effort on the project. I don't have any plans for this.
Most often the light gun is consructed in such way that is it just a simple light detector that detects the light going to position the gun is pointing at. On your typical tv set the electron gun (in the CRT) scans across the screen (phospor) one line at a time. It starts at the upper left corner of the screen then draws going to the right. When it gets to the right the electron gun turns off goes down one line and turns on and draws the next line. Well when the electron beam hits the phosphor it glows brightly and slowly dims until it is struck again by the electron beam.
The video chip in the video game knows where it is currently drawing the curent raster line. The light pen when pointed to the screen detects this bright/dim effect and when the light goes from dim to bright it sends a signal pulse to the video chip. The video chip sets a latch which feeds 2 numbers, usually X location, Y location, into a memory location associated with the video card/chip. The computer program then looks at the numbers in the memory location. And can tell where the light pen is pointed on the screen by the two numbers. This is how this idea is implemented in most video gme hardware.
PC graphics cards once (CGA and EGA cards etc..) used to have connector for attaching a light pen or light gun. It worked in the way above. This feature was very rearely used. With the introduction of the VGA card, this connector and functionality has been removed from the graphics cards, because it was not needed.
So adding a light gun to a modern PC get much harder, because the graphics card does not have the necessary hardware built into it. If you want to get the location information from light pen signal, some special external hardware that connects to light pen and graphics card connector needs to be added. The hardware can measure the Y position by counting the number of HSYNC pulses between last VSYNC pulse and the pulse from the light pen sensor. For X-position the time from las HSYNC pulse to light gun pulse needs to be measure accurately (counting the number of pixel clock pulses from grahics card is the idea, but generally you can't get the pixel clock out of PC graphics card through the standard connectors in them, so other tricks needs to be used)
Maybe constructing this technology today does not make much sense. The reason is that there is a huge work ro build this kind of thing and the time it is usable is pretty limited. Light gun can only work on CRT monitors (and maybe some CRT video projectors). Light gun technology does not work with LCD flat nale displays that are quicly becoming more and more popular on PC systems.