Fixed issues with MK (Pi)

This commit is contained in:
Akop Karapetyan 2019-10-15 00:10:38 -07:00 committed by tmaul
parent 7f737c1474
commit 58ebd0aaf0
1 changed files with 30 additions and 57 deletions

View File

@ -48,6 +48,13 @@ static int handleFreeplayHack(int player, int code);
#define JOY_DEADZONE 0x4000 #define JOY_DEADZONE 0x4000
static unsigned int defaultLayout[] = {
FBK_Z, FBK_X, FBK_C, FBK_A, FBK_S, FBK_D, FBK_Q, FBK_W, FBK_E,
};
static unsigned int capcom6Layout[] = {
FBK_A, FBK_S, FBK_D, FBK_Z, FBK_X, FBK_C,
};
static unsigned char* keyState = NULL; static unsigned char* keyState = NULL;
static struct { static struct {
unsigned char buttons; unsigned char buttons;
@ -368,63 +375,33 @@ static bool usesStreetFighterLayout()
static int setupDefaults(int pindex) static int setupDefaults(int pindex)
{ {
int fbDirs[4];
int fbButtons[6]; // absolute max
int buttonCount = 0;
if (pindex == 0) { if (pindex == 0) {
int i = 0; joyLookupTable[FBK_UPARROW] = JOY_MAP_DIR(pindex, JOY_DIR_UP);
fbDirs[i++] = FBK_UPARROW; joyLookupTable[FBK_LEFTARROW] = JOY_MAP_DIR(pindex, JOY_DIR_LEFT);
fbDirs[i++] = FBK_LEFTARROW; joyLookupTable[FBK_RIGHTARROW] = JOY_MAP_DIR(pindex, JOY_DIR_RIGHT);
fbDirs[i++] = FBK_RIGHTARROW; joyLookupTable[FBK_DOWNARROW] = JOY_MAP_DIR(pindex, JOY_DIR_DOWN);
fbDirs[i++] = FBK_DOWNARROW;
if (usesStreetFighterLayout()) { if (usesStreetFighterLayout())
fbButtons[buttonCount++] = FBK_A; for (int i = 0; i < 6; i++)
fbButtons[buttonCount++] = FBK_S; joyLookupTable[capcom6Layout[i]] = JOY_MAP_BUTTON(pindex, i);
fbButtons[buttonCount++] = FBK_D; else
fbButtons[buttonCount++] = FBK_Z; for (int i = 0; i < 9; i++)
fbButtons[buttonCount++] = FBK_X; joyLookupTable[defaultLayout[i]] = JOY_MAP_BUTTON(pindex, i);
fbButtons[buttonCount++] = FBK_C;
} else { } else {
fbButtons[buttonCount++] = FBK_Z; unsigned int mask = 0x4000 + 0x100 * (pindex - 1);
fbButtons[buttonCount++] = FBK_X; joyLookupTable[mask|0x02] = JOY_MAP_DIR(pindex, JOY_DIR_UP);
fbButtons[buttonCount++] = FBK_C; joyLookupTable[mask|0x00] = JOY_MAP_DIR(pindex, JOY_DIR_LEFT);
fbButtons[buttonCount++] = FBK_V; joyLookupTable[mask|0x01] = JOY_MAP_DIR(pindex, JOY_DIR_RIGHT);
} joyLookupTable[mask|0x03] = JOY_MAP_DIR(pindex, JOY_DIR_DOWN);
} else if (pindex >= 1 && pindex <= 3) {
// P2 to P4
int pmasks[] = { 0x4000, 0x4100, 0x4200 };
int pmask = pmasks[pindex - 1];
int i = 0; for (int i = 0; i < 9; i++)
fbDirs[i++] = pmask|0x02; joyLookupTable[mask|(0x80 + i)] = JOY_MAP_BUTTON(pindex, i);
fbDirs[i++] = pmask|0x00;
fbDirs[i++] = pmask|0x01;
fbDirs[i++] = pmask|0x03;
for (; buttonCount < 6; buttonCount++) {
fbButtons[buttonCount] = pmask|(0x80 + buttonCount);
}
} else {
return 0;
}
// Set direction defaults
int joyDirs[] = { JOY_DIR_UP, JOY_DIR_LEFT, JOY_DIR_RIGHT, JOY_DIR_DOWN };
for (int i = 0; i < 4; i++) {
joyLookupTable[fbDirs[i]] = JOY_MAP_DIR(pindex, joyDirs[i]);
}
// Set button defaults
for (int i = 0; i < buttonCount; i++) {
joyLookupTable[fbButtons[i]] = JOY_MAP_BUTTON(pindex, i);
} }
return 1; return 1;
} }
static int readKonfigFile(int pindex, const char *path, int sixButton) static int readConfigFile(int pindex, const char *path, int sixButton)
{ {
FILE *f = fopen(path, "r"); FILE *f = fopen(path, "r");
if (!f) if (!f)
@ -455,14 +432,10 @@ static int readKonfigFile(int pindex, const char *path, int sixButton)
} else if (pindex == 0) { } else if (pindex == 0) {
if (strncmp(line, "BUTTON", 6) == 0) { if (strncmp(line, "BUTTON", 6) == 0) {
int vbindex = atoi(line + 6) - 1; int vbindex = atoi(line + 6) - 1;
unsigned int code; if (sixButton && vbindex < 6)
if (sixButton && vbindex < 3) joyLookupTable[capcom6Layout[vbindex]] = JOY_MAP_BUTTON(pindex, hbindex);
code = FBK_A + vbindex; else if (!sixButton && vbindex < 9)
else if (sixButton && vbindex >= 3) joyLookupTable[defaultLayout[vbindex]] = JOY_MAP_BUTTON(pindex, hbindex);
code = FBK_Z + vbindex - 3;
else
code = FBK_Z + vbindex;
joyLookupTable[code] = JOY_MAP_BUTTON(pindex, hbindex);
} else if (strncmp(line, "UP", 2) == 0) { } else if (strncmp(line, "UP", 2) == 0) {
joyLookupTable[FBK_UPARROW] = JOY_MAP_DIR(pindex, JOY_DIR_UP); joyLookupTable[FBK_UPARROW] = JOY_MAP_DIR(pindex, JOY_DIR_UP);
} else if (strncmp(line, "DOWN", 4) == 0) { } else if (strncmp(line, "DOWN", 4) == 0) {
@ -525,7 +498,7 @@ static void resetJoystickMap()
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
setupDefaults(i); setupDefaults(i);
if (loadConfig) if (loadConfig)
readKonfigFile(i, path, sixButton); readConfigFile(i, path, sixButton);
} }
} }