ld_immediate_word
This commit is contained in:
parent
289acd0070
commit
ba69b1070b
1 changed files with 15 additions and 12 deletions
27
src/main.rs
27
src/main.rs
|
@ -116,23 +116,18 @@ struct CPU {
|
||||||
impl CPU {
|
impl CPU {
|
||||||
fn exec_next(&mut self) -> u8 {
|
fn exec_next(&mut self) -> u8 {
|
||||||
let opcode = self.next_opcode();
|
let opcode = self.next_opcode();
|
||||||
println!("opcode: {:#X}", opcode);
|
|
||||||
|
|
||||||
match opcode {
|
match opcode {
|
||||||
0x0 => {
|
0x0 => {
|
||||||
// noop
|
// noop
|
||||||
}
|
}
|
||||||
0x01 => {
|
0x01 => {
|
||||||
self.state.bc.as_u8s.left = self.next_opcode();
|
self.state.bc = self.ld_immediate_word();
|
||||||
self.state.bc.as_u8s.right = self.next_opcode();
|
|
||||||
}
|
}
|
||||||
0x11 => {
|
0x11 => {
|
||||||
self.state.de.as_u8s.left = self.next_opcode();
|
self.state.de = self.ld_immediate_word();
|
||||||
self.state.de.as_u8s.right = self.next_opcode();
|
|
||||||
}
|
}
|
||||||
0x21 => {
|
0x21 => {
|
||||||
self.state.de.as_u8s.left = self.next_opcode();
|
self.state.hl = self.ld_immediate_word();
|
||||||
self.state.de.as_u8s.right = self.next_opcode();
|
|
||||||
}
|
}
|
||||||
0x2C => {
|
0x2C => {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -145,9 +140,7 @@ impl CPU {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
0xC3 => {
|
0xC3 => {
|
||||||
let (a, b) = (self.next_opcode(), self.next_opcode());
|
self.state.pc = self.ld_immediate_word();
|
||||||
self.state.pc.as_u8s.left = a;
|
|
||||||
self.state.pc.as_u8s.right = b;
|
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
panic!("unimplemented opcode: {:#X}", opcode);
|
panic!("unimplemented opcode: {:#X}", opcode);
|
||||||
|
@ -155,6 +148,7 @@ impl CPU {
|
||||||
};
|
};
|
||||||
return opcode;
|
return opcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn next_opcode(&mut self) -> u8 {
|
fn next_opcode(&mut self) -> u8 {
|
||||||
unsafe {
|
unsafe {
|
||||||
let opcode = self.memory.get(self.state.pc.as_u16);
|
let opcode = self.memory.get(self.state.pc.as_u16);
|
||||||
|
@ -162,6 +156,15 @@ impl CPU {
|
||||||
return opcode;
|
return opcode;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn ld_immediate_word(&mut self) -> Register {
|
||||||
|
Register {
|
||||||
|
as_u8s: Inner {
|
||||||
|
left: self.next_opcode(),
|
||||||
|
right: self.next_opcode(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -175,10 +178,10 @@ fn main() {
|
||||||
};
|
};
|
||||||
loop {
|
loop {
|
||||||
cpu.exec_next();
|
cpu.exec_next();
|
||||||
pause();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
fn pause() {
|
fn pause() {
|
||||||
io::stdin().read_line(&mut String::new()).unwrap();
|
io::stdin().read_line(&mut String::new()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue