ASMB,L,C,R
      HED DATA BASE CO-ORDINATING PROGRAM OF IMAGE/1000 
      NAM DBCOP,4,50 92069-16256 REV.1912 790316
* 
* 
******************************************************************* 
* (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-18256
*     RELOC:     92069-16256
* 
*     PRGMR:     CEJ
* 
* 
******************************************************************* 
* 
* 
* 
*  DBCOP is the Data Base Co-Ordinating Program used by all IMAGE soft- 
*  ware modules to co-ordinate access to all data bases on the system.
*  In order to control access, DBCOP sets up and maintains a co-ordinating
*  table consisting of 20 27-word entries where each entry is formatted as
*  follows: 
* 
*       +-----------------------------------------------+ 
*       |           data base                           | 
*       |                root file                      | 
*       |                     name (3 words)            | 
*       ------------------------------------------------- 
*       |               cartridge number                | 
*       ------------------------------------------------- 
*       |      open mode        |       # of users      | 
*       ------------------------------------------------- 
*       |               resource number                 | 
*       +-----------------------------------------------+ 
*       |            name of first program with         | -> -1 if empty
*       |                  data base open               | 
*       |                     (3 words)                 | 
*       ------------------------------------------------- 
*       .                       .                       . 
*       .                       .                       . 
*       .                       .                       . 
*       ------------------------------------------------- 
*       |            name of seventh program with       | -> -1 if empty
*       |                  data base open               | 
*       |                     (3 words)                 | 
*       +-----------------------------------------------+ 
* 
*  (An empty entry is signified by a -1 in the first two characters of
*  the data base name.) 
* 
*  DBCOP currently provides four services to the calling program.  The
*  specific function provided by DBCOP for each schedule is defined by a
*  passed function code, where the function codes are defined as follows: 
* 
*    1 - check open mode on data base for obtainability 
*    2 - add user to co-ordinating table
*    3 - remove user from co-ordinating table 
* 
*   -1 - return a copy of co-ordinating table to scheduler (used solely 
*        by RECOV)
* 
*  The scheduling sequence for DBCOP is:
* 
*         JSB EXEC         Call EXEC to schedule program
*          DEF *+10 
*          DEF D23         (schedule queue with wait) 
*          DEF NAME        name = "DBCOP" 
*          DEF FC/MD       DBCOP function code in first byte, 
*                            open mode in second byte.
*                            For RECOV, entire word is -1.
*          DEF DBNAM       data 
*          DEF DBNAM+1         base 
*          DEF DBNAM+2             name 
*          DEF CRN         Data Base cartridge number.
*          DEF PNAME       buffer containing program's name 
*          DEF D3          length of buffer 
* 
*  DBCOP returns up to two parameters to its father.  The first is always 
*  returned and is the status word, zero if successful, non-zero if un- 
*  successful.  The second is a resource number for a function code 2 
*  schedule, the remaining user count for a function code 3 schedule, or
*  a class number for a function code -1 schedule.  The RN is the data
*  base RN for mode 1 DBOPNs, the class number is the class on which DBCOP
*  wrote a copy of the co-ordinating table for RECOV to retrieve. 
* 
      EXT .CMW,.MVW,DTACH,EXEC,PRTN,RMPAR,RNRQ
* 
      SUP 
A     EQU 0 
B     EQU 1 
* 
FC/MD NOP 
DBNAM BSS 3 
CRN   NOP 
* 
*  Retrieve scheduling parameters 
* 
BEGIN JSB RMPAR 
       DEF *+2
      DEF FC/MD 
* 
      JSB EXEC
       DEF *+5
       DEF NA14     No abort string passage 
       DEF D1       retrieve string code = 1
       DEF PNAME,I
       DEF D3 
      NOP 
* 
      JSB DTACH     Tell Session Monitor that 
       DEF *+2        we are not a session program. 
       DEF DUMMY
* 
*  If the function code > 0, then search the co-ordinating table for an 
*  entry containing the passed name and cartridge number.  Also, find the 
*  first empty entry in the table.
* 
      LDA FC/MD     If function code = -1 
      SSA             jump to -1 process
      JMP FCM1
* 
      AND LOBYT     Else split open mode and
      STA MODE
      LDA FC/MD       function code 
      ALF,ALF 
      AND LOBYT 
      STA FCODE 
* 
      LDA DBCNT       and perform table search
      STA COUNT     Set loop counter = - # entries in table 
* 
      CLA 
      STA EMPTY     Set empty entry pointer to zero 
* 
      CMA 
      STA FOUND     Set found flag to FALSE (-1)
* 
      LDA COTAB     Get address of next entry in table
LOOP1 STA SAVE        and save. 
      LDB A,I       If the first word of the entry is negative, 
      SSB             the entry is empty
      JMP LOOP2 
* 
      LDB NAMAD     If non-empty, compare data base 
      JSB .CMW        names.
       DEF D3 
       DEC 0
* 
      JMP SAME1     entry name same as passed name
* 
      NOP           entry name LT passed name 
      JMP LOOP3     entry name GT passed name 
* 
SAME1 LDB A,I       Names the same, see if the CRNs 
      CPB CRN         are.
      JMP SAME2       Yes - get out of loop 
      JMP LOOP3       No - just continue. 
* 
LOOP2 LDB EMPTY     came here from empty jump 
      SZB,RSS       if first empty entry, 
      STA EMPTY       save its address for future use 
* 
LOOP3 LDA SAVE      Get next entry address
      ADA ENTSZ 
      ISZ COUNT       (if there is one) 
      JMP LOOP1       and try it
* 
      JMP LOOPE       else we've completed search.
* 
SAME2 ADA M3        Come here from successful comparison--
      CLB             point back to top of entry &
      STB FOUND     set found flag to TRUE (0)
* 
LOOPE LDB FCODE     Get function code again and 
      CMB,INB       compliment it for CASE statement. 
      INB,SZB,RSS 
      JMP FC1         FCODE = 1 
      INB,SZB,RSS 
      JMP FC2         FCODE = 2 
      INB,SZB,RSS 
      JMP FC3         FCODE = 3 
* 
      JMP E161      Illegal FCODE!!! - "shouldn't" happen.
* 
*  Function code = 1
*  Check desired data base and open mode for obtainability. 
* 
FC1   LDB FOUND     If data base already open to someone
      SZB             (i.e. an entry matched) 
      JMP NOTOP 
* 
      ADA OP/CT       then check to make sure that the
      LDA A,I         data base is not open in mode 3 
      ALF,ALF         and if open in the same mode
      AND LOBYT       as the one desired by this father.
      CPA D3
      JMP E129      open in mode 3 - only one user
* 
      CPA MODE
      JMP OKAY      same open mode - user okay
      JMP E152      different modes - unobtainable open 
* 
NOTOP LDB EMPTY     Data base is not already open 
      SZB             is there an empty entry in which
      JMP OKAY        to add it?
      JMP E131        No--unobtainable open 
* 
*  Function code = 2
*  Add the user to the co-ordinating table
* 
FC2   LDB FOUND     If entry already exists for 
      SZB             this data base, 
      JMP NEW 
* 
      LDB A           then make sure open modes match 
      ADB OP/CT       and open mode is not 3. 
      LDA B,I 
      ALF,ALF 
      AND LOBYT 
      CPA D3
      JMP E129      Open mode 3, only one user. 
* 
      CPA MODE      If modes match
      RSS 
      JMP E152
* 
      LDA B,I         increment the user count. 
      INA 
      STA B,I 
* 
      INB           Put RN in return parameter for father.
      LDA B,I 
      STA RN/CL 
* 
      LDA M7        Find next empty slot for name.
      STA COUNT 
      INB 
FC2A  LDA B,I 
      SSA 
      JMP FC2B
      ADB D3
      ISZ COUNT 
      JMP FC2A
      LDB SAVE      No empty slot, reduce user count again. 
      ADB OP/CT 
      CCA 
      ADA B,I 
      STA B,I 
      JMP E131
* 
FC2B  LDA PNAME     Put name in slot
      JSB .MVW
       DEF D3 
       DEC 0
      JMP OKAY        and return successful.
* 
NEW   LDB EMPTY     Entry doesn't exist, must create one
      SZB,RSS         if there is room. 
      JMP E131
* 
      LDA MODE      If open mode =1 
      CPA D1
      RSS 
      JMP BUILD 
* 
      JSB RNRQ        then we have to allocate an RN
       DEF *+4
       DEF ALLOC
       DEF RN/CL
       DEF ERROR
      JMP E132      Call was in error (?) 
* 
      LDA RN/CL     Was an RN available?
      SZA,RSS 
      JMP E132        No--cannot create entry 
* 
      LDB EMPTY       Yes--put it in entry. 
      ADB RNIDX 
      STA B,I 
      LDB EMPTY 
* 
BUILD LDA NAMAD     Put data base name in entry.
      JSB .MVW
       DEF D3 
       DEC 0
      LDA CRN       Put cartridge # in entry. 
      STA B,I 
      INB 
      LDA MODE      Put open mode and user count = 1
      ALF,ALF         in entry. 
      INA 
      STA B,I 
      ADB D2        Put the program's name
      LDA PNAME       in first name slot. 
      JSB .MVW
       DEF D3 
       DEC 0
      JMP OKAY      Then, the entry is built. 
* 
*  Function code = 3
*  Remove a user from the co-ordinating table 
* 
FC3   LDB FOUND     The entry must be there 
      SZB             else this is an erroneous schedule
      JMP E103
* 
      ADA OP/CT     Decrement user count for data base
      CCB 
      ADB A,I 
      STB A,I 
* 
      LDA B         Get remaining user count
      AND LOBYT       and store it in the 
      STA USCNT       2nd return parameter. 
* 
      LDA M7        Find the slot containing
      STA COUNT       this program's name.
      LDB SAVE
      ADB NAMES 
FC3A  STB EMPTY 
      LDA PNAME 
      JSB .CMW
       DEF D3 
       DEC 0
      JMP FC3B      Names match.
      NOP 
      LDB EMPTY     Not a match,
      ADB D3          continue for all entries. 
      ISZ COUNT 
      JMP FC3A
      JMP FC3C      No name match.
* 
FC3B  CCA           Set found slot to empty 
      STA EMPTY,I 
      LDA USCNT     Now get count again.
      SZA           If count NE 0 
      JMP OKAY        then this process is done 
* 
      LDB SAVE
      ADB OP/CT 
      LDA B,I         else we must remove the 
      ALF,ALF         entry entirely. 
      AND LOBYT 
      CPA D1        For an open mode = 1
      RSS             this means releasing
      JMP ERASE       the allocated RN. 
* 
      LDB SAVE      Get it from the entry & 
      ADB RNIDX       put it in the RNRQ call.
      STB RNADR 
* 
      JSB RNRQ      Deallocate the RN.
       DEF *+4
       DEF DEALL    (global, no wait, no abort) 
RNADR  ABS *-*
       DEF ERROR
      JMP E137      erroneous call (?)
* 
      LDA ERROR     Was deallocate successful?
      SZA 
      JMP E137      No - illegal RN usage somewhere 
* 
ERASE CCA           Erase entry by setting its first
      STA SAVE,I      word to a -1
      JMP OKAY        (signifies empty entry).
* 
FC3C  LDB SAVE      Program's name did not appear 
      ADB OP/CT 
      LDA B,I         in name slots of entry. 
      INA 
      STA B,I       Restore user count
      JMP E103        and return error # 103. 
* 
*  Function code = -1 
*  Put a copy of co-ordinating table in SAM and pass it to RECOV. 
* 
FCM1  CLA,CCE       Set the class # to zero, bit 15 set 
      ERA             to tell EXEC to allocate one. 
      STA RN/CL 
* 
      JSB EXEC
       DEF *+8
       DEF CLWRT    Class write/read--no wait, no abort 
       DEF D0 
       DEF COTAB,I  Co-ordinating table address 
       DEF TASIZ      and its size
       DEF D0        dummy
       DEF D0          parameters 
       DEF RN/CL
      JMP E162
* 
      SZA           Was write successful? 
      JMP E162      No--let RECOV know. 
* 
OKAY  CLA           Here on successful operation. 
EXIT  STA ERROR 
* 
      JSB PRTN      Return parameters to father.
       DEF *+2
       DEF ERROR
* 
      JSB EXEC      Terminate, save resources.
       DEF *+4
       DEF D6 
       DEF D0 
       DEF D1 
* 
      JMP BEGIN     Next schedule begins here.
* 
*  Error return points. 
* 
E103  LDA D103      Data base not opened properly 
      JMP EXIT        no entry in table on close. 
E129  LDA D129      Data base already opened exclusively. 
      JMP EXIT
E131  LDA D131      No room in co-ordinating table
      JMP EXIT        to add entry. 
E132  LDA D132      No RN available 
      JMP EXIT
E137  LDB SAVE      If an RN error on a remove, 
      ADB OP/CT       increment the user count
      CLA,INA         back to one.
      ADA B,I 
      STA B,I 
      LDA PNAME,I   And restore first word
      STA EMPTY,I     of program's name.
      LDA D137      Illegal RN usage. 
      JMP EXIT
E152  LDA D152      Data base already opened
      JMP EXIT        in a different mode 
E161  LDA D161     Illegal function code
      JMP EXIT
E162  LDA D162      Class write unsuccessful. 
      JMP EXIT
* 
*  Work areas, table, and constants.
* 
M7    DEC -7
M3    DEC -3
D0    DEC 0 
D1    DEC 1 
D2    DEC 2 
D3    DEC 3 
D6    DEC 6 
D103  DEC 103 
D129  DEC 129 
D131  DEC 131 
D132  DEC 132 
D137  DEC 137 
D152  DEC 152 
D161  DEC 161 
D162  DEC 162 
LOBYT OCT 377 
* 
COTAB DEF *+1       Co-ordinating table address 
      UNL 
      REP 540 
      DEC -1
      LST 
ENTSZ DEC 27        Size of entries in table
TASIZ DEC 540       Table size
DBCNT DEC -20       Negative # of entries in table
OP/CT DEC 4         Index to open mode/ user count
RNIDX DEC 5         Index to RN 
NAMES DEC 6         Index to start of program names in entry. 
MODE  NOP 
FCODE NOP 
* 
ERROR NOP 
RN/CL NOP 
USCNT EQU RN/CL 
* 
NAMAD DEF DBNAM 
COUNT NOP 
FOUND DEC -1
SAVE  NOP 
EMPTY NOP 
DUMMY EQU EMPTY 
PNAME DEF *+1 
      BSS 3 
* 
ALLOC OCT 140020
DEALL OCT 140040
CLWRT OCT 100024
NA14  OCT 100016
      END BEGIN 
* 
              