io

package
v0.0.0-...-e7615e3 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VRAM uint16 = 0b0000_0011_0000_0000
	OAM         = 0b1000_0000_0000_0000
)
View Source
const (
	VBlankINT = types.Bit0 // ppu vblank
	LCDINT    = types.Bit1 // lcd stat
	TimerINT  = types.Bit2 // timer overflow
	SerialINT = types.Bit3 // serial transfer
	JoypadINT = types.Bit4 // joypad
)
View Source
const (
	CameraShoot               = iota
	CameraNVH                 // output gain and edge operation mode
	CameraC0                  // exposure MSB
	CameraC1                  // exposure LSB
	CameraEVI                 // output voltage reference, edge enhancement ratio & invert
	CameraDitherContrastStart = 6
	CameraDitherContrastEnd   = 0x35

	CameraSensorW = 128
	CameraSensorH = 120
	CameraW       = 128
	CameraH       = 112

	CameraTileSize = 14 << 8

	Filter1D         = 0
	Filter1DAndHoriz = 2
	Filter2D         = 14
)

Variables

This section is empty.

Functions

func NoiseShooter

func NoiseShooter(w, h int) func() image.Image

NoiseShooter is a simple CameraShooter that returns random noise.

Types

type Bus

type Bus struct {
	InterruptCallback func(v uint8) // used to notify CPU of interrupts
	// contains filtered or unexported fields
}

Bus is the main component responsible for handling IO operations on the Game Boy. The Game Boy has a 16-bit address bus, allowing for a 64KiB memory space.

The memory space is mapped as so:

	Start  | End	| Name
 ----------------------------
	0x0000 | 0x7FFF | ROM
	0x8000 | 0x9FFF | VRAM
	0xA000 | 0xBFFF | External RAM
	0xC000 | 0xDFFF | Work RAM
	0xE000 | 0xFDFF | Work RAM Mirror
	0xFE00 | 0xFE9F | OAM
	0xFEA0 | 0xFEFF | Not used
	0xFF00 | 0xFF7F | IO Registers
	0xFF80 | 0xFFFE | High RAM
	0xFFFF | 0xFFFF | Interrupt Enable Register

func NewBus

func NewBus(s *scheduler.Scheduler, rom []byte) *Bus

NewBus creates a new Bus instance.

func (*Bus) Boot

func (b *Bus) Boot()

Boot the Bus to the state it would be in after execution of the boot ROM.

func (*Bus) CanInterrupt

func (b *Bus) CanInterrupt() bool

func (*Bus) Cartridge

func (b *Bus) Cartridge() *Cartridge

func (*Bus) ClearBit

func (b *Bus) ClearBit(addr uint16, bit byte)

func (*Bus) ClockedRead

func (b *Bus) ClockedRead(addr uint16) byte

ClockedRead clocks the Game Boy and reads a byte from the bus.

func (*Bus) ClockedWrite

func (b *Bus) ClockedWrite(address uint16, value byte)

ClockedWrite clocks the Game Boy and writes a byte to the bus.

func (*Bus) CopyFrom

func (b *Bus) CopyFrom(start, end uint16, dest []byte)

func (*Bus) CopyTo

func (b *Bus) CopyTo(start, end uint16, src []byte)

func (*Bus) DisableInterrupts

func (b *Bus) DisableInterrupts()

func (*Bus) EnableInterrupts

func (b *Bus) EnableInterrupts()

EnableInterrupts sets IME

func (*Bus) Get

func (b *Bus) Get(addr uint16) byte

func (*Bus) HandleHDMA

func (b *Bus) HandleHDMA()

func (*Bus) HasInterrupts

func (b *Bus) HasInterrupts() bool

func (*Bus) IRQVector

func (b *Bus) IRQVector(irq uint8) uint16

IRQVector returns the current interrupt vector and clears the corresponding interrupt from types.IF.

When an interrupt occurs, there is a chance for the interrupt vector to change during the execution of the dispatch handler. https://mgba.io/2018/03/09/holy-grail-bugs-revisited/

func (*Bus) InterruptsEnabled

func (b *Bus) InterruptsEnabled() bool

func (*Bus) IsBooting

func (b *Bus) IsBooting() bool

func (*Bus) IsGBC

func (b *Bus) IsGBC() bool

