Compare commits
No commits in common. "cb96ee0dd72de8b7aafe32399e91f987d2747b75" and "9145c71a3494766408aa8b7a99a3db838acfb645" have entirely different histories.
cb96ee0dd7
...
9145c71a34
42
Cargo.lock
generated
42
Cargo.lock
generated
@ -378,6 +378,12 @@ 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"
|
||||
@ -444,8 +450,8 @@ dependencies = [
|
||||
"paste",
|
||||
"reedline-repl-rs",
|
||||
"serde",
|
||||
"serde_yaml",
|
||||
"thiserror",
|
||||
"toml",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -658,6 +664,12 @@ 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"
|
||||
@ -690,6 +702,19 @@ 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"
|
||||
@ -823,15 +848,6 @@ 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"
|
||||
@ -850,6 +866,12 @@ 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"
|
||||
|
@ -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"
|
||||
|
13
config.toml
13
config.toml
@ -1,13 +0,0 @@
|
||||
symbol_tables = ["rom/rom.elf"]
|
||||
|
||||
[[cards]]
|
||||
type = "rom"
|
||||
image = "rom/rom.bin"
|
||||
|
||||
[[cards]]
|
||||
type = "ram"
|
||||
size = 4096
|
||||
|
||||
[[cards]]
|
||||
type = "storage"
|
||||
|
9
config.yaml
Normal file
9
config.yaml
Normal file
@ -0,0 +1,9 @@
|
||||
---
|
||||
cards:
|
||||
- type: rom
|
||||
image: rom/rom.bin
|
||||
- type: ram
|
||||
size: 4096
|
||||
- type: storage
|
||||
symbol_tables:
|
||||
- rom/rom.elf
|
@ -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: Value) -> anyhow::Result<usize> {
|
||||
pub fn add_card(&mut self, type_name: &str, config: Mapping) -> anyhow::Result<usize> {
|
||||
if self.cards.len() >= 255 {
|
||||
return Err(CardAddError::BackplaneFull.into());
|
||||
}
|
||||
|
10
src/card.rs
10
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: Value) -> anyhow::Result<Box<dyn Card>>,
|
||||
new: fn(data: Mapping) -> anyhow::Result<Box<dyn Card>>,
|
||||
}
|
||||
|
||||
impl Type {
|
||||
@ -16,7 +16,7 @@ impl Type {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_card(&self, data: Value) -> anyhow::Result<Box<dyn Card>> {
|
||||
pub fn new_card(&self, data: Mapping) -> anyhow::Result<Box<dyn Card>> {
|
||||
(self.new)(data)
|
||||
}
|
||||
}
|
||||
@ -24,10 +24,10 @@ impl Type {
|
||||
inventory::collect!(Type);
|
||||
|
||||
pub trait Card: Debug + Display {
|
||||
fn new(data: Value) -> anyhow::Result<Self>
|
||||
fn new(data: Mapping) -> anyhow::Result<Self>
|
||||
where
|
||||
Self: Sized;
|
||||
fn new_dyn(data: Value) -> anyhow::Result<Box<dyn Card>>
|
||||
fn new_dyn(data: Mapping) -> anyhow::Result<Box<dyn Card>>
|
||||
where
|
||||
Self: Sized + 'static,
|
||||
{
|
||||
|
11
src/main.rs
11
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: Value,
|
||||
config: Mapping,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
@ -57,11 +57,10 @@ struct EmuState {
|
||||
}
|
||||
|
||||
fn main() -> Result<(), anyhow::Error> {
|
||||
let config_str = fs::read_to_string("config.toml")
|
||||
let config_str = fs::read_to_string("config.yaml")
|
||||
.map_err(|e| anyhow!("Could not read config file ({})", e))?;
|
||||
let config: EmuConfig =
|
||||
toml::from_str(&config_str).map_err(|e| anyhow!("Could not parse config file ({})", e))?;
|
||||
dbg!(&config);
|
||||
let config: EmuConfig = serde_yaml::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)?;
|
||||
|
@ -3,7 +3,7 @@ use std::fmt::Display;
|
||||
use human_repr::HumanCount;
|
||||
use nullable_result::NullableResult;
|
||||
use serde::Deserialize;
|
||||
use toml::Value;
|
||||
use serde_yaml::Mapping;
|
||||
|
||||
use crate::{
|
||||
card::{u32_get_be_byte, Card},
|
||||
@ -26,8 +26,8 @@ pub struct Ram {
|
||||
impl Ram {}
|
||||
|
||||
impl Card for Ram {
|
||||
fn new(data: Value) -> anyhow::Result<Self> {
|
||||
let size = data.try_into::<Config>()?.size;
|
||||
fn new(data: Mapping) -> anyhow::Result<Self> {
|
||||
let size = serde_yaml::from_value::<Config>(data.into())?.size;
|
||||
Ok(Self {
|
||||
data: vec![0; size as usize],
|
||||
start: 0,
|
||||
|
@ -4,7 +4,7 @@ use anyhow::anyhow;
|
||||
use human_repr::HumanCount;
|
||||
use nullable_result::NullableResult;
|
||||
use serde::Deserialize;
|
||||
use toml::Value;
|
||||
use serde_yaml::Mapping;
|
||||
|
||||
use crate::{
|
||||
card::{u16_get_be_byte, u16_set_be_byte, Card},
|
||||
@ -14,7 +14,7 @@ use crate::{
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Config {
|
||||
image: Option<String>,
|
||||
file_name: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -29,8 +29,8 @@ pub struct Rom {
|
||||
impl Rom {}
|
||||
|
||||
impl Card for Rom {
|
||||
fn new(data: Value) -> anyhow::Result<Self> {
|
||||
let file_name = data.try_into::<Config>()?.image;
|
||||
fn new(data: Mapping) -> anyhow::Result<Self> {
|
||||
let file_name = serde_yaml::from_value::<Config>(data.into())?.file_name;
|
||||
let mut data = Vec::new();
|
||||
if let Some(file_name) = file_name.as_ref() {
|
||||
File::open(file_name)
|
||||
|
@ -4,7 +4,7 @@ use anyhow::anyhow;
|
||||
use human_repr::HumanCount;
|
||||
use nullable_result::NullableResult;
|
||||
use serde::Deserialize;
|
||||
use toml::Value;
|
||||
use serde_yaml::Mapping;
|
||||
|
||||
use crate::{
|
||||
card::{u32_get_be_byte, u32_set_be_byte, Card},
|
||||
@ -16,7 +16,7 @@ const SECTOR_SIZE: usize = 256;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Config {
|
||||
image: Option<String>,
|
||||
file_name: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -28,8 +28,8 @@ pub struct Storage {
|
||||
}
|
||||
|
||||
impl Card for Storage {
|
||||
fn new(data: Value) -> anyhow::Result<Self> {
|
||||
let file_name = data.try_into::<Config>()?.image;
|
||||
fn new(data: Mapping) -> anyhow::Result<Self> {
|
||||
let file_name = serde_yaml::from_value::<Config>(data.into())?.file_name;
|
||||
let mut data = Vec::new();
|
||||
if let Some(file_name) = file_name.as_ref() {
|
||||
File::open(file_name)
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
use nullable_result::NullableResult;
|
||||
use toml::Value;
|
||||
use serde_yaml::Mapping;
|
||||
|
||||
use crate::{card::Card, m68k::BusError, register};
|
||||
|
||||
@ -15,7 +15,7 @@ impl Display for Term {
|
||||
}
|
||||
|
||||
impl Card for Term {
|
||||
fn new(_data: Value) -> anyhow::Result<Self>
|
||||
fn new(_data: Mapping) -> anyhow::Result<Self>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user