(nw) z8 : added the DA instruction

This commit is contained in:
Robbbert 2018-09-15 22:25:36 +10:00
parent 94d215f4a1
commit 77b986a85d
2 changed files with 19 additions and 1 deletions

View File

@ -12,7 +12,6 @@
- strobed I/O
- expose register file to disassembler
- decimal adjust instruction
- timer Tin/Tout modes
- serial
- instruction pipeline

View File

@ -308,6 +308,25 @@ INSTRUCTION( cp_IR1_IM ) { mode_IR1_IM(compare) }
void z8_device::decimal_adjust(uint8_t dst)
{
uint8_t data = register_read(dst);
uint16_t new_data = data;
if (flag(D))
{
if (flag(H) | ((data&0xf)>9)) new_data-=6;
if (flag(C) | (data>0x99)) new_data-=0x60;
}
else
{
if (flag(H) | ((data&0xf)>9)) new_data+=6;
if (flag(C) | (data>0x99)) new_data+=0x60;
}
set_flag_c(new_data & 0x100);
set_flag_s(new_data & 0x80);
new_data &= 0xff;
set_flag_z(new_data == 0);
// officially, v is undefined
register_write(dst, new_data);
}
INSTRUCTION( da_R1 ) { mode_R1(decimal_adjust) }