Simulating Фахівець-85

2025-08-10

The book

I recently read a book on the history of computing in Ukraine: Innovation in Isolation. It has the story of Fahivets-85 - my first computer I got as a birthday gift when I was 6. The urge to try this machine again was so big I decided to simulate it and run some programs (and games) I remember from the childhood. Even though there are several existing emulators of this and similar machines, I wanted to take the implementation path myself.

The code

At the moment of writing I have an emulator that compiles into Web Assembly and is good enough to run the game called "Rain". The game is quite simple: press any key to go past the main screen, then use the arrow keys (left and right) to control a up and catch the rain drops. Is you miss a drop once, a cactus starts growing. If you miss twice on the same place, the cactus get bigger and you will die if you touch it. If you miss for the 3rd time, the cactus will transform into a demon that will move randomly.

There are some issues with how the keyboard is handled, and I don't yet have the sound. But the game is quite playable.

It took me 43 commits to get to this state. Here are the main ones.

  cmd  encoding   flags   size  cycles     time  semantics            example
  ACI  11001110   ZSCPA      2       2        7  A = A + data + fC   |A=2, data=1, fC=1 => A=4
  ADC  10001r/m   ZSCPA      1     1/2      4/7  A = A + r/m + fC    |A=2, B=1, r/m=b000, fC=1 => A=4

My original idea was that I can write a generator of Go code from this table. Instead of implementing my own generator, I take the path of asking AI assistant to generate implementation and tests for me looking at those specs. It took some time to get implementation and tests in the style I liked, but once I prepared first examples myself, AI was quite good in following the existing pattern and adding other implementations.

Now the game is playable. Most likely, I have more problems with the CPU emulation. I'm not confident in my decimal addition implementation and handing the decimal carry flag (A). Other games are not working yet.

But it's such a joy to see the first result and share it with friends... Let's see when I get energy to continue.