Q(uick)BASIC Statement: WAIT
Quick View
WAIT
A control flow statement that suspends program execution while monitoring the status of a machine input port
Worth knowing
Useful and cross-version information about the programming environments of QBasic and QuickBasic.
Syntax
- WAIT portnumber%, AND-expression% [,XOR-expression%]
Description/Parameter(s)
portnumber% | The number of the input port. |
AND-expression% | An integer expression that WAIT combines with the bit pattern value using an AND operator. When the result is nonzero, WAIT stops monitoring the port. |
XOR-expression% | Can be used to turn line bits on and off in the bit pattern before the AND operation is applied. |
Example
'Reads the interrupt controller port address &H20.
'Press any key to continue.
WAIT &H20, 1
See also:
Syntax
- WAIT portnumber,and-expression[,xor-expression]
Description/Parameter(s)
Argument | Description |
portnumber | An integer expression in the range 0-255 that is the number of the port |
and-expression | An integer expression combined with data from the port through an AND operation |
xor-expression | An integer expression combined with data from the port using an XOR operation |
The WAIT statement suspends execution until a specified bit pattern is read from a designated input port. The data read from the port is combined, using an XOR operation, with xor-expression, if it appears. The result is then combined with the and-expression using an AND operation. If the result is zero, BASIC loops back and reads the data at the port again. If the result is nonzero, execution continues with the next statement. If xor-expression is omitted, it is assumed to be 0. XXX,
Warning
- It is possible to enter an infinite loop with the WAIT statement if the input port fails to develop a nonzero bit pattern. In this case, you must manually restart the machine.
The following example program line illustrates the syntax of the WAIT statement:
WAIT HandShakePort, 2
This statement will cause QuickBASIC to do an AND operation on the bit pattern received at DOS I/O port HandShakePort with the bit pattern represented by 2 (00000010).
Syntax
- WAIT portnumber, and-expression% [,xor-expression%]
Description/Parameter(s)
portnumber | An unsigned integer expression between 0 and 65,535, inclusive, that is the number of the machine input port. |
and-expression% | An integer expression that is repeatedly combined with the bit pattern received at the port, using an AND operator; when the result is nonzero, the WAIT statement stops monitoring the port, and program execution resumes with the next program statement. |
xor-expression% | Can be used to turn bits on and off in the received bit pattern before the AND operation is applied. |
The WAIT statement is not available in OS/2 protected mode. |
Usage Notes
- The WAIT statement is an enhanced version of the INP function; it suspends execution until a specified bit pattern is input from an input port:
- The data byte read from the port is combined, using an XOR operation, with xor-expression%. If xor-expression% is omitted, it is assumed to be 0.
- The result is combined with and-expression% using an AND operation.
- If the result is zero, the first two steps are repeated.
- If the result is nonzero, execution continues with the next program statement.
- It is possible to enter an infinite loop with the WAIT statement if the input port fails to develop a nonzero bit pattern. In this case, you must manually restart the machine.
- The following example program line illustrates the syntax of the WAIT statement:
- WAIT HandShakePort, 2
Example
This example uses the WAIT statement to suspend program execution whilemonitioring the status of COM1.
Note: To run this program, you must have an ASCII terminal connected toCOM1 at 9600 baud, 8 data bits, 1 stop bit, and no parity.
CLS
'Open and close the port at the proper baud rate.
OPEN "COM1:9600,N,8,1,BIN" FOR RANDOM AS #1
CLOSE #1
PortNum% = &H3F8 'COM1
NonPrintCharMask% = 96
'Wait until there's some activity on COM1.
'Mask out characters less than 32 for the first input character.
LOCATE 12, 15: PRINT "Waiting for a printable input character. "
WAIT PortNum%, NonPrintCharMask%
'Once a printable character comes in, accept all characters.
DO
'Get a character from the port.
A% = INP(PortNum%)
'Evaluate the character.
SELECT CASE A%
CASE 7
Character$ = " BELL "
CASE 8
Character$ = "BACK SPACE "
CASE 9
Character$ = " TAB "
CASE 13
Character$ = " CR "
CASE 32
Character$ = " SPACE "
CASE 127
Character$ = " DEL "
CASE IS < 31, IS > 127
Character$ = "unprintable"
CASE ELSE
Character$ = SPACE$(5) + CHR$(A%) + SPACE$(5)
END SELECT
LOCATE 12, 15
'Report the input character.
PRINT "Numeric Value ASCII Character"
LOCATE 14, 20
PRINT A%; TAB(50); Character$
IF A% > 127 THEN STOP
LOCATE 23, 25
PRINT "Press ANY key to quit."
LOOP WHILE INKEY$ = ""
END
See also: