Show HN: I wrote a BASIC interpreter that boots on UEFI machines

Hacker News Top Tools

Summary

Thoreau BASIC is a GW-BASIC compatible interpreter that runs on bare metal UEFI systems and Windows, featuring modern enhancements like graphics, text windows, and improved performance.

I started writing Thoreau BASIC because I wanted a small, old-fashioned BASIC interpreter: line numbers, immediate mode, simple graphics, strings, arrays, the sort of environment where the computer starts with a &quot;Ready&quot; prompt and you can immediately make it do something.<p>Then I wondered: why should it need an operating system?<p>So I made it boot directly on x64 machines using UEFI.<p>The UEFI version uses the Graphics Output Protocol for its framebuffer and gets its keyboard input directly from the firmware. There is no Windows or Linux underneath it. The machine boots into BASIC.<p>It supports the usual BASIC machinery plus graphics primitives, 32-bit colour, floating point, file operations and other features I&#x27;ve been adding as I encounter programs that need them. There is now also a Windows version, which makes it considerably easier to try.<p>One of my goals is compatibility with the style and behaviour of old Microsoft BASICs rather than creating a modern language that merely happens to use BASIC syntax.<p>I&#x27;m currently porting my text adventure Pixel Prose to Thoreau BASIC. That&#x27;s becoming a much better test suite than artificial tests because every missing feature or subtly wrong behaviour eventually gets exposed by an actual program.<p>The project is deliberately small. The UEFI version greets you with:<p>&quot;I make myself rich by making my wants few.&quot; — Henry David Thoreau<p>followed, somewhat ironically on a modern PC, by something like:<p>27,340,685,312 bytes free<p>I&#x27;d be interested in hearing from people who wrote BASIC in the 80s&#x2F;90s, interpreter&#x2F;compiler people, and anyone sufficiently strange to still find a Ready prompt inviting.
Original Article
View Cached Full Text

Cached at: 08/25/26, 04:52 AM

