.MCALL .MODULE .MODULE WRREC,VERSION=05,COMMENT= ; Copyright (c) 1998 by Mentec, Inc., Nashua, NH. ; All rights reserved ; ; This software is furnished under a license for use only on a ; single computer system and may be copied only with the ; inclusion of the above copyright notice. This software, or ; any other copies thereof, may not be provided or otherwise ; made available to any other person except for use on such ; system and to one who agrees to these license terms. Title ; to and ownership of the software shall at all times remain ; in Mentec, Inc. ; ; The information in this document is subject to change without ; notice and should not be construed as a commitment by Digital ; Equipment Corporation, or Mentec, Inc. ; ; Digital and Mentec assume no responsibility for the use or ; reliability of its software on equipment which is not supplied ; by Digital or Mentec, and listed in the Software Product ; Description. .ENABL GBL,LC .SBTTL Macros definitions ;+ ;External macro library calls. ;- .MCALL FDBDF$, FERDF$, DEFIN$ FDBDF$ ;Define FDB offsets FERDF$ ;Define file service error codes DEFIN$ ;Definitions for IND files .PSECT $WRREC .SBTTL $WRREC - write record ;+ ;$WRREC ;This routine writes the specified record to the file indicated by the ;specified FDB. ; ; Input: R1 - address of FDB ; R2 - address of record ; R3 - length of record ; ; Output: FDB updated ; all registers preserved ; C-bit set if error ;- .ENABL LSB $WRREC::SAVE CALL $CKOPW ;Is the file opened for write? BCS 8$ ;No CALL ISFLST ;Is device file structured? BNE 1$ ;Branch if some kind of file structure MOV R2,R4 ;Set up buffer address MOV R3,R5 ;Set up byte count CALL $WRBLK ;Write the block BCS 8$ ;Branch if error BR 7$ ;Indicate success and return ;+ ;If random access. ;- 1$: MOV $OOWNR,R4 ;Is the output blocking buffer in use? BEQ 2$ ;No CMP R1,R4 ;Yes, does it belong to this FDB? BEQ 3$ ;Yes, just move data to buffer ;+ ;If not the current FDB, the contents of the buffer must be written out to ;the file before moving in new data for the new FDB. ;- SAVE R1 ;Save current FDB address MOV R4,R1 ;Get the FBD address that corresponds ;to the data in the buffer CALL $WRLST ;Write buffer to next block in file RESTOR R1 ;Restore current FDB address BCS 8$ ;Branch out if error ;+ ;At this point the contents has been written out to the original file. Now ;the current data should be moved into the buffer. If is the first data for ;the file, just store it in the buffer. If data has been previously been ;written to the file that data must be read into the buffer before moving ;the new data into the buffer. ;- 2$: MOV F$BLKN(R1),R4 ;Get current block number CMP #<-1>,R4 ;Has data been written to file yet? BEQ 3$ ;No, don't attempt to read it ;+ ;Read data from file into buffer. ;- MOV R4,R3 ;R3 = current block number MOV #$OUPBF,R4 ;Set up buffer address MOV #<$OUPND-$OUPBF>,R5 ;Get byte count CALL $RDBLK ;Read current block back into buffer BCS 8$ ;Branch out if error MOV @SP,R3 ;Restore the record length DEC F$BLKN(R1) ;Decrement current block number ;+ ;Common code to read new data line into the buffer. ;- 3$: MOV R1,$OOWNR ;Save current FDB address as owner 4$: MOV #$OUPND,R5 ;Point to end of blocking buffer MOV F$BUFP(R1),R4 ;Get the current buffer pointer BNE 5$ ;Branch around if not start of buffer MOV #$OUPBF,R4 ;Point to start output buffer 5$: CMP R4,R5 ;Is the buffer full? BLO 6$ ;No, move character into buffer SAVE CALL WRITE ;Write-out block MOV R4,F$BUFP(R1) ;Update buffer pointer RESTOR BCS 8$ ;Branch out if error BR 4$ ;Store rest of recond ;+ ;Move character into buffer. ;- 6$: MOVB (R2)+,(R4)+ ;Move another character into buffer DEC R3 ;Have all characters been moved in? BGT 5$ ;No, get next ;+ ;Common exit routine. ;- 7$: MOV R4,F$BUFP(R1) ;Save buffer pointer MOV #,F$ERR(R1) ;Indicate success CLC ;Make sure C-bit clear for no error 8$: RESTOR RETURN .DSABL LSB .SBTTL $WRLST - write last block to file ;+ ;$WRLST ;This routine zero fills the rest of the buffer then writes the block to the ;next logical block of the specified file. ; ; Input: R1 -> address of FDB ; ; Output: R1 -> address of FDB ; C-bit set if error ;- .ENABL LSB $WRLST::SAVE MOV F$BUFP(R1),R4 ;Get buffer pointer MOV #$OUPND,R5 ;Get end of buffer address 1$: CMP R4,R5 ;End of buffer found? BHIS 2$ ;Yes, write it to file CLRB (R4)+ ;Zero next location in buffer BR 1$ ;See if any more 2$: CALL WRITE ;Write the block to file 3$: RESTOR RETURN .DSABL LSB .SBTTL WRITE - subroutine to write buffer ot file ;+ ;WRITE ;The following subroutine writes the current contents of the buffer ($OUPBF) ;to the specified file. ;- .ENABL LSB WRITE: SAVE R3 MOV F$BLKN(R1),R3 ;Set up block number MOV #$OUPBF,R4 ;Set up buffer address MOV #<$OUPND-$OUPBF>,R5 ;Set up byte count INC R3 ;Update lbock number CALL $WRBLK ;Write the last block RESTOR R3 RETURN .DSABL LSB .END