Skip to content

Commit

Permalink
Saturn: Automatically enable Stunner / Virtua Gun where supported.
Browse files Browse the repository at this point in the history
  • Loading branch information
clobber committed May 7, 2020
1 parent e1708ac commit e8507ea
Showing 1 changed file with 114 additions and 8 deletions.
122 changes: 114 additions & 8 deletions MednafenGameCore.mm
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ @interface MednafenGameCore () <OELynxSystemResponderClient, OENGPSystemResponde
BOOL _isSBIRequired;
BOOL _isMultiDiscGame;
BOOL _isSS3DControlPadSupportedGame;
BOOL _isSSVirtuaGunSupportedGame;
BOOL _isPCE6ButtonPadSupportedGame;
NSMutableArray *_allCueSheetFiles;
NSMutableArray <NSMutableDictionary <NSString *, id> *> *_availableDisplayModes;
Expand Down Expand Up @@ -133,6 +134,8 @@ - (void)initializeMednafen

MDFNI_SetSetting("psx.h_overscan", "0"); // Remove PSX overscan

//MDFNI_SetSetting("ss.input.port1.gun_chairs", "0x1000000"); // SS: Disable crosshair drawing

// PlayStation SBI required games (LibCrypt)
NSDictionary<NSString *, NSNumber *> *sbiRequiredGames =
@{
Expand Down Expand Up @@ -2674,9 +2677,9 @@ - (void)initializeMednafen
@"MK-81067", // Christmas NiGHTS into Dreams... (USA)
@"T-5029H-50", // Croc - Legend of the Gobbos (Europe) / (USA)
@"T-26410G", // Croc! - Pau-Pau Island (Japan)
@"T-9509H-50", // Crypt Killer (Europe)
@"T-9518G", // Henry Explorers (Japan)
@"T-9509H", // Crypt Killer (USA)
//@"T-9509H-50", // Crypt Killer (Europe)
//@"T-9518G", // Henry Explorers (Japan)
//@"T-9509H", // Crypt Killer (USA)
@"MK-81205", // Cyber Speedway (Europe)
@"MK-81204", // Cyber Speedway (USA)
@"GS-9022", // Gran Chaser (Japan)
Expand Down Expand Up @@ -2710,8 +2713,8 @@ - (void)initializeMednafen
@"T-12303H", // Hardcore 4X4 (Europe)
@"T-13703H", // TNN Motor Sports Hardcore 4X4 (USA)
@"T-4313G", // Deka Yonku - Tough The Truck (Japan)
@"MK-81802", // House of the Dead, The (Europe) / (USA)
@"GS-9173", // House of the Dead, The (Japan)
//@"MK-81802", // House of the Dead, The (Europe) / (USA)
//@"GS-9173", // House of the Dead, The (Japan)
@"T-25503G", // Initial D - Koudou Saisoku Densetsu (Japan)
@"T-18008G", // Jungle Park - Saturn Shima (Japan)
@"T-19723G", // Kiss yori... (Japan)
Expand Down Expand Up @@ -2771,8 +2774,8 @@ - (void)initializeMednafen
@"T-1105G", // Taito Chase H.Q. + S.C.I. (Japan)
//@"T-4801G", // Tama - Adventurous Ball in Giddy Labyrinth (Japan)
@"T-14412G", // Touge King the Spirits 2 (Japan)
@"MK-81043", // Virtua Cop 2 (Europe) / (Korea) / (USA)
@"GS-9097", // Virtua Cop 2 (Japan)
//@"MK-81043", // Virtua Cop 2 (Europe) / (Korea) / (USA)
//@"GS-9097", // Virtua Cop 2 (Japan)
@"T-19718G", // Virtuacall S (Japan) (Disc 1) (Game Honpen)
@"T-7104G", // Virtual Kyoutei 2 (Japan)
@"MK-81024", // Wing Arms (Europe) / (USA)
Expand All @@ -2787,6 +2790,35 @@ - (void)initializeMednafen
@"GS-9120", // World Series Baseball II (Japan)
];

// Saturn Stunner / Virtua Gun supported games
NSArray<NSString *> *ssVirtuaGunGames =
@[
@"T-25408H", // Area 51 (Europe)
@"T-18613G", // Area 51 (Japan)
@"T-9705H", // Area 51 (USA)
@"T-15102H", // Chaos Control (Europe)
@"T-7006G", // Chaos Control Remix (Japan)
@"T-9509H-50", // Crypt Killer (Europe)
@"T-9518G", // Henry Explorers (Japan)
@"T-9509H", // Crypt Killer (USA)
@"T-23202G", // Death Crimson (Japan)
//@"T-16103H", // Die Hard Trilogy (Europe) / (USA)
//@"GS-9123", // Die Hard Trilogy (Japan)
@"MK-81802", // House of the Dead, The (Europe) / (USA)
@"GS-9173", // House of the Dead, The (Japan)
@"T-25417H", // Maximum Force (Europe)
@"T-9707H", // Maximum Force (USA)
@"GS-9088", // Mechanical Violator Hakaider - Last Judgement (Japan)
@"MK-81087", // Mighty Hits (Europe)
@"T-16604G", // Mighty Hits (Japan)
//@"T-9510G", // Policenauts (Japan)
@"T-30403H", // Scud - The Disposable Assassin (USA)
@"MK-81015", // Virtua Cop (Europe) / (USA)
@"GS-9060", // Virtua Cop (Japan)
@"MK-81043", // Virtua Cop 2 (Europe) / (Korea) / (USA)
@"GS-9097", // Virtua Cop 2 (Japan)
];

// TurboGrafx-16/PC Engine/CD 6-Button Pad supported games
NSArray<NSString *> *pce6ButtonPadGames =
@[
Expand Down Expand Up @@ -2913,6 +2945,12 @@ - (void)initializeMednafen
_isSS3DControlPadSupportedGame = YES;
}

// SS: Check if Stunner / Virtua Gun is supported
if ([ssVirtuaGunGames containsObject:self.ROMSerial])
{
_isSSVirtuaGunSupportedGame = YES;
}

}
}

Expand Down Expand Up @@ -3149,12 +3187,18 @@ - (BOOL)loadFileAtPath:(NSString *)path error:(NSError **)error
// Toggle default position of analog mode switch to Analog(○)
// "Analog mode is not compatible with all games. For some compatible games, analog mode reportedly must be enabled before the game boots up for the game to recognize it properly."
//_inputBuffer[i][0] |= 1 << SS3DMap[OESaturnButtonAnalogMode];

//Center the analog axis inputs
uint8_t *buf = (uint8_t *)_inputBuffer[i];
MDFN_en16lsb(&buf[2], 32767);
MDFN_en16lsb(&buf[4], 32767);
}
else if(_isSSVirtuaGunSupportedGame)
{
// Force Stunner / Virtua Gun to Port 1 and Gamepad to Port 2
game->SetInput(0, "gun", (uint8_t *)_inputBuffer[0]);
game->SetInput(1, "gamepad", (uint8_t *)_inputBuffer[1]);
}
else
{
game->SetInput(i, "gamepad", (uint8_t *)_inputBuffer[i]);
Expand Down Expand Up @@ -3448,6 +3492,15 @@ - (oneway void)didPushSaturnButton:(OESaturnButton)button forPlayer:(NSUInteger)
else
_inputBuffer[player-1][0] ^= 1 << SS3DMap[button];
}
else if(_isSSVirtuaGunSupportedGame && player == 1)
{
// Handle START for player 1 Stunner / Virtua Gun
if (button == OESaturnButtonStart)
{
uint8_t *buf = (uint8_t *)_inputBuffer[0];
MDFN_enlsb(&buf[4], 1 << 1); // START
}
}
else
_inputBuffer[player-1][0] |= 1 << SSMap[button];

Expand All @@ -3463,6 +3516,15 @@ - (oneway void)didReleaseSaturnButton:(OESaturnButton)button forPlayer:(NSUInteg
if (button != OESaturnButtonAnalogMode)
_inputBuffer[player-1][0] &= ~(1 << SS3DMap[button]);
}
else if(_isSSVirtuaGunSupportedGame && player == 1)
{
// Handle START for player 1 Stunner / Virtua Gun
if (button == OESaturnButtonStart)
{
uint8_t *buf = (uint8_t *)_inputBuffer[0];
MDFN_enlsb(&buf[4], 0); // release
}
}
else
_inputBuffer[player-1][0] &= ~(1 << SSMap[button]);
}
Expand Down Expand Up @@ -3533,22 +3595,66 @@ - (oneway void)didMoveSaturnJoystickDirection:(OESaturnButton)button withValue:(

- (oneway void)mouseMovedAtPoint:(OEIntPoint)point
{
if(_isSSVirtuaGunSupportedGame)
{
int scaled_x_coord;
int scaled_y_coord;

// Handle high res mode
// Can probably simplify this; check SMPC_EndFrame() and IODevice_Gun::Draw()
if(_videoHeight < 480)
{
scaled_x_coord = (point.x + game->mouse_offs_x) * game->mouse_scale_x / game->nominal_width;
scaled_y_coord = (point.y + game->mouse_offs_y) * game->mouse_scale_y / game->nominal_height;
}
else
{
scaled_x_coord = (point.x + game->mouse_offs_x) * game->mouse_scale_x / (game->nominal_width * 2);
scaled_y_coord = (point.y + game->mouse_offs_y) * game->mouse_scale_y / (game->nominal_height * 2);
}

uint8_t *buf = (uint8_t *)_inputBuffer[0];
MDFN_en16lsb(&buf[0], scaled_x_coord); // X coord
MDFN_en16lsb(&buf[2], scaled_y_coord); // Y coord
}
}

- (oneway void)leftMouseDownAtPoint:(OEIntPoint)point
{
if(_isSSVirtuaGunSupportedGame)
{
[self mouseMovedAtPoint:point];

uint8_t *buf = (uint8_t *)_inputBuffer[0];
MDFN_enlsb(&buf[4], 1 << 0); // TRIGGER
}
}

- (oneway void)leftMouseUp
{
if(_isSSVirtuaGunSupportedGame)
{
uint8_t *buf = (uint8_t *)_inputBuffer[0];
MDFN_enlsb(&buf[4], 0); // release TRIGGER
}
}

- (oneway void)rightMouseDownAtPoint:(OEIntPoint)point
{
if(_isSSVirtuaGunSupportedGame)
{
uint8_t *buf = (uint8_t *)_inputBuffer[0];
MDFN_enlsb(&buf[4], 1 << 2); // Offscreen Shot aka RELOAD
}
}

- (oneway void)rightMouseUp
{
if(_isSSVirtuaGunSupportedGame)
{
uint8_t *buf = (uint8_t *)_inputBuffer[0];
MDFN_enlsb(&buf[4], 0); // release Offscreen Shot aka RELOAD
}
}

# pragma mark - Display Mode
Expand Down

0 comments on commit e8507ea

Please sign in to comment.