From 96b49d496e40fd96726057c2e5e66bc27bf4a2fc Mon Sep 17 00:00:00 2001 From: neauoire Date: Mon, 28 Mar 2022 09:39:05 -0700 Subject: [PATCH] Fixed issue with controller/key --- README.md | 2 +- build.sh | 2 +- src/uxn11.c | 43 ++++++++++++++++++++++++------------------- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 350ed78..be25be5 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ cc src/devices/datetime.c src/devices/system.c src/devices/file.c src/uxn.c -DND - `20` screen(partial/vector) - `30` audio(missing) - `70` midi(missing) -- `80` controller(partial/key) +- `80` controller - `90` mouse(partial/scroll) - `a0` file(missing) - `c0` datetime diff --git a/build.sh b/build.sh index adeeca6..b1271ba 100755 --- a/build.sh +++ b/build.sh @@ -15,4 +15,4 @@ gcc -std=c89 -D_POSIX_C_SOURCE=199309L -DDEBUG -Wall -Wno-unknown-pragmas -Wpeda # gcc src/uxn.c src/devices/system.c src/devices/screen.c src/devices/controller.c src/devices/mouse.c src/devices/file.c src/devices/datetime.c src/uxn11.c -o bin/uxn11 -lX11 echo "Running.." -bin/uxn11 etc/mouse.rom +bin/uxn11 ~/roms/left.rom # etc/mouse.rom diff --git a/src/uxn11.c b/src/uxn11.c index 3142ddf..f377fb3 100644 --- a/src/uxn11.c +++ b/src/uxn11.c @@ -117,6 +117,22 @@ hide_cursor(void) #define XK_Control 0xffe3 #define XK_Alt 0xffe9 +static Uint8 +get_button(KeySym sym) +{ + switch(sym) { + case XK_Up: return 0x10; + case XK_Down: return 0x20; + case XK_Left: return 0x40; + case XK_Right: return 0x80; + case XK_Control: return 0x01; + case XK_Alt: return 0x02; + case XK_Shift: return 0x04; + case XK_Home: return 0x08; + } + return 0x00; +} + static void processEvent(void) { @@ -134,29 +150,18 @@ processEvent(void) } break; case KeyPress: { XKeyPressedEvent *e = (XKeyPressedEvent *)&ev; + KeySym sym; char buf[7]; - if(e->keycode == XKeysymToKeycode(display, XK_Escape)) exit(0); - if(e->keycode == XKeysymToKeycode(display, XK_Up)) controller_down(devctrl, 0x10); - if(e->keycode == XKeysymToKeycode(display, XK_Down)) controller_down(devctrl, 0x20); - if(e->keycode == XKeysymToKeycode(display, XK_Left)) controller_down(devctrl, 0x40); - if(e->keycode == XKeysymToKeycode(display, XK_Right)) controller_down(devctrl, 0x80); - if(e->keycode == XKeysymToKeycode(display, XK_Control)) controller_down(devctrl, 0x01); - if(e->keycode == XKeysymToKeycode(display, XK_Alt)) controller_down(devctrl, 0x02); - if(e->keycode == XKeysymToKeycode(display, XK_Shift)) controller_down(devctrl, 0x04); - if(e->keycode == XKeysymToKeycode(display, XK_Home)) controller_down(devctrl, 0x08); - XLookupString(e, buf, 7, NULL, NULL); - controller_key(devctrl, buf[0]); + XLookupString(e, buf, 7, &sym, 0); + controller_down(devctrl, get_button(sym)); + controller_key(devctrl, sym < 0x80 ? sym : buf[0]); } break; case KeyRelease: { XKeyPressedEvent *e = (XKeyPressedEvent *)&ev; - if(e->keycode == XKeysymToKeycode(display, XK_Up)) controller_up(devctrl, 0x10); - if(e->keycode == XKeysymToKeycode(display, XK_Down)) controller_up(devctrl, 0x20); - if(e->keycode == XKeysymToKeycode(display, XK_Left)) controller_up(devctrl, 0x40); - if(e->keycode == XKeysymToKeycode(display, XK_Right)) controller_up(devctrl, 0x80); - if(e->keycode == XKeysymToKeycode(display, XK_Control)) controller_up(devctrl, 0x01); - if(e->keycode == XKeysymToKeycode(display, XK_Alt)) controller_up(devctrl, 0x02); - if(e->keycode == XKeysymToKeycode(display, XK_Shift)) controller_up(devctrl, 0x04); - if(e->keycode == XKeysymToKeycode(display, XK_Home)) controller_up(devctrl, 0x08); + KeySym sym; + char buf[7]; + XLookupString(e, buf, 7, &sym, 0); + controller_up(devctrl, get_button(sym)); } break; case ButtonPress: { XButtonPressedEvent *e = (XButtonPressedEvent *)&ev;