DEBRO Posted April 9, 2003 Share Posted April 9, 2003 Does the 6502 restore the status flags after it returns from an interrupt? Lets say you're in a loop... .doSomething lda (somePageValue),y sta (newPageValue),y dey bpl .doSomething and the interrupt happes right after the dey. When you come back if the status flags have changed you could get strange results. 2600 programmers don't have to worry too much about this since there are no interrupts (neglecting BRK and location $285). But what of programmers that utilize a true 6502 CPU? Just curious Quote Link to comment Share on other sites More sharing options...
Cybergoth Posted April 9, 2003 Share Posted April 9, 2003 Hi Dennis! Does the 6502 restore the status flags after it returns from an interrupt? Quick answer: Yes Longer Answer: When an interrupt occurs, this happens: - The MSB of the PC is pushed onto the stack - The LSB of the PC is pushed onto the stack - The status flags are pushed onto the stack - The interrupt flag is set - The interrupt vector is loaded into the PC - The interrupt code is executed Ending the interrupt code properly with RTI will pull the three values from the stack and restore everything exactly as it was when the interrupt occured. Greetings, Manuel Quote Link to comment Share on other sites More sharing options...
Nukey Shay Posted April 9, 2003 Share Posted April 9, 2003 When you RTI the processor status is automatically fetched from the stack. Quote Link to comment Share on other sites More sharing options...
Wrathchild Posted April 9, 2003 Share Posted April 9, 2003 Yep, the 6502 handles this, an interrupt causes the status register to be pushed to the stack and then when an RTI is executed, this is popped. On the 4/6/8/XL/XE family, if you use the OS hooks for VBI's (vertical blank interrupts) then the saving of A,X and Y are done for you, wheras you must always restore them in a DLI (display list interrupt). Rgds, Mark Quote Link to comment Share on other sites More sharing options...
DEBRO Posted April 9, 2003 Author Share Posted April 9, 2003 Thanks for the quick response guys. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.