Guys ... You want to use something very important in the compiler!
#pragma zp_reserve(0x80..0xA8)
This directive ensures that you are not using zero page registers which are used by the X16, but only when not using any BASIC or floating point!
When you use BASIC or floating point, use this pragma:
#pragma zp_reserve(0x80..0xFF)
See the following extract from the manual:
This is the allocation of fixed RAM in the KERNAL/BASIC environment.
Addresses |
Description |
---|
$0000-$007F |
User zero page |
$0080-$00FF |
KERNAL and BASIC zero page variables |
$0100-$01FF |
CPU stack |
$0200-$03FF |
KERNAL and BASIC variables, vectors |
$0400-$07FF |
Available for machine code programs or custom data storage |
$0800-$9EFF |
BASIC program/variables; available to the user |
The following zero page locations are completely unused by KERNAL/BASIC/FPLIB and are available to the user:
In a machine language application that only uses KERNAL (no BASIC or floating point), the following zero page locations are also available:
This is the allocation of banked RAM in the KERNAL/BASIC environment.
Bank |
Description |
---|
0 |
Used for KERNAL/CBDOS variables and buffers |
1-255 |
Available to the user |
(On systems with only 512 KB RAM, banks 64-255 are unavailable.)
During startup, the KERNAL activates RAM bank 1 as the default for the user.
When your program is growing, (like mine), it will consume a lot of zeropage registers.
Just ensure that you use the #pragma at the start of your program, or the kernal will start consuming zero page addresses in the 80-FF space,
which basically will erase local variables you've setup, with unexpected results. I had this problem and just could not understand why.
(when my program got bigger i only got into this problem).
But i started to debug the zeropage and saw that the kernal was overwriting some of the local variables (file I/O kernal routines), which were allocated at zero page $8D ...
So, hopefully you'll see this message and you'll take note!
It took me 3 weeks to get to this understanding ... I also have seen that the vera card lib additions are using a lot of zero page addresses, so i need to recode some of the variables.