Skip to content

Commit 5a28186

Browse files
Initial, hacky nintendo switch support
1 parent 7475264 commit 5a28186

15 files changed

Lines changed: 139 additions & 21 deletions

File tree

3rdparty/linenoise/linenoise.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,11 @@
114114
//#define snprintf _snprintf
115115
#endif
116116
#else
117+
#ifndef __DEVKITPRO__
117118
#include <termios.h>
118119
#include <sys/ioctl.h>
119120
#include <poll.h>
121+
#endif
120122
#define USE_TERMIOS
121123
#define HAVE_UNISTD_H
122124
#endif
@@ -248,7 +250,9 @@ static int checkForColor(const char *buf, int *colors, int *size)
248250

249251
#if defined(USE_TERMIOS)
250252
static void linenoiseAtExit(void);
253+
#ifndef __DEVKITPRO__
251254
static struct termios orig_termios; /* in order to restore at exit */
255+
#endif
252256
static int rawmode = 0; /* for atexit() function to check if restore is needed*/
253257
static int atexit_registered = 0; /* register atexit just 1 time */
254258

@@ -269,6 +273,7 @@ static int isUnsupportedTerm(void) {
269273
}
270274

271275
static int enableRawMode(struct current *current) {
276+
#ifndef __DEVKITPRO__
272277
struct termios raw;
273278

274279
current->fd = STDIN_FILENO;
@@ -280,12 +285,14 @@ static int enableRawMode(struct current *current) {
280285
errno = ENOTTY;
281286
return -1;
282287
}
288+
#endif
283289

284290
if (!atexit_registered) {
285291
atexit(linenoiseAtExit);
286292
atexit_registered = 1;
287293
}
288294

295+
#ifndef __DEVKITPRO__
289296
raw = orig_termios; /* modify the original mode */
290297
/* input modes: no break, no CR to NL, no parity check, no strip char,
291298
* no start/stop output control. */
@@ -306,20 +313,25 @@ static int enableRawMode(struct current *current) {
306313
goto fatal;
307314
}
308315
rawmode = 1;
316+
#endif
309317
return 0;
310318
}
311319

312320
static void disableRawMode(struct current *current) {
321+
#ifndef __DEVKITPRO__
313322
/* Don't even check the return value as it's too late. */
314323
if (rawmode && tcsetattr(current->fd,TCSADRAIN,&orig_termios) != -1)
315324
rawmode = 0;
325+
#endif
316326
}
317327

318328
/* At exit we'll try to fix the terminal to the initial conditions. */
319329
static void linenoiseAtExit(void) {
330+
#ifndef __DEVKITPRO__
320331
if (rawmode) {
321332
tcsetattr(STDIN_FILENO, TCSADRAIN, &orig_termios);
322333
}
334+
#endif
323335
linenoiseHistoryFree();
324336
}
325337

