.TITLE DIRIO - DIR I/O Routines .IDENT /1.0/ .ENABL LC ;+ ; ; Free software BY ; Project Software & Development, Inc. ; ; This software is furnished for free and may be used and copied as ; desired. This software or any other copies thereof may be provided or ; otherwise made available to any other person. No title to and ; ownership of the software is hereby transferred or allowed. ; ; The information in this software is subject to change without notice ; and should not be construed as a commitment by PROJECT SOFTWARE ; AND DEVELOPMENT, INC. ; ; PROJECT SOFTWARE assumes no responsibility for the use or reliability ; of this software on any equipment whatsoever. ; ; Project Software & Development, Inc. ; 14 Story St. ; Cambridge, Ma. 02138 ; 617-661-1444 ; ; ; Title: DIRIO.MAC ; Author: Robin Miller ; Date: February 19, 1985 ; ; Description: ; ; This module contains the routines for the terminal I/O. ; ; Modification History: ; ;- .ENABL AMA .NLIST BEX .MCALL QIO$S, QIOW$S, PUT$, WTSE$S .SBTTL WRITE - Write a message to the terminal. ;+ ; ; WRITE - Write a message to the terminal. ; ; This routine is used to write a message terminated by null to the ; terminal. It also makes sure that writes do not exceed 512 bytes ; in length. This is done becuase one of the VMS sysgen parameters ; prevents us from writing the entire message all at once. RSX-11M ; allows us to write up to 8128 bytes in length with one QIO. ; ; Inputs: ; R4 = Message address terminated by NULL. ; ; Outputs: ; All registers are preserved. ; ;- WRITE:: CALL $SAVAL ; Save all registers. MOV R4,R0 ; Copy the buffer address. CALL GETLEN ; Calculate the length --> R1. MOV #8128.,R3 ; Setup the maximum write size. TST VAXFLG ; Are we running on VAX/VMS ? BEQ 10$ ; If EQ, no (presume RSX-11M). MOV #512.,R3 ; Else, set smaller write size. 10$: CLR R2 ; Presume a single write. CMP R1,R3 ; Is the length too large ? BLE 20$ ; If LE, no (write it). ; The length is too big, adjust into 512 bytes length. MOV R1,R2 ; Save the message length. MOV R3,R1 ; Set the maximum message length. 20$: CALL WRITIT ; Write the message. BCS 100$ ; If CS, we had an error. TST R2 ; Is there any more to write ? BEQ 100$ ; If EQ, no (we're all done). ; Adjust the buffer address and the message length. ADD R1,R0 ; Yes, adjust the buffer address SUB R1,R2 ; and the message length. MOV R2,R1 ; Set the new message length. BR 10$ ; And continue ... 100$: RETURN .SBTTL WRITIT - Write a message to the terminal. ;+ ; ; WRITIT - Write a message to the terminal. ; ; All messages written to the terminal come through this routine. ; ; Inputs: ; R0 = The buffer address. ; R1 = The buffer byte count. ; ; Outputs: ; Carry clear/set = success/failure. ; ; All registers are preserved. ; ;- WRITIT::BIT #B.OFIL,STATUS ; Outputting to a disk file ? BEQ 10$ ; If EQ, no (to the terminal). TST OUTFDB+F.BDB ; Is the output file open ? BNE WRTFIL ; If NE, yes (write to file). 10$: CALL $SAVAL ; Save all registers. ; ; If we're in the startup code, we used normal single spacing ; and wait for the I/O to complete. Otherwise, we queue up the ; I/O so we can go format the next directory entry (if any). ; BIT #B.STUP,STATUS ; Are we in the startup code ? BEQ 20$ ; If EQ, no. QIOW$S #IO.WLB,#TOLUN,#TOEFN,,#TIOSB,, CALL CHKERR ; Check/report any errors. BR 100$ ; And use common return ... 20$: MOV #IO.WLB,R3 ; Set normal write function. BIT #B.CTRO,STATUS ; Did user typed CTRL/O ? BEQ 30$ ; If EQ, no. BIS #TF.CCO,R3 ; Yes, cancel the CTRL/O state. BIC #B.CTRO,STATUS ; Reset the CTRL/O status bit. 30$: CALL WAITIO ; Wait for previous I/O (if any). CALL CCTRLO ; Get the CTRL/O status. QIO$S R3,#TOLUN,#TOEFN,,#TIOSB,, CALL CHKDIR ; Check for directive errors. BCS 100$ ; If CS, we had an error. INC TIOCNT ; Else, show I/O outstanding. 100$: RETURN .SBTTL WRTFIL - Write a buffer to the output file. ;+ ; ; WRTFIL - Write a buffer to the output file. ; ; This routine is used to write the specified buffer to the output file. ; Each record is broken at the which we presume is in the buffer. ; ; Inputs: ; R0 = The buffer address. ; R1 = The buffer byte count. ; ; Outputs: ; C bit clear/set = success/failure. ; ; All registers are preserved. ; ;- WRTFIL::CALL $SAVAL ; Save all registers. MOV OENTRY,R5 ; Set address of output entry. MOV R0,R2 ; Copy the output buffer address. MOV R2,R3 ; Save buffer address here also. MOV O.FDB(R5),R0 ; Set output file FDB address. 10$: TST R1 ; Any byte count remaining ? BLE 100$ ; If LE, no (we're finished). CMPB (R3)+,#CR ; Search for a carriage return. BEQ 20$ ; If EQ, we found one. SOB R1,10$ ; Check the next character. ; If no carriage return found, write whatever is in the buffer. MOV R3,R4 ; Copy the ending buffer address. BR 30$ ; And do the write ... 20$: MOV R3,R4 ; Copy ending buffer address. DEC R4 ; Adjust for the carriage return. 30$: SUB R2,R4 ; Calculate the byte count. PUT$ R0,R2,R4 ; Write it to the output file. BCS 90$ ; If CS, don't write any more. INC R3 ; Point past the line feed. MOV R3,R2 ; Save the starting address. SUB #2,R1 ; Adjust the buffer byte count. BR 10$ ; And look for another end of line. 90$: CALL FILERR ; Report the file error. CALL CLOFIL ; Close the output file. BIC #B.OFIL,STATUS ; Show no output file is open. SEC ; Show we had an I/O error. 100$: RETURN .SBTTL WAITIO - Wait for terminal I/O to complete. ;+ ; ; WAITIO - Wait for the terminal I/O to complete. ; ; This routine is used to wait for the terminal I/O previous queued up. ; ; Inputs: ; None ; ; Outputs: ; All registers are preserved. ; ;- WAITIO::JSR R2,$SAVVR ; Save R0 - R2. BIT #B.OFIL,STATUS ; Writing to an output file ? BNE 100$ ; If NE, yes. TST TIOCNT ; Terminal I/O outstanding ? BEQ 100$ ; If EQ, no. WTSE$S #TOEFN ; Yes, wait for terminal I/O. DEC TIOCNT ; Adjust the I/O counter. 100$: RETURN .END