accumulator rotate instructions

that's the rest of the arithmetics
This commit is contained in:
Martin Löffler 2023-01-26 04:51:55 +01:00
parent 08a15a2e51
commit ed05dd5d30
Signed by: FatalErrorCoded
GPG key ID: FFEF368AC076566A
2 changed files with 32 additions and 0 deletions

View file

@ -105,3 +105,28 @@ pub fn dcx(register: Register, state: &mut EmulatorState) {
let (result, _) = get_register_pair(register, state).overflowing_sub(1);
set_register_pair(register, result, state);
}
pub fn rlc(state: &mut EmulatorState) {
let result = state.a.rotate_left(1);
state.a = result;
state.cc.c = result & 0x01 > 0;
}
pub fn rrc(state: &mut EmulatorState) {
state.cc.c = state.a & 0x01 > 0;
state.a = state.a.rotate_right(1);
}
pub fn ral(state: &mut EmulatorState) {
let new_carry = state.a & 0x80 > 0;
let result = state.a << 1;
state.a = result | new_carry as u8;
state.cc.c = new_carry;
}
pub fn rar(state: &mut EmulatorState) {
let new_carry = state.a & 0x01 > 0;
let result = state.a >> 1;
state.a = result | (new_carry as u8) << 7;
state.cc.c = new_carry;
}

View file

@ -111,6 +111,13 @@ fn tick(state: &mut EmulatorState) {
0x2b => arithmetic::dcx(Register::H, state),
0x3b => arithmetic::dcx(Register::SP, state),
// Accumulator rotates
0x07 => arithmetic::rlc(state),
0x0f => arithmetic::rrc(state),
0x17 => arithmetic::ral(state),
0x1f => arithmetic::rar(state),
// Carry and complements
0x27 => panic!("Auxiliary Carry not implemented, unable to execute DAA instruction"),
0x2f => state.a = !state.a, // CMA
0x37 => state.cc.c = true, // STC