From cacf71b61c9e9919f5e4bb07f57dfb90fa8d68b1 Mon Sep 17 00:00:00 2001 From: Muhammad Nauman Raza Date: Fri, 22 Mar 2024 20:35:05 +0000 Subject: [PATCH] refactor: with clippy Former-commit-id: c57ef7336468ec1b2386a1c3faa753468b45eeb3 Former-commit-id: a98ec18b83a192c371cedbf3cd0efbb1586c4552 --- Cargo.toml | 2 +- arm7tdmi/build.rs | 6 +++--- arm7tdmi/src/alu.rs | 16 +++++++-------- arm7tdmi/src/arm/exec.rs | 13 ++++++------ arm7tdmi/src/cpu.rs | 2 +- arm7tdmi/src/disass.rs | 2 +- arm7tdmi/src/thumb/exec.rs | 15 ++++++-------- core/src/bios.rs | 2 +- core/src/cartridge/backup/backup_file.rs | 2 +- core/src/cartridge/backup/eeprom.rs | 14 ++----------- core/src/cartridge/backup/flash.rs | 8 ++++---- core/src/cartridge/builder.rs | 17 ++++++++-------- core/src/cartridge/mod.rs | 7 ++----- core/src/cartridge/rtc.rs | 5 +---- core/src/gba.rs | 3 +-- core/src/gdb_support.rs | 2 +- core/src/gpu/layer.rs | 2 -- core/src/gpu/mod.rs | 4 ++-- core/src/gpu/mosaic.rs | 1 - core/src/gpu/render/obj.rs | 6 +++--- core/src/gpu/render/text.rs | 8 ++++---- core/src/iodev.rs | 26 +++++++++++------------- core/src/keypad.rs | 6 +++--- core/src/mgba_debug.rs | 6 ++++++ core/src/sched.rs | 8 +++++++- core/src/sound/interface.rs | 2 +- core/src/sysbus.rs | 2 +- platform/rustboyadvance-sdl2/src/main.rs | 1 - 28 files changed, 86 insertions(+), 102 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8520793..0ad98b1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ members = [ "platform/rustboyadvance-jni", "fps_bench" ] - +resolver = "1" default-members = ["platform/rustboyadvance-sdl2"] [profile.dev] diff --git a/arm7tdmi/build.rs b/arm7tdmi/build.rs index 33eeeae..80e3757 100644 --- a/arm7tdmi/build.rs +++ b/arm7tdmi/build.rs @@ -42,7 +42,7 @@ fn thumb_decode(i: u16) -> (&'static str, String) { } else if i & 0xfc00 == 0x4000 { ( "AluOps", - format!("exec_thumb_alu_ops::<{OP}>", OP = i.bit_range(6..10) as u16), + format!("exec_thumb_alu_ops::<{OP}>", OP = i.bit_range(6..10)), ) } else if i & 0xfc00 == 0x4400 { ( @@ -424,11 +424,11 @@ fn main() { // TODO - don't do this in the build script and use `const fn` instead when it becomes stable let out_dir = env::var_os("OUT_DIR").unwrap(); let thumb_lut_path = Path::new(&out_dir).join("thumb_lut.rs"); - let mut thumb_lut_file = fs::File::create(&thumb_lut_path).expect("failed to create file"); + let mut thumb_lut_file = fs::File::create(thumb_lut_path).expect("failed to create file"); generate_thumb_lut(&mut thumb_lut_file).expect("failed to generate thumb table"); let arm_lut_path = Path::new(&out_dir).join("arm_lut.rs"); - let mut arm_lut_file = fs::File::create(&arm_lut_path).expect("failed to create file"); + let mut arm_lut_file = fs::File::create(arm_lut_path).expect("failed to create file"); generate_arm_lut(&mut arm_lut_file).expect("failed to generate arm table"); println!("cargo:rerun-if-changed=build.rs"); diff --git a/arm7tdmi/src/alu.rs b/arm7tdmi/src/alu.rs index 9d0a897..d23996d 100644 --- a/arm7tdmi/src/alu.rs +++ b/arm7tdmi/src/alu.rs @@ -77,7 +77,7 @@ impl BarrelShifterValue { /// Decode operand2 as an immediate value pub fn decode_rotated_immediate(&self) -> Option { if let BarrelShifterValue::RotatedImmediate(immediate, rotate) = self { - return Some(immediate.rotate_right(*rotate) as u32); + return Some(immediate.rotate_right(*rotate)); } None } @@ -163,7 +163,7 @@ impl Arm7tdmiCore { pub fn rrx(&mut self, val: u32, carry: &mut bool) -> u32 { let old_c = *carry as i32; *carry = val & 0b1 != 0; - (((val as u32) >> 1) as i32 | (old_c << 31)) as u32 + ((val >> 1) as i32 | (old_c << 31)) as u32 } pub fn ror( @@ -189,7 +189,7 @@ impl Arm7tdmiCore { } else { val }; - *carry = (val as u32).bit(31); + *carry = (val).bit(31); val } } @@ -265,7 +265,7 @@ impl Arm7tdmiCore { let rs = offset.bit_range(8..12) as usize; self.shift_by_register(op, reg, rs, carry) } else { - let amount = offset.bit_range(7..12) as u32; + let amount = offset.bit_range(7..12); self.barrel_shift_op(op, self.get_reg(reg), amount, carry, true) } } @@ -284,12 +284,12 @@ impl Arm7tdmiCore { pub fn get_barrel_shifted_value(&mut self, sval: &BarrelShifterValue, carry: &mut bool) -> u32 { // TODO decide if error handling or panic here match sval { - BarrelShifterValue::ImmediateValue(offset) => *offset as u32, + BarrelShifterValue::ImmediateValue(offset) => *offset, BarrelShifterValue::ShiftedRegister(shifted_reg) => { - let added = (*shifted_reg).added.unwrap_or(true); - let abs = self.register_shift(shifted_reg, carry) as u32; + let added = (shifted_reg).added.unwrap_or(true); + let abs = self.register_shift(shifted_reg, carry); if added { - abs as u32 + abs } else { (-(abs as i32)) as u32 } diff --git a/arm7tdmi/src/arm/exec.rs b/arm7tdmi/src/arm/exec.rs index ef3984d..11db301 100644 --- a/arm7tdmi/src/arm/exec.rs +++ b/arm7tdmi/src/arm/exec.rs @@ -8,7 +8,6 @@ use crate::{ use MemoryAccess::*; -use super::ArmDecodeHelper; use super::*; impl Arm7tdmiCore { @@ -177,7 +176,7 @@ impl Arm7tdmiCore { let rs = insn.bit_range(8..12) as usize; ShiftRegisterBy::ByRegister(rs) } else { - let amount = insn.bit_range(7..12) as u32; + let amount = insn.bit_range(7..12); ShiftRegisterBy::ByAmount(amount) }; @@ -240,7 +239,7 @@ impl Arm7tdmiCore { let mut result = CpuAction::AdvancePC(Seq); if let Some(alu_res) = alu_res { - self.set_reg(rd, alu_res as u32); + self.set_reg(rd, alu_res); if rd == REG_PC { // T bit might have changed match self.cpsr.state() { @@ -290,7 +289,7 @@ impl Arm7tdmiCore { self.register_shift_const::(offset, rm as usize, &mut carry); } let offset = if ADD { - offset as u32 + offset } else { (-(offset as i32)) as u32 }; @@ -411,7 +410,7 @@ impl Arm7tdmiCore { if LOAD { let data = match transfer_type { - ArmHalfwordTransferType::SignedByte => self.load_8(addr, NonSeq) as u8 as i8 as u32, + ArmHalfwordTransferType::SignedByte => self.load_8(addr, NonSeq) as u32, ArmHalfwordTransferType::SignedHalfwords => self.ldr_sign_half(addr, NonSeq), ArmHalfwordTransferType::UnsignedHalfwords => self.ldr_half(addr, NonSeq), }; @@ -599,7 +598,7 @@ impl Arm7tdmiCore { } if writeback { - self.set_reg(base_reg, addr as u32); + self.set_reg(base_reg, addr); } result @@ -705,7 +704,7 @@ impl Arm7tdmiCore { } else { let t = self.ldr_word(base_addr, NonSeq); self.store_aligned_32(base_addr, self.get_reg(insn.rm()), Seq); - self.set_reg(rd, t as u32); + self.set_reg(rd, t); } self.idle_cycle(); diff --git a/arm7tdmi/src/cpu.rs b/arm7tdmi/src/cpu.rs index 913424b..297162c 100644 --- a/arm7tdmi/src/cpu.rs +++ b/arm7tdmi/src/cpu.rs @@ -4,7 +4,7 @@ use log::debug; use serde::{Deserialize, Serialize}; use bit::BitIndex; use num::FromPrimitive; -use ansi_term::{Colour, Style}; +use ansi_term::{Style}; use rustboyadvance_utils::{Shared, WeakPointer}; diff --git a/arm7tdmi/src/disass.rs b/arm7tdmi/src/disass.rs index c178e78..c7e85fe 100644 --- a/arm7tdmi/src/disass.rs +++ b/arm7tdmi/src/disass.rs @@ -42,7 +42,7 @@ where let mut line = String::new(); let addr = self.base + self.pos as Addr; - let decoded: D = D::decode_from_bytes(&self.bytes[(self.pos as usize)..], addr); + let decoded: D = D::decode_from_bytes(&self.bytes[(self.pos)..], addr); let decoded_raw = decoded.get_raw(); self.pos += self.word_size; write!(&mut line, "{addr:8x}:\t{decoded_raw:08x} \t{decoded}").unwrap(); diff --git a/arm7tdmi/src/thumb/exec.rs b/arm7tdmi/src/thumb/exec.rs index 93cb02d..8e988b0 100644 --- a/arm7tdmi/src/thumb/exec.rs +++ b/arm7tdmi/src/thumb/exec.rs @@ -5,9 +5,6 @@ use crate::{ Arm7tdmiCore, CpuAction, }; -use bit::BitIndex; - -use super::ThumbDecodeHelper; use super::*; use MemoryAccess::*; @@ -59,7 +56,7 @@ impl Arm7tdmiCore { self.alu_add_flags(op1, op2, &mut carry, &mut overflow) }; self.alu_update_flags(result, true, carry, overflow); - self.set_reg(rd, result as u32); + self.set_reg(rd, result); CpuAction::AdvancePC(Seq) } @@ -84,7 +81,7 @@ impl Arm7tdmiCore { let arithmetic = op == ADD || op == SUB; self.alu_update_flags(result, arithmetic, carry, overflow); if op != CMP { - self.gpr[RD] = result as u32; + self.gpr[RD] = result; } CpuAction::AdvancePC(Seq) @@ -144,7 +141,7 @@ impl Arm7tdmiCore { self.alu_update_flags(result, op.is_arithmetic(), carry, overflow); if !op.is_setting_flags() { - self.set_reg(rd, result as u32); + self.set_reg(rd, result); } CpuAction::AdvancePC(Seq) @@ -189,7 +186,7 @@ impl Arm7tdmiCore { self.alu_update_flags(result, true, carry, overflow); } OpFormat5::MOV => { - self.set_reg(dst_reg, op2 as u32); + self.set_reg(dst_reg, op2); if dst_reg == REG_PC { self.reload_pipeline16(); result = CpuAction::PipelineFlushed; @@ -333,7 +330,7 @@ impl Arm7tdmiCore { if LOAD { let data = self.ldr_half(addr, NonSeq); self.idle_cycle(); - self.gpr[rd] = data as u32; + self.gpr[rd] = data; CpuAction::AdvancePC(Seq) } else { self.store_aligned_16(addr, self.gpr[rd] as u16, NonSeq); @@ -541,7 +538,7 @@ impl Arm7tdmiCore { /// Format 18 /// Execution Time: 2S+1N pub(in super::super) fn exec_thumb_branch(&mut self, insn: u16) -> CpuAction { - let offset = ((insn.offset11() << 21) >> 20) as i32; + let offset = (insn.offset11() << 21) >> 20; self.pc = (self.pc as i32).wrapping_add(offset) as u32; self.reload_pipeline16(); // 2S + 1N CpuAction::PipelineFlushed diff --git a/core/src/bios.rs b/core/src/bios.rs index a3427ef..e8344ad 100644 --- a/core/src/bios.rs +++ b/core/src/bios.rs @@ -57,7 +57,7 @@ impl BusIO for Bios { #[inline] fn read_16(&mut self, addr: Addr) -> u16 { if self.read_allowed() { - self.rom.read_16(addr) as u16 + self.rom.read_16(addr) } else { (self.last_opcode >> ((addr & 2) << 3)) as u16 } diff --git a/core/src/cartridge/backup/backup_file.rs b/core/src/cartridge/backup/backup_file.rs index d8a8165..a92f258 100644 --- a/core/src/cartridge/backup/backup_file.rs +++ b/core/src/cartridge/backup/backup_file.rs @@ -81,7 +81,7 @@ impl BackupFile { let mut _file = OpenOptions::new() .read(true) .write(true) - .open(&path) + .open(path) .unwrap(); let mut buffer = Vec::new(); diff --git a/core/src/cartridge/backup/eeprom.rs b/core/src/cartridge/backup/eeprom.rs index 826282f..9edf19e 100644 --- a/core/src/cartridge/backup/eeprom.rs +++ b/core/src/cartridge/backup/eeprom.rs @@ -1,6 +1,5 @@ use super::{BackupFile, BackupMemoryInterface}; -use bytesize; use num::FromPrimitive; use serde::{Deserialize, Serialize}; @@ -66,12 +65,6 @@ enum SpiState { RxData, } -impl Default for SpiState { - fn default() -> SpiState { - SpiState::RxInstruction - } -} - #[derive(Serialize, Deserialize, Clone, Debug)] pub struct EepromChip { memory: BackupFile, @@ -255,10 +248,7 @@ impl EepromChip { pub(crate) fn is_transmitting(&self) -> bool { use SpiState::*; - match self.state { - TxData | TxDummy => true, - _ => false, - } + matches!(self.state, TxData | TxDummy) } pub(crate) fn reset(&mut self) { @@ -288,7 +278,7 @@ impl EepromController { let mut detect = true; let mut eeprom_type = EepromType::Eeprom512; if let Some(path) = &path { - if let Ok(metadata) = fs::metadata(&path) { + if let Ok(metadata) = fs::metadata(path) { let human_size = bytesize::ByteSize::b(metadata.len()); let assumed_type = match metadata.len() { 512 => EepromType::Eeprom512, diff --git a/core/src/cartridge/backup/flash.rs b/core/src/cartridge/backup/flash.rs index 93a7d92..363e812 100644 --- a/core/src/cartridge/backup/flash.rs +++ b/core/src/cartridge/backup/flash.rs @@ -39,9 +39,9 @@ pub enum FlashSize { Flash128k, } -impl Into for FlashSize { - fn into(self) -> usize { - match self { +impl From for usize { + fn from(val: FlashSize) -> Self { + match val { FlashSize::Flash64k => 64 * 1024, FlashSize::Flash128k => 128 * 1024, } @@ -143,7 +143,7 @@ impl Flash { /// Returns the phyiscal offset inside the flash file according to the selected bank #[inline] fn flash_offset(&self, offset: usize) -> usize { - let offset = (offset & 0xffff) as usize; + let offset = offset & 0xffff; self.bank * BANK_SIZE + offset } diff --git a/core/src/cartridge/builder.rs b/core/src/cartridge/builder.rs index 80790ca..a4075cd 100644 --- a/core/src/cartridge/builder.rs +++ b/core/src/cartridge/builder.rs @@ -34,6 +34,12 @@ pub struct GamepakBuilder { create_backup_file: bool, } +impl Default for GamepakBuilder { + fn default() -> Self { + Self::new() + } +} + impl GamepakBuilder { pub fn new() -> GamepakBuilder { GamepakBuilder { @@ -199,11 +205,7 @@ impl GamepakBuilder { const BACKUP_FILE_EXT: &str = "sav"; fn create_backup(backup_type: BackupType, rom_path: Option) -> BackupMedia { - let backup_path = if let Some(rom_path) = rom_path { - Some(rom_path.with_extension(BACKUP_FILE_EXT)) - } else { - None - }; + let backup_path = rom_path.map(|rom_path| rom_path.with_extension(BACKUP_FILE_EXT)); match backup_type { BackupType::Flash | BackupType::Flash512 => { BackupMedia::Flash(Flash::new(backup_path, FlashSize::Flash64k)) @@ -220,10 +222,7 @@ fn detect_backup_type(bytes: &[u8]) -> Option { for i in 0..5 { let search = TwoWaySearcher::new(ID_STRINGS[i].as_bytes()); - match search.search_in(bytes) { - Some(_) => return Some(BackupType::from_u8(i as u8).unwrap()), - _ => {} - } + if let Some(_) = search.search_in(bytes) { return Some(BackupType::from_u8(i as u8).unwrap()) } } None } diff --git a/core/src/cartridge/mod.rs b/core/src/cartridge/mod.rs index 1b543ed..154cbc6 100644 --- a/core/src/cartridge/mod.rs +++ b/core/src/cartridge/mod.rs @@ -103,10 +103,7 @@ use super::sysbus::consts::*; pub const EEPROM_BASE_ADDR: u32 = 0x0DFF_FF00; fn is_gpio_access(addr: u32) -> bool { - match addr & 0x1ff_ffff { - GPIO_PORT_DATA | GPIO_PORT_DIRECTION | GPIO_PORT_CONTROL => true, - _ => false, - } + matches!(addr & 0x1ff_ffff, GPIO_PORT_DATA | GPIO_PORT_DIRECTION | GPIO_PORT_CONTROL) } impl BusIO for Cartridge { @@ -122,7 +119,7 @@ impl BusIO for Cartridge { if offset >= self.size { self.read_unused(addr) } else { - unsafe { *self.bytes.get_unchecked(offset as usize) } + unsafe { *self.bytes.get_unchecked(offset) } } } } diff --git a/core/src/cartridge/rtc.rs b/core/src/cartridge/rtc.rs index 8311fac..591359e 100644 --- a/core/src/cartridge/rtc.rs +++ b/core/src/cartridge/rtc.rs @@ -223,10 +223,7 @@ impl Rtc { fn serial_transfer_in_progress(&self) -> bool { use RtcState::*; - match self.state { - Idle | WaitForChipSelectHigh => false, - _ => true, - } + !matches!(self.state, Idle | WaitForChipSelectHigh) } /// Loads a register contents into an internal buffer diff --git a/core/src/gba.rs b/core/src/gba.rs index 9d67b77..76731d7 100644 --- a/core/src/gba.rs +++ b/core/src/gba.rs @@ -2,7 +2,6 @@ use std::cell::Cell; use std::rc::Rc; -use bincode; use serde::{Deserialize, Serialize}; use crate::gdb_support::{gdb_thread::start_gdb_server_thread, DebuggerRequestHandler}; @@ -19,7 +18,7 @@ use super::timer::Timers; use super::sound::interface::DynAudioInterface; -use arm7tdmi::{self, Arm7tdmiCore}; +use arm7tdmi::{Arm7tdmiCore}; use rustboyadvance_utils::Shared; pub struct GameBoyAdvance { diff --git a/core/src/gdb_support.rs b/core/src/gdb_support.rs index 7f117bb..d511c1b 100644 --- a/core/src/gdb_support.rs +++ b/core/src/gdb_support.rs @@ -111,7 +111,7 @@ impl DebuggerRequestHandler { data.len(), addr ); - gba.cpu.write_addrs(*addr, &data)?; + gba.cpu.write_addrs(*addr, data)?; self.complete_request(None) } Interrupt => { diff --git a/core/src/gpu/layer.rs b/core/src/gpu/layer.rs index c3d8d6c..09b4c54 100644 --- a/core/src/gpu/layer.rs +++ b/core/src/gpu/layer.rs @@ -1,5 +1,3 @@ -use num::FromPrimitive; - use super::*; #[derive(Primitive, Debug, Ord, Eq, PartialOrd, PartialEq, Clone, Copy)] diff --git a/core/src/gpu/mod.rs b/core/src/gpu/mod.rs index 078704d..58153d4 100644 --- a/core/src/gpu/mod.rs +++ b/core/src/gpu/mod.rs @@ -367,8 +367,8 @@ impl Gpu { self.render_scanline(); // update BG2/3 reference points on the end of a scanline for i in 0..2 { - self.bg_aff[i].internal_x += self.bg_aff[i].pb as i16 as i32; - self.bg_aff[i].internal_y += self.bg_aff[i].pd as i16 as i32; + self.bg_aff[i].internal_x += self.bg_aff[i].pb as i32; + self.bg_aff[i].internal_y += self.bg_aff[i].pd as i32; } (GpuEvent::HDraw, CYCLES_HDRAW) diff --git a/core/src/gpu/mosaic.rs b/core/src/gpu/mosaic.rs index d5b1d92..96ed532 100644 --- a/core/src/gpu/mosaic.rs +++ b/core/src/gpu/mosaic.rs @@ -1,5 +1,4 @@ use super::*; -use regs::RegMosaic; impl RegMosaic { fn is_enabled_for_bg(&self) -> bool { diff --git a/core/src/gpu/render/obj.rs b/core/src/gpu/render/obj.rs index dc09846..4a12f2c 100644 --- a/core/src/gpu/render/obj.rs +++ b/core/src/gpu/render/obj.rs @@ -278,7 +278,7 @@ impl Gpu { } fn write_obj_pixel(&mut self, x: usize, y: usize, pixel_color: Rgb15, attrs: &ObjAttrs) { - let mut current_obj = self.obj_buffer_get_mut(x, y); + let current_obj = self.obj_buffer_get_mut(x, y); let obj_mode = attrs.0.objmode(); match obj_mode { ObjMode::Normal | ObjMode::Sfx => { @@ -315,7 +315,7 @@ pub enum ObjMode { impl From for ObjMode { fn from(v: u16) -> ObjMode { - ObjMode::from_u16(v as u16).unwrap() + ObjMode::from_u16(v).unwrap() } } @@ -329,7 +329,7 @@ enum ObjType { impl From for ObjType { fn from(v: u16) -> ObjType { - ObjType::from_u16(v as u16).unwrap() + ObjType::from_u16(v).unwrap() } } diff --git a/core/src/gpu/render/text.rs b/core/src/gpu/render/text.rs index a9851f6..a45407c 100644 --- a/core/src/gpu/render/text.rs +++ b/core/src/gpu/render/text.rs @@ -37,14 +37,14 @@ impl Gpu { (256, 512) => bg_y / 256, (512, 512) => index2d!(u32, bg_x / 256, bg_y / 256, 2), _ => unreachable!(), - } as u32; + }; let mut se_row = (bg_x / 8) % 32; let se_column = (bg_y / 8) % 32; // this will be non-zero if the h-scroll lands in a middle of a tile let mut start_tile_x = bg_x % 8; - let tile_py = (bg_y % 8) as u32; + let tile_py = bg_y % 8; #[allow(unused)] macro_rules! render_loop { @@ -98,8 +98,8 @@ impl Gpu { let viewport = ViewPort::new(texture_size, texture_size); let ref_point = self.get_ref_point(bg); - let pa = self.bg_aff[bg - 2].pa as i16 as i32; - let pc = self.bg_aff[bg - 2].pc as i16 as i32; + let pa = self.bg_aff[bg - 2].pa as i32; + let pc = self.bg_aff[bg - 2].pc as i32; let screen_block = self.bgcnt[bg].screen_block(); let char_block = self.bgcnt[bg].char_block(); diff --git a/core/src/iodev.rs b/core/src/iodev.rs index 56e5e21..7395df1 100644 --- a/core/src/iodev.rs +++ b/core/src/iodev.rs @@ -3,8 +3,6 @@ use std::cmp; use arm7tdmi::memory::{Addr, BusIO, DebugRead}; use super::dma::DmaController; -use super::gpu::regs::GpuMemoryMappedIO; -use super::gpu::regs::WindowFlags; use super::gpu::*; use super::interrupt::{InterruptConnect, InterruptController, SharedInterruptFlags}; use super::keypad; @@ -109,22 +107,22 @@ impl BusIO for IoDevices { REG_BG1CNT => io.gpu.bgcnt[1].read(), REG_BG2CNT => io.gpu.bgcnt[2].read(), REG_BG3CNT => io.gpu.bgcnt[3].read(), - REG_WIN0H => ((io.gpu.win0.left as u16) << 8 | (io.gpu.win0.right as u16)), - REG_WIN1H => ((io.gpu.win1.left as u16) << 8 | (io.gpu.win1.right as u16)), - REG_WIN0V => ((io.gpu.win0.top as u16) << 8 | (io.gpu.win0.bottom as u16)), - REG_WIN1V => ((io.gpu.win1.top as u16) << 8 | (io.gpu.win1.bottom as u16)), + REG_WIN0H => (io.gpu.win0.left as u16) << 8 | (io.gpu.win0.right as u16), + REG_WIN1H => (io.gpu.win1.left as u16) << 8 | (io.gpu.win1.right as u16), + REG_WIN0V => (io.gpu.win0.top as u16) << 8 | (io.gpu.win0.bottom as u16), + REG_WIN1V => (io.gpu.win1.top as u16) << 8 | (io.gpu.win1.bottom as u16), REG_WININ => { - ((io.gpu.win1.flags.bits() as u16) << 8) | (io.gpu.win0.flags.bits() as u16) + (io.gpu.win1.flags.bits() << 8) | io.gpu.win0.flags.bits() } REG_WINOUT => { - ((io.gpu.winobj_flags.bits() as u16) << 8) | (io.gpu.winout_flags.bits() as u16) + (io.gpu.winobj_flags.bits() << 8) | io.gpu.winout_flags.bits() } REG_BLDCNT => io.gpu.bldcnt.read(), REG_BLDALPHA => io.gpu.bldalpha.read(), REG_IME => io.intc.interrupt_master_enable as u16, - REG_IE => io.intc.interrupt_enable.0 as u16, - REG_IF => io.intc.interrupt_flags.get().value() as u16, + REG_IE => io.intc.interrupt_enable.0, + REG_IF => io.intc.interrupt_flags.get().value(), REG_TM0CNT_L..=REG_TM3CNT_H => io.timers.handle_read(io_addr, &io.scheduler), @@ -170,7 +168,7 @@ impl BusIO for IoDevices { } fn write_16(&mut self, addr: Addr, value: u16) { - let mut io = self; + let io = self; // if addr > 0x0800 { // return; // } @@ -310,11 +308,11 @@ impl BusIO for IoDevices { fn write_8(&mut self, addr: Addr, value: u8) { match addr + IO_BASE { /* FIFO_A */ - 0x0400_00A0 | 0x0400_00A1 | 0x0400_00A2 | 0x0400_00A3 => { + 0x0400_00A0..=0x0400_00A3 => { self.sound.write_fifo(0, value as i8) } /* FIFO_B */ - 0x0400_00A4 | 0x0400_00A5 | 0x0400_00A6 | 0x0400_00A7 => { + 0x0400_00A4..=0x0400_00A7 => { self.sound.write_fifo(1, value as i8) } _ => { @@ -588,5 +586,5 @@ pub fn io_reg_string(addr: u32) -> &'static str { fn sign_extend_i32(value: i32, size: u32) -> i32 { let shift = 32 - size; - ((value << shift) as i32) >> shift + (value << shift) >> shift } diff --git a/core/src/keypad.rs b/core/src/keypad.rs index c80fb91..437119f 100644 --- a/core/src/keypad.rs +++ b/core/src/keypad.rs @@ -23,9 +23,9 @@ pub enum KeyState { Released = 1, } -impl Into for KeyState { - fn into(self) -> bool { - match self { +impl From for bool { + fn from(val: KeyState) -> Self { + match val { KeyState::Pressed => false, KeyState::Released => true, } diff --git a/core/src/mgba_debug.rs b/core/src/mgba_debug.rs index a5a8972..f10b444 100644 --- a/core/src/mgba_debug.rs +++ b/core/src/mgba_debug.rs @@ -16,6 +16,12 @@ pub struct DebugPort { debug_string: Box<[u8]>, } +impl Default for DebugPort { + fn default() -> Self { + Self::new() + } +} + impl DebugPort { pub fn new() -> DebugPort { DebugPort { diff --git a/core/src/sched.rs b/core/src/sched.rs index 0f734fa..8566314 100644 --- a/core/src/sched.rs +++ b/core/src/sched.rs @@ -67,7 +67,7 @@ impl Ord for Event { impl PartialOrd for Event { #[inline] fn partial_cmp(&self, other: &Self) -> Option { - other.time.partial_cmp(&self.time) + Some(self.cmp(other)) } #[inline] @@ -108,6 +108,12 @@ pub struct Scheduler { pub type SharedScheduler = Shared; +impl Default for Scheduler { + fn default() -> Self { + Self::new() + } +} + impl Scheduler { pub fn new() -> Scheduler { Scheduler { diff --git a/core/src/sound/interface.rs b/core/src/sound/interface.rs index ad6bb0f..b386e77 100644 --- a/core/src/sound/interface.rs +++ b/core/src/sound/interface.rs @@ -58,6 +58,6 @@ impl AudioInterface for NullAudio {} impl NullAudio { pub fn new() -> Box { - Box::new(NullAudio::default()) + Box::::default() } } diff --git a/core/src/sysbus.rs b/core/src/sysbus.rs index 34a3540..987242c 100644 --- a/core/src/sysbus.rs +++ b/core/src/sysbus.rs @@ -8,7 +8,7 @@ use super::cartridge::Cartridge; use super::dma::DmaNotifer; use super::iodev::{IoDevices, WaitControl}; use super::sched::*; -use arm7tdmi::{self, Arm7tdmiCore}; +use arm7tdmi::{Arm7tdmiCore}; use rustboyadvance_utils::{Shared, WeakPointer}; pub mod consts { diff --git a/platform/rustboyadvance-sdl2/src/main.rs b/platform/rustboyadvance-sdl2/src/main.rs index 69ad196..806dbd2 100644 --- a/platform/rustboyadvance-sdl2/src/main.rs +++ b/platform/rustboyadvance-sdl2/src/main.rs @@ -1,7 +1,6 @@ use sdl2::controller::Button; use sdl2::event::Event; use sdl2::keyboard::Scancode; -use sdl2::{self}; use structopt::StructOpt;