diff --git a/src/cpu/instructions.rs b/src/cpu/instructions.rs index 7a4f356..07982b2 100644 --- a/src/cpu/instructions.rs +++ b/src/cpu/instructions.rs @@ -25,6 +25,9 @@ pub struct RunnableInstruction { impl RunnableInstruction { /// `from_data` will produce an instruction from the given data and return the data after /// processing that operation. + /// + /// # Errors + /// Returns an error if the instruction couldn't be parsed. pub fn from_data(data: &[u8]) -> ParseResult { parse::next_instruction(data) } diff --git a/src/register.rs b/src/register.rs index d895cdd..1696066 100644 --- a/src/register.rs +++ b/src/register.rs @@ -73,6 +73,7 @@ impl Flag { } impl Registers { + #[must_use] pub fn new() -> Self { Self::default() } @@ -101,10 +102,11 @@ impl Registers { /// Get the a flag in the flag register. /// It is suggested that you use the constants in the `flag` module when calling this method. /// Will only ever be zero or one + #[must_use] + #[allow(clippy::missing_panics_doc)] pub fn get_flag_bit(&self, flag: Flag) -> u8 { let pos = flag.get_regiter_pos(); - // There are only 8 flag registers. If you use anything other than the constants, - // you may deserve what you get. + // programming error if this happens assert!(pos < 8); (self.flags & (1 << pos)) >> pos @@ -112,6 +114,9 @@ impl Registers { /// Set a flag register bit (at position `pos`) to the given value. /// This will only pay attention to the first bit, so only zero or one should be passed + /// + /// # Panics + /// Panics if flag is of a value that isn't 0 or 1 pub fn set_flag_bit(&mut self, flag: Flag, value: u8) { assert!(value <= 1); @@ -123,6 +128,7 @@ impl Registers { self.flags |= bit << pos; } + #[must_use] pub fn get_single_8bit_register(&self, register: SingleEightBit) -> u8 { match register { SingleEightBit::A => self.a, @@ -151,6 +157,7 @@ impl Registers { /// Get the value of a 16 bit register, whether it's natively a 16 bit register or a combination of /// 8 bit registers + #[must_use] pub fn get_16bit_register(&self, register: SixteenBit) -> u16 { match register { SixteenBit::Single(single) => self.get_single_16bit_register(single), @@ -159,6 +166,7 @@ impl Registers { } /// Get the value of a single 16 bit register (i.e. a natively 16 bit register) + #[must_use] pub fn get_single_16bit_register(&self, register: SingleSixteenBit) -> u16 { match register { SingleSixteenBit::StackPointer => self.stack_pointer, @@ -167,6 +175,7 @@ impl Registers { } /// Get the value of combined single 16 bit register (i.e. a combination of two 8 bit registers) + #[must_use] pub fn get_combined_register(&self, registers: Combined) -> u16 { let (left_register, right_register) = self.get_register_values_for_combined(registers); let mut res = 0_u16;