.TITLE GETFIL V03.00 11-Oct-86 ; Gets the next entry in the file directory ; for the device opened on channel CHAN ; Call GETFIL(IFLG) ; IFLG - Indicates the results: ; 0 - OK, file returned to common block /file/ ; 1 - End of directory, no more files ; -1 - Error of some kind. ; Common area, .PSECT FILE ; FILE Stores the name date, size of the ; file returned. ; The channel number in use and the ; current device block in memory. ; ; A total of the number of blocks used, ; the number of free blocks and the ; largest free block is maintained. ; The total is available when the ; end of the directory is reached. ; TUSED, TFREE and MFREE should be ; cleared by the calling program before ; the first call to GETFIL. ; BLKEY must be set to 0 by the calling ; program to ensure the start of the ; directory is read. ; File status masks PERM = 2000 EOFSEG = 4000 ; Author: ; D. N. Tanner ; Livermore, CA .GLOBL GETFIL .MCALL .READW GETFIL: TST (R5)+ CLR LCLMAX ;Clear local max free block total TST BLKEY ;Is a block in memory BGT GFIL ;Yes MOV #1,BLKEY ;Set up to read home block .READW #AREA, CHAN, #BUF, #1000, BLKEY BCC 1$ JMP ERROR 1$: CMP SYSID,#"DE ;Is this a RT directory? BNE 11$ MOV SEG1,BLKEY ;Now read the first segment .READW #AREA, CHAN, #BUF, #1000, BLKEY BCC 2$ 11$: JMP ERROR 2$: TST NSEG ;Test the number of segments, In range? BLT ERROR CMP NSEG,#31. BGT ERROR TST NXTSEG BLT ERROR CMP NXTSEG,#31. BGT ERROR MOV #FSTAT,FILPTR ;Pointer to next file MOV #16,R1 ADD XBYTE,R1 ;Number of bytes per file MOV R1,ENTSIZ ;Entry size GFIL: MOV FILPTR,R1 BIT #PERM,@R1 ;Is this a permanent file? BNE 2$ ;YES BIT #EOFSEG,@R1 ;Is this the end of the segment? BEQ IGNORE ;No, it must be an empty or tentative file. MOV NXTSEG,R1 ;Get the next segment number BEQ DONE ;No next segment, we are done. ASL R1 ;Times 2 ADD #4,R1 ;add offset to get the next block MOV R1,BLKEY ;Save it .READW #AREA, CHAN, #BUF, #1000, BLKEY BCC 1$ JMP ERROR 1$: MOV #FSTAT,FILPTR ;Pointer to next file TST NXTSEG BLT ERROR CMP NXTSEG,#31. BGT ERROR BR GFIL ;Get the file 2$: TST (R1)+ MOV (R1)+,NAME MOV (R1)+,NAME+2 MOV (R1)+,TYPE MOV (R1),SIZE ADD (R1),TUSED ;Update the block total MOV 4(R1),DATE ADD ENTSIZ,FILPTR CMP LCLMAX, MFREE ;Did we find a new free max. BLE 3$ ;No MOV LCLMAX, MFREE ;Store the new max free block count 3$: CLR @(R5)+ ;IFLG=0, GOOD RETURN RTS PC IGNORE: MOV FILPTR, R4 ;Save the file pointer ADD 10(R4), TFREE ;Add the free section to the total ADD 10(R4), LCLMAX ;Add the size to the max area. ADD ENTSIZ,FILPTR ;NEXT FILE BR GFIL DONE: CMP LCLMAX, MFREE ;Did we find a new max free area BLE 1$ ;No MOV LCLMAX, MFREE ;Save the new maximum 1$: MOV #1,@(R5)+ ;IFLG=1, no more files. RTS PC ;RETURN ERROR: MOV #-1,@(R5)+ ;IFLG=-1, ERROR RTS PC LCLMAX: .WORD 0 FILPTR: .WORD 0 ENTSIZ: .WORD 0 AREA: .BLKW 5 ; BUF - Space for 2 disk blocks for directory segment BUF: NSEG: .BLKW ;Number of segments NXTSEG: .BLKW ;NEXT SEGMENT MAXSEG: .BLKW ;HIGHEST SEGMENT USED. XBYTE: .BLKW ;NUMBER OF EXTRA BYTES IN DIRECTORY SBLOCK: .BLKW ;STARTING BLOCK FOR THE FILES FSTAT: .BLKW 229. ;file directory area SEG1: .BLKW 1. ;First segment (in home block) .BLKW 13. SYSID: .BLKW 1. ;Used to check home block .BLKW 263. ;Rest of directory segments ; COMMON /FILE/ .PSECT FILE,GBL,OVR,D NAME: .BLKW 2 TYPE: .BLKW 1 DATE: .BLKW 1 SIZE: .BLKW 1 CHAN: .BLKW 1 ; BLKEY - Directory block in memory, 0 means no block. BLKEY: .BLKW 1 TUSED: .BLKW 1 ;Total number of blocks used. TFREE: .BLKW 1 ;Total free blocks in the directory MFREE: .BLKW 1 ;Largest free area in the directory .END