Sektor Tutorial

See all articles from SMUG Bytes v6 n1
Author(s): Lloyd Dreger
Publication: SMUG Bytes
Pub Details: SMUG Bytes v6 n1 (Volume 6, Issue 1)
Date: January 1989
Pages: 4-6

Sektor by Mowgli Assor is perhaps one of the most powerful disk utilities ever written for the 2068. Sooner or later everyone gets a messed up disk containing their one and only copy of a program or data which took hours to generate. That is when you use Sektor. But, you’ve got to know what you are doing or you can really mess up a disk so badly noone can ever straighten it out again. So here are some pointers on its use.

Sektor is quite well documented. Reading this article with the documentation in front of you is highly recommended. Save this article as a supplement to the documentation.

CORRECTING BASIC PROGRAMS: We will talk about a messed up program first. This usually happens when you shorten a program you already have on the disk. I have found it good practice to do such a resave twice. The second MOVE generally assures all the sectors get moved down correctly.

Failing to do this sometimes results in a save to disk that will have a sector containing the same lines found at the end of the previous sector. Trying to load this program is no problem but listing and running it is disaster. You just can’t delete the offending line either and rewrite it which would be simple enough.

The easiest is to list the program from the top and find out exactly at what line number the error occurs. Then use Sektor to find it and correct it.

Another very helpful hint. Make a copy of your messed up disk by using the MOVE “b:=a:” command to a clean formatted disk and work with that copy. If you mess up beyond saving you can always make another copy by reformatting and reMOVing. This only works if the disk is still readable. If you have a READ/WRITE error go to the next section.

First something about the anatomy of a disk. A DSDD (double sided, double density) disk in Aerco format consists of 40 tracks of 10 sectors each per side. Each track is 5120 bytes long and thus each sector contains 512 bytes. To read a full track in Sektor requires 10 different loads of a sector at a time. There is no sector 0. Each screen of Sektor is only 128 bytes long so you have to page through the 4 pages (Caps Shifted number) to see the whole sector.

To find out where a program is on the disk you need to read the header in the directory. Track 00, Sector 01, Side 00 contains the Disk header information which we will talk about later. Track 00, Sector 02, Side 00 starts the program header listings. Load it by using the R command and answering the questions for the track, sector and side. You get a listing of all the numbers on the left side of the screen in HEX code and the printable ASCII values on the right. Each of these headers is 32 bytes long (4 lines on the left) and consists of the following format:

1st byte–file type: 0 = BAS, 3 = BIN ect.
next 10 byes–file name padded with blanks if necessary.
next 2 bytes–file or total program length.
next 2 bytes–starting address (or line number if BASIC).
next 2 bytes–Program length (start of VARS in basic).

Then what we are looking for–a listing of the track numbers in sequence (in Hex). When you find the program you want by paging though the directory until you find the name, copy these down remembering that they run 01 to 09 and then 0A, 0B, 0C, 0D, 0E, 0F, before you get to 20 which is actually track 16. Tracks on side 0 go from 00 to 27 HEX, on side 1, from 80 to B9 HEX. This is confusing because the READ command needs decimal numbers, not HEX.

If you are advanced enough to be writing in code or saving data tables as BIN files you have no trouble interpreting the data in a sector. Only BASIC gives us a problem as we have to know the anatomy of a Basic line. To the uniniatiated, and for the rest of us a review is in order. Each line consists of a lot of overhead bytes in the following format:

2 bytes–line number in high byte/low byte format even if the first byte is zero. 01 02 is line 258—256*1+2.

Next 2 bytes line length to the ENTER at the end of the line starting the count at the byte after these two. This is in the format of low byte/high byte, the high byte is always the integer of the line length divided by 256. The low byte is the remainder of the length after this.

Now, remember that every number is “slugged”. That means that after the ASCII codes (Consult Appendix B of your User Manual) for a number will appear an 0E (HEX) and 5 additional bytes which never appear on a screen listing of the program. These slug byes count in the line length. If the number happens to be an integer many of these slug numbers will be 00. DATA lines containing a lot of numbers can be exceedingly long. Finally, the line ends with an 0D–the enter code.

Using this format we can page through the program sector by sector and track by track. Here we can save some time by taking into account about where in the program we found the problem. Generally, its going to be at the boundary between tracks.

