From 8d39d845451fe7f753970138a09394ef324dce98 Mon Sep 17 00:00:00 2001 From: transistor Date: Wed, 20 Oct 2021 15:53:25 -0700 Subject: [PATCH] Refactored to separate out the commands, and machine configs Machine definitions are now in their own module and can be optionally compiled in, and there is now a console and soon to be gui version of the compiled binary, with individual binaries for each machine --- frontends/moa-console/Cargo.toml | 9 +++ frontends/moa-console/src/bin/moa-computie.rs | 10 +++ frontends/moa-console/src/lib.rs | 16 +++++ src/host/frontend/mod.rs | 11 ++++ src/host/frontend/traits.rs | 21 ++++++ src/host/mod.rs | 3 + src/lib.rs | 14 ++++ src/{main.rs => machines/computie.rs} | 64 ++++++++++++------- src/machines/mod.rs | 3 + todo.txt | 6 ++ 10 files changed, 134 insertions(+), 23 deletions(-) create mode 100644 frontends/moa-console/Cargo.toml create mode 100644 frontends/moa-console/src/bin/moa-computie.rs create mode 100644 frontends/moa-console/src/lib.rs create mode 100644 src/host/frontend/mod.rs create mode 100644 src/host/frontend/traits.rs create mode 100644 src/lib.rs rename src/{main.rs => machines/computie.rs} (64%) create mode 100644 src/machines/mod.rs diff --git a/frontends/moa-console/Cargo.toml b/frontends/moa-console/Cargo.toml new file mode 100644 index 0000000..56c9f61 --- /dev/null +++ b/frontends/moa-console/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "moa-console" +version = "0.1.0" +edition = "2018" +default-run = "moa-computie" + +[dependencies] +moa = { path = "../../", features = ["tty"] } + diff --git a/frontends/moa-console/src/bin/moa-computie.rs b/frontends/moa-console/src/bin/moa-computie.rs new file mode 100644 index 0000000..6bdabd3 --- /dev/null +++ b/frontends/moa-console/src/bin/moa-computie.rs @@ -0,0 +1,10 @@ + +use moa_console::ConsoleFrontend; +use moa::machines::computie::run_computie; + +fn main() { + let mut frontend = ConsoleFrontend; + + run_computie(&mut frontend); +} + diff --git a/frontends/moa-console/src/lib.rs b/frontends/moa-console/src/lib.rs new file mode 100644 index 0000000..bf62020 --- /dev/null +++ b/frontends/moa-console/src/lib.rs @@ -0,0 +1,16 @@ + +use moa::error::Error; +use moa::host::frontend::{Frontend, SharedCanvas, SharedAudio}; + +pub struct ConsoleFrontend; + +impl Frontend for ConsoleFrontend { + fn get_canvas(&mut self) -> Result { + Err(Error::new("Console frontend doesn't support canvas")) + } + + fn get_audio(&mut self) -> Result { + Err(Error::new("Console frontend doesn't support audio")) + } +} + diff --git a/src/host/frontend/mod.rs b/src/host/frontend/mod.rs new file mode 100644 index 0000000..3ac59d1 --- /dev/null +++ b/src/host/frontend/mod.rs @@ -0,0 +1,11 @@ + +pub mod traits; + +pub use self::traits::{ + Frontend, + Canvas, + SharedCanvas, + Audio, + SharedAudio, +}; + diff --git a/src/host/frontend/traits.rs b/src/host/frontend/traits.rs new file mode 100644 index 0000000..ea5b9e5 --- /dev/null +++ b/src/host/frontend/traits.rs @@ -0,0 +1,21 @@ + +use std::sync::{Arc, Mutex}; + +use crate::error::Error; + +pub trait Canvas { + fn draw_bitmap(&mut self, x: u32, y: u32, bitmap: &[u8]); +} + +pub trait Audio { + +} + +pub type SharedCanvas = Arc>>; +pub type SharedAudio = Arc>>; + +pub trait Frontend { + fn get_canvas(&mut self) -> Result; + fn get_audio(&mut self) -> Result; +} + diff --git a/src/host/mod.rs b/src/host/mod.rs index 30d919b..7bb6bab 100644 --- a/src/host/mod.rs +++ b/src/host/mod.rs @@ -1,3 +1,6 @@ +pub mod frontend; + +#[cfg(feature = "tty")] pub mod tty; diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..3b3cdec --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,14 @@ + +#[macro_use] +pub mod error; +pub mod memory; +pub mod timers; +pub mod devices; +pub mod interrupts; +pub mod system; + +pub mod host; +pub mod cpus; +pub mod peripherals; +pub mod machines; + diff --git a/src/main.rs b/src/machines/computie.rs similarity index 64% rename from src/main.rs rename to src/machines/computie.rs index 042af28..a137ac8 100644 --- a/src/main.rs +++ b/src/machines/computie.rs @@ -1,32 +1,18 @@ -#[macro_use] -mod error; -mod memory; -mod timers; -mod devices; -mod interrupts; -mod system; - -mod host; -mod cpus; -mod peripherals; - use crate::system::System; use crate::memory::MemoryBlock; -use crate::peripherals::ata::AtaDevice; -use crate::cpus::m68k::{M68k, M68kType}; -use crate::peripherals::mc68681::MC68681; +use crate::host::frontend::Frontend; use crate::devices::wrap_transmutable; -fn main() { - run_computie(); -} +use crate::cpus::m68k::{M68k, M68kType}; +use crate::peripherals::ata::AtaDevice; +use crate::peripherals::mc68681::MC68681; -fn run_computie() { + +pub fn run_computie(frontend: &mut dyn Frontend) { let mut system = System::new(); let monitor = MemoryBlock::load("binaries/monitor.bin").unwrap(); - //let monitor = MemoryBlock::load("binaries/monitor-68030.bin").unwrap(); for byte in monitor.contents.iter() { print!("{:02x} ", byte); } @@ -34,7 +20,6 @@ fn run_computie() { let mut ram = MemoryBlock::new(vec![0; 0x00100000]); ram.load_at(0, "binaries/kernel.bin").unwrap(); - //ram.load_at(0, "binaries/kernel-68030.bin").unwrap(); system.add_addressable_device(0x00100000, wrap_transmutable(ram)).unwrap(); let mut ata = AtaDevice::new(); @@ -48,7 +33,41 @@ fn run_computie() { let mut cpu = M68k::new(M68kType::MC68010); - //let mut cpu = M68k::new(M68kType::MC68030); + + //cpu.enable_tracing(); + //cpu.add_breakpoint(0x10781a); + //cpu.add_breakpoint(0x10bc9c); + //cpu.add_breakpoint(0x106a94); + //cpu.add_breakpoint(0x1015b2); + //cpu.add_breakpoint(0x103332); + //cpu.decoder.dump_disassembly(&mut system, 0x100000, 0x2000); + //cpu.decoder.dump_disassembly(&mut system, 0x2ac, 0x200); + + system.add_interruptable_device(wrap_transmutable(cpu)).unwrap(); + system.run_loop(); +} + +pub fn run_computie_k30(frontend: &mut dyn Frontend) { + let mut system = System::new(); + + let monitor = MemoryBlock::load("binaries/monitor-68030.bin").unwrap(); + system.add_addressable_device(0x00000000, wrap_transmutable(monitor)).unwrap(); + + let mut ram = MemoryBlock::new(vec![0; 0x00100000]); + ram.load_at(0, "binaries/kernel-68030.bin").unwrap(); + system.add_addressable_device(0x00100000, wrap_transmutable(ram)).unwrap(); + + let mut ata = AtaDevice::new(); + ata.load("binaries/disk-with-partition-table.img").unwrap(); + system.add_addressable_device(0x00600000, wrap_transmutable(ata)).unwrap(); + + let mut serial = MC68681::new(); + launch_terminal_emulator(serial.port_a.open().unwrap()); + //launch_slip_connection(serial.port_b.open().unwrap()); + system.add_addressable_device(0x00700000, wrap_transmutable(serial)).unwrap(); + + + let mut cpu = M68k::new(M68kType::MC68030); //cpu.enable_tracing(); //cpu.add_breakpoint(0x10781a); @@ -83,4 +102,3 @@ pub fn launch_slip_connection(name: String) { Command::new("sudo").args(["sh", "-c", "echo 1 > /proc/sys/net/ipv4/ip_forward"]).status().unwrap(); } - diff --git a/src/machines/mod.rs b/src/machines/mod.rs new file mode 100644 index 0000000..5813805 --- /dev/null +++ b/src/machines/mod.rs @@ -0,0 +1,3 @@ + +pub mod computie; + diff --git a/todo.txt b/todo.txt index 3f26199..16ca3e3 100644 --- a/todo.txt +++ b/todo.txt @@ -1,4 +1,10 @@ +* should the frontend and simulator parts be separated so that the simulator part can be a library package? +* it should be call something other than canvas because it'll have input as well +* how will you get the canvas/app shared object between the sim thread and the io thread? It kind of has to be passed through the system-creation + functions (an only if they need them), which raises questions about how to configure things. It'd be nice if you could still run the same hardware + simulated without using a frontend + * can you eventually make the system connections all configurable via a config file? * test using mpsc to pass messages with the tty IO thread, and test if it's slower than what you have now