#include "libpicofe/fonts.h"
#include "libpicofe/plat_sdl.h"
#include "libpicofe/gl.h"
-#include "../plugins/gpulib/cspace.h"
+#include "cspace.h"
#include "plugin_lib.h"
#include "plugin.h"
#include "main.h"
{ 0, 0, 0 }
};
-static int psx_w, psx_h;
+const struct menu_keymap in_sdl_key_map[] =
+{
+ { SDLK_UP, PBTN_UP },
+ { SDLK_DOWN, PBTN_DOWN },
+ { SDLK_LEFT, PBTN_LEFT },
+ { SDLK_RIGHT, PBTN_RIGHT },
+ { SDLK_RETURN, PBTN_MOK },
+ { SDLK_ESCAPE, PBTN_MBACK },
+ { SDLK_SEMICOLON, PBTN_MA2 },
+ { SDLK_QUOTE, PBTN_MA3 },
+ { SDLK_LEFTBRACKET, PBTN_L },
+ { SDLK_RIGHTBRACKET, PBTN_R },
+};
+
+const struct menu_keymap in_sdl_joy_map[] =
+{
+ { SDLK_UP, PBTN_UP },
+ { SDLK_DOWN, PBTN_DOWN },
+ { SDLK_LEFT, PBTN_LEFT },
+ { SDLK_RIGHT, PBTN_RIGHT },
+ /* joystick */
+ { SDLK_WORLD_0, PBTN_MOK },
+ { SDLK_WORLD_1, PBTN_MBACK },
+ { SDLK_WORLD_2, PBTN_MA2 },
+ { SDLK_WORLD_3, PBTN_MA3 },
+};
+
+static const struct in_pdata in_sdl_platform_data = {
+ .defbinds = in_sdl_defbinds,
+ .key_map = in_sdl_key_map,
+ .kmap_size = sizeof(in_sdl_key_map) / sizeof(in_sdl_key_map[0]),
+ .joy_map = in_sdl_joy_map,
+ .jmap_size = sizeof(in_sdl_joy_map) / sizeof(in_sdl_joy_map[0]),
+};
+
+static int psx_w = 256, psx_h = 240;
static void *shadow_fb, *menubg_img;
static int in_menu;
+static void centered_clear(void);
+static void *setup_blit_callbacks(int w);
+
static int change_video_mode(int force)
{
- int w, h;
+ int w, h, ret;
if (in_menu) {
w = g_menuscreen_w;
h = psx_h;
}
- return plat_sdl_change_video_mode(w, h, force);
+ ret = plat_sdl_change_video_mode(w, h, force);
+ if (ret == 0 && plat_sdl_overlay == NULL && !plat_sdl_gl_active)
+ centered_clear();
+ return ret;
}
static void resize_cb(int w, int h)
pl_rearmed_cbs.gles_display = gl_es_display;
pl_rearmed_cbs.gles_surface = gl_es_surface;
plugin_call_rearmed_cbs();
+ setup_blit_callbacks(psx_w);
}
static void quit_cb(void)
void plat_init(void)
{
+ int shadow_size;
int ret;
plat_sdl_quit_cb = quit_cb;
in_menu = 1;
SDL_WM_SetCaption("PCSX-ReARMed " REV, NULL);
- shadow_fb = malloc(640 * 512 * 2);
- menubg_img = malloc(640 * 512 * 2);
+ shadow_size = g_menuscreen_w * g_menuscreen_h * 2;
+ // alloc enough for double res. rendering
+ if (shadow_size < 1024 * 512 * 2)
+ shadow_size = 1024 * 512 * 2;
+
+ shadow_fb = malloc(shadow_size);
+ menubg_img = malloc(shadow_size);
if (shadow_fb == NULL || menubg_img == NULL) {
fprintf(stderr, "OOM\n");
exit(1);
}
- in_sdl_init(in_sdl_defbinds, plat_sdl_event_handler);
+ in_sdl_init(&in_sdl_platform_data, plat_sdl_event_handler);
in_probe();
pl_rearmed_cbs.only_16bpp = 1;
pl_rearmed_cbs.pl_get_layer_pos = get_layer_pos;
SDL_UnlockYUVOverlay(plat_sdl_overlay);
}
-void *plat_gvideo_set_mode(int *w, int *h, int *bpp)
+static void centered_clear(void)
{
- psx_w = *w;
- psx_h = *h;
- change_video_mode(0);
+ int dstride = plat_sdl_screen->pitch / 2;
+ int w = plat_sdl_screen->w;
+ int h = plat_sdl_screen->h;
+ unsigned short *dst;
+
+ SDL_LockSurface(plat_sdl_screen);
+ dst = plat_sdl_screen->pixels;
+
+ for (; h > 0; dst += dstride, h--)
+ memset(dst, 0, w * 2);
+
+ SDL_UnlockSurface(plat_sdl_screen);
+}
+
+static void centered_blit(int doffs, const void *src_, int w, int h,
+ int sstride, int bgr24)
+{
+ const unsigned short *src = src_;
+ unsigned short *dst;
+ int dstride;
+
+ SDL_LockSurface(plat_sdl_screen);
+ dst = plat_sdl_screen->pixels;
+ dstride = plat_sdl_screen->pitch / 2;
+
+ dst += doffs + (plat_sdl_screen->w - w) / 2;
+ dst += dstride * (plat_sdl_screen->h - h) / 2;
+ if (bgr24) {
+ for (; h > 0; dst += dstride, src += sstride, h--)
+ bgr888_to_rgb565(dst, src, w * 3);
+ }
+ else {
+ for (; h > 0; dst += dstride, src += sstride, h--)
+ bgr555_to_rgb565(dst, src, w * 2);
+ }
+
+ SDL_UnlockSurface(plat_sdl_screen);
+}
+
+static void centered_blit_menu(void)
+{
+ const unsigned short *src = g_menuscreen_ptr;
+ int w = g_menuscreen_w;
+ int h = g_menuscreen_h;
+ unsigned short *dst;
+ int dstride;
+
+ SDL_LockSurface(plat_sdl_screen);
+ dst = plat_sdl_screen->pixels;
+ dstride = plat_sdl_screen->pitch / 2;
+
+ dst += (plat_sdl_screen->w - w) / 2;
+ dst += dstride * (plat_sdl_screen->h - h) / 2;
+ for (; h > 0; dst += dstride, src += g_menuscreen_pp, h--)
+ memcpy(dst, src, w * 2);
+
+ SDL_UnlockSurface(plat_sdl_screen);
+}
+
+static void centered_hud_print(int x, int y, const char *str, int bpp)
+{
+ x += (plat_sdl_screen->w - psx_w) / 2;
+ y += (plat_sdl_screen->h - psx_h) / 2;
+ SDL_LockSurface(plat_sdl_screen);
+ basic_text_out16_nf(plat_sdl_screen->pixels, plat_sdl_screen->pitch / 2, x, y, str);
+ SDL_UnlockSurface(plat_sdl_screen);
+}
+
+static void *setup_blit_callbacks(int w)
+{
+ pl_plat_clear = NULL;
+ pl_plat_blit = NULL;
+ pl_plat_hud_print = NULL;
if (plat_sdl_overlay != NULL) {
pl_plat_clear = plat_sdl_overlay_clear;
pl_plat_blit = overlay_blit;
pl_plat_hud_print = overlay_hud_print;
- return NULL;
+ }
+ else if (plat_sdl_gl_active) {
+ return shadow_fb;
}
else {
- pl_plat_clear = NULL;
- pl_plat_blit = NULL;
- pl_plat_hud_print = NULL;
- if (plat_sdl_gl_active)
- return shadow_fb;
- else
+ if (w == plat_sdl_screen->w)
return plat_sdl_screen->pixels;
+ else {
+ pl_plat_clear = centered_clear;
+ pl_plat_blit = centered_blit;
+ pl_plat_hud_print = centered_hud_print;
+ }
}
+ return NULL;
+}
+
+void *plat_gvideo_set_mode(int *w, int *h, int *bpp)
+{
+ psx_w = *w;
+ psx_h = *h;
+ change_video_mode(0);
+ if (plat_sdl_gl_active)
+ memset(shadow_fb, 0, psx_w * psx_h * 2);
+ return setup_blit_callbacks(*w);
}
void *plat_gvideo_flip(void)
void plat_video_menu_begin(void)
{
- if (plat_sdl_overlay != NULL || plat_sdl_gl_active) {
- g_menuscreen_ptr = shadow_fb;
- }
- else {
- SDL_LockSurface(plat_sdl_screen);
- g_menuscreen_ptr = plat_sdl_screen->pixels;
- }
+ g_menuscreen_ptr = shadow_fb;
}
void plat_video_menu_end(void)
gl_flip(g_menuscreen_ptr, g_menuscreen_w, g_menuscreen_h);
}
else {
- SDL_UnlockSurface(plat_sdl_screen);
+ centered_blit_menu();
SDL_Flip(plat_sdl_screen);
}
g_menuscreen_ptr = NULL;
void plat_video_menu_leave(void)
{
+ void *fb = NULL;
+ if (plat_sdl_overlay != NULL || plat_sdl_gl_active)
+ fb = shadow_fb;
+ else if (plat_sdl_screen)
+ fb = plat_sdl_screen->pixels;
+ if (fb)
+ memset(fb, 0, g_menuscreen_w * g_menuscreen_h * 2);
in_menu = 0;
}
return 0;
}
-void plat_trigger_vibrate(int is_strong)
+void plat_trigger_vibrate(int pad, int low, int high)
{
}