Cocoa Port:

- Although the Cocoa port looks very similar to the last update, there have been a lot of changes under the hood! Lots of code has moved around, lots of refactoring has been done, and lots of new code was copied from the upcoming Cocoa code base. Due to this, there have been a few collateral improvements as a result.
- Convert main.mm back to a plain Obj-C file, and remove all code from it. It has now been reverted back to its original empty form.
- Move all app related stuff to appDelegate_legacy.mm/h.
- Move all emulation window related stuff to emuWindowDelegate_legacy.mm/h.
- Because we're now using xibs, translations have been reworked. The English xib is the base xib, and translations now use .strings files to make modified copies of the English xib at compile time.
- Add user interface icons.
- Make the Custom Speed Limit Window panel more functional and look nicer.
- Add new Tools > Show Support Folder in Finder menu option, which opens DeSmuME's Application Support folder. This exists as a convenience for Lion users.
- Remove the View > Constrain Proportions menu option. Now, DeSmuME behaves as if this option is always enabled.
- Combine Emulation > Execute and Emulation > Pause into a single menu item.
- Status text now gives more user feedback.
- Add a sound volume slider to the emulation window.
- Remove the Sound menu.
- In the main emulation window, you can now click close to unload ROMs and quit the application.
- Add ability to save screenshots in JPEG 2000 format.
- Add ability to copy a screenshot to the clipboard using Edit > Copy.
- BUG #3394244: Fix bug where touch coordinates did not map correctly on rotated screens.
This commit is contained in:
rogerman 2012-01-11 19:59:17 +00:00
parent 0bcaded804
commit 02acfa3fe3
40 changed files with 3166 additions and 1197 deletions

File diff suppressed because it is too large Load Diff

View File

@ -40,6 +40,7 @@
+ (void) setupAllFilePaths;
+ (BOOL) setupAllAppDirectories;
+ (NSURL *) saveStateURL;
+ (BOOL) saveScreenshot:(NSURL *)fileURL bitmapData:(NSBitmapImageRep *)bitmapImageRep fileType:(NSBitmapImageFileType)fileType;
+ (BOOL) saveStateExistsForSlot:(NSURL *)romURL slotNumber:(NSUInteger)slotNumber;
+ (BOOL) isSaveStateSlotExtension:(NSString *)extension;
+ (NSString *) getSaveSlotFileName:(NSURL *)romURL slotNumber:(NSUInteger)slotNumber;

View File

@ -222,6 +222,53 @@
return [CocoaDSFile getURLUserAppSupport:@STATEKEY appVersion:nil];
}
+ (BOOL) saveScreenshot:(NSURL *)fileURL bitmapData:(NSBitmapImageRep *)bitmapImageRep fileType:(NSBitmapImageFileType)fileType
{
BOOL result = NO;
if (fileURL == nil || bitmapImageRep == nil)
{
return result;
}
NSString *fileExt = nil;
switch (fileType)
{
case NSTIFFFileType:
fileExt = @"tiff";
break;
case NSBMPFileType:
fileExt = @"bmp";
break;
case NSGIFFileType:
fileExt = @"gif";
break;
case NSJPEGFileType:
fileExt = @"jpg";
break;
case NSPNGFileType:
fileExt = @"png";
break;
case NSJPEG2000FileType:
fileExt = @"jp2";
break;
default:
break;
}
NSURL *saveFileURL = [NSURL fileURLWithPath:[[fileURL path] stringByAppendingPathExtension:fileExt]];
result = [[bitmapImageRep representationUsingType:fileType properties:[NSDictionary dictionary]] writeToURL:saveFileURL atomically:NO];
return result;
}
/********************************************************************************************
fileKind:

View File

@ -41,6 +41,8 @@
#define NSSTRING_TITLE_ENABLE_CHEATS NSLocalizedString(@"Enable Cheats", nil)
#define NSSTRING_TITLE_DISABLE_HUD NSLocalizedString(@"Disable HUD", nil)
#define NSSTRING_TITLE_ENABLE_HUD NSLocalizedString(@"Enable HUD", nil)
#define NSSTRING_TITLE_HIDE_STATUS_BAR NSLocalizedString(@"Hide Status Bar", nil)
#define NSSTRING_TITLE_SHOW_STATUS_BAR NSLocalizedString(@"Show Status Bar", nil)
#define NSSTRING_TITLE_SPEED_1X NSLocalizedString(@"Speed 1x", nil)
#define NSSTRING_TITLE_SPEED_2X NSLocalizedString(@"Speed 2x", nil)
#define NSSTRING_TITLE_SLOT_NUMBER NSLocalizedString(@"Slot %d", nil)
@ -85,6 +87,27 @@
#define NSSTRING_DISPLAYMODE_TOUCH NSLocalizedString(@"Touch", nil)
#define NSSTRING_DISPLAYMODE_COMBO NSLocalizedString(@"Combo", nil)
// LEGACY STRINGS
#define NSSTRING_TITLE_OPEN_ROM_PANEL_LEGACY NSLocalizedString(@"Open ROM...", nil)
#define NSSTRING_TITLE_OPEN_STATE_FILE_PANEL_LEGACY NSLocalizedString(@"Load State From...", nil)
#define NSSTRING_TITLE_SAVE_STATE_FILE_PANEL_LEGACY NSLocalizedString(@"Save State...", nil)
#define NSSTRING_STATUS_ROM_UNLOADED_LEGACY NSLocalizedString(@"No ROM Loaded", nil)
#define NSSTRING_STATUS_ROM_LOADED_LEGACY NSLocalizedString(@"ROM Loaded", nil)
#define NSSTRING_STATUS_ROM_LOADING_FAILED_LEGACY NSLocalizedString(@"Couldn't load ROM", nil)
#define NSSTRING_STATUS_EMULATOR_EXECUTING_LEGACY NSLocalizedString(@"Emulation Executing", nil)
#define NSSTRING_STATUS_EMULATOR_PAUSED_LEGACY NSLocalizedString(@"Emulation Paused", nil)
#define NSSTRING_STATUS_EMULATOR_RESET_LEGACY NSLocalizedString(@"Emulation Reset", nil)
#define NSSTRING_ERROR_TITLE_LEGACY NSLocalizedString(@"Error", nil)
#define NSSTRING_ERROR_GENERIC_LEGACY NSLocalizedString(@"An emulation error occurred", nil)
#define NSSTRING_ERROR_SCREENSHOT_FAILED_LEGACY NSLocalizedString(@"Couldn't create the screenshot image", nil)
#define NSSTRING_MESSAGE_TITLE_LEGACY NSLocalizedString(@"DeSmuME Emulator", nil)
#define NSSTRING_MESSAGE_ASK_CLOSE_LEGACY NSLocalizedString(@"Are you sure you want to close the ROM?", nil)
#define FILENAME_README "README"
#define FILENAME_COPYING "COPYING"
#define FILENAME_AUTHORS "AUTHORS"
#define FILENAME_CHANGELOG "ChangeLog"
#define PATH_CONFIG_DIRECTORY_0_9_6 "~/.config/desmume"
#define FILE_EXT_FIRMWARE_CONFIG "dfc"
@ -113,7 +136,9 @@
#define WINDOW_STATUS_BAR_HEIGHT 24 // Height of an emulation window status bar in pixels.
#define SPEED_SCALAR_QUARTER 0.25 // Speed scalar for quarter execution speed.
#define SPEED_SCALAR_HALF 0.5 // Speed scalar for half execution speed.
#define SPEED_SCALAR_THREE_QUARTER 0.75 // Speed scalar for three quarters execution speed.
#define SPEED_SCALAR_NORMAL 1.0 // Speed scalar for normal execution speed.
#define SPEED_SCALAR_DOUBLE 2.0 // Speed scalar for double execution speed.
#define SPEED_SCALAR_MIN 0.005 // Lower limit for the speed multiplier.

View File

@ -81,7 +81,7 @@
#ifdef __cplusplus
extern "C"
{
#endif
#endif
uint32_t RGBA5551ToRGBA8888(const uint16_t color16);
uint32_t RGBA8888ToRGB888(const uint32_t color24);

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

@ -27,26 +27,44 @@
@class VideoOutputWindow;
@class CocoaDSController;
@interface ControlsDelegate : NSObject {}
+ (id)sharedObject;
@end
@interface InputHandler : NSResponder
{
@private
VideoOutputWindow *my_ds;
CocoaDSController *dsController;
CocoaDSController *cdsController;
}
//preferences
+ (NSView*)createPreferencesView:(float)width;
+ (NSDictionary*)appDefaults;
//creation/deletion
- (id)initWithWindow:(VideoOutputWindow*)nds;
- (void)dealloc;
- (id) initWithCdsController:(CocoaDSController *)theController;
- (void) setCdsController:(CocoaDSController *)theController;
- (CocoaDSController *) cdsController;
//keyboard input
- (void)keyDown:(NSEvent*)event;
- (void)keyUp:(NSEvent*)event;
//mouse input
- (void)mouseDown:(NSEvent*)event;
- (void)mouseDragged:(NSEvent*)event;
- (void)mouseUp:(NSEvent*)event;
@end
#ifdef __cplusplus
extern "C"
{
#endif
int testKey(NSString *chars_pressed, NSString *chars_for_key);
#ifdef __cplusplus
}
#endif

View File

@ -19,44 +19,13 @@
#import "input.h"
#import "cocoa_input.h"
#import "main_window.h"
#import "preferences.h"
unsigned char utf8_return = 0x0D;
unsigned char utf8_right[3] = { 0xEF, 0x9C, 0x83 };
unsigned char utf8_up[3] = { 0xEF, 0x9C, 0x80 };
unsigned char utf8_down[3] = { 0xEF, 0x9C, 0x81 };
unsigned char utf8_left[3] = { 0xEF, 0x9C, 0x82 };
@interface ControlsDelegate : NSObject {}
+ (id)sharedObject;
@end
inline int testKey(NSString *chars_pressed, NSString *chars_for_key)
{
//Checks for common characters in chars_pressed and chars_for_key
unichar *buffer1 = (unichar*)malloc([chars_pressed length] * sizeof(unichar));
unichar *buffer2 = (unichar*)malloc([chars_for_key length] * sizeof(unichar));
if(!buffer1 || !buffer2)return 0;
[chars_pressed getCharacters:buffer1];
[chars_for_key getCharacters:buffer2];
int i1, i2;
for(i1 = 0; i1 < [chars_pressed length]; i1++)
for(i2 = 0; i2 < [chars_for_key length]; i2++)
if(buffer1[i1] == buffer2[i2])
{
free(buffer1);
free(buffer2);
return 1;
}
free(buffer1);
free(buffer2);
return 0;
}
static unsigned char utf8_return = 0x0D;
static unsigned char utf8_right[3] = { 0xEF, 0x9C, 0x83 };
static unsigned char utf8_up[3] = { 0xEF, 0x9C, 0x80 };
static unsigned char utf8_down[3] = { 0xEF, 0x9C, 0x81 };
static unsigned char utf8_left[3] = { 0xEF, 0x9C, 0x82 };
//
@ -160,24 +129,39 @@ inline int testKey(NSString *chars_pressed, NSString *chars_for_key)
return nil;
}
- (id)initWithWindow:(VideoOutputWindow*)nds
- (id) initWithCdsController:(CocoaDSController *)theController
{
self = [super init];
if(self == nil)
{
return nil;
}
my_ds = nds;
[my_ds retain];
dsController = [nds getDSController];
[dsController retain];
cdsController = theController;
[cdsController retain];
return self;
}
- (void)dealloc
{
[cdsController release];
[super dealloc];
}
- (void) setCdsController:(CocoaDSController *)theController
{
[cdsController release];
cdsController = theController;
[cdsController retain];
}
- (CocoaDSController *) cdsController
{
return cdsController;
}
- (void)keyDown:(NSEvent*)event
{
if([event isARepeat])return;
@ -185,18 +169,18 @@ inline int testKey(NSString *chars_pressed, NSString *chars_for_key)
NSUserDefaults *settings = [NSUserDefaults standardUserDefaults];
NSString *chars = [event characters];
if(testKey(chars, [settings stringForKey:PREF_KEY_A ]))[dsController pressA];
else if(testKey(chars, [settings stringForKey:PREF_KEY_B ]))[dsController pressB];
else if(testKey(chars, [settings stringForKey:PREF_KEY_SELECT]))[dsController pressSelect];
else if(testKey(chars, [settings stringForKey:PREF_KEY_START ]))[dsController pressStart];
else if(testKey(chars, [settings stringForKey:PREF_KEY_RIGHT ]))[dsController pressRight];
else if(testKey(chars, [settings stringForKey:PREF_KEY_LEFT ]))[dsController pressLeft];
else if(testKey(chars, [settings stringForKey:PREF_KEY_UP ]))[dsController pressUp];
else if(testKey(chars, [settings stringForKey:PREF_KEY_DOWN ]))[dsController pressDown];
else if(testKey(chars, [settings stringForKey:PREF_KEY_R ]))[dsController pressR];
else if(testKey(chars, [settings stringForKey:PREF_KEY_L ]))[dsController pressL];
else if(testKey(chars, [settings stringForKey:PREF_KEY_X ]))[dsController pressX];
else if(testKey(chars, [settings stringForKey:PREF_KEY_Y ]))[dsController pressY];
if(testKey(chars, [settings stringForKey:PREF_KEY_A ]))[cdsController pressA];
else if(testKey(chars, [settings stringForKey:PREF_KEY_B ]))[cdsController pressB];
else if(testKey(chars, [settings stringForKey:PREF_KEY_SELECT]))[cdsController pressSelect];
else if(testKey(chars, [settings stringForKey:PREF_KEY_START ]))[cdsController pressStart];
else if(testKey(chars, [settings stringForKey:PREF_KEY_RIGHT ]))[cdsController pressRight];
else if(testKey(chars, [settings stringForKey:PREF_KEY_LEFT ]))[cdsController pressLeft];
else if(testKey(chars, [settings stringForKey:PREF_KEY_UP ]))[cdsController pressUp];
else if(testKey(chars, [settings stringForKey:PREF_KEY_DOWN ]))[cdsController pressDown];
else if(testKey(chars, [settings stringForKey:PREF_KEY_R ]))[cdsController pressR];
else if(testKey(chars, [settings stringForKey:PREF_KEY_L ]))[cdsController pressL];
else if(testKey(chars, [settings stringForKey:PREF_KEY_X ]))[cdsController pressX];
else if(testKey(chars, [settings stringForKey:PREF_KEY_Y ]))[cdsController pressY];
}
- (void)keyUp:(NSEvent*)event
@ -204,39 +188,44 @@ inline int testKey(NSString *chars_pressed, NSString *chars_for_key)
NSUserDefaults *settings = [NSUserDefaults standardUserDefaults];
NSString *chars = [event characters];
if(testKey(chars, [settings stringForKey:PREF_KEY_A ]))[dsController liftA];
else if(testKey(chars, [settings stringForKey:PREF_KEY_B ]))[dsController liftB];
else if(testKey(chars, [settings stringForKey:PREF_KEY_SELECT]))[dsController liftSelect];
else if(testKey(chars, [settings stringForKey:PREF_KEY_START ]))[dsController liftStart];
else if(testKey(chars, [settings stringForKey:PREF_KEY_RIGHT ]))[dsController liftRight];
else if(testKey(chars, [settings stringForKey:PREF_KEY_LEFT ]))[dsController liftLeft];
else if(testKey(chars, [settings stringForKey:PREF_KEY_UP ]))[dsController liftUp];
else if(testKey(chars, [settings stringForKey:PREF_KEY_DOWN ]))[dsController liftDown];
else if(testKey(chars, [settings stringForKey:PREF_KEY_R ]))[dsController liftR];
else if(testKey(chars, [settings stringForKey:PREF_KEY_L ]))[dsController liftL];
else if(testKey(chars, [settings stringForKey:PREF_KEY_X ]))[dsController liftX];
else if(testKey(chars, [settings stringForKey:PREF_KEY_Y ]))[dsController liftY];
}
- (void)mouseDown:(NSEvent*)event
{
NSPoint temp = [my_ds windowPointToDSCoords:[event locationInWindow]];
if(temp.x >= 0 && temp.y>=0)
{
[dsController touch:temp];
}
}
- (void)mouseDragged:(NSEvent*)event
{
[self mouseDown:event];
}
- (void)mouseUp:(NSEvent*)event
{
[dsController releaseTouch];
if(testKey(chars, [settings stringForKey:PREF_KEY_A ]))[cdsController liftA];
else if(testKey(chars, [settings stringForKey:PREF_KEY_B ]))[cdsController liftB];
else if(testKey(chars, [settings stringForKey:PREF_KEY_SELECT]))[cdsController liftSelect];
else if(testKey(chars, [settings stringForKey:PREF_KEY_START ]))[cdsController liftStart];
else if(testKey(chars, [settings stringForKey:PREF_KEY_RIGHT ]))[cdsController liftRight];
else if(testKey(chars, [settings stringForKey:PREF_KEY_LEFT ]))[cdsController liftLeft];
else if(testKey(chars, [settings stringForKey:PREF_KEY_UP ]))[cdsController liftUp];
else if(testKey(chars, [settings stringForKey:PREF_KEY_DOWN ]))[cdsController liftDown];
else if(testKey(chars, [settings stringForKey:PREF_KEY_R ]))[cdsController liftR];
else if(testKey(chars, [settings stringForKey:PREF_KEY_L ]))[cdsController liftL];
else if(testKey(chars, [settings stringForKey:PREF_KEY_X ]))[cdsController liftX];
else if(testKey(chars, [settings stringForKey:PREF_KEY_Y ]))[cdsController liftY];
}
@end
inline int testKey(NSString *chars_pressed, NSString *chars_for_key)
{
//Checks for common characters in chars_pressed and chars_for_key
unichar *buffer1 = (unichar*)malloc([chars_pressed length] * sizeof(unichar));
unichar *buffer2 = (unichar*)malloc([chars_for_key length] * sizeof(unichar));
if(!buffer1 || !buffer2)return 0;
[chars_pressed getCharacters:buffer1];
[chars_for_key getCharacters:buffer2];
int i1, i2;
for(i1 = 0; i1 < [chars_pressed length]; i1++)
for(i2 = 0; i2 < [chars_for_key length]; i2++)
if(buffer1[i1] == buffer2[i2])
{
free(buffer1);
free(buffer2);
return 1;
}
free(buffer1);
free(buffer2);
return 0;
}

25
desmume/src/cocoa/main.m Normal file
View File

@ -0,0 +1,25 @@
/*
Copyright (C) 2007 Jeff Bland
Copyright (C) 2011 Roger Manuel
Copyright (C) 2012 DeSmuME team
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the this software. If not, see <http://www.gnu.org/licenses/>.
*/
#import <Cocoa/Cocoa.h>
int main(int argc, char *argv[])
{
return NSApplicationMain(argc, (const char **) argv);
}

