Code: Select all
PROCEDURE BITS(i: INTEGER): SET;
Code: Select all
BITS(i) = SYSTEM.VAL(SET, i)
ORD(BITS(i)) = i
BITS(ORD(s)) = s
For example, in the Astrobe library procedure Serial.SetFormat, to modify the wordlength in the ULCR register we have to clear the six least significant bits of ULCR and replace them with the integer value: (wordlength - 5). In earlier versions of Astrobe, one way to do this would be to write:
Code: Select all
PROCEDURE SetFormat*(wordLength, stopBits: INTEGER; parity: SET);
VAR
ULCR: SET;
BEGIN
SYSTEM.GET(MCU.U0LCR, ULCR);
ULCR := ULCR - {0..5} + parity + SYSTEM.VAL(SET, (wordLength - 5));
Code: Select all
ULCR := ULCR - {0..5} + parity + BITS(wordLength - 5);
The following examples show the use of BITS with a constant value and the equivalent SET constants:
Code: Select all
BITS(0) = {}
BITS(1) = {0}
BITS(3) = {0, 1}
BITS(0FFFFFFFFH) = {0..31}