.TITLE KEYBRD KEYBOARD INPUT NOTIFICATION .IDENT /F01/ .ENABL LC ; AUTHOR: Bradford Castalia ; CHANGES: ; MODULE FUNCTION: ; CHAR = KEYBRD () ; CHAR - The last character received from the keyboard, ; or null if none. ; The first time this function is called a QIO is issued which attaches ; the task to the terminal so that unsolicited input is trapped locally. ; Subsequently (or until KEYOFF is called) the function returns the ; character most recently received from the keyboard, or 0 if no character ; has been received since the last time the function was called. ; *** NOTE *** The function must be called once before normal use and ; after calling KEYOFF to establish keyboard character trapping. ; *** CAUTION *** The task is attached to the user's terminal. Any other ; attachment operations to the terminal will fail while this function is ; in effect. The task may continue to solicit input from the terminal ; in the normal manner while this function is in effect. ; *** IMPORTANT *** This function assumes that the user's terminal is ; assigned to logical unit 5 as per normal FORTRAN convention. ; STATUS = KEYOFF () ; STATUS - The status of the operation. ; The user's terminal is detached from the task if it had been previously ; attached by a call to KEYBRD. .LIST TTM ; TERMINAL LISTING MODE .NLIST BEX ; SUPPRESS BIN EXTENSION .MCALL QIO$S,ASTX$S ; DATA BLOCKS: .PSECT ,D CHAR: .WORD 0 ; Last character received SET: .WORD 0 ; Setup done flag STATUS: .BLKW 2 ; IO Status Block .PSECT ,I KEYBRD:: TST SET ; First time setup? BEQ SETUP ; Yes MOV CHAR,R0 ; Get the current character CLR CHAR ; Clear for the next time around RETURN ; Attach to user's terminal with unsolicited input AST SETUP: QIO$S #IO.ATA!TF.XCC,#5,#5,,STATUS,,<#KEY> MOV $DSW,R0 ; Directive accepted? BMI 1$ ; No, return error code MOV STATUS,R0 ; Directive completed successfully? BMI 1$ ; No, return error code DEC SET ; Flag setup as complete CLR R0 ; Null is success 1$: RETURN ; Unsolicited character received from terminal KEY: MOV (SP)+,CHAR ; Stash the character ASTX$S ; Detach from the user's terminal KEYOFF:: QIO$S #IO.DET,#5,#5,,STATUS MOV $DSW,R0 ; Directive accepted? BMI 1$ ; No, return error code MOV STATUS,R0 ; Directive completed successfully? BMI 1$ ; No, return error code CLR SET ; Flag detach as complete CLR R0 ; Null is successful status 1$: RETURN .END