Skip to main content

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 at variable must be a member of a module, not a class.
  • 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 at address is in the RAM segment, then the variable must have a caret type; for any other address, it must not have a caret type.