SCP: On Windows fixed writing to Console when Console is file.

This commit is contained in:
Richard Cornwell 2022-10-24 18:37:03 -04:00
parent f1c233afe7
commit 144d8a10cb

View file

@ -3670,11 +3670,21 @@ return (WAIT_OBJECT_0 == WaitForSingleObject (std_input, ms_timeout));
static uint8 out_buf[ESC_HOLD_MAX]; /* Buffered characters pending output */ static uint8 out_buf[ESC_HOLD_MAX]; /* Buffered characters pending output */
static int32 out_ptr = 0; static int32 out_ptr = 0;
static void sim_console_write(uint8 *outbuf, int32 outsz)
{
DWORD unused;
DWORD mode;
if (GetConsoleMode(std_output, &mode)) {
WriteConsoleA(std_output, outbuf, outsz, &unused, NULL);
} else {
BOOL result = WriteFile(std_output, outbuf, outsz, &unused, NULL);
}
}
static t_stat sim_out_hold_svc (UNIT *uptr) static t_stat sim_out_hold_svc (UNIT *uptr)
{ {
DWORD unused; sim_console_write(out_buf, out_ptr);
WriteConsoleA(std_output, out_buf, out_ptr, &unused, NULL);
out_ptr = 0; out_ptr = 0;
return SCPE_OK; return SCPE_OK;
} }
@ -3683,16 +3693,16 @@ return SCPE_OK;
static t_stat sim_os_putchar (int32 c) static t_stat sim_os_putchar (int32 c)
{ {
DWORD unused;
uint32 now; uint32 now;
static uint32 last_bell_time; static uint32 last_bell_time;
uint8 ch = (c & 0xff);
if (c != 0177) { if (ch != 0177) {
switch (c) { switch (ch) {
case BELL_CHAR: case BELL_CHAR:
now = sim_os_msec (); now = sim_os_msec ();
if ((now - last_bell_time) > BELL_INTERVAL_MS) { if ((now - last_bell_time) > BELL_INTERVAL_MS) {
WriteConsoleA(std_output, &c, 1, &unused, NULL); sim_console_write(&ch, 1);
last_bell_time = now; last_bell_time = now;
} }
break; break;
@ -3701,26 +3711,26 @@ if (c != 0177) {
case CSI_CHAR: case CSI_CHAR:
case ESC_CHAR: case ESC_CHAR:
if (out_ptr) { if (out_ptr) {
WriteConsoleA(std_output, out_buf, out_ptr, &unused, NULL); sim_console_write(out_buf, out_ptr);
out_ptr = 0; out_ptr = 0;
sim_cancel (&out_hold_unit); sim_cancel (&out_hold_unit);
} }
out_buf[out_ptr++] = (uint8)c; out_buf[out_ptr++] = ch;
sim_activate_after (&out_hold_unit, ESC_HOLD_USEC_DELAY); sim_activate_after (&out_hold_unit, ESC_HOLD_USEC_DELAY);
out_hold_unit.action = &sim_out_hold_svc; out_hold_unit.action = &sim_out_hold_svc;
break; break;
default: default:
if (out_ptr) { if (out_ptr) {
if (out_ptr >= ESC_HOLD_MAX) { /* Stop buffering if full */ if (out_ptr >= ESC_HOLD_MAX) { /* Stop buffering if full */
WriteConsoleA(std_output, out_buf, out_ptr, &unused, NULL); sim_console_write(out_buf, out_ptr);
out_ptr = 0; out_ptr = 0;
WriteConsoleA(std_output, &c, 1, &unused, NULL); sim_console_write(&ch, 1);
} }
else else
out_buf[out_ptr++] = (uint8)c; out_buf[out_ptr++] = ch;
} }
else else
WriteConsoleA(std_output, &c, 1, &unused, NULL); sim_console_write(&ch, 1);
} }
} }
return SCPE_OK; return SCPE_OK;