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

Support the SCF/CCF behaviour discovered by Patrik Rak #42

Open
kosarev opened this issue Nov 7, 2021 · 5 comments
Open

Support the SCF/CCF behaviour discovered by Patrik Rak #42

kosarev opened this issue Nov 7, 2021 · 5 comments
Labels

Comments

@kosarev
Copy link
Owner

kosarev commented Nov 7, 2021

The test:
https://github.com/raxoft/z80test/blob/master/src/z80ccf.asm

The original discussion on WoS:
https://worldofspectrum.org/forums/discussion/41704/scf-ccf-flags-new-discovery

@kosarev
Copy link
Owner Author

kosarev commented Jul 10, 2022

After 912d1bf, it seems we now can formally prove that at least what concerns the A and F register values, Patrik and Woody were right.

$ ./z80sim.py
ccf reg_f3                                
old state f3                              
new state (or f3 a3)                      
expected f3                               
22-07-10 22:41:22       Traceback (most recent call last):
  File "./z80sim.py", line 1997, in <module>
    main()
...

@kosarev
Copy link
Owner Author

kosarev commented Sep 27, 2022

Hmm, the simulation indicates that not all instructions updating flags cause the following scf/ccf to set flags 3 and 5 to A instead of (A | F), e.g., cpl and rlca/rrca/rla/rra:

if instr == 'scf/ccf':

But in the same time somehow the tests from Patrik do seem to test these instructions and (I presume) still pass:
https://github.com/raxoft/z80test/blob/master/src/tests.asm#L73

This clearly needs some more looking into it.

@kosarev
Copy link
Owner Author

kosarev commented Oct 6, 2022

Simulation indicates that whether the corresponding bits of F participate in the values of flags 3 and 5 of scf/ccf depends on the opcode the instruction latch contains at the beginning of execution of these instructions. Symbolising the latch further confirms that amongst unprefixed instructions F does not contribute to the flags only after scf/ccf themselves, alu r/n, inc/dec r and add hl, rp. What happens with the latch during processing of prefixed instructions is yet to be understood.

The way things look at the moment, the logic has little to do with updating flags 3 and 5 or any other flags and is dictated by the contents of the latch.

is_scf_ccf = (op == 0x37) | (op == 0x3f)

@redcode
Copy link

redcode commented Oct 7, 2022

Hello, we have spent the last year researching the flag behavior of the ccf/scf instructions. Please, join our discord server, we would like to talk with you: https://discord.gg/N3exr4Z6

Patrik, Woody, Hoglet, TonyB and others are on our server.

@kosarev
Copy link
Owner Author

kosarev commented Oct 15, 2022

This clearly needs some more looking into it.

#51 (comment) may probably explain this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants