experimenting with serde
This commit is contained in:
parent
56925d0815
commit
531240e94e
|
@ -6,6 +6,7 @@ edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
sdl2 = { version = "0.33", features = ["bundled", "static-link"] }
|
sdl2 = { version = "0.33", features = ["bundled", "static-link"] }
|
||||||
|
serde = { version = "1.0.104", features = ["derive"] }
|
||||||
cpuprofiler = "0.0.3"
|
cpuprofiler = "0.0.3"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
|
|
|
@ -4,6 +4,8 @@ mod utility;
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
use serde::{Serialize, Deserialize};
|
||||||
|
use serde::ser::{Serializer, SerializeStruct};
|
||||||
use crate::cartridge::Mapper;
|
use crate::cartridge::Mapper;
|
||||||
|
|
||||||
// RAM locations
|
// RAM locations
|
||||||
|
@ -21,7 +23,7 @@ const DECIMAL_FLAG: u8 = 1 << 3;
|
||||||
const OVERFLOW_FLAG: u8 = 1 << 6;
|
const OVERFLOW_FLAG: u8 = 1 << 6;
|
||||||
const NEGATIVE_FLAG: u8 = 1 << 7;
|
const NEGATIVE_FLAG: u8 = 1 << 7;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
|
||||||
pub enum Mode {
|
pub enum Mode {
|
||||||
ABS, ABX, ABY, ACC,
|
ABS, ABX, ABY, ACC,
|
||||||
IMM, IMP, IDX, IND,
|
IMM, IMP, IDX, IND,
|
||||||
|
@ -51,7 +53,7 @@ impl Mode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct Cpu {
|
pub struct Cpu {
|
||||||
mem: Vec<u8>, // CPU's RAM, $0000-$1FFF
|
mem: Vec<u8>, // CPU's RAM, $0000-$1FFF
|
||||||
A: u8, // accumulator
|
A: u8, // accumulator
|
||||||
|
@ -64,6 +66,7 @@ pub struct Cpu {
|
||||||
clock: u64, // number of ticks in current cycle
|
clock: u64, // number of ticks in current cycle
|
||||||
delay: usize, // for skipping cycles during OAM DMA
|
delay: usize, // for skipping cycles during OAM DMA
|
||||||
|
|
||||||
|
// #[serde(skip_serializing)]
|
||||||
mapper: Rc<RefCell<dyn Mapper>>, // cartridge data
|
mapper: Rc<RefCell<dyn Mapper>>, // cartridge data
|
||||||
pub ppu: super::Ppu,
|
pub ppu: super::Ppu,
|
||||||
pub apu: super::Apu,
|
pub apu: super::Apu,
|
||||||
|
@ -285,6 +288,30 @@ impl Cpu {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
impl Serialize for Cpu {
|
||||||
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
|
let mut state = serializer.serialize_struct("Cpu", 13)?;
|
||||||
|
state.serialize_field("mem", &self.mem)?;
|
||||||
|
state.serialize_field("A", &self.A)?;
|
||||||
|
state.serialize_field("X", &self.X)?;
|
||||||
|
state.serialize_field("Y", &self.Y)?;
|
||||||
|
state.serialize_field("PC", &self.PC)?;
|
||||||
|
state.serialize_field("S", &self.S)?;
|
||||||
|
state.serialize_field("P", &self.P)?;
|
||||||
|
state.serialize_field("clock", &self.clock)?;
|
||||||
|
state.serialize_field("delay", &self.delay)?;
|
||||||
|
state.serialize_field("strobe", &self.strobe)?;
|
||||||
|
state.serialize_field("button_states", &self.button_states)?;
|
||||||
|
state.serialize_field("button_number", &self.button_number)?;
|
||||||
|
state.serialize_field("mode_table", &self.mode_table)?;
|
||||||
|
state.end()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Address range Size Device
|
Address range Size Device
|
||||||
$0000-$07FF $0800 2KB internal RAM
|
$0000-$07FF $0800 2KB internal RAM
|
||||||
|
|
Loading…
Reference in New Issue