From 79adffc887ffcb01f209cbc851b2479133d505b5 Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 12 Apr 2009 14:51:01 +0000 Subject: [PATCH] added mdpcjoy --- mdpcjoy/mdpcjoy.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 mdpcjoy/mdpcjoy.c diff --git a/mdpcjoy/mdpcjoy.c b/mdpcjoy/mdpcjoy.c new file mode 100644 index 0000000..8ae6f82 --- /dev/null +++ b/mdpcjoy/mdpcjoy.c @@ -0,0 +1,111 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main() +{ + int i, ret, fd; + int dpad = 0; + + for (i = 0;; i++) + { + int support = 0; + char name[64]; + + snprintf(name, sizeof(name), "/dev/input/event%d", i); + fd = open(name, O_RDONLY); + if (fd == -1) + break; + + /* check supported events */ + ret = ioctl(fd, EVIOCGBIT(0, sizeof(support)), &support); + if (ret == -1) { + printf("ioctl failed on %s\n", name); + goto skip; + } + + if (!(support & (1 << EV_KEY))) + goto skip; + if (!(support & (1 << EV_ABS))) + goto skip; + + ioctl(fd, EVIOCGNAME(sizeof(name)), name); + printf("found \"%s\" (type %08x)\n", name, support); + break; + +skip: + close(fd); + fd = -1; + } + + if (fd == -1) { + printf("no suitable devs\n"); + return 1; + } + + ret = ioperm(888, 3, 1); + if (ret != 0) { + perror("ioperm"); + return 1; + } + + outb(0xc0, 890); /* switch to output mode, TL and TR high */ + outb(0x0f, 888); /* Dx high */ + + while (1) + { + struct input_event ev; + int rd; + + rd = read(fd, &ev, sizeof(ev)); + if (rd < (int) sizeof(ev)) { + perror("in_evdev: error reading"); + return 1; + } + + if (ev.type == EV_KEY) { + int val = 0xc0; + if (ev.code & 1) { + if (ev.value) + val |= 2; + else + val &= ~2; + } else { + if (ev.value) + val |= 8; + else + val &= ~8; + } + outb(val, 890); + } + else if (ev.type == EV_ABS) + { + if (ev.code == ABS_X) { + if (ev.value < 128) + dpad |= 4; + else if (ev.value > 128) + dpad |= 8; + else + dpad &= ~0x0c; + } + if (ev.code == ABS_Y) { + if (ev.value < 128) + dpad |= 1; + else if (ev.value > 128) + dpad |= 2; + else + dpad &= ~3; + } + outb(~dpad & 0x0f, 888); + } + } + + return 0; +} + -- 2.39.5