Upgrade to Hi-res Chess

Drawing of a chess king and pawn
Drawing of a chess king and pawn

Courtesy Silicon Mountain Computers

Most of you are undoubtedly as thrilled as I am, about the WRX16 high resolution core routines published in SyncWare News #4:2. This software opens new vistas (quite literally) for our ZX81’s and TS1000/1500’s. In fact, several new programs are already available from Silicon Mountain, including an Extended BASIC, a dungeon game, and various utilities. The only hardware requirement is a suitable 8K NVM board as a “Hunter” board or our own updated version, or even the built-in NVM published in SWN 4:1.

What about existing software? Can any of it be easily upgraded to a high resolution format? The answer is a resounding YES. BASIC programs, of course, can be upgraded using SRAM HI*RES. But what about some of the great machine-code programs that have come along over the years? Once again, the answer is YES, although such projects will demand more ability and/or ingenuity.

One of my all-time favourite programs for the ZX81 family is Psion’s ZX CHESS, as distributed by Timex. (I actually prefer it over Psion’s QL CHESS, since I’m not that good a chess player.) Its only real drawback is the inadequacy of the board display; it is a virtual necessity to “play along” using a real board. Still, it is remarkably competent for a program that runs in just over 8K of memory. Wouldn’t it be great if you could play this with “real” chess pieces on the screen?

Well now you can. Though it is a rather tricky program, I will give detailed steps that will result in an upgrade that will amaze and delight you, and perhaps rekindle your interest in that old “doorstopper.” Though we’ll be dealing almost exclusively in machine language, no knowledge of ML will be required to successfully complete this project. Patience, persistence, and a few hours of time are all you’ll need.

Upgrade Software

Central to the project are the new display routines and associated data that will translate the CHESS screen display into a large, high-resolution chess board. To leave room for the larger board display, the “messages” will be printed in a window panel along the left, in 64-column characters. (Believe it!) All this will be entered into a data array in a separate program which is loaded before the main program. A short machine-code routine in a 0 REM line is used to transfer the data into the 14-15.5K region after loading.

Get Started

Start by powering up your computer with 16K RAM plus suitable 8K NVM. Enter the loader program of LISTING 1, and save it to tape just in case Murphy strikes.

Note that line 1 is a REM followed by 28 characters. Enter POKE 16510,0; this gives the REM a line number of 0, making it un-deletable. Then enter RUN.

Enter the Code

Now take a deep breath, get good and comfortable, and start entering the data and machine code of TABLE 1. The data is arranged in “screens” of hex numbers, each with a specific start address. Enter the start address, then the hex numbers. Go from left to right, top to bottom. You’ll be entering over 1600 hex numbers, so take your time. Save to tape frequently, preferably after every “screen,” by entering GOTO 100. Take a break whenever you start feeling error-prone. Finding errors “after the fact” is MUCH harder than being careful in the first place. The data is stored in string array A$, so you should be aware NEVER to use RUN or CLEAR after you’ve started entering data. Restart after every screen with GOTO 10.

There are quite a few zeros (00) in the data tables. To make things a little easier for you, the loader will accept ENTER (only) to mean zero.

Downloader

When all the data has been entered, delete the loader lines (all that will be left is line 0 REM), and enter the “REM-loader” of LISTING 2. GOTO 10, and enter the values of TABLE 2. This is a little down-loader that will transfer the data in A$ into its operating region from 14-15.5K.

Once you’re all done, delete the REM-loader program lines. In their place, enter the “boot” program of LISTING 3. SAVE it to a fresh, clean tape with GOTO 10. After the SAVE, and subsequently LOAD, the data will be transferred into low memory. Don’t power down (or if you do, reload the program before proceeding), as some of the routines are needed for the next step.

Modify ‘CHESS’

Now that the laborious part is complete, we only have to modify the CHESS program so that it will work with the new software. Follow the instructions EXACTLY, and in the order that they are given; as I implied earlier, this is not the kind of program you’ll want to get “creative” with unless you know what you’re doing.

LOAD “CHESS”. Do not use the RAND USR 837 trick for “breaking” the program. When loading is complete, the screen will (presumably) say, “LOAD CHECK PASSED. WOULD YOU LIKE A GAME OF CHESS?” Press EDIT (shift 1), which will remove the quotes from the input cursor. Now enter STOP, and you’ll get report D/3.

Now enter the following immediate commands (no line numbers):

