diff options
| author | SND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97> | 2013-07-08 03:35:06 +0000 |
|---|---|---|
| committer | SND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97> | 2013-07-08 03:35:06 +0000 |
| commit | 60e436cbfc50b7ec6af134ecec0d4c19ee6b95ed (patch) | |
| tree | 874d0e8e909ea97c63fa08684fa8cad71c4ddda4 /macosx | |
| parent | 1be32b430bb24d88642409f6b80338e36879c342 (diff) | |
| download | pcsxr-60e436cbfc50b7ec6af134ecec0d4c19ee6b95ed.tar.gz | |
Implement compaction of memory cards.
Other assorted bug fixes.
git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@85890 e17a0e51-4ae3-4d35-97c3-1a29b211df97
Diffstat (limited to 'macosx')
| -rw-r--r-- | macosx/PcsxrMemCardArray.h | 1 | ||||
| -rw-r--r-- | macosx/PcsxrMemCardArray.m | 89 | ||||
| -rwxr-xr-x | macosx/PcsxrMemCardController.m | 7 | ||||
| -rwxr-xr-x | macosx/main.m | 4 |
4 files changed, 89 insertions, 12 deletions
diff --git a/macosx/PcsxrMemCardArray.h b/macosx/PcsxrMemCardArray.h index b8961e3f..a1d209fb 100644 --- a/macosx/PcsxrMemCardArray.h +++ b/macosx/PcsxrMemCardArray.h @@ -32,5 +32,6 @@ @property (nonatomic, readonly, unsafe_unretained) NSArray *memoryArray; @property (nonatomic, readonly, unsafe_unretained) NSURL *memCardURL; +@property (nonatomic, readonly) const char *memCardCPath; @end diff --git a/macosx/PcsxrMemCardArray.m b/macosx/PcsxrMemCardArray.m index d482cd5b..b3b8ce41 100644 --- a/macosx/PcsxrMemCardArray.m +++ b/macosx/PcsxrMemCardArray.m @@ -9,6 +9,7 @@ #import "PcsxrMemCardArray.h" #import "ARCBridge.h" #import "ConfigurationController.h" +#include "sio.h" #define MAX_MEMCARD_BLOCKS 15 @@ -25,6 +26,43 @@ static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, cha //printf("data = %s\n", from + (srci+1) * 128); } +static inline char* CreateBlankHeader() +{ + struct PSXMemHeader { + unsigned int allocState; + unsigned int fileSize; + unsigned short nextBlock; + char fileName[21]; + unsigned char garbage[96]; + unsigned char checksum; + }; + struct PSXMemHeader *toReturn = calloc(sizeof(struct PSXMemHeader), 1); + + toReturn->allocState = 0x000000a0; + toReturn->nextBlock = 0xFFFF; + unsigned char *bytePtr = (unsigned char*)toReturn; + for (int i = 0; i < sizeof(struct PSXMemHeader) - sizeof(unsigned char); i++) { + toReturn->checksum = toReturn->checksum ^ bytePtr[i]; + } + + return (char*)toReturn; +} + +static inline void ClearMemcardData(char *to, int dsti, char *str) +{ + // header + char *header = CreateBlankHeader(); + + memcpy(to + (dsti + 1) * 128, header, 128); + SaveMcd(str, to, (dsti + 1) * 128, 128); + free(header); + + // data + memset(to + (dsti + 1) * 1024 * 8, 0, 1024 * 8); + SaveMcd(str, to, (dsti + 1) * 1024 * 8, 1024 * 8); + +} + @interface PcsxrMemCardArray () @property (arcretain) NSArray *rawArray; @@ -45,6 +83,15 @@ static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, cha } } +- (const char *)memCardCPath +{ + if (cardNumber == 1) { + return Config.Mcd1; + } else { + return Config.Mcd2; + } +} + - (id)initWithMemoryCardNumber:(int)carNum { NSParameterAssert(carNum == 1 || carNum == 2); @@ -152,18 +199,10 @@ static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, cha NSAssert(toCopy != -1, @"Compacting the card should have made space!"); } - char *to, *from; - if (cardNumber == 1) { - to = Mcd2Data; - from = Mcd1Data; - } else { - to = Mcd1Data; - from = Mcd2Data; - } int memIdx = tmpObj.startingIndex; int i; for (i = 0; i < memSize; i++) { - CopyMemcardData([self memDataPtr], [otherCard memDataPtr], (memIdx+i), (toCopy+i), (char*)[[[otherCard memCardURL] path] fileSystemRepresentation]); + CopyMemcardData([self memDataPtr], [otherCard memDataPtr], (memIdx+i), (toCopy+i), (char*)otherCard.memCardCPath); } return YES; @@ -227,9 +266,37 @@ static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, cha - (void)compactMemory { - NSAssert(NO, @"Compacting memory cards is not implemented yet!"); + int i = 0, x = 1; + while (i < MAX_MEMCARD_BLOCKS && x < MAX_MEMCARD_BLOCKS) { + x = i; + McdBlock baseBlock; + GetMcdBlockInfo(cardNumber, i+1, &baseBlock); + PCSXRMemFlags theFlags = [PcsxrMemoryObject memFlagsFromBlockFlags:baseBlock.Flags]; + + if (theFlags == memFlagDeleted || theFlags == memFlagFree) { + PCSXRMemFlags up1Flags = theFlags; + while ((up1Flags == memFlagDeleted || up1Flags == memFlagFree) && x < MAX_MEMCARD_BLOCKS){ + x++; + McdBlock up1Block; + GetMcdBlockInfo(cardNumber, x+1, &up1Block); + up1Flags = [PcsxrMemoryObject memFlagsFromBlockFlags:up1Block.Flags]; + } + if (x >= MAX_MEMCARD_BLOCKS) { + + break; + } + CopyMemcardData(self.memDataPtr, self.memDataPtr, x, i, (char*)[[self.memCardURL path] fileSystemRepresentation]); + ClearMemcardData(self.memDataPtr, x, (char*)self.memCardCPath ); + } + i++; + } + + while (i < MAX_MEMCARD_BLOCKS) { + ClearMemcardData(self.memDataPtr, i, (char*)self.memCardCPath); + i++; + } - LoadMcd(cardNumber, cardNumber == 1 ? Config.Mcd1 : Config.Mcd2); + LoadMcd(cardNumber, (char*)self.memCardCPath); #if 0 [[NSNotificationCenter defaultCenter] postNotificationName:memChangeNotifier object:nil userInfo:[NSDictionary dictionaryWithObject:@(cardNumber) forKey:memCardChangeNumberKey]]; #endif diff --git a/macosx/PcsxrMemCardController.m b/macosx/PcsxrMemCardController.m index e04ace66..00d77ca7 100755 --- a/macosx/PcsxrMemCardController.m +++ b/macosx/PcsxrMemCardController.m @@ -133,12 +133,17 @@ int cardSize, freeConsBlocks, availBlocks; + if ([[[fromCard memoryArray] objectAtIndex:selectedIndex] flagNameIndex] == memFlagFree) { + NSBeep(); + return; + } + cardSize = [fromCard memorySizeAtIndex:selectedIndex]; freeConsBlocks = [toCard indexOfFreeBlocksWithSize:cardSize]; availBlocks = [toCard availableBlocks]; if (freeConsBlocks == -1 && availBlocks >= cardSize) { PcsxrMemoryObject *tmpmemobj = [fromCard.memoryArray objectAtIndex:selectedIndex]; - NSInteger copyOK = NSRunInformationalAlertPanel(NSLocalizedString(@"Free Size", nil), NSLocalizedString(@"Memory card %i does not have enough free consecutive blocks.\n\nIn order to copy over \"%@ (%@),\" memory card %i must be compressed. Compressing memory cards will make deleted blocks unrecoverable.\n\nDo you want to continue?", nil), NSLocalizedString(@"Yes", nil), NSLocalizedString(@"No", nil), nil, cardnum, tmpmemobj.englishName, tmpmemobj.sjisName, cardnum == 1 ? 2 : 1); + NSInteger copyOK = NSRunInformationalAlertPanel(NSLocalizedString(@"Free Size", nil), NSLocalizedString(@"Memory card %i does not have enough free consecutive blocks.\n\nIn order to copy over \"%@ (%@),\" memory card %i must be compressed. Compressing memory cards will make deleted blocks unrecoverable.\n\nDo you want to continue?", nil), NSLocalizedString(@"Yes", nil), NSLocalizedString(@"No", nil), nil, cardnum, tmpmemobj.englishName, tmpmemobj.sjisName, cardnum); if (copyOK != NSAlertDefaultReturn) { return; } diff --git a/macosx/main.m b/macosx/main.m index 595475dd..700bfdda 100755 --- a/macosx/main.m +++ b/macosx/main.m @@ -8,6 +8,7 @@ #import <Cocoa/Cocoa.h> #import "EmuThread.h" #import "PcsxrController.h" +#import "ConfigurationController.h" #include <dlfcn.h> //#import <sys/param.h> #import <unistd.h> @@ -187,9 +188,12 @@ void SysClose() { sysInited = NO; detachHotkeys(); + if (((PcsxrController *)[NSApp delegate]).endAtEmuClose) { [NSApp stop:nil]; } + //Tell the memory card manager that the memory cards changed. + [[NSNotificationCenter defaultCenter] postNotificationName:memChangeNotifier object:nil userInfo:[NSDictionary dictionaryWithObject:@3 forKey:memCardChangeNumberKey]]; } void OnFile_Exit() { |
