dk'tronics DKT64k User manual

Dk'tronics 64K/256K Memory Expansion
For the Amstrad CPC comp ters

64K AND 256K MEMORY EXPANSION UNITS.
1.0 PREFACE 1
1.1 INSTALLATION 2
1.2 USING YOUR EXTRA RAM 2
1.3 RAM TEST 3
1.4
EXTENDED BASIC COMMANDS
3
1.5 WINDOWS AND PULLDOWN MENUS 4
1.5.1 MORE WINDOWING 5
1.6 ARRAYS, VARIABLES AND STRINGS 6
1.6.1 MORE ABOUT ARRAYS 9
1.6.2 STRING STORAGE 10
1.7
ANIMATION AND PICTURE SHOWS
11
1.8 ADVANCED PROGRAMMING 13
1.9
PEEKING AND POKING
15
1.10 PROGRAMMING WITHOUT RSX's 16
1.11 TECHNICAL DETAILS 17
1.11.1 THE LOAD ADDRESS 17
1.11.2
SAVING TO DISC
17
1.11.3 INCREASING CP/M 2.2 TPA 17
1.11.4 COMMERCIAL PROGRAM COMPATIBILITY 17
1.11.5 USING CP/M 2.2 18
1.12 ERROR MESSAGES 18
1.13 REFERENCE OF RSX COMMANDS 19
1.14 TECHNICAL DETAILS (HARDWARE) 20
1.15 CUSTOMIZING YOUR CP/M+ DISC 22
CONTENTS
PAGE.

64K and 256K MEMORY EXPANSIONS.
These nits are available for the CPC 464, 664 and 6128 comp ters.
By sing the 64K pgrade the 464 and 664 comp ters will have the same amo nt
and config ration of RAM as the CPC 6128. The 256K gives an extra 192K on top
of this! The expansion will allow the se of CP/M+ as s pplied with the CPC
6128 with its massive 61K TPA opening p an even larger software base for
Amstrad sers. There is also an tility for increasing the TPA on CP/M 2.2 to
61K.
The RAM can be accessed by means of bank switching sing a single I/0 port.
Memory is act ally switched in and o t of the 64K Z80 address space in 16K
s b-blocks, as are the ROMs. The port determines which partic lar combination
of the original fo r 16K s b-blocks and any new s b-blocks from the expansion
RAM will occ py the 64K address space at any time. Control of the I/0 port
can be from either BASIC or machine code.
To se the additional 64K/256K of RAM, the expansion is s pplied with bank
switching software (altho gh it can be switched witho t this software).
The software adds some extra BASIC commands, RSXs, which make it possible to
se the second 64K (or 3rd, 4th and 5th in the case of the 256K expansion)
for storage for screens, windows, graphics and BASIC arrays. This ability
means that yo can write m ch larger BASIC programs, as most of the memory on
the nexpanded CPC464/664 is normally sed for arrays, variables and
graphics.
The additional BASIC commands are :
|BANK,n Map a bank of 16K directly into memory space.
|SWAP Alternate between the low an high screens.
|LOW Change to the low screen.
|HIGH Change to the high screen. (Defa lt screen).
|SAVES,n Store a screen to a 16K bank.
|LOADS,n Retrieve a screen from a 16K bank.
|SAVEW,w,n Store a window's contents into expansion RAM.
|LOADW,w,n Load a window with data from the expansion RAM.
|SAVED,n,s,l Transfer original RAM to expansion RAM.
|LOADD,n,s,l Load original RAM from expansion RAM.
|PEEK,n,s,v Read the val e of a byte in expansion RAM.
|POKE,n,s,v Change a byte in the expansion RAM.
These commands make s ch feat res as p ll down men s, f ll screen animation
and large spreadsheet type programs or databases very easily programmed from
BASIC as never before possible on the nexpanded CPC464 and 664 comp ters.
-1-

WARNING.
Ens re that the power to yo r Amstrad comp ter is switched OFF before yo fit
the interface to the expansion socket. Fail re to comply with these
instr ctions may ca se permanent damage to the RAM pack or the comp ter.
1.1 Installation.
Power down yo r Amstrad comp ter. Pl g the RAM pack into the socket on the
back of the comp ter. On the CPC 464 this socket is labelled 'Floppy
Disc', on the CPC 664 and CPC 6128 the socket is labelled 'Expansion'.
Other expansions s ch as the Amstrad Disc interface for the CPC 464,
DK'tronics Lightpen and Speech Synthesizer, or ROM expansions can be
fitted into the expansion socket on the back of the RAM pack. Now switch on
the comp ter.
The comp ter sho ld power p as normal. If it fails to do so, check that
all the connections are correctly made. Note that all DK'tronics prod cts
have a key location on the connector to ens re that there can be no
alignment problems. OTHER interfaces may not have this keyway (the
Amstrad disc interface is the most familiar example). Hence any
connection problems will s ally lie between the RAM pack and these
expansions. If this is the case, try reconnecting the interfaces BEFORE
inserting the RAM pack into the comp ter. This will give yo a better view
when lining p the pins.
If the comp ter fails to power p, or crashes on power p (Miscellaneo s
patterns all over the screen!), the monitor may c t o t the power to
the comp ter. On the colo r monitor, j st switch the MONITOR off and
then attempt to reconnect as above. The monochrome monitor may have to
remain switched off for several seconds before power will be reinstated
to the comp ter.
It is very nlikely that the comp ter will fail to power p with the RAM
pack alone. If this is the case, then the fa lt will probably lie with the
RAM pack. * Ret rn the RAM pack to RAM ELECTRONICS if this is the case.
* IT IS ESSENTIAL THAT YOU COMPLETE YOUR WARRANTY REGISTRATION CARD AND
RETURN IT TO US IMMEDIATELY UPON PURCHASING THIS PRODUCT FROM YOUR DEALER
(UK ONLY).
1.2 USING YOUR EXTRA RAM.
There are two ways to se the extra RAM. There is a cassette s pplied with
the RAM pack containing extensions to BASIC. Here the extra RAM can be
sed simply from BASIC programs. Alternatively, the RAM is accessible both
from BASIC and machine code sing the OUT command. The experienced
programmer will be able to se the RAM for whatever he pleases and
write c stom software for that p rpose. Commercial programs will no
do bt se this approach.
The second method is described in detail in section 1.10. The first way
is explained in the following chapters:-
-2-

