Diecom light gun in MESS

MESS bug #971 is a feature request for adding a Diecom light gun adaptor emulation to mess. It was committed this morning. Woo, hoo!

But I’d like to take a moment to explain some of the deficiencies of my emulation. As is usual, I only implement enough of the converter box to get the two written games working: Iron Forest and Medieval Madness.

Here is how the games work. When the light gun trigger is pressed, the CoCo clocks the device to state 6 and waits for the start of a video frame. After vertical retrace, all of the palette registers are set to white and the device is clocked to state 7. This starts the 9 bit timer. The 9 bits are timed to roll-over every horizontal refresh. At every horizontal refresh the device is polled to determine if there was a “hit”. A “hit”" is when the gun senses the light of a white pixel on the screen. Further more, when a hit is detected the internal timer is stopped automatically. Clocking the device’s state from 8 to 15 make the nine bits of timer data available to the CoCo. A low timer value says the hit was early in the scan line, a high timer value says the hit was late in the scan line.

Since the CoCo is counting off scan lines it knows the vertical axis of the hit. Since the CoCo reads the nine bit timer value it knows the horizontal axis of the hit. Thus the hit is pin-pointed on the screen.

Let me describe another method of using the device, one which isn’t emulated. This other method is what is used in the Nintendo Entertainments System’s Duck Hunt game. When the gun’s trigger is pressed the screen is blacked out and at the end of the frame, the device is queried for a hit. If there was a hit, then the game player must have been pointing the gun at a bright light source (not the TV) so the game registers a miss. If there was no hit, an object is painted white at the start of the next video frame, then at the end of the frame the device is queried for another hit. This is not emulated because I do not sample the video buffer, looking for a bright light. I score a “hit” whenever the device is sampled and scan line matches the mouse vertical position.

If people start writing new games and they want to use the second method I will add it to the emulation.