Es otra característica undocumentada del Z80. Creo que la descubrio Patrik Rak autor del emulador ZXDS

http://www.worldofspectrum.org/forums/discussion/41704/redirect/p1

Y aqui una bateria de tests que hizo Patrik por acá:

http://www.worldofspectrum.org/forums/discussion/41834/new-z80-cpu-emulation-tester#latest


Parece que se implementa asi:
" In actual fact, we'll probably model our Q register in such a way that Q takes the value 0 if flags change, but takes the value F & ((1 << 3) | (1 << 5)) when flags are left unchanged."


Como se lee el valor de dicho flag? no se pero afecta comportamiento de scf y ccf, que se pueden validar mediante z80full.tap.
Retrovirtualmachine hace:

"
Si la instrucción cambia flags q=1 sino q=0

y luego en scf y ccf los bits 3 y 5:

si q=1 son una copia del registro A

si q=0 son A or F (solo los bits 3 y 5) vamos en mi código:

    void scf(z80* z)
    {
      uint8_t v=z->r.q ? (z->r.a & 0x28) : ((z->r.f | z->r.a) & 0x28);
      z->r.f=(z->r.f & 0xc4) | v | 0x1;

      z->r.q=1;
      z->T=4;
    }



y

    void ccf(z80* z)
    {
      uint8_t c=z->r.f & 0x1;
      uint8_t nc=c ? 0 : 0x1;
      uint8_t v=z->r.q ? (z->r.a & 0x28) : ((z->r.f | z->r.a) & 0x28);
      z->r.f=(z->r.f & 0xc4) | v | (c<<4) | nc;

      z->r.q=1;
      z->T=4;
    }


En cuanto a lo de bit n,(hl) si te falla es por el memptr el registro q no influye aquí como lo hago yo:

Código: Seleccionar todo
    z->r.f=(sz53cFlags[v] & 0x80) | (sz53cFlags[z->r.mptrh] & 0x28) | ((v) ? 0x10 : 0x54) | (z->r.f & 0x1);
      z->r.q=1;



"
