#2 DA A emulation is incorrect

open
nobody
None
5
2008-06-21
2008-06-21
Anonymous
No

It adds '9' to each nibble when it should be adding '6'.

Also I don't think it sets the carry flag correctly. I am using the following code, which is correct as far as my testing goes:

//____________________________________________________________________________
void ds5002_cpu::DA()
{
unsigned result = ACC();

if ( ( result & 0x0F ) > 0x09 || AC() )
{
result += 6;
}
if ( ( result & 0x0100 ) != 0 )
{
C( true );
}
if ( ( result & 0xF0 ) > 0x90 || C() )
{
result += 0x60;
}
if ( ( result & 0x0100 ) != 0 )
{
C( true );
}
ACC( result & 0xFF );
}

Discussion