]> git.mdlowis.com Git - proto/uefi.git/commitdiff
finally fixed scrolling
authorMichael D. Lowis <mike@mdlowis.com>
Fri, 24 Sep 2021 02:25:25 +0000 (22:25 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Fri, 24 Sep 2021 02:25:25 +0000 (22:25 -0400)
core/kernel.h
core/main.c
core/term.c
uefi/platform.h

index 98f5c62d2bee53d4bbfa8c3f56663a5538b8f883..4e35be57f669d1f86d67f2ac874988876eedf7c6 100644 (file)
@@ -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);
index 6a792135b80c3a9c374214c716356960967c3cea..8fd3a767866cc80b3aa40575dd7c2f365d2290ea 100644 (file)
@@ -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;
index 0619e240943a01c4821e89419560d56a02bff0dd..92cf1943cc341019da14d2776a2d20daa5292c9d 100644 (file)
@@ -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++)
index d282b0d52a9b2b2478cac3625ac0fb7130ae7cbe..1ec72bddc09791748423f4bb08695c2d9532e21e 100644 (file)
@@ -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;