From f7975fc1ab2b18525687386eed8d7cd6fa7f946c Mon Sep 17 00:00:00 2001 From: Nathan Strong Date: Mon, 2 Jan 2023 00:36:18 -0800 Subject: [PATCH 1/9] (WiiU) explicitly shut down HID driver, preventing lockup == DETAILS serial debug and some testing revealed that the cause of the lockup on exit was because of a deadlock in the HID i/o thread. solution: explicitly shutdown the HID thread during RetroArch termination process. --- input/drivers_joypad/wiiu_joypad.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/input/drivers_joypad/wiiu_joypad.c b/input/drivers_joypad/wiiu_joypad.c index 6c4c972159e5..8adf4083f547 100644 --- a/input/drivers_joypad/wiiu_joypad.c +++ b/input/drivers_joypad/wiiu_joypad.c @@ -17,6 +17,7 @@ #include "../include/wiiu/input.h" static bool ready = false; +const hid_driver_t *hid_driver; wiiu_joypad_t joypad_state = {0}; @@ -25,7 +26,7 @@ static void *wiiu_joypad_init(void *data) memset(&joypad_state, 0, sizeof(wiiu_joypad_t)); joypad_state.pads[MAX_USERS].data = (void *)0xdeadbeef; joypad_state.max_slot = MAX_USERS; - input_hid_init_first(); + hid_driver = input_hid_init_first(); wpad_driver.init(data); kpad_driver.init(data); @@ -50,6 +51,12 @@ static void wiiu_joypad_destroy(void) wpad_driver.destroy(); kpad_driver.destroy(); hidpad_driver.destroy(); + + if(hid_driver) { + hid_driver->free((void *)hid_driver_get_data()); + hid_driver_reset_data(); + hid_driver = NULL; + } } static int32_t wiiu_joypad_button(unsigned port, uint16_t joykey) From 2ca2d96f462272e2e7c1ded77ac884b9cdad010c Mon Sep 17 00:00:00 2001 From: Ash Logan Date: Sun, 18 Dec 2022 15:44:05 +1100 Subject: [PATCH 2/9] (WiiU) Port to wut toolchain This commit is enough to compile RetroArch using wut and more modern versions of devkitPPC. Among the requisite ports and bugfixes, the wiiu code has been switched to use wut's headers (where possible). There's a handful of headers where RA's are more precise, and these have been put into the `wiiu/include/` hierarchy mirroring WUT's folder structure, but with `ra_` prepended to the filename to avoid include directory priority fighting. Other changes are related to the header changes: - update defines to use WUT's new definition - replace custom integer types with standard ones (eg u8 -> uint8_t) - remove some workarounds/hacks in favor of more precise handling in WUT. Cut features that will be re-added later: - Current rpx symbol names in the exception handler - somemopt networking optimisations - Core loading - libfat support - always uses fs:/vol/external01 (WiiU) memory: handle being in the background properly Quitting on Aroma works a little differently to HBL - we need to use a ProcUI loop and go into the background before quitting. This patch prepares the MEM1 and bucket allocators so they won't crash when this happens. (WiiU) aroma: fix conflict with FTPiiU plug-in == DETAILS The HID polling thread was written to be run on a single core, and basically completely occupies it, not allowing any other threads to run on it. It turns out, this is a problem in Aroma, because other things can be running on your cores. For instance, the FTPiiU server thread runs on the same core as the HID polling thread, which explains why FTPiiU stopped working when RetroArch was running. The other problem, is that if FTPiiU is holding the IPC BufPool mutex when RA is started, a deadlock will eventually happen because RA will try to acquire the mutex and the FTPii thread, being suspended, won't be able to release it. So! To fix it: - add a 500-microsecond sleep to the HID polling thread - update to WUT's HID headers, which makes some minor changes to structure member names --- Makefile.wiiu | 78 +- audio/drivers/wiiu_audio.c | 19 +- frontend/drivers/platform_wiiu.c | 415 +- gfx/common/gx2_defines.h | 25 +- gfx/drivers/gx2_gfx.c | 25 +- gfx/drivers/gx2_shaders/bokeh.c | 39 +- gfx/drivers/gx2_shaders/frame.c | 17 +- gfx/drivers/gx2_shaders/ribbon.c | 17 +- gfx/drivers/gx2_shaders/ribbon_simple.c | 15 +- gfx/drivers/gx2_shaders/snow.c | 47 +- gfx/drivers/gx2_shaders/snow_simple.c | 47 +- gfx/drivers/gx2_shaders/snowflake.c | 25 +- gfx/drivers/gx2_shaders/sprite.c | 31 +- gfx/drivers/gx2_shaders/sprite.h | 2 +- gfx/drivers/gx2_shaders/tex.c | 19 +- gfx/drivers_font_renderer/freetype.c | 4 +- gfx/drivers_font_renderer/stb_unicode.c | 4 +- input/drivers/wiiu_input.c | 2 +- input/drivers_hid/wiiu_hid.c | 32 +- input/drivers_joypad/wiiu/kpad_driver.c | 38 +- input/include/wiiu/hid.h | 3 + input/include/wiiu/input.h | 6 +- libretro-common/features/features_cpu.c | 4 +- libretro-common/include/net/net_compat.h | 4 - libretro-common/include/retro_timers.h | 4 +- libretro-common/net/net_compat.c | 52 - libretro-common/net/net_socket.c | 46 +- menu/menu_driver.c | 16168 ++++++++++----------- wiiu/fs/fs_utils.c | 66 - wiiu/fs/fs_utils.h | 16 - wiiu/fs/sd_fat_devoptab.c | 1073 -- wiiu/fs/sd_fat_devoptab.h | 38 - wiiu/gx2_shader_inl.h | 4 +- wiiu/hbl.h | 26 - wiiu/include/arpa/inet.h | 21 - wiiu/include/array_helper.h | 3 + wiiu/include/gx2/ra_shaders.h | 581 + wiiu/include/netdb.h | 63 - wiiu/include/netinet/in.h | 36 - wiiu/include/netinet/tcp.h | 14 - wiiu/include/nn/ac/ra_ac_c.h | 150 + wiiu/include/nsyskbd/ra_nsyskbd.h | 38 + wiiu/include/sndcore2/ra_dsp.h | 21 + wiiu/include/sndcore2/ra_multivoice.h | 40 + wiiu/include/sys/socket.h | 143 - wiiu/link.ld | 36 - wiiu/link_elf.ld | 261 - wiiu/link_rpl.ld | 264 - wiiu/main.c | 249 - wiiu/shader_utils.c | 36 +- wiiu/shader_utils.h | 4 +- wiiu/system/atomic.c | 2 +- wiiu/system/dynamic.c | 4 +- wiiu/system/exception_handler.c | 44 +- wiiu/system/exception_handler.h | 3 +- wiiu/system/imports.h | 324 - wiiu/system/memory.c | 86 +- wiiu/system/missing_libc_functions.c | 26 +- wiiu/system/stubs_elf.S | 31 - wiiu/system/stubs_rpl.S | 58 - wiiu/wiiu_dbg.h | 19 - wiiu/wut/elf2rpl/Makefile | 27 - wiiu/wut/elf2rpl/be_val.h | 72 - wiiu/wut/elf2rpl/elf.h | 314 - wiiu/wut/elf2rpl/elf2rpl.vcxproj | 172 - wiiu/wut/elf2rpl/elf2rpl.vcxproj.filters | 39 - wiiu/wut/elf2rpl/main.cpp | 1816 --- wiiu/wut/elf2rpl/utils.h | 119 - 68 files changed, 9311 insertions(+), 14216 deletions(-) delete mode 100644 wiiu/fs/fs_utils.c delete mode 100644 wiiu/fs/fs_utils.h delete mode 100644 wiiu/fs/sd_fat_devoptab.c delete mode 100644 wiiu/fs/sd_fat_devoptab.h delete mode 100644 wiiu/hbl.h delete mode 100644 wiiu/include/arpa/inet.h create mode 100644 wiiu/include/array_helper.h create mode 100644 wiiu/include/gx2/ra_shaders.h delete mode 100644 wiiu/include/netdb.h delete mode 100644 wiiu/include/netinet/in.h delete mode 100644 wiiu/include/netinet/tcp.h create mode 100644 wiiu/include/nn/ac/ra_ac_c.h create mode 100644 wiiu/include/nsyskbd/ra_nsyskbd.h create mode 100644 wiiu/include/sndcore2/ra_dsp.h create mode 100644 wiiu/include/sndcore2/ra_multivoice.h delete mode 100644 wiiu/include/sys/socket.h delete mode 100644 wiiu/link.ld delete mode 100644 wiiu/link_elf.ld delete mode 100644 wiiu/link_rpl.ld delete mode 100644 wiiu/main.c delete mode 100644 wiiu/system/imports.h delete mode 100644 wiiu/system/stubs_elf.S delete mode 100644 wiiu/system/stubs_rpl.S delete mode 100644 wiiu/wut/elf2rpl/Makefile delete mode 100644 wiiu/wut/elf2rpl/be_val.h delete mode 100644 wiiu/wut/elf2rpl/elf.h delete mode 100644 wiiu/wut/elf2rpl/elf2rpl.vcxproj delete mode 100644 wiiu/wut/elf2rpl/elf2rpl.vcxproj.filters delete mode 100644 wiiu/wut/elf2rpl/main.cpp delete mode 100644 wiiu/wut/elf2rpl/utils.h diff --git a/Makefile.wiiu b/Makefile.wiiu index e1f96a04ebb0..cdf50d79cd94 100644 --- a/Makefile.wiiu +++ b/Makefile.wiiu @@ -1,10 +1,8 @@ TARGET := retroarch_wiiu -BUILD_HBL_ELF = 1 -BUILD_RPX = 1 DEBUG = 0 GRIFFIN_BUILD = 0 -SALAMANDER_BUILD = 0 +SALAMANDER_BUILD ?= 0 HAVE_STATIC_DUMMY ?= 0 WHOLE_ARCHIVE_LINK = 0 WIIU_HID = 1 @@ -37,18 +35,10 @@ INCDIRS := #----------------------------- # Features and object files -OBJ += wiiu/main.o OBJ += wiiu/system/memory.o OBJ += wiiu/system/atomic.o OBJ += wiiu/system/exception_handler.o OBJ += wiiu/system/missing_libc_functions.o -OBJ += wiiu/fs/sd_fat_devoptab.o -OBJ += wiiu/fs/fs_utils.o -OBJ += wiiu/hbl.o - -RPX_OBJ = $(BUILD_DIR)/wiiu/system/stubs_rpl.o -HBL_ELF_OBJ = $(BUILD_DIR)/wiiu/system/dynamic.o \ - $(BUILD_DIR)/wiiu/system/stubs_elf.o ifeq ($(SALAMANDER_BUILD),1) DEFINES += -DRARCH_CONSOLE -DIS_SALAMANDER @@ -248,15 +238,6 @@ ifeq ($(HAVE_BUILTINZLIB),0) endif endif -LDFLAGS += -Wl,--gc-sections - -RPX_LDFLAGS := -pie -fPIE -RPX_LDFLAGS += -z common-page-size=64 -z max-page-size=64 -RPX_LDFLAGS += -T wiiu/link_rpl.ld -RPX_LDFLAGS += -nostartfiles - -HBL_ELF_LDFLAGS := -T wiiu/link_elf.ld - #----------------------------- # Compiler setup @@ -267,7 +248,7 @@ ifeq ($(strip $(DEVKITPRO)),) $(error "Please set DEVKITPRO in your environment. export DEVKITPRO=devkitPRO") endif -export PATH := $(PATH):$(DEVKITPPC)/bin +export PATH := $(PATH):$(DEVKITPPC)/bin:$(DEVKITPRO)/tools/bin PREFIX := powerpc-eabi- @@ -280,25 +261,19 @@ STRIP := $(PREFIX)strip NM := $(PREFIX)nm LD := $(CXX) -ELF2RPL := wiiu/wut/elf2rpl/elf2rpl +WUT_ROOT ?= $(DEVKITPRO)/wut -ifneq ($(findstring Linux,$(shell uname -a)),) -else ifneq ($(findstring Darwin,$(shell uname -a)),) -else - ELF2RPL := $(ELF2RPL).exe -endif +RPXSPECS := -specs=$(WUT_ROOT)/share/wut.specs +RPLSPECS := -specs=$(WUT_ROOT)/share/wut.specs -specs=$(WUT_ROOT)/share/rpl.specs + +INCDIRS += -I$(WUT_ROOT)/include +LIBDIRS += -L$(WUT_ROOT)/lib +LIBS += -lwut #----------------------------- # Targets and build rules -TARGETS := -ifeq ($(BUILD_RPX), 1) -TARGETS += $(TARGET).rpx -endif - -ifeq ($(BUILD_HBL_ELF), 1) -TARGETS += $(TARGET).elf -endif +TARGETS := $(TARGET).rpx DEPFLAGS = -MT $@ -MMD -MP -MF $(BUILD_DIR)/$*.depend @@ -334,38 +309,21 @@ $(BUILD_DIR)/%.o: %.s %.depend %.depend: ; %.last: ; -$(ELF2RPL): - @$(if $(Q), echo MAKE $@,) - $(Q)$(MAKE) -C wiiu/wut/elf2rpl/ - -$(BUILD_DIR)/$(TARGET).elf: $(OBJ) $(HBL_ELF_OBJ) libretro_wiiu.a wiiu/link_elf.ld .$(TARGET).elf.last +$(BUILD_DIR)/$(TARGET).rpx.elf: $(OBJ) libretro_wiiu.a @$(if $(Q), echo LD $@,) - @touch .$(TARGET).elf.last - $(Q)$(LD) $(OBJ) $(HBL_ELF_OBJ) $(LDFLAGS) $(HBL_ELF_LDFLAGS) $(LIBDIRS) $(LIBS) -o $@ + $(Q)$(LD) $(OBJ) $(RPXSPECS) $(LDFLAGS) $(LIBDIRS) $(LIBS) -o $@ -$(BUILD_DIR)/$(TARGET).rpx.elf: $(OBJ) $(RPX_OBJ) libretro_wiiu.a wiiu/link_elf.ld - @$(if $(Q), echo LD $@,) - $(Q)$(LD) $(OBJ) $(RPX_OBJ) $(LDFLAGS) $(RPX_LDFLAGS) $(LIBDIRS) $(LIBS) -o $@ - -$(BUILD_DIR)/$(TARGET).large.rpx: $(BUILD_DIR)/$(TARGET).rpx.elf $(ELF2RPL) .$(TARGET).rpx.large.last +$(BUILD_DIR)/$(TARGET).rpx: $(BUILD_DIR)/$(TARGET).rpx.elf @$(if $(Q), echo ELF2RPL $@,) - @touch .$(TARGET).rpx.large.last - $(Q)-$(ELF2RPL) $< $@ - -$(BUILD_DIR)/$(TARGET).rpx: $(BUILD_DIR)/$(TARGET).large.rpx .$(TARGET).rpx.last - @$(if $(Q), echo COMPRESS $@,) - @touch .$(TARGET).rpx.large.last - $(Q)wiiurpxtool -c $< $@ + $(Q)elf2rpl $< $@ clean: @$(if $(Q), echo $@,) - $(Q)rm -f $(OBJ) $(RPX_OBJ) $(HBL_ELF_OBJ) $(TARGET).elf $(TARGET).rpx.elf $(TARGET).rpx - $(Q)rm -f $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).rpx.elf $(BUILD_DIR)/$(TARGET).large.rpx $(BUILD_DIR)/$(TARGET).rpx - $(Q)rm -f .$(TARGET).elf.last .$(TARGET).rpx.elf.last .$(TARGET).rpx.large.last .$(TARGET).rpx.last - $(Q)rm -f $(OBJ:.o=.depend) $(RPX_OBJ:.o=.depend) $(HBL_ELF_OBJ:.o=.depend) - $(Q)$(MAKE) -C wiiu/wut/elf2rpl/ clean + $(Q)rm -f $(OBJ) $(TARGET).rpx.elf $(TARGET).rpx + $(Q)rm -f $(BUILD_DIR)/$(TARGET).rpx.elf $(BUILD_DIR)/$(TARGET).rpx + $(Q)rm -f $(OBJ:.o=.depend) .PHONY: clean all .PRECIOUS: %.depend %.last --include $(OBJ:.o=.depend) $(RPX_OBJ:.o=.depend) $(HBL_ELF_OBJ:.o=.depend) +-include $(OBJ:.o=.depend) diff --git a/audio/drivers/wiiu_audio.c b/audio/drivers/wiiu_audio.c index de5d3d93531c..9065a66297fa 100644 --- a/audio/drivers/wiiu_audio.c +++ b/audio/drivers/wiiu_audio.c @@ -18,8 +18,12 @@ #include #include -#include -#include + +#include +#include +#include +#include +#include #include "../../wiiu/wiiu_dbg.h" #include "../../wiiu/system/memory.h" @@ -75,16 +79,15 @@ void wiiu_ax_callback(void) } } -extern void AXRegisterFrameCallback(void *cb); - static void* ax_audio_init(const char* device, unsigned rate, unsigned latency, unsigned block_frames, unsigned *new_rate) { AXVoiceOffsets offsets[2]; - u16 setup_buf[0x30] = {0}; - setup_buf[0x25] = 2; /* we request 2 channels */ - AXInitParams init = {AX_INIT_RENDERER_48KHZ, 0, 0}; + DspConfig setup_buf = {0}; + setup_buf.multi_ch_count = 2; + + AXInitParams init = {AX_INIT_RENDERER_48KHZ, {0, 0}}; AXVoiceVeData ve = {0x8000, 0}; ax_audio_t* ax = (ax_audio_t*)calloc(1, sizeof(ax_audio_t)); @@ -93,7 +96,7 @@ static void* ax_audio_init(const char* device, unsigned rate, unsigned latency, AXInitWithParams(&init); - AXAcquireMultiVoice(31, NULL, 0, setup_buf, &ax->mvoice); + AXAcquireMultiVoice(31, NULL, 0, &setup_buf, &ax->mvoice); if (!ax->mvoice || ax->mvoice->channels != 2) { diff --git a/frontend/drivers/platform_wiiu.c b/frontend/drivers/platform_wiiu.c index c87607cd0b9a..1c36fc0701d6 100644 --- a/frontend/drivers/platform_wiiu.c +++ b/frontend/drivers/platform_wiiu.c @@ -22,8 +22,6 @@ #include #include -#include -#include #include #ifndef IS_SALAMANDER @@ -32,13 +30,20 @@ #include -#include -#include -#include -#include -#include -#include - +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include #include "../frontend.h" #include "../frontend_driver.h" @@ -59,21 +64,16 @@ #endif #endif -#include "hbl.h" #include "wiiu_dbg.h" #include "system/exception_handler.h" +#include "system/memory.h" -#define WIIU_SD_PATH "sd:/" -#define WIIU_USB_PATH "usb:/" -#define WIIU_STORAGE_USB_PATH "storage_usb:/" +#define WIIU_SD_PATH "fs:/vol/external01/" /** * The Wii U frontend driver, along with the main() method. */ -#ifndef IS_SALAMANDER -static enum frontend_fork wiiu_fork_mode = FRONTEND_FORK_NONE; -#endif static const char *elf_path_cst = WIIU_SD_PATH "retroarch/retroarch.elf"; static bool exists(char *path) @@ -166,7 +166,10 @@ static void frontend_wiiu_init(void *data) DEBUG_LINE(); } -static int frontend_wiiu_get_rating(void) { return 10; } +static int frontend_wiiu_get_rating(void) +{ + return 10; +} enum frontend_architecture frontend_wiiu_get_arch(void) { @@ -188,152 +191,22 @@ static int frontend_wiiu_parse_drive_list(void *data, bool load_content) msg_hash_to_str(MENU_ENUM_LABEL_FILE_DETECT_CORE_LIST_PUSH_DIR), enum_idx, FILE_TYPE_DIRECTORY, 0, 0, NULL); - - menu_entries_append(list, WIIU_USB_PATH, - msg_hash_to_str(MENU_ENUM_LABEL_FILE_DETECT_CORE_LIST_PUSH_DIR), - enum_idx, - FILE_TYPE_DIRECTORY, 0, 0, NULL); - menu_entries_append(list, WIIU_STORAGE_USB_PATH, - msg_hash_to_str(MENU_ENUM_LABEL_FILE_DETECT_CORE_LIST_PUSH_DIR), - enum_idx, - FILE_TYPE_DIRECTORY, 0, 0, NULL); #endif return 0; } -static void frontend_wiiu_exec(const char *path, bool should_load_content) -{ - struct - { - u32 magic; - u32 argc; -#ifndef IS_SALAMANDER -#ifdef HAVE_NETWORKING - char *argv[NETPLAY_FORK_MAX_ARGS + 1]; -#else - char *argv[3]; -#endif -#else - char *argv[2]; -#endif - char args[]; - } *param = getApplicationEndAddr(); - char *arg = param->args; - - DEBUG_STR(path); - - param->argc = 1; - param->argv[0] = arg; - arg += strlcpy(arg, elf_path_cst, PATH_MAX_LENGTH); - arg += 1; - - param->argv[1] = NULL; - -#ifndef IS_SALAMANDER - if (should_load_content) - { - const char *content = path_get(RARCH_PATH_CONTENT); -#ifdef HAVE_NETWORKING - char *arg_data[NETPLAY_FORK_MAX_ARGS]; - - if (netplay_driver_ctl(RARCH_NETPLAY_CTL_GET_FORK_ARGS, (void*)arg_data)) - { - char **cur_arg = arg_data; - - do - { - param->argv[param->argc++] = arg; - arg += strlcpy(arg, *cur_arg, PATH_MAX_LENGTH); - arg += 1; - } - while (*(++cur_arg)); - - param->argv[param->argc] = NULL; - } - else -#endif - if (!string_is_empty(content)) - { - param->argc = 2; - param->argv[1] = arg; - arg += strlcpy(arg, content, PATH_MAX_LENGTH); - arg += 1; - - param->argv[2] = NULL; - } - } -#endif - - if (HBL_loadToMemory(path, (u32)arg - (u32)param) < 0) - { - RARCH_ERR("Failed to load core\n"); - } - else - { - param->magic = ARGV_MAGIC; - ARGV_PTR = param; - - DEBUG_VAR(param->argc); - DEBUG_VAR(param->argv); - } -} - -#ifndef IS_SALAMANDER -static bool frontend_wiiu_set_fork(enum frontend_fork fork_mode) -{ - switch (fork_mode) - { - case FRONTEND_FORK_CORE: - wiiu_fork_mode = fork_mode; - break; - case FRONTEND_FORK_CORE_WITH_ARGS: - wiiu_fork_mode = fork_mode; - break; - case FRONTEND_FORK_RESTART: - /* NOTE: We don't implement Salamander, so just turn - * this into FRONTEND_FORK_CORE. */ - wiiu_fork_mode = FRONTEND_FORK_CORE; - break; - case FRONTEND_FORK_NONE: - default: - return false; - } - - return true; -} -#endif - -static void frontend_wiiu_exitspawn(char *s, size_t len, char *args) -{ - bool should_load_content = false; -#ifndef IS_SALAMANDER - if (wiiu_fork_mode == FRONTEND_FORK_NONE) - return; - - switch (wiiu_fork_mode) - { - case FRONTEND_FORK_CORE_WITH_ARGS: - should_load_content = true; - break; - default: - break; - } -#endif - frontend_wiiu_exec(s, should_load_content); -} - frontend_ctx_driver_t frontend_ctx_wiiu = { frontend_wiiu_get_env_settings, frontend_wiiu_init, frontend_wiiu_deinit, - frontend_wiiu_exitspawn, + NULL, /* exitspawn */ NULL, /* process_args */ - frontend_wiiu_exec, + NULL, /* exec */ #ifdef IS_SALAMANDER NULL, /* set_fork */ #else - frontend_wiiu_set_fork, + NULL, /* set_fork */ #endif frontend_wiiu_shutdown, NULL, /* get_name */ @@ -368,45 +241,24 @@ frontend_ctx_driver_t frontend_ctx_wiiu = /* main() and its supporting functions */ static void main_setup(void); -static void get_arguments(int *argc, char ***argv); #ifndef IS_SALAMANDER static void main_loop(void); #endif static void main_teardown(void); -static void init_network(void); -static void deinit_network(void); static void init_logging(void); static void deinit_logging(void); -static void wiiu_log_init(int port); -static void wiiu_log_deinit(void); static ssize_t wiiu_log_write(struct _reent *r, void *fd, const char *ptr, size_t len); static void init_pad_libraries(void); static void deinit_pad_libraries(void); -static void SaveCallback(void); - -static struct sockaddr_in broadcast; -static int wiiu_log_socket = -1; -static volatile int wiiu_log_lock = 0; - -#if !defined(PC_DEVELOPMENT_TCP_PORT) -#define PC_DEVELOPMENT_TCP_PORT 4405 -#endif - -static devoptab_t dotab_stdout = -{ - "stdout_net", /* device name */ - 0, /* size of file structure */ - NULL, /* device open */ - NULL, /* device close */ - wiiu_log_write, /* device write */ - NULL, /* ... */ -}; +static void proc_setup(void); +static void proc_exit(void); +static void proc_save_callback(void); int main(int argc, char **argv) { + proc_setup(); main_setup(); - get_arguments(&argc, &argv); #ifdef IS_SALAMANDER int salamander_main(int argc, char **argv); @@ -418,42 +270,16 @@ int main(int argc, char **argv) #endif /* IS_SALAMANDER */ main_teardown(); + proc_exit(); /* We always return 0 because if we don't, it can prevent loading a * different RPX/ELF in HBL. */ return 0; } -static void get_arguments(int *argc, char ***argv) -{ - DEBUG_VAR(ARGV_PTR); - if (ARGV_PTR && ((u32)ARGV_PTR < 0x01000000)) - { - struct - { - u32 magic; - u32 argc; - char *argv[3]; - } *param = ARGV_PTR; - - if (param->magic == ARGV_MAGIC) - { - *argc = param->argc; - *argv = param->argv; - } - ARGV_PTR = NULL; - } - - DEBUG_VAR(argc); - DEBUG_VAR(argv[0]); - DEBUG_VAR(argv[1]); - fflush(stdout); -} - static void main_setup(void) { - setup_os_exceptions(); - ProcUIInit(&SaveCallback); - init_network(); + memoryInitialize(); + init_os_exceptions(); init_logging(); init_pad_libraries(); verbosity_enable(); @@ -463,9 +289,24 @@ static void main_setup(void) static void main_teardown(void) { deinit_pad_libraries(); - ProcUIShutdown(); deinit_logging(); - deinit_network(); + deinit_os_exceptions(); + memoryRelease(); +} + +static void proc_setup(void) +{ + ProcUIInit(&proc_save_callback); +} + +static void proc_exit(void) +{ + ProcUIShutdown(); +} + +static void proc_save_callback(void) +{ + OSSavesDone_ReadyToRelease(); } #ifndef IS_SALAMANDER @@ -501,51 +342,20 @@ static void main_loop(void) } #endif -static void SaveCallback(void) -{ - OSSavesDone_ReadyToRelease(); -} - - -static void init_network(void) -{ - ACInitialize(); - ACConnect(); -#ifdef IS_SALAMANDER - socket_lib_init(); -#else - network_init(); -#endif /* IS_SALAMANDER */ -} - -static void deinit_network(void) -{ - ACClose(); - ACFinalize(); -} - -int getBroadcastAddress(ACIpAddress *broadcast) +static devoptab_t dotab_stdout = { - ACIpAddress myIp, mySubnet; - ACResult result; - - if (!broadcast) - return -1; - - result = ACGetAssignedAddress(&myIp); - if (result < 0) - return -1; - result = ACGetAssignedSubnet(&mySubnet); - if (result < 0) - return -1; - - *broadcast = myIp | (~mySubnet); - return 0; -} + "stdout_whb", /* device name */ + 0, /* size of file structure */ + NULL, /* device open */ + NULL, /* device close */ + wiiu_log_write, /* device write */ + NULL, /* ... */ +}; static void init_logging(void) { - wiiu_log_init(PC_DEVELOPMENT_TCP_PORT); + WHBLogUdpInit(); + WHBLogCafeInit(); devoptab_list[STD_OUT] = &dotab_stdout; devoptab_list[STD_ERR] = &dotab_stdout; } @@ -555,59 +365,29 @@ static void deinit_logging(void) fflush(stdout); fflush(stderr); - wiiu_log_deinit(); + WHBLogCafeDeinit(); + WHBLogUdpDeinit(); } -static int broadcast_init(int port) -{ - ACIpAddress broadcast_ip; - if (getBroadcastAddress(&broadcast_ip) < 0) - return -1; - - memset(&broadcast, 0, sizeof(broadcast)); - broadcast.sin_family = AF_INET; - broadcast.sin_port = htons(port); - broadcast.sin_addr.s_addr = htonl(broadcast_ip); - - return 0; -} - -static void wiiu_log_init(int port) +static ssize_t wiiu_log_write(struct _reent *r, + void *fd, const char *ptr, size_t len) { - wiiu_log_lock = 0; - - if (wiiu_log_socket >= 0) - return; + // Do a bit of line buffering to try and make the log output nicer + // we just truncate if a line goes over + static char linebuf[2048]; //match wut's PRINTF_BUFFER_LENGTH + static size_t linebuf_pos = 0; - if (broadcast_init(port) < 0) - return; - - wiiu_log_socket = socket(AF_INET, SOCK_DGRAM, 0); - - if (wiiu_log_socket < 0) - return; - - struct sockaddr_in connect_addr; - memset(&connect_addr, 0, sizeof(connect_addr)); - connect_addr.sin_family = AF_INET; - connect_addr.sin_port = 0; - connect_addr.sin_addr.s_addr = htonl(INADDR_ANY); + snprintf(linebuf + linebuf_pos, sizeof(linebuf) - linebuf_pos - 1, "%.*s", + len, ptr); + linebuf_pos = strlen(linebuf); - if ( bind(wiiu_log_socket, (struct sockaddr *)&connect_addr, sizeof(connect_addr)) < 0) + if (linebuf[linebuf_pos - 1] == '\n' || linebuf_pos >= sizeof(linebuf) - 2) { - socketclose(wiiu_log_socket); - wiiu_log_socket = -1; - return; + WHBLogWrite(linebuf); + linebuf_pos = 0; } -} -static void wiiu_log_deinit(void) -{ - if (wiiu_log_socket >= 0) - { - socketclose(wiiu_log_socket); - wiiu_log_socket = -1; - } + return (ssize_t) len; } static void init_pad_libraries(void) @@ -625,54 +405,3 @@ static void deinit_pad_libraries(void) KPADShutdown(); #endif /* IS_SALAMANDER */ } - -/* logging routines */ - -void net_print(const char *str) -{ - wiiu_log_write(NULL, 0, str, strlen(str)); -} - -void net_print_exp(const char *str) -{ - sendto(wiiu_log_socket, str, strlen(str), 0, (struct sockaddr *)&broadcast, sizeof(broadcast)); -} - -/* RFC 791 specifies that any IP host must be able - * to receive a datagram of 576 bytes. - * Since we're generally never logging more than a - * line or two's worth of data (~100 bytes) - * this is a reasonable size for our use. */ -#define DGRAM_SIZE 576 - -static ssize_t wiiu_log_write(struct _reent *r, - void *fd, const char *ptr, size_t len) -{ - int remaining; - if (wiiu_log_socket < 0) - return len; - - while (wiiu_log_lock) - OSSleepTicks(((248625000 / 4)) / 1000); - - wiiu_log_lock = 1; - - remaining = len; - - while (remaining > 0) - { - int block = remaining < DGRAM_SIZE ? remaining : DGRAM_SIZE; - int sent = sendto(wiiu_log_socket, ptr, block, 0, - (struct sockaddr *)&broadcast, sizeof(broadcast)); - - if (sent < 0) - break; - - remaining -= sent; - ptr += sent; - } - - wiiu_log_lock = 0; - - return len; -} diff --git a/gfx/common/gx2_defines.h b/gfx/common/gx2_defines.h index 05a71d912fc7..857a468ca63b 100644 --- a/gfx/common/gx2_defines.h +++ b/gfx/common/gx2_defines.h @@ -1,7 +1,22 @@ #ifndef __GX2_DEFINES_H #define __GX2_DEFINES_H -#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define GX2_INVALIDATE_MODE_CPU_UNIFORM_BLOCK (GX2_INVALIDATE_MODE_CPU | GX2_INVALIDATE_MODE_UNIFORM_BLOCK) #include "../video_defines.h" #include "../video_shader_parse.h" @@ -26,8 +41,8 @@ #define _1 0x05 #define GX2_COMP_SEL(c0, c1, c2, c3) (((c0) << 24) | ((c1) << 16) | ((c2) << 8) | (c3)) -#define COLOR_ARGB(r, g, b, a) (((u32)(a) << 24) | ((u32)(r) << 16) | ((u32)(g) << 8) | ((u32)(b) << 0)) -#define COLOR_RGBA(r, g, b, a) (((u32)(r) << 24) | ((u32)(g) << 16) | ((u32)(b) << 8) | ((u32)(a) << 0)) +#define COLOR_ARGB(r, g, b, a) (((uint32_t)(a) << 24) | ((uint32_t)(r) << 16) | ((uint32_t)(g) << 8) | ((uint32_t)(b) << 0)) +#define COLOR_RGBA(r, g, b, a) (((uint32_t)(r) << 24) | ((uint32_t)(g) << 16) | ((uint32_t)(b) << 8) | ((uint32_t)(a) << 0)) typedef struct { @@ -70,8 +85,8 @@ typedef struct GX2_mat4x4 *ubo_mvp; void *input_ring_buffer; void *output_ring_buffer; - u32 input_ring_buffer_size; - u32 output_ring_buffer_size; + uint32_t input_ring_buffer_size; + uint32_t output_ring_buffer_size; int width; int height; diff --git a/gfx/drivers/gx2_gfx.c b/gfx/drivers/gx2_gfx.c index 48e9c6eca65c..573853c6cc23 100644 --- a/gfx/drivers/gx2_gfx.c +++ b/gfx/drivers/gx2_gfx.c @@ -19,9 +19,6 @@ #include #include -#include -#include - #include #include #include @@ -1016,8 +1013,8 @@ static void *gx2_init(const video_info_t *video, { unsigned i; float refresh_rate = 60.0f / 1.001f; - u32 size = 0; - u32 tmp = 0; + uint32_t size = 0; + uint32_t tmp = 0; void *wiiuinput = NULL; wiiu_video_t *wiiu = (wiiu_video_t*)calloc(1, sizeof(*wiiu)); settings_t *settings = config_get_ptr(); @@ -1039,9 +1036,9 @@ static void *gx2_init(const video_info_t *video, /* video initialize */ wiiu->cmd_buffer = MEM2_alloc(0x400000, 0x40); - u32 init_attributes[] = + uint32_t init_attributes[] = { - GX2_INIT_CMD_BUF_BASE, (u32)wiiu->cmd_buffer, + GX2_INIT_CMD_BUF_BASE, (uint32_t)wiiu->cmd_buffer, GX2_INIT_CMD_BUF_POOL_SIZE, 0x400000, GX2_INIT_ARGC, 0, GX2_INIT_ARGV, 0, @@ -1752,21 +1749,21 @@ static void gx2_update_uniform_block(wiiu_video_t *wiiu, *dst = wiiu->shader_preset->pass[pass].frame_count_mod ? frame_count % wiiu->shader_preset->pass[pass].frame_count_mod : frame_count; - *(u32 *)dst = __builtin_bswap32(*(u32 *)dst); + *(uint32_t *)dst = __builtin_bswap32(*(uint32_t *)dst); continue; } if (string_is_equal(id, "FrameDirection")) { *dst = frame_direction; - *(u32 *)dst = __builtin_bswap32(*(u32 *)dst); + *(uint32_t *)dst = __builtin_bswap32(*(uint32_t *)dst); continue; } if (string_is_equal(id, "Rotation")) { - *dst = rotation; - *(u32 *)dst = __builtin_bswap32(*(u32 *)dst); + *dst = rotation; + *(uint32_t *)dst = __builtin_bswap32(*(uint32_t *)dst); continue; } @@ -1863,8 +1860,8 @@ static void gx2_update_uniform_block(wiiu_video_t *wiiu, { if (string_is_equal(id, wiiu->shader_preset->parameters[k].id)) { - *dst = wiiu->shader_preset->parameters[k].current; - *(u32 *)dst = __builtin_bswap32(*(u32 *)dst); + *dst = wiiu->shader_preset->parameters[k].current; + *(uint32_t *)dst = __builtin_bswap32(*(uint32_t *)dst); break; } } @@ -1901,7 +1898,7 @@ static bool gx2_frame(void *data, const void *frame, if (wiiu->last_vsync >= last_vsync) { GX2WaitForVsync(); - wiiu->last_vsync = last_vsync + ms_to_ticks(17); + wiiu->last_vsync = last_vsync + OSMillisecondsToTicks(17); } else wiiu->last_vsync = last_vsync; diff --git a/gfx/drivers/gx2_shaders/bokeh.c b/gfx/drivers/gx2_shaders/bokeh.c index 050b4378adb3..8e025794c75c 100644 --- a/gfx/drivers/gx2_shaders/bokeh.c +++ b/gfx/drivers/gx2_shaders/bokeh.c @@ -16,15 +16,16 @@ #include #include #include -#include +#include +#include #include "gx2_shader_inl.h" #include "menu_shaders.h" -__attribute__((aligned(GX2_SHADER_ALIGNMENT))) +__attribute__((aligned(GX2_SHADER_PROGRAM_ALIGNMENT))) static struct { - u64 cf[32]; - u64 alu[16]; + uint64_t cf[32]; + uint64_t alu[16]; } vs_program = { { @@ -62,23 +63,23 @@ static struct }, }; -__attribute__((aligned(GX2_SHADER_ALIGNMENT))) +__attribute__((aligned(GX2_SHADER_PROGRAM_ALIGNMENT))) static struct { - u64 cf[32]; - u64 alu[70]; - u64 alu1[19]; - u64 alu2[31]; - u64 alu3[25]; - u64 alu4[31]; - u64 alu5[25]; - u64 alu6[31]; - u64 alu7[25]; - u64 alu8[31]; - u64 alu9[25]; - u64 alu10[31]; - u64 alu11[25]; - u64 alu12[17]; + uint64_t cf[32]; + uint64_t alu[70]; + uint64_t alu1[19]; + uint64_t alu2[31]; + uint64_t alu3[25]; + uint64_t alu4[31]; + uint64_t alu5[25]; + uint64_t alu6[31]; + uint64_t alu7[25]; + uint64_t alu8[31]; + uint64_t alu9[25]; + uint64_t alu10[31]; + uint64_t alu11[25]; + uint64_t alu12[17]; } ps_program = { { diff --git a/gfx/drivers/gx2_shaders/frame.c b/gfx/drivers/gx2_shaders/frame.c index ad9d1b416b04..09793fbb2ebb 100644 --- a/gfx/drivers/gx2_shaders/frame.c +++ b/gfx/drivers/gx2_shaders/frame.c @@ -16,15 +16,16 @@ #include #include #include -#include +#include +#include #include "gx2_shader_inl.h" #include "frame.h" -__attribute__((aligned(GX2_SHADER_ALIGNMENT))) +__attribute__((aligned(GX2_SHADER_PROGRAM_ALIGNMENT))) static struct { - u64 cf[32]; - u64 alu[18]; + uint64_t cf[32]; + uint64_t alu[18]; } vs_program = { { @@ -60,11 +61,11 @@ static struct } }; -__attribute__((aligned(GX2_SHADER_ALIGNMENT))) +__attribute__((aligned(GX2_SHADER_PROGRAM_ALIGNMENT))) static struct { - u64 cf[16]; - u64 tex[1 * 2]; + uint64_t cf[16]; + uint64_t tex[1 * 2]; } ps_program = { @@ -102,7 +103,7 @@ static GX2UniformBlock uniform_blocks[] = { }; static GX2UniformVar uniform_vars[] = { - {"global.MVP", GX2_SHADER_VAR_TYPE_MATRIX4X4, 1, 0, 0}, + {"global.MVP", GX2_SHADER_VAR_TYPE_FLOAT4X4, 1, 0, 0}, }; GX2Shader frame_shader = diff --git a/gfx/drivers/gx2_shaders/ribbon.c b/gfx/drivers/gx2_shaders/ribbon.c index 1cafaa5b7fa1..39c17bfcf3ed 100644 --- a/gfx/drivers/gx2_shaders/ribbon.c +++ b/gfx/drivers/gx2_shaders/ribbon.c @@ -16,15 +16,16 @@ #include #include #include -#include +#include +#include #include "gx2_shader_inl.h" #include "menu_shaders.h" -__attribute__((aligned(GX2_SHADER_ALIGNMENT))) +__attribute__((aligned(GX2_SHADER_PROGRAM_ALIGNMENT))) static struct { - u64 cf[32]; - u64 alu[123 + 51]; + uint64_t cf[32]; + uint64_t alu[123 + 51]; } vs_program = { { @@ -243,12 +244,12 @@ static struct } }; -__attribute__((aligned(GX2_SHADER_ALIGNMENT))) +__attribute__((aligned(GX2_SHADER_PROGRAM_ALIGNMENT))) static struct { - u64 cf[32]; - u64 alu[64-32]; - u64 tex[2 * 2]; + uint64_t cf[32]; + uint64_t alu[64-32]; + uint64_t tex[2 * 2]; } ps_program = { diff --git a/gfx/drivers/gx2_shaders/ribbon_simple.c b/gfx/drivers/gx2_shaders/ribbon_simple.c index 214f6ab3d2bd..738a30bf007c 100644 --- a/gfx/drivers/gx2_shaders/ribbon_simple.c +++ b/gfx/drivers/gx2_shaders/ribbon_simple.c @@ -16,15 +16,16 @@ #include #include #include -#include +#include +#include #include "gx2_shader_inl.h" #include "menu_shaders.h" -__attribute__((aligned(GX2_SHADER_ALIGNMENT))) +__attribute__((aligned(GX2_SHADER_PROGRAM_ALIGNMENT))) static struct { - u64 cf[32]; - u64 alu[88]; + uint64_t cf[32]; + uint64_t alu[88]; } vs_program = { { @@ -167,11 +168,11 @@ static struct }, }; -__attribute__((aligned(GX2_SHADER_ALIGNMENT))) +__attribute__((aligned(GX2_SHADER_PROGRAM_ALIGNMENT))) static struct { - u64 cf[32]; - u64 alu[3]; + uint64_t cf[32]; + uint64_t alu[3]; } ps_program = { { diff --git a/gfx/drivers/gx2_shaders/snow.c b/gfx/drivers/gx2_shaders/snow.c index 455facee0791..2387cd22a3b1 100644 --- a/gfx/drivers/gx2_shaders/snow.c +++ b/gfx/drivers/gx2_shaders/snow.c @@ -16,15 +16,16 @@ #include #include #include -#include +#include +#include #include "gx2_shader_inl.h" #include "menu_shaders.h" -__attribute__((aligned(GX2_SHADER_ALIGNMENT))) +__attribute__((aligned(GX2_SHADER_PROGRAM_ALIGNMENT))) static struct { - u64 cf[32]; - u64 alu[16]; + uint64_t cf[32]; + uint64_t alu[16]; } vs_program = { { @@ -62,27 +63,27 @@ static struct }, }; -__attribute__((aligned(GX2_SHADER_ALIGNMENT))) +__attribute__((aligned(GX2_SHADER_PROGRAM_ALIGNMENT))) static struct { - u64 cf[32]; - u64 alu[56]; - u64 alu1[27]; - u64 alu2[51]; - u64 alu3[27]; - u64 alu4[52]; - u64 alu5[27]; - u64 alu6[51]; - u64 alu7[27]; - u64 alu8[52]; - u64 alu9[27]; - u64 alu10[52]; - u64 alu11[27]; - u64 alu12[52]; - u64 alu13[27]; - u64 alu14[52]; - u64 alu15[27]; - u64 alu16[6]; + uint64_t cf[32]; + uint64_t alu[56]; + uint64_t alu1[27]; + uint64_t alu2[51]; + uint64_t alu3[27]; + uint64_t alu4[52]; + uint64_t alu5[27]; + uint64_t alu6[51]; + uint64_t alu7[27]; + uint64_t alu8[52]; + uint64_t alu9[27]; + uint64_t alu10[52]; + uint64_t alu11[27]; + uint64_t alu12[52]; + uint64_t alu13[27]; + uint64_t alu14[52]; + uint64_t alu15[27]; + uint64_t alu16[6]; } ps_program = { { diff --git a/gfx/drivers/gx2_shaders/snow_simple.c b/gfx/drivers/gx2_shaders/snow_simple.c index 7f6715f458ee..1ed7106fbc3d 100644 --- a/gfx/drivers/gx2_shaders/snow_simple.c +++ b/gfx/drivers/gx2_shaders/snow_simple.c @@ -16,15 +16,16 @@ #include #include #include -#include +#include +#include #include "gx2_shader_inl.h" #include "menu_shaders.h" -__attribute__((aligned(GX2_SHADER_ALIGNMENT))) +__attribute__((aligned(GX2_SHADER_PROGRAM_ALIGNMENT))) static struct { - u64 cf[32]; - u64 alu[16]; + uint64_t cf[32]; + uint64_t alu[16]; } vs_program = { { @@ -62,27 +63,27 @@ static struct }, }; -__attribute__((aligned(GX2_SHADER_ALIGNMENT))) +__attribute__((aligned(GX2_SHADER_PROGRAM_ALIGNMENT))) static struct { - u64 cf[32]; - u64 alu[56]; - u64 alu1[27]; - u64 alu2[51]; - u64 alu3[27]; - u64 alu4[52]; - u64 alu5[27]; - u64 alu6[51]; - u64 alu7[27]; - u64 alu8[52]; - u64 alu9[27]; - u64 alu10[52]; - u64 alu11[27]; - u64 alu12[52]; - u64 alu13[27]; - u64 alu14[52]; - u64 alu15[27]; - u64 alu16[6]; + uint64_t cf[32]; + uint64_t alu[56]; + uint64_t alu1[27]; + uint64_t alu2[51]; + uint64_t alu3[27]; + uint64_t alu4[52]; + uint64_t alu5[27]; + uint64_t alu6[51]; + uint64_t alu7[27]; + uint64_t alu8[52]; + uint64_t alu9[27]; + uint64_t alu10[52]; + uint64_t alu11[27]; + uint64_t alu12[52]; + uint64_t alu13[27]; + uint64_t alu14[52]; + uint64_t alu15[27]; + uint64_t alu16[6]; } ps_program = { { diff --git a/gfx/drivers/gx2_shaders/snowflake.c b/gfx/drivers/gx2_shaders/snowflake.c index b01bbcf1e6c9..7f66732590c7 100644 --- a/gfx/drivers/gx2_shaders/snowflake.c +++ b/gfx/drivers/gx2_shaders/snowflake.c @@ -16,15 +16,16 @@ #include #include #include -#include +#include +#include #include "gx2_shader_inl.h" #include "menu_shaders.h" -__attribute__((aligned(GX2_SHADER_ALIGNMENT))) +__attribute__((aligned(GX2_SHADER_PROGRAM_ALIGNMENT))) static struct { - u64 cf[32]; - u64 alu[16]; + uint64_t cf[32]; + uint64_t alu[16]; } vs_program = { { @@ -62,16 +63,16 @@ static struct }, }; -__attribute__((aligned(GX2_SHADER_ALIGNMENT))) +__attribute__((aligned(GX2_SHADER_PROGRAM_ALIGNMENT))) static struct { - u64 cf[32]; - u64 alu[120]; - u64 alu1[19]; - u64 alu2[1]; - u64 alu3[106]; - u64 alu4[19]; - u64 alu5[2]; + uint64_t cf[32]; + uint64_t alu[120]; + uint64_t alu1[19]; + uint64_t alu2[1]; + uint64_t alu3[106]; + uint64_t alu4[19]; + uint64_t alu5[2]; } ps_program = { { diff --git a/gfx/drivers/gx2_shaders/sprite.c b/gfx/drivers/gx2_shaders/sprite.c index 4d729c70b43c..c791d7cab962 100644 --- a/gfx/drivers/gx2_shaders/sprite.c +++ b/gfx/drivers/gx2_shaders/sprite.c @@ -16,15 +16,16 @@ #include #include #include -#include +#include +#include #include "gx2_shader_inl.h" #include "sprite.h" -__attribute__((aligned(GX2_SHADER_ALIGNMENT))) +__attribute__((aligned(GX2_SHADER_PROGRAM_ALIGNMENT))) static struct { - u64 cf[32]; - u64 alu[26]; + uint64_t cf[32]; + uint64_t alu[26]; } vs_program = { { @@ -71,12 +72,12 @@ static struct } }; -__attribute__((aligned(GX2_SHADER_ALIGNMENT))) +__attribute__((aligned(GX2_SHADER_PROGRAM_ALIGNMENT))) static struct { - u64 cf[32]; /* @0 */ - u64 alu[16]; /* @32 */ - u64 tex[1 * 2]; /* @48 */ + uint64_t cf[32]; /* @0 */ + uint64_t alu[16]; /* @32 */ + uint64_t tex[1 * 2]; /* @48 */ } ps_program = { { @@ -97,12 +98,12 @@ static struct } }; -__attribute__((aligned(GX2_SHADER_ALIGNMENT))) +__attribute__((aligned(GX2_SHADER_PROGRAM_ALIGNMENT))) static struct { - u64 cf[32]; /* @0 */ - u64 alu[80-32]; /* @32 */ - u64 tex[3 * 2]; /* @80 */ + uint64_t cf[32]; /* @0 */ + uint64_t alu[80-32]; /* @32 */ + uint64_t tex[3 * 2]; /* @80 */ } gs_program = { { @@ -175,11 +176,11 @@ static struct } }; -__attribute__((aligned(GX2_SHADER_ALIGNMENT))) +__attribute__((aligned(GX2_SHADER_PROGRAM_ALIGNMENT))) static struct { - u64 cf[16]; /* @0 */ - u64 vtx[3 * 2]; /* @16 */ + uint64_t cf[16]; /* @0 */ + uint64_t vtx[3 * 2]; /* @16 */ } gs_copy_program= { { diff --git a/gfx/drivers/gx2_shaders/sprite.h b/gfx/drivers/gx2_shaders/sprite.h index dfbf4a6f5676..2ece24298c6d 100644 --- a/gfx/drivers/gx2_shaders/sprite.h +++ b/gfx/drivers/gx2_shaders/sprite.h @@ -40,7 +40,7 @@ typedef struct float height; }coord; - u32 color; + uint32_t color; }sprite_vertex_t; extern GX2Shader sprite_shader; diff --git a/gfx/drivers/gx2_shaders/tex.c b/gfx/drivers/gx2_shaders/tex.c index 5a8b7ede357b..8c2f486df34b 100644 --- a/gfx/drivers/gx2_shaders/tex.c +++ b/gfx/drivers/gx2_shaders/tex.c @@ -16,15 +16,16 @@ #include #include #include -#include +#include +#include #include "gx2_shader_inl.h" #include "tex.h" -__attribute__((aligned(GX2_SHADER_ALIGNMENT))) +__attribute__((aligned(GX2_SHADER_PROGRAM_ALIGNMENT))) static struct { - u64 cf[32]; - u64 alu[16]; + uint64_t cf[32]; + uint64_t alu[16]; } vs_program = { { @@ -59,12 +60,12 @@ static struct } }; -__attribute__((aligned(GX2_SHADER_ALIGNMENT))) +__attribute__((aligned(GX2_SHADER_PROGRAM_ALIGNMENT))) static struct { - u64 cf[32]; - u64 alu[16]; - u64 tex[1 * 2]; + uint64_t cf[32]; + uint64_t alu[16]; + uint64_t tex[1 * 2]; } ps_program = { @@ -113,7 +114,7 @@ static GX2UniformBlock uniform_blocks[] = { }; static GX2UniformVar uniform_vars[] = { - {"global.MVP", GX2_SHADER_VAR_TYPE_MATRIX4X4, 1, 0, 0}, + {"global.MVP", GX2_SHADER_VAR_TYPE_FLOAT4X4, 1, 0, 0}, }; GX2Shader tex_shader = diff --git a/gfx/drivers_font_renderer/freetype.c b/gfx/drivers_font_renderer/freetype.c index 1e83a0895f83..e5ff62843f37 100644 --- a/gfx/drivers_font_renderer/freetype.c +++ b/gfx/drivers_font_renderer/freetype.c @@ -39,7 +39,7 @@ #endif #ifdef WIIU -#include +#include #endif #include FT_FREETYPE_H @@ -278,7 +278,7 @@ static void *font_renderer_ft_init(const char *font_path, float font_size) void* font_data = NULL; uint32_t font_data_size = 0; - if (!OSGetSharedData(SHARED_FONT_DEFAULT, 0, + if (!OSGetSharedData(OS_SHAREDDATATYPE_FONT_STANDARD, 0, &font_data, &font_data_size)) goto error; diff --git a/gfx/drivers_font_renderer/stb_unicode.c b/gfx/drivers_font_renderer/stb_unicode.c index 7ed6bd6c2d67..947e17b35fe2 100644 --- a/gfx/drivers_font_renderer/stb_unicode.c +++ b/gfx/drivers_font_renderer/stb_unicode.c @@ -22,7 +22,7 @@ #include #ifdef WIIU -#include +#include #endif #include "../font_driver.h" @@ -252,7 +252,7 @@ static void *font_renderer_stb_unicode_init(const char *font_path, float font_si if (!*font_path) { uint32_t size = 0; - if (!OSGetSharedData(SHARED_FONT_DEFAULT, 0, (void**)&self->font_data, &size)) + if (!OSGetSharedData(OS_SHAREDDATATYPE_FONT_STANDARD, 0, (void**)&self->font_data, &size)) goto error; } else diff --git a/input/drivers/wiiu_input.c b/input/drivers/wiiu_input.c index c26276ad8684..ae64ad42170d 100644 --- a/input/drivers/wiiu_input.c +++ b/input/drivers/wiiu_input.c @@ -21,7 +21,7 @@ #include #include -#include +#include #include #ifdef HAVE_CONFIG_H diff --git a/input/drivers_hid/wiiu_hid.c b/input/drivers_hid/wiiu_hid.c index 285bcb9e0a47..79b7e03778c0 100644 --- a/input/drivers_hid/wiiu_hid.c +++ b/input/drivers_hid/wiiu_hid.c @@ -16,7 +16,9 @@ #include #include "../include/wiiu/hid.h" -#include +#include +#include +#include #include /* TODO/FIXME - static globals */ @@ -397,7 +399,7 @@ static void wiiu_poll_adapters(wiiu_hid_t *hid) static wiiu_attach_event *wiiu_hid_synchronized_get_events_list(void) { - return (wiiu_attach_event *)SwapAtomic32((uint32_t *)&events.list, 0); + return (wiiu_attach_event *)OSSwapAtomic((uint32_t *)&events.list, 0); } static int wiiu_hid_polling_thread(int argc, const char **argv) @@ -408,6 +410,7 @@ static int wiiu_hid_polling_thread(int argc, const char **argv) { wiiu_handle_attach_events(hid, wiiu_hid_synchronized_get_events_list()); wiiu_poll_adapters(hid); + OSSleepTicks(OSMicrosecondsToTicks(500)); } return 0; @@ -479,10 +482,10 @@ static void wiiu_hid_stop_polling_thread(wiiu_hid_t *hid) static void wiiu_hid_synchronized_add_event(wiiu_attach_event *event) { - wiiu_attach_event *head = (wiiu_attach_event *)SwapAtomic32((uint32_t *)&events.list, 0); + wiiu_attach_event *head = (wiiu_attach_event *)OSSwapAtomic((uint32_t *)&events.list, 0); event->next = head; head = event; - SwapAtomic32((uint32_t *)&events.list, (uint32_t)head); + OSSwapAtomic((uint32_t *)&events.list, (uint32_t)head); } static void wiiu_hid_synchronized_add_to_adapters_list(wiiu_adapter_t *adapter) @@ -496,14 +499,14 @@ static void wiiu_hid_synchronized_add_to_adapters_list(wiiu_adapter_t *adapter) static void wiiu_hid_log_device(HIDDevice *device) { RARCH_LOG(" handle: %d\n", device->handle); - RARCH_LOG(" physical_device_inst: %d\n", device->physical_device_inst); + RARCH_LOG(" physical_device_inst: %d\n", device->physicalDeviceInst); RARCH_LOG(" vid: 0x%04x\n", SWAP_IF_BIG(device->vid)); RARCH_LOG(" pid: 0x%04x\n", SWAP_IF_BIG(device->pid)); - RARCH_LOG(" interface_index: %d\n", device->interface_index); - RARCH_LOG(" sub_class: %d\n", device->sub_class); + RARCH_LOG(" interface_index: %d\n", device->interfaceIndex); + RARCH_LOG(" sub_class: %d\n", device->subClass); RARCH_LOG(" protocol: %d\n", device->protocol); - RARCH_LOG(" max_packet_size_rx: %d\n", device->max_packet_size_rx); - RARCH_LOG(" max_packet_size_tx: %d\n", device->max_packet_size_tx); + RARCH_LOG(" max_packet_size_rx: %d\n", device->maxPacketSizeRx); + RARCH_LOG(" max_packet_size_tx: %d\n", device->maxPacketSizeTx); } static void wiiu_hid_get_device_name(HIDDevice *device, wiiu_attach_event *event) @@ -546,13 +549,13 @@ static wiiu_attach_event *wiiu_hid_new_attach_event(HIDDevice *device) event->handle = device->handle; event->vendor_id = device->vid; event->product_id = device->pid; - event->interface_index = device->interface_index; - event->is_keyboard = (device->sub_class == 1 + event->interface_index = device->interfaceIndex; + event->is_keyboard = (device->subClass == 1 && device->protocol == 1); - event->is_mouse = (device->sub_class == 1 + event->is_mouse = (device->subClass == 1 && device->protocol == 2); - event->max_packet_size_rx = device->max_packet_size_rx; - event->max_packet_size_tx = device->max_packet_size_tx; + event->max_packet_size_rx = device->maxPacketSizeRx; + event->max_packet_size_tx = device->maxPacketSizeTx; wiiu_hid_get_device_name(device, event); return event; @@ -832,6 +835,7 @@ static int32_t wiiu_hid_set_idle(void *data, uint8_t duration) return HIDSetIdle(adapter->handle, adapter->interface_index, + 0, // reportId? duration, NULL, NULL); } diff --git a/input/drivers_joypad/wiiu/kpad_driver.c b/input/drivers_joypad/wiiu/kpad_driver.c index a5c9da957b3e..8d7629a5a07a 100644 --- a/input/drivers_joypad/wiiu/kpad_driver.c +++ b/input/drivers_joypad/wiiu/kpad_driver.c @@ -173,37 +173,37 @@ static void kpad_register(unsigned channel, uint8_t device_type) } } -static void kpad_poll_one_channel(unsigned channel, KPADData *kpad) +static void kpad_poll_one_channel(unsigned channel, KPADStatus *kpad) { - kpad_register(channel, kpad->device_type); - switch (kpad->device_type) + kpad_register(channel, kpad->extensionType); + switch (kpad->extensionType) { case WIIMOTE_TYPE_PRO: - joypad_state.kpad.wiimotes[channel].button_state = kpad->classic.btns_h + joypad_state.kpad.wiimotes[channel].button_state = kpad->classic.hold & ~WIIU_PRO_BUTTON_MASK; pad_functions.set_axis_value(joypad_state.kpad.wiimotes[channel].analog_state, - WIIU_READ_STICK(kpad->classic.lstick_x), - WIIU_READ_STICK(kpad->classic.lstick_y), - WIIU_READ_STICK(kpad->classic.rstick_x), - WIIU_READ_STICK(kpad->classic.rstick_y), 0, 0); + WIIU_READ_STICK(kpad->classic.leftStick.x), + WIIU_READ_STICK(kpad->classic.leftStick.y), + WIIU_READ_STICK(kpad->classic.rightStick.x), + WIIU_READ_STICK(kpad->classic.rightStick.y), 0, 0); break; case WIIMOTE_TYPE_CLASSIC: - joypad_state.kpad.wiimotes[channel].button_state = kpad->classic.btns_h + joypad_state.kpad.wiimotes[channel].button_state = kpad->classic.hold & ~CLASSIC_BUTTON_MASK; pad_functions.set_axis_value(joypad_state.kpad.wiimotes[channel].analog_state, - WIIU_READ_STICK(kpad->classic.lstick_x), - WIIU_READ_STICK(kpad->classic.lstick_y), - WIIU_READ_STICK(kpad->classic.rstick_x), - WIIU_READ_STICK(kpad->classic.rstick_y), 0, 0); + WIIU_READ_STICK(kpad->classic.leftStick.x), + WIIU_READ_STICK(kpad->classic.leftStick.y), + WIIU_READ_STICK(kpad->classic.rightStick.x), + WIIU_READ_STICK(kpad->classic.rightStick.y), 0, 0); break; case WIIMOTE_TYPE_NUNCHUK: - joypad_state.kpad.wiimotes[channel].button_state = kpad->btns_h; + joypad_state.kpad.wiimotes[channel].button_state = kpad->hold; pad_functions.set_axis_value(joypad_state.kpad.wiimotes[channel].analog_state, - WIIU_READ_STICK(kpad->nunchuck.stick_x), - WIIU_READ_STICK(kpad->nunchuck.stick_y), 0, 0, 0, 0); + WIIU_READ_STICK(kpad->nunchuck.stick.x), + WIIU_READ_STICK(kpad->nunchuck.stick.y), 0, 0, 0, 0); break; case WIIMOTE_TYPE_WIIPLUS: - joypad_state.kpad.wiimotes[channel].button_state = kpad->btns_h; + joypad_state.kpad.wiimotes[channel].button_state = kpad->hold; pad_functions.set_axis_value(joypad_state.kpad.wiimotes[channel].analog_state, 0, 0, 0, 0, 0, 0); break; @@ -226,7 +226,7 @@ static void kpad_deregister(unsigned channel) static void kpad_poll(void) { - KPADData kpad; + KPADStatus kpad; unsigned channel; int32_t result = 0; @@ -248,7 +248,7 @@ static void kpad_poll(void) /* Several reads when a device is connected or an attachment added give */ /* bogus results, try to weed them out */ - if (kpad.wpad_error || kpad.device_type == 255) + if (kpad.error || kpad.extensionType == 255) continue; kpad_poll_one_channel(channel, &kpad); diff --git a/input/include/wiiu/hid.h b/input/include/wiiu/hid.h index f4833c7c3bb1..5767f8f522da 100644 --- a/input/include/wiiu/hid.h +++ b/input/include/wiiu/hid.h @@ -19,6 +19,9 @@ #include "hid_types.h" #include "input.h" +#include +#include +#include #define DEVICE_UNUSED 0 #define DEVICE_USED 1 diff --git a/input/include/wiiu/input.h b/input/include/wiiu/input.h index e0c36d2b9edf..bae638795908 100644 --- a/input/include/wiiu/input.h +++ b/input/include/wiiu/input.h @@ -24,12 +24,12 @@ #include "hid_types.h" #include "../gamepad.h" -#include -#include #include -#include #include +#include +#include + #include "../../connect/joypad_connection.h" #include "../../../retroarch.h" #include "../../../verbosity.h" diff --git a/libretro-common/features/features_cpu.c b/libretro-common/features/features_cpu.c index 98b85024d9db..cad2e193d043 100644 --- a/libretro-common/features/features_cpu.c +++ b/libretro-common/features/features_cpu.c @@ -92,7 +92,7 @@ #endif #ifdef WIIU -#include +#include #endif #if defined(HAVE_LIBNX) @@ -231,7 +231,7 @@ retro_time_t cpu_features_get_time_usec(void) #elif defined(GEKKO) return ticks_to_microsecs(gettime()); #elif defined(WIIU) - return ticks_to_us(OSGetSystemTime()); + return OSTicksToMicroseconds(OSGetSystemTime()); #elif defined(SWITCH) || defined(HAVE_LIBNX) return (svcGetSystemTick() * 10) / 192; #elif defined(_3DS) diff --git a/libretro-common/include/net/net_compat.h b/libretro-common/include/net/net_compat.h index 05970a79d1ba..079f310207e6 100644 --- a/libretro-common/include/net/net_compat.h +++ b/libretro-common/include/net/net_compat.h @@ -350,8 +350,6 @@ static INLINE bool isagain(int val) return (sys_net_errno == SYS_NET_EAGAIN) || (sys_net_errno == SYS_NET_EWOULDBLOCK); #elif defined(VITA) return (val == SCE_NET_ERROR_EAGAIN) || (val == SCE_NET_ERROR_EWOULDBLOCK); -#elif defined(WIIU) - return (val == -1) && (socketlasterr() == SO_SUCCESS || socketlasterr() == SO_EWOULDBLOCK); #elif defined(GEKKO) return (-val == EAGAIN); #else @@ -367,8 +365,6 @@ static INLINE bool isinprogress(int val) return (sys_net_errno == SYS_NET_EINPROGRESS); #elif defined(VITA) return (val == SCE_NET_ERROR_EINPROGRESS); -#elif defined(WIIU) - return (val == -1) && (socketlasterr() == SO_EINPROGRESS); #elif defined(GEKKO) return (-val == EINPROGRESS); #else diff --git a/libretro-common/include/retro_timers.h b/libretro-common/include/retro_timers.h index 96041255a3f1..2efe851b10eb 100644 --- a/libretro-common/include/retro_timers.h +++ b/libretro-common/include/retro_timers.h @@ -32,7 +32,7 @@ #elif defined(GEKKO) || defined(__PSL1GHT__) || defined(__QNX__) #include #elif defined(WIIU) -#include +#include #elif defined(PSP) #include #elif defined(VITA) @@ -99,7 +99,7 @@ static int nanosleepDOS(const struct timespec *rqtp, struct timespec *rmtp) #elif defined(GEKKO) || defined(__PSL1GHT__) || defined(__QNX__) #define retro_sleep(msec) (usleep(1000 * (msec))) #elif defined(WIIU) -#define retro_sleep(msec) (OSSleepTicks(ms_to_ticks((msec)))) +#define retro_sleep(msec) (OSSleepTicks(OSMillisecondsToTicks((msec)))) #elif defined(EMSCRIPTEN) #define retro_sleep(msec) (emscripten_sleep(msec)) #else diff --git a/libretro-common/net/net_compat.c b/libretro-common/net/net_compat.c index e291bbee90c2..d1becb5753f9 100644 --- a/libretro-common/net/net_compat.c +++ b/libretro-common/net/net_compat.c @@ -233,28 +233,6 @@ int inet_pton(int af, const char *src, void *dst) return 0; } -#elif defined(WIIU) -#include - -static int _net_compat_thread_entry(int argc, const char **argv) -{ - void *buf = memalign(128, WIIU_RCVBUF + WIIU_SNDBUF); - - if (!buf) - return -1; - - somemopt(1, buf, WIIU_RCVBUF + WIIU_SNDBUF, 0); - - free(buf); - - return 0; -} - -static void _net_compat_thread_cleanup(OSThread *thread, void *stack) -{ - free(stack); -} - #elif defined(_3DS) #include #include <3ds/types.h> @@ -568,36 +546,6 @@ bool network_init(void) initialized = true; } - return true; -#elif defined(WIIU) - static OSThread net_compat_thread; - static bool initialized = false; - - if (!initialized) - { - void *stack = malloc(0x1000); - - if (!stack) - return false; - - socket_lib_init(); - - if (!OSCreateThread(&net_compat_thread, _net_compat_thread_entry, - 0, NULL, (void*)((size_t)stack + 0x1000), 0x1000, 3, - OS_THREAD_ATTRIB_AFFINITY_ANY)) - { - free(stack); - - return false; - } - - OSSetThreadName(&net_compat_thread, "Network compat thread"); - OSSetThreadDeallocator(&net_compat_thread, _net_compat_thread_cleanup); - OSResumeThread(&net_compat_thread); - - initialized = true; - } - return true; #elif defined(_3DS) static bool initialized = false; diff --git a/libretro-common/net/net_socket.c b/libretro-common/net/net_socket.c index 039a0b670ed5..50308fedc386 100644 --- a/libretro-common/net/net_socket.c +++ b/libretro-common/net/net_socket.c @@ -212,7 +212,7 @@ int socket_close(int fd) #if defined(_WIN32) && !defined(_XBOX360) /* WinSock has headers from the stone age. */ return closesocket(fd); -#elif defined(__PS3__) || defined(WIIU) +#elif defined(__PS3__) return socketclose(fd); #elif defined(VITA) return sceNetSocketClose(fd); @@ -691,25 +691,6 @@ int socket_connect(int fd, void *data) { struct addrinfo *addr = (struct addrinfo*)data; -#ifdef WIIU - { - int op = 1; - - setsockopt(fd, SOL_SOCKET, SO_WINSCALE, &op, sizeof(op)); - - if (addr->ai_socktype == SOCK_STREAM) - { - int recvsz = WIIU_RCVBUF; - int sendsz = WIIU_SNDBUF; - - setsockopt(fd, SOL_SOCKET, SO_TCPSACK, &op, sizeof(op)); - setsockopt(fd, SOL_SOCKET, SO_RUSRBUF, &op, sizeof(op)); - setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &recvsz, sizeof(recvsz)); - setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &sendsz, sizeof(sendsz)); - } - } -#endif - return connect(fd, addr->ai_addr, addr->ai_addrlen); } @@ -721,25 +702,6 @@ bool socket_connect_with_timeout(int fd, void *data, int timeout) if (!socket_nonblock(fd)) return false; -#ifdef WIIU - { - int op = 1; - - setsockopt(fd, SOL_SOCKET, SO_WINSCALE, &op, sizeof(op)); - - if (addr->ai_socktype == SOCK_STREAM) - { - int recvsz = WIIU_RCVBUF; - int sendsz = WIIU_SNDBUF; - - setsockopt(fd, SOL_SOCKET, SO_TCPSACK, &op, sizeof(op)); - setsockopt(fd, SOL_SOCKET, SO_RUSRBUF, &op, sizeof(op)); - setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &recvsz, sizeof(recvsz)); - setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &sendsz, sizeof(sendsz)); - } - } -#endif - res = connect(fd, addr->ai_addr, addr->ai_addrlen); if (res) { @@ -764,12 +726,6 @@ bool socket_connect_with_timeout(int fd, void *data, int timeout) /* libctru getsockopt does not return expected value */ if ((connect(fd, addr->ai_addr, addr->ai_addrlen) < 0) && errno != EISCONN) return false; -#elif defined(WIIU) - /* On WiiU, getsockopt() returns -1 and sets lastsocketerr() (Wii's - * equivalent to errno) to 16. */ - if ((connect(fd, addr->ai_addr, addr->ai_addrlen) == -1) - && socketlasterr() != SO_EISCONN) - return false; #else { int error = -1; diff --git a/menu/menu_driver.c b/menu/menu_driver.c index 569bfe757f8e..9c20c858c2e2 100644 --- a/menu/menu_driver.c +++ b/menu/menu_driver.c @@ -1,8084 +1,8084 @@ -/* RetroArch - A frontend for libretro. - * Copyright (C) 2011-2021 - Daniel De Matteis - * Copyright (C) 2014-2017 - Jean-André Santoni - * Copyright (C) 2016-2019 - Andrés Suárez - * Copyright (C) 2016-2019 - Brad Parker - * - * RetroArch is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with RetroArch. - * If not, see . - */ - -#if defined(HAVE_CONFIG_H) -#include "../config.h" -#endif - -#include -#include -#include -#include -#include -#include -#include -#include