Clean up code
This commit is contained in:
parent
add054813d
commit
90bf6aa04f
@ -101,7 +101,7 @@ impl AudioThread {
|
||||
.unwrap();
|
||||
sw_click
|
||||
};
|
||||
let slf: AudioThread = Self {
|
||||
let slf = Self {
|
||||
fan_startup,
|
||||
fan_loop,
|
||||
fan_shutdown,
|
||||
@ -183,7 +183,7 @@ impl AudioThread {
|
||||
self.fan_state = FanState::On;
|
||||
}
|
||||
AudioMessage::FanOff => match self.fan_state {
|
||||
FanState::Off | FanState::Stopping { .. } => return,
|
||||
FanState::Off | FanState::Stopping { .. } => (),
|
||||
FanState::Starting {
|
||||
start_time,
|
||||
sound_offset,
|
||||
|
@ -9,6 +9,7 @@ pub enum CardEnum {
|
||||
|
||||
#[enum_dispatch]
|
||||
pub trait Card {
|
||||
#[allow(clippy::new_ret_no_self)]
|
||||
fn new(_settings: ron::Value) -> CardEnum;
|
||||
|
||||
fn read_mem(&mut self, _address: u16) -> Option<u8> {
|
||||
|
@ -13,7 +13,7 @@ use ux::{u4, u5};
|
||||
use self::opcode::{Condition, Opcode, Register, RegisterPair};
|
||||
|
||||
bitflags! {
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
|
||||
pub struct Status: u8 {
|
||||
const INTA = 0x1;
|
||||
const WO = 0x2;
|
||||
|
@ -26,12 +26,11 @@ pub enum ActionSwitch {
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum FrontpanelInteraction {
|
||||
ActionSwChanged(ActionSwitch, SwitchState),
|
||||
AdChanged(u16),
|
||||
PowerChanged(bool),
|
||||
ActionSw(ActionSwitch, SwitchState),
|
||||
Power(bool),
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
#[derive(Copy, Clone, Default)]
|
||||
pub struct FrontpanelState {
|
||||
ad_sws: u16,
|
||||
power: bool,
|
||||
@ -49,24 +48,6 @@ pub struct FrontpanelState {
|
||||
}
|
||||
|
||||
impl FrontpanelState {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
ad_sws: 0,
|
||||
power: false,
|
||||
runstop: SwitchState::Neut,
|
||||
single_step: SwitchState::Neut,
|
||||
exam: SwitchState::Neut,
|
||||
dep: SwitchState::Neut,
|
||||
reset: SwitchState::Neut,
|
||||
prot: SwitchState::Neut,
|
||||
aux1: SwitchState::Neut,
|
||||
aux2: SwitchState::Neut,
|
||||
addr: 0,
|
||||
data: 0,
|
||||
status: Status::empty(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ad_sws(&self) -> u16 {
|
||||
self.ad_sws
|
||||
}
|
||||
@ -154,8 +135,7 @@ impl Widget for &mut Frontpanel<'_> {
|
||||
.changed()
|
||||
{
|
||||
self.state.power = !power_inv;
|
||||
self.interaction =
|
||||
Some(FrontpanelInteraction::PowerChanged(self.state.power));
|
||||
self.interaction = Some(FrontpanelInteraction::Power(self.state.power));
|
||||
};
|
||||
});
|
||||
}
|
||||
@ -165,7 +145,7 @@ impl Widget for &mut Frontpanel<'_> {
|
||||
ui.allocate_ui_at_rect(Rect::from_center_size(pos, vec2(11.0, 25.0)), |ui| {
|
||||
let key_offset = (i - 1) % 8;
|
||||
let key = ["Q", "W", "E", "R", "T", "Y", "U", "I"][key_offset];
|
||||
let key = Key::from_name(&key).unwrap();
|
||||
let key = Key::from_name(key).unwrap();
|
||||
let mods = if (i - 1) < 8 {
|
||||
Modifiers::SHIFT
|
||||
} else {
|
||||
@ -181,9 +161,7 @@ impl Widget for &mut Frontpanel<'_> {
|
||||
.changed()
|
||||
{
|
||||
self.state.ad_sws =
|
||||
(self.state.ad_sws & !(bit_mask)) | ((sw_state as u16) << (16 - i));
|
||||
self.interaction =
|
||||
Some(FrontpanelInteraction::AdChanged(self.state.ad_sws));
|
||||
(self.state.ad_sws & !(bit_mask)) | (u16::from(sw_state) << (16 - i));
|
||||
};
|
||||
});
|
||||
}
|
||||
@ -227,8 +205,7 @@ impl Widget for &mut Frontpanel<'_> {
|
||||
24 => ActionSwitch::Aux2,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
self.interaction =
|
||||
Some(FrontpanelInteraction::ActionSwChanged(sw, *state));
|
||||
self.interaction = Some(FrontpanelInteraction::ActionSw(sw, *state));
|
||||
};
|
||||
});
|
||||
}
|
||||
|
@ -7,33 +7,33 @@ const NULL_UV: Rect = Rect::from_min_max(pos2(0.0, 0.0), pos2(1.0, 1.0));
|
||||
const NULL_TINT: Color32 = Color32::WHITE;
|
||||
|
||||
pub struct Textures {
|
||||
sw_up: TextureHandle,
|
||||
sw_neut: TextureHandle,
|
||||
sw_down: TextureHandle,
|
||||
up: TextureHandle,
|
||||
neut: TextureHandle,
|
||||
down: TextureHandle,
|
||||
}
|
||||
|
||||
impl Textures {
|
||||
pub fn new(sw_up: TextureHandle, sw_neut: TextureHandle, sw_down: TextureHandle) -> Self {
|
||||
pub fn new(up: TextureHandle, neut: TextureHandle, down: TextureHandle) -> Self {
|
||||
Self {
|
||||
sw_up,
|
||||
sw_neut,
|
||||
sw_down,
|
||||
up,
|
||||
neut,
|
||||
down,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_for_state(&self, state: SwitchState) -> TextureId {
|
||||
match state {
|
||||
SwitchState::Up => self.sw_up.id(),
|
||||
SwitchState::Neut => self.sw_neut.id(),
|
||||
SwitchState::Down => self.sw_down.id(),
|
||||
SwitchState::Up => self.up.id(),
|
||||
SwitchState::Neut => self.neut.id(),
|
||||
SwitchState::Down => self.down.id(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_for_bool(&self, state: bool) -> TextureId {
|
||||
if state {
|
||||
self.sw_up.id()
|
||||
self.up.id()
|
||||
} else {
|
||||
self.sw_down.id()
|
||||
self.down.id()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -106,8 +106,8 @@ impl Widget for ThreePosSwitch<'_> {
|
||||
let old_state = *self.state;
|
||||
if resp.dragged() {
|
||||
let interact_pos = resp.interact_pointer_pos().unwrap();
|
||||
let sw_center = painter.clip_rect().left_top() + vec2(5.0, 12.0);
|
||||
if interact_pos.y > sw_center.y {
|
||||
let center = painter.clip_rect().left_top() + vec2(5.0, 12.0);
|
||||
if interact_pos.y > center.y {
|
||||
*self.state = SwitchState::Down;
|
||||
} else {
|
||||
*self.state = SwitchState::Up;
|
||||
|
@ -65,7 +65,7 @@ impl LoadBinWindow {
|
||||
match self.ftype {
|
||||
BinaryType::Raw => {
|
||||
let bin = std::fs::read(path).unwrap();
|
||||
state.write_binary(self.start_addr as usize, bin);
|
||||
state.write_binary(self.start_addr as usize, &bin);
|
||||
}
|
||||
BinaryType::IntelHex => {
|
||||
let data = std::fs::read_to_string(path).unwrap();
|
||||
@ -73,7 +73,7 @@ impl LoadBinWindow {
|
||||
let record = record.unwrap();
|
||||
match record {
|
||||
ihex::Record::Data { offset, value } => {
|
||||
state.write_binary(offset as usize, value);
|
||||
state.write_binary(offset as usize, &value);
|
||||
}
|
||||
ihex::Record::StartLinearAddress(_) => todo!(),
|
||||
ihex::Record::EndOfFile => (),
|
||||
@ -94,12 +94,10 @@ impl Window for LoadBinWindow {
|
||||
if ui.button("Choose file").clicked() {
|
||||
self.choose_file();
|
||||
}
|
||||
ui.label(format!(
|
||||
"{}",
|
||||
self.path.as_ref().map_or("".into(), |x| x
|
||||
.file_name()
|
||||
.map_or("".into(), |x| x.to_string_lossy().to_string()))
|
||||
));
|
||||
ui.label(self.path.as_ref().map_or(String::new(), |x| {
|
||||
x.file_name()
|
||||
.map_or(String::new(), |x| x.to_string_lossy().to_string())
|
||||
}));
|
||||
});
|
||||
egui::ComboBox::from_label("File type")
|
||||
.selected_text(format!("{}", self.ftype))
|
||||
|
@ -18,7 +18,6 @@ use eframe::{
|
||||
use frontpanel::Textures;
|
||||
use load_bin_window::LoadBinWindow;
|
||||
use option_window::OptionWindow;
|
||||
use rfd::FileDialog;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use state::EmuState;
|
||||
use window::Window;
|
||||
|
@ -18,7 +18,7 @@ impl OptionWindow {
|
||||
pub fn new(ctx: &egui::Context, state: &EmuState) -> Self {
|
||||
Modal::new(ctx, "options_modal").open();
|
||||
Self {
|
||||
options: state.options().clone(),
|
||||
options: state.options(),
|
||||
category: OptionsCategory::General,
|
||||
}
|
||||
}
|
||||
|
13
src/state.rs
13
src/state.rs
@ -22,13 +22,13 @@ impl EmuState {
|
||||
pub fn new(audio_tx: Sender<AudioMessage>, options: Options) -> Self {
|
||||
let mut mem = [0; 65536];
|
||||
rand::thread_rng().fill_bytes(&mut mem);
|
||||
let mut slf = EmuState {
|
||||
let mut slf = Self {
|
||||
mem,
|
||||
cpu: I8080::new(),
|
||||
running: false,
|
||||
audio_tx,
|
||||
options,
|
||||
fp_state: FrontpanelState::new(),
|
||||
fp_state: FrontpanelState::default(),
|
||||
};
|
||||
slf.apply_options();
|
||||
slf
|
||||
@ -37,7 +37,7 @@ impl EmuState {
|
||||
pub fn handle_fp_interaction(&mut self, interaction: FrontpanelInteraction) {
|
||||
self.audio_tx.send(AudioMessage::PlaySwitchClick).unwrap();
|
||||
match interaction {
|
||||
FrontpanelInteraction::ActionSwChanged(sw, state) => {
|
||||
FrontpanelInteraction::ActionSw(sw, state) => {
|
||||
if self.fp_state.power() {
|
||||
match sw {
|
||||
ActionSwitch::RunStop => {
|
||||
@ -92,8 +92,7 @@ impl EmuState {
|
||||
}
|
||||
}
|
||||
}
|
||||
FrontpanelInteraction::AdChanged(_) => (),
|
||||
FrontpanelInteraction::PowerChanged(pwr) => {
|
||||
FrontpanelInteraction::Power(pwr) => {
|
||||
if pwr {
|
||||
self.audio_tx.send(AudioMessage::FanOn).unwrap();
|
||||
self.cpu = I8080::new();
|
||||
@ -154,9 +153,9 @@ impl EmuState {
|
||||
self.cpu.finish_m_cycle(data);
|
||||
}
|
||||
|
||||
pub fn write_binary(&mut self, start: usize, data: Vec<u8>) {
|
||||
pub fn write_binary(&mut self, start: usize, data: &[u8]) {
|
||||
assert!(0x1_0000 - start >= data.len());
|
||||
self.mem[start..(start + data.len())].copy_from_slice(&data);
|
||||
self.mem[start..(start + data.len())].copy_from_slice(data);
|
||||
}
|
||||
|
||||
pub fn update_options(&mut self, new_opts: Options) {
|
||||
|
Loading…
Reference in New Issue
Block a user