mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-08 23:25:40 +12:00
Run clang-format
This commit is contained in:
parent
414e8cf6c8
commit
53917841bc
1 changed files with 45 additions and 53 deletions
|
@ -7,14 +7,13 @@
|
|||
#include "memory.hpp"
|
||||
|
||||
namespace {
|
||||
|
||||
struct LoadInfo {
|
||||
struct LoadInfo {
|
||||
u32 codeSegSizeAligned;
|
||||
u32 rodataSegSizeAligned;
|
||||
u32 dataSegSizeAligned;
|
||||
};
|
||||
};
|
||||
|
||||
static inline u32 translateAddr(const u32 off, const u32* addrs, const u32* offsets) {
|
||||
static inline u32 translateAddr(const u32 off, const u32* addrs, const u32* offsets) {
|
||||
if (off < offsets[1]) {
|
||||
return addrs[0] + off;
|
||||
}
|
||||
|
@ -23,15 +22,14 @@ static inline u32 translateAddr(const u32 off, const u32* addrs, const u32* offs
|
|||
return addrs[1] + off - offsets[1];
|
||||
}
|
||||
return addrs[2] + off - offsets[2];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
bool Memory::map3DSX(HB3DSX& hb3dsx, const HB3DSX::Header& header) {
|
||||
const LoadInfo hbInfo = {
|
||||
.codeSegSizeAligned = (header.codeSegSize+0xFFF) &~ 0xFFF,
|
||||
.rodataSegSizeAligned = (header.rodataSegSize+0xFFF) &~ 0xFFF,
|
||||
.dataSegSizeAligned = (header.dataSegSize+0xFFF) &~ 0xFFF,
|
||||
.codeSegSizeAligned = (header.codeSegSize + 0xFFF) & ~0xFFF,
|
||||
.rodataSegSizeAligned = (header.rodataSegSize + 0xFFF) & ~0xFFF,
|
||||
.dataSegSizeAligned = (header.dataSegSize + 0xFFF) & ~0xFFF,
|
||||
};
|
||||
|
||||
const u32 textSegAddr = HB3DSX::entrypoint;
|
||||
|
@ -143,8 +141,8 @@ bool Memory::map3DSX(HB3DSX& hb3dsx, const HB3DSX::Header& header) {
|
|||
const u32 inAddr = textSegAddr + (sectionData.data() - code.data()); // byte offset -> word count
|
||||
u32 origData = 0;
|
||||
std::memcpy(&origData, §ionData[0], sizeof(u32));
|
||||
const u32 subType = origData >> (32-4);
|
||||
const u32 addr = translateAddr(origData &~ 0xF0000000, segAddrs, segOffs);
|
||||
const u32 subType = origData >> (32 - 4);
|
||||
const u32 addr = translateAddr(origData & ~0xF0000000, segAddrs, segOffs);
|
||||
|
||||
switch (relocType) {
|
||||
case HB3DSX::RelocType::Absolute: {
|
||||
|
@ -164,9 +162,7 @@ bool Memory::map3DSX(HB3DSX& hb3dsx, const HB3DSX::Header& header) {
|
|||
case 0: // 32-bit signed offset
|
||||
std::memcpy(§ionData[0], &data, sizeof(u32));
|
||||
break;
|
||||
default:
|
||||
Helpers::panic("Unsupported relative reloc subtype");
|
||||
return false;
|
||||
default: Helpers::panic("Unsupported relative reloc subtype"); return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -195,7 +191,7 @@ bool Memory::map3DSX(HB3DSX& hb3dsx, const HB3DSX::Header& header) {
|
|||
// Detect and fill _prm structure
|
||||
HB3DSX::PrmStruct pst;
|
||||
std::memcpy(&pst, &code[4], sizeof(pst));
|
||||
if (pst.magic[0] == '_' && pst.magic[1] == 'p' && pst.magic[2] == 'r' && pst.magic[3] == 'm' ) {
|
||||
if (pst.magic[0] == '_' && pst.magic[1] == 'p' && pst.magic[2] == 'r' && pst.magic[3] == 'm') {
|
||||
// if there was any argv to put, it would go there
|
||||
// first u32: argc
|
||||
// remaining: continuous argv string (NUL-char separated, ofc)
|
||||
|
@ -262,8 +258,7 @@ std::optional<u32> Memory::load3DSX(const std::filesystem::path& path) {
|
|||
}
|
||||
|
||||
if (hbHeader.headerSize == 0x20 || hbHeader.headerSize == 0x2C) {
|
||||
if (hbHeader.headerSize == 0x2C)
|
||||
{
|
||||
if (hbHeader.headerSize == 0x2C) {
|
||||
hb3dsx.file.seek(8, SEEK_CUR); // skip SMDH info
|
||||
std::tie(success, bytes) = hb3dsx.file.readBytes(&hb3dsx.romFSOffset, 4);
|
||||
if (!success || bytes != 4) {
|
||||
|
@ -278,8 +273,7 @@ std::optional<u32> Memory::load3DSX(const std::filesystem::path& path) {
|
|||
}
|
||||
hb3dsx.romFSSize = *fileSize - hb3dsx.romFSOffset;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
printf("Invalid 3DSX header size\n");
|
||||
return std::nullopt;
|
||||
}
|
||||
|
@ -293,17 +287,15 @@ std::optional<u32> Memory::load3DSX(const std::filesystem::path& path) {
|
|||
return HB3DSX::entrypoint;
|
||||
}
|
||||
|
||||
bool HB3DSX::hasRomFs() const {
|
||||
return romFSSize != 0 && romFSOffset != 0;
|
||||
}
|
||||
bool HB3DSX::hasRomFs() const { return romFSSize != 0 && romFSOffset != 0; }
|
||||
|
||||
std::pair<bool, std::size_t> HB3DSX::readRomFSBytes(void *dst, std::size_t offset, std::size_t size) {
|
||||
std::pair<bool, std::size_t> HB3DSX::readRomFSBytes(void* dst, std::size_t offset, std::size_t size) {
|
||||
if (!hasRomFs()) {
|
||||
return { false, 0 };
|
||||
return {false, 0};
|
||||
}
|
||||
|
||||
if (!file.seek(romFSOffset + offset)) {
|
||||
return { false, 0 };
|
||||
return {false, 0};
|
||||
}
|
||||
|
||||
return file.readBytes(dst, size);
|
||||
|
|
Loading…
Add table
Reference in a new issue