DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/hardware/serialport/serialfile.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 "serialfile.h"
00026 
00027 CSerialFile::CSerialFile(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 
00035     filename = "serial"; // Default output filename
00036     cmd->FindStringBegin("file:", filename, false); // if the user specifies serial1=file file:something, set it to that
00037     LOG_MSG("Serial: port %d will write to file %s", int(id), filename.c_str());
00038         
00039     InstallationSuccessful=true;
00040 }
00041 
00042 CSerialFile::~CSerialFile() {
00043     if (fp != NULL) {
00044         fclose(fp);
00045         fp = NULL;
00046     }
00047 
00048         // clear events
00049         removeEvent(SERIAL_TX_EVENT);
00050 }
00051 
00052 void CSerialFile::handleUpperEvent(Bit16u type) {
00053         if(type==SERIAL_TX_EVENT) {
00054         //LOG_MSG("SERIAL_TX_EVENT");
00055                 ByteTransmitted(); // tx timeout
00056         }
00057         else if(type==SERIAL_THR_EVENT){
00058                 //LOG_MSG("SERIAL_THR_EVENT");
00059                 ByteTransmitting();
00060                 setEvent(SERIAL_TX_EVENT,bytetime);
00061         }
00062 
00063 }
00064 
00065 /*****************************************************************************/
00066 /* updatePortConfig is called when emulated app changes the serial port     **/
00067 /* parameters baudrate, stopbits, number of databits, parity.               **/
00068 /*****************************************************************************/
00069 void CSerialFile::updatePortConfig(Bit16u divider, Bit8u lcr) {
00070     (void)divider;//UNUSED
00071     (void)lcr;//UNUSED
00072         //LOG_MSG("Serial port at 0x%x: Port params changed: %d Baud", base,dcb.BaudRate);
00073 }
00074 
00075 void CSerialFile::updateMSR() {
00076 }
00077 
00078 void CSerialFile::transmitByte(Bit8u val, bool first) {
00079         if(first) setEvent(SERIAL_THR_EVENT, bytetime/10); 
00080         else setEvent(SERIAL_TX_EVENT, bytetime);
00081 
00082     if (fp == NULL) {
00083         fp = fopen(filename.c_str(),"wb");
00084         if (fp != NULL) setbuf(fp,NULL); // disable buffering
00085     }
00086     if (fp != NULL)
00087         fwrite(&val,1,1,fp);
00088 }
00089 
00090 /*****************************************************************************/
00091 /* setBreak(val) switches break on or off                                   **/
00092 /*****************************************************************************/
00093 
00094 void CSerialFile::setBreak(bool value) {
00095     (void)value;//UNUSED
00096         //LOG_MSG("UART 0x%x: Break toggeled: %d", base, value);
00097 }
00098 
00099 /*****************************************************************************/
00100 /* setRTSDTR sets the modem control lines                                   **/
00101 /*****************************************************************************/
00102 void CSerialFile::setRTSDTR(bool rts, bool dtr) {
00103         setRTS(rts);
00104         setDTR(dtr);
00105 }
00106 
00107 void CSerialFile::setRTS(bool val) {
00108         setCTS(val);
00109 }
00110 
00111 void CSerialFile::setDTR(bool val) {
00112         setDSR(val);
00113         setRI(val);
00114         setCD(val);
00115 }