diff --git a/sys/teton/CMakeLists.txt b/sys/teton/CMakeLists.txt index 72498fa..4758b4a 100644 --- a/sys/teton/CMakeLists.txt +++ b/sys/teton/CMakeLists.txt @@ -1,4 +1,5 @@ add_executable(teton + framebuffer/framebuffer.cpp teton.cpp ) diff --git a/sys/teton/framebuffer/framebuffer.cpp b/sys/teton/framebuffer/framebuffer.cpp new file mode 100644 index 0000000..16e8537 --- /dev/null +++ b/sys/teton/framebuffer/framebuffer.cpp @@ -0,0 +1,15 @@ +#include "framebuffer/framebuffer.h" + +#include + +Framebuffer::Framebuffer(const FramebufferInfo& info) : fb_info_(info) { + uint64_t buff_size_bytes = fb_info_.height() * fb_info_.pitch(); + MappedMemoryRegion region = MappedMemoryRegion::DirectPhysical( + fb_info_.address_phys(), buff_size_bytes); + fb_ = reinterpret_cast(region.vaddr()); +} + +void Framebuffer::DrawPixel(uint32_t row, uint32_t col, uint32_t pixel) { + // Div by 4 because pitch is in bytes and fb_ is a 32bit array. + fb_[(row * fb_info_.pitch() / 4) + col] = pixel; +} diff --git a/sys/teton/framebuffer/framebuffer.h b/sys/teton/framebuffer/framebuffer.h new file mode 100644 index 0000000..2d8ec55 --- /dev/null +++ b/sys/teton/framebuffer/framebuffer.h @@ -0,0 +1,16 @@ +#pragma once + +#include + +class Framebuffer { + public: + Framebuffer(const FramebufferInfo& info); + + void DrawPixel(uint32_t row, uint32_t col, uint32_t pixel); + + private: + // FIXME: Implement Yunq copy or move so we + // don't have to store a reference here. + const FramebufferInfo& fb_info_; + uint32_t* fb_; +}; diff --git a/sys/teton/teton.cpp b/sys/teton/teton.cpp index f6222b7..3a9cae2 100644 --- a/sys/teton/teton.cpp +++ b/sys/teton/teton.cpp @@ -2,6 +2,8 @@ #include #include +#include "framebuffer/framebuffer.h" + uint64_t main(uint64_t init_port) { ParseInitPort(init_port); @@ -12,8 +14,17 @@ uint64_t main(uint64_t init_port) { FramebufferInfo framebuffer; RET_ERR(client.GetFramebufferInfo({}, framebuffer)); - dbgln("FB addr {x}, width {} , height {}", framebuffer.address_phys(), - framebuffer.width(), framebuffer.height()); + dbgln("FB addr {x}, bpp {}, width {} , height {}, pitch {}", + framebuffer.address_phys(), framebuffer.bpp(), framebuffer.width(), + framebuffer.height(), framebuffer.pitch()); + + Framebuffer fbuf(framebuffer); + + for (uint64_t r = 0; r < 20; r++) { + for (uint64_t c = 0; c < 20; c++) { + fbuf.DrawPixel(r, c, 0x0000FF00); + } + } // 2. Parse a font file.