|
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
RET 201
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
181 118
17302 36 8 183 179 167 176 182 167 179
183 118
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
17349 18562
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.
ALIST
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
RET 201
CHGMV
17143 LD HL NN 33 55 67
(247) LD A (HL) 126
( 66) ADD N 198 128
LD(HL) A 119
RET 201
PMOVE
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
RET 201
|
|
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
chess.
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
routine.
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:
- Line
- Function
- 1
- A Rem statement. From address 16514 to
17186
- 2
- 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.
- 3
- A Rand Usr statement. To call the
machine-code routine.
- 4
- A Rem statement. From address 17207 to
17362 to create the display and move
itself above RAMtop.
- 10
- onwards. Your favourite machine-code
loader or this one.
10 FOR A = 16514 to 18000
11 SCROLL
12 PRINT A; TAB 8;
13 INPUT B
14 POKEA, B
15 PRINT PEEK A
NEXT A.
To explain the logic of 1-4 above, assume
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:
POKE 16389,72
PRINT USR 1040
Now move the King's pawn:
POKE 17241,0
POKE 17252,53
|
OR move the Queen's pawn:
POKE 17242,128
POKE 17253,53
Run the machine-code program in Rem 4 by
typing
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
typing:
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
|
|
|
|