View File

@ -1,560 +0,0 @@
/*
Copyright (C) 2007 Jeff Bland
Copyright (C) 2011 Roger Manuel
Copyright (C) 2012 DeSmuME team
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the this software. If not, see <http://www.gnu.org/licenses/>.
*/
/*
This file is part of the Cocoa (Mac OS X) port of DeSmuME emulator
By Jeff Bland
Based on work by yopyop and the DeSmuME team!
Mac related questions can go to osx@desmume.org
*/
#import <Cocoa/Cocoa.h>
#import "cocoa_file.h"
#import "cocoa_util.h"
#import "main_window.h"
#import "preferences.h"
#include "sndOSX.h"
#ifdef GDB_STUB
#include <pthread.h>
#endif
/*
FIXME: .nds.gba support?
*/
//Globals----------------------------------------------------------------------------------------
//view (defined/managed in main_window.m)
extern NSMenuItem *resize1x;
extern NSMenuItem *resize2x;
extern NSMenuItem *resize3x;
extern NSMenuItem *resize4x;
extern NSMenuItem *constrain_item;
extern NSMenuItem *min_size_item;
extern NSMenuItem *toggle_status_bar_item;
extern NSMenuItem *rotation0_item;
extern NSMenuItem *rotation90_item;
extern NSMenuItem *rotation180_item;
extern NSMenuItem *rotation270_item;
extern NSMenuItem *topBG0_item;
extern NSMenuItem *topBG1_item;
extern NSMenuItem *topBG2_item;
extern NSMenuItem *topBG3_item;
extern NSMenuItem *topOBJ_item;
extern NSMenuItem *subBG0_item;
extern NSMenuItem *subBG1_item;
extern NSMenuItem *subBG2_item;
extern NSMenuItem *subBG3_item;
extern NSMenuItem *subOBJ_item;
extern NSMenuItem *screenshot_to_file_item;
extern NSMenuItem *screenshot_to_window_item;
//execution control (defined/managed in nds_control.m)
extern NSMenuItem *close_rom_item;
extern NSMenuItem *execute_item;
extern NSMenuItem *pause_item;
extern NSMenuItem *reset_item;
extern NSMenuItem *save_type_item[];
extern NSString *save_types[];
extern NSMenuItem *speed_limit_25_item;
extern NSMenuItem *speed_limit_50_item;
extern NSMenuItem *speed_limit_75_item;
extern NSMenuItem *speed_limit_100_item;
extern NSMenuItem *speed_limit_200_item;
extern NSMenuItem *speed_limit_none_item;
extern NSMenuItem *speed_limit_custom_item;
extern NSMenuItem *save_state_as_item;
extern NSMenuItem *load_state_from_item;
//sound (defined/managed in nds_control.m)
extern NSMenuItem *volume_item[];
extern NSMenuItem *mute_item;
#define SAVE_SLOTS 10 //this should never be more than NB_SAVES in saves.h
extern NSMenuItem *saveSlot_item[];
extern NSMenuItem *loadSlot_item[];
//extern NSMenuItem *clear_all_saves_item; waiting for more functionality from saves.h
extern NSMenuItem *rom_info_item;
//Interfaces--------------------------------------------------------------------------------------
@interface AppDelegate : NSObject
{}
//our methods
- (void)pickROM;
//delegate methods
- (BOOL)application:(NSApplication*)sender openFile:(NSString*)filename;
- (void)applicationWillFinishLaunching:(NSNotification*)aNotification;
- (void)applicationDidFinishLaunching:(NSNotification*)aNotification;
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)sender;
- (void)applicationWillTerminate:(NSNotification*)aNotification;
@end
//
VideoOutputWindow *main_window;
///////////////////////////////
//This generates and sets the entire menubar (and sets defaults)
void CreateMenu(AppDelegate *delegate)
{
//Grab the main menu
NSMenu *main_menu = [NSApp mainMenu];
if(main_menu == nil)return;
//
int i;
NSMenuItem *temp;
//File Menu
temp = [main_menu addItemWithTitle:@"" action:nil keyEquivalent:@""];
NSMenu *file_menu = [[NSMenu alloc] initWithTitle:NSLocalizedString(@"File", nil)];
if(file_menu != nil)
{
[main_menu setSubmenu:file_menu forItem:temp];
[[file_menu addItemWithTitle:NSLocalizedString(@"Open ROM...", nil) action:@selector(pickROM) keyEquivalent:@"o"] setTarget:delegate];
//Recent items menu
// Thanks to Jeff Johnson and the Lap Cat Software Blog for their information on the Open Recent menu in Cocoa
// http://lapcatsoftware.com/blog/
temp = [file_menu addItemWithTitle:NSLocalizedString(@"Open Recent", nil) action:nil keyEquivalent:@""];
NSMenu *recent_menu = [[NSMenu alloc] initWithTitle:NSLocalizedString(@"Open Recent", nil)];
if(recent_menu != nil)
{
[recent_menu performSelector:@selector(_setMenuName:) withObject:@"NSRecentDocumentsMenu"];
[temp setSubmenu:recent_menu];
[[recent_menu addItemWithTitle:@"Clear Menu" action:@selector(clearRecentDocuments:) keyEquivalent:@""] setTarget:[NSDocumentController sharedDocumentController]];
[recent_menu release];
}
[file_menu addItem:[NSMenuItem separatorItem]];
rom_info_item = [file_menu addItemWithTitle:NSLocalizedString(@"ROM Info...", nil) action:@selector(showRomInfo) keyEquivalent:@""];
#ifdef HAVE_LIBZ //internally, save states only work when zlib is there
[file_menu addItem:[NSMenuItem separatorItem]];
[save_state_as_item = [file_menu addItemWithTitle:NSLocalizedString(@"Save State As...", nil) action:@selector(saveStateAs) keyEquivalent:@""] setEnabled:NO];
[load_state_from_item = [file_menu addItemWithTitle:NSLocalizedString(@"Load State From...", nil) action:@selector(loadStateFrom) keyEquivalent:@""] setEnabled:NO];
[file_menu addItem:[NSMenuItem separatorItem]];
//Save state menu
[save_state_as_item setEnabled:NO];
temp = [file_menu addItemWithTitle:NSLocalizedString(@"Save State", nil) action:nil keyEquivalent:@""];
NSMenu *save_state_menu = [[NSMenu alloc] initWithTitle:NSLocalizedString(@"Save State", nil)];
if(save_state_menu != nil)
{
[temp setSubmenu:save_state_menu];
for(i = 0; i < SAVE_SLOTS; i++)
{
saveSlot_item[i] = [save_state_menu addItemWithTitle:[NSString stringWithFormat:NSLocalizedString(@"Slot %d", nil), i+1] action:@selector(saveToSlot:) keyEquivalent:[NSString stringWithFormat:@"%d", i<9?i+1:0]];
[saveSlot_item[i] setKeyEquivalentModifierMask:NSShiftKeyMask];
}
[save_state_menu release];
}
//Load state menu
temp = [file_menu addItemWithTitle:NSLocalizedString(@"Load State", nil) action:nil keyEquivalent:@""];
NSMenu *load_state_menu = [[NSMenu alloc] initWithTitle:NSLocalizedString(@"Load State", nil)];
if(load_state_menu != nil)
{
[temp setSubmenu:load_state_menu];
for(i = 0; i < SAVE_SLOTS; i++)
{
loadSlot_item[i] = [load_state_menu addItemWithTitle:[saveSlot_item[i] title] action:@selector(loadFromSlot:) keyEquivalent:[NSString stringWithFormat:@"%d", i<9?i+1:0]];
[loadSlot_item[i] setKeyEquivalentModifierMask:0];
}
[load_state_menu release];
}
#endif
[file_menu addItem:[NSMenuItem separatorItem]];
close_rom_item = [file_menu addItemWithTitle:NSLocalizedString(@"Close ROM", nil) action:@selector(askAndCloseROM) keyEquivalent:@"w"];
[file_menu release];
}
//Emulation menu
temp = [main_menu addItemWithTitle:@"" action:nil keyEquivalent:@""];
NSMenu *emulation_menu = [[NSMenu alloc] initWithTitle:NSLocalizedString(@"Emulation", nil)];
if(emulation_menu != nil)
{
[main_menu setSubmenu:emulation_menu forItem:temp];
execute_item = [emulation_menu addItemWithTitle:NSLocalizedString(@"Execute", nil) action:@selector(execute) keyEquivalent:@"e"];
pause_item = [emulation_menu addItemWithTitle:NSLocalizedString(@"Pause", nil) action:@selector(pause) keyEquivalent:@"p"];
reset_item = [emulation_menu addItemWithTitle:NSLocalizedString(@"Reset", nil) action:@selector(reset) keyEquivalent:@"r"];
[emulation_menu addItem:[NSMenuItem separatorItem]];
//Speed limit menu
temp = [emulation_menu addItemWithTitle:NSLocalizedString(@"Speed Limit", nil) action:nil keyEquivalent:@""];
NSMenu *speed_limit_menu = [[NSMenu alloc] initWithTitle:NSLocalizedString(@"Speed Limit", nil)];
if(speed_limit_menu != nil)
{
[temp setSubmenu:speed_limit_menu];
speed_limit_25_item = [speed_limit_menu addItemWithTitle:NSLocalizedString(@"25% Speed Limit", nil) action:@selector(setSpeedLimitFromMenuItem:) keyEquivalent:@""];
speed_limit_50_item = [speed_limit_menu addItemWithTitle:NSLocalizedString(@"50% Speed Limit", nil) action:@selector(setSpeedLimitFromMenuItem:) keyEquivalent:@""];
speed_limit_75_item = [speed_limit_menu addItemWithTitle:NSLocalizedString(@"75% Speed Limit", nil) action:@selector(setSpeedLimitFromMenuItem:) keyEquivalent:@""];
[speed_limit_menu addItem:[NSMenuItem separatorItem]];
speed_limit_100_item = [speed_limit_menu addItemWithTitle:NSLocalizedString(@"100% Speed Limit", nil) action:@selector(setSpeedLimitFromMenuItem:) keyEquivalent:@""];
[speed_limit_menu addItem:[NSMenuItem separatorItem]];
speed_limit_200_item = [speed_limit_menu addItemWithTitle:NSLocalizedString(@"200% Speed Limit", nil) action:@selector(setSpeedLimitFromMenuItem:) keyEquivalent:@""];
speed_limit_none_item = [speed_limit_menu addItemWithTitle:NSLocalizedString(@"No Speed Limit" , nil) action:@selector(setSpeedLimitFromMenuItem:) keyEquivalent:@""];
[speed_limit_menu addItem:[NSMenuItem separatorItem]];
speed_limit_custom_item = [speed_limit_menu addItemWithTitle:NSLocalizedString(@"Custom Speed Limit", nil) action:@selector(setSpeedLimitFromMenuItem:) keyEquivalent:@""];
[speed_limit_menu release];
}
// Backup media type
temp = [emulation_menu addItemWithTitle:NSLocalizedString(@"Backup Media Type", nil) action:nil keyEquivalent:@""];
NSMenu *save_type_menu = [[NSMenu alloc] initWithTitle:NSLocalizedString(@"Backup Media Type", nil)];
if(save_type_menu != nil)
{
[temp setSubmenu:save_type_menu];
// Add autodetect apart from the others
save_type_item[0] = [save_type_menu addItemWithTitle:save_types[0] action:@selector(setSaveTypeFromMenuItem:) keyEquivalent:@""];
[save_type_menu addItem:[NSMenuItem separatorItem]];
// Add the rest
for(i = 1; i < MAX_SAVE_TYPE; i++)
{
save_type_item[i] = [save_type_menu addItemWithTitle:save_types[i] action:@selector(setSaveTypeFromMenuItem:) keyEquivalent:@""];
}
[save_type_menu release];
}
[emulation_menu release];
}
//View menu
temp = [main_menu addItemWithTitle:@"" action:nil keyEquivalent:@""];
NSMenu *view_menu = [[NSMenu alloc] initWithTitle:NSLocalizedString(@"View", nil)];
if(view_menu)
{
[main_menu setSubmenu:view_menu forItem:temp];
resize1x = [view_menu addItemWithTitle:NSLocalizedString(@"Size 1x", nil) action:@selector(resizeScreen1x) keyEquivalent:@"1"];
resize2x = [view_menu addItemWithTitle:NSLocalizedString(@"Size 2x", nil) action:@selector(resizeScreen2x) keyEquivalent:@"2"];
resize3x = [view_menu addItemWithTitle:NSLocalizedString(@"Size 3x", nil) action:@selector(resizeScreen3x) keyEquivalent:@"3"];
resize4x = [view_menu addItemWithTitle:NSLocalizedString(@"Size 4x", nil) action:@selector(resizeScreen4x) keyEquivalent:@"4"];
[view_menu addItem:[NSMenuItem separatorItem]];
constrain_item = [view_menu addItemWithTitle:NSLocalizedString(@"Constrain Proportions", nil) action:@selector(toggleConstrainProportions) keyEquivalent:@""];
min_size_item = [view_menu addItemWithTitle:NSLocalizedString(@"No Smaller Than DS", nil) action:@selector(toggleMinSize) keyEquivalent:@""];
toggle_status_bar_item = [view_menu addItemWithTitle:NSLocalizedString(@"Show Status Bar", nil) action:@selector(toggleStatusBar) keyEquivalent:@"/"];
[view_menu addItem:[NSMenuItem separatorItem]];
//Rotation menu
temp = [view_menu addItemWithTitle:NSLocalizedString(@"Rotation", nil) action:nil keyEquivalent:@""];
NSMenu *rotation_menu = [[NSMenu alloc] initWithTitle:NSLocalizedString(@"Rotation", nil)];
if(rotation_menu != nil)
{
[temp setSubmenu:rotation_menu];
rotation0_item = [rotation_menu addItemWithTitle:NSLocalizedString(@"Rotation 0", nil) action:@selector(setRotation0) keyEquivalent:@""];
rotation90_item = [rotation_menu addItemWithTitle:NSLocalizedString(@"Rotation 90", nil) action:@selector(setRotation90) keyEquivalent:@""];
rotation180_item = [rotation_menu addItemWithTitle:NSLocalizedString(@"Rotation 180", nil) action:@selector(setRotation180) keyEquivalent:@""];
rotation270_item = [rotation_menu addItemWithTitle:NSLocalizedString(@"Rotation 270", nil) action:@selector(setRotation270) keyEquivalent:@""];
[rotation_menu release];
}
[view_menu addItem:[NSMenuItem separatorItem]];
//Layer Menu
temp = [view_menu addItemWithTitle:NSLocalizedString(@"Layers", nil) action:nil keyEquivalent:@""];
NSMenu *layer_menu = [[NSMenu alloc] initWithTitle:NSLocalizedString(@"Layers", nil)];
if(layer_menu != nil)
{
[temp setSubmenu: layer_menu];
topBG0_item = [layer_menu addItemWithTitle:NSLocalizedString(@"Top BG0", nil) action:@selector(toggleTopBackground0) keyEquivalent:@""];
topBG1_item = [layer_menu addItemWithTitle:NSLocalizedString(@"Top BG1", nil) action:@selector(toggleTopBackground1) keyEquivalent:@""];
topBG2_item = [layer_menu addItemWithTitle:NSLocalizedString(@"Top BG2", nil) action:@selector(toggleTopBackground2) keyEquivalent:@""];
topBG3_item = [layer_menu addItemWithTitle:NSLocalizedString(@"Top BG3", nil) action:@selector(toggleTopBackground3) keyEquivalent:@""];
topOBJ_item = [layer_menu addItemWithTitle:NSLocalizedString(@"Top OBJ", nil) action:@selector(toggleTopObject) keyEquivalent:@""];
[layer_menu addItem:[NSMenuItem separatorItem]];
subBG0_item = [layer_menu addItemWithTitle:NSLocalizedString(@"Sub BG0", nil) action:@selector(toggleSubBackground0) keyEquivalent:@""];
subBG1_item = [layer_menu addItemWithTitle:NSLocalizedString(@"Sub BG1", nil) action:@selector(toggleSubBackground1) keyEquivalent:@""];
subBG2_item = [layer_menu addItemWithTitle:NSLocalizedString(@"Sub BG2", nil) action:@selector(toggleSubBackground2) keyEquivalent:@""];
subBG3_item = [layer_menu addItemWithTitle:NSLocalizedString(@"Sub BG3", nil) action:@selector(toggleSubBackground3) keyEquivalent:@""];
subOBJ_item = [layer_menu addItemWithTitle:NSLocalizedString(@"Sub OBJ", nil) action:@selector(toggleSubObject) keyEquivalent:@""];
[layer_menu release];
}
[view_menu addItem:[NSMenuItem separatorItem]];
screenshot_to_file_item = [view_menu addItemWithTitle:NSLocalizedString(@"Save Screenshot...", nil) action:@selector(saveScreenshot) keyEquivalent:@""];
[view_menu release];
}
//Sound Menu
temp = [main_menu addItemWithTitle:@"" action:nil keyEquivalent:@""];
NSMenu *sound_menu = [[NSMenu alloc] initWithTitle:NSLocalizedString(@"Sound", nil)];
if(sound_menu != nil)
{
[main_menu setSubmenu:sound_menu forItem:temp];
[temp = [sound_menu addItemWithTitle:NSLocalizedString(@"Volume", nil) action:nil keyEquivalent:@""] setTarget:[NSApp delegate]];
NSMenu *volume_menu = [[NSMenu alloc] initWithTitle:NSLocalizedString(@"Volume", nil)];
if(volume_menu)
{
[sound_menu setSubmenu:volume_menu forItem:temp];
for(i = 0; i < 10; i++)
volume_item[i] = [volume_menu addItemWithTitle:[NSString stringWithFormat:NSLocalizedString(@"Volume %d", nil), (i+1)*10] action:@selector(setVolumeFromMenu:) keyEquivalent:@""];
[volume_menu release];
}
[sound_menu addItem:[NSMenuItem separatorItem]];
mute_item = [sound_menu addItemWithTitle:NSLocalizedString(@"Mute", nil) action:@selector(toggleMute) keyEquivalent:@""];
[sound_menu release];
}
//Create the help menu
temp = [main_menu addItemWithTitle:@"" action:nil keyEquivalent:@""];
NSMenu *help_menu = [[NSMenu alloc] initWithTitle:NSLocalizedString(@"Help", nil)];
if(help_menu != nil)
{
[main_menu setSubmenu:help_menu forItem:temp];
[[help_menu addItemWithTitle:NSLocalizedString(@"Go to Website", nil) action:@selector(launchWebsite) keyEquivalent: @""] setTarget:NSApp];
[[help_menu addItemWithTitle:NSLocalizedString(@"Go to Forums", nil) action:@selector(launchForums) keyEquivalent: @""] setTarget:NSApp];
[[help_menu addItemWithTitle:NSLocalizedString(@"Submit a Bug Report", nil) action:@selector(bugReport) keyEquivalent: @""] setTarget:NSApp];
[help_menu release];
}
}
#ifdef GDB_STUB
//GDB Stub implementation----------------------------------------------------------------------------
void * createThread_gdb(void (*thread_function)( void *data),void *thread_data)
{
// Create the thread using POSIX routines.
pthread_attr_t attr;
pthread_t* posixThreadID = (pthread_t*)malloc(sizeof(pthread_t));
assert(!pthread_attr_init(&attr));
assert(!pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE));
int threadError = pthread_create(posixThreadID, &attr, (void* (*)(void *))thread_function, thread_data);
assert(!pthread_attr_destroy(&attr));
if (threadError != 0)
{
// Report an error.
return NULL;
}
else
{
return posixThreadID;
}
}
void joinThread_gdb( void *thread_handle)
{
pthread_join(*((pthread_t*)thread_handle), NULL);
free(thread_handle);
}
#endif
//Main Function--------------------------------------------------------------------------------------
int main(int argc, char *argv[])
{
srand(time(NULL));
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[NSApplication sharedApplication];
[NSApp setDelegate:[[AppDelegate alloc] init]];
int result = NSApplicationMain(argc, (const char**)argv);
[pool release];
return result;
}
//Implementations-------------------------------------------------------------------------
@implementation AppDelegate
- (void)pickROM
{
NSOpenPanel *panel = [NSOpenPanel openPanel];
[panel setCanChooseDirectories:NO];
[panel setCanChooseFiles:YES];
[panel setResolvesAliases:YES];
[panel setAllowsMultipleSelection:NO];
[panel setTitle:NSLocalizedString(@"Open ROM...", nil)];
if([panel runModalForDirectory:nil file:nil types:[NSArray arrayWithObjects:@"NDS", @"DS.GBA", nil]] == NSOKButton)
{
NSString* selected_file = [[panel filenames] lastObject]; //hopefully also the first object
[self application:NSApp openFile:selected_file];
}
}
- (BOOL)application:(NSApplication*)sender openFile:(NSString*)filename
{
BOOL result = NO;
NSURL *fileURL = [NSURL fileURLWithPath:filename];
NSString *fileKind = [CocoaDSFile fileKind:fileURL];
if ([fileKind isEqualToString:@"DS ROM"] || [fileKind isEqualToString:@"GBA ROM"])
{
result = [main_window loadRom:fileURL];
}
return result;
}
- (void)applicationWillFinishLaunching:(NSNotification*)notification
{
// Create the needed directories in Application Support if they haven't already
// been created.
if (![CocoaDSFile setupAllAppDirectories])
{
[CocoaDSUtil quickDialogUsingTitle:NSLocalizedString(@"Error", nil) message:NSLocalizedString(@"Could not create the required directories in your Application Support folder. DeSmuME will now quit.", nil)];
return;
}
[CocoaDSFile setupAllFilePaths];
SNDOSXStartup();
//Set default values for all preferences
//(this wont override saved preferences as
//they work in different preference domains)
setAppDefaults();
//create the menus
CreateMenu(self);
//create the video output window (the only window that opens with the app)
main_window = [[VideoOutputWindow alloc] init];
}
- (void)applicationDidFinishLaunching:(NSNotification*)notification
{
//Bring the application to the front
[NSApp activateIgnoringOtherApps:TRUE];
//check if it should load something by default
if([[[NSUserDefaults standardUserDefaults] stringForKey:PREF_AFTER_LAUNCHED] compare:PREF_AFTER_LAUNCHED_OPTION_LAST_ROM]==NSOrderedSame)
{
NSArray *recent_documents = [[NSDocumentController sharedDocumentController] recentDocumentURLs];
if([recent_documents count] > 0)
{
NSURL *romURL = [recent_documents objectAtIndex:0];
[main_window loadRom:romURL];
}
}
}
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)sender
{
//Ask user about quitting if a rom is loaded (avoid accidentally quiting with unsaved progress)
if([main_window ROMLoaded])
if(![CocoaDSUtil quickYesNoDialogUsingTitle:NSLocalizedString(@"DeSmuME Emulator", nil) message:NSLocalizedString(@"Are you sure you want to quit?", nil)])
return NSTerminateCancel;
return NSTerminateNow;
}
- (void)applicationWillTerminate:(NSNotification*)notification
{
[main_window pause];
[main_window release];
SNDOSXShutdown();
}
@end

