.TITLE VTLUTL - VTL Utility Routines .IDENT /1.3/ .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: VTLUTL.MAC ; Author: Robin Miller ; Date: June 30, 1983 ; ; Description: ; ; This module contains the utility routines for the VTL program. ; ; Modification History: ; ; June 13, 1984 by Robin Miller. Version 1.3 ; Added error code IE.BTP (bad record type) to the non-fatal ; error code table to allow lookup of next file is wildcards. ; ; June 6, 1984 by Robin Miller. Version 1.2 ; Rewrite the DELAY routine to make it more effecient. ; ;- .ENABL AMA .NLIST BEX .MCALL ASTX$S, MRKT$S, WTSE$S, IOERR$ IOERR$ ; Define I/O error codes. ; Local equates: TICKS = 1 ; TIME UNITS FOR MARKTIME SECNDS = 2 ; MINUTE = 3 ; HOURS = 4 ; ; Non-fatal error code table: ERRTBL: .BYTE IE.VER ; Parity error on device. .BYTE IE.PRI ; Privilege violation. .BYTE IE.LCK ; Locked from read/write access. .BYTE IE.WAC ; Accessed for write. .BYTE IE.CKS ; File header checksum failure. .BYTE IE.RER ; File processor device read error. .BYTE IE.SNC ; File ID, file number check. .BYTE IE.SQC ; File ID, sequence number check. .BYTE IE.CLO ; File was not properly closed. .BYTE IE.RBG ; Illegal record size. .BYTE IE.BTP ; Bad record type. .BYTE IE.BBE ; Bad block on device. .BYTE IE.BHD ; Bad file header. .BYTE IE.EXP ; File expiration date expired. TBLSIZ = .-ERRTBL ; Number of entrys in error table. .EVEN .SBTTL CALPOS - Calculate character position. ;+ ; ; CALPOS - Calculate the character position. ; ; This routine is used to calculate the character position on a line. ; This is done to adjust for tabs on the line. By default, a tab is ; equated to eight spaces. ; ; Inputs: ; R0 = The buffer address. ; R1 = The real character count. ; ; Outputs: ; R2 = The calculated character count. ; ; All other registers are preserved. ; ;- CALPOS::JSR R5,$SAVRG ; Save R3 - R5. CLR R2 ; Initialize the calculated count. MOV TABSIZ,R3 ; Set the tab size. MOV R0,R4 ; Copy the buffer address. MOV R1,R5 ; and the byte count. BLE 100$ ; If LE, no byte count. 10$: CMPB (R4)+,#HT ; Is this a horizontal tab ? BNE 20$ ; If NE, no. ADD R3,R2 ; Yes, adjust the character count. BR 30$ ; And continue ... 20$: INC R2 ; Adjust the character count. DEC R3 ; Adjust the tab size. BGT 40$ ; If GT, more count to go. 30$: MOV TABSIZ,R3 ; Reset the tab size. 40$: SOB R5,10$ ; Loop until real count is done. 100$: RETURN .SBTTL CTRLC - Control/C AST routine. ;+ ; ; CTRLC - Control/C AST routine. ; ; This routine is entered when the users types CTRL/C to abort. ; ;- CTRLC:: BIS #B.CTRC,STATUS ; Show Control/C was typed. TST (SP)+ ; Remove CTRL/C from stack. ASTX$S ; Exit from the AST. .SBTTL CUPPER - Convert string to upper case. ;+ ; ; CUPPER - Convert string to upper case. ; CUCHAR - Convert single character to upper case. ; ; This routine is used to convert a string of characters to uppercase. ; ; Inputs: ; R0 = The string address (terminated by NULL). ; ; Outputs: ; All registers are preserved. ; ;- CUPPER::JSR R2,$SAVVR ; Save R0 - R2. 10$: CALL CUCHAR ; Convert character to uppercase. TSTB (R0)+ ; End of the string ? BNE 10$ ; If NE, no - more to go. RETURN ; Convert a single character to upper case. CUCHAR::CMPB (R0),#'a ; Possible lowercase ? BLO 10$ ; If LO, no. CMPB (R0),#'z ; Is it really lowercase ? BHI 10$ ; If HI, no. BICB #40,(R0) ; Yes, convert it to uppercase. 10$: RETURN .SBTTL CVTDEC - Convert Binary Number To Decimal ASCII ;+ ; ; CVTDEC - Convert binary number to Decimal ASCII. ; ; Inputs: ; R0 = the output buffer address. ; R1 = the binary number to convert. ; ; Outputs: ; R0 = the updated output buffer address. ; ; All other registers are preserved. ; ;- CVTDEC::JSR R5,.SAVR1 ; Save R1 - R5 MOV #030012,R2 ; WIDTH=6 ! ZERO-SUPPRESS ! DECIMAL CALL $CBTA ; Convert it to decimal ASCII. RETURN .SBTTL CVTDTD - Convert Double Precision Binary To Decimal ASCII ;+ ; ; CVTDTD - Convert double precision binary number to decimal ASCII. ; ; Inputs: ; R0 = the output buffer address. ; R1 = address of the double precision number. ; ; Outputs: ; R0 = the updated output buffer address. ; ; All other registers are preserved. ; ;- CVTDTD::JSR R5,.SAVR1 ; Save R1 - R5 CLR R2 ; Suppress leading zeroes. CALL $CDDMG ; Convert it to decimal ASCII. RETURN .SBTTL CVTOCT - Convert Binary Number To Octal ASCII ;+ ; ; CVTOCT - Convert binary number to octal ASCII. ; ; Inputs: ; R0 = the output buffer address. ; R1 = the binary number to convert. ; ; Outputs: ; R0 = the updated output buffer address. ; ; All other registers are preserved. ; ;- CVTOCT::JSR R5,.SAVR1 ; Save R1 - R5 MOV #030010,R2 ; WIDTH=6 ! ZERO-SUPPRESS ! OCTAL CALL $CBTA ; Convert it to octal ASCII. RETURN .SBTTL DELAY - Wait Specified Time Interval ;+ ; ; DELAY - Wait specified time interval. ; ; Inputs: ; R0 = the time interval magnitude. ; R1 = the time interval unit (i.e., TICKS). ; ; Outputs: ; Carry clear/set = success/failure. ; ; All registers are preserved. ; ;- DELAY:: MRKT$S #MRKEFN,R0,R1 ; ISSUE THE MARK TIME CALL CHKDIR ; Check fir directive status. BCS 100$ ; If CS, the directive failed. WTSE$S #MRKEFN ; ELSE WAIT FOR MARKTIME 100$: RETURN .SBTTL FCSERR - Report an FCS error message. ;+ ; ; FCSERR - Report an FCS error message. ; ; This routine is used to report an FCS error message without appending ; the file name to the error message. It doesn't check for the severity ; of the error either (may want to change this later). If the error is ; "End of file", the error message is not reported (expected error). ; ; Inputs: ; R0 = The FDB address. ; ; Outputs: ; All registers are preserved. ; ;- FCSERR::JSR R2,$SAVVR ; Save R0 - R2. MOV F.ERR(R0),R0 ; Copy the FCS error code. CMPB #IE.EOF,R0 ; Is the error "End of file" ? BEQ 10$ ; If EQ, yes (don't report). CALL WRTERR ; Write the error message text. 10$: SEC ; Show we had an error. RETURN .SBTTL FILERR - Report file error with name. ;+ ; ; FILERR - Report a file error with name. ; ; This routine is used to report an FCS error with the file name appended ; to the error messsage. In addition, it checks for non-fatal errors and ; returns the C-bit clear/set appropriatly. ; ; ; Inputs: ; R5 = The file table entry address. ; ; Outputs: ; C bit clear/set = non-fatal/fatal error. ; ; All registers are preserved. ; ;- FILERR::JSR R2,$SAVVR ; Save R0 - R2 BIS #B.FERR,STATUS ; Show we had a file error. MOV O.FDB(R5),R0 ; Copy the FDB address. MOV F.ERR(R0),R0 ; Copy the FCS error code. CALL WRTERR ; Write the error message text. CALL DOWAIT ; Wait for the user to respond. BIC #B.FERR,STATUS ; The file error was reported. MOV #ERRTBL,R1 ; Copy address of error table. MOV #TBLSIZ,R2 ; Setup the number of entrys. ; Check the error table to see if this is a non-fatal error. 10$: CMPB R0,(R1)+ ; Is this a non-fatal error ? BEQ 100$ ; If EQ, yes. SOB R2,10$ ; Loop through the table. SEC ; Show it's a fatal error. RETURN 100$: CLC ; Show it's a non-fatal error. RETURN .SBTTL GETLEN - Get the length of a string. ;+ ; ; GETLEN - Get the length of a string. ; ; This routine is used to calculate the length of a string which is ; terminated by a NULL byte. ; ; Inputs: ; R0 = The string address (terminated by NULL). ; ; Outputs: ; R0 = The string address. ; R1 = The string length. ; ; All other registers are preserved. ; ;- GETLEN::MOV R0,R1 ; Copy the string address. 10$: TSTB (R1)+ ; Is this the NULL byte ? BNE 10$ ; If NE, no (loop). DEC R1 ; Adjust for the NULL byte. SUB R0,R1 ; Now calculate the length. RETURN .SBTTL MOVEC - Move a character string. ;+ ; ; MOVEC - Move a character string. ; ; Inputs: ; R0 = The output buffer address. ; R1 = The character string to copy (terminated by NULL). ; ; Outputs: ; R0 = The updated buffer address. ; ;- MOVEC:: MOVB (R1)+,(R0)+ ; Copy the next character. BNE MOVEC ; If NE, more to copy. DEC R0 ; Point to the null byte. RETURN .END