From 53f40b3bf6e7c28ef13476c59a663f2650c76aff Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Wed, 15 Sep 2021 22:38:23 -0400 Subject: [PATCH] refactored video code --- uefi/font.c => font.c | 0 kernel.h | 29 +++++++++++++++++++++++++++++ main.c | 35 +++++++++++++++-------------------- uefi/term.c => term.c | 0 uefi/uefi.h | 27 --------------------------- uefi/video.c => video.c | 10 +++++----- 6 files changed, 49 insertions(+), 52 deletions(-) rename uefi/font.c => font.c (100%) create mode 100644 kernel.h rename uefi/term.c => term.c (100%) rename uefi/video.c => video.c (85%) diff --git a/uefi/font.c b/font.c similarity index 100% rename from uefi/font.c rename to font.c diff --git a/kernel.h b/kernel.h new file mode 100644 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 190f4ff..792286b 100644 --- a/main.c +++ b/main.c @@ -1,32 +1,27 @@ #include - -static void PutIntField(char* label, int val) -{ - Term_PutString(label); - Term_PutInt(val); - Term_PutNewline(); -} +#include 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); } diff --git a/uefi/term.c b/term.c similarity index 100% rename from uefi/term.c rename to term.c diff --git a/uefi/uefi.h b/uefi/uefi.h index 1ac5f1d..b49a321 100644 --- a/uefi/uefi.h +++ b/uefi/uefi.h @@ -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 diff --git a/uefi/video.c b/video.c similarity index 85% rename from uefi/video.c rename to video.c index 468de43..39741ea 100644 --- a/uefi/video.c +++ b/video.c @@ -1,7 +1,7 @@ #include +#include -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) -- 2.54.0