diff --git a/src/debugger/gui/Cart0840Widget.cxx b/src/debugger/gui/Cart0840Widget.cxx index 4b33fdc5a..8902690d8 100644 --- a/src/debugger/gui/Cart0840Widget.cxx +++ b/src/debugger/gui/Cart0840Widget.cxx @@ -59,14 +59,14 @@ Cartridge0840Widget::Cartridge0840Widget( // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Cartridge0840Widget::loadConfig() { - myBank->setSelectedIndex(myCart.myCurrentBank); + myBank->setSelectedIndex(myCart.getBank()); CartDebugWidget::loadConfig(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Cartridge0840Widget::handleCommand(CommandSender* sender, - int cmd, int data, int id) + int cmd, int data, int id) { if(cmd == kBankChanged) { @@ -83,8 +83,8 @@ string Cartridge0840Widget::bankState() ostringstream& buf = buffer(); static const char* const spot[] = { "$800", "$840" }; - buf << "Bank = " << std::dec << myCart.myCurrentBank - << ", hotspot = " << spot[myCart.myCurrentBank]; + buf << "Bank = " << std::dec << myCart.getBank() + << ", hotspot = " << spot[myCart.getBank()]; return buf.str(); } diff --git a/src/emucore/Cart0840.cxx b/src/emucore/Cart0840.cxx index 877fed9cd..c2a38b8eb 100644 --- a/src/emucore/Cart0840.cxx +++ b/src/emucore/Cart0840.cxx @@ -22,7 +22,7 @@ Cartridge0840::Cartridge0840(const BytePtr& image, uInt32 size, const Settings& settings) : Cartridge(settings), - myCurrentBank(0) + myBankOffset(0) { // Copy the ROM image into my buffer memcpy(myImage, image.get(), std::min(8192u, size)); @@ -135,8 +135,7 @@ bool Cartridge0840::bank(uInt16 bank) if(bankLocked()) return false; // Remember what bank we're in - myCurrentBank = bank; - uInt16 offset = myCurrentBank << 12; + myBankOffset = bank << 12; // Setup the page access methods for the current bank System::PageAccess access(this, System::PA_READ); @@ -144,8 +143,8 @@ bool Cartridge0840::bank(uInt16 bank) // Map ROM image into the system for(uInt32 address = 0x1000; address < 0x2000; address += (1 << System::PAGE_SHIFT)) { - access.directPeekBase = &myImage[offset + (address & 0x0FFF)]; - access.codeAccessBase = &myCodeAccessBase[offset + (address & 0x0FFF)]; + access.directPeekBase = &myImage[myBankOffset + (address & 0x0FFF)]; + access.codeAccessBase = &myCodeAccessBase[myBankOffset + (address & 0x0FFF)]; mySystem->setPageAccess(address >> System::PAGE_SHIFT, access); } return myBankChanged = true; @@ -154,7 +153,7 @@ bool Cartridge0840::bank(uInt16 bank) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt16 Cartridge0840::getBank() const { - return myCurrentBank; + return myBankOffset >> 12; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -166,7 +165,7 @@ uInt16 Cartridge0840::bankCount() const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool Cartridge0840::patch(uInt16 address, uInt8 value) { - myImage[(myCurrentBank << 12) + (address & 0x0fff)] = value; + myImage[myBankOffset + (address & 0x0fff)] = value; return myBankChanged = true; } @@ -183,7 +182,7 @@ bool Cartridge0840::save(Serializer& out) const try { out.putString(name()); - out.putShort(myCurrentBank); + out.putShort(myBankOffset); } catch(...) { @@ -202,7 +201,7 @@ bool Cartridge0840::load(Serializer& in) if(in.getString() != name()) return false; - myCurrentBank = in.getShort(); + myBankOffset = in.getShort(); } catch(...) { @@ -211,7 +210,7 @@ bool Cartridge0840::load(Serializer& in) } // Remember what bank we were in - bank(myCurrentBank); + bank(myBankOffset); return true; } diff --git a/src/emucore/Cart0840.hxx b/src/emucore/Cart0840.hxx index ebc6965df..4d2c96b14 100644 --- a/src/emucore/Cart0840.hxx +++ b/src/emucore/Cart0840.hxx @@ -150,8 +150,8 @@ class Cartridge0840 : public Cartridge // The 8K ROM image of the cartridge uInt8 myImage[8192]; - // Indicates which bank is currently active - uInt16 myCurrentBank; + // Indicates the offset into the ROM image (aligns to current bank) + uInt16 myBankOffset; // Previous Device's page access System::PageAccess myHotSpotPageAccess[8]; diff --git a/src/emucore/Cart2K.cxx b/src/emucore/Cart2K.cxx index 005687eaf..9547a7774 100644 --- a/src/emucore/Cart2K.cxx +++ b/src/emucore/Cart2K.cxx @@ -71,19 +71,6 @@ void Cartridge2K::install(System& system) } } -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt8 Cartridge2K::peek(uInt16 address) -{ - return myImage[address & myMask]; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool Cartridge2K::poke(uInt16, uInt8) -{ - // This is ROM so poking has no effect :-) - return false; -} - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool Cartridge2K::patch(uInt16 address, uInt8 value) { diff --git a/src/emucore/Cart2K.hxx b/src/emucore/Cart2K.hxx index 273627d6e..c79479df0 100644 --- a/src/emucore/Cart2K.hxx +++ b/src/emucore/Cart2K.hxx @@ -114,23 +114,6 @@ class Cartridge2K : public Cartridge } #endif - public: - /** - Get the byte at the specified address - - @return The byte at the specified address - */ - 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: // Pointer to a dynamically allocated ROM image of the cartridge BytePtr myImage; diff --git a/src/emucore/Cart4K.cxx b/src/emucore/Cart4K.cxx index 3e376f264..77b9e8540 100644 --- a/src/emucore/Cart4K.cxx +++ b/src/emucore/Cart4K.cxx @@ -50,19 +50,6 @@ void Cartridge4K::install(System& system) } } -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt8 Cartridge4K::peek(uInt16 address) -{ - return myImage[address & 0x0FFF]; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool Cartridge4K::poke(uInt16, uInt8) -{ - // This is ROM so poking has no effect :-) - return false; -} - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool Cartridge4K::patch(uInt16 address, uInt8 value) { diff --git a/src/emucore/Cart4K.hxx b/src/emucore/Cart4K.hxx index 07d98d77a..f2b33624c 100644 --- a/src/emucore/Cart4K.hxx +++ b/src/emucore/Cart4K.hxx @@ -113,23 +113,6 @@ class Cartridge4K : public Cartridge } #endif - public: - /** - Get the byte at the specified address. - - @return The byte at the specified address - */ - 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 for the cartridge uInt8 myImage[4096]; diff --git a/src/emucore/Cart4KSC.cxx b/src/emucore/Cart4KSC.cxx index daead3848..20f20e6d4 100644 --- a/src/emucore/Cart4KSC.cxx +++ b/src/emucore/Cart4KSC.cxx @@ -74,33 +74,18 @@ void Cartridge4KSC::install(System& system) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt8 Cartridge4KSC::peek(uInt16 address) { - uInt16 peekAddress = address; - address &= 0x0FFF; + // The only way we can get to this method is if we attempt to read from + // the write port (0xF000 - 0xF080, 128 bytes), in which case an + // unwanted write is triggered + uInt8 value = mySystem->getDataBusState(0xFF); - if(address < 0x0080) // Write port is at 0xF000 - 0xF080 (128 bytes) - { - // Reading from the write port triggers an unwanted write - uInt8 value = mySystem->getDataBusState(0xFF); - - if(bankLocked()) - return value; - else - { - triggerReadFromWritePort(peekAddress); - return myRAM[address] = value; - } - } + if(bankLocked()) + return value; else - return myImage[address & 0x0FFF]; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool Cartridge4KSC::poke(uInt16 address, uInt8) -{ - // 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; + { + triggerReadFromWritePort(address); + return myRAM[address & 0x0FFF] = value; + } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/Cart4KSC.hxx b/src/emucore/Cart4KSC.hxx index 668a8c718..81344e245 100644 --- a/src/emucore/Cart4KSC.hxx +++ b/src/emucore/Cart4KSC.hxx @@ -119,17 +119,8 @@ 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 8K ROM image of the cartridge + // The 4K ROM image of the cartridge uInt8 myImage[4096]; // The 128 bytes of RAM diff --git a/src/emucore/Device.hxx b/src/emucore/Device.hxx index 817cb9ef7..35bc48b77 100644 --- a/src/emucore/Device.hxx +++ b/src/emucore/Device.hxx @@ -99,7 +99,7 @@ class Device : public Serializable @return The byte at the specified address */ - virtual uInt8 peek(uInt16 address) = 0; + virtual uInt8 peek(uInt16 address) { return 0; } /** Change the byte at the specified address to the given value @@ -109,7 +109,7 @@ class Device : public Serializable @return True if the poke changed the device address space, else false */ - virtual bool poke(uInt16 address, uInt8 value) = 0; + virtual bool poke(uInt16 address, uInt8 value) { return false; } /** Query the given address for its disassembly flags