Vpadbase.rpl

From WiiUBrew
Jump to navigation Jump to search

Internal library used by several others to get low-level access to the Gamepad's functions. Notably used by vpad.rpl and nfc.rpl. Internal structures indicate support for two Gamepads.

Functions

Name Prototype Description
VPADBASEIsInit
char VPADBASEIsInit();
Returns 0 if not initialised. Other possible values unclear.
VPADBASEInit
void VPADBASEInit();
Initialises the library (if not already initialised)
VPADBASEShutdown
void VPADBASEShutdown();
Shuts down the library.
VPADBASEGetState
int VPADBASEGetState(int channel);
Gets the state of the given channel.
VPADBASEGetCalibrationData
void VPADBASEGetCalibrationData(char buffer[0x44], int channel);
Copies calibration data for the given channel into buffer. Treated as 0x11 32-bit values internally.
VPADBASEGetGameControllerMode
void VPADBASEGetGameControllerMode(int channel, int* mode);
Gets the controller mode for the given channel, writing the result to *mode.
VPADBASESetGameControllerMode
void VPADBASESetGameControllerMode(int channel, int mode);
Sets the controller mode for the given channel to mode. Any non-zero mode will turn off the display, like the "Display Off" button under Controller Settings. Will not disable inputs.
VPADBASEGetFactorySetting
void VPADBASEGetFactorySetting(char buffer[0x1C], int channel);
Copies factory setting for given channel into buffer. Treated internally as 0xE 16-bit values rather than 0x1C 8-bit values.
VPADBASEGetVolumeOverrideSetting
void VPADBASEGetVolumeOverrideSetting(int channel, char* enabled, char* volume);
Sets *enabled to 1 if a volume override is in effect, otherwise 0. Sets *value to the volume forced by the override, if any.
VPADBASEGetVolumeOverrideStatus
char VPADBASEGetVolumeOverrideStatus(int channel);
Same as VPADBASEGetVolumeOverrideSetting, except it returns the enabled value rather than writing it to memory.
VPADBASESetVolumeOverrideSetting
void VPADBASESetVolumeOverrideSetting(int channel, char enabled, char volume);
Sets a volume override. Set enabled to 1 and volume to the desired value (0-255) to enforce; or set enabled to 0 to disable. When a volume override is in effect, all sound will come out the speakers regardless of whether headphones are connected.
VPADBASEInitVolumeOverrideSettingSyncTime
void VPADBASEInitVolumeOverrideSettingSyncTime(int channel);
Writes 0x190 to the "volume override sync time". VPADBASESetVolumeOverrideSetting does the same.
VPADBASEGetHeadphoneStatus
int VPADBASEGetHeadphoneStatus(int channel);
Returns 1 if headphones are connected, 0 otherwise.

Internal Data Structure

VPADBASE holds data from its Gamepads in the rpl's BSS section. On 5.5.1, the layout indicates room for two Gamepads, each with a dedicated 0x380 byte struct; one at 0x10002740 (not relocated, channel 0) and the other at 0x10002AC0 (not relocated, channel 1). Functions in this library index these structs with their channel number as you'd expect, with the exception of the library's "system mode callback" (see OSRegisterSystemModeCallback), which accesses 0x288 bytes into the first struct in a hard-coded manner. The final version of Cafe OS only allows you to connect one Gamepad - channel 0.

Gamepad Struct

Some of the functions use a more complex addressing system rather than simple offsets, so some items are missing from the following struct.

//TODO add padding bytes to make this actually work
struct VPADBASEGamepad {
	/* +214 */ char calibrationData[0x44]; //VPADBASEGetCalibrationData, actually 0x11 ints
	/* +25C */ char factorySetting[0x1C]; //VPADBASEGetFactorySetting, actually 0xE shorts
	/* +284 */ int state; //VPADBASEGetState
	/* +34C */ int gameControllerMode; //VPADBASE[Set/Get]GameControllerMode
	/* +378 */ char volumeOverrideEnable //VPADBASE[Set/Get]VolumeOverride[Status/Setting]
	/* +379 */ char volumeOverrideValue //VPADBASE[Set/Get]VolumeOverrideSetting
	/* +37C */ int volumeOverrideSyncTime //VPADBASESetVolumeOverrideSetting/VPADBASEInitVolumeOverrideSettingSyncTime
}