nesdev.com
http://forums.nesdev.com/

Saving A, X and Y in an interrupt: With PHP?
http://forums.nesdev.com/viewtopic.php?f=2&t=16877
Page 1 of 1

Author:  DRW [ Sat Dec 30, 2017 1:01 pm ]
Post subject:  Saving A, X and Y in an interrupt: With PHP?

During an interrupt, I do this:

Code:
PHA
TXA
PHA
TYA
PHA

; Regular code.
; ...

PLA
TAY
PLA
TAX
PLA

Now I've seen an example where the last command before the regular code is PHP and the first command after the regular code is PLP (push and pull procssor status).

Is this necessary? Why? Why not?

Author:  pubby [ Sat Dec 30, 2017 1:12 pm ]
Post subject:  Re: Saving A, X and Y in an interrupt: With PHP?

Interrupts automatically push the status flags to the stack and RTI automatically pops them.

So no, you don't need to use PHP/PLP. BRK/RTI do the same plus more.

Author:  DRW [ Sat Dec 30, 2017 2:26 pm ]
Post subject:  Re: Saving A, X and Y in an interrupt: With PHP?

Thanks. That's good because I didn't do it in my previous game.

Author:  Dwedit [ Sat Dec 30, 2017 2:31 pm ]
Post subject:  Re: Saving A, X and Y in an interrupt: With PHP?

it's common to see PHP/PLP because not everyone who codes 6502 knows that interrupts and RTI instructions push and pop the flags.

Author:  Quietust [ Sat Dec 30, 2017 4:38 pm ]
Post subject:  Re: Saving A, X and Y in an interrupt: With PHP?

Even if you did do PHP/PLP, you'd want to do PHP first and PLP last so that the Z and X flags wouldn't get modified by the other instructions (TXA, TAX, TAY, TYA, and PLA all modify those flags).

Page 1 of 1 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/