Keyboard and CRT I/O Reference

This appendix is a reference that describes in detail the routines which provide access to the BASIC keyboard and CRT.

The CRT I/O routines access the CRT drivers at a fairly low-level. For example, the scrolling routines and disp_at_xy are below the high-level PRINT driver. Therefore, system variables defining the top and bottom of current text, and current print position are not updated by these routines. This leads to what appears to be abnormal behavior in arrow key scrolling and current print position. Consequently, it is recommended these routines not be used when mixing CSUB displays with normal BASIC displays.

The routines described in this appendix are implemented in HP Pascal for the Pascal Workstation and HP-UX. If you wish to call them from another language, you will need to determine the parameter types in that language which match the types of the formal parameters of the routines.

CLEAR_SCREEN

IMPORT: KBDCRT

This procedure clears the alpha CRT, which is exactly the same as the [Clear display] key on the keyboard, or the BASIC CLEAR SCREEN statement.

Syntax

CLEAR_SCREEN

Example Procedure Calls


   CLEAR_SCREEN

   IF finished THEN CLEAR_SCREEN

CONTROLCRT

IMPORT: KBDCRT

This procedure sends information to a CRT control register

Syntax

CONTROLCRT ( register , control ) number

Item Description Range
register number numeric expression of TYPE cbyte 0 to 21 except for 3,6,7,9, and 19.
control numeric expression of TYPE cword depends on the register

Example Procedure Calls


   CONTROLCRT(reg, cont)

   CONTROLCRT(1,10)

Semantics

The "register number" (reg) parameter designates the register to be written.

The "control" (cont) contains the value to be written into the CRT control register. Refer to the "CRT Status and Control Registers" section in the HP BASIC Language Reference for more information.

This procedure will escape with a BASIC errorcode if an illegal argument is given. The value will be such that errorcode MOD 1000 = 401 is true.

CONTROLKBD

IMPORT: KBDCRT

This procedure sends information to a keyboard control register

Syntax

CONTROLKBD ( register , control ) number

Item Description Range
register number numeric expression of TYPE cbyte 0 to 17 except for 5,6,8,9 and 10
control numeric expression of TYPE cword depends on register

Example Procedure Calls


   CONTROLKBD(reg, cont)

   CONTROLKBD(2,0)

Semantics

The "register number" (reg) parameter designates the register to be written.

The "control" (cont) contains the value to be written into the keyboard control register. Refer to the "Keyboard Status and Control Registers" section in the HP BASIC Language Reference for more information.

This procedure will escape with a BASIC errorcode if an illegal argument is given. The value will be such that errorcode MOD 1000 = 401 is true.

CRTREADCHAR

IMPORT: KBDCRT

This function reads one character from the specified location on the CRT.

Syntax

CRTREADCHAR ( x_coordinate , y_coordinate )

Item Description Range
x_coordinate numeric expression of TYPE cbyte 1 to screen width
y_coordinate word numeric expression of TYPE cbyte 1 to screen height

Function Heading


   FUNCTION CRTREADCHAR (X,Y:CBYTE): CHAR;

Example Function Calls


   One_chr := CRTREADCHAR(xcrd,ycrd)

   IF CRTREADCHAR(24,22) = 'A' THEN foundit := TRUE

Semantics

The "x_coordinate" (xcrd) and "y_coordinate" (ycrd) specify the on-screen alpha location from the upper left corner of the alpha CRT area (affected by ALPHA HEIGHT). Invalid values of x,y result in an escape with escapecode set to 1019.

CRTSCROLL

IMPORT: KBDCRT

This procedure scrolls the CRT area from line first to line last up or down one line.

Syntax

CRTSCROLL ( first , last , down ) line line

Item Description Range
first line numeric expression of TYPE cbyte 1 thru screen height
last line numeric expression of TYPE cbyte 1 thru screen height
boolean expression of TYPE boolean true or false

