cleanup wii usb keyboard a little - really needs to use inputcommon or something...

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4597 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Shawn Hoffman 2009-11-21 10:25:27 +00:00
parent 6e7395cef1
commit 32c74c6481
9 changed files with 233 additions and 313 deletions

View File

@ -2095,19 +2095,11 @@
Name="Keyboard"
>
<File
RelativePath=".\Src\IPC_HLE\WII_IPC_HLE_Device_Usb_Kbd_apple.h"
RelativePath=".\Src\IPC_HLE\WII_IPC_HLE_Device_usb_kbd.cpp"
>
</File>
<File
RelativePath=".\Src\IPC_HLE\WII_IPC_HLE_Device_Usb_Kbd_linux.h"
>
</File>
<File
RelativePath=".\Src\IPC_HLE\WII_IPC_HLE_Device_Usb_Kbd_win32.h"
>
</File>
<File
RelativePath=".\Src\IPC_HLE\WII_IPC_HLE_Usb_Kbd.cpp"
RelativePath=".\Src\IPC_HLE\WII_IPC_HLE_Device_usb_kbd.h"
>
</File>
</Filter>

View File

@ -55,6 +55,7 @@
#include "WII_IPC_HLE_Device_net.h"
#include "WII_IPC_HLE_Device_es.h"
#include "WII_IPC_HLE_Device_usb.h"
#include "WII_IPC_HLE_Device_usb_kbd.h"
#include "WII_IPC_HLE_Device_sdio_slot0.h"
#include "FileUtil.h" // For Copy

View File

@ -1,24 +0,0 @@
// Copyright (C) 2003 Dolphin Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
u8 CWII_IPC_HLE_Device_usb_kbd::m_KeyCodesQWERTY[256] = {
//Add support for apple keycodes
};
u8 CWII_IPC_HLE_Device_usb_kbd::m_KeyCodesAZERTY[256] = {
//Add support for apple keycodes
};

View File

@ -1,25 +0,0 @@
// Copyright (C) 2003 Dolphin Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
u8 CWII_IPC_HLE_Device_usb_kbd::m_KeyCodesQWERTY[256] = {
//Add support for Linux keycodes
};
u8 CWII_IPC_HLE_Device_usb_kbd::m_KeyCodesAZERTY[256] = {
//Add support for Linux keycodes
};

View File

@ -235,61 +235,5 @@ public:
// virtual u32 Update();
};
class CWII_IPC_HLE_Device_usb_kbd : public IWII_IPC_HLE_Device
{
public:
CWII_IPC_HLE_Device_usb_kbd(u32 _DeviceID, const std::string& _rDeviceName);
virtual ~CWII_IPC_HLE_Device_usb_kbd();
virtual bool Open(u32 _CommandAddress, u32 _Mode);
virtual bool IOCtl(u32 _CommandAddress);
virtual u32 Update();
private:
static u8 m_KeyCodesQWERTY[256];
static u8 m_KeyCodesAZERTY[256];
enum
{
KBD_LAYOUT_QWERTY = 0,
KBD_LAYOUT_AZERTY
};
int m_KeyboardLayout;
enum
{
MSG_KBD_CONNECT = 0,
MSG_KBD_DISCONNECT,
MSG_EVENT
};
// This struct is designed to be directly writeable to memory
// without any translation
struct SMessageData
{
u32 dwMessage;
u32 dwUnk1;
u8 bModifiers;
u8 bUnk2;
u8 bPressedKeys[6];
};
std::queue<SMessageData> m_MessageQueue;
bool m_OldKeyBuffer[256];
u8 m_OldModifiers;
virtual bool IsKeyPressed(int _Key);
virtual void PushMessage(u32 _Message, u8 _Modifiers, u8 * _PressedKeys);
virtual void WriteMessage(u32 _Address, SMessageData _Message);
};
#endif

View File

@ -15,6 +15,152 @@
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#include "../Core.h" // Local core functions
#include "WII_IPC_HLE_Device_usb.h"
#include "WII_IPC_HLE_Device_usb_kbd.h"
CWII_IPC_HLE_Device_usb_kbd::CWII_IPC_HLE_Device_usb_kbd(u32 _DeviceID, const std::string& _rDeviceName)
: IWII_IPC_HLE_Device(_DeviceID, _rDeviceName)
{}
CWII_IPC_HLE_Device_usb_kbd::~CWII_IPC_HLE_Device_usb_kbd()
{}
bool CWII_IPC_HLE_Device_usb_kbd::Open(u32 _CommandAddress, u32 _Mode)
{
Memory::Write_U32(GetDeviceID(), _CommandAddress+4);
IniFile ini;
ini.Load(CONFIG_FILE);
ini.Get("USB Keyboard", "Layout", &m_KeyboardLayout, KBD_LAYOUT_QWERTY);
for(int i = 0; i < 256; i++)
m_OldKeyBuffer[i] = false;
m_OldModifiers = 0x00;
m_MessageQueue.push(SMessageData(MSG_KBD_CONNECT, 0, NULL));
return true;
}
bool CWII_IPC_HLE_Device_usb_kbd::Write(u32 _CommandAddress)
{
WARN_LOG(WII_IPC_STM, "Ignoring write to CWII_IPC_HLE_Device_usb_kbd");
DumpCommands(_CommandAddress, 10, LogTypes::WII_IPC_STM, LogTypes::LDEBUG);
return true;
}
bool CWII_IPC_HLE_Device_usb_kbd::IOCtl(u32 _CommandAddress)
{
u32 Parameter = Memory::Read_U32(_CommandAddress + 0x0C);
u32 BufferIn = Memory::Read_U32(_CommandAddress + 0x10);
u32 BufferInSize = Memory::Read_U32(_CommandAddress + 0x14);
u32 BufferOut = Memory::Read_U32(_CommandAddress + 0x18);
u32 BufferOutSize = Memory::Read_U32(_CommandAddress + 0x1C);
if (!m_MessageQueue.empty())
{
*(SMessageData*)Memory::GetPointer(BufferOut) = m_MessageQueue.front();
m_MessageQueue.pop();
}
Memory::Write_U32(0, _CommandAddress + 0x4);
return true;
}
bool CWII_IPC_HLE_Device_usb_kbd::IsKeyPressed(int _Key)
{
#ifdef _WIN32
if (GetAsyncKeyState(_Key) & 0x8000)
return true;
else
return false;
#else
// TODO: do it for non-Windows platforms
return false;
#endif
}
u32 CWII_IPC_HLE_Device_usb_kbd::Update()
{
u8 Modifiers = 0x00;
u8 PressedKeys[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
bool GotEvent = false;
int num_pressed_keys = 0;
for (int i = 0; i < 256; i++)
{
bool KeyPressedNow = IsKeyPressed(i);
bool KeyPressedBefore = m_OldKeyBuffer[i];
u8 KeyCode = 0;
if (KeyPressedNow ^ KeyPressedBefore)
{
if (KeyPressedNow)
{
switch (m_KeyboardLayout)
{
case KBD_LAYOUT_QWERTY:
KeyCode = m_KeyCodesQWERTY[i];
break;
case KBD_LAYOUT_AZERTY:
KeyCode = m_KeyCodesAZERTY[i];
break;
}
if (KeyCode == 0x00)
continue;
PressedKeys[num_pressed_keys] = KeyCode;
num_pressed_keys++;
if (num_pressed_keys == 6)
break;
}
GotEvent = true;
}
m_OldKeyBuffer[i] = KeyPressedNow;
}
#ifdef _WIN32
if (GetAsyncKeyState(VK_LCONTROL) & 0x8000)
Modifiers |= 0x01;
if (GetAsyncKeyState(VK_LSHIFT) & 0x8000)
Modifiers |= 0x02;
if (GetAsyncKeyState(VK_MENU) & 0x8000)
Modifiers |= 0x04;
if (GetAsyncKeyState(VK_LWIN) & 0x8000)
Modifiers |= 0x08;
if (GetAsyncKeyState(VK_RCONTROL) & 0x8000)
Modifiers |= 0x10;
if (GetAsyncKeyState(VK_RSHIFT) & 0x8000)
Modifiers |= 0x20;
if (GetAsyncKeyState(VK_MENU) & 0x8000) // TODO: VK_MENU is for ALT, not for ALT GR (ALT GR seems to work though...)
Modifiers |= 0x40;
if (GetAsyncKeyState(VK_RWIN) & 0x8000)
Modifiers |= 0x80;
#else
// TODO: modifiers for non-Windows platforms
#endif
if (Modifiers ^ m_OldModifiers)
{
GotEvent = true;
m_OldModifiers = Modifiers;
}
if (GotEvent)
m_MessageQueue.push(SMessageData(MSG_EVENT, Modifiers, PressedKeys));
return 0;
}
// Crazy ugly
#ifdef _WIN32
u8 CWII_IPC_HLE_Device_usb_kbd::m_KeyCodesQWERTY[256] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -189,4 +335,23 @@ u8 CWII_IPC_HLE_Device_usb_kbd::m_KeyCodesAZERTY[256] = {
0x38, // '!'
0x00, // Nothing interesting past this point.
};
};
#elif defined __linux__
// TODO Add support for Linux keycodes
u8 CWII_IPC_HLE_Device_usb_kbd::m_KeyCodesQWERTY[256] = {
0
};
u8 m_KeyCodesAZERTY[256] = {
0
};
#elif defined __APPLE__
// TODO Add support for Apple keycodes
u8 CWII_IPC_HLE_Device_usb_kbd::m_KeyCodesQWERTY[256] = {
0
};
u8 CWII_IPC_HLE_Device_usb_kbd::m_KeyCodesAZERTY[256] = {
0
};
#endif

