mirror of
https://github.com/mre/mos6502.git
synced 2024-12-01 11:51:51 +00:00
Implement JMP instruction.
This commit is contained in:
parent
6d7388c779
commit
1c1353127a
@ -29,7 +29,7 @@ use log;
|
|||||||
|
|
||||||
use std;
|
use std;
|
||||||
|
|
||||||
use address::{AddressDiff};
|
use address::{Address, AddressDiff};
|
||||||
use instruction;
|
use instruction;
|
||||||
use instruction::{DecodedInstr};
|
use instruction::{DecodedInstr};
|
||||||
use memory::Memory;
|
use memory::Memory;
|
||||||
@ -92,7 +92,11 @@ impl Machine {
|
|||||||
|
|
||||||
(instruction::DEX, instruction::UseImplied) => {
|
(instruction::DEX, instruction::UseImplied) => {
|
||||||
self.dec_x();
|
self.dec_x();
|
||||||
}
|
},
|
||||||
|
|
||||||
|
(instruction::JMP, instruction::UseAddress(addr)) => {
|
||||||
|
self.jump(addr)
|
||||||
|
},
|
||||||
|
|
||||||
(instruction::LDA, instruction::UseImmediate(val)) => {
|
(instruction::LDA, instruction::UseImmediate(val)) => {
|
||||||
log!(log::DEBUG, "load A immediate: {}", val);
|
log!(log::DEBUG, "load A immediate: {}", val);
|
||||||
@ -208,6 +212,10 @@ impl Machine {
|
|||||||
let val = self.registers.index_x;
|
let val = self.registers.index_x;
|
||||||
self.load_x_register(val - 1);
|
self.load_x_register(val - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn jump(&mut self, addr: Address) {
|
||||||
|
self.registers.program_counter = addr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Show for Machine {
|
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_NEGATIVE), true);
|
||||||
assert_eq!(machine.registers.status.contains(PS_OVERFLOW), false);
|
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);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user