diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/apu.rs | 29 | ||||
-rw-r--r-- | src/bin.rs | 2 | ||||
-rw-r--r-- | src/lib.rs | 1 | ||||
-rw-r--r-- | src/memory.rs | 38 | ||||
-rw-r--r-- | src/mos6502.rs | 8 | ||||
-rw-r--r-- | src/ppu.rs | 14 | ||||
-rw-r--r-- | src/utils.rs | 3 |
7 files changed, 50 insertions, 45 deletions
@@ -720,18 +720,19 @@ pub struct APU<'a> { spkr: &'a mut Speaker, } -const APU_IGNORED_SIZE: usize = - size_of::<Pulse>() + - size_of::<Pulse>() + - size_of::<Triangle>() + - size_of::<Noise>() + - size_of::<DMC>() + - size_of::<LPFilter>() + - size_of::<HPFilter>() + - size_of::<HPFilter>() + - size_of::<Sampler>() + - size_of::<Sampler>() + - size_of::<&Speaker>(); +macro_rules! APU_IGNORED_SIZE { + () => (size_of::<Pulse>() + + size_of::<Pulse>() + + size_of::<Triangle>() + + size_of::<Noise>() + + size_of::<DMC>() + + size_of::<LPFilter>() + + size_of::<HPFilter>() + + size_of::<HPFilter>() + + size_of::<Sampler>() + + size_of::<Sampler>() + + size_of::<&Speaker>()) +} impl<'a> APU<'a> { pub fn new(spkr: &'a mut Speaker) -> Self { @@ -752,7 +753,7 @@ impl<'a> APU<'a> { } pub fn load(&mut self, reader: &mut Read) -> bool { - load_prefix(self, APU_IGNORED_SIZE, reader) && + load_prefix(self, APU_IGNORED_SIZE!(), reader) && self.pulse1.load(reader) && self.pulse2.load(reader) && self.triangle.load(reader) && @@ -766,7 +767,7 @@ impl<'a> APU<'a> { } pub fn save(&self, writer: &mut Write) -> bool { - save_prefix(self, APU_IGNORED_SIZE, writer) && + save_prefix(self, APU_IGNORED_SIZE!(), writer) && self.pulse1.save(writer) && self.pulse2.save(writer) && self.triangle.save(writer) && @@ -4,7 +4,7 @@ extern crate core; use std::fs::File; use std::sync::{Mutex, Condvar}; use std::io::{Read, Write}; -use std::intrinsics::transmute; +use std::mem::transmute; use std::process::exit; use std::cell::Cell; @@ -1,5 +1,4 @@ #![no_std] -#![feature(const_size_of)] //extern crate core; mod utils; mod memory; diff --git a/src/memory.rs b/src/memory.rs index f199317..46a9464 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -31,11 +31,12 @@ pub struct CPUBus<'a> { apu: *mut APU<'a>, } -const CPUBUS_IGNORED_SIZE: usize = - size_of::<RefCell<Sampler>>() + - size_of::<*mut CPU>() + - size_of::<*mut PPU>() + - size_of::<*mut APU>(); +macro_rules! CPUBUS_IGNORED_SIZE { + () => (size_of::<RefCell<Sampler>>() + + size_of::<*mut CPU>() + + size_of::<*mut PPU>() + + size_of::<*mut APU>()) +} impl<'a> CPUBus<'a> { pub fn new() -> Self { @@ -49,12 +50,12 @@ impl<'a> CPUBus<'a> { } pub fn load(&mut self, reader: &mut Read) -> bool { - load_prefix(self, CPUBUS_IGNORED_SIZE, reader) && + load_prefix(self, CPUBUS_IGNORED_SIZE!(), reader) && self.ppu_sampler.borrow_mut().load(reader) } pub fn save(&self, writer: &mut Write) -> bool { - save_prefix(self, CPUBUS_IGNORED_SIZE, writer) && + save_prefix(self, CPUBUS_IGNORED_SIZE!(), writer) && self.ppu_sampler.borrow().save(writer) } @@ -126,11 +127,12 @@ pub struct CPUMemory<'a> { ctl2: Option<&'a Controller> } -const CPUMEM_IGNORED_SIZE: usize = - size_of::<CPUBus>() + - size_of::<&RefMapper>() + - size_of::<Option<&Controller>>() + - size_of::<Option<&Controller>>(); +macro_rules! CPUMEM_IGNORED_SIZE { + () => (size_of::<CPUBus>() + + size_of::<&RefMapper>() + + size_of::<Option<&Controller>>() + + size_of::<Option<&Controller>>()) +} impl<'a> CPUMemory<'a> { pub fn new(mapper: &'a RefMapper<'a>, @@ -142,12 +144,12 @@ impl<'a> CPUMemory<'a> { } pub fn load(&mut self, reader: &mut Read) -> bool { - load_prefix(self, CPUMEM_IGNORED_SIZE, reader) && + load_prefix(self, CPUMEM_IGNORED_SIZE!(), reader) && self.bus.load(reader) } pub fn save(&self, writer: &mut Write) -> bool { - save_prefix(self, CPUMEM_IGNORED_SIZE, writer) && + save_prefix(self, CPUMEM_IGNORED_SIZE!(), writer) && self.bus.save(writer) } @@ -282,7 +284,9 @@ pub struct PPUMemory<'a> { mapper: &'a RefMapper<'a> } -const PPUMEM_IGNORED_SIZE: usize = size_of::<&RefMapper>(); +macro_rules! PPUMEM_IGNORED_SIZE { + () => (size_of::<&RefMapper>()) +} impl<'a> PPUMemory<'a> { pub fn new(mapper: &'a RefMapper<'a>) -> Self { @@ -294,11 +298,11 @@ impl<'a> PPUMemory<'a> { } pub fn load(&mut self, reader: &mut Read) -> bool { - load_prefix(self, PPUMEM_IGNORED_SIZE, reader) + load_prefix(self, PPUMEM_IGNORED_SIZE!(), reader) } pub fn save(&self, writer: &mut Write) -> bool { - save_prefix(self, PPUMEM_IGNORED_SIZE, writer) + save_prefix(self, PPUMEM_IGNORED_SIZE!(), writer) } } diff --git a/src/mos6502.rs b/src/mos6502.rs index e8c471f..a97ece1 100644 --- a/src/mos6502.rs +++ b/src/mos6502.rs @@ -615,7 +615,9 @@ pub struct CPU<'a> { /*-- end sub-state --*/ } -const CPU_IGNORED_SIZE: usize = size_of::<CPUMemory>(); +macro_rules! CPU_IGNORED_SIZE { + () => (size_of::<CPUMemory>()) +} macro_rules! make_int { ($f:ident, $v: expr) => ( @@ -668,12 +670,12 @@ impl<'a> CPU<'a> { } pub fn load(&mut self, reader: &mut Read) -> bool { - load_prefix(self, CPU_IGNORED_SIZE, reader) && + load_prefix(self, CPU_IGNORED_SIZE!(), reader) && self.mem.load(reader) } pub fn save(&self, writer: &mut Write) -> bool { - save_prefix(self, CPU_IGNORED_SIZE, writer) && + save_prefix(self, CPU_IGNORED_SIZE!(), writer) && self.mem.save(writer) } @@ -1,7 +1,6 @@ #![allow(dead_code)] use memory::{VMem, PPUMemory, CPUBus}; -use core::intrinsics::transmute; -use core::mem::size_of; +use core::mem::{size_of, transmute}; use utils::{Read, Write, load_prefix, save_prefix}; pub trait Screen { @@ -62,9 +61,10 @@ pub struct PPU<'a> { pub scr: &'a mut Screen, } -const PPU_IGNORED_SIZE: usize = - size_of::<PPUMemory>() + - size_of::<&mut Screen>(); +macro_rules! PPU_IGNORED_SIZE { + () => (size_of::<PPUMemory>() + + size_of::<&mut Screen>()) +} impl<'a> PPU<'a> { #[inline] @@ -491,12 +491,12 @@ impl<'a> PPU<'a> { } pub fn load(&mut self, reader: &mut Read) -> bool { - load_prefix(self, PPU_IGNORED_SIZE, reader) && + load_prefix(self, PPU_IGNORED_SIZE!(), reader) && self.mem.load(reader) } pub fn save(&self, writer: &mut Write) -> bool { - save_prefix(self, PPU_IGNORED_SIZE, writer) && + save_prefix(self, PPU_IGNORED_SIZE!(), writer) && self.mem.save(writer) } diff --git a/src/utils.rs b/src/utils.rs index ea20ac9..2a7827f 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,5 +1,4 @@ -use core::intrinsics::transmute; -use core::mem::size_of; +use core::mem::{transmute, size_of}; use core::slice::{from_raw_parts_mut, from_raw_parts}; pub struct Sampler { |