5 #include "../common/emu.h"
6 #include "../common/menu.h"
7 #include "../common/plat.h"
8 #include "../common/input.h"
9 #include "sndout_oss.h"
15 unsigned char *PicoDraw2FB;
24 #include <semaphore.h>
26 static int current_bpp = 16;
27 static int current_pal[256];
28 static const char *verstring = "PicoDrive " VERSION;
29 static int scr_changed = 0, scr_w = SCREEN_WIDTH, scr_h = SCREEN_HEIGHT;
32 enum { GP2X_UP=0x1, GP2X_LEFT=0x4, GP2X_DOWN=0x10, GP2X_RIGHT=0x40,
33 GP2X_START=1<<8, GP2X_SELECT=1<<9, GP2X_L=1<<10, GP2X_R=1<<11,
34 GP2X_A=1<<12, GP2X_B=1<<13, GP2X_X=1<<14, GP2X_Y=1<<15,
35 GP2X_VOL_UP=1<<23, GP2X_VOL_DOWN=1<<22, GP2X_PUSH=1<<27 };
37 static void key_press_event(int keycode)
42 case 0x62: current_keys |= GP2X_UP; break;
44 case 0x68: current_keys |= GP2X_DOWN; break;
46 case 0x64: current_keys |= GP2X_LEFT; break;
48 case 0x66: current_keys |= GP2X_RIGHT; break;
49 case 0x24: current_keys |= GP2X_START; break; // enter
50 case 0x23: current_keys |= GP2X_SELECT;break; // ]
51 case 0x34: current_keys |= GP2X_A; break; // z
52 case 0x35: current_keys |= GP2X_X; break; // x
53 case 0x36: current_keys |= GP2X_B; break; // c
54 case 0x37: current_keys |= GP2X_Y; break; // v
55 case 0x27: current_keys |= GP2X_L; break; // s
56 case 0x28: current_keys |= GP2X_R; break; // d
57 case 0x29: current_keys |= GP2X_PUSH; break; // f
58 case 0x18: current_keys |= GP2X_VOL_DOWN;break; // q
59 case 0x19: current_keys |= GP2X_VOL_UP;break; // w
60 case 0x2d: log_io_clear(); break; // k
61 case 0x2e: log_io_dump(); break; // l
63 extern int PicoReset(void);
70 static void key_release_event(int keycode)
75 case 0x62: current_keys &= ~GP2X_UP; break;
77 case 0x68: current_keys &= ~GP2X_DOWN; break;
79 case 0x64: current_keys &= ~GP2X_LEFT; break;
81 case 0x66: current_keys &= ~GP2X_RIGHT; break;
82 case 0x24: current_keys &= ~GP2X_START; break; // enter
83 case 0x23: current_keys &= ~GP2X_SELECT;break; // ]
84 case 0x34: current_keys &= ~GP2X_A; break; // z
85 case 0x35: current_keys &= ~GP2X_X; break; // x
86 case 0x36: current_keys &= ~GP2X_B; break; // c
87 case 0x37: current_keys &= ~GP2X_Y; break; // v
88 case 0x27: current_keys &= ~GP2X_L; break; // s
89 case 0x28: current_keys &= ~GP2X_R; break; // d
90 case 0x29: current_keys &= ~GP2X_PUSH; break; // f
91 case 0x18: current_keys &= ~GP2X_VOL_DOWN;break; // q
92 case 0x19: current_keys &= ~GP2X_VOL_UP;break; // w
99 #include <X11/Xutil.h>
101 static Display *xlib_display;
102 static Window xlib_window;
103 static XImage *ximage;
105 static void ximage_realloc(Display *display, Visual *visual)
109 XLockDisplay(xlib_display);
112 XDestroyImage(ximage);
115 xlib_screen = calloc(scr_w * scr_h, 4);
116 if (xlib_screen != NULL)
117 ximage = XCreateImage(display, visual, 24, ZPixmap, 0,
118 xlib_screen, scr_w, scr_h, 32, 0);
120 fprintf(stderr, "failed to alloc ximage\n");
122 XUnlockDisplay(xlib_display);
125 static void xlib_update(void)
129 XLockDisplay(xlib_display);
131 xstatus = XPutImage(xlib_display, xlib_window, DefaultGC(xlib_display, 0), ximage,
132 0, 0, 0, 0, g_screen_width, g_screen_height);
134 fprintf(stderr, "XPutImage %d\n", xstatus);
136 XUnlockDisplay(xlib_display);
139 static void *xlib_threadf(void *targ)
141 unsigned int width, height, display_width, display_height;
143 XTextProperty windowName;
152 xlib_display = display = XOpenDisplay(NULL);
155 fprintf(stderr, "cannot connect to X server %s\n",
161 visual = DefaultVisual(display, 0);
162 if (visual->class != TrueColor)
164 fprintf(stderr, "cannot handle non true color visual\n");
165 XCloseDisplay(display);
170 printf("X vendor: %s, rel: %d, display: %s, protocol ver: %d.%d\n", ServerVendor(display),
171 VendorRelease(display), DisplayString(display), ProtocolVersion(display),
172 ProtocolRevision(display));
174 screen = DefaultScreen(display);
176 ximage_realloc(display, visual);
179 display_width = DisplayWidth(display, screen);
180 display_height = DisplayHeight(display, screen);
182 xlib_window = win = XCreateSimpleWindow(display,
183 RootWindow(display, screen),
184 display_width / 2 - scr_w / 2,
185 display_height / 2 - scr_h / 2,
186 scr_w + 2, scr_h + 2, 1,
187 BlackPixel(display, screen),
188 BlackPixel(display, screen));
190 XStringListToTextProperty((char **)&verstring, 1, &windowName);
191 XSetWMName(display, win, &windowName);
193 XSelectInput(display, win, ExposureMask |
194 KeyPressMask | KeyReleaseMask |
195 StructureNotifyMask);
197 XMapWindow(display, win);
201 XNextEvent(display, &report);
205 while (XCheckTypedEvent(display, Expose, &report))
210 case ConfigureNotify:
211 width = report.xconfigure.width;
212 height = report.xconfigure.height;
213 if (scr_w != width - 2 || scr_h != height - 2) {
224 key_press_event(report.xkey.keycode);
228 key_release_event(report.xkey.keycode);
237 static void xlib_init(void)
242 sem_init(&xlib_sem, 0, 0);
244 pthread_create(&x_thread, NULL, xlib_threadf, &xlib_sem);
245 pthread_detach(x_thread);
248 sem_destroy(&xlib_sem);
253 static void realloc_screen(void)
255 int size = scr_w * scr_h * 2;
256 g_screen_width = g_menuscreen_w = scr_w;
257 g_screen_height = g_menuscreen_h = scr_h;
258 g_screen_ptr = realloc(g_screen_ptr, size);
259 g_menubg_ptr = realloc(g_menubg_ptr, size);
260 memset(g_screen_ptr, 0, size);
261 memset(g_menubg_ptr, 0, size);
262 PicoDraw2FB = g_menubg_ptr;
266 void plat_video_flip(void)
274 pixel_count = g_screen_width * g_screen_height;
275 image = (void *)ximage->data;
277 if (current_bpp == 8)
279 unsigned char *pixels = g_screen_ptr;
282 for (i = 0; i < pixel_count; i++)
284 pix = current_pal[pixels[i]];
290 unsigned short *pixels = g_screen_ptr;
292 for (i = 0; i < pixel_count; i++)
294 /* in: rrrr rggg gggb bbbb */
295 /* out: rrrr r000 gggg gg00 bbbb b000 */
296 image[i] = (pixels[i] << 8) & 0xf80000;
297 image[i] |= (pixels[i] << 5) & 0x00fc00;
298 image[i] |= (pixels[i] << 3) & 0x0000f8;
305 ximage_realloc(xlib_display, DefaultVisual(xlib_display, 0));
307 // propagate new ponters to renderers
308 plat_video_toggle_renderer(0, 0);
312 void plat_video_wait_vsync(void)
318 void plat_early_init(void)
326 ret = vout_fbdev_init(&w, &h);
329 g_screen_width = g_menuscreen_w = w;
330 g_screen_height = g_menuscreen_h = h;
331 g_menubg_ptr = realloc(g_menubg_ptr, w * g_screen_height * 2);
332 PicoDraw2FB = g_menubg_ptr;
335 memset(g_screen_ptr, 0, g_screen_width * g_screen_height * 2);
343 void plat_finish(void)
354 int mp3_get_bitrate(void *f, int size)
359 void mp3_start_play(void *f, int pos)
363 void mp3_update(int *buffer, int length, int stereo)
367 #include <linux/input.h>
369 struct in_default_bind in_evdev_defbinds[] =
372 { KEY_UP, IN_BINDTYPE_PLAYER12, 0 },
373 { KEY_DOWN, IN_BINDTYPE_PLAYER12, 1 },
374 { KEY_LEFT, IN_BINDTYPE_PLAYER12, 2 },
375 { KEY_RIGHT, IN_BINDTYPE_PLAYER12, 3 },
376 { KEY_S, IN_BINDTYPE_PLAYER12, 4 }, /* B */
377 { KEY_D, IN_BINDTYPE_PLAYER12, 5 }, /* C */
378 { KEY_A, IN_BINDTYPE_PLAYER12, 6 }, /* A */
379 { KEY_ENTER, IN_BINDTYPE_PLAYER12, 7 },
380 { KEY_BACKSLASH, IN_BINDTYPE_EMU, PEVB_MENU },