One 32K Datapak that plays Connect 4 on every Organiser II, from an 8K CM to a 64K LZ64. The game runs as 6303 machine code in a single 4,330-byte array; everything else waits on the pack and is read in when needed. This report shows the screens and menus, how the program is put together, how the engine thinks, and where every byte goes.
The two-line models (CM, XP, LA) draw the whole board in the display's eight custom characters: a block 4 characters wide and 2 high, each cell 2 by 2 dots. Solid is a filled square, Hollow a diagonal pair. The four-line LZ and LZ64 give each column its own character and draw discs 5 by 3 dots. The other 12 characters of each line are the text panel. The screens below are drawn dot for dot from the game's rules, with the same sample position.
15 items, shown 2 or 4 at a time with “>” on the chosen one. UP and DOWN move, a letter jumps to the next item starting with it, EXE takes it, ON/CLEAR goes back. New game asks One player, Two players or Demo; Two players then asks each player for a name of up to 6 letters.
| Item | Values (LEFT / RIGHT) | What it does |
|---|---|---|
| Level | 1 … 8, Auto | How hard the Psion plays; Auto moves up after your win and down after your loss |
| Play | 1st, 2nd, Alt | Whether you start, the Psion starts, or you take turns |
| Coach | Off, On | Comments on each move from the book and solved endings; shows threat cells; names a drop that misses a four or lets one in or a fork, before it is made (one and two players) |
| Hints | Yes, No | SPACE asks for a 600-position search |
| Undo | Yes, No | DEL takes back your move and the reply |
| Keep | Ask, All, Off | Finished games: ask “Export game?” before a new game starts over one not exported; export every one as its result shows; or neither. The last game is kept in A:C4LAST whatever this says |
| Pace | Nat, Fast | A short pause before the moves the Psion makes without searching (book moves, a win, the one block, every move at levels 1-2), or none |
| Sound | All, Tick, Off | Win tune and buzzes, only the drop tick, or silence |
| Digits | Off, On | Whether 1–7 also drop the disc |
| Starts | Alt, Lost, Won | Two players: who starts the next game (the one who lost, or who won) |
| Swap | Off, On | Two players: after Solid's first disc, Hollow may take Solid |
| Timer | Off, 10s, 20s, 30s | Two players: a countdown for each move, shown after the column (“ANN:4 17”); held while the menu is open; at 0 the disc drops in the chosen column |
| Match | 1, 3, 5, 10 | Two players: games needed to win a match |
| Clock | None, 1m, 3m, 5m, 10m | Two players: a game clock for each side |
| Demo S / Demo H | 1 … 8 | The levels Solid and Hollow play at in the demo |
Coach verdicts: “Coach: win”, “Coach: draw”, “Coach: lost”, “Still a win”, “Good move”, “Win -> draw”, “Win -> loss”, “Draw -> loss”, and for solved endings “Win in 9”, “Loss in 4”, “A draw”; out of the book with no solved ending, “Can't tell”. Exported games are files A:C4G1 … A:C4G99, one record of column digits such as 4435362; the last game finished is A:C4LAST.
Nothing about the game is written in OPL except a few lines that make room for it. Two small OPL procedures check the free RAM and make one integer array; a 75-byte loader poked into the top of that array finds the kernel on the pack, reads it in and starts it. From then on the 6303 kernel runs the game, and every screen, the opening book and the animations are read from the pack into a 671-byte slot only when they are needed.
flowchart LR L[game loop] -->|game over| R[OV_RESULT
count, show] --> TA[OV_HELP
the tally] --> EN[OV_END
keys, blink] L -->|your turn| PA[OV_PANEL
fixed lines] --> PL[OV_PLAY / OV_PLAY2
keys, ghost disc] L -->|Psion's turn| BK[OV_BOOK
book move or
search figures] --> TH[search
+ OV_THINK display] PL -->|command| C[kernel commands] --> L EN -->|command| C TH --> MV[play the move] BK -->|book move| MV MV --> FX[OV_FX
record, fall, make,
show; the end?] --> SV[OV_GAME
save] --> L
Each box after the loop is an overlay read from the pack into the slot (about 40 ms each). An overlay can hand straight on to the next by jumping into the loader, so a chain such as OV_RESULT → OV_END costs no kernel code.
| Unit | Bytes | Job |
|---|
The engine is 2,229 bytes of 6303 code and tables, kept in RAM all the time. It was written twice: once in JavaScript as the specification, and once in assembler. A test plays both side by side and requires every state byte, every evaluation, and every search's move, score, depth and position count to be identical.
A move updates only the lines through its cell (3 to 13, about 6.5 on average). One routine plays both sides: a branch is patched to “always” or “never” to read each line byte with its halves swapped for Hollow.
The open-line score, plus threat parity. For each column, the lowest threat a side has there counts 16 if it is on that side's good rows (odd rows for Solid, even rows for Hollow, the rows where the other side will be forced to give the cell up) and 4 otherwise. The result is kept between −50 and +50, well away from the scores of won and lost positions.
Levels 1 and 2 add noise drawn from the key, so their mistakes vary from game to game.
The search's table and working space (779 bytes) are laid over the screen driver and the overlay slot, which are idle while it thinks; the driver is read back from the pack afterwards. Speed: about 3,230 processor cycles a position, 285 positions a second at 0.92 MHz, the same on every model.
| Level | Positions | ≈ time | Other | Kept |
|---|---|---|---|---|
| 1 | depth 2 | <1 s | noise 48 | 96.2% |
| 2 | depth 2 | <1 s | noise 24 | 96.0% |
| 3 | 600 | 2 s | noise 12 | 97.6% |
| 4 | 900 | 3 s | noise 6, book 2 | 97.2% |
| 5 | 1,500 | 5 s | book 3 | 96.7% |
| 6 | 3,000 | 10 s | book 4 | 97.3% |
| 7 | 9,000 | 30 s | whole book | 97.7% |
| 8 | 30,000 | 100 s | whole book | 98.5% |
“Kept”: the share of its moves that keep the position's true result, against a perfect opponent, from random positions after 8 discs. “Book n”: the Psion's first n moves come from the book.
Solved on the PC by our own perfect solver and checked against John Tromp's database of all 8-disc positions. Each entry is 4 bits: the best column, a win (only 20 entries are draws or losses, and they use just 8 column-and-result pairs, which codes 8–15 stand for). Entries are found by the opponent's moves alone (the Psion's are the book's own), with openings in columns 5–7 mirrored, so no positions are stored.
Every position with 14 or fewer empty cells is solved exactly at level 8, most with 16–18 (“Win in 9”). The Psion's solved results and book values are kept in a 2-bit-a-move history in the save file, which the coach and the review use to mark moves that threw away a win or a draw. The review also marks, anywhere in any game, a move that missed a four, or let in a four or a fork that another move would have stopped (“Allows fork”); DOWN in the review jumps from one marked move to the next. With the coach on, the same check runs on each drop before it is made (since 19 Nov).
The game is the same 4,330-byte array on every model (4,530 on the morning of 20 Nov: then the overlay and command tables moved onto the pack, the empty-board routine used the ROM’s fill, the rarer commands and the end of a game moved into overlays, and the start-up code took over the kernel’s entry). The tight case is the 8K CM, where the Organiser's own system variables and stack already take 1,683 bytes. Drawn to scale:
On an XP (16K) or LA (32K) the same array leaves 8–24K free. On the LZ64, files on A: live in separate RAM banks and cost the game nothing.
The kernel's working variables (75 bytes) are not in the array: they sit in C4G's copy of the loader string, which is dead once the loader has run. The saved part (settings to checksum, 81 bytes) is written to A:C4SAV straight from where it sits. The tally is not in RAM at all: it lives in A:C4TAL and is read only on the result screen.
Most of the engine’s tables (326 of 341 bytes) list the lines through each cell, read on every move of the search. Working them out instead was built and measured on 20 Nov (same moves as the reference engine): 124 bytes less RAM with the search 21% slower, or 96 bytes with a small range table and 12% slower. Levels count positions, so strength would not change, but level 8 would think about 12 s longer a move. Not done.
The screen driver and the overlay slot are 957 bytes together. Between searches they hold the driver and one overlay. During a search they hold the engine's table, its working space and the thinking display (which carries its own variables), with 2 bytes to spare:
Hatched: the bytes some overlays leave at the top of the slot (set-up's search; the review's tactics; the result's last line, kept for the key names). Since 19 Nov export and import use the screen driver's area as their buffer instead, and read the driver in again after. The slot is as big as the largest overlay with its buffer; set-up fills it exactly.
C4K, C4B0 and C4B1 are data blocks disguised as OPL procedures whose code is a single RETURN, so running one by mistake does nothing; each costs 33 bytes of headers.
The fix-up list is stored as steps between addresses, two to a byte (1–15: on that far and fix the word there; 0: on 15): 261 bytes, where one byte a gap took 485 until 19 Nov. The overlays’ lists are stored the same way, so each loads 6–12 ms faster. The two lengths at the front let the loader read everything in one go.
Read a byte at a time straight from the pack while the Psion chooses its book move; never copied into RAM.
Solid: the code. Light: its fix-up list (read and applied as it loads, never kept in RAM). The block starts with two tables the kernel kept in RAM until 20 Nov: the command table (34 bytes) and where each unit starts (40); each command and each load now reads its two bytes from the pack. Shared routines such as the menu, the move record and the history are copied into each overlay that needs them, which costs pack space but no RAM.