cart

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2018 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BankingController

type BankingController interface {
	// Read returns the value from the cartridges ROM or RAM depending on
	// the banking.
	Read(address uint16) byte

	// WriteROM attempts to write a value to an address in ROM. This is
	// generally used for switching memory banks depending on the implementation.
	WriteROM(address uint16, value byte)

	// WriteRAM sets a value on an address in the internal cartridge RAM.
	// Like the ROM, this can be banked depending on the implementation
	// of the memory controller. Furthermore, if the cartridge supports
	// RAM+BATTERY, then this data can be saved between sessions.
	WriteRAM(address uint16, value byte)

	// GetSaveData returns the save data for this banking controller. In
	// general this will the contents of the RAM, however controllers may
	// choose to store this data in their own format.
	GetSaveData() []byte

	// LoadSaveData loads some save data into the cartridge. The banking
	// controller implementation can decide how this data should be loaded.
	LoadSaveData(data []byte)
}

BankingController provides methods for accessing and writing data to a cartridge, which provides different banking functionality depending on the implementation.

func NewMBC1

func NewMBC1(data []byte) BankingController

NewMBC1 returns a new MBC1 memory controller.

func NewMBC2

func NewMBC2(data []byte) BankingController

NewMBC2 returns a new MBC2 memory controller.

func NewMBC3

func NewMBC3(data []byte) BankingController

NewMBC3 returns a new MBC3 memory controller.

func NewMBC5

func NewMBC5(data []byte) BankingController

NewMBC5 returns a new MBC5 memory controller.

func NewROM

func NewROM(data []byte) BankingController

NewROM returns a new ROM cartridge.

type Cart

type Cart struct {
	BankingController
	// contains filtered or unexported fields
}

Cart represents a GameBoy cartridge.

The cartridge is an extension of a banking controller which determines how the cart reacts with memory banking. The banking controller provides methods for reading and writing data to the cartridge, along with extra functionality such as RTC (real time clock).

func NewCart

func NewCart(rom []byte, filename string) *Cart

NewCart loads a cartridge ROM from a byte array and returns a new cartridge with the correct memory banking controller. If the game supports saves, then the save file for the cartridge will also be loaded, and the saving loop will be started to write the save data back to file.

The function will use the following list to determine which MBC to use. Not all of the controllers are supported, and the function will only start the save loop for controllers which support RAM+BATTERY.

0x00  ROM ONLY
0x01  MBC1
0x02  MBC1+RAM
0x03  MBC1+RAM+BATTERY
0x05  MBC2
0x06  MBC2+BATTERY
0x08  ROM+RAM
0x09  ROM+RAM+BATTERY
0x0B  MMM01
0x0C  MMM01+RAM
0x0D  MMM01+RAM+BATTERY
0x0F  MBC3+TIMER+BATTERY
0x10  MBC3+TIMER+RAM+BATTERY
0x11  MBC3
0x12  MBC3+RAM
0x13  MBC3+RAM+BATTERY
0x15  MBC4
0x16  MBC4+RAM
0x17  MBC4+RAM+BATTERY
0x19  MBC5
0x1A  MBC5+RAM
0x1B  MBC5+RAM+BATTERY
0x1C  MBC5+RUMBLE
0x1D  MBC5+RUMBLE+RAM
0x1E  MBC5+RUMBLE+RAM+BATTERY
0xFC  POCKET CAMERA
0xFD  BANDAI TAMA5
0xFE  HuC3
0xFF  HuC1+RAM+BATTERY

func NewCartFromFile

func NewCartFromFile(filename string) (*Cart, error)

NewCartFromFile loads a cartridge ROM from a file.

func (*Cart) GetMode

func (c *Cart) GetMode() Mode

GetMode returns the modes that this cart can run in.

func (*Cart) GetName

func (c *Cart) GetName() string

GetName returns the name of the cartridge. This is retrieved from the memory location [0x134,0x142) on the cartridge. The function will cache the result of the read from the cartridge.

func (*Cart) GetSaveFilename

func (c *Cart) GetSaveFilename() string

GetSaveFilename returns the name of the file that the game should be saved to. This is used for saving and loading save data to the cartridge. TODO: do something better here

func (*Cart) Save

func (c *Cart) Save()

Save dumps the carts RAM to the save location.

type MBC1

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

MBC1 is a GameBoy cartridge that supports rom and ram banking.

func (*MBC1) GetSaveData

