Skip to content

Commit

Permalink
added "code in RAM" execution check for F4SC, F6SC and F8SC (addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
thrust26 committed Jan 29, 2023
1 parent 5f1f902 commit 433d8da
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/emucore/Cart.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,13 @@ class Cartridge : public Device
*/
virtual uInt16 ramBankCount() const { return 0; }

/**
Query wether the current PC allows code execution.
@return true, if code execution is allowed
*/
virtual bool canExecute(uInt16 PC) const { return true; }

/**
Get the number of segments supported by the cartridge.
*/
Expand Down
16 changes: 16 additions & 0 deletions src/emucore/CartEnhanced.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,22 @@ class CartridgeEnhanced : public Cartridge
*/
uInt16 ramBankCount() const override;

/**
Query wether the current PC allows code execution.
@return true, if code execution is allowed
*/
bool canExecute(uInt16 PC) const override {
return !(PC & 0x1000) || (PC & ROM_MASK) >= myRomOffset || executableCartRam();
}

/**
Query wether the cart RAM allows code execution.
@return true, if code execution is allowed
*/
virtual bool executableCartRam() const { return true; }

/**
Get the number of segments supported by the cartridge.
*/
Expand Down
7 changes: 7 additions & 0 deletions src/emucore/CartF4SC.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ class CartridgeF4SC : public CartridgeF4
~CartridgeF4SC() override = default;

public:
/**
Query wether the cart RAM allows code execution.
@return true, if code execution is allowed
*/
bool executableCartRam() const override { return false; }

/**
Get a descriptor for the device name (used in error checking).
Expand Down
7 changes: 7 additions & 0 deletions src/emucore/CartF6SC.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ class CartridgeF6SC : public CartridgeF6
~CartridgeF6SC() override = default;

public:
/**
Query wether the cart RAM allows code execution.
@return true, if code execution is allowed
*/
bool executableCartRam() const override { return false; }

/**
Get a descriptor for the device name (used in error checking).
Expand Down
7 changes: 7 additions & 0 deletions src/emucore/CartF8SC.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ class CartridgeF8SC : public CartridgeF8
~CartridgeF8SC() override = default;

public:
/**
Query wether the cart RAM allows code execution.
@return true, if code execution is allowed
*/
bool executableCartRam() const override { return false; }

/**
Get a descriptor for the device name (used in error checking).
Expand Down
4 changes: 4 additions & 0 deletions src/emucore/M6502.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,10 @@ inline void M6502::_execute(uInt64 cycles, DispatchResult& result)
icycles = 0;
#ifdef DEBUGGER_SUPPORT
const uInt16 oldPC = PC;

// Only check for code in RAM execution if we have debugger support
if(!mySystem->cart().canExecute(PC))
FatalEmulationError::raise("cannot run code from cart RAM");
#endif

// Fetch instruction at the program counter
Expand Down

0 comments on commit 433d8da

Please sign in to comment.