Skip to content

Commit e79be83

Browse files
committed
Fix building for latest libnx, remove Atmosphere-libs dependency
1 parent 670968a commit e79be83

18 files changed

+326
-179
lines changed

.gitmodules

-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
[submodule "source/libstratosphere"]
2-
path = source/libstratosphere
3-
url = https://github.com/Atmosphere-NX/Atmosphere-libs.git

Makefile

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: all build clean mrproper
1+
.PHONY: all build clean
22

33
SOURCE_DIR := source
44
OUT_DIR := out
@@ -21,8 +21,3 @@ build:
2121
clean:
2222
$(MAKE) -C $(SOURCE_DIR) clean
2323
rm -rf $(OUT_DIR)
24-
25-
mrproper:
26-
$(MAKE) -C $(SOURCE_DIR) mrproper
27-
rm -rf $(OUT_DIR)
28-

source/ControllerLib/IUSBInterface.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ class IUSBInterface
2424
virtual Result Open() = 0;
2525
virtual void Close() = 0;
2626

27-
virtual Result ControlTransfer(uint8_t bmRequestType, uint8_t bmRequest, uint16_t wValue, uint16_t wIndex, uint16_t wLength, void *buffer) = 0;
28-
virtual Result ControlTransfer(uint8_t bmRequestType, uint8_t bmRequest, uint16_t wValue, uint16_t wIndex, uint16_t wLength, const void *buffer) = 0;
27+
virtual Result ControlTransfer(uint8_t bmRequestType, uint8_t bmRequest, uint16_t wValue, uint16_t wIndex, uint16_t wLength, void* buffer) = 0;
28+
virtual Result ControlTransfer(uint8_t bmRequestType, uint8_t bmRequest, uint16_t wValue, uint16_t wIndex, uint16_t wLength, const void* buffer) = 0;
2929

30-
virtual IUSBEndpoint *GetEndpoint(IUSBEndpoint::Direction direction, uint8_t index) = 0;
31-
virtual InterfaceDescriptor *GetDescriptor() = 0;
30+
virtual IUSBEndpoint* GetEndpoint(IUSBEndpoint::Direction direction, uint8_t index) = 0;
31+
virtual InterfaceDescriptor* GetDescriptor() = 0;
3232

3333
virtual Result Reset() = 0;
3434
};

source/ControllerSwitch/SwitchAbstractedPadHandler.cpp

+10-9
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
#include "ControllerHelpers.h"
33
#include <cmath>
44
#include <array>
5+
#include "SwitchUtils.h"
56

6-
SwitchAbstractedPadHandler::SwitchAbstractedPadHandler(std::unique_ptr<IController> &&controller)
7+
SwitchAbstractedPadHandler::SwitchAbstractedPadHandler(std::unique_ptr<IController>&& controller)
78
: SwitchVirtualGamepadHandler(std::move(controller))
89
{
910
}
@@ -46,7 +47,7 @@ void SwitchAbstractedPadHandler::Exit()
4647
ExitAbstractedPadState();
4748
}
4849

49-
//Used to give out unique ids to abstracted pads
50+
// Used to give out unique ids to abstracted pads
5051
static std::array<bool, 8> uniqueIDs{};
5152

5253
static s8 getUniqueId()
@@ -76,7 +77,7 @@ Result SwitchAbstractedPadHandler::InitAbstractedPadState()
7677
m_state.npadInterfaceType = HidNpadInterfaceType_USB;
7778
m_state.flags = 0xff;
7879
m_state.state.battery_level = 4;
79-
ControllerConfig *config = GetController()->GetConfig();
80+
ControllerConfig* config = GetController()->GetConfig();
8081
m_state.singleColorBody = config->bodyColor.rgbaValue;
8182
m_state.singleColorButtons = config->buttonsColor.rgbaValue;
8283

@@ -93,7 +94,7 @@ Result SwitchAbstractedPadHandler::ExitAbstractedPadState()
9394
return hiddbgUnsetAutoPilotVirtualPadState(m_abstractedPadID);
9495
}
9596

