2D Game of Life for the Commodore 64

In 1970, British mathematician John Horton Conway devised a zero-player game called „Game of Life“. In a two-dimensional simulation you can watch cell colonies multiply, divide, and die. Although always starting in random, chaotic patterns, the cell colonies often strive for symmetric patterns after a while.

An old implementation of this game called „Life“ from 1986 seems to have no valid download path anymore. There is one version of this game for the Commodore 64 by a user named „ruk“, written in assembly and released in 2012. It is a bit fast and hectic for my taste and features annoying „music“. Another version by user  Marek Karcz is also written in assembly. It is fast but maybe a bit complicated to use the first time started. Yet another nice version by Tom Toad is also written in assembly. Here you have to create your cell colony first and then run the simulation. Maybe there is a reason why all these versions are written in assembly language and not in something like C?

My version of the game starts with a random sized cell colony in the middle of the screen with up to 25 cells. There is nothing the user has to do but sit back, relax, and watch cells multiply and die.

On the bottom of the screen the program will tell the current generation starting with one, then the population (number of alive cells), and lastly the number of cells the simulation started with:

If there are no more alive cells the program ends with the message „No more alive cells!“. For the unlikely case that the simulation started with zero alive cells, the program will also end.

When I finished coding the Game of Life in modern C, I wanted to transfer the code over to the Commodore 64 platform. Aside from getting better in programming, I also wanted to find out the performance difference between an older Office PC running Linux/GCC and the C64 running code created by POWER C.

My code for GCC and the C64 can be found on GitHub.

Working with POWER C with a slightly bigger project is not always fun, especially when you are coming from a modern development environment like on a Linux system. During each hour of compiling and linking I had to roughly restart the system twice to get it out of a crash.

Speed is another thing. My x86 C code of this game takes 1 second from generation to generation, and this is only because I put a 1-second pause („sleep(1)“) in there. The game on a C64 running at 2 MHz takes around 4.6 seconds from generation to generation, and this is without the pause and some code optimization! I could not determine a speed difference between starting the program from the BASIC prompt versus from the POWER C shell.

One annoying thing with POWER C is this: When the floppy disk is almost full, POWER C will not give you a warning. Instead, it will create a 0-byte file and later on send a cryptic error message your way. Here is an example from the linker:

The compiler ended without an error message but did not write the object file. It created it and then ran out of disk space, leaving the file handle open.

So, what do I think of this experiment? Unless you want to use the simulation for meditation purposes, the software is running a bit too slow. Maybe I can come up with some faster algorithms in a future release.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert


Der Zeitraum für die reCAPTCHA-Überprüfung ist abgelaufen. Bitte laden Sie die Seite neu.