Skip to content

Commit

Permalink
Rename BasicMapper to TestMapper
Browse files Browse the repository at this point in the history
  • Loading branch information
lyrakisk committed Nov 16, 2024
1 parent 09d6b52 commit 3bee3eb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
6 changes: 3 additions & 3 deletions examples/snake/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn main() {

let rom_bytes = read(PathBuf::from("examples/snake/snake.nes")).unwrap();
let rom = Rom::try_from(&rom_bytes).unwrap();
let cpu_mapper = Rc::new(RefCell::new(BasicMapper::new()));
let cpu_mapper = Rc::new(RefCell::new(TestMapper::new()));
let mut cpu = CPU::new(cpu_mapper.clone());

println!("rom len: {}", rom.prg_rom.len());
Expand All @@ -59,7 +59,7 @@ fn main() {
cpu.execute_next_instruction();
}
}
fn handle_user_input(mapper: Rc<RefCell<BasicMapper>>, event_pump: &mut EventPump) {
fn handle_user_input(mapper: Rc<RefCell<TestMapper>>, event_pump: &mut EventPump) {
for event in event_pump.poll_iter() {
match event {
Event::Quit { .. }
Expand Down Expand Up @@ -110,7 +110,7 @@ fn color(byte: u8) -> Color {
}
}

fn read_screen_state(mapper: Rc<RefCell<BasicMapper>>, frame: &mut [u8; 32 * 3 * 32]) -> bool {
fn read_screen_state(mapper: Rc<RefCell<TestMapper>>, frame: &mut [u8; 32 * 3 * 32]) -> bool {
let mut frame_idx = 0;
let mut update = false;
for i in 0x0200..0x600 {
Expand Down
22 changes: 11 additions & 11 deletions src/cpu/addressing_modes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ impl AddressingModes {
#[cfg(test)]
mod test_addressing_modes {
use super::*;
use crate::cpu::mappers::BasicMapper;
use crate::cpu::mappers::TestMapper;
#[test]
fn test_addressing_mode_immediate() {
let mapper = Rc::new(RefCell::new(BasicMapper::new()));
let mapper = Rc::new(RefCell::new(TestMapper::new()));
let mut cpu = CPU::new(mapper);
cpu.program_counter = 0x8000;
let result = AddressingModes::Immediate.get_operand_address(&cpu);
Expand All @@ -145,7 +145,7 @@ mod test_addressing_modes {

#[test]
fn test_addressing_mode_zero_page() {
let mapper = Rc::new(RefCell::new(BasicMapper::new()));
let mapper = Rc::new(RefCell::new(TestMapper::new()));
let mut cpu = CPU::new(mapper);
cpu.program_counter = 0xAAAA;
cpu.mapper.borrow_mut().write_u8(0xAAAA, 0xAA);
Expand All @@ -155,7 +155,7 @@ mod test_addressing_modes {

#[test]
fn test_addressing_mode_zero_page_x() {
let mapper = Rc::new(RefCell::new(BasicMapper::new()));
let mapper = Rc::new(RefCell::new(TestMapper::new()));
let mut cpu = CPU::new(mapper);
cpu.program_counter = 0xAAAA;
cpu.mapper.borrow_mut().write_u8(0xAAAA, 0x80);
Expand All @@ -166,7 +166,7 @@ mod test_addressing_modes {

#[test]
fn test_addressing_mode_zero_page_y() {
let mapper = Rc::new(RefCell::new(BasicMapper::new()));
let mapper = Rc::new(RefCell::new(TestMapper::new()));
let mut cpu = CPU::new(mapper);
cpu.program_counter = 0xAAAA;
cpu.mapper.borrow_mut().write_u8(0xAAAA, 0x80);
Expand All @@ -177,7 +177,7 @@ mod test_addressing_modes {

#[test]
fn test_addressing_mode_absolute() {
let mapper = Rc::new(RefCell::new(BasicMapper::new()));
let mapper = Rc::new(RefCell::new(TestMapper::new()));
let mut cpu = CPU::new(mapper);
cpu.program_counter = 0x0;
cpu.mapper.borrow_mut().write_u8(0x0, 0x9e);
Expand All @@ -188,7 +188,7 @@ mod test_addressing_modes {

#[test]
fn test_addressing_mode_absolute_x() {
let mapper = Rc::new(RefCell::new(BasicMapper::new()));
let mapper = Rc::new(RefCell::new(TestMapper::new()));
let mut cpu = CPU::new(mapper);
cpu.program_counter = 0x0;
cpu.mapper.borrow_mut().write_u16(0x00, 2000);
Expand All @@ -199,7 +199,7 @@ mod test_addressing_modes {

#[test]
fn test_addressing_mode_absolute_y() {
let mapper = Rc::new(RefCell::new(BasicMapper::new()));
let mapper = Rc::new(RefCell::new(TestMapper::new()));
let mut cpu = CPU::new(mapper);
cpu.program_counter = 0x0;
cpu.mapper.borrow_mut().write_u16(0x00, 2000);
Expand All @@ -210,7 +210,7 @@ mod test_addressing_modes {

#[test]
fn test_addressing_mode_indexed_indirect_x() {
let mapper = Rc::new(RefCell::new(BasicMapper::new()));
let mapper = Rc::new(RefCell::new(TestMapper::new()));
let mut cpu = CPU::new(mapper);
cpu.program_counter = 0x8000;
cpu.mapper.borrow_mut().write_u8(0x8000, 0x20);
Expand All @@ -222,7 +222,7 @@ mod test_addressing_modes {

#[test]
fn test_addressing_mode_indirect_indexed_y() {
let mapper = Rc::new(RefCell::new(BasicMapper::new()));
let mapper = Rc::new(RefCell::new(TestMapper::new()));
let mut cpu = CPU::new(mapper);
cpu.program_counter = 0x8000;
cpu.mapper.borrow_mut().write_u8(0x8000, 0x52);
Expand All @@ -235,7 +235,7 @@ mod test_addressing_modes {

#[test]
fn test_get_operand() {
let mapper = Rc::new(RefCell::new(BasicMapper::new()));
let mapper = Rc::new(RefCell::new(TestMapper::new()));
let mut cpu = CPU::new(mapper);
cpu.register_a = 0x80;
let result = AddressingModes::Accumulator.get_operand(&cpu);
Expand Down
16 changes: 8 additions & 8 deletions src/cpu/mappers.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use crate::memory::*;

#[derive(Debug, Clone, PartialEq)]
pub struct BasicMapper {
pub struct TestMapper {
memory: [u8; 65536],
}

impl BasicMapper {
impl TestMapper {
pub fn new() -> Self {
BasicMapper { memory: [0; 65536] }
TestMapper { memory: [0; 65536] }
}
}

impl Memory for BasicMapper {
impl Memory for TestMapper {
fn read_u8(&self, address: u16) -> u8 {
return self.memory[address as usize];
}
Expand Down Expand Up @@ -52,29 +52,29 @@ mod test_mapper {

#[test]
fn test_mem_read() {
let mut mapper = BasicMapper::new();
let mut mapper = TestMapper::new();
mapper.memory[0x00AA] = 12;
assert_eq!(mapper.read_u8(0x00AA), 12);
}

#[test]
fn test_mem_write() {
let mut mapper = BasicMapper::new();
let mut mapper = TestMapper::new();
mapper.write_u8(0x00AA, 12);
assert_eq!(mapper.memory[0x00AA], 12);
}

#[test]
fn test_mem_write_u16() {
let mut mapper = BasicMapper::new();
let mut mapper = TestMapper::new();
mapper.write_u16(0x00AA, 0x8000);
assert_eq!(mapper.memory[0x00AA], 0x00);
assert_eq!(mapper.memory[0x00AB], 0x80);
}

#[test]
fn test_mem_read_u16() {
let mut mapper = BasicMapper::new();
let mut mapper = TestMapper::new();
mapper.memory[0x00AA] = 0x00;
mapper.memory[0x00AB] = 0x80;
assert_eq!(mapper.read_u16(0x00AA), 0x8000);
Expand Down
10 changes: 5 additions & 5 deletions src/cpu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,13 @@ impl CPU {
#[cfg(test)]
mod test_cpu {
use super::*;
use crate::cpu::mappers::BasicMapper;
use crate::cpu::mappers::TestMapper;
use json::JsonValue;
use test_case::test_case;

#[test]
fn test_load() {
let mapper = Rc::new(RefCell::new((BasicMapper::new())));
let mapper = Rc::new(RefCell::new((TestMapper::new())));
let mut cpu = CPU::new(mapper);
cpu.program_counter = 0x8000;
let program = vec![0xAA, 0x35, 0xFF, 0x00];
Expand All @@ -234,7 +234,7 @@ mod test_cpu {
#[test_case(0b0, 0b0000_0010)]
#[test_case(0b10, 0b0)]
fn test_update_zero_flag(register: u8, expected: u8) {
let mapper = Rc::new(RefCell::new(BasicMapper::new()));
let mapper = Rc::new(RefCell::new(TestMapper::new()));
let mut cpu = CPU::new(mapper);
cpu.update_zero_flag(register);
assert_eq!(cpu.status, expected);
Expand Down Expand Up @@ -491,8 +491,8 @@ mod test_cpu {
assert_eq!(mapper, final_mapper, "Memories don't match!",);
}

fn parse_json_value(json_value: &JsonValue) -> (CPU, Rc<RefCell<BasicMapper>>) {
let mapper = Rc::new(RefCell::new(BasicMapper::new()));
fn parse_json_value(json_value: &JsonValue) -> (CPU, Rc<RefCell<TestMapper>>) {
let mapper = Rc::new(RefCell::new(TestMapper::new()));
for ram_tuple in json_value["ram"].members() {
mapper.borrow_mut().write_u8(
ram_tuple[0].as_u16().unwrap(),
Expand Down

0 comments on commit 3bee3eb

Please sign in to comment.