diff --git a/README.md b/README.md index 70de8554..1d27bc94 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,7 @@ All Simulator updates on Open SIMH will be present in this repository, and any c - TAPE and SCSI libraries have been extended to fully support partial record reads of fixed sized records which may contain multiple records in recorded data. Images of this type are common for QIC tape archives generally available on bitsavers and elsewhere. Attach time checking on simulated QIC tape devices reports possible problems that may occur. - Github CI Actions builds of all simulators for Linux, macOS and Windows platforms. - All the available simulator defined environment variables are documented in the help and sim_doc document file. +- SET CONSOLE TELNET=CONNECT will start a telnet session to the simulator console in a separate window. #### Changes to the PDP-11 and VAX simulators also not in the Open SIMH repo diff --git a/doc/simh_doc.doc b/doc/simh_doc.doc index 8bf94fc5..b64e0392 100644 Binary files a/doc/simh_doc.doc and b/doc/simh_doc.doc differ diff --git a/frontpanel/FrontPanelTest.c b/frontpanel/FrontPanelTest.c index 846e1470..2970fa39 100644 --- a/frontpanel/FrontPanelTest.c +++ b/frontpanel/FrontPanelTest.c @@ -229,15 +229,8 @@ if ((f = fopen (sim_config, "w"))) { fprintf (f, "set cpu 64\n"); fprintf (f, "set console telnet=buffered\n"); fprintf (f, "set console -u telnet=1927\n"); - /* Start a terminal emulator for the console port */ -#if defined(_WIN32) - fprintf (f, "set env PATH=%%PATH%%;%%ProgramFiles%%\\PuTTY;%%ProgramFiles(x86)%%\\PuTTY\n"); - fprintf (f, "! start PuTTY telnet://localhost:1927\n"); -#elif defined(__linux) || defined(__linux__) - fprintf (f, "! nohup xterm -e 'telnet localhost 1927' &\n"); -#elif defined(__APPLE__) - fprintf (f, "! osascript -e 'tell application \"Terminal\" to do script \"telnet localhost 1927; exit\"'\n"); -#endif + fprintf (f, "# Start a terminal emulator for the console port\n"); + fprintf (f, "set console telnet=connect\n"); fclose (f); } diff --git a/scp.c b/scp.c index 11af38f8..07a669e1 100644 --- a/scp.c +++ b/scp.c @@ -1350,6 +1350,8 @@ static const char simh_help1[] = "+SET CONSOLE TELNET=UNBUFFERED\n" "++++++++ disables console telnet buffering\n" "+SET CONSOLE NOTELNET disable console telnet\n" + "+SET CONSOLE TELNET=CONNECT open a window running a telnet session\n" + "++++++++ to the simulator console\n" "+SET CONSOLE SERIAL=serialport[;config]\n" "++++++++ specify console serial port and optionally\n" "++++++++ the port config (i.e. ;9600-8n1)\n" @@ -2821,7 +2823,6 @@ static SHTAB show_unit_tab[] = { #if defined(_WIN32) || defined(__hpux) -static int setenv(const char *envname, const char *envval, int overwrite) { char *envstr = (char *)malloc(strlen(envname)+strlen(envval)+2); diff --git a/sim_console.c b/sim_console.c index c3ace0ba..95a7e8df 100644 --- a/sim_console.c +++ b/sim_console.c @@ -142,6 +142,10 @@ #define MIN(a,b) (((a) <= (b)) ? (a) : (b)) #endif +#if defined(_WIN32) || defined(__hpux) +int setenv(const char *envname, const char *envval, int overwrite); +#endif + /* Forward Declaraations of Platform specific routines */ static t_stat sim_os_poll_kbd (void); @@ -152,6 +156,7 @@ static t_stat sim_os_ttrun (void); static t_stat sim_os_ttcmd (void); static t_stat sim_os_ttclose (void); static t_bool sim_os_fd_isatty (int fd); +static t_stat sim_os_connect_telnet (int port); static t_stat sim_set_rem_telnet (int32 flag, CONST char *cptr); static t_stat sim_set_rem_bufsize (int32 flag, CONST char *cptr); @@ -373,6 +378,7 @@ static CTAB set_con_telnet_tab[] = { { "BUFFERED", &sim_set_cons_buff, 0 }, { "NOBUFFERED", &sim_set_cons_unbuff, 0 }, { "UNBUFFERED", &sim_set_cons_unbuff, 0 }, + { "CONNECT", &sim_set_cons_connect, 0 }, { NULL, NULL, 0 } }; @@ -2604,6 +2610,16 @@ else return SCPE_OK; } +/* Start telnet session/window to console */ + +t_stat sim_set_cons_connect (int32 flg, CONST char *cptr) +{ +if (sim_con_tmxr.port == NULL) + return sim_messagef (SCPE_ARG, "Console not listening for telnet connections\n"); +return sim_os_connect_telnet (atoi (sim_con_tmxr.port)); +} + + /* Set console Debug Mode */ t_stat sim_set_cons_debug (int32 flg, CONST char *cptr) @@ -3464,6 +3480,12 @@ if ((status != SS$_NORMAL) || (iosb.status != SS$_NORMAL)) return SCPE_OK; } +static t_stat sim_os_connect_telnet (int port) +{ +return SCPE_NOFNC; +} + + /* Win32 routines */ #elif defined (_WIN32) @@ -3734,6 +3756,30 @@ if (c != 0177) { return SCPE_OK; } +static t_stat sim_os_connect_telnet (int port) +{ +char gbuf[CBUFSIZE]; +const char *program = sim_get_tool_path ("PuTTY"); + +if (program[0] != '\0') { + snprintf (gbuf, sizeof (gbuf), "start PuTTY telnet://localhost:%d", port); + return spawn_cmd (0, gbuf); + } +snprintf (gbuf, sizeof (gbuf), "%s;%s\\PuTTY;%s\\PuTTY", getenv ("PATH"), getenv ("ProgramFiles"), getenv ("ProgramFiles(x86)")); +setenv("PATH", gbuf, 1); +program = sim_get_tool_path ("PuTTY"); +if (program[0] != '\0') { + snprintf (gbuf, sizeof (gbuf), "start PuTTY telnet://localhost:%d", port); + return spawn_cmd (0, gbuf); + } +program = sim_get_tool_path ("telnet"); +if (program[0] != '\0') { + snprintf (gbuf, sizeof (gbuf), "start telnet localhost:%d", port); + return spawn_cmd (0, gbuf); + } +return sim_messagef (SCPE_NOFNC, "Can't find a telnet program to connect to the console in a window\n"); +} + /* OS/2 routines, from Bruce Ray and Holger Veit */ #elif defined (__OS2__) @@ -4010,6 +4056,12 @@ if (c != 0177) { return SCPE_OK; } +static t_stat sim_os_connect_telnet (int port) +{ +return SCPE_NOFNC; +} + + /* BSD UNIX routines */ #elif defined (BSDTTY) @@ -4162,6 +4214,11 @@ write (1, &c, 1); return SCPE_OK; } +static t_stat sim_os_connect_telnet (int port) +{ +return SCPE_NOFNC; +} + /* POSIX UNIX routines, from Leendert Van Doorn */ #else @@ -4336,6 +4393,38 @@ if (write (1, &c, 1)) {}; return SCPE_OK; } +static t_stat sim_os_connect_telnet (int port) +{ +char gbuf[CBUFSIZE]; +const char *program = sim_get_tool_path ("osascript"); + +if (program[0] != '\0') { + snprintf (gbuf, sizeof (gbuf), "osascript -e 'tell application \"Terminal\" to do script \"telnet localhost %d; exit\"'", port); + return spawn_cmd (0, gbuf); + } +program = sim_get_tool_path ("putty"); +if (program[0] != '\0') { + snprintf (gbuf, sizeof (gbuf), "nohup putty telnet://localhost:%d' 2>/dev/null&", port); + return spawn_cmd (0, gbuf); + } +program = sim_get_tool_path ("gnome-terminal"); +if (program[0] != '\0') { + snprintf (gbuf, sizeof (gbuf), "nohup gnome-terminal -- telnet localhost %d' 2>/dev/null&", port); + return spawn_cmd (0, gbuf); + } +program = sim_get_tool_path ("uxterm"); +if (program[0] != '\0') { + snprintf (gbuf, sizeof (gbuf), "nohup uxterm -e 'telnet localhost %d' 2>/dev/null&", port); + return spawn_cmd (0, gbuf); + } +program = sim_get_tool_path ("xterm"); +if (program[0] != '\0') { + snprintf (gbuf, sizeof (gbuf), "nohup xterm -e 'telnet localhost %d' 2>/dev/null&", port); + return spawn_cmd (0, gbuf); + } +return sim_messagef (SCPE_NOFNC, "Can't find a telnet program to connect to the console in a window\n"); +} + #endif /* Decode a string. diff --git a/sim_console.h b/sim_console.h index b73348ee..e044bf35 100644 --- a/sim_console.h +++ b/sim_console.h @@ -88,6 +88,7 @@ t_stat sim_set_cons_buff (int32 flg, CONST char *cptr); t_stat sim_set_cons_unbuff (int32 flg, CONST char *cptr); t_stat sim_set_cons_log (int32 flg, CONST char *cptr); t_stat sim_set_cons_nolog (int32 flg, CONST char *cptr); +t_stat sim_set_cons_connect (int32 flg, CONST char *cptr); t_stat sim_set_deboff (int32 flag, CONST char *cptr); t_stat sim_set_cons_expect (int32 flg, CONST char *cptr); t_stat sim_set_cons_noexpect (int32 flg, CONST char *cptr);