Files
LithosAnanake/include/starkernel/framebuffer.h
T
Robert Allan JamesandClaude Sonnet 5 c92be2768f FABRIC.md item 4.4t: confine REPL text rendering to the CANVAS box
vt100's TTF-mode text grid now operates within the per-arch 640x480 box
(computed in 4.4o, pixel-verified in 4.4p) instead of the full framebuffer:
box-origin offset in px_of()/py_of(), box-derived cols/rows (53x20) set
before the 4.4q scrollback allocation depends on them, mode-aware
erase_display()/reverse-index fill, and a new box-scoped fb_scroll_rect()
alongside the existing whole-framebuffer fb_scroll_rows() (bitmap/boot mode
unaffected either way). Also clears the full framebuffer once at the
bitmap-to-TTF switch so leftover boot debris doesn't sit frozen outside the
box now that erase_display(2) is box-scoped afterward.

Three-arch QEMU boot + pixel-scanned screendumps confirm zero non-background
pixels land outside the box on amd64, aarch64, and riscv64.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-11 23:07:04 -04:00

121 lines
4.3 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
StarForth — Steady-State Virtual Machine Runtime
Copyright (c) 20232025 Robert A. James
All rights reserved.
Licensed under the StarForth License, Version 1.0.
*/
/**
* framebuffer.h — UEFI GOP framebuffer driver interface
*
* Pixel format: BGRX32 (PixelBlueGreenRedReserved8BitPerColor),
* the dominant format for QEMU virt GOP. RGBX32 is also supported.
*
* Color values throughout this API are packed as 0x00RRGGBB.
*/
#ifndef STARKERNEL_FRAMEBUFFER_H
#define STARKERNEL_FRAMEBUFFER_H
#include <stdint.h>
#include "uefi.h"
/* Pixel format of the GOP framebuffer */
typedef enum {
FB_PIXEL_BGRX32 = 0, /* PixelBlueGreenRedReserved8BitPerColor (default) */
FB_PIXEL_RGBX32 = 1, /* PixelRedGreenBlueReserved8BitPerColor */
} FbPixelFormat;
/* Pack / unpack 24-bit 0x00RRGGBB color */
#define FB_RGB(r, g, b) \
(((uint32_t)(r) << 16) | ((uint32_t)(g) << 8) | (uint32_t)(b))
#define FB_R(c) (((uint32_t)(c) >> 16) & 0xFFu)
#define FB_G(c) (((uint32_t)(c) >> 8) & 0xFFu)
#define FB_B(c) ( (uint32_t)(c) & 0xFFu)
/* Standard ANSI 16-color palette (indices 015) */
extern const uint32_t FB_ANSI_PALETTE[16] __attribute__((visibility("hidden")));
/* -----------------------------------------------------------------------
* Lifecycle
* --------------------------------------------------------------------- */
/**
* Initialize the framebuffer from UEFI bootloader GOP data.
* Must be called before any other fb_* function.
* fmt: pixel layout reported by GOP (default FB_PIXEL_BGRX32).
*/
void fb_init(const FramebufferInfo *info, FbPixelFormat fmt);
/** Returns 1 if the framebuffer has been successfully initialized. */
int fb_is_available(void);
/* -----------------------------------------------------------------------
* Geometry queries
* --------------------------------------------------------------------- */
uint32_t fb_width(void);
uint32_t fb_height(void);
/** Effective character cell width/height in pixels (8/16 × scale factor). */
uint32_t fb_cell_w(void);
uint32_t fb_cell_h(void);
/* -----------------------------------------------------------------------
* Pixel-level primitives
* --------------------------------------------------------------------- */
/** Write a single pixel. Out-of-bounds writes are silently ignored. */
void fb_put_pixel(uint32_t x, uint32_t y, uint32_t rgb);
/** Fill a rectangle with a solid color. */
void fb_fill_rect(uint32_t x, uint32_t y, uint32_t w, uint32_t h,
uint32_t rgb);
/* -----------------------------------------------------------------------
* Glyph rendering (8 × 16 font cells)
* --------------------------------------------------------------------- */
/**
* Draw one 8×16 character glyph at pixel position (px, py).
* fg / bg are packed 0x00RRGGBB colors.
*/
void fb_draw_glyph(uint32_t px, uint32_t py, uint8_t ch,
uint32_t fg, uint32_t bg);
/* -----------------------------------------------------------------------
* Boot diagnostic
* --------------------------------------------------------------------- */
/**
* One-time boot diagnostic (FABRIC.md item 4.3.1): fills each raster corner
* with a distinct solid color so a screendump reveals orientation. Not part
* of the Console drawing fabric -- diagnostic-only.
*/
void fb_draw_orientation_test(void);
/* -----------------------------------------------------------------------
* Scrolling
* --------------------------------------------------------------------- */
/**
* Scroll the framebuffer up by `char_rows` character rows (each 16 px).
* The vacated rows at the bottom are filled with bg.
*/
void fb_scroll_rows(uint32_t char_rows, uint32_t bg);
/**
* Scroll a sub-rectangle of the framebuffer up by `pixel_rows` pixel rows
* (FABRIC.md item 4.4t: box-confined REPL scrolling). Unlike fb_scroll_rows()
* (whole-framebuffer, fixed 16px-row assumption), this is bounded to
* [x, x+w) x [y, y+h) and takes an explicit pixel-row count so callers with
* a non-8x16 cell height (e.g. TTF mode) pass their own cell height directly.
* Pixels outside the rect are untouched. The vacated rows at the bottom of
* the rect are filled with bg.
*/
void fb_scroll_rect(uint32_t x, uint32_t y, uint32_t w, uint32_t h,
uint32_t pixel_rows, uint32_t bg);
#endif /* STARKERNEL_FRAMEBUFFER_H */