ld_immediate_word

This commit is contained in:
Alex Janka 2023-01-16 11:46:00 +11:00
parent 289acd0070
commit ba69b1070b

View file

@ -116,23 +116,18 @@ struct CPU {
impl CPU {
fn exec_next(&mut self) -> u8 {
let opcode = self.next_opcode();
println!("opcode: {:#X}", opcode);
match opcode {
0x0 => {
// noop
}
0x01 => {
self.state.bc.as_u8s.left = self.next_opcode();
self.state.bc.as_u8s.right = self.next_opcode();
self.state.bc = self.ld_immediate_word();
}
0x11 => {
self.state.de.as_u8s.left = self.next_opcode();
self.state.de.as_u8s.right = self.next_opcode();
self.state.de = self.ld_immediate_word();
}
0x21 => {
self.state.de.as_u8s.left = self.next_opcode();
self.state.de.as_u8s.right = self.next_opcode();
self.state.hl = self.ld_immediate_word();
}
0x2C => {
unsafe {
@ -145,9 +140,7 @@ impl CPU {
};
}
0xC3 => {
let (a, b) = (self.next_opcode(), self.next_opcode());
self.state.pc.as_u8s.left = a;
self.state.pc.as_u8s.right = b;
self.state.pc = self.ld_immediate_word();
}
_ => {
panic!("unimplemented opcode: {:#X}", opcode);
@ -155,6 +148,7 @@ impl CPU {
};
return opcode;
}
fn next_opcode(&mut self) -> u8 {
unsafe {
let opcode = self.memory.get(self.state.pc.as_u16);
@ -162,6 +156,15 @@ impl CPU {
return opcode;
};
}
fn ld_immediate_word(&mut self) -> Register {
Register {
as_u8s: Inner {
left: self.next_opcode(),
right: self.next_opcode(),
},
}
}
}
fn main() {
@ -175,10 +178,10 @@ fn main() {
};
loop {
cpu.exec_next();
pause();
}
}
#[allow(dead_code)]
fn pause() {
io::stdin().read_line(&mut String::new()).unwrap();
}