Directory Manipulation Routines
Generalized Routines -- DIRF and DIRFS
Buffer Allocation Routine -- DBUFFER
Disk Parameter Information Extraction Routine -- DPARAMS
Free Space Computation Routine -- DFREE
File Size Computation Routine -- FSIZE
Directory Load Routines -- DIRLOAD and DIRSLOAD
Directory Alphabetization Routine -- DIRALPHA
Directory Entry Selection Routine -- DIRSEL
Directory Pack Routine -- DIRPACK
:Directory Manipulation Routines
    Thi� se� o� SYSLI� routine� concern� itsel� wit� th� loadin� �
o� an� acces� o� � dis� director� fo� th� genera� purpose� o� th� �
user.  Included in this set of routines are the functions of:
         1.  Preallocation of buffer space for the routines
         2.  Two routines which load all undeleted directory
              entries into a buffer, constantly checking for
              memory overflow as they go
                   DIRLOAD loads the first entry for each file
                        (this is the faster of the two)
                   DIRSLOAD loads the last entry for each file
                        (this routine is required if the
                             user wishes to compute file sizes)
         3.  A routine to determine the amount of free space on
              the disk
         4.  A routine to compute the size of a file in K
         5.  A routine to sort a loaded directory by file name
              and type or by file type and name
         6.  A routine to select (by marking) a set of directory
              entries which match a given ambiguous file spec
         7.  A routine to pack the loaded directory, leaving in
              it only those entries marked by the select routine
:Generalized Routines -- DIRF and DIRFS
    Routine Name: DIRF and DIRFS
    Function�
         Thi� routin� initialize� th� buffe� area�� load� � dis� �
directory�� select� � se� o� file� fro� th� loade� director� �
specifie� b�� th� user'� ambiguou� fil� nam� an� � passe� fla� �
(whic� indicate� i� Syste� file� ar� selected�� Non-syste� file� �
ar� selected�� al� use� area� ar� t� b� covered�� an� wha� �
particula� use� are� i� t� b� covere� i� al� use� area� ar� no� �
selected)� pack� th� directory� an� alphabetize� th� director� b� �
fil� nam� an� fil� type.
    I� DIR� i� used�� th� processin� proceed� faste� sinc� onl� �
th� firs� entr� o� eac� fil� i� loade� int� th� memor�� buffer�  �
Fil� sizin� informatio� i� no� include� i� thi� load� however.
    I� DIRF� i� used� th� processin� i� somewha� slower� bu� th� �
las� entr� fo� eac� fil� i� loade� rathe� tha� th� first��  Fil� �
sizin� informatio� i� containe� i� thi� entry��� an䠠 thi� �
informatio� ca� b� use� b� th� FSIZ� routine.
    Inputs:  HL points to a dynamic buffer which extends from
              after the user's code and buffer areas to the
              end of the TPA
             DE points to the first byte of the FCB used to
              specify the ambiguous file name; only the chars
              in the FN and FT fields are significant, so this
              need not be a true FCB and may be as short as 12
              bytes
             A is the selection flag, structured as follows:
              Bit 7 - If Set, Select Non-System Files
              Bit 6 - If Set, Select System Files
              Bit 5 - If Set, Select All User Areas
              Bits 4-0 - If Bit 5 is Cleared, contains number
                   of User Area to Select
    Outputs:  HL points to the first file entry in the buffer;
               each file entry is 16 bytes long
              BC contains the number of files selected
�����          A contains an error flag; A=0 and Zero Flag Set
�����           (Z) indicates TPA overflow error during load of
�����           directory entries; A<>0 and NZ indicates load OK

    Registers Affected:  HL, BC, PSW
    SYSLIB Routines Called:  DBUFFER, DIRLOAD, DIRSEL, DIRPACK,
                             DIRALPHA
    Special Error Conditions:  As outline for the A register
�����     above.


:Buffer Allocation Routine -- DBUFFER
    Routine Name: DBUFFER
    Function:
         Thi� routin� allocate� th� buffe� spac� necessar�� fo� �
th� se� o� director� function� i� general��  I� particular�� i� �
allocate� th� necessar� spac� fo� th� alphabetizatio� functio� a� �
wel� a� th� loade� director� itself��  Thi� routin� mus� b� use� �
i� th� DIRALPH�� routin� i� t� b� late� use� t� sor� th� �
directory�� thi� routin� allocate� al� th� spac� necessar�� b� �
DIRALPH� t� sor� th� routin� (pointe� space)�  I� thi� routin� i� �
called� i� i� no� necessar� t� cal� th� DPARAM� routine.
    Inputs:  HL points to the beginning address of a dynamic
�����          buffer area which extends to under the CCP
    Outputs:  HL points to the first byte at which the directory
�����           entries are to be loaded
�����          A=0 and Zero Flag is Set (Z) if the CCP is
�����           already overrun; else, A<>0 and NZ
    Registers Affected:  HL, PSW
    SYSLIB Routines Called:  DPARAMS
    Special Error Conditions:  As indicated by A reg and Z flag
:Disk Parameter Information Extraction Routine -- DPARAMS
    Routine Name:  DPARAMS
    Function:
    Thi� routin� extract� necessar� informatio� fro� th� Dis� �
