Removed cpu timer and moved audio wave generators to libraries

This commit is contained in:
transistor 2023-04-23 19:52:19 -07:00
parent 86eb73f78a
commit 69c94fa3af
19 changed files with 24 additions and 98 deletions

5
Cargo.lock generated
View File

@ -577,6 +577,10 @@ dependencies = [
"adler",
]
[[package]]
name = "moa_audio"
version = "0.1.0"
[[package]]
name = "moa_common"
version = "0.1.0"
@ -696,6 +700,7 @@ dependencies = [
name = "moa_peripherals_yamaha"
version = "0.1.0"
dependencies = [
"moa_audio",
"moa_core",
]

View File

@ -210,3 +210,4 @@ impl Device {
}

View File

@ -1,12 +1,11 @@
mod traits;
mod keys;
mod gfx;
mod controllers;
mod mouse;
pub mod gfx;
pub mod audio;
pub use self::gfx::{Pixel, PixelEncoding, Frame, FrameQueue};
pub use self::keys::{Key, KeyEvent};
pub use self::mouse::{MouseButton, MouseEventType, MouseEvent, MouseState};
pub use self::controllers::{ControllerDevice, ControllerEvent};

View File

@ -11,7 +11,6 @@ mod signals;
mod system;
pub mod host;
pub mod timers;
pub use log::{trace, debug, info, warn, error};

View File

@ -1,67 +0,0 @@
use std::fmt;
use std::time::Instant;
#[derive(Clone)]
pub struct AverageTimer {
pub high: u32,
pub average: f32,
pub low: u32,
pub events: u32,
pub start: Option<Instant>,
}
impl Default for AverageTimer {
fn default() -> AverageTimer {
AverageTimer {
high: 0,
average: 0.0,
low: u32::MAX,
events: 0,
start: None,
}
}
}
impl AverageTimer {
pub fn start(&mut self) {
//self.start = Some(Instant::now())
}
pub fn end(&mut self) {
//let time = self.start.unwrap().elapsed().as_nanos() as u32;
//self.events += 1;
//if time > self.high {
// self.high = time;
//}
//if time < self.low {
// self.low = time;
//}
//self.average = (self.average + time as f32) / 2.0;
}
}
impl fmt::Display for AverageTimer {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "H: {:8} A: {:4} L: {:8} over {} events", self.high, self.average as u32, self.low, self.events)
}
}
#[derive(Clone, Default)]
pub struct CpuTimer {
pub decode: AverageTimer,
pub execute: AverageTimer,
pub cycle: AverageTimer,
}
impl fmt::Display for CpuTimer {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "Decode: {}", self.decode)?;
writeln!(f, "Execute: {}", self.execute)?;
writeln!(f, "Cycle: {}", self.cycle)?;
Ok(())
}
}

View File

