From d3146f30110aaad30ba7abe3af89570f1e8fe849 Mon Sep 17 00:00:00 2001 From: skidau Date: Thu, 7 May 2015 14:45:25 +0000 Subject: [PATCH] Hooked up the GBA tilt sensor to the wx gui --- src/Util.cpp | 1 + src/gba/GBA.cpp | 3 +- src/gba/GBAinline.h | 24 +++++++------- src/gba/RTC.cpp | 18 ++++++----- src/gba/RTC.h | 1 + src/wx/opts.cpp | 23 +++++++------- src/wx/opts.h | 2 +- src/wx/panel.cpp | 2 +- src/wx/sys.cpp | 34 ++++++++++++++++++-- src/wx/wxvbam.h | 2 ++ src/wx/xrc/JoyPanel.xrc | 70 ++++++++++++++++++++++++++++------------- 11 files changed, 121 insertions(+), 59 deletions(-) diff --git a/src/Util.cpp b/src/Util.cpp index aa296b5a..d9096eb2 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -743,6 +743,7 @@ void utilGBAFindSave(const int size) detectedSaveType = 3; } rtcEnable(rtcFound); + rtcEnableRumble(!rtcFound); saveType = detectedSaveType; flashSetSize(flashSize); } diff --git a/src/gba/GBA.cpp b/src/gba/GBA.cpp index a76c4468..195f105d 100644 --- a/src/gba/GBA.cpp +++ b/src/gba/GBA.cpp @@ -3923,8 +3923,7 @@ void CPULoop(int ticks) // read default joystick joy = systemReadJoypad(-1); P1 = 0x03FF ^ (joy & 0x3FF); - if(cpuEEPROMSensorEnabled) - systemUpdateMotionSensor(); + systemUpdateMotionSensor(); UPDATE_REG(0x130, P1); u16 P1CNT = READ16LE(((u16 *)&ioMem[0x132])); // this seems wrong, but there are cases where the game diff --git a/src/gba/GBAinline.h b/src/gba/GBAinline.h index 5bfced85..f10d460b 100644 --- a/src/gba/GBAinline.h +++ b/src/gba/GBAinline.h @@ -406,20 +406,18 @@ static inline u8 CPUReadByte(u32 address) goto unreadable; case 14: case 15: - if(cpuSramEnabled | cpuFlashEnabled) - return flashRead(address); - if(cpuEEPROMSensorEnabled) { - switch(address & 0x00008f00) { - case 0x8200: - return systemGetSensorX() & 255; - case 0x8300: - return (systemGetSensorX() >> 8)|0x80; - case 0x8400: - return systemGetSensorY() & 255; - case 0x8500: - return systemGetSensorY() >> 8; - } + switch(address & 0x00008f00) { + case 0x8200: + return systemGetSensorX() & 255; + case 0x8300: + return (systemGetSensorX() >> 8)|0x80; + case 0x8400: + return systemGetSensorY() & 255; + case 0x8500: + return systemGetSensorY() >> 8; } + if (cpuSramEnabled | cpuFlashEnabled) + return flashRead(address); // default default: unreadable: diff --git a/src/gba/RTC.cpp b/src/gba/RTC.cpp index b5c6ec45..7852d64d 100644 --- a/src/gba/RTC.cpp +++ b/src/gba/RTC.cpp @@ -34,6 +34,7 @@ typedef struct { static RTCCLOCKDATA rtcClockData; static bool rtcEnabled = true; +static bool rtcRumbleEnabled = false; void rtcEnable(bool e) { @@ -45,9 +46,13 @@ bool rtcIsEnabled() return rtcEnabled; } +void rtcEnableRumble(bool e) +{ + rtcRumbleEnabled = e; +} + u16 rtcRead(u32 address) { - if(rtcEnabled) { switch(address){ case 0x80000c8: return rtcClockData.byte2; @@ -71,16 +76,16 @@ u16 rtcRead(u32 address) else if (rtcClockData.byte1 == 0x0b) { //sprintf(DebugStr, "Reading Twisted Sensor bit %d", rtcClockData.reserved[11]); u16 v = systemGetSensorZ(); + v = 0x6C0 + v; return ((v >> rtcClockData.reserved[11]) & 1) << 2; } // Real Time Clock - else { + else if (rtcEnabled) { //sprintf(DebugStr, "Reading RTC %02x, %02x, %02x", rtcClockData.byte0, rtcClockData.byte1, rtcClockData.byte2); return rtcClockData.byte0; } break; } - } return READ16LE((&rom[address & 0x1FFFFFE])); } @@ -95,20 +100,17 @@ static u8 toBCD(u8 value) bool rtcWrite(u32 address, u16 value) { - if(!rtcEnabled) - return false; - if(address == 0x80000c8) { rtcClockData.byte2 = (u8)value; // bit 0 = enable reading from 0x80000c4 c6 and c8 } else if (address == 0x80000c6) { rtcClockData.byte1 = (u8)value; // 0=read/1=write (for each of 4 low bits) // rumble is off when not writing to that pin - if (/*rtcWarioRumbleEnabled &&*/ !(value & 8)) systemCartridgeRumble(false); + if (rtcRumbleEnabled && !(value & 8)) systemCartridgeRumble(false); } else if (address == 0x80000c4) { // 4 bits of I/O Port Data (upper bits not used) // WarioWare Twisted rumble - if (/*rtcWarioRumbleEnabled &&*/ (rtcClockData.byte1 & 8)) { + if (rtcRumbleEnabled && (rtcClockData.byte1 & 8)) { systemCartridgeRumble(value & 8); } // Boktai solar sensor diff --git a/src/gba/RTC.h b/src/gba/RTC.h index a125a623..21e65701 100644 --- a/src/gba/RTC.h +++ b/src/gba/RTC.h @@ -4,6 +4,7 @@ u16 rtcRead(u32 address); bool rtcWrite(u32 address, u16 value); void rtcEnable(bool); +void rtcEnableRumble(bool e); bool rtcIsEnabled(); void rtcReset(); diff --git a/src/wx/opts.cpp b/src/wx/opts.cpp index 23d5a796..0a1c31fe 100644 --- a/src/wx/opts.cpp +++ b/src/wx/opts.cpp @@ -106,21 +106,22 @@ const char * const joynames[NUM_KEYS] = { ("A"), ("B"), ("L"), ("R"), ("Select"), ("Start"), ("MotionUp"), ("MotionDown"), ("MotionLeft"), ("MotionRight"), - ("AutoA"), ("AutoB"), + ("MotionIn"), ("MotionOut"), ("AutoA"), ("AutoB"), ("Speed"), ("Capture"), ("GS") }; wxJoyKeyBinding defkeys[NUM_KEYS * 2] = { - { WXK_UP }, { 1, WXJB_AXIS_MINUS, 1 }, { WXK_DOWN }, { 1, WXJB_AXIS_PLUS, 1 }, - { WXK_LEFT }, { 0, WXJB_AXIS_MINUS, 1 }, { WXK_RIGHT }, { 0, WXJB_AXIS_PLUS, 1 }, - { wxT('X') }, { 0, WXJB_BUTTON, 1 }, { wxT('Z') }, { 1, WXJB_BUTTON, 1 }, - { wxT('A') }, { 2, WXJB_BUTTON, 1 }, { wxT('S') }, { 3, WXJB_BUTTON, 1 }, - { WXK_BACK }, { 4, WXJB_BUTTON, 1 }, { WXK_RETURN }, { 5, WXJB_BUTTON, 1 }, - { WXK_NUMPAD_UP }, { 2, WXJB_AXIS_PLUS, 1 }, { WXK_NUMPAD_DOWN }, { 2, WXJB_AXIS_MINUS, 1 }, - { WXK_NUMPAD_LEFT }, { 3, WXJB_AXIS_MINUS, 1 }, { WXK_NUMPAD_RIGHT }, { 3, WXJB_AXIS_PLUS, 1 }, - { wxT('W') }, { 0 }, { wxT('Q') }, { 0 }, - { WXK_SPACE }, { 0 }, { WXK_F11 }, { 0 }, - { 0 } , { 0 } + { WXK_UP }, { 1, WXJB_AXIS_MINUS, 1 }, { WXK_DOWN }, { 1, WXJB_AXIS_PLUS, 1 }, + { WXK_LEFT }, { 0, WXJB_AXIS_MINUS, 1 }, { WXK_RIGHT }, { 0, WXJB_AXIS_PLUS, 1 }, + { wxT('X') }, { 0, WXJB_BUTTON, 1 }, { wxT('Z') }, { 1, WXJB_BUTTON, 1 }, + { wxT('A') }, { 2, WXJB_BUTTON, 1 }, { wxT('S') }, { 3, WXJB_BUTTON, 1 }, + { WXK_BACK }, { 4, WXJB_BUTTON, 1 }, { WXK_RETURN }, { 5, WXJB_BUTTON, 1 }, + { WXK_NUMPAD_UP }, { 2, WXJB_AXIS_PLUS, 1 }, { WXK_NUMPAD_DOWN }, { 2, WXJB_AXIS_MINUS, 1 }, + { WXK_NUMPAD_LEFT }, { 3, WXJB_AXIS_MINUS, 1 }, { WXK_NUMPAD_RIGHT }, { 3, WXJB_AXIS_PLUS, 1 }, + { WXK_NUMPAD_PAGEUP }, { 4, WXJB_AXIS_PLUS, 1 }, { WXK_NUMPAD_PAGEDOWN }, { 4, WXJB_AXIS_MINUS, 1 }, + { wxT('W') }, { 0 }, { wxT('Q') }, { 0 }, + { WXK_SPACE }, { 0 }, { WXK_F11 }, { 0 }, + { 0 } , { 0 } }; wxAcceleratorEntry_v sys_accels; diff --git a/src/wx/opts.h b/src/wx/opts.h index 9af699e5..732ff4ec 100644 --- a/src/wx/opts.h +++ b/src/wx/opts.h @@ -1,7 +1,7 @@ #ifndef WX_OPTS_H #define WX_OPTS_H -#define NUM_KEYS 19 +#define NUM_KEYS 21 extern const char * const joynames[NUM_KEYS]; extern wxJoyKeyBinding defkeys[NUM_KEYS * 2]; // keyboard + joystick defaults diff --git a/src/wx/panel.cpp b/src/wx/panel.cpp index dca0358c..b630cc02 100644 --- a/src/wx/panel.cpp +++ b/src/wx/panel.cpp @@ -913,7 +913,7 @@ void GameArea::OnIdle(wxIdleEvent &event) static uint32_t bmask[NUM_KEYS] = { KEYM_UP, KEYM_DOWN, KEYM_LEFT, KEYM_RIGHT, KEYM_A, KEYM_B, KEYM_L, KEYM_R, KEYM_SELECT, KEYM_START, KEYM_MOTION_UP, KEYM_MOTION_DOWN, KEYM_MOTION_LEFT, - KEYM_MOTION_RIGHT, KEYM_AUTO_A, KEYM_AUTO_B, KEYM_SPEED, KEYM_CAPTURE, + KEYM_MOTION_RIGHT, KEYM_MOTION_IN, KEYM_MOTION_OUT, KEYM_AUTO_A, KEYM_AUTO_B, KEYM_SPEED, KEYM_CAPTURE, KEYM_GS }; diff --git a/src/wx/sys.cpp b/src/wx/sys.cpp index 2ab1833b..3ac1b319 100644 --- a/src/wx/sys.cpp +++ b/src/wx/sys.cpp @@ -30,7 +30,7 @@ int RGB_LOW_BITS_MASK; // these are local, though. int joypress[4], autofire; -static int sensorx[4], sensory[4]; +static int sensorx[4], sensory[4], sensorz[4]; bool pause_next; bool turbo; @@ -531,6 +531,36 @@ void systemUpdateMotionSensor() if(sensory[i] > 2047) sensory[i] = 2047; } + + const int lowZ = -1800; + const int centerZ = 0; + const int highZ = 1800; + const int accelZ = 3; + if (joypress[i] & KEYM_MOTION_IN) { + sensorz[i] += accelZ; + if (sensorz[i] > highZ) + sensorz[i] = highZ; + if (sensorz[i] < centerZ) + sensorz[i] = centerZ + (accelZ * 300); + } + else if (joypress[i] & KEYM_MOTION_OUT) { + sensorz[i] -= accelZ; + if (sensorz[i] < lowZ) + sensorz[i] = lowZ; + if (sensorz[i] > centerZ) + sensorz[i] = centerZ - (accelZ * 300); + } + else if (sensorz[i] > centerZ) { + sensorz[i] -= (accelZ * 100); + if (sensorz[i] < centerZ) + sensorz[i] = centerZ; + } + else { + sensorz[i] += (accelZ * 100); + if (sensorz[i] > centerZ) + sensorz[i] = centerZ; + } + } systemUpdateSolarSensor(); } @@ -547,7 +577,7 @@ int systemGetSensorY() int systemGetSensorZ() { - return sensory[gopts.default_stick - 1]; + return sensorz[gopts.default_stick - 1] / 10; } class PrintDialog : public wxEvtHandler, public wxPrintout diff --git a/src/wx/wxvbam.h b/src/wx/wxvbam.h index cd1c550c..99f8185c 100644 --- a/src/wx/wxvbam.h +++ b/src/wx/wxvbam.h @@ -616,6 +616,8 @@ extern int joypress[4], autofire; #define KEYM_MOTION_DOWN (1<<16) #define KEYM_MOTION_LEFT (1<<17) #define KEYM_MOTION_RIGHT (1<<18) +#define KEYM_MOTION_IN (1<<19) +#define KEYM_MOTION_OUT (1<<20) #include "filters.h" diff --git a/src/wx/xrc/JoyPanel.xrc b/src/wx/xrc/JoyPanel.xrc index 83d454c0..d4efcfe8 100644 --- a/src/wx/xrc/JoyPanel.xrc +++ b/src/wx/xrc/JoyPanel.xrc @@ -227,7 +227,7 @@ - + wxALL|wxALIGN_RIGHT|wxALIGN_CENTRE_VERTICAL 5 @@ -239,26 +239,6 @@ wxALL|wxEXPAND 5 - - wxEXPAND - - - wxEXPAND - - - - - - wxALL|wxALIGN_RIGHT|wxALIGN_CENTRE_VERTICAL - 5 - - - - - - wxALL|wxGROW - 5 - @@ -273,6 +253,20 @@ wxALL|wxEXPAND 5 + + + + + wxALL|wxALIGN_RIGHT|wxALIGN_CENTRE_VERTICAL + 5 + + + + + + wxALL|wxGROW + 5 + @@ -287,6 +281,40 @@ wxALL|wxEXPAND 5 + + + + + wxALL|wxALIGN_RIGHT|wxALIGN_CENTRE_VERTICAL + 5 + + + + + + wxALL|wxEXPAND + 5 + + + wxEXPAND + + + wxEXPAND + + + + + + wxALL|wxALIGN_RIGHT|wxALIGN_CENTRE_VERTICAL + 5 + + + + + + wxALL|wxGROW + 5 +