common

package
v0.0.0-...-f6f1029 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2024 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const SaveStateVersion = 1

Variables

View Source
var JoystickAlreadyAdded = errors.New("Joystick has already been added")
View Source
var MaxCyclesReached error = errors.New("maximum cycles reached")

Functions

func FileExists

func FileExists(path string) bool

func FindFile

func FindFile(path string) string

func GetOrCreateConfigDir

func GetOrCreateConfigDir() (string, error)

make the directory where the config file lives, which is ~/.config/jon-nes on linux

func GetSha256

func GetSha256(path string) (string, error)

return the sha256 hash of a file given by the path

func RenderPixelsRGBA

func RenderPixelsRGBA(screen nes.VirtualScreen, raw_pixels []byte, overscanPixels int)

func RunDummyNES

func RunDummyNES(quit context.Context, actions <-chan EmulatorAction)

func RunNES

func RunNES(romPath string, cpu *nes.CPUState, maxCycles uint64, quit context.Context, toDraw chan<- nes.VirtualScreen,
	bufferReady <-chan nes.VirtualScreen, audio chan<- []float32,
	emulatorActions <-chan EmulatorAction, screenListeners *ScreenListeners,
	renderOverlayUpdate chan<- string,
	sampleRate float32, verbose int, debugger debug.Debugger) error

func SaveConfigData

func SaveConfigData(data ConfigData) error

create the config.json file in the config dir and return the opened file, or an error

func SaveEmulatorKeys

func SaveEmulatorKeys(keys EmulatorKeys)

func SetupCPU

func SetupCPU(nesFile nes.NESFile, debugCpu bool, debugPpu bool) (nes.CPUState, error)

Types

type AudioResponse

type AudioResponse int
const (
	AudioResponseEnabled AudioResponse = iota
	AudioResponseDisabled
)

type CombineButtons

type CombineButtons struct {
	Buttons []nes.HostInput
}

func MakeCombineButtons

func MakeCombineButtons(input1 nes.HostInput, input2 nes.HostInput) CombineButtons

func (*CombineButtons) Get

func (combine *CombineButtons) Get() nes.ButtonMapping

type ConfigData

type ConfigData struct {
	Version         int                `json:"version,omitempty"`
	Player1Joystick ConfigJoystickData `json:"player1-joystick,omitempty"`
	Player1Keys     ConfigKeys         `json:"player1-keys,omitempty"`
}

func DefaultConfigData

func DefaultConfigData() ConfigData

func LoadConfigData

func LoadConfigData() (ConfigData, error)

type ConfigJoystickData

type ConfigJoystickData struct {
	A      string `json:"a,omitempty"`
	B      string `json:"b,omitempty"`
	Select string `json:"select,omitempty"`
	Start  string `json:"start,omitempty"`
	Up     string `json:"up,omitempty"`
	Down   string `json:"down,omitempty"`
	Left   string `json:"left,omitempty"`
	Right  string `json:"right,omitempty"`
	Guid   string `json:"guid,omitempty"`
	Name   string `json:"name,omitempty"`
}

type ConfigKeys

type ConfigKeys struct {
	Turbo     string
	Pause     string
	HardReset string
	PPUDebug  string
	SlowDown  string
	SpeedUp   string
	Normal    string
	StepFrame string
	Record    string
	SaveState string
	LoadState string
	Console   string

	ButtonA      string
	ButtonB      string
	ButtonTurboA string
	ButtonTurboB string
	ButtonSelect string
	ButtonStart  string
	ButtonUp     string
	ButtonDown   string
	ButtonLeft   string
	ButtonRight  string
}

type DefaultEmulatorAction

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

func (DefaultEmulatorAction) Value

type EmulatorAction

type EmulatorAction interface {
	Value() EmulatorActionValue
}

func MakeEmulatorAction

func MakeEmulatorAction(value EmulatorActionValue) EmulatorAction

type EmulatorActionGetDebugger

type EmulatorActionGetDebugger struct {
	Response chan<- debug.Debugger
}

func (EmulatorActionGetDebugger) Value

