Multitasking on a Z80 CPU

I’ve been thinking about doing this for years, and it’s finally here. Pre-emptive Multitasking on the Z80. This video goes through the steps of setting up a Multitasking environment. Tasks are switched in and out of the CPU to create the illusion that all tasks are running simultaneously.

The sample code is a “Proof of Concept”, and there is room for improvement. But it’s a start.

The code designed for the TEC-1G can be viewed at:
https://github.com/bchiha/Ready-Z80/t…

If you like my work, consider buying me a Coffee!
https://buymeacoffee.com/readyz80

00:00 Intro
00:53 Basic Concept of Pre-emptive Multitasking
06:15 Interrupt Service Routine
08:34 Task Swapper Z80 Assembly code
10:37 Square wave generator for Interrupts
12:02 Multitasking demo on the TEC-1G

Hi there,

I have mentioned this before here, So, back in the 80’s I worked for a company called Computerm…in Pittsburgh PA. :backhand_index_pointing_left: :grin: Voted Best city Too, Go Steelers!

They emulated and coupled devices on the IBM BUS & TAG arcitecture for IBM systems, 3070-3080’s and more. they used Z-80 B’s in boards on both ends of a Switched 56K ISDN Channel pairs phone line pairs(4) in between. The first HIGH Speed SDLC on the globe. They developed a similar proprietary OS, or monitor System that ran both ends, Emulator on one side & couple on the other, each had a stack of boards all containing at least one Z-80 and some windows eeprom chips and let’s not forget those great peripheri-ie some SIO’s PIO’s CTC’s and a DUART :grin: console ports.

I don’t care what anyone says… that stuff was bullet proof.
and Great video. :+1:

it was for banks, the (IBM)host were in Chicago <—> the check printers and terminals were in Atlanta… The host never knew the difference, same as the peripherals. everything appeared LOCAL. :smile:

GL :slight_smile: PJ :v:

1 Like

… I think it is important to remember the past to build the future… I remember I had a Commadore Vic 20 and I remember reading the manual and Peek and Poke and all that stuff you type… hexadecimal ? what da? I didnt understand why anyone needed more than just regular numbers… i thought it was a unit conversoin to make you fail a test… Binary? what da? is this Algebra…but i never understood what i was doing or how it really worked… I wish I had the knowledge back then..

1 Like

Oh man… I cut my teeth on a Z-80. I love 'em! I knew a lot of the assembly nemonics by heart, I could writ assembly almost as well as I can C. I still have a huge cache of Zilog chips, most old, but a few new ones (combined CPU/IO). Always wanted to build a new system, but just never seem to get to it.

.. if you have the parts… its interesting… I wonder if a XIAO could be used as the Memory and IO -Video and Sound “Co Processor”… another waste of time and money… but it would be cool to see

:grinning_face:
The primary integrated family is the Z84C15 Intelligent Peripheral Controller (IPC), which packed a standard Z80 core with the full CTC, SIO, PIO, and watchdog hardware into a 100-pin QFP package

:+1:

GL :slight_smile: PJ :victory_hand:

That’s more or less what I had planned. Use a microcontroller as the I/O controller mostly, keyboard, display etc. That would save a lot of processing power on the Z80 and really simplify things, like using I2C SPI devices, memory cards etc…

1 Like

I think I bought several of those, I figured with everything integrated, it’d be a lot easier to get going. Still in the unopened packages… I bought a couple of variants.

I thought about giving all the old Zilog chips to a school electronics/robotics club. But I can’t really find any in this area. I like the Z80 because it’s simple, straight forward and powerful enough. Plus it really lays the groundwork for most of everything else out there. Great for learning about the accumulator/flags/pointer registers etc…

2 Likes

Hi there,

Yes, MY favorite Z80 topics were always the

Interrupts

DMA

Bonus Round was ,

Cycle Stealing

(taking memory liberties in between the clock cycles the IBM host was waiting on IO. it was some next level SHITE :grinning_face:
Connecting an 8-bit Z80 running at 4 MHz to an IBM mainframe channel capable of multi-megabyte burst rates was a massive speed mismatch. Tying up the Z80 bus or making the channel stall was out of the question, which made cycle stealing the only viable approach:

  • Transparent DMA & The M1 Refresh Trick: The Z80 naturally executed opcode fetch during clock cycles T_1 and T_2 of an M_1 machine cycle, then used T_3 and T_4 strictly for internal DRAM row refresh (/RFSH and the 7-bit R register on the low address lines). External channel logic could intercept those dead execution slices or assert /BUSREQ for single T-states to steal bus access without stalling instructions. :face_with_hand_over_mouth:

in the 80’s LOL

Love it.

TRIGGER WARNING

:face_with_tongue: :index_pointing_up:


GL :slight_smile: PJ :victory_hand:

now thats what i call a breadboard…lol

1 Like

ROFLMAO,
Indeed < Literally I forgot about that. :smile:

good one, :+1:

Todays Z80 ,
you got to give it up for the Arm Cortex M33 :clap: :clap:

The ARM Cortex-M33 is very much a spiritual successor to what the Z-80 represented in its era — but it is not the same class of thing.

The analogy is actually pretty good.

The Z-80 (1976)

The Z-80 was revolutionary because it put a complete programmable computer into a practical single chip.

Before:

  • CPU boards
  • support chips
  • lots of glue logic :backhand_index_pointing_left: :smiling_face_with_tear: The “22V10”, Sounded like a good name for a YT channel ..

:face_with_peeking_eye:

After:

Z-80
 |
 +-- Memory
 +-- I/O
 +-- Peripherals

Suddenly engineers could build:

  • controllers
  • terminals
  • hobby computers
  • industrial equipment

It became the brain of countless systems.

Cortex-M33 today

The Cortex-M33 plays a similar role in modern embedded systems.

Today:

Cortex-M33
 |
 +-- Flash
 +-- RAM
 +-- GPIO
 +-- ADC
 +-- PWM
 +-- Timers
 +-- SPI/I2C/UART
 +-- Security
 +-- DSP capability
 +-- Radio interfaces

It is the “controller brain” inside:

  • IoT devices
  • wearables
  • industrial sensors
  • smart locks
  • medical devices
  • appliances

The difference is the scale.
The Z-80 did not win because it was the most powerful CPU.

It won because it was:

  • accessible
  • affordable
  • well documented
  • supported by an ecosystem

That same formula is why ARM Cortex-M dominates embedded today.

The nRF54 chips you’re playing with are basically that same philosophy, but now the “computer” includes:

CPU
+
radio
+
security
+
power management
+
sensors
+
wireless protocols

The crazy part is a modern $5–$15 embedded board has more computing capability than early desktop computers.

Our XIAO nRF54LM20A is, in a weird historical sense, the descendant of those Z-80 systems. Same mission:

Put intelligence into things.

The Z-80 made computers personal.

The Cortex-M33 is making intelligence ubiquitous.
:+1: Great Time to be in TECH…

:grin:
When isn’t it ?

GL :slight_smile: PJ :v: