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 Oct 13, 2021
1 parent 544ade2 commit 71a2b2b
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 73 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 @@ -70,10 +70,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 @@ -241,17 +249,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 @@ -316,21 +324,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 @@ -375,7 +383,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 @@ -788,7 +796,7 @@ - (NSInteger)controllerValueForButtonID:(unsigned)buttonID forPlayer:(NSInteger)
case PVGenesisButtonStart:
return [[gamepad rightTrigger] isPressed];
default:
break;
break;
}}

} else if ([controller gamepad]) {
Expand Down Expand Up @@ -889,16 +897,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 @@ -907,16 +915,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
55 changes: 31 additions & 24 deletions Cores/snes9x/PVSNES/SNES/PVSNESEmulatorCore.mm
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ - (id)init
memset(soundBuffer, 0, SIZESOUNDBUFFER * sizeof(UInt16));
_current = self;
cheatList = [[NSMutableDictionary alloc] init];
}
}

return self;
}
Expand Down Expand Up @@ -125,32 +125,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
{

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 @@ -162,7 +165,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 @@ -176,7 +179,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 @@ -206,16 +209,16 @@ - (BOOL)loadFileAtPath:(NSString *)path error:(NSError**)error
{
free(videoBuffer);
}

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

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

videoBuffer = NULL;

Expand Down Expand Up @@ -754,7 +757,7 @@ - (BOOL)loadFileAtPath:(NSString *)path error:(NSError**)error

#pragma mark Video

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

- (const void *)videoBuffer
{
Expand Down Expand Up @@ -889,7 +896,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 71a2b2b

Please sign in to comment.