DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/hardware/serialport/nullmodem.h
00001 /*
00002  *  Copyright (C) 2002-2013  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
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 
00020 // include guard
00021 #ifndef DOSBOX_NULLMODEM_WIN32_H
00022 #define DOSBOX_NULLMODEM_WIN32_H
00023 
00024 #include "dosbox.h"
00025 
00026 #if C_MODEM
00027 
00028 #include "misc_util.h"
00029 #include "serialport.h"
00030 
00031 #define SERIAL_SERVER_POLLING_EVENT     SERIAL_BASE_EVENT_COUNT+1
00032 #define SERIAL_TX_REDUCTION             SERIAL_BASE_EVENT_COUNT+2
00033 #define SERIAL_NULLMODEM_DTR_EVENT      SERIAL_BASE_EVENT_COUNT+3
00034 #define SERIAL_NULLMODEM_EVENT_COUNT    SERIAL_BASE_EVENT_COUNT+3
00035 
00036 class CNullModem : public CSerial {
00037 public:
00038         CNullModem(Bitu id, CommandLine* cmd);
00039         ~CNullModem();
00040 
00041         void updatePortConfig(Bit16u divider, Bit8u lcr);
00042         void updateMSR();
00043         void transmitByte(Bit8u val, bool first);
00044         void setBreak(bool value);
00045         
00046         void setRTSDTR(bool rts, bool dtr);
00047         void setRTS(bool val);
00048         void setDTR(bool val);
00049         void handleUpperEvent(Bit16u type);
00050 
00051 private:
00052         TCPServerSocket* serversocket;
00053         TCPClientSocket* clientsocket;
00054 
00055         bool receiveblock;              // It's not a block of data it rather blocks
00056         Bit16u serverport;              // we are a server if this is nonzero
00057         Bit16u clientport;
00058 
00059         Bit8u hostnamebuffer[128]; // the name passed to us by the user
00060 
00061         Bitu rx_state;
00062 #define N_RX_IDLE               0
00063 #define N_RX_WAIT               1
00064 #define N_RX_BLOCKED    2
00065 #define N_RX_FASTWAIT   3
00066 #define N_RX_DISC               4
00067 
00068         bool doReceive();
00069         bool ClientConnect(TCPClientSocket* newsocket);
00070         bool ServerListen();
00071         bool ServerConnect();
00072     void Disconnect();
00073         Bits readChar();
00074         void WriteChar(Bit8u data);
00075 
00076         bool DTR_delta;         // with dtrrespect, we try to establish a connection
00077                                                 // whenever DTR switches to 1. This variable is
00078                                                 // used to remember the old state.
00079 
00080         bool tx_block;          // true while the SERIAL_TX_REDUCTION event
00081                                                 // is pending
00082 
00083         Bitu rx_retry;          // counter of retries
00084 
00085         Bitu rx_retry_max;      // how many POLL_EVENTS to wait before causing
00086                                                 // a overrun error.
00087 
00088         Bitu tx_gather;         // how long to gather tx data before
00089                                                 // sending all of them [milliseconds]
00090 
00091         
00092         bool dtrrespect;        // dtr behavior - only send data to the serial
00093                                                 // port when DTR is on
00094 
00095         bool transparent;       // if true, don't send 0xff 0xXX to toggle
00096                                                 // DSR/CTS.
00097 
00098         bool telnet;            // Do Telnet parsing.
00099 
00100     bool nonlocal;      // Enable connections NOT originating from localhost
00101 
00102         // Telnet's brain
00103 #define TEL_CLIENT 0
00104 #define TEL_SERVER 1
00105 
00106         Bits TelnetEmulation(Bit8u data);
00107 
00108         // Telnet's memory
00109         struct {
00110                 bool binary[2];
00111                 bool echo[2];
00112                 bool supressGA[2];
00113                 bool timingMark[2];
00114                                         
00115                 bool inIAC;
00116                 bool recCommand;
00117                 Bit8u command;
00118         } telClient;
00119 };
00120 
00121 #endif  // C_MODEM
00122 #endif  // include guard