1
0
mirror of https://github.com/mre/mos6502.git synced 2024-11-28 07:49:19 +00:00

Implement JMP instruction.

This commit is contained in:
Andrew Keeton 2014-10-19 21:37:43 -04:00
parent 6d7388c779
commit 1c1353127a

View File

@ -29,7 +29,7 @@ use log;
use std;
use address::{AddressDiff};
use address::{Address, AddressDiff};
use instruction;
use instruction::{DecodedInstr};
use memory::Memory;
@ -92,7 +92,11 @@ impl Machine {
(instruction::DEX, instruction::UseImplied) => {
self.dec_x();
}
},
(instruction::JMP, instruction::UseAddress(addr)) => {
self.jump(addr)
},
(instruction::LDA, instruction::UseImmediate(val)) => {
log!(log::DEBUG, "load A immediate: {}", val);
@ -208,6 +212,10 @@ impl Machine {
let val = self.registers.index_x;
self.load_x_register(val - 1);
}
pub fn jump(&mut self, addr: Address) {
self.registers.program_counter = addr;
}
}
impl std::fmt::Show for Machine {
@ -335,3 +343,12 @@ fn dec_x_test() {
assert_eq!(machine.registers.status.contains(PS_NEGATIVE), true);
assert_eq!(machine.registers.status.contains(PS_OVERFLOW), false);
}
#[test]
fn jump_test() {
let mut machine = Machine::new();
let addr = Address(0xA1B1);
machine.jump(addr);
assert_eq!(machine.registers.program_counter, addr);
}