From 9350ee01a5125c43a9e224c64986a825e242459d Mon Sep 17 00:00:00 2001 From: OBattler Date: Sun, 19 Jul 2020 06:18:38 +0200 Subject: [PATCH] More MO fixes. --- src/disk/mo.c | 30 +++++++++++++++++++++++++++--- src/include/86box/language.h | 3 ++- src/win/86Box.rc | 3 ++- src/win/win_new_floppy.c | 2 +- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/disk/mo.c b/src/disk/mo.c index 7df757419..3ad2a0e85 100644 --- a/src/disk/mo.c +++ b/src/disk/mo.c @@ -326,12 +326,31 @@ mo_load_abort(mo_t *dev) } +int +image_is_mdi(const wchar_t *s) +{ + int len; + wchar_t ext[5] = { 0, 0, 0, 0, 0 }; + char *ws = (char *) s; + len = wcslen(s); + if ((len < 4) || (s[0] == L'.')) + return 0; + memcpy(ext, ws + ((len - 4) << 1), 8); + if (! wcscasecmp(ext, L".MDI")) + return 1; + else + return 0; +} + + int mo_load(mo_t *dev, wchar_t *fn) { - int size = 0; + int is_mdi, size = 0; unsigned int i, found = 0; + is_mdi = image_is_mdi(fn); + dev->drv->f = plat_fopen(fn, dev->drv->read_only ? L"rb" : L"rb+"); if (!dev->drv->f) { if (!dev->drv->read_only) { @@ -347,6 +366,12 @@ mo_load(mo_t *dev, wchar_t *fn) fseek(dev->drv->f, 0, SEEK_END); size = ftell(dev->drv->f); + if (is_mdi) { + /* This is a MDI image. */ + size -= 0x1000; + dev->drv->base = 0x1000; + } + for (i = 0; i < KNOWN_MO_TYPES; i++) { if (size == mo_types[i].disk_size) { found = 1; @@ -356,9 +381,8 @@ mo_load(mo_t *dev, wchar_t *fn) } } - if (!found) { + if (!found) return mo_load_abort(dev); - } if (fseek(dev->drv->f, dev->drv->base, SEEK_SET) == -1) fatal("mo_load(): Error seeking to the beginning of the file\n"); diff --git a/src/include/86box/language.h b/src/include/86box/language.h index 3413b1eb9..2e2ae96c7 100644 --- a/src/include/86box/language.h +++ b/src/include/86box/language.h @@ -112,6 +112,7 @@ #define IDS_2136 2136 // "Don't Exit" #define IDS_2137 2137 // "Reset" #define IDS_2138 2138 // "Don't Reset" +#define IDS_2139 2139 // "MO images (*.IM?)\0*.IM?..." #define IDS_4096 4096 // "Hard disk (%s)" #define IDS_4097 4097 // "%01i:%01i" @@ -208,7 +209,7 @@ #define IDS_LANG_ENUS IDS_7168 -#define STR_NUM_2048 91 +#define STR_NUM_2048 92 #define STR_NUM_3072 11 #define STR_NUM_4096 18 #define STR_NUM_4352 7 diff --git a/src/win/86Box.rc b/src/win/86Box.rc index cda429397..25748fbdf 100644 --- a/src/win/86Box.rc +++ b/src/win/86Box.rc @@ -979,7 +979,7 @@ BEGIN IDS_2113 "Are you sure you want to exit 86Box?" IDS_2114 "Unable to initialize Ghostscript" IDS_2115 "MO %i (%ls): %ls" - IDS_2116 "MO images (*.IM?)\0*.IM?\0All files (*.*)\0*.*\0" + IDS_2116 "MO images (*.IM?;*.MDI)\0*.IM?;*.MDI\0All files (*.*)\0*.*\0" IDS_2117 "Welcome to 86Box!" IDS_2118 "Internal controller" IDS_2119 "Exit" @@ -1022,6 +1022,7 @@ BEGIN IDS_2136 "Don't Exit" IDS_2137 "Reset" IDS_2138 "Don't Reset" + IDS_2139 "MO images (*.IM?;*.MDI)\0*.IM?;*.MDI\0All files (*.*)\0*.*\0" END STRINGTABLE DISCARDABLE diff --git a/src/win/win_new_floppy.c b/src/win/win_new_floppy.c index f09d0d6f2..eb9dc55de 100644 --- a/src/win/win_new_floppy.c +++ b/src/win/win_new_floppy.c @@ -754,7 +754,7 @@ NewFloppyDialogProcedure(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) return TRUE; case IDC_CFILE: - if (!file_dlg_w(hdlg, plat_get_string(is_zip ? IDS_2055 : IDS_2062), L"", 1)) { + if (!file_dlg_w(hdlg, plat_get_string(is_mo ? IDS_2139 : (is_zip ? IDS_2055 : IDS_2062)), L"", 1)) { if (!wcschr(wopenfilestring, L'.')) { if (wcslen(wopenfilestring) && (wcslen(wopenfilestring) <= 256)) { twcs = &wopenfilestring[wcslen(wopenfilestring)];