In memory of Ben “bushing” Byer, who passed away on Monday, February 8th, 2016.

Difference between revisions of "Developer tips"

From WiiBrew
Jump to navigation Jump to search
(added 16:9 video fix)
Line 8: Line 8:
 
// ...
 
// ...
 
rmode = VIDEO_GetPreferredMode(NULL);
 
rmode = VIDEO_GetPreferredMode(NULL);
 +
 +
if( CONF_GetAspectRatio() )
 +
{
 +
rmode->viWidth = 678;
 +
rmode->viXOrigin = (VI_MAX_WIDTH_PAL - 678)/2;
 +
}
 
VIDEO_Configure(rmode);
 
VIDEO_Configure(rmode);
 
</source>
 
</source>

Revision as of 11:41, 1 August 2008

Code Snippets

Video Auto-Detect Routine

The libogc included in DevkitPPC r15 does this for you with one function call. Here is the video detect code from the DevKitPro Wii example.

#include <gccore.h>
static GXRModeObj *rmode = NULL;
// ...
rmode = VIDEO_GetPreferredMode(NULL);

if( CONF_GetAspectRatio() )
{
	rmode->viWidth = 678;
	rmode->viXOrigin = (VI_MAX_WIDTH_PAL - 678)/2;
}
VIDEO_Configure(rmode);

Forum thread

Exit to Loader

It's a good idea to add some way to return to the loader, otherwise you have to reboot you Wii to exit.

// Just call the exit() function to go back to the loader
// Returning from main also works, since that calls exit for you
    #include <stdlib.h>
    // ...
    exit(0);

How to use the Wiimote

A separate article is available: How to use the Wiimote.

Reboot Wii

Use:

#include <gccore.h>
// ...
SYS_ResetSystem(SYS_RESTART,0,0);

Or use SYS_RETURNTOMENU for a "soft" return to the system menu, SYS_POWEROFF to shut down the wii (automatically to the appropriate Idle or Standby mode, depending on the WC24 setting), or SYS_POWEROFF_STANDBY or _IDLE to specify the mode and override the system setting.

General Programming Tips

  • Keep your code commented throughout; it helps others help you.
  • Any unused code should be deleted out of the program, unless it is a program for teaching people.
  • If someone does the same thing in a more efficient way (i.e. faster and/or in less code), accept it and learn from it.
  • To keep things tidy, instead of a folder on the root of the sd card, put it in a folder called data, so fat0:\data\XXXXX