From d4c2c3d2098616b3596b743f33fcc37629282ec0 Mon Sep 17 00:00:00 2001 From: Exzap <13877693+Exzap@users.noreply.github.com> Date: Tue, 25 Jun 2024 15:50:06 +0200 Subject: [PATCH] nsyskbd: Stub KBDGetKey Fixes MSX VC games freezing on boot --- src/Cafe/OS/libs/nsyskbd/nsyskbd.cpp | 35 ++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/Cafe/OS/libs/nsyskbd/nsyskbd.cpp b/src/Cafe/OS/libs/nsyskbd/nsyskbd.cpp index 72cb9bd0..f1571cc0 100644 --- a/src/Cafe/OS/libs/nsyskbd/nsyskbd.cpp +++ b/src/Cafe/OS/libs/nsyskbd/nsyskbd.cpp @@ -3,6 +3,11 @@ namespace nsyskbd { + bool IsValidChannel(uint32 channel) + { + return channel >= 0 && channel < 4; + } + uint32 KBDGetChannelStatus(uint32 channel, uint32be* status) { static bool loggedError = false; @@ -16,8 +21,38 @@ namespace nsyskbd return 0; } +#pragma pack(push, 1) + struct KeyState + { + uint8be channel; + uint8be ukn1; + uint8be _padding[2]; + uint32be ukn4; + uint32be ukn8; + uint16be uknC; + }; +#pragma pack(pop) + static_assert(sizeof(KeyState) == 0xE); // actual size might be padded to 0x10? + + uint32 KBDGetKey(uint32 channel, KeyState* keyState) + { + // used by MSX VC + if(!IsValidChannel(channel) || !keyState) + { + cemuLog_log(LogType::APIErrors, "KBDGetKey(): Invalid parameter"); + return 0; + } + keyState->channel = channel; + keyState->ukn1 = 0; + keyState->ukn4 = 0; + keyState->ukn8 = 0; + keyState->uknC = 0; + return 0; + } + void nsyskbd_load() { cafeExportRegister("nsyskbd", KBDGetChannelStatus, LogType::Placeholder); + cafeExportRegister("nsyskbd", KBDGetKey, LogType::Placeholder); } }