@@ -388,8 +400,9 @@ static void setCursorPos(struct current *current, int x)
388400
*/
389401
static int fd_read_char(int fd, int timeout)
390402
{
391-
struct pollfd p;
392403
unsigned char c;
404+
#ifndef __DEVKITPRO__
405+
struct pollfd p;
393406

394407
p.fd = fd;
395408
p.events = POLLIN;
@@ -398,6 +411,7 @@ static int fd_read_char(int fd, int timeout)
398411
/* timeout */
399412
return -1;
400413
}
414+
#endif
401415
if (read(fd, &c, 1) != 1) {
402416
return -1;
403417
}
@@ -410,8 +424,9 @@ static int fd_read_char(int fd, int timeout)
410424
*/
411425
static int fd_read(struct current *current)
412426
{
413-
struct pollfd p;
414427
int ret;
428+
#ifndef __DEVKITPRO__
429+
struct pollfd p;
415430
p.fd = current->fd;
416431
p.events = POLLIN;
417432
while(1) {
@@ -427,6 +442,7 @@ static int fd_read(struct current *current)
427442
else
428443
break;
429444
}
445+
#endif
430446
#ifdef USE_UTF8
431447
char buf[4];
432448
int n;
@@ -499,12 +515,14 @@ static int queryCursor(int fd, int* cols)
499515
*/
500516
static int getWindowSize(struct current *current)
501517
{
518+
#ifndef __DEVKITPRO__
502519
struct winsize ws;
503520

504521
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == 0 && ws.ws_col != 0) {
505522
current->cols = ws.ws_col;
506523
return 0;
507524
}
525+
#endif
508526

509527
/* Failed to query the window size. Perhaps we are on a serial terminal.
510528
* Try to query the width by sending the cursor as far to the right

3rdparty/lsqlite3/lsqlite3.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,6 +1209,7 @@ static int db_create_collation(lua_State *L) {
12091209
return 0;
12101210
}
12111211

1212+
#ifndef __DEVKITPRO__
12121213
/* Thanks to Wolfgang Oertl...
12131214
*/
12141215
static int db_load_extension(lua_State *L) {
@@ -1236,6 +1237,7 @@ static int db_load_extension(lua_State *L) {
12361237
sqlite3_free(errmsg);
12371238
return 2;
12381239
}
1240+
#endif
12391241

12401242
/*
12411243
** trace callback:
@@ -2192,7 +2194,9 @@ static const luaL_Reg dblib[] = {
21922194
{"create_function", db_create_function },
21932195
{"create_aggregate", db_create_aggregate },
21942196
{"create_collation", db_create_collation },
2197+
#ifndef __DEVKITPRO__
21952198
{"load_extension", db_load_extension },
2199+
#endif
21962200

21972201
{"trace", db_trace },
21982202
{"progress_handler", db_progress_handler },

3rdparty/sqlite3/sqlite3.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,9 @@ SQLITE_PRIVATE const char **sqlite3CompileOptions(int *pnOpt){
926926
#else
927927
/* This is not VxWorks. */
928928
#define OS_VXWORKS 0
929+
#ifndef __DEVKITPRO__
929930
#define HAVE_FCHOWN 1
931+
#endif
930932
#define HAVE_READLINK 1
931933
#define HAVE_LSTAT 1
932934
#endif /* defined(_WRS_KERNEL) */
@@ -33440,7 +33442,9 @@ SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
3344033442
#include <sys/types.h>
3344133443
#include <sys/stat.h>
3344233444
#include <fcntl.h>
33445+
#ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE
3344333446
#include <sys/ioctl.h>
33447+
#endif
3344433448
#include <unistd.h>
3344533449
/* #include <time.h> */
3344633450
#include <sys/time.h>

Makefile.libretro

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,13 @@ ifeq ($(platform),android-x86_64)
151151
PTR64 :=
152152
endif
153153

154-
ifeq ($(platform),linux32)
154+
ifeq ($(platform),libnx)
155155
PTR64 := 0
156+
PLATFLAGS += TARGETOS="libnx" PLATFORM="arm64" FORCE_DRC_C_BACKEND="1"
157+
LIBRETRO_CPU :=
158+
ARCH :=
159+
LIBRETRO_OS :=
160+
PTR64 :=
156161
endif
157162

158163
ifeq ($(platform),osx)
@@ -243,6 +248,7 @@ build:
243248
@mv $(SUBTARGET)_libretro.dll $(SAME_SYSTEM)_libretro.dll 2> /dev/null || true
244249
@mv $(SUBTARGET)_libretro.so $(SAME_SYSTEM)_libretro.so 2> /dev/null || true
245250
@mv $(SUBTARGET)_libretro_android.so $(SAME_SYSTEM)_libretro_android.so 2> /dev/null || true
251+
@mv $(SUBTARGET)_libretro.a $(SAME_SYSTEM)_libretro.a 2> /dev/null || true
246252
@echo "Done!"
247253

248254
vs2015:

makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,18 @@ openbsd_x86: generate $(PROJECTDIR)/$(MAKETYPE)-openbsd/Makefile
14361436
$(SILENT) $(MAKE) -C $(PROJECTDIR)/$(MAKETYPE)-openbsd config=$(CONFIG)32 precompile
14371437
$(SILENT) $(MAKE) -C $(PROJECTDIR)/$(MAKETYPE)-openbsd config=$(CONFIG)32
14381438

1439+
#-------------------------------------------------
1440+
# gmake-linux
1441+
#-------------------------------------------------
1442+
1443+
$(PROJECTDIR)/$(MAKETYPE)-libnx/Makefile: makefile $(SCRIPTS) $(GENIE)
1444+
$(SILENT) $(GENIE) $(PARAMS) $(TARGET_PARAMS) --gcc=libnx --gcc_version=$(GCC_VERSION) $(MAKETYPE)
1445+
1446+
.PHONY: libnx-arm64
1447+
libnx: generate $(PROJECTDIR)/$(MAKETYPE)-libnx/Makefile
1448+
$(SILENT) $(MAKE) $(MAKEPARAMS) -C $(PROJECTDIR)/$(MAKETYPE)-libnx-arm64 config=$(CONFIG) precompile
1449+
$(SILENT) $(MAKE) $(MAKEPARAMS) -C $(PROJECTDIR)/$(MAKETYPE)-libnx-arm64 config=$(CONFIG)
1450+
14391451
#-------------------------------------------------
14401452
# Clean/bootstrap
14411453
#-------------------------------------------------

scripts/genie.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ newoption {
126126
{ "windows", "Windows" },
127127
{ "haiku", "Haiku" },
128128
{ "solaris", "Solaris SunOS" },
129+
{ "libnx", "libnx" },
129130
},
130131
}
131132

scripts/src/3rdparty.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ end
857857
"LUA_COMPAT_5_1",
858858
"LUA_COMPAT_5_2",
859859
}
860-
if not (_OPTIONS["targetos"]=="windows") and not (_OPTIONS["targetos"]=="asmjs") then
860+
if not (_OPTIONS["targetos"]=="windows") and not (_OPTIONS["targetos"]=="asmjs") and not (_OPTIONS["targetos"]=="libnx") then
861861
defines {
862862
"LUA_USE_POSIX",
863863
}
@@ -981,6 +981,10 @@ if _OPTIONS["vs"]=="clangcl" then
981981
end
982982

