Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ RENDER_API ?= GL
WINDOW_API ?= SDL2
# Audio backends: SDL1, SDL2
AUDIO_API ?= SDL2
# Controller backends (can have multiple, space separated): SDL2, SDL1
# Controller backends (can have multiple, space separated): SDL2, SDL1, RAPHNET
CONTROLLER_API ?= SDL2

# Misc settings for EXTERNAL_DATA
Expand Down Expand Up @@ -316,6 +316,10 @@ LEVEL_DIRS := $(patsubst levels/%,%,$(dir $(wildcard levels/*/header.h)))
SRC_DIRS := src src/engine src/game src/audio src/menu src/buffers actors levels bin data assets src/pc src/pc/gfx src/pc/audio src/pc/controller src/pc/fs src/pc/fs/packtypes
ASM_DIRS :=

ifneq (,$(findstring RAPHNET,${CONTROLLER_API}))
SRC_DIRS += src/pc/controller/raphnet
endif

ifeq ($(DISCORDRPC),1)
SRC_DIRS += src/pc/discord
endif
Expand Down Expand Up @@ -571,6 +575,10 @@ ifneq ($(SDL1_USED)$(SDL2_USED),00)
endif
endif

ifneq (,$(findstring RAPHNET,${CONTROLLER_API}))
BACKEND_LDFLAGS += -lhidapi
endif

ifeq ($(WINDOWS_BUILD),1)
CC_CHECK := $(CC) -fsyntax-only -fsigned-char $(BACKEND_CFLAGS) $(INCLUDE_CFLAGS) -Wall -Wextra -Wno-format-security $(VERSION_CFLAGS) $(GRUCODE_CFLAGS)
CFLAGS := $(OPT_FLAGS) $(INCLUDE_CFLAGS) $(BACKEND_CFLAGS) $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -fno-strict-aliasing -fwrapv
Expand Down
4 changes: 4 additions & 0 deletions src/pc/controller/controller_entry_point.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
#include "controller_recorded_tas.h"
#include "controller_keyboard.h"
#include "controller_sdl.h"
#include "controller_raphnet.h"

// Analog camera movement by Pathétique (github.com/vrmiguel), y0shin and Mors
// Contribute or communicate bugs at github.com/vrmiguel/sm64-analog-camera

static struct ControllerAPI *controller_implementations[] = {
&controller_recorded_tas,
#if defined(CAPI_RAPHNET)
&controller_raphnet,
#endif
#if defined(CAPI_SDL2) || defined(CAPI_SDL1)
&controller_sdl,
#endif
Expand Down
121 changes: 121 additions & 0 deletions src/pc/controller/controller_raphnet.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#ifdef CAPI_RAPHNET

#include <stdarg.h>
#include <stdio.h>

#include "controller_api.h"
#include "raphnet/plugin_back.h"
#include "lib/src/osContInternal.h"
#include "macros.h"

static int l_PluginInit = 0;
static int n_controllers = 0;

static u32 pifRam[16];

static void DebugMessage(int level, const char *message, ...) {
switch (level) {
case PB_MSG_ERROR:
printf("Raphnet: [ERROR] ");
break;
case PB_MSG_WARNING:
printf("Raphnet: [WARNING] ");
break;
case PB_MSG_INFO:
printf("Raphnet: [INFO] ");
break;
case PB_MSG_STATUS:
printf("Raphnet: [STATUS] ");
break;
case PB_MSG_VERBOSE:
printf("Raphnet: [VERBOSE] ");
break;
default:
printf("Raphnet: ");
break;
}

va_list args;
va_start(args, message);
vprintf(message, args);
va_end(args);
}

static void controller_raphnet_init() {
if (l_PluginInit) {
return;
}
l_PluginInit = 1;

pb_init(DebugMessage);

n_controllers = pb_scanControllers();
if (n_controllers <= 0) {
DebugMessage(PB_MSG_ERROR, "No adapters detected\n");
return;
}

pb_romOpen();
}

static void controller_raphnet_read(OSContPad *pad) {
if (n_controllers <= 0) {
return;
}

u8 *cmdBufPtr;
OSContPackedRequest request;
s32 i;
cmdBufPtr = (u8 *) pifRam;

for (i = 0; i < 16; i++) {
pifRam[i] = 0;
}

request.padOrEnd = 0xff;
request.txLen = 1;
request.rxLen = 4;
request.command = 1;
request.data1 = 0xff;
request.data2 = 0xff;
request.data3 = 0xff;
request.data4 = 0xff;
for (i = 0; i < 4; i++) {
* (OSContPackedRequest *) cmdBufPtr = request;
cmdBufPtr += sizeof(OSContPackedRequest);
}
*cmdBufPtr = 0xfe;

pb_readController(0, (u8 *) pifRam + 1);
pb_readController(-1, NULL);

OSContPackedRead response = * (OSContPackedRead *) pifRam;
pad->errnum = (response.rxLen & 0xc0) >> 4;
if (pad->errnum == 0) {
pad->button = BE_TO_HOST16(response.button);
pad->stick_x = response.rawStickX;
pad->stick_y = response.rawStickY;
}
}

static u32 controller_raphnet_rawkey() {
return VK_INVALID;
}

static void controller_raphnet_shutdown() {
pb_romClosed();
pb_shutdown();
}

struct ControllerAPI controller_raphnet = {
VK_INVALID,
controller_raphnet_init,
controller_raphnet_read,
controller_raphnet_rawkey,
NULL,
NULL,
NULL,
controller_raphnet_shutdown,
};

#endif // CAPI_RAPHNET
8 changes: 8 additions & 0 deletions src/pc/controller/controller_raphnet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef CONTROLLER_RAPHNET_H
#define CONTROLLER_RAPHNET_H

#include "controller_api.h"

extern struct ControllerAPI controller_raphnet;

#endif
Loading