Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge DME 1.0.0 #57

Merged
merged 2 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 81 additions & 14 deletions Source/.clang-format
Original file line number Diff line number Diff line change
@@ -1,17 +1,84 @@
---
AlignAfterOpenBracket: 'true'
AllowAllParametersOfDeclarationOnNextLine: 'true'
AllowShortFunctionsOnASingleLine: None
AlwaysBreakBeforeMultilineStrings: 'true'
AlwaysBreakTemplateDeclarations: 'true'
BreakBeforeBraces: Allman
BreakStringLiterals: 'true'
FixNamespaceComments: 'true'
ColumnLimit: '100'
Cpp11BracedListStyle: 'true'
Language: Cpp
---
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: InlineOnly
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: false
ColumnLimit: 100
CommentPragmas: '^ (IWYU pragma:|NOLINT)'
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ForEachMacros: []
IncludeCategories:
- Regex: '^<[Ww]indows\.h>$'
Priority: 1
- Regex: '^<'
Priority: 2
- Regex: '^"'
Priority: 3
IndentCaseLabels: false
IndentWidth: 2
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
Standard: Cpp11
UseTab: Never
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Latest
TabWidth: 2
UseTab: Never

...
52 changes: 30 additions & 22 deletions Source/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
cmake_minimum_required(VERSION 3.5.0)
project(Dolphin-memory-engine CXX)

if(WIN32)
set(DolphinProcessSrc DolphinProcess/Windows/WindowsDolphinProcess.cpp)
elseif(UNIX)
set(DolphinProcessSrc DolphinProcess/Linux/LinuxDolphinProcess.cpp)
else()
set(DolphinProcessSrc DolphinProcess/Dummy/DummyDolphinProcess.cpp)
endif()

set(SRCS ${DolphinProcessSrc}
DolphinProcess/DolphinAccessor.cpp
Common/MemoryCommon.cpp
MemoryWatch/MemWatchEntry.cpp
)

set(CMAKE_INCLUE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_STANDARD 14)

add_library(dolphin-memory-engine ${SRCS})
cmake_minimum_required(VERSION 3.13)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(GCC_min_version 10)
project(dolphin-memory-engine)

if(WIN32)
set(DolphinProcessSrc DolphinProcess/Windows/WindowsDolphinProcess.cpp)
endif(WIN32)

if(UNIX AND NOT APPLE)
set(DolphinProcessSrc DolphinProcess/Linux/LinuxDolphinProcess.cpp)
endif(UNIX AND NOT APPLE)

if(APPLE)
set(DolphinProcessSrc DolphinProcess/Mac/MacDolphinProcess.cpp)
endif(APPLE)

set(SRCS ${DolphinProcessSrc}
DolphinProcess/DolphinAccessor.cpp
Common/MemoryCommon.cpp
MemoryWatch/MemWatchEntry.cpp
MemoryScanner/MemoryScanner.cpp)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

add_library(dolphin-memory-engine ${SRCS})
65 changes: 37 additions & 28 deletions Source/Common/CommonUtils.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@
#include <byteswap.h>
#elif _WIN32
#include <stdlib.h>
#elif defined(__APPLE__)
#include <libkern/OSByteOrder.h>
#elif __APPLE__
#define bswap_16(value) ((((value)&0xff) << 8) | ((value) >> 8))

#define bswap_32(value) \
(((uint32_t)bswap_16((uint16_t)((value)&0xffff)) << 16) | \
(uint32_t)bswap_16((uint16_t)((value) >> 16)))

#define bswap_64(value) \
(((uint64_t)bswap_32((uint32_t)((value)&0xffffffff)) << 32) | \
(uint64_t)bswap_32((uint32_t)((value) >> 32)))
#endif

#include "CommonTypes.h"
Expand All @@ -27,7 +35,7 @@ inline u64 bSwap64(u64 data)
return _byteswap_uint64(data);
}

