From 1e90a84e9025d470fdcf6ecb885ea5e724c74c0c Mon Sep 17 00:00:00 2001 From: SarahW Date: Wed, 5 Jul 2017 21:54:48 +0100 Subject: [PATCH] Tweaks to hard drive image parameter finding. Patch from Greatpsycho. --- src/allegro-gui-hdconf.c | 19 ++++++++++--------- src/win-hdconf.c | 16 ++++++++++------ src/wx-sdl2-hdconf.c | 13 +++++++++---- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/allegro-gui-hdconf.c b/src/allegro-gui-hdconf.c index 493c3ff..050be68 100644 --- a/src/allegro-gui-hdconf.c +++ b/src/allegro-gui-hdconf.c @@ -68,7 +68,7 @@ static int hdconf_open(int msg, DIALOG *d, int c) fseeko64(f, -1, SEEK_END); sz = ftello64(f) + 1; fclose(f); - if ((sz % 17) == 0 && sz <= 133693440) + if ((sz % 17) == 0 && sz <= 142606336) { sprintf(hd_sectors_new, "17"); if (sz <= 26738688) @@ -76,20 +76,21 @@ static int hdconf_open(int msg, DIALOG *d, int c) sprintf(hd_heads_new, "4"); sprintf(hd_cylinders_new, "%i", (int)((sz / 512) / 4) / 17); } - else if (sz <= 53477376) + else if ((sz % 3072) == 0 && sz <= 53477376) { sprintf(hd_heads_new, "6"); sprintf(hd_cylinders_new, "%i", (int)((sz / 512) / 6) / 17); } - else if (sz <= 71303168) - { - sprintf(hd_heads_new, "8"); - sprintf(hd_cylinders_new, "%i", (int)((sz / 512) / 8) / 17); - } else { - sprintf(hd_heads_new, "15"); - sprintf(hd_cylinders_new, "%i", (int)((sz / 512) / 15) / 17); + int i; + for(i=5;i<16;i++) + { + if((sz % (i * 512)) == 0 && sz <= 1024*i*17*512) break; + if (i == 5) i++; + } + sprintf(hd_heads_new, "%i",i); + sprintf(hd_cylinders_new, "%i", (int)((sz / 512) / i) / 17); } } else diff --git a/src/win-hdconf.c b/src/win-hdconf.c index d53e86c..c1107e9 100644 --- a/src/win-hdconf.c +++ b/src/win-hdconf.c @@ -61,19 +61,23 @@ static void check_hd_type(off64_t sz) } else { - if ((sz % 17) == 0 && sz <= 133693440) + if ((sz % 17) == 0 && sz <= 142606336) { hd_new_spt = 17; if (sz <= 26738688) hd_new_hpc = 4; - else if (sz <= 53477376) + else if ((sz % 3072) == 0 && sz <= 53477376) hd_new_hpc = 6; - else if (sz <= 71303168) - hd_new_hpc = 8; else - hd_new_hpc = 15; - + { + for (c=5;c<16;c++) + { + if((sz % (c * 512)) == 0 && sz <= 1024*c*17*512) break; + if (c == 5) c++; + } + hd_new_hpc = c; + } hd_new_cyl = (int)((sz / 512) / hd_new_hpc) / 17; } else diff --git a/src/wx-sdl2-hdconf.c b/src/wx-sdl2-hdconf.c index f462cb1..b4e1e51 100644 --- a/src/wx-sdl2-hdconf.c +++ b/src/wx-sdl2-hdconf.c @@ -65,12 +65,17 @@ static void check_hd_type(off64_t sz) if (sz <= 26738688) hd_new_hpc = 4; - else if (sz <= 53477376) + else if ((sz % 3072) == 0 && sz <= 53477376) hd_new_hpc = 6; - else if (sz <= 71303168) - hd_new_hpc = 8; else - hd_new_hpc = 15; + { + for (c=5;c<16;c++) + { + if((sz % (c * 512)) == 0 && sz <= 1024*c*17*512) break; + if (c == 5) c++; + } + hd_new_hpc = c; + } hd_new_cyl = (int)((sz / 512) / hd_new_hpc) / 17; }