DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/hardware/serialport/seriallog.cpp
00001 /*
00002  *  Copyright (C) 2002-2020  The DOSBox Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License along
00015  *  with this program; if not, write to the Free Software Foundation, Inc.,
00016  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 
00019 
00020 #include "dosbox.h"
00021 
00022 #include "setup.h"
00023 #include "serialdummy.h"
00024 #include "serialport.h"
00025 #include "seriallog.h"
00026 
00027 CSerialLog::CSerialLog(Bitu id, CommandLine* cmd):CSerial(id, cmd) {
00028         CSerial::Init_Registers();
00029         // DSR+CTS on to make sure the DOS COM device will not get stuck waiting for them
00030         setRI(false);
00031         setCD(false);
00032         setDSR(true);
00033         setCTS(true);
00034         InstallationSuccessful=true;
00035 }
00036 
00037 CSerialLog::~CSerialLog() {
00038         // clear events
00039         removeEvent(SERIAL_TX_EVENT);
00040 }
00041 
00042 void CSerialLog::log_emit() {
00043         if (!log_line.empty()) {
00044                 LOG_MSG("CSerial Log: %s",log_line.c_str());
00045                 log_line.clear();
00046         }
00047 }
00048 
00049 void CSerialLog::handleUpperEvent(Bit16u type) {
00050         if(type==SERIAL_TX_EVENT) {
00051         //LOG_MSG("SERIAL_TX_EVENT");
00052                 ByteTransmitted(); // tx timeout
00053         }
00054         else if(type==SERIAL_THR_EVENT){
00055                 //LOG_MSG("SERIAL_THR_EVENT");
00056                 ByteTransmitting();
00057                 setEvent(SERIAL_TX_EVENT,bytetime);
00058         }
00059 
00060 }
00061 
00062 /*****************************************************************************/
00063 /* updatePortConfig is called when emulated app changes the serial port     **/
00064 /* parameters baudrate, stopbits, number of databits, parity.               **/
00065 /*****************************************************************************/
00066 void CSerialLog::updatePortConfig(Bit16u divider, Bit8u lcr) {
00067     (void)divider;//UNUSED
00068     (void)lcr;//UNUSED
00069         //LOG_MSG("Serial port at 0x%x: Port params changed: %d Baud", base,dcb.BaudRate);
00070 }
00071 
00072 void CSerialLog::updateMSR() {
00073 }
00074 
00075 void CSerialLog::transmitByte(Bit8u val, bool first) {
00076         if(first) setEvent(SERIAL_THR_EVENT, bytetime/10); 
00077         else setEvent(SERIAL_TX_EVENT, bytetime);
00078 
00079         if (val == '\n' || val == '\r')
00080                 log_emit();
00081         else {
00082                 log_line += (char)val;
00083                 if (log_line.length() >= 256) log_emit();
00084         }
00085 }
00086 
00087 /*****************************************************************************/
00088 /* setBreak(val) switches break on or off                                   **/
00089 /*****************************************************************************/
00090 
00091 void CSerialLog::setBreak(bool value) {
00092     (void)value;//UNUSED
00093         //LOG_MSG("UART 0x%x: Break toggeled: %d", base, value);
00094 }
00095 
00096 /*****************************************************************************/
00097 /* setRTSDTR sets the modem control lines                                   **/
00098 /*****************************************************************************/
00099 void CSerialLog::setRTSDTR(bool rts, bool dtr) {
00100         setRTS(rts);
00101         setDTR(dtr);
00102 }
00103 
00104 void CSerialLog::setRTS(bool val) {
00105         setCTS(val);
00106 }
00107 
00108 void CSerialLog::setDTR(bool val) {
00109         setDSR(val);
00110         setRI(val);
00111         setCD(val);
00112 }