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