mirror of
https://github.com/mre/mos6502.git
synced 2024-11-30 20:51:21 +00:00
Fix modules.
This commit is contained in:
parent
1f896fb4e9
commit
2e2ba84d61
@ -25,31 +25,29 @@
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
mod address {
|
||||
#[deriving(PartialEq)]
|
||||
#[deriving(Eq)]
|
||||
#[deriving(PartialOrd)]
|
||||
#[deriving(Ord)]
|
||||
pub struct Address(u16);
|
||||
#[deriving(PartialEq)]
|
||||
#[deriving(Eq)]
|
||||
#[deriving(PartialOrd)]
|
||||
#[deriving(Ord)]
|
||||
pub struct Address(u16);
|
||||
|
||||
impl Address {
|
||||
/* TODO akeeton: Hide struct Address(u16) "constructor."
|
||||
pub fn new(address_: u16) -> Address {
|
||||
Address(address_)
|
||||
}
|
||||
*/
|
||||
impl Address {
|
||||
/* TODO akeeton: Hide struct Address(u16) "constructor."
|
||||
pub fn new(address_: u16) -> Address {
|
||||
Address(address_)
|
||||
}
|
||||
*/
|
||||
|
||||
pub fn to_int(&self) -> u16 {
|
||||
match *self {
|
||||
Address(address_) => address_
|
||||
}
|
||||
}
|
||||
|
||||
pub fn min() -> Address { Address(0x0100) }
|
||||
pub fn max() -> Address { Address(0x01ff) }
|
||||
|
||||
pub fn is_valid(&self) -> bool {
|
||||
Address::min() <= *self && *self <= Address::max()
|
||||
pub fn to_int(&self) -> u16 {
|
||||
match *self {
|
||||
Address(address_) => address_
|
||||
}
|
||||
}
|
||||
|
||||
pub fn min() -> Address { Address(0x0100) }
|
||||
pub fn max() -> Address { Address(0x01ff) }
|
||||
|
||||
pub fn is_valid(&self) -> bool {
|
||||
Address::min() <= *self && *self <= Address::max()
|
||||
}
|
||||
}
|
||||
|
@ -25,9 +25,9 @@
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
mod registers;
|
||||
mod address;
|
||||
mod memory;
|
||||
use registers::Registers;
|
||||
use address::Address;
|
||||
use memory::Memory;
|
||||
|
||||
struct Machine {
|
||||
registers: Registers,
|
@ -26,6 +26,9 @@
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
mod machine;
|
||||
mod registers;
|
||||
mod address;
|
||||
mod memory;
|
||||
|
||||
fn main() {
|
||||
let machine = machine::Machine::new();
|
||||
|
@ -25,45 +25,41 @@
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
mod address;
|
||||
use address::Address;
|
||||
|
||||
mod memory {
|
||||
use address::Address;
|
||||
pub struct Memory {
|
||||
bytes: [u8,.. 256]
|
||||
}
|
||||
|
||||
pub struct Memory {
|
||||
bytes: [u8,.. 256]
|
||||
impl Memory {
|
||||
fn address_to_byte_offset(address: &Address) -> uint {
|
||||
(address.to_int() - Address::min().to_int()) as uint
|
||||
}
|
||||
|
||||
impl Memory {
|
||||
fn address_to_byte_offset(address: &Address) -> uint {
|
||||
(address.to_int() - Address::min().to_int()) as uint
|
||||
pub fn get_byte(&self, address: &Address) -> u8 {
|
||||
if !address.is_valid()
|
||||
{
|
||||
fail!("Invalid address.");
|
||||
}
|
||||
|
||||
pub fn get_byte(&self, address: &Address) -> u8 {
|
||||
if !address.is_valid()
|
||||
{
|
||||
fail!("Invalid address.");
|
||||
}
|
||||
else
|
||||
{
|
||||
return self.bytes[Memory::address_to_byte_offset(address)];
|
||||
}
|
||||
else
|
||||
{
|
||||
return self.bytes[Memory::address_to_byte_offset(address)];
|
||||
}
|
||||
}
|
||||
|
||||
// Sets the byte at the given address to the given value and returns the
|
||||
// previous value at the address.
|
||||
pub fn set_byte(&mut self, address: &Address, value: u8) -> u8 {
|
||||
if !address.is_valid()
|
||||
{
|
||||
fail!("Invalid address.");
|
||||
}
|
||||
else
|
||||
{
|
||||
let old_value = self.get_byte(address);
|
||||
self.bytes[Memory::address_to_byte_offset(address)] = value;
|
||||
// Sets the byte at the given address to the given value and returns the
|
||||
// previous value at the address.
|
||||
pub fn set_byte(&mut self, address: &Address, value: u8) -> u8 {
|
||||
if !address.is_valid()
|
||||
{
|
||||
fail!("Invalid address.");
|
||||
}
|
||||
else
|
||||
{
|
||||
let old_value = self.get_byte(address);
|
||||
self.bytes[Memory::address_to_byte_offset(address)] = value;
|
||||
|
||||
return old_value;
|
||||
}
|
||||
return old_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,41 +25,39 @@
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
mod registers {
|
||||
// Each status flag should be 0 or 1.
|
||||
pub struct Status {
|
||||
pub carry: u8,
|
||||
pub zero: u8,
|
||||
pub interrupt: u8,
|
||||
pub decimal_mode: u8,
|
||||
pub brk: u8,
|
||||
pub unused: u8,
|
||||
pub overflow: u8,
|
||||
pub sign: u8
|
||||
}
|
||||
// Each status flag should be 0 or 1.
|
||||
pub struct Status {
|
||||
pub carry: u8,
|
||||
pub zero: u8,
|
||||
pub interrupt: u8,
|
||||
pub decimal_mode: u8,
|
||||
pub brk: u8,
|
||||
pub unused: u8,
|
||||
pub overflow: u8,
|
||||
pub sign: u8
|
||||
}
|
||||
|
||||
impl Status {
|
||||
pub fn to_byte(&self) -> u8 {
|
||||
self.carry << 0
|
||||
| self.zero << 1
|
||||
| self.interrupt << 2
|
||||
| self.decimal_mode << 3
|
||||
| self.brk << 4
|
||||
| self.unused << 5
|
||||
| self.overflow << 6
|
||||
| self.sign << 7
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Registers {
|
||||
pub accumulator: i8,
|
||||
pub index_x: i8,
|
||||
pub index_y: i8,
|
||||
pub stack_pointer: u8,
|
||||
pub program_counter: u16,
|
||||
pub status: Status
|
||||
}
|
||||
|
||||
impl Registers {
|
||||
impl Status {
|
||||
pub fn to_byte(&self) -> u8 {
|
||||
self.carry << 0
|
||||
| self.zero << 1
|
||||
| self.interrupt << 2
|
||||
| self.decimal_mode << 3
|
||||
| self.brk << 4
|
||||
| self.unused << 5
|
||||
| self.overflow << 6
|
||||
| self.sign << 7
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Registers {
|
||||
pub accumulator: i8,
|
||||
pub index_x: i8,
|
||||
pub index_y: i8,
|
||||
pub stack_pointer: u8,
|
||||
pub program_counter: u16,
|
||||
pub status: Status
|
||||
}
|
||||
|
||||
impl Registers {
|
||||
}
|
Loading…
Reference in New Issue
Block a user