Documentation ¶
Index ¶
Constants ¶
const ( RAMBankSize = 0x2000 ROMBankSize = 0x4000 )
const ( ROMBanking = 0x00 RAMBanking = 0x01 )
6000-7FFF - ROM/RAM Mode Select
const AddrDMA = 0xff46
AddrDMA is the address of DMA register in DMG address space.
const AddrExternalRAM = 0xa000
const BootAddr = 0xff50
BootAddr is the address of BOOT register in I/O RAM.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Addressable ¶
type Addressable interface { // Contains returns true if the given address belongs to the address space. Contains(addr uint16) bool // Read returns the value stored at the given address. Read(addr uint16) uint8 // Write attempts to store the given value at the given address if writable. Write(addr uint16, value uint8) }
Addressable interface provides functions to read/write bytes in a given 16-bit address space.
func NewCartridge ¶
func NewCartridge(romPath, savePath string) (cart Addressable)
NewCartridge instantiates the proper kind of adress space depending on the given ROM's header. TODO: we only handle ROM-only and MBC1 so far.
type BankedRAM ¶
RAM as an array of R/W bytes at addresses starting from a given offset. If dealing with a battery-backed RAM, this can also be saved to a file.
func NewBankedRAM ¶
NewBankedRAM instantiates a zeroed slice of the given size to represent RAM along with a bank index to map an 8Kb bank to the 0xa000-0xbfff range.
type BankedROM ¶
type BankedROM struct { *ROM Bank0 uint // 16Kb bank to map to 0x0000-0x3fff. Bank1 uint // 16Kb bank to map to 0x4000-0x7fff }
ROM as an array of R/W bytes at addresses starting from a given offset. If dealing with a battery-backed ROM, this can also be saved to a file.
func NewBankedROM ¶
NewBankedROM instantiates a zeroed slice of the given size to represent ROM along with bank indexes to map 16Kb bank to the 0x0000-0x3fff and 0x4000-0x7fff ranges.
type Boot ¶
Boot address space holding Boot ROM and BOOT register to disable it.
func NewBootFromFile ¶
NewBootFromFile returns a new Boot address space containing the boot ROM in the given file.
func (*Boot) Contains ¶
Contains returns true if the given address belongs to the ROM or BOOT register, false otherwise.
type DMA ¶
type DMA struct { DMA uint8 MMU Addressable OAM Addressable // contains filtered or unexported fields }
DMA address space taking care of memory transfers between main MMU and OAM memory.
func NewDMA ¶
func NewDMA(mmu, oam Addressable) *DMA
NewDMA returns an instance of DMA managing the actual register and memory transfers. Parameter is an Addressable that must span source and destination address spaces.
type DMAMemory ¶
type DMAMemory struct { Addressable DMA *DMA }
DMAMemory wraps the whole address space to forbid memory access to the CPU while a DMA transfer is taking place.
func NewDMAMemory ¶
func NewDMAMemory(mmu, oam Addressable) *DMAMemory
NewDMA returns an instance of DMA managing the actual register and memory transfers. Parameter is an Addressable that must span source and destination address spaces.
type MBC1 ¶
type MBC1 struct { ROM *BankedROM // Complete ROM (will be addressed according to ROMBank) RAM *BankedRAM // Optional RAM (up to 32KB) RAMEnabled bool // 0000-1FFF - RAM Enable BankLow uint8 // 2000-3FFF - ROM Bank Number (bits 0-4) BankHigh uint8 // 4000-5FFF - RAM Bank Number / ROM Bank Number (bits 5-6) // 6000-7FFF - ROM/RAM Mode Select // 00h = ROM Banking Mode (up to 8KByte RAM, 2MByte ROM) (default) // 01h = RAM Banking Mode (up to 32KByte RAM, 512KByte ROM) BankingMode uint8 // contains filtered or unexported fields }
MBC1 (max 2MByte ROM and/or 32KByte RAM)
func NewMBC1 ¶
NewMBC1 creates an address space emulating a cartridge with an MBC1 chip. Takes an instance of ROM because to know which kind of chip it uses, we had to read it beforehand anyway.
type MMU ¶
type MMU struct {
Spaces []Addressable
}
MMU manages an arbitrary number of ordered address spaces. It also satisfies the Addressable interface.
func NewEmptyMMU ¶
func NewEmptyMMU() *MMU
NewEmptyMMU returns an instance of MMU with no address space.
func NewMMU ¶
func NewMMU(spaces []Addressable) *MMU
NewMMU returns an instance of MMU initialized with existing address spaces.
func (*MMU) Add ¶
func (m *MMU) Add(space Addressable)
Add an address space at the end of this MMU's list.
func (*MMU) Contains ¶
Contains returns whether one of the address spaces known to the MMU contains the given address. The first address space in the internal list containing a given address will shadow any other that may contain it.
type RAM ¶
RAM as an array of R/W bytes at addresses starting from a given offset. If dealing with a battery-backed RAM, this can also be saved to a file.
func (*RAM) Contains ¶
Contains indicates true as long as address fits in the slice. Careful not to wrap uint16 here.
func (*RAM) Load ¶
Load sets the current content of RAM from the given file, and stores the path to that file for subsequent saves.
type ROM ¶
type ROM struct {
RAM
}
ROM is a read-only special case of RAM, initialized from a binary file.
func NewROMFromFile ¶
NewROMFromFile instantiates a read-only chunk of memory from a binary dump. Try to support ZIP files (room for improvement there).