From 14cd01be51863db7b354957f9bb8ab227ecc2fbf Mon Sep 17 00:00:00 2001 From: kub Date: Fri, 15 Oct 2021 19:22:01 +0200 Subject: [PATCH] sms, improve gg detection (zip, rom header) --- pico/cart.c | 1 + pico/media.c | 5 +++-- pico/sms.c | 10 ++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pico/cart.c b/pico/cart.c index ed766156..1b15a454 100644 --- a/pico/cart.c +++ b/pico/cart.c @@ -243,6 +243,7 @@ zip_failed: file->param = cso; file->size = cso->header.total_bytes; file->type = PMT_CSO; + strncpy(file->ext, ext, sizeof(file->ext) - 1); return file; cso_failed: diff --git a/pico/media.c b/pico/media.c index d7e91a0f..d6d136bc 100644 --- a/pico/media.c +++ b/pico/media.c @@ -259,7 +259,6 @@ enum media_type_e PicoLoadMedia(const char *filename, } ret = PicoCartLoad(rom, &rom_data, &rom_size, (PicoIn.AHW & PAHW_SMS) ? 1 : 0); - pm_close(rom); if (ret != 0) { if (ret == 2) lprintf("Out of memory\n"); else if (ret == 3) lprintf("Read failed\n"); @@ -299,7 +298,7 @@ enum media_type_e PicoLoadMedia(const char *filename, // simple test for GG. Do this here since m.hardware is nulled in Insert if (PicoIn.AHW & PAHW_SMS) { - if (strstr(filename,".gg")) { + if (!strcmp(rom->ext,"gg")) { Pico.m.hardware |= 0x1; lprintf("detected GG ROM\n"); } else @@ -322,6 +321,8 @@ enum media_type_e PicoLoadMedia(const char *filename, PicoSetInputDevice(0, PICO_INPUT_PAD_6BTN); out: + if (rom) + pm_close(rom); if (rom_data) free(rom_data); return media_type; diff --git a/pico/sms.c b/pico/sms.c index 6c8ce358..78fce13b 100644 --- a/pico/sms.c +++ b/pico/sms.c @@ -323,6 +323,7 @@ void PicoResetMS(void) void PicoPowerMS(void) { int s, tmp; + unsigned tmr; memset(&PicoMem,0,sizeof(PicoMem)); memset(&Pico.video,0,sizeof(Pico.video)); @@ -339,6 +340,15 @@ void PicoPowerMS(void) tmp = 1 << s; bank_mask = (tmp - 1) >> 14; + // check if the ROM header contains more system information to detect GG + for (tmr = 0x2000; tmr < 0xbfff && tmr <= Pico.romsize; tmr *= 2) { + if (!memcmp(Pico.rom + tmr-16, "TMR SEGA", 8)) { + if (Pico.rom[tmr-1] >= 0x50 && Pico.rom[tmr-1] < 0x80) + Pico.m.hardware |= 0x1; + break; + } + } + PicoReset(); } -- 2.39.5