Cocoa Port:

- Convert cocoa_util.m from Obj-C to Obj-C++, and add many new utility methods.
- Remove obsolete globals.h file, and convert needed C functions into Obj-C methods in cocoa_util.mm.
- Add cocoa_file.mm for general file handling methods.
- Change all file handling to use NSURLs instead of NSString paths.
- Refactor existing code to use the new methods.
- Remove obsolete UI code.
- Move Tiger-specific compatibility code to a new file, macosx_10_4_compat.h.
This commit is contained in:
rogerman 2012-01-06 08:53:13 +00:00
parent 5f0805e306
commit cf86f83fb0
23 changed files with 2092 additions and 820 deletions

View File

@ -25,7 +25,6 @@
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
956B96C313DF4CF900FCDCD0 /* slot1_retail_nand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 956B96C213DF4CF900FCDCD0 /* slot1_retail_nand.cpp */; };
AB06CB57135B8A4D00E977B3 /* about.m in Sources */ = {isa = PBXBuildFile; fileRef = AB06CB4B135B8A4D00E977B3 /* about.m */; };
AB06CB58135B8A4D00E977B3 /* cocoa_util.m in Sources */ = {isa = PBXBuildFile; fileRef = AB06CB4C135B8A4D00E977B3 /* cocoa_util.m */; };
AB06CB59135B8A4D00E977B3 /* screen_state.m in Sources */ = {isa = PBXBuildFile; fileRef = AB06CB4D135B8A4D00E977B3 /* screen_state.m */; };
AB06CB5A135B8A4D00E977B3 /* cocoa_input.mm in Sources */ = {isa = PBXBuildFile; fileRef = AB06CB4E135B8A4D00E977B3 /* cocoa_input.mm */; };
AB06CB5B135B8A4D00E977B3 /* input.mm in Sources */ = {isa = PBXBuildFile; fileRef = AB06CB4F135B8A4D00E977B3 /* input.mm */; };
@ -36,7 +35,6 @@
AB06CB60135B8A4D00E977B3 /* screenshot.mm in Sources */ = {isa = PBXBuildFile; fileRef = AB06CB54135B8A4D00E977B3 /* screenshot.mm */; };
AB06CB62135B8A4D00E977B3 /* video_output_view.mm in Sources */ = {isa = PBXBuildFile; fileRef = AB06CB56135B8A4D00E977B3 /* video_output_view.mm */; };
AB06CB63135B8A4D00E977B3 /* about.m in Sources */ = {isa = PBXBuildFile; fileRef = AB06CB4B135B8A4D00E977B3 /* about.m */; };
AB06CB64135B8A4D00E977B3 /* cocoa_util.m in Sources */ = {isa = PBXBuildFile; fileRef = AB06CB4C135B8A4D00E977B3 /* cocoa_util.m */; };
AB06CB65135B8A4D00E977B3 /* screen_state.m in Sources */ = {isa = PBXBuildFile; fileRef = AB06CB4D135B8A4D00E977B3 /* screen_state.m */; };
AB06CB66135B8A4D00E977B3 /* cocoa_input.mm in Sources */ = {isa = PBXBuildFile; fileRef = AB06CB4E135B8A4D00E977B3 /* cocoa_input.mm */; };
AB06CB67135B8A4D00E977B3 /* input.mm in Sources */ = {isa = PBXBuildFile; fileRef = AB06CB4F135B8A4D00E977B3 /* input.mm */; };
@ -232,7 +230,6 @@
AB0A0D1E14AACACC00E83E91 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = AB0A0D1D14AACACC00E83E91 /* libz.dylib */; };
AB0A0D3714AACE9500E83E91 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 1F4B55090F53924500C8B514 /* Localizable.strings */; };
AB0A0D3A14AACE9500E83E91 /* about.m in Sources */ = {isa = PBXBuildFile; fileRef = AB06CB4B135B8A4D00E977B3 /* about.m */; };
AB0A0D3B14AACE9500E83E91 /* cocoa_util.m in Sources */ = {isa = PBXBuildFile; fileRef = AB06CB4C135B8A4D00E977B3 /* cocoa_util.m */; };
AB0A0D3C14AACE9500E83E91 /* screen_state.m in Sources */ = {isa = PBXBuildFile; fileRef = AB06CB4D135B8A4D00E977B3 /* screen_state.m */; };
AB0A0D3D14AACE9500E83E91 /* cocoa_input.mm in Sources */ = {isa = PBXBuildFile; fileRef = AB06CB4E135B8A4D00E977B3 /* cocoa_input.mm */; };
AB0A0D3E14AACE9500E83E91 /* input.mm in Sources */ = {isa = PBXBuildFile; fileRef = AB06CB4F135B8A4D00E977B3 /* input.mm */; };
@ -378,10 +375,19 @@
AB46781714ABD4890002FF94 /* AppIcon_NintendoDS_ROM.icns in Resources */ = {isa = PBXBuildFile; fileRef = AB46780714ABD4890002FF94 /* AppIcon_NintendoDS_ROM.icns */; };
AB46781814ABD4890002FF94 /* AppIcon_ROMSave.icns in Resources */ = {isa = PBXBuildFile; fileRef = AB46780814ABD4890002FF94 /* AppIcon_ROMSave.icns */; };
AB46781914ABD4890002FF94 /* AppIcon_SaveState.icns in Resources */ = {isa = PBXBuildFile; fileRef = AB46780914ABD4890002FF94 /* AppIcon_SaveState.icns */; };
AB8FE37614B652EC009E20B1 /* cocoa_util.mm in Sources */ = {isa = PBXBuildFile; fileRef = AB8FE37514B652EC009E20B1 /* cocoa_util.mm */; };
AB8FE37714B652EC009E20B1 /* cocoa_util.mm in Sources */ = {isa = PBXBuildFile; fileRef = AB8FE37514B652EC009E20B1 /* cocoa_util.mm */; };
AB8FE37814B652EC009E20B1 /* cocoa_util.mm in Sources */ = {isa = PBXBuildFile; fileRef = AB8FE37514B652EC009E20B1 /* cocoa_util.mm */; };
AB8FE37914B652EC009E20B1 /* cocoa_util.mm in Sources */ = {isa = PBXBuildFile; fileRef = AB8FE37514B652EC009E20B1 /* cocoa_util.mm */; };
AB8FE48C14B6657D009E20B1 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = AB0A0D1D14AACACC00E83E91 /* libz.dylib */; };
ABBF04BD14B519A500E505A0 /* MainMenu (Legacy).xib in Resources */ = {isa = PBXBuildFile; fileRef = ABBF04BC14B519A500E505A0 /* MainMenu (Legacy).xib */; };
ABBF04BE14B519A500E505A0 /* MainMenu (Legacy).xib in Resources */ = {isa = PBXBuildFile; fileRef = ABBF04BC14B519A500E505A0 /* MainMenu (Legacy).xib */; };
ABBF04BF14B519A500E505A0 /* MainMenu (Legacy).xib in Resources */ = {isa = PBXBuildFile; fileRef = ABBF04BC14B519A500E505A0 /* MainMenu (Legacy).xib */; };
ABBF04C014B519A500E505A0 /* MainMenu (Legacy).xib in Resources */ = {isa = PBXBuildFile; fileRef = ABBF04BC14B519A500E505A0 /* MainMenu (Legacy).xib */; };
ABBF053014B5436E00E505A0 /* cocoa_file.mm in Sources */ = {isa = PBXBuildFile; fileRef = ABBF052F14B5436E00E505A0 /* cocoa_file.mm */; };
ABBF053114B5436E00E505A0 /* cocoa_file.mm in Sources */ = {isa = PBXBuildFile; fileRef = ABBF052F14B5436E00E505A0 /* cocoa_file.mm */; };
ABBF053214B5436E00E505A0 /* cocoa_file.mm in Sources */ = {isa = PBXBuildFile; fileRef = ABBF052F14B5436E00E505A0 /* cocoa_file.mm */; };
ABBF053314B5436E00E505A0 /* cocoa_file.mm in Sources */ = {isa = PBXBuildFile; fileRef = ABBF052F14B5436E00E505A0 /* cocoa_file.mm */; };
ABF4007714B4F19200578AE7 /* AppIcon_ROMCheats.icns in Resources */ = {isa = PBXBuildFile; fileRef = ABF4007614B4F19200578AE7 /* AppIcon_ROMCheats.icns */; };
ABF4007814B4F19200578AE7 /* AppIcon_ROMCheats.icns in Resources */ = {isa = PBXBuildFile; fileRef = ABF4007614B4F19200578AE7 /* AppIcon_ROMCheats.icns */; };
ABF4007914B4F19200578AE7 /* AppIcon_ROMCheats.icns in Resources */ = {isa = PBXBuildFile; fileRef = ABF4007614B4F19200578AE7 /* AppIcon_ROMCheats.icns */; };
@ -392,7 +398,6 @@
ABF4008214B4F1C000578AE7 /* sndOSX.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ABF4007E14B4F1C000578AE7 /* sndOSX.cpp */; };
ABFE4242143E32F0009A3CCE /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 1F4B55090F53924500C8B514 /* Localizable.strings */; };
ABFE4245143E32F0009A3CCE /* about.m in Sources */ = {isa = PBXBuildFile; fileRef = AB06CB4B135B8A4D00E977B3 /* about.m */; };
ABFE4246143E32F0009A3CCE /* cocoa_util.m in Sources */ = {isa = PBXBuildFile; fileRef = AB06CB4C135B8A4D00E977B3 /* cocoa_util.m */; };
ABFE4247143E32F0009A3CCE /* screen_state.m in Sources */ = {isa = PBXBuildFile; fileRef = AB06CB4D135B8A4D00E977B3 /* screen_state.m */; };
ABFE4248143E32F0009A3CCE /* cocoa_input.mm in Sources */ = {isa = PBXBuildFile; fileRef = AB06CB4E135B8A4D00E977B3 /* cocoa_input.mm */; };
ABFE4249143E32F0009A3CCE /* input.mm in Sources */ = {isa = PBXBuildFile; fileRef = AB06CB4F135B8A4D00E977B3 /* input.mm */; };
@ -519,7 +524,6 @@
7FA9121F1426523900E2ABDD /* tinyxmlparser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = tinyxmlparser.cpp; sourceTree = "<group>"; };
956B96C213DF4CF900FCDCD0 /* slot1_retail_nand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = slot1_retail_nand.cpp; path = ../addons/slot1_retail_nand.cpp; sourceTree = SOURCE_ROOT; };
AB06CB41135B8A4D00E977B3 /* cocoa_input.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cocoa_input.h; sourceTree = "<group>"; };
AB06CB42135B8A4D00E977B3 /* globals.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = globals.h; sourceTree = "<group>"; };
AB06CB43135B8A4D00E977B3 /* input.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = input.h; sourceTree = "<group>"; };
AB06CB44135B8A4D00E977B3 /* main_window.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = main_window.h; sourceTree = "<group>"; };
AB06CB45135B8A4D00E977B3 /* nds_control.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = nds_control.h; sourceTree = "<group>"; };
@ -529,7 +533,6 @@
AB06CB49135B8A4D00E977B3 /* sndOSX.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sndOSX.h; sourceTree = "<group>"; };
AB06CB4A135B8A4D00E977B3 /* video_output_view.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = video_output_view.h; sourceTree = "<group>"; };
AB06CB4B135B8A4D00E977B3 /* about.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = about.m; sourceTree = "<group>"; };
AB06CB4C135B8A4D00E977B3 /* cocoa_util.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = cocoa_util.m; sourceTree = "<group>"; };
AB06CB4D135B8A4D00E977B3 /* screen_state.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = screen_state.m; sourceTree = "<group>"; };
AB06CB4E135B8A4D00E977B3 /* cocoa_input.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = cocoa_input.mm; sourceTree = "<group>"; };
AB06CB4F135B8A4D00E977B3 /* input.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = input.mm; sourceTree = "<group>"; };
@ -750,6 +753,9 @@
AB46780714ABD4890002FF94 /* AppIcon_NintendoDS_ROM.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = AppIcon_NintendoDS_ROM.icns; sourceTree = "<group>"; };
AB46780814ABD4890002FF94 /* AppIcon_ROMSave.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = AppIcon_ROMSave.icns; sourceTree = "<group>"; };
AB46780914ABD4890002FF94 /* AppIcon_SaveState.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = AppIcon_SaveState.icns; sourceTree = "<group>"; };
AB8FE30A14B647D6009E20B1 /* macosx_10_4_compat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = macosx_10_4_compat.h; sourceTree = "<group>"; };
AB8FE37414B652EC009E20B1 /* cocoa_util.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cocoa_util.h; sourceTree = "<group>"; };
AB8FE37514B652EC009E20B1 /* cocoa_util.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = cocoa_util.mm; sourceTree = "<group>"; };
ABBF045E14B5144D00E505A0 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = "translations/English.lproj/MainMenu (Legacy).xib"; sourceTree = "<group>"; };
ABBF04C114B519CD00E505A0 /* French */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = French; path = "translations/French.lproj/MainMenu (Legacy).xib"; sourceTree = "<group>"; };
ABBF04C314B519DF00E505A0 /* Italian */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Italian; path = "translations/Italian.lproj/MainMenu (Legacy).xib"; sourceTree = "<group>"; };
@ -760,6 +766,8 @@
ABBF04CB14B51BBB00E505A0 /* Chinese */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Chinese; path = translations/Chinese.lproj/Localizable.strings; sourceTree = "<group>"; };
ABBF04CC14B51BC300E505A0 /* Norwegian */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Norwegian; path = translations/Norwegian.lproj/Localizable.strings; sourceTree = "<group>"; };
ABBF04CD14B51BC900E505A0 /* Romanian */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Romanian; path = translations/Romanian.lproj/Localizable.strings; sourceTree = "<group>"; };
ABBF052F14B5436E00E505A0 /* cocoa_file.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = cocoa_file.mm; sourceTree = "<group>"; };
ABBF053B14B543B600E505A0 /* cocoa_file.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cocoa_file.h; sourceTree = "<group>"; };
ABF4007614B4F19200578AE7 /* AppIcon_ROMCheats.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = AppIcon_ROMCheats.icns; sourceTree = "<group>"; };
ABF4007E14B4F1C000578AE7 /* sndOSX.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sndOSX.cpp; sourceTree = "<group>"; };
ABF95B4714B4F4FC007912B8 /* cocoa_globals.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cocoa_globals.h; sourceTree = "<group>"; };
@ -814,6 +822,7 @@
ABFE42AF143E32F0009A3CCE /* AudioUnit.framework in Frameworks */,
ABFE42B0143E32F0009A3CCE /* AppKit.framework in Frameworks */,
ABFE42B1143E32F0009A3CCE /* Foundation.framework in Frameworks */,
AB8FE48C14B6657D009E20B1 /* libz.dylib in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -825,10 +834,12 @@
children = (
AB06CEC4135B8E0B00E977B3 /* dialogs */,
ABF4007E14B4F1C000578AE7 /* sndOSX.cpp */,
ABBF053B14B543B600E505A0 /* cocoa_file.h */,
ABF95B4714B4F4FC007912B8 /* cocoa_globals.h */,
AB06CB41135B8A4D00E977B3 /* cocoa_input.h */,
AB06CB42135B8A4D00E977B3 /* globals.h */,
AB8FE37414B652EC009E20B1 /* cocoa_util.h */,
AB06CB43135B8A4D00E977B3 /* input.h */,
AB8FE30A14B647D6009E20B1 /* macosx_10_4_compat.h */,
AB06CB44135B8A4D00E977B3 /* main_window.h */,
AB06CB45135B8A4D00E977B3 /* nds_control.h */,
AB06CB46135B8A4D00E977B3 /* preferences.h */,
@ -837,9 +848,10 @@
AB06CB49135B8A4D00E977B3 /* sndOSX.h */,
AB06CB4A135B8A4D00E977B3 /* video_output_view.h */,
AB06CB4B135B8A4D00E977B3 /* about.m */,
AB06CB4C135B8A4D00E977B3 /* cocoa_util.m */,
AB06CB4D135B8A4D00E977B3 /* screen_state.m */,
ABBF052F14B5436E00E505A0 /* cocoa_file.mm */,
AB06CB4E135B8A4D00E977B3 /* cocoa_input.mm */,
AB8FE37514B652EC009E20B1 /* cocoa_util.mm */,
AB06CB4F135B8A4D00E977B3 /* input.mm */,
AB06CB51135B8A4D00E977B3 /* main.mm */,
AB06CB50135B8A4D00E977B3 /* main_window.mm */,
@ -1446,7 +1458,6 @@
buildActionMask = 2147483647;
files = (
AB06CB63135B8A4D00E977B3 /* about.m in Sources */,
AB06CB64135B8A4D00E977B3 /* cocoa_util.m in Sources */,
AB06CB65135B8A4D00E977B3 /* screen_state.m in Sources */,
AB06CB66135B8A4D00E977B3 /* cocoa_input.mm in Sources */,
AB06CB67135B8A4D00E977B3 /* input.mm in Sources */,
@ -1557,6 +1568,8 @@
7FA912261426523900E2ABDD /* tinyxmlerror.cpp in Sources */,
7FA912271426523900E2ABDD /* tinyxmlparser.cpp in Sources */,
ABF4008214B4F1C000578AE7 /* sndOSX.cpp in Sources */,
ABBF053314B5436E00E505A0 /* cocoa_file.mm in Sources */,
AB8FE37914B652EC009E20B1 /* cocoa_util.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -1565,7 +1578,6 @@
buildActionMask = 2147483647;
files = (
AB06CB57135B8A4D00E977B3 /* about.m in Sources */,
AB06CB58135B8A4D00E977B3 /* cocoa_util.m in Sources */,
AB06CB59135B8A4D00E977B3 /* screen_state.m in Sources */,
AB06CB5A135B8A4D00E977B3 /* cocoa_input.mm in Sources */,
AB06CB5B135B8A4D00E977B3 /* input.mm in Sources */,
@ -1666,6 +1678,8 @@
7FA912221426523900E2ABDD /* tinyxmlerror.cpp in Sources */,
7FA912231426523900E2ABDD /* tinyxmlparser.cpp in Sources */,
ABF4007F14B4F1C000578AE7 /* sndOSX.cpp in Sources */,
ABBF053014B5436E00E505A0 /* cocoa_file.mm in Sources */,
AB8FE37714B652EC009E20B1 /* cocoa_util.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -1674,7 +1688,6 @@
buildActionMask = 2147483647;
files = (
AB0A0D3A14AACE9500E83E91 /* about.m in Sources */,
AB0A0D3B14AACE9500E83E91 /* cocoa_util.m in Sources */,
AB0A0D3C14AACE9500E83E91 /* screen_state.m in Sources */,
AB0A0D3D14AACE9500E83E91 /* cocoa_input.mm in Sources */,
AB0A0D3E14AACE9500E83E91 /* input.mm in Sources */,
@ -1775,6 +1788,8 @@
AB0A0D9F14AACE9500E83E91 /* tinyxmlerror.cpp in Sources */,
AB0A0DA014AACE9500E83E91 /* tinyxmlparser.cpp in Sources */,
ABF4008014B4F1C000578AE7 /* sndOSX.cpp in Sources */,
ABBF053114B5436E00E505A0 /* cocoa_file.mm in Sources */,
AB8FE37614B652EC009E20B1 /* cocoa_util.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -1783,7 +1798,6 @@
buildActionMask = 2147483647;
files = (
ABFE4245143E32F0009A3CCE /* about.m in Sources */,
ABFE4246143E32F0009A3CCE /* cocoa_util.m in Sources */,
ABFE4247143E32F0009A3CCE /* screen_state.m in Sources */,
ABFE4248143E32F0009A3CCE /* cocoa_input.mm in Sources */,
ABFE4249143E32F0009A3CCE /* input.mm in Sources */,
@ -1884,6 +1898,8 @@
ABFE42AA143E32F0009A3CCE /* tinyxmlerror.cpp in Sources */,
ABFE42AB143E32F0009A3CCE /* tinyxmlparser.cpp in Sources */,
ABF4008114B4F1C000578AE7 /* sndOSX.cpp in Sources */,
ABBF053214B5436E00E505A0 /* cocoa_file.mm in Sources */,
AB8FE37814B652EC009E20B1 /* cocoa_util.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@ -1,20 +1,19 @@
/* Copyright (C) 2011 Roger Manuel
This file is part of DeSmuME
DeSmuME 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.
DeSmuME 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 DeSmuME; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
/*
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/>.
*/
#ifdef __OBJC__
@ -23,4 +22,5 @@
#define DESMUME_COCOA
#define HAVE_OPENGL
#define HAVE_LIBZ
#define HAVE_LIBZ
#define PORT_VERSION "Cocoa"

View File

@ -1,27 +1,29 @@
/* Copyright (C) 2007 Jeff Bland
/*
Copyright (C) 2007 Jeff Bland
Copyright (C) 2011 Roger Manuel
Copyright (C) 2012 DeSmuME team
This file is part of DeSmuME
DeSmuME is free software; you can redistribute it and/or modify
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
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
DeSmuME is distributed in the hope that it will be useful,
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 DeSmuME; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
along with the this software. If not, see <http://www.gnu.org/licenses/>.
*/
#import "globals.h"
#import <Cocoa/Cocoa.h>
#define STRING_DESMUME_WEBSITE "http://www.desmume.org"
#define STRING_DESMUME_FORUM_SITE "http://forums.desmume.org/index.php"
#define STRING_DESMUME_BUG_SITE "http://sourceforge.net/tracker/?group_id=164579&atid=832291"
#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
#include "macosx_10_4_compat.h"
#endif
#import "cocoa_globals.h"
#define STRING_FILENAME_README "README"
#define STRING_FILENAME_COPYING "COPYING"

View File

@ -0,0 +1,65 @@
/*
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>
#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
#include "macosx_10_4_compat.h"
#endif
@interface CocoaDSFile : NSDocument
{
}
+ (BOOL) loadState:(NSURL *)saveStateURL;
+ (BOOL) saveState:(NSURL *)saveStateURL;
+ (BOOL) loadRom:(NSURL *)romURL;
+ (BOOL) importRomSave:(NSURL *)romSaveURL;
+ (BOOL) exportRomSave:(NSURL *)romSaveURL;
+ (NSURL *) romSaveURLFromRomURL:(NSURL *)romURL;
+ (NSURL *) cheatsURLFromRomURL:(NSURL *)romURL;
+ (BOOL) romSaveExists:(NSURL *)romURL;
+ (BOOL) romSaveExistsWithRom:(NSURL *)romURL;
+ (void) setupAllFilePaths;
+ (BOOL) setupAllAppDirectories;
+ (NSURL *) saveStateURL;
+ (BOOL) saveStateExistsForSlot:(NSURL *)romURL slotNumber:(NSUInteger)slotNumber;
+ (BOOL) isSaveStateSlotExtension:(NSString *)extension;
+ (NSString *) getSaveSlotFileName:(NSURL *)romURL slotNumber:(NSUInteger)slotNumber;
+ (NSString *) fileKind:(NSURL *)fileURL;
+ (NSString *) fileVersion:(NSURL *)fileURL;
+ (BOOL) fileExistsForCurrent:(NSURL *)fileURL;
+ (NSURL *) getURLUserAppSupportByKind:(NSString *)fileKind;
+ (NSURL *) getBaseURLUserAppSupport;
+ (NSURL *) getURLUserAppSupport:(NSString *)directoryName appVersion:(NSString *)appVersion;
+ (BOOL) createUserAppSupportDirectory:(NSString *)directoryName;
+ (NSURL *) lastLoadedRomURL;
#if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4
+ (BOOL) moveFileToCurrentDirectory:(NSURL *)fileURL;
+ (BOOL) copyFileToCurrentDirectory:(NSURL *)fileURL;
+ (BOOL) moveFileListToCurrent:(NSMutableArray *)fileList;
+ (BOOL) copyFileListToCurrent:(NSMutableArray *)fileList;
+ (NSMutableArray *) completeFileList;
+ (NSMutableArray *) appFileList:(NSURL *)directoryURL;
+ (NSMutableArray *) appFileList:(NSURL *)directoryURL fileKind:(NSString *)theFileKind;
#endif
@end

View File

@ -0,0 +1,835 @@
/*
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_file.h"
#include <libkern/OSAtomic.h>
#import "cocoa_globals.h"
#import "cocoa_util.h"
#include "../NDSSystem.h"
#include "../path.h"
#include "../saves.h"
#undef BOOL
@implementation CocoaDSFile
+ (BOOL) loadState:(NSURL *)saveStateURL
{
BOOL result = NO;
if (saveStateURL == nil)
{
return result;
}
const char *statePath = [[saveStateURL path] cStringUsingEncoding:NSUTF8StringEncoding];
bool cResult = savestate_load(statePath);
if(cResult)
{
result = YES;
}
return result;
}
+ (BOOL) saveState:(NSURL *)saveStateURL
{
BOOL result = NO;
if (saveStateURL == nil)
{
return result;
}
const char *statePath = [[saveStateURL path] cStringUsingEncoding:NSUTF8StringEncoding];
bool cResult = savestate_save(statePath);
if(cResult)
{
result = YES;
}
return result;
}
+ (BOOL) loadRom:(NSURL *)romURL
{
BOOL result = NO;
if (romURL == nil)
{
return result;
}
const char *romPath = [[romURL path] cStringUsingEncoding:NSUTF8StringEncoding];
NSInteger resultCode = NDS_LoadROM(romPath, nil);
if (resultCode > 0)
{
result = YES;
}
return result;
}
+ (BOOL) importRomSave:(NSURL *)romSaveURL
{
BOOL result = NO;
const char *romSavePath = [[romSaveURL path] cStringUsingEncoding:NSUTF8StringEncoding];
NSInteger resultCode = NDS_ImportSave(romSavePath);
if (resultCode == 0)
{
return result;
}
result = YES;
return result;
}
+ (BOOL) exportRomSave:(NSURL *)romSaveURL
{
BOOL result = NO;
const char *romSavePath = [[romSaveURL path] cStringUsingEncoding:NSUTF8StringEncoding];
NSInteger resultCode = NDS_ExportSave(romSavePath);
if (resultCode == 0)
{
return result;
}
result = YES;
return result;
}
+ (NSURL *) romSaveURLFromRomURL:(NSURL *)romURL
{
return [NSURL fileURLWithPath:[[[romURL path] stringByDeletingPathExtension] stringByAppendingPathExtension:@FILE_EXT_ROM_SAVE]];
}
+ (NSURL *) cheatsURLFromRomURL:(NSURL *)romURL
{
return [NSURL fileURLWithPath:[[[romURL path] stringByDeletingPathExtension] stringByAppendingPathExtension:@FILE_EXT_CHEAT]];
}
+ (BOOL) romSaveExists:(NSURL *)romURL
{
BOOL exists = NO;
if (romURL == nil)
{
return exists;
}
NSString *romSaveFileName = [[[[romURL path] stringByDeletingPathExtension] stringByAppendingPathExtension:@FILE_EXT_ROM_SAVE] lastPathComponent];
NSURL *romSaveURL = [CocoaDSFile getURLUserAppSupport:@BATTERYKEY appVersion:nil];
NSString *romSavePath = [romSaveURL path];
romSavePath = [romSavePath stringByAppendingPathComponent:romSaveFileName];
NSFileManager *fileManager = [[NSFileManager alloc] init];
exists = [fileManager isReadableFileAtPath:romSavePath];
[fileManager release];
return exists;
}
+ (BOOL) romSaveExistsWithRom:(NSURL *)romURL
{
BOOL exists = NO;
if (romURL == nil)
{
return exists;
}
NSString *romSavePath = [[CocoaDSFile romSaveURLFromRomURL:romURL] path];
NSFileManager *fileManager = [[NSFileManager alloc] init];
exists = [fileManager isReadableFileAtPath:romSavePath];
[fileManager release];
return exists;
}
+ (void) setupAllFilePaths
{
NSURL *romURL = [CocoaDSFile getURLUserAppSupport:@ROMKEY appVersion:nil];
NSURL *romSaveURL = [CocoaDSFile getURLUserAppSupport:@BATTERYKEY appVersion:nil];
NSURL *saveStateURL = [CocoaDSFile getURLUserAppSupport:@STATEKEY appVersion:nil];
NSURL *screenshotURL = [CocoaDSFile getURLUserAppSupport:@SCREENSHOTKEY appVersion:nil];
NSURL *aviURL = [CocoaDSFile getURLUserAppSupport:@AVIKEY appVersion:nil];
NSURL *cheatURL = [CocoaDSFile getURLUserAppSupport:@CHEATKEY appVersion:nil];
NSURL *soundSamplesURL = [CocoaDSFile getURLUserAppSupport:@SOUNDKEY appVersion:nil];
NSURL *firmwareURL = [CocoaDSFile getURLUserAppSupport:@FIRMWAREKEY appVersion:nil];
NSURL *luaURL = [CocoaDSFile getURLUserAppSupport:@LUAKEY appVersion:nil];
strlcpy(path.pathToRoms, [[romURL path] cStringUsingEncoding:NSUTF8StringEncoding], MAX_PATH);
strlcpy(path.pathToBattery, [[romSaveURL path] cStringUsingEncoding:NSUTF8StringEncoding], MAX_PATH);
strlcpy(path.pathToStates, [[saveStateURL path] cStringUsingEncoding:NSUTF8StringEncoding], MAX_PATH);
strlcpy(path.pathToScreenshots, [[screenshotURL path] cStringUsingEncoding:NSUTF8StringEncoding], MAX_PATH);
strlcpy(path.pathToAviFiles, [[aviURL path] cStringUsingEncoding:NSUTF8StringEncoding], MAX_PATH);
strlcpy(path.pathToCheats, [[cheatURL path] cStringUsingEncoding:NSUTF8StringEncoding], MAX_PATH);
strlcpy(path.pathToSounds, [[soundSamplesURL path] cStringUsingEncoding:NSUTF8StringEncoding], MAX_PATH);
strlcpy(path.pathToFirmware, [[firmwareURL path] cStringUsingEncoding:NSUTF8StringEncoding], MAX_PATH);
strlcpy(path.pathToLua, [[luaURL path] cStringUsingEncoding:NSUTF8StringEncoding], MAX_PATH);
}
+ (BOOL) setupAllAppDirectories
{
BOOL result = NO;
if (![CocoaDSFile createUserAppSupportDirectory:@BATTERYKEY])
{
return result;
}
if (![CocoaDSFile createUserAppSupportDirectory:@STATEKEY])
{
return result;
}
if (![CocoaDSFile createUserAppSupportDirectory:@CHEATKEY])
{
return result;
}
result = YES;
return result;
}
+ (NSURL *) saveStateURL
{
return [CocoaDSFile getURLUserAppSupport:@STATEKEY appVersion:nil];
}
/********************************************************************************************
fileKind:
Determines a DeSmuME file's type, and returns a description as a string.
Takes:
fileURL - An NSURL that points to a file.
Returns:
An NSString representing the file type. The NSString will be nil if the file
type is not recognized as a DeSmuME file.
Details:
This is not the most reliable method for determining a file's type. The current
implementation simply checks the file extension to determine the file type.
Future implementations could be made more reliable by actually opening the file
and validating some header info.
********************************************************************************************/
+ (NSString *) fileKind:(NSURL *)fileURL
{
NSString *fileKind = nil;
if (fileURL == nil)
{
return fileKind;
}
NSString *fileExt = [[fileURL path] pathExtension];
if ([fileExt isEqualToString:@FILE_EXT_ROM_SAVE])
{
fileKind = @"ROM Save";
}
else if ([fileExt isEqualToString:@FILE_EXT_CHEAT])
{
fileKind = @"Cheat File";
}
else if ([fileExt isEqualToString:@FILE_EXT_FIRMWARE_CONFIG])
{
fileKind = @"Firmware Configuration";
}
else if ([CocoaDSFile isSaveStateSlotExtension:fileExt])
{
fileKind = @"Save State";
}
else if ([fileExt isEqualToString:@FILE_EXT_ROM_DS])
{
fileKind = @"DS ROM";
}
else if ([fileExt isEqualToString:@FILE_EXT_ROM_GBA])
{
fileKind = @"GBA ROM";
}
return fileKind;
}
+ (NSString *) fileVersion:(NSURL *)fileURL
{
NSString *fileVersion = @"Unknown Version";
if (fileURL == nil)
{
return fileVersion;
}
NSString *versionStr = nil;
NSString *portStr = nil;
NSString *filePath = [fileURL path];
NSURL *versionURL = nil;
NSString *versionPath = @PATH_CONFIG_DIRECTORY_0_9_6;
versionPath = [versionPath stringByExpandingTildeInPath];
if ([[filePath stringByDeletingLastPathComponent] isEqualToString:versionPath])
{
versionStr = @"0.9.6";
portStr = @"GTK";
}
versionURL = [CocoaDSFile getURLUserAppSupport:nil appVersion:@"0.9.7"];
versionPath = [versionURL path];
if (versionPath != nil && [[[filePath stringByDeletingLastPathComponent] stringByDeletingLastPathComponent] isEqualToString:versionPath])
{
versionStr = @"0.9.7";
portStr = @"Cocoa";
}
versionURL = [CocoaDSFile getURLUserAppSupport:nil appVersion:@"0.9.8"];
versionPath = [versionURL path];
if (versionPath != nil && [[[filePath stringByDeletingLastPathComponent] stringByDeletingLastPathComponent] isEqualToString:versionPath])
{
versionStr = @"0.9.8";
portStr = @"Cocoa";
}
fileVersion = [[versionStr stringByAppendingString:@" "] stringByAppendingString:portStr];
return fileVersion;
}
+ (BOOL) fileExistsForCurrent:(NSURL *)fileURL
{
BOOL result = NO;
NSString *currentVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
NSDictionary *versionSearchDict = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"VersionPaths" ofType:@"plist"]];
if (fileURL == nil)
{
return result;
}
else if (currentVersion == nil)
{
NSLog(@"Could not read the main application bundle!");
return result;
}
else if (versionSearchDict == nil)
{
NSLog(@"Could not read the version plist file!");
return result;
}
NSDictionary *versionDict = [versionSearchDict valueForKey:currentVersion];
NSDictionary *portDict = [versionDict valueForKey:@PORT_VERSION];
NSFileManager *fileManager = [[NSFileManager alloc] init];
NSString *existsPath = [[CocoaDSFile getURLUserAppSupportByKind:[CocoaDSFile fileKind:fileURL]] path];
if (existsPath == nil)
{
return result;
}
existsPath = [existsPath stringByAppendingPathComponent:[[fileURL path] lastPathComponent]];
result = [fileManager fileExistsAtPath:existsPath];
[fileManager release];
return result;
}
+ (NSURL *) getURLUserAppSupportByKind:(NSString *)fileKind
{
NSURL *fileURL = nil;
if ([fileKind isEqualToString:@"ROM Save"])
{
fileURL = [CocoaDSFile getURLUserAppSupport:@BATTERYKEY appVersion:nil];
}
else if ([fileKind isEqualToString:@"Cheat File"])
{
fileURL = [CocoaDSFile getURLUserAppSupport:@CHEATKEY appVersion:nil];
}
else if ([fileKind isEqualToString:@"Firmware Configuration"])
{
fileURL = [CocoaDSFile getURLUserAppSupport:@FIRMWAREKEY appVersion:nil];
}
else if ([fileKind isEqualToString:@"Save State"])
{
fileURL = [CocoaDSFile getURLUserAppSupport:@STATEKEY appVersion:nil];
}
return fileURL;
}
+ (BOOL) saveStateExistsForSlot:(NSURL *)romURL slotNumber:(NSUInteger)slotNumber
{
BOOL exists = NO;
if (romURL == nil)
{
return exists;
}
if (slotNumber == 10)
{
slotNumber = 0;
}
NSURL *searchURL = [CocoaDSFile getURLUserAppSupport:@STATEKEY appVersion:nil];
NSString *searchFileName = [CocoaDSFile getSaveSlotFileName:romURL slotNumber:slotNumber];
if (searchURL == nil || searchFileName == nil)
{
return exists;
}
NSString *searchFullPath = [[searchURL path] stringByAppendingPathComponent:searchFileName];
NSFileManager *fileManager = [[NSFileManager alloc] init];
exists = [fileManager isReadableFileAtPath:searchFullPath];
[fileManager release];
return exists;
}
/********************************************************************************************
isSaveStateSlotExtension:
Determines if a given extension represents a save state file type.
Takes:
extension - An NSString representing the file extension.
Returns:
A BOOL indicating if extension represents a save state file type.
Details:
Save state file extensions are represented by .ds#, where # is an integer that
is greater than or equal to 0.
********************************************************************************************/
+ (BOOL) isSaveStateSlotExtension:(NSString *)extension
{
BOOL result = NO;
if ([extension length] < 3 || ![extension hasPrefix:@"ds"])
{
return result;
}
NSString *slotNum = [extension substringFromIndex:2];
if ([slotNum isEqualToString:@"0"])
{
result = YES;
}
else if ([slotNum intValue] != 0)
{
result = YES;
}
return result;
}
+ (NSString *) getSaveSlotFileName:(NSURL *)romURL slotNumber:(NSUInteger)slotNumber
{
if (romURL == nil)
{
return nil;
}
if (slotNumber == 10)
{
slotNumber = 0;
}
NSString *romFileName = [[romURL path] lastPathComponent];
NSString *fileExt = [NSString stringWithFormat:@"ds%d", slotNumber];
return [[romFileName stringByDeletingPathExtension] stringByAppendingPathExtension:fileExt];
}
+ (NSURL *) getBaseURLUserAppSupport
{
NSURL *userAppSupportURL = nil;
NSString *userAppSupportPath = nil;
NSString *appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
NSArray *savePaths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
if ([savePaths count] == 0)
{
return userAppSupportURL;
}
userAppSupportPath = [[savePaths objectAtIndex:0] stringByAppendingPathComponent:appName];
userAppSupportURL = [NSURL fileURLWithPath:userAppSupportPath];
return userAppSupportURL;
}
+ (NSURL *) getURLUserAppSupport:(NSString *)directoryName appVersion:(NSString *)appVersion
{
NSURL *userAppSupportURL = [CocoaDSFile getBaseURLUserAppSupport];
if (userAppSupportURL == nil)
{
return userAppSupportURL;
}
NSString *userAppSupportPath = [userAppSupportURL path];
NSString *appVersionForURL = appVersion;
// If nil is passed in for appVersion, then just use the current app version.
if (appVersionForURL == nil)
{
appVersionForURL = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
}
userAppSupportPath = [userAppSupportPath stringByAppendingPathComponent:appVersionForURL];
if (directoryName != nil)
{
userAppSupportPath = [userAppSupportPath stringByAppendingPathComponent:directoryName];
}
userAppSupportURL = [NSURL fileURLWithPath:userAppSupportPath];
return userAppSupportURL;
}
+ (BOOL) createUserAppSupportDirectory:(NSString *)directoryName
{
BOOL result = NO;
NSString *tempPath = nil;
NSString *appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
NSString *appVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
if (directoryName == nil)
{
return result;
}
NSArray *savePaths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
if ([savePaths count] > 0)
{
tempPath = [savePaths objectAtIndex:0];
}
else
{
return result;
}
NSFileManager *fileManager = [[NSFileManager alloc] init];
#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 // Mac OS X v10.4 and earlier.
BOOL isDir = YES;
tempPath = [tempPath stringByAppendingPathComponent:appName];
result = [fileManager createDirectoryAtPath:tempPath attributes:nil];
if (!result)
{
if(![fileManager fileExistsAtPath:tempPath isDirectory:&isDir])
{
[fileManager release];
return result;
}
}
tempPath = [tempPath stringByAppendingPathComponent:appVersion];
result = [fileManager createDirectoryAtPath:tempPath attributes:nil];
if (!result)
{
if(![fileManager fileExistsAtPath:tempPath isDirectory:&isDir])
{
[fileManager release];
return result;
}
}
tempPath = [tempPath stringByAppendingPathComponent:directoryName];
result = [fileManager createDirectoryAtPath:tempPath attributes:nil];
if (!result)
{
if(![fileManager fileExistsAtPath:tempPath isDirectory:&isDir])
{
[fileManager release];
return result;
}
}
/*
In Mac OS X v10.4 and earlier, having the File Manager create new directories where they already
exist returns NO. Note that this behavior is not per Apple's own documentation. Therefore, we
manually set result=YES at the end to make sure the function returns the right result.
*/
result = YES;
#else // Mac OS X v10.5 and later. Yes, it's that simple...
tempPath = [tempPath stringByAppendingPathComponent:appName];
tempPath = [tempPath stringByAppendingPathComponent:appVersion];
tempPath = [tempPath stringByAppendingPathComponent:directoryName];
result = [fileManager createDirectoryAtPath:tempPath withIntermediateDirectories:YES attributes:nil error:NULL];
#endif
[fileManager release];
return result;
}
+ (NSURL *) lastLoadedRomURL
{
return [[[NSDocumentController sharedDocumentController] recentDocumentURLs] objectAtIndex:0];
}
#if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4
+ (BOOL) moveFileToCurrentDirectory:(NSURL *)fileURL
{
BOOL result = NO;
if (fileURL == nil)
{
return result;
}
NSFileManager *fileManager = [[NSFileManager alloc] init];
NSString *newLocationPath = [[CocoaDSFile getURLUserAppSupportByKind:[CocoaDSFile fileKind:fileURL]] path];
if (newLocationPath == nil)
{
return result;
}
NSString *filePath = [fileURL path];
newLocationPath = [newLocationPath stringByAppendingPathComponent:[filePath lastPathComponent]];
result = [fileManager moveItemAtPath:filePath toPath:newLocationPath error:nil];
[fileManager release];
return result;
}
+ (BOOL) copyFileToCurrentDirectory:(NSURL *)fileURL
{
BOOL result = NO;
if (fileURL == nil)
{
return result;
}
NSFileManager *fileManager = [[NSFileManager alloc] init];
NSString *newLocationPath = [[CocoaDSFile getURLUserAppSupportByKind:[CocoaDSFile fileKind:fileURL]] path];
if (newLocationPath == nil)
{
return result;
}
NSString *filePath = [fileURL path];
newLocationPath = [newLocationPath stringByAppendingPathComponent:[filePath lastPathComponent]];
result = [fileManager copyItemAtPath:filePath toPath:newLocationPath error:nil];
[fileManager release];
return result;
}
+ (BOOL) moveFileListToCurrent:(NSMutableArray *)fileList
{
BOOL result = NO;
if (fileList == nil)
{
return result;
}
for (NSDictionary *fileDict in fileList)
{
BOOL willMigrate = [[fileDict valueForKey:@"willMigrate"] boolValue];
if (!willMigrate)
{
continue;
}
NSURL *fileURL = [NSURL URLWithString:[fileDict valueForKey:@"URL"]];
[CocoaDSFile moveFileToCurrentDirectory:fileURL];
}
result = YES;
return result;
}
+ (BOOL) copyFileListToCurrent:(NSMutableArray *)fileList
{
BOOL result = NO;
if (fileList == nil)
{
return result;
}
for (NSDictionary *fileDict in fileList)
{
BOOL willMigrate = [[fileDict valueForKey:@"willMigrate"] boolValue];
if (!willMigrate)
{
continue;
}
NSURL *fileURL = [NSURL URLWithString:[fileDict valueForKey:@"URL"]];
[CocoaDSFile copyFileToCurrentDirectory:fileURL];
}
result = YES;
return result;
}
+ (NSMutableArray *) completeFileList
{
NSMutableArray *fileList = [NSMutableArray arrayWithCapacity:100];
if (fileList == nil)
{
return fileList;
}
NSString *currentVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
NSDictionary *versionTopDict = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"VersionPaths" ofType:@"plist"]];
NSDictionary *versionDirectoriesDict = (NSDictionary *)[versionTopDict valueForKey:@"VersionDirectories"];
NSArray *versionArray = [versionDirectoriesDict allKeys];
for (NSString *versionKey in versionArray)
{
if ([currentVersion isEqualToString:versionKey])
{
continue;
}
NSDictionary *versionDict = (NSDictionary *)[versionDirectoriesDict valueForKey:versionKey];
NSArray *portArray = [versionDict allKeys];
for (NSString *portKey in portArray)
{
NSDictionary *portDict = (NSDictionary *)[versionDict valueForKey:portKey];
NSArray *typeArray = [portDict allKeys];
for (NSString *typeKey in typeArray)
{
NSString *typePath = [portDict valueForKey:typeKey];
NSURL *typeURL = nil;
if ([typePath isEqualToString:@"${WITHROM}"])
{
continue;
}
else if ([typePath isEqualToString:@"${APPSUPPORT}"])
{
typeURL = [CocoaDSFile getURLUserAppSupportByKind:typeKey];
[fileList addObjectsFromArray:[CocoaDSFile appFileList:typeURL fileKind:typeKey]];
}
else
{
typeURL = [NSURL fileURLWithPath:[typePath stringByExpandingTildeInPath]];
[fileList addObjectsFromArray:[CocoaDSFile appFileList:typeURL fileKind:typeKey]];
}
}
}
}
return fileList;
}
+ (NSMutableArray *) appFileList:(NSURL *)directoryURL
{
return [self appFileList:directoryURL fileKind:nil];
}
+ (NSMutableArray *) appFileList:(NSURL *)directoryURL fileKind:(NSString *)theFileKind
{
NSMutableArray *outArray = nil;
if (directoryURL == nil)
{
return outArray;
}
NSString *directoryPath = [directoryURL path];
NSFileManager *fileManager = [[NSFileManager alloc] init];
NSArray *fileList = [fileManager contentsOfDirectoryAtPath:directoryPath error:nil];
if (fileList == nil)
{
[fileManager release];
return outArray;
}
outArray = [NSMutableArray arrayWithCapacity:100];
if (outArray == nil)
{
[fileManager release];
return outArray;
}
for (NSString *fileName in fileList)
{
NSNumber *willMigrate = [NSNumber numberWithBool:YES];
NSString *filePath = [directoryPath stringByAppendingPathComponent:fileName];
NSURL *fileURL = [NSURL fileURLWithPath:filePath];
NSString *fileVersion = [CocoaDSFile fileVersion:fileURL];
NSString *fileKind = [CocoaDSFile fileKind:fileURL];
if (fileKind == nil ||
(theFileKind != nil && ![theFileKind isEqualToString:fileKind]) ||
[CocoaDSFile fileExistsForCurrent:fileURL])
{
continue;
}
NSDictionary *fileAttributes = [fileManager attributesOfItemAtPath:filePath error:nil];
NSMutableDictionary *finalDict = [NSMutableDictionary dictionaryWithObjectsAndKeys:
willMigrate, @"willMigrate",
fileName, @"name",
fileVersion, @"version",
fileKind, @"kind",
[fileAttributes fileModificationDate], @"dateModified",
[fileURL absoluteString], @"URL",
nil];
[outArray addObject:finalDict];
}
[fileManager release];
return outArray;
}
#endif
@end

