diff --git a/.gitignore b/.gitignore index f4ed99a..75f2eee 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ # Rust files +**/target +**/Cargo.lock /target Cargo.lock flamegraph.svg diff --git a/Cargo.toml b/Cargo.toml index 1ce8546..fdca0be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,12 +1,22 @@ -[package] -name = "chirp" +[workspace] +members = ["chirp-imgui", "chirp-minifb"] +# default-members = ["chirp-imgui"] + +[workspace.package] version = "0.1.1" edition = "2021" -default-run = "chirp-imgui" authors = ["John Breaux"] license = "MIT" publish = false +[package] +name = "chirp" +version.workspace = true +edition.workspace = true +authors.workspace = true +license.workspace = true +publish.workspace = true + [[bin]] name = "chirp" path = "src/bin/chirp-minifb/main.rs" @@ -16,26 +26,14 @@ required-features = ["minifb"] name = "chirp-disasm" required-features = ["default"] -[[bin]] -name = "chirp-imgui" -required-features = ["imgui"] - [[bin]] name = "chirp-shot-viewer" required-features = ["default", "drawille"] [features] -default = ["drawille", "imgui", "serde"] +default = ["drawille", "serde"] nightly = [] drawille = ["dep:drawille"] -imgui = [ - "dep:imgui", - "dep:imgui-wgpu", - "dep:imgui-winit-support", - "dep:winit", - "dep:winit_input_helper", - "dep:pixels", -] minifb = ["dep:minifb"] rhexdump = ["dep:rhexdump"] @@ -54,14 +52,6 @@ overflow-checks = false [dependencies] -imgui = { version = "^0.10", optional = true } -imgui-winit-support = { version = "^0.10", optional = true } -imgui-wgpu = { version = "^0", optional = true } -pixels = { version = "^0", optional = true } -# TODO: When imgui-winit-support updates to 0.28 (Soon:tm:), update winit and winit_input_helper -winit = { version = "0.27.5", features = ["default", "x11"], optional = true } -winit_input_helper = { version = "^0.13.0", optional = true } - drawille = { version = "0.3.0", optional = true } rhexdump = { version = "0.1.1", optional = true } serde = { version = "1.0.0", features = ["derive"], optional = true } diff --git a/chirp-imgui/Cargo.toml b/chirp-imgui/Cargo.toml new file mode 100644 index 0000000..d836d49 --- /dev/null +++ b/chirp-imgui/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "chirp-imgui" +version.workspace = true +edition.workspace = true +authors.workspace = true +license.workspace = true +publish.workspace = true + +[dependencies] + +chirp = { path = ".." } + +gumdrop = "0.8.1" +owo-colors = "3" +thiserror = "1.0.39" + +imgui = { version = "^0.11" } +imgui-winit-support = { version = "^0.11" } +imgui-wgpu = { version = "^0.23" } +pixels = { version = "^0" } +# TODO: When imgui-winit-support updates to 0.28 (Soon:tm:), update winit and winit_input_helper +winit = { version = "0.27.5", features = ["default", "x11"] } +winit_input_helper = { version = "^0.13.0" } diff --git a/src/bin/chirp-imgui/args.rs b/chirp-imgui/src/args.rs similarity index 100% rename from src/bin/chirp-imgui/args.rs rename to chirp-imgui/src/args.rs diff --git a/src/bin/chirp-imgui/emu.rs b/chirp-imgui/src/emu.rs similarity index 100% rename from src/bin/chirp-imgui/emu.rs rename to chirp-imgui/src/emu.rs diff --git a/src/bin/chirp-imgui/error.rs b/chirp-imgui/src/error.rs similarity index 100% rename from src/bin/chirp-imgui/error.rs rename to chirp-imgui/src/error.rs diff --git a/src/bin/chirp-imgui/gui.rs b/chirp-imgui/src/gui.rs similarity index 100% rename from src/bin/chirp-imgui/gui.rs rename to chirp-imgui/src/gui.rs diff --git a/src/bin/chirp-imgui/gui/about.rs b/chirp-imgui/src/gui/about.rs similarity index 100% rename from src/bin/chirp-imgui/gui/about.rs rename to chirp-imgui/src/gui/about.rs diff --git a/src/bin/chirp-imgui/gui/menubar.rs b/chirp-imgui/src/gui/menubar.rs similarity index 100% rename from src/bin/chirp-imgui/gui/menubar.rs rename to chirp-imgui/src/gui/menubar.rs diff --git a/src/bin/chirp-imgui/main.rs b/chirp-imgui/src/main.rs similarity index 100% rename from src/bin/chirp-imgui/main.rs rename to chirp-imgui/src/main.rs diff --git a/chirp-minifb/Cargo.toml b/chirp-minifb/Cargo.toml new file mode 100644 index 0000000..4ea8195 --- /dev/null +++ b/chirp-minifb/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "chirp-minifb" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] + +chirp = { path = ".." } +minifb = { version = "0.24.0" } + +gumdrop = "0.8.1" +owo-colors = "3" +thiserror = "1.0.39" diff --git a/chirp-minifb/src/error.rs b/chirp-minifb/src/error.rs new file mode 100644 index 0000000..463cc7e --- /dev/null +++ b/chirp-minifb/src/error.rs @@ -0,0 +1,18 @@ +//! Error type for chirp-minifb + +use thiserror::Error; + +pub type Result = std::result::Result; + +#[derive(Debug, Error)] +pub enum Error { + /// Error originated in [`chirp`] + #[error(transparent)] + Chirp(#[from] chirp::error::Error), + /// Error originated in [`std::io`] + #[error(transparent)] + Io(#[from] std::io::Error), + /// Error originated in [`minifb`] + #[error(transparent)] + Minifb(#[from] minifb::Error), +} diff --git a/src/bin/chirp-minifb/main.rs b/chirp-minifb/src/main.rs similarity index 97% rename from src/bin/chirp-minifb/main.rs rename to chirp-minifb/src/main.rs index 81eee87..7ed3ca1 100644 --- a/src/bin/chirp-minifb/main.rs +++ b/chirp-minifb/src/main.rs @@ -6,10 +6,13 @@ #[cfg(test)] mod tests; + +mod error; mod ui; use chirp::error::Error::BreakpointHit; -use chirp::{error::Result, *}; +use chirp::*; +use error::Result; use gumdrop::*; use owo_colors::OwoColorize; use std::{ @@ -162,7 +165,7 @@ impl State { self.ui.keys(&mut self.ch8) } fn frame(&mut self) -> Result { - self.ui.frame(&mut self.ch8) + self.ui.frame(&self.ch8) } fn tick_cpu(&mut self) -> Result<()> { if !self.ch8.cpu.flags.pause { @@ -209,7 +212,7 @@ impl Iterator for State { } // Allow breakpoint hit messages match self.tick_cpu() { - Err(BreakpointHit { addr, next }) => { + Err(error::Error::Chirp(BreakpointHit { addr, next })) => { eprintln!("Breakpoint hit: {:3x} ({:4x})", addr, next); } Err(e) => return Some(Err(e)), diff --git a/src/bin/chirp-minifb/tests.rs b/chirp-minifb/src/tests.rs similarity index 97% rename from src/bin/chirp-minifb/tests.rs rename to chirp-minifb/src/tests.rs index a2289fd..27e9002 100644 --- a/src/bin/chirp-minifb/tests.rs +++ b/chirp-minifb/src/tests.rs @@ -3,6 +3,7 @@ use super::ui::*; use super::Chip8; +use crate::error::Result; use chirp::*; use std::{collections::hash_map::DefaultHasher, hash::Hash}; @@ -37,8 +38,8 @@ mod ui { #[test] fn frame() -> Result<()> { let mut ui = UIBuilder::new(32, 64, "dummy.ch8").build()?; - let mut ch8 = new_chip8(); - ui.frame(&mut ch8).unwrap(); + let ch8 = new_chip8(); + ui.frame(&ch8).unwrap(); Ok(()) } #[test] diff --git a/src/bin/chirp-minifb/ui.rs b/chirp-minifb/src/ui.rs similarity index 98% rename from src/bin/chirp-minifb/ui.rs rename to chirp-minifb/src/ui.rs index f043c76..7070bd5 100644 --- a/src/bin/chirp-minifb/ui.rs +++ b/chirp-minifb/src/ui.rs @@ -5,7 +5,8 @@ //! TODO: Destroy this all. use super::Chip8; -use chirp::{error::Result, screen::Screen}; +use crate::error::Result; +use chirp::screen::Screen; use minifb::*; use std::{ path::{Path, PathBuf}, @@ -144,7 +145,7 @@ pub struct UI { } impl UI { - pub fn frame(&mut self, ch8: &mut Chip8) -> Result { + pub fn frame(&mut self, ch8: &Chip8) -> Result { if ch8.cpu.flags.pause { self.window.set_title("Chirp ⏸") } else {