View File

@ -33,17 +33,6 @@
@class CocoaDSController;
@class ScreenState;
@interface CocoaDSStateBuffer : NSObject
{
@public
int frame_skip;
int speed_limit;
}
- (id) init;
@end
//This class is a compelte objective-c wrapper for
//the core emulation features, other objective-c code inherit
//upon or instanciate this to add interfaces for these features
@ -72,16 +61,15 @@
volatile bool paused; //sey by other thread to let us know if its executing
bool muted;
int volume;
float volume;
volatile int frame_skip;
volatile int speed_limit;
volatile int save_type;
bool doesConfigNeedUpdate;
CGFloat speedScalar;
BOOL isSpeedLimitEnabled;
NSTimeInterval calcTimeBudget;
CocoaDSController *dsController;
CocoaDSController *cdsController;
#ifdef GDB_STUB
NSInteger arm9_gdb_port;
@ -93,8 +81,8 @@
unsigned char gpu_buff[256 * 256 * 5]; //this is where the 3D rendering of the NDS is stored
@public
CocoaDSStateBuffer *dsStateBuffer;
NSURL *loadedRomURL;
NSInteger prevCoreState;
}
//Instanciating, setup, and deconstruction
@ -104,34 +92,44 @@
- (void)dealloc;
// Data accessors
- (CocoaDSController*) getDSController;
- (void) setMasterExecute:(BOOL)theState;
- (BOOL) masterExecute;
- (void) setCdsController:(CocoaDSController *)theController;
- (CocoaDSController*) cdsController;
//Firmware control
- (void)setPlayerName:(NSString*)player_name;
//ROM control
- (BOOL) loadRom:(NSURL *)romURL;
- (BOOL)ROMLoaded;
- (BOOL)isRomLoaded;
- (void)closeROM;
//ROM Info
- (NSImage *)ROMIcon;
- (NSImage *)romIcon;
- (NSString *) romFileName;
- (NSString *)ROMTitle;
- (NSInteger)ROMMaker;
- (NSInteger)ROMSize;
- (NSInteger)ROMARM9Size;
- (NSInteger)ROMARM7Size;
- (NSInteger)ROMDataSize;
- (NSString *)romTitle;
- (NSInteger)romMaker;
- (NSInteger)romSize;
- (NSInteger)romArm9Size;
- (NSInteger)romArm7Size;
- (NSInteger)romDataSize;
- (NSURL *) loadedRomURL;
- (NSMutableDictionary *) romInfoBindings;
+ (NSMutableDictionary *) romNotLoadedBindings;
//execution control
- (void) setCoreState:(NSInteger)coreState;
- (void) restoreCoreState;
- (BOOL)executing;
- (void)execute;
- (BOOL)paused;
- (void)pause;
- (void)reset;
- (void)setSpeedLimit:(int)percent; //0 is off, 1-1000 is the pertance speed it runs at, anything else does nothing
- (int)speedLimit;
- (void) setSpeedScalar:(CGFloat)scalar;
- (CGFloat) speedScalar;
- (void) setIsSpeedLimitEnabled:(BOOL)theState;
- (BOOL) isSpeedLimitEnabled;
- (void)setSaveType:(int)savetype; // see save_types in src/mmu.h
- (int)saveType; // default is 0, which is autodetect
- (void) updateConfig;
@ -146,10 +144,14 @@
//Sound
- (BOOL)hasSound;
- (void)setVolume:(int)volume; //clamped: 0 to 100
- (int)volume;
- (void) setVolume:(float)vol; //clamped: 0 to 100
- (float) volume;
- (void)enableMute;
- (void)disableMute;
- (void)toggleMute;
- (BOOL)muted;
- (void) copyToPasteboard;
- (NSBitmapImageRep *) bitmapImageRep;
@end

View File

@ -24,11 +24,7 @@
#import "cocoa_util.h"
#import "preferences.h"
#import "screen_state.h"
#import "main_window.h"
#ifdef DESMUME_COCOA
#import "sndOSX.h"
#endif
#include "sndOSX.h"
#ifdef HAVE_OPENGL
#import <OpenGL/OpenGL.h>
@ -54,38 +50,17 @@ volatile bool execute = true;
GPU3DInterface *core3DList[] = {
&gpu3DNull,
&gpu3DRasterize,
#ifdef HAVE_OPENGL
//&gpu3Dgl,
#endif
NULL
};
SoundInterface_struct *SNDCoreList[] = {
&SNDDummy,
#ifdef DESMUME_COCOA
&SNDOSX,
#endif
NULL
};
struct NDS_fw_config_data macDS_firmware;
bool opengl_init()
{
return true;
}
@implementation CocoaDSStateBuffer
- (id) init
{
frame_skip = -1; //default to auto frame skip
speed_limit = 100; //default to max speed = normal speed
return self;
}
@end
@implementation NintendoDS
- (id)init
@ -97,8 +72,9 @@ bool opengl_init()
display_object = nil;
error_object = nil;
frame_skip = -1; //default to auto frame skip
speed_limit = 100; //default to max speed = normal speed
calcTimeBudget = (NSTimeInterval)(DS_SECONDS_PER_FRAME / ((float)speed_limit / 100.0));
speedScalar = SPEED_SCALAR_NORMAL;
calcTimeBudget = (NSTimeInterval)(DS_SECONDS_PER_FRAME / speedScalar);
isSpeedLimitEnabled = YES;
gui_thread = [NSThread currentThread];
loadedRomURL = nil;
execution_lock = [[NSLock alloc] init];
@ -252,8 +228,7 @@ bool opengl_init()
if(context)
{
[context makeCurrentContext];
//oglrender_init = &opengl_init;
NDS_3D_SetDriver(CORE3DLIST_SWRASTERIZE);
if(!gpu3D->NDS_3D_Init())
[CocoaDSUtil quickDialogUsingTitle:NSLocalizedString(@"Error", nil) message:NSLocalizedString(@"Unable to initialize OpenGL components", nil)];
@ -269,12 +244,12 @@ bool opengl_init()
//Sound Init
muted = false;
volume = 100;
volume = 100.0;
#ifdef DESMUME_COCOA
if(SPU_ChangeSoundCore(SNDCORE_OSX, 735 * 4) != 0)
[CocoaDSUtil quickDialogUsingTitle:NSLocalizedString(@"Error", nil) message:NSLocalizedString(@"Unable to initialize sound core", nil)];
else
SPU_SetVolume(volume);
SPU_SetVolume((int)volume);
#endif
//Breakoff a new thread that will execute the ds stuff
@ -282,6 +257,7 @@ bool opengl_init()
finished = false;
run = false;
paused = false;
prevCoreState = CORESTATE_PAUSE;
[NSThread detachNewThreadSelector:@selector(run:) toTarget:self withObject:context];
//Start a timer to update the screen
@ -291,8 +267,7 @@ bool opengl_init()
[NSTimer scheduledTimerWithTimeInterval:DS_SECONDS_PER_FRAME target:self selector:@selector(videoUpdateTimerHelper) userInfo:nil repeats:YES];
}
dsStateBuffer = [[CocoaDSStateBuffer alloc] init];
dsController = [[CocoaDSController alloc] init];
cdsController = nil;
return self;
}
@ -326,8 +301,7 @@ bool opengl_init()
finish = true;
while(!finished){}
[dsStateBuffer release];
[dsController release];
[cdsController release];
[display_object release];
[error_object release];
@ -353,9 +327,46 @@ bool opengl_init()
[super dealloc];
}
- (CocoaDSController*) getDSController
- (void) setMasterExecute:(BOOL)theState
{
return dsController;
//OSSpinLockLock(&spinlockMasterExecute);
if (theState)
{
execute = true;
}
else
{
execute = false;
}
//OSSpinLockUnlock(&spinlockMasterExecute);
}
- (BOOL) masterExecute
{
BOOL theState = NO;
//OSSpinLockLock(&spinlockMasterExecute);
if (execute)
{
theState = YES;
}
//OSSpinLockUnlock(&spinlockMasterExecute);
return theState;
}
- (void) setCdsController:(CocoaDSController *)theController
{
cdsController = theController;
}
- (CocoaDSController*) cdsController
{
return cdsController;
}
- (void)setPlayerName:(NSString*)player_name
@ -390,16 +401,16 @@ bool opengl_init()
//continue playing if load didn't work
if(was_paused == NO)[self execute];
return NO;
return result;
}
/*
//clear screen data
if(current_screen != nil)
{
[current_screen release];
current_screen = nil;
}
*/
// Retain a copy of the URL of the currently loaded ROM, since we'll be
// using it later.
loadedRomURL = romURL;
@ -408,11 +419,13 @@ bool opengl_init()
//this is incase emulation stopped from the
//emulation core somehow
execute = true;
return YES;
result = YES;
return result;
}
- (BOOL)ROMLoaded
- (BOOL) isRomLoaded
{
return (loadedRomURL==nil)?NO:YES;
}
@ -420,20 +433,20 @@ bool opengl_init()
- (void)closeROM
{
[self pause];
/*
if(current_screen != nil)
{
[current_screen release];
current_screen = nil;
}
*/
NDS_FreeROM();
[loadedRomURL release];
loadedRomURL = nil;
}
- (NSImage*)ROMIcon
- (NSImage *) romIcon
{
NDS_header *header = NDS_getROMHeader();
if(!header)return nil;
@ -512,41 +525,124 @@ bool opengl_init()
return result;
}
- (NSString*)romFileName
- (NSString *) romFileName
{
return [[loadedRomURL path] lastPathComponent];
}
- (NSString*)ROMTitle
- (NSString *) romTitle
{
return [[NSString alloc] initWithCString:(NDS_getROMHeader()->gameTile) encoding:NSUTF8StringEncoding];
}
- (NSInteger)ROMMaker
- (NSInteger) romMaker
{
return NDS_getROMHeader()->makerCode;
}
- (NSInteger)ROMSize
- (NSInteger) romSize
{
return NDS_getROMHeader()->cardSize;
}
- (NSInteger)ROMARM9Size
- (NSInteger) romArm9Size
{
return NDS_getROMHeader()->ARM9binSize;
}
- (NSInteger)ROMARM7Size
- (NSInteger) romArm7Size
{
return NDS_getROMHeader()->ARM7binSize;
}
- (NSInteger)ROMDataSize
- (NSInteger) romDataSize
{
return NDS_getROMHeader()->ARM7binSize + NDS_getROMHeader()->ARM7src;
}
- (NSMutableDictionary *) romInfoBindings
{
if (![self isRomLoaded])
{
return [NintendoDS romNotLoadedBindings];
}
return [NSMutableDictionary dictionaryWithObjectsAndKeys:
[self romFileName], @"romFileName",
[self romTitle], @"romTitle",
[NSString stringWithFormat:@"%04X", [self romMaker]], @"makerCode",
[NSString stringWithFormat:NSSTRING_STATUS_SIZE_BYTES, [self romSize]], @"romSize",
[NSString stringWithFormat:NSSTRING_STATUS_SIZE_BYTES, [self romArm9Size]], @"arm9BinarySize",
[NSString stringWithFormat:NSSTRING_STATUS_SIZE_BYTES, [self romArm7Size]], @"arm7BinarySize",
[NSString stringWithFormat:NSSTRING_STATUS_SIZE_BYTES, [self romDataSize]], @"dataSize",
[self romIcon], @"iconImage",
nil];
}
+ (NSMutableDictionary *) romNotLoadedBindings
{
NSImage *iconImage = [[[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"AppIcon_DeSmuME" ofType:@"icns"]] autorelease];
return [NSMutableDictionary dictionaryWithObjectsAndKeys:
NSSTRING_STATUS_NO_ROM_LOADED, @"romFileName",
NSSTRING_STATUS_NO_ROM_LOADED, @"romTitle",
NSSTRING_STATUS_NO_ROM_LOADED, @"makerCode",
[NSString stringWithFormat:NSSTRING_STATUS_SIZE_BYTES, 0], @"romSize",
[NSString stringWithFormat:NSSTRING_STATUS_SIZE_BYTES, 0], @"arm9BinarySize",
[NSString stringWithFormat:NSSTRING_STATUS_SIZE_BYTES, 0], @"arm7BinarySize",
[NSString stringWithFormat:NSSTRING_STATUS_SIZE_BYTES, 0], @"dataSize",
iconImage, @"iconImage",
nil];
}
- (NSURL *) loadedRomURL
{
return loadedRomURL;
}
- (void) setCoreState:(NSInteger)coreState
{
if ([self paused])
{
prevCoreState = CORESTATE_PAUSE;
}
else
{
prevCoreState = CORESTATE_EXECUTE;
}
switch (coreState)
{
case CORESTATE_EXECUTE:
[self execute];
break;
case CORESTATE_PAUSE:
[self pause];
break;
default:
break;
}
}
- (void) restoreCoreState
{
switch (prevCoreState)
{
case CORESTATE_EXECUTE:
[self execute];
break;
case CORESTATE_PAUSE:
[self pause];
break;
default:
break;
}
}
- (BOOL)executing
{
return run;
@ -595,21 +691,26 @@ bool opengl_init()
execute = true;
}
- (void)setSpeedLimit:(int)speedLimit
- (void) setSpeedScalar:(CGFloat)scalar
{
if(speedLimit < 0 || speedLimit > 1000)
{
return;
}
dsStateBuffer->speed_limit = speedLimit;
doesConfigNeedUpdate = true;
speedScalar = scalar;
[self updateConfig];
}
- (int)speedLimit
- (CGFloat) speedScalar
{
return speed_limit;
return speedScalar;
}
- (void) setIsSpeedLimitEnabled:(BOOL)theState
{
isSpeedLimitEnabled = theState;
[self updateConfig];
}
- (BOOL) isSpeedLimitEnabled
{
return isSpeedLimitEnabled;
}
- (void)setSaveType:(int)savetype
@ -742,19 +843,25 @@ bool opengl_init()
return core != &SNDDummy;
}
- (void)setVolume:(int)new_volume
- (void) setVolume:(float)vol
{
if(new_volume < 0)new_volume = 0;
if(new_volume > 100)new_volume = 100;
if(volume == new_volume)return;
if (vol < 0.0f)
{
vol = 0.0f;
}
else if (vol > MAX_VOLUME)
{
vol = MAX_VOLUME;
}
volume = new_volume;
volume = vol;
[sound_lock lock];
SPU_SetVolume(volume);
SPU_SetVolume((int)vol);
[sound_lock unlock];
}
- (int)volume
- (float) volume
{
if([self hasSound])
return volume;
@ -772,7 +879,7 @@ bool opengl_init()
- (void)disableMute
{
[sound_lock lock];
SPU_SetVolume(volume);
SPU_SetVolume((int)volume);
[sound_lock unlock];
muted = false;
}
@ -790,6 +897,38 @@ bool opengl_init()
return muted?YES:NO;
}
- (void) copyToPasteboard
{
if (current_screen == nil)
{
return;
}
NSImage *screenshot = [[current_screen image] autorelease];
if (screenshot == nil)
{
return;
}
NSPasteboard *pboard = [NSPasteboard generalPasteboard];
[pboard declareTypes:[NSArray arrayWithObjects:NSTIFFPboardType, nil] owner:self];
[pboard setData:[screenshot TIFFRepresentationUsingCompression:NSTIFFCompressionLZW factor:1.0f] forType:NSTIFFPboardType];
}
- (NSBitmapImageRep *) bitmapImageRep
{
NSBitmapImageRep *currentScreenImageRep = nil;
if (current_screen == nil)
{
return currentScreenImageRep;
}
currentScreenImageRep = [current_screen imageRep];
return currentScreenImageRep;
}
//----------------------------
//Here's the run function which continuously executes in a separate thread
//it's controlled by the run and finish varaiables of the instance
@ -812,20 +951,12 @@ bool opengl_init()
- (void)videoUpdateTimerHelper
{
if(!run)return;
[video_update_lock lock];
ScreenState *screen = current_screen;
[screen retain];
current_screen = nil;
[video_update_lock unlock];
if(screen != nil)
if(!run || current_screen == nil)
{
[display_object performSelector:display_func withObject:screen];
[screen release];
return;
}
[display_object performSelector:display_func withObject:current_screen];
}
- (void)run:(NSOpenGLContext*)gl_context
@ -863,18 +994,6 @@ bool opengl_init()
*/
loopStartDate = [NSDate date];
/*
Some controls may affect how the loop runs.
Instead of checking and modifying the NDS config every time through
the loop, only change the config on an as-needed basis.
*/
if(doesConfigNeedUpdate == true)
{
[self updateConfig];
doesConfigNeedUpdate = false;
}
// Force paused state.
paused = false;
@ -904,7 +1023,7 @@ bool opengl_init()
The time taken up by this step should be insignificant, so we
won't bother calculating this in the time budget.
*/
[dsController setupAllDSInputs];
[cdsController setupAllDSInputs];
NDS_beginProcessingInput();
/*
Shouldn't need to do any special processing steps in between.
@ -997,17 +1116,20 @@ bool opengl_init()
if(timer_based)
{ //for tiger compatibility
[video_update_lock lock];
[current_screen release];
ScreenState *oldScreenData = current_screen;
current_screen = new_screen_data;
[oldScreenData release];
[video_update_lock unlock];
}
else
{ //for leopard and later
ScreenState *oldScreenData = current_screen;
current_screen = new_screen_data;
//this will generate a warning when compiling on tiger or earlier, but it should
//be ok since the purpose of the if statement is to check if this will work
[self performSelector:@selector(videoUpdateHelper:) onThread:gui_thread withObject:new_screen_data waitUntilDone:NO];
[new_screen_data release]; //performSelector will auto retain the screen data while the other thread displays
[self performSelector:@selector(videoUpdateHelper:) onThread:gui_thread withObject:current_screen waitUntilDone:NO];
[oldScreenData release]; //performSelector will auto retain the screen data while the other thread displays
}
}
@ -1026,22 +1148,25 @@ bool opengl_init()
- (void) updateConfig
{
// Update the Nintendo DS config
frame_skip = dsStateBuffer->frame_skip;
speed_limit = dsStateBuffer->speed_limit;
CGFloat newTimeBudget;
if(speed_limit <= 0)
// Update speed limit
if(!isSpeedLimitEnabled)
{
calcTimeBudget = 0;
}
else if(speed_limit > 0 && speed_limit < 1000)
{
calcTimeBudget = (NSTimeInterval)(DS_SECONDS_PER_FRAME / ((float)speed_limit / 100.0));
newTimeBudget = 0.0;
}
else
{
calcTimeBudget = (NSTimeInterval)(DS_SECONDS_PER_FRAME / ((float)1000.0 / 100.0));
CGFloat theSpeed = speedScalar;
if(theSpeed <= SPEED_SCALAR_MIN)
{
theSpeed = SPEED_SCALAR_MIN;
}
newTimeBudget = (NSTimeInterval)(DS_SECONDS_PER_FRAME / theSpeed);
}
calcTimeBudget = newTimeBudget;
}
@end

View File

@ -93,7 +93,7 @@ void setAppDefaults()
{
BOOL value = ([sender indexOfSelectedItem] == 0) ? YES : NO;
[[NSUserDefaults standardUserDefaults] setBool:value forKey:PREF_EXECUTE_UPON_LOAD];
[[NSUserDefaults standardUserDefaults] setBool:value forKey:@"ExecuteROMOnLoad"];
}
- (void)afterLaunch:(id)sender
@ -308,7 +308,9 @@ NSView *createPreferencesView(NSString *helpinfo, NSDictionary *options, id dele
NSArray* keys = [[options allKeys] sortedArrayUsingSelector:@selector(localizedCompare:)];
NSEnumerator *key_enumerator = [keys reverseObjectEnumerator];
id key, key_raw, object;
NSString *key;
NSString *key_raw;
NSArray *object;
NSRect text_rect = NSMakeRect(5, 5, 220, 29);
NSRect button_rect = NSMakeRect(230, 5, PREFERENCES_WIDTH - 235, 26);
while ((key_raw = [key_enumerator nextObject]))
@ -319,7 +321,7 @@ NSView *createPreferencesView(NSString *helpinfo, NSDictionary *options, id dele
NSString *current_setting = [[NSUserDefaults standardUserDefaults] objectForKey:key_raw];
if([[object objectAtIndex:0] compare:@"Bool"] == NSOrderedSame)
if([(NSString *)[object objectAtIndex:0] compare:@"Bool"] == NSOrderedSame)
{
//Create the button for this option
NSPopUpButton *button = [[NSPopUpButton alloc] initWithFrame:button_rect pullsDown:NO];
@ -335,12 +337,12 @@ NSView *createPreferencesView(NSString *helpinfo, NSDictionary *options, id dele
[button addItemWithTitle:NSLocalizedString(@"Yes",nil)];
[button addItemWithTitle:NSLocalizedString(@"No",nil)];
[button selectItemAtIndex:([[NSUserDefaults standardUserDefaults] boolForKey:PREF_EXECUTE_UPON_LOAD] == YES) ? 0 : 1];
[button selectItemAtIndex:([[NSUserDefaults standardUserDefaults] boolForKey:@"ExecuteROMOnLoad"] == YES) ? 0 : 1];
[view addSubview:button];
}
else if([[object objectAtIndex:0] compare:@"Array"] == NSOrderedSame)
else if([(NSString *)[object objectAtIndex:0] compare:@"Array"] == NSOrderedSame)
{
//Create the button for this option
NSPopUpButton *button = [[NSPopUpButton alloc] initWithFrame:button_rect pullsDown:NO];
@ -387,7 +389,7 @@ NSView *createPreferencesView(NSString *helpinfo, NSDictionary *options, id dele
[view addSubview:button];
}
else if ([[object objectAtIndex:0] caseInsensitiveCompare:@"Text"] == NSOrderedSame)
else if ([(NSString *)[object objectAtIndex:0] caseInsensitiveCompare:@"Text"] == NSOrderedSame)
{
//if this preference is a text field
@ -406,7 +408,7 @@ NSView *createPreferencesView(NSString *helpinfo, NSDictionary *options, id dele
[view addSubview:text];
}
else if([[object objectAtIndex:0] compare:@"Dictionary"] == NSOrderedSame)
else if([(NSString *)[object objectAtIndex:0] compare:@"Dictionary"] == NSOrderedSame)
{
//Create the button for this option
NSPopUpButton *button = [[NSPopUpButton alloc] initWithFrame:button_rect pullsDown:NO];

View File

@ -6,91 +6,16 @@
//"OK" = ?;
//"Cancel" = ?;
/* Menu Headers */
"File" = "Fichier";
"Emulation" = "Emulation";
"View" = "Présentation";
"Sound" = "Son";
"Window" = "Fenêtre";
"Help" = "Aide";
/* File Menu */
"Open ROM..." = "Ouvrir une ROM...";
"Open Recent" = "Fichiers récents";
"ROM Info..." = "Informations sur la ROM...";
"Save State As..." = "Enregistrer l'état sous...";
"Load State From..." = "Charger l'état depuis...";
"Save State" = "Enregistrer l'état";
"Load State" = "Charger l'état";
"Close ROM" = "Fermer la ROM";
"Slot %d" = "Slot %d";
/* Emulation Menu */
"Execute" = "Exécuter";
"Pause" = "Pause";
"Reset" = "Réinitialiser";
"Frame Skip" = "Saut d'image";
"Auto" = "Automatique";
"Off" = "Off";
"Skip %d" = "%d";
//"Speed Limit" = ?;
//"25% Speed Limit" = ?;
//"50% Speed Limit" = ?;
//"75% Speed Limit" = ?;
//"100% Speed Limit" = ?;
//"200% Speed Limit" = ?;
//"No Speed Limit" = ?;
//"Custom Speed Limit" = ?;
//"Custom Speed Limit Window" = ?;
//"Set Max Speed:" = ?;
"Speed %d%%" = "%d%%";
"Set FAT Image File..." = "Définir le fichier d'image FAT...";
/* View Menu */
"Size 1x" = "Taille 1x";
"Size 2x" = "Taille 2x";
"Size 3x" = "Taille 3x";
"Size 4x" = "Taille 4x";
"Full Screen" = "Plein écran";
"Constrain Proportions" = "Contraindre les proportions";
"No Smaller Than DS" = "Pas plus petit que la DS";
"Show Status Bar" = "Afficher la barre d&apos;état";
"Rotation" = "Rotation";
"Rotation 0" = "0°";
"Rotation 90" = "90°";
"Rotation 180" = "180°";
"Rotation 270" = "270°";
"Layers" = "Calques";
"Top BG0" = "Top BG0";
"Top BG1" = "Top BG1";
"Top BG2" = "Top BG2";
"Top BG3" = "Top BG3";
"Sub BG0" = "Sub BG0";
"Sub BG1" = "Sub BG1";
"Sub BG2" = "Sub BG2";
"Sub BG3" = "Sub BG3";
"Save Screenshot..." = "Enregistrer une capture d'écran...";
/* Sound Menu */
"Volume" = "Volume";
"Volume %d" = "%d%";
"Mute" = "Muet";
/* Window Menu */
/* Help Menu */
"Go to Website" = "Aller sur le site web";
"Go to Forums" = "Aller sur les forums";
"Submit a Bug Report" = "Envoyer un rapport de bug";
/* About panel */
"DeSmuME" = "DeSmuME";
"Nintendo DS Emulator" = "Emulateur Nintendo DS";
"Version %@" = "Version %@";
"Readme" = "Lisez-moi";
"License" = "Licence";
"Authors" = "Auteurs";
"Change Log" = "Change Log";
"Hide Status Bar" = "Hide Status Bar";
/* Dialogs */
"Are you sure you want to quit?" = "Etes vous su de vouloir quitter ?";
@ -136,26 +61,6 @@
//"Space Bar" = ?;
//"Enter Key" = ?;
/* ROM Info */
"ROM File" = "Fichier";
"ROM Title" = "Titre";
"ROM Maker" = "Maker";
"ROM Size" = "Taille de la ROM";
"ARM9 Size" = "ARM9 Size";
"ARM7 Size" = "ARM7 Size";
"Data Size" = "Taille des données";
"ROM Icon" = "Icône de la ROM";
/* Screenshots */
"Save Screenshot to File..." = "Enregistrer une capture d'écran dans un fichier...";
"Select Image Format: " = "Sélectionner le format d'image :";
"Pick by Extension" = "Choisir par extension";
"BMP" = "BMP";
"GIF" = "GIF";
"JPG" = "JPG";
"PNG" = "PNG";
"TIFF" = "TIFF";
/* Status Bar */
"No ROM loaded" = "Aucune ROM chargée";
"ROM Loaded" = "ROM chargée";
@ -163,9 +68,6 @@
"Emulation Paused" = "En pause";
"Emulation Reset" = "Réinitialiser";
/* Save States */
"Save State..." = "Enregistrer l'état...";
/* Errors */
"Error" = "Erreur";
"An emulation error occured" = "Une erreur d'émulation est survenue";
"An emulation error occurred" = "Une erreur d'émulation est survenue";

