The GunCon controller (known as G-Con 45 in Europe) is a light gun made by Namco for Sony Playstation.
How does it work ?
The GunCon uses cathode ray timing method to detect where the barrel is aimed at on the screen when the trigger is pulled.
Cathode ray timing method
This method relies on how the cathodic ray tube tv monitor works.
The screen is rendered by a scanning electron beam that travels across the screen starting at top-left corner to the right until it hits the right side, then it moves down to update the next line.
This is then repeated until it reaches the bottom-right corner.
This is done very quickly so it appears instantaneous to the human eyes (due to persistence of vision)
When the trigger of the light gun is pulled, a photodiode will sense the change in brightness at the location at which the gun is pointed on the screen.
This change in brightness is due to the beam hitting the phosphore of the screen.
The GunCon use a T-connector on the A/V cable to be able to track HSYNC/VSYNC pulses from the video signal in order to determine the X/Y position aimed at on the screen.
The Y position is determined by counting number of HSYNC pulses received between last VSYNC pulse and the pulse from the photodiode.
The X position is determined by measuring the time between the last HSYNC pulse and the pulse from the photodiode.
Anatomy of a Video Signal (PAL)
- 625 scan lines (576 for display) per frame
- 2 interlaced fields per frame
- 50 fields per second
- 768 pixels per line (square pixel)
Field frequency
50 fields per second = 50 Hz
Field frequency = 50 Hz (20ms per field)
Frame frequency
50 Hz / 2 fields per frame = 25 Hz
Frame frequency = 25 Hz (40ms per field)
Line frequency
50Hz * 625 lines = 15625 Hz
Line frequency = 15.625 KHz (64µs per line)
Horizontal sync time
Front porch = ~1.65µs
HSync pulse = ~4.7µs
Back porch = ~5.7µs
Horizontal sync time = 12.05µs
Horizontal Active video time
64µs - 12.05µs = ~51.95µs
Active video time per line = ~51.95µs
Pixel Clock frequency
768 pixels per line / 51.95µs per line = 14.78 MHz
Pixel clock frequency = 14.78Mhz
X/Y Calculation
After VSYNC (2.5 scan lines) is done the post-equalizing pulses, which lasts for 2.5 scan lines, so the first two scan lines can be ignored.
Then 305 scan lines are used for data.
The last 2.5 lines are used for pre-equalizing.
2.5 + 2.5 + 305 + 2.5 = 312.5 = 625 scan lines / 2 fields per frame
From the 305 data scan lines only 288 are usually used for video data, others are used to hold teletext data for example.
Let's consider the 288 scan lines are fully visible on the screen.
If the center of the screen is aimed, we should have something like:
Number of HSYNC since VSYNC = 2 + (305 - 288) + (288 / 2) = 163
Time since last HSYNC = 52µs / 2 = 26µs
Now we need to calculate a percentage from these values.
X% = 26µs / 52µs = 0.5
Y% = (163 - 17 - 2) / 288 = 0.5
And if we map that to a [0, 640; 0, 480] cartesian plane, it yelds the following coordinates:
X = 640 * 0.5 = 320
Y = 480 * 0.5 = 240