diff --git a/src/debugger.c b/src/debugger.c index 7e87942..dbc07ea 100644 --- a/src/debugger.c +++ b/src/debugger.c @@ -3571,7 +3571,8 @@ static void cmd_exit( int argc, char** argv ) printf( "Exit.\n" ); save_before_exit = false; - please_exit = true; + // please_exit = true; + close_and_exit(); } } @@ -3581,7 +3582,8 @@ static void cmd_quit( int argc, char** argv ) printf( "Exit.\n" ); save_before_exit = true; - please_exit = true; + // please_exit = true; + close_and_exit(); } } @@ -4072,7 +4074,7 @@ int debug( void ) if ( config.verbose ) printf( "usnterrupt (SIGINT) ignored\n" ); - please_exit = true; + // please_exit = true; if ( enter_debugger & BREAKPOINT_HIT ) if ( config.verbose ) @@ -4183,7 +4185,7 @@ int debug( void ) } in_debugger = false; - } while ( !continue_flag && !please_exit ); + } while ( !continue_flag /* && !please_exit */ ); /* * adjust the hp48's timers diff --git a/src/emu_init.c b/src/emu_init.c index 7bde3f1..01e7b2c 100644 --- a/src/emu_init.c +++ b/src/emu_init.c @@ -18,7 +18,7 @@ #define RAM_SIZE_SX 0x10000 #define RAM_SIZE_GX 0x40000 -bool please_exit = false; +// bool please_exit = false; bool save_before_exit = true; bool rom_is_new = true; @@ -1001,7 +1001,7 @@ void init_display( void ) void start_emulator( void ) { - please_exit = false; + // please_exit = false; save_before_exit = true; /* If files are successfully read => return and let's go */ diff --git a/src/emulator.h b/src/emulator.h index 8c315b3..306897f 100644 --- a/src/emulator.h +++ b/src/emulator.h @@ -287,7 +287,7 @@ extern void reset_timer( int timer ); /**************/ extern hpkey_t keyboard[ NB_KEYS ]; extern int annunciators_bits[ NB_ANNUNCIATORS ]; -extern bool please_exit; +// extern bool please_exit; extern bool save_before_exit; extern void start_emulator( void ); /* used in main.c */ diff --git a/src/main.c b/src/main.c index a8a216d..7023a38 100644 --- a/src/main.c +++ b/src/main.c @@ -152,11 +152,16 @@ int main( int argc, char** argv ) if ( schedule_event-- <= 0 ) schedule(); - } while ( !please_exit && !enter_debugger ); + + /* if ( please_exit ) */ + /* fprintf( stderr, "Should exit\n" ); */ + /* else */ + /* fprintf( stderr, "Should continue\n" ); */ + } while ( /* !please_exit && */ !enter_debugger ); if ( enter_debugger ) debug(); - } while ( !please_exit ); + } while ( true /* !please_exit */ ); ui_stop(); exit_emulator(); diff --git a/src/ui.c b/src/ui.c index ad22f2d..df64c09 100644 --- a/src/ui.c +++ b/src/ui.c @@ -2124,8 +2124,6 @@ void start_UI( int argc, char** argv ) void ui_stop( void ) { - ui_init_LCD(); - switch ( config.frontend_type ) { #if defined( HAS_X11 ) case FRONTEND_X11: @@ -2151,3 +2149,11 @@ void ui_stop( void ) break; } } + +void close_and_exit( void ) +{ + ui_stop(); + exit_emulator(); + + exit( 0 ); +} diff --git a/src/ui.h b/src/ui.h index 136d31b..5009521 100644 --- a/src/ui.h +++ b/src/ui.h @@ -55,7 +55,8 @@ extern void ( *ui_refresh_LCD )( void ); /* used in: main.c */ /*******************/ extern void ui_stop( void ); - extern void start_UI( int argc, char** argv ); +extern void close_and_exit( void ); + #endif /* !_UI_H */ diff --git a/src/ui_sdl.c b/src/ui_sdl.c index a391617..4626d58 100644 --- a/src/ui_sdl.c +++ b/src/ui_sdl.c @@ -386,8 +386,9 @@ static int sdlkey_to_hpkey( SDLKey k ) return HPKEY_ALPHA; case SDLK_F7: case SDLK_F10: - please_exit = true; - break; + // please_exit = true; + close_and_exit(); + return -1; default: return -1; } @@ -1244,7 +1245,8 @@ void sdl_get_event( void ) while ( SDL_PollEvent( &event ) ) { switch ( event.type ) { case SDL_QUIT: - please_exit = true; + // please_exit = true; + close_and_exit(); break; case SDL_MOUSEBUTTONDOWN: diff --git a/src/ui_text.c b/src/ui_text.c index 1515203..5fdabcf 100644 --- a/src/ui_text.c +++ b/src/ui_text.c @@ -542,7 +542,8 @@ void text_get_event( void ) case '|': /* Shift+\ */ case KEY_SEND: /* Shift+End */ case KEY_F( 10 ): - please_exit = true; + // please_exit = true; + close_and_exit(); break; } diff --git a/src/ui_x11.c b/src/ui_x11.c index 4283746..fb89c1d 100644 --- a/src/ui_x11.c +++ b/src/ui_x11.c @@ -2051,7 +2051,8 @@ static void decode_key( XEvent* xev, KeySym sym, char* buf, int buflen ) break; case XK_F7: case XK_F10: - please_exit = true; + close_and_exit(); + // please_exit = true; break; default: break; @@ -2419,6 +2420,10 @@ void x11_get_event( void ) i = XLookupString( &xev.xkey, buf, bufs, &sym, NULL ); decode_key( &xev, sym, buf, i ); + + /* if ( please_exit ) */ + /* return; */ + first_key = 1; break; @@ -2896,8 +2901,11 @@ void x11_get_event( void ) cm = ( XClientMessageEvent* )&xev; if ( cm->message_type == wm_protocols ) { - if ( cm->data.l[ 0 ] == ( long )wm_delete_window ) - please_exit = true; + if ( cm->data.l[ 0 ] == ( long )wm_delete_window ) { + close_and_exit(); + // please_exit = true; + // return; + } if ( cm->data.l[ 0 ] == ( long )wm_save_yourself ) { int wm_argc = 0; char** wm_argv = ( char** )malloc( ( saved_argc + 5 ) * sizeof( char* ) );