96-
void SwitchAbstractedPadHandler::FillAbstractedState(const NormalizedButtonData &data)
97+
void SwitchAbstractedPadHandler::FillAbstractedState(const NormalizedButtonData& data)
9798
{
9899
m_state.state.buttons = 0;
99100
m_state.state.buttons |= (data.buttons[0] ? HidNpadButton_X : 0);
@@ -113,7 +114,7 @@ void SwitchAbstractedPadHandler::FillAbstractedState(const NormalizedButtonData
113114
m_state.state.buttons |= (data.buttons[10] ? HidNpadButton_Minus : 0);
114115
m_state.state.buttons |= (data.buttons[11] ? HidNpadButton_Plus : 0);
115116

116-
ControllerConfig *config = GetController()->GetConfig();
117+
ControllerConfig* config = GetController()->GetConfig();
117118

118119
if (config && config->swapDPADandLSTICK)
119120
{
@@ -124,10 +125,10 @@ void SwitchAbstractedPadHandler::FillAbstractedState(const NormalizedButtonData
124125

125126
float daxis_x{}, daxis_y{};
126127

127-
daxis_y += data.buttons[12] ? 1.0f : 0.0f; //DUP
128-
daxis_x += data.buttons[13] ? 1.0f : 0.0f; //DRIGHT
129-
daxis_y += data.buttons[14] ? -1.0f : 0.0f; //DDOWN
130-
daxis_x += data.buttons[15] ? -1.0f : 0.0f; //DLEFT
128+
daxis_y += data.buttons[12] ? 1.0f : 0.0f; // DUP
129+
daxis_x += data.buttons[13] ? 1.0f : 0.0f; // DRIGHT
130+
daxis_y += data.buttons[14] ? -1.0f : 0.0f; // DDOWN
131+
daxis_x += data.buttons[15] ? -1.0f : 0.0f; // DLEFT
131132

132133
ConvertAxisToSwitchAxis(daxis_x, daxis_y, 0, &m_state.state.analog_stick_l.x, &m_state.state.analog_stick_l.y);
133134
}

source/ControllerSwitch/SwitchUtils.h

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#pragma once
2+
#include "switch.h"
3+
4+
namespace SwitchUtils
5+
{
6+
constexpr size_t ThreadStackAlignment = 0x1000;
7+
constexpr size_t MemoryPageSize = 0x1000;
8+
9+
class ScopedLock
10+
{
11+
public:
12+
[[nodiscard]]
13+
explicit ScopedLock(Mutex& In) : mutex(In)
14+
{
15+
mutexLock(&mutex);
16+
}
17+
18+
~ScopedLock()
19+
{
20+
mutexUnlock(&mutex);
21+
}
22+
23+
ScopedLock(const ScopedLock&) = delete;
24+
ScopedLock& operator=(const ScopedLock&) = delete;
25+
26+
private:
27+
Mutex& mutex;
28+
};
29+
30+
#ifndef R_ABORT_UNLESS
31+
#define R_ABORT_UNLESS(rc) \
32+
{ \
33+
if (R_FAILED(rc)) [[unlikely]] \
34+
{ \
35+
diagAbortWithResult(rc); \
36+
} \
37+
}
38+
#endif
39+
40+
#ifndef R_TRY
41+
#define R_TRY(rc) \
42+
{ \
43+
if (R_FAILED(rc)) \
44+
{ \
45+
return rc; \
46+
} \
47+
}
48+
#endif
49+
50+
} // namespace SwitchUtils

source/ControllerSwitch/SwitchVirtualGamepadHandler.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "SwitchVirtualGamepadHandler.h"
22

3-
SwitchVirtualGamepadHandler::SwitchVirtualGamepadHandler(std::unique_ptr<IController> &&controller)
3+
SwitchVirtualGamepadHandler::SwitchVirtualGamepadHandler(std::unique_ptr<IController>&& controller)
44
: m_controller(std::move(controller))
55
{
66
}
@@ -19,20 +19,20 @@ void SwitchVirtualGamepadHandler::Exit()
1919
m_controller->Exit();
2020
}
2121

22-
void SwitchVirtualGamepadHandler::InputThreadLoop(void *handler)
22+
void SwitchVirtualGamepadHandler::InputThreadLoop(void* handler)
2323
{
2424
do
2525
{
26-
static_cast<SwitchVirtualGamepadHandler *>(handler)->UpdateInput();
27-
} while (static_cast<SwitchVirtualGamepadHandler *>(handler)->m_inputThreadIsRunning);
26+
static_cast<SwitchVirtualGamepadHandler*>(handler)->UpdateInput();
27+
} while (static_cast<SwitchVirtualGamepadHandler*>(handler)->m_inputThreadIsRunning);
2828
}
2929

30-
void SwitchVirtualGamepadHandler::OutputThreadLoop(void *handler)
30+
void SwitchVirtualGamepadHandler::OutputThreadLoop(void* handler)
3131
{
3232
do
3333
{
34-
static_cast<SwitchVirtualGamepadHandler *>(handler)->UpdateOutput();
35-
} while (static_cast<SwitchVirtualGamepadHandler *>(handler)->m_outputThreadIsRunning);
34+
static_cast<SwitchVirtualGamepadHandler*>(handler)->UpdateOutput();
35+
} while (static_cast<SwitchVirtualGamepadHandler*>(handler)->m_outputThreadIsRunning);
3636
}
3737

