Skip to content

Commit

Permalink
Merge pull request #274 from wheremyfoodat/SystemSaveData
Browse files Browse the repository at this point in the history
Split PTM service types
  • Loading branch information
wheremyfoodat authored Sep 14, 2023
2 parents 7fdffd5 + 712be4c commit 61bfd3d
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 16 deletions.
8 changes: 6 additions & 2 deletions include/kernel/handles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ namespace KernelHandles {
NDM, // ?????
NWM_UDS, // Local multiplayer
NEWS_U, // This service literally has 1 command (AddNotification) and I don't even understand what it does
PTM, // PTM service (Used for accessing various console info, such as battery, shell and pedometer state)
PTM_U, // PTM service (Used for accessing various console info, such as battery, shell and pedometer state)
PTM_SYSM, // PTM system service
PTM_PLAY, // PTM Play service, ues for retrieving play history
SOC, // Socket service
SSL, // SSL service (Totally didn't expect that)
Y2R, // Also does camera stuff
Expand Down Expand Up @@ -96,7 +98,9 @@ namespace KernelHandles {
case NWM_UDS: return "nwm::UDS";
case NFC: return "NFC";
case NIM: return "NIM";
case PTM: return "PTM";
case PTM_U: return "PTM:U";
case PTM_SYSM: return "PTM:SYSM";
case PTM_PLAY: return "PTM:PLAY";
case SOC: return "SOC";
case SSL: return "SSL";
case Y2R: return "Y2R";
Expand Down
10 changes: 8 additions & 2 deletions include/services/ptm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "result/result.hpp"

class PTMService {
Handle handle = KernelHandles::PTM;
Memory& mem;
MAKE_LOG_FUNCTION(log, ptmLogger)

Expand All @@ -19,12 +18,19 @@ class PTMService {
void getBatteryChargeState(u32 messagePointer);
void getBatteryLevel(u32 messagePointer);
void getStepHistory(u32 messagePointer);
void getStepHistoryAll(u32 messagePointer);
void getTotalStepCount(u32 messagePointer);

public:
enum class Type {
U, // ptm:u
SYSM, // ptm:sysm
PLAY, // ptm:play
};

PTMService(Memory& mem, const EmulatorConfig& config) : mem(mem), config(config) {}
void reset();
void handleSyncRequest(u32 messagePointer);
void handleSyncRequest(u32 messagePointer, Type type);

// 0% -> 0 (shutting down)
// 1-5% -> 1
Expand Down
51 changes: 42 additions & 9 deletions src/core/services/ptm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,50 @@ namespace PTMCommands {
GetBatteryChargeState = 0x00080000,
GetStepHistory = 0x000B00C2,
GetTotalStepCount = 0x000C0000,
GetStepHistoryAll = 0x000F0084,
ConfigureNew3DSCPU = 0x08180040,

// ptm:play functions
GetPlayHistory = 0x08070082,
GetPlayHistoryStart = 0x08080000,
GetPlayHistoryLength = 0x08090000,
CalcPlayHistoryStart = 0x080B0080,
};
}

void PTMService::reset() {}

void PTMService::handleSyncRequest(u32 messagePointer) {
void PTMService::handleSyncRequest(u32 messagePointer, PTMService::Type type) {
const u32 command = mem.read32(messagePointer);

// ptm:play functions
switch (command) {
case PTMCommands::ConfigureNew3DSCPU: configureNew3DSCPU(messagePointer); break;
case PTMCommands::GetAdapterState: getAdapterState(messagePointer); break;
case PTMCommands::GetBatteryChargeState: getBatteryChargeState(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);
}
case PTMCommands::ConfigureNew3DSCPU: configureNew3DSCPU(messagePointer); break;
case PTMCommands::GetAdapterState: getAdapterState(messagePointer); break;
case PTMCommands::GetBatteryChargeState: getBatteryChargeState(messagePointer); break;
case PTMCommands::GetBatteryLevel: getBatteryLevel(messagePointer); break;
case PTMCommands::GetStepHistory: getStepHistory(messagePointer); break;
case PTMCommands::GetStepHistoryAll: getStepHistoryAll(messagePointer); break;
case PTMCommands::GetTotalStepCount: getTotalStepCount(messagePointer); break;

default:
// ptm:play-only functions
if (type == Type::PLAY) {
switch (command) {
case PTMCommands::GetPlayHistory:
case PTMCommands::GetPlayHistoryStart:
case PTMCommands::GetPlayHistoryLength:
mem.write32(messagePointer + 4, Result::Success);
mem.write64(messagePointer + 8, 0);
Helpers::warn("Stubbed PTM:PLAY service requested. Command: %08X\n", command);
break;

default: Helpers::panic("PTM PLAY service requested. Command: %08X\n", command); break;
}
} else {
Helpers::panic("PTM service requested. Command: %08X\n", command);
}
}
}

void PTMService::getAdapterState(u32 messagePointer) {
Expand Down Expand Up @@ -59,6 +86,12 @@ void PTMService::getStepHistory(u32 messagePointer) {
mem.write32(messagePointer + 4, Result::Success);
}

void PTMService::getStepHistoryAll(u32 messagePointer) {
log("PTM::GetStepHistoryAll [stubbed]\n");
mem.write32(messagePointer, IPC::responseHeader(0xF, 1, 2));
mem.write32(messagePointer + 4, Result::Success);
}

void PTMService::getTotalStepCount(u32 messagePointer) {
log("PTM::GetTotalStepCount\n");
mem.write32(messagePointer, IPC::responseHeader(0xC, 2, 0));
Expand Down
9 changes: 6 additions & 3 deletions src/core/services/service_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,9 @@ static std::map<std::string, Handle> serviceMap = {
{ "nfc:u", KernelHandles::NFC },
{ "nwm::UDS", KernelHandles::NWM_UDS },
{ "nim:aoc", KernelHandles::NIM },
{ "ptm:u", KernelHandles::PTM }, // TODO: ptm:u and ptm:sysm have very different command sets
{ "ptm:sysm", KernelHandles::PTM },
{ "ptm:u", KernelHandles::PTM_U }, // TODO: ptm:u and ptm:sysm have very different command sets
{ "ptm:sysm", KernelHandles::PTM_SYSM },
{ "ptm:play", KernelHandles::PTM_PLAY },
{ "soc:U", KernelHandles::SOC },
{ "ssl:C", KernelHandles::SSL },
{ "y2r:u", KernelHandles::Y2R },
Expand Down Expand Up @@ -223,7 +224,9 @@ void ServiceManager::sendCommandToService(u32 messagePointer, Handle handle) {
case KernelHandles::NDM: ndm.handleSyncRequest(messagePointer); break;
case KernelHandles::NEWS_U: news_u.handleSyncRequest(messagePointer); break;
case KernelHandles::NWM_UDS: nwm_uds.handleSyncRequest(messagePointer); break;
case KernelHandles::PTM: ptm.handleSyncRequest(messagePointer); break;
case KernelHandles::PTM_PLAY: ptm.handleSyncRequest(messagePointer, PTMService::Type::PLAY); break;
case KernelHandles::PTM_SYSM: ptm.handleSyncRequest(messagePointer, PTMService::Type::SYSM); break;
case KernelHandles::PTM_U: ptm.handleSyncRequest(messagePointer, PTMService::Type::U); break;
case KernelHandles::SOC: soc.handleSyncRequest(messagePointer); break;
case KernelHandles::SSL: ssl.handleSyncRequest(messagePointer); break;
case KernelHandles::Y2R: y2r.handleSyncRequest(messagePointer); break;
Expand Down

0 comments on commit 61bfd3d

Please sign in to comment.