gpu

package
v0.0.0-...-8886972 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SCREEN_WIDTH  = 160
	SCREEN_HEIGHT = 144
)
View Source
const (
	LCDCAddr types.Addr = 0x40
	LCDSAddr            = 0x41
	SCYAddr             = 0x42
	SCXAddr             = 0x43
	LYAddr              = 0x44
	LYCAddr             = 0x45
	DMAAddr             = 0x46
	BGPAddr             = 0x47
	OBP0Addr            = 0x48
	OBP1Addr            = 0x49
	WYAddr              = 0x4A
	WXAddr              = 0x4B
	BCPSAddr            = 0x68
	BCPDAddr            = 0x69
	OCPSAddr            = 0x6A
	OCPDAddr            = 0x6B
)

Offset is FF00

View Source
const CyclePerLine = 456
View Source
const OAMSTARTAddr types.Addr = 0xFE00
View Source
const SPRITE_NUM = 40

Variables

This section is empty.

Functions

This section is empty.

Types

type BGTileMapArea

type BGTileMapArea types.Addr
const (
	BGTileMapArea0 BGTileMapArea = 0x9800
	BGTileMapArea1               = 0x9C00
)

type BGWindowTileDataArea

type BGWindowTileDataArea types.Addr
const (
	BGWindowTileDataArea0 BGWindowTileDataArea = 0x8800
	BGWindowTileDataArea1                      = 0x8000
)

type Color

type Color byte
const (
	White Color = iota
	LightGray
	DarkGray
	Black
)

type GPU

type GPU struct {
	LCDC   *LCDC
	LCDS   *LCDS
	Scroll *Scroll

	DMA byte
	// contains filtered or unexported fields
}

func New

func New() *GPU

func (*GPU) Display

func (g *GPU) Display() (*image.RGBA, *image.RGBA)

func (*GPU) ImageData

func (g *GPU) ImageData() ([SCREEN_WIDTH][SCREEN_HEIGHT]color.RGBA, [3][128]Tile)

func (*GPU) Init

func (g *GPU) Init(bus interfaces.Bus, requestIRQ func(byte))

func (*GPU) IsDmaStarted

func (g *GPU) IsDmaStarted() bool

func (*GPU) Read

func (g *GPU) Read(addr types.Addr) byte

func (*GPU) Step

func (g *GPU) Step(cycles uint)

gpu main process

func (*GPU) TransferOAM

func (g *GPU) TransferOAM()

WIP

func (*GPU) Write

func (g *GPU) Write(addr types.Addr, value byte)

type LCDC

type LCDC struct {
	Data byte
}

Addresss is $FF40

LCDC is [Liquid Crystal Display Controll]
Its bits toggle what elements are displayed on the screen, and how.
@see https://gbdev.io/pandocs/LCDC.html#lcd-control

func NewLCDC

func NewLCDC(data byte) *LCDC

func (*LCDC) BGTileMapArea

func (l *LCDC) BGTileMapArea() BGTileMapArea

BG tile map area

0=9800-9BFF, 1=9C00-9FFF

func (*LCDC) BGWinEnable

func (l *LCDC) BGWinEnable() bool

BG and Window enable/priority

func (*LCDC) BGWinTileDataArea

func (l *LCDC) BGWinTileDataArea() BGWindowTileDataArea

BG and Window tile data area

0=8800-97FF, 1=8000-8FFF

func (*LCDC) LCDPPUEnable

func (l *LCDC) LCDPPUEnable() bool

LCD and PPU enable

func (*LCDC) OBJEnable

func (l *LCDC) OBJEnable() bool

OBJ enable

func (*LCDC) OBJSize

func (l *LCDC) OBJSize() uint8

OBJ size

0=8x8, 1=8x16

func (*LCDC) WinTileMapArea

func (l *LCDC) WinTileMapArea() WindowTileMapArea

Window tile map area

0=9800-9BFF, 1=9C00-9FFF

func (*LCDC) WindowEnable

func (l *LCDC) WindowEnable() bool

Window enable

type LCDS

type LCDS struct {
	Data byte
}

Addresss is $FF41

LCDC is [Liquid Crystal Display Status]
@see https://gbdev.io/pandocs/STAT.html#lcd-status-register

func NewLCDS

func NewLCDS(data byte) *LCDS

