18 [[nodiscard]]
int getDelta()
const {
return delta; }
20 template<
typename Archive>
void serialize(Archive& ar,
unsigned )
22 ar.template serializeBase<StateChange>(*
this);
23 ar.serialize(
"delta", delta);
33 : eventDistributor(eventDistributor_)
34 , stateChangeDistributor(stateChangeDistributor_)
41 Paddle::unplugHelper(EmuTime::dummy());
47std::string_view Paddle::getName()
const
52std::string_view Paddle::getDescription()
const
57void Paddle::plugHelper(Connector& , EmuTime::param )
63void Paddle::unplugHelper(EmuTime::param )
70uint8_t Paddle::read(EmuTime::param time)
76 assert(time >= lastPulse);
77 bool before = (time - lastPulse) < (TICK * analogValue);
78 bool output = before && !(lastInput & 4);
79 return output ? 0x3F : 0x3E;
82void Paddle::write(uint8_t value, EmuTime::param time)
84 uint8_t diff = lastInput ^ value;
86 if ((diff & 4) && !(lastInput & 4)) {
92void Paddle::signalMSXEvent(
const Event& event,
93 EmuTime::param time)
noexcept
96 [&](
const MouseMotionEvent&
e) {
97 constexpr int SCALE = 2;
98 if (
int delta =
e.getX() / SCALE) {
99 stateChangeDistributor.distributeNew<PaddleState>(
103 [](
const EventBase&) { }
108void Paddle::signalStateChange(
const StateChange& event)
110 const auto* ps =
dynamic_cast<const PaddleState*
>(&event);
112 analogValue = narrow_cast<uint8_t>(std::clamp(analogValue + ps->getDelta(), 0, 255));
115void Paddle::stopReplay(EmuTime::param )
noexcept
119template<
typename Archive>
122 ar.serialize(
"lastPulse", lastPulse,
123 "analogValue", analogValue,
124 "lastInput", lastInput);
126 if constexpr (Archive::IS_LOADER) {
static constexpr EmuDuration hz(unsigned x)
void registerEventListener(MSXEventListener &listener)
Registers a given object to receive certain events.
void unregisterEventListener(MSXEventListener &listener)
Unregisters a previously registered event listener.
void serialize(Archive &ar, unsigned)
PaddleState(EmuTime::param time_, int delta_)
Paddle(MSXEventDistributor &eventDistributor, StateChangeDistributor &stateChangeDistributor)
void serialize(Archive &ar, unsigned version)
bool isPluggedIn() const
Returns true if this pluggable is currently plugged into a connector.
Connector * getConnector() const
Get the connector this Pluggable is plugged into.
void registerListener(StateChangeListener &listener)
(Un)registers the given object to receive state change events.
void unregisterListener(StateChangeListener &listener)
Base class for all external MSX state changing events.
This file implemented 3 utility functions:
std::variant< KeyUpEvent, KeyDownEvent, MouseMotionEvent, MouseButtonUpEvent, MouseButtonDownEvent, MouseWheelEvent, JoystickAxisMotionEvent, JoystickHatEvent, JoystickButtonUpEvent, JoystickButtonDownEvent, OsdControlReleaseEvent, OsdControlPressEvent, WindowEvent, TextEvent, FileDropEvent, QuitEvent, FinishFrameEvent, CliCommandEvent, GroupEvent, BootEvent, FrameDrawnEvent, BreakEvent, SwitchRendererEvent, TakeReverseSnapshotEvent, AfterTimedEvent, MachineLoadedEvent, MachineActivatedEvent, MachineDeactivatedEvent, MidiInReaderEvent, MidiInWindowsEvent, MidiInCoreMidiEvent, MidiInCoreMidiVirtualEvent, MidiInALSAEvent, Rs232TesterEvent, Rs232NetEvent, ImGuiDelayedActionEvent, ImGuiActiveEvent > Event
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)