Changeset 479 for GPL/trunk/lib32/debug.c
- Timestamp:
- May 1, 2010, 9:49:10 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GPL/trunk/lib32/debug.c
r421 r479 34 34 #define SIGNIFICANT_FIELD 0x0007 35 35 36 //#define COMM_DEBUG 37 36 38 BOOL fLineTerminate=TRUE; 37 39 int DebugLevel = 1; … … 123 125 124 126 if (Power==0xF0000000) // 1 billion 125 Power=0xF000000; 127 Power=0xF000000; 126 128 else if (Power==0xF000000) 127 129 Power=0xF00000; … … 144 146 } 145 147 146 #define DEBUG1 147 148 #ifdef DEBUG1 149 char BuildString[1024]; 150 #endif // DEBUG 151 152 //------------------------- PrintfOut - 153 void _cdecl DPD(int level, char *DbgStr, ...) 154 { 155 #ifdef DEBUG1 156 char *BuildPtr=BuildString; 157 char *pStr=(char *) DbgStr; 158 char *SubStr; 159 union { 160 void *VoidPtr; 161 USHORT *WordPtr; 162 ULONG *LongPtr; 163 ULONG *StringPtr; 164 } Parm; 165 USHORT wBuildOption; 166 167 Parm.VoidPtr=(void *) &DbgStr; 168 Parm.StringPtr++; // skip size of string pointer 169 170 while (*pStr) 171 { 172 // don't overflow target 173 if (BuildPtr >= (char *) &BuildString[1024-2]) 174 break; 175 176 switch (*pStr) 177 { 178 case '%': 179 wBuildOption=0; 180 pStr++; 181 if (*pStr=='0') 182 { 183 wBuildOption|=LEADING_ZEROES; 184 pStr++; 185 } 186 if (*pStr=='u') // always unsigned 187 pStr++; 188 if (*pStr=='#') 189 pStr++; 190 191 switch(*pStr) 192 { 193 case 'x': 194 case 'X': 195 case 'p': 196 case 'P': 197 BuildPtr=HexLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption); 198 pStr++; 199 continue; 200 201 case 'd': 202 BuildPtr=DecLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption); 203 pStr++; 204 continue; 205 206 case 's': 207 SubStr=(char *)*Parm.StringPtr; 208 while (*BuildPtr++ = *SubStr++); 209 Parm.StringPtr++; 210 BuildPtr--; // remove the \0 211 pStr++; 212 continue; 213 214 case 'l': 215 pStr++; 216 switch (*pStr) 217 { 218 case 'x': 219 case 'X': 220 BuildPtr=HexLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption); 221 pStr++; 222 continue; 223 224 case 'd': 225 BuildPtr=DecLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption); 226 pStr++; 227 continue; 228 } // end switch 229 continue; // dunno what he wants 230 231 case 0: 232 continue; 233 } // end switch 234 break; 235 236 case '\\': 237 pStr++; 238 switch (*pStr) 239 { 240 case 'n': 241 *BuildPtr++=LF; 242 pStr++; 243 continue; 244 245 case 'r': 246 *BuildPtr++=CR; 247 pStr++; 248 continue; 249 250 case 0: 251 continue; 252 break; 253 } // end switch 254 255 break; 256 } // end switch 257 258 *BuildPtr++=*pStr++; 259 } // end while 260 261 *BuildPtr=0; // cauterize the string 262 StringOut((char *) BuildString); // print to comm port 263 #endif //DEBUG 264 } 265 266 267 void _cdecl DPE(char *DbgStr, ...) 268 { 269 #ifdef DEBUG1 270 char *BuildPtr=BuildString; 271 char *pStr = (char *) DbgStr; 272 char *SubStr; 273 union { 274 void *VoidPtr; 275 USHORT *WordPtr; 276 ULONG *LongPtr; 277 ULONG *StringPtr; 278 } Parm; 279 USHORT wBuildOption; 280 281 Parm.VoidPtr=(void *) &DbgStr; 282 Parm.StringPtr++; // skip size of string pointer 283 284 while (*pStr) 285 { 286 // don't overflow target 287 if (BuildPtr >= (char *) &BuildString[1024-2]) 288 break; 289 290 switch (*pStr) 291 { 292 case '%': 293 wBuildOption=0; 294 pStr++; 295 if (*pStr=='0') 296 { 297 wBuildOption|=LEADING_ZEROES; 298 pStr++; 299 } 300 // if (*pStr=='u') // always unsigned 301 // pStr++; 302 303 switch(*pStr) 304 { 305 case 'x': 306 case 'X': 307 case 'p': 308 case 'P': 309 BuildPtr=HexLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption); 310 pStr++; 311 continue; 312 313 case 'd': 314 case 'u': 315 BuildPtr=DecLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption); 316 pStr++; 317 continue; 318 319 case 's': 320 SubStr=(char *)*Parm.StringPtr; 321 while (*BuildPtr++ = *SubStr++); 322 Parm.StringPtr++; 323 BuildPtr--; // remove the \0 324 pStr++; 325 continue; 326 327 case 'c': 328 *BuildPtr++ = (char)*Parm.LongPtr; 329 Parm.LongPtr++; 330 pStr++; 331 continue; 332 333 case 'l': 334 pStr++; 335 switch (*pStr) 336 { 337 case 'x': 338 case 'X': 339 BuildPtr=HexLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption); 340 pStr++; 341 continue; 342 343 case 'd': 344 BuildPtr=DecLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption); 345 pStr++; 346 continue; 347 } // end switch 348 continue; // dunno what he wants 349 350 case 0: 351 continue; 352 } // end switch 353 break; 354 355 case '\\': 356 pStr++; 357 switch (*pStr) 358 { 359 case 'n': 360 *BuildPtr++=LF; 361 pStr++; 362 continue; 363 364 case 'r': 365 *BuildPtr++=CR; 366 pStr++; 367 continue; 368 369 case 0: 370 continue; 371 break; 372 } // end switch 373 374 break; 375 } // end switch 376 377 *BuildPtr++=*pStr++; 378 } // end while 379 380 *BuildPtr=0; // cauterize the string 381 StringOut((char *) BuildString); // print to comm port 382 #endif //DEBUG 383 } 384 385 struct snd_info_buffer { 386 char *buffer; /* pointer to begin of buffer */ 387 char *curr; /* current position in buffer */ 388 unsigned long size; /* current size */ 389 unsigned long len; /* total length of buffer */ 390 int stop; /* stop flag */ 391 int error; /* error code */ 392 }; 393 394 typedef struct snd_info_buffer snd_info_buffer_t; 395 396 int snd_iprintf(snd_info_buffer_t * buffer, char *fmt,...) 397 { 398 char *BuildPtr=buffer->curr; 399 char *pStr=(char *) fmt; 400 char *SubStr; 401 int res; 402 union { 403 void *VoidPtr; 404 USHORT *WordPtr; 405 ULONG *LongPtr; 406 ULONG *StringPtr; 407 } Parm; 408 USHORT wBuildOption; 409 410 Parm.VoidPtr=(void *) &fmt; 411 Parm.StringPtr++; // skip size of string pointer 412 413 if (buffer->stop || buffer->error) 414 return 0; 415 416 while (*pStr) 417 { 418 // don't overflow target 419 if (BuildPtr >= (char *) &buffer->curr[buffer->len - 4]) 420 break; 421 422 switch (*pStr) 423 { 424 case '%': 425 wBuildOption=0; 426 pStr++; 427 if (*pStr=='0') 428 { 429 wBuildOption|=LEADING_ZEROES; 430 pStr++; 431 } 432 // if (*pStr=='u') // always unsigned 433 // pStr++; 434 if (*pStr=='#') 435 pStr++; 436 437 switch(*pStr) 438 { 439 case 'x': 440 case 'X': 441 case 'p': 442 case 'P': 443 BuildPtr=HexLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption); 444 pStr++; 445 continue; 446 447 case 'd': 448 case 'u': 449 BuildPtr=DecLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption); 450 pStr++; 451 continue; 452 453 case 's': 454 SubStr=(char *)*Parm.StringPtr; 455 while (*BuildPtr++ = *SubStr++); 456 Parm.StringPtr++; 457 BuildPtr--; // remove the \0 458 pStr++; 459 continue; 460 461 case 'c': 462 *BuildPtr++ = (char)*Parm.LongPtr; 463 Parm.LongPtr++; 464 pStr++; 465 continue; 466 467 case 'l': 468 pStr++; 469 switch (*pStr) 470 { 471 case 'x': 472 case 'X': 473 BuildPtr=HexLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption); 474 pStr++; 475 continue; 476 477 case 'd': 478 BuildPtr=DecLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption); 479 pStr++; 480 continue; 481 } // end switch 482 continue; // dunno what he wants 483 484 case 0: 485 continue; 486 } // end switch 487 break; 488 489 case '\\': 490 pStr++; 491 switch (*pStr) 492 { 493 case 'n': 494 *BuildPtr++=LF; 495 pStr++; 496 continue; 497 498 case 'r': 499 *BuildPtr++=CR; 500 pStr++; 501 continue; 502 503 case 0: 504 continue; 505 break; 506 } // end switch 507 508 break; 509 } // end switch 510 511 *BuildPtr++=*pStr++; 512 } // end while 513 514 *BuildPtr=0; // cauterize the string 515 516 res = strlen(buffer->curr); 517 if (buffer->size + res >= buffer->len) { 518 buffer->stop = 1; 519 return 0; 520 } 521 buffer->curr += res; 522 buffer->size += res; 523 return res; 524 } 525 526 #ifdef DEBUG1 148 #ifdef DEBUG 527 149 //------------------------- StringOut --------------------------// 528 150 … … 546 168 return psz - pszC; 547 169 } 548 //PS+++ Changes for right debug output 549 #ifdef DEBUG550 short int MAGIC_COMM_PORT = 0; 170 171 #ifdef COMM_DEBUG 172 short int MAGIC_COMM_PORT = 0; // pulled from word ptr 40:0 551 173 552 174 … … 562 184 563 185 #define DELAY nop 564 #else 565 short int MAGIC_COMM_PORT = 0x0; // pulled from word ptr 40:0 186 187 void CharOut(char c) 188 { 189 if( MAGIC_COMM_PORT ) 190 { 191 192 _asm { 193 194 mov dx, MAGIC_COMM_PORT // address of PS/2's first COM port 195 add dx, UART_LINE_STAT 196 197 ReadyCheck: 198 in al, dx // wait for comm port ready signal 199 200 DELAY 201 DELAY 202 DELAY 203 204 test al, 020h 205 jz ReadyCheck 206 207 // Send the character 208 209 add dx, UART_DATA - UART_LINE_STAT 210 mov al,c 211 out dx, al 212 213 DELAY 214 DELAY 215 DELAY 216 } 217 } 218 } 566 219 #endif 567 220 … … 569 222 { 570 223 int len; 571 #ifdef DEBUG224 #ifdef COMM_DEBUG 572 225 int i; 573 226 #endif /* DEBUG */ 574 227 575 228 len= _strnlen( DbgStr, 1024 ); 576 /* 229 /* 577 230 while (*DbgStr) 578 231 CharOut(*DbgStr++); 579 232 */ 580 #ifdef DEBUG233 #ifdef COMM_DEBUG 581 234 if (MAGIC_COMM_PORT) //PS+++ If have comport - out to it 582 235 { … … 631 284 #endif 632 285 633 634 #ifdef DEBUG //--------------------------- CharOut - 635 void CharOut(char c) 636 { 637 if( MAGIC_COMM_PORT ) 638 { 639 640 _asm { 641 642 mov dx, MAGIC_COMM_PORT // address of PS/2's first COM port 643 add dx, UART_LINE_STAT 644 645 ReadyCheck: 646 in al, dx // wait for comm port ready signal 647 648 DELAY 649 DELAY 650 DELAY 651 652 test al, 020h 653 jz ReadyCheck 654 655 // Send the character 656 657 add dx, UART_DATA - UART_LINE_STAT 658 mov al,c 659 out dx, al 660 661 DELAY 662 DELAY 663 DELAY 664 } 665 } 666 } 667 #endif 286 #ifdef DEBUG 287 char BuildString[1024]; 288 #endif // DEBUG 289 290 //------------------------- PrintfOut - 291 void _cdecl DPD(int level, char *DbgStr, ...) 292 { 293 #ifdef DEBUG 294 char *BuildPtr=BuildString; 295 char *pStr=(char *) DbgStr; 296 char *SubStr; 297 union { 298 void *VoidPtr; 299 USHORT *WordPtr; 300 ULONG *LongPtr; 301 ULONG *StringPtr; 302 } Parm; 303 USHORT wBuildOption; 304 305 Parm.VoidPtr=(void *) &DbgStr; 306 Parm.StringPtr++; // skip size of string pointer 307 308 while (*pStr) 309 { 310 // don't overflow target 311 if (BuildPtr >= (char *) &BuildString[1024-2]) 312 break; 313 314 switch (*pStr) 315 { 316 case '%': 317 wBuildOption=0; 318 pStr++; 319 if (*pStr=='0') 320 { 321 wBuildOption|=LEADING_ZEROES; 322 pStr++; 323 } 324 if (*pStr=='u') // always unsigned 325 pStr++; 326 if (*pStr=='#') 327 pStr++; 328 329 switch(*pStr) 330 { 331 case 'x': 332 case 'X': 333 case 'p': 334 case 'P': 335 BuildPtr=HexLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption); 336 pStr++; 337 continue; 338 339 case 'd': 340 BuildPtr=DecLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption); 341 pStr++; 342 continue; 343 344 case 's': 345 SubStr=(char *)*Parm.StringPtr; 346 while (*BuildPtr++ = *SubStr++); 347 Parm.StringPtr++; 348 BuildPtr--; // remove the \0 349 pStr++; 350 continue; 351 352 case 'l': 353 pStr++; 354 switch (*pStr) 355 { 356 case 'x': 357 case 'X': 358 BuildPtr=HexLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption); 359 pStr++; 360 continue; 361 362 case 'd': 363 BuildPtr=DecLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption); 364 pStr++; 365 continue; 366 } // end switch 367 continue; // dunno what he wants 368 369 case 0: 370 continue; 371 } // end switch 372 break; 373 374 case '\\': 375 pStr++; 376 switch (*pStr) 377 { 378 case 'n': 379 *BuildPtr++=LF; 380 pStr++; 381 continue; 382 383 case 'r': 384 *BuildPtr++=CR; 385 pStr++; 386 continue; 387 388 case 0: 389 continue; 390 break; 391 } // end switch 392 393 break; 394 } // end switch 395 396 *BuildPtr++=*pStr++; 397 } // end while 398 399 *BuildPtr=0; // cauterize the string 400 StringOut((char *) BuildString); 401 #endif //DEBUG 402 } 403 404 405 void _cdecl DPE(char *DbgStr, ...) 406 { 407 #ifdef DEBUG 408 char *BuildPtr=BuildString; 409 char *pStr = (char *) DbgStr; 410 char *SubStr; 411 union { 412 void *VoidPtr; 413 USHORT *WordPtr; 414 ULONG *LongPtr; 415 ULONG *StringPtr; 416 } Parm; 417 USHORT wBuildOption; 418 419 Parm.VoidPtr=(void *) &DbgStr; 420 Parm.StringPtr++; // skip size of string pointer 421 422 while (*pStr) 423 { 424 // don't overflow target 425 if (BuildPtr >= (char *) &BuildString[1024-2]) 426 break; 427 428 switch (*pStr) 429 { 430 case '%': 431 wBuildOption=0; 432 pStr++; 433 if (*pStr=='0') 434 { 435 wBuildOption|=LEADING_ZEROES; 436 pStr++; 437 } 438 // if (*pStr=='u') // always unsigned 439 // pStr++; 440 441 switch(*pStr) 442 { 443 case 'x': 444 case 'X': 445 case 'p': 446 case 'P': 447 BuildPtr=HexLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption); 448 pStr++; 449 continue; 450 451 case 'd': 452 case 'u': 453 BuildPtr=DecLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption); 454 pStr++; 455 continue; 456 457 case 's': 458 SubStr=(char *)*Parm.StringPtr; 459 while (*BuildPtr++ = *SubStr++); 460 Parm.StringPtr++; 461 BuildPtr--; // remove the \0 462 pStr++; 463 continue; 464 465 case 'c': 466 *BuildPtr++ = (char)*Parm.LongPtr; 467 Parm.LongPtr++; 468 pStr++; 469 continue; 470 471 case 'l': 472 pStr++; 473 switch (*pStr) 474 { 475 case 'x': 476 case 'X': 477 BuildPtr=HexLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption); 478 pStr++; 479 continue; 480 481 case 'd': 482 BuildPtr=DecLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption); 483 pStr++; 484 continue; 485 } // end switch 486 continue; // dunno what he wants 487 488 case 0: 489 continue; 490 } // end switch 491 break; 492 493 case '\\': 494 pStr++; 495 switch (*pStr) 496 { 497 case 'n': 498 *BuildPtr++=LF; 499 pStr++; 500 continue; 501 502 case 'r': 503 *BuildPtr++=CR; 504 pStr++; 505 continue; 506 507 case 0: 508 continue; 509 break; 510 } // end switch 511 512 break; 513 } // end switch 514 515 *BuildPtr++=*pStr++; 516 } // end while 517 518 *BuildPtr=0; // cauterize the string 519 StringOut((char *) BuildString); 520 #endif //DEBUG 521 } 522 523 struct snd_info_buffer { 524 char *buffer; /* pointer to begin of buffer */ 525 char *curr; /* current position in buffer */ 526 unsigned long size; /* current size */ 527 unsigned long len; /* total length of buffer */ 528 int stop; /* stop flag */ 529 int error; /* error code */ 530 }; 531 532 typedef struct snd_info_buffer snd_info_buffer_t; 533 534 int snd_iprintf(snd_info_buffer_t * buffer, char *fmt,...) 535 { 536 char *BuildPtr=buffer->curr; 537 char *pStr=(char *) fmt; 538 char *SubStr; 539 int res; 540 union { 541 void *VoidPtr; 542 USHORT *WordPtr; 543 ULONG *LongPtr; 544 ULONG *StringPtr; 545 } Parm; 546 USHORT wBuildOption; 547 548 Parm.VoidPtr=(void *) &fmt; 549 Parm.StringPtr++; // skip size of string pointer 550 551 if (buffer->stop || buffer->error) 552 return 0; 553 554 while (*pStr) 555 { 556 // don't overflow target 557 if (BuildPtr >= (char *) &buffer->curr[buffer->len - 4]) 558 break; 559 560 switch (*pStr) 561 { 562 case '%': 563 wBuildOption=0; 564 pStr++; 565 if (*pStr=='0') 566 { 567 wBuildOption|=LEADING_ZEROES; 568 pStr++; 569 } 570 // if (*pStr=='u') // always unsigned 571 // pStr++; 572 if (*pStr=='#') 573 pStr++; 574 575 switch(*pStr) 576 { 577 case 'x': 578 case 'X': 579 case 'p': 580 case 'P': 581 BuildPtr=HexLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption); 582 pStr++; 583 continue; 584 585 case 'd': 586 case 'u': 587 BuildPtr=DecLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption); 588 pStr++; 589 continue; 590 591 case 's': 592 SubStr=(char *)*Parm.StringPtr; 593 while (*BuildPtr++ = *SubStr++); 594 Parm.StringPtr++; 595 BuildPtr--; // remove the \0 596 pStr++; 597 continue; 598 599 case 'c': 600 *BuildPtr++ = (char)*Parm.LongPtr; 601 Parm.LongPtr++; 602 pStr++; 603 continue; 604 605 case 'l': 606 pStr++; 607 switch (*pStr) 608 { 609 case 'x': 610 case 'X': 611 BuildPtr=HexLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption); 612 pStr++; 613 continue; 614 615 case 'd': 616 BuildPtr=DecLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption); 617 pStr++; 618 continue; 619 } // end switch 620 continue; // dunno what he wants 621 622 case 0: 623 continue; 624 } // end switch 625 break; 626 627 case '\\': 628 pStr++; 629 switch (*pStr) 630 { 631 case 'n': 632 *BuildPtr++=LF; 633 pStr++; 634 continue; 635 636 case 'r': 637 *BuildPtr++=CR; 638 pStr++; 639 continue; 640 641 case 0: 642 continue; 643 break; 644 } // end switch 645 646 break; 647 } // end switch 648 649 *BuildPtr++=*pStr++; 650 } // end while 651 652 *BuildPtr=0; // cauterize the string 653 654 res = strlen(buffer->curr); 655 if (buffer->size + res >= buffer->len) { 656 buffer->stop = 1; 657 return 0; 658 } 659 buffer->curr += res; 660 buffer->size += res; 661 return res; 662 } 663
Note:
See TracChangeset
for help on using the changeset viewer.