Are MS-DOS hard disk image storage affected by changing the hard disk physical geometry? E.g. by improving an old algorithm to calculate CHS dimensions of a hard disk to be more efficient, would it break data stored on said disk(which is stored as a flat disk image)? Or does MS-DOS always autodetect the disk geometry on startup and adjust it's calculations for CHS values accordingly?
Just modified the geometry formula, then tested my large test games disk image(with a MS-DOS 5.0 OS and various games on it to test functionality of my emulator) by mounting it in dosbox and using it normally(though the dosbox prompt). The new geometry is 3968,16,63(C,H,S format) and inputting that (reordered to 512,S,H,C used by Dosbox) mounts it correctly in Dosbox. Even tried some games in Dosbox and they all seem to run correctly:D So it seems that MS-DOS isn't affected by changing physical geometry(CHS) of hard disk emulation(with same size of disk image)?
DOS does not care about physical geometry and does not even know it.
It cares and knows only about the geometry it sees via standard BIOS disk IO as that is what it must use to access the disk.
If for some reason the geometry is different even if exact amount of sectors is identical, then it won't work, as even the partition table contains CHS values so the MBR may not find the partition to boot from.
Geometry shown by BIOS may or may not be translated depending on the physical geometry and BIOS may not support it or have different methods for performing the translation (none, large(old), large(new), lba, ...).
Assuming that the physical geometry is even correctly detected by BIOS.
All it needs to work is the translated geometry to be identical, so that DOS sees nothing has changed, and these translations may not be identical throughout implementations and computing eras.
Would the fact that the default CHS geometry that's reported in UniPCemu's ATA hard disk emulation at drive diagnostics offsets 54,55,56(Default CHS translation) change and make MS-DOS using of the hard disk image buggy? Or will it continue to work without problems using the newly set geometry(assuming the BIOS doesn't need to translate it, e.g. with 20MB disk images)?
I don't know how BIOSes work to determine drive parameters, it's up to them to detect drives and translate if necessary.
I just re-read your previous post and noticed you were mounting disk images on dosbox. What was the exact command you used to mount them, and did you try to boot from that image?
Dosbox only needs CHS parameters when mounting a unformatted raw image or trying to boot from it. Besides, to boot from it, it needs the translated geometry if you want to boot from DOS that was installed using translated geometry.
I simply mounted using:
imgmount c .\games_~1.img -t hdd -size 512,63,16,3968
The original geometry I used in UniPCemu (formatting it in that way and using it until recent, MS-DOS 5.0a 2GB sfdimg disk image) was the same(due to forced 16,64 and cylinders being automatically calculated). I'll need to use a disk image with another format to check correctly(e.g. 100MB disk image?).
I have a 100MB disk image, which used to be 203,16,63 in the old translation method(which it was formatted in). The new method would be 12800,16,1. So it would fail to read it, if changing cylinders screws up reading it?
I added another one before booting c using "boot -l c":
imgmount 3 .\largehdd.img -t hdd -fs none -size 512,1,16,12800
fdisk does see the second disk, being only 4MB large, but the partition of 99MB is still there? CD-ing to the second harddisk on drive letter D doesn't detect it(Invalid drive specification) on Dosbox.
I simply mounted using:
imgmount c .\games_~1.img -t hdd -size 512,63,16,3968
Mounting as filesystem (not raw, not booting from it) does not require geometry so it does not use your numbers. It does not need them because formatted images have the logical translated geometry in MBR and DOS partition boot sector. And yet you are trying to feed it the physical geometry which is wrong, DOS does not use physical geometry.
superfury wrote:
I have a 100MB disk image, which used to be 203,16,63 in the old translation method(which it was formatted in). The new method would be 12800,16,1. So it would fail to read it, if changing cylinders screws up reading it?
Those images are of different size, the new one is larger. If you have a DOS image you want to boot from, you need to tell DOSBOX the translated geometry it will show to DOS.
Besides the physical geometry is unrealistic, no 100MB drive would ever have 12800 cylinders. So you cannot use such geometry in DOS untranslated, it needs translation, which is why dosbox needs translated numbers it shows to DOS as DOS uses translated numbers.
superfury wrote:I added another one before booting c using "boot -l c":
imgmount 3 .\largehdd.img -t hdd -fs none -size 512,1,16,12800 […] Show full quote
I added another one before booting c using "boot -l c":
imgmount 3 .\largehdd.img -t hdd -fs none -size 512,1,16,12800
fdisk does see the second disk, being only 4MB large, but the partition of 99MB is still there? CD-ing to the second harddisk on drive letter D doesn't detect it(Invalid drive specification) on Dosbox.
Now trying on UniPCemu...
As I explained, that is untranslated geometry that BIOS cannot show so DOS cannot use, max is 1024 cyls, so that wraps around to 1*16*512=4MB disk. FDISK will read the MBR as that is always the first sector and thus it is readable, and the partition table has the old, already translated geometries in it as the partition was created with those values.
So I would need to create a new disk and move the files from the old disk to a newly created disk(which has an improved CHS partitioning, which follows the ATA-5 appendix C specification)? The 2GB disk image has no problems, since the geometry is unchanged(although the new geometry might have some orphan sectors(only accessable through LBA addressing mode), depending on how close it can get with CHS addressing format in the new spec).
Edit: Just made another small (almost classic, seeing how many times I did that in the past(should have learned by now not to do this: )) mistake: trying to load an unformatted, freshly partitioned disk image in WinImage: it will hang Windows mostly(needing task manager through extreme lagg and almost unresponsive OS with hard disk trashing to terminate it, as it's practically hanging the whole Windows 10 OS when trying to load the empty partition:S).
Just tried using the new geometry and disk image(which has been reformatted to the new geometry). It still shows up at 4MB only in Dosbox(after booting)?
The rules mentioned in the ATA-5 spec are followed, as far as I know, to create the emulated disk image geometry(which is reported at diagnostic words 54(cylinders), 55(heads), 56(Sectors Per Track)).
1void HDD_detectGeometry(uint_64 disk_size, word *cylinders, word *heads, word *SPT) 2{ 3 //Plain CHS geometry detection! 4 #ifdef TRADITIONALCHSTRANSLATION 5 uint_32 tempcylinders=0; 6 tempcylinders = (uint_32)(disk_size / (63 * 16)); //How many cylinders! 7 *cylinders = (tempcylinders>=0x3FFF)?0x3FFF:(tempcylinders?tempcylinders:1); //Give the maximum amount of cylinders allowed! 8 *heads = ((disk_size/get_SPT(disk_size))>=16)?16:((disk_size/get_SPT(disk_size))?(disk_size/get_SPT(disk_size)):1); //1-16 heads! 9 *SPT = (disk_size>=63)?63:disk_size; //How many sectors use for each track? No more than 63! 10 #else 11 //Optimal size detection? 12 word C, H, S; //To detect the size! 13 uint_64 CHSsize; //Found size! 14 word optimalC, optimalH, optimalS; //Optimal found size! 15 uint_64 optimalsize; 16 optimalsize = 1; //Optimal size found! 17 optimalC = 1; //Init! 18 optimalH = 1; //Init! 19 optimalS = 1; //Init! 20 21 //Basic requirement rule initialization! 22 byte limitcylinders; 23 limitcylinders = ((disk_size>1032192) && (disk_size<=16514064))?1:0; //Limit available using table? 24 if (disk_size>15481935) limitcylinders = 2; //Force 0x3FFF! 25 26 word limitheads; 27 limitheads = (disk_size<=8257536)?16:((disk_size>16514064)?15:0); //Head limit, if any! 28 29 word limitSPT; 30 limitSPT = (disk_size>1032192)?63:0; //Limit SPT? 31 32 C=0x3FFF; //Init! 33 do //Process all cylinder combinations! 34 { 35 H=16; //Init! 36 do 37 { 38 S=63; //Init! 39 do 40 { 41 CHSsize = (C*H*S); //Found size! 42 if (unlikely((CHSsize>optimalsize) && (CHSsize<=disk_size))) //New optimal found? 43 { 44 //Check additional requirements? Rules based on http://www.t13.org/Documents/UploadedDocuments/project/d1321r3-ATA-ATAPI-5.pdf appendix C! 45 if (unlikely(limitcylinders)) //Cylinder limited rule? 46 { 47 switch (limitcylinders) //What method? 48 { 49 case 1: //Using table? 50 if (H<5) //Maximum FFFFh? 51 { 52 if (unlikely(C>0xFFFF)) goto ignoreDetection; //Don't allow invalid combinations! 53 } 54 else if (H<9) //Maximum 7FFFh? 55 { 56 if (unlikely(C>0x7FFF)) goto ignoreDetection; //Don't allow invalid combinations! 57 } 58 else //Maximum 3FFFh? 59 { 60 if (unlikely(C>0x3FFF)) goto ignoreDetection; //Don't allow invalid combinations!
…Show last 30 lines
61 } 62 break; 63 case 2: //Force 0x3FFF? 64 if (unlikely(C!=0x3FFF)) goto ignoreDetection; //Don't allow invalid combinations! 65 break; 66 default: //Unknown? 67 break; 68 } 69 } 70 if (unlikely(limitheads && (H!=limitheads))) goto ignoreDetection; //Don't allow invalid combinations! 71 if (unlikely(limitSPT && (S!=limitSPT))) goto ignoreDetection; //Don't allow invalid combinations! 72 73 //Accept the new found size! 74 optimalC = C; //Optimal C! 75 optimalH = H; //Optimal H! 76 optimalS = S; //Optimal S! 77 optimalsize = CHSsize; //New optimal size! 78 } 79 ignoreDetection: 80 --S; 81 } while (S); 82 --H; 83 } while (H); 84 --C; 85 } while (C); 86 *cylinders = optimalC; //Optimally found cylinders! 87 *heads = optimalH; //Optimally found heads! 88 *SPT = optimalS; //Optimally found sectors! 89 #endif 90}
TRADITIONALCHSTRANSLATION is the old method used in UniPCemu. The other case(which is now activated) takes the largest size that can be found(defaulting to at least 1,1,1 when nothing is found, even for 0 sector images(empty .img file, which cannot be mounted in UniPCemu)). It should take the largest size available while adhering to the ATA-5 appendix C specs?
So this changes what to BIOS and DOS? The drive physical geometry C/H/S values are reported as per specification to BIOS?
But if BIOS uses LBA to access the drive, if there is no change in LBA total sectors, BIOS will most likely show identical logical translation to DOS no matter what the reported physical geometry is. Although for drives that can fit into 504MiB BIOS limits parameters should be reported in a way that does not need translation or LBA, so when mounting existing images, the parameters cannot be calculated, the parameters in the existing image must be used, no matter how non-optimal they are.
Yeah it's difficult, but in reality, is it really necessary to calculate CHS parameters for any possible size of image file? What if there are multiple solutions that are equally good at minimizing orphaned sectors, or resulting into zero orphaned sectors? That's why many image generating programs just use X*16*63 as the granularity is good enough, and when mounting existing images, the parameters are most likely generated again with assumption of X*16*63, or when this does not hold then the parameters can be detected from MBR and FAT partition info sector. When using X*16*63 method, X=1024 so max without translation fits the 504MiB limit. For larger drives, sectors are always 63, and bitshift method can be used by BIOS to cyl/head values so the limit kind of is (X/F) * (16*F) * 63, where F=factor 1,2,4,8, but 16 will cause trouble, so 1024*128*63 is the limit as 256 heads cause trouble, and thus larger drives used 15 heads to work around this to get (X/F) * (15*F) * 63, where F=factor 1,2,4,8, and 16 to get up to 1024*240*63, before LBA is necessary to go to 1024*255*63.
The words 54, 55 and 56 are supposed to be words 1,3,6. 54,55,56 are the current setting loaded by INITIALIZE DEVICE PARAMETERS command. Wirds 1,3,6 is the default CHS translation used by the disk, loaded when loading the disk image only.
16.2.1 Definitions and value ranges of IDENTIFY DEVICE words Definitions and value ranges of IDENTIFY DEVICE words (see 8.12) 21) Word 1 shall contain the number of user-addressable logical cylinders in the default CHS 3translation. If the content of words (61:60) is less than 16,514,064 then the content of word 1 4shall be greater than or equal to one and less than or equal to 65,535. If the content of words 5(61:60) is greater than or equal to 16,514,064 then the content of word 1 shall be equal to 616,383. 72) Word 3 shall contain the number of user-addressable logical heads in the default CHS 8translation. The content of word 3 shall be greater than or equal to one and less than or equal to 916. For compatibility with some BIOSs, the content of word 3 may be equal to 15 if the content of 10word 1 is greater than 8192. 113) Word 6 shall contain the number of user-addressable logical sectors in the default CHS 12translation. The content of word 6 shall be greater than or equal to one and less than or equal to 1363. 144) [(The content of word 1) ∗ (the content of word 3) ∗ (the content of word 6)] shall be less than or 15equal to 16,514,064. 165) Word 54 shall contain the number of user-addressable logical cylinders in the current CHS 17translation. The content of word 54 shall be greater than or equal to one and less than or equal 18to 65,535. After power-on or after a hardware reset the content of word 54 shall be equal to the 19content of word 1. 206) Word 55 shall contain the number of user-addressable logical heads in the current CHS 21translation. The content of word 55 shall be greater than or equal to one and less than or equal 22to 16. After power-on or after a hardware reset the content of word 55 shall be equal to the 23content of word 3. 247) Word 56 shall contain the number of user-addressable logical sectors in the current CHS 25translation. The content of word 56 should be equal to 63 for compatibility with all BIOSs. 26However, the content of word 56 may be greater than or equal to one and less than or equal to 27255. At power-on or after a hardware reset the content of word 56 shall equal the content of 28word 6. 298) Words (58:57) shall contain the user-addressable capacity in sectors for the current CHS 30translation. The content of words (58:57) shall equal [(the content of word 54) ∗ (the content of 31word 55) ∗ (the content of word 56)]. The content of words (58:57) shall be less than or equal to 3216,514,064. The content of words (58:57) shall be less than or equal to the content of words 33(61:60). 349) The content of words 54, 55, 56, and (58:57) may be affected by the host issuing an INITIALIZE 35DEVICE PARAMETERS command (see 8.16). 3610) If the content of words (61:60) is greater than 16,514,064 and if the device does not support CHS 37addressing, then the content of words 1, 3, 6, 54, 55, 56, and (58:57) shall equal zero. If the 38content of word 1, word 3, or word 6 equals zero, then the content of words 1, 3, 6, 54, 55, 56, 39and (58:57) shall equal zero. 4011) Words (61:60) shall contain the total number of user-addressable sectors. The content of words 41(61:60) shall be greater than or equal to one and less than or equal to 268,435,456. 4212) The content of words 1, 54, (58:57), and (61:60) may be affected by the host issuing a SET MAX 43ADDRESS command (see 8.38).
Words 1/54, 3/55 and 6/56 are loaded with the function's result when a IDE disk is mounted. Currently the rules of appendix C are applied:
1Annex C 2(informative) 3Identify device data for devices with more than 1024 logical cylinders 4C.1 Definitions and background information 5The original IBM PC BIOS (Basic Input/Output System) imposed several restrictions on the support of 6devices, and these have been incorporated into many higher level software products. One such restriction 7limits the capacity of a device. BIOS software cannot support a device with more than 1,024 cylinders, 16 8heads, and 63 sectors per track without translating an input logical geometry to a different output logical 9geometry. The maximum addressable capacity of a device that does not require BIOS translation is 101,032,192 sectors. 11These rules allow BIOSes using bit shifting translation to access 15,481,935 (16,383∗15∗63) sectors, and 12BIOSes using LBA assisted translation to access 16,450,560 (1024∗255∗63) sectors. Extended BIOS 13functionality is defined in the ANSI Technical Report Enhanced BIOS Services for Disk Drives, which 14describes new services provided by BIOS firmware to support ATA hard disks up to 16 mega-terra-sectors. 15C.2 Cylinder, head, and sector addressing 16BIOSs and other software that operate a device in CHS translation employ a combination of IDENTIFY 17DEVICE data words 1, 3, 6, words 53-58, and words 60-61 to ascertain the appropriate translation to use and 18determine the capacity of a device. 19Maximum compatibility is facilitated if the following guidelines are used. These guidelines limit the values 20placed into words 1, 3, 6, 53-58, and 60-61. Accessing beyond 15,481,935 sectors should be performed 21using LBA. 22C.2.1 Word 1 23For devices with a capacity less than or equal to 1,032,192 sectors, if IDENTIFY DEVICE data word 1 24(Default Cylinders) does not specify a value greater than 1,024, then no guideline is necessary. 25If a device is greater than 1,032,192 sectors, but less than or equal to 16,514,064 sectors, the maximum 26value that can be placed into this word is determined by the value in word 3 as shown in table C.1. 27If a device is greater than 15,481,935 sectors and supports CHS, this word should contain 16,383 (3FFFh). 28The INITIALIZE DEVICE PARAMETERS command does not change this value. 29The value in this word is changed by the SET MAX ADDRESS command. 30 31Table C.1 − Word 1 value for devices between 1,032,192 and 16,514,064 sectors 32Value in word 3 Maximum value in word 1 Value in word 3 Maximum value in word 1 331 1h 65,535 FFFFh 342 2h 65,535 FFFFh 353 3h 65,535 FFFFh 364 4h 65,535 FFFFh 375 5h 32,767 7FFFh 386 6h 32,767 7FFFh 397 7h 32,767 7FFFh 408 8h 32,767 7FFFh 419 9h 16,383 3FFFh 4210 Ah 16,383 3FFFh 4311 Bh 16,383 3FFFh 4412 Ch 16,383 3FFFh 4513 Dh 16,383 3FFFh 4614 Eh 16,383 3FFFh 4715 Fh 16,383 3FFFh 4816 10h 16,383 3FFFh 49C.2.2 Word 3 50IDENTIFY DEVICE data word 3 (Default Heads) does not specify a value greater than 16. If the device has 51less than or equal to 8,257,536 sectors, then set word 3 to 16 heads. If the device has more than 16,514,064 52sectors, then set word 3 to 15 heads. If this value is set to 16 when the device has more than 16,514,064 53sectors, some systems will not boot some operating systems. 54The INITIALIZE DEVICE PARAMETERS command does not change this value. 55C.2.3 Word 6 56If the device is above 1,032,192 sectors then the value should be 63. This value does not exceed 63 (3Fh). 57The INITIALIZE DEVICE PARAMETERS command does not change this value. 58C.2.4 Use of words 53 through 58 59Devices with a capacity over 1,032,192 sectors implement words 53-58. Devices with a capacity less than or 60equal to 1,032,192 sectors may also implement these words. These words define the address range for all
…Show last 18 lines
61sectors accessible in CHS mode under 16,514,064. The product of word 54, word 55, and word 56 must not 62exceed 16,514,064. 63C.2.5 Words 60-61 64IDENTIFY DEVICE data words 60-61 contain a 32-bit value that is equal to the total number of sectors that 65can be accessed using LBA. If the device is less than or equal to 15,481,935 sectors, this value should be the 66product of words 1, 3, and 6. Setting the total number of LBA sectors in this manner reduces the probability of 67conflicting device capacities being calculated by different operating systems. 68 69C.3 Orphan sectors 70The sectors, if any, between the last sector addressable in CHS mode and the last sector addressable in LBA 71mode are known as "orphan" sectors. A device may or may not allow access to these sectors in CHS 72addressing mode. 73The values in words 1, 3, and 6 are selected such that the number of orphan sectors is minimized. Normally, 74the number of orphan sectors should not exceed ( [word55] x [word56] - 1 ). However, the host system may 75create conditions where there are a larger number of orphans sectors by issuing the INITIALIZE DEVICE 76PARAMETERS command with values other than the values in words 3 and 6. If the recommendation in C.2.5 77is followed, there will be no orphan sectors and problems associated with new operating systems calculating 78a different device size from older operating systems will be minimized.
Last edited by superfury on 2017-11-08, 23:13. Edited 1 time in total.
Just found a bug in the CHS detection algorithm, not counting past 0x3FFF instead of 0xFFFF cylinders. I've fixed this now. 2GB reports as 3968,16,63(CHS) and 100MB reports as 12800,16,1(CHS). That should be correct, according to the rules of ATA-5?
I can't rely on disk contents, as disks may start out blank(filled with zeroes for the entire image) for all UniPCemu's supported formats(creating static .img and sparse .sfdimg disk images), which only have a size and no geometry(except default by above function and a size in sectors only).
The words 54, 55 and 56 are supposed to be words 1,3,6. 54,55,56 are the current setting loaded by JNITIALIZE DEVICE PARAMETERS command. Wirds 1,3,6 is the default CHS translation used by the disk, loaded when loading the disk image only.
I don't know if BIOSes send these, and if they do, do they ever select other geometries than the physical default. I believe this command has nothing to do with the way BIOS translates geometry to INT13H interface. But it may be also the way how BIOS implements DOS CHS to DRIVE CHS conversion, by setting the drive to virtual geometry. Most definitely DOS CHS to LBA calculations are done by the BIOS before LBA is sent to drive. You should know what your BIOS does.
The point was, your situation is same as with real hardware. One hard drive may end up being translated differently at the INT13H interface between two computers depending on their BIOS so DOS won't boot.
superfury wrote:
Just found a bug in the CHS detection algorithm, not counting past 0x3FFF instead of 0xFFFF cylinders. I've fixed this now. 2GB reports as 3968,16,63(CHS) and 100MB reports as 12800,16,1(CHS). That should be correct, according to the rules of ATA-5?
I still think 100MB drives were used back in the day when BIOS level translation was not invented, so it was impossible for cylinders to be over 1024.
The geometry given is generated by the function, which currently follows the appendix C and general rules quoted in my last post. If I were to reduce the cylinders to 1024, it wouldn't match the rules without loss of data, or would it? Do I need to add an additional restraint for 1024 cylinders when below 512MB to fix that?
Edit: After applying the limit for ~504MB and below, it now ends up with 800,16,16 for the 100MB disk image. Dosbox(as well as my other disk image booted through Dosbox) seems to read it fine now:D
Edit: This is the new geometry autodetection routine:
1void HDD_detectGeometry(uint_64 disk_size, word *cylinders, word *heads, word *SPT) 2{ 3 //Plain CHS geometry detection! 4 #ifdef TRADITIONALCHSTRANSLATION 5 uint_32 tempcylinders=0; 6 tempcylinders = (uint_32)(disk_size / (63 * 16)); //How many cylinders! 7 *cylinders = (tempcylinders>=0x3FFF)?0x3FFF:(tempcylinders?tempcylinders:1); //Give the maximum amount of cylinders allowed! 8 *heads = ((disk_size/get_SPT(disk_size))>=16)?16:((disk_size/get_SPT(disk_size))?(disk_size/get_SPT(disk_size)):1); //1-16 heads! 9 *SPT = (disk_size>=63)?63:disk_size; //How many sectors use for each track? No more than 63! 10 #else 11 //Optimal size detection? 12 word C, H, S; //To detect the size! 13 uint_64 CHSsize; //Found size! 14 word optimalC, optimalH, optimalS; //Optimal found size! 15 uint_64 optimalsize; 16 optimalsize = 1; //Optimal size found! 17 optimalC = 1; //Init! 18 optimalH = 1; //Init! 19 optimalS = 1; //Init! 20 21 //Basic requirement rule initialization! 22 byte limitcylinders; 23 limitcylinders = ((disk_size>1032192) && (disk_size<=16514064))?1:((disk_size<=1032192)?3:0); //Limit available using table? 24 if (disk_size>15481935) limitcylinders = 2; //Force 0x3FFF! 25 26 word limitheads; 27 limitheads = (disk_size<=8257536)?16:((disk_size>16514064)?15:0); //Head limit, if any! 28 29 word limitSPT; 30 limitSPT = (disk_size>1032192)?63:0; //Limit SPT? 31 32 //Apply Bochs compatibility! 33 if ((disk_size>=20160) && (disk_size<(262144*16*63)) && (((disk_size/1008)*1008)==disk_size) && ((disk_size/(16*63))<=0xFFFF)) //Assume Bochs compatiblity and still within valid range of disk size we support? 34 { 35 optimalH = 16; //Force Bochs-style compatiblity! 36 optimalS = 63; //Force Bochs-style compatiblity! 37 optimalC = (word)(disk_size/(16*63)); //Force Bochs-style compatiblity! 38 goto applyBochsImage; 39 } 40 41 C=0xFFFF; //Init! 42 do //Process all cylinder combinations! 43 { 44 H=16; //Init! 45 do 46 { 47 S=63; //Init! 48 do 49 { 50 CHSsize = (C*H*S); //Found size! 51 if (unlikely((CHSsize>optimalsize) && (CHSsize<=disk_size))) //New optimal found? 52 { 53 //Check additional requirements? Rules based on http://www.t13.org/Documents/UploadedDocuments/project/d1321r3-ATA-ATAPI-5.pdf appendix C! 54 if (unlikely(limitcylinders)) //Cylinder limited rule? 55 { 56 switch (limitcylinders) //What method? 57 { 58 case 1: //Using table? 59 if (H<5) //Maximum FFFFh? 60 {
Anyone? Is this routine correct? It tries to be compatible with Bochs' 16x63 block geometry(which has priority over the older autodetection), while also being compatible with disk images formatted in the optimal geometry documented by the appendix C of the ATA/ATAPI-5 spec.
I've made the disk CHS partitioning autodetect a bit more configurable:
- Old sfdimg files will use a compatibility CHS layout(the defined ifdef part in my code).
- New sfdimg files will use the new improved autodetect CHS layout(based on rules described earlier, this method is done by a disk image extension block of 512 bytes).
- img files will default to the same CHS layout as new sfdimg files.
- img files with a accompanying .img.unipcemu.txt file will be treated the same as old .sfdimg files.
- img files with a accompanying .img.bochs.txt file will use the Bochs geometry(16 heads, 63 sectors per track) layout, for up to 65535 cylinders.
- img files with and without .img.*.txt can be converted to and from .sfdimg files using the new disk image extension block to keep it's geometry when converting between the two disk formats.
The newer format specifications(newly createn sfdimg files and converted/defragmented sfdimg files) are incompatible with the older UniPCemu versions, due to extensions on the file format. Older disk images can still be used on the new builds, as long as they're not defragmented(which recreates a new sfdimg file, which adds the new extension block, which is unsupported by older UniPCemu versions).
So, to use the new format, just create and use it(both being in the new geometry format). To use Bochs static disk images or old UniPCemu static disk images, add a text file with the same filename which has .bochs.txt or .unipcemu.txt appended to the original disk filename, e.g. games.img.sfdimg.txt or bochsimage.img.bochs.txt
Is that a better way of handling the new and other geometries?
Edit: Just improved Bochs/Dosbox compatibility a little by making it create new empty static&dynamic disk images(using the settings menu option to create a disk image) in the Optimal format by default. It uses the Bochs format when using square(Numpad 4 key) instead of the normal way(like toggling readonly on non-CD-ROM drives).