2015-02-26 21:13:08 -05:00
|
|
|
// Copyright 2015 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2016-09-17 20:38:01 -04:00
|
|
|
#include "core/hle/service/ptm/ptm.h"
|
2015-04-30 16:13:22 -04:00
|
|
|
#include "common/logging/log.h"
|
2015-05-06 01:15:46 -04:00
|
|
|
#include "core/file_sys/file_backend.h"
|
2015-02-26 21:13:08 -05:00
|
|
|
#include "core/hle/service/fs/archive.h"
|
|
|
|
#include "core/hle/service/ptm/ptm_play.h"
|
|
|
|
#include "core/hle/service/ptm/ptm_sysm.h"
|
|
|
|
#include "core/hle/service/ptm/ptm_u.h"
|
2015-05-06 01:15:46 -04:00
|
|
|
#include "core/hle/service/service.h"
|
2016-09-17 20:38:01 -04:00
|
|
|
#include "core/settings.h"
|
2015-02-26 21:13:08 -05:00
|
|
|
|
|
|
|
namespace Service {
|
|
|
|
namespace PTM {
|
|
|
|
|
|
|
|
/// Values for the default gamecoin.dat file
|
2016-09-17 20:38:01 -04:00
|
|
|
static const GameCoin default_game_coin = {0x4F00, 42, 0, 0, 0, 2014, 12, 29};
|
2015-02-26 21:13:08 -05:00
|
|
|
|
|
|
|
/// Id of the SharedExtData archive used by the PTM process
|
|
|
|
static const std::vector<u8> ptm_shared_extdata_id = {0, 0, 0, 0, 0x0B, 0, 0, 0xF0, 0, 0, 0, 0};
|
|
|
|
|
2015-04-27 22:01:48 -04:00
|
|
|
static bool shell_open;
|
2015-02-26 21:13:08 -05:00
|
|
|
|
2015-04-27 22:01:48 -04:00
|
|
|
static bool battery_is_charging;
|
2015-02-26 21:13:08 -05:00
|
|
|
|
2015-04-30 16:13:22 -04:00
|
|
|
void GetAdapterState(Service::Interface* self) {
|
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
|
2015-02-26 21:13:08 -05:00
|
|
|
// TODO(purpasmart96): This function is only a stub,
|
|
|
|
// it returns a valid result without implementing full functionality.
|
2015-04-30 16:13:22 -04:00
|
|
|
|
|
|
|
cmd_buff[1] = RESULT_SUCCESS.raw;
|
|
|
|
cmd_buff[2] = battery_is_charging ? 1 : 0;
|
|
|
|
|
|
|
|
LOG_WARNING(Service_PTM, "(STUBBED) called");
|
2015-02-26 21:13:08 -05:00
|
|
|
}
|
|
|
|
|
2015-04-30 16:13:22 -04:00
|
|
|
void GetShellState(Service::Interface* self) {
|
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
|
|
|
|
cmd_buff[1] = RESULT_SUCCESS.raw;
|
|
|
|
cmd_buff[2] = shell_open ? 1 : 0;
|
2015-02-26 21:13:08 -05:00
|
|
|
}
|
|
|
|
|
2015-04-30 16:13:22 -04:00
|
|
|
void GetBatteryLevel(Service::Interface* self) {
|
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
|
2015-02-26 21:13:08 -05:00
|
|
|
// TODO(purpasmart96): This function is only a stub,
|
|
|
|
// it returns a valid result without implementing full functionality.
|
2015-04-30 16:13:22 -04:00
|
|
|
|
|
|
|
cmd_buff[1] = RESULT_SUCCESS.raw;
|
2016-09-17 20:38:01 -04:00
|
|
|
cmd_buff[2] =
|
|
|
|
static_cast<u32>(ChargeLevels::CompletelyFull); // Set to a completely full battery
|
2015-04-30 16:13:22 -04:00
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2015-10-23 17:58:54 -04:00
|
|
|
void GetTotalStepCount(Service::Interface* self) {
|
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
|
|
|
|
// TODO: This function is only a stub,
|
|
|
|
// it returns 0 as the total step count
|
|
|
|
|
|
|
|
cmd_buff[1] = RESULT_SUCCESS.raw;
|
|
|
|
cmd_buff[2] = 0;
|
|
|
|
|
|
|
|
LOG_WARNING(Service_PTM, "(STUBBED) called");
|
|
|
|
}
|
|
|
|
|
2015-04-30 16:13:22 -04:00
|
|
|
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");
|
2015-02-26 21:13:08 -05:00
|
|
|
}
|
|
|
|
|
2016-04-20 06:12:05 -04:00
|
|
|
void CheckNew3DS(Service::Interface* self) {
|
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
2016-05-24 17:22:44 -04:00
|
|
|
const bool is_new_3ds = Settings::values.is_new_3ds;
|
2016-04-20 06:12:05 -04:00
|
|
|
|
|
|
|
if (is_new_3ds) {
|
2016-09-17 20:38:01 -04:00
|
|
|
LOG_CRITICAL(Service_PTM, "The option 'is_new_3ds' is enabled as part of the 'System' "
|
|
|
|
"settings. Citra does not fully support New 3DS emulation yet!");
|
2016-04-20 06:12:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
cmd_buff[1] = RESULT_SUCCESS.raw;
|
|
|
|
cmd_buff[2] = is_new_3ds ? 1 : 0;
|
|
|
|
|
|
|
|
LOG_WARNING(Service_PTM, "(STUBBED) called isNew3DS = 0x%08x", static_cast<u32>(is_new_3ds));
|
|
|
|
}
|
|
|
|
|
2015-03-07 20:54:16 -05:00
|
|
|
void Init() {
|
2015-02-26 21:13:08 -05:00
|
|
|
AddService(new PTM_Play_Interface);
|
|
|
|
AddService(new PTM_Sysm_Interface);
|
|
|
|
AddService(new PTM_U_Interface);
|
|
|
|
|
2015-04-27 22:01:48 -04:00
|
|
|
shell_open = true;
|
|
|
|
battery_is_charging = true;
|
|
|
|
|
2016-09-17 20:38:01 -04:00
|
|
|
// Open the SharedExtSaveData archive 0xF000000B and create the gamecoin.dat file if it doesn't
|
|
|
|
// exist
|
2015-02-26 21:13:08 -05:00
|
|
|
FileSys::Path archive_path(ptm_shared_extdata_id);
|
2016-09-17 20:38:01 -04:00
|
|
|
auto archive_result =
|
|
|
|
Service::FS::OpenArchive(Service::FS::ArchiveIdCode::SharedExtSaveData, archive_path);
|
2015-02-26 21:13:08 -05:00
|
|
|
// If the archive didn't exist, create the files inside
|
|
|
|
if (archive_result.Code().description == ErrorDescription::FS_NotFormatted) {
|
|
|
|
// Format the archive to create the directories
|
2016-09-17 20:38:01 -04:00
|
|
|
Service::FS::FormatArchive(Service::FS::ArchiveIdCode::SharedExtSaveData,
|
|
|
|
FileSys::ArchiveFormatInfo(), archive_path);
|
2015-02-26 21:13:08 -05:00
|
|
|
// Open it again to get a valid archive now that the folder exists
|
2016-09-17 20:38:01 -04:00
|
|
|
archive_result =
|
|
|
|
Service::FS::OpenArchive(Service::FS::ArchiveIdCode::SharedExtSaveData, archive_path);
|
2015-02-26 21:13:08 -05:00
|
|
|
ASSERT_MSG(archive_result.Succeeded(), "Could not open the PTM SharedExtSaveData archive!");
|
|
|
|
|
|
|
|
FileSys::Path gamecoin_path("gamecoin.dat");
|
|
|
|
FileSys::Mode open_mode = {};
|
2016-02-11 12:41:15 -05:00
|
|
|
open_mode.write_flag.Assign(1);
|
|
|
|
open_mode.create_flag.Assign(1);
|
2015-02-26 21:13:08 -05:00
|
|
|
// Open the file and write the default gamecoin information
|
2016-09-17 20:38:01 -04:00
|
|
|
auto gamecoin_result =
|
|
|
|
Service::FS::OpenFileFromArchive(*archive_result, gamecoin_path, open_mode);
|
2015-02-26 21:13:08 -05:00
|
|
|
if (gamecoin_result.Succeeded()) {
|
|
|
|
auto gamecoin = gamecoin_result.MoveFrom();
|
2016-09-17 20:38:01 -04:00
|
|
|
gamecoin->backend->Write(0, sizeof(GameCoin), 1,
|
|
|
|
reinterpret_cast<const u8*>(&default_game_coin));
|
2015-02-26 21:13:08 -05:00
|
|
|
gamecoin->backend->Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-07 20:54:16 -05:00
|
|
|
void Shutdown() {
|
2015-02-26 21:13:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace PTM
|
|
|
|
} // namespace Service
|