View File

@ -0,0 +1,97 @@
/*
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>
#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
#include "macosx_10_4_compat.h"
#endif
@interface CocoaDSUtil : NSObject
{
}
+ (void) messageSendOneWay:(NSPort *)sendPort msgID:(NSInteger)msgID;
+ (void) messageSendOneWayWithData:(NSPort *)sendPort msgID:(NSInteger)msgID data:(NSData *)msgData;
+ (void) messageSendOneWayWithInteger:(NSPort *)sendPort msgID:(NSInteger)msgID integerValue:(NSInteger)integerValue;
+ (void) messageSendOneWayWithFloat:(NSPort *)sendPort msgID:(NSInteger)msgID floatValue:(float)floatValue;
+ (void) messageSendOneWayWithBool:(NSPort *)sendPort msgID:(NSInteger)msgID boolValue:(BOOL)boolValue;
+ (void) messageSendOneWayWithRect:(NSPort *)sendPort msgID:(NSInteger)msgID rect:(NSRect)rect;
+ (NSInteger) getIBActionSenderTag:(id)sender;
+ (BOOL) getIBActionSenderButtonStateBool:(id)sender;
+ (void) quickDialogUsingTitle:(NSString *)titleText message:(NSString *)messageText;
+ (BOOL) quickYesNoDialogUsingTitle:(NSString *)titleText message:(NSString *)messageText;
@end
#if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4
#if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
@interface CocoaDSThread : NSObject <NSPortDelegate>
#else
@interface CocoaDSThread : NSObject
#endif
{
NSThread *thread;
BOOL threadExit;
NSTimeInterval autoreleaseInterval;
NSPort *sendPort;
NSPort *receivePort;
}
@property (assign) NSThread *thread;
@property (assign) BOOL threadExit;
@property (assign) NSTimeInterval autoreleaseInterval;
@property (assign) NSPort *sendPort;
@property (readonly) NSPort *receivePort;
- (id) initWithAutoreleaseInterval:(NSTimeInterval)interval;
- (void) runThread:(id)object;
@end
#endif
@interface NSNotificationCenter (MainThread)
- (void)postNotificationOnMainThread:(NSNotification *)notification;
- (void)postNotificationOnMainThreadName:(NSString *)aName object:(id)anObject;
- (void)postNotificationOnMainThreadName:(NSString *)aName object:(id)anObject userInfo:(NSDictionary *)aUserInfo;
@end
#ifdef __cplusplus
extern "C"
{
#endif
uint32_t RGBA5551ToRGBA8888(const uint16_t color16);
uint32_t RGBA8888ToRGB888(const uint32_t color24);
void RGBA5551ToRGBA8888Buffer(const uint16_t *__restrict__ srcBuffer, uint32_t *__restrict__ destBuffer, unsigned int numberPixels);
void RGB888ToRGBA8888Buffer(const uint32_t *__restrict__ srcBuffer, uint32_t *__restrict__ destBuffer, unsigned int numberPixels);
NSSize GetTransformedBounds(NSSize normalBounds, double scalar, double angleDegrees);
double GetMaxScalarInBounds(double normalBoundsWidth, double normalBoundsHeight, double keepInBoundsWidth, double keepInBoundsHeight);
NSPoint GetNormalPointFromTransformedPoint(NSPoint transformedPt, NSSize normalBounds, NSSize transformBounds, double scalar, double angleDegrees);
uint32_t GetNearestPositivePOT(uint32_t value);
#ifdef __cplusplus
}
#endif

View File

@ -1,167 +0,0 @@
/* Copyright (C) 2007 Jeff Bland
This file is part of DeSmuME
DeSmuME 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.
DeSmuME 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 DeSmuME; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#import <Cocoa/Cocoa.h>
#import "globals.h"
////////////////////////////////////////////////////////////////
//Dialog Boxes-------------------------------------------------
////////////////////////////////////////////////////////////////
void messageDialog(NSString *title, NSString *text)
{
NSRunAlertPanel(title, text, nil/*OK*/, nil, nil);
}
BOOL messageDialogYN(NSString *title, NSString *text)
{
return NSRunAlertPanel(title, text, NSLocalizedString(@"Yes", nil), NSLocalizedString(@"No", nil), nil) != 0;
}
//does an open dialog to choose an NDS file
//returns the filename or NULL if the user selected cancel
NSOpenPanel* panel;
NSString* openDialog(NSArray *file_types)
{
panel = [NSOpenPanel openPanel];
[panel setCanChooseDirectories:NO];
[panel setCanChooseFiles:YES];
[panel setAllowsMultipleSelection:NO];
if([panel runModalForDirectory:nil file:nil types:file_types] == NSOKButton)
{
//a file was selected
id selected_file = [[panel filenames] lastObject]; //hopefully also the first object
return selected_file;
}
//a file wasn't selected
return NULL;
}
BOOL CreateAppDirectory(NSString *directoryName)
{
BOOL result = NO;
BOOL isDir = YES;
NSString *tempPath = nil;
NSString *appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
NSString *appVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
NSArray *savePaths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
if ([savePaths count] > 0)
{
tempPath = [savePaths objectAtIndex:0];
}
else
{
return result;
}
NSFileManager *fileManager = [[NSFileManager alloc] init];
/*
Mac OS X v10.4 only
Code for creating new directories based on NSString paths.
*/
tempPath = [[tempPath stringByAppendingString:@"/"] stringByAppendingString:appName];
result = [fileManager createDirectoryAtPath:tempPath attributes:nil];
if (result == NO)
{
if([fileManager fileExistsAtPath:tempPath isDirectory:&isDir] == NO)
{
[fileManager release];
return result;
}
}
tempPath = [[tempPath stringByAppendingString:@"/"] stringByAppendingString:appVersion];
result = [fileManager createDirectoryAtPath:tempPath attributes:nil];
if (result == NO)
{
if([fileManager fileExistsAtPath:tempPath isDirectory:&isDir] == NO)
{
[fileManager release];
return result;
}
}
if (directoryName != nil)
{
tempPath = [[tempPath stringByAppendingString:@"/"] stringByAppendingString:directoryName];
result = [fileManager createDirectoryAtPath:tempPath attributes:nil];
if (result == NO)
{
if([fileManager fileExistsAtPath:tempPath isDirectory:&isDir] == NO)
{
[fileManager release];
return result;
}
}
}
/*
In Mac OS X v10.4, having the File Manager create new directories where they already exist
returns NO. Note that this behavior is not per Apple's own documentation. Therefore, we manually
set result=YES at the end to make sure the function returns the right result.
*/
result = YES;
/*
Mac OS X v10.5 and later
Yes, it's that simple...
*/
//result = [fileManager createDirectoryAtPath:savePath createIntermediates:YES attributes:nil error:NULL];
[fileManager release];
return result;
}
NSString* GetPathUserAppSupport(NSString *directoryName)
{
NSString *userAppSupportPath = nil;
NSString *appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
NSString *appVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
NSArray *savePaths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
if ([savePaths count] > 0)
{
userAppSupportPath = [savePaths objectAtIndex:0];
}
else
{
return userAppSupportPath;
}
if (directoryName == nil)
{
userAppSupportPath = [[[[userAppSupportPath stringByAppendingString:@"/"] stringByAppendingString:appName] stringByAppendingString:@"/"] stringByAppendingString:appVersion];
}
else
{
userAppSupportPath = [[[[[[userAppSupportPath stringByAppendingString:@"/"] stringByAppendingString:appName] stringByAppendingString:@"/"] stringByAppendingString:appVersion] stringByAppendingString:@"/"] stringByAppendingString:directoryName];
}
return userAppSupportPath;
}

