[][src]Trait spectrusty::memory::ZxMemory

pub trait ZxMemory {
    pub const PAGE_SIZE: usize;
    pub const ROM_SIZE: usize;
    pub const RAMTOP: u16;
    pub const PAGES_MAX: u8;
    pub const SCR_BANKS_MAX: usize;
    pub const ROM_BANKS_MAX: usize;
    pub const RAM_BANKS_MAX: usize;

    pub fn reset(&mut self);
pub fn read(&self, addr: u16) -> u8;
pub fn read16(&self, addr: u16) -> u16;
pub fn read_screen(&self, screen_bank: usize, addr: u16) -> u8;
pub fn write(&mut self, addr: u16, val: u8);
pub fn write16(&mut self, addr: u16, val: u16);
pub fn mem_ref(&self) -> &[u8]

Notable traits for &'_ [u8]

impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
;
pub fn mem_mut(&mut self) -> &mut [u8]

Notable traits for &'_ [u8]

impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
;
pub fn screen_ref(
        &self,
        screen_bank: usize
    ) -> Result<&[u8; 6912], ZxMemoryError>;
pub fn screen_mut(
        &mut self,
        screen_bank: usize
    ) -> Result<&mut [u8; 6912], ZxMemoryError>;
pub fn page_kind(&self, page: u8) -> Result<MemoryKind, ZxMemoryError>;
pub fn page_bank(
        &self,
        page: u8
    ) -> Result<(MemoryKind, usize), ZxMemoryError>;
pub fn page_ref(&self, page: u8) -> Result<&[u8], ZxMemoryError>;
pub fn page_mut(&mut self, page: u8) -> Result<&mut [u8], ZxMemoryError>;
pub fn rom_bank_ref(&self, rom_bank: usize) -> Result<&[u8], ZxMemoryError>;
pub fn rom_bank_mut(
        &mut self,
        rom_bank: usize
    ) -> Result<&mut [u8], ZxMemoryError>;
pub fn ram_bank_ref(&self, ram_bank: usize) -> Result<&[u8], ZxMemoryError>;
pub fn ram_bank_mut(
        &mut self,
        ram_bank: usize
    ) -> Result<&mut [u8], ZxMemoryError>;
pub fn map_rom_bank(
        &mut self,
        rom_bank: usize,
        page: u8
    ) -> Result<(), ZxMemoryError>;
pub fn map_ram_bank(
        &mut self,
        ram_bank: usize,
        page: u8
    ) -> Result<(), ZxMemoryError>; pub fn map_exrom(
        &mut self,
        _exrom_bank: Rc<[u8]>,
        _page: u8
    ) -> Result<(), ZxMemoryError> { ... }
pub fn unmap_exrom(&mut self, _exrom_bank: &Rc<[u8]>) { ... }
pub fn is_exrom_at(&self, _page: u8) -> bool { ... }
pub fn has_mapped_exrom(&self, _exrom_bank: &Rc<[u8]>) -> bool { ... }
pub fn page_index_at(
        &self,
        address: u16
    ) -> Result<MemPageOffset, ZxMemoryError> { ... }
pub fn rom_ref(&self) -> &[u8]

Notable traits for &'_ [u8]

impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
{ ... }
pub fn rom_mut(&mut self) -> &mut [u8]

Notable traits for &'_ [u8]

impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
{ ... }
pub fn ram_ref(&self) -> &[u8]

Notable traits for &'_ [u8]

impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
{ ... }
pub fn ram_mut(&mut self) -> &mut [u8]

Notable traits for &'_ [u8]

impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
{ ... }
pub fn load_into_rom<R>(&mut self, rd: R) -> Result<(), ZxMemoryError>
    where
        R: Read
, { ... }
pub fn load_into_rom_bank<R>(
        &mut self,
        rom_bank: usize,
        rd: R
    ) -> Result<(), ZxMemoryError>
    where
        R: Read
, { ... }
pub fn iter_pages<A>(
        &self,
        address_range: A
    ) -> Result<MemPageRefIter<'_, Self>, ZxMemoryError>
    where
        A: RangeBounds<u16>
, { ... }
pub fn for_each_page_mut<A, F>(
        &mut self,
        address_range: A,
        f: F
    ) -> Result<(), ZxMemoryError>
    where
        F: for<'a> FnMut(PageMutSlice<'a>) -> Result<(), ZxMemoryError>,
        A: RangeBounds<u16>
, { ... }
pub fn load_into_mem<A, R>(
        &mut self,
        address_range: A,
        rd: R
    ) -> Result<(), ZxMemoryError>
    where
        A: RangeBounds<u16>,
        R: Read
, { ... }
pub fn fill_mem<R, F>(
        &mut self,
        address_range: R,
        f: F
    ) -> Result<(), ZxMemoryError>
    where
        F: FnMut() -> u8,
        R: RangeBounds<u16>
