Windfall wrote:
In general cases, a string constant (anything between double quotes) is statically allocated (clearly visible in the assembly code as well ...), i.e. it exists for the entire program run, and its type is either 'const char*' or 'char*' (depending on the implementation). There is no need here to copy it by value.
I had to double check on the scope of constant strings - I was wrong and you are right that they should be global and statically allocated.
I also agree that both constant character strings are statically allocated in the assembly code, so that part seems to be working OK. The part I'm still having issue with is that the pointer being declared has type "unsigned char *" while the constant string has type "const unsigned char *". The extra const in there allows/disallows certain optimizations. Further looking at the generated assembly makes me think this isn't the issue causing this problem, though.
The ldaxysp function being run just before the second _lcdPrint looks to me like the compiler is trying to load A and X (which we can see hold the string pointer by looking at the working call to _lcdPrint) based on Y and the stack pointer, and Y was just loaded with 1 prior to that. That looks like the compiler is trying to get that pointer from the stack (which makes sense, as the pointer in main is a local variable).
The local variables should be initialized right at the start of main, and it looks like, indeed, the address of L0004 is being pushed onto the stack right at the beginning.
I think leepivonka has the correct answer - the data stack is not being allocated to RAM properly. I believe cc65 uses a data stack that is separate from the return stack, so it's possible for the jsr/rts to work properly but the local variables to not work properly. Can you (echidna) share the cc65 config file (and a description of your memory map for your computer)?