diff options
| author | SND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97> | 2013-07-08 01:43:06 +0000 |
|---|---|---|
| committer | SND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97> | 2013-07-08 01:43:06 +0000 |
| commit | 1be32b430bb24d88642409f6b80338e36879c342 (patch) | |
| tree | be73fef78ef1e1571620d7bfce134dfa5d54f697 /macosx/PcsxrMemCardArray.m | |
| parent | a65d2267a5b86826c59a9673e6aa185469f24000 (diff) | |
| download | pcsxr-1be32b430bb24d88642409f6b80338e36879c342.tar.gz | |
We can now copy to other cards, but compacting cards isn't available right now.
git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@85887 e17a0e51-4ae3-4d35-97c3-1a29b211df97
Diffstat (limited to 'macosx/PcsxrMemCardArray.m')
| -rw-r--r-- | macosx/PcsxrMemCardArray.m | 59 |
1 files changed, 53 insertions, 6 deletions
diff --git a/macosx/PcsxrMemCardArray.m b/macosx/PcsxrMemCardArray.m index 181b993d..d482cd5b 100644 --- a/macosx/PcsxrMemCardArray.m +++ b/macosx/PcsxrMemCardArray.m @@ -28,11 +28,22 @@ static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, cha @interface PcsxrMemCardArray () @property (arcretain) NSArray *rawArray; +@property (readonly) char* memDataPtr; @end @implementation PcsxrMemCardArray @synthesize rawArray; +//@synthesize memDataPtr; + +- (char*)memDataPtr +{ + if (cardNumber == 1) { + return Mcd1Data; + } else { + return Mcd2Data; + } +} - (id)initWithMemoryCardNumber:(int)carNum { @@ -124,13 +135,40 @@ static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, cha #endif return NO; } + PcsxrMemoryObject *tmpObj = [rawArray objectAtIndex:idx]; + int memSize = tmpObj.blockSize; + + if ([otherCard availableBlocks] < memSize) { + NSLog(@"Failing because the other card does not have enough space!"); + return NO; + } + + int toCopy = [otherCard indexOfFreeBlocksWithSize:memSize]; + if (toCopy == -1) { + NSLog(@"Not enough consecutive blocks. Compacting the other card."); + [otherCard compactMemory]; + toCopy = [otherCard indexOfFreeBlocksWithSize:memSize]; + 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]); + } - //TODO: Implement! - return NO; + return YES; } - - (int)freeBlocks { int memSize = 15; @@ -166,7 +204,7 @@ static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, cha return rawArray; } -- (NSURL*)memCardLocation +- (NSURL*)memCardURL { if (cardNumber == 1) { return [[NSUserDefaults standardUserDefaults] URLForKey:@"Mcd1"]; @@ -179,7 +217,7 @@ static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, cha { if (idx == [rawArray count]) { #ifdef DEBUG - NSLog(@"Trying to get an object one more than the length of the raw array. Perhaps you were trying to \"delete\" the free blocks"); + NSLog(@"Trying to get an object one more than the length of the raw array. Perhaps you were trying to \"count\" the free blocks"); #endif return [self freeBlocks]; } @@ -189,9 +227,10 @@ static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, cha - (void)compactMemory { + NSAssert(NO, @"Compacting memory cards is not implemented yet!"); -#if 0 LoadMcd(cardNumber, cardNumber == 1 ? Config.Mcd1 : Config.Mcd2); +#if 0 [[NSNotificationCenter defaultCenter] postNotificationName:memChangeNotifier object:nil userInfo:[NSDictionary dictionaryWithObject:@(cardNumber) forKey:memCardChangeNumberKey]]; #endif } @@ -240,5 +279,13 @@ static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, cha } } +#if !__has_feature(objc_arc) +- (void)dealloc +{ + self.rawArray = nil; + + [super dealloc]; +} +#endif @end |
