X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=gp2x%2Femu.c;h=eca0dc4d99247b6c437ce35c25de687fc41368aa;hb=9e68ce27d43539d2699b00102d62cec9fa7c0c5b;hp=c16b65817a4b852a411b988e828e540e9bec792e;hpb=5e2e14f284d1abbee9f212f75d6766a5825c7ada;p=libpicofe.git diff --git a/gp2x/emu.c b/gp2x/emu.c index c16b658..eca0dc4 100644 --- a/gp2x/emu.c +++ b/gp2x/emu.c @@ -1,4 +1,4 @@ -// (c) Copyright 2006 notaz, All rights reserved. +// (c) Copyright 2006-2007 notaz, All rights reserved. // Free for non-commercial use. // For commercial use, separate licencing terms must be obtained. @@ -272,6 +272,9 @@ int emu_ReloadRom(void) get_ext(romFileName, ext); } + if ((PicoMCD & 1) && Pico_mcd != NULL) + Stop_CD(); + // check for MegaCD image cd_state = emu_cd_check(&used_rom_name); if (cd_state > 0) { @@ -307,7 +310,7 @@ int emu_ReloadRom(void) // detect wrong files (Pico crashes on very small files), also see if ROM EP is good if(rom_size <= 0x200 || strncmp((char *)rom_data, "Pico", 4) == 0 || - ((*(unsigned short *)(rom_data+4)<<16)|(*(unsigned short *)(rom_data+6))) >= (int)rom_size) { + ((*(unsigned char *)(rom_data+4)<<16)|(*(unsigned short *)(rom_data+6))) >= (int)rom_size) { if (rom_data) free(rom_data); rom_data = 0; sprintf(menuErrorMsg, "Not a ROM selected."); @@ -479,8 +482,8 @@ int emu_ReadConfig(int game) // set default config memset(¤tConfig, 0, sizeof(currentConfig)); currentConfig.lastRomFile[0] = 0; - currentConfig.EmuOpt = 0x1f | 0x400; // | cd_leds - currentConfig.PicoOpt = 0x0f | 0xe00; // | use_940 | cd_pcm | cd_cdda + currentConfig.EmuOpt = 0x1f | 0x600; // | confirm_save, cd_leds + currentConfig.PicoOpt = 0x0f | 0xe00; // | use_940, cd_pcm, cd_cdda currentConfig.PsndRate = 22050; // 44100; currentConfig.PicoRegion = 0; // auto currentConfig.PicoAutoRgnOrder = 0x184; // US, EU, JP @@ -837,9 +840,11 @@ static void RunEvents(unsigned int which) { if(which & 0x1800) { // save or load (but not both) int do_it = 1; - if (!(which & 0x1000) && (currentConfig.EmuOpt & 0x200) && emu_check_save_file(state_slot)) { + if ( emu_check_save_file(state_slot) && + (( (which & 0x1000) && (currentConfig.EmuOpt & 0x800)) || // load + (!(which & 0x1000) && (currentConfig.EmuOpt & 0x200))) ) { // save unsigned long keys; - blit("", "OVERWRITE SAVE? (Y=yes, X=no)"); + blit("", (which & 0x1000) ? "LOAD STATE? (Y=yes, X=no)" : "OVERWRITE SAVE? (Y=yes, X=no)"); while( !((keys = gp2x_joystick_read(1)) & (GP2X_X|GP2X_Y)) ) usleep(50*1024); if (keys & GP2X_X) do_it = 0; @@ -1323,7 +1328,7 @@ if (Pico.m.frame_count == 31563) { // save SRAM if((currentConfig.EmuOpt & 1) && SRam.changed) { - osd_text(4, 232, "Writing SRAM/BRAM.."); + emu_state_cb("Writing SRAM/BRAM.."); emu_SaveLoadGame(0, 1); SRam.changed = 0; } @@ -1454,29 +1459,42 @@ int emu_SaveLoadGame(int load, int sram) FILE *sramFile; int sram_size; unsigned char *sram_data; + int truncate = 1; if (PicoMCD&1) { - sram_size = 0x2000; - sram_data = Pico_mcd->bram; + if (PicoOpt&0x8000) { // MCD RAM cart? + sram_size = 0x12000; + sram_data = SRam.data; + if (sram_data) + memcpy32((int *)sram_data, (int *)Pico_mcd->bram, 0x2000/4); + } else { + sram_size = 0x2000; + sram_data = Pico_mcd->bram; + truncate = 0; // the .brm may contain RAM cart data after normal brm + } } 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 (!sram_data) return 0; // SRam forcefully disabled for this game - if(load) { + if (load) { sramFile = fopen(saveFname, "rb"); if(!sramFile) return -1; fread(sram_data, 1, sram_size, sramFile); fclose(sramFile); + if ((PicoMCD&1) && (PicoOpt&0x8000)) + memcpy32((int *)Pico_mcd->bram, (int *)sram_data, 0x2000/4); } 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; + for (; sram_size > 0; sram_size--) + if (sram_data[sram_size-1]) break; - if(sram_size) { - sramFile = fopen(saveFname, "wb"); + if (sram_size) { + sramFile = fopen(saveFname, truncate ? "wb" : "r+b"); + if (!sramFile) sramFile = fopen(saveFname, "wb"); // retry + if (!sramFile) return -1; ret = fwrite(sram_data, 1, sram_size, sramFile); ret = (ret != sram_size) ? -1 : 0; fclose(sramFile);