View File

@ -0,0 +1,596 @@
/*
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_util.h"
#import "cocoa_globals.h"
#import "types.h"
#undef BOOL
@implementation CocoaDSUtil
static NSDate *distantFutureDate = [[NSDate distantFuture] retain];
+ (void) messageSendOneWay:(NSPort *)sendPort msgID:(NSInteger)msgID
{
NSPortMessage *message = [[NSPortMessage alloc] initWithSendPort:sendPort receivePort:nil components:nil];
[message setMsgid:msgID];
NSDate *sendDate = [[NSDate alloc] init];
[message sendBeforeDate:distantFutureDate];
[sendDate release];
[message release];
}
+ (void) messageSendOneWayWithData:(NSPort *)sendPort msgID:(NSInteger)msgID data:(NSData *)msgData
{
NSArray *messageComponents = [[NSArray alloc] initWithObjects:msgData, nil];
NSPortMessage *message = [[NSPortMessage alloc] initWithSendPort:sendPort receivePort:nil components:messageComponents];
[message setMsgid:msgID];
NSDate *sendDate = [[NSDate alloc] init];
[message sendBeforeDate:distantFutureDate];
[sendDate release];
[messageComponents release];
[message release];
}
+ (void) messageSendOneWayWithInteger:(NSPort *)sendPort msgID:(NSInteger)msgID integerValue:(NSInteger)integerValue
{
NSData *messageData = [[NSData alloc] initWithBytes:&integerValue length:sizeof(NSInteger)];
[CocoaDSUtil messageSendOneWayWithData:sendPort msgID:msgID data:messageData];
[messageData release];
}
+ (void) messageSendOneWayWithFloat:(NSPort *)sendPort msgID:(NSInteger)msgID floatValue:(float)floatValue
{
NSData *messageData = [[NSData alloc] initWithBytes:&floatValue length:sizeof(float)];
[CocoaDSUtil messageSendOneWayWithData:sendPort msgID:msgID data:messageData];
[messageData release];
}
+ (void) messageSendOneWayWithBool:(NSPort *)sendPort msgID:(NSInteger)msgID boolValue:(BOOL)boolValue
{
NSData *messageData = [[NSData alloc] initWithBytes:&boolValue length:sizeof(BOOL)];
[CocoaDSUtil messageSendOneWayWithData:sendPort msgID:msgID data:messageData];
[messageData release];
}
+ (void) messageSendOneWayWithRect:(NSPort *)sendPort msgID:(NSInteger)msgID rect:(NSRect)rect
{
NSData *messageData = [[NSData alloc] initWithBytes:&rect length:sizeof(NSRect)];
[CocoaDSUtil messageSendOneWayWithData:sendPort msgID:msgID data:messageData];
[messageData release];
}
+ (NSInteger) getIBActionSenderTag:(id)sender
{
NSInteger senderTag = 0;
if ([sender isKindOfClass:[NSButton class]])
{
senderTag = [sender tag];
}
else if ([sender respondsToSelector:@selector(selectedCell)])
{
senderTag = [[sender selectedCell] tag];
}
else if ([sender respondsToSelector:@selector(tag)])
{
senderTag = [sender tag];
}
return senderTag;
}
+ (BOOL) getIBActionSenderButtonStateBool:(id)sender
{
BOOL theState = NO;
NSInteger buttonState = NSOffState;
if ([sender respondsToSelector:@selector(state)])
{
buttonState = [sender state];
}
if (buttonState == NSOnState)
{
theState = YES;
}
return theState;
}
+ (void) quickDialogUsingTitle:(NSString *)titleText message:(NSString *)messageText
{
NSRunAlertPanel(titleText, messageText, nil, nil, nil);
}
+ (BOOL) quickYesNoDialogUsingTitle:(NSString *)titleText message:(NSString *)messageText
{
return NSRunAlertPanel(titleText, messageText, NSLocalizedString(@"Yes", nil), NSLocalizedString(@"No", nil), nil) != 0;
}
@end
#if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4
@implementation CocoaDSThread
@synthesize thread;
@synthesize threadExit;
@synthesize autoreleaseInterval;
@synthesize sendPort;
@synthesize receivePort;
- (id)init
{
return [self initWithAutoreleaseInterval:15.0];
}
- (id) initWithAutoreleaseInterval:(NSTimeInterval)interval
{
// Set up thread info.
thread = nil;
threadExit = NO;
autoreleaseInterval = interval;
// Set up thread ports.
sendPort = [[NSPort port] retain];
[sendPort setDelegate:self];
receivePort = [[NSPort port] retain];
[receivePort setDelegate:self];
return self;
}
- (void)dealloc
{
// Exit the thread.
if (self.thread != nil)
{
// Tell the thread to shut down.
self.threadExit = YES;
// Wait until the thread has shut down.
while (self.thread != nil)
{
[NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
}
}
[self.sendPort release];
[self.receivePort release];
[super dealloc];
}
- (void) runThread:(id)object
{
NSAutoreleasePool *threadPool = [[NSAutoreleasePool alloc] init];
NSRunLoop *runLoop = [[NSRunLoop currentRunLoop] retain];
[runLoop addPort:self.receivePort forMode:NSDefaultRunLoopMode];
self.thread = [[NSThread currentThread] retain];
do
{
NSAutoreleasePool *runLoopPool = [[NSAutoreleasePool alloc] init];
NSDate *runDate = [[NSDate alloc] initWithTimeIntervalSinceNow:self.autoreleaseInterval];
[runLoop runUntilDate:runDate];
[runDate release];
[runLoopPool release];
} while (!self.threadExit);
[self.thread release];
self.thread = nil;
[runLoop release];
[threadPool release];
}
- (void)handlePortMessage:(NSPortMessage *)portMessage
{
NSInteger message = (NSInteger)[portMessage msgid];
switch (message)
{
case MESSAGE_EXIT_THREAD:
self.threadExit = YES;
break;
default:
break;
}
}
@end
#endif
@implementation NSNotificationCenter (MainThread)
- (void)postNotificationOnMainThread:(NSNotification *)notification
{
[self performSelectorOnMainThread:@selector(postNotification:) withObject:notification waitUntilDone:YES];
}
- (void)postNotificationOnMainThreadName:(NSString *)aName object:(id)anObject
{
NSNotification *notification = [NSNotification notificationWithName:aName object:anObject];
[self postNotificationOnMainThread:notification];
}
- (void)postNotificationOnMainThreadName:(NSString *)aName object:(id)anObject userInfo:(NSDictionary *)aUserInfo
{
NSNotification *notification = [NSNotification notificationWithName:aName object:anObject userInfo:aUserInfo];
[self postNotificationOnMainThread:notification];
}
@end
/********************************************************************************************
RGBA5551ToRGBA8888() - INLINE
Converts a color from 16-bit RGBA5551 format into 32-bit RGBA8888 format.
Takes:
color16 - The pixel in 16-bit RGBA5551 format.
Returns:
A 32-bit unsigned integer containing the RGBA8888 formatted color.
Details:
The input and output pixels are expected to have little-endian byte order.
********************************************************************************************/
FORCEINLINE uint32_t RGBA5551ToRGBA8888(const uint16_t color16)
{
return ((color16 & 0x001F) << 3) |
((color16 & 0x03E0) << 6) |
((color16 & 0x7C00) << 9) |
0xFF000000;
}
/********************************************************************************************
RGB888ToRGBA8888() - INLINE
Converts a color from 24-bit RGB888 format into 32-bit RGBA8888 format.
Takes:
color24 - The pixel in 24-bit RGB888 format.
Returns:
A 32-bit unsigned integer containing the RGBA8888 formatted color.
Details:
The input and output pixels are expected to have little-endian byte order.
********************************************************************************************/
FORCEINLINE uint32_t RGB888ToRGBA8888(const uint32_t color24)
{
return color24 | 0xFF000000;
}
/********************************************************************************************
RGBA5551ToRGBA8888Buffer()
Copies a 16-bit RGBA5551 pixel buffer into a 32-bit RGBA8888 pixel buffer.
Takes:
srcBuffer - Pointer to the source 16-bit RGBA5551 pixel buffer.
destBuffer - Pointer to the destination 32-bit RGBA8888 pixel buffer.
numberPixels - The number of pixels to copy.
Returns:
Nothing.
Details:
The source and destination pixels are expected to have little-endian byte order.
Also, it is the caller's responsibility to ensure that the source and destination
buffers are large enough to accomodate the requested number of pixels.
********************************************************************************************/
void RGBA5551ToRGBA8888Buffer(const uint16_t *__restrict__ srcBuffer, uint32_t *__restrict__ destBuffer, unsigned int numberPixels)
{
const uint32_t *__restrict__ destBufferEnd = destBuffer + numberPixels;
while (destBuffer < destBufferEnd)
{
*destBuffer++ = RGBA5551ToRGBA8888(*srcBuffer++);
}
}
/********************************************************************************************
RGBA5551ToRGBA8888Buffer()
Copies a 24-bit RGB888 pixel buffer into a 32-bit RGBA8888 pixel buffer.
Takes:
srcBuffer - Pointer to the source 24-bit RGB888 pixel buffer.
destBuffer - Pointer to the destination 32-bit RGBA8888 pixel buffer.
numberPixels - The number of pixels to copy.
Returns:
Nothing.
Details:
The source and destination pixels are expected to have little-endian byte order.
Also, it is the caller's responsibility to ensure that the source and destination
buffers are large enough to accomodate the requested number of pixels.
********************************************************************************************/
void RGB888ToRGBA8888Buffer(const uint32_t *__restrict__ srcBuffer, uint32_t *__restrict__ destBuffer, unsigned int numberPixels)
{
const uint32_t *__restrict__ destBufferEnd = destBuffer + numberPixels;
while (destBuffer < destBufferEnd)
{
*destBuffer++ = RGB888ToRGBA8888(*srcBuffer++);
}
}
/********************************************************************************************
GetTransformedBounds()
Returns the bounds of a normalized 2D surface using affine transformations.
Takes:
normalBounds - The rectangular bounds of the normal 2D surface.
scalar - The scalar used to transform the 2D surface.
angleDegrees - The rotation angle, in degrees, to transform the 2D surface.
Returns:
The bounds of a normalized 2D surface using affine transformations.
Details:
The returned bounds is always a normal rectangle. Ignoring the scaling, the
returned bounds will always be at its smallest when the angle is at 0, 90, 180,
or 270 degrees, and largest when the angle is at 45, 135, 225, or 315 degrees.
********************************************************************************************/
NSSize GetTransformedBounds(NSSize normalBounds, double scalar, double angleDegrees)
{
NSSize transformBounds = {0.0, 0.0};
double angleRadians = angleDegrees * (M_PI/180.0);
double w = scalar * normalBounds.width;
double h = scalar * normalBounds.height;
double d = hypot(w, h);
double dAngle = atan2(h, w);
double px = d * cos(dAngle + angleRadians);
double py = d * sin(dAngle + angleRadians);
double qx = h * cos((M_PI/2.0) + angleRadians);
double qy = h * sin((M_PI/2.0) + angleRadians);
double rx = w * cos(angleRadians);
double ry = w * sin(angleRadians);
double transformWidth = px;
double transformHeight = py;
// Determine the transform width, which is dependent on the location of
// the x-coordinate of point p.
if (px > 0.0)
{
transformWidth = px;
if (px < qx)
{
transformWidth = qx - rx;
}
else if (px < rx)
{
transformWidth = rx - qx;
}
}
else if (px < 0.0)
{
transformWidth = -px;
if (px > qx)
{
transformWidth = -(qx - rx);
}
else if (px > rx)
{
transformWidth = -(rx - qx);
}
}
// Determine the transform height, which is dependent on the location of
// the y-coordinate of point p.
if (py > 0.0)
{
transformHeight = py;
if (py < qy)
{
transformHeight = qy - ry;
}
else if (py < ry)
{
transformHeight = ry - qy;
}
}
else if (py < 0.0)
{
transformHeight = -py;
if (py > qy)
{
transformHeight = -(qy - ry);
}
else if (py > ry)
{
transformHeight = -(ry - qy);
}
}
transformBounds.width = transformWidth;
transformBounds.height = transformHeight;
return transformBounds;
}
/********************************************************************************************
GetMaxScalarInBounds()
Returns the maximum scalar that a rectangle can grow, while maintaining its aspect
ratio, within a boundary.
Takes:
normalBoundsWidth - The rectangular width of the normal 2D surface.
normalBoundsHeight - The rectangular height of the normal 2D surface.
keepInBoundsWidth - The rectangular width of the keep in 2D surface.
keepInBoundsHeight - The rectangular height of the keep in 2D surface.
Returns:
The maximum scalar that a rectangle can grow, while maintaining its aspect ratio,
within a boundary.
Details:
If keepInBoundsWidth or keepInBoundsHeight are less than or equal to zero, the
returned scalar will be zero.
********************************************************************************************/
double GetMaxScalarInBounds(double normalBoundsWidth, double normalBoundsHeight, double keepInBoundsWidth, double keepInBoundsHeight)
{
double maxX;
double maxY;
double maxS;
if (normalBoundsWidth <= 0.0)
{
maxX = 0.0;
}
else
{
maxX = keepInBoundsWidth / normalBoundsWidth;
}
if (normalBoundsHeight <= 0.0)
{
maxY = 0.0;
}
else
{
maxY = keepInBoundsHeight / normalBoundsHeight;
}
maxS = maxY;
if (maxX < maxY)
{
maxS = maxX;
}
return maxS;
}
/********************************************************************************************
GetNormalPointFromTransformedPoint()
Returns a normalized point from a point from a 2D transformed surface.
Takes:
transformedPt - A point as it exists on a 2D transformed surface.
normalBounds - The rectangular bounds of the normal 2D surface.
transformedBounds - The rectangular bounds of the transformed 2D surface.
scalar - The scalar used on the transformed 2D surface.
angleDegrees - The rotation angle, in degrees, of the transformed 2D surface.
Returns:
A normalized point from a point from a 2D transformed surface.
Details:
It may help to call GetTransformedBounds() for the transformBounds parameter.
********************************************************************************************/
NSPoint GetNormalPointFromTransformedPoint(NSPoint transformedPt, NSSize normalBounds, NSSize transformBounds, double scalar, double angleDegrees)
{
double transformedX = 0.0;
double transformedY = 0.0;
double r = 0.0;
double theta = 0.0;
double normalizedAngle = 0.0;
double normalizedX = 0.0;
double normalizedY = 0.0;
NSPoint normalizedPt = {transformedPt.x, transformedPt.y};
// Get the coordinates of the transformed point and translate the coordinate
// system so that the origin becomes the center.
transformedX = transformedPt.x - (transformBounds.width / 2.0);
transformedY = transformedPt.y - (transformBounds.height / 2.0);
// Perform rect-polar conversion.
// Get the radius r with respect to the origin.
r = hypot(transformedX, transformedY);
// Get the angle theta with respect to the origin.
if (transformedX == 0.0)
{
if (transformedY > 0.0)
{
theta = M_PI / 2.0;
}
else if (transformedY < 0.0)
{
theta = M_PI * 1.5;
}
}
else if (transformedX < 0.0)
{
theta = M_PI - atan2(transformedY, -transformedX);
}
else if (transformedY < 0.0)
{
theta = atan2(transformedY, transformedX) + (M_PI * 2.0);
}
else
{
theta = atan2(transformedY, transformedX);
}
// Get the normalized angle and use it to rotate about the origin.
// Then do polar-rect conversion and translate back to transformed coordinates
// with a 0 degree rotation.
normalizedAngle = theta - angleDegrees;
normalizedX = (r * cos(normalizedAngle)) + (normalBounds.width * scalar / 2.0);
normalizedY = (r * sin(normalizedAngle)) + (normalBounds.height * scalar / 2.0);
// Scale the location to get a one-to-one correlation to normal coordinates.
normalizedPt.x = (CGFloat)(normalizedX / scalar);
normalizedPt.y = (CGFloat)(normalizedY / scalar);
return normalizedPt;
}
/********************************************************************************************
GetNearestPositivePOT()
Returns the next highest power of two of a 32-bit integer value.
Takes:
value - A 32-bit integer value.
Returns:
A 32-bit integer with the next highest power of two compared to the input value.
Details:
If the input value is already a power of two, this function returns the same
value.
********************************************************************************************/
uint32_t GetNearestPositivePOT(uint32_t value)
{
value--;
value |= value >> 1;
value |= value >> 2;
value |= value >> 4;
value |= value >> 8;
value |= value >> 16;
value++;
return value;
}

