Ben Eater Vs. Microsoft BASIC

[Ben Eater]’s breadboard 6502 computer is no stranger to these parts, so it was a bit of a surprise that when [Mark] wrote in asking us if we’d covered [Ben]’s getting MS BASIC running on the breadboard, that our answer was “no”. Well, that changes today!

This is a three-part video series, documenting how [Ben Eater] ports a 1977 version of MS BASIC to his 6502-based computer. The first video is all about just getting the BASIC up and working. It’s full of detail about how MS BASIC adapts to different architectures on the inside, and [Ben] essentially defines his own along the way.

Once he has BASIC working, the next two videos are about making it work not just with the serial terminal that he has attached, but also with the LCD display peripheral he has plugged into the breadboard. BASIC fans will not be surprised to see that it’s all about using POKE. But that ends up being to slow, so he extends it out with his own LCDPRINT command written in assembly.

Now that he can write a character to the LCD, he wants to be able to pass it a string: LCDPRINT “Hello world”. But that requires his command to be able to parse a string, and this has him diving down the rabbit hole into how MS BASIC parses strings, handles evals, and so on. If you want to know how MS BASIC works on the inside, this is the video for you. This video makes a lot of use of wozmon, which seems an almost ideal tool for this kind of low-level poking around.

All of this is done in [Ben]’s very well rehearsed, accessible, but pulling-no-punches style. Get ready to nerd out. All three of the videos are embedded just below the break.

While it’s not the Altair BASIC that Bill himself was writing about last week, it’s probably a direct descendent, and reading about the Altair version was what spurred [Mark Stevens] to send us the tip. Thanks!

