clippy: Fix all clippy lints
This commit is contained in:
		| @@ -190,12 +190,13 @@ impl Iterator for State { | ||||
| fn main() -> Result<()> { | ||||
|     let options = Arguments::parse_args_default_or_exit(); | ||||
|     let state = State::new(options)?; | ||||
|     Ok(for result in state { | ||||
|     for result in state { | ||||
|         if let Err(e) = result { | ||||
|             eprintln!("{}", e.bold().red()); | ||||
|             break; | ||||
|         } | ||||
|     }) | ||||
|     } | ||||
|     Ok(()) | ||||
| } | ||||
|  | ||||
| /// Parses a hexadecimal string into a u16 | ||||
|   | ||||
							
								
								
									
										12
									
								
								src/cpu.rs
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								src/cpu.rs
									
									
									
									
									
								
							| @@ -394,7 +394,7 @@ impl CPU { | ||||
|     /// Unset a breakpoint | ||||
|     // TODO: Unit test this | ||||
|     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() { | ||||
|                 if *v == needle { | ||||
|                     return Some(i); | ||||
| @@ -402,7 +402,7 @@ impl CPU { | ||||
|             } | ||||
|             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)); | ||||
|         } | ||||
|         self | ||||
| @@ -419,7 +419,7 @@ impl CPU { | ||||
|     ///# } | ||||
|     /// ``` | ||||
|     pub fn breakpoints(&self) -> &[Adr] { | ||||
|         &self.breakpoints.as_slice() | ||||
|         self.breakpoints.as_slice() | ||||
|     } | ||||
|  | ||||
|     /// Unpauses the emulator for a single tick, | ||||
| @@ -498,7 +498,7 @@ impl CPU { | ||||
|         // Use a monotonic counter when testing | ||||
|         if let Some(speed) = self.flags.monotonic { | ||||
|             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; | ||||
|             self.delay -= speed; | ||||
| @@ -1003,7 +1003,7 @@ impl CPU { | ||||
|             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 | ||||
|             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 | ||||
|             let mut screen: u16 = bus.read(addr); | ||||
|             // Save the bits-toggled-off flag if necessary | ||||
| @@ -1145,7 +1145,7 @@ impl CPU { | ||||
|     fn load_dma(&mut self, x: Reg, bus: &mut Bus) { | ||||
|         let i = self.i as usize; | ||||
|         for (reg, value) in bus | ||||
|             .get(i + 0..=i + x) | ||||
|             .get(i..=i + x) | ||||
|             .unwrap_or_default() | ||||
|             .iter() | ||||
|             .enumerate() | ||||
|   | ||||
| @@ -1,5 +1,5 @@ | ||||
| //! A disassembler for Chip-8 opcodes | ||||
|  | ||||
| #![allow(clippy::bad_bit_mask)] | ||||
| use super::Disassembler; | ||||
| use imperative_rs::InstructionSet; | ||||
| use owo_colors::{OwoColorize, Style}; | ||||
| @@ -175,7 +175,7 @@ impl Default for Dis { | ||||
|  | ||||
| impl Disassembler for Dis { | ||||
|     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)) | ||||
|         } else { | ||||
|             format!("{}", format_args!("inval  {insn:04x}").style(self.invalid)) | ||||
|   | ||||
| @@ -109,7 +109,7 @@ mod sys { | ||||
|         // Place the address on the stack | ||||
|         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 | ||||
|         assert_eq!(test_addr, cpu.pc); | ||||
| @@ -715,20 +715,20 @@ mod io { | ||||
|                 for x in 0..0xf { | ||||
|                     cpu.v[x] = 0xff; | ||||
|                     cpu.wait_for_key(x); | ||||
|                     assert_eq!(true, cpu.flags.keypause); | ||||
|                     assert!(cpu.flags.keypause); | ||||
|                     assert_eq!(0xff, cpu.v[x]); | ||||
|                     // There are three parts to a button press | ||||
|                     // When the button is pressed | ||||
|                     cpu.press(key); | ||||
|                     assert_eq!(true, cpu.flags.keypause); | ||||
|                     assert!(cpu.flags.keypause); | ||||
|                     assert_eq!(0xff, cpu.v[x]); | ||||
|                     // When the button is held | ||||
|                     cpu.wait_for_key(x); | ||||
|                     assert_eq!(true, cpu.flags.keypause); | ||||
|                     assert!(cpu.flags.keypause); | ||||
|                     assert_eq!(0xff, cpu.v[x]); | ||||
|                     // And when the button is released! | ||||
|                     cpu.release(key); | ||||
|                     assert_eq!(false, cpu.flags.keypause); | ||||
|                     assert!(!cpu.flags.keypause); | ||||
|                     assert_eq!(Some(key), cpu.flags.lastkey); | ||||
|                     cpu.wait_for_key(x); | ||||
|                     assert_eq!(key as u8, cpu.v[x]); | ||||
| @@ -880,7 +880,7 @@ mod io { | ||||
|         const DATA: &[u8] = b"ABCDEFGHIJKLMNOP"; | ||||
|         // Load some test data into memory | ||||
|         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 { | ||||
|             // Perform DMA store | ||||
|             cpu.i = addr as u16; | ||||
| @@ -890,7 +890,7 @@ mod io { | ||||
|             assert_eq!(bus[0..=len], DATA[0..=len]); | ||||
|             assert_eq!(bus[len + 1..], [0; 16][len + 1..]); | ||||
|             // clear | ||||
|             bus.write(&[0; 16]).unwrap(); | ||||
|             bus.write_all(&[0; 16]).unwrap(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @@ -904,7 +904,7 @@ mod io { | ||||
|         let addr = 0x456; | ||||
|         bus.get_mut(addr..addr + DATA.len()) | ||||
|             .unwrap() | ||||
|             .write(DATA) | ||||
|             .write_all(DATA) | ||||
|             .unwrap(); | ||||
|         for len in 0..16 { | ||||
|             // Perform DMA load | ||||
| @@ -958,7 +958,7 @@ mod behavior { | ||||
|                 std::thread::sleep(Duration::from_secs_f64(1.0 / 60.0)); | ||||
|             } | ||||
|             // Display wait is disabled after a 1 frame pause | ||||
|             assert_eq!(false, cpu.flags.vbi_wait); | ||||
|             assert!(!cpu.flags.vbi_wait); | ||||
|         } | ||||
|     } | ||||
|     mod breakpoint { | ||||
| @@ -968,7 +968,7 @@ mod behavior { | ||||
|             let (mut cpu, mut bus) = setup_environment(); | ||||
|             cpu.set_break(0x202); | ||||
|             cpu.multistep(&mut bus, 10).unwrap(); | ||||
|             assert_eq!(true, cpu.flags.pause); | ||||
|             assert!(cpu.flags.pause); | ||||
|             assert_eq!(0x202, cpu.pc); | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -110,7 +110,7 @@ impl FrameBuffer { | ||||
|         if let Some(screen) = bus.get_region(Region::Screen) { | ||||
|             for (idx, byte) in screen.iter().enumerate() { | ||||
|                 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 | ||||
|                     } else { | ||||
|                         self.format.bg | ||||
| @@ -156,7 +156,7 @@ impl UI { | ||||
|             } | ||||
|             self.time = Instant::now(); | ||||
|             // update framebuffer | ||||
|             self.fb.render(&mut self.window, &mut ch8.bus); | ||||
|             self.fb.render(&mut self.window, &ch8.bus); | ||||
|         } | ||||
|         Some(()) | ||||
|     } | ||||
| @@ -189,7 +189,7 @@ impl UI { | ||||
|                     .print_screen() | ||||
|                     .expect("The 'screen' memory region should exist"), | ||||
|                 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 => { | ||||
|                     eprintln!("Debug {}.", { | ||||
|   | ||||
| @@ -1,7 +1,7 @@ | ||||
| // (c) 2023 John A. Breaux | ||||
| // This code is licensed under MIT license (see LICENSE.txt for details) | ||||
| #![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, | ||||
| //! 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. | ||||
|   | ||||
		Reference in New Issue
	
	Block a user