Skip to content

Commit

Permalink
Sprinkle const around where appropriate (#1909)
Browse files Browse the repository at this point in the history
* Sprinkle `const` around where appropriate

- This will make it easier to use `NDS` objects in `const` contexts (e.g. `const` parameters or methods)

* Remove the `const` qualifier on `DSi_DSP::DSPRead16`

- MMIO reads can be non-pure, so this may not be `const` in the future
  • Loading branch information
JesseTG authored Dec 12, 2023
1 parent 2cba2e7 commit 9bfc9c0
Show file tree
Hide file tree
Showing 57 changed files with 253 additions and 243 deletions.
6 changes: 3 additions & 3 deletions src/AREngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ AREngine::AREngine(melonDS::NDS& nds) : NDS(nds)
case ((x)+0x08): case ((x)+0x09): case ((x)+0x0A): case ((x)+0x0B): \
case ((x)+0x0C): case ((x)+0x0D): case ((x)+0x0E): case ((x)+0x0F)

void AREngine::RunCheat(ARCode& arcode)
void AREngine::RunCheat(const ARCode& arcode)
{
u32* code = &arcode.Code[0];
const u32* code = &arcode.Code[0];

u32 offset = 0;
u32 datareg = 0;
u32 cond = 1;
u32 condstack = 0;

u32* loopstart = code;
const u32* loopstart = code;
u32 loopcount = 0;
u32 loopcond = 1;
u32 loopcondstack = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/AREngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AREngine
void SetCodeFile(ARCodeFile* file) { CodeFile = file; }

void RunCheats();
void RunCheat(ARCode& arcode);
void RunCheat(const ARCode& arcode);
private:
melonDS::NDS& NDS;
ARCodeFile* CodeFile; // AR code file - frontend is responsible for managing this
Expand Down
6 changes: 3 additions & 3 deletions src/ARM.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class ARM
virtual void ExecuteJIT() = 0;
#endif

bool CheckCondition(u32 code)
bool CheckCondition(u32 code) const
{
if (code == 0xE) return true;
if (ConditionTable[code] & (1 << (CPSR>>28))) return true;
Expand Down Expand Up @@ -109,7 +109,7 @@ class ARM
if (v) CPSR |= 0x10000000;
}

inline bool ModeIs(u32 mode)
inline bool ModeIs(u32 mode) const
{
u32 cm = CPSR & 0x1f;
mode &= 0x1f;
Expand Down Expand Up @@ -315,7 +315,7 @@ class ARMv5 : public ARM
void ICacheInvalidateAll();

void CP15Write(u32 id, u32 val);
u32 CP15Read(u32 id);
u32 CP15Read(u32 id) const;

u32 CP15Control;

Expand Down
4 changes: 2 additions & 2 deletions src/ARMJIT_A64/ARMJIT_Compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class Compiler : public Arm64Gen::ARM64XEmitter

bool CanCompile(bool thumb, u16 kind);

bool FlagsNZNeeded()
bool FlagsNZNeeded() const
{
return CurInstr.SetFlags & 0xC;
}
Expand Down Expand Up @@ -234,7 +234,7 @@ class Compiler : public Arm64Gen::ARM64XEmitter
return (u8*)entry - GetRXBase();
}

bool IsJITFault(u8* pc);
bool IsJITFault(const u8* pc);
u8* RewriteMemAccess(u8* pc);

void SwapCodeRegion()
Expand Down
2 changes: 1 addition & 1 deletion src/ARMJIT_A64/ARMJIT_LoadStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ using namespace Arm64Gen;
namespace melonDS
{

bool Compiler::IsJITFault(u8* pc)
bool Compiler::IsJITFault(const u8* pc)
{
return (u64)pc >= (u64)GetRXBase() && (u64)pc - (u64)GetRXBase() < (JitMemMainSize + JitMemSecondarySize);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ARMJIT_Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ typedef void (*InterpreterFunc)(ARM* cpu);
extern InterpreterFunc InterpretARM[];
extern InterpreterFunc InterpretTHUMB[];

inline bool PageContainsCode(AddressRange* range)
inline bool PageContainsCode(const AddressRange* range)
{
for (int i = 0; i < 8; i++)
{
Expand Down
2 changes: 1 addition & 1 deletion src/ARMJIT_RegisterCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class RegisterCache
LiteralsLoaded &= ~(1 << reg);
}

bool IsLiteral(int reg)
bool IsLiteral(int reg) const
{
return LiteralsLoaded & (1 << reg);
}
Expand Down
4 changes: 2 additions & 2 deletions src/ARMJIT_x64/ARMJIT_Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ const Compiler::CompileFunc T_Comp[ARMInstrInfo::tk_Count] = {
};
#undef F

bool Compiler::CanCompile(bool thumb, u16 kind)
bool Compiler::CanCompile(bool thumb, u16 kind) const
{
return (thumb ? T_Comp[kind] : A_Comp[kind]) != NULL;
}
Expand All @@ -667,7 +667,7 @@ void Compiler::Reset()
LoadStorePatches.clear();
}

bool Compiler::IsJITFault(u8* addr)
bool Compiler::IsJITFault(const u8* addr)
{
return (u64)addr >= (u64)ResetStart && (u64)addr < (u64)ResetStart + CodeMemSize;
}
Expand Down
4 changes: 2 additions & 2 deletions src/ARMJIT_x64/ARMJIT_Compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class Compiler : public Gen::XEmitter
void LoadReg(int reg, Gen::X64Reg nativeReg);
void SaveReg(int reg, Gen::X64Reg nativeReg);

bool CanCompile(bool thumb, u16 kind);
bool CanCompile(bool thumb, u16 kind) const;

typedef void (Compiler::*CompileFunc)();

Expand Down Expand Up @@ -234,7 +234,7 @@ class Compiler : public Gen::XEmitter
SetCodePtr(FarCode);
}

bool IsJITFault(u8* addr);
bool IsJITFault(const u8* addr);

u8* RewriteMemAccess(u8* pc);

Expand Down
2 changes: 1 addition & 1 deletion src/CP15.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ void ARMv5::CP15Write(u32 id, u32 val)
Log(LogLevel::Debug, "unknown CP15 write op %03X %08X\n", id, val);
}

u32 ARMv5::CP15Read(u32 id)
u32 ARMv5::CP15Read(u32 id) const
{
//printf("CP15 read op %03X %08X\n", id, NDS::ARM9->R[15]);

Expand Down
12 changes: 6 additions & 6 deletions src/DSi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ std::unique_ptr<NDSCart::CartCommon> DSi::EjectCart()
return oldcart;
}

void DSi::CamInputFrame(int cam, u32* data, int width, int height, bool rgb)
void DSi::CamInputFrame(int cam, const u32* data, int width, int height, bool rgb)
{
switch (cam)
{
Expand Down Expand Up @@ -277,7 +277,7 @@ void DSi::SetCartInserted(bool inserted)
SCFG_MC |= 1;
}

void DSi::DecryptModcryptArea(u32 offset, u32 size, u8* iv)
void DSi::DecryptModcryptArea(u32 offset, u32 size, const u8* iv)
{
AES_ctx ctx;
u8 key[16];
Expand Down Expand Up @@ -957,21 +957,21 @@ void DSi::StallNDMAs()
}


bool DSi::DMAsInMode(u32 cpu, u32 mode)
bool DSi::DMAsInMode(u32 cpu, u32 mode) const
{
if (NDS::DMAsInMode(cpu, mode)) return true;

return NDMAsInMode(cpu, NDMAModes[mode]);
}

bool DSi::DMAsRunning(u32 cpu)
bool DSi::DMAsRunning(u32 cpu) const
{
if (NDS::DMAsRunning(cpu)) return true;

return NDMAsRunning(cpu);
}

bool DSi::NDMAsInMode(u32 cpu, u32 mode)
bool DSi::NDMAsInMode(u32 cpu, u32 mode) const
{
cpu <<= 2;
if (NDMAs[cpu+0].IsInMode(mode)) return true;
Expand All @@ -981,7 +981,7 @@ bool DSi::NDMAsInMode(u32 cpu, u32 mode)
return false;
}

bool DSi::NDMAsRunning(u32 cpu)
bool DSi::NDMAsRunning(u32 cpu) const
{
cpu <<= 2;
if (NDMAs[cpu+0].IsRunning()) return true;
Expand Down
14 changes: 7 additions & 7 deletions src/DSi.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ class DSi final : public NDS

void RunNDMAs(u32 cpu);
void StallNDMAs();
bool NDMAsInMode(u32 cpu, u32 mode);
bool NDMAsRunning(u32 cpu);
bool NDMAsInMode(u32 cpu, u32 mode) const;
bool NDMAsRunning(u32 cpu) const;
void CheckNDMAs(u32 cpu, u32 mode);
void StopNDMAs(u32 cpu, u32 mode);

Expand Down Expand Up @@ -138,7 +138,7 @@ class DSi final : public NDS
DSi& operator=(DSi&&) = delete;
void SetNDSCart(std::unique_ptr<NDSCart::CartCommon>&& cart) override;
std::unique_ptr<NDSCart::CartCommon> EjectCart() override;
bool NeedsDirectBoot() override
bool NeedsDirectBoot() const override
{
// for now, DSi mode requires original BIOS/NAND
return false;
Expand All @@ -153,9 +153,9 @@ class DSi final : public NDS
void SetSDCard(FATStorage&& sdcard) noexcept { SDMMC.SetSDCard(std::move(sdcard)); }
void SetSDCard(std::optional<FATStorage>&& sdcard) noexcept { SDMMC.SetSDCard(std::move(sdcard)); }

void CamInputFrame(int cam, u32* data, int width, int height, bool rgb) override;
bool DMAsInMode(u32 cpu, u32 mode) override;
bool DMAsRunning(u32 cpu) override;
void CamInputFrame(int cam, const u32* data, int width, int height, bool rgb) override;
bool DMAsInMode(u32 cpu, u32 mode) const override;
bool DMAsRunning(u32 cpu) const override;
void StopDMAs(u32 cpu, u32 mode) override;
void CheckDMAs(u32 cpu, u32 mode) override;
u16 SCFG_Clock7;
Expand All @@ -178,7 +178,7 @@ class DSi final : public NDS
bool FullBIOSBoot;
void Set_SCFG_Clock9(u16 val);
void Set_SCFG_MC(u32 val);
void DecryptModcryptArea(u32 offset, u32 size, u8* iv);
void DecryptModcryptArea(u32 offset, u32 size, const u8* iv);
void ApplyNewRAMSize(u32 size);
};

Expand Down
2 changes: 1 addition & 1 deletion src/DSi_AES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ void DSi_AES::ProcessBlock_CTR()
}


u32 DSi_AES::ReadCnt()
u32 DSi_AES::ReadCnt() const
{
u32 ret = Cnt;

Expand Down
2 changes: 1 addition & 1 deletion src/DSi_AES.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class DSi_AES
void Reset();
void DoSavestate(Savestate* file);

u32 ReadCnt();
u32 ReadCnt() const;
void WriteCnt(u32 val);
void WriteBlkCnt(u32 val);

Expand Down
10 changes: 5 additions & 5 deletions src/DSi_Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ void DSi_Camera::Stop()
Platform::Camera_Stop(Num);
}

bool DSi_Camera::IsActivated()
bool DSi_Camera::IsActivated() const
{
if (StandbyCnt & (1<<14)) return false; // standby
if (!(MiscCnt & (1<<9))) return false; // data transfer not enabled
Expand Down Expand Up @@ -477,7 +477,7 @@ void DSi_Camera::StartTransfer()
Platform::Camera_CaptureFrame(Num, FrameBuffer, 640, 480, true);
}

bool DSi_Camera::TransferDone()
bool DSi_Camera::TransferDone() const
{
return TransferY >= FrameHeight;
}
Expand Down Expand Up @@ -590,7 +590,7 @@ void DSi_Camera::Write(u8 val, bool last)
else DataPos++;
}

u16 DSi_Camera::I2C_ReadReg(u16 addr)
u16 DSi_Camera::I2C_ReadReg(u16 addr) const
{
switch (addr)
{
Expand Down Expand Up @@ -695,7 +695,7 @@ void DSi_Camera::I2C_WriteReg(u16 addr, u16 val)
// TODO: not sure at all what is the accessible range
// or if there is any overlap in the address range

u8 DSi_Camera::MCU_Read(u16 addr)
u8 DSi_Camera::MCU_Read(u16 addr) const
{
addr &= 0x7FFF;

Expand Down Expand Up @@ -724,7 +724,7 @@ void DSi_Camera::MCU_Write(u16 addr, u8 val)
}


void DSi_Camera::InputFrame(u32* data, int width, int height, bool rgb)
void DSi_Camera::InputFrame(const u32* data, int width, int height, bool rgb)
{
// TODO: double-buffering?

Expand Down
12 changes: 7 additions & 5 deletions src/DSi_Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ class DSi_Camera : public DSi_I2CDevice

void Reset() override;
void Stop();
bool IsActivated();
bool IsActivated() const;

void StartTransfer();
bool TransferDone();
bool TransferDone() const;

// lengths in words
int TransferScanline(u32* buffer, int maxlen);
Expand All @@ -50,7 +50,7 @@ class DSi_Camera : public DSi_I2CDevice
u8 Read(bool last) override;
void Write(u8 val, bool last) override;

void InputFrame(u32* data, int width, int height, bool rgb);
void InputFrame(const u32* data, int width, int height, bool rgb);

u32 Num;

Expand All @@ -59,7 +59,7 @@ class DSi_Camera : public DSi_I2CDevice
u32 RegAddr;
u16 RegData;

u16 I2C_ReadReg(u16 addr);
u16 I2C_ReadReg(u16 addr) const;
void I2C_WriteReg(u16 addr, u16 val);

u16 PLLDiv;
Expand All @@ -72,7 +72,7 @@ class DSi_Camera : public DSi_I2CDevice
u16 MCUAddr;
u8 MCURegs[0x8000];

u8 MCU_Read(u16 addr);
u8 MCU_Read(u16 addr) const;
void MCU_Write(u16 addr, u8 val);

u16 FrameWidth, FrameHeight;
Expand All @@ -91,7 +91,9 @@ class DSi_CamModule
void Stop();
void DoSavestate(Savestate* file);

const DSi_Camera* GetOuterCamera() const { return Camera0; }
DSi_Camera* GetOuterCamera() { return Camera0; }
const DSi_Camera* GetInnerCamera() const { return Camera1; }
DSi_Camera* GetInnerCamera() { return Camera1; }

void IRQ(u32 param);
Expand Down
8 changes: 4 additions & 4 deletions src/DSi_DSP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const u32 DSi_DSP::DataMemoryOffset = 0x20000; // from Teakra memory_interface.h
// NOTE: ^ IS IN DSP WORDS, NOT IN BYTES!


u16 DSi_DSP::GetPSTS()
u16 DSi_DSP::GetPSTS() const
{
u16 r = DSP_PSTS & (1<<9); // this is the only sticky bit
//r &= ~((1<<2)|(1<<7)); // we support instant resets and wrfifo xfers
Expand Down Expand Up @@ -182,7 +182,7 @@ void DSi_DSP::Reset()
SNDExCnt = 0;
}

bool DSi_DSP::IsRstReleased()
bool DSi_DSP::IsRstReleased() const
{
return SCFG_RST;
}
Expand All @@ -193,12 +193,12 @@ void DSi_DSP::SetRstLine(bool release)
DSPTimestamp = DSi.ARM9Timestamp; // only start now!
}

inline bool DSi_DSP::IsDSPCoreEnabled()
inline bool DSi_DSP::IsDSPCoreEnabled() const
{
return (DSi.SCFG_Clock9 & (1<<1)) && SCFG_RST && (!(DSP_PCFG & (1<<0)));
}

inline bool DSi_DSP::IsDSPIOEnabled()
inline bool DSi_DSP::IsDSPIOEnabled() const
{
return (DSi.SCFG_Clock9 & (1<<1)) && SCFG_RST;
}
Expand Down
Loading

0 comments on commit 9bfc9c0

Please sign in to comment.