VOGONS


First post, by superfury

User metadata
Rank l33t++
Rank
l33t++

I'm currently always using 16 heads and 63 sectors per track in UniPCemu, with the cylinder count being adjusted to be within range of the hard disk image, when possible, with a minimum of 1 cylinder.

Of course, this will fail with disk sizes less than 16 heads and 63 SPT.

Is there an official method to convert this?

Edit: This is what I'm currently experimenting with:

OPTINLINE word get_SPT(uint_64 disk_size)
{
return (disk_size>=63)?63:disk_size; //How many sectors use for each track? No more than 63!
}

OPTINLINE word get_heads(uint_64 disk_size)
{
return ((disk_size/get_SPT(disk_size))>=16)?16:((disk_size/get_SPT(disk_size))?(disk_size/get_SPT(disk_size)):1); //1-16 heads!
}

word get_cylinders(uint_64 disk_size)
{
uint_32 cylinders=0;
cylinders = (uint_32)(disk_size / (63 * 16)); //How many cylinders!
return (cylinders>=0x3FFF)?0x3FFF:(cylinders?cylinders:1); //Give the maximum amount of cylinders allowed!
}

So:
It will use the sectors as Sectors per Track with 1 head and cylinder up to 63 sectors large.
It will use 63 sectors per track with 1 cylinder and heads being the maximum quotient up to 1008 sectors large.
Otherwise, it will use 16 heads and 63 sectors per track with cylinders being the maximum quotient possible with 16 heads and 63 sectors per track.

Is this method of calculating the CHS geometry of an emulated harddisk correct(the hard disks can be any amount of sectors)?

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 1 of 7, by vladstamate

User metadata
Rank Oldbie
Rank
Oldbie

Do you support all those hard disk types?

http://www.win.tue.nl/~aeb/linux/hdtypes/hdtypes-3.html

YouTube channel: https://www.youtube.com/channel/UC7HbC_nq8t1S9l7qGYL0mTA
Collection: http://www.digiloguemuseum.com/index.html
Emulator: https://sites.google.com/site/capex86/
Raytracer: https://sites.google.com/site/opaqueraytracer/

Reply 2 of 7, by Jepael

User metadata
Rank Oldbie
Rank
Oldbie

Disk drives can be of any size, right? So given that an image can be calculated to be N sectors, there are multiple triplets of cyl*head*sec that makes N sector image.

Another thing is, are you talking about the hardware geometry of the drive, or, the logical geometry seen by DOS, because these can be different if BIOS does a geometry translation.

Fortunately, since most likely you are dealing with images of DOS systems, you can assume there is a partition table, and usually partitions are aligned to cylinder boundary. So from that, you can determine the last sector, last cylinder, and last head of a partition, which gives you a hint about logical geometry. Also, the first FAT partition sector contains info about head and sector counts. As these are the geometry seen by DOS, it's the logical geometry.

Just as a reminder, standard BIOS limits are:
-1:1 physical to logical mapping, max 528MB/504MiB (1024/16/63)
-BIOS maximum values give about 8455MB/8064MiB (1024/256/63)
-DOS does not like 256 heads so usually compatible BIOSes limit it to 255 heads instead, so head number 0 is first and 254 is last, so (1024/255/63) gives 8422MB/8032MiB
-IDE/ATA maximum values in the latest standard are (16383/16/63) but of course there were limits even before that, and LBA was in use before this anyway.
-There might be several different ways to translate geometry than LBA and LARGE methods.

Reply 3 of 7, by superfury

User metadata
Rank l33t++
Rank
l33t++

I'm talking about the default geometry that the hard disk IDENTIFY(PACKET DEVICE too) bytes 1,3,6(and 54,55,56 too, when a different emulated geometry is set up) return. Those two addresses are loaded with those two functions in the top post, when a new disk image is loaded to emulate. That applies to both hard disks(when starting emulation and CD-ROMs(when inserted or loaded in any other way).

The device can use geometry translation as well, using the official Initialize drive parameters(0x91) ATA-1 command to set the amount of heads and sectors per track(reflected on&updates bytes 55&56 of the identify commands(which is the currently used geometry for CHS commands). Bytes 57&58 contain the conversion of the currently used geometry to LBA, so the equivalent of the last CHS address comverted to LBA(maximum LBA using current CHS geometry).

Last edited by superfury on 2017-06-08, 20:07. Edited 1 time in total.

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 5 of 7, by superfury

User metadata
Rank l33t++
Rank
l33t++

It specifies some limits and tells when to use those limits, but nothing is said other than to minimize the amount of orphan sectors(MaxLBA>MaxCHS). So what's the best way to calculate it, based on the amount of LBA sectors(disk_size parameter) on the disk backend?

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 6 of 7, by Jepael

User metadata
Rank Oldbie
Rank
Oldbie

Well, have you analyzed the math? I mean, for any given disk size in LBA, by using those limits, and by minimizing orhpan sectors, do you always get a single possibility, or multiple possibilities?

Reply 7 of 7, by superfury

User metadata
Rank l33t++
Rank
l33t++

Well, the bigger problem might be: how to calculate the CHS to use, while adhering to those rules, without taking too much CPU time? Especially on the 512MB range, there's a huge range of possibilities to loop(CHS combinations to try).

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io