diff --git a/src/devices/cpu/z8/z8.cpp b/src/devices/cpu/z8/z8.cpp index 3545b7cf620..9b2febe17fc 100644 --- a/src/devices/cpu/z8/z8.cpp +++ b/src/devices/cpu/z8/z8.cpp @@ -12,7 +12,6 @@ - strobed I/O - expose register file to disassembler - - decimal adjust instruction - timer Tin/Tout modes - serial - instruction pipeline diff --git a/src/devices/cpu/z8/z8ops.hxx b/src/devices/cpu/z8/z8ops.hxx index fbab7c3385c..2e42640a344 100644 --- a/src/devices/cpu/z8/z8ops.hxx +++ b/src/devices/cpu/z8/z8ops.hxx @@ -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) }