With the comp ter set p as above, load the RSX software from the cassette
tape s pplied:-
On disc systems type '|TAPE' and press <ENTER>
b) Type 'RUN”' and press <ENTER>.
c) The loading seq ence is described in detail in yo r Amstrad ser
man al.
d) When the program has finished loading, yo will be asked to enter a
loading address. J st press <ENTER> for now. (See section 11.)
e) The comp ter will test the RAM and then print o t how m ch RAM yo have
got, then the comp ter memory will be clear ready for yo r own programs.
1.3 RAM TEST.
When the RSX code is first loaded, it does an extensive RAM test.
Sho ld the RAM not f nction correctly the program will inform yo that an
error has been fo nd. Along with this, it will print o t diagnostic
information to help in the repair of the RAM pack.
In the nlikely event that an error is fo nd, please note the information that
is given and ret rn the RAM pack for replacement or repair.
(See warranty registration note.)
1.4 EXTENDED BASIC COMMANDS.
There are a total of twelve extra commands provided by the RSXs on
tape. Some may have parameters, some will not. Sometimes the command may
have different formats and n mbers of parameters. We have tried to disc ss
each command in its simplest form and later sections will describe added
parameters which make the command more flexible and economic on memory.
Yo may have noticed that d ring the RAM test, the comp ter printed o t the
n mber of the 'bank' it was testing. Each bank is 16K of memory. For
the 64K expansion there are 4 banks while the 256K RAM pack has 16
banks. To access a partic lar part of the expansion's m emory the re h as
to be a bank n mber and possibly a bank address.
For example, type:- '|SAVES,1' and press <ENTER>
The comp ter will respond with READY. What yo have done is to store what
was on the screen into bank 1.
Now clear the screen sing CLS. To get the screen's contents back,
type:- '|LOADS,1' and press <ENTER>
Yo can save as many screens as yo have memory for. That means fo r
screens on the 64K RAM and sixteen screens for the 256K RAM. Screen displays
co ld be created from another program or drawn sing a lightpen. Store these
on tape or disc then load them back into RAM for se thro gho t the program.
Screen displays which take a long time to create within a program, for
example mazes, can be created once, then stored for instant se whenever
necessary.
-3-

The command can be s mmarized:-
|SAVES,[n] save data to bank (n= the bank n mber)
|LOADS,[n] load data from bank
1.5 WINDOWS AND PULLDOWN MENUS.
One of the feat res that makes the Amstrad's windows less flexible than
those on larger b siness machines, is the fact that the contents of a
window which overlaps another are lost when the other window is sed.
There are two new commands which allow the contents of windows to be saved
and reloaded from RAM. This will allow the se of tr e p lldown men s,
that can cover text, b t not remove it.
EXAMPLE:-
NEW
10 MODE 1
20 FOR i=0.05 TO 1 STEP 0.05 : REM Draw grid on screen
30 MOVE 640*i,0 : DRAW 640*i,400
40 MOVE 0,400*i : DRAW 640,400*i
50 NEXT i
60 WHILE INKEY$="" : WEND : REM Wait for a key press
70 WINDOW#1, INT(RND(1)*19+1),INT(RND(0)*9+INT(RND(1)*5+17)),
INT(RND(1)*14+1),INT(RND(0)*14+INT(RND(1)*10+5))
80 PEN#1, 2 : PAPER#1, 3
90 |SAVEW,1,1 : REM Save contents of window into RAM
100 CLS#1 : REM Clear window
110 WHILE INKEY$="" : REM Wait for 2nd key press
120 PRINT#l, "This is a window"
130 WEND
140 |LOADW,1,1 : REM restore window's contents
150 GOTO 60
The above program ses two new commands: |LOADW and |SAVEW. As yo are
probably aware, there are eight windows (0-7) which can be defined. The
first parameter is the reference to a window. The second is the bank
n mber.
|SAVEW, [window n mber], (bank] save window to bank
|LOADW, (window n mber], (bank] load window from bank
See the chapters in the ser man al abo t windows for more details.
-4-

