This is an article from the February 1983 issue of `Your Computer'.
I apologise for the excessive width: I have attempted to recreate
the original layout, which is printed on a double page and a single
page. If you like you can just read the text
of the article. I'm afraid the article was scanned without permission;
if the copyright owner objects then I will remove this page.
The listings are shown in image form because my OCR has difficulty in
decoding them. You can download the large version of each image if
you like and attempt to OCR them yourself. My attempt didn't produce
anything reasonable for the ZX Printer output on the first page, but
I made a reasonable attempt for the assembler
listings on the second page which you can look at. I corrected
by hand the short assembler listings on the
first page so they should be OK.
The text in blue within the article was not originally present but
was pencilled in - I presume from a correction printed in the next
issue. Similarly I also had pencilled in a correction to
the numeric listing: it had under the caption `Figure 2'
the address 16514 and the numbers 118 118
and had corrected 16514 at the top of the listing to
16516. This doesn't make sense to me so I have not shown
the correction below. You will see that there are two or three
corrections written on image of the assembler listing. One that
hasn't been included is that the KYBD routine appears to
be referred to as KT in other parts of the listing.
Figure 3. Rem display.
4 REM DISPLAY
17287 LD HL NN 33 67 67 (17219)
LD DE NN 17 0 72 (18432)
LD BC NN 1 205 0
LDIR 237 176
17219 18432 128 8 169 183 173 118
29 8 55 51 39 48 54 39 51 55 118
17236 30 8 53 53 53 53 53 53 53 53 118
31 8 0 128 0 128 0 128 0 128 118
17258 32 8 128 0 128 0 128 0 128 0 118
33 8 0 128 0 128 0 128 0 128 118
17280 34 8 128 0 128 0 128 0 128 0 118
35 8 181 181 181 181 181 181 181
17302 36 8 183 179 167 176 182 167 179
8 8 45 44 43 42 41 40 39 38 118
17324 8 8 8 8 8
17329 18542 LD BC NN 1 0 4
CALL NN 205 245 8 (2293)
LD HL NN 33 0 72
LD B N 6 110
PUSH BC 197
PUSH HL 229
LD A (HL) 126
RST 16 215
POP HL 225
POP BC 193
INC HL 35
DJNZ 16 247
LD HL NN 33 125 64 16509
LD (NN) HL 34 41 64 16425
JP NN 195 7 3
© Copyright David Horne 1983
Figure 4. Code map. See also page 102.
17837 LD HL NN 33 70 64
(141) INC (HL) 52
( 66) LD A (HL) 126
ADD L 133
LD L A 111
LD (HL) C 113
17143 LD HL NN 33 55 67
(247) LD A (HL) 126
( 66) ADD N 198 128
LD(HL) A 119
17151 LD HL (NN) 42 7 64
(255) LD A (DE) 26
( 66) LD C A 79
LD A (HL) 126
LD(HL) N 54 0
LD(DE) A 18
LD B A 71
IF YOU HAVE followed the series of articles to|
date, you should have managed to produce a
game which consisted of a chessboard and
logic which restricts the possible moves to
only those that are legal, providing two-player
Examining the memory map of the game
you may have noticed that a significant
proportion of the code is used in creating the
board, which is big by ZX-81 1K display
standards. If some way could be found to use
the display file saved on tape and a minimal
file "to boot", then we would have enough
space to write a short computer playing
One further point should be explained. It is
not possible to give a good opening or finish to
the game because that would require slightly
more code than we have available in the 1K
game. We actually have only 672 bytes.
The game, therefore, starts off with the
computer playing white and either the King's
pawn or the Queen's pawn moved forward one
position. The following describes the machine
code and techniques used in the creation of my
1K ZX-81 chess program. In order to produce
the code you will require a machine with at
least 3K of memory. The code has been
created using a 3K machine, there should be
no problems using 16K if the procedures
given are followed and RAMtop is lowered to
1K before loading from tape.
First the Basic program consists of:
To explain the logic of 1-4 above, assume
- A Rem statement. From address 16514 to
- A Slow statement. This has been called
from Basic to ensure that all ZX-81s will
work irrespective of whether you have an
early ROM with error or not.
- A Rand Usr statement. To call the
- A Rem statement. From address 17207 to
17362 to create the display and move
itself above RAMtop.
- onwards. Your favourite machine-code
loader or this one.
10 FOR A = 16514 to 18000
12 PRINT A; TAB 8;
13 INPUT B
14 POKEA, B
15 PRINT PEEK A
you have entered the machine code in Rems 1
and 4. Delete all Basic lines except 1 to 4
inclusive. Now lower RAMtop by typing:
Now move the King's pawn:
PRINT USR 1040
OR move the Queen's pawn:
Run the machine-code program in Rem 4 by
RAND USR 17207.
This copies Rem 4 above RAMtop and it is
therefore protected when the next commands
are typed in. Delete line 4, then type Clear.
This removes all the stored variable making
available the maximum possible RAM space
for our program. Now add the variable X by
LET X= 16959
This sets up the variable X for the Basic
program. Line 3 Rand UsrX actually calls the
driver routine. Now type:
RAND USR 18542
At this stage you save the program on tape.
The machine-code program loaded above
RAMtop will execute. The first section creates
a display file on the board and pieces, the
second section loads into address 16425 -
Sinclair variable Nxtlin, the address of the
next program line to be executed - this is the
actual start of Rem 1, that is, address 16509.
The program then jumps to the Save routine
in ROM; this will Save the display just
produced and then auto-run at line 1. The
whole of the above most be done in fast mode,
or else the Save routine will not be executed.
Now for a brief description of the function
of each of the machine-code segments: Kybd
is a routine which sets up machine control of
the keyboard such that only the eight key
codes from code 29 and the eight key codes
from code 38 are acceptable entries. Any other
(continued from previous page)|
position whilst Check is being evaluated, and
then recovers the move list on completion. It is
also used to shift the best move so far up into
the move list.
PSC gives a score to a chess piece Q(5),
R(4), B(3), N(2), P(1).
MPScan scans the board for computer
pieces and, using move and score, determines
all legal moves and saves the best. INC
determines whether a square is being attacked.
Driver Main control logic, uses all the
other subroutines to provide program control.
TestList: tests to see if there are any moves
in the move list. AddList: adds to the current
legal move list another entry on the end.
The program is copyright. You can produce
a copy of the program from the listings for
your own use, but you should not copy the
listings or parts thereof and offer for sale.
|Figure 1. Code map continued from page 100.|