Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cellKb: implement key repeat mode #10965

Merged
merged 1 commit into from Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 19 additions & 2 deletions rpcs3/Emu/Cell/Modules/cellKb.cpp
Expand Up @@ -301,9 +301,22 @@ error_code cellKbRead(u32 port_no, vm::ptr<CellKbData> data)
data->mkey = current_data.mkey;
data->len = std::min<s32>(CELL_KB_MAX_KEYCODES, current_data.len);

for (s32 i = 0; i < current_data.len; i++)
if (current_data.len > 0)
{
data->keycode[i] = current_data.keycode[i].first;
for (s32 i = 0; i < current_data.len; i++)
{
data->keycode[i] = current_data.keycode[i].first;
}

KbConfig& current_config = handler.GetConfig(port_no);

// For single character mode to work properly we need to "flush" the buffer after reading or else we'll constantly get the same key presses with each call.
// Actual key repeats are handled by adding a new key code to the buffer periodically. Key releases are handled in a similar fashion.
// Warning: Don't do this in packet mode, which is basically the mouse and keyboard gaming mode. Otherwise games like Unreal Tournament will be unplayable.
if (current_config.read_mode == CELL_KB_RMODE_INPUTCHAR)
{
current_data.len = 0;
}
}

return CELL_OK;
Expand Down Expand Up @@ -386,6 +399,10 @@ error_code cellKbSetReadMode(u32 port_no, u32 rmode)
KbConfig& current_config = handler.GetConfig(port_no);
current_config.read_mode = rmode;

// Key repeat must be disabled in packet mode. But let's just always enable it otherwise.
Keyboard& keyboard = handler.GetKeyboards()[port_no];
keyboard.m_key_repeat = rmode != CELL_KB_RMODE_PACKET;

// can also return CELL_KB_ERROR_SYS_SETTING_FAILED

return CELL_OK;
Expand Down
2 changes: 0 additions & 2 deletions rpcs3/Emu/Io/KeyboardHandler.cpp
Expand Up @@ -42,8 +42,6 @@ void fmt_class_string<CellKbMappingType>::format(std::string& out, u64 arg)

void KeyboardHandlerBase::Key(u32 code, bool pressed)
{
// TODO: Key Repeat

std::lock_guard<std::mutex> lock(m_mutex);

for (Keyboard& keyboard : m_keyboards)
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Io/KeyboardHandler.h
Expand Up @@ -74,7 +74,7 @@ struct KbButton

struct Keyboard
{
bool m_key_repeat = false; // for future use
bool m_key_repeat = false;
KbData m_data;
KbConfig m_config;
std::vector<KbButton> m_buttons;
Expand Down