6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Nov 23, 2024 3:20 pm

All times are UTC




Post new topic Reply to topic  [ 19 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: cc65 confusion...
PostPosted: Tue Mar 08, 2022 9:49 pm 
Offline

Joined: Sun May 13, 2018 5:49 pm
Posts: 255
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)?


Top
 Profile  
Reply with quote  
 Post subject: Re: cc65 confusion...
PostPosted: Wed Mar 09, 2022 12:16 am 
Offline

Joined: Thu Mar 12, 2020 10:04 pm
Posts: 704
Location: North Tejas
Windfall wrote:
echidna wrote:
I would expect the ','s to print, followed by the '!'s. Instead I get the ','s then garbage.
Any insight into what I'm doing wrong or misunderstanding about how all of this works would be greatly appreciated.

My first guess would be that something in _lcdPrint corrupts the stack (and therefore the pointer to the string of plings, which is stacked at the time).

That can be easily tested by commenting out the first call to _lcdPrint...

Divide and conquer.


Top
 Profile  
Reply with quote  
 Post subject: Re: cc65 confusion...
PostPosted: Wed Mar 09, 2022 4:25 am 
Offline

Joined: Fri Apr 15, 2016 1:03 am
Posts: 140
The CC65 documentation has detail on how to make a configuration for custom hardware: https://cc65.github.io/doc/customizing.html
There are also many supplied configurations for various systems.

When you run CC65, the "target" parameter picks the configuration to use.

Source files for all of this, and the library routines like ldaxysp is available in the CC65 distribution at http://cc65.github.io .


Since the 6502's return stack is limited to 256 bytes, CC65 maintains another software stack to keep procedure local data on.
There are many library routines like pushax, ldaxysp, & incsp2 to operate on this stack.


Top
 Profile  
Reply with quote  
 Post subject: Re: cc65 confusion...
PostPosted: Tue Mar 22, 2022 11:43 am 
Offline
User avatar

Joined: Tue Aug 11, 2020 3:45 am
Posts: 311
Location: A magnetic field
echidna on Sun 6 Mar 2022 wrote:
65SC02


I presume that's not a standard configuration. I also presume that you're attempting to run a CMOS 6502 binary on NMOS 6502.

Actually, we should start with the "digital thermometer" test. I don't care where you bought a 6502 or what it has on the label. Stick you finger ("digit") on the middle of your 6502. If it is noticeably warm then it is NMOS 6502. This lacks one addressing mode and a short, unconditional branch. When running unoptimized C, branch will be ignored. The result is that for loops and while loops may fail to iterate and else blocks may execute unconditionally. When optimized C has unrolled loops, the first byte of a string may be pre-loaded but the remainder is not fetched. This is very much like the symptoms you observe.

_________________
Modules | Processors | Boards | Boxes | Beep, Beep! I'm a sheep!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 19 posts ]  Go to page Previous  1, 2

All times are UTC


Who is online

Users browsing this forum: No registered users and 39 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: