1.70beta0 pandora release
authornotaz <notasas@gmail.com>
Tue, 22 Dec 2009 11:06:52 +0000 (11:06 +0000)
committernotaz <notasas@gmail.com>
Tue, 22 Dec 2009 11:06:52 +0000 (11:06 +0000)
git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@847 be3aeb3a-fb24-0410-a615-afba39da0efa

linux/in_evdev.c
linux/x11h.c [new file with mode: 0644]
linux/x11h.h [new file with mode: 0644]
pandora/Makefile
pandora/pandora.c

index df40368..631bb3d 100644 (file)
@@ -411,16 +411,20 @@ static const struct {
        { KEY_LEFT,     PBTN_LEFT },
        { KEY_RIGHT,    PBTN_RIGHT },
        { KEY_ENTER,    PBTN_MOK },
-       { BTN_A,        PBTN_MOK },
+       { KEY_KP2,      PBTN_MOK },
        { BTN_TRIGGER,  PBTN_MOK },
        { KEY_ESC,      PBTN_MBACK },
-       { BTN_B,        PBTN_MBACK },
+       { KEY_KP3,      PBTN_MBACK },
        { BTN_THUMB,    PBTN_MBACK },
        { KEY_A,        PBTN_MA2 },
+       { KEY_KP4,      PBTN_MA2 },
        { KEY_S,        PBTN_MA3 },
+       { KEY_KP1,      PBTN_MA3 },
        { KEY_BACKSLASH,  PBTN_MENU },
-       { KEY_MENU,       PBTN_MENU },
+       { KEY_LEFTCTRL,   PBTN_MENU },
+       { BTN_TL,         PBTN_L },
        { KEY_LEFTBRACE,  PBTN_L },
+       { BTN_TR,         PBTN_R },
        { KEY_RIGHTBRACE, PBTN_R },
 };
 
@@ -483,15 +487,16 @@ static const struct {
        { KEY_LEFT,     IN_BINDTYPE_PLAYER12, 2 },
        { KEY_RIGHT,    IN_BINDTYPE_PLAYER12, 3 },
        { KEY_S,        IN_BINDTYPE_PLAYER12, 4 },      /* B */
-       { BTN_B,        IN_BINDTYPE_PLAYER12, 4 },
+       { KEY_KP3,      IN_BINDTYPE_PLAYER12, 4 },
        { KEY_D,        IN_BINDTYPE_PLAYER12, 5 },      /* C */
-       { BTN_A,        IN_BINDTYPE_PLAYER12, 5 },
+       { KEY_KP2,      IN_BINDTYPE_PLAYER12, 5 },
        { KEY_A,        IN_BINDTYPE_PLAYER12, 6 },      /* A */
-       { BTN_Y,        IN_BINDTYPE_PLAYER12, 6 },
+       { KEY_KP4,      IN_BINDTYPE_PLAYER12, 6 },
        { KEY_ENTER,    IN_BINDTYPE_PLAYER12, 7 },
-       { BTN_START,    IN_BINDTYPE_PLAYER12, 7 },
+       { KEY_LEFTALT,  IN_BINDTYPE_PLAYER12, 7 },
        { BTN_TL,       IN_BINDTYPE_EMU, PEVB_STATE_LOAD },
        { BTN_TR,       IN_BINDTYPE_EMU, PEVB_STATE_SAVE },
+       { KEY_LEFTCTRL, IN_BINDTYPE_EMU, PEVB_MENU },
 };
 
 #define DEF_BIND_COUNT (sizeof(in_evdev_def_binds) / sizeof(in_evdev_def_binds[0]))
