X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=pico%2Fcarthw%2Fcarthw.c;h=cd47e7c7c7bca7a18144059f60d07d0a878cf28f;hb=2b46e6c1054e1551d0edaecd8164cdaebc0c09b1;hp=0d6b9c5c7e4cd4ebea5b2ded656cff6e37e352f7;hpb=6a47c2d4fbd413d86c7f6a0cac8e4a4a163f3713;p=picodrive.git diff --git a/pico/carthw/carthw.c b/pico/carthw/carthw.c index 0d6b9c5..cd47e7c 100644 --- a/pico/carthw/carthw.c +++ b/pico/carthw/carthw.c @@ -11,6 +11,16 @@ #include "eeprom_spi.h" +static int have_bank(u32 base) +{ + // the loader allocs in 512K quantities + if (base >= Pico.romsize) { + elprintf(EL_ANOMALY|EL_STATUS, "carthw: missing bank @ %06x", base); + return 0; + } + return 1; +} + /* The SSFII mapper */ static unsigned char ssf2_banks[8]; @@ -36,10 +46,8 @@ static void carthw_ssf2_write8(u32 a, u32 d) ssf2_banks[a >> 1] = d; base = d << 19; target = a << 18; - if (base + 0x80000 > Pico.romsize) { - elprintf(EL_ANOMALY|EL_STATUS, "ssf2: missing bank @ %06x", base); + if (!have_bank(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); @@ -310,7 +318,7 @@ static void carthw_pier_write8(u32 a, u32 d) base = d << 19; goto do_map; case 0x09: - SRam.changed = 1; + Pico.sv.changed = 1; eeprom_spi_write(d); break; case 0x0b: @@ -324,10 +332,9 @@ static void carthw_pier_write8(u32 a, u32 d) return; do_map: - if (base + 0x80000 > Pico.romsize) { - elprintf(EL_ANOMALY|EL_STATUS, "pier: missing bank @ %06x", base); + if (!have_bank(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); } @@ -416,7 +423,6 @@ 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(); eeprom_spi_init(NULL); } @@ -436,17 +442,19 @@ void carthw_pier_startup(void) return; } + pier_dump_prot = 3; + // create dump protection bank for (i = 0; i < M68K_BANK_SIZE; i += 0x8000) memcpy(Pico.rom + Pico.romsize + i, Pico.rom, 0x8000); // save EEPROM eeprom_state = eeprom_spi_init(&eeprom_size); - SRam.flags = 0; - SRam.size = 0x10000; - SRam.data = calloc(1, SRam.size); - if (!SRam.data) - SRam.size = 0; + Pico.sv.flags = 0; + Pico.sv.size = 0x10000; + Pico.sv.data = calloc(1, Pico.sv.size); + if (!Pico.sv.data) + Pico.sv.size = 0; carthw_pier_state[2].ptr = eeprom_state; carthw_pier_state[2].size = eeprom_size;