TechnoBabble A Light Gun for the c64? by Errol Smith For those who are unfamiliar with the term, a 'light gun' is the same kind of device you see people using at arcades, where they stand back from the screen with a 'gun' in their hand shooting at targets/bad-guys. Similar devices exist for most console machines such as the Playstation and Nintendo64/NES systems. Many moons ago someone gave me a lightgun from an Atari XE games system. At the time I plugged it in to my 64 & tried to get something out of it but to no avail. I assumed the interface was different to that of the 64, so it went in the back of a drawer for a rainy day. Then recently I played Virtua Cop 2 at the arcades, which uses lightguns, and was reminded of the Atari lightgun, thinking it would be cool to have that style of game controller on the 64, so I set about seeing how it worked and if it could be used with the commodore. After some checking of the wiring, I found that it was wired similarly to a normal c64 lightpen, and that the wires in the cord were frayed which explained why it didn't work. After repairing the cord, writing a small test program, and connecting the lightgun, to my suprise it worked! (Picture Homer Simpson going "Woohoo!") I don't personally know of any games for the commodore that made use of of a lightgun as a controller, or even if there was a lightgun available for commodore machines. The game Operation Wolf comes into mind as a perfect candidate though, but it only used joystick or mouse. If any readers know of such games or controllers, they can contact me c/- the editor. This particular lightgun (an 'Atari XG-1') is modelled after some kind of high tech 'laser gun', rather than a revolver or automatic pistol like most of the arcade ones seem to be. On my C= 1802 monitor, it works up to a distance of about a metre (3 feet), with the brightness up high. That was almost dissapointing, but trying it on a large screen tv (68cm/27") was amazing - it would work perfectly at a distance of at least 3 metres (10 feet away), with normal brightness levels. Techy Details: This lightgun uses the lightpen input, which is pin 6 of joystick port 1 on the commodore 64/128. This pin is the 'fire' of a normal joystick, but it is also wired to the lightpen input of the VIC chip. The atari lightgun also has a trigger which is wired to pin 1 of the joystick port (usually 'up'). Lightguns like this one operate on the same principal as a lightpen, except at a distance from the screen rather than up against it. To know how a lightpen works, you have to know a little about how your tv/monitor displays a picture. Images on the screen are made from tiny dots of light which are produced by a beam from an electron gun hitting the phosphor inside the screen, creating light. The beam scans across the screen, from left to right and top to bottom, creating the image. As the VIC chip (in our case) is creating the picture, it 'knows' where the beam is at any instant. The lightpen works by triggering the vic chip when the beam passes it, and the vic chip stores the X and Y location of the beam into a set of registers - $d013 and $d014 (hex) respectively. To do this the lightpen contains a photo-transistor, which is essentially a switch that is triggered by light, and some simple electronics connected to the lightpen input on the joystick port. As a lightgun has to work at a distance from the screen, it also has a lens to 'aim' the phototransistor at a point on the screen. The Atari lightgun has it's electronics permanently connected to the LP input of the computer. This allows the computer to always 'know' where it is pointing. The trigger is wired seperately to pin 1. This would allow for example, a 'gun sight' or crosshairs to always be visible on the screen showing where the light-gun is aimed, and you could fire when the crosshairs were on your target. Implementing this type of control into a game is not difficult. The main problem is that the lightpen does not always give a stable reading. ie. if you held the lightpen or lightgun against the screen dead-still, the position indicated by the VIC will still vary, or 'shake'. An inconvenience with the Atari lightgun for the c64 is that the trigger switch is wired 'backwards' - it is normally connected, and disconnected when the switch is pressed, rather than the reverse. If you've ever left a joystick in port one with it's auto-fire on you'll know this makes the keyboard misbehave - unless the lightgun is unplugged or the trigger is held down!