The Psi CHESS is an excellent chess program. It was put out in 1983 by “The Edge”, Covent Garden, London England. It is designed for the Spectrum, and can be played on a Spectrumized TS2068. By use of the NMI-key it can be saved to disk with the Larken system.
The program has the capability of saving the pertinent data (about 256 bytes) of a game in progress, for reloading later. The drawback, for a Larken user, is that the SAVE is to tape. This article details how to convert the program to do this save and load to a Larken disk.
The procedure on this disk requires use of four utilities which are to be found on disks #1 and #12 of the club Larken library. The process is complex because I found no easy way to break into the program (all my tricks failed!). This procedure would be applicable to all such programs.
It was first necessary to locate the SAVE and LOAD routines in the program. By doing some experimental saves and loads it was evident that the data was being saved as a short headerless block of code. That is to say, there was no header to the saved code. This meant that one could not inspect the saved code for header information.
So…. I think the best thing is to prepare two copies of the chess program, over and above your original. What we want to start off with is one 9-track (Larken) NMI-save, and one 10-track NMI-save copy of the chess program. We shall call them chess-9 and chess-10 to simplify things. (You make 9-track copies by holding down the CAPS SHIFT key while pressing the 1-5 keys.
Using the programs “crack.B1” and “saver1.B1” from library disk #12, I saved a portion of “chess-9”, from address 24000, to the top of memory. Maybe I should explain the way it is done. The “crack.B1” program loads the “chess-9” program track-by-track into the computer. As each track is loaded into the computer it is saved off to tape before the next track is called up. This process is automatic; it takes about 10 minutes to save a program to tape. Then the “saver1.B1” program is loaded, the tape is played back, and the “chess-9” program is placed back into the computer, again automatically. But with a difference. Only a portion of the “chess-9” has been put back into the computer; that portion from address 24000 and upwards. The computer has been given a CLEAR 23999 instruction, so there is a bit of room for some short Basic routines. Save this code to disk. SAVE “pchess.C1” CODE 24000,41535.
We do this so we can get into the chess program and search out the location of the LOAD/SAVE routines. And to find some empty space for our Larken code. We are going to use this information later to modify the chess-10 program. After we have this information this “pchess.C1” will be discarded.
Now to search for the SAVE and LOAD routines. One thing that is common to these routines is the m/c instruction LD IX. This equates to a 221 and 33 (decimal) in adjacent addresses. I used a FOR/NEXT loop to search through the program looking for this number sequence. The routine would print out the address of every occurrance. There were several. I then loaded the program “spec48.Cs” (a disassembler on library disk #12) and took a look at these locations. They looked promising. I took note of two addresses, 42917 and 42934. These were significant because they were CALLs to LOAD and SAVE routines in the Spectrum ROM; addresses 1378 and 1222. I took a printout of the m/c around those addresses.
I propose to do the same with this program as I had done with the “Penetrator” program, described earlier in Sinc-Link (Vol.8 No.2). That is, introduce a Larken SAVE and LOAD routine in an empty space somewhere in the program, and redirect the ROM calls to the Larken code. I would need room for about 130 bytes of code. I searched through the memory for some space, and found some starting at address 48400.
Since loading “spec48.Cs” partially corrupted the “chess.C1” program in memory, I reloaded it. Then I did a PRINT USR 42893 and PRINT USR 42922 to verify the SAVE and LOAD routines. These were addresses of m/c leading up to the ROM calls SAVE and LOAD. And sure enough these put us into the SAVE and LOAD modes.
I reworked addresses of the “Penetrator” code to suit the new location. Also, since the original chess “tape-saves” were headerless, i.e. had no name, a name had to be added to the code to satisfy the Larken system.
The Basic listing included here is the result of this. Type this in, SAVE it (hopefully you will not need it again); then RUN it and save the resulting code at 48400. Save “chess.C1” CODE 48400,130. Save it to tape, not disk. It will be easier this way.
Now comes the tricky part. Although we have been working with the “chess-9” program, this SAVE/LOAD code has to be introduced into the uncrackable “chess-10” program. To do this we are going to use two utility programs; “bopeep.B1” (on library disk #12), and “doctor.B1” (library disk #1).
We are going to use “bopeep.B1” to do two things. Description of the “bopeep.B1” utility is too involved to go into here. Details are on the disk. Suffice to say that with this utility we shall POKE several numbers “directly” into the “chess-10” program. Firstly, we shall POKE four addresses with new numbers. These numbers will cause the chess program to CALL the Larken code when a SAVE or LOAD function is invoked. Poke these numbers:
Address new no. (orig. no.)
42918 16 (98)
42919 189 (5)
42935 25 (198)
42936 189 (4)
Note: 16+256*189=48401 and
25+256*189=48409
calls to the Larken code
Secondly, we shall “mark” the spot where we want to locate the Larken code. Now, we could POKE this code directly, continuing the process described above. However, there are about 125 numbers to be POKEd, and this can be quite a chore. Instead, we are going to make use of the “doctor” utility and the 130-byte block of code (chess.C1) we saved earlier on tape. Using the “doctor” utility we shall load into the computer the track of the “chess-10” program that contains the wanted address 48400.
But I digress. To mark the track we shall call up addresses 48400, 48401, and 48402; and POKE a value of 201 into each. We do this to make this address quite distinctive when we search for it later, with “doctor”. At the same time, take note of which disk-track the 7th track of chess-10 is located. We’ll want to know this shortly. The ten disk tracks of “chess-10” appear on the screen of “bopeep”.
Having completed the “marking” we shall now load “doctor.B1”. I’m going to make it easy for both of us. I’ve already determined, by breaking into the “bopeep” program during it’s operation, and looking at some of it’s variables, that this address, 48400, is located in the 7th of the 10 tracks of the “chess-10” program. And by using a FOR/NEXT loop to search for the three 201’s on the track while it was in the “doctor” program, I find that the wanted chess-10 address (48400) is now at address 51500 in the “doctor” program. Are you still with me? Do check this out.
While you have this track 7 of chess-10 in the “doctor” program, and while you are viewing the (doctor) address 51500 with Option “D”, you should see the 201’s that we poked earlier. BREAK from the program, load the “chess.C1” code you saved earlier (be sure to LOAD “chess.C1” CODE 51500). Then get back into the doctor program by pressing the C (CONTINUE) key, then work the “B” and “C” keys. If this fails to put you back into the “doctor” program, then do a GOTO 4100. Verify that the code you just loaded is in place starting at address 51500. Note that it over-writes the 201’s. If you have done things correctly it will have!
Be sure the disk with chess-10 is still in the drive, and is unprotected. Then re-save the track in “doctor”, by pressing the “S” key to save to the same track.
This completes the operation. Load your “chess-10” program into the computer (Spectrum mode, of course), and try out the SAVE and LOAD options. Be sure to have an unprotected disk with at least one spare track in the drive. It could be the same disk as chess-10 was loaded from. Or it could be another disk. However the SAVE and LOAD will be to the same drive as the program was originally loaded from. You cannot change drives.
Do a SAVE first, so that when you try a LOAD there will be a chess code file to load. Otherwise the system will crash. I assigned the name “chess.Cx” to this code file. It takes one track.
***********************************
Basic Code Loader
10 FOR n=48400 TO 48526
20 READ a: POKE n,a
30 NEXT n
100 DATA 205,33,189,201,0,0,0,0,0
110 DATA 205,80,189,201,0,0,0,0
120 DATA 243,0,205,98,0,33,126,189,17,34,32,1,10,0,237
130 DATA 176,62,11,50,2,32,205,198,0,33,0,251,34,51,32
140 DATA 33,0,1,34,49,32,205,201,0,58,100,0,251,201,0
150 DATA 0,0,243,0,205,98,0,33,126,189,17
160 DATA 34,32,1,10,0,237,176,62,11,50,2,32,205,204,0
170 DATA 33,0,251,34,51,32,33,0,1,34,49,32,205,207,0
180 DATA 58,100,0,251,201,0,0,112,99,104,101,115,115,46,67,120,28,0,0,0,0,0,0,0
200 STOP
9000 PRINT USR 100: SAVE "chess.B1"
LOAD & SAVE code from “chess-09”
42892 C9 RET
->42893 3EFF LD A,255
42895 118012 LD DE,4736
42898 DD2100A8 LD IX,43008
42902 37 SCF
42903 CD9DA7 CALL 42909
42906 FDE1 POP IY
42908 C9 RET
42909 14 INC D
42910 08 EX AF,AF'
42911 15 DEC D
42912 F3 DI
42913 3E0F LD A,15
42915 D3FE OUT (254),A
->42917 CD6205 CALL 1378
42920 FB EI
42921 C9 RET
->42922 CDCDA7 CALL 42957
42925 DD2100FB LD IX,64256
42929 110001 LD DE,256
42932 3EFF LD A,255
->42934 CDC604 CALL 1222
42937 FDE1 POP IY
42939 C3CDA7 JP 42957
42942 3EFF LD A,255
42944 DD2100FB LD IX,64256
42948 110001 LD DE,256
42951 37 SCF
42952 CD9DA7 CALL 42909
42955 FDE1 POP IY
42957 2100FB LD HL,64256
42960 7E LD A,(HL)
42961 EEFE XOR 254
42963 77 LD (HL),A
42964 2C INC L
42965 20F9 JR NZ,42960
42967 C9 RET
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.