Classic Computer Magazine Archive COMPUTE! ISSUE 144 / SEPTEMBER 1992 / PAGE G32

Smart Format
by Rustin Ambrose

Smart Format for the 1541 drive is a utility program that executes a full NEW format of a disk in one-third the usual time. Anyone who must format a number of disks at one session will appreciate this timesaving feature.

With another welcome feature, Smart Format eliminates head bumping--that banging noise in your drive that normally occurs at the start of a conventional format. Smart Format was designed to work only with the 1541 drive.

Entering the Program

Smart Format is written entirely in BASIC. To help avoid typing errors, use The Automatic Proofreader; see "Typing Aids" elsewhere in this section. Be sure to save a copy of the program before exiting Proofreader.

To use Smart Format, simply load and run it as you would any BASIC program. The program uses DATA statements to send custom machine language routines to the drive.

Why It's Faster

Formatting a disk is usually done with the NEW command, which is written OPEN15, 8, 15,"NO: DISK NAME, ID": CLOSE15. This type of formatting usually takes about 85 seconds. More than half of this time is spent calculating the optimal size of the disk's intersector gaps.

The inter-sector gaps are strings of about 4-18 bytes that are added to the end of each sector during formatting. The gap areas are never used by the drive but rather act as padding between sectors of a track. The optimal gap size depends partly on the rotational speed of the drive.

Commodore's Disk Operating System (DOS) repeats a complex algorithm on each track to calculate the best gap size. The time-consuming part of the algorithm compensates for small changes in drive speed that can occur from track to track. Testing shows, however, that drive speeds don't vary enough during the short time of the NEW command to make a significant difference in the gap calculations. As a result, there's no good reason to repeat the algorithm on every track on a disk.

Smart Format uses the DOS algorithm only on track 1. The gap length for track 1 is then used to calculate the gaps for all other tracks.

Smart Format also improves the efficiency of the routine that clears a track prior to formatting. The combined effect of these changes reduces execution time to about 28 seconds. User group librarians or anyone else who must format a number of disks during one computing session will appreciate this faster procedure.

Eliminating the Bump

When you format a disk using the conventional command, you probably hear a banging noise coming from the drive. This banging sound at the start of formatting is caused by the drive read/write head stepping outward an excessive number of times. The regular format routines do this to guarantee that formatting begins on track 1, the outermost track. The bump can contribute to alignment problems and should be avoided whenever possible. Smart Format uses the drive's internal track counter to move the read/write head precisely to track 1 without the bump. If the drive hasn't been used since power-up, the internal track counter will need to be initialized. Should Smart Format detect this situation, will ask the user to insert any formatted disk. The track counter is then updated by reading the track number from the formatted disk using the INITIALIZE command.

Other Details

Smart Format does all of the standard error checking. This includes a full verification of every formatted track. If an error is detected, the program will attempt to correct it up to ten times before giving up. Smart Format's final display shows the number of retries required (usually zero).

The final display also indicates four inter-sector gap lengths (in bytes) used during the format. Each gap value applies to an entire zone of the disk. The track number ranges of the four zones are 1-17, 18-24, 25-30, and 31-35. Drives that rotate at slower speeds will produce larger gap values. Smart Format makes no permanent changes in the DOS, and all drive commands will function normally. The BASIC program must be used to execute the custom drive routines.

SMART FORMAT

JA 100 REM SMART FORMAT BY RUS

TIN AMBROSE CE 110 REM COPYRIGHT 1992 - Co

MPUTE PUBLICATIONS INTL LTD - ALL RIGHTS RESER

VED RJ 120 REM A$ MUST BE FIRST VA

RIABLE USED IN PROGRAM FF 130 A$="":C0$=CHR$(0):CR$=C

HR$(13):VA=PEEK(45)+256

* PEEK(46) CX 140 POKE(VA+2),255:POKE(VA+

3),0:POKE(VA+4),192 QC 150 PRINT"SETTING UP. . ."

FA 160 FORAD=49176 TO 49375:READ

X:POKEAD,X:NEXTAD HS 170 POKE53280,0:POKE53281,0 AP 180 PRINT"{CLR)(8){DOWN)";C

HR$(14) RQ 190 PRINT"***********SMART

{SHIFT-SPACE}FORMAT V1. 0***********"

FJ 200 PRINTCR$SPC(11)"1541 FA

ST FORMAT"CR$SPC(12)"WI

THOUT ~BUMP'" CA 210 PRINTCR$SPC(11) "BY RUST

IN AMBROSE" EQ 220 PRINT"[3 DOWN} ENTER:

{2 SPACES} DISKETTE NAME ,ID"

JR 230 PRINT" (NAME CAN HAVE MA

X OF 16 CHARS," BM 240 PRINT" I.D. MUST BE 2 C

HARS LONG)"; CR$ PH 250 DN$=" ":ID$=" ":INPUTDN$,

ID$:IF(DN$=" ") OR (ID$=" "

) THENEND KH 260 LN=LEN (DN$): IFLN> 16 THEN

PRINTCR$"--NAME TOO LON

G.":GOTO 220 BH 270 IFLEN (ID$) <> 2 THEN PRINTC R$"--I.D. NOT 2 CHARACT ERS LONG.":GOTO220

RJ 280 CS$="N0:"+DN$+CHRS (44)+

ID$ + CHR$ (13): CL=LEN (CS$

) : POKE49175, CL FP 290 FORI1= 1TOCL: POKE49151+ I

