From 764697ec8c3cf66910e78ea29571238c13a58682 Mon Sep 17 00:00:00 2001 From: gecko_reverse Date: Sun, 6 Apr 2008 08:08:25 +0000 Subject: [PATCH] Applied patch by TypeError (adds FAT image support and corrects function calls without prototypes), fixed various compile warnings in OGLrender, fixed an error message that would have crashed (c string instead of expected obj-c string) --- desmume/ChangeLog | 1 + desmume/README.MAC | 27 +++++++---- desmume/src/SPU.h | 1 + desmume/src/armcpu.h | 2 +- desmume/src/cflash.c | 16 ++++--- .../cocoa/DeSmuME.xcodeproj/project.pbxproj | 2 + desmume/src/cocoa/English.strings | Bin 6390 -> 6492 bytes desmume/src/cocoa/Japanese.strings | Bin 5750 -> 5832 bytes desmume/src/cocoa/main.m | 25 +++++++++++ desmume/src/cocoa/nds_control.h | 5 +++ desmume/src/cocoa/nds_control.m | 40 +++++++++++++++-- desmume/src/cocoa/preferences.h | 2 + desmume/src/cocoa/preferences.m | 7 ++- desmume/src/cocoa/screenshot.m | 2 +- desmume/src/cocoa/sndOSX.h | 8 +++- desmume/src/fs-linux.c | 1 + desmume/src/mc.c | 1 + desmume/src/windows/OGLRender.c | 42 +++++++++--------- 18 files changed, 140 insertions(+), 42 deletions(-) diff --git a/desmume/ChangeLog b/desmume/ChangeLog index b27fd8b2b..718d6b598 100644 --- a/desmume/ChangeLog +++ b/desmume/ChangeLog @@ -14,6 +14,7 @@ - Added an optional status bar (resize handle no longer overlaps screen). [Jeff B] - New ROM Info and About DeSmuME windows have been added. [Jeff B] - Fixed several bugs in window resizing. [Jeff B] + - Added FAT image support for homebrew games (thanks to TypeError). [Jeff B] general: - Fixed possible segfault in ROMReader on ia64 and amd64. [evilynux] - Fixed a crash bug with 2D background corrupting memory [shash] diff --git a/desmume/README.MAC b/desmume/README.MAC index d5547444a..8cb671fb5 100644 --- a/desmume/README.MAC +++ b/desmume/README.MAC @@ -6,8 +6,8 @@ 1) Compiling instructions...................................13 2) How to use DeSmuME.......................................31 -3) Contact information......................................67 -4) Disclaimer...............................................84 +3) Contact information......................................76 +4) Disclaimer...............................................93 1 Compiling instructions______________________________________ @@ -45,7 +45,7 @@ Linux and Windows versions. Click the lower screen for DS touch-screen input. -Here are the default key mappings(they may be subject to change): +Here are the default key mappings(may be subject to change): up arrow - Up left arrow - Left down arrow - Down @@ -59,10 +59,19 @@ n - Right Trigger enter - Start button space - Select button -Shift + F1 (through F10) will save the state with the corresponding number. -F1 (through F10) will load the state with the corresponding number. +Shift + F1 (through F10) will save the state with the +corresponding number. F1 (through F10) will load the state +with the corresponding number. -NOTE: These key bindings may not be correct on foreign keyboards. +NOTE: These key bindings may not be correct on foreign +keyboards. + +To set up a FAT disk image (for homebrew apps) you can use the +"Emulation > Set FAT Image File" option in the menu. You can +also set this from the command line by launching DeSmuME +inside its app bundle: + +DeSmuME.app/Contents/MacOS/DeSmuME -FlashFile /path/to/file.img 3 Contact information_________________________________________ @@ -77,9 +86,9 @@ Web: http://desmume.sourceforge.net Please don't ask for roms, bios files or any other copyrighted stuff. -If you want to submit a bug report, please run desmume, go into -the "Help" menu, and click on "Submit a bug report". If you're -having trouble with it, please feel free to email. +If you want to submit a bug report, please run desmume, go +into the "Help" menu, and click on "Submit a bug report". If +you're having trouble with it, please feel free to email. 4 Disclaimer__________________________________________________ diff --git a/desmume/src/SPU.h b/desmume/src/SPU.h index 4a7650369..eff5845f5 100644 --- a/desmume/src/SPU.h +++ b/desmume/src/SPU.h @@ -88,6 +88,7 @@ void SPU_KeyOn(int channel); void SPU_WriteByte(u32 addr, u8 val); void SPU_WriteWord(u32 addr, u16 val); void SPU_WriteLong(u32 addr, u32 val); +u32 SPU_ReadLong(u32 addr); void SPU_Emulate(void); #endif diff --git a/desmume/src/armcpu.h b/desmume/src/armcpu.h index cc6c0d1ab..733716f64 100644 --- a/desmume/src/armcpu.h +++ b/desmume/src/armcpu.h @@ -233,7 +233,7 @@ void armcpu_init(armcpu_t *armcpu, u32 adr); u32 armcpu_switchMode(armcpu_t *armcpu, u8 mode); static u32 armcpu_prefetch(armcpu_t *armcpu); u32 armcpu_exec(armcpu_t *armcpu); -//BOOL armcpu_irqExeption(armcpu_t *armcpu); +BOOL armcpu_irqExeption(armcpu_t *armcpu); //BOOL armcpu_prefetchExeption(armcpu_t *armcpu); BOOL armcpu_flagIrq( armcpu_t *armcpu); diff --git a/desmume/src/cflash.c b/desmume/src/cflash.c index 244ed4754..4d6be20e3 100644 --- a/desmume/src/cflash.c +++ b/desmume/src/cflash.c @@ -36,6 +36,7 @@ #define WRITE_FN _write #define READ_FN _read #else +#include #define OPEN_MODE O_RDWR #define OPEN_FN open @@ -67,7 +68,7 @@ debug_output( const char *fmt, ...) { } #endif -#if 0 +#if 1 #ifdef WIN32 #define LOCAL_LOG debug_output #else @@ -483,12 +484,16 @@ cflash_init( const char *disk_image_filename) { if ( disk_image != -1) { file_size = LSEEK_FN( disk_image, 0, SEEK_END); - LSEEK_FN( disk_image, 0, SEEK_SET); + if (0 && file_size == -1) { + LOCAL_LOG( "Error when seeking to end of disk image" ); + } else { + LSEEK_FN( disk_image, 0, SEEK_SET); - LOCAL_LOG( "Disk image size = %d (%d sectors)\n", + LOCAL_LOG( "Disk image size = %d (%d sectors)\n", file_size, file_size / 512); - init_good = TRUE; - } + init_good = TRUE; + } + } else { LOCAL_LOG("Failed to open file %s: \"%s\"\n", disk_image_filename, @@ -643,6 +648,7 @@ cflash_read(unsigned int address) { BUFFERED_BLOCK_SIZE - read_bytes); if ( cur_read == -1) { + LOCAL_LOG( "Error during read: %s\n", strerror(errno) ); break; } read_bytes += cur_read; diff --git a/desmume/src/cocoa/DeSmuME.xcodeproj/project.pbxproj b/desmume/src/cocoa/DeSmuME.xcodeproj/project.pbxproj index ae2299b6c..d1f48d2e6 100644 --- a/desmume/src/cocoa/DeSmuME.xcodeproj/project.pbxproj +++ b/desmume/src/cocoa/DeSmuME.xcodeproj/project.pbxproj @@ -466,6 +466,7 @@ ARCHS = "$(ARCHS_STANDARD_32_BIT)"; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = DESMUME_COCOA; + GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; ONLY_ACTIVE_ARCH = YES; @@ -480,6 +481,7 @@ ALWAYS_SEARCH_USER_PATHS = NO; ARCHS = "$(ARCHS_STANDARD_32_BIT)"; GCC_PREPROCESSOR_DEFINITIONS = DESMUME_COCOA; + GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; PREBINDING = NO; diff --git a/desmume/src/cocoa/English.strings b/desmume/src/cocoa/English.strings index 27935162f9e38aac9274bd1d2f237c31e6eb331e..5f3c7d39f36c2f6b2f203f5c00f5cb36cbd3cf65 100644 GIT binary patch delta 82 zcmexnc*kf%4Xd;gLoh=sLkWWdgByb*LkN)eWXNSmWJqU7oopx~tf;_X3lzhzN_=w- HYn3nn$!HK$ delta 12 Tcmca(^v!TX4eRDdtX0AQDE0-8 diff --git a/desmume/src/cocoa/Japanese.strings b/desmume/src/cocoa/Japanese.strings index 2f257572d05d562e552b9b0054df42039104cbbe..aa24276c894182bf2d4a0c7ef0d61b3164e2544e 100644 GIT binary patch delta 66 zcmeySb3%864y&{hLoh=sLkWWdgByb*LkN)eWXNSmWJqU7oh&INEea9MGgxBq(BO~3 P4g);~Al$6V8Yl<=0ksc_ delta 16 XcmX@1`%Pzq4(sH9%p9BBSe*m`Jk$mz diff --git a/desmume/src/cocoa/main.m b/desmume/src/cocoa/main.m index 2bfbcb431..deec232aa 100644 --- a/desmume/src/cocoa/main.m +++ b/desmume/src/cocoa/main.m @@ -24,6 +24,7 @@ Based on work by yopyop and the DeSmuME team! */ #import "main_window.h" +#import "preferences.h" /* FIXME: Hardware acceleration for openglrender.c ?? @@ -267,6 +268,10 @@ a way to get the time of a save that's not a string / human formatted... [frame_skip_menu release]; + [emulation addItem:[NSMenuItem separatorItem]]; + + temp = [emulation addItemWithTitle:NSLocalizedString(@"Set FAT Image File...", nil) action:@selector(pickFlash) keyEquivalent:@""]; + [emulation release]; //Create the screens menu @@ -432,6 +437,8 @@ void joinThread_gdb(void *thread_handle) [panel setCanChooseFiles:YES]; [panel setAllowsMultipleSelection:NO]; + [panel setTitle:NSLocalizedString(@"Open ROM...", nil)]; + if([panel runModalForDirectory:nil file:nil types:[NSArray arrayWithObjects:@"NDS", @"DS.GBA", nil]] == NSOKButton) { NSString* selected_file = [[panel filenames] lastObject]; //hopefully also the first object @@ -440,6 +447,24 @@ void joinThread_gdb(void *thread_handle) } } +- (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 diff --git a/desmume/src/cocoa/nds_control.h b/desmume/src/cocoa/nds_control.h index b307d128c..ff3895c9f 100644 --- a/desmume/src/cocoa/nds_control.h +++ b/desmume/src/cocoa/nds_control.h @@ -62,6 +62,7 @@ volatile int frame_skip; NSString *current_file; + NSString *flash_file; unsigned char gpu_buff[256 * 256 * 5]; //this is where the 3D rendering of the NDS is stored } @@ -90,6 +91,10 @@ - (NSInteger)ROMARM7Size; - (NSInteger)ROMDataSize; +//Flash memory +- (NSString*)flashFile; +- (void)setFlashFile:(NSString*)filename; + //execution control - (BOOL)executing; - (void)execute; diff --git a/desmume/src/cocoa/nds_control.m b/desmume/src/cocoa/nds_control.m index 22c329386..21bf56d6c 100644 --- a/desmume/src/cocoa/nds_control.m +++ b/desmume/src/cocoa/nds_control.m @@ -18,10 +18,12 @@ */ #import "nds_control.h" +#import //DeSmuME general includes #define OBJ_C #include "sndOSX.h" +#include "preferences.h" #include "../NDSSystem.h" #include "../saves.h" #include "../render3D.h" @@ -70,9 +72,21 @@ struct NDS_fw_config_data firmware; frame_skip = -1; //default to auto frame skip gui_thread = [NSThread currentThread]; current_file = nil; + flash_file = nil; sound_lock = [[NSLock alloc] init]; current_screen = nil; + //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"); + } + //check if we can sen messages on other threads, which we will use for video update timer_based = ([NSObject instancesRespondToSelector:@selector(performSelector:onThread:withObject:waitUntilDone:)]==NO)?true:false; @@ -181,6 +195,7 @@ struct NDS_fw_config_data firmware; [context release]; [pixel_format release]; [current_file release]; + [flash_file release]; [sound_lock release]; NDS_DeInit(); @@ -208,8 +223,15 @@ struct NDS_fw_config_data firmware; 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:NSASCIIStringEncoding], backupmemorytype, backupmemorysize, "temp.sav") > 0) + if(!NDS_LoadROM([filename cStringUsingEncoding:NSASCIIStringEncoding], backupmemorytype, backupmemorysize, flash) > 0) { //if it didn't work give an error and dont unpause messageDialog(NSLocalizedString(@"Error", nil), @"Could not open file"); @@ -217,7 +239,7 @@ struct NDS_fw_config_data firmware; //continue playing if load didn't work if(was_paused == NO)[self execute]; - return FALSE; + return NO; } //clear screen data @@ -235,7 +257,7 @@ struct NDS_fw_config_data firmware; //emulation core somehow execute = true; - return true; + return YES; } - (BOOL)ROMLoaded @@ -373,6 +395,18 @@ struct NDS_fw_config_data firmware; 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; diff --git a/desmume/src/cocoa/preferences.h b/desmume/src/cocoa/preferences.h index bfb64b470..ae5cddb9a 100644 --- a/desmume/src/cocoa/preferences.h +++ b/desmume/src/cocoa/preferences.h @@ -17,4 +17,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#define PREF_FLASH_FILE @"FlashFile" + void setAppDefaults(); //this is defined in preferences.m and should be called at app launch diff --git a/desmume/src/cocoa/preferences.m b/desmume/src/cocoa/preferences.m index b80267ef7..b95b26cfa 100644 --- a/desmume/src/cocoa/preferences.m +++ b/desmume/src/cocoa/preferences.m @@ -241,7 +241,11 @@ void setAppDefaults() //@"DeSmuME User", PREF_FIRMWARE_PLAYER_NAME, //@"English", PREF_FIRMWARE_LANGUAGE, + //Flash file default + @"", PREF_FLASH_FILE, + nil]; + [desmume_defaults retain]; //window size defaults @@ -253,7 +257,6 @@ void setAppDefaults() //[NSData dataWithBytes:&temp length:sizeof(NSRect)], @"DeSmuME Preferences Window", nil]; [[NSUserDefaults standardUserDefaults] registerDefaults:desmume_defaults]; - } //this is a hack - in the nib we connect preferences to this function name, @@ -272,7 +275,7 @@ void setAppDefaults() //---------------------------------------------------------------------------------------------- //get the applications main bundle - NSBundle* app_bundle = [NSBundle mainBundle]; + //NSBundle* app_bundle = [NSBundle mainBundle]; //get a font for displaying text preferences_font = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSRegularControlSize]]; diff --git a/desmume/src/cocoa/screenshot.m b/desmume/src/cocoa/screenshot.m index 2add30893..2342e5156 100644 --- a/desmume/src/cocoa/screenshot.m +++ b/desmume/src/cocoa/screenshot.m @@ -179,7 +179,7 @@ //tell cocoa save the file NSBitmapImageRep *image = [screen imageRep]; if(image == nil) - messageDialog(NSLocalizedString(@"Error", nil), "Couldn't create the screenshot image"); + messageDialog(NSLocalizedString(@"Error", nil), @"Couldn't create the screenshot image"); else [[image representationUsingType:type properties:[NSDictionary dictionary]] writeToFile:[panel filename] atomically:NO]; diff --git a/desmume/src/cocoa/sndOSX.h b/desmume/src/cocoa/sndOSX.h index 2ea8e05e5..255f0c8ff 100644 --- a/desmume/src/cocoa/sndOSX.h +++ b/desmume/src/cocoa/sndOSX.h @@ -26,7 +26,13 @@ extern SoundInterface_struct SNDOSX; //Beyond this point are sound interface extensions specific to the mac port -//recording to file + +int SNDOSXReset(); +void SNDOSXMuteAudio(); +void SNDOSXUnMuteAudio(); +void SNDOSXSetVolume(int volume); + +//Recording bool SNDOSXOpenFile(void *fname); //opens a file for recording (if filename is the currently opened one, it will restart the file), fname is an NSString void SNDOSXStartRecording(); //begins recording to the currently open file if there is an open file void SNDOSXStopRecording(); //pauses recording (you can continue recording later) diff --git a/desmume/src/fs-linux.c b/desmume/src/fs-linux.c index f3993e52a..d01b03c26 100644 --- a/desmume/src/fs-linux.c +++ b/desmume/src/fs-linux.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include diff --git a/desmume/src/mc.c b/desmume/src/mc.c index eff6395f8..226dcc48c 100644 --- a/desmume/src/mc.c +++ b/desmume/src/mc.c @@ -19,6 +19,7 @@ */ #include +#include #include "debug.h" #include "types.h" #include "mc.h" diff --git a/desmume/src/windows/OGLRender.c b/desmume/src/windows/OGLRender.c index 9dc058f9c..e9dc163d8 100644 --- a/desmume/src/windows/OGLRender.c +++ b/desmume/src/windows/OGLRender.c @@ -19,13 +19,15 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include +#include +#include + #ifndef DESMUME_COCOA #define WIN32_LEAN_AND_MEAN #include #include -#include -#include #include "..\debug.h" #include "..\MMU.h" #include "..\bits.h" @@ -33,7 +35,6 @@ #else - #include #include #include "../debug.h" @@ -174,7 +175,7 @@ char NDS_glInit(void) glClearColor (0.0f, 0.0f, 0.0f, 0.0f); glColor3f (1.f, 1.f, 1.f); - glGenTextures (1, &oglTextureID); + glGenTextures (1, (GLuint*)&oglTextureID); glViewport(0, 0, 256, 192); @@ -485,13 +486,14 @@ static __inline void SetupTexture (unsigned int format, unsigned int palette) unsigned int sizeY = (1<<(((format>>23)&0x7)+3)); unsigned int mode = (unsigned short)((format>>26)&0x7); unsigned char * adr = (unsigned char *)(ARM9Mem.ARM9_LCD + ((format&0xFFFF)<<3)); - unsigned short param = (unsigned short)((format>>30)&0xF); - unsigned short param2 = (unsigned short)((format>>16)&0xF); + //unsigned short param = (unsigned short)((format>>30)&0xF); + //unsigned short param2 = (unsigned short)((format>>16)&0xF); unsigned int imageSize = sizeX*sizeY; unsigned int paletteSize = 0; unsigned int palZeroTransparent = (1-((format>>29)&1))*255; // shash: CONVERT THIS TO A TABLE :) unsigned int x=0, y=0; - unsigned char * dst = texMAP, *src = NULL; + unsigned char * dst = texMAP; + //unsigned char *src = NULL; if (mode == 0) glDisable (GL_TEXTURE_2D); @@ -841,7 +843,7 @@ static __inline void SetupTexture (unsigned int format, unsigned int palette) case 2: { - u32 *src = (u32*)texMAP, *dst = (u32*)texMAP2; + u32 *src = (u32*)texMAP;//, *dst = (u32*)texMAP2; for (y = 0; y < sizeY; y++) { @@ -957,7 +959,7 @@ void NDS_glBegin(unsigned long v) */ colorRGB[3] = colorAlpha; - glColor4iv (colorRGB); + glColor4iv ((GLint*)colorRGB); } else { @@ -1003,7 +1005,7 @@ void NDS_glColor3b(unsigned long v) colorRGB[0] = (v&0x1F) << 26; colorRGB[1] = ((v>>5)&0x1F) << 26; colorRGB[2] = ((v>>10)&0x1F) << 26; - glColor4iv (colorRGB); + glColor4iv ((GLint*)colorRGB); } static __inline void SetVertex() @@ -1135,7 +1137,7 @@ void NDS_glFlush(unsigned long v) void NDS_glPolygonAttrib (unsigned long val) { - u32 polygonID = (val>>24)&63; + //u32 polygonID = (val>>24)&63; // Light enable/disable lightMask = (val&0xF); @@ -1188,8 +1190,8 @@ void NDS_glMaterial0 (unsigned long val) glEnd(); } - glMaterialiv (GL_FRONT_AND_BACK, GL_AMBIENT, ambient); - glMaterialiv (GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse); + glMaterialiv (GL_FRONT_AND_BACK, GL_AMBIENT, (GLint*)ambient); + glMaterialiv (GL_FRONT_AND_BACK, GL_DIFFUSE, (GLint*)diffuse); if (beginCalled) { @@ -1213,8 +1215,8 @@ void NDS_glMaterial1 (unsigned long val) glEnd(); } - glMaterialiv (GL_FRONT_AND_BACK, GL_SPECULAR, specular); - glMaterialiv (GL_FRONT_AND_BACK, GL_EMISSION, emission); + glMaterialiv (GL_FRONT_AND_BACK, GL_SPECULAR, (GLint*)specular); + glMaterialiv (GL_FRONT_AND_BACK, GL_EMISSION, (GLint*)emission); if (beginCalled) { @@ -1317,9 +1319,9 @@ void NDS_glLightColor (unsigned long v) if (beginCalled) glEnd(); - glLightiv(GL_LIGHT0 + index, GL_AMBIENT, lightColor); - glLightiv(GL_LIGHT0 + index, GL_DIFFUSE, lightColor); - glLightiv(GL_LIGHT0 + index, GL_SPECULAR, lightColor); + glLightiv(GL_LIGHT0 + index, GL_AMBIENT, (GLint*)lightColor); + glLightiv(GL_LIGHT0 + index, GL_DIFFUSE, (GLint*)lightColor); + glLightiv(GL_LIGHT0 + index, GL_SPECULAR, (GLint*)lightColor); if (beginCalled) glBegin (vtxFormat); @@ -1383,7 +1385,7 @@ void NDS_glNormal(unsigned long v) void NDS_glCallList(unsigned long v) { - static unsigned long oldval = 0, shit = 0; + //static unsigned long oldval = 0, shit = 0; if(!clInd) { @@ -1808,7 +1810,7 @@ void NDS_glCallList(unsigned long v) void NDS_glGetMatrix(unsigned int mode, unsigned int index, float* dest) { - int n; + //int n; if(index == -1) {