/* StarForth — Steady-State Virtual Machine Runtime Copyright (c) 2023–2025 Robert A. James All rights reserved. Licensed under the StarForth License, Version 1.0 */ /* scroll_words.c — REPL scrollback entry points (FABRIC.md item 4.4q). * Kernel-only; no-op on hosted builds. */ #include "include/scroll_words.h" #include "../../include/log.h" #include "../../include/word_registry.h" #ifdef __STARKERNEL__ #include "starkernel/console.h" /* SCROLL-BACK ( n -- ) -- move the REPL scrollback view back n lines. * Relies on vm_pop()'s own underflow guard (sets vm->error, logs, returns * 0) rather than a separate dsp precheck -- this codebase has more than * one dsp convention across older word_source files (some treat it as a * top-of-stack index, some as a raw count); vm_pop() is the one this word * actually calls, so deferring to its own check sidesteps the mismatch * entirely instead of risking silently picking the wrong one. */ static void scroll_word_back(VM *vm) { cell_t n = vm_pop(vm); if (vm->error) return; if (n < 0) n = 0; console_fb_scroll_back((uint32_t)n); } /* SCROLL-FWD ( n -- ) -- move the REPL scrollback view forward n lines * (toward live). Same underflow-handling rationale as SCROLL-BACK above. */ static void scroll_word_fwd(VM *vm) { cell_t n = vm_pop(vm); if (vm->error) return; if (n < 0) n = 0; console_fb_scroll_fwd((uint32_t)n); } #endif /* __STARKERNEL__ */ void register_scroll_words(VM *vm) { #ifdef __STARKERNEL__ register_word(vm, "SCROLL-BACK", scroll_word_back); register_word(vm, "SCROLL-FWD", scroll_word_fwd); #else (void) vm; #endif }