Jul 22, 2013

Man, I'm a slow learner.

If I actually read through all of the NESDev Wiki (it's pretty thorough), I'd have learned long ago that on the NES the RAM offsets $0100 through $01FF are for the stack. I'd have learned that before I noticed it in Ninja Gaiden 3. I would have also learned that the JSR routine writes the current PRG-ROM offset to the stack and then the RTS routine retrieves the values from the stack. All this time I was seeing weird code (to me it was weird) like:

PLA
PLA

I was like, "Why the heck are they retrieving from the stack and then discarding the values?" While reworking some of my Trevor code (for the umpteenth time... Wow, spellchecker recognized 'umpteenth'!), I noticed an RTS didn't redirect me to where I thought it would. I then noticed that odd code and looked at the values being retrieved -- it was the RAM offset of the JSR routine.

I'd always wondered how the NES knew where to go when RTS was used. It never occurred to me to look at the stack. I always thought it was just for storing variables to be used at a later time.

No comments:

Post a Comment

©TheouAegis Productions™. Powered by Blogger.