Skip to content

Commit

Permalink
bugfix: restore 3DS build
Browse files Browse the repository at this point in the history
Cleanup network code
Add 3dslink debug code
  • Loading branch information
carstene1ns committed Dec 29, 2024
1 parent da53123 commit b0981ba
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 42 deletions.
2 changes: 1 addition & 1 deletion builds/cmake/OJ-misc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ if(CPPCHECK_EXECUTABLE)
-I${CMAKE_CURRENT_SOURCE_DIR}/src
-U__SYMBIAN32__ -UUIQ3 -UENABLE_JJ2 # unmaintained
-UGP2X -UWIZ -UDINGOO -UCAANOO -UGAMESHELL # contributed
-UPSP -U__vita__ -U_3DS -U__wii__ # homebrew
-UPSP -U__vita__ -U__3DS__ -U__wii__ # homebrew
-U__riscos__
#--enable=information
)
Expand Down
2 changes: 1 addition & 1 deletion src/io/controls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
#define DEFAULT_BUTTON_PAUSE (5)
#define DEFAULT_BUTTON_YES (-1)
#define DEFAULT_BUTTON_NO (-1)
#elif defined (_3DS)
#elif defined (__3DS__)
#define DEFAULT_BUTTON_UP (-1)
#define DEFAULT_BUTTON_DOWN (-1)
#define DEFAULT_BUTTON_LEFT (-1)
Expand Down
2 changes: 1 addition & 1 deletion src/io/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <unistd.h>
#include <miniz.h>

