memory

package
v0.0.0-...-db979c7 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NoMBCType      MBCType = iota
	MBC1Type               = iota
	MBC2Type               = iota
	MBC3Type               = iota
	MBC5Type               = iota
	MBC1MultiType          = iota
	MBCUnknownType         = iota
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cartridge

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

Cartridge holds the data and metadata of a gameboy cartridge.

func NewCartridge

func NewCartridge() *Cartridge

NewCartridge creates an empty cartridge, useful only for debugging purposes.

func NewCartridgeWithData

func NewCartridgeWithData(bytes []byte) *Cartridge

NewCartridgeWithData initializes a new Cartridge from a slice of bytes.

func (*Cartridge) Read

func (c *Cartridge) Read(addr uint16) uint8

ReadByte reads a byte at the specified address. Does not check bounds, so the caller must make sure the address is valid for the cartridge.

func (*Cartridge) Write

func (c *Cartridge) Write(addr uint16, value uint8) uint8

WriteByte attempts a write to the specified address. Writing to a cartridge has sense if the cartridge has extra RAM or for some special operations, like switching ROM banks.

type MBC

type MBC interface {
	// Read reads a byte from the specified address
	Read(addr uint16) uint8
	// Write writes a byte to the specified address, returns the written value
	Write(addr uint16, value uint8) uint8
}

MBC represents a Memory Bank Controller interface that all MBC types must implement

type MBC1

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

MBC1 is the first and most common MBC chip. Features include: - Supports up to 2MB ROM (125 16KB banks) - Up to 32KB RAM (4 8KB banks) - Bank 0 always mapped to 0x0000-0x3FFF - Switchable ROM bank at 0x4000-0x7FFF - Optional RAM banking at 0xA000-0xBFFF - Two banking modes:

  • Mode 0 (ROM): Allows access to full ROM but only 8KB RAM
  • Mode 1 (RAM): Restricts ROM banking but allows full RAM access

- Optional battery backup for RAM persistence

func NewMBC1

func NewMBC1(romData []uint8, hasBattery bool, ramBankCount uint8) *MBC1

NewMBC1 creates a new MBC1 controller

func (*MBC1) Read

func (m *MBC1) Read(addr uint16) uint8

func (*MBC1) Write

func (m *MBC1) Write(addr uint16, value uint8) uint8

type MBC2

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

MBC2 is a simpler MBC chip with built-in RAM. Features include:

  • Supports up to 256KB ROM (16 16KB banks)
  • Built-in 512x4 bits RAM (not external)
  • RAM does not require enabling (always accessible)
  • ROM banking similar to MBC1 but simpler
  • The least significant bit of the upper address byte selects between ROM banking and RAM access
  • RAM is limited to 4-bit values (upper 4 bits are ignored)
  • Optional battery backup for the built-in RAM

func NewMBC2

func NewMBC2(romData []uint8) *MBC2

NewMBC2 creates a new MBC2 controller

type MBC3

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

MBC3 is an advanced MBC chip with RTC support. Features include: - Supports up to 2MB ROM (128 16KB banks) - Up to 32KB RAM (4 8KB banks) - Real-Time Clock (RTC) functionality - RTC has 5 registers: Seconds, Minutes, Hours, Days (lower), Days (upper)/Flags - Similar banking to MBC1 but with different register layout - RAM and RTC can be battery backed - Used in games that needed to track real time (e.g. Pokémon Gold/Silver)

func NewMBC3

func NewMBC3(romData []uint8, hasRTC bool, ramBankCount uint8) *MBC3

NewMBC3 creates a new MBC3 controller

type MBC5

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

MBC5 is the most advanced MBC chip. Features include: - Supports up to 8MB ROM (512 16KB banks) - Up to 128KB RAM (16 8KB banks) - Simple ROM/RAM banking with no quirks (unlike MBC1) - 9-bit ROM bank number (allows all 512 banks to be directly accessed) - Optional rumble motor support - Used in Game Boy Color games that needed more ROM/RAM - Backwards compatible with Game Boy

func NewMBC5

func NewMBC5(romData []uint8, hasRumble bool, ramBankCount uint8) *MBC5

NewMBC5 creates a new MBC5 controller

type MBCType

type MBCType int

type MMU

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

MMU allows access to all memory mapped I/O and data/registers

func New

func New() *MMU

New creates a new memory unity with default data, i.e. nothing cartridge loaded. Equivalent to turning on a Gameboy without a cartridge in.

func NewWithCartridge

func NewWithCartridge(cart *Cartridge) *MMU

NewWithCartridge creates a new memory unit with the provided cartridge data loaded. Equivalent to turning on a Gameboy with a cartridge in.

func (*MMU) Read

func (m *MMU) Read(addr uint16) byte

func (*MMU) ReadBit

func (m *MMU) ReadBit(index uint8, addr uint16) bool

func (*MMU) RequestInterrupt

func (m *MMU) RequestInterrupt(interrupt addr.Interrupt)

RequestInterrupt sets the interrupt flag (IF register) of the chosen interrupt to 1.

func (*MMU) SetBit

func (m *MMU) SetBit(index uint8, addr uint16, set bool)

func (*MMU) Write

func (m *MMU) Write(addr uint16, value byte)

type NoMBC

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

NoMBC represents cartridges with no memory banking capabilities. These are typically smaller games (32KB or less) that fit entirely in the base memory region. The cartridge ROM is directly mapped to 0x0000-0x7FFF and cannot be banked/switched. These cartridges cannot have external RAM.

func NewNoMBC

func NewNoMBC(romData []uint8) *NoMBC

NewNoMBC creates a new NoMBC controller

func (*NoMBC) Read

func (m *NoMBC) Read(addr uint16) uint8

func (*NoMBC) Write

func (m *NoMBC) Write(addr uint16, value uint8) uint8

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