From 2c2b8e58b4602dd2f0fcc5b26f295427a3a4bd08 Mon Sep 17 00:00:00 2001 From: transistor Date: Thu, 8 Sep 2022 19:51:29 -0700 Subject: [PATCH] WIP --- frontends/moa-minifb/src/bin/moa-synth.rs | 2 +- src/cpus/m68k/tests.rs | 4 ++-- src/error.rs | 2 +- src/host/audio.rs | 6 ++++++ src/machines/genesis.rs | 5 +++-- src/peripherals/genesis/ym7101.rs | 10 ++++++++-- src/peripherals/sn76489.rs | 2 +- src/timers.rs | 20 ++++++++++---------- 8 files changed, 32 insertions(+), 19 deletions(-) diff --git a/frontends/moa-minifb/src/bin/moa-synth.rs b/frontends/moa-minifb/src/bin/moa-synth.rs index 85065e9..ce9efd8 100644 --- a/frontends/moa-minifb/src/bin/moa-synth.rs +++ b/frontends/moa-minifb/src/bin/moa-synth.rs @@ -77,7 +77,7 @@ fn initialize_ym(ym_sound: TransmutableBox) -> Result<(), Error> { set_register(device, 0, 0x30, 0x71)?; set_register(device, 0, 0x34, 0x0D)?; set_register(device, 0, 0x38, 0x33)?; - set_register(device, 0, 0x3C, 0x01)?; + set_register(device, 0, 0x3C, 0x00)?; set_register(device, 0, 0xA4, 0x22)?; set_register(device, 0, 0xA0, 0x69)?; diff --git a/src/cpus/m68k/tests.rs b/src/cpus/m68k/tests.rs index dc5c48e..a33590f 100644 --- a/src/cpus/m68k/tests.rs +++ b/src/cpus/m68k/tests.rs @@ -167,11 +167,11 @@ mod decode_tests { let mut tests = 0; let mut errors = 0; - //use super::super::testcases::{TimingCase, TIMING_TESTS}; + use super::super::testcases::{TimingCase, TIMING_TESTS}; for case in TIMING_TESTS { tests += 1; let assembly_text = format!("{}", case.ins); - print!("Testing assembling of {:?} ", assembly_text); + print!("Testing assembling of {:?} from {:?}", assembly_text, case.ins); let mut assembler = M68kAssembler::new(M68kType::MC68000); match assembler.assemble_words(&assembly_text) { diff --git a/src/error.rs b/src/error.rs index ab41c26..f702694 100644 --- a/src/error.rs +++ b/src/error.rs @@ -48,7 +48,7 @@ pub enum LogLevel { Debug, } -static mut LOG_LEVEL: LogLevel = LogLevel::Warning; +static mut LOG_LEVEL: LogLevel = LogLevel::Info; pub fn log_level() -> LogLevel { unsafe { LOG_LEVEL } diff --git a/src/host/audio.rs b/src/host/audio.rs index de1f5ff..518e827 100644 --- a/src/host/audio.rs +++ b/src/host/audio.rs @@ -19,7 +19,9 @@ impl SineWave { } pub fn set_frequency(&mut self, frequency: f32) { + let ratio = self.frequency / frequency; self.frequency = frequency; + self.position = (self.position as f32 * ratio) as usize; } pub fn reset(&mut self) { @@ -54,7 +56,9 @@ impl SquareWave { } pub fn set_frequency(&mut self, frequency: f32) { + let ratio = self.frequency / frequency; self.frequency = frequency; + self.position = (self.position as f32 * ratio) as usize; } pub fn reset(&mut self) { @@ -106,7 +110,9 @@ impl SkewedSquareWave { } pub fn set_frequency(&mut self, frequency: f32) { + let ratio = self.frequency / frequency; self.frequency = frequency; + self.position = (self.position as f32 * ratio) as usize; } pub fn reset(&mut self) { diff --git a/src/machines/genesis.rs b/src/machines/genesis.rs index 3eb9e35..c467c11 100644 --- a/src/machines/genesis.rs +++ b/src/machines/genesis.rs @@ -86,7 +86,8 @@ pub fn build_genesis(host: &mut H, options: SegaGenesisOptions) -> Resu system.add_addressable_device(0x00a00000, coproc_ram)?; system.add_addressable_device(0x00a04000, coproc_ym_sound)?; system.add_addressable_device(0x00a06000, coproc_register)?; - system.add_addressable_device(0x00c00010, coproc_sn_sound)?; + //system.add_addressable_device(0x00c00010, coproc_sn_sound)?; + system.add_device("sn_sound", coproc_sn_sound.clone())?; system.add_device("coproc", wrap_transmutable(coproc))?; @@ -97,7 +98,7 @@ pub fn build_genesis(host: &mut H, options: SegaGenesisOptions) -> Resu let coproc = genesis::coprocessor::CoprocessorCoordinator::new(reset, bus_request); system.add_addressable_device(0x00a11000, wrap_transmutable(coproc)).unwrap(); - let vdp = genesis::ym7101::Ym7101::new(host, interrupt); + let vdp = genesis::ym7101::Ym7101::new(host, interrupt, coproc_sn_sound); system.break_signal = Some(vdp.frame_complete.clone()); system.add_peripheral("vdp", 0x00c00000, wrap_transmutable(vdp)).unwrap(); diff --git a/src/peripherals/genesis/ym7101.rs b/src/peripherals/genesis/ym7101.rs index 54ca1bd..908b87e 100644 --- a/src/peripherals/genesis/ym7101.rs +++ b/src/peripherals/genesis/ym7101.rs @@ -5,7 +5,7 @@ use crate::error::Error; use crate::system::System; use crate::memory::dump_slice; use crate::signals::{EdgeSignal}; -use crate::devices::{Clock, ClockElapsed, Address, Addressable, Steppable, Inspectable, Transmutable, read_beu16}; +use crate::devices::{Clock, ClockElapsed, Address, Addressable, Steppable, Inspectable, Transmutable, TransmutableBox, read_beu16}; use crate::host::traits::{Host, BlitableSurface, HostData}; use crate::host::gfx::{Frame, FrameSwapper}; @@ -678,13 +678,14 @@ impl Steppable for Ym7101 { pub struct Ym7101 { swapper: FrameSwapper, state: Ym7101State, + sn_sound: TransmutableBox, pub external_interrupt: HostData, pub frame_complete: EdgeSignal, } impl Ym7101 { - pub fn new(host: &mut H, external_interrupt: HostData) -> Ym7101 { + pub fn new(host: &mut H, external_interrupt: HostData, sn_sound: TransmutableBox) -> Ym7101 { let swapper = FrameSwapper::new(320, 224); host.add_window(FrameSwapper::to_boxed(swapper.clone())).unwrap(); @@ -692,6 +693,7 @@ impl Ym7101 { Ym7101 { swapper, state: Ym7101State::new(), + sn_sound, external_interrupt, frame_complete: EdgeSignal::new(), } @@ -834,6 +836,10 @@ impl Addressable for Ym7101 { } }, + 0x11 | 0x12 => { + self.sn_sound.borrow_mut().as_addressable().unwrap().write(0, data)?; + }, + _ => { warning!("{}: !!! unhandled write to {:x} with {:?}", DEV_NAME, addr, data); }, } Ok(()) diff --git a/src/peripherals/sn76489.rs b/src/peripherals/sn76489.rs index 77cce5f..2696234 100644 --- a/src/peripherals/sn76489.rs +++ b/src/peripherals/sn76489.rs @@ -41,7 +41,7 @@ impl ToneGenerator { } pub fn get_sample(&mut self) -> f32 { - self.wave.next().unwrap() + self.wave.next().unwrap() / self.attenuation } } diff --git a/src/timers.rs b/src/timers.rs index 3fb9078..a8fb825 100644 --- a/src/timers.rs +++ b/src/timers.rs @@ -23,20 +23,20 @@ impl AverageTimer { } pub fn start(&mut self) { - self.start = Some(Instant::now()) + //self.start = Some(Instant::now()) } pub fn end(&mut self) { - let time = self.start.unwrap().elapsed().as_nanos() as u32; + //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; + //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; } }