Disks in detail
written by Tim Cowell / SUC/UK
Source: SUC-magazine December 1986, Volume 6, Number 2, pp. 44 - 48
|
|
Sharp Users Club - MZ-700 Section - Disks in detail
|
|
I would first like to give my greatest thanks to Ching Rashbrooke for
supplying me with the Rom disassembly and boot disk, also to Danny Abondanza
for his assistance with Disk Basic.
My objective was to get a disk system for my MZ700 without spending
the vast amounts of money usually required for such nice things. I wanted
my disk system to be compatible with existing disk systems but to also
provide a more comprehensive operating environment.
|
|
The Hardware
|
|
From the Z80's point of view my hardware had to appear identical to
the original hardware, this being the Kersten & Partner disk system
from Germany. First I went through the disassembly of the Boot Rom and
flowcharted it, this told me what IO addresses the system used, and
how to write to each.
| Port No. |
Dir |
Use |
| D8 |
Read |
Disk Controller Status |
| D8 |
Write |
Disk Controller Command |
| D9 |
Write |
Disk Controller Track Register |
| DA |
Write |
Disk Controller Sector Register |
| DB |
Read / Write |
Disk Controller data |
| DC |
Write |
Drive select & Motor on control |
| DD |
Write |
Side select |
|
|
The Software
|
|
The firmware uses memory starting at 1000H, these bytes and their uses
are :-
| Address. |
No. Bytes |
Use |
|
1000
|
1
|
Latest FDC command byte |
|
1001
|
1
|
Motor on flag, 01 = on, 00 = off |
|
1002
|
4
|
Track 0 flags for each drive ( 1 to 4 ) |
|
1006
|
1
|
Retry count |
|
1007
|
1
|
Not sure of this one? |
|
1008
|
1
|
Drive Number ( 0 to 3 ) |
|
1009
|
2
|
Logical Sector Number ( 0 to 1119 ) |
|
100B
|
1
|
Bytes to read |
|
100C
|
1
|
Number of sectors to read |
|
100D
|
2
|
Memory Load address |
|
100F
|
1
|
Current track No. ( 0 to 69 ) |
|
1010
|
1
|
Current Sector No. ( 1 to 16 ) |
|
1011
|
1
|
Start track No. ( 0 to 69 ) |
|
1012
|
1
|
Start Sector No. ( 1 to 16 ) |
The interesting thing to note is that all disk accesses are done by
reference to the logical sector numbers. Each disk is double sided,
35 tracks per side and 16 sectors per track. To convert a logical sector
into physical side, track & sector the following calculation should
be done :-
Side = ( Logical DIV 16 ) MOD 2
|
( i.e. 0 or 1 ) |
| Track = ( Logical DIV 32 ) |
( i.e. 0 to 34 ) |
| Sect = 1 + ( Logical MOD 16 ) |
( i.e. 1 to 16 ) |
In practice however the software assumes it is a 70 track drive and
automatically splits the track number ( 0 to 69 ) into track and side
when accessing the disks.
The bootstrap ROM lives at F000H, when you type 'F' from the monitor,
the processor looks at F000 and if it sees a ROM there then jumps to
F000. This displays a prompt asking for the boot drive, press 1 to 4
or simply [CR] to default to 1. The system then reads in logical sector
0 to memory at CE00 ( 256 bytes ). If it is a boot disk this sector
will contain a header with a file name beginning with IPLPRO",
a new memory load address, the size of the file and the start sector
on disk. This is then loaded and run, the disk I had was the Disk Basic
disk.
All the routines in the ROM get their parameters from memory pointed
to by the IX register, this is usually set to 1008H. It is possible
to use these ROM routines yourself by setting up a parameter block and
calling them, however I am not sure that all versions of the boot ROMs
contain the same code. To read sectors from disk into memory the following
technique was used,
| Set 1008 to the Drive Number ( 0 to 3 ) |
| Set 1009 to the logical sector number ( 0 to 1119 ) |
| Set 100B to 00 |
| Set 100C to the number of sectors to read |
| Set 100D to the memory address to load into |
| Set IX to 1008 |
| Call F1BA - This reads the sector/s |
| Call F151 - This deselects the drives |
Using the above technique I was able to write a small MC program to
read disks sector by sector and display their contents in Hex and ASCII
form. The following are printer dumps of the results :-

First Sector of Boot Disk. File = MZ700D-BASIC, Size = 8800H, Load =
1200H, Exec = 9229H,
Sector 0030H. N.B. 02 = Boot Disk ( 03 if 1E05 is used ).

