Skip to content

Commit

Permalink
Implement CLV instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
lyrakisk committed Apr 9, 2024
1 parent 9c634dc commit af97cc4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ A (soon to be) fully-featured NES emulator written in Rust.
- [X] CLC
- [ ] CLD
- [ ] CLI
- [ ] CLV
- [X] CLV
- [ ] CMP
- [ ] CPX
- [ ] CPY
Expand Down
1 change: 1 addition & 0 deletions src/cpu/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub static INSTRUCTIONS: Lazy<HashMap<u8, Instruction>> = Lazy::new(|| {
Instruction {opcode: 0x50, name: "BVC", bytes: 2, addressing_mode: AddressingMode::Relative},
Instruction {opcode: 0x70, name: "BVS", bytes: 2, addressing_mode: AddressingMode::Relative},
Instruction {opcode: 0x18, name: "CLC", bytes: 1, addressing_mode: AddressingMode::Implicit},
Instruction {opcode: 0xB8, name: "CLV", bytes: 1, addressing_mode: AddressingMode::Implicit},
Instruction {opcode: 0xA9, name: "LDA", bytes: 2, addressing_mode: AddressingMode::Immediate},
Instruction {opcode: 0xA5, name: "LDA", bytes: 2, addressing_mode: AddressingMode::ZeroPage},
Instruction {opcode: 0xB5, name: "LDA", bytes: 2, addressing_mode: AddressingMode::ZeroPage_X},
Expand Down
19 changes: 19 additions & 0 deletions src/cpu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ impl CPU {
self.clc();
None
}
"CLV" => {
self.clv();
None
}
"BRK" => Some(0),
"LDA" => {
self.lda(&instruction.addressing_mode);
Expand Down Expand Up @@ -408,6 +412,10 @@ impl CPU {
self.clear_flag(STATUS_FLAG_MASK_CARRY);
}

fn clv(&mut self) {
self.clear_flag(STATUS_FLAG_MASK_OVERFLOW);
}

fn lda(&mut self, addressing_mode: &AddressingMode) {
let operand = self.get_operand(addressing_mode);
self.register_a = operand;
Expand Down Expand Up @@ -723,6 +731,17 @@ mod test_cpu {
assert_eq!(cpu.status, expected_status)
}

#[test_case(0b0100_0000, 0b0000_0000)]
#[test_case(0b0000_0000, 0b0000_0000)]
#[test_case(0b0100_0001, 0b0000_0001)]
#[test_case(0b0000_0001, 0b0000_0001)]
fn test_clv(status: u8, expected_status: u8) {
let mut cpu = CPU::new();
cpu.status = status;
cpu.clv();
assert_eq!(cpu.status, expected_status)
}

#[test_case(0b0000_0001, 0x5, 0x4, 0x1, 0b0000_0001)]
#[test_case(0b0000_0001, 0x5, 0x5, 0x0, 0b0000_0011)]
#[test_case(0b0000_0001, 0x0, 0x1, 0xFF, 0b1000_0000)]
Expand Down

0 comments on commit af97cc4

Please sign in to comment.