ATR: chpt.2: Disk Operating System (D:)

From: Doug Wokoun (aa384)
Date: 12/24/89-07:47:21 PM Z


From: aa384 (Doug Wokoun)
Subject: ATR: chpt.2: Disk Operating System (D:)
Date: Sun Dec 24 19:47:21 1989


                                   CHAPTER 2
     
     
                        THE DISK OPERATING SYSTEM (D:)
     
     
     The disk operating system program (DOS) is also called the file
     management system (FMS).  DOS is not a permanent part of the computer,
     it is loaded in upon power-up if a disk drive is attached to the
     computer.
     
     When the computer is turned on, one of the first things it does is
     send a request to the disk drive to load DOS into the computer.  This
     startup operation is called booting.  The word boot is short for
     bootstrapping -- the start-up process of early computers.  The term
     comes from "lifting one's self by one's boot straps".
     
     Anytime the disk boots, the computer tries to read a program starting
     at sector 1 and continuing in sequence.  If the disk has DOS on it,
     the first three sectors, called the boot record, have a program which
     loads the DOS.SYS file.  If there is no DOS.SYS file on the disk the
     computer will display:
     
     
       -------------------- 
      | BOOT ERROR         |
      | BOOT ERROR         |
      | BOOT ERROR         |
      | BOOT ERROR         |
      | BOOT ERROR         |
      | BOOT ERROR         |
      |   (etc.)           |
      |                    |
      |                    |
       -------------------- 
     
     
     When a disk is formatted, the drive read/write head passes over the
     entire disk and puts magnetic marks on it.  These marks divide the
     disk into 32 concentric tracks.  With DOS 2.0 each track is divided
     into 18 sectors, each holding 128 bytes of data.  With DOS 2.5 there
     are 32 sectors per track giving a total of 1,024 sectors.
     
     Each sector on the disk is marked with a reference number from 1 to
     720.  Unfortunately, the writers of DOS 2.0 didn't know this so they
     wrote the DOS to use sectors numbered from 0 to 719.  As a result, DOS
     2.0 cannot access sector 720.  The designers of the disk drive were
     the guilty party in this case.  It is normal to number from 0 in
     computers.  With DOS 2.5, sectors 720 - 1,024 can be accessed
     normally.
     
     Sector 720 can be accessed using the computer's resident disk handler.
     Some software writers use sector 720 to hide special information to
     make their programs difficult to copy.
     
     
     DOS 2 SECTOR ASSIGNMENTS
     
     Sectors 1 through 3 are called the boot record.  They contain a
     program which loads the DOS.SYS file into memory. 
     
     Sector 360 is called the Volume Table of Contents or VTOC.  The main
     purpose of the VTOC is to keep track of what sectors are occupied. 
     Bytes 3 and 4 of the VTOC tell how many sectors are available. 
     Starting at byte 10 is the Volume Bit Map.  Each byte in the VBM tells
     the status of eight sectors.  If a bit is a 1 the sector is available.
     If a bit is a 0 the sector is occupied.
     
     Sectors 361 through 368 contain the disk directory.  Each directory
     sector holds eight file names.  The first byte of a file name is
     called the flag byte.  It tells the status of that file.
     
     
                             Directory flag byte.
     
           7 6 5 4 3 2 1 0
          -----------------
          |   flag byte   |
          -----------------
     
     Bits: 7    1 = file deleted
           6    1 = file in use
           5    1 = file locked
           0    1 = open for output
     
     
     The next two bytes tell how many sectors are in the file.  The two
     bytes after them tell the starting sector of the file.  The last 11
     bytes contain the file name.
     
     Sector 720 cannot be accessed with DOS 2.0.
     
     The boot record, VTOC, directory and sector 720 use 13 sectors.  This
     leaves 707 sectors for storing files with DOS 2.0.
     
     Each file sector has 125 bytes of data.  The last three bytes tell how
     many bytes of the sector are used, what directory entry the sector
     belongs to and which sector is next in the file.
     
                             File sector structure
     
           7 6 5 4 3 2 1 0
          -----------------
          |     data      | byte 0
          - -           - -
          |     bytes     | byte 124
          -----------------
          | Dir. No.  |hi | byte 125
          -----------------
          |forward pointer| byte 126
          -----------------
          |S| byte count  | byte 127
          -----------------
     
          hi = high 2 bits of forward pointer
           S = Short sector flag. 1 = short sector (End Of File)
     
     
     If the directory number does not match the order of the file name in
     the directory, an error 167 (file number mismatch) will occur.
     
     
     As a file is written to an empty disk it is put in consecutive
     sectors, 125 bytes at a time.  After the file is written, the VTOC and
     directory are updated.  When new files are written they also use
     consecutive sectors.
     
     When a file is deleted the status bit of the directory is changed to
     show that the file has been deleted.  DOS then tracks the file, sector
     by sector, to find what sectors are used.  Finally the VTOC is updated
     to show that the deleted file's sectors are available for new files. 
     The file is not erased from the disk; only the VTOC and directory are
     changed.
     
     When a file is deleted, an "island" of free sectors may be left on the
     disk.  When a new file is then written to the disk it will first use
     these new free sectors.  When the island is used up, DOS will skip
     over the occupied sectors to the next free sector.  This is the reason
     for the sector link.  A file can end up with it's sectors scattered
     all over a disk.  It can be complicated but it's efficient.
                                                                           



                              DISK FILE STRUCTURE
     
     The first few bytes of a file may tell DOS or another program what
     kind of file it is.  These information bytes are called a header.
     
     A text file is any file which has no header.  A listed BASIC program
     is a type of text file.  A letter from a word processor is another.
     
     A binary load file is a file intended to load to a specific address in
     memory.  The first two bytes of a binary load file are decimal 255. 
     The next two bytes hold the address at which the file is to load.  The
     last two header bytes tell the ending address for the file.  If the
     file is a program and is to run automatically, the initialization and
     run address are appended to the end of the file.
     
     
                            binary load file header
     
     
           Decimal        Hexadecimal
     
             255  identifier   FF
             255               FF
               0     start     00
               7               07
              15      end      FF
               8               08
     
     
     The above file would load at address $0700 (1792 decimal) and end at
     address $08FF (2063).  If a binary load file has initialization and
     run address appended to it they take on the following format:
     
     
                              Init and run tailer
     
        CHR   Decimal        Hexadecimal
     
     
                              init address format
     
     
        [b]     226  identifier  E2
          |       2              02
        [c]     227              E3
          |       2              02
                  n    address   nn
                  n              nn
     
                              run address format
     
     
      [diamond] 224  identifier  E0

          |       2              02
        [a]     225              E1
          |       2              02
                  n    address   nn
                  n              nn
     
      [ ]=inverse video
     
     
     A program which doesn't need special initialization can be run at the
     init address.  Otherwise, an RTS instruction is expected at the end of
     the initialization section.  The computer will then jump to the run
     address if specified.
     
     
     INSIDE THE COMPUTER
     
     DOS uses the computer's CIO utility.  When a DOS disk is booted a
     non-resident handler is loaded into memory.  A new handler name, D, is
     then added to the handler table.  When CIO is called with a device
     name of D: or Dn:, CIO will search the handler table for that device
     name.  If the 'D' is found, the next two bytes in the table point to
     the DOS entry address.
     
     DOS FILE NAME CONVENTIONS
     
     DOS is unique among CIO handlers in that it requires an eight
     character file name to follow the device name.  This file name may be
     followed by a period and then a three character extender.
     
     
     EXAMPLES: D:TEST, D2:FIREMAN, D:VENTURE.EXE, D:CHAPTER.001
     
     
     The D2: is used for drive number two if present.
     
     The file name must use upper-case letters or numbers.  The first
     character must always be a letter.  
     WILD CARDS
     
     The characters * and ? may be used as wild cards.  * means any
     combination of characters and ? means any single character.
     
     
     EXAMPLES: D:P*           any file beginning with P and
                               without an extender
               D:*.EXE        any file with the extender .EXE
               D:*.*          any file.
               D:F?REMAN      one unknown character,
                               FIREMAN or FOREMAN will match
     
     
     Wild cards can only be used to load, delete, lock and unlock files. 

     When loading a file using wild cards, only the first matching file
     will be loaded.
     
     When renaming a file, both the new and old names are expected after
     the device name.
     
     EXAMPLE: D:OLDNAME.BAS,NEWNAME.BAS
     
     To format a disk, only the device name (D: or Dn:) is needed.
     
     
     USING DOS
     
     When a CIO channel is opened to the disk drive it must actually be
     opened to a specific file on the disk.  The device name in the open
     command must be followed by a file name.
     
     When a channel is opened to the disk, two special parameters may be
     used in ICAX1.
     
                             ICAX1 for disk open:
     
               7 6 5 4 3 2 1 0
              -----------------
              |        W R D A|
              -----------------
     
      D   1 = open to read the directory instead of a file
      A   1 = append data to the end of the file
     
     This gives the following extra ICAX1 options.
     
                         Disk specific ICAX1 options:
     
     
          HEX       DEC
     
          $06         6       open to read directory
          $09         9       output, append to the end of an
                              existing file
     
     
     READING THE DIRECTORY
     
     When the directory is read, each file name is treated as if it were
     followed by an EOL.  A loop must be used to read all of the file names
     in the directory.  The last entry read is the free sector count. 
     After it is read, another read operation will result in an End-Of-File
     error.
     
     The disk drive has a number of device specific commands other than the
     regular CIO commands.  From BASIC the XIO command is used to access
     these commands.  The XIO command allows you to directly load the IOCBs
     from BASIC.  Each parameter of the XIO command places values in
     certain bytes of an IOCB.
     
     
                              XIO command format:
     
     
      XIO command channel,aux1,aux2,device:file name
     
     
     Note that the parameters resemble the BASIC OPEN command.  The BASIC
     OPEN command is identical to it's equivalent XIO command.
     
     
                   XIO commands specific to the disk drive.
     
     RENAME    XIO  $20   (32)
     DELETE    XIO  $21   (33)
     LOCK      XIO  $23   (35)
     UNLOCK    XIO  $24   (36)
     POINT     XIO  $25   (37)
     NOTE      XIO  $26   (38)
     FORMAT    XIO  $FE  (254)
     
     
     EXAMPLES:
     
      XIO 33 #1,0,0,"D:JUNK" = delete file named D:JUNK
      XIO 32 #1,0,0,"D:OLD,NEW" = change name of D:OLD to D:NEW
     
     
     NOTE and POINT can also be used directly from BASIC.  NOTE finds the
     current position of the read/write head on the disk.  POINT moves the
     read/write head to the desired position.
     
     USING NOTE AND POINT
     
     The command format for NOTE and POINT is as follows:
     
     
      NOTE \
            channel,sector,byte
      POINT/
     
     
     EXAMPLE:
     
     
      NOTE #1,SECT,BYTE
     
     
     BASIC requires the sector and byte parameters in both commands to be
     variables.  Fixed numbers cannot be used.  If you try to do a POINT to
     a sector outside the file the channel is open to, a point error will
     occur.  Care may need to be taken to be sure the file being accessed
     is in contiguous sectors on the disk.  If it is not, it will be
     difficult to know where to do points to.
     
     One use of NOTE is to use the command immediately after opening a
     channel to a disk file.  After the NOTE command, the parameter
     variables contain the coordinates of the first byte of the file.  They
     can then be used as a reference for the POINT command.
     
     In assembly language, ICAX3 and ICAX4 are used for the sector number
     (lsb,msb).  ICAX5 is used for the byte number.
     
     STATUS REQUEST
     
     If the status request command is used, one of the following values
     will be found in ICSTA and the 6502 Y register.
     
     
          HEX       DEC
     
          $01         1       OK
          $A7       167       file locked
          $AA       170       file not found
                                                                           
-- 

-- 


-----------------------------------------
Return to message index