For Retro Computing Enthusiasts

VICreations

By Dan Carmichael — originally published in COMPUTE!’s Gazette Volume 1, Issue 1

Let me tell you a little about myself first and then we’ll get down to an interesting technique you can use – how to speed up your BASIC programs.

After studying computer science in the late 1960s, I entered the world of “data processing” at a relatively early stage in the computer revolution. My first job in the field involved what were then considered ultra-giant computers – IBM 370 168’s. With a memory capacity of around eight million bytes, the 168’s provided the programmer with a lot of room to work in.

I was so used to the large memory of these machines that when the first personal computers hit the consumer market around 1977, I was hesitant to buy one. After all, I figured, what can 16K offer to a programmer who is accustomed to working with millions of bytes of memory? I continued to resist home computers until 1981 when the VIC-20 hit the market. Its price – $300 then – was low enough to justify the experiment.

I bought one, and was pleasantly surprised. Amazed might be a better word. To put it simply, the VIC turned out to be a scaled-down version of the IBMs I loved so much. Just less memory, that’s all. The VIC screen editor was surprisingly sophisticated. You can easily and quickly move the cursor anywhere you want to and change things efficiently on screen. (Many other computers have cumbersome editing.) And the other internal workings of the VIC turned out to be similar to the IBMs. Even the BASIC language in the VIC was very much like the BASIC emulator in the large IBMs. I’ve been fascinated with my VIC ever since. Like a good book, it’s hard to pull yourself away from it.

Future Columns

This monthly column will contain everything from useful bits of information for the beginner (did you know that if you type POKE 650,128 and hit RETURN, every key on the keyboard will “repeat” if you continue to hold it down?) to helpful tutorials for the intermediate-level programmer.

We’ll look at the best VIC software as it comes on the market and talk about the best new games. We’ll even get into how to go about writing some games of your own. And there’ll be useful programs and utilities to help you get the most out of your amazing “little” computer.

Above all, we’ll explore the programs, techniques, new products, and discoveries that should make for many hours of fun, and fascination, with your VIC.

Speedy Variables

Sometimes one of the biggest problems when programming with BASIC (especially in writing games) is figuring out how to make the program run fast enough. It’s no good playing slow-motion Ping Pong. There are ways, however, to squeeze more speed out of your BASIC programs. One simple way is to use more variables. The following programs will demonstrate this. The programs will fill the screen with dots and then tell you how many seconds it took to finish the job.

Carefully type in Program 1, type RUN, and press the RETURN key. (To type the clear-screen character [CLR] in line 10, hold down the SHIFT key and press the CLR/HOME key. You should then see a reversed heart character. If you have a problem, see “How To Type In COMPUTE!’s Gazette Programs” elsewhere in this issue.)

The running time for Program 1 is approximately 12.16 seconds. The only variable used here is the variable “A”, which serves to increment both the screen (7680 + A) and color (38400 + A) memory locations.

Now type in Program 2, and RUN it.

The running time for Program 2 is approximately 8.53 seconds, an increase in speed of 30 percent! The only changes we made in Program 2 were to define the numbers 7680 and 38400 as variables (“B” and “C”) during the initialization (the preliminary definitions and instructions to the computer) in the program. Then we used these variables in the program itself.

Now enter Program 3, and RUN it.

In Program 3, we have replaced most of the numbers in the program with variables. Remember that the variables were first defined for the VIC during the initialization phase of the program. Without first being defined, a variable would mean nothing to the computer later on in the program. The variable would just be a zero, and that would cause havoc.

The running time of Program 3 is approximately 6.7 seconds, almost twice as fast as Program 1, and a marked improvement over Program 2.

The trade-offs here are obvious. By using a little more of the VIC’s memory to define variables, you can greatly increase the swiftness of your programs. Also, if these variables are used more than once in your program, you can save memory at the same time you’re increasing speed. So you can have your cake and eat it too.

Speedy BASIC

You could also try the FOR/NEXT structure instead of the POKE we’ve been using so far (in Programs 1-3). Here’s how.

Enter Program 4, and RUN.

This version runs in just over four seconds. It’s the fastest version yet.

Programming with the FOR/NEXT technique might be a bit more difficult. But in some cases, where speed is important, the extra effort would be worth it.

A Word About Machine Language

For maximum efficiency, for programs that run at lightning speed, machine language is the way to go. Machine language is the VIC’s native language. It talks to itself in machine language; BASIC has to be “interpreted” while a program is running. This translating process can significantly retard progress from one instruction to the next. Of course, computers are so fundamentally fast that many programs don’t require any extra speed. But some do. That’s when the techniques we’ve looked at this month are worth knowing. Even so, in certain cases, machine language is the only solution. To see the spectacular speed of machine language, try Program 5:

After many years of programming, I am still fascinated by the extraordinary speed of machine language.

As you can see, this program runs in just over 1/100 of a second, approximately 730 times faster than Program 1, which is written in BASIC. For those of you who are unfamiliar with machine language, there’s no trick here. As a matter of fact, this program could have been written to run even faster, but you get the idea.

Machine language is an advanced topic and won’t be covered in any detail in this column, but if you’re interested, COMPUTE!’s Gazette for Commodore has a column on the subject, “Machine Language For Beginners,” elsewhere in this issue.

If you’ve got questions or ideas about subjects you’d like to see covered in this column, write to: VICreations, P.O. Box 5406, Greensboro, NC 27403.

Companion disk Companion Disk (.d64)

Enjoyed this? It’s what we do every month.

The revived COMPUTE!’s Gazette brings the spirit of the golden era to today’s retro scene — Commodore, Atari, Amiga, and more, in full-color print and digital every month.