ASMB,L,C,R
      HED DBFDS & DBFDI IMAGE/1000 UTILITY SUBROUTINES
      NAM DBFDS,7 92069-16163 REV.2026 800122 
* 
* 
******************************************************************* 
* (C) COPYRIGHT HEWLETT-PACKARD COMPANY 1979. ALL RIGHTS RESERVED.
* NO PART OF THIS PROGRAM MAY BE PHOTOCOPIED, REPRODUCED, OR
* TRANSLATED TO ANOTHER PROGRAM LANGUAGE WITHOUT THE PRIOR WRITTEN
* CONSENT OF HEWLETT-PACKARD COMPANY. 
******************************************************************* 
* 
* 
*     SOURCE:    92069-18163
*     RELOC:     92069-16163
* 
*     PRGMR:     CEJ
*     ALTERED:   JANUARY 22, 1980 FOR SORTED CHAINS FEATURE - CEJ 
* 
* 
******************************************************************* 
* 
* 
* 
*  Find Data Set is a subroutine which searches the data set control block
*  table in the currently active Run Table for a set to determine its 
*  number, entry address, and the accessibility of the set. 
* 
*  The set whose table entry is to be found is passed to DBFDS as either
*  a set name or set number.  If a set name, it must be six characters
*  long padded with trailing blanks if necessary.  When the set is spe- 
*  cified by number the number is used to calculate the set's entry ad- 
*  dress as follows:
* 
*       Entryaddress = (Set Control Block Table address) +
*                      ((Set number - 1) * DSLNG<length of entry in table>) 
* 
*  When the set is specified by name, a binary search of the set control
*  block table is performed using the set sort table and comparing the
*  set name given with the name in the set control block table entry. 
*  If a match is found, the set's entry address is the address of the entry 
*  that matched.
* 
*  Once the set's entry is found, the entry is checked for the write and/ 
*  or read bit set and a flag is set to indicate whether both, one, or
*  neither are set.  DBFDS then returns to the user with the set number,
*  entry address and accessibility flag.  If the set was not found in the 
*  set control block table, the set number is set to zero before DBFDS
*  returns. 
* 
*  The calling sequence for DBFDS is: 
* 
*                  JSB DBFDS
*                   DEF *+5        return point 
*                   DEF SET        set name or number 
*                   DEF NUMBR      returned set number or zero
*                   DEF FLAG       returned accessibility flag: 
*                                   <0 if set writeable 
*                                   =0 if set readable
*                                   >0 if set inaccessible
*                   DEF DSADR      returned set table entry address 
* 
      SKP 
*********************************************************************** 
*                                                                     * 
*  Run Table for IMAGE/1000 Local machine.                            * 
*                                                                     * 
*  The Run Table is comprised of the following sections:              * 
*                                                                     * 
*    1)  Data Base Control Block                                      * 
*    2)  Item Table                                                   * 
*    3)  Data Set Control Block Table                                 * 
*    4)  Data Set Info Table                                          * 
*        A)  Record Definition Table                                  * 
*        B)  Path Table                                               * 
*    5)  Sort Table                                                   * 
*    6)  Free Record Table                                            * 
*                                                                     * 
*  These sections appear in the order described.  Details of each     * 
*  section follow.                                                    * 
*                                                                     * 
*********************************************************************** 
***                                                                 *** 
*                                                                     * 
*  Data Base Control Block - one 59 word entry per data base          * 
*                                                                     * 
***                                                                 *** 
DBCBS DEC 59        Control Block Size
DBNAM DEC 0         Data Base name - 3 words
      DEC 1 
      DEC 2 
