diff --git a/Cargo.lock b/Cargo.lock index 2839461..f521542 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -378,12 +378,6 @@ dependencies = [ "either", ] -[[package]] -name = "itoa" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" - [[package]] name = "js-sys" version = "0.3.60" @@ -450,8 +444,8 @@ dependencies = [ "paste", "reedline-repl-rs", "serde", - "serde_yaml", "thiserror", + "toml", ] [[package]] @@ -664,12 +658,6 @@ version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97477e48b4cf8603ad5f7aaf897467cf42ab4218a38ef76fb14c2d6773a6d6a8" -[[package]] -name = "ryu" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" - [[package]] name = "scopeguard" version = "1.1.0" @@ -702,19 +690,6 @@ dependencies = [ "syn", ] -[[package]] -name = "serde_yaml" -version = "0.9.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d232d893b10de3eb7258ff01974d6ee20663d8e833263c99409d4b13a0209da" -dependencies = [ - "indexmap", - "itoa", - "ryu", - "serde", - "unsafe-libyaml", -] - [[package]] name = "signal-hook" version = "0.3.14" @@ -848,6 +823,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "toml" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" +dependencies = [ + "serde", +] + [[package]] name = "unicode-ident" version = "1.0.5" @@ -866,12 +850,6 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" -[[package]] -name = "unsafe-libyaml" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1e5fa573d8ac5f1a856f8d7be41d390ee973daf97c806b2c1a465e4e1406e68" - [[package]] name = "utf8parse" version = "0.2.0" diff --git a/Cargo.toml b/Cargo.toml index 5efb73f..d101a64 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,5 +19,5 @@ parse_int = "0.6.0" paste = "1.0.9" reedline-repl-rs = { path = "reedline-repl-rs" } serde = { version = "1.0.144", features = ["derive"] } -serde_yaml = "0.9.13" thiserror = "1.0.37" +toml = "0.5.9" diff --git a/config.toml b/config.toml new file mode 100644 index 0000000..e6f2324 --- /dev/null +++ b/config.toml @@ -0,0 +1,13 @@ +symbol_tables = ["rom/rom.elf"] + +[[cards]] +type = "rom" +image = "rom/rom.bin" + +[[cards]] +type = "ram" +size = 4096 + +[[cards]] +type = "storage" + diff --git a/config.yaml b/config.yaml deleted file mode 100644 index 10ce250..0000000 --- a/config.yaml +++ /dev/null @@ -1,9 +0,0 @@ ---- -cards: - - type: rom - image: rom/rom.bin - - type: ram - size: 4096 - - type: storage -symbol_tables: - - rom/rom.elf diff --git a/src/backplane.rs b/src/backplane.rs index 0d60472..1090f4b 100644 --- a/src/backplane.rs +++ b/src/backplane.rs @@ -1,6 +1,6 @@ use nullable_result::{GeneralIterExt, NullableResult}; -use serde_yaml::Mapping; use thiserror::Error; +use toml::Value; use crate::{ card::{self, Card}, @@ -34,7 +34,7 @@ impl Backplane { &mut self.cards } - pub fn add_card(&mut self, type_name: &str, config: Mapping) -> anyhow::Result { + pub fn add_card(&mut self, type_name: &str, config: Value) -> anyhow::Result { if self.cards.len() >= 255 { return Err(CardAddError::BackplaneFull.into()); } diff --git a/src/card.rs b/src/card.rs index 9e885cc..911fa13 100644 --- a/src/card.rs +++ b/src/card.rs @@ -1,11 +1,11 @@ use crate::m68k::BusError; use nullable_result::NullableResult; -use serde_yaml::Mapping; use std::fmt::{Debug, Display}; +use toml::Value; pub struct Type { pub name: &'static str, - new: fn(data: Mapping) -> anyhow::Result>, + new: fn(data: Value) -> anyhow::Result>, } impl Type { @@ -16,7 +16,7 @@ impl Type { } } - pub fn new_card(&self, data: Mapping) -> anyhow::Result> { + pub fn new_card(&self, data: Value) -> anyhow::Result> { (self.new)(data) } } @@ -24,10 +24,10 @@ impl Type { inventory::collect!(Type); pub trait Card: Debug + Display { - fn new(data: Mapping) -> anyhow::Result + fn new(data: Value) -> anyhow::Result where Self: Sized; - fn new_dyn(data: Mapping) -> anyhow::Result> + fn new_dyn(data: Value) -> anyhow::Result> where Self: Sized + 'static, { diff --git a/src/main.rs b/src/main.rs index 53cc292..f024cd2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,16 +30,16 @@ use reedline_repl_rs::{ Repl, }; use serde::Deserialize; -use serde_yaml::Mapping; use std::{fs, path::Path, process}; use symbol_tables::SymbolTables; +use toml::Value; #[derive(Deserialize, Debug)] struct CardConfig<'a> { #[serde(rename = "type")] typ: &'a str, #[serde(flatten)] - config: Mapping, + config: Value, } #[derive(Deserialize, Debug)] @@ -57,10 +57,10 @@ struct EmuState { } fn main() -> Result<(), anyhow::Error> { - let config_str = fs::read_to_string("config.yaml") + let config_str = fs::read_to_string("config.toml") .map_err(|e| anyhow!("Could not read config file ({})", e))?; - let config: EmuConfig = serde_yaml::from_str(&config_str) - .map_err(|e| anyhow!("Could not parse config file ({})", e))?; + let config: EmuConfig = + toml::from_str(&config_str).map_err(|e| anyhow!("Could not parse config file ({})", e))?; let mut backplane = Backplane::new(); for card in config.cards { backplane.add_card(card.typ, card.config)?; diff --git a/src/ram.rs b/src/ram.rs index e739b70..4d03060 100644 --- a/src/ram.rs +++ b/src/ram.rs @@ -3,7 +3,7 @@ use std::fmt::Display; use human_repr::HumanCount; use nullable_result::NullableResult; use serde::Deserialize; -use serde_yaml::Mapping; +use toml::Value; use crate::{ card::{u32_get_be_byte, Card}, @@ -26,8 +26,8 @@ pub struct Ram { impl Ram {} impl Card for Ram { - fn new(data: Mapping) -> anyhow::Result { - let size = serde_yaml::from_value::(data.into())?.size; + fn new(data: Value) -> anyhow::Result { + let size = data.try_into::()?.size; Ok(Self { data: vec![0; size as usize], start: 0, diff --git a/src/rom.rs b/src/rom.rs index 0646161..5d8877a 100644 --- a/src/rom.rs +++ b/src/rom.rs @@ -4,7 +4,7 @@ use anyhow::anyhow; use human_repr::HumanCount; use nullable_result::NullableResult; use serde::Deserialize; -use serde_yaml::Mapping; +use toml::Value; use crate::{ card::{u16_get_be_byte, u16_set_be_byte, Card}, @@ -29,8 +29,8 @@ pub struct Rom { impl Rom {} impl Card for Rom { - fn new(data: Mapping) -> anyhow::Result { - let file_name = serde_yaml::from_value::(data.into())?.file_name; + fn new(data: Value) -> anyhow::Result { + let file_name = data.try_into::()?.image; let mut data = Vec::new(); if let Some(file_name) = file_name.as_ref() { File::open(file_name) diff --git a/src/storage.rs b/src/storage.rs index a710a70..0c0cb53 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -4,7 +4,7 @@ use anyhow::anyhow; use human_repr::HumanCount; use nullable_result::NullableResult; use serde::Deserialize; -use serde_yaml::Mapping; +use toml::Value; use crate::{ card::{u32_get_be_byte, u32_set_be_byte, Card}, @@ -28,8 +28,8 @@ pub struct Storage { } impl Card for Storage { - fn new(data: Mapping) -> anyhow::Result { - let file_name = serde_yaml::from_value::(data.into())?.file_name; + fn new(data: Value) -> anyhow::Result { + let file_name = data.try_into::()?.image; let mut data = Vec::new(); if let Some(file_name) = file_name.as_ref() { File::open(file_name) diff --git a/src/term.rs b/src/term.rs index 903f3ab..79a8965 100644 --- a/src/term.rs +++ b/src/term.rs @@ -1,7 +1,7 @@ use std::fmt::Display; use nullable_result::NullableResult; -use serde_yaml::Mapping; +use toml::Value; use crate::{card::Card, m68k::BusError, register}; @@ -15,7 +15,7 @@ impl Display for Term { } impl Card for Term { - fn new(_data: Mapping) -> anyhow::Result + fn new(_data: Value) -> anyhow::Result where Self: Sized, {