Hauptsache es klingt !

My personal scrap book.

MicroChess on the Poly-88: an unfinished 1979 port, restored as in 1977, and completed with 2026 techniques

In short. A Poly-88 cassette from 1979 held CHESS51, an unfinished 8080 transcription of MicroChess: board and commands, but no move generator and no search. CHESS8080 completes it as MicroChess itself did, after the published MicroChess algorithm of 1976, at the same addresses; it assembles with the period assembler ASM G03 once a one-byte symbol-table limit is raised from the front panel. CHESS8080-2026 keeps the face and adds a complete engine (legal chess, alpha-beta, iterative deepening, move ordering, piece-square tables, an opening book) in 8 KB of 8080 code. On the Poly-88’s 1.8 MHz it searches about 110 positions a second, passes every perft test, and beat the MicroChess algorithm in 10 of 12 games (2 draws), and in a side-by-side showdown by 22.Qxc8#.
Background. MicroChess was written by Peter Jennings for the KIM-1 in 1976; 8080 versions followed. His own account, „History of Microchess“, is at benlo.com/microchess; his site is Benlo Park.

Where CHESS51 came from

A private collector shared recordings of PolyMorphic Systems Poly-88 cassettes. One side holds a file named CHESS51, an assembler source of 7,075 bytes whose first line reads ;** CHESS ** VER 0.51 02/24/79. All 31 tape records were read with both checksums holding. The source assembles with the period assembler ASM G03 (LOADP /CHESS51/, ASMB 7000, CALL 7000) and shows the MicroChess title, „Written by: P. Jennings & T. O’Brien.“, the question „Do you want WHITE ?“, the board and the prompt CMD:. Asked to move, it answers „O-O“ and moves nothing.

Poly-88 screen: a text chess board framed by '+------ MicroChess -------+' and '+------ Challenger -------+'.
Fig. 1 — The CHESS51 transcription assembled with ASM G03 and started: MicroChess' board on the Poly-88's 64 x 16 screen.

What was missing, and how it was found

CHESS51 turned out to be a partial transcription of an 8080 version of MicroChess. Its labels are the addresses of the original program (H00D7, H047D, H09ED …), and every routine sits behind an ORG START+… at its original address. Reading the source against the published MicroChess algorithm showed:

  • Present: the command loop (G, D, E, S, O, R, A, N), the board display, move entry in MicroChess‘ two-digit squares (14-34), the second stack used to take moves back (MOVE at H086D), the routine that turns the board around (REVERSE at H05C3) and the MicroChess tables: the 32-slot piece table BOARD, the start position SETW, the move directions MOVEX and the piece values POINTS.
  • Missing: the whole move generator and evaluation. GO at H047D is a bare RET marked TEMP, two calls in the G command are DB 0,0,0 ;*** TEMP ***, the O command jumps to „Input error“, and the address ranges 05DDH–071CH, 071FH–085FH, 0862H–086CH and 08ACH–09BEH are empty ORG gaps.
  • The „always O-O“ bug: the G command tests LDA H0075+3 before printing O-O. H0075+3 is the byte 21H of an instruction, never zero. The same routine clears the castling flag at 0A78H right after printing; the transcription dropped an „A“ (0078H for 0A78H).

The work cells give the layout away: the 25 bytes at 0A5BH–0A73H are the 6502 version’s zero-page counters $DC–$F4 in the same order, and the leftover values 15H, 16H and 14H sit exactly where the mobility counters BMOB, WMOB and PMOB belong. Two earlier drafts on another tape of the same collection, CHESS03 and „CHESS03A, 2nd part“, show the porter splitting the source into two files joined by EQUs; version 0.51 is one file again.

Two editions

The work produced two completions. The recovered transcription stays unchanged beside them.

Program What it is Runs at Size
CHESS51 the transcription as recovered, byte for byte 7000H (32K) 1,643 bytes assembled, gaps empty
CHESS8080 restored 1977 edition: the gaps filled as MicroChess does it 7000H–7E0FH (32K), the transcription’s own footprint 2,863 bytes assembled
CHESS8080-2026 enhanced edition: the same face, a complete engine written in 2026 2000H–3FC1H, work area 4000H–5FFFH (16K, 32K or 48K) 7,994 bytes assembled
Poly-88 screen with the MicroChess board, black pieces at the top, white at the bottom.
Fig. 2 — CHESS8080, the restored 1977 edition, after "Do you want WHITE ? Y": the player's pieces at the bottom.
Poly-88 screen with the chess board seen from black, digits 0-7 and files h to a under it, prompt CMD:.
Fig. 3 — CHESS8080-2026 after "N" and mode N: the same frames, with row digits and ranks on the right, column digits and files below.

CHESS8080: the restoration

No 8080 MicroChess listing was available. The reconstruction follows the published 6502 MicroChess by Peter Jennings (written for the KIM-1 in 1976) as given in the Apple I source listing (port by Daryl Rictor, 2002), routine by routine, in new 8080 code that uses the transcription’s own tables and work cells. Each reconstructed routine carries an [R] comment naming the 6502 routine it follows.

  • GO: the opening book, then a pass in STATE 0CH (the present position’s counts) and one in STATE 4 (every legal move, each judged by ON4).
  • JANUS, ON4, TREE: after each generated move: count mobility and captures, generate the replies, the continuation and the capture exchanges.
  • GNM, CMOVE, CHKCHK, LINE, SNGMV, PAWN: the move generator; legality by generating all replies and looking for a king capture.
  • STRATGY, CKMATE: the weighted sum of the counts with the same additions and subtractions in the same order; the 6502 SBC chains become SUB/SBB chains.
  • 8080 specifics: the 8080 has no overflow flag, so the capture flag that the 6502 code passes in V lives in the work cell 0A52H.
CHESS8080: CMOVE and CHKCHK, after the 6502 routine by Jim Butterfield (excerpt) · lines 964–1015
 964  CMOVE   LDA     H0A55   ** CMOVE **
 965          MOV     E,A
 966          MVI     D,0
 967          LXI     H,H0A2C
 968          DAD     D
 969          LDA     H0A4E
 970          ADD     M
 971          STA     H0A4E
 972          ANI     88H
 973          JNZ     ILLEGL
 974          LDA     H0A4E
 975          LXI     H,H0A0C
 976          MVI     C,20H
 977  CMLOOP  DCR     C
 978          JM      CMNO
 979          CMP     M
 980          DCX     H
 981          JNZ     CMLOOP
 982          MOV     A,C
 983          CPI     10H
 984          JC      ILLEGL
 985          MVI     A,1
 986          JMP     SPX
 987  CMNO    XRA     A
 988  SPX     STA     H0A52
 989          LDA     H0A54
 990          ORA     A
 991          JM      RETL
 992          CPI     8
 993          JNC     RETL
 994          LDA     H0A52   ** CHKCHK **
 995          PUSH    PSW
 996          LDA     H0A54
 997          PUSH    PSW
 998          MVI     A,0F9H
 999          STA     H0A54
1000          STA     H0A53
1001          CALL    H086D
1002          CALL    H05C3
1003          CALL    GNM
1004          CALL    RUM
1005          POP     PSW
1006          STA     H0A54
1007          POP     PSW
1008          STA     H0A52
1009          LDA     H0A53
1010          ORA     A
1011          JM      RETL
1012          MVI     A,0FFH
1013          ORA     A
1014          STC
1015          RET

The S command of the transcription already wrote two bytes, at 071EH and 0861H. These match the MicroChess KIM-1 level patches (Super blitz / Blitz / Normal). In the restored edition they are the operands of MVI A,08H in ON4 (continuation on or off) and of MVI A,0FBH in TREE (how many capture levels are examined).

Weaknesses kept on purpose. The computer neither castles (except from its book), nor captures en passant, nor promotes. Its pawn on the last rank stays a pawn. The player’s moves are not checked. A double pawn step is not tried when the single step is refused. Pawn captures do not extend the exchange tree. Stalemate is not recognised.

Test against its own rules. The move generator was run on the 8080 core and compared with a reference that applies MicroChess‘ rules (no castling, no en passant, no promotion, and no double step where the single step is refused). Every count agrees:

PositionDepthReferenceCHESS8080Equal
start12020yes
start2400400yes
start38,9028,902yes
start4197,277197,277yes
kiwipete, castling rights removed14646yes
kiwipete, castling rights removed21,8651,865yes
kiwipete, castling rights removed386,58586,585yes
position 311414yes
position 32191191yes
position 332,8102,810yes
position 3443,08743,087yes
italian middlegame13737yes
italian middlegame21,1831,183yes
italian middlegame342,96842,968yes
black to move, pins14242yes
black to move, pins21,7231,723yes
black to move, pins369,73869,738yes
checks and evasions111yes
checks and evasions22727yes
checks and evasions3544544yes
checks and evasions412,74212,742yes
Table 1 — CHESS8080's own move generator (GNM, CMOVE, CHKCHK at STATE 4) against a reference under MicroChess' rules.

The ASM G03 finding: 128 symbols

ASM G03 assembled the original CHESS51 (126 symbols) without complaint. CHESS8080 stopped with „Symbol table overflow – assembly aborted!“. The table’s size is a single byte in the assembler: 2006H = 80H, 128 entries of 10 bytes each. ASM G03 reads it once, when it starts (code at 204FH multiplies it by ten to place the source text above the table). CHESS8080 has 217 symbols. The assembler’s manual allows values up to 254 (FEH) and says to restart at 2000H after changing it.

On a real Poly-88 the change takes four front-panel commands (steps 1–4) and is undone by reloading ASM G03. The whole build runs as follows:

  1. MNTR (from the ASM G03 prompt *): the front panel with registers and a memory window.
  2. L2006 RETURN: the window points at 2006H, which shows 80.
  3. FE RETURN: 2006H now holds FEH (254 entries).
  4. SP, J2000 RETURN, G: the program counter is set to 2000H and ASM G03 restarts with the larger table.
  5. LOADP /S8080/, then ASMB 7000 9000: assembled for 7000H; the object goes to 9000H, because the source text now reaches past 7000H.
  6. A 22-byte copy routine typed in at 0C80H (21 00 90 11 00 70 01 10 0E 7E 12 23 13 0B 78 B1 C2 89 0C C3 00 70) moves the object to 7000H and jumps there.
Hex memory dump on the Poly-88 screen; the arrow points at address 2006 holding 80.
Fig. 4 — The ASM G03 front panel with the memory window at 2006H, before the change: 80H, a symbol table of 128 entries.
Hex memory dump; the arrow at address 2006 now shows FE.
Fig. 5 — The same window after "FE" RETURN: 2006H holds FEH, 254 entries; ASM G03 is then restarted at 2000H.
Poly-88 screen with the MicroChess board after the computer's first move.
Fig. 6 — CHESS8080 as assembled by ASM G03, copied to 7000H and started: the computer (white) opens from its book, MC : 13-33, that is e2-e4.

The object ASM G03 writes this way is byte for byte the object of the shipped CHESS8080 binary. The original CHESS51, at 126 symbols, sits just under the limit. A completed program in one file needs more. The two-part draft CHESS03/CHESS03A suggests the porter was already working around the assembler’s limits.

Video 1 — Assembling CHESS8080 with ASM G03 on a 32K Poly-88: ASM G03 loads from tape, the front-panel change at 2006H, LOADP /S8080/, ASMB 7000 9000 with its listing, the copy routine at 0C80H, the start and the first move. Time-lapsed: tape loading and the listing x60, typing x4, marked in the picture.

CHESS8080-2026: the enhanced edition

The 2026 edition keeps the program’s face: the title, „Do you want WHITE ?“, CMD:, the board with its MicroChess and Challenger frames, the two-digit squares and the commands. Underneath, the engine is new. It plays legal chess: castling, en passant, all promotions, check, checkmate, stalemate, the 50-move rule, threefold repetition and insufficient material. Moves can also be entered in algebraic form (e2e4, e7e8q). New commands are B (take back), F (set up a position in FEN), P (perft) and H (help).

Board and move generation

A 0x88 board holds the piece on [square] and its piece-list slot on [square+8] of the same 256-byte page, so one register pair reaches both. The piece codes P1 N2 K3 B5 R6 Q7 (+8 for black) make the slider tests single masks: a diagonal slider is (code AND 5) = 5, a straight one (code AND 6) = 6.

CHESS8080-2026: the attack test's knight, king and straight-line part (excerpt) · lines 1401–1463
1401  AK2     LDA     ATBY
1402          ORI     2
1403          MOV     B,A
1404          LXI     D,KNOFF
1405          CALL    AKSTEP
1406          RNZ
1407          LDA     ATBY
1408          ORI     3
1409          MOV     B,A
1410          LXI     D,DIRS
1411          CALL    AKSTEP
1412          RNZ
1413          LDA     ATBY
1414          ORI     6
1415          MOV     B,A
1416          LXI     D,DIRS
1417          MVI     A,4
1418          STA     AKCNT
1419  AK3     LDAX    D
1420          STA     AKDIR
1421          MOV     L,C
1422  AK4     LDA     AKDIR
1423          ADD     L
1424          MOV     L,A
1425          ANI     88H
1426          JNZ     AK5
1427          MOV     A,M
1428          ORA     A
1429          JZ      AK4
1430          ANI     0EH
1431          CMP     B
1432          JZ      AKYES
1433  AK5     INX     D
1434          LDA     AKCNT
1435          DCR     A
1436          STA     AKCNT
1437          JNZ     AK3
1438          LDA     ATBY
1439          ORI     5
1440          MOV     B,A
1441          MVI     A,4
1442          STA     AKCNT
1443  AK6     LDAX    D
1444          STA     AKDIR
1445          MOV     L,C
1446  AK7     LDA     AKDIR
1447          ADD     L
1448          MOV     L,A
1449          ANI     88H
1450          JNZ     AK8
1451          MOV     A,M
1452          ORA     A
1453          JZ      AK7
1454          ANI     0DH
1455          CMP     B
1456          JZ      AKYES
1457  AK8     INX     D
1458          LDA     AKCNT
1459          DCR     A
1460          STA     AKCNT
1461          JNZ     AK6
1462          XRA     A
1463          RET

Legality without a full attack test

After a move, the side that moved must not be in check. The full test walks eight lines and checks knights, pawns and the king. Most moves avoid it: if the mover was not in check, did not move the king and did not capture en passant, only the line from the king through the square just left can have opened. A 256-byte table built at start-up (DIRT) gives the direction of any square difference, so the test becomes one lookup and one walk.

CHESS8080-2026: ILLEG, legality with one table lookup (excerpt) · lines 1479–1545
1479  ;*** ILLEG: after MAKE, NZ if the mover's king is
1480  ; attacked. 2026 shortcut: when the mover was not in
1481  ; check and did not move the king (nor capture en
1482  ; passant), only the line from the king through the
1483  ; square left can have opened: one lookup in DIRT and
1484  ; one walk along that line instead of a full test.
1485  ILLEG   LDA     STM
1486          STA     ATBY
1487          XRI     8
1488          ADD     A
1489          MOV     L,A
1490          MVI     H,PLISTH
1491          MOV     C,M
1492          LDA     MFLAG
1493          ORA     A
1494          JM      ILFULL
1495          LDA     MPC
1496          ANI     7
1497          CPI     3
1498          JZ      ILFULL
1499          LDA     INCHK
1500          ANI     1
1501          JNZ     ILFULL
1502          LDA     MFROM
1503          SUB     C
1504          ADI     77H
1505          MOV     L,A
1506          MVI     H,DIRTH
1507          MOV     A,M
1508          ORA     A
1509          RZ
1510          MOV     D,A
1511          MVI     H,BRDH
1512          MOV     L,C
1513  IL1     MOV     A,L
1514          ADD     D
1515          MOV     L,A
1516          ANI     88H
1517          JNZ     ILOK
1518          MOV     A,M
1519          ORA     A
1520          JZ      IL1
1521          MOV     E,A
1522          MOV     A,D
1523          CPI     1
1524          JZ      ILORTH
1525          CPI     0FFH
1526          JZ      ILORTH
1527          CPI     10H
1528          JZ      ILORTH
1529          CPI     0F0H
1530          JZ      ILORTH
1531          LDA     ATBY
1532          ORI     5
1533          MOV     B,A
1534          MOV     A,E
1535          ANI     0DH
1536          JMP     ILCMP
1537  ILORTH  LDA     ATBY
1538          ORI     6
1539          MOV     B,A
1540          MOV     A,E
1541          ANI     0EH
1542  ILCMP   CMP     B
1543          JZ      AKYES
1544  ILOK    XRA     A
1545          RET

Search

The search is negamax alpha-beta with the node’s state in fixed cells, pushed onto the stack around each child. The 8080 has few registers, so this is its native style. Scores are kept with a bias of 8000H: an unsigned compare orders them, and 0 − x negates them.

  • Iterative deepening to a time limit read from the monitor’s 60 Hz clock at 0C00H (S 5 s, B 15 s, N 45 s); the best move of each depth is searched first in the next.
  • Move ordering: captures by MVV-LVA (most valuable victim, least valuable attacker), queening, two killer moves per ply, then the rest.
  • Quiescence search of captures with stand-pat, a check extension, and futility pruning of quiet moves one ply from the leaves (margin 1.5 pawns).
  • Evaluation: material plus piece-square tables (values after Tomasz Michniewski’s „Simplified Evaluation Function“), kept up to date move by move; king tables for middle game and endgame.
  • Opening book: 20 main lines from the start position, for both colours; one is chosen by the clock.
CHESS8080-2026: the move loop of SEARCH: futility, make, legality, recursion (excerpt) · lines 2446–2545
2446  SRLOOP  CALL    PICK
2447          JZ      SREND
2448          LDA     DEPTH
2449          CPI     1
2450          JNZ     SRMK
2451          LDA     FUTON
2452          ORA     A
2453          JZ      SRMK
2454          LDA     LEGAL
2455          ORA     A
2456          JZ      SRMK
2457          LHLD    MVCUR
2458          INX     H
2459          INX     H
2460          MOV     A,M
2461          INX     H
2462          MOV     B,M
2463          ANI     87H
2464          JNZ     SRMK
2465          MOV     A,B
2466          CPI     40H
2467          JNC     SRMK
2468          LHLD    ALPHA
2469          XCHG
2470          LHLD    FUTV
2471          MOV     A,E
2472          SUB     L
2473          MOV     A,D
2474          SBB     H
2475          JNC     SRNEXT          ;pruned
2476  SRMK    LHLD    MVCUR
2477          CALL    MAKE
2478          CALL    ILLEG
2479          JNZ     SRSKIP
2480          LXI     H,LEGAL
2481          INR     M
2482          LHLD    ALPHA
2483          PUSH    H
2484          LHLD    BETA
2485          PUSH    H
2486          LHLD    DEPTH
2487          PUSH    H
2488          LHLD    INCHK
2489          PUSH    H
2490          LHLD    MVCUR
2491          PUSH    H
2492          LHLD    MVHI
2493          PUSH    H
2494          LHLD    ALPHA
2495          CALL    NEGHL
2496          XCHG
2497          LHLD    BETA
2498          CALL    NEGHL
2499          SHLD    ALPHA
2500          XCHG
2501          SHLD    BETA
2502          LXI     H,DEPTH
2503          MOV     A,M
2504          ORA     A
2505          JZ      SR2
2506          DCR     M
2507  SR2     LXI     H,PLY
2508          INR     M
2509          CALL    SEARCH
2510          CALL    NEGHL
2511          XCHG
2512          POP     H
2513          SHLD    MVHI
2514          SHLD    MVPUT
2515          POP     H
2516          SHLD    MVCUR
2517          POP     H
2518          SHLD    INCHK
2519          POP     H
2520          SHLD    DEPTH
2521          POP     H
2522          SHLD    BETA
2523          POP     H
2524          SHLD    ALPHA
2525          PUSH    D
2526          CALL    UNMAKE
2527          POP     D
2528          LDA     ABORT
2529          ORA     A
2530          JNZ     SRRET
2531          LHLD    ALPHA
2532          MOV     A,L
2533          SUB     E
2534          MOV     A,H
2535          SBB     D
2536          JNC     SRNEXT
2537          LHLD    BETA
2538          MOV     A,E
2539          SUB     L
2540          MOV     A,D
2541          SBB     H
2542          JNC     SRCUT
2543          XCHG
2544          SHLD    ALPHA
2545          JMP     SRNEXT

Why it fits a 1.8 MHz 8080. The whole program is 7,994 bytes plus 8 KB of work area. The undo record of a move is written with seven PUSH and read with seven POP instructions, with interrupts off for those few microseconds. The search runs at about 110 nodes per second. That is enough for depth 3 in 15 seconds and depth 3–4 in 45 seconds, plus captures.

Move generator check (perft)

The generator was checked with perft: the number of positions after n plies, compared with the published reference counts for the standard test positions. The edition’s own P n command counted them on the 8080 core. All 24 counts agree:

PositionDepthReferenceCHESS8080-2026Seconds
start120200.0
start24004001.0
start38,9028,90222.5
start4197,281197,281–
kiwipete148480.1
kiwipete22,0392,0395.2
kiwipete397,86297,862238.9
kiwipete44,085,6034,085,603–
position 3114140.0
position 321911910.6
position 332,8122,8128.1
position 3443,23843,238–
position 41660.1
position 422642640.8
position 439,4679,46725.3
position 44422,333422,333–
position 5144440.1
position 521,4861,4863.7
position 5362,37962,379170.2
position 542,103,4872,103,487–
position 6146460.1
position 622,0792,0794.5
position 6389,89089,890194.1
position 643,894,5943,894,594–
Table 2 — Perft of CHESS8080-2026 (its P command on the 8080 core) against the published counts; time on the Poly-88 clock (depth 4 runs exceed the 16-bit tick counter and are not timed).
Video 2 — CHESS8080-2026 on a 16K Poly-88 plays the whole showdown game as white, to 22.Qxc8# and "CHECKMATE – I WIN!!!!". Time-lapsed: think time x60, typing x4, marked in the picture.

Measured: the MicroChess algorithm against the 2026 engine

Think times. CHESS8080 takes 40 to 180 seconds a move, at all three levels. The cost is MicroChess‘ legality test: every reply is itself tested by generating all of its replies. CHESS8080-2026 uses its time limit (5, 15 or 45 s).

Test positions. Ten positions with known answers: seven mates in one, one mate in two, and two material wins (each answer checked by brute force).

PositionTask2026 moves1977 moves
back-rank matemate in 1d1d8 ✓0.5d1d8 ✓11.7
mate on f7mate in 1h5f7 ✓1.9h5f7 ✓120.6
rook matemate in 1h1h8 ✓0.4h1h8 ✓3.5
back-rank mate, blackmate in 1d8d1 ✓0.4d8d1 ✓8.3
smothered matemate in 1g5f7 ✓1.0g5f7 ✓20.4
rook laddermate in 2a2a7 ✓45.2b1b8 ✗6.5
queen and rookmate in 1a2a8 ✓1.0b1b8 ✓27.3
rook and kingmate in 1a7a8 ✓0.5a7a8 ✓4.5
win the queenmateriald2d5 ✓45.1d2d5 ✓15.4
knight forkmaterialb5d6 ✓29.0b5d6 ✓4.8
Table 3 — Test positions: the move each edition chose and its think time on the Poly-88 clock (CHESS8080-2026 in mode N, CHESS8080 at Normal). Solved: 10 of 10 and 9 of 10.

Head-to-head. Twelve games on the 8080 core at the Poly-88’s clock rate, with colours alternating and CHESS8080 always at its Normal level. Both programs are deterministic, so each pairing of colour and level repeats its game; there are six distinct games.

Game2026 levelWhiteBlackResultEnd2026 s/move1977 s/move
1N (45 s)CHESS8080-2026CHESS80801-0checkmate32123
2N (45 s)CHESS8080CHESS8080-20260-1checkmate4055
3N (45 s)CHESS8080-2026CHESS80801-0checkmate32123
4N (45 s)CHESS8080CHESS8080-20260-1checkmate4055
5B (15 s)CHESS8080-2026CHESS80801-0checkmate12112
6B (15 s)CHESS8080CHESS8080-20260-1checkmate1296
7B (15 s)CHESS8080-2026CHESS80801-0checkmate12112
8B (15 s)CHESS8080CHESS8080-20260-1checkmate1296
9S (5 s)CHESS8080-2026CHESS8080½–½threefold repetition5141
10S (5 s)CHESS8080CHESS8080-20260-1checkmate460
11S (5 s)CHESS8080-2026CHESS8080½–½threefold repetition5141
12S (5 s)CHESS8080CHESS8080-20260-1checkmate460
Table 4 — Head-to-head: twelve games, colours alternating; mean think time per move in machine seconds. Result: 10 wins and 2 draws for CHESS8080-2026.

The two draws at 5 seconds come from repetition. At that speed the 2026 edition reaches depth 1–2, and it sees repetitions only at the game level, not inside the search.

The showdown

One game was played on two Poly-88 exhibits, side by side: CHESS8080-2026 (white, 16K machine, 45 s) against CHESS8080 (black, 32K machine, Normal). Each machine’s move was typed into the other.

1. e4 e5 2. Nf3 Qf6 3. Nc3 Bb4 4. Nd5 Qd6 5. a3 Ba5 6. b4 Bb6 7. Nxb6 axb6 8. Bb2 Nc6 9. d4 exd4 10. b5 Nce7 11. e5 Qd5 12. Qxd4 Qe6 13. O-O-O Qh6+ 14. Kb1 c5 15. bxc6 e.p. Nxc6 16. Qxb6 d5 17. exd6 e.p. Bf5 18. Qxb7 Bxc2+ 19. Kxc2 Qg6+ 20. Bd3 Nd4+ 21. Nxd4 Rc8+ 22. Qxc8# 1–0

MoveCHESS8080-2026sdepthCHESS8080s
1e41 (book)–e552
2Nf32 (book)–Qf676
3Nc3463Bb4104
4Nd5243Qd6137
5a3463Ba5118
6b4462Bb698
7Nxb6472+axb698
8Bb2323Nc6102
9d4472exd4109
10b5282Nce7124
11e5463Qd596
12Qxd4453Qe6119
13O-O-O462Qh6+128
14Kb1463c5124
15bxc6473Nxc6124
16Qxb6243d5144
17exd6462Bf5157
18Qxb7472Bxc2+184
19Kxc2473Qg6+141
20Bd3473Nd4+180
21Nxd4483Rc8+112
22Qxc8#22
Table 5 — The showdown move by move: think time in seconds on each machine's clock and the depth CHESS8080-2026 completed. Totals: CHESS8080-2026 13.6 min (mean 37 s), CHESS8080 42.1 min (mean 120 s).
Video 3 — The showdown: CHESS8080-2026 (left, white) against CHESS8080 (right, black) on two Poly-88 exhibits; each move is typed into the other machine. The real think times are in Table 5. Time-lapsed: think time x120, marked in the picture; the first and the last moves at real speed.
Video 4 — The same game from CHESS8080's machine: its long thinking, and at the end "CHECKMATE – YOU WIN!!!". Time-lapsed: think time x120, typing x4, marked in the picture.

Start it in the emulator

Start it in the emulator. It loads the tape and stops at the first question; answer Y to play White.

