X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=picodrive.git;a=blobdiff_plain;f=pico%2Fcarthw%2Fcarthw.c;h=a8b4333f434ac9644fff1ce094b488035e945392;hp=06936fbf9af56e6fe3dc30a69a51131b13f40c05;hb=f50806540979413d06aedc47a195e3fa4ba8bde6;hpb=30f0fdd42279a99893034a5d21b64439536c60aa diff --git a/pico/carthw/carthw.c b/pico/carthw/carthw.c index 06936fb..a8b4333 100644 --- a/pico/carthw/carthw.c +++ b/pico/carthw/carthw.c @@ -8,8 +8,19 @@ #include "../pico_int.h" #include "../memory.h" +#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]; @@ -35,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); @@ -270,6 +279,7 @@ static carthw_state_chunk carthw_pier_state[] = { { CHUNK_CARTHW, sizeof(pier_regs), pier_regs }, { CHUNK_CARTHW + 1, sizeof(pier_dump_prot), &pier_dump_prot }, + { CHUNK_CARTHW + 2, 0, NULL }, // filled later { 0, 0, NULL } }; @@ -308,7 +318,8 @@ static void carthw_pier_write8(u32 a, u32 d) base = d << 19; goto do_map; case 0x09: - // TODO + SRam.changed = 1; + eeprom_spi_write(d); break; case 0x0b: // eeprom read @@ -321,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); } @@ -346,7 +356,7 @@ static u32 carthw_pier_read8(u32 a) return PicoRead8_io(a); if (a == 0xa1300b) - return 0; // TODO + return eeprom_spi_read(a); elprintf(EL_UIO, "pier r8 [%06x] @%06x", a, SekPc); return 0; @@ -415,10 +425,13 @@ static void carthw_pier_reset(void) pier_regs[1] = pier_regs[2] = pier_regs[3] = 0; pier_dump_prot = 3; carthw_pier_statef(); + eeprom_spi_init(NULL); } void carthw_pier_startup(void) { + void *eeprom_state; + int eeprom_size = 0; int i; elprintf(EL_STATUS, "Pier Solar mapper startup"); @@ -434,6 +447,16 @@ void carthw_pier_startup(void) 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; + carthw_pier_state[2].ptr = eeprom_state; + carthw_pier_state[2].size = eeprom_size; + PicoCartMemSetup = carthw_pier_mem_setup; PicoResetHook = carthw_pier_reset; PicoLoadStateHook = carthw_pier_statef; @@ -679,3 +702,4 @@ void carthw_prot_lk3_startup(void) PicoCartMemSetup = carthw_prot_lk3_mem_setup; } +// vim:ts=2:sw=2:expandtab