+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;
+}
+
+u32 wiz_load_gamepak(char *name)
+{
+ char *dot_position = strrchr(name, '.');
+ u32 ret;
+
+ if (!strcasecmp(dot_position, ".zip"))
+ {
+ if (wiz_gamepak_fd >= 0)
+ {
+ wiz_gamepak_cleanup();
+ printf("switching to ROM malloc\n");
+ init_gamepak_buffer();
+ }
+ return load_file_zip(name);
+ }
+
+ if (wiz_gamepak_fd < 0)
+ {
+ extern void *gamepak_memory_map;
+ free(gamepak_rom);
+ free(gamepak_memory_map);
+ gamepak_memory_map = NULL;
+ printf("switching to ROM mmap\n");
+ }
+ else
+ wiz_gamepak_cleanup();
+
+ wiz_gamepak_fd = open(name, O_RDONLY|O_NOATIME, S_IRUSR);
+ if (wiz_gamepak_fd < 0)
+ {
+ perror("wiz_load_gamepak: open failed");
+ return -1;
+ }
+
+ ret = lseek(wiz_gamepak_fd, 0, SEEK_END);
+ wiz_gamepak_size = gamepak_ram_buffer_size = ret;
+
+ gamepak_rom = mmap(0, ret, PROT_READ, MAP_SHARED, wiz_gamepak_fd, 0);
+ if (gamepak_rom == MAP_FAILED)
+ {
+ perror("wiz_load_gamepak: mmap failed");
+ return -1;
+ }
+
+ return ret;
+}
+
+#define KEYBITS_BIT(x) (keybits[(x)/sizeof(keybits[0])/8] & \
+ (1 << ((x) & (sizeof(keybits[0])*8-1))))
+
+static int abs_min, abs_max, lzone_step;
+
+static int open_caanoo_pad(void)
+{
+ long keybits[KEY_CNT / sizeof(long) / 8];
+ long absbits[(ABS_MAX+1) / sizeof(long) / 8];
+ struct input_absinfo ainfo;
+ int fd = -1, i;
+
+ memset(keybits, 0, sizeof(keybits));
+ memset(absbits, 0, sizeof(absbits));
+
+ for (i = 0;; i++)
+ {
+ int support = 0, need;
+ int ret;
+ char name[64];
+
+ snprintf(name, sizeof(name), "/dev/input/event%d", i);
+ fd = open(name, O_RDONLY|O_NONBLOCK);
+ if (fd == -1)
+ break;
+
+ /* check supported events */
+ ret = ioctl(fd, EVIOCGBIT(0, sizeof(support)), &support);
+ if (ret == -1) {
+ printf("in_evdev: ioctl failed on %s\n", name);
+ goto skip;
+ }
+
+ need = (1 << EV_KEY) | (1 << EV_ABS);
+ if ((support & need) != need)
+ goto skip;
+
+ ret = ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybits)), keybits);
+ if (ret == -1) {
+ printf("in_evdev: ioctl failed on %s\n", name);
+ goto skip;
+ }
+
+ if (!KEYBITS_BIT(BTN_JOYSTICK))
+ goto skip;
+
+ ret = ioctl(fd, EVIOCGABS(ABS_X), &ainfo);
+ if (ret == -1)
+ goto skip;
+
+ abs_min = ainfo.minimum;
+ abs_max = ainfo.maximum;
+ lzone_step = (abs_max - abs_min) / 2 / 9;
+
+ ioctl(fd, EVIOCGNAME(sizeof(name)), name);
+ printf("using \"%s\" (type %08x)\n", name, support);
+ break;
+
+skip:
+ close(fd);
+ fd = -1;
+ }
+
+ if (fd == -1) {
+ printf("missing input device\n");
+ exit(1);
+ }
+
+ return fd;
+}
+#endif // POLLUX_BUILD
+
+void gpsp_plat_init(void)