gameboy

package
v0.0.0-...-657eaca Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const VBlankRate = apu.GameBoyRate / 60

VBlankRate represents ticks to wait before refreshing the Home screen.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action func(eventType uint32)

Action type for user interactions. This might move to a ui package someday.

type GameBoy

type GameBoy struct {
	UI *ui.UI

	APU     *apu.APU
	CPU     *cpu.CPU
	PPU     *ppu.PPU
	Display *screen.Screen
	DMA     *memory.DMA
	Serial  *serial.Serial
	Timer   *timer.Timer
	JPad    *joypad.Joypad

	Controls map[options.KeyStroke]Action
	// contains filtered or unexported fields
}

GameBoy structure grouping all our state machines to tick them together.

func New

func New(config *options.Options) *GameBoy

New just instantiates most of the emulator. No biggie. TODO: try cleaning this mess up a little.

func (*GameBoy) Home

func (g *GameBoy) Home(eventType uint32)

Home stops the emulation to display some kind of home menu. Clearing it should be done from the UI itself. Which, in itself, is going to be another whole thing.

Doing this should pave the way for high-level stuff the emulator should do on VBlank like saving or loading states and suchlike.

func (*GameBoy) JoypadA

func (g *GameBoy) JoypadA(eventType uint32)

JoypadA updates the Joypad's registers for the A button.

func (*GameBoy) JoypadB

func (g *GameBoy) JoypadB(eventType uint32)

JoypadB updates the Joypad's registers for the B button.

func (*GameBoy) JoypadDown

func (g *GameBoy) JoypadDown(eventType uint32)

JoypadDown updates the Joypad's registers for the Down direction.

func (*GameBoy) JoypadLeft

func (g *GameBoy) JoypadLeft(eventType uint32)

JoypadLeft updates the Joypad's registers for the Left direction.

func (*GameBoy) JoypadRight

func (g *GameBoy) JoypadRight(eventType uint32)

JoypadRight updates the Joypad's registers for the Right direction.

func (*GameBoy) JoypadSelect

func (g *GameBoy) JoypadSelect(eventType uint32)

JoypadSelect updates the Joypad's registers for the Select button.

func (*GameBoy) JoypadStart

func (g *GameBoy) JoypadStart(eventType uint32)

JoypadStart updates the Joypad's registers for the Start button.

func (*GameBoy) JoypadUp

func (g *GameBoy) JoypadUp(eventType uint32)

JoypadUp updates the Joypad's registers for the Up direction.

func (*GameBoy) NextPalette

func (g *GameBoy) NextPalette(eventType uint32)

NextPalette switches colors to the next defined palette, wrapping around. There should always be at least a default palette in the config object.

func (*GameBoy) PreviousPalette

func (g *GameBoy) PreviousPalette(eventType uint32)

PreviousPalette switches colors to the previous defined palette, wrapping around. There should always be at least a default palette in the config object.

func (*GameBoy) ProcessEvents

func (g *GameBoy) ProcessEvents()

func (*GameBoy) Quit

func (g *GameBoy) Quit(eventType uint32)

Quit cleanly quits the program.

func (*GameBoy) Recover

func (g *GameBoy) Recover()

Recover should be called at the end of each Tick. If the program panics, it should then display some useful debug info before crashing.

func (*GameBoy) Screenshot

func (g *GameBoy) Screenshot(eventType uint32)

Screenshot saves the current frame to disk as a PNG file. TODO: configurable folder, obviously.

func (*GameBoy) SetControls

func (g *GameBoy) SetControls(keymap options.Keymap) (err error)

SetControls validates and sets the given control map for the emulator.

func (*GameBoy) StartStopRecord

func (g *GameBoy) StartStopRecord(eventType uint32)

StartStopRecord starts recording video output to GIF and closes the file when done. Defined as a single action to toggle between the two and avoid opening several GIFs at once.

func (*GameBoy) Stop

func (g *GameBoy) Stop()

Stop should be called before quitting the program and will close all needed resources.

func (*GameBoy) Tick

func (g *GameBoy) Tick() (res TickResult)

Tick advances the whole emulator one step at a theoretical 4MHz. Since we're using SDL audio for timing this, we also return the current value of audio samples for each stereo channel as well as whether they should be played now.

func (*GameBoy) ToggleVoice1

func (g *GameBoy) ToggleVoice1(eventType uint32)

ToggleVoice1 mutes or unmutes the first audio generator (Square 1).

func (*GameBoy) ToggleVoice2

func (g *GameBoy) ToggleVoice2(eventType uint32)

ToggleVoice2 mutes or unmutes the second audio generator (Square 2).

func (*GameBoy) ToggleVoice3

func (g *GameBoy) ToggleVoice3(eventType uint32)

ToggleVoice3 mutes or unmutes the third audio generator (Wave).

func (*GameBoy) ToggleVoice4

func (g *GameBoy) ToggleVoice4(eventType uint32)

ToggleVoice4 mutes or unmutes the fourth audio generator (Noise).

type TickResult

type TickResult struct {
	Left, Right int8
	Play        bool
}

TickResult type to group return values from Tick.

Jump to

Keyboard shortcuts

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