Multitasking On The Humble Z80 CPU
Multitasking is something we take for granted these days. Just about every computer we use, from our desktops to our phones, is capable of multitasking. It might sound silly to implement multitasking on lower-spec machines from many decades ago, given their limited resources, but it can be done, as [bchiha] demonstrates on a Z80-based machine. [bchiha] has achieved pre-emptive multitasking on the TEC-1G Z80 computer, a modern reimagining of the classic Talking Electronics TEC-1 from the 1980s. The proof of concept code allows running up to eight separate tasks at once. Task switching runs on interrupts, triggered at approximately 50 Hz. When an interrupt fires, the CPU registers are transferred onto that task’s stack, and the next task’s stack is swapped to the stack pointer to allow execution of the new task to proceed. There is an overhead, of course, with [bchiha] noting that the task swapping routine itself takes about 430 clock cycles to run in between tasks. Multitasking...