Skip to content

Commit

Permalink
More double buffering changes in snes and genesis
Browse files Browse the repository at this point in the history
Signed-off-by: Joseph Mattiello <[email protected]>
  • Loading branch information
JoeMatt committed Feb 16, 2022
1 parent b8dfa75 commit 0c35d3d
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 72 deletions.
106 changes: 57 additions & 49 deletions Cores/Genesis-Plus-GX/PVGenesis/Genesis/PVGenesisEmulatorCore.m
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,18 @@ static void video_callback(const void *data, unsigned width, unsigned height, si
dispatch_queue_t the_queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

dispatch_apply(height, the_queue, ^(size_t y){
const uint32_t *src = (uint32_t*)data + y * (pitch >> 2); //pitch is in bytes not pixels
uint32_t *dst = strongCurrent->videoBuffer + y * 720;
[strongCurrent flipBuffers];

const uint16_t *src = (uint16_t*)data + y * (pitch >> 1); //pitch is in bytes not pixels
uint16_t *dst = strongCurrent->videoBuffer + y * 320;

memcpy(dst, src, sizeof(uint32_t)*width);
memcpy(dst, src, sizeof(uint16_t)*width);
/* check diff
const uint32_t *src = (uint32_t*)data + y * (pitch >> 2); //pitch is in bytes not pixels
uint32_t *dst = strongCurrent->videoBuffer + y * 720;
memcpy(dst, src, sizeof(uint32_t)*width);
*/
});

strongCurrent = nil;
Expand Down Expand Up @@ -455,17 +463,17 @@ - (BOOL)loadFileAtPath:(NSString*)path error:(NSError**)error
if (dataObj == nil)
{
if(error != NULL) {
NSDictionary *userInfo = @{
NSLocalizedDescriptionKey: @"Failed to load game.",
NSLocalizedFailureReasonErrorKey: @"File was unreadble.",
NSLocalizedRecoverySuggestionErrorKey: @"Check the file isn't corrupt and exists."
};

NSError *newError = [NSError errorWithDomain:PVEmulatorCoreErrorDomain
code:PVEmulatorCoreErrorCodeCouldNotLoadRom
userInfo:userInfo];

*error = newError;
NSDictionary *userInfo = @{
NSLocalizedDescriptionKey: @"Failed to load game.",
NSLocalizedFailureReasonErrorKey: @"File was unreadble.",
NSLocalizedRecoverySuggestionErrorKey: @"Check the file isn't corrupt and exists."
};
NSError *newError = [NSError errorWithDomain:PVEmulatorCoreErrorDomain
code:PVEmulatorCoreErrorCodeCouldNotLoadRom
userInfo:userInfo];
*error = newError;
}
return false;
}
Expand Down Expand Up @@ -543,21 +551,21 @@ - (BOOL)loadFileAtPath:(NSString*)path error:(NSError**)error

return YES;
}

if(error != NULL) {
NSDictionary *userInfo = @{
NSLocalizedDescriptionKey: @"Failed to load game.",
NSLocalizedFailureReasonErrorKey: @"GenPlusGX failed to load game.",
NSLocalizedRecoverySuggestionErrorKey: @"Check the file isn't corrupt and supported GenPlusGX ROM format."
};

NSError *newError = [NSError errorWithDomain:PVEmulatorCoreErrorDomain
code:PVEmulatorCoreErrorCodeCouldNotLoadRom
userInfo:userInfo];

*error = newError;
NSDictionary *userInfo = @{
NSLocalizedDescriptionKey: @"Failed to load game.",
NSLocalizedFailureReasonErrorKey: @"GenPlusGX failed to load game.",
NSLocalizedRecoverySuggestionErrorKey: @"Check the file isn't corrupt and supported GenPlusGX ROM format."
};
NSError *newError = [NSError errorWithDomain:PVEmulatorCoreErrorDomain
code:PVEmulatorCoreErrorCodeCouldNotLoadRom
userInfo:userInfo];
*error = newError;
}

return NO;
}

Expand Down Expand Up @@ -657,7 +665,7 @@ - (BOOL)writeSaveFile:(NSString *)path forType:(int)type

#pragma mark - Video

