OSDN Git Service

[UI][Qt] Drop LockVM() / UnlockVM() from Open FD Dialog/Change Recent FD/Eject FD...
authorK.Ohta <whatisthis.sowhat@gmail.com>
Sun, 18 Oct 2015 15:44:33 +0000 (00:44 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Sun, 18 Oct 2015 15:44:33 +0000 (00:44 +0900)
source/src/qt/common/emu_utils.cpp
source/src/qt/common/qt_gldraw.cpp
source/src/qt/common/qt_gldraw.h
source/src/qt/common/qt_glutil.cpp
source/src/qt/common/qt_main.cpp
source/src/qt/common/qt_main.h
source/src/qt/common/qt_screen.cpp
source/src/qt/gui/mainwidget.h
source/src/qt/gui/util_fd.cpp

index 2994133..1419c18 100644 (file)
@@ -72,12 +72,9 @@ void open_disk(int drv, _TCHAR* path, int bank)
 
 void close_disk(int drv)
 {
-  emu->LockVM();
-  emu->close_disk(drv);
-  emu->d88_file[drv].bank_num = 0;
-  emu->d88_file[drv].cur_bank = -1;
-  emu->UnlockVM();
-
+       emu->close_disk(drv);
+       emu->d88_file[drv].bank_num = 0;
+       emu->d88_file[drv].cur_bank = -1;
 }
 #endif
 
index 03d55ba..8a55cdc 100644 (file)
@@ -523,7 +523,7 @@ void GLDrawClass::paintGL(void)
        int i;
        if(!crt_flag) return;
        if(p_emu != NULL) {
-               if(imgptr == NULL) return;
+               //if(imgptr == NULL) return;
                drawUpdateTexture(imgptr);
                crt_flag = false;
        }
index 94841d7..a5fb834 100644 (file)
@@ -176,7 +176,7 @@ public:
        void InitFBO(void);
        
 public slots:
-       void update_screen(void);
+       void update_screen(QImage *);
        void resizeGL(int width, int height);
        void mouseMoveEvent(QMouseEvent *event);
        void mousePressEvent(QMouseEvent *event);
index 4a235ca..3a5c6c0 100644 (file)
 #ifdef _USE_OPENCL
 //class GLCLDraw *cldraw = NULL;
 #endif
-void GLDrawClass::update_screen()
+void GLDrawClass::update_screen(QImage *p)
 {
        //if(tick < (1000 / 75)) tick = 1000 / 75;
-       if(p_emu == NULL) return;
-       imgptr = p_emu->getPseudoVramClass();
+       imgptr = p;
        crt_flag = true;
        this->update();
 }
 
+
+
 void GLDrawClass::InitContextCL(void)
 {
 #if 0
index bf5d2b0..3d17cb7 100644 (file)
@@ -116,6 +116,70 @@ void EmuThreadClass::set_tape_play(bool flag)
 #endif
 }
 
+#if defined(USE_FD1) || defined(USE_FD2) || defined(USE_FD3) || defined(USE_FD4) || \
+    defined(USE_FD5) || defined(USE_FD6) || defined(USE_FD7) || defined(USE_FD8)
+
+void EmuThreadClass::do_close_disk(int drv)
+{
+       p_emu->close_disk(drv);
+       p_emu->d88_file[drv].bank_num = 0;
+       p_emu->d88_file[drv].cur_bank = -1;
+}
+
+void EmuThreadClass::do_open_disk(int drv, QString path, int bank)
+{
+   
+   
+        _TCHAR path_shadow[_MAX_PATH];
+   
+       //strncpy(path_shadow, path, _MAX_PATH - 1);
+       strncpy(path_shadow, path.toUtf8().constData(), _MAX_PATH - 1);
+       p_emu->d88_file[drv].bank_num = 0;
+       p_emu->d88_file[drv].cur_bank = -1;
+//     p_emu->d88_file[drv].bank[0].offset = 0;
+
+       if(check_file_extension(path.toUtf8().constData(), ".d88") || check_file_extension(path.toUtf8().constData(), ".d77")) {
+       
+               FILEIO *fio = new FILEIO();
+               if(fio->Fopen(path.toUtf8().constData(), FILEIO_READ_BINARY)) {
+                       try {
+                               fio->Fseek(0, FILEIO_SEEK_END);
+                               int file_size = fio->Ftell(), file_offset = 0;
+                               while(file_offset + 0x2b0 <= file_size && p_emu->d88_file[drv].bank_num < MAX_D88_BANKS) {
+                                       fio->Fseek(file_offset, FILEIO_SEEK_SET);
+                                       char tmp[18];
+                                       memset(tmp, 0x00, sizeof(tmp));
+                                       fio->Fread(tmp, 17, 1);
+                                       memset(p_emu->d88_file[drv].disk_name[p_emu->d88_file[drv].bank_num], 0x00, 128);
+                                       if(strlen(tmp) > 0) Convert_CP932_to_UTF8(p_emu->d88_file[drv].disk_name[p_emu->d88_file[drv].bank_num], tmp, 127, 17);
+
+                                       fio->Fseek(file_offset + 0x1c, FILEIO_SEEK_SET);
+                                       file_offset += fio->FgetUint32_LE();
+                                       p_emu->d88_file[drv].bank_num++;
+                               }
+                               strcpy(p_emu->d88_file[drv].path, path.toUtf8().constData());
+                               if(bank >= p_emu->d88_file[drv].bank_num) bank = p_emu->d88_file[drv].bank_num - 1;
+                               if(bank < 0) bank = 0;
+                               p_emu->d88_file[drv].cur_bank = bank;
+                       }
+                       catch(...) {
+                               bank = 0;
+                               p_emu->d88_file[drv].bank_num = 0;
+                       }
+                       fio->Fclose();
+               }
+               delete fio;
+       } else {
+          bank = 0;
+       }
+       p_emu->open_disk(drv, path.toUtf8().constData(), bank);
+       emit sig_update_recent_disk(drv);
+}
+
+#endif
+
+
+
 void EmuThreadClass::print_framerate(int frames)
 {
        if(frames >= 0) draw_frames += frames;
@@ -292,10 +356,12 @@ DrawThreadClass::DrawThreadClass(QObject *parent) : QThread(parent) {
 
 void DrawThreadClass::doDraw(void)
 {
+       QImage *p;
        p_emu->LockVM();
        draw_frames = p_emu->draw_screen();
-       p_emu->update_screen();// Okay?
+       p = p_emu->getPseudoVramClass(); 
        p_emu->UnlockVM();
+       emit sig_update_screen(p);
        emit sig_draw_frames(draw_frames);
 }
 
@@ -360,6 +426,13 @@ void Ui_MainWindow::LaunchEmuThread(void)
        connect(this, SIGNAL(sig_vm_loadstate()), hRunEmu, SLOT(doLoadState()));
        connect(this, SIGNAL(sig_vm_savestate()), hRunEmu, SLOT(doSaveState()));
 
+#if defined(USE_FD1) || defined(USE_FD2) || defined(USE_FD3) || defined(USE_FD4) || \
+    defined(USE_FD5) || defined(USE_FD6) || defined(USE_FD7) || defined(USE_FD8)
+       connect(this, SIGNAL(sig_open_disk(int, QString, int)), hRunEmu, SLOT(do_open_disk(int, QString, int)));
+       connect(this, SIGNAL(sig_close_disk(int)), hRunEmu, SLOT(do_close_disk(int)));
+       connect(hRunEmu, SIGNAL(sig_update_recent_disk(int)), this, SLOT(do_update_recent_disk(int)));
+#endif
+
        connect(this, SIGNAL(quit_emu_thread()), hRunEmu, SLOT(doExit()));
        connect(hRunEmu, SIGNAL(sig_mouse_enable(bool)),
                this, SLOT(do_set_mouse_enable(bool)));
@@ -385,6 +458,8 @@ void Ui_MainWindow::LaunchEmuThread(void)
        AGAR_DebugLog(AGAR_LOG_DEBUG, "DrawThread : Start.");
        connect(hDrawEmu, SIGNAL(sig_draw_frames(int)), hRunEmu, SLOT(print_framerate(int)));
        connect(hDrawEmu, SIGNAL(message_changed(QString)), this, SLOT(message_status_bar(QString)));
+       connect(hDrawEmu, SIGNAL(sig_update_screen(QImage *)), glv, SLOT(update_screen(QImage *)), Qt::QueuedConnection);
+
        connect(hRunEmu, SIGNAL(sig_draw_thread()), hDrawEmu, SLOT(doDraw()));
        connect(hRunEmu, SIGNAL(quit_draw_thread()), hDrawEmu, SLOT(doExit()));
 
index 835af0b..dd6b2f8 100644 (file)
@@ -14,6 +14,7 @@
 #include <qthread.h>
 #include <QTimer>
 #include <QIcon>
+#include <QImage>
 #include <QString>
 
 #include <SDL2/SDL.h>
@@ -113,6 +114,11 @@ public slots:
        void moved_mouse(int, int);
        void button_pressed_mouse(Qt::MouseButton);
        void button_released_mouse(Qt::MouseButton);
+#if defined(USE_FD1) || defined(USE_FD2) || defined(USE_FD3) || defined(USE_FD4) || \
+    defined(USE_FD5) || defined(USE_FD6) || defined(USE_FD7) || defined(USE_FD8)
+       void do_close_disk(int);
+       void do_open_disk(int, QString, int);
+#endif
 signals:
        int message_changed(QString);
        int sig_draw_thread(void);
@@ -126,6 +132,10 @@ signals:
 #ifdef USE_TAPE_BUTTON
        int sig_tape_play_stat(bool);
 #endif
+#if defined(USE_FD1) || defined(USE_FD2) || defined(USE_FD3) || defined(USE_FD4) || \
+    defined(USE_FD5) || defined(USE_FD6) || defined(USE_FD7) || defined(USE_FD8)
+       int sig_update_recent_disk(int);
+#endif
 };
 
 class JoyThreadClass : public QThread {
@@ -186,6 +196,7 @@ public slots:
 signals:
        int sig_draw_frames(int);
        int message_changed(QString);
+       int sig_update_screen(QImage *);
 };
 
 
index 711323b..80a4862 100644 (file)
@@ -289,7 +289,7 @@ void EMU::update_screen()
        // UpdateScreen
        if(instance_handle != NULL) {
                // In Qt, You should updateGL() inside of widget?
-               instance_handle->update_screen();
+               //instance_handle->update_screen();
        }
 
 #if 0
index 5f2a4e4..e1ec50f 100644 (file)
@@ -452,7 +452,8 @@ public slots:
 #endif
 
 #ifdef USE_FD1
-       void open_disk_dialog(int drv);
+       void open_disk_dialog(int);
+       void do_update_recent_disk(int);
 #endif
 #ifdef USE_CART1
        void open_cart_dialog(int);
@@ -568,6 +569,11 @@ signals:
        int sig_vm_savestate(void);
        int sig_check_grab_mouse(bool);
        int sig_resize_uibar(int, int);
+#if defined(USE_FD1) || defined(USE_FD2) || defined(USE_FD3) || defined(USE_FD4) || \
+    defined(USE_FD5) || defined(USE_FD6) || defined(USE_FD7) || defined(USE_FD8)
+       int sig_open_disk(int, QString, int);
+       int sig_close_disk(int);
+#endif     
 #ifdef SUPPORT_DUMMY_DEVICE_LED
        int sig_led_update(QRectF);
 #endif 
index c8b9e1f..e8b505f 100644 (file)
@@ -30,21 +30,63 @@ int Ui_MainWindow::write_protect_fd(int drv, bool flag)
 #ifdef USE_FD1
 int Ui_MainWindow::set_d88_slot(int drive, int num)
 {
+       QString path;
+       
        if((num < 0) || (num >= MAX_D88_BANKS)) return -1;
+       path = QString::fromUtf8(emu->d88_file[drive].path);
        if(emu && emu->d88_file[drive].cur_bank != num) {
-               //    emu->open_disk(drive, emu->d88_file[drive].path, emu->d88_file[drive].bank[num].offset);
-               emu->open_disk(drive, emu->d88_file[drive].path, num);
+               //emu->open_disk(drive, emu->d88_file[drive].path, num);
+               emit sig_open_disk(drive, path, num);
                if(emu->get_disk_protected(drive)) {
                        actionProtection_ON_FD[drive]->setChecked(true);
                } else {
                        actionProtection_OFF_FD[drive]->setChecked(true);
                }
                action_D88_ListImage_FD[drive][num]->setChecked(true);
-               emu->d88_file[drive].cur_bank = num;
+               //emu->d88_file[drive].cur_bank = num;
        }
        return 0;
 }
 
+void Ui_MainWindow::do_update_recent_disk(int drv)
+{
+       int i;
+       if(emu == NULL) return;
+       if((actionGroup_D88_Image_FD[drv] != NULL) && (emu != NULL)){
+               for(i = 0; i < emu->d88_file[drv].bank_num; i++) {
+                       if(action_D88_ListImage_FD[drv][i] != NULL) { 
+                               action_D88_ListImage_FD[drv][i]->setText(QString::fromUtf8(emu->d88_file[drv].disk_name[i]));
+                               action_D88_ListImage_FD[drv][i]->setVisible(true);
+                               if(i == 0) action_D88_ListImage_FD[drv][i]->setChecked(true);
+                       }
+               }
+               for(; i < MAX_D88_BANKS; i++) {
+                       if(action_D88_ListImage_FD[drv][i] != NULL) { 
+                               action_D88_ListImage_FD[drv][i]->setVisible(false);
+                               //emit action_D88_ListImage_FD[drv][i]->changed();
+                       }
+               }
+                       //actionSelect_D88_Image_FD[drv][0].setChecked(true);
+       }
+       for(i = 0; i < MAX_HISTORY; i++) {
+               if(action_Recent_List_FD[drv][i] != NULL) { 
+                       action_Recent_List_FD[drv][i]->setText(QString::fromUtf8(config.recent_disk_path[drv][i]));
+                       //actiont_Recent_List_FD[drv][i]->changed();
+               }
+       }
+       if(emu->d88_file[drv].cur_bank < emu->d88_file[drv].bank_num) action_D88_ListImage_FD[drv][emu->d88_file[drv].cur_bank]->setChecked(true);
+# if defined(USE_DISK_WRITE_PROTECT)
+       //emu->LockVM();
+       if(emu->get_disk_protected(drv)) {
+               actionProtection_ON_FD[drv]->setChecked(true);
+       } else {
+               actionProtection_OFF_FD[drv]->setChecked(true);
+       }
+       //emu->UnlockVM();
+# endif      
+}
+
+
 int Ui_MainWindow::set_recent_disk(int drv, int num) 
 {
        QString s_path;
@@ -61,76 +103,21 @@ int Ui_MainWindow::set_recent_disk(int drv, int num)
        strncpy(path_shadow, s_path.toUtf8().constData(), PATH_MAX);
    
        if(emu) {
-               close_disk(drv);
-               emu->LockVM();
-               open_disk(drv, path_shadow, 0);
-               if((actionGroup_D88_Image_FD[drv] != NULL) && (emu != NULL)){
-                       for(i = 0; i < emu->d88_file[drv].bank_num; i++) {
-                               if(action_D88_ListImage_FD[drv][i] != NULL) { 
-                                       action_D88_ListImage_FD[drv][i]->setText(QString::fromUtf8(emu->d88_file[drv].disk_name[i]));
-                                       action_D88_ListImage_FD[drv][i]->setVisible(true);
-                                       if(i == 0) action_D88_ListImage_FD[drv][i]->setChecked(true);
-                                       //emit action_D88_ListImage_FD[drv][i]->changed();
-                               }
-                       }
-                       for(; i < MAX_D88_BANKS; i++) {
-                               if(action_D88_ListImage_FD[drv][i] != NULL) { 
-                                       action_D88_ListImage_FD[drv][i]->setVisible(false);
-                                       //emit action_D88_ListImage_FD[drv][i]->changed();
-                               }
-                       }
-                       //actionSelect_D88_Image_FD[drv][0].setChecked(true);
-               }
-               for(i = 0; i < MAX_HISTORY; i++) {
-                       if(action_Recent_List_FD[drv][i] != NULL) { 
-                               action_Recent_List_FD[drv][i]->setText(QString::fromUtf8(config.recent_disk_path[drv][i]));
-                               //actiont_Recent_List_FD[drv][i]->changed();
-                       }
-               }
-               emu->UnlockVM();
-# if defined(USE_DISK_WRITE_PROTECT)
-               emu->LockVM();
-               if(emu->get_disk_protected(drv)) {
-                       actionProtection_ON_FD[drv]->setChecked(true);
-               } else {
-                       actionProtection_OFF_FD[drv]->setChecked(true);
-               }
-               emu->UnlockVM();
-# endif      
+               emit sig_close_disk(drv);
+               //emu->LockVM();
+               //open_disk(drv, path_shadow, 0);
+               emit sig_open_disk(drv, s_path, 0);
+               //emu->UnlockVM();
 # ifdef USE_FD2
                strncpy(path_shadow, s_path.toUtf8().constData(), PATH_MAX);
                if(check_file_extension(path_shadow, ".d88") || check_file_extension(path_shadow, ".d77")) {
                        if(((drv & 1) == 0) && (drv + 1 < MAX_FD) && (1 < emu->d88_file[drv].bank_num)) {
                                int drv2 = drv + 1;
-                               close_disk(drv2);
-                               emu->LockVM();
-                               open_disk(drv2, path_shadow, 1);
+                               emit sig_close_disk(drv2);
+                               //emu->LockVM();
+                               emit sig_open_disk(drv2, s_path, 1);
                                
-                               if((actionGroup_D88_Image_FD[drv2] != NULL) && (emu != NULL)){
-                                       for(i = 0; i < emu->d88_file[drv2].bank_num; i++) {
-                                               if(action_D88_ListImage_FD[drv2][i] != NULL) { 
-                                                       action_D88_ListImage_FD[drv2][i]->setText(QString::fromUtf8(emu->d88_file[drv2].disk_name[i]));
-                                                       if(i == 1) action_D88_ListImage_FD[drv2][i]->setChecked(true);
-                                                       action_D88_ListImage_FD[drv2][i]->setVisible(true);
-                                               }
-                                       }
-                                       for(; i < MAX_D88_BANKS; i++) {
-                                               if(action_D88_ListImage_FD[drv2][i] != NULL) { 
-                                                       action_D88_ListImage_FD[drv2][i]->setVisible(false);
-                                               }
-                                       }
-                                       //if(emu->d88_file[drv2].bank_num > 0) actionSelect_D88_Image_FD[drv2][1].setChecked(true);
-                               }
-                               emu->UnlockVM();
-#  if defined(USE_DISK_WRITE_PROTECT)
-                               emu->LockVM();
-                               if(emu->get_disk_protected(drv2)) {
-                                       actionProtection_ON_FD[drv2]->setChecked(true);
-                               } else {
-                                       actionProtection_OFF_FD[drv2]->setChecked(true);
-                               }
-#  endif
-                               emu->UnlockVM();
+                               //emu->UnlockVM();
                        }
                }
 # endif
@@ -154,76 +141,18 @@ void Ui_MainWindow::_open_disk(int drv, const QString fname)
        // Update List
        strncpy(path_shadow, fname.toUtf8().constData(), PATH_MAX);
        if(emu) {
-               close_disk(drv);
-               emu->LockVM();
-               open_disk(drv, path_shadow, 0);
-               if((actionGroup_D88_Image_FD[drv] != NULL) && (emu != NULL)){
-                       for(i = 0; i < emu->d88_file[drv].bank_num; i++) {
-                               if(action_D88_ListImage_FD[drv][i] != NULL) { 
-                                       action_D88_ListImage_FD[drv][i]->setText(QString::fromUtf8(emu->d88_file[drv].disk_name[i]));
-                                       if(i == 0) action_D88_ListImage_FD[drv][i]->setChecked(true);
-                                       action_D88_ListImage_FD[drv][i]->setVisible(true);
-                                       //emit action_D88_ListImage_FD[drv][i]->changed();
-                               }
-                       }
-                       for(; i < MAX_D88_BANKS; i++) {
-                               if(action_D88_ListImage_FD[drv][i] != NULL) { 
-                                       //actionSelect_D88_Image_FD[drv][i]->setText(emu->d88_file[drv].bank[i].name);
-                                       action_D88_ListImage_FD[drv][i]->setVisible(false);
-                                       //emit action_D88_ListImage_FD[drv][i]->changed();
-                               }
-                       }
-               }
-               for(i = 0; i < MAX_HISTORY; i++) {
-                       if(action_Recent_List_FD[drv][i] != NULL) { 
-                               action_Recent_List_FD[drv][i]->setText(QString::fromUtf8(config.recent_disk_path[drv][i]));
-                               //actiont_Recent_List_FD[drv][i]->changed();
-                       }
-               }
-               emu->UnlockVM();
-# if defined(USE_DISK_WRITE_PROTECT)
-               emu->LockVM();
-               if(emu->get_disk_protected(drv)) {
-                       actionProtection_ON_FD[drv]->setChecked(true);
-               } else {
-                 actionProtection_OFF_FD[drv]->setChecked(true);
-               }
-# endif
-               emu->UnlockVM();
+               emit sig_close_disk(drv);
+               //emu->LockVM();
+               emit sig_open_disk(drv, fname, 0);
        }
 # ifdef USE_FD2
        if(check_file_extension(path_shadow, ".d88") || check_file_extension(path_shadow, ".d77")) {
                if(((drv & 1) == 0) && (drv + 1 < MAX_FD) && (1 < emu->d88_file[drv].bank_num)) {
                        int drv2 = drv + 1;
-                       close_disk(drv2);
-                       emu->LockVM();
+                       emit sig_close_disk(drv2);
+                       //emu->LockVM();
                        strncpy(path_shadow, fname.toUtf8().constData(), PATH_MAX);
-                       open_disk(drv2, path_shadow, 1);
-             
-                       if((actionGroup_D88_Image_FD[drv2] != NULL) && (emu != NULL)){
-                               for(i = 0; i < emu->d88_file[drv2].bank_num; i++) {
-                                       if(action_D88_ListImage_FD[drv2][i] != NULL) { 
-                                               action_D88_ListImage_FD[drv2][i]->setText(QString::fromUtf8(emu->d88_file[drv2].disk_name[i]));
-                                               if(i == 1) action_D88_ListImage_FD[drv2][i]->setChecked(true);
-                                               action_D88_ListImage_FD[drv2][i]->setVisible(true);
-                                       }
-                               }
-                               for(; i < MAX_D88_BANKS; i++) {
-                                       if(action_D88_ListImage_FD[drv2][i] != NULL) { 
-                                               action_D88_ListImage_FD[drv2][i]->setVisible(false);
-                                       }
-                               }
-                       }
-                       emu->UnlockVM();
-# if defined(USE_DISK_WRITE_PROTECT)
-                       emu->LockVM();
-                       if(emu->get_disk_protected(drv2)) {
-                               actionProtection_ON_FD[drv2]->setChecked(true);
-                       } else {
-                               actionProtection_OFF_FD[drv2]->setChecked(true);
-                       }
-# endif
-                       emu->UnlockVM();
+                       emit sig_open_disk(drv2, fname, 1);
                }
        }
 # endif
@@ -236,7 +165,7 @@ void Ui_MainWindow::eject_fd(int drv)
 #ifdef USE_FD1
        if(emu) {
                //      emu->LockVM();
-               close_disk(drv);
+               emit sig_close_disk(drv);
                for(i = 0; i < MAX_D88_BANKS; i++) {
                        if(action_D88_ListImage_FD[drv][i] != NULL) { 
                                action_D88_ListImage_FD[drv][i]->setVisible(false);