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"
40 #include "../config.h"
41 #include "../fileio.h"
43 #include "../vm/device.h"
48 #include "gui/dock_disks.h"
49 #include "gui/menu_flags.h"
51 #include "../vm/vm_template.h"
53 OSD_BASE::OSD_BASE(std::shared_ptr<USING_FLAGS> p, std::shared_ptr<CSP_Logger> logger) : QObject(0)
57 device_node_list.clear();
62 SupportedFeatures.clear();
64 is_glcontext_shared = false;
67 m_sound_driver.reset();
69 sound_initialized = false;
75 if(log_mutex.try_lock_for(std::chrono::milliseconds(100))) {
76 p_logger->set_osd(NULL);
81 extern std::string cpp_homedir;
82 extern std::string my_procname;
84 const _TCHAR *OSD_BASE::get_lib_osd_version()
86 const _TCHAR *p = (const _TCHAR *)"\0";
87 #if defined(__LIBOSD_VERSION)
88 return (const _TCHAR *)__LIBOSD_VERSION;
93 QOpenGLContext *OSD_BASE::get_gl_context()
95 if(glContext == NULL) return NULL;
96 if(!(glContext->isValid())) return NULL;
100 EmuThreadClass *OSD_BASE::get_parent_handler()
102 return parent_thread;
105 const _TCHAR *OSD_BASE::get_vm_device_name()
107 if(using_flags != NULL) {
108 QString s = using_flags->get_device_name();
109 static QByteArray __n = s.toUtf8();
110 return (const _TCHAR*)(__n.constData());
112 return (const _TCHAR*)"";
115 void OSD_BASE::set_parent_thread(EmuThreadClass *parent)
117 parent_thread = parent;
120 void OSD_BASE::initialize(int rate, int samples, int* presented_rate, int* presented_samples)
124 void OSD_BASE::release()
128 void OSD_BASE::suspend()
130 if(get_use_movie_player()) {
131 if(now_movie_play && !now_movie_pause) {
133 now_movie_pause = false;
139 void OSD_BASE::restore()
141 if(get_use_movie_player()) {
142 if(now_movie_play && !now_movie_pause) {
150 void OSD_BASE::debug_log(int level, const char *fmt, ...)
156 vsnprintf(strbuf, 4095, fmt, ap);
157 debug_log(level, 0, strbuf);
161 void OSD_BASE::debug_log(int level, int domain_num, const char *fmt, ...)
167 vsnprintf(strbuf, 4095, fmt, ap);
168 debug_log(level, domain_num, strbuf);
172 _TCHAR *OSD_BASE::get_app_path(void)
177 _TCHAR* OSD_BASE::bios_path(const _TCHAR* file_name)
179 static _TCHAR file_path[_MAX_PATH];
180 snprintf((char *)file_path, _MAX_PATH, "%s%s", app_path, (const char *)file_name);
181 debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_OSD, "BIOS PATH:%s", file_path);
185 void OSD_BASE::get_host_time(cur_time_t* time)
188 //GetLocalTime(&sTime);
189 QDateTime nowTime = QDateTime::currentDateTime();
190 QDate d = nowTime.date();
191 QTime t = nowTime.time();
193 time->year = d.year();
194 time->month = d.month();
196 time->day_of_week = d.dayOfWeek();
197 time->hour = t.hour();
198 time->minute = t.minute();
199 time->second = t.second();
202 void OSD_BASE::sleep(uint32_t ms)
207 void OSD_BASE::create_date_file_name(_TCHAR *name, int length, const _TCHAR *extension)
209 QDateTime nowTime = QDateTime::currentDateTime();
210 QString tmps = QString::fromUtf8("emu");
211 tmps = tmps + get_vm_config_name();
212 tmps = tmps + QString::fromUtf8("_");
213 tmps = tmps + nowTime.toString(QString::fromUtf8("yyyy-MM-dd_hh-mm-ss.zzz."));
214 tmps = tmps + QString::fromUtf8((const char *)extension);
215 snprintf((char *)name, length, "%s", tmps.toLocal8Bit().constData());
218 _TCHAR* OSD_BASE::application_path()
224 bool OSD_BASE::get_use_socket(void)
229 bool OSD_BASE::get_use_auto_key(void)
234 bool OSD_BASE::get_dont_keeep_key_pressed(void)
239 bool OSD_BASE::get_one_board_micro_computer(void)
244 bool OSD_BASE::get_use_screen_rotate(void)
249 bool OSD_BASE::get_use_movie_player(void)
254 bool OSD_BASE::get_use_video_capture(void)
260 void OSD_BASE::vm_key_down(int code, bool flag)
262 // ToDo: Really need to lock? 20221011 K.O
263 std::lock_guard<std::recursive_timed_mutex> lv(vm_mutex);
266 vm->key_down(code, flag);
270 void OSD_BASE::vm_key_up(int code)
272 // ToDo: Really need to lock? 20221011 K.O
273 std::lock_guard<std::recursive_timed_mutex> lv(vm_mutex);
280 void OSD_BASE::vm_reset(void)
282 std::lock_guard<std::recursive_timed_mutex> lv(vm_mutex);
288 void OSD_BASE::notify_power_off(void)
290 emit sig_notify_power_off();
293 int OSD_BASE::get_vm_buttons_code(int num)
298 QString OSD_BASE::get_vm_config_name(void)
300 return QString::fromUtf8(" ");
303 int OSD_BASE::get_screen_width(void)
308 int OSD_BASE::get_screen_height(void)
313 void OSD_BASE::lock_vm(void)
319 void OSD_BASE::unlock_vm(void)
326 bool OSD_BASE::is_vm_locked(void)
331 void OSD_BASE::force_unlock_vm(void)
337 void OSD_BASE::set_draw_thread(DrawThreadClass *handler)
341 void OSD_BASE::initialize_screen()
343 first_draw_screen = false;
344 first_invalidate = true;
345 self_invalidate = false;
348 void OSD_BASE::release_screen()
352 int OSD_BASE::get_window_mode_width(int mode)
357 int OSD_BASE::get_window_mode_height(int mode)
362 double OSD_BASE::get_window_mode_power(int mode)
366 } else if(mode + 1 > 2) {
372 void OSD_BASE::reset_vm_node(void)
375 device_node_list.clear();
380 void OSD_BASE::debug_log(int level, int domain_num, char *strbuf)
382 p_logger->debug_log(level, domain_num, strbuf);
386 void OSD_BASE::set_device_name(int id, char *name)
388 p_logger->set_device_name(id, (char *)name);
391 void OSD_BASE::set_vm_node(int id, const _TCHAR *name)
395 for(i = 0; i < device_node_list.size(); i++) {
396 sp = device_node_list.at(i);
400 set_device_name(id, (char *)name);
401 device_node_list.replace(i, sp);
402 if(id >= max_vm_nodes) max_vm_nodes = id + 1;
409 set_device_name(id, (char *)name);
410 device_node_list.append(sp);
411 if(id >= max_vm_nodes) max_vm_nodes = id + 1;
414 const _TCHAR *OSD_BASE::get_vm_node_name(int id)
418 for(i = 0; i < device_node_list.size(); i++) {
419 sp = device_node_list.at(i);
427 int OSD_BASE::get_vm_node_size(void)
433 void OSD_BASE::add_feature(const _TCHAR *key, double value)
437 tmps = QString::fromUtf8(key);
438 if(!check_feature(key)) {
441 SupportedFeatures.append(l);
445 void OSD_BASE::add_feature(const _TCHAR *key, int64_t value)
449 tmps = QString::fromUtf8(key);
450 if(!check_feature(key)) {
453 SupportedFeatures.append(l);
457 void OSD_BASE::add_feature(const _TCHAR *key, uint64_t value)
461 tmps = QString::fromUtf8(key);
462 if(!check_feature(key)) {
465 SupportedFeatures.append(l);
469 void OSD_BASE::add_feature(const _TCHAR *key, float value)
471 add_feature(key, (double)value);
474 void OSD_BASE::add_feature(const _TCHAR *key, int value)
476 add_feature(key, (int64_t)value);
480 void OSD_BASE::add_feature(const _TCHAR *key, int16_t value)
482 add_feature(key, (int64_t)value);
485 void OSD_BASE::add_feature(const _TCHAR *key, int8_t value)
487 add_feature(key, (int64_t)value);
490 void OSD_BASE::add_feature(const _TCHAR *key, uint32_t value)
492 add_feature(key, (uint64_t)(value & 0xffffffff));
495 void OSD_BASE::add_feature(const _TCHAR *key, uint16_t value)
497 add_feature(key, (uint64_t)(value & 0xffff));
500 void OSD_BASE::add_feature(const _TCHAR *key, uint8_t value)
502 add_feature(key, (uint64_t)(value & 0xff));
506 bool OSD_BASE::check_feature(const _TCHAR *key)
510 tmps = QString::fromUtf8(key);
511 for(int i = 0; i < SupportedFeatures.size(); i++) {
512 l = SupportedFeatures.at(i);
513 if(l.string == tmps) {
520 double OSD_BASE::get_feature_double_value(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) {
531 return std::numeric_limits<double>::quiet_NaN(); // You don't use (0.0 / 0.0).
534 int64_t OSD_BASE::get_feature_int64_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) {
548 int OSD_BASE::get_feature_int_value(const _TCHAR *key)
550 return (int)get_feature_int64_value(key);
553 int32_t OSD_BASE::get_feature_int32_value(const _TCHAR *key)
555 return (int32_t)get_feature_int64_value(key);
558 int16_t OSD_BASE::get_feature_int16_value(const _TCHAR *key)
560 return (int16_t)get_feature_int64_value(key);
563 int8_t OSD_BASE::get_feature_int8_value(const _TCHAR *key)
565 return (int8_t)get_feature_int64_value(key);
569 uint64_t OSD_BASE::get_feature_uint64_value(const _TCHAR *key)
573 tmps = QString::fromUtf8(key);
574 for(int i = 0; i < SupportedFeatures.size(); i++) {
575 l = SupportedFeatures.at(i);
576 if(l.string == tmps) {
583 uint32_t OSD_BASE::get_feature_uint32_value(const _TCHAR *key)
585 return (uint32_t)(get_feature_uint64_value(key) & 0xffffffff);
588 uint16_t OSD_BASE::get_feature_uint16_value(const _TCHAR *key)
590 return (uint16_t)(get_feature_uint64_value(key) & 0xffff);
593 uint8_t OSD_BASE::get_feature_uint8_value(const _TCHAR *key)
595 return (uint8_t)(get_feature_uint64_value(key) & 0xff);
598 void OSD_BASE::start_waiting_in_debugger()
600 // ToDo: Wait for rising up debugger window.
604 void OSD_BASE::finish_waiting_in_debugger()
606 // ToDo: Wait for closing up debugger window.
607 debug_mutex.unlock();
610 void OSD_BASE::process_waiting_in_debugger()
612 // ToDo: Check sequence
616 void OSD_BASE::set_dbg_completion_list(std::list<std::string> *p)
619 emit sig_clear_dbg_completion_list();
620 for(auto n = p->begin(); n != p->end(); ++n) {
621 emit sig_add_dbg_completion_list((_TCHAR *)((*n).c_str()));
623 emit sig_apply_dbg_completion_list();
627 void OSD_BASE::clear_dbg_completion_list(void)
629 emit sig_clear_dbg_completion_list();
630 emit sig_apply_dbg_completion_list();
633 // Belows are API for GUI STATUS BAR.
634 void OSD_BASE::set_hdd_image_name(int drv, _TCHAR *filename)
636 QString _n = QString::fromLocal8Bit(filename);
637 emit sig_change_virtual_media(CSP_DockDisks_Domain_HD, drv, _n);
640 // Moved from OSD_WRAPPER.
641 const _TCHAR *OSD_BASE::get_lib_common_vm_version()
643 return (const _TCHAR *)"\0";
646 const _TCHAR *OSD_BASE::get_lib_common_vm_git_version()
648 // ToDo: Really need to lock? 20221011 K.O
649 //std::lock_guard<std::recursive_timed_mutex> lv(vm_mutex);
650 return vm->get_vm_git_version();
655 void OSD_BASE::vm_draw_screen(void)
660 double OSD_BASE::vm_frame_rate(void)
662 // ToDo: Really need to lock? 20221011 K.O
663 //std::lock_guard<std::recursive_timed_mutex> lv(vm_mutex);
664 return vm->get_frame_rate();
667 Sint16* OSD_BASE::create_sound(int *extra_frames)
669 // ToDo: Really need to lock? 20221011 K.O
670 //std::lock_guard<std::recursive_timed_mutex> lv(vm_mutex);
671 return (Sint16 *)vm->create_sound(extra_frames);
674 void OSD_BASE::string_message_from_emu(EMU_MEDIA_TYPE::type_t media_type, int drive, EMU_MESSAGE_TYPE::type_t message_type, _TCHAR* message)
676 // switch(media_type) {
677 // case EMU_MEDIA_TYPE::BINARY:
681 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)
683 // switch(media_type) {
684 // case EMU_MEDIA_TYPE::BINARY: