Move BoxedMemory to core::util

Former-commit-id: 99a04859982f39f0062c781d9f61b2a55f8e5c10
Former-commit-id: 1ae7808c64116347410b52770edf132f3beec817
This commit is contained in:
Michel Heily 2020-05-29 17:46:44 +03:00
parent 6e39780b43
commit b888fc0c95
3 changed files with 28 additions and 27 deletions

View file

@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
use super::dma::{DmaNotifer, TIMING_HBLANK, TIMING_VBLANK}; use super::dma::{DmaNotifer, TIMING_HBLANK, TIMING_VBLANK};
use super::interrupt::{self, Interrupt, SharedInterruptFlags}; use super::interrupt::{self, Interrupt, SharedInterruptFlags};
pub use super::sysbus::consts::*; pub use super::sysbus::consts::*;
use super::sysbus::BoxedMemory; use super::util::BoxedMemory;
use super::VideoInterface; use super::VideoInterface;
use super::{Addr, Bus}; use super::{Addr, Bus};

View file

@ -6,7 +6,7 @@ use super::cartridge::Cartridge;
use super::dma::DmaNotifer; use super::dma::DmaNotifer;
use super::iodev::{IoDevices, WaitControl}; use super::iodev::{IoDevices, WaitControl};
use super::{Addr, Bus}; use super::{Addr, Bus};
use super::util::WeakPointer; use super::util::{BoxedMemory, WeakPointer};
pub mod consts { pub mod consts {
pub const WORK_RAM_SIZE: usize = 256 * 1024; pub const WORK_RAM_SIZE: usize = 256 * 1024;
@ -70,30 +70,6 @@ pub enum MemoryAccessWidth {
MemoryAccess32, MemoryAccess32,
} }
#[derive(Serialize, Deserialize, Clone, Debug)]
#[repr(transparent)]
pub struct BoxedMemory {
pub mem: Box<[u8]>,
}
impl BoxedMemory {
pub fn new(boxed_slice: Box<[u8]>) -> BoxedMemory {
BoxedMemory { mem: boxed_slice }
}
}
impl Bus for BoxedMemory {
fn read_8(&self, addr: Addr) -> u8 {
unsafe { *self.mem.get_unchecked(addr as usize) }
}
fn write_8(&mut self, addr: Addr, value: u8) {
unsafe {
*self.mem.get_unchecked_mut(addr as usize) = value;
}
}
}
const CYCLE_LUT_SIZE: usize = 0x10; const CYCLE_LUT_SIZE: usize = 0x10;
#[derive(Serialize, Deserialize, Clone)] #[derive(Serialize, Deserialize, Clone)]

View file

@ -4,9 +4,10 @@ use std::io::prelude::*;
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
use std::path::Path; use std::path::Path;
use std::ptr; use std::ptr;
use std::time; use std::time;
use super::bus::{Addr, Bus};
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
type Instant = time::Instant; type Instant = time::Instant;
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
@ -191,3 +192,27 @@ impl<T> Default for WeakPointer<T> {
} }
} }
} }
#[derive(Serialize, Deserialize, Clone, Debug)]
#[repr(transparent)]
pub struct BoxedMemory {
pub mem: Box<[u8]>,
}
impl BoxedMemory {
pub fn new(boxed_slice: Box<[u8]>) -> BoxedMemory {
BoxedMemory { mem: boxed_slice }
}
}
impl Bus for BoxedMemory {
fn read_8(&self, addr: Addr) -> u8 {
unsafe { *self.mem.get_unchecked(addr as usize) }
}
fn write_8(&mut self, addr: Addr, value: u8) {
unsafe {
*self.mem.get_unchecked_mut(addr as usize) = value;
}
}
}