We've just updated MediaWiki and its underlying software. If anything doesn't look or work quite right, please mention it to us. --RanAS

RTI: Difference between revisions

From SnesLab
Jump to: navigation, search
(→‎Syntax: linkify E&L)
 
(45 intermediate revisions by the same user not shown)
Line 7: Line 7:
|'''Speed'''
|'''Speed'''
|+
|+
|stack
|[[Stack Addressing | Stack]] (RTI)
|40
|40
|1 byte
|1 byte
|6 cycles
|7 cycles*
|}
|}


{| class="wikitable" style="float:right;clear:right;width:30%"
{| class="wikitable" style="float:right;clear:right;width:30%"
!colspan="9"|Flags Clobbered
!colspan="9"|Flags Affected
|+
|+
|
|[[N Flag|N]]
|[[V Flag|V]]
|[[M Flag|M]]
|[[X Flag|X]]
|[[D Flag|D]]
|[[I Flag|I]]
|[[Z Flag|Z]]
|[[C Flag|C]]
|+
|[[65c816 native mode]]
|N
|N
|V
|V
Line 25: Line 36:
|C
|C
|+
|+
|
|[[6502 emulation mode]]
|
|N
|
|V
|
|.
|
|.
|
|D
|
|I
|
|Z
|C
|}
|}


'''RTI''' (Return from INterrupt) is a 65x instruction used to return control from an [[interrupt handler]].
'''RTI''' (ReTurn from Interrupt) is a 65x instruction used to return control from an [[interrupt handler]]. It does this by first pulling the [[status flags]] off of the [[stack]] and then the [[program counter]] too.  In native mode, the [[program bank register]] is pulled after that for a total of 4 bytes.  In emulation mode, 3 bytes are pulled.
 
==== Syntax ====
<pre>
RTI
</pre>
 
Figure 18.10 on [https://archive.org/details/0893037893ProgrammingThe65816/page/493 page 493] of [[Eyes & Lichty]] has the old status register diagrammed as being four bytes deeper than the top of the stack before RTI, but the text on the previous page (and the bsnes source code) have the status register being pulled first.
 
==== Pitfalls ====
* RTI should only be run when the [[e flag]] is in the same state as when the interrupt fired
* RTI cannot even tell whether the interrupt actually occurred or not
* RTI does not increment the program counter after pulling it like [[RTS]] and [[RTL]] do
 
==== Cycle Skipped ====
RTI takes one fewer cycle in [[emulation mode]] as the [[program bank register]] doesn't need to be pulled from the [[stack]].
 
[[File:rti.png]]


=== See Also ===
=== See Also ===
* [[BRK]]
* [[RTS]]
* [[RTS]]
* [[RTL]]
* [[RTL]]
* [[RETI]]
* [[PLP]]


=== External Links ===
=== External Links ===
* [[Eyes & Lichty]] page on RTI: https://archive.org/details/0893037893ProgrammingThe65816/page/n518
* [[Eyes & Lichty]], [https://archive.org/details/0893037893ProgrammingThe65816/page/492 page 492] on RTI
* [[Labiak]] page on RTI: https://archive.org/details/Programming_the_65816/page/n186
* [[Labiak]], [https://archive.org/details/Programming_the_65816/page/n186 page 176] on RTI
* [[MCS6500 Manual]] page on RTI: https://archive.org/details/mos_microcomputers_programming_manual/page/n152
* 9.6 on [[MCS6500 Manual]], [https://archive.org/details/mos_microcomputers_programming_manual/page/n152 page 132] on RTI
* [[Carr]] page on RTI: https://archive.org/details/6502UsersManual/page/n283
* [[Carr]], [https://archive.org/details/6502UsersManual/page/n283 page 270] on RTI
* [[Leventhal]] page on RTI: https://archive.org/details/6502-assembly-language-programming/page/n138
* [[Leventhal]], [https://archive.org/details/6502-assembly-language-programming/page/n138 page 3-89] on RTI
* snes9x implementation of RTI: https://github.com/snes9xgit/snes9x/blob/master/cpuops.cpp#L3272
* snes9x implementation of RTI: https://github.com/snes9xgit/snes9x/blob/master/cpuops.cpp#L3272
* undisbeliever on RTI: https://undisbeliever.net/snesdev/65816-opcodes.html#rti-return-from-interrupt
* undisbeliever on RTI: https://undisbeliever.net/snesdev/65816-opcodes.html#rti-return-from-interrupt
* Pickens, John. http://www.6502.org/tutorials/6502opcodes.html#RTI
* Clark, Bruce. http://www.6502.org/tutorials/65c816opcodes.html#6.3.2
* lbid, APPENDIX: EMULATION MODE, http://www.6502.org/tutorials/65c816opcodes.html#APPENDIX:


[[Category:ASM]]
[[Category:ASM]]
[[Category:Inherited from 6502]]
[[Category:Inherited from 6502]]
[[Category:Unconditional Branches]]
[[Category:One-byte Instructions]]
[[Category:Single Admode Mnemonics]]

Latest revision as of 01:19, 20 September 2024

Basic Info
Addressing Mode Opcode Length Speed
Stack (RTI) 40 1 byte 7 cycles*
Flags Affected
N V M X D I Z C
65c816 native mode N V M X D I Z C
6502 emulation mode N V . . D I Z C

RTI (ReTurn from Interrupt) is a 65x instruction used to return control from an interrupt handler. It does this by first pulling the status flags off of the stack and then the program counter too. In native mode, the program bank register is pulled after that for a total of 4 bytes. In emulation mode, 3 bytes are pulled.

Syntax

RTI

Figure 18.10 on page 493 of Eyes & Lichty has the old status register diagrammed as being four bytes deeper than the top of the stack before RTI, but the text on the previous page (and the bsnes source code) have the status register being pulled first.

Pitfalls

  • RTI should only be run when the e flag is in the same state as when the interrupt fired
  • RTI cannot even tell whether the interrupt actually occurred or not
  • RTI does not increment the program counter after pulling it like RTS and RTL do

Cycle Skipped

RTI takes one fewer cycle in emulation mode as the program bank register doesn't need to be pulled from the stack.

rti.png

See Also

External Links