From 12d9edf5c4c8a55a7a64539fc445e6f4d1d15aa7 Mon Sep 17 00:00:00 2001 From: Michel Heily Date: Mon, 5 Sep 2022 00:31:38 +0300 Subject: [PATCH] Fix some cargo-clippy, and broken sub-crates Former-commit-id: 93db7bc11bff9a48f4d66e0a378cd77ab42ca197 Former-commit-id: a6ce714c2a6a4112ff30d748c0686b1b2da41c6b --- Cargo.lock | 3 +++ arm7tdmi/build.rs | 2 +- arm7tdmi/src/arm/exec.rs | 4 +--- core/src/cartridge/rtc.rs | 4 +--- core/src/gpu/mod.rs | 10 +++++----- core/src/sched.rs | 11 +++++++---- platform/rustboyadvance-jni/Cargo.toml | 1 + platform/rustboyadvance-jni/src/audio/thread.rs | 2 +- platform/rustboyadvance-jni/src/emulator.rs | 2 +- platform/rustboyadvance-jni/src/lib.rs | 2 +- platform/rustboyadvance-libretro/Cargo.toml | 1 + platform/rustboyadvance-libretro/src/lib.rs | 4 ++-- platform/rustboyadvance-sdl2/src/main.rs | 5 +++++ platform/rustboyadvance-wasm/Cargo.toml | 1 + platform/rustboyadvance-wasm/src/emulator.rs | 8 ++++---- utils/src/lib.rs | 12 +++++------- 16 files changed, 40 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ef0a2d9..d6c1786 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1413,6 +1413,7 @@ dependencies = [ "jni", "log 0.4.11", "rustboyadvance-core", + "rustboyadvance-utils", ] [[package]] @@ -1425,6 +1426,7 @@ dependencies = [ "libretro-sys", "log 0.4.11", "rustboyadvance-core", + "rustboyadvance-utils", "unsafe_unwrap", ] @@ -1472,6 +1474,7 @@ dependencies = [ "js-sys", "log 0.4.11", "rustboyadvance-core", + "rustboyadvance-utils", "wasm-bindgen", "wasm-bindgen-console-logger", "wasm-bindgen-test", diff --git a/arm7tdmi/build.rs b/arm7tdmi/build.rs index d02b75c..33eeeae 100644 --- a/arm7tdmi/build.rs +++ b/arm7tdmi/build.rs @@ -265,7 +265,7 @@ fn arm_decode(i: u32) -> (&'static str, String) { } (0b010, 0b0001) => { if 0b010 == i.bit_range(20..23) { - Some(("BranchExchange", format!("exec_arm_bx"))) + Some(("BranchExchange", "exec_arm_bx".to_string())) } else { None } diff --git a/arm7tdmi/src/arm/exec.rs b/arm7tdmi/src/arm/exec.rs index adf9d9f..72fd706 100644 --- a/arm7tdmi/src/arm/exec.rs +++ b/arm7tdmi/src/arm/exec.rs @@ -336,9 +336,7 @@ impl Arm7tdmiCore { } if !LOAD || base_reg != dest_reg { - if !PRE_INDEX { - self.set_reg(base_reg, effective_addr); - } else if WRITEBACK { + if !PRE_INDEX || WRITEBACK{ self.set_reg(base_reg, effective_addr); } } diff --git a/core/src/cartridge/rtc.rs b/core/src/cartridge/rtc.rs index 148fe79..309e33b 100644 --- a/core/src/cartridge/rtc.rs +++ b/core/src/cartridge/rtc.rs @@ -496,8 +496,6 @@ mod registers { #[cfg(test)] mod tests { use super::*; - use std::cell::Cell; - use std::rc::Rc; fn transmit(rtc: &mut Rtc, gpio_state: &GpioState, bit: u8) { rtc.write(&gpio_state, 0b0100_u16 | (u16::from(bit) << 1)); @@ -617,7 +615,7 @@ mod tests { let mut bytes = [0]; receive_bytes(&mut rtc, &gpio_state, &mut bytes); - let mut read_status = registers::StatusRegister(bytes[0]); + let read_status = registers::StatusRegister(bytes[0]); assert_eq!(read_status.mode_24h(), true); } diff --git a/core/src/gpu/mod.rs b/core/src/gpu/mod.rs index 36989cc..d65d46e 100644 --- a/core/src/gpu/mod.rs +++ b/core/src/gpu/mod.rs @@ -577,18 +577,18 @@ mod tests { macro_rules! update { ($cycles:expr) => { sched.update($cycles); - let (event, cycles_late) = sched.pop_pending_event().unwrap(); - assert_eq!(cycles_late, 0); - match event { + let (event, event_time) = sched.pop_pending_event().unwrap(); + assert_eq!(event_time, sched.timestamp()); + let next_event = match event { EventType::Gpu(event) => gpu.on_event( event, - cycles_late, &mut dma_notifier, #[cfg(not(feature = "no_video_interface"))] &video_clone, ), _ => panic!("Found unexpected event in queue!"), - } + }; + sched.schedule(next_event); }; } diff --git a/core/src/sched.rs b/core/src/sched.rs index 4ef031c..2cbff20 100644 --- a/core/src/sched.rs +++ b/core/src/sched.rs @@ -109,12 +109,15 @@ pub struct Scheduler { pub type SharedScheduler = Shared; impl Scheduler { - pub fn new_shared() -> SharedScheduler { - let sched = Scheduler { + pub fn new() -> Scheduler { + Scheduler { timestamp: 0, events: BinaryHeap::with_capacity(NUM_EVENTS), - }; - SharedScheduler::new(sched) + } + } + + pub fn new_shared() -> SharedScheduler { + Scheduler::new().make_shared() } pub fn make_shared(self) -> SharedScheduler { diff --git a/platform/rustboyadvance-jni/Cargo.toml b/platform/rustboyadvance-jni/Cargo.toml index 33aba92..824e1d1 100644 --- a/platform/rustboyadvance-jni/Cargo.toml +++ b/platform/rustboyadvance-jni/Cargo.toml @@ -11,6 +11,7 @@ crate-type = ["staticlib", "cdylib"] [dependencies] rustboyadvance-core = {path = "../../core/", features = ["no_video_interface"]} +rustboyadvance-utils = {path = "../../utils/" } jni = "0.17.0" log = {version = "0.4.8", features = ["release_max_level_info", "max_level_debug"]} diff --git a/platform/rustboyadvance-jni/src/audio/thread.rs b/platform/rustboyadvance-jni/src/audio/thread.rs index d2e1efa..6f042f0 100644 --- a/platform/rustboyadvance-jni/src/audio/thread.rs +++ b/platform/rustboyadvance-jni/src/audio/thread.rs @@ -4,7 +4,7 @@ use std::sync::mpsc::{channel, Sender}; use std::thread; use std::thread::JoinHandle; -use rustboyadvance_core::util::audio::Consumer; +use rustboyadvance_utils::audio::Consumer; use jni::JavaVM; diff --git a/platform/rustboyadvance-jni/src/emulator.rs b/platform/rustboyadvance-jni/src/emulator.rs index 00a55ed..992f0c1 100644 --- a/platform/rustboyadvance-jni/src/emulator.rs +++ b/platform/rustboyadvance-jni/src/emulator.rs @@ -1,5 +1,5 @@ use rustboyadvance_core::prelude::*; -use rustboyadvance_core::util::audio::{AudioRingBuffer, Producer}; +use rustboyadvance_utils::audio::{AudioRingBuffer, Producer}; // use rustboyadvance_core::util::FpsCounter; use std::cell::RefCell; diff --git a/platform/rustboyadvance-jni/src/lib.rs b/platform/rustboyadvance-jni/src/lib.rs index 9a8a955..a8f8d4d 100644 --- a/platform/rustboyadvance-jni/src/lib.rs +++ b/platform/rustboyadvance-jni/src/lib.rs @@ -289,7 +289,7 @@ pub mod bindings { pub unsafe extern "C" fn Java_com_mrmichel_rustboyadvance_EmulatorBindings_log( _env: JNIEnv, _obj: JClass, - ctx: jlong, + _ctx: jlong, ) { info!("unimplemented") } diff --git a/platform/rustboyadvance-libretro/Cargo.toml b/platform/rustboyadvance-libretro/Cargo.toml index bfca404..68e1002 100644 --- a/platform/rustboyadvance-libretro/Cargo.toml +++ b/platform/rustboyadvance-libretro/Cargo.toml @@ -11,6 +11,7 @@ crate-type = ["cdylib"] [dependencies] rustboyadvance-core = { path = "../../core/", features = ["no_video_interface"] } +rustboyadvance-utils = { path = "../../utils" } log = "0.4.8" libc = "0.2" libretro-sys = "0.1.1" diff --git a/platform/rustboyadvance-libretro/src/lib.rs b/platform/rustboyadvance-libretro/src/lib.rs index 3201c3f..c5c75b9 100644 --- a/platform/rustboyadvance-libretro/src/lib.rs +++ b/platform/rustboyadvance-libretro/src/lib.rs @@ -13,7 +13,7 @@ use unsafe_unwrap::UnsafeUnwrap; use rustboyadvance_core::keypad::Keys as GbaButton; use rustboyadvance_core::prelude::*; -use rustboyadvance_core::util::audio::AudioRingBuffer; +use rustboyadvance_utils::audio::AudioRingBuffer; use std::path::Path; @@ -115,7 +115,7 @@ impl libretro_backend::Core for RustBoyAdvanceCore { let hwif = Rc::new(RefCell::new(HwInterface { key_state: rustboyadvance_core::keypad::KEYINPUT_ALL_RELEASED, - audio_ring_buffer: AudioRingBuffer::new(), + audio_ring_buffer: Default::default(), })); let gba = GameBoyAdvance::new( bios.into_boxed_slice(), diff --git a/platform/rustboyadvance-sdl2/src/main.rs b/platform/rustboyadvance-sdl2/src/main.rs index df17136..82604c1 100644 --- a/platform/rustboyadvance-sdl2/src/main.rs +++ b/platform/rustboyadvance-sdl2/src/main.rs @@ -48,6 +48,7 @@ use rustboyadvance_core::prelude::*; use rustboyadvance_utils::FpsCounter; const LOG_DIR: &str = ".logs"; +#[cfg(feature = "gdb")] const DEFAULT_GDB_SERVER_ADDR: &'static str = "localhost:1337"; const CANVAS_WIDTH: u32 = SCREEN_WIDTH; @@ -243,6 +244,10 @@ fn main() -> Result<(), Box> { if with_gdbserver { spawn_and_run_gdb_server(&mut gba, DEFAULT_GDB_SERVER_ADDR)?; } + #[cfg(not(feature = "gdb"))] + if with_gdbserver { + panic!("Please compile me with 'gdb' feature") + } let mut fps_counter = FpsCounter::default(); let frame_time = time::Duration::new(0, 1_000_000_000u32 / 60); diff --git a/platform/rustboyadvance-wasm/Cargo.toml b/platform/rustboyadvance-wasm/Cargo.toml index 72473b8..7efc3d2 100644 --- a/platform/rustboyadvance-wasm/Cargo.toml +++ b/platform/rustboyadvance-wasm/Cargo.toml @@ -14,6 +14,7 @@ default = ["console_error_panic_hook"] js-sys = "0.3.37" wasm-bindgen = "0.2" rustboyadvance-core = { path = "../../core" } +rustboyadvance-utils = { path = "../../utils" } # The `console_error_panic_hook` crate provides better debugging of panics by # logging them with `console.error`. This is great for development, but requires diff --git a/platform/rustboyadvance-wasm/src/emulator.rs b/platform/rustboyadvance-wasm/src/emulator.rs index 5cbc959..b8c6ea5 100644 --- a/platform/rustboyadvance-wasm/src/emulator.rs +++ b/platform/rustboyadvance-wasm/src/emulator.rs @@ -11,7 +11,7 @@ use web_sys::CanvasRenderingContext2d; use rustboyadvance_core::keypad as gba_keypad; use rustboyadvance_core::prelude::*; -use rustboyadvance_core::util::audio::AudioRingBuffer; +use rustboyadvance_utils::audio::AudioRingBuffer; use bit::BitIndex; @@ -42,7 +42,7 @@ impl Interface { keyinput: gba_keypad::KEYINPUT_ALL_RELEASED, sample_rate: audio_ctx.sample_rate() as i32, audio_ctx: audio_ctx, - audio_ring_buffer: AudioRingBuffer::new(), + audio_ring_buffer: Default::default(), }) } } @@ -61,7 +61,7 @@ impl VideoInterface for Interface { } fn convert_sample(s: i16) -> f32 { - ((s as f32) / 32767_f32) + (s as f32) / 32767_f32 } impl AudioInterface for Interface { @@ -156,7 +156,7 @@ impl Emulator { } pub fn test_fps(&mut self) { - use rustboyadvance_core::util::FpsCounter; + use rustboyadvance_utils::FpsCounter; let mut fps_counter = FpsCounter::default(); diff --git a/utils/src/lib.rs b/utils/src/lib.rs index ab1747e..07927d3 100644 --- a/utils/src/lib.rs +++ b/utils/src/lib.rs @@ -29,7 +29,7 @@ pub fn read_bin_file(filename: &Path) -> io::Result> { Ok(buf) } -pub fn write_bin_file(filename: &Path, data: &Vec) -> io::Result<()> { +pub fn write_bin_file(filename: &Path, data: &[u8]) -> io::Result<()> { let mut f = File::create(filename)?; f.write_all(data)?; @@ -94,11 +94,13 @@ pub mod audio { cons: Consumer, } - impl AudioRingBuffer { - pub fn new() -> AudioRingBuffer { + impl Default for AudioRingBuffer { + fn default() -> AudioRingBuffer { AudioRingBuffer::new_with_capacity(2 * 4096) } + } + impl AudioRingBuffer { pub fn new_with_capacity(capacity: usize) -> AudioRingBuffer { let rb = RingBuffer::new(capacity); let (prod, cons) = rb.split(); @@ -192,10 +194,6 @@ impl Shared { pub fn new(t: T) -> Shared { Shared(Rc::new(UnsafeCell::new(t))) } - - pub unsafe fn inner_unsafe(&self) -> &mut T { - &mut (*self.0.get()) - } } impl Shared