DIM B$(37)
LET B$( TO 2)=CHR$ 237+CHR$ 79
LET B$(35 TO )=CHR$ 195+CHR$ 159+CHR$ 60

If you prefer the message window in inverse video (I do), then also enter the following command:

LET B$(3 TO 9)="       " (7 inverse spaces)

Now the following:

LET A=15572
LET B=15578
LET SAVE=15906 (SAVE is spelled out)

Time to do a check on your work. Enter PRINT PEEK 24707. This should print 237. If it doesn’t, you did something wrong.

Now enter the following program lines (with line numbers), overwriting the lines in the BASIC driver. Enter them EXACTLY as shown; this is critical.

4 LET T=USR A
5 LET T=USR B
6 GOTO 3

Again check PRINT PEEK 24707. Again you should get 237.

Now we’ll enter the following list of POKEs (no line numbers). These make cosmetic changes to the various messages, to allow them to fit into the narrower window:

POKE 17499,118
POKE 17522,118
POKE 18042,118
POKE 23866,28
POKE 17813,118
POKE 17821,39
POKE 17822,52
POKE 17823,38
POKE 17824,55
POKE 17825,41
POKE 17826,15
POKE 17844,118
POKE 24493,118
POKE 24504,0
POKE 24505,29
POKE 24506,22
POKE 24507,34
POKE 24508,0
POKE 24519,118 (NOTE: 24519, not 24509)

(optional: executes NEW instead of reset when quitting, i.e. preserves RAMTOP.)

POKE 23879,195
POKE 23880,3

SAVING

There! All done! Well, almost; we still have to save it to tape. You probably know that you can’t just GOTO 1, for protection purposes. So we have to use a little trickery to get around this. Start your tape a few seconds after the end of the “boot” program, and enter GOTO USR SAVE. (GOTO and USR are the tokens, but SAVE is spelled out.) The program will save to tape, while keeping the LOAD CHECK routines active to warn of subsequent bad loads, and bypassing the crash-and-burn anti-piracy feature.

To make backups of the boot program, (“HRCHESS”), break operation when loaded and GOTO 10. To make a backup of the modified “CHESS” program, press EDIT then enter STOP after loading, then GOTO USR SAVE. (The HRCHESS boot program must be present.)

RUNNING

To load the high-res chess program, enter LOAD “HRCHESS” which, when loaded, will automatically chain the modified “CHESS” portion. The very first screen will be pretty much as you’re accustomed to; the subsequent displays, however, are like nothing you’ve seen on a ZX81 before. But don’t take my word for it, see for yourself! Incidentally, this will run on a TS1500 if you add a 16K RAM pack in addition to the SRAM.

Since the new display takes 26 lines, the picture might spill off the top or bottom of your TV. Simply adjust the VERT. HEIGHT control on the back to bring it on-screen if necessary.

If you want a graphic demonstration of the difference the new display makes, or if you have a nostalgic urge to view the old display, hold down the SHIFT key while the computer is thinking about its next move. This will show the subsequent move in the original “stone-age” mode.

If you don’t want to go to the trouble of entering all the machine-code, or if your attempts fail, I will supply tapes of the “HRCHESS” boot program only (Psion CHESS is copyrighted, so I can’t supply the modified program unless you send your original tape). Send $10 to Silicon Mountain Computers, C-12 Mtn. Stn. Group Box, Nelson, BC V1L 5P1 Canada. Also write to inquire about our other high-res products, or our “SCRAM” 8K NVM board which will support this software.

Tech Info

The high-res display file is mapped at 2000-37FFh. The data from 3800h to 3BA7 are the bit patterns for the chess pieces. These are 3 bytes wide by 24 bytes “deep,” for a total of 72 bytes per character. There are two of each character, first a “filled” version followed by an “open” one. The print algorithm chooses and complements them (or not) as required, depending on the colour of the piece and the colour of the square it’s on. King is at 3800 and 3848, Queen at 3890 and 38D8, Rook at 3920 and 3968, Bishop at 39B0 and 39F8, Knight at 3A40 and 3A88, Pawn at 3AD0 and 3B18. 3B60 is the character (a large circle) used during board setup to replace the “=” cursor. Modify these patterns to your heart’s content.

3BA8-3C6F are the 64-column bit patterns for CHR$ 14d (:) through 63d (Z). The high nybble is the even numbered characters, the low nybble is the odd-numbered characters. For example, the left nybble of 3BA8-3BAF is “:”, the right nybble is “?”, etc. Note that the actual “base” for these is at 3B70, but we have no need to print characters below CHR$ 15 so there was no point in including them.

