From 148b4dcf2cd9a5bf2c0c5c3825fdf49e31bc7de6 Mon Sep 17 00:00:00 2001 From: transistor Date: Mon, 13 Dec 2021 12:00:24 -0800 Subject: [PATCH] Cleaned up warnings --- frontends/moa-common/src/audio.rs | 15 ++--- frontends/moa-common/src/tty.rs | 1 + frontends/moa-console/src/lib.rs | 2 +- frontends/moa-minifb/src/lib.rs | 2 +- src/debugger.rs | 6 +- src/host/traits.rs | 2 +- src/interrupts.rs | 6 +- src/machines/computie.rs | 2 +- src/machines/genesis.rs | 8 +-- src/machines/macintosh.rs | 11 ++-- src/machines/trs80.rs | 4 +- src/memory.rs | 22 ++++--- src/peripherals/ata.rs | 8 +-- src/peripherals/genesis/controllers.rs | 29 ++++----- src/peripherals/genesis/coprocessor.rs | 17 ++--- src/peripherals/genesis/ym7101.rs | 88 ++++---------------------- src/peripherals/macintosh/iwm.rs | 28 ++++---- src/peripherals/macintosh/mainboard.rs | 46 ++++++-------- src/peripherals/macintosh/video.rs | 6 +- src/peripherals/mc68681.rs | 40 ++++++------ src/peripherals/mos6522.rs | 2 +- src/peripherals/sn76489.rs | 22 ++----- src/peripherals/trs80/model1.rs | 6 +- src/peripherals/ym2612.rs | 7 +- src/peripherals/z8530.rs | 12 +++- src/signals.rs | 4 ++ src/system.rs | 2 +- todo.txt | 1 - 28 files changed, 172 insertions(+), 227 deletions(-) diff --git a/frontends/moa-common/src/audio.rs b/frontends/moa-common/src/audio.rs index c1dae1d..5dedfc5 100644 --- a/frontends/moa-common/src/audio.rs +++ b/frontends/moa-common/src/audio.rs @@ -1,6 +1,6 @@ use moa::host::traits::{HostData, Audio}; -use cpal::{Data, Sample, Stream, SampleRate, SampleFormat, StreamConfig, traits::{DeviceTrait, HostTrait, StreamTrait}}; +use cpal::{Sample, Stream, SampleRate, SampleFormat, StreamConfig, traits::{DeviceTrait, HostTrait, StreamTrait}}; const SAMPLE_RATE: usize = 48000; @@ -122,8 +122,8 @@ impl AudioSource { } } - pub fn fill_with(&mut self, samples: usize, iter: &mut Iterator) { - for i in 0..samples { + pub fn fill_with(&mut self, samples: usize, iter: &mut dyn Iterator) { + for _ in 0..samples { let sample = 0.25 * iter.next().unwrap(); self.buffer.insert(sample); self.buffer.insert(sample); @@ -156,7 +156,7 @@ impl Audio for AudioSource { self.sample_rate } - fn write_samples(&mut self, samples: usize, iter: &mut Iterator) { + fn write_samples(&mut self, samples: usize, iter: &mut dyn Iterator) { self.fill_with(samples, iter); } } @@ -254,7 +254,7 @@ impl AudioMixer { // it's running fast. (If it's running slow, you can insert silence) } - +#[allow(dead_code)] pub struct AudioOutput { stream: Stream, mixer: HostData, @@ -274,7 +274,7 @@ impl AudioOutput { .with_sample_rate(SampleRate(SAMPLE_RATE as u32)) .into(); - let channels = config.channels as usize; + //let channels = config.channels as usize; let data_callback = { let mixer = mixer.clone(); @@ -308,8 +308,7 @@ impl AudioOutput { &config, data_callback, move |err| { - // react to errors here. - println!("ERROR"); + println!("ERROR: {:?}", err); }, ).unwrap(); diff --git a/frontends/moa-common/src/tty.rs b/frontends/moa-common/src/tty.rs index 30672eb..87c0dfe 100644 --- a/frontends/moa-common/src/tty.rs +++ b/frontends/moa-common/src/tty.rs @@ -3,6 +3,7 @@ use std::thread; use std::sync::mpsc; use std::time::Duration; use std::io::{Read, Write}; +use std::os::unix::io::AsRawFd; use nix::fcntl::OFlag; use nix::pty::{self, PtyMaster}; diff --git a/frontends/moa-console/src/lib.rs b/frontends/moa-console/src/lib.rs index c554af9..0f85975 100644 --- a/frontends/moa-console/src/lib.rs +++ b/frontends/moa-console/src/lib.rs @@ -10,7 +10,7 @@ impl Host for ConsoleFrontend { Ok(Box::new(SimplePty::open()?)) } - fn add_window(&mut self, updater: Box) -> Result<(), Error> { + fn add_window(&mut self, _updater: Box) -> Result<(), Error> { println!("console: add_window() is not supported from the console; ignoring request..."); Ok(()) } diff --git a/frontends/moa-minifb/src/lib.rs b/frontends/moa-minifb/src/lib.rs index be3689b..32bb0d4 100644 --- a/frontends/moa-minifb/src/lib.rs +++ b/frontends/moa-minifb/src/lib.rs @@ -9,7 +9,7 @@ use clap::{App, ArgMatches}; use moa::error::Error; use moa::system::System; use moa::host::traits::{Host, HostData, ControllerUpdater, KeyboardUpdater, WindowUpdater, Audio}; -use moa::host::controllers::{ControllerDevice, ControllerEvent}; +use moa::host::controllers::{ControllerDevice}; use moa_common::audio::{AudioOutput, AudioMixer, AudioSource}; diff --git a/src/debugger.rs b/src/debugger.rs index c81ba20..3531729 100644 --- a/src/debugger.rs +++ b/src/debugger.rs @@ -7,9 +7,9 @@ use crate::devices::{Address, Addressable, Debuggable, TransmutableBox}; pub struct Debugger { - pub last_command: Option, - pub repeat: u32, - pub trace_only: bool, + last_command: Option, + repeat: u32, + trace_only: bool, } diff --git a/src/host/traits.rs b/src/host/traits.rs index f1fcc3f..1089248 100644 --- a/src/host/traits.rs +++ b/src/host/traits.rs @@ -50,7 +50,7 @@ pub trait KeyboardUpdater: Send { pub trait Audio { fn samples_per_second(&self) -> usize; - fn write_samples(&mut self, samples: usize, iter: &mut Iterator); + fn write_samples(&mut self, samples: usize, iter: &mut dyn Iterator); } pub trait BlitableSurface { diff --git a/src/interrupts.rs b/src/interrupts.rs index 6a66f45..ee8cfc7 100644 --- a/src/interrupts.rs +++ b/src/interrupts.rs @@ -4,9 +4,9 @@ use crate::devices::TransmutableBox; pub struct InterruptController { - pub target: Option, - pub interrupts: Vec<(bool, u8)>, - pub highest: u8, + target: Option, + interrupts: Vec<(bool, u8)>, + highest: u8, } impl InterruptController { diff --git a/src/machines/computie.rs b/src/machines/computie.rs index 8fc5ab5..8d128d2 100644 --- a/src/machines/computie.rs +++ b/src/machines/computie.rs @@ -69,7 +69,7 @@ pub fn build_computie_k30(host: &H) -> Result { system.add_addressable_device(0x00700000, wrap_transmutable(serial))?; - let mut cpu = M68k::new(M68kType::MC68030, 10_000_000, BusPort::new(0, 32, 32, system.bus.clone())); + let cpu = M68k::new(M68kType::MC68030, 10_000_000, BusPort::new(0, 32, 32, system.bus.clone())); //cpu.enable_tracing(); //cpu.add_breakpoint(0x10781a); diff --git a/src/machines/genesis.rs b/src/machines/genesis.rs index 009cd61..496e2bf 100644 --- a/src/machines/genesis.rs +++ b/src/machines/genesis.rs @@ -4,9 +4,9 @@ use std::cell::RefCell; use crate::error::Error; use crate::system::System; -use crate::signals::{Signal, Observable}; +use crate::signals::{Signal}; use crate::memory::{MemoryBlock, Bus, BusPort}; -use crate::devices::{wrap_transmutable, Address, Addressable, Debuggable}; +use crate::devices::{wrap_transmutable, Address, Addressable}; use crate::cpus::m68k::{M68k, M68kType}; use crate::cpus::z80::{Z80, Z80Type}; @@ -33,7 +33,7 @@ impl SegaGenesisOptions { pub fn build_genesis(host: &mut H, options: SegaGenesisOptions) -> Result { let mut system = System::new(); - let mut rom = MemoryBlock::load(&options.rom).unwrap(); + let rom = MemoryBlock::load(&options.rom).unwrap(); //let mut rom = MemoryBlock::load("binaries/genesis/GenTestV3.0.bin").unwrap(); //let mut rom = MemoryBlock::load("binaries/genesis/HDRV_Genesis_Test_v1_4.bin").unwrap(); //let mut rom = MemoryBlock::load("binaries/genesis/ComradeOj's tiny demo.bin").unwrap(); @@ -99,7 +99,7 @@ pub fn build_genesis(host: &mut H, options: SegaGenesisOptions) -> Resu system.break_signal = Some(vdp.frame_complete.clone()); system.add_peripheral("vdp", 0x00c00000, wrap_transmutable(vdp)).unwrap(); - let mut cpu = M68k::new(M68kType::MC68000, 7_670_454, BusPort::new(0, 24, 16, system.bus.clone())); + let cpu = M68k::new(M68kType::MC68000, 7_670_454, BusPort::new(0, 24, 16, system.bus.clone())); system.add_interruptable_device("cpu", wrap_transmutable(cpu)).unwrap(); Ok(system) diff --git a/src/machines/macintosh.rs b/src/machines/macintosh.rs index 851fc3a..b8cb737 100644 --- a/src/machines/macintosh.rs +++ b/src/machines/macintosh.rs @@ -2,12 +2,9 @@ use crate::error::Error; use crate::system::System; use crate::devices::{wrap_transmutable, Debuggable}; -use crate::memory::{MemoryBlock, AddressAdapter, BusPort}; +use crate::memory::{MemoryBlock, BusPort}; use crate::cpus::m68k::{M68k, M68kType}; -use crate::peripherals::mos6522::Mos6522; -use crate::peripherals::z8530::Z8530; -use crate::peripherals::macintosh::iwm::IWM; use crate::peripherals::macintosh::video::MacVideo; use crate::peripherals::macintosh::mainboard::Mainboard; @@ -18,6 +15,10 @@ pub fn build_macintosh_512k(host: &mut H) -> Result { let mut system = System::new(); /* + use crate::peripherals::mos6522::Mos6522; + use crate::peripherals::z8530::Z8530; + use crate::peripherals::macintosh::iwm::IWM; + let mut ram = MemoryBlock::new(vec![0; 0x00100000]); ram.load_at(0, "binaries/macintosh/Macintosh 128k.rom")?; let boxed_ram = wrap_transmutable(ram); @@ -60,7 +61,7 @@ pub fn build_macintosh_512k(host: &mut H) -> Result { system.add_addressable_device(0x00EFE000, wrap_transmutable(adapter))?; */ - let mut ram = MemoryBlock::new(vec![0; 0x00080000]); + let ram = MemoryBlock::new(vec![0; 0x00080000]); let mut rom = MemoryBlock::load("binaries/macintosh/Macintosh 512k.rom")?; rom.read_only(); diff --git a/src/machines/trs80.rs b/src/machines/trs80.rs index aa03373..a2473ad 100644 --- a/src/machines/trs80.rs +++ b/src/machines/trs80.rs @@ -1,7 +1,7 @@ use crate::error::Error; use crate::system::System; -use crate::devices::{Debuggable, wrap_transmutable}; +use crate::devices::wrap_transmutable; use crate::memory::{MemoryBlock, BusPort}; use crate::cpus::z80::{Z80, Z80Type}; @@ -42,7 +42,7 @@ pub fn build_trs80(host: &mut H, options: Trs80Options) -> Result, + read_only: bool, + contents: Vec, } impl MemoryBlock { @@ -76,8 +76,8 @@ impl Transmutable for MemoryBlock { pub struct AddressAdapter { - pub subdevice: TransmutableBox, - pub shift: u8, + subdevice: TransmutableBox, + shift: u8, } impl AddressAdapter { @@ -118,7 +118,7 @@ pub struct Block { } pub struct Bus { - pub blocks: Vec, + blocks: Vec, } impl Bus { @@ -128,6 +128,10 @@ impl Bus { } } + pub fn clear_all_bus_devices(&mut self) { + self.blocks.clear(); + } + pub fn insert(&mut self, base: Address, dev: TransmutableBox) { let length = dev.borrow_mut().as_addressable().unwrap().len(); let block = Block { base, length, dev }; @@ -189,10 +193,10 @@ impl Addressable for Bus { } pub struct BusPort { - pub offset: Address, - pub address_mask: Address, - pub data_width: u8, - pub subdevice: Rc>, + offset: Address, + address_mask: Address, + data_width: u8, + subdevice: Rc>, } impl BusPort { diff --git a/src/peripherals/ata.rs b/src/peripherals/ata.rs index 4eba0a3..6065789 100644 --- a/src/peripherals/ata.rs +++ b/src/peripherals/ata.rs @@ -34,10 +34,10 @@ const ATA_SECTOR_SIZE: u32 = 512; const DEV_NAME: &'static str = "ata"; pub struct AtaDevice { - pub selected_sector: u32, - pub selected_count: u32, - pub last_error: u8, - pub contents: Vec, + selected_sector: u32, + selected_count: u32, + last_error: u8, + contents: Vec, } diff --git a/src/peripherals/genesis/controllers.rs b/src/peripherals/genesis/controllers.rs index 590125f..d56d9e5 100644 --- a/src/peripherals/genesis/controllers.rs +++ b/src/peripherals/genesis/controllers.rs @@ -1,7 +1,6 @@ use crate::error::Error; -use crate::system::System; -use crate::devices::{Clock, ClockElapsed, Address, Addressable, Steppable, Transmutable}; +use crate::devices::{Address, Addressable, Transmutable}; use crate::host::controllers::{ControllerDevice, ControllerEvent}; use crate::host::traits::{Host, ControllerUpdater, HostData}; @@ -24,13 +23,13 @@ pub struct GenesisControllerPort { /// Data contains bits: /// 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 /// X | Y | Z | MODE | START | A | C | B | RIGHT | LEFT | DOWN | UP - pub buttons: HostData, + buttons: HostData, - pub ctrl: u8, - pub outputs: u8, - pub th_count: u8, + ctrl: u8, + outputs: u8, + th_count: u8, - pub s_ctrl: u8, + s_ctrl: u8, } impl GenesisControllerPort { @@ -113,12 +112,12 @@ impl ControllerUpdater for GenesisControllerUpdater { pub struct GenesisController { - pub port_1: GenesisControllerPort, - pub port_2: GenesisControllerPort, - pub expansion: GenesisControllerPort, - pub interrupt: HostData, - pub last_clock: Clock, - pub last_write: Clock, + port_1: GenesisControllerPort, + port_2: GenesisControllerPort, + expansion: GenesisControllerPort, + interrupt: HostData, + //last_clock: Clock, + //last_write: Clock, } impl GenesisController { @@ -128,8 +127,8 @@ impl GenesisController { port_2: GenesisControllerPort::new(), expansion: GenesisControllerPort::new(), interrupt: HostData::new(false), - last_clock: 0, - last_write: 0, + //last_clock: 0, + //last_write: 0, } } diff --git a/src/peripherals/genesis/coprocessor.rs b/src/peripherals/genesis/coprocessor.rs index e4a2e68..1feabcf 100644 --- a/src/peripherals/genesis/coprocessor.rs +++ b/src/peripherals/genesis/coprocessor.rs @@ -5,14 +5,14 @@ use std::cell::RefCell; use crate::memory::Bus; use crate::error::Error; use crate::signals::Signal; -use crate::devices::{Address, Addressable, Transmutable, TransmutableBox}; +use crate::devices::{Address, Addressable, Transmutable}; const DEV_NAME: &'static str = "coprocessor"; pub struct CoprocessorCoordinator { - pub bus_request: Signal, - pub reset: Signal, + bus_request: Signal, + reset: Signal, } @@ -73,7 +73,7 @@ impl Transmutable for CoprocessorCoordinator { pub struct CoprocessorBankRegister { - pub base: Signal
, + base: Signal
, } impl CoprocessorBankRegister { @@ -89,12 +89,13 @@ impl Addressable for CoprocessorBankRegister { 0x01 } - fn read(&mut self, addr: Address, data: &mut [u8]) -> Result<(), Error> { + fn read(&mut self, _addr: Address, _data: &mut [u8]) -> Result<(), Error> { Ok(()) } - fn write(&mut self, addr: Address, data: &[u8]) -> Result<(), Error> { + fn write(&mut self, _addr: Address, data: &[u8]) -> Result<(), Error> { let value = ((self.base.get() >> 1) | ((data[0] as Address) << 23)) & 0xFF8000; + //let value = ((self.base.get() << 1) | ((data[0] as Address) << 15)) & 0xFF8000; println!("New base is {:x}", value); self.base.set(value); Ok(()) @@ -109,8 +110,8 @@ impl Transmutable for CoprocessorBankRegister { pub struct CoprocessorBankArea { - pub base: Signal
, - pub bus: Rc>, + base: Signal
, + bus: Rc>, } impl CoprocessorBankArea { diff --git a/src/peripherals/genesis/ym7101.rs b/src/peripherals/genesis/ym7101.rs index 1103c37..4c9d49c 100644 --- a/src/peripherals/genesis/ym7101.rs +++ b/src/peripherals/genesis/ym7101.rs @@ -1,12 +1,11 @@ use std::iter::Iterator; -use std::sync::{Arc, Mutex}; use crate::error::Error; use crate::system::System; use crate::memory::dump_slice; -use crate::signals::{Signal, EdgeSignal}; -use crate::devices::{Clock, ClockElapsed, Address, Addressable, Steppable, Inspectable, Transmutable, read_beu16, read_beu32, write_beu16}; +use crate::signals::{EdgeSignal}; +use crate::devices::{Clock, ClockElapsed, Address, Addressable, Steppable, Inspectable, Transmutable, read_beu16}; use crate::host::traits::{Host, BlitableSurface, HostData}; use crate::host::gfx::{Frame, FrameSwapper}; @@ -37,18 +36,18 @@ const REG_DMA_ADDR_MID: usize = 0x16; const REG_DMA_ADDR_HIGH: usize = 0x17; -const STATUS_PAL_MODE: u16 = 0x0001; +//const STATUS_PAL_MODE: u16 = 0x0001; const STATUS_DMA_BUSY: u16 = 0x0002; const STATUS_IN_HBLANK: u16 = 0x0004; const STATUS_IN_VBLANK: u16 = 0x0008; -const STATUS_ODD_FRAME: u16 = 0x0010; -const STATUS_SPRITE_COLLISION: u16 = 0x0020; -const STATUS_SPRITE_OVERFLOW: u16 = 0x0040; -const STATUS_V_INTERRUPT: u16 = 0x0080; -const STATUS_FIFO_FULL: u16 = 0x0100; +//const STATUS_ODD_FRAME: u16 = 0x0010; +//const STATUS_SPRITE_COLLISION: u16 = 0x0020; +//const STATUS_SPRITE_OVERFLOW: u16 = 0x0040; +//const STATUS_V_INTERRUPT: u16 = 0x0080; +//const STATUS_FIFO_FULL: u16 = 0x0100; const STATUS_FIFO_EMPTY: u16 = 0x0200; -const MODE1_BF_ENABLE_HV_COUNTER: u8 = 0x02; +//const MODE1_BF_ENABLE_HV_COUNTER: u8 = 0x02; const MODE1_BF_HSYNC_INTERRUPT: u8 = 0x10; const MODE2_BF_V_CELL_MODE: u8 = 0x08; @@ -60,7 +59,7 @@ const MODE3_BF_V_SCROLL_MODE: u8 = 0x04; const MODE3_BF_H_SCROLL_MODE: u8 = 0x03; const MODE4_BF_H_CELL_MODE: u8 = 0x01; -const MODE4_BF_SHADOW_HIGHLIGHT: u8 = 0x08; +//const MODE4_BF_SHADOW_HIGHLIGHT: u8 = 0x08; @@ -387,7 +386,6 @@ impl Ym7101State { pub fn draw_scrolls(&mut self, frame: &mut Frame) { let (scroll_h, scroll_v) = self.scroll_size; let (cells_h, cells_v) = self.screen_size; - let (offset_x, offset_y) = self.window_offset; if scroll_h == 0 || scroll_v == 0 { return; @@ -458,7 +456,6 @@ impl Ym7101State { let (size_h, size_v) = (((size >> 2) & 0x03) as u16 + 1, (size & 0x03) as u16 + 1); let h_rev = (pattern_name & 0x0800) != 0; let v_rev = (pattern_name & 0x1000) != 0; -//println!("i: {} ({} {}) {:x} ({}, {}) {:x}", i, h_pos, v_pos, size, size_h, size_v, pattern_name); for ih in 0..size_h { for iv in 0..size_v { @@ -467,7 +464,6 @@ impl Ym7101State { if x > 128 && x < pos_limit_h && y > 128 && y < pos_limit_v { let iter = self.get_pattern_iter(((pattern_name & 0x07FF) + (h * size_v) + v) | (pattern_name & 0xF800)); -//println!("{}: ({} {}), {:x}", i, x, y, ((pattern_name & 0x07FF) + (h * size_v) + v)); frame.blit(x as u32 - 128, y as u32 - 128, iter, 8, 8); } } @@ -540,8 +536,9 @@ impl<'a> Iterator for PatternIterator<'a> { pub struct Ym7101 { - pub swapper: FrameSwapper, - pub state: Ym7101State, + swapper: FrameSwapper, + state: Ym7101State, + pub external_interrupt: HostData, pub frame_complete: EdgeSignal, } @@ -613,63 +610,6 @@ impl Steppable for Ym7101 { let mut frame = self.swapper.current.lock().unwrap(); self.state.draw_frame(&mut frame); - //let mut frame = self.swapper.current.lock().unwrap(); - //let iter = PatternIterator::new(&self.state, 0x260, 0, true, true); - //frame.blit(0, 0, iter, 8, 8); - - /* - // Print Palette - for i in 0..16 { - println!("{:x}", self.state.get_palette_colour(0, i)); - } - */ - - /* - // Print Pattern Table - let mut frame = self.swapper.current.lock().unwrap(); - let (cells_h, cells_v) = self.state.get_screen_size(); - for cell_y in 0..cells_v { - for cell_x in 0..cells_h { - let pattern_addr = (cell_x + (cell_y * cells_h)) * 32; - let iter = PatternIterator::new(&self.state, pattern_addr as u32, 0, false, false); - frame.blit((cell_x << 3) as u32, (cell_y << 3) as u32, iter, 8, 8); - } - } - */ - - - /* - // Print Sprite - let mut frame = self.swapper.current.lock().unwrap(); - self.state.draw_background(&mut frame); - let sprite_table = self.get_vram_sprites_addr(); - let (cells_h, cells_v) = self.state.get_screen_size(); - let sprite = 0; - println!("{:?}", &self.state.vram[(sprite_table + (sprite * 8))..(sprite_table + (sprite * 8) + 8)].iter().map(|byte| format!("{:02x}", byte)).collect::>()); - let size = self.state.vram[sprite_table + (sprite * 8) + 2]; - let (size_h, size_v) = (((size >> 2) & 0x03) as u16 + 1, (size & 0x03) as u16 + 1); - let pattern_name = ((self.state.vram[sprite_table + (sprite * 8) + 4] as u16) << 8) | (self.state.vram[sprite_table + (sprite * 8) + 5] as u16); - let pattern_gen = pattern_name & 0x7FF; - println!("{:x}", pattern_name); - - for cell_y in 0..size_v { - for cell_x in 0..size_h { - let pattern_addr = (pattern_gen + (cell_y * size_h) + cell_x) as u32; - println!("pattern: ({}, {}) {:x}", cell_x, cell_y, pattern_addr); - let iter = PatternIterator::new(&self.state, pattern_addr * 32, 3, true, true); - frame.blit((cell_x << 3) as u32, (cell_y << 3) as u32, iter, 8, 8); - } - } - */ - - //let mut frame = self.swapper.current.lock().unwrap(); - //frame.blit(0, 0, PatternIterator::new(&self.state, 0x408 * 32, 3, false, false), 8, 8); - //frame.blit(0, 8, PatternIterator::new(&self.state, 0x409 * 32, 3, false, false), 8, 8); - //frame.blit(8, 0, PatternIterator::new(&self.state, 0x402 * 32, 3, false, false), 8, 8); - //frame.blit(8, 8, PatternIterator::new(&self.state, 0x403 * 32, 3, false, false), 8, 8); - //frame.blit(16, 0, PatternIterator::new(&self.state, 0x404 * 32, 3, false, false), 8, 8); - //frame.blit(16, 8, PatternIterator::new(&self.state, 0x405 * 32, 3, false, false), 8, 8); - self.frame_complete.signal(); } @@ -810,7 +750,7 @@ impl Addressable for Ym7101 { impl Inspectable for Ym7101 { - fn inspect(&mut self, system: &System, args: &[&str]) -> Result<(), Error> { + fn inspect(&mut self, _system: &System, args: &[&str]) -> Result<(), Error> { match args[0] { "" | "state" => { self.state.dump_state(); diff --git a/src/peripherals/macintosh/iwm.rs b/src/peripherals/macintosh/iwm.rs index 652acec..ee8c59e 100644 --- a/src/peripherals/macintosh/iwm.rs +++ b/src/peripherals/macintosh/iwm.rs @@ -4,21 +4,21 @@ use crate::system::System; use crate::devices::{ClockElapsed, Address, Addressable, Steppable, Transmutable}; -const CA0: u8 = 0x01; -const CA1: u8 = 0x02; -const CA2: u8 = 0x04; -const LSTRB: u8 = 0x08; +//const CA0: u8 = 0x01; +//const CA1: u8 = 0x02; +//const CA2: u8 = 0x04; +//const LSTRB: u8 = 0x08; const ENABLE: u8 = 0x10; -const SELECT: u8 = 0x20; +//const SELECT: u8 = 0x20; const Q6: u8 = 0x40; const Q7: u8 = 0x80; const DEV_NAME: &'static str = "iwm"; pub struct IWM { - pub state: u8, - pub mode: u8, - pub handshake: u8, + state: u8, + mode: u8, + handshake: u8, } impl IWM { @@ -102,14 +102,20 @@ impl Addressable for IWM { } } +impl Steppable for IWM { + fn step(&mut self, _system: &System) -> Result { + + Ok(1_000_000_00) + } +} impl Transmutable for IWM { fn as_addressable(&mut self) -> Option<&mut dyn Addressable> { Some(self) } - //fn as_steppable(&mut self) -> Option<&mut dyn Steppable> { - // Some(self) - //} + fn as_steppable(&mut self) -> Option<&mut dyn Steppable> { + Some(self) + } } diff --git a/src/peripherals/macintosh/mainboard.rs b/src/peripherals/macintosh/mainboard.rs index 721fc5a..bc77f35 100644 --- a/src/peripherals/macintosh/mainboard.rs +++ b/src/peripherals/macintosh/mainboard.rs @@ -5,25 +5,24 @@ use std::cell::RefCell; use crate::memory::Bus; use crate::error::Error; use crate::system::System; -use crate::signals::{Signal, Observable}; +use crate::signals::Observable; use crate::devices::{Clock, ClockElapsed, Address, Addressable, Steppable, Transmutable, TransmutableBox, wrap_transmutable}; use crate::peripherals::z8530::Z8530; use crate::peripherals::mos6522::Mos6522; use crate::peripherals::macintosh::iwm::IWM; -use crate::peripherals::macintosh::video::MacVideo; const DEV_NAME: &'static str = "mac"; pub struct Mainboard { - pub lower_bus: Rc>, - pub scc1: Z8530, - pub scc2: Z8530, - pub iwm: IWM, - pub via: Mos6522, - pub phase_read: PhaseRead, - pub last_sec: Clock, + lower_bus: Rc>, + scc1: Z8530, + scc2: Z8530, + iwm: IWM, + via: Mos6522, + phase_read: PhaseRead, + last_sec: Clock, } impl Mainboard { @@ -35,8 +34,6 @@ impl Mainboard { let phase_read = PhaseRead::new(); let lower_bus = Rc::new(RefCell::new(Bus::new())); - let ram_len = ram.borrow_mut().as_addressable().unwrap().len(); - let rom_len = rom.borrow_mut().as_addressable().unwrap().len(); let mainboard = Self { lower_bus: lower_bus.clone(), @@ -51,13 +48,13 @@ impl Mainboard { mainboard.via.port_a.set_observer(move |port| { if (port.data & 0x10) == 0 { println!("{}: overlay is 0 (normal)", DEV_NAME); - lower_bus.borrow_mut().blocks.clear(); + lower_bus.borrow_mut().clear_all_bus_devices(); lower_bus.borrow_mut().insert(0x000000, wrap_transmutable(AddressRepeater::new(ram.clone(), 32))); lower_bus.borrow_mut().insert(0x400000, wrap_transmutable(AddressRepeater::new(rom.clone(), 16))); lower_bus.borrow_mut().insert(0x600000, wrap_transmutable(AddressRepeater::new(rom.clone(), 16))); } else { println!("{}: overlay is 1 (startup)", DEV_NAME); - lower_bus.borrow_mut().blocks.clear(); + lower_bus.borrow_mut().clear_all_bus_devices(); lower_bus.borrow_mut().insert(0x000000, wrap_transmutable(AddressRepeater::new(rom.clone(), 16))); lower_bus.borrow_mut().insert(0x200000, wrap_transmutable(AddressRepeater::new(rom.clone(), 16))); lower_bus.borrow_mut().insert(0x400000, wrap_transmutable(AddressRepeater::new(rom.clone(), 16))); @@ -82,14 +79,13 @@ impl Addressable for Mainboard { } else if addr >= 0x900000 && addr < 0xA00000 { self.scc1.read((addr >> 9) & 0x0F, data) } else if addr >= 0xB00000 && addr < 0xC00000 { - self.scc1.read((addr >> 9) & 0x0F, data) + self.scc2.read((addr >> 9) & 0x0F, data) } else if addr >= 0xD00000 && addr < 0xE00000 { self.iwm.read((addr >> 9) & 0x0F, data) } else if addr >= 0xE80000 && addr < 0xF00000 { self.via.read((addr >> 9) & 0x0F, data) } else if addr >= 0xF00000 && addr < 0xF80000 { - // TODO phase read - Ok(()) + self.phase_read.read(addr, data) } else if addr >= 0xF80000 && addr < 0xF80010 { // Debugger Ok(()) @@ -104,14 +100,13 @@ impl Addressable for Mainboard { } else if addr >= 0x900000 && addr < 0xA00000 { self.scc1.write((addr >> 9) & 0x0F, data) } else if addr >= 0xB00000 && addr < 0xC00000 { - self.scc1.write((addr >> 9) & 0x0F, data) + self.scc2.write((addr >> 9) & 0x0F, data) } else if addr >= 0xD00000 && addr < 0xE00000 { self.iwm.write((addr >> 9) & 0x0F, data) } else if addr >= 0xE80000 && addr < 0xF00000 { self.via.write((addr >> 9) & 0x0F, data) } else if addr >= 0xF00000 && addr < 0xF80000 { - // TODO phase read - Ok(()) + self.phase_read.write(addr, data) } else { Err(Error::new(&format!("Error writing address {:#010x}", addr))) } @@ -161,13 +156,14 @@ impl Addressable for PhaseRead { 0x80000 } - fn read(&mut self, addr: Address, data: &mut [u8]) -> Result<(), Error> { - + fn read(&mut self, _addr: Address, data: &mut [u8]) -> Result<(), Error> { + // TODO I'm not sure how this is supposed to work + data[0] = 0x00; Ok(()) } - fn write(&mut self, addr: Address, data: &[u8]) -> Result<(), Error> { - + fn write(&mut self, _addr: Address, _data: &[u8]) -> Result<(), Error> { + // TODO I'm not sure how this is supposed to work Ok(()) } } @@ -175,8 +171,8 @@ impl Addressable for PhaseRead { pub struct AddressRepeater { - pub subdevice: TransmutableBox, - pub repeat: u8, + subdevice: TransmutableBox, + repeat: u8, } impl AddressRepeater { diff --git a/src/peripherals/macintosh/video.rs b/src/peripherals/macintosh/video.rs index 222913d..606b3fd 100644 --- a/src/peripherals/macintosh/video.rs +++ b/src/peripherals/macintosh/video.rs @@ -12,7 +12,7 @@ use crate::host::traits::{Host, BlitableSurface}; const SCRN_BASE: u32 = 0x07A700; pub struct MacVideo { - pub frame: Arc>, + frame: Arc>, } impl MacVideo { @@ -28,8 +28,8 @@ impl MacVideo { } pub struct BitIter { - pub bit: i8, - pub data: u16, + bit: i8, + data: u16, } impl BitIter { diff --git a/src/peripherals/mc68681.rs b/src/peripherals/mc68681.rs index 0b1c64c..d3e34ad 100644 --- a/src/peripherals/mc68681.rs +++ b/src/peripherals/mc68681.rs @@ -58,12 +58,12 @@ const SR_RX_READY: u8 = 0x01; // Interrupt Status/Mask Bits (ISR/IVR) -const ISR_INPUT_CHANGE: u8 = 0x80; -const ISR_CH_B_BREAK_CHANGE: u8 = 0x40; +//const ISR_INPUT_CHANGE: u8 = 0x80; +//const ISR_CH_B_BREAK_CHANGE: u8 = 0x40; const ISR_CH_B_RX_READY_FULL: u8 = 0x20; const ISR_CH_B_TX_READY: u8 = 0x10; const ISR_TIMER_CHANGE: u8 = 0x08; -const ISR_CH_A_BREAK_CHANGE: u8 = 0x04; +//const ISR_CH_A_BREAK_CHANGE: u8 = 0x04; const ISR_CH_A_RX_READY_FULL: u8 = 0x02; const ISR_CH_A_TX_READY: u8 = 0x01; @@ -71,13 +71,13 @@ const ISR_CH_A_TX_READY: u8 = 0x01; const DEV_NAME: &'static str = "mc68681"; pub struct MC68681Port { - pub tty: Option>, - pub status: u8, + tty: Option>, + status: u8, - pub tx_enabled: bool, + tx_enabled: bool, - pub rx_enabled: bool, - pub input: u8, + rx_enabled: bool, + input: u8, } impl MC68681Port { @@ -164,23 +164,23 @@ impl MC68681Port { } pub struct MC68681 { - pub acr: u8, + acr: u8, pub port_a: MC68681Port, pub port_b: MC68681Port, - pub int_mask: u8, - pub int_status: u8, - pub int_vector: u8, + int_mask: u8, + int_status: u8, + int_vector: u8, - pub timer_preload: u16, - pub timer_count: u16, - pub is_timing: bool, - pub timer_divider: u16, + timer_preload: u16, + timer_count: u16, + is_timing: bool, + timer_divider: u16, - pub input_pin_change: u8, - pub input_state: u8, - pub output_conf: u8, - pub output_state: u8, + input_pin_change: u8, + input_state: u8, + output_conf: u8, + output_state: u8, } impl MC68681 { diff --git a/src/peripherals/mos6522.rs b/src/peripherals/mos6522.rs index f92eba8..35e0cd2 100644 --- a/src/peripherals/mos6522.rs +++ b/src/peripherals/mos6522.rs @@ -102,7 +102,7 @@ impl Addressable for Mos6522 { } impl Steppable for Mos6522 { - fn step(&mut self, system: &System) -> Result { + fn step(&mut self, _system: &System) -> Result { Ok(16_600_000) } diff --git a/src/peripherals/sn76489.rs b/src/peripherals/sn76489.rs index 5535c2f..442333b 100644 --- a/src/peripherals/sn76489.rs +++ b/src/peripherals/sn76489.rs @@ -2,26 +2,12 @@ use crate::error::Error; use crate::system::System; use crate::devices::{ClockElapsed, Address, Addressable, Steppable, Transmutable}; -use crate::host::audio::{SineWave, SquareWave}; +use crate::host::audio::{SquareWave}; use crate::host::traits::{Host, Audio}; const DEV_NAME: &'static str = "sn76489"; -/* -pub struct Sn76489Updater(HostData); - -impl AudioUpdater for Sn76489Updater { - fn update_audio_frame(&mut self, samples: usize, sample_rate: usize, buffer: &mut [f32]) { - let mut sine = self.0.lock(); - //for i in 0..samples { - // buffer[i] = sine.next().unwrap(); - //} - } -} -*/ - - pub struct Sn76489 { pub regs: [u8; 8], pub first_byte: Option, @@ -52,8 +38,8 @@ impl Steppable for Sn76489 { self.sine.frequency -= 1.0; } - let rate = self.source.samples_per_second(); - self.source.write_samples(rate / 1000, &mut self.sine); + //let rate = self.source.samples_per_second(); + //self.source.write_samples(rate / 1000, &mut self.sine); //println!("{}", self.sine.frequency); Ok(1_000_000) // Every 1ms of simulated time } @@ -64,7 +50,7 @@ impl Addressable for Sn76489 { 0x01 } - fn read(&mut self, addr: Address, data: &mut [u8]) -> Result<(), Error> { + fn read(&mut self, _addr: Address, _data: &mut [u8]) -> Result<(), Error> { warning!("{}: !!! device can't be read", DEV_NAME); Ok(()) } diff --git a/src/peripherals/trs80/model1.rs b/src/peripherals/trs80/model1.rs index 4aec812..f7aece4 100644 --- a/src/peripherals/trs80/model1.rs +++ b/src/peripherals/trs80/model1.rs @@ -16,9 +16,9 @@ use super::charset::CharacterGenerator; const DEV_NAME: &'static str = "model1"; pub struct Model1Peripherals { - pub frame: Arc>, - pub keyboard_mem: Arc>, - pub video_mem: [u8; 1024], + frame: Arc>, + keyboard_mem: Arc>, + video_mem: [u8; 1024], } impl Model1Peripherals { diff --git a/src/peripherals/ym2612.rs b/src/peripherals/ym2612.rs index 6e548bf..88e283d 100644 --- a/src/peripherals/ym2612.rs +++ b/src/peripherals/ym2612.rs @@ -4,7 +4,7 @@ use std::num::NonZeroU8; use crate::error::Error; use crate::system::System; use crate::devices::{ClockElapsed, Address, Addressable, Steppable, Transmutable}; -use crate::host::audio::{SineWave, SquareWave}; +use crate::host::audio::{SquareWave}; use crate::host::traits::{Host, Audio}; const DEV_NAME: &'static str = "ym2612"; @@ -53,7 +53,7 @@ impl Ym2612 { Ok(Self { source, selected_reg: None, - channels: vec![Channel::new(sample_rate); 6], + channels: vec![Channel::new(sample_rate); 7], }) } @@ -64,6 +64,9 @@ impl Ym2612 { self.channels[ch].on = data >> 4; println!("Note: {}: {:x}", ch, self.channels[ch].on); }, + 0x30 => { + let _op = if bank == 0 { 0 } else { 3 }; + } _ => warning!("{}: !!! unhandled write to register {:0x} with {:0x}", DEV_NAME, reg, data), } } diff --git a/src/peripherals/z8530.rs b/src/peripherals/z8530.rs index 844970c..673b80c 100644 --- a/src/peripherals/z8530.rs +++ b/src/peripherals/z8530.rs @@ -43,15 +43,21 @@ impl Addressable for Z8530 { } } +impl Steppable for Z8530 { + fn step(&mut self, _system: &System) -> Result { + + Ok(1_000_000_00) + } +} impl Transmutable for Z8530 { fn as_addressable(&mut self) -> Option<&mut dyn Addressable> { Some(self) } - //fn as_steppable(&mut self) -> Option<&mut dyn Steppable> { - // Some(self) - //} + fn as_steppable(&mut self) -> Option<&mut dyn Steppable> { + Some(self) + } } diff --git a/src/signals.rs b/src/signals.rs index 7c5967a..ffaf04f 100644 --- a/src/signals.rs +++ b/src/signals.rs @@ -9,10 +9,14 @@ pub trait Observable { // TODO these could be used to imply how it should be used, or they could even be shorthands for T=bool, except TriState which would have 3 // TODO or maybe even tristate is T=Option +#[allow(dead_code)] type Output = Signal; +#[allow(dead_code)] type Input = Signal; +#[allow(dead_code)] type TriState = Signal; + #[derive(Clone, Debug)] pub struct Signal(Rc>); diff --git a/src/system.rs b/src/system.rs index d972857..9779c12 100644 --- a/src/system.rs +++ b/src/system.rs @@ -99,7 +99,7 @@ impl System { pub fn step(&mut self) -> Result<(), Error> { if self.debug_enabled.get() && self.event_queue[self.event_queue.len() - 1].device.borrow_mut().as_debuggable().is_some() { - self.debugger.borrow_mut().run_debugger(&self, self.event_queue[self.event_queue.len() - 1].device.clone()); + self.debugger.borrow_mut().run_debugger(&self, self.event_queue[self.event_queue.len() - 1].device.clone()).unwrap(); } match self.process_one_event() { diff --git a/todo.txt b/todo.txt index 07abb39..6d88a4f 100644 --- a/todo.txt +++ b/todo.txt @@ -16,7 +16,6 @@ a callback with the frontend sound system that is called when it needs data, or you write to a shared buffer which is passed back to the frontend when it needs it, or it has a copy it can use directly -* add sound * should you rename devices.rs traits.rs? * add command line arguments to speed up or slow down either the frame rate limiter or the simulated time per frame