From 415c3eca40a039e280296cfbda38dcd8c0131eaa Mon Sep 17 00:00:00 2001 From: Logan McNaughton <848146+loganmc10@users.noreply.github.com> Date: Tue, 31 Dec 2024 22:15:39 +0100 Subject: [PATCH] Clippy fixes (#99) --- src/device.rs | 4 ++-- src/device/cart.rs | 2 +- src/device/controller.rs | 4 ++-- src/device/cop1.rs | 3 +-- src/device/cpu_instructions.rs | 10 ++++------ src/device/rsp_su_instructions.rs | 9 ++++----- src/device/rsp_vu_instructions.rs | 8 +++----- src/device/tlb.rs | 3 +-- src/ui/audio.rs | 6 ++---- 9 files changed, 20 insertions(+), 29 deletions(-) diff --git a/src/device.rs b/src/device.rs index fce584c5..8d037a3d 100644 --- a/src/device.rs +++ b/src/device.rs @@ -89,7 +89,7 @@ fn swap_rom(contents: Vec) -> Vec { fn get_rom_contents(file_path: &std::path::Path) -> Vec { let mut contents = vec![]; - if file_path.extension().unwrap().to_ascii_lowercase() == "zip" { + if file_path.extension().unwrap().eq_ignore_ascii_case("zip") { let zip_file = fs::File::open(file_path).unwrap(); let mut archive = zip::ZipArchive::new(zip_file).unwrap(); for i in 0..archive.len() { @@ -106,7 +106,7 @@ fn get_rom_contents(file_path: &std::path::Path) -> Vec { break; } } - } else if file_path.extension().unwrap().to_ascii_lowercase() == "7z" { + } else if file_path.extension().unwrap().eq_ignore_ascii_case("7z") { let mut archive = sevenz_rust::SevenZReader::open(file_path, sevenz_rust::Password::empty()).unwrap(); diff --git a/src/device/cart.rs b/src/device/cart.rs index d31f7b49..bd5aa8e6 100644 --- a/src/device/cart.rs +++ b/src/device/cart.rs @@ -159,7 +159,7 @@ pub fn af_rtc_write_block(device: &mut device::Device, block: usize, offset: usi match device.pif.ram[block] { 0 => { device.cart.rtc.control = - (device.pif.ram[offset + 1] as u16) << 8 | device.pif.ram[offset] as u16; + ((device.pif.ram[offset + 1] as u16) << 8) | device.pif.ram[offset] as u16; device.pif.ram[status] = 0x00; } 1 => { diff --git a/src/device/controller.rs b/src/device/controller.rs index f73cbf09..5631b8ff 100644 --- a/src/device/controller.rs +++ b/src/device/controller.rs @@ -75,7 +75,7 @@ pub fn pak_read_block( channel: usize, ) { let address = - (device.pif.ram[addr_acrc] as u16) << 8 | (device.pif.ram[addr_acrc + 1] & 0xe0) as u16; + ((device.pif.ram[addr_acrc] as u16) << 8) | (device.pif.ram[addr_acrc + 1] & 0xe0) as u16; let handler = device.pif.channels[channel].pak_handler; if handler.is_some() { @@ -94,7 +94,7 @@ pub fn pak_write_block( channel: usize, ) { let address = - (device.pif.ram[addr_acrc] as u16) << 8 | (device.pif.ram[addr_acrc + 1] & 0xe0) as u16; + ((device.pif.ram[addr_acrc] as u16) << 8) | (device.pif.ram[addr_acrc + 1] & 0xe0) as u16; let handler = device.pif.channels[channel].pak_handler; if handler.is_some() { diff --git a/src/device/cop1.rs b/src/device/cop1.rs index ace74f8e..1441674b 100644 --- a/src/device/cop1.rs +++ b/src/device/cop1.rs @@ -359,8 +359,7 @@ pub fn set_control_registers_fpu(device: &mut device::Device, index: u32, data: device.cpu.cop1.fcr31 = data & FCR31_WRITE_MASK; // the Cause bits are ANDed with the Enable bits to check for exceptions // "Unimplemented Operation" has no Enable bit and always causes an exception - if (device.cpu.cop1.fcr31 & FCR31_CAUSE_MASK) >> 5 - & (device.cpu.cop1.fcr31 & FCR31_ENABLE_MASK) + if ((device.cpu.cop1.fcr31 & FCR31_CAUSE_MASK) >> 5) & (device.cpu.cop1.fcr31 & FCR31_ENABLE_MASK) != 0 || device.cpu.cop1.fcr31 & FCR31_CAUSE_UNIMP_BIT != 0 { diff --git a/src/device/cpu_instructions.rs b/src/device/cpu_instructions.rs index 36875ab7..1dad9e8b 100644 --- a/src/device/cpu_instructions.rs +++ b/src/device/cpu_instructions.rs @@ -345,13 +345,12 @@ pub fn lwl(device: &mut device::Device, opcode: u32) { phys_address &= !3; device.cpu.gpr[rt(opcode) as usize] = se32( - ((device.cpu.gpr[rt(opcode) as usize] as u32) & mask - | device::memory::data_read( + ((device.cpu.gpr[rt(opcode) as usize] as u32) & mask | (device::memory::data_read( device, phys_address, device::memory::AccessSize::Word, cached, - ) << shift) as i32, + ) << shift)) as i32, ) } @@ -430,13 +429,12 @@ pub fn lwr(device: &mut device::Device, opcode: u32) { phys_address &= !3; device.cpu.gpr[rt(opcode) as usize] = se32( - ((device.cpu.gpr[rt(opcode) as usize] as u32) & (mask as u32) - | device::memory::data_read( + ((device.cpu.gpr[rt(opcode) as usize] as u32) & (mask as u32) | (device::memory::data_read( device, phys_address, device::memory::AccessSize::Word, cached, - ) >> shift) as i32, + ) >> shift)) as i32, ) } diff --git a/src/device/rsp_su_instructions.rs b/src/device/rsp_su_instructions.rs index 3db83ff5..9a31ab8a 100644 --- a/src/device/rsp_su_instructions.rs +++ b/src/device/rsp_su_instructions.rs @@ -208,7 +208,7 @@ pub fn lw(device: &mut device::Device, opcode: u32) { w[3] = device.rsp.mem[(address as usize + 3) & 0xFFF]; device.rsp.cpu.gpr[rt(opcode) as usize] = - (w[0] as u32) << 24 | (w[1] as u32) << 16 | (w[2] as u32) << 8 | (w[3] as u32) + ((w[0] as u32) << 24) | ((w[1] as u32) << 16) | ((w[2] as u32) << 8) | (w[3] as u32) } pub fn lbu(device: &mut device::Device, opcode: u32) { @@ -240,7 +240,7 @@ pub fn lwu(device: &mut device::Device, opcode: u32) { w[3] = device.rsp.mem[(address as usize + 3) & 0xFFF]; device.rsp.cpu.gpr[rt(opcode) as usize] = - (w[0] as u32) << 24 | (w[1] as u32) << 16 | (w[2] as u32) << 8 | (w[3] as u32) + ((w[0] as u32) << 24) | ((w[1] as u32) << 16) | ((w[2] as u32) << 8) | (w[3] as u32) } pub fn sb(device: &mut device::Device, opcode: u32) { @@ -486,7 +486,7 @@ pub fn mfc2(device: &mut device::Device, opcode: u32) { device.rsp.cpu.vpr[rd(opcode) as usize], velement(opcode) + 1, ); - device.rsp.cpu.gpr[rt(opcode) as usize] = ((hi as u16) << 8 | (lo as u16)) as i16 as i32 as u32 + device.rsp.cpu.gpr[rt(opcode) as usize] = (((hi as u16) << 8) | (lo as u16)) as i16 as i32 as u32 } pub fn cfc2(device: &mut device::Device, opcode: u32) { @@ -936,8 +936,7 @@ pub fn shv(device: &mut device::Device, opcode: u32) { let mut offset = 0; while offset < 8 { let byte_val = element + offset * 2; - let value = get_vpr_byte(device.rsp.cpu.vpr[rt(opcode) as usize], byte_val) << 1 - | get_vpr_byte(device.rsp.cpu.vpr[rt(opcode) as usize], byte_val + 1) >> 7; + let value = (get_vpr_byte(device.rsp.cpu.vpr[rt(opcode) as usize], byte_val) << 1) | (get_vpr_byte(device.rsp.cpu.vpr[rt(opcode) as usize], byte_val + 1) >> 7); device.rsp.mem[((address + ((index + offset * 2) & 15) as u32) & 0xFFF) as usize] = value; offset += 1; } diff --git a/src/device/rsp_vu_instructions.rs b/src/device/rsp_vu_instructions.rs index 93f015ad..ee51a960 100644 --- a/src/device/rsp_vu_instructions.rs +++ b/src/device/rsp_vu_instructions.rs @@ -478,7 +478,7 @@ pub fn vmacq(device: &mut device::Device, opcode: u32) { let mut n = 0; while n < 8 { let mut product = - (get_vpr_element(*acch, n) as i32) << 16 | (get_vpr_element(*accm, n) as i32); + ((get_vpr_element(*acch, n) as i32) << 16) | (get_vpr_element(*accm, n) as i32); if product < 0 && (product & (1 << 5)) == 0 { product += 32 } else if product >= 32 && (product & (1 << 5)) == 0 { @@ -1275,8 +1275,7 @@ pub fn vrcpl(device: &mut device::Device, opcode: u32) { let mut result; let vte = vte(device, vt(opcode), ve(opcode) as usize); let input = if device.rsp.cpu.divdp { - (device.rsp.cpu.divin as i32) << 16 - | get_vpr_element(device.rsp.cpu.vpr[vt(opcode) as usize], ve(opcode) as u8) as u16 + ((device.rsp.cpu.divin as i32) << 16) | get_vpr_element(device.rsp.cpu.vpr[vt(opcode) as usize], ve(opcode) as u8) as u16 as i32 } else { get_vpr_element(device.rsp.cpu.vpr[vt(opcode) as usize], ve(opcode) as u8) as i16 as i32 @@ -1371,8 +1370,7 @@ pub fn vrsql(device: &mut device::Device, opcode: u32) { let mut result; let vte = vte(device, vt(opcode), ve(opcode) as usize); let input = if device.rsp.cpu.divdp { - (device.rsp.cpu.divin as i32) << 16 - | get_vpr_element(device.rsp.cpu.vpr[vt(opcode) as usize], ve(opcode) as u8) as u16 + ((device.rsp.cpu.divin as i32) << 16) | get_vpr_element(device.rsp.cpu.vpr[vt(opcode) as usize], ve(opcode) as u8) as u16 as i32 } else { get_vpr_element(device.rsp.cpu.vpr[vt(opcode) as usize], ve(opcode) as u8) as i16 as i32 diff --git a/src/device/tlb.rs b/src/device/tlb.rs index a84e7e46..b6bb9e9c 100644 --- a/src/device/tlb.rs +++ b/src/device/tlb.rs @@ -38,8 +38,7 @@ pub fn read(device: &mut device::Device, index: u64) { device.cpu.cop0.tlb_entries[index as usize].mask << 13; device.cpu.cop0.regs[device::cop0::COP0_ENTRYHI_REG as usize] = - (device.cpu.cop0.tlb_entries[index as usize].region as u64) << 62 - | device.cpu.cop0.tlb_entries[index as usize].vpn2 << 13 + ((device.cpu.cop0.tlb_entries[index as usize].region as u64) << 62) | (device.cpu.cop0.tlb_entries[index as usize].vpn2 << 13) | (device.cpu.cop0.tlb_entries[index as usize].asid) as u64; device.cpu.cop0.regs[device::cop0::COP0_ENTRYLO0_REG as usize] = diff --git a/src/ui/audio.rs b/src/ui/audio.rs index 00ebc0ff..a48da040 100644 --- a/src/ui/audio.rs +++ b/src/ui/audio.rs @@ -23,12 +23,10 @@ pub fn play_audio(device: &mut device::Device, dram_addr: usize, length: u64) { let mut i = 0; while i < length as usize / 2 { // Left channel - primary_buffer[i] = device.rdram.mem[dram_addr + (i * 2) + 2] as i16 - | (device.rdram.mem[dram_addr + (i * 2) + 3] as i16) << 8; + primary_buffer[i] = device.rdram.mem[dram_addr + (i * 2) + 2] as i16 | ((device.rdram.mem[dram_addr + (i * 2) + 3] as i16) << 8); // Right channel - primary_buffer[i + 1] = device.rdram.mem[dram_addr + (i * 2)] as i16 - | (device.rdram.mem[dram_addr + (i * 2) + 1] as i16) << 8; + primary_buffer[i + 1] = device.rdram.mem[dram_addr + (i * 2)] as i16 | ((device.rdram.mem[dram_addr + (i * 2) + 1] as i16) << 8); i += 2; }