Compare commits
2 Commits
9145c71a34
...
cb96ee0dd7
Author | SHA1 | Date | |
---|---|---|---|
cb96ee0dd7 | |||
daf6bdc477 |
42
Cargo.lock
generated
42
Cargo.lock
generated
@ -378,12 +378,6 @@ dependencies = [
|
|||||||
"either",
|
"either",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "itoa"
|
|
||||||
version = "1.0.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "js-sys"
|
name = "js-sys"
|
||||||
version = "0.3.60"
|
version = "0.3.60"
|
||||||
@ -450,8 +444,8 @@ dependencies = [
|
|||||||
"paste",
|
"paste",
|
||||||
"reedline-repl-rs",
|
"reedline-repl-rs",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_yaml",
|
|
||||||
"thiserror",
|
"thiserror",
|
||||||
|
"toml",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -664,12 +658,6 @@ version = "1.0.9"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "97477e48b4cf8603ad5f7aaf897467cf42ab4218a38ef76fb14c2d6773a6d6a8"
|
checksum = "97477e48b4cf8603ad5f7aaf897467cf42ab4218a38ef76fb14c2d6773a6d6a8"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ryu"
|
|
||||||
version = "1.0.11"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "scopeguard"
|
name = "scopeguard"
|
||||||
version = "1.1.0"
|
version = "1.1.0"
|
||||||
@ -702,19 +690,6 @@ dependencies = [
|
|||||||
"syn",
|
"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]]
|
[[package]]
|
||||||
name = "signal-hook"
|
name = "signal-hook"
|
||||||
version = "0.3.14"
|
version = "0.3.14"
|
||||||
@ -848,6 +823,15 @@ dependencies = [
|
|||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "toml"
|
||||||
|
version = "0.5.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-ident"
|
name = "unicode-ident"
|
||||||
version = "1.0.5"
|
version = "1.0.5"
|
||||||
@ -866,12 +850,6 @@ version = "0.1.10"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
|
checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "unsafe-libyaml"
|
|
||||||
version = "0.2.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c1e5fa573d8ac5f1a856f8d7be41d390ee973daf97c806b2c1a465e4e1406e68"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "utf8parse"
|
name = "utf8parse"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
|
@ -19,5 +19,5 @@ parse_int = "0.6.0"
|
|||||||
paste = "1.0.9"
|
paste = "1.0.9"
|
||||||
reedline-repl-rs = { path = "reedline-repl-rs" }
|
reedline-repl-rs = { path = "reedline-repl-rs" }
|
||||||
serde = { version = "1.0.144", features = ["derive"] }
|
serde = { version = "1.0.144", features = ["derive"] }
|
||||||
serde_yaml = "0.9.13"
|
|
||||||
thiserror = "1.0.37"
|
thiserror = "1.0.37"
|
||||||
|
toml = "0.5.9"
|
||||||
|
13
config.toml
Normal file
13
config.toml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
symbol_tables = ["rom/rom.elf"]
|
||||||
|
|
||||||
|
[[cards]]
|
||||||
|
type = "rom"
|
||||||
|
image = "rom/rom.bin"
|
||||||
|
|
||||||
|
[[cards]]
|
||||||
|
type = "ram"
|
||||||
|
size = 4096
|
||||||
|
|
||||||
|
[[cards]]
|
||||||
|
type = "storage"
|
||||||
|
|
@ -1,9 +0,0 @@
|
|||||||
---
|
|
||||||
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 nullable_result::{GeneralIterExt, NullableResult};
|
||||||
use serde_yaml::Mapping;
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
use toml::Value;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
card::{self, Card},
|
card::{self, Card},
|
||||||
@ -34,7 +34,7 @@ impl Backplane {
|
|||||||
&mut self.cards
|
&mut self.cards
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_card(&mut self, type_name: &str, config: Mapping) -> anyhow::Result<usize> {
|
pub fn add_card(&mut self, type_name: &str, config: Value) -> anyhow::Result<usize> {
|
||||||
if self.cards.len() >= 255 {
|
if self.cards.len() >= 255 {
|
||||||
return Err(CardAddError::BackplaneFull.into());
|
return Err(CardAddError::BackplaneFull.into());
|
||||||
}
|
}
|
||||||
|
10
src/card.rs
10
src/card.rs
@ -1,11 +1,11 @@
|
|||||||
use crate::m68k::BusError;
|
use crate::m68k::BusError;
|
||||||
use nullable_result::NullableResult;
|
use nullable_result::NullableResult;
|
||||||
use serde_yaml::Mapping;
|
|
||||||
use std::fmt::{Debug, Display};
|
use std::fmt::{Debug, Display};
|
||||||
|
use toml::Value;
|
||||||
|
|
||||||
pub struct Type {
|
pub struct Type {
|
||||||
pub name: &'static str,
|
pub name: &'static str,
|
||||||
new: fn(data: Mapping) -> anyhow::Result<Box<dyn Card>>,
|
new: fn(data: Value) -> anyhow::Result<Box<dyn Card>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Type {
|
impl Type {
|
||||||
@ -16,7 +16,7 @@ impl Type {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_card(&self, data: Mapping) -> anyhow::Result<Box<dyn Card>> {
|
pub fn new_card(&self, data: Value) -> anyhow::Result<Box<dyn Card>> {
|
||||||
(self.new)(data)
|
(self.new)(data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -24,10 +24,10 @@ impl Type {
|
|||||||
inventory::collect!(Type);
|
inventory::collect!(Type);
|
||||||
|
|
||||||
pub trait Card: Debug + Display {
|
pub trait Card: Debug + Display {
|
||||||
fn new(data: Mapping) -> anyhow::Result<Self>
|
fn new(data: Value) -> anyhow::Result<Self>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
fn new_dyn(data: Mapping) -> anyhow::Result<Box<dyn Card>>
|
fn new_dyn(data: Value) -> anyhow::Result<Box<dyn Card>>
|
||||||
where
|
where
|
||||||
Self: Sized + 'static,
|
Self: Sized + 'static,
|
||||||
{
|
{
|
||||||
|
11
src/main.rs
11
src/main.rs
@ -30,16 +30,16 @@ use reedline_repl_rs::{
|
|||||||
Repl,
|
Repl,
|
||||||
};
|
};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_yaml::Mapping;
|
|
||||||
use std::{fs, path::Path, process};
|
use std::{fs, path::Path, process};
|
||||||
use symbol_tables::SymbolTables;
|
use symbol_tables::SymbolTables;
|
||||||
|
use toml::Value;
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
struct CardConfig<'a> {
|
struct CardConfig<'a> {
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
typ: &'a str,
|
typ: &'a str,
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
config: Mapping,
|
config: Value,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
@ -57,10 +57,11 @@ struct EmuState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), anyhow::Error> {
|
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))?;
|
.map_err(|e| anyhow!("Could not read config file ({})", e))?;
|
||||||
let config: EmuConfig = serde_yaml::from_str(&config_str)
|
let config: EmuConfig =
|
||||||
.map_err(|e| anyhow!("Could not parse config file ({})", e))?;
|
toml::from_str(&config_str).map_err(|e| anyhow!("Could not parse config file ({})", e))?;
|
||||||
|
dbg!(&config);
|
||||||
let mut backplane = Backplane::new();
|
let mut backplane = Backplane::new();
|
||||||
for card in config.cards {
|
for card in config.cards {
|
||||||
backplane.add_card(card.typ, card.config)?;
|
backplane.add_card(card.typ, card.config)?;
|
||||||
|
@ -3,7 +3,7 @@ use std::fmt::Display;
|
|||||||
use human_repr::HumanCount;
|
use human_repr::HumanCount;
|
||||||
use nullable_result::NullableResult;
|
use nullable_result::NullableResult;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_yaml::Mapping;
|
use toml::Value;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
card::{u32_get_be_byte, Card},
|
card::{u32_get_be_byte, Card},
|
||||||
@ -26,8 +26,8 @@ pub struct Ram {
|
|||||||
impl Ram {}
|
impl Ram {}
|
||||||
|
|
||||||
impl Card for Ram {
|
impl Card for Ram {
|
||||||
fn new(data: Mapping) -> anyhow::Result<Self> {
|
fn new(data: Value) -> anyhow::Result<Self> {
|
||||||
let size = serde_yaml::from_value::<Config>(data.into())?.size;
|
let size = data.try_into::<Config>()?.size;
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
data: vec![0; size as usize],
|
data: vec![0; size as usize],
|
||||||
start: 0,
|
start: 0,
|
||||||
|
@ -4,7 +4,7 @@ use anyhow::anyhow;
|
|||||||
use human_repr::HumanCount;
|
use human_repr::HumanCount;
|
||||||
use nullable_result::NullableResult;
|
use nullable_result::NullableResult;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_yaml::Mapping;
|
use toml::Value;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
card::{u16_get_be_byte, u16_set_be_byte, Card},
|
card::{u16_get_be_byte, u16_set_be_byte, Card},
|
||||||
@ -14,7 +14,7 @@ use crate::{
|
|||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct Config {
|
struct Config {
|
||||||
file_name: Option<String>,
|
image: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -29,8 +29,8 @@ pub struct Rom {
|
|||||||
impl Rom {}
|
impl Rom {}
|
||||||
|
|
||||||
impl Card for Rom {
|
impl Card for Rom {
|
||||||
fn new(data: Mapping) -> anyhow::Result<Self> {
|
fn new(data: Value) -> anyhow::Result<Self> {
|
||||||
let file_name = serde_yaml::from_value::<Config>(data.into())?.file_name;
|
let file_name = data.try_into::<Config>()?.image;
|
||||||
let mut data = Vec::new();
|
let mut data = Vec::new();
|
||||||
if let Some(file_name) = file_name.as_ref() {
|
if let Some(file_name) = file_name.as_ref() {
|
||||||
File::open(file_name)
|
File::open(file_name)
|
||||||
|
@ -4,7 +4,7 @@ use anyhow::anyhow;
|
|||||||
use human_repr::HumanCount;
|
use human_repr::HumanCount;
|
||||||
use nullable_result::NullableResult;
|
use nullable_result::NullableResult;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_yaml::Mapping;
|
use toml::Value;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
card::{u32_get_be_byte, u32_set_be_byte, Card},
|
card::{u32_get_be_byte, u32_set_be_byte, Card},
|
||||||
@ -16,7 +16,7 @@ const SECTOR_SIZE: usize = 256;
|
|||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct Config {
|
struct Config {
|
||||||
file_name: Option<String>,
|
image: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -28,8 +28,8 @@ pub struct Storage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Card for Storage {
|
impl Card for Storage {
|
||||||
fn new(data: Mapping) -> anyhow::Result<Self> {
|
fn new(data: Value) -> anyhow::Result<Self> {
|
||||||
let file_name = serde_yaml::from_value::<Config>(data.into())?.file_name;
|
let file_name = data.try_into::<Config>()?.image;
|
||||||
let mut data = Vec::new();
|
let mut data = Vec::new();
|
||||||
if let Some(file_name) = file_name.as_ref() {
|
if let Some(file_name) = file_name.as_ref() {
|
||||||
File::open(file_name)
|
File::open(file_name)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
|
|
||||||
use nullable_result::NullableResult;
|
use nullable_result::NullableResult;
|
||||||
use serde_yaml::Mapping;
|
use toml::Value;
|
||||||
|
|
||||||
use crate::{card::Card, m68k::BusError, register};
|
use crate::{card::Card, m68k::BusError, register};
|
||||||
|
|
||||||
@ -15,7 +15,7 @@ impl Display for Term {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Card for Term {
|
impl Card for Term {
|
||||||
fn new(_data: Mapping) -> anyhow::Result<Self>
|
fn new(_data: Value) -> anyhow::Result<Self>
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user