mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-05-04 03:04:48 +12:00
We can almost load commercial carts now
This commit is contained in:
parent
36b0117ebc
commit
87bf469447
5 changed files with 50 additions and 8 deletions
|
@ -49,6 +49,10 @@ bool NCCH::loadFromHeader(u8* header, IOFile& file) {
|
|||
compressCode = (exheader[0xD] & 1) != 0;
|
||||
stackSize = *(u32*)&exheader[0x1C];
|
||||
bssSize = *(u32*)&exheader[0x3C];
|
||||
|
||||
text.extract(&exheader[0x10]);
|
||||
rodata.extract(&exheader[0x20]);
|
||||
data.extract(&exheader[0x30]);
|
||||
}
|
||||
|
||||
printf("Stack size: %08X\nBSS size: %08X\n", stackSize, bssSize);
|
||||
|
@ -84,7 +88,9 @@ bool NCCH::loadFromHeader(u8* header, IOFile& file) {
|
|||
}
|
||||
|
||||
if (std::strcmp(name, ".code") == 0) {
|
||||
std::vector<u8> code;
|
||||
if (hasCode()) {
|
||||
Helpers::panic("Second code file in a single NCCH partition. What should this do?\n");
|
||||
}
|
||||
|
||||
if (compressCode) {
|
||||
std::vector<u8> tmp;
|
||||
|
@ -96,15 +102,14 @@ bool NCCH::loadFromHeader(u8* header, IOFile& file) {
|
|||
file.readBytes(tmp.data(), fileSize);
|
||||
|
||||
// Decompress .code file from the tmp vector to the "code" vector
|
||||
if (!CartLZ77::decompress(code, tmp)) {
|
||||
if (!CartLZ77::decompress(codeFile, tmp)) {
|
||||
printf("Failed to decompress .code file\n");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
code.resize(fileSize);
|
||||
codeFile.resize(fileSize);
|
||||
file.seek(exeFSOffset + exeFSHeaderSize + fileOffset);
|
||||
file.readBytes(code.data(), fileSize);
|
||||
Helpers::panic("Uncompressed .code file!");
|
||||
file.readBytes(codeFile.data(), fileSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,11 +67,20 @@ std::optional<NCSD> Memory::loadNCSD(const std::filesystem::path& path) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!ncsd.partitions[0].ncch.hasExtendedHeader()) {
|
||||
printf("NCSD's CXI doesn't have exheader?\n");
|
||||
|
||||
auto& cxi = ncsd.partitions[0].ncch;
|
||||
if (!cxi.hasExtendedHeader() || !cxi.hasCode()) {
|
||||
printf("NCSD with an invalid CXI in partition 0?\n");
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// Map code file to memory
|
||||
const auto& code = cxi.codeFile;
|
||||
printf("Text address = %08X page count = %08X\n", cxi.text.address, cxi.text.size);
|
||||
printf("Rodata address = %08X page count = %08X\n", cxi.rodata.address, cxi.rodata.size);
|
||||
printf("Data address = %08X page count = %08X\n", cxi.data.address, cxi.data.size);
|
||||
|
||||
ncsd.entrypoint = cxi.text.address;
|
||||
|
||||
return ncsd;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue