From 4dd7a0d9ce220711b56a65846ec5f440684e7339 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Sun, 4 Apr 2021 01:19:39 -0500 Subject: [PATCH] chore: fix several clippy warnings --- src/bus.rs | 4 ++-- src/cpu.rs | 6 +++--- src/instruction.rs | 11 ++++++----- src/ppu.rs | 6 +++--- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/bus.rs b/src/bus.rs index d0b19c0..4dc2730 100644 --- a/src/bus.rs +++ b/src/bus.rs @@ -214,8 +214,8 @@ impl Bus { 0xFF01 => self.serial.next = byte, 0xFF02 => self.serial.control = byte.into(), 0xFF04 => self.timer.divider = 0x00, - 0xFF05 => self.timer.counter = byte.into(), - 0xFF06 => self.timer.modulo = byte.into(), + 0xFF05 => self.timer.counter = byte, + 0xFF06 => self.timer.modulo = byte, 0xFF07 => self.timer.control = byte.into(), 0xFF0F => self.set_interrupt_flag(byte), 0xFF11 => self.sound.ch1.sound_duty = byte.into(), diff --git a/src/cpu.rs b/src/cpu.rs index f65f1e7..a4bd8ba 100644 --- a/src/cpu.rs +++ b/src/cpu.rs @@ -68,7 +68,7 @@ impl Cpu { } pub fn load_cartridge(&mut self, path: &str) -> std::io::Result<()> { - Ok(self.bus.load_cartridge(path)?) + self.bus.load_cartridge(path) } } @@ -155,7 +155,7 @@ impl Cpu { let req = self.read_byte(0xFF0F); let enabled = self.read_byte(0xFFFF); - if let Some(_) = self.halted() { + if self.halted.is_some() { // When we're here either a HALT with IME set or // a HALT with IME not set and No pending Interrupts was called @@ -335,7 +335,7 @@ impl Cpu { write!(handle, "({:02X} ", self.read_byte(self.reg.pc))?; write!(handle, "{:02X} ", self.read_byte(self.reg.pc + 1))?; write!(handle, "{:02X} ", self.read_byte(self.reg.pc + 2))?; - write!(handle, "{:02X})\n", self.read_byte(self.reg.pc + 3))?; + writeln!(handle, "{:02X})", self.read_byte(self.reg.pc + 3))?; handle.flush()?; Ok(()) diff --git a/src/instruction.rs b/src/instruction.rs index 96863b7..391f581 100644 --- a/src/instruction.rs +++ b/src/instruction.rs @@ -613,12 +613,10 @@ impl Instruction { let halt_state = if cpu.ime() { ImeSet + } else if req & enabled != 0 { + SomePending } else { - if req & enabled != 0 { - SomePending - } else { - NonePending - } + NonePending }; cpu.halt(halt_state); @@ -1583,6 +1581,7 @@ impl Instruction { fn from_unprefixed_byte(cpu: &mut Cpu, opcode: u8) -> Self { // https://gb-archive.github.io/salvage/decoding_gbz80_opcodes/Decoding%20Gamboy%20Z80%20Opcodes.html + #![allow(clippy::many_single_char_names)] let x = (opcode >> 6) & 0x03; let y = (opcode >> 3) & 0x07; @@ -1770,6 +1769,8 @@ impl Instruction { } fn from_prefixed_byte(cpu: &mut Cpu) -> Self { + #![allow(clippy::many_single_char_names)] + let pc = cpu.register_pair(RegisterPair::PC); let opcode = cpu.read_imm_byte(pc); // FIXME: Should the PC be incremented here? diff --git a/src/ppu.rs b/src/ppu.rs index d87f086..c47a724 100644 --- a/src/ppu.rs +++ b/src/ppu.rs @@ -144,7 +144,7 @@ impl Ppu { let tile_number = self.read_byte(tile_addr); let tile_data_addr = match self.lcd_control.tile_data_addr() { - TileDataAddress::X8800 => (0x9000 as i32 + (tile_number as i32 * 16)) as u16, + TileDataAddress::X8800 => (0x9000_i32 + (tile_number as i32 * 16)) as u16, TileDataAddress::X8000 => 0x8000 + (tile_number as u16 * 16), }; @@ -554,8 +554,8 @@ impl Pixels { } pub fn pixel(&self, bit: usize) -> u8 { - let higher = &self.0[0] >> bit; - let lower = &self.0[1] >> bit; + let higher = self.0[0] >> bit; + let lower = self.0[1] >> bit; (higher & 0x01) << 1 | lower & 0x01 }