ports

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2020 License: GPL-3.0, GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package ports represents the input/output parts of the VCS (the IO in RIOT).

Implementations of the Peripheral interface can be attached with the AttachPlayer() functions.

Index

Constants

View Source
const (
	PowerOff = "emulated machine has been powered off"
)

Sentinal error returned by Panel.HandleEvent() if power button is pressed.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event string

Event represents the actions that can be performed at one of the VCS ports, either the panel or one of the two player ports.

const (
	NoEvent Event = "NoEvent" // nil

	// joystick.
	Fire  Event = "Fire"  // bool
	Up    Event = "Up"    // bool
	Down  Event = "Down"  // bool
	Left  Event = "Left"  // bool
	Right Event = "Right" // bool

	// paddles.
	PaddleFire Event = "PaddleFire" // bool
	PaddleSet  Event = "PaddleSet"  // float64

	// keyboard.
	KeyboardDown Event = "KeyboardDown" // rune
	KeyboardUp   Event = "KeyboardUp"   // nil

	// panel.
	PanelSelect Event = "PanelSelect" // bool
	PanelReset  Event = "PanelReset"  // bool

	PanelSetColor      Event = "PanelSetColor"      // bool
	PanelSetPlayer0Pro Event = "PanelSetPlayer0Pro" // bool
	PanelSetPlayer1Pro Event = "PanelSetPlayer1Pro" // bool

	PanelToggleColor      Event = "PanelToggleColor"      // nil
	PanelTogglePlayer0Pro Event = "PanelTogglePlayer0Pro" // nil
	PanelTogglePlayer1Pro Event = "PanelTogglePlayer1Pro" // nil

	PanelPowerOff Event = "PanelPowerOff" // nil
)

List of defined events.

type EventData

type EventData interface{}

EventData is the value associated with the event. The underlying type should be restricted to bool, float32, or int. string is also acceptable but for simplicity of playback parsers, the strings "true" or "false" should not be used and numbers should be represented by float32 or int never as a string.

type EventPlayback

type EventPlayback interface {
	// note the type restrictions on EventData in the type definition's
	// commentary
	GetPlayback() (PortID, Event, EventData, error)
}

Playback implementations feed controller Events to the device on request with the CheckInput() function.

Intended for playback of controller events previously recorded to a file on disk but usable for many purposes I suspect. For example, AI control.

type EventRecorder

type EventRecorder interface {
	RecordEvent(PortID, Event, EventData) error
}

EventRecorder implementations mirror an incoming event.

Implementations should be able to handle being attached to more than one peripheral at once. The ID parameter of the EventRecord() function will help to differentiate between multiple devices.

type NewPeripheral

type NewPeripheral func(PortID, PeripheralBus) Peripheral

NewPeripheral defines the function signature for a creating a new peripheral, suitable for use with AttachPloyer0() and AttachPlayer1().

type Panel

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

Panel represents the console's front control panel.

func (*Panel) HandleEvent

func (pan *Panel) HandleEvent(event Event, value EventData) error

HandleEvent implements Peripheral interface.

func (*Panel) Name

func (pan *Panel) Name() string

Name implements the Peripheral interface.

func (*Panel) Plumb

func (pan *Panel) Plumb(bus PeripheralBus)

Plumb implements the Peripheral interface.

func (*Panel) Reset

func (pan *Panel) Reset()

Reset implements the Peripheral interface.

func (*Panel) Step

func (pan *Panel) Step()

Step implements the Peripheral interface.

func (*Panel) String

func (pan *Panel) String() string

String implements the Peripheral interface.

func (*Panel) Update

func (pan *Panel) Update(data bus.ChipData) bool

Update implements the Peripheral interface.

type Peripheral

type Peripheral interface {
	// String should return information about the state of the peripheral
	String() string

	// Plumb a new PeripheralBus into the Peripheral
	Plumb(PeripheralBus)

	// Name should return the canonical name for the peripheral (eg. "Paddle"
	// for the paddle peripheral). It shouldn't include information about which
	// port the peripheral is attached to.
	Name() string

	// handle an incoming input event
	HandleEvent(Event, EventData) error

	// memory has been updated. peripherals are notified.
	Update(bus.ChipData) bool

	// step is called every CPU clock. important for paddle devices
	Step()

	// reset state of peripheral. this has nothing to do with the reset switch
	// on the VCS panel
	Reset()
}

