32 uint8_t x_, uint8_t y_,
bool touch_,
bool button_)
34 , x(x_), y(y_), touch(touch_), button(button_) {}
35 [[nodiscard]] uint8_t
getX()
const {
return x; }
36 [[nodiscard]] uint8_t
getY()
const {
return y; }
37 [[nodiscard]]
bool getTouch()
const {
return touch; }
38 [[nodiscard]]
bool getButton()
const {
return button; }
40 template<
typename Archive>
void serialize(Archive& ar,
unsigned )
42 ar.template serializeBase<StateChange>(*
this);
59 : eventDistributor(eventDistributor_)
60 , stateChangeDistributor(stateChangeDistributor_)
62 , transformSetting(commandController,
63 "touchpad_transform_matrix",
64 "2x3 matrix to transform host mouse coordinates to "
65 "MSX touchpad coordinates, see manual for details",
66 "{ 256 0 0 } { 0 256 0 }")
71 parseTransformMatrix(interp, newValue);
74 "Invalid transformation matrix: ", e.getMessage());
78 parseTransformMatrix(interp, transformSetting.
getValue());
81 std::cerr << e.getMessage() <<
'\n';
83 m[0][0] = 256.0f; m[1][0] = 0.0f; m[2][0] = 0.0f;
84 m[0][1] = 0.0f; m[1][1] = 256.0f; m[2][1] = 0.0f;
91 Touchpad::unplugHelper(EmuTime::dummy());
100 for (
auto i :
xrange(2)) {
102 if (row.getListLength(interp) != 3) {
103 throw CommandException(
"each row must have 3 elements");
105 for (
auto j :
xrange(3)) {
106 m[j][i] = row.getListIndex(interp, j).getFloat(interp);
112std::string_view Touchpad::getName()
const
117std::string_view Touchpad::getDescription()
const
119 return "MSX Touchpad";
122void Touchpad::plugHelper(Connector& , EmuTime::param )
128void Touchpad::unplugHelper(EmuTime::param )
143uint8_t Touchpad::read(EmuTime::param time)
145 uint8_t result = SENSE | BUTTON;
146 if (touch) result &= ~SENSE;
147 if (button) result &= ~BUTTON;
153 if ((time - start) > delta) {
157 if (shift & 0x80) result |= SO;
158 if (last & CS) result |= SO;
160 return result | 0x30;
163void Touchpad::write(uint8_t value, EmuTime::param time)
165 uint8_t diff = last ^ value;
177 shift = (channel == 0) ? (touch ? x : 0)
178 : (channel == 3) ? (touch ? y : 148)
182 if (((value & (CS | SCK)) == SCK) && (diff & SCK)) {
185 shift |= (value & SI) != 0;
195 return clamp(xy, 0, 255);
199void Touchpad::signalMSXEvent(
const Event& event,
200 EmuTime::param time)
noexcept
203 auto b = hostButtons;
206 [&](
const MouseMotionEvent&
e) {
207 pos = transformCoords(
ivec2(
e.getAbsX(),
e.getAbsY()));
209 [&](
const MouseButtonDownEvent&
e) {
210 switch (
e.getButton()) {
211 case SDL_BUTTON_LEFT:
214 case SDL_BUTTON_RIGHT:
222 [&](
const MouseButtonUpEvent&
e) {
223 switch (
e.getButton()) {
224 case SDL_BUTTON_LEFT:
227 case SDL_BUTTON_RIGHT:
235 [](
const EventBase&) { }
238 if ((pos != hostPos) || (b != hostButtons)) {
241 createTouchpadStateChange(
243 narrow_cast<uint8_t>(pos.x),
244 narrow_cast<uint8_t>(pos.y),
245 (hostButtons & 1) != 0,
246 (hostButtons & 2) != 0);
250void Touchpad::createTouchpadStateChange(
251 EmuTime::param time, uint8_t x_, uint8_t y_,
bool touch_,
bool button_)
254 time, x_, y_, touch_, button_);
258void Touchpad::signalStateChange(
const StateChange& event)
260 if (
const auto* ts =
dynamic_cast<const TouchpadState*
>(&event)) {
263 touch = ts->getTouch();
264 button = ts->getButton();
268void Touchpad::stopReplay(EmuTime::param time)
noexcept
271 if (x || y || touch || button) {
272 stateChangeDistributor.distributeNew<TouchpadState>(
273 time, uint8_t(0), uint8_t(0),
false,
false);
278template<
typename Archive>
283 ar.serialize(
"start", start,
292 if constexpr (Archive::IS_LOADER) {
static constexpr EmuDuration duration(unsigned ticks)
Calculates the duration of the given number of ticks at this clock's frequency.
virtual Interpreter & getInterpreter()=0
Represents the output window/screen of openMSX.
OutputSurface * getOutputSurface()
static constexpr uint8_t WR_PIN8
static constexpr uint8_t RD_PIN1
static constexpr uint8_t WR_PIN6
static constexpr uint8_t RD_PIN3
static constexpr uint8_t RD_PIN4
static constexpr uint8_t WR_PIN7
static constexpr uint8_t RD_PIN2
void registerEventListener(MSXEventListener &listener)
Registers a given object to receive certain events.
void unregisterEventListener(MSXEventListener &listener)
Unregisters a previously registered event listener.
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 setChecker(std::function< void(TclObject &)> checkFunc_)
Set value-check-callback.
const TclObject & getValue() const final
Gets the current value of this setting as a TclObject.
void registerListener(StateChangeListener &listener)
(Un)registers the given object to receive state change events.
void distributeNew(EmuTime::param time, Args &&...args)
Deliver the event to all registered listeners MSX input devices should call the distributeNew() versi...
void unregisterListener(StateChangeListener &listener)
Base class for all external MSX state changing events.
unsigned getListLength(Interpreter &interp) const
TclObject getListIndex(Interpreter &interp, unsigned index) const
void serialize(Archive &ar, unsigned)
TouchpadState(EmuTime::param time_, uint8_t x_, uint8_t y_, bool touch_, bool button_)
void serialize(Archive &ar, unsigned version)
Touchpad(MSXEventDistributor &eventDistributor, StateChangeDistributor &stateChangeDistributor, Display &display, CommandController &commandController)
constexpr vecN< N, T > clamp(const vecN< N, T > &x, const vecN< N, T > &minVal, const vecN< N, T > &maxVal)
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)
constexpr auto xrange(T e)