First pass at cleanup of the peek/poke API from Device class:

- remove peek and poke from classes where the addressing is set up such that they aren't needed
- where possible, move from using 'myCurrentBank << 12' everywhere, to precomputing the value (perhaps a small optimization, but still valid)
This commit is contained in:
Stephen Anthony 2017-08-30 19:45:57 -02:30
parent 8cf8200908
commit a5d9550f2f
10 changed files with 28 additions and 113 deletions

View File

@ -59,14 +59,14 @@ Cartridge0840Widget::Cartridge0840Widget(
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Cartridge0840Widget::loadConfig() void Cartridge0840Widget::loadConfig()
{ {
myBank->setSelectedIndex(myCart.myCurrentBank); myBank->setSelectedIndex(myCart.getBank());
CartDebugWidget::loadConfig(); CartDebugWidget::loadConfig();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Cartridge0840Widget::handleCommand(CommandSender* sender, void Cartridge0840Widget::handleCommand(CommandSender* sender,
int cmd, int data, int id) int cmd, int data, int id)
{ {
if(cmd == kBankChanged) if(cmd == kBankChanged)
{ {
@ -83,8 +83,8 @@ string Cartridge0840Widget::bankState()
ostringstream& buf = buffer(); ostringstream& buf = buffer();
static const char* const spot[] = { "$800", "$840" }; static const char* const spot[] = { "$800", "$840" };
buf << "Bank = " << std::dec << myCart.myCurrentBank buf << "Bank = " << std::dec << myCart.getBank()
<< ", hotspot = " << spot[myCart.myCurrentBank]; << ", hotspot = " << spot[myCart.getBank()];
return buf.str(); return buf.str();
} }

View File

@ -22,7 +22,7 @@
Cartridge0840::Cartridge0840(const BytePtr& image, uInt32 size, Cartridge0840::Cartridge0840(const BytePtr& image, uInt32 size,
const Settings& settings) const Settings& settings)
: Cartridge(settings), : Cartridge(settings),
myCurrentBank(0) myBankOffset(0)
{ {
// Copy the ROM image into my buffer // Copy the ROM image into my buffer
memcpy(myImage, image.get(), std::min(8192u, size)); memcpy(myImage, image.get(), std::min(8192u, size));
@ -135,8 +135,7 @@ bool Cartridge0840::bank(uInt16 bank)
if(bankLocked()) return false; if(bankLocked()) return false;
// Remember what bank we're in // Remember what bank we're in
myCurrentBank = bank; myBankOffset = bank << 12;
uInt16 offset = myCurrentBank << 12;
// Setup the page access methods for the current bank // Setup the page access methods for the current bank
System::PageAccess access(this, System::PA_READ); System::PageAccess access(this, System::PA_READ);
@ -144,8 +143,8 @@ bool Cartridge0840::bank(uInt16 bank)
// Map ROM image into the system // Map ROM image into the system
for(uInt32 address = 0x1000; address < 0x2000; address += (1 << System::PAGE_SHIFT)) for(uInt32 address = 0x1000; address < 0x2000; address += (1 << System::PAGE_SHIFT))
{ {
access.directPeekBase = &myImage[offset + (address & 0x0FFF)]; access.directPeekBase = &myImage[myBankOffset + (address & 0x0FFF)];
access.codeAccessBase = &myCodeAccessBase[offset + (address & 0x0FFF)]; access.codeAccessBase = &myCodeAccessBase[myBankOffset + (address & 0x0FFF)];
mySystem->setPageAccess(address >> System::PAGE_SHIFT, access); mySystem->setPageAccess(address >> System::PAGE_SHIFT, access);
} }
return myBankChanged = true; return myBankChanged = true;
@ -154,7 +153,7 @@ bool Cartridge0840::bank(uInt16 bank)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt16 Cartridge0840::getBank() const uInt16 Cartridge0840::getBank() const
{ {
return myCurrentBank; return myBankOffset >> 12;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -166,7 +165,7 @@ uInt16 Cartridge0840::bankCount() const
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool Cartridge0840::patch(uInt16 address, uInt8 value) bool Cartridge0840::patch(uInt16 address, uInt8 value)
{ {
myImage[(myCurrentBank << 12) + (address & 0x0fff)] = value; myImage[myBankOffset + (address & 0x0fff)] = value;
return myBankChanged = true; return myBankChanged = true;
} }
@ -183,7 +182,7 @@ bool Cartridge0840::save(Serializer& out) const
try try
{ {
out.putString(name()); out.putString(name());
out.putShort(myCurrentBank); out.putShort(myBankOffset);
} }
catch(...) catch(...)
{ {
@ -202,7 +201,7 @@ bool Cartridge0840::load(Serializer& in)
if(in.getString() != name()) if(in.getString() != name())
return false; return false;
myCurrentBank = in.getShort(); myBankOffset = in.getShort();
} }
catch(...) catch(...)
{ {
@ -211,7 +210,7 @@ bool Cartridge0840::load(Serializer& in)
} }
// Remember what bank we were in // Remember what bank we were in
bank(myCurrentBank); bank(myBankOffset);
return true; return true;
} }

View File

@ -150,8 +150,8 @@ class Cartridge0840 : public Cartridge
// The 8K ROM image of the cartridge // The 8K ROM image of the cartridge
uInt8 myImage[8192]; uInt8 myImage[8192];
// Indicates which bank is currently active // Indicates the offset into the ROM image (aligns to current bank)
uInt16 myCurrentBank; uInt16 myBankOffset;
// Previous Device's page access // Previous Device's page access
System::PageAccess myHotSpotPageAccess[8]; System::PageAccess myHotSpotPageAccess[8];

View File

@ -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) bool Cartridge2K::patch(uInt16 address, uInt8 value)
{ {

View File

@ -114,23 +114,6 @@ class Cartridge2K : public Cartridge
} }
#endif #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: private:
// Pointer to a dynamically allocated ROM image of the cartridge // Pointer to a dynamically allocated ROM image of the cartridge
BytePtr myImage; BytePtr myImage;

View File

@ -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) bool Cartridge4K::patch(uInt16 address, uInt8 value)
{ {

View File

@ -113,23 +113,6 @@ class Cartridge4K : public Cartridge
} }
#endif #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: private:
// The 4K ROM image for the cartridge // The 4K ROM image for the cartridge
uInt8 myImage[4096]; uInt8 myImage[4096];

View File

@ -74,33 +74,18 @@ void Cartridge4KSC::install(System& system)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt8 Cartridge4KSC::peek(uInt16 address) uInt8 Cartridge4KSC::peek(uInt16 address)
{ {
uInt16 peekAddress = address; // The only way we can get to this method is if we attempt to read from
address &= 0x0FFF; // 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) if(bankLocked())
{ return value;
// 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;
}
}
else else
return myImage[address & 0x0FFF]; {
} triggerReadFromWritePort(address);
return myRAM[address & 0x0FFF] = value;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
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;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -119,17 +119,8 @@ class Cartridge4KSC : public Cartridge
*/ */
uInt8 peek(uInt16 address) override; 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: private:
// The 8K ROM image of the cartridge // The 4K ROM image of the cartridge
uInt8 myImage[4096]; uInt8 myImage[4096];
// The 128 bytes of RAM // The 128 bytes of RAM

View File

@ -99,7 +99,7 @@ class Device : public Serializable
@return The byte at the specified address @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 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 @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 Query the given address for its disassembly flags