3838
Result SwitchVirtualGamepadHandler::InitInputThread()
@@ -70,17 +70,17 @@ void SwitchVirtualGamepadHandler::ExitOutputThread()
7070
static_assert(JOYSTICK_MAX == 32767 && JOYSTICK_MIN == -32767,
7171
"JOYSTICK_MAX and/or JOYSTICK_MIN has incorrect values. Update libnx");
7272

73-
void SwitchVirtualGamepadHandler::ConvertAxisToSwitchAxis(float x, float y, float deadzone, s32 *x_out, s32 *y_out)
73+
void SwitchVirtualGamepadHandler::ConvertAxisToSwitchAxis(float x, float y, float deadzone, s32* x_out, s32* y_out)
7474
{
7575
float floatRange = 2.0f;
76-
//JOYSTICK_MAX is 1 above and JOYSTICK_MIN is 1 below acceptable joystick values, causing crashes on various games including Xenoblade Chronicles 2 and Resident Evil 4
76+
// JOYSTICK_MAX is 1 above and JOYSTICK_MIN is 1 below acceptable joystick values, causing crashes on various games including Xenoblade Chronicles 2 and Resident Evil 4
7777
float newRange = (JOYSTICK_MAX - JOYSTICK_MIN);
7878

7979
*x_out = (((x + 1.0f) * newRange) / floatRange) + JOYSTICK_MIN;
8080
*y_out = (((y + 1.0f) * newRange) / floatRange) + JOYSTICK_MIN;
8181
/*
82-
OldRange = (OldMax - OldMin)
83-
NewRange = (NewMax - NewMin)
82+
OldRange = (OldMax - OldMin)
83+
NewRange = (NewMax - NewMin)
8484
NewValue = (((OldValue - OldMin) * NewRange) / OldRange) + NewMin
8585
*/
8686
}
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,56 @@
11
#pragma once
22
#include "switch.h"
33
#include "IController.h"
4-
#include <stratosphere.hpp>
4+
#include "SwitchUtils.h"
55

