diff --git a/src/emucore/Cart4KSC.cxx b/src/emucore/Cart4KSC.cxx index 2eca3a83b..cdd61974a 100644 --- a/src/emucore/Cart4KSC.cxx +++ b/src/emucore/Cart4KSC.cxx @@ -44,16 +44,16 @@ void Cartridge4KSC::install(System& system) System::PageAccess access(this, System::PA_READ); // Set the page accessing method for the RAM writing pages + // Map access to this class, since we need to inspect all accesses to + // check if RWP happens access.type = System::PA_WRITE; for(uInt16 addr = 0x1000; addr < 0x1080; addr += System::PAGE_SIZE) { - access.directPokeBase = &myRAM[addr & 0x007F]; access.codeAccessBase = &myCodeAccessBase[addr & 0x007F]; mySystem->setPageAccess(addr, access); } // Set the page accessing method for the RAM reading pages - access.directPokeBase = nullptr; access.type = System::PA_READ; for(uInt16 addr = 0x1080; addr < 0x1100; addr += System::PAGE_SIZE) { @@ -76,17 +76,15 @@ uInt8 Cartridge4KSC::peek(uInt16 address) { // The only way we can get to this method is if we attempt to read from // the write port (0xF000 - 0xF07F, 128 bytes), in which case an - // unwanted write is triggered - uInt8 value = mySystem->getDataBusState(0xFF); + // unwanted write is potentially triggered + return peekRAM(myRAM[address & 0x007F], address); +} - if(bankLocked()) - return value; - else - { - myRAM[address & 0x0FFF] = value; - triggerReadFromWritePort(address); - return value; - } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool Cartridge4KSC::poke(uInt16 address, uInt8 value) +{ + pokeRAM(myRAM[address & 0x007F], address, value); + return true; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/Cart4KSC.hxx b/src/emucore/Cart4KSC.hxx index d46a6eb78..c9f81cc81 100644 --- a/src/emucore/Cart4KSC.hxx +++ b/src/emucore/Cart4KSC.hxx @@ -120,6 +120,15 @@ class Cartridge4KSC : public Cartridge */ uInt8 peek(uInt16 address) override; + /** + Change the byte at the specified address to the given value + + @param address The address where the value should be stored + @param value The value to be stored at the address + @return True if the poke changed the device address space, else false + */ + bool poke(uInt16 address, uInt8 value) override; + private: // The 4K ROM image of the cartridge uInt8 myImage[4096]; diff --git a/src/emucore/CartBFSC.cxx b/src/emucore/CartBFSC.cxx index f68edbbdd..a06b3406f 100644 --- a/src/emucore/CartBFSC.cxx +++ b/src/emucore/CartBFSC.cxx @@ -47,16 +47,16 @@ void CartridgeBFSC::install(System& system) System::PageAccess access(this, System::PA_READ); // Set the page accessing method for the RAM writing pages + // Map access to this class, since we need to inspect all accesses to + // check if RWP happens access.type = System::PA_WRITE; for(uInt16 addr = 0x1000; addr < 0x1080; addr += System::PAGE_SIZE) { - access.directPokeBase = &myRAM[addr & 0x007F]; access.codeAccessBase = &myCodeAccessBase[addr & 0x007F]; mySystem->setPageAccess(addr, access); } // Set the page accessing method for the RAM reading pages - access.directPokeBase = nullptr; access.type = System::PA_READ; for(uInt16 addr = 0x1080; addr < 0x1100; addr += System::PAGE_SIZE) { @@ -80,36 +80,25 @@ uInt8 CartridgeBFSC::peek(uInt16 address) bank(address - 0x0F80); if(address < 0x0080) // Write port is at 0xF000 - 0xF07F (128 bytes) - { - // Reading from the write port triggers an unwanted write - uInt8 value = mySystem->getDataBusState(0xFF); - - if(bankLocked()) - return value; - else - { - myRAM[address] = value; - triggerReadFromWritePort(peekAddress); - return value; - } - } + return peekRAM(myRAM[address], peekAddress); else return myImage[myBankOffset + address]; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool CartridgeBFSC::poke(uInt16 address, uInt8) +bool CartridgeBFSC::poke(uInt16 address, uInt8 value) { address &= 0x0FFF; // Switch banks if necessary if((address >= 0x0F80) && (address <= 0x0FBF)) + { bank(address - 0x0F80); + return false; + } - // NOTE: This does not handle accessing RAM, however, this method - // should never be called for RAM because of the way page accessing - // has been setup - return false; + pokeRAM(myRAM[address & 0x007F], address, value); + return true; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/CartDFSC.cxx b/src/emucore/CartDFSC.cxx index 65c14b56e..afb4e3b2a 100644 --- a/src/emucore/CartDFSC.cxx +++ b/src/emucore/CartDFSC.cxx @@ -47,16 +47,16 @@ void CartridgeDFSC::install(System& system) System::PageAccess access(this, System::PA_READ); // Set the page accessing method for the RAM writing pages + // Map access to this class, since we need to inspect all accesses to + // check if RWP happens access.type = System::PA_WRITE; for(uInt16 addr = 0x1000; addr < 0x1080; addr += System::PAGE_SIZE) { - access.directPokeBase = &myRAM[addr & 0x007F]; access.codeAccessBase = &myCodeAccessBase[addr & 0x007F]; mySystem->setPageAccess(addr, access); } // Set the page accessing method for the RAM reading pages - access.directPokeBase = nullptr; access.type = System::PA_READ; for(uInt16 addr = 0x1080; addr < 0x1100; addr += System::PAGE_SIZE) { @@ -80,36 +80,25 @@ uInt8 CartridgeDFSC::peek(uInt16 address) bank(address - 0x0FC0); if(address < 0x0080) // Write port is at 0xF000 - 0xF07F (128 bytes) - { - // Reading from the write port triggers an unwanted write - uInt8 value = mySystem->getDataBusState(0xFF); - - if(bankLocked()) - return value; - else - { - myRAM[address] = value; - triggerReadFromWritePort(peekAddress); - return value; - } - } + return peekRAM(myRAM[address], peekAddress); else return myImage[myBankOffset + address]; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool CartridgeDFSC::poke(uInt16 address, uInt8) +bool CartridgeDFSC::poke(uInt16 address, uInt8 value) { address &= 0x0FFF; // Switch banks if necessary if((address >= 0x0FC0) && (address <= 0x0FDF)) + { bank(address - 0x0FC0); + return false; + } - // NOTE: This does not handle accessing RAM, however, this method - // should never be called for RAM because of the way page accessing - // has been setup - return false; + pokeRAM(myRAM[address & 0x007F], address, value); + return true; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/CartEFSC.cxx b/src/emucore/CartEFSC.cxx index c1b74423d..271ea1029 100644 --- a/src/emucore/CartEFSC.cxx +++ b/src/emucore/CartEFSC.cxx @@ -47,16 +47,16 @@ void CartridgeEFSC::install(System& system) System::PageAccess access(this, System::PA_READ); // Set the page accessing method for the RAM writing pages + // Map access to this class, since we need to inspect all accesses to + // check if RWP happens access.type = System::PA_WRITE; for(uInt16 addr = 0x1000; addr < 0x1080; addr += System::PAGE_SIZE) { - access.directPokeBase = &myRAM[addr & 0x007F]; access.codeAccessBase = &myCodeAccessBase[addr & 0x007F]; mySystem->setPageAccess(addr, access); } // Set the page accessing method for the RAM reading pages - access.directPokeBase = nullptr; access.type = System::PA_READ; for(uInt16 addr = 0x1080; addr < 0x1100; addr += System::PAGE_SIZE) { @@ -80,36 +80,25 @@ uInt8 CartridgeEFSC::peek(uInt16 address) bank(address - 0x0FE0); if(address < 0x0080) // Write port is at 0xF000 - 0xF07F (128 bytes) - { - // Reading from the write port triggers an unwanted write - uInt8 value = mySystem->getDataBusState(0xFF); - - if(bankLocked()) - return value; - else - { - myRAM[address] = value; - triggerReadFromWritePort(peekAddress); - return value; - } - } + return peekRAM(myRAM[address], peekAddress); else return myImage[myBankOffset + address]; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool CartridgeEFSC::poke(uInt16 address, uInt8) +bool CartridgeEFSC::poke(uInt16 address, uInt8 value) { address &= 0x0FFF; // Switch banks if necessary if((address >= 0x0FE0) && (address <= 0x0FEF)) + { bank(address - 0x0FE0); + return false; + } - // NOTE: This does not handle accessing RAM, however, this function - // should never be called for RAM because of the way page accessing - // has been setup - return false; + pokeRAM(myRAM[address & 0x007F], address, value); + return true; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/CartF4SC.cxx b/src/emucore/CartF4SC.cxx index 93e9dd309..856f806cd 100644 --- a/src/emucore/CartF4SC.cxx +++ b/src/emucore/CartF4SC.cxx @@ -47,16 +47,16 @@ void CartridgeF4SC::install(System& system) System::PageAccess access(this, System::PA_READ); // Set the page accessing method for the RAM writing pages + // Map access to this class, since we need to inspect all accesses to + // check if RWP happens access.type = System::PA_WRITE; for(uInt16 addr = 0x1000; addr < 0x1080; addr += System::PAGE_SIZE) { - access.directPokeBase = &myRAM[addr & 0x007F]; access.codeAccessBase = &myCodeAccessBase[addr & 0x007F]; mySystem->setPageAccess(addr, access); } // Set the page accessing method for the RAM reading pages - access.directPokeBase = nullptr; access.type = System::PA_READ; for(uInt16 addr = 0x1080; addr < 0x1100; addr += System::PAGE_SIZE) { @@ -80,39 +80,25 @@ uInt8 CartridgeF4SC::peek(uInt16 address) bank(address - 0x0FF4); if(address < 0x0080) // Write port is at 0xF000 - 0xF07F (128 bytes) - { - // Reading from the write port triggers an unwanted write - uInt8 value = mySystem->getDataBusState(0xFF); - - if(bankLocked()) - return value; - else - { - myRAM[address] = value; - triggerReadFromWritePort(peekAddress); - return value; - } - } - - // NOTE: This does not handle accessing RAM, however, this function - // should never be called for RAM because of the way page accessing - // has been setup - return myImage[myBankOffset + address]; + return peekRAM(myRAM[address], peekAddress); + else + return myImage[myBankOffset + address]; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool CartridgeF4SC::poke(uInt16 address, uInt8) +bool CartridgeF4SC::poke(uInt16 address, uInt8 value) { address &= 0x0FFF; // Switch banks if necessary if((address >= 0x0FF4) && (address <= 0x0FFB)) + { bank(address - 0x0FF4); + return false; + } - // NOTE: This does not handle accessing RAM, however, this function - // should never be called for RAM because of the way page accessing - // has been setup - return false; + pokeRAM(myRAM[address & 0x007F], address, value); + return true; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/CartF6SC.cxx b/src/emucore/CartF6SC.cxx index 6b536caf1..56903242a 100644 --- a/src/emucore/CartF6SC.cxx +++ b/src/emucore/CartF6SC.cxx @@ -47,16 +47,16 @@ void CartridgeF6SC::install(System& system) System::PageAccess access(this, System::PA_READ); // Set the page accessing method for the RAM writing pages + // Map access to this class, since we need to inspect all accesses to + // check if RWP happens access.type = System::PA_WRITE; for(uInt16 addr = 0x1000; addr < 0x1080; addr += System::PAGE_SIZE) { - access.directPokeBase = &myRAM[addr & 0x007F]; access.codeAccessBase = &myCodeAccessBase[addr & 0x007F]; mySystem->setPageAccess(addr, access); } // Set the page accessing method for the RAM reading pages - access.directPokeBase = nullptr; access.type = System::PA_READ; for(uInt16 addr = 0x1080; addr < 0x1100; addr += System::PAGE_SIZE) { @@ -103,25 +103,13 @@ uInt8 CartridgeF6SC::peek(uInt16 address) } if(address < 0x0080) // Write port is at 0xF000 - 0xF07F (128 bytes) - { - // Reading from the write port triggers an unwanted write - uInt8 value = mySystem->getDataBusState(0xFF); - - if(bankLocked()) - return value; - else - { - myRAM[address] = value; - triggerReadFromWritePort(peekAddress); - return value; - } - } + return peekRAM(myRAM[address], peekAddress); else return myImage[myBankOffset + address]; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool CartridgeF6SC::poke(uInt16 address, uInt8) +bool CartridgeF6SC::poke(uInt16 address, uInt8 value) { address &= 0x0FFF; @@ -131,31 +119,29 @@ bool CartridgeF6SC::poke(uInt16 address, uInt8) case 0x0FF6: // Set the current bank to the first 4k bank bank(0); - break; + return false; case 0x0FF7: // Set the current bank to the second 4k bank bank(1); - break; + return false; case 0x0FF8: // Set the current bank to the third 4k bank bank(2); - break; + return false; case 0x0FF9: // Set the current bank to the forth 4k bank bank(3); - break; + return false; default: break; } - // NOTE: This does not handle accessing RAM, however, this function - // should never be called for RAM because of the way page accessing - // has been setup - return false; + pokeRAM(myRAM[address & 0x007F], address, value); + return true; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -