home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / aspisrc.zip / dev / DEVDEBUG.H < prev    next >
C/C++ Source or Header  |  1998-11-29  |  7KB  |  266 lines

  1.  
  2. // Prevent multiple inclusion
  3. #if !defined(DevDebug_h)
  4. #define DevDebug_h 1
  5.  
  6. #if !defined(__WATCOMC__) || !defined(__cplusplus)
  7. #error Watcom C++ must be used for the RS-232 debugging library.
  8. #endif
  9.  
  10.  
  11. #include "devtype.h"
  12.  
  13.  
  14.  
  15. // Interface to the assembler IO routines
  16.  
  17. WORD16 ComWriteChar(WORD16 Port, WORD16 Char);
  18. #pragma aux ComWriteChar "ComWriteChar"               \
  19.   parm [dx] [ax]                                      \
  20.   value [ax]                                          \
  21.   modify exact [ax cx si];
  22.  
  23. WORD16 ComWriteStr(WORD16 Port, const CHAR FAR* String);
  24. #pragma aux ComWriteStr "ComWriteStr"                 \
  25.   parm [dx] [gs bx]                                   \
  26.   value [ax]                                          \
  27.   modify exact [ax bx cx si];
  28.  
  29. WORD16 ComWrite32(WORD16 Port, WORD32 Number, WORD16 Base, WORD16 Width);
  30. #pragma aux ComWrite32 "ComWrite32"                   \
  31.   parm [si] [dx ax] [bx] [di]                         \
  32.   value [ax]                                          \
  33.   modify exact [ax bx cx dx di si];
  34.  
  35.  
  36.  
  37. // COM Port debugging stream
  38. //
  39. // This is a structure (rather than a class) so that it can be statically
  40. // initialized at compile time.  If it had a constructor, then Watcom
  41. // would generate a function call which is expected to be called when the
  42. // runtime library starts up; however, because the runtime is not being
  43. // included, the constructor would never get called.
  44. //
  45. // These routines are only defined if DEBUG is defined at the time that
  46. // this header file is processed.  Otherwise, all of the inline functions
  47. // are defined as empty functions, so that production-level code is
  48. // generated.
  49.  
  50. // Stream type (public so that it can be statically initialized)
  51. struct COMStream
  52.   {
  53.   WORD16      Port;           // Base port address
  54.   WORD16      Base;           // Current numeric base setting
  55.   WORD16      Width;          // Current field width (integers only)
  56.   WORD16      Level;          // Current debugging level
  57.   WORD16      Mask;           // Debugging level mask
  58.   };
  59.  
  60. // Types for internal use by manipulators
  61. struct COMBase  { WORD16 Value; };
  62. struct COMWidth { WORD16 Value; };
  63. struct COMMask  { WORD16 Value; };
  64. enum   COMEndl  { endl };
  65. enum   COMLevel
  66.          {
  67.          ALL = 0xFFFF,
  68.          NONE = 0x0000,
  69.          FATAL = 0x8000,
  70.          ERROR = 0x4000,
  71.          WARNING = 0x2000,
  72.          SKELETON = 0x1000,
  73.          OPERATION = 0x0800,
  74.          VARIABLE = 0x0400,
  75.          USER9 = 0x0200,
  76.          USER8 = 0x0100,
  77.          USER7 = 0x0080,
  78.          USER6 = 0x0040,
  79.          USER5 = 0x0020,
  80.          USER4 = 0x0010,
  81.          USER3 = 0x0008,
  82.          USER2 = 0x0004,
  83.          USER1 = 0x0002,
  84.          USER0 = 0x0001,
  85.          };
  86.  
  87. // Aliases for standard bases
  88. #define       oct             setb(8)
  89. #define       dec             setb(10)
  90. #define       hex             setb(16)
  91.  
  92.  
  93. #if defined(DEBUG)
  94.  
  95. inline COMBase setb(WORD16 b = 10)
  96.   {
  97.   COMBase cb;
  98.   cb.Value = b;
  99.   return cb;
  100.   }
  101.  
  102. inline COMWidth setw(WORD16 w = 0)
  103.   {
  104.   COMWidth cw;
  105.   cw.Value = w;
  106.   return cw;
  107.   }
  108.  
  109. inline COMMask setm(WORD16 m = ALL)
  110.   {
  111.   COMMask cm;
  112.   cm.Value = m;
  113.   return cm;
  114.   }
  115.  
  116. inline COMStream& operator<<(COMStream& cs, COMBase b)
  117.   {
  118.   cs.Base = b.Value;
  119.   return cs;
  120.   }
  121.  
  122. inline COMStream& operator<<(COMStream& cs, COMWidth w)
  123.   {
  124.   cs.Width = w.Value;
  125.   return cs;
  126.   }
  127.  
  128. inline COMStream& operator<<(COMStream& cs, COMMask m)
  129.   {
  130.   cs.Mask = m.Value;
  131.   return cs;
  132.   }
  133.  
  134. inline COMStream& operator<<(COMStream& cs, COMLevel l)
  135.   {
  136.   cs.Level = l;
  137.   return cs;
  138.   }
  139.  
  140. inline COMStream& operator<<(COMStream& cs, COMEndl)
  141.   {
  142.   if (!(cs.Level & cs.Mask)) return cs;
  143.   ComWriteChar(cs.Port, '\r');
  144.   ComWriteChar(cs.Port, '\n');
  145.   return cs;
  146.   }
  147.  
  148. inline COMStream& operator<<(COMStream& cs, const CHAR FAR* s)
  149.   {
  150.   if (!(cs.Level & cs.Mask)) return cs;
  151.   ComWriteStr(cs.Port, s);
  152.   return cs;
  153.   }
  154.  
  155. inline COMStream& operator<<(COMStream& cs, CHAR c)
  156.   {
  157.   if (!(cs.Level & cs.Mask)) return cs;
  158.   ComWriteChar(cs.Port, c);
  159.   return cs;
  160.   }
  161.  
  162. inline COMStream& operator<<(COMStream& cs, unsigned short i)
  163.   {
  164.   if (!(cs.Level & cs.Mask)) return cs;
  165.   ComWrite32(cs.Port, i, cs.Base, cs.Width);
  166.   return cs;
  167.   }
  168.  
  169. inline COMStream& operator<<(COMStream& cs, signed short i)
  170.   {
  171.   if (!(cs.Level & cs.Mask)) return cs;
  172.   WORD16 width = cs.Width;
  173.   if (cs.Base == 10 && i < 0)
  174.     {
  175.     ComWriteChar(cs.Port, '-');
  176.     i = -i;
  177.     if (width == 1)
  178.       return cs;
  179.     if (width != 0)
  180.       width--;
  181.     }
  182.   ComWrite32(cs.Port, i, cs.Base, width);
  183.   return cs;
  184.   }
  185.  
  186. inline COMStream& operator<<(COMStream& cs, unsigned int i)
  187.   {
  188.   if (!(cs.Level & cs.Mask)) return cs;
  189.   ComWrite32(cs.Port, i, cs.Base, cs.Width);
  190.   return cs;
  191.   }
  192.  
  193. inline COMStream& operator<<(COMStream& cs, signed int i)
  194.   {
  195.   if (!(cs.Level & cs.Mask)) return cs;
  196.   WORD16 width = cs.Width;
  197.   if (cs.Base == 10 && i < 0)
  198.     {
  199.     ComWriteChar(cs.Port, '-');
  200.     i = -i;
  201.     if (width == 1)
  202.       return cs;
  203.     if (width != 0)
  204.       width--;
  205.     }
  206.   ComWrite32(cs.Port, i, cs.Base, width);
  207.   return cs;
  208.   }
  209.  
  210. inline COMStream& operator<<(COMStream& cs, unsigned long i)
  211.   {
  212.   if (!(cs.Level & cs.Mask)) return cs;
  213.   ComWrite32(cs.Port, i, cs.Base, cs.Width);
  214.   return cs;
  215.   }
  216.  
  217. inline COMStream& operator<<(COMStream& cs, signed long i)
  218.   {
  219.   if (!(cs.Level & cs.Mask)) return cs;
  220.   WORD16 width = cs.Width;
  221.   if (cs.Base == 10 && i < 0)
  222.     {
  223.     ComWriteChar(cs.Port, '-');
  224.     i = -i;
  225.     if (width == 1)
  226.       return cs;
  227.     if (width != 0)
  228.       width--;
  229.     }
  230.   ComWrite32(cs.Port, i, cs.Base, width);
  231.   return cs;
  232.   }
  233.  
  234. #else // DEBUG
  235.  
  236. inline COMEndl setb(WORD16 = 10)                              { return endl; }
  237. inline COMEndl setw(WORD16 = 0)                               { return endl; }
  238. inline COMEndl setm(WORD16 = ALL)                             { return endl; }
  239. inline COMStream& operator<<(COMStream& cs, COMBase)          { return cs; }
  240. inline COMStream& operator<<(COMStream& cs, COMWidth)         { return cs; }
  241. inline COMStream& operator<<(COMStream& cs, COMMask)          { return cs; }
  242. inline COMStream& operator<<(COMStream& cs, COMLevel)         { return cs; }
  243. inline COMStream& operator<<(COMStream& cs, COMEndl)          { return cs; }
  244. inline COMStream& operator<<(COMStream& cs, const CHAR FAR*)  { return cs; }
  245. inline COMStream& operator<<(COMStream& cs, CHAR)             { return cs; }
  246. inline COMStream& operator<<(COMStream& cs, unsigned short)   { return cs; }
  247. inline COMStream& operator<<(COMStream& cs, signed short)     { return cs; }
  248. inline COMStream& operator<<(COMStream& cs, unsigned int)     { return cs; }
  249. inline COMStream& operator<<(COMStream& cs, signed int)       { return cs; }
  250. inline COMStream& operator<<(COMStream& cs, unsigned long)    { return cs; }
  251. inline COMStream& operator<<(COMStream& cs, signed long)      { return cs; }
  252.  
  253. #endif // DEBUG
  254.  
  255.  
  256.  
  257. // Standard debugging streams
  258.  
  259. extern COMStream cdbg;        // Standard debugging stream
  260. extern COMStream ccom1;       // COM Port 1
  261. extern COMStream ccom2;       // COM Port 2
  262.  
  263.  
  264.  
  265. #endif // DevDebug_h
  266.