+ void *ret = plat_prepare_screenshot(w, h, bpp);
+ if (ret != NULL)
+ return ret;
+
+ *w = pl_vout_w;
+ *h = pl_vout_h;
+ *bpp = pl_vout_bpp;
+
+ return pl_vout_buf;
+}
+
+/* display/redering mode switcher */
+static int dispmode_default(void)
+{
+ pl_rearmed_cbs.gpu_neon.enhancement_enable = 0;
+ soft_filter = SOFT_FILTER_NONE;
+ snprintf(hud_msg, sizeof(hud_msg), "default mode");
+ return 1;
+}
+
+#ifdef BUILTIN_GPU_NEON
+static int dispmode_doubleres(void)
+{
+ if (!(pl_rearmed_cbs.gpu_caps & GPU_CAP_SUPPORTS_2X)
+ || !resolution_ok(psx_w * 2, psx_h * 2) || psx_bpp != 16)
+ return 0;
+
+ dispmode_default();
+ pl_rearmed_cbs.gpu_neon.enhancement_enable = 1;
+ snprintf(hud_msg, sizeof(hud_msg), "double resolution");
+ return 1;
+}
+#endif
+
+#ifdef __ARM_NEON__
+static int dispmode_scale2x(void)
+{
+ if (!resolution_ok(psx_w * 2, psx_h * 2) || psx_bpp != 16)
+ return 0;
+
+ dispmode_default();
+ soft_filter = SOFT_FILTER_SCALE2X;
+ snprintf(hud_msg, sizeof(hud_msg), "scale2x");
+ return 1;
+}
+
+static int dispmode_eagle2x(void)
+{
+ if (!resolution_ok(psx_w * 2, psx_h * 2) || psx_bpp != 16)
+ return 0;
+
+ dispmode_default();
+ soft_filter = SOFT_FILTER_EAGLE2X;
+ snprintf(hud_msg, sizeof(hud_msg), "eagle2x");
+ return 1;
+}
+#endif
+
+static int (*dispmode_switchers[])(void) = {
+ dispmode_default,
+#ifdef BUILTIN_GPU_NEON
+ dispmode_doubleres,
+#endif
+#ifdef __ARM_NEON__
+ dispmode_scale2x,
+ dispmode_eagle2x,
+#endif
+};
+
+static int dispmode_current;
+
+void pl_switch_dispmode(void)
+{
+ if (pl_rearmed_cbs.gpu_caps & GPU_CAP_OWNS_DISPLAY)
+ return;
+
+ while (1) {
+ dispmode_current++;
+ if (dispmode_current >=
+ sizeof(dispmode_switchers) / sizeof(dispmode_switchers[0]))
+ dispmode_current = 0;
+ if (dispmode_switchers[dispmode_current]())
+ break;
+ }
+}
+
+#ifndef MAEMO
+/* adjust circle-like analog inputs to better match
+ * more square-like analogs in PSX */
+static void update_analog_nub_adjust(int *x_, int *y_)
+{
+ #define d 16
+ static const int scale[] =
+ { 0 - d*2, 0 - d*2, 0 - d*2, 12 - d*2,
+ 30 - d*2, 60 - d*2, 75 - d*2, 60 - d*2, 60 - d*2 };
+ int x = abs(*x_);
+ int y = abs(*y_);
+ int scale_x = scale[y / 16];
+ int scale_y = scale[x / 16];
+
+ if (x) {
+ x += d + (x * scale_x >> 8);
+ if (*x_ < 0)
+ x = -x;
+ }
+ if (y) {
+ y += d + (y * scale_y >> 8);
+ if (*y_ < 0)
+ y = -y;
+ }