Microsoft Open-Sources GW-BASIC

Avatar

Rich

We are excited to announce the open-sourcing of Microsoft GW-BASIC on GitHub!

Yes, seriously ๐Ÿ˜€

Why?

Since re-open-sourcing MS-DOS 1.25 & 2.0 on GitHub last year, we’ve received numerous requests to also open-source Microsoft BASIC.

Well, here we are! ๐Ÿ˜

The Source

These sources, as clearly stated in the repo’s readme, are the 8088 assembly language sources from 10th Feb 1983, and are being open-sourced for historical reference and educational purposes. This means we will not be accepting PRs that modify the source in any way.

A little historical context

The GW-BASIC source code being published is dated Feb 10th 1983. That was quite a while ago, so just to set a little historical perspective:

The week this source was created Men At Work topped the US and UK singles charts with “Down Under”, Dustin Hoffman starred in the #1 US box-office movie, “Tootsie”. In 1983, “Star Wars Episode VI – Return of the Jedi” was released, as was “War Games”! And, Emily Blunt, Kate Mara, Jonah Hill, Chris Hemsworth, and Henry Cavill, were born! Ronald Reagan was President of the USA, and Margaret Thatcher was the UK’s Prime Minister.

That same year, Bjarne Stroustrup was in the middle of developing the first version of the C++ programming language, ARPANET standardized TCP/IP. Borland announced Turbo Pascal, created by Anders Hejlsberg (who went on to join Microsoft, and create J++, C# and TypeScript).

1983 was also the year AT&T released UNIX System V R1, and BSD 4.2 was released, introducing the pseudoterminal for the first time (the progenitor to Windows’ ConPTY we introduced to Windows in 2018 ๐Ÿ˜)

I was 13, and spent every spare second that I wasn’t finishing my homework or doing my chores, writing BASIC and assembly code on one of the hottest home computers of the time – the BBC Micro sporting 32KB RAM (yes, 32,768 bytes, total!), powered by a 6502 processor running at a BLAZING 2MHz. When not coding, I was usually playing one of the most groundbreaking games of all time: “Elite” by David Braben & Ian Bell.

In 1983, Apple launched the 1MHz 6502-powered Apple IIe for US$1,395 (> $3,500 in 2020). Apple also launched the first retail-available computer with a GUI – the Apple Lisa. The Lisa contained a staggering 1MB RAM, and ran the awesome Motorola 68000 processor at an astounding 5MHz, but it cost $9,995 (> $25,000 in 2020 dollars), so all I could do was peer at it through the window of the one computer store in our town authorized to sell Apple’s products … and dream.

And, in 1983 Microsoft released MS-DOS 2.0 (source here), and GW-BASIC for the IBM PC XT and compatibles.

What IS GW-BASIC?

GW-BASIC was a BASIC interpreter derived from IBM’s Advanced BASIC/BASICA, which itself was a port of Microsoft BASIC.

Microsoft’s various BASIC implementations can trace their origins all the way back to Bill Gates & Paul Allen’s implementation of Microsoft’s first product – a BASIC interpreter for the Altair 8800.

During the late ’70s and 80s, Microsoft’s BASIC was ported to many OEM’s specific platform and hardware needs, and for several processors popular at that time, including the 8088, 6502, 6809, Z80, and others.

FAQ

Wait – where’s the C source code?

There is no C source code!

Like much software from the 70s and 80s, and just like the source for MS-DOS, the source code of GW-BASIC is 100% assembly language.

Why assembly? Why didn’t developers use higher-level languages like C, or Pascal?

When developing on/for mainframes and minicomputers of the day, developers were sometimes able to use higher-level languages like FORTRAN, LISP, COBOL, RPG, CPL/BCPL, C, etc. but the compilers for such languages were often hugely expensive, rarely generated efficient code, and were generally unavailable for the space and performance constrained home and personal computers of the day.

When writing software for early PCs, every single byte and every single instruction mattered, so developers often wrote code entirely in assembly language simply to be able to physically fit their software into the available memory, and to be able to access the computer’s resources and internal workings.

Thus, all the source code for GW-BASIC is pure assembly code, translated on a per-processor/per-machine basis from core/master sources.

This source was ‘translated’?

Each of the assembly source files contains a header stating This translation created 10-Feb-83 by Version 4.3

Since the Instruction Set Architecture (ISA) of the early processors used in home and personal computers weren’t spectacularly different from one another, Microsoft was able to generate a substantial amount of the code for a port from the sources of a master implementation. (Alas, sorry, we’re unable to open-source the ISA translator.)

What about other ports?

Many have asked if we can also open-source implementations for processors other than the 808x. Alas, we’re unable to provide sources for these ports and/or customizations.

Enjoy!

We hope you enjoy exploring this fascinating snapshot of what software development looked like during the glorious, exciting, heady days of the ’70s and early ’80s at the dawn of “the personal computer” ๐Ÿ˜

Many thanks to Amy, Julia Liuson, Amanda Silver, and our awesome CELA team for their approval and help finding, reviewing, and open-sourcing GW-BASIC.

62 comments

Leave a comment

    • Avatar
      Rich TurnerMicrosoft logo

      PDS was QuickBASIC bundled with a few extra features & tools (inc. BASIC compiler). It was last released in 1990 – long before C++ became popular for commercial software development on the PC.

      There may be some C in there, but there’s a 90% chance that 90% of the code was all assembler even then.

      And, no, sorry, no plans to OSS QuickBASIC/PDS.

      • Avatar
        Doug Franklin

        90% assembler is about right. I recall that portions of the QuickBasic UI were in C, but the interpreter, runtime, and compiler were all hand-coded assembler. Each code review looked for both size and speed optimizations, with size taking precidence, since we had to fit the user’s code and data into the scarce memory in addition to our own.

      • Avatar
        David Cornelson

        I still have a payroll app I built with this in production. Still own the manuals and probably have the floppy disks somewhere. It was a great platform for building custom DOS-based software.

        I actually have DOSbox and PDS loaded for nostalgia. Itโ€™s a pain to work with, but it works.

        So the only true way to bring it forward would be a complete rebuild of a QBasic compiler from scratch. Has anyone done that?

    • Avatar
      Anthony Foxclaw

      I know one big problem with open sourcing proprietary software is that they often rely on other proprietary software and/or patents associated with them. Finding open source, yet compatible, equivalents can be difficult. It’s why it took Id Software forever to open source the Doom 3 engine.

      • Avatar
        Rich TurnerMicrosoft logo

        GW-BASIC only contains Microsoft-owned IP. It’s also one of the reasons why we cannot provide source for ports to specific OEM hardware – they often required or implemented customizations for their specific architecture, hardware, etc.

        You think I’d risk my career by publishing Microsoft source code without fully reviewing with our legal teams? ๐Ÿ˜œ

        • Steve Jones
          Steve Jones

          Ahh.. That explains why just the 8088 then… Bummer.. I think this is super cool for the retro computer community, and those building single board 8 bit computers of various types just for the learning experience (see Ben Eater’s 6502 series on Youtube for an awesome example!) but I was really hoping this had a chance of being extended eventually to the 6809 (for the TRS-80 COCO) but I guess there could be Tandy/Radio shack IP in there.. ugh..

          Back in the 5150 PC days, when I learned Assembly, I remember just how much it helped to have the IBM published source code to the IBM BIOS. Now a new generation can use this to learn too!

          Thanks for all the effort I’m sure this was.. I saw a thread just a few months ago discussing just how cold it would have to get in hell before this would happen, so although that specific discussion was about the 6502 C64 variant, I’m sure this was no small effort to get through all the red tape that would be protecting this in a company like Microsoft!

          Steve

  • Avatar
    Carlo Santagostino

    I am very happy that Microsoft continues in the work of releasing the sources of its historical software, this is certainly a positive thing. But Rich, I must correct you for the short historical paragraphs that you wrote, you managed to insert a serious historical error: The Apple Lisa wasn’t the first commercially available computer with a GUI but it was the Xerox Star workstation, officially named Xerox 8010 Information System, Introduced by Xerox Corporation on April 27, 1981.
    The Xerox Star (not to be confused with the 1973 Xerox Alto that wasn’t really a commercial system) was the first commercial system to incorporate a window-based graphical user interface with icons, folders, mouse (two-button), Ethernet networking, file servers, print servers, and also e-mail.
    Then, I see that you love your first computer, the BBC Micro, but you’ve had to know that the BBC was hardly known outside UK, worldwide sales are very low. In 1983 the IT world was dominated by Commodore with the Vic 20 and the Commodore 64 (both of them had Microsoft Basic also), and also your beloved 6502 was made by Commodore (in 1983 “MOS Technology” was named “Commodore Semiconductor Group” and fully owned by Commodore).

    • Avatar
      Rich TurnerMicrosoft logo

      Hey Carlo. Thanks – I should’ve been clearer: I don’t believe that the Star was available at retail – only via business-business sales, whereas that Lisa was available at retail. I’ll amend the text above.

      While Commodore’s C64 and Vic20 (and PET, etc.) were indeed very popular here in the US and elsewhere in the world, and indeed in the UK too, the UK had its own explosion of computers:

      The BBC Micro Mode A & B, and/or Electron were present in the majority of UK secondary schools, colleges, and universities throughout the ’80s. They were preceded by the Acorn Atom, and was followed by the Acorn Archimedes which hosted the (then quite novel) Acorn RISC Machine processor. The processor was later spun-off (at Apple’s behest) into Advanced RISC Machines (now ARM Holdings), and renamed the processor to the Advanced RISC Machine – ARM – … derivatives of which now run many of the smartphones we all carry around with us today.

      Sinclair’s ZX-80, ZX-81, and ZX-Spectrum were also enormously popular (you may know clones offered by Timex. Also the Oric-1 and Oric Atmos, the Jupiter Ace (which used Forth as it’s programming language rather than BASIC).

      The Research Machines (RM) LINK’s 380-Z and 480-Z were also popular in some schools and colleges. RM went on to be the major supplier of PC architecture machines into Schools and colleges throughout the UK and much of EMEA and Asia throughout the ’90s.

      Interestingly, Apple had very little footprint in the UK & EMEA in the 80s and 90s – they were just sooo expensive when compared to home-grown tech and PC clones from Asia.

      And yet … despite owning MOS, CSG continued to brand their processors MOS until the late ’80s ๐Ÿ˜œ I’ll make a note above.

      • Avatar
        Carlo Santagostino

        Thank you very much for your reply! Yes, I know the computer history of England (and Europe in general) as I’m italian and in the 80’s I studied in England, my first computer was a Sinclair ZX Spectrum (I also was 13 years old in 1983).
        Regarding the commercial issue or retail (in stores) I do not find relevant differences between the Xerox Star and the Lisa. They had similar commercial policies, dedicated to business and office programs, available in brand stores (Xerox also had its stores like Apple). Xerox also suffered from less recognition in the computer market as it was famous primarily for its photocopiers market domination. Both are to be considered commercial failures for very similar reasons, solved only by the Apple Macintosh which really was the first computer that popularized the window/icon interface and the mouse. So I would say that in general it cannot be said that the Lisa was the first available in stores or retail available since the availability of the Star was pretty the same, if you want you can say that the Lisa was the first Apple computer with icons and mouse, but in the end the most people of that time (like me) knew the mouse with the Apple Macintosh and for years nobody knew even about the existence of the Apple Lisa.

        • Pardha Sai
          Pardha Sai

          What I know is Steve from Apple scrapped the Lisa unit after he became incharge for Lisa. He treated Lisa was a failed product developed by ‘B’ class employees and layed off most of Lisa employees. Although Lisa is part of the Apple, he always treated it as rival.

    • Avatar
      Jim Callahan

      My understanding is that nostalgic memories of the BBC Micro inspired the Raspberry Pi.

      Actually, as Eben Upton himself generously put it:
      “When we started Raspberry Pi, we had a simple goal: to increase the number of people applying to study Computer Science at Cambridge. By putting cheap, programmable computers in the hands of the right young people, we hoped that we might revive some of the sense of excitement about computing that we had back in the 1980s with our Sinclair Spectrums, BBC Micros and Commodore 64s.”
      https://www.raspberrypi.org/blog/ten-millionth-raspberry-pi-new-kit/

      Another account from IEEE Spectrum:
      “In 1988, 10-year-old Eben Upton bought his first computer: a beat-up, secondhand BBC Micro. This little machine was ubiquitous in British schools at the time, not least because it ran a simple programming language called BASIC, which Upton quickly mastered and used to create various games.”
      https://spectrum.ieee.org/geek-life/profiles/eben-upton-the-raspberry-pi-pioneer

      • Avatar
        Rich TurnerMicrosoft logo

        Hey Jim! I am convinced that Eben & team’s approach and positioning was a major reason people paid attention to the Pi from even the earliest days. Note that the Pi wasn’t the first/only cheap single-board computer, but by plugging into the zeitgeist of the 80s I think they plumbed directly into the cerebral memory and pleasure centers of the brains of so many of us who got our start on simple, cheap (ish) home computers in the 80s.

        I wonder jow many early Pi’s were bought for their kids by parents who’d spent most of their youth in front of a BBC, Electron, C64, Speccy, etc. ๐Ÿ˜œ

  • Avatar
    Mikael Bonnier

    I started programming BASIC in the fall of 1981: Luxor ABC80 and Sinclair ZX81 BASIC. About 1983 I learned Forth. It was in spring 1987 that I started to program in Microsoft GW-BASIC, and then I wrote programs to simulate physics, e.g. elastic pendulum in 2D, orbits, and heat conduction. I also programmed Turbo Pascal at this time, but we were required at University to hand in some assignments in GWBASIC. One of the programs later became a success when I translated it into Scratch in 2013: https://scratch.mit.edu/projects/11504974/. The GW-BASIC source code is there too in Notes and Credits section.

  • Avatar
    Mike Colucci

    GW Basic brings back memories as does looking at the 8088 assembler code. I had a few occasions to work with assembler back in the day. In many ways, those early programs were truly magic. Friends and family were amazed even at “Hello World” or “Hello ” (your name).

    Working in such small memory spaces, allocating and un-allocating memory, moving bits, single letter vars. Sloppy programming meant running out of resources. You didn’t throw stuff in because it was “cool”, unlike today where taxing resource limits is near impossible without some horrendous code.

    Then the thrill of assembling, linking and compiling, virtually blind. Something like test flights of a spacecraft. You did your best at engineering but the outcome, well, your mileage could vary, lol.

    Not the good old days, but surely interesting!

    • Avatar
      Rich TurnerMicrosoft logo

      I still think of those as the good old days that taught the value of discipline, patience, care, careful thought and logic.

      Many developers working today have no idea how a computer works under the hood and are astonished that their JavaScript/node apps consume VAST amounts of memory, and run MUCH slower than natively compiled & optimized code.

      I recently spoke with a recent grad from a top-tier US Uni that there’s no way you could write an entire game that rendered 3D graphics in-app into < 32 KB RAM! imagine his surprise … ๐Ÿ˜‰

  • Avatar
    Crefelean Nicolae

    Great news, thanks! ๐Ÿ˜€

    Now I can’t help wonder how much time it could take until we see all the MS-DOS versions open sourced, and even Windows, up to 3.x. ๐Ÿ™‚ I mean having MS-DOS 6.22 + Windows for Workgroups 3.11 would’ve helped a lot of geeks to go through the quarantine with a huge grin on their faces. :))

      • Steve Nickolas
        Steve Nickolas

        I’m aware of Symantec owning MS-DOS 5’s MIRROR, UNDELETE and UNFORMAT by virtue of them devouring Central Point sometime in the 1990s, as well as a bunch of chunks of 6.x. Also, there might be a snarl for anything past 3.0 because of the IBM deal? I’d like to see 3.3, 4.01 or even parts of 5 opened, but I wonder if IBM is a potential obstacle to that.

  • theuserbl
    theuserbl

    Ok, here again my comment.
    I have had written on May 22, 2020 2:13 am and there still stands “Your comment is awaiting moderation.”.
    Now Rich Turner have answered a lot of commets after my one. And my was still not activated. I think the reason could be the integrated links.

    Here the comment I posted, without links:

    Please add on the โ€œreleasesโ€ section of GW-BASIC and MS-DOS on GitHub precompiled โ€ฆ ehโ€ฆ I mean preassembled binaries
    [Link to Github GW-BASIC releases]
    [Link to Github MS-DOS releases]
    With which assembler was GW-BASIC and MS-DOS generated?
    Which assembler can build it today?

    • Avatar
      Rich TurnerMicrosoft logo

      Thanks for re-posting. Your previous posts likely got blocked by our comment filter.

      Sorry – this isn’t a repo for distributing binaries – we’re simply preserving and sharing the source for historical & research purposes.

      Which assembler was used? Good question – depends on the processor architecture being targeted. In the 808x case, likely early versions of Microsoft Assembler – MASM.

      No idea if MASM can still build it – give it a try! ๐Ÿ™‚

      • Avatar
        Diomidis Spinellis

        Thank you Rich for making this available!

        After making a few changes I was able to assemble all files with MASM 5.10A. You can find them, together with a rough Makefile and a linker script, in this repo. Slightly earlier MASM versions might have also worked, but initially I was moving from one MASM version to the next, trying to find one that would assemble all files without an error. In the end, I fixed a few issues by hand. Sadly, many routines are missing from the source code. It seems to me that this source code was coupled with an OEM vendor-specific file that performed low-level stuff, such as clearing the screen.

  • Avatar
    Luis Alonso Ramos

    Awesome!! I remember using GW-BASIC when I was 9 or 10, learning programming in 1991-92.

    10 PRINT “Hi!”
    20 GOTO 100
    100 END

    The most impressive thing for me is the copyright notice in GWMAIN.ASM:

    COPYRIGHT 1975 BY BILL GATES AND PAUL ALLEN

    No Microsoft back then!

  • Avatar
    John Selbie

    Rich,

    Two things that would make this interesting:

    1) Build instructions. Or at least some hints about what tools to us to build gwbasic.exe.

    2) The original sources – not the transpiled output from the ISA translator.

  • Avatar
    Shaun Rossi

    Big thanks for doing this ! I spent so much time in GW-Basic, then later moving on the Qbasic. I often dump old computer programming books, but I’ve kept my GW Basic book all these years. Was so much fun. It will be interesting to poke around the ASM code.

  • Avatar
    Jim Callahan

    Could PDF scans of the original programming manuals be posted?
    Perhaps the original IBM Basic manual that came with the original IBM PC
    or the Compaq Microsoft Basic manual that came with Compaq’s original luggable?

    UPDATE:
    I found this manual:
    https://hwiegman.home.xs4all.nl/gw-man/index.html

    I remember programming a hexdump utility in Compaq Basic.
    This would have been in 1986 or 1987,
    I was trying to emulate this style of output:

    0000: 57 69 6B 69 70 65 64 69 61 2C 20 74 68 65 20 66 Wikipedia, the f
    0010: 72 65 65 20 65 6E 63 79 63 6C 6F 70 65 64 69 61 ree encyclopedia
    0020: 20 74 68 61 74 20 61 6E 79 6F 6E 65 20 63 61 6E that anyone can
    0030: 20 65 64 69 74 00 00 00 00 00 00 00 00 00 00 00 edit………..
    https://en.wikipedia.org/wiki/Hex_dump

    I had had a crash course in C and had a copy of K&R;
    so my starting point was the C copy program which
    reads and writes a character in a “while not eof()” loop.

    GW-Basic had a hex$() function, so I knew I could copy the input character to hex.
    https://hwiegman.home.xs4all.nl/gw-man/HEXS.html

    And GW-Basic had an eof() function, but the example used an if and goto!
    https://hwiegman.home.xs4all.nl/gw-man/EOF.html

    But, there was a WHILE loop implemented as While….Wend.
    https://hwiegman.home.xs4all.nl/gw-man/WHILEWEND.html

    So, I could do a K&R C style While not eof() loop to get one character and convert it to hex with the hex$() function
    then for output formatting I could also output a space before looping back for the the next character. Then I implemented
    a counter to keep track of the number of characters on the output line. I think I decided to output each input line as a “paragraph”
    and then skip an output line before printing the next input line.

    The finishing touch was the line numbers on the left and the original text on the right hand side.

    The program was very slow, but spead up dramatically when I told it to use buffers.
    I don’t see a buffer option in GW-Basic so it may have been an MS-DOS command.

    It would have been routine to add “files=20” and “buffers=20” to the config.sys file,
    but I thought there was a command line option to request buffered I/O when invoking GW-Basic.

    So, I think I wound up writing a MS-DOS batch file that invoked GW-Basic with the hexdump.bas program which
    prompted the user for a filename if it did not find one on the input line.

    The program eventually worked and its use case was identifying problematic characters that caused the file import utilities
    in Lotus 1-2-3 spreadsheet or dBase database to blow up. Once the offending character was identified;
    another “While not eof()” copy program could be written with an IF statement to replace offending character
    with an acceptable substitute such as a space or simply resume with the next character. Often the offending character
    would be a happy face! I recall one time I was trying to import into dBase a file that had been downloaded from an IBM mainframe
    and it turned out to have a column of null characters and dBase stopped at this column and ignored all the data to the right.
    I ran a fix-up “While not eof()” loop program that replaced the null characters with spaces and read in the entire file into dBase.
    I think it may have been a prank by the mainframe programmers; because they were really surprised when I read the whole thing!

    Now most file input routines are more robust or provide more useful error messages. If it became necessary to dump a file; Linux has a hexdump utility.
    And of course with open source software there are many choices for implementation languages from shell scripts to interpreted languages to compiled languages. But, that’s my how we made do in the “old days” story.

  • Pedro Prado
    Pedro Prado

    I was already happy to read you talking how we simply had to use ASM to do useful things, but you got me totally when you mentioned Elite. I played it a lot on the MSX (popular in Brazil).

    Nice article, Commander Jameson!