base:quick_exit_from_interrupt
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | base:quick_exit_from_interrupt [2015-04-17 04:33] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Quick exit from a timer interrupt ====== | ||
+ | |||
+ | Written by Frantic. | ||
+ | |||
+ | I found the following trick when peeking through Mahoney' | ||
+ | |||
+ | Normally, when you exit from an interrupt, you first acknowledge the interrupt, and then execute the final rti instruction after that to return to the code that was executed before the interrupt was triggered. Acknowledging the interrupt involves reading a register, which typically takes 4 cycles: | ||
+ | |||
+ | < | ||
+ | bit $dd0d ;4 cycles - ack | ||
+ | rti ;quit interrupt routine | ||
+ | </ | ||
+ | |||
+ | ...and here comes the trick: If you set up a timer interrupt and make sure that $dd0c contains $40 (which is the byte value for the opcode rti), then you can simply quit the irq by performing a "jmp $dd0c" | ||
+ | |||
+ | So... | ||
+ | |||
+ | < | ||
+ | ;Interrupt init code | ||
+ | […] | ||
+ | lda #$40 | ||
+ | sta $dd0c ;Put an " | ||
+ | […] | ||
+ | </ | ||
+ | |||
+ | ...and: | ||
+ | |||
+ | < | ||
+ | ;Interrupt code | ||
+ | […] | ||
+ | jmp $dd0c ;3 cycles - quit interrupt | ||
+ | </ | ||
+ | |||
+ | Of course, in either case the rti will have to be executed, taking 6 cycles, but the lda can be exchanged for a jmp, thus saving once cycle. | ||
+ | |||
+ | Why not? :) | ||
base/quick_exit_from_interrupt.txt · Last modified: 2015-04-17 04:33 by 127.0.0.1