manual clippy fixes

This commit is contained in:
Alex Janka 2024-11-19 10:15:27 +11:00
parent bc8da0212d
commit 1e4a478d1f
31 changed files with 157 additions and 127 deletions

View file

@ -54,6 +54,7 @@ impl From<SerialTargetOption> for SerialTarget {
#[command(author, version, about, long_about = None)] #[command(author, version, about, long_about = None)]
#[command(group(ArgGroup::new("saves").args(["save","no_save"])))] #[command(group(ArgGroup::new("saves").args(["save","no_save"])))]
#[command(subcommand_negates_reqs = true)] #[command(subcommand_negates_reqs = true)]
#[allow(clippy::struct_excessive_bools)]
struct Args { struct Args {
#[command(subcommand)] #[command(subcommand)]
command: Option<Commands>, command: Option<Commands>,

View file

@ -55,7 +55,8 @@ pub struct Debugger {
} }
impl Debugger { impl Debugger {
#[must_use] pub fn new(core: Box<dyn EmulatorCoreTrait>) -> Self { #[must_use]
pub fn new(core: Box<dyn EmulatorCoreTrait>) -> Self {
Self { Self {
core, core,
stepping: true, stepping: true,
@ -80,9 +81,9 @@ impl Debugger {
Err(_) => String::new(), Err(_) => String::new(),
}; };
if line.trim().is_empty() { if line.trim().is_empty() {
line = self.last_command.clone(); line.clone_from(&self.last_command);
} else { } else {
self.last_command = line.clone(); self.last_command.clone_from(&line);
} }
if let Ok(command) = Commands::from_str(&line) { if let Ok(command) = Commands::from_str(&line) {
match command { match command {

View file

@ -65,6 +65,7 @@ fn access_config<'a>() -> &'a Configs {
CONFIGS.get().expect("accessed config before it was set!") CONFIGS.get().expect("accessed config before it was set!")
} }
#[allow(clippy::struct_excessive_bools)]
pub struct RunOptions { pub struct RunOptions {
pub rom: PathBuf, pub rom: PathBuf,
pub save: SramType, pub save: SramType,
@ -77,7 +78,8 @@ pub struct RunOptions {
} }
impl RunOptions { impl RunOptions {
#[must_use] pub fn new(rom: PathBuf) -> Self { #[must_use]
pub fn new(rom: PathBuf) -> Self {
Self { Self {
rom, rom,
save: SramType::Auto, save: SramType::Auto,

View file

@ -60,9 +60,10 @@ where
Backend: RendererBackend, Backend: RendererBackend,
<Backend as RendererBackend>::RendererError: Sync + Send + 'static, <Backend as RendererBackend>::RendererError: Sync + Send + 'static,
{ {
#[must_use] pub fn new( #[must_use]
pub fn new(
sender: Sender<EmulatorMessage<[u8; 4]>>, sender: Sender<EmulatorMessage<[u8; 4]>>,
_stream: Stream, stream: Stream,
record_main: bool, record_main: bool,
) -> Self { ) -> Self {
let event_loop = EventLoop::new().unwrap(); let event_loop = EventLoop::new().unwrap();
@ -80,7 +81,7 @@ where
sender, sender,
gamepad_handler: Gilrs::new().unwrap(), gamepad_handler: Gilrs::new().unwrap(),
joypad_state: Default::default(), joypad_state: Default::default(),
_stream, _stream: stream,
}, },
record_main, record_main,
} }
@ -340,11 +341,15 @@ where
let window = WindowBuilder::new() let window = WindowBuilder::new()
.with_title("Gameboy") .with_title("Gameboy")
.with_resizable(resizable); .with_resizable(resizable);
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
let window = window.with_name("TWINC", ""); let window = window.with_name("TWINC", "");
let window = window.build(event_loop)?; let window = window.build(event_loop)?;
#[allow(clippy::cast_sign_loss)]
let real_factor = (window.scale_factor() * factor as f64) as u32; let real_factor = (window.scale_factor() * factor as f64) as u32;
let inner_size = window.inner_size(); let inner_size = window.inner_size();
let resolutions = ResolutionData { let resolutions = ResolutionData {
real_width: inner_size.width, real_width: inner_size.width,
@ -415,8 +420,8 @@ where
fn process(&mut self) { fn process(&mut self) {
while let Ok(message) = self.receiver.try_recv() { while let Ok(message) = self.receiver.try_recv() {
match message { match message {
RendererMessage::Prepare { width, height } => self.attempt_resize(width, height), RendererMessage::Resize { width, height }
RendererMessage::Resize { width, height } => self.attempt_resize(width, height), | RendererMessage::Prepare { width, height } => self.attempt_resize(width, height),
RendererMessage::Display { buffer } => self.display(buffer), RendererMessage::Display { buffer } => self.display(buffer),
RendererMessage::SetTitle { title } => self.window.set_title(&title), RendererMessage::SetTitle { title } => self.window.set_title(&title),
RendererMessage::Rumble { rumble: _ } => todo!(), RendererMessage::Rumble { rumble: _ } => todo!(),
@ -428,6 +433,7 @@ where
self.width = width; self.width = width;
self.height = height; self.height = height;
#[allow(clippy::cast_sign_loss)]
let real_factor = (self.window.scale_factor() * self.factor as f64) as u32; let real_factor = (self.window.scale_factor() * self.factor as f64) as u32;
let real_width = (width as u32) * real_factor; let real_width = (width as u32) * real_factor;

View file

@ -84,6 +84,7 @@ impl Editor for TwincEditor {
} }
fn size(&self) -> (u32, u32) { fn size(&self) -> (u32, u32) {
#[allow(clippy::cast_sign_loss)]
(self.size.width as u32, self.size.height as u32) (self.size.width as u32, self.size.height as u32)
} }
@ -127,6 +128,7 @@ impl TwincEditorWindow {
size: Size, size: Size,
shader_path: Option<std::path::PathBuf>, shader_path: Option<std::path::PathBuf>,
) -> Self { ) -> Self {
#[allow(clippy::cast_sign_loss)]
let current_resolution = ResolutionData { let current_resolution = ResolutionData {
real_width: size.width as u32, real_width: size.width as u32,
real_height: size.height as u32, real_height: size.height as u32,
@ -152,17 +154,17 @@ impl TwincEditorWindow {
if let Some(ref comms) = *comms { if let Some(ref comms) = *comms {
while let Ok(e) = comms.receiver.try_recv() { while let Ok(e) = comms.receiver.try_recv() {
match e { match e {
RendererMessage::Display { buffer } => self.latest_buf = buffer,
RendererMessage::Prepare { RendererMessage::Prepare {
width: _, width: _,
height: _, height: _,
} => {} }
RendererMessage::Resize { | RendererMessage::Resize {
width: _, width: _,
height: _, height: _,
} => {} }
RendererMessage::Display { buffer } => self.latest_buf = buffer, | RendererMessage::SetTitle { title: _ }
RendererMessage::SetTitle { title: _ } => {} | RendererMessage::Rumble { rumble: _ } => {}
RendererMessage::Rumble { rumble: _ } => {}
} }
} }
} }

View file

@ -58,8 +58,7 @@ impl RomFile {
let save_location = match save { let save_location = match save {
SramType::File(path) => Some(SaveDataLocation::File(path)), SramType::File(path) => Some(SaveDataLocation::File(path)),
SramType::RawBuffer(buf) => Some(SaveDataLocation::Raw(buf)), SramType::RawBuffer(buf) => Some(SaveDataLocation::Raw(buf)),
SramType::Auto => None, SramType::Auto | SramType::None => None,
SramType::None => None,
}; };
Ok(Rom::load(data, save_location)) Ok(Rom::load(data, save_location))
} }
@ -84,7 +83,8 @@ pub enum RendererMessage<Format: From<Colour>> {
} }
impl<Format: From<Colour>> RendererMessage<Format> { impl<Format: From<Colour>> RendererMessage<Format> {
#[must_use] pub fn display_message(buffer: Vec<Format>) -> Self { #[must_use]
pub fn display_message(buffer: Vec<Format>) -> Self {
Self::Display { buffer } Self::Display { buffer }
} }
} }
@ -105,11 +105,13 @@ pub struct AudioOutput {
} }
impl AudioOutput { impl AudioOutput {
#[must_use] pub fn new( #[must_use]
pub fn new(
sample_rate: f32, sample_rate: f32,
buffers_per_frame: usize, buffers_per_frame: usize,
downsample_type: DownsampleType, downsample_type: DownsampleType,
) -> (Self, AsyncHeapCons<[f32; 2]>) { ) -> (Self, AsyncHeapCons<[f32; 2]>) {
#[allow(clippy::cast_sign_loss)]
let rb_len = (sample_rate as usize / 60) / buffers_per_frame; let rb_len = (sample_rate as usize / 60) / buffers_per_frame;
let rb = AsyncHeapRb::<[f32; 2]>::new(rb_len); let rb = AsyncHeapRb::<[f32; 2]>::new(rb_len);
@ -190,7 +192,9 @@ where
#[allow(unused)] #[allow(unused)]
pub(crate) fn tick(&mut self, steps: usize) { pub(crate) fn tick(&mut self, steps: usize) {
if self.counter > 0 { if self.counter > 0 {
self.counter = if let Some(num) = self.counter.checked_sub(steps) { num } else { self.counter = if let Some(num) = self.counter.checked_sub(steps) {
num
} else {
self.next_image = Some(self.inner.get_image()); self.next_image = Some(self.inner.get_image());
0 0
}; };
@ -239,7 +243,8 @@ impl<ColourFormat> EmulatorOptions<ColourFormat>
where where
ColourFormat: From<Colour> + Copy, ColourFormat: From<Colour> + Copy,
{ {
#[must_use] pub fn new( #[must_use]
pub fn new(
window: Option<Sender<RendererMessage<ColourFormat>>>, window: Option<Sender<RendererMessage<ColourFormat>>>,
rom: Rom, rom: Rom,
output: AudioOutput, output: AudioOutput,
@ -290,42 +295,50 @@ where
} }
} }
#[must_use]
pub fn with_sram_buffer(mut self, buffer: Arc<RwLock<Vec<u8>>>) -> Self { pub fn with_sram_buffer(mut self, buffer: Arc<RwLock<Vec<u8>>>) -> Self {
self.save = Some(SramType::RawBuffer(buffer)); self.save = Some(SramType::RawBuffer(buffer));
self self
} }
#[must_use] pub fn with_dmg_bootrom(mut self, dmg_bootrom: Option<RomFile>) -> Self { #[must_use]
pub fn with_dmg_bootrom(mut self, dmg_bootrom: Option<RomFile>) -> Self {
self.dmg_bootrom = dmg_bootrom; self.dmg_bootrom = dmg_bootrom;
self self
} }
#[must_use] pub fn with_cgb_bootrom(mut self, cgb_bootrom: Option<RomFile>) -> Self { #[must_use]
pub fn with_cgb_bootrom(mut self, cgb_bootrom: Option<RomFile>) -> Self {
self.cgb_bootrom = cgb_bootrom; self.cgb_bootrom = cgb_bootrom;
self self
} }
#[must_use] pub fn with_show_bootrom(mut self, show_bootrom: bool) -> Self { #[must_use]
pub fn with_show_bootrom(mut self, show_bootrom: bool) -> Self {
self.show_bootrom = show_bootrom; self.show_bootrom = show_bootrom;
self self
} }
#[must_use] pub fn with_no_output(mut self, no_output: bool) -> Self { #[must_use]
pub fn with_no_output(mut self, no_output: bool) -> Self {
self.no_output = no_output; self.no_output = no_output;
self self
} }
#[must_use] pub fn with_stdout(mut self) -> Self { #[must_use]
pub fn with_stdout(mut self) -> Self {
self.serial_target = SerialTarget::Stdout(StdoutType::Ascii); self.serial_target = SerialTarget::Stdout(StdoutType::Ascii);
self self
} }
#[must_use] pub fn with_serial_target(mut self, target: SerialTarget) -> Self { #[must_use]
pub fn with_serial_target(mut self, target: SerialTarget) -> Self {
self.serial_target = target; self.serial_target = target;
self self
} }
#[must_use] pub fn with_tile_window( #[must_use]
pub fn with_tile_window(
mut self, mut self,
window: Option<Sender<RendererMessage<ColourFormat>>>, window: Option<Sender<RendererMessage<ColourFormat>>>,
) -> Self { ) -> Self {
@ -333,7 +346,8 @@ where
self self
} }
#[must_use] pub fn with_layer_window( #[must_use]
pub fn with_layer_window(
mut self, mut self,
window: Option<Sender<RendererMessage<ColourFormat>>>, window: Option<Sender<RendererMessage<ColourFormat>>>,
) -> Self { ) -> Self {
@ -341,7 +355,8 @@ where
self self
} }
#[must_use] pub fn with_cgb_mode(mut self, cgb_mode: bool) -> Self { #[must_use]
pub fn with_cgb_mode(mut self, cgb_mode: bool) -> Self {
self.cgb_mode = cgb_mode; self.cgb_mode = cgb_mode;
self self
} }

View file

@ -125,7 +125,7 @@ where
self.set_or_clear_flag(Flags::Zero, result == 0x0); self.set_or_clear_flag(Flags::Zero, result == 0x0);
self.set_or_clear_flag( self.set_or_clear_flag(
Flags::HalfCarry, Flags::HalfCarry,
first.get_low_nibble() + second.get_low_nibble() + if with_carry { 1 } else { 0 } > 0xF, first.get_low_nibble() + second.get_low_nibble() + u8::from(with_carry) > 0xF,
); );
result result
} }

View file

@ -49,7 +49,7 @@ impl Wram {
bank_0: Box::new([0; 4096]), bank_0: Box::new([0; 4096]),
banks: if cgb { banks: if cgb {
WramBanks::Cgb { WramBanks::Cgb {
banks: Box::new([[0; 4096]; 8]), banks: crate::util::boxed_array([0; 4096]),
selected: 0, selected: 0,
} }
} else { } else {
@ -386,10 +386,11 @@ where
CgbIoAddress::Palette(address) => self.gpu.set_cgb_palette(address, data), CgbIoAddress::Palette(address) => self.gpu.set_cgb_palette(address, data),
CgbIoAddress::ObjPriority => self.gpu.set_obj_priority(data), CgbIoAddress::ObjPriority => self.gpu.set_obj_priority(data),
CgbIoAddress::WramBank => *selected = (data & 0b111).max(1) as usize, CgbIoAddress::WramBank => *selected = (data & 0b111).max(1) as usize,
CgbIoAddress::Pcm12 => {} CgbIoAddress::Pcm12 | CgbIoAddress::Pcm34 => {}
CgbIoAddress::Pcm34 => {}
CgbIoAddress::Unused(v) => { CgbIoAddress::Unused(v) => {
log::error!("attempt to set unused address 0x{v:0>4X} to 0x{data:0>2X}"); log::error!(
"attempt to set unused address 0x{v:0>4X} to 0x{data:0>2X}"
);
} }
} }
} }

View file

@ -67,7 +67,7 @@ impl<const MIN: u16, const MAX: u16> TryInto<BoundedAddress<MIN, MAX>> for u16 {
} }
impl<const MIN: u16, const MAX: u16> BoundedAddress<MIN, MAX> { impl<const MIN: u16, const MAX: u16> BoundedAddress<MIN, MAX> {
pub(crate) fn get_local(&self) -> u16 { pub(crate) fn get_local(self) -> u16 {
self.0 - MIN self.0 - MIN
} }
} }

View file

@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize};
use crate::util::get_bit; use crate::util::get_bit;
#[derive(Default, Debug, Copy, Clone, Serialize, Deserialize)] #[derive(Default, Debug, Copy, Clone, Serialize, Deserialize)]
#[allow(clippy::struct_excessive_bools)]
struct InterruptRegister { struct InterruptRegister {
vblank: bool, vblank: bool,
lcd_stat: bool, lcd_stat: bool,
@ -12,7 +13,7 @@ struct InterruptRegister {
} }
impl InterruptRegister { impl InterruptRegister {
fn as_register(&self) -> u8 { fn as_register(self) -> u8 {
bool_to_shifted(self.vblank, 0) bool_to_shifted(self.vblank, 0)
| bool_to_shifted(self.lcd_stat, 1) | bool_to_shifted(self.lcd_stat, 1)
| bool_to_shifted(self.timer, 2) | bool_to_shifted(self.timer, 2)
@ -30,7 +31,7 @@ impl InterruptRegister {
} }
fn bool_to_shifted(input: bool, shift: u8) -> u8 { fn bool_to_shifted(input: bool, shift: u8) -> u8 {
(if input { 1 } else { 0 }) << shift u8::from(input) << shift
} }
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]

View file

@ -37,11 +37,11 @@ impl DacSample {
} }
pub struct Apu { pub struct Apu {
apu_enable: bool, enable: bool,
channels: Channels, channels: Channels,
vin: VinEnable, vin: VinEnable,
mixer: Mixer, mixer: Mixer,
div_apu: u8, div: u8,
converter: Downsampler, converter: Downsampler,
output: AudioOutput, output: AudioOutput,
} }
@ -49,11 +49,11 @@ pub struct Apu {
impl Apu { impl Apu {
pub fn new(output: AudioOutput) -> Self { pub fn new(output: AudioOutput) -> Self {
Self { Self {
apu_enable: true, enable: true,
channels: Channels::default(), channels: Channels::default(),
vin: VinEnable::default(), vin: VinEnable::default(),
mixer: Mixer::default(), mixer: Mixer::default(),
div_apu: 0, div: 0,
converter: Downsampler::new(output.sample_rate, output.downsample_type), converter: Downsampler::new(output.sample_rate, output.downsample_type),
output, output,
} }
@ -65,18 +65,18 @@ impl Apu {
} }
pub fn div_apu_tick(&mut self) { pub fn div_apu_tick(&mut self) {
self.div_apu = self.div_apu.wrapping_add(1); self.div = self.div.wrapping_add(1);
if self.div_apu % 8 == 0 { if self.div % 8 == 0 {
// envelope sweep // envelope sweep
self.channels.one.envelope_tick(); self.channels.one.envelope_tick();
self.channels.two.envelope_tick(); self.channels.two.envelope_tick();
self.channels.four.envelope_tick(); self.channels.four.envelope_tick();
} }
if self.div_apu % 4 == 0 { if self.div % 4 == 0 {
// ch1 frequency sweep // ch1 frequency sweep
self.channels.one.frequency_tick(); self.channels.one.frequency_tick();
} }
if self.div_apu % 2 == 0 { if self.div % 2 == 0 {
// tick sound length timers // tick sound length timers
self.channels.one.length_tick(); self.channels.one.length_tick();
self.channels.two.length_tick(); self.channels.two.length_tick();
@ -124,7 +124,7 @@ impl Apu {
} }
pub(crate) fn get_register(&self, addr: AudioAddress) -> u8 { pub(crate) fn get_register(&self, addr: AudioAddress) -> u8 {
if self.apu_enable { if self.enable {
self.make_register(addr) self.make_register(addr)
} else { } else {
match addr.inner() { match addr.inner() {
@ -178,11 +178,7 @@ impl Apu {
} }
0xFF26 => { 0xFF26 => {
// NR52 - Sound on/off // NR52 - Sound on/off
let mut v = if self.apu_enable { let mut v = if self.enable { 0b11111111 } else { 0b01111111 };
0b11111111
} else {
0b01111111
};
v = set_or_clear_bit(v, 0, self.channels.one.is_dac_enabled()); v = set_or_clear_bit(v, 0, self.channels.one.is_dac_enabled());
v = set_or_clear_bit(v, 1, self.channels.two.is_dac_enabled()); v = set_or_clear_bit(v, 1, self.channels.two.is_dac_enabled());
v = set_or_clear_bit(v, 2, self.channels.three.is_dac_enabled()); v = set_or_clear_bit(v, 2, self.channels.three.is_dac_enabled());
@ -190,7 +186,7 @@ impl Apu {
v v
} }
// write-only registers // write-only registers
0xFF13 | 0xFF18 | 0xFF1B | 0xFF1D | 0xFF20 => 0xFF, 0xFF13 | 0xFF18 | 0xFF1B | 0xFF1D | 0xFF20 |
// not registers // not registers
0xFF15 | 0xFF1F => 0xFF, 0xFF15 | 0xFF1F => 0xFF,
0x0..0xFF10 | 0xFF27..=0xFFFF => unreachable!(), 0x0..0xFF10 | 0xFF27..=0xFFFF => unreachable!(),
@ -198,6 +194,7 @@ impl Apu {
} }
pub(crate) fn mmio_write(&mut self, addr: AudioAddress, data: u8) { pub(crate) fn mmio_write(&mut self, addr: AudioAddress, data: u8) {
#[allow(clippy::match_same_arms)]
match addr.inner() { match addr.inner() {
0xFF10 => self.channels.one.update_sweep(data), 0xFF10 => self.channels.one.update_sweep(data),
0xFF11 => self.channels.one.update_length_timer_and_duty_cycle(data), 0xFF11 => self.channels.one.update_length_timer_and_duty_cycle(data),
@ -236,7 +233,7 @@ impl Apu {
self.mixer.ch4.left = Volume::from_bool(get_bit(data, 7)); self.mixer.ch4.left = Volume::from_bool(get_bit(data, 7));
} }
0xFF26 => { 0xFF26 => {
if !self.apu_enable { if !self.enable {
for i in 0xFF10..0xFF20 { for i in 0xFF10..0xFF20 {
self.mmio_write(i.try_into().unwrap(), 0x0); self.mmio_write(i.try_into().unwrap(), 0x0);
} }
@ -244,7 +241,7 @@ impl Apu {
self.mmio_write(i.try_into().unwrap(), 0x0); self.mmio_write(i.try_into().unwrap(), 0x0);
} }
} }
self.apu_enable = (1 << 7) == (data & 0b10000000); self.enable = (1 << 7) == (data & 0b10000000);
} }
0x0..0xFF10 | 0xFF27..=0xFFFF => unreachable!(), 0x0..0xFF10 | 0xFF27..=0xFFFF => unreachable!(),
} }

View file

@ -105,7 +105,7 @@ const FIFTY: [u8; 8] = [1, 0, 0, 0, 0, 1, 1, 1];
const SEVENTY_FIVE: [u8; 8] = [0, 1, 1, 1, 1, 1, 1, 0]; const SEVENTY_FIVE: [u8; 8] = [0, 1, 1, 1, 1, 1, 1, 0];
impl DutyCycle { impl DutyCycle {
fn get_waveform(&self, index: usize) -> u8 { fn get_waveform(self, index: usize) -> u8 {
match self { match self {
DutyCycle::TwelvePointFive => TWELVE_POINT_FIVE[index], DutyCycle::TwelvePointFive => TWELVE_POINT_FIVE[index],
DutyCycle::TwentyFive => TWENTY_FIVE[index], DutyCycle::TwentyFive => TWENTY_FIVE[index],
@ -114,7 +114,7 @@ impl DutyCycle {
} }
} }
fn as_u8(&self) -> u8 { fn as_u8(self) -> u8 {
match self { match self {
DutyCycle::TwelvePointFive => 0b00, DutyCycle::TwelvePointFive => 0b00,
DutyCycle::TwentyFive => 0b01, DutyCycle::TwentyFive => 0b01,
@ -315,7 +315,7 @@ enum ShiftVolumePercent {
} }
impl ShiftVolumePercent { impl ShiftVolumePercent {
fn as_shift_amount(&self) -> u8 { fn as_shift_amount(self) -> u8 {
match self { match self {
ShiftVolumePercent::Zero => 8, ShiftVolumePercent::Zero => 8,
ShiftVolumePercent::TwentyFive => 2, ShiftVolumePercent::TwentyFive => 2,
@ -472,7 +472,10 @@ impl WaveChannel {
pub(super) fn update_wave_ram(&mut self, addr: WaveRamAddress, data: u8) { pub(super) fn update_wave_ram(&mut self, addr: WaveRamAddress, data: u8) {
let real_addr = addr.get_local() as usize; let real_addr = addr.get_local() as usize;
assert!(real_addr < self.wave_ram.data.len(), "sent the wrong address to update_wave_ram"); assert!(
real_addr < self.wave_ram.data.len(),
"sent the wrong address to update_wave_ram"
);
self.wave_ram.data[real_addr] = data; self.wave_ram.data[real_addr] = data;
} }
@ -518,21 +521,13 @@ impl Lfsr {
} }
fn next_value(&mut self) { fn next_value(&mut self) {
let next = if (self.register & 0b1) == ((self.register >> 1) & 0b1) { let next = u16::from((self.register & 0b1) == ((self.register >> 1) & 0b1));
1
} else {
0
};
self.register = (self.register & !(0b1 << 15)) | (next << 15); self.register = (self.register & !(0b1 << 15)) | (next << 15);
if self.width == LfsrWidth::SevenBit { if self.width == LfsrWidth::SevenBit {
self.register = (self.register & !(0b1 << 7)) | (next << 7); self.register = (self.register & !(0b1 << 7)) | (next << 7);
} }
self.register >>= 1; self.register >>= 1;
self.current_value = if (self.register & 0b1) == 0b1 { self.current_value = u8::from((self.register & 0b1) == 0b1);
0x1
} else {
0x0
};
} }
} }

View file

@ -15,7 +15,7 @@ impl Default for Averager {
} }
impl Averager { impl Averager {
fn push(&mut self, next: &[f32; 2]) { fn push(&mut self, next: [f32; 2]) {
self.accum[0] += next[0]; self.accum[0] += next[0];
self.accum[1] += next[1]; self.accum[1] += next[1];
self.num += 1; self.num += 1;
@ -58,7 +58,7 @@ impl Downsampler {
pub fn push(&mut self, signal: [f32; 2]) -> Option<[f32; 2]> { pub fn push(&mut self, signal: [f32; 2]) -> Option<[f32; 2]> {
self.time_accum += 1.; self.time_accum += 1.;
if let Some(ref mut averager) = self.average { if let Some(ref mut averager) = self.average {
averager.push(&signal); averager.push(signal);
} }
if self.time_accum >= self.ratio { if self.time_accum >= self.ratio {
self.time_accum -= self.ratio; self.time_accum -= self.ratio;

View file

@ -34,14 +34,14 @@ pub(super) enum Volume {
} }
impl Volume { impl Volume {
pub(super) fn gate(&self, val: f32) -> f32 { pub(super) fn gate(self, val: f32) -> f32 {
match self { match self {
Volume::Muted => 0., Volume::Muted => 0.,
Volume::Enabled => val, Volume::Enabled => val,
} }
} }
pub(super) fn bool(&self) -> bool { pub(super) fn bool(self) -> bool {
match self { match self {
Volume::Muted => false, Volume::Muted => false,
Volume::Enabled => true, Volume::Enabled => true,

View file

@ -8,8 +8,8 @@ pub(crate) struct DoubleSpeed {
} }
impl DoubleSpeed { impl DoubleSpeed {
pub(crate) fn get(&self) -> u8 { pub(crate) fn get(self) -> u8 {
0b01111110 | if self.current { 0b1 << 7 } else { 0 } | if self.prepared { 0b1 } else { 0 } 0b01111110 | if self.current { 0b1 << 7 } else { 0 } | u8::from(self.prepared)
} }
pub(crate) fn set(&mut self, data: u8) { pub(crate) fn set(&mut self, data: u8) {

View file

@ -9,8 +9,8 @@ pub struct Infrared {
} }
impl Infrared { impl Infrared {
pub(crate) fn get(&self) -> u8 { pub(crate) fn get(self) -> u8 {
0b111110 | if self.led { 1 } else { 0 } | if self.read_enable { 0b11 << 6 } else { 0 } 0b111110 | u8::from(self.led) | if self.read_enable { 0b11 << 6 } else { 0 }
} }
pub(crate) fn set(&mut self, data: u8) { pub(crate) fn set(&mut self, data: u8) {

View file

@ -26,10 +26,10 @@ enum DmaMode {
} }
impl DmaMode { impl DmaMode {
fn get_byte(&self) -> u8 { fn get_byte(self) -> u8 {
match self { match self {
DmaMode::Halt(_) => unreachable!(), DmaMode::Halt(_) => unreachable!(),
DmaMode::Hblank(v, _) => *v, DmaMode::Hblank(v, _) => v,
DmaMode::Waiting => 0xFF, DmaMode::Waiting => 0xFF,
} }
} }
@ -42,7 +42,7 @@ impl Default for DmaMode {
} }
impl VramDma { impl VramDma {
pub(crate) fn get_register(&self, address: VramDmaAddress) -> u8 { pub(crate) fn get_register(self, address: VramDmaAddress) -> u8 {
match address.inner() { match address.inner() {
0xFF51 => self.source.get_high(), 0xFF51 => self.source.get_high(),
0xFF52 => self.source.get_low(), 0xFF52 => self.source.get_low(),

View file

@ -358,7 +358,7 @@ where
} }
let tile_row = object_row % 8; let tile_row = object_row % 8;
let tile_addr = (TiledataArea::D8000 let tile_addr = (TiledataArea::D8000
.get_addr(object.tile_index + if object_row >= 8 { 1 } else { 0 }) .get_addr(object.tile_index + u8::from(object_row >= 8))
+ (u16::from(tile_row) * 2)) + (u16::from(tile_row) * 2))
.unwrap(); .unwrap();
let bank = if self.is_cgb_mode() { let bank = if self.is_cgb_mode() {
@ -466,7 +466,7 @@ where
.get_with_bank(tilemap_addr, VramBank::Bank0) .get_with_bank(tilemap_addr, VramBank::Bank0)
.unwrap(), .unwrap(),
) + u16::from(tiledata_offset)) ) + u16::from(tiledata_offset))
.unwrap(); .unwrap();
let lsbs = self let lsbs = self
.vram .vram

View file

@ -37,12 +37,12 @@ where
} }
pub fn get_lcdc(&self) -> u8 { pub fn get_lcdc(&self) -> u8 {
(if self.lcdc.enable { 1 } else { 0 }) << 7 u8::from(self.lcdc.enable) << 7
| (match self.lcdc.window_tilemap { | (match self.lcdc.window_tilemap {
TilemapArea::T9800 => 0, TilemapArea::T9800 => 0,
TilemapArea::T9C00 => 1, TilemapArea::T9C00 => 1,
}) << 6 }) << 6
| (if self.lcdc.window_enable { 1 } else { 0 }) << 5 | u8::from(self.lcdc.window_enable) << 5
| (match self.lcdc.tile_area { | (match self.lcdc.tile_area {
TiledataArea::D8000 => 1, TiledataArea::D8000 => 1,
TiledataArea::D9000 => 0, TiledataArea::D9000 => 0,
@ -55,8 +55,8 @@ where
ObjSize::S8x8 => 0, ObjSize::S8x8 => 0,
ObjSize::S8x16 => 1, ObjSize::S8x16 => 1,
}) << 2 }) << 2
| (if self.lcdc.obj_enable { 1 } else { 0 }) << 1 | u8::from(self.lcdc.obj_enable) << 1
| (if self.lcdc.bg_window_enable { 1 } else { 0 }) | u8::from(self.lcdc.bg_window_enable)
} }
pub fn update_lcd_status(&mut self, data: u8) { pub fn update_lcd_status(&mut self, data: u8) {

View file

@ -138,7 +138,7 @@ where
tile_bank: bank, tile_bank: bank,
..Default::default() ..Default::default()
}; };
let data_begin = data_begin + ((tile_x * 16) as u16); let data_begin = data_begin + (tile_x * 16);
for px_y in 0..8_u16 { for px_y in 0..8_u16 {
let lsbs = memory let lsbs = memory

View file

@ -24,7 +24,7 @@ pub(super) enum TilemapArea {
} }
impl TilemapArea { impl TilemapArea {
pub(super) fn get_addr(&self, addr: u16) -> VramAddress { pub(super) fn get_addr(self, addr: u16) -> VramAddress {
match self { match self {
TilemapArea::T9800 => (0x9800 + addr).try_into().unwrap(), TilemapArea::T9800 => (0x9800 + addr).try_into().unwrap(),
TilemapArea::T9C00 => (0x9C00 + addr).try_into().unwrap(), TilemapArea::T9C00 => (0x9C00 + addr).try_into().unwrap(),
@ -39,7 +39,7 @@ pub(super) enum TiledataArea {
} }
impl TiledataArea { impl TiledataArea {
pub(super) fn get_addr(&self, addr: u8) -> VramAddress { pub(super) fn get_addr(self, addr: u8) -> VramAddress {
match self { match self {
TiledataArea::D8000 => (0x8000 + (u16::from(addr) * 16)).try_into().unwrap(), TiledataArea::D8000 => (0x8000 + (u16::from(addr) * 16)).try_into().unwrap(),
TiledataArea::D9000 => 0x9000_u16 TiledataArea::D9000 => 0x9000_u16
@ -57,7 +57,7 @@ pub(super) enum ObjSize {
} }
impl ObjSize { impl ObjSize {
pub(super) fn get_height(&self) -> u8 { pub(super) fn get_height(self) -> u8 {
match self { match self {
ObjSize::S8x8 => 8, ObjSize::S8x8 => 8,
ObjSize::S8x16 => 16, ObjSize::S8x16 => 16,
@ -66,6 +66,7 @@ impl ObjSize {
} }
#[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize)] #[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize)]
#[allow(clippy::struct_excessive_bools)]
pub(super) struct Lcdc { pub(super) struct Lcdc {
pub(super) enable: bool, pub(super) enable: bool,
pub(super) window_tilemap: TilemapArea, pub(super) window_tilemap: TilemapArea,
@ -139,17 +140,16 @@ pub(super) fn rgb_from_bytes(bytes: u16) -> Colour {
} }
impl ColourInner { impl ColourInner {
pub(super) fn rgb_bytes(&self, cgb_data: Option<(&CgbPalette, u8)>) -> Colour { pub(super) fn rgb_bytes(self, cgb_data: Option<(&CgbPalette, u8)>) -> Colour {
if let Some((cgb_palette, pallete_num)) = cgb_data { if let Some((cgb_palette, pallete_num)) = cgb_data {
let offset: usize = (pallete_num as usize * 2 * 4) let offset: usize = (pallete_num as usize * 2 * 4)
+ (if *self == ColourInner::Error { + (if self == ColourInner::Error {
if cfg!(feature = "error-colour") { if cfg!(feature = "error-colour") {
return ERROR_COLOUR; return ERROR_COLOUR;
} else {
ColourInner::Zero
} }
ColourInner::Zero
} else { } else {
*self self
} as usize } as usize
* 2); * 2);
@ -180,13 +180,12 @@ impl ColourInner {
} }
} }
fn as_bits(&self) -> u8 { fn as_bits(self) -> u8 {
match self { match self {
ColourInner::Zero => 0b00, ColourInner::Error | ColourInner::Zero => 0b00,
ColourInner::One => 0b01, ColourInner::One => 0b01,
ColourInner::Two => 0b10, ColourInner::Two => 0b10,
ColourInner::Three => 0b11, ColourInner::Three => 0b11,
ColourInner::Error => 0b00,
} }
} }
} }
@ -209,14 +208,14 @@ impl Palette {
} }
} }
pub(super) fn as_byte(&self) -> u8 { pub(super) fn as_byte(self) -> u8 {
self.zero.as_bits() self.zero.as_bits()
| (self.one.as_bits() << 2) | (self.one.as_bits() << 2)
| (self.two.as_bits() << 4) | (self.two.as_bits() << 4)
| (self.three.as_bits() << 6) | (self.three.as_bits() << 6)
} }
pub(super) fn map_bits(&self, lsb: bool, msb: bool) -> (ColourInner, bool) { pub(super) fn map_bits(self, lsb: bool, msb: bool) -> (ColourInner, bool) {
match (lsb, msb) { match (lsb, msb) {
(true, true) => (self.three, false), (true, true) => (self.three, false),
(true, false) => (self.one, false), (true, false) => (self.one, false),
@ -249,6 +248,7 @@ pub(super) struct Object {
} }
#[derive(Serialize, Deserialize, Clone, Copy, Debug)] #[derive(Serialize, Deserialize, Clone, Copy, Debug)]
#[allow(clippy::struct_excessive_bools)]
pub(super) struct Stat { pub(super) struct Stat {
pub(super) lyc_eq_ly_interrupt_enabled: bool, pub(super) lyc_eq_ly_interrupt_enabled: bool,
pub(super) mode_2_interrupt_enabled: bool, pub(super) mode_2_interrupt_enabled: bool,

View file

@ -11,6 +11,7 @@ pub struct Joypad {
} }
#[derive(Debug, Clone, Copy, PartialEq, Default)] #[derive(Debug, Clone, Copy, PartialEq, Default)]
#[allow(clippy::struct_excessive_bools)]
pub struct JoypadState { pub struct JoypadState {
pub down: bool, pub down: bool,
pub up: bool, pub up: bool,

View file

@ -18,7 +18,7 @@ impl Default for OamDma {
} }
impl OamDma { impl OamDma {
pub(crate) fn get_register(&self) -> u8 { pub(crate) fn get_register(self) -> u8 {
self.addr self.addr
} }
@ -27,7 +27,7 @@ impl OamDma {
self.addr = data; self.addr = data;
} }
pub(crate) fn is_active(&self) -> bool { pub(crate) fn is_active(self) -> bool {
self.progress.is_some() self.progress.is_some()
} }
} }

View file

@ -67,7 +67,7 @@ const BYTE_DELAY: usize = 2000;
const CLOCK_DIV: usize = CLOCK_SPEED / 8192; const CLOCK_DIV: usize = CLOCK_SPEED / 8192;
impl InputByte { impl InputByte {
fn advance(&mut self, rx: &Option<Receiver<u8>>) -> u8 { fn advance(&mut self, rx: Option<&Receiver<u8>>) -> u8 {
if let Some(byte) = self.byte { if let Some(byte) = self.byte {
let val = (byte >> (7 - self.progress)) & 0b1; let val = (byte >> (7 - self.progress)) & 0b1;
self.progress += 1; self.progress += 1;
@ -83,7 +83,7 @@ impl InputByte {
} }
} }
fn try_fill(&mut self, rx: &Option<Receiver<u8>>) -> Option<u8> { fn try_fill(&mut self, rx: Option<&Receiver<u8>>) -> Option<u8> {
self.byte = None; self.byte = None;
self.progress = 0; self.progress = 0;
if let Some(rx) = rx { if let Some(rx) = rx {
@ -96,7 +96,7 @@ impl InputByte {
None None
} }
fn is_ready(&mut self, rx: &Option<Receiver<u8>>) -> bool { fn is_ready(&mut self, rx: Option<&Receiver<u8>>) -> bool {
if self.byte.is_none() { if self.byte.is_none() {
self.try_fill(rx); self.try_fill(rx);
} }
@ -139,9 +139,9 @@ impl Serial {
return false; return false;
} }
let rx = if let SerialTarget::Custom { rx, tx: _ } = &self.target { let rx = if let SerialTarget::Custom { rx, tx: _ } = &self.target {
rx rx.as_ref()
} else { } else {
&None None
}; };
for _ in 0..steps { for _ in 0..steps {
#[cfg(feature = "clocked-serial")] #[cfg(feature = "clocked-serial")]
@ -212,11 +212,7 @@ impl Serial {
pub fn get_control(&self) -> u8 { pub fn get_control(&self) -> u8 {
0b01111110 0b01111110
| (if self.control.transfer_in_progress { | (u8::from(self.control.transfer_in_progress) << 7)
0b1
} else {
0b0
} << 7)
| match self.control.clock_source { | match self.control.clock_source {
ClockSource::Internal => 0b1, ClockSource::Internal => 0b1,
ClockSource::External => 0b0, ClockSource::External => 0b0,

View file

@ -20,7 +20,7 @@ impl TimerRate {
} }
} }
fn as_bits(&self) -> u8 { fn as_bits(self) -> u8 {
match self { match self {
TimerRate::Sixteen => 0b01, TimerRate::Sixteen => 0b01,
TimerRate::SixtyFour => 0b10, TimerRate::SixtyFour => 0b10,
@ -29,7 +29,7 @@ impl TimerRate {
} }
} }
fn as_num(&self) -> usize { fn as_num(self) -> usize {
match self { match self {
TimerRate::Sixteen => 16, TimerRate::Sixteen => 16,
TimerRate::SixtyFour => 64, TimerRate::SixtyFour => 64,

View file

@ -134,9 +134,10 @@ pub enum LicenseeCode {
} }
impl LicenseeCode { impl LicenseeCode {
#[must_use] pub fn from_header(old_licensee_code: u8, new_code: [u8; 2]) -> Self { #[must_use]
#[allow(clippy::match_same_arms)]
pub fn from_header(old_licensee_code: u8, new_code: [u8; 2]) -> Self {
match old_licensee_code { match old_licensee_code {
0x00 => Self::None,
0x01 => Self::Nintendo, 0x01 => Self::Nintendo,
0x08 => Self::Capcom, 0x08 => Self::Capcom,
0x09 => Self::HotB, 0x09 => Self::HotB,

View file

@ -35,7 +35,7 @@ struct Rtc {
} }
impl Rtc { impl Rtc {
fn get_register(&self, rtc_register: &RtcRegister) -> u8 { fn get_register(&self, rtc_register: RtcRegister) -> u8 {
let time = self.latched_time.unwrap_or(Instant::now()) - self.base_time; let time = self.latched_time.unwrap_or(Instant::now()) - self.base_time;
match rtc_register { match rtc_register {
RtcRegister::Seconds => (time.as_secs() % 60) as u8, RtcRegister::Seconds => (time.as_secs() % 60) as u8,
@ -49,17 +49,22 @@ impl Rtc {
} }
} }
fn set_register(&mut self, rtc_register: &RtcRegister, data: u8) { fn set_register(&mut self, rtc_register: RtcRegister, data: u8) {
let seconds_offset = match rtc_register { let seconds_offset = match rtc_register {
RtcRegister::Seconds => i64::from(data) - i64::from(self.get_register(&RtcRegister::Seconds)), RtcRegister::Seconds => {
i64::from(data) - i64::from(self.get_register(RtcRegister::Seconds))
}
RtcRegister::Minutes => { RtcRegister::Minutes => {
(i64::from(data) - i64::from(self.get_register(&RtcRegister::Minutes))) * 60 (i64::from(data) - i64::from(self.get_register(RtcRegister::Minutes))) * 60
} }
RtcRegister::Hours => { RtcRegister::Hours => {
(i64::from(data) - i64::from(self.get_register(&RtcRegister::Hours))) * 60 * 60 (i64::from(data) - i64::from(self.get_register(RtcRegister::Hours))) * 60 * 60
} }
RtcRegister::DayCounterLsb => { RtcRegister::DayCounterLsb => {
(i64::from(data) - i64::from(self.get_register(&RtcRegister::DayCounterLsb))) * 60 * 60 * 24 (i64::from(data) - i64::from(self.get_register(RtcRegister::DayCounterLsb)))
* 60
* 60
* 24
} }
RtcRegister::Misc => 0, RtcRegister::Misc => 0,
}; };
@ -148,7 +153,7 @@ impl Mbc for Mbc3 {
} }
RamBank::Rtc(rtc_register) => { RamBank::Rtc(rtc_register) => {
if let Some(rtc) = &self.rtc { if let Some(rtc) = &self.rtc {
return rtc.get_register(rtc_register); return rtc.get_register(*rtc_register);
} }
} }
} }
@ -205,7 +210,7 @@ impl Mbc for Mbc3 {
} }
RamBank::Rtc(rtc_register) => { RamBank::Rtc(rtc_register) => {
if let Some(ref mut rtc) = self.rtc { if let Some(ref mut rtc) = self.rtc {
rtc.set_register(rtc_register, data); rtc.set_register(*rtc_register, data);
} }
} }
} }

View file

@ -72,7 +72,7 @@ where
fn get_cam_reg(&self, address: CartRamAddress) -> u8 { fn get_cam_reg(&self, address: CartRamAddress) -> u8 {
match address.inner() { match address.inner() {
0xA000 => (if self.camera.is_capturing() { 0x1 } else { 0x0 }) | self.extra_bits_a000, 0xA000 => u8::from(self.camera.is_capturing()) | self.extra_bits_a000,
0xA001..=0xA035 => self.camera_ram[(address.inner() - 0xA001) as usize], 0xA001..=0xA035 => self.camera_ram[(address.inner() - 0xA001) as usize],
_ => 0x00, _ => 0x00,
} }

View file

@ -20,6 +20,7 @@ pub(crate) enum Direction {
Right, Right,
} }
#[allow(clippy::struct_excessive_bools)]
pub struct Cpu<ColourFormat> pub struct Cpu<ColourFormat>
where where
ColourFormat: From<Colour> + Copy, ColourFormat: From<Colour> + Copy,

View file

@ -164,3 +164,8 @@ pub fn scale_buffer_in_place<T: From<Colour> + Copy>(
} }
} }
} }
pub(crate) fn boxed_array<T: Copy, const SIZE: usize>(default: T) -> Box<[T; SIZE]> {
let temp = vec![default; SIZE].into_boxed_slice();
unsafe { Box::from_raw(Box::into_raw(temp).cast::<[T; SIZE]>()) }
}

View file

@ -8,7 +8,7 @@ pub enum Platform {
} }
impl Platform { impl Platform {
pub fn as_cargo(&self) -> cfg_expr::targets::Os { pub fn as_cargo(self) -> cfg_expr::targets::Os {
match self { match self {
Platform::Windows => cfg_expr::targets::Os::windows, Platform::Windows => cfg_expr::targets::Os::windows,
Platform::Linux => cfg_expr::targets::Os::linux, Platform::Linux => cfg_expr::targets::Os::linux,
@ -58,7 +58,7 @@ pub enum Architecture {
} }
impl Architecture { impl Architecture {
pub fn as_cargo(&self) -> cfg_expr::targets::Arch { pub fn as_cargo(self) -> cfg_expr::targets::Arch {
match self { match self {
Architecture::Aarch64 => cfg_expr::targets::Arch::aarch64, Architecture::Aarch64 => cfg_expr::targets::Arch::aarch64,
Architecture::X86_64 => cfg_expr::targets::Arch::x86_64, Architecture::X86_64 => cfg_expr::targets::Arch::x86_64,