Peripheral represents a (input or output) device that can attached to the VCS ports.

func NewPanel

func NewPanel(bus PeripheralBus) Peripheral

NewPanel is the preferred method of initialisation for the Panel type.

type PeripheralBus

type PeripheralBus interface {
	WriteINPTx(inptx addresses.ChipRegister, data uint8)

	// the SWCHA register is logically divided into two nibbles. player 0
	// uses the upper nibble and player 1 uses the lower nibble. peripherals
	// attached to either player port *must* only use the upper nibble. this
	// write function will transparently shift the data into the lower nibble
	// for peripherals attached to the player 1 port.
	//
	// also note that peripherals do not need to worry about preserving bits
	// in the opposite nibble. the WriteSWCHx implementation will do that
	// transparently according to which port the peripheral is attached
	//
	// Peripherals attached to the panel port can use the entire byte of the
	// SWCHB register
	WriteSWCHx(id PortID, data uint8)
}

PeripheralBus defines the memory operations required by peripherals. We keep this bus definition here rather than the Bus package because it is very specific to this package and sub-packages.

type PortID

type PortID int

PortID differentiates the different ports peripherals can be attached to.

const (
	NoPortID  PortID = -1
	Player0ID PortID = iota
	Player1ID
	PanelID
)

List of defined IDs.

func (*PortID) String

func (id *PortID) String() string

type Ports

type Ports struct {
	Panel   Peripheral
	Player0 Peripheral
	Player1 Peripheral
	// contains filtered or unexported fields
}

Input implements the input/output part of the RIOT (the IO in RIOT).

func NewPorts

func NewPorts(riotMem bus.ChipBus, tiaMem bus.ChipBus) *Ports

NewPorts is the preferred method of initialisation of the Ports type.

func (*Ports) AttachEventRecorder

func (p *Ports) AttachEventRecorder(r EventRecorder)

AttachEventRecorder attaches an EventRecorder implementation to all ports that implement RecordablePort.

func (*Ports) AttachPlayback

func (p *Ports) AttachPlayback(b EventPlayback)

AttachPlayback attaches an EventPlayback implementation to all ports that implement RecordablePort.

func (*Ports) AttachPlayer

func (p *Ports) AttachPlayer(id PortID, c NewPeripheral) error

AttachPlayer attaches a peripheral (represented by a PeripheralConstructor) to a port.

func (*Ports) GetPlayback

func (p *Ports) GetPlayback() error

GetPlayback requests playback events from all attached and eligible peripherals.

func (*Ports) HandleEvent

func (p *Ports) HandleEvent(id PortID, ev Event, d EventData) error

func (*Ports) Plumb

func (p *Ports) Plumb(riotMem bus.ChipBus, tiaMem bus.ChipBus)

Plumb new ChipBusses into the Ports sub-system.

func (*Ports) Reset

func (p *Ports) Reset()

Reset peripherals to an initial state.

func (*Ports) Snapshot

func (p *Ports) Snapshot() *Ports

Snapshot returns a copy of the RIOT Ports sub-system in its current state.

func (*Ports) Step

func (p *Ports) Step()

Step input state forward one cycle.

func (*Ports) String

func (p *Ports) String() string

func (*Ports) Update

func (p *Ports) Update(data bus.ChipData) bool

Update checks to see if ChipData applies to the Input type and updates the internal controller/panel states accordingly. Returns true if ChipData requires more attention.

func (*Ports) WriteINPTx

func (p *Ports) WriteINPTx(inptx addresses.ChipRegister, data uint8)

WriteINPTx implements the MemoryAccess interface.

func (*Ports) WriteSWCHx

func (p *Ports) WriteSWCHx(id PortID, data uint8)

WriteSWCHx implements the MemoryAccess interface.

Directories

Path Synopsis
Package controllers contains the implementations for all the emulated controllers for the VCS.
Package controllers contains the implementations for all the emulated controllers for the VCS.
Package savekey implements the SaveKey external memory card.
Package savekey implements the SaveKey external memory card.

Jump to

Keyboard shortcuts

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