diff --git a/linux/x11h.c b/linux/x11h.c
new file mode 100644 (file)
index 0000000..4ca5d30
--- /dev/null
@@ -0,0 +1,179 @@
+#include <stdio.h>
+#include <string.h>
+#include <pthread.h>
+#include <dlfcn.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+
+#define FPTR(f) typeof(f) * p##f
+#define FPTR_LINK(xf, dl, f) { \
+       xf.p##f = dlsym(dl, #f); \
+       if (xf.p##f == NULL) { \
+               fprintf(stderr, "missing symbol: %s\n", #f); \
+               goto fail; \
+       } \
+}
+
+struct xfuncs {
+FPTR(XCreateBitmapFromData);
+FPTR(XCreatePixmapCursor);
+FPTR(XFreePixmap);
+FPTR(XOpenDisplay);
+FPTR(XDisplayName);
+FPTR(XCloseDisplay);
+FPTR(XCreateSimpleWindow);
+FPTR(XChangeWindowAttributes);
+FPTR(XSelectInput);
+FPTR(XMapWindow);
+FPTR(XNextEvent);
+FPTR(XCheckTypedEvent);
+FPTR(XUnmapWindow);
+FPTR(XGrabKeyboard);
+};
+
+
+static Cursor transparent_cursor(struct xfuncs *xf, Display *display, Window win)
+{
+       Cursor cursor;
+       Pixmap pix;
+       XColor dummy;
+       char d = 0;
+
+       memset(&dummy, 0, sizeof(dummy));
+       pix = xf->pXCreateBitmapFromData(display, win, &d, 1, 1);
+       cursor = xf->pXCreatePixmapCursor(display, pix, pix,
+                       &dummy, &dummy, 0, 0);
+       xf->pXFreePixmap(display, pix);
+       return cursor;
+}
+
+static void *x11h_handler(void *arg)
+{
+       struct xfuncs xf;
+       unsigned int display_width, display_height;
+       XSetWindowAttributes attributes;
+       Window win;
+       XEvent report;
+       Display *display;
+       Visual *visual;
+       void *x11lib;
+       int screen;
+
+       memset(&xf, 0, sizeof(xf));
+       x11lib = dlopen("libX11.so.6", RTLD_LAZY);
+       if (x11lib == NULL) {
+               fprintf(stderr, "libX11.so load failed:\n%s\n", dlerror());
+               goto fail;
+       }
+       FPTR_LINK(xf, x11lib, XCreateBitmapFromData);
+       FPTR_LINK(xf, x11lib, XCreatePixmapCursor);
+       FPTR_LINK(xf, x11lib, XFreePixmap);
+       FPTR_LINK(xf, x11lib, XOpenDisplay);
+       FPTR_LINK(xf, x11lib, XDisplayName);
+       FPTR_LINK(xf, x11lib, XCloseDisplay);
+       FPTR_LINK(xf, x11lib, XCreateSimpleWindow);
+       FPTR_LINK(xf, x11lib, XChangeWindowAttributes);
+       FPTR_LINK(xf, x11lib, XSelectInput);
+       FPTR_LINK(xf, x11lib, XMapWindow);
+       FPTR_LINK(xf, x11lib, XNextEvent);
+       FPTR_LINK(xf, x11lib, XCheckTypedEvent);
+       FPTR_LINK(xf, x11lib, XUnmapWindow);
+       FPTR_LINK(xf, x11lib, XGrabKeyboard);
+
+       //XInitThreads();
+
+       display = xf.pXOpenDisplay(NULL);
+       if (display == NULL)
+       {
+               fprintf(stderr, "cannot connect to X server %s, X handling disabled.\n",
+                               xf.pXDisplayName(NULL));
+               goto fail2;
+       }
+
+       visual = DefaultVisual(display, 0);
+       if (visual->class != TrueColor)
+       {
+               fprintf(stderr, "cannot handle non true color visual\n");
+               xf.pXCloseDisplay(display);
+               goto fail2;
+       }
+
+       printf("x11h: X vendor: %s, rel: %d, display: %s, protocol ver: %d.%d\n", ServerVendor(display),
+               VendorRelease(display), DisplayString(display), ProtocolVersion(display),
+               ProtocolRevision(display));
+
+       screen = DefaultScreen(display);
+
+       display_width = DisplayWidth(display, screen);
+       display_height = DisplayHeight(display, screen);
+       printf("x11h: display is %dx%d\n", display_width, display_height);
+
+       win = xf.pXCreateSimpleWindow(display,
+                       RootWindow(display, screen),
+                       0, 0, display_width, display_height, 0,
+                       BlackPixel(display, screen),
+                       BlackPixel(display, screen));
+
+       attributes.override_redirect = True;
+       attributes.cursor = transparent_cursor(&xf, display, win);
+       xf.pXChangeWindowAttributes(display, win, CWOverrideRedirect | CWCursor, &attributes);
+
+       xf.pXSelectInput(display, win, ExposureMask | FocusChangeMask | KeyPressMask | KeyReleaseMask);
+       xf.pXMapWindow(display, win);
+       xf.pXGrabKeyboard(display, win, False, GrabModeAsync, GrabModeAsync, CurrentTime);
+       // XSetIOErrorHandler
+
+       while (1)
+       {
+               xf.pXNextEvent(display, &report);
+               switch (report.type)
+               {
+                       case Expose:
+                               while (xf.pXCheckTypedEvent(display, Expose, &report))
+                                       ;
+                               break;
+
+                       case FocusOut:
+                               // XFocusChangeEvent
+                               // printf("focus out\n");
+                               // xf.pXUnmapWindow(display, win);
+                               break;
+
+                       case KeyPress:
+                               // printf("press %d\n", report.xkey.keycode);
+                               break;
+
+                       default:
+                               break;
+               }
+       }
+
+fail2:
+       dlclose(x11lib);
+fail:
+       fprintf(stderr, "x11 handling disabled.\n");
+       return NULL;
+}
+
+int x11h_init(void)
+{
+       pthread_t tid;
+       int ret;
+
+       ret = pthread_create(&tid, NULL, x11h_handler, NULL);
+       if (ret != 0) {
+               fprintf(stderr, "x11h: failed to create thread: %d\n", ret);
+               return ret;
+       }
+       pthread_detach(tid);
+
+       return 0;
+}
+
+#if 0
+int main()
+{
+       x11h_init();
+       sleep(5);
+}
+#endif
diff --git a/linux/x11h.h b/linux/x11h.h
new file mode 100644 (file)
index 0000000..b491b48
--- /dev/null
@@ -0,0 +1,2 @@
+int x11h_init(void);
+
index c70c835..875c253 100644 (file)
@@ -33,7 +33,7 @@ CFLAGS += -Wall -Winline -mcpu=cortex-a8 -mtune=cortex-a8 -march=armv7-a
 ifeq ($(DEBUG),)\r
 CFLAGS += -O2 -fomit-frame-pointer -fstrict-aliasing -ffast-math\r
 endif\r
