6 ms·
Show HN: I wrote a BASIC interpreter that boots on UEFI machines
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 "Ready" prompt and you can immediately make it do something.
Then I wondered: why should it need an operating system?
So I made it boot directly on x64 machines using UEFI.
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.
It supports the usual BASIC machinery plus graphics primitives, 32-bit colour, floating point, file operations and other features I've been adding as I encounter programs that need them. There is now also a Windows version, which makes it considerably easier to try.
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.
I'm currently porting my text adventure Pixel Prose to Thoreau BASIC. That'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.
The project is deliberately small. The UEFI version greets you with:
"I make myself rich by making my wants few."
— Henry David Thoreau
followed, somewhat ironically on a modern PC, by something like:
27,340,685,312 bytes free
I'd be interested in hearing from people who wrote BASIC in the 80s/90s, interpreter/compiler people, and anyone sufficiently strange to still find a Ready prompt inviting.
- deleted 1mo ago[deleted]
- JoeAltmaier 1mo agoVery cool! The raw-metal boot part is impressive. BASIC requires more support than you'd expect. Here's an interpreter, with a similarly long list of features it has to support: https://www.moondew.com/basic/index.htm https://www.moondew.com/basic/index.htm
- dlcarrier 1mo agoI learned to program on the Commodore 64 and in QBASIC in th 90's. I'll give it a try. Considering how much it supports, if it could chainload a full operating system, it would make a great replacement for GRUB or rEFIt.
- Gorsefound 1mo agoThat's an interesting idea. :-)
- edoceo 1mo agoWhat's wrong with those bootloaders? Maybe try syslinux?
- skrellm 1mo ago> it would make a great replacement for GRUB or rEFIt. Try https://gitlab.com/bztsrc/easyboot https://gitlab.com/bztsrc/easyboot
- glimshe 1mo agoThis is a great project. How do you handle saving/loading data? You mentioned file operations but you need some sort of file system - perhaps FAT32 - to support that. I'd need that to consider using it on UEFI. One thing you could use for more test cases is the book 101 BASIC Computers Games by David Ahl. Games always encouraged people to use computers and that's as classic as it gets!
- WalterGR 1mo ago> How do you handle saving/loading data? The linked page has this to say: "Disk I/O — SAVE, LOAD, MERGE, FILES, KILL, running directly on the UEFI Simple File System."
- Gorsefound 1mo agoThat's right. It uses UEFI's FAT32.
- fuzzfactor 1mo agoIf you have a PC mainboard whose UEFI supports NTFS, does that filesystem work too?
- skrellm 1mo ago> If you have a PC mainboard whose UEFI supports NTFS, does that filesystem work too? Yes. The UEFI Simple Filesystem Protocol is transparent to the UEFI app. The protocol gives you open/read/write/close calls, without needing to know the underlying fs.
- jonjacky 1mo agoVery nice! I am curious how you built your BASIC as an EFI application. I didn't find any source code or build instructions in the downloads. I am investigating whether it would be feasible to do something similar for Python.
- NegativeLatency 1mo agoMaybe the embedded python flavors would be a good fit?
- shakna 1mo agoNot the author. But binding micropython and posix-uefi is a weekend project. [0] [0] https://gitlab.com/bztsrc/posix-uefi https://gitlab.com/bztsrc/posix-uefi
- Gorsefound 1mo agoIt's C code compiled with MSVS. Not sure about a FOSS release yet. I'm still in the early stages of experimenting.
- jonjacky 1mo agoThanks, this is helpful.
- ale42 1mo agoGreat, nice project! In the time of Electron bloat, it's really refreshing to see bare-metal UEFI stuff.
- fuzzfactor 1mo agoLooking at the download sizes: UEFI "native" 114kb Windows version 1.4mb VHD version 12.6mb None of them are huge but it does emphasize how much difference in resource savings is available if your program can run directly on "bare metal" without even an OS at all.
- ale42 1mo agoNot sure why the Windows version would be much bigger than the bare metal one. If you use native code, the code size overhead from using native GDI calls to draw the window is almost zero. Didn't check if the Windows version uses some GUI toolkit that inflates the size.
- skrellm 1mo ago> Not sure why the Windows version would be much bigger than the bare metal one. That's probably because there's a bug in the linker, which puts uninitialized variables in the data segment instead of bss. This means unlike the bare metal variant, the Windows executable is full of zeros. This is a well known bug (see https://github.com/msys2/MINGW-packages/issues/18612 https://github.com/msys2/MINGW-packages/issues/18612 for example) which also affects my projects: https://gitlab.com/bztsrc/skandi https://gitlab.com/bztsrc/skandi The Linux CLI version is 216K, the Windows CLI version is 5.4M and the only difference is the lack of bss.
- convolvatron 1mo agoUEFI supports device discovery, TCP/HTTP, transfers to raw disks, filesystems, memory management and a bunch of other facilities. while it lacks a general process model and multitasking, I'm not sure its really correct to call UEFI programs bare metal.
- polaris64 1mo agoI really like this! I started a personal project a long time ago to boot a Raspberry PI into an environment like this, the idea being to bring back the good old days of the ZX Spectrum, Amstrad CPC, Commodore 64, etc. I had to abandon the project but seeing this makes me want to resurrect it.
- dragonfax 1mo agoI know at least old Apple systems had a full Forth interpreter in their bootloader.
- Someone 1mo agoOpenFirmware, developed by Sun, used by Sun, Apple, IBM and ARM, according to Wikipedia (https://en.wikipedia.org/wiki/Open_Firmware https://en.wikipedia.org/wiki/Open_Firmware)
- roryirvine 1mo agoNot FOSS? That's a real pity. I learned to program on 8 bit micros, and created a rough boot-to-BASIC experiment ~15 years ago following the JeOS pattern. So this project sounds really exciting, but I'd be more interested if I weren't restricted to being a passive end user.
- skrellm 1mo agoI agree, it's a shame it's not FOSS. Besides UEFI, it has a Windows GDI port, but if it were FOSS one could add SDL backend for example and then one could compile it for Linux and Webassembly as well.
- avadodin 1mo agoAny BASIC is FLOSS if it provides full PEEK and POKE implementations. > PRINT PEEK ( A ) 88 > A: pop %rax
- trashb 1mo agoThis is great! Allowing anyone to program like it is the 1980s and bring them back to their hardware somewhat. I think it will also find it's way to the permacomputing crowd since UEFI is so ubiquitous these days it may be a good platform for that can offer modern features with a understandable interface.
- Rygian 1mo ago"The machine boots into BASIC" :-) I was 8 or 9 years old when the ZX Spectrum +2 arrived home. I'm seriously considering installing this on an old laptop and giving it to my son when he's 8 years old, together with a hard-copy of a BASIC reference and a few simple programs and games to type in. Getting a FAT32 filesystem on day 1 is already a huge jump from my childhood experience (loading from tape).
- StilesCrisis 1mo agoAs a parent who had a very similar experience growing up, I've tried putting BASIC in front of my young kids. It didn't work at all; the magic just isn't there anymore. If you've got an iPad, there's unfortunately no wonder in "I can make the computer do whatever I want". Also, kids know how modern computers are supposed to look and feel, and BASIC won't get them there. Sorry.
- raverbashing 1mo agoThat sounds more like an opportunity to rethink how a new beginner language for modern computers should look like (Maybe something more like Hypercard I guess - or something that renders to HTML)
- unrented7977 1mo agoThat's why they made Scratch, which seems to have been fairly successful
- skrellm 1mo agoVisual programming is not for everyone. I have two kids, one loves Scratch, the other despises it. Fun fact, Scratch wasn't the first iteration of visual programming, and one could argue that Lego NXT was even more successful. https://www.nxtprograms.com/help/learn.html https://www.nxtprograms.com/help/learn.html
- StilesCrisis 1mo ago
- sras-me 1mo agoI am on a similar quest with https://hackage.haskell.org/package/spade https://hackage.haskell.org/package/spade But it is not bare metal yet and it is not BASIC.
- wahid_seddiqi 1mo ago[flagged]
- deleted 1mo ago[deleted]
- saidnooneever 1mo agothis is actually a really cool project been thinking of something like this ever since i saw a dudes Pascal (amd64) uefi loader and OS project looks like a lot of fun to explore and learn from thank you
- jonjacky 1mo agoMaybe that was https://github.com/TYDQSoft/UEFIPascalOS https://github.com/TYDQSoft/UEFIPascalOS
- scotty79 1mo agoYou should put it on bootable USB stick.
- timonoko 1mo agoOff-topic, but some average AI would have made all this in 7 seconds.
- allenrb 1mo agoAnd machines could hit a baseball or drive a race car better than any human, but we still want to see people doing things.
- timonoko 1mo agoNo we do not. There is correct time and correct season for everything. -- 3 points by timonoko 11 days ago: Turbo Pascal on CP/M, MSX-DOS and MS-DOS: I wrote Pascal for 8080 in 1976 and Finnish Army even paid some money for it. I was truly disappointed that Turbo Pascal did not copy my handy PORT-metavariable. You can write & read IO-ports without any extra hässle: https://photos.app.goo.gl/qeJpYb94XzLBCE139 https://photos.app.goo.gl/qeJpYb94XzLBCE139
- andrewww95 1mo ago[flagged]
- vancekai 1mo ago[dead]
- jonjacky 1mo agoWhat hardware have you run the UEFI version on? Can you assume that pretty much any computer these days provides UEFI firmware that supports ThoreauBASIC, or might some computers provide only a cut-down UEFI that doesn't provide all the functions you need? Is there some way to investigate the UEFI implementation on any computer? Can you get to the UEFI shell on any computer somehow or is the UEFI shell a separate application you have to download from somewhere and install? I realize these questions are getting far afield from what you wanted to tell us about, but UEFI is still kind of a mystery despite being installed almost everywhere -- it's hard to find explanations about it.