From c099bcb7402421985e6e8c025e8cde591eaa073a Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Tue, 14 Oct 2025 17:54:17 -0700 Subject: Add MAIL_T macro; read framebuffer allocation response --- src/framebuffer.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/framebuffer.c') diff --git a/src/framebuffer.c b/src/framebuffer.c index e3303b6..c3845b1 100644 --- a/src/framebuffer.c +++ b/src/framebuffer.c @@ -2,6 +2,7 @@ #include +#include #include #define WIDTH 640 @@ -9,8 +10,15 @@ #define DEPTH 32 #define ALIGNMENT 16 // Framebuffer byte alignment. +typedef struct Framebuffer { + volatile void* pixels; + size_t size; +} Framebuffer; + +static Framebuffer framebuffer = {}; + bool framebuffer_init(uint32_t* error) { - volatile __attribute__((aligned(MAIL_ALIGN))) uint32_t ConfigureScreen[20] = { + MAIL_T uint32_t ConfigureScreen[20] = { 80, // Size in bytes, aligned to MAIL_ALIGN. MAILBOX_REQUEST, TAG_FRAMEBUFFER_SET_PHYSICAL_SCREEN_SIZE, 8, MAILBOX_REQUEST, WIDTH, HEIGHT, @@ -25,7 +33,7 @@ bool framebuffer_init(uint32_t* error) { goto end; } - volatile __attribute__((aligned(MAIL_ALIGN))) uint32_t InitFramebuffer[8] = { + MAIL_T uint32_t InitFramebuffer[8] = { 32, // Size in bytes, aligned to MAIL_ALIGN. MAILBOX_REQUEST, TAG_FRAMEBUFFER_ALLOCATE, 8, MAILBOX_REQUEST, ALIGNMENT, 0, @@ -33,6 +41,15 @@ bool framebuffer_init(uint32_t* error) { }; mbox_write(PROPERTY_CHANNEL, InitFramebuffer); response = mbox_read(PROPERTY_CHANNEL); + if (response->code != MAILBOX_SUCCESS) { + goto end; + } + + // The input mail is overwritten with the response. + // u32 fb base address + // u32 fb size + framebuffer.pixels = (void*)(uintptr_t)InitFramebuffer[5]; + framebuffer.size = InitFramebuffer[6]; end: *error = response->code; -- cgit v1.2.3