[FS/Memory] Add ENVINFO and some FS calls for Metroid 2

This commit is contained in:
wheremyfoodat 2022-10-15 21:58:14 +03:00
parent ec26631e5d
commit 015343a848
5 changed files with 45 additions and 2 deletions

View file

@ -6,6 +6,7 @@ namespace ConfigMem {
enum : u32 {
KernelVersionMinor = 0x1FF80002,
KernelVersionMajor = 0x1FF80003,
EnvInfo = 0x1FF80014,
AppMemAlloc = 0x1FF80040,
Datetime0 = 0x1FF81020,
LedState3D = 0x1FF81084

View file

@ -124,6 +124,10 @@ class Memory {
std::optional<u32> findPaddr(u32 size);
u64 timeSince3DSEpoch();
// https://www.3dbrew.org/wiki/Configuration_Memory#ENVINFO
// Report a retail unit without JTAG
static constexpr u32 envInfo = 1;
public:
u16 kernelVersion = 0;
u32 usedUserMemory = 0;

View file

@ -28,10 +28,16 @@ class FSService {
// Service commands
void closeArchive(u32 messagePointer);
void getPriority(u32 messagePointer);
void initialize(u32 messagePointer);
void initializeWithSdkVersion(u32 messagePointer);
void openArchive(u32 messagePointer);
void openFile(u32 messagePointer);
void openFileDirectly(u32 messagePointer);
void setPriority(u32 messagePointer);
// Used for set/get priority: Not sure what sort of priority this is referring to
u32 priority;
public:
FSService(Memory& mem, Kernel& kernel) : mem(mem), saveData(mem), sdmc(mem), selfNcch(mem), kernel(kernel) {}

View file

@ -74,6 +74,7 @@ u8 Memory::read8(u32 vaddr) {
}
else {
switch (vaddr) {
case ConfigMem::EnvInfo: return envInfo;
case ConfigMem::KernelVersionMinor: return u8(kernelVersion & 0xff);
case ConfigMem::KernelVersionMajor: return u8(kernelVersion >> 8);
case ConfigMem::LedState3D: return 1; // Report the 3D LED as always off (non-zero) for now

View file

@ -7,7 +7,10 @@ namespace FSCommands {
OpenFile = 0x080201C2,
OpenFileDirectly = 0x08030204,
OpenArchive = 0x080C00C2,
CloseArchive = 0x080E0080
CloseArchive = 0x080E0080,
InitializeWithSdkVersion = 0x08610042,
SetPriority = 0x08620040,
GetPriority = 0x08630000
};
}
@ -18,7 +21,9 @@ namespace Result {
};
}
void FSService::reset() {}
void FSService::reset() {
priority = 0;
}
ArchiveBase* FSService::getArchiveFromID(u32 id) {
switch (id) {
@ -69,10 +74,13 @@ void FSService::handleSyncRequest(u32 messagePointer) {
const u32 command = mem.read32(messagePointer);
switch (command) {
case FSCommands::CloseArchive: closeArchive(messagePointer); break;
case FSCommands::GetPriority: getPriority(messagePointer); break;
case FSCommands::Initialize: initialize(messagePointer); break;
case FSCommands::InitializeWithSdkVersion: initializeWithSdkVersion(messagePointer); break;
case FSCommands::OpenArchive: openArchive(messagePointer); break;
case FSCommands::OpenFile: openFile(messagePointer); break;
case FSCommands::OpenFileDirectly: openFileDirectly(messagePointer); break;
case FSCommands::SetPriority: setPriority(messagePointer); break;
default: Helpers::panic("FS service requested. Command: %08X\n", command);
}
}
@ -82,6 +90,14 @@ void FSService::initialize(u32 messagePointer) {
mem.write32(messagePointer + 4, Result::Success);
}
// TODO: Figure out how this is different from Initialize
void FSService::initializeWithSdkVersion(u32 messagePointer) {
const auto version = mem.read32(messagePointer + 4);
log("FS::InitializeWithSDKVersion(version = %d)\n", version);
initialize(messagePointer);
}
void FSService::closeArchive(u32 messagePointer) {
const Handle handle = static_cast<u32>(mem.read64(messagePointer + 4)); // TODO: archive handles should be 64-bit
const auto object = kernel.getObject(handle, KernelObjectType::Archive);
@ -179,4 +195,19 @@ void FSService::openFileDirectly(u32 messagePointer) {
mem.write32(messagePointer + 4, Result::Success);
mem.write32(messagePointer + 12, handle.value());
}
}
void FSService::getPriority(u32 messagePointer) {
log("FS::GetPriority\n");
mem.write32(messagePointer + 4, Result::Success);
mem.write32(messagePointer + 8, priority);
}
void FSService::setPriority(u32 messagePointer) {
const u32 value = mem.read32(messagePointer + 4);
log("FS::SetPriority (priority = %d)\n", value);
mem.write32(messagePointer + 4, Result::Success);
priority = value;
}