More sanity with scancodes and keycodes

* Use defines instead of magic numbers in a bunch of places
    * Remove deprecated ii_keymaps and only use iie_keymaps
    * Allow keypad corners for emulated joystick
This commit is contained in:
Aaron Culliney 2013-12-29 18:07:24 -08:00
parent d2215b0f0b
commit 4ada3d7319
6 changed files with 246 additions and 229 deletions

View File

@ -68,9 +68,6 @@ static void pad_string(char *s, const char c, const int len) {
*p = '\0';
}
/* in keys.c */
//extern void c_mouse_close();
/* -------------------------------------------------------------------------
c_load_interface_font()
------------------------------------------------------------------------- */
@ -547,7 +544,7 @@ void c_interface_select_diskette( int drive )
curpos--;
}
}
else if (ch == kDOWN)
else if (ch == kDN)
{
if (curpos < entries - 1)
{
@ -968,7 +965,7 @@ void c_interface_parameters()
}
}
}
else if (ch == kDOWN) /* Arrow down */
else if (ch == kDN) /* Arrow down */
{
++option;
@ -982,7 +979,7 @@ void c_interface_parameters()
cur_y = option = 0; /* wrap both to first */
}
}
else if ((ch == kLEFT) && (c_rawkey() != SCODE_BS)) /* Arrow left */
else if ((ch == kLT) && (c_rawkey() != SCODE_BS)) /* Arrow left */
{
switch (option)
{
@ -1072,7 +1069,7 @@ void c_interface_parameters()
break;
}
}
else if (ch == kRIGHT) /* Arrow right */
else if (ch == kRT) /* Arrow right */
{
switch (option)
{
@ -1459,7 +1456,7 @@ void c_interface_credits()
pos = 0;
}
}
else if (ch == kDOWN)
else if (ch == kDN)
{
++pos;
if (pos >= SCROLL_LENGTH-SCROLL_AREA_HEIGHT)

View File

@ -37,6 +37,7 @@ short joy_x = HALF_JOY_RANGE;
short joy_y = HALF_JOY_RANGE;
unsigned char joy_button0 = 0;
unsigned char joy_button1 = 0;
unsigned char joy_button2 = 0; // unused?
#ifdef KEYPAD_JOYSTICK
short joy_step = 1;
@ -493,3 +494,14 @@ void c_calibrate_joystick()
#endif
}
void c_joystick_reset()
{
#ifdef KEYPAD_JOYSTICK
if (joy_mode == JOY_KPAD)
{
joy_x = HALF_JOY_RANGE;
joy_y = HALF_JOY_RANGE;
}
#endif
}

View File

@ -25,5 +25,6 @@
void c_open_joystick();
void c_close_joystick();
void c_calibrate_joystick();
void c_joystick_reset();
#endif // whole file

View File

