X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=Pico%2FCart.c;h=1dc3eae2d66e9897152698ad6f9443aa74994a8c;hb=9037e45d9f2752fdd6ebbc01328148839403a84f;hp=25bb96106b2559325a7b7330c06bb2428b788c04;hpb=1ca2ea4f60d990a4240a387fdde78a87f77f30f1;p=picodrive.git diff --git a/Pico/Cart.c b/Pico/Cart.c index 25bb961..1dc3eae 100644 --- a/Pico/Cart.c +++ b/Pico/Cart.c @@ -20,6 +20,8 @@ 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 { @@ -135,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; @@ -201,6 +206,7 @@ cso_failed: file->size = ftell(f); file->type = PMT_UNCOMPRESSED; fseek(f, 0, SEEK_SET); + return file; } @@ -412,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; @@ -468,8 +474,9 @@ 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); } @@ -489,17 +496,24 @@ 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; } + PicoAHW &= ~PAHW_SVP; + PicoMemResetHooks(); PicoDmaHook = NULL; PicoResetHook = NULL; @@ -509,17 +523,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) @@ -550,10 +570,9 @@ static int name_cmp(const char *name) * various cart-specific things, which can't be handled by generic code * (maybe I should start using CRC for this stuff?) */ -void PicoCartDetect(void) +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; @@ -587,10 +606,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; @@ -654,9 +679,18 @@ 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(); }