X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=pico%2Fcart.c;h=8d30a93b4a1bb613877f55299e0b0556f23a20e3;hb=b081408f66662068a3d274f696bdabba5186b68e;hp=26fb59bb81fafa9cfa334b150df4c7148d7f327c;hpb=83ff19ec52ff47992b5d6ceda3900b914eda2123;p=picodrive.git diff --git a/pico/cart.c b/pico/cart.c index 26fb59b..8d30a93 100644 --- a/pico/cart.c +++ b/pico/cart.c @@ -13,6 +13,7 @@ #include "../unzip/unzip_stream.h" +static int rom_alloc_size; static const char *rom_exts[] = { "bin", "gen", "smd", "iso", "sms", "gg", "sg" }; void (*PicoCartUnloadHook)(void); @@ -21,7 +22,7 @@ void (*PicoCartMemSetup)(void); void (*PicoCartLoadProgressCB)(int percent) = NULL; void (*PicoCDLoadProgressCB)(const char *fname, int percent) = NULL; // handled in Pico/cd/cd_file.c -static void PicoCartDetect(void); +static void PicoCartDetect(const char *carthw_cfg); /* cso struct */ typedef struct _cso_struct @@ -425,22 +426,10 @@ static int DecodeSmd(unsigned char *data,int len) return 0; } -static unsigned char *cd_realloc(void *old, int filesize) -{ - unsigned char *rom; - rom=realloc(old, sizeof(mcd_state)); - if (rom) memset(rom+0x20000, 0, sizeof(mcd_state)-0x20000); - return rom; -} - static unsigned char *PicoCartAlloc(int filesize, int is_sms) { - int alloc_size; unsigned char *rom; - if (PicoAHW & PAHW_MCD) - return cd_realloc(NULL, filesize); - if (is_sms) { // make size power of 2 for easier banking handling int s = 0, tmp = filesize; @@ -448,18 +437,24 @@ static unsigned char *PicoCartAlloc(int filesize, int is_sms) s++; if (filesize > (1 << s)) s++; - alloc_size = 1 << s; + rom_alloc_size = 1 << s; } else { + // make alloc size at least sizeof(mcd_state), + // in case we want to switch to CD mode + if (filesize < sizeof(mcd_state)) + filesize = sizeof(mcd_state); + // align to 512K for memhandlers - alloc_size = (filesize + 0x7ffff) & ~0x7ffff; + rom_alloc_size = (filesize + 0x7ffff) & ~0x7ffff; } - if (alloc_size - filesize < 4) - alloc_size += 4; // padding for out-of-bound exec protection + if (rom_alloc_size - filesize < 4) + rom_alloc_size += 4; // padding for out-of-bound exec protection // Allocate space for the rom plus padding - rom = calloc(alloc_size, 1); + // use special address for 32x dynarec + rom = plat_mmap(0x02000000, rom_alloc_size); return rom; } @@ -513,7 +508,6 @@ int PicoCartLoad(pm_file *f,unsigned char **prom,unsigned int *psize,int is_sms) 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: @@ -541,7 +535,7 @@ int PicoCartLoad(pm_file *f,unsigned char **prom,unsigned int *psize,int is_sms) } // Insert a cartridge: -int PicoCartInsert(unsigned char *rom,unsigned int romsize) +int PicoCartInsert(unsigned char *rom, unsigned int romsize, const char *carthw_cfg) { // notaz: add a 68k "jump one op back" opcode to the end of ROM. // This will hang the emu, but will prevent nasty crashes. @@ -572,7 +566,7 @@ int PicoCartInsert(unsigned char *rom,unsigned int romsize) carthw_chunks = NULL; if (!(PicoAHW & (PAHW_MCD|PAHW_SMS))) - PicoCartDetect(); + PicoCartDetect(carthw_cfg); // setup correct memory map for loaded ROM switch (PicoAHW) { @@ -608,8 +602,8 @@ void PicoCartUnload(void) if (Pico.rom != NULL) { SekFinishIdleDet(); - free(Pico.rom); - Pico.rom=NULL; + plat_munmap(Pico.rom, rom_alloc_size); + Pico.rom = NULL; } } @@ -695,16 +689,16 @@ static int is_expr(const char *expr, char **pr) return 1; } -static void parse_carthw(int *fill_sram) +static void parse_carthw(const char *carthw_cfg, int *fill_sram) { int line = 0, any_checks_passed = 0, skip_sect = 0; int tmp, rom_crc = 0; char buff[256], *p, *r; FILE *f; - f = fopen("carthw.cfg", "r"); + f = fopen(carthw_cfg, "r"); if (f == NULL) { - elprintf(EL_STATUS, "couldn't open carthw.txt!"); + elprintf(EL_STATUS, "couldn't open carthw.cfg!"); return; } @@ -924,7 +918,7 @@ no_checks: /* * various cart-specific things, which can't be handled by generic code */ -static void PicoCartDetect(void) +static void PicoCartDetect(const char *carthw_cfg) { int fill_sram = 0; @@ -954,7 +948,8 @@ static void PicoCartDetect(void) SRam.eeprom_bit_in = 0; SRam.eeprom_bit_out= 0; - parse_carthw(&fill_sram); + if (carthw_cfg != NULL) + parse_carthw(carthw_cfg, &fill_sram); if (SRam.flags & SRF_ENABLED) {