-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
44e39d5
commit ed46459
Showing
6 changed files
with
121 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use crate::{Register16bTarget, CPU}; | ||
|
||
pub fn ld_d16_u16(reg: Register16bTarget) -> impl Fn(&mut CPU) { | ||
move |cpu: &mut CPU| { | ||
let low = cpu.bus.memory[(cpu.pc + 1) as usize]; | ||
let high = cpu.bus.memory[(cpu.pc + 2) as usize]; | ||
cpu.registers.set_u16(reg, u16::from_le_bytes([low, high])); | ||
cpu.pc += 3; | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_ld_d16_u16() { | ||
let mut cpu = CPU::default(); | ||
cpu.bus.memory[1] = 0x01; | ||
cpu.bus.memory[2] = 0x02; | ||
ld_d16_u16(Register16bTarget::BC)(&mut cpu); | ||
assert_eq!(cpu.registers.get_u16(Register16bTarget::BC), 0x0201); | ||
assert_eq!(cpu.pc, 3); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.