CGA: Reading the current beam position with the lightpen latch

Here is a little known trick that a genuine IBM Color Graphics Adapter can play, that I noticed when looking at its schematic recently. There are two ports (0x3db and 0x3dc) which are related to the light pen. A read to or write from 0x3db clears the light pen strobe (which you need to do after reading the light pen position so that you'll be able to read a different position next time). A read to or write from 0x3dc sets the light pen strobe - what's the point of that? One possibility might be to implement a light pen that signals the computer in a different way (via an interrupt) rather than being connected directly to the CGA card. That wouldn't work very well though - the interrupt latency of the original IBM PCs was extremely high.

Another possibility is to allow the programmer to directly find the position of the beam at any moment, to an accuracy of 2 scanlines (in graphics modes) and one character width (1/40th of the visible screen width in graphics modes and 40-column text modes, 1/80th of the visible screen width in 80-column text modes). Read from 0x3db and 0x3dc and then read the light pen CRTC registers to find out where the beam was when you read from 0x3dc. This technique is so obscure it probably won't work on non-IBM CGA cards, so its usefulness is rather limited. Might be useful for an oldskool demo, though. I'll be sure to implement this technique when I finally get around to making my extremely accurate PC emulator.

3 Responses to “CGA: Reading the current beam position with the lightpen latch”

  1. Jim Leonard says:

    Here's the rub: Try to find a lightpen. They were rare even when they were new! And I'd almost be afraid to use one with my decent 5153 monitor because I'd be afraid of scratches. I have other monitors, I suppose... but no lightpen, and I've been trying to find one for two decades.

  2. […] CGA has none of this. There is the lightpen functionality, which could be used… but because of the ‘hack’ with even/odd scanlines, it does […]

Leave a Reply