ASMB,L,C,R
      HED DBHRD IMAGE/1000 UTILITY SUBROUTINE 
      NAM DBHRD,7 92069-16149 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-18149
*     RELOC:     92069-16149
* 
*     PRGMR:     CEJ
*     ALTERED:   JANUARY 22, 1980 FOR SORTED CHAINS FEATURE - CEJ 
* 
* 
******************************************************************* 
* 
* 
* 
*  Hash ReaD entry is a subroutine which finds the record in a master 
*  data set which contains a specified key value. 
* 
*  DBHRD first hashes into the specified master data set then reads the 
*  hashed record into the record buffer.  If the hashed record is a pri-
*  mary and contains the specified kay value, DBHRD returns with the read 
*  flag set to zero.  If the hashed record is a sysnonym, DBHRD returns 
*  with the read flag > 0.  A synonym in the primary location for a key 
*  can occur when a record containing the key value has not already been
*  entered.  Since DBPUT call DBHRD to make sure a record containing a
*  certain key value does not already exist before putting a new master 
*  record, this occurrance does not signify an error in DBHRD.  However,
*  all other callers will treat this return (i.e. read flag > 0) as an
*  error. 
* 
*  If the hashed record is a primary but does not contain the specified 
*  key value, DBHRD chases down any synonyms to the primary, searching
*  for a record containing the specified key value.  If a match is found, 
*  DBHRD returns with the read flag set to zero and the matching record 
*  in the record buffer.  If no match, DBHRD returns with the read flag 
*  < 0 and the sysnonym chain foot in the record buffer.
* 
*  DBHRD also returns the number of synonyms on the chain in the A & B
*  registers. 
* 
*  The calling sequence for DBHRD is: 
* 
*           JSB DBHRD 
*            DEF *+7        return point
*            DEF BASE       data base # (1st word of ibase parameter) 
*            DEF SET        master data set's number
*            DEF KEY        key item value
*            DEF READ       returned read flag: 
*                             <0 if no matching record found
*                             =0 if record found
*                             >0 if synonym in primary location 
*            DEF RECRD      returned doubleword record number of record 
*                             in record buffer. 
*            DEF ERROR      returned FMP or IMAGE error code
*                             zero if no error
* 
      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
*                                                                     * 
*********************************************************************** 
***                                                                 *** 
*                                                                     * 
      EXT .CMW,.DDI,.DIS,.DMP,.DSBR,.ENTR 
      EXT AIRUN,DBCIX,DBFDI,DBFDS 
      EXT DBRBP,DBRED,HASH
      ENT DBHRD 
A     EQU 0 
B     EQU 1 
* 
BASE  NOP 
SET   NOP 
KEY   NOP 
READ  NOP 
RECRD NOP 
ERROR NOP 
* 
*  Get true addresses of parameters and return point
* 
DBHRD NOP 
      JSB .ENTR 
       DEF BASE 
* 
*  Set synonym count to zero. 
* 
      CLA 
      STA SYCNT 
      STA SYCNT+1 
* 
*  Set read flag to < 0.
* 
      CMA 
      STA READ,I
* 
*  Get data set entry address in Run Table (this will be relative to the
*  start of the Run Table). 
* 
      JSB DBFDS 
       DEF *+5
       DEF SET,I
       DEF SETNO
       DEF FLAG 
       DEF DSADR
* 
*  If SETNO came back as zero, caller (i.e. other IMAGE subroutine) gave
*  us an errorneous data set number.
* 
      LDA SETNO 
      SZA,RSS 
      JMP E160      Error 160--Run Table corrupt
* 
*  Get master's media record length, capacity and key item number from
*  data set control block.
* 
      LDB DSADR     Must add relative set entry address to
      ADB AIRUN       beginning of Run Table to get true address. 
      ADB DSMDL     Increment to word containing media record 
      LDA B,I         length. 
      AND LOBYT     (In low order byte of this word.) 
      STA DAINX     Save it for computing key item's address. 
* 
      ADB D4        Increment to capacity words.
      STB CAPAC     Save address for later. 
* 
      ADB D2        Increment to word containing key item #.
      LDA B,I       In high order byte of this word.
      ALF,ALF       Make it an integer
      AND LOBYT       (i.e. put it into low order byte).
      SZA,RSS       If zero - currupt Run Table.
      JMP E160
      STA ITEM
* 
*  Get the item's Item Table entry address.  This will be relative to the 
*  start of the Run Table.
* 
      JSB DBFDI 
       DEF *+5
       DEF ITEM 
       DEF ITMNO
       DEF FLAG 
       DEF ITADR
* 
*  If ITMNO came back as zero, Run Table is corrupt.
* 
      LDA ITMNO 
      SZA,RSS 
      JMP E160
* 
*  Get item's length, and location in data record of master.
* 
      LDB ITADR     Get true address of item table entry. 
      ADB AIRUN 
* 
      ADB ITLNG     Increment to word containing item length. 
      LDA B,I 
      STA LENTH     Save for HASH.
