Spectrum Disc Interface Kempston
Spectrum Disc Interface Kempston
KEMPSTON
The Kempston disc interface for the ZX Spectrum provides a simple upgrade from cassette or
microdrive based systems to floppy discs. The operating system provides a powerful
command library, including all the standard file manipulation functions and a number of
additional commands to make K-DOS arguably the most powerful disc operating system
(DOS) currently available for the Spectrum.
1.0 INTRODUCTION
The Kempston interface can be used with any standard independently powered BBC disc
drive. Up to a maximum of four drives can be connected to the system, be they 5.25, 3.5 or 3”
drives, provided they are capable of operating in double density. Connection between your
disc drive and interface should be made through a 34-way ribbon cable terminating with a 34-
way male IDC connector at the interface end and a standard Shugart connector at the drive
end. If in doubt your supplier will be able to advise you on a suitable cable.
1.1 INSTALLATION
The interface fits into the expansion port at the back of the Spectrum. It will plug in directly,
or if you are using other interfaces (ie. Kempston’s Centronic E) then via the Kempston
interface adaptor. It is advisable to apply power to the Spectrum before the disc drive; damage
may occur if this sequence is not adhered to.
On powering up the system the Spectrum will display a copyright message to indicate the
presence of the disc interface;
and the LED will be illuminated. If this message does not appear then check that you have
installed the interface correctly. If you can find no fault in installation then consult your
supplier for advice.
If the message appears then your disc system is ready for use.
Before a disc can be used it needs to be formatted, that is the process of dividing the disc into
tracks and sectors. To format discs you will need to know the characteristics of your drive(s),
and supply the DOS with the following information:-
a) the number of tracks (35, 40 or 80)
b) the number of sides (1 or 2)
c) the stepping rate (6, 12, 20, 30 ms)
where the stepping rate is the time taken by the head in moving from one track to the next.
When formatting it is necessary to select a stepping rate greater than or equal to the stepping
speed of your drive. The FORMAT command is described in full in section 2.8.
The disc system can be reset at any time by the reset switch on the top of the interface.
WARNING: A system reset will destroy any programs currently in the DOS workspace.
Care should be taken in using the reset function.
The Kempston disc system operates as an extension to Sinclair BASIC and enhances the
performance of the Spectrum by combining high speed and capacity with a powerful set of
commands. The following file types are supported:
All K-DOS commands are prefixed by a ‘software switch’ to distinguish disc commands from
standard Sinclair syntax. The keyword PRINT following a DOS command passes parameters
needed for specific operations.
where p1, p2 etc refers to any parameters needed by the particular command.
The parameters are particularly important when using commands to access multi-drive
systems. So for a number of commands p1, p2 etc refer to the particular drive selected. It
should be noted that once a drive has been selected, it becomes the DEFAULT drive and does
not need specifying again. The PRINT statement can thus be omitted. Any references to files
other than on the default will result in a “Record not found” error.
The following sections describe the commands available under K-DOS and it is
recommended that these are read carefully before using the system.
K-DOS commands can be accomodated on the same line as standard BASIC statements.
However, since PRINT is used to pass parameters into the DOS care needs to be taken in the
use of the standard PRINT statement following a K-DOS command.
To avoid confusion when using multistatement lines use of a double colon will distinguish
innocent PRINT statements from a DOS keyword.
For example:
PRINT #4: command : : PRINT “string”
file_type:= the type of file, ie. BASIC, bytes, $data, ndata, sequ
file_size:= the size of the file in multiples of 1 kbytes (1024 bytes)
file_name:= a BASIC filename
So for example,
will catalogue all files on the specified drive (1 – 4). The current drive is selected if the
keyword PRINT is not included.
It is possible to do a selective catalogue by:
CLEAR will delete a block of BASIC lines starting at a specified line and ending at a
specified line
CLEAR 0 will substantially reduce the amount of memory taken by a BASIC program
without altering the logic flow of that program.
The BASIC size reduction is achieved by replacing all numbers by ‘VAL “nn” ‘(saving 3
bytes for each number), and integers 0, 1 and 3 by NOT PI, SGN PI and INT PI respectively
(saves 5 bytes).
When the CLEAR 0 command is used the screen is cleared and the amount of free space
before and after the command is shown. Some large BASIC programs (eg. TASWORD II)
will liberate MORE memory than is reserved by the DOS.
If a RENUMBER utility is available then re-numbering should be done prior to using this
command.
CLOSE is a Sequential Access file handling command. It will close stream #n and reclaim the
buffer.
Using stream n without opening it again (after CLOSE) will cause an ‘Invalid stream’ error
report. No drive specification is required by the CLOSE statement.
See the section on Sequential Access files for further details on the use of this command.
COPY is a tape to disc transfer utility which allows transfer of most cassette programs to disc.
where d is an optional drive specification indicating the destination drive. Default drive used
if d is not specified.
Once invoked, the command batch processes your tapes until a BREAK is detected.
file_name := disc filename (identical tape names stored with number appended to
the tape_name, incremented for subsequent files)
start_address := start address of file
file_length := length of file in decimal
Headerless blocks are saved using the filename “default” with appended numbers if
necessary.
Use of the COPY command retains whatever protection was originally built into the program,
so there is no guarantee that programs will run under the DOS. A break into the BASIC loader
will allow modification of all occurences of LOAD, SAVE, MERGE to correct K-DOS
syntax. Each file call needs to be modified if the filename on disc is different to that on tape.
BASIC programs that use machine code imbedded in REM statements will only run if the
code is relocatable and the USR address is expressed relative to BASIC variables (PROG etc).
ERASE allows the deletion of files from the specified drive’s directory.
For example,
would delete all files on drive 1 with a ten character filename referenced by the first nine
characters “file_name”. (This includes file_name1, file_name2, file_name*, file_name$,
file_name? etc)
Erasing a file from a disc with a WRITE PROTECT tab on, will generate a ‘Write protected’
error report, and a return to the DOS
So for example: A Mitsubishi 80-track, 2-sided drive with a stepping rate of 3ms could be
formatted on drive 1 as follows,
A CATalogue of which would show a disc capacity of 800 kbytes 795 of which are available
to the user. (The other 5 bytes are used by the directory).
All errors, including the error reports ‘OK’, ‘STOP’, etc are trapped and control is passed to a
line in the BASIC program. So it is possible to trap an error, and either re-run the program or
report your own error. The GOTO command gives complete anti-BREAK protection and the
facility to do all necessary housekeeping work (closing OPEN files etc) before reporting an
error.
INKEY$ will read the next character of a Sequential file opened on #n.
syntax: INKEY$ #n
INKEY$ returns the next character from a sequential file. So from a file ‘file_name’ on drive
1, INKEY$ would return successive characters from the file. If an attempt is made to read a
character after the end of a file a ‘End of file’ error report is generated.
2.11 INPUT command
INPUT will read the next record of a sequential file opened on stream n.
INPUT #n is similar to the keyboard INPUT command, but the keyboard is replaced by an
open disc file. Data is input sequentially, the file pointer being incremented by one complete
record on each read. CLOSE #n followed by OPEN #n resets the file pointer to the start of the
file.
INPUT needs information on the format of the data in the file, ie destination (string or
numeric variable), terminator used to data save, to read successfully. Any characters not
recognized by the standard keyboard INPUT are also un-acceptable to INPUT #.
So for, example,
For example,
will load a file ‘ file_name ‘ from drive 1, saved in the format of a screen.
Programs will AUTO-BOOT after a reset or power-on if they are SAVEd as file ‘AUTO’
with a line number (see sec 2.18).
MERGE will load a BASIC file from the specified drive and merge it with the program
currently in memory.
MERGE offers the programmer the ability to use ‘BASIC OVERLAYS’ to reduce the
memory usage in large BASIC programs (see sec 4).
MOVE will copy files from a specified drive to another specified drive. It can also rename
files on the specified drive.
MOVE can be used to rename discs or files on a specified drive. For example:
will rename the disc or a file on drive 1 named ‘file_name1’, file_name2. MOVE checks that
file_name1 is a disc or file identifier before renaming.
If the file cannot be found on the specified drive then a ‘record not found’ error is generated.
There are two levels of file transfer available; a single file copy and a block copy.
where d1 is the source drive, and d2 is the destination. If file_name2 = “” then a copy with
the same name as the source file is created.
The drive numbers, d1 and d2, can be identical to allow file back-up. If d1=d2 then K-DOS
prompts the user to swap diskettes as and when necessary.
For example,
will copy all files on drive d1 with the extension /BAS to drive d2.
This command can prove useful if an extension system is applied to the definition of files, ie.
/BAK for back-ups, /BAS for BASIC programs, /OBJ for object files etc.
NEW is similar to the BASIC NEW in that it will clear any program and variables in
memory. However the K-DOS NEW does not overwrite the DOS variables, and the DOS
remains enabled.
OPEN is a Sequential file handling command. It opens stream n to sequential file ‘file_name’
on the specified drive, and assigns a buffer to it. If the file already exists, it is opened for
reading, otherwise it is opened for writing.
Whenever a file is used one of more buffers need to be assigned to it. Before a file can be
read or written into it has to be OPENed. OPEN creates a buffer, accessible to the user by its
attachment to a stream. If the file already exists it is automatically opened for reading,
otherwise it is opened for writing. An existing file can be opened for reading into more than
one buffer by opening it to different streams (memory allowing). An attempt to re-open a
newly created file will generate a ‘file already open for writing’ error report.
Whenever a buffer is created, the BASIC program and its variables are ‘pushed’ up by about
570 bytes.
Consequently machine code programs imbedded in a REM statement will not execute
correctly unless they are fully relocateable. Furthermore, having all 15 buffers open accounts
for 8 kbytes of buffer space.
NOTE: DO NOT REMOVE A DISC CONTAINING OPEN FILES. CLOSE SAVES
THE FILE BUFFER, AND SETS THE END OF FILE MARKER.
It should be noted that it is possible to OPEN streams 0 – 3 for sequential input or output, and
when they are closed the Sinclair operating system re-assigns them to the Default channels, ie.
screen, keyboard and printer.
Stream 3, usually attached to the printer, will accept LPRINT, LLIST as well as PRINT #3
and LIST #3. So, by
it is possible to re-direct all printer output into a disc file which can be read and printed after
the main task has been completed.
PRINT will write individual data records into a buffer for subsequent transfer to a sequential
file.
PRINT #n is similar to the screen PRINT command, however the use of terminators and
seperators is important.
PRINT #n accepts all the standard separators; semicolon, coma and apostrophe.
Care must be taken in the use of a semicolon as a separator since it will merge two records.
For example;
PRINT #n ; a$ ; b$
would be saved as string1string2 <CR>, which could not be read back into two variables.
This can be achieved by;
PRINT #n ; a$ ; CHR$ 13 ; b$
which would be saved as string1 <CR> string2 <CR>. Similar care must be taken in the use
of a comma, since records will be saved with the same format as if they had been printed,
separated by a number of nulls.
For example,
It is possible to save an auto-booting program under K-DOS. Any program saved wit a line
number and with a filename ‘AUTO’, will auto run on a system power-up or reset. So, for
example,
Auto-booting programs need not be written in BASIC, and a machine code program will auto
run from its first memory location.
A Sequential access file is a file consisting of a number of individual data records. A data
record being an alphanumeric string or numeric data whose end is marked by a terminating
character (comma, apostrophe, CR code etc). The beginning of a record is usually defined as
the character after an end of record character. So a sequential access file can be considered as
a collection of n records which can only be read starting with record 1, and incrementing the
file pointer by one upon each read operation until the n th record has been accessed. Attempts
to read a non-existent (n+1) record will generate an ‘end of file” error report. The size of a
sequential access file will depend on the available space on the data disc and so, the demand
on memory is very modest.
K-DOS contains a number of commands for sequential access file handling OPEN #n,
CLOSE #n, INPUT #, INKEY$, and PRINT #. Reference to each command description will
give an indication of the application of each of these commands.
The K-DOS versions of MERGE and CLEAR offer the BASIC programmer immense
programming power by allowing the construction of ‘BASIC OVERLAYS’ to reduce the
memory usage in large programs.
If a BASIC program, saved with a line number, is MERGed it will auto run from that line
number having first been merged with the main program. A large BASIC program could be
written in modular form with the modules made to occupy the same block of line numbers
and SAVEd as separate auto-running programs. A Master menu would form the main body of
the program and the user responses to that menu would be simply to load the appropriate
module (overlay), run it and then return to the menu. The modules need to be auto-running
because in this way they are protected and can run from any line number.
If the MERGed module doesn’t use exactly the same line numbers as the one before you
would expect errors due to the execution of lines that should not be there. However CLEAR
simply acts as a block delete to prevent this.
APPENDIX
1. ERROR MESSAGES
The following description of error messages includes some already used by the spectrum. The
explanation below outlines any differences from the normal meaning.
6 Number too big : Used to check parameter values eg. drive number in disc
command. Check your command carefully. If error persists it
may be due to a DOS error, cleared by re-booting the system.
Most likely to occur after a ‘drive inoperable error’.
8 End of file : An attempt has been made to read beyond the end of a
sequential access file.
F Invalid file name : This may occur if a SAVE command uses a file name longer
than 10 characters. For all commands except ERASE, a “^” in
the filename will produce this error.
H STOP in INPUT : You have used INPUT with a seq. file which contains non-
printable characters. Use INKEY$ for this type of file.
J Invalid I/O device : This will occur if you attempt to write to a file open for reading
and vice-versa. If the error occurs when you read AND write to
a particular channel it means an error occured when it was
OPENed and it should be CLOSEd before proceeding.
O Invalid stream : The stream has not been OPENed. If this occurs for #4 you must
reboot the system or use RANDOMISE USR 58500.
S Drive inoperable : You have specified a drive number not used by your system, the
door is open, the disc is inserted incorrectly or the drive is
faulty.
T Disc data lost : A DOS error has occured. Try repeating the command after a
CAT. If this fails the disc may be faulty.
V Record not found : This normally means the filename used in your command does
not correspond with any on the disc. Check the spelling against a
CAT. Note that keywords or special characters should be used
consistently. If the error persists then suspect the disc.
W Write protected : You have attempted to write to a disc that has a write protect tab
on it. This will also occur if you attempt to OPEN a file that
does not exist on a write-protected disc. Channel must be closed
to remove the error condition.
X Disc faulty : The system has failed to write or read to the disc after 50
attempts. Retry the command and then suspect the disc.
Y Illegal command : You have attempted to use commands not supported by the
system and not saved as an executive file.
Z Copyright message
a Wrong filetype : Occurs when attempting to load a file with the wrong
specification. This error will also occur if you attempt to OPEN
a file not produced as a sequential file.
b Undefined error : You have used an undefined command or routine in the DOS.
c Directory full : 144 entries have been used in the directory for this disc. There
may be fewer than 144 files as extra entries are used for
sequential files larger than 48K and for all files if the disc is
becoming full. The problem may be solved by doing a complete
copy of the disc which will ensure efficient use of the directory
entries.
d Disc full : All space on the disc has been used. The last save operation will
have been terminated and the file should be saved to another
disc. If this occurs with a sequential write file a CLOSE will not
work in the normal way and some data may be lost.
e Filename in use : For the MOVE command this warns that a file of this name
exists and should be ERASEd before the command is retried.
f Protected file : An attempt has been made to MOVE a protected file.
g Stream already open : The stream is already OPEN for a DOS file and should be
CLOSEd before an attempt is made to OPEN it again.
h File open for writing : A file by the same name is already OPENed for writing to the
same drive. You may only have a file OPENed to several
channels if it already exists and is therefore OPENed for
reading.
i Verification failed : Try reformatting the disc. If this error is repeated the disc should
be replaced as it is probably faulty.
All commands with the exception of INPUT #, PRINT #, and INKEY$ # are preceded by :
PRINT#4 :
NOTES