Classic Computer Magazine Archive COMPUTE! ISSUE 61 / JUNE 1985 / PAGE 98

Commodore Disk Editor

Martin Sikes

Examine or edit any sector on a disk with this short, useful program for the Commodore 64 and 1541 disk drive. Recommended for intermediate to advanced users.

One of the best ways to learn about disk storage is to look at the actual contents of sectors on the disk. "Commodore Disk Editor" lets you do just that and even change the contents if you wish. Equipped with this tool, you can repair garbled disks, retrieve accidentally scratched files, as well as protect your programs against tampering by others.

To make the most of Disk Editor, you'll need to know at least the basics of Commodore disk storage. Consult your 1541 User's Manual. Additional information also is available in various books and programming guides. Even without advanced knowledge, however, you can perform some interesting tricks. A few examples are given below.

To get started, type in the program and save it. When running it for the first time, put an unimportant disk in the drive. Making mistakes with a program like this can scramble a disk and render it useless. Until you have gained some experience, practice on an unimportant disk. Make a backup copy of any important disk before you try to alter it.

Reading And Editing Blocks

Disk Editor begins by prompting you to enter track and sector numbers of the block of data you want to examine. Commodore 1541 disks have 35 tracks, and each track con-tains a number of sectors. (The terms sector and block are often used interchangeably to describe a 256-byte data area on the disk.) The available track and sector numbers are listed below. Tracks 1-17 each have 21 sectors, numbered 0-20, and so on.

Tracks Sectors
1-17 0-20
18-24 0-18
25-30 0-17
31-35 0-16

To choose a particular sector, you must enter two numbers separated by a comma. The program does not let you enter nonexistent track or sector values, with the exception noted below. For example, enter 18,1 and press RETURN to examine track 18, sector 1 (this block holds the first part of the disk directory). Disk Editor reads that block from the disk and displays its contents at the top of the screen.

Disk Editor displays the block using the upper-/lowercase character mode. Thus, the values on the screen correspond to the numbers in your 64 User's Guide screen code table: A zero is displayed as an @ character, 13 as a lowercase m, and so on.

The next prompt asks whether you want to edit the block displayed on the screen. Press Y to edit, or N to choose another sector. If you select Y, press the cursor keys to move the blinking cursor atop the character you want to change. Then type in the new character over the old one. For instance, if the first filename in your directory is DOG, you can change the name to BOG simply by typing SHIFT-B over the D.

When your editing is complete, you again have two options. You can press RETURN to write the changed block back to the disk, or press the fl special function key to escape the editing mode without changing anything on the disk. In either case, you'll return to the first prompt, so you can read the same sector again to verify your changes or proceed to another sector. To exit the program, enter track 99, sector 99 at the first prompt. These are the only nonexistent track and sector numbers that Disk Editor allows you to enter.

Don't Boggle The BAM

You've already seen how to change filenames by editing directory blocks. The disk name can be changed just as easily, by editing track 18, sector 0. Note that these names cannot be more than 16 characters long.

Sector 0 of track 18 contains the Block Availability Map, or BAM— important information about the organization of programs on the disk. It's very easy to damage files by improperly changing things in this sector. Until you're familiar with the BAM, avoid changing anything in this sector other than the disk name.

You may notice that a copy of the disk ID follows the disk name in the BAM. However, you cannot change the disk ID by changing this value in the BAM. (You can change the value of the ID shown in sector 0, but this won't change the disk ID; there's no way to do that without reformatting the disk.)

Hidden Programs

Lots of tricks are possible with Disk Editor. Perhaps you'd like to conceal a program's name to make it difficult for others to find in the directory. Directory lists are displayed on the screen with the equivalent of PRINT, so it's easy to disrupt the list by inserting control characters in a filename.

For instance, you might conceal the filename DOG by adding three delete characters after the name. The ASCII table in your 64 User's Guide tells you that a delete character has a value of 20. This corresponds to lowercase t in the screen code table, so you simply type three t's after DOG. Now the program appears as "" when you list the directory. But you can still load the program with the filename DOG* or DOG???. It can also be loaded with the line A$="DOG" + CHR$(20) + CHR$(20) + CHR$(20): LOAD A$,8.

Most characters are easily entered from the keyboard. To enter a reverse video character, press CTRL-9 before typing the character. Disable reverse video by pressing CTRL-0.

Like many protection methods, of course, these simple tricks are only effective against people who know less than you do. It's not very difficult to write a BASIC program that displays a directory without using PRINT statements. If your friends also are familiar with Disk Editor, your attempts at concealment will be utterly transparent. Nevertheless, such methods should be sufficient to deter casual users.

