3 * Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 //#define DEBUG_INIFILE
29 //#define DEBUG_REACTOS
30 //#define DEBUG_CUSTOM
33 #if defined (DEBUG_ULTRA)
34 U32 DebugPrintMask
= DPRINT_WARNING
| DPRINT_MEMORY
| DPRINT_FILESYSTEM
|
35 DPRINT_UI
| DPRINT_DISK
| DPRINT_CACHE
| DPRINT_REACTOS
|
37 #elif defined (DEBUG_INIFILE)
38 U32 DebugPrintMask
= DPRINT_INIFILE
;
39 #elif defined (DEBUG_REACTOS)
40 U32 DebugPrintMask
= DPRINT_REACTOS
| DPRINT_REGISTRY
;
41 #elif defined (DEBUG_CUSTOM)
42 U32 DebugPrintMask
= DPRINT_WARNING
|DPRINT_FILESYSTEM
;
43 #else //#elif defined (DEBUG_NONE)
44 U32 DebugPrintMask
= 0;
56 #define BOCHS_OUTPUT_PORT 0xe9
58 //U32 DebugPort = RS232;
59 U32 DebugPort
= SCREEN
;
60 //U32 DebugPort = BOCHS;
62 //U32 BaudRate = 19200;
63 U32 BaudRate
= 115200;
65 BOOL DebugStartOfLine
= TRUE
;
69 if (DebugPort
== RS232
)
71 Rs232PortInitialize(ComPort
, BaudRate
);
75 VOID
DebugPrintChar(UCHAR Character
)
77 if (Character
== '\n')
79 DebugStartOfLine
= TRUE
;
82 if (DebugPort
== RS232
)
84 if (Character
== '\n')
86 Rs232PortPutByte('\r');
88 Rs232PortPutByte(Character
);
90 else if (DebugPort
== BOCHS
)
92 WRITE_PORT_UCHAR((PUCHAR
)BOCHS_OUTPUT_PORT
, Character
);
100 VOID
DebugPrintHeader(U32 Mask
)
129 case DPRINT_FILESYSTEM
:
174 case DPRINT_REGISTRY
:
220 VOID
DebugPrint(U32 Mask
, char *format
, ...)
222 int *dataptr
= (int *) &format
;
223 char c
, *ptr
, str
[16];
225 // Mask out unwanted debug messages
226 if (!(Mask
& DebugPrintMask
))
231 // Print the header if we have started a new line
232 if (DebugStartOfLine
)
234 DebugPrintHeader(Mask
);
235 DebugStartOfLine
= FALSE
;
240 while ((c
= *(format
++)))
248 switch (c
= *(format
++))
250 case 'd': case 'u': case 'x':
252 *convert_to_ascii(str
, c
, *((unsigned long *) dataptr
++)) = 0;
258 DebugPrintChar(*(ptr
++));
264 DebugPrintChar((*(dataptr
++))&0xff);
269 ptr
= (char *)(*(dataptr
++));
271 while ((c
= *(ptr
++)))
280 DebugPrint(Mask
, "\nDebugPrint() invalid format specifier - %%%c\n", c
);
287 if (DebugPort
== SCREEN
)
294 VOID
DebugDumpBuffer(U32 Mask
, PVOID Buffer
, U32 Length
)
296 PUCHAR BufPtr
= (PUCHAR
)Buffer
;
300 // Mask out unwanted debug messages
301 if (!(Mask
& DebugPrintMask
))
306 DebugStartOfLine
= FALSE
; // We don't want line headers
307 DebugPrint(Mask
, "Dumping buffer at 0x%x with length of %d bytes:\n", Buffer
, Length
);
309 for (Idx
=0; Idx
<Length
; )
311 DebugStartOfLine
= FALSE
; // We don't want line headers
315 DebugPrint(Mask
, "000%x:\t", Idx
);
317 else if (Idx
< 0x0100)
319 DebugPrint(Mask
, "00%x:\t", Idx
);
321 else if (Idx
< 0x1000)
323 DebugPrint(Mask
, "0%x:\t", Idx
);
327 DebugPrint(Mask
, "%x:\t", Idx
);
330 for (Idx2
=0; Idx2
<16; Idx2
++,Idx
++)
332 if (BufPtr
[Idx
] < 0x10)
334 DebugPrint(Mask
, "0");
336 DebugPrint(Mask
, "%x", BufPtr
[Idx
]);
340 DebugPrint(Mask
, "-");
344 DebugPrint(Mask
, " ");
349 DebugPrint(Mask
, " ");
351 for (Idx2
=0; Idx2
<16; Idx2
++,Idx
++)
353 if ((BufPtr
[Idx
] > 20) && (BufPtr
[Idx
] < 0x80))
355 DebugPrint(Mask
, "%c", BufPtr
[Idx
]);
359 DebugPrint(Mask
, ".");
363 DebugPrint(Mask
, "\n");
367 #endif // defined DEBUG