Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

halvprnt.c

Go to the documentation of this file.
00001 /*++ 00002 00003 Copyright (c) 1990 Microsoft Corporation 00004 00005 Module Name: 00006 00007 halvprnt.c 00008 00009 Author: 00010 00011 John Vert (jvert) 13-Aug-1991 00012 based on TomP's video.c 00013 00014 Abstract: 00015 00016 Video support routines. 00017 00018 The vprintf function here outputs to the console via InbvDisplayString. 00019 All the global variables have been made local, so multiple processors 00020 can execute it simultaneously. If this is the case, it relies on 00021 InbvDisplayString to sort the output to avoid interleaving the text from 00022 the processors. 00023 00024 History: 00025 00026 --*/ 00027 00028 #include <ntos.h> 00029 #include <inbv.h> 00030 00031 typedef unsigned char BYTE, *PBYTE; 00032 00033 00034 // 00035 // Internal routines 00036 // 00037 00038 static 00039 int 00040 xatoi(char c); 00041 00042 static 00043 int 00044 fields( 00045 char *cp, 00046 int *zerofill, 00047 int *fieldwidth 00048 ); 00049 00050 static 00051 VOID 00052 putx( 00053 ULONG x, 00054 int digits, 00055 int zerofill, 00056 int *fieldwidth 00057 ); 00058 00059 static 00060 VOID 00061 puti( 00062 LONG i, 00063 int digits, 00064 int zerofill, 00065 int *fieldwidth 00066 ); 00067 00068 static 00069 VOID 00070 putu( 00071 ULONG u, 00072 int digits, 00073 int zerofill, 00074 int *fieldwidth 00075 ); 00076 00077 static 00078 VOID 00079 putc( 00080 CHAR c 00081 ); 00082 00083 00084 /*++ 00085 00086 Name 00087 00088 vprintf - DbgPrint function on standard video 00089 00090 Currently handles 00091 00092 00093 %i, %li - signed short, signed long (same as d) 00094 %d, %ld - signed short, signed long 00095 %u, %lu - unsigned short, unsigned long 00096 %c, %s, %.*s - character, string 00097 %Z - PSTRING data type 00098 %x, %lx - unsigned print in hex, unsigned long print in hex 00099 %X, %lX, %X, %X, %X, %X - same as %x and %lx 00100 field widths 00101 leading 0 fills 00102 00103 Does not do yet: 00104 00105 No floating point. 00106 00107 00108 --*/ 00109 void 00110 vprintf(PCHAR cp,USHORT a1) 00111 { 00112 ULONG cb; 00113 USHORT b,c; 00114 PBYTE ap; 00115 PCHAR s; 00116 PSTRING str; 00117 ULONG Flags; 00118 int zerofill, fieldwidth; 00119 00120 // 00121 // Cast a pointer to the first word on the stack 00122 // 00123 00124 ap = (PBYTE)&a1; 00125 00126 00127 // Save flags in automatic variable on stack, turn off ints. 00128 00129 _asm { 00130 pushfd 00131 pop Flags 00132 cli 00133 } 00134 00135 // 00136 // Process the argements using the descriptor string 00137 // 00138 00139 while (b = *cp++) { 00140 if (b == '%') { 00141 cp += fields(cp, &zerofill, &fieldwidth); 00142 c = *cp++; 00143 00144 switch (c) { 00145 case '.': 00146 if (*cp != '*' || cp[1] != 's') { 00147 putc((char)b); 00148 putc((char)c); 00149 break; 00150 } 00151 cp += 2; 00152 cb = *((ULONG *)ap); 00153 ap += sizeof( ULONG ); 00154 s = *((PCHAR *)ap); 00155 ap += sizeof( PCHAR ); 00156 if (s == NULL) { 00157 s = "(null)"; 00158 cb = 6; 00159 } 00160 if (cb > 0xFFF) { 00161 s = "(overflow)"; 00162 cb = 10; 00163 } 00164 00165 while (cb--) { 00166 if (*s) { 00167 putc(*s++); 00168 } else { 00169 putc(' '); 00170 } 00171 } 00172 break; 00173 00174 case 'i': 00175 case 'd': 00176 puti((long)*((int *)ap), 1, zerofill, &fieldwidth); 00177 ap += sizeof(int); 00178 break; 00179 00180 case 'S': 00181 str = *((PSTRING *)ap); 00182 ap += sizeof (STRING *); 00183 b = str->Length; 00184 s = str->Buffer; 00185 if (s == NULL) 00186 s = "(null)"; 00187 while (b--) 00188 putc(*s++); 00189 break; 00190 00191 case 's': 00192 s = *((PCHAR *)ap); 00193 ap += sizeof( PCHAR ); 00194 if (s == NULL) 00195 s = "(null)"; 00196 while (*s) 00197 putc(*s++); 00198 break; 00199 00200 case 'c': 00201 putc(*((char *)ap)); 00202 ap += sizeof(int); 00203 break; 00204 00205 00206 // 00207 // If we cannot find the status value in the table, print it in 00208 // hex. 00209 // 00210 case 'C': 00211 case 'B': 00212 // 00213 // Should search bugcodes.h to display bug code 00214 // symbolically. For now just show as hex 00215 // 00216 00217 case 'X': 00218 case 'x': 00219 putx((ULONG)*((USHORT *)ap), 1, zerofill, &fieldwidth); 00220 ap += sizeof(int); 00221 break; 00222 00223 case 'u': 00224 putu((ULONG)*((USHORT *)ap), 1, zerofill, &fieldwidth); 00225 ap += sizeof(int); 00226 break; 00227 00228 case 'l': 00229 c = *cp++; 00230 00231 switch(c) { 00232 case 'u': 00233 putu(*((ULONG *)ap), 1, zerofill, &fieldwidth); 00234 ap += sizeof(long); 00235 break; 00236 00237 case 'C': 00238 case 'B': 00239 // 00240 // Should search bugcodes.h to display bug code 00241 // symbolically. For now just show as hex 00242 // 00243 00244 case 'X': 00245 case 'x': 00246 putx(*((ULONG *)ap), 1, zerofill, &fieldwidth); 00247 ap += sizeof(long); 00248 break; 00249 00250 case 'i': 00251 case 'd': 00252 puti(*((ULONG *)ap), 1, zerofill, &fieldwidth); 00253 ap += sizeof(long); 00254 break; 00255 } // inner switch 00256 break; 00257 00258 default : 00259 putc((char)b); 00260 putc((char)c); 00261 } // outer switch 00262 } // if 00263 else 00264 putc((char)b); 00265 } // while 00266 00267 // Restore flags from automatic variable on stack 00268 00269 _asm { 00270 push Flags 00271 popfd 00272 } 00273 return; 00274 } 00275 00276 00277 // 00278 // Fields computation 00279 // 00280 00281 static int fields(char *cp, int *zerofill, int *fieldwidth) 00282 { 00283 int incval = 0; 00284 00285 *zerofill = 0; 00286 *fieldwidth = 0; 00287 00288 if (*cp == '0') { 00289 *zerofill = 1; 00290 cp++; 00291 incval++; 00292 } 00293 00294 while ((*cp >= '0') && (*cp <= '9')) { 00295 *fieldwidth = (*fieldwidth * 10) + xatoi(*cp); 00296 cp++; 00297 incval++; 00298 } 00299 return incval; 00300 } 00301 00302 // 00303 // Write a hex short to display 00304 // 00305 00306 static void putx(ULONG x, int digits, int zerofill, int *fieldwidth) 00307 { 00308 ULONG j; 00309 00310 if (x/16) 00311 putx(x/16, digits+1, zerofill, fieldwidth); 00312 00313 if (*fieldwidth > digits) { 00314 while (*fieldwidth > digits) { 00315 if (zerofill) 00316 putc('0'); 00317 else 00318 putc(' '); 00319 *fieldwidth--; 00320 } 00321 } 00322 *fieldwidth = 0; 00323 00324 00325 if((j=x%16) > 9) 00326 putc((char)(j+'A'- 10)); 00327 else 00328 putc((char)(j+'0')); 00329 00330 } 00331 00332 00333 // 00334 // Write a short integer to display 00335 // 00336 00337 static void puti(long i, int digits, int zerofill, int *fieldwidth) 00338 { 00339 if (i<0) { 00340 i = -i; 00341 putc((char)'-'); 00342 } 00343 00344 if (i/10) 00345 puti(i/10, digits+1, zerofill, fieldwidth); 00346 00347 if (*fieldwidth > digits) { 00348 while (*fieldwidth > digits) { 00349 if (zerofill) 00350 putc('0'); 00351 else 00352 putc(' '); 00353 *fieldwidth--; 00354 } 00355 } 00356 *fieldwidth = 0; 00357 00358 putc((char)((i%10)+'0')); 00359 } 00360 00361 00362 // 00363 // Write an unsigned short to display 00364 // 00365 00366 static void putu(ULONG u, int digits, int zerofill, int *fieldwidth) 00367 { 00368 if (u/10) 00369 putu(u/10, digits+1, zerofill, fieldwidth); 00370 00371 if (*fieldwidth > digits) { 00372 while (*fieldwidth > digits) { 00373 if (zerofill) 00374 putc('0'); 00375 else 00376 putc(' '); 00377 *fieldwidth--; 00378 } 00379 } 00380 *fieldwidth = 0; 00381 00382 putc((char)((u%10)+'0')); 00383 } 00384 00385 // 00386 // Write a character to display 00387 // 00388 00389 VOID putc( 00390 CHAR c 00391 ) 00392 { 00393 static UCHAR OneCharacter[2]; 00394 00395 OneCharacter[1] = '\0'; 00396 OneCharacter[0] = c; 00397 InbvDisplayString(OneCharacter); 00398 } 00399 00400 00401 // 00402 // Return the integer value of numeral represented by ascii char 00403 // 00404 00405 int xatoi(char c) 00406 { 00407 return c - '0'; 00408 }

Generated on Sat May 15 19:40:14 2004 for test by doxygen 1.3.7