.ENABLE LC .TITLE TCFLU2 ; ; AUTHOR: S.C. Cribbs (Technical Services Branch) ; Atomic Energy of Canada Ltd. Pinawa, Manitoba ; 83/05/15 version 2 ; .NLIST ; Conditional Assembly Definitions ; NHD = 1 ;Symbol should be defined for NHD multiplication .LIST .NLIST BEX,CND,MC .LIST ME ; The following symbols have been defined for this assembly: .IIF NDF NHD, NHD = 0 .IF EQ NHD NHD = 0 ;Extended Instruction Set (EIS) multiplication .IFF NHD = 1 ;Non_Hardware_Dependent (NHD) multiplication .ENDC ;NE NHD .GLOBL KTRMID,KCURP,KITCC ;Entry points .GLOBL FLUSHB,LESCSQ,OUTSTR ;External .PSECT USER$D RW,D,LCL,REL,CON ;For subroutine KTRMID NPARM: .BLKW 1 ;Holds #parameters to be returned IPARM: .BLKW 1 ;Holds address of user's vector PKNT: .BLKW 1 ;Holds #parameters found STRTID: .ASCII <33>/[0c/<200> ;Prompt: Report terminal ID. .EVEN ;For subroutine KCURP ROW: .BLKW 1 ;Temporary storage for cursor row# COLM: .BLKW 1 ;Temporary storage for cursor column# STRCRP: .ASCII <33>/[6n/<200> ;Prompt: Report cursor position .EVEN ;Common to subroutines KTRMID, KCURP, KITCC STRING: .BLKB 81. ;Buffer for terminal input .EVEN .PSECT USER$I RW,I,LCL,REL,CON ;Pure Code .PAGE ; Determine terminal's identity ; ;Called from FORTRAN by: ; I = KTRMID(NPARM,IPARM,LPRVTE) ;where: ; NPARM - Maximum number of parameters to return ; IPARM - Integer vector to contain parameter values ; LPRVTE - -1 if private sequence found, else zero ; I - Returned funtion value ; = -1 - Timeout (No response from terminal) ; = 0 - Unrecognized response received ; = >0 - The number of parameters available ; KTRMID: TST (R5)+ ;Skip over FORTRAN arg. count MOV R5,-(SP) ;Preserve argument pointer CALL FLUSHB ;Empty the terminal's input buffer MOV #STRTID,R0 ;Point to prompt string CALL OUTSTR ;Send it to the terminal MOV #STRING,-(SP) ;Construct arg. block on stack MOV #-1,-(SP) ; for subroutine LESCSQ MOV SP,R5 ;Point to the argument block CALL LESCSQ ;Read in terminal's response CMP (SP)+,(SP)+ ;Clear off the stack MOV (SP)+,R5 ;Restore our argument pointer TST R0 ;Look at value returned by LESCSQ BGT 1$ ;If + - received an Escape Sequence RETURN ; else just return error code 1$: MOV @(R5)+,NPARM ;Get the count of parmeters wanted MOV (R5)+,IPARM ; and address of where to put them CLR PKNT ;Initialize #parameters found counter MOV #STRING+1,R0 ;Load address of second char. received CMPB #'[,(R0)+ ;Insist it's the Control Seq. Intro. BNE 4$ ; else declare unrecognized MOV #-1,@(R5)+ ;Assume a private sequence found CMPB #'?,(R0)+ ;Is it DEC's identfier? BEQ 2$ ;Hope so! CLR @-(R5) ; else clear the flag and TSTB -(R0) ; roll back the string pointer 2$: JSR PC,DCODE ;Decode a parameter from the string BCS 4$ ;Abort if error detected in parameter INC PKNT ;Keep track of #parameters found DEC NPARM ;Count down #parameters to be returned BMI 3$ ;Just return those requested MOV R1,@IPARM ;Load into user's vector ADD #2,IPARM ;Point to next vector element 3$: CMPB #'c,(R0)+ ;Have we reached proper end_of_string? BNE 2$ ;Loop till we do (or error) MOV PKNT,R0 ;Return Parameter count RETURN ; to caller 4$: CLR R0 ;Declare Unrecognized input received RETURN ;Tell caller .PAGE ; Get the video terminal's present cursor position ; ;Called from FORTRAN by: ; I = KCURP(IROW,ICOL) ;where: ; IROW - Cursor position row number ; ICOLM - & column number ; I - Returned value ; = -1 - Timeout (No response from terminal) ; = 0 - Unrecognized response received ; = 1 - Proper format response recived ; KCURP: TST (R5)+ ;Skip over FORTRAN arg. count MOV R5,-(SP) ;Preserve argument pointer CALL FLUSHB ;Empty the terminal's input buffer MOV #STRCRP,R0 ;Point to prompt string CALL OUTSTR ;Send it to the terminal MOV #STRING,-(SP) ;Construct arg. block on stack MOV #-1,-(SP) ; for subroutine LESCSQ MOV SP,R5 ;Point to the argument block CALL LESCSQ ;Read in terminal's response CMP (SP)+,(SP)+ ;Clear off the stack MOV (SP)+,R5 ;Restore our argument pointer TST R0 ;Look at value returned by LESCSQ BGT 1$ ;If + - received an Escape Sequence RETURN ; else just return error code 1$: MOV #1,ROW ;Define default row number MOV #1,COLM ; and column number MOV #STRING+1,R0 ;Load address of second char. received CMPB #'[,(R0)+ ;Insist it's the Control Seq. Intro. BNE 4$ ; else declare unrecognized JSR PC,DCODE ;Decode the first parameter BCS 4$ ;Abort if an error found TST R1 ;Look at parameter value BLE 2$ ;Assume default if zero or negative MOV R1,ROW ; else store the row number 2$: CMPB #';,@R0 ;Parameter separator found? BNE 3$ ;Jump if not INC R0 ;Yes, update pointer past it JSR PC,DCODE ;Decode the second parameter BCS 4$ ;Abort if an error found TST R1 ;Look at parameter value BLE 3$ ;Assume default if zero or negative MOV R1,COLM ; else store the column number 3$: CMPB #'R,(R0)+ ;Encountered proper end_of_string? BNE 4$ ;Take error exit if not MOV ROW,@(R5)+ ;Load cursor row number MOV COLM,@(R5)+ ; and column number for user MOV #1,R0 ;Report success RETURN ; to caller 4$: CLR R0 ;Declare Unrecognized input received RETURN ;Tell caller .PAGE ; Internally called subroutine: DCODE ; ; DCODE translate Escape Sequence parameters into representative ; numeric values. DCODE assumes no parameter will exceed 32767. ; ; Input: R0 points to the first character of parameter ; Output: R0 points to the parameter termination character ; or the illegal character if one found ; R1 will contain the numeric value of the parameter ; ; Note: -The carry flag will be set on return if an ; illegal or unrecognized character is found. ; -Control Sequence Intermediate characters are ; not recognized (but then, none are defined) ; DCODE: MOV R2,-(SP) ;Require workspace CLR R1 ;Initialize value to be returned 1$: MOVB (R0)+,R2 ;Get a character from the string CMPB #'0,R2 ;Compare against lowest numeric BHI 2$ ;Error if too small CMPB #'9,R2 ;Compare with highest decimal numeric BLO 3$ ;Anything higher is a legal terminator BIC #^C17,R2 ;Strip character to a number value CLC ;Be sure carry flag is reset .IF NE NHD ASL R1 ;+ NHD multiply parameter value by 10 BVS 2$ ;+ MOV R1,-(SP) ;+ ASL R1 ;+ BVS 2$ ;+ ASL R1 ;+ BVS 2$ ;+ ADD (SP)+,R1 ;+ BVS 2$ ;+ .IFF MUL #10.,R1 ;Decimal scale of parameter value .ENDC ;NE NHD BCS 2$ ;Detect overflow in decimal scaling ADD R2,R1 ;Add in latest digit BVC 1$ ;Monitor for value overflow 2$: SEC ;Declare problem to caller 3$: MOV (SP)+,R2 ;Restore saved value into workspace TSTB -(R0) ;Point to Parameter terminator RTS PC ; back to calling routine .PAGE ; ; KITCC - Decodes Keypad and Cursor positioning key input ; ; Note: Terminal must have Keypad Application Mode set for ; keypad keys (except PF1->PF4) to be detected. ; ANSI Cursor Key Mode must be set for cursor ; positioning keys to be detected. ; ;Called from FORTRAN by: ; I = KITCC(INCHAR,ICODE) ;where: ; INCHAR - Provided by user, the termination character of ; the just received Escape sequence ; ICODE - Integer returned, the numeric value of the received ; terminal command key; ; -if numeric or punctuation, ICODE will ; contain the actual character code: ; ',' = "54 44 decimal ; '-' = "55 45 ; '.' = "56 46 ; '0' = "60 48 ; '1' = "61 49 ; '2' = "62 50 ; '3' = "63 51 ; '4' = "64 52 ; '5' = "65 53 ; '6' = "66 54 ; '7' = "67 55 ; '8' = "70 56 ; '9' = "71 57 ; -if Cursor control, Programmable function or ; the key; ; Up = "1 1 decimal ; Down = "2 2 ; Right = "3 3 ; Left = "4 4 ; = "15 13 ; PF1 = "20 16 ; PF2 = "21 17 ; PF3 = "22 18 ; PF4 = "23 19 ; - or if an error or unrecognized character is detected ; the ASCII character actually received ; I - Returned function value ; = -1 - Timeout or unrecognized input ; = 0 - Numeric or puntuation command ; = 1 - Cursor control, Programmable function or ; the key pressed ; KITCC: TST (R5)+ ;Skip over the FORTRAN arg. count MOVB @(R5)+,R0 ;Look at Escape Sequence terminator MOV (R5)+,-(SP) ;Preserve address for returned ICODE CMPB #'O,R0 ;Is this the expected terminator? BEQ 2$ ;Yes, can run full series of tests CLRB STRING ;Define a null to return in ICODE 1$: MOV (SP)+,R5 ;Reload argument pointer MOVB STRING,@R5 ;Load the cause of the problem MOV #-1,R0 ; and the function error code RETURN ;Inform user of our misfortune 2$: MOV #STRING,-(SP) ;Construct arg. block on stack MOV #-1,-(SP) ; for subroutine LESCSQ MOV SP,R5 ;Point to the argument block CALL LESCSQ ;Read in terminal's response CMP (SP)+,(SP)+ ;Clear off the stack TST R0 ;What did LESCSQ get us? BNE 1$ ;Problem, if Timeout or Escape Seq. MOVB STRING,R1 ;Get the single character received BITB #100,R1 ;From ASCII table col. 4 or greater? BEQ 1$ ; else we wont recognize it BIC #^C77,R1 ;Strip to least significant 6 bits BEQ 1$ ; but null code is not defined MOV #1,R0 ;Assume it's a terminal command CMPB #4,R1 ;Test against cursor control codes BHIS 3$ ;Identified it if in range CMPB #15,R1 ;Could this be an key? BEQ 3$ ;Yes, if matched CMPB #20,R1 ;Maybe a Programmable Function Key? BHI 1$ ;Trap unidentified codes CMPB #23,R1 ;Still within range of codes? BHIS 3$ ;Yup, go report find CLR R0 ;Assume Punctuation or Numeric CMPB #',,R1 ;Is it a coma? BHI 1$ ;Trap unidentified codes CMPB #'.,R1 ;Is it a "-" or "."? BHIS 3$ ;Punctuation identified if in range CMPB #'0,R1 ;Check the numeric range BHI 1$ ;Trap unidentified codes CMPB #'9,R1 ;Recognize full decimal numerics BLO 1$ ; else trap the unidentified code 3$: MOV (SP)+,R5 ;Get address for ICODE from stack MOVB R1,@R5 ;Load the value for the user RETURN ; to caller .END