{"id":15049486,"url":"https://github.com/redcode/z80","last_synced_at":"2025-05-15T18:06:01.497Z","repository":{"id":10893383,"uuid":"13185740","full_name":"redcode/Z80","owner":"redcode","description":"Highly portable Zilog Z80 CPU emulator written in ANSI C","archived":false,"fork":false,"pushed_at":"2025-03-21T20:10:44.000Z","size":983,"stargazers_count":491,"open_issues_count":0,"forks_count":49,"subscribers_count":26,"default_branch":"master","last_synced_at":"2025-04-07T23:07:45.639Z","etag":null,"topics":["ansi-c","c","c89","c90","cpu","cpu-emulation","cpu-emulator","emulation","emulator","retrocomputing","z80","z80-emulation","z80-emulator","zilog"],"latest_commit_sha":null,"homepage":"https://zxe.io/software/Z80","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/redcode.png","metadata":{"files":{"readme":"README","changelog":"HISTORY","contributing":null,"funding":".github/FUNDING.yml","license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":"support/Z80.pc.in","governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null},"funding":{"buy_me_a_coffee":"redcode","github":"redcode","ko_fi":"redcode","liberapay":"redcode","patreon":"redcode"}},"created_at":"2013-09-29T03:38:39.000Z","updated_at":"2025-04-06T15:50:10.000Z","dependencies_parsed_at":"2023-02-14T07:31:17.685Z","dependency_job_id":"a11229af-9b64-4a2e-9d4d-937c0d6525a5","html_url":"https://github.com/redcode/Z80","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redcode%2FZ80","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redcode%2FZ80/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redcode%2FZ80/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redcode%2FZ80/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/redcode","download_url":"https://codeload.github.com/redcode/Z80/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247744332,"owners_count":20988783,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansi-c","c","c89","c90","cpu","cpu-emulation","cpu-emulator","emulation","emulator","retrocomputing","z80","z80-emulation","z80-emulator","zilog"],"created_at":"2024-09-24T21:20:42.299Z","updated_at":"2025-05-15T18:06:01.491Z","avatar_url":"https://github.com/redcode.png","language":"C","readme":"\n             ________________   ________________ _________________\n            |               /\\ |                ||                |\n            |_______       / / |      ____      ||      ____      |\n             \\_____/      / /  |     |____|     ||     |___/|     |\n                  /      / /   |                ||     |  | |     |\n                 /      / /    |      ____      ||     |  | |     |\n                /      /_/_____|     |____|     ||     |__|_|     |\n               /              ||                ||                |\n              /_______________||________________||________________|\n              \\________________\\\\______________//________________/\n\n ______________________________________________________________________________\n|                                                                              |\n|                            Zilog Z80 CPU Emulator                            |\n|                                  version 0.2                                 |\n|                                                                              |\n|            Copyright (C) 1999-2025 Manuel Sainz de Baranda y Goñi            |\n|     Released under the terms of the GNU Lesser General Public License v3     |\n|                                                                              |\n|                          https://zxe.io/software/Z80                         |\n|                                                                              |\n'=============================================================================='\n\n\n1.  Introduction\n================\n\nThe Z80 library implements a fast, small and accurate emulator of the Zilog Z80.\nIt emulates all that is known to date about this CPU, including the undocumented\nbehaviors, MEMPTR, Q and the special RESET. It also has the honor of having been\nthe first open-source project to provide full emulation of the interrupt mode 0.\n\nThe source code is written in ANSI C for maximum portability and is extensively\ncommented. The aim has been to write a well-structured, easy-to-understand piece\nof software; something solid and elegant that can stand the test of time with no\nneed for major changes.\n\n\n2.  Accuracy\n============\n\nThis Z80 CPU emulator has a classic design with instruction-level granularity\nthat delivers the best performance, whilst offering a reasonable flexibility to\nachieve precision down to the T-state level.\n\nInstruction-level granularity implies that, except in a few well-defined cases,\nthe execution of a given instruction cannot stop until all its internal M-cycles\nhave been processed (i.e., instructions are not divided into micro-operations).\nMoreover, registers are modified only once per instruction and the T-state\ncounter is normally updated after a full instruction has been executed.\n\nThat said, instructions, flags, memory accesses, interrupts, clock cycles, etc.,\nare accurately emulated according to the available technical documentation, the\nfindings made after decades of research on the Z80 and electronic simulations.\nAnd, of course, the emulator passes the most exhaustive tests written to date,\nsuch as Frank D. Cringle's \"Z80 Instruction Set Exerciser\", Mark Woodmass' \"Z80\nTest Suite\", Patrik Rak's \"Zilog Z80 CPU Test Suite\" and Peter Helcmanovsky's\n\"Z80 Block Flags Test\", to name a few.\n\n\n3.  Installation from source code\n=================================\n\n3.1.  Prerequisites\n\nYou will need CMake v3.14 or later to build the package and, optionally, recent\nversions of Doxygen, Sphinx and Breathe to compile the documentation. Also, make\nsure that you have LaTeX with PDF support installed on your system if you want\nto generate the documentation in PDF format.\n\nThe Z80 library requires some types and macros included in Zeta, a header-only,\ndependency-free library used for portability reasons. Install Zeta or extract\nits source code tarball to the root directory of the Z80 project or its parent\ndirectory. Zeta is the sole dependency; the emulator does not depend on the C\nstandard library.\n\nLastly, the package includes two testing tools, which are optional to build.\nThe first one runs various Z80-specific tests for CP/M and ZX Spectrum, and will\nuse libzip and zlib if they are available on your system. The second tool is for\nunit tests in JSON format and requires the cJSON and Z80InsnClock libraries.\n\n3.2.  Configure\n\nOnce the prerequisites are met, create a directory and run `cmake` from there to\nprepare the build system:\n\n    $ mkdir build\n    $ cd build\n    $ cmake [options] \u003cZ80-project-directory\u003e\n\nThe resulting build files can be configured by passing options to `cmake`. To\nshow a complete list of those available along with their current settings, type\nthe following:\n\n    $ cmake -LAH -N -B .\n\nIf in doubt, read the CMake documentation for more information on configuration\noptions. The following are some of the most relevant standard options of CMake:\n\n    -DBUILD_SHARED_LIBS=(YES|NO)\n        Generate shared libraries rather than static libraries.\n        The default is `NO`.\n\n    -DCMAKE_BUILD_TYPE=(Debug|Release|RelWithDebInfo|MinSizeRel)\n        Choose the type of build (configuration) to generate.\n        The default is `Release`.\n\n    -DCMAKE_INSTALL_NAME_DIR=\"\u003cpath\u003e\"\n        Specify the directory portion of the dynamic library install name on\n        Apple platforms (for installed shared libraries).\n        Not defined by default.\n\n    -DCMAKE_INSTALL_PREFIX=\"\u003cpath\u003e\"\n        Specify the installation prefix.\n        The default is `/usr/local` (on UNIX and UNIX-like operating systems).\n\nPackage-specific options are prefixed with `Z80_` and can be divided into two\ngroups. The first one controls aspects not related to the source code of the\nlibrary:\n\n    -DZ80_DEPOT_LOCATION=\"\u003clocation\u003e\"\n        Specify the directory or URL of the depot containing the test files\n        (i.e., the firmware and software required by the `test-Z80` tool).\n        The default is `http://zxe.io/depot`.\n\n    -DZ80_FETCH_TEST_FILES=(YES|NO)\n        If `Z80_WITH_TESTING_TOOL` is `YES`, copy or download the test files\n        from the depot to the build directory.\n        The default is `NO`.\n\n    -DZ80_INSTALL_CMAKEDIR=\"\u003cpath\u003e\"\n        Specify the directory in which to install the CMake config-file package.\n        The default is `\"${CMAKE_INSTALL_LIBDIR}/cmake/Z80\"`.\n\n    -DZ80_INSTALL_PKGCONFIGDIR=\"\u003cpath\u003e\"\n        Specify the directory in which to install the pkg-config file.\n        The default is `\"${CMAKE_INSTALL_LIBDIR}/pkgconfig\"`.\n\n    -DZ80_NOSTDLIB_FLAGS=(Auto|\"[\u003cflag\u003e[;\u003cflag\u003e...]]\")\n        Specify the linker flags used to avoid linking against system libraries.\n        The default is `Auto` (autoconfigure flags). If you get linker errors,\n        set this option to `\"\"`.\n\n    -DZ80_OBJECT_LIBS=(YES|NO)\n        Build the emulator as an object library.\n        This option takes precedence over `BUILD_SHARED_LIBS` and\n        `Z80_SHARED_LIBS`. If enabled, the build system will ignore\n        `Z80_WITH_CMAKE_SUPPORT` and `Z80_WITH_PKGCONFIG_SUPPORT`, as no\n        libraries or support files will be installed.\n        The default is `NO`.\n\n    -DZ80_SHARED_LIBS=(YES|NO)\n        Build the emulator as a shared library, rather than static.\n        This option takes precedence over `BUILD_SHARED_LIBS`.\n        Not defined by default.\n\n    -DZ80_SPHINX_HTML_THEME=\"[\u003cname\u003e]\"\n        Specify the Sphinx theme for the documentation in HTML format.\n        The default is `\"\"` (use the default theme).\n\n    -DZ80_WITH_CMAKE_SUPPORT=(YES|NO)\n        Generate and install the CMake config-file package.\n        The default is `NO`.\n\n    -DZ80_WITH_HTML_DOCUMENTATION=(YES|NO)\n        Build and install the documentation in HTML format.\n        It requires Doxygen, Sphinx and Breathe.\n        The default is `NO`.\n\n    -DZ80_WITH_PDF_DOCUMENTATION=(YES|NO)\n        Build and install the documentation in PDF format.\n        It requires Doxygen, Sphinx, Breathe, and LaTeX with PDF support.\n        The default is `NO`.\n\n    -DZ80_WITH_PKGCONFIG_SUPPORT=(YES|NO)\n        Generate and install the pkg-config file.\n        The default is `NO`.\n\n    -DZ80_WITH_STANDARD_DOCUMENTS=(YES|NO)\n        Install the standard text documents distributed with the package:\n        AUTHORS, COPYING, COPYING.LESSER, HISTORY, README and THANKS.\n        The default is `NO`.\n\n    -DZ80_WITH_STEP_TESTING_TOOL=(YES|NO)\n        Build `step-test-Z80`, a tool for unit tests in JSON format.\n        It requires cJSON and Z80InsnClock.\n        The default is `NO`.\n\n    -DZ80_WITH_TESTING_TOOL=(YES|NO)\n        Build `test-Z80`, a tool that runs various Z80-specific tests for CP/M\n        and ZX Spectrum.\n        The default is `NO`.\n\nThe second group of package-specific options configures the source code of the\nlibrary by predefining macros that enable optional features:\n\n    -DZ80_WITH_EXECUTE=(YES|NO)\n        Build the implementation of the `z80_execute` function.\n        The default is `NO`.\n\n    -DZ80_WITH_FULL_IM0=(YES|NO)\n        Build the full implementation of the interrupt mode 0 rather than the\n        reduced one.\n        The default is `NO`.\n\n    -DZ80_WITH_IM0_RETX_NOTIFICATIONS=(YES|NO)\n        Enable optional notifications for any `reti` or `retn` instruction\n        executed during the interrupt mode 0 response.\n        The default is `NO`.\n\n    -DZ80_WITH_PARITY_COMPUTATION=(YES|NO)\n        Enable actual parity calculation for the P/V flag instead of using a\n        table of precomputed values (NOT RECOMMENDED for production builds).\n        The default is `NO`.\n\n    -DZ80_WITH_PRECOMPUTED_DAA=(YES|NO)\n        Use a table of precomputed values to emulate the `daa` instruction (NOT\n        RECOMMENDED for production builds).\n        The default is `NO`.\n\n    -DZ80_WITH_Q=(YES|NO)\n        Build the implementation of Q.\n        The default is `NO`.\n\n    -DZ80_WITH_SPECIAL_RESET=(YES|NO)\n        Build the implementation of the special RESET.\n        The default is `NO`.\n\n    -DZ80_WITH_UNOFFICIAL_RETI=(YES|NO)\n        Configure the undocumented instructions ED5Dh, ED6Dh and ED7Dh as `reti`\n        instead of `retn`.\n        The default is `NO`.\n\n    -DZ80_WITH_ZILOG_NMOS_LD_A_IR_BUG=(YES|NO)\n        Build the implementation of the bug affecting the Zilog Z80 NMOS, which\n        causes the P/V flag to be reset when a maskable interrupt is accepted\n        during the execution of the `ld a,{i|r}` instructions.\n        The default is `NO`.\n\nPackage maintainers are encouraged to use at least the following options for the\nshared library:\n\n    -DZ80_WITH_EXECUTE=YES\n    -DZ80_WITH_FULL_IM0=YES\n    -DZ80_WITH_IM0_RETX_NOTIFICATIONS=YES\n    -DZ80_WITH_Q=YES\n    -DZ80_WITH_ZILOG_NMOS_LD_A_IR_BUG=YES\n\n3.3.  Build and install\n\nFinally, once the build system is configured according to your needs, build and\ninstall the package:\n\n    $ cmake --build . [--config (Debug|Release|RelWithDebInfo|MinSizeRel)]\n    # cmake --install . [--config \u003cconfiguration\u003e] [--strip]\n\nThe `--config` option is only necessary for those CMake generators that ignore\n`CMAKE_BUILD_TYPE` (e.g., Xcode and Visual Studio). Use `--strip` to remove\ndebugging information and non-public symbols when installing non-debug builds of\nthe shared library.\n\n\n4.  Integration\n===============\n\n4.1.  As an external dependency in CMake-based projects\n\nThe Z80 library includes a config-file package for integration into CMake-based\nprojects that must be installed for development. Use `find_package` to find the\n`Z80` package. This creates the `Z80` imported library target, which carries the\nnecessary transitive link dependencies. Optionally, the linking method can be\nselected by specifying either the `Shared` or `Static` component.\n\nExample:\n\n    find_package(Z80 REQUIRED Shared)\n    target_link_libraries(your-target Z80)\n\nWhen not specified as a component, the linking method is selected according to\n`Z80_SHARED_LIBS`. If this option is not defined, the config-file uses the type\nof library that is installed on the system and, if it finds both the shared and\nthe static versions, `BUILD_SHARED_LIBS` determines which one to link against.\n\n4.2.  As a CMake subproject\n\nTo embed the Z80 library as a CMake subproject, extract the source code tarballs\nof Zeta and Z80 (or clone their respective repositories) into a subdirectory of\nanother project. Then use `add_subdirectory` in the parent project to add the\nZ80 source code tree to the build process (N.B., the Z80 subproject will\nautomatically find Zeta and import it as an interface library).\n\nIt is advisable to configure the Z80 library in the CMakeLists.txt of the parent\nproject. This will eliminate the need for the user to specify configuration\noptions for the Z80 subproject through the command line when building the main\nproject. See section 3.2 of this document for a list of available configuration\noptions.\n\nExample:\n\n    set(Z80_SHARED_LIBS                 NO  CACHE BOOL \"\")\n    set(Z80_WITH_Q                      YES CACHE BOOL \"\")\n    set(Z80_WITH_ZILOG_NMOS_LD_A_IR_BUG YES CACHE BOOL \"\")\n\n    add_subdirectory(dependencies/Z80)\n    target_link_libraries(your-target Z80)\n\nIt is important to set the `Z80_SHARED_LIBS` option. Otherwise, CMake will build\nthe library type indicated by `BUILD_SHARED_LIBS`, which may not be the desired\none.\n\n4.3.  Non-CMake-based projects\n\nThe source code of the emulator can be configured at compile time by predefining\na series of macros. Both Z80.h and Z80.c obey the first two explained below. The\nrest of the macros are only relevant when compiling Z80.c:\n\n    #define Z80_EXTERNAL_HEADER \"header-name.h\"\n        Specifies the only external header to `#include`, replacing all others.\n        Predefine this macro to provide a header file that defines the external\n        types and macros used by the emulator, thus preventing your project from\n        depending on Zeta. You can use this when compiling Z80.c within your\n        project or (if your types do not break the binary compatibility) when\n        including `\u003cZ80.h\u003e` and linking against a pre-built Z80 library.\n\n    #define Z80_STATIC\n        Indicates that the emulator is a static library.\n        This macro must be predefined when building Z80.c as a static library.\n        Additionally, if you compile Z80.c directly within your project or link\n        your program against the static version of the Z80 library, ensure that\n        this macro is defined before including `\"Z80.h\"` or `\u003cZ80.h\u003e`.\n\n    #define Z80_WITH_LOCAL_HEADER\n        Tells Z80.c to `#include \"Z80.h\"` instead of `\u003cZ80.h\u003e`.\n\nThe optional features of the emulator mentioned in section 3.2 of this document\nare disabled by default. If you compile Z80.c within your project, enable those\nfeatures you need by predefining their respective activation macros. They have\nthe same name as their CMake equivalents:\n\n    #define Z80_WITH_EXECUTE\n    #define Z80_WITH_FULL_IM0\n    #define Z80_WITH_IM0_RETX_NOTIFICATIONS\n    #define Z80_WITH_PARITY_COMPUTATION\n    #define Z80_WITH_PRECOMPUTED_DAA\n    #define Z80_WITH_Q\n    #define Z80_WITH_SPECIAL_RESET\n    #define Z80_WITH_UNOFFICIAL_RETI\n    #define Z80_WITH_VOLATILE_CYCLES\n    #define Z80_WITH_ZILOG_NMOS_LD_A_IR_BUG\n\nExcept for `Z80_EXTERNAL_HEADER`, the above macros can be empty; the source code\nonly checks whether they are defined.\n\nPlease note that the activation of some of the optional features affects the\nspeed of the emulator due to various factors (read the documentation for more\ndetails).\n\n\n5.  License\n===========\n\nThis library is free software: you can redistribute it and/or modify it under\nthe terms of the GNU Lesser General Public License as published by the Free\nSoftware Foundation, either version 3 of the License, or (at your option) any\nlater version.\n\nThis library is distributed in the hope that it will be useful, but WITHOUT ANY\nWARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A\nPARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public License along\nwith this library. If not, see \u003chttp://www.gnu.org/licenses/\u003e.\n\n\n________________________________________________________________________________\nLast update: 2025-05-04                                               README EOF\n","funding_links":["https://buymeacoffee.com/redcode","https://github.com/sponsors/redcode","https://ko-fi.com/redcode","https://liberapay.com/redcode","https://patreon.com/redcode"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredcode%2Fz80","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fredcode%2Fz80","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredcode%2Fz80/lists"}