Compare commits
4 Commits
7021dd1e56
...
2f64343196
| Author | SHA1 | Date |
|---|---|---|
|
|
2f64343196 | 2 years ago |
|
|
6af0fb3cb3 | 2 years ago |
|
|
cccc23f2e6 | 2 years ago |
|
|
93e16f0d02 | 2 years ago |
@ -1,207 +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));
|
|
||||||
}
|
|
||||||
@ -1,207 +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));
|
|
||||||
}
|
|
||||||
@ -1,227 +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));
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,185 +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));
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,24 +1,175 @@
|
|||||||
|
|
||||||
#[cfg(test)]
|
#![allow(dead_code, non_snake_case)]
|
||||||
mod ORA;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
use crate::tests::test_bus::RAMBus;
|
||||||
mod AND;
|
use crate::r6502::{R6502, Bus, Registers};
|
||||||
|
|
||||||
#[cfg(test)]
|
/////////////////////////////////////////////////////////////////////
|
||||||
mod EOR;
|
// GROUP ONE
|
||||||
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ORA()
|
||||||
|
{
|
||||||
|
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));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod ADC;
|
mod ADC;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[test]
|
||||||
mod LDA;
|
fn AND()
|
||||||
|
{
|
||||||
|
let mut cpu = R6502::new();
|
||||||
|
let mut bus = RAMBus::new();
|
||||||
|
|
||||||
#[cfg(test)]
|
// program address
|
||||||
mod STA;
|
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 EOR()
|
||||||
|
{
|
||||||
|
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 LDA()
|
||||||
|
{
|
||||||
|
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 STA()
|
||||||
|
{
|
||||||
|
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 $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));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod CMP;
|
mod CMP;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod SBC;
|
mod SBC;
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
// GROUP TWO
|
||||||
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// TODO: TEST ASL
|
||||||
Loading…
Reference in New Issue