View File

@ -1,51 +0,0 @@
/* Copyright (C) 2007 Jeff Bland
This file is part of DeSmuME
DeSmuME 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.
DeSmuME 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 DeSmuME; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#import <Cocoa/Cocoa.h>
#ifdef __cplusplus
extern "C"
{
#endif
void messageDialog(NSString *title, NSString *text);
BOOL messageDialogYN(NSString *title, NSString *text);
NSString* openDialog(NSArray *file_types);
BOOL CreateAppDirectory(NSString *directoryName);
NSString* GetPathUserAppSupport(NSString *directoryName);
//
#if !defined(__LP64__) && !defined(NS_BUILD_32_LIKE_64)
typedef int NSInteger;
typedef unsigned int NSUInteger;
#endif
// Taken from CIVector.h of the Mac OS X 10.5 SDK.
// Defines CGFloat for Mac OS X 10.4 and earlier.
#ifndef CGFLOAT_DEFINED
typedef float CGFloat;
# define CGFLOAT_MIN FLT_MIN
# define CGFLOAT_MAX FLT_MAX
# define CGFLOAT_IS_DOUBLE 0
# define CGFLOAT_DEFINED 1
#endif
#ifdef __cplusplus
}
#endif

View File

@ -1,23 +1,24 @@
/* Copyright (C) 2007 Jeff Bland
/*
Copyright (C) 2007 Jeff Bland
Copyright (C) 2011 Roger Manuel
Copyright (C) 2012 DeSmuME team
This file is part of DeSmuME
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.
DeSmuME 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.
DeSmuME 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 DeSmuME; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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 "input.h"
#import "cocoa_input.h"
#import "main_window.h"
#import "preferences.h"

View File

@ -0,0 +1,42 @@
/*
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/>.
*/
#ifndef MACOSX_10_4_COMPATIBILITY_H
#define MACOSX_10_4_COMPATIBILITY_H
// Taken from NSObjCRuntime.h of the Mac OS X 10.5 SDK.
// Defines NSInteger and NSUInteger for Mac OS X 10.4 and earlier.
#ifndef NSINTEGER_DEFINED
#define NSINTEGER_DEFINED 1
typedef int NSInteger;
typedef unsigned int NSUInteger;
#define NSIntegerMax LONG_MAX
#define NSIntegerMin LONG_MIN
#define NSUIntegerMax ULONG_MAX
#endif
// Taken from CIVector.h of the Mac OS X 10.5 SDK.
// Defines CGFloat for Mac OS X 10.4 and earlier.
#ifndef CGFLOAT_DEFINED
#define CGFLOAT_DEFINED 1
typedef float CGFloat;
#define CGFLOAT_MIN FLT_MIN
#define CGFLOAT_MAX FLT_MAX
#define CGFLOAT_IS_DOUBLE 0
#endif
#endif // MACOSX_10_4_COMPATIBILITY_H

View File

@ -1,20 +1,20 @@
/* Copyright (C) 2007 Jeff Bland
/*
Copyright (C) 2007 Jeff Bland
Copyright (C) 2011 Roger Manuel
Copyright (C) 2012 DeSmuME team
This file is part of DeSmuME
DeSmuME is free software; you can redistribute it and/or modify
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
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
DeSmuME is distributed in the hope that it will be useful,
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 DeSmuME; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
along with the this software. If not, see <http://www.gnu.org/licenses/>.
*/
/*
@ -24,6 +24,9 @@ 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"
@ -75,9 +78,6 @@ extern NSMenuItem *execute_item;
extern NSMenuItem *pause_item;
extern NSMenuItem *reset_item;
extern NSMenuItem *frame_skip_auto_item;
extern NSMenuItem *frame_skip_item[];
extern NSMenuItem *save_type_item[];
extern NSString *save_types[];
@ -114,7 +114,6 @@ extern NSMenuItem *rom_info_item;
//delegate methods
- (BOOL)application:(NSApplication*)sender openFile:(NSString*)filename;
- (void)application:(NSApplication*)sender openFiles:(NSArray*)filenames;
- (void)applicationWillFinishLaunching:(NSNotification*)aNotification;
- (void)applicationDidFinishLaunching:(NSNotification*)aNotification;
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)sender;
@ -238,30 +237,6 @@ void CreateMenu(AppDelegate *delegate)
[emulation_menu addItem:[NSMenuItem separatorItem]];
//Frake skip menu
// Disabling frame skipping for now since it doesn't yield any significant speed improvements. -rogerman 03/28/2011
/*
temp = [emulation_menu addItemWithTitle:NSLocalizedString(@"Frame Skip", nil) action:nil keyEquivalent:@""];
NSMenu *frame_skip_menu = [[NSMenu alloc] initWithTitle:NSLocalizedString(@"Frame Skip", nil)];
if(frame_skip_menu != nil)
{
[temp setSubmenu:frame_skip_menu];
frame_skip_auto_item = [frame_skip_menu addItemWithTitle:NSLocalizedString(@"Auto", nil) action:@selector(setFrameSkipFromMenuItem:) keyEquivalent:@""];
[frame_skip_menu addItem:[NSMenuItem separatorItem]];
frame_skip_item[0] = [frame_skip_menu addItemWithTitle:NSLocalizedString(@"Off", nil) action:@selector(setFrameSkipFromMenuItem:) keyEquivalent:@""];
for(i = 1; i < MAX_FRAME_SKIP; i++)
{
frame_skip_item[i] = [frame_skip_menu addItemWithTitle:[NSString stringWithFormat:NSLocalizedString(@"Skip %d", nil), i] action:@selector(setFrameSkipFromMenuItem:) keyEquivalent:@""];
}
[frame_skip_menu release];
}
*/
//Speed limit menu
temp = [emulation_menu addItemWithTitle:NSLocalizedString(@"Speed Limit", nil) action:nil keyEquivalent:@""];
@ -311,11 +286,6 @@ void CreateMenu(AppDelegate *delegate)
[save_type_menu release];
}
[emulation_menu addItem:[NSMenuItem separatorItem]];
[emulation_menu addItemWithTitle:NSLocalizedString(@"Set FAT Image File...", nil) action:@selector(pickFlash) keyEquivalent:@""];
[emulation_menu release];
}
@ -415,12 +385,7 @@ void CreateMenu(AppDelegate *delegate)
[sound_menu addItem:[NSMenuItem separatorItem]];
mute_item = [sound_menu addItemWithTitle:NSLocalizedString(@"Mute", nil) action:@selector(toggleMute) keyEquivalent:@""];
//[sound_menu addItem:[NSMenuItem separatorItem]];
//temp = [sound_menu addItemWithTitle:@"Record to File..." action:@selector(chooseSoundOutputFile) keyEquivalent: @"r"];
//temp = [sound_menu addItemWithTitle:@"Pause Recording" action:@selector(startRecording) keyEquivalent: @""];
//temp = [sound_menu addItemWithTitle:@"Save Recording" action:@selector(pauseRecording) keyEquivalent: @""];
[sound_menu release];
}
@ -505,7 +470,6 @@ int main(int argc, char *argv[])
[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)
@ -516,64 +480,18 @@ int main(int argc, char *argv[])
}
}
- (void)pickFlash
{
NSOpenPanel *panel = [NSOpenPanel openPanel];
[panel setCanChooseDirectories:NO];
[panel setCanChooseFiles:YES];
[panel setAllowsMultipleSelection:NO];
[panel setTitle:NSLocalizedString(@"Set FAT Image File...", nil)];
if([panel runModalForDirectory:nil file:nil types:[NSArray arrayWithObjects:@"FAT", @"IMG", nil]] == NSOKButton)
{
NSString* selected_file = [[panel filenames] lastObject];
[main_window setFlashFile:selected_file];
}
}
- (BOOL)application:(NSApplication*)sender openFile:(NSString*)filename
{
//verify everything
if(sender != NSApp)return NO;
if(!filename)return NO;
if([filename length] == 0)return NO;
if([main_window loadROM:filename])
{
//[main_window execute];
return YES;
}
return NO;
}
- (void)application:(NSApplication*)sender openFiles:(NSArray*)filenames
{
//verify everything
if(sender != NSApp ||
filenames == nil ||
[filenames count] == 0)
{
[sender replyToOpenOrPrint:NSApplicationDelegateReplySuccess];
return;
}
BOOL result = NO;
NSURL *fileURL = [NSURL fileURLWithPath:filename];
NSString *filename = [filenames lastObject];
if(!filename || [filename length] == 0)
NSString *fileKind = [CocoaDSFile fileKind:fileURL];
if ([fileKind isEqualToString:@"DS ROM"] || [fileKind isEqualToString:@"GBA ROM"])
{
[sender replyToOpenOrPrint:NSApplicationDelegateReplySuccess];
return;
result = [main_window loadRom:fileURL];
}
if([main_window loadROM:filename])
{
//[main_window execute];
[sender replyToOpenOrPrint:NSApplicationDelegateReplySuccess];
return;
}
return result;
}
- (void)applicationWillFinishLaunching:(NSNotification*)notification
@ -587,6 +505,9 @@ int main(int argc, char *argv[])
//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
@ -595,7 +516,7 @@ int main(int argc, char *argv[])
[NSApp activateIgnoringOtherApps:TRUE];
//create the video output window (the only window that opens with the app)
main_window = [[VideoOutputWindow alloc] init];
//main_window = [[VideoOutputWindow alloc] init];
//check if it should load something by default
if([[[NSUserDefaults standardUserDefaults] stringForKey:PREF_AFTER_LAUNCHED] compare:PREF_AFTER_LAUNCHED_OPTION_LAST_ROM]==NSOrderedSame)
@ -604,13 +525,9 @@ int main(int argc, char *argv[])
if([recent_documents count] > 0)
{
//we have to convert from a URL to file path. in the future, URL's ought to be used since they are more capable/robust...
NSURL *romURL = [recent_documents objectAtIndex:0];
NSString *file = [[recent_documents objectAtIndex:0] absoluteString]; //gets it in url form
file = [file stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; //convert escaped characters in url
file = [file substringFromIndex:16]; //gets rid of "File://localhost" url component (there should be a much better way to do this....)
[main_window loadROM:file];
[main_window loadRom:romURL];
}
}
}
@ -619,8 +536,8 @@ int main(int argc, char *argv[])
{
//Ask user about quitting if a rom is loaded (avoid accidentally quiting with unsaved progress)
if([main_window ROMLoaded])
if(!messageDialogYN(NSLocalizedString(@"DeSmuME Emulator", nil), NSLocalizedString(@"Are you sure you want to quit?", nil)))
return NSTerminateCancel;
if(![CocoaDSUtil quickYesNoDialogUsingTitle:NSLocalizedString(@"DeSmuME Emulator", nil) message:NSLocalizedString(@"Are you sure you want to quit?", nil)])
return NSTerminateCancel;
return NSTerminateNow;
}