Paramete� Bloc� (DPB� an� store� i� awa� i� som� globa� buffer� �
use� b� othe� Dis� Director� Routines�  Th� informatio� extracte� �
i� no� o� genera� concer� b� th� programmer��  AL� TH� PROGRAMME� �
NEEDӠ T� KNO� I� THA� THI� ROUTIN� MUS� B� CALLE� A� LEASԠ ONC� �
BEFOR� TH� DIRLOA� O� DIRSLOA� ROUTIN� I� CALLED�  I� th� DBUFFE� �
routin� i� called�� the� i� i� no� necessar�� t� cal� DPARAM� �
again.
    Fo� th� informatio� o� th� reader� th� followin� informatio� �
i� extracted:
�����          BLKSHF <-- Block Shift Factor (1 Byte)
�����          BLKMSK <-- Block Mask (1 Byte)
�����          EXTENT <-- Extent Mask (1 Byte)
�����          BLKMAX <-- Max Number of Blocks on Disk (2 Bytes)
�����          DIRMA� <-- Ma� Numbe� o� Di� Entrie� (� Bytes)
    Thi� routin� automaticall� adjust� fo� version� 1.� an� 2.� �
o� CP/� an� i� compatabl� wit� bot� version� o� CP/M.

    Inputs:  None
    Outputs:  None (Information Extracted into Buffers)
    Registers Affected:  None
    SYSLIB Routines Called:  None
    Special Error Conditions:  None
:Free Space Computation Routine -- DFREE
    Routine Name: DFREE
    Function:
         Thi� routin� compute� th� amoun� o� fre� spac� (i� � �
bytes� lef� o� disk.
    Th� routin� DPARAMӠ (o� DBUFFER�� sinc� i� als� call� �
DPARAMS�� mus� b� calle� befor� thi� routin� i� use� s� tha� th� �
correct disk parameter information is loaded for it.
    Inputs:  None
    Outputs:  DE = Amount of Free Disk Space in K Bytes
    Registers Affected:  DE
    SYSLIB Routines Called:  None
    Special Error Conditions:  None
:File Size Computation Routine -- FSIZE
    Routine Name: FSIZE
    Function:
         Thi� routin� compute� th� siz� o� � fil� whos� entr� �
(whic� MUS� b� loade� b� DIRSLOAD� i� pointe� t� b�� HL��  Thi� �
routin� wil� work� bu� generall� retur� incorrec� results� i� th� �
entr� pointe� t� wa� loade� b� DIRLOA� instead.
    Th� routin� DPARAMӠ (o� DBUFFER�� sinc� i� als� call� �
DPARAMS�� mus� b� calle� befor� thi� routin� i� use� s� tha� th� �
correct disk parameter information is loaded for it.
    Inputs:  HL points to first byte of file entry
    Outputs:  DE contains the file size in K Bytes
    Registers Affected:  DE
    SYSLIB Routines Called:  None
    Special Error Conditions:  None
:Directory Load Routines -- DIRLOAD and DIRSLOAD
    Routine Name: DIRLOAD and DIRSLOAD
    Function:
         DIRLOAĠ an� DIRSLOA� loa� entrie� fo� al� undelete� �
file� o� th� currentl� logge� i� dis� int� th� memor�� buffe� �
pointe� t� b� HL�  Al� entrie� ar� 1� byte� long.
    DIRLOAĠ i� faste� tha� DIRSLOAD��  I� load� jus� th� firs� �
entr� o� eac� fil� o� disk��  DIRLOAD�� however�� shoul� b� use� �
onl��� i� fil� sizin� informatio� i� no� require� b��� th� �
application� program.
    DIRSLOAĠ load� jus� th� LAS� entr� o� eac� fil� o� disk�  �
Thi� entr� contain� th� necessar� fil� sizin� informatio� whic� �
ma� b� use� b� FSIZ� t� comput� th� siz� o� th� loade� file.
    I� th� TP� i� fille� durin� DIRLOA� o� DIRSLOA� an� ther� �
ar� stil� mor� fil� entrie� t� load�� th� loa� wil� b� halte� an� �
a� erro� retur� wil� b� mad� t� th� caller��  O� return�� i� A=� �
an� th� Zer� Fla� i� Se� (Z)�� the� � loa� erro� occurred� �
otherwise� th� loa� wa� OK.


    Inputs:  HL points to the first byte of the directory buffer
�����          area; this area extends from after the last buffer
�����          used by the applications program to the page
�����          before the CCP.  If alphabetization is to be done,
�����          the value returned in HL by DBUFFER is a correct
�����          input for DIRLOAD or DIRSLOAD
�����         A=0 and Zero Flag is Set (Z) if TPA Overflow;
�����          A<>0 and NZ if load OK
    Outputs:  BC is the number of files loaded into the buffer
    Registers Affected:  BC
    SYSLIB Routines Called:  None
    Special Error Conditions:  If TPA is filled and load is
�����     incomplete, A=0 and Zero Flag is Set (Z) as error indic
:Directory Alphabetization Routine -- DIRALPHA
    Routine Name: DIRALPHA
    Function:
         T� alphabetiz� th� file� i� th� director� pointe� t� b� �
H̠ b� eithe� fil� nam� an� typ� (STEST.AS� goe� befor� TEST.AAA� �
o� b� fil� typ� an� nam� (TEST.AA� goe� befor� STEST.ASM).
    Inputs:  HL points to first directory entry
�����         BC contains the number of files to sort
�����         � i� th� sor� flag� A=� mean� sor� b� fil� nam� an� �
�����     �����then file type, A<>0 means by file type and name
    Outputs:  None (directory list is sorted)
    Registers Affected:  PSW
    SYSLIB Routines Called:  PRINT
    Special Error Conditions:
�����     I� i� possible�� alth� highl� unlikel� fro� al� test� �
�����give� s� far�� tha� DIRALPH� ma� experienc� a� interna� �
�����error.  If this happens, the message:
�����          DIRALPHA -- Pointer Error
�����wil� b� printe� an� th� routin� wil� abor� t� CP/M�  I� thi� �
�����happens�� pleas� repor� thi� proble� an� b� prepare� t� �
�����duplicat� th� exac� situatio� whic� cause� thi� erro� t� th� �
�����author, Richard Conn.
:Directory Entry Selection Routine -- DIRSEL
    Routine Name: DIRSEL
    Function:
         DIRSE̠ select� al� entrie� i� th� director�� buffe� �
whic� matc� th� ambiguou� fil� nam� specifie� i� th� FΠ an� F� �
field� o� th� FC� pointe� t� b� D� upo� entr�� t� DIRSEL��  � �
selectio� fla� i� als� passe� t� DIRSE� i� th� �� register�� an� �
thi� fla� tell� DIRSE� whethe� o� no� t� includ� Non-Syste� file� �
an� Syste� file� i� th� selectio� an� whethe� t� selec� file� i� �
al� use� area� o� i� � particula� use� area.
    DIRSE̠ identifie� th� selecte� fil� entrie� b� settin� th� �
Mos� Significan� Bi� o� th� firs� byt� o� eac� o� thes� entrie� �
t� � i� th� entr� i� selected��  DIRSE� make� n� othe� change� t� �
th� fil� entrie� i� th� director� buffer.

    Inputs:  HL points to the directory buffer
�����         DŠ point� t� th� FC� containin� th� ambiguou� F� �
�����          and FT fields; only the first 12 bytes are needed
�����         BC contains the number of files in the directory
�����         A contains a selection flag, organized as follows:
�����          Bit 7 - Select Non-System Files
�����          Bit 6 - Select System Files
�����          Bit 5 - Select Files in All User Areas
�����          Bits 4-0 - If Bit 5 is 0, indicates number of
�����               User Area to select files from
    Outputs:  None (MSBs of selected entries are set)
    Registers Affected:  None
    SYSLIB Routines Called:  None
    Special Error Conditions:  None
:Directory Pack Routine -- DIRPACK and DIRNPACK
    Routine Name:  DIRPACK
    Function:
         DIRPACˠ restructure� th� director� buffe� t� contai� �
onl� thos� entrie� marke� b� DIRSEL��  I� thi� way� thos� entrie� �
NOԠ marke� b� DIRSE� ar� discarde� fro� th� buffe� (actually� �
jus� take� ou� o� consideration�� bu� th� content� o� th� buffe� �
afte� th� las� selecte� entr� i� no� guarantee� t� contai� �
anythin� significant).
    Th� Mos� Significan� Bi� o� th� firs� byt� o� al� entrie� �
remainin� i� th� director� buffe� i� rese� t� � a� � sid� effec� �
o� DIRPACK.
    Inputs:  HL points to the directory buffer
�����         BC contains the number of files in the buffer
    Outputs:  BC contains the number of files (those selected by
�����           DIRSEL) remaining in the directory buffer
    Registers Affected:  BC
    SYSLIB Routines Called:  None
    Special Error Conditions:  None
    Routine Name:  DIRNPACK
    Function:
         DIRNPACˠ restructure� th� director� buffe� t� contai� �
onl�� thos� entrie� NO� marke� b� DIRSEL��  I� thi� way�� thos� �
entrie� marke� b� DIRSE� ar� discarde� fro� th� buffe� (actually� �
jus� take� ou� o� consideration�� bu� th� content� o� th� buffe� �
afte� th� las� selecte� entr� i� no� guarantee� t� contai� �
anythin� significant).
    Th� Mos� Significan� Bi� o� th� firs� byt� o� al� entrie� �
remainin� i� th� director� buffe� i� rese� t� � a� � sid� effec� �
o� DIRNPACK.
    Th� routin� DIRSE� MUS� b� calle� befor� DIRNPAC� i� use� �
sinc� DIRNPAC� use� a� interna� fla� se� b� DIRSE̠ (fo� SYSTE� �
and R/O information).
    Inputs:  HL points to the directory buffer
�����         BC contains the number of files in the buffer
    Outputs:  BC contains the number of files (those NOT selected
�����           by DIRSEL) remaining in the directory buffer
    Registers Affected:  BC
    SYSLIB Routines Called:  DIRPACK
    Special Error Conditions:  None