From 6a358490d46e98a0ead5643f2f64f70e5dc8e4c9 Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Tue, 2 Apr 2024 16:16:29 +0200 Subject: [PATCH] add --inhibit-shutdown as a quick and crude temporary fix for #15 --- dist/x48ng.man.1 | 2 + src/emu_actions.c | 46 ++++++++++++++++++++++- src/runtime_options.c | 85 ++++++++++++++++++++++++------------------- src/runtime_options.h | 1 + 4 files changed, 96 insertions(+), 38 deletions(-) diff --git a/dist/x48ng.man.1 b/dist/x48ng.man.1 index 13d4c12..467278f 100644 --- a/dist/x48ng.man.1 +++ b/dist/x48ng.man.1 @@ -116,6 +116,8 @@ where options include (depending on compiled front-ends): \-\-gray make the UI grayscale (default: false) .br \-\-leave\-shift\-keys _not_ mapping the shift keys to let them free for numbers (default: false) +.br + \-\-inhibit\-shutdown __tentative fix for stuck-on-OFF bug__ (default: false) .SH DESCRIPTION diff --git a/src/emu_actions.c b/src/emu_actions.c index aca3824..d067c27 100644 --- a/src/emu_actions.c +++ b/src/emu_actions.c @@ -2,6 +2,7 @@ #include #include +#include "runtime_options.h" /* only for inhibit_shutdown in do_shutdown() */ #include "emulator.h" #include "emulator_inner.h" #include "romio.h" @@ -251,6 +252,49 @@ int get_identification( void ) void do_shutdown( void ) { + if ( inhibit_shutdown ) + return; + + /***************************/ + /* hpemu/src/opcodes.c:367 */ + /***************************/ + /* static void op807( byte* opc ) // SHUTDN */ + /* { */ + /* // TODO: Fix SHUTDN */ + /* if ( !cpu.in[ 0 ] && !cpu.in[ 1 ] && !cpu.in[ 3 ] ) { */ + /* cpu.shutdown = true; */ + /* } */ + /* cpu.pc += 3; */ + /* cpu.cycles += 5; */ + /* } */ + + /***********************************/ + /* saturn_bertolotti/src/cpu.c:364 */ + /***********************************/ + /* static void ExecSHUTDN( void ) */ + /* { */ + /* debug1( DEBUG_C_TRACE, CPU_I_CALLED, "SHUTDN" ); */ + + /* #ifdef CPU_SPIN_SHUTDN */ + /* /\* If the CPU_SPIN_SHUTDN symbol is defined, the CPU module implements */ + /* SHUTDN as a spin loop; the program counter is reset to the starting */ + /* nibble of the SHUTDN opcode. */ + /* *\/ */ + /* cpu_status.PC -= 3; */ + /* #endif */ + + /* /\* Set shutdown flag *\/ */ + /* cpu_status.shutdn = 1; */ + + /* #ifndef CPU_SPIN_SHUTDN */ + /* /\* If the CPU_SPIN_SHUTDN symbol is not defined, the CPU module implements */ + /* SHUTDN signalling the condition CPU_I_SHUTDN */ + /* *\/ */ + /* ChfCondition CPU_I_SHUTDN, CHF_INFO ChfEnd; */ + /* ChfSignal(); */ + /* #endif */ + /* } */ + if ( device.display_touched ) { device.display_touched = 0; ui_refresh_LCD(); @@ -478,7 +522,7 @@ void press_key( int hpkey ) keyboard[ hpkey ].pressed = 1; int code = keyboard[ hpkey ].code; - if ( code == 0x8000 ) { + if ( code == 0x8000 ) { /* HPKEY_ON */ for ( int i = 0; i < 9; i++ ) saturn.keybuf.rows[ i ] |= 0x8000; do_kbd_int(); diff --git a/src/runtime_options.c b/src/runtime_options.c index 571debf..d5430b9 100644 --- a/src/runtime_options.c +++ b/src/runtime_options.c @@ -38,6 +38,7 @@ char* port2FileName = NULL; int frontend_type = FRONTEND_TEXT; bool leave_shift_keys = false; +bool inhibit_shutdown = false; bool mono = false; bool gray = false; @@ -247,55 +248,57 @@ int parse_args( int argc, char* argv[] ) int clopt_small = -1; int clopt_tiny = -1; int clopt_leave_shift_keys = -1; + int clopt_inhibit_shutdown = -1; char* optstring = "c:hvVtsirT"; struct option long_options[] = { - {"config", required_argument, NULL, 'c' }, - { "config-dir", required_argument, NULL, 1000 }, - { "rom", required_argument, NULL, 1010 }, - { "ram", required_argument, NULL, 1011 }, - { "state", required_argument, NULL, 1012 }, - { "port1", required_argument, NULL, 1013 }, - { "port2", required_argument, NULL, 1014 }, + {"config", required_argument, NULL, 'c' }, + {"config-dir", required_argument, NULL, 1000 }, + {"rom", required_argument, NULL, 1010 }, + {"ram", required_argument, NULL, 1011 }, + {"state", required_argument, NULL, 1012 }, + {"port1", required_argument, NULL, 1013 }, + {"port2", required_argument, NULL, 1014 }, - { "serial-line", required_argument, NULL, 1015 }, + {"serial-line", required_argument, NULL, 1015 }, - { "help", no_argument, NULL, 'h' }, - { "version", no_argument, NULL, 'v' }, + {"help", no_argument, NULL, 'h' }, + {"version", no_argument, NULL, 'v' }, - { "print-config", no_argument, ( int* )&print_config, true }, - { "verbose", no_argument, &clopt_verbose, true }, - { "terminal", no_argument, &clopt_useTerminal, true }, - { "serial", no_argument, &clopt_useSerial, true }, + {"print-config", no_argument, ( int* )&print_config, true }, + {"verbose", no_argument, &clopt_verbose, true }, + {"terminal", no_argument, &clopt_useTerminal, true }, + {"serial", no_argument, &clopt_useSerial, true }, - { "reset", no_argument, ( int* )&resetOnStartup, true }, - { "throttle", no_argument, &clopt_throttle, true }, + {"reset", no_argument, ( int* )&resetOnStartup, true }, + {"throttle", no_argument, &clopt_throttle, true }, - { "debug", no_argument, &clopt_useDebugger, true }, + {"debug", no_argument, &clopt_useDebugger, true }, - { "sdl", no_argument, &clopt_frontend_type, FRONTEND_SDL}, - { "no-chrome", no_argument, &clopt_hide_chrome, true }, - { "fullscreen", no_argument, &clopt_show_ui_fullscreen, true }, + {"sdl", no_argument, &clopt_frontend_type, FRONTEND_SDL}, + {"no-chrome", no_argument, &clopt_hide_chrome, true }, + {"fullscreen", no_argument, &clopt_show_ui_fullscreen, true }, - { "x11", no_argument, &clopt_frontend_type, FRONTEND_X11}, - { "netbook", no_argument, &clopt_netbook, true }, - { "visual", required_argument, NULL, 8110 }, - { "small-font", required_argument, NULL, 8111 }, - { "medium-font", required_argument, NULL, 8112 }, - { "large-font", required_argument, NULL, 8113 }, - { "connection-font", required_argument, NULL, 8114 }, + {"x11", no_argument, &clopt_frontend_type, FRONTEND_X11}, + {"netbook", no_argument, &clopt_netbook, true }, + {"visual", required_argument, NULL, 8110 }, + {"small-font", required_argument, NULL, 8111 }, + {"medium-font", required_argument, NULL, 8112 }, + {"large-font", required_argument, NULL, 8113 }, + {"connection-font", required_argument, NULL, 8114 }, - { "tui", no_argument, NULL, 9100 }, - { "tui-small", no_argument, NULL, 9110 }, - { "tui-tiny", no_argument, NULL, 9120 }, - { "small", no_argument, NULL, 9109 }, /* DEPRECATED */ - { "tiny", no_argument, NULL, 9119 }, /* DEPRECATED */ + {"tui", no_argument, NULL, 9100 }, + {"tui-small", no_argument, NULL, 9110 }, + {"tui-tiny", no_argument, NULL, 9120 }, + {"small", no_argument, NULL, 9109 }, /* DEPRECATED */ + {"tiny", no_argument, NULL, 9119 }, /* DEPRECATED */ - { "mono", no_argument, &clopt_mono, true }, - { "gray", no_argument, &clopt_gray, true }, - { "leave-shift-keys", no_argument, &clopt_leave_shift_keys, true }, + {"mono", no_argument, &clopt_mono, true }, + {"gray", no_argument, &clopt_gray, true }, + {"leave-shift-keys", no_argument, &clopt_leave_shift_keys, true }, + {"inhibit-shutdown", no_argument, &clopt_inhibit_shutdown, true }, - { 0, 0, 0, 0 } + {0, 0, 0, 0 } }; char* help_text = "usage: %s [options]\n" @@ -355,7 +358,9 @@ int parse_args( int argc, char* argv[] ) "false)\n" " --gray make the UI grayscale (default: " "false)\n" - " --leave-shift-keys _not_ mapping the shift keys to let them free for numbers (default: " + " --leave-shift-keys _not_ mapping the shift keys to let them free for numbers (default: " + "false)\n" + " --inhibit-shutdown __tentative fix for stuck-on-OFF bug__ (default: " "false)\n"; while ( c != EOF ) { c = getopt_long( argc, argv, optstring, long_options, &option_index ); @@ -564,6 +569,9 @@ int parse_args( int argc, char* argv[] ) lua_getglobal( config_lua_values, "leave_shift_keys" ); leave_shift_keys = lua_toboolean( config_lua_values, -1 ); + lua_getglobal( config_lua_values, "inhibit_shutdown" ); + inhibit_shutdown = lua_toboolean( config_lua_values, -1 ); + lua_getglobal( config_lua_values, "x11_visual" ); x11_visual = ( char* )luaL_optstring( config_lua_values, -1, "default" ); @@ -635,6 +643,8 @@ int parse_args( int argc, char* argv[] ) tiny = clopt_tiny; if ( clopt_leave_shift_keys != -1 ) leave_shift_keys = clopt_leave_shift_keys; + if ( clopt_inhibit_shutdown != -1 ) + inhibit_shutdown = clopt_inhibit_shutdown; /* After getting configs and params */ /* normalize config_dir again in case it's been modified */ @@ -690,6 +700,7 @@ int parse_args( int argc, char* argv[] ) fprintf( stdout, "mono = %s\n", mono ? "true" : "false" ); fprintf( stdout, "gray = %s\n", gray ? "true" : "false" ); fprintf( stdout, "leave_shift_keys = %s\n", leave_shift_keys ? "true" : "false" ); + fprintf( stdout, "inhibit_shutdown = %s\n", inhibit_shutdown ? "true" : "false" ); fprintf( stdout, "\n" ); fprintf( stdout, "x11_visual = \"%s\"\n", x11_visual ); fprintf( stdout, "netbook = %s\n", netbook ? "true" : "false" ); diff --git a/src/runtime_options.h b/src/runtime_options.h index 0f2ca1a..05c41bf 100644 --- a/src/runtime_options.h +++ b/src/runtime_options.h @@ -20,6 +20,7 @@ extern int frontend_type; extern char* serialLine; extern bool leave_shift_keys; +extern bool inhibit_shutdown; extern bool mono; extern bool gray;