.TITLE VTLWRT - Output File Routines .IDENT /1.1/ .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: VTLWRT.MAC ; Author: Robin Miller ; Date: July 26, 1983 ; ; Description: ; ; These routines are used for the "WRITE" commands. ; ; Modification History: ; ; June 2, 1984 by Robin Miller. Edit (01). ; Use common routine to Get/Mark the next input record. ; ;- .ENABL AMA .NLIST BEX .MCALL PUT$ ; Local messages: OFILEM: .ASCIZ "Output file: " CLOSEM: .ASCIZ "Closing output file " TOTALM: .ASCIZ ", total records = " RECRDM: .ASCIZ "Records " THRUM: .ASCIZ " thru " WRITNM: .ASCIZ " written." .EVEN ; Local storage: BRANGE: .BLKW 2 ; Beginning of range. ERANGE: .BLKW 2 ; End of range. TOTREC: .BLKW 2 ; Total records written. .SBTTL RESCMD - Reset the select command. ;+ ; ; RESCMD - Reset the select command. ; ; This routine is used to reset the effects of the select command. It ; resets the select status bit and redisplays the screen so the reverse ; video (select) is removed. ; ; Inputs: ; None. ; ; Outputs: ; All registers except R2 are preserved. ; ;- RESCMD::MOV IENTRY,R2 ; Copy the file entry address. BIT #S.SEL,(R2) ; Is the select range active ? BEQ 100$ ; If EQ, no (nothing to do). BIC #S.SEL,(R2) ; Clear the select status bit. JMP REPAGE ; Now redisplay the page. 100$: BIS #B.DOPR,STATUS ; Show we should reprompt user. RETURN .SBTTL SELCMD - Enable the select range. ;+ ; ; SELCMD - Enable the select command. ; ; This routine is used to enable the select range for the write command. ; The select status bit is set and the page is redisplayed so the select ; records are displayed in reverse video. ; ; Inputs: ; None. ; ; Outputs: ; All registers except R2 are preserved. ; ;- SELCMD::MOV IENTRY,R2 ; Copy the file entry address. BIT #S.SEL,(R2) ; Is the select already active ? BNE 90$ ; If NE, yes (tell the user). MOV O.TOPR(R2),O.SELR(R2) ; Now copy the top of MOV O.TOPR+2(R2),O.SELR+2(R2) ; page record number. BIS #S.SEL,(R2) ; Show the select is active. JMP REPAGE ; Now redisplay the page. 90$: ERRMSG SELACT, JMP FAIL ; Return failure to .TPARS. ;****************************************************************************** ; Action routine for the "WRITE WHOLE" command. WWHOLE::CALL WBEGIN ; Setup starting record number. CALL WEND ; Setup the ending record number. RETURN ;****************************************************************************** ; Action routines to setup range for "BEGIN" and "END" commands. WBEGIN::CLR BRANGE ; Setup the starting MOV #1,BRANGE+2 ; range record number. RETURN WEND:: MOV #-1,ERANGE ; Setup the ending MOV #-1,ERANGE+2 ; range record number. RETURN ;****************************************************************************** ; Action routines to setup range when record numbers specified. WBRANG::MOV .PNUMH,BRANGE ; Copy the starting MOV .PNUMB,BRANGE+2 ; range record number. RETURN WERANG::MOV .PNUMH,ERANGE ; Copy the ending MOV .PNUMB,ERANGE+2 ; range record number. RETURN ;****************************************************************************** ; Action routines to setup range for the "BPAGE" command. WBBPAG::MOV IENTRY,R2 ; Copy the file entry address. MOV O.TOPR(R2),BRANGE ; Copy the starting MOV O.TOPR+2(R2),BRANGE+2 ; range record number. RETURN WEBPAG::MOV IENTRY,R2 ; Copy the file entry address. MOV O.TOPR(R2),ERANGE ; Copy the ending MOV O.TOPR+2(R2),ERANGE+2 ; range record number. RETURN ;****************************************************************************** ; Action routines to setup range for the "EPAGE" command. WBEPAG::MOV IENTRY,R2 ; Copy the file entry address. MOV O.CREC(R2),BRANGE ; Copy the starting MOV O.CREC+2(R2),BRANGE+2 ; range record number. RETURN WEEPAG::MOV IENTRY,R2 ; Copy the file entry address. MOV O.CREC(R2),ERANGE ; Copy the ending MOV O.CREC+2(R2),ERANGE+2 ; range record number. RETURN .SBTTL WCHECK - Check for an output file. ;+ ; ; WCHECK - Check for an output file. ; ; This routine is used to open an output file if one is not already open. ; If the user specified a file name at startup time via the /OUTPUT switch, ; then that file is opened, otherwise the user is prompted for a file name. ; ; Inputs: ; None: ; ; Outputs: ; R0 = The output file FDB address. ; R3 = The input file FDB address. ; R4 = The input file entry address. ; R5 = The output file entry address. ; ; C bit clear/set = success/failure. ; ;- WCHECK::CALL WRTINI ; Do the initial processing. BCC 100$ ; If CC, a file is already open. BIT #B.OFIL,STATUS ; Was an output file specified ? BNE 10$ ; If NE, yes (try to open it). ; Prompt the user for a file name. MOV #OFILEM,R1 ; Set address of the message. CALL WRTPRL ; Write it to the prompt line. MOV O.FNAM(R5),R0 ; Set the input buffer address. MOV #FILSIZ,R1 ; And the size of the buffer. CALL GETCMD ; Now read the users response. BCS 100$ ; If CS, time to exit or error. TST R1 ; Did the user input anything ? BEQ 90$ ; If EQ, no (nothing to open). ; Prepare the output FDB and open it for write. 10$: CLR TOTREC ; Initialize the total CLR TOTREC+2 ; number of records. MOV O.FDB(R5),R0 ; Copy the FDB address. MOV O.FNAM(R5),R1 ; Copy the file name address. ; Copy the file attributes from the input file. MOVB F.RATT(R3),F.RATT(R0) ; Copy the file attributes. MOVB F.RTYP(R3),F.RTYP(R0) ; Copy the record attributes. CALL OPENW ; Open the file for write. BCC 100$ ; If CC, we're ready to go. ; Report the open file error. CALL MAKNAM ; Make the ASCII file name. CALL FILERR ; Else, report the error. BIC #B.OFIL,STATUS ; Don't try to open this one again. 90$: SEC ; Show the file wasn't opened. 100$: RETURN .SBTTL WRTINI - Do initial write processing. ;+ ; ; WRTINI - Do initial write processing. ; ; This routine simply sets up some registers an passes back a status ; as to whether an output file is already open. ; ; Inputs: ; None. ; ; Outputs: ; R0 = The output FDB address. ; R3 = The input FDB address. ; R4 = The input file entry address. ; R5 = The output file entry address. ; ; C bit clear/set = file open/not open. ; ;- WRTINI::MOV IENTRY,R4 ; Copy the input file address. MOV O.FDB(R4),R3 ; Copy the input FDB address. MOV OENTRY,R5 ; Copy the file entry address. MOV O.FDB(R5),R0 ; Copy the output FDB address. TST F.BDB(R0) ; Is an output file already open ? BNE 100$ ; If NE, yes (return C bit clear). SEC ; Show no output file is open. 100$: RETURN .SBTTL CRANGE - Check the range to write. ;+ ; ; CRANGE - Check the range to write. ; ; This routine checks the range specified by the user to ensure the range ; is valid. The starting range must be less than or equal to the ending ; range to be valid. ; ; Implicit inputs: ; BRANGE = The beginning range record number. ; ERANGE = The ending range record number. ; ; Implicit outputs: ; All registers are preserved. ; ;- .ENABL LSB CRANGE: JSR R2,$SAVVR ; Save R0 - R2. CMP BRANGE,ERANGE ; Starting range < ending range ? BLO 10$ ; If LO, yes. CMP BRANGE+2,ERANGE+2 ; Starting range really valid ? BLOS 10$ ; If LOS, yes. ERRMSG BADRAN, SEC ; Show invalid range specified. RETURN 10$: CLC ; Show valid range speicifed. RETURN .DSABL LSB .SBTTL WRANGE - Write range to output file. ;+ ; ; WRANGE - Write range to the output file. ; ; Implicit inputs: ; BRANGE and ERANGE are setup with the record numbers. ; ; Outputs: ; Registers R3 - R5 are preserved. ; ;- WRANGE::JSR R5,$SAVRG ; Save R3 - R5. CALL CRANGE ; Check the range to write. BCS 110$ ; If CS, bad range specified. CALL WCHECK ; Check for & open an output file. BCS 110$ ; If CS, no file was opened. CALL MRKSAV ; Save the record position. MOV BRANGE,WTGREC ; Copy the beginning MOV BRANGE+2,WTGREC+2 ; record number. CALL POINTR ; Point to the record number. BCS 100$ ; If CS, error or end of file. MOV BRANGE,R1 ; Copy the beginning MOV BRANGE+2,R2 ; range record number. 10$: TST STATUS ; Was CTRL/C typed to abort ? BMI 100$ ; If MI, yes (stop writing). CALL GETM ; Get/Mark the next record. (01) BCS 20$ ; If CS, error or end of file. CMPB #R.SEQ,F.RTYP(R3) ; Input file have sequence records ? BNE 15$ ; If NE, no. MOV F.SEQN(R3),F.SEQN(R0) ; Yes, copy the sequence number. 15$: PUT$ R0,F.NRBD+2(R3),F.NRBD(R3) ; Write this record. BCS 90$ ; If CS, we had an error. ADD #1,TOTREC+2 ; Accumulate the ADC TOTREC ; total record count. ADD #1,R2 ; Adjust the starting ADC R1 ; range record number. CMP R1,ERANGE ; Are we finished with the range ? BHI 20$ ; If HI, yes. CMP R2,ERANGE+2 ; Are we really finished ? BLOS 10$ ; If LO, no (write next record). ; Write the range of records written to the terminal. 20$: MOV #FMTBUF,R0 ; Set the output buffer address. CALL SETMSG ; Setup to write to message line. MOV #RECRDM,R1 ; Set address of "Records " message. CALL MOVEC ; Copy it to the output buffer. MOV #BRANGE,R1 ; Set address of beginning range. CALL CVTDTD ; Convert it to decimal ASCII. MOV #THRUM,R1 ; Set address of " thru " message. CALL MOVEC ; Copy it to the output buffer. MOV #ERANGE,R1 ; Set address of ending range. BIT #S.EOF,(R4) ; Did we run into end of file ? BEQ 30$ ; If EQ, no (continue ...). MOV O.CREC(R4),(R1) ; Else, copy the end of MOV O.CREC+2(R4),2(R1) ; file record number. 30$: CALL CVTDTD ; Convert it to decimal ASCII. MOV #WRITNM,R1 ; Set address of " written." message. CALL MOVEC ; Copy it to the output buffer. CALL TYPMSG ; Write the message to the terminal. BR 100$ ; Reposition file and return ... 90$: CALL FCSERR ; Report the error message. 100$: CALL PNTSAV ; Point to saved record position. 110$: RETURN .END