In designing the emulator – we need to understand how the Z80 CPU works. The first part will be the instruction cycle.
The Z80 instructions execute the following five basic operations:
External Device Read – IO
External Device Write – IO
Each of these operations takes anywhere from three to six clock periods to complete. However, the Z80 is very flexible and the time to performed these operations can be lengthen as needed.
These basic operations are performed in an instruction cycle.
The Z80 instruction cycle is divided up into three sub-cycles called Machine Cycles. Here is a nice picture of it so you can get an idea of it.
M1 – Op Code Fetch
M2 – Memory or I/O Read
M3 – Memory or I/O Write
This starts to give us a basic diagram of the program flow.
This will run in a loop.
Next we will start to fill in what functions take place during each machine cycle.