diff options
Diffstat (limited to 'demos/3rdparty/doom/i_system.c')
-rw-r--r-- | demos/3rdparty/doom/i_system.c | 211 |
1 files changed, 210 insertions, 1 deletions
diff --git a/demos/3rdparty/doom/i_system.c b/demos/3rdparty/doom/i_system.c index 60f5e1b8..2c6fde95 100644 --- a/demos/3rdparty/doom/i_system.c +++ b/demos/3rdparty/doom/i_system.c @@ -120,7 +120,7 @@ void I_EndRead(void) { } -byte* I_AllocLow(int length) +byte* I_Malloc(int length) { byte* mem; @@ -191,8 +191,217 @@ void I_FilePos(int handle, int pos) { int I_FileOpenRead(char *fname) { return strcmp(fname, F1NAME) ? -1 : F1HANDLE; } +int I_FileCreate(char *fname) { + return -1; +} +int I_FileWrite(int handle, char *source, int length) { + return 0; +} void I_FileClose(int handle) { } void *I_Realloc(void *p, int nsize) { return gfxRealloc(p, 0 /* Oops - we don't know this */, nsize); } +void I_Exit(int code) { + gfxExit(); +} +void I_printf(const char *fmt, ...) { +} +void I_DBGprintf(const char *fmt, ...) { +} + +#include <stdarg.h> + +#define MAX_FILLER 11 +#define FLOAT_PRECISION 100000 + +static char *ltoa_wd(char *p, long num, unsigned radix, long divisor) { + int i; + char *q; + + if (!divisor) divisor = num; + + q = p + MAX_FILLER; + do { + i = (int)(num % radix); + i += '0'; + if (i > '9') + i += 'A' - '0' - 10; + *--q = i; + num /= radix; + } while ((divisor /= radix) != 0); + + i = (int)(p + MAX_FILLER - q); + do { + *p++ = *q++; + } while (--i); + + return p; +} + +#if USE_FLOAT + static char *ftoa(char *p, double num) { + long l; + unsigned long precision = FLOAT_PRECISION; + + l = num; + p = ltoa_wd(p, l, 10, 0); + *p++ = '.'; + l = (num - l) * precision; + return ltoa_wd(p, l, 10, precision / 10); + } +#endif + +void I_sprintf(char *buf, const char *fmt, ...) { + va_list ap; + char *p, *s, c, filler; + int i, precision, width; + bool_t is_long, left_align; + long l; + #if USE_FLOAT + float f; + char tmpbuf[2*MAX_FILLER + 1]; + #else + char tmpbuf[MAX_FILLER + 1]; + #endif + + va_start(ap, fmt); + while (TRUE) { + c = *fmt++; + if (c == 0) { + va_end(ap); + return; + } + if (c != '%') { + *buf++ = c; + continue; + } + + p = tmpbuf; + s = tmpbuf; + left_align = FALSE; + if (*fmt == '-') { + fmt++; + left_align = TRUE; + } + filler = ' '; + if (*fmt == '.') { + fmt++; + filler = '0'; + } + width = 0; + + while (TRUE) { + c = *fmt++; + if (c >= '0' && c <= '9') + c -= '0'; + else if (c == '*') + c = va_arg(ap, int); + else + break; + width = width * 10 + c; + } + precision = 0; + if (c == '.') { + while (TRUE) { + c = *fmt++; + if (c >= '0' && c <= '9') + c -= '0'; + else if (c == '*') + c = va_arg(ap, int); + else + break; + precision = precision * 10 + c; + } + } + /* Long modifier.*/ + if (c == 'l' || c == 'L') { + is_long = TRUE; + if (*fmt) + c = *fmt++; + } + else + is_long = (c >= 'A') && (c <= 'Z'); + + /* Command decoding.*/ + switch (c) { + case 'c': + filler = ' '; + *p++ = va_arg(ap, int); + break; + case 's': + filler = ' '; + if ((s = va_arg(ap, char *)) == 0) + s = "(null)"; + if (precision == 0) + precision = 32767; + for (p = s; *p && (--precision >= 0); p++); + break; + case 'D': + case 'd': + if (is_long) + l = va_arg(ap, long); + else + l = va_arg(ap, int); + if (l < 0) { + *p++ = '-'; + l = -l; + } + p = ltoa_wd(p, l, 10, 0); + break; + #if USE_FLOAT + case 'f': + f = (float) va_arg(ap, double); + if (f < 0) { + *p++ = '-'; + f = -f; + } + p = ftoa(p, f); + break; + #endif + case 'X': + case 'x': + c = 16; + goto unsigned_common; + case 'U': + case 'u': + c = 10; + goto unsigned_common; + case 'O': + case 'o': + c = 8; + unsigned_common: + if (is_long) + l = va_arg(ap, long); + else + l = va_arg(ap, int); + p = ltoa_wd(p, l, c, 0); + break; + default: + *p++ = c; + break; + } + + i = (int)(p - s); + if ((width -= i) < 0) + width = 0; + if (left_align == FALSE) + width = -width; + if (width < 0) { + if (*s == '-' && filler == '0') { + *buf++ = *s++; + i--; + } + do { + *buf++ = filler; + } while (++width != 0); + } + while (--i >= 0) + *buf++ = *s++; + while (width) { + *buf++ = filler; + width--; + } + } +} + |