View File

@ -48,8 +48,6 @@
bool no_smaller_than_ds;
bool keep_proportions;
NSString *pathLoadedRom;
}
//initialization
@ -57,17 +55,14 @@
- (void)dealloc;
//overloaded from NintendoDS class
- (BOOL)loadROM:(NSString*)filename;
- (BOOL) loadRom:(NSURL *)romURL;
- (void)execute;
- (void)pause;
- (void)reset;
- (void)setFrameSkip:(int)frameskip;
- (void)setSaveType:(int)savetype;
- (void)closeROM;
//save features overloaded from nds class
- (BOOL)saveState:(NSString*)file;
- (BOOL)loadState:(NSString*)file;
- (BOOL)saveStateToSlot:(int)slot; //0 to MAX_SLOTS-1, anything else is ignored
- (BOOL)loadStateFromSlot:(int)slot;

View File

@ -1,24 +1,27 @@
/* Copyright (C) 2007 Jeff Bland
/*
Copyright (C) 2007 Jeff Bland
Copyright (C) 2011 Roger Manuel
Copyright (C) 2012 DeSmuME team
This file is part of DeSmuME
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.
DeSmuME 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.
DeSmuME 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 DeSmuME; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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/>.
*/
//DeSmuME Cocoa includes
#import "main_window.h"
#import "cocoa_globals.h"
#import "cocoa_util.h"
#import "cocoa_file.h"
#import "screenshot.h"
#import "screen_state.h"
#import "video_output_view.h"
@ -30,8 +33,6 @@
//How much padding to put around the video output
#define WINDOW_BORDER_PADDING 5
#define MAX_FRAME_SKIP 10
// Save types settings
NSString *save_types[MAX_SAVE_TYPE] = {
NSLocalizedString(@"Auto Detect", nil), // 0
@ -58,8 +59,6 @@ NSMenuItem *load_state_from_item = nil;
NSMenuItem *saveSlot_item[MAX_SLOTS] = { nil, nil, nil, nil, nil, nil, nil, nil, nil, nil }; //make sure this corresponds to the amount in max slots
NSMenuItem *loadSlot_item[MAX_SLOTS] = { nil, nil, nil, nil, nil, nil, nil, nil, nil, nil };
NSMenuItem *rom_info_item = nil;
NSMenuItem *frame_skip_auto_item = nil;
NSMenuItem *frame_skip_item[MAX_FRAME_SKIP] = { nil, nil, nil, nil, nil, nil, nil, nil, nil, nil };
NSMenuItem *speed_limit_25_item = nil;
NSMenuItem *speed_limit_50_item = nil;
NSMenuItem *speed_limit_75_item = nil;
@ -196,7 +195,7 @@ NSMenuItem *screenshot_to_file_item = nil;
NSTitledWindowMask|NSResizableWindowMask|/*NSClosableWindowMask|*/NSMiniaturizableWindowMask|NSTexturedBackgroundWindowMask
backing:NSBackingStoreBuffered defer:NO screen:nil])==nil)
{
messageDialog(NSLocalizedString(@"Error", nil), @"Couldn't create window");
[CocoaDSUtil quickDialogUsingTitle:NSLocalizedString(@"Error", nil) message:NSLocalizedString(@"Couldn't create window", nil)];
[super release];
return nil;
}
@ -234,8 +233,6 @@ NSMenuItem *screenshot_to_file_item = nil;
NSResponder *temp = [window nextResponder];
[window setNextResponder:input];
[input setNextResponder:temp];
pathLoadedRom = nil;
return self;
}
@ -248,22 +245,21 @@ NSMenuItem *screenshot_to_file_item = nil;
[status_view release];
[status_bar_text release];
[input release];
[pathLoadedRom release];
[super dealloc];
}
- (BOOL)loadROM:(NSString*)filename
- (BOOL) loadRom:(NSURL *)romURL
{
//Attemp to load the rom
BOOL result = [super loadROM:filename];
//Attempt to load the rom
BOOL result = [super loadRom:romURL];
//Set status var and screen depending on whether the rom could be loaded
if(result == NO)
{
[video_output_view setScreenState:[ScreenState blackScreenState]]; //black if the rom doesn't load
[self setStatusText:NSLocalizedString(@"No ROM Loaded", nil)];
messageDialog(NSLocalizedString(@"Error", nil), @"Couldn't load ROM");
[CocoaDSUtil quickDialogUsingTitle:NSLocalizedString(@"Error", nil) message:NSLocalizedString(@"Couldn't load ROM", nil)];
} else
{
//if it worked, check the execute upon load option
@ -276,13 +272,10 @@ NSMenuItem *screenshot_to_file_item = nil;
}
//add the rom to the recent documents list
[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:[NSURL fileURLWithPath:filename]];
[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:romURL];
//update the rom info window, if needed
[ROMInfo changeDS:self];
pathLoadedRom = filename;
[pathLoadedRom retain];
}
//reset menu items
@ -345,47 +338,7 @@ NSMenuItem *screenshot_to_file_item = nil;
- (void)emulationError
{
messageDialog(NSLocalizedString(@"Error", nil), NSLocalizedString(@"An emulation error occured", nil));
}
- (void)setFrameSkip:(int)frameskip
{
[super setFrameSkip:frameskip];
frameskip = dsStateBuffer->frame_skip;
if([frame_skip_auto_item target] == self)
if(frameskip < 0)
[frame_skip_auto_item setState:NSOnState];
else
[frame_skip_auto_item setState:NSOffState];
int i;
for(i = 0; i < MAX_FRAME_SKIP; i++)
if([frame_skip_item[i] target] == self)
if(i == frameskip)
[frame_skip_item[i] setState:NSOnState];
else
[frame_skip_item[i] setState:NSOffState];
}
- (void)setFrameSkipFromMenuItem:(id)sender
{
//see if this was sent from the autoskip menu item
if(sender == frame_skip_auto_item)
{
//set the frame skip to auto
[self setFrameSkip:-1];
return;
}
//search through the frame skip menu items to find out which one called this function
int i;
for(i = 0; i < MAX_FRAME_SKIP; i++)
if(sender == frame_skip_item[i])
{
[self setFrameSkip:i];
return;
}
[CocoaDSUtil quickDialogUsingTitle:NSLocalizedString(@"Error", nil) message:NSLocalizedString(@"An emulation error occured", nil)];
}
- (void)setSpeedLimit:(int)speedLimit
@ -504,33 +457,23 @@ NSMenuItem *screenshot_to_file_item = nil;
- (void)askAndCloseROM
{
if(messageDialogYN(NSLocalizedString(@"DeSmuME Emulator", nil), NSLocalizedString(@"Are you sure you want to close the ROM?", nil)))
if([CocoaDSUtil quickYesNoDialogUsingTitle:NSLocalizedString(@"DeSmuME Emulator", nil) message:NSLocalizedString(@"Are you sure you want to close the ROM?", nil)])
[self closeROM];
}
- (BOOL)saveState:(NSString*)file
{
return [super saveState:file];
}
- (BOOL)loadState:(NSString*)file
{
return [super loadState:file];
}
- (BOOL)saveStateToSlot:(int)slot
{
BOOL result = NO;
int i = slot;
NSString *savePath = GetPathUserAppSupport(@"States");
if (savePath == nil)
NSString *saveStatePath = [[CocoaDSFile getURLUserAppSupportByKind:@"Save State"] path];
if (saveStatePath == nil)
{
// Throw an error message here...
return result;
}
result = CreateAppDirectory(@"States");
result = [CocoaDSFile createUserAppSupportDirectory:@"States"];
if (result == NO)
{
// Should throw an error message here...
@ -543,8 +486,10 @@ NSMenuItem *screenshot_to_file_item = nil;
return result;
}
NSString *fullFilePath = [[savePath stringByAppendingString:@"/"] stringByAppendingString:fileName];
result = [self saveState:fullFilePath];
BOOL wasExecuting = [self executing];
[super pause];
result = [CocoaDSFile saveState:[NSURL fileURLWithPath:[saveStatePath stringByAppendingPathComponent:fileName]]];
if(result)
{
if([saveSlot_item[i] target] == self);
@ -554,6 +499,11 @@ NSMenuItem *screenshot_to_file_item = nil;
result = YES;
}
if(wasExecuting == YES)
{
[super execute];
}
return result;
}
@ -562,8 +512,8 @@ NSMenuItem *screenshot_to_file_item = nil;
{
BOOL result = NO;
NSString *savePath = GetPathUserAppSupport(@"States");
if (savePath == nil)
NSString *saveStatePath = [[CocoaDSFile getURLUserAppSupportByKind:@"Save State"] path];
if (saveStatePath == nil)
{
// Should throw an error message here...
return result;
@ -575,48 +525,94 @@ NSMenuItem *screenshot_to_file_item = nil;
return result;
}
NSString *fullFilePath = [[savePath stringByAppendingString:@"/"] stringByAppendingString:fileName];
result = [self loadState:fullFilePath];
BOOL wasExecuting = [self executing];
[super pause];
result = [CocoaDSFile loadState:[NSURL fileURLWithPath:[saveStatePath stringByAppendingPathComponent:fileName]]];
if(wasExecuting == YES)
{
[super execute];
}
return result;
}
- (BOOL)saveStateAs
- (BOOL) saveStateAs
{
//pause emulation so it doesnt save the state after
BOOL was_executing = [self executing];
[self pause];
BOOL result = NO;
NSInteger buttonClicked;
//file select
NSSavePanel *panel = [NSSavePanel savePanel];
[panel setTitle:NSLocalizedString(@"Save State...", nil)];
[panel setRequiredFileType:@"DST"];
[panel setRequiredFileType:@FILE_EXT_SAVE_STATE];
//save it
if([panel runModal] == NSFileHandlingPanelOKButton)
buttonClicked = [panel runModal];
if(buttonClicked == NSFileHandlingPanelOKButton)
{
if(was_executing == YES)[self execute];
return [self saveState:[panel filename]];
BOOL wasExecuting = [self executing];
[super pause];
result = [CocoaDSFile saveState:[panel URL]];
if (!result)
{
return result;
}
if(wasExecuting == YES)
{
[super execute];
}
}
//unpause emulation if needed
if(was_executing == YES)[self execute];
return NO;
return result;
}
- (BOOL)loadStateFrom
{
BOOL result = NO;
NSInteger buttonClicked;
NSURL *selectedFile = nil;
NSOpenPanel *panel = [NSOpenPanel openPanel];
[panel setTitle:NSLocalizedString(@"Load State From...", nil)];
[panel setCanChooseFiles:YES];
[panel setCanChooseDirectories:NO];
[panel setAllowsMultipleSelection:NO];
if([panel runModalForTypes:[NSArray arrayWithObject:@"DST"]] == NSFileHandlingPanelOKButton)
return [self loadState:[panel filename]];
return NO;
[panel setRequiredFileType:@FILE_EXT_SAVE_STATE];
buttonClicked = [panel runModal];
if(buttonClicked == NSOKButton)
{
selectedFile = [[panel URLs] lastObject]; //hopefully also the first object
if(selectedFile == nil)
{
return result;
}
BOOL wasExecuting = [self executing];
[super pause];
result = [CocoaDSFile loadState:selectedFile];
if (!result)
{
if(wasExecuting == YES)
{
[super execute];
}
return result;
}
if(wasExecuting == YES)
{
[super execute];
}
}
return result;
}
- (BOOL)saveToSlot:(id)menu_item
@ -876,7 +872,7 @@ NSMenuItem *screenshot_to_file_item = nil;
} else
{
messageDialog(NSLocalizedString(@"Error", nil), @"Couldn't create status bar");
[CocoaDSUtil quickDialogUsingTitle:NSLocalizedString(@"Error", nil) message:NSLocalizedString(@"Couldn't create status bar", nil)];
return;
}
@ -1289,10 +1285,6 @@ NSMenuItem *screenshot_to_file_item = nil;
[execute_item setState:NSOffState];
[pause_item setState:NSOffState];
}
[frame_skip_auto_item setTarget:self];
for(i = 0; i < MAX_FRAME_SKIP; i++)[frame_skip_item[i] setTarget:self];
[self setFrameSkip:[self frameSkip]]; //set the menu checkmarks correctly
// Backup media type
for(i = 0; i < MAX_SAVE_TYPE; i++)[save_type_item[i] setTarget:self];
@ -1480,7 +1472,7 @@ NSMenuItem *screenshot_to_file_item = nil;
{
BOOL exists = false;
NSString *searchPath = GetPathUserAppSupport(@"States");
NSString *searchPath = [[CocoaDSFile getURLUserAppSupportByKind:@"Save State"] path];
NSString *searchFileName = [self getSaveSlotFileName:slot];
if (searchPath == nil || searchFileName == nil)
@ -1489,7 +1481,7 @@ NSMenuItem *screenshot_to_file_item = nil;
}
NSFileManager *fileManager = [[NSFileManager alloc] init];
NSString *searchFullPath = [[searchPath stringByAppendingString:@"/"] stringByAppendingString:searchFileName];
NSString *searchFullPath = [searchPath stringByAppendingPathComponent:searchFileName];
exists = [fileManager isReadableFileAtPath:searchFullPath];
@ -1502,7 +1494,7 @@ NSMenuItem *screenshot_to_file_item = nil;
{
NSString *fileExtension = [NSString stringWithFormat:@".ds%d", slotNumber];
return [[[pathLoadedRom lastPathComponent] stringByDeletingPathExtension] stringByAppendingString:fileExtension];
return [[[self romFileName] stringByDeletingPathExtension] stringByAppendingString:fileExtension];
}
@end