- (void)swapBuffers
- (void)flipBuffers
{
if (bitmap.data == (uint8_t*)videoBufferA)
{
Expand Down Expand Up @@ -1069,7 +1077,7 @@ - (NSInteger)controllerValueForButtonID:(unsigned)buttonID forPlayer:(NSInteger)
case PVGenesisButtonStart:
return [[gamepad rightTrigger] isPressed];
default:
break;
break;
}}

} else if ([controller gamepad]) {
Expand Down Expand Up @@ -1170,16 +1178,16 @@ - (BOOL)loadStateFromFileAtPath:(NSString *)path error:(NSError *__autoreleasing
if (!saveStateData)
{
if(error != NULL) {
NSDictionary *userInfo = @{
NSLocalizedDescriptionKey: @"Failed to load save state.",
NSLocalizedFailureReasonErrorKey: @"Genesis failed to read savestate data.",
NSLocalizedRecoverySuggestionErrorKey: @"Check that the path is correct and file exists."
};

NSError *newError = [NSError errorWithDomain:PVEmulatorCoreErrorDomain
code:PVEmulatorCoreErrorCodeCouldNotLoadState
userInfo:userInfo];
*error = newError;
NSDictionary *userInfo = @{
NSLocalizedDescriptionKey: @"Failed to load save state.",
NSLocalizedFailureReasonErrorKey: @"Genesis failed to read savestate data.",
NSLocalizedRecoverySuggestionErrorKey: @"Check that the path is correct and file exists."
};

NSError *newError = [NSError errorWithDomain:PVEmulatorCoreErrorDomain
code:PVEmulatorCoreErrorCodeCouldNotLoadState
userInfo:userInfo];
*error = newError;
}
ELOG(@"Unable to load save state from path: %@", path);
return NO;
Expand All @@ -1188,16 +1196,16 @@ - (BOOL)loadStateFromFileAtPath:(NSString *)path error:(NSError *__autoreleasing
if (!retro_unserialize([saveStateData bytes], [saveStateData length]))
{
if(error != NULL) {
NSDictionary *userInfo = @{
NSLocalizedDescriptionKey: @"Failed to load save state.",
NSLocalizedFailureReasonErrorKey: @"Genesis failed to load savestate data.",
NSLocalizedRecoverySuggestionErrorKey: @"Check that the path is correct and file exists."
};

NSError *newError = [NSError errorWithDomain:PVEmulatorCoreErrorDomain
code:PVEmulatorCoreErrorCodeCouldNotLoadState
userInfo:userInfo];
*error = newError;
NSDictionary *userInfo = @{
NSLocalizedDescriptionKey: @"Failed to load save state.",
NSLocalizedFailureReasonErrorKey: @"Genesis failed to load savestate data.",
NSLocalizedRecoverySuggestionErrorKey: @"Check that the path is correct and file exists."
};

NSError *newError = [NSError errorWithDomain:PVEmulatorCoreErrorDomain
code:PVEmulatorCoreErrorCodeCouldNotLoadState
userInfo:userInfo];
*error = newError;
}
DLOG(@"Unable to load save state");
return NO;
Expand Down
54 changes: 31 additions & 23 deletions Cores/snes9x/PVSNES/SNES/PVSNESEmulatorCore.mm
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ - (id)init
memset(soundBuffer, 0, SIZESOUNDBUFFER * sizeof(UInt16));
_current = self;
cheatList = [[NSMutableDictionary alloc] init];
}
}

return self;
}
Expand Down Expand Up @@ -136,31 +136,35 @@ - (void)stopEmulation

}

- (void)executeFrame {
IPPU.RenderThisFrame = TRUE;
- (void)executeFrameSkippingFrame:(BOOL)skip {
IPPU.RenderThisFrame = !skip;
S9xMainLoop();
}

- (void)executeFrame {
[self executeFrameSkippingFrame:NO];
}

- (BOOL)loadFileAtPath:(NSString *)path error:(NSError**)error {

CPU.Flags = 0;
memset(&Settings, 0, sizeof(Settings));

Settings.DontSaveOopsSnapshot = false;
Settings.ForcePAL = false;
Settings.ForceNTSC = false;
Settings.ForceHeader = false;
Settings.ForceNoHeader = false;
Settings.MouseMaster = true;
Settings.SuperScopeMaster = true;
Settings.MultiPlayer5Master = true;
Settings.JustifierMaster = true;
Settings.ForcePAL = false;
Settings.ForceNTSC = false;
Settings.ForceHeader = false;
Settings.ForceNoHeader = false;

Settings.MouseMaster = true;
Settings.SuperScopeMaster = true;
Settings.MultiPlayer5Master = true;
Settings.JustifierMaster = true;

// Sound

Settings.SoundSync = true;
Settings.SixteenBitSound = true;
Settings.SixteenBitSound = true;
Settings.Stereo = true;
Settings.ReverseStereo = false;
Settings.SoundPlaybackRate = SAMPLERATE;
Expand All @@ -172,7 +176,7 @@ - (BOOL)loadFileAtPath:(NSString *)path error:(NSError**)error {

// Display

Settings.SupportHiRes = true;
Settings.SupportHiRes = true;
Settings.Transparency = true;
Settings.DisplayFrameRate = false;
Settings.DisplayPressedKeys = false;
Expand All @@ -186,7 +190,7 @@ - (BOOL)loadFileAtPath:(NSString *)path error:(NSError**)error {

// Settings

Settings.BSXBootup = false;
Settings.BSXBootup = false;
Settings.TurboMode = false;
Settings.TurboSkipFrames = 15;
Settings.MovieTruncate = false;
Expand Down Expand Up @@ -216,16 +220,16 @@ - (BOOL)loadFileAtPath:(NSString *)path error:(NSError**)error {
{
free(videoBuffer);
}

if (videoBufferA)
{
{
free(videoBufferA);
}

}
if (videoBufferB)
{
{
free(videoBufferB);
}
}

videoBuffer = NULL;

Expand Down Expand Up @@ -764,7 +768,7 @@ - (BOOL)loadFileAtPath:(NSString *)path error:(NSError**)error {

#pragma mark Video

- (void)swapBuffers {
- (void)flipBuffers {
if (GFX.Screen == (short unsigned int *)videoBufferA) {
videoBuffer = videoBufferA;
GFX.Screen = (short unsigned int *)videoBufferB;
Expand All @@ -773,6 +777,10 @@ - (void)swapBuffers {
GFX.Screen = (short unsigned int *)videoBufferA;
}
}
TEST THIS
- (void)swapBuffers {
[self.renderDelegate didRenderFrameOnAlternateThread];
}

- (const void *)videoBuffer {
return videoBuffer;
Expand Down Expand Up @@ -884,7 +892,7 @@ - (BOOL)setCheat:(NSString *)code setType:(NSString *)type setEnabled:(BOOL)enab
cheatListSuccessfull = NO;
[failedCheats addObject:singleCode];

// [cheatList removeObjectForKey:code];
// [cheatList removeObjectForKey:code];
ELOG(@"Code %@ failed", singleCode);
}
}
Expand Down

0 comments on commit 0c35d3d

Please sign in to comment.