DBSCD DEC 3         Data Base Security Code (FMP) 
DBCRN DEC 4         Data Base Cartridge Number (FMP)
DBDSN DEC 5         Data Base node number (DS/1000) 
DBRSN DEC 6         Data Base resource number 
DBICT DEC 7         Data Item Count 
DBITP DEC 8         Data item table pointer 
DBSCT DEC 9         Data set count
DBSTP DEC 10        Data set control block table pointer
DBSOP DEC 11        Sort table pointer
DBFRP DEC 12        Free record table pointer 
DBLMD DEC 13        Data Base lock flag and open mode 
DBLFG EQU DBLMD     1st byte: lock flag 
DBMOD EQU DBLMD     2nd byte: open mode 
DBLVL DEC 14        Access level words - 3 words per level
DBFRL EQU DBLVL     Free record table length
DBOPT DEC 15        Optimal number of DCBs
DBMAX DEC 16        Maximum size of a data entry
DCBWS DEC 17        DCB storage area
* 
ZERO  EQU DBNAM     base of zero for future equates 
***                                                                 *** 
*                                                                     * 
*  Data Item Table - one 7-word entry per item                        * 
*                                                                     * 
***                                                                 *** 
ITELN EQU ZERO+7    item table entry length 
ITNME EQU ZERO      item name - 3 words 
ITINF EQU ZERO+3    item write/read level and type
ITRDL EQU ITINF     1st nibble: item read level 
ITWRL EQU ITINF     2nd nibble: item write level
ITTYP EQU ITINF     2nd byte: item type 
ITSET EQU ZERO+4    set count and 1st set number
ITSCT EQU ITSET     1st byte: set count 
ITSNO EQU ITSET     2nd byte: set number
ITWRC EQU ZERO+5    write/read bits and element count 
ITECT EQU ITWRC     2nd byte: element count 
ITLNG EQU ZERO+6    item length in words
***                                                                 *** 
*                                                                     * 
*  Data Set Control Block Table - one 17 word entry per set           * 
*                                                                     * 
***                                                                 *** 
DSLNG EQU ZERO+17   table entry length
DSNME EQU ZERO      set name - 3 words
DSCRN EQU ZERO+3    cartridge reference number
DSINF EQU ZERO+4    W/R bits, set type and media length 
DSTYP EQU DSINF     1st byte, 2nd nibble: set type
DSMDL EQU DSINF     2nd byte: media record length 
DSDRL EQU ZERO+5    data record length
DSFPC EQU ZERO+6    field and path counts 
DSFCT EQU DSFPC     1st byte: # fields per entry
DSPCT EQU DSFPC     2nd byte: # paths per entry 
DSITP EQU ZERO+7    data set info table entry pointer 
DSCAP EQU ZERO+8    doubleword data set capacity
DSCPN EQU ZERO+10   current path info 
DSCCT EQU DSCPN     1st byte: search item number
DSPAN EQU DSCPN     2nd byte: path # of search item 
DSRCN EQU ZERO+11   doubleword current record number
DSBWN EQU ZERO+13   doubleword previous record number 
DSFWN EQU ZERO+15   doubleword next record number 
***                                                                 *** 
*                                                                     * 
*  Data Set Info Table - one Record Definition Table and one Path     * 
*    Table per data set                                               * 
*                                                                     * 
***                                                                 *** 
*                                                                     * 
*  Record Definition Table - one 1-byte entry per field               * 
*                                                                     * 
***                                                                 *** 
RDLNG EQU ZERO+1    entry length (number of words)
RDINF EQU ZERO      field info (two fields per word)
RDIT1 EQU RDINF     1st byte: item # for field n
RDIT2 EQU RDINF     2nd byte: item # for field n+1
***                                                                 *** 
*                                                                     * 
*  Path Table - one 2-word entry per path                             * 
*                                                                     * 
***                                                                 *** 
PTLNG EQU ZERO+2    entry length
PTINF EQU ZERO      path information - item & set numbers 
PTSIN EQU PTINF     1st byte: detail's search item # for path 
PTDSN EQU PTINF     2nd byte: related set's number
PTSRT EQU ZERO+1    sort item for path
***                                                                 *** 
*                                                                     * 
*  Sort Table - one 1-word entry per item and set                     * 
*                                                                     * 
***                                                                 *** 
STITS EQU ZERO      beginning of item entries 
STSTS NOP           beginning of set entries
***                                                                 *** 
*                                                                     * 
*  Free Record Table - one 4-word entry per set                       * 
*                                                                     * 
***                                                                 *** 
FRLNG EQU ZERO+4    length of entry 
FRRCT EQU ZERO      doubleword free record count
FRPTR EQU ZERO+2    doubleword first free record
*                                                                     * 
*********************************************************************** 
***                                                                 *** 
*                                                                     * 
      ENT DBFDI,DBFDS 
      EXT .CMW,.ENTR,AIRUN
A     EQU 0 
B     EQU 1 
* 
SET   NOP 
NUMBR NOP 
FLAG  NOP 
DSADR NOP 
* 
*  Get true addresses of parameters and return point. 
* 
DBFDS NOP 
      JSB .ENTR 
       DEF SET
* 
*  Initialize search parameters.
* 
      LDA AIRUN     Get # of sets in data base
      ADA DBSCT       as upper bound for set #
      LDB A,I         or binary search index. 
      STB HIGH
* 
      INA           Get address of set table for
      LDB A,I         binary search (this is relative 
      STB TABAD       to start of Run Table). 
* 
      INA           Set sort table address =
      LDB A,I         pointer to Sort Table 
      ADA M4
      ADB A,I         + number of items in data base
      ADB AIRUN       + address of Run Table. 
      STB STADR 
* 
      LDA DSLNG     Data Set Control Block Table
      STA ENTLN       entry length. 
      LDA DSINF     W & R bits in 5th word
      STA WRBTS       of DSCB entry.
* 
*  Initialize return parameters.
*    (DBFDI joins with DBFDS at this point.)
* 
JOIN  CLA 
      STA NUMBR,I   Set number to zero (not found). 
      INA           Set accessiblity flag > 0 
      STA FLAG,I      (set inaccessible). 
* 
*  Determine if name or number was given.  If a number, the high order
*  byte with be zero, if a name, non-zero.  In either case, if the sign 
*  bit is set, the parameter is erroneous.
* 
      LDA SET,I     Get high order byte of first
      AND HIBYT       word of SET.
      SSA           If sign bit set,
      JMP DBFDS,I     return unsuccessful to caller.
      SZA           If byte non-zero, 
      JMP FDS1        perform search on name. 
* 
*  We come here when a number is given.  Make sure the number falls 
*  within the bounds of 1 <= SET <= upper bound (HIGH).  Then, use the
*  number as an index into the table to get the set's (or item's) entry 
*  address. 
* 
      LDA SET,I     Get number again. 
      SZA,RSS       If zero,
      JMP DBFDS,I     return unsuccessful to caller.
      CMA,INA       If > # sets (or items) in data base,
      ADA HIGH
      SSA 
      JMP DBFDS,I     return unsuccessful to caller.
* 
      LDA SET,I     Else all okay,
      STA NUMBR,I     put number in return parameter. 
* 
      ADA M1        Calculate entry address = 
      CLB             (number - 1) *
      MPY ENTLN       entry length (ENTLN) +
      ADA TABAD       table address,
      STA DSADR,I 
      JMP FDS5        then go check accessibility.
* 
*  We come here when a name is given.  A simple binary search of the
*  Set Control Block Table (or Item Table) is performed using the Sort
*  Table as a sorted binary tree and using the name given and the name
*  in the table entry as the object of comparison.
* 
FDS1  CLA           Initialize search parameters: 
      STA LOW         0->LOW
      LDA HIGH        # sets (or items) in base + 1 -> HIGH 
      INA 
      STA HIGH
      ARS           Get first index into Sort Table = 
      STA INDEX       HIGH / 2. 
* 
*                   BEGIN MAIN LOOP HERE
*  The following is the actual binary search.  The search is performed
*  on the Sort Table.  The entries of the Sort Table contain set (or item)
*  numbers.  When an entry of the table is chosen by the algorithm, the 
*  number it contains is used to calculate the true address of the set's
*  (or item's) table entry (i.e. not relative to the start of the Run 
*  Table but rather that relative address plus the address of the Run 
*  Table).  The comparison of the set (or item) names is then done. 
* 
FDS2  ADA STADR     A = sort table entry =
      ADA M1          sort table address + INDEX - 1. 
      LDA A,I 
      STA SANUM     SANUM = set (or item) number
* 
      ADA M1        Determine entry index in Table. 
      CLB 
      MPY ENTLN 
      ADA TABAD     SAENT = address of set's (or item's) entry
      STA SAENT       relative to beginning of Run Table. 
* 
      ADA AIRUN     A = true address of set's entry.
* 
      LDB SET       Compare set names.
      JSB .CMW
       DEF D3 
       DEC 0
      JMP FDS4      A match!
      JMP FDS3      entry name < given name 
* 
      CCA           entry name > given name 
      ADA INDEX     Calculate next (lower) index to use.
      CMA,INA 
      ADA LOW       If this is lowest 
      SSA,RSS         return unsuccessful to caller.
      JMP DBFDS,I 
* 
      LDA INDEX     Else this index becomes the HIGH
      STA HIGH
      LDB LOW         and INDEX = 
      CMB,INB         INDEX - 
      ADA B           (HIGH - LOW) / 2. 
      ARS 
      CMA,INA 
      ADA INDEX 
      STA INDEX 
      JMP FDS2      Try this entry. 
* 
FDS3  LDA INDEX     entry name < given name 
      INA           Calculate next (higher) index to use. 
      CMA 
      ADA HIGH      If this is highest, 
      SSA             return unsuccessful to caller.
      JMP DBFDS,I 
* 
      LDA INDEX     Else this index becomes the LOW and 
      STA LOW 
      CMA,INA         INDEX = 
      ADA HIGH        INDEX + 
      ARS             (HIGH - LOW) / 2. 
      ADA INDEX 
      STA INDEX 
      JMP FDS2      Try this entry. 
