A few fixes, CD-ROM ejecting/reloading should no longer cause heap problems because they now allocate prev_image_path with the correct length, and the status bar should now work after a hard reset with no config change.

This commit is contained in:
OBattler
2018-10-21 22:09:18 +02:00
parent c182b9f269
commit f088896a74
6 changed files with 29 additions and 17 deletions

View File

@@ -8,7 +8,7 @@
*
* Generic CD-ROM drive core.
*
* Version: @(#)cdrom.c 1.0.2 2018/10/17
* Version: @(#)cdrom.c 1.0.3 2018/10/21
*
* Author: Miran Grca, <mgrca8@gmail.com>
*
@@ -300,7 +300,7 @@ cdrom_eject(uint8_t id)
}
if (dev->host_drive == 200) {
dev->prev_image_path = (wchar_t *) malloc(1024);
dev->prev_image_path = (wchar_t *) malloc(1024 * sizeof(wchar_t));
wcscpy(dev->prev_image_path, dev->image_path);
}

View File

@@ -8,7 +8,7 @@
*
* CD-ROM image support.
*
* Version: @(#)cdrom_image.cc 1.0.5 2018/10/21
* Version: @(#)cdrom_image.cc 1.0.6 2018/10/21
*
* Author: RichardG867,
* Miran Grca, <mgrca8@gmail.com>
@@ -1084,6 +1084,7 @@ cdrom_image_open(cdrom_t *dev, const wchar_t *fn)
if (!img->SetDevice(temp, false)) {
cdrom_image_close(dev);
cdrom->ops = NULL;
cdrom->host_drive = 0;
cdrom_image_log("[f] image_open(): cdrom[%i]->ops = %08X\n", dev->id, dev->ops);
return 1;
}

View File

@@ -712,7 +712,7 @@ pc_send_cae(void)
void
pc_reset_hard_close(void)
{
ui_sb_set_not_ready();
ui_sb_set_ready(0);
suppress_overscan = 0;
@@ -822,7 +822,8 @@ pc_reset_hard_init(void)
config_save();
config_changed = 0;
}
} else
ui_sb_set_ready(1);
/* Needs the status bar... */
if (bugger_enabled)

View File

@@ -53,7 +53,7 @@ extern void ui_check_menu_item(int id, int checked);
extern wchar_t *ui_window_title(wchar_t *s);
extern void ui_status_update(void);
extern int ui_sb_find_part(int tag);
extern void ui_sb_set_not_ready(void);
extern void ui_sb_set_ready(int ready);
extern void ui_sb_update_panes(void);
extern void ui_sb_update_tip(int meaning);
extern void ui_sb_check_menu_item(int tag, int id, int chk);

View File

@@ -8,7 +8,7 @@
*
* Handle the platform-side of CDROM drives.
*
* Version: @(#)win_cdrom.c 1.0.10 2018/10/17
* Version: @(#)win_cdrom.c 1.0.11 2018/10/21
*
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
* Miran Grca, <mgrca8@gmail.com>
@@ -45,12 +45,10 @@ plat_cdrom_ui_update(uint8_t id, uint8_t reload)
if (drv->host_drive == 0) {
ui_sb_check_menu_item(SB_CDROM|id, IDM_CDROM_EMPTY | id, MF_CHECKED);
drv->host_drive = 0;
ui_sb_check_menu_item(SB_CDROM|id, IDM_CDROM_IMAGE | id, MF_UNCHECKED);
ui_sb_update_icon_state(SB_CDROM|id, 1);
} else {
ui_sb_check_menu_item(SB_CDROM|id, IDM_CDROM_EMPTY | id, MF_UNCHECKED);
drv->host_drive = 200;
ui_sb_check_menu_item(SB_CDROM|id, IDM_CDROM_IMAGE | id, MF_CHECKED);
ui_sb_update_icon_state(SB_CDROM|id, 0);
}

View File

@@ -470,9 +470,9 @@ StatusBarCreatePopupMenu(int part)
/* API: mark the status bar as not ready. */
void
ui_sb_set_not_ready(void)
ui_sb_set_ready(int ready)
{
sb_ready = 0;
sb_ready = ready;
}
@@ -486,8 +486,9 @@ ui_sb_update_panes(void)
int c_ide, c_scsi;
int do_net;
if (sb_ready)
if (sb_ready) {
sb_ready = 0;
}
hdint = (machines[machine].flags & MACHINE_HDC) ? 1 : 0;
c_mfm = hdd_count(HDD_BUS_MFM);
@@ -816,6 +817,9 @@ StatusBarProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
case IDM_FLOPPY_IMAGE_NEW:
id = item_params & 0x0003;
part = sb_map[SB_FLOPPY | id];
if ((part == 0xff) || (sb_menu_handles == NULL))
break;
NewFloppyDialogCreate(hwnd, id, part);
break;
@@ -875,11 +879,19 @@ StatusBarProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
case IDM_CDROM_EMPTY:
id = item_params & 0x0007;
part = sb_map[SB_CDROM | id];
if ((part == 0xff) || (sb_menu_handles == NULL))
break;
cdrom_eject(id);
break;
case IDM_CDROM_RELOAD:
id = item_params & 0x0007;
part = sb_map[SB_CDROM | id];
if ((part == 0xff) || (sb_menu_handles == NULL))
break;
cdrom_reload(id);
break;
@@ -887,30 +899,30 @@ StatusBarProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
id = item_params & 0x0007;
part = sb_map[SB_CDROM | id];
if ((part == 0xff) || (sb_menu_handles == NULL))
break;
break;
if (!file_dlg_w_st(hwnd, IDS_2075, cdrom[id].image_path, 0)) {
cdrom[id].prev_host_drive = cdrom[id].host_drive;
wcscpy(temp_path, wopenfilestring);
if (!cdrom[id].prev_image_path)
cdrom[id].prev_image_path = (wchar_t *) malloc(1024);
cdrom[id].prev_image_path = (wchar_t *) malloc(1024 * sizeof(wchar_t));
wcscpy(cdrom[id].prev_image_path, cdrom[id].image_path);
if (cdrom[id].ops && cdrom[id].ops->exit)
cdrom[id].ops->exit(&(cdrom[id]));
cdrom[id].ops = NULL;
memset(cdrom[id].image_path, 0, 2048);
memset(cdrom[id].image_path, 0, sizeof(cdrom[id].image_path));
cdrom_image_open(&(cdrom[id]), temp_path);
/* Signal media change to the emulated machine. */
if (cdrom[id].insert)
cdrom[id].insert(cdrom[id].p);
CheckMenuItem(sb_menu_handles[part], IDM_CDROM_EMPTY | id, MF_UNCHECKED);
cdrom[id].host_drive = (wcslen(cdrom[id].image_path) == 0) ? 0 : 200;
if (cdrom[id].host_drive == 200) {
CheckMenuItem(sb_menu_handles[part], IDM_CDROM_EMPTY | id, MF_UNCHECKED);
CheckMenuItem(sb_menu_handles[part], IDM_CDROM_IMAGE | id, MF_CHECKED);
ui_sb_update_icon_state(SB_CDROM | id, 0);
} else {
CheckMenuItem(sb_menu_handles[part], IDM_CDROM_IMAGE | id, MF_UNCHECKED);
CheckMenuItem(sb_menu_handles[part], IDM_CDROM_EMPTY | id, MF_UNCHECKED);
CheckMenuItem(sb_menu_handles[part], IDM_CDROM_EMPTY | id, MF_CHECKED);
ui_sb_update_icon_state(SB_CDROM | id, 1);
}
EnableMenuItem(sb_menu_handles[part], IDM_CDROM_RELOAD | id, MF_BYCOMMAND | MF_GRAYED);