Don't panic on stack over- and underflow

This commit is contained in:
Sam M W 2021-01-30 15:11:02 +00:00
parent 34bbe55712
commit b566265dbb
1 changed files with 21 additions and 12 deletions

View File

@ -26,7 +26,7 @@
// POSSIBILITY OF SUCH DAMAGE.
use address::{Address, AddressDiff};
use memory::{STACK_ADDRESS_LO, STACK_ADDRESS_HI};
use memory::{STACK_ADDRESS_HI, STACK_ADDRESS_LO};
// Useful for constructing Status instances
#[derive(Copy, Clone)]
@ -88,15 +88,18 @@ impl Status {
})
}
pub fn new(StatusArgs { negative,
overflow,
unused,
brk,
decimal_mode,
disable_interrupts,
zero,
carry }: StatusArgs) -> Status
{
pub fn new(
StatusArgs {
negative,
overflow,
unused,
brk,
decimal_mode,
disable_interrupts,
zero,
carry,
}: StatusArgs,
) -> Status {
let mut out = Status::empty();
if negative {
@ -151,11 +154,11 @@ impl StackPointer {
// JAM: FIXME: Should we prevent overflow here? What would a 6502 do?
pub fn decrement(&mut self) {
self.0 -= 1;
self.0 = self.0.wrapping_sub(1);
}
pub fn increment(&mut self) {
self.0 += 1;
self.0 = self.0.wrapping_add(1);
}
}
@ -169,6 +172,12 @@ pub struct Registers {
pub status: Status,
}
impl Default for Registers {
fn default() -> Self {
Self::new()
}
}
impl Registers {
pub fn new() -> Registers {
// TODO akeeton: Revisit these defaults.