Jump to content
IGNORED

6502 interrupt question


DEBRO

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

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...