From ef7ed24947e577b5516a90ea92b3dd36ca6afa25 Mon Sep 17 00:00:00 2001 From: Laurent Vivier Date: Fri, 25 Jun 2004 11:16:51 +0000 Subject: [PATCH] Enable serial console on request --- second/serial.c | 64 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 15 deletions(-) diff --git a/second/serial.c b/second/serial.c index 60fc49e..d6ad45d 100644 --- a/second/serial.c +++ b/second/serial.c @@ -4,6 +4,7 @@ * */ +#include #include #include @@ -11,8 +12,8 @@ #include "glue.h" #include "head.h" -static short refnum0; -static short refnum1; +static short refnum0 = -1; +static short refnum1 = -1; #if USE_BUFFER #define BUFFER_LEN 80 @@ -258,15 +259,26 @@ void serial_put(char c) return; flush: - write(refnum0, buffer, buff_len); + if (refnum0 != -1) + write(refnum0, buffer, buff_len); + if (refnum1 != -1) + write(refnum1, buffer, buff_len); buff_len = 0; #else if ( c == '\n' ) { - write(refnum0, "\n\r", 2); + if (refnum0 != -1) + write(refnum0, "\n\r", 2); + if (refnum1 != -1) + write(refnum1, "\n\r", 2); } else - write(refnum0, &c, 1); + { + if (refnum0 != -1) + write(refnum0, &c, 1); + if (refnum1 != -1) + write(refnum1, &c, 1); + } #endif } @@ -274,17 +286,39 @@ void serial_init(emile_l2_header_t* info) { int res; - res = OpenDriver(c2pstring(".AOut"), &refnum0); - res = setserial(refnum0, info->serial0_bitrate, - info->serial0_datasize, - info->serial0_parity, - info->serial0_stopbits); + if (info->console_mask & STDOUT_SERIAL0) { + res = OpenDriver(c2pstring(".AOut"), &refnum0); + if (res != noErr) { + printf("Cannot open modem port (%d)\n", res); + } + else + { + res = setserial(refnum0, info->serial0_bitrate, + info->serial0_datasize, + info->serial0_parity, + info->serial0_stopbits); + if (res != noErr) { + printf("Cannot setup modem port (%d)\n", res); + } + } + } - res = OpenDriver(c2pstring(".BOut"), &refnum1); - res = setserial(refnum0, info->serial1_bitrate, - info->serial1_datasize, - info->serial1_parity, - info->serial1_stopbits); + if (info->console_mask & STDOUT_SERIAL1) { + res = OpenDriver(c2pstring(".BOut"), &refnum1); + if (res != noErr) { + printf("Cannot open printer port (%d)\n", res); + } + else + { + res = setserial(refnum0, info->serial1_bitrate, + info->serial1_datasize, + info->serial1_parity, + info->serial1_stopbits); + if (res != noErr) { + printf("Cannot setup printer port (%d)\n", res); + } + } + } #if USE_BUFFER buff_len = 0;