Example Procedure Calls


   CRTSCROLL(first,last,dn)

   CRTSCROLL(12,22,tf)

Semantics

The "first line" (first) parameter signifies the first line.

The "last line" (last) parameter signifies the last line. Lines first and last are relative to the current alpha screen (i.e., modified by ALPHA HEIGHT). Tests are made for 0<first line<last line<=screen height, if they fail, an escape(1019) occurs.

These routines do not scroll text to/from the offscreen alpha buffer (if any) which the system uses. Instead, they clear the first or last line of the scrolling region.

The "down" (dn) parameter signifies whether to scroll up or down one line. That is, if down (dn) is false, it scrolls this area up one line.

CURSOR

IMPORT: KBDCRT

This procedure removes the previous cursor and writes a new cursor to any on-screen alpha location.

Syntax

CURSOR ( x_coordinate , y_coordinate , cursorstate )

Item Description Range
x_coordinate numeric expression of TYPE cbyte 1 thru screen width
y_coordinate numeric expression of TYPE cbyte 1 thru screen height
cursorstate expression of TYPE cursortype normal_cursor, insert_cursor, or off_cursor

Example Procedure Calls


   CURSOR(xcrd,ycrd,ctype)

   CURSOR(24,22,normalcursor)

Semantics

The "x_coordinate" (xcrd) and "y_coordinate" (ycrd) specify the on-screen alpha location of the cursor from the upper left corner of the alpha CRT area (affected by ALPHA HEIGHT).

Any system action which moves the cursor will overwrite the action of this procedure. This includes any key press if not trapped by ON KBD. The programmer must take this into account in using this feature.

The possible values of "cursorstate" (ctype) are normal_cursor, insert_cursor, and off_cursor.

DISP_AT_XY

IMPORT: KBDCRT

This procedure writes text to any on-screen alpha location.

Syntax

DISP_AT_XY ( x_coordinate , y_coordinate , bufstring , parseflag , enhancee )

Item Description Range
x_coordinate numeric expression of TYPE cbyte 1 thru screen width
y_coordinate numeric expression of TYPE cbyte 1 thru screen height
bufstring expression of TYPE

kbd_string __ packed record len: word; c: packed array [1..256] of char; end;

within range of kbd_string
parseflag numeric expression of TYPE boolean true or false
enhance expression of TYPE enh_type __packed record color : cbyte; hilite : cbyte; end; within range of enhtype

Example Procedure Calls


   DISP_AT_XY(xcrd, ycrd, var_str, parse, var_enhc)

   DISP_AT_XY(22, 34, strrecord, tf, enhcrecord)

Semantics

disp_at_xy can be used to put characters anywhere on the screen including the areas which are normally the keyboard lines, key labels, etc. This does not put those characters into the keyboard buffer, or any other internal buffer related to those areas. Specifically, it does not do an OUTPUT KBD. They will, however, be re-displayed by a GCLEAR on a bit-mapped display.

The "x_coordinate" (xcrd) and "y_coordinate" (ycrd) specify the on-screen alpha location of the cursor from the upper left corner of the alpha CRT area (affected by ALPHA HEIGHT). Characters will be wrapped at the alpha CRT width (not necessarily the PRINTER IS;WIDTH). A check is made for strings which would run off the end of the display. Out of range values of x and y are mapped to 1,1 and strings that are too long are truncated.

The "parseflag" (parse) parameter indicates whether characters in the range 128..143 are to be interpreted as highlights or displayed as characters. It also affects the display of characters 144..159; characters 0..31 are always displayed.

The "bufstring" (var_str) parameter contains the text to be written to the screen.

The "enhance" (var_enhc) parameter specifies the color and highlights for the text. It should be initialized to an appropriate value. However, internal color values for ALPHA PEN 1..7 may be different from the user specified value. For ALPHA PENs above 7 the value of color is the pen number. The highlight values are also encoded. The simplest way to initialize enhc for highlights and for colors less than 8 is to set parseflag to true and print a string with characters in the range 128..143. Then the correct values will be returned in the var parameter var_enhc.

