diff --git a/src/video/ogc/SDL_ogcgxcommon.c b/src/video/ogc/SDL_ogcgxcommon.c index ed7e096369c5a..82e61ef25964e 100644 --- a/src/video/ogc/SDL_ogcgxcommon.c +++ b/src/video/ogc/SDL_ogcgxcommon.c @@ -28,6 +28,7 @@ #include #include #include +#include static const f32 tex_pos[] __attribute__((aligned(32))) = { 0.0, @@ -40,12 +41,28 @@ static const f32 tex_pos[] __attribute__((aligned(32))) = { 1.0, }; +float OGC_get_aspect_ratio() +{ + const char *ratioString; + float w, h; + ratioString = getenv("SDL_OGC_ASPECT_RATIO"); + + if(ratioString == NULL) { + #ifdef __wii__ + if(CONF_GetAspectRatio() == CONF_ASPECT_16_9) + return 16.0f / 9.0f; + #endif + return 4.0f / 3.0f; + } else if(sscanf(ratioString, "%f:%f", w, h) == 2) + return w/h; +} + void OGC_set_viewport(int x, int y, int w, int h) { Mtx44 proj; - GX_SetViewport(x, y, w, h, 0, 1); - GX_SetScissor(x, y, w, h); + GX_SetViewport(x, y, (w > 640) ? 640 : w, h, 0, 1); + GX_SetScissor(x, y, (w > 640) ? 640 : w, h); // matrix, t, b, l, r, n, f guOrtho(proj, 0, h, 0, w, 0, 1); diff --git a/src/video/ogc/SDL_ogcgxcommon.h b/src/video/ogc/SDL_ogcgxcommon.h index 1b2ed5b321e71..14e0de9af20c1 100644 --- a/src/video/ogc/SDL_ogcgxcommon.h +++ b/src/video/ogc/SDL_ogcgxcommon.h @@ -30,6 +30,7 @@ #define GX_COLOR_AS_U32(c) *((u32*)&c) void OGC_draw_init(int w, int h); +float OGC_get_aspect_ratio(); void OGC_set_viewport(int x, int y, int w, int h); void OGC_load_texture(void *texels, int w, int h, u8 gx_format, SDL_ScaleMode scale_mode); diff --git a/src/video/ogc/SDL_ogcvideo.c b/src/video/ogc/SDL_ogcvideo.c index 5653700f738c3..12a6e21419801 100644 --- a/src/video/ogc/SDL_ogcvideo.c +++ b/src/video/ogc/SDL_ogcvideo.c @@ -38,6 +38,7 @@ #include #include +#include #include #include #include @@ -87,13 +88,20 @@ static void OGC_VideoQuit(_THIS); static void init_display_mode(SDL_DisplayMode *mode, const GXRModeObj *vmode) { + float aspect = OGC_get_aspect_ratio(); + u32 format = VI_FORMAT_FROM_MODE(vmode->viTVMode); /* Use a fake 32-bpp desktop mode */ SDL_zero(*mode); mode->format = SDL_PIXELFORMAT_ARGB8888; - mode->w = vmode->fbWidth; + mode->h = vmode->efbHeight; + if (aspect != 4.0f/3.0f) { + mode->w = mode->h * aspect; + mode->w = (mode->w + 1) & ~1; + } else + mode->w = vmode->fbWidth; switch (format) { case VI_DEBUG: case VI_NTSC: @@ -170,7 +178,8 @@ static void setup_video_mode(_THIS, GXRModeObj *vmode) VIDEO_Flush(); VIDEO_WaitVSync(); - if (vmode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync(); + if (vmode->viTVMode & VI_NON_INTERLACE) + VIDEO_WaitVSync(); /* Setup the EFB -> XFB copy operation */ GX_SetDispCopySrc(0, 0, vmode->fbWidth, vmode->efbHeight); @@ -287,6 +296,18 @@ int OGC_VideoInit(_THIS) VIDEO_Init(); vmode = VIDEO_GetPreferredMode(NULL); + if(OGC_get_aspect_ratio() != (4.0f / 3.0f)) + { + vmode->viWidth = VI_MAX_WIDTH_NTSC; // VI_MAX_WIDTH is the same for all regions + // set Center point + if (VI_FORMAT_FROM_MODE(vmode->viTVMode) == VI_PAL) { + vmode->viXOrigin = (VI_MAX_WIDTH_PAL - vmode->viWidth) / 2; + vmode->viYOrigin = (VI_MAX_HEIGHT_PAL - vmode->viHeight) / 2; + } else { + vmode->viXOrigin = (VI_MAX_WIDTH_NTSC - vmode->viWidth) / 2; + vmode->viYOrigin = (VI_MAX_HEIGHT_NTSC - vmode->viHeight) / 2; + } + } videodata->gp_fifo = memalign(32, DEFAULT_FIFO_SIZE); memset(videodata->gp_fifo, 0, DEFAULT_FIFO_SIZE);