1.5.1 MORE WINDOWING.
A window of any size, even the whole screen, will fit into a single bank
of expansion RAM. This is fine if yo r window is nearly a f ll screen or
will vary in size like the above example. On the other hand if yo r window
was defined as 10 x 10 in Mode 1, then the amo nt of memory needed to
store this window wo ld be less than 16K. In fact only 1600 bytes are
needed (see below). Th s to se a whole bank wo ld mean wasting over 14K of
memory.
To deal with this problem, the RSX window command can take an extra
parameter to define where yo want the window's contents to reside in the
RAM bank. In the 10 x 10 window yo co ld place the data anywhere
between 0 and 14783.
The command can be written:-
|SAVEW, [window n mber], [bank], [bank address]
|LOADW, [window n mber], [bank], [bank address]
The bank address is an address between 0 and 16383. The amo nt of data in
bytes sed to store a window needs to be taken away from the top val e
and this leaves the range between which the data can be stored. If
yo p t the data at the bottom of the RAM bank, at address 0, then the
memory from 1600 to 16383 is free for other windows or data arrays.
HOW TO CALCULATE A WINDOW'S SIZE.
In order to have more than one window per bank, yo need to know how m ch
memory the window will take p. If the window will vary in size between
two limits, se the higher of the two. Depending on which mode yo are
sing, the fig res are calc lated as below.
In each case: X1 is the left most x coordinate
X2 is the right most x coordinate
Y1 is the top y coordinate
Y2 is the bottom y coordinate
MODE 0 SIZE=(X2-X1+1) * 4 * (Y2-Y1+1) * 8
MODE 1 SIZE=(X2-X1+1) * 2 * (Y2-Y1+1) * 8
MODE 2 SIZE=(X2-X1+1) * (Y2-Y1+1) * 8
The comp ter will give an error if the window is too large to fit in the
space yo have allotted for it. Also if the size is miscalc lated the
windows may overlap in the bank and ca se strange effects.
EXAMPLE 2:-
10 PEN 1 : PAPER 0 : MODE 1
20 size = 14 * 2 * 10 * 8
30 LOCATE 1, 13 : PRINT " 'n' for new window 'd' to remove window"
40 WINDOW 1, 14, 1, 10 : PAPER 3 : CLS
50 bankaddress=0 : level=0
60 PRINT#level, "Window";level
70 keypress$=LOWER$(INKEY$)
-5-

80 IF keypress$="n" THEN GOSUB 110
90 IF keypress$="d" THEN GOSUB 190
100 GOTO 60
110 If level=7 THEN RETURN
120 level=level+1
130 WINDOW#level, 1+level*3, 14+level*3, 1+level*2, 10+level*2
140 |SAVEW,level,1,bankaddress
150 bankaddress=bankaddress+size
160 PEN#level,0 : PAPER#level, (level AND 1) + 1
170 CLS#level
180 RETURN
190 IF level=0 THEN RETURN
200 bankaddress=bankaddress – size
210 |LOADW,level,1,bankaddress
220 level=level-1
230 RETURN
The above program only ses one bank of RAM b t all 8 windows are
defined. The variable 'level' is sed to stand for the level of
windows and the variable 'bankaddress' points to the next free place in
the bank RAM.
1.6 ARRAYS, VARIABLES AND STRINGS.
There are two general p rpose data moving commands to allow data from
the program to be moved to and from the RAM pack.
These two commands are :
|SAVED, [bank], [Start location], [length], [bank address]
|LOADD, [bank], [Start location], [length], [bank address]
The first parameter references which bank yo want to se. The start
location is a memory address where there is some data. The amo nt of data
is given as the length. Optionally a bank address can be given to allow
more than one type of data to be stored in the RAM.
It is possible to save all kinds of data sing these commands, b t we will
firstly disc ss how to save simple n merical arrays these being the
easiest to nderstand.
Say for example that yo r program deals with stock control of p to 60
items. Yo may have a string array containing the names and a n merical array
containing the n mber of each item yo have in stock.
This wo ld se abo t 1K for the names and 300 bytes for the stock
fig res. However what if yo pdate the stock val e every week and yo want
to keep the last year of stock on record! Or even the last five years. Now
the fig res wo ld take p abo t 15K or even 75K.
These co ld be comfortably stored on disc, or even tape for a year's
stock, and the data read every time a calc lation was needed, b t yo
will probably agree that a long time wo ld be spent waiting for
reading the data each time a distrib tion is calc lated for each item.
-6-

