From 296650e2c70a244c7e0c0904bc6fcc1c2bc298e9 Mon Sep 17 00:00:00 2001 From: Michael Buckley Date: Sat, 19 Oct 2019 07:08:27 -0700 Subject: [PATCH] Rearrange mac controls to be configured by player, reducing the number of button codes required --- macosx/Snes9x/AppDelegate.m | 119 +++++---- macosx/Snes9x/Base.lproj/MainMenu.xib | 4 +- macosx/mac-controls.h | 283 +++----------------- macosx/mac-controls.mm | 284 ++++++++++---------- macosx/mac-keyboard.h | 9 +- macosx/mac-keyboard.mm | 31 ++- macosx/mac-musicbox.h | 2 +- macosx/mac-os.h | 9 +- macosx/mac-os.mm | 362 +++++++------------------- 9 files changed, 370 insertions(+), 733 deletions(-) diff --git a/macosx/Snes9x/AppDelegate.m b/macosx/Snes9x/AppDelegate.m index 490586ee..9d18570f 100644 --- a/macosx/Snes9x/AppDelegate.m +++ b/macosx/Snes9x/AppDelegate.m @@ -66,47 +66,47 @@ static NSString * const kKeyboardPrefs = @"KeyboardConfig"; NSDictionary *defaultKeyBindings = @{ kKeyboardPrefs : @{ - @(k1PUp).stringValue : @(kVK_UpArrow), - @(k1PDown).stringValue : @(kVK_DownArrow), - @(k1PLeft).stringValue : @(kVK_LeftArrow), - @(k1PRight).stringValue : @(kVK_RightArrow), - @(k1PY).stringValue : @(kVK_ANSI_X), - @(k1PB).stringValue : @(kVK_ANSI_C), - @(k1PX).stringValue : @(kVK_ANSI_D), - @(k1PA).stringValue : @(kVK_ANSI_V), - @(k1PL).stringValue : @(kVK_ANSI_A), - @(k1PR).stringValue : @(kVK_ANSI_S), - @(k1PStart).stringValue : @(kVK_Space), - @(k1PSelect).stringValue : @(kVK_Return), + @(kUp).stringValue : @(kVK_UpArrow), + @(kDown).stringValue : @(kVK_DownArrow), + @(kLeft).stringValue : @(kVK_LeftArrow), + @(kRight).stringValue : @(kVK_RightArrow), + @(kY).stringValue : @(kVK_ANSI_X), + @(kB).stringValue : @(kVK_ANSI_C), + @(kX).stringValue : @(kVK_ANSI_D), + @(kA).stringValue : @(kVK_ANSI_V), + @(kL).stringValue : @(kVK_ANSI_A), + @(kR).stringValue : @(kVK_ANSI_S), + @(kStart).stringValue : @(kVK_Space), + @(kSelect).stringValue : @(kVK_Return), - @(k2PUp).stringValue : @(kVK_ANSI_Keypad8), - @(k2PDown).stringValue : @(kVK_ANSI_Keypad2), - @(k2PLeft).stringValue : @(kVK_ANSI_Keypad4), - @(k2PRight).stringValue : @(kVK_ANSI_Keypad6), - @(k2PY).stringValue : @(kVK_PageDown), - @(k2PB).stringValue : @(kVK_PageUp), - @(k2PX).stringValue : @(kVK_End), - @(k2PA).stringValue : @(kVK_Home), - @(k2PL).stringValue : @(kVK_ANSI_Keypad0), - @(k2PR).stringValue : @(kVK_ANSI_KeypadDecimal), - @(k2PStart).stringValue : @(kVK_ANSI_KeypadEnter), - @(k2PSelect).stringValue : @(kVK_ANSI_KeypadPlus), + @(kNumButtons + kUp).stringValue : @(kVK_ANSI_Keypad8), + @(kNumButtons + kDown).stringValue : @(kVK_ANSI_Keypad2), + @(kNumButtons + kLeft).stringValue : @(kVK_ANSI_Keypad4), + @(kNumButtons + kRight).stringValue : @(kVK_ANSI_Keypad6), + @(kNumButtons + kY).stringValue : @(kVK_PageDown), + @(kNumButtons + kB).stringValue : @(kVK_PageUp), + @(kNumButtons + kX).stringValue : @(kVK_End), + @(kNumButtons + kA).stringValue : @(kVK_Home), + @(kNumButtons + kL).stringValue : @(kVK_ANSI_Keypad0), + @(kNumButtons + kR).stringValue : @(kVK_ANSI_KeypadDecimal), + @(kNumButtons + kStart).stringValue : @(kVK_ANSI_KeypadEnter), + @(kNumButtons + kSelect).stringValue : @(kVK_ANSI_KeypadPlus), - @(k1PKeyFastForward).stringValue : @(kVK_ANSI_Backslash), - @(k1PKeyFreeze).stringValue : @(kVK_ANSI_1), - @(k1PKeyDefrost).stringValue : @(kVK_ANSI_0), - @(k1PKeyScreenshot).stringValue : @(kVK_ANSI_Grave), - @(k1PKeySPC).stringValue : @(kVK_ANSI_R), - @(k1PKeyScopeTurbo).stringValue : @(kVK_ANSI_B), - @(k1PKeyScopePause).stringValue : @(kVK_ANSI_N), - @(k1PKeyScopeCursor).stringValue : @(kVK_ANSI_Q), - @(k1PKeyOffScreen).stringValue : @(kVK_Tab), - @(k1PKeyFunction).stringValue : @(kVK_ANSI_Slash), - @(k1PKeyAlt).stringValue : @(kVK_ANSI_Period), - @(k1PKeyFFDown).stringValue : @(kVK_ANSI_Q), - @(k1PKeyFFUp).stringValue : @(kVK_ANSI_W), - @(k1PKeyEsc).stringValue : @(kVK_Escape), - @(k1PKeyTC).stringValue : @(kVK_ANSI_Comma) + @(kKeyFastForward).stringValue : @(kVK_ANSI_Backslash), + @(kKeyFreeze).stringValue : @(kVK_ANSI_1), + @(kKeyDefrost).stringValue : @(kVK_ANSI_0), + @(kKeyScreenshot).stringValue : @(kVK_ANSI_Grave), + @(kKeySPC).stringValue : @(kVK_ANSI_R), + @(kKeyScopeTurbo).stringValue : @(kVK_ANSI_B), + @(kKeyScopePause).stringValue : @(kVK_ANSI_N), + @(kKeyScopeCursor).stringValue : @(kVK_ANSI_Q), + @(kKeyOffScreen).stringValue : @(kVK_Tab), + @(kKeyFunction).stringValue : @(kVK_ANSI_Slash), + @(kKeyAlt).stringValue : @(kVK_ANSI_Period), + @(kKeyFFDown).stringValue : @(kVK_ANSI_Q), + @(kKeyFFUp).stringValue : @(kVK_ANSI_W), + @(kKeyEsc).stringValue : @(kVK_Escape), + @(kKeyTC).stringValue : @(kVK_ANSI_Comma) } }; @@ -116,31 +116,36 @@ static NSString * const kKeyboardPrefs = @"KeyboardConfig"; for (NSString *control in [self.keys copy]) { - [self setControl:@(control.integerValue) forKey:self.keys[control]]; + NSInteger key = control.integerValue; + NSInteger player = key / kNumButtons; + S9xButtonCode buttonCode = (S9xButtonCode)(key - (kNumButtons * player)); + [self setButtonCode:buttonCode forKeyCode:self.keys[control].integerValue player:player]; } [self importKeySettings]; [defaults synchronize]; } -- (void)setControl:(NSNumber *)control forKey:(NSNumber *)key +- (void)setButtonCode:(S9xButtonCode)buttonCode forKeyCode:(int16)keyCode player:(int8)player { - if (key == nil || control == nil) + if (keyCode < 0) { return; } - self.keys[control.stringValue] = key; + self.keys[@(buttonCode + (kNumButtons * player)).stringValue] = @(keyCode); - S9xKey oldControl = kNumButtons; - [self.s9xEngine setControl:(S9xKey)control.intValue forKey:key.intValue oldControl:&oldControl oldKey:NULL]; - - if (oldControl >= 0 && oldControl < kNumButtons) + S9xButtonCode oldButton = kNumButtons; + int8 oldPlayer = -1; + if ([self.s9xEngine setButton:buttonCode forKey:keyCode player:player oldButton:&oldButton oldPlayer:&oldPlayer oldKey:NULL]) { - [self.keys removeObjectForKey:@(oldControl).stringValue]; - } + if (oldButton >= 0 && oldButton < kNumButtons && oldPlayer >= 0 && oldPlayer < MAC_MAX_PLAYERS) + { + [self.keys removeObjectForKey:@(oldButton + (kNumButtons * oldPlayer)).stringValue]; + } - [NSUserDefaults.standardUserDefaults setObject:[self.keys copy] forKey:kKeyboardPrefs]; + [NSUserDefaults.standardUserDefaults setObject:[self.keys copy] forKey:kKeyboardPrefs]; + } } - (void)importRecentItems @@ -188,11 +193,11 @@ static NSString * const kKeyboardPrefs = @"KeyboardConfig"; // The first 24 enum values are the same, but we have to adjust after that. if ( i < 24 ) { - [self setControl:@(i) forKey:@(bytes[i])]; + [self setButtonCode:(S9xButtonCode)(i - (i / 12)) forKeyCode:bytes[i] player:i / 12]; } else { - [self setControl:@(i - 24 + k1PKeyFastForward) forKey:@(bytes[i])]; + [self setButtonCode:(S9xButtonCode)(i - 24 + kKeyFastForward) forKeyCode:bytes[i] player:0]; } } } @@ -226,4 +231,14 @@ static NSString * const kKeyboardPrefs = @"KeyboardConfig"; return NO; } +- (BOOL)validateMenuItem:(NSMenuItem *)menuItem +{ + return [self.s9xEngine isPaused]; +} + +- (IBAction)terminate:(id)sender +{ + [NSApp terminate:sender]; +} + @end diff --git a/macosx/Snes9x/Base.lproj/MainMenu.xib b/macosx/Snes9x/Base.lproj/MainMenu.xib index cb4a74d9..227ccc14 100644 --- a/macosx/Snes9x/Base.lproj/MainMenu.xib +++ b/macosx/Snes9x/Base.lproj/MainMenu.xib @@ -10,7 +10,7 @@ - + @@ -53,7 +53,7 @@ - + diff --git a/macosx/mac-controls.h b/macosx/mac-controls.h index 0dc56ff9..bf1f7c2f 100644 --- a/macosx/mac-controls.h +++ b/macosx/mac-controls.h @@ -22,7 +22,9 @@ #ifndef _mac_controls_h_ #define _mac_controls_h_ -#define KeyIsPressed(km, bm, k) (km[k] || bm[k]) +#define MAC_MAX_PLAYERS 8 + +#define KeyIsPressed(km, bm, p, k) (km[p][k] || bm[p][k]) enum { @@ -181,256 +183,39 @@ enum typedef enum { - k1PUp, - k1PDown, - k1PLeft, - k1PRight, - k1PY, - k1PB, - k1PX, - k1PA, - k1PL, - k1PR, - k1PStart, - k1PSelect, + kUp, + kDown, + kLeft, + kRight, + kY, + kB, + kX, + kA, + kL, + kR, + kStart, + kSelect, - k2PUp, - k2PDown, - k2PLeft, - k2PRight, - k2PY, - k2PB, - k2PX, - k2PA, - k2PL, - k2PR, - k2PStart, - k2PSelect, - - k3PUp, - k3PDown, - k3PLeft, - k3PRight, - k3PY, - k3PB, - k3PX, - k3PA, - k3PL, - k3PR, - k3PStart, - k3PSelect, - - k4PUp, - k4PDown, - k4PLeft, - k4PRight, - k4PY, - k4PB, - k4PX, - k4PA, - k4PL, - k4PR, - k4PStart, - k4PSelect, - - k5PUp, - k5PDown, - k5PLeft, - k5PRight, - k5PY, - k5PB, - k5PX, - k5PA, - k5PL, - k5PR, - k5PStart, - k5PSelect, - - k6PUp, - k6PDown, - k6PLeft, - k6PRight, - k6PY, - k6PB, - k6PX, - k6PA, - k6PL, - k6PR, - k6PStart, - k6PSelect, - - k7PUp, - k7PDown, - k7PLeft, - k7PRight, - k7PY, - k7PB, - k7PX, - k7PA, - k7PL, - k7PR, - k7PStart, - k7PSelect, - - k8PUp, - k8PDown, - k8PLeft, - k8PRight, - k8PY, - k8PB, - k8PX, - k8PA, - k8PL, - k8PR, - k8PStart, - k8PSelect, - - k1PKeyFastForward, - k1PKeyFreeze, - k1PKeyDefrost, - k1PKeyScreenshot, - k1PKeySPC, - k1PKeyScopeTurbo, - k1PKeyScopePause, - k1PKeyScopeCursor, - k1PKeyOffScreen, - k1PKeyFunction, - k1PKeyAlt, - k1PKeyFFDown, - k1PKeyFFUp, - k1PKeyEsc, - k1PKeyTC, - k1PKeyMouseLeft, - k1PKeyMouseRight, - - k2PKeyFastForward, - k2PKeyFreeze, - k2PKeyDefrost, - k2PKeyScreenshot, - k2PKeySPC, - k2PKeyScopeTurbo, - k2PKeyScopePause, - k2PKeyScopeCursor, - k2PKeyOffScreen, - k2PKeyFunction, - k2PKeyAlt, - k2PKeyFFDown, - k2PKeyFFUp, - k2PKeyEsc, - k2PKeyTC, - k2PKeyMouseLeft, - k2PKeyMouseRight, - - k3PKeyFastForward, - k3PKeyFreeze, - k3PKeyDefrost, - k3PKeyScreenshot, - k3PKeySPC, - k3PKeyScopeTurbo, - k3PKeyScopePause, - k3PKeyScopeCursor, - k3PKeyOffScreen, - k3PKeyFunction, - k3PKeyAlt, - k3PKeyFFDown, - k3PKeyFFUp, - k3PKeyEsc, - k3PKeyTC, - k3PKeyMouseLeft, - k3PKeyMouseRight, - - k4PKeyFastForward, - k4PKeyFreeze, - k4PKeyDefrost, - k4PKeyScreenshot, - k4PKeySPC, - k4PKeyScopeTurbo, - k4PKeyScopePause, - k4PKeyScopeCursor, - k4PKeyOffScreen, - k4PKeyFunction, - k4PKeyAlt, - k4PKeyFFDown, - k4PKeyFFUp, - k4PKeyEsc, - k4PKeyTC, - k4PKeyMouseLeft, - k4PKeyMouseRight, - - k5PKeyFastForward, - k5PKeyFreeze, - k5PKeyDefrost, - k5PKeyScreenshot, - k5PKeySPC, - k5PKeyScopeTurbo, - k5PKeyScopePause, - k5PKeyScopeCursor, - k5PKeyOffScreen, - k5PKeyFunction, - k5PKeyAlt, - k5PKeyFFDown, - k5PKeyFFUp, - k5PKeyEsc, - k5PKeyTC, - k5PKeyMouseLeft, - k5PKeyMouseRight, - - k6PKeyFastForward, - k6PKeyFreeze, - k6PKeyDefrost, - k6PKeyScreenshot, - k6PKeySPC, - k6PKeyScopeTurbo, - k6PKeyScopePause, - k6PKeyScopeCursor, - k6PKeyOffScreen, - k6PKeyFunction, - k6PKeyAlt, - k6PKeyFFDown, - k6PKeyFFUp, - k6PKeyEsc, - k6PKeyTC, - k6PKeyMouseLeft, - k6PKeyMouseRight, - - k7PKeyFastForward, - k7PKeyFreeze, - k7PKeyDefrost, - k7PKeyScreenshot, - k7PKeySPC, - k7PKeyScopeTurbo, - k7PKeyScopePause, - k7PKeyScopeCursor, - k7PKeyOffScreen, - k7PKeyFunction, - k7PKeyAlt, - k7PKeyFFDown, - k7PKeyFFUp, - k7PKeyEsc, - k7PKeyTC, - k7PKeyMouseLeft, - k7PKeyMouseRight, - - k8PKeyFastForward, - k8PKeyFreeze, - k8PKeyDefrost, - k8PKeyScreenshot, - k8PKeySPC, - k8PKeyScopeTurbo, - k8PKeyScopePause, - k8PKeyScopeCursor, - k8PKeyOffScreen, - k8PKeyFunction, - k8PKeyAlt, - k8PKeyFFDown, - k8PKeyFFUp, - k8PKeyEsc, - k8PKeyTC, - k8PKeyMouseLeft, - k8PKeyMouseRight, + kKeyFastForward, + kKeyFreeze, + kKeyDefrost, + kKeyScreenshot, + kKeySPC, + kKeyScopeTurbo, + kKeyScopePause, + kKeyScopeCursor, + kKeyOffScreen, + kKeyFunction, + kKeyAlt, + kKeyFFDown, + kKeyFFUp, + kKeyEsc, + kKeyTC, + kKeyMouseLeft, + kKeyMouseRight, kNumButtons -} S9xKey; +} S9xButtonCode; typedef enum { kISpFastForward, @@ -455,6 +240,6 @@ typedef enum { void ControlPadFlagsToS9xReportButtons (int, uint32); void ControlPadFlagsToS9xPseudoPointer (uint32); -long ISpKeyIsPressed (bool8 keys[kNumButtons], bool8 gamepadButtons[kNumButtons], ISpKey key); +long ISpKeyIsPressed (bool8 keys[MAC_MAX_PLAYERS][kNumButtons], bool8 gamepadButtons[MAC_MAX_PLAYERS][kNumButtons], ISpKey key); #endif diff --git a/macosx/mac-controls.mm b/macosx/mac-controls.mm index 89d83874..f3251087 100644 --- a/macosx/mac-controls.mm +++ b/macosx/mac-controls.mm @@ -175,8 +175,8 @@ bool S9xPollButton (uint32 id, bool *pressed) { #define kmControlKey 0x3B - bool8 keys[MAC_NUM_KEYCODES]; - bool8 gamepadButtons[kNumButtons]; + bool8 keys[MAC_MAX_PLAYERS][kNumButtons]; + bool8 gamepadButtons[MAC_MAX_PLAYERS][kNumButtons]; CopyPressedKeys(keys, gamepadButtons); @@ -218,9 +218,9 @@ bool S9xPollButton (uint32 id, bool *pressed) { switch (id & 0xFF) { - case 0: *pressed = KeyIsPressed(keys, gamepadButtons, k2PStart); break; - case 1: *pressed = KeyIsPressed(keys, gamepadButtons, k2PB); break; - case 2: *pressed = KeyIsPressed(keys, gamepadButtons, k2PA); + case 0: *pressed = KeyIsPressed(keys, gamepadButtons, 1, kStart); break; + case 1: *pressed = KeyIsPressed(keys, gamepadButtons, 1, kB); break; + case 2: *pressed = KeyIsPressed(keys, gamepadButtons, 1, kA); } } } @@ -310,196 +310,196 @@ void ControlPadFlagsToS9xPseudoPointer (uint32 p) S9xReportButton(kMacCMapPseudoPtrBase + 3, (p & 0x0100)); } -long ISpKeyIsPressed (bool8 keys[kNumButtons], bool8 gamepadButtons[kNumButtons], ISpKey key) +long ISpKeyIsPressed (bool8 keys[MAC_MAX_PLAYERS][kNumButtons], bool8 gamepadButtons[MAC_MAX_PLAYERS][kNumButtons], ISpKey key) { switch (key) { case kISpFastForward: return - KeyIsPressed(keys, gamepadButtons, k1PKeyFastForward) || - KeyIsPressed(keys, gamepadButtons, k2PKeyFastForward) || - KeyIsPressed(keys, gamepadButtons, k3PKeyFastForward) || - KeyIsPressed(keys, gamepadButtons, k4PKeyFastForward) || - KeyIsPressed(keys, gamepadButtons, k5PKeyFastForward) || - KeyIsPressed(keys, gamepadButtons, k6PKeyFastForward) || - KeyIsPressed(keys, gamepadButtons, k7PKeyFastForward) || - KeyIsPressed(keys, gamepadButtons, k8PKeyFastForward); + KeyIsPressed(keys, gamepadButtons, 0, kKeyFastForward) || + KeyIsPressed(keys, gamepadButtons, 1, kKeyFastForward) || + KeyIsPressed(keys, gamepadButtons, 2, kKeyFastForward) || + KeyIsPressed(keys, gamepadButtons, 3, kKeyFastForward) || + KeyIsPressed(keys, gamepadButtons, 4, kKeyFastForward) || + KeyIsPressed(keys, gamepadButtons, 5, kKeyFastForward) || + KeyIsPressed(keys, gamepadButtons, 6, kKeyFastForward) || + KeyIsPressed(keys, gamepadButtons, 7, kKeyFastForward); case kISpFreeze: return - KeyIsPressed(keys, gamepadButtons, k1PKeyFreeze) || - KeyIsPressed(keys, gamepadButtons, k2PKeyFreeze) || - KeyIsPressed(keys, gamepadButtons, k3PKeyFreeze) || - KeyIsPressed(keys, gamepadButtons, k4PKeyFreeze) || - KeyIsPressed(keys, gamepadButtons, k5PKeyFreeze) || - KeyIsPressed(keys, gamepadButtons, k6PKeyFreeze) || - KeyIsPressed(keys, gamepadButtons, k7PKeyFreeze) || - KeyIsPressed(keys, gamepadButtons, k8PKeyFreeze); + KeyIsPressed(keys, gamepadButtons, 0, kKeyFreeze) || + KeyIsPressed(keys, gamepadButtons, 1, kKeyFreeze) || + KeyIsPressed(keys, gamepadButtons, 2, kKeyFreeze) || + KeyIsPressed(keys, gamepadButtons, 3, kKeyFreeze) || + KeyIsPressed(keys, gamepadButtons, 4, kKeyFreeze) || + KeyIsPressed(keys, gamepadButtons, 5, kKeyFreeze) || + KeyIsPressed(keys, gamepadButtons, 6, kKeyFreeze) || + KeyIsPressed(keys, gamepadButtons, 7, kKeyFreeze); case kISpDefrost: return - KeyIsPressed(keys, gamepadButtons, k1PKeyDefrost) || - KeyIsPressed(keys, gamepadButtons, k2PKeyDefrost) || - KeyIsPressed(keys, gamepadButtons, k3PKeyDefrost) || - KeyIsPressed(keys, gamepadButtons, k4PKeyDefrost) || - KeyIsPressed(keys, gamepadButtons, k5PKeyDefrost) || - KeyIsPressed(keys, gamepadButtons, k6PKeyDefrost) || - KeyIsPressed(keys, gamepadButtons, k7PKeyDefrost) || - KeyIsPressed(keys, gamepadButtons, k8PKeyDefrost); + KeyIsPressed(keys, gamepadButtons, 0, kKeyDefrost) || + KeyIsPressed(keys, gamepadButtons, 1, kKeyDefrost) || + KeyIsPressed(keys, gamepadButtons, 2, kKeyDefrost) || + KeyIsPressed(keys, gamepadButtons, 3, kKeyDefrost) || + KeyIsPressed(keys, gamepadButtons, 4, kKeyDefrost) || + KeyIsPressed(keys, gamepadButtons, 5, kKeyDefrost) || + KeyIsPressed(keys, gamepadButtons, 6, kKeyDefrost) || + KeyIsPressed(keys, gamepadButtons, 7, kKeyDefrost); case kISpScreenshot: return - KeyIsPressed(keys, gamepadButtons, k1PKeyScreenshot) || - KeyIsPressed(keys, gamepadButtons, k2PKeyScreenshot) || - KeyIsPressed(keys, gamepadButtons, k3PKeyScreenshot) || - KeyIsPressed(keys, gamepadButtons, k4PKeyScreenshot) || - KeyIsPressed(keys, gamepadButtons, k5PKeyScreenshot) || - KeyIsPressed(keys, gamepadButtons, k6PKeyScreenshot) || - KeyIsPressed(keys, gamepadButtons, k7PKeyScreenshot) || - KeyIsPressed(keys, gamepadButtons, k8PKeyScreenshot); + KeyIsPressed(keys, gamepadButtons, 0, kKeyScreenshot) || + KeyIsPressed(keys, gamepadButtons, 1, kKeyScreenshot) || + KeyIsPressed(keys, gamepadButtons, 2, kKeyScreenshot) || + KeyIsPressed(keys, gamepadButtons, 3, kKeyScreenshot) || + KeyIsPressed(keys, gamepadButtons, 4, kKeyScreenshot) || + KeyIsPressed(keys, gamepadButtons, 5, kKeyScreenshot) || + KeyIsPressed(keys, gamepadButtons, 6, kKeyScreenshot) || + KeyIsPressed(keys, gamepadButtons, 7, kKeyScreenshot); case kISpSPC: return - KeyIsPressed(keys, gamepadButtons, k1PKeySPC) || - KeyIsPressed(keys, gamepadButtons, k2PKeySPC) || - KeyIsPressed(keys, gamepadButtons, k3PKeySPC) || - KeyIsPressed(keys, gamepadButtons, k4PKeySPC) || - KeyIsPressed(keys, gamepadButtons, k5PKeySPC) || - KeyIsPressed(keys, gamepadButtons, k6PKeySPC) || - KeyIsPressed(keys, gamepadButtons, k7PKeySPC) || - KeyIsPressed(keys, gamepadButtons, k8PKeySPC); + KeyIsPressed(keys, gamepadButtons, 0, kKeySPC) || + KeyIsPressed(keys, gamepadButtons, 1, kKeySPC) || + KeyIsPressed(keys, gamepadButtons, 2, kKeySPC) || + KeyIsPressed(keys, gamepadButtons, 3, kKeySPC) || + KeyIsPressed(keys, gamepadButtons, 4, kKeySPC) || + KeyIsPressed(keys, gamepadButtons, 5, kKeySPC) || + KeyIsPressed(keys, gamepadButtons, 6, kKeySPC) || + KeyIsPressed(keys, gamepadButtons, 7, kKeySPC); case kISpScopeTurbo: return - KeyIsPressed(keys, gamepadButtons, k1PKeyScopeTurbo) || - KeyIsPressed(keys, gamepadButtons, k2PKeyScopeTurbo) || - KeyIsPressed(keys, gamepadButtons, k3PKeyScopeTurbo) || - KeyIsPressed(keys, gamepadButtons, k4PKeyScopeTurbo) || - KeyIsPressed(keys, gamepadButtons, k5PKeyScopeTurbo) || - KeyIsPressed(keys, gamepadButtons, k6PKeyScopeTurbo) || - KeyIsPressed(keys, gamepadButtons, k7PKeyScopeTurbo) || - KeyIsPressed(keys, gamepadButtons, k8PKeyScopeTurbo); + KeyIsPressed(keys, gamepadButtons, 0, kKeyScopeTurbo) || + KeyIsPressed(keys, gamepadButtons, 1, kKeyScopeTurbo) || + KeyIsPressed(keys, gamepadButtons, 2, kKeyScopeTurbo) || + KeyIsPressed(keys, gamepadButtons, 3, kKeyScopeTurbo) || + KeyIsPressed(keys, gamepadButtons, 4, kKeyScopeTurbo) || + KeyIsPressed(keys, gamepadButtons, 5, kKeyScopeTurbo) || + KeyIsPressed(keys, gamepadButtons, 6, kKeyScopeTurbo) || + KeyIsPressed(keys, gamepadButtons, 7, kKeyScopeTurbo); case kISpScopePause: return - KeyIsPressed(keys, gamepadButtons, k1PKeyScopePause) || - KeyIsPressed(keys, gamepadButtons, k2PKeyScopePause) || - KeyIsPressed(keys, gamepadButtons, k3PKeyScopePause) || - KeyIsPressed(keys, gamepadButtons, k4PKeyScopePause) || - KeyIsPressed(keys, gamepadButtons, k5PKeyScopePause) || - KeyIsPressed(keys, gamepadButtons, k6PKeyScopePause) || - KeyIsPressed(keys, gamepadButtons, k7PKeyScopePause) || - KeyIsPressed(keys, gamepadButtons, k8PKeyScopePause); + KeyIsPressed(keys, gamepadButtons, 0, kKeyScopePause) || + KeyIsPressed(keys, gamepadButtons, 1, kKeyScopePause) || + KeyIsPressed(keys, gamepadButtons, 2, kKeyScopePause) || + KeyIsPressed(keys, gamepadButtons, 3, kKeyScopePause) || + KeyIsPressed(keys, gamepadButtons, 4, kKeyScopePause) || + KeyIsPressed(keys, gamepadButtons, 5, kKeyScopePause) || + KeyIsPressed(keys, gamepadButtons, 6, kKeyScopePause) || + KeyIsPressed(keys, gamepadButtons, 7, kKeyScopePause); case kISpScopeCursor: return - KeyIsPressed(keys, gamepadButtons, k1PKeyScopeCursor) || - KeyIsPressed(keys, gamepadButtons, k2PKeyScopeCursor) || - KeyIsPressed(keys, gamepadButtons, k3PKeyScopeCursor) || - KeyIsPressed(keys, gamepadButtons, k4PKeyScopeCursor) || - KeyIsPressed(keys, gamepadButtons, k5PKeyScopeCursor) || - KeyIsPressed(keys, gamepadButtons, k6PKeyScopeCursor) || - KeyIsPressed(keys, gamepadButtons, k7PKeyScopeCursor) || - KeyIsPressed(keys, gamepadButtons, k8PKeyScopeCursor); + KeyIsPressed(keys, gamepadButtons, 0, kKeyScopeCursor) || + KeyIsPressed(keys, gamepadButtons, 1, kKeyScopeCursor) || + KeyIsPressed(keys, gamepadButtons, 2, kKeyScopeCursor) || + KeyIsPressed(keys, gamepadButtons, 3, kKeyScopeCursor) || + KeyIsPressed(keys, gamepadButtons, 4, kKeyScopeCursor) || + KeyIsPressed(keys, gamepadButtons, 5, kKeyScopeCursor) || + KeyIsPressed(keys, gamepadButtons, 6, kKeyScopeCursor) || + KeyIsPressed(keys, gamepadButtons, 7, kKeyScopeCursor); case kISpOffScreen: return - KeyIsPressed(keys, gamepadButtons, k1PKeyOffScreen) || - KeyIsPressed(keys, gamepadButtons, k2PKeyOffScreen) || - KeyIsPressed(keys, gamepadButtons, k3PKeyOffScreen) || - KeyIsPressed(keys, gamepadButtons, k4PKeyOffScreen) || - KeyIsPressed(keys, gamepadButtons, k5PKeyOffScreen) || - KeyIsPressed(keys, gamepadButtons, k6PKeyOffScreen) || - KeyIsPressed(keys, gamepadButtons, k7PKeyOffScreen) || - KeyIsPressed(keys, gamepadButtons, k8PKeyOffScreen); + KeyIsPressed(keys, gamepadButtons, 0, kKeyOffScreen) || + KeyIsPressed(keys, gamepadButtons, 1, kKeyOffScreen) || + KeyIsPressed(keys, gamepadButtons, 2, kKeyOffScreen) || + KeyIsPressed(keys, gamepadButtons, 3, kKeyOffScreen) || + KeyIsPressed(keys, gamepadButtons, 4, kKeyOffScreen) || + KeyIsPressed(keys, gamepadButtons, 5, kKeyOffScreen) || + KeyIsPressed(keys, gamepadButtons, 6, kKeyOffScreen) || + KeyIsPressed(keys, gamepadButtons, 7, kKeyOffScreen); case kISpFunction: return - KeyIsPressed(keys, gamepadButtons, k1PKeyFunction) || - KeyIsPressed(keys, gamepadButtons, k2PKeyFunction) || - KeyIsPressed(keys, gamepadButtons, k3PKeyFunction) || - KeyIsPressed(keys, gamepadButtons, k4PKeyFunction) || - KeyIsPressed(keys, gamepadButtons, k5PKeyFunction) || - KeyIsPressed(keys, gamepadButtons, k6PKeyFunction) || - KeyIsPressed(keys, gamepadButtons, k7PKeyFunction) || - KeyIsPressed(keys, gamepadButtons, k8PKeyFunction); + KeyIsPressed(keys, gamepadButtons, 0, kKeyFunction) || + KeyIsPressed(keys, gamepadButtons, 1, kKeyFunction) || + KeyIsPressed(keys, gamepadButtons, 2, kKeyFunction) || + KeyIsPressed(keys, gamepadButtons, 3, kKeyFunction) || + KeyIsPressed(keys, gamepadButtons, 4, kKeyFunction) || + KeyIsPressed(keys, gamepadButtons, 5, kKeyFunction) || + KeyIsPressed(keys, gamepadButtons, 6, kKeyFunction) || + KeyIsPressed(keys, gamepadButtons, 7, kKeyFunction); case kISpAlt: return - KeyIsPressed(keys, gamepadButtons, k1PKeyAlt) || - KeyIsPressed(keys, gamepadButtons, k2PKeyAlt) || - KeyIsPressed(keys, gamepadButtons, k3PKeyAlt) || - KeyIsPressed(keys, gamepadButtons, k4PKeyAlt) || - KeyIsPressed(keys, gamepadButtons, k5PKeyAlt) || - KeyIsPressed(keys, gamepadButtons, k6PKeyAlt) || - KeyIsPressed(keys, gamepadButtons, k7PKeyAlt) || - KeyIsPressed(keys, gamepadButtons, k8PKeyAlt); + KeyIsPressed(keys, gamepadButtons, 0, kKeyAlt) || + KeyIsPressed(keys, gamepadButtons, 1, kKeyAlt) || + KeyIsPressed(keys, gamepadButtons, 2, kKeyAlt) || + KeyIsPressed(keys, gamepadButtons, 3, kKeyAlt) || + KeyIsPressed(keys, gamepadButtons, 4, kKeyAlt) || + KeyIsPressed(keys, gamepadButtons, 5, kKeyAlt) || + KeyIsPressed(keys, gamepadButtons, 6, kKeyAlt) || + KeyIsPressed(keys, gamepadButtons, 7, kKeyAlt); case kISpFFDown: return - KeyIsPressed(keys, gamepadButtons, k1PKeyFFDown) || - KeyIsPressed(keys, gamepadButtons, k2PKeyFFDown) || - KeyIsPressed(keys, gamepadButtons, k3PKeyFFDown) || - KeyIsPressed(keys, gamepadButtons, k4PKeyFFDown) || - KeyIsPressed(keys, gamepadButtons, k5PKeyFFDown) || - KeyIsPressed(keys, gamepadButtons, k6PKeyFFDown) || - KeyIsPressed(keys, gamepadButtons, k7PKeyFFDown) || - KeyIsPressed(keys, gamepadButtons, k8PKeyFFDown); + KeyIsPressed(keys, gamepadButtons, 0, kKeyFFDown) || + KeyIsPressed(keys, gamepadButtons, 1, kKeyFFDown) || + KeyIsPressed(keys, gamepadButtons, 2, kKeyFFDown) || + KeyIsPressed(keys, gamepadButtons, 3, kKeyFFDown) || + KeyIsPressed(keys, gamepadButtons, 4, kKeyFFDown) || + KeyIsPressed(keys, gamepadButtons, 5, kKeyFFDown) || + KeyIsPressed(keys, gamepadButtons, 6, kKeyFFDown) || + KeyIsPressed(keys, gamepadButtons, 7, kKeyFFDown); case kISpFFUp: return - KeyIsPressed(keys, gamepadButtons, k1PKeyFFUp) || - KeyIsPressed(keys, gamepadButtons, k2PKeyFFUp) || - KeyIsPressed(keys, gamepadButtons, k3PKeyFFUp) || - KeyIsPressed(keys, gamepadButtons, k4PKeyFFUp) || - KeyIsPressed(keys, gamepadButtons, k5PKeyFFUp) || - KeyIsPressed(keys, gamepadButtons, k6PKeyFFUp) || - KeyIsPressed(keys, gamepadButtons, k7PKeyFFUp) || - KeyIsPressed(keys, gamepadButtons, k8PKeyFFUp); + KeyIsPressed(keys, gamepadButtons, 0, kKeyFFUp) || + KeyIsPressed(keys, gamepadButtons, 1, kKeyFFUp) || + KeyIsPressed(keys, gamepadButtons, 2, kKeyFFUp) || + KeyIsPressed(keys, gamepadButtons, 3, kKeyFFUp) || + KeyIsPressed(keys, gamepadButtons, 4, kKeyFFUp) || + KeyIsPressed(keys, gamepadButtons, 5, kKeyFFUp) || + KeyIsPressed(keys, gamepadButtons, 6, kKeyFFUp) || + KeyIsPressed(keys, gamepadButtons, 7, kKeyFFUp); case kISpEsc: return - KeyIsPressed(keys, gamepadButtons, k1PKeyEsc) || - KeyIsPressed(keys, gamepadButtons, k2PKeyEsc) || - KeyIsPressed(keys, gamepadButtons, k3PKeyEsc) || - KeyIsPressed(keys, gamepadButtons, k4PKeyEsc) || - KeyIsPressed(keys, gamepadButtons, k5PKeyEsc) || - KeyIsPressed(keys, gamepadButtons, k6PKeyEsc) || - KeyIsPressed(keys, gamepadButtons, k7PKeyEsc) || - KeyIsPressed(keys, gamepadButtons, k8PKeyEsc); + KeyIsPressed(keys, gamepadButtons, 0, kKeyEsc) || + KeyIsPressed(keys, gamepadButtons, 1, kKeyEsc) || + KeyIsPressed(keys, gamepadButtons, 2, kKeyEsc) || + KeyIsPressed(keys, gamepadButtons, 3, kKeyEsc) || + KeyIsPressed(keys, gamepadButtons, 4, kKeyEsc) || + KeyIsPressed(keys, gamepadButtons, 5, kKeyEsc) || + KeyIsPressed(keys, gamepadButtons, 6, kKeyEsc) || + KeyIsPressed(keys, gamepadButtons, 7, kKeyEsc); case kISpTC: return - KeyIsPressed(keys, gamepadButtons, k1PKeyTC) || - KeyIsPressed(keys, gamepadButtons, k2PKeyTC) || - KeyIsPressed(keys, gamepadButtons, k3PKeyTC) || - KeyIsPressed(keys, gamepadButtons, k4PKeyTC) || - KeyIsPressed(keys, gamepadButtons, k5PKeyTC) || - KeyIsPressed(keys, gamepadButtons, k6PKeyTC) || - KeyIsPressed(keys, gamepadButtons, k7PKeyTC) || - KeyIsPressed(keys, gamepadButtons, k8PKeyTC); + KeyIsPressed(keys, gamepadButtons, 0, kKeyTC) || + KeyIsPressed(keys, gamepadButtons, 1, kKeyTC) || + KeyIsPressed(keys, gamepadButtons, 2, kKeyTC) || + KeyIsPressed(keys, gamepadButtons, 3, kKeyTC) || + KeyIsPressed(keys, gamepadButtons, 4, kKeyTC) || + KeyIsPressed(keys, gamepadButtons, 5, kKeyTC) || + KeyIsPressed(keys, gamepadButtons, 6, kKeyTC) || + KeyIsPressed(keys, gamepadButtons, 7, kKeyTC); case kISpMouseLeft: return - KeyIsPressed(keys, gamepadButtons, k1PKeyMouseLeft) || - KeyIsPressed(keys, gamepadButtons, k2PKeyMouseLeft) || - KeyIsPressed(keys, gamepadButtons, k3PKeyMouseLeft) || - KeyIsPressed(keys, gamepadButtons, k4PKeyMouseLeft) || - KeyIsPressed(keys, gamepadButtons, k5PKeyMouseLeft) || - KeyIsPressed(keys, gamepadButtons, k6PKeyMouseLeft) || - KeyIsPressed(keys, gamepadButtons, k7PKeyMouseLeft) || - KeyIsPressed(keys, gamepadButtons, k7PKeyMouseLeft); + KeyIsPressed(keys, gamepadButtons, 0, kKeyMouseLeft) || + KeyIsPressed(keys, gamepadButtons, 1, kKeyMouseLeft) || + KeyIsPressed(keys, gamepadButtons, 2, kKeyMouseLeft) || + KeyIsPressed(keys, gamepadButtons, 3, kKeyMouseLeft) || + KeyIsPressed(keys, gamepadButtons, 4, kKeyMouseLeft) || + KeyIsPressed(keys, gamepadButtons, 5, kKeyMouseLeft) || + KeyIsPressed(keys, gamepadButtons, 6, kKeyMouseLeft) || + KeyIsPressed(keys, gamepadButtons, 7, kKeyMouseLeft); case kISpMouseRight: return - KeyIsPressed(keys, gamepadButtons, k1PKeyMouseRight) || - KeyIsPressed(keys, gamepadButtons, k2PKeyMouseRight) || - KeyIsPressed(keys, gamepadButtons, k3PKeyMouseRight) || - KeyIsPressed(keys, gamepadButtons, k4PKeyMouseRight) || - KeyIsPressed(keys, gamepadButtons, k5PKeyMouseRight) || - KeyIsPressed(keys, gamepadButtons, k6PKeyMouseRight) || - KeyIsPressed(keys, gamepadButtons, k7PKeyMouseRight) || - KeyIsPressed(keys, gamepadButtons, k7PKeyMouseRight); + KeyIsPressed(keys, gamepadButtons, 0, kKeyMouseRight) || + KeyIsPressed(keys, gamepadButtons, 1, kKeyMouseRight) || + KeyIsPressed(keys, gamepadButtons, 2, kKeyMouseRight) || + KeyIsPressed(keys, gamepadButtons, 3, kKeyMouseRight) || + KeyIsPressed(keys, gamepadButtons, 4, kKeyMouseRight) || + KeyIsPressed(keys, gamepadButtons, 5, kKeyMouseRight) || + KeyIsPressed(keys, gamepadButtons, 6, kKeyMouseRight) || + KeyIsPressed(keys, gamepadButtons, 7, kKeyMouseRight); default: break; diff --git a/macosx/mac-keyboard.h b/macosx/mac-keyboard.h index 216e010b..891b58bd 100755 --- a/macosx/mac-keyboard.h +++ b/macosx/mac-keyboard.h @@ -26,11 +26,16 @@ #define MAC_NUM_KEYCODES 255 -extern int16 keyCodes[MAC_NUM_KEYCODES]; +struct S9xButton { + int16 buttonCode; + int8 player; +}; + +extern struct S9xButton keyCodes[MAC_NUM_KEYCODES]; void InitKeyboard (void); void DeinitKeyboard (void); -void SetKeyCode(int16 keyCode, S9xKey control, int16 *oldKeyCode, S9xKey *oldControl); +bool SetKeyCode(int16 keyCode, S9xButtonCode button, int8 player, int16 *oldKeyCode, S9xButtonCode *oldButton, int8 *oldPlayer); #endif diff --git a/macosx/mac-keyboard.mm b/macosx/mac-keyboard.mm index 25dac71a..a0a61701 100755 --- a/macosx/mac-keyboard.mm +++ b/macosx/mac-keyboard.mm @@ -28,13 +28,13 @@ #include "mac-os.h" #include "mac-keyboard.h" -int16 keyCodes[MAC_NUM_KEYCODES]; +struct S9xButton keyCodes[MAC_NUM_KEYCODES]; void InitKeyboard (void) { for (int i = 0; i < MAC_NUM_KEYCODES; ++i) { - keyCodes[i] = -1; + keyCodes[i] = { -1, -1 }; } } @@ -42,17 +42,23 @@ void DeinitKeyboard (void) { for (int i = 0; i < MAC_NUM_KEYCODES; ++i) { - keyCodes[i] = -1; + keyCodes[i] = { -1, -1 }; } } -void SetKeyCode(int16 keyCode, S9xKey control, int16 *oldKeyCode, S9xKey *oldControl) +bool SetKeyCode(int16 keyCode, S9xButtonCode buttonCode, int8 player, int16 *oldKeyCode, S9xButtonCode *oldButtonCode, int8 *oldPlayer) { + if (player < 0 || player >= MAC_MAX_PLAYERS || buttonCode < 0 || buttonCode >= kNumButtons) + { + return false; + } + for ( int i = 0; i < MAC_NUM_KEYCODES; ++i) { - if (keyCodes[i] == control && i != keyCode) + struct S9xButton button = keyCodes[i]; + if (button.player == player && button.buttonCode == buttonCode && i != keyCode) { - keyCodes[i] = -1; + keyCodes[i] = { -1, -1 }; if (oldKeyCode !=NULL) { @@ -61,10 +67,17 @@ void SetKeyCode(int16 keyCode, S9xKey control, int16 *oldKeyCode, S9xKey *oldCon } } - if (oldControl != NULL) + if (oldButtonCode != NULL) { - *oldControl = (S9xKey)keyCodes[keyCode]; + *oldButtonCode = (S9xButtonCode)keyCodes[keyCode].buttonCode; } - keyCodes[keyCode] = control; + if (*oldPlayer != NULL ) + { + *oldPlayer = (S9xButtonCode)keyCodes[keyCode].player; + } + + keyCodes[keyCode] = { static_cast(buttonCode), player }; + + return true; } diff --git a/macosx/mac-musicbox.h b/macosx/mac-musicbox.h index 5effce26..17866a9c 100755 --- a/macosx/mac-musicbox.h +++ b/macosx/mac-musicbox.h @@ -27,7 +27,7 @@ @interface MusicBoxController : NSObject { - IBOutlet id window; + IBOutlet NSWindow *window; IBOutlet id gametitle; IBOutlet id disclosure; IBOutlet id rewind; diff --git a/macosx/mac-os.h b/macosx/mac-os.h index a75a91d0..b6afcc6a 100644 --- a/macosx/mac-os.h +++ b/macosx/mac-os.h @@ -112,7 +112,6 @@ typedef struct } ExtraOption; #define kMacWindowHeight (SNES_HEIGHT_EXTENDED) -#define MAC_MAX_PLAYERS 8 #define MAC_MAX_CHEATS 150 extern volatile bool8 running, s9xthreadrunning; @@ -164,8 +163,8 @@ extern CFStringRef multiCartPath[2]; extern IconRef macIconRef[118]; #endif -extern bool8 pressedKeys[kNumButtons]; -extern bool8 pressedGamepadButtons[kNumButtons]; +extern bool8 pressedKeys[MAC_MAX_PLAYERS][kNumButtons]; +extern bool8 pressedGamepadButtons[MAC_MAX_PLAYERS][kNumButtons]; extern os_unfair_lock keyLock; extern NSOpenGLView *s9xView; @@ -180,7 +179,7 @@ void PostQueueToSubEventLoop (void); int PromptFreezeDefrost (Boolean); uint64 GetMicroseconds(void); -void CopyPressedKeys(uint8 keys[kNumButtons], uint8 gamepadButtons[kNumButtons]); +void CopyPressedKeys(uint8 keys[MAC_MAX_PLAYERS][kNumButtons], uint8 gamepadButtons[MAC_MAX_PLAYERS][kNumButtons]); @interface S9xEngine : NSObject @@ -191,7 +190,7 @@ void CopyPressedKeys(uint8 keys[kNumButtons], uint8 gamepadButtons[kNumButtons]) - (void)pause; - (void)resume; -- (void)setControl:(S9xKey)control forKey:(int16)key oldControl:(S9xKey *)oldControl oldKey:(int16 *)oldControl; +- (BOOL)setButton:(S9xButtonCode)button forKey:(int16)key player:(int8)player oldButton:(S9xButtonCode *)oldButton oldPlayer:(int8 *)oldPlayer oldKey:(int16 *)oldKey; - (BOOL)loadROM:(NSURL *)fileURL; diff --git a/macosx/mac-os.mm b/macosx/mac-os.mm index da9638ba..622d1997 100644 --- a/macosx/mac-os.mm +++ b/macosx/mac-os.mm @@ -174,8 +174,8 @@ CFStringRef multiCartPath[2]; IconRef macIconRef[118]; #endif -bool8 pressedKeys[kNumButtons] = { 0 }; -bool8 pressedGamepadButtons[kNumButtons] = { 0 }; +bool8 pressedKeys[MAC_MAX_PLAYERS][kNumButtons] = { 0 }; +bool8 pressedGamepadButtons[MAC_MAX_PLAYERS][kNumButtons] = { 0 }; os_unfair_lock keyLock; os_unfair_lock renderLock; @@ -357,51 +357,51 @@ static void * MacSnes9xThread (void *) return (NULL); } -void CopyPressedKeys(bool8 keys[MAC_NUM_KEYCODES], bool8 gamepadButtons[kNumButtons]) +void CopyPressedKeys(bool8 keys[MAC_MAX_PLAYERS][kNumButtons], bool8 gamepadButtons[MAC_MAX_PLAYERS][kNumButtons]) { os_unfair_lock_lock(&keyLock); NSEventModifierFlags flags = [NSEvent modifierFlags]; - int16 key = keyCodes[kVK_Shift]; - if ( key >= 0 && key < MAC_NUM_KEYCODES) + struct S9xButton button = keyCodes[kVK_Shift]; + if (button.buttonCode >= 0 && button.buttonCode < kNumButtons && button.player >= 0 && button.player < MAC_MAX_PLAYERS) { - pressedKeys[key] = (flags & NSEventModifierFlagShift) != 0; + pressedKeys[button.player][button.buttonCode] = (flags & NSEventModifierFlagShift) != 0; } - key = keyCodes[kVK_Command]; - if ( key >= 0 && key < MAC_NUM_KEYCODES) + button = keyCodes[kVK_Command]; + if (button.buttonCode >= 0 && button.buttonCode < kNumButtons && button.player >= 0 && button.player < MAC_MAX_PLAYERS) { - pressedKeys[key] = (flags & NSEventModifierFlagCommand) != 0; + pressedKeys[button.player][button.buttonCode] = (flags & NSEventModifierFlagCommand) != 0; } - key = keyCodes[kVK_Control]; - if ( key >= 0 && key < MAC_NUM_KEYCODES) + button = keyCodes[kVK_Control]; + if (button.buttonCode >= 0 && button.buttonCode < kNumButtons && button.player >= 0 && button.player < MAC_MAX_PLAYERS) { - pressedKeys[key] = (flags & NSEventModifierFlagControl) != 0; + pressedKeys[button.player][button.buttonCode] = (flags & NSEventModifierFlagControl) != 0; } - key = keyCodes[kVK_CapsLock]; - if ( key >= 0 && key < MAC_NUM_KEYCODES) + button = keyCodes[kVK_CapsLock]; + if (button.buttonCode >= 0 && button.buttonCode < kNumButtons && button.player >= 0 && button.player < MAC_MAX_PLAYERS) { - pressedKeys[key] = (flags & NSEventModifierFlagCapsLock) != 0; + pressedKeys[button.player][button.buttonCode] = (flags & NSEventModifierFlagCapsLock) != 0; } - key = keyCodes[kVK_Option]; - if ( key >= 0 && key < MAC_NUM_KEYCODES) + button = keyCodes[kVK_Option]; + if (button.buttonCode >= 0 && button.buttonCode < kNumButtons && button.player >= 0 && button.player < MAC_MAX_PLAYERS) { - pressedKeys[key] = (flags & NSEventModifierFlagOption) != 0; + pressedKeys[button.player][button.buttonCode] = (flags & NSEventModifierFlagOption) != 0; } - key = keyCodes[kVK_Help]; - if ( key >= 0 && key < MAC_NUM_KEYCODES) + button = keyCodes[kVK_Help]; + if (button.buttonCode >= 0 && button.buttonCode < kNumButtons && button.player >= 0 && button.player < MAC_MAX_PLAYERS) { - pressedKeys[key] = (flags & NSEventModifierFlagHelp) != 0; + pressedKeys[button.player][button.buttonCode] = (flags & NSEventModifierFlagHelp) != 0; } - key = keyCodes[kVK_Function]; - if ( key >= 0 && key < MAC_NUM_KEYCODES) + button = keyCodes[kVK_Function]; + if (button.buttonCode >= 0 && button.buttonCode < kNumButtons && button.player >= 0 && button.player < MAC_MAX_PLAYERS) { - pressedKeys[key] = (flags & NSEventModifierFlagFunction) != 0; + pressedKeys[button.player][button.buttonCode] = (flags & NSEventModifierFlagFunction) != 0; } memcpy(keys, pressedKeys, sizeof(pressedKeys)); @@ -1760,8 +1760,8 @@ int PromptFreezeDefrost (Boolean freezing) CGRect rct; CFURLRef url; FSCatalogInfo info; - bool8 keys[kNumButtons]; - bool8 gamepadButtons[kNumButtons]; + bool8 keys[MAC_MAX_PLAYERS][kNumButtons]; + bool8 gamepadButtons[MAC_MAX_PLAYERS][kNumButtons]; CFAbsoluteTime newestDate, currentDate; int64 startTime; float x, y; @@ -1963,69 +1963,69 @@ int PromptFreezeDefrost (Boolean freezing) for (int count = 0; count <= 12; count++) { - while (KeyIsPressed(keys, gamepadButtons, count)) + while (KeyIsPressed(keys, gamepadButtons, 0, count)) { result = count - 1; CopyPressedKeys(keys, gamepadButtons); } } - while (KeyIsPressed(keys, gamepadButtons, k1PRight)) + while (KeyIsPressed(keys, gamepadButtons, 0, kRight)) { startTime = mach_absolute_time(); current_selection += 1; if (current_selection > 11) current_selection -= 12; UpdateFreezeDefrostScreen(current_selection, image, draw, ctx); - while (KeyIsPressed(keys, gamepadButtons, k1PRight) && (mach_absolute_time() < (startTime + repeatDelay))) + while (KeyIsPressed(keys, gamepadButtons, 0, kRight) && (mach_absolute_time() < (startTime + repeatDelay))) CopyPressedKeys(keys, gamepadButtons); } - while (KeyIsPressed(keys, gamepadButtons, k1PLeft)) + while (KeyIsPressed(keys, gamepadButtons, 0, kLeft)) { startTime = mach_absolute_time(); current_selection -= 1; if (current_selection < 0) current_selection += 12; UpdateFreezeDefrostScreen(current_selection, image, draw, ctx); - while (KeyIsPressed(keys, gamepadButtons, k1PLeft) && (mach_absolute_time() < (startTime + repeatDelay))) + while (KeyIsPressed(keys, gamepadButtons, 0, kLeft) && (mach_absolute_time() < (startTime + repeatDelay))) CopyPressedKeys(keys, gamepadButtons); } - while (KeyIsPressed(keys, gamepadButtons, k1PDown)) + while (KeyIsPressed(keys, gamepadButtons, 0, kDown)) { startTime = mach_absolute_time(); current_selection += 4; if (current_selection > 11) current_selection -= 12; UpdateFreezeDefrostScreen(current_selection, image, draw, ctx); - while (KeyIsPressed(keys, gamepadButtons, k1PDown) && (mach_absolute_time() < (startTime + repeatDelay))) + while (KeyIsPressed(keys, gamepadButtons, 0, kDown) && (mach_absolute_time() < (startTime + repeatDelay))) CopyPressedKeys(keys, gamepadButtons); } - while (KeyIsPressed(keys, gamepadButtons, k1PUp)) + while (KeyIsPressed(keys, gamepadButtons, 0, kUp)) { startTime = mach_absolute_time(); current_selection -= 4; if (current_selection < 0) current_selection += 12; UpdateFreezeDefrostScreen(current_selection, image, draw, ctx); - while (KeyIsPressed(keys, gamepadButtons, k1PUp) && (mach_absolute_time() < (startTime + repeatDelay))) + while (KeyIsPressed(keys, gamepadButtons, 0, kUp) && (mach_absolute_time() < (startTime + repeatDelay))) CopyPressedKeys(keys, gamepadButtons); } - while (KeyIsPressed(keys, gamepadButtons, k1PA ) || - KeyIsPressed(keys, gamepadButtons, k2PA ) || - KeyIsPressed(keys, gamepadButtons, k1PB ) || - KeyIsPressed(keys, gamepadButtons, k2PB ) || - KeyIsPressed(keys, gamepadButtons, k1PX ) || - KeyIsPressed(keys, gamepadButtons, k2PX ) || - KeyIsPressed(keys, gamepadButtons, k1PY ) || - KeyIsPressed(keys, gamepadButtons, k2PY ) || - KeyIsPressed(keys, gamepadButtons, k1PStart ) || - KeyIsPressed(keys, gamepadButtons, k2PStart ) || - KeyIsPressed(keys, gamepadButtons, k1PSelect) || - KeyIsPressed(keys, gamepadButtons, k2PSelect)) + while (KeyIsPressed(keys, gamepadButtons, 1, kA ) || + KeyIsPressed(keys, gamepadButtons, 2, kA ) || + KeyIsPressed(keys, gamepadButtons, 1, kB ) || + KeyIsPressed(keys, gamepadButtons, 2, kB ) || + KeyIsPressed(keys, gamepadButtons, 1, kX ) || + KeyIsPressed(keys, gamepadButtons, 2, kX ) || + KeyIsPressed(keys, gamepadButtons, 1, kY ) || + KeyIsPressed(keys, gamepadButtons, 2, kY ) || + KeyIsPressed(keys, gamepadButtons, 1, kStart ) || + KeyIsPressed(keys, gamepadButtons, 2, kStart ) || + KeyIsPressed(keys, gamepadButtons, 1, kSelect) || + KeyIsPressed(keys, gamepadButtons, 2, kSelect)) { CopyPressedKeys(keys, gamepadButtons); result = current_selection; @@ -2034,8 +2034,8 @@ int PromptFreezeDefrost (Boolean freezing) uint32 pad1, pad2; while (ISpKeyIsPressed(keys, gamepadButtons, kISpEsc) || - KeyIsPressed(keys, gamepadButtons, k1PStart) || - KeyIsPressed(keys, gamepadButtons, k2PStart)) + KeyIsPressed(keys, gamepadButtons, 0, kStart) || + KeyIsPressed(keys, gamepadButtons, 1, kStart)) { CopyPressedKeys(keys, gamepadButtons); result = -1; @@ -2113,14 +2113,14 @@ int PromptFreezeDefrost (Boolean freezing) } while (((pad1 & 0x0400) || (pad2 & 0x0400)) && (mach_absolute_time() < (startTime + repeatDelay))); } - while (KeyIsPressed(keys, gamepadButtons, k1PA) || - KeyIsPressed(keys, gamepadButtons, k2PA) || - KeyIsPressed(keys, gamepadButtons, k1PB) || - KeyIsPressed(keys, gamepadButtons, k2PB) || - KeyIsPressed(keys, gamepadButtons, k1PX) || - KeyIsPressed(keys, gamepadButtons, k2PX) || - KeyIsPressed(keys, gamepadButtons, k1PY) || - KeyIsPressed(keys, gamepadButtons, k2PY)) + while (KeyIsPressed(keys, gamepadButtons, 0, kA) || + KeyIsPressed(keys, gamepadButtons, 1, kA) || + KeyIsPressed(keys, gamepadButtons, 0, kB) || + KeyIsPressed(keys, gamepadButtons, 1, kB) || + KeyIsPressed(keys, gamepadButtons, 0, kX) || + KeyIsPressed(keys, gamepadButtons, 1, kX) || + KeyIsPressed(keys, gamepadButtons, 0, kY) || + KeyIsPressed(keys, gamepadButtons, 1, kY)) result = current_selection; } @@ -2177,8 +2177,8 @@ static void UpdateFreezeDefrostScreen (int newIndex, CGImageRef image, uint8 *dr static void ProcessInput (void) { - bool8 keys[MAC_NUM_KEYCODES]; - bool8 gamepadButtons[kNumButtons]; + bool8 keys[MAC_MAX_PLAYERS][kNumButtons]; + bool8 gamepadButtons[MAC_MAX_PLAYERS][kNumButtons]; bool8 isok, fnbtn, altbtn, tcbtn; static bool8 toggleff = false, lastTimeTT = false, lastTimeFn = false, ffUp = false, ffDown = false, ffUpSp = false, ffDownSp = false; @@ -2254,106 +2254,6 @@ static void ProcessInput (void) else ffDownSp = false; - controlPad[0] = controlPad[1] = 0; - - JoypadScanDirection(0, &(controlPad[0])); - if (KeyIsPressed(keys, gamepadButtons, k1PR )) controlPad[0] |= 0x0010; - if (KeyIsPressed(keys, gamepadButtons, k1PL )) controlPad[0] |= 0x0020; - if (KeyIsPressed(keys, gamepadButtons, k1PX )) controlPad[0] |= 0x0040; - if (KeyIsPressed(keys, gamepadButtons, k1PA )) controlPad[0] |= 0x0080; - if (KeyIsPressed(keys, gamepadButtons, k1PStart )) controlPad[0] |= 0x1000; - if (KeyIsPressed(keys, gamepadButtons, k1PSelect)) controlPad[0] |= 0x2000; - if (KeyIsPressed(keys, gamepadButtons, k1PY )) controlPad[0] |= 0x4000; - if (KeyIsPressed(keys, gamepadButtons, k1PB )) controlPad[0] |= 0x8000; - - JoypadScanDirection(1, &(controlPad[1])); - if (KeyIsPressed(keys, gamepadButtons, k2PR )) controlPad[1] |= 0x0010; - if (KeyIsPressed(keys, gamepadButtons, k2PL )) controlPad[1] |= 0x0020; - if (KeyIsPressed(keys, gamepadButtons, k2PX )) controlPad[1] |= 0x0040; - if (KeyIsPressed(keys, gamepadButtons, k2PA )) controlPad[1] |= 0x0080; - if (KeyIsPressed(keys, gamepadButtons, k2PStart )) controlPad[1] |= 0x1000; - if (KeyIsPressed(keys, gamepadButtons, k2PSelect)) controlPad[1] |= 0x2000; - if (KeyIsPressed(keys, gamepadButtons, k2PY )) controlPad[1] |= 0x4000; - if (KeyIsPressed(keys, gamepadButtons, k2PB )) controlPad[1] |= 0x8000; - - if (((macControllerOption == SNES_MULTIPLAYER5) || (macControllerOption == SNES_MULTIPLAYER5_2)) && Settings.MultiPlayer5Master) - { - controlPad[2] = controlPad[3] = controlPad[4] = 0; - - JoypadScanDirection(2, &(controlPad[2])); - if (KeyIsPressed(keys, gamepadButtons, k3PR )) controlPad[2] |= 0x0010; - if (KeyIsPressed(keys, gamepadButtons, k3PL )) controlPad[2] |= 0x0020; - if (KeyIsPressed(keys, gamepadButtons, k3PX )) controlPad[2] |= 0x0040; - if (KeyIsPressed(keys, gamepadButtons, k3PA )) controlPad[2] |= 0x0080; - if (KeyIsPressed(keys, gamepadButtons, k3PStart )) controlPad[2] |= 0x1000; - if (KeyIsPressed(keys, gamepadButtons, k3PSelect)) controlPad[2] |= 0x2000; - if (KeyIsPressed(keys, gamepadButtons, k3PY )) controlPad[2] |= 0x4000; - if (KeyIsPressed(keys, gamepadButtons, k3PB )) controlPad[2] |= 0x8000; - - JoypadScanDirection(3, &(controlPad[3])); - if (KeyIsPressed(keys, gamepadButtons, k4PR )) controlPad[3] |= 0x0010; - if (KeyIsPressed(keys, gamepadButtons, k4PL )) controlPad[3] |= 0x0020; - if (KeyIsPressed(keys, gamepadButtons, k4PX )) controlPad[3] |= 0x0040; - if (KeyIsPressed(keys, gamepadButtons, k4PA )) controlPad[3] |= 0x0080; - if (KeyIsPressed(keys, gamepadButtons, k4PStart )) controlPad[3] |= 0x1000; - if (KeyIsPressed(keys, gamepadButtons, k4PSelect)) controlPad[3] |= 0x2000; - if (KeyIsPressed(keys, gamepadButtons, k4PY )) controlPad[3] |= 0x4000; - if (KeyIsPressed(keys, gamepadButtons, k4PB )) controlPad[3] |= 0x8000; - - JoypadScanDirection(4, &(controlPad[4])); - if (KeyIsPressed(keys, gamepadButtons, k5PR )) controlPad[4] |= 0x0010; - if (KeyIsPressed(keys, gamepadButtons, k5PL )) controlPad[4] |= 0x0020; - if (KeyIsPressed(keys, gamepadButtons, k5PX )) controlPad[4] |= 0x0040; - if (KeyIsPressed(keys, gamepadButtons, k5PA )) controlPad[4] |= 0x0080; - if (KeyIsPressed(keys, gamepadButtons, k5PStart )) controlPad[4] |= 0x1000; - if (KeyIsPressed(keys, gamepadButtons, k5PSelect)) controlPad[4] |= 0x2000; - if (KeyIsPressed(keys, gamepadButtons, k5PY )) controlPad[4] |= 0x4000; - if (KeyIsPressed(keys, gamepadButtons, k5PB )) controlPad[4] |= 0x8000; - - ControlPadFlagsToS9xReportButtons(2, controlPad[2]); - ControlPadFlagsToS9xReportButtons(3, controlPad[3]); - ControlPadFlagsToS9xReportButtons(4, controlPad[4]); - - if (macControllerOption == SNES_MULTIPLAYER5_2) - { - controlPad[5] = controlPad[6] = controlPad[7] = 0; - - JoypadScanDirection(5, &(controlPad[5])); - if (KeyIsPressed(keys, gamepadButtons, k6PR )) controlPad[5] |= 0x0010; - if (KeyIsPressed(keys, gamepadButtons, k6PL )) controlPad[5] |= 0x0020; - if (KeyIsPressed(keys, gamepadButtons, k6PX )) controlPad[5] |= 0x0040; - if (KeyIsPressed(keys, gamepadButtons, k6PA )) controlPad[5] |= 0x0080; - if (KeyIsPressed(keys, gamepadButtons, k6PStart )) controlPad[5] |= 0x1000; - if (KeyIsPressed(keys, gamepadButtons, k6PSelect)) controlPad[5] |= 0x2000; - if (KeyIsPressed(keys, gamepadButtons, k6PY )) controlPad[5] |= 0x4000; - if (KeyIsPressed(keys, gamepadButtons, k6PB )) controlPad[5] |= 0x8000; - - JoypadScanDirection(6, &(controlPad[6])); - if (KeyIsPressed(keys, gamepadButtons, k7PR )) controlPad[6] |= 0x0010; - if (KeyIsPressed(keys, gamepadButtons, k7PL )) controlPad[6] |= 0x0020; - if (KeyIsPressed(keys, gamepadButtons, k7PX )) controlPad[6] |= 0x0040; - if (KeyIsPressed(keys, gamepadButtons, k7PA )) controlPad[6] |= 0x0080; - if (KeyIsPressed(keys, gamepadButtons, k7PStart )) controlPad[6] |= 0x1000; - if (KeyIsPressed(keys, gamepadButtons, k7PSelect)) controlPad[6] |= 0x2000; - if (KeyIsPressed(keys, gamepadButtons, k7PY )) controlPad[6] |= 0x4000; - if (KeyIsPressed(keys, gamepadButtons, k7PB )) controlPad[6] |= 0x8000; - - JoypadScanDirection(7, &(controlPad[7])); - if (KeyIsPressed(keys, gamepadButtons, k8PR )) controlPad[7] |= 0x0010; - if (KeyIsPressed(keys, gamepadButtons, k8PL )) controlPad[7] |= 0x0020; - if (KeyIsPressed(keys, gamepadButtons, k8PX )) controlPad[7] |= 0x0040; - if (KeyIsPressed(keys, gamepadButtons, k8PA )) controlPad[7] |= 0x0080; - if (KeyIsPressed(keys, gamepadButtons, k8PStart )) controlPad[7] |= 0x1000; - if (KeyIsPressed(keys, gamepadButtons, k8PSelect)) controlPad[7] |= 0x2000; - if (KeyIsPressed(keys, gamepadButtons, k8PY )) controlPad[7] |= 0x4000; - if (KeyIsPressed(keys, gamepadButtons, k8PB )) controlPad[7] |= 0x8000; - - ControlPadFlagsToS9xReportButtons(5, controlPad[5]); - ControlPadFlagsToS9xReportButtons(6, controlPad[6]); - ControlPadFlagsToS9xReportButtons(7, controlPad[7]); - } - } - fnbtn = ISpKeyIsPressed(keys, gamepadButtons, kISpFunction); altbtn = ISpKeyIsPressed(keys, gamepadButtons, kISpAlt); @@ -2499,109 +2399,22 @@ static void ProcessInput (void) else ffDown = false; - if (KeyIsPressed(keys, gamepadButtons, k1PR )) controlPad[0] |= 0x0010; - if (KeyIsPressed(keys, gamepadButtons, k1PL )) controlPad[0] |= 0x0020; - if (KeyIsPressed(keys, gamepadButtons, k1PX )) controlPad[0] |= 0x0040; - if (KeyIsPressed(keys, gamepadButtons, k1PA )) controlPad[0] |= 0x0080; - if (KeyIsPressed(keys, gamepadButtons, k1PRight )) controlPad[0] |= 0x0100; - if (KeyIsPressed(keys, gamepadButtons, k1PLeft )) controlPad[0] |= 0x0200; - if (KeyIsPressed(keys, gamepadButtons, k1PDown )) controlPad[0] |= 0x0400; - if (KeyIsPressed(keys, gamepadButtons, k1PUp )) controlPad[0] |= 0x0800; - if (KeyIsPressed(keys, gamepadButtons, k1PStart )) controlPad[0] |= 0x1000; - if (KeyIsPressed(keys, gamepadButtons, k1PSelect)) controlPad[0] |= 0x2000; - if (KeyIsPressed(keys, gamepadButtons, k1PY )) controlPad[0] |= 0x4000; - if (KeyIsPressed(keys, gamepadButtons, k1PB )) controlPad[0] |= 0x8000; - - if (KeyIsPressed(keys, gamepadButtons, k2PR )) controlPad[1] |= 0x0010; - if (KeyIsPressed(keys, gamepadButtons, k2PL )) controlPad[1] |= 0x0020; - if (KeyIsPressed(keys, gamepadButtons, k2PX )) controlPad[1] |= 0x0040; - if (KeyIsPressed(keys, gamepadButtons, k2PA )) controlPad[1] |= 0x0080; - if (KeyIsPressed(keys, gamepadButtons, k2PRight )) controlPad[1] |= 0x0100; - if (KeyIsPressed(keys, gamepadButtons, k2PLeft )) controlPad[1] |= 0x0200; - if (KeyIsPressed(keys, gamepadButtons, k2PDown )) controlPad[1] |= 0x0400; - if (KeyIsPressed(keys, gamepadButtons, k2PUp )) controlPad[1] |= 0x0800; - if (KeyIsPressed(keys, gamepadButtons, k2PStart )) controlPad[1] |= 0x1000; - if (KeyIsPressed(keys, gamepadButtons, k2PSelect)) controlPad[1] |= 0x2000; - if (KeyIsPressed(keys, gamepadButtons, k2PY )) controlPad[1] |= 0x4000; - if (KeyIsPressed(keys, gamepadButtons, k2PB )) controlPad[1] |= 0x8000; - - if (KeyIsPressed(keys, gamepadButtons, k3PR )) controlPad[2] |= 0x0010; - if (KeyIsPressed(keys, gamepadButtons, k3PL )) controlPad[2] |= 0x0020; - if (KeyIsPressed(keys, gamepadButtons, k3PX )) controlPad[2] |= 0x0040; - if (KeyIsPressed(keys, gamepadButtons, k3PA )) controlPad[2] |= 0x0080; - if (KeyIsPressed(keys, gamepadButtons, k3PRight )) controlPad[2] |= 0x0100; - if (KeyIsPressed(keys, gamepadButtons, k3PLeft )) controlPad[2] |= 0x0200; - if (KeyIsPressed(keys, gamepadButtons, k3PDown )) controlPad[2] |= 0x0400; - if (KeyIsPressed(keys, gamepadButtons, k3PUp )) controlPad[2] |= 0x0800; - if (KeyIsPressed(keys, gamepadButtons, k3PStart )) controlPad[2] |= 0x1000; - if (KeyIsPressed(keys, gamepadButtons, k3PSelect)) controlPad[2] |= 0x2000; - if (KeyIsPressed(keys, gamepadButtons, k3PY )) controlPad[2] |= 0x4000; - if (KeyIsPressed(keys, gamepadButtons, k3PB )) controlPad[2] |= 0x8000; - - if (KeyIsPressed(keys, gamepadButtons, k4PR )) controlPad[3] |= 0x0010; - if (KeyIsPressed(keys, gamepadButtons, k4PL )) controlPad[3] |= 0x0020; - if (KeyIsPressed(keys, gamepadButtons, k4PX )) controlPad[3] |= 0x0040; - if (KeyIsPressed(keys, gamepadButtons, k4PA )) controlPad[3] |= 0x0080; - if (KeyIsPressed(keys, gamepadButtons, k4PRight )) controlPad[3] |= 0x0100; - if (KeyIsPressed(keys, gamepadButtons, k4PLeft )) controlPad[3] |= 0x0200; - if (KeyIsPressed(keys, gamepadButtons, k4PDown )) controlPad[3] |= 0x0400; - if (KeyIsPressed(keys, gamepadButtons, k4PUp )) controlPad[3] |= 0x0800; - if (KeyIsPressed(keys, gamepadButtons, k4PStart )) controlPad[3] |= 0x1000; - if (KeyIsPressed(keys, gamepadButtons, k4PSelect)) controlPad[3] |= 0x2000; - if (KeyIsPressed(keys, gamepadButtons, k4PY )) controlPad[3] |= 0x4000; - if (KeyIsPressed(keys, gamepadButtons, k4PB )) controlPad[3] |= 0x8000; - - if (KeyIsPressed(keys, gamepadButtons, k5PR )) controlPad[4] |= 0x0010; - if (KeyIsPressed(keys, gamepadButtons, k5PL )) controlPad[4] |= 0x0020; - if (KeyIsPressed(keys, gamepadButtons, k5PX )) controlPad[4] |= 0x0040; - if (KeyIsPressed(keys, gamepadButtons, k5PA )) controlPad[4] |= 0x0080; - if (KeyIsPressed(keys, gamepadButtons, k5PRight )) controlPad[4] |= 0x0100; - if (KeyIsPressed(keys, gamepadButtons, k5PLeft )) controlPad[4] |= 0x0200; - if (KeyIsPressed(keys, gamepadButtons, k5PDown )) controlPad[4] |= 0x0400; - if (KeyIsPressed(keys, gamepadButtons, k5PUp )) controlPad[4] |= 0x0800; - if (KeyIsPressed(keys, gamepadButtons, k5PStart )) controlPad[4] |= 0x1000; - if (KeyIsPressed(keys, gamepadButtons, k5PSelect)) controlPad[4] |= 0x2000; - if (KeyIsPressed(keys, gamepadButtons, k5PY )) controlPad[4] |= 0x4000; - if (KeyIsPressed(keys, gamepadButtons, k5PB )) controlPad[4] |= 0x8000; - - if (KeyIsPressed(keys, gamepadButtons, k6PR )) controlPad[5] |= 0x0010; - if (KeyIsPressed(keys, gamepadButtons, k6PL )) controlPad[5] |= 0x0020; - if (KeyIsPressed(keys, gamepadButtons, k6PX )) controlPad[5] |= 0x0040; - if (KeyIsPressed(keys, gamepadButtons, k6PA )) controlPad[5] |= 0x0080; - if (KeyIsPressed(keys, gamepadButtons, k6PRight )) controlPad[5] |= 0x0100; - if (KeyIsPressed(keys, gamepadButtons, k6PLeft )) controlPad[5] |= 0x0200; - if (KeyIsPressed(keys, gamepadButtons, k6PDown )) controlPad[5] |= 0x0400; - if (KeyIsPressed(keys, gamepadButtons, k6PUp )) controlPad[5] |= 0x0800; - if (KeyIsPressed(keys, gamepadButtons, k6PStart )) controlPad[5] |= 0x1000; - if (KeyIsPressed(keys, gamepadButtons, k6PSelect)) controlPad[5] |= 0x2000; - if (KeyIsPressed(keys, gamepadButtons, k6PY )) controlPad[5] |= 0x4000; - if (KeyIsPressed(keys, gamepadButtons, k6PB )) controlPad[5] |= 0x8000; - - if (KeyIsPressed(keys, gamepadButtons, k7PR )) controlPad[6] |= 0x0010; - if (KeyIsPressed(keys, gamepadButtons, k7PL )) controlPad[6] |= 0x0020; - if (KeyIsPressed(keys, gamepadButtons, k7PX )) controlPad[6] |= 0x0040; - if (KeyIsPressed(keys, gamepadButtons, k7PA )) controlPad[6] |= 0x0080; - if (KeyIsPressed(keys, gamepadButtons, k7PRight )) controlPad[6] |= 0x0100; - if (KeyIsPressed(keys, gamepadButtons, k7PLeft )) controlPad[6] |= 0x0200; - if (KeyIsPressed(keys, gamepadButtons, k7PDown )) controlPad[6] |= 0x0400; - if (KeyIsPressed(keys, gamepadButtons, k7PUp )) controlPad[6] |= 0x0800; - if (KeyIsPressed(keys, gamepadButtons, k7PStart )) controlPad[6] |= 0x1000; - if (KeyIsPressed(keys, gamepadButtons, k7PSelect)) controlPad[6] |= 0x2000; - if (KeyIsPressed(keys, gamepadButtons, k7PY )) controlPad[6] |= 0x4000; - if (KeyIsPressed(keys, gamepadButtons, k7PB )) controlPad[6] |= 0x8000; - - if (KeyIsPressed(keys, gamepadButtons, k8PR )) controlPad[7] |= 0x0010; - if (KeyIsPressed(keys, gamepadButtons, k8PL )) controlPad[7] |= 0x0020; - if (KeyIsPressed(keys, gamepadButtons, k8PX )) controlPad[7] |= 0x0040; - if (KeyIsPressed(keys, gamepadButtons, k8PA )) controlPad[7] |= 0x0080; - if (KeyIsPressed(keys, gamepadButtons, k8PRight )) controlPad[7] |= 0x0100; - if (KeyIsPressed(keys, gamepadButtons, k8PLeft )) controlPad[7] |= 0x0200; - if (KeyIsPressed(keys, gamepadButtons, k8PDown )) controlPad[7] |= 0x0400; - if (KeyIsPressed(keys, gamepadButtons, k8PUp )) controlPad[7] |= 0x0800; - if (KeyIsPressed(keys, gamepadButtons, k8PStart )) controlPad[7] |= 0x1000; - if (KeyIsPressed(keys, gamepadButtons, k8PSelect)) controlPad[7] |= 0x2000; - if (KeyIsPressed(keys, gamepadButtons, k8PY )) controlPad[7] |= 0x4000; - if (KeyIsPressed(keys, gamepadButtons, k8PB )) controlPad[7] |= 0x8000; + for (int i = 0; i < MAC_MAX_PLAYERS; ++i) + { + controlPad[i] = 0; + if (KeyIsPressed(keys, gamepadButtons, i, kR )) controlPad[i] |= 0x0010; + if (KeyIsPressed(keys, gamepadButtons, i, kL )) controlPad[i] |= 0x0020; + if (KeyIsPressed(keys, gamepadButtons, i, kX )) controlPad[i] |= 0x0040; + if (KeyIsPressed(keys, gamepadButtons, i, kA )) controlPad[i] |= 0x0080; + if (KeyIsPressed(keys, gamepadButtons, i, kRight )) controlPad[i] |= 0x0100; + if (KeyIsPressed(keys, gamepadButtons, i, kLeft )) controlPad[i] |= 0x0200; + if (KeyIsPressed(keys, gamepadButtons, i, kDown )) controlPad[i] |= 0x0400; + if (KeyIsPressed(keys, gamepadButtons, i, kUp )) controlPad[i] |= 0x0800; + if (KeyIsPressed(keys, gamepadButtons, i, kStart )) controlPad[i] |= 0x1000; + if (KeyIsPressed(keys, gamepadButtons, i, kSelect)) controlPad[i] |= 0x2000; + if (KeyIsPressed(keys, gamepadButtons, i, kY )) controlPad[i] |= 0x4000; + if (KeyIsPressed(keys, gamepadButtons, i, kB )) controlPad[i] |= 0x8000; + } if (altbtn) { @@ -3127,10 +2940,10 @@ void QuitWithFatalError ( NSString *message) - (void)keyDown:(NSEvent *)event { os_unfair_lock_lock(&keyLock); - int16 key = keyCodes[event.keyCode]; - if ( key >= 0 && key < MAC_NUM_KEYCODES ) + S9xButton button = keyCodes[event.keyCode]; + if ( button.buttonCode >= 0 && button.buttonCode < kNumButtons && button.player <= 0 && button.player <= MAC_MAX_PLAYERS) { - pressedKeys[key] = true; + pressedKeys[button.player][button.buttonCode] = true; } os_unfair_lock_unlock(&keyLock); } @@ -3138,10 +2951,10 @@ void QuitWithFatalError ( NSString *message) - (void)keyUp:(NSEvent *)event { os_unfair_lock_lock(&keyLock); - int16 key = keyCodes[event.keyCode]; - if ( key >= 0 && key < MAC_NUM_KEYCODES) + S9xButton button = keyCodes[event.keyCode]; + if ( button.buttonCode >= 0 && button.buttonCode < kNumButtons && button.player <= 0 && button.player <= MAC_MAX_PLAYERS) { - pressedKeys[key] = false; + pressedKeys[button.player][button.buttonCode] = false; } os_unfair_lock_unlock(&keyLock); } @@ -3174,6 +2987,11 @@ void QuitWithFatalError ( NSString *message) return YES; } +- (BOOL)validateMenuItem:(NSMenuItem *)menuItem +{ + return !( running && !pauseEmulation); +} + @end @implementation S9xEngine @@ -3265,7 +3083,7 @@ void QuitWithFatalError ( NSString *message) - (BOOL)isPaused { - return pauseEmulation; + return running && pauseEmulation; } - (void)pause @@ -3278,11 +3096,13 @@ void QuitWithFatalError ( NSString *message) pauseEmulation = false; } -- (void)setControl:(S9xKey)control forKey:(int16)key oldControl:(S9xKey *)oldControl oldKey:(int16 *)oldKey +- (BOOL)setButton:(S9xButtonCode)button forKey:(int16)key player:(int8)player oldButton:(S9xButtonCode *)oldButton oldPlayer:(int8 *)oldPlayer oldKey:(int16 *)oldKey { + BOOL result = NO; os_unfair_lock_lock(&keyLock); - SetKeyCode(key, control, oldKey, oldControl); + result = SetKeyCode(key, button, player, oldKey, oldButton, oldPlayer); os_unfair_lock_unlock(&keyLock); + return result; } - (BOOL)loadROM:(NSURL *)fileURL