Fix some clang-tidy warnings.

This commit is contained in:
Stephen Anthony 2024-07-30 14:52:21 -02:30
parent 3c4fc5c5c4
commit 08257941b8
9 changed files with 120 additions and 67 deletions

View File

@ -166,7 +166,7 @@ void PhysicalJoystickHandler::addToDatabase(const PhysicalJoystickPtr& stick)
} }
else // adding for the first time else // adding for the first time
{ {
StickInfo info("", stick); const StickInfo info("", stick);
myDatabase.emplace(stick->name, info); myDatabase.emplace(stick->name, info);
setStickDefaultMapping(stick->ID, Event::NoType, EventMode::kMenuMode); setStickDefaultMapping(stick->ID, Event::NoType, EventMode::kMenuMode);
setStickDefaultMapping(stick->ID, Event::NoType, EventMode::kEmulationMode); setStickDefaultMapping(stick->ID, Event::NoType, EventMode::kEmulationMode);

View File

@ -151,7 +151,7 @@ namespace {
void writeDebugBinary(const ElfLinker& linker) void writeDebugBinary(const ElfLinker& linker)
{ {
constexpr size_t IMAGE_SIZE = 4 * 0x00100000; constexpr size_t IMAGE_SIZE = 4L * 0x00100000;
static const char* IMAGE_FILE_NAME = "elf_executable_image.bin"; static const char* IMAGE_FILE_NAME = "elf_executable_image.bin";
auto binary = make_unique<uInt8[]>(IMAGE_SIZE); auto binary = make_unique<uInt8[]>(IMAGE_SIZE);
@ -168,10 +168,10 @@ namespace {
std::ofstream binaryFile; std::ofstream binaryFile;
binaryFile.open(IMAGE_FILE_NAME); binaryFile.open(IMAGE_FILE_NAME);
binaryFile.write(reinterpret_cast<const char*>(binary.get()), 4 * 0x00100000); binaryFile.write(reinterpret_cast<const char*>(binary.get()), 4L * 0x00100000);
} }
cout << "wrote executable image to " << IMAGE_FILE_NAME << std::endl; cout << "wrote executable image to " << IMAGE_FILE_NAME << '\n';
} }
#endif #endif
} // namespace } // namespace
@ -194,7 +194,6 @@ CartridgeELF::CartridgeELF(const ByteBuffer& image, size_t size, string_view md5
setupMemoryMap(); setupMemoryMap();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CartridgeELF::~CartridgeELF() = default; CartridgeELF::~CartridgeELF() = default;
@ -286,6 +285,7 @@ bool CartridgeELF::poke(uInt16 address, uInt8 value)
return false; return false;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CartridgeELF::consoleChanged(ConsoleTiming timing) void CartridgeELF::consoleChanged(ConsoleTiming timing)
{ {
myConsoleTiming = timing; myConsoleTiming = timing;
@ -325,6 +325,7 @@ CortexM0::err_t CartridgeELF::BusFallbackDelegate::fetch16(
: CortexM0::errIntrinsic(CortexM0::ERR_UNMAPPED_FETCH16, address); : CortexM0::errIntrinsic(CortexM0::ERR_UNMAPPED_FETCH16, address);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CortexM0::err_t CartridgeELF::BusFallbackDelegate::read8(uInt32 address, uInt8& value, CortexM0& cortex) CortexM0::err_t CartridgeELF::BusFallbackDelegate::read8(uInt32 address, uInt8& value, CortexM0& cortex)
{ {
// TODO: remove this hack and replace it with a setting. // TODO: remove this hack and replace it with a setting.
@ -332,6 +333,7 @@ CortexM0::err_t CartridgeELF::BusFallbackDelegate::read8(uInt32 address, uInt8&
return 0; return 0;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
inline uInt64 CartridgeELF::getArmCycles() const inline uInt64 CartridgeELF::getArmCycles() const
{ {
return myCortexEmu.getCycles() + myArmCyclesOffset; return myCortexEmu.getCycles() + myArmCyclesOffset;
@ -398,8 +400,8 @@ void CartridgeELF::parseAndLinkElf()
cout cout
<< "\nARM entrypoint: 0x" << "\nARM entrypoint: 0x"
<< std::hex << std::setw(8) << std::setfill('0') << myArmEntrypoint << std::dec << std::hex << std::setw(8) << std::setfill('0') << myArmEntrypoint
<< '\n'; << std::dec << '\n';
writeDebugBinary(*myLinker); writeDebugBinary(*myLinker);
#endif #endif
@ -463,6 +465,7 @@ uInt32 CartridgeELF::getSystemType() const
} }
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CartridgeELF::switchExecutionStage() void CartridgeELF::switchExecutionStage()
{ {
constexpr uInt32 sp = ADDR_STACK_BASE + STACK_SIZE; constexpr uInt32 sp = ADDR_STACK_BASE + STACK_SIZE;
@ -478,7 +481,8 @@ void CartridgeELF::switchExecutionStage()
myInitFunctionIndex = 0; myInitFunctionIndex = 0;
} }
else { else {
return callFn(myLinker->getPreinitArray()[myInitFunctionIndex++], sp); callFn(myLinker->getPreinitArray()[myInitFunctionIndex++], sp);
return;
} }
} }
@ -487,13 +491,15 @@ void CartridgeELF::switchExecutionStage()
myExecutionStage = ExecutionStage::main; myExecutionStage = ExecutionStage::main;
} }
else { else {
return callFn(myLinker->getInitArray()[myInitFunctionIndex++], sp); callFn(myLinker->getInitArray()[myInitFunctionIndex++], sp);
return;
} }
} }
callMain(); callMain();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CartridgeELF::callFn(uInt32 ptr, uInt32 sp) void CartridgeELF::callFn(uInt32 ptr, uInt32 sp)
{ {
myCortexEmu myCortexEmu
@ -526,6 +532,7 @@ void CartridgeELF::callMain()
callFn(myArmEntrypoint, sp); callFn(myArmEntrypoint, sp);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CartridgeELF::runArm() void CartridgeELF::runArm()
{ {
if ( if (
@ -537,7 +544,7 @@ void CartridgeELF::runArm()
const uInt32 cyclesGoal = const uInt32 cyclesGoal =
(mySystem->cycles() + ARM_RUNAHED_MAX) * myArmCyclesPer6502Cycle - getArmCycles(); (mySystem->cycles() + ARM_RUNAHED_MAX) * myArmCyclesPer6502Cycle - getArmCycles();
uInt32 cycles; uInt32 cycles = 0;
const CortexM0::err_t err = myCortexEmu.run(cyclesGoal, cycles); const CortexM0::err_t err = myCortexEmu.run(cyclesGoal, cycles);
@ -556,5 +563,3 @@ void CartridgeELF::runArm()
FatalEmulationError::raise("error executing ARM code: " + CortexM0::describeError(err)); FatalEmulationError::raise("error executing ARM code: " + CortexM0::describeError(err));
} }
} }

View File

@ -1277,7 +1277,7 @@ void Console::changeAutoFireRate(int direction)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
float Console::currentFrameRate() const float Console::currentFrameRate() const
{ {
uInt32 scalinesLastFrame = myTIA->frameBufferScanlinesLastFrame(); const uInt32 scalinesLastFrame = myTIA->frameBufferScanlinesLastFrame();
return return
scalinesLastFrame != 0 ? scalinesLastFrame != 0 ?

View File

@ -77,9 +77,6 @@
#define branch_target_9(inst) (read_register(15) + 2 + (((Int32)(inst) << 24) >> 23)) #define branch_target_9(inst) (read_register(15) + 2 + (((Int32)(inst) << 24) >> 23))
#define branch_target_12(inst) (read_register(15) + 2 + (((Int32)(inst) << 21) >> 20)) #define branch_target_12(inst) (read_register(15) + 2 + (((Int32)(inst) << 21) >> 20))
using std::dec;
using Common::Base;
namespace { namespace {
constexpr uInt32 PAGEMAP_SIZE = 0x100000000 / 4096; constexpr uInt32 PAGEMAP_SIZE = 0x100000000 / 4096;
@ -462,6 +459,9 @@ namespace {
case CortexM0::ERR_UNDEFINED_INST: case CortexM0::ERR_UNDEFINED_INST:
return "undefined instruction"; return "undefined instruction";
default:
break;
} }
ostringstream s; ostringstream s;
@ -469,38 +469,45 @@ namespace {
return s.str(); return s.str();
} }
} } // namespace
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CortexM0::err_t CortexM0::BusTransactionDelegate::read32(uInt32 address, uInt32& value, CortexM0& cortex) CortexM0::err_t CortexM0::BusTransactionDelegate::read32(uInt32 address, uInt32& value, CortexM0& cortex)
{ {
return errIntrinsic(ERR_UNMAPPED_READ32, address); return errIntrinsic(ERR_UNMAPPED_READ32, address);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CortexM0::err_t CortexM0::BusTransactionDelegate::read16(uInt32 address, uInt16& value, CortexM0& cortex) CortexM0::err_t CortexM0::BusTransactionDelegate::read16(uInt32 address, uInt16& value, CortexM0& cortex)
{ {
return errIntrinsic(ERR_UNMAPPED_READ16, address); return errIntrinsic(ERR_UNMAPPED_READ16, address);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CortexM0::err_t CortexM0::BusTransactionDelegate::read8(uInt32 address, uInt8& value, CortexM0& cortex) CortexM0::err_t CortexM0::BusTransactionDelegate::read8(uInt32 address, uInt8& value, CortexM0& cortex)
{ {
return errIntrinsic(ERR_UNMAPPED_READ8, address); return errIntrinsic(ERR_UNMAPPED_READ8, address);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CortexM0::err_t CortexM0::BusTransactionDelegate::write32(uInt32 address, uInt32 value, CortexM0& cortex) CortexM0::err_t CortexM0::BusTransactionDelegate::write32(uInt32 address, uInt32 value, CortexM0& cortex)
{ {
return errIntrinsic(ERR_UNMAPPED_WRITE32, address); return errIntrinsic(ERR_UNMAPPED_WRITE32, address);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CortexM0::err_t CortexM0::BusTransactionDelegate::write16(uInt32 address, uInt16 value, CortexM0& cortex) CortexM0::err_t CortexM0::BusTransactionDelegate::write16(uInt32 address, uInt16 value, CortexM0& cortex)
{ {
return errIntrinsic(ERR_UNMAPPED_WRITE16, address); return errIntrinsic(ERR_UNMAPPED_WRITE16, address);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CortexM0::err_t CortexM0::BusTransactionDelegate::write8(uInt32 address, uInt8 value, CortexM0& cortex) CortexM0::err_t CortexM0::BusTransactionDelegate::write8(uInt32 address, uInt8 value, CortexM0& cortex)
{ {
return errIntrinsic(ERR_UNMAPPED_WRITE8, address); return errIntrinsic(ERR_UNMAPPED_WRITE8, address);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CortexM0::err_t CortexM0::BusTransactionDelegate::fetch16( CortexM0::err_t CortexM0::BusTransactionDelegate::fetch16(
uInt32 address, uInt16& value, uInt8& op, CortexM0& cortex uInt32 address, uInt16& value, uInt8& op, CortexM0& cortex
) { ) {
@ -512,6 +519,7 @@ CortexM0::err_t CortexM0::BusTransactionDelegate::fetch16(
return 0; return 0;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string CortexM0::describeError(err_t err) { string CortexM0::describeError(err_t err) {
if (err == ERR_NONE) return "no error"; if (err == ERR_NONE) return "no error";
@ -524,7 +532,7 @@ string CortexM0::describeError(err_t err) {
return s.str(); return s.str();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CortexM0::CortexM0() CortexM0::CortexM0()
{ {
myPageMap = make_unique<uInt8[]>(PAGEMAP_SIZE); myPageMap = make_unique<uInt8[]>(PAGEMAP_SIZE);
@ -533,6 +541,7 @@ CortexM0::CortexM0()
reset(); reset();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CortexM0& CortexM0::mapRegionData(uInt32 pageBase, CortexM0& CortexM0::mapRegionData(uInt32 pageBase,
uInt32 pageCount, bool readOnly, uInt8* backingStore) uInt32 pageCount, bool readOnly, uInt8* backingStore)
{ {
@ -544,6 +553,7 @@ CortexM0& CortexM0::mapRegionData(uInt32 pageBase,
return *this; return *this;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CortexM0& CortexM0::mapRegionCode(uInt32 pageBase, CortexM0& CortexM0::mapRegionCode(uInt32 pageBase,
uInt32 pageCount, bool readOnly, uInt8* backingStore) uInt32 pageCount, bool readOnly, uInt8* backingStore)
{ {
@ -556,6 +566,7 @@ CortexM0& CortexM0::mapRegionCode(uInt32 pageBase,
return *this; return *this;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CortexM0& CortexM0::mapRegionDelegate(uInt32 pageBase, uInt32 pageCount, bool readOnly, CortexM0& CortexM0::mapRegionDelegate(uInt32 pageBase, uInt32 pageCount, bool readOnly,
CortexM0::BusTransactionDelegate* delegate) CortexM0::BusTransactionDelegate* delegate)
{ {
@ -567,6 +578,7 @@ CortexM0& CortexM0::mapRegionDelegate(uInt32 pageBase, uInt32 pageCount, bool re
return *this; return *this;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CortexM0& CortexM0::mapDefault(CortexM0::BusTransactionDelegate* delegate) CortexM0& CortexM0::mapDefault(CortexM0::BusTransactionDelegate* delegate)
{ {
myDefaultDelegate = delegate; myDefaultDelegate = delegate;
@ -574,6 +586,7 @@ CortexM0& CortexM0::mapDefault(CortexM0::BusTransactionDelegate* delegate)
return *this; return *this;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CortexM0& CortexM0::reset() CortexM0& CortexM0::reset()
{ {
reg_norm.fill(0); reg_norm.fill(0);
@ -585,11 +598,13 @@ CortexM0& CortexM0::reset()
return *this; return *this;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CortexM0& CortexM0::setPc(uInt32 pc) CortexM0& CortexM0::setPc(uInt32 pc)
{ {
return setRegister(15, (pc & ~1) + 2); return setRegister(15, (pc & ~1) + 2);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CortexM0& CortexM0::setRegister(uInt8 regno, uInt32 value) CortexM0& CortexM0::setRegister(uInt8 regno, uInt32 value)
{ {
write_register(regno, value); write_register(regno, value);
@ -597,23 +612,26 @@ CortexM0& CortexM0::setRegister(uInt8 regno, uInt32 value)
return *this; return *this;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt32 CortexM0::getRegister(uInt32 regno) uInt32 CortexM0::getRegister(uInt32 regno)
{ {
return read_register(regno); return read_register(regno);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt8 CortexM0::decodeInstructionWord(uInt16 instructionWord) uInt8 CortexM0::decodeInstructionWord(uInt16 instructionWord)
{ {
return static_cast<uInt8>(::decodeInstructionWord(instructionWord)); return static_cast<uInt8>(::decodeInstructionWord(instructionWord));
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CortexM0::err_t CortexM0::run(uInt32 maxCycles, uInt32& cycles) CortexM0::err_t CortexM0::run(uInt32 maxCycles, uInt32& cycles)
{ {
for (cycles = 0; cycles < maxCycles; cycles++, myCycleCounter++) { for (cycles = 0; cycles < maxCycles; cycles++, myCycleCounter++) {
const uInt32 pc = read_register(15); const uInt32 pc = read_register(15);
uInt16 inst; uInt16 inst = 0;
uInt8 op; uInt8 op = 0;
err_t err = fetch16(pc - 2, inst, op); err_t err = fetch16(pc - 2, inst, op);
if (err) return err; if (err) return err;
@ -635,6 +653,7 @@ CortexM0::err_t CortexM0::run(uInt32 maxCycles, uInt32& cycles)
return ERR_NONE; return ERR_NONE;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CortexM0::MemoryRegion& CortexM0::setupMapping(uInt32 pageBase, uInt32 pageCount, CortexM0::MemoryRegion& CortexM0::setupMapping(uInt32 pageBase, uInt32 pageCount,
bool readOnly, CortexM0::MemoryRegionType type) bool readOnly, CortexM0::MemoryRegionType type)
{ {
@ -654,6 +673,7 @@ CortexM0::MemoryRegion& CortexM0::setupMapping(uInt32 pageBase, uInt32 pageCount
return region; return region;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CortexM0::recompileCodeRegions() void CortexM0::recompileCodeRegions()
{ {
for (const auto& region: myRegions) { for (const auto& region: myRegions) {
@ -665,6 +685,7 @@ void CortexM0::recompileCodeRegions()
} }
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CortexM0::err_t CortexM0::read32(uInt32 address, uInt32& value) CortexM0::err_t CortexM0::read32(uInt32 address, uInt32& value)
{ {
if (address & 0x03) return errIntrinsic(ERR_ACCESS_ALIGNMENT_FAULT, address); if (address & 0x03) return errIntrinsic(ERR_ACCESS_ALIGNMENT_FAULT, address);
@ -689,6 +710,7 @@ CortexM0::err_t CortexM0::read32(uInt32 address, uInt32& value)
} }
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CortexM0::err_t CortexM0::read16(uInt32 address, uInt16& value) CortexM0::err_t CortexM0::read16(uInt32 address, uInt16& value)
{ {
if (address & 0x01) return errIntrinsic(ERR_ACCESS_ALIGNMENT_FAULT, address); if (address & 0x01) return errIntrinsic(ERR_ACCESS_ALIGNMENT_FAULT, address);
@ -713,6 +735,7 @@ CortexM0::err_t CortexM0::read16(uInt32 address, uInt16& value)
} }
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CortexM0::err_t CortexM0::read8(uInt32 address, uInt8& value) CortexM0::err_t CortexM0::read8(uInt32 address, uInt8& value)
{ {
MemoryRegion& region = myRegions[myPageMap[address / PAGE_SIZE]]; MemoryRegion& region = myRegions[myPageMap[address / PAGE_SIZE]];
@ -735,6 +758,7 @@ CortexM0::err_t CortexM0::read8(uInt32 address, uInt8& value)
} }
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CortexM0::err_t CortexM0::write32(uInt32 address, uInt32 value) CortexM0::err_t CortexM0::write32(uInt32 address, uInt32 value)
{ {
if (address & 0x03) return errIntrinsic(ERR_ACCESS_ALIGNMENT_FAULT, address); if (address & 0x03) return errIntrinsic(ERR_ACCESS_ALIGNMENT_FAULT, address);
@ -760,6 +784,7 @@ CortexM0::err_t CortexM0::write32(uInt32 address, uInt32 value)
} }
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CortexM0::err_t CortexM0::write16(uInt32 address, uInt16 value) CortexM0::err_t CortexM0::write16(uInt32 address, uInt16 value)
{ {
if (address & 0x01) return errIntrinsic(ERR_ACCESS_ALIGNMENT_FAULT, address); if (address & 0x01) return errIntrinsic(ERR_ACCESS_ALIGNMENT_FAULT, address);
@ -790,6 +815,7 @@ CortexM0::err_t CortexM0::write16(uInt32 address, uInt16 value)
} }
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CortexM0::err_t CortexM0::write8(uInt32 address, uInt8 value) CortexM0::err_t CortexM0::write8(uInt32 address, uInt8 value)
{ {
MemoryRegion& region = myRegions[myPageMap[address / PAGE_SIZE]]; MemoryRegion& region = myRegions[myPageMap[address / PAGE_SIZE]];
@ -818,6 +844,7 @@ CortexM0::err_t CortexM0::write8(uInt32 address, uInt8 value)
} }
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CortexM0::err_t CortexM0::fetch16(uInt32 address, uInt16& value, uInt8& op) CortexM0::err_t CortexM0::fetch16(uInt32 address, uInt16& value, uInt8& op)
{ {
if (address & 0x01) return errIntrinsic(ERR_ACCESS_ALIGNMENT_FAULT, address); if (address & 0x01) return errIntrinsic(ERR_ACCESS_ALIGNMENT_FAULT, address);
@ -849,6 +876,7 @@ CortexM0::err_t CortexM0::fetch16(uInt32 address, uInt16& value, uInt8& op)
} }
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CortexM0::do_cvflag(uInt32 a, uInt32 b, uInt32 c) void CortexM0::do_cvflag(uInt32 a, uInt32 b, uInt32 c)
{ {
uInt32 rc = (a & 0x7FFFFFFF) + (b & 0x7FFFFFFF) + c; //carry in uInt32 rc = (a & 0x7FFFFFFF) + (b & 0x7FFFFFFF) + c; //carry in
@ -864,9 +892,10 @@ void CortexM0::do_cvflag(uInt32 a, uInt32 b, uInt32 c)
cFlag = rc & 2; cFlag = rc & 2;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CortexM0::err_t CortexM0::execute(uInt16 inst, uInt8 op) CortexM0::err_t CortexM0::execute(uInt16 inst, uInt8 op)
{ {
uInt32 sp, ra, rb, rc, rm, rd, rn, rs; // NOLINT uInt32 sp, ra, rb, rc, rm, rd, rn, rs; // NOLINT: don't need to initialize
#ifdef THUMB_DISS #ifdef THUMB_DISS
cout << "0x" << std::hex << std::setw(8) << std::setfill('0') << (read_register(15) - 4) << " " << std::dec; cout << "0x" << std::hex << std::setw(8) << std::setfill('0') << (read_register(15) - 4) << " " << std::dec;
@ -1378,13 +1407,13 @@ CortexM0::err_t CortexM0::execute(uInt16 inst, uInt8 op)
#endif #endif
sp = read_register(rn); sp = read_register(rn);
std::array<uInt32, 16> regsOld = reg_norm; const std::array<uInt32, 16> regsOld = reg_norm;
for(ra = 0, rb = 0x01; rb; rb = (rb << 1) & 0xFF, ++ra) for(ra = 0, rb = 0x01; rb; rb = (rb << 1) & 0xFF, ++ra)
{ {
if(inst & rb) if(inst & rb)
{ {
err_t err = read32(sp, reg_norm[ra]); const err_t err = read32(sp, reg_norm[ra]);
if (err) { if (err) {
reg_norm = regsOld; reg_norm = regsOld;
@ -1474,7 +1503,7 @@ CortexM0::err_t CortexM0::execute(uInt16 inst, uInt8 op)
DO_DISS("ldrb r" << dec << rd << ",[r" << dec << rn << ",#0x" << Base::HEX2 << rb << "]\n"); DO_DISS("ldrb r" << dec << rd << ",[r" << dec << rn << ",#0x" << Base::HEX2 << rb << "]\n");
rb = read_register(rn) + rb; rb = read_register(rn) + rb;
uInt8 val8; uInt8 val8 = 0;
const err_t err = read8(rb, val8); const err_t err = read8(rb, val8);
if (err) return err; if (err) return err;
@ -1492,7 +1521,7 @@ CortexM0::err_t CortexM0::execute(uInt16 inst, uInt8 op)
DO_DISS("ldrb r" << dec << rd << ",[r" << dec << rn << ",r" << dec << rm << "]\n"); DO_DISS("ldrb r" << dec << rd << ",[r" << dec << rn << ",r" << dec << rm << "]\n");
rb = read_register(rn) + read_register(rm); rb = read_register(rn) + read_register(rm);
uInt8 val8; uInt8 val8 = 0;
const err_t err = read8(rb, val8); const err_t err = read8(rb, val8);
if (err) return err; if (err) return err;
@ -1511,7 +1540,7 @@ CortexM0::err_t CortexM0::execute(uInt16 inst, uInt8 op)
DO_DISS("ldrh r" << dec << rd << ",[r" << dec << rn << ",#0x" << Base::HEX2 << rb << "]\n"); DO_DISS("ldrh r" << dec << rd << ",[r" << dec << rn << ",#0x" << Base::HEX2 << rb << "]\n");
rb = read_register(rn) + rb; rb = read_register(rn) + rb;
uInt16 val16; uInt16 val16 = 0;
const err_t err = read16(rb, val16); const err_t err = read16(rb, val16);
if (err) return err; if (err) return err;
@ -1529,7 +1558,7 @@ CortexM0::err_t CortexM0::execute(uInt16 inst, uInt8 op)
DO_DISS("ldrh r" << dec << rd << ",[r" << dec << rn << ",r" << dec << rm << "]\n"); DO_DISS("ldrh r" << dec << rd << ",[r" << dec << rn << ",r" << dec << rm << "]\n");
rb = read_register(rn) + read_register(rm); rb = read_register(rn) + read_register(rm);
uInt16 val16; uInt16 val16 = 0;
const err_t err = read16(rb, val16); const err_t err = read16(rb, val16);
if (err) return err; if (err) return err;
@ -1547,7 +1576,7 @@ CortexM0::err_t CortexM0::execute(uInt16 inst, uInt8 op)
DO_DISS("ldrsb r" << dec << rd << ",[r" << dec << rn << ",r" << dec << rm << "]\n"); DO_DISS("ldrsb r" << dec << rd << ",[r" << dec << rn << ",r" << dec << rm << "]\n");
rb = read_register(rn) + read_register(rm); rb = read_register(rn) + read_register(rm);
uInt8 val8; uInt8 val8 = 0;
const err_t err = read8(rb, val8); const err_t err = read8(rb, val8);
if (err) return err; if (err) return err;
@ -1565,7 +1594,7 @@ CortexM0::err_t CortexM0::execute(uInt16 inst, uInt8 op)
DO_DISS("ldrsh r" << dec << rd << ",[r" << dec << rn << ",r" << dec << rm << "]\n"); DO_DISS("ldrsh r" << dec << rd << ",[r" << dec << rn << ",r" << dec << rm << "]\n");
rb = read_register(rn) + read_register(rm); rb = read_register(rn) + read_register(rm);
uInt16 val16; uInt16 val16 = 0;
const err_t err = read16(rb, val16); const err_t err = read16(rb, val16);
if (err) return err; if (err) return err;
@ -1806,14 +1835,14 @@ CortexM0::err_t CortexM0::execute(uInt16 inst, uInt8 op)
} }
#endif #endif
std::array<uInt32, 16> regOld = reg_norm; const std::array<uInt32, 16> regOld = reg_norm;
sp = read_register(13); sp = read_register(13);
for(ra = 0, rb = 0x01; rb; rb = (rb << 1) & 0xFF, ++ra) for(ra = 0, rb = 0x01; rb; rb = (rb << 1) & 0xFF, ++ra)
{ {
if(inst & rb) if(inst & rb)
{ {
err_t err = read32(sp, reg_norm[ra]); const err_t err = read32(sp, reg_norm[ra]);
if (err) { if (err) {
reg_norm = regOld; reg_norm = regOld;
return err; return err;
@ -1825,7 +1854,7 @@ CortexM0::err_t CortexM0::execute(uInt16 inst, uInt8 op)
if(inst & 0x100) if(inst & 0x100)
{ {
err_t err = read32(sp, rc); const err_t err = read32(sp, rc);
if (err) { if (err) {
reg_norm = regOld; reg_norm = regOld;
return err; return err;
@ -2029,7 +2058,7 @@ CortexM0::err_t CortexM0::execute(uInt16 inst, uInt8 op)
{ {
if(inst & rb) if(inst & rb)
{ {
err_t err = write32(sp, read_register(ra)); const err_t err = write32(sp, read_register(ra));
if (err) return err; if (err) return err;
sp += 4; sp += 4;
@ -2049,7 +2078,7 @@ CortexM0::err_t CortexM0::execute(uInt16 inst, uInt8 op)
rb = read_register(rn) + rb; rb = read_register(rn) + rb;
rc = read_register(rd); rc = read_register(rd);
err_t err = write32(rb, rc); const err_t err = write32(rb, rc);
if (err) return err; if (err) return err;
return ERR_NONE; return ERR_NONE;
@ -2064,7 +2093,7 @@ CortexM0::err_t CortexM0::execute(uInt16 inst, uInt8 op)
rb = read_register(rn) + read_register(rm); rb = read_register(rn) + read_register(rm);
rc = read_register(rd); rc = read_register(rd);
err_t err = write32(rb, rc); const err_t err = write32(rb, rc);
if (err) return err; if (err) return err;
return ERR_NONE; return ERR_NONE;
@ -2080,7 +2109,7 @@ CortexM0::err_t CortexM0::execute(uInt16 inst, uInt8 op)
//fprintf(stderr,"0x%08X\n",rb); //fprintf(stderr,"0x%08X\n",rb);
rc = read_register(rd); rc = read_register(rd);
err_t err = write32(rb, rc); const err_t err = write32(rb, rc);
if (err) return err; if (err) return err;
return ERR_NONE; return ERR_NONE;
@ -2095,7 +2124,7 @@ CortexM0::err_t CortexM0::execute(uInt16 inst, uInt8 op)
rb = read_register(rn) + rb; rb = read_register(rn) + rb;
rc = read_register(rd); rc = read_register(rd);
err_t err = write8(rb, rc); const err_t err = write8(rb, rc);
if (err) return err; if (err) return err;
return ERR_NONE; return ERR_NONE;
@ -2110,7 +2139,7 @@ CortexM0::err_t CortexM0::execute(uInt16 inst, uInt8 op)
rb = read_register(rn) + read_register(rm); rb = read_register(rn) + read_register(rm);
rc = read_register(rd); rc = read_register(rd);
err_t err = write8(rb, rc); const err_t err = write8(rb, rc);
if (err) return err; if (err) return err;
return ERR_NONE; return ERR_NONE;

View File

@ -35,7 +35,6 @@ BusTransactionQueue::Transaction BusTransactionQueue::Transaction::transactionDr
return {.address = address, .value = value, .timestamp = timestamp, .yield = false}; return {.address = address, .value = value, .timestamp = timestamp, .yield = false};
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void BusTransactionQueue::Transaction::setBusState(bool& bs_drive, uInt8& bs_value) const void BusTransactionQueue::Transaction::setBusState(bool& bs_drive, uInt8& bs_value) const
{ {
@ -47,7 +46,6 @@ void BusTransactionQueue::Transaction::setBusState(bool& bs_drive, uInt8& bs_val
} }
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
BusTransactionQueue::BusTransactionQueue(size_t capacity) : myQueueCapacity(capacity) BusTransactionQueue::BusTransactionQueue(size_t capacity) : myQueueCapacity(capacity)
{ {
@ -73,11 +71,13 @@ BusTransactionQueue& BusTransactionQueue::setNextInjectAddress(uInt16 address)
return *this; return *this;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt16 BusTransactionQueue::getNextInjectAddress() const uInt16 BusTransactionQueue::getNextInjectAddress() const
{ {
return myNextInjectAddress; return myNextInjectAddress;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
BusTransactionQueue& BusTransactionQueue::setTimestamp(uInt64 timestamp) BusTransactionQueue& BusTransactionQueue::setTimestamp(uInt64 timestamp)
{ {
myTimestamp = timestamp; myTimestamp = timestamp;
@ -102,6 +102,7 @@ BusTransactionQueue& BusTransactionQueue::injectROMAt(uInt8 value, uInt16 addres
return *this; return *this;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
BusTransactionQueue& BusTransactionQueue::stuffByte(uInt8 value, uInt16 address) BusTransactionQueue& BusTransactionQueue::stuffByte(uInt8 value, uInt16 address)
{ {
push(Transaction::transactionDrive(address, value, myTimestamp)); push(Transaction::transactionDrive(address, value, myTimestamp));

View File

@ -1,5 +1,23 @@
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-2024 by Bradford W. Mott, Stephen Anthony
// and the Stella Team
//
// See the file "License.txt" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//============================================================================
#include "ElfEnvironment.hxx" #include "ElfEnvironment.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const uInt8 elfEnvironment::OVERBLANK_PROGRAM[] = { const uInt8 elfEnvironment::OVERBLANK_PROGRAM[] = {
0xa0,0x00, // ldy #0 0xa0,0x00, // ldy #0
0xa5,0xe0, // lda $e0 0xa5,0xe0, // lda $e0
@ -34,8 +52,10 @@ const uInt8 elfEnvironment::OVERBLANK_PROGRAM[] = {
0x4c, 0x00, 0x10 // jmp $1000 0x4c, 0x00, 0x10 // jmp $1000
}; };
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const uInt32 elfEnvironment::OVERBLANK_PROGRAM_SIZE = sizeof(elfEnvironment::OVERBLANK_PROGRAM); const uInt32 elfEnvironment::OVERBLANK_PROGRAM_SIZE = sizeof(elfEnvironment::OVERBLANK_PROGRAM);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const uInt8 elfEnvironment::LOOKUP_TABLES[3 * 256] = { const uInt8 elfEnvironment::LOOKUP_TABLES[3 * 256] = {
// Ntsc2600 // Ntsc2600
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F, 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,
@ -92,6 +112,7 @@ const uInt8 elfEnvironment::LOOKUP_TABLES[3 * 256] = {
0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff
}; };
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
vector<ElfLinker::ExternalSymbol> elfEnvironment::externalSymbols(elfEnvironment::Palette palette) vector<ElfLinker::ExternalSymbol> elfEnvironment::externalSymbols(elfEnvironment::Palette palette)
{ {
static const vector<ElfLinker::ExternalSymbol> EXTERNAL_SYMBOLS_STATIC = { static const vector<ElfLinker::ExternalSymbol> EXTERNAL_SYMBOLS_STATIC = {

View File

@ -17,6 +17,7 @@
#include "ElfUtil.hxx" #include "ElfUtil.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Int32 elfUtil::decode_B_BL(uInt32 opcode) Int32 elfUtil::decode_B_BL(uInt32 opcode)
{ {
// nomenclature follows Thumb32 BL / B.W encoding in Arm Architecture Reference // nomenclature follows Thumb32 BL / B.W encoding in Arm Architecture Reference
@ -38,6 +39,7 @@ Int32 elfUtil::decode_B_BL(uInt32 opcode)
return offset; return offset;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt32 elfUtil::encode_B_BL(Int32 offset, bool link) uInt32 elfUtil::encode_B_BL(Int32 offset, bool link)
{ {
// nomenclature follows Thumb32 BL / B.W encoding in Arm Architecture Reference // nomenclature follows Thumb32 BL / B.W encoding in Arm Architecture Reference

View File

@ -22,7 +22,6 @@
#include "BusTransactionQueue.hxx" #include "BusTransactionQueue.hxx"
#include "ElfEnvironment.hxx" #include "ElfEnvironment.hxx"
#include "exception/FatalEmulationError.hxx" #include "exception/FatalEmulationError.hxx"
#include "ElfEnvironment.hxx"
using namespace elfEnvironment; using namespace elfEnvironment;
@ -31,7 +30,7 @@ namespace {
{ {
const uInt16 value16 = value | (value << 8); const uInt16 value16 = value | (value << 8);
const uInt32 value32 = value16 | (value16 << 16); const uInt32 value32 = value16 | (value16 << 16);
CortexM0::err_t err; CortexM0::err_t err = CortexM0::ERR_NONE;
uInt32 ptr = target; uInt32 ptr = target;
while (ptr < target + size) { while (ptr < target + size) {
@ -57,12 +56,12 @@ namespace {
CortexM0::err_t memcpy(uInt32 dest, uInt32 src, uInt32 size, CortexM0& cortex) CortexM0::err_t memcpy(uInt32 dest, uInt32 src, uInt32 size, CortexM0& cortex)
{ {
CortexM0::err_t err; CortexM0::err_t err = CortexM0::ERR_NONE;
const uInt32 destOrig = dest; const uInt32 destOrig = dest;
while (size > 0) { while (size > 0) {
if (((dest | src) & 0x03) == 0 && size >= 4) { if (((dest | src) & 0x03) == 0 && size >= 4) {
uInt32 value; uInt32 value = 0;
err = cortex.read32(src, value); err = cortex.read32(src, value);
if (err) return err; if (err) return err;
@ -74,7 +73,7 @@ namespace {
src += 4; src += 4;
} }
else if (((dest | src) & 0x01) == 0 && size >= 2) { else if (((dest | src) & 0x01) == 0 && size >= 2) {
uInt16 value; uInt16 value = 0;
err = cortex.read16(src, value); err = cortex.read16(src, value);
if (err) return err; if (err) return err;
@ -86,7 +85,7 @@ namespace {
src += 2; src += 2;
} }
else { else {
uInt8 value; uInt8 value = 0;
err = cortex.read8(src, value); err = cortex.read8(src, value);
if (err) return err; if (err) return err;
@ -104,7 +103,7 @@ namespace {
cortex.setRegister(0, destOrig); cortex.setRegister(0, destOrig);
return 0; return 0;
} }
} } // namespace
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
VcsLib::VcsLib(BusTransactionQueue& transactionQueue) : myTransactionQueue(transactionQueue) VcsLib::VcsLib(BusTransactionQueue& transactionQueue) : myTransactionQueue(transactionQueue)
@ -177,8 +176,8 @@ void VcsLib::vcsLda2(uInt8 value)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CortexM0::err_t VcsLib::fetch16(uInt32 address, uInt16& value, uInt8& op, CortexM0& cortex) CortexM0::err_t VcsLib::fetch16(uInt32 address, uInt16& value, uInt8& op, CortexM0& cortex)
{ {
uInt32 arg; uInt32 arg = 0;
CortexM0::err_t err; CortexM0::err_t err = CortexM0::ERR_NONE;
if (myTransactionQueue.size() >= elfEnvironment::QUEUE_SIZE_LIMIT) if (myTransactionQueue.size() >= elfEnvironment::QUEUE_SIZE_LIMIT)
return CortexM0::errCustom(ERR_STOP_EXECUTION); return CortexM0::errCustom(ERR_STOP_EXECUTION);
@ -405,14 +404,3 @@ CortexM0::err_t VcsLib::fetch16(uInt32 address, uInt16& value, uInt8& op, Cortex
return CortexM0::errIntrinsic(CortexM0::ERR_UNMAPPED_FETCH16, address); return CortexM0::errIntrinsic(CortexM0::ERR_UNMAPPED_FETCH16, address);
} }
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CortexM0::err_t VcsLib::returnFromStub(uInt16& value, uInt8& op)
{
constexpr uInt16 BX_LR = 0x4770;
value = BX_LR;
op = CortexM0::decodeInstructionWord(BX_LR);
return CortexM0::ERR_NONE;
}

View File

@ -48,7 +48,14 @@ class VcsLib: public CortexM0::BusTransactionDelegate {
void vcsLda2(uInt8 value); void vcsLda2(uInt8 value);
private: private:
CortexM0::err_t returnFromStub(uInt16& value, uInt8& op); static CortexM0::err_t returnFromStub(uInt16& value, uInt8& op) {
constexpr uInt16 BX_LR = 0x4770;
value = BX_LR;
op = CortexM0::decodeInstructionWord(BX_LR);
return CortexM0::ERR_NONE;
}
private: private:
BusTransactionQueue& myTransactionQueue; BusTransactionQueue& myTransactionQueue;