X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=platform%2Fcommon%2Femu.c;h=b7832bbb2302bbca1390751bf44783c961bca285;hb=0336d6438af039e2108adabb861b041bb0d866ba;hp=723dfb74050e3d8c79a37a3c72353f694f117925;hpb=da42200b24749eee63cccf49d87781b861146e9f;p=picodrive.git diff --git a/platform/common/emu.c b/platform/common/emu.c index 723dfb7..b7832bb 100644 --- a/platform/common/emu.c +++ b/platform/common/emu.c @@ -26,12 +26,16 @@ #elif defined(__GIZ__) #include "../gizmondo/giz.h" #define SCREEN_WIDTH 321 - #define SCREEN_BUFFER giz_screen // ? + #define SCREEN_BUFFER giz_screen +#elif defined(PSP) + #include "../psp/psp.h" + #define SCREEN_WIDTH 512 + #define SCREEN_BUFFER psp_screen #endif char *PicoConfigFile = "picoconfig.bin"; currentConfig_t currentConfig; -unsigned char *rom_data = NULL; +int rom_loaded = 0; char noticeMsg[64]; int state_slot = 0; int config_slot = 0, config_slot_current = 0; @@ -133,6 +137,19 @@ int emu_findBios(int region, char **bios_file) } } +/* check if the name begins with BIOS name */ +static int emu_isBios(const char *name) +{ + int i; + for (i = 0; i < sizeof(biosfiles_us)/sizeof(biosfiles_us[0]); i++) + if (strstr(name, biosfiles_us[i]) != NULL) return 1; + for (i = 0; i < sizeof(biosfiles_eu)/sizeof(biosfiles_eu[0]); i++) + if (strstr(name, biosfiles_eu[i]) != NULL) return 1; + for (i = 0; i < sizeof(biosfiles_jp)/sizeof(biosfiles_jp[0]); i++) + if (strstr(name, biosfiles_jp[i]) != NULL) return 1; + return 0; +} + /* checks if romFileName points to valid MegaCD image * if so, checks for suitable BIOS */ int emu_cdCheck(int *pregion) @@ -176,6 +193,7 @@ int emu_ReloadRom(void) { unsigned int rom_size = 0; char *used_rom_name = romFileName; + unsigned char *rom_data = NULL; char ext[5]; pm_file *rom; int ret, cd_state, cd_region, cfg_loaded = 0; @@ -185,7 +203,7 @@ int emu_ReloadRom(void) get_ext(romFileName, ext); // detect wrong extensions - if(!strcmp(ext, ".srm") || !strcmp(ext, "s.gz") || !strcmp(ext, ".mds")) { // s.gz ~ .mds.gz + if (!strcmp(ext, ".srm") || !strcmp(ext, "s.gz") || !strcmp(ext, ".mds")) { // s.gz ~ .mds.gz sprintf(menuErrorMsg, "Not a ROM selected."); return 0; } @@ -193,11 +211,11 @@ int emu_ReloadRom(void) PicoPatchUnload(); // check for movie file - if(movie_data) { + if (movie_data) { free(movie_data); movie_data = 0; } - if(!strcmp(ext, ".gmv")) { + if (!strcmp(ext, ".gmv")) { // check for both gmv and rom int dummy; FILE *movie_file = fopen(romFileName, "rb"); @@ -276,20 +294,17 @@ int emu_ReloadRom(void) } rom = pm_open(used_rom_name); - if(!rom) { + if (!rom) { sprintf(menuErrorMsg, "Failed to open rom."); return 0; } - menu_romload_prepare(used_rom_name); + menu_romload_prepare(used_rom_name); // also CD load - if(rom_data) { - free(rom_data); - rom_data = 0; - rom_size = 0; - } + PicoCartUnload(); + rom_loaded = 0; - if( (ret = PicoCartLoad(rom, &rom_data, &rom_size)) ) { + if ( (ret = PicoCartLoad(rom, &rom_data, &rom_size)) ) { sprintf(menuErrorMsg, "PicoCartLoad() failed."); lprintf("%s\n", menuErrorMsg); pm_close(rom); @@ -297,14 +312,13 @@ int emu_ReloadRom(void) return 0; } pm_close(rom); - menu_romload_end(); // 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 || + if (rom_size <= 0x200 || strncmp((char *)rom_data, "Pico", 4) == 0 || ((*(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."); + menu_romload_end(); return 0; } @@ -315,8 +329,9 @@ int emu_ReloadRom(void) } lprintf("PicoCartInsert(%p, %d);\n", rom_data, rom_size); - if(PicoCartInsert(rom_data, rom_size)) { + if (PicoCartInsert(rom_data, rom_size)) { sprintf(menuErrorMsg, "Failed to load ROM."); + menu_romload_end(); return 0; } @@ -328,13 +343,19 @@ int emu_ReloadRom(void) if (ret != 0) { sprintf(menuErrorMsg, "Insert_CD() failed, invalid CD image?"); lprintf("%s\n", menuErrorMsg); + menu_romload_end(); return 0; } } - // emu_ReadConfig() might have messed currentConfig.lastRomFile - strncpy(currentConfig.lastRomFile, romFileName, sizeof(currentConfig.lastRomFile)-1); - currentConfig.lastRomFile[sizeof(currentConfig.lastRomFile)-1] = 0; + menu_romload_end(); + + if (!emu_isBios(romFileName)) + { + // emu_ReadConfig() might have messed currentConfig.lastRomFile + strncpy(currentConfig.lastRomFile, romFileName, sizeof(currentConfig.lastRomFile)-1); + currentConfig.lastRomFile[sizeof(currentConfig.lastRomFile)-1] = 0; + } if (PicoPatches) { PicoPatchPrepare(); @@ -371,9 +392,10 @@ int emu_ReloadRom(void) emu_noticeMsgUpdated(); // load SRAM for this ROM - if(currentConfig.EmuOpt & 1) + if (currentConfig.EmuOpt & 1) emu_SaveLoadGame(1, 1); + rom_loaded = 1; return 1; } @@ -444,7 +466,11 @@ int emu_ReadConfig(int game, int no_defaults) //scaling_update(); // some sanity checks if (currentConfig.CPUclock < 10 || currentConfig.CPUclock > 4096) currentConfig.CPUclock = 200; +#ifdef PSP + if (currentConfig.gamma < -4 || currentConfig.gamma > 16) currentConfig.gamma = 0; +#else if (currentConfig.gamma < 10 || currentConfig.gamma > 300) currentConfig.gamma = 100; +#endif if (currentConfig.volume < 0 || currentConfig.volume > 99) currentConfig.volume = 50; #ifdef __GP2X__ // if volume keys are unbound, bind them to volume control