Jump to content
IGNORED

6502 question(s)


OldGuru

Recommended Posts

What is the limit of nested subroutines in the 6502 on the 5200?

 

What do I mean?

In some cases, I have my main code jumping to a subroutine, this subroutine calls another one and so on... The uP has to retain the return address of each JSR. I'd assume that it stores these addresses (and what else?) in the Stack (where is the stack located on the 5200?). How many memory location does each JSR take ?

 

Now, if the Stack is located in the memory such that it overwirtes some program variables, the code execution will be corrupted...

 

How does that work on the emulators? Where is the stack located? Is there a "different" memory location for the JSR return address than the stack?

 

...and, yes, there are quite a few questions here but an answer to any of them could help...

 

Thank you,

OldGuru.

Link to comment
Share on other sites

Ok, so to make things a bit more complicated: If there are JMP instructions in various routines, the address will not be restored, right?

So, if instead of using RTS, I'd use JMP (back to a place I'd want) the stack can overflow... Is that right?

 

Not that I do that in my code, I just try to understand the limits...

 

The actual reason that I posted my questions is that after adding some more features to my game, the text area on the screen gets corrupted... That happend on the real console but not on VSS (0.7)... Still have no idea why...

 

Thanks,

OG

Link to comment
Share on other sites

By the way...

Most of my programming experience is from hacking into games and adding my own little routines to them (as in "combo this, cheatin' cpu!")...so I had used branching instructions much more often in place of JSR's or JMP's (in an attempt to keep my routines as relocateable as possible). You might want to try them for short interruptions to the routines.

Also, 2 PLA instructions will remove only the last stored return address. If you wanted to kill off the previous return address but keep the current one intact, you would need to PLA TAX PLA TAY PLA PLA TYA PHA TXA PHA...pretty messy, isn't it? And you can seriously muck things up when manipulating the stack in this manner...so it's best to try to build the routines as straight as possible from the start rather than wedging stuff in later.

Link to comment
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...