Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

9 Commits

Folders and files

Repository files navigation

1982 Chess Lab: Play chess in 1K RAM

Play it: https://patrickh50.github.io/ZX81_Chess_In_1K/

An HTML emulator for the Sinclair ZX81 that runs David Horne's Chess in 1K, the 1982–83 type-in from Your Computer magazine, byte for byte, with a 3D board and modern debugging tools.

In 1982 David Horne fitted a chess program, including a computer opponent, into the unexpanded ZX81's 1 KB of RAM. He published it as a three-part series:

Part Issue What it does
1 December 1982, pp. 68–69 Machine code that draws the board
2 January 1983, pp. 81 and 83 Move logic: two-player chess with legal-move checking
3 February 1983, pp. 100–102 The complete 672-byte game: the computer plays White, you play Black

All three run here.

How to play

The default is Part 3. The board loads "from tape", then the computer opens with the King's pawn and you play Black. Enter a move as From then To, each as rank then file, so 7E then 5E moves your e-pawn two squares. You can type on your keyboard, tap the on-screen keys, or tap a piece and then a highlighted square. Red rings mark the squares the 1983 code considers legal.

Other modes, under Experiments:

  • Queen's pawn opening: the article's alternative POKEs.
  • Part 2, two players: press W or B, then enter moves for both sides.
  • Rook jumps a pawn: a quirk in Part 2 as printed, fixed by Horne in Part 3.
  • Part 1: board drawing, plus misprint and memory-limit experiments.

What's real and what's a stand-in

  • A Z80 interpreter written in JavaScript runs Horne's bytes at their real addresses, from RAND USR.
  • The 1K memory map is faithful: system variables, the REM line holding the code, the collapsed display file, and the stack under RAMTOP.
  • No Sinclair ROM is included. The ROM routines the program calls (print, PRINT AT, print string, keyboard scan, key decode, and the tail of the NEWLINE routine at 0x0724) are rewritten in JavaScript to the same rules.
  • Not modelled: video timing, FAST/SLOW, T-states, and the ROM character set (a modern font is used).

2026 tooling on 1981 code

  • Timeline and reverse stepping: rewind and replay any instruction; typing a different move after rewinding starts a new branch.
  • Profiler: each listing line shows how often it ran.
  • Tap to inspect: tap any square to see the byte behind it and which instruction wrote it.
  • Live prompts: the panel reads the Z80 stack to show what the program is waiting for.
  • Thinking counter: counts the instructions in the computer's search.
  • The engine's thoughts, made visible: while the computer searches, a streak flashes for every candidate move it tries (each call to its PMOVE routine), and its chosen move draws a glowing arc.
  • Cinematic captures: a captured piece shatters, with slow motion and a camera shake.

Repository layout

index.html            the built page (served by GitHub Pages)
vendor/               three.js r170 bundle and its MIT licence
src/emu.js            Z80 core, ZX81 memory model, ROM stand-ins, disassembler
src/page.html         page template
src/part1.js          Horne's code, part 1   (© David Horne, not MIT; see NOTICE)
src/part2.js          Horne's code, part 2   (© David Horne, not MIT; see NOTICE)
src/part3.js          Horne's code, part 3   (© David Horne, not MIT; see NOTICE)
src/build.py          combines the above into index.html
tests/                CPU tests, byte verifiers, scripted games (Node.js)
docs/TRANSCRIPTION.md how each listing was transcribed and checked

Rebuild with python3 src/build.py. Run the checks with node tests/cputest.js, node tests/verify2.js and node tests/verify3.js.

Licence

The emulator and page are MIT licensed (see LICENSE). That licence does not cover David Horne's code or the Your Computer material. See NOTICE.md.

Built with Claude (Anthropic).

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages