The CPU simulator is often the most complicated part of an emulator.
Many emulators are written using "pre-packaged" CPU simulators, in
order to concentrate on good and efficient emulation of a specific
machine.
The simplest form of a CPU simulator is an interpreter, which
follows the execution flow of the emulated program code and, for
every machine code instruction encountered, executes operations on
the host processor that are semantically equivalent to the original
instructions.
This is made possible by assigning a variable to each register and
flag of the simulated CPU. The logic of the simulated CPU can then
more or less be directly translated into software algorithms,
creating a software re-implementation that basically mirrors the
original hardware implementation. The following example illustrates
how CPU simulation is accomplished by an interpreter. In this case,
interrupts are checked-for before every instruction executed, though
this behavior is rare in real emulators for performance reasons. |
|