-
Notifications
You must be signed in to change notification settings - Fork 8
/
GBGameCore.mm
648 lines (546 loc) · 21.4 KB
/
GBGameCore.mm
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
/*
Copyright (c) 2015, OpenEmu Team
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the OpenEmu Team nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#import "GBGameCore.h"
#import <OpenEmuBase/OERingBuffer.h>
#import "OEGBSystemResponderClient.h"
#import <OpenGL/gl.h>
#include <sstream>
#include "gambatte.h"
#include "gbcpalettes.h"
#include "resamplerinfo.h"
#include "resampler.h"
#define OptionDefault(_NAME_, _PREFKEY_) @{ OEGameCoreDisplayModeNameKey : _NAME_, OEGameCoreDisplayModePrefKeyNameKey : _PREFKEY_, OEGameCoreDisplayModeStateKey : @YES, }
#define Option(_NAME_, _PREFKEY_) @{ OEGameCoreDisplayModeNameKey : _NAME_, OEGameCoreDisplayModePrefKeyNameKey : _PREFKEY_, OEGameCoreDisplayModeStateKey : @NO, }
#define OptionIndented(_NAME_, _PREFKEY_) @{ OEGameCoreDisplayModeNameKey : _NAME_, OEGameCoreDisplayModePrefKeyNameKey : _PREFKEY_, OEGameCoreDisplayModeStateKey : @NO, OEGameCoreDisplayModeIndentationLevelKey : @(1), }
#define OptionToggleable(_NAME_, _PREFKEY_) @{ OEGameCoreDisplayModeNameKey : _NAME_, OEGameCoreDisplayModePrefKeyNameKey : _PREFKEY_, OEGameCoreDisplayModeStateKey : @NO, OEGameCoreDisplayModeAllowsToggleKey : @YES, }
#define OptionToggleableNoSave(_NAME_, _PREFKEY_) @{ OEGameCoreDisplayModeNameKey : _NAME_, OEGameCoreDisplayModePrefKeyNameKey : _PREFKEY_, OEGameCoreDisplayModeStateKey : @NO, OEGameCoreDisplayModeAllowsToggleKey : @YES, OEGameCoreDisplayModeDisallowPrefSaveKey : @YES, }
#define Label(_NAME_) @{ OEGameCoreDisplayModeLabelKey : _NAME_, }
#define SeparatorItem() @{ OEGameCoreDisplayModeSeparatorItemKey : @"",}
gambatte::GB gb;
Resampler *resampler;
uint32_t pad[OEGBButtonCount];
class GetInput : public gambatte::InputGetter
{
public:
unsigned operator()()
{
return pad[0];
}
} static GetInput;
@interface GBGameCore () <OEGBSystemResponderClient>
{
uint32_t *_videoBuffer;
uint32_t *_inSoundBuffer;
int16_t *_outSoundBuffer;
double _sampleRate;
NSMutableDictionary <NSString *, NSNumber *> *_cheatList;
NSMutableArray <NSMutableDictionary <NSString *, id> *> *_availableDisplayModes;
}
- (void)applyCheat:(NSString *)code;
- (void)loadDisplayModeOptions;
- (NSString *)gameInternalName;
- (BOOL)gameHasInternalPalette;
- (void)loadPalette;
- (void)loadPaletteDefault;
- (void)changePalette:(NSString *)palette;
@end
@implementation GBGameCore
- (id)init
{
if((self = [super init]))
{
_inSoundBuffer = (uint32_t *)malloc(2064 * 2 * 4);
_outSoundBuffer = (int16_t *)malloc(2064 * 2 * 2);
_cheatList = [NSMutableDictionary dictionary];
}
return self;
}
- (void)dealloc
{
free(_videoBuffer);
free(_inSoundBuffer);
free(_outSoundBuffer);
}
# pragma mark - Execution
- (BOOL)loadFileAtPath:(NSString *)path error:(NSError **)error
{
memset(pad, 0, sizeof(pad));
// Set battery save dir
NSURL *batterySavesDirectory = [NSURL fileURLWithPath:self.batterySavesDirectoryPath];
[[NSFileManager defaultManager] createDirectoryAtURL:batterySavesDirectory withIntermediateDirectories:YES attributes:nil error:nil];
gb.setSaveDir(batterySavesDirectory.fileSystemRepresentation);
// Set input state callback
gb.setInputGetter(&GetInput);
// Setup resampler
double fps = 4194304.0 / 70224.0;
double inSampleRate = fps * 35112; // 2097152
// 2 = "Very high quality (polyphase FIR)", see resamplerinfo.cpp
resampler = ResamplerInfo::get(2).create(inSampleRate, 48000.0, 2 * 2064);
unsigned long mul, div;
resampler->exactRatio(mul, div);
double outSampleRate = inSampleRate * mul / div;
_sampleRate = outSampleRate; // 47994.326636
if (gb.load(path.fileSystemRepresentation) != 0)
return NO;
[self loadDisplayModeOptions];
return YES;
}
- (void)executeFrame
{
size_t samples = 2064;
while (gb.runFor(_videoBuffer, 160, _inSoundBuffer, samples) == -1) {
[self outputAudio:samples];
samples = 2064;
}
[self outputAudio:samples];
}
- (void)resetEmulation
{
gb.reset();
}
- (void)stopEmulation
{
gb.saveSavedata();
delete resampler;
[super stopEmulation];
}
- (NSTimeInterval)frameInterval
{
return 59.727501;
}
# pragma mark - Video
- (const void *)getVideoBufferWithHint:(void *)hint
{
if (!hint) {
if (!_videoBuffer) _videoBuffer = (uint32_t *)malloc(160 * 144 * 4);
hint = _videoBuffer;
}
return _videoBuffer = (uint32_t*)hint;
}
- (OEIntRect)screenRect
{
return OEIntRectMake(0, 0, 160, 144);
}
- (OEIntSize)bufferSize
{
return OEIntSizeMake(160, 144);
}
- (OEIntSize)aspectSize
{
return OEIntSizeMake(10, 9);
}
- (GLenum)pixelFormat
{
return GL_BGRA;
}
- (GLenum)pixelType
{
return GL_UNSIGNED_INT_8_8_8_8_REV;
}
# pragma mark - Audio
- (double)audioSampleRate
{
return _sampleRate;
}
- (NSUInteger)channelCount
{
return 2;
}
# pragma mark - Save States
- (void)saveStateToFileAtPath:(NSString *)fileName completionHandler:(void (^)(BOOL, NSError *))block
{
int success = gb.saveState(0, 0, fileName.fileSystemRepresentation);
if(block) block(success==1, nil);
}
- (void)loadStateFromFileAtPath:(NSString *)fileName completionHandler:(void (^)(BOOL, NSError *))block
{
int success = gb.loadState(fileName.fileSystemRepresentation);
if(block) block(success==1, nil);
}
- (NSData *)serializeStateWithError:(NSError **)outError
{
std::stringstream stream(std::ios::in|std::ios::out|std::ios::binary);
if(gb.serializeState(stream)) {
stream.seekg(0, std::ios::end);
NSUInteger length = stream.tellg();
stream.seekg(0, std::ios::beg);
char *bytes = (char *)malloc(length);
stream.read(bytes, length);
return [NSData dataWithBytesNoCopy:bytes length:length];
}
if(outError) {
*outError = [NSError errorWithDomain:OEGameCoreErrorDomain code:OEGameCoreCouldNotSaveStateError userInfo:@{
NSLocalizedDescriptionKey : @"Save state data could not be written",
NSLocalizedRecoverySuggestionErrorKey : @"The emulator could not write the state data."
}];
}
return nil;
}
- (BOOL)deserializeState:(NSData *)state withError:(NSError **)outError
{
std::stringstream stream(std::ios::in|std::ios::out|std::ios::binary);
char const *bytes = (char const *)(state.bytes);
std::streamsize size = state.length;
stream.write(bytes, size);
if(gb.deserializeState(stream))
return YES;
if(outError) {
*outError = [NSError errorWithDomain:OEGameCoreErrorDomain code:OEGameCoreCouldNotLoadStateError userInfo:@{
NSLocalizedDescriptionKey : @"The save state data could not be read",
NSLocalizedRecoverySuggestionErrorKey : @"Could not load data from the save state"
}];
}
return NO;
}
# pragma mark - Input
const int GBMap[] = {gambatte::InputGetter::UP, gambatte::InputGetter::DOWN, gambatte::InputGetter::LEFT, gambatte::InputGetter::RIGHT, gambatte::InputGetter::A, gambatte::InputGetter::B, gambatte::InputGetter::START, gambatte::InputGetter::SELECT};
- (oneway void)didPushGBButton:(OEGBButton)button;
{
pad[0] |= GBMap[button];
}
- (oneway void)didReleaseGBButton:(OEGBButton)button;
{
pad[0] &= ~GBMap[button];
}
#pragma mark - Cheats
- (void)setCheat:(NSString *)code setType:(NSString *)type setEnabled:(BOOL)enabled
{
// Sanitize
code = [code stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];
// Gambatte expects cheats UPPERCASE
code = code.uppercaseString;
// Remove any spaces
code = [code stringByReplacingOccurrencesOfString:@" " withString:@""];
if (enabled)
_cheatList[code] = @YES;
else
[_cheatList removeObjectForKey:code];
NSMutableArray <NSString *> *combinedGameSharkCodes = [NSMutableArray array];
NSMutableArray <NSString *> *combinedGameGenieCodes = [NSMutableArray array];
// Gambatte expects all cheats in one combined string per-type e.g. 01xxxxxx+01xxxxxx
// Add enabled per-type cheats to arrays and later join them all by a '+' separator
for (NSString *key in _cheatList)
{
if ([_cheatList[key] boolValue])
{
// GameShark
if (![key containsString:@"-"])
[combinedGameSharkCodes addObject:key];
// Game Genie
else if ([key containsString:@"-"])
[combinedGameGenieCodes addObject:key];
}
}
// Apply combined cheats or force a final reset if all cheats are disabled
[self applyCheat:combinedGameSharkCodes.count != 0 ? [combinedGameSharkCodes componentsJoinedByString:@"+"] : @"0"];
[self applyCheat:combinedGameGenieCodes.count != 0 ? [combinedGameGenieCodes componentsJoinedByString:@"+"] : @"0-"];
}
# pragma mark - Display Mode
- (NSArray <NSDictionary <NSString *, id> *> *)displayModes
{
if (_availableDisplayModes.count == 0)
{
_availableDisplayModes = [NSMutableArray array];
NSArray <NSDictionary <NSString *, id> *> *availableModesWithDefault;
if (gb.isCgb())
{
availableModesWithDefault =
@[
Label(@"Color Correction"),
OptionDefault(@"Default", @"colorCorrection"),
Option(@"Modern", @"colorCorrection"),
];
}
else
{
availableModesWithDefault =
@[
Option(@"Internal", @"palette"),
Option(@"Grayscale", @"palette"),
Option(@"Greenscale", @"palette"),
Option(@"Pocket", @"palette"),
SeparatorItem(),
Label(@"GBC Palettes"),
Option(@"Blue", @"palette"),
Option(@"Dark Blue", @"palette"),
Option(@"Green", @"palette"),
Option(@"Dark Green", @"palette"),
Option(@"Brown", @"palette"),
Option(@"Dark Brown", @"palette"),
Option(@"Red", @"palette"),
Option(@"Yellow", @"palette"),
Option(@"Orange", @"palette"),
Option(@"Pastel Mix", @"palette"),
Option(@"Inverted", @"palette"),
];
}
// Deep mutable copy
_availableDisplayModes = (NSMutableArray *)CFBridgingRelease(CFPropertyListCreateDeepCopy(kCFAllocatorDefault, (CFArrayRef)availableModesWithDefault, kCFPropertyListMutableContainers));
if (!gb.isCgb() && ![self gameHasInternalPalette])
[_availableDisplayModes removeObjectAtIndex:0];
}
return [_availableDisplayModes copy];
}
- (void)changeDisplayWithMode:(NSString *)displayMode
{
// NOTE: This is a more complex implementation to serve as an example for handling submenus,
// toggleable options and multiple groups of mutually exclusive options.
if (_availableDisplayModes.count == 0)
[self displayModes];
// First check if 'displayMode' is toggleable and grab its preference key
BOOL isDisplayModeToggleable = NO;
BOOL isValidDisplayMode = NO;
BOOL displayModeState = NO;
NSString *displayModePrefKey;
for (NSDictionary *modeDict in _availableDisplayModes)
{
if ([modeDict[OEGameCoreDisplayModeNameKey] isEqualToString:displayMode])
{
displayModeState = [modeDict[OEGameCoreDisplayModeStateKey] boolValue];
displayModePrefKey = modeDict[OEGameCoreDisplayModePrefKeyNameKey];
isDisplayModeToggleable = [modeDict[OEGameCoreDisplayModeAllowsToggleKey] boolValue];
isValidDisplayMode = YES;
break;
}
// Submenu Items
for (NSDictionary *subModeDict in modeDict[OEGameCoreDisplayModeGroupItemsKey])
{
if ([subModeDict[OEGameCoreDisplayModeNameKey] isEqualToString:displayMode])
{
displayModeState = [subModeDict[OEGameCoreDisplayModeStateKey] boolValue];
displayModePrefKey = subModeDict[OEGameCoreDisplayModePrefKeyNameKey];
isDisplayModeToggleable = [subModeDict[OEGameCoreDisplayModeAllowsToggleKey] boolValue];
isValidDisplayMode = YES;
break;
}
}
}
// Disallow a 'displayMode' not found in _availableDisplayModes
if (!isValidDisplayMode)
return;
// Handle option state changes
for (NSMutableDictionary *optionDict in _availableDisplayModes)
{
NSString *modeName = optionDict[OEGameCoreDisplayModeNameKey];
NSString *prefKey = optionDict[OEGameCoreDisplayModePrefKeyNameKey];
if (!modeName && !optionDict[OEGameCoreDisplayModeGroupNameKey])
continue;
// Mutually exclusive option state change
else if ([modeName isEqualToString:displayMode] && !isDisplayModeToggleable)
optionDict[OEGameCoreDisplayModeStateKey] = @YES;
// Reset mutually exclusive options that are the same prefs group as 'displayMode'
else if (!isDisplayModeToggleable && [prefKey isEqualToString:displayModePrefKey])
optionDict[OEGameCoreDisplayModeStateKey] = @NO;
// Toggleable option state change
else if ([modeName isEqualToString:displayMode] && isDisplayModeToggleable)
optionDict[OEGameCoreDisplayModeStateKey] = @(!displayModeState);
// Submenu group
else if (optionDict[OEGameCoreDisplayModeGroupNameKey])
{
// Submenu items
for (NSMutableDictionary *subOptionDict in optionDict[OEGameCoreDisplayModeGroupItemsKey])
{
NSString *modeName = subOptionDict[OEGameCoreDisplayModeNameKey];
NSString *prefKey = subOptionDict[OEGameCoreDisplayModePrefKeyNameKey];
if (!modeName)
continue;
// Mutually exclusive option state change
else if ([modeName isEqualToString:displayMode] && !isDisplayModeToggleable)
subOptionDict[OEGameCoreDisplayModeStateKey] = @YES;
// Reset mutually exclusive options that are the same prefs group as 'displayMode'
else if (!isDisplayModeToggleable && [prefKey isEqualToString:displayModePrefKey])
subOptionDict[OEGameCoreDisplayModeStateKey] = @NO;
// Toggleable option state change
else if ([modeName isEqualToString:displayMode] && isDisplayModeToggleable)
subOptionDict[OEGameCoreDisplayModeStateKey] = @(!displayModeState);
}
continue;
}
}
// Set the new palette
if ([displayModePrefKey isEqualToString:@"palette"])
[self changePalette:displayMode];
else if ([displayModePrefKey isEqualToString:@"colorCorrection"])
gb.setCgbColorCorrection([displayMode isEqual:@"Modern"] ? 1 : 0);
}
# pragma mark - Misc Helper Methods
- (void)outputAudio:(size_t)frames
{
if (!frames)
return;
size_t len = resampler->resample(_outSoundBuffer, reinterpret_cast<const int16_t *>(_inSoundBuffer), frames);
if (len)
[[self audioBufferAtIndex:0] write:_outSoundBuffer maxLength:len << 2];
}
- (void)applyCheat:(NSString *)code
{
std::string s = [code UTF8String];
if (s.find("-") != std::string::npos)
gb.setGameGenie(s);
else
gb.setGameShark(s);
}
- (void)loadDisplayModeOptions
{
if (gb.isCgb())
{
// Restore color correction
NSString *lastColorCorrection = self.displayModeInfo[@"colorCorrection"] ?: @"Default";
[self changeDisplayWithMode:lastColorCorrection];
}
else
{
// Load built-in GBC palette for monochrome games if supported
[self loadPalette];
}
}
- (NSString *)gameInternalName
{
NSString *title = [NSString stringWithUTF8String:gb.romTitle().c_str()];
return title;
}
- (BOOL)gameHasInternalPalette
{
unsigned short *gbc_bios_palette = NULL;
NSString *title = [self gameInternalName];
gbc_bios_palette = const_cast<unsigned short *>(findGbcTitlePal(title.UTF8String));
return gbc_bios_palette != 0 ? YES : NO;
}
- (void)loadPalette
{
// Only temporary, so core doesn't crash on an older OpenEmu version
if (![self respondsToSelector:@selector(displayModeInfo)])
{
[self loadPaletteDefault];
}
// No previous palette saved, set a default
else if (self.displayModeInfo[@"palette"] == nil)
{
[self loadPaletteDefault];
}
else
{
NSString *lastPalette = self.displayModeInfo[@"palette"];
// Don't try to load "Internal" palette for a game without one
if ([lastPalette isEqualToString:@"Internal"] && ![self gameHasInternalPalette])
[self changeDisplayWithMode:@"Grayscale"];
else
[self changeDisplayWithMode:lastPalette];
}
}
- (void)loadPaletteDefault
{
if ([self gameHasInternalPalette])
// load a GBC BIOS builtin palette
[self changeDisplayWithMode:@"Internal"];
else
// no custom palette found, load the default (Original Grayscale)
[self changeDisplayWithMode:@"Grayscale"];
}
- (void)changePalette:(NSString *)palette
{
NSDictionary <NSString *, NSString *> *paletteNames =
@{
@"Internal" : @"Internal",
@"Grayscale" : @"GBC - Grayscale",
@"Greenscale" : @"Greenscale",
@"Pocket" : @"Pocket",
@"Blue" : @"GBC - Blue",
@"Dark Blue" : @"GBC - Dark Blue",
@"Green" : @"GBC - Green",
@"Dark Green" : @"GBC - Dark Green",
@"Brown" : @"GBC - Brown",
@"Dark Brown" : @"GBC - Dark Brown",
@"Red" : @"GBC - Red",
@"Yellow" : @"GBC - Yellow",
@"Orange" : @"GBC - Orange",
@"Pastel Mix" : @"GBC - Pastel Mix",
@"Inverted" : @"GBC - Inverted",
};
palette = paletteNames[palette];
unsigned short *gbc_bios_palette = NULL;
if ([palette isEqualToString:@"Internal"])
{
NSString *title = [self gameInternalName];
gbc_bios_palette = const_cast<unsigned short *>(findGbcTitlePal(title.UTF8String));
}
else if ([palette isEqualToString:@"Greenscale"])
{
// GB Pea Soup Green
gb.setDmgPaletteColor(0, 0, 8369468);
gb.setDmgPaletteColor(0, 1, 6728764);
gb.setDmgPaletteColor(0, 2, 3629872);
gb.setDmgPaletteColor(0, 3, 3223857);
gb.setDmgPaletteColor(1, 0, 8369468);
gb.setDmgPaletteColor(1, 1, 6728764);
gb.setDmgPaletteColor(1, 2, 3629872);
gb.setDmgPaletteColor(1, 3, 3223857);
gb.setDmgPaletteColor(2, 0, 8369468);
gb.setDmgPaletteColor(2, 1, 6728764);
gb.setDmgPaletteColor(2, 2, 3629872);
gb.setDmgPaletteColor(2, 3, 3223857);
return;
}
else if ([palette isEqualToString:@"Pocket"])
{
// GB Pocket
gb.setDmgPaletteColor(0, 0, 13487791);
gb.setDmgPaletteColor(0, 1, 10987158);
gb.setDmgPaletteColor(0, 2, 6974033);
gb.setDmgPaletteColor(0, 3, 2828823);
gb.setDmgPaletteColor(1, 0, 13487791);
gb.setDmgPaletteColor(1, 1, 10987158);
gb.setDmgPaletteColor(1, 2, 6974033);
gb.setDmgPaletteColor(1, 3, 2828823);
gb.setDmgPaletteColor(2, 0, 13487791);
gb.setDmgPaletteColor(2, 1, 10987158);
gb.setDmgPaletteColor(2, 2, 6974033);
gb.setDmgPaletteColor(2, 3, 2828823);
// gb.setDmgPaletteColor(0, 0, 13029285);
// gb.setDmgPaletteColor(0, 1, 9213547);
// gb.setDmgPaletteColor(0, 2, 4870457);
// gb.setDmgPaletteColor(0, 3, 1580056);
// gb.setDmgPaletteColor(1, 0, 13029285);
// gb.setDmgPaletteColor(1, 1, 9213547);
// gb.setDmgPaletteColor(1, 2, 4870457);
// gb.setDmgPaletteColor(1, 3, 1580056);
// gb.setDmgPaletteColor(2, 0, 13029285);
// gb.setDmgPaletteColor(2, 1, 9213547);
// gb.setDmgPaletteColor(2, 2, 4870457);
// gb.setDmgPaletteColor(2, 3, 1580056);
return;
}
else
gbc_bios_palette = const_cast<unsigned short *>(findGbcDirPal(palette.UTF8String));
unsigned long rgb32 = 0;
for (unsigned palnum = 0; palnum < 3; ++palnum)
{
for (unsigned colornum = 0; colornum < 4; ++colornum)
{
rgb32 = gbcToRgb32(gbc_bios_palette[palnum * 4 + colornum]);
gb.setDmgPaletteColor(palnum, colornum, rgb32);
}
}
}
@end