home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / ASYCLS10.ZIP / ASYNCH.H < prev    next >
C/C++ Source or Header  |  1991-04-03  |  5KB  |  138 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  Asynchronous Class for C++
  4. //  Copyright (C) 1991 by Jui-Lin Hung and SPD!
  5. //
  6. //  You may freely use or incorporate these routines into your own programs
  7. //  without royalty to me, as I believe this is beneficial to programmers.
  8. //  However, I would like to request that if you distribute the source code,
  9. //  you would include this header in the source file and not remove it.
  10. //  Of course, I would have no way of knowing, but I am appealing to your
  11. //  sense of good will and morality.  Thank you, and I hope these routines
  12. //  are useful.
  13. //
  14. //  April, 1991 - Version 1.0
  15. //
  16. /////////////////////////////////////////////////////////////////////////////
  17.  
  18.  
  19. #ifndef __ASYNCH_H
  20. #define __ASYNCH_H
  21.  
  22.  
  23. //-------------------------------------------------------------------------\\
  24.  
  25.  
  26. // Definitions used by the object class Asynch
  27. enum COM_PORTS {
  28.     COM1 =  0x01,   // Com port 1
  29.     COM2 =  0x02,   // Com port 2
  30.     COM3 =  0x03,   // Com port 3
  31.     COM4 =  0x04    // Com port 4
  32. };
  33.  
  34. // Character input/output buffer length define
  35. #define IBUF_LEN    2048    // Incoming buffer
  36. #define OBUF_LEN    1024    // Outgoing buffer
  37.  
  38. // Port addresses for the 8259 Programmable Interrupt Controller (PIC)
  39. #define ICR         0x20    // Interrupt Control Register port
  40. #define IMR         0x21    // Interrupt Mask Register port
  41.  
  42. // An End Of Interrupt needs to be sent to the 8259 control port when
  43. // a hardware interrupt ends
  44. #define EOI         0x20    // End Of Interrupt
  45.  
  46. // TXR  Output data to the serial port
  47. // RXR  Input data from the serial port
  48. // LCR  Initialize the serial port
  49. // IER  Controls interrupt generation
  50. // IIR  Identifies interrupts
  51. // MCR  Send control signals to the modem
  52. // LSR  Monitor the status of the serial port
  53. // MSR  Receive status of the modem
  54. #define TXR         0x00    // Transmit Register    (WRITE)
  55. #define RXR         0x00    // Receive Register     (READ)
  56. #define IER         0x01    // Interrupt Enable Register
  57. #define IIR         0x02    // Interrupt ID Register
  58. #define LCR         0x03    // Line Control Register
  59. #define MCR         0x04    // Modem Control Register
  60. #define LSR         0x05    // Line Status Register
  61. #define MSR         0x06    // Modem Status Register
  62.  
  63. #define DTR         0x01    // Data Terminal Ready
  64. #define RTS         0x02    // Request To Send.  There is data to send.
  65. #define MCI         0x08    // Modem Control Interrupt
  66.  
  67. #define CTS         0x10    // Clear To Send
  68. #define DSR         0x20    // Data Set Ready
  69.  
  70.  
  71. //-------------------------------------------------------------------------\\
  72.  
  73.  
  74. // Asynchronous port information structure
  75. typedef struct _asynch_info {
  76.     unsigned char   port;               // serial port
  77.     volatile int    inhead,intail;      // pointers to the in buffer
  78.     volatile int    outhead,outtail;    // pointers to the out buffer
  79.     volatile char   inbuf[IBUF_LEN];    // in buffer
  80.     volatile char   outbuf[OBUF_LEN];   // out buffer
  81.     int             base;               // base address to this port
  82.     int             irq;                // interrupt number for this port
  83.     int             flow;               // high-speed modem flow control
  84.     unsigned int    baud;               // maximum baud speed for modem
  85.     int             nohangup;           // hang up at end of session?
  86. } _asynch_info;
  87.  
  88. extern _asynch_info _ainfo;
  89.  
  90.  
  91. //-------------------------------------------------------------------------\\
  92.  
  93.  
  94. // Function prototype for serial interrupt
  95. void far interrupt asynch_irq(...); // interrupt handler
  96.  
  97.  
  98. //-------------------------------------------------------------------------\\
  99.  
  100.  
  101. // Asynchronous object class definition
  102. class Asynch {
  103. private:
  104.     // Private member functions
  105.     void asynchInit();              // interrupt initialization
  106. public:
  107.     // Constructors/Destructors
  108.     Asynch(unsigned char);          // constructors
  109.     Asynch(unsigned char,unsigned int);
  110.    ~Asynch(void);                   // destructor
  111.  
  112.     // Public member functions
  113.     void setBaud(unsigned int);     // sets the baudrate
  114.     int dtr(void);                  // returns 1 if dtr high, 0 if not
  115.     inline void setDtr(void);              // sets DTR high
  116.     void dropDtr(void);             // sets DTR low
  117.     int  inCount(void);             // counts chars left in the in buffer
  118.     int  outCount(void);            // counts chars left in the out buffer
  119.     void flushInBuf(void);          // dumps in buffer
  120.     void flushOutBuf(void);         // dumps out buffer
  121.  
  122.     // Operator overloaders
  123.     Asynch &operator<<(char);       // overloaded << operator for chars
  124.     Asynch &operator<<(char *);     // overloaded << operator for strings
  125.     Asynch &operator>>(char &);     // overloaded >> operator for chars
  126.  
  127.     // C type functions
  128.     void outCh(char);               // outputs character to port
  129.     void outStr(char *);            // outputs string to port
  130.     char inCh(void);                // inputs character from port
  131.  
  132.     // Inline functions
  133.     void flushAllBufs(void)     { flushInBuf(), flushOutBuf();          }
  134. };
  135.  
  136.  
  137. #endif // __ASYNCH_H
  138.