diff options
author | Fabio Battaglia | 2010-01-15 23:35:24 +0000 |
---|---|---|
committer | Fabio Battaglia | 2010-01-15 23:35:24 +0000 |
commit | c4a9d373ca30eed9df9aaf555f9798d131f0dd19 (patch) | |
tree | 42b3b9f0f9f49ab88c013fde0ad82582ba7848cc | |
parent | f1439b4fa7246c97820c69bf12625e9ec50e2221 (diff) | |
download | scummvm-rg350-c4a9d373ca30eed9df9aaf555f9798d131f0dd19.tar.gz scummvm-rg350-c4a9d373ca30eed9df9aaf555f9798d131f0dd19.tar.bz2 scummvm-rg350-c4a9d373ca30eed9df9aaf555f9798d131f0dd19.zip |
N64: Use first controller found as input, easier to add support for different input peripherals now
svn-id: r47317
-rw-r--r-- | backends/platform/n64/osys_n64.h | 3 | ||||
-rw-r--r-- | backends/platform/n64/osys_n64_base.cpp | 25 | ||||
-rw-r--r-- | backends/platform/n64/osys_n64_events.cpp | 6 |
3 files changed, 28 insertions, 6 deletions
diff --git a/backends/platform/n64/osys_n64.h b/backends/platform/n64/osys_n64.h index 9ca2e05dd4..d01eb1ff88 100644 --- a/backends/platform/n64/osys_n64.h +++ b/backends/platform/n64/osys_n64.h @@ -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__ */ diff --git a/backends/platform/n64/osys_n64_base.cpp b/backends/platform/n64/osys_n64_base.cpp index 9479081897..59733107a3 100644 --- a/backends/platform/n64/osys_n64_base.cpp +++ b/backends/platform/n64/osys_n64_base.cpp @@ -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); } diff --git a/backends/platform/n64/osys_n64_events.cpp b/backends/platform/n64/osys_n64_events.cpp index 13d04888cb..b0c7ac191d 100644 --- a/backends/platform/n64/osys_n64_events.cpp +++ b/backends/platform/n64/osys_n64_events.cpp @@ -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 |