+u32 gpsp_plat_joystick_read(void)
+{
+#ifdef WIZ_BUILD
+ u32 value = 0;
+ read(gpsp_gp2x_indev, &value, 4);
+ if(value & 0x02)
+ value |= 0x05;
+ if(value & 0x08)
+ value |= 0x14;
+ if(value & 0x20)
+ value |= 0x50;
+ if(value & 0x80)
+ value |= 0x41;
+ return value;
+#elif defined(POLLUX_BUILD)
+ // caanoo
+ static const int evdev_to_gp2x[] = {
+ GP2X_A, GP2X_X, GP2X_B, GP2X_Y, GP2X_L, GP2X_R,
+ GP2X_HOME, 0, GP2X_START, GP2X_SELECT, GP2X_PUSH
+ };
+ int keybits[KEY_CNT / sizeof(int)];
+ struct input_absinfo ainfo;
+ int lzone = analog_sensitivity_level * lzone_step;
+ u32 retval = 0;
+ int i, ret;
+
+ ret = ioctl(gpsp_gp2x_indev, EVIOCGKEY(sizeof(keybits)), keybits);
+ if (ret == -1) {
+ perror("EVIOCGKEY ioctl failed");
+ sleep(1);
+ return 0;
+ }
+
+ for (i = 0; i < sizeof(evdev_to_gp2x) / sizeof(evdev_to_gp2x[0]); i++) {
+ if (KEYBITS_BIT(BTN_TRIGGER + i))
+ retval |= evdev_to_gp2x[i];
+ }
+
+ if (lzone != 0)
+ lzone--;
+
+ ret = ioctl(gpsp_gp2x_indev, EVIOCGABS(ABS_X), &ainfo);
+ if (ret != -1) {
+ if (ainfo.value <= abs_min + lzone) retval |= GP2X_LEFT;
+ else if (ainfo.value >= abs_max - lzone) retval |= GP2X_RIGHT;
+ }
+ ret = ioctl(gpsp_gp2x_indev, EVIOCGABS(ABS_Y), &ainfo);
+ if (ret != -1) {
+ if (ainfo.value <= abs_min + lzone) retval |= GP2X_UP;
+ else if (ainfo.value >= abs_max - lzone) retval |= GP2X_DOWN;
+ }
+
+ return retval;
+#else
+ // GP2X
+ u32 value = (gpsp_gp2x_memregs[0x1198 >> 1] & 0x00FF);
+
+ if(value == 0xFD)
+ value = 0xFA;
+ if(value == 0xF7)
+ value = 0xEB;
+ if(value == 0xDF)
+ value = 0xAF;
+ if(value == 0x7F)
+ value = 0xBE;
+
+ return ~((gpsp_gp2x_memregs[0x1184 >> 1] & 0xFF00) | value |
+ (gpsp_gp2x_memregs[0x1186 >> 1] << 16));
+#endif
+}
+
+u32 gpsp_plat_buttons_to_cursor(u32 buttons)
+{
+ gui_action_type new_button = CURSOR_NONE;
+
+ if(buttons & GP2X_A)
+ new_button = CURSOR_BACK;
+
+ if(buttons & GP2X_X)
+ new_button = CURSOR_EXIT;
+
+ if(buttons & GP2X_B)
+ new_button = CURSOR_SELECT;
+
+ if(buttons & GP2X_UP)
+ new_button = CURSOR_UP;
+
+ if(buttons & GP2X_DOWN)
+ new_button = CURSOR_DOWN;
+
+ if(buttons & GP2X_LEFT)
+ new_button = CURSOR_LEFT;
+
+ if(buttons & GP2X_RIGHT)
+ new_button = CURSOR_RIGHT;
+
+ if(buttons & GP2X_L)
+ new_button = CURSOR_L;
+
+ if(buttons & GP2X_R)
+ new_button = CURSOR_R;
+
+ return new_button;
+}
+
+// Fout = (m * Fin) / (p * 2^s)
+void set_FCLK(u32 MHZ)
+{
+ u32 v;
+ u32 mdiv, pdiv, sdiv = 0;
+#ifdef POLLUX_BUILD
+ int i;
+ #define SYS_CLK_FREQ 27
+ // m = MDIV, p = PDIV, s = SDIV
+ pdiv = 9;
+ mdiv = (MHZ * pdiv) / SYS_CLK_FREQ;
+ if (mdiv & ~0x3ff)
+ return;
+ v = (pdiv<<18) | (mdiv<<8) | sdiv;
+
+ gpsp_gp2x_memregl[0xf004>>2] = v;
+ gpsp_gp2x_memregl[0xf07c>>2] |= 0x8000;
+ for (i = 0; (gpsp_gp2x_memregl[0xf07c>>2] & 0x8000) && i < 0x100000; i++)
+ ;
+
+ // must restart sound as it's PLL is shared with CPU one
+ sound_exit();
+ init_sound(0);
+#else
+ #define SYS_CLK_FREQ 7372800
+ // m = MDIV + 8, p = PDIV + 2, s = SDIV
+ pdiv = 3;
+ mdiv = (MHZ * pdiv * 1000000) / SYS_CLK_FREQ;
+ mdiv &= 0xff;
+ v = ((mdiv-8)<<8) | ((pdiv-2)<<2) | sdiv;
+ gpsp_gp2x_memregs[0x910>>1] = v;
+#endif
+}
+