X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=Pico%2FCart.c;h=f2683ca8f5c5ac22ca01a08a0aa5b243043937d6;hb=1cb1584b86a5679b8d32ccfc190f6e76c920810f;hp=e616622a4488c996ae384c2aadbfc8ca9581539b;hpb=945c2fdcfda07a12c9210a90ab2e809bf4d33e6f;p=picodrive.git diff --git a/Pico/Cart.c b/Pico/Cart.c index e616622..f2683ca 100644 --- a/Pico/Cart.c +++ b/Pico/Cart.c @@ -15,9 +15,13 @@ static char *rom_exts[] = { "bin", "gen", "smd", "iso" }; +void (*PicoCartUnloadHook)(void) = NULL; + void (*PicoCartLoadProgressCB)(int percent) = NULL; void (*PicoCDLoadProgressCB)(int percent) = NULL; // handled in Pico/cd/cd_file.c +static void PicoCartDetect(void); + /* cso struct */ typedef struct _cso_struct { @@ -133,6 +137,9 @@ zip_failed: if (f == NULL) goto cso_failed; + /* we use our own buffering */ + setvbuf(f, NULL, _IONBF, 0); + cso = malloc(sizeof(*cso)); if (cso == NULL) goto cso_failed; @@ -199,6 +206,7 @@ cso_failed: file->size = ftell(f); file->type = PMT_UNCOMPRESSED; fseek(f, 0, SEEK_SET); + return file; } @@ -487,16 +495,27 @@ int PicoCartInsert(unsigned char *rom,unsigned int romsize) // notaz: add a 68k "jump one op back" opcode to the end of ROM. // This will hang the emu, but will prevent nasty crashes. // note: 4 bytes are padded to every ROM - if(rom != NULL) + if (rom != NULL) *(unsigned long *)(rom+romsize) = 0xFFFE4EFA; // 4EFA FFFE byteswapped Pico.rom=rom; Pico.romsize=romsize; + if (SRam.data) { + free(SRam.data); + SRam.data = NULL; + } + + if (PicoCartUnloadHook != NULL) { + PicoCartUnloadHook(); + PicoCartUnloadHook = NULL; + } + PicoMemResetHooks(); PicoDmaHook = NULL; PicoResetHook = NULL; PicoLineHook = NULL; + PicoLoadStateHook = NULL; carthw_chunks = NULL; PicoMemReset(); @@ -511,12 +530,16 @@ int PicoCartInsert(unsigned char *rom,unsigned int romsize) else PicoMemSetup(); PicoMemReset(); - return PicoReset(1); + PicoPower(); + return 0; } -int PicoUnloadCart(unsigned char* romdata) +int PicoCartUnload(void) { - free(romdata); + if (Pico.rom != NULL) { + free(Pico.rom); + Pico.rom=NULL; + } return 0; } @@ -535,11 +558,13 @@ static int name_cmp(const char *name) return rom_strcmp(0x150, name); } -/* various cart-specific things, which can't be handled by generic code */ -void PicoCartDetect(void) +/* + * various cart-specific things, which can't be handled by generic code + * (maybe I should start using CRC for this stuff?) + */ +static void PicoCartDetect(void) { int sram_size = 0, csum; - if(SRam.data) free(SRam.data); SRam.data=0; Pico.m.sram_reg = 0; csum = PicoRead32(0x18c) & 0xffff; @@ -573,10 +598,16 @@ void PicoCartDetect(void) sram_size = 0x004000; } + // this game actually doesn't have SRAM, but some weird protection + if (rom_strcmp(0x120, "PUGGSY") == 0) + { + SRam.start = SRam.end = sram_size = 0; + } + if (sram_size) { SRam.data = (unsigned char *) calloc(sram_size, 1); - if(!SRam.data) return; + if (SRam.data == NULL) return; } SRam.changed = 0; @@ -633,20 +664,40 @@ void PicoCartDetect(void) SRam.eeprom_bit_out= 7; } + // SVP detection + else if (name_cmp("Virtua Racing") == 0 || + name_cmp("VIRTUA RACING") == 0) + { + PicoSVPStartup(); + } + + // Detect 12-in-1 mapper + else if ((name_cmp("ROBOCOP 3") == 0 && Pico.romsize == 0x200000) || + (rom_strcmp(0x160, "FLICKY") == 0 && Pico.romsize >= 0x200000) || + (name_cmp(" SHOVE IT!") == 0 && Pico.romsize >= 0x200000) || + (name_cmp("MS PACMAN") == 0 && Pico.romsize >= 0x200000)) // bad dump? + { + carthw_12in1_startup(); + } + + // Realtec mapper + else if (Pico.romsize == 512*1024 && ( + rom_strcmp(0x94, "THE EARTH DEFEND") == 0 || + rom_strcmp(0xfe, "WISEGAME 11-03-1993") == 0 || // Funny World + rom_strcmp(0x95, "MALLET LEGEND ") == 0)) // Whac-A-Critter + { + carthw_realtec_startup(); + } + // Some games malfunction if SRAM is not filled with 0xff if (name_cmp("DINO DINI'S SOCCER") == 0 || name_cmp("MICRO MACHINES II") == 0) + { memset(SRam.data, 0xff, sram_size); + } // Unusual region 'code' if (rom_strcmp(0x1f0, "EUROPE") == 0) *(int *) (Pico.rom+0x1f0) = 0x20204520; - - // SVP detection - if (name_cmp("Virtua Racing") == 0 || - name_cmp("VIRTUA RACING") == 0) - { - PicoSVPInit(); - } }