Sources

  • MicroChess, Peter Jennings, 1976 (Copyright 1976 Peter Jennings benlo.com, MIT License): the algorithm, the tables and the KIM-1 levels, as published in the 6502 source listing „MicroChess (c) 1996-2002 Peter Jennings“ (Apple I port by Daryl Rictor, 2002).
  • Peter Jennings, „History of Microchess“: https://www.benlo.com/microchess/index.html; Benlo Park: https://www.benlo.com/.
  • CHESS51: the 8080 transcription of 02/24/79 on a private collector’s cassette („Written by: P. Jennings & T. O’Brien“).
  • PolyMorphic Systems: Assembler V4 manual (symbol table at 2006H), System 88 User’s Manual (front panel), Poly-88 System Volumes I and II.
  • Intel 8080 Microcomputer Systems User’s Manual (1975).
  • Tomasz Michniewski, „Simplified Evaluation Function“, chessprogramming wiki (piece-square values).
  • Perft reference counts: chessprogramming wiki, „Perft Results“.

The three listings

All three are derivations of MicroChess. The MicroChess history page states: „Derivations from the original code are now open source and subject to the MIT license and should contain the reference Copyright 1976 Peter Jennings benlo.com and the MIT License text.“ CHESS8080 and CHESS8080-2026 carry that line and the MIT License text in their header comments; the 2026 additions carry the same licence. CHESS51 is printed byte for byte as found, so its notice sits beside it in LICENSE-MicroChess.txt.