Obvio sly, it wo ld be easier to load all the records into RAM, then access
the data immediately:-
Instead of defining an array of dimensions 'stock(60,52)' taking over 15K of
val able RAM which co ld be sed for programs, define and array 'stock(60)'
Read all the data from disc a week at a time, and store each week of data
int o bank RA M. To do thi s yo n eed t o know tw o things. One, where
does the array lie in memory? and two, how many bytes is it necessary
to save?
1) Where is an array stored?
The address of any variable can be q ickly fo nd sing the '@' before a
variable. For example, dimension the above array:-
DIM stock (60)
Now type: PRINT @stock(0)
The comp ter will reply by giving the memory address where the first
element of the array is stored. Try:-
PRINT @stock(1)
The n mber ret rned will be five higher in val e. This is the address of
the second variable.
The '@' prefix will work in front of any variable. The first item of an
array is obvio sly '@stock(0)'. If yo are sing m lti-dimensional arrays,
the first item is '@stock(0,0)' or '@stock(0,0,0,0)' depending on the n mber
of dimensions.
2) How long is an array?
First of all, different types of array take different n mbers of bytes per
element. For real n mbers, there are 5 bytes per element. Integer arrays
take 2 bytes per element. String arrays are of variable length. And will be
dealt with later.
Next, the n mber of dimensions and elements needs to be taken into
acco nt. Remember that elements start from 0. This means that an array of
'stock(60)' has 61 elements. Whether or not yo prefer to se the 0 element
is p to yo , b t if yo forget it, there co ld be some nexplainable
b gs appearing in yo r program. Once yo know the real n mber of elements
in every dimension, simply m ltiply together all the dimensions to find
o t the total n mber of elements in all dimensions.
For example: 'stock(60)' has a total of 61 elements.
'stock(60,52)' has 61*53 elements = 3233 elements.
'stock%(10,5,12)' has 11*6*13 elements = 858 in all.
To find the total memory, m ltiply the total n mber of elements by the
amo nt of memory needed by each element.
For example: 'stock(60)' takes 61*5 = 305 bytes.
'stock(60,52)' takes 3233*5 = 16165 bytes.
'stock%(10,5,12)' takes 858*2 = 1716 bytes in all.
-7-

The array we are sing is 304 bytes long, and starts at @stock(0). In a
single bank of RAM we can store 305 bytes abo t 53 times. The bank address
starts at 0 and goes p in steps of 305 bytes:-
0 305 610 915 1220 1525 etc.
We shall store week 1 at bank address 305, week 2 at address 610 and so on
for all 52 weeks.
Data for test p rposes co ld be written onto disc or tape by the
program below. Once the test file is written, keep it for se while yo
are developing yo r program.
10 OPENOUT "stock.dat"
20 FOR week=1 TO 52
30 FOR item=1 TO 60
40 Print#90, INT(RND(1)*3000+100)
40 NEXT item
60 NEXT week
70 CLOSEOUT
80 END
Now type 'NEW' and enter the following program:-
10 DIM stock(60)
20 INPUT "read file (y/n)";ans$
30 IF LOWER$(ans$)="y" or LOWER$(ans$)="yes" THEN GOSUB 1000
40 REM rest of program ....
1000 REM s bro tine to read data from disc.
1010 OPENIN "stock.dat"
1020 FOR week=1 TO 52
1030 FOR item=1 TO 60
1040 INPUT#9, stock(item)
1050 NEXT item
1060 |SAVED,4,@stock(0),61*5,week*305
1070 NEXT week
1080 CLOSEIN
1090 RETURN
The above program co ld be sed to read the file from disc or tape. Once
the file is in bank RAM, the contents will stay there for se ntil the
comp ter is switched off, or some other data is p t in that bank. This
means that data need only be read once from disc, then the program can be
rer n witho t losing the data. This co ld also be sef l too if yo
wish to write a n mber of programs to se the same data.
Once the data is in memory, yo can access each week's data simply by
reloading the stock array. Add the section below to draw a bar graph for a
given section.
100 MODE 2
110 LOCATE 1,1
120 INPUT "Which item to analyse",itemno
130 IF itemno < 1 OR itemno > 60 THEN 120
-8-

140 CLS : LOCATE 30,1
150 PRINT "Bar Chart For Item"; itemno
160 LOCATE 10,25
170 PRINT"Jan Feb Mar Apr May J n J l A g Sep Oct Nov Dec": REM 3 spaces
between each.
180 FOR loop=0 TO 4
190 LOCATE 1,24-loop*5
200 PRINT STR$(loop);"000"
210 NEXT loop
220 MOVE 60,328 : DRAW 60,0 : DRAW 61,0 : DRAW 61,368 :
MOVE 640,24 : DRAW 48,24
230 FOR loop=1 TO 4
240 MOVE 48,loop*80+24 : DRAW 60,loop*80+24
250 NEXT loop
260 FOR week=1 TO 52
270 If week/2=week/2 THEN n=l ELSE n=2
280 |LOADD,4,@stock(0),61*5,week*305
290 ycoord=(stock(itemno)/4000*320) AND 4092
300 FOR xcoord=1 TO 11 STEP n
310 MOVE 49 + xcoord + week*11,ycoord+26 :
DRAW 49 + xcoord + week*11, 26
320 NEXT xcoord
330 NEXT week : GOTO 110
1.6.1 MORE ARRAYS, VARIABLES AND STRINGS.
If yo have a program that ses all the memory of the comp ter d e
to needing a large array, yo can se the bank RAM for storing data
witho t even dimensioning an array.
For example if yo have a two dimensional array 'sales%(365,30)' to
store the amo nts of certain types of stock yo sell for each day in one
year. Even tho gh yo are sing integers, the array ses over 22K of
memory.
Instead of having the whole array in BASIC memory, each element can be
accessed by sing a s bro tine to read o t a val e, and one to store a
val e.
10000 REM load 'store%' from bank memory sing 'year' & 'type'.
10010 p= (year*31 + type)*2
10020 bank=1 : IF p >=16000 THEN p=p-16000 : bank=2
10030 |LOADD, bank, @store%, 2, p
10040 RETURN
11000 rem copy 'store%' to bank sing 'year' & 'type'
11010 p= (year*31 + type)*2
11020 bank=1 : IF p >=16000 THEN p=p-16000 : bank=2
11030 |SAVED, bank, @store%,2, p
11040 RETURN
Two banks are sed, 1 and 2, and the variables 'year' and 'type' are
sed to reference which element is req ired. On line 10030 and 11030,
there are j st 2 bytes moved to and from the bank RAM beca se we are
sing integers. The '*2' in lines 10010 and 11010 reflect the fact
that an integer is stored in two bytes. If real variables were sed, 5
bytes wo ld need to be sed instead. Lines 10020 and 11020 decide
whether the element is in the first bank or the second.
-9-

