Show HN: 我写了一个可以在 UEFI 机器上引导的 BASIC 解释器
Show HN: I wrote a BASIC interpreter that boots on UEFI machines

原始链接: https://tarjan.itch.io/thoreaubasic

Thoreau BASIC 是一款现代化的 GW-BASIC 兼容解释器,专为 Windows 和裸机环境设计。它打破了传统的内存限制,利用所有可用的系统内存来支持海量数据数组,并采用了灵活的三指针内存模型。 主要特性包括: * **语言与逻辑:** 完整的控制流、强大的错误捕获(ON ERROR/RESUME),以及对包括 64 位整数在内的多种数值类型的支持。 * **图形与文本:** 支持原生分辨率和 24 位真彩色、精灵/位图处理(LOADBMP/BITBLT),以及带有独立光标和调色板的可定制文本窗口。 * **开发工具:** 包含全屏编辑器、RENUM、AUTO 命令,以及可直接与 UEFI 文件系统交互的完整磁盘 I/O 功能。 * **性能:** 得益于逐行标记缓存(token cache)和优化的表达式求值,近期更新显著提升了执行速度,最高可达之前的 25 倍。 凭借其在裸机上运行的能力,以及对硬件指针、PEEK/POKE 和高精度计时器的现代处理方式,Thoreau BASIC 架起了经典复古编程与现代高性能计算之间的桥梁,使其成为无论是怀旧项目还是复杂计算任务的通用工具。

一位开发者创建了“Thoreau BASIC”,这是一款怀旧的 BASIC 解释器,旨在直接在 x64 UEFI 硬件上启动,无需底层操作系统。该项目旨在复刻 1980 年代 BASIC 那种经典的即时交互体验——包括行号和“Ready”提示符——同时通过 UEFI 提供诸如 32 位色彩、浮点运算和 FAT32 文件支持等现代功能。 该解释器优先考虑与复古 Microsoft BASIC 的行为兼容性,而非现代语言设计。为了确保稳健性,作者目前正在将一款文字冒险游戏移植到该环境中,将其作为严格的测试套件。虽然该项目旨在提供一个小型的独立体验,但它支持文件 I/O,并提供了一个与 Windows 兼容的版本以便于实验。该项目已在 Hacker News 社区引发关注,用户们讨论了其文件系统集成的潜力、作为 EFI 应用程序的技术实现,以及对于在 Commodore 64 等系统上成长起来的程序员所具有的怀旧吸引力。
相关文章

原文

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, ERRON 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/OSAVE, 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.
  • Windows: 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$.
联系我们 contact @ memedata.com