Обсуждение:Zilog Z80/Система команд/DAA

Материал из Emuverse

http://pudsoft.com/model2/libs/libz80/z80.c <source lang="c"> /* The DAA opcode

* According to the value in A and the flags set, add a value to A
*
* Flags set   Byte (0..9)(0..9) 
* -------------------------------------------- 
* (None)   + &00 
* Carry:+ &60 
* Subtract:+ &00 
* Subtract+Carry:+ &A0 
* Half-carry:+ &06 
* Half-carry+Carry:+ &66 
* Half-carry+Subtract:+ &FA 
* Half-carry+Subtract+Carry:+ &9A 
* 
* Flags set   Byte (0..9)(A..F) 
* -------------------------------------------- 
* (None)   + &06 
* Carry:+ &66 
* Subtract:+ &00 
* Subtract+Carry:+ &a0 
* Half-carry:+ &06 
* Half-carry+Carry:+ &66 
* Half-carry+Subtract:+ &fa 
* Half-carry+Subtract+Carry:+ &9A 
* 
* Flags set   Byte (A..F)(0..9) 
* -------------------------------------------- 
* (None)   + &60 
* Carry:+ &60 
* Subtract:+ &00 
* Subtract+Carry:+ &A0 
* Half-carry:+ &66 
* Half-carry+Carry:+ &66 
* Half-carry+Subtract:+ &fa 
* Half-carry+Subtract+Carry:+ &9A 
* 
* Flags set   Byte (A..F)(A..F) 
* -------------------------------------------- 
* (None)   + &66 
* Carry:+ &66 
* Subtract:+ &00 
* Subtract+Carry:+ &a0 
* Half-carry:+ &66 
* Half-carry+Carry:+ &66 
* Half-carry+Subtract:+ &fa 
* Half-carry+Subtract+Carry:+ &9A 
*/	

static int DAA_BYTETYPE[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1 };

static byte DAA_ADJUSTMENT[4][8] = { { 0x00, 0x60, 0x00, 0xA0, 0x06, 0x66, 0xFA, 0x9A }, { 0x06, 0x66, 0x00, 0xA0, 0x06, 0x66, 0xFA, 0x9A }, { 0x60, 0x60, 0x00, 0xA0, 0x66, 0x66, 0xFA, 0x9A }, { 0x66, 0x66, 0x00, 0xA0, 0x66, 0x66, 0xFA, 0x9A } };

static void doDAA (Z80Context *ctx) { /* (0..9)(0..9) = 0 */ /* (0..9)(A..F) = 1 */ /* (A..F)(0..9) = 2 */ /* (A..F)(A..F) = 3 */ int byteType = DAA_BYTETYPE[BR.A] | ((DAA_BYTETYPE[BR.A >> 4]) << 1);

int flagMask = 0; if (GETFLAG(F_C)) flagMask |= 1; if (GETFLAG(F_S)) flagMask |= 2; if (GETFLAG(F_H)) flagMask |= 4;

BR.A += DAA_ADJUSTMENT[byteType][flagMask];

adjustFlags(ctx, BR.A); } </source>