1 /*
2  *  Copyright (C) 2002-2013  The DOSBox Team
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  */
18 
19 
20 // include guard
21 #ifndef DOSBOX_NULLMODEM_WIN32_H
22 #define DOSBOX_NULLMODEM_WIN32_H
23 
24 #include "dosbox.h"
25 
26 #if C_MODEM
27 
28 #include "misc_util.h"
29 #include "serialport.h"
30 
31 #define SERIAL_SERVER_POLLING_EVENT	SERIAL_BASE_EVENT_COUNT+1
32 #define SERIAL_TX_REDUCTION		SERIAL_BASE_EVENT_COUNT+2
33 #define SERIAL_NULLMODEM_DTR_EVENT	SERIAL_BASE_EVENT_COUNT+3
34 #define SERIAL_NULLMODEM_EVENT_COUNT	SERIAL_BASE_EVENT_COUNT+3
35 
36 class CNullModem : public CSerial {
37 public:
38 	CNullModem(Bitu id, CommandLine* cmd);
39 	~CNullModem();
40 
41 	void updatePortConfig(Bit16u divider, Bit8u lcr);
42 	void updateMSR();
43 	void transmitByte(Bit8u val, bool first);
44 	void setBreak(bool value);
45 
46 	void setRTSDTR(bool rts, bool dtr);
47 	void setRTS(bool val);
48 	void setDTR(bool val);
49 	void handleUpperEvent(Bit16u type);
50 
51 private:
52 	TCPServerSocket* serversocket;
53 	TCPClientSocket* clientsocket;
54 
55 	bool receiveblock;		// It's not a block of data it rather blocks
56 	Bit16u serverport;		// we are a server if this is nonzero
57 	Bit16u clientport;
58 
59 	Bit8u hostnamebuffer[128]; // the name passed to us by the user
60 
61 	Bitu rx_state;
62 #define N_RX_IDLE		0
63 #define N_RX_WAIT		1
64 #define N_RX_BLOCKED	2
65 #define N_RX_FASTWAIT	3
66 #define N_RX_DISC		4
67 
68 	bool doReceive();
69 	bool ClientConnect(TCPClientSocket* newsocket);
70 	bool ServerListen();
71 	bool ServerConnect();
72     void Disconnect();
73 	Bits readChar();
74 	void WriteChar(Bit8u data);
75 
76 	bool DTR_delta;		// with dtrrespect, we try to establish a connection
77 						// whenever DTR switches to 1. This variable is
78 						// used to remember the old state.
79 
80 	bool tx_block;		// true while the SERIAL_TX_REDUCTION event
81 						// is pending
82 
83 	Bitu rx_retry;		// counter of retries
84 
85 	Bitu rx_retry_max;	// how many POLL_EVENTS to wait before causing
86 						// a overrun error.
87 
88 	Bitu tx_gather;		// how long to gather tx data before
89 						// sending all of them [milliseconds]
90 
91 
92 	bool dtrrespect;	// dtr behavior - only send data to the serial
93 						// port when DTR is on
94 
95 	bool transparent;	// if true, don't send 0xff 0xXX to toggle
96 						// DSR/CTS.
97 
98 	bool telnet;		// Do Telnet parsing.
99 
100 	// Telnet's brain
101 #define TEL_CLIENT 0
102 #define TEL_SERVER 1
103 
104 	Bits TelnetEmulation(Bit8u data);
105 
106 	// Telnet's memory
107 	struct {
108 		bool binary[2];
109 		bool echo[2];
110 		bool supressGA[2];
111 		bool timingMark[2];
112 
113 		bool inIAC;
114 		bool recCommand;
115 		Bit8u command;
116 	} telClient;
117 };
118 
119 #endif	// C_MODEM
120 #endif	// include guard
121