View File

@ -0,0 +1,75 @@
/*
Copyright (C) 2007 Jeff Bland
Copyright (C) 2012 DeSmuME team
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the this software. If not, see <http://www.gnu.org/licenses/>.
*/
#import <Cocoa/Cocoa.h>
#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
#include "macosx_10_4_compat.h"
#endif
@class NintendoDS;
@class InputHandler;
@class VideoOutputWindow;
@compatibility_alias CocoaDSCore NintendoDS;
@compatibility_alias CocoaDSRom NintendoDS;
#if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
@interface AppDelegate : NSObject <NSApplicationDelegate>
#else
@interface AppDelegate : NSObject
#endif
{
IBOutlet NSWindow *mainWindow;
IBOutlet NSObjectController *aboutWindowController;
IBOutlet NSObjectController *emuWindowController;
IBOutlet NSObjectController *cdsCoreController;
IBOutlet NSObjectController *romInfoPanelController;
IBOutlet NSTextView *readMeTextView;
IBOutlet NSMenu *mLoadStateSlot;
IBOutlet NSMenu *mSaveStateSlot;
InputHandler *keyboardHandler;
}
// Tools Menu
- (IBAction) showSupportFolderInFinder:(id)sender;
// Help Menu
- (IBAction) launchWebsite:(id)sender;
- (IBAction) launchForums:(id)sender;
- (IBAction) bugReport:(id)sender;
- (void) setupSlotMenuItems;
- (NSMenuItem *) addSlotMenuItem:(NSMenu *)menu slotNumber:(NSUInteger)slotNumber;
@end
#ifdef __cplusplus
extern "C"
{
#endif
void* createThread_gdb(void (*thread_function)( void *data),void *thread_data);
void joinThread_gdb(void *thread_handle);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,259 @@
/*
Copyright (C) 2007 Jeff Bland
Copyright (C) 2012 DeSmuME team
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the this software. If not, see <http://www.gnu.org/licenses/>.
*/
#import "appDelegate_legacy.h"
#import "emuWindowDelegate_legacy.h"
#import "cocoa_input.h"
#import "cocoa_file.h"
#import "cocoa_util.h"
#import "cocoa_globals.h"
#import "nds_control.h"
#import "input.h"
#import "preferences.h"
#include "sndOSX.h"
#undef BOOL
#ifdef GDB_STUB
#include <pthread.h>
#endif
#ifdef GDB_STUB
//GDB Stub implementation----------------------------------------------------------------------------
void* createThread_gdb(void (*thread_function)( void *data),void *thread_data)
{
// Create the thread using POSIX routines.
pthread_attr_t attr;
pthread_t* posixThreadID = (pthread_t*)malloc(sizeof(pthread_t));
assert(!pthread_attr_init(&attr));
assert(!pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE));
int threadError = pthread_create(posixThreadID, &attr, (void* (*)(void *))thread_function, thread_data);
assert(!pthread_attr_destroy(&attr));
if (threadError != 0)
{
// Report an error.
return NULL;
}
else
{
return posixThreadID;
}
}
void joinThread_gdb(void *thread_handle)
{
pthread_join(*((pthread_t*)thread_handle), NULL);
free(thread_handle);
}
#endif
@implementation AppDelegate
- (BOOL)application:(NSApplication *)sender openFile:(NSString *)filename
{
BOOL result = NO;
NSURL *fileURL = [NSURL fileURLWithPath:filename];
EmuWindowDelegate *mainWindowDelegate = [mainWindow delegate];
CocoaDSCore *cdsCore = (CocoaDSCore *)[cdsCoreController content];
if (cdsCore == nil)
{
return result;
}
NSString *fileKind = [CocoaDSFile fileKind:fileURL];
if ([fileKind isEqualToString:@"DS ROM"] || [fileKind isEqualToString:@"GBA ROM"])
{
result = [mainWindowDelegate handleLoadRom:fileURL];
}
return result;
}
- (void)applicationWillFinishLaunching:(NSNotification *)notification
{
EmuWindowDelegate *mainWindowDelegate = (EmuWindowDelegate *)[mainWindow delegate];
// Create the needed directories in Application Support if they haven't already
// been created.
if (![CocoaDSFile setupAllAppDirectories])
{
[CocoaDSUtil quickDialogUsingTitle:NSLocalizedString(@"Error", nil) message:NSLocalizedString(@"Could not create the required directories in your Application Support folder. DeSmuME will now quit.", nil)];
return;
}
[CocoaDSFile setupAllFilePaths];
// Setup the About window.
NSMutableDictionary *aboutWindowProperties = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[[NSBundle mainBundle] pathForResource:@FILENAME_README ofType:@""], @"readMePath",
[[NSBundle mainBundle] pathForResource:@FILENAME_COPYING ofType:@""], @"licensePath",
[[NSBundle mainBundle] pathForResource:@FILENAME_AUTHORS ofType:@""], @"authorsPath",
[[NSBundle mainBundle] pathForResource:@FILENAME_CHANGELOG ofType:@""], @"changeLogPath",
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"], @"versionString",
@__DATE__, @"dateString",
nil];
[aboutWindowController setContent:aboutWindowProperties];
SNDOSXStartup();
//Set default values for all preferences
//(this wont override saved preferences as
//they work in different preference domains)
setAppDefaults();
// Setup the slot menu items. We set this up manually instead of through Interface
// Builder because we're assuming an arbitrary number of slot items.
[self setupSlotMenuItems];
// Setup the user interface controllers.
[romInfoPanelController setContent:[CocoaDSRom romNotLoadedBindings]];
[emuWindowController setContent:[mainWindowDelegate bindings]];
// Init the DS emulation core.
CocoaDSCore *newCore = [[CocoaDSCore alloc] init];
[newCore setVideoUpdateCallback:@selector(setScreenState:) withObject:[mainWindowDelegate displayView]];
[newCore setErrorCallback:@selector(emulationError) withObject:[mainWindow delegate]];
[cdsCoreController setContent:newCore];
// Init the DS controller.
CocoaDSController *newController = [[CocoaDSController alloc] init];
[newCore setCdsController:newController];
[[mainWindowDelegate displayView] setCdsController:newController];
keyboardHandler = [[InputHandler alloc] initWithCdsController:newController];
NSResponder *mainNextResponder = [mainWindow nextResponder];
[mainWindow setNextResponder:keyboardHandler];
[keyboardHandler setNextResponder:mainNextResponder];
}
- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
EmuWindowDelegate *mainWindowDelegate = [mainWindow delegate];
//Bring the application to the front
[NSApp activateIgnoringOtherApps:TRUE];
//check if it should load something by default
if([[[NSUserDefaults standardUserDefaults] stringForKey:PREF_AFTER_LAUNCHED] compare:PREF_AFTER_LAUNCHED_OPTION_LAST_ROM]==NSOrderedSame)
{
NSArray *recent_documents = [[NSDocumentController sharedDocumentController] recentDocumentURLs];
if([recent_documents count] > 0)
{
NSURL *romURL = [recent_documents objectAtIndex:0];
[mainWindowDelegate loadRom:romURL];
}
}
}
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
{
EmuWindowDelegate *mainWindowDelegate = [mainWindow delegate];
//Ask user about quitting if a rom is loaded (avoid accidentally quitting with unsaved progress)
if([mainWindowDelegate isRomLoaded])
if(![CocoaDSUtil quickYesNoDialogUsingTitle:NSLocalizedString(@"DeSmuME Emulator", nil) message:NSLocalizedString(@"Are you sure you want to quit?", nil)])
return NSTerminateCancel;
return NSTerminateNow;
}
- (void)applicationWillTerminate:(NSNotification*)notification
{
CocoaDSCore *cdsCore = (CocoaDSCore *)[cdsCoreController content];
[cdsCore pause];
[keyboardHandler release];
[[cdsCore cdsController] release];
[cdsCore release];
[cdsCoreController setContent:nil];
SNDOSXShutdown();
}
- (IBAction) showSupportFolderInFinder:(id)sender
{
NSURL *folderURL = [CocoaDSFile getBaseURLUserAppSupport];
[[NSWorkspace sharedWorkspace] openFile:[folderURL path] withApplication:@"Finder"];
}
- (IBAction) launchWebsite:(id)sender
{
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@STRING_DESMUME_WEBSITE]];
}
- (IBAction) launchForums:(id)sender
{
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@STRING_DESMUME_FORUM_SITE]];
}
- (IBAction) bugReport:(id)sender
{
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@STRING_DESMUME_BUG_SITE]];
}
- (void) setupSlotMenuItems
{
NSInteger i;
NSMenuItem *loadItem = nil;
NSMenuItem *saveItem = nil;
for(i = 0; i < MAX_SAVESTATE_SLOTS; i++)
{
loadItem = [self addSlotMenuItem:mLoadStateSlot slotNumber:(NSUInteger)(i + 1)];
[loadItem setKeyEquivalentModifierMask:0];
[loadItem setTag:i];
[loadItem setAction:@selector(loadEmuSaveStateSlot:)];
saveItem = [self addSlotMenuItem:mSaveStateSlot slotNumber:(NSUInteger)(i + 1)];
[saveItem setKeyEquivalentModifierMask:NSShiftKeyMask];
[saveItem setTag:i];
[saveItem setAction:@selector(saveEmuSaveStateSlot:)];
}
}
- (NSMenuItem *) addSlotMenuItem:(NSMenu *)menu slotNumber:(NSUInteger)slotNumber
{
NSUInteger slotNumberKey = slotNumber;
if (slotNumber == 10)
{
slotNumberKey = 0;
}
NSMenuItem *mItem = [menu addItemWithTitle:[NSString stringWithFormat:NSSTRING_TITLE_SLOT_NUMBER, slotNumber]
action:nil
keyEquivalent:[NSString stringWithFormat:@"%d", slotNumberKey]];
[mItem setTarget:[mainWindow delegate]];
return mItem;
}
@end

