X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=platform%2Fgp2x%2Femu.c;h=3d6cd3a2ca94d1959a1ab500b549a9e5eaec985c;hb=83bd0b76aba19ff62368cfee76089e15579e3b7c;hp=d9738055517956598d7c54cf4567815e0ac7d420;hpb=68cba51e206ea6089e8ebc04d7dcd9980bc9575c;p=picodrive.git diff --git a/platform/gp2x/emu.c b/platform/gp2x/emu.c index d973805..3d6cd3a 100644 --- a/platform/gp2x/emu.c +++ b/platform/gp2x/emu.c @@ -21,8 +21,9 @@ #include "asmutils.h" #include "cpuctrl.h" -#include "Pico/PicoInt.h" -#include "zlib/zlib.h" +#include +#include +#include #ifdef BENCHMARK @@ -168,31 +169,31 @@ int find_bios(int region, char **bios_file) /* checks if romFileName points to valid MegaCD image * if so, checks for suitable BIOS */ -static int cd_check(char *ext, char **bios_file) +static int cd_check(char **bios_file) { unsigned char buf[32]; - FILE *cd_f; + pm_file *cd_f; int type = 0, region = 4; // 1: Japan, 4: US, 8: Europe - cd_f = fopen(romFileName, "rb"); + cd_f = pm_open(romFileName); if (!cd_f) return 0; // let the upper level handle this - if (fread(buf, 1, 32, cd_f) != 32) { - fclose(cd_f); + if (pm_read(buf, 32, cd_f) != 32) { + pm_close(cd_f); return 0; } if (!strncasecmp("SEGADISCSYSTEM", (char *)buf+0x00, 14)) type = 1; // Sega CD (ISO) if (!strncasecmp("SEGADISCSYSTEM", (char *)buf+0x10, 14)) type = 2; // Sega CD (BIN) if (type == 0) { - fclose(cd_f); + pm_close(cd_f); return 0; } /* it seems we have a CD image here. Try to detect region and load a suitable BIOS now.. */ - fseek(cd_f, (type == 1) ? 0x100+0x10B : 0x110+0x10B, SEEK_SET); - fread(buf, 1, 1, cd_f); - fclose(cd_f); + pm_seek(cd_f, (type == 1) ? 0x100+0x10B : 0x110+0x10B, SEEK_SET); + pm_read(buf, 1, cd_f); + pm_close(cd_f); if (buf[0] == 0x64) region = 8; // EU if (buf[0] == 0xa1) region = 1; // JAP @@ -216,7 +217,7 @@ int emu_ReloadRom(void) unsigned int rom_size = 0; char *used_rom_name = romFileName; char ext[5]; - FILE *rom; + pm_file *rom; int ret, cd_state; printf("emu_ReloadRom(%s)\n", romFileName); @@ -229,6 +230,8 @@ int emu_ReloadRom(void) return 0; } + PicoPatchUnload(); + // check for movie file if(movie_data) { free(movie_data); @@ -269,9 +272,19 @@ int emu_ReloadRom(void) } get_ext(romFileName, ext); } + else if (!strcmp(ext, ".pat")) { + int dummy; + PicoPatchLoad(romFileName); + dummy = try_rfn_cut() || try_rfn_cut(); + if (!dummy) { + sprintf(menuErrorMsg, "Could't find a ROM to patch."); + return 0; + } + get_ext(romFileName, ext); + } // check for MegaCD image - cd_state = cd_check(ext, &used_rom_name); + cd_state = cd_check(&used_rom_name); if (cd_state > 0) { PicoMCD |= 1; get_ext(used_rom_name, ext); @@ -283,7 +296,7 @@ int emu_ReloadRom(void) PicoMCD &= ~1; } - rom = fopen(used_rom_name, "rb"); + rom = pm_open(used_rom_name); if(!rom) { sprintf(menuErrorMsg, "Failed to open rom."); return 0; @@ -295,25 +308,13 @@ int emu_ReloadRom(void) rom_size = 0; } - // zipfile support - if(!strcasecmp(ext, ".zip")) { - fclose(rom); - ret = CartLoadZip(used_rom_name, &rom_data, &rom_size); - if(ret) { - if (ret == 4) strcpy(menuErrorMsg, "No ROMs found in zip."); - else sprintf(menuErrorMsg, "Unzip failed with code %i", ret); - printf("%s\n", menuErrorMsg); - return 0; - } - } else { - if( (ret = PicoCartLoad(rom, &rom_data, &rom_size)) ) { - sprintf(menuErrorMsg, "PicoCartLoad() failed."); - printf("%s\n", menuErrorMsg); - fclose(rom); - return 0; - } - fclose(rom); + if( (ret = PicoCartLoad(rom, &rom_data, &rom_size)) ) { + sprintf(menuErrorMsg, "PicoCartLoad() failed."); + printf("%s\n", menuErrorMsg); + pm_close(rom); + return 0; } + pm_close(rom); // 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 || @@ -351,6 +352,11 @@ int emu_ReloadRom(void) strncpy(currentConfig.lastRomFile, romFileName, sizeof(currentConfig.lastRomFile)-1); currentConfig.lastRomFile[sizeof(currentConfig.lastRomFile)-1] = 0; + if (PicoPatches) { + PicoPatchPrepare(); + PicoPatchApply(); + } + // additional movie stuff if(movie_data) { if(movie_data[0x14] == '6')