By Larry Isaacs — originally published in COMPUTE!’s Gazette Issue 2, August 1983
In this month’s column I will be reviewing the Commodore 64 Programmer’s Reference Guide and discussing some topics involving the 1541 Floppy Disk Drive. I’ll also introduce a handy disk copy program which will be included in next month’s column.
Commodore 64 Programmer’s Reference Guide
The Commodore 64 User’s Guide which comes with the 64 is written to be an introductory manual. It keeps technical terms to a minimum and tries to keep each discussion on a very simple level. As a result, most topics are not covered in great detail. If you plan to do your own programming, this detail will be essential. Fortunately, a second book is published by Commodore to address this need: the Commodore 64 Programmer’s Reference Guide. This book is available from Howard W. Sams & Co. Inc., of Indianapolis, Indiana, for $19.95. This may seem a bit expensive, but it is well worth the price.
The Reference Guide is written for both the experienced as well as the beginning to intermediate programmer. The information is divided into six chapters and 16 appendices. Six chapters may not seem like much, but a great deal is covered in each chapter, and the book totals 487 pages.
The first two chapters pertain to the BASIC language on the 64. The first chapter, “BASIC Programming Rules,” gives a number of specific details about the BASIC interpreter. One of the most important topics covered in this chapter is a discussion of each operator available for arithmetic and relational expressions. The second chapter, “BASIC Language Vocabulary,” is the primary reference in this book for the BASIC language itself. The majority of the chapter is devoted to describing each of the BASIC commands.
The third chapter covers graphics programming on the 64. This includes how to set up the different graphics screens, plus a very detailed discussion on the operation of sprites. Mostly this involves explaining how the hardware operates. The book does a good job of explaining these technical topics in simple terms. The example programs are written only in BASIC, but hexadecimal addresses for all the memory locations are provided for machine language programmers.
The fourth chapter deals with sound and music. Again, a technical subject, but one covered in fairly simple terms. Primarily this chapter discusses the different features of the 6851 SID (Sound Interface Device) chip. Like Chapter 3, the examples are all in BASIC.
The fifth chapter covers machine language programming on the 64. This includes a discussion of the 6510 instruction set for those who are not yet familiar with it (the 6510 is the main microprocessor chip of the 64). Also discussed are the various memory configurations possible by juggling Random Access Memory (RAM) and Read Only Memory (ROM). The most important part, in my estimation, is the section on the Kernal routines. These are routines which may be used by machine language programs to access various functions of the 64’s operating system. I used this section quite a bit while developing the program presented later in this column.
The sixth chapter, “Input/Output Guide,” discusses the different ways in which the 64 can communicate with the outside world. This includes output to the TV and other devices. It also describes how to use the game, user, and expansion ports. A discussion of the serial bus is included in this chapter as well.
The remaining fourth of the book contains the 16 appendices. These appendices range from a table of abbreviations for BASIC keywords to specifications for most of the special chips in the 64. Throughout, decimal and hexadecimal addresses are given for each important memory location.
If you run into a question about how something should be done, or how something works on the 64, the Commodore 64 Programmer’s Reference Guide is a good place to start looking for the answer. This applies to beginning programmers as well as experienced ones. Again, it is well worth the price.
Cassette Versus Disk
Now to move on to the next topic. Before you can begin doing any serious programming, naturally you will need some way to save your work. With the 64, you have two primary choices. These are the C2N Datassette tape recorder and the VIC-1541 Floppy Disk Drive. I won’t take the time in this month’s column to give an in-depth discussion of the relative merits of cassette versus disk. Future articles in COMPUTE!’s Gazette will cover this.
But briefly, the primary advantage of the cassette unit is its low cost (about $65-$75). What you get for the extra cost of the floppy disk drive (about $375) is primarily improved speed and reliability. It is also much easier to store many files on a floppy disk than on a cassette. Manipulating large data files may be impossible on cassette, but not that difficult if they are stored on floppy disk.
If the 64 is your first computer, or if you are not sure whether to go with cassette or disk, I would recommend starting with the cassette. Even if you later switch to the 1541 disk drive, the cassette unit will still come in handy from time to time. The primary reasons for switching from cassette to disk would be that the slowness of cassette is driving you crazy, or some program you write or buy requires the disk for data storage.
For those who have already chosen the disk drive, I will try to provide some information and advice to augment what you receive with your 1541. First, here is a little background information on the disk drive.
Giving Orders To A Disk Drive
In order for a disk drive to work with a computer, there must be some form of Disk Operating System (DOS – rhymes with floss). DOS consists of the programs and routines which manage and manipulate files on the disk drive. Naturally, this implies there must be some way for people to make their wishes known to the DOS. Usually the DOS is a program which runs in your computer, independent of other programs, allowing disk operations to be called for by the user or by programs.
Commodore, from the beginning, has taken a different approach. The majority of the DOS actually is run in the 1541 disk drive instead of the 64. The 64 contains only routines for the LOAD and SAVE commands, plus routines for some input-output commands (such as PRINT#) which permit transferring data to or from the 1541 disk drive.
To execute a DOS command – for instance, to delete a file or program – the command must be sent as data to the 1541 via a command channel. After receiving the command, the 1541 will try to perform the requested operation. If it is unsuccessful, the small red light on the front of the 1541 will begin to flash. For the computer to receive a signal indicating the command was completed, it must read data from the command channel of the 1541. Unfortunately, the extra work required to start up these channels and send the commands or read the error status can be a bit of a nuisance if you are trying to execute DOS commands directly from the keyboard.
Here is an illustration of what I mean. Suppose you wish to delete a file named “OLD FILE”. The sequence of commands would be:
OPEN 15,8,15,”S0:OLD FILE”
INPUT# 15,EN,EM$,ET,ES
PRINT EN,EM$,ET,ES:CLOSE 15
This includes reading the error status to insure the file was deleted. Since the INPUT# command cannot be executed as a direct command, the middle statement above would have to be entered with a preceding line number and then RUN, just like any other program. This is a lot of typing just to delete a file.
The Wedge
Fortunately, there is a program on the Test/Demo disk that comes with your 1541 disk drive which will minimize the typing. It is called “DOS 5.1” and is accompanied by another program called “C-64 WEDGE.” DOS 5.1 is a machine language program which loads in a free area of memory in the 64 (the 4K region of RAM at $C000 hex, 49152 decimal). Because it is a somewhat special program, you can’t just LOAD and RUN it like a BASIC program. C-64 WEDGE is a very short BASIC program which will load and execute the DOS 5.1 program for you. You may simply LOAD and RUN the C-64 WEDGE program to start up the WEDGE.
When executed, the DOS 5.1 program will link, or wedge, an additional set of commands into the BASIC language. These commands provide
simple means of communicating with the 1541 disk drive without lot of typing. Each of these DOS commands must have one of small set of
special characters as the first character of the command. These special characters are the greater-than sign (>), “at” sign (@), slash or divide character (/), up arrow (↑), percent sign (%), and left arrow (←).When executed, the DOS 5.1 program will link, or wedge, an additional set of commands into the BASIC language. These commands provide simple means of communicating with the 1541 disk drive without lot of typing. Each of these DOS commands must have one of small set of special characters as the first character of the command. These special characters are the greater-than sign (>), “at” sign (@), slash or divide character (/), up arrow (↑), percent sign (%), and left arrow (←). When one of these characters is found as the first character in statement, DOS 5.1 will execute the command before BASIC misinterprets it as
typing error.
The “>” and “@” symbols serve the same purpose. At least one of these can he typed with out holding down the SHIFT key on every Commodore computer. This is the “@” key on the 64, so it may he the easier to use. This symbol is used in several different DOS commands. If you type
@ and press RETURN, DOS 5.1 will read and display the error status of the disk drive. The @ symbol may also be used to read and display the
directory of the disk without destroying the program in memory (which ordinarily is not possible). Such command would be:
@$
or
@0$: (file spec)
where (file spec) specifies pattern to be matched if the filename is to be displayed. DOS commands also are sent using the “@” symbol. The command:
@ (command string)
would accomplish the same thing as:
OPEN 15,8,15
PRINT#15,” (command string)”
CLOSE 15
A couple of miscellaneous commands use the @ symbol as well. The command:
@#9
will change the 1541 device number from 8 to 9. This is useful when you have more than one drive to connect lo the 64. However, DOS 5.1 will only access 1541 addressed as device 8. And finally, the command:
@Q
will remove the DOS WEDGE commands from the BASIC language.
As for the other symbols, the “/” is used to load BASIC programs and other programs which are to load at location 2048. The command:
/MYPROGKAM
is equivalent to:
LOAD “MYPROGRAM”,8
The “↑” symbol works the same as the “/” except that it runs the program as well. The “%” symbol is used to load machine language programs, or other programs which are to be loaded at some other location than 2048. The command:
%MYCODE.OBJ
is equivalent to:
LOAD “MYCODE.OBJ”,8,1
The “←” symbol is used to SAVE the BASIC program currently in memory. The command:
←NEWPROGRAM
is equivalent to:
SAVE “NEWPROGRAM”,8
It is important to remember that this command isn’t intended to save machine language programs, such as DOS 5.1 itself.
From the discussion above, you can see that DOS 5.1 can be very handy program. Unless there were specific reasons not to, you would
probably want to always have it running.
The Backup Problem
There are some additional programs on the 1541 Test/Demo disk you received with your drive. Since there is always at least small possibility of
having an “accident” with disk, it is wise to make backup copy of your important disks. Once copy is made, you can store the original away in a safe place and use the copy. If something should happen to this copy, or if it wears out, you can always make another copy from the original.
You can copy most programs by loading them into memory and saving them back to another disk. But as you may have already discovered,
this won’t work with special programs which load via non-relocating LOAD command, i.e., LOAD “FILE”,8, 1. The DOS 5.1 program falls
into this category.
The Test/Demo disk contains copy program called “COPY/ALL.” However, this program works only if you have two 1541 disk drives. After
fair amount of searching, was unable to find any information on how you would transfer DOS 5.1 or other such machine language programs to
other disks. Actually, consider it major over sight for Commodore not to have provided some way to at least copy DOS 5.1, if not some program
to copy all such files lo other disks.
Since it is better to light candle than curse the darkness, wrote single drive file copy program myself. In next month’s “64 Explorer,” I’ll include ready-to-type listing of this handy utility, full instructions on how to use it, plus short program you can run to verify that you typed it in
correctly. See you then.
