clippy: automatic fixes

This commit is contained in:
Alex Janka 2024-11-19 10:16:32 +11:00
parent 0cb78d5a8f
commit bc8da0212d
30 changed files with 118 additions and 126 deletions

View file

@ -55,11 +55,11 @@ pub struct Debugger {
}
impl Debugger {
pub fn new(core: Box<dyn EmulatorCoreTrait>) -> Self {
#[must_use] pub fn new(core: Box<dyn EmulatorCoreTrait>) -> Self {
Self {
core,
stepping: true,
last_command: String::from(""),
last_command: String::new(),
watches: HashMap::new(),
breakpoints: Vec::new(),
}
@ -77,7 +77,7 @@ impl Debugger {
let mut line = String::new();
line = match io::stdin().read_line(&mut line) {
Ok(_) => line,
Err(_) => String::from(""),
Err(_) => String::new(),
};
if line.trim().is_empty() {
line = self.last_command.clone();
@ -95,7 +95,7 @@ impl Debugger {
Commands::Continue => self.stepping = false,
Commands::Break(address) => {
if !self.breakpoints.contains(&address) {
self.breakpoints.push(address)
self.breakpoints.push(address);
}
}
}
@ -116,7 +116,7 @@ impl Debugger {
should_pause = true;
println!("Memory at 0x{address:0>4X} changed:");
println!(" from 0b{0:0>8b}/0x{0:0>2X}", *data);
println!(" to 0b{0:0>8b}/0x{0:0>2X}", new_data);
println!(" to 0b{new_data:0>8b}/0x{new_data:0>2X}");
*data = new_data;
}
}

View file

@ -77,7 +77,7 @@ pub struct RunOptions {
}
impl RunOptions {
pub fn new(rom: PathBuf) -> Self {
#[must_use] pub fn new(rom: PathBuf) -> Self {
Self {
rom,
save: SramType::Auto,

View file

@ -60,7 +60,7 @@ where
Backend: RendererBackend,
<Backend as RendererBackend>::RendererError: Sync + Send + 'static,
{
pub fn new(
#[must_use] pub fn new(
sender: Sender<EmulatorMessage<[u8; 4]>>,
_stream: Stream,
record_main: bool,

View file

@ -22,7 +22,7 @@ impl Default for VstConfig {
fn default() -> Self {
Self {
scale_factor: 3,
rom: String::from(""),
rom: String::new(),
force_skip_bootrom: true,
}
}

View file

@ -346,7 +346,7 @@ impl Plugin for GameboyEmu {
if let Ok(comms) = self.emu_comms.lock() {
if let Some(ref comms) = *comms {
match comms.sender.send(EmulatorMessage::Exit) {
Ok(_) => self.vars = None,
Ok(()) => self.vars = None,
Err(e) => nih_log!("error {e} sending message to emulator"),
}
}

View file

@ -222,7 +222,7 @@ impl WindowHandler for TwincEditorWindow {
self.joypad_state,
),
) {
Ok(_) => {}
Ok(()) => {}
Err(e) => nih_error!("error sending joypad update: {e:#?}"),
}
}

View file

@ -81,7 +81,7 @@ impl ObjectImpl for GameListWindow {
.and_then(move |v| v.downcast::<GameListEntryObject>().ok())
.unwrap()
.path()
)
);
});
}
}

View file

@ -33,24 +33,22 @@ impl ConfigManager {
})
}
pub fn dir(&self) -> PathBuf {
#[must_use] pub fn dir(&self) -> PathBuf {
self.path.clone()
}
pub fn load_or_create_base_config(&self) -> Config {
#[must_use] pub fn load_or_create_base_config(&self) -> Config {
self.load_or_create_config()
}
pub fn load_or_create_config<C>(&self) -> C
#[must_use] pub fn load_or_create_config<C>(&self) -> C
where
C: NamedConfig + Serialize + DeserializeOwned + Default + Clone,
{
match self.load_custom_config::<C>() {
Some(v) => {
if let Some(v) = self.load_custom_config::<C>() {
let _ = self.save_custom_config(v.clone());
v
}
None => {
} else {
let config = C::default();
if let Ok(true) = self.path.join(C::name()).try_exists() {
log::error!(
@ -66,9 +64,8 @@ impl ConfigManager {
config
}
}
}
pub fn load_custom_config<C>(&self) -> Option<C>
#[must_use] pub fn load_custom_config<C>(&self) -> Option<C>
where
C: NamedConfig + DeserializeOwned + Default,
{

View file

@ -84,7 +84,7 @@ pub enum RendererMessage<Format: From<Colour>> {
}
impl<Format: From<Colour>> RendererMessage<Format> {
pub fn display_message(buffer: Vec<Format>) -> Self {
#[must_use] pub fn display_message(buffer: Vec<Format>) -> Self {
Self::Display { buffer }
}
}
@ -105,7 +105,7 @@ pub struct AudioOutput {
}
impl AudioOutput {
pub fn new(
#[must_use] pub fn new(
sample_rate: f32,
buffers_per_frame: usize,
downsample_type: DownsampleType,
@ -190,12 +190,9 @@ where
#[allow(unused)]
pub(crate) fn tick(&mut self, steps: usize) {
if self.counter > 0 {
self.counter = match self.counter.checked_sub(steps) {
Some(num) => num,
None => {
self.counter = if let Some(num) = self.counter.checked_sub(steps) { num } else {
self.next_image = Some(self.inner.get_image());
0
}
};
}
}
@ -242,7 +239,7 @@ impl<ColourFormat> EmulatorOptions<ColourFormat>
where
ColourFormat: From<Colour> + Copy,
{
pub fn new(
#[must_use] pub fn new(
window: Option<Sender<RendererMessage<ColourFormat>>>,
rom: Rom,
output: AudioOutput,
@ -298,37 +295,37 @@ where
self
}
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
}
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
}
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
}
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
}
pub fn with_stdout(mut self) -> Self {
#[must_use] pub fn with_stdout(mut self) -> Self {
self.serial_target = SerialTarget::Stdout(StdoutType::Ascii);
self
}
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
}
pub fn with_tile_window(
#[must_use] pub fn with_tile_window(
mut self,
window: Option<Sender<RendererMessage<ColourFormat>>>,
) -> Self {
@ -336,7 +333,7 @@ where
self
}
pub fn with_layer_window(
#[must_use] pub fn with_layer_window(
mut self,
window: Option<Sender<RendererMessage<ColourFormat>>>,
) -> Self {
@ -344,7 +341,7 @@ where
self
}
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
}

View file

@ -67,7 +67,7 @@ where
rom.mbc_type(),
if is_cgb_mode { "CGB" } else { "DMG" }
),
})?
})?;
}
Ok(Self::new(
@ -167,7 +167,7 @@ where
EmulatorMessage::Start => self.paused = false,
EmulatorMessage::Pause => self.paused = true,
EmulatorMessage::JoypadUpdate(new_state) => {
self.cpu.next_joypad_state = Some(new_state)
self.cpu.next_joypad_state = Some(new_state);
}
EmulatorMessage::NewLayerWindow(new) => self.cpu.memory.gpu.set_layer_window(new),
EmulatorMessage::NewTileWindow(new) => self.cpu.memory.gpu.set_tile_window(new),

View file

@ -103,9 +103,9 @@ where
pub(crate) fn set_or_clear_flag(&mut self, flag: Flags, state: bool) {
if state {
self.set_flag(flag)
self.set_flag(flag);
} else {
self.clear_flag(flag)
self.clear_flag(flag);
}
}

View file

@ -218,7 +218,7 @@ where
Address::Prohibited(_) => 0xFF,
Address::Io(address) => self.get_io(address),
Address::Hram(address) => self.cpu_ram[address.get_local() as usize],
Address::InterruptEnable(_) => self.interrupts.get_enable_register(),
Address::InterruptEnable(()) => self.interrupts.get_enable_register(),
}
}
@ -253,25 +253,25 @@ where
Address::CartRam(address) => self.rom.set_ram(address, data),
Address::WorkRam(address) => self.ram.bank_0[address.get_local() as usize] = data,
Address::BankedWorkRam(address) => {
self.ram.set_banked(address.get_local() as usize, data)
self.ram.set_banked(address.get_local() as usize, data);
}
Address::MirroredWorkRam(address) => {
self.ram.bank_0[address.get_local() as usize] = data
self.ram.bank_0[address.get_local() as usize] = data;
}
Address::MirroredBankedWorkRam(address) => {
self.ram.set_banked(address.get_local() as usize, data)
self.ram.set_banked(address.get_local() as usize, data);
}
Address::Oam(address) => self.gpu.set_oam(address, data),
Address::Prohibited(_) => {}
Address::Io(address) => {
if address.inner() == 0xFF50 {
self.bootrom = None
self.bootrom = None;
} else {
self.set_io(address, data)
self.set_io(address, data);
}
}
Address::Hram(address) => self.cpu_ram[address.get_local() as usize] = data,
Address::InterruptEnable(_) => self.interrupts.set_enable_register(data),
Address::InterruptEnable(()) => self.interrupts.set_enable_register(data),
}
}
@ -380,7 +380,7 @@ where
CgbIoAddress::PrepareSpeed => cgb_peripherals.double_speed.set(data),
CgbIoAddress::VramBank => self.gpu.vram.set_vram_bank(data),
CgbIoAddress::VramDma(address) => {
cgb_peripherals.vram_dma.set_register(address, data)
cgb_peripherals.vram_dma.set_register(address, data);
}
CgbIoAddress::Infrared => cgb_peripherals.infrared.set(data),
CgbIoAddress::Palette(address) => self.gpu.set_cgb_palette(address, data),
@ -389,7 +389,7 @@ where
CgbIoAddress::Pcm12 => {}
CgbIoAddress::Pcm34 => {}
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