@ -55,159 +55,104 @@ static int last_scancode = -1;
static char caps_lock = 1; /* is enabled */
static bool in_interface = false;
/* ----------------------------------------------------
Keymap. Mapping scancodes to Apple II+ US Keyboard
---------------------------------------------------- */
static int apple_ii_keymap_plain[128] =
{ -1, 27, '1', '2', '3', '4', '5', '6', /* 00-07 */
'7', '8', '9', '0', ':', '-', 8, 27, /* 08-15 */
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', /* 16-23 */
'O', 'P', -1, 8, 13, -1, 'A', 'S', /* 24-31 */
'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', /* 32-39 */
8, -1, -1, 21, 'Z', 'X', 'C', 'V', /* 40-47 */
'B', 'N', 'M', ',', '.', '/', -1, -1, /* 48-55 */
JB0, ' ', -1, kF1, kF2, kF3, kF4, kF5, /* 56-63 */
kF6, kF7, kF8, kF9, kF10, -1, -1, JUL, /* 64-71 */
J_U, JUR, S_D, J_L, J_C, J_R, S_I, JDL, /* 72-79 */
J_D, JDR, -1, -1, -1, kF11, kF12, -1, /* 80-87 */
-1, -1, -1, -1, -1, -1, -1, -1, /* 88-95 */
-1, -1, -1, -1, JB1, -1, kHOME, -1, /* 96-103 */
kPGUP, 8, 21, kEND, -1, kPGDN, JB2, -1, /* 104-111 */
-1, -1, -1, -1, -1, -1, -1, kPAUSE, /* 112-119 */
-1, -1, -1, -1, -1, -1, -1, -1 }; /* 120-127 */
static int apple_ii_keymap_ctrl[128] =
{ -1, 027, '1', '2', '3', '4', '5', '6', /* 00-07 */
'7', '8', '9', '0', ':', '-', 8, 27, /* 08-15 */
17, 23, 5, 18, 20, 25, 21, 9, /* 16-23 */
15, 16, -1, 8, 13, -1, 1, 19, /* 24-31 */
4, 6, 7, 8, 10, 11, 12, ';', /* 32-39 */
8, -1, -1, 21, 26, 24, 3, 22, /* 40-47 */
2, 14, 13, ',', '.', '/', -1, -1, /* 48-55 */
JB0, ' ', -1, kF1, kF2, kF3, kF4, kF5, /* 56-63 */
kF6, kF7, kF8, kF9, kF10, -1, -1, JUL, /* 64-71 */
J_U, JUR, S_D, J_L, J_C, J_R, S_I, JDL, /* 72-79 */
J_D, JDR, -1, -1, -1, kF11, kF12, -1, /* 80-87 */
-1, -1, -1, -1, -1, -1, -1, -1, /* 88-95 */
-1, -1, -1, -1, JB1, -1, kHOME, -1, /* 96-103 */
kPGUP, 8, 21, kEND, -1, kPGDN, JB2, -1, /* 104-111 */
-1, -1, -1, -1, -1, -1, -1, kPAUSE, /* 112-119 */
-1, -1, -1, -1, -1, -1, -1, -1 }; /* 120-127 */
static int apple_ii_keymap_shifted[128] =
{ -1, 27, '!', '"', '#', '$', '%', '&', /* 00-07 */
39, '(', ')', '0', '*', '=', 8, 27, /* 08-15 */
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', /* 16-23 */
'O', '@', -1, 8, 13, -1, 'A', 'S', /* 24-31 */
'D', 'F', 'G', 'H', 'J', 'K', 'L', '+', /* 32-39 */
8, -1, -1, 21, 'Z', 'X', 'C', 'V', /* 40-47 */
'B', '^', 'M', '<', '>', '?', -1, -1, /* 48-55 */
JB0, ' ', -1, kF1, kF2, kF3, kF4, kF5, /* 56-63 */
kF6, kF7, kF8, kF9, kF10, -1, -1, JUL, /* 64-71 */
J_U, JUR, S_D, J_L, J_C, J_R, S_I, JDL, /* 72-79 */
J_D, JDR, -1, -1, -1, kF11, kF12, -1, /* 80-87 */
-1, -1, -1, -1, -1, -1, -1, -1, /* 88-95 */
-1, -1, -1, -1, JB1, -1, kHOME, -1, /* 96-103 */
kPGUP, 8, 21, kEND, -1, kPGDN, JB2, -1, /* 104-111 */
-1, -1, -1, -1, -1, -1, -1, kPAUSE, /* 112-119 */
-1, -1, -1, -1, -1, -1, -1, -1 }; /* 120-127 */
/* ----------------------------------------------------
//e Keymap. Mapping scancodes to Apple //e US Keyboard
---------------------------------------------------- */
static int apple_iie_keymap_plain[128] =
{ -1, 27, '1', '2', '3', '4', '5', '6', /* 00-07 */
'7', '8', '9', '0', '-', '=', 8, 9, /* 08-15 */
#define MAP_SIZE 128
static int apple_iie_keymap_plain[MAP_SIZE] =
{ -1, kESC, '1', '2', '3', '4', '5', '6', /* 00-07 */
'7', '8', '9', '0', '-', '=', kLT, kTAB, /* 08-15 */
'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', /* 16-23 */
'o', 'p', '[', ']', 13, -1, 'a', 's', /* 24-31 */
'o', 'p', '[', ']', kRET, -1, 'a', 's', /* 24-31 */
'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', /* 32-39 */
'\'', '`', -1,'\\', 'z', 'x', 'c', 'v', /* 40-47 */
'b', 'n', 'm', ',', '.', '/', -1, -1, /* 48-55 */
JB0, ' ', -1, kF1, kF2, kF3, kF4, kF5, /* 56-63 */
kF6, kF7, kF8, kF9, kF10, -1, -1, JUL, /* 64-71 */
J_U, JUR, S_D, J_L, J_C, J_R, S_I, JDL, /* 72-79 */
kF6, kF7, kF8, kF9, kF10, kF11, kF12, JUL, /* 64-71 */
J_U, JUR, -1, J_L, J_C, J_R, -1, JDL, /* 72-79 */
J_D, JDR, -1, -1, -1, kF11, kF12, -1, /* 80-87 */
-1, -1, -1, -1, -1, -1, -1, -1, /* 88-95 */
-1, -1, -1, -1, JB1, -1, kHOME, 11, /* 96-103 */
kPGUP, 8, 21, kEND, 10, kPGDN, JB2, 127, /* 104-111 */
-1, -1, -1, -1, JB1, -1, kHOME, kUP, /* 96-103 */
kPGUP, kLT, kRT, kEND, kDN, kPGDN, JB2, kDEL, /* 104-111 */
-1, -1, -1, -1, -1, -1, -1, kPAUSE, /* 112-119 */
-1, -1, -1, -1, -1, -1, -1, -1 }; /* 120-127 */
static int apple_iie_keymap_ctrl[128] =
{ -1, 27, '1', '2', '3', '4', '5', '6', /* 00-07 */
'7', '8', '9', '0', '-', '=', 8, 9, /* 08-15 */
17, 23, 5, 18, 20, 25, 21, 9, /* 16-23 */
15, 16, 27, 29, 13, -1, 1, 19, /* 24-31 */
4, 6, 7, 8, 10, 11, 12, ';', /* 32-39 */
// TODO FIXME : remove magic constants and verify ctrl-keys
static int apple_iie_keymap_ctrl[MAP_SIZE] =
{ -1, kESC, '1', '2', '3', '4', '5', '6', /* 00-07 */
'7', '8', '9', '0', '-', '=', kLT, kTAB, /* 08-15 */
17, 23, 5, 18, 20, 25, kRT, kTAB, /* 16-23 */
15, 16, kESC, 29, kRET, -1, 1, 19, /* 24-31 */
4, 6, 7, kLT, kDN, kUP, 12, ';', /* 32-39 */
'\'', '`', -1,'\\', 26, 24, 3, 22, /* 40-47 */
2, 14, 13, ',', '.', '/', -1, -1, /* 48-55 */
2, 14, kRET, ',', '.', '/', -1, -1, /* 48-55 */
JB0, ' ', -1, kF1, kF2, kF3, kF4, kF5, /* 56-63 */
kF6, kF7, kF8, kF9, kF10, -1, -1, JUL, /* 64-71 */
J_U, JUR, S_D, J_L, J_C, J_R, S_I, JDL, /* 72-79 */
kF6, kF7, kF8, kF9, kF10, kF11, kF12, JUL, /* 64-71 */
J_U, JUR, -1, J_L, J_C, J_R, -1, JDL, /* 72-79 */
J_D, JDR, -1, -1, -1, kF11, kF12, -1, /* 80-87 */
-1, -1, -1, -1, -1, -1, -1, -1, /* 88-95 */
-1, -1, -1, -1, JB1, -1, kHOME, 11, /* 96-103 */
kPGUP, 8, 21, kEND, 10, kPGDN, JB2, 127, /* 104-111 */
-1, -1, -1, -1, JB1, -1, kHOME, kUP, /* 96-103 */
kPGUP, kLT, kRT, kEND, kDN, kPGDN, JB2, kDEL, /* 104-111 */
-1, -1, -1, -1, -1, -1, -1, kPAUSE, /* 112-119 */
-1, -1, -1, -1, -1, -1, -1, -1 }; /* 120-127 */
static int apple_iie_keymap_shifted[128] =
{ -1, 27, '!', '@', '#', '$', '%', '^', /* 00-07 */
'&', '*', '(', ')', '_', '+', 8, 9, /* 08-15 */
static int apple_iie_keymap_shifted[MAP_SIZE] =
{ -1, kESC, '!', '@', '#', '$', '%', '^', /* 00-07 */
'&', '*', '(', ')', '_', '+', kLT, kTAB, /* 08-15 */
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', /* 16-23 */
'O', 'P', '{', '}', 13, -1, 'A', 'S', /* 24-31 */
'O', 'P', '{', '}', kRET, -1, 'A', 'S', /* 24-31 */
'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', /* 32-39 */
'"', '~', -1, '|', 'Z', 'X', 'C', 'V', /* 40-47 */
'B', 'N', 'M', '<', '>', '?', -1, -1, /* 48-55 */
JB0, ' ', -1, kF1, kF2, kF3, kF4, kF5, /* 56-63 */
kF6, kF7, kF8, kF9, kF10, -1, -1, JUL, /* 64-71 */
J_U, JUR, S_D, J_L, J_C, J_R, S_I, JDL, /* 72-79 */
kF6, kF7, kF8, kF9, kF10, kF11, kF12, JUL, /* 64-71 */
J_U, JUR, -1, J_L, J_C, J_R, -1, JDL, /* 72-79 */
J_D, JDR, -1, -1, -1, kF11, kF12, -1, /* 80-87 */
-1, -1, -1, -1, -1, -1, -1, -1, /* 88-95 */
-1, -1, -1, -1, JB1, -1, kHOME, 11, /* 96-103 */
kPGUP, 8, 21, kEND, 10, kPGDN, JB2, 127, /* 104-111 */
-1, -1, -1, -1, JB1, -1, kHOME, kUP, /* 96-103 */
kPGUP, kLT, kRT, kEND, kDN, kPGDN, JB2, kDEL, /* 104-111 */
-1, -1, -1, -1, -1, -1, -1, kPAUSE, /* 112-119 */
-1, -1, -1, -1, -1, -1, -1, -1 }; /* 120-127 */
static int apple_iie_keymap_caps[128] =
{ -1, 27, '1', '2', '3', '4', '5', '6', /* 00-07 */
'7', '8', '9', '0', '-', '=', 8, 9, /* 08-15 */
static int apple_iie_keymap_caps[MAP_SIZE] =
{ -1, kESC, '1', '2', '3', '4', '5', '6', /* 00-07 */
'7', '8', '9', '0', '-', '=', kLT, kTAB, /* 08-15 */
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', /* 16-23 */
'O', 'P', '[', ']', 13, -1, 'A', 'S', /* 24-31 */
'O', 'P', '[', ']', kRET, -1, 'A', 'S', /* 24-31 */
'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', /* 32-39 */
'\'', '`', -1,'\\', 'Z', 'X', 'C', 'V', /* 40-47 */
'B', 'N', 'M', ',', '.', '/', -1, -1, /* 48-55 */
JB0, ' ', -1, kF1, kF2, kF3, kF4, kF5, /* 56-63 */
kF6, kF7, kF8, kF9, kF10, -1, -1, JUL, /* 64-71 */
J_U, JUR, S_D, J_L, J_C, J_R, S_I, JDL, /* 72-79 */
kF6, kF7, kF8, kF9, kF10, kF11, kF12, JUL, /* 64-71 */
J_U, JUR, -1, J_L, J_C, J_R, -1, JDL, /* 72-79 */
J_D, JDR, -1, -1, -1, kF11, kF12, -1, /* 80-87 */
-1, -1, -1, -1, -1, -1, -1, -1, /* 88-95 */
-1, -1, -1, -1, JB1, -1, kHOME, 11, /* 96-103 */
kPGUP, 8, 21, kEND, 10, kPGDN, JB2, 127, /* 104-111 */
-1, -1, -1, -1, JB1, -1, kHOME, kUP, /* 96-103 */
kPGUP, kLT, kRT, kEND, kDN, kPGDN, JB2, kDEL, /* 104-111 */
-1, -1, -1, -1, -1, -1, -1, kPAUSE, /* 112-119 */
-1, -1, -1, -1, -1, -1, -1, -1 }; /* 120-127 */
static int apple_iie_keymap_shift_ctrl[128] =
{ -1, 27, '1', 0, '3', '4', '5', 30, /* 00-07 */
'7', '8', '9', '0', 31, '=', 8, 9, /* 08-15 */
17, 23, 5, 18, 20, 25, 21, 9, /* 16-23 */
15, 16, 27, 29, 13, -1, 1, 19, /* 24-31 */
4, 6, 7, 8, 10, 11, 12, ';', /* 32-39 */
// TODO FIXME : remove magic constants and verify ctrl-keys
static int apple_iie_keymap_shift_ctrl[MAP_SIZE] =
{ -1, kESC, '1', 0, '3', '4', '5', 30, /* 00-07 */
'7', '8', '9', '0', 31, '=', kLT, kTAB, /* 08-15 */
17, 23, 5, 18, 20, 25, kRT, kTAB, /* 16-23 */
15, 16, kESC, 29, kRET, -1, 1, 19, /* 24-31 */
4, 6, 7, kLT, kDN, kUP, 12, ';', /* 32-39 */
'\'', '`', 28, -1, 26, 24, 3, 22, /* 40-47 */
2, 14, 13, ',', '.', '/', -1, -1, /* 48-55 */
2, 14, kRET, ',', '.', '/', -1, -1, /* 48-55 */
JB0, ' ', -1, kF1, kF2, kF3, kF4, kF5, /* 56-63 */
kF6, kF7, kF8, kF9, kF10, -1, -1, JUL, /* 64-71 */
J_U, JUR, S_D, J_L, J_C, J_R, S_I, JDL, /* 72-79 */
kF6, kF7, kF8, kF9, kF10, kF11, kF12, JUL, /* 64-71 */
J_U, JUR, -1, J_L, J_C, J_R, -1, JDL, /* 72-79 */
J_D, JDR, -1, -1, -1, kF11, kF12, -1, /* 80-87 */
-1, -1, -1, -1, -1, -1, -1, -1, /* 88-95 */
-1, -1, -1, -1, JB1, -1, kHOME, 11, /* 96-103 */
kPGUP, 8, 21, kEND, 10, kPGDN, JB2, 127, /* 104-111 */
-1, -1, -1, -1, JB1, -1, kHOME, kUP, /* 96-103 */
kPGUP, kLT, kRT, kEND, kDN, kPGDN, JB2, kDEL, /* 104-111 */
-1, -1, -1, -1, -1, -1, -1, kPAUSE, /* 112-119 */
-1, -1, -1, -1, -1, -1, -1, -1 }; /* 120-127 */
static char key_pressed[ 256 ] = { 0 };
/* -------------------------------------------------------------------------
void c_handle_input() : Handle input : keys and joystick.
------------------------------------------------------------------------- */
@ -215,60 +160,38 @@ void c_handle_input(int scancode, int pressed)
{
int *keymap = NULL;
// raw key input mapping ...
assert(scancode < 0x80);
if (scancode >= 0)
{
last_scancode = scancode;
/* determine which key mapping to use */
if (apple_mode == IIE_MODE || in_interface)
if (key_pressed[ SCODE_CAPS ])
{
/* set/reset caps lock */
if (key_pressed[ SCODE_CAPS ])
{
caps_lock = !caps_lock;
}
caps_lock = !caps_lock;
}
if ((key_pressed[ SCODE_L_SHIFT ] || key_pressed[ SCODE_R_SHIFT ]) && /* shift-ctrl */
(key_pressed[ SCODE_L_CTRL ] || key_pressed[ SCODE_R_CTRL ]))
{
keymap = apple_iie_keymap_shift_ctrl;
}
else if (key_pressed[ SCODE_L_CTRL ] || key_pressed[ SCODE_R_CTRL ]) /* ctrl */
{
keymap = apple_iie_keymap_ctrl;
}
else if (key_pressed[ SCODE_L_SHIFT ] || key_pressed[ SCODE_R_SHIFT ]) /* shift */
{
keymap = apple_iie_keymap_shifted;
}
else if (caps_lock)
{
keymap = apple_iie_keymap_caps;
}
else /* plain */
{
keymap = apple_iie_keymap_plain;
}
if ((key_pressed[ SCODE_L_SHIFT ] || key_pressed[ SCODE_R_SHIFT ]) &&
(key_pressed[ SCODE_L_CTRL ] || key_pressed[ SCODE_R_CTRL ]))
{
keymap = apple_iie_keymap_shift_ctrl;
}
else if (key_pressed[ SCODE_L_CTRL ] || key_pressed[ SCODE_R_CTRL ])
{
keymap = apple_iie_keymap_ctrl;
}
else if (key_pressed[ SCODE_L_SHIFT ] || key_pressed[ SCODE_R_SHIFT ])
{
keymap = apple_iie_keymap_shifted;
}
else if (caps_lock)
{
keymap = apple_iie_keymap_caps;
}
else
{
if (key_pressed[ SCODE_L_CTRL ] || key_pressed[ SCODE_R_CTRL ])
{
keymap = apple_ii_keymap_ctrl;
}
else if (key_pressed[ SCODE_L_SHIFT ] || key_pressed[ SCODE_R_SHIFT ])
{
keymap = apple_ii_keymap_shifted;
}
else
{
keymap = apple_ii_keymap_plain;
}
keymap = apple_iie_keymap_plain;
}
/* key is pressed */
if (pressed)
{
key_pressed[ scancode ] = 1;
@ -285,7 +208,6 @@ void c_handle_input(int scancode, int pressed)
break;
}
}
/* key is released */
else
{
key_pressed[ scancode ] = 0;
@ -383,6 +305,7 @@ void c_handle_input(int scancode, int pressed)
}
SoundSystemUnpause();
c_joystick_reset();
pthread_mutex_unlock(&interface_mutex);
in_interface = false;
@ -396,17 +319,19 @@ void c_handle_input(int scancode, int pressed)
joy_x = joy_y = 0xFF;
}
#if defined(KEYPAD_JOYSTICK)
// Keypad emulated joystick relies on "raw" keyboard input
else if (joy_mode == JOY_KPAD)
{
bool joy_axis_unpressed = (!pressed && ((scancode == SCODE_J_U) || (scancode == SCODE_J_D) || (scancode == SCODE_J_L) || (scancode == SCODE_J_R)) );
bool joy_axis_unpressed = !( key_pressed[SCODE_KPAD_U] || key_pressed[SCODE_KPAD_D] || key_pressed[SCODE_KPAD_L] || key_pressed[SCODE_KPAD_R] ||
key_pressed[SCODE_KPAD_UL] || key_pressed[SCODE_KPAD_DL] || key_pressed[SCODE_KPAD_UR] || key_pressed[SCODE_KPAD_DR] );
if (key_pressed[ SCODE_J_C ] || (auto_recenter && joy_axis_unpressed))
if (key_pressed[ SCODE_KPAD_C ] || (auto_recenter && joy_axis_unpressed))
{
joy_x = HALF_JOY_RANGE;
joy_y = HALF_JOY_RANGE;
}
if (key_pressed[ SCODE_J_U ])
if (key_pressed[ SCODE_KPAD_UL ] || key_pressed[ SCODE_KPAD_U ] || key_pressed[ SCODE_KPAD_UR ])
{
if (joy_y > joy_step)
{
@ -418,7 +343,7 @@ void c_handle_input(int scancode, int pressed)
}
}
if (key_pressed[ SCODE_J_D ])
if (key_pressed[ SCODE_KPAD_DL ] || key_pressed[ SCODE_KPAD_D ] || key_pressed[ SCODE_KPAD_DR ])
{
if (joy_y < JOY_RANGE - joy_step)
{
@ -430,7 +355,7 @@ void c_handle_input(int scancode, int pressed)
}
}
if (key_pressed[ SCODE_J_L ])
if (key_pressed[ SCODE_KPAD_UL ] || key_pressed[ SCODE_KPAD_L ] || key_pressed[ SCODE_KPAD_DL ])
{
if (joy_x > joy_step)
{
@ -442,7 +367,7 @@ void c_handle_input(int scancode, int pressed)
}
}
if (key_pressed[ SCODE_J_R ])
if (key_pressed[ SCODE_KPAD_UR ] || key_pressed[ SCODE_KPAD_R ] || key_pressed[ SCODE_KPAD_DR ])
{
if (joy_x < JOY_RANGE - joy_step)
{

View File

@ -19,17 +19,85 @@
#ifndef A2_KEYS_H
#define A2_KEYS_H
#define SCODE_BS 14
// NOTES:
// Ugh, key mapping is a bit schizophrenic... It was originally based on
// Linux/SVGAlib raw scancodes that were mapped to a regular or special keycode
// through a particular map that corresponded to whether a modifier key such as
// shift, control, caps, or a combo, or no modifer was also pressed. The
// emulator makes use of both the raw scancodes and the mapped values.
// ----------------------------------------------------------------------------
// Scancodes aka "raw" values (range 0-127)
// raw key scancodes
#define SCODE_ESC 1
#define SCODE_BS 14
#define SCODE_TAB 15
#define SCODE_RET 28
#define SCODE_L_CTRL 29
#define SCODE_R_CTRL 97
#define SCODE_L_SHIFT 42
#define SCODE_R_SHIFT 54
#define SCODE_L_ALT 56
#define SCODE_CAPS 58
#define SCODE_J_U 72
#define SCODE_J_D 80
#define SCODE_J_L 75
#define SCODE_J_R 77
#define SCODE_J_C 76
#define SCODE_F1 59
#define SCODE_F2 60
#define SCODE_F3 61
#define SCODE_F4 62
#define SCODE_F5 63
#define SCODE_F6 64
#define SCODE_F7 65
#define SCODE_F8 66
#define SCODE_F9 67
#define SCODE_F10 68
#define SCODE_F11 69
#define SCODE_F12 70
#define SCODE_KPAD_UL 71
#define SCODE_KPAD_U 72
#define SCODE_KPAD_UR 73
#define SCODE_KPAD_L 75
#define SCODE_KPAD_C 76
#define SCODE_KPAD_R 77
#define SCODE_KPAD_DL 79
#define SCODE_KPAD_D 80
#define SCODE_KPAD_DR 81
#define SCODE_R_CTRL 97
#define SCODE_PRNT 99
#define SCODE_R_ALT 100
#define SCODE_BRK 101
#define SCODE_HOME 102
#define SCODE_U 103
#define SCODE_PGUP 104
#define SCODE_L 105
#define SCODE_R 106
#define SCODE_END 107
#define SCODE_D 108
#define SCODE_PGDN 109
#define SCODE_INS 110
#define SCODE_DEL 111
#define SCODE_PAUSE 119
// ----------------------------------------------------------------------------
// Keycodes (range 0-255)
// Apple //e special keycodes
#define kLT 8
#define kTAB 9
#define kDN 10
#define kUP 11
#define kRET 13
#define kRT 21
#define kESC 27
#define kDEL 127
// Emulator special keycodes (> 127)
#define kF1 128
#define kF2 129
@ -44,6 +112,7 @@
#define kF11 138
#define kF12 139
// Emulated Joystick
#define J_U 141
#define J_D 142
#define J_L 143
@ -52,26 +121,20 @@
#define JUR 146
#define JDL 147
#define JDR 148
#define JB0 149
#define JB1 150
#define JB2 151
#define S_D 152
#define S_I 153
#define J_C 154
#define JB0 149 // Alt-L
#define JB1 150 // Alt-R
#define JB2 151 // NOTE : unused ...
#define kPAUSE 155
#define kLEFT 8 /* 157 */
#define kRIGHT 21 /* 158 */
#define kUP 11 /* 159 */
#define kDOWN 10 /* 160 */
#define kPGUP 162 // Also : JUR
#define kHOME 163 // Also : JUL
#define kPGDN 164 // Also : JDR
#define kEND 165 // Also : JDL
#define kESC 27 /* 161 */
#define kPGUP 162
#define kHOME 163
#define kPGDN 164
#define kEND 165
// ----------------------------------------------------------------------------
extern pthread_mutex_t interface_mutex;

View File

@ -313,50 +313,49 @@ static void c_initialize_colors() {
//XStoreColors(display, cmap, colors, 256);
}
/* HACK: this is incredibly broken.
* Map the X keysyms back into scancodes so the routines in keys.c can deal
* with it. We do this to be compatible with what the SVGAlib version does.
*/
// Map X keysyms into Apple//ix internal-representation scancodes.
static int keysym_to_scancode(void) {
static int rc = 0xFF;
switch (rc = XkbKeycodeToKeysym(display, xevent.xkey.keycode, 0, 0))
int rc = XkbKeycodeToKeysym(display, xevent.xkey.keycode, 0, 0);
switch (rc)
{
case XK_F1:
rc = 59; break;
rc = SCODE_F1; break;
case XK_F2:
rc = 60; break;
rc = SCODE_F2; break;
case XK_F3:
rc = 61; break;
rc = SCODE_F3; break;
case XK_F4:
rc = 62; break;
rc = SCODE_F4; break;
case XK_F5:
rc = 63; break;
rc = SCODE_F5; break;
case XK_F6:
rc = 64; break;
rc = SCODE_F6; break;
case XK_F7:
rc = 65; break;
rc = SCODE_F7; break;
case XK_F8:
rc = 66; break;
rc = SCODE_F8; break;
case XK_F9:
rc = 67; break;
rc = SCODE_F9; break;
case XK_F10:
rc = 68; break;
rc = SCODE_F10; break;
case XK_F11:
rc = SCODE_F11; break;
case XK_F12:
rc = SCODE_F12; break;
case XK_Left:
rc = 105; break;
rc = SCODE_L; break;
case XK_Right:
rc = 106; break;
rc = SCODE_R; break;
case XK_Down:
rc = 108; break;
rc = SCODE_D; break;
case XK_Up:
rc = 103; break;
rc = SCODE_U; break;
case XK_Escape:
rc = 1; break;
rc = SCODE_ESC; break;
case XK_Return:
rc = 28; break;
rc = SCODE_RET; break;
case XK_Tab:
rc = 15; break;
rc = SCODE_TAB; break;
case XK_Shift_L:
rc = SCODE_L_SHIFT; break;
case XK_Shift_R:
@ -368,11 +367,11 @@ static int keysym_to_scancode(void) {
case XK_Caps_Lock:
rc = SCODE_CAPS; break;
case XK_BackSpace:
rc = 14; break;
rc = SCODE_BS; break;
case XK_Insert:
rc = 110; break;
rc = SCODE_INS; break;
case XK_Pause:
rc = 119; break;
rc = SCODE_PAUSE; break;
case XK_Break:
/* Pause and Break are the same key, but have different
* scancodes (on PC keyboards). Ctrl makes the difference.
@ -380,52 +379,72 @@ static int keysym_to_scancode(void) {
* We assume the X server is passing along the distinction to us,
* rather than making us check Ctrl manually.
*/
rc = 101; break;
rc = SCODE_BRK; break;
case XK_Print:
rc = 99; break;
rc = SCODE_PRNT; break;
case XK_Delete:
rc = 111; break;
rc = SCODE_DEL; break;
case XK_End:
rc = 107; break;
rc = SCODE_END; break;
case XK_Home:
rc = 102; break;
rc = SCODE_HOME; break;
case XK_Page_Down:
rc = 109; break;
rc = SCODE_PGDN; break;
case XK_Page_Up:
rc = 104; break;
rc = SCODE_PGUP; break;
// keypad joystick movement
case XK_KP_5:
case XK_KP_Begin:
rc = SCODE_J_C; break;
rc = SCODE_KPAD_C; break;
case XK_KP_4:
case XK_KP_Left:
rc = SCODE_J_L; break;
rc = SCODE_KPAD_L; break;
case XK_KP_8:
case XK_KP_Up:
rc = SCODE_J_U; break;
rc = SCODE_KPAD_U; break;
case XK_KP_6:
case XK_KP_Right:
rc = SCODE_J_R; break;
rc = SCODE_KPAD_R; break;
case XK_KP_2:
case XK_KP_Down:
rc = SCODE_J_D; break;
rc = SCODE_KPAD_D; break;
case XK_KP_7:
case XK_KP_Home:
rc = SCODE_KPAD_UL; break;
break;
case XK_KP_9:
case XK_KP_Page_Up:
rc = SCODE_KPAD_UR; break;
break;
case XK_KP_1:
case XK_KP_End:
rc = SCODE_KPAD_DL; break;
break;
case XK_KP_3:
case XK_KP_Page_Down:
rc = SCODE_KPAD_DR; break;
break;
case XK_Alt_L:
rc = 56; break;
rc = SCODE_L_ALT; break;
case XK_Alt_R:
rc = 100; break;
rc = SCODE_R_ALT; break;
default:
if ((rc >= XK_space) && (rc <= XK_asciitilde))
{
rc = xevent.xkey.keycode - 8;
}
else
{
rc = -1; // unmapped
}
break;
}
return rc & 0xFF; /* normalize */
assert(rc < 0x80);
return rc;
}
static void post_image() {