2020-10-03 15:22:44 +00:00
|
|
|
#include "global.h"
|
|
|
|
#include "vt.h"
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-18 00:09:21 +00:00
|
|
|
s32 D_8012D280 = 1;
|
|
|
|
|
2020-04-14 17:17:25 +00:00
|
|
|
OSMesgQueue* PadMgr_LockSerialMesgQueue(PadMgr* padmgr) {
|
2020-06-14 03:29:59 +00:00
|
|
|
OSMesgQueue* ctrlrQ = NULL;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (D_8012D280 > 2) {
|
2020-06-14 03:29:59 +00:00
|
|
|
// "serialMsgQ Waiting for lock"
|
2020-03-22 21:19:43 +00:00
|
|
|
osSyncPrintf("%2d %d serialMsgQロック待ち %08x %08x %08x\n", osGetThreadId(NULL),
|
2020-06-14 03:29:59 +00:00
|
|
|
padmgr->serialMsgQ.validCount, padmgr, &padmgr->serialMsgQ, &ctrlrQ);
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-06-14 03:29:59 +00:00
|
|
|
osRecvMesg(&padmgr->serialMsgQ, &ctrlrQ, OS_MESG_BLOCK);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (D_8012D280 > 2) {
|
2020-06-14 03:29:59 +00:00
|
|
|
// "serialMsgQ Locked"
|
2020-03-22 21:19:43 +00:00
|
|
|
osSyncPrintf("%2d %d serialMsgQをロックしました %08x\n", osGetThreadId(NULL),
|
2020-06-14 03:29:59 +00:00
|
|
|
padmgr->serialMsgQ.validCount, ctrlrQ);
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-06-14 03:29:59 +00:00
|
|
|
return ctrlrQ;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 03:29:59 +00:00
|
|
|
void PadMgr_UnlockSerialMesgQueue(PadMgr* padmgr, OSMesgQueue* ctrlrQ) {
|
2020-03-22 21:19:43 +00:00
|
|
|
if (D_8012D280 > 2) {
|
2020-06-14 03:29:59 +00:00
|
|
|
// "serialMsgQ Unlock"
|
2020-03-22 21:19:43 +00:00
|
|
|
osSyncPrintf("%2d %d serialMsgQロック解除します %08x %08x %08x\n", osGetThreadId(NULL),
|
2020-06-14 03:29:59 +00:00
|
|
|
padmgr->serialMsgQ.validCount, padmgr, &padmgr->serialMsgQ, ctrlrQ);
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-06-14 03:29:59 +00:00
|
|
|
osSendMesg(&padmgr->serialMsgQ, ctrlrQ, OS_MESG_BLOCK);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (D_8012D280 > 2) {
|
2020-06-14 03:29:59 +00:00
|
|
|
// "serialMsgQ Unlocked"
|
2020-03-22 21:19:43 +00:00
|
|
|
osSyncPrintf("%2d %d serialMsgQロック解除しました %08x %08x %08x\n", osGetThreadId(NULL),
|
2020-06-14 03:29:59 +00:00
|
|
|
padmgr->serialMsgQ.validCount, padmgr, &padmgr->serialMsgQ, ctrlrQ);
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-04-14 17:17:25 +00:00
|
|
|
void PadMgr_LockPadData(PadMgr* padmgr) {
|
2020-06-14 03:29:59 +00:00
|
|
|
osRecvMesg(&padmgr->lockMsgQ, NULL, OS_MESG_BLOCK);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-04-14 17:17:25 +00:00
|
|
|
void PadMgr_UnlockPadData(PadMgr* padmgr) {
|
2020-06-14 03:29:59 +00:00
|
|
|
osSendMesg(&padmgr->lockMsgQ, NULL, OS_MESG_BLOCK);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-04-14 17:17:25 +00:00
|
|
|
void PadMgr_RumbleControl(PadMgr* padmgr) {
|
|
|
|
static u32 errcnt = 0;
|
2020-06-14 03:29:59 +00:00
|
|
|
static u32 frame;
|
2020-03-18 00:09:21 +00:00
|
|
|
s32 temp;
|
2020-04-14 17:17:25 +00:00
|
|
|
s32 triedRumbleComm;
|
2020-06-14 03:29:59 +00:00
|
|
|
OSMesgQueue* ctrlrQ;
|
2020-03-17 04:31:30 +00:00
|
|
|
s32 var4;
|
|
|
|
s32 i;
|
|
|
|
|
2020-03-18 00:09:21 +00:00
|
|
|
temp = 1;
|
2020-06-14 03:29:59 +00:00
|
|
|
ctrlrQ = PadMgr_LockSerialMesgQueue(padmgr);
|
2020-04-14 17:17:25 +00:00
|
|
|
triedRumbleComm = 0;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
for (i = 0; i < 4; i++) {
|
2020-06-14 03:29:59 +00:00
|
|
|
if (padmgr->ctrlrIsConnected[i]) {
|
|
|
|
if (padmgr->padStatus[i].status & 1) {
|
2020-04-14 17:17:25 +00:00
|
|
|
if (padmgr->pakType[i] == temp) {
|
|
|
|
if (padmgr->rumbleEnable[i] != 0) {
|
|
|
|
if (padmgr->rumbleCounter[i] < 3) {
|
2020-06-14 03:29:59 +00:00
|
|
|
// clang-format off
|
|
|
|
if (1) {} osSyncPrintf(VT_FGCOL(YELLOW));
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
// "Vibration pack jumble jumble"?
|
2020-03-18 00:09:21 +00:00
|
|
|
osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "振動パック ぶるぶるぶるぶる");
|
|
|
|
osSyncPrintf(VT_RST);
|
|
|
|
|
2020-06-17 11:16:30 +00:00
|
|
|
if (osSetRumble(&padmgr->pfs[i], temp) != 0) {
|
2020-04-14 17:17:25 +00:00
|
|
|
padmgr->pakType[i] = 0;
|
2020-03-18 00:09:21 +00:00
|
|
|
osSyncPrintf(VT_FGCOL(YELLOW));
|
2020-06-14 03:29:59 +00:00
|
|
|
// "A communication error has occurred with the vibraton pack"
|
2020-03-18 00:09:21 +00:00
|
|
|
osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "振動パックで通信エラーが発生しました");
|
|
|
|
osSyncPrintf(VT_RST);
|
2020-03-22 21:19:43 +00:00
|
|
|
} else {
|
2020-04-14 17:17:25 +00:00
|
|
|
padmgr->rumbleCounter[i] = 3;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
2020-03-18 00:09:21 +00:00
|
|
|
|
2020-04-14 17:17:25 +00:00
|
|
|
triedRumbleComm = 1;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
2020-03-22 21:19:43 +00:00
|
|
|
} else {
|
2020-04-14 17:17:25 +00:00
|
|
|
if (padmgr->rumbleCounter[i] != 0) {
|
2020-06-14 03:29:59 +00:00
|
|
|
// clang-format off
|
|
|
|
if (1) {} osSyncPrintf(VT_FGCOL(YELLOW));
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
// "Stop vibration pack"
|
2020-03-18 00:09:21 +00:00
|
|
|
osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "振動パック 停止");
|
|
|
|
osSyncPrintf(VT_RST);
|
|
|
|
|
2020-06-17 11:16:30 +00:00
|
|
|
if (osSetRumble(&padmgr->pfs[i], 0) != 0) {
|
2020-04-14 17:17:25 +00:00
|
|
|
padmgr->pakType[i] = 0;
|
2020-03-18 00:09:21 +00:00
|
|
|
osSyncPrintf(VT_FGCOL(YELLOW));
|
2020-06-14 03:29:59 +00:00
|
|
|
// "A communication error has occurred with the vibration pack"
|
2020-03-18 00:09:21 +00:00
|
|
|
osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "振動パックで通信エラーが発生しました");
|
|
|
|
osSyncPrintf(VT_RST);
|
2020-03-22 21:19:43 +00:00
|
|
|
} else {
|
2020-04-14 17:17:25 +00:00
|
|
|
padmgr->rumbleCounter[i]--;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
2020-03-18 00:09:21 +00:00
|
|
|
|
2020-04-14 17:17:25 +00:00
|
|
|
triedRumbleComm = 1;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-22 21:19:43 +00:00
|
|
|
} else {
|
2020-04-14 17:17:25 +00:00
|
|
|
if (padmgr->pakType[i] != 0) {
|
|
|
|
if (padmgr->pakType[i] == 1) {
|
2020-03-18 00:09:21 +00:00
|
|
|
osSyncPrintf(VT_FGCOL(YELLOW));
|
2020-06-14 03:29:59 +00:00
|
|
|
// "It seems that a vibration pack was pulled out"
|
2020-03-18 00:09:21 +00:00
|
|
|
osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "振動パックが抜かれたようです");
|
|
|
|
osSyncPrintf(VT_RST);
|
2020-04-14 17:17:25 +00:00
|
|
|
padmgr->pakType[i] = 0;
|
2020-03-22 21:19:43 +00:00
|
|
|
} else {
|
2020-03-18 00:09:21 +00:00
|
|
|
osSyncPrintf(VT_FGCOL(YELLOW));
|
2020-06-14 03:29:59 +00:00
|
|
|
// "It seems that a controller pack that is not a vibration pack was pulled out"
|
2020-03-22 21:19:43 +00:00
|
|
|
osSyncPrintf("padmgr: %dコン: %s\n", i + 1,
|
|
|
|
"振動パックではないコントローラパックが抜かれたようです");
|
2020-03-18 00:09:21 +00:00
|
|
|
osSyncPrintf(VT_RST);
|
2020-04-14 17:17:25 +00:00
|
|
|
padmgr->pakType[i] = 0;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-14 17:17:25 +00:00
|
|
|
if (!triedRumbleComm) {
|
2020-06-14 03:29:59 +00:00
|
|
|
i = frame % 4;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-06-14 03:29:59 +00:00
|
|
|
if (padmgr->ctrlrIsConnected[i] && (padmgr->padStatus[i].status & 1) && (padmgr->pakType[i] != 1)) {
|
2020-06-17 11:16:30 +00:00
|
|
|
var4 = osProbeRumblePak(ctrlrQ, &padmgr->pfs[i], i);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (var4 == 0) {
|
2020-06-14 03:29:59 +00:00
|
|
|
padmgr->pakType[i] = 1;
|
2020-06-17 11:16:30 +00:00
|
|
|
osSetRumble(&padmgr->pfs[i], 1);
|
|
|
|
osSetRumble(&padmgr->pfs[i], 0);
|
2020-03-18 00:09:21 +00:00
|
|
|
osSyncPrintf(VT_FGCOL(YELLOW));
|
2020-06-14 03:29:59 +00:00
|
|
|
// "Recognized vibration pack"
|
|
|
|
osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "振動パックを認識しました");
|
2020-03-18 00:09:21 +00:00
|
|
|
osSyncPrintf(VT_RST);
|
2020-03-22 21:19:43 +00:00
|
|
|
} else if (var4 == 11) {
|
2020-06-14 03:29:59 +00:00
|
|
|
padmgr->pakType[i] = 2;
|
2020-03-22 21:19:43 +00:00
|
|
|
} else if (var4 == 4) {
|
2020-04-14 17:17:25 +00:00
|
|
|
LOG_NUM("++errcnt", ++errcnt, "../padmgr.c", 282);
|
2020-03-18 00:09:21 +00:00
|
|
|
osSyncPrintf(VT_FGCOL(YELLOW));
|
2020-06-14 03:29:59 +00:00
|
|
|
// "Controller pack communication error"
|
|
|
|
osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "コントローラパックの通信エラー");
|
2020-03-18 00:09:21 +00:00
|
|
|
osSyncPrintf(VT_RST);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-14 03:29:59 +00:00
|
|
|
frame++;
|
|
|
|
PadMgr_UnlockSerialMesgQueue(padmgr, ctrlrQ);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-04-14 17:17:25 +00:00
|
|
|
void PadMgr_RumbleStop(PadMgr* padmgr) {
|
2020-03-17 04:31:30 +00:00
|
|
|
s32 i;
|
2020-06-14 03:29:59 +00:00
|
|
|
OSMesgQueue* ctrlrQ;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-06-14 03:29:59 +00:00
|
|
|
ctrlrQ = PadMgr_LockSerialMesgQueue(padmgr);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
for (i = 0; i < 4; i++) {
|
2020-06-17 11:16:30 +00:00
|
|
|
if (osProbeRumblePak(ctrlrQ, &padmgr->pfs[i], i) == 0) {
|
2020-04-14 17:17:25 +00:00
|
|
|
if ((gFaultStruct.msgId == 0) && (padmgr->rumbleOnFrames != 0)) {
|
2020-03-18 00:09:21 +00:00
|
|
|
osSyncPrintf(VT_FGCOL(YELLOW));
|
2020-06-14 03:29:59 +00:00
|
|
|
osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "振動パック 停止"); // "Stop vibration pack"
|
2020-03-18 00:09:21 +00:00
|
|
|
osSyncPrintf(VT_RST);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-06-17 11:16:30 +00:00
|
|
|
osSetRumble(&padmgr->pfs[i], 0);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-14 03:29:59 +00:00
|
|
|
PadMgr_UnlockSerialMesgQueue(padmgr, ctrlrQ);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-04-14 17:17:25 +00:00
|
|
|
void PadMgr_RumbleReset(PadMgr* padmgr) {
|
|
|
|
padmgr->rumbleOffFrames = 3;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-04-14 17:17:25 +00:00
|
|
|
void PadMgr_RumbleSetSingle(PadMgr* padmgr, u32 ctrlr, u32 rumble) {
|
|
|
|
padmgr->rumbleEnable[ctrlr] = rumble;
|
2020-06-14 03:29:59 +00:00
|
|
|
padmgr->rumbleOnFrames = 240;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-04-14 17:17:25 +00:00
|
|
|
void PadMgr_RumbleSet(PadMgr* padmgr, u8* ctrlrRumbles) {
|
|
|
|
s32 i;
|
2020-06-14 03:29:59 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
2020-04-14 17:17:25 +00:00
|
|
|
padmgr->rumbleEnable[i] = ctrlrRumbles[i];
|
|
|
|
}
|
2020-06-14 03:29:59 +00:00
|
|
|
|
|
|
|
padmgr->rumbleOnFrames = 240;
|
2020-04-14 17:17:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PadMgr_ProcessInputs(PadMgr* padmgr) {
|
|
|
|
s32 i;
|
2020-06-14 03:29:59 +00:00
|
|
|
Input* input;
|
2020-10-03 15:22:44 +00:00
|
|
|
OSContPad* padnow1; // original name
|
2020-06-14 03:29:59 +00:00
|
|
|
s32 buttonDiff;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-04-14 17:17:25 +00:00
|
|
|
PadMgr_LockPadData(padmgr);
|
2020-06-14 03:29:59 +00:00
|
|
|
|
|
|
|
input = &padmgr->inputs[0];
|
|
|
|
padnow1 = &padmgr->pads[0];
|
|
|
|
|
|
|
|
for (i = 0; i < padmgr->ncontrollers; i++, input++, padnow1++) {
|
|
|
|
input->prev = input->cur;
|
|
|
|
|
|
|
|
if (1) {} // Necessary to match
|
|
|
|
|
|
|
|
switch (padnow1->errno) {
|
|
|
|
case 0:
|
|
|
|
input->cur = *padnow1;
|
|
|
|
if (!padmgr->ctrlrIsConnected[i]) {
|
|
|
|
padmgr->ctrlrIsConnected[i] = true;
|
|
|
|
osSyncPrintf(VT_FGCOL(YELLOW));
|
|
|
|
osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "認識しました"); // "Recognized"
|
|
|
|
osSyncPrintf(VT_RST);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
input->cur = input->prev;
|
|
|
|
LOG_NUM("this->Key_switch[i]", padmgr->ctrlrIsConnected[i], "../padmgr.c", 380);
|
|
|
|
osSyncPrintf(VT_FGCOL(YELLOW));
|
|
|
|
osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "オーバーランエラーが発生"); // "Overrun error occurred"
|
|
|
|
osSyncPrintf(VT_RST);
|
|
|
|
break;
|
|
|
|
case 8:
|
2020-10-03 15:22:44 +00:00
|
|
|
input->cur.button = 0;
|
|
|
|
input->cur.stick_x = 0;
|
|
|
|
input->cur.stick_y = 0;
|
2020-06-14 03:29:59 +00:00
|
|
|
input->cur.errno = padnow1->errno;
|
|
|
|
if (padmgr->ctrlrIsConnected[i]) {
|
|
|
|
padmgr->ctrlrIsConnected[i] = false;
|
|
|
|
padmgr->pakType[i] = 0;
|
|
|
|
padmgr->rumbleCounter[i] = 0xFF;
|
|
|
|
osSyncPrintf(VT_FGCOL(YELLOW));
|
|
|
|
osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "応答しません"); // "Do not respond"?
|
|
|
|
osSyncPrintf(VT_RST);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
LOG_HEX("padnow1->errno", padnow1->errno, "../padmgr.c", 396);
|
|
|
|
Fault_AddHungupAndCrash("../padmgr.c", 397);
|
2020-04-14 17:17:25 +00:00
|
|
|
}
|
2020-06-14 03:29:59 +00:00
|
|
|
|
2020-10-03 15:22:44 +00:00
|
|
|
buttonDiff = input->prev.button ^ input->cur.button;
|
|
|
|
input->press.button |= (u16)(buttonDiff & input->cur.button);
|
|
|
|
input->rel.button |= (u16)(buttonDiff & input->prev.button);
|
2020-05-25 21:18:14 +00:00
|
|
|
PadUtils_UpdateRelXY(input);
|
2020-10-03 15:22:44 +00:00
|
|
|
input->press.stick_x += (s8)(input->cur.stick_x - input->prev.stick_x);
|
|
|
|
input->press.stick_y += (s8)(input->cur.stick_y - input->prev.stick_y);
|
2020-04-14 17:17:25 +00:00
|
|
|
}
|
2020-06-14 03:29:59 +00:00
|
|
|
|
|
|
|
PadMgr_UnlockPadData(padmgr);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-04-14 17:17:25 +00:00
|
|
|
void PadMgr_HandleRetraceMsg(PadMgr* padmgr) {
|
2020-06-14 03:29:59 +00:00
|
|
|
s32 i;
|
|
|
|
OSMesgQueue* queue;
|
2020-04-14 17:17:25 +00:00
|
|
|
u32 mask;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-04-14 17:17:25 +00:00
|
|
|
queue = PadMgr_LockSerialMesgQueue(padmgr);
|
|
|
|
osContStartReadData(queue);
|
|
|
|
if (padmgr->retraceCallback) {
|
|
|
|
padmgr->retraceCallback(padmgr, padmgr->retraceCallbackValue);
|
|
|
|
}
|
|
|
|
osRecvMesg(queue, NULL, OS_MESG_BLOCK);
|
2020-06-14 03:29:59 +00:00
|
|
|
osContGetReadData(padmgr->pads);
|
2020-04-14 17:17:25 +00:00
|
|
|
if (padmgr->preNMIShutdown) {
|
2020-06-14 03:29:59 +00:00
|
|
|
bzero(padmgr->pads, sizeof(padmgr->pads));
|
2020-04-14 17:17:25 +00:00
|
|
|
}
|
|
|
|
PadMgr_ProcessInputs(padmgr);
|
2020-04-19 01:40:27 +00:00
|
|
|
osContStartQuery(queue);
|
2020-04-14 17:17:25 +00:00
|
|
|
osRecvMesg(queue, NULL, OS_MESG_BLOCK);
|
2020-06-14 03:29:59 +00:00
|
|
|
osContGetQuery(padmgr->padStatus);
|
2020-04-14 17:17:25 +00:00
|
|
|
PadMgr_UnlockSerialMesgQueue(padmgr, queue);
|
|
|
|
|
|
|
|
mask = 0;
|
2020-06-14 03:29:59 +00:00
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
if (padmgr->padStatus[i].errno == 0) {
|
|
|
|
if (padmgr->padStatus[i].type == 5) {
|
2020-04-14 17:17:25 +00:00
|
|
|
mask |= 1 << i;
|
|
|
|
} else {
|
2020-06-14 03:29:59 +00:00
|
|
|
LOG_HEX("this->pad_status[i].type", padmgr->padStatus[i].type, "../padmgr.c", 458);
|
|
|
|
// "An unknown type of controller is connected"
|
2020-04-14 17:17:25 +00:00
|
|
|
osSyncPrintf("知らない種類のコントローラが接続されています\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
padmgr->validCtrlrsMask = mask;
|
|
|
|
|
|
|
|
if (gFaultStruct.msgId) {
|
|
|
|
PadMgr_RumbleStop(padmgr);
|
|
|
|
} else if (padmgr->rumbleOffFrames > 0) {
|
|
|
|
--padmgr->rumbleOffFrames;
|
|
|
|
PadMgr_RumbleStop(padmgr);
|
|
|
|
} else if (padmgr->rumbleOnFrames == 0) {
|
|
|
|
PadMgr_RumbleStop(padmgr);
|
|
|
|
} else if (!padmgr->preNMIShutdown) {
|
|
|
|
PadMgr_RumbleControl(padmgr);
|
|
|
|
--padmgr->rumbleOnFrames;
|
|
|
|
}
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-04-14 17:17:25 +00:00
|
|
|
void PadMgr_HandlePreNMI(PadMgr* padmgr) {
|
2020-03-17 04:31:30 +00:00
|
|
|
osSyncPrintf("padmgr_HandlePreNMI()\n");
|
2020-06-14 03:29:59 +00:00
|
|
|
padmgr->preNMIShutdown = true;
|
2020-04-14 17:17:25 +00:00
|
|
|
PadMgr_RumbleReset(padmgr);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-04-14 17:17:25 +00:00
|
|
|
void PadMgr_RequestPadData(PadMgr* padmgr, Input* inputs, s32 mode) {
|
2020-06-14 03:29:59 +00:00
|
|
|
s32 i;
|
|
|
|
Input* ogInput;
|
|
|
|
Input* newInput;
|
|
|
|
s32 buttonDiff;
|
2020-04-14 17:17:25 +00:00
|
|
|
|
|
|
|
PadMgr_LockPadData(padmgr);
|
2020-06-14 03:29:59 +00:00
|
|
|
|
|
|
|
ogInput = &padmgr->inputs[0];
|
|
|
|
newInput = &inputs[0];
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
if (mode != 0) {
|
|
|
|
*newInput = *ogInput;
|
2020-10-03 15:22:44 +00:00
|
|
|
ogInput->press.button = 0;
|
|
|
|
ogInput->press.stick_x = 0;
|
|
|
|
ogInput->press.stick_y = 0;
|
|
|
|
ogInput->rel.button = 0;
|
2020-04-14 17:17:25 +00:00
|
|
|
} else {
|
2020-06-14 03:29:59 +00:00
|
|
|
newInput->prev = newInput->cur;
|
|
|
|
newInput->cur = ogInput->cur;
|
2020-10-03 15:22:44 +00:00
|
|
|
buttonDiff = newInput->prev.button ^ newInput->cur.button;
|
|
|
|
newInput->press.button = newInput->cur.button & buttonDiff;
|
|
|
|
newInput->rel.button = newInput->prev.button & buttonDiff;
|
2020-06-14 03:29:59 +00:00
|
|
|
PadUtils_UpdateRelXY(newInput);
|
2020-10-03 15:22:44 +00:00
|
|
|
newInput->press.stick_x += (s8)(newInput->cur.stick_x - newInput->prev.stick_x);
|
|
|
|
newInput->press.stick_y += (s8)(newInput->cur.stick_y - newInput->prev.stick_y);
|
2020-04-14 17:17:25 +00:00
|
|
|
}
|
2020-06-14 03:29:59 +00:00
|
|
|
ogInput++;
|
|
|
|
newInput++;
|
2020-04-14 17:17:25 +00:00
|
|
|
}
|
2020-06-14 03:29:59 +00:00
|
|
|
|
2020-04-14 17:17:25 +00:00
|
|
|
PadMgr_UnlockPadData(padmgr);
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-06-14 03:29:59 +00:00
|
|
|
void PadMgr_ThreadEntry(PadMgr* padmgr) {
|
|
|
|
s16* mesg = NULL;
|
2020-04-14 17:17:25 +00:00
|
|
|
s32 exit;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-06-14 03:29:59 +00:00
|
|
|
// "Controller thread execution start"
|
2020-03-17 04:31:30 +00:00
|
|
|
osSyncPrintf("コントローラスレッド実行開始\n");
|
|
|
|
|
2020-06-14 03:29:59 +00:00
|
|
|
exit = false;
|
2020-04-14 17:17:25 +00:00
|
|
|
while (!exit) {
|
2020-06-14 03:29:59 +00:00
|
|
|
if ((D_8012D280 > 2) && (padmgr->interruptMsgQ.validCount == 0)) {
|
|
|
|
// "Waiting for controller thread event"
|
2020-04-08 16:36:15 +00:00
|
|
|
osSyncPrintf("コントローラスレッドイベント待ち %lld\n", OS_CYCLES_TO_USEC(osGetTime()));
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-06-14 03:29:59 +00:00
|
|
|
osRecvMesg(&padmgr->interruptMsgQ, &mesg, OS_MESG_BLOCK);
|
2020-03-17 04:31:30 +00:00
|
|
|
LogUtils_CheckNullPointer("msg", mesg, "../padmgr.c", 563);
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
switch (*mesg) {
|
2020-03-17 04:31:30 +00:00
|
|
|
case OS_SC_RETRACE_MSG:
|
2020-03-22 21:19:43 +00:00
|
|
|
if (D_8012D280 > 2) {
|
2020-04-08 16:36:15 +00:00
|
|
|
osSyncPrintf("padmgr_HandleRetraceMsg START %lld\n", OS_CYCLES_TO_USEC(osGetTime()));
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-04-14 17:17:25 +00:00
|
|
|
PadMgr_HandleRetraceMsg(padmgr);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (D_8012D280 > 2) {
|
2020-04-08 16:36:15 +00:00
|
|
|
osSyncPrintf("padmgr_HandleRetraceMsg END %lld\n", OS_CYCLES_TO_USEC(osGetTime()));
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
case OS_SC_PRE_NMI_MSG:
|
2020-04-14 17:17:25 +00:00
|
|
|
PadMgr_HandlePreNMI(padmgr);
|
2020-03-17 04:31:30 +00:00
|
|
|
break;
|
|
|
|
case OS_SC_NMI_MSG:
|
2020-06-14 03:29:59 +00:00
|
|
|
exit = true;
|
2020-03-17 04:31:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-14 03:29:59 +00:00
|
|
|
IrqMgr_RemoveClient(padmgr->irqMgr, &padmgr->irqClient);
|
|
|
|
|
|
|
|
// "Controller thread execution end"
|
2020-03-17 04:31:30 +00:00
|
|
|
osSyncPrintf("コントローラスレッド実行終了\n");
|
|
|
|
}
|
|
|
|
|
2020-06-14 03:29:59 +00:00
|
|
|
void PadMgr_Init(PadMgr* padmgr, OSMesgQueue* siIntMsgQ, IrqMgr* irqMgr, OSId id, OSPri priority, void* stack) {
|
|
|
|
// "Pad Manager creation"
|
2020-03-17 04:31:30 +00:00
|
|
|
osSyncPrintf("パッドマネージャ作成 padmgr_Create()\n");
|
2020-06-14 03:29:59 +00:00
|
|
|
|
2020-03-17 04:31:30 +00:00
|
|
|
bzero(padmgr, sizeof(PadMgr));
|
2020-06-14 03:29:59 +00:00
|
|
|
padmgr->irqMgr = irqMgr;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-06-14 03:29:59 +00:00
|
|
|
osCreateMesgQueue(&padmgr->interruptMsgQ, padmgr->interruptMsgBuf, 4);
|
|
|
|
IrqMgr_AddClient(padmgr->irqMgr, &padmgr->irqClient, &padmgr->interruptMsgQ);
|
|
|
|
osCreateMesgQueue(&padmgr->serialMsgQ, padmgr->serialMsgBuf, 1);
|
2020-04-14 17:17:25 +00:00
|
|
|
PadMgr_UnlockSerialMesgQueue(padmgr, siIntMsgQ);
|
2020-06-14 03:29:59 +00:00
|
|
|
osCreateMesgQueue(&padmgr->lockMsgQ, padmgr->lockMsgBuf, 1);
|
2020-04-14 17:17:25 +00:00
|
|
|
PadMgr_UnlockPadData(padmgr);
|
2020-06-21 22:43:14 +00:00
|
|
|
PadSetup_Init(siIntMsgQ, &padmgr->validCtrlrsMask, padmgr->padStatus);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-04-14 17:17:25 +00:00
|
|
|
padmgr->ncontrollers = 4;
|
2020-06-17 11:16:30 +00:00
|
|
|
osContSetCh(padmgr->ncontrollers);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-06-14 03:29:59 +00:00
|
|
|
osCreateThread(&padmgr->thread, id, PadMgr_ThreadEntry, padmgr, stack, priority);
|
2020-03-17 04:31:30 +00:00
|
|
|
osStartThread(&padmgr->thread);
|
|
|
|
}
|