clippy: Fix all clippy lints
This commit is contained in:
parent
627511282a
commit
a676280ec8
@ -190,12 +190,13 @@ impl Iterator for State {
|
|||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
let options = Arguments::parse_args_default_or_exit();
|
let options = Arguments::parse_args_default_or_exit();
|
||||||
let state = State::new(options)?;
|
let state = State::new(options)?;
|
||||||
Ok(for result in state {
|
for result in state {
|
||||||
if let Err(e) = result {
|
if let Err(e) = result {
|
||||||
eprintln!("{}", e.bold().red());
|
eprintln!("{}", e.bold().red());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parses a hexadecimal string into a u16
|
/// Parses a hexadecimal string into a u16
|
||||||
|
12
src/cpu.rs
12
src/cpu.rs
@ -394,7 +394,7 @@ impl CPU {
|
|||||||
/// Unset a breakpoint
|
/// Unset a breakpoint
|
||||||
// TODO: Unit test this
|
// TODO: Unit test this
|
||||||
pub fn unset_break(&mut self, point: Adr) -> &mut Self {
|
pub fn unset_break(&mut self, point: Adr) -> &mut Self {
|
||||||
fn linear_find(needle: Adr, haystack: &Vec<Adr>) -> Option<usize> {
|
fn linear_find(needle: Adr, haystack: &[Adr]) -> Option<usize> {
|
||||||
for (i, v) in haystack.iter().enumerate() {
|
for (i, v) in haystack.iter().enumerate() {
|
||||||
if *v == needle {
|
if *v == needle {
|
||||||
return Some(i);
|
return Some(i);
|
||||||
@ -402,7 +402,7 @@ impl CPU {
|
|||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
if let Some(idx) = linear_find(point, &self.breakpoints) {
|
if let Some(idx) = linear_find(point, self.breakpoints.as_slice()) {
|
||||||
assert_eq!(point, self.breakpoints.swap_remove(idx));
|
assert_eq!(point, self.breakpoints.swap_remove(idx));
|
||||||
}
|
}
|
||||||
self
|
self
|
||||||
@ -419,7 +419,7 @@ impl CPU {
|
|||||||
///# }
|
///# }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn breakpoints(&self) -> &[Adr] {
|
pub fn breakpoints(&self) -> &[Adr] {
|
||||||
&self.breakpoints.as_slice()
|
self.breakpoints.as_slice()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Unpauses the emulator for a single tick,
|
/// Unpauses the emulator for a single tick,
|
||||||
@ -498,7 +498,7 @@ impl CPU {
|
|||||||
// Use a monotonic counter when testing
|
// Use a monotonic counter when testing
|
||||||
if let Some(speed) = self.flags.monotonic {
|
if let Some(speed) = self.flags.monotonic {
|
||||||
if self.flags.vbi_wait {
|
if self.flags.vbi_wait {
|
||||||
self.flags.vbi_wait = !(self.cycle % speed == 0);
|
self.flags.vbi_wait = self.cycle % speed != 0;
|
||||||
}
|
}
|
||||||
let speed = 1.0 / speed as f64;
|
let speed = 1.0 / speed as f64;
|
||||||
self.delay -= speed;
|
self.delay -= speed;
|
||||||
@ -1003,7 +1003,7 @@ impl CPU {
|
|||||||
let addr = (y + byte) * 8 + (x & 0x3f) / 8 + self.screen;
|
let addr = (y + byte) * 8 + (x & 0x3f) / 8 + self.screen;
|
||||||
// Read a byte of sprite data into a u16, and shift it x % 8 bits
|
// Read a byte of sprite data into a u16, and shift it x % 8 bits
|
||||||
let sprite: u8 = bus.read(self.i + byte);
|
let sprite: u8 = bus.read(self.i + byte);
|
||||||
let sprite = (sprite as u16) << 8 - (x & 7) & if x % 64 > 56 { 0xff00 } else { 0xffff };
|
let sprite = (sprite as u16) << (8 - (x & 7)) & if x % 64 > 56 { 0xff00 } else { 0xffff };
|
||||||
// Read a u16 from the bus containing the two bytes which might need to be updated
|
// Read a u16 from the bus containing the two bytes which might need to be updated
|
||||||
let mut screen: u16 = bus.read(addr);
|
let mut screen: u16 = bus.read(addr);
|
||||||
// Save the bits-toggled-off flag if necessary
|
// Save the bits-toggled-off flag if necessary
|
||||||
@ -1145,7 +1145,7 @@ impl CPU {
|
|||||||
fn load_dma(&mut self, x: Reg, bus: &mut Bus) {
|
fn load_dma(&mut self, x: Reg, bus: &mut Bus) {
|
||||||
let i = self.i as usize;
|
let i = self.i as usize;
|
||||||
for (reg, value) in bus
|
for (reg, value) in bus
|
||||||
.get(i + 0..=i + x)
|
.get(i..=i + x)
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
//! A disassembler for Chip-8 opcodes
|
//! A disassembler for Chip-8 opcodes
|
||||||
|
#![allow(clippy::bad_bit_mask)]
|
||||||
use super::Disassembler;
|
use super::Disassembler;
|
||||||
use imperative_rs::InstructionSet;
|
use imperative_rs::InstructionSet;
|
||||||
use owo_colors::{OwoColorize, Style};
|
use owo_colors::{OwoColorize, Style};
|
||||||
@ -175,7 +175,7 @@ impl Default for Dis {
|
|||||||
|
|
||||||
impl Disassembler for Dis {
|
impl Disassembler for Dis {
|
||||||
fn once(&self, insn: u16) -> String {
|
fn once(&self, insn: u16) -> String {
|
||||||
if let Some((_, insn)) = Insn::decode(&insn.to_be_bytes()).ok() {
|
if let Ok((_, insn)) = Insn::decode(&insn.to_be_bytes()) {
|
||||||
format!("{}", insn.style(self.normal))
|
format!("{}", insn.style(self.normal))
|
||||||
} else {
|
} else {
|
||||||
format!("{}", format_args!("inval {insn:04x}").style(self.invalid))
|
format!("{}", format_args!("inval {insn:04x}").style(self.invalid))
|
||||||
|
@ -109,7 +109,7 @@ mod sys {
|
|||||||
// Place the address on the stack
|
// Place the address on the stack
|
||||||
bus.write(cpu.sp.wrapping_add(2), test_addr);
|
bus.write(cpu.sp.wrapping_add(2), test_addr);
|
||||||
|
|
||||||
cpu.ret(&mut bus);
|
cpu.ret(&bus);
|
||||||
|
|
||||||
// Verify the current address is the address from the stack
|
// Verify the current address is the address from the stack
|
||||||
assert_eq!(test_addr, cpu.pc);
|
assert_eq!(test_addr, cpu.pc);
|
||||||
@ -715,20 +715,20 @@ mod io {
|
|||||||
for x in 0..0xf {
|
for x in 0..0xf {
|
||||||
cpu.v[x] = 0xff;
|
cpu.v[x] = 0xff;
|
||||||
cpu.wait_for_key(x);
|
cpu.wait_for_key(x);
|
||||||
assert_eq!(true, cpu.flags.keypause);
|
assert!(cpu.flags.keypause);
|
||||||
assert_eq!(0xff, cpu.v[x]);
|
assert_eq!(0xff, cpu.v[x]);
|
||||||
// There are three parts to a button press
|
// There are three parts to a button press
|
||||||
// When the button is pressed
|
// When the button is pressed
|
||||||
cpu.press(key);
|
cpu.press(key);
|
||||||
assert_eq!(true, cpu.flags.keypause);
|
assert!(cpu.flags.keypause);
|
||||||
assert_eq!(0xff, cpu.v[x]);
|
assert_eq!(0xff, cpu.v[x]);
|
||||||
// When the button is held
|
// When the button is held
|
||||||
cpu.wait_for_key(x);
|
cpu.wait_for_key(x);
|
||||||
assert_eq!(true, cpu.flags.keypause);
|
assert!(cpu.flags.keypause);
|
||||||
assert_eq!(0xff, cpu.v[x]);
|
assert_eq!(0xff, cpu.v[x]);
|
||||||
// And when the button is released!
|
// And when the button is released!
|
||||||
cpu.release(key);
|
cpu.release(key);
|
||||||
assert_eq!(false, cpu.flags.keypause);
|
assert!(!cpu.flags.keypause);
|
||||||
assert_eq!(Some(key), cpu.flags.lastkey);
|
assert_eq!(Some(key), cpu.flags.lastkey);
|
||||||
cpu.wait_for_key(x);
|
cpu.wait_for_key(x);
|
||||||
assert_eq!(key as u8, cpu.v[x]);
|
assert_eq!(key as u8, cpu.v[x]);
|
||||||
@ -880,7 +880,7 @@ mod io {
|
|||||||
const DATA: &[u8] = b"ABCDEFGHIJKLMNOP";
|
const DATA: &[u8] = b"ABCDEFGHIJKLMNOP";
|
||||||
// Load some test data into memory
|
// Load some test data into memory
|
||||||
let addr = 0x456;
|
let addr = 0x456;
|
||||||
cpu.v.as_mut_slice().write(DATA).unwrap();
|
cpu.v.as_mut_slice().write_all(DATA).unwrap();
|
||||||
for len in 0..16 {
|
for len in 0..16 {
|
||||||
// Perform DMA store
|
// Perform DMA store
|
||||||
cpu.i = addr as u16;
|
cpu.i = addr as u16;
|
||||||
@ -890,7 +890,7 @@ mod io {
|
|||||||
assert_eq!(bus[0..=len], DATA[0..=len]);
|
assert_eq!(bus[0..=len], DATA[0..=len]);
|
||||||
assert_eq!(bus[len + 1..], [0; 16][len + 1..]);
|
assert_eq!(bus[len + 1..], [0; 16][len + 1..]);
|
||||||
// clear
|
// clear
|
||||||
bus.write(&[0; 16]).unwrap();
|
bus.write_all(&[0; 16]).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -904,7 +904,7 @@ mod io {
|
|||||||
let addr = 0x456;
|
let addr = 0x456;
|
||||||
bus.get_mut(addr..addr + DATA.len())
|
bus.get_mut(addr..addr + DATA.len())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.write(DATA)
|
.write_all(DATA)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
for len in 0..16 {
|
for len in 0..16 {
|
||||||
// Perform DMA load
|
// Perform DMA load
|
||||||
@ -958,7 +958,7 @@ mod behavior {
|
|||||||
std::thread::sleep(Duration::from_secs_f64(1.0 / 60.0));
|
std::thread::sleep(Duration::from_secs_f64(1.0 / 60.0));
|
||||||
}
|
}
|
||||||
// Display wait is disabled after a 1 frame pause
|
// Display wait is disabled after a 1 frame pause
|
||||||
assert_eq!(false, cpu.flags.vbi_wait);
|
assert!(!cpu.flags.vbi_wait);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mod breakpoint {
|
mod breakpoint {
|
||||||
@ -968,7 +968,7 @@ mod behavior {
|
|||||||
let (mut cpu, mut bus) = setup_environment();
|
let (mut cpu, mut bus) = setup_environment();
|
||||||
cpu.set_break(0x202);
|
cpu.set_break(0x202);
|
||||||
cpu.multistep(&mut bus, 10).unwrap();
|
cpu.multistep(&mut bus, 10).unwrap();
|
||||||
assert_eq!(true, cpu.flags.pause);
|
assert!(cpu.flags.pause);
|
||||||
assert_eq!(0x202, cpu.pc);
|
assert_eq!(0x202, cpu.pc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,7 @@ impl FrameBuffer {
|
|||||||
if let Some(screen) = bus.get_region(Region::Screen) {
|
if let Some(screen) = bus.get_region(Region::Screen) {
|
||||||
for (idx, byte) in screen.iter().enumerate() {
|
for (idx, byte) in screen.iter().enumerate() {
|
||||||
for bit in 0..8 {
|
for bit in 0..8 {
|
||||||
self.buffer[8 * idx + bit] = if byte & (1 << 7 - bit) as u8 != 0 {
|
self.buffer[8 * idx + bit] = if byte & (1 << (7 - bit)) as u8 != 0 {
|
||||||
self.format.fg
|
self.format.fg
|
||||||
} else {
|
} else {
|
||||||
self.format.bg
|
self.format.bg
|
||||||
@ -156,7 +156,7 @@ impl UI {
|
|||||||
}
|
}
|
||||||
self.time = Instant::now();
|
self.time = Instant::now();
|
||||||
// update framebuffer
|
// update framebuffer
|
||||||
self.fb.render(&mut self.window, &mut ch8.bus);
|
self.fb.render(&mut self.window, &ch8.bus);
|
||||||
}
|
}
|
||||||
Some(())
|
Some(())
|
||||||
}
|
}
|
||||||
@ -189,7 +189,7 @@ impl UI {
|
|||||||
.print_screen()
|
.print_screen()
|
||||||
.expect("The 'screen' memory region should exist"),
|
.expect("The 'screen' memory region should exist"),
|
||||||
F3 => {
|
F3 => {
|
||||||
debug_dump_screen(&ch8, &self.rom).expect("Unable to write debug screen dump");
|
debug_dump_screen(ch8, &self.rom).expect("Unable to write debug screen dump");
|
||||||
}
|
}
|
||||||
F4 | Slash => {
|
F4 | Slash => {
|
||||||
eprintln!("Debug {}.", {
|
eprintln!("Debug {}.", {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// (c) 2023 John A. Breaux
|
// (c) 2023 John A. Breaux
|
||||||
// This code is licensed under MIT license (see LICENSE.txt for details)
|
// This code is licensed under MIT license (see LICENSE.txt for details)
|
||||||
#![cfg_attr(feature = "unstable", feature(no_coverage))]
|
#![cfg_attr(feature = "unstable", feature(no_coverage))]
|
||||||
#![deny(missing_docs)]
|
#![deny(missing_docs, clippy::all)]
|
||||||
//! This crate implements a Chip-8 interpreter as if it were a real CPU architecture,
|
//! This crate implements a Chip-8 interpreter as if it were a real CPU architecture,
|
||||||
//! to the best of my current knowledge. As it's the first emulator project I've
|
//! to the best of my current knowledge. As it's the first emulator project I've
|
||||||
//! embarked on, and I'm fairly new to Rust, it's going to be rough around the edges.
|
//! embarked on, and I'm fairly new to Rust, it's going to be rough around the edges.
|
||||||
|
@ -22,6 +22,7 @@ mod bus {
|
|||||||
assert_eq!(r1, r2);
|
assert_eq!(r1, r2);
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(clippy::clone_on_copy)]
|
||||||
fn clone() {
|
fn clone() {
|
||||||
let r1 = Screen;
|
let r1 = Screen;
|
||||||
let r2 = r1.clone();
|
let r2 = r1.clone();
|
||||||
@ -194,8 +195,9 @@ mod dis {
|
|||||||
use imperative_rs::InstructionSet;
|
use imperative_rs::InstructionSet;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(clippy::clone_on_copy)]
|
||||||
fn clone() {
|
fn clone() {
|
||||||
let opcode = Insn::decode(&[0xeF, 0xa1]).unwrap().1; // random valid opcode
|
let opcode = Insn::decode(&[0xef, 0xa1]).unwrap().1; // random valid opcode
|
||||||
let clone = opcode.clone();
|
let clone = opcode.clone();
|
||||||
assert_eq!(opcode, clone);
|
assert_eq!(opcode, clone);
|
||||||
}
|
}
|
||||||
@ -226,6 +228,7 @@ mod ui_builder {
|
|||||||
println!("{ui_builder:?}");
|
println!("{ui_builder:?}");
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(clippy::redundant_clone)]
|
||||||
fn clone_debug() {
|
fn clone_debug() {
|
||||||
let ui_builder_clone = UIBuilder::default().clone();
|
let ui_builder_clone = UIBuilder::default().clone();
|
||||||
println!("{ui_builder_clone:?}");
|
println!("{ui_builder_clone:?}");
|
||||||
|
Loading…
Reference in New Issue
Block a user