3C6F-3C86 is a look-up table which gives the address of the first (filled) pattern of each piece. The first byte is the Sinclair character (K, Q, R, etc.), the next two are the address of the pattern.

3C88-3E62 is all code. 3C88-3CD3 is the WRX16 core. 3CD4 is where we return to FAST mode, thence to the program.

3CDA-3E21 is our display routine. This code segment is relocatable, i.e. no JPs or self-referred CALLs. At 3CDA we check for “shift,” returning if pressed. 3CE1 makes sure that the dummy display file exists in high memory (making it usable with 64K, provided that its 8-16K region is disabled and SRAM used instead). 3CEC clears the high-res display file. 3CF9 copies the messages from the normal display file to the 64-column window. (Want a challenge? Figure THAT one out!)

3D7F prints the board, using the contents of the normal display file as a template. This is another fairly involved routine. 3DF5 prints the frame around the board. Finally, 3E1A calls SLOW mode and sets the display vector (IX) to enter high-res mode. (As a side note, this entire stretch of code takes less than a second to run, even with all those nested loops!)

The last routine is the USR SAVE program at 3E22. This computes the checksum and stores it in the reference bytes at 6072, and undoes Psion’s “auto-crash” at 6074.

The area from 3E70 to 3EFF is filled with zeros by the downloader; this represents the “pattern” for zero (blank squares), and should not be used for other purposes. 3FF0-3FF2 are variables used by the board-printing routine. The bytes from 3F00 to 3FEF and 3FF3 to 3FFF are yours to do with as you see fit.

LISTING #1

   1 REM XXXXXXXXXXXXXXXXXXXXXXXXXXXX
10 DIM A$(1648)
20 CLS
30 PRINT "ADDRESS=";
35 INPUT AD
40 CLS
45 PRINT "ADDRESS=";AD
50 LET SUM=0
55 LET A=AD
60 FOR L=1 TO 20
70 FOR C=0 TO 30 STEP 3
80 INPUT H$
90 IF H$="" THEN LET H$="00"
100 IF LEN H$<>2 THEN GOTO 80
110 LET N=16*CODE H$(1)+CODE H$(2)-476
120 IF N>255 OR N<0 THEN GOTO 80
130 PRINT AT L,C;H$
140 LET A$(A-14335)=CHR$ N
150 LET SUM=SUM+N
160 LET A=A+1
170 IF A=15984 THEN GOTO 200
180 NEXT C
190 NEXT L
200 PRINT AT 21,0;"CHECKSUM=";SUM;" OK? Y/N"
210 PAUSE 4E4
220 IF INKEY$="Y" THEN GOTO 250
230 IF INKEY$="N" THEN GOTO 40
240 GOTO 210
250 CLS
260 PRINT "SAVE? Y/N"
270 PAUSE 4E4
280 IF INKEY$="Y" THEN SAVE "TABLE1"
290 IF INKEY$<>"N" THEN GOTO 250
300 GOTO 20

LISTING #2

   0~REM XXXXXXXXXXXXXXXXXXXXXXXXXXXX
10 FOR A=16514 TO 16541
20 INPUT N
30 LET N$=STR$ N+" "
40 PRINT N$( TO 3);":";
50 POKE A,N
60 NEXT A

LISTING #3

  10 REM HRCHESS BOOT PROGRAM
20 SAVE "HRCHESS"
30 PRINT "****DO NOT TURN OFF RECORDER****STAND BY TO LOAD HIGHRES ""CHESS"""
40 RAND USR 16516
50 PAUSE 300
60~LOAD "CHESS"

TABLE 1

ADDRESS=14336
00 00 00 00 10 00 00 10 00 00 7C
00 00 10 00 00 10 00 00 38 00 00
7C 00 00 7C 00 00 7C 00 00 38 00
00 28 00 00 7C 00 00 FE 00 00 FE
00 01 FF 00 01 FF 00 00 FE 00 01
FF 00 01 FF 00 03 FF 80 06 AA C0
07 FF C0 00 00 00 00 00 00 00 10
00 00 10 00 00 7C 00 00 10 00 00
10 00 00 38 00 00 44 00 00 44 00
00 44 00 00 28 00 00 38 00 00 6C
00 00 C6 00 00 82 00 01 01 00 01
01 00 00 82 00 01 83 00 01 01 00
03 FF 80 06 AA C0 07 FF C0 00 00
00 00 00 00 00 10 00 01 7D 00 00
FE 00 00 FE 00 00 7C 00 00 38 00
00 28 00 00 7C 00 00 FE 00 00 FE
00 01 FF 00 01 FF 00 01 FF 00 00
FE 00 00 FE 00 00 7C 00 00 54 00
00 FE 00 01 FF 00 03 FF 80 06 AA
C0 07 FF C0 00 00 00 00 00 00 00
CHECKSUM=10990

