/****************************************************************** * LibC for the LittleFox' Operating System * * Copyright (c) 2010 LittleFox * * http://littlefox.web-fuxx.de/ * ******************************************************************* * based on the API of LF OS 1.0 Alpha 4 * ******************************************************************/ #include "sdk/stdio.h" int printf_res; int inputCount = 0; int getch() { int c; __asm__ __volatile__ ("int $0x30": "=b"(c):"a"(3)); if(c >= 0x20 && c <= 0x7E) inputCount++; return c; } char keyBuffer[2048] = ""; void putc(char c) { printf_res++; __asm __volatile__ ("int $0x30":: "a" (0), "b" (c)); } void puts(const char* s) { while (*s) { putc(*s++); } } void putn(unsigned long x, int base) { char buf[65]; const char* digits = "0123456789abcdefghijklmnopqrstuvwxyz"; char* p; if (base > 36) { return; } p = buf + 64; *p = '\0'; do { *--p = digits[x % base]; x /= base; } while (x); puts(p); } int printf(const char* fmt, ...) { va_list ap; const char* s; unsigned long n; va_start(ap, fmt); int printf_res = 0; int c; inputCount = 0; while (*fmt) { if (*fmt == '%') { fmt++; switch (*fmt) { case 's': s = va_arg(ap, char*); puts(s); break; case 'd': case 'u': n = va_arg(ap, unsigned long int); putn(n, 10); break; case 'x': case 'p': n = va_arg(ap, unsigned long int); putn(n, 16); break; case '%': putc('%'); break; case 'c': c = va_arg(ap, int); putc(c); break; case '\0': goto out; default: putc('%'); putc(*fmt); break; } } else { putc(*fmt); } fmt++; } out: va_end(ap); return printf_res; } char *getline() { int i; for(i = 0; i < 2048; i++) { keyBuffer[i] = 0; } int t = getch(); i = 0; while(t != '\n') { if(t != 0 && t != '\b') { keyBuffer[i] = t; i++; putc(t); } if(t == '\b' && inputCount > 0) { i--; keyBuffer[i] = 0; asm("int $0x30"::"a"(5), "b"(-1), "d"(1)); putc(' '); asm("int $0x30"::"a"(5), "b"(-1), "d"(1)); inputCount--; } t = getch(); } inputCount = 0; return keyBuffer; } void clear_screen() { __asm__ __volatile__ ("int $0x30"::"a"(1)); } void set_color(int color) { __asm__ __volatile__ ("int $0x30"::"a"(2), "b"(color)); }