Light pen

From C64-Wiki
(Redirected from light pen)
Jump to navigationJump to 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.


Companies[edit | edit source]

Circuit diagram

The following companies produced light pens:

  • REX 9631/9520
  • Conrad
  • Lindy
  • Cardco, Inc (VIC-20, C64)
  • Futurehouse (Edumate Lightpen)
  • Amicron Ltd. (Microscirbe Lightpen)
  • Madison Computer (McPen Lightpen)
  • Koala Soft
  • Pixsticks
  • Inkwell Systems
  • Turbo
  • Tech Sketch Inc
  • Pen-Datel
  • Stack 100, Stack Computer Services Ltd.
  • Trojan C64/128/16/116, Plus/4


Software[edit | edit source]

Paint'n'Sketch

This software supports light pens:

  • GEOS has got a driver for the light pen for using the graphic programs GeoPaint and GeoCanvas.
  • CAD-Master (Trojan) for C64/128/16/116 and Plus/4
  • FlexiDraw 5.0/5.5 (Inkwell Systems)
  • Koala Soft: Koala Painter
  • Paintbox Package (Stack) for these games Crossword Twister, Seek and Destroy, Draughts, Concentration, Simon, Othello, Go-Go, Shuffler, Life, Lost in the Labrynth
  • Penmaster Art Package (Trojan) for C64/128
  • Picasso's Revenge (1986) from Progressive Peripherals & Software (USA); Box inlusive Lightpen.
  • BASIC programs like Cardriter 1 (Cardco, Inc, 1983) for VIC-20 and C64: Introduction to the Light Pen, Pen Map, Fun With Numbers, Computer Literacy Quiz, Tic-Tac-Toe, Mailing List

Easy to build, but rarely supported[edit | edit source]

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 its 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 from 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 nearby brighter spot on the screen instead.

These limitations 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.

Since light pens work by detecting the scanning of the CRT image they will not work with LCD monitors.

Programmer's How-To-section[edit | edit source]

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 occurring because the light pen caught a screen position.

Address Hex Address Dez Function Descritpion
$D013 53267 X Coordinate about half resolution of the the C64 display in X direction
$D014 53268 Y Coordinate
$D019 53273 Interrupt Requests Bit 3: LPIRQ, IRQ vom Lightpen, 1 = active
$D01A 53274 Interrupt Request Mask Bit 3: MLPI, 1 = Interrupt in $D019 activated

Example:[1]

100 POKE 53280,0: POKE 53281,1
110 L=0: REM WITH L=1 the POINTS WILL NOT DELETED INSTANTLY
120 PRINT CHR$(147)
130 FOR I = 1 TO 5
140 X=X+PEEK(53267)
150 Y=Y+PEEK(53268)
160 NEXT
200 X=INT((X/5-34)/3.8)
210 Y=INT((Y/5-49)/7.8)
300 IF X<0 THEN X=0
310 IF Y<0 THEN Y=0
320 IF Y>24 THEN Y=24
330 IF L=0 THEN POKE P,32
340 P=1024+X+40*Y
350 POKE 54272+P,5:POKE P,160
360 X=0:Y=0
370 GOTO 130

In other BASIC dialects it is easier to programming light pens with BASIC commands.

Dialect: Command:
BASIC 7.0 PEN(0), PEN(1)
Simons' Basic PENX, PENY
Super Expander 64 RPEN()
Supergrafik Programs: LIGHTPEN / LIGHTPEN-IRQ (routine in a German BASIC dialect book of the company Data Becker)

References[edit | edit source]

  1. Manual: Lightpen RTO 9520

Links[edit | edit source]