ADDRESS=14556
10 00 01 7D 00 00 C6 00 00 82 00
00 44 00 00 28 00 00 38 00 00 44
00 00 C6 00 00 82 00 01 01 00 01
01 00 01 01 00 00 82 00 00 C6 00
00 44 00 00 54 00 00 82 00 01 01
00 03 FF 80 06 AA C0 07 FF C0 00
00 00 00 00 00 00 00 00 00 00 00
00 00 00 01 99 80 01 99 80 01 FF
80 01 24 80 01 FF 80 00 FF 00 00
7E 00 00 7E 00 00 7E 00 00 3C 00
00 3C 00 00 24 00 00 7E 00 00 FF
00 00 FF 00 01 FF 80 01 99 80 03
FF C0 03 FF C0 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 01 99
80 01 99 80 01 FF 80 01 00 80 01
81 80 00 C3 00 00 42 00 00 42 00
00 42 00 00 24 00 00 24 00 00 3C
00 00 66 00 00 81 00 00 81 00 01
00 80 01 66 80 03 00 C0 03 FF C0
00 00 00 00 00 00 00 00 00 00 10
CHECKSUM=10585

ADDRESS=14776
00 00 10 00 00 38 00 00 74 00 00
6C 00 00 7C 00 00 7C 00 00 38 00
00 28 00 00 7C 00 00 7C 00 00 FE
00 00 FE 00 00 FE 00 00 FE 00 00
7C 00 00 7C 00 00 FE 00 01 FF 00
03 55 80 03 FF 80 00 00 00 00 00
00 00 00 00 00 10 00 00 10 00 00
28 00 00 4C 00 00 54 00 00 44 00
00 6C 00 00 28 00 00 38 00 00 6C
00 00 44 00 00 82 00 00 82 00 00
82 00 00 C6 00 00 44 00 00 44 00
00 82 00 01 FF 00 03 55 80 03 FF
80 00 00 00 00 00 00 00 80 00 00
C0 00 00 70 00 01 FC 00 01 E4 00
01 FF 00 01 FF 80 00 FF 80 00 FC
00 00 78 00 00 38 00 00 38 00 00
7C 00 00 FE 00 00 FE 00 00 FE 00
00 7C 00 00 7C 00 00 FE 00 01 FF
00 03 55 80 03 FF 80 00 00 00 00
00 00 00 80 00 00 C0 00 00 F0 00
CHECKSUM=10883

ADDRESS=14996
01 0C 00 01 34 00 01 03 00 01 00
80 00 83 80 00 C4 00 00 68 00 00
28 00 00 28 00 00 44 00 00 82 00
00 82 00 00 C6 00 00 44 00 00 44
00 00 82 00 01 FF 00 03 55 80 03
FF 80 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 38 00 00
7C 00 00 FE 00 01 FF 00 01 FF 00
01 FF 00 00 FE 00 00 7C 00 00 38
00 00 38 00 00 38 00 00 7C 00 01
FF 00 03 FF 80 03 FF 80 00 00 00
00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00
00 00 00 38 00 00 44 00 00 82 00
01 01 00 01 01 00 01 01 00 00 82
00 00 44 00 00 28 00 00 28 00 00
28 00 00 44 00 00 82 00 03 83 80
03 FF 80 00 00 00 00 00 00 00 00
00 00 00 00 00 FF 00 03 00 C0 04
CHECKSUM=7266

