Updating variables when compiling as ROM

Gilbert François Duivesteijn

< Back to main page

When your program is compiled for cartridge as ROM, you cannot change values of variables in this memory area. For example:

Compile with VASM

or with Glass (you can choose)

This example won't work. The memory of MyVar lies inside the ROM. Let's look at the debugger and see what is happening. Pay special attention to memory location $4018, where MyVar is located.


In the section Memory layout of the debugger, we can see that page 0 and 1 are reserved for the ROM:


Our ORG address is $4000 and MyVar is located at $4018. Since this is still in ROM area, the memory content is read-only. The solution is to store the variables or anything that needs to be manipulated in memory, in RAM area. Page 2 and 3 are RAM. There are several ways to do that in code. However, most methods are assembler specific. The standard syntax that works with all assembers is by simply specifying the address as constant, e.g:MyVarRam equ $c000. The new listing is:

First, we copy the initial values from ROM to RAM (when needed). Then we continue our original program, and can successfully change values in MyVarRam. You can see in the debugger that the increase of the value is successful.


Final words....

When you have many variables, lists or other data, you can declare them as follows: