bugfixes, CD swap, autorepeat
[libpicofe.git] / gp2x / emu.c
index 99357b2..c16b658 100644 (file)
@@ -156,7 +156,7 @@ int find_bios(int region, char **bios_file)
 \r
 /* checks if romFileName points to valid MegaCD image\r
  * if so, checks for suitable BIOS */\r
-static int cd_check(char **bios_file)\r
+int emu_cd_check(char **bios_file)\r
 {\r
        unsigned char buf[32];\r
        pm_file *cd_f;\r
@@ -177,7 +177,7 @@ static int cd_check(char **bios_file)
                return 0;\r
        }\r
 \r
-       /* it seems we have a CD image here. Try to detect region and load a suitable BIOS now.. */\r
+       /* it seems we have a CD image here. Try to detect region now.. */\r
        pm_seek(cd_f, (type == 1) ? 0x100+0x10B : 0x110+0x10B, SEEK_SET);\r
        pm_read(buf, 1, cd_f);\r
        pm_close(cd_f);\r
@@ -193,7 +193,9 @@ static int cd_check(char **bios_file)
                printf("overrided region to %s\n", region != 4 ? (region == 8 ? "EU" : "JAP") : "USA");\r
        }\r
 \r
-       if(find_bios(region, bios_file))\r
+       if (bios_file == NULL) return type;\r
+\r
+       if (find_bios(region, bios_file))\r
                 return type;   // CD and BIOS detected\r
 \r
        return -1;              // CD detected but load failed\r
@@ -271,7 +273,7 @@ int emu_ReloadRom(void)
        }\r
 \r
        // check for MegaCD image\r
-       cd_state = cd_check(&used_rom_name);\r
+       cd_state = emu_cd_check(&used_rom_name);\r
        if (cd_state > 0) {\r
                PicoMCD |= 1;\r
                get_ext(used_rom_name, ext);\r
@@ -381,6 +383,7 @@ int emu_ReloadRom(void)
 \r
 \r
 static void emu_msg_cb(const char *msg);\r
+static void emu_msg_tray_open(void);\r
 \r
 void emu_Init(void)\r
 {\r
@@ -399,8 +402,8 @@ void emu_Init(void)
 \r
        PicoInit();\r
        PicoMessage = emu_msg_cb;\r
-\r
-//     logf = fopen("log.txt", "w");\r
+       PicoMCDopenTray = emu_msg_tray_open;\r
+       PicoMCDcloseTray = menu_loop_tray;\r
 }\r
 \r
 \r
@@ -528,8 +531,9 @@ int emu_ReadConfig(int game)
        }\r
        scaling_update();\r
        // some sanity checks\r
-       if (currentConfig.CPUclock < 1 || currentConfig.CPUclock > 4096) currentConfig.CPUclock = 200;\r
+       if (currentConfig.CPUclock < 10 || currentConfig.CPUclock > 4096) currentConfig.CPUclock = 200;\r
        if (currentConfig.gamma < 10 || currentConfig.gamma > 300) currentConfig.gamma = 100;\r
+       if (currentConfig.volume < 0 || currentConfig.volume > 99) currentConfig.volume = 50;\r
        // if volume keys are unbound, bind them to volume control\r
        if (!currentConfig.KeyBinds[23] && !currentConfig.KeyBinds[22]) {\r
                currentConfig.KeyBinds[23] = 1<<29; // vol up\r
@@ -603,7 +607,6 @@ void emu_Deinit(void)
        free(framebuff);\r
 \r
        PicoExit();\r
-//     fclose(logf);\r
 \r
        // restore gamma\r
        if (gp2x_old_gamma != 100)\r
@@ -824,6 +827,12 @@ static void emu_state_cb(const char *str)
        blit("", str);\r
 }\r
 \r
+static void emu_msg_tray_open(void)\r
+{\r
+       strcpy(noticeMsg, "CD tray opened");\r
+       gettimeofday(&noticeMsgTime, 0);\r
+}\r
+\r
 static void RunEvents(unsigned int which)\r
 {\r
        if(which & 0x1800) { // save or load (but not both)\r
@@ -974,7 +983,7 @@ static void updateKeys(void)
        if(events & 0x6000) {\r
                int vol = currentConfig.volume;\r
                if (events & 0x2000) {\r
-                       if (vol < 90) vol++;\r
+                       if (vol < 99) vol++;\r
                } else {\r
                        if (vol >  0) vol--;\r
                }\r
@@ -1196,7 +1205,7 @@ void emu_Loop(void)
                                if (frames_shown > frames_done) frames_shown = frames_done;\r
                        }\r
                }\r
-#if 1\r
+#if 0\r
                sprintf(fpsbuff, "%05i", Pico.m.frame_count);\r
 #endif\r
                lim_time = (frames_done+1) * target_frametime;\r