Old BASIC interpreters era: is there anything left for today’s PCs? An introduction to Freebasic.

Most 8 bit computers were equipped with a BASIC interpreter directly available in ROM. Microsoft BASIC was the most common interpreter back then. Many BASIC dialects originated, so that they could accommodate for the different computer makes.

Popular 8 bit computers like the Commodore PET, VIC 20, Commodore 64, the Apple II, the Sinclair ZX Spectrum and many others made it possible for many users to learn programming. And BASIC was the most common way to speak to a computer back then.

Any home computer came with a manual explaining BASIC, and that just created a huge amount of programmers that were doing it for fun. I was in that bandwagon too. I was really happy to code simple BASIC programs on my Commodore 64, and the C64 User’s guide was the next best thing to me. It actually omitted many aspects of the Commodore 64 features, but still, I could learn programming by reading it – and that’s something I am very grateful for to Commodore.

BASIC was so common back then that I think nobody ever imagined that it would just fade out. Today, BASIC is no longer common. High schools are focusing on other languages for students, hobby programming today is not as common as it used to be either, so BASIC – a language clearly intended for beginners – wasn’t just able to find a good place among today’s programmers.

BASIC interpreters had a sense when computers did not have an hard disk drive. Most home computers featuring a built-in BASIC in ROM were actually tape based systems. Some BASIC compilers did come up, but they needed at least a floppy disk drive. Something that was not available to all users. Some home computers did not enjoy a standard floppy disk support as well. And those drives were generally expensive.

When computers started to become more powerful and less pricey, compiled languages started to spread among users. And languages like C just outperformed BASIC. Obviously, interpreted BASIC could not just compete – but even compiled BASIC could not produce executables with performances as good as those made with C.

BASIC did have its evolution. On IBM PC clones, we had GW-BASIC, then QuickBASIC, then Visual BASIC… but other kind of languages made it on today’s computers.

Still, if you still want to code BASIC programs on today’s machines there is something that will suit your needs. Freebasic is a nice BASIC compiler available for either Windows or Linux (I have tested it on both platforms). It’s a modern language but still, it retains many aspects of old BASICs. What I like the most of it it’s the ability to provide you with a built-in support for graphics by using custom instructions. That means, you won’t need libraries to do simple experiments with 2D graphics.

Here’s a link to the Freebasic official site. You can download the compiler and look for documentation there.

Freebasic just makes it possible to use graphics as easily as you could do by using QuickBasic for instance. That is also very similar to what you could do by using Commodore 64 Simons’ BASIC or Sinclair BASIC in the 8 bit era. You can just have the easy approach of the past with the speed of today.

Freebasic is something I have learned about very recently. So, I don’t have a deep knowledge of it but I was able to code a very simple program. It’s a new version of the “Sphere” program I coded for the Commodore 64 some time ago. You may refer to that article for further explanations of the algorithm.

The code is quite simple and should have that familiar touch for retrocomputers enthusiasts.

Screen 19
Dim as integer w, h, radius
Dim as single a, an, t

ScreenInfo w, h

a = 3.141592654/2/16
radius = (h/2)-50

For an = a to a * 16 step a

t = 2 * radius * sin(an/2) * cos(an/2)
   Circle (w/2, h/2), radius, 2, , ,radius/t
   Circle (w/2, h/2), radius, 2, , ,t/radius

line (w/2, h/2-radius)-(w/2, h/2+radius), 2
line (w/2-radius, h/2)-(w/2+radius, h/2), 2


A picture of the program output follows. It’s a wireframe sphere made up of many ellipses. Perspective is taken into account by the formula:

t = 2 * radius * sin(an/2) * cos(an/2)


Most instructions are quite easy to grasp. Screen 19 sets the screen mode to be used (1024 x 768 pixels). Origin is on the top, left hand corner.

Variables need to be declared. Suffixes are no longer used. So, integer variables are no longer written as NUMBER% for instance. Some compiling options actually allow some old fashioned syntax, but I am going to use the new rules.

Real numbers are either available as single precision and double precision. I have used single numeric variables here.

ScreenInfo is used to get information dealing with screen size. Using variables for width and height of the screen, you don’t need to modify the program if you later want to change the screen mode.

A simple for … next loop is used to draw the ellipses. For each angle, a new t radius is calculated.

The instruction circle is a bit tricky. It can be used to draw circles and ellipses as well. But to draw an ellipse, you are not supposed to enter both radii. You just have to enter one radius, then the ratio between radii. If the ratio is less than one, the biggest radius will be in the X direction. Otherwise, it will be in the Y direction.

The line instruction is quite easy instead, and it just requires the X, Y coordinates of the two points to join.

Finally, the sleep instruction just waits for a keypress after the sphere have been drawn.

I am quite happy about this language, and I think it will be very useful to make some experiments. I may use it to test some ideas before coding them on the Commodore 64.

Precedente Commodore 64: breaking the 38K RAM barrier from BASIC. Creating an additional 4K BASIC variables storage area. Successivo 3D Graphics: rotating a cube with Freebasic (PC) and Simons' BASIC (C64)

Lascia un commento