From: Michael D. Lowis Date: Fri, 24 Sep 2021 02:25:25 +0000 (-0400) Subject: finally fixed scrolling X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=2dd6406b669316e653b7e0527c2af3a992dead6d;p=proto%2Fuefi.git finally fixed scrolling --- diff --git a/core/kernel.h b/core/kernel.h index 98f5c62..4e35be5 100644 --- a/core/kernel.h +++ b/core/kernel.h @@ -15,6 +15,7 @@ static inline void Video_PutPixel(int x, int y, uint32_t pixel) */ void Term_Init(void); void Term_Clear(void); +void Term_Print(char*, ...); void Term_PutChar(int c); void Term_PutString(char* s); void Term_PutInt(int64_t val); diff --git a/core/main.c b/core/main.c index 6a79213..8fd3a76 100644 --- a/core/main.c +++ b/core/main.c @@ -9,11 +9,17 @@ int main (int argc, char** argv) for (;;) { Term_PutString("foo\n"); - sleep(250); Term_PutString("bar\n"); - sleep(250); Term_PutString("baz\n"); - sleep(250); + Term_Print("%% %d %u %c %s %p %x\n", + -1234, + 4321, + 'F', + "hi!", + (void*)0x12345678, + 0x12345678lu + ); + } return 0; diff --git a/core/term.c b/core/term.c index 0619e24..92cf194 100644 --- a/core/term.c +++ b/core/term.c @@ -40,12 +40,12 @@ static void PutCell(int c) Term.cursor = (Term.rows - 1) * Term.cols; while (src < max) { - PutGlyph((dst % Term.cols) * 8, (dst / Term.rows) * 16, Term.cells[src]); + PutGlyph((dst % Term.cols) * 8, (dst / Term.cols) * 16, Term.cells[src]); Term.cells[dst++] = Term.cells[src++]; } - for (int i = Term.cursor; i < Term.cols; i++) + for (int i = Term.cursor; i < (Term.cursor + Term.cols); i++) { - PutGlyph((i % Term.cols) * 8, (i / Term.rows) * 16, ' '); + PutGlyph((i % Term.cols) * 8, (i / Term.cols) * 16, ' '); Term.cells[i] = ' '; } } @@ -72,9 +72,17 @@ void Term_PutChar(int c) break; case '\n': - Term.cursor = (Term.cursor / Term.cols) * Term.cols; - Term.cursor += Term.cols; + { + int next = (Term.cursor / Term.cols) * Term.cols + Term.cols; + while (Term.cursor < next) + { + PutCell(' '); + } + +// Term.cursor = (Term.cursor / Term.cols) * Term.cols; +// Term.cursor += Term.cols; break; + } default: PutCell(c); @@ -82,6 +90,86 @@ void Term_PutChar(int c) } } +void Term_Print(char* fmt, ...) +{ + va_list arg; + va_start (arg, fmt); + for (; *fmt; fmt++) + { + if (*fmt == '%') + { + int ndigits = sizeof(intptr_t); + fmt++; + if (*fmt >= '0' && *fmt <= '9') + { + ndigits = *(fmt++) - '0'; + } + switch(*fmt) + { + case 'd': + Term_PutInt(va_arg(arg, int)); + break; + + case 'u': + Term_PutInt(va_arg(arg, unsigned int)); + break; + +// case 'f': +// TODO +// break; + + case 'c': + Term_PutChar((char)va_arg(arg, int)); + break; + + case 's': + for (char* s = va_arg(arg, char*); *s; s++) + { + Term_PutChar(*s); + } + break; + + case 'p': + case 'x': + { + uint64_t val = va_arg(arg, uint64_t); + if (ndigits > 6u) + { + Term_PutHex64(val); + } + else if (ndigits > 4u) + { + Term_PutHex32(val); + } + else if (ndigits > 2u) + { + Term_PutHex16(val); + } + else + { + Term_PutHex8(val); + } + break; + } + + case '%': + Term_PutChar('%'); + break; +// +// default: +// Term_PutChar(*fmt); +// break; + } + } + else + { + Term_PutChar(*fmt); + } + } + va_end (arg); +} + + void Term_PutString(char* s) { for (; *s; s++) diff --git a/uefi/platform.h b/uefi/platform.h index d282b0d..1ec72bd 100644 --- a/uefi/platform.h +++ b/uefi/platform.h @@ -21,6 +21,11 @@ extern char check_uptr[sizeof(uintptr_t) == 8 ? 1 : -1]; #define min(x,y) ((x)<(y)?(x):(y)) #define max(x,y) ((x)>(y)?(x):(y)) +typedef __builtin_va_list va_list; +#define va_start(v,l) __builtin_va_start(v,l) +#define va_end(v) __builtin_va_end(v) +#define va_arg(v,l) __builtin_va_arg(v,l) + /* video memory configuration info */ typedef struct { uint32_t* buffer;