From d395fcd3cc712463bad1263d2cfcd6a89555b32f Mon Sep 17 00:00:00 2001 From: wheremyfoodat Date: Tue, 11 Oct 2022 23:32:40 +0300 Subject: [PATCH] [HID] Implement some extra service calls. [CFG] Add language checking. --- CMakeLists.txt | 2 +- include/services/cfg.hpp | 1 + include/services/hid.hpp | 5 ++++ include/services/region_codes.hpp | 42 +++++++++++++++++++++++++++++++ src/core/services/cfg.cpp | 22 +++++++++++++--- src/core/services/hid.cpp | 20 ++++++++++++++- 6 files changed, 86 insertions(+), 6 deletions(-) create mode 100644 include/services/region_codes.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e6a48a4..57ed4218 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,7 +73,7 @@ set(HEADER_FILES include/emulator.hpp include/helpers.hpp include/opengl.hpp inc include/PICA/shader.hpp include/PICA/shader_unit.hpp include/PICA/float_types.hpp include/logger.hpp include/loader/ncch.hpp include/loader/ncsd.hpp include/io_file.hpp include/loader/lz77.hpp include/fs/archive_base.hpp include/fs/archive_ncch.hpp - include/services/dsp.hpp include/services/cfg.hpp + include/services/dsp.hpp include/services/cfg.hpp include/services/region_codes.hpp ) set(THIRD_PARTY_SOURCE_FILES third_party/imgui/imgui.cpp diff --git a/include/services/cfg.hpp b/include/services/cfg.hpp index 7539e470..4eae51b5 100644 --- a/include/services/cfg.hpp +++ b/include/services/cfg.hpp @@ -10,6 +10,7 @@ class CFGService { // Service functions void getConfigInfoBlk2(u32 messagePointer); + void secureInfoGetRegion(u32 messagePointer); public: CFGService(Memory& mem) : mem(mem) {} diff --git a/include/services/hid.hpp b/include/services/hid.hpp index 09f4feae..b092220f 100644 --- a/include/services/hid.hpp +++ b/include/services/hid.hpp @@ -9,9 +9,14 @@ class HIDService { Memory& mem; u8* sharedMem = nullptr; // Pointer to HID shared memory + bool accelerometerEnabled; + bool gyroEnabled; + MAKE_LOG_FUNCTION(log, hidLogger) // Service commands + void enableAccelerometer(u32 messagePointer); + void enableGyroscopeLow(u32 messagePointer); void getIPCHandles(u32 messagePointer); public: diff --git a/include/services/region_codes.hpp b/include/services/region_codes.hpp new file mode 100644 index 00000000..fff9b165 --- /dev/null +++ b/include/services/region_codes.hpp @@ -0,0 +1,42 @@ +#pragma once +#include "helpers.hpp" + +// Used for CFG::SecureInfoGetRegion +enum class Regions : u32 { + Japan = 0, + USA = 1, + Europe = 2, + Australia = 3, + China = 4, + Korea = 5, + Taiwan = 6 +}; + +// Used for the language field in the NAND user data +enum class LanguageCodes : u32 { + JP = 0, + EN = 1, + FR = 2, + DE = 3, + IT = 4, + ES = 5, + ZH = 6, + KO = 7, + NL = 8, + PT = 9, + RU = 10, + TW = 11, + + Japanese = JP, + English = EN, + French = FR, + German = DE, + Italian = IT, + Spanish = ES, + Chinese = ZH, + Korean = KO, + Dutch = NL, + Portuguese = PT, + Russian = RU, + Taiwanese = TW +}; \ No newline at end of file diff --git a/src/core/services/cfg.cpp b/src/core/services/cfg.cpp index ffb9802d..2fb21070 100644 --- a/src/core/services/cfg.cpp +++ b/src/core/services/cfg.cpp @@ -1,9 +1,11 @@ #include "services/cfg.hpp" #include "services/dsp.hpp" +#include "services/region_codes.hpp" namespace CFGCommands { enum : u32 { - GetConfigInfoBlk2 = 0x00010082 + GetConfigInfoBlk2 = 0x00010082, + SecureInfoGetRegion = 0x00020000 }; } @@ -19,6 +21,7 @@ void CFGService::handleSyncRequest(u32 messagePointer) { const u32 command = mem.read32(messagePointer); switch (command) { case CFGCommands::GetConfigInfoBlk2: getConfigInfoBlk2(messagePointer); break; + case CFGCommands::SecureInfoGetRegion: secureInfoGetRegion(messagePointer); break; default: Helpers::panic("CFG service requested. Command: %08X\n", command); } } @@ -29,12 +32,23 @@ void CFGService::getConfigInfoBlk2(u32 messagePointer) { u32 output = mem.read32(messagePointer + 16); // Pointer to write the output data to log("CFG::GetConfigInfoBlk2 (size = %X, block ID = %X, output pointer = %08X\n", size, blockID, output); - // Implement checking the sound output mode - if (size == 1 && blockID == 0x70001) { - mem.write8(output, (u8) DSPService::SoundOutputMode::Stereo); + // TODO: Make this not bad + if (size == 1 && blockID == 0x70001) { // Sound output mode + mem.write8(output, static_cast(DSPService::SoundOutputMode::Stereo)); + } else if (size == 1 && blockID == 0xA0002){ // System language + mem.write8(output, static_cast(LanguageCodes::English)); + } else if (size == 0x20 && blockID == 0x50005) { + printf("[Unimplemented] Read stereo display settings from NAND\n"); } else { Helpers::panic("Unhandled GetConfigInfoBlk2 configuration"); } mem.write32(messagePointer + 4, Result::Success); +} + +void CFGService::secureInfoGetRegion(u32 messagePointer) { + log("CFG::SecureInfoGetRegion\n"); + + mem.write32(messagePointer + 4, Result::Success); + mem.write32(messagePointer + 8, static_cast(Regions::USA)); // TODO: Detect the game region and report it } \ No newline at end of file diff --git a/src/core/services/hid.cpp b/src/core/services/hid.cpp index 8fe7697e..d8a7df74 100644 --- a/src/core/services/hid.cpp +++ b/src/core/services/hid.cpp @@ -2,7 +2,9 @@ namespace HIDCommands { enum : u32 { - GetIPCHandles = 0x000A0000 + GetIPCHandles = 0x000A0000, + EnableAccelerometer = 0x00110000, + EnableGyroscopeLow = 0x00130000 }; } @@ -15,16 +17,32 @@ namespace Result { void HIDService::reset() { sharedMem = nullptr; + accelerometerEnabled = false; + gyroEnabled = false; } void HIDService::handleSyncRequest(u32 messagePointer) { const u32 command = mem.read32(messagePointer); switch (command) { + case HIDCommands::EnableAccelerometer: enableAccelerometer(messagePointer); break; + case HIDCommands::EnableGyroscopeLow: enableGyroscopeLow(messagePointer); break; case HIDCommands::GetIPCHandles: getIPCHandles(messagePointer); break; default: Helpers::panic("HID service requested. Command: %08X\n", command); } } +void HIDService::enableAccelerometer(u32 messagePointer) { + log("HID::EnableAccelerometer\n"); + mem.write32(messagePointer + 4, Result::Success); + accelerometerEnabled = true; +} + +void HIDService::enableGyroscopeLow(u32 messagePointer) { + log("HID::EnableGyroscopeLow\n"); + mem.write32(messagePointer + 4, Result::Success); + gyroEnabled = true; +} + void HIDService::getIPCHandles(u32 messagePointer) { log("HID::GetIPCHandles\n"); mem.write32(messagePointer + 4, Result::Success); // Result code