X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=platform%2Fgp2x%2Femu.c;h=e564dfb71629070bdbd83e758af34a3c8315ff03;hb=4f265db77684ec33f9533e7c76734498df03bba4;hp=666537cb08e971bb3cb7af73e93e313cff2a335f;hpb=bf098bc53228f6b5016cb4a6126f4466bfba4e00;p=picodrive.git diff --git a/platform/gp2x/emu.c b/platform/gp2x/emu.c index 666537c..e564dfb 100644 --- a/platform/gp2x/emu.c +++ b/platform/gp2x/emu.c @@ -187,11 +187,11 @@ static int cd_check(char *ext, char **bios_file) } /* it seems we have a CD image here. Try to detect region and load a suitable BIOS now.. */ - fseek(cd_f, (type == 1) ? 0x100 : 0x110, SEEK_SET); + fseek(cd_f, (type == 1) ? 0x100+0x10B : 0x110+0x10B, SEEK_SET); fread(buf, 1, 1, cd_f); fclose(cd_f); - if (buf[0] == 0x64) region = 4; // EU + if (buf[0] == 0x64) region = 8; // EU if (buf[0] == 0xa1) region = 1; // JAP printf("detected %s Sega/Mega CD image with %s region\n", @@ -276,6 +276,7 @@ int emu_ReloadRom(void) // bios_help() ? return 0; } else { + if (PicoMCD & 1) PicoExitMCD(); PicoMCD &= ~1; } @@ -452,10 +453,11 @@ int emu_ReadConfig(int game) // set default config memset(¤tConfig, 0, sizeof(currentConfig)); currentConfig.lastRomFile[0] = 0; - currentConfig.EmuOpt = 0x1f; - currentConfig.PicoOpt = 0x0f; - currentConfig.PsndRate = 22050; + currentConfig.EmuOpt = 0x1f | 0x400; // | cd_leds + currentConfig.PicoOpt = 0x0f | 0xe00; // | use_940 | cd_pcm | cd_cdda + currentConfig.PsndRate = 44100; currentConfig.PicoRegion = 0; // auto + currentConfig.PicoAutoRgnOrder = 0x184; // US, EU, JP currentConfig.Frameskip = -1; // auto currentConfig.CPUclock = 200; currentConfig.volume = 50; @@ -490,6 +492,7 @@ int emu_ReadConfig(int game) PicoOpt = currentConfig.PicoOpt; PsndRate = currentConfig.PsndRate; PicoRegionOverride = currentConfig.PicoRegion; + PicoAutoRgnOrder = currentConfig.PicoAutoRgnOrder; if (PicoOpt & 0x20) { actionNames[ 8] = "Z"; actionNames[ 9] = "Y"; actionNames[10] = "X"; actionNames[11] = "MODE"; @@ -527,6 +530,7 @@ int emu_WriteConfig(int game) currentConfig.PicoOpt = PicoOpt; currentConfig.PsndRate = PsndRate; currentConfig.PicoRegion = PicoRegionOverride; + currentConfig.PicoAutoRgnOrder = PicoAutoRgnOrder; bwrite = fwrite(¤tConfig, 1, sizeof(currentConfig), f); fflush(f); fclose(f); @@ -586,28 +590,30 @@ void osd_text(int x, int y, char *text) static void cd_leds(void) { - static int old_reg = 0; - if (!((Pico_mcd->s68k_regs[0] ^ old_reg) & 3)) return; // no change + // mmu problems? +// static + int old_reg; +// if (!((Pico_mcd->s68k_regs[0] ^ old_reg) & 3)) return; // no change old_reg = Pico_mcd->s68k_regs[0]; if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) { // 8-bit modes unsigned int col_g = (old_reg & 2) ? 0xc0c0c0c0 : 0xe0e0e0e0; unsigned int col_r = (old_reg & 1) ? 0xd0d0d0d0 : 0xe0e0e0e0; - *(unsigned int *)((char *)gp2x_screen + 320*2+306) = - *(unsigned int *)((char *)gp2x_screen + 320*3+306) = - *(unsigned int *)((char *)gp2x_screen + 320*4+306) = col_g; - *(unsigned int *)((char *)gp2x_screen + 320*2+312) = - *(unsigned int *)((char *)gp2x_screen + 320*3+312) = - *(unsigned int *)((char *)gp2x_screen + 320*4+312) = col_r; + *(unsigned int *)((char *)gp2x_screen + 320*2+ 4) = + *(unsigned int *)((char *)gp2x_screen + 320*3+ 4) = + *(unsigned int *)((char *)gp2x_screen + 320*4+ 4) = col_g; + *(unsigned int *)((char *)gp2x_screen + 320*2+12) = + *(unsigned int *)((char *)gp2x_screen + 320*3+12) = + *(unsigned int *)((char *)gp2x_screen + 320*4+12) = col_r; } else { // 16-bit modes - unsigned int *p = (unsigned int *)((short *)gp2x_screen + 320*2+306); + unsigned int *p = (unsigned int *)((short *)gp2x_screen + 320*2+4); unsigned int col_g = (old_reg & 2) ? 0x06000600 : 0; unsigned int col_r = (old_reg & 1) ? 0xc000c000 : 0; - *p++ = col_g; *p++ = col_g; p++; *p++ = col_r; *p++ = col_r; p += 320/2 - 10/2; - *p++ = col_g; *p++ = col_g; p++; *p++ = col_r; *p++ = col_r; p += 320/2 - 10/2; - *p++ = col_g; *p++ = col_g; p++; *p++ = col_r; *p++ = col_r; p += 320/2 - 10/2; + *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += 320/2 - 12/2; + *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += 320/2 - 12/2; + *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += 320/2 - 12/2; } } @@ -771,8 +777,6 @@ static void RunEvents(unsigned int which) } if (do_it) { blit("", (which & 0x1000) ? "LOADING GAME" : "SAVING GAME"); - if(movie_data) { - } emu_SaveLoadGame(which & 0x1000, 0); } @@ -1023,7 +1027,7 @@ void emu_Loop(void) if(PsndRate != PsndRate_old || (PicoOpt&0x20b) != (PicoOpt_old&0x20b) || Pico.m.pal != pal_old || crashed_940) { /* if 940 is turned off, we need it to be put back to sleep */ if (!(PicoOpt&0x200) && ((PicoOpt^PicoOpt_old)&0x200)) { - Reset940(1); + Reset940(1, 2); Pause940(1); } sound_rerate(); @@ -1231,6 +1235,7 @@ if (Pico.m.frame_count == 31563) { // save SRAM if((currentConfig.EmuOpt & 1) && SRam.changed) { + blit("", "Writing SRAM/BRAM.."); emu_SaveLoadGame(0, 1); SRam.changed = 0; } @@ -1260,7 +1265,6 @@ size_t gzWrite2(void *p, size_t _size, size_t _n, void *file) return gzwrite(file, p, _n); } -typedef unsigned int (*STATE_SL_FUNC)(void *, unsigned int, unsigned int, void *); int emu_SaveLoadGame(int load, int sram) { @@ -1269,7 +1273,7 @@ int emu_SaveLoadGame(int load, int sram) // make save filename romfname_ext(saveFname, ""); - if(sram) strcat(saveFname, ".srm"); + if(sram) strcat(saveFname, (PicoMCD&1) ? ".brm" : ".srm"); else { if(state_slot > 0 && state_slot < 10) sprintf(saveFname, "%s.%i", saveFname, state_slot); strcat(saveFname, ".mds"); @@ -1279,30 +1283,41 @@ int emu_SaveLoadGame(int load, int sram) if(sram) { FILE *sramFile; - int sram_size = SRam.end-SRam.start+1; - if(SRam.reg_back & 4) sram_size=0x2000; - if(!SRam.data) return 0; // SRam forcefully disabled for this game + int sram_size; + unsigned char *sram_data; + if (PicoMCD&1) { + sram_size = 0x2000; + sram_data = Pico_mcd->bram; + } else { + sram_size = SRam.end-SRam.start+1; + if(SRam.reg_back & 4) sram_size=0x2000; + sram_data = SRam.data; + } + if(!sram_data) return 0; // SRam forcefully disabled for this game + if(load) { sramFile = fopen(saveFname, "rb"); if(!sramFile) return -1; - fread(SRam.data, 1, sram_size, sramFile); + fread(sram_data, 1, sram_size, sramFile); fclose(sramFile); } else { // sram save needs some special processing // see if we have anything to save for(; sram_size > 0; sram_size--) - if(SRam.data[sram_size-1]) break; + if(sram_data[sram_size-1]) break; if(sram_size) { sramFile = fopen(saveFname, "wb"); - ret = fwrite(SRam.data, 1, sram_size, sramFile); + ret = fwrite(sram_data, 1, sram_size, sramFile); ret = (ret != sram_size) ? -1 : 0; fclose(sramFile); sync(); } } return ret; - } else { + } + else + { void *PmovFile = NULL; // try gzip first if(currentConfig.EmuOpt & 8) { @@ -1310,26 +1325,34 @@ int emu_SaveLoadGame(int load, int sram) if( (PmovFile = gzopen(saveFname, load ? "rb" : "wb")) ) { areaRead = gzRead2; areaWrite = gzWrite2; + areaEof = (areaeof *) gzeof; + areaSeek = (areaseek *) gzseek; if(!load) gzsetparams(PmovFile, 9, Z_DEFAULT_STRATEGY); } else saveFname[strlen(saveFname)-3] = 0; } if(!PmovFile) { // gzip failed or was disabled if( (PmovFile = fopen(saveFname, load ? "rb" : "wb")) ) { - areaRead = (STATE_SL_FUNC) fread; - areaWrite = (STATE_SL_FUNC) fwrite; + areaRead = (arearw *) fread; + areaWrite = (arearw *) fwrite; + areaEof = (areaeof *) feof; + areaSeek = (areaseek *) fseek; } } if(PmovFile) { - PmovState(load ? 6 : 5, PmovFile); - strcpy(noticeMsg, load ? "GAME LOADED " : "GAME SAVED "); + ret = PmovState(load ? 6 : 5, PmovFile); if(areaRead == gzRead2) gzclose(PmovFile); else fclose ((FILE *) PmovFile); PmovFile = 0; if (!load) sync(); else Pico.m.dirtyPal=1; - } else { + } + else ret = -1; + if (!ret) + strcpy(noticeMsg, load ? "GAME LOADED " : "GAME SAVED "); + else + { strcpy(noticeMsg, load ? "LOAD FAILED " : "SAVE FAILED "); ret = -1; }