From a6be6683287d82d1a9ee215cdea3ef3730fe6818 Mon Sep 17 00:00:00 2001 From: "J. Hinchliffe" Date: Tue, 17 Jun 2025 19:19:49 +0100 Subject: [PATCH] emulator: just saving my changes --- .vscode/settings.json | 3 +- Cargo.lock | 177 +++++++++++++++++++++++++++++- emulator/Cargo.toml | 6 + emulator/src/emulator/config.rs | 2 + emulator/src/emulator/misc/mod.rs | 2 + emulator/src/emulator/misc/rpc.rs | 56 ++++++++++ emulator/src/emulator/mod.rs | 3 + 7 files changed, 247 insertions(+), 2 deletions(-) create mode 100644 emulator/src/emulator/config.rs create mode 100644 emulator/src/emulator/misc/mod.rs create mode 100644 emulator/src/emulator/misc/rpc.rs diff --git a/.vscode/settings.json b/.vscode/settings.json index 9281181..a4566e9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,5 @@ { "rust-analyzer.check.command": "clippy", - "editor.formatOnSave": true + "editor.formatOnSave": true, + "rust-analyzer.cargo.features": "all" } diff --git a/Cargo.lock b/Cargo.lock index 6afd181..e77f9c8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -558,6 +558,12 @@ dependencies = [ "syn", ] +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + [[package]] name = "byteorder-lite" version = "0.1.0" @@ -744,6 +750,15 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "crossbeam-channel" +version = "0.5.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82b8f8f868b36967f9606790d1903570de9ceaf870a7bf9fbbd3016d636a2cb2" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "crossbeam-utils" version = "0.8.21" @@ -794,7 +809,29 @@ dependencies = [ "libc", "option-ext", "redox_users", - "windows-sys 0.59.0", + "windows-sys 0.60.2", +] + +[[package]] +name = "discord-presence" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91d7c2fc01ffdc327e2b66d65dd59b8bd3f31a17e88811ce0540412fa0b84c1" +dependencies = [ + "byteorder", + "bytes", + "cfg-if", + "crossbeam-channel", + "log", + "num-derive", + "num-traits", + "parking_lot", + "paste", + "quork", + "serde", + "serde_json", + "thiserror 2.0.12", + "uuid", ] [[package]] @@ -1002,9 +1039,11 @@ dependencies = [ "assembler", "common", "dirs", + "discord-presence", "eframe", "egui", "rfd", + "toml", ] [[package]] @@ -1585,6 +1624,12 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "itoa" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" + [[package]] name = "jni" version = "0.21.1" @@ -1868,6 +1913,17 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" +[[package]] +name = "num-derive" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "num-traits" version = "0.2.19" @@ -2379,6 +2435,28 @@ dependencies = [ "toml_edit", ] +[[package]] +name = "proc-macro-error-attr2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96de42df36bb9bba5542fe9f1a054b8cc87e172759a1868aa05c1f3acc89dfc5" +dependencies = [ + "proc-macro2", + "quote", +] + +[[package]] +name = "proc-macro-error2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11ec05c52be0a07b08061f7dd003e7d7092e0472bc731b4af7bb1ef876109802" +dependencies = [ + "proc-macro-error-attr2", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "proc-macro2" version = "1.0.95" @@ -2413,6 +2491,32 @@ dependencies = [ "memchr", ] +[[package]] +name = "quork" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bd9640e0addc098a3481fd53bdc23970e5dd0edf6b349403aa680fb576c8f83" +dependencies = [ + "cfg-if", + "nix 0.29.0", + "quork-proc", + "thiserror 2.0.12", + "windows-sys 0.59.0", +] + +[[package]] +name = "quork-proc" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "860d36740d9412e39fff90f57010e9870b15c2b48e5325295a6f5a824a480439" +dependencies = [ + "proc-macro-crate", + "proc-macro-error2", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "quote" version = "1.0.40" @@ -2596,6 +2700,12 @@ version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a0d197bd2c9dc6e53b84da9556a69ba4cdfab8619eb41a8bd1cc2027a0f6b1d" +[[package]] +name = "ryu" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" + [[package]] name = "same-file" version = "1.0.6" @@ -2650,6 +2760,18 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_json" +version = "1.0.140" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + [[package]] name = "serde_repr" version = "0.1.20" @@ -2661,6 +2783,15 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_spanned" +version = "0.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf41e0cfaf7226dca15e8197172c295a782857fcb97fad1808a166870dee75a3" +dependencies = [ + "serde", +] + [[package]] name = "sha1" version = "0.10.6" @@ -2938,11 +3069,26 @@ dependencies = [ "zerovec", ] +[[package]] +name = "toml" +version = "0.8.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + [[package]] name = "toml_datetime" version = "0.6.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c" +dependencies = [ + "serde", +] [[package]] name = "toml_edit" @@ -2951,10 +3097,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" dependencies = [ "indexmap", + "serde", + "serde_spanned", "toml_datetime", + "toml_write", "winnow", ] +[[package]] +name = "toml_write" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801" + [[package]] name = "tracing" version = "0.1.41" @@ -3066,6 +3221,17 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" +[[package]] +name = "uuid" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3cf4199d1e5d15ddd86a694e4d0dffa9c323ce759fea589f00fef9d81cc1931d" +dependencies = [ + "getrandom 0.3.3", + "js-sys", + "wasm-bindgen", +] + [[package]] name = "version_check" version = "0.9.5" @@ -3544,6 +3710,15 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets 0.53.2", +] + [[package]] name = "windows-targets" version = "0.42.2" diff --git a/emulator/Cargo.toml b/emulator/Cargo.toml index 4921fbb..e79fe90 100644 --- a/emulator/Cargo.toml +++ b/emulator/Cargo.toml @@ -14,3 +14,9 @@ eframe = "0.31.1" egui = "0.31.1" rfd = "0.15.3" dirs = "6.0.0" +discord-presence = { version = "1.6.0", optional = true } +toml = { version = "0.8.23", optional = true } + +[features] +discord-rpc = ["dep:discord-presence"] +config = ["dep:toml"] diff --git a/emulator/src/emulator/config.rs b/emulator/src/emulator/config.rs new file mode 100644 index 0000000..534ce40 --- /dev/null +++ b/emulator/src/emulator/config.rs @@ -0,0 +1,2 @@ +//! Loads configuration information from a TOML file in the current working directory. +//! Currently doesn't do much but this may be expanded. diff --git a/emulator/src/emulator/misc/mod.rs b/emulator/src/emulator/misc/mod.rs new file mode 100644 index 0000000..7689ddb --- /dev/null +++ b/emulator/src/emulator/misc/mod.rs @@ -0,0 +1,2 @@ +#[cfg(feature = "discord-rpc")] +pub mod rpc; diff --git a/emulator/src/emulator/misc/rpc.rs b/emulator/src/emulator/misc/rpc.rs new file mode 100644 index 0000000..94d2f9c --- /dev/null +++ b/emulator/src/emulator/misc/rpc.rs @@ -0,0 +1,56 @@ +//! Just for fun I thought I would add a Discord RPC client to the emulator. +//! +//! This will display information like the current value of PCX, architecture name and +//! GitHub repo links to show off the ISA. Perhaps in the future if we cross-compile to +//! WASM we could include a link to run this software in the browser. +//! +//! +//! # Configuration +//! +//! This may be disabled like so in your `.dsarc.toml` file: +//! +//! ```toml +//! [misc] +//! use_discord_rpc = false +//! ``` +//! +//! Alternatively, you can hide this in your Discord settings. + +use discord_presence::{Client, DiscordError}; + +#[derive(Debug)] +pub enum DiscordRpcError { + Client(DiscordError), +} + +impl std::fmt::Display for DiscordRpcError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Self::Client(why) => write!(f, "discord RPC error: {why}"), + } + } +} + +impl std::error::Error for DiscordRpcError {} + +impl From for DiscordRpcError { + fn from(err: DiscordError) -> Self { + Self::Client(err) + } +} + +/// Sets up the Discord RPC client. +#[expect(clippy::unreadable_literal)] +pub fn start_rpc() -> Result { + let mut client = discord_presence::Client::new(1384303074088190042); + + _ = client.on_ready(|ctx| { + eprintln!("The discord RPC client is ready. Got event {:?}", ctx.event); + }); + + client.start(); + + client.set_activity(|act| act)?; + + Ok(client) +} diff --git a/emulator/src/emulator/mod.rs b/emulator/src/emulator/mod.rs index 140dea3..9d6cc6f 100644 --- a/emulator/src/emulator/mod.rs +++ b/emulator/src/emulator/mod.rs @@ -1,2 +1,5 @@ +#[cfg(feature = "config")] +pub mod config; +pub mod misc; pub mod system; pub mod ui;