Skip to content

Commit 495f0cd

Browse files
committed
wii:
- add support in many places - libromfs use in correct place
1 parent df7416f commit 495f0cd

File tree

11 files changed

+180
-39
lines changed

11 files changed

+180
-39
lines changed

platforms/build-wii.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export OGC_MACHINE="rvl"
1313

1414
export PORTLIBS_PATH="$DEVKITPRO/portlibs"
1515
export LIBOGC="$DEVKITPRO/libogc"
16+
export WUT="$DEVKITPRO/wut"
1617

1718
export PORTLIBS_PATH_OGC="$PORTLIBS_PATH/$OGC_CONSOLE"
1819
export PORTLIBS_PATH_PPC="$PORTLIBS_PATH/ppc"
@@ -55,9 +56,9 @@ export ENDIANESS="big"
5556

5657
export COMMON_FLAGS="'-m${OGC_MACHINE}','-mcpu=750','-meabi','-mhard-float','-ffunction-sections','-fdata-sections'"
5758

58-
export COMPILE_FLAGS="'-D__WII__','-D__CONSOLE__','-D__NINTENDO_CONSOLE__','-D_OGC_','-DGEKKO','-isystem', '$LIBOGC/include', '-I$PORTLIBS_PATH_PPC/include', '-I$PORTLIBS_PATH_OGC/include'"
59+
export COMPILE_FLAGS="'-D__WII__','-D__CONSOLE__','-D__NINTENDO_CONSOLE__','-D_OGC_','-DGEKKO','-isystem', '$LIBOGC/include', '-isystem', '$WUT/include', '-I$PORTLIBS_PATH_PPC/include', '-I$PORTLIBS_PATH_OGC/include'"
5960

60-
export LINK_FLAGS="'-L$LIBOGC/lib','-L$PORTLIBS_LIB_PPC','-L$PORTLIBS_LIB_OGC'"
61+
export LINK_FLAGS="'-L$LIBOGC_LIB','-L$WUT/lib','-L$PORTLIBS_LIB_PPC','-L$PORTLIBS_LIB_OGC'"
6162

6263
export CROSS_FILE="./platforms/crossbuild-wii.ini"
6364

@@ -107,7 +108,7 @@ cpp_link_args = [$COMMON_FLAGS, $LINK_FLAGS]
107108
[properties]
108109
pkg_config_libdir = '$PKG_CONFIG_PATH'
109110
needs_exe_wrapper = true
110-
library_dirs= ['$LIBOGC_LIB', '$PORTLIBS_LIB_OGC','$PORTLIBS_LIB_PPC']
111+
library_dirs= ['$LIBOGC_LIB', '$WUT/lib', '$PORTLIBS_LIB_OGC','$PORTLIBS_LIB_PPC']
111112
112113
USE_META_XML = true
113114

platforms/wii/meson.build

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ wii_dependencies_native = [
2929
'SDL2main',
3030
'wiikeyboard',
3131
'wiiuse',
32+
'wut',
3233
]
3334

3435
foreach dep : wii_dependencies
@@ -54,34 +55,6 @@ foreach dep : wii_dependencies_native
5455
)
5556
endforeach
5657

57-
## ROMFS handling, this is special in the case of the wii
58-
59-
APP_ROMFS = meson.get_external_property('APP_ROMFS', '')
60-
61-
if APP_ROMFS != ''
62-
fs = import('fs')
63-
64-
if not fs.is_absolute(APP_ROMFS)
65-
APP_ROMFS = meson.project_source_root() / APP_ROMFS
66-
endif
67-
68-
if not fs.exists(APP_ROMFS)
69-
error('APP_ROMFS should exist, but doesn\'t: \'' + APP_ROMFS + '\'')
70-
endif
71-
72-
wii_deps = dependency(
73-
'libromfs',
74-
required: true,
75-
allow_fallback: true,
76-
native: false,
77-
default_options: {'romfs_dir': APP_ROMFS},
78-
)
79-
80-
81-
endif
82-
83-
84-
8558
## compilation
8659