@ -90,13 +90,8 @@ impl M68k {
}
pub fn cycle_one(&mut self, system: &System) -> Result<ClockDuration, Error> {
self.timer.cycle.start();
self.decode_next()?;
self.execute_current()?;
self.timer.cycle.end();
//if (self.timer.cycle.events % 500) == 0 {
// println!("{}", self.timer);
//}
self.check_pending_interrupts(system)?;
self.check_breakpoints(system);
@ -204,10 +199,8 @@ impl M68k {
pub fn decode_next(&mut self) -> Result<(), Error> {
self.timing.reset();
self.timer.decode.start();
self.start_instruction_request(self.state.pc)?;
self.decoder.decode_at(&mut self.port, self.current_clock, self.state.pc)?;
self.timer.decode.end();
self.timing.add_instruction(&self.decoder.instruction);
@ -221,7 +214,6 @@ impl M68k {
}
pub fn execute_current(&mut self) -> Result<(), Error> {
self.timer.execute.start();
match self.decoder.instruction {
Instruction::ABCD(src, dest) => self.execute_abcd(src, dest),
Instruction::ADD(src, dest, size) => self.execute_add(src, dest, size),
@ -310,7 +302,6 @@ impl M68k {
_ => { return Err(Error::new("Unsupported instruction")); },
}?;
self.timer.execute.end();
Ok(())
}

View File

@ -1,6 +1,5 @@
use moa_core::{ClockTime, Address, BusPort, Frequency};
use moa_core::timers::CpuTimer;
use crate::instructions::Size;
use crate::decode::M68kDecoder;
@ -131,7 +130,6 @@ pub struct M68k {
pub timing: M68kInstructionTiming,
pub debugger: M68kDebugger,
pub port: BusPort,
pub timer: CpuTimer,
pub current_clock: ClockTime,
}
@ -165,7 +163,6 @@ impl M68k {
timing: M68kInstructionTiming::new(cputype, port.data_width()),
debugger: M68kDebugger::default(),
port,
timer: CpuTimer::default(),
current_clock: ClockTime::START,
}
}

View File

@ -3,8 +3,7 @@ use std::sync::mpsc;
use moa_peripherals_yamaha::{Ym2612, Sn76489};
use moa_core::host::gfx::{Frame, FrameQueue, PixelEncoding};
use moa_core::host::{Host, WindowUpdater, KeyboardUpdater, Key, KeyEvent /*, MouseUpdater, MouseState, MouseEvent*/};
use moa_core::host::{Host, Frame, FrameQueue, PixelEncoding, WindowUpdater, KeyboardUpdater, Key, KeyEvent /*, MouseUpdater, MouseState, MouseEvent*/};
use moa_core::{System, Error, ClockTime, ClockDuration, Frequency, Address, Addressable, Steppable, Transmutable, TransmutableBox, wrap_transmutable};

View File

@ -8,8 +8,7 @@ use minifb::{self, Key, MouseMode, MouseButton};
use clap::{App, Arg, ArgMatches};
use moa_core::{System, Error, ClockDuration};
use moa_core::host::{Host, ControllerUpdater, KeyboardUpdater, KeyEvent, MouseUpdater, MouseState, WindowUpdater, Audio, ControllerDevice};
use moa_core::host::gfx::{PixelEncoding, Frame};
use moa_core::host::{Host, ControllerUpdater, KeyboardUpdater, KeyEvent, MouseUpdater, MouseState, WindowUpdater, Audio, ControllerDevice, PixelEncoding, Frame};
use moa_common::{AudioMixer, AudioSource};
use moa_common::CpalAudioOutput;

View File

@ -7,8 +7,7 @@ use winit::event::{Event, VirtualKeyCode, WindowEvent, ElementState};
use winit::event_loop::{ControlFlow, EventLoop};
use moa_core::{System, Error};
use moa_core::host::{Host, WindowUpdater, ControllerDevice, ControllerEvent, ControllerUpdater, Audio, DummyAudio};
use moa_core::host::gfx::{PixelEncoding, Frame};
use moa_core::host::{Host, PixelEncoding, Frame, WindowUpdater, ControllerDevice, ControllerEvent, ControllerUpdater, Audio, DummyAudio};
use moa_common::{AudioMixer, AudioSource, CpalAudioOutput};
use crate::settings;

View File

@ -0,0 +1,6 @@
[package]
name = "moa_audio"
version = "0.1.0"
edition = "2021"
[dependencies]

View File

@ -5,3 +5,4 @@ edition = "2021"
[dependencies]
moa_core = { path = "../../core" }
moa_audio = { path = "../../libraries/audio" }

View File

@ -2,7 +2,7 @@
use moa_core::{info, warn, debug};
use moa_core::{System, Error, ClockTime, ClockDuration, Frequency, Address, Addressable, Steppable, Transmutable};
use moa_core::host::{Host, Audio};
use moa_core::host::audio::{SquareWave};
use moa_audio::SquareWave;
const DEV_NAME: &str = "sn76489";

View File

@ -14,7 +14,7 @@ use std::collections::VecDeque;
use moa_core::{debug, warn};
use moa_core::{System, Error, ClockTime, ClockDuration, Frequency, Address, Addressable, Steppable, Transmutable};
use moa_core::host::{Host, Audio};
use moa_core::host::audio::{SineWave, db_to_gain};
use moa_audio::{SineWave, db_to_gain};
/// Table of shift values for each possible rate angle

View File

@ -1,8 +1,7 @@
use moa_core::{debug, warn, error};
use moa_core::{System, Error, EdgeSignal, ClockTime, ClockDuration, Frequency, Address, Addressable, Steppable, Inspectable, Transmutable, TransmutableBox, read_beu16, dump_slice};
use moa_core::host::{Host, BlitableSurface, HostData};
use moa_core::host::gfx::{Pixel, PixelEncoding, Frame, FrameQueue};
use moa_core::host::{Host, Pixel, PixelEncoding, Frame, FrameQueue, BlitableSurface, HostData};
const REG_MODE_SET_1: usize = 0x00;

View File

@ -1,7 +1,6 @@
use moa_core::{System, Error, ClockDuration, Address, Addressable, Steppable, Transmutable};
use moa_core::host::gfx::{Frame, FrameQueue, Pixel};
use moa_core::host::{Host, BlitableSurface};
use moa_core::host::{Host, BlitableSurface, Frame, FrameQueue, Pixel};
const SCRN_BASE: u32 = 0x07A700;

View File

@ -650,7 +650,7 @@ const CHARACTERS: [[u8; 8]; 64] = [
];
use moa_core::host::gfx::Pixel;
use moa_core::host::Pixel;
pub struct CharacterGenerator {
pub row: i8,

View File

@ -2,8 +2,7 @@
use std::sync::{Arc, Mutex};
use moa_core::{System, Error, ClockTime, ClockDuration, Address, Addressable, Steppable, Transmutable, debug, warn};
use moa_core::host::gfx::{Frame, FrameQueue};
use moa_core::host::{Host, BlitableSurface, KeyboardUpdater, KeyEvent};
use moa_core::host::{Host, Frame, FrameQueue, BlitableSurface, KeyboardUpdater, KeyEvent};
use super::keymap;
use super::charset::CharacterGenerator;