From 71a2b2bae4363b4447814fdd0ab4a497144baba9 Mon Sep 17 00:00:00 2001 From: Joseph Mattiello Date: Tue, 12 Oct 2021 20:50:14 -0400 Subject: [PATCH] More double buffering changes in snes and genesis Signed-off-by: Joseph Mattiello --- .../PVGenesis/Genesis/PVGenesisEmulatorCore.m | 106 ++++++++++-------- .../snes9x/PVSNES/SNES/PVSNESEmulatorCore.mm | 55 +++++---- 2 files changed, 88 insertions(+), 73 deletions(-) diff --git a/Cores/Genesis-Plus-GX/PVGenesis/Genesis/PVGenesisEmulatorCore.m b/Cores/Genesis-Plus-GX/PVGenesis/Genesis/PVGenesisEmulatorCore.m index 3dd7c74ff4..00aadf2867 100644 --- a/Cores/Genesis-Plus-GX/PVGenesis/Genesis/PVGenesisEmulatorCore.m +++ b/Cores/Genesis-Plus-GX/PVGenesis/Genesis/PVGenesisEmulatorCore.m @@ -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; @@ -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; } @@ -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; } @@ -375,7 +383,7 @@ - (BOOL)writeSaveFile:(NSString *)path forType:(int)type #pragma mark - Video -- (void)swapBuffers +- (void)flipBuffers { if (bitmap.data == (uint8_t*)videoBufferA) { @@ -788,7 +796,7 @@ - (NSInteger)controllerValueForButtonID:(unsigned)buttonID forPlayer:(NSInteger) case PVGenesisButtonStart: return [[gamepad rightTrigger] isPressed]; default: - break; + break; }} } else if ([controller gamepad]) { @@ -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; @@ -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; diff --git a/Cores/snes9x/PVSNES/SNES/PVSNESEmulatorCore.mm b/Cores/snes9x/PVSNES/SNES/PVSNESEmulatorCore.mm index 5446c8e28c..38834988a8 100644 --- a/Cores/snes9x/PVSNES/SNES/PVSNESEmulatorCore.mm +++ b/Cores/snes9x/PVSNES/SNES/PVSNESEmulatorCore.mm @@ -78,7 +78,7 @@ - (id)init memset(soundBuffer, 0, SIZESOUNDBUFFER * sizeof(UInt16)); _current = self; cheatList = [[NSMutableDictionary alloc] init]; - } + } return self; } @@ -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; @@ -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; @@ -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; @@ -206,16 +209,16 @@ - (BOOL)loadFileAtPath:(NSString *)path error:(NSError**)error { free(videoBuffer); } - + if (videoBufferA) - { + { free(videoBufferA); - } - + } + if (videoBufferB) - { + { free(videoBufferB); - } + } videoBuffer = NULL; @@ -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) { @@ -767,6 +770,10 @@ - (void)swapBuffers GFX.Screen = (short unsigned int *)videoBufferA; } } +TEST THIS +- (void)swapBuffers { + [self.renderDelegate didRenderFrameOnAlternateThread]; +} - (const void *)videoBuffer { @@ -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); } }