diff --git a/.github/workflows/basic-pipeline.yml b/.github/workflows/basic-pipeline.yml index 075d88e..517d516 100644 --- a/.github/workflows/basic-pipeline.yml +++ b/.github/workflows/basic-pipeline.yml @@ -21,6 +21,8 @@ jobs: uses: dtolnay/rust-toolchain@stable - name: Build + env: + RUSTFLAGS: -D warnings run: cargo build - name: Test @@ -62,4 +64,4 @@ jobs: with: packages: libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev libsdl2-gfx-dev gcc - run: if ls ~/.cargo/bin/ | grep -q "^cargo-tarpaulin" ; then echo "cargo-tarpaulin is already installed"; else cargo install cargo-tarpaulin; fi - - run: cargo tarpaulin --ignore-tests \ No newline at end of file + - run: cargo tarpaulin --fail-under 60 \ No newline at end of file diff --git a/emulator/src/cartridge/cartridge.rs b/emulator/src/cartridge/cartridge.rs index 6d7c4a4..fcc74b2 100644 --- a/emulator/src/cartridge/cartridge.rs +++ b/emulator/src/cartridge/cartridge.rs @@ -5,7 +5,6 @@ use crate::cartridge::formats::i_nes::Ines; use crate::cartridge::formats::nes_2::Nes2; use crate::cartridge::registers::chr_rom::ChrRom; use crate::cartridge::registers::prg_rom::PrgRom; -use byteorder::ReadBytesExt; use std::fs::File; use std::io::{BufReader, Read, Seek, SeekFrom}; use std::path::Path; diff --git a/emulator/src/cartridge/common/enums.rs b/emulator/src/cartridge/common/enums.rs index 7e4758b..c8bc6dd 100644 --- a/emulator/src/cartridge/common/enums.rs +++ b/emulator/src/cartridge/common/enums.rs @@ -1,13 +1,52 @@ -#[derive(Debug, PartialEq)] +use std::fmt::Debug; pub enum Nes { Ines, Nes2, } -#[derive(Debug, PartialEq)] +impl Debug for Nes { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Nes::Ines => write!(f, "Ines"), + Nes::Nes2 => write!(f, "Nes2"), + } + } +} + +impl PartialEq for Nes { + fn eq(&self, other: &Self) -> bool { + matches!( + (self, other), + (Nes::Ines, Nes::Ines) | (Nes::Nes2, Nes::Nes2) + ) + } +} pub enum Mirroring { Horizontal, Vertical, SingleScreen, FourScreen, } + +impl Debug for Mirroring { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Mirroring::Horizontal => write!(f, "Mirroring::Horizontal"), + Mirroring::Vertical => write!(f, "Mirroring::Vertical"), + Mirroring::SingleScreen => write!(f, "Mirroring::SingleScreen"), + Mirroring::FourScreen => write!(f, "Mirroring::FourScreen"), + } + } +} + +impl PartialEq for Mirroring { + fn eq(&self, other: &Self) -> bool { + matches!( + (self, other), + (Mirroring::Horizontal, Mirroring::Horizontal) + | (Mirroring::Vertical, Mirroring::Vertical) + | (Mirroring::SingleScreen, Mirroring::SingleScreen) + | (Mirroring::FourScreen, Mirroring::FourScreen) + ) + } +} diff --git a/emulator/src/cartridge/file_loader.rs b/emulator/src/cartridge/file_loader.rs index 473e287..c5e1ade 100644 --- a/emulator/src/cartridge/file_loader.rs +++ b/emulator/src/cartridge/file_loader.rs @@ -37,15 +37,6 @@ pub fn read_banks( Ok(banks) } -fn read_check_is_valid_nes_file(file: &mut R) -> anyhow::Result<()> { - let mut magic_bytes = [0; 4]; - file.read_exact(&mut magic_bytes)?; - if (magic_bytes) != NES_FILE_MAGIC_BYTES { - return Err(anyhow::Error::new(NesRomReadError::FileFormatNotSupported)); - } - Ok(()) -} - #[cfg(test)] mod tests { use super::*; diff --git a/emulator/src/cartridge/formats/i_nes.rs b/emulator/src/cartridge/formats/i_nes.rs index 8faa9b6..307fe96 100644 --- a/emulator/src/cartridge/formats/i_nes.rs +++ b/emulator/src/cartridge/formats/i_nes.rs @@ -10,6 +10,8 @@ use std::fs::File; use std::io::{BufReader, Read}; use std::path::Path; +use std::fmt::Debug; + // Bytes Description // 0-3 Constant $4E $45 $53 $1A (ASCII "NES" followed by MS-DOS end-of-file) // 4 Size of PRG ROM in 16 KB units @@ -20,7 +22,6 @@ use std::path::Path; // 9 Flags 9 – TV system (rarely used extension) // 10 Flags 10 – TV system, PRG-RAM presence (unofficial, rarely used extension) // 11-15 Unused padding (should be filled with zero, but some rippers put their name across bytes 7-15) -#[derive(Debug)] struct InesHeader { prg_rom_size: u8, chr_rom_size: u8, @@ -32,6 +33,21 @@ struct InesHeader { zero: [u8; 5], } +impl Debug for InesHeader { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("InesHeader") + .field("prg_rom_size", &self.prg_rom_size) + .field("chr_rom_size", &self.chr_rom_size) + .field("flags_6", &self.flags_6) + .field("flags_7", &self.flags_7) + .field("prg_ram_size", &self.prg_ram_size) + .field("flags_9", &self.flags_9) + .field("flags_10", &self.flags_10) + .field("zero", &self.zero) + .finish() + } +} + // Header (16 bytes) // Trainer, if present (0 or 512 bytes) // PRG ROM data (16384 * x bytes) @@ -39,7 +55,6 @@ struct InesHeader { // PlayChoice INST-ROM, if present (0 or 8192 bytes) // PlayChoice PROM, if present (16 bytes Data, 16 bytes CounterOut) (this is often missing; see PC10 ROM-Images for details) // Some ROM-Images additionally contain a 128-byte (or sometimes 127-byte) title at the end of the file. -#[derive(Debug)] pub struct Ines { header: InesHeader, trainer: Option<[u8; 512]>, @@ -54,6 +69,24 @@ pub struct Ines { title: Option<[u8; 128]>, } +impl Debug for Ines { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("Ines") + .field("header", &self.header) + .field("trainer", &self.trainer) + .field("mirroring", &self.mirroring) + .field("battery", &self.battery) + .field("four_screen_vram", &self.four_screen_vram) + .field("prg_rom", &self.prg_rom) + .field("chr_rom", &self.chr_rom) + .field("mapper", &self.mapper) + .field("play_choice_inst_rom", &self.play_choice_inst_rom) + .field("play_choice_10", &self.play_choice_10) + .field("title", &self.title) + .finish() + } +} + impl Ines { fn header_from_file(file: &mut R) -> anyhow::Result { let mut header = [0; 16]; diff --git a/emulator/src/cartridge/formats/nes_2.rs b/emulator/src/cartridge/formats/nes_2.rs index 7c9967a..39cfed8 100644 --- a/emulator/src/cartridge/formats/nes_2.rs +++ b/emulator/src/cartridge/formats/nes_2.rs @@ -7,7 +7,7 @@ use std::io::{BufReader, Read}; use std::path::Path; struct Nes2Header {} - +#[allow(dead_code)] pub struct Nes2 { header: Nes2Header, } @@ -46,3 +46,17 @@ impl FileLoadable for Nes2 { Ok(Nes2 { header }) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_header_from_file() { + let data = [ + 'N' as u8, 'E' as u8, 'S' as u8, 0x1A, 0, 0, 0, 0x08, 0, 0, 0, 0, 0, 0, 0, 0, + ]; + let mut cursor = std::io::Cursor::new(data); + let header = Nes2::header_from_file(&mut cursor).unwrap(); + } +} diff --git a/emulator/src/cpu/cpu.rs b/emulator/src/cpu/cpu.rs index 3621841..aeb9b85 100644 --- a/emulator/src/cpu/cpu.rs +++ b/emulator/src/cpu/cpu.rs @@ -1,8 +1,8 @@ use crate::bus::BusLike; use crate::cpu::micro_instructions::{MicroInstruction, MicroInstructionSequence}; -use crate::cpu::operations::Operation; use crate::cpu::registers::Registers; +#[allow(dead_code)] pub struct CPU { bus: T, registers: Registers, @@ -28,7 +28,7 @@ pub enum CPUState { Fetching, Execution, } - +#[allow(dead_code)] impl CPU { fn new(bus: T) -> Self { let registers = Registers::new(); @@ -168,6 +168,7 @@ impl CPUFlag { #[cfg(test)] mod tests { + use crate::cpu::operations::Operation; use std::collections::btree_map::Values; use crate::bus; diff --git a/emulator/src/cpu/registers.rs b/emulator/src/cpu/registers.rs index d2884f4..058a753 100644 --- a/emulator/src/cpu/registers.rs +++ b/emulator/src/cpu/registers.rs @@ -3,6 +3,7 @@ use crate::cpu::cpu::CPUFlag; use crate::cpu::micro_instructions::MicroInstructionSequence; use crate::cpu::operations::Operation; +#[allow(dead_code)] pub struct Registers { pub x: u8, pub y: u8, @@ -93,7 +94,7 @@ impl Registers { pub fn read_operation_code(&mut self, bus: &mut T) { self.operation = bus.read(self.program_counter as u16); } - + #[allow(unused_variables)] pub fn decode_operation(&mut self, bus: &T) { let operation_code = self.operation; println!("Operation code: {:#X}", operation_code); diff --git a/emulator/src/ppu/vram/vram.rs b/emulator/src/ppu/vram/vram.rs index 52ab031..9e58dac 100644 --- a/emulator/src/ppu/vram/vram.rs +++ b/emulator/src/ppu/vram/vram.rs @@ -1,6 +1,7 @@ use crate::addressing::Addressable; use crate::mirroring::Mirroring; use log::{debug, info}; +#[allow(unused_imports)] use std::cmp::PartialEq; use std::fmt::Debug;