All Projects → redcode → Z80

redcode / Z80

Licence: GPL-3.0 License
Highly portable Zilog Z80 CPU emulator written in ANSI C

Programming Languages

c
50402 projects - #5 most used programming language
lua
6591 projects

Projects that are alternatives of or similar to Z80

z80
Single header Z80 emulator for C++ (C++11 or later)
Stars: ✭ 17 (-87.02%)
Mutual labels:  cpu, z80, z80-emulator
SherwoodArch
The Sherwood Architecture is a custom 64-Bit RISC based CPU architecture.
Stars: ✭ 13 (-90.08%)
Mutual labels:  emulator, cpu, cpu-emulator
jsGBC
👾 A GameBoy Color Emulator written in JavaScript
Stars: ✭ 44 (-66.41%)
Mutual labels:  z80, z80-emulator
cpu emulator
LMC emulator written in Rust
Stars: ✭ 32 (-75.57%)
Mutual labels:  cpu, cpu-emulator
a80
Intel 8080/Zilog Z80 assembler written in D.
Stars: ✭ 23 (-82.44%)
Mutual labels:  z80, zilog
Riscv Rust
RISC-V processor emulator written in Rust+WASM
Stars: ✭ 253 (+93.13%)
Mutual labels:  emulator, cpu
Unicorn
Unicorn CPU emulator framework (ARM, AArch64, M68K, Mips, Sparc, PowerPC, RiscV, X86)
Stars: ✭ 4,934 (+3666.41%)
Mutual labels:  emulator, cpu
Z80Core
A Z80 core written in Java
Stars: ✭ 25 (-80.92%)
Mutual labels:  emulator, z80
Awesome Cpus
All CPU and MCU documentation in one place
Stars: ✭ 1,602 (+1122.9%)
Mutual labels:  cpu, z80
z80e
A z80 calculator emulator (and debugger)
Stars: ✭ 65 (-50.38%)
Mutual labels:  emulator, z80
emuStudio
Universal emulation platform and framework.
Stars: ✭ 28 (-78.63%)
Mutual labels:  emulator, z80
vrcpu
Code, documentation, schematics, notes for my Ben Eater inspired breadboard computer and emulator
Stars: ✭ 98 (-25.19%)
Mutual labels:  emulator, cpu
mos6502
MOS 6502 emulator written in Rust
Stars: ✭ 25 (-80.92%)
Mutual labels:  emulator, cpu
pac-man-emulator
🕹 An emulator for the Pac-Man arcade machine (Zilog Z80 CPU) for Win/Mac/*nix and Xbox One.
Stars: ✭ 20 (-84.73%)
Mutual labels:  emulator, z80
rygar-emu
An emulator for the Rygar arcade game
Stars: ✭ 18 (-86.26%)
Mutual labels:  emulator, z80
nes-rust
NES emulator in Rust with GUI
Stars: ✭ 78 (-40.46%)
Mutual labels:  emulator, cpu
Zany80
Zany80 fantasy computer system
Stars: ✭ 48 (-63.36%)
Mutual labels:  z80, z80-emulator
6502-emulator
An Understandable 6502 Emulator
Stars: ✭ 26 (-80.15%)
Mutual labels:  emulator, cpu
MC6809
Implementation of the MC6809 CPU in Python (Extracted from https://github.com/jedie/DragonPy project)
Stars: ✭ 24 (-81.68%)
Mutual labels:  emulator, cpu
zasm
Z80 / 8080 / Z180 assembler (for unix-style OS)
Stars: ✭ 47 (-64.12%)
Mutual labels:  z80

al-tag


Zilog Z80 CPU Emulator

Copyright © 1999-2018 Manuel Sainz de Baranda y Goñi.
Released under the terms of the GNU General Public License v3.

This is a very accurate Z80 emulator I wrote many years ago. It has been used in several machine emulators by other people and it has been extensivelly tested. It is fast, small (33 KB when compiled as a x86-64 dynamic library), easy to understand, and the code is profusely commented.

If you are looking for a Zilog Z80 CPU emulator for your project maybe you have found the correct one. I use this core in the ZX Spectrum emulator I started as hobby.


Building

You must first install Z, a header-only library that provides types and macros. This is the only dependency, the emulator does not use the C standard library or its headers. Then add Z80.h and Z80.c to your project and configure its build system so that CPU_Z80_STATIC and CPU_Z80_USE_LOCAL_HEADER are predefined when compiling the sources.

If you preffer to build the emulator as a library, you can use premake4:

$ cd building
$ premake4 gmake                         # generate Makefile
$ make help                              # list available targets
$ make [config=<configuration>] [target] # build the emulator

There is also an Xcode project in development/Xcode with several targets:

Target Description
Z80 (dynamic) Shared library.
Z80 (dynamic module) Shared library with a generic module ABI to be used in modular multi-machine emulators.
Z80 (static) Static library.
Z80 (static module) Static library with a generic CPU emulator ABI to be used in monolithic multi-machine emulators.

Code configuration

There are some predefined macros that control the compilation:

Name Description
CPU_Z80_DEPENDENCIES_H If defined, it replaces the inclusion of any external header with this one. If you don't want to use Z, you can provide your own header with the types and macros used by the emulator.
CPU_Z80_HIDE_ABI Makes the generic CPU emulator ABI private.
CPU_Z80_HIDE_API Makes the public functions private.
CPU_Z80_STATIC You need to define this to compile or use the emulator as a static library or if you have added Z80.h and Z80.c to your project.
CPU_Z80_USE_LOCAL_HEADER Use this if you have imported Z80.h and Z80.c to your project. Z80.c will #include "Z80.h" instead of <emulation/CPU/Z80.h>.
CPU_Z80_WITH_ABI Builds the generic CPU emulator ABI and declares its prototype in Z80.h.
CPU_Z80_WITH_MODULE_ABI Builds the generic module ABI. This macro also enables CPU_Z80_WITH_ABI, so the generic CPU emulator ABI will be built too. This option is intended to be used when building a true module loadable at runtime with dlopen(), LoadLibrary() or similar. The ABI module can be accessed via the weak symbol __module_abi__.

API: Z80 emulator instance

This structure contains the state of the emulated CPU and callback pointers necessary to interconnect the emulator with external logic. There is no constructor function, so, before using an object of this type, some of its members must be initialized, in particular the following: context, read, write, in, out, int_data and halt.

zusize cycles;

Description
Number of cycles executed in the current call to z80_run.
Details
z80run sets this variable to 0 before starting to execute instructions and its value persists after returning. The callbacks can use this variable to know during what cycle they are being called.

void *context;

Description
The value used as the first argument when calling a callback.
Details
This variable should be initialized before using the emulator and can be used to reference the context/instance of the machine being emulated.

zuint8 (* read)(void *context, zuint16 address);

Description
Callback: Called when the CPU needs to read 8 bits from memory.
Parameters
context → The value of the member context.
address → The memory address to read from.
Returns
The 8 bits read from memory.

void (* write)(void *context, zuint16 address, zuint8 value);

Description
Callback: Called when the CPU needs to write 8 bits to memory.
Parameters
context → The value of the member context.
address → The memory address to write to.
value → The value to write.

zuint8 (* in)(void *context, zuint16 port);

Description
Callback: Called when the CPU needs to read 8 bits from an I/O port.
Parameters
context → The value of the member context.
port → The number of the I/O port to read from.
Returns
The 8 bits read from the I/O port.

void (* out)(void *context, zuint16 port, zuint8 value);

Description
Callback: Called when the CPU needs to write 8 bits to an I/O port.
Parameters
context → The value of the member context.
port → The number of the I/O port to write to.
value → The value to write.

zuint32 (* int_data)(void *context);

Description
Callback: Called when the CPU needs to read one instruction from the data bus to service a maskable interrupt (INT) in mode 0.
Parameters
context → The value of the member context.
Returns
A 32-bit value containing the bytes of an instruction. The instruction must begin at the most significant byte (big endian).

void (* halt)(void *context, zboolean state);

Description
Callback: Called when the CPU enters or exits the halt state.
Note
This callback is optional and must be set to NULL if not used.
Parameters
context → The value of the member context.
stateTRUE if halted; FALSE otherwise.

ZZ80State state;

Description
CPU registers and internal bits.
Details
It contains the state of the registers, as well as the interrupt flip-flops, variables related to interrupts and other necessary flags. This is what a debugger should use as data source.

zuint8 r7;

Description
Backup of the 7th bit of the R register.
Details
The value of the R register is incremented as instructions are executed, but its most significant bit remains unchanged. For optimization reasons, this bit is saved at the beginning of the execution of z80_run and restored before returning. If an instruction directly affects the R register, this variable is also updated accordingly.

Z16Bit xy;

Description
Temporay IX/IY register for instructions with DDh/FDh prefix.
Details
Since instructions with prefix DDh and FDh behave similarly, differing only in the use of register IX or IY, for reasons of size optimization, a single register is used that acts as both. During opcode analysis, the IX or IY register is copied to this variable and, once the instruction emulation is complete, its contents are copied back to the appropriate register.

Z32Bit data;

Description
Temporary storage for opcode fetching.
Details
This is an internal private variable.


API: Public Functions

void z80_power(Z80 *object, zboolean state);

Description
Changes the CPU power status.
Parameters
object → A pointer to a Z80 emulator instance.
stateTRUE = power ON; FALSE = power OFF.

void z80_reset(Z80 *object);

Description
Resets the CPU.
Details
This is equivalent to a pulse on the RESET line of a real Z80.
Parameters
object → A pointer to a Z80 emulator instance.

zusize z80_run(Z80 *object, zusize cycles);

Description
Runs the CPU for a given number of cycles.
Note
Given the fact that one Z80 instruction needs between 4 and 23 cycles to be executed, it's not always possible to run the CPU the exact number of cycles specfified.
Parameters
object → A pointer to a Z80 emulator instance.
cycles → The number of cycles to be executed.
Returns
The number of cycles executed.

void z80_nmi(Z80 *object);

Description
Performs a non-maskable interrupt (NMI).
Details
This is equivalent to a pulse on the NMI line of a real Z80.
Parameters
object → A pointer to a Z80 emulator instance.

void z80_int(Z80 *object, zboolean state);

Description
Changes the state of the maskable interrupt (INT).
Details
This is equivalent to a change on the INT line of a real Z80.
Parameters
object → A pointer to a Z80 emulator instance.
stateTRUE = line high; FALSE = line low.


Use in Proprietary Software

This library is released under the terms of the GNU General Public License v3, but I can license it for non-free/propietary projects if you contact me.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].