Skip to content

Commit

Permalink
Work on public API
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkwhoffmann committed Jul 10, 2024
1 parent a236b5e commit f43bcc3
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 24 deletions.
11 changes: 11 additions & 0 deletions Emulator/Peripherals/Joystick/Joystick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ Joystick::Joystick(Amiga& ref, ControlPort& pref) : SubComponent(ref, pref.objid

};

void
Joystick::cacheInfo(JoystickInfo &result) const
{
{ SYNCHRONIZED

result.button = button;
result.axisX = axisX;
result.axisY = axisY;
}
}

i64
Joystick::getOption(Option option) const
{
Expand Down
42 changes: 31 additions & 11 deletions Emulator/Peripherals/Joystick/Joystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace vamiga {

class Joystick : public SubComponent {
class Joystick : public SubComponent, public Inspectable<JoystickInfo> {

Descriptions descriptions = {
{
Expand Down Expand Up @@ -70,18 +70,20 @@ class Joystick : public SubComponent {

Joystick(Amiga& ref, ControlPort& pref);

Joystick& operator= (const Joystick& other) {

CLONE(button)
CLONE(axisX)
CLONE(axisY)

CLONE(config)

return *this;
}


//
// Methods from CoreObject
//

private:

void _dump(Category category, std::ostream& os) const override;


//
// Methods from CoreComponent
// Methods from Serializable
//

private:
Expand All @@ -104,10 +106,28 @@ class Joystick : public SubComponent {

void _didLoad() override;


//
// Methods from CoreComponent
//

public:

const Descriptions &getDescriptions() const override { return descriptions; }

private:

void _dump(Category category, std::ostream& os) const override;


//
// Methods from Inspectable
//

private:

void cacheInfo(JoystickInfo &result) const override;


//
// Methods from Configurable
Expand Down
8 changes: 8 additions & 0 deletions Emulator/Peripherals/Joystick/JoystickTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,11 @@ typedef struct
isize autofireDelay;
}
JoystickConfig;

typedef struct
{
bool button;
int axisX;
int axisY;
}
JoystickInfo;
52 changes: 52 additions & 0 deletions Emulator/VAmiga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,58 @@ HardDriveAPI::setFlag(DiskFlags mask, bool value)
}


//
// Peripherals (Joystick)
//

const JoystickInfo &
JoystickAPI::getInfo() const
{
return joystick->getInfo();
}

const JoystickInfo &
JoystickAPI::getCachedInfo() const
{
return joystick->getCachedInfo();
}


//
// Mouse
//

bool
MouseAPI::detectShakeXY(double x, double y)
{
return mouse->detectShakeXY(x, y);
}

bool
MouseAPI::detectShakeDxDy(double dx, double dy)
{
return mouse->detectShakeDxDy(dx, dy);
}

void
MouseAPI::setXY(double x, double y)
{
emu->put(Cmd(CMD_MOUSE_MOVE_ABS, CoordCmd { .port = mouse->objid, .x = x, .y = y }));
}

void
MouseAPI::setDxDy(double dx, double dy)
{
emu->put(Cmd(CMD_MOUSE_MOVE_REL, CoordCmd { .port = mouse->objid, .x = dx, .y = dy }));
}

void
MouseAPI::trigger(GamePadAction action)
{
emu->put(Cmd(CMD_MOUSE_EVENT, GamePadCmd { .port = mouse->objid, .action = action }));
}


//
// Miscellaneous (Debugger)
//
Expand Down
Loading

0 comments on commit f43bcc3

Please sign in to comment.