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.
|
||||
|
||||
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.
|
||||
|
Loading…
Reference in New Issue
Block a user