! %TITLE 'Console Terminal I/O Routines' MODULE consolio (IDENT = 'V01.01' ! File: CONSOLIO.BLI ) = BEGIN !++ ! ! FACILITY: CON - Console terminal I/O routines. ! ! ABSTRACT: This module contains routines that perform simple formatting ! and output to the console terminal. ! ! ENVIRONMENT: VAX, kernel mode, any IPL, no VMS dependencies. ! ! AUTHOR: James A. Gray ! ! CREATED: 25 August 1986 ! ! MODIFICATION ! HISTORY: ! ! V01.01 25 August 1986, James A. Gray ! Original version. ! !-- %SBTTL 'Declarations' !+ ! SWITCHES: !- SWITCHES ADDRESSING_MODE (EXTERNAL = GENERAL, NONEXTERNAL = WORD_RELATIVE); !+ ! LINKAGE/GLOBAL REGISTERS: !- ! None. !+ ! LINKAGES: !- LIBRARY 'CONSOLIO_LIB'; ! Linkage declarations. !+ ! TABLE OF CONTENTS: !- FORWARD ROUTINE con_getchar : ! Get a character from the console terminal. consolio_getchar_linkage, con_outblank : ! Outputs a blank character to the console. NOVALUE consolio_outblank_linkage, con_outchar : ! Outputs a single character to the console. NOVALUE consolio_outchar_linkage, con_outcrlf : ! Outputs a return/line feed sequence to the console. NOVALUE consolio_outcrlf_linkage, con_outcstring : ! Outputs a counted string to the console. NOVALUE consolio_outcstring_linkage, con_outhex : ! Outputs a longword as a hexadecimal value to the console. NOVALUE consolio_outhex_linkage, con_outzstring : ! Outputs a zero terminated string (ASCIZ) to the console. NOVALUE consolio_outzstring_linkage, con_owncty : ! "Allocate" console terminal. NOVALUE consolio_owncty_linkage, con_putchar : ! Outputs a character to the console. NOVALUE consolio_putchar_linkage, con_putstring : ! Outputs a string to the console. NOVALUE consolio_putstring_linkage, con_read_prompt, ! Read a string from the console. con_releasecty : ! "Deallocate" console terminal. NOVALUE consolio_releasecty_linkage; !+ ! INCLUDE FILES: !- LIBRARY 'SYS$LIBRARY:LIB'; ! VMS dependent macros/symbols. !+ ! MACROS: !- MACRO rxcs_v_ready = ! Receiver ready bit. 0, 7, 1, 0 %, rxdb_v_char = ! Received character. 0, 0, 7, 0 %, txcs_v_ready = ! Transmitter ready bit. 0, 7, 1, 0 %; !+ ! FIELDS: !- ! None. !+ ! STRUCTURES: !- ! None. !+ ! PROGRAM SECTION DECLARATIONS: !- ! None. !+ ! EQUATED SYMBOLS: !- LITERAL con_k_control_u = 21, ! ASCII control U. con_k_control_q = 17, ! ASCII control Q. con_k_control_s = 19, ! ASCII control S. con_k_cr = 13, ! ASCII carriage return. con_k_lf = 10, ! ASCII line feed. con_k_nul = 0, ! ASCII null (or fill). con_k_sp = 32, ! ASCII space. con_k_rub = 127, ! ASCII rubout. con_k_tab = 9; ! ASCII tab. !+ ! OWN (R/O) STORAGE: !- BIND con_t_hex = ! Hexadecimal conversion table. UPLIT (%ASCII'0123456789ABCDEF') : VECTOR [, BYTE]; !+ ! OWN (R/W) STORAGE: !- ! None. !+ ! BUILTIN DECLARATIONS: !- BUILTIN MFPR, MTPR; !+ ! EXTERNAL ROUTINES: !- ! None. !+ ! EXTERNAL REFERENCES: !- ! None. %SBTTL 'CON_GETCHAR - Read a string from the console' GLOBAL ROUTINE con_getchar : consolio_getchar_linkage = !++ ! ! FUNCTIONAL DESCRIPTION: ! ! This routine returns the next character input to the console terminal. ! If a character is pending, i.e. was already typed before this routine ! was called, then that character will be returned otherwise this ! routine will wait for the next one. ! ! ENVIRONMENT: ! ! Kernel access mode, kernel or interrupt stack, any IPL. ! ! CALLING SEQUENCE: ! ! CON_GETCHAR () ! ! LINKAGE: ! ! JSB ! ! FORMAL PARAMETERS: ! ! None. ! ! IMPLICIT INPUTS: ! ! None. ! ! IMPLICIT OUTPUTS: ! ! None. ! ! RETURNED VALUE: ! ! The character read from the console terminal. ! ! SIDE EFFECTS: ! ! None. ! !-- BEGIN LABEL get_string_loop, read_prompt_loop; LOCAL con_l_char : ! Character last read from console terminal. BLOCK [1, LONG]; !+ ! Wait for a character to be typed. !- DO MFPR (pr$_rxcs, con_l_char) UNTIL .con_l_char [rxcs_v_ready]; !+ ! Read the last character typed. !- MFPR (pr$_rxdb, con_l_char); .con_l_char [rxdb_v_char] END; ! End of routine CON_GETCHAR %SBTTL 'CON_OUTBLANK - Outputs a blank character to the console' GLOBAL ROUTINE con_outblank : NOVALUE consolio_outblank_linkage = !++ ! ! FUNCTIONAL DESCRIPTION: ! ! This routine outputs a space (or blank) character to the ! console terminal. ! ! ENVIRONMENT: ! ! Kernel access mode, kernel or interrupt stack, any IPL. ! ! CALLING SEQUENCE: ! ! CON_OUTBLANK () ! ! LINKAGE: ! ! JSB ! ! FORMAL PARAMETERS: ! ! None. ! ! IMPLICIT INPUTS: ! ! None. ! ! IMPLICIT OUTPUTS: ! ! None. ! ! COMPLETION CODES: ! ! None. ! ! SIDE EFFECTS: ! ! None. ! !-- BEGIN _outchar (char = con_k_sp); END; ! End of routine CON_OUTBLANK %SBTTL 'CON_OUTCHAR - Outputs a single character to the console' GLOBAL ROUTINE con_outchar ( ! con_b_char : BYTE ! ) : NOVALUE consolio_outchar_linkage = !++ ! ! FUNCTIONAL DESCRIPTION: ! ! This routine outputs a single character to the console terminal. If that ! character is a carriage return, then an appropriate number of fill ! characaters are output to give the carriage time to return assuming that ! it is a hardcopy terminal. ! ! ENVIRONMENT: ! ! Kernel access mode, kernel or interrupt stack, any IPL. ! ! CALLING SEQUENCE: ! ! CON_OUTCHAR (con_b_char.rbu.v) ! ! LINKAGE: ! ! JSB ! ! FORMAL PARAMETERS: ! ! con_b_char ! The character to be output. ! ! IMPLICIT INPUTS: ! ! None. ! ! IMPLICIT OUTPUTS: ! ! None. ! ! COMPLETION CODES: ! ! None. ! ! SIDE EFFECTS: ! ! None. ! !-- BEGIN con_putchar (.con_b_char); !+ ! If the character just output was a carriage returen then output the ! proper number of nulls. !- IF .con_b_char EQL con_k_cr THEN DECR i FROM 1 TO 0 DO con_putchar (con_k_nul); END; ! End of routine CON_OUTCHAR %SBTTL 'CON_OUTCRLF - Outputs a return/line feed sequence to the console' GLOBAL ROUTINE con_outcrlf : NOVALUE consolio_outcrlf_linkage = !++ ! ! FUNCTIONAL DESCRIPTION: ! ! This routine outputs a carriage return/line feed sequence to the ! console terminal. ! ! ENVIRONMENT: ! ! Kernel access mode, kernel or interrupt stack, any IPL. ! ! CALLING SEQUENCE: ! ! CON_OUTCRLF () ! ! LINKAGE: ! ! JSB ! ! FORMAL PARAMETERS: ! ! None. ! ! IMPLICIT INPUTS: ! ! None. ! ! IMPLICIT OUTPUTS: ! ! None. ! ! COMPLETION CODES: ! ! None. ! ! SIDE EFFECTS: ! ! None. ! !-- BEGIN _outchar (char = con_k_cr); _outchar (char = con_k_lf); END; ! End of routine CON_OUTCRLF %SBTTL 'CON_OUTCSTRING - Outputs a counted string to the console' GLOBAL ROUTINE con_outcstring ( ! con_a_string ! ) : NOVALUE consolio_outcstring_linkage = !++ ! ! FUNCTIONAL DESCRIPTION: ! ! This routine outputs a counted string (ASCIC) to the console terminal. ! ! ENVIRONMENT: ! ! Kernel access mode, kernel or interrupt stack, any IPL. ! ! CALLING SEQUENCE: ! ! CON_OUTCSTRING (con_a_string.rt.r) ! ! LINKAGE: ! ! JSB ! ! FORMAL PARAMETERS: ! ! con_a_cstring ! Address of the string to be output. ! ! IMPLICIT INPUTS: ! ! None. ! ! IMPLICIT OUTPUTS: ! ! None. ! ! COMPLETION CODES: ! ! None. ! ! SIDE EFFECTS: ! ! None. ! !-- BEGIN LOCAL con_l_length; ! Length of the string; con_l_length = CH$RCHAR_A (con_a_string); con_putstring (.con_a_string, .con_l_length); END; ! End of routine CON_OUTCSTRING %SBTTL 'CON_OUTHEX - Outputs a longword as a hexadecimal value to the console' GLOBAL ROUTINE con_outhex ( ! con_l_value : BLOCK [, BYTE], ! con_l_zero_sup ! ) : NOVALUE consolio_outhex_linkage = !++ ! ! FUNCTIONAL DESCRIPTION: ! ! This routine converts a longword to hexadecimal and outputs the resulting ! characters to the console terminal. ! ! ENVIRONMENT: ! ! Kernel access mode, kernel or interrupt stack, any IPL. ! ! CALLING SEQUENCE: ! ! CON_OUTHEX (con_l_value.rlu.v, con_l_zero_sup.rlu.v) ! ! LINKAGE: ! ! JSB ! ! FORMAL PARAMETERS: ! ! con_l_value ! The value to be converted and output. ! ! con_l_zero_sup ! Flag, true => suppress leading zeros. ! ! IMPLICIT INPUTS: ! ! None. ! ! IMPLICIT OUTPUTS: ! ! None. ! ! COMPLETION CODES: ! ! None. ! ! SIDE EFFECTS: ! ! None. ! !-- BEGIN LOCAL con_c_char : ! Next character to be output. BYTE, con_l_sup_zero; ! Zero suppression flag. con_l_sup_zero = .con_l_zero_sup; DECR i FROM 7 TO 0 DO BEGIN con_c_char = .con_t_hex [.con_l_value [0, .i*4, 4, 0]]; IF ( NOT .con_l_sup_zero) OR (.con_c_char NEQU %C'0') THEN BEGIN con_l_sup_zero = 0; _outchar (char = .con_c_char); END; END; END; ! End of routine CON_OUTHEX %SBTTL 'CON_OUTZSTRING - Outputs a zero terminated string (ASCIZ) to the console' GLOBAL ROUTINE con_outzstring ( ! con_a_string ! ) : NOVALUE consolio_outzstring_linkage = !++ ! ! FUNCTIONAL DESCRIPTION: ! ! This routine outputs a zero terminated string (ASCIZ) to the console ! terminal. ! ! ENVIRONMENT: ! ! Kernel access mode, kernel or interrupt stack, any IPL. ! ! CALLING SEQUENCE: ! ! CON_OUTZSTRING (con_a_string.rt.r) ! ! LINKAGE: ! ! JSB ! ! FORMAL PARAMETERS: ! ! con_a_string ! Address of the string to be output. ! ! IMPLICIT INPUTS: ! ! None. ! ! IMPLICIT OUTPUTS: ! ! None. ! ! COMPLETION CODES: ! ! None. ! ! SIDE EFFECTS: ! ! None. ! !-- BEGIN con_putstring (.con_a_string, 255); END; ! End of routine CON_OUTZSTRING %SBTTL 'CON_OWNCTY - "Allocate" the console terminal' GLOBAL ROUTINE con_owncty ( ; ! con_l_txcs, ! con_l_rxcs ! ) : NOVALUE consolio_owncty_linkage = !++ ! ! FUNCTIONAL DESCRIPTION: ! ! This routine "allocates" the console terminal by saving the contents ! of the status registers and then disabling interrupts. "Deallocation" ! is done by the routine CON_RELEASECTY. ! ! ENVIRONMENT: ! ! Kernel access mode, kernel or interrupt stack, any IPL. ! ! CALLING SEQUENCE: ! ! CON_OWNCTY (; con_l_txcs.wlu.r, con_l_rxcs.wlu.r) ! ! LINKAGE: ! ! JSB ! ! FORMAL PARAMETERS: ! ! con_l_txcs ! Address of a longword in which to save the current console ! terminal transmitter status register. ! ! con_l_rxcs ! Address of a longword in which to save the current console ! terminal receiver status register. ! ! IMPLICIT INPUTS: ! ! None. ! ! IMPLICIT OUTPUTS: ! ! None. ! ! COMPLETION CODES: ! ! None. ! ! SIDE EFFECTS: ! ! Console terminal interrupts are disabled. ! !-- BEGIN MFPR (pr$_txcs, con_l_txcs); MFPR (pr$_rxcs, con_l_rxcs); MTPR (%REF (0), pr$_rxcs); MTPR (%REF (0), pr$_txcs); END; ! End of routine CON_OWNCTY %SBTTL 'CON_PUTCHAR - Outputs a character to the console' GLOBAL ROUTINE con_putchar ( ! con_b_char : BYTE ! ) : NOVALUE consolio_putchar_linkage = !++ ! ! FUNCTIONAL DESCRIPTION: ! ! This routine outputs a single character to the console terminal. No ! provision is made for fill characters if that character is a carriage ! return. ! ! ENVIRONMENT: ! ! Kernel access mode, kernel or interrupt stack, any IPL. ! ! CALLING SEQUENCE: ! ! CON_PUTCHAR (con_b_char.rbu.v) ! ! LINKAGE: ! ! JSB ! ! FORMAL PARAMETERS: ! ! con_b_char ! The character to be output. ! ! IMPLICIT INPUTS: ! ! None. ! ! IMPLICIT OUTPUTS: ! ! None. ! ! COMPLETION CODES: ! ! None. ! ! SIDE EFFECTS: ! ! None. ! !-- BEGIN LOCAL con_l_temp : ! BLOCK [1, LONG]; !+ ! Look to see if a character has been received. !- MFPR (pr$_rxcs, con_l_temp); IF .con_l_temp [rxcs_v_ready] THEN BEGIN !+ ! A character has been received, check if it is a control-S thereby ! stopping output for a while. If the character is not a control-S ! then just ignore it. !- MFPR (pr$_rxdb, con_l_temp); IF .con_l_temp [rxdb_v_char] EQLU con_k_control_s THEN BEGIN !+ ! A control-S has been received. Wait for a corresponding ! control-Q before outputting character. !- DO BEGIN DO MFPR (pr$_rxcs, con_l_temp) UNTIL .con_l_temp [rxcs_v_ready]; MFPR (pr$_rxdb, con_l_temp); END UNTIL .con_l_temp [rxdb_v_char] EQLU con_k_control_q; END; END; !+ ! Wait for the transmitter to become idle and then output the character. !- DO MFPR (pr$_txcs, con_l_temp) UNTIL .con_l_temp [txcs_v_ready]; MTPR (%REF (.con_b_char), pr$_txdb); END; ! End of routine CON_PUTCHAR %SBTTL 'CON_PUTSTRING - Outputs a string to the console' GLOBAL ROUTINE con_putstring ( ! con_a_string, ! con_l_length ! ) : NOVALUE consolio_putstring_linkage = !++ ! ! FUNCTIONAL DESCRIPTION: ! ! This routine outputs a string to the console terminal. The number ! of characters to be output is supplied. If a zero byte is found ! then the string output will be truncated. ! ! ENVIRONMENT: ! ! Kernel access mode, kernel or interrupt stack, any IPL. ! ! CALLING SEQUENCE: ! ! CON_PUTSTRING (con_a_string.rt.r, con_l_length.rlu.v) ! ! LINKAGE: ! ! JSB ! ! FORMAL PARAMETERS: ! ! con_a_string ! Address of the string to be output. ! ! con_l_length ! Number of characters in the string tobe output. ! ! IMPLICIT INPUTS: ! ! None. ! ! IMPLICIT OUTPUTS: ! ! None. ! ! COMPLETION CODES: ! ! None. ! ! SIDE EFFECTS: ! ! None. ! !-- BEGIN LOCAL con_b_char : ! Current character being output. BYTE; DECR i FROM .con_l_length - 1 TO 0 DO IF (con_b_char = CH$RCHAR_A (con_a_string)) EQLU 0 THEN EXITLOOP ELSE _outchar (char = .con_b_char); END; ! End of routine CON_PUTSTRING %SBTTL 'CON_READ_PROMPT - Read a string from the console' GLOBAL ROUTINE con_read_prompt ( ! con_t_prompt : REF VECTOR [, BYTE], ! con_l_string_siz, ! con_t_string : REF VECTOR [, BYTE] ! ) = !++ ! ! FUNCTIONAL DESCRIPTION: ! ! This routine first prompts the user at the console terminal and then ! reads a string from the console terminal and then returns the length ! of the string read. Support for the delete character is included. ! Characters will be read from the console terminal until either the ! string is full or a carriage return is typed. All characters read ! will be forced to uppercase before echoing; no lowercase characters ! will be returned. ! ! ENVIRONMENT: ! ! Kernel access mode, kernel or interrupt stack, any IPL. ! ! CALLING SEQUENCE: ! ! CON_READ_PROMPT (con_t_prompt.rt.r, con_l_string_siz.rlu.v, con_t_string.wt.r) ! ! LINKAGE: ! ! CALL ! ! FORMAL PARAMETERS: ! ! con_t_prompt ! Prompt string as an ASCIZ string. Passed by reference. ! ! con_l_string_siz ! Maximum size of the string to be read. ! ! con_t_string ! String buffer. Passed by reference. ! ! IMPLICIT INPUTS: ! ! None. ! ! IMPLICIT OUTPUTS: ! ! None. ! ! RETURNED VALUE: ! ! Length of the string read. ! ! SIDE EFFECTS: ! ! None. ! !-- BEGIN LABEL get_string_loop, read_prompt_loop; LOCAL con_c_last : ! Character last read from console terminal. BYTE, con_l_rub_started, ! Rubout sequence started. con_l_string_len; ! Length of the string read. read_prompt_loop : BEGIN WHILE 1 DO BEGIN !+ ! No string read nor RUBOUT in progress. !- con_l_string_len = 0; con_l_rub_started = 0; !+ ! Output the prompt string. !- _outzstring (string = con_t_prompt [0]); get_string_loop : BEGIN WHILE 1 DO BEGIN !+ ! If string is full then done. !- IF .con_l_string_len GEQU .con_l_string_siz THEN LEAVE read_prompt_loop; !+ ! Get a character and if it's a carriage return then done. !- IF (con_c_last = _getchar AND %X'7F') EQLU con_k_cr THEN BEGIN _outcrlf; LEAVE read_prompt_loop; END; !+ ! If current character is a control-U then set string length to null, echo ! the carriage return and loop back to re-echo the prompt string. !- IF .con_c_last EQLU con_k_control_u THEN BEGIN _outcrlf; LEAVE get_string_loop; END; !+ ! If current character is a RUBOUT the begin a RUBOUT sequence (if not already ! started) by echoing a backslash ("\"), the character being deleted and remove ! the string from the string. !- IF .con_c_last EQLU con_k_rub THEN BEGIN IF NOT .con_l_rub_started THEN BEGIN con_l_rub_started = 1; _outzstring (string = '\'); END; IF .con_l_string_len GTRU 0 THEN _outchar (char = .con_t_string [(con_l_string_len = .con_l_string_len - 1)]); END ELSE BEGIN !+ ! Current character is not a special character. If a RUBOUT was in progress ! then output closing backslash ("\"). !- IF .con_l_rub_started THEN BEGIN con_l_rub_started = 0; _outzstring (string = '\'); END; !+ ! Upcase the current character. !- IF (.con_c_last GEQU %C'a') AND (.con_c_last LEQU %C'z') THEN con_c_last = .con_c_last - (%C'a' - %C'A'); !+ ! Echo the current character and add it to the string. !- _outchar (char = .con_c_last); con_t_string [.con_l_string_len] = .con_c_last; con_l_string_len = .con_l_string_len + 1; END; END; END; END; END; !+ ! Return the length of the string. !- .con_l_string_len END; ! End of routine CON_READ_PROMPT %SBTTL 'CON_RELEASECTY - "Deallocate" the console terminal' GLOBAL ROUTINE con_releasecty ( ! con_l_txcs, ! con_l_rxcs ! ) : NOVALUE consolio_releasecty_linkage = !++ ! ! FUNCTIONAL DESCRIPTION: ! ! This routine "deallocates" the console terminal by restoring the contents ! of the status registers saved by a call to CON_OWNCTY. ! ! ENVIRONMENT: ! ! Kernel access mode, kernel or interrupt stack, any IPL. ! ! CALLING SEQUENCE: ! ! CON_RELEASECTY (con_l_txcs.rlu.v, con_l_rxcs.rlu.v) ! ! LINKAGE: ! ! JSB ! ! FORMAL PARAMETERS: ! ! con_l_txcs ! Value of the longword in which the console terminal transmitter ! status register contents was saved by a call to _owncty. ! ! con_l_rxcs ! Value of the longword in which the console terminal receiver ! status register contents was saved by a call to _owncty. ! ! IMPLICIT INPUTS: ! ! None. ! ! IMPLICIT OUTPUTS: ! ! None. ! ! COMPLETION CODES: ! ! None. ! ! SIDE EFFECTS: ! ! Console terminal interrupts may be enabled. ! !-- BEGIN MTPR (con_l_txcs, pr$_txcs); MTPR (con_l_rxcs, pr$_rxcs); END; ! End of routine CON_RELEASECTY END ! End of module CONSOLIO ELUDOM