Skip to content

Commit

Permalink
Added support for Model-M keyboards. (SDL frontend only)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas-jonsson committed Dec 6, 2024
1 parent ebc2d0f commit a64ad31
Show file tree
Hide file tree
Showing 10 changed files with 376 additions and 113 deletions.
6 changes: 3 additions & 3 deletions front/libretro/keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static enum vxtu_scancode retro_to_xt_scan(enum retro_key key) {
return VXTU_SCAN_ENTER;
case RETROK_LCTRL:
case RETROK_RCTRL:
return VXTU_SCAN_CONTROL;
return VXTU_SCAN_LCONTROL;
case RETROK_a:
return VXTU_SCAN_A;
case RETROK_s:
Expand Down Expand Up @@ -114,7 +114,7 @@ static enum vxtu_scancode retro_to_xt_scan(enum retro_key key) {
case RETROK_LSHIFT:
return VXTU_SCAN_LSHIFT;
case RETROK_BACKSLASH:
return VXTU_SCAN_BACKSLASH;
return VXTU_SCAN_INT2;
case RETROK_z:
return VXTU_SCAN_Z;
case RETROK_x:
Expand All @@ -141,7 +141,7 @@ static enum vxtu_scancode retro_to_xt_scan(enum retro_key key) {
return VXTU_SCAN_PRINT;
case RETROK_LALT:
case RETROK_RALT:
return VXTU_SCAN_ALT;
return VXTU_SCAN_LALT;
case RETROK_SPACE:
return VXTU_SCAN_SPACE;
case RETROK_CAPSLOCK:
Expand Down
8 changes: 4 additions & 4 deletions front/rpi/keymap.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@

#define NUM_MODIFIERS 9
enum vxtu_scancode modifierToXT[NUM_MODIFIERS] = {
VXTU_SCAN_CONTROL, // ModifierKeyLeftCtrl
VXTU_SCAN_LCONTROL, // ModifierKeyLeftCtrl
VXTU_SCAN_LSHIFT, // ModifierKeyLeftShift
VXTU_SCAN_ALT, // ModifierKeyAlt
VXTU_SCAN_INVALID, // ModifierKeyLeftWin
VXTU_SCAN_CONTROL, // ModifierKeyRightCtrl
VXTU_SCAN_LCONTROL, // ModifierKeyRightCtrl
VXTU_SCAN_RSHIFT, // ModifierKeyRightShift
VXTU_SCAN_ALT, // ModifierKeyAltGr
VXTU_SCAN_INVALID, // ModifierKeyRightWin
Expand Down Expand Up @@ -260,11 +260,11 @@ enum vxtu_scancode usbToXT[256] = {
VXTU_SCAN_INVALID, // USB dd (none)
VXTU_SCAN_INVALID, // USB de (none)
VXTU_SCAN_INVALID, // USB df (none)
VXTU_SCAN_CONTROL, // USB e0 ControlLeft
VXTU_SCAN_LCONTROL, // USB e0 ControlLeft
VXTU_SCAN_LSHIFT, // USB e1 ShiftLeft
VXTU_SCAN_ALT, // USB e2 AltLeft
VXTU_SCAN_INVALID, // USB e3 OSLeft
VXTU_SCAN_CONTROL, // USB e4 ControlRight
VXTU_SCAN_LCONTROL, // USB e4 ControlRight
VXTU_SCAN_RSHIFT, // USB e5 ShiftRight
VXTU_SCAN_ALT, // USB e6 AltRight
VXTU_SCAN_INVALID, // USB e7 OSRight
Expand Down
10 changes: 7 additions & 3 deletions front/sdl2/docopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ int elems_to_args(struct Elements *elements, struct DocoptArgs *args,
for (i = 0; i < elements->n_options; i++) {
option = &elements->options[i];
if (help && option->value && strcmp(option->olong, "--help") == 0) {
for (j = 0; j < 20; j++)
for (j = 0; j < 21; j++)
puts(args->help_message[j]);
return EXIT_FAILURE;
} else if (version && option->value &&
Expand All @@ -245,6 +245,8 @@ int elems_to_args(struct Elements *elements, struct DocoptArgs *args,
args->hdboot = option->value;
} else if (strcmp(option->olong, "--help") == 0) {
args->help = option->value;
} else if (strcmp(option->olong, "--kb101") == 0) {
args->kb101 = option->value;
} else if (strcmp(option->olong, "--locate") == 0) {
args->locate = option->value;
} else if (strcmp(option->olong, "--mute") == 0) {
Expand Down Expand Up @@ -301,7 +303,7 @@ int elems_to_args(struct Elements *elements, struct DocoptArgs *args,

struct DocoptArgs docopt(int argc, char *argv[], const bool help, const char *version) {
struct DocoptArgs args = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, (char *) "10.0", NULL,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, (char *) "10.0", NULL,
NULL, NULL,
usage_pattern,
{ "Usage: virtualxt [options]",
Expand All @@ -313,6 +315,7 @@ struct DocoptArgs docopt(int argc, char *argv[], const bool help, const char *ve
" --halt Debug break on startup.",
" --mute Disable audio.",
" --a20 Enable support for A20 line.",
" --kb101 US 101 Model-M keyboard layout. (Require BIOS support)",
" --no-activity Disable disk activity indicator.",
" --no-idle Disable CPU idle on INT28.",
" --clean Remove config file and write a new default one.",
Expand All @@ -336,6 +339,7 @@ struct DocoptArgs docopt(int argc, char *argv[], const bool help, const char *ve
{NULL, "--halt", 0, 0, NULL},
{NULL, "--hdboot", 0, 0, NULL},
{"-h", "--help", 0, 0, NULL},
{NULL, "--kb101", 0, 0, NULL},
{NULL, "--locate", 0, 0, NULL},
{NULL, "--mute", 0, 0, NULL},
{NULL, "--no-activity", 0, 0, NULL},
Expand All @@ -353,7 +357,7 @@ struct DocoptArgs docopt(int argc, char *argv[], const bool help, const char *ve

elements.n_commands = 0;
elements.n_arguments = 0;
elements.n_options = 17;
elements.n_options = 18;
elements.commands = commands;
elements.arguments = arguments;
elements.options = options;
Expand Down
3 changes: 2 additions & 1 deletion front/sdl2/docopt.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ struct DocoptArgs {
size_t halt;
size_t hdboot;
size_t help;
size_t kb101;
size_t locate;
size_t mute;
size_t no_activity;
Expand All @@ -102,7 +103,7 @@ struct DocoptArgs {
char *trace;
/* special */
const char *usage_pattern;
const char *help_message[20];
const char *help_message[21];
};

struct DocoptArgs docopt(int, char *[], bool, const char *);
Expand Down
221 changes: 217 additions & 4 deletions front/sdl2/keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <SDL.h>
#include <vxt/vxtu.h>

static enum vxtu_scancode sdl_to_xt_scan(SDL_Scancode scan) {
static enum vxtu_scancode sdl_to_model_f(SDL_Scancode scan) {
switch ((int)scan) {
case SDL_SCANCODE_ESCAPE:
return VXTU_SCAN_ESCAPE;
Expand Down Expand Up @@ -85,8 +85,9 @@ static enum vxtu_scancode sdl_to_xt_scan(SDL_Scancode scan) {
case SDL_SCANCODE_KP_ENTER:
return VXTU_SCAN_ENTER;
case SDL_SCANCODE_LCTRL:
return VXTU_SCAN_LCONTROL;
case SDL_SCANCODE_RCTRL:
return VXTU_SCAN_CONTROL;
return VXTU_SCAN_RCONTROL;
case SDL_SCANCODE_A:
return VXTU_SCAN_A;
case SDL_SCANCODE_S:
Expand Down Expand Up @@ -114,7 +115,7 @@ static enum vxtu_scancode sdl_to_xt_scan(SDL_Scancode scan) {
case SDL_SCANCODE_LSHIFT:
return VXTU_SCAN_LSHIFT;
case SDL_SCANCODE_BACKSLASH:
return VXTU_SCAN_BACKSLASH;
return VXTU_SCAN_INT2;
case SDL_SCANCODE_Z:
return VXTU_SCAN_Z;
case SDL_SCANCODE_X:
Expand All @@ -140,8 +141,9 @@ static enum vxtu_scancode sdl_to_xt_scan(SDL_Scancode scan) {
case SDL_SCANCODE_PRINTSCREEN:
return VXTU_SCAN_PRINT;
case SDL_SCANCODE_LALT:
return VXTU_SCAN_LALT;
case SDL_SCANCODE_RALT:
return VXTU_SCAN_ALT;
return VXTU_SCAN_RALT;
case SDL_SCANCODE_SPACE:
return VXTU_SCAN_SPACE;
case SDL_SCANCODE_CAPSLOCK:
Expand Down Expand Up @@ -200,6 +202,217 @@ static enum vxtu_scancode sdl_to_xt_scan(SDL_Scancode scan) {
return VXTU_SCAN_KP_INSERT;
case SDL_SCANCODE_KP_COMMA:
return VXTU_SCAN_KP_DELETE;
case SDL_SCANCODE_SYSREQ:
return VXTU_SCAN_SYS_REQ;
default:
return VXTU_SCAN_INVALID;
}
}

static enum vxtu_scancode sdl_to_model_m(SDL_Scancode scan) {
switch ((int)scan) {
case SDL_SCANCODE_ESCAPE:
return VXTU_SCAN_ESCAPE;
case SDL_SCANCODE_1:
return VXTU_SCAN_1;
case SDL_SCANCODE_2:
return VXTU_SCAN_2;
case SDL_SCANCODE_3:
return VXTU_SCAN_3;
case SDL_SCANCODE_4:
return VXTU_SCAN_4;
case SDL_SCANCODE_5:
return VXTU_SCAN_5;
case SDL_SCANCODE_6:
return VXTU_SCAN_6;
case SDL_SCANCODE_7:
return VXTU_SCAN_7;
case SDL_SCANCODE_8:
return VXTU_SCAN_8;
case SDL_SCANCODE_9:
return VXTU_SCAN_9;
case SDL_SCANCODE_0:
return VXTU_SCAN_0;
case SDL_SCANCODE_MINUS:
return VXTU_SCAN_MINUS;
case SDL_SCANCODE_EQUALS:
return VXTU_SCAN_EQUAL;
case SDL_SCANCODE_BACKSPACE:
return VXTU_SCAN_BACKSPACE;
case SDL_SCANCODE_TAB:
return VXTU_SCAN_TAB;
case SDL_SCANCODE_Q:
return VXTU_SCAN_Q;
case SDL_SCANCODE_W:
return VXTU_SCAN_W;
case SDL_SCANCODE_E:
return VXTU_SCAN_E;
case SDL_SCANCODE_R:
return VXTU_SCAN_R;
case SDL_SCANCODE_T:
return VXTU_SCAN_T;
case SDL_SCANCODE_Y:
return VXTU_SCAN_Y;
case SDL_SCANCODE_U:
return VXTU_SCAN_U;
case SDL_SCANCODE_I:
return VXTU_SCAN_I;
case SDL_SCANCODE_O:
return VXTU_SCAN_O;
case SDL_SCANCODE_P:
return VXTU_SCAN_P;
case SDL_SCANCODE_LEFTBRACKET:
return VXTU_SCAN_LBRACKET;
case SDL_SCANCODE_RIGHTBRACKET:
return VXTU_SCAN_RBRACKET;
case SDL_SCANCODE_RETURN:
return VXTU_SCAN_ENTER;
case SDL_SCANCODE_KP_ENTER:
return VXTU_SCAN_KP_ENTER;
case SDL_SCANCODE_LCTRL:
return VXTU_SCAN_LCONTROL;
case SDL_SCANCODE_RCTRL:
return VXTU_SCAN_RCONTROL;
case SDL_SCANCODE_A:
return VXTU_SCAN_A;
case SDL_SCANCODE_S:
return VXTU_SCAN_S;
case SDL_SCANCODE_D:
return VXTU_SCAN_D;
case SDL_SCANCODE_F:
return VXTU_SCAN_F;
case SDL_SCANCODE_G:
return VXTU_SCAN_G;
case SDL_SCANCODE_H:
return VXTU_SCAN_H;
case SDL_SCANCODE_J:
return VXTU_SCAN_J;
case SDL_SCANCODE_K:
return VXTU_SCAN_K;
case SDL_SCANCODE_L:
return VXTU_SCAN_L;
case SDL_SCANCODE_SEMICOLON:
return VXTU_SCAN_SEMICOLON;
case SDL_SCANCODE_APOSTROPHE:
return VXTU_SCAN_QUOTE;
case SDL_SCANCODE_GRAVE:
return VXTU_SCAN_BACKQUOTE;
case SDL_SCANCODE_LSHIFT:
return VXTU_SCAN_LSHIFT;
case SDL_SCANCODE_BACKSLASH:
return VXTU_SCAN_INT2;
case SDL_SCANCODE_Z:
return VXTU_SCAN_Z;
case SDL_SCANCODE_X:
return VXTU_SCAN_X;
case SDL_SCANCODE_C:
return VXTU_SCAN_C;
case SDL_SCANCODE_V:
return VXTU_SCAN_V;
case SDL_SCANCODE_B:
return VXTU_SCAN_B;
case SDL_SCANCODE_N:
return VXTU_SCAN_N;
case SDL_SCANCODE_M:
return VXTU_SCAN_M;
case SDL_SCANCODE_COMMA:
return VXTU_SCAN_COMMA;
case SDL_SCANCODE_PERIOD:
return VXTU_SCAN_PERIOD;
case SDL_SCANCODE_SLASH:
return VXTU_SCAN_SLASH;
case SDL_SCANCODE_RSHIFT:
return VXTU_SCAN_RSHIFT;
case SDL_SCANCODE_PRINTSCREEN:
return VXTU_SCAN_PRINT;
case SDL_SCANCODE_LALT:
return VXTU_SCAN_LALT;
case SDL_SCANCODE_RALT:
return VXTU_SCAN_RALT;
case SDL_SCANCODE_SPACE:
return VXTU_SCAN_SPACE;
case SDL_SCANCODE_CAPSLOCK:
return VXTU_SCAN_CAPSLOCK;
case SDL_SCANCODE_F1:
return VXTU_SCAN_F1;
case SDL_SCANCODE_F2:
return VXTU_SCAN_F2;
case SDL_SCANCODE_F3:
return VXTU_SCAN_F3;
case SDL_SCANCODE_F4:
return VXTU_SCAN_F4;
case SDL_SCANCODE_F5:
return VXTU_SCAN_F5;
case SDL_SCANCODE_F6:
return VXTU_SCAN_F6;
case SDL_SCANCODE_F7:
return VXTU_SCAN_F7;
case SDL_SCANCODE_F8:
return VXTU_SCAN_F8;
case SDL_SCANCODE_F9:
return VXTU_SCAN_F9;
case SDL_SCANCODE_F10:
return VXTU_SCAN_F10;
case SDL_SCANCODE_F11:
return VXTU_SCAN_F11;
case SDL_SCANCODE_F12:
return VXTU_SCAN_F12;
case SDL_SCANCODE_NUMLOCKCLEAR:
return VXTU_SCAN_NUMLOCK;
case SDL_SCANCODE_SCROLLLOCK:
return VXTU_SCAN_SCRLOCK;
case SDL_SCANCODE_KP_7:
return VXTU_SCAN_KP_HOME;
case SDL_SCANCODE_KP_8:
return VXTU_SCAN_KP_UP;
case SDL_SCANCODE_UP:
return VXTU_SCAN_UP;
case SDL_SCANCODE_KP_9:
return VXTU_SCAN_KP_PAGEUP;
case SDL_SCANCODE_KP_MINUS:
return VXTU_SCAN_KP_MINUS;
case SDL_SCANCODE_KP_4:
return VXTU_SCAN_KP_LEFT;
case SDL_SCANCODE_LEFT:
return VXTU_SCAN_LEFT;
case SDL_SCANCODE_KP_5:
return VXTU_SCAN_KP_5;
case SDL_SCANCODE_KP_6:
return VXTU_SCAN_KP_RIGHT;
case SDL_SCANCODE_RIGHT:
return VXTU_SCAN_RIGHT;
case SDL_SCANCODE_KP_PLUS:
return VXTU_SCAN_KP_PLUS;
case SDL_SCANCODE_KP_1:
return VXTU_SCAN_KP_END;
case SDL_SCANCODE_KP_2:
return VXTU_SCAN_KP_DOWN;
case SDL_SCANCODE_DOWN:
return VXTU_SCAN_DOWN;
case SDL_SCANCODE_KP_3:
return VXTU_SCAN_KP_PAGEDOWN;
case SDL_SCANCODE_KP_0:
return VXTU_SCAN_KP_INSERT;
case SDL_SCANCODE_KP_COMMA:
return VXTU_SCAN_KP_DELETE;
case SDL_SCANCODE_DELETE:
return VXTU_SCAN_DELETE;
case SDL_SCANCODE_INSERT:
return VXTU_SCAN_INSERT;
case SDL_SCANCODE_SYSREQ:
return VXTU_SCAN_SYS_REQ;
case SDL_SCANCODE_KP_MULTIPLY:
return VXTU_SCAN_KP_MUL;
case SDL_SCANCODE_KP_DIVIDE:
return VXTU_SCAN_KP_DIV;
case SDL_SCANCODE_END:
return VXTU_SCAN_END;
case SDL_SCANCODE_HOME:
return VXTU_SCAN_HOME;
case SDL_SCANCODE_PAGEUP:
return VXTU_SCAN_PAGEUP;
case SDL_SCANCODE_PAGEDOWN:
return VXTU_SCAN_PAGEDOWN;
default:
return VXTU_SCAN_INVALID;
}
Expand Down
Loading

0 comments on commit a64ad31

Please sign in to comment.