OSDN Git Service

[Qt][DEBUGGER] Temporally revert changes around debugger, will use src/debugger.cpp .
[csp-qt/common_source_project-fm7.git] / source / src / qt / osd.cpp
1 /*
2         Skelton for retropc emulator
3
4         Author : K.Ohta <whatisthis.sowhat _at_ gmail.com>
5         Date   : 2015.11.30-
6
7         [ Qt dependent ]
8 */
9
10 #include "emu.h"
11 #include <string>
12 #include <QDateTime>
13 #include <QDate>
14 #include <QTime>
15 #include <QString>
16 #include <QObject>
17 #include "emu_thread.h"
18 #include "draw_thread.h"
19 #include "qt_gldraw.h"
20 #include "agar_logger.h"
21
22 OSD::OSD() : QThread(0)
23 {
24         VMSemaphore = new QSemaphore(1);
25 }
26
27 OSD::~OSD()
28 {
29         delete VMSemaphore;
30 }
31
32 extern std::string cpp_homedir;
33 extern std::string my_procname;
34
35 EmuThreadClass *OSD::get_parent_handler()
36 {
37         return parent_thread;
38 }
39
40 void OSD::set_parent_thread(EmuThreadClass *parent)
41 {
42         parent_thread = parent;
43 #ifdef USE_AUTO_KEY     
44         connect(parent, SIGNAL(sig_auto_key_string(QByteArray)), this, SLOT(set_auto_key_string(QByteArray)));
45 #endif  
46 }
47
48 void OSD::set_draw_thread(DrawThreadClass *handler)
49 {
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()));
58 }
59
60 void OSD::initialize(int rate, int samples)
61 {
62         // get module path
63         QString tmp_path;
64         tmp_path = QString::fromStdString(cpp_homedir);
65         tmp_path = tmp_path + QString::fromStdString(my_procname);
66 #if defined(Q_OS_WIN)
67         const char *delim = "\\";
68 #else
69         const char *delim = "/";
70 #endif
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);
74         
75         memset(console_string, 0x00, sizeof(console_string));
76         osd_console_opened = false;
77         //CoInitialize(NULL);
78         initialize_input();
79         initialize_printer();
80         initialize_screen();
81         initialize_sound(rate, samples);
82 #if defined(USE_MOVIE_PLAYER) || defined(USE_VIDEO_CAPTURE)
83         initialize_video();
84 #endif
85 #ifdef USE_SOCKET
86         initialize_socket();
87 #endif
88 }
89
90 void OSD::release()
91 {
92         release_input();
93         release_printer();
94         release_screen();
95         release_sound();
96 #if defined(USE_MOVIE_PLAYER) || defined(USE_VIDEO_CAPTURE)
97         release_video();
98 #endif
99 #ifdef USE_SOCKET
100         release_socket();
101 #endif
102         //CoUninitialize();
103 }
104
105 void OSD::power_off()
106 {
107         emit sig_close_window();
108 }
109
110 void OSD::suspend()
111 {
112 #ifdef USE_MOVIE_PLAYER
113         if(now_movie_play && !now_movie_pause) {
114                 pause_movie();
115                 now_movie_pause = false;
116         }
117 #endif
118         mute_sound();
119 }
120
121 void OSD::restore()
122 {
123 #ifdef USE_MOVIE_PLAYER
124         if(now_movie_play && !now_movie_pause) {
125                 play_movie();
126         }
127 #endif
128 }
129
130 _TCHAR* OSD::bios_path(const _TCHAR* file_name)
131 {
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);
135         return file_path;
136 }
137
138 void OSD::get_host_time(cur_time_t* time)
139 {
140         //SYSTEMTIME sTime;
141         //GetLocalTime(&sTime);
142         QDateTime nowTime = QDateTime::currentDateTime();
143         QDate d = nowTime.date();
144         QTime t = nowTime.time();
145
146         time->year = d.year();
147         time->month = d.month();
148         time->day = d.day();
149         time->day_of_week = d.dayOfWeek();
150         time->hour = t.hour();
151         time->minute = t.minute();
152         time->second = t.second();
153 }
154
155 void OSD::sleep(uint32 ms)
156 {
157         QThread::msleep(ms);
158 }
159
160 void OSD::create_date_file_name(_TCHAR *name, int length, const _TCHAR *extension)
161 {
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());
169 }
170
171 void OSD::lock_vm(void)
172 {
173         if(parent_thread != NULL) { 
174                 if(!parent_thread->now_debugging()) VMSemaphore->acquire(1);
175         } else {
176                 VMSemaphore->acquire(1);
177         }
178 }
179
180 void OSD::unlock_vm(void)
181 {
182         if(parent_thread != NULL) { 
183                 if(!parent_thread->now_debugging()) VMSemaphore->release(1);
184         } else {
185                 VMSemaphore->release(1);
186         }
187 }
188
189 void OSD::force_unlock_vm(void)
190 {
191         if(parent_thread == NULL) {
192                 while(VMSemaphore->available() < 1) VMSemaphore->release(1);
193                 return;
194         }
195         if(parent_thread->now_debugging()) return;
196         while(VMSemaphore->available() < 1) VMSemaphore->release(1);
197 }