aboutsummaryrefslogtreecommitdiff
path: root/src/core/hle/service/ir/ir_rst.h
blob: 2514ab6f9af3b1f96061340b602697272f2dbe54 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright 2014 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included..

#pragma once

#include <atomic>
#include <memory>
#include "common/bit_field.h"
#include "common/common_types.h"
#include "common/swap.h"
#include "core/frontend/input.h"
#include "core/hle/service/service.h"

namespace Kernel {
class Event;
class SharedMemory;
} // namespace Kernel

namespace Core {
struct TimingEventType;
};

namespace Service::IR {

union PadState {
    u32_le hex{};

    BitField<14, 1, u32> zl;
    BitField<15, 1, u32> zr;

    BitField<24, 1, u32> c_stick_right;
    BitField<25, 1, u32> c_stick_left;
    BitField<26, 1, u32> c_stick_up;
    BitField<27, 1, u32> c_stick_down;
};

/// Interface to "ir:rst" service
class IR_RST final : public ServiceFramework<IR_RST> {
public:
    explicit IR_RST(Core::System& system);
    ~IR_RST();
    void ReloadInputDevices();

private:
    /**
     * GetHandles service function
     *  No input
     *  Outputs:
     *      1 : Result of function, 0 on success, otherwise error code
     *      2 : Handle translation descriptor
     *      3 : Shared memory handle
     *      4 : Event handle
     */
    void GetHandles(Kernel::HLERequestContext& ctx);

    /**
     * Initialize service function
     *  Inputs:
     *      1 : pad state update period in ms
     *      2 : bool output raw c-stick data
     *  Outputs:
     *      1 : Result of function, 0 on success, otherwise error code
     */
    void Initialize(Kernel::HLERequestContext& ctx);

    /**
     * Shutdown service function
     *  No input
     *  Outputs:
     *      1 : Result of function, 0 on success, otherwise error code
     */
    void Shutdown(Kernel::HLERequestContext& ctx);

    void LoadInputDevices();
    void UnloadInputDevices();
    void UpdateCallback(std::uintptr_t user_data, s64 cycles_late);

    Core::System& system;
    std::shared_ptr<Kernel::Event> update_event;
    std::shared_ptr<Kernel::SharedMemory> shared_memory;
    u32 next_pad_index{0};
    Core::TimingEventType* update_callback_id;
    std::unique_ptr<Input::ButtonDevice> zl_button;
    std::unique_ptr<Input::ButtonDevice> zr_button;
    std::unique_ptr<Input::AnalogDevice> c_stick;
    std::atomic<bool> is_device_reload_pending{false};
    bool raw_c_stick{false};
    int update_period{0};

    template <class Archive>
    void serialize(Archive& ar, const unsigned int);
    friend class boost::serialization::access;
};

} // namespace Service::IR

BOOST_CLASS_EXPORT_KEY(Service::IR::IR_RST)
SERVICE_CONSTRUCT(Service::IR::IR_RST)