PTM: Changed the way the ptm services are handled to be like the

IR, HID, and APT services.
This commit is contained in:
purpasmart96 2015-04-30 13:13:22 -07:00
parent a08bb13e8b
commit 53130fffd9
5 changed files with 112 additions and 125 deletions

View File

@ -2,6 +2,8 @@
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "common/logging/log.h"
#include "core/file_sys/file_backend.h" #include "core/file_sys/file_backend.h"
#include "core/hle/service/fs/archive.h" #include "core/hle/service/fs/archive.h"
#include "core/hle/service/ptm/ptm.h" #include "core/hle/service/ptm/ptm.h"
@ -23,20 +25,56 @@ static bool shell_open;
static bool battery_is_charging; static bool battery_is_charging;
u32 GetAdapterState() { void GetAdapterState(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
// TODO(purpasmart96): This function is only a stub, // TODO(purpasmart96): This function is only a stub,
// it returns a valid result without implementing full functionality. // it returns a valid result without implementing full functionality.
return battery_is_charging ? 1 : 0;
cmd_buff[1] = RESULT_SUCCESS.raw;
cmd_buff[2] = battery_is_charging ? 1 : 0;
LOG_WARNING(Service_PTM, "(STUBBED) called");
} }
u32 GetShellState() { void GetShellState(Service::Interface* self) {
return shell_open ? 1 : 0; u32* cmd_buff = Kernel::GetCommandBuffer();
cmd_buff[1] = RESULT_SUCCESS.raw;
cmd_buff[2] = shell_open ? 1 : 0;
} }
ChargeLevels GetBatteryLevel() { void GetBatteryLevel(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
// TODO(purpasmart96): This function is only a stub, // TODO(purpasmart96): This function is only a stub,
// it returns a valid result without implementing full functionality. // it returns a valid result without implementing full functionality.
return ChargeLevels::CompletelyFull; // Set to a completely full battery
cmd_buff[1] = RESULT_SUCCESS.raw;
cmd_buff[2] = static_cast<u32>(ChargeLevels::CompletelyFull); // Set to a completely full battery
LOG_WARNING(Service_PTM, "(STUBBED) called");
}
void GetBatteryChargeState(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
// TODO(purpasmart96): This function is only a stub,
// it returns a valid result without implementing full functionality.
cmd_buff[1] = RESULT_SUCCESS.raw;
cmd_buff[2] = battery_is_charging ? 1 : 0;
LOG_WARNING(Service_PTM, "(STUBBED) called");
}
void IsLegacyPowerOff(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
cmd_buff[1] = RESULT_SUCCESS.raw;
cmd_buff[2] = 0;
LOG_WARNING(Service_PTM, "(STUBBED) called");
} }
void Init() { void Init() {

View File

@ -5,6 +5,7 @@
#pragma once #pragma once
#include <array> #include <array>
#include "core/hle/service/service.h"
#include "core/hle/result.h" #include "core/hle/result.h"
namespace Service { namespace Service {
@ -35,25 +36,48 @@ struct GameCoin {
}; };
/** /**
* Returns whether the battery is charging or not.
* It is unknown if GetAdapterState is the same as GetBatteryChargeState, * It is unknown if GetAdapterState is the same as GetBatteryChargeState,
* it is likely to just be a duplicate function of GetBatteryChargeState * it is likely to just be a duplicate function of GetBatteryChargeState
* that controls another part of the HW. * that controls another part of the HW.
* @returns 1 if the battery is charging, and 0 otherwise. * PTM::GetAdapterState service function
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : Output of function, 0 = not charging, 1 = charging.
*/ */
u32 GetAdapterState(); void GetAdapterState(Interface* self);
/** /**
* Returns whether the 3DS's physical shell casing is open or closed * PTM::GetShellState service function.
* @returns 1 if the shell is open, and 0 if otherwise * Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : Whether the 3DS's physical shell casing is open (1) or closed (0)
*/ */
u32 GetShellState(); void GetShellState(Interface* self);
/** /**
* Get the current battery's charge level. * PTM::GetBatteryLevel service function
* @returns The battery's charge level. * Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : Battery level, 5 = completely full battery, 4 = mostly full battery,
* 3 = half full battery, 2 = low battery, 1 = critical battery.
*/ */
ChargeLevels GetBatteryLevel(); void GetBatteryLevel(Interface* self);
/**
* PTM::GetBatteryChargeState service function
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : Output of function, 0 = not charging, 1 = charging.
*/
void GetBatteryChargeState(Interface* self);
/**
* PTM::IsLegacyPowerOff service function
* Outputs:
* 1: Result code, 0 on success, otherwise error code
* 2: Whether the system is going through a power off
*/
void IsLegacyPowerOff(Interface* self);
/// Initialize the PTM service /// Initialize the PTM service
void Init(); void Init();

View File

@ -2,26 +2,13 @@
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "common/make_unique.h"
#include "core/file_sys/archive_extsavedata.h"
#include "core/hle/hle.h" #include "core/hle/hle.h"
#include "core/hle/service/ptm/ptm.h"
#include "core/hle/service/ptm/ptm_sysm.h" #include "core/hle/service/ptm/ptm_sysm.h"
namespace Service { namespace Service {
namespace PTM { namespace PTM {
/**
* Returns whether the system is powering off (?)
* Outputs:
* 1: Result code, 0 on success, otherwise error code
* 2: Whether the system is going through a power off
*/
static void IsLegacyPowerOff(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
cmd_buff[1] = RESULT_SUCCESS.raw;
cmd_buff[2] = 0;
}
const Interface::FunctionInfo FunctionTable[] = { const Interface::FunctionInfo FunctionTable[] = {
{0x040100C0, nullptr, "SetRtcAlarmEx"}, {0x040100C0, nullptr, "SetRtcAlarmEx"},
{0x04020042, nullptr, "ReplySleepQuery"}, {0x04020042, nullptr, "ReplySleepQuery"},

View File

@ -11,68 +11,6 @@
namespace Service { namespace Service {
namespace PTM { namespace PTM {
/**
* PTM_U::GetAdapterState service function
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : Output of function, 0 = not charging, 1 = charging.
*/
static void GetAdapterState(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
cmd_buff[1] = RESULT_SUCCESS.raw;
cmd_buff[2] = GetAdapterState();
LOG_WARNING(Service_PTM, "(STUBBED) called");
}
/*
* PTM_User::GetShellState service function.
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : Whether the 3DS's physical shell casing is open (1) or closed (0)
*/
static void GetShellState(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
cmd_buff[1] = RESULT_SUCCESS.raw;
cmd_buff[2] = GetShellState();
}
/**
* PTM_U::GetBatteryLevel service function
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : Battery level, 5 = completely full battery, 4 = mostly full battery,
* 3 = half full battery, 2 = low battery, 1 = critical battery.
*/
static void GetBatteryLevel(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
cmd_buff[1] = RESULT_SUCCESS.raw;
cmd_buff[2] = static_cast<u32>(GetBatteryLevel());
LOG_WARNING(Service_PTM, "(STUBBED) called");
}
/**
* PTM_U::GetBatteryChargeState service function
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : Output of function, 0 = not charging, 1 = charging.
*/
static void GetBatteryChargeState(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
// TODO(purpasmart96): This function is only a stub,
// it returns a valid result without implementing full functionality.
cmd_buff[1] = RESULT_SUCCESS.raw;
cmd_buff[2] = GetAdapterState();
LOG_WARNING(Service_PTM, "(STUBBED) called");
}
const Interface::FunctionInfo FunctionTable[] = { const Interface::FunctionInfo FunctionTable[] = {
{0x00010002, nullptr, "RegisterAlarmClient"}, {0x00010002, nullptr, "RegisterAlarmClient"},
{0x00020080, nullptr, "SetRtcAlarm"}, {0x00020080, nullptr, "SetRtcAlarm"},