From ed05dd5d305e47a9b20083392f9c4760193cbc33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20L=C3=B6ffler?= Date: Thu, 26 Jan 2023 04:51:55 +0100 Subject: [PATCH] accumulator rotate instructions that's the rest of the arithmetics --- src/emulator/instructions/arithmetic.rs | 25 +++++++++++++++++++++++++ src/emulator/main.rs | 7 +++++++ 2 files changed, 32 insertions(+) diff --git a/src/emulator/instructions/arithmetic.rs b/src/emulator/instructions/arithmetic.rs index 6a5f77f..c5ba470 100644 --- a/src/emulator/instructions/arithmetic.rs +++ b/src/emulator/instructions/arithmetic.rs @@ -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; +} diff --git a/src/emulator/main.rs b/src/emulator/main.rs index 7c9fffb..0569b02 100644 --- a/src/emulator/main.rs +++ b/src/emulator/main.rs @@ -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