If the array is to be filled with data from tape or disc, there is no need
to initially clear the val es to nil. If yo want all elements preset to
zero then the easiest way is to save a blank screen into each bank at
the start of the program:-
10 MODE 1 : PAPER 0 : CLS
20 |SAVES,1
30 |SAVES,2
1.6.2 STRING STORAGE.
The major obstacle in storing strings is that they can vary in length and
can be stored anywhere in memory, incl ding in a BASIC program. One
method of storing string arrays is o tlined below. However yo may find an
easier way to store strings than the one described below when yo consider
exactly what yo want to do.
S ppose that yo wanted to store 500 names, p to 20 characters long each.
A bank is separated into nits of memory 21 bytes each so that strings can
be randomly accessed. In each 21 byte segment there is one string, and one
byte to say how many letters there are in that string. That means that we
will se a total of j st over 10K. If we se the variable 'name' to
specify the string we want then we can enter two s bro tines; one to p t
a string from bank 1 into 'name$' and one to store the contents of
'name$' into RAM bank n mber 1:-
20000 REM assign 'name$' to string n mber 'name'
20010 b$=" " : REM 21 spaces
20020 |LOADD, 1, PEEK(@b$+1) + PEEK(@b$+2)*256, 21, name*21
20030 name$=MID$(b$, 2, ASC(b$)) : RETURN
21000 REM Store 'name$' in bank as element 'name'
21010 b$=" " : REM 21 spaces
21020 MID$(b$,1,21) = CHR$(LEN(name$)) + name$
21030 |SAVED, 1, PEEK(@b$+1) + PEEK(@b$+2)*256, 21, name*21
21040 RETURN
A d mmy string b$ is sed to form the element before it is saved into RAM.
The first character is set to the length of 'name$'. The latter 20
characters are where the contents of 'name$' are stored. Then 21
characters are copied into bank RAM. When the string is retrieved the
characters are copied o t and 'name$' is set to the right length by
looking at the first character.
String storage wo ld come into its own if all the words were of the same
length beca se there wo ld be no wastage. For example a word q iz program
sing five, six and seven letter words. A bank of RAM co ld be sed for each
length of word. A loader program wo ld set p the data into the RAM, then
another co ld be CHAINed and se p to 36K of RAM for program.
A n mber array co ld also be stored in bank RAM to index the first
letters and so aid the speed of access to a partic lar word.
-10-

1.7 ANIMATION AND PICTURE SHOWS.
We have seen how screens and windows can be stored and retrieved.
Animation is the act of p tting pict res on the screen q ickly eno gh
so that the eyes see something move. With 64K or 256K of memory whole
screens can be stored away, then p t on the screen to prod ce animation.
Yo may have noticed in section 4 that when a screen loads onto the
screen, yo can see each line appear. To ill strate, type in the
following program:-
10 MODE 1
20 BORDER 0
30 FOR col=0 TO 3
40 INK col,0
50 NEXT col
60 FOR col=0 TO 3
70 PAPER col : CLS
80 |SAVES,col+1
90 NEXT col
100 INK 0,1 : INK 1,6 : INK 2,21 : INK 3,13
110 PEN 1 : PAPER 0
120 WHILE INKEY$=""
130 FOR screen=1 TO 4
140 |LOADS, screen
150 NEXT screen
160 WEND
170 END
The program saves fo r colo red screens into bank RAM, then loads then p in
seq ence. Unfort nately, the effect is a striped pattern.
In order to create animation which is easy on the eye the comp ter
needs to create the screen display, then instantly display it.
Three new instr ctions that allow this to be done are:-
|LOW, |HIGH and |SWAP
Before the commands can be nderstood it is necessary to know how the
Amstrad's screen can be sed. The normal screen is located at 49152.
However the Amstrad is capable of viewing a screen anywhere in memory in
16K blocks. The first block at 0 and the third block at 32768 are
diffic lt to se for screen as the comp ter ses these as part of the
BASIC interpreter. The block of memory at 16384 is free for se as
long as BASICs HIMEM is lowered to below 16384. Using this, we have
called the original screen the high screen and the new screen at 16384 is
called the low screen. To go from one to the other j st se:-
|LOW to set the low screen in action
|HIGH to reset the high screen
|SWAP to swap from low to high and vice-versa
Whenever the swap is made, the comp ter is told, and all f rther text and
graphics appear on the selected screen.
-11-

