1
0
mirror of https://github.com/mre/mos6502.git synced 2024-11-30 20:51:21 +00:00

move tests and README away from Address

This commit is contained in:
Sam M W 2022-10-18 09:59:52 +01:00
parent a3c4a7689f
commit 3de8f9158d
6 changed files with 47 additions and 56 deletions

View File

@ -52,9 +52,9 @@ fn main() {
let mut cpu = cpu::CPU::new();
cpu.memory.set_bytes(Address(0x00), &zero_page_data);
cpu.memory.set_bytes(Address(0x10), &program);
cpu.registers.program_counter = Address(0x10);
cpu.memory.set_bytes(0x00, &zero_page_data);
cpu.memory.set_bytes(0x10, &program);
cpu.registers.program_counter = 0x10;
cpu.run();

View File

@ -1,5 +1,5 @@
extern crate mos6502;
use mos6502::address::Address;
use mos6502::cpu;
fn main() {
@ -35,9 +35,9 @@ fn main() {
let mut cpu = cpu::CPU::new();
cpu.memory.set_bytes(Address(0x00), &zero_page_data);
cpu.memory.set_bytes(Address(0x10), &program);
cpu.registers.program_counter = Address(0x10);
cpu.memory.set_bytes(0x00, &zero_page_data);
cpu.memory.set_bytes(0x10, &program);
cpu.registers.program_counter = 0x10;
cpu.run();

View File

@ -30,9 +30,6 @@ extern crate mos6502;
#[cfg(not(test))]
use mos6502::cpu;
#[cfg(not(test))]
use mos6502::address::Address;
#[cfg(not(test))]
fn main() {
let mut cpu = cpu::CPU::new();
@ -94,11 +91,11 @@ fn main() {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, // ADC IndirectIndexedY target
];
cpu.memory.set_bytes(Address(0x0000), &zero_page_data);
cpu.memory.set_bytes(Address(0x4000), &program);
cpu.memory.set_bytes(Address(0x8000), &data);
cpu.memory.set_bytes(0x0000, &zero_page_data);
cpu.memory.set_bytes(0x4000, &program);
cpu.memory.set_bytes(0x8000, &data);
cpu.registers.program_counter = Address(0x4000);
cpu.registers.program_counter = 0x4000;
cpu.run();

View File

@ -25,7 +25,6 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
use crate::instruction::{self, DecodedInstr, Instruction, OpInput};
use crate::memory::Memory;
use crate::registers::{Registers, StackPointer, Status, StatusArgs};
@ -68,7 +67,8 @@ impl CPU {
let am_out = am.process(self, slice);
// Increment program counter
self.registers.program_counter = self.registers.program_counter.wrapping_add(num_bytes);
self.registers.program_counter =
self.registers.program_counter.wrapping_add(num_bytes);
Some((instr, am_out))
}
@ -1022,7 +1022,7 @@ mod tests {
#[test]
fn decrement_memory_test() {
let mut cpu = CPU::new();
let addr = Address(0xA1B2);
let addr: u16 = 0xA1B2;
cpu.memory.set_byte(addr, 5);
@ -1135,7 +1135,7 @@ mod tests {
#[test]
fn jump_test() {
let mut cpu = CPU::new();
let addr = Address(0xA1B1);
let addr: u16 = 0xA1B1;
cpu.jump(addr);
assert_eq!(cpu.registers.program_counter, addr);
@ -1146,12 +1146,12 @@ mod tests {
let mut cpu = CPU::new();
cpu.execute_instruction((Instruction::SEC, OpInput::UseImplied));
cpu.branch_if_carry_clear(Address(0xABCD));
assert_eq!(cpu.registers.program_counter, Address(0));
cpu.branch_if_carry_clear(0xABCD);
assert_eq!(cpu.registers.program_counter, (0));
cpu.execute_instruction((Instruction::CLC, OpInput::UseImplied));
cpu.branch_if_carry_clear(Address(0xABCD));
assert_eq!(cpu.registers.program_counter, Address(0xABCD));
cpu.branch_if_carry_clear(0xABCD);
assert_eq!(cpu.registers.program_counter, (0xABCD));
}
#[test]
@ -1159,24 +1159,24 @@ mod tests {
let mut cpu = CPU::new();
cpu.execute_instruction((Instruction::CLC, OpInput::UseImplied));
cpu.branch_if_carry_set(Address(0xABCD));
assert_eq!(cpu.registers.program_counter, Address(0));
cpu.branch_if_carry_set(0xABCD);
assert_eq!(cpu.registers.program_counter, (0));
cpu.execute_instruction((Instruction::SEC, OpInput::UseImplied));
cpu.branch_if_carry_set(Address(0xABCD));
assert_eq!(cpu.registers.program_counter, Address(0xABCD));
cpu.branch_if_carry_set(0xABCD);
assert_eq!(cpu.registers.program_counter, (0xABCD));
}
#[test]
fn branch_if_equal_test() {
let mut cpu = CPU::new();
cpu.branch_if_equal(Address(0xABCD));
assert_eq!(cpu.registers.program_counter, Address(0));
cpu.branch_if_equal(0xABCD);
assert_eq!(cpu.registers.program_counter, (0));
cpu.registers.status.or(Status::PS_ZERO);
cpu.branch_if_equal(Address(0xABCD));
assert_eq!(cpu.registers.program_counter, Address(0xABCD));
cpu.branch_if_equal(0xABCD);
assert_eq!(cpu.registers.program_counter, (0xABCD));
}
#[test]
@ -1185,9 +1185,9 @@ mod tests {
let mut cpu = CPU::new();
let registers_before = cpu.registers;
cpu.branch_if_minus(Address(0xABCD));
cpu.branch_if_minus(0xABCD);
assert_eq!(cpu.registers, registers_before);
assert_eq!(cpu.registers.program_counter, Address(0));
assert_eq!(cpu.registers.program_counter, (0));
}
{
@ -1196,9 +1196,9 @@ mod tests {
cpu.registers.status.or(Status::PS_NEGATIVE);
let registers_before = cpu.registers;
cpu.branch_if_minus(Address(0xABCD));
cpu.branch_if_minus(0xABCD);
assert_eq!(cpu.registers.status, registers_before.status);
assert_eq!(cpu.registers.program_counter, Address(0xABCD));
assert_eq!(cpu.registers.program_counter, (0xABCD));
}
}
@ -1207,12 +1207,12 @@ mod tests {
let mut cpu = CPU::new();
cpu.registers.status.insert(Status::PS_NEGATIVE);
cpu.branch_if_positive(Address(0xABCD));
assert_eq!(cpu.registers.program_counter, Address(0));
cpu.branch_if_positive(0xABCD);
assert_eq!(cpu.registers.program_counter, (0));
cpu.registers.status.remove(Status::PS_NEGATIVE);
cpu.branch_if_positive(Address(0xABCD));
assert_eq!(cpu.registers.program_counter, Address(0xABCD));
cpu.branch_if_positive(0xABCD);
assert_eq!(cpu.registers.program_counter, (0xABCD));
}
#[test]
@ -1220,24 +1220,24 @@ mod tests {
let mut cpu = CPU::new();
cpu.registers.status.insert(Status::PS_OVERFLOW);
cpu.branch_if_overflow_clear(Address(0xABCD));
assert_eq!(cpu.registers.program_counter, Address(0));
cpu.branch_if_overflow_clear(0xABCD);
assert_eq!(cpu.registers.program_counter, (0));
cpu.registers.status.remove(Status::PS_OVERFLOW);
cpu.branch_if_overflow_clear(Address(0xABCD));
assert_eq!(cpu.registers.program_counter, Address(0xABCD));
cpu.branch_if_overflow_clear(0xABCD);
assert_eq!(cpu.registers.program_counter, (0xABCD));
}
#[test]
fn branch_if_overflow_set_test() {
let mut cpu = CPU::new();
cpu.branch_if_overflow_set(Address(0xABCD));
assert_eq!(cpu.registers.program_counter, Address(0));
cpu.branch_if_overflow_set(0xABCD);
assert_eq!(cpu.registers.program_counter, (0));
cpu.registers.status.insert(Status::PS_OVERFLOW);
cpu.branch_if_overflow_set(Address(0xABCD));
assert_eq!(cpu.registers.program_counter, Address(0xABCD));
cpu.branch_if_overflow_set(0xABCD);
assert_eq!(cpu.registers.program_counter, (0xABCD));
}
#[cfg(test)]

View File

@ -25,8 +25,6 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
use crate::cpu::CPU;
// Abbreviations

View File

@ -25,8 +25,7 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
use crate::address::{Address};
use crate::address::Address;
// JAM: We can probably come up with a better way to represent address ranges.
// Address range type?
@ -112,17 +111,14 @@ mod tests {
#[test]
fn test_memory_set_bytes() {
let mut memory = Memory::new();
memory.set_bytes(Address(0x0100), &[1, 2, 3, 4, 5]);
assert_eq!(
memory.get_slice(Address(0x00FF), AddressDiff(7)),
&[0, 1, 2, 3, 4, 5, 0]
);
memory.set_bytes(0x0100, &[1, 2, 3, 4, 5]);
assert_eq!(memory.get_slice(0x00FF, 7), &[0, 1, 2, 3, 4, 5, 0]);
}
#[test]
#[should_panic]
fn test_memory_overflow_panic() {
let mut memory = Memory::new();
memory.set_bytes(Address(0xFFFE), &[1, 2, 3]);
memory.set_bytes(0xFFFE, &[1, 2, 3]);
}
}