Open agg23 opened 3 years ago
I guess the compiler should warn about it, but initialization of variables on ROM-based targets requires manual handling right now: https://karols.github.io/millfork/api/rom-vs-ram.html
In your case, it should just be enough to call init_rw_memory()
near the beginning of the program.
Interesting. Good to know that exists. What is the rationale behind not running it immediately on start?
It lets you defer it for later if you want to do some hardware initialization beforehand, and also it is in line with Millfork's "middle-level language" philosophy. It also has bonus points of being able to reset your program's memory with a single line of code (as you can call init_rw_memory()
whenever you want as many times you want).
Currently, Millfork is not designed to have any kind of runtime, it just goes straight to your main function in the simplest and fastest way necessary. In comparison, C runtime does many things like memory initialization before it finally calls main.
The compiler allows you to initialize a global variable with a literal:
const byte test = 1
, but doesn't actually generate any code to initialize those variables on program start.Built with
java -jar millfork.jar main.mfk -o build/rom.nes -t nes_small -g -s -fsource-in-asm -fillegals