* 
*  When (if) found, put number and relative entry address in return 
*  parameters.
* 
FDS4  LDA SANUM 
      STA NUMBR,I 
      LDA SAENT 
      STA DSADR,I 
* 
*  Join number and name processing here to determine accessibility of 
*  set (or item). 
* 
FDS5  ADA AIRUN     Get true address of entry.
      ADA WRBTS     Bump to word containing W & R bits
      LDA A,I         and pick it up. 
* 
      SSA           If sign bit set,
      JMP FDS7        set or item is witeable 
      RAL             else if next to sign bit is set 
      SSA 
      JMP FDS6          it is readable
      JMP DBFDS,I       else it is inaccessible.
* 
FDS6  CLB,RSS       FLAG = 0 means set (or item) readable 
FDS7  CCB           FLAG < 0 means set (or item) writeable
      STB FLAG,I    Set flag
      JMP DBFDS,I     and return. 
* 
*  Constants and variables. 
* 
M4    DEC -4
M1    DEC -1
D3    EQU ZERO+3
HIBYT OCT 177400
* 
HIGH  NOP 
LOW   NOP 
INDEX NOP 
* 
TABAD NOP 
STADR NOP 
SANUM NOP 
SAENT NOP 
ENTLN NOP 
WRBTS NOP 
      SKP 
* 
*  Find Data Item is a subroutine which searches the item table in the
*  currently active Run Table for an item to determine its number, entry
*  address (relative to beginning of Run Table) and whether or not the
*  item is accessible.
* 
*  The item whose entry is to be found is passed to DBFDI as either an
*  item name or item number.  If an item name it must be six characters 
*  long padded with trailing blanks if necessary.  When the item is speci-
*  fied by number, the number is used to calculate the item entry address 
*  as follows:
* 
*     Entry-address=(item table address + ((item # - 1) * 7)) 
* 
*  When the item is specified by name, a binary search of the item table
*  is performed useing the item sort table and comparing the item name
*  given with the name in the item table entry.  If a match is found, the 
*  entry address is the address of the entry that matched.
* 
*  Once the item's entry is found, the entry is checked for the write 
*  and/or read bit set and a flag is set to indicate whither both, one, 
*  or neither is set.  DBFDI then returns to the user with the item number, 
*  entry address, and mode of acces.  If the item was not found in the
*  item table, the item number is set to zero before DBFDI returns. 
* 
*  The calling sequence for DBFDI is: 
* 
*           JSB DBFDI 
*            DEF *+5
*            DEF ITEM          item name array or number
*            DEF ITNO          returned item # if found, else 0 
*            DEF ITFLG         returned accessibility flag: 
*                                <0 if item writeable 
*                                =0 if item readable
*                                >0 if item inaccessible
*            DEF DIADR         returned item table entry address relative 
*                                to beginning of the Run Table
* 
* 
*  Since the algorithms of DBFDS and DBFDI are identical, DBFDI is entered
*  only to set up the search parameters that are specific to data items,
*  move the parameter and return point addresses to the DBFDS entry point 
*  then, DBFDI joins DBFDS for actual table entry calculation.
* 
      SKP 
* 
ITEM  NOP 
ITNO  NOP 
ITFLG NOP 
DIADR NOP 
* 
*  Get true parameter and return point addresses. 
* 
DBFDI NOP 
      JSB .ENTR 
       DEF ITEM 
* 
*  Initialize search parameters.
* 
      LDA AIRUN     Get # of items in data base as
      ADA DBICT       upper bound for item number 
      LDB A,I         or binary search index. 
      STB HIGH
* 
      INA           Get address of item table for 
      LDB A,I         binary search (this is
      STB TABAD       relative to start of Run Table).
* 
      ADA D3        Item sort table address = 
      LDB A,I         pointer to Sort Table 
      ADB AIRUN       + address of Run Table. 
      STB STADR 
* 
      LDA ITELN     Item Table entry length.
      STA ENTLN 
      LDA ITWRC     W & R bits in 6th word of 
      STA WRBTS       Item Table entry. 
* 
*  Make DBFDS look like the entry point and join the DBFDS process. 
* 
      LDA ITEM      Parameters: 
      STA SET 
      LDA ITNO
      STA NUMBR 
      LDA ITFLG 
      STA FLAG
      LDA DIADR 
      STA DSADR 
* 
      LDA DBFDI     Return point: 
      STA DBFDS 
* 
      JMP JOIN
      END 
      END$
                                                                                                                                                                                                                          