old-bit-manip
Nick Krichevsky 2023-11-26 23:16:33 -05:00
parent 9e785d117c
commit 61f64af4a4
1 changed files with 7 additions and 3 deletions

View File

@ -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)
}
}