, { ... } }

A trait for interfacing ZX Spectrum's various memory types.

Associated Constants

pub const PAGE_SIZE: usize[src]

This is just a hint. Actual page sizes may vary.

pub const ROM_SIZE: usize[src]

The size of the whole ROM, not just one bank.

pub const RAMTOP: u16[src]

The last available memory address.

pub const PAGES_MAX: u8[src]

A maximum value allowed for a page argument.

pub const SCR_BANKS_MAX: usize[src]

A maximum value allowed for a screen_bank argument

pub const ROM_BANKS_MAX: usize[src]

A maximum value allowed for a rom_bank argument

pub const RAM_BANKS_MAX: usize[src]

A maximum value allowed for a ram_bank argument

Loading content...

Required methods

pub fn reset(&mut self)[src]

Resets memory banks.

pub fn read(&self, addr: u16) -> u8[src]

If addr is above RAMTOP the function should return std::u8::MAX.

pub fn read16(&self, addr: u16) -> u16[src]

If addr is above RAMTOP the function should return std::u16::MAX.

pub fn read_screen(&self, screen_bank: usize, addr: u16) -> u8[src]

Reads a byte from screen memory at the given addr.

The screen banks are different from memory banks. E.g. for Spectrum 128k then screen bank 0 resides in a memory bank 5 and screen bank 1 resides in a memory bank 7. For 16k/48k Spectrum, there is only one screen bank: 0.

addr is in screen address space (0 addresses the first byte of screen memory).

Panics

If addr is above the upper limit of screen memory address space the function should panic. If screen_bank doesn't exist the function should also panic.

pub fn write(&mut self, addr: u16, val: u8)[src]

If addr is above RAMTOP the function should do nothing.

pub fn write16(&mut self, addr: u16, val: u16)[src]

If addr is above RAMTOP the function should do nothing.

pub fn mem_ref(&self) -> &[u8]

Notable traits for &'_ [u8]

impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
[src]

Provides a continuous view into the whole memory (all banks: ROM + RAM).

pub fn mem_mut(&mut self) -> &mut [u8]

Notable traits for &'_ [u8]

impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
[src]

Provides a continuous view into the whole memory (all banks: ROM + RAM).

pub fn screen_ref(
    &self,
    screen_bank: usize
) -> Result<&[u8; 6912], ZxMemoryError>
[src]

Returns a reference to the screen memory.

See ZxMemory::read_screen for an explanation of screen_bank argument.

pub fn screen_mut(
    &mut self,
    screen_bank: usize
) -> Result<&mut [u8; 6912], ZxMemoryError>
[src]

Returns a mutable reference to the screen memory.

See ZxMemory::read_screen for an explanation of screen_bank argument.

pub fn page_kind(&self, page: u8) -> Result<MemoryKind, ZxMemoryError>[src]

Returns an enum describing what kind of memory is currently paged at the specified page.

If an EX-ROM bank is currently mapped at the specified page a MemoryKind::Rom will be returned in this instance.

page should be less or equal to PAGES_MAX.

pub fn page_bank(&self, page: u8) -> Result<(MemoryKind, usize), ZxMemoryError>[src]

Returns a tuple of an enum describing what kind of memory and which bank of that memory is currently paged at the specified page.

Note

Unlike ZxMemory::page_kind this method ignores if an EX-ROM bank is currently mapped at the specified page. In this instance, the returned value corresponds to a memory bank that would be mapped at the page if the EX-ROM bank wasn't mapped.

page should be less or equal to PAGES_MAX.

pub fn page_ref(&self, page: u8) -> Result<&[u8], ZxMemoryError>[src]

page should be less or equal to PAGES_MAX.

pub fn page_mut(&mut self, page: u8) -> Result<&mut [u8], ZxMemoryError>[src]

page should be less or equal to PAGES_MAX.

pub fn rom_bank_ref(&self, rom_bank: usize) -> Result<&[u8], ZxMemoryError>[src]

rom_bank should be less or equal to ROM_BANKS_MAX.

pub fn rom_bank_mut(
    &mut self,
    rom_bank: usize
) -> Result<&mut [u8], ZxMemoryError>
[src]

rom_bank should be less or equal to ROM_BANKS_MAX.

pub fn ram_bank_ref(&self, ram_bank: usize) -> Result<&[u8], ZxMemoryError>[src]

ram_bank should be less or equal to RAM_BANKS_MAX.

pub fn ram_bank_mut(
    &mut self,
    ram_bank: usize
) -> Result<&mut [u8], ZxMemoryError>
[src]

ram_bank should be less or equal to RAM_BANKS_MAX.

pub fn map_rom_bank(
    &mut self,
    rom_bank: usize,
    page: u8
) -> Result<(), ZxMemoryError>
[src]

rom_bank should be less or equal to ROM_BANKS_MAX and page should be less or equal to PAGES_MAX.

pub fn map_ram_bank(
    &mut self,
    ram_bank: usize,
    page: u8
) -> Result<(), ZxMemoryError>
[src]

ram_bank should be less or equal to RAM_BANKS_MAX and page should be less or equal to PAGES_MAX.

Loading content...

Provided methods

pub fn map_exrom(
    &mut self,
    _exrom_bank: Rc<[u8]>,
    _page: u8
) -> Result<(), ZxMemoryError>
[src]

Maps EX-ROM bank at the specified page.

exrom_bank should be one of the attachable EX-ROMS and page should be less or equal to PAGES_MAX.

Only one EX-ROM can be mapped at the same time. If an EX-ROM bank is already mapped when calling this function it will be unmapped first, regardless of the page, the previous EX-ROM bank has been mapped at.

Not all types of memory support attaching external ROMs.

pub fn unmap_exrom(&mut self, _exrom_bank: &Rc<[u8]>)[src]

Unmaps an external ROM if the currently mapped EX-ROM bank is the same as in the argument. Otherwise does nothing.

pub fn is_exrom_at(&self, _page: u8) -> bool[src]

Returns true if an EX-ROM bank is currently being mapped at the specified memory page.

pub fn has_mapped_exrom(&self, _exrom_bank: &Rc<[u8]>) -> bool[src]

Returns true if a specified EX-ROM bank is currently being mapped.

pub fn page_index_at(
    &self,
    address: u16
) -> Result<MemPageOffset, ZxMemoryError>
[src]

Returns Ok(MemPageOffset) if address is equal to or less than ZxMemory::RAMTOP.

pub fn rom_ref(&self) -> &[u8]

Notable traits for &'_ [u8]

impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
[src]

Provides a continuous view into the ROM memory (all banks).

pub fn rom_mut(&mut self) -> &mut [u8]

Notable traits for &'_ [u8]

impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
[src]

Provides a continuous mutable view into the ROM memory (all banks).

pub fn ram_ref(&self) -> &[u8]

Notable traits for &'_ [u8]

impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
[src]

Provides a continuous view into RAM (all banks).

pub fn ram_mut(&mut self) -> &mut [u8]

Notable traits for &'_ [u8]

impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
[src]

Provides a continuous mutable view into RAM (all banks).

pub fn load_into_rom<R>(&mut self, rd: R) -> Result<(), ZxMemoryError> where
    R: Read
[src]

The data read depends on how big ROM is ZxMemory::ROM_SIZE. Results in an error when the ROM data size is less than the ROM_SIZE.

pub fn load_into_rom_bank<R>(
    &mut self,
    rom_bank: usize,
    rd: R
) -> Result<(), ZxMemoryError> where
    R: Read
[src]

Results in an error when the ROM data size is less than the ROM bank's size.

pub fn iter_pages<A>(
    &self,
    address_range: A
) -> Result<MemPageRefIter<'_, Self>, ZxMemoryError> where
    A: RangeBounds<u16>, 
[src]

Returns an iterator of memory page slice references intersecting with a given address range.

Errors

May return an ZxMemoryError::UnsupportedAddressRange error.

pub fn for_each_page_mut<A, F>(
    &mut self,
    address_range: A,
    f: F
) -> Result<(), ZxMemoryError> where
    F: for<'a> FnMut(PageMutSlice<'a>) -> Result<(), ZxMemoryError>,
    A: RangeBounds<u16>, 
[src]

Iterates over mutable memory page slices PageMutSlice intersecting with a given address range passing the slices to the closure f.

Errors

May return an ZxMemoryError::UnsupportedAddressRange error or an error returned by the provided closure.

pub fn load_into_mem<A, R>(
    &mut self,
    address_range: A,
    rd: R
) -> Result<(), ZxMemoryError> where
    A: RangeBounds<u16>,
    R: Read
[src]

Reads data into a paged-in memory area at the given address range.

pub fn fill_mem<R, F>(
    &mut self,
    address_range: R,
    f: F
) -> Result<(), ZxMemoryError> where
    F: FnMut() -> u8,
    R: RangeBounds<u16>, 
[src]

Fills currently paged-in pages with the data produced by the closure F.

Useful to fill RAM with random bytes.

Provide the address range.

NOTE: this will overwrite both ROM and RAM locations.

Loading content...

Implementors

impl ZxMemory for Memory16k[src]

impl ZxMemory for Memory48k[src]

impl ZxMemory for Memory64k[src]

impl<M> ZxMemory for MemPageableRomRamExRom<M> where
    M: MemoryBlock, 
[src]

Loading content...