Running QBASIC in a Browser – My Nostalgic Trip Back to the 1990s

Recently, I saw Windows 95 running under Electron. The project definitely brought up some old memories from when I was young and new to computers in the mid-1990s. Back then, I spent all of my time outside of school learning how to write code in BASIC.

I discovered that the Windows 95 under Electron project uses a v86, x86 emulator running in JavaScript, and I decided that it would be fun to experiment with the emulator and get QBASIC up and running in a browser. Maybe I could recreate my programming experience from my childhood, all in a browser!

I was able to get QBASIC running under an MS-DOS 6.22 image by doing the following.

  1. Clone the v86 repository using Git.
    $ git clone https://github.com/copy/v86.git
    
  2. Download a copy of MS-DOS 6.22.
    $ curl https://i.copy.sh/images/msdos.img > msdos.img
    
  3. Build the emulator code.
    $ cd v86 && make build/libv86.js
    
  4. Create a simple HTML page with some basic configuration for the emulator based on the examples provided by the v86 emulator.
    <script src="v86/build/libv86.js"></script>
    <script>
    "use strict";
    
    window.onload = function()
    {
        var emulator = window.emulator = new V86Starter({
            memory_size: 32 * 1024 * 1024,
            vga_memory_size: 2 * 1024 * 1024,
            screen_container: document.getElementById("screen_container"),
            boot_order: 0x312,
            bios: {
                url: "v86/bios/seabios.bin",
            },
            vga_bios: {
                url: "v86/bios/vgabios.bin",
            },
            hda: {
                url: "images/msdos.img",
                size: 8 * 1024 * 1024
            },
            autostart: true,
        });
    }
    </script>
    
    <body style="background: black;">
    
      <div id="screen_container">
        <div style="white-space: pre; font: 18px monospace; line-height: 18px"></div>
        <canvas style="display: none"></canvas>
    </div>
    </body>
    
  5. Use a the Python SimpleHTTPServer to serve the files.
    $ python -m SimpleHTTPServer
  6. Open up the emulator in our browser, http://localhost:8000. The emulator automatically boots into DOS:
  7. Type QBASIC to enter:

    Then, we see my old friend:

  8. Let’s write a line of code:
  9. Let it run:
  10. I experimented with getting some of the SCREEN modes working so that I could do some graphics programming, but I received ILLEGAL FUNCTIONAL CALL errors. Maybe with some more experimentation, I can get that working. In the meantime, it was nice to have a nostalgic trip back to the origins of my programming experience.