in BASIC ROM:
|List of all BASIC keywords|
Type: Command General Programming-Syntax: WAIT <Memoryadress>,<bit-1>[,<bit-2>]
WAIT is a keyword in the built-in BASIC interpreter, which waits for a given memory location to assume specific values.
Syntax[edit | edit source]
- address is a 16-bit unsigned integer designating the address to "wait for"
- mask1 and mask2 are unsigned bytes, used as parameters for the logic condition to wait for
Any address can be specified from 0 to 65535. Valid values for mask1 and mask2 may range from 0 to 255. Values outside the given ranges result in the BASIC-error ?ILLEGAL QUANTITY ERROR in line
Operation[edit | edit source]
WAIT is performed by a loop in ROM address 47166–47175/$B83E–$B847, which first reads the contents of the given address, then does a bit-wise exclusive-or with the mask2 parameter (if given), and finally a bit-wise and with the mask1 parameter. The loop will run for as long as the result of these operations yields a zero byte.
Examples[edit | edit source]
This will wait for the Commodore key to be pressed — until that happens, the "least drastic" way out of this, is to press Run/Stop + Restore. The three least significant bits in address 653 turn "on" (1) if Shift keys, the Commodore key or the Ctrl keys are pressed down at the moment; you may change the "2" at the end of the WAIT instruction to a "1" to wait for Shift keys, or a "4" to wait for the Ctrl key to be pressed.
Try this one in direct mode: When pressing the Return key after typing the command, hold the Return key down for a while, and notice how the "Ready." prompt and cursor doesn't reappear before you release. Address 203 holds the keyboard code for the key currently being pressed, or the value 64/$40 if none are pressed.
Since the keyboard codes for all keys are less than 64, bit 6 basically indicate that no key is currently pressed. To wait for a key to be pressed, this example uses the extra mask2 parameter to "invert" that bit, and wait for this "inverted" bit to indicate that a key was pressed.
If this example is given in direct mode, be sure to press and release the Return key very rapidly after typing in the command — otherwise the WAIT command will find the Return key still pressed down as it does it's loop the first time.
WAIT 1, 32, 32
(The C64 wait until a button is pressed on the datassette.)
WAIT 53273, 6, 6
(The C64 wait until a sprite has got a collosion with a char.)
WAIT 36868, 144, 16
(The C64 wait until at the memoryadress 36868 the 4th bit is deleted or
the 7th bit is set.)
POKE 198,0: WAIT 198,1
(The C64 wait until a key is pushed on the keyboard.)