From: kub Date: Tue, 21 Sep 2021 19:52:04 +0000 (+0200) Subject: core, add some superfighter mappers X-Git-Tag: v2.00~490 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=60392bf469c551364ca0d2178d1adc2c9d19383f;p=picodrive.git core, add some superfighter mappers --- diff --git a/pico/cart.c b/pico/cart.c index 1d17c713..903b3bef 100644 --- a/pico/cart.c +++ b/pico/cart.c @@ -1133,6 +1133,10 @@ static void parse_carthw(const char *carthw_cfg, int *fill_sram, carthw_radica_startup(); else if (strcmp(p, "piersolar_mapper") == 0) carthw_pier_startup(); + else if (strcmp(p, "sf001_mapper") == 0) + carthw_sf001_startup(); + else if (strcmp(p, "sf002_mapper") == 0) + carthw_sf002_startup(); else if (strcmp(p, "prot_lk3") == 0) carthw_prot_lk3_startup(); else { diff --git a/pico/carthw.cfg b/pico/carthw.cfg index c0ad6bce..bf8715c0 100644 --- a/pico/carthw.cfg +++ b/pico/carthw.cfg @@ -16,6 +16,8 @@ # realtec_mapper # radica_mapper - similar to x_in_1_mapper # piersolar_mapper - used in Pier Solar +# sf001_mapper +# sf002_mapper # # save storage memory range (inclusive, overrides ROM header): # sram_range = @@ -90,6 +92,17 @@ check_str = 0x150, "PIER" check_str = 0x610, "Respect" hw = piersolar_mapper +# Beggar Prince, unusual SRAM location +[Beggar Prince] +check_str = 0x150, "BEGGAR PRINCE" +hw = sf001_mapper +sram_range = 0x400000,0x40ffff +prop = filled_sram + +[Legend of Wukong] +check_str = 0x150, "LEGEND OF WUKONG" +hw = sf002_mapper + # detect *_in_1 based on first game and if it's larger than it should be, # as some dumps look like to be incomplete. # This will also pick overdumps, but those should still work with the mapper applied. diff --git a/pico/carthw/carthw.c b/pico/carthw/carthw.c index 3b8e8d43..0cadacda 100644 --- a/pico/carthw/carthw.c +++ b/pico/carthw/carthw.c @@ -483,6 +483,139 @@ void carthw_pier_startup(void) carthw_chunks = carthw_pier_state; } +/* superfighter mappers */ +unsigned int carthw_sf00x_reg; + +static carthw_state_chunk carthw_sf00x_state[] = +{ + { CHUNK_CARTHW, sizeof(carthw_sf00x_reg), &carthw_sf00x_reg }, + { 0, 0, NULL } +}; + +// hack to remap SRAM from 0x400000 to 0x3c0000 (there are 2 versions of sf001) +u32 carthw_sf001_read8_sram(u32 a) +{ + return m68k_read8((a & 0xffff) + 0x400000); +} + +u32 carthw_sf001_read16_sram(u32 a) +{ + return m68k_read16((a & 0xffff) + 0x400000); +} + +void carthw_sf001_write8_sram(u32 a, u32 d) +{ + m68k_write8((a & 0xffff) + 0x400000, d); +} + +void carthw_sf001_write16_sram(u32 a, u32 d) +{ + m68k_write16((a & 0xffff) + 0x400000, d); +} + +void carthw_sf001_write8(u32 a, u32 d) +{ + if ((a & 0xf00) != 0x0e00) + return; + + if (d & 0x80) { + // bank 0xe at addr 0x000000 + cpu68k_map_set(m68k_read8_map, 0x000000, 0x040000-1, Pico.rom+0x380000, 0); + cpu68k_map_set(m68k_read16_map, 0x000000, 0x040000-1, Pico.rom+0x380000, 0); + // SRAM at 0x3c0000; hack to map SRAM from old to new location + cpu68k_map_set(m68k_read8_map, 0x3c0000, 0x400000-1, carthw_sf001_read8_sram, 1); + cpu68k_map_set(m68k_read16_map, 0x3c0000, 0x400000-1, carthw_sf001_read16_sram, 1); + cpu68k_map_set(m68k_write8_map, 0x3c0000, 0x400000-1, carthw_sf001_write8_sram, 1); + cpu68k_map_set(m68k_write16_map,0x3c0000, 0x400000-1, carthw_sf001_write16_sram, 1); + } else { + // bank 0x0 at addr 0x000000 + cpu68k_map_set(m68k_read8_map, 0x000000, 0x040000-1, Pico.rom, 0); + cpu68k_map_set(m68k_read16_map, 0x000000, 0x040000-1, Pico.rom, 0); + // SRAM off, bank 0xf at addr 0x3c0000 + cpu68k_map_set(m68k_read8_map, 0x3c0000, 0x400000-1, Pico.rom+0x3c0000, 0); + cpu68k_map_set(m68k_read16_map, 0x3c0000, 0x400000-1, Pico.rom+0x3c0000, 0); + cpu68k_map_set(m68k_write8_map, 0x3c0000, 0x400000-1, Pico.rom+0x3c0000, 0); + cpu68k_map_set(m68k_write16_map,0x3c0000, 0x400000-1, Pico.rom+0x3c0000, 0); + } + carthw_sf00x_reg = d; +} + +void carthw_sf001_write16(u32 a, u32 d) +{ + carthw_sf001_write8(a + 1, d); +} + +static void carthw_sf001_mem_setup(void) +{ + cpu68k_map_set(m68k_write8_map, 0x000000, 0x00ffff, carthw_sf001_write8, 1); + cpu68k_map_set(m68k_write16_map, 0x000000, 0x00ffff, carthw_sf001_write16, 1); +} + +static void carthw_sf001_reset(void) +{ + carthw_sf001_write8(0x0e01, 0); +} + +static void carthw_sf001_statef(void) +{ + carthw_sf001_write8(0x0e01, carthw_sf00x_reg); +} + +void carthw_sf001_startup(void) +{ + PicoCartMemSetup = carthw_sf001_mem_setup; + PicoResetHook = carthw_sf001_reset; + PicoLoadStateHook = carthw_sf001_statef; + carthw_chunks = carthw_sf00x_state; +} + + +void carthw_sf002_write8(u32 a, u32 d) +{ + if ((a & 0xf00) != 0x0e00) + return; + + if (d & 0x80) { + // bank 0x00-0x0e on addr 0x20000 + cpu68k_map_set(m68k_read8_map, 0x200000, 0x3c0000-1, Pico.rom, 0); + cpu68k_map_set(m68k_read16_map, 0x200000, 0x3c0000-1, Pico.rom, 0); + } else { + // bank 0x10-0x1e on addr 0x20000 + cpu68k_map_set(m68k_read8_map, 0x200000, 0x3c0000-1, Pico.rom+0x200000, 0); + cpu68k_map_set(m68k_read16_map, 0x200000, 0x3c0000-1, Pico.rom+0x200000, 0); + } + carthw_sf00x_reg = d; +} + +void carthw_sf002_write16(u32 a, u32 d) +{ + carthw_sf002_write8(a + 1, d); +} + +static void carthw_sf002_mem_setup(void) +{ + cpu68k_map_set(m68k_write8_map, 0x000000, 0x00ffff, carthw_sf002_write8, 1); + cpu68k_map_set(m68k_write16_map, 0x000000, 0x00ffff, carthw_sf002_write16, 1); +} + +static void carthw_sf002_reset(void) +{ + carthw_sf002_write8(0x0e01, 0); +} + +static void carthw_sf002_statef(void) +{ + carthw_sf002_write8(0x0e01, carthw_sf00x_reg); +} + +void carthw_sf002_startup(void) +{ + PicoCartMemSetup = carthw_sf002_mem_setup; + PicoResetHook = carthw_sf002_reset; + PicoLoadStateHook = carthw_sf002_statef; + carthw_chunks = carthw_sf00x_state; +} + /* Simple unlicensed ROM protection emulation */ static struct { u32 addr; diff --git a/pico/carthw_cfg.c b/pico/carthw_cfg.c index 2ce6d29f..4ff097a2 100644 --- a/pico/carthw_cfg.c +++ b/pico/carthw_cfg.c @@ -42,6 +42,13 @@ static const char builtin_carthw_cfg[] = "check_str=0x610,\"Respect\"\n" "hw=piersolar_mapper\n" "[]\n" + "check_str=0x150,\"BEGGAR PRINCE\"\n" + "hw=sf001_mapper\n" + "sram_range=0x400000,0x40ffff\n" + "[]\n" + "check_str=0x150,\"LEGEND OF WUKONG\"\n" + "hw=sf002_mapper\n" + "[]\n" "check_str=0x120,\"FLICKY\"\n" "check_size_gt=0x020000\n" "hw=x_in_1_mapper\n" diff --git a/pico/memory.c b/pico/memory.c index fab46c21..46c335ca 100644 --- a/pico/memory.c +++ b/pico/memory.c @@ -777,7 +777,7 @@ PICO_INTERNAL void PicoMemSetup(void) // Common case of on-cart (save) RAM, usually at 0x200000-... if ((Pico.sv.flags & SRF_ENABLED) && Pico.sv.data != NULL) { - sstart = Pico.sv.start; + sstart = Pico.sv.start & ~mask; rs = Pico.sv.end - sstart; rs = (rs + mask) & ~mask; if (sstart + rs >= 0x1000000)