mirror of
https://github.com/AloUltraExt/sm64ex-alo.git
synced 2025-01-24 00:24:33 -05:00
add switch port by fgsfds - controller by vatuu
This commit is contained in:
parent
95fc994cc6
commit
990724e06e
10 changed files with 290 additions and 44 deletions
111
Makefile
111
Makefile
|
@ -33,6 +33,8 @@ TARGET_WEB ?= 0
|
|||
TARGET_WII_U ?= 0
|
||||
# Build for the 3DS
|
||||
TARGET_N3DS ?= 0
|
||||
# Build for Nintendo Switch
|
||||
TARGET_SWITCH ?= 1
|
||||
# Makeflag to enable OSX fixes
|
||||
OSX_BUILD ?= 0
|
||||
# Specify the target you are building for, TARGET_BITS=0 means native
|
||||
|
@ -72,7 +74,8 @@ RENDER_API ?= GL
|
|||
WINDOW_API ?= SDL2
|
||||
# Audio backends: SDL1, SDL2 (forced if the target is Wii U), 3DS (forced if the target is 3DS)
|
||||
AUDIO_API ?= SDL2
|
||||
# Controller backends (can have multiple, space separated): SDL1, SDL2, WII_U (forced if the target is Wii U), 3DS (forced if the target is 3DS)
|
||||
# Controller backends (can have multiple, space separated): SDL1, SDL2
|
||||
# WII_U (forced if the target is Wii U), 3DS (forced if the target is 3DS), SWITCH (forced if the target is SWITCH)
|
||||
CONTROLLER_API ?= SDL2
|
||||
|
||||
ifeq ($(TARGET_WII_U),1)
|
||||
|
@ -89,10 +92,15 @@ ifeq ($(TARGET_N3DS),1)
|
|||
CONTROLLER_API := 3DS
|
||||
endif
|
||||
|
||||
ifeq ($(TARGET_WII_U),1)
|
||||
ifeq ($(TARGET_N3DS),1)
|
||||
TARGET_GAME_CONSOLE := 1
|
||||
ifeq ($(TARGET_SWITCH),1)
|
||||
RENDER_API := GL
|
||||
WINDOW_API := SDL2
|
||||
AUDIO_API := SDL2
|
||||
CONTROLLER_API := SWITCH
|
||||
endif
|
||||
|
||||
ifeq ($(TARGET_N3DS)$(TARGET_WII_U)$(TARGET_SWITCH),111)
|
||||
TARGET_GAME_CONSOLE := 1
|
||||
endif
|
||||
|
||||
# Misc settings for EXTERNAL_DATA
|
||||
|
@ -252,23 +260,21 @@ VERSION_CFLAGS := $(VERSION_CFLAGS) -DNON_MATCHING -DAVOID_UB
|
|||
|
||||
ifeq ($(TARGET_RPI),1) # Define RPi to change SDL2 title & GLES2 hints
|
||||
VERSION_CFLAGS += -DUSE_GLES
|
||||
endif
|
||||
|
||||
ifeq ($(OSX_BUILD),1) # Modify GFX & SDL2 for OSX GL
|
||||
else ifeq ($(OSX_BUILD),1) # Modify GFX & SDL2 for OSX GL
|
||||
VERSION_CFLAGS += -DOSX_BUILD
|
||||
endif
|
||||
|
||||
VERSION_ASFLAGS := $(VERSION_ASFLAGS) --defsym AVOID_UB=1
|
||||
COMPARE := 0
|
||||
|
||||
ifeq ($(TARGET_WEB),1)
|
||||
else ifeq ($(TARGET_WEB),1)
|
||||
VERSION_CFLAGS := $(VERSION_CFLAGS) -DTARGET_WEB -DUSE_GLES
|
||||
else ifeq ($(TARGET_WII_U),1)
|
||||
VERSION_CFLAGS := $(VERSION_CFLAGS) -DTARGET_WII_U
|
||||
else ifeq ($(TARGET_N3DS),1)
|
||||
VERSION_CFLAGS := $(VERSION_CFLAGS) -DTARGET_N3DS
|
||||
else ifeq ($(TARGET_SWITCH),1)
|
||||
VERSION_CFLAGS += $(VERSION_CFLAGS) -DUSE_GLES -DTARGET_SWITCH
|
||||
endif
|
||||
|
||||
VERSION_ASFLAGS := $(VERSION_ASFLAGS) --defsym AVOID_UB=1
|
||||
COMPARE := 0
|
||||
|
||||
# Check backends
|
||||
|
||||
ifneq (,$(filter $(RENDER_API),D3D11 D3D12))
|
||||
|
@ -325,6 +331,8 @@ else ifeq ($(TARGET_WII_U),1)
|
|||
BUILD_DIR := $(BUILD_DIR_BASE)/$(VERSION)_wiiu
|
||||
else ifeq ($(TARGET_N3DS),1)
|
||||
BUILD_DIR := $(BUILD_DIR_BASE)/$(VERSION)_3ds
|
||||
else ifeq ($(TARGET_SWITCH),1)
|
||||
BUILD_DIR := $(BUILD_DIR_BASE)/$(VERSION)_nx
|
||||
else
|
||||
BUILD_DIR := $(BUILD_DIR_BASE)/$(VERSION)_pc
|
||||
endif
|
||||
|
@ -636,8 +644,33 @@ else ifeq ($(TARGET_N3DS),1)
|
|||
CXX := $(DEVKITARM)/bin/arm-none-eabi-g++
|
||||
LD := $(CXX)
|
||||
SDLCONFIG :=
|
||||
|
||||
else
|
||||
|
||||
ifeq ($(TARGET_SWITCH),1)
|
||||
ifeq ($(strip $(DEVKITPRO)),)
|
||||
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
|
||||
endif
|
||||
export PATH := $(DEVKITPRO)/devkitA64/bin:$(PATH)
|
||||
PORTLIBS ?= $(DEVKITPRO)/portlibs/switch
|
||||
LIBNX ?= $(DEVKITPRO)/libnx
|
||||
CROSS ?= aarch64-none-elf-
|
||||
SDLCROSS :=
|
||||
CC := $(CROSS)gcc
|
||||
CXX := $(CROSS)g++
|
||||
STRIP := $(CROSS)strip
|
||||
NXARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE
|
||||
APP_TITLE := Super Mario 64
|
||||
APP_AUTHOR := Nintendo, n64decomp team, sm64pc team
|
||||
APP_VERSION := 1_master_$(VERSION)
|
||||
APP_ICON := nx_icon.jpg
|
||||
INCLUDE_CFLAGS += -isystem$(LIBNX)/include -I$(PORTLIBS)/include
|
||||
OPT_FLAGS := -g -O0 -std=gnu99
|
||||
endif
|
||||
|
||||
# for some reason sdl-config in dka64 is not prefixed, while pkg-config is
|
||||
SDLCROSS ?= $(CROSS)
|
||||
|
||||
AS := $(CROSS)as
|
||||
|
||||
ifeq ($(OSX_BUILD),1)
|
||||
|
@ -680,7 +713,7 @@ else # Linux & other builds
|
|||
OBJDUMP := $(CROSS)objdump
|
||||
endif
|
||||
|
||||
SDLCONFIG := $(CROSS)sdl2-config
|
||||
SDLCONFIG := $(SDLCROSS)sdl2-config
|
||||
|
||||
endif
|
||||
|
||||
|
@ -707,7 +740,8 @@ ifeq ($(WINDOW_API),DXGI)
|
|||
else ifeq ($(findstring SDL,$(WINDOW_API)),SDL)
|
||||
ifeq ($(WINDOWS_BUILD),1)
|
||||
BACKEND_LDFLAGS += -lglew32 -lglu32 -lopengl32
|
||||
else ifeq ($(TARGET_RPI),1)
|
||||
# else ifeq ($(TARGET_RPI),1)
|
||||
else ifneq ($(TARGET_RPI)$(TARGET_SWITCH),00)
|
||||
BACKEND_LDFLAGS += -lGLESv2
|
||||
else ifeq ($(OSX_BUILD),1)
|
||||
BACKEND_LDFLAGS += -framework OpenGL `pkg-config --libs glew`
|
||||
|
@ -735,21 +769,19 @@ endif
|
|||
# SDL can be used by different systems, so we consolidate all of that shit into this
|
||||
|
||||
ifeq ($(SDL2_USED),1)
|
||||
SDLCONFIG := $(CROSS)sdl2-config
|
||||
SDLCONFIG := $(SDLCROSS)sdl2-config
|
||||
BACKEND_CFLAGS += -DHAVE_SDL2=1
|
||||
else ifeq ($(SDL1_USED),1)
|
||||
SDLCONFIG := $(CROSS)sdl-config
|
||||
SDLCONFIG := $(SDLCROSS)sdl-config
|
||||
BACKEND_CFLAGS += -DHAVE_SDL1=1
|
||||
endif
|
||||
|
||||
ifeq ($(TARGET_GAME_CONSOLE),0)
|
||||
ifneq ($(SDL1_USED)$(SDL2_USED),00)
|
||||
BACKEND_CFLAGS += `$(SDLCONFIG) --cflags`
|
||||
ifeq ($(WINDOWS_BUILD),1)
|
||||
BACKEND_LDFLAGS += `$(SDLCONFIG) --static-libs` -lsetupapi -luser32 -limm32 -lole32 -loleaut32 -lshell32 -lwinmm -lversion
|
||||
else
|
||||
BACKEND_LDFLAGS += `$(SDLCONFIG) --libs`
|
||||
endif
|
||||
ifneq ($(SDL1_USED)$(SDL2_USED),00)
|
||||
BACKEND_CFLAGS += `$(SDLCONFIG) --cflags`
|
||||
ifeq ($(WINDOWS_BUILD),1)
|
||||
BACKEND_LDFLAGS += `$(SDLCONFIG) --static-libs` -lsetupapi -luser32 -limm32 -lole32 -loleaut32 -lshell32 -lwinmm -lversion
|
||||
else
|
||||
BACKEND_LDFLAGS += `$(SDLCONFIG) --libs`
|
||||
endif
|
||||
endif
|
||||
|
||||
|
@ -781,6 +813,11 @@ ifeq ($(TARGET_N3DS),1)
|
|||
CFLAGS += -mtp=soft -DARM11 -DosGetTime=n64_osGetTime -D_3DS -march=armv6k -mtune=mpcore -mfloat-abi=hard -mword-relocations -fomit-frame-pointer -ffast-math $(foreach dir,$(LIBDIRS),-I$(dir)/include)
|
||||
endif
|
||||
|
||||
ifeq ($(TARGET_SWITCH),1)
|
||||
CC_CHECK := $(CC) $(NXARCH) -fsyntax-only -fsigned-char $(BACKEND_CFLAGS) $(INCLUDE_CFLAGS) -Wall -Wextra -Wno-format-security $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -D__SWITCH__=1
|
||||
CFLAGS := $(NXARCH) $(OPT_FLAGS) $(INCLUDE_CFLAGS) $(BACKEND_CFLAGS) $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -fno-strict-aliasing -ftls-model=local-exec -fPIE -fwrapv -D__SWITCH__=1
|
||||
endif
|
||||
|
||||
# Check for enhancement options
|
||||
|
||||
# Check for Puppycam option
|
||||
|
@ -877,6 +914,9 @@ LDFLAGS := -lm -no-pie $(BACKEND_LDFLAGS) $(MACHDEP) $(RPXSPECS) $(LIBPATHS)
|
|||
else ifeq ($(TARGET_N3DS),1)
|
||||
LDFLAGS := $(LIBPATHS) -lcitro3d -lctru -lm -specs=3dsx.specs -g -marm -mthumb-interwork -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft # -Wl,-Map,$(notdir $*.map)
|
||||
|
||||
else ifeq ($(TARGET_SWITCH),1)
|
||||
LDFLAGS := -specs=$(LIBNX)/switch.specs $(NXARCH) $(OPT_FLAGS) -L$(LIBNX)/lib $(BACKEND_LDFLAGS) -lstdc++ -lnx -lm
|
||||
|
||||
else ifeq ($(WINDOWS_BUILD),1)
|
||||
LDFLAGS := $(BITS) -march=$(TARGET_ARCH) -Llib -lpthread $(BACKEND_LDFLAGS) -static
|
||||
ifeq ($(CROSS),)
|
||||
|
@ -946,6 +986,10 @@ else
|
|||
all: $(EXE)
|
||||
endif
|
||||
|
||||
ifeq ($(TARGET_SWITCH),1)
|
||||
all: $(EXE).nro
|
||||
endif
|
||||
|
||||
# thank you apple very cool
|
||||
ifeq ($(HOST_OS),Darwin)
|
||||
CP := gcp
|
||||
|
@ -1337,6 +1381,23 @@ $(EXE): $(O_FILES) $(MIO0_FILES:.mio0=.o) $(SOUND_OBJ_FILES) $(ULTRA_O_FILES) $(
|
|||
$(LD) -L $(BUILD_DIR) -o $@ $(O_FILES) $(SOUND_OBJ_FILES) $(ULTRA_O_FILES) $(GODDARD_O_FILES) $(LDFLAGS)
|
||||
endif
|
||||
|
||||
ifeq ($(TARGET_SWITCH), 1)
|
||||
|
||||
# add `--icon=$(APP_ICON)` to this when we get a suitable icon
|
||||
%.nro: %.stripped %.nacp
|
||||
@elf2nro $< $@ --nacp=$*.nacp
|
||||
@echo built ... $(notdir $@)
|
||||
|
||||
%.nacp:
|
||||
@nacptool --create "$(APP_TITLE)" "$(APP_AUTHOR)" "$(APP_VERSION)" $@ $(NACPFLAGS)
|
||||
@echo built ... $(notdir $@)
|
||||
|
||||
%.stripped: %
|
||||
@$(STRIP) -o $@ $<
|
||||
@echo stripped ... $(notdir $<)
|
||||
|
||||
endif
|
||||
|
||||
.PHONY: all clean distclean default diff test load libultra res
|
||||
.PRECIOUS: $(BUILD_DIR)/bin/%.elf $(SOUND_BIN_DIR)/%.ctl $(SOUND_BIN_DIR)/%.tbl $(SOUND_SAMPLE_TABLES) $(SOUND_BIN_DIR)/%.s $(BUILD_DIR)/%
|
||||
.DELETE_ON_ERROR:
|
||||
|
|
|
@ -3,10 +3,11 @@ Fork of [sm64pc/sm64ex](https://github.com/sm64pc/sm64ex/tree/nightly) with addi
|
|||
|
||||
## Changes
|
||||
* Restored N64 build.
|
||||
* Additional backends merged from other forks (3ds, Wii U) (more incoming)
|
||||
* Additional backends merged from other forks (3DS, Wii U, Switch) (more incoming)
|
||||
|
||||
## Building
|
||||
* To build for N64, [click here](https://github.com/n64decomp/sm64/blob/master/README.md). (TARGET_N64=1)
|
||||
* To build for sm64ex platforms, [click here](https://github.com/sm64pc/sm64ex/blob/nightly/README.md).
|
||||
* To build for N64, [click here](https://github.com/n64decomp/sm64/blob/master/README.md). (TARGET_N64=1)
|
||||
* To build for Wii U, [click here](https://github.com/aboood40091/sm64-port/blob/master/README.md). (TARGET_WII_U=1)
|
||||
* To build for N3DS, [click here](https://github.com/sm64-port/sm64_3ds/blob/master/README.md). (TARGET_N3DS=1)
|
||||
* To build for Switch, [click here](https://github.com/fgsfdsfgs/sm64ex/blob/switch/README.md). (TARGET_SWITCH=1)
|
||||
|
|
|
@ -1,13 +1,18 @@
|
|||
#ifndef _ULTRA64_TYPES_H_
|
||||
#define _ULTRA64_TYPES_H_
|
||||
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
||||
typedef float f32;
|
||||
typedef double f64;
|
||||
|
||||
#ifndef TARGET_SWITCH
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL (void *)0
|
||||
#endif
|
||||
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
||||
typedef signed char s8;
|
||||
typedef unsigned char u8;
|
||||
typedef signed short int s16;
|
||||
|
@ -26,9 +31,6 @@ typedef volatile s16 vs16;
|
|||
typedef volatile s32 vs32;
|
||||
typedef volatile s64 vs64;
|
||||
|
||||
typedef float f32;
|
||||
typedef double f64;
|
||||
|
||||
#ifdef TARGET_N64
|
||||
typedef u32 size_t;
|
||||
typedef s32 ssize_t;
|
||||
|
@ -53,4 +55,12 @@ typedef ptrdiff_t ssize_t;
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#else // TARGET_SWITCH
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <switch.h>
|
||||
typedef ptrdiff_t ssize_t;
|
||||
#endif
|
||||
|
||||
#endif // _ULTRA64_TYPES_H_
|
||||
|
|
|
@ -36,15 +36,21 @@ s32 gTitleFadeCounter;
|
|||
const Gfx *introBackgroundDlRows[] = { title_screen_bg_dl_0A000130, title_screen_bg_dl_0A000148,
|
||||
title_screen_bg_dl_0A000160, title_screen_bg_dl_0A000178 };
|
||||
|
||||
/*
|
||||
// intro screen background texture X offsets
|
||||
float introBackgroundOffsetX[] = {
|
||||
0.0, 80.0, 160.0, 240.0, 0.0, 80.0, 160.0, 240.0, 0.0, 80.0, 160.0, 240.0,
|
||||
-80.0, 0.0, 80.0, 160.0,
|
||||
-80.0, 0.0, 80.0, 160.0,
|
||||
-80.0, 0.0, 80.0, 160.0,
|
||||
};
|
||||
|
||||
// intro screen background texture Y offsets
|
||||
float introBackgroundOffsetY[] = {
|
||||
160.0, 160.0, 160.0, 160.0, 80.0, 80.0, 80.0, 80.0, 0.0, 0.0, 0.0, 0.0,
|
||||
160.0, 160.0, 160.0, 160.0,
|
||||
80.0, 80.0, 80.0, 80.0,
|
||||
0.0, 0.0, 0.0, 0.0,
|
||||
};
|
||||
*/
|
||||
|
||||
// table that points to either the "Super Mario 64" or "Game Over" tables
|
||||
const u8 *const *introBackgroundTextureType[] = { mario_title_texture_table, game_over_texture_table };
|
||||
|
@ -154,6 +160,15 @@ Gfx *geo_fade_transition(s32 sp40, struct GraphNode *sp44, UNUSED void *context)
|
|||
return displayList;
|
||||
}
|
||||
|
||||
// center tiles for these consoles
|
||||
#if defined(TARGET_SWITCH) || defined(TARGET_WII_U)
|
||||
#define CENTER_TILES_ASPECT (79*2*aspect)
|
||||
#define CENTER_TILES_POS (80*aspect)
|
||||
#else
|
||||
#define CENTER_TILES_ASPECT 79
|
||||
#define CENTER_TILES_POS 0
|
||||
#endif
|
||||
|
||||
Gfx *intro_backdrop_one_image(s32 index, s8 *backgroundTable) {
|
||||
Mtx *mtx; // sp5c
|
||||
Gfx *displayList; // sp58
|
||||
|
@ -161,14 +176,14 @@ Gfx *intro_backdrop_one_image(s32 index, s8 *backgroundTable) {
|
|||
const u8 *const *vIntroBgTable; // sp50
|
||||
s32 i; // sp4c
|
||||
f32 aspect = GFX_DIMENSIONS_ASPECT_RATIO;
|
||||
int num_tiles_h = (((aspect*SCREEN_HEIGHT)+79)/80);
|
||||
int num_tiles_h = (((aspect*SCREEN_HEIGHT)+CENTER_TILES_ASPECT)/80);
|
||||
float x_ofs = (SCREEN_WIDTH/2)-(aspect*SCREEN_HEIGHT/2);
|
||||
|
||||
|
||||
mtx = alloc_display_list(sizeof(*mtx));
|
||||
displayList = alloc_display_list(36 * sizeof(*displayList));
|
||||
displayListIter = displayList;
|
||||
vIntroBgTable = segmented_to_virtual(introBackgroundTextureType[backgroundTable[0]]);
|
||||
guTranslate(mtx, ((index%num_tiles_h)*80)+x_ofs, (index/num_tiles_h)*80, 0.0f);
|
||||
guTranslate(mtx, (((index%num_tiles_h)*80)+x_ofs)-CENTER_TILES_POS, (index/num_tiles_h)*80, 0.0f);
|
||||
gSPMatrix(displayListIter++, mtx, G_MTX_MODELVIEW | G_MTX_LOAD | G_MTX_PUSH);
|
||||
gSPDisplayList(displayListIter++, &title_screen_bg_dl_0A000118);
|
||||
for (i = 0; i < 4; ++i) {
|
||||
|
@ -189,7 +204,7 @@ Gfx *geo_intro_backdrop(s32 sp48, struct GraphNode *sp4c, UNUSED void *context)
|
|||
Gfx *displayListIter; // sp34
|
||||
s32 i; // sp30
|
||||
f32 aspect = GFX_DIMENSIONS_ASPECT_RATIO;
|
||||
int num_tiles_h = (((aspect*SCREEN_HEIGHT)+79)/80);
|
||||
int num_tiles_h = (((aspect*SCREEN_HEIGHT)+CENTER_TILES_ASPECT)/80);
|
||||
graphNode = (struct GraphNodeMore *) sp4c;
|
||||
index = graphNode->unk18 & 0xff; // TODO: word at offset 0x18 of struct GraphNode
|
||||
backgroundTable = introBackgroundTables[index];
|
||||
|
@ -219,7 +234,7 @@ Gfx *geo_game_over_tile(s32 sp40, struct GraphNode *sp44, UNUSED void *context)
|
|||
s32 j; // sp30
|
||||
s32 i; // sp2c
|
||||
f32 aspect = GFX_DIMENSIONS_ASPECT_RATIO;
|
||||
int num_tiles_h = (((aspect*SCREEN_HEIGHT)+79)/80);
|
||||
int num_tiles_h = (((aspect*SCREEN_HEIGHT)+CENTER_TILES_ASPECT)/80);
|
||||
graphNode = sp44;
|
||||
displayList = NULL;
|
||||
displayListIter = NULL;
|
||||
|
@ -260,3 +275,6 @@ Gfx *geo_game_over_tile(s32 sp40, struct GraphNode *sp44, UNUSED void *context)
|
|||
}
|
||||
return displayList;
|
||||
}
|
||||
|
||||
#undef CENTER_TILES_ASPECT
|
||||
#undef CENTER_TILES_POS
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "controller_sdl.h"
|
||||
#include "controller_wiiu.h"
|
||||
#include "controller_3ds.h"
|
||||
#include "controller_switch.h"
|
||||
|
||||
// Analog camera movement by Pathétique (github.com/vrmiguel), y0shin and Mors
|
||||
// Contribute or communicate bugs at github.com/vrmiguel/sm64-analog-camera
|
||||
|
@ -19,6 +20,8 @@ static struct ControllerAPI *controller_implementations[] = {
|
|||
&controller_wiiu,
|
||||
#elif defined(CAPI_3DS)
|
||||
&controller_3ds,
|
||||
#elif defined(CAPI_SWITCH)
|
||||
&controller_switch,
|
||||
#else
|
||||
#if defined(CAPI_SDL1) || defined(CAPI_SDL2)
|
||||
&controller_sdl,
|
||||
|
|
122
src/pc/controller/controller_switch.c
Normal file
122
src/pc/controller/controller_switch.c
Normal file
|
@ -0,0 +1,122 @@
|
|||
#ifdef CAPI_SWITCH
|
||||
|
||||
#include <switch.h>
|
||||
#include <ultra64.h>
|
||||
|
||||
#include <sm64.h>
|
||||
#include "../../game/level_update.h"
|
||||
|
||||
#include "controller_api.h"
|
||||
|
||||
static HidControllerID joyConId;
|
||||
|
||||
static bool isSixAxis = false;
|
||||
static u32 sixAxisHandles[4];
|
||||
static struct SixAxisSensorValues sixAxis;
|
||||
|
||||
static void startSixAxis() {
|
||||
isSixAxis = true;
|
||||
//Initiating the SixAxis, needs to be done for all options; Obviously no GC Controller.
|
||||
hidGetSixAxisSensorHandles(&sixAxisHandles[0], 2, CONTROLLER_PLAYER_1, TYPE_JOYCON_PAIR);
|
||||
hidGetSixAxisSensorHandles(&sixAxisHandles[2], 1, CONTROLLER_PLAYER_1, TYPE_PROCONTROLLER);
|
||||
hidGetSixAxisSensorHandles(&sixAxisHandles[3], 1, CONTROLLER_HANDHELD, TYPE_HANDHELD);
|
||||
for(int i = 0; i < 4; i++)
|
||||
hidStartSixAxisSensor(sixAxisHandles[i]);
|
||||
hidScanInput();
|
||||
hidSixAxisSensorValuesRead(&sixAxis, joyConId, 1);
|
||||
}
|
||||
|
||||
static void stopSixAxis() {
|
||||
isSixAxis = false;
|
||||
for(int i = 0; i < 4; i++)
|
||||
hidStopSixAxisSensor(sixAxisHandles[i]);
|
||||
}
|
||||
|
||||
static s8 gyroToSByte(float f) {
|
||||
return (s8)(f * 0xFF);
|
||||
}
|
||||
|
||||
static void joycon_init(void) {
|
||||
joyConId = CONTROLLER_P1_AUTO;
|
||||
}
|
||||
|
||||
static void joycon_read(OSContPad *pad) {
|
||||
hidScanInput();
|
||||
|
||||
switch(gMarioState->action) {
|
||||
case ACT_IN_CANNON:
|
||||
case ACT_FIRST_PERSON:
|
||||
if(!isSixAxis) startSixAxis();
|
||||
break;
|
||||
default:
|
||||
if(isSixAxis) stopSixAxis();
|
||||
}
|
||||
|
||||
u64 pressed = hidKeysDown(joyConId);
|
||||
u64 held = hidKeysHeld(joyConId);
|
||||
|
||||
JoystickPosition sticks[2];
|
||||
hidJoystickRead(&sticks[0], joyConId, JOYSTICK_LEFT);
|
||||
hidJoystickRead(&sticks[1], joyConId, JOYSTICK_RIGHT);
|
||||
|
||||
if(pressed & KEY_PLUS || held & KEY_PLUS) pad->button |= START_BUTTON;
|
||||
if(pressed & KEY_MINUS || held & KEY_MINUS) pad->button |= START_BUTTON;
|
||||
|
||||
if(pressed & KEY_B || held & KEY_B) pad->button |= A_BUTTON;
|
||||
if(pressed & KEY_A || held & KEY_A) pad->button |= A_BUTTON;
|
||||
if(pressed & KEY_Y || held & KEY_Y) pad->button |= B_BUTTON;
|
||||
if(pressed & KEY_X || held & KEY_X) pad->button |= B_BUTTON;
|
||||
|
||||
if(pressed & KEY_L || held & KEY_L) pad->button |= L_TRIG;
|
||||
if(pressed & KEY_ZL || held & KEY_ZL) pad->button |= Z_TRIG;
|
||||
if(pressed & KEY_R || held & KEY_R) pad->button |= R_TRIG;
|
||||
if(pressed & KEY_ZR || held & KEY_ZR) pad->button |= R_TRIG;
|
||||
|
||||
if(pressed & KEY_DUP || held & KEY_DUP) pad->button |= U_JPAD;
|
||||
if(pressed & KEY_DLEFT || held & KEY_DLEFT) pad->button |= L_JPAD;
|
||||
if(pressed & KEY_DDOWN || held & KEY_DDOWN) pad->button |= D_JPAD;
|
||||
if(pressed & KEY_DRIGHT || held & KEY_DRIGHT) pad->button |= R_JPAD;
|
||||
|
||||
if(sticks[1].dx > 0x4000) pad->button |= R_CBUTTONS;
|
||||
if(sticks[1].dx < -0x4000) pad->button |= L_CBUTTONS;
|
||||
if(sticks[1].dy > 0x4000) pad->button |= U_CBUTTONS;
|
||||
if(sticks[1].dy < -0x4000) pad->button |= D_CBUTTONS;
|
||||
|
||||
|
||||
s8 anaInput[2];
|
||||
anaInput[0] = sticks[0].dx / 0x100; //Stick X
|
||||
anaInput[1] = sticks[0].dy / 0x100; //Stick Y
|
||||
|
||||
if(isSixAxis) {
|
||||
hidSixAxisSensorValuesRead(&sixAxis, joyConId, 1);
|
||||
s8 gyroX = gyroToSByte(sixAxis.gyroscope.x); //Gyroscope X-Axis (Controller Y)
|
||||
s8 gyroY = gyroToSByte(sixAxis.gyroscope.y); //Gyroscope Y-Axis (Controller X)
|
||||
if(anaInput[0] == 0 && anaInput[1] == 0) {
|
||||
anaInput[0] = -gyroY;
|
||||
anaInput[1] = -gyroX;
|
||||
}
|
||||
}
|
||||
|
||||
pad->stick_x = anaInput[0];
|
||||
pad->stick_y = anaInput[1];
|
||||
}
|
||||
|
||||
static void joycon_rawkey(void) {
|
||||
return VK_INVALID;
|
||||
}
|
||||
|
||||
static void joycon_shutdown(void) {
|
||||
}
|
||||
|
||||
struct ControllerAPI controller_switch = {
|
||||
VK_INVALID,
|
||||
joycon_init,
|
||||
joycon_read,
|
||||
joycon_rawkey,
|
||||
NULL, // no rumble_play
|
||||
NULL, // no rumble_stop
|
||||
NULL, // no rebinding
|
||||
joycon_shutdown
|
||||
};
|
||||
|
||||
#endif
|
8
src/pc/controller/controller_switch.h
Normal file
8
src/pc/controller/controller_switch.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef CONTROLLER_SWITCH_H
|
||||
#define CONTROLLER_SWITCH_H
|
||||
|
||||
#include "controller_api.h"
|
||||
|
||||
extern struct ControllerAPI controller_switch;
|
||||
|
||||
#endif
|
|
@ -139,6 +139,10 @@ int test_vsync(void) {
|
|||
}
|
||||
|
||||
static inline void gfx_sdl_set_vsync(const bool enabled) {
|
||||
#ifdef TARGET_SWITCH
|
||||
SDL_GL_SetSwapInterval(2); // change to 1 if 60 fps patch is applied
|
||||
use_timer = false;
|
||||
#else
|
||||
if (enabled) {
|
||||
// try to detect refresh rate
|
||||
SDL_GL_SetSwapInterval(1);
|
||||
|
@ -155,6 +159,7 @@ static inline void gfx_sdl_set_vsync(const bool enabled) {
|
|||
|
||||
use_timer = true;
|
||||
SDL_GL_SetSwapInterval(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void gfx_sdl_set_fullscreen(void) {
|
||||
|
@ -210,13 +215,30 @@ static void gfx_sdl_init(const char *window_title) {
|
|||
//SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
|
||||
//SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);
|
||||
|
||||
#ifdef TARGET_SWITCH
|
||||
configWindow.fullscreen = false;
|
||||
// if docked, set 1920x1080
|
||||
if (appletGetOperationMode() == 1) {
|
||||
configWindow.w = 1920;
|
||||
configWindow.h = 1080;
|
||||
} else {
|
||||
configWindow.w = 1280;
|
||||
configWindow.h = 720;
|
||||
}
|
||||
int xpos = 0;
|
||||
int ypos = 0;
|
||||
#else
|
||||
int xpos = (configWindow.x == WAPI_WIN_CENTERPOS) ? SDL_WINDOWPOS_CENTERED : configWindow.x;
|
||||
int ypos = (configWindow.y == WAPI_WIN_CENTERPOS) ? SDL_WINDOWPOS_CENTERED : configWindow.y;
|
||||
#endif
|
||||
|
||||
wnd = SDL_CreateWindow(
|
||||
window_title,
|
||||
xpos, ypos, configWindow.w, configWindow.h,
|
||||
SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE
|
||||
SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN
|
||||
#ifndef TARGET_SWITCH
|
||||
| SDL_WINDOW_RESIZABLE
|
||||
#endif
|
||||
);
|
||||
ctx = SDL_GL_CreateContext(wnd);
|
||||
|
||||
|
@ -348,7 +370,6 @@ static double gfx_sdl_get_time(void) {
|
|||
return 0.0;
|
||||
}
|
||||
|
||||
|
||||
static void gfx_sdl_shutdown(void) {
|
||||
if (SDL_WasInit(0)) {
|
||||
if (ctx) { SDL_GL_DeleteContext(ctx); ctx = NULL; }
|
||||
|
|
|
@ -301,8 +301,10 @@ void main_func(void) {
|
|||
wm_api->main_loop(produce_one_frame);
|
||||
#else
|
||||
|
||||
#ifdef TARGET_WII_U
|
||||
#if defined(TARGET_WII_U)
|
||||
while (whb_window_is_running()) {
|
||||
#elif defined(TARGET_SWITCH)
|
||||
while (appletMainLoop()) {
|
||||
#else
|
||||
while (true) {
|
||||
#endif
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
const char *sys_ropaths[] = {
|
||||
".", // working directory
|
||||
"!", // executable directory
|
||||
#if defined(__linux__) || defined(__unix__)
|
||||
#if (defined(__linux__) || defined(__unix__)) && !defined(TARGET_SWITCH)
|
||||
// some common UNIX directories for read only stuff
|
||||
"/usr/local/share/sm64pc",
|
||||
"/usr/share/sm64pc",
|
||||
|
|
Loading…
Add table
Reference in a new issue