- Implemented the printing of 64 bit numbers.

svn path=/trunk/; revision=9431
This commit is contained in:
Hartmut Birr 2004-05-17 20:25:01 +00:00
parent d462152e6d
commit 869728e524
4 changed files with 98 additions and 5 deletions

View file

@ -234,6 +234,7 @@ VOID DebugPrint(U32 Mask, char *format, ...)
{
int *dataptr = (int *) &format;
char c, *ptr, str[16];
int ll;
// Mask out unwanted debug messages
if (!(Mask & DebugPrintMask))
@ -249,7 +250,7 @@ VOID DebugPrint(U32 Mask, char *format, ...)
}
dataptr++;
ll = 0;
while ((c = *(format++)))
{
if (c != '%')
@ -258,11 +259,28 @@ VOID DebugPrint(U32 Mask, char *format, ...)
}
else
{
if (*format == 'I' && *(format+1) == '6' && *(format+2) == '4')
{
ll = 1;
format += 3;
}
else
{
ll = 0;
}
switch (c = *(format++))
{
case 'd': case 'u': case 'x':
*convert_to_ascii(str, c, *((unsigned long *) dataptr++)) = 0;
if (ll)
{
*convert_i64_to_ascii(str, c, *((unsigned long long*) dataptr)) = 0;
dataptr += 2;
}
else
{
*convert_to_ascii(str, c, *((unsigned long *) dataptr++)) = 0;
}
ptr = str;

View file

@ -70,6 +70,7 @@ int isdigit(int c);
int isxdigit(int c);
char * convert_to_ascii(char *buf, int c, ...);
char * convert_i64_to_ascii(char *buf, int c, ...);
void putchar(int ch); // Implemented in asmcode.S
int kbhit(void); // Implemented in asmcode.S

View file

@ -38,6 +38,7 @@ void printf(char *format, ... )
{
int *dataptr = (int *) &format;
char c, *ptr, str[16];
int ll;
dataptr++;
@ -49,10 +50,26 @@ void printf(char *format, ... )
}
else
{
if (*format == 'I' && *(format+1) == '6' && *(format+2) == '4')
{
ll = 1;
format += 3;
}
else
{
ll = 0;
}
switch (c = *(format++))
{
case 'd': case 'u': case 'x':
*convert_to_ascii(str, c, *((unsigned long *) dataptr++)) = 0;
if (ll)
{
*convert_i64_to_ascii(str, c, *((unsigned long long *) dataptr++)) = 0;
}
else
{
*convert_to_ascii(str, c, *((unsigned long *) dataptr++)) = 0;
}
ptr = str;
@ -88,6 +105,7 @@ void sprintf(char *buffer, char *format, ... )
int *dataptr = (int *) &format;
char c, *ptr, str[16];
char *p = buffer;
int ll;
dataptr++;
@ -100,11 +118,27 @@ void sprintf(char *buffer, char *format, ... )
}
else
{
if (*format == 'I' && *(format+1) == '6' && *(format+2) == '4')
{
ll = 1;
format += 3;
}
else
{
ll = 0;
}
switch (c = *(format++))
{
case 'd': case 'u': case 'x':
*convert_to_ascii(str, c, *((unsigned long *) dataptr++)) = 0;
if (ll)
{
*convert_i64_to_ascii(str, c, *((unsigned long long*) dataptr++)) = 0;
}
else
{
*convert_to_ascii(str, c, *((unsigned long *) dataptr++)) = 0;
}
ptr = str;
while (*ptr)

View file

@ -63,6 +63,46 @@ char *convert_to_ascii(char *buf, int c, ...)
return ptr;
}
char *convert_i64_to_ascii(char *buf, int c, ...)
{
unsigned long long num = *(long long*)((&c) + 1);
int mult = 10;
char *ptr = buf;
if (c == 'x')
mult = 16;
if ((num & 0x8000000000000000uLL) && c == 'd')
{
num = (~num)+1;
*(ptr++) = '-';
buf++;
}
do
{
int dig = num % mult;
*(ptr++) = ( (dig > 9) ? dig + 'a' - 10 : '0' + dig );
}
while (num /= mult);
/* reorder to correct direction!! */
{
char *ptr1 = ptr-1;
char *ptr2 = buf;
while (ptr1 > ptr2)
{
int c = *ptr1;
*ptr1 = *ptr2;
*ptr2 = c;
ptr1--;
ptr2++;
}
}
return ptr;
}
char *itoa(int value, char *string, int radix)
{
if(radix == 16)