-
Notifications
You must be signed in to change notification settings - Fork 2
Relocation Directives
The Language Reference - Relocation Directives
Relocation directives affect what memory area of ROM to write to or where to reserve RAM, and as a side-effect, will affect what locations that labels will end up pointing to. These become fairly important, because they set the locations in ROM for code and data statements, and addresses to maintain for variable definitions.
Relocation can be accomplished by in bnk, position:
where bnk is the name of a program bank to choose (which must be previously defined with one of your bank definitions), and position is the place to start the program counter within that bank. position is an unsigned 16-bit expression in the range 0 .. 65535
, is an unsigned 16-bit expression in the range 0 .. 65535
, which must be greater than the current position for this bank (You cannot move backwards in a bank).
A bank has no position by default, so the first position becomes its origin point. After that contiguous space between origin .. origin + size
becomes available to the bank.
To switch to a bank, but not change the location in the bank, just do in bnk:
and it will use the last position. Note that the bank must have been set a position previously for this to be useful.
Here is an example of some relocation being utilized:
bank ram : ram[2048]
bank code, data : prg[8192]
in ram, 0x00:
var playerX, playerY : word
in ram, 0x200:
var sprite_data : byte[256]
in code, 0xC000:
def reset:
// ... code here
def nmi:
// ... code here
def irq:
// ... code here
in data, 0xE000:
def text: byte: 'Hello world!\n', 0
in data, 0xFFFA:
word: nmi, reset, irq