sprite DMA works
[mdlife] / src / libc / stdlib.c
index a6149e9..8a4c8f0 100644 (file)
@@ -72,10 +72,12 @@ long strtol(const char *str, char **endp, int base)
 
 void itoa(int val, char *buf, int base)
 {
-       static char rbuf[16];
+       char rbuf[16];
        char *ptr = rbuf;
        int neg = 0;
 
+       if(base <= 0) base = 10;
+
        if(val < 0) {
                neg = 1;
                val = -val;
@@ -103,11 +105,41 @@ void itoa(int val, char *buf, int base)
        *buf = 0;
 }
 
+void xtoa(unsigned int val, char *buf)
+{
+       char rbuf[16];
+       char *ptr = rbuf;
+
+       if(val == 0) {
+               *ptr++ = '0';
+       }
+
+       while(val) {
+               unsigned int digit = val & 0xf;
+               *ptr++ = digit < 10 ? (digit + '0') : (digit - 10 + 'a');
+               val >>= 4;
+       }
+
+       ptr--;
+
+       while(ptr >= rbuf) {
+               *buf++ = *ptr--;
+       }
+       *buf = 0;
+}
+
 void utoa(unsigned int val, char *buf, int base)
 {
        static char rbuf[16];
        char *ptr = rbuf;
 
+       if(base == 16) {
+               xtoa(val, buf);
+               return;
+       }
+
+       if(base <= 0) base = 10;
+
        if(val == 0) {
                *ptr++ = '0';
        }