' Format Demo to write FAST FORMATTED DISKS vs. .02
' Steve Crunk 1/30/90
'
' Hey, it's just a demo...
' So it doesn't have all the error trapping and glitzy stuff. It works.
'
CLS
'
' get graphics rez, calcuate offsets and so forth
rez%=XBIOS(4)
IF rez%=0
  offset%=11
ELSE
  offset%=30
ENDIF
DEFTEXT 1,5,0,6-7*(rez%=2)
TEXT 80-150*(rez%<>0),10-10*(rez%=2),"The FLASH FORMATTER"
DEFTEXT 1,0,0,6
'
' Parameters for Format call are:
' drv%=Drive Number
' sid%=1 for single sided ; 2 for double sided
' trk%=Number of tracks (usually 80, but 81 and 82 are possible)
' spt%=Number of sectors per track (9 is normal, but 10 is also ok)
' med%=media number (even for single sided, odd for double sided)
' intl%=interleave (if interleave is not one, then 11 is assumed)
'                  defaults for # sectors becomes 9 if interleave of 11 is used
'
DO
  msg$="Insert disk to|format in Drive A"
  ALERT 1,msg$,1,"GO ON|ABORT",ans
  IF ans=1
    @format(0,2,80,9,101,11)
    ' this call would format a double sided diskette with 80 tracks and 9
    ' sectors per track, in fast format, in drive a.
  ENDIF
  PRINT AT(offset%,3);"                         ";
  PRINT AT(offset%,4);"                         ";
  msg$=" Format another disk? "
  ALERT 2,msg$,1,"YES|END",ans
LOOP UNTIL ans=2
END
'
'
PROCEDURE format(drv%,sid%,trk%,spt%,med%,intl%)
  ON ERROR GOSUB error_handler
  IF drv%=0
    driv$="A"
  ELSE
    driv$="B"
  ENDIF
  msg$=" Are you SURE you | want to format | drive "+driv$+"?"
  ALERT 3,msg$,1,"GO AHEAD| STOP! ",ans
  IF ans=1
    IF intl%<>1
      spt%=9
    ENDIF
    buf$=STRING$(10500,0)
    VOID FRE(0)
    buf%=VARPTR(buf$)
    reformat:
    cnt%=0
    IF rez%=0
      BOX 78,70,241,104
      BOX 76,68,243,106
    ELSE IF rez%=1
      BOX 227,70,396,104
      BOX 223,68,400,106
    ELSE
      BOX 227,142,396,208
      BOX 225,140,398,210
    ENDIF
    SGET temp$
    dash1$="-"+CHR$(27)+"D"
    dash2$="*"
    FOR t%=0 TO trk%-1
      FOR s%=0 TO sid%-1
        e%=XBIOS(10,L:buf%,L:0,drv%,spt%,t%,s%,intl%,L:&H87654321,&HE5E5)
        IF e%=-13
          ERROR 70
        ELSE IF e%
          PRINT AT(1,18);"Side ";s%;" track ";t%;" Error ";e%;" sector ";
          b%=buf%
          WHILE DPEEK(b%)
            PRINT DPEEK(b%);" ";
            ADD b%,2
          WEND
        ELSE
          IF cnt%=0
            HTAB offset%
            VTAB 10
          ENDIF
          INC cnt%
          IF cnt%=40 OR cnt%=80 OR cnt%=120
            PRINT dash1$
            HTAB offset%
          ELSE
            PRINT dash1$;
          ENDIF
          SWAP dash1$,dash2$
        ENDIF
      NEXT s%
    NEXT t%
    ' ----- zero buffer
    buf$=STRING$(10500,0)
    buf%=V:buf$
    ' ----- write buffer to FAT and Directory
    ~XBIOS(9,L:buf%,L:0,drv%,1,0,0,9)
    ~XBIOS(9,L:buf%,L:0,drv%,1,0,1,9)
    ' ----- create & write the boot sector
    ~XBIOS(18,L:buf%,L:&H1111111,sid%+1,0)
    ~XBIOS(9,L:buf%,L:0,drv%,1,0,0,1)
    PRINT
    PRINT AT(offset%+1,3);DFREE(drv%+1);" Bytes free   "
    PRINT AT(offset%+1,4);"press any key..."
    ~INP(2)
  ENDIF
  SPUT temp$
  SHOWM
RETURN
PROCEDURE error_handler
  msg$="Disk is WRITE PROTECTED|or MISSING. Please fix|before continuing"
  ALERT 3,msg$,1," OK ",ans
  ON ERROR GOSUB error_handler
  RESUME reformat
RETURN
