diff --git a/Cargo.toml b/Cargo.toml index a599d7f..2e69cdf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,13 +4,8 @@ version = "0.1.0" edition = "2018" [workspace] -members = [".", "frontends/moa-console", "frontends/moa-minifb"] +members = [".", "frontends/moa-common", "frontends/moa-console", "frontends/moa-minifb"] default-members = ["frontends/moa-console"] -[features] -default = ["tty"] -tty = ["nix"] - [dependencies] -nix = { version = "0.23", optional = true } diff --git a/frontends/moa-common/Cargo.toml b/frontends/moa-common/Cargo.toml new file mode 100644 index 0000000..35f26f6 --- /dev/null +++ b/frontends/moa-common/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "moa-common" +version = "0.1.0" +edition = "2018" + +[features] +tty = ["nix"] + +[dependencies] +moa = { path = "../../" } +nix = { version = "0.23", optional = true } + diff --git a/frontends/moa-common/src/lib.rs b/frontends/moa-common/src/lib.rs new file mode 100644 index 0000000..72fdffd --- /dev/null +++ b/frontends/moa-common/src/lib.rs @@ -0,0 +1,3 @@ + +pub mod tty; + diff --git a/src/host/tty.rs b/frontends/moa-common/src/tty.rs similarity index 96% rename from src/host/tty.rs rename to frontends/moa-common/src/tty.rs index 1e997fa..30672eb 100644 --- a/src/host/tty.rs +++ b/frontends/moa-common/src/tty.rs @@ -3,14 +3,13 @@ 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}; use nix::fcntl::{fcntl, FcntlArg}; -use crate::error::Error; -use crate::host::traits::Tty; +use moa::error::Error; +use moa::host::traits::Tty; pub struct SimplePty { diff --git a/frontends/moa-console/Cargo.toml b/frontends/moa-console/Cargo.toml index 56c9f61..d2b8103 100644 --- a/frontends/moa-console/Cargo.toml +++ b/frontends/moa-console/Cargo.toml @@ -5,5 +5,6 @@ edition = "2018" default-run = "moa-computie" [dependencies] -moa = { path = "../../", features = ["tty"] } +moa = { path = "../../" } +moa-common = { path = "../moa-common", features = ["tty"] } diff --git a/frontends/moa-console/src/lib.rs b/frontends/moa-console/src/lib.rs index f81046e..c554af9 100644 --- a/frontends/moa-console/src/lib.rs +++ b/frontends/moa-console/src/lib.rs @@ -1,10 +1,15 @@ use moa::error::Error; -use moa::host::traits::{Host, WindowUpdater}; +use moa::host::traits::{Host, Tty, WindowUpdater}; pub struct ConsoleFrontend; impl Host for ConsoleFrontend { + fn create_pty(&self) -> Result, Error> { + use moa_common::tty::SimplePty; + Ok(Box::new(SimplePty::open()?)) + } + 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/src/host/traits.rs b/src/host/traits.rs index bb00c1c..e4c6744 100644 --- a/src/host/traits.rs +++ b/src/host/traits.rs @@ -6,10 +6,21 @@ use crate::host::keys::Key; use crate::host::controllers::{ControllerDevice, ControllerEvent}; pub trait Host { - //fn create_pty(&self) -> Result, Error>; - fn add_window(&mut self, updater: Box) -> Result<(), Error>; - fn register_controller(&mut self, _device: ControllerDevice, _input: Box) -> Result<(), Error> { Err(Error::new("Not supported")) } - fn register_keyboard(&mut self, _input: Box) -> Result<(), Error> { Err(Error::new("Not supported")) } + fn create_pty(&self) -> Result, Error> { + Err(Error::new("This frontend doesn't support PTYs")) + } + + fn add_window(&mut self, updater: Box) -> Result<(), Error> { + Err(Error::new("This frontend doesn't support windows")) + } + + fn register_controller(&mut self, _device: ControllerDevice, _input: Box) -> Result<(), Error> { + Err(Error::new("This frontend doesn't support game controllers")) + } + + fn register_keyboard(&mut self, _input: Box) -> Result<(), Error> { + Err(Error::new("This frontend doesn't support the keyboard")) + } } pub trait Tty { diff --git a/src/machines/computie.rs b/src/machines/computie.rs index a570969..8fc5ab5 100644 --- a/src/machines/computie.rs +++ b/src/machines/computie.rs @@ -9,7 +9,6 @@ use crate::peripherals::ata::AtaDevice; use crate::peripherals::mc68681::MC68681; use crate::host::traits::Host; -use crate::host::tty::SimplePty; pub fn build_computie(host: &H) -> Result { @@ -27,8 +26,8 @@ pub fn build_computie(host: &H) -> Result { system.add_addressable_device(0x00600000, wrap_transmutable(ata))?; let mut serial = MC68681::new(); - launch_terminal_emulator(serial.port_a.connect(Box::new(SimplePty::open()?))?); - launch_slip_connection(serial.port_b.connect(Box::new(SimplePty::open()?))?); + launch_terminal_emulator(serial.port_a.connect(host.create_pty()?)?); + launch_slip_connection(serial.port_b.connect(host.create_pty()?)?); system.add_addressable_device(0x00700000, wrap_transmutable(serial))?; @@ -65,8 +64,8 @@ pub fn build_computie_k30(host: &H) -> Result { system.add_addressable_device(0x00600000, wrap_transmutable(ata))?; let mut serial = MC68681::new(); - launch_terminal_emulator(serial.port_a.connect(Box::new(SimplePty::open()?))?); - //launch_slip_connection(serial.port_b.connect(Box::new(SimplePty::open()?))?); + launch_terminal_emulator(serial.port_a.connect(host.create_pty()?)?); + //launch_slip_connection(serial.port_b.connect(host.create_pty()?)?); system.add_addressable_device(0x00700000, wrap_transmutable(serial))?;