I am trying to switch normal program flow while an interrupt returns:
START
SEI
LDX #<IRQ
LDY #>IRQ
STX $FFFE
STY $FFFF
CLI
LOOP1
INC $D020
JMP LOOP1
LOOP2
INC $D021
JMP LOOP2
IRQ
STA SAVEA+1
STX SAVEX+1
STY SAVEY+1
// Some Routines
LDA #$00
PHA
LDA #<LOOP2
PHA
LDA #>LOOP2
PHA
SAVEA
LDA #$00
SAVEX
LDX #$00
SAVEY
LDY #$00
RTI
I wrote this code accourding to that source: http://6502.org/tutorials/interrupts.html#1.3

But PHA's cause crash, how to switch normal flow LOOP1 to LOOP2 in an interrupt?
The simplest thing is probably to have two stack areas -- one for every task. $100-$17f and $180-$1ff, for example. Then, you would have your interrupt task switching code like this:
pha
txa
pha
tya
pha ;saving task's registers on its stack,
;where flags and PC are already saved
;by entering the interrupt
tsx
stx ... ;save task's stack position
... ;select new task to run/etc.
ldx ...
txs ;load other task's stack position
pla
tay
pla
tax
pla ;restore other task's registers
rti ;and finally continue other task
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With