mirror of https://github.com/stella-emu/stella.git
fix #663 (illegal segment access)
This commit is contained in:
parent
dc3324e083
commit
9cf4686bc2
|
@ -155,8 +155,7 @@ uInt8 CartridgeEnhanced::peek(uInt16 address)
|
||||||
// This is a read access to a write port!
|
// This is a read access to a write port!
|
||||||
// Reading from the write port triggers an unwanted write
|
// Reading from the write port triggers an unwanted write
|
||||||
// The RAM banks follow the ROM banks and are half the size of a ROM bank
|
// The RAM banks follow the ROM banks and are half the size of a ROM bank
|
||||||
return peekRAM(myRAM[((myCurrentSegOffset[(peekAddress & ROM_MASK) >> myBankShift] - mySize) >> 1) + address],
|
return peekRAM(myRAM[ramAddressSegmentOffset(peekAddress) + address], peekAddress);
|
||||||
peekAddress);
|
|
||||||
}
|
}
|
||||||
address &= ROM_MASK;
|
address &= ROM_MASK;
|
||||||
|
|
||||||
|
@ -168,8 +167,7 @@ uInt8 CartridgeEnhanced::peek(uInt16 address)
|
||||||
return peekRAM(myRAM[address], peekAddress);
|
return peekRAM(myRAM[address], peekAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
return myImage[myCurrentSegOffset[(peekAddress & ROM_MASK) >> myBankShift]
|
return myImage[romAddressSegmentOffset(peekAddress) + (peekAddress & myBankMask)];
|
||||||
+ (peekAddress & myBankMask)];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
@ -190,7 +188,7 @@ bool CartridgeEnhanced::poke(uInt16 address, uInt8 value)
|
||||||
{
|
{
|
||||||
address &= myRamMask;
|
address &= myRamMask;
|
||||||
// The RAM banks follow the ROM banks and are half the size of a ROM bank
|
// The RAM banks follow the ROM banks and are half the size of a ROM bank
|
||||||
pokeRAM(myRAM[((myCurrentSegOffset[(pokeAddress & ROM_MASK) >> myBankShift] - mySize) >> 1) + address],
|
pokeRAM(myRAM[ramAddressSegmentOffset(pokeAddress) + address],
|
||||||
pokeAddress, value);
|
pokeAddress, value);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -300,10 +298,22 @@ bool CartridgeEnhanced::bank(uInt16 bank, uInt16 segment)
|
||||||
return myBankChanged = true;
|
return myBankChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
uInt16 CartridgeEnhanced::romAddressSegmentOffset(uInt16 address) const
|
||||||
|
{
|
||||||
|
return myCurrentSegOffset[((address & ROM_MASK) >> myBankShift) % myBankSegs];
|
||||||
|
}
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
uInt16 CartridgeEnhanced::ramAddressSegmentOffset(uInt16 address) const
|
||||||
|
{
|
||||||
|
return uInt16(myCurrentSegOffset[((address & ROM_MASK) >> myBankShift) % myBankSegs] - mySize) >> 1;
|
||||||
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
uInt16 CartridgeEnhanced::getBank(uInt16 address) const
|
uInt16 CartridgeEnhanced::getBank(uInt16 address) const
|
||||||
{
|
{
|
||||||
return myCurrentSegOffset[(address & ROM_MASK) >> myBankShift] >> myBankShift;
|
return romAddressSegmentOffset(address) >> myBankShift;
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
@ -335,7 +345,7 @@ bool CartridgeEnhanced::patch(uInt16 address, uInt8 value)
|
||||||
{
|
{
|
||||||
if(isRamBank(address))
|
if(isRamBank(address))
|
||||||
{
|
{
|
||||||
myRAM[((myCurrentSegOffset[(address & ROM_MASK) >> myBankShift] - mySize) >> 1) + (address & myRamMask)] = value;
|
myRAM[ramAddressSegmentOffset(address) + (address & myRamMask)] = value;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -347,7 +357,7 @@ bool CartridgeEnhanced::patch(uInt16 address, uInt8 value)
|
||||||
myRAM[address & myRamMask] = value;
|
myRAM[address & myRamMask] = value;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
myImage[myCurrentSegOffset[(address & ROM_MASK) >> myBankShift] + (address & myBankMask)] = value;
|
myImage[romAddressSegmentOffset(address) + (address & myBankMask)] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return myBankChanged = true;
|
return myBankChanged = true;
|
||||||
|
|
|
@ -256,6 +256,7 @@ class CartridgeEnhanced : public Cartridge
|
||||||
|
|
||||||
@param address The address to check
|
@param address The address to check
|
||||||
@param value The optional value used to determine the bank switched to
|
@param value The optional value used to determine the bank switched to
|
||||||
|
|
||||||
@return True if a bank switch happened.
|
@return True if a bank switch happened.
|
||||||
*/
|
*/
|
||||||
virtual bool checkSwitchBank(uInt16 address, uInt8 value = 0) = 0;
|
virtual bool checkSwitchBank(uInt16 address, uInt8 value = 0) = 0;
|
||||||
|
@ -268,6 +269,22 @@ class CartridgeEnhanced : public Cartridge
|
||||||
*/
|
*/
|
||||||
virtual uInt16 getStartBank() const { return 0; }
|
virtual uInt16 getStartBank() const { return 0; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
Get the ROM offset of the segment of the given address
|
||||||
|
|
||||||
|
@param address The address to get the offset for
|
||||||
|
@return The calculated offset
|
||||||
|
*/
|
||||||
|
uInt16 romAddressSegmentOffset(uInt16 address) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Get the RAM offset of the segment of the given address
|
||||||
|
|
||||||
|
@param address The address to get the offset for
|
||||||
|
@return The calculated offset
|
||||||
|
*/
|
||||||
|
uInt16 ramAddressSegmentOffset(uInt16 address) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Following constructors and assignment operators not supported
|
// Following constructors and assignment operators not supported
|
||||||
CartridgeEnhanced() = delete;
|
CartridgeEnhanced() = delete;
|
||||||
|
|
Loading…
Reference in New Issue