ASMB,L,C,R
      HED DBFRT IMAGE/1000 UTILITY SUBROUTINE 
      NAM DBFRT,7 92069-16154 REV.1912 790130 
* 
* 
******************************************************************* 
* (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-18154
*     RELOC:     92069-16154
* 
*     PRGMR:     CEJ
* 
* 
******************************************************************* 
* 
* 
* 
*  Find Run Table is a subroutine which searches through the Run Tables 
*  for all open data bases for the Run Table of the data base specified 
*  in the ibase parameter of the DBMS call. 
* 
*  On a DBOPN, the entire Run Table pointer table is searched sequential- 
*  ly for an entry pointing to the Run Table of the specified data base.
*  If the Run Table is found, the search is considered unsuccessful 
*  since the user may not open the same data base twice.  In addition,
*  on an DBOPN a successful search will return the index to the first 
*  empty entry in the Run Table pointer table.
* 
*  On any other call, the first word of the ibase parameter is used as
*  an index into the Run Table pointer table.  If the entry in this table 
*  points to the proper Run Table, the call is considered succesful and 
*  the address of the Run Table is passed back to the caller.  If the entry 
*  in the pointer table is empty or points to a Run Table not of the
*  specified data base the call is considered unsuccessful. 
* 
*  On entry the A register is set to zero if caller is DBOPN, to minus
*  one if not.  DBFRT returns the FOUND condition in the A register:
*  zero if data base found, -1 if not.
* 
*  The calling sequence from DBOPN for DBFRT is:
* 
*                 CLA 
*                 JSB DBFRT 
*                  DEF *+4
*                  DEF IBASE         IBASE parameter from DBMS call 
*                  DEF NAME          data base name 
*                  DEF CRN           data base CR number
* 
*  The calling sequence from any other DBMS routine for DBFRT is: 
* 
*                 CCA 
*                 JSB DBFRT 
*                  DEF *+2
*                  DEF IBASE         IBASE parameter from DBMS call 
* 
      ENT DBFRT 
      EXT .CMW,.ENTP,AIRUN,DBRTM,DBRTP
* 
A     EQU 0 
B     EQU 1 
* 
BASE  NOP 
NAME  NOP 
CRN   NOP 
* 
*  Get true addresses of parameters and return point. 
* 
DBFRT NOP 
      STA SAVE
      NOP           NOTE: This NOP is necessary for .ENTP!
      JSB .ENTP 
       DEF BASE 
* 
*  Initialize search parameters.
* 
      LDB BASE,I    Set index/node # variable 
      STB INDEX       to first word of ibase parameter
      LDB DBRTP     Get Run Table pointer table address 
      STB RTPTR       for search. 
* 
*  If FLAG = 0 indicating DBOPN requests search, perform serial search
*  on Run Table pointer table.  The index word of ibase is either a node
*  number or two blanks.
* 
      LDA SAVE
      SZA           If DBOPN calling, 
      JMP FRT6
      STA AIRUN       then set free entry index = 0 and 
      LDA DBRTM       set up for serial search. 
      CMA,INA       Entry counter = -maximum
      STA CNTR        Run Tables. 
* 
*  Perform serial search by examining each entry in the pointer table for 
*  either an empty flag (i.e. contents of first word of entry = 0) or a 
*  Run Table pointer.  If empty, then if this is the first empty entry
*  found, save its index in AIRUN and continue on to next entry.  If a
*  pointer, compare data base names, cartridge numbers, and node numbers
*  for a match.  If they do not match continue on to next entry.  If they 
*  do match return as unsuccessful (i.e. FOUND = TRUE). 
* 
FRT1  LDA RTPTR,I   Get contents of pointer table entry.
      SZA           If a zero,
      JMP FRT2
      LDA DBRTM       get entry's index 
      ADA CNTR
      INA 
      LDB AIRUN       then if first empty entry 
      SZB,RSS 
      STA AIRUN       save it for DBOPN to use
      JMP FRT5        and continue with search. 
* 
FRT2  LDB NAME      If not empty, get the passed name 
      JSB .CMW        (A already points to name in Run Table) 
       DEF D3         and compare names 
       DEC 0
      JMP FRT3
      NOP           If not a match
      JMP FRT5        continue with search. 
* 
FRT3  INA           If same, compare cartridge numbers
      LDB A,I         from CRN and Run Table
      CPB CRN,I 
      JMP FRT4      A match.
* 
      LDB CRN,I     If not a match, then if the user
      SZB             did not specify a cartridge,
      JMP FRT5        treat the CRN as if it matched. 
* 
FRT4  INA           If a match, compare node numbers
      LDB A,I         from IBASE and Run Table. 
      CPB NODE
      RSS 
      JMP FRT5      If not a match, continue with search
* 
      CLA 
      JMP DBFRT,I     else return to DBOPN unsuccessful.
* 
FRT5  ISZ RTPTR     Bump pointer table address to next entry
      ISZ CNTR      If more to search,
      JMP FRT1        continue on 
      CCA 
      JMP DBFRT,I     else return to DBOPN successfully 
* 
*  We come here when the call is from a DBMS subroutine other than DBOPN. 
*  The first word of the ibase parameter should be the entry number of
*  the entry in the Run Table pointer table which holds the Run Table 
*  pointer for the specified data base.  Use the entry number - 1 as an 
*  index into the pointer table and check the entry for validity (i.e.
*  non-empty pointer to proper Run Table).  But first, make sure the
*  entry number is within [1..20].
* 
FRT6  CCA 
      LDB INDEX 
      SSB 
      JMP DBFRT,I   Number < 0, illegal param.
* 
      SZB,RSS 
      JMP DBFRT,I   Number = 0, illegal param.
* 
      CMB,INB 
      ADB DBRTM 
      SSB 
      JMP DBFRT,I   Number > max. db's, illegal param.
* 
      ADA INDEX     Address of entry in pointer table = address of
      ADA RTPTR       pointer table + entry number - 1. 
* 
      LDB A,I       Get contents of entry.
      CCA 
      SZB,RSS       If entry empty (i.e. first word = 0)
      JMP DBFRT,I     return unsuccessful to caller.
* 
      STB AIRUN     Else, set up current Run Table
      CLA             address as this Run Table,
      JMP DBFRT,I     then return successful to the caller. 
* 
*  Constants and variables
* 
D3    DEC 3 
* 
SAVE  NOP 
INDEX NOP 
NODE  EQU INDEX 
RTPTR NOP 
CNTR  NOP 
      END 
                                                                                                                                                                              