.TITLE DIRUTL - DIR Utility Routines .IDENT /1.2/ .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: DIRUTL.MAC ; Author: Robin Miller ; Date: February 19, 1985 ; ; Description: ; ; This module contains the utility routines for the DIR program. ; ; Modification History: ; ; April 11, 1985 by Robin Miller. Edit (02), Version 1.2 ; Don't convert lowercase characters within a quoted string. ; ; April 11, 1985 by Robin Miller. Edit (01), Version 1.1 ; When CTRL/C is detected, detach the terminal so the second CTRL/C ; gets sent to MCR or DCL so the user can abort the program. This ; allows us to abort the program for example when the magtape is ; spacing forward looking for a file on the tape. ; ;- .ENABL AMA .NLIST BEX .MCALL ASTX$S, DIR$, MRKT$S, WTSE$S .SBTTL Local Definitions. ; Local definitions: C.RADX = 377 ; ( 0-7 ) Conversion radix (2.-16.). C.BIN = 2. ; Binary radix. C.OCT = 8. ; Octal radix. C.DEC = 10. ; Decimal radix. C.HEX = 16. ; Hexadecimal radix. C.SIGN = 400 ; ( 8 ) Convert signed value. C.NZS = 1000 ; ( 9 ) Non-zero suppression flag. C.BLF = 2000 ; ( 10 ) Blank fill flag (0=zero fill). C.FLDS = 174000 ; (11-15) Field width bits (1-32). .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. DIR$ #DETACH ; And detach the terminal. (01) TST (SP)+ ; Remove CTRL/C from the 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. CLR R2 ; Initialize quoted string flag.(02) 10$: CMPB #'",(R0) ; Is this a quoted string ? (02) BNE 20$ ; If NE, no. (02) COM R2 ; Show quoted string detected. (02) 20$: TST R2 ; Processing a quoted string ? (02) BNE 30$ ; If NE, yes, don't convert. (02) CALL CUCHAR ; Convert character to uppercase. 30$: 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. CLRB (R0) ; Terminate the output buffer. RETURN .SBTTL CVTTWO - Convert To Two Decimal Digits. ;+ ; ; CVTTWO - Convert binary number to two decimal ASCII digits. ; ; Inputs: ; R0 = the output buffer address. ; R1 = the binary number to convert. ; ; Outputs: ; R0 = the updated output buffer address. ; ; All other registers are preserved. ; ;- CVTTWO::JSR R5,.SAVR1 ; Save R1 - R5 MOV #010000!C.NZS!C.DEC,R2 ; Decimal radix. ; Non-zero suppression. ; Zero fill. ; Field width = 2 CALL $CBTA ; Convert it to decimal ASCII. CLRB (R0) ; Terminate the output buffer. 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 MOV R0,-(SP) ; Save current buffer address. CLR R2 ; Suppress leading zeroes. CALL $CDDMG ; Convert it to decimal ASCII. MOV R0,R3 ; Copy the buffer address. SUB (SP)+,R3 ; Calculate the byte count. ADD R3,FLDSIZ ; Adjust the current field size. CLRB (R0) ; Terminate the output buffer. 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. CLRB (R0) ; Terminate the output buffer. 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. ; ; Inputs: ; R0 = The FDB address. ; R5 = The file entry address. ; ; Outputs: ; C bit set to show we had an error. ; ; All registers are preserved. ; ;- FILERR::JSR R2,$SAVVR ; Save R0 - R2 BIS #B.FERR,STATUS ; Show we had a file error. MOV R5,EENTRY ; Save entry which had error. MOV F.ERR(R0),R0 ; Copy the FCS error code. CALL WRTERR ; Write the error message text. BIC #B.FERR,STATUS ; Reset the file error flag. 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