type EmulatorActionGetInfo

type EmulatorActionGetInfo struct {
	Response chan<- EmulatorInfo
}

func (EmulatorActionGetInfo) Value

type EmulatorActionValue

type EmulatorActionValue int
const (
	EmulatorNothing EmulatorActionValue = iota // just a default value that has no behavior
	EmulatorNormal
	EmulatorTurbo
	EmulatorInfinite
	EmulatorSlowDown
	EmulatorSpeedUp
	EmulatorTogglePause
	EmulatorTogglePPUDebug
	EmulatorStepFrame
	EmulatorSetPause
	EmulatorUnpause
	EmulatorSaveState
	EmulatorLoadState
	EmulatorGetInfo
	EmulatorGetDebugger
)

type EmulatorInfo

type EmulatorInfo struct {
	Cycles uint64 // current cycle of emulator
	Pc     uint16 // current pc register value
}

type EmulatorKey

type EmulatorKey struct {
	Name string
	Code sdl.Keycode
}

type EmulatorKeys

type EmulatorKeys struct {
	Turbo     sdl.Keycode
	Pause     sdl.Keycode
	HardReset sdl.Keycode
	PPUDebug  sdl.Keycode
	SlowDown  sdl.Keycode
	SpeedUp   sdl.Keycode
	Normal    sdl.Keycode
	StepFrame sdl.Keycode
	Record    sdl.Keycode
	SaveState sdl.Keycode
	LoadState sdl.Keycode
	Console   sdl.Keycode

	ButtonA      sdl.Keycode
	ButtonB      sdl.Keycode
	ButtonTurboA sdl.Keycode
	ButtonTurboB sdl.Keycode
	ButtonSelect sdl.Keycode
	ButtonStart  sdl.Keycode
	ButtonUp     sdl.Keycode
	ButtonDown   sdl.Keycode
	ButtonLeft   sdl.Keycode
	ButtonRight  sdl.Keycode
}

func DefaultEmulatorKeys

func DefaultEmulatorKeys() EmulatorKeys

func LoadEmulatorKeys

func LoadEmulatorKeys() EmulatorKeys

func (EmulatorKeys) AllKeys

func (keys EmulatorKeys) AllKeys() []EmulatorKey

func (*EmulatorKeys) Update

func (keys *EmulatorKeys) Update(key string, value sdl.Keycode)

func (*EmulatorKeys) UpdateAll

func (keys *EmulatorKeys) UpdateAll(other EmulatorKeys)

type IControlPad

type IControlPad SDLJoystickButtons

func MakeIControlPadInput

func MakeIControlPadInput(index int) (IControlPad, error)

func (*IControlPad) Close

func (icontrolpad *IControlPad) Close()

func (*IControlPad) Get

func (icontrolpad *IControlPad) Get() nes.ButtonMapping

type JoystickAxis

type JoystickAxis struct {
	Axis  int
	Value int
}

func (*JoystickAxis) Serialize

func (axis *JoystickAxis) Serialize() string

type JoystickButton

type JoystickButton struct {
	Button int
}

func (*JoystickButton) Serialize

func (button *JoystickButton) Serialize() string

type JoystickInput

type JoystickInput interface {
	/* FIXME: return a mapping suitable for json */
	Serialize() string
}

type JoystickManager

type JoystickManager struct {
	Joysticks []*SDLJoystickButtons
	Player1   *SDLJoystickButtons
	Player2   *SDLJoystickButtons
	Lock      sync.Mutex
}

func NewJoystickManager

func NewJoystickManager() *JoystickManager

func (*JoystickManager) AddJoystick

func (manager *JoystickManager) AddJoystick(index int) error

func (*JoystickManager) Close

func (manager *JoystickManager) Close()

func (*JoystickManager) CurrentName

func (manager *JoystickManager) CurrentName() string

func (*JoystickManager) Get

func (manager *JoystickManager) Get() nes.ButtonMapping

func (*JoystickManager) HandleEvent

func (manager *JoystickManager) HandleEvent(event sdl.Event) EmulatorAction

