mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-07 06:35:40 +12:00
[PTM] Implement GetAdapterState, GetBatteryLevel
This commit is contained in:
parent
fc7bdc9158
commit
3f16bcc704
2 changed files with 47 additions and 1 deletions
|
@ -12,6 +12,8 @@ class PTMService {
|
|||
|
||||
// Service commands
|
||||
void configureNew3DSCPU(u32 messagePointer);
|
||||
void getAdapterState(u32 messagePointer);
|
||||
void getBatteryLevel(u32 messagePointer);
|
||||
void getStepHistory(u32 messagePointer);
|
||||
void getTotalStepCount(u32 messagePointer);
|
||||
|
||||
|
@ -19,4 +21,26 @@ public:
|
|||
PTMService(Memory& mem) : mem(mem) {}
|
||||
void reset();
|
||||
void handleSyncRequest(u32 messagePointer);
|
||||
|
||||
// 0% -> 0 (shutting down)
|
||||
// 1-5% -> 1
|
||||
// 6-10% -> 2
|
||||
// 11-30% -> 3
|
||||
// 31-60% -> 4
|
||||
// 61-100% -> 5
|
||||
static constexpr u8 batteryPercentToLevel(u8 percent) {
|
||||
if (percent == 0) {
|
||||
return 0;
|
||||
} else if (percent >= 1 && percent <= 5) {
|
||||
return 1;
|
||||
} else if (percent >= 6 && percent <= 10) {
|
||||
return 2;
|
||||
} else if (percent >= 11 && percent <= 30) {
|
||||
return 3;
|
||||
} else if (percent >= 31 && percent <= 60) {
|
||||
return 4;
|
||||
} else {
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
};
|
|
@ -3,9 +3,11 @@
|
|||
|
||||
namespace PTMCommands {
|
||||
enum : u32 {
|
||||
GetAdapterState = 0x00050000,
|
||||
GetBatteryLevel = 0x00070000,
|
||||
GetStepHistory = 0x000B00C2,
|
||||
GetTotalStepCount = 0x000C0000,
|
||||
ConfigureNew3DSCPU = 0x08180040
|
||||
ConfigureNew3DSCPU = 0x08180040,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -15,12 +17,32 @@ void PTMService::handleSyncRequest(u32 messagePointer) {
|
|||
const u32 command = mem.read32(messagePointer);
|
||||
switch (command) {
|
||||
case PTMCommands::ConfigureNew3DSCPU: configureNew3DSCPU(messagePointer); break;
|
||||
case PTMCommands::GetAdapterState: getAdapterState(messagePointer); break;
|
||||
case PTMCommands::GetBatteryLevel: getBatteryLevel(messagePointer); break;
|
||||
case PTMCommands::GetStepHistory: getStepHistory(messagePointer); break;
|
||||
case PTMCommands::GetTotalStepCount: getTotalStepCount(messagePointer); break;
|
||||
default: Helpers::panic("PTM service requested. Command: %08X\n", command);
|
||||
}
|
||||
}
|
||||
|
||||
void PTMService::getAdapterState(u32 messagePointer) {
|
||||
log("PTM::GetAdapterState\n");
|
||||
constexpr bool adapterConnected = true; // Pretend the 3DS is charging cause why not
|
||||
|
||||
mem.write32(messagePointer, IPC::responseHeader(0x5, 2, 0));
|
||||
mem.write32(messagePointer + 4, Result::Success);
|
||||
mem.write8(messagePointer + 8, adapterConnected ? 1 : 0);
|
||||
}
|
||||
|
||||
void PTMService::getBatteryLevel(u32 messagePointer) {
|
||||
log("PTM::GetBatteryLevel");
|
||||
constexpr u8 batteryPercent = 3; // 3% battery so users can suffer
|
||||
|
||||
mem.write32(messagePointer, IPC::responseHeader(0x7, 2, 0));
|
||||
mem.write32(messagePointer + 4, Result::Success);
|
||||
mem.write8(messagePointer + 8, batteryPercentToLevel(batteryPercent));
|
||||
}
|
||||
|
||||
void PTMService::getStepHistory(u32 messagePointer) {
|
||||
log("PTM::GetStepHistory [stubbed]\n");
|
||||
mem.write32(messagePointer, IPC::responseHeader(0xB, 1, 2));
|
||||
|
|
Loading…
Add table
Reference in a new issue