From a4d745a471d002c612d6208de70e1189db43723f Mon Sep 17 00:00:00 2001 From: aliaspider Date: Thu, 27 Oct 2016 01:34:10 +0100 Subject: [PATCH] preliminary port to the wiiu platform --- Makefile.wiiu | 166 +++ config.def.h | 9 + configuration.c | 6 + frontend/drivers/platform_wiiu.c | 309 +++++ gfx/drivers/wiiu_gfx.c | 368 ++++++ gfx/video_driver.c | 3 + gfx/video_driver.h | 1 + input/drivers/nullinput.c | 9 + input/drivers/wiiu_input.c | 192 ++++ input/drivers_joypad/wiiu_joypad.c | 194 ++++ input/input_autodetect_builtin.c | 27 + input/input_driver.c | 7 +- input/input_driver.h | 1 + input/input_joypad_driver.c | 3 + input/input_joypad_driver.h | 1 + libretro-common/features/features_cpu.c | 6 + libretro-common/include/memmap.h | 2 +- libretro-common/include/retro_miscellaneous.h | 6 +- wiiu/common/common.h | 36 + wiiu/common/fs_defs.h | 62 + wiiu/common/os_defs.h | 25 + wiiu/common/types.h | 7 + wiiu/dynamic_libs/ax_functions.c | 74 ++ wiiu/dynamic_libs/ax_functions.h | 59 + wiiu/dynamic_libs/fs_functions.c | 120 ++ wiiu/dynamic_libs/fs_functions.h | 87 ++ wiiu/dynamic_libs/gx2_functions.c | 162 +++ wiiu/dynamic_libs/gx2_functions.h | 205 ++++ wiiu/dynamic_libs/gx2_types.h | 699 +++++++++++ wiiu/dynamic_libs/os_functions.c | 166 +++ wiiu/dynamic_libs/os_functions.h | 130 +++ wiiu/dynamic_libs/padscore_functions.c | 50 + wiiu/dynamic_libs/padscore_functions.h | 122 ++ wiiu/dynamic_libs/socket_functions.c | 82 ++ wiiu/dynamic_libs/socket_functions.h | 95 ++ wiiu/dynamic_libs/sys_functions.c | 40 + wiiu/dynamic_libs/sys_functions.h | 42 + wiiu/dynamic_libs/vpad_functions.c | 39 + wiiu/dynamic_libs/vpad_functions.h | 102 ++ wiiu/fs/fs_utils.c | 182 +++ wiiu/fs/fs_utils.h | 23 + wiiu/fs/sd_fat_devoptab.c | 1019 +++++++++++++++++ wiiu/fs/sd_fat_devoptab.h | 38 + wiiu/link.ld | 40 + wiiu/net.sh | 2 + wiiu/system/memory.c | 198 ++++ wiiu/system/memory.h | 42 + wiiu/utils/utils.h | 47 + wiiu/wiiload.py | 43 + wiiu/wiiu_dbg.h | 26 + 50 files changed, 5370 insertions(+), 4 deletions(-) create mode 100644 Makefile.wiiu create mode 100644 frontend/drivers/platform_wiiu.c create mode 100644 gfx/drivers/wiiu_gfx.c create mode 100644 input/drivers/wiiu_input.c create mode 100644 input/drivers_joypad/wiiu_joypad.c create mode 100644 wiiu/common/common.h create mode 100644 wiiu/common/fs_defs.h create mode 100644 wiiu/common/os_defs.h create mode 100644 wiiu/common/types.h create mode 100644 wiiu/dynamic_libs/ax_functions.c create mode 100644 wiiu/dynamic_libs/ax_functions.h create mode 100644 wiiu/dynamic_libs/fs_functions.c create mode 100644 wiiu/dynamic_libs/fs_functions.h create mode 100644 wiiu/dynamic_libs/gx2_functions.c create mode 100644 wiiu/dynamic_libs/gx2_functions.h create mode 100644 wiiu/dynamic_libs/gx2_types.h create mode 100644 wiiu/dynamic_libs/os_functions.c create mode 100644 wiiu/dynamic_libs/os_functions.h create mode 100644 wiiu/dynamic_libs/padscore_functions.c create mode 100644 wiiu/dynamic_libs/padscore_functions.h create mode 100644 wiiu/dynamic_libs/socket_functions.c create mode 100644 wiiu/dynamic_libs/socket_functions.h create mode 100644 wiiu/dynamic_libs/sys_functions.c create mode 100644 wiiu/dynamic_libs/sys_functions.h create mode 100644 wiiu/dynamic_libs/vpad_functions.c create mode 100644 wiiu/dynamic_libs/vpad_functions.h create mode 100644 wiiu/fs/fs_utils.c create mode 100644 wiiu/fs/fs_utils.h create mode 100644 wiiu/fs/sd_fat_devoptab.c create mode 100644 wiiu/fs/sd_fat_devoptab.h create mode 100644 wiiu/link.ld create mode 100755 wiiu/net.sh create mode 100644 wiiu/system/memory.c create mode 100644 wiiu/system/memory.h create mode 100644 wiiu/utils/utils.h create mode 100755 wiiu/wiiload.py create mode 100644 wiiu/wiiu_dbg.h diff --git a/Makefile.wiiu b/Makefile.wiiu new file mode 100644 index 0000000000..62f0c303d2 --- /dev/null +++ b/Makefile.wiiu @@ -0,0 +1,166 @@ +TARGET := retroarch_wiiu +DEBUG = 0 +GRIFFIN_BUILD = 0 +WHOLE_ARCHIVE_LINK = 0 + +OBJ := +OBJ += wiiu/dynamic_libs/ax_functions.o +OBJ += wiiu/dynamic_libs/os_functions.o +OBJ += wiiu/dynamic_libs/sys_functions.o +OBJ += wiiu/fs/sd_fat_devoptab.o +OBJ += wiiu/dynamic_libs/fs_functions.o +OBJ += wiiu/dynamic_libs/padscore_functions.o +OBJ += wiiu/dynamic_libs/vpad_functions.o +OBJ += wiiu/system/memory.o +OBJ += wiiu/dynamic_libs/gx2_functions.o +OBJ += wiiu/dynamic_libs/socket_functions.o +OBJ += wiiu/fs/fs_utils.o + +DEFINES := + +ifeq ($(GRIFFIN_BUILD), 1) + OBJ += griffin/griffin.o + DEFINES += -DHAVE_GRIFFIN=1 -DHAVE_MENU -DHAVE_RGUI -DHAVE_LIBRETRODB + DEFINES += -DHAVE_ZLIB -DHAVE_RPNG -DHAVE_RJPEG -DHAVE_RBMP -DHAVE_RTGA -DWANT_ZLIB +# DEFINES += -DHAVE_XMB -DHAVE_MATERIALUI +else + HAVE_MENU_COMMON = 1 + HAVE_RTGA = 1 + HAVE_RPNG = 1 + HAVE_RJPEG = 1 + HAVE_RBMP = 1 + HAVE_RGUI = 1 + HAVE_ZLIB = 1 + HAVE_7ZIP = 1 + HAVE_BUILTINZLIB = 1 + HAVE_LIBRETRODB = 1 + HAVE_ZARCH = 0 + HAVE_MATERIALUI = 0 + HAVE_XMB = 0 + + include Makefile.common + BLACKLIST := + BLACKLIST += input/input_overlay.o + BLACKLIST += tasks/task_overlay.o + OBJ := $(filter-out $(BLACKLIST),$(OBJ)) + + OBJ += gfx/drivers/wiiu_gfx.o +# OBJ += gfx/drivers_font/wiiu_font.o +# OBJ += menu/drivers_display/menu_display_wiiu.o + OBJ += input/drivers/wiiu_input.o + OBJ += input/drivers_joypad/wiiu_joypad.o +# OBJ += audio/drivers/wiiu_audio.o + OBJ += frontend/drivers/platform_wiiu.o + OBJ += gfx/video_filters/2xsai.o + OBJ += gfx/video_filters/super2xsai.o + OBJ += gfx/video_filters/supereagle.o + OBJ += gfx/video_filters/2xbr.o + OBJ += gfx/video_filters/darken.o + OBJ += gfx/video_filters/epx.o + OBJ += gfx/video_filters/scale2x.o + OBJ += gfx/video_filters/blargg_ntsc_snes.o + OBJ += gfx/video_filters/lq2x.o + OBJ += gfx/video_filters/phosphor2x.o + OBJ += audio/audio_filters/echo.o + OBJ += audio/audio_filters/eq.o + OBJ += audio/audio_filters/chorus.o + OBJ += audio/audio_filters/iir.o + OBJ += audio/audio_filters/panning.o + OBJ += audio/audio_filters/phaser.o + OBJ += audio/audio_filters/reverb.o + OBJ += audio/audio_filters/wahwah.o +endif + + +ifeq ($(strip $(DEVKITPPC)),) +$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") +endif +ifeq ($(strip $(DEVKITPRO)),) +$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=devkitPRO") +endif +export PATH := $(PATH):$(DEVKITPPC)/bin:$(PORTLIBS)/bin +export LIBOGC_INC := $(DEVKITPRO)/libogc/include +export LIBOGC_LIB := $(DEVKITPRO)/libogc/lib/wii +export PORTLIBS := $(DEVKITPRO)/portlibs/ppc + +PREFIX := powerpc-eabi- + +CC := $(PREFIX)gcc +CXX := $(PREFIX)g++ +AS := $(PREFIX)as +AR := $(PREFIX)ar +OBJCOPY := $(PREFIX)objcopy +STRIP := $(PREFIX)strip +NM := $(PREFIX)nm +LD := $(CXX) + + +INCDIRS := -I. -Ideps/zlib -Ideps/7zip -Ilibretro-common/include -Iwiiu -I$(LIBOGC_INC) +LIBDIRS := -L. + +CFLAGS := -mrvl -mcpu=750 -meabi -mhard-float +LDFLAGS := +#LDFLAGS := $(CFLAGS) + +ifeq ($(DEBUG), 1) + CFLAGS += -O0 -g +else + CFLAGS += -O3 +endif + +ASFLAGS := $(CFLAGS) -mregnames + +CFLAGS += -ffast-math -Werror=implicit-function-declaration +#CFLAGS += -fomit-frame-pointer -mword-relocations +#CFLAGS += -Wall +CFLAGS += -DWIIU +CFLAGS += -DHAVE_MAIN +CFLAGS += -DRARCH_INTERNAL -DRARCH_CONSOLE -DSINC_LOWEST_QUALITY +CFLAGS += -DHAVE_FILTERS_BUILTIN $(DEFINES) + +ifeq ($(WHOLE_ARCHIVE_LINK), 1) + WHOLE_START := -Wl,--whole-archive + WHOLE_END := -Wl,--no-whole-archive +endif + + +CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11 + +LDFLAGS += -nostartfiles -Wl,-Map,$(notdir $@).map,-wrap,malloc,-wrap,free,-wrap,memalign,-wrap,calloc,-wrap,realloc +LDFLAGS += -Wl,-wrap,malloc_usable_size,-wrap,_malloc_r,-wrap,_free_r,-wrap,_realloc_r,-wrap,_calloc_r,-wrap,_memalign_r +LDFLAGS += -Wl,-wrap,_malloc_usable_size_r,-wrap,valloc,-wrap,_valloc_r,-wrap,_pvalloc_r,--gc-sections + +CFLAGS += -std=gnu99 + +LIBS := $(WHOLE_START) -lretro_wiiu $(WHOLE_END) -lm + +all: $(TARGET) + +$(TARGET): $(TARGET).elf + +$(TARGET).elf: $(OBJ) libretro_wiiu.a + +%.o: %.cpp + $(CXX) -c -o $@ $< $(CXXFLAGS) $(INCDIRS) + +%.o: %.c + $(CC) -c -o $@ $< $(CFLAGS) $(INCDIRS) + +%.o: %.s + $(CC) -c -o $@ $< $(ASFLAGS) + +%.o: %.S + $(CC) -c -o $@ $< $(ASFLAGS) + +%.a: + $(AR) -rc $@ $^ + +$(TARGET).elf: wiiu/link.ld $(OBJ) +# $(LD) -T wiiu/link.ld $(OBJ) $(LDFLAGS) $(LIBDIRS) $(LIBS) -o $@ + $(LD) -n -T wiiu/link.ld $(OBJ) $(LDFLAGS) $(LIBDIRS) $(LIBS) -o $@ + +clean: + rm -f $(OBJ) + rm -f $(TARGET).elf + +.PHONY: $(BUILD) clean all diff --git a/config.def.h b/config.def.h index 75d7d782b7..867614efd5 100644 --- a/config.def.h +++ b/config.def.h @@ -34,6 +34,7 @@ enum VIDEO_SDL2, VIDEO_EXT, VIDEO_WII, + VIDEO_WIIU, VIDEO_XENON360, VIDEO_XDK_D3D, VIDEO_PSP1, @@ -85,6 +86,7 @@ enum INPUT_CTR, INPUT_XENON360, INPUT_WII, + INPUT_WIIU, INPUT_XINPUT, INPUT_UDEV, INPUT_LINUXRAW, @@ -96,6 +98,7 @@ enum JOYPAD_PS3, JOYPAD_XINPUT, JOYPAD_GX, + JOYPAD_WIIU, JOYPAD_XDK, JOYPAD_PSP, JOYPAD_CTR, @@ -146,6 +149,8 @@ enum #define VIDEO_DEFAULT_DRIVER VIDEO_GL #elif defined(GEKKO) #define VIDEO_DEFAULT_DRIVER VIDEO_WII +#elif defined(WIIU) +#define VIDEO_DEFAULT_DRIVER VIDEO_WIIU #elif defined(XENON) #define VIDEO_DEFAULT_DRIVER VIDEO_XENON360 #elif (defined(_XBOX1) || defined(_XBOX360)) && (defined(HAVE_D3D8) || defined(HAVE_D3D9)) @@ -250,6 +255,8 @@ enum #define INPUT_DEFAULT_DRIVER INPUT_CTR #elif defined(GEKKO) #define INPUT_DEFAULT_DRIVER INPUT_WII +#elif defined(WIIU) +#define INPUT_DEFAULT_DRIVER INPUT_WIIU #elif defined(HAVE_UDEV) #define INPUT_DEFAULT_DRIVER INPUT_UDEV #elif defined(__linux__) && !defined(ANDROID) @@ -276,6 +283,8 @@ enum #define JOYPAD_DEFAULT_DRIVER JOYPAD_XINPUT #elif defined(GEKKO) #define JOYPAD_DEFAULT_DRIVER JOYPAD_GX +#elif defined(WIIU) +#define JOYPAD_DEFAULT_DRIVER JOYPAD_WIIU #elif defined(_XBOX) #define JOYPAD_DEFAULT_DRIVER JOYPAD_XDK #elif defined(PSP) || defined(VITA) diff --git a/configuration.c b/configuration.c index 1b33e375d7..b1bdd94b3b 100644 --- a/configuration.c +++ b/configuration.c @@ -265,6 +265,8 @@ const char *config_get_default_video(void) return "drm"; case VIDEO_WII: return "gx"; + case VIDEO_WIIU: + return "gx2"; case VIDEO_XENON360: return "xenon360"; case VIDEO_XDK_D3D: @@ -340,6 +342,8 @@ const char *config_get_default_input(void) return "xinput"; case INPUT_WII: return "gx"; + case INPUT_WIIU: + return "wiiu"; case INPUT_LINUXRAW: return "linuxraw"; case INPUT_UDEV: @@ -374,6 +378,8 @@ const char *config_get_default_joypad(void) return "xinput"; case JOYPAD_GX: return "gx"; + case JOYPAD_WIIU: + return "wiiu"; case JOYPAD_XDK: return "xdk"; case JOYPAD_PSP: diff --git a/frontend/drivers/platform_wiiu.c b/frontend/drivers/platform_wiiu.c new file mode 100644 index 0000000000..1c3fbd2b79 --- /dev/null +++ b/frontend/drivers/platform_wiiu.c @@ -0,0 +1,309 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2014-2016 - Ali Bouhlel + * + * 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 . + */ + +#include +#include +#include +#include +#include + +#include + +#include + +#include "../frontend_driver.h" +#include "../frontend.h" +#include "../../configuration.h" +#include "../../verbosity.h" +#include "../../defaults.h" +#include "../../paths.h" +#include "retroarch.h" +#include "file_path_special.h" +#include "audio/audio_driver.h" + + +#include "tasks/tasks_internal.h" +#include "runloop.h" +#include "dynamic_libs/os_functions.h" +#include "dynamic_libs/fs_functions.h" +#include "dynamic_libs/gx2_functions.h" +#include "dynamic_libs/sys_functions.h" +#include "dynamic_libs/vpad_functions.h" +#include "dynamic_libs/padscore_functions.h" +#include "dynamic_libs/socket_functions.h" +#include "dynamic_libs/ax_functions.h" +#include "fs/fs_utils.h" +#include "fs/sd_fat_devoptab.h" +#include "system/memory.h" +#include "utils/logger.h" +#include "utils/utils.h" +#include "common/common.h" +#include + +#include "wiiu_dbg.h" + +#ifdef HAVE_MENU +#include "../../menu/menu_driver.h" +#endif + +static enum frontend_fork wiiu_fork_mode = FRONTEND_FORK_NONE; +static const char* elf_path_cst = "sd:/retroarch/retroarch.elf"; + +static void frontend_wiiu_get_environment_settings(int *argc, char *argv[], + void *args, void *params_data) +{ + (void)args; + DEBUG_LINE(); + + fill_pathname_basedir(g_defaults.dir.port, elf_path_cst, sizeof(g_defaults.dir.port)); + DEBUG_LINE(); + RARCH_LOG("port dir: [%s]\n", g_defaults.dir.port); + + fill_pathname_join(g_defaults.dir.core_assets, g_defaults.dir.port, + "downloads", sizeof(g_defaults.dir.core_assets)); + fill_pathname_join(g_defaults.dir.assets, g_defaults.dir.port, + "media", sizeof(g_defaults.dir.assets)); + fill_pathname_join(g_defaults.dir.core, g_defaults.dir.port, + "cores", sizeof(g_defaults.dir.core)); + fill_pathname_join(g_defaults.dir.core_info, g_defaults.dir.core, + "info", sizeof(g_defaults.dir.core_info)); + fill_pathname_join(g_defaults.dir.savestate, g_defaults.dir.core, + "savestates", sizeof(g_defaults.dir.savestate)); + fill_pathname_join(g_defaults.dir.sram, g_defaults.dir.core, + "savefiles", sizeof(g_defaults.dir.sram)); + fill_pathname_join(g_defaults.dir.system, g_defaults.dir.core, + "system", sizeof(g_defaults.dir.system)); + fill_pathname_join(g_defaults.dir.playlist, g_defaults.dir.core, + "playlists", sizeof(g_defaults.dir.playlist)); + fill_pathname_join(g_defaults.dir.menu_config, g_defaults.dir.port, + "config", sizeof(g_defaults.dir.menu_config)); + fill_pathname_join(g_defaults.dir.remap, g_defaults.dir.port, + "config/remaps", sizeof(g_defaults.dir.remap)); + fill_pathname_join(g_defaults.dir.video_filter, g_defaults.dir.port, + "filters", sizeof(g_defaults.dir.remap)); + fill_pathname_join(g_defaults.dir.database, g_defaults.dir.port, + "database/rdb", sizeof(g_defaults.dir.database)); + fill_pathname_join(g_defaults.dir.cursor, g_defaults.dir.port, + "database/cursors", sizeof(g_defaults.dir.cursor)); + fill_pathname_join(g_defaults.path.config, g_defaults.dir.port, + file_path_str(FILE_PATH_MAIN_CONFIG), sizeof(g_defaults.path.config)); +} + +static void frontend_wiiu_deinit(void *data) +{ + (void)data; +} + +static void frontend_wiiu_shutdown(bool unused) +{ + (void)unused; +} + +static void frontend_wiiu_init(void *data) +{ + (void)data; + DEBUG_LINE(); + verbosity_enable(); + DEBUG_LINE(); +} + + +static int frontend_wiiu_get_rating(void) +{ + return 10; +} + +enum frontend_architecture frontend_wiiu_get_architecture(void) +{ + return FRONTEND_ARCH_PPC; +} + +static int frontend_wiiu_parse_drive_list(void *data) +{ + file_list_t *list = (file_list_t*)data; + + if (!list) + return -1; + + menu_entries_append_enum(list, + "sd:/", "", MSG_UNKNOWN, FILE_TYPE_DIRECTORY, 0, 0); + + return 0; +} + +frontend_ctx_driver_t frontend_ctx_wiiu = { + frontend_wiiu_get_environment_settings, + frontend_wiiu_init, + frontend_wiiu_deinit, + NULL, /* exitspawn */ + NULL, /* process_args */ + NULL, /* exec */ + NULL, /* set_fork */ + frontend_wiiu_shutdown, + NULL, /* get_name */ + NULL, /* get_os */ + frontend_wiiu_get_rating, + NULL, /* load_content */ + frontend_wiiu_get_architecture, + NULL, /* get_powerstate */ + frontend_wiiu_parse_drive_list, + NULL, /* get_mem_total */ + NULL, /* get_mem_free */ + NULL, /* install_signal_handler */ + NULL, /* get_signal_handler_state */ + NULL, /* set_signal_handler_state */ + NULL, /* destroy_signal_handler_state */ + NULL, /* attach_console */ + NULL, /* detach_console */ + "wiiu", +}; + +static int log_socket = -1; +static volatile int log_lock = 0; + +void log_init(const char * ipString) +{ + log_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + if (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 = 4405; + inet_aton(ipString, &connect_addr.sin_addr); + + if(connect(log_socket, (struct sockaddr*)&connect_addr, sizeof(connect_addr)) < 0) + { + socketclose(log_socket); + log_socket = -1; + } +} + +void log_deinit(void) +{ + if(log_socket >= 0) + { + socketclose(log_socket); + log_socket = -1; + } +} +static int log_write(struct _reent *r, int fd, const char *ptr, size_t len) +{ + if(log_socket < 0) + return len; + + while(log_lock) + OSSleepTicks(((BUS_SPEED/4)) / 1000); + log_lock = 1; + + int ret; + while (len > 0) { + int block = len < 1400 ? len : 1400; // take max 1400 bytes per UDP packet + ret = send(log_socket, ptr, block, 0); + if(ret < 0) + break; + + len -= ret; + ptr += ret; + } + + log_lock = 0; + + return len; +} + +static devoptab_t dotab_stdout = { + "stdout", // device name + 0, // size of file structure + NULL, // device open + NULL, // device close + log_write, // device write + NULL, // device read + NULL, // device seek + NULL, // device fstat + NULL, // device stat + NULL, // device link + NULL, // device unlink + NULL, // device chdir + NULL, // device rename + NULL, // device mkdir + 0, // dirStateSize + NULL, // device diropen_r + NULL, // device dirreset_r + NULL, // device dirnext_r + NULL, // device dirclose_r + NULL, // device statvfs_r + NULL, // device ftrunctate_r + NULL, // device fsync_r + NULL, // deviceData; +}; + +int __entry_menu(int argc, char **argv) +{ + InitOSFunctionPointers(); + InitSocketFunctionPointers(); + + log_init("10.42.0.1"); + + devoptab_list[STD_OUT] = &dotab_stdout; + devoptab_list[STD_ERR] = &dotab_stdout; + InitFSFunctionPointers(); + InitVPadFunctionPointers(); + memoryInitialize(); + mount_sd_fat("sd"); + VPADInit(); + OSScreenInit(); + + int vpadError = -1; + VPADData vpad; + + verbosity_enable(); + DEBUG_VAR(argc); + DEBUG_STR(argv[0]); + DEBUG_STR(argv[1]); +#if 0 + int argc_ = 2; + char* argv_[] = {"retroarch.elf", "sd:/zz.gb"}; + rarch_main(argc_, argv_, NULL); +#else + rarch_main(argc, argv, NULL); +#endif + int frames = 0; + do + { + unsigned sleep_ms = 0; + int ret = runloop_iterate(&sleep_ms); + + if (ret == 1 && sleep_ms > 0) + retro_sleep(sleep_ms); + task_queue_ctl(TASK_QUEUE_CTL_CHECK, NULL); + if (ret == -1) + break; + + }while(1); +// }while(frames++ < 300); + + main_exit(NULL); + + + printf("Unmount SD\n"); + unmount_sd_fat("sd"); + printf("Release memory\n"); + memoryRelease(); + log_deinit(); + + return 0; +} diff --git a/gfx/drivers/wiiu_gfx.c b/gfx/drivers/wiiu_gfx.c new file mode 100644 index 0000000000..79822ddd71 --- /dev/null +++ b/gfx/drivers/wiiu_gfx.c @@ -0,0 +1,368 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2014-2016 - Ali Bouhlel + * + * 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 . + */ + +#include "../../driver.h" +#include "../../configuration.h" +#include "../../verbosity.h" + +#include "dynamic_libs/os_functions.h" +#include "system/memory.h" +#include "string.h" + +#include "wiiu_dbg.h" + +typedef struct +{ + void* screen_buffer0; + int screen_buffer0_size; + void* screen_buffer1; + int screen_buffer1_size; + int screen_buffer0_id; + int screen_buffer1_id; + struct + { + void* texture; + int tex_width; + int tex_height; + int width; + int height; + bool enable; + }menu; + + void* texture; + int tex_width; + int tex_height; + +}wiiu_video_t; + +static void *wiiu_gfx_init(const video_info_t *video, + const input_driver_t **input, void **input_data) +{ + *input = NULL; + *input_data = NULL; + + wiiu_video_t* wiiu = calloc(1, sizeof(*wiiu)); + if(!wiiu) + return NULL; + + wiiu->screen_buffer0_size = OSScreenGetBufferSizeEx(0); + wiiu->screen_buffer0 = MEM1_alloc(wiiu->screen_buffer0_size, 0x40); + wiiu->screen_buffer1_size = OSScreenGetBufferSizeEx(1); + wiiu->screen_buffer1 = MEM1_alloc(wiiu->screen_buffer1_size, 0x40); + + DEBUG_INT(wiiu->screen_buffer0_size); + DEBUG_INT(wiiu->screen_buffer1_size); + + OSScreenSetBufferEx(0, wiiu->screen_buffer0); + OSScreenSetBufferEx(1, wiiu->screen_buffer1); + OSScreenEnableEx(0, 1); + OSScreenEnableEx(1, 1); + OSScreenClearBufferEx(0, 0); + OSScreenClearBufferEx(1, 0); + + DCFlushRange(wiiu->screen_buffer0, wiiu->screen_buffer0_size); + DCFlushRange(wiiu->screen_buffer1, wiiu->screen_buffer1_size); + + OSScreenFlipBuffersEx(0); + wiiu->screen_buffer0_id = 0; + OSScreenFlipBuffersEx(1); + wiiu->screen_buffer1_id = 0; + + wiiu->menu.tex_width = 512; + wiiu->menu.tex_height = 512; + wiiu->menu.texture = malloc(wiiu->menu.tex_width * wiiu->menu.tex_height * sizeof(uint16_t)); + + wiiu->tex_width = video->input_scale * RARCH_SCALE_BASE;; + wiiu->tex_height = video->input_scale * RARCH_SCALE_BASE;; + wiiu->texture = malloc(wiiu->tex_width * wiiu->tex_height * sizeof(uint16_t)); + + + if (input && input_data) + { + void* wiiuinput = NULL; + wiiuinput = input_wiiu.init(); + *input = wiiuinput ? &input_wiiu : NULL; + *input_data = wiiuinput; + } + + DEBUG_LINE(); + + return wiiu; +} +static void wiiu_gfx_free(void *data) +{ + wiiu_video_t* wiiu = (wiiu_video_t*) data; + + if(!wiiu) + return; + + MEM1_free(wiiu->screen_buffer0); + MEM1_free(wiiu->screen_buffer1); + free(wiiu->menu.texture); + free(wiiu->texture); + free(wiiu); + DEBUG_LINE(); + +} + +static bool wiiu_gfx_frame(void *data, const void *frame, + unsigned width, unsigned height, uint64_t frame_count, + unsigned pitch, const char *msg) +{ + (void)frame; + (void)width; + (void)height; + (void)pitch; + (void)msg; + int i; + + wiiu_video_t* wiiu = (wiiu_video_t*) data; + + static int frames = 0; + char frames_str [512]; + snprintf(frames_str, sizeof(frames_str), "frames : %i", frames++); + + OSScreenClearBufferEx(1, 0); +// OSScreenPutFontEx(1, 0, 0, "Hello world on DRC!!!"); + + const uint16_t* src = (uint16_t*)wiiu->menu.texture; + uint32_t* dst = (uint32_t*)((uint8_t*)wiiu->screen_buffer1 + wiiu->screen_buffer1_id * wiiu->screen_buffer1_size / 2); +// for (i = 0; i < wiiu->menu.height; i++) +// { +// memcpy(dst, src, wiiu->menu.width * sizeof(uint16_t)); +// dst += 896; +// src += wiiu->menu.tex_width; +// } + + dst += 896 * (480 - wiiu->menu.height) / 2 + (896 - wiiu->menu.width) / 2; + int x, y; + for(y = 0; y < wiiu->menu.height; y++) + { + for(x = 0; x < wiiu->menu.width; x++) + { + int r = ((src[x] >> 12) & 0xF) << 4; + int g = ((src[x] >> 8) & 0xF) << 4; + int b = ((src[x] >> 4) & 0xF) << 4; +// r = 0; +// g = 0; +// b = 0; + dst[x] = (r << 0) | (b << 8) | (g << 16); + } + src += wiiu->menu.tex_width; + dst += 896; + } + + + + OSScreenPutFontEx(1, 0, 16, frames_str); + DCFlushRange(((uint8_t*)wiiu->screen_buffer1 + wiiu->screen_buffer1_id * wiiu->screen_buffer1_size / 2) + , wiiu->screen_buffer1_size / 2); + OSScreenFlipBuffersEx(1); + wiiu->screen_buffer1_id ^= 1; + + + + return true; +} + +static void wiiu_gfx_set_nonblock_state(void *data, bool toggle) +{ + (void)data; + (void)toggle; +} + +static bool wiiu_gfx_alive(void *data) +{ + (void)data; + return true; +} + +static bool wiiu_gfx_focus(void *data) +{ + (void)data; + return true; +} + +static bool wiiu_gfx_suppress_screensaver(void *data, bool enable) +{ + (void)data; + (void)enable; + return false; +} + +static bool wiiu_gfx_has_windowed(void *data) +{ + (void)data; + return true; +} + +static bool wiiu_gfx_set_shader(void *data, + enum rarch_shader_type type, const char *path) +{ + (void)data; + (void)type; + (void)path; + + return false; +} + +static void wiiu_gfx_set_rotation(void *data, + unsigned rotation) +{ + (void)data; + (void)rotation; +} + +static void wiiu_gfx_viewport_info(void *data, + struct video_viewport *vp) +{ + (void)data; + (void)vp; +} + +static bool wiiu_gfx_read_viewport(void *data, uint8_t *buffer) +{ + (void)data; + (void)buffer; + + return true; +} + +static uintptr_t wiiu_load_texture(void *video_data, void *data, + bool threaded, enum texture_filter_type filter_type) +{ + return 0; +} +static void wiiu_unload_texture(void *data, uintptr_t handle) +{ + +} +static void wiiu_set_filtering(void* data, unsigned index, bool smooth) +{ +} +static void wiiu_set_aspect_ratio(void* data, unsigned aspect_ratio_idx) +{ + +} +static void wiiu_apply_state_changes(void* data) +{ + +} + +static void wiiu_viewport_info(void* data, struct video_viewport* vp) +{ + vp->full_width = 800; + vp->full_height = 480; + vp->width = 800; + vp->height = 480; + vp->x = 0; + vp->y = 0; +} +static void wiiu_set_texture_frame(void* data, const void* frame, bool rgb32, + unsigned width, unsigned height, float alpha) +{ + int i; + wiiu_video_t* wiiu = (wiiu_video_t*) data; + if(!wiiu) + return; + + if(!frame || !width || !height) + return; + + if(width > wiiu->menu.tex_width) + width = wiiu->menu.tex_width; + if(height > wiiu->menu.tex_height) + height = wiiu->menu.tex_height; + + wiiu->menu.width = width; + wiiu->menu.height = height; + + const uint16_t* src = frame; + uint16_t* dst = (uint16_t*)wiiu->menu.texture; + for (i = 0; i < height; i++) + { + memcpy(dst, src, width * sizeof(uint16_t)); + dst += wiiu->menu.tex_width; + src += width; + } +} + +static void wiiu_set_texture_enable(void* data, bool state, bool full_screen) +{ + (void) full_screen; + wiiu_video_t* wiiu = (wiiu_video_t*) data; + wiiu->menu.enable = state; + +} + +static void wiiu_set_osd_msg(void *data, const char *msg, + const struct font_params *params, void *font) +{ +} + + + +static const video_poke_interface_t wiiu_poke_interface = +{ + wiiu_load_texture, + wiiu_unload_texture, + NULL, + wiiu_set_filtering, + NULL, /* get_video_output_size */ + NULL, /* get_video_output_prev */ + NULL, /* get_video_output_next */ + NULL, /* get_current_framebuffer */ + NULL, + wiiu_set_aspect_ratio, + wiiu_apply_state_changes, +#ifdef HAVE_MENU + wiiu_set_texture_frame, + wiiu_set_texture_enable, + wiiu_set_osd_msg, +#endif + NULL, + NULL, + NULL +}; + +static void wiiu_gfx_get_poke_interface(void *data, + const video_poke_interface_t **iface) +{ + (void)data; + *iface = &wiiu_poke_interface; +} + +video_driver_t video_wiiu = +{ + wiiu_gfx_init, + wiiu_gfx_frame, + wiiu_gfx_set_nonblock_state, + wiiu_gfx_alive, + wiiu_gfx_focus, + wiiu_gfx_suppress_screensaver, + wiiu_gfx_has_windowed, + wiiu_gfx_set_shader, + wiiu_gfx_free, + "gx2", + NULL, /* set_viewport */ + wiiu_gfx_set_rotation, + wiiu_gfx_viewport_info, + wiiu_gfx_read_viewport, + NULL, /* read_frame_raw */ +#ifdef HAVE_OVERLAY + NULL, /* overlay_interface */ +#endif + wiiu_gfx_get_poke_interface, +}; diff --git a/gfx/video_driver.c b/gfx/video_driver.c index ad1e2dddf1..a62c7e0a55 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -185,6 +185,9 @@ static const video_driver_t *video_drivers[] = { #ifdef GEKKO &video_gx, #endif +#ifdef WIIU + &video_wiiu, +#endif #ifdef HAVE_VG &video_vg, #endif diff --git a/gfx/video_driver.h b/gfx/video_driver.h index 49dd6767b4..3403136453 100644 --- a/gfx/video_driver.h +++ b/gfx/video_driver.h @@ -498,6 +498,7 @@ extern video_driver_t video_vita2d; extern video_driver_t video_ctr; extern video_driver_t video_d3d; extern video_driver_t video_gx; +extern video_driver_t video_wiiu; extern video_driver_t video_xenon360; extern video_driver_t video_xvideo; extern video_driver_t video_xdk_d3d; diff --git a/input/drivers/nullinput.c b/input/drivers/nullinput.c index ff5d2074d4..9ac42d0751 100644 --- a/input/drivers/nullinput.c +++ b/input/drivers/nullinput.c @@ -95,6 +95,14 @@ static bool nullinput_set_rumble(void *data, unsigned port, return false; } +static bool nullinput_keyboard_mapping_is_blocked(void *data) +{ + (void)data; + + return false; +} + + input_driver_t input_null = { nullinput_input_init, nullinput_input_poll, @@ -111,5 +119,6 @@ input_driver_t input_null = { nullinput_set_rumble, NULL, NULL, + nullinput_keyboard_mapping_is_blocked, NULL, }; diff --git a/input/drivers/wiiu_input.c b/input/drivers/wiiu_input.c new file mode 100644 index 0000000000..7d30907834 --- /dev/null +++ b/input/drivers/wiiu_input.c @@ -0,0 +1,192 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2014-2015 - Ali Bouhlel + * + * 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 . + */ + +#include +#include + +#include +#include + +#ifdef HAVE_CONFIG_H +#include "../../config.h" +#endif + +#include "../../configuration.h" +#include "../input_config.h" +#include "../input_joypad_driver.h" + +#include "wiiu_dbg.h" + +#define MAX_PADS 1 + +typedef struct wiiu_input +{ + bool blocked; + const input_device_driver_t *joypad; +} wiiu_input_t; + +uint64_t lifecycle_state; + +static void wiiu_input_poll(void *data) +{ + wiiu_input_t *wiiu = (wiiu_input_t*)data; + + if (wiiu->joypad) + wiiu->joypad->poll(); +} + +static int16_t wiiu_input_state(void *data, const struct retro_keybind **binds, + unsigned port, unsigned device, + unsigned idx, unsigned id) +{ + wiiu_input_t *wiiu = (wiiu_input_t*)data; + + if (port > 0) + return 0; + + switch (device) + { + case RETRO_DEVICE_JOYPAD: + if (binds[port][id].valid) + return input_joypad_pressed(wiiu->joypad, port, binds[port], id); + break; + case RETRO_DEVICE_ANALOG: + return input_joypad_analog(wiiu->joypad, port, idx, id, binds[port]); + } + + return 0; +} + +static void wiiu_input_free_input(void *data) +{ + wiiu_input_t *wiiu = (wiiu_input_t*)data; + + if (wiiu && wiiu->joypad) + wiiu->joypad->destroy(); + + free(data); +} + +static void* wiiu_input_initialize(void) +{ + settings_t *settings = config_get_ptr(); + wiiu_input_t *wiiu = (wiiu_input_t*)calloc(1, sizeof(*wiiu)); + if (!wiiu) + return NULL; + + DEBUG_STR(settings->input.joypad_driver); + wiiu->joypad = input_joypad_init_driver(settings->input.joypad_driver, wiiu); + + return wiiu; +} + +static bool wiiu_input_key_pressed(void *data, int key) +{ + settings_t *settings = config_get_ptr(); + wiiu_input_t *wiiu = (wiiu_input_t*)data; + int port = 0; + + if (settings->input.all_users_control_menu) + { + for (port = 0; port < MAX_USERS; port++) + if (settings->input.binds[0][key].valid && + input_joypad_pressed(wiiu->joypad, + port, settings->input.binds[0], key)) + return true; + } + else + if (settings->input.binds[0][key].valid && + input_joypad_pressed(wiiu->joypad, + 0, settings->input.binds[0], key)) + return true; + + return false; +} + +static bool wiiu_input_meta_key_pressed(void *data, int key) +{ + if (BIT64_GET(lifecycle_state, key)) + return true; + + return false; +} + +static uint64_t wiiu_input_get_capabilities(void *data) +{ + (void)data; + + return (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG); +} + +static const input_device_driver_t *wiiu_input_get_joypad_driver(void *data) +{ + wiiu_input_t *wiiu = (wiiu_input_t*)data; + if (wiiu) + return wiiu->joypad; + return NULL; +} + +static void wiiu_input_grab_mouse(void *data, bool state) +{ + (void)data; + (void)state; +} + +static bool wiiu_input_set_rumble(void *data, unsigned port, + enum retro_rumble_effect effect, uint16_t strength) +{ + (void)data; + (void)port; + (void)effect; + (void)strength; + + return false; +} + +static bool wiiu_input_keyboard_mapping_is_blocked(void *data) +{ + wiiu_input_t *wiiu = (wiiu_input_t*)data; + if (!wiiu) + return false; + return wiiu->blocked; +} + +static void wiiu_input_keyboard_mapping_set_block(void *data, bool value) +{ + wiiu_input_t *wiiu = (wiiu_input_t*)data; + if (!wiiu) + return; + wiiu->blocked = value; +} + +input_driver_t input_wiiu = { + wiiu_input_initialize, + wiiu_input_poll, + wiiu_input_state, + wiiu_input_key_pressed, + wiiu_input_meta_key_pressed, + wiiu_input_free_input, + NULL, + NULL, + wiiu_input_get_capabilities, + "wiiu", + wiiu_input_grab_mouse, + NULL, + wiiu_input_set_rumble, + wiiu_input_get_joypad_driver, + NULL, + wiiu_input_keyboard_mapping_is_blocked, + wiiu_input_keyboard_mapping_set_block, +}; diff --git a/input/drivers_joypad/wiiu_joypad.c b/input/drivers_joypad/wiiu_joypad.c new file mode 100644 index 0000000000..ad37dca9a0 --- /dev/null +++ b/input/drivers_joypad/wiiu_joypad.c @@ -0,0 +1,194 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2011-2016 - Daniel De Matteis + * Copyright (C) 2014-2015 - Ali Bouhlel + * + * 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 . + */ + +#ifdef HAVE_CONFIG_H +#include "../../config.h" +#endif + +#include "../input_joypad_driver.h" +#include "../input_driver.h" +#include "../input_autodetect.h" +#include "../../configuration.h" +#include "../../runloop.h" +#include "../../configuration.h" +#include "../../retroarch.h" +#include "../../command.h" +#include "string.h" + +#include "dynamic_libs/vpad_functions.h" + +#ifndef MAX_PADS +#define MAX_PADS 1 +#endif + +static uint64_t pad_state; +static int16_t analog_state[1][2][2]; +extern uint64_t lifecycle_state; + +static const char *wiiu_joypad_name(unsigned pad) +{ + return "WIIU Controller"; +} + +static void wiiu_joypad_autodetect_add(unsigned autoconf_pad) +{ + settings_t *settings = config_get_ptr(); + autoconfig_params_t params = {{0}}; + + strlcpy(settings->input.device_names[autoconf_pad], + wiiu_joypad_name(autoconf_pad), + sizeof(settings->input.device_names[autoconf_pad])); + + /* TODO - implement VID/PID? */ + params.idx = autoconf_pad; + strlcpy(params.name, wiiu_joypad_name(autoconf_pad), sizeof(params.name)); + strlcpy(params.driver, wiiu_joypad.ident, sizeof(params.driver)); + input_config_autoconfigure_joypad(¶ms); +} + +static bool wiiu_joypad_init(void *data) +{ + wiiu_joypad_autodetect_add(0); + + (void)data; + + return true; +} + +static bool wiiu_joypad_button(unsigned port_num, uint16_t key) +{ + if (port_num >= MAX_PADS) + return false; + + return (pad_state & (UINT64_C(1) << key)); +} + +static uint64_t wiiu_joypad_get_buttons(unsigned port_num) +{ + return pad_state; +} + +static int16_t wiiu_joypad_axis(unsigned port_num, uint32_t joyaxis) +{ + int val = 0; + int axis = -1; + bool is_neg = false; + bool is_pos = false; + + if (joyaxis == AXIS_NONE || port_num >= MAX_PADS) + return 0; + + if (AXIS_NEG_GET(joyaxis) < 4) + { + axis = AXIS_NEG_GET(joyaxis); + is_neg = true; + } + else if (AXIS_POS_GET(joyaxis) < 4) + { + axis = AXIS_POS_GET(joyaxis); + is_pos = true; + } + + switch (axis) + { + case 0: + val = analog_state[port_num][0][0]; + break; + case 1: + val = analog_state[port_num][0][1]; + break; + case 2: + val = analog_state[port_num][1][0]; + break; + case 3: + val = analog_state[port_num][1][1]; + break; + } + + if (is_neg && val > 0) + val = 0; + else if (is_pos && val < 0) + val = 0; + + return val; +} + +static void wiiu_joypad_poll(void) +{ + VPADData vpad; + int vpadError = -1; + VPADRead(0, &vpad, 1, &vpadError); + + pad_state = 0; + pad_state |= (vpad.btns_h & VPAD_BUTTON_LEFT) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0; + pad_state |= (vpad.btns_h & VPAD_BUTTON_DOWN) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0; + pad_state |= (vpad.btns_h & VPAD_BUTTON_RIGHT) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0; + pad_state |= (vpad.btns_h & VPAD_BUTTON_UP) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_UP) : 0; + pad_state |= (vpad.btns_h & VPAD_BUTTON_PLUS) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_START) : 0; + pad_state |= (vpad.btns_h & VPAD_BUTTON_MINUS) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_SELECT) : 0; + pad_state |= (vpad.btns_h & VPAD_BUTTON_X) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_X) : 0; + pad_state |= (vpad.btns_h & VPAD_BUTTON_Y) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_Y) : 0; + pad_state |= (vpad.btns_h & VPAD_BUTTON_B) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_B) : 0; + pad_state |= (vpad.btns_h & VPAD_BUTTON_A) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_A) : 0; + pad_state |= (vpad.btns_h & VPAD_BUTTON_R) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_R) : 0; + pad_state |= (vpad.btns_h & VPAD_BUTTON_L) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_L) : 0; + pad_state |= (vpad.btns_h & VPAD_BUTTON_ZR) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_R2) : 0; + pad_state |= (vpad.btns_h & VPAD_BUTTON_ZL) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_L2) : 0; + pad_state |= (vpad.btns_h & VPAD_BUTTON_STICK_R) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_R3) : 0; + pad_state |= (vpad.btns_h & VPAD_BUTTON_STICK_L) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_L3) : 0; + + analog_state[0][RETRO_DEVICE_INDEX_ANALOG_LEFT] [RETRO_DEVICE_ID_ANALOG_X] = vpad.lstick.x * 0x7FF0; + analog_state[0][RETRO_DEVICE_INDEX_ANALOG_LEFT] [RETRO_DEVICE_ID_ANALOG_Y] = -vpad.lstick.y * 0x7FF0; + analog_state[0][RETRO_DEVICE_INDEX_ANALOG_RIGHT] [RETRO_DEVICE_ID_ANALOG_X] = vpad.rstick.x * 0x7FF0; + analog_state[0][RETRO_DEVICE_INDEX_ANALOG_RIGHT] [RETRO_DEVICE_ID_ANALOG_Y] = -vpad.rstick.y * 0x7FF0; + + BIT64_CLEAR(lifecycle_state, RARCH_MENU_TOGGLE); + + if((vpad.tpdata.touched) && (vpad.tpdata.x > 200)) + BIT64_SET(lifecycle_state, RARCH_MENU_TOGGLE); + + /* panic button */ + if((vpad.btns_h & VPAD_BUTTON_R) && + (vpad.btns_h & VPAD_BUTTON_L) && + (vpad.btns_h & VPAD_BUTTON_STICK_R) && + (vpad.btns_h & VPAD_BUTTON_STICK_L)) + command_event(CMD_EVENT_QUIT, NULL); + +} + +static bool wiiu_joypad_query_pad(unsigned pad) +{ + /* FIXME */ + return pad < MAX_USERS && pad_state; +} + + +static void wiiu_joypad_destroy(void) +{ +} + +input_device_driver_t wiiu_joypad = { + wiiu_joypad_init, + wiiu_joypad_query_pad, + wiiu_joypad_destroy, + wiiu_joypad_button, + wiiu_joypad_get_buttons, + wiiu_joypad_axis, + wiiu_joypad_poll, + NULL, + wiiu_joypad_name, + "wiiu", +}; diff --git a/input/input_autodetect_builtin.c b/input/input_autodetect_builtin.c index 85c88c9eb1..2cf70cbac1 100644 --- a/input/input_autodetect_builtin.c +++ b/input/input_autodetect_builtin.c @@ -103,6 +103,30 @@ DECL_AXIS(r_x_minus, -2) \ DECL_AXIS(r_y_plus, -3) \ DECL_AXIS(r_y_minus, +3) +#define WIIUINPUT_DEFAULT_BINDS \ +DECL_BTN(a, 8) \ +DECL_BTN(b, 0) \ +DECL_BTN(x, 9) \ +DECL_BTN(y, 1) \ +DECL_BTN(start, 3) \ +DECL_BTN(select, 2) \ +DECL_BTN(up, 4) \ +DECL_BTN(down, 5) \ +DECL_BTN(left, 6) \ +DECL_BTN(right, 7) \ +DECL_BTN(l, 10) \ +DECL_BTN(r, 11) \ +DECL_BTN(l2, 12) \ +DECL_BTN(r2, 13) \ +DECL_AXIS(l_x_plus, +0) \ +DECL_AXIS(l_x_minus, -0) \ +DECL_AXIS(l_y_plus, +1) \ +DECL_AXIS(l_y_minus, -1) \ +DECL_AXIS(r_x_plus, +2) \ +DECL_AXIS(r_x_minus, -2) \ +DECL_AXIS(r_y_plus, -3) \ +DECL_AXIS(r_y_minus, +3) + #define GXINPUT_GAMECUBE_DEFAULT_BINDS \ DECL_BTN(a, 0) \ DECL_BTN(b, 1) \ @@ -291,6 +315,9 @@ const char* const input_builtin_autoconfs[] = DECL_AUTOCONF_DEVICE("Classic Controller", "gx", GXINPUT_CLASSIC_DEFAULT_BINDS), #endif #endif +#ifdef WIIU + DECL_AUTOCONF_DEVICE("WIIU Controller", "wiiu", WIIUINPUT_DEFAULT_BINDS), +#endif #ifdef __CELLOS_LV2__ DECL_AUTOCONF_DEVICE("SixAxis Controller", "ps3", PS3INPUT_DEFAULT_BINDS), #endif diff --git a/input/input_driver.c b/input/input_driver.c index 0ce9206fb7..327754737f 100644 --- a/input/input_driver.c +++ b/input/input_driver.c @@ -65,6 +65,9 @@ static const input_driver_t *input_drivers[] = { #ifdef GEKKO &input_gx, #endif +#ifdef WIIU + &input_wiiu, +#endif #ifdef ANDROID &input_android, #endif @@ -512,8 +515,8 @@ static bool check_input_driver_block_hotkey(bool enable_hotkey) &settings->input.binds[0][RARCH_ENABLE_HOTKEY]; const struct retro_keybind *autoconf_bind = &settings->input.autoconf_binds[0][RARCH_ENABLE_HOTKEY]; - bool kb_mapping_is_blocked = current_input->keyboard_mapping_is_blocked( - current_input_data); + bool kb_mapping_is_blocked = current_input->keyboard_mapping_is_blocked && + current_input->keyboard_mapping_is_blocked(current_input_data); /* Don't block the check to RARCH_ENABLE_HOTKEY * unless we're really supposed to. */ diff --git a/input/input_driver.h b/input/input_driver.h index 0d07b6d976..657be73c9b 100644 --- a/input/input_driver.h +++ b/input/input_driver.h @@ -314,6 +314,7 @@ extern input_driver_t input_psp; extern input_driver_t input_ctr; extern input_driver_t input_xenon360; extern input_driver_t input_gx; +extern input_driver_t input_wiiu; extern input_driver_t input_xinput; extern input_driver_t input_linuxraw; extern input_driver_t input_udev; diff --git a/input/input_joypad_driver.c b/input/input_joypad_driver.c index 606df76eb2..2aa4f9f898 100644 --- a/input/input_joypad_driver.c +++ b/input/input_joypad_driver.c @@ -39,6 +39,9 @@ static input_device_driver_t *joypad_drivers[] = { #ifdef GEKKO &gx_joypad, #endif +#ifdef WIIU + &wiiu_joypad, +#endif #ifdef _XBOX &xdk_joypad, #endif diff --git a/input/input_joypad_driver.h b/input/input_joypad_driver.h index f7fd2478a6..d06e90d5c9 100644 --- a/input/input_joypad_driver.h +++ b/input/input_joypad_driver.h @@ -219,6 +219,7 @@ extern input_device_driver_t psp_joypad; extern input_device_driver_t ctr_joypad; extern input_device_driver_t xdk_joypad; extern input_device_driver_t gx_joypad; +extern input_device_driver_t wiiu_joypad; extern input_device_driver_t hid_joypad; extern input_device_driver_t android_joypad; extern input_device_driver_t qnx_joypad; diff --git a/libretro-common/features/features_cpu.c b/libretro-common/features/features_cpu.c index 596e503c6f..b6c2f73f5c 100644 --- a/libretro-common/features/features_cpu.c +++ b/libretro-common/features/features_cpu.c @@ -168,6 +168,8 @@ retro_perf_tick_t cpu_features_get_perf_counter(void) sceRtcGetCurrentTick((SceRtcTick*)&time_ticks); #elif defined(_3DS) time_ticks = svcGetSystemTick(); +#elif defined(WIIU) + time_ticks = 0; #elif defined(__mips__) struct timeval tv; gettimeofday(&tv,NULL); @@ -216,6 +218,8 @@ retro_time_t cpu_features_get_time_usec(void) return osGetTime() * 1000; #elif defined(VITA) return sceKernelGetProcessTimeWide(); +#elif defined(WIIU) + return 0; #else #error "Your platform does not have a timer function implemented in cpu_features_get_time_usec(). Cannot continue." #endif @@ -459,6 +463,8 @@ unsigned cpu_features_get_core_amount(void) return 4; #elif defined(_3DS) return 1; +#elif defined(WIIU) + return 3; #elif defined(_SC_NPROCESSORS_ONLN) /* Linux, most UNIX-likes. */ long ret = sysconf(_SC_NPROCESSORS_ONLN); diff --git a/libretro-common/include/memmap.h b/libretro-common/include/memmap.h index b93c0f090e..bc7d9fbef5 100644 --- a/libretro-common/include/memmap.h +++ b/libretro-common/include/memmap.h @@ -23,7 +23,7 @@ #ifndef _LIBRETRO_MEMMAP_H #define _LIBRETRO_MEMMAP_H -#if defined(__CELLOS_LV2__) || defined(PSP) || defined(GEKKO) || defined(VITA) || defined(_XBOX) || defined(_3DS) +#if defined(__CELLOS_LV2__) || defined(PSP) || defined(GEKKO) || defined(VITA) || defined(_XBOX) || defined(_3DS) || defined(WIIU) /* No mman available */ #elif defined(_WIN32) && !defined(_XBOX) #include diff --git a/libretro-common/include/retro_miscellaneous.h b/libretro-common/include/retro_miscellaneous.h index c9a0e91a71..fe98f1fbb7 100644 --- a/libretro-common/include/retro_miscellaneous.h +++ b/libretro-common/include/retro_miscellaneous.h @@ -32,6 +32,8 @@ #include