diff --git a/common.h b/common.h index 9627c71..6bf0a45 100644 --- a/common.h +++ b/common.h @@ -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; diff --git a/libretro/libretro.c b/libretro/libretro.c index 697e59d..6bd4108 100644 --- a/libretro/libretro.c +++ b/libretro/libretro.c @@ -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)) diff --git a/video.cc b/video.cc index e6f31b0..3f7dca2 100644 --- a/video.cc +++ b/video.cc @@ -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); } diff --git a/video.h b/video.h index e7ca137..c4808b7 100644 --- a/video.h +++ b/video.h @@ -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