983983
configuration { }
984+
defines {
985+
"SQLITE_OMIT_WAL",
986+
"SQLITE_OMIT_LOAD_EXTENSION",
987+
}
984988

985989
files {
986990
MAME_DIR .. "3rdparty/sqlite3/sqlite3.c",

scripts/src/main.lua

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ else
2424
project (_subtarget)
2525
end
2626
uuid (os.uuid(_target .."_" .. _subtarget))
27-
kind "ConsoleApp"
27+
if _OPTIONS["targetos"]=="libnx" then
28+
kind "StaticLib"
29+
else
30+
kind "ConsoleApp"
31+
end
2832

2933
configuration { "android*" }
3034
linkoptions {
@@ -65,7 +69,9 @@ end
6569
targetextension ".bc"
6670
-- BEGIN libretro overrides to MAME's GENie build
6771
configuration { "libretro*" }
68-
kind "SharedLib"
72+
if _OPTIONS["targetos"]~="libnx" then
73+
kind "SharedLib"
74+
end
6975
targetsuffix "_libretro"
7076
if _OPTIONS["targetos"]=="android" then
7177
targetsuffix "_libretro_android"

scripts/src/osd/retro.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ if BASE_TARGETOS=="unix" then
5555
"nsl",
5656
}
5757
else
58-
links {
59-
"util",
60-
}
58+
-- What are you needed for? nobody knows...
59+
-- links {
60+
-- "util",
61+
-- }
6162
end
6263
end
6364

scripts/toolchain.lua

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ newoption {
3333
{ "osx", "OSX (GCC compiler)" },
3434
{ "osx-clang", "OSX (Clang compiler)" },
3535
{ "solaris", "Solaris" },
36+
{ "libnx", "libnx" },
3637
},
3738
}
3839

@@ -208,6 +209,13 @@ function toolchain(_buildDir, _subDir)
208209
premake.gcc.ar = toolchainPrefix .. "ar"
209210
location (_buildDir .. "projects/" .. _subDir .. "/".. _ACTION .. "-osx-clang")
210211
end
212+
213+
if "libnx" == _OPTIONS["gcc"] then
214+
premake.gcc.cc = "aarch64-none-elf-gcc"
215+
premake.gcc.cxx = "aarch64-none-elf-g++"
216+
premake.gcc.ar = "aarch64-none-elf-ar"
217+
location (_buildDir .. "projects/" .. _subDir .. "/".. _ACTION .. "-libnx-arm64")
218+
end
211219
elseif _ACTION == "vs2019" then
212220

213221
if "clangcl" == _OPTIONS["vs"] then
@@ -686,6 +694,38 @@ function toolchain(_buildDir, _subDir)
686694
configuration { "rpi" }
687695
targetdir (_buildDir .. "rpi" .. "/bin")
688696
objdir (_buildDir .. "rpi" .. "/obj")
697+
698+
configuration { "libnx" }
699+
systemincludedirs {
700+
"/opt/devkitpro/libnx/include",
701+
"/opt/devkitpro/portlibs/switch/include",
702+
}
703+
defines {
704+
"LLONG_MAX=0x7fffffffffffffffLL",
705+
"LLONG_MIN=-0x8000000000000000LL",
706+
"ULLONG_MAX=0xffffffffffffffffLL",
707+
}
708+
libdirs {
709+
"/opt/devkitpro/libnx/lib",
710+
"/opt/devkitpro/portlibs/switch/lib",
711+
}
712+
links {
713+
"nx",
714+
}
715+
buildoptions {
716+
"-g -ffunction-sections",
717+
"-march=armv8-a -mtune=cortex-a57 -mtp=soft",
718+
}
719+
buildoptions_cpp {
720+
-- Added by libretro-super, but we seem to need these
721+
-- "-fno-rtti -fno-exceptions",
722+
}
723+
linkoptions {
724+
"-specs=/opt/devkitpro/libnx/switch.specs",
725+
"-march=armv8-a -mtune=cortex-a57 -mtp=soft",
726+
"-ftls-model=local-exec",
727+
}
728+
689729
-- BEGIN libretro overrides to MAME's GENie build
690730

691731
configuration { "libretro*" }

0 commit comments

Comments
 (0)