func (*Bus) IsGBCCart

func (b *Bus) IsGBCCart() bool

func (*Bus) LazyRead

func (b *Bus) LazyRead(addr uint16) byte

func (*Bus) Lock

func (b *Bus) Lock(region uint16)

func (*Bus) Map

func (b *Bus) Map(m types.Model)

func (*Bus) Model

func (b *Bus) Model() types.Model

func (*Bus) OAMCatchup

func (b *Bus) OAMCatchup(f func([160]byte))

OAMCatchup calls f with the OAM memory region.

func (*Bus) OAMChanged

func (b *Bus) OAMChanged() bool

func (*Bus) Press

func (b *Bus) Press(i uint8)

func (*Bus) RLock

func (b *Bus) RLock(region uint16)

func (*Bus) RUnlock

func (b *Bus) RUnlock(region uint16)

func (*Bus) RaiseInterrupt

func (b *Bus) RaiseInterrupt(interrupt uint8)

RaiseInterrupt sets the requested interrupt high in types.IF

func (*Bus) RegisterBootHandler

func (b *Bus) RegisterBootHandler(f func())

func (*Bus) RegisterGBCHandler

func (b *Bus) RegisterGBCHandler(f func())

func (*Bus) Release

func (b *Bus) Release(i uint8)

func (*Bus) ReserveAddress

func (b *Bus) ReserveAddress(addr uint16, f func(byte) byte)

func (*Bus) ReserveLazyReader

func (b *Bus) ReserveLazyReader(addr uint16, f func() byte)

func (*Bus) Set

func (b *Bus) Set(addr uint16, value byte)

func (*Bus) SetBit

func (b *Bus) SetBit(addr uint16, bit byte)

func (*Bus) Unlock

func (b *Bus) Unlock(region uint16)

func (*Bus) VRAMCatchup

func (b *Bus) VRAMCatchup(f func([]VRAMChange))

VRAMCatchup calls f with pending vRAM changes.

func (*Bus) VRAMChanged

func (b *Bus) VRAMChanged() bool

func (*Bus) WLock

func (b *Bus) WLock(region uint16)

func (*Bus) WUnlock

func (b *Bus) WUnlock(region uint16)

func (*Bus) Write

func (b *Bus) Write(addr uint16, value byte)

Write writes to the specified memory address. This function calls the write handler if it exists.

type Button

type Button = uint8
const (
	ButtonA Button = iota
	ButtonB
	ButtonSelect
	ButtonStart
	ButtonRight
	ButtonLeft
	ButtonUp
	ButtonDown
)

type CGBFlag

type CGBFlag uint8 // CGBFlag specifies the level of CGB support in a Cartridge.
const (
	CGBUnset    CGBFlag = iota // No CGB support has been specified, >99.9% a regular Game Boy game.
	CGBEnhanced                // The game supports CGB enhancements, but is backwards compatible.
	CGBOnly                    // The game works on CGB only.
)

func (CGBFlag) String

func (i CGBFlag) String() string

type Camera

type Camera struct {
	CameraShooter

	Filter1D, Filter1DAndHoriz, Filter2D bool // disable/enable filtering modes

	ShotImage   image.Image                       // the image that comes in from CameraShooter
	SensedImage [CameraSensorW][CameraSensorH]int // the image that the sensor "sees"
	Registers   [0x36]uint8
	// contains filtered or unexported fields
}

Camera implements the functionality of the POCKETCAMERA cartridge, allowing for any image.Image to be used as the camera's source.

type CameraShooter

type CameraShooter func() image.Image

CameraShooter mimics a "camera" attached to the emulator, by simply returning an image.Image. This allows for any image source to be used as a camera input.

type Cartridge

