diff --git a/src/z80_ops.inc.c b/src/z80_ops.inc.c index a4f3303..2064a80 100644 --- a/src/z80_ops.inc.c +++ b/src/z80_ops.inc.c @@ -139,9 +139,17 @@ static uint8_t z80_inst_ld_r_hl(Z80 *z80, uint8_t opcode) // static uint8_t z80_inst_ld_de_a(Z80 *z80, uint8_t opcode) /* - LD (nn), A + LD (nn), A (0x32): + Load a into memory address nn. */ -// static uint8_t z80_inst_ld_nn_a(Z80 *z80, uint8_t opcode) +static uint8_t z80_inst_ld_nn_a(Z80 *z80, uint8_t opcode) +{ + (void) opcode; + uint16_t addr = mmu_read_double(z80->mmu, ++z80->regfile.pc); + mmu_write_byte(z80->mmu, addr, z80->regfile.a); + z80->regfile.pc += 2; + return 13; +} /* LD A, I @@ -284,6 +292,23 @@ static uint8_t z80_inst_exx(Z80 *z80, uint8_t opcode) // XOR s +/* + XOR r (0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAF): + Bitwise XOR a with r (8-bit register). +*/ +static uint8_t z80_inst_xor_r(Z80 *z80, uint8_t opcode) +{ + uint8_t *reg = extract_reg(z80, opcode); + uint8_t a = (z80->regfile.a ^= *reg); + + bool parity = !(__builtin_popcount(a) % 2); + update_flags(z80, 0, 0, parity, !!(a & 0x08), 0, !!(a & 0x20), a == 0, + !!(a & 0x80), 0xFF); + + z80->regfile.pc++; + return 4; +} + // CP s /* diff --git a/src/z80_tables.inc.c b/src/z80_tables.inc.c index 5cf9a6d..f1b5120 100644 --- a/src/z80_tables.inc.c +++ b/src/z80_tables.inc.c @@ -52,7 +52,7 @@ static DispatchTable instruction_table = { [0x2F] = z80_inst_unimplemented, // TODO [0x30] = z80_inst_unimplemented, // TODO [0x31] = z80_inst_ld_dd_nn, - [0x32] = z80_inst_unimplemented, // TODO + [0x32] = z80_inst_ld_nn_a, [0x33] = z80_inst_inc_ss, [0x34] = z80_inst_unimplemented, // TODO [0x35] = z80_inst_unimplemented, // TODO @@ -170,14 +170,14 @@ static DispatchTable instruction_table = { [0xA5] = z80_inst_unimplemented, // TODO [0xA6] = z80_inst_unimplemented, // TODO [0xA7] = z80_inst_unimplemented, // TODO - [0xA8] = z80_inst_unimplemented, // TODO - [0xA9] = z80_inst_unimplemented, // TODO - [0xAA] = z80_inst_unimplemented, // TODO - [0xAB] = z80_inst_unimplemented, // TODO - [0xAC] = z80_inst_unimplemented, // TODO - [0xAD] = z80_inst_unimplemented, // TODO + [0xA8] = z80_inst_xor_r, + [0xA9] = z80_inst_xor_r, + [0xAA] = z80_inst_xor_r, + [0xAB] = z80_inst_xor_r, + [0xAC] = z80_inst_xor_r, + [0xAD] = z80_inst_xor_r, [0xAE] = z80_inst_unimplemented, // TODO - [0xAF] = z80_inst_unimplemented, // TODO + [0xAF] = z80_inst_xor_r, [0xB0] = z80_inst_unimplemented, // TODO [0xB1] = z80_inst_unimplemented, // TODO [0xB2] = z80_inst_unimplemented, // TODO