View File

@ -0,0 +1,63 @@
#ifndef _WII_IPC_HLE_DEVICE_USB_KBD_H_
#define _WII_IPC_HLE_DEVICE_USB_KBD_H_
class CWII_IPC_HLE_Device_usb_kbd : public IWII_IPC_HLE_Device
{
public:
CWII_IPC_HLE_Device_usb_kbd(u32 _DeviceID, const std::string& _rDeviceName);
virtual ~CWII_IPC_HLE_Device_usb_kbd();
virtual bool Open(u32 _CommandAddress, u32 _Mode);
virtual bool Write(u32 _CommandAddress);
virtual bool IOCtl(u32 _CommandAddress);
virtual u32 Update();
private:
enum
{
MSG_KBD_CONNECT = 0,
MSG_KBD_DISCONNECT,
MSG_EVENT
};
#pragma pack(push, 1)
struct SMessageData
{
u32 MsgType;
u32 Unk1;
u8 Modifiers;
u8 Unk2;
u8 PressedKeys[6];
SMessageData(u32 _MsgType, u8 _Modifiers, u8 *_PressedKeys) {
MsgType = Common::swap32(_MsgType);
Unk1 = 0; // swapped
Modifiers = _Modifiers;
Unk2 = 0;
if (_PressedKeys) // Doesn't need to be in a specific order
memcpy(PressedKeys, _PressedKeys, sizeof(PressedKeys));
else
memset(PressedKeys, 0, sizeof(PressedKeys));
}
};
#pragma pack(pop)
std::queue<SMessageData> m_MessageQueue;
bool m_OldKeyBuffer[256];
u8 m_OldModifiers;
virtual bool IsKeyPressed(int _Key);
// This stuff should probably die
enum
{
KBD_LAYOUT_QWERTY = 0,
KBD_LAYOUT_AZERTY
};
int m_KeyboardLayout;
static u8 m_KeyCodesQWERTY[256];
static u8 m_KeyCodesAZERTY[256];
};
#endif // _WII_IPC_HLE_DEVICE_USB_KBD_H_

View File

