[Fuse-for-macosx-commits] SF.net SVN: fuse-for-macosx: [391] trunk/fuse
Brought to you by:
fredm
|
From: <fr...@us...> - 2007-06-20 02:25:53
|
Revision: 391
http://svn.sourceforge.net/fuse-for-macosx/?rev=391&view=rev
Author: fredm
Date: 2007-06-19 19:25:45 -0700 (Tue, 19 Jun 2007)
Log Message:
-----------
AppKit can only be called from the main thread, so pass any calls in the
emulator back to FuseController.
Modified Paths:
--------------
trunk/fuse/fusepb/controllers/FuseController.h
trunk/fuse/fusepb/controllers/FuseController.m
trunk/fuse/fusepb/models/Emulator.h
trunk/fuse/fusepb/models/Emulator.m
trunk/fuse/fusepb/views/DisplayOpenGLView.h
trunk/fuse/fusepb/views/DisplayOpenGLView.m
trunk/fuse/ui/cocoa/cocoaui.m
Modified: trunk/fuse/fusepb/controllers/FuseController.h
===================================================================
--- trunk/fuse/fusepb/controllers/FuseController.h 2007-06-19 02:56:57 UTC (rev 390)
+++ trunk/fuse/fusepb/controllers/FuseController.h 2007-06-20 02:25:45 UTC (rev 391)
@@ -196,6 +196,12 @@
- (void)showAlertPanel:(NSString*)message;
- (void)showCriticalAlertPanel:(NSString*)message;
+-(ui_confirm_save_t) confirmSave:(NSString*)theMessage;
+-(int) tapeWrite;
+-(int) plus3DiskWrite:(specplus3_drive_number)which;
+-(int) trdosDiskWrite:(trdos_drive_number)which;
+-(ui_confirm_joystick_t) confirmJoystick:(libspectrum_joystick)type inputs:(int)theInputs;
+
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication;
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender;
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename;
Modified: trunk/fuse/fusepb/controllers/FuseController.m
===================================================================
--- trunk/fuse/fusepb/controllers/FuseController.m 2007-06-19 02:56:57 UTC (rev 390)
+++ trunk/fuse/fusepb/controllers/FuseController.m 2007-06-20 02:25:45 UTC (rev 391)
@@ -117,6 +117,12 @@
static NSSavePanel *sPanel = nil;
+const char* connection_names[] = {
+ "the keyboard",
+ "joystick 1",
+ "joystick 2",
+};
+
@implementation FuseController
static FuseController *singleton = nil;
@@ -749,7 +755,7 @@
- (IBAction)tape_write:(id)sender
{
- ui_tape_write();
+ [self tapeWrite];
}
- (IBAction)tape_record:(id)sender
@@ -1466,6 +1472,199 @@
NSRunCriticalAlertPanel(@"Fuse - Error", message, nil, nil, nil);
}
+-(ui_confirm_save_t) confirmSave:(NSString*)theMessage
+{
+ int result;
+
+ ui_confirm_save_t confirm;
+
+ if( !settings_current.confirm_actions ) return UI_CONFIRM_SAVE_DONTSAVE;
+
+ [[DisplayOpenGLView instance] pause];
+
+ if( ui_mouse_grabbed ) ui_mouse_grabbed = ui_mouse_release( 1 );
+
+ confirm = UI_CONFIRM_SAVE_CANCEL;
+
+ result = NSRunAlertPanel(@"Confirm", theMessage, @"Save",
+ @"Don't Save", @"Cancel");
+
+ switch( result ) {
+ case NSAlertDefaultReturn:
+ confirm = UI_CONFIRM_SAVE_SAVE;
+ break;
+ case NSAlertAlternateReturn:
+ confirm = UI_CONFIRM_SAVE_DONTSAVE;
+ break;
+ case NSAlertOtherReturn:
+ default:
+ confirm = UI_CONFIRM_SAVE_CANCEL;
+ }
+
+ [[DisplayOpenGLView instance] unpause];
+
+ return confirm;
+}
+
+-(int) tapeWrite
+{
+ char *filename = NULL;
+
+ [[DisplayOpenGLView instance] pause];
+
+ filename = cocoaui_savepanel_get_filename( @"Write Tape As", [NSArray arrayWithObjects:@"tzx", @"tap", @"csw", nil] );
+
+ if( !filename ) { [[DisplayOpenGLView instance] unpause]; return 1; }
+
+ /* We will be calling this from the main thread while the emulator is
+ paused */
+ tape_write( filename );
+
+ [self addRecentSnapshotWithString:[NSString stringWithUTF8String:filename]];
+
+ free( filename );
+
+ [[DisplayOpenGLView instance] unpause];
+
+ return 0;
+}
+
+-(int) plus3DiskWrite:(specplus3_drive_number)which
+{
+ char drive, *filename = NULL;
+
+ drive = which == SPECPLUS3_DRIVE_A ? 'A' : 'B';
+
+ if( !specplus3_disk_present( which ) ) {
+ ui_error( UI_ERROR_INFO, "No disk present in drive %c:", drive );
+ return 0;
+ }
+
+ [[DisplayOpenGLView instance] pause];
+
+ NSString *title = [NSString stringWithFormat:@"Write +3 Disk %c: As", drive];
+ filename = cocoaui_savepanel_get_filename( title, [NSArray arrayWithObjects:@"dsk", nil] );
+
+ if( !filename ) { [[DisplayOpenGLView instance] unpause]; return 1; }
+
+ /* We will be calling this from the Emulator thread */
+ specplus3_disk_write( which, filename );
+
+ [self addRecentSnapshotWithString:[NSString stringWithUTF8String:filename]];
+
+ free( filename );
+
+ [[DisplayOpenGLView instance] unpause];
+
+ return 0;
+}
+
+-(int) trdosDiskWrite:(trdos_drive_number)which
+{
+ char drive, *filename = NULL;
+
+ switch( which ) {
+ case TRDOS_DRIVE_A: drive = 'A'; break;
+ case TRDOS_DRIVE_B: drive = 'B'; break;
+ case TRDOS_DRIVE_C: drive = 'C'; break;
+ case TRDOS_DRIVE_D: drive = 'D'; break;
+ default: drive = '?'; break;
+ }
+
+ [[DisplayOpenGLView instance] pause];
+
+ NSString *title = [NSString stringWithFormat:@"Write TR-DOS Disk %c: As", drive];
+ filename = cocoaui_savepanel_get_filename( title, [NSArray arrayWithObjects:@"trd", nil] );
+
+ if( !filename ) { [[DisplayOpenGLView instance] unpause]; return 1; }
+
+ /* We will be calling this from the main thread with emulator paused */
+ trdos_disk_write( which, filename );
+
+ [self addRecentSnapshotWithString:[NSString stringWithUTF8String:filename]];
+
+ free( filename );
+
+ [[DisplayOpenGLView instance] unpause];
+
+ return 0;
+}
+
+-(ui_confirm_joystick_t) confirmJoystick:(libspectrum_joystick)type inputs:(int)theInputs
+{
+ char* joystick_name;
+ char input_names[256] = "";
+ NSString *alertString;
+ NSAlert *alert;
+
+ if( !settings_current.joy_prompt ) return UI_CONFIRM_JOYSTICK_NONE;
+
+ alert = [[NSAlert alloc] init];
+ [alert addButtonWithTitle:@"None"];
+ [alert addButtonWithTitle:@"Joystick 2"];
+ [alert addButtonWithTitle:@"Joystick 1"];
+ [alert addButtonWithTitle:@"Keyboard"];
+
+ [alert setMessageText:@"Configure joystick"];
+ joystick_name = strdup( libspectrum_joystick_name( type ) );
+ joystick_name[0] = tolower( joystick_name[0] );
+ if( theInputs ) {
+ int num_inputs = 0;
+ int i = 0;
+ const char* conn_names[3];
+
+ for( i = 0; theInputs>>i; i++ ) {
+ if( ( theInputs>> i ) & 0x01 ) {
+ conn_names[num_inputs++] = connection_names[i];
+ }
+ }
+
+ if( num_inputs >= 1 ) {
+ sprintf(input_names, " connected to %s", conn_names[0]);
+ }
+ if( num_inputs >= 3 ) {
+ sprintf(input_names, "%s, %s", input_names, conn_names[2]);
+ }
+ if( num_inputs >= 2 ) {
+ sprintf(input_names, "%s and %s", input_names, conn_names[1]);
+ }
+ }
+ alertString = [NSString stringWithFormat:@"The snapshot you are loading is configured for a %s joystick%s. Fuse is not currently configured for a %s joystick, would you like to connect the joystick to:", joystick_name, input_names, joystick_name ];
+ free( joystick_name );
+
+ [alert setInformativeText:alertString];
+ [alert setAlertStyle:NSWarningAlertStyle];
+
+ ui_confirm_joystick_t confirm;
+
+ if( ui_mouse_grabbed ) ui_mouse_grabbed = ui_mouse_release( 1 );
+
+ [[DisplayOpenGLView instance] pause];
+
+ confirm = UI_CONFIRM_JOYSTICK_NONE;
+
+ switch( [alert runModal] ) {
+ case NSAlertFirstButtonReturn:
+ confirm = UI_CONFIRM_JOYSTICK_NONE;
+ break;
+ case NSAlertSecondButtonReturn:
+ confirm = UI_CONFIRM_JOYSTICK_JOYSTICK_2;
+ break;
+ case NSAlertThirdButtonReturn:
+ confirm = UI_CONFIRM_JOYSTICK_JOYSTICK_1;
+ break;
+ case NSAlertThirdButtonReturn+1:
+ confirm = UI_CONFIRM_JOYSTICK_KEYBOARD;
+ break;
+ }
+
+ [alert release];
+
+ [[DisplayOpenGLView instance] unpause];
+
+ return confirm;
+}
+
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication
{
return YES;
@@ -1865,222 +2064,6 @@
return 0;
}
-int
-ui_tape_write( void )
-{
- char *filename = NULL;
-
- [[DisplayOpenGLView instance] pause];
-
- filename = cocoaui_savepanel_get_filename( @"Write Tape As", [NSArray arrayWithObjects:@"tzx", @"tap", @"csw", nil] );
-
- if( !filename ) { [[DisplayOpenGLView instance] unpause]; return 1; }
-
- /* We will be calling this from the Emulator thread */
- tape_write( filename );
-
- [[FuseController singleton]
- performSelectorOnMainThread:@selector(addRecentSnapshotWithString:)
- withObject:[NSString stringWithUTF8String:filename]
- waitUntilDone:NO
- ];
-
- free( filename );
-
- [[DisplayOpenGLView instance] unpause];
-
- return 0;
-}
-
-int
-ui_plus3_disk_write( specplus3_drive_number which )
-{
- char drive, *filename = NULL;
-
- drive = which == SPECPLUS3_DRIVE_A ? 'A' : 'B';
-
- if( !specplus3_disk_present( which ) ) {
- ui_error( UI_ERROR_INFO, "No disk present in drive %c:", drive );
- return 0;
- }
-
- [[DisplayOpenGLView instance] pause];
-
- NSString *title = [NSString stringWithFormat:@"Write +3 Disk %c: As", drive];
- filename = cocoaui_savepanel_get_filename( title, [NSArray arrayWithObjects:@"dsk", nil] );
-
- if( !filename ) { [[DisplayOpenGLView instance] unpause]; return 1; }
-
- /* We will be calling this from the Emulator thread */
- specplus3_disk_write( which, filename );
-
- [[FuseController singleton]
- performSelectorOnMainThread:@selector(addRecentSnapshotWithString:)
- withObject:[NSString stringWithUTF8String:filename]
- waitUntilDone:NO
- ];
-
- free( filename );
-
- [[DisplayOpenGLView instance] unpause];
-
- return 0;
-}
-
-int
-ui_trdos_disk_write( trdos_drive_number which )
-{
- char drive, *filename = NULL;
-
- switch( which ) {
- case TRDOS_DRIVE_A: drive = 'A'; break;
- case TRDOS_DRIVE_B: drive = 'B'; break;
- case TRDOS_DRIVE_C: drive = 'C'; break;
- case TRDOS_DRIVE_D: drive = 'D'; break;
- default: drive = '?'; break;
- }
-
- [[DisplayOpenGLView instance] pause];
-
- NSString *title = [NSString stringWithFormat:@"Write TR-DOS Disk %c: As", drive];
- filename = cocoaui_savepanel_get_filename( title, [NSArray arrayWithObjects:@"trd", nil] );
-
- if( !filename ) { [[DisplayOpenGLView instance] unpause]; return 1; }
-
- /* We will be calling this from the Emulator thread */
- trdos_disk_write( which, filename );
-
- [[FuseController singleton]
- performSelectorOnMainThread:@selector(addRecentSnapshotWithString:)
- withObject:[NSString stringWithUTF8String:filename]
- waitUntilDone:NO
- ];
-
- free( filename );
-
- [[DisplayOpenGLView instance] unpause];
-
- return 0;
-}
-
-ui_confirm_save_t
-ui_confirm_save( const char *message )
-{
- NSString *alertString = [NSString stringWithUTF8String:message];
- int result;
-
- ui_confirm_save_t confirm;
-
- if( !settings_current.confirm_actions ) return UI_CONFIRM_SAVE_DONTSAVE;
-
- if( ui_mouse_grabbed ) ui_mouse_grabbed = ui_mouse_release( 1 );
-
- [[DisplayOpenGLView instance] pause];
-
- confirm = UI_CONFIRM_SAVE_CANCEL;
-
- result = NSRunAlertPanel(@"Confirm", alertString, @"Save",
- @"Don't Save", @"Cancel");
-
- switch( result ) {
- case NSAlertDefaultReturn:
- confirm = UI_CONFIRM_SAVE_SAVE;
- break;
- case NSAlertAlternateReturn:
- confirm = UI_CONFIRM_SAVE_DONTSAVE;
- break;
- case NSAlertOtherReturn:
- default:
- confirm = UI_CONFIRM_SAVE_CANCEL;
- }
-
- [[DisplayOpenGLView instance] unpause];
-
- return confirm;
-}
-
-const char* connection_names[] = {
- "the keyboard",
- "joystick 1",
- "joystick 2",
-};
-
-ui_confirm_joystick_t
-ui_confirm_joystick( libspectrum_joystick libspectrum_type, int inputs )
-{
- char* joystick_name;
- char input_names[256] = "";
- NSString *alertString;
- NSAlert *alert;
-
- if( !settings_current.joy_prompt ) return UI_CONFIRM_JOYSTICK_NONE;
-
- alert = [[NSAlert alloc] init];
- [alert addButtonWithTitle:@"None"];
- [alert addButtonWithTitle:@"Joystick 2"];
- [alert addButtonWithTitle:@"Joystick 1"];
- [alert addButtonWithTitle:@"Keyboard"];
-
- [alert setMessageText:@"Configure joystick"];
- joystick_name = strdup( libspectrum_joystick_name( libspectrum_type ) );
- joystick_name[0] = tolower( joystick_name[0] );
- if( inputs ) {
- int num_inputs = 0;
- int i = 0;
- const char* conn_names[3];
-
- for( i = 0; inputs>>i; i++ ) {
- if( ( inputs >> i ) & 0x01 ) {
- conn_names[num_inputs++] = connection_names[i];
- }
- }
-
- if( num_inputs >= 1 ) {
- sprintf(input_names, " connected to %s", conn_names[0]);
- }
- if( num_inputs >= 3 ) {
- sprintf(input_names, "%s, %s", input_names, conn_names[2]);
- }
- if( num_inputs >= 2 ) {
- sprintf(input_names, "%s and %s", input_names, conn_names[1]);
- }
- }
- alertString = [NSString stringWithFormat:@"The snapshot you are loading is configured for a %s joystick%s. Fuse is not currently configured for a %s joystick, would you like to connect the joystick to:", joystick_name, input_names, joystick_name ];
- free( joystick_name );
-
- [alert setInformativeText:alertString];
- [alert setAlertStyle:NSWarningAlertStyle];
-
- ui_confirm_joystick_t confirm;
-
- if( ui_mouse_grabbed ) ui_mouse_grabbed = ui_mouse_release( 1 );
-
- [[DisplayOpenGLView instance] pause];
-
- confirm = UI_CONFIRM_JOYSTICK_NONE;
-
- switch( [alert runModal] ) {
- case NSAlertFirstButtonReturn:
- confirm = UI_CONFIRM_JOYSTICK_NONE;
- break;
- case NSAlertSecondButtonReturn:
- confirm = UI_CONFIRM_JOYSTICK_JOYSTICK_2;
- break;
- case NSAlertThirdButtonReturn:
- confirm = UI_CONFIRM_JOYSTICK_JOYSTICK_1;
- break;
- case NSAlertThirdButtonReturn+1:
- confirm = UI_CONFIRM_JOYSTICK_KEYBOARD;
- break;
- }
-
- [alert release];
-
- [[DisplayOpenGLView instance] unpause];
-
- return confirm;
-}
-
static int
cocoaui_confirm( const char *message )
{
Modified: trunk/fuse/fusepb/models/Emulator.h
===================================================================
--- trunk/fuse/fusepb/models/Emulator.h 2007-06-19 02:56:57 UTC (rev 390)
+++ trunk/fuse/fusepb/models/Emulator.h 2007-06-20 02:25:45 UTC (rev 391)
@@ -29,7 +29,10 @@
#include "input.h"
#include "machines/specplus3.h"
#include "trdos.h"
+#include "ui/ui.h"
+@class DisplayOpenGLView;
+
@interface Emulator : NSObject
{
BOOL isEmulating;
@@ -46,6 +49,8 @@
int cocoakeyboard_caps_shift_pressed;
int cocoakeyboard_symbol_shift_pressed;
input_key unicode_keysym;
+
+ DisplayOpenGLView *proxy_view;
}
+(Emulator *) instance;
@@ -158,4 +163,10 @@
-(void) keyDown:(NSEvent *)theEvent;
-(void) keyUp:(NSEvent *)theEvent;
+-(ui_confirm_save_t) confirmSave:(NSString*)theMessage;
+-(int) tapeWrite;
+-(int) plus3DiskWrite:(specplus3_drive_number)which;
+-(int) trdosDiskWrite:(trdos_drive_number)which;
+-(ui_confirm_joystick_t) confirmJoystick:(libspectrum_joystick)type inputs:(int)theInputs;
+
@end
Modified: trunk/fuse/fusepb/models/Emulator.m
===================================================================
--- trunk/fuse/fusepb/models/Emulator.m 2007-06-19 02:56:57 UTC (rev 390)
+++ trunk/fuse/fusepb/models/Emulator.m 2007-06-20 02:25:45 UTC (rev 391)
@@ -76,7 +76,8 @@
connectionWithReceivePort:[portArray objectAtIndex:0]
sendPort:[portArray objectAtIndex:1]];
[serverConnection setRootObject:self];
- [(id)[serverConnection rootProxy] setServer:self];
+ proxy_view = (id)[serverConnection rootProxy];
+ [proxy_view setServer:self];
if( fuse_init( ac, av ) ) {
fprintf( stderr, "%s: error initialising -- giving up!\n", fuse_progname );
@@ -687,4 +688,29 @@
[self keyChange:theEvent type:INPUT_EVENT_KEYRELEASE];
}
+-(ui_confirm_save_t) confirmSave:(NSString*)theMessage
+{
+ return [proxy_view confirmSave:theMessage];
+}
+
+-(int) tapeWrite
+{
+ return [proxy_view tapeWrite];
+}
+
+-(int) plus3DiskWrite:(specplus3_drive_number)which
+{
+ return [proxy_view plus3DiskWrite:which];
+}
+
+-(int) trdosDiskWrite:(trdos_drive_number)which
+{
+ return [proxy_view trdosDiskWrite:which];
+}
+
+-(ui_confirm_joystick_t) confirmJoystick:(libspectrum_joystick)type inputs:(int)theInputs
+{
+ return [proxy_view confirmJoystick:type inputs:theInputs];
+}
+
@end
Modified: trunk/fuse/fusepb/views/DisplayOpenGLView.h
===================================================================
--- trunk/fuse/fusepb/views/DisplayOpenGLView.h 2007-06-19 02:56:57 UTC (rev 390)
+++ trunk/fuse/fusepb/views/DisplayOpenGLView.h 2007-06-20 02:25:45 UTC (rev 391)
@@ -185,6 +185,12 @@
-(void) setTapeState:(NSNumber*)state;
-(void) setMdrState:(NSNumber*)state;
+-(ui_confirm_save_t) confirmSave:(NSString*)theMessage;
+-(int) tapeWrite;
+-(int) plus3DiskWrite:(specplus3_drive_number)which;
+-(int) trdosDiskWrite:(trdos_drive_number)which;
+-(ui_confirm_joystick_t) confirmJoystick:(libspectrum_joystick)type inputs:(int)theInputs;
+
-(void) mouseMoved:(NSEvent *)theEvent;
-(void) mouseDown:(NSEvent *)theEvent;
-(void) mouseUp:(NSEvent *)theEvent;
Modified: trunk/fuse/fusepb/views/DisplayOpenGLView.m
===================================================================
--- trunk/fuse/fusepb/views/DisplayOpenGLView.m 2007-06-19 02:56:57 UTC (rev 390)
+++ trunk/fuse/fusepb/views/DisplayOpenGLView.m 2007-06-20 02:25:45 UTC (rev 391)
@@ -573,9 +573,7 @@
-(void) openFile:(const char *)filename
{
- /* openFile can end up calling a dialog for joystick selection, this must
- run on the main thread */
- [real_emulator openFile:filename];
+ [proxy_emulator openFile:filename];
}
-(void) tapeOpen:(const char *)filename
@@ -887,6 +885,31 @@
//[[FuseController singleton] setMdrState:state];
}
+-(ui_confirm_save_t) confirmSave:(NSString*)theMessage
+{
+ return [[FuseController singleton] confirmSave:theMessage];
+}
+
+-(int) tapeWrite
+{
+ return [[FuseController singleton] tapeWrite];
+}
+
+-(int) plus3DiskWrite:(specplus3_drive_number)which
+{
+ return [[FuseController singleton] plus3DiskWrite:which];
+}
+
+-(int) trdosDiskWrite:(trdos_drive_number)which
+{
+ return [[FuseController singleton] trdosDiskWrite:which];
+}
+
+-(ui_confirm_joystick_t) confirmJoystick:(libspectrum_joystick)type inputs:(int)theInputs
+{
+ return [[FuseController singleton] confirmJoystick:type inputs:theInputs];
+}
+
-(void) mouseMoved:(NSEvent *)theEvent
{
[proxy_emulator mouseMoved:theEvent];
Modified: trunk/fuse/ui/cocoa/cocoaui.m
===================================================================
--- trunk/fuse/ui/cocoa/cocoaui.m 2007-06-19 02:56:57 UTC (rev 390)
+++ trunk/fuse/ui/cocoa/cocoaui.m 2007-06-20 02:25:45 UTC (rev 391)
@@ -29,6 +29,7 @@
#include <stdio.h>
#import "FuseController.h"
+#import "Emulator.h"
#include "display.h"
#include "fuse.h"
@@ -106,3 +107,34 @@
return 0;
}
+
+ui_confirm_save_t
+ui_confirm_save( const char *message )
+{
+ return [[Emulator instance]
+ confirmSave:[NSString stringWithUTF8String:message]];
+}
+
+int
+ui_tape_write( void )
+{
+ return [[Emulator instance] tapeWrite];
+}
+
+int
+ui_plus3_disk_write( specplus3_drive_number which )
+{
+ return [[Emulator instance] plus3DiskWrite:which];
+}
+
+int
+ui_trdos_disk_write( trdos_drive_number which )
+{
+ return [[Emulator instance] trdosDiskWrite:which];
+}
+
+ui_confirm_joystick_t
+ui_confirm_joystick( libspectrum_joystick libspectrum_type, int inputs )
+{
+ return [[Emulator instance] confirmJoystick:libspectrum_type inputs:inputs];
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|