View File

@ -1,26 +1,27 @@
/* Copyright (C) 2007 Jeff Bland
/*
Copyright (C) 2007 Jeff Bland
Copyright (C) 2011 Roger Manuel
Copyright (C) 2012 DeSmuME team
This file is part of DeSmuME
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.
DeSmuME 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.
DeSmuME 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 DeSmuME; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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 "globals.h"
#import "cocoa_input.h"
#import <Cocoa/Cocoa.h>
@class ScreenState;
#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
#include "macosx_10_4_compat.h"
#endif
#ifdef GDB_STUB
#define OBJ_C
@ -28,7 +29,9 @@
#endif
#define MAX_SLOTS 10
#define MAX_FRAME_SKIP 10
@class CocoaDSController;
@class ScreenState;
@interface CocoaDSStateBuffer : NSObject
{
@ -75,8 +78,7 @@
volatile int speed_limit;
volatile int save_type;
NSString *current_file;
NSString *flash_file;
NSURL *loadedRomURL;
bool doesConfigNeedUpdate;
NSTimeInterval calcTimeBudget;
@ -109,32 +111,26 @@
- (void)setPlayerName:(NSString*)player_name;
//ROM control
- (BOOL)loadROM:(NSString*)filename;
- (BOOL) loadRom:(NSURL *)romURL;
- (BOOL)ROMLoaded;
- (void)closeROM;
//ROM Info
- (NSImage*)ROMIcon;
- (NSString*)ROMFile;
- (NSString*)ROMTitle;
- (NSImage *)ROMIcon;
- (NSString *) romFileName;
- (NSString *)ROMTitle;
- (NSInteger)ROMMaker;
- (NSInteger)ROMSize;
- (NSInteger)ROMARM9Size;
- (NSInteger)ROMARM7Size;
- (NSInteger)ROMDataSize;
//Flash memory
- (NSString*)flashFile;
- (void)setFlashFile:(NSString*)filename;
//execution control
- (BOOL)executing;
- (void)execute;
- (BOOL)paused;
- (void)pause;
- (void)reset;
- (void)setFrameSkip:(int)frameskip; //negative is auto, 0 is off, more than 0 is the amount of frames to skip before showing a frame
- (int)frameSkip; //defaults to -1
- (void)setSpeedLimit:(int)percent; //0 is off, 1-1000 is the pertance speed it runs at, anything else does nothing
- (int)speedLimit;
- (void)setSaveType:(int)savetype; // see save_types in src/mmu.h
@ -144,10 +140,6 @@
- (void) drawFrame;
- (void) padTime:(NSTimeInterval)timePad;
//save states
- (BOOL)saveState:(NSString*)file;
- (BOOL)loadState:(NSString*)file;
- (BOOL) isSubScreenLayerDisplayed:(int)i;
- (BOOL) isMainScreenLayerDisplayed:(int)i;
- (void) toggleMainScreenLayer:(int)i;

View File

@ -1,23 +1,27 @@
/* Copyright (C) 2007 Jeff Bland
/*
Copyright (C) 2007 Jeff Bland
Copyright (C) 2011 Roger Manuel
Copyright (C) 2012 DeSmuME team
This file is part of DeSmuME
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.
DeSmuME 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.
DeSmuME 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 DeSmuME; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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 "nds_control.h"
#import "cocoa_globals.h"
#import "cocoa_file.h"
#import "cocoa_input.h"
#import "cocoa_util.h"
#import "preferences.h"
#import "screen_state.h"
#import "main_window.h"
@ -44,11 +48,6 @@
//or if we can use inter-thread messaging introduced in leopard to update the screen (more efficient)
bool timer_based;
//ds screens are 59.8 frames per sec, so 1/59.8 seconds per frame
//times one million for microseconds per frame
#define DS_SECONDS_PER_FRAME (1.0 / 59.8)
#define DS_MICROSECONDS_PER_FRAME (1.0 / 59.8) * 1000000.0
//accessed from other files
volatile bool execute = true;
@ -61,13 +60,6 @@ GPU3DInterface *core3DList[] = {
NULL
};
enum
{
CORE3DLIST_NULL = 0,
CORE3DLIST_RASTERIZE,
CORE3DLIST_OPENGL
};
SoundInterface_struct *SNDCoreList[] = {
&SNDDummy,
#ifdef DESMUME_COCOA
@ -108,8 +100,7 @@ bool opengl_init()
speed_limit = 100; //default to max speed = normal speed
calcTimeBudget = (NSTimeInterval)(DS_SECONDS_PER_FRAME / ((float)speed_limit / 100.0));
gui_thread = [NSThread currentThread];
current_file = nil;
flash_file = nil;
loadedRomURL = nil;
execution_lock = [[NSLock alloc] init];
sound_lock = [[NSLock alloc] init];
current_screen = nil;
@ -123,20 +114,7 @@ bool opengl_init()
struct armcpu_memory_iface *arm7_memio = &arm7_base_memory_iface;
struct armcpu_ctrl_iface *arm9_ctrl_iface;
struct armcpu_ctrl_iface *arm7_ctrl_iface;
#endif
//Set the flash file if it's in the prefs/cmd line. It will be nil if it isn't.
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
flash_file = [[defaults stringForKey:PREF_FLASH_FILE] retain];
if ([flash_file length] > 0) {
//NSLog(@"Using flash file: \"%@\"\n", flash_file);
} else {
[flash_file release];
flash_file = nil;
//NSLog(@"No flash file given\n");
}
#ifdef GDB_STUB
//create GDB stubs if required
arm9_gdb_port = [defaults integerForKey:PREF_ARM9_GDB_PORT];
arm7_gdb_port = [defaults integerForKey:PREF_ARM7_GDB_PORT];
@ -219,14 +197,14 @@ bool opengl_init()
if((pixel_format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs]) == nil)
{
messageDialog(NSLocalizedString(@"Error", nil), @"Couldn't create OpenGL pixel format for 3D rendering");
[CocoaDSUtil quickDialogUsingTitle:NSLocalizedString(@"Error", nil) message:NSLocalizedString(@"Couldn't create OpenGL pixel format for 3D rendering", nil)];
context = nil;
} else if((context = [[NSOpenGLContext alloc] initWithFormat:pixel_format shareContext:nil]) == nil)
{
[pixel_format release];
pixel_format = nil;
messageDialog(NSLocalizedString(@"Error", nil), @"Couldn't create OpenGL context for 3D rendering");
[CocoaDSUtil quickDialogUsingTitle:NSLocalizedString(@"Error", nil) message:NSLocalizedString(@"Couldn't create OpenGL context for 3D rendering", nil)];
} else
{
[context makeCurrentContext];
@ -253,8 +231,8 @@ bool opengl_init()
if(pixel_buffer == nil)
{
GLenum error = glGetError();
messageDialog(NSLocalizedString(@"Error", nil),
[NSString stringWithFormat:@"Error setting up rgba pixel buffer for 3D rendering (glerror: %d)", error]);
NSString *errorStr = [NSString stringWithFormat:@"Error setting up rgba pixel buffer for 3D rendering (glerror: %d)", error];
[CocoaDSUtil quickDialogUsingTitle:NSLocalizedString(@"Error", nil) message:NSLocalizedString(errorStr, nil)];
} else
{
[context setPixelBuffer:pixel_buffer cubeMapFace:0 mipMapLevel:0 currentVirtualScreen:0];
@ -276,9 +254,9 @@ bool opengl_init()
[context makeCurrentContext];
//oglrender_init = &opengl_init;
NDS_3D_SetDriver(CORE3DLIST_RASTERIZE);
NDS_3D_SetDriver(CORE3DLIST_SWRASTERIZE);
if(!gpu3D->NDS_3D_Init())
messageDialog(NSLocalizedString(@"Error", nil), @"Unable to initialize OpenGL components");
[CocoaDSUtil quickDialogUsingTitle:NSLocalizedString(@"Error", nil) message:NSLocalizedString(@"Unable to initialize OpenGL components", nil)];
}
if(prev_context != nil) //make sure the old context is restored, and make sure our new context is not set in this thread (since the other thread will need it)
@ -294,7 +272,7 @@ bool opengl_init()
volume = 100;
#ifdef DESMUME_COCOA
if(SPU_ChangeSoundCore(SNDCORE_OSX, 735 * 4) != 0)
messageDialog(NSLocalizedString(@"Error", nil), @"Unable to initialize sound core");
[CocoaDSUtil quickDialogUsingTitle:NSLocalizedString(@"Error", nil) message:NSLocalizedString(@"Unable to initialize sound core", nil)];
else
SPU_SetVolume(volume);
#endif
@ -355,8 +333,7 @@ bool opengl_init()
[error_object release];
[context release];
[pixel_format release];
[current_file release];
[flash_file release];
[loadedRomURL release];
[sound_lock release];
[execution_lock release];
@ -395,24 +372,20 @@ bool opengl_init()
//NDS_CreateDummyFirmware(&macDS_firmware);
}
- (BOOL)loadROM:(NSString*)filename
- (BOOL) loadRom:(NSURL *)romURL
{
BOOL result = NO;
//pause if not already paused
BOOL was_paused = [self paused];
[self pause];
//get the flash file
const char *flash;
if (flash_file != nil)
flash = [flash_file UTF8String];
else
flash = NULL;
//load the rom
if(!NDS_LoadROM([filename cStringUsingEncoding:NSUTF8StringEncoding], flash) > 0)
result = [CocoaDSFile loadRom:romURL];
if(!result)
{
//if it didn't work give an error and dont unpause
messageDialog(NSLocalizedString(@"Error", nil), @"Could not open file");
[CocoaDSUtil quickDialogUsingTitle:NSLocalizedString(@"Error", nil) message:NSLocalizedString(@"Could not open file", nil)];
//continue playing if load didn't work
if(was_paused == NO)[self execute];
@ -427,9 +400,10 @@ bool opengl_init()
current_screen = nil;
}
//set local vars
current_file = filename;
[current_file retain];
// Retain a copy of the URL of the currently loaded ROM, since we'll be
// using it later.
loadedRomURL = romURL;
[loadedRomURL retain];
//this is incase emulation stopped from the
//emulation core somehow
@ -440,7 +414,7 @@ bool opengl_init()
- (BOOL)ROMLoaded
{
return (current_file==nil)?NO:YES;
return (loadedRomURL==nil)?NO:YES;
}
- (void)closeROM
@ -455,8 +429,8 @@ bool opengl_init()
NDS_FreeROM();
[current_file release];
current_file = nil;
[loadedRomURL release];
loadedRomURL = nil;
}
- (NSImage*)ROMIcon
@ -538,9 +512,9 @@ bool opengl_init()
return result;
}
- (NSString*)ROMFile
- (NSString*)romFileName
{
return current_file;
return [[loadedRomURL path] lastPathComponent];
}
- (NSString*)ROMTitle
@ -573,18 +547,6 @@ bool opengl_init()
return NDS_getROMHeader()->ARM7binSize + NDS_getROMHeader()->ARM7src;
}
- (NSString*)flashFile
{
return flash_file;
}
- (void)setFlashFile:(NSString*)filename
{
if (flash_file)
[flash_file release];
flash_file = [filename retain];
}
- (BOOL)executing
{
return run;
@ -633,23 +595,6 @@ bool opengl_init()
execute = true;
}
- (void)setFrameSkip:(int)frameskip
{
dsStateBuffer->frame_skip = frameskip;
if(frameskip < 0)
{
dsStateBuffer->frame_skip = -1;
}
doesConfigNeedUpdate = true;
}
- (int)frameSkip
{
return frame_skip;
}
- (void)setSpeedLimit:(int)speedLimit
{
if(speedLimit < 0 || speedLimit > 1000)
@ -680,44 +625,6 @@ bool opengl_init()
return CommonSettings.manualBackupType;
}
- (BOOL)saveState:(NSString*)file
{
[execution_lock lock];
BOOL result = NO;
if(savestate_save([file cStringUsingEncoding:NSUTF8StringEncoding]))
result = YES;
[execution_lock unlock];
return result;
}
- (BOOL)loadState:(NSString*)file
{
[execution_lock lock];
//Set the GPU context (if it exists) incase the core needs to load anything into opengl during state load
NSOpenGLContext *prev_context = [NSOpenGLContext currentContext];
[prev_context retain];
[context makeCurrentContext];
BOOL result = NO;
if(savestate_load([file cStringUsingEncoding:NSUTF8StringEncoding]))
result = YES;
[execution_lock unlock];
if(prev_context != nil)
{
[prev_context makeCurrentContext];
[prev_context release];
} else
[NSOpenGLContext clearCurrentContext];
return result;
}
- (BOOL) isSubScreenLayerDisplayed:(int)i
{
GPU *theGPU = SubScreen.gpu;
@ -1106,7 +1013,7 @@ bool opengl_init()
- (void) padTime:(NSTimeInterval)timePad
{
#if (MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4) // Code for Mac OS X 10.4 and earlier
#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 // Code for Mac OS X 10.4 and earlier
[NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:timePad]];

View File

@ -1,32 +1,34 @@
/* Copyright (C) 2007 Jeff Bland
/*
Copyright (C) 2007 Jeff Bland
Copyright (C) 2011 Roger Manuel
Copyright (C) 2012 DeSmuME team
This file is part of DeSmuME
DeSmuME is free software; you can redistribute it and/or modify
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
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
DeSmuME is distributed in the hope that it will be useful,
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 DeSmuME; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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
#define PREF_EXECUTE_UPON_LOAD @"Execute Upon Load"
#define PREF_AFTER_LAUNCHED @"When Launching, Load"
#define PREF_AFTER_LAUNCHED_OPTION_NOTHING @"Load Nothing"
#define PREF_AFTER_LAUNCHED_OPTION_LAST_ROM @"Load Last ROM"
#define PREF_FLASH_FILE @"Flash File"
#ifdef GDB_STUB
#define PREF_ARM9_GDB_PORT @"arm9gdb"
#define PREF_ARM7_GDB_PORT @"arm7gdb"

View File

@ -1,24 +1,24 @@
/* Copyright (C) 2007 Jeff Bland
/*
Copyright (C) 2007 Jeff Bland
Copyright (C) 2011 Roger Manuel
Copyright (C) 2012 DeSmuME team
This file is part of DeSmuME
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.
DeSmuME 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.
DeSmuME 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 DeSmuME; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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 "preferences.h"
#import "globals.h"
#import "cocoa_util.h"
#import "input.h"
/* Preference settings are stored using NSUserDefaults
@ -49,9 +49,6 @@ NSMutableDictionary *defaults;
void setAppDefaults()
{
defaults = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
//Flash file default
@"", PREF_FLASH_FILE,
//Interface defaults
@"Yes", PREF_EXECUTE_UPON_LOAD,
@ -376,7 +373,7 @@ NSView *createPreferencesView(NSString *helpinfo, NSDictionary *options, id dele
NSString *default_setting = [defaults objectForKey:key_raw];
//show an error
messageDialog(NSLocalizedString(@"Error",nil), [NSString stringWithFormat:@"%@ setting corrupt (%@), resetting to default (%@)", key, NSLocalizedString(current_setting, nil), NSLocalizedString(default_setting, nil)]);
[CocoaDSUtil quickDialogUsingTitle:NSLocalizedString(@"Error", nil) message:[NSString stringWithFormat:@"%@ setting corrupt (%@), resetting to default (%@)", key, NSLocalizedString(current_setting, nil), NSLocalizedString(default_setting, nil)]];
//set the setting to default
[[NSUserDefaults standardUserDefaults] setObject:default_setting forKey:key_raw];

View File

@ -1,23 +1,27 @@
/* Copyright (C) 2007 Jeff Bland
/*
Copyright (C) 2007 Jeff Bland
Copyright (C) 2011 Roger Manuel
Copyright (C) 2012 DeSmuME team
This file is part of DeSmuME
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.
DeSmuME 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.
DeSmuME 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 DeSmuME; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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 "globals.h"
#import <Cocoa/Cocoa.h>
#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
#include "macosx_10_4_compat.h"
#endif
#define DS_BPP 2 //bytes per pixel
#define DS_SCREEN_X_RATIO (256.0 / (192.0 * 2.0))

View File

@ -1,23 +1,24 @@
/* Copyright (C) 2007 Jeff Bland
/*
Copyright (C) 2007 Jeff Bland
Copyright (C) 2011 Roger Manuel
Copyright (C) 2012 DeSmuME team
This file is part of DeSmuME
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.
DeSmuME 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.
DeSmuME 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 DeSmuME; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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 "screen_state.h"
#import "cocoa_util.h"
@implementation ScreenState
+ (NSInteger)width
@ -85,41 +86,67 @@
return color_data;
}
- (NSImage*)image
- (NSImage *)image
{
NSImage *result = [[NSImage alloc] initWithSize:[ScreenState size]];
[result addRepresentation:[self imageRep]];
return [result autorelease];
}
- (NSBitmapImageRep*)imageRep
{
NSBitmapImageRep *image = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
pixelsWide:DS_SCREEN_WIDTH
pixelsHigh:DS_SCREEN_HEIGHT*2
bitsPerSample:8
samplesPerPixel:3
hasAlpha:NO
isPlanar:NO
colorSpaceName:NSCalibratedRGBColorSpace
bytesPerRow:DS_SCREEN_WIDTH*3
bitsPerPixel:24];
if(image == nil)return nil;
unsigned char *bitmap_data = [image bitmapData];
const unsigned short *buffer_16 = (unsigned short*)color_data;
int i;
for(i = 0; i < DS_SCREEN_WIDTH * DS_SCREEN_HEIGHT*2; i++)
{ //this loop we go through pixel by pixel and convert from 16bit to 24bit for the NSImage
*(bitmap_data++) = (*buffer_16 & 0x001F) << 3;
*(bitmap_data++) = (*buffer_16 & 0x03E0) >> 5 << 3;
*(bitmap_data++) = (*buffer_16 & 0x7C00) >> 10 << 3;
buffer_16++;
NSImage *newImage = [[NSImage alloc] initWithSize:[ScreenState size]];
if (newImage == nil)
{
return newImage;
}
return [image autorelease];
// Render the frame in an NSBitmapImageRep
NSBitmapImageRep *newImageRep = [self imageRep];
if (newImageRep == nil)
{
[newImage release];
newImage = nil;
return newImage;
}
// Attach the rendered frame to the NSImageRep
[newImage addRepresentation:newImageRep];
return newImage;
}
@end
- (NSBitmapImageRep *)imageRep
{
if (color_data == nil)
{
return nil;
}
NSUInteger w = DS_SCREEN_WIDTH;
NSUInteger h = DS_SCREEN_HEIGHT * 2;
NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
pixelsWide:w
pixelsHigh:h
bitsPerSample:8
samplesPerPixel:4
hasAlpha:YES
isPlanar:NO
colorSpaceName:NSCalibratedRGBColorSpace
bytesPerRow:w * 4
bitsPerPixel:32];
if(imageRep == nil)
{
return imageRep;
}
UInt32 *bitmapData = (UInt32 *)[imageRep bitmapData];
RGBA5551ToRGBA8888Buffer((const uint16_t *)color_data, (uint32_t *)bitmapData, (w * h));
#ifdef __BIG_ENDIAN__
UInt32 *bitmapDataEnd = bitmapData + (w * h);
while (bitmapData < bitmapDataEnd)
{
*bitmapData++ = CFSwapInt32LittleToHost(*bitmapData);
}
#endif
return [imageRep autorelease];
}
@end

View File

@ -1,23 +1,24 @@
/* Copyright (C) 2007 Jeff Bland
/*
Copyright (C) 2007 Jeff Bland
Copyright (C) 2011 Roger Manuel
Copyright (C) 2012 DeSmuME team
This file is part of DeSmuME
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.
DeSmuME 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.
DeSmuME 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 DeSmuME; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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 "screenshot.h"
#import "cocoa_util.h"
#import "nds_control.h"
#import "screen_state.h"
@ -180,7 +181,7 @@
//tell cocoa save the file
NSBitmapImageRep *image = [screen imageRep];
if(image == nil)
messageDialog(NSLocalizedString(@"Error", nil), @"Couldn't create the screenshot image");
[CocoaDSUtil quickDialogUsingTitle:NSLocalizedString(@"Error", nil) message:NSLocalizedString(@"Couldn't create the screenshot image", nil)];
else
[[image representationUsingType:type properties:[NSDictionary dictionary]]
writeToFile:[panel filename] atomically:NO];

View File

@ -1,23 +1,23 @@
/* Copyright (C) 2007 Jeff Bland
/*
Copyright (C) 2007 Jeff Bland
Copyright (C) 2011 Roger Manuel
Copyright (C) 2012 DeSmuME team
This file is part of DeSmuME
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.
DeSmuME 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.
DeSmuME 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 DeSmuME; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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 "nds_control.h"
#import <Cocoa/Cocoa.h>
//This class uses OpenGL for drawing for speed
//if opengl is not available it uses NSImage

View File

@ -1,23 +1,25 @@
/* Copyright (C) 2007 Jeff Bland
/*
Copyright (C) 2007 Jeff Bland
Copyright (C) 2011 Roger Manuel
Copyright (C) 2012 DeSmuME team
This file is part of DeSmuME
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.
DeSmuME 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.
DeSmuME 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 DeSmuME; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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 "video_output_view.h"
#import "nds_control.h"
#import "cocoa_util.h"
#import "screen_state.h"
#define HORIZONTAL(angle) ((angle) == -90 || (angle) == -270)
@ -45,7 +47,7 @@
if(self==nil)
{
messageDialog(NSLocalizedString(@"Error", nil), @"Couldn't create a view for video output");
[CocoaDSUtil quickDialogUsingTitle:NSLocalizedString(@"Error", nil) message:NSLocalizedString(@"Couldn't create a view for video output", nil)];
return nil;
}
@ -72,7 +74,7 @@
NSOpenGLPixelFormat* pixel_format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
if(pixel_format == nil)
{
messageDialog(NSLocalizedString(@"Error", nil), @"Couldn't create OpenGL pixel format for video output");
[CocoaDSUtil quickDialogUsingTitle:NSLocalizedString(@"Error", nil) message:NSLocalizedString(@"Couldn't create OpenGL pixel format for video output", nil)];
context = nil;
[self release];
return nil;
@ -83,7 +85,7 @@
[pixel_format release];
if(context == nil)
{
messageDialog(NSLocalizedString(@"Error", nil), @"Couldn't create OpenGL context for video output");
[CocoaDSUtil quickDialogUsingTitle:NSLocalizedString(@"Error", nil) message:NSLocalizedString(@"Couldn't create OpenGL context for video output", nil)];
[self release];
return nil;
}
@ -116,7 +118,7 @@
if(screen == nil)
{
messageDialog(NSLocalizedString(@"Error", nil), @"Recieved invalid screen update");
[CocoaDSUtil quickDialogUsingTitle:NSLocalizedString(@"Error", nil) message:NSLocalizedString(@"Recieved invalid screen update", nil)];
return;
}