add watchdog thread to detect lockups
[pcsx_rearmed.git] / frontend / main.c
index 7b45983..cb37bd7 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "main.h"
 #include "plugin.h"
+#include "plugin_lib.h"
 #include "pcnt.h"
 #include "menu.h"
 #include "../libpcsxcore/misc.h"
@@ -61,15 +62,16 @@ static void CheckSubDir() {
 
 void set_cd_image(const char *fname)
 {
-       const char *ext;
-       int len;
+       const char *ext = NULL;
        
-       len = strlen(fname);
-       ext = fname;
-       if (len > 2)
-               ext = fname + len - 2;
+       if (fname != NULL) {
+               int len = strlen(fname);
+               ext = fname;
+               if (len > 2)
+                       ext = fname + len - 2;
+       }
 
-       if (strcasecmp(ext, ".z") == 0) {
+       if (ext && strcasecmp(ext, ".z") == 0) {
                SetIsoFile(NULL);
                cdrcimg_set_fname(fname);
                strcpy(Config.Cdr, "builtin_cdrcimg");
@@ -169,7 +171,7 @@ int main(int argc, char *argv[])
        MAKE_PATH(Config.Mcd1, MEMCARD_DIR, "card1.mcd");
        MAKE_PATH(Config.Mcd2, MEMCARD_DIR, "card2.mcd");
        strcpy(Config.Bios, "HLE");
-       strcpy(Config.BiosDir, "./");
+       strcpy(Config.BiosDir, "bios");
 
        strcpy(Config.PluginsDir, "plugins");
        strcpy(Config.Gpu, "builtin_gpu");
@@ -242,6 +244,8 @@ int main(int argc, char *argv[])
        else
                menu_loop();
 
+       pl_start_watchdog();
+
        while (1)
        {
                psxCpu->Execute();
@@ -274,11 +278,23 @@ void StartGui() {
         printf("StartGui\n");
 }
 
+static void dummy_lace()
+{
+}
+
 void SysReset() {
+       // rearmed hack: EmuReset() runs some code when real BIOS is used,
+       // but we usually do reset from menu while GPU is not open yet,
+       // so we need to prevent updateLace() call..
+       void *real_lace = GPU_updateLace;
+       GPU_updateLace = dummy_lace;
+
        EmuReset();
 
        // hmh core forgets this
        CDR_stop();
+
+       GPU_updateLace = real_lace;
 }
 
 void SysClose() {