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);
32 extern std::string cpp_homedir;
33 extern std::string my_procname;
35 EmuThreadClass *OSD::get_parent_handler()
40 void OSD::set_parent_thread(EmuThreadClass *parent)
42 parent_thread = parent;
44 connect(parent, SIGNAL(sig_auto_key_string(QByteArray)), this, SLOT(set_auto_key_string(QByteArray)));
48 void OSD::set_draw_thread(DrawThreadClass *handler)
50 this->moveToThread(handler);
51 connect(this, SIGNAL(sig_update_screen(screen_buffer_t *)), handler, SLOT(do_update_screen(screen_buffer_t *)));
52 connect(this, SIGNAL(sig_save_screen(const char *)), glv, SLOT(do_save_frame_screen(const char *)));
53 connect(this, SIGNAL(sig_close_window()), parent_thread, SLOT(doExit()));
54 connect(this, SIGNAL(sig_resize_vm_screen(QImage *, int, int)), glv, SLOT(do_set_texture_size(QImage *, int, int)));
55 connect(this, SIGNAL(sig_console_input_string(QString)), parent_thread, SLOT(do_call_debugger_command(QString)));
56 connect(parent_thread, SIGNAL(sig_debugger_input(QString)), this, SLOT(do_set_input_string(QString)));
57 connect(parent_thread, SIGNAL(sig_quit_debugger()), this, SLOT(do_close_debugger_thread()));
60 void OSD::initialize(int rate, int samples)
64 tmp_path = QString::fromStdString(cpp_homedir);
65 tmp_path = tmp_path + QString::fromStdString(my_procname);
67 const char *delim = "\\";
69 const char *delim = "/";
71 tmp_path = tmp_path + QString::fromUtf8(delim);
72 memset(app_path, 0x00, sizeof(app_path));
73 strncpy(app_path, tmp_path.toUtf8().constData(), _MAX_PATH);
75 memset(console_string, 0x00, sizeof(console_string));
76 osd_console_opened = false;
81 initialize_sound(rate, samples);
82 #if defined(USE_MOVIE_PLAYER) || defined(USE_VIDEO_CAPTURE)
96 #if defined(USE_MOVIE_PLAYER) || defined(USE_VIDEO_CAPTURE)
105 void OSD::power_off()
107 emit sig_close_window();
112 #ifdef USE_MOVIE_PLAYER
113 if(now_movie_play && !now_movie_pause) {
115 now_movie_pause = false;
123 #ifdef USE_MOVIE_PLAYER
124 if(now_movie_play && !now_movie_pause) {
130 _TCHAR* OSD::bios_path(const _TCHAR* file_name)
132 static _TCHAR file_path[_MAX_PATH];
133 snprintf(file_path, _MAX_PATH, _T("%s%s"), app_path, file_name);
134 AGAR_DebugLog(AGAR_LOG_INFO, "BIOS PATH:%s", file_path);
138 void OSD::get_host_time(cur_time_t* time)
141 //GetLocalTime(&sTime);
142 QDateTime nowTime = QDateTime::currentDateTime();
143 QDate d = nowTime.date();
144 QTime t = nowTime.time();
146 time->year = d.year();
147 time->month = d.month();
149 time->day_of_week = d.dayOfWeek();
150 time->hour = t.hour();
151 time->minute = t.minute();
152 time->second = t.second();
155 void OSD::sleep(uint32 ms)
160 void OSD::create_date_file_name(_TCHAR *name, int length, const _TCHAR *extension)
162 QDateTime nowTime = QDateTime::currentDateTime();
163 QString tmps = QString::fromUtf8("emu");
164 tmps = tmps + QString::fromUtf8(CONFIG_NAME);
165 tmps = tmps + QString::fromUtf8("_");
166 tmps = tmps + nowTime.toString(QString::fromUtf8("yyyy-MM-dd_hh-mm-ss.zzz."));
167 tmps = tmps + QString::fromUtf8(extension);
168 snprintf(name, length, _T("%s"), tmps.toLocal8Bit().constData());
171 void OSD::lock_vm(void)
173 if(parent_thread != NULL) {
174 if(!parent_thread->now_debugging()) VMSemaphore->acquire(1);
176 VMSemaphore->acquire(1);
180 void OSD::unlock_vm(void)
182 if(parent_thread != NULL) {
183 if(!parent_thread->now_debugging()) VMSemaphore->release(1);
185 VMSemaphore->release(1);
189 void OSD::force_unlock_vm(void)
191 if(parent_thread == NULL) {
192 while(VMSemaphore->available() < 1) VMSemaphore->release(1);
195 if(parent_thread->now_debugging()) return;
196 while(VMSemaphore->available() < 1) VMSemaphore->release(1);