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 took some time to appear on home computers for good reason—it’s not very useful unless you have a machine with enough power to practically run multiple tasks at once. While a Z80 machine like this can do multitasking, you’d better hope each task is pretty tiny to avoid each individual task taking forever to run.
[bchiha] has made the simple multitasking code available on Github for the curious. We’ve featured multitasking work on other unconventional platforms before, too, like the Arduino Uno. Video after the break.
[Thanks to Stephen Walters for the tip!]



Post Comment