WINCOMM.H 14 KB

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