48k Spectrum
Technical Information
Microdrives And Interface 1
 
  • The Interface 1 provides the hardware/software for a RS232 serial interface and a LAN.

  • The Microdrive is a continuous loop based tape providing data storage. They are basically a faster tape with the facility to duplex data (i.e. read one file while writing to another).

  • The software extensions to the Interface 1 allows the creation of 'proper' data files. It seems better to talk about the software first, so what better way…

Software

The Interface 1 contains an 8K of additional ROM and contains extended tape commands, Microdrive specific commands, extended channel commands and other non-specific commands.
When referencing a file on a Microdrive a device, device number and file name must be specified, in the format:
device;number;name.

Device is a string identifying the type of device that the file is on (e.g. "m" for Microdrive), device number specifies which device (in case more are connected).

Extensions to the tape commands are as follows: LOAD*, MERGE*, SAVE*, VERIFY*
They work in a similar way to tapes except the full drive specification is required, e.g. LOAD* "m";1;"program"

New commands for the Microdrive are as follows:
CAT drive - produces a list of the files on 'drive', e.g. CAT 1
ERASE detail - erases a file, in the standard format, e.g. ERASE "m";1;"program"
FORMAT detail - erases all files on a cartridge, e.g. FORMAT "m";1;"label"
MOVE f1 TO f2 - Only works with files not created with SAVE. This copies files, e.g. MOVE "m";1;"file1" TO "m";2;"file1".
Extended channel and stream commands basically extend the OPEN#, INPUT# and other #commands using the standard Microdrive format, e.g.

OPEN #5,"m",1,"file"

Data is not written immediately to the Microdrive. It is buffered to an area occupying 512 bytes.

The built-in streams can be used with the Microdrive. MOVE "m";1;"file" TO #2 will display the file to the screen; MOVE #1 TO #3 will move the keyboard to the printer.

Other non-specific commands include CLEAR# and CLS#. CLEAR# will resets the streams and channels and CLS# will clear the screen and reset the screen to black on white. Thus, when using a Microdrive it is good practice to do a CLS# | CLEAR#

To determine the end of a file store CHR$(0) as the last byte to be written.

Hardware

With a 48K Spectrum using 64K of address space (16K lower RAM, 32K upper RAM, 16K ROM) there is the problem of how another 8K of Interface 1 ROM be used. The answer is by paging - the sharing of memory. At any one time, either the 16K BASIC ROM is present or the 8K Interface 1 ROM is present. The ROM disable line on the edge connector, when set to +5V, stops the 16K ROM responding to any address - allowing another ROM to take its place.


This implies that the Spectrum is continuously swapping BASIC with the Interface 1 ROM. This is achieved by RST 8. This command is signalled by the Spectrum when an unexpected command is invoked and calls the error handler in the BASIC ROM. The Interface 1 monitors the address bus for the occurrence of address 8 and swaps the ROM.

Interface 1 will also page in the new ROM if address 5896 is used. This corresponds to the BASIC CLOSE command and has to be intercepted before a CLOSE is attempted. The 16K ROM is paged back by using address 1792.

Data Format

Data is written and read on two tracks. Data is stored on the Microdrive in blocks of fixed size (sectors). Each sector has a header block and a data block. The format of the header is:
Lead * 12|flag *1|sector no *1|unused * 2|name * 10| check * 1
This is similar to the tape header format. Each sector is given a unique number in the range 0 to 255. The data block has two parts: the descriptor and the record. The descriptor is the same format as the header. The record is in the following format: data * 512|check *1

The header block is never re-written so cannot be used to determine whether a sector is free. Due to timing problems, the Microdrive can only rewrite an entire block. The Sinclair solution is a Microdrive Map. Consisting of 32 bytes, each of the theoretical 256 sector numbers is stored as a bit. If the bit is 1 the sector is being used or does not exist.

Microdrive Channel

Referring back to the section on channels/streams it can be seen that all that is necessary to extend the system to include files held on Microdrive is the introduction of a new type of channel record (and to extend the software that handles streams and channels, for which the new 8K ROM takes cares of). A Microdrive channel record has the following format:

0 0008 error routines address
2 0008 error routines address
4 M channel identifier
5 address of output routine
7 address of input routine
9 595 length of channel descriptor
11 CHBYTE next byte in record
13 CHREC current record number
14 CHNAME 10 byte file name
24 CHFLAG flag bO=0 open for read
25 CHDRIV drive number
26 CHMAP address of microdrive map
28 12 bytes of lead-in signal
40 HDFLAG header flag bO set to 1
41 HDNUM sector number
42 not used
44 HDNAME cartridge name
54 HDCHK header check sum
55 12 bytes of lead-in signal
67 REMG record flag bO set to 0
68 RECNUM record number
69 RECLEN number of bytes in record
71 RECNAM 10 byte file name
81 DESCHK record descriptor check sum
82 CHDATA 512 byte data buffer
594 DCHK data checksum
Bytes 0 to 27 for general channel information; bytes 28 to 54 form a sector header; bytes 55 to 594 for a data block. Byte 9 holds the length of the entire channel descriptor record to allow searching. Byte 67 shows whether the block under the read/write head is a data ( if bit 0 is 0) block, the last record read is the last record in the file (bit 1 is 1), and if the file was created by a SAVE command (bit 2 is 1).

