WINCOMM.H 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. /*
  2. ** Command & Conquer Red Alert(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Command & Conquer/ WW Library *
  23. * *
  24. * File Name : WINCOMM.H *
  25. * *
  26. * Programmer : Steve Tall *
  27. * *
  28. * Start Date : 1/10/96 *
  29. * *
  30. * Last Update : January 10th 1996 [ST] *
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Overview: *
  34. * *
  35. * These classes was created to replace the greenleaf comms functions used in C&C DOS with *
  36. * WIN32 API calls. *
  37. * *
  38. *---------------------------------------------------------------------------------------------*
  39. * *
  40. * Functions: *
  41. * *
  42. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  43. #ifndef WIN32
  44. #define WIN32
  45. #define _WIN32
  46. #endif //WIN32
  47. #include <windows.h>
  48. typedef enum WinCommDialMethodType {
  49. WC_TOUCH_TONE = 0,
  50. WC_PULSE
  51. } WinCommDialMethodType;
  52. #define COMMSUCCESS 0
  53. #define ASTIMEOUT -10
  54. #define COMMUSERABORT -16
  55. /*
  56. ** The size of our serial buffer within the class.
  57. **
  58. ** !!!!!! THIS MUST BE A POWER OF 2 !!!!!!
  59. **
  60. */
  61. #define SIZE_OF_WINDOWS_SERIAL_BUFFER 2048
  62. /*
  63. ** WinModemClass.
  64. **
  65. ** This class provides access to modems under Win95. The functions are designed to be more or less
  66. ** drop in replacements for the Grenleaf comms functions.
  67. */
  68. class WinModemClass
  69. {
  70. public:
  71. WinModemClass (void); //WinModemClass Contructor
  72. virtual ~WinModemClass (void); //WinModemClass Destructor
  73. /*
  74. ** Serial port open should be called to get a handle to the COM port
  75. ** This needs to be called first as other class members rely on the handle
  76. **
  77. ** Replacement for Greenleaf function: PortOpenGreenleafFast
  78. */
  79. //virtual HANDLE Serial_Port_Open (int port, int baud, int parity, int wordlen, int stopbits);
  80. virtual HANDLE Serial_Port_Open (char *device_name, int baud, int parity, int wordlen, int stopbits, int flowcontrol);
  81. /*
  82. ** This function releases the COM port handle and should be called after
  83. ** communications have finished
  84. **
  85. ** Replacement for Greenleaf function: PortClose
  86. */
  87. void Serial_Port_Close (void);
  88. /*
  89. ** This member copies any bytes from the internal class serial buffer
  90. ** into your user buffer.
  91. **
  92. ** Replacement for Greenleaf function: ReadBuffer
  93. */
  94. int Read_From_Serial_Port (unsigned char *dest_ptr, int buffer_len);
  95. /*
  96. ** Write chars to the serial port
  97. **
  98. ** Replacement for Greenleaf function: WriteBuffer
  99. */
  100. void Write_To_Serial_Port (unsigned char *buffer, int length);
  101. /*
  102. ** Wait for the outgoing buffer to empty
  103. */
  104. void Wait_For_Serial_Write (void);
  105. /*
  106. ** Set the dial type to DIAL_TOUCH_TONE or DIAL_PULSE
  107. **
  108. ** Replacement for Greenleaf function: HMSetDiallingMethod
  109. */
  110. virtual void Set_Modem_Dial_Type (WinCommDialMethodType method);
  111. /*
  112. ** Get the status of the modem control lines
  113. ** Possible flags are: CTS_SET DSR_SET RI_SET & CD_SET
  114. **
  115. ** Replacement for Greenleaf function: GetModemStatus
  116. */
  117. virtual unsigned Get_Modem_Status (void);
  118. /*
  119. ** Set the DTR line to the given state
  120. **
  121. ** Replacement for Greenleaf function: SetDtr
  122. */
  123. virtual void Set_Serial_DTR (BOOL state);
  124. /*
  125. ** Get the result code from the modem after issuing an 'AT' command
  126. **
  127. ** Replacement for Greenleaf function: HMInputLine
  128. */
  129. virtual int Get_Modem_Result (int delay, char *buffer, int buffer_len);
  130. /*
  131. ** Issue a dial command to the modem.
  132. ** Use Set_Modem_Dial_Type to select pulse or tone dial
  133. **
  134. ** Replacement for Greenleaf function: HMDial
  135. */
  136. virtual void Dial_Modem (char *dial_number);
  137. /*
  138. ** Send a command to the modem. This is usually an 'AT' command.
  139. ** Function will optionally retry until 'OK' is received.
  140. */
  141. virtual int Send_Command_To_Modem (char *command, char terminator, char *buffer, int buflen, int delay, int retries);
  142. /*
  143. ** Sets a pointer to a function that will be called for each incoming serial char
  144. **
  145. ** Replacement for Greenleaf function: HMSetUpEchoRoutine
  146. */
  147. virtual void Set_Echo_Function (void(*func)(char c));
  148. /*
  149. ** Sets a pointer to a function that will be called if ESC is pressed during a dial
  150. **
  151. ** Replacement for Greenleaf function: HMSetUpAbortKey
  152. */
  153. virtual void Set_Abort_Function (int (*func)(void));
  154. /*
  155. ** Member to allow access to the serial port handle
  156. */
  157. HANDLE Get_Port_Handle(void);
  158. /*
  159. ** Status vars for debugging purposes
  160. */
  161. int FramingErrors;
  162. int IOErrors;
  163. int BufferOverruns;
  164. int InBufferOverflows;
  165. int ParityErrors;
  166. int OutBufferOverflows;
  167. int InQueue;
  168. int OutQueue;
  169. /*
  170. ** Modem send result codes
  171. */
  172. enum SendModemEnum {
  173. MODEM_CMD_TIMEOUT = 0,
  174. MODEM_CMD_OK,
  175. MODEM_CMD_0,
  176. MODEM_CMD_ERROR
  177. };
  178. /*
  179. ** Enums for modem status flags
  180. */
  181. enum {
  182. CTS_SET = 0x10,
  183. DSR_SET = 0x20,
  184. RI_SET = 0x40,
  185. CD_SET = 0x80
  186. };
  187. protected:
  188. /*
  189. ** Copy incoming data from the windows file buffer into the internal class buffer
  190. */
  191. BOOL Read_Serial_Chars(void);
  192. /*
  193. ** Pointer to the internal class circular buffer for incoming data
  194. */
  195. unsigned char *SerialBuffer;
  196. /*
  197. ** Overlap object for asyncronous reads from the serial port
  198. */
  199. OVERLAPPED ReadOverlap;
  200. /*
  201. ** Overlap object for asyncronous writes to the serial port
  202. */
  203. OVERLAPPED WriteOverlap;
  204. /*
  205. ** Flag that there is no outstanding incoming data in the windows buffer
  206. */
  207. BOOL WaitingForSerialCharRead;
  208. /*
  209. ** Flag that we are waiting for the last write to port operation to complete
  210. */
  211. BOOL WaitingForSerialCharWrite;
  212. /*
  213. ** Head and Tail pointers for our internal serial buffer
  214. */
  215. int SerialBufferReadPtr;
  216. int SerialBufferWritePtr;
  217. /*
  218. ** Windows handle to the COM port device
  219. */
  220. HANDLE PortHandle;
  221. /*
  222. ** Dialing method - DIAL_TOUCH_TONE or DIAL_PULSE
  223. */
  224. WinCommDialMethodType DialingMethod;
  225. /*
  226. ** Pointer to function for echoing incoming data - can be NULL
  227. */
  228. void (*EchoFunction)(char c);
  229. /*
  230. ** Pointer to function for aborting when ESC pressed - can be NULL
  231. */
  232. int (*AbortFunction)(void);
  233. /*
  234. ** Serial buffer for asyncronous reads
  235. */
  236. char TempSerialBuffer[SIZE_OF_WINDOWS_SERIAL_BUFFER];
  237. };
  238. /*
  239. ** WinNullModemClass.
  240. **
  241. ** This class provides access to serial ports under Win95. The functions are designed to be more or less
  242. ** drop in replacements for the Grenleaf comms functions.
  243. **
  244. ** This class just overloads the WinModemClass members that arent required for direct serial communications
  245. ** via a 'null modem' cable.
  246. */
  247. class WinNullModemClass : public WinModemClass
  248. {
  249. public:
  250. virtual inline void Set_Modem_Dial_Type (int){};
  251. virtual inline unsigned Get_Modem_Status (void){return (0);};
  252. virtual inline void Set_Serial_DTR (BOOL){};
  253. virtual inline int Get_Modem_Result (int, char*, int){return(0);};
  254. virtual inline void Dial_Modem (char*){};
  255. virtual inline int Send_Command_To_Modem (char*, char, char*, int, int, int){return (0);};
  256. virtual inline void Set_Echo_Function (void(*)(char)){};
  257. virtual inline void Set_Abort_Function (int(*)(void)){};
  258. };
  259. extern WinModemClass *SerialPort;
  260. //
  261. //
  262. // This bit swiped from the SDK because its not in the Watcom headers yet
  263. //
  264. //
  265. /************************************************************************
  266. * *
  267. * mcx.h -- This module defines the 32-Bit Windows MCX APIs *
  268. * *
  269. * Copyright (c) 1990-1995, Microsoft Corp. All rights reserved. *
  270. * *
  271. ************************************************************************/
  272. #ifndef _MCX_H_
  273. #define _MCX_H_
  274. typedef struct _MODEMDEVCAPS {
  275. DWORD dwActualSize;
  276. DWORD dwRequiredSize;
  277. DWORD dwDevSpecificOffset;
  278. DWORD dwDevSpecificSize;
  279. // product and version identification
  280. DWORD dwModemProviderVersion;
  281. DWORD dwModemManufacturerOffset;
  282. DWORD dwModemManufacturerSize;
  283. DWORD dwModemModelOffset;
  284. DWORD dwModemModelSize;
  285. DWORD dwModemVersionOffset;
  286. DWORD dwModemVersionSize;
  287. // local option capabilities
  288. DWORD dwDialOptions; // bitmap of supported values
  289. DWORD dwCallSetupFailTimer; // maximum in seconds
  290. DWORD dwInactivityTimeout; // maximum in seconds
  291. DWORD dwSpeakerVolume; // bitmap of supported values
  292. DWORD dwSpeakerMode; // bitmap of supported values
  293. DWORD dwModemOptions; // bitmap of supported values
  294. DWORD dwMaxDTERate; // maximum value in bit/s
  295. DWORD dwMaxDCERate; // maximum value in bit/s
  296. // Variable portion for proprietary expansion
  297. BYTE abVariablePortion [1];
  298. } MODEMDEVCAPS, *PMODEMDEVCAPS, *LPMODEMDEVCAPS;
  299. typedef struct _MODEMSETTINGS {
  300. DWORD dwActualSize;
  301. DWORD dwRequiredSize;
  302. DWORD dwDevSpecificOffset;
  303. DWORD dwDevSpecificSize;
  304. // static local options (read/write)
  305. DWORD dwCallSetupFailTimer; // seconds
  306. DWORD dwInactivityTimeout; // seconds
  307. DWORD dwSpeakerVolume; // level
  308. DWORD dwSpeakerMode; // mode
  309. DWORD dwPreferredModemOptions; // bitmap
  310. // negotiated options (read only) for current or last call
  311. DWORD dwNegotiatedModemOptions; // bitmap
  312. DWORD dwNegotiatedDCERate; // bit/s
  313. // Variable portion for proprietary expansion
  314. BYTE abVariablePortion [1];
  315. } MODEMSETTINGS, *PMODEMSETTINGS, *LPMODEMSETTINGS;
  316. // Dial Options
  317. #define DIALOPTION_BILLING 0x00000040 // Supports wait for bong "$"
  318. #define DIALOPTION_QUIET 0x00000080 // Supports wait for quiet "@"
  319. #define DIALOPTION_DIALTONE 0x00000100 // Supports wait for dial tone "W"
  320. // SpeakerVolume for MODEMDEVCAPS
  321. #define MDMVOLFLAG_LOW 0x00000001
  322. #define MDMVOLFLAG_MEDIUM 0x00000002
  323. #define MDMVOLFLAG_HIGH 0x00000004
  324. // SpeakerVolume for MODEMSETTINGS
  325. #define MDMVOL_LOW 0x00000000
  326. #define MDMVOL_MEDIUM 0x00000001
  327. #define MDMVOL_HIGH 0x00000002
  328. // SpeakerMode for MODEMDEVCAPS
  329. #define MDMSPKRFLAG_OFF 0x00000001
  330. #define MDMSPKRFLAG_DIAL 0x00000002
  331. #define MDMSPKRFLAG_ON 0x00000004
  332. #define MDMSPKRFLAG_CALLSETUP 0x00000008
  333. // SpeakerMode for MODEMSETTINGS
  334. #define MDMSPKR_OFF 0x00000000
  335. #define MDMSPKR_DIAL 0x00000001
  336. #define MDMSPKR_ON 0x00000002
  337. #define MDMSPKR_CALLSETUP 0x00000003
  338. // Modem Options
  339. #define MDM_COMPRESSION 0x00000001
  340. #define MDM_ERROR_CONTROL 0x00000002
  341. #define MDM_FORCED_EC 0x00000004
  342. #define MDM_CELLULAR 0x00000008
  343. #define MDM_FLOWCONTROL_HARD 0x00000010
  344. #define MDM_FLOWCONTROL_SOFT 0x00000020
  345. #define MDM_CCITT_OVERRIDE 0x00000040
  346. #define MDM_SPEED_ADJUST 0x00000080
  347. #define MDM_TONE_DIAL 0x00000100
  348. #define MDM_BLIND_DIAL 0x00000200
  349. #define MDM_V23_OVERRIDE 0x00000400
  350. #endif /* _MCX_H_ */