type Cartridge struct {
	ROM []byte
	RAM []byte

	Title            string  // $0134-$0143 Title of the game in uppercase ASCII.
	ManufacturerCode string  // $013F-$0142 4-character ManufacturerCode (in uppercase ASCII) - purpose remains unknown
	CGBFlag                  // $0142 - Indicates level of CGB support
	NewLicenseeCode  [2]byte // $0144-$0145 2-character ASCII "licensee code"
	SGBFlag          bool    // $0146 - Specifies whether the game supports SGB functions
	CartridgeType            // $0147 - Specifies the hardware present on a Cartridge.
	ROMSize          int     // $0148 - Specifies how much ROM is on the Cartridge, calculated by 32 KiB x (1<<value)
	RAMSize          int     // $0149 - Specifies how much RAM is present on the Cartridge, if any.
	DestinationCode  byte    // $014A - Specifies whether the game is intended to be sold in Japan or elsewhere
	OldLicenseeCode  byte    // $014B - Specifies the game's publisher; see NewLicenseeCode if val == $33
	MaskROMVersion   uint8   // $014C - Specifies the version of the game, usually $00
	HeaderChecksum   uint8   // $014D - 8-Bit checksum of header bytes $0134-$014C
	GlobalChecksum   uint16  // $014E-$014F 16-bit (big endian) checksum of Cartridge ROM (excluding these bytes)

	Features struct {
		Accelerometer bool
		Battery       bool
		RAM           bool
		RTC           bool
		Rumble        bool
	}

	RumbleCallback func(bool)

	Camera *Camera

	AccelerometerX, AccelerometerY float32 // TODO refactor this to somewhere more appropriate
	// contains filtered or unexported fields
}

func NewCartridge

func NewCartridge(rom []byte, b *Bus) *Cartridge

NewCartridge creates a new cartridge from the provided ROM.

func (*Cartridge) Destination

func (c *Cartridge) Destination() string

Destination returns the destination as specified in the cartridge header.

func (*Cartridge) IsCGBCartridge

func (c *Cartridge) IsCGBCartridge() bool

IsCGBCartridge returns true if the cartridge makes use of CGB features, optionally or not.

func (*Cartridge) Licensee

func (c *Cartridge) Licensee() string

Licensee returns the Licensee of the cartridge, according to the parsed header data.

func (*Cartridge) SGB

func (c *Cartridge) SGB() bool

SGB returns true if the Cartridge supports SGB functions.

func (*Cartridge) String

func (c *Cartridge) String() string

String implements the fmt.Stringer interface.

func (*Cartridge) Write

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

Write writes an 8-bit value to the cartridge.

type CartridgeType

type CartridgeType uint16 // CartridgeType represents the hardware present in a Cartridge.
const (
	ROM               CartridgeType = 0x00
	MBC1              CartridgeType = 0x01
	MBC1RAM           CartridgeType = 0x02
	MBC1RAMBATT       CartridgeType = 0x03
	MBC2              CartridgeType = 0x05
	MBC2BATT          CartridgeType = 0x06
	MMM01             CartridgeType = 0x0B
	MMM01RAM          CartridgeType = 0x0C
	MMM01RAMBATT      CartridgeType = 0x0D
	MBC3TIMERBATT     CartridgeType = 0x0F
	MBC3TIMERRAMBATT  CartridgeType = 0x10
	MBC3              CartridgeType = 0x11
	MBC3RAM           CartridgeType = 0x12
	MBC3RAMBATT       CartridgeType = 0x13
	MBC5              CartridgeType = 0x19
	MBC5RAM           CartridgeType = 0x1A
	MBC5RAMBATT       CartridgeType = 0x1B
	MBC5RUMBLE        CartridgeType = 0x1C
	MBC5RUMBLERAM     CartridgeType = 0x1D
	MBC5RUMBLERAMBATT CartridgeType = 0x1E
	MBC6              CartridgeType = 0x20
	MBC7              CartridgeType = 0x22
	POCKETCAMERA      CartridgeType = 0xFC
	BANDAITAMA5       CartridgeType = 0xFD
	HUDSONHUC3        CartridgeType = 0xFE
	HUDSONHUC1        CartridgeType = 0xFF
	MBC1M             CartridgeType = 0x0100
	M161              CartridgeType = 0x0101
	WISDOMTREE        CartridgeType = 0x102
)

func (CartridgeType) String

func (i CartridgeType) String() string

type GameGenieCode

type GameGenieCode struct {
	NewData byte
	Address uint16
	OldData byte
}

type GameSharkCode

type GameSharkCode struct {
	ExternalRAMBank uint8
	Address         uint16
	NewData         uint8
}

type VRAMChange

type VRAMChange struct {
	Address uint16
	Value   uint8
	Bank    uint8
}

Jump to

Keyboard shortcuts

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