2 Skelton for retropc emulator
3 Author : Takeda.Toshiya
4 Port to Qt : K.Ohta <whatisthis.sowhat _at_ gmail.com>
7 [ win32 main ] -> [ agar main ]
13 #include <QApplication>
17 #include <QImageReader>
20 #include <QTranslator>
21 #include <QProcessEnvironment>
22 #include <QCommandLineParser>
28 #include "menuclasses.h"
29 #include "mainwidget.h"
30 #include "commonclasses.h"
32 #include "emu_thread.h"
33 #include "joy_thread.h"
34 #include "draw_thread.h"
36 #include "qt_gldraw.h"
37 #include "../gui/gl2/qt_glutil_gl2_0.h"
38 #include "csp_logger.h"
39 #include "dock_disks.h"
40 #include "menu_disk.h"
41 #include "menu_bubble.h"
42 #include "menu_flags_ext.h"
43 #include "dialog_movie.h"
44 #include "../avio/movie_saver.h"
48 QApplication *GuiMain = NULL;
49 extern config_t config;
50 #if defined(CSP_OS_WINDOWS)
51 CSP_Logger DLL_PREFIX_I *csp_logger;
53 extern CSP_Logger *csp_logger;
56 // Start to define MainWindow.
57 class META_MainWindow *rMainWindow;
62 #define MAX_FONT_SIZE 32
66 extern DLL_PREFIX_I std::string cpp_homedir;
67 extern DLL_PREFIX_I std::string cpp_confdir;
68 extern DLL_PREFIX_I std::string my_procname;
69 extern DLL_PREFIX_I std::string sRssDir;
70 bool now_menuloop = false;
71 static int close_notified = 0;
75 unsigned int desktop_width;
76 unsigned int desktop_height;
78 int prev_window_mode = 0;
79 bool now_fullscreen = false;
81 int window_mode_count;
83 void Ui_MainWindow::do_set_mouse_enable(bool flag)
86 if(emu == NULL) return;
89 graphicsView->grabMouse();
92 graphicsView->releaseMouse();
99 void Ui_MainWindow::do_toggle_mouse(void)
102 if(emu == NULL) return;
104 bool flag = emu->is_mouse_enabled();
106 graphicsView->grabMouse();
109 graphicsView->releaseMouse();
110 emu->disable_mouse();
116 void Ui_MainWindow::rise_movie_dialog(void)
118 CSP_DialogMovie *dlg = new CSP_DialogMovie(hSaveMovieThread, using_flags);
119 dlg->setWindowTitle(QApplication::translate("CSP_DialogMovie", "Configure movie encodings", 0));
122 void Ui_MainWindow::LaunchEmuThread(void)
125 GLDrawClass *glv = this->getGraphicsView();
129 hRunEmu = new EmuThreadClass(rMainWindow, using_flags);
130 connect(hRunEmu, SIGNAL(message_changed(QString)), this, SLOT(message_status_bar(QString)));
131 connect(hRunEmu, SIGNAL(sig_is_enable_mouse(bool)), glv, SLOT(do_set_mouse_enabled(bool)));
132 connect(glv, SIGNAL(sig_key_down(uint32_t, uint32_t, bool)), hRunEmu, SLOT(do_key_down(uint32_t, uint32_t, bool)));
133 connect(glv, SIGNAL(sig_key_up(uint32_t, uint32_t)),hRunEmu, SLOT(do_key_up(uint32_t, uint32_t)));
134 connect(this, SIGNAL(sig_quit_widgets()), glv, SLOT(do_stop_run_vm()));
137 //connect(hRunEmu, SIGNAL(sig_finished()), this, SLOT(delete_emu_thread()));
138 connect(this, SIGNAL(sig_vm_reset()), hRunEmu, SLOT(do_reset()));
139 connect(this, SIGNAL(sig_vm_specialreset()), hRunEmu, SLOT(do_special_reset()));
141 connect(this, SIGNAL(sig_emu_update_config()), hRunEmu, SLOT(do_update_config()));
142 connect(this, SIGNAL(sig_emu_update_volume_level(int, int)), hRunEmu, SLOT(do_update_volume_level(int, int)));
143 connect(this, SIGNAL(sig_emu_update_volume_balance(int, int)), hRunEmu, SLOT(do_update_volume_balance(int, int)));
144 connect(this, SIGNAL(sig_emu_start_rec_sound()), hRunEmu, SLOT(do_start_record_sound()));
145 connect(this, SIGNAL(sig_emu_stop_rec_sound()), hRunEmu, SLOT(do_stop_record_sound()));
146 connect(this, SIGNAL(sig_emu_set_display_size(int, int, int, int)), hRunEmu, SLOT(do_set_display_size(int, int, int, int)));
148 if(using_flags->is_use_state()) {
149 for(int i = 0; i < 10; i++) {
150 connect(actionLoad_State[i], SIGNAL(sig_load_state(QString)), hRunEmu, SLOT(do_load_state(QString))); // OK?
151 connect(actionSave_State[i], SIGNAL(sig_save_state(QString)), hRunEmu, SLOT(do_save_state(QString))); // OK?
154 #if defined(USE_FLOPPY_DISK)
155 connect(this, SIGNAL(sig_write_protect_disk(int, bool)), hRunEmu, SLOT(do_write_protect_disk(int, bool)));
156 connect(this, SIGNAL(sig_open_disk(int, QString, int)), hRunEmu, SLOT(do_open_disk(int, QString, int)));
157 connect(this, SIGNAL(sig_close_disk(int)), hRunEmu, SLOT(do_close_disk(int)));
158 connect(hRunEmu, SIGNAL(sig_update_recent_disk(int)), this, SLOT(do_update_recent_disk(int)));
159 //connect(hRunEmu, SIGNAL(sig_change_osd_fd(int, QString)), this, SLOT(do_change_osd_fd(int, QString)));
160 drvs = USE_FLOPPY_DISK;
161 for(int ii = 0; ii < drvs; ii++) {
162 menu_fds[ii]->setEmu(emu);
163 connect(menu_fds[ii], SIGNAL(sig_update_inner_fd(int ,QStringList , class Action_Control **, QStringList , int, bool)),
164 this, SLOT(do_update_inner_fd(int ,QStringList , class Action_Control **, QStringList , int, bool)));
167 #if defined(USE_HARD_DISK)
168 connect(this, SIGNAL(sig_open_hard_disk(int, QString)), hRunEmu, SLOT(do_open_hard_disk(int, QString)));
169 connect(this, SIGNAL(sig_close_hard_disk(int)), hRunEmu, SLOT(do_close_hard_disk(int)));
170 connect(hRunEmu, SIGNAL(sig_update_recent_hard_disk(int)), this, SLOT(do_update_recent_hard_disk(int)));
171 //connect(hRunEmu, SIGNAL(sig_change_osd_fd(int, QString)), this, SLOT(do_change_osd_fd(int, QString)));
173 #if defined(USE_TAPE)
174 connect(this, SIGNAL(sig_play_tape(int, QString)), hRunEmu, SLOT(do_play_tape(int, QString)));
175 connect(this, SIGNAL(sig_rec_tape(int, QString)), hRunEmu, SLOT(do_rec_tape(int, QString)));
176 connect(this, SIGNAL(sig_close_tape(int)), hRunEmu, SLOT(do_close_tape(int)));
177 //connect(hRunEmu, SIGNAL(sig_change_osd_cmt(QString)), this, SLOT(do_change_osd_cmt(QString)));
178 # if defined(USE_TAPE_BUTTON)
179 connect(this, SIGNAL(sig_cmt_push_play(int)), hRunEmu, SLOT(do_cmt_push_play(int)));
180 connect(this, SIGNAL(sig_cmt_push_stop(int)), hRunEmu, SLOT(do_cmt_push_stop(int)));
181 connect(this, SIGNAL(sig_cmt_push_fast_forward(int)), hRunEmu, SLOT(do_cmt_push_fast_forward(int)));
182 connect(this, SIGNAL(sig_cmt_push_fast_rewind(int)), hRunEmu, SLOT(do_cmt_push_fast_rewind(int)));
183 connect(this, SIGNAL(sig_cmt_push_apss_forward(int)), hRunEmu, SLOT(do_cmt_push_apss_forward(int)));
184 connect(this, SIGNAL(sig_cmt_push_apss_rewind(int)), hRunEmu, SLOT(do_cmt_push_apss_rewind(int)));
187 #if defined(USE_QUICK_DISK)
188 connect(this, SIGNAL(sig_write_protect_quickdisk(int, bool)), hRunEmu, SLOT(do_write_protect_quickdisk(int, bool)));
189 connect(this, SIGNAL(sig_open_quickdisk(int, QString)), hRunEmu, SLOT(do_open_quickdisk(int, QString)));
190 connect(this, SIGNAL(sig_close_quickdisk(int)), hRunEmu, SLOT(do_close_quickdisk(int)));
191 //connect(hRunEmu, SIGNAL(sig_change_osd_qd(int, QString)), this, SLOT(do_change_osd_qd(int, QString)));
193 #if defined(USE_CART)
194 connect(this, SIGNAL(sig_open_cart(int, QString)), hRunEmu, SLOT(do_open_cart(int, QString)));
195 connect(this, SIGNAL(sig_close_cart(int)), hRunEmu, SLOT(do_close_cart(int)));
197 #if defined(USE_COMPACT_DISC)
198 connect(this, SIGNAL(sig_open_cdrom(int, QString)), hRunEmu, SLOT(do_open_cdrom(int, QString)));
199 connect(this, SIGNAL(sig_close_cdrom(int)), hRunEmu, SLOT(do_eject_cdrom(int)));
200 //connect(hRunEmu, SIGNAL(sig_change_osd_cdrom(QString)), this, SLOT(do_change_osd_cdrom(QString)));
201 // ToDo: multiple CDs
203 #if defined(USE_LASER_DISC)
204 connect(this, SIGNAL(sig_open_laserdisc(int, QString)), hRunEmu, SLOT(do_open_laser_disc(int, QString)));
205 connect(this, SIGNAL(sig_close_laserdisc(int)), hRunEmu, SLOT(do_close_laser_disc(int)));
206 // ToDo: multiple LDs
208 #if defined(USE_BINARY_FILE)
209 connect(this, SIGNAL(sig_load_binary(int, QString)), hRunEmu, SLOT(do_load_binary(int, QString)));
210 connect(this, SIGNAL(sig_save_binary(int, QString)), hRunEmu, SLOT(do_save_binary(int, QString)));
212 #if defined(USE_BUBBLE)
213 connect(this, SIGNAL(sig_write_protect_bubble(int, bool)), hRunEmu, SLOT(do_write_protect_bubble_casette(int, bool)));
214 connect(this, SIGNAL(sig_open_bubble(int, QString, int)), hRunEmu, SLOT(do_open_bubble_casette(int, QString, int)));
215 connect(this, SIGNAL(sig_close_bubble(int)), hRunEmu, SLOT(do_close_bubble_casette(int)));
216 connect(hRunEmu, SIGNAL(sig_update_recent_bubble(int)), this, SLOT(do_update_recent_bubble(int)));
217 //connect(hRunEmu, SIGNAL(sig_change_osd_bubble(int, QString)), this, SLOT(do_change_osd_bubble(int, QString)));
219 for(int ii = 0; ii < drvs; ii++) {
220 menu_bubbles[ii]->setEmu(emu);
221 connect(menu_bubbles[ii],
222 SIGNAL(sig_update_inner_bubble(int ,QStringList , class Action_Control **, QStringList , int, bool)),
224 SLOT(do_update_inner_bubble(int ,QStringList , class Action_Control **, QStringList , int, bool)));
228 connect(this, SIGNAL(quit_emu_thread()), hRunEmu, SLOT(doExit()));
229 connect(hRunEmu, SIGNAL(sig_mouse_enable(bool)),
230 this, SLOT(do_set_mouse_enable(bool)));
233 #ifdef USE_TAPE_BUTTON
234 hRunEmu->set_tape_play(false);
236 #if defined(USE_KEY_LOCKED) || defined(USE_LED_DEVICE)
237 connect(hRunEmu, SIGNAL(sig_send_data_led(quint32)), this, SLOT(do_recv_data_led(quint32)));
240 connect(this, SIGNAL(sig_start_auto_key(QString)), hRunEmu, SLOT(do_start_auto_key(QString)));
241 connect(this, SIGNAL(sig_stop_auto_key()), hRunEmu, SLOT(do_stop_auto_key()));
242 connect(this, SIGNAL(sig_set_roma_kana(bool)), hRunEmu, SLOT(set_romakana(bool)));
244 //connect(actionExit_Emulator, SIGNAL(triggered()), hRunEmu, SLOT(doExit()));
245 csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "EmuThread : Start.");
246 objNameStr = QString("EmuThreadClass");
247 hRunEmu->setObjectName(objNameStr);
249 hDrawEmu = new DrawThreadClass(emu->get_osd(), csp_logger, this);
250 emu->set_parent_handler(hRunEmu, hDrawEmu);
252 #ifdef ONE_BOARD_MICRO_COMPUTER
253 QImageReader *reader = new QImageReader(":/background.png");
254 QImage *result = new QImage(reader->read()); // this acts as a default if the size is not matched
255 QImage result2 = result->convertToFormat(QImage::Format_ARGB32);
256 glv->updateBitmap(&result2);
257 emu->get_osd()->upload_bitmap(&result2);
260 emu->get_osd()->set_buttons();
262 csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "DrawThread : Start.");
263 connect(hDrawEmu, SIGNAL(sig_draw_frames(int)), hRunEmu, SLOT(print_framerate(int)));
264 //connect(emu->get_osd(), SIGNAL(sig_draw_frames(int)), hRunEmu, SLOT(print_framerate(int)));
265 connect(hRunEmu, SIGNAL(window_title_changed(QString)), this, SLOT(do_set_window_title(QString)));
266 connect(hDrawEmu, SIGNAL(message_changed(QString)), this, SLOT(message_status_bar(QString)));
267 connect(actionCapture_Screen, SIGNAL(triggered()), glv, SLOT(do_save_frame_screen()));
269 /*if(config.use_separate_thread_draw) {
270 connect(hRunEmu, SIGNAL(sig_draw_thread(bool)), hDrawEmu, SLOT(doDraw(bool)), Qt::QueuedConnection);
271 connect(hRunEmu, SIGNAL(sig_set_draw_fps(double)), hDrawEmu, SLOT(do_set_frames_per_second(double)), Qt::QueuedConnection);
272 connect(hRunEmu, SIGNAL(sig_draw_one_turn(bool)), hDrawEmu, SLOT(do_draw_one_turn(bool)), Qt::QueuedConnection);
274 connect(hRunEmu, SIGNAL(sig_draw_thread(bool)), hDrawEmu, SLOT(doDraw(bool)));
275 connect(hRunEmu, SIGNAL(sig_set_draw_fps(double)), hDrawEmu, SLOT(do_set_frames_per_second(double)));
276 connect(hRunEmu, SIGNAL(sig_draw_one_turn(bool)), hDrawEmu, SLOT(do_draw_one_turn(bool)));
278 //connect(hRunEmu, SIGNAL(sig_draw_thread(bool)), emu->get_osd(), SLOT(do_draw(bool)));
279 //connect(hRunEmu, SIGNAL(quit_draw_thread()), hDrawEmu, SLOT(doExit()));
280 connect(this, SIGNAL(quit_draw_thread()), hDrawEmu, SLOT(doExit()));
282 connect(glv, SIGNAL(do_notify_move_mouse(int, int)),
283 hRunEmu, SLOT(moved_mouse(int, int)));
284 connect(glv, SIGNAL(do_notify_button_pressed(Qt::MouseButton)),
285 hRunEmu, SLOT(button_pressed_mouse(Qt::MouseButton)));
286 connect(glv, SIGNAL(do_notify_button_released(Qt::MouseButton)),
287 hRunEmu, SLOT(button_released_mouse(Qt::MouseButton)));
289 connect(glv, SIGNAL(sig_toggle_mouse(void)),
290 this, SLOT(do_toggle_mouse(void)));
292 connect(hRunEmu, SIGNAL(sig_resize_screen(int, int)),
293 glv, SLOT(resizeGL(int, int)));
294 connect(hRunEmu, SIGNAL(sig_resize_osd(int)), driveData, SLOT(setScreenWidth(int)));
296 connect(glv, SIGNAL(sig_resize_uibar(int, int)),
297 this, SLOT(resize_statusbar(int, int)));
298 connect(hRunEmu, SIGNAL(sig_resize_uibar(int, int)),
299 this, SLOT(resize_statusbar(int, int)));
301 connect(emu->get_osd(), SIGNAL(sig_req_encueue_video(int, int, int)),
302 hDrawEmu, SLOT(do_req_encueue_video(int, int, int)));
303 connect(hRunEmu, SIGNAL(sig_finished()), glv, SLOT(releaseKeyCode(void)));
304 connect(hRunEmu, SIGNAL(sig_finished()), this, SLOT(delete_emu_thread()));
305 objNameStr = QString("EmuDrawThread");
306 hDrawEmu->setObjectName(objNameStr);
308 if(config.use_separate_thread_draw) hDrawEmu->start();
310 csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "DrawThread : Launch done.");
312 hSaveMovieThread = new MOVIE_SAVER(640, 400, 30, emu->get_osd(), &config);
314 connect(actionStart_Record_Movie->binds, SIGNAL(sig_start_record_movie(int)), hRunEmu, SLOT(do_start_record_video(int)));
315 connect(this, SIGNAL(sig_start_saving_movie()),
316 actionStart_Record_Movie->binds, SLOT(do_save_as_movie()));
317 connect(actionStart_Record_Movie, SIGNAL(triggered()), this, SLOT(do_start_saving_movie()));
319 connect(actionStop_Record_Movie->binds, SIGNAL(sig_stop_record_movie()), hRunEmu, SLOT(do_stop_record_video()));
320 connect(this, SIGNAL(sig_stop_saving_movie()), actionStop_Record_Movie->binds, SLOT(do_stop_saving_movie()));
321 connect(hSaveMovieThread, SIGNAL(sig_set_state_saving_movie(bool)), this, SLOT(do_set_state_saving_movie(bool)));
322 connect(actionStop_Record_Movie, SIGNAL(triggered()), this, SLOT(do_stop_saving_movie()));
324 connect(emu->get_osd(), SIGNAL(sig_save_as_movie(QString, int, int)),
325 hSaveMovieThread, SLOT(do_open(QString, int, int)));
326 connect(emu->get_osd(), SIGNAL(sig_stop_saving_movie()), hSaveMovieThread, SLOT(do_close()));
328 actionStop_Record_Movie->setIcon(QIcon(":/icon_process_stop.png"));
329 actionStop_Record_Movie->setVisible(false);
331 connect(this, SIGNAL(sig_movie_set_width(int)), hSaveMovieThread, SLOT(do_set_width(int)));
332 connect(this, SIGNAL(sig_movie_set_height(int)), hSaveMovieThread, SLOT(do_set_height(int)));
334 connect(emu->get_osd(), SIGNAL(sig_movie_set_width(int)), hSaveMovieThread, SLOT(do_set_width(int)));
335 connect(emu->get_osd(), SIGNAL(sig_movie_set_height(int)), hSaveMovieThread, SLOT(do_set_height(int)));
337 connect(emu->get_osd(), SIGNAL(sig_enqueue_audio(int16_t*, int)), hSaveMovieThread, SLOT(enqueue_audio(int16_t *, int)));
338 connect(emu->get_osd(), SIGNAL(sig_enqueue_video(int, int, int, QImage *)),
339 hSaveMovieThread, SLOT(enqueue_video(int, int, int, QImage *)), Qt::DirectConnection);
340 connect(glv->extfunc, SIGNAL(sig_push_image_to_movie(int, int, int, QImage *)),
341 hSaveMovieThread, SLOT(enqueue_video(int, int, int, QImage *)));
342 connect(this, SIGNAL(sig_quit_movie_thread()), hSaveMovieThread, SLOT(do_exit()));
344 objNameStr = QString("EmuMovieThread");
345 hSaveMovieThread->setObjectName(objNameStr);
346 hSaveMovieThread->start();
347 csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "MovieThread : Launch done.");
349 connect(action_SetupMovie, SIGNAL(triggered()), this, SLOT(rise_movie_dialog()));
350 connect(hRunEmu, SIGNAL(sig_change_osd(int, int, QString)), driveData, SLOT(updateMessage(int, int, QString)));
351 connect(hRunEmu, SIGNAL(sig_change_access_lamp(int, int, QString)), driveData, SLOT(updateLabel(int, int, QString)));
352 connect(hRunEmu, SIGNAL(sig_set_access_lamp(int, bool)), graphicsView, SLOT(do_display_osd_leds(int, bool)));
355 csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "EmuThread : Launch done.");
356 this->set_screen_aspect(config.window_stretch_type);
357 emit sig_movie_set_width(SCREEN_WIDTH);
358 emit sig_movie_set_height(SCREEN_HEIGHT);
361 void Ui_MainWindow::LaunchJoyThread(void)
363 #if defined(USE_JOYSTICK)
364 hRunJoy = new JoyThreadClass(emu, emu->get_osd(), using_flags, &config, csp_logger);
365 connect(this, SIGNAL(quit_joy_thread()), hRunJoy, SLOT(doExit()));
366 hRunJoy->setObjectName("JoyThread");
371 void Ui_MainWindow::StopJoyThread(void)
373 #if defined(USE_JOYSTICK)
374 emit quit_joy_thread();
378 void Ui_MainWindow::delete_joy_thread(void)
380 // delete hRunJoyThread;
384 void Ui_MainWindow::on_actionExit_triggered()
386 OnMainWindowClosed();
389 void Ui_MainWindow::OnWindowRedraw(void)
392 //emu->update_screen();
396 void Ui_MainWindow::OnWindowMove(void)
404 #ifdef USE_NOTIFY_POWER_OFF
405 bool Ui_MainWindow::GetPowerState(void)
407 if(close_notified == 0) return true;
414 void Ui_MainWindow::OnMainWindowClosed(void)
417 #ifdef USE_NOTIFY_POWER_OFF
419 if(!close_notified) {
421 emu->notify_power_off();
428 if(statusUpdateTimer != NULL) statusUpdateTimer->stop();
429 #if defined(USE_KEY_LOCKED) || defined(USE_LED_DEVICE)
430 if(ledUpdateTimer != NULL) ledUpdateTimer->stop();
432 emit quit_draw_thread();
433 emit quit_joy_thread();
434 emit quit_emu_thread();
435 emit sig_quit_movie_thread();
436 emit sig_quit_widgets();
438 if(hSaveMovieThread != NULL) {
439 hSaveMovieThread->wait();
440 delete hSaveMovieThread;
441 hSaveMovieThread = NULL;
444 if(hDrawEmu != NULL) {
449 if(hRunEmu != NULL) {
455 save_config(create_local_path(_T("%s.ini"), _T(CONFIG_NAME)));
459 std::string localstr;
460 snprintf(tmps, sizeof(tmps), _T("%s.ini"), _T(CONFIG_NAME));
462 localstr = cpp_confdir + localstr;
463 save_config(localstr.c_str());
467 #if defined(USE_JOYSTICK)
468 if(hRunJoy != NULL) {
474 do_release_emu_resources();
479 //ChangeDisplaySettings(NULL, 0);
481 now_fullscreen = false;
487 void LostFocus(QWidget *widget)
490 emu->key_lost_focus();
496 void Ui_MainWindow::do_release_emu_resources(void)
504 extern void DLL_PREFIX_I get_long_full_path_name(_TCHAR* src, _TCHAR* dst);
505 extern _TCHAR* DLL_PREFIX_I get_parent_dir(_TCHAR* file);
506 extern void get_short_filename(_TCHAR *dst, _TCHAR *file, int maxlen);
508 #if defined(Q_OS_CYGWIN)
509 #include <sys/stat.h>
511 static void my_util_mkdir(std::string n)
513 #if !defined(Q_OS_CYGWIN)
514 QDir dir = QDir::current();
515 dir.mkdir( QString::fromStdString(n));
518 if(stat(n.c_str(), &st) != 0) {
519 _mkdir(n.c_str()); // Not found
524 static void setup_logs(void)
530 my_procname = my_procname + CONFIG_NAME;
531 #if defined(Q_OS_WIN)
536 #if !defined(Q_OS_WIN)
537 p = SDL_getenv("HOME");
539 p = SDL_getenv("PWD");
546 tmpstr = "Warning : Can't get HOME directory...Making conf on " + cpp_homedir + delim;
547 perror(tmpstr.c_str());
554 cpp_homedir = cpp_homedir + delim;
556 #if !defined(CSP_OS_WINDOWS)
557 cpp_confdir = cpp_homedir + ".config" + delim;
558 my_util_mkdir(cpp_confdir);
560 cpp_confdir = cpp_homedir;
563 cpp_confdir = cpp_confdir + "CommonSourceCodeProject" + delim;
564 my_util_mkdir(cpp_confdir);
566 cpp_confdir = cpp_confdir + my_procname + delim;
567 my_util_mkdir(cpp_confdir);
568 //AG_MkPath(cpp_confdir.c_str());
571 #if defined(_USE_AGAR) || defined(_USE_QT)
572 sRssDir = "/usr/local/share/";
574 sRssDir = "." + delim;
576 sRssDir = sRssDir + "CommonSourceCodeProject" + delim + my_procname;
582 QStringList virtualMediaList; // {TYPE, POSITION}
583 QCommandLineOption *_opt_fds[8];
584 QCommandLineOption *_opt_hdds[8];
585 QCommandLineOption *_opt_cmts[2];
586 QCommandLineOption *_opt_lds[2];
587 QCommandLineOption *_opt_cds[2];
588 QCommandLineOption *_opt_binaries[8];
589 QCommandLineOption *_opt_bubbles[8];
590 QCommandLineOption *_opt_qds[8];
591 QCommandLineOption *_opt_carts[8];
592 extern QCommandLineOption *_opt_homedir;
593 extern QCommandLineOption *_opt_cfgfile;
594 extern QCommandLineOption *_opt_cfgdir;
595 extern QCommandLineOption *_opt_resdir;
596 extern QCommandLineOption *_opt_opengl;
597 extern QCommandLineOption *_opt_envver;
598 extern QCommandLineOption *_opt_dump_envver;
599 extern QCommandLineOption *_opt_dipsw_on;
600 extern QCommandLineOption *_opt_dipsw_off;
601 extern QProcessEnvironment _envvers;
603 std::string config_fullpath;
605 void SetFDOptions(QCommandLineParser *cmdparser)
607 #if defined(USE_FLOPPY_DISK)
608 for(int i = 0; i < USE_FLOPPY_DISK; i++) {
609 QString sfdType1 = QString::fromUtf8("fd%1").arg(i);
610 QString sfdType2 = QString::fromUtf8("vFd%1").arg(i);
611 QString sfdType3 = QString::fromUtf8("vFloppyDisk%1").arg(i);
613 _cl.append(sfdType1);
614 _cl.append(sfdType2);
615 _cl.append(sfdType3);
616 _opt_fds[i] = new QCommandLineOption(_cl,QCoreApplication::translate("main", "Set virtual floppy disk %1.").arg(i) , "[D88_SLOT@]fullpath");
617 cmdparser->addOption(*_opt_fds[i]);
623 void SetHDDOptions(QCommandLineParser *cmdparser)
625 #if defined(USE_HARD_DISK)
626 for(int i = 0; i < USE_HARD_DISK; i++) {
627 QString sfdType1 = QString::fromUtf8("hd%1").arg(i);
628 QString sfdType2 = QString::fromUtf8("vHd%1").arg(i);
629 QString sfdType3 = QString::fromUtf8("vHardDisk%1").arg(i);
630 QString sfdType4 = QString::fromUtf8("vHardDrive%1").arg(i);
632 _cl.append(sfdType1);
633 _cl.append(sfdType2);
634 _cl.append(sfdType3);
635 _cl.append(sfdType4);
636 _opt_hdds[i] = new QCommandLineOption(_cl,QCoreApplication::translate("main", "Set virtual hard drive %1.").arg(i) , "[D88_SLOT@]fullpath");
637 cmdparser->addOption(*_opt_hdds[i]);
643 void SetBinaryOptions(QCommandLineParser *cmdparser)
645 #if defined(USE_BINARY_FILE)
646 for(int i = 0; i < USE_BINARY_FILE; i++) {
647 QString sfdType1 = QString::fromUtf8("bin%1").arg(i);
648 QString sfdType2 = QString::fromUtf8("vBinary%1").arg(i);
650 _cl.append(sfdType1);
651 _cl.append(sfdType2);
652 _opt_binaries[i] = new QCommandLineOption(_cl,QCoreApplication::translate("main", "Set virtual binary image %1.").arg(i) , "fullpath");
653 cmdparser->addOption(*_opt_binaries[i]);
659 void SetCartOptions(QCommandLineParser *cmdparser)
661 #if defined(USE_CART)
662 for(int i = 0; i < USE_CART; i++) {
663 QString sfdType1 = QString::fromUtf8("cart%1").arg(i);
664 QString sfdType2 = QString::fromUtf8("vCart%1").arg(i);
665 QString sfdType3 = QString::fromUtf8("vCartridge%1").arg(i);
667 _cl.append(sfdType1);
668 _cl.append(sfdType2);
669 _cl.append(sfdType3);
670 _opt_carts[i] = new QCommandLineOption(_cl,QCoreApplication::translate("main", "Set virtual cartridge %1 (mostly ROM).").arg(i) , "fullpath");
671 cmdparser->addOption(*_opt_carts[i]);
676 void SetBubbleOptions(QCommandLineParser *cmdparser)
678 #if defined(USE_BUBBLE)
679 for(int i = 0; i < USE_BUBBLE; i++) {
680 QString sfdType1 = QString::fromUtf8("bub%1").arg(i);
681 QString sfdType2 = QString::fromUtf8("vBubble%1").arg(i);
683 _cl.append(sfdType1);
684 _cl.append(sfdType2);
685 _opt_bubbles[i] = new QCommandLineOption(_cl,QCoreApplication::translate("main", "Set virtual bubble cartridge %1.").arg(i) , "[B88_SLOT@]fullpath");
686 cmdparser->addOption(*_opt_bubbles[i]);
691 void SetLDOptions(QCommandLineParser *cmdparser)
693 #if defined(USE_LASER_DISC)
694 for(int i = 0; i < USE_LASER_DISC; i++) {
695 QString sfdType1 = QString::fromUtf8("ld%1").arg(i);
696 QString sfdType2 = QString::fromUtf8("vLaserDisc%1").arg(i);
698 _cl.append(sfdType1);
699 _cl.append(sfdType2);
700 _opt_lds[i] = new QCommandLineOption(_cl, QCoreApplication::translate("main", "Set virtual laser disc %1 (mostly movie file).").arg(i) , "fullpath");
701 cmdparser->addOption(*_opt_lds[i]);
706 void SetCDOptions(QCommandLineParser *cmdparser)
708 #if defined(USE_COMPACT_DISC)
709 for(int i = 0; i < USE_COMPACT_DISC; i++) {
710 QString sfdType1 = QString::fromUtf8("cd%1").arg(i);
711 QString sfdType2 = QString::fromUtf8("vCompactDisc%1").arg(i);
713 _cl.append(sfdType1);
714 _cl.append(sfdType2);
715 _opt_cds[i] = new QCommandLineOption(_cl,QCoreApplication::translate("main", "Set virtual compact disc %1.").arg(i) , "fullpath");
716 cmdparser->addOption(*_opt_cds[i]);
722 void SetCmtOptions(QCommandLineParser *cmdparser)
724 #if defined(USE_TAPE)
725 for(int i = 0; i < USE_TAPE; i++) {
726 QString sfdType1 = QString::fromUtf8("cmt%1").arg(i);
727 QString sfdType2 = QString::fromUtf8("tape%1").arg(i);
728 QString sfdType3 = QString::fromUtf8("vCmt%1").arg(i);
729 QString sfdType4 = QString::fromUtf8("vTape%1").arg(i);
731 _cl.append(sfdType1);
732 _cl.append(sfdType2);
733 _cl.append(sfdType3);
734 _cl.append(sfdType4);
735 _opt_cmts[i] = new QCommandLineOption(_cl, QCoreApplication::translate("main", "Set virtual casette tape %1.").arg(i) , "fullpath");
736 cmdparser->addOption(*_opt_cmts[i]);
742 void SetQuickDiskOptions(QCommandLineParser *cmdparser)
744 #if defined(USE_QUICK_DISK)
745 for(int i = 0; i < USE_QUICK_DISK; i++) {
746 QString sfdType1 = QString::fromUtf8("qd%1").arg(i);
747 QString sfdType2 = QString::fromUtf8("vQuickDisk%1").arg(i);
750 _cl.append(sfdType1);
751 _cl.append(sfdType2);
752 _opt_qds[i] = new QCommandLineOption(_cl, QCoreApplication::translate("main", "Set virtual quick disk %1.").arg(i) , "fullpath");
753 cmdparser->addOption(*_opt_qds[i]);
760 void SetProcCmdFD(QCommandLineParser *cmdparser, QStringList *_l)
762 #if defined(USE_FLOPPY_DISK)
763 for(int i = 0; i < USE_FLOPPY_DISK; i++) {
764 if(_opt_fds[i] != NULL) {
765 if(cmdparser->isSet(*_opt_fds[i])) {
766 QString sfdType = QString::fromUtf8("vFloppyDisk%1").arg(i);
767 QString medianame = cmdparser->value(*_opt_fds[i]);
769 _l->append(medianame);
776 void SetProcCmdHDD(QCommandLineParser *cmdparser, QStringList *_l)
778 #if defined(USE_HARD_DISK)
779 for(int i = 0; i < USE_HARD_DISK; i++) {
780 if(_opt_hdds[i] != NULL) {
781 if(cmdparser->isSet(*_opt_hdds[i])) {
782 QString sfdType = QString::fromUtf8("vHardDisk%1").arg(i);
783 QString medianame = cmdparser->value(*_opt_hdds[i]);
785 _l->append(medianame);
792 void SetProcCmdQuickDisk(QCommandLineParser *cmdparser, QStringList *_l)
794 #if defined(USE_QUICK_DISK)
795 for(int i = 0; i < USE_QUICK_DISK; i++) {
796 if(_opt_qds[i] != NULL) {
797 if(cmdparser->isSet(*_opt_qds[i])) {
798 QString sfdType = QString::fromUtf8("vQuickDisk%1").arg(i);
799 QString medianame = cmdparser->value(*_opt_qds[i]);
801 _l->append(medianame);
808 void SetProcCmdCmt(QCommandLineParser *cmdparser, QStringList *_l)
810 #if defined(USE_TAPE)
811 for(int i = 0; i < USE_TAPE; i++) {
812 if(_opt_cmts[i] != NULL) {
813 if(cmdparser->isSet(*_opt_cmts[i])) {
814 QString sfdType = QString::fromUtf8("vCmt%1").arg(i);
815 QString medianame = cmdparser->value(*_opt_cmts[i]);
817 _l->append(medianame);
824 void SetProcCmdBinary(QCommandLineParser *cmdparser, QStringList *_l)
826 #if defined(USE_BINARY_FILE)
827 for(int i = 0; i < USE_BINARY_FILE; i++) {
828 if(_opt_binaries[i] != NULL) {
829 if(cmdparser->isSet(*_opt_binaries[i])) {
830 QString sfdType = QString::fromUtf8("vBinary%1").arg(i);
831 QString medianame = cmdparser->value(*_opt_binaries[i]);
833 _l->append(medianame);
840 void SetProcCmdBubble(QCommandLineParser *cmdparser, QStringList *_l)
842 #if defined(USE_BUBBLE)
843 for(int i = 0; i < USE_BUBBLE; i++) {
844 if(_opt_bubbles[i] != NULL) {
845 if(cmdparser->isSet(*_opt_bubbles[i])) {
846 QString sfdType = QString::fromUtf8("vBubble%1").arg(i);
847 QString medianame = cmdparser->value(*_opt_bubbles[i]);
849 _l->append(medianame);
856 void SetProcCmdCart(QCommandLineParser *cmdparser, QStringList *_l)
858 #if defined(USE_CART)
859 for(int i = 0; i < USE_CART; i++) {
860 if(_opt_carts[i] != NULL) {
861 if(cmdparser->isSet(*_opt_carts[i])) {
862 QString sfdType = QString::fromUtf8("vCart%1").arg(i);
863 QString medianame = cmdparser->value(*_opt_carts[i]);
865 _l->append(medianame);
872 void SetProcCmdLD(QCommandLineParser *cmdparser, QStringList *_l)
874 #if defined(USE_LASER_DISC)
875 for(int i = 0; i < USE_LASER_DISC; i++) {
876 if(_opt_lds[i] != NULL) {
877 if(cmdparser->isSet(*_opt_lds[i])) {
878 QString sfdType = QString::fromUtf8("vLD%1").arg(i);
879 QString medianame = cmdparser->value(*_opt_lds[i]);
881 _l->append(medianame);
888 void SetProcCmdCD(QCommandLineParser *cmdparser, QStringList *_l)
890 #if defined(USE_COMPACT_DISC)
891 for(int i = 0; i < USE_COMPACT_DISC; i++) {
892 if(_opt_cds[i] != NULL) {
893 if(cmdparser->isSet(*_opt_cds[i])) {
894 QString sfdType = QString::fromUtf8("vCD%1").arg(i);
895 QString medianame = cmdparser->value(*_opt_cds[i]);
897 _l->append(medianame);
904 extern void SetOptions_Sub(QCommandLineParser *cmdparser);
905 void SetOptions(QCommandLineParser *cmdparser)
907 QString emudesc = QString::fromUtf8("Emulator for ");
908 emudesc = emudesc + QString::fromUtf8(DEVICE_NAME);
909 cmdparser->setApplicationDescription(emudesc);
910 cmdparser->addHelpOption();
911 //cmdparser->addVersionOption();
913 SetOptions_Sub(cmdparser);
916 for(int i = 0; i < 8; i++) {
920 _opt_bubbles[i] = NULL;
921 _opt_binaries[i] = NULL;
922 _opt_carts[i] = NULL;
924 for(int i = 0; i < 2; i++) {
930 SetFDOptions(cmdparser);
931 SetHDDOptions(cmdparser);
932 //SetBinaryOptions(cmdparser); // Temporally disabled.
933 SetCmtOptions(cmdparser);
934 SetCartOptions(cmdparser);
935 SetBubbleOptions(cmdparser); // Temporally disabled.
936 SetQuickDiskOptions(cmdparser);
937 SetLDOptions(cmdparser); // Temporally disabled.
938 SetCDOptions(cmdparser);
940 cmdparser->addOption(*_opt_envver);
941 cmdparser->addOption(*_opt_dump_envver);
944 extern void ProcessCmdLine_Sub(QCommandLineParser *cmdparser, QStringList *_l);
946 void ProcessCmdLine(QCommandLineParser *cmdparser, QStringList *_l)
948 char homedir[PATH_MAX];
950 #if defined(Q_OS_WIN)
955 ProcessCmdLine_Sub(cmdparser, _l);
958 std::string localstr;
959 memset(tmps, 0x00, 128);
960 if(cmdparser->isSet(*_opt_cfgfile)) {
961 strncpy(tmps, cmdparser->value(*_opt_cfgfile).toLocal8Bit().constData(), 127);
963 if(strlen(tmps) <= 0){
964 snprintf(tmps, sizeof(tmps), _T("%s.ini"), _T(CONFIG_NAME));
967 localstr = cpp_confdir + localstr;
968 load_config(localstr.c_str());
969 config_fullpath = localstr;
971 if(cmdparser->isSet(*_opt_opengl)) {
972 char tmps[128] = {0};
973 strncpy(tmps, cmdparser->value(*_opt_opengl).toLocal8Bit().constData(), 128 - 1);
974 if(strlen(tmps) > 0) {
975 QString render = QString::fromLocal8Bit(tmps).toUpper();
976 if((render == QString::fromUtf8("GL2")) ||
977 (render == QString::fromUtf8("GLV2"))) {
978 config.render_platform = CONFIG_RENDER_PLATFORM_OPENGL_MAIN;
979 config.render_major_version = 2;
980 config.render_minor_version = 0;
981 GuiMain->setAttribute(Qt::AA_UseDesktopOpenGL, true);
982 GuiMain->setAttribute(Qt::AA_UseOpenGLES, false);
983 } else if((render == QString::fromUtf8("GL3")) ||
984 (render == QString::fromUtf8("GLV3")) ||
985 (render == QString::fromUtf8("OPENGLV3")) ||
986 (render == QString::fromUtf8("OPENGL")) ||
987 (render == QString::fromUtf8("GL"))) {
988 config.render_platform = CONFIG_RENDER_PLATFORM_OPENGL_MAIN;
989 config.render_major_version = 3;
990 config.render_minor_version = 0;
991 GuiMain->setAttribute(Qt::AA_UseDesktopOpenGL, true);
992 GuiMain->setAttribute(Qt::AA_UseOpenGLES, false);
993 } else if((render == QString::fromUtf8("GLES2")) ||
994 (render == QString::fromUtf8("GLESV2")) ||
995 (render == QString::fromUtf8("GLES3")) ||
996 (render == QString::fromUtf8("GLESV3")) ||
997 (render == QString::fromUtf8("GLES"))) {
998 config.render_platform = CONFIG_RENDER_PLATFORM_OPENGL_ES;
999 config.render_major_version = 2;
1000 config.render_minor_version = 1;
1001 GuiMain->setAttribute(Qt::AA_UseDesktopOpenGL, false);
1002 GuiMain->setAttribute(Qt::AA_UseOpenGLES, true);
1003 } else if((render == QString::fromUtf8("GL4")) ||
1004 (render == QString::fromUtf8("GL43")) ||
1005 (render == QString::fromUtf8("GL4.3")) ||
1006 (render == QString::fromUtf8("GL4_3")) ||
1007 (render == QString::fromUtf8("GL4_CORE"))) {
1008 config.render_platform = CONFIG_RENDER_PLATFORM_OPENGL_CORE;
1009 config.render_major_version = 4;
1010 config.render_minor_version = 3;
1011 GuiMain->setAttribute(Qt::AA_UseDesktopOpenGL, true);
1012 GuiMain->setAttribute(Qt::AA_UseOpenGLES, false);
1016 SetProcCmdFD(cmdparser, _l);
1017 SetProcCmdHDD(cmdparser, _l);
1018 SetProcCmdQuickDisk(cmdparser, _l);
1019 SetProcCmdCmt(cmdparser, _l);
1020 SetProcCmdCart(cmdparser, _l);
1021 SetProcCmdBinary(cmdparser, _l);
1022 SetProcCmdBubble(cmdparser, _l);
1023 SetProcCmdLD(cmdparser, _l);
1024 SetProcCmdCD(cmdparser, _l);
1027 memset(homedir, 0x00, PATH_MAX);
1028 if(cmdparser->isSet(*_opt_homedir)) {
1029 strncpy(homedir, cmdparser->value(*_opt_homedir).toLocal8Bit().constData(), PATH_MAX - 1);
1030 cpp_homedir = homedir;
1031 size_t _len = cpp_homedir.length() - 1;
1032 size_t _pos = cpp_homedir.rfind(delim);
1034 (_pos == std::string::npos)) {
1035 cpp_homedir.append(delim);
1038 cpp_homedir.copy(homedir, PATH_MAX - 1, 0);
1041 if(cmdparser->isSet(*_opt_cfgdir)) {
1042 char tmps[PATH_MAX];
1044 memset(tmps, 0x00, PATH_MAX);
1045 strncpy(tmps, cmdparser->value(*_opt_cfgdir).toLocal8Bit().constData(), PATH_MAX - 1);
1047 size_t _len = cpp_confdir.length() - 1;
1048 size_t _pos = cpp_confdir.rfind(delim);
1050 (_pos == std::string::npos)) {
1051 cpp_confdir.append(delim);
1057 std::string localstr;
1058 memset(tmps, 0x00, 128);
1059 if(cmdparser->isSet(*_opt_cfgfile)) {
1060 strncpy(tmps, cmdparser->value(*_opt_cfgfile).toLocal8Bit().constData(), 127);
1062 if(strlen(tmps) <= 0){
1063 snprintf(tmps, sizeof(tmps), _T("%s.ini"), _T(CONFIG_NAME));
1066 localstr = cpp_confdir + localstr;
1067 load_config(localstr.c_str());
1068 config_fullpath = localstr;
1070 if(cmdparser->isSet(*_opt_resdir)) {
1071 char tmps[PATH_MAX];
1073 memset(tmps, 0x00, PATH_MAX);
1074 strncpy(tmps, cmdparser->value(*_opt_resdir).toLocal8Bit().constData(), PATH_MAX - 1);
1076 size_t _len = sRssDir.length() - 1;
1077 size_t _pos = sRssDir.rfind(delim);
1079 (_pos == std::string::npos)) {
1080 sRssDir.append(delim);
1083 if(cmdparser->isSet(*_opt_opengl)) {
1084 char tmps[128] = {0};
1085 strncpy(tmps, cmdparser->value(*_opt_opengl).toLocal8Bit().constData(), 128 - 1);
1086 if(strlen(tmps) > 0) {
1087 QString render = QString::fromLocal8Bit(tmps).toUpper();
1088 if((render == QString::fromUtf8("GL2")) ||
1089 (render == QString::fromUtf8("GLV2"))) {
1090 config.render_platform = CONFIG_RENDER_PLATFORM_OPENGL_MAIN;
1091 config.render_major_version = 2;
1092 config.render_minor_version = 0;
1093 GuiMain->setAttribute(Qt::AA_UseDesktopOpenGL, true);
1094 GuiMain->setAttribute(Qt::AA_UseOpenGLES, false);
1095 } else if((render == QString::fromUtf8("GL3")) ||
1096 (render == QString::fromUtf8("GLV3")) ||
1097 (render == QString::fromUtf8("OPENGLV3")) ||
1098 (render == QString::fromUtf8("OPENGL")) ||
1099 (render == QString::fromUtf8("GL"))) {
1100 config.render_platform = CONFIG_RENDER_PLATFORM_OPENGL_MAIN;
1101 config.render_major_version = 3;
1102 config.render_minor_version = 0;
1103 GuiMain->setAttribute(Qt::AA_UseDesktopOpenGL, true);
1104 GuiMain->setAttribute(Qt::AA_UseOpenGLES, false);
1105 } else if((render == QString::fromUtf8("GLES2")) ||
1106 (render == QString::fromUtf8("GLESV2")) ||
1107 (render == QString::fromUtf8("GLES3")) ||
1108 (render == QString::fromUtf8("GLESV3")) ||
1109 (render == QString::fromUtf8("GLES"))) {
1110 config.render_platform = CONFIG_RENDER_PLATFORM_OPENGL_ES;
1111 config.render_major_version = 2;
1112 config.render_minor_version = 1;
1113 GuiMain->setAttribute(Qt::AA_UseDesktopOpenGL, false);
1114 GuiMain->setAttribute(Qt::AA_UseOpenGLES, true);
1115 } else if((render == QString::fromUtf8("GL4")) ||
1116 (render == QString::fromUtf8("GL43")) ||
1117 (render == QString::fromUtf8("GL4.3")) ||
1118 (render == QString::fromUtf8("GL4_3")) ||
1119 (render == QString::fromUtf8("GL4_CORE"))) {
1120 config.render_platform = CONFIG_RENDER_PLATFORM_OPENGL_CORE;
1121 config.render_major_version = 4;
1122 config.render_minor_version = 3;
1123 GuiMain->setAttribute(Qt::AA_UseDesktopOpenGL, true);
1124 GuiMain->setAttribute(Qt::AA_UseOpenGLES, false);
1128 if(cmdparser->isSet(*_opt_envver)) {
1129 QStringList nList = cmdparser->values(*_opt_envver);
1131 //QProcessEnvironment ev = QProcessEnvironment::systemEnvironment();
1132 QProcessEnvironment ev = _envvers;
1133 if(nList.size() > 0) {
1134 for(int i = 0; i < nList.size(); i++) {
1136 if(tv.indexOf(QString::fromUtf8("-")) == 0) {
1138 int n1 = tv.indexOf(QString::fromUtf8("="));
1140 tv = tv.left(n1).right(n1 - 1);
1142 tv = tv.right(tv.length() - 1);
1144 printf("DEBUG: DEL ENV:%s\n", tv.toLocal8Bit().constData());
1146 } else if(tv.indexOf(QString::fromUtf8("=")) > 0) {
1148 int n1 = tv.indexOf(QString::fromUtf8("="));
1152 if((tv.length() - n1) < 1) {
1153 sval = QString::fromUtf8("");
1155 sval = tv.right(tv.length() - n1 - 1);
1157 printf("DEBUG: SET ENV:%s to %s\n", skey.toLocal8Bit().constData(), sval.toLocal8Bit().constData());
1158 if(skey.length() > 0) ev.insert(skey, sval);
1159 } else if(tv.indexOf(QString::fromUtf8("=")) < 0) {
1160 printf("DEBUG: SET ENV:%s to (NULL)\n", tv.toLocal8Bit().constData());
1161 if(tv.length() > 0) ev.insert(tv, QString::fromUtf8(""));
1167 _b_dump_envver = false;
1168 if(cmdparser->isSet(*_opt_dump_envver)) {
1169 _b_dump_envver = true;
1172 uint32_t dipsw_onbits = 0x0000000;
1173 uint32_t dipsw_offmask = 0xffffffff;
1174 if(cmdparser->isSet(*_opt_dipsw_off)) {
1175 QStringList bitList = cmdparser->values(*_opt_dipsw_off);
1178 for(int i = 0; i < bitList.size(); i++) {
1180 int _bit = tv.toInt(&num_ok);
1182 if((_bit >= 0) && (_bit < 32)) {
1183 dipsw_offmask &= (uint32_t)(~(1 << _bit));
1188 if(cmdparser->isSet(*_opt_dipsw_on)) {
1189 QStringList bitList = cmdparser->values(*_opt_dipsw_on);
1192 for(int i = 0; i < bitList.size(); i++) {
1194 int _bit = tv.toInt(&num_ok);
1196 if((_bit >= 0) && (_bit < 32)) {
1197 dipsw_onbits |= (uint32_t)(1 << _bit);
1202 config.dipswitch &= dipsw_offmask;
1203 config.dipswitch |= dipsw_onbits;
1206 void OpeningMessage(std::string archstr)
1208 csp_logger->set_emu_vm_name(DEVICE_NAME); // Write to syslog, console
1209 csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "Start Common Source Project '%s'", my_procname.c_str());
1210 csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "(C) Toshiya Takeda / Qt Version K.Ohta");
1211 csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "Architecture: %s", archstr.c_str());
1212 csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "Use -h or --help for help.");
1214 //csp_logger->debug_log(AGAR_LOG_INFO, " -? is print help(s).");
1215 csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "Home = %s, Resource directory = %s",
1216 cpp_homedir.c_str(),
1217 sRssDir.c_str()); // Debug
1219 csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "Config dir = %s, config_file = %s",
1220 cpp_confdir.c_str(),
1221 config_fullpath.c_str()); // Debug
1223 csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "DIPSW VALUE IS 0x%08x", config.dipswitch);
1224 if(virtualMediaList.size() >= 2) {
1225 for(int i = 0; i < virtualMediaList.size(); i += 2) {
1226 csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "Virtual media %d, type %s, name %s",
1228 virtualMediaList.at(i).toLocal8Bit().constData(),
1229 virtualMediaList.at(i + 1).toLocal8Bit().constData());
1236 QStringList _el = _envvers.toStringList();
1237 if(_el.size() > 0) {
1238 for(int i = 0; i < _el.size(); i++) {
1239 QString _s = _el.at(i);
1240 if(_s.startsWith("SDL_")) {
1243 _nl = _s.indexOf('=');
1245 skey = _s.left(_nl);
1246 svar = _s.right(_s.length() - _nl);
1249 svar = QString::fromUtf8("");
1251 SDL_setenv(skey.toLocal8Bit().constData(), svar.toLocal8Bit().constData(), 1);
1252 csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "Note: SDL ENVIROMENT : %s to %s.",
1253 skey.toLocal8Bit().constData(),
1254 svar.toLocal8Bit().constData());
1258 #if defined(USE_SDL2)
1259 SDL_Init(SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER);
1261 SDL_Init(SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_VIDEO);
1263 csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "Audio and JOYSTICK subsystem was initialised.");
1267 void SetupLogger(QObject *parent, std::string emustr, int _size)
1270 csp_logger = new CSP_Logger(parent, config.log_to_syslog, config.log_to_console, emustr.c_str()); // Write to syslog, console
1271 csp_logger->set_log_stdout(CSP_LOG_DEBUG, true);
1272 csp_logger->set_log_stdout(CSP_LOG_INFO, true);
1273 csp_logger->set_log_stdout(CSP_LOG_WARN, true);
1275 csp_logger->set_state_log(0, config.state_log_to_recording);
1276 csp_logger->set_state_log(1, config.state_log_to_syslog);
1277 csp_logger->set_state_log(2, config.state_log_to_console);
1279 for(int ii = 0; ii < _size; ii++) {
1280 for(int jj = 0; jj < 8; jj++) {
1281 csp_logger->set_device_node_log(ii, 1, jj, config.dev_log_to_syslog[ii][jj]);
1282 csp_logger->set_device_node_log(ii, 2, jj, config.dev_log_to_console[ii][jj]);
1283 csp_logger->set_device_node_log(ii, 0, jj, config.dev_log_recording[ii][jj]);
1288 int MainLoop(int argc, char *argv[])
1291 std::string archstr;
1292 std::string emustr("emu");
1293 std::string cfgstr(CONFIG_NAME);
1298 #if defined(Q_OS_WIN)
1304 GuiMain = new QApplication(argc, argv);
1305 GuiMain->setObjectName(QString::fromUtf8("Gui_Main"));
1306 _envvers = QProcessEnvironment::systemEnvironment();
1308 QCommandLineParser cmdparser;
1310 virtualMediaList.clear();
1311 SetOptions(&cmdparser);
1313 cmdparser.process(QCoreApplication::arguments());
1315 ProcessCmdLine(&cmdparser, &virtualMediaList);
1317 emustr = emustr + cfgstr;
1319 SetupLogger(GuiMain, emustr, CSP_LOG_TYPE_VM_DEVICE_END - CSP_LOG_TYPE_VM_DEVICE_0 + 1);
1322 archstr = "Generic";
1323 #if defined(__x86_64__)
1326 #if defined(__i386__)
1329 OpeningMessage(archstr);
1335 //SetupTranslators();
1336 QTranslator local_translator;
1338 if(local_translator.load(s_locale, QLatin1String("csp_qt_machine"), QLatin1String("_"), QLatin1String(":/"))) {
1339 GuiMain->installTranslator(&local_translator);
1341 QTranslator s_translator;
1342 if(s_translator.load(s_locale, QLatin1String("csp_qt_gui"), QLatin1String("_"), QLatin1String(":/"))) {
1343 GuiMain->installTranslator(&s_translator);
1345 QTranslator common_translator;
1346 if(common_translator.load(s_locale, QLatin1String("csp_qt_common"), QLatin1String("_"), QLatin1String(":/"))) {
1347 GuiMain->installTranslator(&common_translator);
1349 QTranslator debugger_translator;
1350 if(debugger_translator.load(s_locale, QLatin1String("csp_qt_debugger"), QLatin1String("_"), QLatin1String(":/"))) {
1351 GuiMain->installTranslator(&debugger_translator);
1353 //QProcessEnvironment::systemEnvironment() = _envvers;
1354 if(_b_dump_envver) {
1355 //QProcessEnvironment ev = QProcessEnvironment::systemEnvironment();
1356 QProcessEnvironment ev = _envvers;
1357 QStringList el = _envvers.toStringList();
1359 csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "Environment Variables:");
1360 for(int i = 0; i < el.size(); i++) {
1361 csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "#%d : %s", i, el.at(i).toLocal8Bit().constData());
1366 USING_FLAGS_EXT *using_flags = new USING_FLAGS_EXT(&config);
1367 // initialize emulation core
1368 rMainWindow = new META_MainWindow(using_flags, csp_logger);
1369 rMainWindow->connect(rMainWindow, SIGNAL(sig_quit_all(void)), rMainWindow, SLOT(deleteLater(void)));
1370 rMainWindow->setCoreApplication(GuiMain);
1371 rMainWindow->getWindow()->show();
1374 rMainWindow->LaunchEmuThread();
1375 #if defined(USE_JOYSTICK)
1376 rMainWindow->LaunchJoyThread();
1378 GLDrawClass *pgl = rMainWindow->getGraphicsView();
1379 pgl->set_emu_launched();
1380 pgl->setFixedSize(pgl->width(), pgl->height());
1381 rMainWindow->retranselateUi_Depended_OSD();
1382 QObject::connect(emu->get_osd(), SIGNAL(sig_update_device_node_name(int, const _TCHAR *)),
1383 rMainWindow, SLOT(do_update_device_node_name(int, const _TCHAR *)));
1384 for(int i = 0; i < (CSP_LOG_TYPE_VM_DEVICE_END - CSP_LOG_TYPE_VM_DEVICE_0 + 1); i++) {
1385 rMainWindow->do_update_device_node_name(i, using_flags->get_vm_node_name(i));
1387 csp_logger->set_osd(emu->get_osd());
1388 csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "InitInstance() OK.");
1390 QObject::connect(GuiMain, SIGNAL(lastWindowClosed()),
1391 rMainWindow, SLOT(on_actionExit_triggered()));
1397 void Ui_MainWindow::do_update_inner_fd(int drv, QStringList base, class Action_Control **action_select_media_list,
1398 QStringList lst, int num, bool use_d88_menus)
1400 #if defined(USE_FLOPPY_DISK)
1402 for(int ii = 0; ii < using_flags->get_max_d88_banks(); ii++) {
1403 if(ii < emu->d88_file[drv].bank_num) {
1404 base << lst.value(ii);
1405 action_select_media_list[ii]->setText(lst.value(ii));
1406 action_select_media_list[ii]->setVisible(true);
1407 if(ii == num) action_select_media_list[ii]->setChecked(true);
1409 if(action_select_media_list[ii] != NULL) {
1410 action_select_media_list[ii]->setText(QString::fromUtf8(""));
1411 action_select_media_list[ii]->setVisible(false);
1419 void Ui_MainWindow::do_update_inner_bubble(int drv, QStringList base, class Action_Control **action_select_media_list,
1420 QStringList lst, int num, bool use_d88_menus)
1422 #if defined(USE_BUBBLE)
1424 for(int ii = 0; ii < using_flags->get_max_b77_banks(); ii++) {
1425 if(ii < emu->b77_file[drv].bank_num) {
1426 base << lst.value(ii);
1427 action_select_media_list[ii]->setText(lst.value(ii));
1428 action_select_media_list[ii]->setVisible(true);
1429 if(ii == num) action_select_media_list[ii]->setChecked(true);
1431 if(action_select_media_list[ii] != NULL) {
1432 action_select_media_list[ii]->setText(QString::fromUtf8(""));
1433 action_select_media_list[ii]->setVisible(false);
1441 int Ui_MainWindow::GetBubbleBankNum(int drv)
1444 if((emu != NULL) && (drv >= 0) && (drv < MAX_BUBBLE)) {
1445 return emu->b77_file[drv].bank_num;
1451 int Ui_MainWindow::GetBubbleCurrentBankNum(int drv)
1454 if((emu != NULL) && (drv >= 0) && (drv < MAX_BUBBLE)) {
1455 return emu->b77_file[drv].cur_bank;
1461 bool Ui_MainWindow::GetBubbleCasetteIsProtected(int drv)
1465 if((drv >= 0) && (drv < MAX_BUBBLE)) {
1466 return emu->is_bubble_casette_protected(drv);
1473 QString Ui_MainWindow::GetBubbleB77FileName(int drv)
1475 QString ans = QString::fromUtf8("");
1478 if((drv < MAX_BUBBLE) && (drv >= 0)) {
1479 ans = QString::fromLocal8Bit(emu->b77_file[drv].path);
1486 QString Ui_MainWindow::GetBubbleB77BubbleName(int drv, int num)
1488 QString ans = QString::fromUtf8("");
1491 if((drv < MAX_BUBBLE) && (drv >= 0)) {
1492 if((num >= 0) && (num < MAX_B77_BANKS)) {
1493 ans = QString::fromLocal8Bit(emu->b77_file[drv].bubble_name[num]);
1502 #include <../debugger/qt_debugger.h>
1504 void Ui_MainWindow::OnOpenDebugger(int no)
1506 if((no < 0) || (no > 7)) return;
1507 //emu->open_debugger(no);
1508 VM *vm = emu->get_vm();
1510 if((emu->now_debugging ) || (emu->hDebugger != NULL)) /* OnCloseDebugger(); */ return;
1512 if(!(emu->now_debugging && emu->debugger_thread_param.cpu_index == no)) {
1513 //emu->close_debugger();
1514 if(vm->get_cpu(no) != NULL && vm->get_cpu(no)->get_debugger() != NULL) {
1515 QString windowName = QString::fromUtf8(vm->get_cpu(no)->get_device_name());
1516 windowName = QString::fromUtf8("Debugger ") + windowName;
1517 emu->hDebugger = new CSP_Debugger(this);
1518 QString objNameStr = QString("EmuDebugThread");
1519 emu->hDebugger->setObjectName(objNameStr);
1520 emu->hDebugger->debugger_thread_param.osd = emu->get_osd();
1521 emu->hDebugger->debugger_thread_param.vm = vm;
1522 emu->hDebugger->debugger_thread_param.cpu_index = no;
1523 emu->stop_record_sound();
1524 emu->stop_record_video();
1525 //emu->now_debugging = true;
1526 connect(this, SIGNAL(quit_debugger_thread()), emu->hDebugger, SLOT(doExit()));
1527 connect(this, SIGNAL(destroyed()), emu->hDebugger, SLOT(do_destroy_thread()));
1528 //connect(this, SIGNAL(quit_debugger_thread()), emu->hDebugger, SLOT(close()));
1529 connect(emu->hDebugger, SIGNAL(sig_finished()), this, SLOT(OnCloseDebugger()));
1530 connect(emu->hDebugger, SIGNAL(sig_put_string(QString)), emu->hDebugger, SLOT(put_string(QString)));
1531 emu->hDebugger->show();
1532 emu->hDebugger->run();
1533 emu->hDebugger->setWindowTitle(windowName);
1538 void Ui_MainWindow::OnCloseDebugger(void )
1541 // emu->close_debugger();
1542 if(emu->now_debugging) {
1543 if(emu->hDebugger->debugger_thread_param.running) {
1544 emit quit_debugger_thread();
1545 //emu->hDebugger->wait();
1549 if(emu->hDebugger != NULL) {
1550 delete emu->hDebugger;
1551 emu->hDebugger = NULL;
1553 emu->now_debugging = false;