feat: ld deref hl opcodes

This commit is contained in:
EliseZeroTwo 2021-11-28 17:49:27 +01:00
parent 06c7197468
commit c7fefe86ca
No known key found for this signature in database
GPG key ID: E6D56A6F7B7991DE
2 changed files with 33 additions and 0 deletions

View file

@ -207,6 +207,13 @@ pub fn tick_cpu(state: &mut Gameboy) {
0x6d => load_store_move::ld_l_l,
0x6e => load_store_move::ld_l_deref_hl,
0x6f => load_store_move::ld_l_a,
0x70 => load_store_move::ld_deref_hl_b,
0x71 => load_store_move::ld_deref_hl_c,
0x72 => load_store_move::ld_deref_hl_d,
0x73 => load_store_move::ld_deref_hl_e,
0x74 => load_store_move::ld_deref_hl_h,
0x75 => load_store_move::ld_deref_hl_l,
0x77 => load_store_move::ld_deref_hl_a,
0x78 => load_store_move::ld_a_b,
0x79 => load_store_move::ld_a_c,
0x7a => load_store_move::ld_a_d,

View file

@ -380,3 +380,29 @@ pub fn ld_deref_imm_u16_a(state: &mut Gameboy) -> CycleResult {
_ => unreachable!(),
}
}
macro_rules! define_ld_reg_imm_u8 {
($lreg:ident) => {
paste::paste! {
pub fn [<ld_deref_hl_ $lreg>](state: &mut Gameboy) -> CycleResult {
match state.registers.cycle {
0 => {
state.cpu_write_u8(state.registers.get_hl(), state.registers.$lreg);
state.registers.opcode_bytecount = Some(1);
CycleResult::NeedsMore
},
1 => CycleResult::Finished,
_ => unreachable!(),
}
}
}
};
}
define_ld_reg_imm_u8!(b);
define_ld_reg_imm_u8!(c);
define_ld_reg_imm_u8!(d);
define_ld_reg_imm_u8!(e);
define_ld_reg_imm_u8!(h);
define_ld_reg_imm_u8!(l);
define_ld_reg_imm_u8!(a);