emulator

package
v0.0.0-...-771d5d4 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EmulatorTypeNES = "NES"
)

Variables

View Source
var (
	ErrorEmulatorNotSupported = errors.New("emulator not supported")
)

Functions

This section is empty.

Types

type BaseEmulatorSave

type BaseEmulatorSave struct {
	Game string
	Data []byte
}

func (*BaseEmulatorSave) GameName

func (s *BaseEmulatorSave) GameName() string

func (*BaseEmulatorSave) SaveData

func (s *BaseEmulatorSave) SaveData() []byte

type BaseFrame

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

func (*BaseFrame) Height

func (b *BaseFrame) Height() int

func (*BaseFrame) Read

func (b *BaseFrame) Read() (image.Image, func(), error)

func (*BaseFrame) Width

func (b *BaseFrame) Width() int

func (*BaseFrame) YCbCr

func (b *BaseFrame) YCbCr() *image.YCbCr

type GraphicOptions

type GraphicOptions struct {
	ReverseColor bool
	Grayscale    bool
}

type IEmulator

type IEmulator interface {
	// Start 启动模拟器
	Start() error
	// Pause 暂停模拟器
	Pause() error
	// Resume 继续运行模拟器
	Resume() error
	// Save 保存游戏
	Save() (IEmulatorSave, error)
	// LoadSave 加载存档,如果需要切换游戏,使用gameFileRepo加载游戏文件
	LoadSave(save IEmulatorSave, gameFileRepo IGameFileRepo) error
	// Restart 重启模拟器
	Restart(options IEmulatorOptions) error
	// Stop 结束模拟器
	Stop() error
	// SubmitInput 提交模拟器按键输入
	SubmitInput(controllerId int, keyCode string, pressed bool)
	// SetGraphicOptions 修改模拟器画面设置
	SetGraphicOptions(*GraphicOptions)

	GetCPUBoostRate() float64
	SetCPUBoostRate(float64) float64
	// OutputResolution 获取模拟器输出分辨率
	OutputResolution() (width, height int)
}

IEmulator 模拟器接口层,用于适配更多种类的模拟器

func MakeEmulator

func MakeEmulator(emulatorType string, options IEmulatorOptions) (IEmulator, error)

type IEmulatorOptions

type IEmulatorOptions interface {
	Game() string
	GameData() []byte
	AudioSampleRate() int
	AudioSampleChan() chan float32
}

IEmulatorOptions 模拟器选项接口

func MakeNesEmulatorOptions

func MakeNesEmulatorOptions(game string, gameData []byte, audioSampleRate int, audioChan chan float32, renderCallback func(frame IFrame)) IEmulatorOptions

type IEmulatorSave

type IEmulatorSave interface {
	GameName() string
	SaveData() []byte
}

type IFrame

type IFrame interface {
	// Width 画面宽度
	Width() int
	// Height 画面高度
	Height() int
	// YCbCr 画面YUV格式数据
	YCbCr() *image.YCbCr
	// Read 读取画面数据, func() 用于释放资源
	Read() (image.Image, func(), error)
}

IFrame 模拟器输出画面接口

func MakeBaseFrame

func MakeBaseFrame(image *image.YCbCr, width, height int) IFrame

func MakeNESFrameAdapter

func MakeNESFrameAdapter(frame *ppu.Frame) IFrame

type IGameFileRepo

type IGameFileRepo interface {
	// GetGameData 获取游戏文件数据
	GetGameData(ctx context.Context, game string) ([]byte, error)
}

type NesEmulatorAdapter

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

func (*NesEmulatorAdapter) GetCPUBoostRate

func (n *NesEmulatorAdapter) GetCPUBoostRate() float64

func (*NesEmulatorAdapter) LoadSave

func (n *NesEmulatorAdapter) LoadSave(save IEmulatorSave, gameFileRepo IGameFileRepo) error

func (*NesEmulatorAdapter) OutputResolution

func (n *NesEmulatorAdapter) OutputResolution() (width, height int)

func (*NesEmulatorAdapter) Pause

func (n *NesEmulatorAdapter) Pause() error

Pause 暂停NES模拟器

func (*NesEmulatorAdapter) Restart

func (n *NesEmulatorAdapter) Restart(options IEmulatorOptions) error

Restart 重启NES模拟器,结束旧模拟器goroutine,创建并运行新模拟器

func (*NesEmulatorAdapter) Resume

func (n *NesEmulatorAdapter) Resume() error

Resume 恢复NES模拟器

func (*NesEmulatorAdapter) Save

func (n *NesEmulatorAdapter) Save() (IEmulatorSave, error)

Save 获取模拟器存档数据

func (*NesEmulatorAdapter) SetCPUBoostRate

func (n *NesEmulatorAdapter) SetCPUBoostRate(rate float64) float64

func (*NesEmulatorAdapter) SetGraphicOptions

func (n *NesEmulatorAdapter) SetGraphicOptions(opts *GraphicOptions)

func (*NesEmulatorAdapter) Start

func (n *NesEmulatorAdapter) Start() error

Start 启动NES模拟器,创建单独的goroutine运行CPU循环,使用context打断

func (*NesEmulatorAdapter) Stop

func (n *NesEmulatorAdapter) Stop() error

Stop 关闭NES模拟器

func (*NesEmulatorAdapter) SubmitInput

func (n *NesEmulatorAdapter) SubmitInput(controllId int, keyCode string, pressed bool)

type NesEmulatorOptions

type NesEmulatorOptions struct {
	NesGame               string
	NesGameData           []byte
	OutputAudioSampleRate int
	OutputAudioSampleChan chan float32
	NesRenderCallback     func(frame *ppu.Frame)
}

func (*NesEmulatorOptions) AudioSampleChan

func (n *NesEmulatorOptions) AudioSampleChan() chan float32

func (*NesEmulatorOptions) AudioSampleRate

func (n *NesEmulatorOptions) AudioSampleRate() int

func (*NesEmulatorOptions) Game

func (n *NesEmulatorOptions) Game() string

func (*NesEmulatorOptions) GameData

func (n *NesEmulatorOptions) GameData() []byte

type NesFrameAdapter

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

func (*NesFrameAdapter) Height

func (f *NesFrameAdapter) Height() int

func (*NesFrameAdapter) Read

func (f *NesFrameAdapter) Read() (image.Image, func(), error)

func (*NesFrameAdapter) Width

func (f *NesFrameAdapter) Width() int

func (*NesFrameAdapter) YCbCr

func (f *NesFrameAdapter) YCbCr() *image.YCbCr

Jump to

Keyboard shortcuts

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