LOCATED AT
A module variable can include LOCATED AT to indicate that it is stored at a specific memory address. For example, here are two BYTE variables located at I/O addresses $D0_0300 and $D0_0301:
MODULE IO
. . .
# PALIX VIDEO SYSTEM
VAR BACKGROUND_COLOR: BYTE LOCATED AT $D0_0300
VAR MATTE_COLOR: BYTE LOCATED AT $D0_0301
. . .
END MODULE
Example usage:
MODULE MAIN
FUNC START()
# STORE A BYTE AT MEMORY ADDRESS $D0_0300;
# THE BACKGROUND COLOR CHANGES TO GREEN (#19)
19 -> IO:: BACKGROUND_COLOR
END FUNC
END MODULE
It is possible for two variables to be mapped to the same location. As a hypothetical example, we could also define:
MODULE EXAMPLE
VAR COMBINED_COLOR: PAIR LOCATED AT $D0_0300
END MODULE
Reading EXAMPLE::COMBINED_COLOR would read both bytes into a 16-bit PAIR variable. BACKGROUND_COLOR would be in the high bits, and MATTE_COLOR would be in the low bits.
Rules for LOCATED AT
Rules that the compiler enforces for LOCATED AT:
- The
LOCATED ATvariable must be a member of aMODULE, not aCLASS. - If the variable has an array or class type, it must be marked as INSET.
- If the variable has a class type, the class must not have a vtable.
- The address must be in the RAM segment or I/O segment. (This restriction may be relaxed in the future.)
- If the
LOCATED ATaddress is in the RAM segment, then the variable must have a caret type; for any other address, it must not have a caret type.