mirror of
https://github.com/mre/mos6502.git
synced 2024-11-21 22:31:44 +00:00
Fix compilation with latest rustc
This commit is contained in:
parent
82e2cac30c
commit
0a3f628168
@ -3,3 +3,4 @@
|
||||
Alex Weisberger <alex.m.weisberger@gmail.com>
|
||||
Andrew Keeton <andrewrkeeton@gmail.com>
|
||||
Johannes Muenzel <jmuenzel@gmail.com>
|
||||
Matthias Endler <matthias-endler@gmx.net>
|
@ -39,5 +39,6 @@ name = "emu6502"
|
||||
name = "emu6502"
|
||||
|
||||
[dependencies]
|
||||
log = "0.2.3"
|
||||
|
||||
bitflags = "0.9.1"
|
||||
log = "0.3.8"
|
||||
num = "0.1"
|
||||
|
@ -25,16 +25,15 @@
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
use std::num::Int;
|
||||
use std::ops::Add;
|
||||
|
||||
// The idea here is that it doesn't make sense to add two addresses, but it
|
||||
// does make sense to add an address and an "address-difference". (If this
|
||||
// is too annoying to work with we should let it go.)
|
||||
#[derive(Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
|
||||
pub struct AddressDiff(pub i32);
|
||||
|
||||
#[derive(Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
|
||||
pub struct Address(pub u16);
|
||||
|
||||
impl Add<AddressDiff> for Address {
|
||||
@ -57,7 +56,7 @@ impl Add for AddressDiff {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct CheckedAddressDiff(u16);
|
||||
|
||||
impl Add<CheckedAddressDiff> for Address {
|
||||
@ -77,7 +76,7 @@ impl Add<CheckedAddressDiff> for Address {
|
||||
impl Address {
|
||||
pub fn to_u16(&self) -> u16 {
|
||||
match *self {
|
||||
Address(address_) => address_
|
||||
Address(address_) => address_,
|
||||
}
|
||||
}
|
||||
|
||||
@ -93,4 +92,3 @@ impl Address {
|
||||
(self.to_u16() & 0x00ff) as u8
|
||||
}
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -25,20 +25,17 @@
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#![feature(core)]
|
||||
#![feature(hash)]
|
||||
#![feature(rustc_private)]
|
||||
|
||||
// Needed for debug! / log! macros
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
extern crate num;
|
||||
|
||||
#[macro_use]
|
||||
extern crate rustc_bitflags;
|
||||
extern crate bitflags;
|
||||
|
||||
pub mod address;
|
||||
pub mod instruction;
|
||||
pub mod machine;
|
||||
pub mod memory;
|
||||
pub mod range_incl;
|
||||
pub mod registers;
|
||||
|
1274
src/machine.rs
1274
src/machine.rs
File diff suppressed because it is too large
Load Diff
@ -25,11 +25,12 @@
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
use std::iter::repeat;
|
||||
use address::{Address, AddressDiff};
|
||||
|
||||
// JAM: We can probably come up with a better way to represent address ranges.
|
||||
// Address range type?
|
||||
//
|
||||
//
|
||||
// // Address range -- inclusive on both sides
|
||||
// pub struct AddressRangeIncl {
|
||||
// begin: Address,
|
||||
@ -39,24 +40,24 @@ use address::{Address, AddressDiff};
|
||||
const ADDR_LO_BARE: u16 = 0x0000;
|
||||
const ADDR_HI_BARE: u16 = 0xFFFF;
|
||||
|
||||
pub const MEMORY_ADDRESS_LO: Address = Address(ADDR_LO_BARE);
|
||||
pub const MEMORY_ADDRESS_HI: Address = Address(ADDR_HI_BARE);
|
||||
pub const STACK_ADDRESS_LO: Address = Address(0x0100);
|
||||
pub const STACK_ADDRESS_HI: Address = Address(0x01FF);
|
||||
pub const MEMORY_ADDRESS_LO: Address = Address(ADDR_LO_BARE);
|
||||
pub const MEMORY_ADDRESS_HI: Address = Address(ADDR_HI_BARE);
|
||||
pub const STACK_ADDRESS_LO: Address = Address(0x0100);
|
||||
pub const STACK_ADDRESS_HI: Address = Address(0x01FF);
|
||||
pub const IRQ_INTERRUPT_VECTOR_LO: Address = Address(0xFFFE);
|
||||
pub const IRQ_INTERRUPT_VECTOR_HI: Address = Address(0xFFFF);
|
||||
|
||||
const MEMORY_SIZE: usize = (ADDR_HI_BARE - ADDR_LO_BARE) as usize + 1us;
|
||||
const MEMORY_SIZE: usize = (ADDR_HI_BARE - ADDR_LO_BARE) as usize + 1usize;
|
||||
|
||||
// FIXME: Should this use indirection for `bytes`?
|
||||
#[derive(Copy)]
|
||||
#[derive(Clone)]
|
||||
pub struct Memory {
|
||||
bytes: [u8; MEMORY_SIZE]
|
||||
bytes: Vec<u8>,
|
||||
}
|
||||
|
||||
impl Memory {
|
||||
pub fn new() -> Memory {
|
||||
Memory { bytes: [0; MEMORY_SIZE] }
|
||||
Memory { bytes: repeat(0).take(MEMORY_SIZE).collect() }
|
||||
}
|
||||
|
||||
pub fn get_byte(&self, address: Address) -> u8 {
|
||||
@ -67,8 +68,7 @@ impl Memory {
|
||||
&mut self.bytes[address.to_usize()]
|
||||
}
|
||||
|
||||
pub fn get_slice(&self, Address(start): Address,
|
||||
AddressDiff(diff): AddressDiff) -> &[u8] {
|
||||
pub fn get_slice(&self, Address(start): Address, AddressDiff(diff): AddressDiff) -> &[u8] {
|
||||
let start = start as usize;
|
||||
let diff = diff as usize;
|
||||
let end = start + diff;
|
||||
@ -100,4 +100,3 @@ impl Memory {
|
||||
STACK_ADDRESS_LO <= *address && *address <= STACK_ADDRESS_HI
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,34 +0,0 @@
|
||||
use std::num::Int;
|
||||
|
||||
pub struct RangeIncl<T: Int> {
|
||||
state: Option<T>,
|
||||
end: T,
|
||||
}
|
||||
|
||||
pub fn range_incl<T: Int>(begin: T, end: T) -> RangeIncl<T> {
|
||||
RangeIncl { state: Some(begin), end: end }
|
||||
}
|
||||
|
||||
trait One : Int {
|
||||
fn my_one(_: Option<Self>) -> Self {
|
||||
Int::one()
|
||||
}
|
||||
}
|
||||
impl<T> One for T where T: Int {}
|
||||
|
||||
impl<T: Int> Iterator for RangeIncl<T> {
|
||||
type Item = T;
|
||||
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
|
||||
match self.state {
|
||||
Some(current) => {
|
||||
self.state =
|
||||
if current == self.end { None }
|
||||
else { Some(current + One::my_one(None::<T>)) };
|
||||
Some(current)
|
||||
},
|
||||
None => {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
119
src/registers.rs
119
src/registers.rs
@ -29,7 +29,7 @@ use address::{Address, AddressDiff};
|
||||
use memory::{STACK_ADDRESS_LO, STACK_ADDRESS_HI};
|
||||
|
||||
// Useful for constructing Status instances
|
||||
#[derive(Copy)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct StatusArgs {
|
||||
pub negative: bool,
|
||||
pub overflow: bool,
|
||||
@ -43,31 +43,32 @@ pub struct StatusArgs {
|
||||
|
||||
impl StatusArgs {
|
||||
pub fn none() -> StatusArgs {
|
||||
StatusArgs { negative: false,
|
||||
overflow: false,
|
||||
unused: false,
|
||||
brk: false,
|
||||
decimal_mode: false,
|
||||
disable_interrupts: false,
|
||||
zero: false,
|
||||
carry: false, }
|
||||
StatusArgs {
|
||||
negative: false,
|
||||
overflow: false,
|
||||
unused: false,
|
||||
brk: false,
|
||||
decimal_mode: false,
|
||||
disable_interrupts: false,
|
||||
zero: false,
|
||||
carry: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub bitflags! {
|
||||
#[derive(Debug)]
|
||||
flags Status: u8 {
|
||||
const PS_NEGATIVE = 0b10000000,
|
||||
const PS_OVERFLOW = 0b01000000,
|
||||
const PS_UNUSED = 0b00100000, // JAM: Should this exist?
|
||||
bitflags! {
|
||||
pub struct Status: u8 {
|
||||
const PS_NEGATIVE = 0b10000000;
|
||||
const PS_OVERFLOW = 0b01000000;
|
||||
const PS_UNUSED = 0b00100000; // JAM: Should this exist?
|
||||
// (note that it affects the
|
||||
// behavior of things like
|
||||
// from_bits_truncate)
|
||||
const PS_BRK = 0b00010000,
|
||||
const PS_DECIMAL_MODE = 0b00001000,
|
||||
const PS_DISABLE_INTERRUPTS = 0b00000100,
|
||||
const PS_ZERO = 0b00000010,
|
||||
const PS_CARRY = 0b00000001,
|
||||
const PS_BRK = 0b00010000;
|
||||
const PS_DECIMAL_MODE = 0b00001000;
|
||||
const PS_DISABLE_INTERRUPTS = 0b00000100;
|
||||
const PS_ZERO = 0b00000010;
|
||||
const PS_CARRY = 0b00000001;
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,14 +76,16 @@ impl Status {
|
||||
pub fn default() -> Status {
|
||||
// TODO akeeton: Revisit these defaults.
|
||||
|
||||
Status::new(StatusArgs { negative: false,
|
||||
overflow: false,
|
||||
unused: true,
|
||||
brk: false,
|
||||
decimal_mode: false,
|
||||
disable_interrupts: true,
|
||||
zero: false,
|
||||
carry: false, } )
|
||||
Status::new(StatusArgs {
|
||||
negative: false,
|
||||
overflow: false,
|
||||
unused: true,
|
||||
brk: false,
|
||||
decimal_mode: false,
|
||||
disable_interrupts: true,
|
||||
zero: false,
|
||||
carry: false,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn new(StatusArgs { negative,
|
||||
@ -96,14 +99,30 @@ impl Status {
|
||||
{
|
||||
let mut out = Status::empty();
|
||||
|
||||
if negative { out = out | PS_NEGATIVE }
|
||||
if overflow { out = out | PS_OVERFLOW }
|
||||
if unused { out = out | PS_UNUSED }
|
||||
if brk { out = out | PS_BRK }
|
||||
if decimal_mode { out = out | PS_DECIMAL_MODE }
|
||||
if disable_interrupts { out = out | PS_DISABLE_INTERRUPTS }
|
||||
if zero { out = out | PS_ZERO }
|
||||
if carry { out = out | PS_CARRY }
|
||||
if negative {
|
||||
out = out | PS_NEGATIVE
|
||||
}
|
||||
if overflow {
|
||||
out = out | PS_OVERFLOW
|
||||
}
|
||||
if unused {
|
||||
out = out | PS_UNUSED
|
||||
}
|
||||
if brk {
|
||||
out = out | PS_BRK
|
||||
}
|
||||
if decimal_mode {
|
||||
out = out | PS_DECIMAL_MODE
|
||||
}
|
||||
if disable_interrupts {
|
||||
out = out | PS_DISABLE_INTERRUPTS
|
||||
}
|
||||
if zero {
|
||||
out = out | PS_ZERO
|
||||
}
|
||||
if carry {
|
||||
out = out | PS_CARRY
|
||||
}
|
||||
|
||||
out
|
||||
}
|
||||
@ -121,12 +140,11 @@ impl Status {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
|
||||
pub struct StackPointer(pub u8);
|
||||
|
||||
impl StackPointer {
|
||||
pub fn to_address(&self) -> Address
|
||||
{
|
||||
pub fn to_address(&self) -> Address {
|
||||
let StackPointer(sp) = *self;
|
||||
STACK_ADDRESS_LO + AddressDiff(sp as i32)
|
||||
}
|
||||
@ -144,27 +162,26 @@ impl StackPointer {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, PartialEq, Eq, Debug)]
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||
pub struct Registers {
|
||||
pub accumulator: i8,
|
||||
pub index_x: i8,
|
||||
pub index_y: i8,
|
||||
pub stack_pointer: StackPointer,
|
||||
pub accumulator: i8,
|
||||
pub index_x: i8,
|
||||
pub index_y: i8,
|
||||
pub stack_pointer: StackPointer,
|
||||
pub program_counter: Address,
|
||||
pub status: Status
|
||||
pub status: Status,
|
||||
}
|
||||
|
||||
impl Registers {
|
||||
pub fn new() -> Registers {
|
||||
// TODO akeeton: Revisit these defaults.
|
||||
Registers {
|
||||
accumulator: 0,
|
||||
index_x: 0,
|
||||
index_y: 0,
|
||||
stack_pointer: StackPointer(STACK_ADDRESS_HI.get_offset()),
|
||||
accumulator: 0,
|
||||
index_x: 0,
|
||||
index_y: 0,
|
||||
stack_pointer: StackPointer(STACK_ADDRESS_HI.get_offset()),
|
||||
program_counter: Address(0),
|
||||
status: Status::default()
|
||||
status: Status::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user