Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpu/z80/z80.cpp: More accurate emulation of WZ in I/O block instructions #11812

Merged
merged 1 commit into from
Dec 3, 2023

Conversation

redcode
Copy link
Contributor

@redcode redcode commented Dec 2, 2023

Credits

  • Z80 CPU: Undocumented behavior of WZ - Manuel Sainz de Baranda y Goñi (redcode)

Description

This tiny PR adds emulation of a recently discovered undocumented behavior of the inir/indr/otir/otdr instructions:

As in cpir/cpdr/ldir/lddr, when the repeat condition is met, the Z80 CPU generates an extra M-cycle of 5 T-states to decrement PC. This M-cycle performs additional flag changes (discovered and cracked by David Banks), but until now it was not known that the WZ register is also modified, being set, as in all other block instructions during this M-cycle, to PCi + 1 (PCi = value of PC at the start of the instruction, before it is incremented).

Testing

As can be checked in the links provided below, this behavior has been verified on real hardware and in electronic simulations. It has been tested on 1 Zilog NMOS and 2 NEC NMOS processors. Also, the most important and so far only test suite capable of partially detecting this behavior has been updated accordingly.

References

@holub
Copy link
Contributor

holub commented Dec 2, 2023

Great job on both finding and fixing yourself!

@cuavas cuavas merged commit 5804471 into mamedev:master Dec 3, 2023
Luigi30 pushed a commit to Luigi30/mame that referenced this pull request Dec 16, 2023
The inir, indr, otir and otdr instructions modify WZ when updating PC when the repeat condition is met.
einstein95 pushed a commit to einstein95/mame that referenced this pull request Mar 2, 2024
The inir, indr, otir and otdr instructions modify WZ when updating PC when the repeat condition is met.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants