mirror of
https://github.com/simh/simh.git
synced 2026-05-04 06:58:38 +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:
committed by
Mark Pizzolato
parent
9b0d7a77d8
commit
0185df8fee
@@ -3430,9 +3430,12 @@ return SCPE_NOFNC;
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
#define RAW_MODE 0
|
#define RAW_MODE 0
|
||||||
|
typedef BOOL (WINAPI *std_output_writer_fn)(HANDLE, const void *, DWORD, LPDWORD, LPVOID);
|
||||||
|
|
||||||
static HANDLE std_input;
|
static HANDLE std_input;
|
||||||
static HANDLE std_output;
|
static HANDLE std_output;
|
||||||
static HANDLE std_error;
|
static HANDLE std_error;
|
||||||
|
static std_output_writer_fn std_output_writer = NULL;
|
||||||
static DWORD saved_input_mode;
|
static DWORD saved_input_mode;
|
||||||
static DWORD saved_output_mode;
|
static DWORD saved_output_mode;
|
||||||
static DWORD saved_error_mode;
|
static DWORD saved_error_mode;
|
||||||
@@ -3484,12 +3487,20 @@ SetConsoleCtrlHandler( ControlHandler, TRUE );
|
|||||||
std_input = GetStdHandle (STD_INPUT_HANDLE);
|
std_input = GetStdHandle (STD_INPUT_HANDLE);
|
||||||
std_output = GetStdHandle (STD_OUTPUT_HANDLE);
|
std_output = GetStdHandle (STD_OUTPUT_HANDLE);
|
||||||
std_error = GetStdHandle (STD_ERROR_HANDLE);
|
std_error = GetStdHandle (STD_ERROR_HANDLE);
|
||||||
|
|
||||||
if ((std_input) && /* Not Background process? */
|
if ((std_input) && /* Not Background process? */
|
||||||
(std_input != INVALID_HANDLE_VALUE))
|
(std_input != INVALID_HANDLE_VALUE))
|
||||||
GetConsoleMode (std_input, &saved_input_mode); /* Save Input Mode */
|
GetConsoleMode (std_input, &saved_input_mode); /* Save Input Mode */
|
||||||
if ((std_output) && /* Not Background process? */
|
if ((std_output) && /* Not Background process? */
|
||||||
(std_output != INVALID_HANDLE_VALUE))
|
(std_output != INVALID_HANDLE_VALUE)) { /* Save Output Mode */
|
||||||
GetConsoleMode (std_output, &saved_output_mode); /* 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? */
|
if ((std_error) && /* Not Background process? */
|
||||||
(std_error != INVALID_HANDLE_VALUE))
|
(std_error != INVALID_HANDLE_VALUE))
|
||||||
GetConsoleMode (std_error, &saved_error_mode); /* Save Output Mode */
|
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)
|
static void sim_console_write(uint8 *outbuf, int32 outsz)
|
||||||
{
|
{
|
||||||
DWORD unused;
|
DWORD unused;
|
||||||
DWORD mode;
|
|
||||||
BOOL result;
|
BOOL result;
|
||||||
|
|
||||||
if (GetConsoleMode(std_output, &mode))
|
/* Useful to see the return value from std_output_writer. */
|
||||||
WriteConsoleA(std_output, outbuf, outsz, &unused, NULL);
|
result = std_output_writer(std_output, outbuf, outsz, &unused, NULL);
|
||||||
else
|
/* But squelch the set-but-not-used warnings. */
|
||||||
result = WriteFile(std_output, outbuf, outsz, &unused, NULL);
|
(void) result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static t_stat sim_out_hold_svc (UNIT *uptr)
|
static t_stat sim_out_hold_svc (UNIT *uptr)
|
||||||
|
|||||||
Reference in New Issue
Block a user