plumbing direct framebuffer access through the libretro way

This commit is contained in:
lif 2023-12-23 21:11:20 -08:00
parent ef45161c94
commit 052656959f
4 changed files with 39 additions and 23 deletions

View File

@ -91,12 +91,12 @@
#define GBA_SCREEN_WIDTH (240)
#define GBA_SCREEN_HEIGHT (160)
#define GBA_SCREEN_PITCH (240)
//#define GBA_SCREEN_PITCH (240)
// The buffer is 16 bit color depth.
// We reserve extra memory at the end for extra effects (winobj rendering).
#define GBA_SCREEN_BUFFER_SIZE \
(GBA_SCREEN_PITCH * (GBA_SCREEN_HEIGHT + 1) * sizeof(uint16_t))
(gba_screen_pitch * (GBA_SCREEN_HEIGHT + 1) * sizeof(uint16_t))
typedef u32 fixed16_16;

View File

@ -136,6 +136,24 @@ static void show_warning_message(const char* text, unsigned durationms) {
}
}
static void set_screen_pixels() {
struct retro_framebuffer fbufr;
fbufr.width = GBA_SCREEN_WIDTH;
fbufr.height = GBA_SCREEN_HEIGHT;
fbufr.access_flags = RETRO_MEMORY_ACCESS_WRITE | RETRO_MEMORY_ACCESS_READ;
if (environ_cb(RETRO_ENVIRONMENT_GET_CURRENT_SOFTWARE_FRAMEBUFFER, &fbufr)) {
gba_screen_pixels = fbufr.data;
gba_screen_pitch = fbufr.pitch / sizeof(uint16_t);
} else if (!gba_screen_pixels) {
gba_screen_pitch = GBA_SCREEN_WIDTH;
#ifdef _3DS
gba_screen_pixels = (uint16_t*)linearMemAlign(GBA_SCREEN_BUFFER_SIZE, 128);
#else
gba_screen_pixels = (uint16_t*)malloc(GBA_SCREEN_BUFFER_SIZE);
#endif
}
}
/* Frameskip START */
static void audio_buff_status_cb(
@ -214,7 +232,7 @@ static void video_post_process_cc(void)
for (y = 0; y < GBA_SCREEN_HEIGHT; y++)
{
for (x = 0; x < GBA_SCREEN_PITCH; x++)
for (x = 0; x < gba_screen_pitch; x++)
{
u16 src_color = *(src + x);
@ -222,8 +240,8 @@ static void video_post_process_cc(void)
*(dst + x) = *(gba_cc_lut + (((src_color & 0xFFC0) >> 1) | (src_color & 0x1F)));
}
src += GBA_SCREEN_PITCH;
dst += GBA_SCREEN_PITCH;
src += gba_screen_pitch;
dst += gba_screen_pitch;
}
}
@ -236,7 +254,7 @@ static void video_post_process_mix(void)
for (y = 0; y < GBA_SCREEN_HEIGHT; y++)
{
for (x = 0; x < GBA_SCREEN_PITCH; x++)
for (x = 0; x < gba_screen_pitch; x++)
{
/* Get colours from current + previous frames (RGB565) */
uint16_t rgb_curr = *(src_curr + x);
@ -251,9 +269,9 @@ static void video_post_process_mix(void)
*(dst + x) = (rgb_curr + rgb_prev + ((rgb_curr ^ rgb_prev) & 0x821)) >> 1;
}
src_curr += GBA_SCREEN_PITCH;
src_prev += GBA_SCREEN_PITCH;
dst += GBA_SCREEN_PITCH;
src_curr += gba_screen_pitch;
src_prev += gba_screen_pitch;
dst += gba_screen_pitch;
}
}
@ -266,7 +284,7 @@ static void video_post_process_cc_mix(void)
for (y = 0; y < GBA_SCREEN_HEIGHT; y++)
{
for (x = 0; x < GBA_SCREEN_PITCH; x++)
for (x = 0; x < gba_screen_pitch; x++)
{
/* Get colours from current + previous frames (RGB565) */
uint16_t rgb_curr = *(src_curr + x);
@ -284,9 +302,9 @@ static void video_post_process_cc_mix(void)
*(dst + x) = *(gba_cc_lut + (((rgb_mix & 0xFFC0) >> 1) | (rgb_mix & 0x1F)));
}
src_curr += GBA_SCREEN_PITCH;
src_prev += GBA_SCREEN_PITCH;
dst += GBA_SCREEN_PITCH;
src_curr += gba_screen_pitch;
src_prev += gba_screen_pitch;
dst += gba_screen_pitch;
}
}
@ -409,7 +427,7 @@ static void video_run(void)
if (skip_next_frame)
{
video_cb(NULL, GBA_SCREEN_WIDTH, GBA_SCREEN_HEIGHT,
GBA_SCREEN_PITCH * 2);
gba_screen_pitch * 2);
return;
}
@ -420,7 +438,8 @@ static void video_run(void)
}
video_cb(gba_screen_pixels_buf, GBA_SCREEN_WIDTH, GBA_SCREEN_HEIGHT,
GBA_SCREEN_PITCH * 2);
gba_screen_pitch * 2);
set_screen_pixels();
}
#ifdef PERF_TEST
@ -532,12 +551,7 @@ void retro_init(void)
init_gamepak_buffer();
init_sound();
if(!gba_screen_pixels)
#ifdef _3DS
gba_screen_pixels = (uint16_t*)linearMemAlign(GBA_SCREEN_BUFFER_SIZE, 128);
#else
gba_screen_pixels = (uint16_t*)malloc(GBA_SCREEN_BUFFER_SIZE);
#endif
set_screen_pixels();
libretro_supports_bitmasks = false;
if (environ_cb(RETRO_ENVIRONMENT_GET_INPUT_BITMASKS, NULL))

View File

@ -23,9 +23,10 @@ extern "C" {
}
u16* gba_screen_pixels = NULL;
u32 gba_screen_pitch = GBA_SCREEN_WIDTH;
#define get_screen_pixels() gba_screen_pixels
#define get_screen_pitch() GBA_SCREEN_PITCH
#define get_screen_pitch() gba_screen_pitch
typedef struct {
u16 attr0, attr1, attr2, attr3;
@ -1471,7 +1472,7 @@ void render_scanline_objs(
u32 obj_enable = read_ioreg(REG_WINOUT) >> 8;
// Render at the next scanline!
u16 *tmp_ptr = (u16*)&scanline[GBA_SCREEN_PITCH];
u16 *tmp_ptr = (u16*)&scanline[get_screen_pitch()];
render_scanline_conditional(sec_start, sec_end, tmp_ptr, obj_enable);
}

View File

@ -27,5 +27,6 @@ extern s32 affine_reference_x[2];
extern s32 affine_reference_y[2];
extern u16* gba_screen_pixels;
extern u32 gba_screen_pitch;
#endif