View File

@ -0,0 +1,123 @@
/*
Copyright (C) 2007 Jeff Bland
Copyright (C) 2012 DeSmuME team
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the this software. If not, see <http://www.gnu.org/licenses/>.
*/
#import <Cocoa/Cocoa.h>
#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
#include "macosx_10_4_compat.h"
#endif
@class NintendoDS;
@class VideoOutputView;
@class InputHandler;
@compatibility_alias CocoaDSCore NintendoDS;
@compatibility_alias CocoaDSRom NintendoDS;
@compatibility_alias CocoaDisplayView VideoOutputView;
#if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
@interface EmuWindowDelegate : NSObject <NSWindowDelegate>
#else
@interface EmuWindowDelegate : NSObject
#endif
{
NSMutableDictionary *bindings;
NSImage *iconVolumeFull;
NSImage *iconVolumeTwoThird;
NSImage *iconVolumeOneThird;
NSImage *iconVolumeMute;
NSImage *iconExecute;
NSImage *iconPause;
NSImage *iconSpeedNormal;
NSImage *iconSpeedDouble;
IBOutlet NSWindow *window;
IBOutlet CocoaDisplayView *displayView;
IBOutlet NSView *saveScreenshotPanelAccessoryView;
IBOutlet NSObjectController *emuWindowController;
IBOutlet NSObjectController *cdsCoreController;
IBOutlet NSObjectController *romInfoPanelController;
BOOL isRomLoading;
NSURL *currentEmuSaveStateURL;
NSUInteger statusBarHeight;
NSSize minDisplayViewSize;
BOOL isSmallestSizeNormal;
BOOL isShowingStatusBar;
NSBitmapImageFileType screenshotFileFormat;
}
- (NSMutableDictionary *) bindings;
- (CocoaDisplayView *) displayView;
- (void) setContentScalar:(double)s;
- (void) setContentRotation:(double)angleDegrees;
- (double) resizeWithTransform:(NSSize)normalBounds scalar:(double)scalar rotation:(double)angleDegrees;
- (double) maxContentScalar:(NSSize)contentBounds;
- (void) setVolume:(float)vol;
- (float) volume;
- (void) setIsRomLoaded:(BOOL)theState;
- (BOOL) isRomLoaded;
- (void) setStatus:(NSString *)theString;
- (NSString *) status;
- (NSURL *) loadedRomURL;
- (void) emulationError;
// File Menu
- (IBAction) openRom:(id)sender;
- (IBAction) closeRom:(id)sender;
- (IBAction) openEmuSaveState:(id)sender;
- (IBAction) saveEmuSaveState:(id)sender;
- (IBAction) saveEmuSaveStateAs:(id)sender;
- (IBAction) revertEmuSaveState:(id)sender;
- (IBAction) loadEmuSaveStateSlot:(id)sender;
- (IBAction) saveEmuSaveStateSlot:(id)sender;
- (IBAction) importRomSave:(id)sender;
- (IBAction) exportRomSave:(id)sender;
// Edit Menu
- (IBAction) copy:(id)sender;
// Emulation Menu
- (IBAction) speedLimitDisable:(id)sender;
- (IBAction) executeCoreToggle:(id)sender;
- (IBAction) resetCore:(id)sender;
- (IBAction) changeRomSaveType:(id)sender;
// Window Elements
- (IBAction) changeCoreSpeed:(id)sender;
- (IBAction) changeVolume:(id)sender;
- (IBAction) changeScale:(id)sender;
- (IBAction) changeRotation:(id)sender;
- (IBAction) changeRotationRelative:(id)sender;
- (IBAction) toggleGPUState:(id)sender;
- (IBAction) toggleMinSize:(id)sender;
- (IBAction) toggleStatusBar:(id)sender;
- (IBAction) changeScreenshotFileFormat:(id)sender;
- (IBAction) saveScreenshotAs:(id)sender;
- (BOOL) handleLoadRom:(NSURL *)fileURL;
- (BOOL) handleUnloadRom:(NSInteger)reasonID romToLoad:(NSURL *)romURL;
- (BOOL) loadRom:(NSURL *)romURL;
- (BOOL) unloadRom;
- (void) executeCore;
- (void) pauseCore;
- (void) restoreCoreState;
@end

