Close

A Software Only CHESSmate

A project log for Commodore CHESSmate Reproduction

The plan is to make a reproduction of the dedicated chess computer CHESSmate released by Commodore in 1978.

michael-gardiMichael Gardi 04/20/2024 at 14:460 Comments

I said I was not going to jump into a software only CHESSmate right away but it turns out I couldn't resist. 

My starting point was a Python based 6502 emulator that I had used for my Challenger 4P project. My decision was based on Python's portability, my current infatuation with Python, and my positive experience with this particular 6502 emulator (solid). 

It turns out that making a software only emulation was more challenging than I thought it would be. With my hardware reproduction, the CHESSmate emulation consisted of observing the CHESSmate program's interaction with the 6530-0024 RRIOT chip (which controlled all the I/O to the 7-Segment displays, buttons, buzzer, and LEDs) and mapping those interactions the to the correct ESP-32 I/O lines that controlled my reproduction hardware. When I finally got the mapping correct everything just worked. 

A software emulation is a different beast. In this case, you have to map the CHESSmate program's interaction with the 6530-0024 RIOT chip to an on screen CHESSmate representation. There are three major areas that have to be addressed, the Display, Keyboard, and Sound.

Display

Since I already had an Inkscape created SVG file for the CHESSmate "membrane", the first part of creating a program was pretty easy. I'm using PyGame to create the software interface. With a few lines of code I was able to create a "window" and load the membrane SVG as a background image. Great start, but it's just a static image. To bring to life, I had to be able to light up the on screen 7-Segment displays and the LEDs. 

For the 7-Segment displays, my first thought was to create graphics for each of the seven segments and "light them up" by drawing them on the background based directly on the which lines of the virtual 6530-0024 RRIOT chip were enabled, but this felt like a lot of complexity. Then I discovered that there was a 7-Segment TrueType font available. I ended up downloading the file DSEG7ClassicMini-BoldItalic.ttf and using PyGame's built in font engine to render the display characters all at once based on the which seven virtual 6530-0024 RRIOT chip lines were enabled. 

The LEDs were much simpler. Just draw a red circle in the appropriate spot and size when the RRIOT code indicated that a particular LED was to be lit. 

For both the 7-Segment displays and LEDs, at system startup before anything had been written to the background image, I captured and saved small image "patches" of the areas that were to be overdrawn, and bitted them back to the screen to "erase" the character or LED when required. 

Keyboard

For the keyboard I recorded the coordinates of the 19 on screen buttons, and monitored PyGame mouse click events to see if they were within one of the button rectangles when a click occurred.  It was then relatively easy to map those clicks back to the appropriate RRIOT register response. In addition I used PyGame keyboard events to also map the following physical keys: A, B, C, D, E, F,G, H, 1, 2, 3, 4, 5, 6, 7, 8, Return (ENTER), Backspace (CLEAR) and Esc (NEW GAME).

Sound

Sound turned out to be the most work. With the hardware emulation I just had to connect the two leads of a piezo "buzzer" to two RRIOT mapped pins. Done.  With software emulation I ended having to create WAV files for each of the 14 unique sounds that CHESSmate uses. To determine when a sound was starting I monitored the two RRIOT sound pins for  "activity" (one or the other pin set high). Note that when no sound was playing both pins would be set low. The sound to be played was set as a number in a zero page data byte ($69). Based on that number I used the PyGame sound library to play the appropriate wave file. Calls to play a sound return immediately and the sounds play asynchronously with continued program execution (nice). To determine when the CHESSmate program is finished playing the sound the activity on the RRIOT sound pins will stop (both low) for at least 5ms and the emulation is reset to wait for the next sound.

CHESSmate Software

The CHESSmate program can be found on GitHub. Simple copy all of the files in the Python folder into a folder on your target machine and run:

python main.py

I believe that the only dependency is that you must have PyGame installed. I've tested the program on Windows and the latest Pi OS using Python 3.x and PyGame 2.1.2. 

If you don't want to build the CHESSmate hardware but would like to check out a CHESSmate "experience" this is your best bet.

Caveats

Discussions