* 
      JSB DBCIX     Call DBCIX to compute location
       DEF *+4        of key item in data record of 
       DEF ITMNO      master's data entry.
       DEF DSADR
       DEF INDEX
* 
      LDA INDEX     If the item could not be found in 
      SSA             the data set's record definition
      JMP E160        table - corrupt Run Table.
* 
*  Determine the primary record number of the key item value in the master
*  data set.  First, call the subroutine HASH to get a doubleword posi- 
*  tive integer value (returned in the A & B registers) then take the 
*  MOD of the returned value and the capacity of the data set and add 1.
* 
      JSB HASH
       DEF *+3
       DEF LENTH
       DEF KEY,I
      DST SAVE      Save returned value (dividend). 
* 
      JSB .DDI      Doubledivide returns quotient 
       DEF CAPAC,I    in A & B registers. 
* 
      JSB .DMP      Multiply the quotient by the divisor
       DEF CAPAC,I
* 
      JSB .DSBR       and substract it from the dividend
       DEF SAVE       to get the remainder (MOD). 
* 
      INB,SZB,RSS   Add one to the B reg.,
      INA             if carry add one to the A reg.
* 
      DST RECRD,I   This is the primary record #. 
      CCA 
      STA PRMRY     Set reading primary flag. 
* 
*                ENTER MAIN LOOP HERE 
*  This section reads a record from the master, determines if it contains 
*  the key item value sought.  If so, returns successful to the caller. 
*  If not, then if the record was to be the key's primary but is not a
*  primary (i.e. synonym flag set in entry) then retruns special case flag
*  to caller.  Else, if key's primary empty, then returns unsuccessful to 
*  caller.  If key's primary a primary record (i.e. primary flag set in 
*  entry) then traces through any synonyms to find a record containing
*  the key item value.  If no synonyms or end or synonym chain is found 
*  before a record containing the key item value is found, returns un-
*  successful to caller.  If any of the synonyms turn up empty, the data
*  base is corrupt and an error is returned.  (Afterall, we only read a 
*  synonym if it is pointed to by the record we just read.) 
* 
HRD1  JSB DBRED     Ask DBRED to get the record for us. 
       DEF *+4
       DEF BASE,I   data base number
       DEF SET,I    data set number 
       DEF RECRD,I  doubleword record number
* 
      SZA 
      JMP HRD6        return unsuccessful to caller.
* 
      LDA DBRBP,I   Get record flag type from record
      SZA           in record buffer.  If zero -
      JMP HRD2        record is empty.
      ISZ PRMRY     Check read type:
      JMP E154      If a synonym read - data base corrupt!
      JMP HRD5      If a primary read - return unsuccessful.
* 
HRD2  SSA,RSS       If a synonym, 
      JMP HRD3
      ISZ PRMRY       then if this was supposed to be the 
      JMP HRD3        key's primary --
      CLA,INA         return special flag.
      STA READ,I    (READ > 0 means synonym found 
      JMP HRD5        in primary location.) 
* 
*  Special cases taken care of, now increment synonym count and check 
*  record for matching key item value.
* 
HRD3  JSB .DIS
       DEF SYCNT
       NOP
* 
      LDA DBRBP     Get address of data record part 
      ADA DAINX       of set's entry. 
      ADA INDEX     Add in the key item's index and we
*                                  are at the compare point in the entry. 
      LDB KEY       Get the address of the specified key value
      JSB .CMW        and compare the two values. 
       DEF LENTH
       DEC 0
      JMP HRD4      A match!! 
* 
      NOP           }  unequal, 
      LDA D3        }    get forward synonym pointer
      ADA DBRBP       from entry. 
      DLD A,I       (in 2nd & 3rd words of record)
      SZB,RSS       If forward synonym pointer = 0
      SZA           (i.e. A & B both zero)
      RSS 
      JMP HRD5        return unsuccessful to caller.
* 
      DST RECRD,I   Else, make this the next record to read 
      CLA             and jump up to beginning of loop.  But first, 
      STA PRMRY       make sure primary flag is cleared.
      JMP HRD1
* 
*  Exit routines for DBHRD
* 
HRD4  CLA           Record with key value found,
      STA READ,I      read flag = 0.
HRD5  CLA           Whether found or not found, if no 
HRD6  STA ERROR,I     error exit, set ERROR to zero.
      DLD SYCNT     Get synonym count 
      JMP DBHRD,I     and return. 
* 
E154  LDA D154      Error exit - corrupt data base
      RSS 
E160  LDA D160      Error exit - corrupt Run Table
      JMP HRD6
* 
*  Constants and variables
* 
D2    EQU ZERO+2
D3    EQU ZERO+3
D4    EQU ZERO+4
D154  DEC 154 
D160  DEC 160 
LOBYT OCT 377 
* 
SETNO NOP 
FLAG  NOP 
DSADR NOP 
DAINX NOP 
CAPAC BSS 2 
SAVE  BSS 2 
SYCNT BSS 2 
ITEM  NOP 
ITMNO NOP 
ITADR NOP 
LENTH NOP 
INDEX NOP 
PRMRY EQU FLAG
      END 
                                                                                            