.TITLE GETSTR .IDENT /V3.01/ .NLIST TOC,SYM .ENABL LC ;+ ; Sira Ltd., South Hill, Chislehurst, Kent, BR7 5EH, England ; ; Author: C J Doran, Date 25-Jan-83 ; ; Read a string from FORTRAN using direct call to FCS routine .GETSQ . ; Reduces the time and code overhead of doing FORTRAN formatted I/O just ; to read a series of bytes. ; ; SUBROUTINE GETSTR(LUN,STRING,LEN{,ERR}) ; ; LUN is unit number of channel to which output must be sent. ; STRING is the name of a BYTE array to receive the line read, terminated ; with a null byte. ; LEN the maximum number of bytes which can be returned (excluding ; terminating null). ; ERR If given, is a BYTE variable returned as:- ; 0 If no errors occur, ; -1 If end-of-file is reached, ; -2 If any other hardware error is detected. ; -3 If the number of bytes read exceeds LEN. ; ; This subroutine is compatible with that in the RT-11 Syslib library. ; Note that ERR is optional, as in RT-11 V2, but seems to be mandatory in V3. ; ; Assemble as: ; >MAC GETSTR=GETSTR ;- D.FDB=12. ; Start of FCS FDB in LUB ; Use the following two lines for F4P ;FL.FMP=1000 ; Formatted records ;FL.RD=200 ; Read with implied OPEN ; Use the following two for F77 FL.FMP=200 ; Formatted records FL.RD=40 ; Read with implied OPEN .PSECT $CODE1,I,RW,LCL,CON GETSTR::MOV #FL.RD!FL.FMP,%1 ; Read formatted with default OPEN JSR PC,$PGINI ; Perform common initialisation CLRB @%2 ; Null STRING in case of failure CLR -(SP) ; Assume success MOV @(%5)+,%4 ; Get LEN JSR PC,.GETSQ ; Get a record BCC 10$ ; Continue if OK DEC @SP ; Failed. Assume e-o-f CMPB F.ERR(%0),#IE.EOF ; Is it end-of-file? BNE 5$ ; No, branch TRAP 128.+24. ; Yes, report it BR 40$ ; and return error code 5$: DEC @SP ; All other errors return ERR=-2 CMPB F.ERR(%0),#IE.RBG ; Record too long? BNE 6$ ; No, give general error TRAP 128.+22. ; Yes, report specially BR 40$ ; and return 6$: TRAP 128.+39. ; Some other input error BR 40$ ; Return 10$: MOV F.NRBD(%0),-(SP) ; Get byte count MOV F.NRBD+2(%0),%1 ; and buffer address 20$: DEC @SP ; Dec byte count BMI 30$ ; Exit when all copied MOVB (%1)+,(%2)+ ; Else copy SOB %4,20$ ; until done or LEN MOV #-3,2(SP) ; If LEN reached first, return -3 30$: CLRB @%2 ; End STRING with null TST (SP)+ ; Purge counter 40$: JMP $PGXIT ; and exit via common code .END