Porting Peter Jennings's Microchess to MKHBC-8-R1.

While the concept of my home brew computer was still in the abstract phase, I have been doing lots of research on the internet regarding the topic of building ones own 8-bit computer system. I found lots of cool web sites and great home brew projects. Some of them referenced Peter Jennings's "Microchess" chess implementation running on their hardware (e.g: Big Mess of Wires or BMOW project). I thought it would be awesome to have this software running on my platform. Through this great portal, I found reference to source code of the implementation of "Microchess" modified by Daryl Rictor to have the program communicate with terminal via serial port (original implementation was on KIM-1 using its hex keypad and 7-segment display).I only modified some zero page addresses so the program would not interfere with my OS and supplied my own I/O functions that called MKHBCOS API and preserved A and X registers. Easy as pie, but... it did not work.
After hours of debugging and looking at the code I finally realized (again) that cl65 has put one segment of my code at wrong address due to incorrect configuration.
Here is the configuration file for my port of "Microchess":

    RAM1:    start = $0400, size = $0520, fill = yes;
    RAM2:    start = $0920, size = $006E;

    CODE:    load = RAM1,    type = rw;
    DATA:    load = RAM2,    type = rw;

Before the corrections, the size property of RAM1 was one byte shorter ($051F). Notice fill=yes property setup? That's right, as you probably already realized, my DATA segment was put at wrong address because of the wrong size declaration of RAM1 memory. When using fill=yes property, (which is necessary to produce continuous code for my bin2hex tool that generates write memory statements to plain text file, which are then sent to the MKHBC-8-R1 via terminal emulator using Send Text File feature), the size of the memory section must be the exact difference between the start of the next section and start of the current section. In above example: $0920 - $0400 = $0520.
After correction to configuration file cl65 linked all segments of program to proper address locations and runs flawlessly:

Figure 1: Peter Jennings's "Microchess" running on MKHBC-8-R1.

Next step (if I ever find time) is to improve the user interface a bit. The presentation is OK I guess, It wont get much better in text mode. However data input is a bit awkward (commands are taken key by key, refreshing the screen unnecessarily after each key stroke, instead of just taking full command line and parsing it when fully entered). I think this is KIM-1's legacy of taking input from hex keypad, Daryl Rictor did not change this part of code much). Well, poor user friendliness is the price you pay for compact code. The whole thing fits in just 1407 bytes! Original program on KIM-1 ran in standard 1 kB of RAM. The whole chess engine! This is awesome. As a professional programmer I can appreciate efficiency in coding.

That's it for today. Thank you for reading.



Popular Posts