6-
//This class is a base class for SwitchHDLHandler and SwitchAbstractedPaadHandler.
6+
// This class is a base class for SwitchHDLHandler and SwitchAbstractedPaadHandler.
77
class SwitchVirtualGamepadHandler
88
{
99
protected:
1010
HidVibrationDeviceHandle m_vibrationDeviceHandle;
1111
std::unique_ptr<IController> m_controller;
1212

13-
alignas(ams::os::ThreadStackAlignment) u8 input_thread_stack[0x1000];
14-
alignas(ams::os::ThreadStackAlignment) u8 output_thread_stack[0x1000];
13+
alignas(SwitchUtils::ThreadStackAlignment) u8 input_thread_stack[0x1000];
14+
alignas(SwitchUtils::ThreadStackAlignment) u8 output_thread_stack[0x1000];
1515

1616
Thread m_inputThread;
1717
Thread m_outputThread;
1818

1919
bool m_inputThreadIsRunning = false;
2020
bool m_outputThreadIsRunning = false;
2121

22-
static void InputThreadLoop(void *argument);
23-
static void OutputThreadLoop(void *argument);
22+
static void InputThreadLoop(void* argument);
23+
static void OutputThreadLoop(void* argument);
2424

2525
public:
26-
SwitchVirtualGamepadHandler(std::unique_ptr<IController> &&controller);
26+
SwitchVirtualGamepadHandler(std::unique_ptr<IController>&& controller);
2727
virtual ~SwitchVirtualGamepadHandler();
2828

29-
//Override this if you want a custom init procedure
29+
// Override this if you want a custom init procedure
3030
virtual Result Initialize();
31-
//Override this if you want a custom exit procedure
31+
// Override this if you want a custom exit procedure
3232
virtual void Exit();
3333

34-
//Separately init the input-reading thread
34+
// Separately init the input-reading thread
3535
Result InitInputThread();
36-
//Separately close the input-reading thread
36+
// Separately close the input-reading thread
3737
void ExitInputThread();
3838

39-
//Separately init the rumble sending thread
39+
// Separately init the rumble sending thread
4040
Result InitOutputThread();
41-
//Separately close the rumble sending thread
41+
// Separately close the rumble sending thread
4242
void ExitOutputThread();
4343

44-
//The function to call indefinitely by the input thread
44+
// The function to call indefinitely by the input thread
4545
virtual void UpdateInput() = 0;
46-
//The function to call indefinitely by the output thread
46+
// The function to call indefinitely by the output thread
4747
virtual void UpdateOutput() = 0;
4848

49-
void ConvertAxisToSwitchAxis(float x, float y, float deadzone, s32 *x_out, s32 *y_out);
49+
void ConvertAxisToSwitchAxis(float x, float y, float deadzone, s32* x_out, s32* y_out);
5050

5151
Result SetControllerVibration(float strong_mag, float weak_mag);
5252

53-
//Get the raw controller pointer
54-
inline IController *GetController() { return m_controller.get(); }
55-
inline HidVibrationDeviceHandle *GetVibrationHandle() { return &m_vibrationDeviceHandle; }
53+
// Get the raw controller pointer
54+
inline IController* GetController() { return m_controller.get(); }
55+
inline HidVibrationDeviceHandle* GetVibrationHandle() { return &m_vibrationDeviceHandle; }
5656
};

source/Makefile

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
1-
COMPONENTS := libstratosphere AppletCompanion Sysmodule
2-
TOPTARGETS := all clean mrproper
1+
COMPONENTS := AppletCompanion Sysmodule
2+
TOPTARGETS := all clean
33

44
.PHONY: $(TOPTARGETS) $(COMPONENTS)
55

66
all: $(COMPONENTS)
77

8-
libstratosphere:
9-
$(MAKE) -C $@
10-
118
AppletCompanion:
129
$(MAKE) -C $@
1310

14-
Sysmodule: libstratosphere
11+
Sysmodule:
1512
$(MAKE) -C $@
1613

1714
clean:
1815
$(MAKE) -C AppletCompanion clean
19-
$(MAKE) -C Sysmodule clean
20-
21-
mrproper: clean
22-
$(MAKE) -C libstratosphere clean
16+
$(MAKE) -C Sysmodule clean

0 commit comments

Comments
 (0)