mirror of
https://github.com/mre/mos6502.git
synced 2024-12-21 21:29:16 +00:00
implementation of RTS
This commit is contained in:
parent
7df9160e32
commit
1b90243738
14
src/cpu.rs
14
src/cpu.rs
@ -409,11 +409,13 @@ impl<M: Bus> CPU<M> {
|
||||
}
|
||||
(Instruction::PLA, OpInput::UseImplied) => {
|
||||
// Pull accumulator
|
||||
self.pull_from_stack();
|
||||
let val: u8 = self.pull_from_stack();
|
||||
self.registers.accumulator = val as i8;
|
||||
}
|
||||
(Instruction::PLP, OpInput::UseImplied) => {
|
||||
// Pull status
|
||||
self.pull_from_stack();
|
||||
let val: u8 = self.pull_from_stack();
|
||||
// The `truncate` here won't do anything because we have a
|
||||
// constant for the single unused flags bit. This probably
|
||||
@ -443,6 +445,12 @@ impl<M: Bus> CPU<M> {
|
||||
CPU::<M>::rotate_right_with_flags(&mut operand, &mut self.registers.status);
|
||||
self.memory.set_byte(addr, operand);
|
||||
}
|
||||
(Instruction::RTS, OpInput::UseImplied) => {
|
||||
self.pull_from_stack();
|
||||
let pcl: u8 = self.pull_from_stack();
|
||||
let pch: u8 = self.fetch_from_stack();
|
||||
self.registers.program_counter = (((pch as u16) << 8) | pcl as u16).wrapping_add(1);
|
||||
}
|
||||
|
||||
(Instruction::SBC, OpInput::UseImmediate(val)) => {
|
||||
debug!("subtract with carry immediate: {}", val);
|
||||
@ -921,6 +929,12 @@ impl<M: Bus> CPU<M> {
|
||||
self.registers.stack_pointer.increment();
|
||||
out
|
||||
}
|
||||
|
||||
fn fetch_from_stack(&mut self) -> u8 {
|
||||
// gets the next value on the stack but does not update the stack pointer
|
||||
let addr = self.registers.stack_pointer.to_u16();
|
||||
self.memory.get_byte(addr)
|
||||
}
|
||||
}
|
||||
|
||||
impl<M: Bus> core::fmt::Debug for CPU<M> {
|
||||
|
Loading…
Reference in New Issue
Block a user