1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
//
// PcsxrMemCardManager.m
// Pcsxr
//
// Created by Charles Betts on 11/23/11.
// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//
#import "PcsxrMemCardController.h"
#import "PcsxrMemoryObject.h"
#include "sio.h"
#define MAX_MEMCARD_BLOCKS 15
static inline 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];
[theImage setScalesWhenResized:YES];
[theImage setSize:NSMakeSize(32, 32)];
[imageRep release];
return [theImage autorelease];
}
@implementation PcsxrMemCardController
//memCard1Array KVO functions
-(void)insertObject:(PcsxrMemoryObject *)p inMemCard1ArrayAtIndex:(NSUInteger)index {
[memCard1Array insertObject:p atIndex:index];
}
-(void)removeObjectFromMemCard1ArrayAtIndex:(NSUInteger)index {
[memCard1Array removeObjectAtIndex:index];
}
- (void)setMemCard1Array:(NSMutableArray *)a
{
if (memCard1Array != a) {
[memCard1Array release];
memCard1Array = [[NSMutableArray alloc] initWithArray:a];
}
}
- (NSArray *)memCard1Array
{
return memCard1Array;
}
//memCard2Array KVO functions
-(void)insertObject:(PcsxrMemoryObject *)p inMemCard2ArrayAtIndex:(NSUInteger)index {
[memCard2Array insertObject:p atIndex:index];
}
-(void)removeObjectFromMemCard2ArrayAtIndex:(NSUInteger)index {
[memCard2Array removeObjectAtIndex:index];
}
- (void)setMemCard2Array:(NSMutableArray *)a
{
if (memCard2Array != a) {
[memCard2Array release];
memCard2Array = [[NSMutableArray alloc] initWithArray:a];
}
}
- (NSArray *)memCard2Array
{
return memCard2Array;
}
- (id)init
{
self = [self initWithWindowNibName:@"MemCardManager"];
return self;
}
- (id)initWithWindow:(NSWindow *)window
{
self = [super initWithWindow:window];
if (self) {
LoadMcds(Config.Mcd1, Config.Mcd2);
[self setMemCard1Array:[[NSMutableArray alloc] initWithCapacity:MAX_MEMCARD_BLOCKS]];
[self setMemCard2Array:[[NSMutableArray alloc] initWithCapacity:MAX_MEMCARD_BLOCKS]];
}
return self;
}
- (void)loadMemoryCardInfoForCard:(int)theCard
{
NSInteger i;
McdBlock info;
NSMutableArray *newArray = [[NSMutableArray alloc] initWithCapacity:MAX_MEMCARD_BLOCKS];
for (i = 0; i < MAX_MEMCARD_BLOCKS; i++) {
GetMcdBlockInfo(theCard, i, &info);
PcsxrMemoryObject *ob = [[PcsxrMemoryObject alloc] init];
NSString *engDes = nil, *japDes = nil;
ob.englishName = [NSString stringWithCString:info.Title encoding:NSASCIIStringEncoding];
ob.sjisName = [NSString stringWithCString:info.sTitle encoding:NSShiftJISStringEncoding];
ob.memImage = imageFromMcd(info.Icon);
ob.memNumber = i;
[newArray insertObject:ob atIndex:i];
[ob release];
}
if (theCard == 1) {
[self setMemCard1Array:newArray];
} else {
[self setMemCard2Array:newArray];
}
[newArray release];
}
- (void)windowDidLoad
{
[super windowDidLoad];
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
[self loadMemoryCardInfoForCard:1];
[self loadMemoryCardInfoForCard:2];
}
- (IBAction)moveToLeft:(id)sender
{
}
- (IBAction)moveToRight:(id)sender
{
}
- (IBAction)formatCard:(id)sender
{
NSInteger formatOkay = NSRunAlertPanel(NSLocalizedString(@"Format Card", nil), NSLocalizedString(@"Formatting a memory card will remove all data on it.\n\nThis cannot be undone.", nil), NSLocalizedString(@"Cancel", nil), NSLocalizedString(@"Format", nil), nil);
if (formatOkay == NSAlertAlternateReturn) {
NSInteger memCardSelect = [sender tag];
if (memCardSelect == 1) {
CreateMcd(Config.Mcd1);
[self loadMemoryCardInfoForCard:1];
} else {
CreateMcd(Config.Mcd2);
[self loadMemoryCardInfoForCard:2];
}
}
}
- (IBAction)deleteMemoryObject:(id)sender {
NSInteger deleteOkay = NSRunAlertPanel(NSLocalizedString(@"Delete Block", nil), NSLocalizedString(@"Deleting a block will remove all saved data on that block.\n\nThis cannot be undone.", nil), NSLocalizedString(@"Cancel", nil), NSLocalizedString(@"Delete", nil), nil);
if (deleteOkay == NSAlertAlternateReturn) {
NSInteger memCardSelect = [sender tag];
if (memCardSelect == 1) {
[self loadMemoryCardInfoForCard:1];
} else {
[self loadMemoryCardInfoForCard:2];
}
}
}
@end
|