Stub 8-bit LD Instructions

This commit is contained in:
Rekai Musuka
2020-07-28 23:58:50 -05:00
parent 167c267e36
commit 0f85e6702b
3 changed files with 180 additions and 0 deletions

View File

@@ -1,7 +1,50 @@
use super::instructions::Instruction;
// Gameboy CPU
pub struct LR35902 {
sp: u16,
pc: u16,
reg: Registers,
}
impl LR35902 {
pub fn cycle(&mut self) {
let opcode = Self::fetch();
self.decode(opcode);
Self::execute();
}
fn fetch() -> u8 {
unimplemented!()
}
fn decode(&mut self, opcode: u8) {
// Source: https://gb-archive.github.io/salvage/decoding_gbz80_opcodes/Decoding%20Gamboy%20Z80%20Opcodes.html
// x = the opcode's 1st octal digit (i.e. bits 7-6)
// y = the opcode's 2nd octal digit (i.e. bits 5-3)
// z = the opcode's 3rd octal digit (i.e. bits 2-0)
// p = y rightshifted one position (i.e. bits 5-4)
// q = y modulo 2 (i.e. bit 3)
let x = opcode >> 6;
let y = (opcode & 0b00111000) >> 3; // 0b00111000 = 0x38
let z = opcode & 0b00000111; // 0b00000111 = 0x07
let p = y >> 1;
let q = y & 0b00000001; // 0b001 = 0x1;
let d: i8 = 0; // Displacement Byte
let n: u8 = 0; // 8-bit Immediate Operand
let nn: u16 = 0; // 16-bit Immediate Operand
match (x, z, q, y, p) {
(0, 0, _, 0, _) => Instruction::nop(),
_ => panic!("Unexpected Opcode!"),
}
}
fn execute() {
unimplemented!()
}
}
#[derive(Debug, Copy, Clone, Default)]