diff options
Diffstat (limited to 'src/mapper.rs')
-rw-r--r-- | src/mapper.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/mapper.rs b/src/mapper.rs index cf946a2..446d5b9 100644 --- a/src/mapper.rs +++ b/src/mapper.rs @@ -1,5 +1,6 @@ #![allow(dead_code)] extern crate core; +use core::cell::UnsafeCell; use memory::{VMem, CPUBus}; use cartridge::{Cartridge, BankType, MirrorType}; @@ -8,6 +9,29 @@ pub trait Mapper : VMem { fn tick(&mut self, _bus: &CPUBus) {} } +pub struct RefMapper<'a> { + mapper: UnsafeCell<&'a mut Mapper> +} + +impl<'a> RefMapper<'a> { + pub fn new(mapper: &'a mut Mapper) -> Self { + RefMapper { mapper: UnsafeCell::new(mapper) } + } + + #[inline(always)] + pub fn get_mut(&self) -> &'a mut Mapper { + unsafe { *self.mapper.get() } + } +} + +impl<'a> core::ops::Deref for RefMapper<'a> { + type Target = &'a mut Mapper; + #[inline(always)] + fn deref(&self) -> &&'a mut Mapper { + unsafe { &*self.mapper.get() } + } +} + pub struct Mapper1<'a, C> where C: Cartridge { cart: C, prg_banks: [&'a [u8]; 2], |