[Prev] [Next] [Contents] [Commodore] [New] [Search] [Home]


TYPE: Statement
FORMAT: WAIT <location>,<mask-1>[,<mask-2>]

Action: The WAIT statement causes program execution to be suspended until a given memory address recognizes a specified bit pattern. In other words WAIT can be used to halt the program until some external event has occurred. This is done by monitoring the status of bits in the input/ output registers, The data items used with WAIT can be any numeric expressions, but they will be converted to integer values. For most programmers, this statement should never be used. It causes the program to halt until a specific memory location's bits change in a specific way. This is used for certain I/O operations and almost nothing else.

The WAIT statement takes the value in the memory location and performs a logical AND operation with the value in mask-1. If there is a mask-2 in the statement, the result of the first operation is exclusive-ORed with mask-2. In other words mask-1 "filters out" any bits that you don't want to test. Where the bit is 0 in mask-1, the corresponding bit in the result will always be 0. The mask-2 value flips any bits, so that you can test for an off condition as well as an on condition, Any bits being tested for a 0 should have a I in the corresponding position in mask-2.

If corresponding bits of the <mask-1> and <mask-2> operands differ, the exclusive-OR operation gives a bit result of 1. If corresponding bits get the same result the bit is 0. It is possible to enter an infinite pause with the WAIT statement, in which case the <RUN/STOP> and <RESTORE> keys can be used to recover. Hold down the <RUN/STOP> key and then press <RESTORE>. The first example below WAITs until a key is pressed on the tape unit to continue with the program. The second example will WAIT until a sprite collides with the screen background.

EXAMPLES of WAIT Statement:
   WAIT 1,32,32
   WAIT 53273,6,6
   WAIT 36868,144,16         (144 & 16 are masks. 144=10010000 in binary
                              and 16=10000 in binary. The WAIT statement
                              will halt the program until the 128 bit is
                              on or until the 16 bit is off)

[Prev] [Next] [Contents] [Commodore] [New] [Search] [Home]
This page has been created by Sami Rautiainen.
Read the small print. Last updated November 15, 1998.