X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=Pico%2FCart.c;h=a0d38a0bd91ae2a6a569ea1a7e1c9619856b81c6;hb=d95259bdaaf911218656d8a74b096ff7306034f6;hp=fadf5580eea99093a0c2c2705e8447455d0508e4;hpb=d6114368e1ee2cc4e6f0eb2785a1fce626987897;p=picodrive.git diff --git a/Pico/Cart.c b/Pico/Cart.c index fadf558..a0d38a0 100644 --- a/Pico/Cart.c +++ b/Pico/Cart.c @@ -137,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; @@ -415,7 +418,7 @@ static unsigned char *PicoCartAlloc(int filesize) int alloc_size; unsigned char *rom; - if (PicoMCD & 1) return cd_realloc(NULL, filesize); + if (PicoAHW & PAHW_MCD) return cd_realloc(NULL, filesize); alloc_size=filesize+0x7ffff; if((filesize&0x3fff)==0x200) alloc_size-=0x200; @@ -471,13 +474,17 @@ int PicoCartLoad(pm_file *f,unsigned char **prom,unsigned int *psize) } // maybe we are loading MegaCD BIOS? - if (!(PicoMCD&1) && size == 0x20000 && (!strncmp((char *)rom+0x124, "BOOT", 4) || !strncmp((char *)rom+0x128, "BOOT", 4))) { - PicoMCD |= 1; + if (!(PicoAHW & PAHW_MCD) && size == 0x20000 && (!strncmp((char *)rom+0x124, "BOOT", 4) || + !strncmp((char *)rom+0x128, "BOOT", 4))) { + PicoAHW |= PAHW_MCD; rom = cd_realloc(rom, size); } // Check for SMD: - if ((size&0x3fff)==0x200) { DecodeSmd(rom,size); size-=0x200; } // Decode and byteswap SMD + if (size >= 0x4200 && (size&0x3fff)==0x200 && + ((rom[0x2280] == 'S' && rom[0x280] == 'E') || (rom[0x280] == 'S' && rom[0x2281] == 'E'))) { + DecodeSmd(rom,size); size-=0x200; // Decode and byteswap SMD + } else Byteswap(rom,size); // Just byteswap if (prom) *prom=rom; @@ -508,6 +515,8 @@ int PicoCartInsert(unsigned char *rom,unsigned int romsize) PicoCartUnloadHook = NULL; } + PicoAHW &= PAHW_MCD; + PicoMemResetHooks(); PicoDmaHook = NULL; PicoResetHook = NULL; @@ -517,17 +526,23 @@ int PicoCartInsert(unsigned char *rom,unsigned int romsize) PicoMemReset(); - if (!(PicoMCD & 1)) + if (!(PicoAHW & PAHW_MCD)) PicoCartDetect(); // setup correct memory map for loaded ROM // call PicoMemReset again due to possible memmap change - if (PicoMCD & 1) - PicoMemSetupCD(); - else PicoMemSetup(); + switch (PicoAHW) { + default: + elprintf(EL_STATUS|EL_ANOMALY, "starting in unknown hw configuration: %x", PicoAHW); + case 0: + case PAHW_SVP: PicoMemSetup(); break; + case PAHW_MCD: PicoMemSetupCD(); break; + case PAHW_PICO: PicoMemSetupPico(); break; + } PicoMemReset(); - return PicoReset(1); + PicoPower(); + return 0; } int PicoCartUnload(void) @@ -594,6 +609,12 @@ static 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); @@ -661,9 +682,18 @@ static void PicoCartDetect(void) PicoSVPStartup(); } + // Pico + else if (rom_strcmp(0x100, "SEGA PICO") == 0 || + rom_strcmp(0x100, "IMA IKUNOUJYUKU") == 0) // what is that supposed to mean? + { + PicoInitPico(); + } + // Detect 12-in-1 mapper else if ((name_cmp("ROBOCOP 3") == 0 && Pico.romsize == 0x200000) || - (rom_strcmp(0x160, "FLICKY") == 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(); } @@ -677,6 +707,12 @@ static void PicoCartDetect(void) carthw_realtec_startup(); } + // Radica mapper + else if (name_cmp("KID CHAMELEON") == 0 && Pico.romsize > 0x100000) + { + carthw_radica_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) @@ -685,7 +721,7 @@ static void PicoCartDetect(void) } // Unusual region 'code' - if (rom_strcmp(0x1f0, "EUROPE") == 0) + if (rom_strcmp(0x1f0, "EUROPE") == 0 || rom_strcmp(0x1f0, "Europe") == 0) *(int *) (Pico.rom+0x1f0) = 0x20204520; }