For multiple stacks, I like using the MMUs page 1 redirection. It works fine as long as you don't try to relocate the stack into Bank 1. Then it will fail with the default Common RAM in low memory (for some reason, the generic Common RAM settings over-ride the specific bank setting for page relocation)
It isn't difficult, so it is usually worth it... I guess it all depends on your value system
Something like this: ;example, 4 tasks
spTab .byte $ff, $ff, $ff, $ff ;default/initial SP pageTab .byte $0c, $0d, $0e, $0f ;pages for each stack ($c00...$f00)
lda #1 ;real page 1 (for safety in switching... IRQs and NMIs you know!) sta $d509 ;re-direct page 1 ldy taskN ;current task tsx txa sta spTab,y ;save SP for the task iny ;next task cpy numTasks bcc + ldy #0 ;did all, start over at first + ldx spTab,y ;get SP for new task lda pageTab,y ;get memory page for stack txs ;set SP for new task sta $d509 ;swith stack page for the task sty taskN ;remember what task is now active After switching stacks, then you would have to decide to jump to some location, or you could just RTS. The RTS method requires a bit more setup. You would need to store the initial address for the task in the custom stack and adjust the SP accordingly.
That code assumes the IRQ/NMI can work with stack located anywhere. The KERNAL routines don't seem to mind, but if you have a custom one it may have problems. In the rare case it has trouble, the IRQ would need to save the $d509 register, set the real page 1, and before exiting restore the previous $d509.
I have a working BASIC task switcher somewhere; I don't recall if it swaps page 1 or not...