int ui_mdr_write( int which, int saveas ) { int err; char *filename = NULL, title[80]; fuse_emulation_pause(); snprintf( title, 80, "Fuse - Write Microdrive Cartridge %i", which + 1 ); if( saveas ) { filename = ui_get_save_filename( title ); if( !filename ) { fuse_emulation_unpause(); return 1; } } err = if1_mdr_write( which, filename ); if( saveas ) libspectrum_free( filename ); fuse_emulation_unpause(); return err; }
void menu_file_loadbinarydata( int action ) { /* FIXME: a way to associate a long type with a window is via SetWindowLong with GWL_USERDATA parameter - review past code and implement */ struct binary_info info; int error; fuse_emulation_pause(); info.dialog_title = TEXT( "Fuse - Load Binary Data" ); info.filename = ui_get_open_filename( info.dialog_title ); if( !info.filename ) { fuse_emulation_unpause(); return; } error = utils_read_file( info.filename, &info.file ); if( error ) { free( info.filename ); fuse_emulation_unpause(); return; } info.on_change_filename = &change_load_filename; info.on_execute = &load_data; /* Information display */ DialogBoxParam( fuse_hInstance, MAKEINTRESOURCE( IDD_BINARY ), fuse_hWnd, binarydata_proc, ( LPARAM ) &info ); free( info.filename ); utils_close_file( &info.file ); fuse_emulation_unpause(); }
static void gtkui_drag_data_received( GtkWidget *widget, GdkDragContext *drag_context, gint x, gint y, GtkSelectionData *data, guint info, guint time ) { static char uri_prefix[] = "file://"; char *filename, *p, *data_end; if ( data && data->length > sizeof( uri_prefix ) ) { filename = ( char * )( data->data + sizeof( uri_prefix ) - 1 ); data_end = ( char * )( data->data + data->length ); p = filename; do { if ( *p == '\r' || *p == '\n' ) { *p = '\0'; break; } } while ( p++ != data_end ); if ( ( filename = g_uri_unescape_string( filename, NULL ) ) != NULL ) { fuse_emulation_pause(); utils_open_file( filename, settings_current.auto_load, NULL ); free( filename ); display_refresh_all(); fuse_emulation_unpause(); } } gtk_drag_finish(drag_context, FALSE, FALSE, time); }
ui_confirm_save_t ui_confirm_save_specific( const char *message ) { ui_confirm_save_t confirm; int result; if( !settings_current.confirm_actions ) return UI_CONFIRM_SAVE_DONTSAVE; fuse_emulation_pause(); confirm = UI_CONFIRM_SAVE_CANCEL; result = MessageBox( fuse_hWnd, message, "Fuse - Confirm", MB_YESNOCANCEL | MB_ICONQUESTION ); switch( result ) { case IDYES: confirm = UI_CONFIRM_SAVE_SAVE; break; case IDNO: confirm = UI_CONFIRM_SAVE_DONTSAVE; break; } fuse_emulation_unpause(); return confirm; }
/* Handler for the main window's WM_SIZE notification */ static int win32ui_window_resize( HWND hWnd, WPARAM wParam, LPARAM lParam ) { if( wParam == SIZE_MINIMIZED ) { if( !size_paused ) { size_paused = 1; fuse_emulation_pause(); /* Process UI events until the window is restored */ win32ui_process_messages( 0 ); } } else { win32display_drawing_area_resize( LOWORD( lParam ), HIWORD( lParam ), 1 ); /* Resize statusbar and inner parts */ SendMessage( fuse_hStatusWindow, WM_SIZE, wParam, lParam ); win32statusbar_resize( hWnd, wParam, lParam ); if( size_paused ) { timer_estimate_reset(); PostMessage( fuse_hWnd, WM_USER_EXIT_PROCESS_MESSAGES, 0, 0 ); size_paused = 0; fuse_emulation_unpause(); } } return 0; }
static void handle_drop( HDROP hDrop ) { size_t bufsize; char *namebuf; /* Check that only one file was dropped */ if( DragQueryFile( hDrop, ~0UL, NULL, 0 ) == 1) { bufsize = DragQueryFile( hDrop, 0, NULL, 0 ) + 1; if( ( namebuf = malloc( bufsize ) ) ) { DragQueryFile( hDrop, 0, namebuf, bufsize ); fuse_emulation_pause(); utils_open_file( namebuf, tape_can_autoload(), NULL ); free( namebuf ); display_refresh_all(); fuse_emulation_unpause(); } } DragFinish( hDrop ); }
void menu_help_about( int action ) { /* Firstly, stop emulation */ fuse_emulation_pause(); if( !IsWindow( fuse_hABOWnd ) ) { fuse_hABOWnd = CreateDialog( fuse_hInstance, MAKEINTRESOURCE( IDD_ABOUT ), fuse_hWnd, dialog_proc ); if( fuse_hABOWnd == NULL ) { fuse_emulation_unpause(); return; } } ShowWindow( fuse_hABOWnd, SW_SHOW ); /* Carry on with emulation */ fuse_emulation_unpause(); }
int ui_event(void) { XEvent event; XFlush( display ); while( XEventsQueued( display, QueuedAlready ) ) { XNextEvent( display, &event ); switch(event.type) { case ConfigureNotify: xdisplay_configure_notify(event.xconfigure.width, event.xconfigure.height); break; case Expose: xdisplay_area( event.xexpose.x, event.xexpose.y, event.xexpose.width, event.xexpose.height ); break; case ButtonPress: ui_mouse_button( event.xbutton.button, 1 ); break; case ButtonRelease: ui_mouse_button( event.xbutton.button, 0 ); break; case MotionNotify: if( ui_mouse_grabbed ) { ui_mouse_motion( event.xmotion.x - 128, event.xmotion.y - 128 ); if( event.xmotion.x != 128 || event.xmotion.y != 128 ) XWarpPointer( display, None, xui_mainWindow, 0, 0, 0, 0, 128, 128 ); } break; case FocusOut: keyboard_release_all(); ui_mouse_suspend(); break; case FocusIn: ui_mouse_resume(); break; case KeyPress: xkeyboard_keypress(&(event.xkey)); break; case KeyRelease: xkeyboard_keyrelease(&(event.xkey)); break; case ClientMessage: if( event.xclient.format == 32 && event.xclient.data.l[0] == delete_window_atom ) { fuse_emulation_pause(); menu_file_exit(0); fuse_emulation_unpause(); } break; } } return 0; }
int ui_tape_write( void ) { char *filename; fuse_emulation_pause(); filename = ui_get_save_filename( "Fuse - Write Tape" ); if( !filename ) { fuse_emulation_unpause(); return 1; } tape_write( filename ); libspectrum_free( filename ); fuse_emulation_unpause(); return 0; }
int uidisplay_hotswap_gfx_mode( void ) { fuse_emulation_pause(); /* Setup the new GFX mode */ gtkdisplay_load_gfx_mode(); fuse_emulation_unpause(); return 0; }
void menu_machine_pokememory( int action GCC_UNUSED ) { fuse_emulation_pause(); pokemem_autoload_pokfile(); DialogBox( fuse_hInstance, MAKEINTRESOURCE( IDD_POKEMEM ), fuse_hWnd, (DLGPROC) win32ui_pokemem_proc ); fuse_emulation_unpause(); }
void ui_pokemem_selector( const char *filename ) { fuse_emulation_pause(); pokemem_read_from_file( filename ); DialogBox( fuse_hInstance, MAKEINTRESOURCE( IDD_POKEMEM ), fuse_hWnd, (DLGPROC) win32ui_pokemem_proc ); fuse_emulation_unpause(); }
void menu_options_joysticks_select( int action ) { struct joystick_info info; fuse_emulation_pause(); setup_info( &info, action ); DialogBoxParam( fuse_hInstance, MAKEINTRESOURCE( IDD_JOYSTICKS ), fuse_hWnd, dialog_proc, ( LPARAM ) &info ); fuse_emulation_unpause(); }
void menu_file_savebinarydata( int action ) { struct binary_info info; fuse_emulation_pause(); info.dialog_title = TEXT( "Fuse - Save Binary Data" ); info.filename = ui_get_save_filename( info.dialog_title ); if( !info.filename ) { fuse_emulation_unpause(); return; } info.file.length = -1; /* let the dialog know to leave length box blank */ info.on_change_filename = &change_save_filename; info.on_execute = &save_data; /* Information display */ DialogBoxParam( fuse_hInstance, MAKEINTRESOURCE( IDD_BINARY ), fuse_hWnd, binarydata_proc, ( LPARAM ) &info ); free( info.filename ); fuse_emulation_unpause(); }
int ui_get_rollback_point( GSList *points ) { int result; fuse_emulation_pause(); current_block = -1; result = DialogBoxParam( fuse_hInstance, MAKEINTRESOURCE( IDD_ROLLBACK ), fuse_hWnd, dialog_proc, ( LPARAM ) points ); fuse_emulation_unpause(); return result; }
int ui_error_specific( ui_error_level severity, const char *message ) { widget_error_t error_info; /* Can't output widgets if we don't have a display yet */ if( !display_ui_initialised ) return 0; error_info.severity = severity; error_info.message = message; fuse_emulation_pause(); widget_do_error( &error_info ); fuse_emulation_unpause(); return 0; }
ui_confirm_joystick_t ui_confirm_joystick( libspectrum_joystick libspectrum_type, int inputs ) { win32ui_select_info items; TCHAR title[ 80 ]; int i, selection; int selected_joystick; if( !settings_current.joy_prompt ) return UI_CONFIRM_JOYSTICK_NONE; /* Some space to store the radio options in */ items.labels = malloc( JOYSTICK_CONN_COUNT * sizeof( char * ) ); if( !items.labels ) { ui_error( UI_ERROR_ERROR, "out of memory at %s:%d", __FILE__, __LINE__ ); return UI_CONFIRM_JOYSTICK_NONE; } /* Stop emulation */ fuse_emulation_pause(); /* Populate win32ui_select_info */ /* FIXME: libspectrum_joystick_name is not unicode compliant */ _sntprintf( title, ARRAY_SIZE( title ), _T( "Fuse - Configure %s Joystick" ), libspectrum_joystick_name( libspectrum_type ) ); items.dialog_title = title; items.length = JOYSTICK_CONN_COUNT; for( i=0; i<JOYSTICK_CONN_COUNT; i++ ) { items.labels[i] = joystick_connection[ i ]; } items.selected = UI_CONFIRM_JOYSTICK_NONE; /* start the joystick select dialog box */ selection = selector_dialog( &items ); selected_joystick = ( selection >= 0 )? selection : UI_CONFIRM_JOYSTICK_NONE; free( items.labels ); /* And then carry on with emulation again */ fuse_emulation_unpause(); return selected_joystick; }
int menu_select_roms_with_title( const char *title, size_t start, size_t n ) { struct callback_info info; /* Firstly, stop emulation */ fuse_emulation_pause(); _sntprintf( info.title, 256, "Fuse - Select ROMs - %s", title ); info.start = start; info.n = n; DialogBoxParam( fuse_hInstance, MAKEINTRESOURCE( IDD_ROMS ), fuse_hWnd, ( DLGPROC ) roms_proc, ( LPARAM ) &info ); /* And then carry on with emulation again */ fuse_emulation_unpause(); return 0; }
/* Called by the menu when Machine/Select selected */ void menu_machine_select( int action ) { /* FIXME: choosing spectrum SE crashes Fuse sound_frame () at sound.c:477 "ay_change[f].ofs = ( ay_change[f].tstates * sfreq ) / cpufreq;" */ /* FIXME: choosing some Timexes crashes (win32) fuse as well */ int selected_machine; win32ui_select_info items; int i; /* Stop emulation */ fuse_emulation_pause(); /* Populate win32ui_select_info */ items.dialog_title = TEXT( "Fuse - Select Machine" ); items.labels = malloc( machine_count * sizeof( char * ) ); items.length = machine_count; for( i=0; i<machine_count; i++ ) { items.labels[i] = libspectrum_machine_name( machine_types[i]->machine ); if( machine_current == machine_types[i] ) { items.selected = i; } } /* start the machine select dialog box */ selected_machine = selector_dialog( &items ); if( selected_machine >= 0 && machine_types[ selected_machine ] != machine_current ) { machine_select( machine_types[ selected_machine ]->machine ); } free( items.labels ); /* Resume emulation */ fuse_emulation_unpause(); }
/* Machine/Pause */ void menu_machine_pause( int action ) { if( paused ) { paused = 0; ui_statusbar_update( UI_STATUSBAR_ITEM_PAUSED, UI_STATUSBAR_STATE_INACTIVE ); timer_estimate_reset(); PostMessage( fuse_hWnd, WM_USER_EXIT_PROCESS_MESSAGES, 0, 0 ); /* Resume emulation */ fuse_emulation_unpause(); } else { /* Stop emulation */ fuse_emulation_pause(); paused = 1; ui_statusbar_update( UI_STATUSBAR_ITEM_PAUSED, UI_STATUSBAR_STATE_ACTIVE ); win32ui_process_messages( 0 ); } }
int win32ui_confirm( const char *string ) { int confirm; int result; /* Return value isn't an error code, but signifies whether to undertake the action */ if( !settings_current.confirm_actions ) return 1; fuse_emulation_pause(); confirm = 0; result = MessageBox( fuse_hWnd, string, "Fuse - Confirm", MB_OKCANCEL | MB_ICONQUESTION ); if( result == IDOK ) confirm = 1; fuse_emulation_unpause(); return confirm; }
static int do_joystick( const input_event_joystick_t *joystick_event, int press ) { int which; #ifdef USE_WIDGET if( widget_level >= 0 ) { if( press ) widget_keyhandler( joystick_event->button ); return 0; } switch( joystick_event->button ) { case INPUT_JOYSTICK_FIRE_2: fuse_emulation_pause(); widget_do( WIDGET_TYPE_MENU, &widget_menu ); fuse_emulation_unpause(); break; default: break; /* Remove gcc warning */ } #endif /* #ifdef USE_WIDGET */ which = joystick_event->which; if( joystick_event->button < INPUT_JOYSTICK_FIRE_1 ) { joystick_button button; switch( joystick_event->button ) { case INPUT_JOYSTICK_UP : button = JOYSTICK_BUTTON_UP; break; case INPUT_JOYSTICK_DOWN : button = JOYSTICK_BUTTON_DOWN; break; case INPUT_JOYSTICK_LEFT : button = JOYSTICK_BUTTON_LEFT; break; case INPUT_JOYSTICK_RIGHT: button = JOYSTICK_BUTTON_RIGHT; break; default: ui_error( UI_ERROR_ERROR, "do_joystick: unknown button %d", joystick_event->button ); fuse_abort(); } joystick_press( which, button, press ); } else { keyboard_key_name key; key = get_fire_button_key( which, joystick_event->button ); if( key == KEYBOARD_JOYSTICK_FIRE ) { joystick_press( which, JOYSTICK_BUTTON_FIRE, press ); } else { if( press ) { keyboard_press( key ); } else { keyboard_release( key ); } } } return 0; }
static int keypress( const input_event_key_t *event ) { int swallow; const keyboard_spectrum_keys_t *ptr; #ifdef USE_WIDGET if( widget_level >= 0 ) { widget_keyhandler( event->native_key ); return 0; } #endif /* #ifdef USE_WIDGET */ /* Escape => ask UI to end mouse grab, return if grab ended */ if( event->native_key == INPUT_KEY_Escape && ui_mouse_grabbed ) { ui_mouse_grabbed = ui_mouse_release( 0 ); if( !ui_mouse_grabbed ) return 0; } swallow = 0; /* Joystick emulation via keyboard keys */ if ( event->spectrum_key == settings_current.joystick_keyboard_up ) { swallow = joystick_press( JOYSTICK_KEYBOARD, JOYSTICK_BUTTON_UP , 1 ); } else if( event->spectrum_key == settings_current.joystick_keyboard_down ) { swallow = joystick_press( JOYSTICK_KEYBOARD, JOYSTICK_BUTTON_DOWN , 1 ); } else if( event->spectrum_key == settings_current.joystick_keyboard_left ) { swallow = joystick_press( JOYSTICK_KEYBOARD, JOYSTICK_BUTTON_LEFT , 1 ); } else if( event->spectrum_key == settings_current.joystick_keyboard_right ) { swallow = joystick_press( JOYSTICK_KEYBOARD, JOYSTICK_BUTTON_RIGHT, 1 ); } else if( event->spectrum_key == settings_current.joystick_keyboard_fire ) { swallow = joystick_press( JOYSTICK_KEYBOARD, JOYSTICK_BUTTON_FIRE , 1 ); } if( swallow ) return 0; ptr = keyboard_get_spectrum_keys( event->spectrum_key ); if( ptr ) { keyboard_press( ptr->key1 ); keyboard_press( ptr->key2 ); } #ifdef USE_WIDGET switch( event->native_key ) { case INPUT_KEY_F1: fuse_emulation_pause(); widget_do( WIDGET_TYPE_MENU, &widget_menu ); fuse_emulation_unpause(); break; case INPUT_KEY_F2: fuse_emulation_pause(); menu_file_savesnapshot( 0 ); fuse_emulation_unpause(); break; case INPUT_KEY_F3: fuse_emulation_pause(); menu_file_open( 0 ); fuse_emulation_unpause(); break; case INPUT_KEY_F4: fuse_emulation_pause(); menu_options_general( 0 ); fuse_emulation_unpause(); break; case INPUT_KEY_F5: fuse_emulation_pause(); menu_machine_reset( 0 ); fuse_emulation_unpause(); break; case INPUT_KEY_F6: fuse_emulation_pause(); menu_media_tape_write( 0 ); fuse_emulation_unpause(); break; case INPUT_KEY_F7: fuse_emulation_pause(); menu_media_tape_open( 0 ); fuse_emulation_unpause(); break; case INPUT_KEY_F8: menu_media_tape_play( 0 ); break; case INPUT_KEY_F9: fuse_emulation_pause(); menu_machine_select( 0 ); fuse_emulation_unpause(); break; case INPUT_KEY_F10: fuse_emulation_pause(); menu_file_exit( 0 ); fuse_emulation_unpause(); break; default: break; /* Remove gcc warning */ } #endif /* #ifdef USE_WIDGET */ return 0; }
int ui_event( void ) { SDL_Event event; while ( SDL_PollEvent( &event ) ) { switch ( event.type ) { case SDL_KEYDOWN: sdlkeyboard_keypress( &(event.key) ); break; case SDL_KEYUP: sdlkeyboard_keyrelease( &(event.key) ); break; case SDL_MOUSEBUTTONDOWN: ui_mouse_button( event.button.button, 1 ); break; case SDL_MOUSEBUTTONUP: ui_mouse_button( event.button.button, 0 ); break; case SDL_MOUSEMOTION: if( ui_mouse_grabbed ) { ui_mouse_motion( event.motion.x - 128, event.motion.y - 128 ); if( event.motion.x != 128 || event.motion.y != 128 ) SDL_WarpMouse( 128, 128 ); } break; #if defined USE_JOYSTICK && !defined HAVE_JSW_H case SDL_JOYBUTTONDOWN: sdljoystick_buttonpress( &(event.jbutton) ); break; case SDL_JOYBUTTONUP: sdljoystick_buttonrelease( &(event.jbutton) ); break; case SDL_JOYAXISMOTION: sdljoystick_axismove( &(event.jaxis) ); break; #endif /* if defined USE_JOYSTICK && !defined HAVE_JSW_H */ case SDL_QUIT: fuse_emulation_pause(); menu_file_exit(0); fuse_emulation_unpause(); break; case SDL_VIDEOEXPOSE: display_refresh_all(); break; case SDL_ACTIVEEVENT: if( event.active.state & SDL_APPINPUTFOCUS ) { if( event.active.gain ) ui_mouse_resume(); else ui_mouse_suspend(); } break; default: break; } } return 0; }
static LRESULT WINAPI fuse_window_proc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) { switch( msg ) { #if defined USE_JOYSTICK && !defined HAVE_JSW_H case WM_CREATE: if( joysticks_supported > 0 ) if( joySetCapture( hWnd, JOYSTICKID1, 0, FALSE ) ) ui_error( UI_ERROR_ERROR, "Couldn't start capture for joystick 1" ); if( joysticks_supported > 1 ) if( joySetCapture( hWnd, JOYSTICKID2, 0, FALSE ) ) ui_error( UI_ERROR_ERROR, "Couldn't start capture for joystick 2" ); break; #endif /* if defined USE_JOYSTICK && !defined HAVE_JSW_H */ case WM_COMMAND: if( ! handle_menu( LOWORD( wParam ), hWnd ) ) return 0; break; case WM_DROPFILES: handle_drop( ( HDROP )wParam ); return 0; case WM_CLOSE: menu_file_exit( 0 ); return 0; case WM_KEYDOWN: win32keyboard_keypress( wParam, lParam ); return 0; case WM_KEYUP: win32keyboard_keyrelease( wParam, lParam ); return 0; case WM_PAINT: if( ! win32ui_window_paint( hWnd, wParam, lParam ) ) return 0; break; case WM_SIZING: if( win32ui_window_resizing( hWnd, wParam, lParam ) ) return TRUE; break; case WM_SIZE: if( ! win32ui_window_resize( hWnd, wParam, lParam ) ) return 0; break; case WM_DRAWITEM: if( wParam == ID_STATUSBAR ) { win32statusbar_redraw( hWnd, lParam ); return TRUE; } break; case WM_DESTROY: fuse_exiting = 1; PostQuitMessage( 0 ); /* Stop the paused state to allow us to exit (occurs from main emulation loop) */ if( paused ) menu_machine_pause( 0 ); return 0; case WM_ENTERMENULOOP: case WM_ENTERSIZEMOVE: { fuse_emulation_pause(); return 0; } case WM_EXITMENULOOP: case WM_EXITSIZEMOVE: { fuse_emulation_unpause(); return 0; } case WM_LBUTTONUP: win32mouse_button( 1, 0 ); return 0; case WM_LBUTTONDOWN: win32mouse_button( 1, 1 ); return 0; case WM_MBUTTONUP: win32mouse_button( 2, 0 ); return 0; case WM_MBUTTONDOWN: win32mouse_button( 2, 1 ); return 0; case WM_RBUTTONUP: win32mouse_button( 3, 0 ); return 0; case WM_RBUTTONDOWN: win32mouse_button( 3, 1 ); return 0; case WM_MOUSEMOVE: win32mouse_position( lParam ); return 0; case WM_SETCURSOR: /* prevent the cursor from being redrawn if fuse has grabbed the mouse */ if( ui_mouse_grabbed ) return TRUE; else return( DefWindowProc( hWnd, msg, wParam, lParam ) ); case WM_ACTIVATE: if( ( LOWORD( wParam ) == WA_ACTIVE ) || ( LOWORD( wParam ) == WA_CLICKACTIVE ) ) win32ui_gain_focus( hWnd, wParam, lParam ); else if( LOWORD( wParam ) == WA_INACTIVE ) win32ui_lose_focus( hWnd, wParam, lParam ); /* We'll call DefWindowProc to get keyboard focus when debugger window is open and inactive */ break; case WM_USER_EXIT_PROCESS_MESSAGES: /* Odd case when message loop is overridden by a modal dialog. This should not be caught here, so we delay this notification */ exit_process_messages++; return 0; case WM_ERASEBKGND: /* Improves speed and avoid flickering when main window is invalidated by another window */ return TRUE; #if defined USE_JOYSTICK && !defined HAVE_JSW_H case MM_JOY1BUTTONDOWN: win32joystick_buttonevent( 0, 1, wParam ); break; case MM_JOY1BUTTONUP: win32joystick_buttonevent( 0, 0, wParam ); break; case MM_JOY2BUTTONDOWN: win32joystick_buttonevent( 1, 1, wParam ); break; case MM_JOY2BUTTONUP: win32joystick_buttonevent( 1, 0, wParam ); break; case MM_JOY1MOVE: win32joystick_move( 0, LOWORD( lParam ), HIWORD( lParam ) ); break; case MM_JOY2MOVE: win32joystick_move( 1, LOWORD( lParam ), HIWORD( lParam ) ); break; #endif /* if defined USE_JOYSTICK && !defined HAVE_JSW_H */ } return( DefWindowProc( hWnd, msg, wParam, lParam ) ); }