From d186950e99f4ea3d18722a8a5887f505deb9dd08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20L=C3=B6ffler?= Date: Wed, 25 Jan 2023 23:44:10 +0100 Subject: [PATCH] 16-bit increment and decrement --- src/emulator/instructions/arithmetic.rs | 12 ++++++++++++ src/emulator/main.rs | 14 +++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/emulator/instructions/arithmetic.rs b/src/emulator/instructions/arithmetic.rs index 517c3c3..58bde33 100644 --- a/src/emulator/instructions/arithmetic.rs +++ b/src/emulator/instructions/arithmetic.rs @@ -68,3 +68,15 @@ pub fn dcr(register: Register, state: &mut EmulatorState) { set_cc(state, result as u16, 0b1101); set_register(register, result, state); } + +/// Increase register pair +pub fn inx(register: Register, state: &mut EmulatorState) { + let (result, _) = get_register_pair(register, state).overflowing_add(1); + set_register_pair(register, result, state); +} + +/// Decrease register pair +pub fn dcx(register: Register, state: &mut EmulatorState) { + let (result, _) = get_register_pair(register, state).overflowing_sub(1); + set_register_pair(register, result, state); +} diff --git a/src/emulator/main.rs b/src/emulator/main.rs index 8863c78..277ec20 100644 --- a/src/emulator/main.rs +++ b/src/emulator/main.rs @@ -62,10 +62,10 @@ fn tick(state: &mut EmulatorState) { 0xfb => state.ei = true, // EI 0xf3 => state.ei = false, // DI 0x76 => { + // HLT if state.ei { todo!() } else { - // HLT println!("HLT called after DI; exiting."); print_state(state); std::process::exit(0); @@ -99,6 +99,18 @@ fn tick(state: &mut EmulatorState) { 0x29 => arithmetic::dad(Register::H, state), 0x39 => arithmetic::dad(Register::SP, state), + // INX + 0x03 => arithmetic::inx(Register::B, state), + 0x13 => arithmetic::inx(Register::D, state), + 0x23 => arithmetic::inx(Register::H, state), + 0x33 => arithmetic::inx(Register::SP, state), + + // DCX + 0x0b => arithmetic::dcx(Register::B, state), + 0x1b => arithmetic::dcx(Register::D, state), + 0x2b => arithmetic::dcx(Register::H, state), + 0x3b => arithmetic::dcx(Register::SP, state), + 0x80..=0x87 => arithmetic::add(register_from_num(instruction & 0xf), state), // ADD 0x88..=0x8f => arithmetic::adc(register_from_num(instruction & 0xf), state), // ADC 0xc6 => arithmetic::adi(next_byte(), state), // ADI