Refurbish Your 64
Richard Roffers And Jeffrey Hock
Enhance your Commodore 64 by modifying its built-in operating system. This unusual program eliminates several annoying bugs and adds convenient new features as well.
While the Commodore 64 is a remarkable computer, its operating system, the Kernal, has a few notorious shortcomings. Some 64s lock up if you type a line more than 80 characters long at the bottom of the screen, then delete a character. POKEs to screen memory are invisible on some models, and none of them handle the ASC value of a null string ("") correctly. "Refurbish Your 64" corrects these problems and makes several other improvements as well. Of course, the changes are only temporary. Restarting the computer returns it to normal.
Type in and save the accompanying program, and be sure to remove any cartridges from the expansion port. When you run the program, the computer behaves as if you just turned the power on— but with a difference. The startup message reveals that the Kernal has been modified. As you may know, the 64 has programmable RAM (Random Access Memory) "underneath" the ROM (Read Only Memory) addresses where BASIC and the Kernal are stored. This program works by copying BASIC and the Kernal from ROM into the underlying RAM, modifying them, and then turning off the ROM to make the computer use the RAM-based Kernal and BASIC.
Don't worry if that seems unclear. You can use this program without knowing how all the details work. For now, notice that the number of bytes free is shown as 51,216, far more than the usual number (38,911). Since the 64 now has RAM instead of ROM at locations 40960–49151, it thinks its BASIC program space stretches all the way from location 2048 to 53264. But that's just an illusion. We can't use the RAM from 40960–49151 without destroying the modified BASIC we just put there. Before you do anything else, reset the top-of-memory pointer to its normal value by typing the following line and pressing RETURN:
POKE 55,0:POKE 56,160:POKE 643,0:POKE 644,160:NEW
This line must always be entered immediately after you run the program (or perform a cold start with SYS 64738). Once that is done, your modified 64 is ready to go. Let's look at each modification in turn and note how you can customize this program to suit your own tastes.
Everyone seems to have different preferences for default screen colors. If you don't like the usual colors, they're easy to change. Lines 1460, 1500, and 1550 define the default background, border, and character colors, respectively. Change the values in those lines to whatever color numbers you like, then rerun the program. The chosen colors will reappear whenever you press RUN/STOP-RESTORE or cause a cold start with SYS 64738.
In this and other parts of the program, you'll notice that each group of DATA statements represents one change, with the first DATA statement in each group specifying the starting address and the number of bytes to be changed in ROM. The remaining DATA statements in each group contain the actual bytes that are POKEd into RAM to make the change. The REM statements in each section explain which values you may change.
Although most 64 owners use a disk drive, the default device for LOAD, SAVE, and VERIFY is the Datassette. Lines 1600–1700 change the default device number to 8 so that a command like SAVE "FILE" (without the, 8) saves to the disk drive rather than cassette. You can still use tape by adding device number 1 to your commands (for instance, SAVE"FILE",1). However, for nonrelocating disk loads you must still add, 8, 1 to the command (as in LOAD"FILE",8,1). Replace the 8 in line 1650 with a 1 if you don't have a disk drive.
When you press SHIFT–RUN/ STOP, normally the 64 loads and runs the first program on tape. Since the disk drive is now the default device, the SHIFT–RUN/STOP routine has been modified to perform the equivalent of L0AD "*", 8 followed by RUN. This was necessary because disk loads (unlike tape) always require a filename. The command LOAD "*", 8 normally loads the first program file on the disk. However, in some cases the wildcard symbol * is equal to the last filename used rather than the first file on disk.
Depending on the age of your 64, POKEs to screen memory (like POKE 1024, 42) may produce white characters, invisible characters (the same color as the background), or characters the same color as the cursor. This program makes all screen POKEs appear in the cursor color as on the newest 64s.
This is a change you may or may not find desirable, so we've made it optional. Some people often hit the CLR/HOME key by accident when trying to press the INST/DEL key. Instead of inserting a character in a line that you're editing, the screen clears and your work is lost. To eliminate this problem, remove the REMs from lines 2060–2280. This modification exchanges the positions of the CLR/HOME key and the £ key, moving CLR/HOME to a less vulnerable position. If you make this change and use this program frequently, you may want to exchange the keycaps for those keys as well. The keycaps are easily removed by prying them straight up.
As you probably know, INPUT permits a prompt message (for example, INPUT "YOUR CHOICE"; A$ prints YOUR CHOICE?). If the prompt message is longer than one screen line, INPUT either tacks the entire prompt message onto the front of your response (when accepting string input) or causes a REDO FROM START error (when accepting numeric input). Lines 2310–2340 eliminate this bug.
The 64 normally lets you slow screen scrolling (caused by PRINTing or LISTing to the screen) by pressing the CTRL key. In many cases, it's more convenient to freeze such displays rather than merely slow them down. When the modified Kernal is installed, SHIFT (or SHIFT-LOCK) will freeze screen scrolling. Pressing CTRL while a screen is frozen causes it to scroll at the normal rate as long as both SHIFT and CTRL are pressed.
Keyboard Buffer Option
Since this modification may not be useful to everyone, we've made it optional. The computer's keyboard buffer stores keystrokes temporarily. If you type faster than the computer can digest the keystrokes, the keyboard buffer remembers them until the system is ready. The buffer is normally ten characters long; when you type more than ten characters "ahead" of the system, the extra characters are lost. There are times when a longer buffer would be useful—for example, to prevent a fast typist from overflowing the buffer or to let the computer execute long direct-mode commands as if they were typed directly on the keyboard.
If you remove the REMs from lines 2530–2720, the keyboard buffer is moved from its normal location (631–640) to an 80-byte area in the cassette buffer (starting at 828). Note that many programs expect to find the keyboard buffer in its normal place and may misbehave or crash as a result of this relocation. For this reason, be careful to test the program after incorporating this change.
This message is displayed when you first run the program, and thereafter (as long as the computer remains on) when you cause a cold start with SYS 64738. After performing a cold start, you must always reset the top-of-memory pointer as explained above. Lines 3190–3220 contain the data for the new startup message. The numbers are ASCII character codes (listed in your user's guide). To replace this message with one of your own, replace these codes with ASCII codes for the characters that you want. Do not try to add any extra characters (there's no room for them in the modified Kernal). Note that the last ASCII code must be a 0. If you omit the final 0, the computer may crash when it tries to print the message.
Some early models of the 64 suffer from the infamous bottom-of-screen lockup bug, caused when you type in a line more than 80 characters long at the bottom of the screen, then delete a character. This bug has been eliminated.
New Erase Key
Commodore computers provide excellent full-screen editing capabilities. However, some people prefer an "erase" key that acts like a mini black hole. When you press it, the character under the cursor disappears, and everything to the right of that character moves left one space. This is the equivalent of pressing CURSOR RIGHT followed by DELETE. We chose to make the seldom-used SHIFT-£ combination into an erase key. To erase a character, just press SHIFT-£. The new erase key repeats when you hold it down, just like the cursor keys and INST/DEL (SHIFT-9 now repeats as well, an unavoidable side effect). If you need the graphics character that SHIFT-£ normally prints, use PRINT CHR$(169).
Null String Fix
The 64's normal ASC function can't handle a null string (two quotation marks with nothing between them). A statement like PRINT ASC("") causes an ILLEGAL QUANTITY error. This is one of the easiest ROM bugs to fix, requiring only a one-byte change.
For most ordinary programming, a RAM-based Kernal and BASIC work just fine. However, since other programs may use the same RAM area (to store a high-resolution screen, make other modifications to BASIC, or whatever), you must be alert for conflicts. If another program POKEs into the RAM where the modified BASIC and Kernal are stored, the computer may crash. As mentioned earlier, turning the computer off and on restores the original, ROM-based versions of BASIC and the Kernal. The only way to make these changes permanent is to store the modified BASIC and Kernal in EPROM (Eraseable Programmable ROM) chips and substitute them for the existing ROM chips—a job requiring specialized equipment and expertise.