-LDFLAGS += -lm -lpng -L$(LIBROOT)/lib -static\r
+LDFLAGS += -L$(LIBROOT)/lib -Wl,-Bstatic -lpng -Wl,-Bdynamic -lm -lpthread -ldl\r
 ASFLAGS = -mcpu=cortex-a8\r
 CC = $(CROSS)gcc\r
 STRIP = $(CROSS)strip\r
@@ -49,7 +49,7 @@ OBJS += platform/common/emu.o platform/common/menu.o platform/common/fonts.o pla
        platform/common/arm_utils.o platform/common/mp3_helix.o platform/common/arm_linux.o \\r
        platform/common/readpng.o platform/common/input.o platform/common/main.o \\r
        platform/linux/fbdev.o platform/linux/in_evdev.o platform/linux/sndout_oss.o \\r
-       platform/linux/plat.o\r
+       platform/linux/plat.o platform/linux/x11h.o\r
 \r
 # ARM stuff\r
 OBJS += pico/carthw/svp/compiler.o pico/carthw/svp/stub_arm.o\r
index 4019994..736052f 100644 (file)
@@ -4,6 +4,7 @@
 \r
 #include "../linux/sndout_oss.h"\r
 #include "../linux/fbdev.h"\r
+#include "../linux/x11h.h"\r
 #include "../common/emu.h"\r
 \r
 void plat_early_init(void)\r
@@ -14,6 +15,8 @@ void plat_init(void)
 {\r
        int ret, w, h;\r
 \r
+       x11h_init();\r
+\r
        ret = vout_fbdev_init(&w, &h);\r
        if (ret != 0) {\r
                fprintf(stderr, "couldn't init framebuffer\n");\r