Once we find the errant line, we have to correct it. Do not try to slug numbers and other fancy things. The simpliest is to lengthen the length of the errant line to include all the garbage and end on the ENTER of that line. This is usually on the next track as it would be very unlikely that a line ends with a track but carries over to the next track. Thus, some careful counting is in order. A hint, don’t worry about 2 lines having the same line number, you can delete one of them when you get back to Basic. You will notice that Sektor tells you what byte number the cursor is on. This helps in counting if you remember that Sektor doesn’t use zero as a byte number.

When you think you have the right line length, do the division into a high and low byte by dividing by 256 and use Sektor to rewrite those bytes and then WRITE (W) them back to the appropite sector of the disk. Now, quit Sektor and load the program and list the problem line. If you did it properly you can edit out the line with the garbage and any duplicate lines–the first duplicate line number goes. If you counted wrong, it will not edit out. Your line length count is off and its back to Sektor to try again. See what I mean by working with a copy?

READ/WRITE ERROR: If you don’t even get a directory, it means that the directory is messed up. This usually occurs when rewriting a program or data file to the disk. The DOS has to erase the allocated tracks and fails to reallocate them when rewriting the program/data. We are talking of Track 00, sector 02, side 00, bytes 1 to 32 which are the allocation bytes, i.e., those tracks used–the first 4 lines of Sector 2 on screen 1.

A freshly formatted disk will contain a 80 in the first byte with the rest being zeros indicating a directory exists on track 0.

In binary that is,
        1 0 0 0 0 0 0 0. (80)
When track 1 is used it turns to:
        1 1 0 0 0 0 0 0. (C0)
When track 2 is used it turns to:
        1 1 1 0 0 0 0 0. (E0)

The numbers behind the binary are the HEX equivalents of the binary numbers. As one can see, each track used turns on another bit. Thus, each byte can handle the allocation of 8 tracks.

Tracks are allocated in ascending order. However, holes may exist if you delete a program. Go through the entire directory listing and see which tracks are used for each program on the disk.

Here you have to fool Sektor as it also doesn’t like to read an unreadable disk. Telling it to read Track 00, Sector 02, side 00 is going to give you the same READ/WRITE error. Merely tell it to GO TO 12 and viola, the track lists. Page through the sector listing the tracks used. Remember the Aerco system assigns by tracks not sectors. Once having this list, work out the bits that are supposed to be on in the first several bytes of track 00, sector 02, side 00 and rewrite them accordingly. Then write back to the disk with the W command. When it happened to me the first 3 bytes were FB BF 20 which were supposed to be FF FF 20–notice the the 3rd byte is NOT 80 as I had deleted something.

RETRIEVING ERASED PROGRAMS/FILES: If you erase a program you didn’t intend to erase, DO NOT write anything more to the disk or you overwrite the program tracks. It can be retrieved with difficulty. This requires a lot of searching. What happens when you erase a program?

1. The tracks are dellocated in the first few bytes of track 00, sector 02, side 00. They must be reallocated.

2. The directory listing is removed. There is a hole in the directory where it should go. It must be reconstructed.

What doesn’t happen is that the actual program is NOT erased. Thus if we can reallocate tracks and rewrite the header we can undo the erase.

Where do we find the data to reconstruct the header? Another copy exists in the first sector of the first track of the program–without the track numbers. It gives the vital data of program length and overall length. Thus all you have to do is go through the first sectors of each track looking for it. Decoding the bytes at the start of Track 00, Sector 2 will tell you which tracks you may skip. Start by looking at the first unallocated track. You also have to find the other parts of the program if it takes more than 1 track but finding the header will tell you how many tracks to look for. Remember tracks on side 2 are set with an 80 HEX prefix. Write down the necessary data and then go back to track 00, sector 02 or higher and reallocate tracks and rewrite the header in its proper placing writing to disk as you do so.

I hope this takes some of the mystery out of Sektor. A basic understanding of binary and Hex are needed and I hope I have given sufficient explainations of them for the average person to proceed. Both the loss of a program and the READ/WRITE error have happened to me and I deliberately did the accidental erase to see what it would be like. It took a little time retrieving the disk but not nearly as much as trying to redo all the programs on a disk. Of course none of this is necessary if you always make at least 2 copies of everything. Unfortunately, when the programing is going along nicely, who takes the time.