1 /* gameplaySP - pandora backend
3 * Copyright (C) 2011 notaz <notasas@gmail.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "../common.h"
21 #include <X11/keysym.h>
22 #include "linux/omapfb.h" //
23 #include <sys/types.h>
26 #include <sys/ioctl.h>
28 #include "linux/fbdev.h"
29 #include "linux/xenv.h"
51 u32 button_plat_mask_to_config[PLAT_BUTTON_COUNT] =
72 u32 gamepad_config_map[PLAT_BUTTON_COUNT] =
75 BUTTON_ID_LEFT, // Left
76 BUTTON_ID_DOWN, // Down
77 BUTTON_ID_RIGHT, // Right
78 BUTTON_ID_START, // Start
79 BUTTON_ID_SELECT, // Select
80 BUTTON_ID_L, // Ltrigger
81 BUTTON_ID_R, // Rtrigger
86 BUTTON_ID_SAVESTATE, // 1
87 BUTTON_ID_LOADSTATE, // 2
88 BUTTON_ID_FASTFORWARD, // 3
90 BUTTON_ID_MENU // Space
93 static const u32 xk_to_gkey[] = {
94 XK_Up, XK_Left, XK_Down, XK_Right, XK_Alt_L, XK_Control_L,
95 XK_Shift_L, XK_Control_R, XK_Home, XK_End, XK_Page_Down, XK_Page_Up,
96 XK_1, XK_2, XK_3, XK_4, XK_space,
99 static const u8 gkey_to_cursor[32] = {
100 [0 ... 31] = CURSOR_NONE,
101 [0] = CURSOR_UP, CURSOR_LEFT, CURSOR_DOWN, CURSOR_RIGHT, CURSOR_NONE, CURSOR_NONE,
102 CURSOR_L, CURSOR_R, CURSOR_SELECT, CURSOR_SELECT, CURSOR_EXIT, CURSOR_BACK,
105 struct vout_fbdev *fb;
107 static int omap_setup_layer(int fd, int enabled, int x, int y, int w, int h, int first_call)
109 struct omapfb_plane_info pi = { 0, };
110 struct omapfb_mem_info mi = { 0, };
113 ret = ioctl(fd, OMAPFB_QUERY_PLANE, &pi);
115 perror("QUERY_PLANE");
119 ret = ioctl(fd, OMAPFB_QUERY_MEM, &mi);
125 /* must disable when changing stuff */
128 ret = ioctl(fd, OMAPFB_SETUP_PLANE, &pi);
130 perror("SETUP_PLANE");
134 mi.size = 640*512*3*3;
135 ret = ioctl(fd, OMAPFB_SETUP_MEM, &mi);
146 pi.enabled = enabled;
148 ret = ioctl(fd, OMAPFB_SETUP_PLANE, &pi);
150 perror("SETUP_PLANE");
157 void gpsp_plat_init(void)
160 const char *layer_fb_name;
162 ret = SDL_Init(SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE);
164 fprintf(stderr, "SDL_Init failed: %s\n", SDL_GetError());
168 layer_fb_name = getenv("FBDEV_LAYER");
169 if (layer_fb_name == NULL)
170 layer_fb_name = "/dev/fb1";
174 fprintf(stderr, "xenv_init failed with %d\n", ret);
178 // must set the layer up first to be able to use it
179 fd = open(layer_fb_name, O_RDWR);
181 fprintf(stderr, "%s: ", layer_fb_name);
186 ret = omap_setup_layer(fd, 0, 0, 0, 400, 272, 1);
189 fprintf(stderr, "failed to set up layer, exiting.\n");
195 fb = vout_fbdev_init("/dev/fb1", &w, &h, 16, 4);
197 fprintf(stderr, "vout_fbdev_init failed\n");
201 // default to 3x scale
205 void gpsp_plat_quit(void)
208 omap_setup_layer(vout_fbdev_get_fd(fb), 0, 0, 0, 0, 0, 0);
209 vout_fbdev_finish(fb);
213 u32 gpsp_plat_joystick_read(void)
215 static int gkeystate;
219 key = xenv_update(&is_down);
220 for (i = 0; i < sizeof(xk_to_gkey) / sizeof(xk_to_gkey[0]); i++) {
221 if (key == xk_to_gkey[i]) {
229 gkeystate |= 1 << gkey;
231 gkeystate &= ~(1 << gkey);
237 u32 gpsp_plat_buttons_to_cursor(u32 buttons)
244 for (i = 0; (buttons & 1) == 0; i++, buttons >>= 1)
247 return gkey_to_cursor[i];
250 static void set_filter(int is_filtered)
252 static int was_filtered = -1;
255 if (is_filtered == was_filtered)
258 snprintf(buf, sizeof(buf), "sudo -n /usr/pandora/scripts/op_videofir.sh %s",
259 is_filtered ? "default" : "none");
261 was_filtered = is_filtered;
264 void *fb_flip_screen(void)
266 return vout_fbdev_flip(fb);
269 void fb_wait_vsync(void)
271 vout_fbdev_wait_vsync(fb);
274 void fb_set_mode(int w, int h, int buffers, int scale, int filter)
276 int lx, ly, lw = w, lh = h;
299 fprintf(stderr, "unknown scale: %d\n", scale);
306 lx = 800 / 2 - lw / 2;
307 ly = 480 / 2 - lh / 2;
309 omap_setup_layer(vout_fbdev_get_fd(fb), 1, lx, ly, lw, lh, 0);
312 vout_fbdev_resize(fb, w, h, 16, 0, 0, 0, 0, buffers);
315 // vim:shiftwidth=2:expandtab