Add nop instruction
parent
b5117e7cf9
commit
2db1e58568
|
@ -7,4 +7,5 @@ pub enum MiscInstruction {
|
|||
ComplementCarryFlag,
|
||||
ComplementARegister,
|
||||
DecimalAdjustAccumulator,
|
||||
Nop,
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ impl OpcodeParser for Parser {
|
|||
0x3F => Ok(build_complement_carry_flag_data()),
|
||||
0x27 => Ok(build_daa_data()),
|
||||
0x2F => Ok(build_complement_a_register_data()),
|
||||
0x00 => Ok(build_nop_data()),
|
||||
_ => Err(super::Error::UnknownOpcode(opcode)),
|
||||
}
|
||||
}
|
||||
|
@ -37,3 +38,10 @@ fn build_daa_data() -> ParseOutput {
|
|||
1,
|
||||
)
|
||||
}
|
||||
|
||||
fn build_nop_data() -> ParseOutput {
|
||||
(
|
||||
Instruction::Misc(MiscInstruction::Nop),
|
||||
1,
|
||||
)
|
||||
}
|
||||
|
|
|
@ -8,11 +8,16 @@ use super::{Cycles, Run};
|
|||
impl Run for MiscInstruction {
|
||||
fn run_on(&self, processor: &mut Processor) -> Result<Cycles, Error> {
|
||||
match *self {
|
||||
MiscInstruction::Nop => {
|
||||
Ok(Cycles(4))
|
||||
}
|
||||
|
||||
MiscInstruction::SetCarryFlag => {
|
||||
set_flags_in_carry_bit_instruction(processor, 1);
|
||||
|
||||
Ok(Cycles(4))
|
||||
}
|
||||
|
||||
MiscInstruction::ComplementCarryFlag => {
|
||||
let current_carry_flag = processor.registers.get_flag_bit(register::Flag::Carry);
|
||||
let flipped = (current_carry_flag == 0).into();
|
||||
|
@ -21,6 +26,7 @@ impl Run for MiscInstruction {
|
|||
|
||||
Ok(Cycles(4))
|
||||
}
|
||||
|
||||
MiscInstruction::ComplementARegister => {
|
||||
let current_value = processor
|
||||
.registers
|
||||
|
@ -38,6 +44,7 @@ impl Run for MiscInstruction {
|
|||
|
||||
Ok(Cycles(4))
|
||||
}
|
||||
|
||||
MiscInstruction::DecimalAdjustAccumulator => {
|
||||
let (adjusted_a_value, carry) = get_daa_value(&processor.registers);
|
||||
|
||||
|
|
|
@ -157,3 +157,17 @@ fn test_daa(
|
|||
(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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue