mirror of
https://github.com/mre/mos6502.git
synced 2024-11-28 22:51:26 +00:00
Don't panic on stack over- and underflow
This commit is contained in:
parent
34bbe55712
commit
b566265dbb
@ -26,7 +26,7 @@
|
|||||||
// POSSIBILITY OF SUCH DAMAGE.
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
use address::{Address, AddressDiff};
|
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
|
// Useful for constructing Status instances
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
@ -88,15 +88,18 @@ impl Status {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(StatusArgs { negative,
|
pub fn new(
|
||||||
overflow,
|
StatusArgs {
|
||||||
unused,
|
negative,
|
||||||
brk,
|
overflow,
|
||||||
decimal_mode,
|
unused,
|
||||||
disable_interrupts,
|
brk,
|
||||||
zero,
|
decimal_mode,
|
||||||
carry }: StatusArgs) -> Status
|
disable_interrupts,
|
||||||
{
|
zero,
|
||||||
|
carry,
|
||||||
|
}: StatusArgs,
|
||||||
|
) -> Status {
|
||||||
let mut out = Status::empty();
|
let mut out = Status::empty();
|
||||||
|
|
||||||
if negative {
|
if negative {
|
||||||
@ -151,11 +154,11 @@ impl StackPointer {
|
|||||||
// JAM: FIXME: Should we prevent overflow here? What would a 6502 do?
|
// JAM: FIXME: Should we prevent overflow here? What would a 6502 do?
|
||||||
|
|
||||||
pub fn decrement(&mut self) {
|
pub fn decrement(&mut self) {
|
||||||
self.0 -= 1;
|
self.0 = self.0.wrapping_sub(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn increment(&mut self) {
|
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,
|
pub status: Status,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for Registers {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Registers {
|
impl Registers {
|
||||||
pub fn new() -> Registers {
|
pub fn new() -> Registers {
|
||||||
// TODO akeeton: Revisit these defaults.
|
// TODO akeeton: Revisit these defaults.
|
||||||
|
Loading…
Reference in New Issue
Block a user