From 2b5416eade556b86776f74cc24fc7959affb7824 Mon Sep 17 00:00:00 2001 From: Christian Speckner Date: Tue, 5 Dec 2017 20:28:41 +0100 Subject: [PATCH] Don't trap write accesses to datastream pointers & friends in CDF / BUS. --- src/emucore/Thumbulator.cxx | 45 +++++++++++++++++++------------------ src/emucore/Thumbulator.hxx | 1 + 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/emucore/Thumbulator.cxx b/src/emucore/Thumbulator.cxx index 986cb7393..36003ab17 100644 --- a/src/emucore/Thumbulator.cxx +++ b/src/emucore/Thumbulator.cxx @@ -226,28 +226,7 @@ void Thumbulator::write16(uInt32 addr, uInt32 data) if((addr > 0x40001fff) && (addr < 0x50000000)) fatalError("write16", addr, "abort - out of range"); - switch(configuration) - { - // this protects 2K Harmony/Melody Drivers - // Initial section of driver is the bootstrap which copies the driver - // from ROM to RAM, so it can safely be used by the custom ARM code - // as additional RAM - case ConfigureFor::BUS: - case ConfigureFor::CDF: - case ConfigureFor::CDF1: - if((addr > 0x40000028) && (addr < 0x40000800)) - fatalError("write16", addr, "to bankswitch code area"); - break; - - // this protects 3K Harmony/Melody Drivers - // Initial section of driver is the bootstrap which copies the driver - // from ROM to RAM, so it can safely be used by the custom ARM code - // as additional RAM - case ConfigureFor::DPCplus: - if((addr > 0x40000028) && (addr < 0x40000c00)) - fatalError("write16", addr, "to bankswitch code area"); - break; - } + if (isProtected(addr)) fatalError("write16", addr, "to driver area"); if(addr & 1) fatalError("write16", addr, "abort - misaligned"); @@ -281,6 +260,7 @@ void Thumbulator::write32(uInt32 addr, uInt32 data) if(addr & 3) fatalError("write32", addr, "abort - misaligned"); + if (isProtected(addr)) fatalError("write32", addr, "to driver area"); DO_DBUG(statusMsg << "write32(" << Base::HEX8 << addr << "," << Base::HEX8 << data << ")" << endl); switch(addr & 0xF0000000) @@ -356,6 +336,27 @@ void Thumbulator::write32(uInt32 addr, uInt32 data) fatalError("write32", addr, data, "abort"); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool Thumbulator::isProtected(uInt32 addr) +{ + if (addr < 0x40000000) return false; + addr -= 0x40000000; + + switch (configuration) { + case ConfigureFor::DPCplus: + return (addr < 0x0c00) && (addr > 0x0028); + + case ConfigureFor::CDF: + return (addr < 0x0800) && (addr > 0x0028) && !((addr >= 0x06e0) && (addr < (0x0e60 + 284))); + + case ConfigureFor::CDF1: + return (addr < 0x0800) && (addr > 0x0028) && !((addr >= 0x00a0) && (addr < (0x00a0 + 284))); + + case ConfigureFor::BUS: + return (addr < 0x06d8) && (addr > 0x0028); + } +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt32 Thumbulator::read16(uInt32 addr) { diff --git a/src/emucore/Thumbulator.hxx b/src/emucore/Thumbulator.hxx index 0b1953a28..68ca803e8 100644 --- a/src/emucore/Thumbulator.hxx +++ b/src/emucore/Thumbulator.hxx @@ -104,6 +104,7 @@ class Thumbulator uInt32 fetch32(uInt32 addr); uInt32 read16(uInt32 addr); uInt32 read32(uInt32 addr); + bool isProtected(uInt32 addr); void write16(uInt32 addr, uInt32 data); void write32(uInt32 addr, uInt32 data); void updateTimer(uInt32 cycles);