+#ifdef WIZ_BUILD
+#include <linux/fb.h>
+void *gpsp_gp2x_screen;
+#define fb_buf_count 4
+static u32 fb_paddr[fb_buf_count];
+static void *fb_vaddr[fb_buf_count];
+static u32 fb_work_buf;
+static int fb_buf_use;
+static int fbdev;
+
+static void fb_video_init()
+{
+ struct fb_fix_screeninfo fbfix;
+ int i, ret;
+
+ fbdev = open("/dev/fb0", O_RDWR);
+ if (fbdev < 0) {
+ perror("can't open fbdev");
+ exit(1);
+ }
+
+ ret = ioctl(fbdev, FBIOGET_FSCREENINFO, &fbfix);
+ if (ret == -1)
+ {
+ perror("ioctl(fbdev) failed");
+ exit(1);
+ }
+
+ printf("framebuffer: \"%s\" @ %08lx\n", fbfix.id, fbfix.smem_start);
+ fb_paddr[0] = fbfix.smem_start;
+
+ fb_vaddr[0] = mmap(0, 320*240*2*fb_buf_count, PROT_READ|PROT_WRITE,
+ MAP_SHARED, gpsp_gp2x_dev, fb_paddr[0]);
+ if (fb_vaddr[0] == MAP_FAILED)
+ {
+ perror("mmap(fb_vaddr) failed");
+ exit(1);
+ }
+ memset(fb_vaddr[0], 0, 320*240*2*fb_buf_count);
+
+ printf(" %p -> %08x\n", fb_vaddr[0], fb_paddr[0]);
+ for (i = 1; i < fb_buf_count; i++)
+ {
+ fb_paddr[i] = fb_paddr[i-1] + 320*240*2;
+ fb_vaddr[i] = (char *)fb_vaddr[i-1] + 320*240*2;
+ printf(" %p -> %08x\n", fb_vaddr[i], fb_paddr[i]);
+ }
+ fb_work_buf = 0;
+ fb_buf_use = fb_buf_count;
+
+ pollux_video_flip();
+ warm_change_cb_upper(WCB_C_BIT|WCB_B_BIT, 1);
+}
+
+void pollux_video_flip()
+{
+ gpsp_gp2x_memregl[0x406C>>2] = fb_paddr[fb_work_buf];
+ gpsp_gp2x_memregl[0x4058>>2] |= 0x10;
+ fb_work_buf++;
+ if (fb_work_buf >= fb_buf_use)
+ fb_work_buf = 0;
+ gpsp_gp2x_screen = fb_vaddr[fb_work_buf];
+}
+
+void fb_use_buffers(int count)
+{
+ if (count < 1)
+ count = 1;
+ else if (count > fb_buf_count)
+ count = fb_buf_count;
+ fb_buf_use = count;
+ memset(fb_vaddr[0], 0, 320*240*2*count);
+}
+
+void wiz_lcd_set_portrait(int y)
+{
+ static int old_y = -1;
+ int cmd[2] = { 0, 0 };
+
+ if (old_y == y)
+ return;
+ cmd[0] = y ? 6 : 5;
+ ioctl(fbdev, _IOW('D', 90, int[2]), cmd);
+ gpsp_gp2x_memregl[0x4004>>2] = y ? 0x013f00ef : 0x00ef013f;
+ gpsp_gp2x_memregl[0x4000>>2] |= 1 << 3;
+ old_y = y;
+
+ /* the above ioctl resets LCD timings, so set them here */
+ pollux_dpc_set(gpsp_gp2x_memregs, getenv("pollux_dpc_set"));
+}
+
+static void fb_video_exit()
+{
+ /* switch to default fb mem, turn portrait off */
+ gpsp_gp2x_memregl[0x406C>>2] = fb_paddr[0];
+ gpsp_gp2x_memregl[0x4058>>2] |= 0x10;
+ wiz_lcd_set_portrait(0);
+ close(fbdev);
+}
+
+static int wiz_gamepak_fd = -1;
+static u32 wiz_gamepak_size;
+
+static void wiz_gamepak_cleanup()
+{
+ if (wiz_gamepak_size)
+ munmap(gamepak_rom, wiz_gamepak_size);
+ if (wiz_gamepak_fd >= 0)
+ close(wiz_gamepak_fd);
+ gamepak_rom = NULL;
+ wiz_gamepak_size = 0;
+ wiz_gamepak_fd = -1;
+}