-
Notifications
You must be signed in to change notification settings - Fork 22
/
MupenGameCore.m
634 lines (523 loc) · 19.1 KB
/
MupenGameCore.m
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
/*
Copyright (c) 2010, 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.
*/
// We need to mess with core internals
#define M64P_CORE_PROTOTYPES 1
#import "MupenGameCore.h"
#import "api/config.h"
#import "api/m64p_common.h"
#import "api/m64p_config.h"
#import "api/m64p_frontend.h"
#import "api/m64p_vidext.h"
#import "api/callbacks.h"
#import "rom.h"
#import "savestates.h"
#import "osal/dynamiclib.h"
#import "version.h"
#import "memory.h"
#import "main.h"
#import <OpenEmuBase/OERingBuffer.h>
#import <OpenEmuBase/OETimingUtils.h>
#import <OpenGL/gl.h>
#import "plugin.h"
#import <dlfcn.h>
NSString *MupenControlNames[] = {
@"N64_DPadU", @"N64_DPadD", @"N64_DPadL", @"N64_DPadR",
@"N64_CU", @"N64_CD", @"N64_CL", @"N64_CR",
@"N64_B", @"N64_A", @"N64_R", @"N64_L", @"N64_Z", @"N64_Start"
}; // FIXME: missing: joypad X, joypad Y, mempak switch, rumble switch
@interface MupenGameCore () <OEN64SystemResponderClient>
- (void)OE_didReceiveStateChangeForParamType:(m64p_core_param)paramType value:(int)newValue;
@end
__weak MupenGameCore *_current = 0;
static void (*ptr_OE_ForceUpdateWindowSize)(int width, int height);
static void MupenDebugCallback(void *context, int level, const char *message)
{
if (level >= 5) return;
NSLog(@"Mupen (%d): %s", level, message);
}
static void MupenStateCallback(void *context, m64p_core_param paramType, int newValue)
{
NSLog(@"Mupen: param %d -> %d", paramType, newValue);
[((__bridge MupenGameCore *)context) OE_didReceiveStateChangeForParamType:paramType value:newValue];
}
@implementation MupenGameCore
{
NSData *romData;
m64p_emu_state _emulatorState;
dispatch_queue_t _callbackQueue;
NSMutableDictionary *_callbackHandlers;
}
- (instancetype)init
{
if (self = [super init]) {
videoWidth = 640;
videoHeight = 480;
videoBitDepth = 32; // ignored
videoDepthBitDepth = 0; // TODO
sampleRate = 33600;
isNTSC = YES;
_callbackQueue = dispatch_queue_create("org.openemu.MupenGameCore.CallbackHandlerQueue", DISPATCH_QUEUE_SERIAL);
_callbackHandlers = [[NSMutableDictionary alloc] init];
}
_current = self;
return self;
}
- (void)dealloc
{
SetStateCallback(NULL, NULL);
SetDebugCallback(NULL, NULL);
}
// Pass 0 as paramType to receive all state changes.
// Return YES from the block to keep watching the changes.
// Return NO to remove the block after the first received callback.
- (void)OE_addHandlerForType:(m64p_core_param)paramType usingBlock:(BOOL(^)(m64p_core_param paramType, int newValue))block
{
// If we already have an emulator state, check if the block is satisfied with it or just add it to the queues.
if(paramType == M64CORE_EMU_STATE && _emulatorState != 0 && !block(M64CORE_EMU_STATE, _emulatorState))
return;
dispatch_async(_callbackQueue, ^{
NSMutableSet *callbacks = _callbackHandlers[@(paramType)];
if(callbacks == nil)
{
callbacks = [[NSMutableSet alloc] init];
_callbackHandlers[@(paramType)] = callbacks;
}
[callbacks addObject:block];
});
}
- (void)OE_didReceiveStateChangeForParamType:(m64p_core_param)paramType value:(int)newValue
{
if(paramType == M64CORE_EMU_STATE) _emulatorState = newValue;
void(^runCallbacksForType)(m64p_core_param) =
^(m64p_core_param type){
NSMutableSet *callbacks = _callbackHandlers[@(type)];
[callbacks filterUsingPredicate:
[NSPredicate predicateWithBlock:
^ BOOL (BOOL(^evaluatedObject)(m64p_core_param, int), NSDictionary *bindings)
{
return evaluatedObject(paramType, newValue);
}]];
};
dispatch_async(_callbackQueue, ^{
runCallbacksForType(paramType);
runCallbacksForType(0);
});
}
static void *dlopen_myself()
{
Dl_info info;
dladdr(dlopen_myself, &info);
return dlopen(info.dli_fname, 0);
}
static void MupenGetKeys(int Control, BUTTONS *Keys)
{
GET_CURRENT_OR_RETURN();
Keys->R_DPAD = current->padData[Control][OEN64ButtonDPadRight];
Keys->L_DPAD = current->padData[Control][OEN64ButtonDPadLeft];
Keys->D_DPAD = current->padData[Control][OEN64ButtonDPadDown];
Keys->U_DPAD = current->padData[Control][OEN64ButtonDPadUp];
Keys->START_BUTTON = current->padData[Control][OEN64ButtonStart];
Keys->Z_TRIG = current->padData[Control][OEN64ButtonZ];
Keys->B_BUTTON = current->padData[Control][OEN64ButtonB];
Keys->A_BUTTON = current->padData[Control][OEN64ButtonA];
Keys->R_CBUTTON = current->padData[Control][OEN64ButtonCRight];
Keys->L_CBUTTON = current->padData[Control][OEN64ButtonCLeft];
Keys->D_CBUTTON = current->padData[Control][OEN64ButtonCDown];
Keys->U_CBUTTON = current->padData[Control][OEN64ButtonCUp];
Keys->R_TRIG = current->padData[Control][OEN64ButtonR];
Keys->L_TRIG = current->padData[Control][OEN64ButtonL];
Keys->X_AXIS = current->xAxis[Control];
Keys->Y_AXIS = current->yAxis[Control];
}
static void MupenInitiateControllers (CONTROL_INFO ControlInfo)
{
ControlInfo.Controls[0].Present = 1;
ControlInfo.Controls[0].Plugin = PLUGIN_MEMPAK;
ControlInfo.Controls[1].Present = 1;
ControlInfo.Controls[1].Plugin = PLUGIN_MEMPAK;
ControlInfo.Controls[2].Present = 1;
ControlInfo.Controls[2].Plugin = PLUGIN_MEMPAK;
ControlInfo.Controls[3].Present = 1;
ControlInfo.Controls[3].Plugin = PLUGIN_NONE;
}
static AUDIO_INFO AudioInfo;
static void MupenAudioSampleRateChanged(int SystemType)
{
GET_CURRENT_OR_RETURN();
float currentRate = current->sampleRate;
switch (SystemType)
{
default:
case SYSTEM_NTSC:
current->sampleRate = 48681812 / (*AudioInfo.AI_DACRATE_REG + 1);
break;
case SYSTEM_PAL:
current->sampleRate = 49656530 / (*AudioInfo.AI_DACRATE_REG + 1);
break;
}
[[current audioDelegate] audioSampleRateDidChange];
NSLog(@"Mupen rate changed %f -> %f\n", currentRate, current->sampleRate);
}
static void MupenAudioLenChanged()
{
GET_CURRENT_OR_RETURN();
int LenReg = *AudioInfo.AI_LEN_REG;
uint8_t *ptr = (uint8_t*)(AudioInfo.RDRAM + (*AudioInfo.AI_DRAM_ADDR_REG & 0xFFFFFF));
// Swap channels
for (uint32_t i = 0; i < LenReg; i += 4)
{
ptr[i] ^= ptr[i + 2];
ptr[i + 2] ^= ptr[i];
ptr[i] ^= ptr[i + 2];
ptr[i + 1] ^= ptr[i + 3];
ptr[i + 3] ^= ptr[i + 1];
ptr[i + 1] ^= ptr[i + 3];
}
[[current ringBufferAtIndex:0] write:ptr maxLength:LenReg];
}
static void SetIsNTSC()
{
GET_CURRENT_OR_RETURN();
extern m64p_rom_header ROM_HEADER;
switch (ROM_HEADER.Country_code&0xFF)
{
case 0x44:
case 0x46:
case 0x49:
case 0x50:
case 0x53:
case 0x55:
case 0x58:
case 0x59:
current->isNTSC = NO;
break;
case 0x37:
case 0x41:
case 0x45:
case 0x4a:
current->isNTSC = YES;
break;
}
}
static int MupenOpenAudio(AUDIO_INFO info)
{
AudioInfo = info;
SetIsNTSC();
return M64ERR_SUCCESS;
}
static void MupenSetAudioSpeed(int percent)
{
// do we need this?
}
- (BOOL)loadFileAtPath:(NSString *)path error:(NSError **)error
{
// Load ROM
romData = [NSData dataWithContentsOfFile:path options:NSDataReadingMappedIfSafe error:error];
if (romData == nil) return NO;
NSBundle *coreBundle = [NSBundle bundleForClass:[self class]];
const char *dataPath;
NSString *configPath = [[self supportDirectoryPath] stringByAppendingString:@"/"];
dataPath = [[coreBundle resourcePath] fileSystemRepresentation];
[[NSFileManager defaultManager] createDirectoryAtPath:configPath withIntermediateDirectories:YES attributes:nil error:nil];
NSString *batterySavesDirectory = [self batterySavesDirectoryPath];
[[NSFileManager defaultManager] createDirectoryAtPath:batterySavesDirectory withIntermediateDirectories:YES attributes:nil error:NULL];
// open core here
CoreStartup(FRONTEND_API_VERSION, [configPath fileSystemRepresentation], dataPath, (__bridge void *)self, MupenDebugCallback, (__bridge void *)self, MupenStateCallback);
// set SRAM path
m64p_handle config;
ConfigOpenSection("Core", &config);
ConfigSetParameter(config, "SaveSRAMPath", M64TYPE_STRING, [batterySavesDirectory UTF8String]);
ConfigSetParameter(config, "SharedDataPath", M64TYPE_STRING, dataPath);
ConfigSaveSection("Core");
// Disable dynarec (for debugging)
m64p_handle section;
#ifdef DEBUG
int ival = 0;
#else
int ival = 2;
#endif
ConfigOpenSection("Core", §ion);
ConfigSetParameter(section, "R4300Emulator", M64TYPE_INT, &ival);
if (CoreDoCommand(M64CMD_ROM_OPEN, (int)[romData length], (void *)[romData bytes]) != M64ERR_SUCCESS)
return NO;
return YES;
}
- (void)setupEmulation
{
NSBundle *coreBundle = [NSBundle bundleForClass:[self class]];
m64p_dynlib_handle core_handle = dlopen_myself();
void (^LoadPlugin)(m64p_plugin_type, NSString *) = ^(m64p_plugin_type pluginType, NSString *pluginName){
m64p_dynlib_handle rsp_handle;
NSString *rspPath = [[coreBundle builtInPlugInsPath] stringByAppendingPathComponent:pluginName];
rsp_handle = dlopen([rspPath fileSystemRepresentation], RTLD_NOW);
ptr_PluginStartup rsp_start = osal_dynlib_getproc(rsp_handle, "PluginStartup");
rsp_start(core_handle, (__bridge void *)self, MupenDebugCallback);
CoreAttachPlugin(pluginType, rsp_handle);
};
// Load Video
LoadPlugin(M64PLUGIN_GFX, @"mupen64plus-video-rice.so");
//LoadPlugin(M64PLUGIN_GFX, @"mupen64plus-video-glide64.so");
//LoadPlugin(M64PLUGIN_GFX, @"mupen64plus-video-glide64mk2.so");
ptr_OE_ForceUpdateWindowSize = dlsym(RTLD_DEFAULT, "_OE_ForceUpdateWindowSize");
// Load Audio
audio.aiDacrateChanged = MupenAudioSampleRateChanged;
audio.aiLenChanged = MupenAudioLenChanged;
audio.initiateAudio = MupenOpenAudio;
audio.setSpeedFactor = MupenSetAudioSpeed;
plugin_start(M64PLUGIN_AUDIO);
// Load Input
input.getKeys = MupenGetKeys;
input.initiateControllers = MupenInitiateControllers;
plugin_start(M64PLUGIN_INPUT);
// Load RSP
//LoadPlugin(M64PLUGIN_RSP, @"mupen64plus-rsp-hle.so");
// Configure if using rsp-cxd4 plugin
m64p_handle configRSP;
ConfigOpenSection("rsp-cxd4", &configRSP);
int usingHLE = 1; // Set to 0 if using LLE GPU plugin/software rasterizer such as Angry Lion
ConfigSetParameter(configRSP, "DisplayListToGraphicsPlugin", M64TYPE_BOOL, &usingHLE);
LoadPlugin(M64PLUGIN_RSP, @"mupen64plus-rsp-cxd4.so");
}
- (void)startEmulation
{
[NSThread detachNewThreadSelector:@selector(runMupenEmuThread) toTarget:self withObject:nil];
[super startEmulation];
}
- (void)runMupenEmuThread
{
@autoreleasepool
{
OESetThreadRealtime(1. / 50, .007, .03); // guessed from bsnes
[self.renderDelegate willRenderFrameOnAlternateThread];
CoreDoCommand(M64CMD_EXECUTE, 0, NULL);
[super stopEmulation];
}
}
- (void)videoInterrupt
{
[self.renderDelegate willRenderFrameOnAlternateThread];
}
- (void)swapBuffers
{
[self.renderDelegate didRenderFrameOnAlternateThread];
}
- (void)executeFrame
{
// Do nothing
}
- (void)stopEmulation
{
CoreDoCommand(M64CMD_STOP, 0, NULL);
[super stopEmulation];
}
- (void)resetEmulation
{
// FIXME: do we want/need soft reset? It doesn’t seem to work well with sending M64CMD_RESET alone
// FIXME: might need to explicitly kick other thread
CoreDoCommand(M64CMD_RESET, 1 /* hard reset */, NULL);
}
- (void)saveStateToFileAtPath:(NSString *)fileName completionHandler:(void (^)(BOOL, NSError *))block
{
[self OE_addHandlerForType:M64CORE_STATE_SAVECOMPLETE usingBlock:
^ BOOL (m64p_core_param paramType, int newValue)
{
[self setRate:0];
NSAssert(paramType == M64CORE_STATE_SAVECOMPLETE, @"This block should only be called for save completion!");
dispatch_async(dispatch_get_main_queue(), ^{
if(newValue == 0)
{
NSError *error = [NSError errorWithDomain:OEGameCoreErrorDomain code:OEGameCoreCouldNotSaveStateError userInfo:@{
NSLocalizedDescriptionKey : @"Mupen Could not save the current state.",
NSFilePathErrorKey : fileName
}];
block(NO, error);
return;
}
block(YES, nil);
});
return NO;
}];
BOOL (^scheduleSaveState)(void) =
^ BOOL {
if(CoreDoCommand(M64CMD_STATE_SAVE, 1, (void *)[fileName fileSystemRepresentation]) == M64ERR_SUCCESS)
{
// Mupen needs to run for a bit for the state saving to take place.
[self setRate:1.0];
return YES;
}
return NO;
};
if(scheduleSaveState()) return;
[self OE_addHandlerForType:M64CORE_EMU_STATE usingBlock:
^ BOOL (m64p_core_param paramType, int newValue)
{
NSAssert(paramType == M64CORE_EMU_STATE, @"This block should only be called for load completion!");
if(newValue != M64EMU_RUNNING && newValue != M64EMU_PAUSED)
return YES;
return !scheduleSaveState();
}];
}
- (void)loadStateFromFileAtPath:(NSString *)fileName completionHandler:(void (^)(BOOL, NSError *))block
{
// FIXME: investigate why old method stopped working for some games (Mario 64), since this is ugly
if(!g_EmulatorRunning)
{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1000 * NSEC_PER_MSEC), dispatch_get_main_queue(), ^{
int success = CoreDoCommand(M64CMD_STATE_LOAD, 1, (void *)[fileName fileSystemRepresentation]);
if(block) block(success==M64ERR_SUCCESS, nil);
});
}
else
{
int success = CoreDoCommand(M64CMD_STATE_LOAD, 1, (void *)[fileName fileSystemRepresentation]);
if(block) block(success==M64ERR_SUCCESS, nil);
}
}
- (OEIntSize)bufferSize
{
return OEIntSizeMake(videoWidth, videoHeight);
}
- (BOOL)tryToResizeVideoTo:(OEIntSize)size
{
VidExt_SetVideoMode(size.width, size.height, 32, M64VIDEO_WINDOWED, 0);
if (ptr_OE_ForceUpdateWindowSize) ptr_OE_ForceUpdateWindowSize(size.width, size.height);
return YES;
}
- (OEGameCoreRendering)gameCoreRendering
{
return OEGameCoreRenderingOpenGL2Video;
}
- (BOOL)hasAlternateRenderingThread
{
return YES;
}
- (BOOL)needsDoubleBufferedFBO
{
return YES;
}
- (const void *)videoBuffer
{
return NULL;
}
- (GLenum)pixelFormat
{
return GL_BGRA;
}
- (GLenum)pixelType
{
return GL_UNSIGNED_INT_8_8_8_8_REV;
}
- (GLenum)internalPixelFormat
{
return GL_RGB8;
}
#pragma mark Mupen Audio
- (NSTimeInterval)frameInterval
{
// Mupen uses 60 but it's probably wrong
return isNTSC ? 60 : 50;
}
- (NSUInteger)channelCount
{
return 2;
}
- (double)audioSampleRate
{
return sampleRate;
}
- (oneway void)didMoveN64JoystickDirection:(OEN64Button)button withValue:(CGFloat)value forPlayer:(NSUInteger)player
{
player -= 1;
switch (button)
{
case OEN64AnalogUp:
yAxis[player] = value * INT8_MAX;
break;
case OEN64AnalogDown:
yAxis[player] = value * INT8_MIN;
break;
case OEN64AnalogLeft:
xAxis[player] = value * INT8_MIN;
break;
case OEN64AnalogRight:
xAxis[player] = value * INT8_MAX;
break;
default:
break;
}
}
- (oneway void)didPushN64Button:(OEN64Button)button forPlayer:(NSUInteger)player
{
player -= 1;
padData[player][button] = 1;
}
- (oneway void)didReleaseN64Button:(OEN64Button)button forPlayer:(NSUInteger)player
{
player -= 1;
padData[player][button] = 0;
}
- (void)setCheat:(NSString *)code setType:(NSString *)type setEnabled:(BOOL)enabled
{
// Sanitize
code = [code stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
// Remove any spaces
code = [code stringByReplacingOccurrencesOfString:@" " withString:@""];
NSString *singleCode;
NSArray *multipleCodes = [code componentsSeparatedByString:@"+"];
m64p_cheat_code *gsCode = (m64p_cheat_code*) calloc([multipleCodes count], sizeof(m64p_cheat_code));
int codeCounter = 0;
for (singleCode in multipleCodes)
{
if ([singleCode length] == 12) // GameShark
{
// GameShark N64 format: XXXXXXXX YYYY
NSString *address = [singleCode substringWithRange:NSMakeRange(0, 8)];
NSString *value = [singleCode substringWithRange:NSMakeRange(8, 4)];
// Convert GS hex to int
unsigned int outAddress, outValue;
NSScanner* scanAddress = [NSScanner scannerWithString:address];
NSScanner* scanValue = [NSScanner scannerWithString:value];
[scanAddress scanHexInt:&outAddress];
[scanValue scanHexInt:&outValue];
gsCode[codeCounter].address = outAddress;
gsCode[codeCounter].value = outValue;
codeCounter++;
}
}
// Update address directly if code needs GS button pressed
if ((gsCode[0].address & 0xFF000000) == 0x88000000 || (gsCode[0].address & 0xFF000000) == 0xA8000000)
{
*(unsigned char *)((g_rdram + ((gsCode[0].address & 0xFFFFFF)^S8))) = (unsigned char)gsCode[0].value; // Update 8-bit address
}
else if ((gsCode[0].address & 0xFF000000) == 0x89000000 || (gsCode[0].address & 0xFF000000) == 0xA9000000)
{
*(unsigned short *)((g_rdram + ((gsCode[0].address & 0xFFFFFF)^S16))) = (unsigned short)gsCode[0].value; // Update 16-bit address
}
// Else add code as normal
else
{
enabled ? CoreAddCheat([code UTF8String], gsCode, codeCounter+1) : CoreCheatEnabled([code UTF8String], 0);
}
}
@end