base:launching_long_tasks_from_irq_handler
This is an old revision of the document!
Launching long tasks from inside a IRQ handler
When executing code within an IRQ handler you have to finish things before the next IRQ occurs. But sometimes tasks just take some more time, for that you can spin off those tasks from inside the handler, and allow then upcoming IRQs to happen. When the IRQ handler is finished it would fetch 3 bytes from stack and return to the code that was interrupted by the IRQ. Here we squeeze in our new task by adding another 3 bytes to the stack. Thus before continuing with the interrupted code our new task will be executed first.
irq ;save registers sta register_a stx register_x sty register_y ;... your desired irq handler code goes here ;now push 3 more bytes on stack lda #>task pha lda #<task pha ;flags, can even be used to signal stuff to task by setting carry/overflow/negative/... lda #$00 pha lda register_a sta register_a_ ldx register_x stx register_x_ ldy register_y sty register_y_ ;rti will now finish this interrupt and continue with the new task instead of the code ;being executed before this IRQ occurred. rti task ;...some code ;restore registers lda register_a_ ldx register_x_ ldy register_y_ ;now finally continue with code being executed before IRQ rti
base/launching_long_tasks_from_irq_handler.1429237954.txt.gz · Last modified: 2016-02-02 20:08 (external edit)