Class Component

Inheritance Relationships

Derived Types

Class Documentation

class Component

The Component is an abstraction mechanism for interfacing with generic emulated Component. The class is used to provide an unified interface for node editors and similar tools.

The Components interface with each other using Ports and Connectors; no other means shall be used, to make the Component as universal as possible.

See documentation for creating a custom component.

Subclassed by APU, Bus, Gamepak, MOS6502, Memory, NESPeripherals, R2C02, Trigger

Public Functions

Component() = default
virtual ~Component() = default
virtual void init() = 0

Initialize a component to a default power-on state (hard reset).

Note

For Component developer: Implement a correct power-on state here.

virtual uintptr_t getDeviceID() const final

Get a emulator-wide unique component identifier. By default a casted pointer to the component instance.

Returns

Component’s unique ID.

virtual std::string getDeviceName() const final

Get a component’s name.

Returns

Component’s name.

virtual void setDeviceName(const std::string &newName) final

Set component’s name.

Parameters

newName – A new name to set.

virtual void connect(const std::string &toPort, std::weak_ptr<Connector> connector) final

Connect a connector to a specified port.

Parameters
  • toPortPort to connect the connector to.

  • connector – The connector to connect.

virtual void disconnect(const std::string &fromPort) final

Disconnect a connector from a specified port.

Parameters

fromPort – A name of a port from which the connector should be disconnected.

virtual std::weak_ptr<Connector> getConnector(const std::string &name) final

Get a connector IO.

Parameters

name – Name of the connector to receive.

Returns

Selected connector.

virtual std::vector<std::string> listConnectors() const final

Return names of all connectors in the component.

virtual std::vector<std::string> listPorts() const final

Return names of all port in the component.

virtual std::vector<EmulatorWindow> getGUIs() = 0

Get GUI windows: metadata and rendering functions.

Note

For Component developer: If the component have a debugger or other GUI, return an arbitrary count of windows, they will be rendered on a load of a system which contains the component.

Returns

A vector of windows to be rendered.

virtual SoundSampleSources getSoundSampleSources()

Get audio sources: a list of functions to request a stereo audio sample (frame).

Note

For Component developer: If the component has any sound outputs, return a functions to get samples from them here. You can return any number of outputs, they will be mixed seamlessly.

virtual std::vector<ImInputBinder::action_t> getInputs()

Get input key/gamepad mapping requests with corresponding actions.

Note

For Component developer: If the component wants to interact with keyboard, gamepad or similar, return a vector of required keys and actions when they are pressed or released. Default keybindings can be changed by the user and saved to their config.

virtual bool initRequested()

Returns true if the component wants a whole system restarted.

Note

For Component developer: It can be used for example if the component represents a program ROM and a new ROM was loaded; therefore CPU needs to be restarted to change the program counter to correct location in the new ROM.

Returns

true Restart is requested.

Returns

false No restart needed.

Protected Attributes

std::string m_deviceName = "Default Component"

Components’ name.

std::map<std::string, std::shared_ptr<Connector>> m_connectors

Exposed connectors by name.

std::map<std::string, Port*> m_ports

Available ports by name.

bool m_initRequested = false

Request init of the whole system. Used mainly by ROM on load to properly load reset vectors.