For monochrome displays, the color byte is ignored.

READ_KBD

IMPORT: KBDCRT

This function returns the buffer contents trapped and held by ON KBD (same as KBD$).

Syntax

READ_KBD

Example Function Calls


   READ_KBD

Semantics

You must execute an ON KBD statement before calling the CSUB. Then any calls to the function read_kbd will return the same data as a call to the BASIC function KBD$ would. Calling this function also clears the KBD$ buffer. Use of this function allows you to poll the keyboard for input while in the CSUB. For the best results, include the ,ALL option in the ON KBD statement. Otherwise, a closure key, such as a typing-aid, causes the keyboard to block until an end-of-line occurs. This will not happen in the CSUB.

NOTE
Closure keys are system-function keys (as opposed to ASCII-character keys) which are logged and subsequently processed by the BASIC system and therefore, normally "close" subsequent keyboard inputs to the system until fully processed. For further information, see the "Keyboard" chapter of the HP BASIC 6.2 Interface Reference manual.

SCROLLDN

IMPORT: KBDCRT

This procedure scrolls the PRINT area of the CRT down one line.

Syntax

SCROLLDN

Example Procedure Calls


   SCROLLDN

SCROLLUP

IMPORT: KBDCRT

This procedure scrolls the PRINT area of the CRT up one line.

Syntax

SCROLLUP

Example Procedure Calls


   SCROLLUP

STATUSCRT

IMPORT: KBDCRT

This function returns the contents of a CRT status register.

Syntax

STATUSCRT ( register ) number

Item Description Range
register number numeric expression of TYPE cbyte 0 thru 21

Function Heading


   FUNCTION STATUSCRT (reg:cbyte) : cword;

Example Function Calls


   St_reg := STATUSCRT(reg_no);

   IF STATUSCRT(13) = 9 THEN CONTROLCRT (13,18);

Semantics

The "register number" (reg_no) parameter designates the register to be read. Refer to the "CRT Status and Control Registers" section in the HP BASIC Language Reference for more information.

This function will escape with a BASIC errorcode if an illegal argument is given. The value will be such that errorcode MOD 1000 = 401 is true.

STATUSKBD

IMPORT: KBDCRT

This function returns the contents of a keyboard status register.

Syntax

STATUSKBD ( register ) number

Item Description Range
register number numeric expression of TYPE cbyte 0 thru 17 except for 3 and 4

Function Heading


   FUNCTION STATUSKBD (reg:cbyte) : cword;

Example Function Calls


   Str_reg := STATUSKBD(reg_no);

   Fn_key := STATUSKBD(2);

Semantics

The "register number" (reg_no) parameter designates the register to be read. Refer to the "Keyboard Status and Control Registers" section in the HP BASIC Language Reference for more information.

This function will escape with a BASIC errorcode if an illegal argument is given. The value will be such that errorcode MOD 1000 = 401 is true.

SYSTEMD

IMPORT: KBDCRT

This function returns a string containing the same results (system status and configuration information) as executing SYSTEM$ with the given argument.

Syntax

SYSTEMD ( argument )

Item Description Range
argument string expression of TYPE STRING[18] (string_18) any valid SYSTEM$ argument

Function Heading


   FUNCTION SYSTEMD (Request: string_18): string_160;

Example Function Calls


   Some_thing := SYSTEMD (arg)

   Or_other := SYSTEMD ("AVAILABLE MEMORY")

Semantics

The "argument" (arg) is the string containing the argument for the BASIC SYSTEM$ function. If the argument is invalid, the result returned is the string "ERROR 401" (i.e., the function does not escape). The value returned is of TYPE STRING[160].

This provides Security Module and ID PROM access plus many other capabilities. Refer to SYSTEM$ in the HP BASIC Language Reference for further information.