Add nop instruction

old-bit-manip
Nick Krichevsky 2023-11-20 18:02:34 -05:00
parent b5117e7cf9
commit 2db1e58568
5 changed files with 30 additions and 0 deletions

View File

@ -7,4 +7,5 @@ pub enum MiscInstruction {
ComplementCarryFlag, ComplementCarryFlag,
ComplementARegister, ComplementARegister,
DecimalAdjustAccumulator, DecimalAdjustAccumulator,
Nop,
} }

View File

@ -14,6 +14,7 @@ impl OpcodeParser for Parser {
0x3F => Ok(build_complement_carry_flag_data()), 0x3F => Ok(build_complement_carry_flag_data()),
0x27 => Ok(build_daa_data()), 0x27 => Ok(build_daa_data()),
0x2F => Ok(build_complement_a_register_data()), 0x2F => Ok(build_complement_a_register_data()),
0x00 => Ok(build_nop_data()),
_ => Err(super::Error::UnknownOpcode(opcode)), _ => Err(super::Error::UnknownOpcode(opcode)),
} }
} }
@ -37,3 +38,10 @@ fn build_daa_data() -> ParseOutput {
1, 1,
) )
} }
fn build_nop_data() -> ParseOutput {
(
Instruction::Misc(MiscInstruction::Nop),
1,
)
}

View File

@ -8,11 +8,16 @@ use super::{Cycles, Run};
impl Run for MiscInstruction { impl Run for MiscInstruction {
fn run_on(&self, processor: &mut Processor) -> Result<Cycles, Error> { fn run_on(&self, processor: &mut Processor) -> Result<Cycles, Error> {
match *self { match *self {
MiscInstruction::Nop => {
Ok(Cycles(4))
}
MiscInstruction::SetCarryFlag => { MiscInstruction::SetCarryFlag => {
set_flags_in_carry_bit_instruction(processor, 1); set_flags_in_carry_bit_instruction(processor, 1);
Ok(Cycles(4)) Ok(Cycles(4))
} }
MiscInstruction::ComplementCarryFlag => { MiscInstruction::ComplementCarryFlag => {
let current_carry_flag = processor.registers.get_flag_bit(register::Flag::Carry); let current_carry_flag = processor.registers.get_flag_bit(register::Flag::Carry);
let flipped = (current_carry_flag == 0).into(); let flipped = (current_carry_flag == 0).into();
@ -21,6 +26,7 @@ impl Run for MiscInstruction {
Ok(Cycles(4)) Ok(Cycles(4))
} }
MiscInstruction::ComplementARegister => { MiscInstruction::ComplementARegister => {
let current_value = processor let current_value = processor
.registers .registers
@ -38,6 +44,7 @@ impl Run for MiscInstruction {
Ok(Cycles(4)) Ok(Cycles(4))
} }
MiscInstruction::DecimalAdjustAccumulator => { MiscInstruction::DecimalAdjustAccumulator => {
let (adjusted_a_value, carry) = get_daa_value(&processor.registers); let (adjusted_a_value, carry) = get_daa_value(&processor.registers);

View File

@ -157,3 +157,17 @@ fn test_daa(
(register::Flag::Zero, u8::from(expected_flags.zero)) (register::Flag::Zero, u8::from(expected_flags.zero))
); );
} }
#[test]
fn test_nop_executes_successfully() {
let mut processor = Processor::default();
let data = [0x00, 0x06];
let (ins, extra_data) = Instruction::from_data(&data).expect("could not parse instruction");
assert_eq!(extra_data, &[0x06]);
processor.run_instruction(ins);
// uhhh it does nothing
assert_eq!(processor.num_cycles, 4);
}