From 07eded0225e41fde321730d9b7b8be5e08908e29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Sun, 19 Jul 2020 17:45:15 +0200 Subject: [PATCH 1/8] Fix typos, closes #935 --- src/disk/hdc.c | 4 ++-- src/win/86Box.rc | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/disk/hdc.c b/src/disk/hdc.c index 1bd40b88f..86ea25fe4 100644 --- a/src/disk/hdc.c +++ b/src/disk/hdc.c @@ -87,7 +87,7 @@ inthdc_close(void *priv) static const device_t inthdc_device = { - "Internal Controller", 0, 0, + "Internal controller", 0, 0, inthdc_init, inthdc_close, NULL, NULL, NULL, NULL, NULL }; @@ -101,7 +101,7 @@ static const struct { { "None", "none", &null_device }, - { "Internal Controller", "internal", + { "Internal controller", "internal", &inthdc_device }, { "[ISA] [MFM] IBM PC Fixed Disk Adapter", "st506_xt", diff --git a/src/win/86Box.rc b/src/win/86Box.rc index 25748fbdf..1995f7802 100644 --- a/src/win/86Box.rc +++ b/src/win/86Box.rc @@ -296,7 +296,7 @@ END DLG_NEW_FLOPPY DIALOG DISCARDABLE 0, 0, 226, 86 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU -CAPTION "New Floppy Image" +CAPTION "New Image" FONT 8, "MS Sans Serif" BEGIN DEFPUSHBUTTON "OK",IDOK,74,65,50,14 From d1fca111373e334880151ae9dd00e63f71b23ade Mon Sep 17 00:00:00 2001 From: OBattler Date: Sun, 19 Jul 2020 17:49:58 +0200 Subject: [PATCH 2/8] Cleaned up the MO struct and some fixed to the new image dialpg. --- src/disk/mo.c | 2 +- src/include/86box/mo.h | 28 +++++++++++++--------------- src/win/win_new_floppy.c | 2 +- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/disk/mo.c b/src/disk/mo.c index 3ad2a0e85..feefe881b 100644 --- a/src/disk/mo.c +++ b/src/disk/mo.c @@ -373,7 +373,7 @@ mo_load(mo_t *dev, wchar_t *fn) } for (i = 0; i < KNOWN_MO_TYPES; i++) { - if (size == mo_types[i].disk_size) { + if (size == (mo_types[i].sectors * mo_types[i].bytes_per_sector)) { found = 1; dev->drv->medium_size = mo_types[i].sectors; dev->drv->sector_size = mo_types[i].bytes_per_sector; diff --git a/src/include/86box/mo.h b/src/include/86box/mo.h index 921a9aba3..cefb336b8 100644 --- a/src/include/86box/mo.h +++ b/src/include/86box/mo.h @@ -31,31 +31,29 @@ typedef struct { uint32_t sectors; uint16_t bytes_per_sector; - int64_t disk_size; - char name[255]; } mo_type_t; #define KNOWN_MO_TYPES 10 static const mo_type_t mo_types[KNOWN_MO_TYPES] = { // 3.5" standard M.O. disks - { 248826, 512, 127398912, "3.5\" 128Mb M.O. (ISO 10090)" }, - { 446325, 512, 228518400, "3.5\" 230Mb M.O. (ISO 13963)" }, - { 1041500, 512, 533248000, "3.5\" 540Mb M.O. (ISO 15498)" }, - { 310352, 2048, 635600896, "3.5\" 640Mb M.O. (ISO 15498)" }, - { 605846, 2048, 1240772608, "3.5\" 1.3Gb M.O. (GigaMO)" }, - { 1063146, 2048, 2177323008, "3.5\" 2.3Gb M.O. (GigaMO 2)" }, + { 248826, 512 }, + { 446325, 512 }, + { 1041500, 512 }, + { 310352, 2048 }, + { 605846, 2048 }, + { 1063146, 2048 }, // 5.25" M.O. disks - {573624, 512, 293695488, "5.25\" 600Mb M.O."}, - {314568, 1024, 322117632, "5.25\" 650Mb M.O."}, - {904995, 512, 463357440, "5.25\" 1Gb M.O."}, - {637041, 1024, 652329984, "5.25\" 1.3Gb M.O."}, + {573624, 512 }, + {314568, 1024 }, + {904995, 512 }, + {637041, 1024 }, }; typedef struct { - char vendor[8]; - char model[16]; - char revision[4]; + const char vendor[8]; + const char model[16]; + const char revision[4]; int8_t supported_media[KNOWN_MO_TYPES]; } mo_drive_type_t; diff --git a/src/win/win_new_floppy.c b/src/win/win_new_floppy.c index eb9dc55de..30cfd8f59 100644 --- a/src/win/win_new_floppy.c +++ b/src/win/win_new_floppy.c @@ -543,7 +543,7 @@ create_mo_sector_image(WCHAR *file_name, int8_t disk_size, uint8_t is_mdi, HWND total_sectors = dp->sectors; total_size = total_sectors * sector_bytes; - pbar_max = dp->sectors >> 11; + pbar_max = total_size; if (is_mdi) pbar_max += base; pbar_max >>= 11; From 146d041945fde9d4a39e44533bad11329f5725cb Mon Sep 17 00:00:00 2001 From: OBattler Date: Sun, 19 Jul 2020 21:32:23 +0200 Subject: [PATCH 3/8] OPL cycles fixes. --- src/include/86box/snd_opl.h | 4 +++- src/sound/snd_opl.c | 15 +++++++++++++-- src/sound/snd_sb.c | 4 ++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/include/86box/snd_opl.h b/src/include/86box/snd_opl.h index 22a5473f4..f01ea0214 100644 --- a/src/include/86box/snd_opl.h +++ b/src/include/86box/snd_opl.h @@ -32,7 +32,7 @@ typedef struct { #else void *opl; #endif - int8_t is_opl3; + int8_t is_opl3, do_cycles; uint16_t port; uint8_t status; @@ -47,6 +47,8 @@ typedef struct { } opl_t; +extern void opl_set_do_cycles(opl_t *dev, int8_t do_cycles); + extern uint8_t opl2_read(uint16_t port, void *); extern void opl2_write(uint16_t port, uint8_t val, void *); extern void opl2_init(opl_t *); diff --git a/src/sound/snd_opl.c b/src/sound/snd_opl.c index 68b778d4b..07a7370fe 100644 --- a/src/sound/snd_opl.c +++ b/src/sound/snd_opl.c @@ -162,11 +162,20 @@ opl_write(opl_t *dev, uint16_t port, uint8_t val) } +void +opl_set_do_cycles(opl_t *dev, int8_t do_cycles) +{ + dev->do_cycles = do_cycles; +} + + static void opl_init(opl_t *dev, int is_opl3) { memset(dev, 0x00, sizeof(opl_t)); + dev->is_opl3 = is_opl3; + dev->do_cycles = 1; /* Create a NukedOPL object. */ dev->opl = nuked_init(48000); @@ -192,7 +201,8 @@ opl2_read(uint16_t port, void *priv) { opl_t *dev = (opl_t *)priv; - cycles -= ISA_CYCLES(8); + if (dev->do_cycles) + sub_cycles((int) (isa_timing * 8)); opl2_update(dev); @@ -240,7 +250,8 @@ opl3_read(uint16_t port, void *priv) { opl_t *dev = (opl_t *)priv; - cycles -= ISA_CYCLES(8); + if (dev->do_cycles) + sub_cycles((int)(isa_timing * 8)); opl3_update(dev); diff --git a/src/sound/snd_sb.c b/src/sound/snd_sb.c index d382fc218..e42317536 100644 --- a/src/sound/snd_sb.c +++ b/src/sound/snd_sb.c @@ -1187,6 +1187,8 @@ sb_pro_v1_opl_read(uint16_t port, void *priv) { sb_t *sb = (sb_t *)priv; + sub_cycles((int)(isa_timing * 8)); + (void)opl2_read(port, &sb->opl2); // read, but ignore return(opl2_read(port, &sb->opl)); } @@ -1225,7 +1227,9 @@ void *sb_pro_v1_init(const device_t *info) sb->opl_enabled = device_get_config_int("opl"); if (sb->opl_enabled) { opl2_init(&sb->opl); + opl_set_do_cycles(&sb->opl, 0); opl2_init(&sb->opl2); + opl_set_do_cycles(&sb->opl2, 0); } sb_dsp_init(&sb->dsp, SBPRO, SB_SUBTYPE_DEFAULT, sb); sb_dsp_setaddr(&sb->dsp, addr); From d2e6414fc68054bd8dde8a8634d5c1cdd0f0ab7a Mon Sep 17 00:00:00 2001 From: OBattler Date: Sun, 19 Jul 2020 21:41:15 +0200 Subject: [PATCH 4/8] MO image creation now only allocates 2048 bytes. --- src/win/win_new_floppy.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/win/win_new_floppy.c b/src/win/win_new_floppy.c index 30cfd8f59..ba162c06e 100644 --- a/src/win/win_new_floppy.c +++ b/src/win/win_new_floppy.c @@ -599,11 +599,11 @@ create_mo_sector_image(WCHAR *file_name, int8_t disk_size, uint8_t is_mdi, HWND pbar_max -= 2; } - empty = (unsigned char *) malloc(total_size); - memset(empty, 0x00, total_size); + empty = (unsigned char *) malloc(2048); + memset(empty, 0x00, 2048); for (i = 0; i < pbar_max; i++) { - fwrite(&empty[i << 11], 1, 2048, f); + fwrite(empty, 1, 2048, f); SendMessage(h, PBM_SETPOS, (WPARAM) i + 2, (LPARAM) 0); while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE | PM_NOYIELD)) { From ee33e13c044599f6732fde4a28b97db58588f6fc Mon Sep 17 00:00:00 2001 From: OBattler Date: Sun, 19 Jul 2020 22:28:37 +0200 Subject: [PATCH 5/8] Changed MO image creation to 1 MB blocks + remainder block. --- src/win/win_new_floppy.c | 73 ++++++++++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 25 deletions(-) diff --git a/src/win/win_new_floppy.c b/src/win/win_new_floppy.c index ba162c06e..0e3da7cb2 100644 --- a/src/win/win_new_floppy.c +++ b/src/win/win_new_floppy.c @@ -526,13 +526,13 @@ create_mo_sector_image(WCHAR *file_name, int8_t disk_size, uint8_t is_mdi, HWND HWND h; FILE *f; const mo_type_t *dp = &mo_types[disk_size]; - uint8_t *empty; - uint32_t total_size = 0; + uint8_t *empty, *empty2 = NULL; + uint32_t total_size = 0, total_size2; uint32_t total_sectors = 0; uint32_t sector_bytes = 0; uint16_t base = 0x1000; - uint32_t pbar_max = 0; - uint32_t i; + uint32_t pbar_max = 0, blocks_num; + uint32_t i, j; MSG msg; f = plat_fopen(file_name, L"wb"); @@ -543,11 +543,18 @@ create_mo_sector_image(WCHAR *file_name, int8_t disk_size, uint8_t is_mdi, HWND total_sectors = dp->sectors; total_size = total_sectors * sector_bytes; + total_size2 = (total_size >> 20) << 20; + total_size = total_size - total_size2; + pbar_max = total_size; + pbar_max >>= 20; + blocks_num = pbar_max; if (is_mdi) - pbar_max += base; - pbar_max >>= 11; - pbar_max--; + pbar_max++; + if (total_size2 == 0) + pbar_max++; + + j = is_mdi ? 1 : 0; h = GetDlgItem(hwnd, IDC_COMBO_RPM_MODE); EnableWindow(h, FALSE); @@ -556,7 +563,7 @@ create_mo_sector_image(WCHAR *file_name, int8_t disk_size, uint8_t is_mdi, HWND EnableWindow(h, FALSE); ShowWindow(h, SW_HIDE); h = GetDlgItem(hwnd, IDC_PBAR_IMG_CREATE); - SendMessage(h, PBM_SETRANGE32, (WPARAM) 0, (LPARAM) pbar_max); + SendMessage(h, PBM_SETRANGE32, (WPARAM) 0, (LPARAM) pbar_max - 1); SendMessage(h, PBM_SETPOS, (WPARAM) 0, (LPARAM) 0); EnableWindow(h, TRUE); ShowWindow(h, SW_SHOW); @@ -565,7 +572,6 @@ create_mo_sector_image(WCHAR *file_name, int8_t disk_size, uint8_t is_mdi, HWND ShowWindow(h, SW_SHOW); h = GetDlgItem(hwnd, IDC_PBAR_IMG_CREATE); - pbar_max++; if (is_mdi) { empty = (unsigned char *) malloc(base); @@ -589,22 +595,7 @@ create_mo_sector_image(WCHAR *file_name, int8_t disk_size, uint8_t is_mdi, HWND fwrite(&empty[0x0800], 1, 2048, f); free(empty); - SendMessage(h, PBM_SETPOS, (WPARAM) 2, (LPARAM) 0); - - while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE | PM_NOYIELD)) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - - pbar_max -= 2; - } - - empty = (unsigned char *) malloc(2048); - memset(empty, 0x00, 2048); - - for (i = 0; i < pbar_max; i++) { - fwrite(empty, 1, 2048, f); - SendMessage(h, PBM_SETPOS, (WPARAM) i + 2, (LPARAM) 0); + SendMessage(h, PBM_SETPOS, (WPARAM) 1, (LPARAM) 0); while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE | PM_NOYIELD)) { TranslateMessage(&msg); @@ -612,6 +603,38 @@ create_mo_sector_image(WCHAR *file_name, int8_t disk_size, uint8_t is_mdi, HWND } } + empty = (unsigned char *) malloc(1048576); + memset(empty, 0x00, 1048576); + + if (total_size2 > 0) { + empty2 = (unsigned char *) malloc(total_size2); + memset(empty, 0x00, total_size2); + } + + for (i = 0; i < blocks_num; i++) { + fwrite(empty, 1, 1048576, f); + + SendMessage(h, PBM_SETPOS, (WPARAM) i + j, (LPARAM) 0); + + while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE | PM_NOYIELD)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + + if (total_size2 > 0) { + fwrite(empty2, 1, total_size2, f); + + SendMessage(h, PBM_SETPOS, (WPARAM) pbar_max - 1, (LPARAM) 0); + + while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE | PM_NOYIELD)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + + if (empty2 != NULL) + free(empty2); free(empty); fclose(f); From b61a1baaf91859cbadc23cb6cc439578909d3372 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sun, 19 Jul 2020 23:05:34 +0200 Subject: [PATCH 6/8] Final MO image creation fix. --- src/win/win_new_floppy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/win/win_new_floppy.c b/src/win/win_new_floppy.c index 0e3da7cb2..9845c77cf 100644 --- a/src/win/win_new_floppy.c +++ b/src/win/win_new_floppy.c @@ -544,7 +544,7 @@ create_mo_sector_image(WCHAR *file_name, int8_t disk_size, uint8_t is_mdi, HWND total_size = total_sectors * sector_bytes; total_size2 = (total_size >> 20) << 20; - total_size = total_size - total_size2; + total_size2 = total_size - total_size2; pbar_max = total_size; pbar_max >>= 20; From e663a4e41c83cc77a159fa262eeb731d8e5d2541 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sun, 19 Jul 2020 23:50:47 +0200 Subject: [PATCH 7/8] More MO fixes. --- src/disk/mo.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/disk/mo.c b/src/disk/mo.c index feefe881b..3841e103c 100644 --- a/src/disk/mo.c +++ b/src/disk/mo.c @@ -346,7 +346,8 @@ image_is_mdi(const wchar_t *s) int mo_load(mo_t *dev, wchar_t *fn) { - int is_mdi, size = 0; + int is_mdi; + uint32_t size = 0; unsigned int i, found = 0; is_mdi = image_is_mdi(fn); @@ -1037,7 +1038,7 @@ mo_insert(mo_t *dev) void mo_format(mo_t *dev) { - long size; + unsigned long size; int ret; int fd; From 2e35cb3df69c8c47bff09c706f48242a3529a44d Mon Sep 17 00:00:00 2001 From: OBattler Date: Mon, 20 Jul 2020 00:07:42 +0200 Subject: [PATCH 8/8] Switched MO to ftello64(). --- src/disk/mo.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/disk/mo.c b/src/disk/mo.c index 3841e103c..18f90c841 100644 --- a/src/disk/mo.c +++ b/src/disk/mo.c @@ -365,11 +365,11 @@ mo_load(mo_t *dev, wchar_t *fn) } fseek(dev->drv->f, 0, SEEK_END); - size = ftell(dev->drv->f); + size = (uint32_t) ftello64(dev->drv->f); if (is_mdi) { /* This is a MDI image. */ - size -= 0x1000; + size -= 0x1000LL; dev->drv->base = 0x1000; } @@ -1045,7 +1045,7 @@ mo_format(mo_t *dev) mo_log("MO %i: Formatting media...\n", dev->id); fseek(dev->drv->f, 0, SEEK_END); - size = ftell(dev->drv->f); + size = (uint32_t) ftello64(dev->drv->f); HANDLE fh; LARGE_INTEGER liSize;