MicroChess: Copyright 1976 Peter Jennings benlo.com, MIT License (see LICENSE-MicroChess.txt and https://www.benlo.com/microchess/index.html). 8080 port as found on a 1970s Poly-88 cassette of a private collector; printed for documentation, byte for byte. The source itself shows "MicroChess (C) 1977." and "Written by: P. Jennings & T. O'Brien.".

Listing 1 — CHESS51, the transcription as recovered (byte for byte; CR line ends shown as lines), 547 lines · download CHESS51.ASM
   1  ;** CHESS **  VER 0.51  02/24/79
   2  ;
   3  CROUT   EQU     038DH
   4  ;
   5  START   LXI     SP,H0D7E+4
   6          CALL    CROUT
   7          LXI     H,H0B6D
   8          CALL    H01DA
   9          LXI     H,H0B93
  10          CALL    H01DA
  11          LXI     H,H0BB9
  12          CALL    H01DA
  13  H0018   CALL    CROUT
  14          CALL    H05AF
  15          LXI     H,H0A95
  16          SHLD    H0A7D
  17          LXI     H,H0ACB
  18          SHLD    H0A7F
  19          LXI     H,H0B01
  20          SHLD    H0A79
  21          LXI     H,H0B37
  22          SHLD    H0A7B
  23          XRA     A
  24          STA     H0A74
  25          STA     H0A78
  26          STA     H0A82
  27          STA     H0A81
  28          STA     H0A75
  29          STA     H0A76
  30          MVI     A,10H
  31          STA     H0A77
  32          MVI     A,0EEH
  33          STA     H0A4D
  34          STA     H0A4E
  35          LXI     H,H0BF5
  36          CALL    STRG
  37          CALL    WH0
  38          CALL    WH1
  39          MOV     A,B
  40          RRC
  41          JNC     H0072-3
  42          MVI     A,1
  43          STA     H0A82
  44          CALL    H05C3
  45          CALL    H0242
  46  H0072   CALL    CROUT
  47  H0075   LXI     SP,H0D7E+4
  48          LXI     H,H0DE6
  49          SHLD    H0A59
  50          LXI     H,2020H
  51          SHLD    H0C20
  52          LXI     H,H0C10
  53          CALL    STRG
  54          CALL    H0320
  55          CALL    CROUT
  56          LXI     H,H0D0A
  57          MOV     A,M
  58          CPI     'G'
  59          JZ      H00D7
  60          CPI     'D'
  61          JZ      H0342
  62          CPI     'E'
  63          JZ      H022C
  64          CPI     'S'
  65          JZ      H01E1
  66          CPI     'O'
  67          JZ      H03D1
  68          CPI     'R'
  69          JZ      H0220
  70          CPI     'A'
  71          JZ      H02F1
  72          CPI     'N'
  73          JZ      H0305
  74          CALL    H0168
  75          LDA     H0D0A+5
  76          CPI     'M'
  77          JZ      H0126
  78          CPI     '='
  79          JZ      H0348
  80          CPI     0DH
  81          JNZ     H012C
  82          CALL    H086D
  83  H00D4   CALL    H0242
  84  H00D7   CALL    H047D   ** G Command **
  85          LDA     H0075+3
  86          ORA     A
  87          JZ      H00F4
  88          LXI     H,204FH
  89          SHLD    H0C10+0EH
  90          LXI     H,4F20H
  91          SHLD    H0C10+0BH
  92          XRA     A
  93          STA     H0A78
  94          JMP     H0102
  95  H00F4   DB      0,0,0   ;*** TEMP ***
  96          DB      0,0,0   ;*** TEMP ***
  97          LDA     H0A4F
  98          CPI     0FFH
  99          JZ      H0138
 100  H0102   LXI     H,H0C10+6
 101          CALL    STRG
 102          LDA     H0A81
 103          CPI     0FFH
 104          JZ      H0317
 105          LDA     H0A74
 106          ORA     A
 107          JZ      H0120-3
 108  H0117   LXI     H,H0CAE
 109          CALL    STRG
 110          CALL    CROUT
 111  H0120   CALL    H0242
 112          JMP     H0075
 113  H0126   CALL    H086D   ** MOVE **
 114          JMP     H0075
 115  H012C   LXI     H,H0C23 ** Input error **
 116          CALL    STRG
 117          CALL    CROUT
 118          JMP     H0075
 119  H0138   LXI     H,H0C30 ** CHKMT YOU WIN **
 120          CALL    H01DA
 121  H013E   CALL    H0242
 122          CALL    CROUT
 123          LXI     H,H0C47
 124          CALL    STRG
 125          CALL    WH0
 126          CALL    WH1
 127          MOV     A,B
 128          CPI     'Y'
 129          JNZ     H01C8
 130          CALL    CROUT
 131          JMP     H0018
 132  STRG    MOV     A,M
 133          CPI     0DH
 134          RZ
 135          MOV     B,A
 136          CALL    WH1
 137          INX     H
 138          JMP     STRG
 139  H0168   LHLD    H0D0A
 140          CALL    H0199
 141          STA     H0A50
 142          LHLD    H0D0A+3
 143          CALL    H0199
 144          STA     H0A51
 145          STA     H0A4E
 146          LDA     H0A50
 147          LXI     H,H0A0C
 148          MVI     C,01FH
 149  H0185   CMP     M
 150          JZ      H0191
 151          DCX     H
 152          DCR     C
 153          JP      H0185
 154          JMP     H012C
 155  H0191   MOV     A,C
 156          STA     H0A4D
 157          STA     H0A4F
 158          RET
 159  H0199   MOV     A,L
 160          ANI     0FH
 161          RAL
 162          RAL
 163          RAL
 164          RAL
 165          MOV     B,A
 166          MOV     A,H
 167          ANI     0FH
 168          ORA     B
 169          MOV     B,A
 170          ANI     88H
 171          JNZ     H012C
 172          MOV     A,B
 173          RET
 174          ORG     START+01C8H
 175  H01C8   CALL    CROUT   ** End of game **
 176          CALL    CROUT
 177          LXI     H,H0C5B
 178          CALL    H01DA
 179          CALL    WH0
 180          JMP     0
 181  H01DA   CALL    STRG
 182          CALL    CROUT
 183          RET
 184  H01E1   CALL    CROUT
 185          LXI     H,H0BDF
 186          CALL    STRG
 187          CALL    WH0
 188          CALL    WH1
 189          MOV     A,B
 190          CPI     'S'
 191          JZ      H0203
 192          CPI     'B'
 193          JZ      H020A
 194          CPI     'N'
 195          JZ      H0211
 196          JMP     H012C
 197  H0203   MVI     B,0
 198          MVI     C,0FFH
 199          JMP     H0215
 200  H020A   MVI     B,0
 201          MVI     C,0FBH
 202          JMP     H0215
 203  H0211   MVI     B,8
 204          MVI     C,0FBH
 205  H0215   MOV     A,B
 206          STA     H071E
 207          MOV     A,C
 208          STA     H0861
 209          JMP     H0072
 210  H0220   CALL    CROUT   ** RESIGN **
 211          LXI     H,H0C7E
 212          CALL    STRG
 213          JMP     H013E
 214  H022C   CALL    H05C3   ** EXCHG **
 215          LDA     H0A82
 216          ORA     A
 217          JZ      H023A
 218          XRA     A
 219          JMP     H023C
 220  H023A   MVI     A,1
 221  H023C   STA     H0A82
 222          JMP     H0075
 223  H0242   CALL    CROUT
 224          CALL    CROUT
 225          MVI     D,0
 226          LXI     H,H0CB6
 227          CALL    H01DA
 228  H0250   MOV     A,D
 229          ORA     A
 230          JZ      H025B
 231          LXI     H,H0CD2
 232          NOP
 233          NOP
 234          NOP
 235  H025B   MVI     B,21H
 236          CALL    WH1
 237          MVI     B,20H
 238          CALL    WH1
 239  H0265   LXI     H,H0A0C
 240          MVI     C,1FH
 241  H026A   MOV     A,M
 242          CMP     D
 243          JZ      H02B8
 244          DCX     H
 245          DCR     C
 246          JP      H026A
 247          MOV     A,D
 248          ANI     0FH
 249          MOV     E,A
 250          MOV     A,D
 251          ANI     0F0H
 252          RRC
 253          RRC
 254          RRC
 255          RRC
 256          ADD     E
 257          RAR
 258          JC      H0289
 259          MVI     B,20H
 260          JMP     H028B
 261  H0289   MVI     B,3AH
 262  H028B   CALL    WH1
 263          CALL    WH1
 264  H0291   MVI     B,20H
 265          CALL    WH1
 266          INR     D
 267          MOV     A,D
 268          ANI     0FH
 269          CPI     8
 270          JNZ     H0265
 271          MVI     B,21H
 272          CALL    WH1
 273          CALL    CROUT
 274          MOV     A,D
 275          ADI     8
 276          MOV     D,A
 277          JP      H0250
 278          LXI     H,H0CEE
 279          CALL    H01DA
 280          CALL    CROUT
 281          RET
 282  H02B8   MOV     A,C
 283          CPI     10H
 284          JNC     H02D3
 285          LDA     H0A82
 286          ORA     A
 287          JNZ     H02CC
 288  H02C5   LDA     H0A83
 289          MOV     B,A
 290          JMP     H02DD
 291  H02CC   LDA     H0A84
 292          MOV     B,A
 293          JMP     H02DD
 294  H02D3   LDA     H0A82
 295          ORA     A
 296          JNZ     H02C5
 297          JMP     H02CC
 298  H02DD   CALL    WH1
 299          MOV     A,C
 300          ANI     0FH
 301          MOV     C,A
 302          MVI     B,0
 303          LXI     H,H0A85
 304          DAD     B
 305          MOV     B,M
 306          CALL    WH1
 307          JMP     H0291
 308  H02F1   MVI     A,0CDH  ** A Command **
 309          STA     H00D4
 310          STA     H0120
 311          LXI     H,H0242
 312          SHLD    H00D4+1
 313          SHLD    H0120+1
 314          JMP     H0072
 315  H0305   LXI     H,0     ** N Command **
 316          SHLD    H00D4
 317          SHLD    H00D4+1
 318          SHLD    H0120
 319          SHLD    H0120+1
 320          JMP     H0072
 321  H0317   LXI     H,H0C96
 322          CALL    STRG
 323          JMP     H013E
 324  H0320   LXI     H,H0D0A
 325          MVI     C,0
 326  H0325   CALL    WH0
 327          MOV     A,B
 328          MOV     M,A
 329          CPI     0DH
 330          JZ      H033C
 331          CPI     07FH
 332          JZ      RUBOUT
 333          CALL    WH1
 334          INX     H
 335          INR     C
 336          JMP     H0325
 337  H033C   XRA     A
 338          CMP     C
 339          JZ      H0325
 340          RET
 341  H0342   CALL    H0242   ** DISPLAY **
 342          JMP     H0075
 343  H0348   CALL    H0168
 344          LXI     H,H0A0C
 345          MVI     C,0FH
 346          LDA     H0A50
 347  H0353   CMP     M
 348          JZ      H035C
 349          DCX     H
 350          DCR     C
 351          JP      H0353
 352  H035C   MVI     M,0CCH
 353          LXI     H,H0A8C
 354          MVI     C,7
 355          LDA     H0D0A+6
 356  H0366   CMP     M
 357          JZ      H0372
 358          DCX     H
 359          DCR     C
 360          JP      H0366
 361          JMP     H012C
 362  H0372   LXI     H,H09FD
 363          MVI     B,0
 364          DAD     B
 365          MVI     A,0CCH
 366          CMP     M
 367          JZ      H0383
 368          DCX     H
 369          CMP     M
 370          JNZ     H012C
 371  H0383   LDA     H0A51
 372          MOV     M,A
 373          LDA     H0D0A+7
 374          CPI     4DH
 375          JZ      H0072
 376          CPI     0DH
 377          JZ      H00D4
 378          JMP     H012C
 379  ;***
 380          ORG     START+03D1H
 381  H03D1   JMP     H012C   ** O Command ** TEMP **
 382  ;
 383          ORG     START+047DH
 384  H047D   RET             ** TEMP **
 385  ;
 386          ORG     START+05AFH
 387  H05AF   LXI     H,H0A0D
 388          LXI     D,H09ED
 389          MVI     C,20H
 390  H05B7   MOV     A,M
 391          STAX    D
 392          INX     H
 393          INX     D
 394          DCR     C
 395          JNZ     H05B7
 396          RET
 397  H05C0   CALL    H05AF
 398  H05C3   LXI     H,H09ED
 399          LXI     D,H09FD
 400          MVI     C,10H
 401  H05CB   MVI     A,77H
 402          SUB     M
 403          MOV     B,A
 404          XCHG
 405          MVI     A,77H
 406          SUB     M
 407          MOV     M,B
 408          XCHG
 409          MOV     M,A
 410          INX     H
 411          INX     D
 412          DCR     C
 413          JNZ     H05CB
 414          RET
 415  ;
 416          ORG     START+071EH
 417  H071E   DS      0
 418  ;
 419          ORG     START+0861H
 420  H0861   DS      0
 421  ;
 422          ORG     START+086DH
 423  H086D   LXI     H,0
 424          DAD     SP
 425          SHLD    H0A57
 426          LHLD    H0A59
 427          SPHL
 428          LDA     H0A4E
 429          MOV     B,A
 430          MVI     C,01FH
 431          LXI     H,H0A0C
 432  H0881   CMP     M
 433          JZ      H088A
 434          DCX     H
 435          DCR     C
 436          JP      H0881
 437  H088A   MVI     M,0CCH
 438          PUSH    H
 439          LXI     H,H09ED
 440          MVI     D,0
 441          LDA     H0A4D
 442          MOV     E,A
 443          DAD     D
 444          PUSH    H
 445          MOV     C,M
 446          MOV     M,B
 447          PUSH    B
 448          LXI     H,H0A55
 449          MOV     D,M
 450          PUSH    D
 451          LXI     H,0
 452          DAD     SP
 453          SHLD    H0A59
 454          LHLD    H0A57
 455          SPHL
 456          RET
 457  ;
 458          ORG     START+09BFH
 459  WH1     EQU     $
 460  H09BF   MOV     A,B
 461          JMP     0C24H
 462  WH0     EQU     $
 463  H09C9   CALL    0C20H
 464          ANI     7FH
 465          CPI     07FH
 466          JZ      WH0END
 467          CPI     60H
 468          JC      WH0END
 469          SUI     20H
 470  WH0END  MOV     B,A
 471          RET
 472          ORG     START+09DDH
 473          DB      '34',0,0,0,0,0,0,0,0,0,0,0,0,0,0CCH
 474  H09ED   DB      4,3,7,0,5,2,6,1,17H,10H,16H,11H,15H,12H,13H,14H
 475  H09FD   DB      'tswpurvqg',60H,'faebc'
 476  H0A0C   DB      'd'
 477  H0A0D   DB      3,4,0,7,2,5,1,6,10H,17H,11H,16H,12H,15H,14H,13H
 478          DB      'stpwruqv',60H,'gafbedc'
 479          DB      0F0H,0FFH,1,10H,11H,0FH,0EFH,0F1H,0DFH,0E1H
 480          DB      0EEH,0F2H,12H,0EH,1FH,21H,0BH,0AH,6,6,4,4
 481          DB      4,4,2,2,2,2,2,2,2,2
 482  H0A4D   DB      0EEH
 483  H0A4E   DB      0EEH
 484  H0A4F   DB      0FH
 485  H0A50   DB      14H
 486  H0A51   DB      34H,0,0,4
 487  H0A55   DB      0,0
 488  H0A57   DW      H0D7E
 489  H0A59   DW      H0DE6
 490          DB      0CDH,0,0,0,0,0,0,15H,0,0,0,0
 491          DB      0,0,0,16H,0,0,0,14H,0,0,0,0,0
 492  H0A74   DB      0
 493  H0A75   DB      0
 494  H0A76   DB      0
 495  H0A77   DB      10H
 496  H0A78   DB      0
 497  H0A79   DB      1,0BH
 498  H0A7B   DB      37H,0BH
 499  H0A7D   DB      095H,0AH
 500  H0A7F   DB      0CBH,0AH
 501  H0A81   DB      0
 502  H0A82   DB      1
 503  H0A83   DB      'W'
 504  H0A84   DB      'B'
 505  H0A85   DB      'KQRRBBN'
 506  H0A8C   DB      'NPPPPPPPP'
 507  H0A95   DB      0EEH,01FH
 508          ORG     START+0ACBH
 509  H0ACB   DS      0
 510          ORG     START+0B01H
 511  H0B01   DS      0
 512          ORG     START+0B37H
 513  H0B37   DS      0
 514          ORG     START+0B6DH
 515  H0B6D   DB      0CH,'MicroChess                 (C) 1977.',13
 516  H0B93   DB      'Written by: P. Jennings & T. O',27H,'Brien.',13
 517  H0BB9   DB      '-------------------------------------',13
 518  H0BDF   DB      'Which mode ? (S,B,N) ',13
 519  H0BF5   DB      'Do you want WHITE ? (Y,N) ',13
 520  H0C10   DB      'CMD: ',13
 521          DB      'MC : 14-34'
 522  H0C20   DB      '  ',13
 523  H0C23   DB      'Input error.',13
 524  H0C30   DB      'CHECKMATE - YOU WIN!!!',13
 525  H0C47   DB      'Play again ? (Y,N) ',13
 526  H0C5B   DB      'Thanks for the game... MicroChess.',13
 527  H0C7E   DB      'You resigned - I WIN!!!',13
 528  H0C96   DB      '  CHECKMATE - I WIN!!!!',13
 529  H0CAE   DB      ' CHECK!',13
 530  H0CB6   DB      '+------ MicroChess -------+',13
 531  H0CD2   DB      '!                         !',13
 532  H0CEE   DB      '+------ Challenger -------+',13
 533  H0D0A   DS      0               ** INPUT  BUFFER **
 534          ORG     START+0D7EH
 535  H0D7E   DS      4
 536          DS      0               ** STACK TOP **
 537          ORG     START+0DE6H
 538  H0DE6   DS      0
 539          ORG     START+0E00H
 540  RUBOUT  MOV     A,C
 541          CPI     0
 542          JZ      H0325
 543          DCR     C
 544          DCX     H
 545          MVI     A,07FH
 546          CALL    WH1
 547          JMP     H0325

Reconstructed routines are marked [R] with the 6502 routine they follow; [8080] marks routines the 8080 shell needs. Copyright 1976 Peter Jennings benlo.com, MIT License (in the header).

Listing 2 — CHESS8080, the restored 1977 edition, 1206 lines · download CHESS8080.ASM
   1  ; CHESS8080 - CHESS51, restored edition: missing routines
   2  ; reconstructed 2026-12-01 after the original Microchess
   3  ; algorithm; original transcription kept unchanged alongside.
   4  ;
   5  ; Source: tape CHESS51 (VER 0.51 02/24/79), an unfinished 8080
   6  ; transcription of MicroChess (P. Jennings, T. O'Brien, 1977).
   7  ; Every line of it is kept; changed lines end in ;was ...
   8  ; Routines marked [R] are reconstructed after the published
   9  ; 6502 MicroChess (P. Jennings 1976), as in the Apple I source
  10  ; listing (D. Rictor 2002 port): same algorithm, same tables,
  11  ; same weaknesses. No 8080 MicroChess listing was available.
  12  ; [8080] marks routines the 8080 shell needs that the 6502
  13  ; listing lacks (O-O entry, move text, check/mate test).
  14  ;
  15  ; Copyright 1976 Peter Jennings benlo.com
  16  ; MIT License (MicroChess derivation; 2026 additions too):
  17  ; Permission is hereby granted, free of charge, to any person
  18  ; obtaining a copy of this software and associated
  19  ; documentation files (the "Software"), to deal in the
  20  ; Software without restriction, including without limitation
  21  ; the rights to use, copy, modify, merge, publish, distribute,
  22  ; sublicense, and/or sell copies of the Software, and to
  23  ; permit persons to whom the Software is furnished to do so,
  24  ; subject to the following conditions:
  25  ; The above copyright notice and this permission notice shall
  26  ; be included in all copies or substantial portions of the
  27  ; Software.
  28  ; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
  29  ; KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  30  ; WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  31  ; PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  32  ; COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  33  ; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  34  ; OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  35  ; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  36  ;
  37  ;** CHESS **  VER 0.51  02/24/79
  38  ;
  39  CROUT   EQU     038DH
  40  ;
  41  START   LXI     SP,H0D7E+4
  42          CALL    CROUT
  43          LXI     H,H0B6D
  44          CALL    H01DA
  45          LXI     H,H0B93
  46          CALL    H01DA
  47          LXI     H,H0BB9
  48          CALL    H01DA
  49  H0018   CALL    CROUT
  50          CALL    H05AF
  51          LXI     H,H0A95
  52          SHLD    H0A7D
  53          LXI     H,H0ACB
  54          SHLD    H0A7F
  55          LXI     H,H0B01
  56          SHLD    H0A79
  57          LXI     H,H0B37
  58          SHLD    H0A7B
  59          XRA     A
  60          STA     H0A74
  61          STA     H0A78
  62          STA     H0A82
  63          STA     H0A81
  64          STA     H0A75
  65          STA     H0A76
  66          MVI     A,10H
  67          STA     H0A77
  68          MVI     A,0EEH
  69          STA     H0A4D
  70          STA     H0A4E
  71          LXI     H,H0BF5
  72          CALL    STRG
  73          CALL    WH0
  74          CALL    WH1
  75          MOV     A,B
  76          RRC
  77          JNC     H0072-3
  78          MVI     A,1
  79          STA     H0A82
  80          CALL    H05C3
  81          CALL    H0242
  82  H0072   CALL    CROUT
  83  H0075   LXI     SP,H0D7E+4
  84          LXI     H,H0DE6
  85          SHLD    H0A59
  86          LXI     H,2020H
  87          SHLD    H0C20
  88          LXI     H,H0C10
  89          CALL    STRG
  90          CALL    H0320
  91          CALL    CROUT
  92          LXI     H,H0D0A
  93          MOV     A,M
  94          CPI     'G'
  95          JZ      H00D7
  96          CPI     'D'
  97          JZ      H0342
  98          CPI     'E'
  99          JZ      H022C
 100          CPI     'S'
 101          JZ      H01E1
 102          CPI     'O'
 103          JZ      H03D1
 104          CPI     'R'
 105          JZ      H0220
 106          CPI     'A'
 107          JZ      H02F1
 108          CPI     'N'
 109          JZ      H0305
 110          CALL    H0168
 111          LDA     H0D0A+5
 112          CPI     'M'
 113          JZ      H0126
 114          CPI     '='
 115          JZ      H0348
 116          CPI     0DH
 117          JNZ     H012C
 118          CALL    H086D
 119  H00D4   CALL    H0242
 120  H00D7   CALL    H047D   ** G Command **
 121          LDA     H0A78   ;was H0075+3
 122          ORA     A
 123          JZ      H00F4
 124          LXI     H,204FH
 125          SHLD    H0C10+0EH
 126          LXI     H,4F20H
 127          SHLD    H0C10+0BH
 128          XRA     A
 129          STA     H0A78
 130          JMP     H0102
 131  H00F4   CALL    MVTXT   ;was TEMP
 132          CALL    CHKTST  ;was TEMP
 133          LDA     H0A4F
 134          CPI     0FFH
 135          JZ      H0138
 136  H0102   LXI     H,H0C10+6
 137          CALL    STRG
 138          LDA     H0A81
 139          CPI     0FFH
 140          JZ      H0317
 141          LDA     H0A74
 142          ORA     A
 143          JZ      H0120-3
 144  H0117   LXI     H,H0CAE
 145          CALL    STRG
 146          CALL    CROUT
 147  H0120   CALL    H0242
 148          JMP     H0075
 149  H0126   CALL    H086D   ** MOVE **
 150          JMP     H0075
 151  H012C   LXI     H,H0C23 ** Input error **
 152          CALL    STRG
 153          CALL    CROUT
 154          JMP     H0075
 155  H0138   LXI     H,H0C30 ** CHKMT YOU WIN **
 156          CALL    H01DA
 157  H013E   CALL    H0242
 158          CALL    CROUT
 159          LXI     H,H0C47
 160          CALL    STRG
 161          CALL    WH0
 162          CALL    WH1
 163          MOV     A,B
 164          CPI     'Y'
 165          JNZ     H01C8
 166          CALL    CROUT
 167          JMP     H0018
 168  STRG    MOV     A,M
 169          CPI     0DH
 170          RZ
 171          MOV     B,A
 172          CALL    WH1
 173          INX     H
 174          JMP     STRG
 175  H0168   LHLD    H0D0A
 176          CALL    H0199
 177          STA     H0A50
 178          LHLD    H0D0A+3
 179          CALL    H0199
 180          STA     H0A51
 181          STA     H0A4E
 182          LDA     H0A50
 183          LXI     H,H0A0C
 184          MVI     C,01FH
 185  H0185   CMP     M
 186          JZ      H0191
 187          DCX     H
 188          DCR     C
 189          JP      H0185
 190          JMP     H012C
 191  H0191   MOV     A,C
 192          STA     H0A4D
 193          STA     H0A4F
 194          RET
 195  H0199   MOV     A,L
 196          ANI     0FH
 197          RAL
 198          RAL
 199          RAL
 200          RAL
 201          MOV     B,A
 202          MOV     A,H
 203          ANI     0FH
 204          ORA     B
 205          MOV     B,A
 206          ANI     88H
 207          JNZ     H012C
 208          MOV     A,B
 209          RET
 210          ORG     START+01C8H
 211  H01C8   CALL    CROUT   ** End of game **
 212          CALL    CROUT
 213          LXI     H,H0C5B
 214          CALL    H01DA
 215          CALL    WH0
 216          JMP     0
 217  H01DA   CALL    STRG
 218          CALL    CROUT
 219          RET
 220  H01E1   CALL    CROUT
 221          LXI     H,H0BDF
 222          CALL    STRG
 223          CALL    WH0
 224          CALL    WH1
 225          MOV     A,B
 226          CPI     'S'
 227          JZ      H0203
 228          CPI     'B'
 229          JZ      H020A
 230          CPI     'N'
 231          JZ      H0211
 232          JMP     H012C
 233  H0203   MVI     B,0
 234          MVI     C,0FFH
 235          JMP     H0215
 236  H020A   MVI     B,0
 237          MVI     C,0FBH
 238          JMP     H0215
 239  H0211   MVI     B,8
 240          MVI     C,0FBH
 241  H0215   MOV     A,B
 242          STA     H071E
 243          MOV     A,C
 244          STA     H0861
 245          JMP     H0072
 246  H0220   CALL    CROUT   ** RESIGN **
 247          LXI     H,H0C7E
 248          CALL    STRG
 249          JMP     H013E
 250  H022C   CALL    H05C3   ** EXCHG **
 251          LDA     H0A82
 252          ORA     A
 253          JZ      H023A
 254          XRA     A
 255          JMP     H023C
 256  H023A   MVI     A,1
 257  H023C   STA     H0A82
 258          JMP     H0075
 259  H0242   CALL    CROUT
 260          CALL    CROUT
 261          MVI     D,0
 262          LXI     H,H0CB6
 263          CALL    H01DA
 264  H0250   MOV     A,D
 265          ORA     A
 266          JZ      H025B
 267          LXI     H,H0CD2
 268          NOP
 269          NOP
 270          NOP
 271  H025B   MVI     B,21H
 272          CALL    WH1
 273          MVI     B,20H
 274          CALL    WH1
 275  H0265   LXI     H,H0A0C
 276          MVI     C,1FH
 277  H026A   MOV     A,M
 278          CMP     D
 279          JZ      H02B8
 280          DCX     H
 281          DCR     C
 282          JP      H026A
 283          MOV     A,D
 284          ANI     0FH
 285          MOV     E,A
 286          MOV     A,D
 287          ANI     0F0H
 288          RRC
 289          RRC
 290          RRC
 291          RRC
 292          ADD     E
 293          RAR
 294          JC      H0289
 295          MVI     B,20H
 296          JMP     H028B
 297  H0289   MVI     B,3AH
 298  H028B   CALL    WH1
 299          CALL    WH1
 300  H0291   MVI     B,20H
 301          CALL    WH1
 302          INR     D
 303          MOV     A,D
 304          ANI     0FH
 305          CPI     8
 306          JNZ     H0265
 307          MVI     B,21H
 308          CALL    WH1
 309          CALL    CROUT
 310          MOV     A,D
 311          ADI     8
 312          MOV     D,A
 313          JP      H0250
 314          LXI     H,H0CEE
 315          CALL    H01DA
 316          CALL    CROUT
 317          RET
 318  H02B8   MOV     A,C
 319          CPI     10H
 320          JNC     H02D3
 321          LDA     H0A82
 322          ORA     A
 323          JNZ     H02CC
 324  H02C5   LDA     H0A83
 325          MOV     B,A
 326          JMP     H02DD
 327  H02CC   LDA     H0A84
 328          MOV     B,A
 329          JMP     H02DD
 330  H02D3   LDA     H0A82
 331          ORA     A
 332          JNZ     H02C5
 333          JMP     H02CC
 334  H02DD   CALL    WH1
 335          MOV     A,C
 336          ANI     0FH
 337          MOV     C,A
 338          MVI     B,0
 339          LXI     H,H0A85
 340          DAD     B
 341          MOV     B,M
 342          CALL    WH1
 343          JMP     H0291
 344  H02F1   MVI     A,0CDH  ** A Command **
 345          STA     H00D4
 346          STA     H0120
 347          LXI     H,H0242
 348          SHLD    H00D4+1
 349          SHLD    H0120+1
 350          JMP     H0072
 351  H0305   LXI     H,0     ** N Command **
 352          SHLD    H00D4
 353          SHLD    H00D4+1
 354          SHLD    H0120
 355          SHLD    H0120+1
 356          JMP     H0072
 357  H0317   LXI     H,H0C96
 358          CALL    STRG
 359          JMP     H013E
 360  H0320   LXI     H,H0D0A
 361          MVI     C,0
 362  H0325   CALL    WH0
 363          MOV     A,B
 364          MOV     M,A
 365          CPI     0DH
 366          JZ      H033C
 367          CPI     07FH
 368          JZ      RUBOUT
 369          CALL    WH1
 370          INX     H
 371          INR     C
 372          JMP     H0325
 373  H033C   XRA     A
 374          CMP     C
 375          JZ      H0325
 376          RET
 377  H0342   CALL    H0242   ** DISPLAY **
 378          JMP     H0075
 379  H0348   CALL    H0168
 380          LXI     H,H0A0C
 381          MVI     C,0FH
 382          LDA     H0A50
 383  H0353   CMP     M
 384          JZ      H035C
 385          DCX     H
 386          DCR     C
 387          JP      H0353
 388  H035C   MVI     M,0CCH
 389          LXI     H,H0A8C
 390          MVI     C,7
 391          LDA     H0D0A+6
 392  H0366   CMP     M
 393          JZ      H0372
 394          DCX     H
 395          DCR     C
 396          JP      H0366
 397          JMP     H012C
 398  H0372   LXI     H,H09FD
 399          MVI     B,0
 400          DAD     B
 401          MVI     A,0CCH
 402          CMP     M
 403          JZ      H0383
 404          DCX     H
 405          CMP     M
 406          JNZ     H012C
 407  H0383   LDA     H0A51
 408          MOV     M,A
 409          LDA     H0D0A+7
 410          CPI     4DH
 411          JZ      H0072
 412          CPI     0DH
 413          JZ      H00D4
 414          JMP     H012C
 415  ;***
 416          ORG     START+03D1H
 417  ;[8080] O command: O-O / O-O-O for the player (king+rook)
 418  H03D1   LDA     H09FD   ** O Command: O-O O-O-O **
 419          MOV     B,A
 420          ANI     0FH
 421          MVI     C,0FFH
 422          CPI     3
 423          JZ      H03D2
 424          MVI     C,1
 425  H03D2   LDA     H0D0A+3
 426          CPI     '-'
 427          MOV     A,B
 428          JNZ     H03D4
 429          MOV     A,C
 430          CMA
 431          INR     A
 432          MOV     C,A
 433          MOV     A,B
 434          ADD     C
 435  H03D4   ADD     C
 436          ADD     C
 437          ADD     C
 438          LXI     H,H09FF
 439          MVI     D,18
 440          CMP     M
 441          JZ      H03D5
 442          INX     H
 443          INR     D
 444          CMP     M
 445          JNZ     H012C
 446  H03D5   MOV     A,D
 447          STA     H0A4D
 448          MOV     A,B
 449          ADD     C
 450          STA     H0A4E
 451          PUSH    B
 452          CALL    H086D
 453          POP     B
 454          MVI     A,16
 455          STA     H0A4D
 456          MOV     A,B
 457          ADD     C
 458          ADD     C
 459          STA     H0A4E
 460          STA     H0A51
 461          CALL    H086D
 462          JMP     H00D4
 463  ;[8080] MVTXT: best move into 'MC : FF-TT' (was TEMP)
 464  MVTXT   LXI     H,H0C10+0BH     ** move to text **
 465          LDA     H0A50
 466          CALL    HEXSQ
 467          MVI     M,'-'
 468          INX     H
 469          LDA     H0A51
 470  HEXSQ   MOV     B,A
 471          RRC
 472          RRC
 473          RRC
 474          RRC
 475          CALL    HEXD
 476          MOV     A,B
 477  HEXD    ANI     0FH
 478          ADI     '0'
 479          MOV     M,A
 480          INX     H
 481          RET
 482  ;
 483          ORG     START+047DH
 484  ;[R] GO: book, then STATE C and STATE 4 passes (6502 GO)
 485  H047D   LHLD    H0A7F   ** GO **
 486          MOV     A,H
 487          ORA     L
 488          JZ      NOOPEN
 489          LDA     H0A82
 490          ORA     A
 491          JNZ     ENDBK
 492          LDA     H0A4E
 493          CMP     M
 494          JNZ     ENDBK
 495          INX     H
 496          MOV     A,M
 497          STA     H0A4F
 498          INX     H
 499          MOV     A,M
 500          STA     H0A51
 501          INX     H
 502          SHLD    H0A7F
 503          MOV     A,M
 504          CPI     99H
 505          JNZ     MV2
 506  ENDBK   LXI     H,0
 507          SHLD    H0A7F
 508  NOOPEN  MVI     A,0CH
 509          STA     H0A54
 510          STA     H0A50
 511          MVI     C,14H
 512          CALL    GNMX
 513          MVI     A,4
 514          STA     H0A54
 515          CALL    GNMZ
 516          LDA     H0A50
 517          CPI     0FH
 518          JC      MATE
 519  MV2     LDA     H0A4F
 520          STA     H0A4D
 521          MOV     E,A
 522          MVI     D,0
 523          LXI     H,H09ED
 524          DAD     D
 525          MOV     A,M
 526          STA     H0A50
 527          LDA     H0A51
 528          STA     H0A4E
 529          CALL    H086D
 530          LDA     H0A4F
 531          ORA     A
 532          RNZ
 533          LDA     H0A50
 534          MOV     B,A
 535          LDA     H0A51
 536          SUB     B
 537          CPI     0FEH
 538          RNZ
 539          MVI     A,2
 540          STA     H0A4D
 541          STA     H0A4E
 542          CALL    H086D
 543          MVI     A,1
 544          STA     H0A78
 545          RET
 546  ;[R] MATE: no move worth 0FH: resign (6502 MATE)
 547  MATE    MVI     A,0FFH
 548          STA     H0A4F
 549          STA     H0A50
 550          STA     H0A51
 551          RET
 552  ;[R] STRATGY: weighted counts (6502 STRATGY, same sums)
 553  STRATG  MVI     A,80H   ** STRATGY **
 554          LXI     H,H0A6A
 555          ADD     M
 556          INX     H
 557          ADC     M
 558          INX     H
 559          ADC     M
 560          LXI     H,H0A60
 561          ADC     M
 562          LXI     H,H0A5E
 563          ADC     M
 564          LXI     H,H0A6F
 565          SUB     M
 566          INX     H
 567          SBB     M
 568          LXI     H,H0A61
 569          SBB     M
 570          LXI     H,H0A5F
 571          SBB     M
 572          LXI     H,H0A5D
 573          SBB     M
 574          LXI     H,H0A6E
 575          SBB     M
 576          LXI     H,H0A62
 577          SBB     M
 578          JNC     POS
 579          XRA     A
 580  POS     ORA     A
 581          RAR
 582          ADI     40H
 583          LXI     H,H0A6B
 584          ADC     M
 585          INX     H
 586          ADC     M
 587          LXI     H,H0A63
 588          SUB     M
 589          ORA     A
 590          RAR
 591          ADI     90H
 592          LXI     H,H0A5C
 593          ADC     M
 594          ADC     M
 595          ADC     M
 596          ADC     M
 597          LXI     H,H0A60
 598          ADC     M
 599          LXI     H,H0A63
 600          SUB     M
 601          SBB     M
 602          INX     H
 603          SBB     M
 604          SBB     M
 605          LXI     H,H0A5F
 606          SBB     M
 607          MOV     B,A
 608          LDA     H0A4E
 609          CPI     33H
 610          JZ      POSN
 611          CPI     34H
 612          JZ      POSN
 613          CPI     22H
 614          JZ      POSN
 615          CPI     25H
 616          JZ      POSN
 617          LDA     H0A4D
 618          ORA     A
 619          JZ      NOPOSN
 620          MOV     E,A
 621          MVI     D,0
 622          LXI     H,H09ED
 623          DAD     D
 624          MOV     A,M
 625          CPI     10H
 626          JNC     NOPOSN
 627  POSN    INR     B
 628          INR     B
 629  NOPOSN  JMP     CKMATE
 630  ;
 631          ORG     START+05AFH
 632  H05AF   LXI     H,H0A0D
 633          LXI     D,H09ED
 634          MVI     C,20H
 635  H05B7   MOV     A,M
 636          STAX    D
 637          INX     H
 638          INX     D
 639          DCR     C
 640          JNZ     H05B7
 641          RET
 642  H05C0   CALL    H05AF
 643  H05C3   LXI     H,H09ED
 644          LXI     D,H09FD
 645          MVI     C,10H
 646  H05CB   MVI     A,77H
 647          SUB     M
 648          MOV     B,A
 649          XCHG
 650          MVI     A,77H
 651          SUB     M
 652          MOV     M,B
 653          XCHG
 654          MOV     M,A
 655          INX     H
 656          INX     D
 657          DCR     C
 658          JNZ     H05CB
 659          RET
 660  ;
 661          ORG     START+05DDH
 662  ;[R] JANUS/COUNTS: what follows each move (6502 JANUS)
 663  JANUS   LDA     H0A54   ** JANUS **
 664          ORA     A
 665          JM      NOCNT
 666          CPI     7
 667          JNZ     COUNTS
 668          LXI     H,H0A75
 669          INR     M
 670          RET
 671  COUNTS  MOV     C,A
 672          LDA     H0A4D
 673          ORA     A
 674          JZ      OVER
 675          MOV     A,C
 676          CPI     8
 677          JNZ     OVER
 678          LDA     H0A65
 679          MOV     B,A
 680          LDA     H0A4D
 681          CMP     B
 682          RZ
 683  OVER    MVI     B,0
 684          LXI     H,H0A62
 685          DAD     B
 686          INR     M
 687          LDA     H0A4D
 688          CPI     1
 689          JNZ     NOQ
 690          INR     M
 691  NOQ     LDA     H0A52
 692          ORA     A
 693          JZ      NOCAP
 694          LDA     H0A4E
 695          LXI     H,H0A0C
 696          MVI     E,0FH
 697  ELOOP   CMP     M
 698          JZ      FOUN
 699          DCX     H
 700          DCR     E
 701          JP      ELOOP
 702  FOUN    MVI     D,0
 703          LXI     H,H0A3D
 704          DAD     D
 705          MOV     A,M
 706          LXI     H,H0A63
 707          DAD     B
 708          CMP     M
 709          JC      LESS
 710          MOV     M,A
 711          INX     H
 712          INX     H
 713          MOV     M,E
 714  LESS    LXI     H,H0A64
 715          DAD     B
 716          ADD     M
 717          MOV     M,A
 718  NOCAP   MOV     A,C
 719          CPI     4
 720          JZ      ON4
 721          JC      TREE
 722          RET
 723  ;[R] NOCOUNT: king capture test for CHKCHK (6502)
 724  NOCNT   CPI     0F9H
 725          JNZ     TREE
 726          LDA     H09FD
 727          MOV     B,A
 728          LDA     H0A4E
 729          CMP     B
 730          RNZ
 731          XRA     A
 732          STA     H0A53
 733          RET
 734  ;[R] ON4: replies and continuation (6502 ON4)
 735  ON4     LDA     H0A67   ** ON4 **
 736          STA     H0A5C
 737          XRA     A
 738          STA     H0A54
 739          CALL    H086D
 740          CALL    H05C3
 741          CALL    GNMZ
 742          CALL    H05C3
 743          JMP     ON4B
 744  ;[R] GNMZ/GNMX/GNM: all moves of one side (6502 GNM)
 745  GNMZ    MVI     C,10H   ** GNM **
 746  GNMX    XRA     A
 747          LXI     H,H0A5D
 748  CLEAR   MOV     M,A
 749          INX     H
 750          DCR     C
 751          JP      CLEAR
 752  GNM     MVI     A,10H
 753          STA     H0A4D
 754  NEWP    LXI     H,H0A4D
 755          DCR     M
 756          RM
 757          CALL    RESET
 758          MVI     A,8
 759          STA     H0A55
 760          LDA     H0A4D
 761          CPI     8
 762          JNC     PAWN
 763          CPI     6
 764          JNC     KNIGHT
 765          CPI     4
 766          JNC     BISHOP
 767          CPI     1
 768          JZ      QUEEN
 769          JNC     ROOK
 770  KING    CALL    SNGMV
 771          JNZ     KING
 772          JMP     NEWP
 773  QUEEN   CALL    LINE
 774          JNZ     QUEEN
 775          JMP     NEWP
 776  ROOK    MVI     A,4
 777          STA     H0A55
 778  AGNR    CALL    LINE
 779          JNZ     AGNR
 780          JMP     NEWP
 781  BISHOP  CALL    LINE
 782          LDA     H0A55
 783          CPI     4
 784          JNZ     BISHOP
 785          JMP     NEWP
 786  KNIGHT  MVI     A,10H
 787          STA     H0A55
 788  AGNN    CALL    SNGMV
 789          LDA     H0A55
 790          CPI     8
 791          JNZ     AGNN
 792          JMP     NEWP
 793          ORG     START+071DH
 794  ;[R] ON4 (cont.); operand 071EH set by S (KIM levels)
 795  ON4B    MVI     A,08H   ;S command: 0 or 8
 796  H071E   EQU     START+071EH
 797          ORA     A
 798          JZ      ON4C
 799          STA     H0A54
 800          CALL    GNM
 801  ON4C    CALL    UMOVE
 802          JMP     STRATG
 803  ;[R] PAWN: captures, step, double step (6502 PAWN)
 804  PAWN    MVI     A,6
 805          STA     H0A55
 806  P1      CALL    CMOVE
 807          JM      P2
 808          LDA     H0A52
 809          ORA     A
 810          CNZ     JANUS
 811  P2      CALL    RESET
 812          LXI     H,H0A55
 813          DCR     M
 814          MOV     A,M
 815          CPI     5
 816          JZ      P1
 817  P3      CALL    CMOVE
 818          JM      NEWP
 819          LDA     H0A52
 820          ORA     A
 821          JNZ     NEWP
 822          CALL    JANUS
 823          LDA     H0A4E
 824          ANI     0F0H
 825          CPI     20H
 826          JZ      P3
 827          JMP     NEWP
 828  ;[R] SNGMV: one-step moves for K, N (6502 SNGMV)
 829  SNGMV   CALL    CMOVE
 830          JM      ILL1
 831          CALL    JANUS
 832  ILL1    CALL    RESET
 833          LXI     H,H0A55
 834          DCR     M
 835          RET
 836  ;[R] LINE: sliding moves for Q, R, B (6502 LINE)
 837  LINE    CALL    CMOVE
 838          JNC     OVL
 839          LDA     H0A52
 840          ORA     A
 841          JZ      LINE
 842          JMP     ILL
 843  OVL     JM      ILL
 844          LDA     H0A52
 845          PUSH    PSW
 846          CALL    JANUS
 847          POP     PSW
 848          ORA     A
 849          JZ      LINE
 850  ILL     CALL    RESET
 851          LXI     H,H0A55
 852          DCR     M
 853          RET
 854  ;[R] TREE: capture exchanges (6502 TREE)
 855  TREE    LDA     H0A52   ** TREE **
 856          ORA     A
 857          RZ
 858          LDA     H0A4E
 859          LXI     H,H0A04
 860          MVI     E,7
 861  LOOPX   CMP     M
 862          JZ      FOUNX
 863          DCX     H
 864          DCR     E
 865          RZ
 866          JMP     LOOPX
 867  FOUNX   MVI     D,0
 868          LXI     H,H0A3D
 869          DAD     D
 870          MOV     B,M
 871          LDA     H0A54
 872          MOV     E,A
 873          ORA     A
 874          JP      TREE1
 875          MVI     D,0FFH
 876  TREE1   LXI     H,H0A61
 877          DAD     D
 878          MOV     A,B
 879          CMP     M
 880          JC      NOMAX
 881          MOV     M,A
 882  NOMAX   LXI     H,H0A54
 883          DCR     M
 884          JMP     TREE2
 885  ;[R] CKMATE/RETV/PUSH: value, keep best (6502 CKMATE)
 886  CKMATE  LDA     H0A63   ** CKMATE **
 887          LXI     H,H0A3D
 888          CMP     M
 889          JNZ     NOCHEK
 890          XRA     A
 891          JMP     RETV
 892  NOCHEK  MOV     A,B
 893          LXI     H,H0A62
 894          MOV     C,M
 895          INR     C
 896          DCR     C
 897          JNZ     RETV
 898          LXI     H,H0A6D
 899          MOV     C,M
 900          INR     C
 901          DCR     C
 902          JNZ     RETV
 903          MVI     A,0FFH
 904  RETV    MVI     B,4
 905          LXI     H,H0A54
 906          MOV     M,B
 907          LXI     H,H0A50
 908          CMP     M
 909          RC
 910          RZ
 911          MOV     M,A
 912          LDA     H0A4D
 913          STA     H0A4F
 914          LDA     H0A4E
 915          STA     H0A51
 916          RET
 917          ORG     START+0860H
 918  ;[R] TREE (cont.); operand 0861H set by S (KIM levels)
 919  TREE2   MVI     A,0FBH  ;S command: FF or FB
 920  H0861   EQU     START+0861H
 921          CMP     M
 922          CNZ     GENRM
 923          LXI     H,H0A54
 924          INR     M
 925          RET
 926  ;
 927          ORG     START+086DH
 928  H086D   LXI     H,0
 929          DAD     SP
 930          SHLD    H0A57
 931          LHLD    H0A59
 932          SPHL
 933          LDA     H0A4E
 934          MOV     B,A
 935          MVI     C,01FH
 936          LXI     H,H0A0C
 937  H0881   CMP     M
 938          JZ      H088A
 939          DCX     H
 940          DCR     C
 941          JP      H0881
 942  H088A   MVI     M,0CCH
 943          PUSH    H
 944          LXI     H,H09ED
 945          MVI     D,0
 946          LDA     H0A4D
 947          MOV     E,A
 948          DAD     D
 949          PUSH    H
 950          MOV     C,M
 951          MOV     M,B
 952          PUSH    B
 953          LXI     H,H0A55
 954          MOV     D,M
 955          PUSH    D
 956          LXI     H,0
 957          DAD     SP
 958          SHLD    H0A59
 959          LHLD    H0A57
 960          SPHL
 961          RET
 962  ;
 963  ;[R] CMOVE+CHKCHK: next square, legality (6502, J. Butterfield)
 964  CMOVE   LDA     H0A55   ** CMOVE **
 965          MOV     E,A
 966          MVI     D,0
 967          LXI     H,H0A2C
 968          DAD     D
 969          LDA     H0A4E
 970          ADD     M
 971          STA     H0A4E
 972          ANI     88H
 973          JNZ     ILLEGL
 974          LDA     H0A4E
 975          LXI     H,H0A0C
 976          MVI     C,20H
 977  CMLOOP  DCR     C
 978          JM      CMNO
 979          CMP     M
 980          DCX     H
 981          JNZ     CMLOOP
 982          MOV     A,C
 983          CPI     10H
 984          JC      ILLEGL
 985          MVI     A,1
 986          JMP     SPX
 987  CMNO    XRA     A
 988  SPX     STA     H0A52
 989          LDA     H0A54
 990          ORA     A
 991          JM      RETL
 992          CPI     8
 993          JNC     RETL
 994          LDA     H0A52   ** CHKCHK **
 995          PUSH    PSW
 996          LDA     H0A54
 997          PUSH    PSW
 998          MVI     A,0F9H
 999          STA     H0A54
1000          STA     H0A53
1001          CALL    H086D
1002          CALL    H05C3
1003          CALL    GNM
1004          CALL    RUM
1005          POP     PSW
1006          STA     H0A54
1007          POP     PSW
1008          STA     H0A52
1009          LDA     H0A53
1010          ORA     A
1011          JM      RETL
1012          MVI     A,0FFH
1013          ORA     A
1014          STC
1015          RET
1016  RETL    XRA     A
1017          RET
1018  ILLEGL  XRA     A
1019          STA     H0A52
1020          DCR     A
1021          ORA     A
1022          RET
1023  ;[R] RESET: piece back to its square (6502 RESET)
1024  RESET   LDA     H0A4D   ** RESET **
1025          MOV     E,A
1026          MVI     D,0
1027          LXI     H,H09ED
1028          DAD     D
1029          MOV     A,M
1030          STA     H0A4E
1031          RET
1032  ;[R] GENRM/RUM/UMOVE: unmake from 2nd stack (6502)
1033  GENRM   CALL    H086D   ** GENRM **
1034          CALL    H05C3
1035          CALL    GNM
1036  RUM     CALL    H05C3
1037  UMOVE   LXI     H,0     ** UMOVE **
1038          DAD     SP
1039          SHLD    H0A57
1040          LHLD    H0A59
1041          SPHL
1042          POP     D
1043          MOV     A,D
1044          STA     H0A55
1045          POP     B
1046          POP     H
1047          MOV     M,C
1048          MOV     A,L
1049          SUI     0EDH
1050          STA     H0A4D
1051          POP     H
1052          MOV     M,B
1053          MOV     A,B
1054          STA     H0A4E
1055          LXI     H,0
1056          DAD     SP
1057          SHLD    H0A59
1058          LHLD    H0A57
1059          SPHL
1060          RET
1061  ;[8080] CHKTST: CHECK! and CHECKMATE - I WIN (was TEMP)
1062  CHKTST  XRA     A       ** check, mate? **
1063          STA     H0A74
1064          MVI     A,0F9H
1065          STA     H0A54
1066          STA     H0A53
1067          CALL    GNM
1068          LDA     H0A53
1069          ORA     A
1070          JNZ     CHKT2
1071          INR     A
1072          STA     H0A74
1073          CALL    H05C3
1074          XRA     A
1075          STA     H0A75
1076          MVI     A,7
1077          STA     H0A54
1078          CALL    GNM
1079          CALL    H05C3
1080          LDA     H0A75
1081          ORA     A
1082          JNZ     CHKT2
1083          DCR     A
1084          STA     H0A81
1085  CHKT2   MVI     A,4
1086          STA     H0A54
1087          RET
1088  ;
1089          ORG     START+09BFH
1090  WH1     EQU     $
1091  H09BF   MOV     A,B
1092          JMP     0C24H
1093  WH0     EQU     $
1094  H09C9   CALL    0C20H
1095          ANI     7FH
1096          CPI     07FH
1097          JZ      WH0END
1098          CPI     60H
1099          JC      WH0END
1100          SUI     20H
1101  WH0END  MOV     B,A
1102          RET
1103          ORG     START+09DDH
1104          DB      '34',0,0,0,0,0,0,0,0,0,0,0,0,0,0CCH
1105  H09ED   DB      4,3,7,0,5,2,6,1,17H,10H,16H,11H,15H,12H,13H,14H
1106  H09FD   DB      'tswpurvqg',60H,'faebc'
1107  H0A0C   DB      'd'
1108  H0A0D   DB      3,4,0,7,2,5,1,6,10H,17H,11H,16H,12H,15H,14H,13H
1109          DB      'stpwruqv',60H,'gafbedc'
1110          DB      0F0H,0FFH,1,10H,11H,0FH,0EFH,0F1H,0DFH,0E1H
1111          DB      0EEH,0F2H,12H,0EH,1FH,21H,0BH,0AH,6,6,4,4
1112          DB      4,4,2,2,2,2,2,2,2,2
1113  H0A4D   DB      0EEH
1114  H0A4E   DB      0EEH
1115  H0A4F   DB      0FH
1116  H0A50   DB      14H
1117  H0A51   DB      34H,0,0,4
1118  H0A55   DB      0,0
1119  H0A57   DW      H0D7E
1120  H0A59   DW      H0DE6
1121          DB      0CDH,0,0,0,0,0,0,15H,0,0,0,0
1122          DB      0,0,0,16H,0,0,0,14H,0,0,0,0,0
1123  H0A74   DB      0
1124  H0A75   DB      0
1125  H0A76   DB      0
1126  H0A77   DB      10H
1127  H0A78   DB      0
1128  H0A79   DB      1,0BH
1129  H0A7B   DB      37H,0BH
1130  H0A7D   DB      095H,0AH
1131  H0A7F   DB      0CBH,0AH
1132  H0A81   DB      0
1133  H0A82   DB      1
1134  H0A83   DB      'W'
1135  H0A84   DB      'B'
1136  H0A85   DB      'KQRRBBN'
1137  H0A8C   DB      'NPPPPPPPP'
1138  H0A95   DB      0EEH,01FH
1139          ORG     START+0ACBH
1140  ;[R] book: the published MicroChess opening (Giuoco Piano),
1141  ;    stored forward; EE = new game (H0018 sets EE)
1142  H0ACB   DB      0EEH,0FH,33H,43H,06H,22H,55H,04H,35H
1143          DB      45H,0DH,25H,52H,0EH,34H,34H,0DH,34H
1144          DB      36H,07H,25H,33H,00H,01H,25H,0BH,25H,99H
1145          ORG     START+0B01H
1146  H0B01   DS      0
1147          ORG     START+0B37H
1148  H0B37   DS      0
1149          ORG     START+0B6DH
1150  H0B6D   DB      0CH,'MicroChess                 (C) 1977.',13
1151  H0B93   DB      'Written by: P. Jennings & T. O',27H,'Brien.',13
1152  H0BB9   DB      '-------------------------------------',13
1153  H0BDF   DB      'Which mode ? (S,B,N) ',13
1154  H0BF5   DB      'Do you want WHITE ? (Y,N) ',13
1155  H0C10   DB      'CMD: ',13
1156          DB      'MC : 14-34'
1157  H0C20   DB      '  ',13
1158  H0C23   DB      'Input error.',13
1159  H0C30   DB      'CHECKMATE - YOU WIN!!!',13
1160  H0C47   DB      'Play again ? (Y,N) ',13
1161  H0C5B   DB      'Thanks for the game... MicroChess.',13
1162  H0C7E   DB      'You resigned - I WIN!!!',13
1163  H0C96   DB      '  CHECKMATE - I WIN!!!!',13
1164  H0CAE   DB      ' CHECK!',13
1165  H0CB6   DB      '+------ MicroChess -------+',13
1166  H0CD2   DB      '!                         !',13
1167  H0CEE   DB      '+------ Challenger -------+',13
1168  H0D0A   DS      0               ** INPUT  BUFFER **
1169          ORG     START+0D7EH
1170  H0D7E   DS      4
1171          DS      0               ** STACK TOP **
1172          ORG     START+0DE6H
1173  H0DE6   DS      0
1174          ORG     START+0E00H
1175  RUBOUT  MOV     A,C
1176          CPI     0
1177          JZ      H0325
1178          DCR     C
1179          DCX     H
1180          MVI     A,07FH
1181          CALL    WH1
1182          JMP     H0325
1183  ;Work cells inside the 1979 data block, by address
1184  H09FF   EQU     START+09FFH
1185  H0A04   EQU     START+0A04H
1186  H0A2C   EQU     START+0A2CH
1187  H0A3D   EQU     START+0A3DH
1188  H0A52   EQU     START+0A52H
1189  H0A53   EQU     START+0A53H
1190  H0A54   EQU     START+0A54H
1191  H0A5C   EQU     START+0A5CH
1192  H0A5D   EQU     START+0A5DH
1193  H0A5E   EQU     START+0A5EH
1194  H0A5F   EQU     START+0A5FH
1195  H0A60   EQU     START+0A60H
1196  H0A61   EQU     START+0A61H
1197  H0A62   EQU     START+0A62H
1198  H0A63   EQU     START+0A63H
1199  H0A64   EQU     START+0A64H
1200  H0A65   EQU     START+0A65H
1201  H0A67   EQU     START+0A67H
1202  H0A6A   EQU     START+0A6AH
1203  H0A6B   EQU     START+0A6BH
1204  H0A6D   EQU     START+0A6DH
1205  H0A6E   EQU     START+0A6EH
1206  H0A6F   EQU     START+0A6FH

New 8080 code of 2026; the 1979 routines it keeps are marked KEPT, the reworked ones CHANGED. Piece-square values after T. Michniewski. Copyright 1976 Peter Jennings benlo.com, MIT License (in the header).

Listing 3 — CHESS8080-2026, the enhanced edition, 3602 lines · download CHESS8080-2026.ASM
   1  ; CHESS8080-2026 - CHESS51, completed edition 2026-12-01: move
   2  ; search finished and modern search added (alpha-beta, move
   3  ; ordering, ...). Original 1970s port kept unchanged alongside.
   4  ; Copyright 1976 Peter Jennings benlo.com
   5  ; MIT License (MicroChess derivation; 2026 additions too):
   6  ; Permission is hereby granted, free of charge, to any person
   7  ; obtaining a copy of this software and associated
   8  ; documentation files (the "Software"), to deal in the
   9  ; Software without restriction, including without limitation
  10  ; the rights to use, copy, modify, merge, publish, distribute,
  11  ; sublicense, and/or sell copies of the Software, and to
  12  ; permit persons to whom the Software is furnished to do so,
  13  ; subject to the following conditions:
  14  ; The above copyright notice and this permission notice shall
  15  ; be included in all copies or substantial portions of the
  16  ; Software.
  17  ; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
  18  ; KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  19  ; WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  20  ; PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  21  ; COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22  ; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  23  ; OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  24  ; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25  ;
  26  ;** CHESS **  VER 0.51  02/24/79
  27  ;
  28  ; The 1979 tape holds an unfinished 8080
  29  ; port of MicroChess (1977): title, command loop, board
  30  ; display and move entry are there; the move generator and
  31  ; the search (GO, H047D) are not. This edition completes it.
  32  ; Every routine is listed in CHANGES.TXT: KEPT (as in 1979),
  33  ; CHANGED (1979 routine, new insides) or NEW (2026).
  34  ;
  35  ; 2026 enhancements (marked ";2026" below):
  36  ;  - legal chess: castling, en passant, all promotions,
  37  ;    check, checkmate, stalemate, 50-move rule, repetition
  38  ;  - alpha-beta search (negamax) with iterative deepening,
  39  ;    a time limit per move (S/B/N = 5/15/45 seconds),
  40  ;    quiescence search of captures, check extension
  41  ;  - futility pruning of quiet moves one ply from the leaves
  42  ;  - move ordering: best move of the last iteration first,
  43  ;    captures by MVV-LVA, two killer moves per ply
  44  ;  - evaluation: material plus piece-square tables
  45  ;  - a small opening book (main lines, both colours)
  46  ;  - commands B (take back), F (set up FEN), P (perft),
  47  ;    H (help); algebraic entry (e2e4) besides 64-44
  48  ;
  49  ; Sources: MicroChess by P. Jennings (1976), the published
  50  ; algorithm and Apple I source listing (piece tables, the
  51  ; MOVEX directions, the S/B/N modes); piece-square values
  52  ; from T. Michniewski, Simplified Evaluation Function
  53  ; (chessprogramming wiki). The code is new 8080 code.
  54  ;
  55  ; Memory: program 2000H-3FFFH (tape), work area 4000H-5FFFH.
  56  ; Runs on a 16K, 32K or 48K Poly-88. Start: 2000H.
  57  ;
  58  CROUT   EQU     038DH           ;monitor: new line (1979)
  59  TIMER   EQU     0C00H           ;monitor: 60 Hz tick count
  60  ;
  61  ; work area (not on tape), 2026
  62  RAM     EQU     4000H
  63  BRD     EQU     RAM             ;board: [sq] piece, [sq+8] slot
  64  BRDH    EQU     40H
  65  DIRT    EQU     RAM+100H        ;line direction of a difference
  66  DIRTH   EQU     41H
  67  PLIST   EQU     RAM+200H        ;32 slots: square or 0CCH
  68  PLISTH  EQU     42H
  69  STM     EQU     RAM+220H        ;side to move: 0 white, 8 black
  70  CASTL   EQU     RAM+221H        ;1 W O-O 2 W O-O-O 4 B O-O 8 B O-O-O
  71  EPSQ    EQU     RAM+222H        ;en passant square or 0CCH
  72  HMC     EQU     RAM+223H        ;half moves since capture/pawn
  73  SCORE   EQU     RAM+224H        ;material+tables, white's view
  74  POSLEN  EQU     38              ;PLIST..SCORE+1
  75  SNAP    EQU     RAM+300H        ;start position: board + block
  76  VARS    EQU     RAM+440H
  77  GFROM   EQU     VARS            ;generator: from square
  78  GCODE   EQU     VARS+1          ;generator: piece
  79  CAPONL  EQU     VARS+2          ;1: captures and queening only
  80  MVPUT   EQU     VARS+3          ;next free move entry
  81  UNDOP   EQU     VARS+5          ;next free undo record
  82  KIL1    EQU     VARS+7          ;killers of this ply (from,to)
  83  KIL2    EQU     VARS+9
  84  ATBY    EQU     VARS+11         ;attacking colour
  85  AKCNT   EQU     VARS+12
  86  AKDIR   EQU     VARS+13
  87  ALPHA   EQU     VARS+14         ;search window (biased)
  88  BETA    EQU     VARS+16
  89  DEPTH   EQU     VARS+18         ;remaining depth
  90  LEGAL   EQU     VARS+19         ;legal moves tried (with DEPTH)
  91  INCHK   EQU     VARS+20         ;1 in check, +80H rest unsorted
  92  PLY     EQU     VARS+21         ;(with INCHK)
  93  MVCUR   EQU     VARS+22         ;current move entry
  94  MVHI    EQU     VARS+24         ;end of this node's moves
  95  NODES   EQU     VARS+26         ;4 bytes
  96  TSTART  EQU     VARS+30
  97  TLIMIT  EQU     VARS+32
  98  ABORT   EQU     VARS+34
  99  ENDG    EQU     VARS+35         ;king table: 08H middle 80H end
 100  MFROM   EQU     VARS+36         ;MAKE: from (8 bytes saved)
 101  MTO     EQU     VARS+37
 102  MFLAG   EQU     VARS+38
 103  MPC     EQU     VARS+39         ;moving piece
 104  MSLOT   EQU     VARS+40
 105  MCAP    EQU     VARS+41         ;captured piece or 0
 106  MCSL    EQU     VARS+42
 107  MCSQ    EQU     VARS+43
 108  MTMP    EQU     VARS+44
 109  PKBEST  EQU     VARS+45
 110  GCRT    EQU     VARS+47
 111  GCBS    EQU     VARS+48
 112  RMLO    EQU     VARS+49         ;root moves
 113  RMHI    EQU     VARS+51
 114  RIDX    EQU     VARS+53
 115  RBI     EQU     VARS+55
 116  RALPHA  EQU     VARS+57
 117  CDEP    EQU     VARS+59
 118  RBEST   EQU     VARS+60         ;chosen move (from,to,flag)
 119  RSC     EQU     VARS+64         ;its score
 120  RDEP    EQU     VARS+66         ;depth completed (0 book)
 121  RKIND   EQU     VARS+67         ;0 search 1 book 2 only move
 122  HUMAN   EQU     VARS+68         ;human's colour (board view)
 123  AUTO    EQU     VARS+69         ;show board after moves
 124  MODE    EQU     VARS+70         ;ticks per move (2)
 125  NPLY    EQU     VARS+72         ;moves in GAME (2)
 126  BOOKOK  EQU     VARS+74         ;game began at the start
 127  PCNT    EQU     VARS+75         ;perft count (4)
 128  INP     EQU     VARS+79         ;parser pointer (2)
 129  PFROM   EQU     VARS+81
 130  PTO     EQU     VARS+82
 131  PPRO    EQU     VARS+83
 132  PSUF    EQU     VARS+84
 133  XMASK   EQU     VARS+85         ;display <-> board squares
 134  TMPW    EQU     VARS+86         ;2
 135  DIGF    EQU     VARS+88
 136  NCAND   EQU     VARS+89
 137  CAND    EQU     VARS+90         ;16 book candidates (2 each)
 138  RAWIN   EQU     VARS+122
 139  RLAST   EQU     VARS+123        ;1: last iteration not complete
 140  SPSAV   EQU     VARS+124        ;2
 141  FUTV    EQU     VARS+126        ;futility bound (2)
 142  FUTON   EQU     VARS+128
 143  RTIME   EQU     VARS+129        ;think time in ticks (2)
 144  INBUF   EQU     RAM+500H        ;input line (1979: H0D0A)
 145  KILLS   EQU     RAM+580H        ;killers, 4 bytes a ply
 146  GAME    EQU     RAM+680H        ;moves played: from,to,flag
 147  GKEYS   EQU     RAM+0B40H       ;position keys of the game (2)
 148  UNDO    EQU     RAM+0E00H       ;undo records, 16 bytes each
 149  MVSTK   EQU     RAM+1100H       ;move entries: from,to,flag,score
 150  MVLIM   EQU     RAM+1B00H       ;no new node above this
 151  STKTOP  EQU     RAM+2000H       ;stack, down to RAM+1C00H
 152  MAXPLY  EQU     40
 153  MAXNP   EQU     400             ;game length limit (plies)
 154  LOWB    EQU     0AD0H           ;-30000 biased
 155  HIGHB   EQU     0F530H          ;+30000 biased
 156  MATEL   EQU     64A8H           ;mated (-7000 biased) + ply
 157  ;
 158  ; squares (rank 1 = 0, file a = 0), for the opening book
 159  A1      EQU     00H
 160  B1      EQU     01H
 161  C1      EQU     02H
 162  D1      EQU     03H
 163  E1      EQU     04H
 164  F1      EQU     05H
 165  G1      EQU     06H
 166  H1      EQU     07H
 167  A2      EQU     10H
 168  B2      EQU     11H
 169  C2      EQU     12H
 170  D2      EQU     13H
 171  E2      EQU     14H
 172  F2      EQU     15H
 173  G2      EQU     16H
 174  H2      EQU     17H
 175  A3      EQU     20H
 176  B3      EQU     21H
 177  C3      EQU     22H
 178  D3      EQU     23H
 179  E3      EQU     24H
 180  F3      EQU     25H
 181  G3      EQU     26H
 182  H3      EQU     27H
 183  A4      EQU     30H
 184  B4      EQU     31H
 185  C4      EQU     32H
 186  D4      EQU     33H
 187  E4      EQU     34H
 188  F4      EQU     35H
 189  G4      EQU     36H
 190  H4      EQU     37H
 191  A5      EQU     40H
 192  B5      EQU     41H
 193  C5      EQU     42H
 194  D5      EQU     43H
 195  E5      EQU     44H
 196  F5      EQU     45H
 197  G5      EQU     46H
 198  H5      EQU     47H
 199  A6      EQU     50H
 200  B6      EQU     51H
 201  C6      EQU     52H
 202  D6      EQU     53H
 203  E6      EQU     54H
 204  F6      EQU     55H
 205  G6      EQU     56H
 206  H6      EQU     57H
 207  A7      EQU     60H
 208  B7      EQU     61H
 209  C7      EQU     62H
 210  D7      EQU     63H
 211  E7      EQU     64H
 212  F7      EQU     65H
 213  G7      EQU     66H
 214  H7      EQU     67H
 215  A8      EQU     70H
 216  B8      EQU     71H
 217  C8      EQU     72H
 218  D8      EQU     73H
 219  E8      EQU     74H
 220  F8      EQU     75H
 221  G8      EQU     76H
 222  H8      EQU     77H
 223  ;
 224          ORG     2000H
 225          JMP     START
 226  ;
 227  ; small tables (2026); kept inside page 20H
 228  DIRS    DB      01H,0FFH,10H,0F0H       ;rook (MOVEX, 1977)
 229          DB      11H,0FH,0EFH,0F1H       ;bishop
 230          DB      0
 231  KNOFF   DB      21H,1FH,12H,0EH,0F2H,0EEH,0E1H,0DFH,0
 232  ; per piece type: table offset, page, material (2)
 233  PSTIX   DB      0,0,0,0                 ;-
 234          DB      0,21H,100,0             ;1 P   100
 235          DB      8,21H,40H,1             ;2 N   320
 236          DB      8,22H,0,0               ;3 K (EVAL)
 237          DB      0,0,0,0                 ;-
 238          DB      80H,21H,4AH,1           ;5 B   330
 239          DB      88H,21H,0F4H,1          ;6 R   500
 240          DB      0,22H,84H,3             ;7 Q   900
 241  GTAB    DW      GPAWN,GKNI,GKING,0,GBIS,GROOK,GQUEEN
 242  PLET    DB      ' PNK BRQ'              ;letters by type
 243  ; castling rights lost when a move touches a square
 244  CRTAB   DB      A1,0FDH,E1,0FCH,H1,0FEH
 245          DB      A8,0F7H,E8,0F3H,H8,0FBH,0FFH
 246  ; start position: piece, square (white; black mirrored)
 247  SETUP   DB      3,E1,7,D1,6,A1,6,H1,5,C1,5,F1,2,B1,2,G1
 248          DB      1,A2,1,B2,1,C2,1,D2,1,E2,1,F2,1,G2,1,H2
 249  ;
 250  ; piece-square tables (Michniewski), 0x88 layout
 251          ORG     2100H
 252  PST     DS      0
 253          DB      0,0,0,0,0,0,0,0 ;P 1
 254          DB      -50,-40,-30,-30,-30,-30,-40,-50 ;N 1
 255          DB      5,10,10,-20,-20,10,10,5 ;P 2
 256          DB      -40,-20,0,5,5,0,-20,-40 ;N 2
 257          DB      5,-5,-10,0,0,-10,-5,5   ;P 3
 258          DB      -30,5,10,15,15,10,5,-30 ;N 3
 259          DB      0,0,0,20,20,0,0,0       ;P 4
 260          DB      -30,0,15,20,20,15,0,-30 ;N 4
 261          DB      5,5,10,25,25,10,5,5     ;P 5
 262          DB      -30,5,15,20,20,15,5,-30 ;N 5
 263          DB      10,10,20,30,30,20,10,10 ;P 6
 264          DB      -30,0,10,15,15,10,0,-30 ;N 6
 265          DB      50,50,50,50,50,50,50,50 ;P 7
 266          DB      -40,-20,0,0,0,0,-20,-40 ;N 7
 267          DB      0,0,0,0,0,0,0,0 ;P 8
 268          DB      -50,-40,-30,-30,-30,-30,-40,-50 ;N 8
 269          DB      -20,-10,-10,-10,-10,-10,-10,-20 ;B 1
 270          DB      0,0,0,5,5,0,0,0 ;R 1
 271          DB      -10,5,0,0,0,0,5,-10     ;B 2
 272          DB      -5,0,0,0,0,0,0,-5       ;R 2
 273          DB      -10,10,10,10,10,10,10,-10       ;B 3
 274          DB      -5,0,0,0,0,0,0,-5       ;R 3
 275          DB      -10,0,10,10,10,10,0,-10 ;B 4
 276          DB      -5,0,0,0,0,0,0,-5       ;R 4
 277          DB      -10,5,5,10,10,5,5,-10   ;B 5
 278          DB      -5,0,0,0,0,0,0,-5       ;R 5
 279          DB      -10,0,5,10,10,5,0,-10   ;B 6
 280          DB      -5,0,0,0,0,0,0,-5       ;R 6
 281          DB      -10,0,0,0,0,0,0,-10     ;B 7
 282          DB      5,10,10,10,10,10,10,5   ;R 7
 283          DB      -20,-10,-10,-10,-10,-10,-10,-20 ;B 8
 284          DB      0,0,0,0,0,0,0,0 ;R 8
 285          DB      -20,-10,-10,-5,-5,-10,-10,-20   ;Q 1
 286          DB      20,30,10,0,0,10,30,20   ;K 1
 287          DB      -10,0,5,0,0,0,0,-10     ;Q 2
 288          DB      20,20,0,0,0,0,20,20     ;K 2
 289          DB      -10,5,5,5,5,5,0,-10     ;Q 3
 290          DB      -10,-20,-20,-20,-20,-20,-20,-10 ;K 3
 291          DB      0,0,5,5,5,5,0,-5        ;Q 4
 292          DB      -20,-30,-30,-40,-40,-30,-30,-20 ;K 4
 293          DB      -5,0,5,5,5,5,0,-5       ;Q 5
 294          DB      -30,-40,-40,-50,-50,-40,-40,-30 ;K 5
 295          DB      -10,0,5,5,5,5,0,-10     ;Q 6
 296          DB      -30,-40,-40,-50,-50,-40,-40,-30 ;K 6
 297          DB      -10,0,0,0,0,0,0,-10     ;Q 7
 298          DB      -30,-40,-40,-50,-50,-40,-40,-30 ;K 7
 299          DB      -20,-10,-10,-5,-5,-10,-10,-20   ;Q 8
 300          DB      -30,-40,-40,-50,-50,-40,-40,-30 ;K 8
 301          DB      -50,-30,-30,-30,-30,-30,-30,-50 ;KE 1
 302          DB      0,0,0,0,0,0,0,0 ;- 1
 303          DB      -30,-30,0,0,0,0,-30,-30 ;KE 2
 304          DB      0,0,0,0,0,0,0,0 ;- 2
 305          DB      -30,-10,20,30,30,20,-10,-30     ;KE 3
 306          DB      0,0,0,0,0,0,0,0 ;- 3
 307          DB      -30,-10,30,40,40,30,-10,-30     ;KE 4
 308          DB      0,0,0,0,0,0,0,0 ;- 4
 309          DB      -30,-10,30,40,40,30,-10,-30     ;KE 5
 310          DB      0,0,0,0,0,0,0,0 ;- 5
 311          DB      -30,-10,20,30,30,20,-10,-30     ;KE 6
 312          DB      0,0,0,0,0,0,0,0 ;- 6
 313          DB      -30,-20,-10,0,0,-10,-20,-30     ;KE 7
 314          DB      0,0,0,0,0,0,0,0 ;- 7
 315          DB      -50,-40,-30,-20,-20,-30,-40,-50 ;KE 8
 316          DB      0,0,0,0,0,0,0,0 ;- 8
 317  ;
 318          ORG     2300H
 319  ;
 320  ;*** START (1979 H0000, CHANGED) ***
 321  START   LXI     SP,STKTOP
 322          CALL    INITT           ;2026: tables
 323          MVI     A,1
 324          STA     AUTO
 325          LXI     H,900           ;Blitz: 15 seconds
 326          SHLD    MODE
 327          CALL    CROUT
 328          LXI     H,H0B6D
 329          CALL    H01DA
 330          LXI     H,H0B93
 331          CALL    H01DA
 332          LXI     H,H0BB9
 333          CALL    H01DA
 334          LXI     H,EDTXT1        ;2026: edition notice
 335          CALL    H01DA
 336          LXI     H,EDTXT2
 337          CALL    H01DA
 338  ;*** H0018: new game (CHANGED) ***
 339  H0018   CALL    CROUT
 340          CALL    NEWPOS          ;2026: start position
 341          LXI     H,H0BF5         ;Do you want WHITE ?
 342          CALL    STRG
 343          CALL    WH0
 344          CALL    WH1
 345          MOV     A,B
 346          CPI     'Y'
 347          MVI     A,0
 348          JZ      HUMW
 349          MVI     A,8
 350  HUMW    STA     HUMAN
 351  H0072   CALL    CROUT
 352          CALL    H0242
 353  ;*** H0075: command loop (CHANGED: new commands) ***
 354  H0075   LXI     SP,STKTOP
 355          LXI     H,H0C10         ;CMD:
 356          CALL    STRG
 357          CALL    H0320
 358          CALL    CROUT
 359          CALL    SETXM
 360          LXI     H,INBUF
 361          MOV     A,M
 362          ORI     20H
 363          CPI     'f'
 364          JNZ     H0075F
 365          LDA     INBUF+1
 366          CPI     ' '
 367          JZ      FENCMD          ;2026: F fen
 368  H0075F  CALL    UPCASE          ;2026
 369          CALL    ISALG           ;2026: e2e4 ?
 370          JZ      ALGMV
 371          LDA     INBUF+1
 372          CPI     0DH
 373          JNZ     H0075A          ;not a one-letter command
 374          LDA     INBUF
 375          CPI     'G'
 376          JZ      H00D7
 377          CPI     'D'
 378          JZ      H0342
 379          CPI     'E'
 380          JZ      H022C
 381          CPI     'S'
 382          JZ      H01E1
 383          CPI     'R'
 384          JZ      H0220
 385          CPI     'A'
 386          JZ      H02F1
 387          CPI     'N'
 388          JZ      H0305
 389          CPI     'B'
 390          JZ      TBACK           ;2026
 391          CPI     'H'
 392          JZ      HELP            ;2026
 393          JMP     H012C
 394  H0075A  LDA     INBUF+1
 395          CPI     '-'
 396          JNZ     H0075B
 397          LDA     INBUF
 398          CPI     'O'
 399          JZ      H03D1           ;castling O-O / O-O-O
 400          CPI     '0'
 401          JZ      H03D1
 402  H0075B  LDA     INBUF
 403          CPI     'P'
 404          JZ      PERFC           ;2026
 405          CALL    MCPARS          ;2026: check the digits
 406          CALL    H0168           ;FF-TT (1979 squares)
 407          LXI     H,INBUF+5
 408          JMP     HUMV
 409  ;
 410  ;*** H00D7: G command, the computer moves (CHANGED) ***
 411  H00D7   CALL    ENDCHK          ;2026: game already over?
 412          JNZ     H013E
 413          CALL    THINK           ;2026: completes H047D
 414          CALL    ELAPS
 415          SHLD    RTIME
 416          LXI     H,RBEST
 417          CALL    GAMEMV
 418  H0120   LDA     AUTO
 419          ORA     A
 420          CNZ     H0242
 421          CALL    SHOWMV          ;MC : 14-34 (d2-d4) + search
 422          CALL    ENDCHK          ;mate, stalemate, draw?
 423          JNZ     H013E
 424          CALL    CHKME           ;check?
 425          JZ      H0075
 426          LXI     H,H0CAE         ;CHECK!
 427          CALL    H01DA
 428          JMP     H0075
 429  ;
 430  ;*** H012C: input error (KEPT) ***
 431  H012C   LXI     H,H0C23
 432          CALL    STRG
 433          CALL    CROUT
 434          JMP     H0075
 435  ;*** H0138/H013E: game over, play again (KEPT) ***
 436  H0138   LXI     H,H0C30
 437          CALL    H01DA
 438  H013E   CALL    CROUT
 439          LXI     H,H0C47
 440          CALL    STRG
 441          CALL    WH0
 442          CALL    WH1
 443          MOV     A,B
 444          CPI     'Y'
 445          JNZ     H01C8
 446          CALL    CROUT
 447          JMP     H0018
 448  ;*** STRG: show text to 0DH (KEPT) ***
 449  STRG    MOV     A,M
 450          CPI     0DH
 451          RZ
 452          MOV     B,A
 453          CALL    WH1
 454          INX     H
 455          JMP     STRG
 456  ;*** H0168: read FF-TT (CHANGED: board squares) ***
 457  H0168   LHLD    INBUF
 458          CALL    H0199
 459          LXI     H,XMASK
 460          XRA     M
 461          STA     PFROM
 462          LHLD    INBUF+3
 463          CALL    H0199
 464          LXI     H,XMASK
 465          XRA     M
 466          STA     PTO
 467          RET
 468  ;*** H0199: two digits to a square (KEPT) ***
 469  H0199   MOV     A,L
 470          ANI     0FH
 471          RAL
 472          RAL
 473          RAL
 474          RAL
 475          MOV     B,A
 476          MOV     A,H
 477          ANI     0FH
 478          ORA     B
 479          MOV     B,A
 480          ANI     88H
 481          JNZ     H012C
 482          MOV     A,B
 483          RET
 484  ;*** H01C8: end of game (KEPT) ***
 485  H01C8   CALL    CROUT
 486          CALL    CROUT
 487          LXI     H,H0C5B
 488          CALL    H01DA
 489          CALL    WH0
 490          JMP     0
 491  ;*** H01DA: text and new line (KEPT) ***
 492  H01DA   CALL    STRG
 493          CALL    CROUT
 494          RET
 495  ;*** H01E1: S command, mode (CHANGED: time limits) ***
 496  H01E1   CALL    CROUT
 497          LXI     H,H0BDF
 498          CALL    STRG
 499          CALL    WH0
 500          CALL    WH1
 501          MOV     A,B
 502          LXI     H,300           ;Super blitz: 5 s
 503          CPI     'S'
 504          JZ      H0215
 505          LXI     H,900           ;Blitz: 15 s
 506          CPI     'B'
 507          JZ      H0215
 508          LXI     H,2700          ;Normal: 45 s
 509          CPI     'N'
 510          JNZ     H012C
 511  H0215   SHLD    MODE
 512          JMP     H0072
 513  ;*** H0220: R command, resign (KEPT) ***
 514  H0220   CALL    CROUT
 515          LXI     H,H0C7E
 516          CALL    STRG
 517          JMP     H013E
 518  ;*** H022C: E command, exchange sides (CHANGED) ***
 519  H022C   LDA     HUMAN
 520          XRI     8
 521          STA     HUMAN
 522          JMP     H0072
 523  ;
 524  ;*** H0242: show the board (CHANGED: pieces, labels) ***
 525  H0242   CALL    CROUT
 526          CALL    SETXM
 527          MVI     D,0             ;display square: row, column
 528          LXI     H,H0CB6         ;+------ MicroChess -------+
 529          CALL    H01DA
 530  H0250   MVI     B,21H
 531          CALL    WH1
 532          MVI     B,20H
 533          CALL    WH1
 534  H0265   LDA     XMASK
 535          XRA     D
 536          MOV     L,A
 537          MVI     H,BRDH
 538          MOV     A,M
 539          ORA     A
 540          JNZ     H02B8
 541          MOV     A,D
 542          ANI     0FH
 543          MOV     E,A
 544          MOV     A,D
 545          ANI     0F0H
 546          RRC
 547          RRC
 548          RRC
 549          RRC
 550          ADD     E
 551          RAR
 552          JC      H0289
 553          MVI     B,20H
 554          JMP     H028B
 555  H0289   MVI     B,3AH
 556  H028B   CALL    WH1
 557          CALL    WH1
 558  H0291   MVI     B,20H
 559          CALL    WH1
 560          INR     D
 561          MOV     A,D
 562          ANI     0FH
 563          CPI     8
 564          JNZ     H0265
 565          MVI     B,21H
 566          CALL    WH1
 567          MVI     B,20H           ;2026: row digit and rank
 568          CALL    WH1
 569          MOV     A,D
 570          RRC
 571          RRC
 572          RRC
 573          RRC
 574          ANI     7
 575          ADI     '0'
 576          MOV     B,A
 577          CALL    WH1
 578          MVI     B,20H
 579          CALL    WH1
 580          LDA     XMASK
 581          XRA     D
 582          RRC
 583          RRC
 584          RRC
 585          RRC
 586          ANI     7
 587          ADI     '1'
 588          MOV     B,A
 589          CALL    WH1
 590          CALL    CROUT
 591          MOV     A,D
 592          ADI     8
 593          MOV     D,A
 594          JP      H0250
 595          LXI     H,H0CEE         ;+------ Challenger -------+
 596          CALL    H01DA
 597          LXI     H,COLDIG        ;2026: column digits, files
 598          CALL    H01DA
 599          MVI     D,0
 600  H02A0   MVI     B,20H
 601          CALL    WH1
 602          CALL    WH1
 603          LDA     XMASK
 604          XRA     D
 605          ANI     7
 606          ADI     'a'
 607          MOV     B,A
 608          CALL    WH1
 609          INR     D
 610          MOV     A,D
 611          CPI     8
 612          JNZ     H02A0
 613          CALL    CROUT
 614          RET
 615  H02B8   MOV     C,A             ;a piece: colour, letter
 616          ANI     8
 617          MVI     B,'W'
 618          JZ      H02DD
 619          MVI     B,'B'
 620  H02DD   CALL    WH1
 621          MOV     A,C
 622          ANI     7
 623          LXI     H,PLET
 624          ADD     L
 625          MOV     L,A
 626          MOV     B,M
 627          CALL    WH1
 628          JMP     H0291
 629  ;*** H02F1/H0305: A, N commands (CHANGED: a flag) ***
 630  H02F1   MVI     A,1
 631          STA     AUTO
 632          JMP     H0072
 633  H0305   XRA     A
 634          STA     AUTO
 635          JMP     H0072
 636  ;*** H0320: read a line (CHANGED: raw keys, length) ***
 637  H0320   LXI     H,INBUF
 638          MVI     C,0
 639  H0325   CALL    RAWKEY
 640          MOV     A,B
 641          MOV     M,A
 642          CPI     0DH
 643          JZ      H033C
 644          CPI     07FH
 645          JZ      RUBOUT
 646          MOV     A,C
 647          CPI     100             ;2026: buffer limit
 648          JNC     H0325
 649          CALL    WH1
 650          INX     H
 651          INR     C
 652          JMP     H0325
 653  H033C   XRA     A
 654          CMP     C
 655          JZ      H0325
 656          RET
 657  RUBOUT  MOV     A,C
 658          CPI     0
 659          JZ      H0325
 660          DCR     C
 661          DCX     H
 662          MVI     A,07FH
 663          CALL    WH1
 664          JMP     H0325
 665  ;*** H0342: D command (KEPT) ***
 666  H0342   CALL    H0242
 667          JMP     H0075
 668  ;*** H03D1: O command, castling (1979 TEMP; 2026) ***
 669  H03D1   CALL    SETXM
 670          LDA     STM
 671          ORA     A
 672          MVI     A,E1
 673          JZ      H03D2
 674          MVI     A,E8
 675  H03D2   STA     PFROM
 676          MOV     B,A
 677          LXI     H,INBUF+3
 678          MOV     A,M
 679          CPI     '-'
 680          JZ      H03D3
 681          INR     B               ;O-O: king to the g file
 682          INR     B
 683          MOV     A,B
 684          STA     PTO
 685          LXI     H,INBUF+3
 686          JMP     HUMV
 687  H03D3   DCR     B               ;O-O-O: to the c file
 688          DCR     B
 689          MOV     A,B
 690          STA     PTO
 691          LXI     H,INBUF+5
 692          JMP     HUMV
 693  ;
 694  ;*** WH1: show B (KEPT) ***
 695  WH1     MOV     A,B
 696          JMP     0C24H
 697  ;*** WH0: key, upper case (KEPT) ***
 698  WH0     CALL    0C20H
 699          ANI     7FH
 700          CPI     07FH
 701          JZ      WH0END
 702          CPI     60H
 703          JC      WH0END
 704          SUI     20H
 705  WH0END  MOV     B,A
 706          RET
 707  ;
 708  ;*** texts (KEPT, 1979) ***
 709  H0B6D   DB      0CH,'MicroChess                 (C) 1977.',13
 710  H0B93   DB      'Written by: P. Jennings & T. O',27H,'Brien.',13
 711  H0BB9   DB      '-------------------------------------',13
 712  H0BDF   DB      'Which mode ? (S,B,N) ',13
 713  H0BF5   DB      'Do you want WHITE ? (Y,N) ',13
 714  H0C10   DB      'CMD: ',13
 715  H0C23   DB      'Input error.',13
 716  H0C30   DB      'CHECKMATE - YOU WIN!!!',13
 717  H0C47   DB      'Play again ? (Y,N) ',13
 718  H0C5B   DB      'Thanks for the game... MicroChess.',13
 719  H0C7E   DB      'You resigned - I WIN!!!',13
 720  H0C96   DB      '  CHECKMATE - I WIN!!!!',13
 721  H0CAE   DB      ' CHECK!',13
 722  H0CB6   DB      '+------ MicroChess -------+',13
 723  H0CEE   DB      '+------ Challenger -------+',13
 724  ;*** texts (2026) ***
 725  EDTXT1  DB      'Completed edition 2026-12-01: search finished,',13
 726  EDTXT2  DB      'modern search added. Not a 1970s original. H=help',13
 727  COLDIG  DB      '  0  1  2  3  4  5  6  7',13
 728  TXSTAL  DB      'STALEMATE - DRAW.',13
 729  TXD50   DB      'DRAW - 50 MOVES WITHOUT CAPTURE OR PAWN MOVE.',13
 730  TXDREP  DB      'DRAW - SAME POSITION THREE TIMES.',13
 731  TXDMAT  DB      'DRAW - NOT ENOUGH MATERIAL TO MATE.',13
 732  TXILL   DB      'Illegal move.',13
 733  TXMC    DB      'MC : ',13
 734  TXDEP   DB      '  depth ',13
 735  TXNOD   DB      ', nodes ',13
 736  TXSEC   DB      ' s, score ',13
 737  TXBOOK  DB      '  (opening book)',13
 738  TXONLY  DB      '  (only move)',13
 739  TXMATE  DB      'mate',13
 740  TXPART  DB      '+',13
 741  TXNODES DB      ' nodes, ',13
 742  TXS     DB      ' s',13
 743  TXFULL  DB      'Game too long.',13
 744  TXHELP  DB      'Moves: 64-44 or e2e4 (add M: no reply), O-O, O-O-O,',13
 745          DB      'promote: 16-06=N or e7e8n. Commands (then RETURN):',13
 746          DB      'G you move  D board  E exchange  S speed  B take back',13
 747          DB      'A/N board on/off  R resign  F fen  P n perft',13
 748          DB      0
 749  ;
 750  ;=====================================================
 751  ; 2026: THE ENGINE. Board: 0x88 mailbox (BRD) plus a
 752  ; piece list (PLIST) with absolute colours; the side
 753  ; to move is STM. Piece codes: P1 N2 K3 B5 R6 Q7, +8
 754  ; black, so "slides diagonally" is (code AND 5)=5 and
 755  ; "slides straight" is (code AND 6)=6.
 756  ;=====================================================
 757  ;
 758  ;*** INITT: line-direction table, undo pointer ***
 759  ; DIRT[a-b+77H] = the step from square b towards a.
 760  INITT   LXI     H,DIRT
 761          XRA     A
 762  IT1     MOV     M,A
 763          INR     L
 764          JNZ     IT1
 765          LXI     D,DIRS
 766          MVI     C,8
 767  IT2     LDAX    D
 768          MOV     B,A
 769          MVI     L,77H
 770          MVI     A,7
 771          STA     MTMP
 772  IT3     MOV     A,L
 773          ADD     B
 774          MOV     L,A
 775          MOV     M,B
 776          LDA     MTMP
 777          DCR     A
 778          STA     MTMP
 779          JNZ     IT3
 780          INX     D
 781          DCR     C
 782          JNZ     IT2
 783          LXI     H,UNDO
 784          SHLD    UNDOP
 785          RET
 786  ;
 787  ;*** NEWPOS: start position (replaces 1979 H05AF) ***
 788  NEWPOS  CALL    CLRPOS
 789          LXI     D,SETUP
 790          MVI     C,0
 791  NP1     LDAX    D
 792          MOV     B,A
 793          INX     D
 794          LDAX    D
 795          INX     D
 796          PUSH    D
 797          MOV     E,A
 798          CALL    PUTPC
 799          MOV     A,B
 800          ORI     8
 801          MOV     B,A
 802          MOV     A,E
 803          XRI     70H
 804          MOV     E,A
 805          MOV     A,C
 806          ADI     16
 807          MOV     C,A
 808          CALL    PUTPC
 809          MOV     A,C
 810          SUI     15
 811          MOV     C,A
 812          POP     D
 813          CPI     16
 814          JNZ     NP1
 815          XRA     A
 816          STA     STM
 817          STA     HMC
 818          MVI     A,0FH
 819          STA     CASTL
 820          MVI     A,1
 821          STA     BOOKOK
 822  NEWGM   CALL    CALCSC
 823          LXI     H,0
 824          SHLD    NPLY
 825          LXI     H,UNDO
 826          SHLD    UNDOP
 827          CALL    SNAPSV
 828          JMP     KEYREC
 829  ;
 830  ; PUTPC: piece B on square E as slot C (keeps B-E)
 831  PUTPC   MVI     H,BRDH
 832          MOV     L,E
 833          MOV     M,B
 834          MOV     A,L
 835          ADI     8
 836          MOV     L,A
 837          MOV     M,C
 838          MVI     H,PLISTH
 839          MOV     L,C
 840          MOV     M,E
 841          RET
 842  CLRPOS  LXI     H,BRD
 843          XRA     A
 844  CP1     MOV     M,A
 845          INR     L
 846          JNZ     CP1
 847          LXI     H,PLIST
 848          MVI     B,32
 849  CP2     MVI     M,0CCH
 850          INX     H
 851          DCR     B
 852          JNZ     CP2
 853          MVI     A,0CCH
 854          STA     EPSQ
 855          RET
 856  ;
 857  ; CALCSC: SCORE from scratch (material + tables)
 858  CALCSC  LXI     H,0
 859          SHLD    SCORE
 860          MVI     C,0
 861  CS1     MVI     H,PLISTH
 862          MOV     L,C
 863          MOV     A,M
 864          CPI     0CCH
 865          JZ      CS2
 866          MOV     B,A
 867          MVI     H,BRDH
 868          MOV     L,A
 869          MOV     A,M
 870          CALL    SCADD
 871  CS2     INR     C
 872          MOV     A,C
 873          CPI     32
 874          JNZ     CS1
 875          RET
 876  ;
 877  ; SNAPSV/SNAPLD: keep or restore the game's start
 878  SNAPSV  LXI     H,BRD
 879          LXI     D,SNAP
 880          LXI     B,256
 881          CALL    COPY
 882          LXI     H,PLIST
 883          LXI     D,SNAP+100H
 884          LXI     B,POSLEN
 885          JMP     COPY
 886  SNAPLD  LXI     H,SNAP
 887          LXI     D,BRD
 888          LXI     B,256
 889          CALL    COPY
 890          LXI     H,SNAP+100H
 891          LXI     D,PLIST
 892          LXI     B,POSLEN
 893  COPY    MOV     A,M
 894          STAX    D
 895          INX     H
 896          INX     D
 897          DCX     B
 898          MOV     A,B
 899          ORA     C
 900          JNZ     COPY
 901          RET
 902  COPYC   MOV     A,M
 903          STAX    D
 904          INX     H
 905          INX     D
 906          DCR     C
 907          JNZ     COPYC
 908          RET
 909  ;
 910  ;*** POSKEY: a 16-bit key of the position (DE) ***
 911  ; used for the threefold repetition rule (game level)
 912  POSKEY  LXI     D,0
 913          LXI     H,BRD
 914  PY1     MOV     A,L
 915          ANI     88H
 916          JNZ     PY3
 917          MOV     A,M
 918          ORA     A
 919          JZ      PY3
 920          XCHG
 921          DAD     H
 922          JNC     PY2
 923          INX     H
 924  PY2     XRA     L
 925          MOV     L,A
 926          MOV     A,E
 927          XRA     H
 928          MOV     H,A
 929          XCHG
 930  PY3     INR     L
 931          MOV     A,L
 932          CPI     78H
 933          JNZ     PY1
 934          LDA     STM
 935          XRA     E
 936          MOV     E,A
 937          LDA     CASTL
 938          XRA     D
 939          MOV     D,A
 940          LDA     EPSQ
 941          ADD     E
 942          MOV     E,A
 943          RET
 944  KEYREC  CALL    POSKEY
 945          LHLD    NPLY
 946          DAD     H
 947          LXI     B,GKEYS
 948          DAD     B
 949          MOV     M,E
 950          INX     H
 951          MOV     M,D
 952          RET
 953  ; REPCNT: A = earlier positions equal to this one
 954  REPCNT  LHLD    NPLY
 955          DAD     H
 956          LXI     D,GKEYS
 957          DAD     D
 958          MOV     E,M
 959          INX     H
 960          MOV     D,M
 961          LHLD    NPLY
 962          MOV     B,H
 963          MOV     C,L
 964          LXI     H,GKEYS
 965          XRA     A
 966          STA     MTMP
 967  RC1     MOV     A,B
 968          ORA     C
 969          JZ      RC3
 970          MOV     A,M
 971          INX     H
 972          CMP     E
 973          JNZ     RC2
 974          MOV     A,M
 975          CMP     D
 976          JNZ     RC2
 977          LDA     MTMP
 978          INR     A
 979          STA     MTMP
 980  RC2     INX     H
 981          DCX     B
 982          JMP     RC1
 983  RC3     LDA     MTMP
 984          RET
 985  ;
 986  ;*** input helpers (2026) ***
 987  SETXM   LDA     HUMAN
 988          ORA     A
 989          MVI     A,70H
 990          JZ      SX1
 991          MVI     A,07H
 992  SX1     STA     XMASK
 993          RET
 994  UPCASE  LXI     H,INBUF
 995  UC1     MOV     A,M
 996          CPI     0DH
 997          RZ
 998          CPI     'a'
 999          JC      UC2
1000          CPI     'z'+1
1001          JNC     UC2
1002          SUI     20H
1003          MOV     M,A
1004  UC2     INX     H
1005          JMP     UC1
1006  ISALG   LXI     H,INBUF
1007          CALL    ISFILE
1008          RNZ
1009          INX     H
1010          CALL    ISRANK
1011          RNZ
1012          INX     H
1013          CALL    ISFILE
1014          RNZ
1015          INX     H
1016          JMP     ISRANK
1017  ISFILE  MOV     A,M
1018          CPI     'A'
1019          JC      NOTZ
1020          CPI     'H'+1
1021          JNC     NOTZ
1022          XRA     A
1023          RET
1024  ISRANK  MOV     A,M
1025          CPI     '1'
1026          JC      NOTZ
1027          CPI     '9'
1028          JNC     NOTZ
1029          XRA     A
1030          RET
1031  NOTZ    MVI     A,1
1032          ORA     A
1033          RET
1034  ALGMV   LXI     H,INBUF
1035          CALL    ALGSQ
1036          STA     PFROM
1037          CALL    ALGSQ
1038          STA     PTO
1039          JMP     HUMV
1040  ALGSQ   MOV     A,M
1041          SUI     'A'
1042  ALGS2   MOV     B,A
1043          INX     H
1044          MOV     A,M
1045          SUI     '1'
1046          RLC
1047          RLC
1048          RLC
1049          RLC
1050          ORA     B
1051          INX     H
1052          RET
1053  ALGSQL  MOV     A,M
1054          SUI     'a'
1055          JMP     ALGS2
1056  MCPARS  LXI     H,INBUF
1057          CALL    ISDIG
1058          INX     H
1059          CALL    ISDIG
1060          INX     H
1061          MOV     A,M
1062          CPI     '-'
1063          JNZ     H012C
1064          INX     H
1065          CALL    ISDIG
1066          INX     H
1067  ISDIG   MOV     A,M
1068          CPI     '0'
1069          JC      H012C
1070          CPI     '8'
1071          JNC     H012C
1072          RET
1073  SKIPSP  MOV     A,M
1074          CPI     ' '
1075          RNZ
1076          INX     H
1077          JMP     SKIPSP
1078  RAWKEY  CALL    0C20H
1079          ANI     7FH
1080          MOV     B,A
1081          RET
1082  ;
1083  ;*** HUMV: the player's move PFROM-PTO, HL: rest ***
1084  ; (1979: H086D moved any piece; 2026: only legal
1085  ; moves are accepted, promotion =Q/R/B/N, default Q)
1086  HUMV    XRA     A
1087          STA     PPRO
1088          MOV     A,M
1089          CPI     '='
1090          JNZ     HV1
1091          INX     H
1092          MOV     A,M
1093  HV1     CALL    PROLET
1094          JNZ     HV2
1095          STA     PPRO
1096          INX     H
1097          MOV     A,M
1098  HV2     STA     PSUF
1099          CALL    GENLEG
1100          LXI     H,MVSTK
1101  HV3     XCHG
1102          LHLD    MVHI
1103          MOV     A,L
1104          CMP     E
1105          JNZ     HV4
1106          MOV     A,H
1107          CMP     D
1108          JZ      HVBAD
1109  HV4     XCHG
1110          LDA     PFROM
1111          CMP     M
1112          JNZ     HV5
1113          INX     H
1114          LDA     PTO
1115          CMP     M
1116          DCX     H
1117          JNZ     HV5
1118          INX     H
1119          INX     H
1120          MOV     A,M
1121          DCX     H
1122          DCX     H
1123          ANI     7
1124          JZ      HVOK
1125          MOV     B,A
1126          LDA     PPRO
1127          ORA     A
1128          JNZ     HV6
1129          MVI     A,7
1130  HV6     CMP     B
1131          JZ      HVOK
1132  HV5     INX     H
1133          INX     H
1134          INX     H
1135          INX     H
1136          JMP     HV3
1137  HVOK    CALL    GAMEMV
1138          LDA     AUTO
1139          ORA     A
1140          CNZ     H0242
1141          CALL    ENDCHK
1142          JNZ     H013E
1143          LDA     PSUF
1144          CPI     'M'
1145          JZ      H0075
1146          JMP     H00D7
1147  HVBAD   LXI     H,TXILL
1148          CALL    H01DA
1149          JMP     H0075
1150  PROLET  CPI     'Q'
1151          MVI     B,7
1152          JZ      PL1
1153          CPI     'R'
1154          MVI     B,6
1155          JZ      PL1
1156          CPI     'B'
1157          MVI     B,5
1158          JZ      PL1
1159          CPI     'N'
1160          MVI     B,2
1161          RNZ
1162  PL1     MOV     A,B
1163          RET
1164  ;
1165  ;*** GAMEMV: play move (HL) in the game ***
1166  GAMEMV  PUSH    H
1167          LHLD    NPLY
1168          PUSH    H
1169          LXI     D,-MAXNP
1170          DAD     D
1171          POP     H
1172          JC      GMFULL
1173          MOV     D,H
1174          MOV     E,L
1175          DAD     H
1176          DAD     D
1177          LXI     D,GAME
1178          DAD     D
1179          XCHG
1180          POP     H
1181          PUSH    H
1182          MVI     C,3
1183          CALL    COPYC
1184          POP     H
1185          CALL    MAKE
1186          LXI     H,UNDO
1187          SHLD    UNDOP
1188          LHLD    NPLY
1189          INX     H
1190          SHLD    NPLY
1191          JMP     KEYREC
1192  GMFULL  POP     H
1193          LXI     H,TXFULL
1194          CALL    H01DA
1195          JMP     H013E
1196  ;
1197  ;*** TBACK: B command, take back a move (2026) ***
1198  ; replays the game from its start without the last
1199  ; two half moves
1200  TBACK   LHLD    NPLY
1201          MOV     A,H
1202          ORA     L
1203          JZ      H012C
1204          DCX     H
1205          MOV     A,H
1206          ORA     L
1207          JZ      TB1
1208          DCX     H
1209  TB1     SHLD    TMPW
1210          CALL    SNAPLD
1211          LXI     H,0
1212          SHLD    NPLY
1213          LXI     H,UNDO
1214          SHLD    UNDOP
1215          CALL    KEYREC
1216          LXI     H,GAME
1217          SHLD    INP
1218  TB2     LHLD    TMPW
1219          MOV     A,H
1220          ORA     L
1221          JZ      H0072
1222          DCX     H
1223          SHLD    TMPW
1224          LHLD    INP
1225          PUSH    H
1226          CALL    GAMEMV
1227          POP     H
1228          INX     H
1229          INX     H
1230          INX     H
1231          SHLD    INP
1232          JMP     TB2
1233  ;
1234  ;*** ENDCHK: is the game over? NZ + message if so ***
1235  ENDCHK  CALL    GENLEG
1236          LHLD    MVHI
1237          LXI     D,MVSTK
1238          MOV     A,L
1239          CMP     E
1240          JNZ     EC2
1241          MOV     A,H
1242          CMP     D
1243          JNZ     EC2
1244          CALL    CHKME
1245          LXI     H,TXSTAL
1246          JZ      ECMSG
1247          LDA     STM
1248          LXI     H,HUMAN
1249          CMP     M
1250          LXI     H,H0C96         ;CHECKMATE - I WIN
1251          JZ      ECMSG
1252          LXI     H,H0C30         ;CHECKMATE - YOU WIN
1253          JMP     ECMSG
1254  EC2     LDA     HMC
1255          CPI     100
1256          LXI     H,TXD50
1257          JNC     ECMSG
1258          CALL    INSUF
1259          LXI     H,TXDMAT
1260          JZ      ECMSG
1261          CALL    REPCNT
1262          CPI     2
1263          LXI     H,TXDREP
1264          JNC     ECMSG
1265          XRA     A
1266          RET
1267  ECMSG   CALL    H01DA
1268          MVI     A,1
1269          ORA     A
1270          RET
1271  ; INSUF: Z if neither side can mate (K, K+N, K+B)
1272  INSUF   MVI     C,0
1273          MVI     B,0
1274          LXI     H,PLIST
1275  IS1     MOV     A,M
1276          CPI     0CCH
1277          JZ      IS2
1278          PUSH    H
1279          MOV     L,A
1280          MVI     H,BRDH
1281          MOV     A,M
1282          ANI     7
1283          POP     H
1284          CPI     3
1285          JZ      IS2
1286          MOV     B,A
1287          INR     C
1288  IS2     INR     L
1289          MOV     A,L
1290          CPI     32
1291          JNZ     IS1
1292          MOV     A,C
1293          ORA     A
1294          RZ
1295          DCR     A
1296          RNZ
1297          MOV     A,B
1298          CPI     2
1299          RZ
1300          CPI     5
1301          RET
1302  ;
1303  ;*** GENLEG: the legal moves, MVSTK..MVHI ***
1304  GENLEG  LXI     H,MVSTK
1305          SHLD    MVPUT
1306          CALL    CHKME
1307          STA     INCHK
1308          XRA     A
1309          STA     CAPONL
1310          CALL    NOKILL
1311          CALL    GEN
1312          LXI     H,MVSTK
1313          SHLD    MVCUR
1314          SHLD    TMPW
1315          LHLD    MVPUT
1316          SHLD    MVHI
1317  GL1     CALL    ATEND
1318          JZ      GL3
1319          CALL    MAKE
1320          CALL    ILLEG
1321          PUSH    PSW
1322          CALL    UNMAKE
1323          POP     PSW
1324          JNZ     GL2
1325          LHLD    TMPW
1326          XCHG
1327          LHLD    MVCUR
1328          MVI     C,4
1329          CALL    COPYC
1330          XCHG
1331          SHLD    TMPW
1332  GL2     CALL    NEXTMV
1333          JMP     GL1
1334  GL3     LHLD    TMPW
1335          SHLD    MVHI
1336          SHLD    MVPUT
1337          RET
1338  NOKILL  LXI     H,0FFFFH
1339          SHLD    KIL1
1340          SHLD    KIL2
1341          RET
1342  NEXTMV  LHLD    MVCUR
1343          LXI     D,4
1344          DAD     D
1345          SHLD    MVCUR
1346          RET
1347  ; ATEND: Z if MVCUR = MVHI (HL = MVCUR)
1348  ATEND   LHLD    MVHI
1349          XCHG
1350          LHLD    MVCUR
1351          MOV     A,L
1352          CMP     E
1353          RNZ
1354          MOV     A,H
1355          CMP     D
1356          RET
1357  ;
1358  ;*** ATTKD: is square A attacked by colour ATBY? ***
1359  ; NZ (A=1) yes, Z (A=0) no. Pawns, knights, king by
1360  ; table; sliders by walking the eight lines.
1361  CHKME   LDA     STM
1362          ADD     A
1363          MOV     L,A
1364          MVI     H,PLISTH
1365          MOV     C,M
1366          LDA     STM
1367          XRI     8
1368          STA     ATBY
1369          MOV     A,C
1370          JMP     ATTKD
1371  ATTOPP  MOV     C,A
1372          LDA     STM
1373          XRI     8
1374          STA     ATBY
1375          MOV     A,C
1376  ATTKD   MOV     C,A
1377          MVI     H,BRDH
1378          LDA     ATBY
1379          ORI     1
1380          MOV     B,A
1381          ANI     8
1382          MOV     A,C
1383          JZ      AKW
1384          ADI     0FH
1385          JMP     AK0
1386  AKW     SUI     11H
1387  AK0     MOV     L,A
1388          ANI     88H
1389          JNZ     AK1
1390          MOV     A,M
1391          CMP     B
1392          JZ      AKYES
1393  AK1     MOV     A,L
1394          ADI     2
1395          MOV     L,A
1396          ANI     88H
1397          JNZ     AK2
1398          MOV     A,M
1399          CMP     B
1400          JZ      AKYES
1401  AK2     LDA     ATBY
1402          ORI     2
1403          MOV     B,A
1404          LXI     D,KNOFF
1405          CALL    AKSTEP
1406          RNZ
1407          LDA     ATBY
1408          ORI     3
1409          MOV     B,A
1410          LXI     D,DIRS
1411          CALL    AKSTEP
1412          RNZ
1413          LDA     ATBY
1414          ORI     6
1415          MOV     B,A
1416          LXI     D,DIRS
1417          MVI     A,4
1418          STA     AKCNT
1419  AK3     LDAX    D
1420          STA     AKDIR
1421          MOV     L,C
1422  AK4     LDA     AKDIR
1423          ADD     L
1424          MOV     L,A
1425          ANI     88H
1426          JNZ     AK5
1427          MOV     A,M
1428          ORA     A
1429          JZ      AK4
1430          ANI     0EH
1431          CMP     B
1432          JZ      AKYES
1433  AK5     INX     D
1434          LDA     AKCNT
1435          DCR     A
1436          STA     AKCNT
1437          JNZ     AK3
1438          LDA     ATBY
1439          ORI     5
1440          MOV     B,A
1441          MVI     A,4
1442          STA     AKCNT
1443  AK6     LDAX    D
1444          STA     AKDIR
1445          MOV     L,C
1446  AK7     LDA     AKDIR
1447          ADD     L
1448          MOV     L,A
1449          ANI     88H
1450          JNZ     AK8
1451          MOV     A,M
1452          ORA     A
1453          JZ      AK7
1454          ANI     0DH
1455          CMP     B
1456          JZ      AKYES
1457  AK8     INX     D
1458          LDA     AKCNT
1459          DCR     A
1460          STA     AKCNT
1461          JNZ     AK6
1462          XRA     A
1463          RET
1464  AKSTEP  LDAX    D
1465          ORA     A
1466          RZ
1467          INX     D
1468          ADD     C
1469          MOV     L,A
1470          ANI     88H
1471          JNZ     AKSTEP
1472          MOV     A,M
1473          CMP     B
1474          JNZ     AKSTEP
1475  AKYES   MVI     A,1
1476          ORA     A
1477          RET
1478  ;
1479  ;*** ILLEG: after MAKE, NZ if the mover's king is
1480  ; attacked. 2026 shortcut: when the mover was not in
1481  ; check and did not move the king (nor capture en
1482  ; passant), only the line from the king through the
1483  ; square left can have opened: one lookup in DIRT and
1484  ; one walk along that line instead of a full test.
1485  ILLEG   LDA     STM
1486          STA     ATBY
1487          XRI     8
1488          ADD     A
1489          MOV     L,A
1490          MVI     H,PLISTH
1491          MOV     C,M
1492          LDA     MFLAG
1493          ORA     A
1494          JM      ILFULL
1495          LDA     MPC
1496          ANI     7
1497          CPI     3
1498          JZ      ILFULL
1499          LDA     INCHK
1500          ANI     1
1501          JNZ     ILFULL
1502          LDA     MFROM
1503          SUB     C
1504          ADI     77H
1505          MOV     L,A
1506          MVI     H,DIRTH
1507          MOV     A,M
1508          ORA     A
1509          RZ
1510          MOV     D,A
1511          MVI     H,BRDH
1512          MOV     L,C
1513  IL1     MOV     A,L
1514          ADD     D
1515          MOV     L,A
1516          ANI     88H
1517          JNZ     ILOK
1518          MOV     A,M
1519          ORA     A
1520          JZ      IL1
1521          MOV     E,A
1522          MOV     A,D
1523          CPI     1
1524          JZ      ILORTH
1525          CPI     0FFH
1526          JZ      ILORTH
1527          CPI     10H
1528          JZ      ILORTH
1529          CPI     0F0H
1530          JZ      ILORTH
1531          LDA     ATBY
1532          ORI     5
1533          MOV     B,A
1534          MOV     A,E
1535          ANI     0DH
1536          JMP     ILCMP
1537  ILORTH  LDA     ATBY
1538          ORI     6
1539          MOV     B,A
1540          MOV     A,E
1541          ANI     0EH
1542  ILCMP   CMP     B
1543          JZ      AKYES
1544  ILOK    XRA     A
1545          RET
1546  ILFULL  MOV     A,C
1547          JMP     ATTKD
1548  ;
1549  ;*** GEN: pseudo-legal moves of STM at MVPUT ***
1550  ; entry: from, to, flag, order score. Flag: promotion
1551  ; piece (bits 0-2), 20H double step, 40H castling,
1552  ; 80H en passant. CAPONL=1: captures and queening.
1553  GEN     LDA     STM
1554          ADD     A
1555          MOV     C,A
1556  GEN1    MVI     H,PLISTH
1557          MOV     L,C
1558          MOV     A,M
1559          CPI     0CCH
1560          JZ      GENX
1561          STA     GFROM
1562          MOV     L,A
1563          MVI     H,BRDH
1564          MOV     A,M
1565          STA     GCODE
1566          PUSH    B
1567          ANI     7
1568          DCR     A
1569          ADD     A
1570          LXI     H,GTAB
1571          ADD     L
1572          MOV     L,A
1573          MOV     E,M
1574          INX     H
1575          MOV     D,M
1576          XCHG
1577          LXI     D,GENRET
1578          PUSH    D
1579          PCHL
1580  GENRET  POP     B
1581  GENX    INR     C
1582          MOV     A,C
1583          ANI     0FH
1584          JNZ     GEN1
1585          RET
1586  GBIS    LXI     D,DIRS+4
1587          MVI     C,4
1588          JMP     SLIDE
1589  GROOK   LXI     D,DIRS
1590          MVI     C,4
1591          JMP     SLIDE
1592  GQUEEN  LXI     D,DIRS
1593          MVI     C,8
1594  SLIDE   MVI     H,BRDH
1595  SL1     LDA     GFROM
1596          MOV     B,A
1597  SL2     LDAX    D
1598          ADD     B
1599          MOV     B,A
1600          ANI     88H
1601          JNZ     SL4
1602          MOV     L,B
1603          MOV     A,M
1604          ORA     A
1605          JNZ     SL3
1606          LDA     CAPONL
1607          ORA     A
1608          JNZ     SL2
1609          CALL    ADD0
1610          JMP     SL2
1611  SL3     MOV     L,A
1612          LDA     GCODE
1613          XRA     L
1614          ANI     8
1615          CNZ     ADD0
1616  SL4     INX     D
1617          DCR     C
1618          JNZ     SL1
1619          RET
1620  GKNI    LXI     D,KNOFF
1621          MVI     C,8
1622          JMP     STEP
1623  GKING   LXI     D,DIRS
1624          MVI     C,8
1625          CALL    STEP
1626          JMP     GCAST
1627  STEP    MVI     H,BRDH
1628  ST1     LDA     GFROM
1629          MOV     B,A
1630          LDAX    D
1631          ADD     B
1632          MOV     B,A
1633          ANI     88H
1634          JNZ     ST3
1635          MOV     L,B
1636          MOV     A,M
1637          ORA     A
1638          JZ      ST2
1639          MOV     L,A
1640          LDA     GCODE
1641          XRA     L
1642          ANI     8
1643          CNZ     ADD0
1644          JMP     ST3
1645  ST2     LDA     CAPONL
1646          ORA     A
1647          CZ      ADD0
1648  ST3     INX     D
1649          DCR     C
1650          JNZ     ST1
1651          RET
1652  ; castling: rights, empty squares, rook at home, the
1653  ; king not in check and not crossing an attacked square
1654  GCAST   LDA     CAPONL
1655          ORA     A
1656          RNZ
1657          LDA     STM
1658          ORA     A
1659          LDA     CASTL
1660          MVI     B,0
1661          JZ      GC1
1662          RRC
1663          RRC
1664          MVI     B,70H
1665  GC1     ANI     3
1666          RZ
1667          STA     GCRT
1668          MOV     A,B
1669          STA     GCBS
1670          ADI     4
1671          CALL    ATTOPP
1672          RNZ
1673          LDA     GCRT
1674          RRC
1675          JNC     GC4
1676          LDA     GCBS
1677          ADI     5
1678          MOV     L,A
1679          MVI     H,BRDH
1680          MOV     A,M
1681          INR     L
1682          ORA     M
1683          JNZ     GC4
1684          INR     L
1685          LDA     STM
1686          ORI     6
1687          CMP     M
1688          JNZ     GC4
1689          LDA     GCBS
1690          ADI     5
1691          CALL    ATTOPP
1692          JNZ     GC4
1693          LDA     GCBS
1694          ADI     6
1695          MOV     B,A
1696          MVI     A,40H
1697          CALL    ADDMV
1698  GC4     LDA     GCRT
1699          ANI     2
1700          RZ
1701          LDA     GCBS
1702          INR     A
1703          MOV     L,A
1704          MVI     H,BRDH
1705          MOV     A,M
1706          INR     L
1707          ORA     M
1708          INR     L
1709          ORA     M
1710          RNZ
1711          LDA     GCBS
1712          MOV     L,A
1713          LDA     STM
1714          ORI     6
1715          CMP     M
1716          RNZ
1717          LDA     GCBS
1718          ADI     3
1719          CALL    ATTOPP
1720          RNZ
1721          LDA     GCBS
1722          ADI     2
1723          MOV     B,A
1724          MVI     A,40H
1725          JMP     ADDMV
1726  GPAWN   LDA     STM
1727          ORA     A
1728          MVI     C,10H
1729          JZ      GP0
1730          MVI     C,0F0H
1731  GP0     LDA     GFROM
1732          ADD     C
1733          DCR     A
1734          CALL    GPCAP
1735          LDA     GFROM
1736          ADD     C
1737          INR     A
1738          CALL    GPCAP
1739          LDA     GFROM
1740          ADD     C
1741          MOV     B,A
1742          MVI     H,BRDH
1743          MOV     L,A
1744          MOV     A,M
1745          ORA     A
1746          RNZ
1747          CALL    PROMRK
1748          JZ      GPPRO
1749          LDA     CAPONL
1750          ORA     A
1751          RNZ
1752          CALL    ADD0
1753          LDA     STM
1754          ORA     A
1755          MVI     E,10H
1756          JZ      GP1
1757          MVI     E,60H
1758  GP1     LDA     GFROM
1759          ANI     0F0H
1760          CMP     E
1761          RNZ
1762          MOV     A,B
1763          ADD     C
1764          MOV     B,A
1765          MOV     L,A
1766          MOV     A,M
1767          ORA     A
1768          RNZ
1769          MVI     A,20H
1770          JMP     ADDMV
1771  GPCAP   MOV     B,A
1772          ANI     88H
1773          RNZ
1774          MVI     H,BRDH
1775          MOV     L,B
1776          MOV     A,M
1777          ORA     A
1778          JZ      GPEP
1779          MOV     L,A
1780          LDA     GCODE
1781          XRA     L
1782          ANI     8
1783          RZ
1784          CALL    PROMRK
1785          JZ      GPPRO
1786          JMP     ADD0
1787  GPEP    LDA     EPSQ
1788          CMP     B
1789          RNZ
1790          MVI     A,80H
1791          JMP     ADDMV
1792  GPPRO   MVI     A,7
1793          CALL    ADDMV
1794          LDA     CAPONL
1795          ORA     A
1796          RNZ
1797          MVI     A,6
1798          CALL    ADDMV
1799          MVI     A,5
1800          CALL    ADDMV
1801          MVI     A,2
1802          JMP     ADDMV
1803  PROMRK  LDA     STM
1804          ORA     A
1805          MOV     A,B
1806          JNZ     PRB
1807          ANI     0F0H
1808          CPI     70H
1809          RET
1810  PRB     ANI     0F0H
1811          RET
1812  ;
1813  ;*** ADDMV: store GFROM->B, flag A, with its order
1814  ; score (2026 move ordering): captures 40H+8*victim
1815  ; -attacker (MVV-LVA), killers 38H/37H, queening
1816  ; +60H, under-promotions 1, other moves 0.
1817  ADD0    XRA     A
1818  ADDMV   PUSH    D
1819          MOV     D,A
1820          LHLD    MVPUT
1821          LDA     GFROM
1822          MOV     M,A
1823          INX     H
1824          MOV     M,B
1825          INX     H
1826          MOV     M,D
1827          INX     H
1828          PUSH    H
1829          MOV     L,B
1830          MVI     H,BRDH
1831          MOV     A,M
1832          ANI     7
1833          MOV     E,A
1834          MOV     A,D
1835          ORA     A
1836          JP      AM1
1837          MVI     E,1
1838  AM1     MOV     A,E
1839          ORA     A
1840          JZ      AMQ
1841          ADD     A
1842          ADD     A
1843          ADD     A
1844          ADI     40H
1845          MOV     E,A
1846          LDA     GCODE
1847          ANI     7
1848          MOV     L,A
1849          MOV     A,E
1850          SUB     L
1851          JMP     AMP
1852  AMQ     LDA     GFROM
1853          MOV     L,A
1854          LDA     KIL1
1855          CMP     L
1856          JNZ     AMK2
1857          LDA     KIL1+1
1858          CMP     B
1859          MVI     A,38H
1860          JZ      AMP
1861  AMK2    LDA     KIL2
1862          CMP     L
1863          MVI     A,0
1864          JNZ     AMP
1865          LDA     KIL2+1
1866          CMP     B
1867          MVI     A,0
1868          JNZ     AMP
1869          MVI     A,37H
1870  AMP     MOV     E,A
1871          MOV     A,D
1872          ANI     7
1873          JZ      AMS
1874          CPI     7
1875          JZ      AMPQ
1876          MVI     E,1
1877          JMP     AMS
1878  AMPQ    MOV     A,E
1879          ADI     60H
1880          MOV     E,A
1881  AMS     POP     H
1882          MOV     M,E
1883          INX     H
1884          SHLD    MVPUT
1885          POP     D
1886          MVI     H,BRDH
1887          RET
1888  ;
1889  ;*** MAKE: play move (HL); 16-byte undo record ***
1890  ; The score is kept up to date as the move is made
1891  ; (2026 incremental evaluation).
1892  MAKE    MOV     A,M
1893          STA     MFROM
1894          INX     H
1895          MOV     A,M
1896          STA     MTO
1897          INX     H
1898          MOV     A,M
1899          STA     MFLAG
1900          MVI     H,BRDH
1901          LDA     MFROM
1902          MOV     L,A
1903          MOV     A,M
1904          STA     MPC
1905          MOV     A,L
1906          ADI     8
1907          MOV     L,A
1908          MOV     A,M
1909          STA     MSLOT
1910          LDA     MFLAG
1911          ORA     A
1912          LDA     MTO
1913          JP      MK1
1914          ANI     0FH
1915          MOV     B,A
1916          LDA     MFROM
1917          ANI     0F0H
1918          ORA     B
1919  MK1     STA     MCSQ
1920          MOV     L,A
1921          MOV     A,M
1922          STA     MCAP
1923          ORA     A
1924          JZ      MK2
1925          MOV     A,L
1926          ADI     8
1927          MOV     L,A
1928          MOV     A,M
1929          STA     MCSL
1930  ; the undo record is written with PUSH (fast on the
1931  ; 8080; interrupts off for these few microseconds)
1932  MK2     LHLD    UNDOP
1933          LXI     D,14
1934          DAD     D
1935          DI
1936          XCHG
1937          LXI     H,0
1938          DAD     SP
1939          SHLD    SPSAV
1940          XCHG
1941          SPHL
1942          LHLD    SCORE+1
1943          PUSH    H
1944          LHLD    HMC
1945          PUSH    H
1946          LHLD    CASTL
1947          PUSH    H
1948          LHLD    MCSL
1949          PUSH    H
1950          LHLD    MSLOT
1951          PUSH    H
1952          LHLD    MFLAG
1953          PUSH    H
1954          LHLD    MFROM
1955          PUSH    H
1956          LHLD    SPSAV
1957          SPHL
1958          EI
1959          LHLD    UNDOP
1960          LXI     D,16
1961          DAD     D
1962          SHLD    UNDOP
1963          LDA     MCAP
1964          ORA     A
1965          JZ      MK3
1966          MVI     H,PLISTH
1967          LDA     MCSL
1968          MOV     L,A
1969          MVI     M,0CCH
1970          MVI     H,BRDH
1971          LDA     MCSQ
1972          MOV     L,A
1973          MVI     M,0
1974          MOV     B,A
1975          LDA     MCAP
1976          CALL    SCSUB
1977          XRA     A
1978          STA     HMC
1979          JMP     MK4
1980  MK3     LDA     MPC
1981          ANI     7
1982          CPI     1
1983          LXI     H,HMC
1984          JZ      MK3P
1985          INR     M
1986          JMP     MK4
1987  MK3P    MVI     M,0
1988  MK4     LDA     MFROM
1989          MOV     B,A
1990          LDA     MPC
1991          CALL    SCSUB
1992          MVI     H,BRDH
1993          LDA     MFROM
1994          MOV     L,A
1995          MVI     M,0
1996          LDA     MFLAG
1997          ANI     7
1998          JZ      MK5
1999          MOV     B,A
2000          LDA     MPC
2001          ANI     8
2002          ORA     B
2003          JMP     MK6
2004  MK5     LDA     MPC
2005  MK6     MOV     D,A
2006          LDA     MTO
2007          MOV     L,A
2008          MOV     M,D
2009          ADI     8
2010          MOV     L,A
2011          LDA     MSLOT
2012          MOV     M,A
2013          MOV     L,A
2014          MVI     H,PLISTH
2015          LDA     MTO
2016          MOV     M,A
2017          MOV     B,A
2018          MOV     A,D
2019          CALL    SCADD
2020          LDA     MFLAG
2021          ANI     40H
2022          JZ      MK8
2023          LDA     MTO
2024          MOV     C,A
2025          ANI     0FH
2026          CPI     6
2027          MOV     A,C
2028          JNZ     MK7
2029          INR     A
2030          MOV     B,A
2031          DCR     C
2032          JMP     MKR
2033  MK7     SUI     2
2034          MOV     B,A
2035          INR     C
2036  MKR     CALL    MOVPC
2037          MOV     A,D
2038          STA     MTMP
2039          CALL    SCSUB
2040          LDA     MTMP
2041          MOV     B,C
2042          CALL    SCADD
2043  MK8     MVI     A,0CCH
2044          STA     EPSQ
2045          LDA     MFLAG
2046          ANI     20H
2047          JZ      MK9
2048          LDA     MFROM
2049          MOV     B,A
2050          LDA     MTO
2051          ADD     B
2052          RAR
2053          STA     EPSQ
2054  MK9     LDA     CASTL
2055          ORA     A
2056          JZ      MK11
2057          LDA     MFROM           ;only moves from or to the
2058          ANI     70H             ;first or last rank matter
2059          JZ      MK9A
2060          CPI     70H
2061          JZ      MK9A
2062          LDA     MTO
2063          ANI     70H
2064          JZ      MK9A
2065          CPI     70H
2066          JNZ     MK11
2067  MK9A    LXI     D,CRTAB
2068  MK10    LDAX    D
2069          CPI     0FFH
2070          JZ      MK11
2071          MOV     B,A
2072          INX     D
2073          LDA     MFROM
2074          CMP     B
2075          JZ      MKC
2076          LDA     MTO
2077          CMP     B
2078          JNZ     MKN
2079  MKC     LDAX    D
2080          LXI     H,CASTL
2081          ANA     M
2082          MOV     M,A
2083  MKN     INX     D
2084          JMP     MK10
2085  MK11    LDA     STM
2086          XRI     8
2087          STA     STM
2088          RET
2089  ;*** UNMAKE: take back the last MAKE ***
2090  UNMAKE  LHLD    UNDOP
2091          LXI     D,-16
2092          DAD     D
2093          SHLD    UNDOP
2094          DI
2095          XCHG
2096          LXI     H,0
2097          DAD     SP
2098          SHLD    SPSAV
2099          XCHG
2100          SPHL
2101          POP     H
2102          SHLD    MFROM
2103          POP     H
2104          SHLD    MFLAG
2105          POP     H
2106          SHLD    MSLOT
2107          POP     H
2108          SHLD    MCSL
2109          POP     H
2110          SHLD    CASTL
2111          POP     H
2112          SHLD    HMC
2113          POP     H
2114          MOV     A,L
2115          STA     SCORE+1
2116          LHLD    SPSAV
2117          SPHL
2118          EI
2119          MVI     H,BRDH
2120          LDA     MTO
2121          MOV     L,A
2122          MVI     M,0
2123          LDA     MFROM
2124          MOV     L,A
2125          LDA     MPC
2126          MOV     M,A
2127          MOV     A,L
2128          ADI     8
2129          MOV     L,A
2130          LDA     MSLOT
2131          MOV     M,A
2132          MOV     L,A
2133          MVI     H,PLISTH
2134          LDA     MFROM
2135          MOV     M,A
2136          LDA     MCAP
2137          ORA     A
2138          JZ      UM1
2139          MVI     H,BRDH
2140          LDA     MCSQ
2141          MOV     L,A
2142          LDA     MCAP
2143          MOV     M,A
2144          MOV     A,L
2145          ADI     8
2146          MOV     L,A
2147          LDA     MCSL
2148          MOV     M,A
2149          MOV     L,A
2150          MVI     H,PLISTH
2151          LDA     MCSQ
2152          MOV     M,A
2153  UM1     LDA     MFLAG
2154          ANI     40H
2155          CNZ     UNCAST
2156          LDA     STM
2157          XRI     8
2158          STA     STM
2159          RET
2160  UNCAST  LDA     MTO
2161          MOV     B,A
2162          ANI     0FH
2163          CPI     6
2164          MOV     A,B
2165          JNZ     UCQ
2166          DCR     A
2167          MOV     B,A
2168          ADI     2
2169          MOV     C,A
2170          JMP     MOVPC
2171  UCQ     INR     A
2172          MOV     B,A
2173          SUI     3
2174          MOV     C,A
2175  ; MOVPC: piece on B to empty C; D = piece, E = slot
2176  MOVPC   MVI     H,BRDH
2177          MOV     L,B
2178          MOV     D,M
2179          MVI     M,0
2180          MOV     A,L
2181          ADI     8
2182          MOV     L,A
2183          MOV     E,M
2184          MOV     L,C
2185          MOV     M,D
2186          MOV     A,L
2187          ADI     8
2188          MOV     L,A
2189          MOV     M,E
2190          MOV     L,E
2191          MVI     H,PLISTH
2192          MOV     M,C
2193          RET
2194  ;
2195  ;*** evaluation (2026): material + piece-square
2196  ; tables, kept in SCORE by MAKE; the kings' tables
2197  ; (middle game or end game) are added by EVAL.
2198  ; PSQV: value of piece A on square B, owner's view
2199  PSQV    MOV     D,A
2200          ANI     7
2201          CPI     3
2202          JZ      PSQK
2203          ADD     A
2204          ADD     A
2205          LXI     H,PSTIX
2206          ADD     L
2207          MOV     L,A
2208          MOV     A,D
2209          ANI     8
2210          MOV     A,B
2211          JZ      PSQ1
2212          XRI     70H
2213  PSQ1    ADD     M
2214          INX     H
2215          MOV     E,M
2216          INX     H
2217          PUSH    H
2218          MOV     L,A
2219          MOV     H,E
2220          MOV     A,M
2221          POP     H
2222          MOV     E,M
2223          INX     H
2224          MOV     D,M
2225          MOV     H,A
2226          ADD     E
2227          MOV     E,A
2228          MOV     A,D
2229          ACI     0
2230          MOV     D,A
2231          MOV     A,H
2232          ORA     A
2233          RP
2234          DCR     D
2235          RET
2236  PSQK    LXI     D,0
2237          RET
2238  SCADD   PUSH    PSW
2239          CALL    PSQV
2240          POP     PSW
2241          ANI     8
2242          JZ      SCPLUS
2243  SCMIN   LHLD    SCORE
2244          MOV     A,L
2245          SUB     E
2246          MOV     L,A
2247          MOV     A,H
2248          SBB     D
2249          MOV     H,A
2250          SHLD    SCORE
2251          RET
2252  SCPLUS  LHLD    SCORE
2253          DAD     D
2254          SHLD    SCORE
2255          RET
2256  SCSUB   PUSH    PSW
2257          CALL    PSQV
2258          POP     PSW
2259          ANI     8
2260          JZ      SCMIN
2261          JMP     SCPLUS
2262  ; EVAL: HL = 8000H + value for the side to move
2263  ; (scores are kept biased by 8000H so that an
2264  ; unsigned compare orders them and 0-x negates)
2265  EVAL    LDA     ENDG
2266          MOV     C,A
2267          LHLD    SCORE
2268          XCHG
2269          LDA     PLIST
2270          ADD     C
2271          MOV     L,A
2272          MVI     H,22H
2273          MOV     A,M
2274          CALL    ADDSX
2275          LDA     PLIST+16
2276          XRI     70H
2277          ADD     C
2278          MOV     L,A
2279          MOV     A,M
2280          CMA
2281          INR     A
2282          CALL    ADDSX
2283          LDA     STM
2284          ORA     A
2285          CNZ     NEGDE
2286          LXI     H,8000H
2287          DAD     D
2288          RET
2289  ADDSX   MOV     B,A
2290          ADD     E
2291          MOV     E,A
2292          MOV     A,D
2293          ACI     0
2294          MOV     D,A
2295          MOV     A,B
2296          ORA     A
2297          RP
2298          DCR     D
2299          RET
2300  NEGDE   MOV     A,E
2301          CMA
2302          MOV     E,A
2303          MOV     A,D
2304          CMA
2305          MOV     D,A
2306          INX     D
2307          RET
2308  NEGHL   MOV     A,L
2309          CMA
2310          MOV     L,A
2311          MOV     A,H
2312          CMA
2313          MOV     H,A
2314          INX     H
2315          RET
2316  ; SETEND: king tables for the end game when each
2317  ; side has no queen or a queen and at most a minor
2318  ; piece (Michniewski's rule)
2319  SIDEOK  MVI     D,0
2320          MVI     E,0
2321          MVI     B,16
2322  SO1     MVI     H,PLISTH
2323          MOV     L,C
2324          MOV     A,M
2325          CPI     0CCH
2326          JZ      SO3
2327          MOV     L,A
2328          MVI     H,BRDH
2329          MOV     A,M
2330          ANI     7
2331          CPI     7
2332          JNZ     SO2
2333          INR     D
2334          JMP     SO3
2335  SO2     CPI     6
2336          JNZ     SO2B
2337          MOV     A,E
2338          ADI     5
2339          MOV     E,A
2340          JMP     SO3
2341  SO2B    CPI     2
2342          JZ      SO2C
2343          CPI     5
2344          JNZ     SO3
2345  SO2C    MOV     A,E
2346          ADI     3
2347          MOV     E,A
2348  SO3     INR     C
2349          DCR     B
2350          JNZ     SO1
2351          MOV     A,D
2352          ORA     A
2353          MVI     A,1
2354          RZ
2355          MOV     A,E
2356          CPI     4
2357          MVI     A,1
2358          RC
2359          XRA     A
2360          RET
2361  SETEND  MVI     C,0
2362          CALL    SIDEOK
2363          STA     MTMP
2364          MVI     C,16
2365          CALL    SIDEOK
2366          LXI     H,MTMP
2367          ANA     M
2368          MVI     A,08H
2369          JZ      SE1
2370          MVI     A,80H
2371  SE1     STA     ENDG
2372          RET
2373  ;
2374  ;*** SEARCH (2026, completes 1979 H047D): negamax
2375  ; alpha-beta. In: ALPHA, BETA, DEPTH, PLY. Out: HL.
2376  ; The node's state lives in fixed cells and is pushed
2377  ; on the stack around each child (8080 style).
2378  ; DEPTH 0 = quiescence: stand pat, then captures.
2379  SEARCH  CALL    NODEC
2380          LDA     ABORT
2381          ORA     A
2382          JNZ     SRRET
2383          LDA     PLY
2384          CPI     MAXPLY
2385          JNC     EVAL
2386          LHLD    MVPUT
2387          LXI     D,-MVLIM
2388          DAD     D
2389          JC      EVAL
2390          LDA     DEPTH
2391          ORA     A
2392          JZ      QS
2393          CALL    CHKME
2394          STA     INCHK
2395          ORA     A
2396          JZ      SR1
2397          LXI     H,DEPTH         ;check extension
2398          INR     M
2399  SR1     XRA     A               ;futility (2026): one ply from
2400          STA     FUTON           ;the leaves, quiet moves cannot
2401          LDA     DEPTH           ;lift a score far below alpha
2402          CPI     1
2403          JNZ     SR1B
2404          LDA     INCHK
2405          ORA     A
2406          JNZ     SR1B
2407          CALL    EVAL
2408          LXI     D,150           ;margin: 1.5 pawns
2409          DAD     D
2410          SHLD    FUTV
2411          MVI     A,1
2412          STA     FUTON
2413  SR1B    CALL    SETKIL
2414          XRA     A
2415          STA     CAPONL
2416          JMP     SRGEN
2417  QS      CALL    EVAL            ;stand pat
2418          XCHG
2419          LHLD    BETA
2420          MOV     A,E
2421          SUB     L
2422          MOV     A,D
2423          SBB     H
2424          JC      QS1
2425          RET
2426  QS1     LHLD    ALPHA
2427          MOV     A,L
2428          SUB     E
2429          MOV     A,H
2430          SBB     D
2431          JNC     QS2
2432          XCHG
2433          SHLD    ALPHA
2434  QS2     CALL    CHKME           ;(only when not cut off)
2435          STA     INCHK
2436          CALL    NOKILL
2437          MVI     A,1
2438          STA     CAPONL
2439  SRGEN   LHLD    MVPUT
2440          SHLD    MVCUR
2441          CALL    GEN
2442          LHLD    MVPUT
2443          SHLD    MVHI
2444          XRA     A
2445          STA     LEGAL
2446  SRLOOP  CALL    PICK
2447          JZ      SREND
2448          LDA     DEPTH
2449          CPI     1
2450          JNZ     SRMK
2451          LDA     FUTON
2452          ORA     A
2453          JZ      SRMK
2454          LDA     LEGAL
2455          ORA     A
2456          JZ      SRMK
2457          LHLD    MVCUR
2458          INX     H
2459          INX     H
2460          MOV     A,M
2461          INX     H
2462          MOV     B,M
2463          ANI     87H
2464          JNZ     SRMK
2465          MOV     A,B
2466          CPI     40H
2467          JNC     SRMK
2468          LHLD    ALPHA
2469          XCHG
2470          LHLD    FUTV
2471          MOV     A,E
2472          SUB     L
2473          MOV     A,D
2474          SBB     H
2475          JNC     SRNEXT          ;pruned
2476  SRMK    LHLD    MVCUR
2477          CALL    MAKE
2478          CALL    ILLEG
2479          JNZ     SRSKIP
2480          LXI     H,LEGAL
2481          INR     M
2482          LHLD    ALPHA
2483          PUSH    H
2484          LHLD    BETA
2485          PUSH    H
2486          LHLD    DEPTH
2487          PUSH    H
2488          LHLD    INCHK
2489          PUSH    H
2490          LHLD    MVCUR
2491          PUSH    H
2492          LHLD    MVHI
2493          PUSH    H
2494          LHLD    ALPHA
2495          CALL    NEGHL
2496          XCHG
2497          LHLD    BETA
2498          CALL    NEGHL
2499          SHLD    ALPHA
2500          XCHG
2501          SHLD    BETA
2502          LXI     H,DEPTH
2503          MOV     A,M
2504          ORA     A
2505          JZ      SR2
2506          DCR     M
2507  SR2     LXI     H,PLY
2508          INR     M
2509          CALL    SEARCH
2510          CALL    NEGHL
2511          XCHG
2512          POP     H
2513          SHLD    MVHI
2514          SHLD    MVPUT
2515          POP     H
2516          SHLD    MVCUR
2517          POP     H
2518          SHLD    INCHK
2519          POP     H
2520          SHLD    DEPTH
2521          POP     H
2522          SHLD    BETA
2523          POP     H
2524          SHLD    ALPHA
2525          PUSH    D
2526          CALL    UNMAKE
2527          POP     D
2528          LDA     ABORT
2529          ORA     A
2530          JNZ     SRRET
2531          LHLD    ALPHA
2532          MOV     A,L
2533          SUB     E
2534          MOV     A,H
2535          SBB     D
2536          JNC     SRNEXT
2537          LHLD    BETA
2538          MOV     A,E
2539          SUB     L
2540          MOV     A,D
2541          SBB     H
2542          JNC     SRCUT
2543          XCHG
2544          SHLD    ALPHA
2545          JMP     SRNEXT
2546  SRCUT   CALL    KILUPD          ;beta cut-off
2547          LHLD    BETA
2548          RET
2549  SRSKIP  CALL    UNMAKE
2550  SRNEXT  CALL    NEXTMV
2551          JMP     SRLOOP
2552  SREND   LDA     DEPTH
2553          ORA     A
2554          JZ      SRRET
2555          LDA     LEGAL
2556          ORA     A
2557          JNZ     SRRET
2558          LDA     INCHK
2559          ANI     1
2560          LXI     H,8000H         ;stalemate: draw
2561          RZ
2562          LDA     PLY             ;mated: shorter is worse
2563          MOV     E,A
2564          MVI     D,0
2565          LXI     H,MATEL
2566          DAD     D
2567          RET
2568  SRRET   LHLD    ALPHA
2569          RET
2570  ;
2571  ; PICK: best-scored move left to MVCUR (selection);
2572  ; once only 0-scored moves are left, INCHK+80H stops
2573  ; the scanning. Z if no move is left.
2574  PICK    CALL    ATEND
2575          RZ
2576          LDA     INCHK
2577          ORA     A
2578          JM      PKNZ
2579          SHLD    PKBEST
2580          INX     H
2581          INX     H
2582          INX     H
2583          MOV     B,M
2584          INX     H
2585  PK2     MOV     A,L
2586          CMP     E
2587          JNZ     PK3
2588          MOV     A,H
2589          CMP     D
2590          JZ      PK5
2591  PK3     INX     H
2592          INX     H
2593          INX     H
2594          MOV     A,M
2595          CMP     B
2596          JC      PK4
2597          JZ      PK4
2598          MOV     B,A
2599          DCX     H
2600          DCX     H
2601          DCX     H
2602          SHLD    PKBEST
2603          INX     H
2604          INX     H
2605          INX     H
2606  PK4     INX     H
2607          JMP     PK2
2608  PK5     MOV     A,B
2609          ORA     A
2610          JNZ     PK6
2611          LDA     INCHK
2612          ORI     80H
2613          STA     INCHK
2614  PK6     LHLD    PKBEST
2615          XCHG
2616          LHLD    MVCUR
2617          MOV     A,L
2618          CMP     E
2619          JNZ     PK7
2620          MOV     A,H
2621          CMP     D
2622          JZ      PKNZ
2623  PK7     MVI     C,4
2624  PK8     LDAX    D
2625          MOV     B,M
2626          MOV     M,A
2627          MOV     A,B
2628          STAX    D
2629          INX     H
2630          INX     D
2631          DCR     C
2632          JNZ     PK8
2633  PKNZ    MVI     A,1
2634          ORA     A
2635          RET
2636  ; killer moves: two quiet moves per ply that caused
2637  ; a cut-off, tried right after the captures
2638  SETKIL  CALL    KILPTR
2639          MOV     E,M
2640          INX     H
2641          MOV     D,M
2642          INX     H
2643          XCHG
2644          SHLD    KIL1
2645          XCHG
2646          MOV     E,M
2647          INX     H
2648          MOV     D,M
2649          XCHG
2650          SHLD    KIL2
2651          RET
2652  KILPTR  LDA     PLY
2653          ADD     A
2654          ADD     A
2655          MOV     E,A
2656          MVI     D,0
2657          LXI     H,KILLS
2658          DAD     D
2659          RET
2660  KILUPD  LDA     MCAP
2661          ORA     A
2662          RNZ
2663          LDA     MFLAG
2664          ANI     87H
2665          RNZ
2666          CALL    KILPTR
2667          LDA     MFROM
2668          CMP     M
2669          JNZ     KU1
2670          INX     H
2671          LDA     MTO
2672          CMP     M
2673          RZ
2674          DCX     H
2675  KU1     MOV     E,M
2676          INX     H
2677          MOV     D,M
2678          INX     H
2679          MOV     M,E
2680          INX     H
2681          MOV     M,D
2682          DCX     H
2683          DCX     H
2684          DCX     H
2685          LDA     MFROM
2686          MOV     M,A
2687          INX     H
2688          LDA     MTO
2689          MOV     M,A
2690          RET
2691  ; NODEC: count a node; every 64 nodes check the clock
2692  NODEC   LXI     H,NODES
2693          INR     M
2694          MOV     A,M
2695          JNZ     NC0
2696          INX     H
2697          INR     M
2698          JNZ     NC1
2699          INX     H
2700          INR     M
2701          JNZ     NC1
2702          INX     H
2703          INR     M
2704          JMP     NC1
2705  NC0     ANI     3FH
2706          RNZ
2707  NC1     CALL    ELAPS
2708          XCHG
2709          LHLD    TLIMIT
2710          MOV     A,E
2711          SUB     L
2712          MOV     A,D
2713          SBB     H
2714          RC
2715          MVI     A,1
2716          STA     ABORT
2717          RET
2718  ; ELAPS: HL = ticks (1/60 s) since TSTART
2719  ELAPS   DI
2720          LHLD    TIMER
2721          EI
2722          XCHG
2723          LHLD    TSTART
2724          MOV     A,E
2725          SUB     L
2726          MOV     L,A
2727          MOV     A,D
2728          SBB     H
2729          MOV     H,A
2730          RET
2731  ;
2732  ;*** THINK (2026, completes 1979 GO H047D) ***
2733  ; legal root moves, opening book, then iterative
2734  ; deepening: depth 1, 2, 3 ... until the time for
2735  ; the move (S/B/N) runs out; each iteration starts
2736  ; with the best move of the one before.
2737  THINK   LXI     H,0
2738          SHLD    NODES
2739          SHLD    NODES+2
2740          XRA     A
2741          STA     ABORT
2742          STA     RKIND
2743          STA     RDEP
2744          STA     RLAST
2745          DI
2746          LHLD    TIMER
2747          EI
2748          SHLD    TSTART
2749          LHLD    MODE
2750          SHLD    TLIMIT
2751          CALL    SETEND
2752          LXI     H,KILLS
2753          MVI     B,0
2754  TK0     MVI     M,0FFH
2755          INX     H
2756          DCR     B
2757          JNZ     TK0
2758          CALL    GENLEG
2759          LHLD    MVHI
2760          SHLD    RMHI
2761          LXI     H,MVSTK
2762          SHLD    RMLO
2763          CALL    RSORT
2764          LXI     H,MVSTK
2765          CALL    SETBST
2766          LXI     H,MVSTK+4
2767          XCHG
2768          LHLD    RMHI
2769          MOV     A,L
2770          CMP     E
2771          JNZ     TK1
2772          MOV     A,H
2773          CMP     D
2774          JNZ     TK1
2775          MVI     A,2             ;only one move
2776          STA     RKIND
2777          RET
2778  TK1     CALL    BOOK
2779          RNZ
2780          MVI     A,1
2781          STA     CDEP
2782  ID1     LXI     H,LOWB
2783          SHLD    RALPHA
2784          LHLD    RMLO
2785          SHLD    RIDX
2786          SHLD    RBI
2787  ID2     LHLD    RIDX
2788          CALL    MAKE
2789          LXI     H,LOWB
2790          SHLD    ALPHA
2791          LHLD    RALPHA
2792          CALL    NEGHL
2793          SHLD    BETA
2794          LDA     CDEP
2795          DCR     A
2796          STA     DEPTH
2797          MVI     A,1
2798          STA     PLY
2799          LHLD    RMHI
2800          SHLD    MVPUT
2801          CALL    SEARCH
2802          CALL    NEGHL
2803          PUSH    H
2804          CALL    UNMAKE
2805          POP     D
2806          LDA     ABORT
2807          ORA     A
2808          JNZ     IDAB
2809          LHLD    RALPHA
2810          MOV     A,L
2811          SUB     E
2812          MOV     A,H
2813          SBB     D
2814          JNC     ID3
2815          XCHG
2816          SHLD    RALPHA
2817          LHLD    RIDX
2818          SHLD    RBI
2819  ID3     LHLD    RIDX
2820          LXI     D,4
2821          DAD     D
2822          SHLD    RIDX
2823          XCHG
2824          LHLD    RMHI
2825          MOV     A,L
2826          CMP     E
2827          JNZ     ID2
2828          MOV     A,H
2829          CMP     D
2830          JNZ     ID2
2831          CALL    RFRONT          ;best first next time
2832          LHLD    RMLO
2833          CALL    SETBST
2834          LHLD    RALPHA
2835          SHLD    RSC
2836          LDA     CDEP
2837          STA     RDEP
2838          LHLD    RSC             ;a mate found: stop
2839          LXI     D,9770H
2840          MOV     A,L
2841          SUB     E
2842          MOV     A,H
2843          SBB     D
2844          RNC
2845          LXI     D,6891H
2846          MOV     A,L
2847          SUB     E
2848          MOV     A,H
2849          SBB     D
2850          RC
2851          CALL    ELAPS           ;half the time used: stop
2852          DAD     H
2853          XCHG
2854          LHLD    TLIMIT
2855          MOV     A,E
2856          SUB     L
2857          MOV     A,D
2858          SBB     H
2859          RNC
2860          LDA     CDEP
2861          CPI     30
2862          RNC
2863          INR     A
2864          STA     CDEP
2865          JMP     ID1
2866  IDAB    LHLD    RBI             ;time out in an iteration
2867          XCHG
2868          LHLD    RMLO
2869          MOV     A,L
2870          CMP     E
2871          JNZ     IDAB1
2872          MOV     A,H
2873          CMP     D
2874          RZ
2875  IDAB1   XCHG
2876          CALL    SETBST
2877          LHLD    RALPHA
2878          SHLD    RSC
2879          MVI     A,1
2880          STA     RLAST
2881          RET
2882  SETBST  LXI     D,RBEST
2883          MVI     C,3
2884          JMP     COPYC
2885  RSORT   LHLD    RMLO
2886          SHLD    MVCUR
2887          LHLD    RMHI
2888          SHLD    MVHI
2889          XRA     A
2890          STA     INCHK
2891  RS1     CALL    PICK
2892          RZ
2893          CALL    NEXTMV
2894          JMP     RS1
2895  ; RFRONT: move entry RBI to RMLO, the others down
2896  RFRONT  LHLD    RBI
2897          MOV     E,M
2898          INX     H
2899          MOV     D,M
2900          INX     H
2901          MOV     C,M
2902          INX     H
2903          MOV     B,M
2904          PUSH    B
2905          PUSH    D
2906          LHLD    RMLO
2907          XCHG
2908          LHLD    RBI
2909          MOV     A,L
2910          SUB     E
2911          MOV     C,A
2912          MOV     A,H
2913          SBB     D
2914          MOV     B,A
2915          LHLD    RBI
2916          DCX     H
2917          MOV     D,H
2918          MOV     E,L
2919          INX     D
2920          INX     D
2921          INX     D
2922          INX     D
2923  RF1     MOV     A,B
2924          ORA     C
2925          JZ      RF2
2926          MOV     A,M
2927          STAX    D
2928          DCX     H
2929          DCX     D
2930          DCX     B
2931          JMP     RF1
2932  RF2     LHLD    RMLO
2933          POP     D
2934          MOV     M,E
2935          INX     H
2936          MOV     M,D
2937          INX     H
2938          POP     B
2939          MOV     M,C
2940          INX     H
2941          MOV     M,B
2942          RET
2943  ;
2944  ;*** BOOK (2026): lines from the start position; all
2945  ; lines whose first moves are the game's moves offer
2946  ; their next move; one is picked by the clock.
2947  BOOK    LDA     BOOKOK
2948          ORA     A
2949          RZ
2950          LHLD    NPLY
2951          MOV     A,H
2952          ORA     A
2953          JNZ     BKNO
2954          MOV     A,L
2955          CPI     16
2956          JNC     BKNO
2957          STA     TMPW
2958          XRA     A
2959          STA     NCAND
2960          LXI     H,BOOKT
2961  BK1     MOV     A,M
2962          CPI     0FEH
2963          JZ      BK5
2964          PUSH    H
2965          LXI     D,GAME
2966          LDA     TMPW
2967          MOV     C,A
2968  BK2     MOV     A,C
2969          ORA     A
2970          JZ      BK3
2971          MOV     A,M
2972          CPI     0FFH
2973          JZ      BKSKIP
2974          LDAX    D
2975          CMP     M
2976          JNZ     BKSKIP
2977          INX     H
2978          INX     D
2979          LDAX    D
2980          CMP     M
2981          JNZ     BKSKIP
2982          INX     H
2983          INX     D
2984          INX     D
2985          DCR     C
2986          JMP     BK2
2987  BK3     MOV     A,M
2988          CPI     0FFH
2989          JZ      BKSKIP
2990          XCHG
2991          LDA     NCAND
2992          CPI     16
2993          JNC     BKSKIP
2994          MOV     L,A
2995          INR     A
2996          STA     NCAND
2997          MVI     H,0
2998          DAD     H
2999          LXI     B,CAND
3000          DAD     B
3001          MOV     M,E
3002          INX     H
3003          MOV     M,D
3004  BKSKIP  POP     H
3005  BK4     MOV     A,M
3006          INX     H
3007          CPI     0FFH
3008          JNZ     BK4
3009          JMP     BK1
3010  BK5     LDA     NCAND
3011          ORA     A
3012          JZ      BKNO
3013          MOV     B,A
3014          LDA     TIMER
3015  BK6     CMP     B
3016          JC      BK7
3017          SUB     B
3018          JMP     BK6
3019  BK7     MOV     L,A
3020          MVI     H,0
3021          DAD     H
3022          LXI     D,CAND
3023          DAD     D
3024          MOV     E,M
3025          INX     H
3026          MOV     D,M
3027          LHLD    RMLO
3028  BK8     PUSH    D
3029          XCHG
3030          LHLD    RMHI
3031          MOV     A,L
3032          CMP     E
3033          JNZ     BK8A
3034          MOV     A,H
3035          CMP     D
3036          JZ      BKNOP
3037  BK8A    XCHG
3038          POP     D
3039          LDAX    D
3040          CMP     M
3041          JNZ     BK9
3042          INX     D
3043          INX     H
3044          LDAX    D
3045          CMP     M
3046          DCX     D
3047          DCX     H
3048          JNZ     BK9
3049          CALL    SETBST
3050          MVI     A,1
3051          STA     RKIND
3052          ORA     A
3053          RET
3054  BK9     INX     H
3055          INX     H
3056          INX     H
3057          INX     H
3058          JMP     BK8
3059  BKNOP   POP     D
3060  BKNO    XRA     A
3061          RET
3062  ;
3063  ;*** SHOWMV: MC : 64-44 (e2-e4) and the search ***
3064  SHOWMV  LXI     H,TXMC
3065          CALL    STRG
3066          LDA     RBEST+2
3067          ANI     40H
3068          JZ      SM1
3069          LXI     H,TXOO
3070          LDA     RBEST+1
3071          ANI     0FH
3072          CPI     6
3073          JZ      SM0
3074          LXI     H,TXOOO
3075  SM0     CALL    STRG
3076          JMP     SM2
3077  SM1     LDA     RBEST
3078          CALL    PRMC
3079          MVI     B,'-'
3080          CALL    WH1
3081          LDA     RBEST+1
3082          CALL    PRMC
3083  SM2     MVI     B,' '
3084          CALL    WH1
3085          MVI     B,'('
3086          CALL    WH1
3087          LDA     RBEST
3088          CALL    PRALG
3089          MVI     B,'-'
3090          CALL    WH1
3091          LDA     RBEST+1
3092          CALL    PRALG
3093          LDA     RBEST+2
3094          ANI     7
3095          JZ      SM3
3096          MOV     C,A
3097          MVI     B,'='
3098          CALL    WH1
3099          MOV     A,C
3100          LXI     H,PLET
3101          ADD     L
3102          MOV     L,A
3103          MOV     B,M
3104          CALL    WH1
3105  SM3     MVI     B,')'
3106          CALL    WH1
3107          CALL    CROUT
3108          LDA     RKIND
3109          LXI     H,TXBOOK
3110          CPI     1
3111          JZ      H01DA
3112          LXI     H,TXONLY
3113          CPI     2
3114          JZ      H01DA
3115          LXI     H,TXDEP
3116          CALL    STRG
3117          LDA     RDEP
3118          MOV     L,A
3119          MVI     H,0
3120          CALL    PRDEC
3121          LDA     RLAST
3122          ORA     A
3123          LXI     H,TXPART
3124          CNZ     STRG
3125          LXI     H,TXNOD
3126          CALL    STRG
3127          LXI     H,NODES
3128          CALL    PRD32
3129          MVI     B,','
3130          CALL    WH1
3131          MVI     B,' '
3132          CALL    WH1
3133          LHLD    RTIME
3134          CALL    PRTIM
3135          LXI     H,TXSEC
3136          CALL    STRG
3137          CALL    PRSCR
3138          JMP     CROUT
3139  PRMC    LXI     H,XMASK
3140          XRA     M
3141          MOV     C,A
3142          RRC
3143          RRC
3144          RRC
3145          RRC
3146          ANI     7
3147          ADI     '0'
3148          MOV     B,A
3149          CALL    WH1
3150          MOV     A,C
3151          ANI     7
3152          ADI     '0'
3153          MOV     B,A
3154          JMP     WH1
3155  PRALG   MOV     C,A
3156          ANI     7
3157          ADI     'a'
3158          MOV     B,A
3159          CALL    WH1
3160          MOV     A,C
3161          RRC
3162          RRC
3163          RRC
3164          RRC
3165          ANI     7
3166          ADI     '1'
3167          MOV     B,A
3168          JMP     WH1
3169  ; PRSCR: the score in pawns from the mover's view
3170  PRSCR   LHLD    RSC
3171          LXI     D,8000H
3172          MOV     A,L
3173          SUB     E
3174          MOV     L,A
3175          MOV     A,H
3176          SBB     D
3177          MOV     H,A
3178          ORA     A
3179          MVI     B,'+'
3180          JP      PS1
3181          CALL    NEGHL
3182          MVI     B,'-'
3183  PS1     CALL    WH1
3184          PUSH    H
3185          LXI     D,-6000
3186          DAD     D
3187          POP     H
3188          JNC     PS2
3189          LXI     H,TXMATE
3190          JMP     STRG
3191  PS2     LXI     D,100
3192          CALL    DIV16
3193          PUSH    D
3194          CALL    PRDEC
3195          MVI     B,'.'
3196          CALL    WH1
3197          POP     H
3198          MOV     A,L
3199          CPI     10
3200          JNC     PRDEC
3201          MVI     B,'0'
3202          CALL    WH1
3203  ; PRDEC: HL in decimal
3204  PRDEC   LXI     D,10
3205          CALL    DIV16
3206          PUSH    D
3207          MOV     A,H
3208          ORA     L
3209          CNZ     PRDEC
3210          POP     D
3211          MOV     A,E
3212          ADI     '0'
3213          MOV     B,A
3214          JMP     WH1
3215  ; PRTIM: HL ticks as seconds with one decimal
3216  PRTIM   LXI     D,60
3217          CALL    DIV16
3218          PUSH    D
3219          CALL    PRDEC
3220          MVI     B,'.'
3221          CALL    WH1
3222          POP     H
3223          LXI     D,6
3224          CALL    DIV16
3225          JMP     PRDEC
3226  ; DIV16: HL/DE: HL quotient, DE remainder
3227  DIV16   MOV     B,D
3228          MOV     C,E
3229          LXI     D,0
3230          MVI     A,16
3231  DV1     PUSH    PSW
3232          DAD     H
3233          MOV     A,E
3234          RAL
3235          MOV     E,A
3236          MOV     A,D
3237          RAL
3238          MOV     D,A
3239          MOV     A,E
3240          SUB     C
3241          MOV     A,D
3242          SBB     B
3243          JC      DV2
3244          MOV     A,E
3245          SUB     C
3246          MOV     E,A
3247          MOV     A,D
3248          SBB     B
3249          MOV     D,A
3250          INX     H
3251  DV2     POP     PSW
3252          DCR     A
3253          JNZ     DV1
3254          RET
3255  ; PRD32: the 4-byte number at HL in decimal
3256  PRD32   LXI     D,CAND
3257          MVI     C,4
3258          CALL    COPYC
3259          MVI     A,0FFH
3260          PUSH    PSW
3261  PR1     LXI     H,CAND+3
3262          MVI     C,4
3263          LXI     D,0
3264  PR2     PUSH    H
3265          MOV     A,M
3266          MOV     H,E
3267          MOV     L,A
3268          LXI     D,10
3269          PUSH    B
3270          CALL    DIV16
3271          POP     B
3272          MOV     A,L
3273          POP     H
3274          MOV     M,A
3275          DCX     H
3276          DCR     C
3277          JNZ     PR2
3278          MOV     A,E
3279          ADI     '0'
3280          PUSH    PSW
3281          LXI     H,CAND
3282          MOV     A,M
3283          INX     H
3284          ORA     M
3285          INX     H
3286          ORA     M
3287          INX     H
3288          ORA     M
3289          JNZ     PR1
3290  PR3     POP     PSW
3291          CPI     0FFH
3292          RZ
3293          MOV     B,A
3294          CALL    WH1
3295          JMP     PR3
3296  ;
3297  ;*** P n: perft (2026), counts the leaf positions
3298  ; of the legal move tree n plies deep (a test of
3299  ; the move generator, as in modern engines)
3300  PERFC   LDA     INBUF+2
3301          SUI     '1'
3302          CPI     9
3303          JNC     H012C
3304          INR     A
3305          STA     DEPTH
3306          LXI     H,0
3307          SHLD    PCNT
3308          SHLD    PCNT+2
3309          DI
3310          LHLD    TIMER
3311          EI
3312          SHLD    TSTART
3313          LXI     H,MVSTK
3314          SHLD    MVPUT
3315          CALL    NOKILL
3316          CALL    PERFT
3317          LXI     H,PCNT
3318          CALL    PRD32
3319          LXI     H,TXNODES
3320          CALL    STRG
3321          CALL    ELAPS
3322          CALL    PRTIM
3323          LXI     H,TXS
3324          CALL    H01DA
3325          JMP     H0075
3326  PERFT   CALL    CHKME
3327          STA     INCHK
3328          XRA     A
3329          STA     CAPONL
3330          LHLD    MVPUT
3331          SHLD    MVCUR
3332          CALL    GEN
3333          LHLD    MVPUT
3334          SHLD    MVHI
3335  PF1     CALL    ATEND
3336          RZ
3337          CALL    MAKE
3338          CALL    ILLEG
3339          JNZ     PF3
3340          LDA     DEPTH
3341          CPI     1
3342          JNZ     PF2
3343          LXI     H,PCNT
3344          INR     M
3345          JNZ     PF3
3346          INX     H
3347          INR     M
3348          JNZ     PF3
3349          INX     H
3350          INR     M
3351          JNZ     PF3
3352          INX     H
3353          INR     M
3354          JMP     PF3
3355  PF2     LHLD    DEPTH
3356          PUSH    H
3357          LHLD    INCHK
3358          PUSH    H
3359          LHLD    MVCUR
3360          PUSH    H
3361          LHLD    MVHI
3362          PUSH    H
3363          LXI     H,DEPTH
3364          DCR     M
3365          CALL    PERFT
3366          POP     H
3367          SHLD    MVHI
3368          SHLD    MVPUT
3369          POP     H
3370          SHLD    MVCUR
3371          POP     H
3372          SHLD    INCHK
3373          POP     H
3374          SHLD    DEPTH
3375  PF3     CALL    UNMAKE
3376          CALL    NEXTMV
3377          JMP     PF1
3378  ;
3379  ;*** F fen: set up a position (2026) ***
3380  FENCMD  LXI     H,INBUF+1
3381          CALL    SKIPSP
3382          PUSH    H
3383          CALL    CLRPOS
3384          MVI     A,1
3385          STA     PFROM
3386          MVI     A,17
3387          STA     PTO
3388          MVI     D,70H
3389          POP     H
3390  FN1     MOV     A,M
3391          INX     H
3392          CPI     ' '
3393          JZ      FN5
3394          CPI     0DH
3395          JZ      FNBAD
3396          CPI     '/'
3397          JNZ     FN2
3398          MOV     A,D
3399          ANI     0F0H
3400          SUI     10H
3401          MOV     D,A
3402          JMP     FN1
3403  FN2     CPI     '1'
3404          JC      FNBAD
3405          CPI     '9'
3406          JNC     FN3
3407          SUI     '0'
3408          ADD     D
3409          MOV     D,A
3410          JMP     FN1
3411  FN3     PUSH    H
3412          CALL    FENPC
3413          JNZ     FNBADP
3414          MOV     A,D
3415          ANI     88H
3416          JNZ     FNBADP
3417          MOV     A,B
3418          ANI     7
3419          CPI     3
3420          JNZ     FN4
3421          MOV     A,B
3422          ANI     8
3423          ADD     A
3424          MOV     C,A
3425          JMP     FN4B
3426  FN4     MOV     A,B
3427          ANI     8
3428          LXI     H,PFROM
3429          JZ      FN4A
3430          LXI     H,PTO
3431  FN4A    MOV     C,M
3432          INR     M
3433          MOV     A,C
3434          ANI     0FH
3435          JZ      FNBADP
3436  FN4B    MOV     E,D
3437          CALL    PUTPC
3438          INR     D
3439          POP     H
3440          JMP     FN1
3441  FN5     CALL    SKIPSP
3442          MOV     A,M
3443          ORI     20H
3444          MVI     B,0
3445          CPI     'w'
3446          JZ      FN6
3447          MVI     B,8
3448          CPI     'b'
3449          JNZ     FNBAD
3450  FN6     MOV     A,B
3451          STA     STM
3452          INX     H
3453          CALL    SKIPSP
3454          MVI     C,0
3455  FN7     MOV     A,M
3456          INX     H
3457          CPI     'K'
3458          MVI     B,1
3459          JZ      FN8
3460          CPI     'Q'
3461          MVI     B,2
3462          JZ      FN8
3463          CPI     'k'
3464          MVI     B,4
3465          JZ      FN8
3466          CPI     'q'
3467          MVI     B,8
3468          JZ      FN8
3469          CPI     '-'
3470          JZ      FN7
3471          DCX     H
3472          JMP     FN9
3473  FN8     MOV     A,C
3474          ORA     B
3475          MOV     C,A
3476          JMP     FN7
3477  FN9     MOV     A,C
3478          STA     CASTL
3479          CALL    SKIPSP
3480          MOV     A,M
3481          CPI     'a'
3482          JC      FN10
3483          CPI     'i'
3484          JNC     FN10
3485          CALL    ALGSQL
3486          STA     EPSQ
3487  FN10    LDA     PLIST
3488          CPI     0CCH
3489          JZ      FNBAD
3490          LDA     PLIST+16
3491          CPI     0CCH
3492          JZ      FNBAD
3493          CALL    FIXCR
3494          XRA     A
3495          STA     HMC
3496          STA     BOOKOK
3497          CALL    NEWGM
3498          JMP     H0072
3499  FNBADP  POP     H
3500  FNBAD   CALL    NEWPOS
3501          JMP     H012C
3502  FENPC   MVI     C,0
3503          CPI     'a'
3504          JC      FP1
3505          SUI     20H
3506          MVI     C,8
3507  FP1     MVI     B,1
3508          CPI     'P'
3509          JZ      FP2
3510          MVI     B,2
3511          CPI     'N'
3512          JZ      FP2
3513          MVI     B,3
3514          CPI     'K'
3515          JZ      FP2
3516          MVI     B,5
3517          CPI     'B'
3518          JZ      FP2
3519          MVI     B,6
3520          CPI     'R'
3521          JZ      FP2
3522          MVI     B,7
3523          CPI     'Q'
3524          RNZ
3525  FP2     MOV     A,B
3526          ORA     C
3527          MOV     B,A
3528          XRA     A
3529          RET
3530  ; FIXCR: no castling right without king and rook
3531  FIXCR   LXI     D,CRCHK
3532  FX1     LDAX    D
3533          ORA     A
3534          RZ
3535          MOV     C,A
3536          INX     D
3537          LDAX    D
3538          MOV     L,A
3539          MVI     H,BRDH
3540          INX     D
3541          LDAX    D
3542          INX     D
3543          CMP     M
3544          JZ      FX1
3545          MOV     A,C
3546          CMA
3547          LXI     H,CASTL
3548          ANA     M
3549          MOV     M,A
3550          JMP     FX1
3551  HELP    LXI     H,TXHELP
3552  HL1     MOV     A,M
3553          ORA     A
3554          JZ      H0075
3555          CALL    H01DA
3556          INX     H
3557          JMP     HL1
3558  ;
3559  CRCHK   DB      1,H1,6,1,E1,3,2,A1,6,2,E1,3
3560          DB      4,H8,0EH,4,E8,0BH,8,A8,0EH,8,E8,0BH,0
3561  TXOO    DB      'O-O',13
3562  TXOOO   DB      'O-O-O',13
3563  ;
3564  ;*** opening book (2026): main lines, from-to pairs,
3565  ; 0FFH ends a line, 0FEH the book
3566  BOOKT   DB      E2,E4,E7,E5,G1,F3,B8,C6,F1,B5,A7,A6
3567          DB      B5,A4,G8,F6,E1,G1,F8,E7,0FFH
3568          DB      E2,E4,E7,E5,G1,F3,B8,C6,F1,C4,F8,C5
3569          DB      C2,C3,G8,F6,D2,D4,E5,D4,0FFH
3570          DB      E2,E4,E7,E5,G1,F3,B8,C6,D2,D4,E5,D4
3571          DB      F3,D4,G8,F6,0FFH
3572          DB      E2,E4,E7,E5,G1,F3,G8,F6,F3,E5,D7,D6
3573          DB      E5,F3,F6,E4,0FFH
3574          DB      E2,E4,C7,C5,G1,F3,D7,D6,D2,D4,C5,D4
3575          DB      F3,D4,G8,F6,B1,C3,A7,A6,0FFH
3576          DB      E2,E4,C7,C5,G1,F3,B8,C6,D2,D4,C5,D4
3577          DB      F3,D4,G8,F6,B1,C3,E7,E5,0FFH
3578          DB      E2,E4,C7,C5,G1,F3,E7,E6,D2,D4,C5,D4
3579          DB      F3,D4,G8,F6,0FFH
3580          DB      E2,E4,E7,E6,D2,D4,D7,D5,B1,C3,G8,F6
3581          DB      C1,G5,F8,E7,0FFH
3582          DB      E2,E4,C7,C6,D2,D4,D7,D5,B1,C3,D5,E4
3583          DB      C3,E4,C8,F5,0FFH
3584          DB      E2,E4,D7,D5,E4,D5,D8,D5,B1,C3,D5,A5,0FFH
3585          DB      E2,E4,G8,F6,E4,E5,F6,D5,D2,D4,D7,D6,0FFH
3586          DB      E2,E4,D7,D6,D2,D4,G8,F6,B1,C3,G7,G6,0FFH
3587          DB      D2,D4,D7,D5,C2,C4,E7,E6,B1,C3,G8,F6
3588          DB      C1,G5,F8,E7,0FFH
3589          DB      D2,D4,D7,D5,C2,C4,C7,C6,G1,F3,G8,F6
3590          DB      B1,C3,D5,C4,0FFH
3591          DB      D2,D4,G8,F6,C2,C4,E7,E6,B1,C3,F8,B4
3592          DB      E2,E3,E8,G8,0FFH
3593          DB      D2,D4,G8,F6,C2,C4,G7,G6,B1,C3,F8,G7
3594          DB      E2,E4,D7,D6,G1,F3,E8,G8,0FFH
3595          DB      D2,D4,G8,F6,C2,C4,E7,E6,G1,F3,B7,B6,0FFH
3596          DB      D2,D4,D7,D5,G1,F3,G8,F6,C2,C4,E7,E6
3597          DB      B1,C3,F8,E7,0FFH
3598          DB      C2,C4,E7,E5,B1,C3,G8,F6,G1,F3,B8,C6,0FFH
3599          DB      G1,F3,D7,D5,D2,D4,G8,F6,C2,C4,E7,E6,0FFH
3600          DB      0FEH
3601  PEND    DS      0
3602          END

Metzner Starlight 60A project / Information Gathering

In a Christmas charity auction I got hold of one of the early classic turntables. Everyone has a TD124, but a Metzner Starlight?

Now the restoration starts and I will collect information and document the steps here

Links and Documents

Metzner Starlight TT – hybrid drive | Audiokarma Home Audio Stereo Discussion Forums

Metzner Coming to Swap Room | Audiokarma Home Audio Stereo Discussion Forums

Metzner Starlight Revisited – + Installation (page 1) – Other Turntables – Lenco Heaven Turntable Forum

Mr. Metzner Comes Home (page 1) – Other Turntables – Lenco Heaven Turntable Forum

ROON CORE: Install Debian 12.x (Bookworm) and some Essentials

Install Linux Distribution: Debian 12

Download the latest installation image of debian 12 alias Bookworm from: look for the file with the .iso extension:

https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/

Now use your favorite imagewriting tool to write this diskimage to a USB stick. (Note this USB stick will be completely wiped during this process)

Boot with this USB stick on your target machine and do a text based install. (Second menu option)

When asked choose LVM with seperate home partition. When you know what you are doing do whatever you like). Assign 256GB to the auto partitioning. (Gives us flexibility later)

In the installation process create a user called roon.

When selecting the install options only choose „ssh server“ and „standard system utilities“ so we get a bare minimum system.

now login as roon and install some fundamentals:

This will

  • update your sytem to allow installing the lastest tools
  • upgrade our base install
  • Install sudo so we can execute privileged commands as our newly created roon user
  • install the curl tool to allow command linde downloads from http sources
  • install your favorite editor (vim or nano)
  • the gnupg key lib
  • a tool to show the usage of your system ressources
# need to do this as root as we do not have sudo yet

su -
apt-get update -y
apt-get upgrade -y
apt-get install sudo curl nano vim gnupg2 htop -y

add user roon to sudo group

usermod -aG sudo roon

ROON CORE: Installing ROON Server

Finally we are almost there

Installing dependencies for roon core:

sudo apt-get install ffmpeg libasound2 cifs-utils  -y

now tun the roon install scripts

curl -O https://download.roonlabs.net/builds/roonserver-installer-linuxx64.sh
chmod +x roonserver-installer-linuxx64.sh
sudo ./roonserver-installer-linuxx64.sh

status

sudo systemctl status roonserver

should look similiar to:

stop it with

sudo systemctl stop roonserver

You cann now configure your roon server via a roon client app (IOS/Win/MacOS/Android)

ROON CORE: Installing WiFi [optional]

Enable WIFI

On debian 12 network-manager is really working ….

sudo apt-get install network-manager -y
# and find out if it is running
sudo systemctl status NetworkManager

Will output something like this:

find your ssd and connect to it:

nmcli device wifi list
sudo nmcli device wifi connect 'myssd' password 'secret'

nmcli connection show

Let´s make that permanent (you could do this for multiple connections)

# and make it sticky

sudo nmcli connection modify 'apfelhome' connection.autoconnect yes
# and add a high priority

sudo nmcli con modify "apfelhome" connection.autoconnect-priority 100
sudo systemctl restart NetworkManager

and you will find the config in /etc/NetworkManager

Optional configure an hotspot for configurations

configure a hotspot for admin purposes if there is now WLAN:

# Create a new Wi-Fi connection
sudo nmcli con add type wifi ifname wlo1 con-name Hotspot autoconnect yes ssid roon-install

# Set the connection to shared
sudo nmcli con modify Hotspot 802-11-wireless.mode ap 802-11-wireless.band bg ipv4.method shared ipv4.addresses 10.1.0.1/24

# Set the Wi-Fi security
sudo nmcli con modify Hotspot wifi-sec.key-mgmt wpa-psk
#replace Blaubär01with a password of your choice
sudo nmcli con modify Hotspot wifi-sec.psk Blaubär01

# Enable the hotspot
sudo nmcli con up Hotspot
# give it a low priority 
sudo nmcli con modify "Hotspot" connection.autoconnect-priority 5

to disconnect :

nmcli device disconnect wlo1

ROON CORE: Extending home partition with a second drive

if you do not have a secont drive, skip the first part and start with creating the new LV.

Extend a logical Volume Group [only if you have a second drive]

as we decided to use LVM we need to find the unused drive and extend our LVM group with this drive:

sudo lsblk

will help you to find the unused drive

here we would like to use the SSD /dev/sda

Now we create a physical volume (PV) on this drive:

sudo pvcreate /dev/sda

We find out the name of the volume group we would like to extend:

sudo vgdisplay

and we extend that group with the newly created PV

sudo vgextend roon-core2-vg /dev/sda

sudo vgdisplay

worked:

Add a new partition for music in the LV [start here if you do not have a second drive]

using all avialable space:

sudo lvcreate -n music -l 100%FREE roon-core2-vg

create the filesystem:

sudo mkfs.ext4 /dev/roon-core2-vg/music

create the director to mount the new file system to:

sudo mkdir /mnt/music

now edit the /etc/fstab to include:

/dev/mapper/roon--core2--vg-music /mnt/music ext4 defaults 0 2
sudo vim /etc/fstab
# now remount fstab
mount -a
sudo systemctl daemon-reload

and finaly allow the user roon to access all that newly created space:

sudo chown roon:roon /mnt/music
sudo chmod 700 /mnt/music
sudo chown -R roon:roon /mnt/music

ROON CORE: NAS access [optional]

If you would like to sync data from your NAS to the local disc you might wan´t to mount you NAS or remote volume directly.

install the necessary driver for the remote filesystem and create a mount point:

sudo apt-get install cifs-utils smbclient -y
sudo mkdir -p /mnt/NAS-music
sudo chown -R roon:roon /mnt/NAS-music
# try it out
sudo mount -t cifs //paulus/music /mnt/NAS-music/ -o username=nasuser,password=nasPW

und nun bei Bedarf in die fstab: securely store the credentials:

sudo nano /etc/cifs-credentials

should look like this:

username=your_samba_username 
password=your_samba_password

And now adjust the security

sudo chmod 600 /etc/cifs-credentials

now edit /etc/fstab and test it

sudo vim /etc/fstab

add

//yourNAS/yourShare /mnt/NAS-music cifs noauto,x-systemd.automount,x-systemd.requires=network-online.target,_netdev,credentials=/etc/cifs-credentials,iocharset=utf8,sec=ntlmssp,ro 0 0

reload and test :

sudo systemctl daemon-reload
sudo systemctl restart remote-fs.target
df -h

ROON CORE: Sync remote NAS shares to local drive [optional]

we will use rsync to do this (works with mounted USB drives as well)

sudo apt-get install rsync

now we automize it:

create sync script:

nano ~/sync_music.sh

#!/bin/bash
rsync -av --progress /mnt/NAS-music/ /mnt/music/

dont´forget to make it executable

chmod +x sync_music.sh
~/sync_music.sh

This script might run for a very long time… To make it independent from your session you may use a terminal multiplexer called tmux. You find more details at the endo of the following article:
10 Maintenance – Hauptsache es klingt ! (apfelbeck.at)

ROON CORE: Roon Display [option]

You would like to use an attached display to show the ROON web display? Don´t do it on low powerd machines

# add a dedicated user for it 
sudo useradd -m roon-display 
sudo passwd roon-display
# and now install some lightwight X enviroment
sudo apt-get install xorg chromium openbox lightdm xdotool unclutter
# thisis evil
sudo mv /etc/pam.d/lightdm-autologin /etc/pam.d/lightdm

# and edit the lightdm.comf
sudo nano /etc/lightdm/lightdm.conf

modify the following section

[Seat:*]
autologin-user=roon-display
user-session=openbox

Now we configure a very basic window manager called openbox for the autologin user.

 mkdir -p ~/.config/openbox
nano ~/.config/openbox/autostart

and add the following content

xset s off
xset -dpms
xset s noblank
unclutter -display 0:0 -noevents -grab

chromium \
    --disable-gpu \
    --no-first-run \
    --disable \
    --disable-translate \
    --disable-infobars \
    --disable-suggestions-service \
    --disable-save-password-bubble \
    --start-maximized \
    --kiosk "http://localhost:9330/display/" &


The –disable-gpu option took me quite some time to find out. The Mesa Driver for the Iris XE integrated INTEL processor graphic used in combination with the chromium browser has a rendering bug in combination deploying two SODIMMs (thus enable dual channel DRAM access)

Added unclutter to hide the Mouse Pointer.

We should reconnect – here every 5 Minutes – from time to time (is it a bug or feature ?)

as user roon-display do (important needs to be executed in the right user context)

crontab -e

and add

*/5 * * * * DISPLAY=:0 /home/roon-display/crontabrefresh.sh

and now we create a script for it

nano ~/crontabrefresh.sh
#!/bin/bash
xdotool key shift+F5

and make it executable

chmod +x ~/crontabrefresh.sh

ROON-CORE: Security / Firewall

Now install nftables as firewall:

sudo apt-get install nftables -y

start it

sudo systemctl enable nftables.service
sudo systemctl start nftables
sudo systemctl status nftables

edit your /etc/nftables.rules

sudo nano /etc/nftables.rules
# Define your local LAN Subnet
define lan = 192.168.1.0/24
define loopback = "lo"

table inet filter {
        chain input {
                type filter hook input priority filter; policy drop;
                # let´s be statefull
                ct state established,related accept
                # Needed for ROON Server
                iifname $loopback counter accept

                meta pkttype multicast counter accept
                meta pkttype broadcast counter accept
                # allow ssh access
                tcp dport 22 accept
                # roon comms
                ip saddr $lan udp dport 9003 counter accept
                ip saddr $lan tcp dport 9300-9339 counter accept

                # Apple Airplay
                ip saddr $lan udp dport 32768-65535 counter accept
                # Devialet Air
                ip saddr $lan tcp dport 32768-65535 counter accept
                log prefix "nftables: " flags all
        }

        chain output {
                type filter hook output priority filter; policy accept;
        }
}



Let´s see if it worked:

sudo nano /etc/nftables.conf

should look like:

#!/usr/sbin/nft -f

flush ruleset
include "/etc/nftables.rules"

and finaly test it by restarting

sudo systemctl restart nftables
sudo nft -s list ruleset

and to see the firewal log for bug fixing:

sudo journalctl -f -k | grep 'nftables'

or see the history:

sudo journalctl -k | grep 'nftables'

ROON CORE: Maintenance and Trouble Shooting

various topic and tools to ease the trouble shooting:

Temperature Measurement

as many of us want to use passively cooled system, looking at the various temperature sensors deployed in the system is helpfull:

sudo apt install lm-sensors
sudo sensors-detect --auto
sudo sensors

my passively cooled NUC 13 stays nice and cool even while indexing:

Checking System Ressource Usage

you may stop it with CTRL-C

sudo htop

Logging……

We have to get used to systemd and the logging and service management. Here some hints where to find logs

Roonserver and Raatserver logs can be found:

# Everything regarding the Management of your music, Desktop,....
/var/roon/RoonServer/Logs
# Audio Backbone : (Roon Advanced Audio Transport
/var/roon/RAATServer/Logs

You may to use journalctl to derive logging of the roonserver systemd unit.

sudo journalctl -u roonserver

sudo journalctl -u roonserver 

To get a list of all services which are running and can be used as filter or to be modified by systemctl:

systemctl | grep running

Most command commands within systemctl

# get the status of a service
sudo systemctl status roonserver
# start the service
sudo systemctl start roonserver
# stop the service
sudo systemctl stop roonserver
# stop and emideatly restart
sudo systemctl restart roonserver
# start service when booting(does not immideatly start it, you have to do it manually if you do not reboot!
sudo systemctl enable roonserver
# disable from autostart
sudo systemctl disable roonserver

Usefull Options for journalctl

# -k gets your the kernel log messages (eg nftables events)
sudo journalctl -k | grep 'nftables'
# while this gives you anything which is related to the service managment 
sudo journlctl -u nftables
# there are plenty way to to filter for the event time e.g.
# everything since the last boot
sudo journalctl -b
# specific timestamp
sudo journalctl --since "2023-01-01" --until "2023-01-31"
sudo journalctl --since today
sudo journalctl --since "2024-01-17 12:00:00"

# and to get continous logging to you console use -f
# like tail -f in good old times....
sudo journalctl -kf | grep 'nftables'

Run sessions in your user context tht survive you ssh session

For long running scripts it is helpfull to make a user sesion independent from your ssh conection. Normally your session ends with all running cripts as soon as you disconnect your ssh connection, however there are basiclly two tools to allow you to run „virtual screens“ for session. The traditional one is „screen“ however the more modern and ressource friendly way is „tmux“. You can also run multiple session in one connection.

# install tmux (terminal multiplexer)
sudo apt-get install tmux
# start a new virtual screen
tmux new -s session_name
# after you closed your connection try 
tmux ls
# and you find all open virtual windows
# than connectto it
tmux attach -t session_name
# You can also start tmux without any parameters and than do CTRL-B W

# you shall try CTRL-B ? to seel all available shortcuts within a tmux screen


to close all sessions and windows and clean upp (alls sessions will e interrupted

tmux kill-server

you can modify the sync script like this:

#!/bin/bash

tmux new-session -d -s rsync-session "rsync -av --progress /mnt/NAS-music/ /mnt/music/; tmux kill-session -t rsync-session"

This open a new session -d detached so it can run in the background. After the rsync has been done it will kill this new session.

you may see the progress if you attach yourself with tmux

tmux attach -t rsync-session

« Ältere Beiträge