#if !(defined(_WIN32) || defined(WII) || defined(PSP) || defined(_3DS))
#if !(defined(_WIN32) || defined(WII) || defined(PSP))
#define UPPERCASE_FILENAMES
#define LOWERCASE_FILENAMES
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/io/gfx/video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ void Video::clearScreen (int index) {
#if defined(CAANOO) || defined(WIZ) || defined(GP2X) || defined(GAMESHELL)
// always 240 lines cleared to black
memset(video.screen->pixels, index, 320*240);
#elif defined (_3DS)
#elif defined (__3DS__)
memset(video.screen->pixels, index, 400*240);
#else
SDL_FillRect(canvas, NULL, index);
Expand Down
2 changes: 1 addition & 1 deletion src/io/gfx/video.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
#define NO_RESIZE

#define FULLSCREEN_FLAGS (SDL_FULLSCREEN | SDL_SWSURFACE | SDL_HWPALETTE)
#elif defined(_3DS)
#elif defined(__3DS__)
#define DEFAULT_SCREEN_WIDTH 400
#define DEFAULT_SCREEN_HEIGHT 240

Expand Down
34 changes: 8 additions & 26 deletions src/io/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,8 @@
#ifndef MSG_NOSIGNAL
#define MSG_NOSIGNAL 0
#endif
#ifdef _3DS
#include <3ds.h>
#include <fcntl.h>
#include <malloc.h>
static u32* socBuffer = NULL;
#define SOC_BUFFERSIZE 0x100000 // maybe 0x80000 is enough
#ifdef __3DS__
#include "platforms/3ds.h"
#endif
#elif defined(__wii__)
#include <network.h>
Expand All @@ -81,9 +77,9 @@ Network::Network () {

// Start Windows Sockets
WSAStartup(MAKEWORD(1, 0), &WSAData);
#elif defined(_3DS)
socBuffer = static_cast<u32*>(memalign(0x1000, SOC_BUFFERSIZE));
socInit(socBuffer, SOC_BUFFERSIZE);
#elif defined(__3DS__)
if (!N3DS_NetHasConsole())
N3DS_NetInit();
#endif
#elif defined USE_SDL_NET
# ifdef __wii__
Expand All @@ -107,9 +103,9 @@ Network::~Network () {
#ifdef _WIN32
// Shut down Windows Sockets
WSACleanup();
#elif defined(_3DS)
socExit();
free(socBuffer);
#elif defined(__3DS_)
if (!N3DS_NetHasConsole())
N3DS_NetExit();
#endif
#elif defined USE_SDL_NET
SDLNet_Quit();
Expand All @@ -136,12 +132,8 @@ int Network::host () {


// Make the socket non-blocking
#ifdef _3DS
fcntl(sock, F_SETFL, fcntl(sock, F_GETFL, 0) | O_NONBLOCK);
#else
int nonblock = 1;
ioctl(sock, FIONBIO, (u_long *)&nonblock);
#endif

memset(&sockAddr, 0, sizeof(sockaddr_in));
sockAddr.sin_family = AF_INET;
Expand Down Expand Up @@ -198,21 +190,15 @@ int Network::join (char *address) {
int sock, con;

// Create socket

sock = socket(AF_INET, SOCK_STREAM, 0);

if (sock == -1) return E_N_SOCKET;

// Make socket non-blocking
#ifdef _3DS
fcntl(sock, F_SETFL, fcntl(sock, F_GETFL, 0) | O_NONBLOCK);
#else
con = 1;
ioctl(sock, FIONBIO, (u_long *)&con);
#endif

// Connect to server

memset(&sockAddr, 0, sizeof(sockaddr_in));
sockAddr.sin_family = AF_INET;
sockAddr.sin_port = htons(NET_PORT);
Expand Down Expand Up @@ -321,12 +307,8 @@ int Network::accept (int sock) {
if (clientSocket != -1) {

// Make the socket non-blocking
#ifdef _3DS
fcntl(clientSocket, F_SETFL, fcntl(sock, F_GETFL, 0) | O_NONBLOCK);
#else
length = 1;
ioctl(clientSocket, FIONBIO, (u_long *)&length);
#endif

}

Expand Down
4 changes: 2 additions & 2 deletions src/io/sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
#define OJ_SDL2 0
#endif

#if defined(__SYMBIAN32__) || defined(_3DS) || defined(PSP) || defined(__vita__)
#if defined(__SYMBIAN32__) || defined(__3DS__) || defined(PSP) || defined(__vita__)
#define SOUND_FREQ 22050
#else
#define SOUND_FREQ 44100
#endif

#if defined(GP2X) || defined(PSP) || defined(_3DS) || defined(__vita__)
#if defined(GP2X) || defined(PSP) || defined(__3DS__) || defined(__vita__)
#define SOUND_SAMPLES 512
#else
#define SOUND_SAMPLES 2048
Expand Down
4 changes: 2 additions & 2 deletions src/menu/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include "io/sound.h"
#include "loop.h"
#include "util.h"
#ifdef _3DS
#ifdef __3DS__
#include "platforms/3ds.h"
#elif defined(__vita__)
#include "platforms/psvita.h"
Expand Down Expand Up @@ -176,7 +176,7 @@ int Menu::textInput (const char* request, char*& text, bool ip) {

char *input;

#ifdef _3DS
#ifdef __3DS__

int res;

Expand Down
2 changes: 1 addition & 1 deletion src/menu/setupmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ int SetupMenu::setupMain () {

case 1:

#if !(defined(CAANOO) || defined(WIZ) || defined(GP2X) || defined(PSP) || defined(_3DS) || defined(__vita__))
#if !(defined(CAANOO) || defined(WIZ) || defined(GP2X) || defined(PSP) || defined(__3DS__) || defined(__vita__))
if (setupKeyboard() == E_QUIT) return E_QUIT;
#else
if (message("FEATURE NOT AVAILABLE") == E_QUIT) return E_QUIT;
Expand Down
48 changes: 47 additions & 1 deletion src/platforms/3ds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,65 @@

#include "3ds.h"

#ifdef _3DS
#ifdef __3DS__

#include <3ds.h>
#include <malloc.h>
#include "util.h"
#include "io/file.h"
#include "io/log.h"

namespace {
constexpr int SOC_BUFFERSIZE = 0x100000;

u32 *socBuffer = nullptr;
int sock = -1;
}

void N3DS_Init() {
// file system
romfsInit();

#ifndef NDEBUG
// network console
N3DS_NetInit();
sock = link3dsStdio();
#endif
}

void N3DS_Exit() {
romfsExit();

#ifndef NDEBUG
N3DS_NetExit();
#endif
}

void N3DS_NetInit() {
socBuffer = static_cast<u32*>(memalign(0x1000, SOC_BUFFERSIZE));
if(!socBuffer) {
LOG_WARN("Failed to allocate soc:u buffer");
return;
}

int ret = socInit(socBuffer, SOC_BUFFERSIZE);
if (ret != 0) {
LOG_WARN("Failed to initialize soc:u: 0x%08X\n", (unsigned int)ret);
}
}

void N3DS_NetExit() {
if(sock > 0)
close(sock);

socExit();

if(socBuffer)
free(socBuffer);
}

bool N3DS_NetHasConsole() {
return sock > 0;
}

void N3DS_AddGamePaths() {
Expand Down
6 changes: 5 additions & 1 deletion src/platforms/3ds.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@
#ifndef _3DS_H
#define _3DS_H

#ifdef _3DS
#ifdef __3DS__

void N3DS_Init();
void N3DS_Exit();

void N3DS_NetInit();
void N3DS_NetExit();
bool N3DS_NetHasConsole();

void N3DS_AddGamePaths();

void N3DS_ErrorNoDatafiles();
Expand Down
8 changes: 4 additions & 4 deletions src/platforms/platforms.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ inline void PLATFORM_Init() {
WII_Init();
#endif

#ifdef _3DS
#ifdef __3DS__
N3DS_Init();
#endif

Expand All @@ -46,7 +46,7 @@ inline void PLATFORM_Init() {
}

inline void PLATFORM_Exit() {
#ifdef _3DS
#ifdef __3DS__
N3DS_Exit();
#endif
}
Expand All @@ -60,7 +60,7 @@ inline void PLATFORM_AddGamePaths() {
SYMBIAN_AddGamePaths();
#endif

#ifdef _3DS
#ifdef __3DS__
N3DS_AddGamePaths();
#endif

Expand Down Expand Up @@ -98,7 +98,7 @@ inline void PLATFORM_ErrorNoDatafiles() {
PSP_ErrorNoDatafiles();
#endif

#ifdef _3DS
#ifdef __3DS__
N3DS_ErrorNoDatafiles();
#endif
}
Expand Down

0 comments on commit b0981ba

Please sign in to comment.