@ -1,196 +0,0 @@
// Copyright (C) 2003 Dolphin Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#include "../Core.h" // Local core functions
#include "WII_IPC_HLE_Device_usb.h"
#ifdef _WIN32
#include "WII_IPC_HLE_Device_Usb_Kbd_win32.h"
#endif
#ifdef __linux__
#include "WII_IPC_HLE_Device_Usb_Kbd_linux.h"
#endif
#ifdef __APPLE__
#include "WII_IPC_HLE_Device_Usb_Kbd_apple.h"
#endif
CWII_IPC_HLE_Device_usb_kbd::CWII_IPC_HLE_Device_usb_kbd(u32 _DeviceID, const std::string& _rDeviceName)
: IWII_IPC_HLE_Device(_DeviceID, _rDeviceName)
{
}
CWII_IPC_HLE_Device_usb_kbd::~CWII_IPC_HLE_Device_usb_kbd()
{}
bool CWII_IPC_HLE_Device_usb_kbd::Open(u32 _CommandAddress, u32 _Mode)
{
Memory::Write_U32(GetDeviceID(), _CommandAddress+4);
IniFile ini;
ini.Load(CONFIG_FILE);
ini.Get("USB Keyboard", "Layout", &m_KeyboardLayout, KBD_LAYOUT_QWERTY);
for(int i = 0; i < 256; i++)
m_OldKeyBuffer[i] = false;
m_OldModifiers = 0x00;
PushMessage(MSG_KBD_CONNECT, 0x00, NULL);
return true;
}
bool CWII_IPC_HLE_Device_usb_kbd::IOCtl(u32 _CommandAddress)
{
u32 Parameter = Memory::Read_U32(_CommandAddress +0x0C);
u32 BufferIn = Memory::Read_U32(_CommandAddress + 0x10);
u32 BufferInSize = Memory::Read_U32(_CommandAddress + 0x14);
u32 BufferOut = Memory::Read_U32(_CommandAddress + 0x18);
u32 BufferOutSize = Memory::Read_U32(_CommandAddress + 0x1C);
if (!m_MessageQueue.empty())
{
WriteMessage(BufferOut, m_MessageQueue.front());
m_MessageQueue.pop();
}
Memory::Write_U32(0, _CommandAddress + 0x4);
return true;
}
bool CWII_IPC_HLE_Device_usb_kbd::IsKeyPressed(int _Key)
{
#ifdef _WIN32
if (GetAsyncKeyState(_Key) & 0x8000)
return true;
else
return false;
#else
// TODO: do it for non-Windows platforms
return false;
#endif
}
u32 CWII_IPC_HLE_Device_usb_kbd::Update()
{
u8 Modifiers = 0x00;
u8 PressedKeys[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
bool GotEvent = false;
int num_pressed_keys = 0;
for (int i = 0; i < 256; i++)
{
bool KeyPressedNow = IsKeyPressed(i);
bool KeyPressedBefore = m_OldKeyBuffer[i];
u8 KeyCode = 0;
if (KeyPressedNow ^ KeyPressedBefore)
{
if (KeyPressedNow)
{
switch (m_KeyboardLayout)
{
case KBD_LAYOUT_QWERTY:
KeyCode = m_KeyCodesQWERTY[i];
break;
case KBD_LAYOUT_AZERTY:
KeyCode = m_KeyCodesAZERTY[i];
break;
}
if (KeyCode == 0x00)
continue;
PressedKeys[num_pressed_keys] = KeyCode;
num_pressed_keys++;
if (num_pressed_keys == 6)
break;
}
GotEvent = true;
}
m_OldKeyBuffer[i] = KeyPressedNow;
}
#ifdef _WIN32
if (GetAsyncKeyState(VK_LCONTROL) & 0x8000)
Modifiers |= 0x01;
if (GetAsyncKeyState(VK_LSHIFT) & 0x8000)
Modifiers |= 0x02;
if (GetAsyncKeyState(VK_MENU) & 0x8000)
Modifiers |= 0x04;
if (GetAsyncKeyState(VK_LWIN) & 0x8000)
Modifiers |= 0x08;
if (GetAsyncKeyState(VK_RCONTROL) & 0x8000)
Modifiers |= 0x10;
if (GetAsyncKeyState(VK_RSHIFT) & 0x8000)
Modifiers |= 0x20;
if (GetAsyncKeyState(VK_MENU) & 0x8000) // TODO: VK_MENU is for ALT, not for ALT GR (ALT GR seems to work though...)
Modifiers |= 0x40;
if (GetAsyncKeyState(VK_RWIN) & 0x8000)
Modifiers |= 0x80;
#else
// TODO: modifiers for non-Windows platforms
#endif
if (Modifiers ^ m_OldModifiers)
{
GotEvent = true;
m_OldModifiers = Modifiers;
}
if (GotEvent)
PushMessage(MSG_EVENT, Modifiers, PressedKeys);
return 0;
}
void CWII_IPC_HLE_Device_usb_kbd::PushMessage(u32 _Message, u8 _Modifiers, u8 * _PressedKeys)
{
SMessageData MsgData;
MsgData.dwMessage = _Message;
MsgData.dwUnk1 = 0;
MsgData.bModifiers = _Modifiers;
MsgData.bUnk2 = 0;
if (_PressedKeys)
memcpy(MsgData.bPressedKeys, _PressedKeys, sizeof(MsgData.bPressedKeys));
else
memset(MsgData.bPressedKeys, 0, sizeof(MsgData.bPressedKeys));
m_MessageQueue.push(MsgData);
}
void CWII_IPC_HLE_Device_usb_kbd::WriteMessage(u32 _Address, SMessageData _Message)
{
// TODO: the MessageData struct could be written directly in memory,
// instead of writing each member separately
Memory::Write_U32(_Message.dwMessage, _Address);
Memory::Write_U32(_Message.dwUnk1, _Address + 0x4);
Memory::Write_U8(_Message.bModifiers, _Address + 0x8);
Memory::Write_U8(_Message.bUnk2, _Address + 0x9);
Memory::Write_U8(_Message.bPressedKeys[0], _Address + 0xA);
Memory::Write_U8(_Message.bPressedKeys[1], _Address + 0xB);
Memory::Write_U8(_Message.bPressedKeys[2], _Address + 0xC);
Memory::Write_U8(_Message.bPressedKeys[3], _Address + 0xD);
Memory::Write_U8(_Message.bPressedKeys[4], _Address + 0xE);
Memory::Write_U8(_Message.bPressedKeys[5], _Address + 0xF);
}

View File

@ -68,7 +68,7 @@ files = ["ActionReplay.cpp",
"IPC_HLE/WII_IPC_HLE_Device_net.cpp",
"IPC_HLE/WII_IPC_HLE_WiiMote.cpp",
"IPC_HLE/WII_IPC_HLE_Device_usb.cpp",
"IPC_HLE/WII_IPC_HLE_Usb_Kbd.cpp",
"IPC_HLE/WII_IPC_HLE_Device_usb_kbd.cpp",
"IPC_HLE/WiiMote_HID_Attr.cpp",
"PowerPC/PowerPC.cpp",
"PowerPC/PPCAnalyst.cpp",