func (*LCDS) LYC

func (l *LCDS) LYC() bool

Bit 6 LY STAT Interrupt source

func (*LCDS) LYCLY

func (l *LCDS) LYCLY() bool

Bit 2 OAM STAT Interrupt source

func (*LCDS) Mode

func (l *LCDS) Mode() Mode

Bit 1-0 0: HBlank 1: VBlank 2: Searching OAM 3: Transferring Data to LCD Controller

func (*LCDS) Mode0

func (l *LCDS) Mode0() bool

Bit 3 HBlank STAT Interrupt source

func (*LCDS) Mode1

func (l *LCDS) Mode1() bool

Bit 4 VBlank STAT Interrupt source

func (*LCDS) Mode2

func (l *LCDS) Mode2() bool

Bit 5 OAM STAT Interrupt source

type Mode

type Mode byte
const (
	Mode_HBlank Mode = iota
	Mode_VBlank
	Mode_SearchingOAM
	Mode_TransferringData
)

type OAM

type OAM struct {
	Objs [40]*Obj
	Buf  [0xA0]byte
}

Object Attribute Memory FE00-FE9F

func NewOAM

func NewOAM() *OAM

func (*OAM) Read

func (o *OAM) Read(addr types.Addr) byte

func (*OAM) Write

func (o *OAM) Write(addr types.Addr, data byte)

WIP @see https://gbdev.io/pandocs/OAM.html#writing-data-to-oam

type Obj

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

type Palette

type Palette struct {
	// FF47
	BGP byte
	// FF48
	OBP0 byte
	// FF49
	OBP1 byte

	// FF68
	BCPS byte
	// FF69
	BCPD byte
	// FF6A
	OCPS byte
	// FF6B
	OCPD byte
}

func NewPalette

func NewPalette() *Palette

func (*Palette) GetObjPalette

func (p *Palette) GetObjPalette(idx Color, obp uint) color.RGBA

func (*Palette) GetPalette

func (p *Palette) GetPalette(idx Color) color.RGBA

func (*Palette) Read

func (p *Palette) Read(addr types.Addr) byte

func (*Palette) Write

func (p *Palette) Write(addr types.Addr, value byte)

type Scroll

type Scroll struct {
	// FF42, FF43
	SCY, SCX byte
	/*
	  FF44
	   LY indicates the current horizontal line
	   LY can hold any value from 0 to 153,
	   with values from 144 to 153 indicating the VBlank period.
	    if LY >= 154 LY = 0
	*/
	LY byte

	/*
	  FF45
	   The Game Boy permanently compares the value of the LYC and LY registers.
	   When both values are identical, the “LYC=LY” flag in the STAT register is
	   set, and (if enabled) a STAT interrupt is requested.
	*/
	LYC byte
	// FF4A, FF4B
	WX, WY byte
}

func NewScroll

func NewScroll() *Scroll

func (*Scroll) Read

func (s *Scroll) Read(addr types.Addr) byte

func (*Scroll) Write

func (s *Scroll) Write(addr types.Addr, value byte)

type Sprite

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

func NewSprite

func NewSprite(bytes4 []byte) *Sprite

func (*Sprite) CGBPaletteNo

func (s *Sprite) CGBPaletteNo() byte

func (*Sprite) MBGPalleteNo

func (s *Sprite) MBGPalleteNo() byte

Non CGB Mode Only 0=OBP0, 1=OBP1

func (*Sprite) TileIdx

func (s *Sprite) TileIdx() byte

func (*Sprite) VRAMBank

func (s *Sprite) VRAMBank() byte

0=Bank 0, 1=Bank 1

func (*Sprite) XFlip

func (s *Sprite) XFlip() bool

func (*Sprite) YFlip

func (s *Sprite) YFlip() bool

type Tile

type Tile struct {
	// 8 x 8 pixels
	Data [8][8]Color
}

https://gbdev.io/pandocs/Tile_Data.html

func NewTile

func NewTile(bytes16 []byte) *Tile

type TileMap

type TileMap struct {
	MapData [32][32]Tile
}

type WindowTileMapArea

type WindowTileMapArea types.Addr
const (
	WindowTileMapArea0 WindowTileMapArea = 0x9800
	WindowTileMapArea1                   = 0x9C00
)

Jump to

Keyboard shortcuts

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