12 thoughts on “Ben Eater Vs. Microsoft BASIC

  1. I’ve been working with MS-BASIC since the original TRS-80, and I’ve seen and disassembled most of the different versions for all the different CPUs. It’s really fun that there are enough versions of the original source code out there to understand how it works and to hack on it. The recent Bill Gates source release only adds to the fun.

    I’ve been messing around with the 68HC11 lately, and have a 4-chip configuration with 32K RAM, and a 68HC11D0 with a built-in 4K Buffalo monitor. The 6502 source that’s out there can be applied very well to a disassembly of the 6800 version. It takes me about 20 seconds to upload BASIC as S19 records, and a few seconds more to paste in the program to run on it. I’ve just rebuilt it on stripboard because I got tired of it flaking out every time I looked at the breadboard wrong, and because three of the chips have pins that line up nicely for stripboard.

    Since the 68HC11 has one of the first ever built-in SPI ports, I’m having it talk to one of those 8-digit MAX7219 displays. I got that up and running as a BASIC program because it may be slow, but it lets me make changes easily. There’s not enough port pins left for a keypad, but I think I can do it by adding a 74LS164. My short term goal is to make a tiny trainer system with it. I’m keeping my eyes open for a tiny suitcase to build it into.

    1. So, you converted 6502 BASIC to the 68HC11, but only using 6800-compatible assembler? That seems a bit surprising when the 68HC11 is quite a bit more powerful.

      PS. See my later comment on the AIM-65.

      1. I applied most of the 6502 version source code’s labels to a disassembly of the Altair 680 version, and a lot of comments too. I’ve been working on an interactive disassembler where I can add labels and comments, which makes it a lot easier. (I’ve also got a TRS-80 diassembly with a lot of labels from the Altair version.) It really helps to understand the code. It’s still mostly the 6800 version, with only a few uses of the ABX opcode taken from the MC-10 version. There were also a lot of places where the D register opcodes were used to move two bytes at a time, but that would have made my source too messy for now.

        The thing which most people don’t realize about the 6800 (and I didn’t until I tried actually writing 6800 code!) is that it only has one index register. This means there are two ways to do a memory copy loop: either keep swapping the X register into and out of memory for every byte you move, or what Microsoft did, which is to disable interrupts and abuse the stack pointer. When I stop being busy playing with hardware, it would be nice to take some time to clean up those memory copy loops to use the Y register.

        I’m still sore that after the perfection that was the 6809 and all its addressing modes, Motorola tossed it all aside with the microcoded 68HC11 and its descendants. The only thing the 6800 group learned from the 6809 was “I guess we need a second index register.” It did, however, go on to inspire the 68000 design.

  2. The HC11 is my first love. The architecture was so simple, so clean, so straightforward, so intuitive; its assembly code read like fine music. Who needs higher languages? Eventually I moved on to 8051, because Motorola wanted a kings ransom for those chips, and HC11 didn’t do flash. What a dumpster fire MCS51 was… but Atmel had a flash version and it was was cheaper. The early AVRs had it all, flash; cheap enough; and clean enough of an architecture. I still use AVRs these days even though they no longer are the optimal choice, but I’m becoming an old fart set in his ways.

  3. Back in the late 1970’s I bought the MS-BASIC ROMs for my Synertek Sym-1. That version of BASIC was a bit limited, however, since it did not include trigonometric functions. Luckily, Synertek published a hack that would add these functions using a few dozen bytes of RAM. Then a guy named Jack Brown from Vancover, Canada published a series of “extensions” for the Sym’s MS-BASIC that added lots of functionality like “Enhanced Save”. As I recall, he wrote that he had figured out how to link-in any kind external function into BASIC. His extended command were preceeded it with a “#” character. Those were good, exciting days!

  4. Similarly, I am a bit surprised that 8052 AH-BASIC has apparently not been mentioned on Hackaday.
    Although a search:
    https://html.duckduckgo.com/html?q=8052+ah-basic

    Also finds a project on hackaday.io
    https://hackaday.io/project/189145-8052ah-basic-single-board-computer

    Euhm, not this one:
    https://nl.wikipedia.org/wiki/AH_Basic
    :)

    Back in the ’90-ies Intel used to sell microcontrollers pre-programmed with a basic interpreter. It’s briefly mentioned on:
    https://nl.wikipedia.org/wiki/AH_Basic

    And over the years, the project has been reverse-engineered, cloned, copied, improved, and I think even the original version has been officially open sourced.

    I never looked into this myself. Maybe it’s my limited mind, but I do not see a significant advantage of using an interpreter on a microcontroller. Once you have a PC (& programmer) to program the thing, pushing your ascii through an compiler is a very small extra (except from the initial environment setup), and a 10x speed bump far outweighs the small extra complexity. On top of that, I’m biased. I never liked basic (too simple, too many arbitrary limitations and different dialects) and the first serious program I bought was Borland Turbo C++, back when I still had a PC which ran DOS.

    I do find microPython (mildly) interesting though. Mainly because it has the REPL mode, which can be used as a simple operating system to load and run programs. This makes it possible to write (and modify) some uC program with nothing but a console / terminal (emulator). But the project appears to never have gained much traction. It would be nice if a simple editor (such as for example nano) would be ported to micropython. MicroPython does have the potential to outclass and outperform the home computers of the ’80-ies, and that all in a single chip (add voltage regulator, FLASH storage and some more for extra convenience).

    1. Borland Turbo C++ is not a “program” (BASIC might have taught you that) and what is this “bought” you speak of? “I do find microPython (mildly) interesting though.” Ah! Both munificent and cromulent.

    2. There were a few other microcontroller BASICs, but by the time they were around, classic 8-bit micros were cheap enough for embedded use, and desktop computers were more than capable of supporting development with a C compiler in cases where the code was too complex for plain assembly language. The other ones that I can think of are Z8 Basic (the Z8 never achieved the popularity of 8051), and the Basic Stamp, which ran on PIC.

      I vaguely recall that some of these required a desktop computer as part of the development progress, rather than giving you REPL on a bare CPU. (which is the mode I’ve been enjoying on 68HC11 lately) The main problem is that microcontroller chips often only had access to a few hundred bytes of RAM, which is not suitable for a desktop-style BASIC environment. Then what you end up doing is merely writing your code in BASIC instead of assembly language. And more modern CPUs (ARM and AVR), that do often have enough RAM and plenty of CPU cycles to spare, have designs that are a good fit for generating C code.

  5. My understanding is that MS BASIC for 6502 is pretty much a direct port of BASIC-80. This includes some techniques that are less efficient than they could be, thanks to that heritage.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.