| 1 | /* $Id: debug.c,v 1.1.1.1 2003/07/02 13:57:02 eleph Exp $ */ | 
|---|
| 2 | /* | 
|---|
| 3 | * COM port debugging functions | 
|---|
| 4 | * | 
|---|
| 5 | * (C) 2000-2002 InnoTek Systemberatung GmbH | 
|---|
| 6 | * (C) 2000-2001 Sander van Leeuwen (sandervl@xs4all.nl) | 
|---|
| 7 | * | 
|---|
| 8 | * This program is free software; you can redistribute it and/or | 
|---|
| 9 | * modify it under the terms of the GNU General Public License as | 
|---|
| 10 | * published by the Free Software Foundation; either version 2 of | 
|---|
| 11 | * the License, or (at your option) any later version. | 
|---|
| 12 | * | 
|---|
| 13 | * This program is distributed in the hope that it will be useful, | 
|---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 16 | * GNU General Public License for more details. | 
|---|
| 17 | * | 
|---|
| 18 | * You should have received a copy of the GNU General Public | 
|---|
| 19 | * License along with this program; if not, write to the Free | 
|---|
| 20 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, | 
|---|
| 21 | * USA. | 
|---|
| 22 | * | 
|---|
| 23 | */ | 
|---|
| 24 | #define INCL_NOPMAPI | 
|---|
| 25 | #define INCL_DOSERRORS           // for ERROR_INVALID_FUNCTION | 
|---|
| 26 | #include <os2.h> | 
|---|
| 27 |  | 
|---|
| 28 | #include <string.h> | 
|---|
| 29 |  | 
|---|
| 30 | #define CR 0x0d | 
|---|
| 31 | #define LF 0x0a | 
|---|
| 32 |  | 
|---|
| 33 | #define LEADING_ZEROES          0x8000 | 
|---|
| 34 | #define SIGNIFICANT_FIELD       0x0007 | 
|---|
| 35 |  | 
|---|
| 36 | BOOL  fLineTerminate=TRUE; | 
|---|
| 37 | int   DebugLevel = 1; | 
|---|
| 38 |  | 
|---|
| 39 | extern int wrOffset; | 
|---|
| 40 | extern char *szprintBuf; | 
|---|
| 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 DEBUG | 
|---|
| 552 | int i; | 
|---|
| 553 | #endif /* DEBUG */ | 
|---|
| 554 |  | 
|---|
| 555 | len= _strnlen( DbgStr, 1024 ); | 
|---|
| 556 | /* | 
|---|
| 557 | while (*DbgStr) | 
|---|
| 558 | CharOut(*DbgStr++); | 
|---|
| 559 | */ | 
|---|
| 560 | #ifdef DEBUG | 
|---|
| 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( 0x10000, VMDHA_FIXED, &szprintBuf ); | 
|---|
| 573 | if( szprintBuf ) | 
|---|
| 574 | memset( szprintBuf, 0, 0x10000 ); | 
|---|
| 575 | wrOffset= 0; | 
|---|
| 576 | } | 
|---|
| 577 | if( szprintBuf ) | 
|---|
| 578 | { | 
|---|
| 579 | if( (len + wrOffset) > 0x10000 ) | 
|---|
| 580 | { | 
|---|
| 581 | int cntr; | 
|---|
| 582 | cntr= 0x10000 - 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 >= 0x10000 ) | 
|---|
| 593 | wrOffset= 0; | 
|---|
| 594 | } | 
|---|
| 595 | if (fLineTerminate) | 
|---|
| 596 | { | 
|---|
| 597 | //           if( (wrOffset+1) >= 0x10000 ) | 
|---|
| 598 | //               wrOffset= 0; | 
|---|
| 599 | szprintBuf[wrOffset]= CR; | 
|---|
| 600 | if( ++wrOffset >= 0x10000 ) | 
|---|
| 601 | wrOffset= 0; | 
|---|
| 602 | } | 
|---|
| 603 | } | 
|---|
| 604 | } | 
|---|
| 605 | #endif | 
|---|
| 606 |  | 
|---|
| 607 | #ifdef DEBUG | 
|---|
| 608 | short int MAGIC_COMM_PORT =  0x3f8;           // pulled from word ptr 40:0 | 
|---|
| 609 |  | 
|---|
| 610 |  | 
|---|
| 611 | #define UART_DATA               0x00            // UART Data port | 
|---|
| 612 | #define UART_INT_ENAB           0x01            // UART Interrupt enable | 
|---|
| 613 | #define UART_INT_ID             0x02            // interrupt ID | 
|---|
| 614 | #define UART_LINE_CTRL          0x03            // line control registers | 
|---|
| 615 | #define UART_MODEM_CTRL         0x04            // modem control register | 
|---|
| 616 | #define UART_LINE_STAT          0x05            // line status register | 
|---|
| 617 | #define UART_MODEM_STAT         0x06            // modem status regiser | 
|---|
| 618 | #define UART_DIVISOR_LO         0x00            // divisor latch least sig | 
|---|
| 619 | #define UART_DIVISOR_HI         0x01h           // divisor latch most sig | 
|---|
| 620 |  | 
|---|
| 621 | #define DELAY   nop | 
|---|
| 622 | #else | 
|---|
| 623 | short int MAGIC_COMM_PORT =  0x0;           // pulled from word ptr 40:0 | 
|---|
| 624 | #endif | 
|---|
| 625 |  | 
|---|
| 626 | #ifdef DEBUG                            //--------------------------- CharOut - | 
|---|
| 627 | void CharOut(char c) | 
|---|
| 628 | { | 
|---|
| 629 | if( MAGIC_COMM_PORT ) | 
|---|
| 630 | { | 
|---|
| 631 |  | 
|---|
| 632 | _asm    { | 
|---|
| 633 |  | 
|---|
| 634 | mov     dx, MAGIC_COMM_PORT     // address of PS/2's first COM port | 
|---|
| 635 | add     dx, UART_LINE_STAT | 
|---|
| 636 |  | 
|---|
| 637 | ReadyCheck: | 
|---|
| 638 | in      al, dx                                                          // wait for comm port ready signal | 
|---|
| 639 |  | 
|---|
| 640 | DELAY | 
|---|
| 641 | DELAY | 
|---|
| 642 | DELAY | 
|---|
| 643 |  | 
|---|
| 644 | test    al, 020h | 
|---|
| 645 | jz      ReadyCheck | 
|---|
| 646 |  | 
|---|
| 647 | // Send the character | 
|---|
| 648 |  | 
|---|
| 649 | add     dx, UART_DATA - UART_LINE_STAT | 
|---|
| 650 | mov     al,c | 
|---|
| 651 | out     dx, al | 
|---|
| 652 |  | 
|---|
| 653 | DELAY | 
|---|
| 654 | DELAY | 
|---|
| 655 | DELAY | 
|---|
| 656 | } | 
|---|
| 657 | } | 
|---|
| 658 | } | 
|---|
| 659 | #endif | 
|---|