diff --git a/core/src/cartridge/backup/backup_file.rs b/core/src/cartridge/backup/backup_file.rs index adfb320..d8a8165 100644 --- a/core/src/cartridge/backup/backup_file.rs +++ b/core/src/cartridge/backup/backup_file.rs @@ -64,7 +64,7 @@ impl<'de> Deserialize<'de> for BackupFile { } } - const FIELDS: &'static [&'static str] = &["size", "path"]; + const FIELDS: &[&str] = &["size", "path"]; deserializer.deserialize_struct("BackupFile", FIELDS, BackupFileVisitor) } } @@ -75,7 +75,7 @@ impl BackupFile { let mut file: Option = None; let buffer = if let Some(path) = &path { if !path.is_file() { - write_bin_file(&path, &vec![0xff; size]).unwrap(); + write_bin_file(path, &vec![0xff; size]).unwrap(); } let mut _file = OpenOptions::new() @@ -98,8 +98,8 @@ impl BackupFile { BackupFile { size, path, - file: file, - buffer: buffer, + file, + buffer, } } diff --git a/core/src/cartridge/backup/eeprom.rs b/core/src/cartridge/backup/eeprom.rs index f590c5a..b7de9c3 100644 --- a/core/src/cartridge/backup/eeprom.rs +++ b/core/src/cartridge/backup/eeprom.rs @@ -95,7 +95,7 @@ impl EepromChip { fn new(eeprom_type: EepromType, mut memory: BackupFile) -> EepromChip { memory.resize(eeprom_type.size()); EepromChip { - memory: memory, + memory, addr_bits: eeprom_type.bits(), state: SpiState::RxInstruction, @@ -130,7 +130,7 @@ impl EepromChip { fn fill_tx_buffer(&mut self) { let mut tx_buffer = 0u64; for i in 0..8 { - tx_buffer = tx_buffer << 8; + tx_buffer <<= 8; tx_buffer |= self.memory.read(self.address + i) as u64; } self.tx_buffer = tx_buffer; @@ -152,10 +152,8 @@ impl EepromChip { RxInstruction => { // If instruction was recvd, proceed to recv the address if self.rx_count >= 2 { - let insn = SpiInstruction::from_u64(self.rx_buffer).expect(&format!( - "invalid spi command {:#010b}", - self.rx_buffer as u8 - )); + let insn = SpiInstruction::from_u64(self.rx_buffer).unwrap_or_else(|| panic!("invalid spi command {:#010b}", + self.rx_buffer as u8)); next_state = Some(RxAddress(insn)); self.reset_rx_buffer(); } @@ -193,7 +191,7 @@ impl EepromChip { for i in 0..8 { self.memory .write(self.address + (7 - i), (data & 0xff) as u8); - data = data >> 8; + data >>= 8; } next_state = Some(StopBit(Write)); self.reset_rx_buffer(); @@ -445,7 +443,7 @@ mod tests { let mut byte = value[i]; for j in 0..8 { let bit = byte >> 7; - byte = byte << 1; + byte <<= 1; bit_stream[8 + i * 8 + j] = bit as u16; } } @@ -464,11 +462,11 @@ mod tests { { let mut chip = spi.chip.borrow_mut(); let bytes = chip.memory.bytes_mut(); - bytes[16] = 'T' as u8; - bytes[17] = 'E' as u8; - bytes[18] = 'S' as u8; - bytes[19] = 'T' as u8; - bytes[20] = '!' as u8; + bytes[16] = b'T'; + bytes[17] = b'E'; + bytes[18] = b'S'; + bytes[19] = b'T'; + bytes[20] = b'!'; drop(bytes); chip.memory.flush(); } diff --git a/core/src/cartridge/backup/flash.rs b/core/src/cartridge/backup/flash.rs index 6ea655e..d3731d2 100644 --- a/core/src/cartridge/backup/flash.rs +++ b/core/src/cartridge/backup/flash.rs @@ -76,12 +76,12 @@ impl Flash { let memory = BackupFile::new(size, flash_path); Flash { - chip_id: chip_id, + chip_id, wrseq: FlashWriteSequence::Initial, mode: FlashMode::Initial, - size: size, + size, bank: 0, - memory: memory, + memory, } } @@ -144,12 +144,14 @@ impl Flash { #[inline] fn flash_offset(&self, offset: usize) -> usize { let offset = (offset & 0xffff) as usize; - return self.bank * BANK_SIZE + offset; + self.bank * BANK_SIZE + offset } pub fn read(&self, addr: u32) -> u8 { let offset = (addr & 0xffff) as usize; - let result = if self.mode == FlashMode::ChipId { + + + if self.mode == FlashMode::ChipId { match offset { 0 => (self.chip_id & 0xff) as u8, 1 => (self.chip_id >> 8) as u8, @@ -157,9 +159,7 @@ impl Flash { } } else { self.memory.read(self.flash_offset(offset)) - }; - - result + } } pub fn write(&mut self, addr: u32, value: u8) { diff --git a/core/src/cartridge/backup/mod.rs b/core/src/cartridge/backup/mod.rs index 9c6a423..cbab666 100644 --- a/core/src/cartridge/backup/mod.rs +++ b/core/src/cartridge/backup/mod.rs @@ -6,7 +6,7 @@ pub use backup_file::BackupFile; pub mod eeprom; pub mod flash; -#[derive(Debug, Primitive, Serialize, Deserialize, Copy, Clone, PartialEq)] +#[derive(Debug, Primitive, Serialize, Deserialize, Copy, Clone, PartialEq, Eq)] pub enum BackupType { Eeprom = 0, Sram = 1, diff --git a/core/src/cartridge/builder.rs b/core/src/cartridge/builder.rs index addaa24..684ce99 100644 --- a/core/src/cartridge/builder.rs +++ b/core/src/cartridge/builder.rs @@ -109,7 +109,7 @@ impl GamepakBuilder { LoadRom::Raw(data) => Ok((data, None)), } } else if let Some(path) = &self.path { - match load_from_file(&path)? { + match load_from_file(path)? { #[cfg(feature = "elf_support")] LoadRom::Elf { data, symbols } => Ok((data, Some(symbols))), LoadRom::Raw(data) => Ok((data, None)), @@ -187,17 +187,17 @@ impl GamepakBuilder { let size = bytes.len(); Ok(Cartridge { - header: header, - gpio: gpio, + header, + gpio, bytes: bytes.into_boxed_slice(), - size: size, - backup: backup, - symbols: symbols, + size, + backup, + symbols, }) } } -const BACKUP_FILE_EXT: &'static str = "sav"; +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)) @@ -216,7 +216,7 @@ fn create_backup(backup_type: BackupType, rom_path: Option) -> BackupMe } fn detect_backup_type(bytes: &[u8]) -> Option { - const ID_STRINGS: &'static [&'static str] = + const ID_STRINGS: &[&str] = &["EEPROM", "SRAM", "FLASH_", "FLASH512_", "FLASH1M_"]; for i in 0..5 { diff --git a/core/src/cartridge/gpio.rs b/core/src/cartridge/gpio.rs index fba4cc0..0449e8c 100644 --- a/core/src/cartridge/gpio.rs +++ b/core/src/cartridge/gpio.rs @@ -4,7 +4,7 @@ use super::{GPIO_PORT_CONTROL, GPIO_PORT_DATA, GPIO_PORT_DIRECTION}; use bit::BitIndex; use serde::{Deserialize, Serialize}; -#[derive(Serialize, Deserialize, Copy, Clone, Debug, PartialEq)] +#[derive(Serialize, Deserialize, Copy, Clone, Debug, PartialEq, Eq)] pub enum GpioDirection { /// GPIO to GBA In = 0, diff --git a/core/src/cartridge/header.rs b/core/src/cartridge/header.rs index 67c6bd7..d527d04 100644 --- a/core/src/cartridge/header.rs +++ b/core/src/cartridge/header.rs @@ -83,7 +83,7 @@ pub fn parse(bytes: &[u8]) -> GBAResult { game_code: String::from(game_code), maker_code: String::from(maker_code), software_version: bytes[0xbc], - checksum: checksum, + checksum, // ram_entry_point: ram_entry_point, // joybus_entry_point: joybus_entry_point, }) diff --git a/core/src/cartridge/rtc.rs b/core/src/cartridge/rtc.rs index 309e33b..8311fac 100644 --- a/core/src/cartridge/rtc.rs +++ b/core/src/cartridge/rtc.rs @@ -18,7 +18,7 @@ fn num2bcd(mut num: u8) -> u8 { while num > 0 { let x = num % 10; bcd += x * digit; - digit = digit << 4; + digit <<= 4; num /= 10; } bcd @@ -168,7 +168,7 @@ impl SerialBuffer { } else { (1 << self.counter) - 1 }; - Some(self.byte & u8::from(mask)) + Some(self.byte & mask) } } @@ -236,7 +236,7 @@ impl Rtc { RegisterKind::DateTime => { let local: DateTime = Local::now(); let year = local.year(); - assert!(year >= 2000 && year <= 2099); // Wonder if I will live to see this one fail + assert!((2000..=2099).contains(&year)); // Wonder if I will live to see this one fail let hour = if self.status.mode_24h() { local.hour() @@ -498,16 +498,16 @@ mod tests { use super::*; fn transmit(rtc: &mut Rtc, gpio_state: &GpioState, bit: u8) { - rtc.write(&gpio_state, 0b0100_u16 | (u16::from(bit) << 1)); - rtc.write(&gpio_state, 0b0101_u16); + rtc.write(gpio_state, 0b0100_u16 | (u16::from(bit) << 1)); + rtc.write(gpio_state, 0b0101_u16); } fn receive_bytes(rtc: &mut Rtc, gpio_state: &GpioState, bytes: &mut [u8]) { for byte in bytes.iter_mut() { for i in 0..8 { - rtc.write(&gpio_state, 0b0100_u16); - let data = rtc.read(&gpio_state); - rtc.write(&gpio_state, 0b0101_u16); + rtc.write(gpio_state, 0b0100_u16); + let data = rtc.read(gpio_state); + rtc.write(gpio_state, 0b0101_u16); byte.set_bit(i, data.bit(Port::Sio.index())); } } @@ -523,11 +523,11 @@ mod tests { assert_eq!(rtc.state, RtcState::Idle); // set CS low, - rtc.write(&gpio_state, 0b0001); + rtc.write(gpio_state, 0b0001); assert_eq!(rtc.state, RtcState::WaitForChipSelectHigh); // set CS high, SCK rising edge - rtc.write(&gpio_state, 0b0101); + rtc.write(gpio_state, 0b0101); assert_eq!(rtc.state, RtcState::GetCommandByte); } diff --git a/core/src/dma.rs b/core/src/dma.rs index e32f282..bf40e89 100644 --- a/core/src/dma.rs +++ b/core/src/dma.rs @@ -39,7 +39,7 @@ impl DmaChannel { panic!("invalid dma id {}", id); } DmaChannel { - id: id, + id, irq: Interrupt::from_usize(id + 8).unwrap(), running: false, src: 0, @@ -115,7 +115,7 @@ impl DmaChannel { self.running = false; } self.ctrl = ctrl; - return start_immediately; + start_immediately } fn transfer(&mut self, sb: &mut SysBus) { diff --git a/core/src/gba.rs b/core/src/gba.rs index f1fbdf3..bf06260 100644 --- a/core/src/gba.rs +++ b/core/src/gba.rs @@ -112,13 +112,13 @@ impl GameBoyAdvance { io_devs, #[cfg(not(feature = "no_video_interface"))] - video_device: video_device, - audio_device: audio_device, - input_device: input_device, + video_device, + audio_device, + input_device, - scheduler: scheduler, + scheduler, - interrupt_flags: interrupt_flags, + interrupt_flags, }; gba.sysbus.init(gba.cpu.weak_ptr()); @@ -160,15 +160,15 @@ impl GameBoyAdvance { Ok(GameBoyAdvance { cpu: arm7tdmi, - sysbus: sysbus, + sysbus, io_devs, interrupt_flags: interrupts, #[cfg(not(feature = "no_video_interface"))] - video_device: video_device, - audio_device: audio_device, - input_device: input_device, + video_device, + audio_device, + input_device, scheduler, }) diff --git a/core/src/gpu/layer.rs b/core/src/gpu/layer.rs index 9e5b7a4..c3d8d6c 100644 --- a/core/src/gpu/layer.rs +++ b/core/src/gpu/layer.rs @@ -25,7 +25,7 @@ impl RenderLayerKind { } } -#[derive(Debug, PartialEq, Clone, Copy)] +#[derive(Debug, PartialEq, Eq, Clone, Copy)] pub struct RenderLayer { pub kind: RenderLayerKind, pub priority: u16, @@ -36,23 +36,23 @@ impl RenderLayer { pub fn background(bg: usize, pixel: Rgb15, priority: u16) -> RenderLayer { RenderLayer { kind: RenderLayerKind::from_usize(1 << bg).unwrap(), - pixel: pixel, - priority: priority, + pixel, + priority, } } pub fn objects(pixel: Rgb15, priority: u16) -> RenderLayer { RenderLayer { kind: RenderLayerKind::Objects, - pixel: pixel, - priority: priority, + pixel, + priority, } } pub fn backdrop(pixel: Rgb15) -> RenderLayer { RenderLayer { kind: RenderLayerKind::Backdrop, - pixel: pixel, + pixel, priority: 4, } } diff --git a/core/src/gpu/mod.rs b/core/src/gpu/mod.rs index d65d46e..c315784 100644 --- a/core/src/gpu/mod.rs +++ b/core/src/gpu/mod.rs @@ -39,8 +39,8 @@ use std::fmt; pub mod consts { pub use super::VRAM_ADDR; pub const VIDEO_RAM_SIZE: usize = 128 * 1024; - pub const PALETTE_RAM_SIZE: usize = 1 * 1024; - pub const OAM_SIZE: usize = 1 * 1024; + pub const PALETTE_RAM_SIZE: usize = 1024; + pub const OAM_SIZE: usize = 1024; pub const DISPLAY_WIDTH: usize = 240; pub const DISPLAY_HEIGHT: usize = 160; diff --git a/core/src/gpu/regs.rs b/core/src/gpu/regs.rs index 25f4033..835ceae 100644 --- a/core/src/gpu/regs.rs +++ b/core/src/gpu/regs.rs @@ -10,7 +10,7 @@ pub trait GpuMemoryMappedIO { fn write(&mut self, value: u16); } -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Eq)] pub enum ObjMapping { TwoDimension, OneDimension, @@ -112,7 +112,7 @@ impl GpuMemoryMappedIO for DisplayStatus { } #[inline] fn read(&self) -> u16 { - u16::from(self.vblank_flag) << 0 + u16::from(self.vblank_flag) | u16::from(self.hblank_flag) << 1 | u16::from(self.vcount_flag) << 2 | u16::from(self.vblank_irq_enable) << 3 @@ -136,7 +136,7 @@ pub struct BgControl { impl GpuMemoryMappedIO for BgControl { #[inline] fn write(&mut self, value: u16) { - self.priority = (value >> 0) & 0b11; + self.priority = value & 0b11; self.character_base_block = (value >> 2) & 0b11; self.mosaic = (value >> 6) & 1 != 0; self.palette256 = (value >> 7) & 1 != 0; @@ -231,7 +231,7 @@ impl BlendFlags { } } -#[derive(SmartDefault, Debug, Serialize, Deserialize, Primitive, PartialEq, Clone, Copy)] +#[derive(SmartDefault, Debug, Serialize, Deserialize, Primitive, PartialEq, Eq, Clone, Copy)] pub enum BlendMode { #[default] BldNone = 0b00, @@ -250,14 +250,14 @@ pub struct BlendControl { impl GpuMemoryMappedIO for BlendControl { #[inline] fn write(&mut self, value: u16) { - self.target1 = BlendFlags::from_bits_truncate((value >> 0) & 0x3f); + self.target1 = BlendFlags::from_bits_truncate(value & 0x3f); self.target2 = BlendFlags::from_bits_truncate((value >> 8) & 0x3f); self.mode = BlendMode::from_u16((value >> 6) & 0b11).unwrap_or_else(|| unreachable!()); } #[inline] fn read(&self) -> u16 { - (self.target1.bits() << 0) | (self.mode as u16) << 6 | (self.target2.bits() << 8) + self.target1.bits() | (self.mode as u16) << 6 | (self.target2.bits() << 8) } } diff --git a/core/src/gpu/render.rs b/core/src/gpu/render.rs index eed2449..d5b3724 100644 --- a/core/src/gpu/render.rs +++ b/core/src/gpu/render.rs @@ -15,8 +15,8 @@ impl ViewPort { pub fn new(w: i32, h: i32) -> ViewPort { ViewPort { origin: (0, 0), - w: w, - h: h, + w, + h, } } diff --git a/core/src/gpu/render/obj.rs b/core/src/gpu/render/obj.rs index b76b6b7..dc09846 100644 --- a/core/src/gpu/render/obj.rs +++ b/core/src/gpu/render/obj.rs @@ -72,7 +72,7 @@ impl Gpu { fn read_obj_attrs(&mut self, obj: usize) -> ObjAttrs { let addr = ATTRS_SIZE * (obj as u32); - let attr0 = Attribute0(self.oam.read_16(addr + 0)); + let attr0 = Attribute0(self.oam.read_16(addr)); let attr1 = Attribute1(self.oam.read_16(addr + 2)); let attr2 = Attribute2(self.oam.read_16(addr + 4)); ObjAttrs(attr0, attr1, attr2) @@ -305,7 +305,7 @@ impl Gpu { } } -#[derive(Debug, Primitive, Copy, Clone, PartialEq)] +#[derive(Debug, Primitive, Copy, Clone, PartialEq, Eq)] pub enum ObjMode { Normal = 0b00, Sfx = 0b01, diff --git a/core/src/gpu/render/text.rs b/core/src/gpu/render/text.rs index b90a6b0..10b3df7 100644 --- a/core/src/gpu/render/text.rs +++ b/core/src/gpu/render/text.rs @@ -80,7 +80,7 @@ impl Gpu { } se_row = 0; if bg_width == 512 { - sbb = sbb ^ 1; + sbb ^= 1; } } }; diff --git a/core/src/gpu/rgb15.rs b/core/src/gpu/rgb15.rs index 107ab10..862cb83 100644 --- a/core/src/gpu/rgb15.rs +++ b/core/src/gpu/rgb15.rs @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize}; bitfield! { #[repr(transparent)] - #[derive(Serialize, Deserialize, Copy, Clone, Default, PartialEq)] + #[derive(Serialize, Deserialize, Copy, Clone, Default, PartialEq, Eq)] pub struct Rgb15(u16); impl Debug; pub r, set_r: 4, 0; diff --git a/core/src/gpu/window.rs b/core/src/gpu/window.rs index 9e8a497..3cd76ba 100644 --- a/core/src/gpu/window.rs +++ b/core/src/gpu/window.rs @@ -57,7 +57,7 @@ impl Window { } } -#[derive(Debug, PartialEq, Copy, Clone)] +#[derive(Debug, PartialEq, Eq, Copy, Clone)] pub enum WindowType { Win0, Win1, diff --git a/core/src/interrupt.rs b/core/src/interrupt.rs index 34226dd..35d1fb4 100644 --- a/core/src/interrupt.rs +++ b/core/src/interrupt.rs @@ -8,7 +8,7 @@ pub trait InterruptConnect { fn connect_irq(&mut self, interrupt_flags: SharedInterruptFlags); } -#[derive(Serialize, Deserialize, Debug, Primitive, Copy, Clone, PartialEq)] +#[derive(Serialize, Deserialize, Debug, Primitive, Copy, Clone, PartialEq, Eq)] #[allow(non_camel_case_types)] pub enum Interrupt { LCD_VBlank = 0, @@ -77,7 +77,7 @@ impl IrqBitmask { } bitfield! { - #[derive(Serialize, Deserialize, Default, Copy, Clone, PartialEq)] + #[derive(Serialize, Deserialize, Default, Copy, Clone, PartialEq, Eq)] pub struct IrqBitmask(u16); impl Debug; u16; diff --git a/core/src/iodev.rs b/core/src/iodev.rs index b482783..2714bd2 100644 --- a/core/src/iodev.rs +++ b/core/src/iodev.rs @@ -17,7 +17,7 @@ use serde::{Deserialize, Serialize}; use self::consts::*; -#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)] +#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)] pub enum HaltState { Running, Halt, // In Halt mode, the CPU is paused as long as (IE AND IF)=0, @@ -67,7 +67,7 @@ impl IoDevices { keyinput: keypad::KEYINPUT_ALL_RELEASED, waitcnt: WaitControl(0), debug: DebugPort::new(), - scheduler: scheduler, + scheduler, sysbus_ptr: Default::default(), } } @@ -82,13 +82,13 @@ impl InterruptConnect for IoDevices { self.intc.connect_irq(interrupt_flags.clone()); self.gpu.connect_irq(interrupt_flags.clone()); self.dmac.connect_irq(interrupt_flags.clone()); - self.timers.connect_irq(interrupt_flags.clone()); + self.timers.connect_irq(interrupt_flags); } } impl SchedulerConnect for IoDevices { fn connect_scheduler(&mut self, scheduler: SharedScheduler) { - self.scheduler = scheduler.clone(); + self.scheduler = scheduler; } } @@ -336,7 +336,7 @@ impl DebugRead for IoDevices { } bitfield! { - #[derive(Serialize, Deserialize, Default, Copy, Clone, PartialEq)] + #[derive(Serialize, Deserialize, Default, Copy, Clone, PartialEq, Eq)] pub struct WaitControl(u16); impl Debug; u16; diff --git a/core/src/keypad.rs b/core/src/keypad.rs index f8749a1..db3a1da 100644 --- a/core/src/keypad.rs +++ b/core/src/keypad.rs @@ -1,4 +1,4 @@ -#[derive(Debug, Primitive, PartialEq)] +#[derive(Debug, Primitive, PartialEq, Eq)] #[repr(u8)] pub enum Keys { ButtonA = 0, @@ -16,7 +16,7 @@ pub enum Keys { pub const NUM_KEYS: usize = 10; pub const KEYINPUT_ALL_RELEASED: u16 = 0b1111111111; -#[derive(Debug, Primitive, PartialEq)] +#[derive(Debug, Primitive, PartialEq, Eq)] #[repr(u8)] pub enum KeyState { Pressed = 0, diff --git a/core/src/lib.rs b/core/src/lib.rs index 5f687f8..670c21c 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -9,7 +9,7 @@ extern crate debug_stub_derive; #[macro_use] extern crate enum_primitive_derive; -use num_traits; + #[macro_use] extern crate bitfield; @@ -27,7 +27,7 @@ extern crate smart_default; extern crate cfg_if; -use zip; + use std::error::Error; use std::fmt; diff --git a/core/src/sound/dsp.rs b/core/src/sound/dsp.rs index 897cfb0..b0d7893 100644 --- a/core/src/sound/dsp.rs +++ b/core/src/sound/dsp.rs @@ -29,7 +29,7 @@ impl Resampler for CosineResampler { output.push((left, right)); self.phase += self.in_freq / self.out_freq; } - self.phase = self.phase - 1.0; + self.phase -= 1.0; self.last_in_sample = s; } } @@ -39,8 +39,8 @@ impl CosineResampler { CosineResampler { last_in_sample: Default::default(), phase: 0.0, - in_freq: in_freq, - out_freq: out_freq, + in_freq, + out_freq, } } } diff --git a/core/src/sound/mod.rs b/core/src/sound/mod.rs index feffbaa..86525e4 100644 --- a/core/src/sound/mod.rs +++ b/core/src/sound/mod.rs @@ -133,7 +133,7 @@ impl SoundController { sample_rate: 32_768f32, dma_sound: [Default::default(), Default::default()], - resampler: resampler, + resampler, output_buffer: Vec::with_capacity(1024), } } @@ -196,11 +196,9 @@ impl SoundController { info!("MSE enabled!"); self.mse = true; } - } else { - if self.mse { - info!("MSE disabled!"); - self.mse = false; - } + } else if self.mse { + info!("MSE disabled!"); + self.mse = false; } // other fields of this register are read-only anyway, ignore them. diff --git a/core/src/sysbus.rs b/core/src/sysbus.rs index b4227f9..9e4f050 100644 --- a/core/src/sysbus.rs +++ b/core/src/sysbus.rs @@ -227,10 +227,10 @@ impl SysBus { /// must be called whenever this object is instanciated pub fn init(&mut self, arm_core: WeakPointer>) { self.arm_core = arm_core.clone(); - self.bios.connect_arm_core(arm_core.clone()); + self.bios.connect_arm_core(arm_core); let ptr = SysBusPtr::new(self as *mut SysBus); // HACK - self.io.set_sysbus_ptr(ptr.clone()); + self.io.set_sysbus_ptr(ptr); } pub fn on_waitcnt_written(&mut self, waitcnt: WaitControl) { @@ -281,7 +281,7 @@ impl SysBus { match (r15 >> 24) as usize { PAGE_BIOS | PAGE_OAM => { // TODO this is probably wrong, according to GBATEK, we should be using $+6 here but it isn't prefetched yet. - value = value << 16; + value <<= 16; value |= decoded; } PAGE_IWRAM => { @@ -291,7 +291,7 @@ impl SysBus { value |= decoded << 16; } else { // LSW = OldLO, MSW = [$+4] ;for opcodes at non-4-byte aligned locations - value = value << 16; + value <<= 16; value |= decoded; } } diff --git a/core/src/timer.rs b/core/src/timer.rs index d474d57..101f578 100644 --- a/core/src/timer.rs +++ b/core/src/timer.rs @@ -31,7 +31,7 @@ impl Timer { panic!("invalid timer id {}", timer_id); } Timer { - timer_id: timer_id, + timer_id, irq: Interrupt::from_usize(timer_id + 3).unwrap(), interrupt_flags, data: 0, @@ -78,7 +78,7 @@ impl Timer { let ticks_remaining = self.ticks_to_overflow(); num_overflows += ticks / ticks_remaining; - ticks = ticks % ticks_remaining; + ticks %= ticks_remaining; if self.ctl.irq_enabled() { interrupt::signal_irq(&self.interrupt_flags, self.irq); @@ -160,11 +160,8 @@ impl Timers { if id != 3 { let next_timer_id = id + 1; let next_timer = &mut self.timers[next_timer_id]; - if next_timer.ctl.cascade() { - if next_timer.update(1) > 0 { - drop(next_timer); - self.handle_timer_overflow(next_timer_id, apu, dmac); - } + if next_timer.ctl.cascade() && next_timer.update(1) > 0 { + self.handle_timer_overflow(next_timer_id, apu, dmac); } } if id == 0 || id == 1 {