| 1 | /*
|
|---|
| 2 | * COM port debugging functions
|
|---|
| 3 | *
|
|---|
| 4 | * (C) 2000-2002 InnoTek Systemberatung GmbH
|
|---|
| 5 | * (C) 2000-2001 Sander van Leeuwen (sandervl@xs4all.nl)
|
|---|
| 6 | *
|
|---|
| 7 | * This program is free software; you can redistribute it and/or
|
|---|
| 8 | * modify it under the terms of the GNU General Public License as
|
|---|
| 9 | * published by the Free Software Foundation; either version 2 of
|
|---|
| 10 | * the License, or (at your option) any later version.
|
|---|
| 11 | *
|
|---|
| 12 | * This program is distributed in the hope that it will be useful,
|
|---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 15 | * GNU General Public License for more details.
|
|---|
| 16 | *
|
|---|
| 17 | * You should have received a copy of the GNU General Public
|
|---|
| 18 | * License along with this program; if not, write to the Free
|
|---|
| 19 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
|
|---|
| 20 | * USA.
|
|---|
| 21 | *
|
|---|
| 22 | */
|
|---|
| 23 | #define INCL_NOPMAPI
|
|---|
| 24 | #define INCL_DOSERRORS // for ERROR_INVALID_FUNCTION
|
|---|
| 25 | #include <os2.h>
|
|---|
| 26 |
|
|---|
| 27 | #include <string.h>
|
|---|
| 28 |
|
|---|
| 29 | #define CR 0x0d
|
|---|
| 30 | #define LF 0x0a
|
|---|
| 31 |
|
|---|
| 32 | #define LEADING_ZEROES 0x8000
|
|---|
| 33 | #define SIGNIFICANT_FIELD 0x0007
|
|---|
| 34 |
|
|---|
| 35 | BOOL fLineTerminate=TRUE;
|
|---|
| 36 | int DebugLevel = 1;
|
|---|
| 37 |
|
|---|
| 38 | extern int wrOffset;
|
|---|
| 39 | extern char *szprintBuf;
|
|---|
| 40 | extern int max_buf_size;
|
|---|
| 41 |
|
|---|
| 42 | char hextab[]="0123456789ABCDEF";
|
|---|
| 43 |
|
|---|
| 44 | //-------------------- DecLongToASCII -
|
|---|
| 45 | char * DecLongToASCII(char *StrPtr, ULONG lDecVal,USHORT Option)
|
|---|
| 46 | {
|
|---|
| 47 | BOOL fNonZero=FALSE;
|
|---|
| 48 | ULONG Digit;
|
|---|
| 49 | ULONG Power=1000000000; // 1 billion
|
|---|
| 50 | LONG lVal = (LONG)lDecVal;
|
|---|
| 51 |
|
|---|
| 52 | if(lVal < 0) {
|
|---|
| 53 | *StrPtr = '-';
|
|---|
| 54 | StrPtr++;
|
|---|
| 55 | lDecVal = -lDecVal;
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | while (Power)
|
|---|
| 59 | {
|
|---|
| 60 | Digit=0; // Digit=lDecVal/Power
|
|---|
| 61 | while (lDecVal >=Power) // replaced with while loop
|
|---|
| 62 | {
|
|---|
| 63 | Digit++;
|
|---|
| 64 | lDecVal-=Power;
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | if (Digit)
|
|---|
| 68 | fNonZero=TRUE;
|
|---|
| 69 |
|
|---|
| 70 | if (Digit ||
|
|---|
| 71 | fNonZero ||
|
|---|
| 72 | (Option & LEADING_ZEROES) ||
|
|---|
| 73 | ((Power==1) && (fNonZero==FALSE)))
|
|---|
| 74 | {
|
|---|
| 75 | *StrPtr=(char)('0'+Digit);
|
|---|
| 76 | StrPtr++;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | if (Power==1000000000) // 1 billion
|
|---|
| 80 | Power=100000000;
|
|---|
| 81 | else if (Power==100000000)
|
|---|
| 82 | Power=10000000;
|
|---|
| 83 | else if (Power==10000000)
|
|---|
| 84 | Power=1000000;
|
|---|
| 85 | else if (Power==1000000)
|
|---|
| 86 | Power=100000;
|
|---|
| 87 | else if (Power==100000)
|
|---|
| 88 | Power=10000;
|
|---|
| 89 | else if (Power==10000)
|
|---|
| 90 | Power=1000;
|
|---|
| 91 | else if (Power==1000)
|
|---|
| 92 | Power=100;
|
|---|
| 93 | else if (Power==100)
|
|---|
| 94 | Power=10;
|
|---|
| 95 | else if (Power==10)
|
|---|
| 96 | Power=1;
|
|---|
| 97 | else
|
|---|
| 98 | Power=0;
|
|---|
| 99 | }
|
|---|
| 100 | return (StrPtr);
|
|---|
| 101 | }
|
|---|
| 102 | //-------------------- HexWordToASCII -
|
|---|
| 103 | //-------------------- HexLongToASCII -
|
|---|
| 104 | char * HexLongToASCII(char *StrPtr, ULONG wHexVal, USHORT Option)
|
|---|
| 105 | {
|
|---|
| 106 | BOOL fNonZero=FALSE;
|
|---|
| 107 | ULONG Digit;
|
|---|
| 108 | ULONG Power=0xF0000000;
|
|---|
| 109 | ULONG ShiftVal=28;
|
|---|
| 110 |
|
|---|
| 111 | while (Power)
|
|---|
| 112 | {
|
|---|
| 113 | Digit=(wHexVal & Power)>>ShiftVal;
|
|---|
| 114 | if (Digit)
|
|---|
| 115 | fNonZero=TRUE;
|
|---|
| 116 |
|
|---|
| 117 | if (Digit ||
|
|---|
| 118 | fNonZero ||
|
|---|
| 119 | (Option & LEADING_ZEROES) ||
|
|---|
| 120 | ((Power==0x0F) && (fNonZero==FALSE)))
|
|---|
| 121 | *StrPtr++=hextab[Digit];
|
|---|
| 122 |
|
|---|
| 123 | if (Power==0xF0000000) // 1 billion
|
|---|
| 124 | Power=0xF000000;
|
|---|
| 125 | else if (Power==0xF000000)
|
|---|
| 126 | Power=0xF00000;
|
|---|
| 127 | else if (Power==0xF00000)
|
|---|
| 128 | Power=0xF0000;
|
|---|
| 129 | else if (Power==0xF0000)
|
|---|
| 130 | Power=0xF000;
|
|---|
| 131 | else if (Power==0xF000)
|
|---|
| 132 | Power=0xF00;
|
|---|
| 133 | else if (Power==0xF00)
|
|---|
| 134 | Power=0xF0;
|
|---|
| 135 | else if (Power==0xF0)
|
|---|
| 136 | Power=0xF;
|
|---|
| 137 | else Power=0;
|
|---|
| 138 |
|
|---|
| 139 | ShiftVal-=4;
|
|---|
| 140 | } // end while
|
|---|
| 141 |
|
|---|
| 142 | return (StrPtr);
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | #define DEBUG1
|
|---|
| 146 |
|
|---|
| 147 | #ifdef DEBUG1
|
|---|
| 148 | char BuildString[1024];
|
|---|
| 149 | #endif // DEBUG
|
|---|
| 150 |
|
|---|
| 151 | //------------------------- PrintfOut -
|
|---|
| 152 | void _cdecl DPD(int level, char *DbgStr, ...)
|
|---|
| 153 | {
|
|---|
| 154 | #ifdef DEBUG1
|
|---|
| 155 | char *BuildPtr=BuildString;
|
|---|
| 156 | char *pStr=(char *) DbgStr;
|
|---|
| 157 | char *SubStr;
|
|---|
| 158 | union {
|
|---|
| 159 | void *VoidPtr;
|
|---|
| 160 | USHORT *WordPtr;
|
|---|
| 161 | ULONG *LongPtr;
|
|---|
| 162 | ULONG *StringPtr;
|
|---|
| 163 | } Parm;
|
|---|
| 164 | USHORT wBuildOption;
|
|---|
| 165 |
|
|---|
| 166 | Parm.VoidPtr=(void *) &DbgStr;
|
|---|
| 167 | Parm.StringPtr++; // skip size of string pointer
|
|---|
| 168 |
|
|---|
| 169 | while (*pStr)
|
|---|
| 170 | {
|
|---|
| 171 | // don't overflow target
|
|---|
| 172 | if (BuildPtr >= (char *) &BuildString[1024-2])
|
|---|
| 173 | break;
|
|---|
| 174 |
|
|---|
| 175 | switch (*pStr)
|
|---|
| 176 | {
|
|---|
| 177 | case '%':
|
|---|
| 178 | wBuildOption=0;
|
|---|
| 179 | pStr++;
|
|---|
| 180 | if (*pStr=='0')
|
|---|
| 181 | {
|
|---|
| 182 | wBuildOption|=LEADING_ZEROES;
|
|---|
| 183 | pStr++;
|
|---|
| 184 | }
|
|---|
| 185 | if (*pStr=='u') // always unsigned
|
|---|
| 186 | pStr++;
|
|---|
| 187 | if (*pStr=='#')
|
|---|
| 188 | pStr++;
|
|---|
| 189 |
|
|---|
| 190 | switch(*pStr)
|
|---|
| 191 | {
|
|---|
| 192 | case 'x':
|
|---|
| 193 | case 'X':
|
|---|
| 194 | case 'p':
|
|---|
| 195 | case 'P':
|
|---|
| 196 | BuildPtr=HexLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
|
|---|
| 197 | pStr++;
|
|---|
| 198 | continue;
|
|---|
| 199 |
|
|---|
| 200 | case 'd':
|
|---|
| 201 | BuildPtr=DecLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
|
|---|
| 202 | pStr++;
|
|---|
| 203 | continue;
|
|---|
| 204 |
|
|---|
| 205 | case 's':
|
|---|
| 206 | SubStr=(char *)*Parm.StringPtr;
|
|---|
| 207 | while (*BuildPtr++ = *SubStr++);
|
|---|
| 208 | Parm.StringPtr++;
|
|---|
| 209 | BuildPtr--; // remove the \0
|
|---|
| 210 | pStr++;
|
|---|
| 211 | continue;
|
|---|
| 212 |
|
|---|
| 213 | case 'l':
|
|---|
| 214 | pStr++;
|
|---|
| 215 | switch (*pStr)
|
|---|
| 216 | {
|
|---|
| 217 | case 'x':
|
|---|
| 218 | case 'X':
|
|---|
| 219 | BuildPtr=HexLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
|
|---|
| 220 | pStr++;
|
|---|
| 221 | continue;
|
|---|
| 222 |
|
|---|
| 223 | case 'd':
|
|---|
| 224 | BuildPtr=DecLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
|
|---|
| 225 | pStr++;
|
|---|
| 226 | continue;
|
|---|
| 227 | } // end switch
|
|---|
| 228 | continue; // dunno what he wants
|
|---|
| 229 |
|
|---|
| 230 | case 0:
|
|---|
| 231 | continue;
|
|---|
| 232 | } // end switch
|
|---|
| 233 | break;
|
|---|
| 234 |
|
|---|
| 235 | case '\\':
|
|---|
| 236 | pStr++;
|
|---|
| 237 | switch (*pStr)
|
|---|
| 238 | {
|
|---|
| 239 | case 'n':
|
|---|
| 240 | *BuildPtr++=LF;
|
|---|
| 241 | pStr++;
|
|---|
| 242 | continue;
|
|---|
| 243 |
|
|---|
| 244 | case 'r':
|
|---|
| 245 | *BuildPtr++=CR;
|
|---|
| 246 | pStr++;
|
|---|
| 247 | continue;
|
|---|
| 248 |
|
|---|
| 249 | case 0:
|
|---|
| 250 | continue;
|
|---|
| 251 | break;
|
|---|
| 252 | } // end switch
|
|---|
| 253 |
|
|---|
| 254 | break;
|
|---|
| 255 | } // end switch
|
|---|
| 256 |
|
|---|
| 257 | *BuildPtr++=*pStr++;
|
|---|
| 258 | } // end while
|
|---|
| 259 |
|
|---|
| 260 | *BuildPtr=0; // cauterize the string
|
|---|
| 261 | StringOut((char *) BuildString); // print to comm port
|
|---|
| 262 | #endif //DEBUG
|
|---|
| 263 | }
|
|---|
| 264 |
|
|---|
| 265 |
|
|---|
| 266 | void _cdecl DPE(char *DbgStr, ...)
|
|---|
| 267 | {
|
|---|
| 268 | #ifdef DEBUG1
|
|---|
| 269 | char *BuildPtr=BuildString;
|
|---|
| 270 | char *pStr = (char *) DbgStr;
|
|---|
| 271 | char *SubStr;
|
|---|
| 272 | union {
|
|---|
| 273 | void *VoidPtr;
|
|---|
| 274 | USHORT *WordPtr;
|
|---|
| 275 | ULONG *LongPtr;
|
|---|
| 276 | ULONG *StringPtr;
|
|---|
| 277 | } Parm;
|
|---|
| 278 | USHORT wBuildOption;
|
|---|
| 279 |
|
|---|
| 280 | Parm.VoidPtr=(void *) &DbgStr;
|
|---|
| 281 | Parm.StringPtr++; // skip size of string pointer
|
|---|
| 282 |
|
|---|
| 283 | while (*pStr)
|
|---|
| 284 | {
|
|---|
| 285 | // don't overflow target
|
|---|
| 286 | if (BuildPtr >= (char *) &BuildString[1024-2])
|
|---|
| 287 | break;
|
|---|
| 288 |
|
|---|
| 289 | switch (*pStr)
|
|---|
| 290 | {
|
|---|
| 291 | case '%':
|
|---|
| 292 | wBuildOption=0;
|
|---|
| 293 | pStr++;
|
|---|
| 294 | if (*pStr=='0')
|
|---|
| 295 | {
|
|---|
| 296 | wBuildOption|=LEADING_ZEROES;
|
|---|
| 297 | pStr++;
|
|---|
| 298 | }
|
|---|
| 299 | // if (*pStr=='u') // always unsigned
|
|---|
| 300 | // pStr++;
|
|---|
| 301 |
|
|---|
| 302 | switch(*pStr)
|
|---|
| 303 | {
|
|---|
| 304 | case 'x':
|
|---|
| 305 | case 'X':
|
|---|
| 306 | case 'p':
|
|---|
| 307 | case 'P':
|
|---|
| 308 | BuildPtr=HexLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
|
|---|
| 309 | pStr++;
|
|---|
| 310 | continue;
|
|---|
| 311 |
|
|---|
| 312 | case 'd':
|
|---|
| 313 | case 'u':
|
|---|
| 314 | BuildPtr=DecLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
|
|---|
| 315 | pStr++;
|
|---|
| 316 | continue;
|
|---|
| 317 |
|
|---|
| 318 | case 's':
|
|---|
| 319 | SubStr=(char *)*Parm.StringPtr;
|
|---|
| 320 | while (*BuildPtr++ = *SubStr++);
|
|---|
| 321 | Parm.StringPtr++;
|
|---|
| 322 | BuildPtr--; // remove the \0
|
|---|
| 323 | pStr++;
|
|---|
| 324 | continue;
|
|---|
| 325 |
|
|---|
| 326 | case 'c':
|
|---|
| 327 | *BuildPtr++ = (char)*Parm.LongPtr;
|
|---|
| 328 | Parm.LongPtr++;
|
|---|
| 329 | pStr++;
|
|---|
| 330 | continue;
|
|---|
| 331 |
|
|---|
| 332 | case 'l':
|
|---|
| 333 | pStr++;
|
|---|
| 334 | switch (*pStr)
|
|---|
| 335 | {
|
|---|
| 336 | case 'x':
|
|---|
| 337 | case 'X':
|
|---|
| 338 | BuildPtr=HexLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
|
|---|
| 339 | pStr++;
|
|---|
| 340 | continue;
|
|---|
| 341 |
|
|---|
| 342 | case 'd':
|
|---|
| 343 | BuildPtr=DecLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
|
|---|
| 344 | pStr++;
|
|---|
| 345 | continue;
|
|---|
| 346 | } // end switch
|
|---|
| 347 | continue; // dunno what he wants
|
|---|
| 348 |
|
|---|
| 349 | case 0:
|
|---|
| 350 | continue;
|
|---|
| 351 | } // end switch
|
|---|
| 352 | break;
|
|---|
| 353 |
|
|---|
| 354 | case '\\':
|
|---|
| 355 | pStr++;
|
|---|
| 356 | switch (*pStr)
|
|---|
| 357 | {
|
|---|
| 358 | case 'n':
|
|---|
| 359 | *BuildPtr++=LF;
|
|---|
| 360 | pStr++;
|
|---|
| 361 | continue;
|
|---|
| 362 |
|
|---|
| 363 | case 'r':
|
|---|
| 364 | *BuildPtr++=CR;
|
|---|
| 365 | pStr++;
|
|---|
| 366 | continue;
|
|---|
| 367 |
|
|---|
| 368 | case 0:
|
|---|
| 369 | continue;
|
|---|
| 370 | break;
|
|---|
| 371 | } // end switch
|
|---|
| 372 |
|
|---|
| 373 | break;
|
|---|
| 374 | } // end switch
|
|---|
| 375 |
|
|---|
| 376 | *BuildPtr++=*pStr++;
|
|---|
| 377 | } // end while
|
|---|
| 378 |
|
|---|
| 379 | *BuildPtr=0; // cauterize the string
|
|---|
| 380 | StringOut((char *) BuildString); // print to comm port
|
|---|
| 381 | #endif //DEBUG
|
|---|
| 382 | }
|
|---|
| 383 |
|
|---|
| 384 | struct snd_info_buffer {
|
|---|
| 385 | char *buffer; /* pointer to begin of buffer */
|
|---|
| 386 | char *curr; /* current position in buffer */
|
|---|
| 387 | unsigned long size; /* current size */
|
|---|
| 388 | unsigned long len; /* total length of buffer */
|
|---|
| 389 | int stop; /* stop flag */
|
|---|
| 390 | int error; /* error code */
|
|---|
| 391 | };
|
|---|
| 392 |
|
|---|
| 393 | typedef struct snd_info_buffer snd_info_buffer_t;
|
|---|
| 394 |
|
|---|
| 395 | int snd_iprintf(snd_info_buffer_t * buffer, char *fmt,...)
|
|---|
| 396 | {
|
|---|
| 397 | char *BuildPtr=buffer->curr;
|
|---|
| 398 | char *pStr=(char *) fmt;
|
|---|
| 399 | char *SubStr;
|
|---|
| 400 | int res;
|
|---|
| 401 | union {
|
|---|
| 402 | void *VoidPtr;
|
|---|
| 403 | USHORT *WordPtr;
|
|---|
| 404 | ULONG *LongPtr;
|
|---|
| 405 | ULONG *StringPtr;
|
|---|
| 406 | } Parm;
|
|---|
| 407 | USHORT wBuildOption;
|
|---|
| 408 |
|
|---|
| 409 | Parm.VoidPtr=(void *) &fmt;
|
|---|
| 410 | Parm.StringPtr++; // skip size of string pointer
|
|---|
| 411 |
|
|---|
| 412 | if (buffer->stop || buffer->error)
|
|---|
| 413 | return 0;
|
|---|
| 414 |
|
|---|
| 415 | while (*pStr)
|
|---|
| 416 | {
|
|---|
| 417 | // don't overflow target
|
|---|
| 418 | if (BuildPtr >= (char *) &buffer->curr[buffer->len - 4])
|
|---|
| 419 | break;
|
|---|
| 420 |
|
|---|
| 421 | switch (*pStr)
|
|---|
| 422 | {
|
|---|
| 423 | case '%':
|
|---|
| 424 | wBuildOption=0;
|
|---|
| 425 | pStr++;
|
|---|
| 426 | if (*pStr=='0')
|
|---|
| 427 | {
|
|---|
| 428 | wBuildOption|=LEADING_ZEROES;
|
|---|
| 429 | pStr++;
|
|---|
| 430 | }
|
|---|
| 431 | // if (*pStr=='u') // always unsigned
|
|---|
| 432 | // pStr++;
|
|---|
| 433 | if (*pStr=='#')
|
|---|
| 434 | pStr++;
|
|---|
| 435 |
|
|---|
| 436 | switch(*pStr)
|
|---|
| 437 | {
|
|---|
| 438 | case 'x':
|
|---|
| 439 | case 'X':
|
|---|
| 440 | case 'p':
|
|---|
| 441 | case 'P':
|
|---|
| 442 | BuildPtr=HexLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
|
|---|
| 443 | pStr++;
|
|---|
| 444 | continue;
|
|---|
| 445 |
|
|---|
| 446 | case 'd':
|
|---|
| 447 | case 'u':
|
|---|
| 448 | BuildPtr=DecLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
|
|---|
| 449 | pStr++;
|
|---|
| 450 | continue;
|
|---|
| 451 |
|
|---|
| 452 | case 's':
|
|---|
| 453 | SubStr=(char *)*Parm.StringPtr;
|
|---|
| 454 | while (*BuildPtr++ = *SubStr++);
|
|---|
| 455 | Parm.StringPtr++;
|
|---|
| 456 | BuildPtr--; // remove the \0
|
|---|
| 457 | pStr++;
|
|---|
| 458 | continue;
|
|---|
| 459 |
|
|---|
| 460 | case 'c':
|
|---|
| 461 | *BuildPtr++ = (char)*Parm.LongPtr;
|
|---|
| 462 | Parm.LongPtr++;
|
|---|
| 463 | pStr++;
|
|---|
| 464 | continue;
|
|---|
| 465 |
|
|---|
| 466 | case 'l':
|
|---|
| 467 | pStr++;
|
|---|
| 468 | switch (*pStr)
|
|---|
| 469 | {
|
|---|
| 470 | case 'x':
|
|---|
| 471 | case 'X':
|
|---|
| 472 | BuildPtr=HexLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
|
|---|
| 473 | pStr++;
|
|---|
| 474 | continue;
|
|---|
| 475 |
|
|---|
| 476 | case 'd':
|
|---|
| 477 | BuildPtr=DecLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
|
|---|
| 478 | pStr++;
|
|---|
| 479 | continue;
|
|---|
| 480 | } // end switch
|
|---|
| 481 | continue; // dunno what he wants
|
|---|
| 482 |
|
|---|
| 483 | case 0:
|
|---|
| 484 | continue;
|
|---|
| 485 | } // end switch
|
|---|
| 486 | break;
|
|---|
| 487 |
|
|---|
| 488 | case '\\':
|
|---|
| 489 | pStr++;
|
|---|
| 490 | switch (*pStr)
|
|---|
| 491 | {
|
|---|
| 492 | case 'n':
|
|---|
| 493 | *BuildPtr++=LF;
|
|---|
| 494 | pStr++;
|
|---|
| 495 | continue;
|
|---|
| 496 |
|
|---|
| 497 | case 'r':
|
|---|
| 498 | *BuildPtr++=CR;
|
|---|
| 499 | pStr++;
|
|---|
| 500 | continue;
|
|---|
| 501 |
|
|---|
| 502 | case 0:
|
|---|
| 503 | continue;
|
|---|
| 504 | break;
|
|---|
| 505 | } // end switch
|
|---|
| 506 |
|
|---|
| 507 | break;
|
|---|
| 508 | } // end switch
|
|---|
| 509 |
|
|---|
| 510 | *BuildPtr++=*pStr++;
|
|---|
| 511 | } // end while
|
|---|
| 512 |
|
|---|
| 513 | *BuildPtr=0; // cauterize the string
|
|---|
| 514 |
|
|---|
| 515 | res = strlen(buffer->curr);
|
|---|
| 516 | if (buffer->size + res >= buffer->len) {
|
|---|
| 517 | buffer->stop = 1;
|
|---|
| 518 | return 0;
|
|---|
| 519 | }
|
|---|
| 520 | buffer->curr += res;
|
|---|
| 521 | buffer->size += res;
|
|---|
| 522 | return res;
|
|---|
| 523 | }
|
|---|
| 524 |
|
|---|
| 525 | #ifdef DEBUG1
|
|---|
| 526 | //------------------------- StringOut --------------------------//
|
|---|
| 527 |
|
|---|
| 528 | #define VMDHA_FIXED 0x0002
|
|---|
| 529 |
|
|---|
| 530 | extern APIRET VMAlloc(ULONG size, ULONG flags, char NEAR* *pAddr);
|
|---|
| 531 |
|
|---|
| 532 | /**
|
|---|
| 533 | * Finds the length of a string up to cchMax.
|
|---|
| 534 | * @returns Length.
|
|---|
| 535 | * @param psz Pointer to string.
|
|---|
| 536 | * @param cchMax Max length.
|
|---|
| 537 | */
|
|---|
| 538 | static unsigned _strnlen(const char *psz, unsigned cchMax)
|
|---|
| 539 | {
|
|---|
| 540 | const char *pszC = psz;
|
|---|
| 541 |
|
|---|
| 542 | while (cchMax-- > 0 && *psz != '\0')
|
|---|
| 543 | psz++;
|
|---|
| 544 |
|
|---|
| 545 | return psz - pszC;
|
|---|
| 546 | }
|
|---|
| 547 |
|
|---|
| 548 | void StringOut(char *DbgStr)
|
|---|
| 549 | {
|
|---|
| 550 | int len;
|
|---|
| 551 | #ifdef DEBUG9
|
|---|
| 552 | int i;
|
|---|
| 553 | #endif /* DEBUG9 */
|
|---|
| 554 |
|
|---|
| 555 | len= _strnlen( DbgStr, 1024 );
|
|---|
| 556 | /*
|
|---|
| 557 | while (*DbgStr)
|
|---|
| 558 | CharOut(*DbgStr++);
|
|---|
| 559 | */
|
|---|
| 560 | #ifdef DEBUG9
|
|---|
| 561 | for( i= 0; i < len; i++ )
|
|---|
| 562 | CharOut( DbgStr[i] );
|
|---|
| 563 |
|
|---|
| 564 | if (fLineTerminate)
|
|---|
| 565 | {
|
|---|
| 566 | CharOut(CR); // append carriage return,
|
|---|
| 567 | CharOut(LF); // linefeed
|
|---|
| 568 | }
|
|---|
| 569 | #endif
|
|---|
| 570 | if( szprintBuf == 0 )
|
|---|
| 571 | {
|
|---|
| 572 | VMAlloc( max_buf_size, VMDHA_FIXED, &szprintBuf );
|
|---|
| 573 | if( szprintBuf )
|
|---|
| 574 | memset( szprintBuf, 0, max_buf_size );
|
|---|
| 575 | wrOffset= 0;
|
|---|
| 576 | }
|
|---|
| 577 | if( szprintBuf )
|
|---|
| 578 | {
|
|---|
| 579 | if( (len + wrOffset) > max_buf_size )
|
|---|
| 580 | {
|
|---|
| 581 | int cntr;
|
|---|
| 582 | cntr= max_buf_size - wrOffset;
|
|---|
| 583 | memcpy( szprintBuf + wrOffset, DbgStr, cntr );
|
|---|
| 584 | DbgStr+= cntr;
|
|---|
| 585 | len= len - cntr;
|
|---|
| 586 | wrOffset= 0;
|
|---|
| 587 | }
|
|---|
| 588 | if( len )
|
|---|
| 589 | {
|
|---|
| 590 | memcpy( szprintBuf + wrOffset, DbgStr, len );
|
|---|
| 591 | wrOffset= wrOffset + len;
|
|---|
| 592 | if( wrOffset >= max_buf_size )
|
|---|
| 593 | wrOffset= 0;
|
|---|
| 594 | }
|
|---|
| 595 | if (fLineTerminate)
|
|---|
| 596 | {
|
|---|
| 597 | // if( (wrOffset+1) >= max_buf_size )
|
|---|
| 598 | // wrOffset= 0;
|
|---|
| 599 | if( szprintBuf[wrOffset-1] == LF )
|
|---|
| 600 | wrOffset = wrOffset - 1;
|
|---|
| 601 | szprintBuf[wrOffset]= CR;
|
|---|
| 602 | if( ++wrOffset >= max_buf_size )
|
|---|
| 603 | wrOffset= 0;
|
|---|
| 604 | szprintBuf[wrOffset]= LF;
|
|---|
| 605 | if( ++wrOffset >= max_buf_size )
|
|---|
| 606 | wrOffset= 0;
|
|---|
| 607 | }
|
|---|
| 608 | }
|
|---|
| 609 | }
|
|---|
| 610 | #endif
|
|---|
| 611 |
|
|---|
| 612 | #ifdef DEBUG
|
|---|
| 613 | short int MAGIC_COMM_PORT = 0x3f8; // pulled from word ptr 40:0
|
|---|
| 614 |
|
|---|
| 615 |
|
|---|
| 616 | #define UART_DATA 0x00 // UART Data port
|
|---|
| 617 | #define UART_INT_ENAB 0x01 // UART Interrupt enable
|
|---|
| 618 | #define UART_INT_ID 0x02 // interrupt ID
|
|---|
| 619 | #define UART_LINE_CTRL 0x03 // line control registers
|
|---|
| 620 | #define UART_MODEM_CTRL 0x04 // modem control register
|
|---|
| 621 | #define UART_LINE_STAT 0x05 // line status register
|
|---|
| 622 | #define UART_MODEM_STAT 0x06 // modem status regiser
|
|---|
| 623 | #define UART_DIVISOR_LO 0x00 // divisor latch least sig
|
|---|
| 624 | #define UART_DIVISOR_HI 0x01h // divisor latch most sig
|
|---|
| 625 |
|
|---|
| 626 | #define DELAY nop
|
|---|
| 627 | #else
|
|---|
| 628 | short int MAGIC_COMM_PORT = 0x0; // pulled from word ptr 40:0
|
|---|
| 629 | #endif
|
|---|
| 630 |
|
|---|
| 631 | #ifdef DEBUG //--------------------------- CharOut -
|
|---|
| 632 | void CharOut(char c)
|
|---|
| 633 | {
|
|---|
| 634 | if( MAGIC_COMM_PORT )
|
|---|
| 635 | {
|
|---|
| 636 |
|
|---|
| 637 | _asm {
|
|---|
| 638 |
|
|---|
| 639 | mov dx, MAGIC_COMM_PORT // address of PS/2's first COM port
|
|---|
| 640 | add dx, UART_LINE_STAT
|
|---|
| 641 |
|
|---|
| 642 | ReadyCheck:
|
|---|
| 643 | in al, dx // wait for comm port ready signal
|
|---|
| 644 |
|
|---|
| 645 | DELAY
|
|---|
| 646 | DELAY
|
|---|
| 647 | DELAY
|
|---|
| 648 |
|
|---|
| 649 | test al, 020h
|
|---|
| 650 | jz ReadyCheck
|
|---|
| 651 |
|
|---|
| 652 | // Send the character
|
|---|
| 653 |
|
|---|
| 654 | add dx, UART_DATA - UART_LINE_STAT
|
|---|
| 655 | mov al,c
|
|---|
| 656 | out dx, al
|
|---|
| 657 |
|
|---|
| 658 | DELAY
|
|---|
| 659 | DELAY
|
|---|
| 660 | DELAY
|
|---|
| 661 | }
|
|---|
| 662 | }
|
|---|
| 663 | }
|
|---|
| 664 | #endif
|
|---|