summaryrefslogtreecommitdiff
path: root/kernel/source/framebuffer.cpp
diff options
context:
space:
mode:
authorBenji Dial <benji@benjidial.net>2024-05-18 21:53:38 -0400
committerBenji Dial <benji@benjidial.net>2024-05-18 21:53:38 -0400
commitb1a912a8a6ff472a49b2e0a09cfd433adfc2cb24 (patch)
tree5009d4415ba13e4baa37f3d0271852528130fd3b /kernel/source/framebuffer.cpp
parenta8a80d326de9550b2a25b1255a2093ab43219ede (diff)
downloadhilbert-os-b1a912a8a6ff472a49b2e0a09cfd433adfc2cb24.tar.gz
reorganization, cross compiler
Diffstat (limited to 'kernel/source/framebuffer.cpp')
-rw-r--r--kernel/source/framebuffer.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/kernel/source/framebuffer.cpp b/kernel/source/framebuffer.cpp
new file mode 100644
index 0000000..ab1b3d7
--- /dev/null
+++ b/kernel/source/framebuffer.cpp
@@ -0,0 +1,40 @@
+#include <hilbert/kernel/application.hpp>
+#include <hilbert/kernel/framebuffer.hpp>
+
+namespace hilbert::kernel::framebuffer {
+
+ uint64_t paddr;
+ static uint32_t *vaddr;
+ int width;
+ int height;
+ int dword_pitch;
+
+ void init_framebuffer(uint64_t paddr, uint64_t vaddr,
+ uint64_t width, uint64_t height, uint64_t pitch
+ ) {
+
+ //TODO: assumes 32-bpp rgb
+
+ framebuffer::paddr = paddr;
+ framebuffer::vaddr = (uint32_t *)vaddr;
+ framebuffer::width = width;
+ framebuffer::height = height;
+ dword_pitch = pitch / 4;
+
+ }
+
+ color encode_color(uint8_t r, uint8_t g, uint8_t b) {
+ return ((uint32_t)r << 16) | ((uint32_t)g << 8) | (uint32_t)b;
+ }
+
+ void set_pixel(int x, int y, color c) {
+ vaddr[y * dword_pitch + x] = c;
+ }
+
+ void fill_color(color c) {
+ for (int y = 0; y < height; ++y)
+ for (int x = 0; x < width; ++x)
+ vaddr[y * dword_pitch + x] = c;
+ }
+
+}