Closed Skertan closed 1 year ago
Strangely enough that works for X16:
My fault. I've playing with the memory manager in the trunk version. It's updated now. However there's still a problem: Commodore64 defines some free bytes in the zero-page and the compiler is locating variable "c" in that free space. And, formally, variables that are out of the main program block (starts at $0801) cannot be initialized that way.
One simple solution could be including the directive {$SET_DATA_ADDR ''} after the USES section so we force to not use the bytes from zero page:
Other solution could be to modify the Commodore64 unit.
I put {$SET_DATA_ADDR ''} and it works. Does it have some side effects, since the original value defines a few bytes from zero page. If there are no side effects this should be the standard in the included Commodore64.pas in the repository.
At the moment compiler can work well without using zero-page. Even when using arrays, compiler generates self-modified binary code to work. But in the future it will be needed to have some zero-page to implement some routines. Moreover, having some bytes in zero-page gives the code some extra speed. And compiler uses it to allocate registers or temporal values. I think it's useful.
Maybe you can use {$SET_DATA_ADDR ''} and if you want some zero-page variables you can use "ABSOLUTE" variable declaration or "ZEROPAGE" variable declaration (Not yet implemented). However, I cannot promise compiler won't need, in the future, some bytes from zero-page. As we know the 6502 CPU is very dependent of the zero-age.
Yes, ZeroPage variables reduce the generated code and increase the performance.
In order to avoid current problems with the compiler, you may put the initialized variable at the end of declarations. This way there is big chance the earlier declared variable to "deplete" ZeroPage, so initialized ones will be in $80D+ space. Of course that is very program depended and no 100% guarantee that will happen.
There is new mode to assign RAM to variables (Recently created to help on implementing Pointers). It is called "decDatSec" and it assures the variable is allocated in the code section. Sadly, it's not accessible from PASCAL. It could be added as: VAR c: char DATASECTION; Currently there is only ABSOLUTE, and in the future ZEROPAGE attribute for declaring variables. Anyway I don't want to invent new reserved words, because that's not the Pascal spirit. Maybe the best solution will be just not to locate variables initialized in the zero page.
It's fixed.
Compiler now force initialized variables to be located in the Data Section, close to the Code section, so they won't use the location defined by {$SET_DATA_ADDR}, and will be able to be initialized.
Error: Cannot initialize absolute variable "c" in location $80D.