refactors unit tests to separate address mode tests from instruction tests.\nAlso fixes SBC instruction
parent
cccc23f2e6
commit
6af0fb3cb3
@ -1,245 +0,0 @@
|
||||
|
||||
#![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));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn IZX()
|
||||
{
|
||||
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, 0x03);
|
||||
|
||||
// Manually put 0x010C into the Zero Page
|
||||
bus.write(0x000B, 0x0C);
|
||||
bus.write(0x000C, 0x01);
|
||||
|
||||
// AND #3
|
||||
bus.write(addr, 0x21); // AND - Indirect, X mode
|
||||
bus.write(addr + 1, 0x0A); // Argument - Pointer into the Zero Page
|
||||
|
||||
// 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); // Zero Page pointer offset
|
||||
|
||||
// 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));
|
||||
}
|
||||
@ -1,246 +0,0 @@
|
||||
|
||||
#![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));
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn IZX()
|
||||
{
|
||||
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);
|
||||
|
||||
// Manually put 0x010C in the Zero Page
|
||||
bus.write(0x000B, 0x0C);
|
||||
bus.write(0x000C, 0x01);
|
||||
|
||||
// AND #3
|
||||
bus.write(addr, 0x41); // EOR - Indirect, 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));
|
||||
}
|
||||
@ -1,269 +0,0 @@
|
||||
|
||||
|
||||
|
||||
#![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));
|
||||
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn IZX()
|
||||
{
|
||||
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);
|
||||
|
||||
// Manually put 0x010B into the Zero Page
|
||||
bus.write(0x000B, 0x0B);
|
||||
bus.write(0x000C, 0x01);
|
||||
|
||||
// ORA #2
|
||||
bus.write(addr, 0x01); // ORA - Indirect, X mode
|
||||
bus.write(addr + 1, 0x0A); // Argument - Pointer to Zero Page
|
||||
|
||||
// Restart cpu
|
||||
cpu.reset(&mut bus);
|
||||
|
||||
|
||||
// manually setup the cpu registers
|
||||
cpu.debug_set_reg(Registers::X, 0x01); // Zero page pointer offset
|
||||
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));
|
||||
|
||||
}
|
||||
@ -1,226 +0,0 @@
|
||||
#![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));
|
||||
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn IZX()
|
||||
{
|
||||
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);
|
||||
|
||||
// Manuall put 0x010B into the Zero Page
|
||||
bus.write(0x000B, 0x0B);
|
||||
bus.write(0x000C, 0x01);
|
||||
|
||||
// STA
|
||||
bus.write(addr, 0x81); // STA - Indirect, X mode
|
||||
bus.write(addr + 1, 0x0A); // Argument - Pointer into the Zero page
|
||||
|
||||
// Restart cpu
|
||||
cpu.reset(&mut bus);
|
||||
|
||||
|
||||
// manually setup the cpu registers
|
||||
cpu.debug_set_reg(Registers::X, 0x01); // Zero Page pointer offset
|
||||
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));
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue