mirror of https://github.com/stella-emu/stella.git
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:
parent
8cf8200908
commit
a5d9550f2f
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue