psp fixes, gamma
[libpicofe.git] / common / emu.c
index 9e07260..71f6716 100644 (file)
@@ -137,6 +137,19 @@ int emu_findBios(int region, char **bios_file)
        }\r
 }\r
 \r
+/* check if the name begins with BIOS name */\r
+static int emu_isBios(const char *name)\r
+{\r
+       int i;\r
+       for (i = 0; i < sizeof(biosfiles_us)/sizeof(biosfiles_us[0]); i++)\r
+               if (strstr(name, biosfiles_us[i]) != NULL) return 1;\r
+       for (i = 0; i < sizeof(biosfiles_eu)/sizeof(biosfiles_eu[0]); i++)\r
+               if (strstr(name, biosfiles_eu[i]) != NULL) return 1;\r
+       for (i = 0; i < sizeof(biosfiles_jp)/sizeof(biosfiles_jp[0]); i++)\r
+               if (strstr(name, biosfiles_jp[i]) != NULL) return 1;\r
+       return 0;\r
+}\r
+\r
 /* checks if romFileName points to valid MegaCD image\r
  * if so, checks for suitable BIOS */\r
 int emu_cdCheck(int *pregion)\r
@@ -285,7 +298,7 @@ int emu_ReloadRom(void)
                return 0;\r
        }\r
 \r
-       menu_romload_prepare(used_rom_name);\r
+       menu_romload_prepare(used_rom_name); // also CD load\r
 \r
        if(rom_data) {\r
                free(rom_data);\r
@@ -301,7 +314,6 @@ int emu_ReloadRom(void)
                return 0;\r
        }\r
        pm_close(rom);\r
-       menu_romload_end();\r
 \r
        // detect wrong files (Pico crashes on very small files), also see if ROM EP is good\r
        if(rom_size <= 0x200 || strncmp((char *)rom_data, "Pico", 4) == 0 ||\r
@@ -309,6 +321,7 @@ int emu_ReloadRom(void)
                if (rom_data) free(rom_data);\r
                rom_data = 0;\r
                sprintf(menuErrorMsg, "Not a ROM selected.");\r
+               menu_romload_end();\r
                return 0;\r
        }\r
 \r
@@ -321,6 +334,7 @@ int emu_ReloadRom(void)
        lprintf("PicoCartInsert(%p, %d);\n", rom_data, rom_size);\r
        if(PicoCartInsert(rom_data, rom_size)) {\r
                sprintf(menuErrorMsg, "Failed to load ROM.");\r
+               menu_romload_end();\r
                return 0;\r
        }\r
 \r
@@ -332,13 +346,19 @@ int emu_ReloadRom(void)
                if (ret != 0) {\r
                        sprintf(menuErrorMsg, "Insert_CD() failed, invalid CD image?");\r
                        lprintf("%s\n", menuErrorMsg);\r
+                       menu_romload_end();\r
                        return 0;\r
                }\r
        }\r
 \r
-       // emu_ReadConfig() might have messed currentConfig.lastRomFile\r
-       strncpy(currentConfig.lastRomFile, romFileName, sizeof(currentConfig.lastRomFile)-1);\r
-       currentConfig.lastRomFile[sizeof(currentConfig.lastRomFile)-1] = 0;\r
+       menu_romload_end();\r
+\r
+       if (!emu_isBios(romFileName))\r
+       {\r
+               // emu_ReadConfig() might have messed currentConfig.lastRomFile\r
+               strncpy(currentConfig.lastRomFile, romFileName, sizeof(currentConfig.lastRomFile)-1);\r
+               currentConfig.lastRomFile[sizeof(currentConfig.lastRomFile)-1] = 0;\r
+       }\r
 \r
        if (PicoPatches) {\r
                PicoPatchPrepare();\r
@@ -448,7 +468,11 @@ int emu_ReadConfig(int game, int no_defaults)
        //scaling_update();\r
        // some sanity checks\r
        if (currentConfig.CPUclock < 10 || currentConfig.CPUclock > 4096) currentConfig.CPUclock = 200;\r
+#ifdef PSP\r
+       if (currentConfig.gamma < -4 || currentConfig.gamma >  16) currentConfig.gamma = 0;\r
+#else\r
        if (currentConfig.gamma < 10 || currentConfig.gamma > 300) currentConfig.gamma = 100;\r
+#endif\r
        if (currentConfig.volume < 0 || currentConfig.volume > 99) currentConfig.volume = 50;\r
 #ifdef __GP2X__\r
        // if volume keys are unbound, bind them to volume control\r