manual clippy fixes
This commit is contained in:
parent
bc8da0212d
commit
1e4a478d1f
|
@ -54,6 +54,7 @@ impl From<SerialTargetOption> for SerialTarget {
|
|||
#[command(author, version, about, long_about = None)]
|
||||
#[command(group(ArgGroup::new("saves").args(["save","no_save"])))]
|
||||
#[command(subcommand_negates_reqs = true)]
|
||||
#[allow(clippy::struct_excessive_bools)]
|
||||
struct Args {
|
||||
#[command(subcommand)]
|
||||
command: Option<Commands>,
|
||||
|
|
|
@ -55,7 +55,8 @@ pub struct Debugger {
|
|||
}
|
||||
|
||||
impl Debugger {
|
||||
#[must_use] pub fn new(core: Box<dyn EmulatorCoreTrait>) -> Self {
|
||||
#[must_use]
|
||||
pub fn new(core: Box<dyn EmulatorCoreTrait>) -> Self {
|
||||
Self {
|
||||
core,
|
||||
stepping: true,
|
||||
|
@ -80,9 +81,9 @@ impl Debugger {
|
|||
Err(_) => String::new(),
|
||||
};
|
||||
if line.trim().is_empty() {
|
||||
line = self.last_command.clone();
|
||||
line.clone_from(&self.last_command);
|
||||
} else {
|
||||
self.last_command = line.clone();
|
||||
self.last_command.clone_from(&line);
|
||||
}
|
||||
if let Ok(command) = Commands::from_str(&line) {
|
||||
match command {
|
||||
|
|
|
@ -65,6 +65,7 @@ fn access_config<'a>() -> &'a Configs {
|
|||
CONFIGS.get().expect("accessed config before it was set!")
|
||||
}
|
||||
|
||||
#[allow(clippy::struct_excessive_bools)]
|
||||
pub struct RunOptions {
|
||||
pub rom: PathBuf,
|
||||
pub save: SramType,
|
||||
|
@ -77,7 +78,8 @@ pub struct RunOptions {
|
|||
}
|
||||
|
||||
impl RunOptions {
|
||||
#[must_use] pub fn new(rom: PathBuf) -> Self {
|
||||
#[must_use]
|
||||
pub fn new(rom: PathBuf) -> Self {
|
||||
Self {
|
||||
rom,
|
||||
save: SramType::Auto,
|
||||
|
|
|
@ -60,9 +60,10 @@ where
|
|||
Backend: RendererBackend,
|
||||
<Backend as RendererBackend>::RendererError: Sync + Send + 'static,
|
||||
{
|
||||
#[must_use] pub fn new(
|
||||
#[must_use]
|
||||
pub fn new(
|
||||
sender: Sender<EmulatorMessage<[u8; 4]>>,
|
||||
_stream: Stream,
|
||||
stream: Stream,
|
||||
record_main: bool,
|
||||
) -> Self {
|
||||
let event_loop = EventLoop::new().unwrap();
|
||||
|
@ -80,7 +81,7 @@ where
|
|||
sender,
|
||||
gamepad_handler: Gilrs::new().unwrap(),
|
||||
joypad_state: Default::default(),
|
||||
_stream,
|
||||
_stream: stream,
|
||||
},
|
||||
record_main,
|
||||
}
|
||||
|
@ -340,11 +341,15 @@ where
|
|||
let window = WindowBuilder::new()
|
||||
.with_title("Gameboy")
|
||||
.with_resizable(resizable);
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
let window = window.with_name("TWINC", "");
|
||||
|
||||
let window = window.build(event_loop)?;
|
||||
|
||||
#[allow(clippy::cast_sign_loss)]
|
||||
let real_factor = (window.scale_factor() * factor as f64) as u32;
|
||||
|
||||
let inner_size = window.inner_size();
|
||||
let resolutions = ResolutionData {
|
||||
real_width: inner_size.width,
|
||||
|
@ -415,8 +420,8 @@ where
|
|||
fn process(&mut self) {
|
||||
while let Ok(message) = self.receiver.try_recv() {
|
||||
match message {
|
||||
RendererMessage::Prepare { width, height } => self.attempt_resize(width, height),
|
||||
RendererMessage::Resize { width, height } => self.attempt_resize(width, height),
|
||||
RendererMessage::Resize { width, height }
|
||||
| RendererMessage::Prepare { width, height } => self.attempt_resize(width, height),
|
||||
RendererMessage::Display { buffer } => self.display(buffer),
|
||||
RendererMessage::SetTitle { title } => self.window.set_title(&title),
|
||||
RendererMessage::Rumble { rumble: _ } => todo!(),
|
||||
|
@ -428,6 +433,7 @@ where
|
|||
self.width = width;
|
||||
self.height = height;
|
||||
|
||||
#[allow(clippy::cast_sign_loss)]
|
||||
let real_factor = (self.window.scale_factor() * self.factor as f64) as u32;
|
||||
|
||||
let real_width = (width as u32) * real_factor;
|
||||
|
|
|
@ -84,6 +84,7 @@ impl Editor for TwincEditor {
|
|||
}
|
||||
|
||||
fn size(&self) -> (u32, u32) {
|
||||
#[allow(clippy::cast_sign_loss)]
|
||||
(self.size.width as u32, self.size.height as u32)
|
||||
}
|
||||
|
||||
|
@ -127,6 +128,7 @@ impl TwincEditorWindow {
|
|||
size: Size,
|
||||
shader_path: Option<std::path::PathBuf>,
|
||||
) -> Self {
|
||||
#[allow(clippy::cast_sign_loss)]
|
||||
let current_resolution = ResolutionData {
|
||||
real_width: size.width as u32,
|
||||
real_height: size.height as u32,
|
||||
|
@ -152,17 +154,17 @@ impl TwincEditorWindow {
|
|||
if let Some(ref comms) = *comms {
|
||||
while let Ok(e) = comms.receiver.try_recv() {
|
||||
match e {
|
||||
RendererMessage::Display { buffer } => self.latest_buf = buffer,
|
||||
RendererMessage::Prepare {
|
||||
width: _,
|
||||
height: _,
|
||||
} => {}
|
||||
RendererMessage::Resize {
|
||||
}
|
||||
| RendererMessage::Resize {
|
||||
width: _,
|
||||
height: _,
|
||||
} => {}
|
||||
RendererMessage::Display { buffer } => self.latest_buf = buffer,
|
||||
RendererMessage::SetTitle { title: _ } => {}
|
||||
RendererMessage::Rumble { rumble: _ } => {}
|
||||
}
|
||||
| RendererMessage::SetTitle { title: _ }
|
||||
| RendererMessage::Rumble { rumble: _ } => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,8 +58,7 @@ impl RomFile {
|
|||
let save_location = match save {
|
||||
SramType::File(path) => Some(SaveDataLocation::File(path)),
|
||||
SramType::RawBuffer(buf) => Some(SaveDataLocation::Raw(buf)),
|
||||
SramType::Auto => None,
|
||||
SramType::None => None,
|
||||
SramType::Auto | SramType::None => None,
|
||||
};
|
||||
Ok(Rom::load(data, save_location))
|
||||
}
|
||||
|
@ -84,7 +83,8 @@ pub enum RendererMessage<Format: From<Colour>> {
|
|||
}
|
||||
|
||||
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 }
|
||||
}
|
||||
}
|
||||
|
@ -105,11 +105,13 @@ pub struct AudioOutput {
|
|||
}
|
||||
|
||||
impl AudioOutput {
|
||||
#[must_use] pub fn new(
|
||||
#[must_use]
|
||||
pub fn new(
|
||||
sample_rate: f32,
|
||||
buffers_per_frame: usize,
|
||||
downsample_type: DownsampleType,
|
||||
) -> (Self, AsyncHeapCons<[f32; 2]>) {
|
||||
#[allow(clippy::cast_sign_loss)]
|
||||
let rb_len = (sample_rate as usize / 60) / buffers_per_frame;
|
||||
|
||||
let rb = AsyncHeapRb::<[f32; 2]>::new(rb_len);
|
||||
|
@ -190,7 +192,9 @@ where
|
|||
#[allow(unused)]
|
||||
pub(crate) fn tick(&mut self, steps: usize) {
|
||||
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());
|
||||
0
|
||||
};
|
||||
|
@ -239,7 +243,8 @@ impl<ColourFormat> EmulatorOptions<ColourFormat>
|
|||
where
|
||||
ColourFormat: From<Colour> + Copy,
|
||||
{
|
||||
#[must_use] pub fn new(
|
||||
#[must_use]
|
||||
pub fn new(
|
||||
window: Option<Sender<RendererMessage<ColourFormat>>>,
|
||||
rom: Rom,
|
||||
output: AudioOutput,
|
||||
|
@ -290,42 +295,50 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn with_sram_buffer(mut self, buffer: Arc<RwLock<Vec<u8>>>) -> Self {
|
||||
self.save = Some(SramType::RawBuffer(buffer));
|
||||
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
|
||||
}
|
||||
|
||||
#[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
|
||||
}
|
||||
|
||||
#[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
|
||||
}
|
||||
|
||||
#[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
|
||||
}
|
||||
|
||||
#[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
|
||||
}
|
||||
|
||||
#[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
|
||||
}
|
||||
|
||||
#[must_use] pub fn with_tile_window(
|
||||
#[must_use]
|
||||
pub fn with_tile_window(
|
||||
mut self,
|
||||
window: Option<Sender<RendererMessage<ColourFormat>>>,
|
||||
) -> Self {
|
||||
|
@ -333,7 +346,8 @@ where
|
|||
self
|
||||
}
|
||||
|
||||
#[must_use] pub fn with_layer_window(
|
||||
#[must_use]
|
||||
pub fn with_layer_window(
|
||||
mut self,
|
||||
window: Option<Sender<RendererMessage<ColourFormat>>>,
|
||||
) -> Self {
|
||||
|
@ -341,7 +355,8 @@ where
|
|||
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
|
||||
}
|
||||
|
|
|
@ -125,7 +125,7 @@ where
|
|||
self.set_or_clear_flag(Flags::Zero, result == 0x0);
|
||||
self.set_or_clear_flag(
|
||||
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
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ impl Wram {
|
|||
bank_0: Box::new([0; 4096]),
|
||||
banks: if cgb {
|
||||
WramBanks::Cgb {
|
||||
banks: Box::new([[0; 4096]; 8]),
|
||||
banks: crate::util::boxed_array([0; 4096]),
|
||||
selected: 0,
|
||||
}
|
||||
} else {
|
||||
|
@ -386,10 +386,11 @@ where
|
|||
CgbIoAddress::Palette(address) => self.gpu.set_cgb_palette(address, data),
|
||||
CgbIoAddress::ObjPriority => self.gpu.set_obj_priority(data),
|
||||
CgbIoAddress::WramBank => *selected = (data & 0b111).max(1) as usize,
|
||||
CgbIoAddress::Pcm12 => {}
|
||||
CgbIoAddress::Pcm34 => {}
|
||||
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}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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> {
|
||||
pub(crate) fn get_local(&self) -> u16 {
|
||||
pub(crate) fn get_local(self) -> u16 {
|
||||
self.0 - MIN
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize};
|
|||
use crate::util::get_bit;
|
||||
|
||||
#[derive(Default, Debug, Copy, Clone, Serialize, Deserialize)]
|
||||
#[allow(clippy::struct_excessive_bools)]
|
||||
struct InterruptRegister {
|
||||
vblank: bool,
|
||||
lcd_stat: bool,
|
||||
|
@ -12,7 +13,7 @@ struct InterruptRegister {
|
|||
}
|
||||
|
||||
impl InterruptRegister {
|
||||
fn as_register(&self) -> u8 {
|
||||
fn as_register(self) -> u8 {
|
||||
bool_to_shifted(self.vblank, 0)
|
||||
| bool_to_shifted(self.lcd_stat, 1)
|
||||
| bool_to_shifted(self.timer, 2)
|
||||
|
@ -30,7 +31,7 @@ impl InterruptRegister {
|
|||
}
|
||||
|
||||
fn bool_to_shifted(input: bool, shift: u8) -> u8 {
|
||||
(if input { 1 } else { 0 }) << shift
|
||||
u8::from(input) << shift
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
|
|
|
@ -37,11 +37,11 @@ impl DacSample {
|
|||
}
|
||||
|
||||
pub struct Apu {
|
||||
apu_enable: bool,
|
||||
enable: bool,
|
||||
channels: Channels,
|
||||
vin: VinEnable,
|
||||
mixer: Mixer,
|
||||
div_apu: u8,
|
||||
div: u8,
|
||||
converter: Downsampler,
|
||||
output: AudioOutput,
|
||||
}
|
||||
|
@ -49,11 +49,11 @@ pub struct Apu {
|
|||
impl Apu {
|
||||
pub fn new(output: AudioOutput) -> Self {
|
||||
Self {
|
||||
apu_enable: true,
|
||||
enable: true,
|
||||
channels: Channels::default(),
|
||||
vin: VinEnable::default(),
|
||||
mixer: Mixer::default(),
|
||||
div_apu: 0,
|
||||
div: 0,
|
||||
converter: Downsampler::new(output.sample_rate, output.downsample_type),
|
||||
output,
|
||||
}
|
||||
|
@ -65,18 +65,18 @@ impl Apu {
|
|||
}
|
||||
|
||||
pub fn div_apu_tick(&mut self) {
|
||||
self.div_apu = self.div_apu.wrapping_add(1);
|
||||
if self.div_apu % 8 == 0 {
|
||||
self.div = self.div.wrapping_add(1);
|
||||
if self.div % 8 == 0 {
|
||||
// envelope sweep
|
||||
self.channels.one.envelope_tick();
|
||||
self.channels.two.envelope_tick();
|
||||
self.channels.four.envelope_tick();
|
||||
}
|
||||
if self.div_apu % 4 == 0 {
|
||||
if self.div % 4 == 0 {
|
||||
// ch1 frequency sweep
|
||||
self.channels.one.frequency_tick();
|
||||
}
|
||||
if self.div_apu % 2 == 0 {
|
||||
if self.div % 2 == 0 {
|
||||
// tick sound length timers
|
||||
self.channels.one.length_tick();
|
||||
self.channels.two.length_tick();
|
||||
|
@ -124,7 +124,7 @@ impl Apu {
|
|||
}
|
||||
|
||||
pub(crate) fn get_register(&self, addr: AudioAddress) -> u8 {
|
||||
if self.apu_enable {
|
||||
if self.enable {
|
||||
self.make_register(addr)
|
||||
} else {
|
||||
match addr.inner() {
|
||||
|
@ -178,11 +178,7 @@ impl Apu {
|
|||
}
|
||||
0xFF26 => {
|
||||
// NR52 - Sound on/off
|
||||
let mut v = if self.apu_enable {
|
||||
0b11111111
|
||||
} else {
|
||||
0b01111111
|
||||
};
|
||||
let mut v = if self.enable { 0b11111111 } else { 0b01111111 };
|
||||
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, 2, self.channels.three.is_dac_enabled());
|
||||
|
@ -190,7 +186,7 @@ impl Apu {
|
|||
v
|
||||
}
|
||||
// write-only registers
|
||||
0xFF13 | 0xFF18 | 0xFF1B | 0xFF1D | 0xFF20 => 0xFF,
|
||||
0xFF13 | 0xFF18 | 0xFF1B | 0xFF1D | 0xFF20 |
|
||||
// not registers
|
||||
0xFF15 | 0xFF1F => 0xFF,
|
||||
0x0..0xFF10 | 0xFF27..=0xFFFF => unreachable!(),
|
||||
|
@ -198,6 +194,7 @@ impl Apu {
|
|||
}
|
||||
|
||||
pub(crate) fn mmio_write(&mut self, addr: AudioAddress, data: u8) {
|
||||
#[allow(clippy::match_same_arms)]
|
||||
match addr.inner() {
|
||||
0xFF10 => self.channels.one.update_sweep(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));
|
||||
}
|
||||
0xFF26 => {
|
||||
if !self.apu_enable {
|
||||
if !self.enable {
|
||||
for i in 0xFF10..0xFF20 {
|
||||
self.mmio_write(i.try_into().unwrap(), 0x0);
|
||||
}
|
||||
|
@ -244,7 +241,7 @@ impl Apu {
|
|||
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!(),
|
||||
}
|
||||
|
|
|
@ -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];
|
||||
|
||||
impl DutyCycle {
|
||||
fn get_waveform(&self, index: usize) -> u8 {
|
||||
fn get_waveform(self, index: usize) -> u8 {
|
||||
match self {
|
||||
DutyCycle::TwelvePointFive => TWELVE_POINT_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 {
|
||||
DutyCycle::TwelvePointFive => 0b00,
|
||||
DutyCycle::TwentyFive => 0b01,
|
||||
|
@ -315,7 +315,7 @@ enum ShiftVolumePercent {
|
|||
}
|
||||
|
||||
impl ShiftVolumePercent {
|
||||
fn as_shift_amount(&self) -> u8 {
|
||||
fn as_shift_amount(self) -> u8 {
|
||||
match self {
|
||||
ShiftVolumePercent::Zero => 8,
|
||||
ShiftVolumePercent::TwentyFive => 2,
|
||||
|
@ -472,7 +472,10 @@ impl WaveChannel {
|
|||
|
||||
pub(super) fn update_wave_ram(&mut self, addr: WaveRamAddress, data: u8) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -518,21 +521,13 @@ impl Lfsr {
|
|||
}
|
||||
|
||||
fn next_value(&mut self) {
|
||||
let next = if (self.register & 0b1) == ((self.register >> 1) & 0b1) {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
};
|
||||
let next = u16::from((self.register & 0b1) == ((self.register >> 1) & 0b1));
|
||||
self.register = (self.register & !(0b1 << 15)) | (next << 15);
|
||||
if self.width == LfsrWidth::SevenBit {
|
||||
self.register = (self.register & !(0b1 << 7)) | (next << 7);
|
||||
}
|
||||
self.register >>= 1;
|
||||
self.current_value = if (self.register & 0b1) == 0b1 {
|
||||
0x1
|
||||
} else {
|
||||
0x0
|
||||
};
|
||||
self.current_value = u8::from((self.register & 0b1) == 0b1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ impl Default for Averager {
|
|||
}
|
||||
|
||||
impl Averager {
|
||||
fn push(&mut self, next: &[f32; 2]) {
|
||||
fn push(&mut self, next: [f32; 2]) {
|
||||
self.accum[0] += next[0];
|
||||
self.accum[1] += next[1];
|
||||
self.num += 1;
|
||||
|
@ -58,7 +58,7 @@ impl Downsampler {
|
|||
pub fn push(&mut self, signal: [f32; 2]) -> Option<[f32; 2]> {
|
||||
self.time_accum += 1.;
|
||||
if let Some(ref mut averager) = self.average {
|
||||
averager.push(&signal);
|
||||
averager.push(signal);
|
||||
}
|
||||
if self.time_accum >= self.ratio {
|
||||
self.time_accum -= self.ratio;
|
||||
|
|
|
@ -34,14 +34,14 @@ pub(super) enum Volume {
|
|||
}
|
||||
|
||||
impl Volume {
|
||||
pub(super) fn gate(&self, val: f32) -> f32 {
|
||||
pub(super) fn gate(self, val: f32) -> f32 {
|
||||
match self {
|
||||
Volume::Muted => 0.,
|
||||
Volume::Enabled => val,
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn bool(&self) -> bool {
|
||||
pub(super) fn bool(self) -> bool {
|
||||
match self {
|
||||
Volume::Muted => false,
|
||||
Volume::Enabled => true,
|
||||
|
|
|
@ -8,8 +8,8 @@ pub(crate) struct DoubleSpeed {
|
|||
}
|
||||
|
||||
impl DoubleSpeed {
|
||||
pub(crate) fn get(&self) -> u8 {
|
||||
0b01111110 | if self.current { 0b1 << 7 } else { 0 } | if self.prepared { 0b1 } else { 0 }
|
||||
pub(crate) fn get(self) -> u8 {
|
||||
0b01111110 | if self.current { 0b1 << 7 } else { 0 } | u8::from(self.prepared)
|
||||
}
|
||||
|
||||
pub(crate) fn set(&mut self, data: u8) {
|
||||
|
|
|
@ -9,8 +9,8 @@ pub struct Infrared {
|
|||
}
|
||||
|
||||
impl Infrared {
|
||||
pub(crate) fn get(&self) -> u8 {
|
||||
0b111110 | if self.led { 1 } else { 0 } | if self.read_enable { 0b11 << 6 } else { 0 }
|
||||
pub(crate) fn get(self) -> u8 {
|
||||
0b111110 | u8::from(self.led) | if self.read_enable { 0b11 << 6 } else { 0 }
|
||||
}
|
||||
|
||||
pub(crate) fn set(&mut self, data: u8) {
|
||||
|
|
|
@ -26,10 +26,10 @@ enum DmaMode {
|
|||
}
|
||||
|
||||
impl DmaMode {
|
||||
fn get_byte(&self) -> u8 {
|
||||
fn get_byte(self) -> u8 {
|
||||
match self {
|
||||
DmaMode::Halt(_) => unreachable!(),
|
||||
DmaMode::Hblank(v, _) => *v,
|
||||
DmaMode::Hblank(v, _) => v,
|
||||
DmaMode::Waiting => 0xFF,
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ impl Default for DmaMode {
|
|||
}
|
||||
|
||||
impl VramDma {
|
||||
pub(crate) fn get_register(&self, address: VramDmaAddress) -> u8 {
|
||||
pub(crate) fn get_register(self, address: VramDmaAddress) -> u8 {
|
||||
match address.inner() {
|
||||
0xFF51 => self.source.get_high(),
|
||||
0xFF52 => self.source.get_low(),
|
||||
|
|
|
@ -358,7 +358,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 })
|
||||
.get_addr(object.tile_index + u8::from(object_row >= 8))
|
||||
+ (u16::from(tile_row) * 2))
|
||||
.unwrap();
|
||||
let bank = if self.is_cgb_mode() {
|
||||
|
|
|
@ -37,12 +37,12 @@ where
|
|||
}
|
||||
|
||||
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 {
|
||||
TilemapArea::T9800 => 0,
|
||||
TilemapArea::T9C00 => 1,
|
||||
}) << 6
|
||||
| (if self.lcdc.window_enable { 1 } else { 0 }) << 5
|
||||
| u8::from(self.lcdc.window_enable) << 5
|
||||
| (match self.lcdc.tile_area {
|
||||
TiledataArea::D8000 => 1,
|
||||
TiledataArea::D9000 => 0,
|
||||
|
@ -55,8 +55,8 @@ where
|
|||
ObjSize::S8x8 => 0,
|
||||
ObjSize::S8x16 => 1,
|
||||
}) << 2
|
||||
| (if self.lcdc.obj_enable { 1 } else { 0 }) << 1
|
||||
| (if self.lcdc.bg_window_enable { 1 } else { 0 })
|
||||
| u8::from(self.lcdc.obj_enable) << 1
|
||||
| u8::from(self.lcdc.bg_window_enable)
|
||||
}
|
||||
|
||||
pub fn update_lcd_status(&mut self, data: u8) {
|
||||
|
|
|
@ -138,7 +138,7 @@ where
|
|||
tile_bank: bank,
|
||||
..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 {
|
||||
let lsbs = memory
|
||||
|
|
|
@ -24,7 +24,7 @@ pub(super) enum TilemapArea {
|
|||
}
|
||||
|
||||
impl TilemapArea {
|
||||
pub(super) fn get_addr(&self, addr: u16) -> VramAddress {
|
||||
pub(super) fn get_addr(self, addr: u16) -> VramAddress {
|
||||
match self {
|
||||
TilemapArea::T9800 => (0x9800 + addr).try_into().unwrap(),
|
||||
TilemapArea::T9C00 => (0x9C00 + addr).try_into().unwrap(),
|
||||
|
@ -39,7 +39,7 @@ pub(super) enum TiledataArea {
|
|||
}
|
||||
|
||||
impl TiledataArea {
|
||||
pub(super) fn get_addr(&self, addr: u8) -> VramAddress {
|
||||
pub(super) fn get_addr(self, addr: u8) -> VramAddress {
|
||||
match self {
|
||||
TiledataArea::D8000 => (0x8000 + (u16::from(addr) * 16)).try_into().unwrap(),
|
||||
TiledataArea::D9000 => 0x9000_u16
|
||||
|
@ -57,7 +57,7 @@ pub(super) enum ObjSize {
|
|||
}
|
||||
|
||||
impl ObjSize {
|
||||
pub(super) fn get_height(&self) -> u8 {
|
||||
pub(super) fn get_height(self) -> u8 {
|
||||
match self {
|
||||
ObjSize::S8x8 => 8,
|
||||
ObjSize::S8x16 => 16,
|
||||
|
@ -66,6 +66,7 @@ impl ObjSize {
|
|||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize)]
|
||||
#[allow(clippy::struct_excessive_bools)]
|
||||
pub(super) struct Lcdc {
|
||||
pub(super) enable: bool,
|
||||
pub(super) window_tilemap: TilemapArea,
|
||||
|
@ -139,17 +140,16 @@ pub(super) fn rgb_from_bytes(bytes: u16) -> Colour {
|
|||
}
|
||||
|
||||
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 {
|
||||
let offset: usize = (pallete_num as usize * 2 * 4)
|
||||
+ (if *self == ColourInner::Error {
|
||||
+ (if self == ColourInner::Error {
|
||||
if cfg!(feature = "error-colour") {
|
||||
return ERROR_COLOUR;
|
||||
} else {
|
||||
ColourInner::Zero
|
||||
}
|
||||
ColourInner::Zero
|
||||
} else {
|
||||
*self
|
||||
self
|
||||
} as usize
|
||||
* 2);
|
||||
|
||||
|
@ -180,13 +180,12 @@ impl ColourInner {
|
|||
}
|
||||
}
|
||||
|
||||
fn as_bits(&self) -> u8 {
|
||||
fn as_bits(self) -> u8 {
|
||||
match self {
|
||||
ColourInner::Zero => 0b00,
|
||||
ColourInner::Error | ColourInner::Zero => 0b00,
|
||||
ColourInner::One => 0b01,
|
||||
ColourInner::Two => 0b10,
|
||||
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.one.as_bits() << 2)
|
||||
| (self.two.as_bits() << 4)
|
||||
| (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) {
|
||||
(true, true) => (self.three, false),
|
||||
(true, false) => (self.one, false),
|
||||
|
@ -249,6 +248,7 @@ pub(super) struct Object {
|
|||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Copy, Debug)]
|
||||
#[allow(clippy::struct_excessive_bools)]
|
||||
pub(super) struct Stat {
|
||||
pub(super) lyc_eq_ly_interrupt_enabled: bool,
|
||||
pub(super) mode_2_interrupt_enabled: bool,
|
||||
|
|
|
@ -11,6 +11,7 @@ pub struct Joypad {
|
|||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Default)]
|
||||
#[allow(clippy::struct_excessive_bools)]
|
||||
pub struct JoypadState {
|
||||
pub down: bool,
|
||||
pub up: bool,
|
||||
|
|
|
@ -18,7 +18,7 @@ impl Default for OamDma {
|
|||
}
|
||||
|
||||
impl OamDma {
|
||||
pub(crate) fn get_register(&self) -> u8 {
|
||||
pub(crate) fn get_register(self) -> u8 {
|
||||
self.addr
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ impl OamDma {
|
|||
self.addr = data;
|
||||
}
|
||||
|
||||
pub(crate) fn is_active(&self) -> bool {
|
||||
pub(crate) fn is_active(self) -> bool {
|
||||
self.progress.is_some()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ const BYTE_DELAY: usize = 2000;
|
|||
const CLOCK_DIV: usize = CLOCK_SPEED / 8192;
|
||||
|
||||
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 {
|
||||
let val = (byte >> (7 - self.progress)) & 0b1;
|
||||
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.progress = 0;
|
||||
if let Some(rx) = rx {
|
||||
|
@ -96,7 +96,7 @@ impl InputByte {
|
|||
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() {
|
||||
self.try_fill(rx);
|
||||
}
|
||||
|
@ -139,9 +139,9 @@ impl Serial {
|
|||
return false;
|
||||
}
|
||||
let rx = if let SerialTarget::Custom { rx, tx: _ } = &self.target {
|
||||
rx
|
||||
rx.as_ref()
|
||||
} else {
|
||||
&None
|
||||
None
|
||||
};
|
||||
for _ in 0..steps {
|
||||
#[cfg(feature = "clocked-serial")]
|
||||
|
@ -212,11 +212,7 @@ impl Serial {
|
|||
|
||||
pub fn get_control(&self) -> u8 {
|
||||
0b01111110
|
||||
| (if self.control.transfer_in_progress {
|
||||
0b1
|
||||
} else {
|
||||
0b0
|
||||
} << 7)
|
||||
| (u8::from(self.control.transfer_in_progress) << 7)
|
||||
| match self.control.clock_source {
|
||||
ClockSource::Internal => 0b1,
|
||||
ClockSource::External => 0b0,
|
||||
|
|
|
@ -20,7 +20,7 @@ impl TimerRate {
|
|||
}
|
||||
}
|
||||
|
||||
fn as_bits(&self) -> u8 {
|
||||
fn as_bits(self) -> u8 {
|
||||
match self {
|
||||
TimerRate::Sixteen => 0b01,
|
||||
TimerRate::SixtyFour => 0b10,
|
||||
|
@ -29,7 +29,7 @@ impl TimerRate {
|
|||
}
|
||||
}
|
||||
|
||||
fn as_num(&self) -> usize {
|
||||
fn as_num(self) -> usize {
|
||||
match self {
|
||||
TimerRate::Sixteen => 16,
|
||||
TimerRate::SixtyFour => 64,
|
||||
|
|
|
@ -134,9 +134,10 @@ pub enum 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 {
|
||||
0x00 => Self::None,
|
||||
0x01 => Self::Nintendo,
|
||||
0x08 => Self::Capcom,
|
||||
0x09 => Self::HotB,
|
||||
|
|
|
@ -35,7 +35,7 @@ struct 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;
|
||||
match rtc_register {
|
||||
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 {
|
||||
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 => {
|
||||
(i64::from(data) - i64::from(self.get_register(&RtcRegister::Minutes))) * 60
|
||||
(i64::from(data) - i64::from(self.get_register(RtcRegister::Minutes))) * 60
|
||||
}
|
||||
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 => {
|
||||
(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,
|
||||
};
|
||||
|
@ -148,7 +153,7 @@ impl Mbc for Mbc3 {
|
|||
}
|
||||
RamBank::Rtc(rtc_register) => {
|
||||
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) => {
|
||||
if let Some(ref mut rtc) = self.rtc {
|
||||
rtc.set_register(rtc_register, data);
|
||||
rtc.set_register(*rtc_register, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ where
|
|||
|
||||
fn get_cam_reg(&self, address: CartRamAddress) -> u8 {
|
||||
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],
|
||||
_ => 0x00,
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ pub(crate) enum Direction {
|
|||
Right,
|
||||
}
|
||||
|
||||
#[allow(clippy::struct_excessive_bools)]
|
||||
pub struct Cpu<ColourFormat>
|
||||
where
|
||||
ColourFormat: From<Colour> + Copy,
|
||||
|
|
|
@ -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]>()) }
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ pub enum Platform {
|
|||
}
|
||||
|
||||
impl Platform {
|
||||
pub fn as_cargo(&self) -> cfg_expr::targets::Os {
|
||||
pub fn as_cargo(self) -> cfg_expr::targets::Os {
|
||||
match self {
|
||||
Platform::Windows => cfg_expr::targets::Os::windows,
|
||||
Platform::Linux => cfg_expr::targets::Os::linux,
|
||||
|
@ -58,7 +58,7 @@ pub enum Architecture {
|
|||
}
|
||||
|
||||
impl Architecture {
|
||||
pub fn as_cargo(&self) -> cfg_expr::targets::Arch {
|
||||
pub fn as_cargo(self) -> cfg_expr::targets::Arch {
|
||||
match self {
|
||||
Architecture::Aarch64 => cfg_expr::targets::Arch::aarch64,
|
||||
Architecture::X86_64 => cfg_expr::targets::Arch::x86_64,
|
||||
|
|
Loading…
Reference in a new issue