From e3435eeb069d1c0df71edad5a2b759c7de4f1dcb Mon Sep 17 00:00:00 2001 From: "K.Ohta" Date: Wed, 1 Feb 2023 23:03:41 +0900 Subject: [PATCH] [UI][EMU][OSD][Qt][FLOPPY] Fix message routing. --- source/src/emu.cpp | 20 ++++++-- source/src/osdcall_types.h | 28 +++++------ source/src/qt/common/qt_utils.cpp | 42 +++++++++------- source/src/qt/common/util_fd2.cpp | 95 ++++++++++++++----------------------- source/src/qt/gui/emu_thread_tmpl.h | 2 + source/src/qt/gui/mainwidget_base.h | 1 + source/src/qt/gui/util_fd.cpp | 7 ++- source/src/qt/osd_base.cpp | 15 ++++++ source/src/qt/osd_base.h | 14 +----- 9 files changed, 113 insertions(+), 111 deletions(-) diff --git a/source/src/emu.cpp b/source/src/emu.cpp index f5db8fdc1..f64b37d6f 100644 --- a/source/src/emu.cpp +++ b/source/src/emu.cpp @@ -2368,12 +2368,16 @@ void EMU::update_media() #ifdef USE_FLOPPY_DISK for(int drv = 0; drv < USE_FLOPPY_DISK; drv++) { if(floppy_disk_status[drv].wait_count != 0 && --floppy_disk_status[drv].wait_count == 0) { - vm->open_floppy_disk(drv, floppy_disk_status[drv].path, floppy_disk_status[drv].bank); + vm->open_floppy_disk(drv, floppy_disk_status[drv].path, floppy_disk_status[drv].bank & 0x7f); #if USE_FLOPPY_DISK > 1 out_message(_T("FD%d: %s"), drv + BASE_FLOPPY_DISK_NUM, floppy_disk_status[drv].path); #else out_message(_T("FD: %s"), floppy_disk_status[drv].path); #endif + osd->string_message_from_emu(EMU_MEDIA_TYPE::FLOPPY_DISK | (floppy_disk_status[drv].bank & 0xff), + drv, + EMU_MESSAGE_TYPE::MEDIA_MOUNTED, + floppy_disk_status[drv].path); } } #endif @@ -2472,7 +2476,11 @@ void EMU::restore_media() #ifdef USE_FLOPPY_DISK for(int drv = 0; drv < USE_FLOPPY_DISK; drv++) { if(floppy_disk_status[drv].path[0] != _T('\0')) { - vm->open_floppy_disk(drv, floppy_disk_status[drv].path, floppy_disk_status[drv].bank); + vm->open_floppy_disk(drv, floppy_disk_status[drv].path, floppy_disk_status[drv].bank & 0x7f); + osd->string_message_from_emu(EMU_MEDIA_TYPE::FLOPPY_DISK | (floppy_disk_status[drv].bank & 0xff), + drv, + EMU_MESSAGE_TYPE::MEDIA_MOUNTED, + floppy_disk_status[drv].path); } } #endif @@ -2640,7 +2648,7 @@ void EMU::open_floppy_disk(int drv, const _TCHAR* file_path, int bank) d88_file[drv].bank_num++; } my_tcscpy_s(d88_file[drv].path, _MAX_PATH, file_path); - d88_file[drv].cur_bank = bank; + d88_file[drv].cur_bank = bank & 0x7f; } catch(...) { d88_file[drv].bank_num = 0; } @@ -2659,12 +2667,16 @@ void EMU::open_floppy_disk(int drv, const _TCHAR* file_path, int bank) out_message(_T("FD: Ejected")); #endif } else if(floppy_disk_status[drv].wait_count == 0) { - vm->open_floppy_disk(drv, file_path, bank); + vm->open_floppy_disk(drv, file_path, bank & 0x7f); #if USE_FLOPPY_DISK > 1 out_message(_T("FD%d: %s"), drv + BASE_FLOPPY_DISK_NUM, file_path); #else out_message(_T("FD: %s"), file_path); #endif + osd->string_message_from_emu(EMU_MEDIA_TYPE::FLOPPY_DISK | (bank & 0xff), + drv, + EMU_MESSAGE_TYPE::MEDIA_MOUNTED, + (_TCHAR *)file_path); } my_tcscpy_s(floppy_disk_status[drv].path, _MAX_PATH, file_path); floppy_disk_status[drv].bank = bank; diff --git a/source/src/osdcall_types.h b/source/src/osdcall_types.h index b5c951137..2303db00a 100644 --- a/source/src/osdcall_types.h +++ b/source/src/osdcall_types.h @@ -14,21 +14,21 @@ namespace EMU_MEDIA_TYPE { typedef uint64_t type_t ; enum { - NONE, - BINARY, - BUBBLE_CASETTE, - CARTRIDGE, - COMPACT_DISC, - FLOPPY_DISK, - HARD_DISK, - LASER_DISC, - QUICK_DISK, - TAPE, + NONE = 0 << 16, + BINARY = 1 << 16, + BUBBLE_CASETTE = 2 << 16, + CARTRIDGE = 3 << 16, + COMPACT_DISC = 4 << 16, + FLOPPY_DISK = 5 << 16, + HARD_DISK = 6 << 16, + LASER_DISC = 7 << 16, + QUICK_DISK = 8 << 16, + TAPE = 9 << 16, - AUDIO, - VIDEO, - ANY_MEDIA, - END + AUDIO = (1 << 18) + (30 << 16), + VIDEO = (2 << 18) + (30 << 16), + ANY_MEDIA = (7 << 18) + (30 << 16), + END = UINT64_MAX }; } diff --git a/source/src/qt/common/qt_utils.cpp b/source/src/qt/common/qt_utils.cpp index 6cd2d23f4..4accaf5db 100644 --- a/source/src/qt/common/qt_utils.cpp +++ b/source/src/qt/common/qt_utils.cpp @@ -117,6 +117,9 @@ void Ui_MainWindow::LaunchEmuThread(EmuThreadClassBase *m) int drvs; hRunEmu = m; + if(hRunEmu == nullptr) return; + OSD_BASE* p_osd = hRunEmu->get_emu()->get_osd(); + connect(hRunEmu, SIGNAL(message_changed(QString)), this, SLOT(message_status_bar(QString)), Qt::QueuedConnection); connect(hRunEmu, SIGNAL(sig_is_enable_mouse(bool)), this, SLOT(do_set_mouse_enable(bool))); connect(glv, SIGNAL(sig_key_down(uint32_t, uint32_t, bool)), hRunEmu, SLOT(do_key_down(uint32_t, uint32_t, bool))); @@ -162,6 +165,10 @@ void Ui_MainWindow::LaunchEmuThread(EmuThreadClassBase *m) connect(this, SIGNAL(sig_close_disk(int)), hRunEmu, SLOT(do_close_disk(int))); connect(hRunEmu, SIGNAL(sig_update_recent_disk(int)), this, SLOT(do_update_recent_disk(int))); //connect(hRunEmu, SIGNAL(sig_change_osd_fd(int, QString)), this, SLOT(do_change_osd_fd(int, QString))); + connect(p_osd, SIGNAL(sig_ui_floppy_insert_history(int, QString, quint64)), + this, SLOT(do_ui_floppy_insert_history(int, QString, quint64)), + Qt::QueuedConnection); + drvs = USE_FLOPPY_DISK; for(int ii = 0; ii < drvs; ii++) { menu_fds[ii]->setEmu(emu); @@ -473,7 +480,7 @@ void Ui_MainWindow::OnMainWindowClosed(void) delete hDrawEmu; hDrawEmu = nullptr; } - if(hRunEmu != NULL) { + if(hRunEmu != nullptr) { OnCloseDebugger(); OSD* op = (OSD*)(emu->get_osd()); if(op != nullptr) { @@ -511,7 +518,7 @@ void Ui_MainWindow::OnMainWindowClosed(void) } #endif do_release_emu_resources(); - hRunEmu = NULL; + hRunEmu = nullptr; return; } @@ -1296,41 +1303,42 @@ int MainLoop(int argc, char *argv[]) rMainWindow->getWindow()->show(); rMainWindow->retranselateUi_Depended_OSD(); // QMetaObject::connectSlotsByName(rMainWindow); - EmuThreadClass *hRunEmu = new EmuThreadClass(rMainWindow, using_flags); - - QObject::connect((OSD*)(emu->get_osd()), SIGNAL(sig_update_device_node_name(int, const _TCHAR *)), + EmuThreadClass *hRunEmu_Real = new EmuThreadClass(rMainWindow, using_flags); + OSD_BASE* p_osd = hRunEmu_Real->get_emu()->get_osd(); + + QObject::connect((OSD*)p_osd, SIGNAL(sig_update_device_node_name(int, const _TCHAR *)), rMainWindow, SLOT(do_update_device_node_name(int, const _TCHAR *))); for(int i = 0; i < (CSP_LOG_TYPE_VM_DEVICE_END - CSP_LOG_TYPE_VM_DEVICE_0 + 1); i++) { rMainWindow->do_update_device_node_name(i, using_flags->get_vm_node_name(i)); } - p_logger->set_osd((OSD*)(emu->get_osd())); + p_logger->set_osd((OSD*)p_osd); p_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "InitInstance() OK."); // ToDo: Update raltime. - rMainWindow->connect(rMainWindow, SIGNAL(sig_osd_sound_output_device(QString)), (OSD*)(emu->get_osd()), SLOT(do_set_host_sound_output_device(QString))); + rMainWindow->connect(rMainWindow, SIGNAL(sig_osd_sound_output_device(QString)), (OSD*)p_osd, SLOT(do_set_host_sound_output_device(QString))); rMainWindow->do_update_sound_output_list(); - QObject::connect((OSD*)(emu->get_osd()), SIGNAL(sig_update_sound_output_list()), rMainWindow, SLOT(do_update_sound_output_list())); - QObject::connect((OSD*)(emu->get_osd()), SIGNAL(sig_clear_sound_output_list()), rMainWindow, SLOT(do_clear_sound_output_list())); - QObject::connect((OSD*)(emu->get_osd()), SIGNAL(sig_append_sound_output_list(QString)), rMainWindow, SLOT(do_append_sound_output_list(QString))); + QObject::connect((OSD*)p_osd, SIGNAL(sig_update_sound_output_list()), rMainWindow, SLOT(do_update_sound_output_list())); + QObject::connect((OSD*)p_osd, SIGNAL(sig_clear_sound_output_list()), rMainWindow, SLOT(do_clear_sound_output_list())); + QObject::connect((OSD*)p_osd, SIGNAL(sig_append_sound_output_list(QString)), rMainWindow, SLOT(do_append_sound_output_list(QString))); - QObject::connect(rMainWindow, SIGNAL(sig_update_master_volume(int)), (OSD*)(emu->get_osd()), SLOT(do_update_master_volume(int))); + QObject::connect(rMainWindow, SIGNAL(sig_update_master_volume(int)), (OSD*)p_osd, SLOT(do_update_master_volume(int))); QObject::connect(GuiMain, SIGNAL(lastWindowClosed()), rMainWindow, SLOT(on_actionExit_triggered())); - QObject::connect((OSD*)(emu->get_osd()), SIGNAL(sig_clear_keyname_table()), rMainWindow, SLOT(do_clear_keyname_table())); - QObject::connect((OSD*)(emu->get_osd()), SIGNAL(sig_add_keyname_table(uint32_t, QString)), rMainWindow, SLOT(do_add_keyname_table(uint32_t, QString))); - emu->get_osd()->update_keyname_table(); + QObject::connect((OSD*)p_osd, SIGNAL(sig_clear_keyname_table()), rMainWindow, SLOT(do_clear_keyname_table())); + QObject::connect((OSD*)p_osd, SIGNAL(sig_add_keyname_table(uint32_t, QString)), rMainWindow, SLOT(do_add_keyname_table(uint32_t, QString))); + p_osd->update_keyname_table(); - QObject::connect(rMainWindow, SIGNAL(sig_notify_power_off()), hRunEmu, SLOT(do_notify_power_off()), Qt::QueuedConnection); + QObject::connect(rMainWindow, SIGNAL(sig_notify_power_off()), hRunEmu_Real, SLOT(do_notify_power_off()), Qt::QueuedConnection); GLDrawClass *pgl = rMainWindow->getGraphicsView(); pgl->do_set_texture_size(NULL, -1, -1); // It's very ugly workaround (;_;) 20191028 K.Ohta // pgl->setFixedSize(pgl->width(), pgl->height()); // main loop - rMainWindow->LaunchEmuThread(hRunEmu); - + rMainWindow->LaunchEmuThread(hRunEmu_Real); + #if defined(USE_JOYSTICK) rMainWindow->LaunchJoyThread(); #endif diff --git a/source/src/qt/common/util_fd2.cpp b/source/src/qt/common/util_fd2.cpp index 2bb0cc04a..f2f5cadce 100644 --- a/source/src/qt/common/util_fd2.cpp +++ b/source/src/qt/common/util_fd2.cpp @@ -68,43 +68,41 @@ extern const _TCHAR* DLL_PREFIX_I get_parent_dir(const _TCHAR* file); int Ui_MainWindowBase::set_recent_disk(int drv, int num) { QString s_path; - char path_shadow[PATH_MAX]; + + if(using_flags->get_max_drive() <= drv) return -1; if((num < 0) || (num >= MAX_HISTORY)) return -1; s_path = QString::fromLocal8Bit(p_config->recent_floppy_disk_path[drv][num]); - strncpy(path_shadow, s_path.toLocal8Bit().constData(), PATH_MAX - 1); - UPDATE_HISTORY(path_shadow, p_config->recent_floppy_disk_path[drv], listFDs[drv]); - - strncpy(p_config->initial_floppy_disk_dir, get_parent_dir((const _TCHAR *)path_shadow), _MAX_PATH - 1); - strncpy(path_shadow, s_path.toLocal8Bit().constData(), PATH_MAX - 1); - -// if(emu) { - emit sig_close_disk(drv); - emit sig_open_disk(drv, s_path, 0); - menu_fds[drv]->do_update_histories(listFDs[drv]); + if(!(s_path.isEmpty())) { + _open_disk(drv, s_path); + return 0; + } + return -1; +} + +void Ui_MainWindowBase::do_ui_floppy_insert_history(int drv, QString fname, quint64 bank) +{ + if(fname.length() <= 0) return; + if(using_flags->get_max_drive() <= drv) return; + + _TCHAR path_shadow[_MAX_PATH] = {0}; + strncpy(path_shadow, fname.toLocal8Bit().constData(), _MAX_PATH - 1); + if(!(FILEIO::IsFileExisting(path_shadow))) return; + + if((bank & 0x80) == 0) { + UPDATE_HISTORY(path_shadow, p_config->recent_floppy_disk_path[drv], listFDs[drv]); + strcpy(p_config->initial_floppy_disk_dir, get_parent_dir((const _TCHAR *)path_shadow)); + // Update List + strncpy(path_shadow, fname.toLocal8Bit().constData(), _MAX_PATH - 1); menu_fds[drv]->do_set_initialize_directory(p_config->initial_floppy_disk_dir); - if(check_file_extension(path_shadow, ".d88") || check_file_extension(path_shadow, ".d77")) { - UPDATE_D88_LIST(drv, listD88[drv]); - menu_fds[drv]->do_update_inner_media(listD88[drv], 0); - } else { - menu_fds[drv]->do_clear_inner_media(); - } - if(using_flags->get_max_drive() >= 2) { - strncpy(path_shadow, s_path.toLocal8Bit().constData(), PATH_MAX - 1); - if(check_file_extension(path_shadow, ".d88") || check_file_extension(path_shadow, ".d77")) { - if(((drv & 1) == 0) && ((drv + 1) < using_flags->get_max_drive()) && (1 < hRunEmu->get_d88_file_bank_num(drv))) { - - int drv2 = drv + 1; - emit sig_close_disk(drv2); - emit sig_open_disk(drv2, s_path, 1); - menu_fds[drv2]->do_update_histories(listFDs[drv2]); - menu_fds[drv2]->do_set_initialize_directory(p_config->initial_floppy_disk_dir); - UPDATE_D88_LIST(drv2, listD88[drv2]); - menu_fds[drv2]->do_update_inner_media(listD88[drv2], 1); - } - } - } -// } - return 0; + } + do_update_floppy_history(drv, listFDs[drv]); + + if(check_file_extension(path_shadow, ".d88") || check_file_extension(path_shadow, ".d77")) { + UPDATE_D88_LIST(drv, listD88[drv]); + menu_fds[drv]->do_update_inner_media(listD88[drv], bank & 0x7f); + } else { + menu_fds[drv]->do_clear_inner_media(); + } } void Ui_MainWindowBase::_open_disk(int drv, const QString fname) @@ -116,35 +114,15 @@ void Ui_MainWindowBase::_open_disk(int drv, const QString fname) if(!(FILEIO::IsFileExisting(fname.toLocal8Bit().constData()))) return; // File not found. // drv = drv & 7; strncpy(path_shadow, fname.toLocal8Bit().constData(), PATH_MAX - 1); - - UPDATE_HISTORY(path_shadow, p_config->recent_floppy_disk_path[drv], listFDs[drv]); - strcpy(p_config->initial_floppy_disk_dir, get_parent_dir((const _TCHAR *)path_shadow)); - // Update List - strncpy(path_shadow, fname.toLocal8Bit().constData(), PATH_MAX - 1); - -// if(emu) { - emit sig_close_disk(drv); - emit sig_open_disk(drv, fname, 0); - menu_fds[drv]->do_update_histories(listFDs[drv]); - menu_fds[drv]->do_set_initialize_directory(p_config->initial_floppy_disk_dir); - if(check_file_extension(path_shadow, ".d88") || check_file_extension(path_shadow, ".d77")) { - UPDATE_D88_LIST(drv, listD88[drv]); - menu_fds[drv]->do_update_inner_media(listD88[drv], 0); - } else { - menu_fds[drv]->do_clear_inner_media(); - } -// } + emit sig_close_disk(drv); + emit sig_open_disk(drv, fname, 0); + if(using_flags->get_max_drive() > (drv + 1)) { if(check_file_extension(path_shadow, ".d88") || check_file_extension(path_shadow, ".d77")) { if(((drv & 1) == 0) && (drv + 1 < using_flags->get_max_drive()) && (1 < hRunEmu->get_d88_file_bank_num(drv))) { int drv2 = drv + 1; emit sig_close_disk(drv2); - strncpy(path_shadow, fname.toLocal8Bit().constData(), PATH_MAX - 1); - emit sig_open_disk(drv2, fname, 1); - menu_fds[drv2]->do_update_histories(listFDs[drv2]); - menu_fds[drv2]->do_set_initialize_directory(p_config->initial_floppy_disk_dir); - UPDATE_D88_LIST(drv2, listD88[drv2]); - menu_fds[drv2]->do_update_inner_media(listD88[drv2], 1); + emit sig_open_disk(drv2, fname, 1 + 128); } } } @@ -156,5 +134,4 @@ void Ui_MainWindowBase::do_update_d88_list(int drv, int bank) UPDATE_D88_LIST(drv, listD88[drv]); menu_fds[drv]->do_update_inner_media(listD88[drv], bank); } - //#endif diff --git a/source/src/qt/gui/emu_thread_tmpl.h b/source/src/qt/gui/emu_thread_tmpl.h index 1bbba60fd..db8034a50 100644 --- a/source/src/qt/gui/emu_thread_tmpl.h +++ b/source/src/qt/gui/emu_thread_tmpl.h @@ -259,6 +259,8 @@ public: void sample_access_drv(void); bool now_debugging(); + EMU_TEMPLATE *get_emu() { return p_emu; } + int get_d88_file_cur_bank(int drive); int get_d88_file_bank_num(int drive); QString get_d88_file_disk_name(int drive, int banknum); diff --git a/source/src/qt/gui/mainwidget_base.h b/source/src/qt/gui/mainwidget_base.h index 091116f72..40120735b 100644 --- a/source/src/qt/gui/mainwidget_base.h +++ b/source/src/qt/gui/mainwidget_base.h @@ -908,6 +908,7 @@ public slots: void do_update_floppy_history(int drive, QStringList lst); void do_insert_floppy_history(int drive, QString path); + void do_ui_floppy_insert_history(int drv, QString fname, quint64 bank); void do_set_emulate_cursor_as(void); void do_set_logging_fdc(bool onoff); diff --git a/source/src/qt/gui/util_fd.cpp b/source/src/qt/gui/util_fd.cpp index 4eaca34f1..a3d16b574 100644 --- a/source/src/qt/gui/util_fd.cpp +++ b/source/src/qt/gui/util_fd.cpp @@ -92,10 +92,9 @@ void Ui_MainWindowBase::ConfigFloppyMenu(void) void Ui_MainWindowBase::do_update_floppy_history(int drive, QStringList lst) { - if((drive < 0) || (drive >= using_flags->get_max_drive())) { - if(menu_fds[drive] != nullptr) { - menu_fds[drive]->do_update_histories(lst); - } + if((drive < 0) || (drive >= using_flags->get_max_drive())) return; + if(menu_fds[drive] != nullptr) { + menu_fds[drive]->do_update_histories(lst); } } diff --git a/source/src/qt/osd_base.cpp b/source/src/qt/osd_base.cpp index 9812fb1eb..41d2c7589 100644 --- a/source/src/qt/osd_base.cpp +++ b/source/src/qt/osd_base.cpp @@ -676,6 +676,21 @@ void OSD_BASE::string_message_from_emu(EMU_MEDIA_TYPE::type_t media_type, int dr // switch(media_type) { // case EMU_MEDIA_TYPE::BINARY: // } + QString tmps; + uint64_t _type = media_type & (31 << 16); + uint64_t _slot = media_type & 255; + switch(_type) { + case EMU_MEDIA_TYPE::FLOPPY_DISK : + if(message != nullptr) { + tmps = QString::fromLocal8Bit(message); + } + switch(message_type) { + case EMU_MESSAGE_TYPE::MEDIA_MOUNTED : + emit sig_ui_floppy_insert_history(drive, tmps, _slot); + break; + } + break; + } } void OSD_BASE::int_message_from_emu(EMU_MEDIA_TYPE::type_t media_type, int drive, EMU_MESSAGE_TYPE::type_t message_type, int64_t data) diff --git a/source/src/qt/osd_base.h b/source/src/qt/osd_base.h index a5040a615..81425773a 100644 --- a/source/src/qt/osd_base.h +++ b/source/src/qt/osd_base.h @@ -769,19 +769,7 @@ signals: int sig_notify_power_off(void); // To GUI 20230120 K.O // To GUI 20230125 K.O - int sig_notify_opened_virtual_media(int type, int drive, QString path); - int sig_notify_closed_virtual_media(int type, int drive); - int sig_notify_update_virtual_media_list(int type, int drive, QStringList names); - - int sig_notify_error_virtual_media(int type, int drive, int64_t status); - int sig_notify_select_d88(int drive, int cur_bank); - int sig_notify_update_d88_list(int drive, int bank_num, QStringList names); - int sig_notify_clear_d88_list(int drive, int cur_bank); - - int sig_notify_select_b77(int drive, int cur_bank); - int sig_notify_update_b77_list(int drive, int bank_num, QStringList names); - int sig_notify_clear_b77_list(int drive, int cur_bank); - + int sig_ui_floppy_insert_history(int, QString, quint64); }; QT_END_NAMESPACE -- 2.11.0