aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/sci/event.cpp173
1 files changed, 48 insertions, 125 deletions
diff --git a/engines/sci/event.cpp b/engines/sci/event.cpp
index 7e0de85e60..0c17db6028 100644
--- a/engines/sci/event.cpp
+++ b/engines/sci/event.cpp
@@ -66,10 +66,10 @@ struct ScancodeRow {
const char *keys;
};
-static const ScancodeRow s_scancodeRows[] = {
- {0x10, "QWERTYUIOP[]"},
- {0x1e, "ASDFGHJKL;'\\"},
- {0x2c, "ZXCVBNM,./"}
+const ScancodeRow s_scancodeRows[] = {
+ { 0x10, "QWERTYUIOP[]" },
+ { 0x1e, "ASDFGHJKL;'\\" },
+ { 0x2c, "ZXCVBNM,./" }
};
static int altify(int ch) {
@@ -93,38 +93,7 @@ static int altify(int ch) {
return ch;
}
-/*
-static int numlockify(int c) {
- switch (c) {
- case SCI_KEY_DELETE:
- return '.';
- case SCI_KEY_INSERT:
- return '0';
- case SCI_KEY_END:
- return '1';
- case SCI_KEY_DOWN:
- return '2';
- case SCI_KEY_PGDOWN:
- return '3';
- case SCI_KEY_LEFT:
- return '4';
- case SCI_KEY_CENTER:
- return '5';
- case SCI_KEY_RIGHT:
- return '6';
- case SCI_KEY_HOME:
- return '7';
- case SCI_KEY_UP:
- return '8';
- case SCI_KEY_PGUP:
- return '9';
- default:
- return c; // Unchanged
- }
-}
-*/
-
-static const byte codepagemap_88591toDOS[0x80] = {
+const byte codepagemap_88591toDOS[0x80] = {
'?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', // 0x8x
'?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', // 0x9x
'?', 0xad, 0x9b, 0x9c, '?', 0x9d, '?', 0x9e, '?', '?', 0xa6, 0xae, 0xaa, '?', '?', '?', // 0xAx
@@ -135,6 +104,42 @@ static const byte codepagemap_88591toDOS[0x80] = {
'?', 0xa4, 0x95, 0xa2, 0x93, '?', 0x94, '?', '?', 0x97, 0xa3, 0x96, 0x81, '?', '?', 0x98 // 0xFx
};
+struct SciKeyConversion {
+ Common::KeyCode scummVMKey;
+ int sciKeyNumlockOff;
+ int sciKeyNumlockOn;
+};
+
+const SciKeyConversion keyMappings[] = {
+ { Common::KEYCODE_UP , SCI_KEY_UP , SCI_KEY_UP },
+ { Common::KEYCODE_DOWN , SCI_KEY_DOWN , SCI_KEY_DOWN },
+ { Common::KEYCODE_RIGHT , SCI_KEY_RIGHT , SCI_KEY_RIGHT },
+ { Common::KEYCODE_LEFT , SCI_KEY_LEFT , SCI_KEY_LEFT },
+ { Common::KEYCODE_INSERT , SCI_KEY_INSERT , SCI_KEY_INSERT },
+ { Common::KEYCODE_HOME , SCI_KEY_HOME , SCI_KEY_HOME },
+ { Common::KEYCODE_END , SCI_KEY_END , SCI_KEY_END },
+ { Common::KEYCODE_PAGEUP , SCI_KEY_PGUP , SCI_KEY_PGUP },
+ { Common::KEYCODE_PAGEDOWN , SCI_KEY_PGDOWN , SCI_KEY_PGDOWN },
+ { Common::KEYCODE_DELETE , SCI_KEY_DELETE , SCI_KEY_DELETE },
+ // Keypad
+ { Common::KEYCODE_KP0 , SCI_KEY_INSERT , '0' },
+ { Common::KEYCODE_KP1 , SCI_KEY_END , '1' },
+ { Common::KEYCODE_KP2 , SCI_KEY_DOWN , '2' },
+ { Common::KEYCODE_KP3 , SCI_KEY_PGDOWN , '3' },
+ { Common::KEYCODE_KP4 , SCI_KEY_LEFT , '4' },
+ { Common::KEYCODE_KP5 , SCI_KEY_CENTER , '5' },
+ { Common::KEYCODE_KP6 , SCI_KEY_RIGHT , '6' },
+ { Common::KEYCODE_KP7 , SCI_KEY_HOME , '7' },
+ { Common::KEYCODE_KP8 , SCI_KEY_UP , '8' },
+ { Common::KEYCODE_KP9 , SCI_KEY_PGUP , '9' },
+ { Common::KEYCODE_KP_PERIOD , SCI_KEY_DELETE , '.' },
+ { Common::KEYCODE_KP_ENTER , SCI_KEY_ENTER , SCI_KEY_ENTER },
+ { Common::KEYCODE_KP_PLUS , '+' , '+' },
+ { Common::KEYCODE_KP_MINUS , '-' , '-' },
+ { Common::KEYCODE_KP_MULTIPLY , '*' , '*' },
+ { Common::KEYCODE_KP_DIVIDE , '/' , '/' },
+};
+
SciEvent EventManager::getScummVMEvent() {
SciEvent input = { SCI_EVENT_NONE, 0, 0, 0 };
@@ -151,6 +156,7 @@ SciEvent EventManager::getScummVMEvent() {
if (found && ev.type != Common::EVENT_MOUSEMOVE) {
int modifiers = em->getModifierState();
+ bool numlockOn = (ev.kbd.flags & Common::KBD_NUM);
// We add the modifier key status to buckybits
//TODO: SCI_EVM_INSERT
@@ -159,7 +165,6 @@ SciEvent EventManager::getScummVMEvent() {
((modifiers & Common::KBD_ALT) ? SCI_KEYMOD_ALT : 0) |
((modifiers & Common::KBD_CTRL) ? SCI_KEYMOD_CTRL : 0) |
((modifiers & Common::KBD_SHIFT) ? SCI_KEYMOD_LSHIFT | SCI_KEYMOD_RSHIFT : 0) |
- ((ev.kbd.flags & Common::KBD_NUM) ? SCI_KEYMOD_NUMLOCK : 0) |
((ev.kbd.flags & Common::KBD_CAPS) ? SCI_KEYMOD_CAPSLOCK : 0) |
((ev.kbd.flags & Common::KBD_SCRL) ? SCI_KEYMOD_SCRLOCK : 0) |
_modifierStates;
@@ -200,10 +205,7 @@ SciEvent EventManager::getScummVMEvent() {
input.modifiers = 0;
return input;
}
- // we get 8859-1 character, we need dos (cp850/437) character for multilingual sci01 games
- // TODO: check, if we get 8859-1 on all platforms
- // Currently checked: Windows XP (works), Wii w/ USB keyboard (works), Mac OS X (works)
- // Ubuntu (works)
+ // We get a 8859-1 character, we need dos (cp850/437) character for multilingual sci01 games
input.character = codepagemap_88591toDOS[input.character & 0x7f];
}
if (input.data == Common::KEYCODE_TAB) {
@@ -230,88 +232,14 @@ SciEvent EventManager::getScummVMEvent() {
input.character = input.data + 0x1900;
else
input.character = input.data;
- // Remove modifier status (e.g. num lock) in this case
- input.modifiers = 0;
} else {
// Special keys that need conversion
input.type = SCI_EVENT_KEYBOARD;
- switch (ev.kbd.keycode) {
- case Common::KEYCODE_UP:
- input.data = SCI_KEY_UP;
- break;
- case Common::KEYCODE_DOWN:
- input.data = SCI_KEY_DOWN;
- break;
- case Common::KEYCODE_RIGHT:
- input.data = SCI_KEY_RIGHT;
- break;
- case Common::KEYCODE_LEFT:
- input.data = SCI_KEY_LEFT;
- break;
- case Common::KEYCODE_INSERT:
- input.data = SCI_KEY_INSERT;
- break;
- case Common::KEYCODE_HOME:
- input.data = SCI_KEY_HOME;
- break;
- case Common::KEYCODE_END:
- input.data = SCI_KEY_END;
- break;
- case Common::KEYCODE_PAGEUP:
- input.data = SCI_KEY_PGUP;
- break;
- case Common::KEYCODE_PAGEDOWN:
- input.data = SCI_KEY_PGDOWN;
- break;
- case Common::KEYCODE_DELETE:
- input.data = SCI_KEY_DELETE;
- break;
- // Keypad keys
- case Common::KEYCODE_KP8: // up
- if (!(_modifierStates & SCI_KEYMOD_NUMLOCK))
- input.data = SCI_KEY_UP;
- break;
- case Common::KEYCODE_KP2: // down
- if (!(_modifierStates & SCI_KEYMOD_NUMLOCK))
- input.data = SCI_KEY_DOWN;
- break;
- case Common::KEYCODE_KP6: // right
- if (!(_modifierStates & SCI_KEYMOD_NUMLOCK))
- input.data = SCI_KEY_RIGHT;
- break;
- case Common::KEYCODE_KP4: // left
- if (!(_modifierStates & SCI_KEYMOD_NUMLOCK))
- input.data = SCI_KEY_LEFT;
- break;
- case Common::KEYCODE_KP5: // center
- if (!(_modifierStates & SCI_KEYMOD_NUMLOCK))
- input.data = SCI_KEY_CENTER;
- break;
- case Common::KEYCODE_KP7: // home
- if (!(_modifierStates & SCI_KEYMOD_NUMLOCK))
- input.data = SCI_KEY_HOME;
- break;
- case Common::KEYCODE_KP9: // pageup
- if (!(_modifierStates & SCI_KEYMOD_NUMLOCK))
- input.data = SCI_KEY_PGUP;
- break;
- case Common::KEYCODE_KP1: // end
- if (!(_modifierStates & SCI_KEYMOD_NUMLOCK))
- input.data = SCI_KEY_END;
- break;
- case Common::KEYCODE_KP3: // pagedown
- if (!(_modifierStates & SCI_KEYMOD_NUMLOCK))
- input.data = SCI_KEY_PGDOWN;
- break;
- case Common::KEYCODE_KP_PLUS: // +
- input.data = '+';
- break;
- case Common::KEYCODE_KP_MINUS: // -
- input.data = '-';
- break;
- default:
- input.type = SCI_EVENT_NONE;
- break;
+ for (int i = 0; i < ARRAYSIZE(keyMappings); i++) {
+ if (keyMappings[i].scummVMKey == ev.kbd.keycode) {
+ input.data = numlockOn ? keyMappings[i].sciKeyNumlockOn : keyMappings[i].sciKeyNumlockOff;
+ break;
+ }
}
input.character = input.data;
}
@@ -427,11 +355,6 @@ SciEvent EventManager::getSciEvent(unsigned int mask) {
event.character += 96; // 0x01 -> 'a'
}
}
-
- // Numlockify if appropriate
- //if (event.modifiers & SCI_KEYMOD_NUMLOCK)
- // event.data = numlockify(event.data);
- // TODO: dont know yet if this can get dumped as well
}
return event;