1
0
mirror of https://github.com/mre/mos6502.git synced 2024-11-28 22:51:26 +00:00

Make Address take i32 so relative addresses work.

This commit is contained in:
Andrew Keeton 2014-10-16 19:38:00 -04:00
parent 34cd5edd44
commit bc1687c247
4 changed files with 7 additions and 7 deletions

View File

@ -29,7 +29,7 @@
// does make sense to add an address and an "address-difference". (If this
// is too annoying to work with we should let it go.)
#[deriving(PartialEq, Eq, PartialOrd, Ord, Show)]
pub struct AddressDiff(pub u16);
pub struct AddressDiff(pub i32);
#[deriving(PartialEq, Eq, PartialOrd, Ord, Show)]
pub struct Address(pub u16);
@ -37,7 +37,7 @@ pub struct Address(pub u16);
impl Add<AddressDiff, Address> for Address {
fn add(&self, &AddressDiff(rhs): &AddressDiff) -> Address {
let &Address(lhs) = self;
Address(lhs + rhs)
Address(((lhs as i32) + rhs) as u16)
}
}

View File

@ -216,12 +216,12 @@ impl AddressingMode {
AbsoluteX => {
// Use [u8, ..2] from instruction as address, add X
// (Output: a 16-bit address)
UseAddress(arr_to_addr(arr) + AddressDiff(x as u16))
UseAddress(arr_to_addr(arr) + AddressDiff(x as i32))
},
AbsoluteY => {
// Use [u8, ..2] from instruction as address, add Y
// (Output: a 16-bit address)
UseAddress(arr_to_addr(arr) + AddressDiff(y as u16))
UseAddress(arr_to_addr(arr) + AddressDiff(y as i32))
},
Indirect => {
// Use [u8, ..2] from instruction as an address. Interpret the
@ -248,7 +248,7 @@ impl AddressingMode {
let start = arr[0];
let slice = memory.get_slice(Address(start as u16),
AddressDiff(2));
UseAddress(arr_to_addr(slice) + AddressDiff(y as u16))
UseAddress(arr_to_addr(slice) + AddressDiff(y as i32))
},
}
}

View File

@ -29,7 +29,7 @@ use log;
use std;
use address::{AddressDiff};
use address::{Address, AddressDiff};
use instruction;
use instruction::{DecodedInstr};
use memory::Memory;

View File

@ -118,7 +118,7 @@ pub struct StackPointer(pub u8);
impl StackPointer {
pub fn to_address(&StackPointer(sp): &StackPointer) -> Address
{
STACK_ADDRESS_LO + AddressDiff(sp as u16)
STACK_ADDRESS_LO + AddressDiff(sp as i32)
}
}