aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/hle/service/ptm/ptm.cpp
diff options
context:
space:
mode:
authorGravatar Subv <subv2112@gmail.com>2015-02-26 21:13:08 -0500
committerGravatar Subv <subv2112@gmail.com>2015-03-03 21:48:08 -0500
commit83a8975cb89b908b4737d647a210c19775f25ed7 (patch)
tree53fd0e37dcab9c3a5328338273315b159381d949 /src/core/hle/service/ptm/ptm.cpp
parent44f46254dc57c4251ed72ee361cb8479a8e546cd (diff)
Services: Moved the PTM and APT services to their own folder
This coincidentally fixes an issue about the PTM service failing to create its SharedExtSaveData archive due to the FS service not being initialized by the time the creating code runs. Ideally I'd like to move each process to its own folder, and have a single file per process that registers the service classes, which would be in their own files inside that folder. Then each service class would just call functions from the process to complete the commands.
Diffstat (limited to 'src/core/hle/service/ptm/ptm.cpp')
-rw-r--r--src/core/hle/service/ptm/ptm.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/core/hle/service/ptm/ptm.cpp b/src/core/hle/service/ptm/ptm.cpp
new file mode 100644
index 00000000..56c918d4
--- /dev/null
+++ b/src/core/hle/service/ptm/ptm.cpp
@@ -0,0 +1,76 @@
+// Copyright 2015 Citra Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#include "core/hle/service/service.h"
+#include "core/hle/service/fs/archive.h"
+#include "core/hle/service/ptm/ptm.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"
+
+namespace Service {
+namespace PTM {
+
+/// Values for the default gamecoin.dat file
+static const GameCoin default_game_coin = { 0x4F00, 42, 0, 0, 0, 2014, 12, 29 };
+
+/// 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};
+
+static bool shell_open = true;
+
+static bool battery_is_charging = true;
+
+u32 GetAdapterState() {
+ // TODO(purpasmart96): This function is only a stub,
+ // it returns a valid result without implementing full functionality.
+ return battery_is_charging ? 1 : 0;
+}
+
+u32 GetShellState() {
+ return shell_open ? 1 : 0;
+}
+
+ChargeLevels GetBatteryLevel() {
+ // TODO(purpasmart96): This function is only a stub,
+ // it returns a valid result without implementing full functionality.
+ return ChargeLevels::CompletelyFull; // Set to a completely full battery
+}
+
+void PTMInit() {
+ AddService(new PTM_Play_Interface);
+ AddService(new PTM_Sysm_Interface);
+ AddService(new PTM_U_Interface);
+
+ // Open the SharedExtSaveData archive 0xF000000B and create the gamecoin.dat file if it doesn't exist
+ FileSys::Path archive_path(ptm_shared_extdata_id);
+ auto archive_result = Service::FS::OpenArchive(Service::FS::ArchiveIdCode::SharedExtSaveData, archive_path);
+ // 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
+ Service::FS::FormatArchive(Service::FS::ArchiveIdCode::SharedExtSaveData, archive_path);
+ // Open it again to get a valid archive now that the folder exists
+ archive_result = Service::FS::OpenArchive(Service::FS::ArchiveIdCode::SharedExtSaveData, archive_path);
+ ASSERT_MSG(archive_result.Succeeded(), "Could not open the PTM SharedExtSaveData archive!");
+
+ FileSys::Path gamecoin_path("gamecoin.dat");
+ FileSys::Mode open_mode = {};
+ open_mode.write_flag = 1;
+ open_mode.create_flag = 1;
+ // Open the file and write the default gamecoin information
+ auto gamecoin_result = Service::FS::OpenFileFromArchive(*archive_result, gamecoin_path, open_mode);
+ if (gamecoin_result.Succeeded()) {
+ auto gamecoin = gamecoin_result.MoveFrom();
+ gamecoin->backend->Write(0, sizeof(GameCoin), 1, reinterpret_cast<const u8*>(&default_game_coin));
+ gamecoin->backend->Close();
+ }
+ }
+}
+
+void PTMShutdown() {
+
+}
+
+} // namespace PTM
+} // namespace Service