diff --git a/desmume/src/addons/slot2_guitarGrip.cpp b/desmume/src/addons/slot2_guitarGrip.cpp index 4b3799494..3f547fd99 100644 --- a/desmume/src/addons/slot2_guitarGrip.cpp +++ b/desmume/src/addons/slot2_guitarGrip.cpp @@ -32,14 +32,17 @@ public: virtual void connect() { - guitarKeyStatus = 0; + guitarKeyStatus = 0xFF; } virtual u8 readByte(u8 PROCNUM, u32 addr) { - if (addr == 0x0A000000) return (~guitarKeyStatus); - return (addr & 1)?0xF9:0xFF; + if (addr == 0x0A000000) + return guitarKeyStatus; + + return (addr & 1) ? 0xF9 : 0xFF; } + virtual u16 readWord(u8 PROCNUM, u32 addr) { return 0xF9FF; } virtual u32 readLong(u8 PROCNUM, u32 addr) { return 0xF9FFF9FF; } }; @@ -48,5 +51,15 @@ ISlot2Interface* construct_Slot2_GuitarGrip() { return new Slot2_GuitarGrip(); } void guitarGrip_setKey(bool green, bool red, bool yellow, bool blue) { - guitarKeyStatus = 0 | (green << 6) | (red << 5) | (yellow << 4) | (blue << 3); + const u8 g = (green) ? (1 << 6) : 0; + const u8 r = (red) ? (1 << 5) : 0; + const u8 y = (yellow) ? (1 << 4) : 0; + const u8 b = (blue) ? (1 << 3) : 0; + + guitarKeyStatus = ~(g | r | y | b); +} + +void guitarGrip_setKey(u8 theKeys) +{ + guitarKeyStatus = theKeys; } diff --git a/desmume/src/addons/slot2_piano.cpp b/desmume/src/addons/slot2_piano.cpp index a4ef5886f..6cbcf7a94 100644 --- a/desmume/src/addons/slot2_piano.cpp +++ b/desmume/src/addons/slot2_piano.cpp @@ -17,7 +17,7 @@ #include "../slot2.h" -static u16 pianoKeyStatus = 0; +static u16 pianoKeyStatus = 0; class Slot2_EasyPiano : public ISlot2Interface { @@ -30,7 +30,7 @@ public: virtual void connect() { - pianoKeyStatus = 0; + pianoKeyStatus = 0xE7FF; } virtual u8 readByte(u8 PROCNUM, u32 addr) @@ -61,10 +61,10 @@ public: //LOG("PIANO: %04X\n",pianoKeyStatus); - if(addr == 0x09FFFFFE) return (~(pianoKeyStatus&0xFF)); - if(addr == 0x09FFFFFF) return (~((pianoKeyStatus>>8)&0xFF))&~(0x18); + if (addr == 0x09FFFFFE) return ((pianoKeyStatus >> 0) & 0xFF); + if (addr == 0x09FFFFFF) return ((pianoKeyStatus >> 8) & 0xFF) & ~(0x18); - return (addr & 1)?0xE7:0xFF; + return (addr & 1) ? 0xE7 : 0xFF; } virtual u16 readWord(u8 PROCNUM, u32 addr) { @@ -99,7 +99,7 @@ void piano_setKey(bool c, bool cs, bool d, bool ds, bool e, bool f, bool fs, boo //0x09FFFFFF:7 = ? #define BIT_P(N,v) ((v)?(1<<(N)):0) - pianoKeyStatus = + pianoKeyStatus = ~( BIT_P(0,c) | BIT_P(1,cs) | BIT_P(2,d) | @@ -113,5 +113,10 @@ void piano_setKey(bool c, bool cs, bool d, bool ds, bool e, bool f, bool fs, boo BIT_P(10,as) | BIT_P(13,b) | BIT_P(14,hic) - ; + ); +} + +void piano_setKey(u16 theKeys) +{ + pianoKeyStatus = theKeys; } diff --git a/desmume/src/frontend/cocoa/ClientExecutionControl.cpp b/desmume/src/frontend/cocoa/ClientExecutionControl.cpp index 6ba59a479..5906f8bb7 100644 --- a/desmume/src/frontend/cocoa/ClientExecutionControl.cpp +++ b/desmume/src/frontend/cocoa/ClientExecutionControl.cpp @@ -849,7 +849,30 @@ void ClientExecutionControl::FetchOutputPostNDSExec() rtcGetTimeAsString(tempBuffer); this->_ndsFrameInfo.rtcString = tempBuffer; free(tempBuffer); - + + const UserInput &ndsInput = NDS_getFinalUserInput(); + + this->_ndsFrameInfo.inputState.value = 0xFFFFFFFFFFFFFFFFUL; + this->_ndsFrameInfo.inputState.A = (ndsInput.buttons.A) ? 0 : 1; + this->_ndsFrameInfo.inputState.B = (ndsInput.buttons.B) ? 0 : 1; + this->_ndsFrameInfo.inputState.Select = (ndsInput.buttons.T) ? 0 : 1; + this->_ndsFrameInfo.inputState.Start = (ndsInput.buttons.S) ? 0 : 1; + this->_ndsFrameInfo.inputState.Right = (ndsInput.buttons.R) ? 0 : 1; + this->_ndsFrameInfo.inputState.Left = (ndsInput.buttons.L) ? 0 : 1; + this->_ndsFrameInfo.inputState.Up = (ndsInput.buttons.U) ? 0 : 1; + this->_ndsFrameInfo.inputState.Down = (ndsInput.buttons.D) ? 0 : 1; + this->_ndsFrameInfo.inputState.R = (ndsInput.buttons.E) ? 0 : 1; + this->_ndsFrameInfo.inputState.L = (ndsInput.buttons.W) ? 0 : 1; + this->_ndsFrameInfo.inputState.X = (ndsInput.buttons.X) ? 0 : 1; + this->_ndsFrameInfo.inputState.Y = (ndsInput.buttons.Y) ? 0 : 1; + this->_ndsFrameInfo.inputState.Debug = (ndsInput.buttons.G) ? 0 : 1; + this->_ndsFrameInfo.inputState.Touch = (ndsInput.touch.isTouch) ? 0 : 1; + this->_ndsFrameInfo.inputState.Lid = (ndsInput.buttons.F) ? 0 : 1; + this->_ndsFrameInfo.inputState.Microphone = (ndsInput.mic.micButtonPressed != 0) ? 0 : 1; + + this->_ndsFrameInfo.touchLocX = ndsInput.touch.touchX; + this->_ndsFrameInfo.touchLocY = ndsInput.touch.touchY; + pthread_mutex_unlock(&this->_mutexOutputPostNDSExec); } diff --git a/desmume/src/frontend/cocoa/ClientExecutionControl.h b/desmume/src/frontend/cocoa/ClientExecutionControl.h index 08d905df3..515e88ff9 100644 --- a/desmume/src/frontend/cocoa/ClientExecutionControl.h +++ b/desmume/src/frontend/cocoa/ClientExecutionControl.h @@ -60,7 +60,174 @@ enum CPUEmulationEngineID CPUEmulationEngineID_DynamicRecompiler = 1 }; -typedef struct ClientExecutionControlSettings +enum NDSInputID +{ + NDSInputID_A = 0, + NDSInputID_B, + NDSInputID_Select, + NDSInputID_Start, + NDSInputID_Right, + NDSInputID_Left, + NDSInputID_Up, + NDSInputID_Down, + NDSInputID_R, + NDSInputID_L, + + NDSInputID_X, + NDSInputID_Y, + NDSInputID_Debug, + NDSInputID_Touch, + NDSInputID_Lid, + + NDSInputID_Microphone, + + NDSInputID_GuitarGrip_Green, + NDSInputID_GuitarGrip_Red, + NDSInputID_GuitarGrip_Yellow, + NDSInputID_GuitarGrip_Blue, + + NDSInputID_Piano_C, + NDSInputID_Piano_CSharp, + NDSInputID_Piano_D, + NDSInputID_Piano_DSharp, + NDSInputID_Piano_E, + NDSInputID_Piano_F, + NDSInputID_Piano_FSharp, + NDSInputID_Piano_G, + NDSInputID_Piano_GSharp, + NDSInputID_Piano_A, + NDSInputID_Piano_ASharp, + NDSInputID_Piano_B, + NDSInputID_Piano_HighC, + + NDSInputID_Paddle, + + NDSInputID_InputCount +}; + +typedef union +{ + uint64_t value; + + struct + { + uint16_t gbaKeys; + uint8_t ndsKeysExt; + uint8_t guitarGripKeys; + uint16_t easyPianoKeys; + uint8_t miscKeys; + uint8_t unused; + }; + + struct + { +#ifndef MSB_FIRST + uint8_t A:1; + uint8_t B:1; + uint8_t Select:1; + uint8_t Start:1; + uint8_t Right:1; + uint8_t Left:1; + uint8_t Up:1; + uint8_t Down:1; + + uint8_t R:1; + uint8_t L:1; + uint8_t :6; + + uint8_t X:1; + uint8_t Y:1; + uint8_t :1; + uint8_t Debug:1; + uint8_t :2; + uint8_t Touch:1; + uint8_t Lid:1; + + uint8_t :3; + uint8_t GuitarGripBlue:1; + uint8_t GuitarGripYellow:1; + uint8_t GuitarGripRed:1; + uint8_t GuitarGripGreen:1; + uint8_t :1; + + uint8_t PianoC:1; + uint8_t PianoCSharp:1; + uint8_t PianoD:1; + uint8_t PianoDSharp:1; + uint8_t PianoE:1; + uint8_t PianoF:1; + uint8_t PianoFSharp:1; + uint8_t PianoG:1; + + uint8_t PianoGSharp:1; + uint8_t PianoA:1; + uint8_t PianoASharp:1; + uint8_t :2; + uint8_t PianoB:1; + uint8_t PianoHighC:1; + uint8_t :1; + + uint8_t Paddle:1; + uint8_t Microphone:1; + uint8_t :6; + + uint8_t :8; +#else + uint8_t Down:1; + uint8_t Up:1; + uint8_t Left:1; + uint8_t Right:1; + uint8_t Start:1; + uint8_t Select:1; + uint8_t B:1; + uint8_t A:1; + + uint8_t :6 + uint8_t L:1; + uint8_t R:1; + + uint8_t Lid:1; + uint8_t Touch:1; + uint8_t :2; + uint8_t Debug:1; + uint8_t :1; + uint8_t Y:1; + uint8_t X:1; + + uint8_t :1; + uint8_t GuitarGripGreen:1; + uint8_t GuitarGripRed:1; + uint8_t GuitarGripYellow:1; + uint8_t GuitarGripBlue:1; + uint8_t :3; + + uint8_t PianoG:1; + uint8_t PianoFSharp:1; + uint8_t PianoF:1; + uint8_t PianoE:1; + uint8_t PianoDSharp:1; + uint8_t PianoD:1; + uint8_t PianoCSharp:1; + uint8_t PianoC:1; + + uint8_t :1; + uint8_t PianoHighC:1; + uint8_t PianoB:1; + uint8_t :2; + uint8_t PianoASharp:1; + uint8_t PianoA:1; + uint8_t PianoGSharp:1; + + uint8_t :6; + uint8_t Microphone:1; + uint8_t Paddle:1; + + uint8_t :8; +#endif + }; +} NDSInputState; // Each bit represents the Pressed/Released state of a single input. Pressed=0, Released=1 + +struct ClientExecutionControlSettings { CPUEmulationEngineID cpuEngineID; uint8_t JITMaxBlockSize; @@ -94,8 +261,7 @@ typedef struct ClientExecutionControlSettings ExecutionBehavior execBehavior; FrameJumpBehavior jumpBehavior; - -} ClientExecutionControlSettings; +}; struct NDSFrameInfo { @@ -109,6 +275,10 @@ struct NDSFrameInfo uint32_t cpuLoadAvgARM9; uint32_t cpuLoadAvgARM7; + NDSInputState inputState; + uint16_t touchLocX; + uint16_t touchLocY; + void clear() { this->cpuEmulationEngineName = std::string(); @@ -119,6 +289,9 @@ struct NDSFrameInfo this->lagFrameCount = 0; this->cpuLoadAvgARM9 = 0; this->cpuLoadAvgARM7 = 0; + this->inputState.value = 0xFFFFFFFFFFFFFFFFUL; + this->touchLocX = 0; + this->touchLocY = 0; } void copyFrom(const NDSFrameInfo &fromObject) @@ -131,6 +304,9 @@ struct NDSFrameInfo this->lagFrameCount = fromObject.lagFrameCount; this->cpuLoadAvgARM9 = fromObject.cpuLoadAvgARM9; this->cpuLoadAvgARM7 = fromObject.cpuLoadAvgARM7; + this->inputState = fromObject.inputState; + this->touchLocX = fromObject.touchLocX; + this->touchLocY = fromObject.touchLocY; } }; diff --git a/desmume/src/frontend/cocoa/cocoa_core.mm b/desmume/src/frontend/cocoa/cocoa_core.mm index 9ab74db30..bd4623f67 100644 --- a/desmume/src/frontend/cocoa/cocoa_core.mm +++ b/desmume/src/frontend/cocoa/cocoa_core.mm @@ -1004,10 +1004,13 @@ static void* RunCoreThread(void *arg) continue; } - // Make sure that the mic level is updated at least once per frame, regardless + // Make sure that the mic level is updated at least once every 8 frames, regardless // of whether the NDS actually reads the mic or not. - [cdsController updateMicLevel]; - [cdsController clearMicLevelMeasure]; + if ((ndsFrameInfo.frameIndex & 0x07) == 0x07) + { + [cdsController updateMicLevel]; + [cdsController clearMicLevelMeasure]; + } const uint8_t framesToSkip = execControl->GetFramesToSkip(); diff --git a/desmume/src/frontend/cocoa/cocoa_input.h b/desmume/src/frontend/cocoa/cocoa_input.h index 59cefc235..c81ae538d 100644 --- a/desmume/src/frontend/cocoa/cocoa_input.h +++ b/desmume/src/frontend/cocoa/cocoa_input.h @@ -1,6 +1,6 @@ /* Copyright (C) 2011 Roger Manuel - Copyright (C) 2012-2015 DeSmuME Team + Copyright (C) 2012-2017 DeSmuME Team This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -20,61 +20,22 @@ #include #include +#include "ClientExecutionControl.h" + @class CocoaDSController; class CoreAudioInput; struct CoreAudioInputDeviceInfo; class AudioGenerator; class AudioSampleBlockGenerator; -enum -{ - DSControllerState_Right = 0, - DSControllerState_Left, - DSControllerState_Down, - DSControllerState_Up, - DSControllerState_Select, - DSControllerState_Start, - DSControllerState_B, - DSControllerState_A, - DSControllerState_Y, - DSControllerState_X, - DSControllerState_L, - DSControllerState_R, - DSControllerState_Debug, - DSControllerState_Lid, - - DSControllerState_Touch, - DSControllerState_Microphone, - - DSControllerState_GuitarGrip_Green, - DSControllerState_GuitarGrip_Red, - DSControllerState_GuitarGrip_Yellow, - DSControllerState_GuitarGrip_Blue, - DSControllerState_Piano_C, - DSControllerState_Piano_CSharp, - DSControllerState_Piano_D, - DSControllerState_Piano_DSharp, - DSControllerState_Piano_E, - DSControllerState_Piano_F, - DSControllerState_Piano_FSharp, - DSControllerState_Piano_G, - DSControllerState_Piano_GSharp, - DSControllerState_Piano_A, - DSControllerState_Piano_ASharp, - DSControllerState_Piano_B, - DSControllerState_Piano_HighC, - DSControllerState_Paddle, - - DSControllerState_StatesCount -}; - typedef struct { - bool state; + bool isPressed; bool turbo; bool autohold; - uint16_t turboPattern; -} NDSInput; + uint32_t turboPattern; + uint8_t turboPatternStep; +} ClientInput; @protocol CocoaDSControllerDelegate @@ -92,7 +53,7 @@ typedef struct { id delegate; - NDSInput ndsInput[DSControllerState_StatesCount]; + ClientInput clientInput[NDSInputID_InputCount]; BOOL autohold; BOOL _isAutoholdCleared; @@ -101,10 +62,12 @@ typedef struct NSInteger stylusPressure; float micLevel; + float _micLevelTotal; + float _micLevelsRead; + BOOL hardwareMicMute; BOOL _useHardwareMic; size_t _availableMicSamples; - std::vector *_hwMicLevelList; NSInteger micMode; AudioSampleBlockGenerator *selectedAudioFileGenerator; @@ -144,7 +107,7 @@ typedef struct @property (retain) NSString *hardwareMicSampleRateString; - (void) setControllerState:(BOOL)theState controlID:(const NSUInteger)controlID; -- (void) setControllerState:(BOOL)theState controlID:(const NSUInteger)controlID turbo:(const BOOL)isTurboEnabled; +- (void) setControllerState:(BOOL)theState controlID:(const NSUInteger)controlID turbo:(const BOOL)isTurboEnabled turboPattern:(uint32_t)turboPattern; - (void) setTouchState:(BOOL)theState location:(const NSPoint)theLocation; - (void) setSineWaveGeneratorFrequency:(const double)freq; - (void) clearAutohold; diff --git a/desmume/src/frontend/cocoa/cocoa_input.mm b/desmume/src/frontend/cocoa/cocoa_input.mm index fc0d484c2..a30208840 100644 --- a/desmume/src/frontend/cocoa/cocoa_input.mm +++ b/desmume/src/frontend/cocoa/cocoa_input.mm @@ -1,6 +1,6 @@ /* Copyright (C) 2011 Roger Manuel - Copyright (C) 2012-2016 DeSmuME team + Copyright (C) 2012-2017 DeSmuME team This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -66,12 +66,13 @@ SineWaveGenerator sineWaveGenerator(250.0, MIC_SAMPLE_RATE); return self; } - for (size_t i = 0; i < DSControllerState_StatesCount; i++) + for (size_t i = 0; i < NDSInputID_InputCount; i++) { - ndsInput[i].state = false; - ndsInput[i].turbo = false; - ndsInput[i].turboPattern = false; - ndsInput[i].autohold = false; + clientInput[i].isPressed = false; + clientInput[i].turbo = false; + clientInput[i].turboPattern = 0; + clientInput[i].turboPatternStep = 0; + clientInput[i].autohold = false; } delegate = nil; @@ -81,10 +82,9 @@ SineWaveGenerator sineWaveGenerator(250.0, MIC_SAMPLE_RATE); _useHardwareMic = NO; _availableMicSamples = 0; - _hwMicLevelList = new std::vector; - _hwMicLevelList->reserve(1024); - _hwMicLevelList->clear(); micLevel = 0.0f; + _micLevelTotal = 0.0f; + _micLevelsRead = 0.0f; micMode = MICMODE_NONE; selectedAudioFileGenerator = NULL; @@ -109,7 +109,6 @@ SineWaveGenerator sineWaveGenerator(250.0, MIC_SAMPLE_RATE); - (void)dealloc { delete CAInputDevice; - delete _hwMicLevelList; [self setDelegate:nil]; [self setHardwareMicInfoString:nil]; @@ -183,14 +182,14 @@ SineWaveGenerator sineWaveGenerator(250.0, MIC_SAMPLE_RATE); - (void) setSoftwareMicState:(BOOL)theState { OSSpinLockLock(&spinlockControllerState); - ndsInput[DSControllerState_Microphone].state = (theState) ? true : false; + clientInput[NDSInputID_Microphone].isPressed = (theState) ? true : false; OSSpinLockUnlock(&spinlockControllerState); } - (BOOL) softwareMicState { OSSpinLockLock(&spinlockControllerState); - BOOL theState = (ndsInput[DSControllerState_Microphone].state) ? YES : NO; + BOOL theState = (clientInput[NDSInputID_Microphone].isPressed) ? YES : NO; OSSpinLockUnlock(&spinlockControllerState); return theState; } @@ -218,15 +217,15 @@ SineWaveGenerator sineWaveGenerator(250.0, MIC_SAMPLE_RATE); if (autohold && _isAutoholdCleared) { - memset(ndsInput, 0, sizeof(ndsInput)); + memset(clientInput, 0, sizeof(clientInput)); _isAutoholdCleared = NO; } if (!autohold) { - for (size_t i = 0; i < DSControllerState_StatesCount; i++) + for (size_t i = 0; i < NDSInputID_InputCount; i++) { - ndsInput[i].state = ndsInput[i].autohold; + clientInput[i].isPressed = clientInput[i].autohold; } } @@ -243,12 +242,12 @@ SineWaveGenerator sineWaveGenerator(250.0, MIC_SAMPLE_RATE); - (void) setControllerState:(BOOL)theState controlID:(const NSUInteger)controlID { - [self setControllerState:theState controlID:controlID turbo:NO]; + [self setControllerState:theState controlID:controlID turbo:NO turboPattern:0]; } -- (void) setControllerState:(BOOL)theState controlID:(const NSUInteger)controlID turbo:(const BOOL)isTurboEnabled +- (void) setControllerState:(BOOL)theState controlID:(const NSUInteger)controlID turbo:(const BOOL)isTurboEnabled turboPattern:(uint32_t)turboPattern { - if (controlID >= DSControllerState_StatesCount) + if (controlID >= NDSInputID_InputCount) { return; } @@ -259,16 +258,26 @@ SineWaveGenerator sineWaveGenerator(250.0, MIC_SAMPLE_RATE); { if (theState) { - ndsInput[controlID].turbo = (isTurboEnabled) ? true : false; - ndsInput[controlID].turboPattern = (ndsInput[controlID].turbo) ? 0x5555 : 0; - ndsInput[controlID].autohold = true; + clientInput[controlID].turbo = (isTurboEnabled) ? true : false; + clientInput[controlID].turboPattern = (clientInput[controlID].turbo) ? turboPattern : 0; + clientInput[controlID].autohold = true; + + if (!clientInput[controlID].turbo) + { + clientInput[controlID].turboPatternStep = 0; + } } } else { - ndsInput[controlID].state = (theState || ndsInput[controlID].autohold); - ndsInput[controlID].turbo = (isTurboEnabled && ndsInput[controlID].state); - ndsInput[controlID].turboPattern = (ndsInput[controlID].turbo) ? 0x5555 : 0; + clientInput[controlID].isPressed = (theState || clientInput[controlID].autohold); + clientInput[controlID].turbo = (isTurboEnabled && clientInput[controlID].isPressed); + clientInput[controlID].turboPattern = (clientInput[controlID].turbo) ? turboPattern : 0; + + if (!clientInput[controlID].turbo) + { + clientInput[controlID].turboPatternStep = 0; + } } OSSpinLockUnlock(&spinlockControllerState); @@ -277,7 +286,7 @@ SineWaveGenerator sineWaveGenerator(250.0, MIC_SAMPLE_RATE); - (void) setTouchState:(BOOL)theState location:(const NSPoint)theLocation { OSSpinLockLock(&spinlockControllerState); - ndsInput[DSControllerState_Touch].state = (theState) ? true : false; + clientInput[NDSInputID_Touch].isPressed = (theState) ? true : false; touchLocation = theLocation; OSSpinLockUnlock(&spinlockControllerState); } @@ -294,7 +303,7 @@ SineWaveGenerator sineWaveGenerator(250.0, MIC_SAMPLE_RATE); if (!_isAutoholdCleared) { - memset(ndsInput, 0, sizeof(ndsInput)); + memset(clientInput, 0, sizeof(clientInput)); _isAutoholdCleared = YES; } @@ -307,48 +316,52 @@ SineWaveGenerator sineWaveGenerator(250.0, MIC_SAMPLE_RATE); const NSPoint theLocation = touchLocation; const NSInteger theMicMode = micMode; - static bool flushedStates[DSControllerState_StatesCount] = {0}; + bool flushedStates[NDSInputID_InputCount] = {0}; if (!autohold) { - for (size_t i = 0; i < DSControllerState_StatesCount; i++) + for (size_t i = 0; i < NDSInputID_InputCount; i++) { - flushedStates[i] = (ndsInput[i].state || ndsInput[i].autohold); + flushedStates[i] = (clientInput[i].isPressed || clientInput[i].autohold); - if (ndsInput[i].turbo) + if (clientInput[i].turbo) { - const bool turboState = ndsInput[i].turboPattern & 0x0001; + const bool turboState = (clientInput[i].turboPattern >> clientInput[i].turboPatternStep) & 0x00000001; flushedStates[i] = (flushedStates[i] && turboState); - ndsInput[i].turboPattern >>= 1; - ndsInput[i].turboPattern |= (turboState) ? 0x8000 : 0x0000; + + clientInput[i].turboPatternStep++; + if (clientInput[i].turboPatternStep >= 32) + { + clientInput[i].turboPatternStep = 0; + } } else { - flushedStates[i] = ndsInput[i].state; + flushedStates[i] = clientInput[i].isPressed; } } } OSSpinLockUnlock(&spinlockControllerState); - const bool isTouchDown = flushedStates[DSControllerState_Touch]; - const bool isMicPressed = flushedStates[DSControllerState_Microphone]; + const bool isTouchDown = flushedStates[NDSInputID_Touch]; + const bool isMicPressed = flushedStates[NDSInputID_Microphone]; // Setup the DS pad. - NDS_setPad(flushedStates[DSControllerState_Right], - flushedStates[DSControllerState_Left], - flushedStates[DSControllerState_Down], - flushedStates[DSControllerState_Up], - flushedStates[DSControllerState_Select], - flushedStates[DSControllerState_Start], - flushedStates[DSControllerState_B], - flushedStates[DSControllerState_A], - flushedStates[DSControllerState_Y], - flushedStates[DSControllerState_X], - flushedStates[DSControllerState_L], - flushedStates[DSControllerState_R], - flushedStates[DSControllerState_Debug], - flushedStates[DSControllerState_Lid]); + NDS_setPad(flushedStates[NDSInputID_Right], + flushedStates[NDSInputID_Left], + flushedStates[NDSInputID_Down], + flushedStates[NDSInputID_Up], + flushedStates[NDSInputID_Select], + flushedStates[NDSInputID_Start], + flushedStates[NDSInputID_B], + flushedStates[NDSInputID_A], + flushedStates[NDSInputID_Y], + flushedStates[NDSInputID_X], + flushedStates[NDSInputID_L], + flushedStates[NDSInputID_R], + flushedStates[NDSInputID_Debug], + flushedStates[NDSInputID_Lid]); // Setup the DS touch pad. CommonSettings.StylusPressure = (int)[self stylusPressure]; @@ -367,26 +380,26 @@ SineWaveGenerator sineWaveGenerator(250.0, MIC_SAMPLE_RATE); switch (slot2DeviceType) { case NDS_SLOT2_GUITARGRIP: - guitarGrip_setKey(flushedStates[DSControllerState_GuitarGrip_Green], - flushedStates[DSControllerState_GuitarGrip_Red], - flushedStates[DSControllerState_GuitarGrip_Yellow], - flushedStates[DSControllerState_GuitarGrip_Blue]); + guitarGrip_setKey(flushedStates[NDSInputID_GuitarGrip_Green], + flushedStates[NDSInputID_GuitarGrip_Red], + flushedStates[NDSInputID_GuitarGrip_Yellow], + flushedStates[NDSInputID_GuitarGrip_Blue]); break; case NDS_SLOT2_EASYPIANO: - piano_setKey(flushedStates[DSControllerState_Piano_C], - flushedStates[DSControllerState_Piano_CSharp], - flushedStates[DSControllerState_Piano_D], - flushedStates[DSControllerState_Piano_DSharp], - flushedStates[DSControllerState_Piano_E], - flushedStates[DSControllerState_Piano_F], - flushedStates[DSControllerState_Piano_FSharp], - flushedStates[DSControllerState_Piano_G], - flushedStates[DSControllerState_Piano_GSharp], - flushedStates[DSControllerState_Piano_A], - flushedStates[DSControllerState_Piano_ASharp], - flushedStates[DSControllerState_Piano_B], - flushedStates[DSControllerState_Piano_HighC]); + piano_setKey(flushedStates[NDSInputID_Piano_C], + flushedStates[NDSInputID_Piano_CSharp], + flushedStates[NDSInputID_Piano_D], + flushedStates[NDSInputID_Piano_DSharp], + flushedStates[NDSInputID_Piano_E], + flushedStates[NDSInputID_Piano_F], + flushedStates[NDSInputID_Piano_FSharp], + flushedStates[NDSInputID_Piano_G], + flushedStates[NDSInputID_Piano_GSharp], + flushedStates[NDSInputID_Piano_A], + flushedStates[NDSInputID_Piano_ASharp], + flushedStates[NDSInputID_Piano_B], + flushedStates[NDSInputID_Piano_HighC]); break; case NDS_SLOT2_PADDLE: @@ -511,9 +524,9 @@ SineWaveGenerator sineWaveGenerator(250.0, MIC_SAMPLE_RATE); - (void) reset { - for (size_t i = 0; i < DSControllerState_StatesCount; i++) + for (size_t i = 0; i < NDSInputID_InputCount; i++) { - memset(ndsInput, 0, sizeof(ndsInput)); + memset(clientInput, 0, sizeof(clientInput)); } [self setAutohold:NO]; @@ -521,32 +534,19 @@ SineWaveGenerator sineWaveGenerator(250.0, MIC_SAMPLE_RATE); _isAutoholdCleared = YES; _availableMicSamples = 0; - _hwMicLevelList->clear(); + _micLevelTotal = 0.0f; + _micLevelsRead = 0.0f; } - (void) clearMicLevelMeasure { - _hwMicLevelList->clear(); + _micLevelTotal = 0.0f; + _micLevelsRead = 0.0f; } - (void) updateMicLevel { - float avgMicLevel = 0.0f; - size_t recordedLevelCount = _hwMicLevelList->size(); - - for(size_t i = 0; i < recordedLevelCount; i++) - { - avgMicLevel += (*_hwMicLevelList)[i]; - } - - if (recordedLevelCount > 0) - { - avgMicLevel /= _hwMicLevelList->size(); - } - else - { - avgMicLevel = 0.0f; - } + float avgMicLevel = _micLevelTotal / _micLevelsRead; NSAutoreleasePool *tempPool = [[NSAutoreleasePool alloc] init]; [self setMicLevel:avgMicLevel]; @@ -586,7 +586,8 @@ SineWaveGenerator sineWaveGenerator(250.0, MIC_SAMPLE_RATE); theSample = sampleGenerator->generateSample(); } - _hwMicLevelList->push_back(fabs((float)theSample - MIC_NULL_SAMPLE_VALUE)); + _micLevelTotal += (float)( (MIC_NULL_SAMPLE_VALUE > theSample) ? MIC_NULL_SAMPLE_VALUE - theSample : theSample - MIC_NULL_SAMPLE_VALUE ); + _micLevelsRead += 1.0f; return theSample; } diff --git a/desmume/src/frontend/cocoa/userinterface/EmuControllerDelegate.mm b/desmume/src/frontend/cocoa/userinterface/EmuControllerDelegate.mm index 202565085..dfa2e8133 100644 --- a/desmume/src/frontend/cocoa/userinterface/EmuControllerDelegate.mm +++ b/desmume/src/frontend/cocoa/userinterface/EmuControllerDelegate.mm @@ -1050,9 +1050,10 @@ const BOOL theState = (cmdAttr.input.state == INPUT_ATTRIBUTE_STATE_ON) ? YES : NO; const NSUInteger controlID = cmdAttr.intValue[0]; const BOOL isTurboEnabled = (BOOL)cmdAttr.intValue[1]; + const uint32_t turboPattern = (uint32_t)cmdAttr.intValue[2]; CocoaDSCore *cdsCore = (CocoaDSCore *)[cdsCoreController content]; - [[cdsCore cdsController] setControllerState:theState controlID:controlID turbo:isTurboEnabled]; + [[cdsCore cdsController] setControllerState:theState controlID:controlID turbo:isTurboEnabled turboPattern:turboPattern]; } - (void) cmdUpdateDSTouch:(NSValue *)cmdAttrValue @@ -1097,7 +1098,7 @@ if (cmdAttr.input.isAnalog) { - const NSInteger paddleSensitivity = cmdAttr.floatValue[0]; + const float paddleSensitivity = cmdAttr.floatValue[0]; const float paddleScalar = cmdAttr.input.scalar; float paddleAdjust = (paddleScalar * 2.0f) - 1.0f; @@ -1113,8 +1114,8 @@ } // Normalize the input value for the paddle. - paddleAdjust *= (float)paddleSensitivity; - [[cdsCore cdsController] setPaddleAdjust:paddleAdjust]; + paddleAdjust *= paddleSensitivity; + [[cdsCore cdsController] setPaddleAdjust:(NSInteger)(paddleAdjust + 0.5f)]; } else { diff --git a/desmume/src/frontend/cocoa/userinterface/InputManager.mm b/desmume/src/frontend/cocoa/userinterface/InputManager.mm index ecfae75f4..120cfe32c 100644 --- a/desmume/src/frontend/cocoa/userinterface/InputManager.mm +++ b/desmume/src/frontend/cocoa/userinterface/InputManager.mm @@ -1122,47 +1122,47 @@ static std::unordered_map keyboardNameTable; // Key commandSelector["Enable/Disable GPU State"] = @selector(cmdToggleGPUState:); // Generate the default command attributes for each command tag. (Do this in code rather than in an external file.) - CommandAttributes cmdDSControlRight = NewCommandAttributesForDSControl("Right", DSControllerState_Right, true); - CommandAttributes cmdDSControlLeft = NewCommandAttributesForDSControl("Left", DSControllerState_Left, true); - CommandAttributes cmdDSControlDown = NewCommandAttributesForDSControl("Down", DSControllerState_Down, true); - CommandAttributes cmdDSControlUp = NewCommandAttributesForDSControl("Up", DSControllerState_Up, true); - CommandAttributes cmdDSControlSelect = NewCommandAttributesForDSControl("Select", DSControllerState_Select, true); - CommandAttributes cmdDSControlStart = NewCommandAttributesForDSControl("Start", DSControllerState_Start, true); - CommandAttributes cmdDSControlB = NewCommandAttributesForDSControl("B", DSControllerState_B, true); - CommandAttributes cmdDSControlA = NewCommandAttributesForDSControl("A", DSControllerState_A, true); - CommandAttributes cmdDSControlY = NewCommandAttributesForDSControl("Y", DSControllerState_Y, true); - CommandAttributes cmdDSControlX = NewCommandAttributesForDSControl("X", DSControllerState_X, true); - CommandAttributes cmdDSControlL = NewCommandAttributesForDSControl("L", DSControllerState_L, true); - CommandAttributes cmdDSControlR = NewCommandAttributesForDSControl("R", DSControllerState_R, true); - CommandAttributes cmdDSControlDebug = NewCommandAttributesForDSControl("Debug", DSControllerState_Debug, false); - CommandAttributes cmdDSControlLid = NewCommandAttributesForDSControl("Lid", DSControllerState_Lid, false); + CommandAttributes cmdDSControlRight = NewCommandAttributesForDSControl("Right", NDSInputID_Right, true); + CommandAttributes cmdDSControlLeft = NewCommandAttributesForDSControl("Left", NDSInputID_Left, true); + CommandAttributes cmdDSControlDown = NewCommandAttributesForDSControl("Down", NDSInputID_Down, true); + CommandAttributes cmdDSControlUp = NewCommandAttributesForDSControl("Up", NDSInputID_Up, true); + CommandAttributes cmdDSControlSelect = NewCommandAttributesForDSControl("Select", NDSInputID_Select, true); + CommandAttributes cmdDSControlStart = NewCommandAttributesForDSControl("Start", NDSInputID_Start, true); + CommandAttributes cmdDSControlB = NewCommandAttributesForDSControl("B", NDSInputID_B, true); + CommandAttributes cmdDSControlA = NewCommandAttributesForDSControl("A", NDSInputID_A, true); + CommandAttributes cmdDSControlY = NewCommandAttributesForDSControl("Y", NDSInputID_Y, true); + CommandAttributes cmdDSControlX = NewCommandAttributesForDSControl("X", NDSInputID_X, true); + CommandAttributes cmdDSControlL = NewCommandAttributesForDSControl("L", NDSInputID_L, true); + CommandAttributes cmdDSControlR = NewCommandAttributesForDSControl("R", NDSInputID_R, true); + CommandAttributes cmdDSControlDebug = NewCommandAttributesForDSControl("Debug", NDSInputID_Debug, false); + CommandAttributes cmdDSControlLid = NewCommandAttributesForDSControl("Lid", NDSInputID_Lid, false); - CommandAttributes cmdDSControlTouch = NewCommandAttributesForDSControl("Touch", DSControllerState_Touch, false); + CommandAttributes cmdDSControlTouch = NewCommandAttributesForDSControl("Touch", NDSInputID_Touch, false); cmdDSControlTouch.useInputForIntCoord = true; - CommandAttributes cmdDSControlMic = NewCommandAttributesForDSControl("Microphone", DSControllerState_Microphone, false); + CommandAttributes cmdDSControlMic = NewCommandAttributesForDSControl("Microphone", NDSInputID_Microphone, false); cmdDSControlMic.intValue[1] = MICMODE_INTERNAL_NOISE; cmdDSControlMic.floatValue[0] = 250.0f; - CommandAttributes cmdGuitarGripGreen = NewCommandAttributesForDSControl("Guitar Grip: Green", DSControllerState_GuitarGrip_Green, false); - CommandAttributes cmdGuitarGripRed = NewCommandAttributesForDSControl("Guitar Grip: Red", DSControllerState_GuitarGrip_Red, false); - CommandAttributes cmdGuitarGripYellow = NewCommandAttributesForDSControl("Guitar Grip: Yellow", DSControllerState_GuitarGrip_Yellow, false); - CommandAttributes cmdGuitarGripBlue = NewCommandAttributesForDSControl("Guitar Grip: Blue", DSControllerState_GuitarGrip_Blue, false); - CommandAttributes cmdPianoC = NewCommandAttributesForDSControl("Piano: C", DSControllerState_Piano_C, false); - CommandAttributes cmdPianoCSharp = NewCommandAttributesForDSControl("Piano: C#", DSControllerState_Piano_CSharp, false); - CommandAttributes cmdPianoD = NewCommandAttributesForDSControl("Piano: D", DSControllerState_Piano_D, false); - CommandAttributes cmdPianoDSharp = NewCommandAttributesForDSControl("Piano: D#", DSControllerState_Piano_DSharp, false); - CommandAttributes cmdPianoE = NewCommandAttributesForDSControl("Piano: E", DSControllerState_Piano_E, false); - CommandAttributes cmdPianoF = NewCommandAttributesForDSControl("Piano: F", DSControllerState_Piano_F, false); - CommandAttributes cmdPianoFSharp = NewCommandAttributesForDSControl("Piano: F#", DSControllerState_Piano_FSharp, false); - CommandAttributes cmdPianoG = NewCommandAttributesForDSControl("Piano: G", DSControllerState_Piano_G, false); - CommandAttributes cmdPianoGSharp = NewCommandAttributesForDSControl("Piano: G#", DSControllerState_Piano_GSharp, false); - CommandAttributes cmdPianoA = NewCommandAttributesForDSControl("Piano: A", DSControllerState_Piano_A, false); - CommandAttributes cmdPianoASharp = NewCommandAttributesForDSControl("Piano: A#", DSControllerState_Piano_ASharp, false); - CommandAttributes cmdPianoB = NewCommandAttributesForDSControl("Piano: B", DSControllerState_Piano_B, false); - CommandAttributes cmdPianoHighC = NewCommandAttributesForDSControl("Piano: High C", DSControllerState_Piano_HighC, false); + CommandAttributes cmdGuitarGripGreen = NewCommandAttributesForDSControl("Guitar Grip: Green", NDSInputID_GuitarGrip_Green, false); + CommandAttributes cmdGuitarGripRed = NewCommandAttributesForDSControl("Guitar Grip: Red", NDSInputID_GuitarGrip_Red, false); + CommandAttributes cmdGuitarGripYellow = NewCommandAttributesForDSControl("Guitar Grip: Yellow", NDSInputID_GuitarGrip_Yellow, false); + CommandAttributes cmdGuitarGripBlue = NewCommandAttributesForDSControl("Guitar Grip: Blue", NDSInputID_GuitarGrip_Blue, false); + CommandAttributes cmdPianoC = NewCommandAttributesForDSControl("Piano: C", NDSInputID_Piano_C, false); + CommandAttributes cmdPianoCSharp = NewCommandAttributesForDSControl("Piano: C#", NDSInputID_Piano_CSharp, false); + CommandAttributes cmdPianoD = NewCommandAttributesForDSControl("Piano: D", NDSInputID_Piano_D, false); + CommandAttributes cmdPianoDSharp = NewCommandAttributesForDSControl("Piano: D#", NDSInputID_Piano_DSharp, false); + CommandAttributes cmdPianoE = NewCommandAttributesForDSControl("Piano: E", NDSInputID_Piano_E, false); + CommandAttributes cmdPianoF = NewCommandAttributesForDSControl("Piano: F", NDSInputID_Piano_F, false); + CommandAttributes cmdPianoFSharp = NewCommandAttributesForDSControl("Piano: F#", NDSInputID_Piano_FSharp, false); + CommandAttributes cmdPianoG = NewCommandAttributesForDSControl("Piano: G", NDSInputID_Piano_G, false); + CommandAttributes cmdPianoGSharp = NewCommandAttributesForDSControl("Piano: G#", NDSInputID_Piano_GSharp, false); + CommandAttributes cmdPianoA = NewCommandAttributesForDSControl("Piano: A", NDSInputID_Piano_A, false); + CommandAttributes cmdPianoASharp = NewCommandAttributesForDSControl("Piano: A#", NDSInputID_Piano_ASharp, false); + CommandAttributes cmdPianoB = NewCommandAttributesForDSControl("Piano: B", NDSInputID_Piano_B, false); + CommandAttributes cmdPianoHighC = NewCommandAttributesForDSControl("Piano: High C", NDSInputID_Piano_HighC, false); - CommandAttributes cmdPaddle = NewCommandAttributesForDSControl("Paddle", DSControllerState_Paddle, false); + CommandAttributes cmdPaddle = NewCommandAttributesForDSControl("Paddle", NDSInputID_Paddle, false); cmdPaddle.allowAnalogInput = true; cmdPaddle.intValue[1] = 0; cmdPaddle.floatValue[0] = 10.0f; @@ -1323,7 +1323,7 @@ static std::unordered_map keyboardNameTable; // Key [self removeAllMappingsForCommandTag:[commandTag cStringUsingEncoding:NSUTF8StringEncoding]]; } - for(NSDictionary *deviceInfo in deviceInfoList) + for (NSDictionary *deviceInfo in deviceInfoList) { const char *cmdTag = [commandTag cStringUsingEncoding:NSUTF8StringEncoding]; CommandAttributes cmdAttr = defaultCommandAttributes[cmdTag]; @@ -1341,6 +1341,11 @@ static std::unordered_map keyboardNameTable; // Key cmdAttr.intValue[0] = defaultCommandAttributes[cmdTag].intValue[0]; } + if (cmdAttr.selector == @selector(cmdUpdateDSControllerWithTurbo:)) + { + cmdAttr.intValue[2] = defaultCommandAttributes[cmdTag].intValue[2]; + } + // Copy all command attributes into a new deviceInfo dictionary. NSMutableDictionary *newDeviceInfo = DeviceInfoDictionaryWithCommandAttributes(&cmdAttr, [deviceInfo valueForKey:@"deviceCode"], @@ -2023,30 +2028,31 @@ CommandAttributes NewCommandAttributesForDSControl(const char *commandTag, const switch (controlID) { - case DSControllerState_Right: - case DSControllerState_Left: - case DSControllerState_Down: - case DSControllerState_Up: - case DSControllerState_Select: - case DSControllerState_Start: - case DSControllerState_B: - case DSControllerState_A: - case DSControllerState_Y: - case DSControllerState_X: - case DSControllerState_L: - case DSControllerState_R: + case NDSInputID_Right: + case NDSInputID_Left: + case NDSInputID_Down: + case NDSInputID_Up: + case NDSInputID_Select: + case NDSInputID_Start: + case NDSInputID_B: + case NDSInputID_A: + case NDSInputID_Y: + case NDSInputID_X: + case NDSInputID_L: + case NDSInputID_R: cmdAttr.selector = @selector(cmdUpdateDSControllerWithTurbo:); + cmdAttr.intValue[2] = (supportTurbo) ? 0x33333333 : 0; break; - case DSControllerState_Touch: + case NDSInputID_Touch: cmdAttr.selector = @selector(cmdUpdateDSTouch:); break; - case DSControllerState_Microphone: + case NDSInputID_Microphone: cmdAttr.selector = @selector(cmdUpdateDSMicrophone:); break; - case DSControllerState_Paddle: + case NDSInputID_Paddle: cmdAttr.selector = @selector(cmdUpdateDSPaddle:); break;