From a063dfe18d2e4d9a4a1b0615dbc0e5ae520fffda Mon Sep 17 00:00:00 2001 From: "simon.kagstrom" Date: Sat, 24 Jan 2009 07:30:06 +0000 Subject: [PATCH] Simplified faking key sequences and do this through the virtual keyboard --- Src/C64_SDL.h | 14 ++---- Src/Display.h | 3 +- Src/Display_SDL.h | 27 ++--------- Src/Makefile | 1 + Src/VirtualKeyboard.cpp | 31 +++++++++++- Src/VirtualKeyboard.h | 1 + Src/char_to_kc.c | 103 ---------------------------------------- 7 files changed, 42 insertions(+), 138 deletions(-) delete mode 100644 Src/char_to_kc.c diff --git a/Src/C64_SDL.h b/Src/C64_SDL.h index 3f0995b..8c13a67 100644 --- a/Src/C64_SDL.h +++ b/Src/C64_SDL.h @@ -71,7 +71,7 @@ void C64::c64_ctor1(void) this->fake_key_sequence = false; this->fake_key_index = 0; - this->fake_key_keytime = 5; + this->fake_key_keytime = 4; this->fake_key_str = "\nLOAD \"*\",8,1\nRUN\n"; this->prefs_changed = false; @@ -470,8 +470,6 @@ void C64::Run(void) thread_func(); } -extern "C" int get_kc_from_char(char c_in, int *shifted); - /* * Vertical blank: Poll keyboard and joysticks, update window */ @@ -494,16 +492,14 @@ void C64::VBlank(bool draw_frame) /* From dreamcast port */ if (this->fake_key_sequence) { - int shifted; - int kc = get_kc_from_char(this->fake_key_str[this->fake_key_index], &shifted); + int kc = this->virtual_keyboard->char_to_keycode(this->fake_key_str[this->fake_key_index]); - TheDisplay->FakeKeyPress(kc, shifted, TheCIA1->KeyMatrix, - TheCIA1->RevMatrix); + TheDisplay->FakeKeyPress(kc, TheCIA1->KeyMatrix, TheCIA1->RevMatrix); this->fake_key_keytime --; if (this->fake_key_keytime == 0) { - this->fake_key_keytime = 1; + this->fake_key_keytime = 4; this->fake_key_index ++; if (this->fake_key_str[this->fake_key_index] == '\0') @@ -605,7 +601,7 @@ void C64::VBlank(bool draw_frame) this->NewPrefs(&np); ThePrefs = np; } - TheDisplay->FakeKeyPress(-1, false, TheCIA1->KeyMatrix, + TheDisplay->FakeKeyPress(-1, TheCIA1->KeyMatrix, TheCIA1->RevMatrix); this->have_a_break = false; diff --git a/Src/Display.h b/Src/Display.h index ba74c06..80824ff 100644 --- a/Src/Display.h +++ b/Src/Display.h @@ -79,8 +79,7 @@ public: void PollKeyboard(uint8 *key_matrix, uint8 *rev_matrix, uint8 *joystick); #endif #if defined(HAVE_SDL) - void FakeKeyPress(int kc, bool shift, uint8 *CIA_key_matrix, - uint8 *CIA_rev_matrix); + void FakeKeyPress(int kc, 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 diff --git a/Src/Display_SDL.h b/Src/Display_SDL.h index 3d4958e..0c6b2d0 100644 --- a/Src/Display_SDL.h +++ b/Src/Display_SDL.h @@ -312,37 +312,18 @@ int C64Display::BitmapXMod(void) return DISPLAY_X; } -void C64Display::FakeKeyPress(int kc, bool shift, uint8 *CIA_key_matrix, +void C64Display::FakeKeyPress(int kc, uint8 *CIA_key_matrix, uint8 *CIA_rev_matrix) { - // Clear matrices + int shifted = kc & 0x80; + // Clear matrices for (int i = 0; i < 8; i ++) { CIA_key_matrix[i] = 0xFF; CIA_rev_matrix[i] = 0xFF; } - - if (shift) - { - CIA_key_matrix[6] &= 0xef; - CIA_rev_matrix[4] &= 0xbf; - } - if (kc != -1) - { - int c64_byte, c64_bit, shifted; - c64_byte = kc >> 3; - c64_bit = kc & 7; - shifted = kc & 128; - c64_byte &= 7; - if (shifted) - { - CIA_key_matrix[6] &= 0xef; - CIA_rev_matrix[4] &= 0xbf; - } - CIA_key_matrix[c64_byte] &= ~(1 << c64_bit); - CIA_rev_matrix[c64_bit] &= ~(1 << c64_byte); - } + this->UpdateKeyMatrix(kc, false, CIA_key_matrix, CIA_rev_matrix); } void C64Display::UpdateKeyMatrix(int c64_key, bool key_up, uint8 *key_matrix, uint8 *rev_matrix) diff --git a/Src/Makefile b/Src/Makefile index 0d35ab9..f1463ab 100644 --- a/Src/Makefile +++ b/Src/Makefile @@ -132,6 +132,7 @@ sysconfig.h: sysconfig.h.Host-SDL main.o: sysdeps.h sysconfig.h main.h C64.h Display.h Prefs.h SAM.h main.o: Basic_ROM.h Kernal_ROM.h Char_ROM.h 1541_ROM.h Display.o: sysdeps.h sysconfig.h Display.h main.h Prefs.h Display_SDL.h +Display_SC.o: sysdeps.h sysconfig.h Display.h main.h Prefs.h Display_SDL.h Prefs.o: sysdeps.h sysconfig.h Prefs.h Display.h C64.h main.h SID.o: sysdeps.h sysconfig.h SID.h Prefs.h REU.o: sysdeps.h sysconfig.h REU.h CPUC64.h C64.h Prefs.h diff --git a/Src/VirtualKeyboard.cpp b/Src/VirtualKeyboard.cpp index 59c7262..184929b 100644 --- a/Src/VirtualKeyboard.cpp +++ b/Src/VirtualKeyboard.cpp @@ -49,7 +49,7 @@ typedef struct static virtkey_t keys[KEY_COLS * KEY_ROWS] = { K("<-",7,1), K("1", 7,0), K("2", 7,3), K("3", 1,0), K("4", 1,3), K("5", 2,0), K("6", 2,3), K("7", 3,0), K("8", 3,3), K("9", 4,0), K("0", 4,3), K("+", 5,0), K("-", 5,3), K("£", 6,0), K("Hom", 6,3), - K("Cr", 7,2), K("Q", 7,6), K("W", 1,1), K("E", 1,6), K("R", 2,2), K("T", 2,6), K("Y", 3,1), K("U", 3,6), K("I", 4,1), K("O", 6,6), K("P", 5,1), K("@", 5,6), K("*", 6,1), K("Au", 6,6),K("Rstr",4,0), + K("Cr", 7,2), K("Q", 7,6), K("W", 1,1), K("E", 1,6), K("R", 2,1), K("T", 2,6), K("Y", 3,1), K("U", 3,6), K("I", 4,1), K("O", 4,6), K("P", 5,1), K("@", 5,6), K("*", 6,1), K("Au", 6,6),K("Rstr",4,0), K("R/Stp", 7,7), K(NULL,0,0), K("A", 1,2), K("S", 1,5), K("D", 2,2), K("F", 2,5), K("G", 3,2), K("H", 3,5), K("J", 4,2), K("K", 4,5), K("L", 5,2), K(":", 5,5), K(";", 6,2), K("=", 6,5), K("Ret", 0,1), K("C=", 7,5), S("Shft",1,7),K(NULL,0,0),K("Z", 1,4), K("X", 2,7), K("C", 2,4), K("V", 3,7), K("B", 3,4), K("N", 4,7), K("M", 4,4), K(",", 5,7), K(".", 5,4), K("/", 6,7), K("Dwn",0,7),K("Rgt", 0,2), N("None"), K(NULL,0,0), K(NULL,0,0), K("space", 7,4),K(0, 0,0),K(NULL,0,0), K("f1", 0,4),K("f3", 0,5),K("f5", 0,6),K("f7", 0,3),K(NULL,0,0), K(NULL,0,0), K(NULL,0,0), K(NULL,0,0), K("Del", 0,0), @@ -171,6 +171,35 @@ const char *VirtualKeyboard::keycode_to_string(int kc) return out; } +int VirtualKeyboard::char_to_keycode(char c) +{ + for (int i = 0; i < KEY_COLS * KEY_ROWS; i++) + { + virtkey_t key = keys[i]; + + if (key.name != NULL) + { + if (strlen(key.name) == 1) + { + if (key.name[0] == c) + return key.kc; + if (shifted_names[i] && strlen(shifted_names[i]) == 1 && + shifted_names[i][0] == c) + return key.kc | 0x80; + } + + /* OK, ugly special cases, but these are pretty important */ + if (c == ' ' && strcmp(key.name, "space") == 0) + return key.kc; + if (c == '\n' && strcmp(key.name, "Ret") == 0) + return key.kc; + } + } + + printf("Vobb! c=%d\n", c); + return -1; +} + const char VirtualKeyboard::get_char(int kc) { /* NULL is never, ever returned */ diff --git a/Src/VirtualKeyboard.h b/Src/VirtualKeyboard.h index daf52ce..45964cb 100644 --- a/Src/VirtualKeyboard.h +++ b/Src/VirtualKeyboard.h @@ -19,6 +19,7 @@ public: int get_key(); const char *get_string(); const char *keycode_to_string(int kc); + int char_to_keycode(char c); private: const char get_char(int kc); diff --git a/Src/char_to_kc.c b/Src/char_to_kc.c deleted file mode 100644 index 833a51b..0000000 --- a/Src/char_to_kc.c +++ /dev/null @@ -1,103 +0,0 @@ -/********************************************************************* - * - * Copyright (C) 2008, Simon Kagstrom - * - * Filename: char_to_kc.c - * Author: Simon Kagstrom - * Description: Convert chars to keycodes - * - * $Id:$ - * - ********************************************************************/ -#include - -#define MATRIX(a,b) (((a) << 3) | (b)) - -#define SHIFT (1<<7) - -static uint8_t char_to_kc[] = -{ - /* Some shifted stuff */ - ['\"'] = MATRIX(7, 3) | SHIFT, - ['?'] = MATRIX(1, 3) | SHIFT, - ['!'] = MATRIX(7, 0) | SHIFT, - - /* CUD */ - /* F5 */ - /* F3 */ - /* F1 */ - /* F7 */ - ['\n'] = MATRIX(0, 1), - [8] = MATRIX(0, 0), - - ['E'] = MATRIX(1, 6), - ['S'] = MATRIX(1, 5), - ['Z'] = MATRIX(1, 4), - ['4'] = MATRIX(1, 3), - ['A'] = MATRIX(1, 2), - ['W'] = MATRIX(1, 1), - ['3'] = MATRIX(1, 0), - - ['X'] = MATRIX(2, 7), - ['T'] = MATRIX(2, 6), - ['F'] = MATRIX(2, 5), - ['C'] = MATRIX(2, 4), - ['6'] = MATRIX(2, 3), - ['D'] = MATRIX(2, 2), - ['R'] = MATRIX(2, 1), - ['5'] = MATRIX(2, 0), - - ['V'] = MATRIX(3, 7), - ['U'] = MATRIX(3, 6), - ['H'] = MATRIX(3, 5), - ['B'] = MATRIX(3, 4), - ['8'] = MATRIX(3, 3), - ['G'] = MATRIX(3, 2), - ['Y'] = MATRIX(3, 1), - ['7'] = MATRIX(3, 0), - - ['N'] = MATRIX(4, 7), - ['O'] = MATRIX(4, 6), - ['K'] = MATRIX(4, 5), - ['M'] = MATRIX(4, 4), - ['0'] = MATRIX(4, 3), - ['J'] = MATRIX(4, 2), - ['I'] = MATRIX(4, 1), - ['9'] = MATRIX(4, 0), - - [','] = MATRIX(5, 7), - ['@'] = MATRIX(5, 6), - [':'] = MATRIX(5, 5), - ['.'] = MATRIX(5, 4), - ['-'] = MATRIX(5, 3), - ['L'] = MATRIX(5, 2), - ['P'] = MATRIX(5, 1), - ['+'] = MATRIX(5, 0), - - ['/'] = MATRIX(6, 7), - ['^'] = MATRIX(6, 6), - ['='] = MATRIX(6, 5), - /* SHR */ - /* HOM */ - [';'] = MATRIX(6, 2), - ['*'] = MATRIX(6, 1), - /* ?? */ - - /* R/S */ - ['Q'] = MATRIX(7, 6), - /* C= */ - [' '] = MATRIX(7, 4), - ['2'] = MATRIX(7, 3), - /* CTL */ - /* <- */ - ['1'] = MATRIX(7, 0), -}; - -int get_kc_from_char(char c_in, int *shifted) -{ - char c = char_to_kc[(int)c_in]; - int out = c & (~SHIFT); - - *shifted = c & SHIFT; - return out; -}