| 1 | /* $Id: cout.cpp,v 1.3 2000-09-02 21:08:13 bird Exp $
|
|---|
| 2 | *
|
|---|
| 3 | * cout - cout replacement.
|
|---|
| 4 | *
|
|---|
| 5 | * Note: use of cout is discurraged.
|
|---|
| 6 | *
|
|---|
| 7 | * Copyright (c) 1998-1999 knut st. osmundsen
|
|---|
| 8 | *
|
|---|
| 9 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 10 | *
|
|---|
| 11 | */
|
|---|
| 12 |
|
|---|
| 13 | /*******************************************************************************
|
|---|
| 14 | * Defined Constants *
|
|---|
| 15 | *******************************************************************************/
|
|---|
| 16 | #define INCL_DOSERRORS
|
|---|
| 17 | #define INCL_NOPMAPI
|
|---|
| 18 |
|
|---|
| 19 | /*******************************************************************************
|
|---|
| 20 | * Header Files *
|
|---|
| 21 | *******************************************************************************/
|
|---|
| 22 | #include <os2.h>
|
|---|
| 23 |
|
|---|
| 24 | #include <builtin.h>
|
|---|
| 25 | #include <stdarg.h>
|
|---|
| 26 |
|
|---|
| 27 | #include "devSegDf.h" /* Win32k segment definitions. */
|
|---|
| 28 | #include "cout.h"
|
|---|
| 29 | #include "options.h"
|
|---|
| 30 | #include "sprintf.h"
|
|---|
| 31 | #include "yield.h"
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 | /*******************************************************************************
|
|---|
| 35 | * Global Variables *
|
|---|
| 36 | *******************************************************************************/
|
|---|
| 37 | kLog _log_;
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 | /** Constructor -> constructor(..) */
|
|---|
| 41 | kLog::kLog()
|
|---|
| 42 | {
|
|---|
| 43 | constructor();
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 | /** Destructor */
|
|---|
| 48 | kLog::~kLog()
|
|---|
| 49 | {
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 | /**
|
|---|
| 54 | * Manual constructor.
|
|---|
| 55 | * @param ulPort Portaddress for the (com)port to use. default: OUTPUT_COM2
|
|---|
| 56 | * @remark (OUTPUT_COM1 and OUTPUT_COM2 are defined in the header file.)
|
|---|
| 57 | */
|
|---|
| 58 | void kLog::constructor(ULONG ulPort /*= OUTPUT_COM2*/)
|
|---|
| 59 | {
|
|---|
| 60 | fHex = TRUE;
|
|---|
| 61 | this->ulPort = ulPort;
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 | /**
|
|---|
| 66 | * Put a single char to the com-port.
|
|---|
| 67 | * @param ch Char to put.
|
|---|
| 68 | */
|
|---|
| 69 | void kLog::putch(char ch)
|
|---|
| 70 | {
|
|---|
| 71 | if (!options.fLogging)
|
|---|
| 72 | return;
|
|---|
| 73 |
|
|---|
| 74 | #if !defined(RING0) || defined(RING0_DEBUG_IN_RING3)
|
|---|
| 75 | putc(ch, stdout);
|
|---|
| 76 | #else
|
|---|
| 77 | while (!(_inp(ulPort + 5) & 0x20)); /* waits for port To Be ready */
|
|---|
| 78 | _outp(ulPort, ch); /* put char */
|
|---|
| 79 | #endif
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 | /**
|
|---|
| 84 | * Puts a string to the comport.
|
|---|
| 85 | * @param psz String to put.
|
|---|
| 86 | * @remark Note that this function may yield the CPU.
|
|---|
| 87 | */
|
|---|
| 88 | void kLog::putstr(const char *psz)
|
|---|
| 89 | {
|
|---|
| 90 | int cch = 0;
|
|---|
| 91 |
|
|---|
| 92 | while (*psz != '\0')
|
|---|
| 93 | {
|
|---|
| 94 | while (!(_inp(ulPort + 5) & 0x20)); /* waits for port To Be ready */
|
|---|
| 95 | _outp(ulPort, *psz); /* put char and inc pointer */
|
|---|
| 96 |
|
|---|
| 97 | /* new line fix */
|
|---|
| 98 | if (psz[1] == '\n' && psz[0] != '\r')
|
|---|
| 99 | {
|
|---|
| 100 | while (!(_inp(ulPort + 5) & 0x20)); /* waits for port To Be ready */
|
|---|
| 101 | _outp(ulPort, '\r'); /* put char and inc pointer */
|
|---|
| 102 | cch++;
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | psz++;
|
|---|
| 106 | if ((++cch % 3) == 0) /* 9600 bit/s -> 1066 bytes (9bit) -> 3 chars takes 3.2 ms to send */
|
|---|
| 107 | Yield();
|
|---|
| 108 | }
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 | /**
|
|---|
| 113 | * Put an unsigned long value to the comport.
|
|---|
| 114 | * @returns Reference to this object.
|
|---|
| 115 | * @param ul Number to put.
|
|---|
| 116 | * @remark May yield the CPU.
|
|---|
| 117 | */
|
|---|
| 118 | kLog& kLog::operator<<(unsigned long ul)
|
|---|
| 119 | {
|
|---|
| 120 | sprintf(szBuffer, fHex ? "%lx" : "%lu", ul);
|
|---|
| 121 | putstr(szBuffer);
|
|---|
| 122 | return *this;
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 | /**
|
|---|
| 127 | * Put a pointer value to the comport.
|
|---|
| 128 | * @returns Reference to this object.
|
|---|
| 129 | * @param p Pointer to put.
|
|---|
| 130 | * @remark May yield the CPU.
|
|---|
| 131 | */
|
|---|
| 132 | kLog& kLog::operator<<(const void *pv)
|
|---|
| 133 | {
|
|---|
| 134 | if (pv != NULL)
|
|---|
| 135 | {
|
|---|
| 136 | sprintf(szBuffer,"%#.8lx", pv);
|
|---|
| 137 | putstr(szBuffer);
|
|---|
| 138 | }
|
|---|
| 139 | else
|
|---|
| 140 | putstr("(null)");
|
|---|
| 141 | return *this;
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 | /**
|
|---|
| 147 | * Put a signed long value to the comport.
|
|---|
| 148 | * @returns Reference to this object.
|
|---|
| 149 | * @param l Number to put.
|
|---|
| 150 | * @remark May yield the CPU.
|
|---|
| 151 | */
|
|---|
| 152 | kLog& kLog::operator<<(long l)
|
|---|
| 153 | {
|
|---|
| 154 | sprintf(szBuffer, fHex ? "%lx" : "%ld", l);
|
|---|
| 155 | putstr(szBuffer);
|
|---|
| 156 | return *this;
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 | /**
|
|---|
| 161 | * Set format.
|
|---|
| 162 | * @param hex Hex indicator.
|
|---|
| 163 | * @param ignored This parameter is ignored.
|
|---|
| 164 | */
|
|---|
| 165 | void kLog::setf(int fHex, int ignored)
|
|---|
| 166 | {
|
|---|
| 167 | if (fHex == 1 || fHex == 0)
|
|---|
| 168 | this->fHex = fHex;
|
|---|
| 169 | }
|
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 | /**
|
|---|
| 173 | * Put a char to the comport.
|
|---|
| 174 | * @returns Reference to this object.
|
|---|
| 175 | * @param c Char to put.
|
|---|
| 176 | */
|
|---|
| 177 | kLog& kLog::operator<<(char c)
|
|---|
| 178 | {
|
|---|
| 179 | kLog::putch(c);
|
|---|
| 180 | return *this;
|
|---|
| 181 | }
|
|---|
| 182 |
|
|---|
| 183 |
|
|---|
| 184 | /**
|
|---|
| 185 | * Put a string to the COM-port.
|
|---|
| 186 | * @returns Reference to this object.
|
|---|
| 187 | * @param psz Pointer to string.
|
|---|
| 188 | * @remark May yield the CPU.
|
|---|
| 189 | */
|
|---|
| 190 | kLog& kLog::operator<<(const char *psz)
|
|---|
| 191 | {
|
|---|
| 192 | kLog::putstr(psz);
|
|---|
| 193 | return *this;
|
|---|
| 194 | }
|
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 | /**
|
|---|
| 198 | * Put a string to the COM-port.
|
|---|
| 199 | * @returns Reference to this object.
|
|---|
| 200 | * @param psz Pointer to string.
|
|---|
| 201 | * @remark May yield the CPU.
|
|---|
| 202 | */
|
|---|
| 203 | kLog& kLog::operator<<(const signed char *psz)
|
|---|
| 204 | {
|
|---|
| 205 | kLog::putstr((char*)psz);
|
|---|
| 206 | return *this;
|
|---|
| 207 | }
|
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 | /**
|
|---|
| 211 | * Put a string to the COM-port.
|
|---|
| 212 | * @returns Reference to this object.
|
|---|
| 213 | * @param psz Pointer to string.
|
|---|
| 214 | * @remark May yield the CPU.
|
|---|
| 215 | */
|
|---|
| 216 | kLog& kLog::operator<<(const unsigned char *psz)
|
|---|
| 217 | {
|
|---|
| 218 | kLog::putstr((char*)psz);
|
|---|
| 219 | return *this;
|
|---|
| 220 | }
|
|---|
| 221 |
|
|---|
| 222 |
|
|---|
| 223 | /**
|
|---|
| 224 | * Put an (signed) int to the COM-port.
|
|---|
| 225 | * @returns Reference to this object.
|
|---|
| 226 | * @param a Number to put.
|
|---|
| 227 | * @remark May yield the CPU.
|
|---|
| 228 | */
|
|---|
| 229 | kLog& kLog::operator<<(int a)
|
|---|
| 230 | {
|
|---|
| 231 | return *this << (long)a;
|
|---|
| 232 | }
|
|---|
| 233 |
|
|---|
| 234 |
|
|---|
| 235 | /**
|
|---|
| 236 | * Put an unsigned int to the COM-port.
|
|---|
| 237 | * @returns Reference to this object.
|
|---|
| 238 | * @param a Number to put.
|
|---|
| 239 | * @remark May yield the CPU.
|
|---|
| 240 | */
|
|---|
| 241 | kLog& kLog::operator<<(unsigned int a)
|
|---|
| 242 | {
|
|---|
| 243 | return *this << (unsigned long)a;
|
|---|
| 244 | }
|
|---|
| 245 |
|
|---|
| 246 |
|
|---|
| 247 | /**
|
|---|
| 248 | * Put a signed short int to the COM-port.
|
|---|
| 249 | * @returns Reference to this object.
|
|---|
| 250 | * @param a Number to put.
|
|---|
| 251 | * @remark May yield the CPU.
|
|---|
| 252 | */
|
|---|
| 253 | kLog& kLog::operator<<(short i)
|
|---|
| 254 | {
|
|---|
| 255 | return *this << (long)i;
|
|---|
| 256 | }
|
|---|
| 257 |
|
|---|
| 258 |
|
|---|
| 259 | /**
|
|---|
| 260 | * Put a unsigned short int to the COM-port.
|
|---|
| 261 | * @returns Reference to this object.
|
|---|
| 262 | * @param a Number to put.
|
|---|
| 263 | * @remark May yield the CPU.
|
|---|
| 264 | */
|
|---|
| 265 | kLog& kLog::operator<<(unsigned short i)
|
|---|
| 266 | {
|
|---|
| 267 | return *this << (unsigned long)i;
|
|---|
| 268 | }
|
|---|
| 269 |
|
|---|
| 270 |
|
|---|
| 271 | /**
|
|---|
| 272 | * Init function for cout.
|
|---|
| 273 | * @param ulPort Portaddress for the (com)port to use. default: OUTPUT_COM2
|
|---|
| 274 | * @remark (OUTPUT_COM1 and OUTPUT_COM2 are defined in the header file.)
|
|---|
| 275 | */
|
|---|
| 276 | void coutInit(USHORT usCom)
|
|---|
| 277 | {
|
|---|
| 278 | _log_.constructor(usCom);
|
|---|
| 279 | }
|
|---|
| 280 |
|
|---|
| 281 |
|
|---|