Light pen

From C64-Wiki

Jump to: navigation, search
Turbo Computer Light pen

A light pen is a pen-shaped input device which connects to a compatible computer (such as the C-64): The device contains a light sensor which, when pointed at a cathode ray tube screen, generates a signal each time the electron beam raster passes by the spot the pen is pointing at. The VIC-II accepts this signal, generates the X and Y coordinates in a pair of registers, and, if desired, causes an interrupt to the CPU every time new coordinates are reported.

[edit] Easy to build, but rarely supported

Light pens are easy for the electronics hobbyist to build from a scrapped ballpen, a phototransistor and some electronics (amplification and Schmitt-trigger): Using a female DB9 allows such a setup to connect directly to, and even draw it's power from, Control port 1 on the 64 (in which the "fire" button line was also connected to the VIC's light pen input).

Similarly, light guns were once available in computer stores etc., which used optics to allow the device to be aimed at on-screen targets frome some distance.

Despite the ease and availability of this technology, it was rarely used, owing mainly to lack of precision. First of all, the X coordinate is "rounded off" to even pixels (or more precisely; the reported X coordinate is an integer representing half of the actual horizontal position). Second, problems with noise, non-ohmic properties of the involved cables etc. causes a lot of "jitter" (several pixels) on the reported X coordinate, even if the pen is held completely still over a specific point on the screen.

The light pen also requires the entire screen image to be quite bright, to ensure a significant "spike" in the amount of light received as the beam passes by the pen's tip. Any dark graphics causes the aiming point to "slip off" the dark areas, catching a neaby brighter spot on the screen instead.

These limitation make the light pen system unsuitable for "precision work", such as drawing things or pointing to menus on the screen, leaving only "non-precision" shooting games as a target application for this technology.

[edit] Programmer's How-To-section

The light pen "system" runs as soon as a correctly adjusted light pen is attached to control port 1; no initialization is required. The VIC registers for light pen coordinates are at 53267-53268:

  • 53267 holds the X coordinate divided by two – in order to obtain the actual X coordinate (a 9-bit figure), one has to multiply by 2, or do an ASL on the byte obtained from this register, to get the actual X coordinate.
  • 53268 holds the Y coordinate.

Notice that the X and Y coordinates follow the same geometry as the coordinates for sprites; thus the very first pixel at the left edge of the text screen would have an X coordinate of 24 on a PAL machine (read as half the value, i.e. 12, from the VIC address).

Bit 3 (weight 8) in the VIC's interrupt register (at 53273/$D019) and interrupt enable register (at 53274/$D01A) is used for interrupts occuring because the light pen caught a screen position.

[edit] Weblinks

Personal tools
Help and Feedback
In other languages