Documentation ¶
Index ¶
- Constants
- func NoiseShooter(w, h int) func() image.Image
- type Bus
- func (b *Bus) Boot()
- func (b *Bus) CanInterrupt() bool
- func (b *Bus) Cartridge() *Cartridge
- func (b *Bus) ClearBit(addr uint16, bit byte)
- func (b *Bus) ClockedRead(addr uint16) byte
- func (b *Bus) ClockedWrite(address uint16, value byte)
- func (b *Bus) CopyFrom(start, end uint16, dest []byte)
- func (b *Bus) CopyTo(start, end uint16, src []byte)
- func (b *Bus) DisableInterrupts()
- func (b *Bus) EnableInterrupts()
- func (b *Bus) Get(addr uint16) byte
- func (b *Bus) HandleHDMA()
- func (b *Bus) HasInterrupts() bool
- func (b *Bus) IRQVector(irq uint8) uint16
- func (b *Bus) InterruptsEnabled() bool
- func (b *Bus) IsBooting() bool
- func (b *Bus) IsGBC() bool
- func (b *Bus) IsGBCCart() bool
- func (b *Bus) LazyRead(addr uint16) byte
- func (b *Bus) LoadCheat(c Cheat, new bool)
- func (b *Bus) Lock(region uint16)
- func (b *Bus) Map(m types.Model)
- func (b *Bus) Model() types.Model
- func (b *Bus) OAMCatchup(f func([160]byte))
- func (b *Bus) OAMChanged() bool
- func (b *Bus) Press(i uint8)
- func (b *Bus) RLock(region uint16)
- func (b *Bus) RUnlock(region uint16)
- func (b *Bus) RaiseInterrupt(interrupt uint8)
- func (b *Bus) RegisterBootHandler(f func())
- func (b *Bus) RegisterGBCHandler(f func())
- func (b *Bus) Release(i uint8)
- func (b *Bus) ReserveAddress(addr uint16, f func(byte) byte)
- func (b *Bus) ReserveLazyReader(addr uint16, f func() byte)
- func (b *Bus) Set(addr uint16, value byte)
- func (b *Bus) SetBit(addr uint16, bit byte)
- func (b *Bus) UnloadCheat(id int, remove bool) error
- func (b *Bus) Unlock(region uint16)
- func (b *Bus) VRAMCatchup(f func([]VRAMChange))
- func (b *Bus) VRAMChanged() bool
- func (b *Bus) WLock(region uint16)
- func (b *Bus) WUnlock(region uint16)
- func (b *Bus) Write(addr uint16, value byte)
- type Button
- type CGBFlag
- type Camera
- type CameraShooter
- type Cartridge
- type CartridgeType
- type Cheat
- type GameGenieCode
- type GameSharkCode
- type VRAMChange
Constants ¶
const ( VRAM uint16 = 0b0000_0011_0000_0000 OAM = 0b1000_0000_0000_0000 )
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 )
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 ¶
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 // cheats LoadedCheats []Cheat GameGenieCodes []GameGenieCode GameSharkCodes []GameSharkCode // 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 (*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 (*Bus) ClockedRead ¶
ClockedRead clocks the Game Boy and reads a byte from the bus.
func (*Bus) ClockedWrite ¶
ClockedWrite clocks the Game Boy and writes a byte to the bus.
func (*Bus) DisableInterrupts ¶
func (b *Bus) DisableInterrupts()
func (*Bus) HandleHDMA ¶
func (b *Bus) HandleHDMA()
func (*Bus) HasInterrupts ¶
func (*Bus) IRQVector ¶
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 (*Bus) OAMCatchup ¶
OAMCatchup calls f with the OAM memory region.
func (*Bus) OAMChanged ¶
func (*Bus) RaiseInterrupt ¶
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) ReserveLazyReader ¶
func (*Bus) VRAMCatchup ¶
func (b *Bus) VRAMCatchup(f func([]VRAMChange))
VRAMCatchup calls f with pending vRAM changes.
func (*Bus) VRAMChanged ¶
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 ¶
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 ¶
NewCartridge creates a new cartridge from the provided ROM.
func (*Cartridge) Destination ¶
Destination returns the destination as specified in the cartridge header.
func (*Cartridge) IsCGBCartridge ¶
IsCGBCartridge returns true if the cartridge makes use of CGB features, optionally or not.
func (*Cartridge) Licensee ¶
Licensee returns the Licensee of the cartridge, according to the parsed header data.
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 ¶
func ParseGameGenieCode ¶
func ParseGameGenieCode(code string) (GameGenieCode, error)
type GameSharkCode ¶
func ParseGameSharkCode ¶
func ParseGameSharkCode(code string) (GameSharkCode, error)