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
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/src/engine/particles
${CMAKE_CURRENT_SOURCE_DIR}/src/enhancements
${CMAKE_CURRENT_SOURCE_DIR}/src/enhancements/freecam
${CMAKE_CURRENT_SOURCE_DIR}/raphnetraw/src
)

# Collect source files to build the executable
Expand Down Expand Up @@ -290,6 +291,8 @@ file(GLOB_RECURSE ALL_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
"src/enhancements/freecam/*.h"
"src/engine/*.cpp"
"src/engine/*.h"
"raphnetraw/src/*.c"
"raphnetraw/src/*.h"
"Resource.rc"
)

Expand Down Expand Up @@ -461,6 +464,9 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU|Clang|AppleClang")
)
endif()

find_package(hidapi REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE hidapi::hidapi)

if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
find_package(Ogg CONFIG REQUIRED)
link_libraries(Ogg::ogg)
Expand Down
15 changes: 12 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
#include "port/Engine.h"
#include "engine/Matrix.h"

#include "raphnetraw/src/plugin_front.h"
#include "port/Raphnet.h"

// Declarations (not in this file)
void func_80091B78(void);

Expand Down Expand Up @@ -333,7 +336,8 @@ void calculate_delta_time(void) {
void init_controllers(void) {
osCreateMesgQueue(&gSIEventMesgQueue, &gSIEventMesgBuf[0], ARRAY_COUNT(gSIEventMesgBuf));
osSetEventMesg(OS_EVENT_SI, &gSIEventMesgQueue, OS_MESG_32(0x33333333));
osContInit(&gSIEventMesgQueue, &gControllerBits, gControllerStatuses);
// osContInit(&gSIEventMesgQueue, &gControllerBits, gControllerStatuses);
Raphnet_osContGetInitData(&gControllerBits, gControllerStatuses);
if ((gControllerBits & 1) == 0) {
sIsController1Unplugged = true;
} else {
Expand Down Expand Up @@ -390,9 +394,11 @@ void update_controller(s32 index) {
void read_controllers(void) {
OSMesg msg;

osContStartReadData(&gSIEventMesgQueue);
// osContStartReadData(&gSIEventMesgQueue);
Raphnet_osContStartReadData(&gSIEventMesgQueue);
// osRecvMesg(&gSIEventMesgQueue, &msg, OS_MESG_BLOCK);
osContGetReadData(gControllerPads);
// osContGetReadData(gControllerPads);
Raphnet_osContGetReadData(gControllerPads);
update_controller(0);
update_controller(1);
update_controller(2);
Expand Down Expand Up @@ -1151,6 +1157,9 @@ void thread5_game_loop(void) {
void thread5_iteration(void) {
func_800CB2C4();
calculate_delta_time();

Raphnet_osContGetInitData(&gControllerBits, gControllerStatuses);

#ifdef TARGET_N64
while (true) {
func_800CB2C4();
Expand Down
6 changes: 6 additions & 0 deletions src/port/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ extern "C" {
#include "code_800029B0.h"
#include "code_80057C60.h"
// #include "engine/wasm.h"

// Raphnet Raw
#include "raphnetraw/src/plugin_front.h"
}

extern "C" void Graphics_PushFrame(Gfx* pool) {
Expand Down Expand Up @@ -958,6 +961,8 @@ extern "C"
#endif
// load_wasm();
GameEngine::Create();
RaphnetInitialize();
ScanControllers();
audio_init();
sound_init();

Expand Down Expand Up @@ -989,6 +994,7 @@ extern "C"
push_frame();
}
CustomEngineDestroy();
RaphnetShutdown();
// GameEngine::Instance->ProcessFrame(push_frame);
GameEngine::Instance->Destroy();
return 0;
Expand Down
116 changes: 116 additions & 0 deletions src/port/Raphnet.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#include <libultraship/libultraship.h>

extern "C" {
#include <raphnetraw/src/plugin_front.h>
}

typedef struct {
/* 0x0 */ u8 dummy;
/* 0x1 */ u8 txsize;
/* 0x2 */ u8 rxsize;
/* 0x3 */ u8 cmd;
/* 0x4 */ u16 button;
/* 0x6 */ s8 stick_x;
/* 0x7 */ s8 stick_y;
} __OSContReadFormat;

u8 __osContLastCmd;
u8 _osContNumControllers;
OSPifRam __osContPifRam;
#define CHNL_ERR(format) ((format.rxsize & CHNL_ERR_MASK) >> 4)

#define RAPHNET_CONTROLLERS 4
#define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0]))

extern "C" void Raphnet_osContGetInitData(u8* bitpattern, OSContStatus* status)
{
u8* ptr;
__OSContRequestHeader response;
s32 i;
u8 bits;

bits = 0;
ptr = (u8*) __osContPifRam.ram;
for (i = 0; i < _osContNumControllers; i++, ptr += sizeof(response), status++) {
response = *((__OSContRequestHeader*) (ptr));
status->err_no = CHNL_ERR(response);
if (status->err_no == 0) {
status->type = response.typel << 8 | response.typeh;
status->status = response.status;

bits |= 1 << i;
}
}

*bitpattern = 1;
status->status |= 1;

}

void __osPackReadData(void);
extern "C" int32_t Raphnet_osContStartReadData(OSMesgQueue* mesg) {
unsigned char* ptr = (unsigned char*)__osContPifRam.ram;

__osPackReadData();

for (int ch = 0; ch < _osContNumControllers; ch++) {
ReadController(ch, ptr);

int tx = ptr[0] & 0x3F;
int rx = ptr[1] & 0x3F;

ptr += 2 + tx + rx;
}

ReadController(-1, NULL); // poll the controllers and set data
return 0;
}

extern "C" void Raphnet_osContGetReadData(OSContPad* pad) {
u8* ptr = (u8*) __osContPifRam.ram;
__OSContReadFormat readformat;
s32 i;

for (i = 0; i < _osContNumControllers; i++, ptr += sizeof(readformat), pad++) {
readformat = *(__OSContReadFormat*) ptr;
pad->err_no = CHNL_ERR(readformat);

if (pad->err_no != 0) {
printf("gamepad error\n");
continue;
}

pad->button = readformat.button;
pad->stick_x = readformat.stick_x;
pad->stick_y = readformat.stick_y;
}
}

void __osPackReadData() {
u8* ptr = (u8*) __osContPifRam.ram;
__OSContReadFormat readformat;
s32 i;

for (i = 0; i < ARRAY_COUNT(__osContPifRam.ram) + 1; i++) {
__osContPifRam.ram[i] = 0;
}

__osContPifRam.status = CONT_CMD_EXE;
readformat.dummy = CONT_CMD_NOP;
readformat.txsize = CONT_CMD_READ_BUTTON_TX;
readformat.rxsize = CONT_CMD_READ_BUTTON_RX;
readformat.cmd = CONT_CMD_READ_BUTTON;
readformat.button = 0xFFFF;
readformat.stick_x = -1;
readformat.stick_y = -1;

for (i = 0; i < _osContNumControllers; i++) {
*(__OSContReadFormat*) ptr = readformat;
ptr += sizeof(readformat);
}
*ptr = CONT_CMD_END;
}

void Raphnet_ScanControllers(void) {
_osContNumControllers = ScanControllers();
}
17 changes: 17 additions & 0 deletions src/port/Raphnet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef PORT_RAPHNET_H
#define PORT_RAPHNET_H

#ifdef __cplusplus
extern "C" {
#endif
#include "libultraship/libultra/message.h"

void Raphnet_osContGetInitData(u8* bitpattern, OSContStatus* status);
int32_t Raphnet_osContStartReadData(OSMesgQueue* mesg);
void Raphnet_osContGetReadData(OSContPad* pad);

#ifdef __cplusplus
}
#endif

#endif // PORT_RAPHNET_H
3 changes: 2 additions & 1 deletion vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"tinyxml2",
"spdlog",
"libogg",
"libvorbis"
"libvorbis",
"hidapi"
],
"builtin-baseline": "2e58bb35ff7a3a037920d959ce20cb4d8c22319a"
}
Loading