Search code examples
assemblyx86-16biososdev

Writing disk sector, numbers of sectors to write question


I'm trying to create my own very basic OS and I'm trying to figure out how writing and reading for a disk works. I'm using this website as a reference.

Why does AL goes up to 128 if the number of sectors per track is 17? If I set AL to 20, CL to 1 and write a (512 * 19) bytes string, since sector 18 and 19 don't exist, where would the last 1024 bytes go?


Solution

  • If you ask to write "N sectors starting with the sector at {cylinder, head, sector}" and the number of sectors you've asked to write is on a different track; then:

    • for some devices on some computers; the BIOS supports "multi-track" and will automatically switch to the next track when you reach the end of the previous track

    • for some device on some computers; the BIOS does not supports "multi-track" and will return an error when you reach the end of the previous track

    Note that other (potentially better) references for that BIOS function (e.g. http://www.ctyme.com/intr/rb-0608.htm ) say nothing about the 128 sector limit; and it's likely that (in some cases) you might be able to write 255 sectors.

    Also note that for floppy disks sometimes (especially for less common media formats - e.g. the "1680 KiB" format) the BIOS has no idea how many sectors there are on a track (it just shoves commands to the floppy controller and reports any errors returned by the floppy controller) and therefore can't support multi-track. For these cases, I vaguely remember some kind of "drive parameters table" in the BIOS Data Area somewhere that software (e.g. ancient MS-DOS) tampered with to correct the information the BIOS uses (using values from the "BPB" structure on the floppy disk).

    There is also no notification/indication/safeguard for disk changes. This means that if the user ejects the floppy disk and puts a different floppy disk in the drive, you won't know, and your software will trash the wrong floppy disk without knowing.

    Finally (due to max. size limits) for hard drives, in the 1990s the old functions became deprecated and were superseded by a newer set of disk IO functions (that use 64-bit LBA addresses and don't use CHS addressing) called "int 0x13 extensions". This didn't happen for floppy disks; so you'll end up needing different code (that uses different functions) for different types of devices.

    Of course the BIOS was never really a formal standard (more like a collection of random manufacturers trying to emulate each other); and now both floppy disks and BIOS are dead (replaced by CDs and USB flash, and replaced by UEFI); so all the "retro computing horror" can be (and has been by many) forgotten; making it hard to find any up-to-date information (e.g. lists of "BIOS bugs" effecting various computers) now.