#elif __linux__
#else
inline u16 bSwap16(u16 data)
{
return bswap_16(data);
Expand All @@ -40,21 +48,21 @@ inline u64 bSwap64(u64 data)
{
return bswap_64(data);
}
#elif defined(__APPLE__)
inline u16 bSwap16(u16 data)
{
return OSSwapInt16(data);
}
inline u32 bSwap32(u32 data)
{
return OSSwapInt32(data);
}
inline u64 bSwap64(u64 data)
{
return OSSwapInt64(data);
}
#endif

constexpr u32 NextPowerOf2(u32 value)
{
--value;
value |= value >> 1;
value |= value >> 2;
value |= value >> 4;
value |= value >> 8;
value |= value >> 16;
++value;

return value;
};

inline u32 dolphinAddrToOffset(u32 addr, bool considerAram)
{
// ARAM address
Expand All @@ -63,14 +71,14 @@ inline u32 dolphinAddrToOffset(u32 addr, bool considerAram)
addr -= ARAM_START;
}
// MEM1 address
else if (addr >= MEM1_START && addr < MEM1_END)
else if (addr >= MEM1_START && addr < GetMEM1End())
{
addr -= MEM1_START;
if (considerAram)
addr += ARAM_FAKESIZE;
}
// MEM2 address
else if (addr >= MEM2_START && addr < MEM2_END)
else if (addr >= MEM2_START && addr < GetMEM2End())
{
addr -= MEM2_START;
addr += (MEM2_START - MEM1_START);
Expand All @@ -86,19 +94,20 @@ inline u32 offsetToDolphinAddr(u32 offset, bool considerAram)
{
offset += ARAM_START;
}
else if (offset >= ARAM_FAKESIZE && offset < ARAM_FAKESIZE + MEM1_SIZE)
else if (offset >= ARAM_FAKESIZE && offset < ARAM_FAKESIZE + GetMEM1SizeReal())
{
offset += MEM1_START;
offset -= ARAM_FAKESIZE;
}
}
else
{
if (offset < MEM1_SIZE)
if (offset < GetMEM1SizeReal())
{
offset += MEM1_START;
}
else if (offset >= MEM2_START - MEM1_START && offset < MEM2_START - MEM1_START + MEM2_SIZE)
else if (offset >= MEM2_START - MEM1_START &&
offset < MEM2_START - MEM1_START + GetMEM2SizeReal())
{
offset += MEM2_START;
offset -= (MEM2_START - MEM1_START);
Expand All @@ -111,16 +120,16 @@ inline u32 offsetToCacheIndex(u32 offset, bool considerAram)
{
if (considerAram)
{
if (offset >= ARAM_FAKESIZE && offset < MEM1_SIZE + ARAM_FAKESIZE)
if (offset >= ARAM_FAKESIZE && offset < GetMEM1SizeReal() + ARAM_FAKESIZE)
{
offset -= (ARAM_FAKESIZE - ARAM_SIZE);
}
}
else
{
if (offset >= MEM2_START - MEM1_START && offset < MEM2_START - MEM1_START + MEM2_SIZE)
if (offset >= MEM2_START - MEM1_START && offset < MEM2_START - MEM1_START + GetMEM2SizeReal())
{
offset -= (MEM2_START - MEM1_END);
offset -= (MEM2_START - GetMEM1End());
}
}
return offset;
Expand All @@ -130,18 +139,18 @@ inline u32 cacheIndexToOffset(u32 cacheIndex, bool considerAram)
{
if (considerAram)
{
if (cacheIndex >= ARAM_SIZE && cacheIndex < MEM1_SIZE + ARAM_SIZE)
if (cacheIndex >= ARAM_SIZE && cacheIndex < GetMEM1SizeReal() + ARAM_SIZE)
{
cacheIndex += (ARAM_FAKESIZE - ARAM_SIZE);
}
}
else
{
if (cacheIndex >= MEM1_SIZE && cacheIndex < MEM1_SIZE + MEM2_SIZE)
if (cacheIndex >= GetMEM1SizeReal() && cacheIndex < GetMEM1SizeReal() + GetMEM2SizeReal())
{
cacheIndex += (MEM2_START - MEM1_END);
cacheIndex += (MEM2_START - GetMEM1End());
}
}
return cacheIndex;
}
} // namespace Common
} // namespace Common
46 changes: 44 additions & 2 deletions Source/Common/MemoryCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,48 @@

namespace Common
{
static u32 s_mem1_size_real;
static u32 s_mem2_size_real;
static u32 s_mem1_size;
static u32 s_mem2_size;
static u32 s_mem1_end;
static u32 s_mem2_end;

u32 GetMEM1SizeReal()
{
return s_mem1_size_real;
}
u32 GetMEM2SizeReal()
{
return s_mem2_size_real;
}
u32 GetMEM1Size()
{
return s_mem1_size;
}
u32 GetMEM2Size()
{
return s_mem2_size;
}
u32 GetMEM1End()
{
return s_mem1_end;
}
u32 GetMEM2End()
{
return s_mem2_end;
}

void UpdateMemoryValues()
{
s_mem1_size_real = 24u * 1024 * 1024;
s_mem2_size_real = 64u * 1024 * 1024;
s_mem1_size = NextPowerOf2(GetMEM1SizeReal());
s_mem2_size = NextPowerOf2(GetMEM2SizeReal());
s_mem1_end = MEM1_START + GetMEM1SizeReal();
s_mem2_end = MEM2_START + GetMEM2SizeReal();
}

size_t getSizeForType(const MemType type, const size_t length)
{
switch (type)
Expand Down Expand Up @@ -57,7 +99,7 @@ bool shouldBeBSwappedForType(const MemType type)
}
}

int getNbrBytesAlignementForType(const MemType type)
int getNbrBytesAlignmentForType(const MemType type)
{
switch (type)
{
Expand Down Expand Up @@ -505,4 +547,4 @@ std::string formatMemoryToString(const char* memory, const MemType type, const s
break;
}
}
} // namespace Common
} // namespace Common
Loading
Loading