Debian Codegraph @

src/hardware/serialport/softmodem.h

raw symbols SCIP
1 /*
2 * Copyright (C) 2002-2010 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 /* $Id: softmodem.h,v 1.12 2009-10-04 20:57:40 h-a-l-9000 Exp $ */
20
21 #ifndef DOSBOX_SERIALMODEM_H
22 #define DOSBOX_SERIALMODEM_H
23
24 #include "dosbox.h"
25 #if C_MODEM
26 #include "serialport.h"
27
28 #include "misc_util.h"
29
30 #define MODEMSPD 57600
31 #define SREGS 100
32
33 //If it's too high you overflow terminal clients buffers i think
34 #define MODEM_BUFFER_QUEUE_SIZE 1024
35
36 #define MODEM_DEFAULT_PORT 23
37
38 #define MODEM_TX_EVENT SERIAL_BASE_EVENT_COUNT + 1
39 #define MODEM_RX_POLLING SERIAL_BASE_EVENT_COUNT + 2
40 #define MODEM_RING_EVENT SERIAL_BASE_EVENT_COUNT + 3
41 #define SERIAL_MODEM_EVENT_COUNT SERIAL_BASE_EVENT_COUNT+3
42
43
44 enum ResTypes {
45 ResNONE,
46 ResOK,ResERROR,
47 ResCONNECT,ResRING,
48 ResBUSY,ResNODIALTONE,ResNOCARRIER
49 };
50
51 #define TEL_CLIENT 0
52 #define TEL_SERVER 1
53
54 class CFifo {
55 public:
56 CFifo(Bitu _size) {
57 size=_size;
58 pos=used=0;
59 data=new Bit8u[size];
60 }
61 ~CFifo() {
62 delete[] data;
63 }
64 INLINE Bitu left(void) {
65 return size-used;
66 }
67 INLINE Bitu inuse(void) {
68 return used;
69 }
70 void clear(void) {
71 used=pos=0;
72 }
73
74 void addb(Bit8u _val) {
75 if(used>=size) {
76 static Bits lcount=0;
77 if (lcount<1000) {
78 lcount++;
79 LOG_MSG("MODEM: FIFO Overflow! (addb)");
80 }
81 return;
82 }
83 //assert(used<size);
84 Bitu where=pos+used;
85 if (where>=size) where-=size;
86 data[where]=_val;
87 //LOG_MSG("+%x",_val);
88 used++;
89 }
90 void adds(Bit8u * _str,Bitu _len) {
91 if((used+_len)>size) {
92 static Bits lcount=0;
93 if (lcount<1000) {
94 lcount++;
95 LOG_MSG("MODEM: FIFO Overflow! (adds len %u)",_len);
96 }
97 return;
98 }
99
100 //assert((used+_len)<=size);
101 Bitu where=pos+used;
102 used+=_len;
103 while (_len--) {
104 if (where>=size) where-=size;
105 //LOG_MSG("+'%x'",*_str);
106 data[where++]=*_str++;
107 }
108 }
109 Bit8u getb(void) {
110 if (!used) {
111 static Bits lcount=0;
112 if (lcount<1000) {
113 lcount++;
114 LOG_MSG("MODEM: FIFO UNDERFLOW! (getb)");
115 }
116 return data[pos];
117 }
118 Bitu where=pos;
119 if (++pos>=size) pos-=size;
120 used--;
121 //LOG_MSG("-%x",data[where]);
122 return data[where];
123 }
124 void gets(Bit8u * _str,Bitu _len) {
125 if (!used) {
126 static Bits lcount=0;
127 if (lcount<1000) {
128 lcount++;
129 LOG_MSG("MODEM: FIFO UNDERFLOW! (gets len %d)",_len);
130 }
131 return;
132 }
133 //assert(used>=_len);
134 used-=_len;
135 while (_len--) {
136 //LOG_MSG("-%x",data[pos]);
137 *_str++=data[pos];
138 if (++pos>=size) pos-=size;
139 }
140 }
141 private:
142 Bit8u * data;
143 Bitu size,pos,used;
144 };
145 #define MREG_AUTOANSWER_COUNT 0
146 #define MREG_RING_COUNT 1
147 #define MREG_ESCAPE_CHAR 2
148 #define MREG_CR_CHAR 3
149 #define MREG_LF_CHAR 4
150 #define MREG_BACKSPACE_CHAR 5
151
152
153 class CSerialModem : public CSerial {
154 public:
155
156 CFifo *rqueue;
157 CFifo *tqueue;
158
159 CSerialModem(Bitu id, CommandLine* cmd);
160 ~CSerialModem();
161
162 void Reset();
163
164 void SendLine(const char *line);
165 void SendRes(ResTypes response);
166 void SendNumber(Bitu val);
167
168 void EnterIdleState();
169 void EnterConnectedState();
170
171 void openConnection(void);
172 bool Dial(char * host);
173 void AcceptIncomingCall(void);
174 Bitu ScanNumber(char * & scan);
175 char GetChar(char * & scan);
176
177 void DoCommand();
178
179 void MC_Changed(Bitu new_mc);
180
181 void TelnetEmulation(Bit8u * data, Bitu size);
182
183 //TODO
184 void Timer2(void);
185 void handleUpperEvent(Bit16u type);
186
187 void RXBufferEmpty();
188
189 void transmitByte(Bit8u val, bool first);
190 void updatePortConfig(Bit16u divider, Bit8u lcr);
191 void updateMSR();
192
193 void setBreak(bool);
194
195 void setRTSDTR(bool rts, bool dtr);
196 void setRTS(bool val);
197 void setDTR(bool val);
198
199 protected:
200 char cmdbuf[255];
201 bool commandmode; // true: interpret input as commands
202 bool echo; // local echo on or off
203
204 bool oldDTRstate;
205 bool ringing;
206 //bool response;
207 bool numericresponse; // true: send control response as number.
208 // false: send text (i.e. NO DIALTONE)
209 bool telnetmode; // true: process IAC commands.
210
211 bool connected;
212 Bitu doresponse;
213
214 Bit8u waiting_tx_character;
215
216 Bitu cmdpause;
217 Bits ringtimer;
218 Bits ringcount;
219 Bitu plusinc;
220 Bitu cmdpos;
221 Bitu flowcontrol;
222
223 Bit8u tmpbuf[MODEM_BUFFER_QUEUE_SIZE];
224
225 Bitu listenport;
226 Bit8u reg[SREGS];
227
228
229 TCPServerSocket* serversocket;
230 TCPClientSocket* clientsocket;
231 TCPClientSocket* waitingclientsocket;
232
233 struct {
234 bool binary[2];
235 bool echo[2];
236 bool supressGA[2];
237 bool timingMark[2];
238
239 bool inIAC;
240 bool recCommand;
241 Bit8u command;
242 } telClient;
243 struct {
244 bool active;
245 double f1, f2;
246 Bitu len,pos;
247 char str[256];
248 } dial;
249 };
250 #endif
251 #endif