region detection, cd states wip, fixes, stuff
[picodrive.git] / platform / gp2x / emu.c
index bea1569..17e7028 100644 (file)
@@ -187,11 +187,11 @@ static int cd_check(char *ext, char **bios_file)
        }\r
 \r
        /* it seems we have a CD image here. Try to detect region and load a suitable BIOS now.. */\r
-       fseek(cd_f, (type == 1) ? 0x100 : 0x110, SEEK_SET);\r
+       fseek(cd_f, (type == 1) ? 0x100+0x10B : 0x110+0x10B, SEEK_SET);\r
        fread(buf, 1, 1, cd_f);\r
        fclose(cd_f);\r
 \r
-       if (buf[0] == 0x64) region = 4; // EU\r
+       if (buf[0] == 0x64) region = 8; // EU\r
        if (buf[0] == 0xa1) region = 1; // JAP\r
 \r
        printf("detected %s Sega/Mega CD image with %s region\n",\r
@@ -374,7 +374,7 @@ int emu_ReloadRom(void)
                }\r
        }\r
        gettimeofday(&noticeMsgTime, 0);\r
-\r
+printf("PicoMCD: %x\n", PicoMCD);\r
        // load SRAM for this ROM\r
        if(currentConfig.EmuOpt & 1)\r
                emu_SaveLoadGame(1, 1);\r
@@ -452,10 +452,11 @@ int emu_ReadConfig(int game)
                // set default config\r
                memset(&currentConfig, 0, sizeof(currentConfig));\r
                currentConfig.lastRomFile[0] = 0;\r
-               currentConfig.EmuOpt  = 0x1f;\r
-               currentConfig.PicoOpt = 0x0f;\r
-               currentConfig.PsndRate = 22050;\r
+               currentConfig.EmuOpt  = 0x1f | 0xc00; // | cd_leds | cd_cdda\r
+               currentConfig.PicoOpt = 0x0f | 0x200; // | use_940\r
+               currentConfig.PsndRate = 44100;\r
                currentConfig.PicoRegion = 0; // auto\r
+               currentConfig.PicoAutoRgnOrder = 0x184; // US, EU, JP\r
                currentConfig.Frameskip = -1; // auto\r
                currentConfig.CPUclock = 200;\r
                currentConfig.volume = 50;\r
@@ -490,6 +491,7 @@ int emu_ReadConfig(int game)
        PicoOpt = currentConfig.PicoOpt;\r
        PsndRate = currentConfig.PsndRate;\r
        PicoRegionOverride = currentConfig.PicoRegion;\r
+       PicoAutoRgnOrder = currentConfig.PicoAutoRgnOrder;\r
        if (PicoOpt & 0x20) {\r
                actionNames[ 8] = "Z"; actionNames[ 9] = "Y";\r
                actionNames[10] = "X"; actionNames[11] = "MODE";\r
@@ -527,6 +529,7 @@ int emu_WriteConfig(int game)
                currentConfig.PicoOpt = PicoOpt;\r
                currentConfig.PsndRate = PsndRate;\r
                currentConfig.PicoRegion = PicoRegionOverride;\r
+               currentConfig.PicoAutoRgnOrder = PicoAutoRgnOrder;\r
                bwrite = fwrite(&currentConfig, 1, sizeof(currentConfig), f);\r
                fflush(f);\r
                fclose(f);\r
@@ -586,8 +589,10 @@ void osd_text(int x, int y, char *text)
 \r
 static void cd_leds(void)\r
 {\r
-       static int old_reg = 0;\r
-       if (!((Pico_mcd->s68k_regs[0] ^ old_reg) & 3)) return; // no change\r
+       // mmu problems?\r
+//     static\r
+       int old_reg;\r
+//     if (!((Pico_mcd->s68k_regs[0] ^ old_reg) & 3)) return; // no change\r
        old_reg = Pico_mcd->s68k_regs[0];\r
 \r
        if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) {\r
@@ -1021,7 +1026,7 @@ void emu_Loop(void)
                if(PsndRate != PsndRate_old || (PicoOpt&0x20b) != (PicoOpt_old&0x20b) || Pico.m.pal != pal_old || crashed_940) {\r
                        /* if 940 is turned off, we need it to be put back to sleep */\r
                        if (!(PicoOpt&0x200) && ((PicoOpt^PicoOpt_old)&0x200)) {\r
-                               Reset940(1);\r
+                               Reset940(1, 2);\r
                                Pause940(1);\r
                        }\r
                        sound_rerate();\r
@@ -1229,6 +1234,7 @@ if (Pico.m.frame_count == 31563) {
 \r
        // save SRAM\r
        if((currentConfig.EmuOpt & 1) && SRam.changed) {\r
+               blit("", "Writing SRAM/BRAM..");\r
                emu_SaveLoadGame(0, 1);\r
                SRam.changed = 0;\r
        }\r
@@ -1319,14 +1325,16 @@ int emu_SaveLoadGame(int load, int sram)
                        if( (PmovFile = gzopen(saveFname, load ? "rb" : "wb")) ) {\r
                                areaRead  = gzRead2;\r
                                areaWrite = gzWrite2;\r
+                               areaEof   = (areaeof *) gzeof;\r
                                if(!load) gzsetparams(PmovFile, 9, Z_DEFAULT_STRATEGY);\r
                        } else\r
                                saveFname[strlen(saveFname)-3] = 0;\r
                }\r
                if(!PmovFile) { // gzip failed or was disabled\r
                        if( (PmovFile = fopen(saveFname, load ? "rb" : "wb")) ) {\r
-                               areaRead  = (STATE_SL_FUNC) fread;\r
-                               areaWrite = (STATE_SL_FUNC) fwrite;\r
+                               areaRead  = (arearw *) fread;\r
+                               areaWrite = (arearw *) fwrite;\r
+                               areaEof   = (areaeof *) feof;\r
                        }\r
                }\r
                if(PmovFile) {\r