To se this facility of swapping from one screen to another instantly, the
screen and window commands can have an added parameter which tells the
comp ter to load or save the data to and from the alternate screen.
The new forms can be written:-
|SAVES, [ bank ], [ swap ]
|LOADS, [ bank ], [ swap ]
|SAVEW, [ window n mber ], [ bank ], [ bank address ], [ swap ]
|LOADW, [ window n mber ], [ bank ], [ bank address ], [ swap ]
If the swap val e is zero, by defa lt, then the command will act on the
screen that is presently being displayed. Alternatively, if the val e is
one the comp ter will load and save data from the screen which is not
being displayed. When the work is done, the comp ter can swap screens and
the effect is that the screen appears to change instantly.
In the above program type these lines:-
5 MEMORY 16383 : |HIGH
135 IF screen\2=screen/2 THEN t=TIME : WHILE TIME <t+20 : WEND
140 |LOADS, screen, 1 : |SWAP
Now that the comp ter can b ild p the screen while another is being
displayed there is no pattern. The colo red screen appears to change
instantly.
D e to the fact that the bank memory moves into the address space at 16K
it takes longer for the transfer of screens to be made to the low screen
than to the high screen. Hence line 135 delays the comp ter as it is to
load the high screen. This means the time each screen is on the screen
remains the same. Try removing line 135 to see the difference.
If a longer delay were to be p t between line 140 and 150 yo wo ld get
a pict re show effect. Alternatively, yo co ld select screens when a
key is pressed.
On a small scale, a window co ld be defined and graphics co ld be
rapidly displayed witho t resorting to swapping screens.
Note, that of less se is the fact that the contents of screens and
windows can be saved from a screen which is not on display simply by
adding a one for the swap parameter. For example if yo want to load a
series of screens from tape or disc, load them into the low (16K)
screen. Messages generated by the tape system need not be switched off as
the screen's contents will not be changed in the low memory screen.
10 LOAD "screen1",16384 : |SAVES, 3, 1
The above will load a screen then save it to bank 3. The screen the ser
sees can have something else on it.
-12-

1.8 ADVANCED PROGRAMMING.
This section introd ces one new command and some other programming
aspects which yo may find sef l.
The new command is:-
|ASKRAM, [ enq iry ], ( variable ]
The command allows certain constants to be fo nd by the program yo are
writing. For example it can ret rn the n mber of banks available to the
program as this will change depending on whether yo are sing the 64K
RAM pack or the 256K RAM pack. The 'enq iry' val e is a n mber 1 to 3 which
selects what yo want to know. The answer is placed in an INTEGER variable
defined by the second parameter.
1000 a%=0 : |ASKRAM, 1, @a% .. will assign a% to the amo nt of RAM
1100 a%=0 : |ASKRAM, 2, @a% .. will assign a% to the n mber of banks
1200 a%=0 : |ASKRAM, 3, @a% .. will set a% to 0 or 1 depending on
whether there is a problem with the RAM
The last command can be sed to make s re the RAM is there and ready to
se if in yo r programs yo do not want to have to load the RSX loader
first. It is possible to load j st the RSX machine code on its own:-
20 MODE 1 : PRINT "Program Loading!"
30 I=HIMEM
40 MEMORY 9999
50 LOAD "rsx", 10000
60 I=I-( PEEK(10004) + PEEK(10005)*256+1)
70 POKE 10002, I-INT(I/256)*256
80 POKE 10003, INT(I/256)
90 PRINT CHR$(30);CHR$(21);
100 CALL 10000
110 PRINT CHR$(30);CHR$(6);
120 a%=0 : |ASKRAM, 3, @a%
130 IF a% THEN PRINT "RAM is fa lty" : END
140 CLEAR : MEMORY PEEK(10002) + PEEK(10003)*256-1
160 CHAIN "part2"
The program above will load the RSX machine code and p t it into
memory. Nothing will be printed on the screen nless the RAM proves to be
fa lty or not even there! The program 'part2' wo ld be the b lk of the
program. Loading the program in two parts saves reloading the RSX code
every time the program is r n.
The code has to be loaded in at 10000 in memory before it is relocated for
se. The 16 bit val e in locations 10002 and 10003 is the place yo want
the code to be located at. Another 16 bit val e in locations 10004 and
10005 contains the length of the code which is moved higher in memory.
Nearly 1K of the program is only needed once - the relocation and the RAM
test programs, and hence this part is not moved higher in RAM.
-13-

