1
0
mirror of https://github.com/simh/simh.git synced 2026-01-11 23:52:58 +00:00

CONSOLE: Remove Win32 console output overhead

Don't repeatedly call GetConsoleMode() on Win32 each time
sim_console_write() is called.

Use an output function pointer to invoke WriteConsoleA (console output)
or WriteFile (output is not a console). The console output destination
doesn't change during the lifetime of the simulator, so avoid
extraneous overhead for each character output (sometimes strings, but
mostly characters.)
This commit is contained in:
B. Scott Michel 2025-03-20 09:25:50 -10:00 committed by Mark Pizzolato
parent 9b0d7a77d8
commit 0185df8fee

View File

@ -3430,9 +3430,12 @@ return SCPE_NOFNC;
#include <fcntl.h>
#include <io.h>
#define RAW_MODE 0
typedef BOOL (WINAPI *std_output_writer_fn)(HANDLE, const void *, DWORD, LPDWORD, LPVOID);
static HANDLE std_input;
static HANDLE std_output;
static HANDLE std_error;
static std_output_writer_fn std_output_writer = NULL;
static DWORD saved_input_mode;
static DWORD saved_output_mode;
static DWORD saved_error_mode;
@ -3484,12 +3487,20 @@ SetConsoleCtrlHandler( ControlHandler, TRUE );
std_input = GetStdHandle (STD_INPUT_HANDLE);
std_output = GetStdHandle (STD_OUTPUT_HANDLE);
std_error = GetStdHandle (STD_ERROR_HANDLE);
if ((std_input) && /* Not Background process? */
(std_input != INVALID_HANDLE_VALUE))
GetConsoleMode (std_input, &saved_input_mode); /* Save Input Mode */
if ((std_output) && /* Not Background process? */
(std_output != INVALID_HANDLE_VALUE))
GetConsoleMode (std_output, &saved_output_mode); /* Save Output Mode */
(std_output != INVALID_HANDLE_VALUE)) { /* Save Output Mode */
std_output_writer = GetConsoleMode(std_output, &saved_output_mode)
? WriteConsoleA
: (std_output_writer_fn) WriteFile;
}
else {
/* Default to something resonable... */
std_output_writer = (std_output_writer_fn) WriteFile;
}
if ((std_error) && /* Not Background process? */
(std_error != INVALID_HANDLE_VALUE))
GetConsoleMode (std_error, &saved_error_mode); /* Save Output Mode */
@ -3640,13 +3651,12 @@ static int32 out_ptr = 0;
static void sim_console_write(uint8 *outbuf, int32 outsz)
{
DWORD unused;
DWORD mode;
BOOL result;
if (GetConsoleMode(std_output, &mode))
WriteConsoleA(std_output, outbuf, outsz, &unused, NULL);
else
result = WriteFile(std_output, outbuf, outsz, &unused, NULL);
/* Useful to see the return value from std_output_writer. */
result = std_output_writer(std_output, outbuf, outsz, &unused, NULL);
/* But squelch the set-but-not-used warnings. */
(void) result;
}
static t_stat sim_out_hold_svc (UNIT *uptr)