I/O CONTROL: KEYBOARD READ (BIT DECODING SCANSHIFT)

This example will show the various way that are allowed in order to check if a specific (shift) bit is on or off. The first is by using the BIT function, that check for a specific bit. The second is using the keywords BIT...OF, that is a synonym of the previous function. Finally, we show the use of conditions HAS BIT and IS, that checks for specific bitmask.

source compile sandbox issues? back to examples

SOURCE CODE ()

    CLS

    DO

        HOME

        PRINT SCANSHIFT
        
        left = BIT( SCANSHIFT, LEFT SHIFT )
        PRINT "LEFT IS: ";left
        
        left = BIT LEFT SHIFT OF SCANSHIFT
        PRINT "LEFT IS: ";left
        
        IF SCANSHIFT HAS BIT LEFT SHIFT THEN : PRINT "LEFT" : ENDIF
        IF SCANSHIFT IS LEFT SHIFT THEN : PRINT "LEFT" : ENDIF
        
        IF SCANSHIFT HAS NOT BIT LEFT SHIFT THEN : PRINT "NOT LEFT" : ENDIF
        IF SCANSHIFT IS NOT LEFT SHIFT THEN : PRINT "NOT LEFT" : ENDIF

    LOOP

How to compile and run the example

The instructions here refer to compiling the example from the command line. For Microsoft Windows users we suggest using UGBASIC-IDE, which allows you to download and compile each single example with just one click.



Are instructions for your specific home computer / console missing? First of all, check if your computer is supported by clicking here. If so, since ugBASIC is a language which does not provide abstractions, it is possible that this example will not work on your target. If you think this is an issue, please click here.

Commodore 128 (CPU 8502)

In order to compile the example, type this command on the command line:

Linux

ugbc.c128 -O prg -o controls_keyboard_05.prg controls_keyboard_05.bas

Windows

ugbc.c128.exe -O prg -o controls_keyboard_05.prg controls_keyboard_05.bas

For Microsoft Windows users we suggest using UGBASIC-IDE, which allows you to download and compile this example with just one click.

Any problem?

If you have found a problem trying to run this example, if you think there is a bug or, more simply, you would like it to be improved, open an issue for this example on GitHub.
Thank you!

open an issue BACK TO EXAMPLES