framebuffer(2)


NAME
    fb_info, fb_map - direct framebuffer access


SYNOPSIS
    void montauk::fb_info(montauk::abi::FbInfo* info);
    void* montauk::fb_map();


DESCRIPTION
    These syscalls allow userspace programs to access the linear
    framebuffer directly for graphical output.


   fb_info
    Fills in an FbInfo structure with the framebuffer geometry:

        montauk::abi::FbInfo fb;
        montauk::fb_info(&fb);
        // fb.width, fb.height, fb.pitch, fb.bpp

    The pitch is the number of bytes per scanline (may be larger
    than width * 4 due to alignment). bpp is always 32.


   fb_map
    Maps the physical framebuffer into a dedicated region of the process
    address space and returns its address. Programs must use the returned
    pointer rather than assuming a particular virtual address.

        uint32_t* pixels = (uint32_t*)montauk::fb_map();

    Each pixel is a 32-bit value in 0xAARRGGBB format (blue in the
    low byte). Writing to this memory directly updates the screen.


PIXEL FORMAT
        Bits 31-24:  Alpha (unused, typically 0xFF)
        Bits 23-16:  Red
        Bits 15-8:   Green
        Bits 7-0:    Blue

    Example: red = 0x00FF0000, green = 0x0000FF00, blue = 0x000000FF


EXAMPLE
    Fill the screen with blue:

        montauk::abi::FbInfo fb;
        montauk::fb_info(&fb);
        uint32_t* pixels = (uint32_t*)montauk::fb_map();

        for (uint64_t y = 0; y < fb.height; y++) {
            uint32_t* row = (uint32_t*)((uint8_t*)pixels + y * fb.pitch);
            for (uint64_t x = 0; x < fb.width; x++) {
                row[x] = 0x000000FF;
            }
        }


NOTES
    After mapping, the cursor overlay is not composited. Programs
    that use the framebuffer take full control of screen output.

    Only one mapping per process is supported. Calling fb_map()
    multiple times returns the same address.


SEE ALSO
    syscalls(2), malloc(3)

Back to Documentation Index