From 3bee3eb74d48690a1f6027d79afbf752e8a3c7e3 Mon Sep 17 00:00:00 2001 From: lyrakisk <24938740+lyrakisk@users.noreply.github.com> Date: Sat, 16 Nov 2024 15:40:50 +0100 Subject: [PATCH] Rename BasicMapper to TestMapper --- examples/snake/main.rs | 6 +++--- src/cpu/addressing_modes.rs | 22 +++++++++++----------- src/cpu/mappers.rs | 16 ++++++++-------- src/cpu/mod.rs | 10 +++++----- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/examples/snake/main.rs b/examples/snake/main.rs index f8d64e7..8538f27 100644 --- a/examples/snake/main.rs +++ b/examples/snake/main.rs @@ -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()); @@ -59,7 +59,7 @@ fn main() { cpu.execute_next_instruction(); } } -fn handle_user_input(mapper: Rc>, event_pump: &mut EventPump) { +fn handle_user_input(mapper: Rc>, event_pump: &mut EventPump) { for event in event_pump.poll_iter() { match event { Event::Quit { .. } @@ -110,7 +110,7 @@ fn color(byte: u8) -> Color { } } -fn read_screen_state(mapper: Rc>, frame: &mut [u8; 32 * 3 * 32]) -> bool { +fn read_screen_state(mapper: Rc>, frame: &mut [u8; 32 * 3 * 32]) -> bool { let mut frame_idx = 0; let mut update = false; for i in 0x0200..0x600 { diff --git a/src/cpu/addressing_modes.rs b/src/cpu/addressing_modes.rs index 87df0a8..7842930 100644 --- a/src/cpu/addressing_modes.rs +++ b/src/cpu/addressing_modes.rs @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); diff --git a/src/cpu/mappers.rs b/src/cpu/mappers.rs index a02e86b..3aefbbc 100644 --- a/src/cpu/mappers.rs +++ b/src/cpu/mappers.rs @@ -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]; } @@ -52,21 +52,21 @@ 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); @@ -74,7 +74,7 @@ mod test_mapper { #[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); diff --git a/src/cpu/mod.rs b/src/cpu/mod.rs index 0d7087d..c71f47f 100644 --- a/src/cpu/mod.rs +++ b/src/cpu/mod.rs @@ -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]; @@ -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); @@ -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>) { - let mapper = Rc::new(RefCell::new(BasicMapper::new())); + fn parse_json_value(json_value: &JsonValue) -> (CPU, Rc>) { + 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(),