outi instruction

By inchl

Supporter (15)

inchl's picture

31-03-2020, 11:44

According to the z80 specification the outi instruction does not affect the carry flag. However when I test my software in openMsx, it does....

Is openMSX doing it wrong, or is the outi instruction on the msx platform with some side effects?

Stephan

Login or register to post comments

By wouter_

Champion (426)

wouter_'s picture

31-03-2020, 12:29

Hi inchl, thanks for your report.

OpenMSX implements the carry flag in 'outi' as described in section "4.3 I/O Block Instructions" in this document. OpenMSX also passes the zexall test-suite (although I don't know how well it covers the 'outi' instruction).

So I think in this case your 'z80 specification' was incomplete. But to be sure also verify this on a real MSX. (And let us know the results).

By inchl

Supporter (15)

inchl's picture

31-03-2020, 12:36

Ok, thanks.

During development I used the following document:
http://clrhome.org/table/
and
https://learn.cemetech.net/index.php/Z80:Opcodes:OUTI

Are these docs incorrect?

By lintweaker

Master (227)

lintweaker's picture

31-03-2020, 13:09

Hmm, just checked the official Zilog Z80 CPU user manual. It states the C flag is not affected.
Doc: UM0080.pdf
page 323

By bore

Expert (116)

bore's picture

31-03-2020, 13:59

Well, it is still necessary to test what the real hardware does.
If the emulator follows the documentation and the documentation and hardware differs then software that works on real hardware might fail on the emulator.

By Dolphin101546015

Master (254)

Dolphin101546015's picture

31-03-2020, 22:16

Flags are set as follows:

S, Z, F5, F3 from decrement B (officially - S is unknown; information on Z matches);
N - copy of the 7th bit of the value received / transmitted to the port (according to official data it is 1);
Further, to obtain CY (officially - does not change) and HC (officially - unknown):

Add one to the value of register C, if the instruction increased HL, otherwise subtract one;
Add to this value the byte received or transmitted to the port;
Copy the flag of the transfer of this operation to the CY and HY flags (that is, they will be the same).
PV (officially unknown) depends on the value of the registers B, C and the transmitted byte (according to Pedro Gimeno (pgimeno@geocities.com))

PS: Except several clones: КР1858ВМ1/U880, where CY (HC and PV?) is not affected.

By pgimeno

Master (130)

pgimeno's picture

04-04-2020, 15:40

Dolphin101546015 wrote:

Flags are set as follows:

S, Z, F5, F3 from decrement B (officially - S is unknown; information on Z matches);
N - copy of the 7th bit of the value received / transmitted to the port (according to official data it is 1);
Further, to obtain CY (officially - does not change) and HC (officially - unknown):

Add one to the value of register C, if the instruction increased HL, otherwise subtract one;
Add to this value the byte received or transmitted to the port;
Copy the flag of the transfer of this operation to the CY and HY flags (that is, they will be the same).
PV (officially unknown) depends on the value of the registers B, C and the transmitted byte (according to Pedro Gimeno (pgimeno@geocities.com))

Man, that's SO long ago oO That seems to be taken from this document: http://gaby.de/z80/z80undoc3.txt

Nowadays I'm no longer confident that these results are accurate. I think that it's more likely that I didn't consider some other variables.

Edit: According to Sean Young's "Undocumented Z80 documented":

Quote:

And now the for OUTI/OTIR/OUTD/OTDR instructions. Take state of the L after the increment
or decrement of HL; add the value written to the I/O port to; call that k for now. If k > 255,
then the CF and HF flags are set. The PF flags is set like the parity of k bitwise and'ed with 7,
bitwise xor'ed with B.

HF and CF Both set if ((HL) + L > 255)

PF The parity of ((((HL) + L) & 7) xor B)

Anyway, for the OP, the bottom line is that indeed, OUTI modifies the carry flag in many Z80's.

By Dolphin101546015

Master (254)

Dolphin101546015's picture

05-04-2020, 21:17

pgimeno wrote:

Man, that's SO long ago oO That seems to be taken from this document: http://gaby.de/z80/z80undoc3.txt

No, I using info from russian testers, maybe they all use same tests from one space, idk.
One good known: official z80 manual is wrong and have many errors.