File diff suppressed because it is too large Load Diff

View File

@ -19,10 +19,15 @@
#import <Cocoa/Cocoa.h>
#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
#include "macosx_10_4_compat.h"
#endif
//This class uses OpenGL for drawing for speed
//if opengl is not available it uses NSImage
@class ScreenState;
@class CocoaDSController;
@interface VideoOutputView :
#ifdef HAVE_OPENGL
@ -35,6 +40,12 @@ NSImageView
NSOpenGLContext* context;
#endif
ScreenState *screen_buffer;
double viewScale;
double viewRotation;
NSInteger displayMode;
UInt32 gpuStateFlags;
CocoaDSController *cdsController;
}
//init
- (id)initWithFrame:(NSRect)frame;
@ -46,5 +57,36 @@ NSImageView
//size in pixels of screen display (disreguarding rotation of the view)
- (float)screenHeight;
- (float)screenWidth;
- (NSSize) normalSize;
- (void) setScale:(double)scalar;
- (double) scale;
- (void) setRotation:(double)angleDegrees;
- (double) rotation;
- (void) setDisplayMode:(NSInteger)theMode;
- (NSInteger) displayMode;
- (void) setGpuStateFlags:(UInt32)flags;
- (UInt32) gpuStateFlags;
- (void) setCdsController:(CocoaDSController *)theController;
- (CocoaDSController*) cdsController;
- (void) setViewToBlack;
- (void) setViewToWhite;
- (BOOL) gpuStateByBit:(UInt32)stateBit;
- (NSPoint) convertPointToDS:(NSPoint)touchLoc;
@end
#ifdef __cplusplus
extern "C"
{
#endif
void SetGPULayerState(int displayType, unsigned int i, bool state);
bool GetGPULayerState(int displayType, unsigned int i);
void SetGPUDisplayState(int displayType, bool state);
bool GetGPUDisplayState(int displayType);
#ifdef __cplusplus
}
#endif

View File

@ -19,8 +19,16 @@
#import "video_output_view.h"
#import "nds_control.h"
#import "input.h"
#import "cocoa_input.h"
#import "cocoa_globals.h"
#import "cocoa_util.h"
#import "preferences.h"
#import "screen_state.h"
#include "../GPU.h"
#include "../NDSSystem.h"
#undef BOOL
#define HORIZONTAL(angle) ((angle) == -90 || (angle) == -270)
#define VERTICAL(angle) ((angle) == 0 || (angle) == -180)
@ -52,6 +60,21 @@
}
screen_buffer = nil;
viewScale = 1.0;
viewRotation = 0.0;
displayMode = DS_DISPLAY_TYPE_COMBO;
gpuStateFlags = GPUSTATE_MAIN_GPU_MASK |
GPUSTATE_MAIN_BG0_MASK |
GPUSTATE_MAIN_BG1_MASK |
GPUSTATE_MAIN_BG2_MASK |
GPUSTATE_MAIN_BG3_MASK |
GPUSTATE_MAIN_OBJ_MASK |
GPUSTATE_SUB_GPU_MASK |
GPUSTATE_SUB_BG0_MASK |
GPUSTATE_SUB_BG1_MASK |
GPUSTATE_SUB_BG2_MASK |
GPUSTATE_SUB_BG3_MASK |
GPUSTATE_SUB_OBJ_MASK;
//Initialize image view if for displaying the screen ----------------------------------------
#ifndef HAVE_OPENGL
@ -98,7 +121,9 @@
//init screen buffer
[self setScreenState:[ScreenState blackScreenState]];
cdsController = nil;
return self;
}
@ -160,6 +185,193 @@
return DS_SCREEN_HEIGHT*2;
}
- (NSSize) normalSize
{
return [ScreenState size];
}
- (void) setScale:(double)scalar
{
viewScale = scalar;
}
- (double) scale
{
return viewScale;
}
- (void) setRotation:(double)angleDegrees
{
viewRotation = angleDegrees;
[self setBoundsRotation:-angleDegrees];
}
- (double) rotation
{
return viewRotation;
}
- (void) setDisplayMode:(NSInteger)theMode
{
// Do nothing. This is a stub function only.
}
- (NSInteger) displayMode
{
return displayMode;
}
- (void) setGpuStateFlags:(UInt32)flags
{
gpuStateFlags = flags;
if (flags & GPUSTATE_MAIN_GPU_MASK)
{
SetGPUDisplayState(DS_GPU_TYPE_MAIN, true);
}
else
{
SetGPUDisplayState(DS_GPU_TYPE_MAIN, false);
}
if (flags & GPUSTATE_MAIN_BG0_MASK)
{
SetGPULayerState(DS_GPU_TYPE_MAIN, 0, true);
}
else
{
SetGPULayerState(DS_GPU_TYPE_MAIN, 0, false);
}
if (flags & GPUSTATE_MAIN_BG1_MASK)
{
SetGPULayerState(DS_GPU_TYPE_MAIN, 1, true);
}
else
{
SetGPULayerState(DS_GPU_TYPE_MAIN, 1, false);
}
if (flags & GPUSTATE_MAIN_BG2_MASK)
{
SetGPULayerState(DS_GPU_TYPE_MAIN, 2, true);
}
else
{
SetGPULayerState(DS_GPU_TYPE_MAIN, 2, false);
}
if (flags & GPUSTATE_MAIN_BG3_MASK)
{
SetGPULayerState(DS_GPU_TYPE_MAIN, 3, true);
}
else
{
SetGPULayerState(DS_GPU_TYPE_MAIN, 3, false);
}
if (flags & GPUSTATE_MAIN_OBJ_MASK)
{
SetGPULayerState(DS_GPU_TYPE_MAIN, 4, true);
}
else
{
SetGPULayerState(DS_GPU_TYPE_MAIN, 4, false);
}
if (flags & GPUSTATE_SUB_GPU_MASK)
{
SetGPUDisplayState(DS_GPU_TYPE_SUB, true);
}
else
{
SetGPUDisplayState(DS_GPU_TYPE_SUB, false);
}
if (flags & GPUSTATE_SUB_BG0_MASK)
{
SetGPULayerState(DS_GPU_TYPE_SUB, 0, true);
}
else
{
SetGPULayerState(DS_GPU_TYPE_SUB, 0, false);
}
if (flags & GPUSTATE_SUB_BG1_MASK)
{
SetGPULayerState(DS_GPU_TYPE_SUB, 1, true);
}
else
{
SetGPULayerState(DS_GPU_TYPE_SUB, 1, false);
}
if (flags & GPUSTATE_SUB_BG2_MASK)
{
SetGPULayerState(DS_GPU_TYPE_SUB, 2, true);
}
else
{
SetGPULayerState(DS_GPU_TYPE_SUB, 2, false);
}
if (flags & GPUSTATE_SUB_BG3_MASK)
{
SetGPULayerState(DS_GPU_TYPE_SUB, 3, true);
}
else
{
SetGPULayerState(DS_GPU_TYPE_SUB, 3, false);
}
if (flags & GPUSTATE_SUB_OBJ_MASK)
{
SetGPULayerState(DS_GPU_TYPE_SUB, 4, true);
}
else
{
SetGPULayerState(DS_GPU_TYPE_SUB, 4, false);
}
}
- (UInt32) gpuStateFlags
{
return gpuStateFlags;
}
- (void) setCdsController:(CocoaDSController *)theController
{
cdsController = theController;
}
- (CocoaDSController*) cdsController
{
return cdsController;
}
- (void) setViewToBlack
{
[self setScreenState:[ScreenState blackScreenState]];
}
- (void) setViewToWhite
{
[self setScreenState:[ScreenState whiteScreenState]];
}
- (BOOL) gpuStateByBit:(UInt32)stateBit
{
BOOL result = NO;
UInt32 flags = [self gpuStateFlags];
if (flags & (1 << stateBit))
{
result = YES;
}
return result;
}
#ifdef HAVE_OPENGL
- (void)viewDidMoveToWindow
{//if the view moves to another window we need to update the drawable object
@ -250,41 +462,133 @@
#ifdef HAVE_OPENGL
- (void)setBoundsRotation:(CGFloat)angle
{
float old_angle = [self boundsRotation];
int angleInt = (int)angle;
int old_angle = (int)[self boundsRotation];
[super setBoundsRotation:angle];
[super setBoundsRotation:angleInt];
[context makeCurrentContext];
NSSize size = [self frame].size;
if(angle == 0)
if(angleInt == 0)
{
glRasterPos2f(-1, 1);
glPixelZoom(((float)size.width) / ((float)DS_SCREEN_WIDTH), -((float)size.height) / ((float)DS_SCREEN_HEIGHT*2));
} else if(angle == -90)
} else if(angleInt == -90)
{
glRasterPos2f(-1, 1);
glPixelZoom(((float)size.width) / ((float)DS_SCREEN_HEIGHT*2), -((float)size.height) / ((float)DS_SCREEN_WIDTH));
} else if (angle == -180)
} else if (angleInt == -180)
{
glRasterPos2f(1, -1);
glPixelZoom(-((float)size.width) / ((float)DS_SCREEN_WIDTH), ((float)size.height) / ((float)DS_SCREEN_HEIGHT*2));
} else if (angle == -270)
} else if (angleInt == -270)
{
glRasterPos2f(1, -1);
glPixelZoom(-((float)size.width) / ((float)DS_SCREEN_HEIGHT*2), ((float)size.height) / ((float)DS_SCREEN_WIDTH));
}
//Rotate the screen buffer
if(HORIZONTAL(angle) && VERTICAL(old_angle))
if(HORIZONTAL(angleInt) && VERTICAL(old_angle))
[screen_buffer rotateTo90];
if(VERTICAL(angle) && HORIZONTAL(old_angle))
if(VERTICAL(angleInt) && HORIZONTAL(old_angle))
[screen_buffer rotateTo0];
}
#endif
- (NSPoint) convertPointToDS:(NSPoint)touchLoc
{
const CGFloat doubleDisplayHeight = (CGFloat)(GPU_DISPLAY_HEIGHT * 2);
const NSInteger rotation = (NSInteger)[self boundsRotation];
const CGFloat frameWidth = [self frame].size.width;
const CGFloat frameHeight = [self frame].size.height;
if(rotation == 0)
{
// Scale
touchLoc.x *= (CGFloat)GPU_DISPLAY_WIDTH / frameWidth;
touchLoc.y *= doubleDisplayHeight / frameHeight;
}
else if(rotation == -90)
{
// Normalize
touchLoc.x += frameHeight;
// Scale
touchLoc.x *= doubleDisplayHeight / frameWidth;
touchLoc.y *= (CGFloat)GPU_DISPLAY_WIDTH / frameHeight;
}
else if(rotation == -180)
{
// Normalize
touchLoc.x += frameWidth;
touchLoc.y += frameHeight;
// Scale
touchLoc.x *= (CGFloat)GPU_DISPLAY_WIDTH / frameWidth;
touchLoc.y *= doubleDisplayHeight / frameHeight;
}
else if(rotation == -270)
{
// Normalize
touchLoc.y += frameWidth;
// Scale
touchLoc.x *= doubleDisplayHeight / frameWidth;
touchLoc.y *= (CGFloat)GPU_DISPLAY_WIDTH / frameHeight;
}
// Normalize the y-coordinate to the DS.
touchLoc.y = GPU_DISPLAY_HEIGHT - touchLoc.y;
// Constrain the touch point to the DS dimensions.
if (touchLoc.x < 0)
{
touchLoc.x = 0;
}
else if (touchLoc.x > (GPU_DISPLAY_WIDTH - 1))
{
touchLoc.x = (GPU_DISPLAY_WIDTH - 1);
}
if (touchLoc.y < 0)
{
touchLoc.y = 0;
}
else if (touchLoc.y > (GPU_DISPLAY_HEIGHT - 1))
{
touchLoc.y = (GPU_DISPLAY_HEIGHT - 1);
}
return touchLoc;
}
- (void)mouseDown:(NSEvent*)event
{
// Convert the clicked location from window coordinates, to view coordinates,
// and finally to DS touchscreen coordinates.
NSPoint touchLoc = [event locationInWindow];
touchLoc = [self convertPoint:touchLoc fromView:nil];
touchLoc = [self convertPointToDS:touchLoc];
if(touchLoc.x >= 0 && touchLoc.y >= 0)
{
[cdsController touch:touchLoc];
}
}
- (void)mouseDragged:(NSEvent*)event
{
[self mouseDown:event];
}
- (void)mouseUp:(NSEvent*)event
{
[cdsController releaseTouch];
}
@end
#ifdef HAVE_OPENGL
@ -323,3 +627,131 @@
@end
#endif
void SetGPULayerState(int displayType, unsigned int i, bool state)
{
GPU *theGpu = NULL;
// Check bounds on the layer index.
if(i > 4)
{
return;
}
switch (displayType)
{
case DS_GPU_TYPE_MAIN:
theGpu = SubScreen.gpu;
break;
case DS_GPU_TYPE_SUB:
theGpu = MainScreen.gpu;
break;
case DS_GPU_TYPE_COMBO:
SetGPULayerState(DS_GPU_TYPE_SUB, i, state); // Recursive call
theGpu = MainScreen.gpu;
break;
default:
break;
}
if (theGpu != NULL)
{
if (state)
{
GPU_addBack(theGpu, i);
}
else
{
GPU_remove(theGpu, i);
}
}
}
bool GetGPULayerState(int displayType, unsigned int i)
{
bool result = false;
// Check bounds on the layer index.
if(i > 4)
{
return result;
}
switch (displayType)
{
case DS_GPU_TYPE_MAIN:
if (SubScreen.gpu != nil)
{
result = CommonSettings.dispLayers[SubScreen.gpu->core][i];
}
break;
case DS_GPU_TYPE_SUB:
if (MainScreen.gpu != nil)
{
result = CommonSettings.dispLayers[MainScreen.gpu->core][i];
}
break;
case DS_GPU_TYPE_COMBO:
if (SubScreen.gpu != nil && MainScreen.gpu != nil)
{
result = (CommonSettings.dispLayers[SubScreen.gpu->core][i] && CommonSettings.dispLayers[MainScreen.gpu->core][i]);
}
break;
default:
break;
}
return result;
}
void SetGPUDisplayState(int displayType, bool state)
{
switch (displayType)
{
case DS_GPU_TYPE_MAIN:
CommonSettings.showGpu.sub = state;
break;
case DS_GPU_TYPE_SUB:
CommonSettings.showGpu.main = state;
break;
case DS_GPU_TYPE_COMBO:
CommonSettings.showGpu.sub = state;
CommonSettings.showGpu.main = state;
break;
default:
break;
}
}
bool GetGPUDisplayState(int displayType)
{
bool result = false;
switch (displayType)
{
case DS_GPU_TYPE_MAIN:
result = CommonSettings.showGpu.sub;
break;
case DS_GPU_TYPE_SUB:
result = CommonSettings.showGpu.main;
break;
case DS_GPU_TYPE_COMBO:
result = (CommonSettings.showGpu.sub && CommonSettings.showGpu.main);
break;
default:
break;
}
return result;
}