memory

package
v0.20.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2020 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package memory defines memory components

Index

Constants

View Source
const (
	Size00K  = 0x0000
	Size128B = 0x0080
	Size256B = 0x0100
	Size512B = 0x0200
	Size1K   = 0x0400
	Size2K   = 0x0800
	Size4K   = 0x1000
	Size8K   = 0x2000
	Size16K  = 0x4000
	Size32K  = 0x8000
	Size48K  = 0xC000
	Size64K  = 0x10000
)

Common memory sizes

View Source
const (
	DataDefault byte = 0
)

Defaults

Variables

This section is empty.

Functions

This section is empty.

Types

type Bank

type Bank struct {
	OnAccess     device.EventBus
	OnPostAccess device.EventBus
	// contains filtered or unexported fields
}

Bank is a memory bank of bytes

func NewBank

func NewBank(size int, readonly bool) *Bank

NewBank creates a new memory bank

func (*Bank) Data

func (bank *Bank) Data() []byte

Data gets bank data

func (*Bank) Init

func (bank *Bank) Init()

Init initializes bank data

func (*Bank) Load

func (bank *Bank) Load(address uint16, data []byte)

Load loads data at address

func (*Bank) Read

func (bank *Bank) Read(address uint16) byte

Read reads a byte from the bank address

func (*Bank) ReadOnly

func (bank *Bank) ReadOnly() bool

ReadOnly is a read only bank

func (*Bank) Reset

func (bank *Bank) Reset()

Reset resets bank data

func (*Bank) Write

func (bank *Bank) Write(address uint16, data byte)

Write writes a byte to the bank address

type BankMap

type BankMap struct {
	// contains filtered or unexported fields
}

BankMap contains a bank bus and mapping information

func NewBankMap

func NewBankMap(address uint16, size int, readonly bool, active bool) *BankMap

NewBankMap creates a memory bank map

func NewBusMap added in v0.20.0

func NewBusMap(bus device.BusDevice, address uint16, size int, readonly bool, active bool) *BankMap

NewBusMap creates a bank map from a device bus

func NewRAM

func NewRAM(address uint16, size int) *BankMap

NewRAM creates a RAM bank map

func NewROM

func NewROM(address uint16, size int) *BankMap

NewROM creates a ROM bank map

func (*BankMap) Active

func (bmap *BankMap) Active() bool

Active is bank active

func (*BankMap) Bank

func (bmap *BankMap) Bank() *Bank

Bank gets the bank

func (*BankMap) Bus

func (bmap *BankMap) Bus() device.BusDevice

Bus gets the device bus of the bank

func (*BankMap) Init

func (bmap *BankMap) Init()

Init inits bank

func (*BankMap) Reset

func (bmap *BankMap) Reset()

Reset resets bank

func (*BankMap) SetActive

func (bmap *BankMap) SetActive(active bool)

SetActive is bank active

type DefaultMapper

type DefaultMapper struct {
	// contains filtered or unexported fields
}

DefaultMapper is a simple but inefficient memory mapper

func (*DefaultMapper) Init

func (mapper *DefaultMapper) Init(memory *Memory)

Init inits the mapper

func (*DefaultMapper) SelectBank

func (mapper *DefaultMapper) SelectBank(address uint16) (*BankMap, uint16)

SelectBank selects the first active bank mapped at address

func (*DefaultMapper) SelectBankWrite

func (mapper *DefaultMapper) SelectBankWrite(address uint16) (*BankMap, uint16)

SelectBankWrite selects the first active bank mapped at address for write

type Mapper

type Mapper interface {
	// Init inits the mapper
	Init(memory *Memory)
	// SelectBank for Read access
	SelectBank(address uint16) (*BankMap, uint16)
	// SelectBank for Write access
	SelectBankWrite(address uint16) (*BankMap, uint16)
}

Mapper memory bank mapper interface

type MaskMapper

type MaskMapper struct {
	Shift uint
	Mask  uint16
	// contains filtered or unexported fields
}

MaskMapper is a efficient memory mapper based on address bits (shift and mask)

func (*MaskMapper) Init

func (mapper *MaskMapper) Init(memory *Memory)

Init inits the mapper

func (*MaskMapper) SelectBank

func (mapper *MaskMapper) SelectBank(address uint16) (*BankMap, uint16)

SelectBank selects read bank mapped at address

func (*MaskMapper) SelectBankWrite

func (mapper *MaskMapper) SelectBankWrite(address uint16) (*BankMap, uint16)

SelectBankWrite selects write bank mapped at address

type Memory

type Memory struct {
	// contains filtered or unexported fields
}

Memory is a memory structure of banks or bus devices

func New

func New(size int, banks int) *Memory

New creates a new memory device with a size and a number banks

func (*Memory) Bank

func (memory *Memory) Bank(index int) *Bank

Bank returns bank mapped at index

func (*Memory) Banks

func (memory *Memory) Banks() []*BankMap

Banks returns Banks

func (*Memory) Init

func (memory *Memory) Init()

Init initializes the memory

func (*Memory) LoadRAM

func (memory *Memory) LoadRAM(address uint16, data []byte)

LoadRAM loads data into memory starting at address

func (*Memory) Map

func (memory *Memory) Map(index int) *BankMap

Map returns bank map at index

func (*Memory) Mapper

func (memory *Memory) Mapper() Mapper

Mapper returns the bank mapper

func (*Memory) Read

func (memory *Memory) Read(address uint16) byte

Read reads a byte from memory

func (*Memory) Reset

func (memory *Memory) Reset()

Reset resets the memory data at initial state

func (*Memory) SetMap

func (memory *Memory) SetMap(index int, bank *BankMap)

SetMap sets the bank map at index

func (*Memory) SetMapper

func (memory *Memory) SetMapper(mapper Mapper)

SetMapper sets the bank mapper

func (*Memory) Switch added in v0.20.0

func (memory *Memory) Switch(current, new int)

Switch switches two memory banks and update its active state

func (*Memory) Write

func (memory *Memory) Write(address uint16, data byte)

Write writes a byte to the memory

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL