Skip to content

Commit

Permalink
Move all core types into namespaces (melonDS-emu#1886)
Browse files Browse the repository at this point in the history
* Reorganize namespaces

- Most types are now moved into the `melonDS` namespace
- Only good chance to do this for a while, since a big refactor is next

* Fix the build
  • Loading branch information
JesseTG authored Nov 25, 2023
1 parent 651b0f6 commit 346dd40
Show file tree
Hide file tree
Showing 178 changed files with 528 additions and 267 deletions.
4 changes: 4 additions & 0 deletions src/ARCodeFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "ARCodeFile.h"
#include "Platform.h"

namespace melonDS
{
using namespace Platform;

// TODO: import codes from other sources (usrcheat.dat, ...)
Expand Down Expand Up @@ -182,3 +184,5 @@ bool ARCodeFile::Save()
CloseFile(f);
return true;
}

}
3 changes: 3 additions & 0 deletions src/ARCodeFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <vector>
#include "types.h"

namespace melonDS
{
struct ARCode
{
std::string Name;
Expand Down Expand Up @@ -59,4 +61,5 @@ class ARCodeFile
std::string Filename;
};

}
#endif // ARCODEFILE_H
4 changes: 4 additions & 0 deletions src/AREngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#include "AREngine.h"
#include "Platform.h"

namespace melonDS
{

using Platform::Log;
using Platform::LogLevel;

Expand Down Expand Up @@ -429,3 +432,4 @@ void AREngine::RunCheats()
}
}
}
}
3 changes: 3 additions & 0 deletions src/AREngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include "ARCodeFile.h"

namespace melonDS
{
class AREngine
{
public:
Expand All @@ -45,4 +47,5 @@ class AREngine
void (*BusWrite32)(u32 addr, u32 val);
};

}
#endif // ARENGINE_H
13 changes: 8 additions & 5 deletions src/ARM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "GPU.h"
#include "ARMJIT_Memory.h"

namespace melonDS
{
using Platform::Log;
using Platform::LogLevel;

Expand Down Expand Up @@ -104,7 +106,7 @@ const u32 ARM::ConditionTable[16] =
0x0000 // NE
};

ARM::ARM(u32 num, ARMJIT::ARMJIT& jit, Melon::GPU& gpu) :
ARM::ARM(u32 num, ARMJIT& jit, melonDS::GPU& gpu) :
#ifdef GDBSTUB_ENABLED
GdbStub(this, Platform::GetConfigInt(num ? Platform::GdbPortARM7 : Platform::GdbPortARM9)),
#endif
Expand All @@ -128,14 +130,14 @@ ARM::~ARM()
// dorp
}

ARMv5::ARMv5(ARMJIT::ARMJIT& jit, Melon::GPU& gpu) : ARM(0, jit, gpu)
ARMv5::ARMv5(ARMJIT& jit, melonDS::GPU& gpu) : ARM(0, jit, gpu)
{
DTCM = JIT.Memory.GetARM9DTCM();

PU_Map = PU_PrivMap;
}

ARMv4::ARMv4(ARMJIT::ARMJIT& jit, Melon::GPU& gpu) : ARM(1, jit, gpu)
ARMv4::ARMv4(ARMJIT& jit, melonDS::GPU& gpu) : ARM(1, jit, gpu)
{
//
}
Expand Down Expand Up @@ -749,7 +751,7 @@ void ARMv5::ExecuteJIT()
return;
}

ARMJIT::JitBlockEntry block = JIT.LookUpBlock(0, FastBlockLookup,
JitBlockEntry block = JIT.LookUpBlock(0, FastBlockLookup,
instrAddr - FastBlockLookupStart, instrAddr);
if (block)
ARM_Dispatch(this, block);
Expand Down Expand Up @@ -906,7 +908,7 @@ void ARMv4::ExecuteJIT()
return;
}

ARMJIT::JitBlockEntry block = JIT.LookUpBlock(1, FastBlockLookup,
JitBlockEntry block = JIT.LookUpBlock(1, FastBlockLookup,
instrAddr - FastBlockLookupStart, instrAddr);
if (block)
ARM_Dispatch(this, block);
Expand Down Expand Up @@ -1191,5 +1193,6 @@ u32 ARMv5::ReadMem(u32 addr, int size)

return ARM::ReadMem(addr, size);
}
}
#endif

21 changes: 9 additions & 12 deletions src/ARM.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "debug/GdbStub.h"
#endif

namespace melonDS
{
inline u32 ROR(u32 x, u32 n)
{
return (x >> (n&0x1F)) | (x << ((32-n)&0x1F));
Expand All @@ -42,15 +44,9 @@ enum
const u32 ITCMPhysicalSize = 0x8000;
const u32 DTCMPhysicalSize = 0x4000;

namespace ARMJIT
{

class ARMJIT;
}
namespace Melon
{
class GPU;
}

class ARMJIT_Memory;

class ARM
Expand All @@ -59,7 +55,7 @@ class ARM
#endif
{
public:
ARM(u32 num, ARMJIT::ARMJIT& jit, Melon::GPU& gpu);
ARM(u32 num, ARMJIT& jit, GPU& gpu);
virtual ~ARM(); // destroy shit

virtual void Reset();
Expand Down Expand Up @@ -190,7 +186,7 @@ class ARM
Gdb::GdbStub GdbStub;
#endif

ARMJIT::ARMJIT& JIT;
ARMJIT& JIT;
protected:
u8 (*BusRead8)(u32 addr);
u16 (*BusRead16)(u32 addr);
Expand Down Expand Up @@ -222,13 +218,13 @@ class ARM
void GdbCheckB();
void GdbCheckC();
private:
Melon::GPU& GPU;
melonDS::GPU& GPU;
};

class ARMv5 : public ARM
{
public:
ARMv5(ARMJIT::ARMJIT& jit, Melon::GPU& gpu);
ARMv5(ARMJIT& jit, melonDS::GPU& gpu);
~ARMv5();

void Reset() override;
Expand Down Expand Up @@ -372,7 +368,7 @@ class ARMv5 : public ARM
class ARMv4 : public ARM
{
public:
ARMv4(ARMJIT::ARMJIT& jit, Melon::GPU& gpu);
ARMv4(ARMJIT& jit, melonDS::GPU& gpu);

void Reset() override;

Expand Down Expand Up @@ -541,4 +537,5 @@ extern ARMv4* ARM7;

}

}
#endif // ARM_H
7 changes: 3 additions & 4 deletions src/ARMInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@
#include "ARMInterpreter_LoadStore.h"
#include "Platform.h"

using Platform::Log;
using Platform::LogLevel;

#ifdef GDBSTUB_ENABLED
#include "debug/GdbStub.h"
#endif

namespace ARMInterpreter
namespace melonDS::ARMInterpreter
{
using Platform::Log;
using Platform::LogLevel;


void A_UNK(ARM* cpu)
Expand Down
3 changes: 3 additions & 0 deletions src/ARMInterpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include "types.h"
#include "ARM.h"

namespace melonDS
{
namespace ARMInterpreter
{

Expand All @@ -41,4 +43,5 @@ void A_BLX_IMM(ARM* cpu); // I'm a special one look at me

}

}
#endif // ARMINTERPRETER_H
2 changes: 1 addition & 1 deletion src/ARMInterpreter_ALU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <stdio.h>
#include "ARM.h"

namespace ARMInterpreter
namespace melonDS::ARMInterpreter
{

inline bool CarryAdd(u32 a, u32 b)
Expand Down
3 changes: 3 additions & 0 deletions src/ARMInterpreter_ALU.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#ifndef ARMINTERPRETER_ALU_H
#define ARMINTERPRETER_ALU_H

namespace melonDS
{
namespace ARMInterpreter
{

Expand Down Expand Up @@ -134,4 +136,5 @@ void T_ADD_SP(ARM* cpu);

}

}
#endif
5 changes: 2 additions & 3 deletions src/ARMInterpreter_Branch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
#include "ARM.h"
#include "Platform.h"

namespace melonDS::ARMInterpreter
{
using Platform::Log;
using Platform::LogLevel;

namespace ARMInterpreter
{


void A_B(ARM* cpu)
{
Expand Down
3 changes: 3 additions & 0 deletions src/ARMInterpreter_Branch.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#ifndef ARMINTERPRETER_BRANCH_H
#define ARMINTERPRETER_BRANCH_H

namespace melonDS
{
namespace ARMInterpreter
{

Expand All @@ -36,4 +38,5 @@ void T_BL_LONG_2(ARM* cpu);

}

}
#endif
2 changes: 1 addition & 1 deletion src/ARMInterpreter_LoadStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "ARM.h"


namespace ARMInterpreter
namespace melonDS::ARMInterpreter
{


Expand Down
2 changes: 1 addition & 1 deletion src/ARMInterpreter_LoadStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#ifndef ARMINTERPRETER_LOADSTORE_H
#define ARMINTERPRETER_LOADSTORE_H

namespace ARMInterpreter
namespace melonDS::ARMInterpreter
{

#define A_PROTO_WB_LDRSTR(x) \
Expand Down
34 changes: 17 additions & 17 deletions src/ARMJIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@
#include "Wifi.h"
#include "NDSCart.h"
#include "Platform.h"
#include "ARMJIT_x64/ARMJIT_Offsets.h"

namespace melonDS
{
using Platform::Log;
using Platform::LogLevel;

#include "ARMJIT_x64/ARMJIT_Offsets.h"
static_assert(offsetof(ARM, CPSR) == ARM_CPSR_offset, "");
static_assert(offsetof(ARM, Cycles) == ARM_Cycles_offset, "");
static_assert(offsetof(ARM, StopExecution) == ARM_StopExecution_offset, "");

namespace ARMJIT
{

#define JIT_DEBUGPRINT(msg, ...)
//#define JIT_DEBUGPRINT(msg, ...) Platform::Log(Platform::LogLevel::Debug, msg, ## __VA_ARGS__)
Expand Down Expand Up @@ -1056,20 +1056,20 @@ bool ARMJIT::SetupExecutableRegion(u32 num, u32 blockAddr, u64*& entry, u32& sta
return false;
}

template void ARMJIT::CheckAndInvalidate<0, ARMJIT_Memory::memregion_MainRAM>(u32);
template void ARMJIT::CheckAndInvalidate<1, ARMJIT_Memory::memregion_MainRAM>(u32);
template void ARMJIT::CheckAndInvalidate<0, ARMJIT_Memory::memregion_SharedWRAM>(u32);
template void ARMJIT::CheckAndInvalidate<1, ARMJIT_Memory::memregion_SharedWRAM>(u32);
template void ARMJIT::CheckAndInvalidate<1, ARMJIT_Memory::memregion_WRAM7>(u32);
template void ARMJIT::CheckAndInvalidate<1, ARMJIT_Memory::memregion_VWRAM>(u32);
template void ARMJIT::CheckAndInvalidate<0, ARMJIT_Memory::memregion_VRAM>(u32);
template void ARMJIT::CheckAndInvalidate<0, ARMJIT_Memory::memregion_ITCM>(u32);
template void ARMJIT::CheckAndInvalidate<0, ARMJIT_Memory::memregion_NewSharedWRAM_A>(u32);
template void ARMJIT::CheckAndInvalidate<1, ARMJIT_Memory::memregion_NewSharedWRAM_A>(u32);
template void ARMJIT::CheckAndInvalidate<0, ARMJIT_Memory::memregion_NewSharedWRAM_B>(u32);
template void ARMJIT::CheckAndInvalidate<1, ARMJIT_Memory::memregion_NewSharedWRAM_B>(u32);
template void ARMJIT::CheckAndInvalidate<0, ARMJIT_Memory::memregion_NewSharedWRAM_C>(u32);
template void ARMJIT::CheckAndInvalidate<1, ARMJIT_Memory::memregion_NewSharedWRAM_C>(u32);
template void ARMJIT::CheckAndInvalidate<0, ARMJIT_Memory::memregion_MainRAM>(u32) noexcept;
template void ARMJIT::CheckAndInvalidate<1, ARMJIT_Memory::memregion_MainRAM>(u32) noexcept;
template void ARMJIT::CheckAndInvalidate<0, ARMJIT_Memory::memregion_SharedWRAM>(u32) noexcept;
template void ARMJIT::CheckAndInvalidate<1, ARMJIT_Memory::memregion_SharedWRAM>(u32) noexcept;
template void ARMJIT::CheckAndInvalidate<1, ARMJIT_Memory::memregion_WRAM7>(u32) noexcept;
template void ARMJIT::CheckAndInvalidate<1, ARMJIT_Memory::memregion_VWRAM>(u32) noexcept;
template void ARMJIT::CheckAndInvalidate<0, ARMJIT_Memory::memregion_VRAM>(u32) noexcept;
template void ARMJIT::CheckAndInvalidate<0, ARMJIT_Memory::memregion_ITCM>(u32) noexcept;
template void ARMJIT::CheckAndInvalidate<0, ARMJIT_Memory::memregion_NewSharedWRAM_A>(u32) noexcept;
template void ARMJIT::CheckAndInvalidate<1, ARMJIT_Memory::memregion_NewSharedWRAM_A>(u32) noexcept;
template void ARMJIT::CheckAndInvalidate<0, ARMJIT_Memory::memregion_NewSharedWRAM_B>(u32) noexcept;
template void ARMJIT::CheckAndInvalidate<1, ARMJIT_Memory::memregion_NewSharedWRAM_B>(u32) noexcept;
template void ARMJIT::CheckAndInvalidate<0, ARMJIT_Memory::memregion_NewSharedWRAM_C>(u32) noexcept;
template void ARMJIT::CheckAndInvalidate<1, ARMJIT_Memory::memregion_NewSharedWRAM_C>(u32) noexcept;

void ARMJIT::ResetBlockCache() noexcept
{
Expand Down
8 changes: 4 additions & 4 deletions src/ARMJIT.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@

#include "ARMJIT_Compiler.h"

namespace melonDS
{
class ARM;

namespace ARMJIT
{
class JitBlock;
class ARMJIT
{
Expand Down Expand Up @@ -74,7 +74,7 @@ class ARMJIT

TinyVector<u32> InvalidLiterals {};
private:
friend class ::ARMJIT_Memory;
friend class ARMJIT_Memory;
void blockSanityCheck(u32 num, u32 blockAddr, JitBlockEntry entry) noexcept;
void RetireJitBlock(JitBlock* block) noexcept;

Expand Down Expand Up @@ -160,6 +160,6 @@ class ARMJIT
}

// Defined in assembly
extern "C" void ARM_Dispatch(ARM* cpu, ARMJIT::JitBlockEntry entry);
extern "C" void ARM_Dispatch(melonDS::ARM* cpu, melonDS::JitBlockEntry entry);

#endif
Loading

0 comments on commit 346dd40

Please sign in to comment.