home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / CPPCOM17.ZIP / COMPORTS.HPP < prev    next >
C/C++ Source or Header  |  1991-02-27  |  4KB  |  101 lines

  1.  
  2. /***************************************************************************
  3. These C++ classes are copyright 1990, by William Herrera.
  4. All those who put this code or its derivatives in a commercial product MUST
  5. mention this copyright in their documentation for users of the products in
  6. which this code or its derivative classes are used.  Otherwise, this code
  7. may be freely distributed and freely used for any purpose.
  8. ***************************************************************************/
  9.  
  10. // File comports.hpp
  11. // Class definition for COM1, COM2, COM3, and COM4 classes.
  12.  
  13. #ifndef COMPORTS_HPP
  14. #define COMPORTS_HPP 1
  15.  
  16. #include "uart.hpp"
  17. #include "charqueu.hpp"
  18.  
  19. static void DoNothing() { return; }
  20.  
  21. #ifdef __TURBOC__
  22.  
  23.  
  24. #define DECLARE_COMX(COM, x, driver)                            \
  25.                                                                 \
  26. class COM##x : public uart                                      \
  27. {                                                               \
  28.     friend void interrupt driver##x(...);                       \
  29.     friend class SerialPort;                                    \
  30. protected:                                                      \
  31.     static CharQueue * inq;                                     \
  32.     static CharQueue * outq;                                    \
  33.     static DRIVER driver;                                       \
  34.     static COM##x * this_ptr;/* allows driver to get to this */ \
  35.     void (*DoIfNoCarrier)(); /* by default does nothing. */     \
  36. public:                                                         \
  37.     COM##x();                                                   \
  38.     ~COM##x();                                                  \
  39.     virtual void SetDoIfNoCarrier(void (*f)());                 \
  40.     virtual void SendChar(char ch);                             \
  41.     virtual int GetChar();                                      \
  42.     void PurgeInput() { inq->Purge(); }                         \
  43.     void FlushOutput();                                         \
  44.     void PurgeOutput() { outq->Purge(); }                       \
  45.     boolean InputEmpty() { return inq->IsEmpty(); }             \
  46.     boolean OutputEmpty() { return outq->IsEmpty(); }           \
  47.     boolean OutputReady() { return (boolean)!outq->IsFull(); }  \
  48. };                                                              \
  49. void interrupt driver##x(...);                                  
  50.  
  51.  
  52.  
  53.  
  54. #else ifdef __ZTC__
  55.  
  56. #define DECLARE_COMX(COM, x, driver)                            \
  57.                                                                 \
  58. class COM##x : public uart                                      \
  59. {                                                               \
  60.     friend int _cdecl driver##x(struct INT_DATA *);             \
  61.     friend class SerialPort;                                    \
  62. protected:                                                      \
  63.     static CharQueue * inq;                                     \
  64.     static CharQueue * outq;                                    \
  65.     static DRIVER driver;                                       \
  66.     static COM##x * this_ptr;/* allows driver to get to this */ \
  67.     void (*DoIfNoCarrier)(); /* by default does nothing. */     \
  68. public:                                                         \
  69.     COM##x();                                                   \
  70.     ~COM##x();                                                  \
  71.     virtual void SetDoIfNoCarrier(void (*f)());                 \
  72.     virtual void SendChar(char ch);                             \
  73.     virtual int GetChar();                                      \
  74.     void PurgeInput() { inq->Purge(); }                         \
  75.     void FlushOutput();                                         \
  76.     void PurgeOutput() { outq->Purge(); }                       \
  77.     boolean InputEmpty() { return inq->IsEmpty(); }             \
  78.     boolean OutputEmpty() { return outq->IsEmpty(); }           \
  79.     boolean OutputReady() { return (boolean)!outq->IsFull(); }  \
  80. };                                                              \
  81. int _cdecl driver##x(struct INT_DATA *);
  82.  
  83.                         
  84.  
  85. #endif
  86.  
  87.  
  88.  
  89. // here we declare COM1 through COM4. Change to suit
  90.  
  91. DECLARE_COMX(COM, 1, driver)
  92.  
  93. DECLARE_COMX(COM, 2, driver)
  94.  
  95. DECLARE_COMX(COM, 3, driver)
  96.  
  97. DECLARE_COMX(COM, 4, driver)
  98.  
  99. #endif
  100.  
  101.