func (r *MBC1) GetSaveData() []byte

GetSaveData returns the save data for this banking controller.

func (*MBC1) LoadSaveData

func (r *MBC1) LoadSaveData(data []byte)

LoadSaveData loads the save data into the cartridge.

func (*MBC1) Read

func (r *MBC1) Read(address uint16) byte

Read returns a value at a memory address in the ROM or RAM.

func (*MBC1) WriteRAM

func (r *MBC1) WriteRAM(address uint16, value byte)

WriteRAM writes data to the ram if it is enabled.

func (*MBC1) WriteROM

func (r *MBC1) WriteROM(address uint16, value byte)

WriteROM attempts to switch the ROM or RAM bank.

type MBC2

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

MBC2 is a basic Gameboy cartridge.

func (*MBC2) GetSaveData

func (r *MBC2) GetSaveData() []byte

GetSaveData returns the save data for this banking controller.

func (*MBC2) LoadSaveData

func (r *MBC2) LoadSaveData(data []byte)

LoadSaveData loads the save data into the cartridge.

func (*MBC2) Read

func (r *MBC2) Read(address uint16) byte

Read returns a value at a memory address in the ROM or RAM.

func (*MBC2) WriteRAM

func (r *MBC2) WriteRAM(address uint16, value byte)

WriteRAM writes data to the ram if it is enabled.

func (*MBC2) WriteROM

func (r *MBC2) WriteROM(address uint16, value byte)

WriteROM attempts to switch the ROM or RAM bank.

type MBC3

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

MBC3 is a GameBoy cartridge that supports rom and ram banking and possibly a real time clock (RTC).

func (*MBC3) GetSaveData

func (r *MBC3) GetSaveData() []byte

GetSaveData returns the save data for this banking controller.

func (*MBC3) LoadSaveData

func (r *MBC3) LoadSaveData(data []byte)

LoadSaveData loads the save data into the cartridge.

func (*MBC3) Read

func (r *MBC3) Read(address uint16) byte

Read returns a value at a memory address in the ROM.

func (*MBC3) WriteRAM

func (r *MBC3) WriteRAM(address uint16, value byte)

WriteRAM writes data to the ram or RTC if it is enabled.

func (*MBC3) WriteROM

func (r *MBC3) WriteROM(address uint16, value byte)

WriteROM attempts to switch the ROM or RAM bank.

type MBC5

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

MBC5 is a GameBoy cartridge that supports rom and ram banking.

func (*MBC5) GetSaveData

func (r *MBC5) GetSaveData() []byte

GetSaveData returns the save data for this banking controller.

func (*MBC5) LoadSaveData

func (r *MBC5) LoadSaveData(data []byte)

LoadSaveData loads the save data into the cartridge.

func (*MBC5) Read

func (r *MBC5) Read(address uint16) byte

Read returns a value at a memory address in the ROM.

func (*MBC5) WriteRAM

func (r *MBC5) WriteRAM(address uint16, value byte)

WriteRAM writes data to the ram if it is enabled.

func (*MBC5) WriteROM

func (r *MBC5) WriteROM(address uint16, value byte)

WriteROM attempts to switch the ROM or RAM bank.

type Mode

type Mode int

Mode represents the types of mode the GameBoy can run in.

const (
	// DMG is the mode for the original GameBoy.
	DMG Mode = 1 << iota
	// CGB is the mode for the GameBoy Color.
	CGB
)

type ROM

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

ROM is a basic Gameboy cartridge.

func (*ROM) GetSaveData

func (r *ROM) GetSaveData() []byte

GetSaveData returns the save data for this banking controller. As RAM is not supported on this memory controller, this is a noop.

func (*ROM) LoadSaveData

func (r *ROM) LoadSaveData([]byte)

LoadSaveData loads the save data into the cartridge. As RAM is not supported on this memory controller, this is a noop.

func (*ROM) Read

func (r *ROM) Read(address uint16) byte

Read returns a value at a memory address in the ROM.

func (*ROM) WriteRAM

func (r *ROM) WriteRAM(address uint16, value byte)

WriteRAM would write data to the cartridge RAM, however a ROM cart does not contain RAM so this is a noop.

func (*ROM) WriteROM

func (r *ROM) WriteROM(address uint16, value byte)

WriteROM would switch between cartridge banks, however a ROM cart does not support banking.

Jump to

Keyboard shortcuts

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