Scor­pio News

  

October–December 1987 – Volume 1. Issue 4.

Page 20 of 55

four CP/M records. We can number these physical sectors from 0 to 7 and the CP/M records within them from 0 to 3.

If we shift the record number (11) right PSH (2) times we get the value 2. It is a simple matter to read the third physical sector into the deblocking buffer ready to extract the required 128 byte record.

Finally, by ANDing the record number (11) with PHM (3) we get the value 3. Consequently, the required record occupies the last 128 bytes in the physical sector, i.e. the fourth record in the sector.

Blocking and Deblocking

Isolating separate 128 byte CP/M records in a physical sector is central to the concept involved with blocking and deblocking. All versions of CP/M transfer data to and from the disk in 128 byte chunks (including CP/M 3). We have already seen that disks may be formatted info sectors of varying size and if sector size of 128 byes is used then no problems are experienced. However, many disk formats use sector sizes of 256, 512 and 1024 bytes. As we have seen, Gemini use a 512 byte sector size for their DDDS, QDSS and QDDS disk formats. Since CP/M requires 128 byte records, surely it is easier to format the disk in 128 byte sectors.

The answer to this is yes. It is easier to use 128 byte sectors but oddly enough it is generally faster to use larger sector sizes. Why this is will become apparent as we proceed but suffice to say that since we are using sectors that are larger thin 128 bytes, we need a method of providing CP/M with 128 bytes at a time and allowing CP/M to write 128 bytes at a time. The processes for writing and reading in this manner are known as blocking and deblocking respectively.

Blocking and deblocking are implemented in the BIOS under CP/M 2.2 and (usually) in the BDOS under CP/M 3 although facilities exist within CP/M 3 to allow the BIOS to do this. The method used requires a buffer in RAM that is one physical sector long (512 bytes for the Gemini DD and QD formats). This buffer is simply an area of RAM reserved by the BIOS for this purpose and is known as the blocking/​deblocking buffer. This buffer is located within the BIOS under CP/M 2.2 but under CP/M 3, the physical record buffers controlled by the BDOS (pointed to by the DTABCBs) are used. From now on I shall assume that CP/M 2.2 is in use and will describe the method of blocking/​deblocking in respect of the CP/M 2.2 BIOS. Under CP/M 3, the BDOS will have calculated physical sector numbers (using PSH and PHM) and the BIOS reads them directly.

When deblocking, the BIOS takes the sector number provided by the BDOS and converts it into a physical sector number. i.e the physical sector that contains the required CP/M record. This physical sector is then read into the blocking/​deblocking buffer and the wanted 128 bytes are identified and passed to CP/M by copying them to the DMA address. At the time of reading the physical sector, certain facts about it are recorded. These are the drive, track and sector number for the physical vector. At the same time a flag is set to say that the buffer in use.

The next time that a read is requested by CP/M, the logical sector number is calculated as before. This time, however, the BIOS will find that the buffer is in use. Bearing in mind that most disk reads are done sequentially, it is a fair bet that the CP/M record we want is in the buffer already. The BIOS checks the drive, track and sector numbers for the required sector against those stored for the buffered sector and if they match, the BIOS skips the disk read and simply transfers the required 128 byes to the DMA address.

When reading sequentially using deblocking, the disk is accessed only every fourth request from CP/M. As disk drives are relatively slow when compared with the time required to extract data from RAM, you can now see why this process is faster than simple disk using 128 byte sectors. Generally, the larger the physical sector size, the greater the improvement in disk access time will be.

Writing to disk using blocking offers a similar (but not as great) increase in speed. You will see why writing is not as fast as reading in a moment.

Imagine that we wish to write a random record to disk and that we are updating one record among many adjacent records. Since we have to write to the disk in terms of complete sectors, we cannot simply write 128 bytes to the disk. If we put the CP/M record in the blocking/​deblocking buffer and wrote that to disks, we would erase the other three records in the physical sector.

Page 20 of 55