ADDRESS=15216
00 20 08 00 10 08 00 10 10 00 08
10 00 08 10 00 08 10 00 08 10 00
08 10 00 08 10 00 08 10 00 08 08
00 10 08 00 10 04 00 20 03 00 C0
00 FF 00 00 00 00 00 00 00 00 00
00 00 04 4A 02 04 40 04 00 00 24
42 42 42 42 24 00 00 82 44 28 44
82 00 00 00 04 E4 0E E4 04 00 00
00 0A 04 EE 04 0A 00 00 00 20 24
40 40 84 84 08 00 00 00 00 00 4C
4C 80 00 64 AC A4 A4 A4 CE 00 00
4E A2 24 42 8A E4 00 00 2E 68 AC
E2 2A 24 00 00 4E 82 C2 A4 A8 48
00 00 44 AA 4A A6 A2 44 00 00 4C
AA AC EA AA AC 00 00 6C 8A 8A 8A
8A 6C 00 00 EE 88 CC 88 88 E8 00
00 4A AA 8E AA AA 6A 00 00 E6 42
42 42 4A E4 00 00 A8 A8 C8 C8 A8
AE 00 00 AC EA EA AA AA AA 00 00
4C AA AA AC A8 48 00 00 4C AA AA
CHECKSUM=14918

ADDRESS=15436
AC AA 4A 20 00 6E 84 44 24 24 C4
00 00 AA AA AA AA A4 64 00 00 AA
AA A4 A4 EA AA 00 00 AE A2 44 44
48 4E 00 70 3E 30 00 38 36 90 38
37 20 39 27 B0 39 33 40 3A 2E D0
3A 14 60 3B 00 F3 3E 07 47 00 10
FD C6 EE 3C 20 FD 06 C0 11 20 00
21 00 20 C3 A6 3C 00 00 05 CA AD
3C 19 7C ED 47 7D C3 83 E0 2A 0C
40 2A 0C 40 2A 0C 40 00 11 F7 82
19 3E 1E ED 47 3E F5 01 07 02 CD
B5 02 CD 92 02 CD 20 02 DD 21 88
3C C3 A4 02 CD 23 0F C3 00 4F CD
BB 02 7C FE FE C8 21 83 60 11 83
E0 01 25 00 ED B0 21 00 20 36 00
54 5D 13 01 FF 17 ED B0 2A 0C 40
11 C3 02 19 06 16 C5 0E 0E C5 05
0D 7E A7 28 45 CB 47 1F 37 3F 57
79 1F 4F 7A E5 F5 21 70 3B 16 00
5F CB 23 CB 12 CB 23 CB 12 CB 23
CHECKSUM=20177

ADDRESS=15656
CB 12 19 EB 21 00 20 09 F1 06 08
C5 F5 1A 46 20 36 38 26 E6 F0 F5
78 E6 0F 47 F1 B0 77 13 D5 11 20
00 19 D1 F1 C1 10 E3 E1 C1 2B 0D
20 AF C1 AF 11 13 00 ED 52 10 A3
18 1E CB 3F CB 3F CB 3F CB 3F F5
78 E6 F0 18 D2 38 0A CB 27 CB 27
CB 27 CB 27 18 C2 E6 0F 18 EA 2A
0C 40 11 95 00 19 06 00 C5 0E 00
C5 22 F0 3F 78 81 CB 47 7E 07 1F
CB BF F5 21 6F 3C BE 28 05 23 23
23 18 F8 23 5E 23 56 F1 F5 30 04
20 0D 18 02 28 09 FE 14 28 05 21
48 00 19 EB 78 80 80 47 79 81 81
4F 21 08 20 09 06 18 0E 03 F1 F5
1A 28 01 2F 77 23 13 0D 20 F4 D5
11 1D 00 19 D1 10 EA F1 2A F0 3F
23 23 C1 3E 08 0C B9 20 9F 11 32
00 19 C1 04 B8 20 93 21 08 20 11
E0 17 06 18 36 FF E5 19 36 FF E1
CHECKSUM=20988

ADDRESS=15876
23 10 F6 21 08 20 06 C0 CB FE 11
17 00 19 CB C6 11 09 00 19 10 F2
CD 2B 0F DD 21 88 3C C9 CD 23 0F
CD 2A 0A 11 70 46 3E 0B CD 64 5F
21 7D 40 11 00 00 4E 06 08 CB 39
CB 13 CB 12 30 04 7B EE 2D 5F 10
F2 23 7C FE 60 20 E9 7D FE 6F 20
E4 ED 53 72 60 21 00 46 22 75 60
CD 2A 0A 01 01 00 C9 00 00 00 00
00 00 00 00 00 00 00 00 00
CHECKSUM=8607

TABLE 2

118:118:42 :16 :64 :17 :6  :0  :
25 :17 :0 :56 :1 :111:6 :237:
176:98 :107:54 :0 :19 :1 :145:
0 :237:176:201:

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.