34 lines
812 B
Rust
34 lines
812 B
Rust
use serde::{Deserialize, Serialize};
|
|
|
|
use crate::card::{Card, CardEnum};
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
pub struct RamCardSettings {
|
|
size: u16,
|
|
start_addr: u16,
|
|
}
|
|
pub struct RamCard {
|
|
ram: Vec<u8>,
|
|
start_addr: u16,
|
|
}
|
|
|
|
impl Card for RamCard {
|
|
fn new(settings: ron::Value) -> CardEnum {
|
|
let settings: RamCardSettings = settings.into_rust().unwrap();
|
|
let mut ram = Vec::with_capacity(settings.size as usize);
|
|
ram.resize(settings.size as usize, 0);
|
|
CardEnum::RamCard(Self {
|
|
ram,
|
|
start_addr: settings.start_addr,
|
|
})
|
|
}
|
|
|
|
fn serialize_settings(&self) -> String {
|
|
ron::to_string(&RamCardSettings {
|
|
size: self.ram.len() as u16,
|
|
start_addr: self.start_addr,
|
|
})
|
|
.unwrap()
|
|
}
|
|
}
|