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