]> git.mdlowis.com Git - proto/uefi.git/commitdiff
refactored video code
authorMichael D. Lowis <mike@mdlowis.com>
Thu, 16 Sep 2021 02:38:23 +0000 (22:38 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Thu, 16 Sep 2021 02:38:23 +0000 (22:38 -0400)
font.c [moved from uefi/font.c with 100% similarity]
kernel.h [new file with mode: 0644]
main.c
term.c [moved from uefi/term.c with 100% similarity]
uefi/uefi.h
video.c [moved from uefi/video.c with 85% similarity]

similarity index 100%
rename from uefi/font.c
rename to font.c
diff --git a/kernel.h b/kernel.h
new file mode 100644 (file)
index 0000000..8363ca7
--- /dev/null
+++ b/kernel.h
@@ -0,0 +1,29 @@
+#define FONT_WIDTH  8
+#define FONT_HEIGHT 16
+extern uint8_t Font[];
+
+struct Video {
+    uint32_t* buffer;
+    uint32_t stride;
+};
+
+extern struct Video Video;
+
+void Video_Init(void);
+void Video_PutGlyph(int x, int y, char c);
+
+static inline void Video_PutPixel(int x, int y, uint32_t pixel)
+{
+    Video.buffer[Video.stride * y + x] = pixel;
+}
+
+void Term_Clear(void);
+void Term_PutChar(int c);
+void Term_PutString(char* s);
+void Term_PutInt(int64_t val);
+void Term_PutHex(uint64_t val);
+void Term_PutHex8(uint8_t val);
+void Term_PutHex16(uint16_t val);
+void Term_PutHex32(uint32_t val);
+void Term_PutHex64(uint64_t val);
+void Term_PutNewline(void);
diff --git a/main.c b/main.c
index 190f4ff843cf9a2c9236759ca2c9c5f11bf4670e..792286b07c08e3a68458f0161b4c0ab189b5e69d 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1,32 +1,27 @@
 #include <uefi.h>
-
-static void PutIntField(char* label, int val)
-{
-    Term_PutString(label);
-    Term_PutInt(val);
-    Term_PutNewline();
-}
+#include <kernel.h>
 
 int main (int argc, char** argv)
 {
     Video_Init();
-//
-//    char glyph = 0;
-//    for (int y = 0; y < 16; y++)
-//    {
-//        for (int x = 0; x < 16; x++)
-//        {
-//            Video_PutGlyph(
-//                x,
-//                y,
-//                glyph++
-//            );
-//        }
-//    }
+
+    char glyph = 0;
+    for (int y = 0; y < 16; y++)
+    {
+        for (int x = 0; x < 16; x++)
+        {
+            Video_PutGlyph(
+                x,
+                y,
+                glyph++
+            );
+        }
+    }
 
     /* loop forever */
     for (;;)
     {
+        Term_PutString(".");
         BS->Stall(1000000);
     }
 
similarity index 100%
rename from uefi/term.c
rename to term.c
index 1ac5f1d04174238e64f1b887f6eff76429cddd7f..b49a3215b6e2ac9d7532bc12146d8d885a9a0939 100644 (file)
@@ -1232,33 +1232,6 @@ typedef struct {
 #define min(x,y) ((x)<(y)?(x):(y))
 #define max(x,y) ((x)>(y)?(x):(y))
 
-#define FONT_WIDTH  8
-#define FONT_HEIGHT 16
-extern uint8_t Font[];
-
-extern uint32_t* VideoMem;
-extern uint32_t VideoStride;
-
-void Video_Init(void);
-void Video_PutGlyph(int x, int y, char c);
-
-static inline void Video_PutPixel(int x, int y, uint32_t pixel)
-{
-    int offset = (sizeof(pixel) * VideoStride * y) + (sizeof(pixel) * x);
-    *(VideoMem + offset) = pixel;
-}
-
-void Term_Clear(void);
-void Term_PutChar(int c);
-void Term_PutString(char* s);
-void Term_PutInt(int64_t val);
-void Term_PutHex(uint64_t val);
-void Term_PutHex8(uint8_t val);
-void Term_PutHex16(uint16_t val);
-void Term_PutHex32(uint32_t val);
-void Term_PutHex64(uint64_t val);
-void Term_PutNewline(void);
-
 #ifdef  __cplusplus
 }
 #endif
similarity index 85%
rename from uefi/video.c
rename to video.c
index 468de43d1ee8127d2bda00770f02a4516179f3d3..39741ea440535c27247a8360916e70c9e70015ed 100644 (file)
+++ b/video.c
@@ -1,7 +1,7 @@
 #include <uefi.h>
+#include <kernel.h>
 
-uint32_t* VideoMem = NULL;
-uint32_t VideoStride = 0;
+struct Video Video;
 
 void Video_Init(void)
 {
@@ -28,15 +28,15 @@ void Video_Init(void)
     if (status == EFI_SUCCESS)
     {
         status = gop->SetMode(gop, 17); /* pick a smaller resolution for QEMU */
-//        status = gop->SetMode(gop, gop->Mode->MaxMode-1);
+//        status = gop->SetMode(gop, gop->Mode->MaxMode - 1);
     }
 
     /*
         Now let's save off the info we need to draw pixels and glyphs.
         The code in this file assumes 32 bits per pixel.
     */
-    VideoMem = (uint32_t*)(gop->Mode->FrameBufferBase);
-    VideoStride = gop->Mode->Information->PixelsPerScanLine;
+    Video.buffer = (uint32_t*)(gop->Mode->FrameBufferBase);
+    Video.stride = gop->Mode->Information->PixelsPerScanLine;
 }
 
 void Video_PutGlyph(int x, int y, char c)