As your knowledge grows, you'll find more practical uses for Disk Editor, such as changing the file type to prevent a program from being scratched. You can also copy blocks from one disk to another, store data directly in unused disk sectors, and restore damaged files to their original condition.

Commodore Disk Editor

Please refer to "COMPUTE!'s Guide to Typing In Programs" before entering this listing.

10 REM BLOCK EDIT                                       :rem 214
20 FORX=0TO26:READA:POKE820+X,A:NEXT                     :rem 28
30 DATA 162,2,32,198,255,160,0,32,207                    :rem 16
40 DATA 255,153,0,4,169,1,153,0,216                     :rem 170
50 DATA 200,208,242,162,1,32,198,255                    :rem 228
60 DATA 96                                              :rem 239
70 PRINT"{CLR}{CYN}":POKE53281 ,0:POKE53280,9           :rem 2
80 POKE 53272,23:PRINTCHR$(8)                           :rem 124
90 OPEN 1,0:OPEN15,8,15                                 :rem 240
100 GOSUB380                                            :rem 172
110 INPUT"ENTER TRACK, SECTOR"
    ;T,S                                                :rem 227
120 IFT=99THEN470                                       :rem 239
130 IFT<1ORS>20ORT>35 THEN100                           :rem 211
140 IFT>17ANDT<25ANDS>18THEN100                         :rem 117
150 IFT>24ANDT<31ANDS>17THEN100                         :rem 112
160 IFT>30ANDS>16THEN100                                :rem 166
170 OPEN 2,8,2,"#"                                      :rem 81
180 PRINT#15,"U1:"2;0;T;S                               :rem 153
190 SYS820:CLOSE2:GOSUB420:GOSUB380                     :rem 186
200 INPUT"EDIT AND SAVE? {RVS} Y{OFF}ES OR
    {RVS}N{OFF}O";
    A$:IFA$<>"Y"THEN100                                 :rem 105
220 POKE254,PEEK(1024):GOSUB380:PRINT"{WHT}";           :rem 103
230 PRINT"USE THE CURSOR TO TYPE
    OVER THE BLOCK. {2 SPACES} IF YOU MAKE
    A MISTAKE, DO ";                                    :rem 160
240 PRINT"NOT PRESS{5 SPACES}RETURN.
    PRESS THE F1 FUNCTION KEY."                         :rem 85
250 POKE781,0:POKE782,0:SYS65520                        :rem 99
260 POKE204,0:WAIT198,255:WAIT 207 ,1:POKE1024,
    PEEK(254)                                           :rem 100
280 GETA$:IFPEEK(203)=0THEN280                          :rem 233
290 IFA$=CHR$(13)THENWAIT207,1:POKE204,1:GOTO340        :rem 66
300 IFA$=CHR$(133)THEN330                               :rem 114
310 POKE205,3:WAIT207,1:PRINTA$;:GOTO260                :rem 144
330 CLOSE1:CLOSE15:OPEN15,8,15,"I0":CLOSE15:
    PRINT"{CLR} {2 DOWN}OK":GOSUB460:GOTO70             :rem 162
340 OPEN2,8,2,"#":PRINT"{HOME}
    {14 DOWN}{RVS}SAVING TRACK "T"SECTOR"S"             :rem 136
350 FORX=0TO254:PRINT#2,CHR$(PEEK(1025+X));:NEXT:PRINT#2
    ,CHR$(PEEK(1024));                                  :rem 163
360 PRINT#15,"U2:"2;0;T;S:CLOSE2                        :rem 124
370 A$="":GOSUB420:GOTO100                              :rem 212
380 PRINT"{HOME}{6 DOWN}"                               :rem 229
390 PRINTCHR$(5);:FORX=0TO39:PRINTCHR$(162);:NEXT:
    PRINTCHR$(159)                                      :rem 254
400 FORX=1TO100:PRINT" {5 SPACES}";:NEXT                :rem 52
410 PRINT"{HOME}(7 DOWN}":RETURN                        :rem 10
420 INPUT#15,A,B$,C,D                                   :rem 141
430 IF B$="OK"THEN RETURN                               :rem 182
440 PRINTA;B$;C;D:POKE53281,9                           :rem 213
450 FORX=1TO2000:NEXT:POKE53281,0:GOTO100               :rem 240
460 FORX=1TO2000:NEXT:RETURN                            :rem 63
470 PRINT"OK":CLOSE1:PRINT#15,
    "I0":CLOSE15:END                                    :rem 71