diff --git a/src/cpu/parse.rs b/src/cpu/parse.rs index db94ee2..a52a3b2 100644 --- a/src/cpu/parse.rs +++ b/src/cpu/parse.rs @@ -1,6 +1,6 @@ //! The `parse` module holds functions that will parse streams of data into an [`crate::instructions::Instruction`] -use crate::memory::View; +use crate::memory::{GetViewTuple, View}; use super::instructions::Instruction; use thiserror::Error; @@ -81,11 +81,15 @@ pub fn next_instruction(data: &View) -> ParseResult { } } - // TODO: support 16bit, too let opcode = get_opcode_from_data(data); Err(Error::UnknownOpcode(opcode)) } fn get_opcode_from_data(data: &View) -> unparsed::Opcode { - unparsed::Opcode::EightBit(data.get()) + let (byte1, byte2) = data.get_tuple(); + if byte1 == 0xCB { + unparsed::Opcode::SixteenBit(u16::from_be_bytes([byte1, byte2])) + } else { + unparsed::Opcode::EightBit(byte1) + } }