summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2011-12-09 23:06:12 +0000
committerSND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2011-12-09 23:06:12 +0000
commitec0822b8f00cd09591c5deafa78a382131186859 (patch)
tree6b55a6aca6e6d8e82175dce69b93b7424eff25b0
parent7bbdf20d981c5fc8691e95bf0da2f71158058c97 (diff)
downloadpcsxr-ec0822b8f00cd09591c5deafa78a382131186859.tar.gz
Moving things around in the Memory manager for Mac OS X.
Fixed a bug in the OS X memory manager that would prevent the change in memory card to be reflected in the window. git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@73112 e17a0e51-4ae3-4d35-97c3-1a29b211df97
-rw-r--r--macosx/PcsxrMemCardController.h2
-rw-r--r--macosx/PcsxrMemCardController.m118
-rw-r--r--macosx/PcsxrMemoryObject.h12
-rw-r--r--macosx/PcsxrMemoryObject.m74
4 files changed, 144 insertions, 62 deletions
diff --git a/macosx/PcsxrMemCardController.h b/macosx/PcsxrMemCardController.h
index c6d05121..8b5598cd 100644
--- a/macosx/PcsxrMemCardController.h
+++ b/macosx/PcsxrMemCardController.h
@@ -21,4 +21,6 @@
- (IBAction)formatCard:(id)sender;
- (IBAction)deleteMemoryObject:(id)sender;
- (void)loadMemoryCardInfoForCard:(int)theCard;
+- (BOOL)isMemoryBlockEmptyOnCard:(int)aCard block:(int)aBlock;
+- (int)countFreeBlocksOnCard:(int)aCard;
@end
diff --git a/macosx/PcsxrMemCardController.m b/macosx/PcsxrMemCardController.m
index 9160d4cf..cbff6ff8 100644
--- a/macosx/PcsxrMemCardController.m
+++ b/macosx/PcsxrMemCardController.m
@@ -15,43 +15,6 @@
//FIXME: This code uses similar code to the GTK memory card manager, and both don't recognize saves that span multiple blocks.
-static NSImage *imageFromMcd(short * icon)
-{
- NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL pixelsWide:16 pixelsHigh:16 bitsPerSample:8 samplesPerPixel:3 hasAlpha:NO isPlanar:NO colorSpaceName:NSCalibratedRGBColorSpace bytesPerRow:0 bitsPerPixel:0];
-
-#if 0
- int x, y, c;
- for (y = 0; y < 32; y++) {
- for (x = 0; x < 32; x++) {
- c = icon[(y>>1) * 16 + (x>>1)];
- c = ((c & 0x001f) << 10) | ((c & 0x7c00) >> 10) | (c & 0x03e0);
- c = ((c & 0x001f) << 3) | ((c & 0x03e0) << 6) | ((c & 0x7c00) << 9);
-
- NSUInteger NSc = c;
-
- [imageRep setPixel:&NSc atX:x y:y];
- }
- }
-#else
- int x, y, c, i, r, g, b;
- for (i = 0; i < 256; i++) {
- x = (i % 16);
- y = (i / 16);
- c = icon[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];
- }
-#endif
- NSImage *theImage = [[NSImage alloc] init];
- [theImage addRepresentation:imageRep];
- [imageRep release];
- [theImage setScalesWhenResized:YES];
- [theImage setSize:NSMakeSize(32, 32)];
- return [theImage autorelease];
-}
-
static inline void CopyMemcardData(char *from, char *to, int *i, char *str, int copy) {
memcpy(to + (*i + 1) * 128, from + (copy + 1) * 128, 128);
SaveMcd(str, to, (*i + 1) * 128, 128);
@@ -132,22 +95,7 @@ static inline void CopyMemcardData(char *from, char *to, int *i, char *str, int
for (i = 0; i < MAX_MEMCARD_BLOCKS; i++) {
GetMcdBlockInfo(theCard, i + 1, &info);
- PcsxrMemoryObject *ob = [[PcsxrMemoryObject alloc] init];
- ob.englishName = [NSString stringWithCString:info.Title encoding:NSASCIIStringEncoding];
- ob.sjisName = [NSString stringWithCString:info.sTitle encoding:NSShiftJISStringEncoding];
- ob.memImage = imageFromMcd(info.Icon);
- ob.memNumber = i;
- ob.memFlags = info.Flags;
- if ((info.Flags & 0xF0) == 0xA0) {
- if ((info.Flags & 0xF) >= 1 &&
- (info.Flags & 0xF) <= 3) {
- ob.notDeleted = NO;
- } else
- ob.notDeleted = NO;
- } else if ((info.Flags & 0xF0) == 0x50)
- ob.notDeleted = YES;
- else
- ob.notDeleted = NO;
+ PcsxrMemoryObject *ob = [[PcsxrMemoryObject alloc] initWithMcdBlock:&info];
[newArray insertObject:ob atIndex:i];
[ob release];
@@ -162,7 +110,9 @@ static inline void CopyMemcardData(char *from, char *to, int *i, char *str, int
- (void)memoryCardDidChangeNotification:(NSNotification *)aNote
{
+ LoadMcd(1, Config.Mcd1);
[self loadMemoryCardInfoForCard:1];
+ LoadMcd(2, Config.Mcd2);
[self loadMemoryCardInfoForCard:2];
}
@@ -178,12 +128,15 @@ static inline void CopyMemcardData(char *from, char *to, int *i, char *str, int
- (void)windowDidBecomeKey:(NSNotification *)notification
{
+ LoadMcd(1, Config.Mcd1);
[self loadMemoryCardInfoForCard:1];
+ LoadMcd(2, Config.Mcd2);
[self loadMemoryCardInfoForCard:2];
}
-- (int)findFreeMemCardSlotInCard:(int)target_card
+- (int)findFreeMemCardBlockInCard:(int)target_card
{
+#if 0
BOOL found = NO;
NSString *blockName;
NSArray *cardArray;
@@ -194,8 +147,9 @@ static inline void CopyMemcardData(char *from, char *to, int *i, char *str, int
}
int i = 0;
- while (i < 15 && found == NO) {
+ while (i < MAX_MEMCARD_BLOCKS && found == NO) {
blockName = [[cardArray objectAtIndex:i] englishName];
+ //FIXME: Does this properly handle saves that span more than one block?
if ([blockName isEqualToString:@""]) {
found = YES;
} else {
@@ -207,7 +161,7 @@ static inline void CopyMemcardData(char *from, char *to, int *i, char *str, int
// no free slots, try to find a deleted one
i = 0;
- while (i < 15 && found == NO) {
+ while (i < MAX_MEMCARD_BLOCKS && found == NO) {
unsigned char flags = [[cardArray objectAtIndex:i] memFlags];
if ((flags & 0xF0) != 0x50) {
found = YES;
@@ -217,6 +171,14 @@ static inline void CopyMemcardData(char *from, char *to, int *i, char *str, int
}
if (found == YES)
return i;
+#else
+ int i;
+ for (i = 0; i < MAX_MEMCARD_BLOCKS; i++) {
+ if ([self isMemoryBlockEmptyOnCard:target_card block:i]) {
+ return i;
+ }
+ }
+#endif
return -1;
}
@@ -249,7 +211,7 @@ static inline void CopyMemcardData(char *from, char *to, int *i, char *str, int
NSInteger selectedIndex = [selection firstIndex];
- freeSlot = [self findFreeMemCardSlotInCard:toCard];
+ freeSlot = [self findFreeMemCardBlockInCard:toCard];
if (freeSlot == -1) {
NSRunCriticalAlertPanel(NSLocalizedString(@"No Free Space", nil), [NSString stringWithFormat:NSLocalizedString(@"Memory card %d doesn't have a free block on it. Please remove some blocks on that card to continue", nil), toCard], NSLocalizedString(@"Okay", nil), nil, nil);
return;
@@ -281,7 +243,7 @@ static inline void CopyMemcardData(char *from, char *to, int *i, char *str, int
}
}
-- (void)deleteMemoryObjectAtSlot:(int)slotnum card:(int)cardNum
+- (void)deleteMemoryBlockAtSlot:(int)slotnum card:(int)cardNum
{
int xor = 0, i, j;
char *data, *ptr, *filename;
@@ -335,7 +297,7 @@ static inline void CopyMemcardData(char *from, char *to, int *i, char *str, int
}
NSInteger selectedIndex = [selected firstIndex];
- [self deleteMemoryObjectAtSlot:selectedIndex card:memCardSelect];
+ [self deleteMemoryBlockAtSlot:selectedIndex card:memCardSelect];
if (memCardSelect == 1) {
LoadMcd(1, Config.Mcd1);
@@ -353,4 +315,42 @@ static inline void CopyMemcardData(char *from, char *to, int *i, char *str, int
[super dealloc];
}
+- (BOOL)isMemoryBlockEmptyOnCard:(int)aCard block:(int)aBlock
+{
+ NSArray *memArray;
+ PcsxrMemoryObject *obj;
+ if (aCard == 1) {
+ memArray = [self memCard1Array];
+ } else {
+ memArray = [self memCard2Array];
+ }
+ obj = [memArray objectAtIndex:aBlock];
+#if 0
+ if (([obj memFlags] & 0xF0) != 0x50)
+ return YES;
+
+ //FIXME: Does this properly handle saves that span more than one block?
+ if ([[obj englishName] isEqualToString:@""]) {
+ return YES;
+ }
+#else
+ if (![obj isNotDeleted]) {
+ return YES;
+ }
+#endif
+
+ return NO;
+}
+
+- (int)countFreeBlocksOnCard:(int)aCard
+{
+ int i, count = 0;
+ for (i = 0; i < MAX_MEMCARD_BLOCKS; i++) {
+ if ([self isMemoryBlockEmptyOnCard:aCard block:i]) {
+ count++;
+ }
+ }
+ return count;
+}
+
@end
diff --git a/macosx/PcsxrMemoryObject.h b/macosx/PcsxrMemoryObject.h
index 6f3bacb6..358acf87 100644
--- a/macosx/PcsxrMemoryObject.h
+++ b/macosx/PcsxrMemoryObject.h
@@ -8,22 +8,30 @@
#import <Foundation/NSString.h>
#import <AppKit/NSImage.h>
+#include "sio.h"
@interface PcsxrMemoryObject : NSObject
{
NSString *englishName;
NSString *sjisName;
+ NSString *memName;
+ NSString *memID;
NSImage *memImage;
+ int memIconCount;
BOOL notDeleted;
- short memNumber;
unsigned char memFlags;
}
++ (NSImage *)imageFromMcd:(short *)icon;
+
+- (id)initWithMcdBlock:(McdBlock *)infoBlock;
@property(copy, readwrite) NSString *englishName;
@property(copy, readwrite) NSString *sjisName;
+@property(copy, readwrite) NSString *memName;
+@property(copy, readwrite) NSString *memID;
@property(retain, readwrite) NSImage *memImage;
+@property(readwrite) int memIconCount;
@property(readwrite, getter = isNotDeleted) BOOL notDeleted;
-@property(readwrite) short memNumber;
@property(readwrite) unsigned char memFlags;
diff --git a/macosx/PcsxrMemoryObject.m b/macosx/PcsxrMemoryObject.m
index 297029a2..aa5c7b44 100644
--- a/macosx/PcsxrMemoryObject.m
+++ b/macosx/PcsxrMemoryObject.m
@@ -7,23 +7,95 @@
//
#import "PcsxrMemoryObject.h"
+#import <AppKit/NSColor.h>
@implementation PcsxrMemoryObject
++ (NSImage *)imageFromMcd:(short *)icon
+{
+ NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL pixelsWide:16 pixelsHigh:16 bitsPerSample:8 samplesPerPixel:3 hasAlpha:NO isPlanar:NO colorSpaceName:NSCalibratedRGBColorSpace bytesPerRow:0 bitsPerPixel:0];
+
+#if 0
+ int x, y, c;
+ for (y = 0; y < 32; y++) {
+ for (x = 0; x < 32; x++) {
+ c = icon[(y>>1) * 16 + (x>>1)];
+ c = ((c & 0x001f) << 10) | ((c & 0x7c00) >> 10) | (c & 0x03e0);
+ c = ((c & 0x001f) << 3) | ((c & 0x03e0) << 6) | ((c & 0x7c00) << 9);
+
+ NSUInteger NSc = c;
+
+ [imageRep setPixel:&NSc atX:x y:y];
+ }
+ }
+#else
+ int x, y, c, i, r, g, b;
+ for (i = 0; i < 256; i++) {
+ x = (i % 16);
+ y = (i / 16);
+ c = icon[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];
+ }
+#endif
+ NSImage *theImage = [[NSImage alloc] init];
+ [theImage addRepresentation:imageRep];
+ [imageRep release];
+ [theImage setScalesWhenResized:YES];
+ [theImage setSize:NSMakeSize(32, 32)];
+ return [theImage autorelease];
+}
+
+- (id)initWithMcdBlock:(McdBlock *)infoBlock
+{
+ if (self = [super init]) {
+ self.englishName = [NSString stringWithCString:infoBlock->Title encoding:NSASCIIStringEncoding];
+ self.sjisName = [NSString stringWithCString:infoBlock->sTitle encoding:NSShiftJISStringEncoding];
+ self.memImage = [PcsxrMemoryObject imageFromMcd:infoBlock->Icon];
+ self.memName = [NSString stringWithCString:infoBlock->Name encoding:NSASCIIStringEncoding];
+ self.memID = [NSString stringWithCString:infoBlock->ID encoding:NSASCIIStringEncoding];
+ self.memIconCount = infoBlock->IconCount;
+ self.memFlags = infoBlock->Flags;
+ if ((infoBlock->Flags & 0xF0) == 0xA0) {
+ if ((infoBlock->Flags & 0xF) >= 1 &&
+ (infoBlock->Flags & 0xF) <= 3) {
+ self.notDeleted = NO;
+ } else
+ self.notDeleted = NO;
+ } else if ((infoBlock->Flags & 0xF0) == 0x50)
+ self.notDeleted = YES;
+ else
+ self.notDeleted = NO;
+
+ }
+ return self;
+}
+
@synthesize englishName;
@synthesize sjisName;
@synthesize memImage;
@synthesize notDeleted;
-@synthesize memNumber;
@synthesize memFlags;
+@synthesize memName;
+@synthesize memID;
+@synthesize memIconCount;
- (void)dealloc
{
[englishName release];
[sjisName release];
+ [memName release];
+ [memID release];
[memImage release];
[super dealloc];
}
+- (NSString *)description
+{
+ return [NSString stringWithFormat:@"%@ (%@): Name: %@ ID: %@ Flags: %d", englishName, sjisName, memName, memID, memFlags];
+}
+
@end