CHESS 4K - the 3rd new homebrew for Videopac / Odyssey2 by bataais

 Doing the impossible: Many believed, the Videopac / Odyssey2 did not have enough memory and computing power for a decent implementation of chess on its own..

(Cover artwork & manual design by my older brother Lopetz, Büro Destruct, Bern)

CHESS 4K
- Plays in accordance with international chess rules:
  Knows en-passant, castling and pawn promotions
- Does not accept illegal moves
- 11 Levels of difficulty, changeable during a game
- Check, stalemate and mate announcement
- Computer can play against itself
- Take back 2 half moves
- Setup positions with clear or full board
- 8049 Chess engine by IM Julio Kaplan, 1982
- Easy joystick move entering
- Works on Odyssey2, Videopac and Videopac+, universal binary
- No need for an external computer module
- All in 4kB ROM!

Released on cartridge, get it here (limited run of 30 carts, already sold out?):




How did I do the impossible?

Engine selection

As a chess computer geek, I knew there were 2 dedicated chess computers in 1982, using the same MCU (in this case the Intel 8049) with only 2KB ROM and 128 bytes internal RAM. (Full ROM access without bank switching.)

1. Fidelity Mini Sensory Chess Challenger II, programmed by Ron Nelson.

2. Novag Micro II, programmed by Julio Kaplan (not by David Kittinger, as I found out here..)

   (Many clones of this one were released by Novag until 1987.)

(VIDEOPAC uses the 8048 MCU with 1KB ROM already filled by the (executive) firmware, 64 bytes of internal RAM (half used by the executive and stack) and 128 bytes of external RAM. Cartridges can be 2-8KB ROM, only 1KB can be accessed at a time, banks must be switched to access other regions.)

Both chess computers are emulated in MAME, the ROM binary is available. Using MAME debugger I could see that the Fidelity used interrupts and parts of the stack as memory, which would have complicated matters. The Novag didn't do this, so I decided to use it as the base engine.

(I tried to contact Julio Kaplan about reusing his 1982 code, found an old email address, but got no answer..)

The disassembly had to be studied, RAM mapping understood, as the whole interface had to be changed from button presses, leds and beeps to a TV graphic, joystick input and sound.

Drawing the chess board and pieces

VIDEOPAC doesn't have enough characters to display all 32 chess figures, so there had to be some kind of multiplexing the major characters, reusing 8 chars per row with help from the line-counting timer, as did the original C7010 chess cartridge.

But C7010 used external RAM for the multiplexing, which I couldn't (because it will be used for the engine). So I had to use the internal RAM.

Drawing alone used up most of the computing power, calculating chess moves and displaying the board would not be feasable at the same time.

While drawing, interrupts are enabled and used by the executive, but for the engine, interrupts had to be disabled. That meant, switching between 2 states, Interface <-> Engine. I decided to have 2KB ROM banks for each.

Adapting RAM access

The 128 bytes external RAM of VIDEOPAC must simulate the internal RAM of the chess computer, there had to be a way to replace some CPU opcodes.

Meaning, external RAM can only be accessed with MOVX A,@r0/1 and MOVX @r0/1,A; while internal RAM has a whole lot of commands.. add, anl, orl, xrl, mov, inc, xch, xchd .. These commands were replaced with calls to Int2Ext & Ext2Int subroutines.

This was quite tricky, because R0-R7 were mostly already used. I had to stop the timer and use it as a temporary variable, but as the timer was part of the randomizer, I had to replace that with another method.

All those adaptations had to be as fast as possible, not to slow down the calculation process too much.

(In the end, it was only ~1.25x slower than the original.)

Adapting ROM access

Bank switching had to be taken care of, every jmp, call, ret had to relocate to the appropriate bank (sel mb0 / mb1).

Replacing functions with the use of joystick and keyboard

I wanted to have all features of the Novag in Chess 4K, including take back, setup, levels, change sides, and I think, I succeeded. I even fixed some shortcommings of the original (like castling rights not restored after takeback) and put more levels into it, so it could solve Mate-in-3 problems.

Of course, VIDEOPAC is an old, slow and limited machine, so one can not expect wonders of the chess playing strength.

J.S. Bach's canon perpetuus

The engine used the whole first 2KB ROM bank, the interface only 1KB of the second bank, so with 1KB available, I filled it with the 3-tone-polyphonic perpetual canon by J.S. Bach (from Das Musikalische Opfer) in the start screen, but that is another story.. (Only this: It's an inversion canon with just intervals, so some data reduction was possible ;) )

The whole thing took me about 4 weeks, from Oct. 30 - Nov. 24, 2024. And I first thought it would take about a year.


Comments