diff --git a/frontend/drivers/platform_ps2.c b/frontend/drivers/platform_ps2.c index 3d937aaeb6..7315d9578d 100644 --- a/frontend/drivers/platform_ps2.c +++ b/frontend/drivers/platform_ps2.c @@ -193,7 +193,6 @@ static const char *getMountParams(const char *command, char *BlockDevice) static void create_path_names(void) { - fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_CORE], g_defaults.dirs[DEFAULT_DIR_PORT], "CORES", sizeof(g_defaults.dirs[DEFAULT_DIR_CORE])); fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_CORE_INFO], g_defaults.dirs[DEFAULT_DIR_PORT], diff --git a/gfx/drivers/ps2_gfx.c b/gfx/drivers/ps2_gfx.c index ca72ebb3f6..0fbb1db5db 100644 --- a/gfx/drivers/ps2_gfx.c +++ b/gfx/drivers/ps2_gfx.c @@ -134,15 +134,17 @@ static void vram_alloc(GSGLOBAL *gsGlobal, GSTEXTURE *texture) } } -static void prim_texture(GSGLOBAL *gsGlobal, GSTEXTURE *texture, int zPosition, bool force_aspect) +static void prim_texture(GSGLOBAL *gsGlobal, GSTEXTURE *texture, int zPosition, bool force_aspect, struct retro_hw_ps2_insets padding) { float x1, y1, x2, y2; + float visible_width = texture->Width - padding.left - padding.right; + float visible_height = texture->Height - padding.top - padding.bottom; if (force_aspect) { - float width_proportion = (float)gsGlobal->Width / (float)texture->Width; - float height_proportion = (float)gsGlobal->Height / (float)texture->Height; + float width_proportion = (float)gsGlobal->Width / (float)visible_width; + float height_proportion = (float)gsGlobal->Height / (float)visible_height; float delta = MIN(width_proportion, height_proportion); - float newWidth = texture->Width * delta; - float newHeight = texture->Height * delta; + float newWidth = visible_width * delta; + float newHeight = visible_height * delta; x1 = (gsGlobal->Width - newWidth) / 2.0f; y1 = (gsGlobal->Height - newHeight) / 2.0f; @@ -159,12 +161,12 @@ static void prim_texture(GSGLOBAL *gsGlobal, GSTEXTURE *texture, int zPosition, gsKit_prim_sprite_texture( gsGlobal, texture, x1, //X1 y1, // Y1 - 0.0f, // U1 - 0.0f, // V1 + padding.left, // U1 + padding.top, // V1 x2, // X2 y2, // Y2 - texture->Width, // U2 - texture->Height, // V2 + texture->Width - padding.right, // U2 + texture->Height - padding.bottom, // V2 zPosition, GS_TEXT); } @@ -194,6 +196,27 @@ static void refreshScreen(ps2_video_t *ps2) ps2->clearVRAM = false; } + +static void ps2_texture_upload(GSGLOBAL *gsGlobal, GSTEXTURE *Texture, bool sendPalette) +{ + gsKit_setup_tbw(Texture); + + if (Texture->PSM == GS_PSM_T8) { + gsKit_texture_send(Texture->Mem, Texture->Width, Texture->Height, Texture->Vram, Texture->PSM, Texture->TBW, GS_CLUT_TEXTURE); + if (sendPalette) { + gsKit_texture_send(Texture->Clut, 16, 16, Texture->VramClut, Texture->ClutPSM, 1, GS_CLUT_PALLETE); + } + + } else if (Texture->PSM == GS_PSM_T4) { + gsKit_texture_send(Texture->Mem, Texture->Width, Texture->Height, Texture->Vram, Texture->PSM, Texture->TBW, GS_CLUT_TEXTURE); + if (sendPalette) { + gsKit_texture_send(Texture->Clut, 8, 2, Texture->VramClut, Texture->ClutPSM, 1, GS_CLUT_PALLETE); + } + } else { + gsKit_texture_send(Texture->Mem, Texture->Width, Texture->Height, Texture->Vram, Texture->PSM, Texture->TBW, GS_CLUT_NONE); + } +} + static void *ps2_gfx_init(const video_info_t *video, const input_driver_t **input, void **input_data) { @@ -245,14 +268,24 @@ static bool ps2_gfx_frame(void *data, const void *frame, clearVRAMIfNeeded(ps2, frame, width, height); if (frame) { + bool sendPalette = false; + struct retro_hw_ps2_insets padding = empty_ps2_insets; if (frame != RETRO_HW_FRAME_BUFFER_VALID){ /* Checking if the transfer is done in the core */ transfer_texture(ps2->coreTexture, frame, width, height, ps2->PSM, ps2->core_filter, 1); + } else { + sendPalette = ps2->iface.updatedPalette; + ps2->iface.updatedPalette = false; + padding = ps2->iface.padding; + if (ps2->iface.clearTexture) { + gsKit_clear(ps2->gsGlobal, GS_BLACK); + ps2->iface.clearTexture = false; + } } if(ps2->clearVRAM) { vram_alloc(ps2->gsGlobal, ps2->coreTexture); } - gsKit_texture_upload(ps2->gsGlobal, ps2->coreTexture); - prim_texture(ps2->gsGlobal, ps2->coreTexture, 1, ps2->force_aspect); + ps2_texture_upload(ps2->gsGlobal, ps2->coreTexture, sendPalette); + prim_texture(ps2->gsGlobal, ps2->coreTexture, 1, ps2->force_aspect, padding); } if (ps2->menuVisible) { @@ -262,7 +295,7 @@ static bool ps2_gfx_frame(void *data, const void *frame, vram_alloc(ps2->gsGlobal, ps2->menuTexture); } gsKit_texture_upload(ps2->gsGlobal, ps2->menuTexture); - prim_texture(ps2->gsGlobal, ps2->menuTexture, 2, ps2->fullscreen); + prim_texture(ps2->gsGlobal, ps2->menuTexture, 2, ps2->fullscreen, empty_ps2_insets); } } else if (video_info->statistics_show) { struct font_params *osd_params = (struct font_params*) @@ -419,6 +452,8 @@ static bool ps2_get_hw_render_interface(void* data, { ps2_video_t* ps2 = (ps2_video_t*)data; ps2->iface.clearTexture = ps2->clearVRAM; + ps2->iface.updatedPalette = true; + ps2->iface.padding = empty_ps2_insets; *iface = (const struct retro_hw_render_interface*)&ps2->iface; return true; } diff --git a/libretro-common/include/libretro_gskit_ps2.h b/libretro-common/include/libretro_gskit_ps2.h index e1e978d4c5..f7b61dc2e8 100644 --- a/libretro-common/include/libretro_gskit_ps2.h +++ b/libretro-common/include/libretro_gskit_ps2.h @@ -35,6 +35,16 @@ #define RETRO_HW_RENDER_INTERFACE_GSKIT_PS2_VERSION 1 +struct retro_hw_ps2_insets +{ + float top; + float left; + float bottom; + float right; +}; + +#define empty_ps2_insets (struct retro_hw_ps2_insets){0.f, 0.f, 0.f, 0.f} + struct retro_hw_render_interface_gskit_ps2 { /* Must be set to RETRO_HW_RENDER_INTERFACE_GSKIT_PS2. */ @@ -48,6 +58,8 @@ struct retro_hw_render_interface_gskit_ps2 */ GSTEXTURE *coreTexture; bool clearTexture; + bool updatedPalette; + struct retro_hw_ps2_insets padding; }; typedef struct retro_hw_render_interface_gskit_ps2 RETRO_HW_RENDER_INTEFACE_GSKIT_PS2; diff --git a/ps2/include/math.h b/ps2/include/math.h index fa0672624f..fd8341ec23 100644 --- a/ps2/include/math.h +++ b/ps2/include/math.h @@ -25,6 +25,7 @@ #define floor(x) ((double)floorf((float)x)) #define sqrt(x) ((double)sqrtf((float)x)) #define fabs(x) ((double)fabsf((float)(x))) +#define round(x) ((double)roundf((float)(x))) #define fmaxf(a, b) (((a) > (b)) ? (a) : (b)) #define fminf(a, b) (((a) < (b)) ? (a) : (b))