12

The only functions of INT 13h available for pre-XT systems are the first six, from AH=00 to AH=05 (see here and here)

Since function AH=08 (Get current drive parameters) is unavailable, how does PC-DOS/MS-DOS detect the number and type (e.g. 180 kB or 360 kB) of floppy drives on a pre-XT machine?

I am particularly interested in the original IBM PC 5150, but the question extends to all pre-XT systems.

I am not referring to the "DIP switches vs. ROM BIOS" issue. Somehow (switches? cmos RAM? irrelevant) the machine can and does provide this information to the operating system. Nor am I referring to INT 21h or any other OS-provided functionality to retrieve this information.

Edit: The question extends to size of sectors, since this is provided by Diskette Parameter Table of aforementioned function (ES:DI, 4th byte)

2 Answers 2

12

TL;DR: It looks at the disk mounted

PC-DOS simply looks at the media present and acts accordingly. At least since 1.1/2.0. PC-DOS 1.0 only assumed.


Details

The only functions of int 13h available for pre-XT systems are the six (6) first ones, from AH=00 to AH=05 ( source , source )

Don't forget the Disk Base stored in Int 1Eh (0:78h) which for an original 1981 BIOS is located at F000:EFC7h and reads:

enter image description here

(1981 Technical Reference p.A-41)

Here DOS can gather sector size and sectors per track.

Note, there is no marker for single or double sided or how many tracks there are. It doesn't need too, BIOS doesn't care.

BIOS works on a Need-to-Know base. The table contains everything it needs to operate a drive (timings) and to execute a format instruction for a track (gaps, sector length). Everything else is of no concern as it will be given as parameters for each call. If a user tries to position to a non-existent track or sector, some error will occur when doing so. No need to check prior.

Since AH=08 function (Get current drive parameters) function is unavailable,

Well, it is for hard drives :))

how does PC-DOS / MS-DOS detect the number and type (e.g. 180 vs 360 kb) of floppy drives on a pre-XT machine?

It doesn't care. At least not for drives. What it cares for is the media logged in (mounted).

  • PC-DOS 1.0 doesn't do anything but simply assumes a value of 40 tracks and 1 head. (*1)

  • PC-DOS 1.1 added support for a second head (*1,2). To detect DS disks DOS recognizes a changed sector-per-track value at offset 3 of the boot sector.

  • PC-DOS 2.0 and later looks at the BIOS Parameter Block at offset 0Bh within the boot sector when logging in a disk and picks the Media Descriptor (BPB+0Ah) which marks the disks structure:

    • 0xFF -> 5.25 DS, 40 T, 8 S/T, 320 KiB (DOS 1.x)
    • 0xFE -> 5.25 SS, 40 T, 8 S/T, 160 KiB (DOS 1.x)
    • 0xFD -> 5.25 DS, 40 T, 9 S/T, 360 KiB (DOS 2.0)
    • 0xFC -> 5.25 SS, 40 T, 9 S/T, 180 KiB (DOS 2.0)
  • PC-DOS 3.0 extended the BPB to directly include values for

    • Heads and
    • Sectors per track

That way DOS learns all it wants to know about the format of the disk. There is no need to know what a drive can do or not.

So a simple straight way ... well, mostly.


I can already hear the big ...

...BUT HOW...

... can it work without knowing ahead of time what a drive can do?

Well, it doesn't. Much like BIOS it works on a Need-to-Know base. It doesn't care for stuff it isn't asked to do. In normal operation it will only work with media already initialized (formatted). Such media will always have the mentioned markings which DOS uses to access it. If the media doesn't fit the hardware it will either not mount, thus not being usable in the first place, or soon return error - like accessing the second side in a single sided drive.

The only time DOS needs to learn about a format different than what it gathered from logging in a disk is when it's called to format a new media. And lucky DOS, Format will hand those values down according to its parameters :)) (*3)

DOS is written with a lot of freedom for errors included I know, hard to believe for today's pampered idea of an OS checking everything ahead of time instead of running into errors from time to time when the user requests impossible stuff.

That way is in fact the best to guarantee upward expansion. Use of 9 sector disks in drives where the ROM's Disk Base tells to use 8: the Boot sector simply replaces the INT 1Eh with a modified structure allowing 9 sectors (*4)


*1 - Fun fact, despite DOS 1.0/1.1 Disks being plain FAT12 disks, many tools, including various Windows versions do not recognize them as they neither carry a BPB nor the boot signature of AA55h at 1FEh

*2 - MS-DOS 1.24/1.25 is the same as PC-DOS 1.1 regarding disk operation.

*3- For those no longer remembering how Format gets them: It's in the command line. With dual sided drives (and PC-DOS 1.1) Format got /1 added. When PC-DOS 2.0 introduced 9 sector per track, Format was given /8 to still create 8 sector per track disks (*5). With both, the well known 4 formats could be commanded:

  • FORMAT /1 /8 for 160 KiB,
  • FORMAT /8 for 320 KiB or
  • FORMAT /1 for 180 KiB

FORMAT alone will give 360 KiB. Works that way since DOS 2.0 - although later DOS versions added a lot more variation and implied/assumed formats. If the drive is not capable to follow, Format simply returns what the BIOS init call (INT 13h/05h) returns to let the user know about. As mentioned, no need to check ahead of time. It was a better time, wasn't it?

