4141#include <ogc/gx.h>
4242#include <ogc/system.h>
4343#include <ogc/video.h>
44+ #include <ogc/conf.h>
4445
4546#include <opengx.h>
4647
5152
5253/* A video mode with a 320 width; we'll build it programmatically. */
5354static GXRModeObj s_mode320 ;
55+ static GXRModeObj s_mode704 ;
5456
5557static const GXRModeObj * s_ntsc_modes [] = {
5658 & TVNtsc240Ds ,
@@ -85,14 +87,14 @@ static const GXRModeObj *s_pal_modes[] = {
8587static int OGC_VideoInit (_THIS );
8688static void OGC_VideoQuit (_THIS );
8789
88- static void init_display_mode (SDL_DisplayMode * mode , const GXRModeObj * vmode )
90+ static void init_display_mode (SDL_DisplayMode * mode , const GXRModeObj * vmode , int width )
8991{
9092 u32 format = VI_FORMAT_FROM_MODE (vmode -> viTVMode );
9193
9294 /* Use a fake 32-bpp desktop mode */
9395 SDL_zero (* mode );
9496 mode -> format = SDL_PIXELFORMAT_ARGB8888 ;
95- mode -> w = vmode -> fbWidth ;
97+ mode -> w = width ;
9698 mode -> h = vmode -> efbHeight ;
9799 switch (format ) {
98100 case VI_DEBUG :
@@ -142,18 +144,48 @@ static void add_supported_modes(SDL_VideoDisplay *display, u32 tv_format)
142144 * take care of the horizontal scale for us. */
143145 memcpy (& s_mode320 , gx_modes [0 ], sizeof (s_mode320 ));
144146 s_mode320 .fbWidth = 320 ;
145- init_display_mode (& mode , & s_mode320 );
147+ init_display_mode (& mode , & s_mode320 , s_mode320 . fbWidth );
146148 SDL_AddDisplayMode (display , & mode );
147149
150+ // libogc uses 640 for the viWidth, but this does not work well for Widescreen
151+ // as such we extend the viWidth to 704 on a new videomode
152+ // TODO: Currently ony added on wii if it's widescreen,
153+ // but should work on GC and a 4:3 Wii
154+ // testing needed
155+
156+ #ifdef __wii__
157+ if (CONF_GetAspectRatio () == CONF_ASPECT_16_9 )
158+ {
159+ memcpy (& s_mode704 , gx_modes [1 ], sizeof (s_mode704 ));
160+ s_mode704 .viWidth = 704 ;
161+
162+ // set Center point
163+ if (& s_mode704 == & TVPal576IntDfScale || & s_mode704 == & TVPal576ProgScale )
164+ {
165+ s_mode704 .viXOrigin = (VI_MAX_WIDTH_PAL - s_mode704 .viWidth ) / 2 ;
166+ s_mode704 .viYOrigin = (VI_MAX_HEIGHT_PAL - s_mode704 .viHeight ) / 2 ;
167+ }
168+ else
169+ {
170+ s_mode704 .viXOrigin = (VI_MAX_WIDTH_NTSC - s_mode704 .viWidth ) / 2 ;
171+ s_mode704 .viYOrigin = (VI_MAX_HEIGHT_NTSC - s_mode704 .viHeight ) / 2 ;
172+ }
173+
174+ // Widescreen is anamorphic, so we provide a different width for the ortho projection
175+ init_display_mode (& mode , & s_mode704 , 854 );
176+ SDL_AddDisplayMode (display , & mode );
177+ }
178+ #endif
179+
148180 /* Now add all the "standard" modes from libogc */
149181 while (* gx_modes ) {
150- init_display_mode (& mode , * gx_modes );
182+ init_display_mode (& mode , * gx_modes , ( * gx_modes ) -> fbWidth );
151183 SDL_AddDisplayMode (display , & mode );
152184 gx_modes ++ ;
153185 }
154186}
155187
156- static void setup_video_mode (_THIS , GXRModeObj * vmode )
188+ static void setup_video_mode (_THIS , GXRModeObj * vmode , int orthoWidth )
157189{
158190 SDL_VideoData * videodata = (SDL_VideoData * )_this -> driverdata ;
159191
@@ -180,7 +212,7 @@ static void setup_video_mode(_THIS, GXRModeObj *vmode)
180212 GX_SetFieldMode (vmode -> field_rendering ,
181213 ((vmode -> viHeight == 2 * vmode -> xfbHeight ) ? GX_ENABLE : GX_DISABLE ));
182214
183- OGC_draw_init (vmode -> fbWidth , vmode -> efbHeight );
215+ OGC_draw_init (vmode -> fbWidth , vmode -> efbHeight , orthoWidth );
184216}
185217
186218static int OGC_SetDisplayMode (_THIS , SDL_VideoDisplay * display ,
@@ -195,7 +227,7 @@ static int OGC_SetDisplayMode(_THIS, SDL_VideoDisplay *display,
195227 if (videodata -> xfb [1 ])
196228 free (MEM_K1_TO_K0 (videodata -> xfb [1 ]));
197229
198- setup_video_mode (_this , vmode );
230+ setup_video_mode (_this , vmode , mode -> w );
199231 return 0 ;
200232}
201233
@@ -277,12 +309,30 @@ int OGC_VideoInit(_THIS)
277309 VIDEO_Init ();
278310
279311 vmode = VIDEO_GetPreferredMode (NULL );
312+ vmode -> viWidth = 704 ;
313+
314+ // set Center point
315+ if (& s_mode704 == & TVPal576IntDfScale || & s_mode704 == & TVPal576ProgScale )
316+ {
317+ vmode -> viXOrigin = (VI_MAX_WIDTH_PAL - vmode -> viWidth ) / 2 ;
318+ vmode -> viYOrigin = (VI_MAX_HEIGHT_PAL - vmode -> viHeight ) / 2 ;
319+ }
320+ else
321+ {
322+ vmode -> viXOrigin = (VI_MAX_WIDTH_NTSC - vmode -> viWidth ) / 2 ;
323+ vmode -> viYOrigin = (VI_MAX_HEIGHT_NTSC - vmode -> viHeight ) / 2 ;
324+ }
280325
281326 videodata -> gp_fifo = memalign (32 , DEFAULT_FIFO_SIZE );
282327 memset (videodata -> gp_fifo , 0 , DEFAULT_FIFO_SIZE );
283328 GX_Init (videodata -> gp_fifo , DEFAULT_FIFO_SIZE );
284329
285- setup_video_mode (_this , vmode );
330+ #ifdef __wii__
331+ if (CONF_GetAspectRatio () == CONF_ASPECT_16_9 )
332+ setup_video_mode (_this , vmode , 854 );
333+ else
334+ #endif
335+ setup_video_mode (_this , vmode , vmode -> fbWidth );
286336 GX_SetCopyClear (background , GX_MAX_Z24 );
287337
288338 GX_SetPixelFmt (GX_PF_RGB8_Z24 , GX_ZC_LINEAR );
@@ -293,7 +343,12 @@ int OGC_VideoInit(_THIS)
293343
294344 GX_Flush ();
295345
296- init_display_mode (& mode , vmode );
346+ #ifdef __wii__
347+ if (CONF_GetAspectRatio () == CONF_ASPECT_16_9 )
348+ init_display_mode (& mode , vmode , 854 );
349+ else
350+ #endif
351+ init_display_mode (& mode , vmode , vmode -> fbWidth );
297352 if (SDL_AddBasicVideoDisplay (& mode ) < 0 ) {
298353 return -1 ;
299354 }
0 commit comments