N64: Use first controller found as input, easier to add support for different input peripherals now

svn-id: r47317
This commit is contained in:
Fabio Battaglia 2010-01-15 23:35:24 +00:00
parent f1439b4fa7
commit c4a9d373ca
3 changed files with 28 additions and 6 deletions

View File

@ -117,6 +117,7 @@ protected:
int _mouseHotspotX, _mouseHotspotY;
controller_data_buttons *_ctrlData; // Controller data read from the N64 serial interface
uint8 _controllerNumber;
bool _controllerHasRumble;
bool _dirtyOffscreen;
@ -197,6 +198,8 @@ public:
void switchGraphicModeId(int mode);
void setupMixer(void);
void detectControllers(void);
};
#endif /* __OSYS_N64_H__ */

View File

@ -134,8 +134,10 @@ OSystem_N64::OSystem_N64() {
_dirtyOffscreen = false;
detectControllers();
_ctrlData = (controller_data_buttons*)memalign(8, sizeof(controller_data_buttons));
_controllerHasRumble = (identifyPak(0) == 2);
_controllerHasRumble = (identifyPak(_controllerNumber) == 2);
_fsFactory = new N64FilesystemFactory();
@ -605,8 +607,8 @@ void OSystem_N64::unlockScreen() {
void OSystem_N64::setShakePos(int shakeOffset) {
// If a rumble pak is plugged in and screen shakes, rumble!
if(shakeOffset && _controllerHasRumble) rumblePakEnable(1, 0);
else if(!shakeOffset && _controllerHasRumble) rumblePakEnable(0, 0);
if (shakeOffset && _controllerHasRumble) rumblePakEnable(1, _controllerNumber);
else if (!shakeOffset && _controllerHasRumble) rumblePakEnable(0, _controllerNumber);
_shakeOffset = shakeOffset;
_dirtyOffscreen = true;
@ -873,6 +875,23 @@ void OSystem_N64::setupMixer(void) {
enableAudioPlayback();
}
/* Check all controller ports for a compatible input adapter. */
void OSystem_N64::detectControllers(void) {
controller_data_status *ctrl_status = (controller_data_status*)memalign(8, sizeof(controller_data_status));
controller_Read_Status(ctrl_status);
_controllerNumber = 0; // Use first controller as default
for (uint8 ctrl_port = 0; ctrl_port < 4; ctrl_port++) {
// Found a standard pad, use this by default.
if (ctrl_status->c[ctrl_port].type == CTRL_PAD_STANDARD) {
_controllerNumber = ctrl_port;
break;
}
}
free(ctrl_status);
}
inline uint16 colRGB888toBGR555(byte r, byte g, byte b) {
return ((r >> 3) << 1) | ((g >> 3) << 6) | ((b >> 3) << 11);
}

View File

@ -60,7 +60,7 @@ bool OSystem_N64::pollEvent(Common::Event &event) {
controller_Read_Buttons(_ctrlData);
static uint16 oldButtons = 0; // old button data... used for button press/release
uint16 newButtons = _ctrlData->c[0].buttons; // Read from controller 0
uint16 newButtons = _ctrlData->c[_controllerNumber].buttons; // Read from controller
bool buttonPressed = false;
static bool left_digital = false;
@ -68,8 +68,8 @@ bool OSystem_N64::pollEvent(Common::Event &event) {
static bool up_digital = false;
static bool down_digital = false;
int8 analogX = (_ctrlData->c[0].throttle >> 8) & 0xFF;
int8 analogY = (_ctrlData->c[0].throttle >> 0) & 0xFF;
int8 analogX = (_ctrlData->c[_controllerNumber].throttle >> 8) & 0xFF;
int8 analogY = (_ctrlData->c[_controllerNumber].throttle >> 0) & 0xFF;
if (newButtons != oldButtons) {
if (DL_BUTTON(newButtons) && !DL_BUTTON(oldButtons)) // Pressed LEFT