*4 - Works quite fine due the fact that reading the first sector is always the first :)) Also, it's not checked against anyway. That value is just for formatting.

*5 - Later, with PC-DOS 3.0 this was accompanied by /4 to allow 40 track disks being formatted on 80 track drives - but that's a different story :)

2
  • So how does the FORMAT command figure out what disk is in the drive then?
    – Joshua
    Aug 20, 2023 at 18:44
  • @Joshua as mentioned, it doesn't figure anything, it simply formats as told. Like FORMAT /1 /8 for 160 KiB, FORMAT a: /8 for 320 KiB or just FORMAT for 360 KiB. Works that way since DOS 2.0. If the drive is not capable to follow, INT 13h/05h will return an error to let format (ant the user) know. As mentioned, no need to check ahead of time. It was a better time, wasn't it?
    – Raffzahn
    Aug 20, 2023 at 19:26
7

The 5150 hardware originally came with a diskette adapter that supported one or two soft-sectored single-sided double-density drives with 40 tracks, using NEC 765 FDC, in MFM mode, meaning a single data transfer rate of 250 kilobits per second. Actually the wire to select the head is connected to floppy drives so the adapter does support two-sided drives but originally came with single-sided drives. Basically the hardware properties regarding the controller and drive type are fixed regarding their capabilities, except for the single or double sided. The logical format differences are handled in software.

The amount of drives is set by DIP switches, it is read by BIOS and stored into equipment flags that can be read from BIOS Data Area or via calling INT 11h to fetch it.

By default the BIOS sets the Disk Parameter Table (INT 1Eh pointer) for eight 512-byte sectors per track which is 160 kilobytes formatted. There is not even information about how many heads or tracks the drive has.

This table can be read by reading from the area pointed by INT 1Eh, or it can be changed by setting up your own table and changing the INT 1Eh dword pointer to point there.

The BIOS diskette formatting functions need the user to define the track format, i.e. an OS can change the sector size and layout to have any amount of 128, 256, 512, or 1024 bytes per sector as can be safely fitted on the track.

When reading or writing tracks via BIOS, the functions take the expected sector size and expected sectors per track from the Drive Parameter Table.

DOS simply used the defaults of the BIOS, and thus DOS 1.00 supported only 160KB SSDD floppies, with 8 sectors of 512 bytes per track. Having 40 tracks on a drive was also an implicit assumption.

The clever part of this is that as long as BIOS can use the defaults and read in the first floppy sector for booting, the first sector can contain information about the floppy format and set the Disk Parameter Table to point to data read from floppy disk in the boot sector code.

DOS 1.0 floppy boot sector data and code can just assume and hardcode the values of 512 bytes per sector and 1 head when reading OS files to memory.

DOS 1.1 added support for DSDD 320KB drives so Boot Record data and code in the first floppy sector must be aware about floppies being formatted with 1 or 2 heads, so that the boot code that loads OS must be aware that when reading OS files also the head number might need updating after reading a whole track of 8 sectors.

DOS 2.0 added support for 180KB and 360KB formats so in addition to just heads, the floppy boot sector must contain data about that it has 9 sectors per track and must edit the BIOS Disk Parameter Table by changing the sectors per track value to 9. I could not find a disassembly of this but I presume it must be very similar to how DOS 5 or 6.22 floppy boot code does it - it copies the BIOS DPT over part of the already executed code and edits the sectors per track number and sets INT 1Eh to point to this updated DPT.

So the giveaway from this is that floppy types are not detected, the floppy contains information about its type and format in the first sector that is readable, and the BIOS DPT is updated by DOS or floppy boot code to set the sectors per track correctly for the floppy controller, and also DOS or floppy boot code can handle the number of heads and sectors per track the floppy has, which of course allows using a single-sided floppy on a dual-sided drive.

Also the type of floppy drive itself (single or double sided, 40 or 80 tracks, double/quad/high/extended density, 5.25" or 3.5") is not and cannot be autodetected. Later machines with support for different drive types always required the user to set the actual drive type somehow, unless the hardware can assume the drive type being fixed and unchangeable by user.

3
  • Bytes per sector is part of the Disk Base but yeah, DOS does simply read ahead - which in turn allows booting from drives with other structure than 512 bytes.
    – Raffzahn
    Aug 19, 2023 at 22:09
  • @Raffzahn To be honest, I don't know if the first sector can be anything else than 512 bytes, as it might be an error as assumed sector size is 512 bytes during IPL. It will likely be an error if FDC is set to expect 512 byte sector and there is another size sector on disk. On the other hand, since the IPL loads the sector to 1KB below 32K, it leaves room for 1KB sectors, but on the other hand, DOS floppy boot sector never overrides the default sector size in Disk Base Table, just sectors per track.
    – Justme
    Aug 19, 2023 at 22:16
  • That's only true for PC-DOS - as PC-DOS was not intended to boot from anything other than 512 Byte sectors. OEM MS-DOS versions had ofc. boot sectors fitting their hardware. It's easy to forget that DOS wasn't an IBM-hardware only OS. At least not until about DOS 4
    – Raffzahn
    Aug 19, 2023 at 22:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .