Stephen Smith's Blog

Musings on Machine Learning…

Playing with FreeDOS and GW-Basic

with one comment


Introduction

Continuing with my series on ancient versions of the BASIC programming language, this week we’ll look at GW-Basic which was Microsoft’s BASIC for the original MS-DOS based computers. This predates QuickBasic, Visual Basic and VB.Net. The program is similar to last week’s Applesoft BASIC implementation since both were created by Microsoft. Applesoft was written in 6502 Assembly Language, and then ported to 8088 Assembly Language with minor tweaks. GW-Basic was replaced with QBasic in MS-DOS 5.0. On May 21, 2020, Microsoft open sourced GWBasic and you can browse the source code here.

Getting GWBasic

GWBasic isn’t included with Windows anymore, but since it’s been open sourced, you could build GWBasic from the source code, and several people have done this and made the executable available. I downloaded it from the Internet Archive. It is a single executable, so it only needs to be saved somewhere in your PATH to run. If you run it on Windows 11, you get:

Since Windows doesn’t support running 16-bit programs anymore. You could run it from an MS-DOS emulator, in a manner similar to what we did for the Apple II last time, but instead let’s take a different approach.

Enter FreeDOS

FreeDOS was started in 1994 after Microsoft announced they were no longer supporting MS-DOS and forcing everyone to Windows. It was created as a free open source alternative to allow everyone who loved MS-DOS to keep running free of Microsoft’s control. FreeDOS is a complete operating system and it runs GW-Basic perfectly. If you want to continue running MS-DOS programs like WordPerfect, Lotus 123 or any number of MS-DOS games, then FreeDOS is a great alternative.

Rather than install FreeDOS directly, I installed it in a VMWare image, where it runs great on my Windows 11 laptop. The installation is relatively pain free, using the LiveCD image from FreeDOS’s website. Once running, I needed to copy GWBASIC.EXE to that image. I did this by using AnyBurn to create an ISO image containing GWBASIC.EXE, which I could then mount as a CD-ROM drive from the VMWare player, and then copy GWBASIC.EXE over into a folder in the PATH on the FreeDOS harddrive. Then I typed in the AppleSoft program from last time, made a couple of minor tweaks to the graphics commands, initial screen location, and size and had a working program to again draw a Koch Snowflake.

The full program listing is at the end of this article. To extract the source code you need to save the GWBasic program with the A option so save will save the file in ASCII rather than a tokenized binary format. Then I used WinImage to create a floppy disk image which I could mount in the VMWare player and copy the file to. Note that VMWare loads CDRoms as read-only, so you can’t copy files to them, and I happen to be away from home and didn’t have a USB key which would also work.

Summary

Playing with GW-Basic is fun, and running under FreeDOS is just like running an old pre-Windows PC under MS-DOS. GWBasic has newer features I could have taken advantage of, but it is still of the line number required, fairly simple versions that people tend to be nostalgic for.

If you have any old MS-DOS 16-bit programs you want to run, this is a great way to do it. Kudos to Intel/AMD that you can still run these 16-bit programs, even if Microsoft doesn’t allow it anymore. FreeDOS itself is a 16-bit operating system. 

10 REM Program to Draw a Koch Snowflake
20 DIM DIST(10)
30 DIM LEVEL(10)
40 ST = 1
50 SCREEN 9
55 CLS
60 PRINT "Koch Snowflake (hit enter to continue)"
70 SX = 40
80 SY = 100
90 SA = 0
100 ST = 1
110 DIST(1) = 270
120 LEVEL(1) = 4
130 PI = 3.14159
140 X = SX
150 Y = SY
160 A = SA
170 A = A + 60
180 ST = 1
190 GOSUB 300
200 A = A - 120
210 ST = 1
220 GOSUB 300
230 A = A - 120
240 ST = 1
250 GOSUB 300
255 INPUT T$
260 END
300 REM Snowflake Side Subroutine
310 BR = 0
320 ST = ST + 1
330 IF LEVEL(ST - 1) = 1 THEN BR = 1
340 IF BR = 1 THEN ST = ST - 1
350 IF BR = 1 THEN GOSUB 1000
360 IF BR = 1 THEN RETURN
370 LEVEL(ST) = LEVEL(ST - 1) - 1
380 DIST(ST) = DIST(ST-1) / 3
390 GOSUB 300
400 A = A + 60
410 GOSUB 300
420 A = A - 120
430 GOSUB 300
440 A = A + 60
450 GOSUB 300
460 ST = ST - 1
470 RETURN
1000 REM Tutle Move Routine
1010 OX = X
1020 OY = Y
1030 X = X + DIST(ST) * COS(A*PI/180)
1040 Y = Y + DIST(ST) * SIN(A*PI/180)
1050 LINE (OX,OY)-(X,Y)
1060 RETURN

Written by smist08

October 6, 2022 at 12:35 pm

One Response

Subscribe to comments with RSS.

  1. That is good stuff.

    For the giggles, works A-1 as-is in BASIC Anywhere Machine.

    Program run in your browser:
    https://basicanywheremachine.neocities.org/sample_programs/Koch%20Snowflake.prod.run.html

    Source code exported from BASIC Anywhere Machine:
    https://basicanywheremachine.neocities.org/sample_programs/Koch%20Snowflake.prod.bas.html

    If you want to play with BASIC Anywhere Machine:
    https://basicanywheremachine.neocities.org/BAM_IDE.html

    And lookup keywords in the Programming Reference:
    https://basicanywheremachine.neocities.org/BAM_ProgReference.html

    Charlie Veniot

    January 29, 2023 at 8:32 pm


Leave a comment

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