Scope decided with Captain Bob before implementation: ring buffer + recall on today's full-screen vt100 grid, not also confining REPL text to the 4.4o 640x480 box (that confinement stays open as its own future item, not a third silent deferral). No keyboard input path exists yet (M8 unstarted), so the trigger is two new FORTH words, SCROLL-BACK ( n -- ) / SCROLL-FWD ( n -- ), exercised via serial injection. vt100.c gains a text-only 1000-line ring buffer (kmalloc'd, tens of KB -- not pixel snapshots, which would be ~1000x larger for no benefit) plus a shadow buffer mirroring the current screen. scroll_up() now pushes evicted rows into the ring before the pixel scroll. History is one continuous sequence (ring then shadow); scrolling always redraws from that sequence -- no separate pixel-scroll path for scrollback, decided up front to avoid retrofitting later. New src/word_source/scroll_words.c (Module 31), thin wrappers over console_fb_scroll_back()/_fwd() -> vt100_scroll_back()/_fwd(). Bug caught during live testing: both words initially used an off-by-one underflow check (dsp < 1) copied from a different, older dsp convention elsewhere in this codebase; vm_pop() (which these words actually call) uses dsp as a 0-based top-of-stack index, so the check rejected every legitimate single-argument call. Fixed by removing the separate precheck and relying on vm_pop()'s own guard. Live-verified on all three architectures (exceeds this item's amd64-minimum bar): generated 50+ lines via a FORTH loop, confirmed SCROLL-BACK recovers correctly older content, and on amd64 confirmed SCROLL-FWD returns to genuinely live state (not a frozen snapshot) by showing the injected commands' own echo. Known limitation confirmed by direct pixel measurement: redrawn lines lose their original SGR color (not stored per-cell) -- text recovers exactly, color does not. Three-arch verified: Failed: 0, dict-hashes identical across all three (values changed correctly from prior items -- two new words were added). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
132 lines
4.1 KiB
C
132 lines
4.1 KiB
C
/*
|
||
StarForth — Steady-State Virtual Machine Runtime
|
||
|
||
Copyright (c) 2023–2025 Robert A. James
|
||
All rights reserved.
|
||
|
||
This file is part of the StarForth project.
|
||
|
||
Licensed under the StarForth License, Version 1.0 (the "License");
|
||
you may not use this file except in compliance with the License.
|
||
|
||
You may obtain a copy of the License at:
|
||
https://github.com/star.4th@proton.me/StarForth/LICENSE.txt
|
||
|
||
This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||
express or implied, including but not limited to the warranties of
|
||
merchantability, fitness for a particular purpose, and noninfringement.
|
||
|
||
See the License for the specific language governing permissions and
|
||
limitations under the License.
|
||
|
||
StarForth — Steady-State Virtual Machine Runtime
|
||
Copyright (c) 2023–2025 Robert A. James
|
||
All rights reserved.
|
||
|
||
This file is part of the StarForth project.
|
||
|
||
Licensed under the StarForth License, Version 1.0 (the "License");
|
||
you may not use this file except in compliance with the License.
|
||
|
||
You may obtain a copy of the License at:
|
||
https://github.com/star.4th@proton.me/StarForth/LICENSE.txt
|
||
|
||
This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||
express or implied, including but not limited to the warranties of
|
||
merchantability, fitness for a particular purpose, and noninfringement.
|
||
|
||
See the License for the specific language governing permissions and
|
||
limitations under the License.
|
||
|
||
*/
|
||
|
||
/**
|
||
* console.h - Serial console + framebuffer VT100 interface for StarKernel
|
||
*
|
||
* Output policy:
|
||
* - Serial UART is always active (initialized by console_init).
|
||
* - When console_fb_init() has been called and the framebuffer is ready,
|
||
* every character is also rendered through the VT100 terminal on screen.
|
||
* - Both outputs are always live simultaneously; serial cannot be disabled.
|
||
*/
|
||
|
||
#ifndef STARKERNEL_CONSOLE_H
|
||
#define STARKERNEL_CONSOLE_H
|
||
|
||
#include <stdint.h>
|
||
#include "uefi.h"
|
||
|
||
/**
|
||
* Initialize serial console (UART).
|
||
* Must be called once during early kernel boot.
|
||
*/
|
||
void console_init(void);
|
||
|
||
/**
|
||
* Initialize the framebuffer VT100 terminal.
|
||
* Call after UEFI boot services have been exited and the GOP framebuffer
|
||
* address is known (from BootInfo). Safe to call with info==NULL (no-op).
|
||
* fmt: FB_PIXEL_BGRX32 is correct for most QEMU / real hardware GOP.
|
||
*/
|
||
#include "framebuffer.h"
|
||
void console_fb_init(const FramebufferInfo *info, FbPixelFormat fmt);
|
||
|
||
/**
|
||
* FABRIC.md item 4.4j: switch the framebuffer console's glyph backend from
|
||
* font_8x16.c to TTF-TEXT's rasterizer. Thin wrapper over
|
||
* vt100_enable_ttf() -- see that function's doc comment for the full
|
||
* contract (lazy font load, cell-geometry/cols/rows recompute, screen
|
||
* clear, one-shot). No-op if the framebuffer console was never
|
||
* initialized (console_fb_init() not called, or it no-op'd on a NULL
|
||
* framebuffer).
|
||
*/
|
||
void console_fb_enable_ttf(void);
|
||
|
||
/**
|
||
* FABRIC.md item 4.4q: thin wrappers over vt100_scroll_back()/
|
||
* vt100_scroll_fwd() -- see those functions' doc comments for the full
|
||
* contract. No-op if the framebuffer console was never initialized.
|
||
*/
|
||
void console_fb_scroll_back(uint32_t n);
|
||
void console_fb_scroll_fwd(uint32_t n);
|
||
|
||
/**
|
||
* Write a single character to serial console
|
||
*/
|
||
void console_putc(char c);
|
||
|
||
/**
|
||
* Write a null-terminated string to serial console
|
||
*/
|
||
void console_puts(const char *s);
|
||
|
||
/**
|
||
* Write a string with newline to serial console
|
||
*/
|
||
void console_println(const char *s);
|
||
|
||
/**
|
||
* Read a single character from serial console (non-blocking)
|
||
* Returns -1 if no character available
|
||
*/
|
||
int console_getc(void);
|
||
|
||
/**
|
||
* Check if character is available for reading
|
||
*/
|
||
int console_poll(void);
|
||
|
||
/**
|
||
* Set the active VM name shown as [Name] prefix on each output line.
|
||
* Pass NULL to suppress the prefix (kernel-only output before any VM).
|
||
* The pointer must remain valid for as long as it is active.
|
||
*/
|
||
void console_set_vm_name(const char *name);
|
||
const char *console_get_vm_name(void);
|
||
|
||
/* Last FORTH word name set by the dispatcher before entry->func(vm).
|
||
* Printed by the #GP fault handler to identify the faulting word. */
|
||
extern volatile const char *g_sk_fault_word;
|
||
|
||
#endif /* STARKERNEL_CONSOLE_H */
|