From fba5faa5eec7b33be6ea1b0a83f77e04f83fd11a Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 6 Dec 2023 23:39:44 +1100 Subject: [PATCH] PS3: WIP on keyboard support --- misc/ps3/Makefile | 3 ++ src/Platform_3DS.c | 1 + src/Platform_PS2.c | 2 +- src/Platform_PSVita.c | 4 +-- src/Window_PS3.c | 64 ++++++++++++++++++++++++++++++++++++------- 5 files changed, 61 insertions(+), 13 deletions(-) diff --git a/misc/ps3/Makefile b/misc/ps3/Makefile index ba8bfa2e7..b37d83967 100644 --- a/misc/ps3/Makefile +++ b/misc/ps3/Makefile @@ -6,6 +6,9 @@ ifeq ($(strip $(PS3DEV)),) $(error "Please set PS3DEV in your environment. export PS3DEV=") endif +ifeq ($(strip $(PSL1GHT)),) +$(error "Please set PSL1GHT in your environment. export PSL1GHT=") +endif include $(PS3DEV)/ppu_rules diff --git a/src/Platform_3DS.c b/src/Platform_3DS.c index 177ae9d82..7b6dd9100 100644 --- a/src/Platform_3DS.c +++ b/src/Platform_3DS.c @@ -288,6 +288,7 @@ void Waitable_WaitFor(void* handle, cc_uint32 milliseconds) { union SocketAddress { struct sockaddr raw; struct sockaddr_in v4; + struct sockaddr_storage total; // matches max size of addr returned by getaddrinfo }; static int ParseHost(union SocketAddress* addr, const char* host) { diff --git a/src/Platform_PS2.c b/src/Platform_PS2.c index dd69f39d3..a28823a7d 100644 --- a/src/Platform_PS2.c +++ b/src/Platform_PS2.c @@ -463,7 +463,7 @@ static void Networking_LoadIOPModules(void) { union SocketAddress { struct sockaddr raw; struct sockaddr_in v4; - struct sockaddr_storage total; // matches size of addr returned by getaddrinfo + struct sockaddr_storage total; // matches max size of addr returned by getaddrinfo }; static int ParseHost(union SocketAddress* addr, const char* host) { diff --git a/src/Platform_PSVita.c b/src/Platform_PSVita.c index 76a07db1d..e7e031302 100644 --- a/src/Platform_PSVita.c +++ b/src/Platform_PSVita.c @@ -393,8 +393,8 @@ static void InitNetworking(void) { SceNetInitParam param; param.memory = net_memory; - param.size = sizeof(net_memory); - param.flags = 0; + param.size = sizeof(net_memory); + param.flags = 0; int ret = sceNetInit(¶m); if (ret < 0) Platform_Log1("Network init failed: %i", &ret); diff --git a/src/Window_PS3.c b/src/Window_PS3.c index 2dcc176a1..1ac4be422 100644 --- a/src/Window_PS3.c +++ b/src/Window_PS3.c @@ -17,10 +17,11 @@ #include static cc_bool launcherMode; -static padInfo pad_info; -static padData pad_data; -static KbInfo kb_info; -static KbData kb_data; +static padInfo pad_info; +static padData pad_data; +static KbInfo kb_info; +static KbData kb_data; +static KbConfig kb_config; struct _DisplayData DisplayInfo; struct _WinData WindowInfo; @@ -62,7 +63,8 @@ void Window_Init(void) { DisplayInfo.ContentOffsetY = 10; ioPadInit(MAX_PORT_NUM); - //ioKbInit(MAX_KB_PORT_NUM); + ioKbInit(MAX_KB_PORT_NUM); + ioKbGetConfiguration(0, &kb_config); } void Window_Create2D(int width, int height) { @@ -91,6 +93,41 @@ void Window_Close(void) { } +/*########################################################################################################################* +*--------------------------------------------------Keyboard processing----------------------------------------------------* +*#########################################################################################################################*/ +static KbMkey old_mods; +#define ToggleMod(field, btn) if (diff._KbMkeyU._KbMkeyS. field) Input_Set(btn, mods->_KbMkeyU._KbMkeyS. field); +static void ProcessKBModifiers(KbMkey* mods) { + KbMkey diff; + diff._KbMkeyU.mkeys = mods->_KbMkeyU.mkeys ^ old_mods._KbMkeyU.mkeys; + + ToggleMod(l_alt, CCKEY_LALT); + ToggleMod(r_alt, CCKEY_RALT); + ToggleMod(l_ctrl, CCKEY_LCTRL); + ToggleMod(r_ctrl, CCKEY_RCTRL); + ToggleMod(l_shift, CCKEY_LSHIFT); + ToggleMod(r_shift, CCKEY_RSHIFT); + ToggleMod(l_win, CCKEY_LWIN); + ToggleMod(r_win, CCKEY_RWIN); + + old_mods = *mods; +} +// TODO ProcessKBButtons() +// TODO: Call at init ioKbSetCodeType(0, KB_CODETYPE_RAW); ioKbSetReadMode(0, KB_RMODE_INPUTCHAR); +static void ProcessKBTextInput(void) { + for (int i = 0; i < kb_data.nb_keycode; i++) + { + int rawcode = kb_data.keycode[i]; + if (!rawcode) continue; + int unicode = ioKbCnvRawCode(kb_config.mapping, kb_data.mkey, kb_data.led, rawcode); + + char C = unicode; + //Platform_Log4("%i --> %i / %h / %r", &rawcode, &unicode, &unicode, &C); + } +} + + /*########################################################################################################################* *----------------------------------------------------Input processing-----------------------------------------------------* *#########################################################################################################################*/ @@ -114,6 +151,7 @@ static void HandleButtons(padData* data) { Input_SetNonRepeatable(CCPAD_ZL, data->BTN_L2); Input_SetNonRepeatable(CCPAD_ZR, data->BTN_R2); } + static void HandleJoystick_Left(int x, int y) { if (Math_AbsI(x) <= 32) x = 0; if (Math_AbsI(y) <= 32) y = 0; @@ -122,6 +160,7 @@ static void HandleJoystick_Left(int x, int y) { Input.JoystickMovement = true; Input.JoystickAngle = Math_Atan2(x, -y); } + static void HandleJoystick_Right(int x, int y, double delta) { float scale = (delta * 60.0) / 64.0f; @@ -137,6 +176,7 @@ static void ProcessPadInput(double delta, padData* pad) { HandleJoystick_Right(pad->ANA_R_H - 0x80, pad->ANA_R_V - 0x80, delta); } + void Window_ProcessEvents(double delta) { Input.JoystickMovement = false; @@ -146,11 +186,15 @@ void Window_ProcessEvents(double delta) { ProcessPadInput(delta, &pad_data); } - //ioKbGetInfo(&kb_info); - //if (kb_info.status[0]) { - // int RES = ioKbRead(0, &kb_data); - // Platform_Log1("RES: %i", &RES); - //} + // TODO set InputSource keyboard + ioKbGetInfo(&kb_info); + if (kb_info.status[0]) { + int res = ioKbRead(0, &kb_data); + if (res == 0 && kb_data.nb_keycode > 0) { + ProcessKBModifiers(&kb_data.mkey); + ProcessKBTextInput(); + } + } } void Cursor_SetPosition(int x, int y) { } // Makes no sense for PS Vita