@ -225,7 +225,7 @@ impl AddressMarker for Address {
Address::Prohibited(v) => v.inner(),
Address::Io(v) => v.inner(),
Address::Hram(v) => v.inner(),
Address::InterruptEnable(_) => 0xFFFF,
Address::InterruptEnable(()) => 0xFFFF,
}
}
}

View file

@ -32,7 +32,7 @@ impl DacSample {
}
fn mix_channel(&self, sums: f32, volume: u8) -> f32 {
sums * ((volume + 1) as f32 / (8. * 4.))
sums * (f32::from(volume + 1) / (8. * 4.))
}
}

View file

@ -59,10 +59,10 @@ impl Envelope {
self.counter = 0;
match self.mode {
EnvelopeMode::Increase => {
self.current_volume = self.current_volume.saturating_add(1)
self.current_volume = self.current_volume.saturating_add(1);
}
EnvelopeMode::Decrease => {
self.current_volume = self.current_volume.saturating_sub(1)
self.current_volume = self.current_volume.saturating_sub(1);
}
}
}
@ -190,7 +190,7 @@ impl PwmChannel {
fn dac(&mut self, digital: u8) -> f32 {
self.last = digital;
(((digital as f32) * (-2.)) + 1.) * ((self.envelope.current_volume as f32) / 15.)
((f32::from(digital) * (-2.)) + 1.) * (f32::from(self.envelope.current_volume) / 15.)
}
pub(super) fn envelope_tick(&mut self) {
@ -206,7 +206,7 @@ impl PwmChannel {
self.sweep.counter += 1;
if self.sweep.counter % self.sweep.pace == 0 {
self.sweep.counter = 0;
let wavelength_diff = self.wavelength / (2_u16.pow(self.sweep.slope as u32));
let wavelength_diff = self.wavelength / (2_u16.pow(u32::from(self.sweep.slope)));
let new_wavelength = match self.sweep.mode {
EnvelopeMode::Increase => self.wavelength + wavelength_diff,
EnvelopeMode::Decrease => self.wavelength.saturating_sub(wavelength_diff),
@ -280,13 +280,13 @@ impl PwmChannel {
}
pub(super) fn update_wavelength_low(&mut self, data: u8) {
self.wavelength = (self.wavelength & 0xFF00) | (data as u16);
self.wavelength = (self.wavelength & 0xFF00) | u16::from(data);
self.set_wave_timer();
}
pub(super) fn update_wavelength_high_and_control(&mut self, data: u8) {
self.length_enable = get_bit(data, 6);
self.wavelength = (self.wavelength & 0xFF) | (((data & 0b111) as u16) << 8);
self.wavelength = (self.wavelength & 0xFF) | (u16::from(data & 0b111) << 8);
self.set_wave_timer();
if get_bit(data, 7) {
self.trigger();
@ -404,7 +404,7 @@ impl WaveChannel {
fn dac(&mut self, digital: u8) -> f32 {
if self.dac_enabled && self.volume != ShiftVolumePercent::Zero {
self.last = digital;
((((digital >> self.volume.as_shift_amount()) as f32) * (-2.)) + 1.) / 15.
((f32::from(digital >> self.volume.as_shift_amount()) * (-2.)) + 1.) / 15.
} else {
self.last = 0;
0.
@ -453,13 +453,13 @@ impl WaveChannel {
}
pub(super) fn update_wavelength_low(&mut self, data: u8) {
self.wavelength = (self.wavelength & 0xFF00) | (data as u16);
self.wavelength = (self.wavelength & 0xFF00) | u16::from(data);
self.set_wave_timer();
}
pub(super) fn update_wavelength_high_and_control(&mut self, data: u8) {
self.length_enable = get_bit(data, 6);
self.wavelength = (self.wavelength & 0xFF) | (((data & 0b111) as u16) << 8);
self.wavelength = (self.wavelength & 0xFF) | (u16::from(data & 0b111) << 8);
self.set_wave_timer();
if get_bit(data, 7) {
self.trigger();
@ -472,9 +472,7 @@ impl WaveChannel {
pub(super) fn update_wave_ram(&mut self, addr: WaveRamAddress, data: u8) {
let real_addr = addr.get_local() as usize;
if real_addr >= self.wave_ram.data.len() {
panic!("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;
}
@ -506,8 +504,8 @@ struct Lfsr {
impl Lfsr {
fn update(&mut self) {
self.interval = (1_u16 << (self.clock_shift as u16))
.wrapping_mul(1 + (2 * self.clock_divider as u16))
self.interval = (1_u16 << u16::from(self.clock_shift))
.wrapping_mul(1 + (2 * u16::from(self.clock_divider)))
.wrapping_mul(8);
}
@ -601,7 +599,7 @@ impl NoiseChannel {
fn dac(&mut self, digital: u8) -> f32 {
self.last = digital;
(((digital as f32) * (-2.)) + 1.) * ((self.envelope.current_volume as f32) / 15.)
((f32::from(digital) * (-2.)) + 1.) * (f32::from(self.envelope.current_volume) / 15.)
}
pub(super) fn envelope_tick(&mut self) {

View file

@ -88,7 +88,7 @@ where
let returning = if let Some(cgb_peripherals) = &mut self.cgb_peripherals {
match cgb_peripherals.vram_dma.mode {
DmaMode::Halt(l) => {
let length = 16 * ((l as u16) + 1);
let length = 16 * (u16::from(l) + 1);
copy = Some((
cgb_peripherals.vram_dma.source,
cgb_peripherals.vram_dma.destination,
@ -109,7 +109,7 @@ where
cgb_peripherals.vram_dma.source += length;
cgb_peripherals.vram_dma.destination += length;
*progress += 1;
if *progress > (l as u16) {
if *progress > u16::from(l) {
cgb_peripherals.vram_dma.mode = DmaMode::Waiting;
cgb_peripherals.vram_dma.reset_registers();
}

View file

@ -192,7 +192,7 @@ where
|| (self.stat.vblank_interrupt_enabled && (self.stat.mode == DrawMode::VBlank))
|| (self.stat.hblank_interrupt_enabled && (self.stat.mode == DrawMode::HBlank));
interrupts.lcd_stat = this_stat & !self.prev_stat;
interrupts.lcd_stat = this_stat && !self.prev_stat;
self.prev_stat = this_stat;
interrupts
}
@ -202,7 +202,7 @@ where
}
pub(crate) fn set_vram(&mut self, address: VramAddress, data: u8) {
self.vram.set(address, data)
self.vram.set(address, data);
}
pub(crate) fn get_oam(&self, address: OamAddress) -> u8 {
@ -215,7 +215,7 @@ where
pub(crate) fn set_oam(&mut self, address: OamAddress, data: u8) {
if self.stat.mode == DrawMode::VBlank || self.stat.mode == DrawMode::HBlank {
self.oam.set(address, data)
self.oam.set(address, data);
}
}
@ -359,7 +359,7 @@ where
let tile_row = object_row % 8;
let tile_addr = (TiledataArea::D8000
.get_addr(object.tile_index + if object_row >= 8 { 1 } else { 0 })
+ (tile_row as u16 * 2))
+ (u16::from(tile_row) * 2))
.unwrap();
let bank = if self.is_cgb_mode() {
object.flags.cgb_vram_bank
@ -416,7 +416,7 @@ where
layer_window.set(
buffer_index + (2 * HEIGHT * WIDTH),
colour.rgb_bytes(cgb_data).into(),
)
);
}
}
}
@ -443,7 +443,7 @@ where
continue;
}
let tilemap_column = (tile_line_x / 8) as u16;
let tilemap_column = u16::from(tile_line_x / 8);
let tilemap_addr = tilemap.get_addr(row_addr + (tilemap_column));
let attributes = if self.is_cgb_mode() {
@ -465,7 +465,7 @@ where
self.vram
.get_with_bank(tilemap_addr, VramBank::Bank0)
.unwrap(),
) + tiledata_offset as u16)
) + u16::from(tiledata_offset))
.unwrap();
let lsbs = self
@ -503,7 +503,7 @@ where
layer_window.set(
(scanline as usize * WIDTH) + x + if is_bg { 0 } else { HEIGHT * WIDTH },
colour.rgb_bytes(cgb_data).into(),
)
);
}
}
}

View file

@ -68,7 +68,7 @@ impl CgbPalette {
fn set_data(&mut self, data: u8) {
self.data[self.index as usize] = data;
if self.auto_increment {
self.index = (self.index + 1) & 0b111111
self.index = (self.index + 1) & 0b111111;
}
}

View file

@ -41,7 +41,7 @@ where
.sender
.send(RendererMessage::display_message(new_buffer))
{
Ok(_) => {
Ok(()) => {
for val in self.buffer.iter_mut() {
*val = get_blank_colour(cgb);
}

View file

@ -79,7 +79,7 @@ where
.sender
.send(RendererMessage::display_message(self.buffer.clone()))
{
Ok(_) => Some(self),
Ok(()) => Some(self),
Err(_) => None,
}
}

View file

@ -41,9 +41,9 @@ pub(super) enum TiledataArea {
impl TiledataArea {
pub(super) fn get_addr(&self, addr: u8) -> VramAddress {
match self {
TiledataArea::D8000 => (0x8000 + ((addr as u16) * 16)).try_into().unwrap(),
TiledataArea::D8000 => (0x8000 + (u16::from(addr) * 16)).try_into().unwrap(),
TiledataArea::D9000 => 0x9000_u16
.wrapping_add_signed((as_signed(addr) as i16) * 16)
.wrapping_add_signed(i16::from(as_signed(addr)) * 16)
.try_into()
.unwrap(),
}
@ -105,7 +105,7 @@ pub struct Colour(pub u8, pub u8, pub u8);
impl From<Colour> for u32 {
fn from(value: Colour) -> Self {
let (r, g, b) = (value.0 as u32, value.1 as u32, value.2 as u32);
let (r, g, b) = (u32::from(value.0), u32::from(value.1), u32::from(value.2));
(r << 16) | (g << 8) | b
}
}
@ -335,7 +335,7 @@ impl Vram {
match self {
Vram::Dmg { inner } => inner[address.get_local() as usize] = data,
Vram::Cgb { inner, index } => {
inner[*index as usize][address.get_local() as usize] = data
inner[*index as usize][address.get_local() as usize] = data;
}
}
}

View file

@ -119,7 +119,7 @@ pub enum RomSize {
}
impl RomSize {
pub fn from(val: u8) -> Option<Self> {
#[must_use] pub fn from(val: u8) -> Option<Self> {
match val {
0x00 => Some(Self::B2),
0x01 => Some(Self::B4),
@ -137,7 +137,7 @@ impl RomSize {
}
}
pub fn size_bytes(&self) -> usize {
#[must_use] pub fn size_bytes(&self) -> usize {
(match self {
RomSize::B2 => 2,
RomSize::B4 => 4,
@ -177,7 +177,7 @@ impl RamSize {
}
}
pub fn size_bytes(&self) -> usize {
#[must_use] pub fn size_bytes(&self) -> usize {
match self {
RamSize::B2 => 2 * KB,
RamSize::B8 => 8 * KB,
@ -370,7 +370,7 @@ impl Rom {
}
}
pub fn get_title(&self) -> &String {
#[must_use] pub fn get_title(&self) -> &String {
&self.title
}
@ -398,7 +398,7 @@ impl Rom {
self.mbc.can_rumble()
}
pub fn mbc_type(&self) -> String {
#[must_use] pub fn mbc_type(&self) -> String {
self.mbc.mbc_type()
}

View file

@ -134,7 +134,7 @@ pub enum LicenseeCode {
}
impl LicenseeCode {
pub fn from_header(old_licensee_code: u8, new_code: [u8; 2]) -> Self {
#[must_use] pub fn from_header(old_licensee_code: u8, new_code: [u8; 2]) -> Self {
match old_licensee_code {
0x00 => Self::None,
0x01 => Self::Nintendo,

View file

@ -51,15 +51,15 @@ impl Rtc {
fn set_register(&mut self, rtc_register: &RtcRegister, data: u8) {
let seconds_offset = match rtc_register {
RtcRegister::Seconds => data as i64 - self.get_register(&RtcRegister::Seconds) as i64,
RtcRegister::Seconds => i64::from(data) - i64::from(self.get_register(&RtcRegister::Seconds)),
RtcRegister::Minutes => {
(data as i64 - self.get_register(&RtcRegister::Minutes) as i64) * 60
(i64::from(data) - i64::from(self.get_register(&RtcRegister::Minutes))) * 60
}
RtcRegister::Hours => {
(data as i64 - self.get_register(&RtcRegister::Hours) as i64) * 60 * 60
(i64::from(data) - i64::from(self.get_register(&RtcRegister::Hours))) * 60 * 60
}
RtcRegister::DayCounterLsb => {
(data as i64 - self.get_register(&RtcRegister::DayCounterLsb) as i64) * 60 * 60 * 24
(i64::from(data) - i64::from(self.get_register(&RtcRegister::DayCounterLsb))) * 60 * 60 * 24
}
RtcRegister::Misc => 0,
};
@ -112,7 +112,7 @@ impl Mbc3 {
rom_size: rom_size.size_bytes(),
ram,
ram_bank: RamBank::Ram(0),
ram_size: ram_size.map(|s| s.size_bytes()).unwrap_or(0),
ram_size: ram_size.map_or(0, |s| s.size_bytes()),
ram_enabled: false,
rtc: if rtc { Some(Rtc::default()) } else { None },
}

View file

@ -40,7 +40,7 @@ impl Mbc5 {
rom_size: rom_size.size_bytes(),
ram,
ram_bank: 0,
ram_size: ram_size.map(|s| s.size_bytes()).unwrap_or(0),
ram_size: ram_size.map_or(0, |s| s.size_bytes()),
ram_enabled: false,
rumble,
is_rumbling: false,
@ -82,14 +82,14 @@ impl Mbc for Mbc5 {
0x0..0x2000 => {
self.ram_enabled = (data & 0xF) == 0xA;
}
0x2000..0x3000 => self.rom_bank = (self.rom_bank & 0x100) | (data as u16),
0x3000..0x4000 => self.rom_bank = (self.rom_bank & 0xFF) | ((data as u16 & 0b1) << 8),
0x2000..0x3000 => self.rom_bank = (self.rom_bank & 0x100) | u16::from(data),
0x3000..0x4000 => self.rom_bank = (self.rom_bank & 0xFF) | ((u16::from(data) & 0b1) << 8),
0x4000..0x6000 => {
if self.rumble {
self.is_rumbling = get_bit(data, 3);
self.ram_bank = data & 0x7;
} else {
self.ram_bank = data & 0xF
self.ram_bank = data & 0xF;
}
}
0x6000..0x8000 => {}

View file

@ -133,7 +133,7 @@ where
}
0x2000..0x4000 => {
if data < 0x40 {
self.rom_bank = data
self.rom_bank = data;
}
}
0x4000..0x6000 => {

View file

@ -223,10 +223,10 @@ impl SplitRegister for u16 {
}
fn set_low(&mut self, val: u8) {
*self = (*self & !0xff) | val as u16;
*self = (*self & !0xff) | u16::from(val);
}
fn set_high(&mut self, val: u8) {
*self = (*self & !0xff00) | (val as u16) << 8;
*self = (*self & !0xff00) | u16::from(val) << 8;
}
}

View file

@ -1,6 +1,6 @@
use clap::Parser;
use crate::types::*;
use crate::types::{Architecture, Binary, Platform, Renderer};
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]

View file

@ -1,8 +1,8 @@
use clap::Parser;
use strum::IntoEnumIterator;
use args::*;
use types::*;
use args::{Args, BuildArgs, Commands, RunArgs};
use types::{Architecture, Binary, CouldntSetOnceLock, Platform, Renderer, get_triple};
mod args;
mod types;
@ -295,7 +295,7 @@ fn cargo_exec(
println!("Building {package} with {renderer} renderer for target {triple}");
let args=format!("{verb} -q -p {package} --target {triple} {release} --no-default-features -F {renderer} --message-format=json-render-diagnostics");
let args = args.split_whitespace().map(|s| s.to_string());
let args = args.split_whitespace().map(std::string::ToString::to_string);
let args = if let Some(additional_flags) = additional_flags {
args.chain(additional_flags).collect::<Vec<_>>()
} else {
@ -338,8 +338,8 @@ fn cargo_exec(
Ok(
cargo_metadata::Message::parse_stream(std::io::BufReader::new(output)).inspect(move |v| {
match v {
Ok(cargo_metadata::Message::BuildScriptExecuted(_))
| Ok(cargo_metadata::Message::CompilerArtifact(_)) => {
Ok(cargo_metadata::Message::BuildScriptExecuted(_) |
cargo_metadata::Message::CompilerArtifact(_)) => {
if let Some(pb) = pb.as_mut() {
pb.inc();
}
@ -382,7 +382,7 @@ fn build_vst(
}
// we need the &str to live for this whole function
let triple_str = triple.map(|t| t.to_string());
let triple_str = triple.map(std::string::ToString::to_string);
if platform != Platform::Mac {
args.push("--target");
args.push(triple_str.as_ref().unwrap().as_str());
@ -428,8 +428,8 @@ fn build_vst(
for v in cargo_metadata::Message::parse_stream(std::io::BufReader::new(output)) {
match v {
Ok(cargo_metadata::Message::BuildScriptExecuted(_))
| Ok(cargo_metadata::Message::CompilerArtifact(_)) => {
Ok(cargo_metadata::Message::BuildScriptExecuted(_) |
cargo_metadata::Message::CompilerArtifact(_)) => {
if pb.as_ref().is_some_and(|pb| pb.is_finish) {
pb = build_plan_iter.next().map(|(arch, num)| {
let mut pb = pbr::ProgressBar::new(num.try_into().unwrap());

View file

@ -131,7 +131,7 @@ impl std::error::Error for CouldntSetOnceLock {
None
}
fn description(&self) -> &str {
fn description(&self) -> &'static str {
"description() is deprecated; use Display"
}