diff --git a/gwenesis/main/main.c b/gwenesis/main/main.c index cbf9db3f3..74d241fa2 100644 --- a/gwenesis/main/main.c +++ b/gwenesis/main/main.c @@ -233,15 +233,19 @@ void app_main(void) RG_LOGI("Genesis start\n"); - FILE *fp = fopen(app->romPath, "rb"); - if (!fp) - RG_PANIC("Rom load failed"); - fseek(fp, 0, SEEK_END); - size_t rom_size = ftell(fp); - void *rom_data = malloc((rom_size & ~0xFFFF) + 0x10000); - fseek(fp, 0, SEEK_SET); - fread(rom_data, 1, rom_size, fp); - fclose(fp); + size_t rom_size; + void *rom_data; + + if (rg_extension_match(app->romPath, "zip")) + { + if (!rg_storage_unzip_file(app->romPath, NULL, &rom_data, &rom_size)) + RG_PANIC("ROM file unzipping failed!"); + } + else + { + if (!rg_storage_read_file(app->romPath, &rom_data, &rom_size)) + RG_PANIC("ROM load failed!"); + } RG_LOGI("load_cartridge(%p, %d)\n", rom_data, rom_size); load_cartridge(rom_data, rom_size); diff --git a/launcher/main/applications.c b/launcher/main/applications.c index 98fef2fae..5f285c9a9 100644 --- a/launcher/main/applications.c +++ b/launcher/main/applications.c @@ -673,18 +673,18 @@ static void application(const char *desc, const char *name, const char *exts, co void applications_init(void) { - application("Nintendo Entertainment System", "nes", "nes fc fds nsf", "retro-core", 16); - application("Super Nintendo", "snes", "smc sfc", "retro-core", 0); - application("Nintendo Gameboy", "gb", "gb gbc", "retro-core", 0); - application("Nintendo Gameboy Color", "gbc", "gbc gb", "retro-core", 0); + application("Nintendo Entertainment System", "nes", "nes fc fds nsf zip", "retro-core", 16); + application("Super Nintendo", "snes", "smc sfc zip", "retro-core", 0); + application("Nintendo Gameboy", "gb", "gb gbc zip", "retro-core", 0); + application("Nintendo Gameboy Color", "gbc", "gbc gb zip", "retro-core", 0); application("Nintendo Game & Watch", "gw", "gw", "retro-core", 0); // application("Sega SG-1000", "sg1", "sms sg sg1", "retro-core", 0); - application("Sega Master System", "sms", "sms sg", "retro-core", 0); - application("Sega Game Gear", "gg", "gg", "retro-core", 0); - application("Sega Mega Drive", "md", "md gen bin", "gwenesis", 0); - application("Coleco ColecoVision", "col", "col rom", "retro-core", 0); - application("NEC PC Engine", "pce", "pce", "retro-core", 0); - application("Atari Lynx", "lnx", "lnx", "retro-core", 64); + application("Sega Master System", "sms", "sms sg zip", "retro-core", 0); + application("Sega Game Gear", "gg", "gg zip", "retro-core", 0); + application("Sega Mega Drive", "md", "md gen bin zip", "gwenesis", 0); + application("Coleco ColecoVision", "col", "col rom zip", "retro-core", 0); + application("NEC PC Engine", "pce", "pce zip", "retro-core", 0); + application("Atari Lynx", "lnx", "lnx zip", "retro-core", 64); // application("Atari 2600", "a26", "a26", "stella-go", 0); // application("Neo Geo Pocket Color", "ngp", "ngp ngc", "ngpocket-go", 0); application("DOOM", "doom", "wad", "prboom-go", 0); diff --git a/retro-core/main/main_gbc.c b/retro-core/main/main_gbc.c index b46bb91b5..ff9203cc6 100644 --- a/retro-core/main/main_gbc.c +++ b/retro-core/main/main_gbc.c @@ -270,8 +270,19 @@ void gbc_main(void) gnuboy_set_soundbuffer((void *)audioBuffer, sizeof(audioBuffer) / 2); // Load ROM - if (gnuboy_load_rom_file(app->romPath) < 0) + if (rg_extension_match(app->romPath, "zip")) + { + void *data; + size_t size; + if (!rg_storage_unzip_file(app->romPath, NULL, &data, &size)) + RG_PANIC("ROM file unzipping failed!"); + if (gnuboy_load_rom(data, size) < 0) + RG_PANIC("ROM Loading failed!"); + } + else if (gnuboy_load_rom_file(app->romPath) < 0) + { RG_PANIC("ROM Loading failed!"); + } // Load BIOS if (loadBIOSFile) diff --git a/retro-core/main/main_lynx.cpp b/retro-core/main/main_lynx.cpp index 26c3fce9b..e92065aa6 100644 --- a/retro-core/main/main_lynx.cpp +++ b/retro-core/main/main_lynx.cpp @@ -86,6 +86,22 @@ static void set_display_mode(void) updates[1]->height = height; } +static CSystem *new_lynx(void) +{ + CSystem *lynx; + if (rg_extension_match(app->romPath, "zip")) + { + void *data; + size_t size; + if (!rg_storage_unzip_file(app->romPath, NULL, &data, &size)) + RG_PANIC("ROM file unzipping failed!"); + CSystem *lynx = new CSystem((UBYTE*)data, size, MIKIE_PIXEL_FORMAT_16BPP_565_BE, app->sampleRate); + free(data); + return lynx; + } + return new CSystem(app->romPath, MIKIE_PIXEL_FORMAT_16BPP_565_BE, app->sampleRate); +} + static rg_gui_event_t rotation_cb(rg_gui_option_t *option, rg_gui_event_t event) { @@ -159,7 +175,7 @@ static bool reset_handler(bool hard) { // This isn't nice but lynx->Reset() crashes... delete lynx; - lynx = new CSystem(app->romPath, MIKIE_PIXEL_FORMAT_16BPP_565_BE, app->sampleRate); + lynx = new_lynx(); return true; } @@ -190,7 +206,7 @@ extern "C" void lynx_main(void) app->tickRate = 60; // Init emulator - lynx = new CSystem(app->romPath, MIKIE_PIXEL_FORMAT_16BPP_565_BE, app->sampleRate); + lynx = new_lynx(); if (lynx->mFileType == HANDY_FILETYPE_ILLEGAL) { diff --git a/retro-core/main/main_nes.c b/retro-core/main/main_nes.c index a4b35e3a5..9002353ba 100644 --- a/retro-core/main/main_nes.c +++ b/retro-core/main/main_nes.c @@ -208,11 +208,23 @@ void nes_main(void) nes = nes_init(SYS_DETECT, app->sampleRate, true, RG_BASE_PATH_BIOS "/fds_bios.bin"); if (!nes) - { RG_PANIC("Init failed."); + + int ret = -1; + + if (rg_extension_match(app->romPath, "zip")) + { + void *data; + size_t size; + if (!rg_storage_unzip_file(app->romPath, NULL, &data, &size)) + RG_PANIC("ROM file unzipping failed!"); + ret = nes_insertcart(rom_loadmem(data, size)); + } + else + { + ret = nes_loadfile(app->romPath); } - int ret = nes_loadfile(app->romPath); if (ret == -1) RG_PANIC("ROM load failed."); else if (ret == -2) diff --git a/retro-core/main/main_pce.c b/retro-core/main/main_pce.c index 4dcebbdbf..7df6f6d82 100644 --- a/retro-core/main/main_pce.c +++ b/retro-core/main/main_pce.c @@ -219,7 +219,16 @@ void pce_main(void) InitPCE(app->sampleRate, true); - if (LoadFile(app->romPath) != 0) + if (rg_extension_match(app->romPath, "zip")) + { + void *data; + size_t size; + if (!rg_storage_unzip_file(app->romPath, NULL, &data, &size)) + RG_PANIC("ROM file unzipping failed!"); + if (LoadCard(data, size) != 0) + RG_PANIC("ROM loading failed"); + } + else if (LoadFile(app->romPath) != 0) { RG_PANIC("ROM loading failed"); } diff --git a/retro-core/main/main_sms.c b/retro-core/main/main_sms.c index f1e72bed0..80fcaa2a3 100644 --- a/retro-core/main/main_sms.c +++ b/retro-core/main/main_sms.c @@ -125,7 +125,16 @@ void sms_main(void) else option.console = 0; - if (!load_rom_file(app->romPath)) + if (rg_extension_match(app->romPath, "zip")) + { + void *data; + size_t size; + if (!rg_storage_unzip_file(app->romPath, NULL, &data, &size)) + RG_PANIC("ROM file unzipping failed!"); + if (!load_rom(data, RG_MAX(0x4000, size), size)) + RG_PANIC("ROM file loading failed!"); + } + else if (!load_rom_file(app->romPath)) RG_PANIC("ROM file loading failed!"); bitmap.width = SMS_WIDTH; diff --git a/retro-core/main/main_snes.c b/retro-core/main/main_snes.c index f136be95e..50ad0577c 100644 --- a/retro-core/main/main_snes.c +++ b/retro-core/main/main_snes.c @@ -289,7 +289,17 @@ void snes_main(void) if (!S9xInitGFX()) RG_PANIC("Graphics init failed!"); - if (!LoadROM(app->romPath)) + const char *filename = app->romPath; + + if (rg_extension_match(filename, "zip")) + { + free(Memory.ROM); // Would be nice to reuse it directly... + if (!rg_storage_unzip_file(filename, NULL, (void **)&Memory.ROM, &Memory.ROM_Size)) + RG_PANIC("ROM file unzipping failed!"); + filename = NULL; + } + + if (!LoadROM(filename)) RG_PANIC("ROM loading failed!"); #ifdef USE_BLARGG_APU