altair_emu/src/ram.rs

34 lines
812 B
Rust
Raw Normal View History

2023-10-12 13:11:38 -05:00
use serde::{Deserialize, Serialize};
2023-08-10 13:58:34 -05:00
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,
2023-10-12 13:11:38 -05:00
start_addr: settings.start_addr,
2023-08-10 13:58:34 -05:00
})
}
fn serialize_settings(&self) -> String {
ron::to_string(&RamCardSettings {
size: self.ram.len() as u16,
start_addr: self.start_addr,
2023-10-12 13:11:38 -05:00
})
.unwrap()
2023-08-10 13:58:34 -05:00
}
}