From 70503973ebce871bf9cebe55c260af42df86179d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Sun, 26 Apr 2020 15:43:33 +0200 Subject: [PATCH] win: Add the new Media menu handler --- src/include/86box/plat.h | 2 + src/include/86box/win.h | 9 +++ src/win/win_cdrom.c | 52 +++++++++---- src/win/win_media_menu.c | 153 +++++++++++++++++++++++++++++++++++++++ src/win/win_new_floppy.c | 6 +- src/win/win_stbar.c | 2 +- 6 files changed, 206 insertions(+), 18 deletions(-) diff --git a/src/include/86box/plat.h b/src/include/86box/plat.h index 25e607e0b..8a892bf7b 100644 --- a/src/include/86box/plat.h +++ b/src/include/86box/plat.h @@ -121,8 +121,10 @@ extern void do_stop(void); /* Platform-specific device support. */ extern void plat_cdrom_ui_update(uint8_t id, uint8_t reload); extern void zip_eject(uint8_t id); +extern void zip_mount(uint8_t id, wchar_t *fn, uint8_t wp); extern void zip_reload(uint8_t id); extern void mo_eject(uint8_t id); +extern void mo_mount(uint8_t id, wchar_t *fn, uint8_t wp); extern void mo_reload(uint8_t id); extern int ioctl_open(uint8_t id, char d); extern void ioctl_reset(uint8_t id); diff --git a/src/include/86box/win.h b/src/include/86box/win.h index 2271a5803..abeffac80 100644 --- a/src/include/86box/win.h +++ b/src/include/86box/win.h @@ -186,6 +186,15 @@ extern int file_dlg_st(HWND hwnd, int i, char *fn, int save); extern wchar_t *BrowseFolder(wchar_t *saved_path, wchar_t *title); +/* Functions in win_media_menu.c */ +extern void media_menu_init(); +extern void media_menu_reset(); +extern void media_menu_update_floppy(int id); +extern void media_menu_update_cdrom(int id); +extern void media_menu_update_zip(int id); +extern void media_menu_update_mo(int id); + + #ifdef __cplusplus } #endif diff --git a/src/win/win_cdrom.c b/src/win/win_cdrom.c index 3a1eecf87..40bc44611 100644 --- a/src/win/win_cdrom.c +++ b/src/win/win_cdrom.c @@ -45,19 +45,39 @@ plat_cdrom_ui_update(uint8_t id, uint8_t reload) cdrom_t *drv = &cdrom[id]; if (drv->host_drive == 0) { - ui_sb_check_menu_item(SB_CDROM|id, IDM_CDROM_EMPTY | id, MF_CHECKED); - 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); - ui_sb_check_menu_item(SB_CDROM|id, IDM_CDROM_IMAGE | id, MF_CHECKED); ui_sb_update_icon_state(SB_CDROM|id, 0); } - ui_sb_enable_menu_item(SB_CDROM|id, IDM_CDROM_RELOAD | id, MF_BYCOMMAND | (reload ? MF_GRAYED : MF_ENABLED)); + media_menu_update_cdrom(id); ui_sb_update_tip(SB_CDROM|id); } +void +cdrom_mount(uint8_t id, wchar_t *fn) +{ + cdrom[id].prev_host_drive = cdrom[id].host_drive; + 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, sizeof(cdrom[id].image_path)); + cdrom_image_open(&(cdrom[id]), fn); + /* Signal media change to the emulated machine. */ + if (cdrom[id].insert) + cdrom[id].insert(cdrom[id].priv); + cdrom[id].host_drive = (wcslen(cdrom[id].image_path) == 0) ? 0 : 200; + if (cdrom[id].host_drive == 200) { + ui_sb_update_icon_state(SB_CDROM | id, 0); + } else { + ui_sb_update_icon_state(SB_CDROM | id, 1); + } + media_menu_update_cdrom(id); + ui_sb_update_tip(SB_CDROM | id); + config_save(); +} + void mo_eject(uint8_t id) { @@ -70,8 +90,7 @@ mo_eject(uint8_t id) } ui_sb_update_icon_state(SB_MO | id, 1); - ui_sb_enable_menu_item(SB_MO|id, IDM_MO_EJECT | id, MF_BYCOMMAND | MF_GRAYED); - ui_sb_enable_menu_item(SB_MO|id, IDM_MO_RELOAD | id, MF_BYCOMMAND | MF_ENABLED); + media_menu_update_mo(id); ui_sb_update_tip(SB_MO | id); config_save(); } @@ -87,6 +106,10 @@ mo_mount(uint8_t id, wchar_t *fn, uint8_t wp) mo_load(dev, fn); mo_insert(dev); + ui_sb_update_icon_state(SB_MO | id, wcslen(mo_drives[id].image_path) ? 0 : 1); + media_menu_update_mo(id); + ui_sb_update_tip(SB_MO | id); + config_save(); } @@ -98,14 +121,12 @@ mo_reload(uint8_t id) mo_disk_reload(dev); if (wcslen(mo_drives[id].image_path) == 0) { - ui_sb_enable_menu_item(SB_MO|id, IDM_MO_EJECT | id, MF_BYCOMMAND | MF_GRAYED); ui_sb_update_icon_state(SB_MO|id, 1); } else { - ui_sb_enable_menu_item(SB_MO|id, IDM_MO_EJECT | id, MF_BYCOMMAND | MF_ENABLED); ui_sb_update_icon_state(SB_MO|id, 0); } - ui_sb_enable_menu_item(SB_MO|id, IDM_MO_RELOAD | id, MF_BYCOMMAND | MF_GRAYED); + media_menu_update_mo(id); ui_sb_update_tip(SB_MO|id); config_save(); @@ -123,8 +144,7 @@ zip_eject(uint8_t id) } ui_sb_update_icon_state(SB_ZIP | id, 1); - ui_sb_enable_menu_item(SB_ZIP|id, IDM_ZIP_EJECT | id, MF_BYCOMMAND | MF_GRAYED); - ui_sb_enable_menu_item(SB_ZIP|id, IDM_ZIP_RELOAD | id, MF_BYCOMMAND | MF_ENABLED); + media_menu_update_zip(id); ui_sb_update_tip(SB_ZIP | id); config_save(); } @@ -140,6 +160,10 @@ zip_mount(uint8_t id, wchar_t *fn, uint8_t wp) zip_load(dev, fn); zip_insert(dev); + ui_sb_update_icon_state(SB_ZIP | id, wcslen(zip_drives[id].image_path) ? 0 : 1); + media_menu_update_zip(id); + ui_sb_update_tip(SB_ZIP | id); + config_save(); } @@ -151,14 +175,12 @@ zip_reload(uint8_t id) zip_disk_reload(dev); if (wcslen(zip_drives[id].image_path) == 0) { - ui_sb_enable_menu_item(SB_ZIP|id, IDM_ZIP_EJECT | id, MF_BYCOMMAND | MF_GRAYED); ui_sb_update_icon_state(SB_ZIP|id, 1); } else { - ui_sb_enable_menu_item(SB_ZIP|id, IDM_ZIP_EJECT | id, MF_BYCOMMAND | MF_ENABLED); ui_sb_update_icon_state(SB_ZIP|id, 0); } - ui_sb_enable_menu_item(SB_ZIP|id, IDM_ZIP_RELOAD | id, MF_BYCOMMAND | MF_GRAYED); + media_menu_update_zip(id); ui_sb_update_tip(SB_ZIP|id); config_save(); diff --git a/src/win/win_media_menu.c b/src/win/win_media_menu.c index 6250d42d7..02fee1497 100644 --- a/src/win/win_media_menu.c +++ b/src/win/win_media_menu.c @@ -14,6 +14,7 @@ #include <86box/scsi_device.h> #include <86box/mo.h> #include <86box/scsi.h> +#include <86box/ui.h> #include <86box/zip.h> #include <86box/win.h> @@ -274,6 +275,13 @@ fdd_mount(uint8_t id, wchar_t *fn, uint8_t wp) config_save(); } +static void +fdd_eject(uint8_t id) +{ + fdd_close(id); + config_save(); +} + static void cdrom_mount(uint8_t id, wchar_t *fn) { @@ -290,4 +298,149 @@ cdrom_mount(uint8_t id, wchar_t *fn) cdrom[id].host_drive = (wcslen(cdrom[id].image_path) == 0) ? 0 : 200; config_save(); +} + +int +media_menu_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + int id = 0, ret = 0, wp = 0; + WCHAR temp_path[1024]; + + id = LOWORD(wParam) & 0x00ff; + + switch (LOWORD(wParam) & 0xff00) { + case IDM_FLOPPY_IMAGE_NEW: + if (menus == NULL) + break; + + NewFloppyDialogCreate(hwnd, id, 0); + break; + + case IDM_FLOPPY_IMAGE_EXISTING_WP: + wp = 1; + /* FALLTHROUGH */ + case IDM_FLOPPY_IMAGE_EXISTING: + if (menus == NULL) + break; + + ret = file_dlg_w_st(hwnd, IDS_2118, floppyfns[id], 0); + if (! ret) { + fdd_mount(id, wopenfilestring, wp); + media_menu_update_floppy(id); + // TODO: status bar update + } + break; + + case IDM_FLOPPY_EJECT: + if (menus == NULL) + break; + + fdd_eject(id); + media_menu_update_floppy(id); + // TODO: status bar update + break; + + case IDM_FLOPPY_EXPORT_TO_86F: + if (menus == NULL) + break; + + ret = file_dlg_w_st(hwnd, IDS_2076, floppyfns[id], 1); + if (! ret) { + plat_pause(1); + ret = d86f_export(id, wopenfilestring); + if (!ret) + ui_msgbox(MBX_ERROR, (wchar_t *)IDS_4108); + plat_pause(0); + } + break; + + case IDM_CDROM_MUTE: + if (menus == NULL) + break; + + cdrom[id].sound_on ^= 1; + config_save(); + media_menu_update_cdrom(id); + // TODO: status bar update + sound_cd_thread_reset(); + break; + + case IDM_CDROM_EMPTY: + if (menus == NULL) + break; + + cdrom_eject(id); + break; + + case IDM_CDROM_RELOAD: + if (menus == NULL) + break; + + cdrom_reload(id); + break; + + case IDM_CDROM_IMAGE: + if (menus == NULL) + break; + + if (!file_dlg_w_st(hwnd, IDS_2075, cdrom[id].image_path, 0)) { + cdrom_mount(id, wopenfilestring); + media_menu_update_cdrom(id); + // TODO: status bar update + } + break; + + case IDM_ZIP_IMAGE_NEW: + NewFloppyDialogCreate(hwnd, id | 0x80, 0); /* NewZIPDialogCreate */ + break; + + case IDM_ZIP_IMAGE_EXISTING_WP: + wp = 1; + /* FALLTHROUGH */ + case IDM_ZIP_IMAGE_EXISTING: + if (menus == NULL) + break; + + ret = file_dlg_w_st(hwnd, IDS_2058, zip_drives[id].image_path, 0); + if (! ret) + zip_mount(id, wopenfilestring, wp); + break; + + case IDM_ZIP_EJECT: + zip_eject(id); + break; + + case IDM_ZIP_RELOAD: + zip_reload(id); + break; + + case IDM_MO_IMAGE_NEW: + NewFloppyDialogCreate(hwnd, id | 0x80, 0); /* NewZIPDialogCreate */ + break; + + case IDM_MO_IMAGE_EXISTING_WP: + wp = 1; + /* FALLTHROUGH */ + case IDM_MO_IMAGE_EXISTING: + if (menus == NULL) + break; + + ret = file_dlg_w_st(hwnd, IDS_2125, mo_drives[id].image_path, 0); + if (! ret) + mo_mount(id, wopenfilestring, wp); + break; + + case IDM_MO_EJECT: + mo_eject(id); + break; + + case IDM_MO_RELOAD: + mo_reload(id); + break; + + default: + return(0); + } + + return(1); } \ No newline at end of file diff --git a/src/win/win_new_floppy.c b/src/win/win_new_floppy.c index 1dd3aa2c1..78c51b497 100644 --- a/src/win/win_new_floppy.c +++ b/src/win/win_new_floppy.c @@ -601,9 +601,11 @@ NewFloppyDialogProcedure(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) } if (ret) { if (is_zip) - ui_sb_mount_zip_img(fdd_id, sb_part, 0, fd_file_name); + //ui_sb_mount_zip_img(fdd_id, sb_part, 0, fd_file_name); + zip_mount(fdd_id, fd_file_name, 0); else - ui_sb_mount_floppy_img(fdd_id, sb_part, 0, fd_file_name); + //ui_sb_mount_floppy_img(fdd_id, sb_part, 0, fd_file_name); + floppy_mount(fdd_id, fd_file_name, 0); } else { new_floppy_msgbox(hdlg, MBX_ERROR, (wchar_t *)IDS_4108); return TRUE; diff --git a/src/win/win_stbar.c b/src/win/win_stbar.c index bdbd13f87..9b2e36d68 100644 --- a/src/win/win_stbar.c +++ b/src/win/win_stbar.c @@ -1325,7 +1325,7 @@ StatusBarCreate(HWND hwndParent, uintptr_t idStatus, HINSTANCE hInst) SendMessage(hwndSBAR, SB_SETTEXT, 0 | SBT_NOBORDERS, (LPARAM)plat_get_string(IDS_2126)); - MediaMenuCreate(hwndParent, idStatus, hInst); + //MediaMenuCreate(hwndParent, idStatus, hInst); sb_ready = 1; }