1, ASC (MID$ (CS$, I1, 1) +C0

$):NEXTI1 ED 300 : QF 310 CLOSE15:OPEN 15,8,15 SQ 320 PRINT#15,"M-R"CHR$(34);

C0$: GET# 15, T$: IFASC (T$+

C0$) THEN 380 HJ 330 PRINTCR$"**INTERNAL TRA

CK COUNTER OF DRIVE NEE

DS" FS 340 PRINT"{2 SPACES} TO BE I

NITIALIZED." EG 350 PRINT" {2 SPACES} PLEASE

{SPACE} INSERT ANY FORMA TTED DISKETTE."

BS 360 PRINT" {2 SPACES) THE DIS

KETTE WILL NOT BE AFFEC

TED**": GOSUB630 BX 370 PRINT#15,"I0":GOSUB700:

GOTO 320 XG 380 PRINTCR$"**PLACE DISKET

TE TO BE FORMATTED INTO

" FK 390 PRINT" {2 SPACES} DRIVE**

":GOSUB630 CP 400 PRINT#15,"M-R" CHR$ (30);

C0$: GET# 15, WP$: IFASC (WP

$ +C0$) AND 16 THEN 430 KJ 410 PRINTCR$"--WRITE PROTEC

T IS ON." AG 420 PRINT"--REPLACE DISKETT

E.": GOSUB630: GOTO 400 XF 430 PRINTCR$"**PLEASE CHECK

THAT DISKETTE IN" DE 440 PRINT"{2 SPACES} DRIVE S

HOULD BE FORMATTED." KS 450 PRINT"{2 SPACES} ALL DAT

A WILL BE DESTROYED!**" JC 460 PRINTCR$SPC (7) " [HIT SPA

CE BAR TO FORMAT ": GOSUB

640 CC 470 PRINT#15,"M-R"CHR$(34);

C0$:GET#15,T$:IFASC(T$+

C0$)=0THEN330 XB 480 PRINT#15,"M-R"CHR$(30);

C0$:GET#15,WP$:IF(ASC(W

P$+C0$)AND16)=0THEN410 EC 490 PRINTCR$"--FORMATTING

"IDN$","ID$'"' . . ." EP 500 PRINT#15,"M-W"CHR$(28);

C0$;CHR$(1);C0$ QM 510 OPEN2,8,2,"#1":PRINT#15

,"B-P";2;0:PRINT#2,A$;:

CLOSE2 FX 520 PRINT#15,"M-E"CHR$(28);

CHR$(4):GOSUB700 JQ 530 PRINTCR$"DONE!

{3 SPACES} [I.S. GAPS: "

; FR 540 PRINT#15,"M-R"CHR$(5)CH

R$(6)CHR$(4) XF 550 FORI1=0TO3:GET#15,G$:G(

I1)=ASC(G$+C0$):NEXTI1 AE 560 FORI1=3TO0STEP-1:PRINTG

I1);:NEXTI1:PRINT"]" BA 570 PRINTSPC(10)"[# OF RE-T

RIES:"; DJ 580 PRINT #15, "M-R" CHR$ (32) C

HR$ (6): GET #15, ER$: ER=AS

C (ER$+C0$) HB 590 PRINT10-ER"]" RH 600 CLOSE15:PRINTCR$"**FORM

AT ANOTHER?**":GOSUB630

:GOTO 220 GH 610: MH 620: SA 630 PRINTCR$SPC(7)" [HIT SPA CE BAR TO CONTINUE"

SF 640 PRINT-SPC(11) "OR ~E' TO {SPACE} EXIT)"

DB 650 POKE198,0 SK 660 GETI$:IFI$="E"THENCLOSE 15:END

QF 670 IFI$<>" "THEN660 JA 680 RETURN GR 690: CS 700 INPUT#15,E1$,E2$,E3$,E4 $:IFE1$="00"THENRETURN

DH 710 PRINTCR$"DRIVE ERROR #" E1$":"

KB 720 PRINT" ~ "2$"' TRACK#"E3 $" SECTOR#"E4$:CLOSE15: END

PS 730: KP 740 DATA1,4,10,0,174,23,4,1 34,163,189,255,3,157,25 5,1,202

BD 750 DATA208,247,160,70,162, 193,169,132,32,93,4,32, 48,6,160,13

AB 760 DATA162,238,169,61,32,9 3,4,32,48,6,160,54,162, 252,169,174

JH 770 DATA32,93,4,169,76,141, 0,6,169,123,141,1,6,169 ,4,32

HG 780 DATA210,200,76,64,238,1 40,105,4,142,106,4,141, 3,6,162,0

AH 790 DATA189,255,255,157,48, 6,232,200,204,3,6,208,2 43,169,96,157

AS 800 DATA48,6,96,165,81,16,1 9,169,6,141,33,6,169,15 ,141,34

KG 810 DATA6,169,10,141,32,6,1 69,1,133,81,160,0,209,5 0,240,13

JM 820 DATA201,2,208,6,174,38, 6,142,4,6,76,251,250,20 1,1,240

AX 830 DATA52,165,68,74,74,74, 74,74,170,189,24,4,24,1 09,4,6

RC 840 DATA157,5,6,141,38,6,32 ,48,6,173,12,28,41,31,9 ,192

RD 850 DATA141,12,28,169,255,1 41,3,28,169,85,141,1,28 ,162,2,32

EE 860 DATA36,254,76,177,252,7 6,0,251