
/SEARCH SUBROUTINE
/ENTER WITH  AC= FILE NAME POINTER
/RETURN      AC= -1, FILE NOT FOUND
/            AC= BIT POSITION IN DIRECTORY MAP
/            LOC SEARCH = FIRST BLOCK# IF FILE FOUND
/            LOC SEARCH = 0 IF FILE NOT FOUND
/EXTERNALS:  MAPAD, FILE0
SEARCH 0
       TAD (-1
       DAC 16      /SET UP FILE NAME POINTER
       LAC* 16     /SAVE FILE NAME
       DAC SNAM1
       LAC* 16
       DAC SNAM2
       LAC* 16
       DAC SNAM3
       LAC SEARCH
       DAC SRCH6   /SAVE RETURN ADDRESS
       JMS MAPIN   /GET MAPS
       LAC MAPAD
       TAD (77     /POINT TO LOC BEFORE DIR. MAP
       DAC 16      /SET UP DIR. MAP POINTER
       LAC (1756   /INITIALIZE DIR.BLOCK POINTER
       DAC SDYBLK
       LAW -20
       DAC SRCNT1  /WORD COUNTER
SRCH4  LAC* 16     /GET MAP WORD
       SNA
       JMP SRCH5   /ALL ZERO
       LAC SDYBLK  /ACTIVE DIR.BLOCK
       JMS DRIN
       FILE0
       LAC .-1
       TAD (-1
       DAC SRCH0   /SET UP DIR.BLCK POINTER
       DAC 17
       LAW -20
       DAC SRCNT2  /BLOCK ENTRY COUNTER
SRCH3  LAC* 17     /GET ENTRY WORD0
       DAC SEARCH    /COULD BE BLOCK POINTER
       SMA
       JMP SRCH1   /ENTRY INACTIVE
       LAC* 17    /GET FIRST NAME WORD
       SAD SNAM1
       SKP         /EQUAL
       JMP SRCH1
       LAC* 17
       SAD SNAM2
       SKP
       JMP SRCH1
       LAC* 17
       SAD SNAM3
       JMP SRCH2   /FILE FOUND
SRCH1  LAC SRCH0   /NOT THIS ENTRY
       TAD (20
       DAC SRCH0   /UPDATE POINTERS
       DAC 17
       ISZ SRCNT2
       JMP SRCH3   /NOT END OF BLOCK
SRCH5  ISZ SDYBLK  /NEXT BLOCK
       ISZ SRCNT1
       JMP SRCH4   /NOT END OF MAP
       DZM SEARCH
       CLA!CMA     /END OF MAP
       JMP* SRCH6
SRCH2  LAC SEARCH   /FILE FOUND
       AND (1777
       DAC SEARCH
       LAC SRCNT2
       TAD (20
       AND (17
       DAC SRCH0   /TEMPORARY SAVE
       LAC SRCNT1
       TAD (20
       AND (17
       SWHA
       TAD SRCH0
       JMP* SRCH6    /RETURN
SNAM1  0
SNAM2  0
SNAM3  0
SRCH0  0
SRCH6  0
SRCNT1  0
SRCNT2  0
SDYBLK  0
/DELETE FILE SUBROUTINE
/SEARCH MUST BE CALLED BEFORE USING DELETE
/ENTER  WITH AC = BIT POSITION IN DIR.MAP
/EXTERNALS: FILE0
DELETE 0
       DAC DELT0   /SAVE MAP POSITION
       JMS ZDYBT   /DELETE DIR.MAP BIT
       LAC DELT0   /GET DIR.BLOCK
       SWHA
       AND (17
       TAD (1756
       DAC DELT1   /SAVE BLOCK #
       JMS DRIN
       FILE0
       LAC DELT0   /GET BIT POINTER
       AND (17
       CLL!RTL     /MULTIPLY BY 16
       RTL
       TAD .-5     /ADD FILE0
       DAC DELT0   /SAVE POINTER TO FILE ENTRY
       LAC* DELT0
       AND (1777
       DAC DELT2   /SAVE BLOCK POINTER
       DZM* DELT0  /ZERO ENT.WORD0
       LAC DELT1
       JMS DROUT
       FILE0       /RESTORE DIR.BLOCK
DELT3  LAC DELT2   /SAVE BLOCK POINTER
       JMS ZFLBT   /DELETE MAP BIT
       LAC DELT2   /GET THAT BLOCK
       JMS DRIN
       FILE0
       LAC .-1
       TAD (2
       DAC DELT2   /SAVE ADDRESS OF WORD2
       LAC* DELT2   /GET POINTER TO NEXT BLOCK
      DAC DELT2
       SZA
       JMP DELT3
       JMS MAPOUT     /RESTORE MAP
       JMP* DELETE   /RETURN
DELT0  0
DELT1  0
DELT2  0
/CREATE FILE SUBROUTINE
/SEARCH AND DELETE MUST BE CALLED FIRST
/ENTER WITH  AC = POINTER TO FILE NAME
/RETURN WITH AC = BLOCK #
/            AC = 0 , NO FREE BLOCKS
/            AC = -1, NO FREE DIR. ENTRIES
/EXTERNALS:  MAPAD,FILE0,LOC16,LOC17
CREATE 0
       DAC CREAT0   /SAVE NAME POINTER
       JMS FRENT    /GET A FREE DIR.ENTRY
       SPA
       JMP* CREATE  /NO FREE DIR.ENTRY
       DAC CREAT1   /SAVE DIR.MAP BIT POSITION
       JMS FRBLK    /GET A FREE BLOCK
       SNA
       JMP* CREATE  /NO FREE BLOCKS
       DAC CREAT2   /SAVE FILE BLOCK#
       LAC CREAT1   /SET DIR.ENT BIT
       JMS SDYBT
       LAC CREAT1   /GET DIR.BLOCK
       SWHA
       AND (17
       TAD (1756
       DAC CREAT3   /SAVE DIR.BLOCK#
       JMS DRIN
       FILE0
       LAC CREAT1   /GET BIT POSITION
       AND (17
       CLL!RTL      /MULTIPLY BY 16
       RTL
       TAD .-5      /ADD FILE0
       TAD (-1      /POINT TO LOC BEFORE
       DAC 17       /SET UP DIR. ENTRY POINTER
       LAC CREAT0
       TAD (-1
       DAC 16       /SET UP FILE NAME POINTER
       LAC CREAT2   /GET FILE BLOCK#
       TAD (600000  /SET AND OPEN FILE
       DAC* 17      /WRITE IN DIR.
       LAC* 16      /TRANSFER FILE NAME
       DAC* 17
       LAC* 16
       DAC* 17
       LAC* 16
       DAC* 17
       LAC CREAT3   /RESTORE DIR.BLOCK
       JMS DROUT
       FILE0
       LAC CREAT2   /GET FILE BLOCK#
       JMS SFLBT    /SET MAP BIT
       LAC CREAT2   /GET BLOCK
       JMS DRIN
       FILE0
       LAC .-1
       TAD (-1     /POINT TO LOC BEFORE FILE0
       DAC 16      /SET UP FILE POINTER
       DZM* 16      /ZERO FIRST 4 WORDS
       DZM* 16
       DZM* 16
       DZM* 16
       LAC CREAT2   /RESTORE FILE BLOCK
       JMS DROUT
       FILE0
       JMS MAPOUT  /RESTORE MAP
       LAC CREAT2   /RETURN WITH FILE BLOCK#
       JMP* CREATE
CREAT0 0
CREAT1 0
CREAT2 0
CREAT3 0
/FIND FREE ENTRY SUBROUTINE
/RETURN WITH AC = DIR.MAP BIT POSITION
/            AC = -1, DIRECTORY FULL
/EXTERNALS: MAPAD, LOC 16
FRENT  0
       LAC MAPAD
       TAD (77
       DAC 16       /SET UP MAP WORD POINTER
       LAW -20
       DAC FRENT1   /SET UP MAP WORD COUNTER
FRENT0 LAC* 16      /GET ONE MAP WORD
       CMA
       AND (777774  /NULL BITS 16,17
       SZA
       JMP .+5
       ISZ FRENT1
       JMP FRENT0   /TRY NEXT WORD
       CLA!CMA     /DIR. FULL
       JMP* FRENT
       DZM FRENT2  /SET UP BIT POINTER
       SPA
       JMP .+4     /BIT FOUND
       RAL
       ISZ FRENT2
       JMP .-4
       LAC FRENT1     /GET WORD POINTER
       TAD (20
       SWHA
       TAD FRENT2      /GET BIT POINTER
       JMP* FRENT
FRENT1 0
FRENT2 0
/MAP GET SUBROUTINE
/EXTERNALS: MAP, DRUM
MAPIN  0
       LAW 17400   /AC = 777400
       JMS DRUM
       -120        / -WC
       MAP-1       / CA-1
       JMP* MAPIN
   .END
