I wrote a BASIC interpreter that boots on UEFI machines and ported it to Windows
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:
| Pointer | Description |
|---|---|
LOMEM | Lower memory bound |
HIMEM | Upper memory bound |
FREEBOT | Bottom of free memory |
FREETOP | Top of free memory |
SCRNADR | Screen address |
GRAPITCH | Graphics 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, andPAINT. - Color Modes: Supports 16-color EGA or 24-bit RGB via
COLOR r,g,b. - Bounds: The variables
GRAMAXX/GRAMAXY(graphics) andTXTMAXX/TXTMAXY(text) provide the current boundaries.
Advanced Visuals
- Bitmaps: Use
LOADBMPto read 24/32-bpp Windows.BMPfiles into a slot. UseBITBLTto render them, including an optional transparency key for sprite-like behavior. - Windowing: The
WINDOW @n, x1,y1,x2,y2command creates distinct regions. Commands likePRINT @n,CLS @n,LOCATE @n, andCOLOR @noperate independently within these windows.
💻 Programming Features
Control Flow & Logic
The interpreter implements a wide array of classic BASIC structures:
DEF FNfor functions.GOSUBandON GOTO/GOSUBfor branching.DATA,READ, andRESTOREfor embedded data.
Error Management
Robust error trapping is available via:
ON ERROR GOTORESUME,RESUME NEXT, andRESUME nERRandERLfor error tracking.ON BREAK GOTO
Disk & Editing
- I/O:
SAVE,LOAD,MERGE,FILES, andKILLoperate directly on the UEFI Simple File System. - Editor: Features a full-screen
EDITmode,AUTOline numbering, and aRENUMcommand that updates all references (includingGOTO,GOSUB,THEN,ELSE,ON,RESTORE,RESUME, andERL).
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 faster—thanks to:
- A per-line token cache.
- A precedence-climbing expression evaluator.
- Variable-slot caching.
Benchmark Results:
- Mandelbrot Set:
- Conway's Game of Life: Now runs interactively.
Version History & Bug Fixes
- v1.1.3
MID$now supports assignment.Fixed.ERLnot stored/shown on program exitFixed.INPUTbackspace malfunction
- v1.1.2
Windows version crashed if RAM < 4GBFixed.
- v1.1.1
Slow scrolling/framebuffer writes on bare metalFixed.- Added
.basfilename autostart.
- v1.1
- Added
LOADBMP,BITBLT,WINDOW,RENUM, andPEEK/POKE. - Implemented exact 64-bit integer math (overflows promote to double).
- Added full-width
HEX$.
- Added
- 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