From b888fc0c95f4d317b49c52bfeda1be9518fdd7ca Mon Sep 17 00:00:00 2001 From: Michel Heily Date: Fri, 29 May 2020 17:46:44 +0300 Subject: [PATCH] Move BoxedMemory to core::util Former-commit-id: 99a04859982f39f0062c781d9f61b2a55f8e5c10 Former-commit-id: 1ae7808c64116347410b52770edf132f3beec817 --- core/src/gpu/mod.rs | 2 +- core/src/sysbus.rs | 26 +------------------------- core/src/util.rs | 27 ++++++++++++++++++++++++++- 3 files changed, 28 insertions(+), 27 deletions(-) diff --git a/core/src/gpu/mod.rs b/core/src/gpu/mod.rs index 5d4adf7..f9550f2 100644 --- a/core/src/gpu/mod.rs +++ b/core/src/gpu/mod.rs @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize}; use super::dma::{DmaNotifer, TIMING_HBLANK, TIMING_VBLANK}; use super::interrupt::{self, Interrupt, SharedInterruptFlags}; pub use super::sysbus::consts::*; -use super::sysbus::BoxedMemory; +use super::util::BoxedMemory; use super::VideoInterface; use super::{Addr, Bus}; diff --git a/core/src/sysbus.rs b/core/src/sysbus.rs index 291bb5c..f7a54f7 100644 --- a/core/src/sysbus.rs +++ b/core/src/sysbus.rs @@ -6,7 +6,7 @@ use super::cartridge::Cartridge; use super::dma::DmaNotifer; use super::iodev::{IoDevices, WaitControl}; use super::{Addr, Bus}; -use super::util::WeakPointer; +use super::util::{BoxedMemory, WeakPointer}; pub mod consts { pub const WORK_RAM_SIZE: usize = 256 * 1024; @@ -70,30 +70,6 @@ pub enum MemoryAccessWidth { 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; #[derive(Serialize, Deserialize, Clone)] diff --git a/core/src/util.rs b/core/src/util.rs index e0217d4..c721a82 100644 --- a/core/src/util.rs +++ b/core/src/util.rs @@ -4,9 +4,10 @@ use std::io::prelude::*; use std::ops::{Deref, DerefMut}; use std::path::Path; use std::ptr; - use std::time; +use super::bus::{Addr, Bus}; + #[cfg(not(target_arch = "wasm32"))] type Instant = time::Instant; #[cfg(not(target_arch = "wasm32"))] @@ -191,3 +192,27 @@ impl Default for WeakPointer { } } } + +#[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; + } + } +}