8760
wii_elf_file = build_target(

src/helper/console_helpers.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
#elif defined(__3DS__)
1212
#include <3ds.h>
1313
#include <cstdlib>
14+
#elif defined(__WII__)
15+
#include <coreinit/debug.h>
16+
#include <wut.h>
17+
18+
#include <romfs-wiiu.h>
1419
#endif
1520

1621
#include <fmt/format.h>
@@ -20,6 +25,9 @@ void console::debug_write(const char* text, size_t size) {
2025
svcOutputDebugString(text, size);
2126
#elif defined(__SWITCH__)
2227
svcOutputDebugString(text, size);
28+
#elif defined(__WII__)
29+
//TODO: maybe use OSReportVerbose
30+
OSConsoleWrite(text, size);
2331
#else
2432
#error "not implemented"
2533
#endif
@@ -46,14 +54,23 @@ void console::debug_write(const char* text, size_t size) {
4654
#elif defined(__SWITCH__)
4755
UNUSED(url);
4856
return "";
57+
#elif defined(__WII__)
58+
UNUSED(url);
59+
return "";
4960
#else
5061
#error "not implemented"
5162
#endif
5263
}
5364

5465

66+
#if defined(__WII__)
67+
#define R_FAILED(x) ((x) != 0)
68+
#define Result int
69+
#endif
70+
71+
5572
void console::platform_init() {
56-
#if defined(__3DS__) || defined(__SWITCH__)
73+
#if defined(__3DS__) || defined(__SWITCH__) || defined(__WII__)
5774
Result ret = romfsInit();
5875
if (R_FAILED(ret)) {
5976
throw helper::InitializationError(fmt::format("romfsInit() failed: {:#2x}", static_cast<unsigned int>(ret)));
@@ -64,7 +81,7 @@ void console::platform_init() {
6481
}
6582

6683
void console::platform_exit() {
67-
#if defined(__3DS__) || defined(__SWITCH__)
84+
#if defined(__3DS__) || defined(__SWITCH__) || defined(__WII__)
6885
Result ret = romfsExit();
6986
if (R_FAILED(ret)) {
7087
throw helper::InitializationError(fmt::format("romfsExit() failed: {:#2x}", static_cast<unsigned int>(ret)));
@@ -79,6 +96,9 @@ bool console::inMainLoop() {
7996
return aptMainLoop();
8097
#elif defined(__SWITCH__)
8198
return appletMainLoop();
99+
#elif defined(__WII__)
100+
// the wii has no such logic
101+
return true;
82102
#else
83103
#error "not implemented"
84104
#endif

src/helper/platform.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ namespace {
4343
return "Nintendo Switch";
4444
#elif defined(__3DS__)
4545
return "Nintendo 3DS";
46+
#elif defined(__WII__)
47+
return "Wii";
4648
#elif defined(FLATPAK_BUILD)
4749
return "Linux (Flatpak)";
4850
#elif defined(__linux__)

src/input/console_buttons.hpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,58 @@ enum JOYCON {
131131
static_assert(BIT(JOYCON_B) == KEY_B);
132132
static_assert(BIT(JOYCON_SELECT) == KEY_SELECT);
133133

134+
#elif defined(__WII__)
135+
136+
137+
// some wii buttons, from (lib)wut, but since SDL doesn't handle inputs as flags, like (lib)wut), the have to be reversed and reversing 1 << x = log_2(x), this is done constexpr
138+
139+
140+
namespace {
141+
// this is rounding down since >> 1 throws away the least significant bit, but if its a power of two it is spot on
142+
constexpr unsigned int BIT_REVERSE(unsigned int x) {
143+
return x == 1 ? 0 : 1 + BIT_REVERSE(x >> 1);
144+
}
145+
}; // namespace
146+
147+
148+
#include <wut.h>
149+
#include <padscore/wpad.h>
150+
151+
152+
//using C enum (not enum class) on purpose
153+
enum JOYCON {
154+
155+
// see /opt/devkitpro/wut/include/padscore/wpad.h
156+
157+
JOYCON_LEFT = BIT_REVERSE(WPAD_BUTTON_LEFT), ///! The left button of the D-pad.
158+
JOYCON_RIGHT = BIT_REVERSE(WPAD_BUTTON_RIGHT), ///! The right button of the D-pad.
159+
JOYCON_DOWN = BIT_REVERSE(WPAD_BUTTON_DOWN), ///! The down button of the D-pad.
160+
JOYCON_UP = BIT_REVERSE(WPAD_BUTTON_UP), ///! The up button of the D-pad.
161+
162+
JOYCON_PLUS = BIT_REVERSE(WPAD_BUTTON_PLUS), ///! The + button.
163+
JOYCON_MINUS = BIT_REVERSE(WPAD_BUTTON_MINUS), ///! The - button.
164+
165+
JOYCON_1 = BIT_REVERSE(WPAD_BUTTON_1), ///! The 1 button.
166+
JOYCON_2 = BIT_REVERSE(WPAD_BUTTON_2), ///! The 2 button.
167+
168+
JOYCON_A = BIT_REVERSE(WPAD_BUTTON_A), ///! The A button.
169+
JOYCON_B = BIT_REVERSE(WPAD_BUTTON_B), ///! The B button.
170+
171+
JOYCON_C = BIT_REVERSE(WPAD_BUTTON_C), ///! The C button on the Nunchuk extension.
172+
JOYCON_Z = BIT_REVERSE(WPAD_BUTTON_Z), ///! The Z button on the Nunchuk extension.
173+
174+
JOYCON_HOME = BIT_REVERSE(WPAD_BUTTON_HOME), ///! The HOME button.
175+
};
176+
177+
/// Creates a bitmask from a bit number.
178+
#define BIT(n) (1U<<(n))
179+
180+
// some static asserts to check if BIT_REVERSE works as expected
181+
static_assert(BIT(JOYCON_LEFT) == WPAD_BUTTON_LEFT);
182+
static_assert(BIT(JOYCON_HOME) == WPAD_BUTTON_HOME);
183+
184+
#else
185+
#error "unsupported console"
134186

135187
#endif
136188

src/input/joystick_input.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ input::JoystickInput& input::JoystickInput::operator=(JoystickInput&& input) noe
4545
return std::make_unique<_3DSJoystickInput_Type1>(joystick, instance_id, name);
4646
}
4747

48+
#elif defined(__WII_)
49+
if (guid == WiiJoystickInput_Type1::guid) {
50+
return std::make_unique<WiiJoystickInput_Type1>(joystick, instance_id, name);
51+
}
52+
4853
#endif
4954
#endif
5055

src/input/joystick_input.hpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,32 @@ namespace input {
193193
};
194194

195195

196+
#elif defined(__WII__)
197+
198+
struct WiiJoystickInput_Type1 : ConsoleJoystickInput {
199+
200+
//TODO
201+
static constexpr sdl::GUID guid{};
202+
203+
WiiJoystickInput_Type1(SDL_Joystick* joystick, SDL_JoystickID instance_id, const std::string& name);
204+
205+
[[nodiscard]] helper::optional<NavigationEvent> get_navigation_event(const SDL_Event& event) const override;
206+
207+
[[nodiscard]] std::string describe_navigation_event(NavigationEvent event) const override;
208+
209+
[[nodiscard]] std::string key_to_string(console::SettingsType key) const override;
210+
211+
[[nodiscard]] JoystickSettings to_normal_settings(
212+
const AbstractJoystickSettings<console::SettingsType>& settings
213+
) const override;
214+
215+
[[nodiscard]] AbstractJoystickSettings<console::SettingsType> default_settings_raw() const override;
216+
};
217+
218+
196219
#endif
197220

221+
198222
#endif
199223

200224

@@ -305,7 +329,7 @@ namespace input {
305329
protected:
306330
[[nodiscard]] helper::optional<InputEvent> sdl_event_to_input_event(const SDL_Event& event) const override;
307331
};
308-
#if !defined(__SWITCH__) && !defined(__3DS__)
332+
#if !defined(__SWITCH__) && !defined(__3DS__) && !defined(__WII__)
309333
#error "unsupported console"
310334
#endif
311335
#endif

src/thirdparty/hash-library/sha256.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@
2727
#define __BYTE_ORDER __BYTE_ORDER__
2828
#define __BIG_ENDIAN __ORDER_BIG_ENDIAN__
2929
#endif
30+
#elif defined(__WII__)
31+
#if !(defined(__BYTE_ORDER__) or defined(__ORDER_BIG_ENDIAN__))
32+
#error "__BYTE_ORDER__ or __ORDER_BIG_ENDIAN__ not defined"!
33+
#else
34+
#define __BYTE_ORDER __BYTE_ORDER__
35+
#define __BIG_ENDIAN __ORDER_BIG_ENDIAN__
36+
#endif
3037
#elif defined(__APPLE__)
3138
#include <machine/endian.h>
3239
#else

subprojects/libromfs.wrap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11

22

33
[wrap-git]
4+
directory = libromfs-0.7
45
url = https://github.com/yawut/libromfs-wiiu.git
56
revision = master
67
depth = 1
8+
79
patch_directory = libromfs
810

911
[provide]

subprojects/packagefiles/libromfs/meson.build

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,24 @@ deps = []
1212

1313

1414
if meson.is_cross_build()
15-
if host_machine.system() == 'wiiu'
15+
if host_machine.system() == 'wiiu' or host_machine.system() == 'wii'
1616

1717
object_target = 'elf32-powerpc'
1818
binary_arch = 'powerpc:common'
19-
## deps +='wut'
2019

21-
elif host_machine.system() == 'wii'
2220

23-
object_target = 'elf32-powerpc'
24-
binary_arch = 'powerpc:common'
21+
library_dirs = meson.get_external_property('library_dirs', [''])
22+
if library_dirs.length() == 0
23+
error('property \'library_dirs\' has to be set!')
24+
endif
25+
26+
c = meson.get_compiler('c')
27+
28+
deps += c.find_library(
29+
'wut',
30+
required: true,
31+
dirs: library_dirs,
32+
)
2533

2634
else
2735
error('not supported platform: ' + host_machine.system())
@@ -81,6 +89,7 @@ inc_dirs = include_directories('include')
8189
libromfs_lib = library(
8290
'libromfs',
8391
files('source/romfs.c'),
92+
c_args: ['-D_POSIX_C_SOURCE=200809'],
8493
include_directories: inc_dirs,
8594
dependencies: deps,
8695
install: true,

0 commit comments

Comments
 (0)