If yo want to se ser defined graphics then add the following lines:-
10 SYMBOL AFTER 256
150 SYMBOL AFTER 0
The val e in line 150 will be different depending on how many ser
defined graphics yo want.
In yo r program yo may want to have a n mber of different styles of
character set. After yo iss e a SYMBOL AFTER command, HIMEM is set j st
below the ser defined graphics. Hence it is possible to se the |LOADD and
|SAVED commands to move graphics to and from the graphics characters.
If yo have a program that defines the character set, the definitions
can be saved and loaded into bank RAM so that a program may have
m ltiple character sets.
10 SYMBOL AFTER 0
20 chars=HIMEM+1
30 REM define symbols here
1000 SAVE "set1.grp", B, chars, 2048
This program will save yo r character set onto disc or tape.
On yo r final program yo may wish to load a n mber of sets:-
10 SYMBOL AFTER 0
20 chars=HIMEM+l
30 LOAD "set1,grp", chars : |SAVED, 1, chars, 2048, 0
40 LOAD "set2.grp", chars : |SAVED, 1, chars, 2048, 2048
50 LOAD "set4.grp", chars : |SAVED, 1, chars, 2048, 4096
The reason the variable 'chars' is set p is beca se the val e of
HIMEM alters when the disc or tape is accessed.
D ring the program, a s bro tine co ld be sed to select a character set:-
1000 REM given the variable 'set', load the characters
1010 |LOADD, 1, chars, 2048,(set-1)*2048
1020 RETURN
Note that the variable 'set' is sed. In the above loading seq ence sets
1 to 3 will be valid. More or less co ld be added as it s its yo .
All of this setting p can be done on the loader program, j st once. When
the program is s bseq ently r n, there is no need to reload the bank RAM.
The setting of chars can be fo nd whenever needed by:-
200 CLEAR : SYMBOL AFTER 0 : chars = HIMEM+l
This will remove any disc b ffers that have been set p and 'chars' will
indeed point to the characters.
-14-

1.9 PEEKING AND POKING.
There are two commands which allow the memory in the banks to be
viewed and changed byte by byte.
|POKE, [ bank ], [ bank address ], [ val e ]
|PEEK, [ bank ], [ bank address ], [ variable ]
|POKE works in a similar way to the original POKE. Yo need to s pply a
bank n mber in addition to the normal address and val e. The bank
address is in the range 0 to 16383 or 0 to 16K.
|PEEK is a command rather than the normal f nction. The bank and bank
address are the same as for |POKE. To find o t the val e, yo need to
s pply an integer variable in a similar way to the |ASKRAM command.
For example:-
10 val e%=0
20 |PEEK, 3, 12345, @val e%
30 PRINT val e%
The above will read the byte from location 12345 in bank n mber 3. The @
character tells the RSX extension where the variable is in memory so that
its contents can be changed to the byte req ired.
|PEEK and |POKE are not really commands for the beginner, in fact they
have only been incl ded for the more advanced programmer who wishes to
se the bank RAM in his own way.
Another advanced command which has been incl ded for the experienced
programmer is |BANK.
|BANK, [ bank n mber ]
The command is followed by one parameter. If this parameter is not
present, a zero is ass med. The bank referenced is mapped into the
address space at 16K to 32K. A bank n mber of zero will map the
original RAM back in, n mbers 1 to the maxim m bank n mber will map that
bank into the address space. If a bank is mapped in, the comp ter will se
the bank memory instead of the normal RAM. However, the screen will
still be taken from the original RAM if |LOW was iss ed. The advantage
of this is that the whole memory can be sed for programming instead
of having to set the top of memory to 16383. The disadvantage is that if
the program is halted while the low screen is being displayed, the
comp ter will write screen data into the BASIC program - ca sing chaos.
Make s re yo are acc stomed to sing |BANK, |POKE and |PEEK before yo
risk creating a large program sing them. Save the program freq ently
in case yo make a mistake and lose yo r work.
-15-

1.10 PROGRAMMING WITHOUT RSX's.
With no RSX software the programmer can still access the memory from the
RAM banks. To se the RAM yo rself, some degree of nderstanding of the
memory map of the Amstrad is necessary.
From both BASIC and machine code, the original block of memory from
16384 to 32767 CANNOT be sed for program. Hence in BASIC, yo need to set
the top of memory to 16383. Machine code is free to se any memory that it
can normally except the block mentioned.
The extra RAM is mapped into the addresses 16384 to 32767 in 16
banks. Once the bank is mapped in, yo can do anything with the RAM yo
normally wo ld. It is inadvisable to se the bank RAM for machine code
beca se if yo s bseq ently change the bank, the program disappears!
Nevertheless, programs can be written to r n in banks and indeed in the
original 16K block that is banked o t, b t it is necessary to do the bank
changing o tside of this memory range. In BASIC it wo ld be extremely
diffic lt to se the banked RAM for extra programs, b t not impossible, b t
we shall leave that possibility p to yo !
The way that banks are selected is defined below:-
IN BASIC: Where 'bank' is the n mber of the bank to map in
OUT &7F00, 196+ (bank AND 3) + (bank AND 28)*2
NOTE: the bank n mbers in this case START AT 0
For 64K expansions the banks are 0 to 3. On the 256K, bank n mbers are 0 to
15.(bank 0-3 = 196-199:bank 4-7 = 204-207 etc.)
To reset the original bank:-
OUT &7F00, 192
IN MACHINE CODE: Where the bank n mber is in the acc m lator. (A)
SELECT: PUSH BC ; select bank A (save all registers except A
LD C,A ; and flags)
AND 3 ; (bank AND 3) +
LD B,A
LD A,C
AND 28 ;(bank AND 28)*2
ADD A,A
OR B
OR 196 ;+ 196
LD BC,07F00H ;BC=&7F00
OUT (C),A
POP BC
RET
Again the bank n mber in the acc m lator starts at 0. To reset the
original bank:-
RESET: PUSH BC ;reset original memory
LD BC,07F00H ;BC=&7F00
LD A,192
OUT (C),A
POP BC
RET
-16-

