If popping directly to memory fails, don't change the stack pointer
This commit is contained in:
parent
bfc0ae96d1
commit
b496d2eb90
30
src/cpu.rs
30
src/cpu.rs
|
@ -2521,19 +2521,28 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
if should_run {
|
if should_run {
|
||||||
let value = self.pop_stack_8()?;
|
let value = self.pop_stack_8()?;
|
||||||
self.bus.memory.write_8(pointer, value)?;
|
let success = self.bus.memory.write_8(pointer, value);
|
||||||
|
if let None = success {
|
||||||
|
self.stack_pointer = self.stack_pointer.overflowing_sub(1).0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
if should_run {
|
if should_run {
|
||||||
let value = self.pop_stack_16()?;
|
let value = self.pop_stack_16()?;
|
||||||
self.bus.memory.write_16(pointer, value)?;
|
let success = self.bus.memory.write_16(pointer, value);
|
||||||
|
if let None = success {
|
||||||
|
self.stack_pointer = self.stack_pointer.overflowing_sub(2).0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
if should_run {
|
if should_run {
|
||||||
let value = self.pop_stack_32()?;
|
let value = self.pop_stack_32()?;
|
||||||
self.bus.memory.write_32(pointer, value)?;
|
let success = self.bus.memory.write_32(pointer, value);
|
||||||
|
if let None = success {
|
||||||
|
self.stack_pointer = self.stack_pointer.overflowing_sub(4).0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2545,19 +2554,28 @@ impl Cpu {
|
||||||
Size::Byte => {
|
Size::Byte => {
|
||||||
if should_run {
|
if should_run {
|
||||||
let value = self.pop_stack_8()?;
|
let value = self.pop_stack_8()?;
|
||||||
self.bus.memory.write_8(pointer, value)?;
|
let success = self.bus.memory.write_8(pointer, value);
|
||||||
|
if let None = success {
|
||||||
|
self.stack_pointer = self.stack_pointer.overflowing_sub(1).0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Half => {
|
Size::Half => {
|
||||||
if should_run {
|
if should_run {
|
||||||
let value = self.pop_stack_16()?;
|
let value = self.pop_stack_16()?;
|
||||||
self.bus.memory.write_16(pointer, value)?;
|
let success = self.bus.memory.write_16(pointer, value);
|
||||||
|
if let None = success {
|
||||||
|
self.stack_pointer = self.stack_pointer.overflowing_sub(2).0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Size::Word => {
|
Size::Word => {
|
||||||
if should_run {
|
if should_run {
|
||||||
let value = self.pop_stack_32()?;
|
let value = self.pop_stack_32()?;
|
||||||
self.bus.memory.write_32(pointer, value)?;
|
let success = self.bus.memory.write_32(pointer, value);
|
||||||
|
if let None = success {
|
||||||
|
self.stack_pointer = self.stack_pointer.overflowing_sub(4).0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user