From 03e3c01771cd7c1b502f5b79b902123fbee96d02 Mon Sep 17 00:00:00 2001 From: "SND\\MaddTheSane_cp" Date: Tue, 25 Jun 2013 22:50:14 +0000 Subject: Implement creating and selecting memory cards in the memory card manager. Get rid of imageFromMcd:index: and move the code to imagesFromMcd:. git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@85555 e17a0e51-4ae3-4d35-97c3-1a29b211df97 --- macosx/English.lproj/MemCardManager.xib | 1629 ++++++++++++++++++++++++++++++- macosx/PcsxrMemCardController.h | 5 + macosx/PcsxrMemCardController.m | 123 ++- macosx/PcsxrMemoryObject.h | 1 - macosx/PcsxrMemoryObject.m | 52 +- 5 files changed, 1730 insertions(+), 80 deletions(-) diff --git a/macosx/English.lproj/MemCardManager.xib b/macosx/English.lproj/MemCardManager.xib index 9b690aae..1ac73c77 100644 --- a/macosx/English.lproj/MemCardManager.xib +++ b/macosx/English.lproj/MemCardManager.xib @@ -2,15 +2,16 @@ 1070 - 12C60 - 2844 - 1187.34 - 625.00 + 12E55 + 3084 + 1187.39 + 626.00 com.apple.InterfaceBuilder.CocoaPlugin - 2844 + 3084 + IBNSLayoutConstraint NSArrayController NSBox NSButton @@ -47,14 +48,14 @@ 15 2 - {{196, 240}, {469, 316}} + {{196, 240}, {469, 351}} 544735232 Memory Card Manager NSWindow - {469, 316} - {469, 316} + {469, 351} + {469, 351} 256 @@ -62,7 +63,7 @@ 269 - {{203, 215}, {63, 32}} + {{203, 216}, {63, 32}} @@ -92,7 +93,7 @@ 293 - {{203, 81}, {63, 32}} + {{203, 82}, {63, 32}} @@ -194,7 +195,7 @@ 0.63157892227172852 - {{268, 48}, {181, 248}} + {{268, 49}, {181, 248}} @@ -264,7 +265,7 @@ {{1, 144}, {233, 15}} - + _NS:3374 NO 1 @@ -273,7 +274,7 @@ 0.63157892227172852 - {{20, 48}, {181, 248}} + {{20, 49}, {181, 248}} @@ -289,7 +290,7 @@ 289 - {{262, 12}, {98, 32}} + {{262, 13}, {98, 32}} @@ -315,7 +316,7 @@ 292 - {{14, 12}, {98, 32}} + {{14, 13}, {98, 32}} @@ -341,7 +342,7 @@ 292 - {{114, 12}, {93, 32}} + {{114, 13}, {93, 32}} @@ -367,7 +368,7 @@ 289 - {{362, 12}, {93, 32}} + {{362, 13}, {93, 32}} _NS:687 @@ -389,20 +390,172 @@ NO + + + 268 + {{14, 296}, {80, 32}} + + + + _NS:9 + 1 + YES + + 67108864 + 134217728 + New… + + _NS:9 + + -2038284288 + 129 + + + 200 + 25 + + NO + + + + 268 + {{106, 296}, {101, 32}} + + + + _NS:9 + 1 + YES + + 67108864 + 134217728 + Change… + + _NS:9 + + -2038284288 + 129 + + + 200 + 25 + + NO + + + + 268 + {{17, 332}, {187, 17}} + + + + _NS:1535 + YES + + 68157504 + 272630784 + Label + + _NS:1535 + + + + 6 + System + controlTextColor + + 3 + MAA + + + + NO + + + + 268 + {{262, 296}, {80, 32}} + + + _NS:9 + 2 + YES + + 67108864 + 134217728 + New… + + _NS:9 + + -2038284288 + 129 + + + 200 + 25 + + NO + + + + 268 + {{354, 296}, {101, 32}} + + + _NS:9 + 2 + YES + + 67108864 + 134217728 + Change… + + _NS:9 + + -2038284288 + 129 + + + 200 + 25 + + NO + + + + 268 + {{265, 332}, {187, 17}} + + + + _NS:1535 + YES + + 68157504 + 272630784 + Label + + _NS:1535 + + + + + NO + - {469, 316} + {469, 351} - + - {{0, 0}, {1680, 1028}} - {469, 338} - {469, 338} + {{0, 0}, {1920, 1058}} + {469, 373} + {469, 373} YES - + 256 @@ -457,15 +610,7 @@ _NS:3944 - - 6 - System - controlTextColor - - 3 - MAA - - + NO @@ -560,6 +705,7 @@ {179, 115} + @@ -667,6 +813,46 @@ 77 + + + memCard1Label + + + + 196 + + + + memCard2Label + + + + 197 + + + + newMemCard: + + + + 203 + + + + newMemCard: + + + + 204 + + + + changeMemCard: + + + + 206 + itemPrototype @@ -882,10 +1068,576 @@ + - + + + + 4 + 0 + + 4 + 1 + + 20 + + 1000 + + 8 + 29 + 3 + + + + 6 + 0 + + 6 + 1 + + 20 + + 1000 + + 8 + 29 + 3 + + + + 4 + 0 + + 4 + 1 + + 20 + + 1000 + + 8 + 29 + 3 + + + + 5 + 0 + + 5 + 1 + + 0.0 + + 1000 + + 6 + 24 + 2 + + + + 11 + 0 + + 11 + 1 + + 0.0 + + 1000 + + 6 + 24 + 2 + + + + 6 + 0 + + 6 + 1 + + 20 + + 1000 + + 8 + 29 + 3 + + + + 4 + 0 + + 4 + 1 + + 20 + + 1000 + + 8 + 29 + 3 + + + + 6 + 0 + + 6 + 1 + + 0.0 + + 1000 + + 6 + 24 + 2 + + + + 4 + 0 + + 4 + 1 + + 89 + + 1000 + + 3 + 9 + 3 + + + + 5 + 0 + + 6 + 1 + + 8 + + 1000 + + 6 + 24 + 3 + + + + 4 + 0 + + 4 + 1 + + 20 + + 1000 + + 8 + 29 + 3 + + + + 5 + 0 + + 5 + 1 + + 20 + + 1000 + + 8 + 29 + 3 + + + + 4 + 0 + + 4 + 1 + + 0.0 + + 1000 + + 6 + 24 + 2 + + + + 5 + 0 + + 6 + 1 + + 8 + + 1000 + + 6 + 24 + 3 + + + + 5 + 0 + + 6 + 1 + + 8 + + 1000 + + 6 + 24 + 3 + + + + 6 + 0 + + 6 + 1 + + 20 + + 1000 + + 8 + 29 + 3 + + + + 11 + 0 + + 11 + 1 + + 0.0 + + 1000 + + 6 + 24 + 2 + + + + 3 + 0 + + 3 + 1 + + 2 + + 1000 + + 3 + 9 + 3 + + + + 6 + 0 + + 6 + 1 + + 20 + + 1000 + + 8 + 29 + 3 + + + + 11 + 0 + + 11 + 1 + + 0.0 + + 1000 + + 6 + 24 + 2 + + + + 5 + 0 + + 5 + 1 + + 0.0 + + 1000 + + 6 + 24 + 2 + + + + 5 + 0 + + 5 + 1 + + 0.0 + + 1000 + + 6 + 24 + 2 + + + + 5 + 0 + + 6 + 1 + + 8 + + 1000 + + 6 + 24 + 3 + + + + 3 + 0 + + 3 + 1 + + 107 + + 1000 + + 3 + 9 + 3 + + + + 9 + 0 + + 9 + 1 + + 0.0 + + 1000 + + 5 + 22 + 2 + + + + 11 + 0 + + 11 + 1 + + 0.0 + + 1000 + + 6 + 24 + 2 + + + + 6 + 0 + + 6 + 1 + + 0.0 + + 1000 + + 6 + 24 + 2 + + + + 5 + 0 + + 5 + 1 + + 20 + + 1000 + + 8 + 29 + 3 + + + + 3 + 0 + + 3 + 1 + + 54 + + 1000 + + 3 + 9 + 3 + + + + 3 + 0 + + 3 + 1 + + 0.0 + + 1000 + + 6 + 24 + 2 + + + + 4 + 0 + + 4 + 1 + + 49 + + 1000 + + 3 + 9 + 3 + + + + 3 + 0 + + 4 + 1 + + 8 + + 1000 + + 6 + 24 + 3 + + + + 5 + 0 + + 5 + 1 + + 20 + + 1000 + + 8 + 29 + 3 + + + + 5 + 0 + + 5 + 1 + + 20 + + 1000 + + 8 + 29 + 3 + + + + 6 + 0 + + 6 + 1 + + 0.0 + + 1000 + + 6 + 24 + 2 + + + + + + @@ -894,6 +1646,22 @@ + + + 7 + 0 + + 0 + 1 + + 51 + + 1000 + + 3 + 9 + 1 + @@ -951,6 +1719,70 @@ + + + 6 + 0 + + 6 + 1 + + 0.0 + + 1000 + + 8 + 29 + 3 + + + + 5 + 0 + + 5 + 1 + + 1 + + 1000 + + 3 + 9 + 3 + + + + 3 + 0 + + 3 + 1 + + 0.0 + + 1000 + + 8 + 29 + 3 + + + + 4 + 0 + + 4 + 1 + + 0.0 + + 1000 + + 8 + 29 + 3 + MemCardObjectView @@ -1001,6 +1833,166 @@ + + + 3 + 0 + + 4 + 1 + + 8 + + 1000 + + 6 + 24 + 3 + + + + 3 + 0 + + 3 + 1 + + 3 + + 1000 + + 3 + 9 + 3 + + + + 9 + 0 + + 9 + 1 + + 0.0 + + 1000 + + 6 + 24 + 2 + + + + 3 + 0 + + 4 + 1 + + 8 + + 1000 + + 6 + 24 + 3 + + + + 5 + 0 + + 5 + 1 + + 0.0 + + 1000 + + 6 + 24 + 2 + + + + 6 + 0 + + 6 + 1 + + 0.0 + + 1000 + + 6 + 24 + 2 + + + + 5 + 0 + + 5 + 1 + + 3 + + 1000 + + 3 + 9 + 3 + + + + 6 + 0 + + 6 + 1 + + 0.0 + + 1000 + + 6 + 24 + 2 + + + + 3 + 0 + + 4 + 1 + + 8 + + 1000 + + 6 + 24 + 3 + + + + 5 + 0 + + 5 + 1 + + 0.0 + + 1000 + + 6 + 24 + 2 + @@ -1009,6 +2001,38 @@ + + + 7 + 0 + + 0 + 1 + + 32 + + 1000 + + 3 + 9 + 1 + + + + 8 + 0 + + 0 + 1 + + 32 + + 1000 + + 3 + 9 + 1 + @@ -1022,6 +2046,22 @@ + + + 7 + 0 + + 0 + 1 + + 171 + + 1000 + + 3 + 9 + 1 + @@ -1108,6 +2148,349 @@ + + 131 + + + + + + + + 132 + + + + + 133 + + + + + + + + 134 + + + + + 135 + + + + + + + + 136 + + + + + 137 + + + + + + + + 138 + + + + + + + + 139 + + + + + + + + 140 + + + + + 141 + + + + + 142 + + + + + 143 + + + + + 144 + + + + + 145 + + + + + 146 + + + + + 148 + + + + + 149 + + + + + 150 + + + + + 151 + + + + + 152 + + + + + 153 + + + + + 154 + + + + + 155 + + + + + 156 + + + + + 157 + + + + + 158 + + + + + 161 + + + + + 162 + + + + + 163 + + + + + 164 + + + + + 165 + + + + + 166 + + + + + 167 + + + + + 168 + + + + + 169 + + + + + 170 + + + + + 171 + + + + + 172 + + + + + 173 + + + + + 174 + + + + + 176 + + + + + 177 + + + + + 178 + + + + + 179 + + + + + 180 + + + + + 181 + + + + + 182 + + + + + 183 + + + + + 184 + + + + + 185 + + + + + 186 + + + + + 187 + + + + + 188 + + + + + 189 + + + + + 190 + + + + + 191 + + + + + 192 + + + + + 193 + + + + + 194 + + + + + 195 + + + + + 198 + + + + + 200 + + + + + 201 + + + + + 202 + + + @@ -1118,45 +2501,194 @@ {{357, 418}, {480, 270}} com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + com.apple.InterfaceBuilder.CocoaPlugin + + + + + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + + + + + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + + + + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + + + + + + + + + + + + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + + + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin - 91 + 206 @@ -1181,15 +2713,29 @@ ./Classes/NSCollectionViewItem.h + + NSLayoutConstraint + NSObject + + IBProjectSource + ./Classes/NSLayoutConstraint.h + + PcsxrMemCardController NSWindowController + id id id id + id + + changeMemCard: + id + deleteMemoryObject: id @@ -1202,16 +2748,30 @@ moveBlock: id + + newMemCard: + id + + NSTextField NSCollectionView + NSTextField NSCollectionView + + memCard1Label + NSTextField + memCard1view NSCollectionView + + memCard2Label + NSTextField + memCard2view NSCollectionView @@ -1232,5 +2792,6 @@ YES 3 + YES diff --git a/macosx/PcsxrMemCardController.h b/macosx/PcsxrMemCardController.h index 8e9eb906..bbdc6fc5 100755 --- a/macosx/PcsxrMemCardController.h +++ b/macosx/PcsxrMemCardController.h @@ -13,6 +13,9 @@ { IBOutlet NSCollectionView *memCard1view; IBOutlet NSCollectionView *memCard2view; + IBOutlet NSTextField *memCard1Label; + IBOutlet NSTextField *memCard2Label; + NSMutableArray *memCard1Array; NSMutableArray *memCard2Array; NSTimer *imageAnimateTimer; @@ -21,6 +24,8 @@ - (IBAction)moveBlock:(id)sender; - (IBAction)formatCard:(id)sender; - (IBAction)deleteMemoryObject:(id)sender; +- (IBAction)newMemCard:(id)sender; +- (IBAction)changeMemCard:(id)sender; - (void)loadMemoryCardInfoForCard:(int)theCard; - (BOOL)isMemoryBlockEmptyOnCard:(int)aCard block:(int)aBlock; - (int)countFreeBlocksOnCard:(int)aCard; diff --git a/macosx/PcsxrMemCardController.m b/macosx/PcsxrMemCardController.m index d1bc8e4d..9729fa74 100755 --- a/macosx/PcsxrMemCardController.m +++ b/macosx/PcsxrMemCardController.m @@ -9,13 +9,15 @@ #import "PcsxrMemCardController.h" #import "PcsxrMemoryObject.h" #import "ConfigurationController.h" +#import "PcsxrMemCardHandler.h" #include "sio.h" #import "ARCBridge.h" #define MAX_MEMCARD_BLOCKS 15 -static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, char *str) { +static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, char *str) +{ // header memcpy(to + (dsti + 1) * 128, from + (srci + 1) * 128, 128); SaveMcd(str, to, (dsti + 1) * 128, 128); @@ -32,11 +34,39 @@ static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, cha //memCard1Array KVO functions --(void)insertObject:(PcsxrMemoryObject *)p inMemCard1ArrayAtIndex:(NSUInteger)index { +- (void)setupValues +{ + LoadMcds(Config.Mcd1, Config.Mcd2); + NSFileManager *fm = [NSFileManager defaultManager]; + NSString *fileName1 = nil; + NSString *fileName2 = nil; + NSString *fullPath1 = [fm stringWithFileSystemRepresentation:Config.Mcd1 length:sizeof(Config.Mcd1)]; + NSString *fullPath2 = [fm stringWithFileSystemRepresentation:Config.Mcd2 length:sizeof(Config.Mcd2)]; +#if 0 + fileName1 = [fm displayNameAtPath:fullPath1]; + fileName2 = [fm displayNameAtPath:fullPath2]; +#else + fileName1 = [fullPath1 lastPathComponent]; + fileName2 = [fullPath2 lastPathComponent]; +#endif + + [memCard1Label setTitleWithMnemonic:fileName1]; + [memCard2Label setTitleWithMnemonic:fileName2]; + + [memCard1Label setToolTip:fullPath1]; + [memCard2Label setToolTip:fullPath2]; + + [self loadMemoryCardInfoForCard:1]; + [self loadMemoryCardInfoForCard:2]; +} + +-(void)insertObject:(PcsxrMemoryObject *)p inMemCard1ArrayAtIndex:(NSUInteger)index +{ [memCard1Array insertObject:p atIndex:index]; } --(void)removeObjectFromMemCard1ArrayAtIndex:(NSUInteger)index { +-(void)removeObjectFromMemCard1ArrayAtIndex:(NSUInteger)index +{ [memCard1Array removeObjectAtIndex:index]; } @@ -52,16 +82,18 @@ static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, cha - (NSArray *)memCard1Array { - return memCard1Array; + return [NSArray arrayWithArray:memCard1Array]; } //memCard2Array KVO functions --(void)insertObject:(PcsxrMemoryObject *)p inMemCard2ArrayAtIndex:(NSUInteger)index { +-(void)insertObject:(PcsxrMemoryObject *)p inMemCard2ArrayAtIndex:(NSUInteger)index +{ [memCard2Array insertObject:p atIndex:index]; } --(void)removeObjectFromMemCard2ArrayAtIndex:(NSUInteger)index { +-(void)removeObjectFromMemCard2ArrayAtIndex:(NSUInteger)index +{ [memCard2Array removeObjectAtIndex:index]; } @@ -77,7 +109,7 @@ static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, cha - (NSArray *)memCard2Array { - return memCard2Array; + return [NSArray arrayWithArray:memCard2Array]; } - (id)init @@ -90,7 +122,7 @@ static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, cha { self = [super initWithWindow:window]; if (self) { - LoadMcds(Config.Mcd1, Config.Mcd2); + //LoadMcds(Config.Mcd1, Config.Mcd2); } return self; @@ -145,9 +177,7 @@ static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, cha - (void)memoryCardDidChangeNotification:(NSNotification *)aNote { - LoadMcds(Config.Mcd1, Config.Mcd2); - [self loadMemoryCardInfoForCard:1]; - [self loadMemoryCardInfoForCard:2]; + [self setupValues]; } - (void)windowDidLoad @@ -156,9 +186,10 @@ static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, cha // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file. [[self window] setDelegate:self]; + //[self setupValues]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(memoryCardDidChangeNotification:) name:memChangeNotifier object:nil]; - imageAnimateTimer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:2] interval:2.0/3.0 target:self selector:@selector(animateMemCards:) userInfo:nil repeats:YES]; + imageAnimateTimer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:2] interval:2.0/5.0 target:self selector:@selector(animateMemCards:) userInfo:nil repeats:YES]; [[NSRunLoop mainRunLoop] addTimer:imageAnimateTimer forMode:NSDefaultRunLoopMode]; } @@ -167,11 +198,10 @@ static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, cha [[NSNotificationCenter defaultCenter] postNotificationName:memoryAnimateTimerKey object:self]; } -- (void)windowDidBecomeKey:(NSNotification *)notification +- (IBAction)showWindow:(id)sender { - LoadMcds(Config.Mcd1, Config.Mcd2); - [self loadMemoryCardInfoForCard:1]; - [self loadMemoryCardInfoForCard:2]; + [super showWindow:sender]; + [self setupValues]; } - (int)findFreeMemCardBlockInCard:(int)target_card length:(int)len @@ -221,7 +251,6 @@ static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, cha return (i-foundcount); return -1; - } - (int)findFreeMemCardBlockInCard:(int)target_card @@ -376,7 +405,6 @@ static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, cha *ptr = xor; SaveMcd(filename, data, i * 128, 128); - } - (IBAction)deleteMemoryObject:(id)sender { @@ -407,6 +435,65 @@ static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, cha } } +- (IBAction)newMemCard:(id)sender { + int tag = [sender tag]; + char *mcd; + NSTextField *label; + NSOpenPanel *openDlg = RETAINOBJ([NSOpenPanel openPanel]); + NSString *path; + + if (tag == 1) { mcd = Config.Mcd1; label = memCard1Label; } + else { mcd = Config.Mcd2; label = memCard2Label; } + + [openDlg setCanChooseFiles:YES]; + [openDlg setCanChooseDirectories:NO]; + [openDlg setAllowedFileTypes:[PcsxrMemCardHandler supportedUTIs]]; + + path = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:mcd length:strlen(mcd)]; + + [openDlg setDirectoryURL:[NSURL fileURLWithPath:[path stringByDeletingLastPathComponent]]]; + [openDlg setNameFieldStringValue:[path lastPathComponent]]; + + if ([openDlg runModal] == NSFileHandlingPanelOKButton) { + NSArray* urls = [openDlg URLs]; + NSString *mcdPath = [[urls objectAtIndex:0] path]; + + [ConfigurationController setMemoryCard:tag toPath:mcdPath]; + } + RELEASEOBJ(openDlg); + +} + +- (IBAction)changeMemCard:(id)sender { + int tag = [sender tag]; + char *mcd; + NSTextField *label; + NSSavePanel *openDlg = RETAINOBJ([NSSavePanel savePanel]); + NSString *path; + + if (tag == 1) { mcd = Config.Mcd1; label = memCard1Label; } + else { mcd = Config.Mcd2; label = memCard2Label; } + + path = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:mcd length:strlen(mcd)]; + + [openDlg setDirectoryURL:[NSURL fileURLWithPath:[path stringByDeletingLastPathComponent]]]; + [openDlg setNameFieldStringValue:@"New Memory Card File.mcr"]; + [openDlg setAllowedFileTypes:[PcsxrMemCardHandler supportedUTIs]]; + + if ([openDlg runModal] == NSFileHandlingPanelOKButton) { + NSString *mcdPath = [[openDlg URL] path]; + + //Workaround/kludge to make sure we create a memory card before posting a notification + strlcpy(mcd, [mcdPath fileSystemRepresentation], MAXPATHLEN); + + CreateMcd(mcd); + + [ConfigurationController setMemoryCard:tag toPath:mcdPath]; + } + RELEASEOBJ(openDlg); + +} + - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; diff --git a/macosx/PcsxrMemoryObject.h b/macosx/PcsxrMemoryObject.h index e197c21a..3cce4796 100755 --- a/macosx/PcsxrMemoryObject.h +++ b/macosx/PcsxrMemoryObject.h @@ -27,7 +27,6 @@ extern NSString *const memoryAnimateTimerKey; BOOL notDeleted; unsigned char memFlags; } -+ (NSImage *)imageFromMcd:(McdBlock *)block index:(int)idx; + (NSArray *)imagesFromMcd:(McdBlock *)block; - (id)initWithMcdBlock:(McdBlock *)infoBlock; diff --git a/macosx/PcsxrMemoryObject.m b/macosx/PcsxrMemoryObject.m index 16989b67..3b0818c8 100755 --- a/macosx/PcsxrMemoryObject.m +++ b/macosx/PcsxrMemoryObject.m @@ -34,11 +34,33 @@ NSString *const memoryAnimateTimerKey = @"PCSXR Memory Card Image Animate"; { NSMutableArray *imagesArray = [[NSMutableArray alloc] initWithCapacity:block->IconCount]; for (int i = 0; i < block->IconCount; i++) { - [imagesArray addObject:[self imageFromMcd:block index:i]]; + NSImage *memImage = nil; + { + NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL pixelsWide:16 pixelsHigh:16 bitsPerSample:8 samplesPerPixel:3 hasAlpha:NO isPlanar:NO colorSpaceName:NSCalibratedRGBColorSpace bytesPerRow:0 bitsPerPixel:0]; + + short *icon = block->Icon; + + int x, y, c, v, r, g, b; + for (v = 0; v < 256; v++) { + x = (v % 16); + y = (v / 16); + c = icon[(i * 256) + v]; + r = (c & 0x001f) << 3; + g = ((c & 0x03e0) >> 5) << 3; + b = ((c & 0x7c00) >> 10) << 3; + [imageRep setColor:[NSColor colorWithCalibratedRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1.0] atX:x y:y]; + } + memImage = [[NSImage alloc] init]; + [memImage addRepresentation:imageRep]; + RELEASEOBJ(imageRep); + [memImage setSize:NSMakeSize(32, 32)]; + } + [imagesArray addObject:memImage]; + RELEASEOBJ(memImage); } - NSArray *retArray = [[NSArray alloc] initWithArray:imagesArray]; + NSArray *retArray = [NSArray arrayWithArray:imagesArray]; RELEASEOBJ(imagesArray); - return AUTORELEASEOBJ(retArray); + return retArray; } + (NSImage *)blankImage @@ -51,34 +73,10 @@ NSString *const memoryAnimateTimerKey = @"PCSXR Memory Card Image Animate"; [[NSColor blackColor] set]; [NSBezierPath fillRect:imageRect]; [imageBlank unlockFocus]; - } return imageBlank; } -+ (NSImage *)imageFromMcd:(McdBlock *)block index:(int)idx -{ - NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL pixelsWide:16 pixelsHigh:16 bitsPerSample:8 samplesPerPixel:3 hasAlpha:NO isPlanar:NO colorSpaceName:NSCalibratedRGBColorSpace bytesPerRow:0 bitsPerPixel:0]; - - short *icon = block->Icon; - - int x, y, c, i, r, g, b; - for (i = 0; i < 256 * (idx + 1); i++) { - x = (i % 16); - y = (i / 16); - c = icon[(idx * 256) + i]; - r = (c & 0x001f) << 3; - g = ((c & 0x03e0) >> 5) << 3; - b = ((c & 0x7c00) >> 10) << 3; - [imageRep setColor:[NSColor colorWithCalibratedRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1.0] atX:x y:y]; - } - NSImage *theImage = [[NSImage alloc] init]; - [theImage addRepresentation:imageRep]; - RELEASEOBJ(imageRep); - [theImage setSize:NSMakeSize(32, 32)]; - return AUTORELEASEOBJ(theImage); -} - - (id)initWithMcdBlock:(McdBlock *)infoBlock { if (self = [super init]) { -- cgit v1.2.3