Fixed keyboard input

This commit is contained in:
simon.kagstrom 2009-01-10 09:02:44 +00:00
parent fe89785105
commit dc6d9aab2b
5 changed files with 80 additions and 66 deletions

View File

@ -1,4 +1,8 @@
version 2:
* Improve keyboard bindings to handle press and release correctly and also
both controllers at the same time (key is released when the last controller releases
it)
* Handle keycode 0 and therefore make del work
* Remove the 1-1 graphics option and make stretched the default. Should avoid
"helpful and constructive" messages such as
http://wiinewz.com/forums/nintendo-news/91829-frodo-v1-0-a.html#post580580

View File

@ -226,13 +226,13 @@ void C64::bind_key(Prefs *np)
{
menu_t bind_key_menu;
menu_t key_menu;
static const char *keys[] = { "space", "Run/Stop", "return", "F1", "F3", "F5", "F7",
static const char *keys[] = { "None", "space", "Run/Stop", "return", "F1", "F3", "F5", "F7",
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A",
"B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
"ctrl", "del", "home,", "shl", "shr", "clr", "C=", "<-",
NULL };
int kcs[] = { MATRIX(7, 4), MATRIX(7, 7), MATRIX(0, 1), /* space, R/S, return */
int kcs[] = { 0, MATRIX(7, 4), MATRIX(7, 7), MATRIX(0, 1), /* space, R/S, return */
MATRIX(0, 4), MATRIX(0, 5), MATRIX(0, 6), MATRIX(0, 3), MATRIX(4, 3), MATRIX(7, 0),
MATRIX(7, 3), MATRIX(1, 0), MATRIX(1, 3), MATRIX(2, 0), MATRIX(2, 3), MATRIX(3, 0),
MATRIX(3, 3), MATRIX(4, 0), MATRIX(1, 2), MATRIX(3, 4), MATRIX(2, 4), MATRIX(2, 2),
@ -253,7 +253,10 @@ void C64::bind_key(Prefs *np)
32, 32, MENU_SIZE_X, MENU_SIZE_Y);
int key = menu_select(real_screen, &key_menu, NULL);
if (key > 0)
np->JoystickKeyBinding[opt] = kcs[key];
else if (key == 0)
np->JoystickKeyBinding[opt] = -1;
menu_fini(&key_menu);
}
menu_fini(&bind_key_menu);
@ -353,7 +356,7 @@ void C64::Run(void)
}
/* From dreamcast port */
static char *auto_seq[4] =
static const char *auto_seq[4] =
{
"\nLOAD \"*\",8,1\nRUN\n",
"\nLOAD \"*\",9,1\nRUN\n",
@ -368,6 +371,10 @@ extern "C" int get_kc_from_char(char c_in, int *shifted);
void C64::VBlank(bool draw_frame)
{
#if defined(GEKKO)
WPAD_ScanPads();
#endif
// Poll joysticks
TheCIA1->Joystick1 = poll_joystick(0);
TheCIA1->Joystick2 = poll_joystick(1);
@ -537,16 +544,17 @@ void C64::open_close_joysticks(bool oldjoy1, bool oldjoy2, bool newjoy1, bool ne
uint8 C64::poll_joystick(int port)
{
#ifdef GEKKO
int extra_keys[N_WIIMOTE_BINDINGS];
int controller = port;
Uint32 held;
Uint32 held, held_other;
uint8 j = 0xff;
if (ThePrefs.JoystickSwap)
controller = !port;
WPAD_ScanPads();
held = WPAD_ButtonsHeld(controller);
held_other = WPAD_ButtonsHeld(!controller);
if (held & WPAD_BUTTON_UP)
j &= 0xfb; // Left
if (held & WPAD_BUTTON_DOWN)
@ -559,23 +567,26 @@ uint8 C64::poll_joystick(int port)
j &= 0xef; // Button
if (held & WPAD_BUTTON_HOME)
this->enter_menu();
else
extra_keys[WIIMOTE_A] = (held | held_other) & WPAD_BUTTON_A;
extra_keys[WIIMOTE_B] = (held | held_other) & WPAD_BUTTON_B;
extra_keys[WIIMOTE_PLUS] = (held | held_other) & WPAD_BUTTON_PLUS;
extra_keys[WIIMOTE_MINUS] = (held | held_other) & WPAD_BUTTON_MINUS;
extra_keys[WIIMOTE_1] = (held | held_other) & WPAD_BUTTON_1;
for (int i = 0; i < N_WIIMOTE_BINDINGS; i++)
{
if ( (held & WPAD_BUTTON_A) && ThePrefs.JoystickKeyBinding[0])
TheDisplay->FakeKeyPressRepeat(ThePrefs.JoystickKeyBinding[0],
false, TheCIA1->KeyMatrix, TheCIA1->RevMatrix);
if ( (held & WPAD_BUTTON_B) && ThePrefs.JoystickKeyBinding[1])
TheDisplay->FakeKeyPressRepeat(ThePrefs.JoystickKeyBinding[1],
false, TheCIA1->KeyMatrix, TheCIA1->RevMatrix);
if ( (held & WPAD_BUTTON_PLUS) && ThePrefs.JoystickKeyBinding[2])
TheDisplay->FakeKeyPressRepeat(ThePrefs.JoystickKeyBinding[2],
false, TheCIA1->KeyMatrix, TheCIA1->RevMatrix);
if ( (held & WPAD_BUTTON_MINUS) && ThePrefs.JoystickKeyBinding[3])
TheDisplay->FakeKeyPressRepeat(ThePrefs.JoystickKeyBinding[3],
false, TheCIA1->KeyMatrix, TheCIA1->RevMatrix);
if ( (held & WPAD_BUTTON_1) && ThePrefs.JoystickKeyBinding[4])
TheDisplay->FakeKeyPressRepeat(ThePrefs.JoystickKeyBinding[4],
false, TheCIA1->KeyMatrix, TheCIA1->RevMatrix);
int kc = ThePrefs.JoystickKeyBinding[i];
if ( kc < 0 )
continue;
if (extra_keys[i])
TheDisplay->UpdateKeyMatrix(kc, false,
TheCIA1->KeyMatrix, TheCIA1->RevMatrix);
else
TheDisplay->UpdateKeyMatrix(kc, true,
TheCIA1->KeyMatrix, TheCIA1->RevMatrix);
}
return j;

View File

@ -16,7 +16,7 @@
#endif
#ifdef HAVE_SDL
struct SDL_Surface;
#include <SDL.h>
extern SDL_Surface *real_screen;
#endif
@ -65,11 +65,10 @@ public:
void PollKeyboard(uint8 *key_matrix, uint8 *rev_matrix, uint8 *joystick);
#endif
#if defined(HAVE_SDL)
void FakeKeyPressRepeat(int kc, bool shift, uint8 *CIA_key_matrix,
uint8 *CIA_rev_matrix);
void FakeKeyPress(int kc, bool shift, uint8 *CIA_key_matrix,
uint8 *CIA_rev_matrix);
void TranslateKey(SDLKey key, bool key_up, uint8 *key_matrix, uint8 *rev_matrix, uint8 *joystick);
void UpdateKeyMatrix(int c64_key, bool key_up, uint8 *key_matrix, uint8 *rev_matrix);
#endif
bool NumLock(void);
void InitColors(uint8 *colors);

View File

@ -245,22 +245,6 @@ int C64Display::BitmapXMod(void)
return screen->pitch;
}
void C64Display::FakeKeyPressRepeat(int kc, bool shift, uint8 *CIA_key_matrix, uint8 *CIA_rev_matrix)
{
static int cnt = 5;
if (cnt > 0) {
this->FakeKeyPress(-1, shift, CIA_key_matrix, CIA_rev_matrix);
cnt--;
}
else
{
this->FakeKeyPress(kc, shift, CIA_key_matrix, CIA_rev_matrix);
cnt = 5;
}
}
void C64Display::FakeKeyPress(int kc, bool shift, uint8 *CIA_key_matrix,
uint8 *CIA_rev_matrix)
{
@ -294,11 +278,34 @@ void C64Display::FakeKeyPress(int kc, bool shift, uint8 *CIA_key_matrix,
}
}
void C64Display::UpdateKeyMatrix(int c64_key, bool key_up, uint8 *key_matrix, uint8 *rev_matrix)
{
bool shifted = c64_key & 0x80;
int c64_byte = (c64_key >> 3) & 7;
int c64_bit = c64_key & 7;
if (key_up) {
if (shifted) {
key_matrix[6] |= 0x10;
rev_matrix[4] |= 0x40;
}
key_matrix[c64_byte] |= (1 << c64_bit);
rev_matrix[c64_bit] |= (1 << c64_byte);
} else {
if (shifted) {
key_matrix[6] &= 0xef;
rev_matrix[4] &= 0xbf;
}
key_matrix[c64_byte] &= ~(1 << c64_bit);
rev_matrix[c64_bit] &= ~(1 << c64_byte);
}
}
/*
* Poll the keyboard
*/
static void translate_key(SDLKey key, bool key_up, uint8 *key_matrix, uint8 *rev_matrix, uint8 *joystick)
void C64Display::TranslateKey(SDLKey key, bool key_up, uint8 *key_matrix, uint8 *rev_matrix, uint8 *joystick)
{
int c64_key = -1;
switch (key) {
@ -412,25 +419,7 @@ static void translate_key(SDLKey key, bool key_up, uint8 *key_matrix, uint8 *rev
return;
}
// Handle other keys
bool shifted = c64_key & 0x80;
int c64_byte = (c64_key >> 3) & 7;
int c64_bit = c64_key & 7;
if (key_up) {
if (shifted) {
key_matrix[6] |= 0x10;
rev_matrix[4] |= 0x40;
}
key_matrix[c64_byte] |= (1 << c64_bit);
rev_matrix[c64_bit] |= (1 << c64_byte);
} else {
if (shifted) {
key_matrix[6] &= 0xef;
rev_matrix[4] &= 0xbf;
}
key_matrix[c64_byte] &= ~(1 << c64_bit);
rev_matrix[c64_bit] &= ~(1 << c64_byte);
}
this->UpdateKeyMatrix(c64_key, key_up, key_matrix, rev_matrix);
}
void C64Display::PollKeyboard(uint8 *key_matrix, uint8 *rev_matrix, uint8 *joystick)
@ -481,7 +470,7 @@ void C64Display::PollKeyboard(uint8 *key_matrix, uint8 *rev_matrix, uint8 *joyst
break;
default:
translate_key(event.key.keysym.sym, false, key_matrix, rev_matrix, joystick);
TranslateKey(event.key.keysym.sym, false, key_matrix, rev_matrix, joystick);
break;
}
break;
@ -491,7 +480,7 @@ void C64Display::PollKeyboard(uint8 *key_matrix, uint8 *rev_matrix, uint8 *joyst
if (event.key.keysym.sym == SDLK_NUMLOCK)
num_locked = false;
else
translate_key(event.key.keysym.sym, true, key_matrix, rev_matrix, joystick);
TranslateKey(event.key.keysym.sym, true, key_matrix, rev_matrix, joystick);
break;
// Quit Frodo

View File

@ -39,6 +39,17 @@ enum {
DISPTYPE_SCREEN // BWindowScreen
};
// Key bindings (WII)
enum {
WIIMOTE_A,
WIIMOTE_B,
WIIMOTE_PLUS,
WIIMOTE_MINUS,
WIIMOTE_1,
N_WIIMOTE_BINDINGS
};
// Preferences data
class Prefs {
@ -116,7 +127,7 @@ private:
#endif
#ifdef HAVE_SDL
int JoystickKeyBinding[5];
int JoystickKeyBinding[N_WIIMOTE_BINDINGS];
int DisplayOption;
#endif
};