New discovery on Z80 I/O block instructions

Struggling with Fuse or trying to find an emulator with a specific feature. Ask your questions here.
Post Reply
User avatar
ZjoyKiLer
Dizzy
Posts: 67
Joined: Thu Sep 09, 2021 3:20 pm

New discovery on Z80 I/O block instructions

Post by ZjoyKiLer »

I've discovered a new undocumented behavior of the inir/indr/otir/otdr instructions:

As in cpir/cpdr/ldir/lddr, when the repeat condition is met, the 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 (AKA hoglet)), but until now it was not known that MEMPTR 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).

After adding this behavior to my Z80 core, z80memptr.tap from Patrik Rak's Zilog Z80 Test Suite v1.2 fails in the following 2 steps:

Code: Select all

102 INIR->NOP'            FAILED
CRC:F3B1BE2F   Expected:0A537B63
103 INDR->NOP'            FAILED
CRC:F3B1BE2F   Expected:0A537B63
Which matches the results obtained on real hardware by Richard Chandler, who kindly tried the test at my request on one of his machines with NEC CPU:

Image
Image

Of course, this "new" behavior has been tested on Visual Z80 Remix.

I've opened a pull request to fix Patrik's test suite: https://github.com/raxoft/z80test/pull/3
User avatar
R-Tape
Site Admin
Posts: 6409
Joined: Thu Nov 09, 2017 11:46 am

Re: New discovery on Z80 I/O block instructions

Post by R-Tape »

I look forward to someone writing a game that tests this in the similar way to MEMPTR snake. :dance
User avatar
Morkin
Bugaboo
Posts: 3277
Joined: Mon Nov 13, 2017 8:50 am
Location: Bristol, UK

Re: New discovery on Z80 I/O block instructions

Post by Morkin »

Every emulator author after reading this:

Image
My Speccy site: thirdharmoniser.com
TheMartian
Microbot
Posts: 100
Joined: Wed Feb 03, 2021 5:18 am

Re: New discovery on Z80 I/O block instructions

Post by TheMartian »

Hi!

Does this happen in all Z80 models, or just NEC? I'm curious.

I'll try later to execute on my machines. Any suggestion or request?
User avatar
Lethargeek
Manic Miner
Posts: 744
Joined: Wed Dec 11, 2019 6:47 am

Re: New discovery on Z80 I/O block instructions

Post by Lethargeek »

TheMartian wrote: Fri Dec 01, 2023 1:05 pm Does this happen in all Z80 models, or just NEC? I'm curious.
couldn't be all, not every one failed Patrik's test before afair, otherwise too many people would complain
jamesh
Dizzy
Posts: 83
Joined: Thu Jul 06, 2023 6:36 pm

Re: New discovery on Z80 I/O block instructions

Post by jamesh »

I not sure what kind of CPU I have, there is big "Z" with Zilog under it (original Zilog's?), but it fails those two tests. Issue 6A board.
User avatar
ZjoyKiLer
Dizzy
Posts: 67
Joined: Thu Sep 09, 2021 3:20 pm

Re: New discovery on Z80 I/O block instructions

Post by ZjoyKiLer »

TheMartian wrote: Fri Dec 01, 2023 1:05 pm Hi!

Does this happen in all Z80 models, or just NEC? I'm curious.

I'll try later to execute on my machines. Any suggestion or request?
Confirmed on Zilog and NEC. I assume that ST CMOS models also have this behaviour, but it is not confirmed.

USSR and MME models could behave differently.
User avatar
ZjoyKiLer
Dizzy
Posts: 67
Joined: Thu Sep 09, 2021 3:20 pm

Re: New discovery on Z80 I/O block instructions

Post by ZjoyKiLer »

Lethargeek wrote: Fri Dec 01, 2023 1:55 pm couldn't be all, not every one failed Patrik's test before afair, otherwise too many people would complain
Actually, I don't know of anyone who specifically tried z80memptr.tap on a real Zilog or NEC on Sinclair hardware until yesterday. People usually try z80full.tap and z80ccf.tap. I have a Russian friend who tried z80memptr.tap on USSR Z80 clones, and failed several steps. He used a Profi, a Russian Speccy clone, which tends to produce CRC errors in the I/O instructions because the values read from the I/O ports are not the expected ones...
Last edited by ZjoyKiLer on Fri Dec 01, 2023 3:49 pm, edited 1 time in total.
TheMartian
Microbot
Posts: 100
Joined: Wed Feb 03, 2021 5:18 am

Re: New discovery on Z80 I/O block instructions

Post by TheMartian »

Looks like I've got a round of testing to do. I thought that z80full.tap already covered the MEMPTR.

Live and learn... :D
User avatar
Weiv
Microbot
Posts: 177
Joined: Fri Apr 06, 2018 5:28 pm
Location: Ukraine

Re: New discovery on Z80 I/O block instructions

Post by Weiv »

Morkin wrote: Fri Dec 01, 2023 11:16 am Every emulator author after reading this:

Image
Not me) I'm glad to update my emulator everytime when new info about emulation accuracy comes. I know that there is no perfection in emulation but we can get as close to it as we can :)
User avatar
Lethargeek
Manic Miner
Posts: 744
Joined: Wed Dec 11, 2019 6:47 am

