refactor: with clippy

Former-commit-id: c57ef7336468ec1b2386a1c3faa753468b45eeb3
Former-commit-id: a98ec18b83a192c371cedbf3cd0efbb1586c4552
This commit is contained in:
Muhammad Nauman Raza 2024-03-22 20:35:05 +00:00
parent 4179b0ec28
commit cacf71b61c
28 changed files with 86 additions and 102 deletions

View file

@ -9,7 +9,7 @@ members = [
"platform/rustboyadvance-jni",
"fps_bench"
]
resolver = "1"
default-members = ["platform/rustboyadvance-sdl2"]
[profile.dev]

View file

@ -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");

View file

@ -77,7 +77,7 @@ impl BarrelShifterValue {
/// Decode operand2 as an immediate value
pub fn decode_rotated_immediate(&self) -> Option<u32> {
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<I: MemoryInterface> Arm7tdmiCore<I> {
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<I: MemoryInterface> Arm7tdmiCore<I> {
} else {
val
};
*carry = (val as u32).bit(31);
*carry = (val).bit(31);
val
}
}
@ -265,7 +265,7 @@ impl<I: MemoryInterface> Arm7tdmiCore<I> {
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<I: MemoryInterface> Arm7tdmiCore<I> {
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
}

View file

@ -8,7 +8,6 @@ use crate::{
use MemoryAccess::*;
use super::ArmDecodeHelper;
use super::*;
impl<I: MemoryInterface> Arm7tdmiCore<I> {
@ -177,7 +176,7 @@ impl<I: MemoryInterface> Arm7tdmiCore<I> {
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<I: MemoryInterface> Arm7tdmiCore<I> {
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<I: MemoryInterface> Arm7tdmiCore<I> {
self.register_shift_const::<BS_OP, SHIFT_BY_REG>(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<I: MemoryInterface> Arm7tdmiCore<I> {
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<I: MemoryInterface> Arm7tdmiCore<I> {
}
if writeback {
self.set_reg(base_reg, addr as u32);
self.set_reg(base_reg, addr);
}
result
@ -705,7 +704,7 @@ impl<I: MemoryInterface> Arm7tdmiCore<I> {
} 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();

View file

@ -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};

View file

@ -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();

View file

@ -5,9 +5,6 @@ use crate::{
Arm7tdmiCore, CpuAction,
};
use bit::BitIndex;
use super::ThumbDecodeHelper;
use super::*;
use MemoryAccess::*;
@ -59,7 +56,7 @@ impl<I: MemoryInterface> Arm7tdmiCore<I> {
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<I: MemoryInterface> Arm7tdmiCore<I> {
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<I: MemoryInterface> Arm7tdmiCore<I> {
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<I: MemoryInterface> Arm7tdmiCore<I> {
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<I: MemoryInterface> Arm7tdmiCore<I> {
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<I: MemoryInterface> Arm7tdmiCore<I> {
/// 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

View file

@ -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
}

View file

@ -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();

View file

@ -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,

View file

@ -39,9 +39,9 @@ pub enum FlashSize {
Flash128k,
}
impl Into<usize> for FlashSize {
fn into(self) -> usize {
match self {
impl From<FlashSize> 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
}

View file

@ -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<PathBuf>) -> 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<BackupType> {
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
}

View file

@ -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) }
}
}
}

View file

@ -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

View file

@ -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 {

View file

@ -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 => {

View file

@ -1,5 +1,3 @@
use num::FromPrimitive;
use super::*;
#[derive(Primitive, Debug, Ord, Eq, PartialOrd, PartialEq, Clone, Copy)]

View file

@ -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)

View file

@ -1,5 +1,4 @@
use super::*;
use regs::RegMosaic;
impl RegMosaic {
fn is_enabled_for_bg(&self) -> bool {

View file

@ -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<u16> 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<u16> for ObjType {
fn from(v: u16) -> ObjType {
ObjType::from_u16(v as u16).unwrap()
ObjType::from_u16(v).unwrap()
}
}

View file

@ -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();

View file

@ -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
}

View file

@ -23,9 +23,9 @@ pub enum KeyState {
Released = 1,
}
impl Into<bool> for KeyState {
fn into(self) -> bool {
match self {
impl From<KeyState> for bool {
fn from(val: KeyState) -> Self {
match val {
KeyState::Pressed => false,
KeyState::Released => true,
}

View file

@ -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 {

View file

@ -67,7 +67,7 @@ impl Ord for Event {
impl PartialOrd for Event {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
other.time.partial_cmp(&self.time)
Some(self.cmp(other))
}
#[inline]
@ -108,6 +108,12 @@ pub struct Scheduler {
pub type SharedScheduler = Shared<Scheduler>;
impl Default for Scheduler {
fn default() -> Self {
Self::new()
}
}
impl Scheduler {
pub fn new() -> Scheduler {
Scheduler {

View file

@ -58,6 +58,6 @@ impl AudioInterface for NullAudio {}
impl NullAudio {
pub fn new() -> Box<NullAudio> {
Box::new(NullAudio::default())
Box::<NullAudio>::default()
}
}

View file

@ -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 {

View file

@ -1,7 +1,6 @@
use sdl2::controller::Button;
use sdl2::event::Event;
use sdl2::keyboard::Scancode;
use sdl2::{self};
use structopt::StructOpt;