From 30f0fdd42279a99893034a5d21b64439536c60aa Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 23 Jun 2013 02:00:43 +0300 Subject: [PATCH] some uncommitted old mapper code apparently from 2011 --- cpu/debug.c | 2 + pico/cart.c | 2 + pico/carthw.cfg | 15 +- pico/carthw/carthw.c | 204 +++++++++++++++++++++++-- pico/carthw/carthw.h | 1 + platform/{pandora => common}/version.h | 0 6 files changed, 209 insertions(+), 15 deletions(-) rename platform/{pandora => common}/version.h (100%) diff --git a/cpu/debug.c b/cpu/debug.c index 1372627..a464413 100644 --- a/cpu/debug.c +++ b/cpu/debug.c @@ -88,6 +88,8 @@ static int pdb_net_send(struct pdb_cpu *cpu, unsigned int pc) packet.header.len = 4 + rl + 4*2; sh2->pdb_io_csum[0] = sh2->pdb_io_csum[1] = 0; } + else + memset(&packet, 0, sizeof(packet)); ret = send(pdb_net_sock, &packet, sizeof(packet.header) + packet.header.len, MSG_NOSIGNAL); if (ret != sizeof(packet.header) + packet.header.len) { diff --git a/pico/cart.c b/pico/cart.c index 2f3078e..debb8a2 100644 --- a/pico/cart.c +++ b/pico/cart.c @@ -823,6 +823,8 @@ static void parse_carthw(const char *carthw_cfg, int *fill_sram) carthw_realtec_startup(); else if (strcmp(p, "radica_mapper") == 0) carthw_radica_startup(); + else if (strcmp(p, "piersolar_mapper") == 0) + carthw_pier_startup(); else if (strcmp(p, "prot_lk3") == 0) carthw_prot_lk3_startup(); else { diff --git a/pico/carthw.cfg b/pico/carthw.cfg index 36c8cf8..ac918bf 100644 --- a/pico/carthw.cfg +++ b/pico/carthw.cfg @@ -10,10 +10,11 @@ # filled_sram - save storage needs to be initialized with FFh instead of 00h # # mappers (hw = ...): -# ssf2_mapper - used in Super Street Fighter2 -# x_in_1_mapper - used in many *-in-1 pirate carts +# ssf2_mapper - used in Super Street Fighter2 +# x_in_1_mapper - used in many *-in-1 pirate carts # realtec_mapper -# radica_mapper - similar to x_in_1_mapper +# radica_mapper - similar to x_in_1_mapper +# piersolar_mapper - used in Pier Solar # # save storage memory range (inclusive, overrides ROM header): # sram_range = @@ -65,6 +66,14 @@ check_str = 0x150, "SUPER STREET FIGHTER2 The New Challengers" hw = ssf2_mapper prop = no_sram +# The Pier Solar mapper, custom eeprom location +[Pier Solar and the Great Architects] +check_str = 0x150, "PIER SOLAR™&THE GREAT ARCHITECTS© WaterMelon™" +hw = piersolar_mapper +sram_range = 0xa13009,0xa1300b +eeprom_type = 3 +eeprom_lines = 2,1,0 + # 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 aba900e..06936fb 100644 --- a/pico/carthw/carthw.c +++ b/pico/carthw/carthw.c @@ -1,6 +1,6 @@ /* * Support for a few cart mappers and some protection. - * (C) notaz, 2008,2009,2010 + * (C) notaz, 2008-2011 * * This work is licensed under the terms of MAME license. * See COPYING file in the top-level directory. @@ -11,7 +11,7 @@ /* The SSFII mapper */ -unsigned char ssf2_banks[8]; +static unsigned char ssf2_banks[8]; static carthw_state_chunk carthw_ssf2_state[] = { @@ -261,25 +261,205 @@ void carthw_radica_startup(void) carthw_chunks = carthw_Xin1_state; } + +/* Pier Solar. Based on my own research */ +static unsigned char pier_regs[8]; +static unsigned char pier_dump_prot; + +static carthw_state_chunk carthw_pier_state[] = +{ + { CHUNK_CARTHW, sizeof(pier_regs), pier_regs }, + { CHUNK_CARTHW + 1, sizeof(pier_dump_prot), &pier_dump_prot }, + { 0, 0, NULL } +}; + +static void carthw_pier_write8(u32 a, u32 d) +{ + u32 a8, target, base; + + if ((a & 0xffff00) != 0xa13000) { + PicoWrite8_io(a, d); + return; + } + + a8 = a & 0x0f; + pier_regs[a8 / 2] = d; + + elprintf(EL_UIO, "pier w8 [%06x] %02x @%06x", a, d & 0xffff, SekPc); + switch (a8) { + case 0x01: + break; + case 0x03: + if (!(pier_regs[0] & 2)) + goto unmapped; + target = 0x280000; + base = d << 19; + goto do_map; + case 0x05: + if (!(pier_regs[0] & 2)) + goto unmapped; + target = 0x300000; + base = d << 19; + goto do_map; + case 0x07: + if (!(pier_regs[0] & 2)) + goto unmapped; + target = 0x380000; + base = d << 19; + goto do_map; + case 0x09: + // TODO + break; + case 0x0b: + // eeprom read + default: + unmapped: + //elprintf(EL_UIO, "pier w8 [%06x] %02x @%06x", a, d & 0xffff, SekPc); + elprintf(EL_STATUS, "-- unmapped w8 [%06x] %02x @%06x", a, d & 0xffff, SekPc); + break; + } + return; + +do_map: + if (base + 0x80000 > Pico.romsize) { + elprintf(EL_ANOMALY|EL_STATUS, "pier: missing bank @ %06x", base); + return; + } + cpu68k_map_set(m68k_read8_map, target, target + 0x80000 - 1, Pico.rom + base, 0); + cpu68k_map_set(m68k_read16_map, target, target + 0x80000 - 1, Pico.rom + base, 0); +} + +static void carthw_pier_write16(u32 a, u32 d) +{ + if ((a & 0xffff00) != 0xa13000) { + PicoWrite16_io(a, d); + return; + } + + elprintf(EL_UIO, "pier w16 [%06x] %04x @%06x", a, d & 0xffff, SekPc); + carthw_pier_write8(a + 1, d); +} + +static u32 carthw_pier_read8(u32 a) +{ + if ((a & 0xffff00) != 0xa13000) + return PicoRead8_io(a); + + if (a == 0xa1300b) + return 0; // TODO + + elprintf(EL_UIO, "pier r8 [%06x] @%06x", a, SekPc); + return 0; +} + +static void carthw_pier_statef(void); + +static u32 carthw_pier_prot_read8(u32 a) +{ + /* it takes more than just these reads here to disable ROM protection, + * but for game emulation purposes this is enough. */ + if (pier_dump_prot > 0) + pier_dump_prot--; + if (pier_dump_prot == 0) { + carthw_pier_statef(); + elprintf(EL_STATUS, "prot off on r8 @%06x", SekPc); + } + elprintf(EL_UIO, "pier r8 [%06x] @%06x", a, SekPc); + + return Pico.rom[(a & 0x7fff) ^ 1]; +} + +static void carthw_pier_mem_setup(void) +{ + cpu68k_map_set(m68k_write8_map, 0xa10000, 0xa1ffff, carthw_pier_write8, 1); + cpu68k_map_set(m68k_write16_map, 0xa10000, 0xa1ffff, carthw_pier_write16, 1); + cpu68k_map_set(m68k_read8_map, 0xa10000, 0xa1ffff, carthw_pier_read8, 1); +} + +static void carthw_pier_prot_mem_setup(int prot_enable) +{ + if (prot_enable) { + /* the dump protection.. */ + int a; + for (a = 0x000000; a < 0x400000; a += M68K_BANK_SIZE) { + cpu68k_map_set(m68k_read8_map, a, a + 0xffff, Pico.rom + Pico.romsize, 0); + cpu68k_map_set(m68k_read16_map, a, a + 0xffff, Pico.rom + Pico.romsize, 0); + } + cpu68k_map_set(m68k_read8_map, M68K_BANK_SIZE, M68K_BANK_SIZE * 2 - 1, + carthw_pier_prot_read8, 1); + } + else { + cpu68k_map_set(m68k_read8_map, 0, 0x27ffff, Pico.rom, 0); + cpu68k_map_set(m68k_read16_map, 0, 0x27ffff, Pico.rom, 0); + } +} + +static void carthw_pier_statef(void) +{ + carthw_pier_prot_mem_setup(pier_dump_prot); + + if (!pier_dump_prot) { + /* setup all banks */ + u32 r0 = pier_regs[0]; + carthw_pier_write8(0xa13001, 3); + carthw_pier_write8(0xa13003, pier_regs[1]); + carthw_pier_write8(0xa13005, pier_regs[2]); + carthw_pier_write8(0xa13007, pier_regs[3]); + carthw_pier_write8(0xa13001, r0); + } +} + +static void carthw_pier_reset(void) +{ + pier_regs[0] = 1; + pier_regs[1] = pier_regs[2] = pier_regs[3] = 0; + pier_dump_prot = 3; + carthw_pier_statef(); +} + +void carthw_pier_startup(void) +{ + int i; + + elprintf(EL_STATUS, "Pier Solar mapper startup"); + + // mostly same as for realtec.. + i = PicoCartResize(Pico.romsize + M68K_BANK_SIZE); + if (i != 0) { + elprintf(EL_STATUS, "OOM"); + return; + } + + // create dump protection bank + for (i = 0; i < M68K_BANK_SIZE; i += 0x8000) + memcpy(Pico.rom + Pico.romsize + i, Pico.rom, 0x8000); + + PicoCartMemSetup = carthw_pier_mem_setup; + PicoResetHook = carthw_pier_reset; + PicoLoadStateHook = carthw_pier_statef; + carthw_chunks = carthw_pier_state; +} + /* Simple unlicensed ROM protection emulation */ static struct { - u32 addr; - u32 mask; - u16 val; - u16 readonly; + u32 addr; + u32 mask; + u16 val; + u16 readonly; } *sprot_items; static int sprot_item_alloc; static int sprot_item_count; static u16 *carthw_sprot_get_val(u32 a, int rw_only) { - int i; + int i; + + for (i = 0; i < sprot_item_count; i++) + if ((a & sprot_items[i].mask) == sprot_items[i].addr) + if (!rw_only || !sprot_items[i].readonly) + return &sprot_items[i].val; - for (i = 0; i < sprot_item_count; i++) - if ((a & sprot_items[i].mask) == sprot_items[i].addr) - if (!rw_only || !sprot_items[i].readonly) - return &sprot_items[i].val; - return NULL; + return NULL; } static u32 PicoRead8_sprot(u32 a) diff --git a/pico/carthw/carthw.h b/pico/carthw/carthw.h index 382e1e2..869a5cd 100644 --- a/pico/carthw/carthw.h +++ b/pico/carthw/carthw.h @@ -19,6 +19,7 @@ void carthw_ssf2_startup(void); void carthw_Xin1_startup(void); void carthw_realtec_startup(void); void carthw_radica_startup(void); +void carthw_pier_startup(void); void carthw_sprot_startup(void); void carthw_sprot_new_location(unsigned int a, diff --git a/platform/pandora/version.h b/platform/common/version.h similarity index 100% rename from platform/pandora/version.h rename to platform/common/version.h -- 2.39.2