home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 2
/
FFMCD02.bin
/
new
/
misc
/
emu
/
z80
/
z80.doc
< prev
next >
Wrap
Text File
|
1993-12-21
|
12KB
|
270 lines
Zilog Z80 CPU emulator package for the Motorola M68000 family.
Version 0.99b
(C) Copyright 1993 Richard Carlsson
Author: Richard Carlsson
E-Mail: m90rca @ tdb.uu.se (Uppsala University, Sweden)
Mail: Solgatan 58, 195 55 Maersta, Sweden.
The emulator package is freeware. It may be distributed freely as long
as nothing is charged for the distribution beyond the actual costs of
media and transfer. If the package is used in a program, the same rules
for distribution must apply to that program unless the rights to charge
a fee have been explicitly obtained from the author.
That should cover just about everything. If you include the emulator in
a project, I would like to hear about it. Please always inform me if
you release such a project as public domain or freeware.
I have done my best to make the emulator as flexible as possible. The
interface should be easy to understand and use, from C as well as from
assembler. The C stubs and the header file Z80.h should make it easy to
use the emulator from a shell written in C. (As I have done myself.)
Please report any bugs, assembler or machine incompatibilities, or mere
stupidity in my code, and I shall fix it as soon as possible. You are
of course also welcome to present new ideas, but please read the file
cache.txt before you attempt to improve the emulation method itself.
The other goal of this project has been emulation speed. There are
Z80 emulators that may be even more flexible and accurate in emulation
than this one, but I know of no one that is also this fast.
This program is a tribute to Sir Clive Sinclair.
Credits:
To Peter McGavin, for the basic idea of using threaded code,
for a lot of idea bouncing and testing, and for giving me new
inspiration to finish this old project. Also to Linus and Oliver
for starting this whole business. See the history below.
Examples of emulation speed:
Run on processor Corresponds to Hz factor
Full-featured version:
68000, 7.16 MHz 0.52 MHz Z80 0.073
68030, 40 MHz 3.3 MHz Z80 0.083
Stripped "games" version:
68000, 7.16 MHz 0.67 MHz Z80 0.094
68030, 40 MHz 3.8 MHz Z80 0.095
The tests were run on an Amiga, with the system up and running,
and lots of other tasks loaded (most of them in waiting state).
To find out what the emulator would correspond to on your machine,
multiply the frequency of your processor with the "Hz factor". For
instance, a 33 MHz 68030 running the full version gives 33 * 0.083
-> 2.7 MHz Z80. Of course this will vary with different memory
configurations etc.
Main files of interest:
Z80.a The main emulator source file.
Z80.i Include file for using the emulator.
Z80_struct.i Include file defining the control structure.
Z80_coding.i Include file with definitions needed to code the
Z80 instruction emulation routines.
extern_instr.a File for external compilation of implementation-
specific Z80 instructions like In/Out.
generic_macs.i Include file defining the implementation-specific
Z80 instructions (generic versions).
user.i User definitions.
Z80.h Header file for using the emulator from C.
c_stubs.a File defining the assembler stubs for calling
the emulator functions from C.
files A more detailed description of all included files.
Use:
Includes/header files
Assembler:
All constants and cross-references are defined in Z80.i. The
control structure, offsets and size, are defined in Z80_struct.i.
The function calls are documented in Z80.i.
C:
Constants, function prototypes and documentation, structure
declarations and so on are all defined/declared in Z80.h.
Allocating memory
The emulator needs several areas of memory to execute:
Size Comment
* Z80 address space Z80_MEMSIZE
* Cache memory Z80_CACHESIZE Must be word-aligned
* Control structure Z80_StructSize Must be word-aligned.
If the memory write access checking feature is used, memory for the
control flags is also needed:
* Flag memory Z80_FLAGMEMSIZE
Z80_MEMSIZE and Z80_FLAGMEMSIZE are approx. 64 K each.
Z80_CACHESIZE is approx. 128 K. The control structure takes about
500 bytes.
Setting up before coldstart
Set the fields Z80_Memory and Z80_Cachemem of the control
structure to point to the corresponding memory areas. If memory
checking is used, set the Z80_Flagmem field to point to the flag
memory, or to zero if the feature is not used. Also set the field
Z80_MemHandler to the address of a user-defined memory exception
handler routine, or to zero if no such routine exists.
After that, call Z80_Init to initialise the remaining fields of
the control structure. The user environment data area is not
affected.
Call Z80_SetMemFlag to flag any memory areas before start.
Documentation on the flags and the User Exception Handler Call can
be found in Z80.i. Other helper functions could for instance be
used to initialise the memory before start.
Coldstart
A coldstart does a CPU reset as it starts the emulation. When (and
if) the emulation exits (see Exit emulation below), you may inspect
and even change the public fields of the control structure, where
the Cpu Status entries are the most interesting ones.
Continuing emulation
Call Z80_Continue each time you want the emulation to proceed
with the information in the Cpu Status entries. Z80_Init sets up
these entries as after a CPU reset. For no other fields of the
control structure are changes guaranteed to have any effect when
calling Z80_Continue directly afterwards (see Reallocating Memory
Areas below).
Exit emulation
Presently, the only way to exit the emulator is to call
Z80_EXITreq from an outside task or interrupt routine. I intend
to make it possible to patch Z80 instructions (particularly
undefined ones) to take on special meanings, like EXIT. It will
then be possible for the task running the emulator to return "by
its own will".
Reallocating memory areas
To inform the emulator that changes to the public fields like
the memory pointers have taken place, call Z80_NewSettings.
Calling Z80_Continue will then proceed using the new locations
(see Continuing emulation above). Do not move a memory area or
call Z80_NewSettings before the emulation has stopped (inspect
the Running field of the control structure).
The control structure may be moved without calling Z80_Realloc,
since its address is always passed as a parameter.
Compilation:
The main emulator file Z80.a and its associated files are written
in Devpac 3 (and mostly Devpac 2 compatible) macro assembler
syntax. The main not generally compatible feature is the local
labels, which are on the form .<label> (that is, an identifier
beginning with a dot).
Compilation of Z80.a can be to either a single stand-alone object
file containing the whole emulator function package, or to a
generic object file that needs external labels (see the section on
In/Out and other implementation-dependent instructions below).
The include files Z80.i and Z80_struct.i as well as the files
external_instr.a, generic_macs.i, Z80_coding.i and c_stubs.a are in
a more standardized macro assembler form.
All user definitions are to be entered in user.i.
Compiling the C stubs should be straightforward. Check with your
C compiler manual to see if they are behaving as they should.
I/O instructions and other implementation-dependent behaviour:
All instructions that are involved with external signalling and I/O
and generally depend on your environment, should be possible to
redesign fairly easily with only a small amount of knowledge about
the internal workings of the emulator. The prototypical examples in
generic_macs.i are probably not exactly what you want, so:
Copy the file generic_macs.i to a file machine_macs.i, and edit the
macros in it. Set Z80_ENV_SIZE (see Z80.i) to suit your needs, and
modify any compilation flags in the file you are compiling. Then
recompile (to object code) either the file external_instr.i (to
link with a 'generic