Skip to content

umjammer/vavi-apps-z80

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Release Java CI CodeQL Java

vavi-apps-z80

zup logo

What is this?

vavi-apps-z80 is a Z80 processor simulator that can be used as the core component for developing computer emulators (see for example NestorMSX), or to exercise pieces of Z80 code in custom test code. It is written in Java targetting the JVM version 17.

If you like vavi-apps-z80 you may want to take a look at ZWatcher too.

vavi-apps-z80 is a fork of Z80dotNet

Install

Usage

Hello, world!

    var z80 = new Z80ProcessorImpl();
    z80.setAutoStopOnRetWithStackEmpty(true);

    var program = new byte[] {
      0x3E, 0x07,        // LD A,7
      (byte) 0xC6, 0x04, // ADD A,4
      0x3C,              // INC A
      (byte) 0xC9        // RET
    };
    z80.getMemory().setContents(0,program);

    z80.start(null);

    assert z80.getRegisters().getA() == 12;
    assert z80.getTStatesElapsedSinceStart() == 28;

How to use

For your convenience, you can add Z80.NET to your project as a maven package if you want. In that case you may want to take a look at the release notes.

  1. Create an instance of the Z80Processor class.
  2. Optionally, plug your own implementations of one or more of the dependencies.
  3. Configure your instance as appropriate.
  4. Optionally, register one or more interrupt sources.
  5. Optionally, capture the memory access events and/or the instruction execution events.
  6. Start the simulated processor execution by using one of the execution control methods.
  7. Execution will stop (and the execution method invoked will then return) when one of the execution stop conditions is met. You can then check the processor state and, if desired, resume execution.

Execution is completely synchronous: one single thread is used for everything, including firing events. As seen in the Hello World example, you just invoke one of the starting methods and wait until it returns (there are means to force this to happen, see the execution stop conditions). If you want some kind of multithreading, you'll have to implement it by yourself, I just tried to keep things simple. :-)

Interaction of the processor with the hosting code and the outside world (memory and ports) can be achieved by handling the class events, by plugging custom implementations of the dependencies, or both at the same time. Interrupts can be generated by using interrupt sources.

Compatibility

Z80.NET implements all the documented Z80 behavior, plus all the undocumented instructions and flag effects as per The undocumented Z80 documented except for the following:

  • The bit 3 and 5 flags are not modified by the BIT instruction
  • The H, C and P/V flags are not modified by the INI, INIR, IND, INDR, OUTI, OTIR, OUTD and OTDR instructions

The processor class passes the ZEXDOC test fully, and the ZEXALL test fully except for the BIT instruction. You can try these tests yourself by running the ZexallTest project.

References

Current Score (#0052fce)

https://gist.github.com/umjammer/ea319aaa7b1ecf10a19b3ade2fd7187b

Resources

The following resources have been used to develop this project:

TODO

  • too slow, x100 slower compare to my z80
  • unit tests have random fixture problems, if it would be failed, rerun.
  • git tree might be corrupted

image z80