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 VGA 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.
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.
he 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.
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.