Permalink
Browse files

Cocoa Port: Retrieve both pending and applied NDS inputs post-NDSExec().

- Also do some minor code cleanup on some input-related stuff.
  • Loading branch information...
rogerman committed Sep 1, 2017
1 parent a86539e commit f67f959fe34fad9a49cdcf5d89091e204b1f426f
View
@@ -2881,54 +2881,56 @@ static void NDS_applyFinalInput()
{
const UserInput& input = NDS_getFinalUserInput();
u16 pad = (0 |
((input.buttons.A ? 0 : 0x80) >> 7) |
((input.buttons.B ? 0 : 0x80) >> 6) |
((input.buttons.T ? 0 : 0x80) >> 5) |
((input.buttons.S ? 0 : 0x80) >> 4) |
((input.buttons.R ? 0 : 0x80) >> 3) |
((input.buttons.L ? 0 : 0x80) >> 2) |
((input.buttons.U ? 0 : 0x80) >> 1) |
((input.buttons.D ? 0 : 0x80) ) |
((input.buttons.E ? 0 : 0x80) << 1) |
((input.buttons.W ? 0 : 0x80) << 2)) ;
pad = LOCAL_TO_LE_16(pad);
((u16 *)MMU.ARM9_REG)[0x130>>1] = (u16)pad;
((u16 *)MMU.ARM7_REG)[0x130>>1] = (u16)pad;
u16 k_cnt = ((u16 *)MMU.ARM9_REG)[0x132>>1];
if ( k_cnt & (1<<14))
{
//INFO("ARM9: KeyPad IRQ (pad 0x%04X, cnt 0x%04X (condition %s))\n", pad, k_cnt, k_cnt&(1<<15)?"AND":"OR");
u16 k_cnt_selected = (k_cnt & 0x3F);
if (k_cnt&(1<<15)) // AND
u16 gbaKeys = ((input.buttons.A) ? 0 : (1 << 0)) |
((input.buttons.B) ? 0 : (1 << 1)) |
((input.buttons.T) ? 0 : (1 << 2)) |
((input.buttons.S) ? 0 : (1 << 3)) |
((input.buttons.R) ? 0 : (1 << 4)) |
((input.buttons.L) ? 0 : (1 << 5)) |
((input.buttons.U) ? 0 : (1 << 6)) |
((input.buttons.D) ? 0 : (1 << 7)) |
((input.buttons.E) ? 0 : (1 << 8)) |
((input.buttons.W) ? 0 : (1 << 9));
gbaKeys = LOCAL_TO_LE_16(gbaKeys);
HostWriteWord(MMU.ARM9_REG, 0x130, gbaKeys);
HostWriteWord(MMU.ARM7_REG, 0x130, gbaKeys);
const u16 k_cnt_9 = HostReadWord(MMU.ARM9_REG, 0x132);
if (k_cnt_9 & (1 << 14))
{
//INFO("ARM9: KeyPad IRQ (pad 0x%04X, cnt 0x%04X (condition %s))\n", pad, k_cnt_9, k_cnt_9 & (1<<15) ? "AND" : "OR");
const u16 k_cnt_selected = (k_cnt_9 & 0x3F);
if (k_cnt_9 & (1 << 15)) // AND
{
if ((~pad & k_cnt_selected) == k_cnt_selected) NDS_makeIrq(ARMCPU_ARM9,IRQ_BIT_KEYPAD);
if ((~gbaKeys & k_cnt_selected) == k_cnt_selected)
NDS_makeIrq(ARMCPU_ARM9,IRQ_BIT_KEYPAD);
}
else // OR
{
if (~pad & k_cnt_selected) NDS_makeIrq(ARMCPU_ARM9,IRQ_BIT_KEYPAD);
if (~gbaKeys & k_cnt_selected)
NDS_makeIrq(ARMCPU_ARM9,IRQ_BIT_KEYPAD);
}
}
k_cnt = ((u16 *)MMU.ARM7_REG)[0x132>>1];
if ( k_cnt & (1<<14))
const u16 k_cnt_7 = HostReadWord(MMU.ARM7_REG, 0x132);
if ( k_cnt_7 & (1 << 14))
{
//INFO("ARM7: KeyPad IRQ (pad 0x%04X, cnt 0x%04X (condition %s))\n", pad, k_cnt, k_cnt&(1<<15)?"AND":"OR");
u16 k_cnt_selected = (k_cnt & 0x3F);
if (k_cnt&(1<<15)) // AND
//INFO("ARM7: KeyPad IRQ (pad 0x%04X, cnt 0x%04X (condition %s))\n", pad, k_cnt_7, k_cnt_7 & (1<<15) ? "AND" : "OR");
const u16 k_cnt_selected = (k_cnt_7 & 0x3F);
if (k_cnt_7 & (1 << 15)) // AND
{
if ((~pad & k_cnt_selected) == k_cnt_selected) NDS_makeIrq(ARMCPU_ARM7,IRQ_BIT_KEYPAD);
if ((~gbaKeys & k_cnt_selected) == k_cnt_selected)
NDS_makeIrq(ARMCPU_ARM7,IRQ_BIT_KEYPAD);
}
else // OR
{
if (~pad & k_cnt_selected) NDS_makeIrq(ARMCPU_ARM7,IRQ_BIT_KEYPAD);
if (~gbaKeys & k_cnt_selected)
NDS_makeIrq(ARMCPU_ARM7,IRQ_BIT_KEYPAD);
}
}
if(input.touch.isTouch)
if (input.touch.isTouch)
{
u16 adc_x = NDS_getADCTouchPosX(input.touch.touchX);
u16 adc_y = NDS_getADCTouchPosY(input.touch.touchY);
@@ -2964,35 +2966,19 @@ static void NDS_applyFinalInput()
if (countLid > 0)
countLid--;
}
u16 padExt = (1<<2) | (1<<4) | (1<<5);
if (!input.buttons.X) padExt |= 1<<0;
if (!input.buttons.Y) padExt |= 1<<1;
if (!input.buttons.G) padExt |= 1<<3; //debug button
if (!nds.isTouch) padExt |= 1<<6; //~touch
if (LidClosed) padExt |= 1<<7;
((u16 *)MMU.ARM7_REG)[0x136>>1] = LOCAL_TO_LE_16(padExt);
InputDisplayString=MakeInputDisplayString(padExt, pad);
//put into the format we want for the movie system
//fRLDUTSBAYXWEg
//we don't really need nds.pad anymore, but removing it would be a pain
nds.pad =
((input.buttons.R ? 1 : 0) << 12)|
((input.buttons.L ? 1 : 0) << 11)|
((input.buttons.D ? 1 : 0) << 10)|
((input.buttons.U ? 1 : 0) << 9)|
((input.buttons.T ? 1 : 0) << 8)|
((input.buttons.S ? 1 : 0) << 7)|
((input.buttons.B ? 1 : 0) << 6)|
((input.buttons.A ? 1 : 0) << 5)|
((input.buttons.Y ? 1 : 0) << 4)|
((input.buttons.X ? 1 : 0) << 3)|
((input.buttons.W ? 1 : 0) << 2)|
((input.buttons.E ? 1 : 0) << 1);
u16 ndsKeysExt = ((input.buttons.X) ? 0 : (1 << 0)) |
((input.buttons.Y) ? 0 : (1 << 1)) |
(1 << 2) |
((input.buttons.G) ? 0 : (1 << 3)) | // debug button
(1 << 4) |
(1 << 5) |
((nds.isTouch) ? 0 : (1 << 6)) |
((!LidClosed) ? 0 : (1 << 7));
T1WriteWord(MMU.ARM7_REG, 0x136, ndsKeysExt);
InputDisplayString = MakeInputDisplayString(ndsKeysExt, gbaKeys);
}
View
@@ -192,7 +192,6 @@ struct NDSSystem
BOOL isFakeBooted;
BOOL isTouch;
u16 pad;
u16 paddle;
@@ -850,28 +850,48 @@ void ClientExecutionControl::FetchOutputPostNDSExec()
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;
const UserInput &ndsInputsPending = NDS_getRawUserInput();
const UserInput &ndsInputsApplied = NDS_getFinalUserInput();
this->_ndsFrameInfo.inputStatesPending.value = INPUT_STATES_CLEAR_VALUE;
this->_ndsFrameInfo.inputStatesPending.A = (ndsInputsPending.buttons.A) ? 0 : 1;
this->_ndsFrameInfo.inputStatesPending.B = (ndsInputsPending.buttons.B) ? 0 : 1;
this->_ndsFrameInfo.inputStatesPending.Select = (ndsInputsPending.buttons.T) ? 0 : 1;
this->_ndsFrameInfo.inputStatesPending.Start = (ndsInputsPending.buttons.S) ? 0 : 1;
this->_ndsFrameInfo.inputStatesPending.Right = (ndsInputsPending.buttons.R) ? 0 : 1;
this->_ndsFrameInfo.inputStatesPending.Left = (ndsInputsPending.buttons.L) ? 0 : 1;
this->_ndsFrameInfo.inputStatesPending.Up = (ndsInputsPending.buttons.U) ? 0 : 1;
this->_ndsFrameInfo.inputStatesPending.Down = (ndsInputsPending.buttons.D) ? 0 : 1;
this->_ndsFrameInfo.inputStatesPending.R = (ndsInputsPending.buttons.E) ? 0 : 1;
this->_ndsFrameInfo.inputStatesPending.L = (ndsInputsPending.buttons.W) ? 0 : 1;
this->_ndsFrameInfo.inputStatesPending.X = (ndsInputsPending.buttons.X) ? 0 : 1;
this->_ndsFrameInfo.inputStatesPending.Y = (ndsInputsPending.buttons.Y) ? 0 : 1;
this->_ndsFrameInfo.inputStatesPending.Debug = (ndsInputsPending.buttons.G) ? 0 : 1;
this->_ndsFrameInfo.inputStatesPending.Touch = (ndsInputsPending.touch.isTouch) ? 0 : 1;
this->_ndsFrameInfo.inputStatesPending.Lid = (ndsInputsPending.buttons.F) ? 0 : 1;
this->_ndsFrameInfo.inputStatesPending.Microphone = (ndsInputsPending.mic.micButtonPressed != 0) ? 0 : 1;
this->_ndsFrameInfo.touchLocXPending = ndsInputsPending.touch.touchX >> 4;
this->_ndsFrameInfo.touchLocYPending = ndsInputsPending.touch.touchY >> 4;
this->_ndsFrameInfo.inputStatesApplied.value = INPUT_STATES_CLEAR_VALUE;
this->_ndsFrameInfo.inputStatesApplied.A = (ndsInputsApplied.buttons.A) ? 0 : 1;
this->_ndsFrameInfo.inputStatesApplied.B = (ndsInputsApplied.buttons.B) ? 0 : 1;
this->_ndsFrameInfo.inputStatesApplied.Select = (ndsInputsApplied.buttons.T) ? 0 : 1;
this->_ndsFrameInfo.inputStatesApplied.Start = (ndsInputsApplied.buttons.S) ? 0 : 1;
this->_ndsFrameInfo.inputStatesApplied.Right = (ndsInputsApplied.buttons.R) ? 0 : 1;
this->_ndsFrameInfo.inputStatesApplied.Left = (ndsInputsApplied.buttons.L) ? 0 : 1;
this->_ndsFrameInfo.inputStatesApplied.Up = (ndsInputsApplied.buttons.U) ? 0 : 1;
this->_ndsFrameInfo.inputStatesApplied.Down = (ndsInputsApplied.buttons.D) ? 0 : 1;
this->_ndsFrameInfo.inputStatesApplied.R = (ndsInputsApplied.buttons.E) ? 0 : 1;
this->_ndsFrameInfo.inputStatesApplied.L = (ndsInputsApplied.buttons.W) ? 0 : 1;
this->_ndsFrameInfo.inputStatesApplied.X = (ndsInputsApplied.buttons.X) ? 0 : 1;
this->_ndsFrameInfo.inputStatesApplied.Y = (ndsInputsApplied.buttons.Y) ? 0 : 1;
this->_ndsFrameInfo.inputStatesApplied.Debug = (ndsInputsApplied.buttons.G) ? 0 : 1;
this->_ndsFrameInfo.inputStatesApplied.Touch = (ndsInputsApplied.touch.isTouch) ? 0 : 1;
this->_ndsFrameInfo.inputStatesApplied.Lid = (ndsInputsApplied.buttons.F) ? 0 : 1;
this->_ndsFrameInfo.inputStatesApplied.Microphone = (ndsInputsApplied.mic.micButtonPressed != 0) ? 0 : 1;
this->_ndsFrameInfo.touchLocXApplied = ndsInputsApplied.touch.touchX >> 4;
this->_ndsFrameInfo.touchLocYApplied = ndsInputsApplied.touch.touchY >> 4;
pthread_mutex_unlock(&this->_mutexOutputPostNDSExec);
}
@@ -39,6 +39,8 @@
#define FRAME_SKIP_BIAS 0.1 // May be any real number. This value acts as a vector addition to the frame skip.
#define MAX_FRAME_SKIP (DS_FRAMES_PER_SECOND / 2.98)
#define INPUT_STATES_CLEAR_VALUE 0xFFFFFFFF00FF03FFUL
enum ExecutionBehavior
{
ExecutionBehavior_Pause = 0,
@@ -112,11 +114,10 @@ typedef union
struct
{
uint16_t gbaKeys;
uint8_t ndsKeysExt;
uint8_t guitarGripKeys;
uint16_t ndsKeysExt;
uint16_t easyPianoKeys;
uint8_t guitarGripKeys;
uint8_t miscKeys;
uint8_t unused;
};
struct
@@ -143,12 +144,7 @@ typedef union
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 :8;
uint8_t PianoC:1;
uint8_t PianoCSharp:1;
@@ -167,11 +163,17 @@ typedef union
uint8_t PianoHighC:1;
uint8_t :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 Paddle:1;
uint8_t Microphone:1;
uint8_t :6;
uint8_t :8;
uint8_t Reset:1;
uint8_t :5;
#else
uint8_t Down:1;
uint8_t Up:1;
@@ -194,12 +196,7 @@ typedef union
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 :8;
uint8_t PianoG:1;
uint8_t PianoFSharp:1;
@@ -218,11 +215,17 @@ typedef union
uint8_t PianoA:1;
uint8_t PianoGSharp:1;
uint8_t :6;
uint8_t :1;
uint8_t GuitarGripGreen:1;
uint8_t GuitarGripRed:1;
uint8_t GuitarGripYellow:1;
uint8_t GuitarGripBlue:1;
uint8_t :3;
uint8_t :5;
uint8_t Reset:1;
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
@@ -275,9 +278,13 @@ struct NDSFrameInfo
uint32_t cpuLoadAvgARM9;
uint32_t cpuLoadAvgARM7;
NDSInputState inputState;
uint16_t touchLocX;
uint16_t touchLocY;
NDSInputState inputStatesPending;
uint8_t touchLocXPending;
uint8_t touchLocYPending;
NDSInputState inputStatesApplied;
uint8_t touchLocXApplied;
uint8_t touchLocYApplied;
void clear()
{
@@ -289,9 +296,14 @@ struct NDSFrameInfo
this->lagFrameCount = 0;
this->cpuLoadAvgARM9 = 0;
this->cpuLoadAvgARM7 = 0;
this->inputState.value = 0xFFFFFFFFFFFFFFFFUL;
this->touchLocX = 0;
this->touchLocY = 0;
this->inputStatesPending.value = INPUT_STATES_CLEAR_VALUE;
this->touchLocXPending = 0;
this->touchLocYPending = 0;
this->inputStatesApplied.value = INPUT_STATES_CLEAR_VALUE;
this->touchLocXApplied = 0;
this->touchLocYApplied = 0;
}
void copyFrom(const NDSFrameInfo &fromObject)
@@ -304,9 +316,14 @@ 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;
this->inputStatesPending = fromObject.inputStatesPending;
this->touchLocXPending = fromObject.touchLocXPending;
this->touchLocYPending = fromObject.touchLocYPending;
this->inputStatesApplied = fromObject.inputStatesApplied;
this->touchLocXApplied = fromObject.touchLocXApplied;
this->touchLocYApplied = fromObject.touchLocYApplied;
}
};
Oops, something went wrong.

0 comments on commit f67f959

Please sign in to comment.