spectrusty_core/memory/
extension.rs

1/*
2    Copyright (C) 2020-2022  Rafal Michalski
3
4    This file is part of SPECTRUSTY, a Rust library for building emulators.
5
6    For the full copyright notice, see the lib.rs file.
7*/
8use super::ZxMemory;
9
10#[cfg(feature = "snapshot")]
11use serde::{Serialize, Deserialize};
12
13/// An interface for memory paging extensions of [ZxMemory].
14///
15/// Provide an implementation as the associated type [crate::chip::MemoryAccess::MemoryExt].
16pub trait MemoryExtension: core::fmt::Debug {
17    /// Read op-code from the given `memory` at the given `pc` address, optionally altering provided memory.
18    #[inline]
19    fn read_opcode<M: ZxMemory>(&mut self, pc: u16, memory: &mut M) -> u8 {
20        memory.read(pc)
21    }
22    // /// Writes to the memory extension port. Should return optionally modified `data` if the extension wants
23    // /// to influence some other chipset functions.
24    // #[inline]
25    // fn write_io<M: ZxMemory>(&mut self, _port: u16, data: u8, _memory: &mut M) -> u8 {
26    //     data
27    // }
28    // /// Reads from the memory extension port. 
29    // fn read_io<M: ZxMemory>(&mut self, _port: u16, _memory: &mut M) -> u8 {
30    //     u8::max_value()
31    // }
32}
33
34/// A placeholder memory extension. Useful as a default.
35#[derive(Clone, Copy, Default, Debug)]
36#[cfg_attr(feature = "snapshot", derive(Serialize, Deserialize))]
37pub struct NoMemoryExtension;
38
39impl MemoryExtension for NoMemoryExtension {}