#include "../unzip/unzip_stream.h"\r
\r
\r
+static int rom_alloc_size;\r
static const char *rom_exts[] = { "bin", "gen", "smd", "iso", "sms", "gg", "sg" };\r
\r
void (*PicoCartUnloadHook)(void);\r
return 0;\r
}\r
\r
-static unsigned char *cd_realloc(void *old, int filesize)\r
-{\r
- unsigned char *rom;\r
- rom=realloc(old, sizeof(mcd_state));\r
- if (rom) memset(rom+0x20000, 0, sizeof(mcd_state)-0x20000);\r
- return rom;\r
-}\r
-\r
static unsigned char *PicoCartAlloc(int filesize, int is_sms)\r
{\r
- int alloc_size;\r
unsigned char *rom;\r
\r
- if (PicoAHW & PAHW_MCD)\r
- return cd_realloc(NULL, filesize);\r
-\r
if (is_sms) {\r
// make size power of 2 for easier banking handling\r
int s = 0, tmp = filesize;\r
s++;\r
if (filesize > (1 << s))\r
s++;\r
- alloc_size = 1 << s;\r
+ rom_alloc_size = 1 << s;\r
}\r
else {\r
+ // make alloc size at least sizeof(mcd_state),\r
+ // in case we want to switch to CD mode\r
+ if (filesize < sizeof(mcd_state))\r
+ filesize = sizeof(mcd_state);\r
+\r
// align to 512K for memhandlers\r
- alloc_size = (filesize + 0x7ffff) & ~0x7ffff;\r
+ rom_alloc_size = (filesize + 0x7ffff) & ~0x7ffff;\r
}\r
\r
- if (alloc_size - filesize < 4)\r
- alloc_size += 4; // padding for out-of-bound exec protection\r
+ if (rom_alloc_size - filesize < 4)\r
+ rom_alloc_size += 4; // padding for out-of-bound exec protection\r
\r
// Allocate space for the rom plus padding\r
- rom = calloc(alloc_size, 1);\r
+ // use special address for 32x dynarec\r
+ rom = plat_mmap(0x02000000, rom_alloc_size);\r
return rom;\r
}\r
\r
if (!(PicoAHW & PAHW_MCD) && size == 0x20000 && (!strncmp((char *)rom+0x124, "BOOT", 4) ||\r
!strncmp((char *)rom+0x128, "BOOT", 4))) {\r
PicoAHW |= PAHW_MCD;\r
- rom = cd_realloc(rom, size);\r
}\r
\r
// Check for SMD:\r
\r
if (Pico.rom != NULL) {\r
SekFinishIdleDet();\r
- free(Pico.rom);\r
- Pico.rom=NULL;\r
+ plat_munmap(Pico.rom, rom_alloc_size);\r
+ Pico.rom = NULL;\r
}\r
}\r
\r