1.11 T ECHNICAL DETAILS.
1.11.1 The Load Address.
The software which loads from tape is relocatable. However the areas of
memory in which the program can go is limited to between 32768 and the top
of memory. This is beca se the banked RAM appears in the block 16384 to
32767. (See previo s chapter for explanation of why!) Below the 16K
bo ndary, the RSX command table will no longer f nction. Hence, d ring
relocation, the code is loaded at 10000 in memory and moves to a place
higher in memory. Pressing <ENTER> while loading, will a tomatically
select the highest location available. Alternatively yo may wish to load
the code to a lower address and reserve some space for yo r own programs.
1.11.2 Saving to Disc.
The software on the cassette is NOT protected. Hence to save it onto disc
or even onto another tape at speed write 1 is a matter of loading the data
into memory, then saving it.
1) Type '|TAPE' and press <ENTER> (for disc systems)
2) LOAD "bank"
3) MEMORY 9999
4) LOAD "rsx", 10000
5) Type '|DISC' or set SPEED WRITE as desired
6) SAVE "bank"
7) SAVE "rsx", B, 10000, 4000
1.11.3 INCREASING CP/M 2.2 TPA.
Boot p CP/M 2.2 that has CLOAD.COM on it. Copy the two programs NEWCPM.COM
and OLDCPM.COM from cassette to disc by typing:-
CLOAD "NEWCPM.COM <enter>.(Repeat for OLDCPM.COM)
Then create a new CP/M system file by typing:-
A> MOVCPM 255 * <enter>
A> SAVE 34 NEWCPM.SYS <enter>
The new working disc now contains yo r increased TPA CP/M, invoked at
any time by typing:-
A> NEWCPM
Yo can ret rn to the original CP/M by typing:-
A> OLDCPM
This m st be done before sing some of the DFS tilities s ch as
format etc. as these will only work with OLDCPM.
1.11.4 Commercial Program Compatibility.
The RAM expansion is compatible with the banked RAM s pplied with the
6128. This means that a n mber of programs written for the 6128 will now
work on the CPC464. The RSX software provided will work on the 6128 where
the 256K pack will give 320K of banked RAM.
The bank switching software in its s pplied state will only access 256K
or 16 banks of memory. If yo add more memory or have the CPC6128 with a
256K memory pack, the RSX software can be told to access a f ll 512K of
banked memory (32 banks) by poking location 10006 with 1. See section 8 for
explanation of how to load the RSX software on its own.
55 POKE 10006, 1 This line will do the trick!
-17-

If a commercial program fails to work on yo r CPC464 or CPC664 then try the
s ggestions below.
1) The software may be sing the new firmware vector at &BD58. If this is
the case, try r nning the RSX program before r nning yo r application
program.
Some programs which will f nction correctly after the RSX software
tape has been loaded in are Tasman's Tasword(R) word processor, Tasspell
and Tasprint for the C PC612 8. In conj nction with these, Campbell
Systems' Masterfile 128 will provide a 64K filespace and interfaces with
Tasman's software.
2) Some software, whether loaded from disc/tape or booted from a backgro nd
ROM will check the ROM identity by sing the firmware call &B915.
There is one more command incl ded in the RSX software on tape which will
ca se a CPC464 or 664 to em late the ROM identity of the CPC6128:
Type |EMULATE and press <ENTER>
Any programs that call the ROM identity ro tine will now be informed
that the comp ter is a CPC6128 and may now work correctly.
3) The software may se some feat res of the CPC6128 ROM which are
navailable on the CPC464 and CPC664 machines. In this instance, yo may
be able to get information on how the program can be altered to work on the
CPC464 or 664 from the man fact rers of the program in q estion.
1.11.5 Using CP/M 2.2.
CP/M 2.2 as s pplied with all Amstrad comp ters will f nction as normal
with the extra memory fitted. However if yo create and se the NEWCPM
program the TPA on C P/M 2. 2 will be increased to 61K.
Programs of yo r own devising written nder this operating system are free
to se the extra memory. See section 1.10 for details of how to se the
extra memory from machine code.
1.12 ERROR MESSAGES.
While yo are sing the RSX software, there will be some occasions when
the comp ter does not nderstand, or cannot carry o t what yo have
instr cted. The software may iss e some error messages in addition to
the normal messages that the comp ter will give. The errors and why
they are likely to occ r are o tlined below:-
1) Bad bank command Given if yo have given the wrong
n mber of parameters or if a
variable is not present where there
sho ld be one.
2) Bank navailable Yo have tried to access a bank which
is not present on yo r system.
-18-
This manual suits for next models
1
Table of contents