Sharp logo
Locating files on CP/M disks 
written by Maurice Hawes / SUC/UK
Source: SUC-magazine March 1992, Volume 12 Number 1, p. 64 - 65 

INTRODUCTION


As I was testing the versions of DISCMOD.COM which are described on the previous page, I found a simple solution to a problem which has niggled me for many years; namely, how to locate the start of a file on a CP/M disk, as track / sector, when all you know from its "directory" entry is that it starts on a 2K block, number "XXH".

Up to a few weeks ago, my only guide was the DISCMOD Manual, which states that:

the blocks on track n are numbered from 5n - 5 to 5n - 1

Until recently I used this to deduce the location of any block; but it is a backwards process and I have never been able to commit it to memory. Furthermore, it only applies to the disk format used for CP/M 2.2 on the Sharp MZ-80B / A / 700.

I have found that there is a different and more useful way of expressing the same rule. For the MZ-80B / A / 700 CP/M format:

block start ( tr, sec ) = 1 + ( block number / 5 )

In this expression, the constants "1" and "5" refer to physical facts."1" in the start location of BLOCK 0 ( i.e. the start of the directory ), and "5" represents the number of 2K blocks per track.

For any CP/M system, this generalises to:

block start ( tr, sec) = DIR start + ( block no. / blocks per track )

or in symbols

t = D + b / B

In the above, "b" must be DECIMAL. The whole number part of "t" gives the track on which block "b" is situated, and the remainder from b / B, multiplied by 16 ( because there are 16 sectors per block in CP/M ) gives the sector number of the start of the block.

It is easier to see how this works if you use real examples. All the examples below were checked on my own disks.

MZ-80B / A / 700 CP/M 2.2


The directory starts on TRACK 1, and there are 5 x 2K blocks on each of 35 tracks. Thus t = 1 + b / 5, and block 16H ( 22D ) is on:

t = 1 + 22 / 5
  = 1 + 4 remainder 2
= track 5 sector 32

MZ-3500 CP/M 2.2


The directory starts on TRACK 3 and there are 4 x 2K blocks on each of 40 tracks. Thus t = 3 + b / 4, and block 7BH ( 123D ) is on:

t = 3 + 123 / 4
= 3 + 30 remainder 3
= track 33 sector 48

MZ-800 PCP/M


The directory starts on TRACK 1 and there are 2 x 2K blocks on each of 80 tracks. Thus t = 1 + b / 2, and block 4AH ( 74D ) is on:

t = 1 + 74 / 2
= 1 + 37 remainder 0
= track 38 sector 0

( MZ-800 PCP/M behaves as if there are 80 tracks on a disk. The tracks on side 0 are 0 - 39, and the tracks on side 1 are 40 - 79 ).

MZ-5600 CP/M-86


The directory starts on TRACK 2, and there are 4 x 2K blocks on each of the 80 tracks. Block numbers can go above 255, so 2 bytes are allocated for each block number. In this case, t = 2 + b / 4, and block 00ACH ( 172 decimal ) is found on:

t = 2 + 172 / 4
= 2 + 43 remainder 0
= track 45 sector 0

HOW TO ASCERTAIN BLOCK NUMBERS FOR A GIVEN FILE


A typical CP/-M 2.2 directory entry, as displayed by DISCMOD, appears as shown below:

00 44 44 54 20 20 20 20 20 43 4F 4D 00 00 00 26 .DDT     COM...&
1D 1E 1F 00 00 00 00 00 00 00 00 00 00 00 00 00 ................

The "blocks" occupied by DDT.COM are on the second row, in this case, blocks 1DH 1EH 1FH, forming a consecutive 6K. CP/M saves a file in this way if it can but, if a disk is nearly full, blocks may be non-consecutive. A directory entry can accommodate 16 block numbers, so files larger than 32K require more than one entry.

In CP/M-86, on the MZ-5600, each directory entry can accommodate only eight 2-byte block numbers; so in this system, files larger than 16K require more than one directory entry. A typical CP/M-86 directory entry, as displayed by PATCH.CMD, appears as:

00 44 44 54 38 36 00 00 00 43 4D 44 01 00 00 6D .DDT86   CMD   m
33 00 34 00 35 00 36 00 37 00 38 00 39 00 00 00 3.4.5.6.7.8.9...

i.e. DDT86.CMD occupies blocks 0033H to 0039H inclusive ( 14K ).

CONCLUSIONS


The formula was checked on several different Sharp machines and on an Epson QX-10, by looking for the starts of well-known files; and it produced the correct answer first time, every time.

In general, the location of block number b ( decimal ) is:

t = D + b / B [ D = DIR ( block 00 ) location, B = blocks / track ]

The whole number part of "t" gives the track location, and the remainder, multiplied by 16, gives the sector location. This very simple formula makes CP/M disk-editing a "piece of cake". ***


Go to the top of this page Home

last updated August 30, 2002
SUC / UK: John Edwards and Maurice Hawes

khmweb barrierefreies webdesign Berchtesgaden