Discussion:
Gameboy Z80: How should RLCA and RRCA behave?
(too old to reply)
Mateusz Viste
2010-08-28 12:15:42 UTC
Permalink
Hi!

I'm working on a small project these days, trying to emulate a GameBoy's
Z80 CPU.
I have some doubts about the RLCA and RRCA instructions, and don't know
how they should be implemented exactly...

What I am wondering about, is what to do with flag Z?
The official Z80 manual says that flag Z should be left untouched (but
still... the GameBoy is not built on an "official" Z80).

In the document "GameBoy CPU manual v1.01" I see:
Z - Set if result is zero.

Hmm... Who should I believe?

Also, I tested the RRCA/RLCA behavior on the NO$GMB emulator (which
integrates a very nice debugger), and it's even more surprising:
Flag Z is set only when register A changes from a non-zero value to zero.
So if A is already 0, NO$GMB does'nt set Z after RRCA/RLCA.

Where could I find 100% sure information about that?

Best regards,
Mateusz Viste
Mateusz Viste
2010-08-28 13:26:02 UTC
Permalink
Post by Mateusz Viste
Also, I tested the RRCA/RLCA behavior on the NO$GMB emulator (which
Flag Z is set only when register A changes from a non-zero value to
zero. So if A is already 0, NO$GMB does'nt set Z after RRCA/RLCA.
Well, I wrote a bit too fast - there's no way a non-zero value become zero
after a RRCA/RRLA operation :-P
In fact, the NO$GMB emulator is *always* resetting Z flag after a
RRCA/RRLA operation (even if accumulator is zero).

Still, I have no clue about what should be the "correct" emulation of a
Z80-like GameBoy CPU...

Best regards,
Mateusz Viste
pgm
2010-09-15 15:26:45 UTC
Permalink
Post by Mateusz Viste
Post by Mateusz Viste
Also, I tested the RRCA/RLCA behavior on the NO$GMB emulator (which
Flag Z is set only when register A changes from a non-zero value to
zero. So if A is already 0, NO$GMB does'nt set Z after RRCA/RLCA.
Well, I wrote a bit too fast - there's no way a non-zero value become zero
after a RRCA/RRLA operation :-P
In fact, the NO$GMB emulator is *always* resetting Z flag after a
RRCA/RRLA operation (even if accumulator is zero).
Still, I have no clue about what should be the "correct" emulation of a
Z80-like GameBoy CPU...
Best regards,
Mateusz Viste
In my opinion, the RRCA/RLCA instructions either behave as they do on
the real Z80 (I've seen no mention of modifications to these opcodes
anywhere) or they've been "adjusted" to act as the other RRC/RLC
instructions do. I vote for the former which means the H and N flags
(Ac and N in the Z80) are reset (set to 0) and the Z and C flags are
untouched.

Regards.

Loading...