Classic Computer Magazine Archive CREATIVE COMPUTING VOL. 11, NO. 10 / OCTOBER 1985 / PAGE 110

Auto boot and redefined function keys for the C128. (Commodore's port) Sheldon Leemon.

Oh the dangers of lead time: Here I am in late July, writing a column for the October issue, having read in John Anderson's August Commodore's Port column that the 128 is currently in distribution. But it is not. Various explanations have been offered but none by Commodore. One clue is that the demonstration model I received in late June looks like a productive version, but if you turn it over, instead of an FCC sticker on the bottom of the case, there is a warning label that the unit has not been FCC certified and is not for sale until clearance has been obtained.

Of course, now that I am writing about the delay, you can let that by the time you read this, the 128 will be shipping, making the whole question moot. It is a well-known effect, like washing your car to make it rain. So if you have your 128 by now, you have me to thank for putting an end to the delay. The delay does illustrate an important change at Commodore, however.

Under the Tramiel regime, the Commodore philosophy was "we will ship no computer before we get paid for it." The new management apparently agrees more with Paul Masson and will ship no computer before its time. That is good news in the long run for the consumer, who is really better off waiting a little longer to get a machine that works right the first time.

C128 Function Keys

This slight delay also works to the benefit of columnists, who have had time to stockpile material about the 128. In this column I will share a couple of tidbits that I have unearthed already. The first item of interest regards the programmable function keys. Basic 7.0 includes the KEY command, which allows you to assign text strings to be printed whenever the function keys are pressed. There are defaults set up every time you turn the computer on, so that pressing the F3 key, for example, prints the keyword DIRECTORY plus a carriage return that enters the command, which then prints a disk directory. You can get a list of these defaults simply by typing the KEY command. But you aren't stuck with Commodore's choices for these keys. You can also use the KEY command to change the values of the text strings.

The F1 key, for example, prints the keyword GRAPHIC. That is not a command I am likely to use every time I sit down at the keyboard. Entering the statement:

KEY 1, "?DS$" +CHR$(13) will set up the F1 key so that everytime I press it, the disk error channel will be read and the error message displayed. Notice that CHR$(13), the carriage return character, was added to the end of the string to enter the command after it has been printed. Using the concatenation operator (that's computer talk for the + sign), we can add any of those little CHR$ characters that we want to our function key string.

For example, if you wanted a function key to clear the screen first and then display the directory, you could enter: KEY 3, "?CHR$(147): DIRECTORY"+CHR$(13) Two functions on the same key. Not bad!

On the 128, the text for these messages is stored in RAM (Bank 0), from locations 4096 to 4351. The binary save and load commands (BSAVE and BLOAD) make it easy to save all of your key definitions to disk and load them back in all at once, instead of having them back in all at once, instead of having to type them one by one with the KEY command.

"So what?" you may be asking yourself. After all, you can accomplish the same thing by creating a Basic program that sets up all of your favorite key definitions with the KEY command. Then you can run it when you want to change all of the definitions at once.

But if you use the machine language monitor, you will discover something very interesting (you can get into the monitor, by the way, by pressing the F8 key). Type'M 1000' and the monitor will display the text characters that are invoked by the function keys on the right side of the screen. If you look at the last couple of strings, you will find that the text printed by the SHIFT-RUN/STOP combination and the HELP key is also stored there. So actually, there are ten user-definable keys, even though the KEY command lets you change only the first eight.

How do you change the text strings assigned to the HELP key and the SHIFT-RUN/STOP? Well, you must know a little bit about how the text for these keys is stored. The function key storage area begins at location 4096 in Bank 0. The first ten bytes hold the lengths of each of the ten text strings. The actual text itself follows at location 4106. When the keyboard editor sees that one of the defiable keys has been pressed, it uses the length bytes to determine where to start and stop printing text.

So, to redefine the two "extra" function keys, we have to POKE in the text for these two keys after the end of the text for the other eight and then change the length bytes at locations 4104 and 4105 to reflect the lengths of these two strings. And you thought that Basic 7.0 would eliminate all POKES!

The short Basic program in Listing 1 shows how to redefine the two keys, and save all of the key assignment to a disk file name Keydata. Then, if you want to read in all ten of your new key definitions at once, you just BLOAD "KEYDATA," B0, P4096.

Run the program, then press the HELP key. Get the idea? Whatever appears in HE$ in line 10 is printed by the HELP key, and whatever appears in RS$ in line 20 is printed by the SHIFT-RUN/STOP combination. You probably will want to set SHIRT-RUN/STOP to something like its default "RUN" + CHR$(34)+"*"+CHR$(13), so that it will still load and run the first program on the disk. But since the HELP command is not really all that helpful, redefining it is like getting an extra function key for free.

Auto Boot for the C128

For my next number, I'm going to play a request. As John has mentioned in earlier columns, the 128 operating system tries to boot the disk on power up. This means that it reads the disk drive, and if it finds some special data on track 1, sector 0, it reads a machine language program from that sector and executes it. By placing on that sector a machine language program that runs a named file from the disk, you can get the 128 to load and run a Basic program automatically when you turn it on. If you happen to have a four-year-old, as I do, this means that you don't have to wait until he is old enough to type LOAD"*",8 and RUN before you can let him use the computer. It is even handy for those of us over four. And contrary to popular belief, it works in 128 mode as well as CP/M mode, and it works on the 1541 as well as on the 1741.

When it came to actually writing the boot sector code, however, John hedged. Since he is a new father, I appreciate the time constraints under which he now operates so, as a personal favor to him, I wrote the program in Listing 2 to "create" a 128 boot disk. I have listed it in lowercase, so that you can clearly see that the character at the end of the string in line 100 is a shifted U (R-SHIFT-U is the abbreviation for the Basic keyword RUN).

Because the program writes directly to the disk, some caution is indicated. First, type in the program and save it to disk. Do not run the program while the disk to which you have saved it is still in the drive. Instead, get out a brand new disk. Format it with the HEADER command. When you list the directory, you should have 664 blocks free. Now, keep this new disk in the drive and run the program. After it is done, the directory should indicate that you have 663 blocks free, because one block has been allocated to the boot sector. Now, all that remains is to save the Basic program you want to have run automatically to the same disk. For demonstration purposes, type NEW, then enter the program: 10 PRINT CHR$(147) "EUREKA! IT WORKS" Enter the command DSAVE "AUTO. Now you are ready for the acid text. Press the reset button on the right side of the 128. If all goes well, after the Commodore Basic 7.0 sign-on message comes on, you will see: BOOTING... rU"auto and the program will run. If not, you will just have to take my word that it works.

The name of the program appears in the DATA statement in line 110. Feel free to replace it with the filename of your choice. Just remember that because only ten characters can be placed in the keyboard buffer at once, you are limited to six characters in the filename. If the name has fewer than six characters, add extra spaces at the end of the name to make exactly six characters as was done above. Also remember that for the boot to work, you must have a program with that name located on the same disk.

What about the 64 side of the computer? Is it possible to boot a machine language program that changes the computer to the 64 mode and then automatically loads and runs a Basic program? At first, I thought not, because once you switch to the 64 mode, you lose control completely (so to speak). I have discovered a way to perform even this seemingly-impossible task, however. Unfortunately, I have run out of space. How many marvels do you expect in one column, for goodness sake? With Mr. Anderson's indulgence, however, I will make another guest appearance at a future date to reveal this and other interesting tidbits. (Sounds like he's hedging, doesn't it?)