2 Skelton for retropc emulator
4 Author : K.Ohta <whatisthis.sowhat _at_ gmail.com>
21 #include <QElapsedTimer>
31 #include <QOpenGLContext>
32 #include <QtMultimedia>
34 #include "simd_types.h"
39 #include "../config.h"
40 #include "../fileio.h"
42 #include "../vm/device.h"
45 //#include "qt_main.h"
46 //#include "csp_logger.h"
48 #include "gui/dock_disks.h"
49 #include "../vm/vm_template.h"
51 #include "./osd_sound_mod_qtmultimedia.h"
53 OSD_BASE::OSD_BASE(std::shared_ptr<USING_FLAGS> p, std::shared_ptr<CSP_Logger> logger) : QObject(0)
57 #if 0 /* Note: Below are new sound driver. */
58 #if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)
59 m_audioOutputDevice = QMediaDevices::defaultAudioOutput();
60 m_audioInputDevice = QMediaDevices::defaultAudioInput();
61 //m_audioOutputSink = std::shared_ptr<QAudioSink>(new QAudioSink(m_audioOutputDevice, m_audioOutputDevice.preferredFormat()));
62 m_audioOutputSink.reset(new QAudioSink(m_audioOutputDevice, m_audioOutputDevice.preferredFormat()));
63 #elif QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
64 m_audioOutputDevice = QAudioDeviceInfo::defaultOutputDevice();
65 m_audioInputDevice = QAudioDeviceInfo::defaultInputDevice();
67 m_audioOutputSink.reset(new QAudioOutput(m_audioOutputDevice, m_audioOutputDevice.preferredFormat()));
69 m_audioInputSource.reset();
70 //m_audioOutputSink->moveToThread(this->thread());
71 m_audioOutput = nullptr;
72 m_audioInput = nullptr;
73 sound_initialized = false;
74 sound_us_before_rendered = 0;
75 #endif /* END Note: */
76 device_node_list.clear();
81 SupportedFeatures.clear();
82 midi_receivers.clear();
84 sio_receivers.clear();
87 is_glcontext_shared = false;
90 #if 1 /* Note: Below are new sound driver. */
92 new SOUND_OUTPUT_MODULE::M_QT_MULTIMEDIA(this,
100 #endif /* END Note: */
101 get_sound_device_list();
104 OSD_BASE::~OSD_BASE()
106 if(log_mutex.try_lock_for(std::chrono::milliseconds(100))) {
107 p_logger->set_osd(NULL);
112 extern std::string cpp_homedir;
113 extern std::string my_procname;
115 const _TCHAR *OSD_BASE::get_lib_osd_version()
117 const _TCHAR *p = (const _TCHAR *)"\0";
118 #if defined(__LIBOSD_VERSION)
119 return (const _TCHAR *)__LIBOSD_VERSION;
124 QOpenGLContext *OSD_BASE::get_gl_context()
126 if(glContext == NULL) return NULL;
127 if(!(glContext->isValid())) return NULL;
131 EmuThreadClass *OSD_BASE::get_parent_handler()
133 return parent_thread;
136 void OSD_BASE::set_parent_thread(EmuThreadClass *parent)
138 parent_thread = parent;
141 void OSD_BASE::initialize(int rate, int samples, int* presented_rate, int* presented_samples)
145 void OSD_BASE::release()
149 void OSD_BASE::suspend()
151 if(get_use_movie_player()) {
152 if(now_movie_play && !now_movie_pause) {
154 now_movie_pause = false;
160 void OSD_BASE::restore()
162 if(get_use_movie_player()) {
163 if(now_movie_play && !now_movie_pause) {
170 void OSD_BASE::debug_log(int level, const char *fmt, ...)
176 vsnprintf(strbuf, 4095, fmt, ap);
177 debug_log(level, 0, strbuf);
181 void OSD_BASE::debug_log(int level, int domain_num, const char *fmt, ...)
187 vsnprintf(strbuf, 4095, fmt, ap);
188 debug_log(level, domain_num, strbuf);
192 _TCHAR *OSD_BASE::get_app_path(void)
197 _TCHAR* OSD_BASE::bios_path(const _TCHAR* file_name)
199 static _TCHAR file_path[_MAX_PATH];
200 snprintf((char *)file_path, _MAX_PATH, "%s%s", app_path, (const char *)file_name);
201 debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_OSD, "BIOS PATH:%s", file_path);
205 void OSD_BASE::get_host_time(cur_time_t* time)
208 //GetLocalTime(&sTime);
209 QDateTime nowTime = QDateTime::currentDateTime();
210 QDate d = nowTime.date();
211 QTime t = nowTime.time();
213 time->year = d.year();
214 time->month = d.month();
216 time->day_of_week = d.dayOfWeek();
217 time->hour = t.hour();
218 time->minute = t.minute();
219 time->second = t.second();
222 void OSD_BASE::sleep(uint32_t ms)
227 void OSD_BASE::create_date_file_name(_TCHAR *name, int length, const _TCHAR *extension)
229 QDateTime nowTime = QDateTime::currentDateTime();
230 QString tmps = QString::fromUtf8("emu");
231 tmps = tmps + get_vm_config_name();
232 tmps = tmps + QString::fromUtf8("_");
233 tmps = tmps + nowTime.toString(QString::fromUtf8("yyyy-MM-dd_hh-mm-ss.zzz."));
234 tmps = tmps + QString::fromUtf8((const char *)extension);
235 snprintf((char *)name, length, "%s", tmps.toLocal8Bit().constData());
238 _TCHAR* OSD_BASE::application_path()
244 bool OSD_BASE::get_use_socket(void)
249 bool OSD_BASE::get_use_auto_key(void)
254 bool OSD_BASE::get_dont_keeep_key_pressed(void)
259 bool OSD_BASE::get_one_board_micro_computer(void)
264 bool OSD_BASE::get_use_screen_rotate(void)
269 bool OSD_BASE::get_use_movie_player(void)
274 bool OSD_BASE::get_use_video_capture(void)
280 void OSD_BASE::vm_key_down(int code, bool flag)
282 std::lock_guard<std::recursive_timed_mutex> lv(vm_mutex);
285 vm->key_down(code, flag);
289 void OSD_BASE::vm_key_up(int code)
291 std::lock_guard<std::recursive_timed_mutex> lv(vm_mutex);
298 void OSD_BASE::vm_reset(void)
300 std::lock_guard<std::recursive_timed_mutex> lv(vm_mutex);
307 int OSD_BASE::get_vm_buttons_code(int num)
312 QString OSD_BASE::get_vm_config_name(void)
314 return QString::fromUtf8(" ");
317 int OSD_BASE::get_screen_width(void)
322 int OSD_BASE::get_screen_height(void)
327 void OSD_BASE::lock_vm(void)
333 void OSD_BASE::unlock_vm(void)
340 bool OSD_BASE::is_vm_locked(void)
345 void OSD_BASE::force_unlock_vm(void)
351 void OSD_BASE::set_draw_thread(DrawThreadClass *handler)
355 void OSD_BASE::initialize_screen()
357 first_draw_screen = false;
358 first_invalidate = true;
359 self_invalidate = false;
362 void OSD_BASE::release_screen()
366 int OSD_BASE::get_window_mode_width(int mode)
371 int OSD_BASE::get_window_mode_height(int mode)
376 double OSD_BASE::get_window_mode_power(int mode)
380 } else if(mode + 1 > 2) {
386 void OSD_BASE::reset_vm_node(void)
389 device_node_list.clear();
394 void OSD_BASE::debug_log(int level, int domain_num, char *strbuf)
396 p_logger->debug_log(level, domain_num, strbuf);
400 void OSD_BASE::set_device_name(int id, char *name)
402 p_logger->set_device_name(id, (char *)name);
405 void OSD_BASE::set_vm_node(int id, const _TCHAR *name)
409 for(i = 0; i < device_node_list.size(); i++) {
410 sp = device_node_list.at(i);
414 set_device_name(id, (char *)name);
415 device_node_list.replace(i, sp);
416 if(id >= max_vm_nodes) max_vm_nodes = id + 1;
423 set_device_name(id, (char *)name);
424 device_node_list.append(sp);
425 if(id >= max_vm_nodes) max_vm_nodes = id + 1;
428 const _TCHAR *OSD_BASE::get_vm_node_name(int id)
432 for(i = 0; i < device_node_list.size(); i++) {
433 sp = device_node_list.at(i);
441 int OSD_BASE::get_vm_node_size(void)
447 void OSD_BASE::add_feature(const _TCHAR *key, double value)
451 tmps = QString::fromUtf8(key);
452 if(!check_feature(key)) {
455 SupportedFeatures.append(l);
459 void OSD_BASE::add_feature(const _TCHAR *key, int64_t value)
463 tmps = QString::fromUtf8(key);
464 if(!check_feature(key)) {
467 SupportedFeatures.append(l);
471 void OSD_BASE::add_feature(const _TCHAR *key, uint64_t value)
475 tmps = QString::fromUtf8(key);
476 if(!check_feature(key)) {
479 SupportedFeatures.append(l);
483 void OSD_BASE::add_feature(const _TCHAR *key, float value)
485 add_feature(key, (double)value);
488 void OSD_BASE::add_feature(const _TCHAR *key, int value)
490 add_feature(key, (int64_t)value);
494 void OSD_BASE::add_feature(const _TCHAR *key, int16_t value)
496 add_feature(key, (int64_t)value);
499 void OSD_BASE::add_feature(const _TCHAR *key, int8_t value)
501 add_feature(key, (int64_t)value);
504 void OSD_BASE::add_feature(const _TCHAR *key, uint32_t value)
506 add_feature(key, (uint64_t)(value & 0xffffffff));
509 void OSD_BASE::add_feature(const _TCHAR *key, uint16_t value)
511 add_feature(key, (uint64_t)(value & 0xffff));
514 void OSD_BASE::add_feature(const _TCHAR *key, uint8_t value)
516 add_feature(key, (uint64_t)(value & 0xff));
520 bool OSD_BASE::check_feature(const _TCHAR *key)
524 tmps = QString::fromUtf8(key);
525 for(int i = 0; i < SupportedFeatures.size(); i++) {
526 l = SupportedFeatures.at(i);
527 if(l.string == tmps) {
534 double OSD_BASE::get_feature_double_value(const _TCHAR *key)
538 tmps = QString::fromUtf8(key);
539 for(int i = 0; i < SupportedFeatures.size(); i++) {
540 l = SupportedFeatures.at(i);
541 if(l.string == tmps) {
545 return std::numeric_limits<double>::quiet_NaN(); // You don't use (0.0 / 0.0).
548 int64_t OSD_BASE::get_feature_int64_value(const _TCHAR *key)
552 tmps = QString::fromUtf8(key);
553 for(int i = 0; i < SupportedFeatures.size(); i++) {
554 l = SupportedFeatures.at(i);
555 if(l.string == tmps) {
562 int OSD_BASE::get_feature_int_value(const _TCHAR *key)
564 return (int)get_feature_int64_value(key);
567 int32_t OSD_BASE::get_feature_int32_value(const _TCHAR *key)
569 return (int32_t)get_feature_int64_value(key);
572 int16_t OSD_BASE::get_feature_int16_value(const _TCHAR *key)
574 return (int16_t)get_feature_int64_value(key);
577 int8_t OSD_BASE::get_feature_int8_value(const _TCHAR *key)
579 return (int8_t)get_feature_int64_value(key);
583 uint64_t OSD_BASE::get_feature_uint64_value(const _TCHAR *key)
587 tmps = QString::fromUtf8(key);
588 for(int i = 0; i < SupportedFeatures.size(); i++) {
589 l = SupportedFeatures.at(i);
590 if(l.string == tmps) {
597 uint32_t OSD_BASE::get_feature_uint32_value(const _TCHAR *key)
599 return (uint32_t)(get_feature_uint64_value(key) & 0xffffffff);
602 uint16_t OSD_BASE::get_feature_uint16_value(const _TCHAR *key)
604 return (uint16_t)(get_feature_uint64_value(key) & 0xffff);
607 uint8_t OSD_BASE::get_feature_uint8_value(const _TCHAR *key)
609 return (uint8_t)(get_feature_uint64_value(key) & 0xff);
612 void OSD_BASE::start_waiting_in_debugger()
614 // ToDo: Wait for rising up debugger window.
618 void OSD_BASE::finish_waiting_in_debugger()
620 // ToDo: Wait for closing up debugger window.
621 debug_mutex.unlock();
624 void OSD_BASE::process_waiting_in_debugger()
626 // ToDo: Check sequence
630 void OSD_BASE::set_dbg_completion_list(std::list<std::string> *p)
633 emit sig_clear_dbg_completion_list();
634 for(auto n = p->begin(); n != p->end(); ++n) {
635 emit sig_add_dbg_completion_list((_TCHAR *)((*n).c_str()));
637 emit sig_apply_dbg_completion_list();
641 void OSD_BASE::clear_dbg_completion_list(void)
643 emit sig_clear_dbg_completion_list();
644 emit sig_apply_dbg_completion_list();
647 // Belows are API for GUI STATUS BAR.
648 void OSD_BASE::set_hdd_image_name(int drv, _TCHAR *filename)
650 QString _n = QString::fromLocal8Bit(filename);
651 emit sig_change_virtual_media(CSP_DockDisks_Domain_HD, drv, _n);
654 // Moved from OSD_WRAPPER.
655 const _TCHAR *OSD_BASE::get_lib_common_vm_version()
657 return (const _TCHAR *)"\0";
660 const _TCHAR *OSD_BASE::get_lib_common_vm_git_version()
662 std::lock_guard<std::recursive_timed_mutex> lv(vm_mutex);
664 return vm->get_vm_git_version();
669 void OSD_BASE::vm_draw_screen(void)
674 double OSD_BASE::vm_frame_rate(void)
676 std::lock_guard<std::recursive_timed_mutex> lv(vm_mutex);
678 return vm->get_frame_rate();
681 Sint16* OSD_BASE::create_sound(int *extra_frames)
683 std::lock_guard<std::recursive_timed_mutex> lv(vm_mutex);
685 return (Sint16 *)vm->create_sound(extra_frames);