Skip to content

Commit 5ca5c95

Browse files
committed
Fix instruction BIT
1 parent 36d0168 commit 5ca5c95

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/emit.dasc

+20-1
Original file line numberDiff line numberDiff line change
@@ -817,8 +817,27 @@ static bool inst_adc(dasm_State **Dst, gbz80_inst *inst, uint64_t *cycles)
817817
static bool inst_bit(dasm_State **Dst, gbz80_inst *inst, uint64_t *cycles)
818818
{
819819
| print "BIT"
820+
/* get C flag and save it */
821+
| pushfq
822+
| pop tmp1
823+
| and tmp1b, 0x01
824+
| push tmp1
825+
820826
| mov byte state->f_subtract, 0
821-
| bitinst test, inst->op1, inst->op2,
827+
| bitinst test, inst->op1, inst->op2,
828+
829+
| pushfq
830+
/* pop for status flag */
831+
| pop tmp1
832+
/* pop for C flag */
833+
| pop tmp2
834+
| and tmp1b, ~0x01
835+
| or tmp1b, tmp2b
836+
/* set H flag to 1 */
837+
| or tmp1b, 0x10
838+
| push tmp1
839+
| popfq
840+
822841
*cycles += inst->cycles;
823842
return true;
824843
}

0 commit comments

Comments
 (0)