![]() 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 |
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 |
t = 1 + 22 / 5 = 1 + 4 remainder 2 |
MZ-3500 CP/M 2.2 |
t = 3 + 123 / 4 |
MZ-800 PCP/M |
t = 1 + 74 / 2 ( 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 |
t = 2 + 172 / 4 |
HOW TO ASCERTAIN BLOCK NUMBERS FOR A GIVEN FILE |
00 44 44 54 20 20 20 20 20 43 4F 4D 00 00 00 26 .DDT COM...& 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 i.e. DDT86.CMD occupies blocks 0033H to 0039H inclusive ( 14K ). |
CONCLUSIONS |
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".
*** |