mirror of
https://github.com/transistorfet/moa.git
synced 2024-05-29 04:41:29 +00:00
Put the types and traits from system into new devices file
This commit is contained in:
parent
8bb43f61ee
commit
c4f41d73ab
|
@ -3,7 +3,7 @@ use crate::error::Error;
|
|||
use crate::system::System;
|
||||
use crate::memory::{Address, Addressable};
|
||||
|
||||
use super::state::{MC68010};
|
||||
use super::state::MC68010;
|
||||
|
||||
pub struct StackTracer {
|
||||
pub calls: Vec<u32>,
|
||||
|
|
|
@ -2,8 +2,9 @@
|
|||
use std::fmt;
|
||||
|
||||
use crate::error::Error;
|
||||
use crate::memory::{Address};
|
||||
use crate::system::{System, AddressableDeviceRefMut};
|
||||
use crate::system::System;
|
||||
use crate::memory::Address;
|
||||
use crate::devices::AddressableDeviceRefMut;
|
||||
|
||||
use super::state::ERR_ILLEGAL_INSTRUCTION;
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
|
||||
use crate::error::Error;
|
||||
use crate::system::System;
|
||||
use crate::memory::{Address, Addressable};
|
||||
use crate::system::{System, Clock, Steppable, Interruptable};
|
||||
use crate::devices::{Clock, Steppable, Interruptable};
|
||||
|
||||
use super::decode::{
|
||||
M68kDecoder,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
use crate::system::System;
|
||||
use crate::memory::Address;
|
||||
use crate::timers::CpuTimer;
|
||||
use crate::memory::{Address};
|
||||
use crate::system::{System};
|
||||
|
||||
use super::decode::M68kDecoder;
|
||||
use super::debugger::M68kDebugger;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
use crate::system::System;
|
||||
use crate::devices::{Steppable, wrap_addressable};
|
||||
use crate::memory::{Address, Addressable, MemoryBlock};
|
||||
use crate::system::{System, Steppable, wrap_addressable};
|
||||
|
||||
use super::state::MC68010;
|
||||
use super::decode::Instruction;
|
||||
|
|
47
src/devices.rs
Normal file
47
src/devices.rs
Normal file
|
@ -0,0 +1,47 @@
|
|||
|
||||
use std::rc::Rc;
|
||||
use std::cell::{RefCell, RefMut};
|
||||
|
||||
use crate::error::Error;
|
||||
use crate::system::System;
|
||||
use crate::memory::{Addressable};
|
||||
|
||||
|
||||
pub type Clock = u64;
|
||||
|
||||
|
||||
pub trait Steppable {
|
||||
fn step(&mut self, system: &System) -> Result<Clock, Error>;
|
||||
fn on_error(&mut self, _system: &System) { }
|
||||
}
|
||||
|
||||
pub trait Interruptable {
|
||||
fn interrupt_state_change(&mut self, system: &System, state: bool, priority: u8, number: u8) -> Result<(), Error>;
|
||||
}
|
||||
|
||||
pub trait AddressableDevice: Addressable + Steppable { }
|
||||
pub trait InterruptableDevice: Interruptable + Steppable { }
|
||||
|
||||
impl<T: Addressable + Steppable> AddressableDevice for T { }
|
||||
impl<T: Interruptable + Steppable> InterruptableDevice for T { }
|
||||
|
||||
pub type AddressableDeviceBox = Rc<RefCell<Box<dyn AddressableDevice>>>;
|
||||
pub type InterruptableDeviceBox = Rc<RefCell<Box<dyn InterruptableDevice>>>;
|
||||
|
||||
pub type AddressableDeviceRefMut<'a> = RefMut<'a, Box<dyn AddressableDevice>>;
|
||||
|
||||
pub fn wrap_addressable<T: AddressableDevice + 'static>(value: T) -> AddressableDeviceBox {
|
||||
Rc::new(RefCell::new(Box::new(value)))
|
||||
}
|
||||
|
||||
pub fn wrap_interruptable<T: InterruptableDevice + 'static>(value: T) -> InterruptableDeviceBox {
|
||||
Rc::new(RefCell::new(Box::new(value)))
|
||||
}
|
||||
|
||||
|
||||
pub enum Device {
|
||||
Addressable(AddressableDeviceBox),
|
||||
Interruptable(InterruptableDeviceBox),
|
||||
}
|
||||
|
||||
|
38
src/interrupts.rs
Normal file
38
src/interrupts.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
|
||||
use crate::error::Error;
|
||||
|
||||
|
||||
pub struct Signal {
|
||||
pub current: bool,
|
||||
pub previous: bool,
|
||||
}
|
||||
|
||||
impl Signal {
|
||||
pub fn new() -> Signal {
|
||||
Signal {
|
||||
current: false,
|
||||
previous: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn check_change<F>(&mut self, f: F) -> Result<(), Error> where F: Fn(bool) -> Result<(), Error> {
|
||||
if self.current != self.previous {
|
||||
self.previous = self.current;
|
||||
f(self.current)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set(&mut self, value: bool) {
|
||||
self.current = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
pub struct InterruptController {
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -3,15 +3,18 @@
|
|||
mod error;
|
||||
mod memory;
|
||||
mod timers;
|
||||
mod devices;
|
||||
mod interrupts;
|
||||
mod cpus;
|
||||
mod peripherals;
|
||||
mod system;
|
||||
|
||||
use crate::system::System;
|
||||
use crate::memory::MemoryBlock;
|
||||
use crate::cpus::m68k::MC68010;
|
||||
use crate::peripherals::ata::AtaDevice;
|
||||
use crate::peripherals::mc68681::MC68681;
|
||||
use crate::system::{System, wrap_addressable, wrap_interruptable};
|
||||
use crate::devices::{wrap_addressable, wrap_interruptable};
|
||||
|
||||
fn main() {
|
||||
let mut system = System::new();
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
use std::fs;
|
||||
|
||||
use crate::error::Error;
|
||||
use crate::system::{Clock, Steppable, AddressableDeviceBox, System};
|
||||
use crate::system::System;
|
||||
use crate::devices::{Clock, Steppable, AddressableDeviceBox};
|
||||
|
||||
|
||||
pub type Address = u64;
|
||||
|
|
|
@ -2,8 +2,9 @@
|
|||
use std::fs;
|
||||
|
||||
use crate::error::Error;
|
||||
use crate::system::System;
|
||||
use crate::memory::{Address, Addressable};
|
||||
use crate::system::{Clock, Steppable, System};
|
||||
use crate::devices::{Clock, Steppable};
|
||||
|
||||
|
||||
const ATA_REG_DEV_CONTROL: Address = 0x1D;
|
||||
|
|
|
@ -3,13 +3,14 @@ use std::process::Command;
|
|||
use std::io::{Read, Write};
|
||||
use std::os::unix::io::AsRawFd;
|
||||
|
||||
use nix::pty::{self, PtyMaster};
|
||||
use nix::fcntl::OFlag;
|
||||
use nix::unistd::sleep;
|
||||
use nix::pty::{self, PtyMaster};
|
||||
use nix::fcntl::{fcntl, FcntlArg};
|
||||
|
||||
use crate::error::Error;
|
||||
use crate::system::{Clock, Steppable, System};
|
||||
use crate::system::System;
|
||||
use crate::devices::{Clock, Steppable};
|
||||
use crate::memory::{Address, Addressable};
|
||||
|
||||
|
||||
|
|
|
@ -3,46 +3,11 @@ use std::rc::Rc;
|
|||
use std::cell::{RefCell, RefMut};
|
||||
|
||||
use crate::error::Error;
|
||||
use crate::interrupts::Signal;
|
||||
use crate::memory::{Address, Addressable, Bus};
|
||||
use crate::devices::{Device, Steppable, AddressableDeviceBox, InterruptableDeviceBox, Clock};
|
||||
|
||||
|
||||
pub type Clock = u64;
|
||||
|
||||
|
||||
pub trait Steppable {
|
||||
fn step(&mut self, system: &System) -> Result<Clock, Error>;
|
||||
fn on_error(&mut self, _system: &System) { }
|
||||
}
|
||||
|
||||
pub trait Interruptable {
|
||||
fn interrupt_state_change(&mut self, system: &System, state: bool, priority: u8, number: u8) -> Result<(), Error>;
|
||||
}
|
||||
|
||||
pub trait AddressableDevice: Addressable + Steppable { }
|
||||
pub trait InterruptableDevice: Interruptable + Steppable { }
|
||||
|
||||
impl<T: Addressable + Steppable> AddressableDevice for T { }
|
||||
impl<T: Interruptable + Steppable> InterruptableDevice for T { }
|
||||
|
||||
pub type AddressableDeviceBox = Rc<RefCell<Box<dyn AddressableDevice>>>;
|
||||
pub type InterruptableDeviceBox = Rc<RefCell<Box<dyn InterruptableDevice>>>;
|
||||
|
||||
pub type AddressableDeviceRefMut<'a> = RefMut<'a, Box<dyn AddressableDevice>>;
|
||||
|
||||
pub fn wrap_addressable<T: AddressableDevice + 'static>(value: T) -> AddressableDeviceBox {
|
||||
Rc::new(RefCell::new(Box::new(value)))
|
||||
}
|
||||
|
||||
pub fn wrap_interruptable<T: InterruptableDevice + 'static>(value: T) -> InterruptableDeviceBox {
|
||||
Rc::new(RefCell::new(Box::new(value)))
|
||||
}
|
||||
|
||||
|
||||
pub enum Device {
|
||||
Addressable(AddressableDeviceBox),
|
||||
Interruptable(InterruptableDeviceBox),
|
||||
}
|
||||
|
||||
pub struct System {
|
||||
pub clock: Clock,
|
||||
pub devices: Vec<Device>,
|
||||
|
@ -112,8 +77,3 @@ impl System {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct InterruptController {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user