func (*JoystickManager) RemoveJoystick

func (manager *JoystickManager) RemoveJoystick(id sdl.JoystickID)

func (*JoystickManager) SaveInput

func (manager *JoystickManager) SaveInput() error

type ProgramActions

type ProgramActions interface {
}

type ProgramLoadRom

type ProgramLoadRom struct {
	Path string
}

type ProgramPauseEmulator

type ProgramPauseEmulator struct {
}

type ProgramQueryAudioState

type ProgramQueryAudioState struct {
	Response chan bool
}

type ProgramQuit

type ProgramQuit struct {
}

type ProgramToggleSound

type ProgramToggleSound struct {
}

type ProgramUnpauseEmulator

type ProgramUnpauseEmulator struct {
}

type SDLJoystickButtons

type SDLJoystickButtons struct {
	Inputs      map[nes.Button]JoystickInput          // normal nes buttons
	ExtraInputs map[EmulatorActionValue]JoystickInput // extra emulator-only buttons
	Pressed     nes.ButtonMapping
	Lock        sync.Mutex
	Name        string
	// contains filtered or unexported fields
}

func OpenJoystick

func OpenJoystick(index int) (SDLJoystickButtons, error)

func (*SDLJoystickButtons) Close

func (joystick *SDLJoystickButtons) Close()

func (*SDLJoystickButtons) Get

func (joystick *SDLJoystickButtons) Get() nes.ButtonMapping

func (*SDLJoystickButtons) HandleEvent

func (joystick *SDLJoystickButtons) HandleEvent(event sdl.Event) EmulatorAction

func (*SDLJoystickButtons) SetButton

func (joystick *SDLJoystickButtons) SetButton(button nes.Button, input JoystickInput)

func (*SDLJoystickButtons) SetExtraButton

func (joystick *SDLJoystickButtons) SetExtraButton(button EmulatorActionValue, input JoystickInput)

type SDLKeyboardButtons

type SDLKeyboardButtons struct {
	Keys *EmulatorKeys

	/* true if held down, false if not */
	ButtonA       bool
	ButtonB       bool
	ButtonTurboA  bool
	ButtonTurboB  bool
	TurboACounter int
	TurboBCounter int
	ButtonSelect  bool
	ButtonStart   bool
	ButtonUp      bool
	ButtonDown    bool
	ButtonLeft    bool
	ButtonRight   bool
}

func (*SDLKeyboardButtons) Get

func (buttons *SDLKeyboardButtons) Get() nes.ButtonMapping

func (*SDLKeyboardButtons) HandleEvent

func (buttons *SDLKeyboardButtons) HandleEvent(event *sdl.KeyboardEvent)

func (*SDLKeyboardButtons) Reset

func (buttons *SDLKeyboardButtons) Reset()

type SaveState

type SaveState struct {
	State   *nes.CPUState `json:"state"`
	Version int           `json:"version"`
	Date    time.Time     `json:"time"`
}

type ScreenListeners

type ScreenListeners struct {
	VideoListeners []chan nes.VirtualScreen
	AudioListeners []chan []float32
	Lock           sync.Mutex
}

func (*ScreenListeners) AddAudioListener

func (listeners *ScreenListeners) AddAudioListener(listener chan []float32)

func (*ScreenListeners) AddVideoListener

func (listeners *ScreenListeners) AddVideoListener(listener chan nes.VirtualScreen)

func (*ScreenListeners) ObserveAudio

func (listeners *ScreenListeners) ObserveAudio(pcm []float32)

func (*ScreenListeners) ObserveVideo

func (listeners *ScreenListeners) ObserveVideo(screen nes.VirtualScreen)

func (*ScreenListeners) RemoveAudioListener

func (listeners *ScreenListeners) RemoveAudioListener(remove chan []float32)

func (*ScreenListeners) RemoveVideoListener

func (listeners *ScreenListeners) RemoveVideoListener(remove chan nes.VirtualScreen)

type WindowSize

type WindowSize struct {
	X int
	Y int
}

Jump to

Keyboard shortcuts

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