deniz.in

Markets

Weather

Loading weather

· via Hacker News – Front Page (native)

Thoreau BASIC: a GW-BASIC interpreter that boots straight into UEFI firmware

Tarjan's Thoreau BASIC is a GW-BASIC–compatible interpreter that boots on bare-metal UEFI hardware without an OS, with gigabyte-scale data segments and a Windows port.

Thoreau BASIC: a GW-BASIC interpreter that boots straight into UEFI firmware

A BASIC that boots before the OS

Thoreau BASIC, published by its author Tarjan on itch.io and now on the Hacker News front page, is a GW-BASIC–compatible interpreter that runs on bare metal: it boots straight from a machine's UEFI firmware, with no operating system in between. A Windows port is available as well. Both builds take the same approach to memory, sizing the interpreter's data segment to the biggest block the firmware or Windows reports as available — on a modern machine, according to the project page, that works out to gigabytes.

Programs load and save as plain ASCII, so listings stay readable and portable in the classic BASIC fashion.

The language surface

The project page describes compatibility with GW-BASIC as close but not total, and the supported surface is broad. Numeric types span 32- and 64-bit integers alongside single- and double-precision floats, plus strings, and line numbers are 32 bits wide. Control flow includes DEF FN, GOSUB, the ON…GOTO/GOSUB family, and DATA/READ/RESTORE. The era's structured error handling is present too: ON ERROR GOTO, the RESUME variants, the ERL and ERR variables, and ON BREAK GOTO.

Graphics, text and sprites

The graphics statements — PSET, LINE, CIRCLE, PAINT and related commands — draw at the native framebuffer resolution, and accept either a 16-color EGA palette or 24-bit RGB values. A SCREEN command requests a mode; the page notes that SCREEN 1024,768 works on almost every machine and is usually what you get at boot. The readable variables GRAMAXX/GRAMAXY and TXTMAXX/TXTMAXY report the actual bounds and update after a mode change.

Bitmaps work through two statements: LOADBMP reads a 24- or 32-bpp Windows .BMP file into a data-segment slot, and BITBLT blits it to the screen with an optional transparent color key, which amounts to sprite support. On the text side, the interpreter uses an IBM VGA 8×16 font with a smoothly scrolling console, and it supports multiple text windows — each with its own cursor and colors — while a plain PRINT still writes to the whole screen.

Memory, disk and editing without the old ceilings

Memory is managed with a three-pointer model and no 64 KB limit; the page says arrays can run to billions of elements. PEEK, POKE and VARPTR are available, along with readable pointer variables such as LOMEM, HIMEM, SCRNADR and GRAPITCH, and HEX$ and OCT$ handle 64-bit values.

Disk I/O — SAVE, LOAD, MERGE, FILES, KILL — runs directly on the UEFI Simple File System, which is what lets the bare-metal build read and write program files without an OS underneath. The TIMER variable is fed by a high-precision clock derived from the CPU's invariant TSC. Editing amenities include full-screen EDIT, AUTO line numbering, and RENUM, which renumbers lines and rewrites every GOTO/GOSUB/THEN/ELSE/ON…/RESTORE/RESUME/ERL reference to match.

Fast iteration

The v1.1 release added a per-line token cache, a precedence-climbing parser for expressions, and variable-slot caching, which the author credits with roughly a 25× speedup on compute-heavy programs: a bundled Mandelbrot demo fell from around 230 seconds to under 10, Conway's Life became interactive, and Lunar Lander now runs at a fixed 100 fps.

Follow-up releases arrived within days. v1.1.1 fixed slow scrolling and framebuffer writes on bare metal, and added Windows autostart when a .bas filename is passed to the executable. v1.1.2 stopped the Windows version from bailing out on machines with less than 4 GB of RAM, fixed BASIC lines at 244 characters excluding line numbers, and corrected an EDIT/LIST bug where line numbers above 32767 displayed as an empty line 0. v1.1.3 made MID$ usable as an assignment target and fixed ERL storage, the error line shown on exit, and backspace handling in INPUT.

Why it matters

GW-BASIC belonged to an era of 64 KB data segments and 16-bit line numbers. Thoreau BASIC keeps the dialect — line-numbered listings, GOTO, PEEK and POKE — but strips away the ceilings, pairing it with gigabyte-scale arrays, 64-bit arithmetic and native-resolution framebuffer graphics. Booting on UEFI makes it more than a nostalgic toy: the interpreter is effectively its own minimal environment at the firmware level, loading and saving files directly through UEFI's file system services. That gives retro-computing fans a practical way to run classic-style BASIC on modern hardware without an emulator, and a glimpse of what 1980s micro-style "computer as BASIC prompt" computing might have looked like with forty years of extra memory underneath.

  • #basic
  • #retro-computing
  • #uefi
  • #interpreter
  • #windows