Group One instructions done EXCEPT for modes (Indirect, X) and (Indirect), Y
parent
4987266110
commit
7021dd1e56
@ -0,0 +1,216 @@
|
|||||||
|
|
||||||
|
#![allow(dead_code, non_snake_case)]
|
||||||
|
|
||||||
|
use crate::tests::test_bus::RAMBus;
|
||||||
|
use crate::r6502::{R6502, Bus, Registers, Flags};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn IMM()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// Write the program to memory
|
||||||
|
// ADC 6
|
||||||
|
bus.write(addr, 0x69); // ADC - Immediate mode
|
||||||
|
bus.write(addr + 1, 0x06); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x04);
|
||||||
|
|
||||||
|
// Clock the cpu twice (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x0A in the A register?
|
||||||
|
assert_eq!(0x0A, cpu.debug_get_reg(Registers::A), "Failed basic addition");
|
||||||
|
|
||||||
|
///////////////////////////////////////////
|
||||||
|
// EXTRA TESTING
|
||||||
|
|
||||||
|
// Add with carry in
|
||||||
|
// Write the program to memory
|
||||||
|
// ADC 6
|
||||||
|
bus.write(addr, 0x69); // ADC - Immediate mode
|
||||||
|
bus.write(addr + 1, 0x06); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu internals
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x04);
|
||||||
|
cpu.set_flag(Flags::C);
|
||||||
|
|
||||||
|
// Clock the cpu twice (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x0B in the A register?
|
||||||
|
assert_eq!(0x0B, cpu.debug_get_reg(Registers::A), "Failed addition with carry");
|
||||||
|
|
||||||
|
// Add with overflow
|
||||||
|
// Write the program to memory
|
||||||
|
// ADC 126
|
||||||
|
bus.write(addr, 0x69); // ADC - Immediate mode
|
||||||
|
bus.write(addr + 1, 126); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu internals
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x04);
|
||||||
|
|
||||||
|
// Clock the cpu twice (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 130 in the A register?
|
||||||
|
assert_eq!(130, cpu.debug_get_reg(Registers::A));
|
||||||
|
|
||||||
|
// Is the overflow bit set?
|
||||||
|
assert_eq!(1, cpu.check_flag(Flags::V), "Failed addition with overflow");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ZP0()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// Manually put 0x04 into memory in the zero page
|
||||||
|
bus.write(0x000B, 0x04);
|
||||||
|
|
||||||
|
// ADC #6
|
||||||
|
bus.write(addr, 0x65); // ADC - Zero Page mode
|
||||||
|
bus.write(addr + 1, 0x0B); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x06);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x0A in the A register?
|
||||||
|
assert_eq!(0x0A, cpu.debug_get_reg(Registers::A));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ZPX()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// Manually put 0x0A into memory in the zero page
|
||||||
|
bus.write(0x000B, 0x04);
|
||||||
|
|
||||||
|
// ADC #A
|
||||||
|
bus.write(addr, 0x75); // ADC - Zero Page, X mode
|
||||||
|
bus.write(addr + 1, 0x0A); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x06);
|
||||||
|
cpu.debug_set_reg(Registers::X, 0x01);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x0A in the A register?
|
||||||
|
assert_eq!(0x0A, cpu.debug_get_reg(Registers::A));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ABS()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// Manually put 0x0A into memory in the zero page
|
||||||
|
bus.write(0x010B, 0x06);
|
||||||
|
|
||||||
|
// AND $10B
|
||||||
|
bus.write(addr, 0x6D); // ADC - Absolute mode
|
||||||
|
bus.write(addr + 1, 0x0B); // Argument
|
||||||
|
bus.write(addr + 2, 0x01); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x04);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x09 in the A register?
|
||||||
|
assert_eq!(0x0A, cpu.debug_get_reg(Registers::A));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ABX()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// Manually put 0x0A into memory
|
||||||
|
bus.write(0x010C, 0x04);
|
||||||
|
|
||||||
|
// ADC $10C
|
||||||
|
bus.write(addr, 0x7D); // ADC - Absolute, X mode
|
||||||
|
bus.write(addr + 1, 0x0B); // Argument
|
||||||
|
bus.write(addr + 2, 0x01); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x06);
|
||||||
|
cpu.debug_set_reg(Registers::X, 0x01);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x0A in the A register?
|
||||||
|
assert_eq!(0x0A, cpu.debug_get_reg(Registers::A));
|
||||||
|
}
|
||||||
@ -0,0 +1,207 @@
|
|||||||
|
|
||||||
|
#![allow(dead_code, non_snake_case)]
|
||||||
|
|
||||||
|
use crate::tests::test_bus::RAMBus;
|
||||||
|
use crate::r6502::{R6502, Bus, Registers, Flags};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn IMM()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// AND #3
|
||||||
|
bus.write(addr, 0x29); // AND - Immediate mode
|
||||||
|
bus.write(addr + 1, 0x03); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x0A);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x02 in the A register?
|
||||||
|
assert_eq!(0x02, cpu.debug_get_reg(Registers::A));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ZP0()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// Manually put 0x0A into memory in the zero page
|
||||||
|
bus.write(0x000B, 0x03);
|
||||||
|
|
||||||
|
// AND #3
|
||||||
|
bus.write(addr, 0x25); // AND - Zero Page mode
|
||||||
|
bus.write(addr + 1, 0x0B); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x0A);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x02 in the A register?
|
||||||
|
assert_eq!(0x02, cpu.debug_get_reg(Registers::A));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ZPX()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// Manually put 0x0A into memory in the zero page
|
||||||
|
bus.write(0x000B, 0x03);
|
||||||
|
|
||||||
|
// AND #3
|
||||||
|
bus.write(addr, 0x35); // AND - Zero Page, X mode
|
||||||
|
bus.write(addr + 1, 0x0A); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x0A);
|
||||||
|
cpu.debug_set_reg(Registers::X, 0x01);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x02 in the A register?
|
||||||
|
assert_eq!(0x02, cpu.debug_get_reg(Registers::A));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ABS()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// Manually put 0x0A into memory in the zero page
|
||||||
|
bus.write(0x010B, 0x03);
|
||||||
|
|
||||||
|
// AND #3
|
||||||
|
bus.write(addr, 0x2D); // AND - Absolute mode
|
||||||
|
bus.write(addr + 1, 0x0B); // Argument
|
||||||
|
bus.write(addr + 2, 0x01); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x0A);
|
||||||
|
//cpu.debug_set_reg(Registers::X, 0x01);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x02 in the A register?
|
||||||
|
assert_eq!(0x02, cpu.debug_get_reg(Registers::A));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ABX()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// Manually put 0x0A into memory in the zero page
|
||||||
|
bus.write(0x010C, 0x03);
|
||||||
|
|
||||||
|
// AND #3
|
||||||
|
bus.write(addr, 0x3D); // AND - Absolute, X mode
|
||||||
|
bus.write(addr + 1, 0x0B); // Argument
|
||||||
|
bus.write(addr + 2, 0x01); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x0A);
|
||||||
|
cpu.debug_set_reg(Registers::X, 0x01);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x02 in the A register?
|
||||||
|
assert_eq!(0x02, cpu.debug_get_reg(Registers::A));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ABY()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// Manually put 0x0A into memory in the zero page
|
||||||
|
bus.write(0x010C, 0x03);
|
||||||
|
|
||||||
|
// AND #3
|
||||||
|
bus.write(addr, 0x39); // AND - Absolute, X mode
|
||||||
|
bus.write(addr + 1, 0x0B); // Argument
|
||||||
|
bus.write(addr + 2, 0x01); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x0A);
|
||||||
|
cpu.debug_set_reg(Registers::Y, 0x01);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x02 in the A register?
|
||||||
|
assert_eq!(0x02, cpu.debug_get_reg(Registers::A));
|
||||||
|
}
|
||||||
@ -0,0 +1,569 @@
|
|||||||
|
|
||||||
|
#![allow(dead_code, non_snake_case)]
|
||||||
|
|
||||||
|
use crate::tests::test_bus::RAMBus;
|
||||||
|
use crate::r6502::{R6502, Bus, Registers, Flags};
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// IMM IMM IMM IMM IMM IMM IMM IMM IMM
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn IMM()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
///////////////////////
|
||||||
|
// Parameter is less than A reg
|
||||||
|
|
||||||
|
// Program to compare 0x10 with 0x05 (0x05 will be the argument)
|
||||||
|
bus.write(addr, 0xC9); // CMP - Immediate mode
|
||||||
|
bus.write(addr + 1, 0x05); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x10);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// C Flag should be 1, Z N Flags should be 0
|
||||||
|
assert_eq!(1, cpu.check_flag(Flags::C));
|
||||||
|
assert_eq!(0, cpu.check_flag(Flags::Z));
|
||||||
|
assert_eq!(0, cpu.check_flag(Flags::N));
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////
|
||||||
|
// Parameter is equal to the A reg
|
||||||
|
|
||||||
|
// Program to compare 0x10 with 0x10
|
||||||
|
bus.write(addr, 0xC9); // CMP - Immediate mode
|
||||||
|
bus.write(addr + 1, 0x10); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x10);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// C Z Flags should be 1, N Flag should be 0
|
||||||
|
assert_eq!(1, cpu.check_flag(Flags::C));
|
||||||
|
assert_eq!(1, cpu.check_flag(Flags::Z));
|
||||||
|
assert_eq!(0, cpu.check_flag(Flags::N));
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////
|
||||||
|
// Parameter is greater than A reg
|
||||||
|
|
||||||
|
// Program to compare 0x05 with 0x10
|
||||||
|
bus.write(addr, 0xC9); // CMP - Immediate mode
|
||||||
|
bus.write(addr + 1, 0x10); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x05);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// C Z Flags should be 0, N Flag should be 1
|
||||||
|
assert_eq!(0, cpu.check_flag(Flags::C));
|
||||||
|
assert_eq!(0, cpu.check_flag(Flags::Z));
|
||||||
|
assert_eq!(1, cpu.check_flag(Flags::N));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// ZP0 ZP0 ZP0 ZP0 ZP0 ZP0 ZP0 ZP0 ZP0
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ZP0()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////
|
||||||
|
// Parameter is less than A reg
|
||||||
|
|
||||||
|
// Manually put 0x05 into memory in the zero page
|
||||||
|
bus.write(0x000A, 0x05);
|
||||||
|
|
||||||
|
// Program to compare 0x10 with 0x05 (0x05 will be the argument)
|
||||||
|
bus.write(addr, 0xC5); // CMP - Zero Page mode
|
||||||
|
bus.write(addr + 1, 0x0A); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x10);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// C Flag should be 1, Z N Flags should be 0
|
||||||
|
assert_eq!(1, cpu.check_flag(Flags::C));
|
||||||
|
assert_eq!(0, cpu.check_flag(Flags::Z));
|
||||||
|
assert_eq!(0, cpu.check_flag(Flags::N));
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////
|
||||||
|
// Parameter is equal to the A reg
|
||||||
|
|
||||||
|
// Manually put 0x05 into memory in the zero page
|
||||||
|
bus.write(0x000A, 0x10);
|
||||||
|
|
||||||
|
// Program to compare 0x10 with 0x10
|
||||||
|
bus.write(addr, 0xC5); // CMP - Zero Page mode
|
||||||
|
bus.write(addr + 1, 0x0A); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x10);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// C Z Flags should be 1, N Flag should be 0
|
||||||
|
assert_eq!(1, cpu.check_flag(Flags::C));
|
||||||
|
assert_eq!(1, cpu.check_flag(Flags::Z));
|
||||||
|
assert_eq!(0, cpu.check_flag(Flags::N));
|
||||||
|
|
||||||
|
///////////////////////
|
||||||
|
// Parameter is greater than A reg
|
||||||
|
|
||||||
|
// Manually put 0x05 into memory in the zero page
|
||||||
|
bus.write(0x000A, 0x10);
|
||||||
|
|
||||||
|
// Program to compare 0x10 with 0x10
|
||||||
|
bus.write(addr, 0xC5); // CMP - Zero Page mode
|
||||||
|
bus.write(addr + 1, 0x0A); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x05);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// C Z Flags should be 0, N Flag should be 1
|
||||||
|
assert_eq!(0, cpu.check_flag(Flags::C));
|
||||||
|
assert_eq!(0, cpu.check_flag(Flags::Z));
|
||||||
|
assert_eq!(1, cpu.check_flag(Flags::N));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// ZPX ZPX ZPX ZPX ZPX ZPX ZPX ZPX ZPX
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
#[test]
|
||||||
|
fn ZPX()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////
|
||||||
|
// Parameter is less than A reg
|
||||||
|
|
||||||
|
// Manually put 0x05 into memory in the zero page
|
||||||
|
bus.write(0x000A, 0x05);
|
||||||
|
|
||||||
|
// Program to compare 0x05 and 0x10
|
||||||
|
bus.write(addr, 0xD5); // CMP - Zero Page, X mode
|
||||||
|
bus.write(addr + 1, 0x04); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x10);
|
||||||
|
cpu.debug_set_reg(Registers::X, 0x06);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// C Flag should be 1, Z N Flags should be 0
|
||||||
|
assert_eq!(1, cpu.check_flag(Flags::C));
|
||||||
|
assert_eq!(0, cpu.check_flag(Flags::Z));
|
||||||
|
assert_eq!(0, cpu.check_flag(Flags::N));
|
||||||
|
|
||||||
|
///////////////////////
|
||||||
|
// Parameter is equal to the A reg
|
||||||
|
|
||||||
|
// Manually put 0x10 into memory in the zero page
|
||||||
|
bus.write(0x000A, 0x10);
|
||||||
|
|
||||||
|
// Program to compare 0x05 and 0x10
|
||||||
|
bus.write(addr, 0xD5); // CMP - Zero Page, X mode
|
||||||
|
bus.write(addr + 1, 0x04); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x10);
|
||||||
|
cpu.debug_set_reg(Registers::X, 0x06);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// C Z Flags should be 1, N Flag should be 0
|
||||||
|
assert_eq!(1, cpu.check_flag(Flags::C));
|
||||||
|
assert_eq!(1, cpu.check_flag(Flags::Z));
|
||||||
|
assert_eq!(0, cpu.check_flag(Flags::N));
|
||||||
|
|
||||||
|
///////////////////////
|
||||||
|
// Parameter is greater than A reg
|
||||||
|
|
||||||
|
// Manually put 0x10 into memory in the zero page
|
||||||
|
bus.write(0x000A, 0x10);
|
||||||
|
|
||||||
|
// Program to compare 0x05 and 0x10
|
||||||
|
bus.write(addr, 0xD5); // CMP - Zero Page, X mode
|
||||||
|
bus.write(addr + 1, 0x04); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x05);
|
||||||
|
cpu.debug_set_reg(Registers::X, 0x06);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// C Z Flags should be 0, N Flag should be 1
|
||||||
|
assert_eq!(0, cpu.check_flag(Flags::C));
|
||||||
|
assert_eq!(0, cpu.check_flag(Flags::Z));
|
||||||
|
assert_eq!(1, cpu.check_flag(Flags::N));
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// ABS ABS ABS ABS ABS ABS ABS ABS ABS
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
#[test]
|
||||||
|
fn ABS()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////
|
||||||
|
// Parameter is less than A reg
|
||||||
|
|
||||||
|
// Manually put 0x05 into memory
|
||||||
|
bus.write(0x010A, 0x05);
|
||||||
|
|
||||||
|
// Program to compare 0x05 and 0x10
|
||||||
|
bus.write(addr, 0xCD); // CMP - Absolute mode
|
||||||
|
bus.write(addr + 1, 0x0A); // Argument lo word
|
||||||
|
bus.write(addr + 2, 0x01); // Argument hi word
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x10);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// C Flag should be 1, Z N Flags should be 0
|
||||||
|
assert_eq!(1, cpu.check_flag(Flags::C));
|
||||||
|
assert_eq!(0, cpu.check_flag(Flags::Z));
|
||||||
|
assert_eq!(0, cpu.check_flag(Flags::N));
|
||||||
|
|
||||||
|
///////////////////////
|
||||||
|
// Parameter is equal to the A reg
|
||||||
|
|
||||||
|
// Manually put 0x10 into memory
|
||||||
|
bus.write(0x010A, 0x10);
|
||||||
|
|
||||||
|
// Program to compare 0x10 and 0x10
|
||||||
|
bus.write(addr, 0xCD); // LDA - Absolute mode
|
||||||
|
bus.write(addr + 1, 0x0A); // Argument lo word
|
||||||
|
bus.write(addr + 2, 0x01); // Argument hi word
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x10);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// C Z Flags should be 1, N Flag should be 0
|
||||||
|
assert_eq!(1, cpu.check_flag(Flags::C));
|
||||||
|
assert_eq!(1, cpu.check_flag(Flags::Z));
|
||||||
|
assert_eq!(0, cpu.check_flag(Flags::N));
|
||||||
|
|
||||||
|
///////////////////////
|
||||||
|
// Parameter is greater than A reg
|
||||||
|
|
||||||
|
// Manually put 0x10 into memory
|
||||||
|
bus.write(0x010A, 0x10);
|
||||||
|
|
||||||
|
// Program to compare 0x05 and 0x10
|
||||||
|
bus.write(addr, 0xCD); // LDA - Absolute mode
|
||||||
|
bus.write(addr + 1, 0x0A); // Argument lo word
|
||||||
|
bus.write(addr + 2, 0x01); // Argument hi word
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x05);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// C Z Flags should be 0, N Flag should be 1
|
||||||
|
assert_eq!(0, cpu.check_flag(Flags::C));
|
||||||
|
assert_eq!(0, cpu.check_flag(Flags::Z));
|
||||||
|
assert_eq!(1, cpu.check_flag(Flags::N));
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// ABX ABX ABX ABX ABX ABX ABX ABX ABX
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
#[test]
|
||||||
|
fn ABX()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////
|
||||||
|
// Parameter is less than A reg
|
||||||
|
|
||||||
|
// Manually put 0x05 into memory
|
||||||
|
bus.write(0x010B, 0x05);
|
||||||
|
|
||||||
|
// Program to compare 0x05 to 0x10
|
||||||
|
bus.write(addr, 0xDD); // CMP - Absolute, X mode
|
||||||
|
bus.write(addr + 1, 0x0A); // Argument lo word
|
||||||
|
bus.write(addr + 2, 0x01); // Argument hi word
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::X, 0x01);
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x10);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// C Flag should be 1, Z N Flags should be 0
|
||||||
|
assert_eq!(1, cpu.check_flag(Flags::C));
|
||||||
|
assert_eq!(0, cpu.check_flag(Flags::Z));
|
||||||
|
assert_eq!(0, cpu.check_flag(Flags::N));
|
||||||
|
|
||||||
|
///////////////////////
|
||||||
|
// Parameter is equal to the A reg
|
||||||
|
|
||||||
|
|
||||||
|
// Manually put 0x10 into memory
|
||||||
|
bus.write(0x010B, 0x10);
|
||||||
|
|
||||||
|
// Program to compare 0x05 to 0x10
|
||||||
|
bus.write(addr, 0xDD); // CMP - Absolute, X mode
|
||||||
|
bus.write(addr + 1, 0x0A); // Argument lo word
|
||||||
|
bus.write(addr + 2, 0x01); // Argument hi word
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::X, 0x01);
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x10);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// C Z Flags should be 1, N Flag should be 0
|
||||||
|
assert_eq!(1, cpu.check_flag(Flags::C));
|
||||||
|
assert_eq!(1, cpu.check_flag(Flags::Z));
|
||||||
|
assert_eq!(0, cpu.check_flag(Flags::N));
|
||||||
|
|
||||||
|
///////////////////////
|
||||||
|
// Parameter is greater than A reg
|
||||||
|
|
||||||
|
|
||||||
|
// Manually put 0x05 into memory
|
||||||
|
bus.write(0x010B, 0x10);
|
||||||
|
|
||||||
|
// Program to compare 0x05 to 0x10
|
||||||
|
bus.write(addr, 0xDD); // CMP - Absolute, X mode
|
||||||
|
bus.write(addr + 1, 0x0A); // Argument lo word
|
||||||
|
bus.write(addr + 2, 0x01); // Argument hi word
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::X, 0x01);
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x05);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// C Z Flags should be 0, N Flag should be 1
|
||||||
|
assert_eq!(0, cpu.check_flag(Flags::C));
|
||||||
|
assert_eq!(0, cpu.check_flag(Flags::Z));
|
||||||
|
assert_eq!(1, cpu.check_flag(Flags::N));
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// ABY ABY ABY ABY ABY ABY ABY ABY ABY
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
#[test]
|
||||||
|
fn ABY()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////
|
||||||
|
// Parameter is less than A reg
|
||||||
|
|
||||||
|
// Manually put 0x05 into memory
|
||||||
|
bus.write(0x010B, 0x05);
|
||||||
|
|
||||||
|
// Program to compare 0x05 to 0x10
|
||||||
|
bus.write(addr, 0xD9); // CMP - Absolute, X mode
|
||||||
|
bus.write(addr + 1, 0x0A); // Argument lo word
|
||||||
|
bus.write(addr + 2, 0x01); // Argument hi word
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::Y, 0x01);
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x10);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// C Flag should be 1, Z N Flags should be 0
|
||||||
|
assert_eq!(1, cpu.check_flag(Flags::C));
|
||||||
|
assert_eq!(0, cpu.check_flag(Flags::Z));
|
||||||
|
assert_eq!(0, cpu.check_flag(Flags::N));
|
||||||
|
|
||||||
|
///////////////////////
|
||||||
|
// Parameter is equal to the A reg
|
||||||
|
|
||||||
|
|
||||||
|
// Manually put 0x10 into memory
|
||||||
|
bus.write(0x010B, 0x10);
|
||||||
|
|
||||||
|
// Program to compare 0x05 to 0x10
|
||||||
|
bus.write(addr, 0xD9); // CMP - Absolute, X mode
|
||||||
|
bus.write(addr + 1, 0x0A); // Argument lo word
|
||||||
|
bus.write(addr + 2, 0x01); // Argument hi word
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::Y, 0x01);
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x10);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// C Z Flags should be 1, N Flag should be 0
|
||||||
|
assert_eq!(1, cpu.check_flag(Flags::C));
|
||||||
|
assert_eq!(1, cpu.check_flag(Flags::Z));
|
||||||
|
assert_eq!(0, cpu.check_flag(Flags::N));
|
||||||
|
|
||||||
|
///////////////////////
|
||||||
|
// Parameter is greater than A reg
|
||||||
|
|
||||||
|
|
||||||
|
// Manually put 0x05 into memory
|
||||||
|
bus.write(0x010B, 0x10);
|
||||||
|
|
||||||
|
// Program to compare 0x05 to 0x10
|
||||||
|
bus.write(addr, 0xD9); // CMP - Absolute, X mode
|
||||||
|
bus.write(addr + 1, 0x0A); // Argument lo word
|
||||||
|
bus.write(addr + 2, 0x01); // Argument hi word
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::Y, 0x01);
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x05);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// C Z Flags should be 0, N Flag should be 1
|
||||||
|
assert_eq!(0, cpu.check_flag(Flags::C));
|
||||||
|
assert_eq!(0, cpu.check_flag(Flags::Z));
|
||||||
|
assert_eq!(1, cpu.check_flag(Flags::N));
|
||||||
|
}
|
||||||
@ -0,0 +1,207 @@
|
|||||||
|
|
||||||
|
#![allow(dead_code, non_snake_case)]
|
||||||
|
|
||||||
|
use crate::tests::test_bus::RAMBus;
|
||||||
|
use crate::r6502::{R6502, Bus, Registers};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn IMM()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// AND #3
|
||||||
|
bus.write(addr, 0x49); // EOR - Immediate mode
|
||||||
|
bus.write(addr + 1, 0x03); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x0A);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x09 in the A register?
|
||||||
|
assert_eq!(0x09, cpu.debug_get_reg(Registers::A));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ZP0()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// Manually put 0x0A into memory in the zero page
|
||||||
|
bus.write(0x000B, 0x03);
|
||||||
|
|
||||||
|
// AND #3
|
||||||
|
bus.write(addr, 0x45); // EOR - Zero Page mode
|
||||||
|
bus.write(addr + 1, 0x0B); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x0A);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x09 in the A register?
|
||||||
|
assert_eq!(0x09, cpu.debug_get_reg(Registers::A));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ZPX()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// Manually put 0x0A into memory in the zero page
|
||||||
|
bus.write(0x000B, 0x03);
|
||||||
|
|
||||||
|
// AND #3
|
||||||
|
bus.write(addr, 0x55); // EOR - Zero Page, X mode
|
||||||
|
bus.write(addr + 1, 0x0A); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x0A);
|
||||||
|
cpu.debug_set_reg(Registers::X, 0x01);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x09 in the A register?
|
||||||
|
assert_eq!(0x09, cpu.debug_get_reg(Registers::A));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ABS()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// Manually put 0x0A into memory in the zero page
|
||||||
|
bus.write(0x010B, 0x03);
|
||||||
|
|
||||||
|
// AND #3
|
||||||
|
bus.write(addr, 0x4D); // EOR - Absolute mode
|
||||||
|
bus.write(addr + 1, 0x0B); // Argument
|
||||||
|
bus.write(addr + 2, 0x01); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x0A);
|
||||||
|
//cpu.debug_set_reg(Registers::X, 0x01);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x09 in the A register?
|
||||||
|
assert_eq!(0x09, cpu.debug_get_reg(Registers::A));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ABX()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// Manually put 0x03 into memory
|
||||||
|
bus.write(0x010C, 0x03);
|
||||||
|
|
||||||
|
// EOR $10B
|
||||||
|
bus.write(addr, 0x5D); // EOR - Absolute, X mode
|
||||||
|
bus.write(addr + 1, 0x0B); // Argument
|
||||||
|
bus.write(addr + 2, 0x01); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x0A);
|
||||||
|
cpu.debug_set_reg(Registers::X, 0x01);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x09 in the A register?
|
||||||
|
assert_eq!(0x09, cpu.debug_get_reg(Registers::A));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ABY()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// Manually put 0x0A into memory in the zero page
|
||||||
|
bus.write(0x010C, 0x03);
|
||||||
|
|
||||||
|
// AND #3
|
||||||
|
bus.write(addr, 0x59); // EOR - Absolute, X mode
|
||||||
|
bus.write(addr + 1, 0x0B); // Argument
|
||||||
|
bus.write(addr + 2, 0x01); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x0A);
|
||||||
|
cpu.debug_set_reg(Registers::Y, 0x01);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x09 in the A register?
|
||||||
|
assert_eq!(0x09, cpu.debug_get_reg(Registers::A));
|
||||||
|
}
|
||||||
@ -0,0 +1,194 @@
|
|||||||
|
|
||||||
|
#![allow(dead_code, non_snake_case)]
|
||||||
|
|
||||||
|
use crate::tests::test_bus::RAMBus;
|
||||||
|
use crate::r6502::{R6502, Bus, Registers};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn IMM()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// Program to load 0x08 into the accumulator
|
||||||
|
bus.write(addr, 0xA9); // LDA - Immediate mode
|
||||||
|
bus.write(addr + 1, 0x08); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x08 in the A register?
|
||||||
|
assert_eq!(0x08, cpu.debug_get_reg(Registers::A));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ZP0()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// Manually put 0x08 into memory in the zero page
|
||||||
|
bus.write(0x000A, 0x08);
|
||||||
|
|
||||||
|
// Program to load 0x08 into the accumulator
|
||||||
|
bus.write(addr, 0xA5); // LDA - Zero Page mode
|
||||||
|
bus.write(addr + 1, 0x0A); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x08 in the A register?
|
||||||
|
assert_eq!(0x08, cpu.debug_get_reg(Registers::A));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ZPX()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// Manually put 0x08 into memory in the zero page
|
||||||
|
bus.write(0x000A, 0x08);
|
||||||
|
|
||||||
|
// Program to load 0x08 into the accumulator
|
||||||
|
bus.write(addr, 0xB5); // LDA - Zero Page, X mode
|
||||||
|
bus.write(addr + 1, 0x04); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::X, 0x06);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x08 in the A register?
|
||||||
|
assert_eq!(0x08, cpu.debug_get_reg(Registers::A));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ABS()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// Manually put 0x08 into memory in the zero page
|
||||||
|
bus.write(0x010A, 0x08);
|
||||||
|
|
||||||
|
// Program to load 0x08 into the accumulator
|
||||||
|
bus.write(addr, 0xAD); // LDA - Absolute mode
|
||||||
|
bus.write(addr + 1, 0x0A); // Argument lo word
|
||||||
|
bus.write(addr + 2, 0x01); // Argument hi word
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x08 in the A register?
|
||||||
|
assert_eq!(0x08, cpu.debug_get_reg(Registers::A));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ABX()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// Manually put 0x08 into memory in the zero page
|
||||||
|
bus.write(0x010B, 0x08);
|
||||||
|
|
||||||
|
// Program to load 0x08 into the accumulator
|
||||||
|
bus.write(addr, 0xBD); // LDA - Absolute, X mode
|
||||||
|
bus.write(addr + 1, 0x0A); // Argument lo word
|
||||||
|
bus.write(addr + 2, 0x01); // Argument hi word
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::X, 0x01);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x08 in the A register?
|
||||||
|
assert_eq!(0x08, cpu.debug_get_reg(Registers::A));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ABY()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// Manually put 0x08 into memory in the zero page
|
||||||
|
bus.write(0x010B, 0x08);
|
||||||
|
|
||||||
|
// Program to load 0x08 into the accumulator
|
||||||
|
bus.write(addr, 0xB9); // LDA - Absolute, X mode
|
||||||
|
bus.write(addr + 1, 0x0A); // Argument lo word
|
||||||
|
bus.write(addr + 2, 0x01); // Argument hi word
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::Y, 0x01);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x08 in the A register?
|
||||||
|
assert_eq!(0x08, cpu.debug_get_reg(Registers::A));
|
||||||
|
}
|
||||||
@ -0,0 +1,227 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#![allow(dead_code, non_snake_case)]
|
||||||
|
|
||||||
|
// mod test_bus;
|
||||||
|
|
||||||
|
// #[cfg(test)]
|
||||||
|
|
||||||
|
use crate::tests::test_bus::RAMBus;
|
||||||
|
use crate::r6502::{R6502, Bus, Registers};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn IMM()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// ORA #2
|
||||||
|
bus.write(addr, 0x09); // ORA - Immediate mode
|
||||||
|
bus.write(addr + 1, 0x02); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x09);
|
||||||
|
|
||||||
|
// Clock the cpu twice (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x0B in the A register?
|
||||||
|
assert_eq!(0x0B, cpu.debug_get_reg(Registers::A));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ZP0()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// Manually put 0x02 into memory in the zero page
|
||||||
|
bus.write(0x000A, 0x02);
|
||||||
|
|
||||||
|
// ORA #2
|
||||||
|
bus.write(addr, 0x05); // ORA - Zero Page mode
|
||||||
|
bus.write(addr +1, 0x0A); // Argument (memory address of the value we want to OR with)
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x09);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x0B in the A register?
|
||||||
|
assert_eq!(0x0B, cpu.debug_get_reg(Registers::A));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ZPX()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// Manually put 0x02 into memory in the zero page
|
||||||
|
bus.write(0x000A, 0x02);
|
||||||
|
|
||||||
|
// ORA #2
|
||||||
|
bus.write(addr, 0x15); // ORA - Zero Page, X mode
|
||||||
|
bus.write(addr + 1, 0x04); // Argument (memory address of the value we want to OR with)
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::X, 0x06);
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x09);
|
||||||
|
|
||||||
|
|
||||||
|
// Clock the cpu twice (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x0B in the A register?
|
||||||
|
assert_eq!(0x0B, cpu.debug_get_reg(Registers::A));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ABS()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// Manually put 0x02 into memory in the zero page
|
||||||
|
bus.write(0x010A, 0x02);
|
||||||
|
|
||||||
|
// ORA #2
|
||||||
|
bus.write(addr, 0x0D); // ORA - Absolute mode
|
||||||
|
bus.write(addr + 1, 0x0A); // Argument (memory address of the value we want to OR with)
|
||||||
|
bus.write(addr + 2, 0x01); // Argument (memory address of the value we want to OR with)
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
// cpu.debug_set_reg(Registers::X, 0x06);
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x09);
|
||||||
|
|
||||||
|
|
||||||
|
// Clock the cpu twice (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x0B in the A register?
|
||||||
|
assert_eq!(0x0B, cpu.debug_get_reg(Registers::A));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ABX()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// Manually put 0x02 into memory in the zero page
|
||||||
|
bus.write(0x010B, 0x02);
|
||||||
|
|
||||||
|
// ORA #2
|
||||||
|
bus.write(addr, 0x1D); // ORA - Absolute, X mode
|
||||||
|
bus.write(addr + 1, 0x0A); // Argument (memory address of the value we want to OR with)
|
||||||
|
bus.write(addr + 2, 0x01); // Argument (memory address of the value we want to OR with)
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::X, 0x01);
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x09);
|
||||||
|
|
||||||
|
|
||||||
|
// Clock the cpu twice (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x0B in the A register?
|
||||||
|
assert_eq!(0x0B, cpu.debug_get_reg(Registers::A));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ABY()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// Manually put 0x02 into memory in the zero page
|
||||||
|
bus.write(0x010B, 0x02);
|
||||||
|
|
||||||
|
// ORA #2
|
||||||
|
bus.write(addr, 0x19); // ORA - Absolute, X mode
|
||||||
|
bus.write(addr + 1, 0x0A); // Argument (memory address of the value we want to OR with)
|
||||||
|
bus.write(addr + 2, 0x01); // Argument (memory address of the value we want to OR with)
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::Y, 0x01);
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x09);
|
||||||
|
|
||||||
|
|
||||||
|
// Clock the cpu twice (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x0B in the A register?
|
||||||
|
assert_eq!(0x0B, cpu.debug_get_reg(Registers::A));
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,233 @@
|
|||||||
|
|
||||||
|
#![allow(dead_code, non_snake_case)]
|
||||||
|
|
||||||
|
use crate::tests::test_bus::RAMBus;
|
||||||
|
use crate::r6502::{R6502, Bus, Registers};
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// IMM IMM IMM IMM IMM IMM IMM IMM IMM
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn IMM()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// Program to subtract 0x06 from 0x0A
|
||||||
|
bus.write(addr, 0xE9); // SBC - Immediate mode
|
||||||
|
bus.write(addr + 1, 0x06); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x0A);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x04 in the A register?
|
||||||
|
assert_eq!(0x04, cpu.debug_get_reg(Registers::A));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// ZP0 ZP0 ZP0 ZP0 ZP0 ZP0 ZP0 ZP0 ZP0
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ZP0()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// Manually put 0x06 into memory in the zero page
|
||||||
|
bus.write(0x000A, 0x06);
|
||||||
|
|
||||||
|
// Program to
|
||||||
|
bus.write(addr, 0xE5); // SBC - Zero Page mode
|
||||||
|
bus.write(addr + 1, 0x0A); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x0A);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x04 in the A register?
|
||||||
|
assert_eq!(0x04, cpu.debug_get_reg(Registers::A));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// ZPX ZPX ZPX ZPX ZPX ZPX ZPX ZPX ZPX
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ZPX()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// Manually put 0x06 into memory in the zero page
|
||||||
|
bus.write(0x000A, 0x06);
|
||||||
|
|
||||||
|
// Program to
|
||||||
|
bus.write(addr, 0xF5); // - Zero Page, X mode
|
||||||
|
bus.write(addr + 1, 0x04); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::X, 0x06);
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x0A);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x04 in the A register?
|
||||||
|
assert_eq!(0x04, cpu.debug_get_reg(Registers::A));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// ABS ABS ABS ABS ABS ABS ABS ABS ABS
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ABS()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// Manually put 0x06 into memory in the zero page
|
||||||
|
bus.write(0x010A, 0x06);
|
||||||
|
|
||||||
|
// Program to
|
||||||
|
bus.write(addr, 0xED); // SBC - Absolute mode
|
||||||
|
bus.write(addr + 1, 0x0A); // Argument lo word
|
||||||
|
bus.write(addr + 2, 0x01); // Argument hi word
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x0A);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x04 in the A register?
|
||||||
|
assert_eq!(0x04, cpu.debug_get_reg(Registers::A));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// ABX ABX ABX ABX ABX ABX ABX ABX ABX
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ABX()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// Manually put 0x06 into memory in the zero page
|
||||||
|
bus.write(0x010B, 0x06);
|
||||||
|
|
||||||
|
// Program to
|
||||||
|
bus.write(addr, 0xFD); // SBC - Absolute, X mode
|
||||||
|
bus.write(addr + 1, 0x0A); // Argument lo word
|
||||||
|
bus.write(addr + 2, 0x01); // Argument hi word
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::X, 0x01);
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x0A);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x04 in the A register?
|
||||||
|
assert_eq!(0x04, cpu.debug_get_reg(Registers::A));
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// ABY ABY ABY ABY ABY ABY ABY ABY ABY
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ABY()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// Manually put 0x08 into memory in the zero page
|
||||||
|
bus.write(0x010B, 0x06);
|
||||||
|
|
||||||
|
// Program to
|
||||||
|
bus.write(addr, 0xF9); // - Absolute, Y mode
|
||||||
|
bus.write(addr + 1, 0x0A); // Argument lo word
|
||||||
|
bus.write(addr + 2, 0x01); // Argument hi word
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::Y, 0x01);
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x0A);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x04 in the A register?
|
||||||
|
assert_eq!(0x04, cpu.debug_get_reg(Registers::A));
|
||||||
|
}
|
||||||
@ -0,0 +1,185 @@
|
|||||||
|
#![allow(dead_code, non_snake_case)]
|
||||||
|
|
||||||
|
use crate::tests::test_bus::RAMBus;
|
||||||
|
use crate::r6502::{R6502, Bus, Registers};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ZP0()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// Manually put 0x0A into memory in the zero page
|
||||||
|
//bus.write(0x000B, 0x0A);
|
||||||
|
|
||||||
|
// STA $0A
|
||||||
|
bus.write(addr, 0x85); // STA - Zero Page mode
|
||||||
|
bus.write(addr + 1, 0x0A); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x0F);
|
||||||
|
|
||||||
|
// Clock the cpu to run the program (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x0F at memory address 0x0A?
|
||||||
|
assert_eq!(0x0F, bus.read(0x0A));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ZPX()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// STA
|
||||||
|
bus.write(addr, 0x95); // STA - Zero Page, X mode
|
||||||
|
bus.write(addr + 1, 0x04); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::X, 0x06);
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x0F);
|
||||||
|
|
||||||
|
|
||||||
|
// Clock the cpu twice (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x0F at memory address 0x0A?
|
||||||
|
assert_eq!(0x0F, bus.read(0x0A));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ABS()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// Manually put 0x02 into memory in the zero page
|
||||||
|
bus.write(0x010A, 0x02);
|
||||||
|
|
||||||
|
// STA
|
||||||
|
bus.write(addr, 0x8D); // STA - Absolute mode
|
||||||
|
bus.write(addr + 1, 0x0A); // Argument
|
||||||
|
bus.write(addr + 2, 0x01); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
// cpu.debug_set_reg(Registers::X, 0x06);
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x0F);
|
||||||
|
|
||||||
|
|
||||||
|
// Clock the cpu twice (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x0F at memory address 0x010A?
|
||||||
|
assert_eq!(0x0F, bus.read(0x010A));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ABX()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// STA
|
||||||
|
bus.write(addr, 0x9D); // STA - Absolute, X mode
|
||||||
|
bus.write(addr + 1, 0x0A); // Argument
|
||||||
|
bus.write(addr + 2, 0x01); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::X, 0x01);
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x0F);
|
||||||
|
|
||||||
|
|
||||||
|
// Clock the cpu twice (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x0F at memory address 0x010B?
|
||||||
|
assert_eq!(0x0F, bus.read(0x010B));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ABY()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
|
// program address
|
||||||
|
let addr = 0x0020 as u16;
|
||||||
|
|
||||||
|
// Set the program counter address
|
||||||
|
bus.write(0xFFFC, (addr & 0x00FF) as u8); // low byte
|
||||||
|
bus.write(0xFFFD, ((addr & 0xFF00) >> 8) as u8); // high byte
|
||||||
|
|
||||||
|
// Manually put 0x02 into memory in the zero page
|
||||||
|
bus.write(0x010B, 0x02);
|
||||||
|
|
||||||
|
// STA
|
||||||
|
bus.write(addr, 0x99); // STA - Absolute, X mode
|
||||||
|
bus.write(addr + 1, 0x0A); // Argument
|
||||||
|
bus.write(addr + 2, 0x01); // Argument
|
||||||
|
|
||||||
|
// Restart cpu
|
||||||
|
cpu.reset(&mut bus);
|
||||||
|
|
||||||
|
|
||||||
|
// manually setup the cpu registers
|
||||||
|
cpu.debug_set_reg(Registers::Y, 0x01);
|
||||||
|
cpu.debug_set_reg(Registers::A, 0x0F);
|
||||||
|
|
||||||
|
|
||||||
|
// Clock the cpu twice (Clock essentially runs one full instruction)
|
||||||
|
cpu.clock(&mut bus);
|
||||||
|
|
||||||
|
// Is 0x0F at memory address 0x010B?
|
||||||
|
assert_eq!(0x0F, bus.read(0x010B));
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,24 @@
|
|||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod ORA;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod AND;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod EOR;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod ADC;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod LDA;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod STA;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod CMP;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod SBC;
|
||||||
Loading…
Reference in New Issue