Files
LithosAnanake/include/starkernel/vt100.h
T
Robert Allan JamesandClaude Sonnet 5 f729b91a09 starkernel: retarget REPL glyph rendering to TTF-TEXT's rasterizer (4.4j)
font_8x16.c keeps rendering everything through and including POST;
TTF-TEXT's rasterizer takes over at the interactive REPL boundary
(sk_repl()) via a new runtime mode switch, vt100_enable_ttf()
(console_fb_enable_ttf() wrapper), not a compile-time swap -- both
backends coexist in the same binary since boot/POST must stay
font_8x16.c per this item's own done-when.

TTF-TEXT (the FORTH word) isn't directly callable from vt100.c -- VM
stack arguments, different call shape than a one-glyph cell draw. Used
hal/ttf.c's VM-independent primitives directly instead (same rasterizer
TTF-TEXT itself calls underneath), added as a native C helper in
vt100.c. Lazily loads fonts:JetBrainsMono-Regular.ttf and kmallocs a
96-slot raster cache (covers all 95 printable ASCII, no eviction
thrash) on first switch.

Cell geometry changes at the switch (mode-aware cell_w()/cell_h()):
provisional 12x24 TTF cell (600/1000em * 20px = 12px exactly, using
4.4i's confirmed-uniform hmtx advance width) vs font_8x16's fixed 8x16
-- cols/rows re-derived and screen cleared at the switch point, same as
vt100_init() itself does. Final REPL text size is 4.4m's decision, not
this item's.

Also fixes the second call site 4.4i flagged: erase_line_range() now
uses one fb_fill_rect() instead of a per-cell font_8x16-specific blank
glyph draw, consistent with erase_display(2)'s full-screen case.

Three-arch verified: amd64/aarch64/riscv64 all reach ok>, POST
Failed: 0, identical dict-hashes. amd64 screendump shows real
proportional JetBrains Mono letterforms on the REPL tail, visibly
distinct from every prior font_8x16 screenshot.

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

97 lines
3.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.
*/
/**
* vt100.h — Full-color ANSI / VT100 terminal state machine
*
* Sits on top of the framebuffer driver. Call vt100_init() once the
* framebuffer is ready, then route all character output through vt100_putc().
*
* Supported escape sequences
* ──────────────────────────
* Cursor movement ESC[H ESC[n;mH ESC[nA ESC[nB ESC[nC ESC[nD
* Cursor save/restore ESC[s ESC[u (also ESC7 / ESC8)
* Erase ESC[2J ESC[K ESC[0K ESC[1K ESC[2K
* SGR attributes ESC[…m (see below)
*
* SGR codes
* ─────────
* 0 reset all attributes
* 1 bold (doubles fg brightness)
* 4 underline
* 7 reverse video
* 22 normal intensity
* 24 underline off
* 27 reverse off
* 3037 set fg to standard ANSI color 07
* 38;2;r;g;b set fg to 24-bit RGB truecolor
* 38;5;n set fg to 256-color index
* 39 reset fg to default
* 4047 set bg to standard ANSI color 07
* 48;2;r;g;b set bg to 24-bit RGB truecolor
* 48;5;n set bg to 256-color index
* 49 reset bg to default
* 9097 set fg to bright ANSI color 815
* 100107 set bg to bright ANSI color 815
*/
#ifndef STARKERNEL_VT100_H
#define STARKERNEL_VT100_H
#include <stdint.h>
/* Default terminal colors */
#define VT100_DEFAULT_FG FB_RGB(0xAA, 0xAA, 0xAA) /* light gray */
#define VT100_DEFAULT_BG FB_RGB(0x00, 0x00, 0x00) /* black */
/* -----------------------------------------------------------------------
* Lifecycle
* --------------------------------------------------------------------- */
/**
* Initialize the VT100 terminal.
* Must be called after fb_init(). Clears the screen and homes the cursor.
*/
void vt100_init(void);
/**
* FABRIC.md item 4.4j: switch the glyph-draw backend from font_8x16.c to
* TTF-TEXT's rasterizer for everything drawn from this call onward --
* boot/POST output before this call stays font_8x16.c, unaffected.
* Lazily loads the font capsule and its raster cache on first call
* (no-op on later calls). Recomputes cols/rows for the new cell size and
* clears the screen, since the two glyph backends use different cell
* dimensions. Provisional TTF point size/cell dimensions -- FABRIC.md
* item 4.4m owns the final decision. No-op if the font capsule fails to
* load (stays on font_8x16.c; logged, not fatal).
*/
void vt100_enable_ttf(void);
/* -----------------------------------------------------------------------
* Character output
* --------------------------------------------------------------------- */
/** Feed one byte into the terminal (handles escape sequences transparently). */
void vt100_putc(char c);
/** Feed a null-terminated string. */
void vt100_puts(const char *s);
/* -----------------------------------------------------------------------
* Queries
* --------------------------------------------------------------------- */
/** Terminal width in character columns. */
uint32_t vt100_cols(void);
/** Terminal height in character rows. */
uint32_t vt100_rows(void);
#endif /* STARKERNEL_VT100_H */