Jump to content
Dave C

Stack Pointer Initialization?

Recommended Posts

Note: I'm assuming this is all old news (I can see threads about the stack on these forums and various stack manipulations in old games)... anyway...

Working through some code I've been working I realized I had a bug where I wasn't initializing the stack pointer ...In the case of the code I had written ...somehow in Stella this all turned out to somehow do what I had originally intended... so I didn't notice at first...

What I'm wondering about is if the stack is pointing at 00 (i.e., not RAM) are pha/pla going to have the same effect as lda/sta. When I wrote some test code (below) the pla and lda never return the same value. With actual hardware I assume the TIA wouldn't know/care whether an lda/pla is trying to address it...?

lda #$ff
ldx #$00
txs
pha
pla
lda $00

Share this post


Link to post
Share on other sites

Use the "CLEAN_START" macro on startup.

It does everything to set the machine into a "clean" state in only 8 bytes or so.

 

Many addresses are write-only, so I guess you'd effectively get randomness (whatever is on the data bus) when trying to read them.

Look into Stella "developer mode" for assistance in finding these sort of hard-to-find bugs.

 

Share this post


Link to post
Share on other sites

Thanks. Reading the Stella programming guide it looked like lda $00 would read CXM0P - which made me wonder if a pla (with SP of $ff) should be expected to return the same value of the lda.

Either way I'd rather use
 CLEAN_START and it will save me a few instructions - thanks!

Share this post


Link to post
Share on other sites

PLA and LDA will always return the same value if they read from the same address. 

 

CXM0P uses only two bits, the other six are undefined (but probably 0).

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...