2 Skelton for retropc emulator
4 Author : K.Ohta <whatisthis.sowhat _at_ gmail.com>
17 #include "emu_thread.h"
18 #include "draw_thread.h"
19 #include "qt_gldraw.h"
20 #include "agar_logger.h"
22 OSD::OSD() : QThread(0)
24 VMSemaphore = new QSemaphore(1);
33 extern std::string cpp_homedir;
34 extern std::string my_procname;
36 EmuThreadClass *OSD::get_parent_handler()
41 void OSD::set_parent_thread(EmuThreadClass *parent)
43 parent_thread = parent;
45 connect(parent, SIGNAL(sig_auto_key_string(QByteArray)), this, SLOT(set_auto_key_string(QByteArray)));
49 void OSD::set_draw_thread(DrawThreadClass *handler)
51 this->moveToThread(handler);
52 connect(this, SIGNAL(sig_update_screen(bitmap_t *)), handler, SLOT(do_update_screen(bitmap_t *)));
53 connect(this, SIGNAL(sig_save_screen(const char *)), glv, SLOT(do_save_frame_screen(const char *)));
54 connect(this, SIGNAL(sig_close_window()), parent_thread, SLOT(doExit()));
55 connect(this, SIGNAL(sig_resize_vm_screen(QImage *, int, int)), glv, SLOT(do_set_texture_size(QImage *, int, int)));
56 connect(this, SIGNAL(sig_console_input_string(QString)), parent_thread, SLOT(do_call_debugger_command(QString)));
57 connect(parent_thread, SIGNAL(sig_debugger_input(QString)), this, SLOT(do_set_input_string(QString)));
58 connect(parent_thread, SIGNAL(sig_quit_debugger()), this, SLOT(do_close_debugger_thread()));
61 void OSD::initialize(int rate, int samples)
65 tmp_path = QString::fromStdString(cpp_homedir);
66 tmp_path = tmp_path + QString::fromStdString(my_procname);
68 const char *delim = "\\";
70 const char *delim = "/";
72 tmp_path = tmp_path + QString::fromUtf8(delim);
73 memset(app_path, 0x00, sizeof(app_path));
74 strncpy(app_path, tmp_path.toUtf8().constData(), _MAX_PATH);
76 //memset(console_string, 0x00, sizeof(console_string));
77 console_cmd_str.clear();
78 osd_console_opened = false;
84 initialize_sound(rate, samples);
85 #if defined(USE_MOVIE_PLAYER) || defined(USE_VIDEO_CAPTURE)
99 #if defined(USE_MOVIE_PLAYER) || defined(USE_VIDEO_CAPTURE)
108 void OSD::power_off()
110 emit sig_close_window();
115 #ifdef USE_MOVIE_PLAYER
116 if(now_movie_play && !now_movie_pause) {
118 now_movie_pause = false;
126 #ifdef USE_MOVIE_PLAYER
127 if(now_movie_play && !now_movie_pause) {
133 _TCHAR* OSD::bios_path(const _TCHAR* file_name)
135 static _TCHAR file_path[_MAX_PATH];
136 snprintf(file_path, _MAX_PATH, _T("%s%s"), app_path, file_name);
137 AGAR_DebugLog(AGAR_LOG_INFO, "BIOS PATH:%s", file_path);
141 void OSD::get_host_time(cur_time_t* time)
144 //GetLocalTime(&sTime);
145 QDateTime nowTime = QDateTime::currentDateTime();
146 QDate d = nowTime.date();
147 QTime t = nowTime.time();
149 time->year = d.year();
150 time->month = d.month();
152 time->day_of_week = d.dayOfWeek();
153 time->hour = t.hour();
154 time->minute = t.minute();
155 time->second = t.second();
158 void OSD::sleep(uint32_t ms)
163 void OSD::create_date_file_name(_TCHAR *name, int length, const _TCHAR *extension)
165 QDateTime nowTime = QDateTime::currentDateTime();
166 QString tmps = QString::fromUtf8("emu");
167 tmps = tmps + QString::fromUtf8(CONFIG_NAME);
168 tmps = tmps + QString::fromUtf8("_");
169 tmps = tmps + nowTime.toString(QString::fromUtf8("yyyy-MM-dd_hh-mm-ss.zzz."));
170 tmps = tmps + QString::fromUtf8(extension);
171 snprintf(name, length, _T("%s"), tmps.toLocal8Bit().constData());
174 void OSD::lock_vm(void)
177 if(parent_thread != NULL) {
178 if(!parent_thread->now_debugging()) VMSemaphore->acquire(1);
180 VMSemaphore->acquire(1);
184 void OSD::unlock_vm(void)
187 if(parent_thread != NULL) {
188 if(!parent_thread->now_debugging()) VMSemaphore->release(1);
190 VMSemaphore->release(1);
194 bool OSD::is_vm_locked(void)
199 void OSD::force_unlock_vm(void)
201 if(parent_thread == NULL) {
202 while(VMSemaphore->available() < 1) VMSemaphore->release(1);
205 if(parent_thread->now_debugging()) return;
206 while(VMSemaphore->available() < 1) VMSemaphore->release(1);