Skip to content

Commit

Permalink
Enable networking and stdio on Switch platform
Browse files Browse the repository at this point in the history
  • Loading branch information
rsn8887 authored and AJenbo committed Nov 24, 2019
1 parent 2dedfcb commit e0e3bd7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Expand Up @@ -283,6 +283,7 @@ set(BIN_TARGET devilutionx)

if(SWITCH)
list(APPEND devilutionx_SRCS
SourceX/platform/switch/network.cpp
SourceX/platform/switch/keyboard.cpp
SourceX/platform/switch/docking.cpp)
set(BIN_TARGET devilutionx.elf)
Expand Down
8 changes: 8 additions & 0 deletions SourceX/main.cpp
@@ -1,5 +1,8 @@
#include <string>
#include <SDL.h>
#ifdef __SWITCH__
#include "platform/switch/network.h"
#endif

#include "devilution.h"

Expand All @@ -25,5 +28,10 @@ static std::string build_cmdline(int argc, char **argv)
int main(int argc, char **argv)
{
auto cmdline = build_cmdline(argc, argv);

#ifdef __SWITCH__
switch_enable_network();
#endif

return dvl::WinMain(NULL, NULL, (char *)cmdline.c_str(), 0);
}
23 changes: 23 additions & 0 deletions SourceX/platform/switch/network.cpp
@@ -0,0 +1,23 @@
#include <stdlib.h>
#include <unistd.h>
#include <switch.h>
#include "platform/switch/network.h"

static int nxlink_sock = -1; // for stdio on Switch

void switch_enable_network()
{
// enable network and stdio on Switch
socketInitializeDefault();
// enable error messages via nxlink on Switch
nxlink_sock = nxlinkStdio();
atexit(switch_disable_network);
}

void switch_disable_network()
{
// disable network and stdio on Switch
if (nxlink_sock != -1)
close(nxlink_sock);
socketExit();
}
4 changes: 4 additions & 0 deletions SourceX/platform/switch/network.h
@@ -0,0 +1,4 @@
#pragma once

void switch_enable_network();
void switch_disable_network();

0 comments on commit e0e3bd7

Please sign in to comment.