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.
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 ¶
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 ¶
NewCartFromFile loads a cartridge ROM from a file.
func (*Cart) GetName ¶
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 ¶
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
type MBC1 ¶
type MBC1 struct {
// contains filtered or unexported fields
}
MBC1 is a GameBoy cartridge that supports rom and ram banking.
func (*MBC1) GetSaveData ¶
GetSaveData returns the save data for this banking controller.
func (*MBC1) LoadSaveData ¶
LoadSaveData loads the save data into the cartridge.
type MBC2 ¶
type MBC2 struct {
// contains filtered or unexported fields
}
MBC2 is a basic Gameboy cartridge.
func (*MBC2) GetSaveData ¶
GetSaveData returns the save data for this banking controller.
func (*MBC2) LoadSaveData ¶
LoadSaveData loads the save data into the cartridge.
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 ¶
GetSaveData returns the save data for this banking controller.
func (*MBC3) LoadSaveData ¶
LoadSaveData loads the save data into the cartridge.
type MBC5 ¶
type MBC5 struct {
// contains filtered or unexported fields
}
MBC5 is a GameBoy cartridge that supports rom and ram banking.
func (*MBC5) GetSaveData ¶
GetSaveData returns the save data for this banking controller.
func (*MBC5) LoadSaveData ¶
LoadSaveData loads the save data into the cartridge.
type ROM ¶
type ROM struct {
// contains filtered or unexported fields
}
ROM is a basic Gameboy cartridge.
func (*ROM) GetSaveData ¶
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 ¶
LoadSaveData loads the save data into the cartridge. As RAM is not supported on this memory controller, this is a noop.