SDL_net: SDL_net for SDL 1.2 on the PSP. (#64)

From 9aa8a57ab1d1a42acf2a421cb4c8220c09ec72bd Mon Sep 17 00:00:00 2001
From: superfury <[EMAIL REDACTED]>
Date: Thu, 8 Sep 2022 22:18:41 +0200
Subject: [PATCH] SDL_net for SDL 1.2 on the PSP. (#64)

---
 Makefile.psp | 22 ++++++++++++++++++++++
 SDL_net.h    |  9 +++++++++
 SDLnetsys.h  |  8 +++++++-
 3 files changed, 38 insertions(+), 1 deletion(-)
 create mode 100644 Makefile.psp

diff --git a/Makefile.psp b/Makefile.psp
new file mode 100644
index 0000000..038fab2
--- /dev/null
+++ b/Makefile.psp
@@ -0,0 +1,22 @@
+TARGET_LIB = libSDL_net.a
+OBJS= SDLnet.o \
+      SDLnetselect.o \
+      SDLnetTCP.o \
+      SDLnetUDP.o \
+
+INCDIR = .
+CFLAGS = -g -O2 -G0 -Wall -D__PSP__ -DHAVE_OPENGL $(shell $(PSPBIN)/sdl-config --cflags)
+CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
+ASFLAGS = $(CFLAGS)
+
+PSPBIN = $(shell psp-config -d)/bin
+
+LDFLAGS=-L$(shell psp-config --pspsdk-path)/lib
+LIBS=-lc -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser
+
+install: $(TARGET_LIB)
+	cp $(TARGET_LIB) $(shell psp-config --psp-prefix)/lib
+	cp SDL_net.h $(shell psp-config --psp-prefix)/include
+
+PSPSDK=$(shell psp-config --pspsdk-path)
+include $(PSPSDK)/lib/build.mak
diff --git a/SDL_net.h b/SDL_net.h
index 17aaa1c..e30e476 100644
--- a/SDL_net.h
+++ b/SDL_net.h
@@ -34,6 +34,15 @@
 extern "C" {
 #endif
 
+//The SDL_reinterpret_cast isn't defined before 1.2.14, so define it if required
+#ifndef SDL_reinterpret_cast
+#ifdef __cplusplus
+#define SDL_reinterpret_cast(type, expression) reinterpret_cast<type>(expression)
+#else
+#define SDL_reinterpret_cast(type, expression) ((type)(expression))
+#endif
+#endif
+
 /* Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL
 */
 #define SDL_NET_MAJOR_VERSION	1
diff --git a/SDLnetsys.h b/SDLnetsys.h
index 2494879..77af410 100644
--- a/SDLnetsys.h
+++ b/SDLnetsys.h
@@ -37,7 +37,7 @@
 #include <ws2tcpip.h>
 #include <iphlpapi.h>
 #else /* UNIX */
-#ifdef __OS2__
+#if defined(__OS2__) || defined(__PSP__)
 #include <sys/param.h>
 #endif
 #include <sys/types.h>
@@ -56,10 +56,16 @@
 #include <netinet/tcp.h>
 #endif
 #include <sys/socket.h>
+#ifndef __PSP__
 #include <net/if.h>
+#endif
 #include <netdb.h>
 #endif /* WIN32 */
 
+#ifdef __PSP__
+#include <sys/select.h> //Required for the FD_SET etc.
+#endif
+
 #ifdef __OS2__
 typedef int socklen_t;
 #elif 0