• Research Center for Advanced Commodore Study

  • by HowlinAl

Making Tomorrows World Better With Yesterdays Technology Today

Oct
1

Variables in C128 DOS

Jim Butterfield Saves The Day!

THE PROBLEM:

The C128's BASIC 7.0 has a lot of nice commands for disk access. DIRECTORY, SCRATCH, and DLOAD, for example. Anyone who's ever used a C64 or VIC-20 can appreciate how nice this is. But there's a big problem, too. What if I want to see the directory of drive unit #9 or #10? DIRECTORY and the other DOS commands in BASIC 7.0 default to drive #8. If you want to view the contents of drive #9, you have to enter:

DIRECTORY U9 

"U" stands for "unit". To load to drive #9, issue:

DLOAD"filename",U9

That's fine for direct mode, but what about inside a program? It seems as though there is no way to use variables with the C128's DOS commands. You can do DIRECTORY U9 but you can't define X=9 and then type DIRECTORY X. You can't define X$="U9"and do DIRECTORY X$. You can't even use variables for filenames as in DLOAD F$.

Then end result? All these fancy new commands for disk access are completely useless within BASIC programs unless you want to "hard code" drive numbers. Not user friendly. The only alternative is to go back to the old BASIC 2.0 way -- yes, I mean OPEN 1,x,15, ... etc, etc. Say it ain't so! Torture!

THE SOLUTION:
 
Of course, the solution comes from the legendary Jim Butterfield. While reading his article in the April 1981 issue of Compute! titled Working With Basic 4.0, I came across this passage:

"It's nice to be able to say things like SCRATCH "WORKFILE", either as a direct statement or in a program. At first glance, however, it seems that variables won't work: you can't say SCRATCH X$, where X$ defines the filename. Similarly, you can designate drive zero within a command as D0 or drive one as D1, but you can't use DN to designate drive N, where N is a variable of value 1 or 0."


This made me sit up. Jim seemed to be describing, albeit for the PET, one of my biggest gripes about BASIC 7.0 on the C128. Eagerly, I read on:

"It all becomes easy when you learn the syntax. Just put the variable name in parentheses and it all works. So you can say, SCRATCH (X$),D(N) and you'll remove the file whose name is defined in X$ from the drive whose number is defined by N. This kind of syntax applies generally to the DOS commands."

And so it was. Jim's advice for the PET worked perfectly on the C128, solving a problem that had infuriated me for years.

In conclusion, my little adventure reinforced two things in my mind:

  1. Jim Butterfield's contributions to Commodore computing are truly incalculable. He's still teaching me things.
  2. There's good stuff in old computer magazines. A lot of the info seems quaint these days, maybe. After all, many of us are now far more expert on these machines than the folks at Compute! ever were. Even so, I still find lots of fun and useful things within those old yellowed pages.

Leave a Comment

You must be signed-in to post comments.

Responses