System

The following new system variables are created with the new ROM (that are worth noting):
IOBORD At 23750 sets the border colour during I/O


COPIES At 23791 sets the number of copies made when SAVE* is used.
The following routines can be called when using the Microdrive, in conjunction with the following assembly:
RST 8
DEFB code

The RST 8 signals an error and the 'code' is the routine required to call. This works because only a small number of errors are required when using the Microdrive.

33 Switch motor on (A register holds which Microdrive, 0 to turn all off)
34 OPEN
35 CLOSE
36 ERASE
37 Read next record of a PRINT file
38 As 37 for WRITE
39 Read a given record of a PRINT file
40 Read a PRINT file sector, specified by CHREC
41 Read next sector on tape
42 Write a sector, specified by CHREC.

When calling the routines, note that none of the registers are saved and the state of the maskable interrupt is not predictable. Therefore, save the HL register and disable the interrupts.

RS232

RS232 is a standard for serial interfaces that specifies many things. However it is not a rigid standard in that a RS232 cable can be made using 3 wires (signal to, signal from, earth). The Spectrum uses 5 wires to allow handshaking. The pin-outs for a cable are:
Pin 2 TX (input data to Spectrum)
Pin 3 RX (output data from Spectrum)
Pin 4 DTR (ready signal to Spectrum)
Pin 5 CTS (ready signal from Spectrum)
Pin 7 Ground
Pin 9 +9 Volts

Take into account the cross-over of the hand-shaking pints when connecting equipment (pins 4/5).

When using the RS232, the channels "t" and "b" can be used. "t" refers to printable ASCII characters (i.e. not 0 to 31 and 12 to 164) while the "b" channel will print everything.

The Spectrum data format is 8 data bits, no parity check, 2 stop bits with a default of 9600 baud. The baud rate is set via the BASIC FORMAT command, e.g. FORMAT "b";baud.

The following routines can be called when using the RS232, in conjunction with the following assembly:
RST 8
DEFB code

The RST 8 signals an error and the 'code' is the routine required to call. This works because only a small number of errors are required when using the RS232.

27 Read keyboard, store in A
28 Write A to screen
29 Read byte from RS232, set carry if read ok
30 Write A to RS232
31 Write A register to ZX Printer
32 Test keyboard. Set carry if key pressed

When calling the routines, note that none of the registers are saved and the state of the maskable interrupt is not predictable. Therefore, save the HL register and disable the interrupts.

Networking

Remember the days in the office, when we were all connected to the Sinclair network? No. Neither can I.
Basically having a Spectrum network over RS232 using 2 wires uses a system of time-sharing between the computers or by taking control of the network.

The network channel is identified by "n", so FORMAT "n";statnum will set the station to be statnum, where statnum is between 1 and 63.

When statnum is set as 0, the transfer of data to multiple stations is made possible.

The network introduces another channel record descriptor to ZX BASIC and is as follows:


0 address 8 the error handler
2 address 8 the error handler
4 "N" the channel identifier
5 address of output routine
7 address of input routine
9 276 length of the channel descriptor the header block
11 NCIRIS the destination station number
12 NCSELF the station number at the time the channel was OPENed
13 WNUM data block number
15 NCTYPE type of data block (0=data I=EOF)
16 NCOBL number of data bytes in block
17 NC13CS data checksum
18 NCHCS the header checksurn general infomation
19 NCCUR the position of the last character taken from buffer
20 NCIBL the number of bytes in the input buffer data block
21 NCB 255 byte data buffer
The following routines can be called when using the network, in conjunction with the following assembly:
RST 8
DEFB code
The RST 8 signals an error and the 'code' is the routine required to call. This works because only a small number of errors are required when using the network.

45 OPEN a temporary channel (D_STR1 should contain the destination station and address 23749 the source station)
46 CLOSE a network channel. IX to contain the address of the channel record
47 READ a network record. IX as code 46
48 Write a network record. IX as code 46, A=0 writes, A=1 sets end of file record

When calling the routines, note that none of the registers are saved and the state of the maskable interrupt is not predictable. Therefore, save the HL register and disable the interrupts.

Information
CPU
Memory
Expansion Connector
Built in I/O
ULA Output
ULA Input
System Variables
ZX Basic
I/O Streams
Video Display
Tape, Sound, Printer
Interface 1
 
 
 
 
©2002 ZeDeX82