Re: New discovery on Z80 I/O block instructions

Post by Lethargeek »

ZjoyKiLer wrote: Fri Dec 01, 2023 3:20 pm Actually, I don't know of anyone who specifically tried z80memptr.tap on a real Zilog or NEC until yesterday on Sinclair hardware.
i dont remember old discussions details now, but do you mean even Patrik himself never tried it on a real hw :?
ZjoyKiLer wrote: Fri Dec 01, 2023 3:20 pm People usually try z80full.tap and z80ccf.tap. I have a Russian friend who tried z80memptr.tap on USSR Z80 clones, and failed several steps.
if it was T34Bx1 then it's supposed to have slightly different memptr behaviour afair
User avatar
ZjoyKiLer
Dizzy
Posts: 67
Joined: Thu Sep 09, 2021 3:20 pm

Re: New discovery on Z80 I/O block instructions

Post by ZjoyKiLer »

Lethargeek wrote: Fri Dec 01, 2023 3:50 pm i dont remember old discussions details now, but do you mean even Patrik himself never tried it on a real hw :?
yep... I was there when Patrik was working on the new releases of his test suite. We knew about new discoveries about the CCF/SCF instructions and the flags of block instructions, which motivated the update. We didn't check all the tapes of the new version on real hardware, sorry.
Lethargeek wrote: Fri Dec 01, 2023 3:50 pm if it was T34Bx1 then it's supposed to have slightly different memptr behaviour afair
Yes, a T34VM1, and MME models too, 80-CPU, U880...
Last edited by ZjoyKiLer on Fri Dec 01, 2023 4:51 pm, edited 1 time in total.
User avatar
Lethargeek
Manic Miner
Posts: 744
Joined: Wed Dec 11, 2019 6:47 am

Re: New discovery on Z80 I/O block instructions

Post by Lethargeek »

ZjoyKiLer wrote: Fri Dec 01, 2023 3:57 pm yep... I was there when Patrik was working on the new releases of his test suite. We knew about new discoveries about the CCF/SCF instructions and the flags of block instructions, which motivated the update. We didn't check all the tapes of the new version on real hardware, sorry.
owww... trust no one :x
Patrik Rak
Microbot
Posts: 117
Joined: Mon Apr 13, 2020 3:07 pm

Re: New discovery on Z80 I/O block instructions

Post by Patrik Rak »

Lethargeek wrote: Fri Dec 01, 2023 3:50 pm i dont remember old discussions details now, but do you mean even Patrik himself never tried it on a real hw :?
There was so many people testing the interrupted flags on the real hardware, using both mine and Ped7g's tests, that it never occurred to anyone the memptr behavior was not tested. Apparently, many people think that z80full covers it all. Or perhaps it was tested on hardware which supplied wrong IN value, so we dismissed it as that. I think it comes as a surprise to everyone involved that no one noticed before.

Well, FWIW, the test suite was updated to 1.2a with the updated CRCs now. Apologies to everyone and thanks to ZjoyKiLer for finding this out.
User avatar
Zoran
Drutt
Posts: 18
Joined: Fri Aug 16, 2019 12:56 pm

Re: New discovery on Z80 I/O block instructions

Post by Zoran »

Weiv wrote: Fri Dec 01, 2023 3:41 pm Not me) I'm glad to update my emulator everytime when new info about emulation accuracy comes. I know that there is no perfection in emulation but we can get as close to it as we can :)
I totally agree.
Many thanks to ZJoyKiller for investigation, to people who tested on hardware, to Patrik for his testing suite (version 1.2 of memptr test, imperfect as it was, actually revealed this).
Now after other people did the hard work, implementing it was easy. :D
User avatar
ZjoyKiLer
Dizzy
Posts: 67
Joined: Thu Sep 09, 2021 3:20 pm

Re: New discovery on Z80 I/O block instructions

Post by ZjoyKiLer »

BTW, many thanks to @TheMartian, who is testing all the tapes from Patrik's Zilog Z80 Test Suite on many of her machines, so that finally everything is 100% tested once and for all.

Some of the results can be checked here.
Post Reply