1 /* Copyright (C) 1996 Robert de Bath <robert@mayday.compulink.co.uk>
2 * This file is part of the Linux-8086 C library and is distributed
3 * under the GNU Library General Public License.
6 /* Modified 14-Jan-2002 by John Coffman <johninsd@san.rr.com> for inclusion
7 * in the set of LILO diagnostics. This code is the property of Robert
8 * de Bath, and is used with his permission.
12 /* #include <conio.h> */
17 #define putch(ch) fputc(ch,stdout)
19 #define putch(ch) bios_putc(ch)
22 static unsigned char * __numout(long i, int base);
24 int cprintf(char * fmt, ...)
42 if (c=='\n') putch('\r');
50 if(padch == '-') fmt++;
55 if( c<'0' || c>'9' ) break;
56 minsize*=10; minsize+=c-'0';
63 if( c<'0' || c>'9' ) break;
64 maxsize*=10; maxsize+=c-'0';
67 if( padch == '-' ) minsize = -minsize;
69 if( padch != '0' ) padch=' ';
85 case 'x': base=16; type |= 4; if(0) {
86 case 'o': base= 8; type |= 4; } if(0) {
87 case 'u': base=10; type |= 4; } if(0) {
91 case 0: val=va_arg(ap, short); break;
92 case 1: val=va_arg(ap, int); break;
93 case 2: val=va_arg(ap, long); break;
94 case 4: val=va_arg(ap, unsigned short); break;
95 case 5: val=va_arg(ap, unsigned int); break;
96 case 6: val=va_arg(ap, unsigned long); break;
99 cp = __numout(val,base);
102 cp=va_arg(ap, char *);
106 if( !maxsize ) maxsize = c;
110 while(minsize>0) { putch(padch); count++; minsize--; }
113 if( minsize < 0 ) minsize= -minsize-c;
114 while(*cp && maxsize-->0 )
119 while(minsize>0) { putch(' '); count++; minsize--; }
122 putch(va_arg(ap, int));
134 static char nstring[]="0123456789ABCDEF";
139 static unsigned char *
140 __numout(long i, int base)
142 static unsigned char out[NUMLTH+1];
162 out[n--] = nstring[val % base];
166 if(flg) out[n--] = '-';
177 .ascii "0123456789ABCDEF"
191 mov byte ptr -8[bp],*$0 ! flg = 0
192 mov si,4[bp] ; i or val.lo
193 mov di,6[bp] ; i or val.hi
195 test cx,cx ! base < 0 ?
197 neg cx ! base = -base
200 mov byte ptr -8[bp],*1 ! flg = 1
206 mov byte ptr [___out+$B],*$0 ! out[11] = nul
207 mov -6[bp],*$A ! n = 10
210 !!! out[n--] = nstring[val % base];
217 xchg ax,si ! val(new) = val / base
219 mov bx,dx ! dx = val % base
227 or ax,di ! while (val)
230 cmp byte ptr -8[bp],*$0 ! flg == 0 ?
235 mov byte ptr ___out[bx],*$2D ! out[n--] = minus