29.12.2014 Views

Apple Orchard 1980 Fall v1n2 reduced

Apple Orchard 1980 Fall v1n2 reduced

Apple Orchard 1980 Fall v1n2 reduced

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

FALL <strong>1980</strong><br />

THE APPLE ORCHARD<br />

PAGE 49<br />

There are many sections of the<br />

<strong>Apple</strong> I l's disk operating system<br />

(DOS) which seem especially designed<br />

to keep you waiting for<br />

eternity. My pet bugaboo for a long<br />

time has been the file handling<br />

routines. Since I couldn't do anything<br />

about them, I began looking<br />

for other places in the DOS to<br />

improve disk speed. The most<br />

obvious start was the "INIT" command.<br />

Fortunately it yielded to<br />

improvements, which I will try to<br />

describe.<br />

This article applies to DOS 3.2.1<br />

in a 48K machine. Addresses mentioned<br />

may be converted to 3.2 or<br />

3.1 by subtracting four bytes from<br />

the given address. Users with less<br />

memory must subtract the appropriate<br />

amount of memory (1K +<br />

1024 bytes).<br />

Before describing the modifications<br />

I made, you should know how<br />

the "INIT" command works, then<br />

you will understand what the<br />

changes do. It is convenient to<br />

think of commands in the DOS as<br />

operating at two levels. The first is<br />

the command level with deals with<br />

interpretation of the "INIT" command<br />

you type. Most command<br />

level operations aren't worth modifying<br />

unless you plan to rewrite<br />

about 10K of machine language<br />

DOS. That is why file handling is<br />

difficult to improve. The second<br />

level is machine level. This mainly<br />

involves a routine called Read/<br />

Write Track and Sector (or RWTS)<br />

which does all of the disk access.<br />

RWTS, fortunately, is well documented<br />

in the original Wozpak.<br />

Most time during INIT is spent at<br />

the machine level in RWTS's disk<br />

formatter. For the purpose of this<br />

explanation we will assume that<br />

the INIT command has been properly<br />

entered and decoded by<br />

INSIDE INITIALIZATION<br />

by Joseph H. Budge<br />

Carolina <strong>Apple</strong> Corps<br />

co~mand level DOS. We shall<br />

enter at the point where RWTS is<br />

being called with the command to<br />

format a diskette:<br />

After turning on the disk drive,<br />

RWTS calibrates the drive's read/<br />

write head to track zero. Calibration<br />

is accomplished by stepping<br />

the read head through 127 tracks.<br />

Since there are only 35 tracks in the<br />

first place, the head hits a stop at<br />

track 0 and halts there, generating<br />

the jackhammer-like noise you<br />

frequently hear. Once calibrated,<br />

RWTS steps through each track,<br />

erasing and formatting as it goes. To<br />

erase, RWTS writes over everything<br />

with one byte, $FF, in a loop that<br />

repeats 7,000 times per track. This<br />

will write over each track several<br />

times before the track is formatted.<br />

The erasure cleans off any previous<br />

data that may be on the disk, at least<br />

most of the time. Sometimes the<br />

manufacturer may put a test signal<br />

on the disk that's too strong to<br />

erase. lnthatcasealargenumberof<br />

1/0 ERRORs on each disk in the<br />

batch tell you to go find a bulk<br />

eraser. Audio recording tape erasers<br />

do a good job.<br />

After erasure, formatting a track<br />

proceeds sector by sector, with<br />

each sector essentially identical. To<br />

format a sector, RWTS first writes a<br />

number of timing bytes onto the<br />

disk. These bytes are $FF's with a<br />

special spacing on the disk, and<br />

there must be at least 16 of them<br />

before each sector. Next RWTS<br />

writes an address block for the<br />

sector. The block contains four<br />

elements. Three starting marks<br />

($DS, $AA and $BS) begin the<br />

block; they tell the DOS that data is<br />

to follow. Then comes the address<br />

data itself. Volume number, track<br />

number, and sector number are<br />

written in encoded form. Next<br />

comes the checksum. Finally three<br />

end of data marks bring up the rear<br />

($AA, $EB, and $FF) .<br />

It is helpful to know thatdata isn 't<br />

put onto the disk in the same form<br />

as the DOS receives it from your<br />

programs or the keyboard. All data<br />

sent to the DOS arrives there in the<br />

standard <strong>Apple</strong> format of eight-bit<br />

words (bytes). But the data can't be<br />

stored on the disk that way for a<br />

variety of reasons. Instead, the<br />

RWTS routines go through a complicated<br />

procedure to recode the<br />

data. In brief: the data is split into<br />

five bit nybbles*, data from each<br />

nybble is combined with data from<br />

other nybbles, creating a pointer to<br />

a table. RWTS gets a byte from the<br />

table and sends that value to the<br />

disk. Believe it or not, the value sent<br />

to the disk is once again an eight-bit<br />

word. But it now only represents<br />

five bits of your information which<br />

are all scrambled. This encoded<br />

byte is sent to the disk hardware,<br />

which stores each bit on the<br />

diskette in serial form, one bit at a<br />

time. Naturally the read section is<br />

smart enough to figure out all this<br />

encoding to extract the information<br />

when you want it.<br />

The upshot of all this encoding is<br />

that no data is stored on the disk as<br />

one byte. The sector number 0, for<br />

example, is written as "$AA, $AA."<br />

The volume number, track number,<br />

and sector number each take<br />

two bytes. One sector of data,<br />

normally 256 bytes, becomes 410<br />

bytes when encoded. Timing<br />

marks, beginning marks, and ending<br />

marks are the only single bytes<br />

ever put on the disk.<br />

The last two paragraphs of diversion<br />

help explain what INIT does<br />

next. You will recall that we left<br />

RWTS just as it finished formatting a<br />

sector's address block. Now, ordinarily<br />

the address block would be<br />

followed by a few timing bytes and<br />

then the sector's data block. Like an<br />

address block, the data block contains<br />

beginning marks, encoded<br />

data, a checksum, and ending<br />

marks. The beginning marks for a<br />

data block are: ($DS,$AAand $AD),<br />

while its end marks are: ($DE, $AA<br />

and $EB). These are different from<br />

the beginning and ending marks in<br />

an address block. But the formatter<br />

in RWTS is lazy. Since no data needs<br />

to be written during the formatting<br />

(continued on page 51)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!