Mr. Chess for Intellivision

tosh1 pts0 comments

Mr. Chess for Intellivision

Main page

Intel 8080 emulator

Chess programs

Contests

Store

Retrogaming

FAQ

Links

About me

Ver en español

Mr. Chess for Intellivision

It was a dark and stormy night, and I could have been watching a movie, but instead, I decided to program a new game for my Intellivision. I felt like it would be far more productive than being stuck in the chair, lowering my IQ with stereotypical scripts, action scenes, and special effects.

Many years ago, when I was a kid, I always wanted to write chess programs. At these times I was using a Z80-based homebrew computer, and I had no idea of tree search, minimax algorithm, alpha-beta cut, or board scoring.

I used to pass hours drawing chess pieces that I would put on the screen and then making the interface for moving pieces, later (and embarrassingly), I only had a two-player game because I couldn’t figure out how to make the computer play.

My first attempt to make a computer to play the game of chess happened in the year 1989, and it was based simply on reading the board, trying all the moves, then calling itself, and being only a kid I didn’t envision all the possible paths of the game. I was able to play excitedly a few movements against the computer, and then the stack overrun all the memory, and my precious first chess game with AI code was lost in the mists of time. Maybe the most interesting thing is that no one of my family saw what I did, so when I told they what just happened I was meet with unbelief.

The year is 2023!

Let us return to the year 2023, 44 years after the introduction of Intellivision, and 41 years after the introduction of USCF Chess for Intellivision.

USCF Chess running on the jzintv emulator.

The USCF Chess game used 8x8 pixels and the chess graphics suffer because of the small space available to draw (although in fact something pretty recognizable can be done in 6x6 pixels as my JS1K Chess shows). I decided to draw the chess pieces on a matrix of 16x8 pixels, in this area I could draw 10x8 pixels for each piece.

The chess figures for my Intellivision chess program.

With an initial set of pieces, I proceeded to design the routines to draw the board on the screen, and put a cursor on the screen movable with the disc controller.

Now I had a typical two-players chess game with no move validation. How about an engine?

The engine

I took my Toledo Atomchess code originally written for x86 processors and started translating it to the CP1610 processor assembler code.

The main challenge was to keep the memory usage inside the limits of the Intellivision (240 bytes, and 112 16-bit words). In contrast, the Mattel USCF Chess has the advantage of an extra 2K of RAM (at the time a pricey cartridge).

In my chess engine, the board is represented as 120 bytes, a 10x12 arrangement where the 8x8 chessboard is positioned at the center, plus a stack is built into the 8-bit memory to keep search data (10 bytes for each ply).

Furthermore, it was being built on a chessboard interface written in the IntyBASIC language, and IntyBASIC requires some memory on its own (40 bytes for basic support and music player, and 41 words for display support), plus the variables required by the chessboard display and interface.

Although it was a pretty direct translation, it wasn’t so easy to port these routines. The most difficult part was to assign registers to the code and keep these valid along the playing routine. More than once, I missed a register that should be preserved along several steps of the engine and caused a bug.

Using the registers R4 and R5 to read or write to memory, also auto-increments these registers. There’s no similar behavior on the x86, but of course, this made several parts of the code to require redesign. By the night I had a working version of this simple engine.

The first working version of my chess game for Intellivision.

This simple engine didn’t have support for the full chess movements, like en passant, castling, and promotion. However, it is so short this little test engine that as a programmer I need to show you the beauty of it! Only 262 lines of assembler source code.

; Chess engine for Intellivision<br>; (c) Copyright 2023 Oscar Toledo G.<br>; https://nanochess.org/<br>; Creation date: Feb/28/2023.

STACK_ENTRY: EQU 10

piece_total:<br>DECLE 3,3,7,3,3,7,7

piece_offsets:<br>DECLE displacement+16<br>DECLE displacement+20<br>DECLE displacement+0<br>DECLE displacement+12<br>DECLE displacement+8<br>DECLE displacement+8<br>DECLE displacement+8

displacement:<br>DECLE -21,-19,-12,-8,8,12,19,21<br>DECLE -10,10,-1,1<br>DECLE 9,11,-9,-11<br>DECLE -11,-9,-10,-20<br>DECLE 9,11,10,20

piece_scores:<br>DECLE 0,1,3,3,5,9

PLAY_CHESS: PROC<br>BEGIN

MVII #-128,R0<br>MVO R0,var_BEST_SCORE

MVI var_TURN,R0<br>XORI #8,R0<br>MVO R0,var_TURN

MVII #array_BOARD+21,R3

SR7: MVI@ R3,R1 ; Read square.<br>XOR var_TURN,R1 ; XOR with current playing side.<br>ANDI #$0F,R1 ; Remove moved bit.<br>DECR R1 ; Translate to 0-5.<br>CMPI #6,R1 ; Is it frontier or empty square?<br>BC SR17 ; Yes,...

chess decle intellivision game engine displacement

Related Articles