aboutsummaryrefslogtreecommitdiff
path: root/backends/platform
diff options
context:
space:
mode:
authorFabio Battaglia2010-01-20 18:51:22 +0000
committerFabio Battaglia2010-01-20 18:51:22 +0000
commitbbc2ec095802421f221046a3882792da52037eab (patch)
treecb2c6c50f076371444df7966cdcbba4eca80f777 /backends/platform
parent0b2453aed8f49840ed275ebb5e13f9215a4c19ff (diff)
downloadscummvm-rg350-bbc2ec095802421f221046a3882792da52037eab.tar.gz
scummvm-rg350-bbc2ec095802421f221046a3882792da52037eab.tar.bz2
scummvm-rg350-bbc2ec095802421f221046a3882792da52037eab.zip
N64: Initial support for n64 mouse, tweaking needed
svn-id: r47408
Diffstat (limited to 'backends/platform')
-rw-r--r--backends/platform/n64/osys_n64.h3
-rw-r--r--backends/platform/n64/osys_n64_base.cpp16
-rw-r--r--backends/platform/n64/osys_n64_events.cpp52
-rw-r--r--backends/platform/n64/osys_n64_utilities.cpp2
4 files changed, 60 insertions, 13 deletions
diff --git a/backends/platform/n64/osys_n64.h b/backends/platform/n64/osys_n64.h
index d01eb1ff88..51a11a5401 100644
--- a/backends/platform/n64/osys_n64.h
+++ b/backends/platform/n64/osys_n64.h
@@ -117,7 +117,8 @@ protected:
int _mouseHotspotX, _mouseHotspotY;
controller_data_buttons *_ctrlData; // Controller data read from the N64 serial interface
- uint8 _controllerNumber;
+ uint8 _controllerPort;
+ int8 _mousePort;
bool _controllerHasRumble;
bool _dirtyOffscreen;
diff --git a/backends/platform/n64/osys_n64_base.cpp b/backends/platform/n64/osys_n64_base.cpp
index 59733107a3..2784bfc235 100644
--- a/backends/platform/n64/osys_n64_base.cpp
+++ b/backends/platform/n64/osys_n64_base.cpp
@@ -137,7 +137,7 @@ OSystem_N64::OSystem_N64() {
detectControllers();
_ctrlData = (controller_data_buttons*)memalign(8, sizeof(controller_data_buttons));
- _controllerHasRumble = (identifyPak(_controllerNumber) == 2);
+ _controllerHasRumble = (identifyPak(_controllerPort) == 2);
_fsFactory = new N64FilesystemFactory();
@@ -607,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, _controllerNumber);
- else if (!shakeOffset && _controllerHasRumble) rumblePakEnable(0, _controllerNumber);
+ if (shakeOffset && _controllerHasRumble) rumblePakEnable(1, _controllerPort);
+ else if (!shakeOffset && _controllerHasRumble) rumblePakEnable(0, _controllerPort);
_shakeOffset = shakeOffset;
_dirtyOffscreen = true;
@@ -880,12 +880,14 @@ 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++) {
+ _controllerPort = 0; // Use first controller as default
+ _mousePort = -1; // Default no mouse
+ for (int8 ctrl_port = 3; ctrl_port >= 0; ctrl_port--) {
// Found a standard pad, use this by default.
if (ctrl_status->c[ctrl_port].type == CTRL_PAD_STANDARD) {
- _controllerNumber = ctrl_port;
- break;
+ _controllerPort = ctrl_port;
+ } else if (ctrl_status->c[ctrl_port].type == CTRL_N64_MOUSE) {
+ _mousePort = ctrl_port;
}
}
diff --git a/backends/platform/n64/osys_n64_events.cpp b/backends/platform/n64/osys_n64_events.cpp
index b0c7ac191d..afbb31c2f6 100644
--- a/backends/platform/n64/osys_n64_events.cpp
+++ b/backends/platform/n64/osys_n64_events.cpp
@@ -45,6 +45,7 @@
#define CU_BUTTON(a) (a & 0x0008)
#define CD_BUTTON(a) (a & 0x0004)
+#define MOUSE_DEADZONE 0
#define PAD_DEADZONE 5
#define PAD_ACCELERATION 10
#define PAD_CHECK_TIME 40
@@ -60,7 +61,13 @@ 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[_controllerNumber].buttons; // Read from controller
+ static uint16 oldMouseButtons = 0;
+
+ uint16 newButtons = _ctrlData->c[_controllerPort].buttons; // Read from controller
+ uint16 newMouseButtons = 0;
+
+ if (_mousePort >= 0)
+ newMouseButtons = _ctrlData->c[_mousePort].buttons;
bool buttonPressed = false;
static bool left_digital = false;
@@ -68,10 +75,18 @@ bool OSystem_N64::pollEvent(Common::Event &event) {
static bool up_digital = false;
static bool down_digital = false;
- int8 analogX = (_ctrlData->c[_controllerNumber].throttle >> 8) & 0xFF;
- int8 analogY = (_ctrlData->c[_controllerNumber].throttle >> 0) & 0xFF;
+ int8 analogX = (_ctrlData->c[_controllerPort].throttle >> 8) & 0xFF;
+ int8 analogY = (_ctrlData->c[_controllerPort].throttle >> 0) & 0xFF;
+
+ int8 mouseX = 0;
+ int8 mouseY = 0;
- if (newButtons != oldButtons) {
+ if (_mousePort >= 0) { // If mouse is present, read movement values
+ mouseX = (_ctrlData->c[_mousePort].throttle >> 8) & 0xFF;
+ mouseY = (_ctrlData->c[_mousePort].throttle >> 0) & 0xFF;
+ }
+
+ if (newButtons != oldButtons) { // Check PAD button press
if (DL_BUTTON(newButtons) && !DL_BUTTON(oldButtons)) // Pressed LEFT
left_digital = true;
else if (!DL_BUTTON(newButtons) && DL_BUTTON(oldButtons)) // Released LEFT
@@ -187,6 +202,30 @@ bool OSystem_N64::pollEvent(Common::Event &event) {
}
}
+ if (newMouseButtons != oldMouseButtons) { // Check mouse button press
+ if (B_BUTTON(newMouseButtons) && !B_BUTTON(oldMouseButtons)) { // Pressed Right Mouse Button
+ buttonPressed = true;
+ event.type = Common::EVENT_RBUTTONDOWN;
+ } else if (!B_BUTTON(newMouseButtons) && B_BUTTON(oldMouseButtons)) { // Released RMB
+ buttonPressed = true;
+ event.type = Common::EVENT_RBUTTONUP;
+ } else if (A_BUTTON(newMouseButtons) && !A_BUTTON(oldMouseButtons)) { // Pressed Left Mouse Button
+ buttonPressed = true;
+ event.type = Common::EVENT_LBUTTONDOWN;
+ } else if (!A_BUTTON(newMouseButtons) && A_BUTTON(oldMouseButtons)) { // Released LMB
+ buttonPressed = true;
+ event.type = Common::EVENT_LBUTTONUP;
+ }
+
+ oldMouseButtons = newMouseButtons; // Save current button status
+
+ if (buttonPressed) {
+ event.mouse.x = _mouseX;
+ event.mouse.y = _mouseY;
+ return true;
+ }
+ }
+
static uint32 _lastPadCheck = 0;
uint32 curTime = getMillis();
@@ -213,6 +252,11 @@ bool OSystem_N64::pollEvent(Common::Event &event) {
if (abs(analogY) > PAD_DEADZONE)
my -= analogY / (PAD_ACCELERATION - (abs(analogY) / 16));
+ if (abs(mouseX) > MOUSE_DEADZONE)
+ mx += mouseX;
+ if (abs(mouseY) > MOUSE_DEADZONE)
+ my -= mouseY;
+
if (mx < 0)
mx = 0;
diff --git a/backends/platform/n64/osys_n64_utilities.cpp b/backends/platform/n64/osys_n64_utilities.cpp
index 969cbb8560..b913151fdb 100644
--- a/backends/platform/n64/osys_n64_utilities.cpp
+++ b/backends/platform/n64/osys_n64_utilities.cpp
@@ -52,7 +52,7 @@ void enableAudioPlayback(void) {
OSystem_N64 *osys = (OSystem_N64*)g_system;
Audio::MixerImpl *_localmixer = (Audio::MixerImpl*)osys->getMixer();
- uint32 sampleBufferSize = 3072;
+ uint32 sampleBufferSize = 2048;
initAudioInterface(osys->_viClockRate, DEFAULT_SOUND_SAMPLE_RATE, 16, sampleBufferSize);
osys->_audioBufferSize = getAIBufferSize();