diff --git a/src/cpu.rs b/src/cpu.rs index 7385f06..1d718fa 100644 --- a/src/cpu.rs +++ b/src/cpu.rs @@ -352,7 +352,7 @@ impl I8080 { self.regs[dst] = self.regs[src]; } Opcode::Sphl => { - self.sp = ((self.regs.h as u16) << 8) | (self.regs.l as u16); + self.sp = (u16::from(self.regs.h) << 8) | u16::from(self.regs.l); } Opcode::MviM => (), Opcode::Mvi(_) => (), @@ -410,8 +410,8 @@ impl I8080 { Opcode::Inx(dst) => self.set_pair(dst, self.get_pair(dst) + 1), Opcode::Dcx(dst) => self.set_pair(dst, self.get_pair(dst) + 2), Opcode::Dad(src) => { - let a = self.get_pair(RegisterPair::HL) as u32; - let b = self.get_pair(src) as u32; + let a = u32::from(self.get_pair(RegisterPair::HL)); + let b = u32::from(self.get_pair(src)); let res = a + b; self.carry = res > 0xffff; self.set_pair(RegisterPair::HL, res as u16); @@ -462,14 +462,14 @@ impl I8080 { }, Opcode::Ral => { let high_bit = (self.regs.a & 0x80) > 0; - self.regs.a = self.regs.a << 1; - self.regs.a |= self.carry as u8; + self.regs.a <<= 1; + self.regs.a |= u8::from(self.carry); self.carry = high_bit; }, Opcode::Rar => { let low_bit = (self.regs.a & 0x1) > 0; - self.regs.a = self.regs.a >> 1; - self.regs.a |= (self.carry as u8) << 7; + self.regs.a >>= 1; + self.regs.a |= u8::from(self.carry) << 7; self.carry = low_bit; }, Opcode::Cma => { @@ -812,7 +812,7 @@ impl I8080 { } fn add_4bit(a: u4, b: u4, cy: bool) -> (bool, u4) { - let res: u5 = u5::from(a) + u5::from(b) + u5::new(cy as u8); + let res: u5 = u5::from(a) + u5::from(b) + u5::new(u8::from(cy)); ( (res >> 4) > u5::new(0), (res & u5::new(0xF)).try_into().unwrap(), @@ -872,15 +872,15 @@ impl I8080 { fn get_pair(&self, pair: RegisterPair) -> u16 { match pair { - RegisterPair::BC => ((self.regs.b as u16) << 8) | (self.regs.c as u16), - RegisterPair::DE => ((self.regs.d as u16) << 8) | (self.regs.e as u16), - RegisterPair::HL => ((self.regs.h as u16) << 8) | (self.regs.l as u16), + RegisterPair::BC => (u16::from(self.regs.b) << 8) | u16::from(self.regs.c), + RegisterPair::DE => (u16::from(self.regs.d) << 8) | u16::from(self.regs.e), + RegisterPair::HL => (u16::from(self.regs.h) << 8) | u16::from(self.regs.l), RegisterPair::SP => self.sp, } } fn get_wz(&self) -> u16 { - ((self.w as u16) << 8) | (self.z as u16) + (u16::from(self.w) << 8) | u16::from(self.z) } fn set_pair(&mut self, pair: RegisterPair, val: u16) { @@ -907,11 +907,11 @@ impl I8080 { } fn get_flags(&self) -> u8 { - 0b10 | self.carry as u8 - | (self.parity as u8) << 2 - | (self.aux_carry as u8) << 4 - | (self.zero as u8) << 6 - | (self.sign as u8) << 7 + 0b10 | u8::from(self.carry) + | u8::from(self.parity) << 2 + | u8::from(self.aux_carry) << 4 + | u8::from(self.zero) << 6 + | u8::from(self.sign) << 7 } fn set_flags(&mut self, flags: u8) { diff --git a/src/cpu/opcode_table.rs b/src/cpu/opcode_table.rs index 991902e..2287ed4 100644 --- a/src/cpu/opcode_table.rs +++ b/src/cpu/opcode_table.rs @@ -1,6 +1,6 @@ use super::opcode::{ Condition, - Opcode::{self, *}, + Opcode::{self, Aci, Adc, AdcM, Add, AddM, Adi, Ana, AnaM, Ani, Call, Ccc, Cma, Cmc, Cmp, CmpM, Cpi, Daa, Dad, Dcr, DcrM, Dcx, Di, Ei, Hlt, In, Inr, InrM, Inx, Jcc, Jmp, Lda, Ldax, Lhld, Lxi, Mov, MovMR, MovRM, Mvi, MviM, Nop, Ora, OraM, Ori, Out, Pchl, Pop, PopPsw, Push, PushPsw, Ral, Rar, Rcc, Ret, Rlc, Rrc, Rst, Sbb, SbbM, Sbi, Shld, Sphl, Sta, Stax, Stc, Sub, SubM, Sui, Xchg, Xra, XraM, Xri, Xthl}, Register, RegisterPair, }; pub(super) static OPCODE_TABLE: [Opcode; 256] = [ diff --git a/src/main.rs b/src/main.rs index 7b6bb06..970fd62 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,7 +11,7 @@ use std::{ use cpu::{MemCycle, Status, I8080}; use device_query::{DeviceState, Keycode}; -use eframe::egui::{self, menu, Button, Pos2, Rect, TextureHandle, TextureOptions, Ui}; +use eframe::{egui::{self, menu, Button, Pos2, Rect, TextureHandle, TextureOptions, Ui}, NativeOptions}; use egui_modal::Modal; use log::{debug, trace, warn}; use parking_lot::Mutex; @@ -57,10 +57,10 @@ fn main() -> Result<(), eframe::Error> { }; debug!(target: "altair_emu::fan_thread", "Fan startup length: {}s. Fan shutdown length: {}s", fan_startup.length(), fan_shutdown.length()); if fan_startup.length() != fan_shutdown.length() { - warn!(target: "altair_emu::fan_thread", "Fan startup sound and shutdown sounds do not have the same length! ({}s and {}s, respectively.) This may cause audio glitches.", fan_startup.length(), fan_shutdown.length()) + warn!(target: "altair_emu::fan_thread", "Fan startup sound and shutdown sounds do not have the same length! ({}s and {}s, respectively.) This may cause audio glitches.", fan_startup.length(), fan_shutdown.length()); } let mut fan_shutdown_start: Option<(Instant, Duration)> = None; - for msg in rx.iter() { + for msg in &rx { if msg { trace!(target: "altair_emu::fan_thread", "Start fan"); let fan_startup_start = if let Some(fan_shutdown_start) = fan_shutdown_start.take() @@ -87,6 +87,7 @@ fn main() -> Result<(), eframe::Error> { fan_shutdown.length() - fan_shutdown_elapsed, ) .unwrap(); + drop(sl); trace!(target: "altair_emu::fan_thread", "Fan startup playing at offset {}s", fan_shutdown.length() - fan_shutdown_elapsed); fan_startup_start } @@ -125,6 +126,7 @@ fn main() -> Result<(), eframe::Error> { fan_startup.length() - fan_startup_elapsed, ) .unwrap(); + drop(sl); trace!(target: "altair_emu::fan_thread", "Fan shutdown playing at offset {}s", fan_startup.length() - fan_startup_elapsed); } continue; @@ -132,6 +134,7 @@ fn main() -> Result<(), eframe::Error> { let mut sl = sl.lock(); let handle = sl.play(&fan_loop); sl.set_looping(handle, true); + drop(sl); trace!(target: "altair_emu::fan_thread", "Fan loop started, start done"); } else { trace!(target: "altair_emu::fan_thread", "Stop fan"); @@ -152,7 +155,7 @@ fn main() -> Result<(), eframe::Error> { .unwrap(); head_step }; - for msg in rx.iter() { + for msg in &rx { match msg { AudioMessage::PlaySwitchClick => { sl.lock().play(&head_step); @@ -162,7 +165,7 @@ fn main() -> Result<(), eframe::Error> { }); eframe::run_native( "Altair 8800 Emulator", - Default::default(), + NativeOptions::default(), Box::new(|cc| Box::new(AltairEmulator::new(cc, main_audio_tx, fan_audio_tx))), ) } @@ -330,8 +333,8 @@ impl eframe::App for AltairEmulator { .add_enabled(self.option_window.is_none(), Button::new("Options")) .clicked() { - self.option_window = Some(OptionWindow::new(&ctx, self.options.clone())); - ui.close_menu() + self.option_window = Some(OptionWindow::new(ctx, self.options)); + ui.close_menu(); } if ui.button("Load binary file").clicked() { let ihex_exts = ["hex", "mcs", "int", "ihex", "ihe", "ihx"]; @@ -371,8 +374,8 @@ impl eframe::App for AltairEmulator { LedSource::Protect => 0x0, LedSource::Iff => 0x0, LedSource::Run => 0x0, - LedSource::CpuStatus => self.fp_status.bits() as u16, - LedSource::Data => self.fp_data as u16, + LedSource::CpuStatus => u16::from(self.fp_status.bits()), + LedSource::Data => u16::from(self.fp_data), LedSource::Address => self.fp_address, }; let led_on = (led_data & led.mask) > 0; @@ -717,7 +720,7 @@ impl eframe::App for AltairEmulator { }); let old_fan_enabled = self.options.fan_enabled; if let Some(option_window) = self.option_window.as_mut() { - if option_window.draw(&ctx, &mut self.options) { + if option_window.draw(ctx, &mut self.options) { self.option_window = None; } } @@ -767,10 +770,10 @@ impl OptionWindow { } modal.buttons(ui, |ui| { if ui.button("Apply").clicked() { - *options = self.options.clone(); + *options = self.options; } if modal.button(ui, "OK").clicked() { - *options = self.options.clone(); + *options = self.options; } modal.caution_button(ui, "Cancel"); }); diff --git a/src/ram.rs b/src/ram.rs index 8d85203..e7413d6 100644 --- a/src/ram.rs +++ b/src/ram.rs @@ -15,8 +15,7 @@ pub struct RamCard { impl Card for RamCard { fn new(settings: ron::Value) -> CardEnum { let settings: RamCardSettings = settings.into_rust().unwrap(); - let mut ram = Vec::with_capacity(settings.size as usize); - ram.resize(settings.size as usize, 0); + let ram = vec![0; settings.size as usize]; CardEnum::RamCard(Self { ram, start_addr: settings.start_addr,