Analysis of the above for various disks enabled me to determine how
the system uses various sectors.
Sector 0 = Boot information sector.
Sector 15 = Sector Allocation information.
Sectors 16 to 23 = Directory information.
|
|
Sector 15
|
|
Byte 0 indicates the volume number, 0 is a master, any other is a slave.
A master contains the bootstrap program. Byte 1 is the first usable
sector on the disk, for a non master this is 30H or for a master is
B8H. Bytes 2 / 3 point to the next sector to be used for writing a file.
Bytes 4 / 5 indicate the total number of sectors on the disk, this is
0460H which is 1120 decimal. Next follows a sector allocation map, this
is a bit map of which sectors are used, a bit set indicates the sector
is used, a bit reset means the sector is available. The last few bytes
are I think a serial identification number.
|
|
Sectors 16 to 23
|
|
A maximum 0f 64 files can be held on disk, only 63 are usable as the
first directory entry is reserved by the system. Each directory entry
takes 32 bytes, i.e. 64 files * 32 bytes = 8 sectors * 256 bytes. Each
of the 32 byte blocks contains the following Information :-
| Byte offset |
No. Bytes |
Use |
|
0
|
1
|
Attribute |
00 = Deleted ( unused entry ) |
| 01 = Machine Code |
| 02 = Bootstrap |
| 03 = Basic Data File |
| 05 = Basic Program |
|
1
|
17
|
File name as in tape system |
|
18
|
2
|
Not sure, always 00 ????? |
|
20
|
2
|
File size in bytes |
|
22
|
2
|
File load address |
|
24
|
2
|
File execute address |
|
30
|
2
|
Start logical sector number |
|
|
Sectors 0
|
|
This contains one directory entry in the above format. This is the program
that gets run as a bootstrap, however this does not get included in
the directory listing.
|
|
The Kersten & Partner System
|
|
The K & P system has the strange convention of Master and Sub-Master
disks, a Master disk being the original supplied disk and a sub-master
being one copied from a Master. The disk contains a utility allowing
disks to be copied, however you cannot copy from a Sub-Master disk,
presumably to prevent people like me using the system without buying
the Hardware. However if your Master disk gets damaged you are stuck
with however many sub-masters you managed to create. The way round this
is simple, the disk copy routine contains a bit of code that checks
whether you are copying a Master, if so it crashes out with a rude message.
1) Load the utility in the usual way and press the reset button.
2) Using the monitor 'M' command enter the following :-
13B9 20 18 [CR] ( You enter the 18 and CR ) 13BA 23 ( Press Shift / Break to exit M command ) J1200 [CR]
The disk copy option will now copy anything.
There is also what I consider to be a bug in the Disk Basic. There
is a utility which allows machine code programs to be loaded from tape
and saved to disk, these can then be executed from disk basic. However
certain programs refused to run properly, on investigation I found it
was programs using any of the monitor melody routines including the
beep. In fact it was because Disk Basic changes the TEMPO byte at 119E,
this causes all sound routines to take much longer to execute. A simple
solution is to modify disk basic as soon as it loads by including the
following two lines as part of your AUTO RUN program.
1 RESTORE : FOR I = 0 TO 4 : READ D : POKE $7AB3 + I, D : NEXT
2 DATA $3E, $04, $32, $9E, $11
This simply causes the original value of 04 to be restored before the
interpreter jumps off to execute a loaded machine code program.
|
|
What Next
|
|
I have written assembler routines to perform the following :-
Sector Read
|
- Reads sectors into memory |
Sector Write
|
- Writes sectors from memory |
Directory
|
- Displays all files, names, attributes and load / size / exec
addresses |
Write Info
|
- Makes a directory entry |
| Write Data |
- Saves memory to a file |
Read Info
|
- Reads a directory entry |
| Read Data |
- Loads memory from a file |
My intention is to use these to produce a BIOS / BDOS for a simple
operating system which is to be tape compatible. The directory read
/ write and file load / save routines are compatible with the inbuilt
tape system. Each time a header is loaded the software effectively reads
the 'Next' directory entry into the tape header area of memory. The
disk is therefore treated as a tape with many files, except access is
direct as the directory points to the location of the files on disk.
Any help or constructive comment concerning a simple DOS would be most
welcome, also I am considering making a PCB of the controller interface,
if anyone has a PCB design package or access to one and feels they could
have a go then write to me and I will supply the circuit diagram.
|
|
Editor's comment:-
|
|
The Kersten and Partners system of Masters and Sub-masters sounds very
similar to the system used by Sharp with their MZ-80K / A / B disc interpreters.
In recent issues we have shown how to create Masters on the MZ-80B and
the MZ-80A, and in this issue, thanks to John Edwards ( see p. 35 )
we reveal how it may be done on the MZ-80K. Now, thanks to Tim Cowell,
we also see how to create a Master of MZ-700 Disc Basic.
|