diff --git a/src/emulator/instructions/transfer.rs b/src/emulator/instructions/transfer.rs index 9af545d..db7102e 100644 --- a/src/emulator/instructions/transfer.rs +++ b/src/emulator/instructions/transfer.rs @@ -1,4 +1,4 @@ -use crate::{get_register, set_register, structs::get_register_pair, EmulatorState, Register}; +use crate::{get_register, get_register_pair, set_register, EmulatorState, Register}; /// Move (copy) value from source to destination register pub fn mov(src: Register, dest: Register, state: &mut EmulatorState) { @@ -22,3 +22,15 @@ pub fn ldax(register: Register, state: &mut EmulatorState) { let address = get_register_pair(register, state); state.a = state.memory[address as usize]; } + +/// Store a 16-bit word from H and L to the specified address +pub fn shld(address: u16, state: &mut EmulatorState) { + state.memory[address as usize] = state.l; + state.memory[address as usize + 1] = state.h; +} + +/// Load a 16-bit word into H and L from the specified address +pub fn lhld(address: u16, state: &mut EmulatorState) { + state.l = state.memory[address as usize]; + state.h = state.memory[address as usize + 1]; +} diff --git a/src/emulator/main.rs b/src/emulator/main.rs index abfe264..a750231 100644 --- a/src/emulator/main.rs +++ b/src/emulator/main.rs @@ -90,6 +90,14 @@ fn tick(state: &mut EmulatorState) { 0x32 => state.memory[state.next_word() as usize] = state.a, // STA 0x3a => state.a = state.memory[state.next_word() as usize], // LDA + // 16-bit transfer instructions + 0x01 => set_register_pair(Register::B, state.next_word(), state), // LXI B + 0x11 => set_register_pair(Register::D, state.next_word(), state), // LXI D + 0x21 => set_register_pair(Register::H, state.next_word(), state), // LXI H + 0x31 => set_register_pair(Register::SP, state.next_word(), state), // LXI SP + 0x22 => transfer::shld(state.next_word(), state), // SHLD + 0x2a => transfer::lhld(state.next_word(), state), // LHLD + /* Maths */ // INR 0x04 => arithmetic::inr(Register::B, state),