logo
Kurashizu Blogwhere ideas flow
  • Home
  • News
  • Blog
  • About
  • Home
  • News
  • Blog
  • About

© 2026 Kurashizu. All rights reserved.

Admin·New Post·Service Status
Powered by Cloudflare·03.11.26
← Back to news

I wrote a BASIC interpreter that boots on UEFI machines and ported it to Windows

Original article
tarjan.itch.io|4 points|1 comments|by Gorsefound|Aug 23, 2026

Thoreau BASIC: A Bare-Metal GW-BASIC Interpreter

Created by Tarjan, Thoreau BASIC is a specialized interpreter designed for compatibility with GW-BASIC. Its most striking feature is its ability to run on bare metal via UEFI, though a version for Windows is also provided.

🏗️ System Architecture

Unlike traditional interpreters that require a heavy operating system, Thoreau BASIC interacts directly with the hardware or the Windows environment.


🛠️ Technical Specifications

Memory & Data Handling

The interpreter utilizes a three-pointer memory model, effectively removing the archaic 64KB ceiling. The data segment is dynamically sized based on the maximum conventional memory reported by Windows or the firmware (often reaching several gigabytes).

Supported Data Types:

  • Integers: 32-bit (%) and 64-bit (&).
  • Floating Point: Single and double precision.
  • Strings: Full string support.

Hardware Interfacing

Users can manipulate memory directly using PEEK, POKE, and VARPTR. The following system pointers are available for reading:

PointerDescription
LOMEMLower memory bound
HIMEMUpper memory bound
FREEBOTBottom of free memory
FREETOPTop of free memory
SCRNADRScreen address
GRAPITCHGraphics pitch/stride

🎨 Graphics & Visuals

Thoreau BASIC supports native framebuffer resolution. While SCREEN 1024,768 is the standard boot mode, users are encouraged to use their native resolution for maximum clarity.

Drawing & Color

  • Primitives: PSET, LINE, CIRCLE, and PAINT.
  • Color Modes: Supports 16-color EGA or 24-bit RGB via COLOR r,g,b.
  • Bounds: The variables GRAMAXX/GRAMAXY (graphics) and TXTMAXX/TXTMAXY (text) provide the current boundaries.

Advanced Visuals

  • Bitmaps: Use LOADBMP to read 24/32-bpp Windows .BMP files into a slot. Use BITBLT to render them, including an optional transparency key for sprite-like behavior.
  • Windowing: The WINDOW @n, x1,y1,x2,y2 command creates distinct regions. Commands like PRINT @n, CLS @n, LOCATE @n, and COLOR @n operate independently within these windows.

💻 Programming Features

Control Flow & Logic

The interpreter implements a wide array of classic BASIC structures:

  • DEF FN for functions.
  • GOSUB and ON GOTO/GOSUB for branching.
  • DATA, READ, and RESTORE for embedded data.

Error Management

Robust error trapping is available via:

  • ON ERROR GOTO
  • RESUME, RESUME NEXT, and RESUME n
  • ERR and ERL for error tracking.
  • ON BREAK GOTO

Disk & Editing

  • I/O: SAVE, LOAD, MERGE, FILES, and KILL operate directly on the UEFI Simple File System.
  • Editor: Features a full-screen EDIT mode, AUTO line numbering, and a RENUM command that updates all references (including GOTO, GOSUB, THEN, ELSE, ON, RESTORE, RESUME, and ERL).

Timing

The TIMER variable provides high-precision timing by reading the CPU's invariant Time Stamp Counter (TSC).


📈 Evolution & Performance

The v1.1 Speed Leap

The transition to version 1.1 introduced a massive performance boost—approximately 25×25\times25× faster—thanks to:

  1. A per-line token cache.
  2. A precedence-climbing expression evaluator.
  3. Variable-slot caching.

Benchmark Results:

  • Mandelbrot Set: 230s→<10s\text{230s} \rightarrow \text{<10s}230s→<10s
  • Conway's Game of Life: Now runs interactively.

Version History & Bug Fixes

  • v1.1.3
    • MID$ now supports assignment.
    • ERL not stored/shown on program exit →\rightarrow→ Fixed.
    • INPUT backspace malfunction →\rightarrow→ Fixed.
  • v1.1.2
    • Windows version crashed if RAM < 4GB →\rightarrow→ Fixed.
  • v1.1.1
    • Slow scrolling/framebuffer writes on bare metal →\rightarrow→ Fixed.
    • Added .bas filename autostart.
  • v1.1
    • Added LOADBMP, BITBLT, WINDOW, RENUM, and PEEK/POKE.
    • Implemented exact 64-bit integer math (overflows promote to double).
    • Added full-width HEX$.
  • v1.0
    • Initial milestone.

📦 Installation & Files

Available Downloads

  • ThoreauBASIC-Windows-1.1.3.zip (1.3 MB)
  • Virtual Harddisk (12 MB) — For VM booting.
  • BASIC64.efi (95 kB) — For bare metal.

To boot on bare metal:

# Rename the EFI file and place it in the boot directory
mv BASIC64.efi BOOTX64.EFI
cp BOOTX64.EFI /EFI/BOOT/

Gallery

"I have been messing with buildroot to create the smallest and quickest possible booting basic, and it works, but this solution is much cleaner, and is not relying on any OS." — User Comment