# Thoreau BASIC by Tarjan Source: [https://tarjan.itch.io/thoreaubasic](https://tarjan.itch.io/thoreaubasic) ### ***Thoreau BASIC*** A GW\-BASIC–compatible interpreter that runs on bare metal \(a Windows version is available, too\)\. The data segment is sized to the largest block of conventional memory the firmware \(or Windows\) reports, which on a modern machine is gigabytes\. **Language** - \(mostly\) GW\-BASIC compatible\. Programs load and save as ASCII\. - Numeric types, including 32 and 64\-bit integers \(`%`,`&`,`&&`\), single and double precision, strings\. - 32 bit wide line numbers\. - `DEF FN`,`GOSUB`,`ON…GOTO/GOSUB`,`DATA`/`READ`/`RESTORE`, and the rest of the control flow\. - Error trapping:`ON ERROR GOTO`,`RESUME`/`RESUME NEXT`/`RESUME n`,`ERL`,`ERR`,`ON BREAK GOTO` **Graphics** - `PSET`,`LINE`,`CIRCLE`,`PAINT`and friends at native framebuffer resolution\. PSET, LINE and PAINT usable with 16 color EGA or 24 bit R,G,B syntax\. - 16\-color EGA palette*and*24\-bit color:`COLOR r,g,b`\(and a background triple\)\. - Bitmaps:`LOADBMP slot, file$`reads a 24/32\-bpp Windows`\.BMP`into a data\-segment slot;`BITBLT slot, x, y \[,key\]`blits it, with an optional transparent color key for sprites\. - `GRAMAXX`/`GRAMAXY`\(graphics\) and`TXTMAXX`/`TXTMAXY`\(text\) are readable variables holding the actual bounds\. - `SCREEN x,y`requests a mode\.`SCREEN 1024,768`works on almost every machine and is usually the boot mode; try your native resolution for a sharper picture\.`GRAMAXX`/`GRAMAXY`update after a`SCREEN`command\. **Text** - IBM VGA 8×16 font, soft\-scrolling console\. - Multiple text windows:`WINDOW @n, x1,y1,x2,y2`carves a region;`PRINT @n`,`CLS @n`,`LOCATE @n`and`COLOR @n`work inside it, each window with its own cursor and pen/paper\. Plain`PRINT`still owns the whole screen\. **Memory & hardware** - A three\-pointer memory model with no 64KB ceiling\. Arrays in the billions of elements, if you want them\. - `PEEK`,`POKE`,`VARPTR`, and readable pointers into the machine:`LOMEM`,`HIMEM`,`FREEBOT`,`FREETOP`,`SCRNADR`,`GRAPITCH`\. - 64\-bit`HEX$`/`OCT$`\. **Disk I/O**—`SAVE`,`LOAD`,`MERGE`,`FILES`,`KILL`, running directly on the UEFI Simple File System\. **Editing**— full\-screen`EDIT`,`AUTO`line numbering, and`RENUM`\(renumbers and rewrites every`GOTO`/`GOSUB`/`THEN`/`ELSE`/`ON…`/`RESTORE`/`RESUME`/`ERL`reference\)\. **Timing**— the`TIMER`variable reads a high\-precision clock from the CPU's invariant TSC\. **New in v1\.2** - CHDIR, MKDIR, RMDIR, FIELD, GET\#, PUT\#, LSET, RSET - CVI, CVS, CVD, MKI$, MKS$, MKD$ - TAB\(\), SPC\(\) - OPTION BASE, ERASE - NAME old$ AS new$ - MERGE - DELETE - CSGN, CDBL - ERROR n, TRON, TROFF - SCREEN \(\) function **New in v1\.1\.3** - MID$ can be an assignment now - ERL wasn't stored and no error line was shown when a program exited with an error - INPUT: backspace didn't work right **New in v1\.1\.2** - When available RAM was less than 4 GB, the Windows version bailed out\. - BASIC lines are now fixed to 244 characters without line numbers\. - EDIT/LIST bug: when line number was greater 32767 it showed an empty line 0 instead\. **New in v1\.1\.1** - Bare metal: Fixed the slow scrolling and writing to the framebuffer\. - Win**d**ows: Added autostart\. You may now call ThorauBASIC with a \.bas filename attached, it will autostart\. **New in v1\.1** - **Much faster\.**A per\-line token cache, a precedence\-climbing expression evaluator, and variable\-slot caching \. Roughly 25× quicker on compute\-heavy programs\. The bundled Mandelbrot dropped from ~230s to under 10s, and Conway's Life now runs interactively\. Lunar Lander runs at a fixed 100 fps now\. - Bitmaps \(`LOADBMP`/`BITBLT`\), text windows with per\-window color,`ON ERROR`/`ON BREAK`/`RESUME`,`ERL`/`ERR`,`RENUM`, and`PEEK`/`POKE`/`VARPTR`\. - Correctness fixes: exact 64\-bit integer math \(overflow promotes to double\), cleaner number formatting, and full\-width`HEX$`\. ## Download Click download now to get access to the following files: ## Development log - [v 1\.2 \- CHDIR, MKDIR, RMDIR and more](https://tarjan.itch.io/thoreaubasic/devlog/1639533/v-12-chdir-mkdir-rmdir-and-more)11 hours ago - [v 1\.1\.3 \- MID$, ERL and INPUT bugs](https://tarjan.itch.io/thoreaubasic/devlog/1638308/v-113-mid-erl-and-input-bugs)1 day ago - [v1\.1\.2 \-](https://tarjan.itch.io/thoreaubasic/devlog/1638164/v112-)1 day ago - [v1\.1\.1 \- Autostart for Windows and scrolling fix for bare metal](https://tarjan.itch.io/thoreaubasic/devlog/1637903/v111-autostart-for-windows-and-scrolling-fix-for-bare-metal)1 day ago - [Windows version is here\!](https://tarjan.itch.io/thoreaubasic/devlog/1637465/windows-version-is-here)2 days ago - [v1\.1 — 25× faster, plus added features](https://tarjan.itch.io/thoreaubasic/devlog/1636874/v11-25-faster-plus-added-features)2 days ago - [v1\.0 milestone](https://tarjan.itch.io/thoreaubasic/devlog/1630056/v10-milestone)9 days ago - [TIMER is now high precision](https://tarjan.itch.io/thoreaubasic/devlog/1621566/timer-is-now-high-precision)16 days ago [View all posts](https://tarjan.itch.io/thoreaubasic/devlog)

Similar Articles

GPT2-BASIC: Portable Machine Intelligence in BASIC

Lobsters Hottest

GPT2-BASIC implements a GPT-style transformer inference engine in FreeBASIC for DOS systems, using fixed-point arithmetic and local model artifacts to run AI-assisted tasks on vintage hardware.

bootai

Reddit r/LocalLLaMA

bootai is an open-source UEFI application that boots directly into an AI chat/code REPL, running Qwen2.5 and SmolLM model inference on bare metal without an OS, with hand-written network drivers and a TCP/IP stack.

Theseus, a static Windows emulator

Lobsters Hottest

Theseus is a new static Windows/x86 emulator that translates programs at compile-time rather than interpreting or JIT-compiling them at runtime, representing an alternative approach to traditional emulation architectures.