]> Nishi Git Mirror - tewi.git/commitdiff
psp support
authorNishi <nishi@nishi.boats>
Fri, 27 Sep 2024 16:15:15 +0000 (16:15 +0000)
committerNishi <nishi@nishi.boats>
Fri, 27 Sep 2024 16:15:15 +0000 (16:15 +0000)
git-svn-id: file:///raid/svn-personal/tewi/trunk@183 8739d7e6-ffea-ec47-b151-bdff447c6205

Binary/psp.png [new file with mode: 0644]
Platform/psp.mk
Server/Makefile
Server/main.c
Server/server.c
Server/version.c

diff --git a/Binary/psp.png b/Binary/psp.png
new file mode 100644 (file)
index 0000000..2610ecb
Binary files /dev/null and b/Binary/psp.png differ
index 385321f05007db1f3ceb49dd8f69971966bc9c76..9973bb570e53fd604f6fb35e9854d57a78f6a952 100644 (file)
@@ -1,10 +1,12 @@
 # $Id$
 
+PREFIX = ms0:/PSP/GAME/httpd
+
 CC = psp-gcc
 AR = psp-ar
 CFLAGS = -g -std=c99 -DPREFIX=\"$(PREFIX)\" -I $(PWD)/Common -I /usr/local/pspdev/psp/sdk/include -D_PSP_FW_VERSION=600
-LDFLAGS = -L /usr/local/pspdev/psp/sdk/lib
-LIBS = -lpspgum -lpspgu -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspnet -lpspnet_apctl
+LDFLAGS = -Wl,-zmax-page-size=128 -L /usr/local/pspdev/psp/sdk/lib
+LIBS = -lpspgum -lpspgu -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspnet -lpspnet_apctl -lcglue -lpspwlan
 EXEC = .elf
 LIB = .so
 MODULE =
index 68322a9e4ddb7ba4211a7b7e0743c8ef654c68be..59c05b624ba3c0017d9cb8f18d1fb049ac832224 100644 (file)
@@ -16,7 +16,7 @@ tewi$(EXEC): $(OBJS) ../Common/common.a
        $(SERVADD)
 
 tewi.pbp: tewi_strip$(EXEC) param.sfo
-       pack-pbp $@ param.sfo NULL NULL NULL NULL NULL tewi_strip$(EXEC) NULL
+       pack-pbp $@ param.sfo ../Binary/psp.png NULL NULL NULL NULL tewi_strip$(EXEC) NULL
 
 param.sfo:
        mksfoex -d MEMSIZE=1 'Tewi HTTPd' $@
index 1fef989983cbe0453dd504ac8ed24c625d8d5753..cc827b203de16595407667e41366c2492953830f 100644 (file)
 #ifdef _PSP
 #include <pspkernel.h>
 #include <pspdebug.h>
+#include <pspsdk.h>
+#include <psputility.h>
+#include <pspctrl.h>
+#include <pspnet_apctl.h>
+#include <pspwlan.h>
 
 PSP_MODULE_INFO("Tewi HTTPd", PSP_MODULE_USER, 1, 1);
 PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER);
 
 #define printf(...) pspDebugScreenPrintf(__VA_ARGS__)
+#define STDERR_LOG(...) pspDebugScreenPrintf(__VA_ARGS__)
+#else
+#define STDERR_LOG(...) fprintf(stderr, __VA_ARGS__)
 #endif
 
 extern bool cm_do_log;
@@ -86,6 +94,20 @@ void WINAPI servmain(DWORD argc, LPSTR* argv) {
 }
 #endif
 
+int running = 1;
+#ifdef _PSP
+
+int psp_exit_callback(int arg1, int arg2, void* arg3) { running = 0; }
+
+int psp_callback_thread(SceSize args, void* argp) {
+       int cid;
+       cid = sceKernelCreateCallback("Exit Call Back", psp_exit_callback, NULL);
+       sceKernelRegisterExitCallback(cid);
+       sceKernelSleepThreadCB();
+       return 0;
+}
+#endif
+
 int main(int argc, char** argv) {
        logfile = stderr;
 #ifdef SERVICE
@@ -95,10 +117,144 @@ int main(int argc, char** argv) {
 #ifdef _PSP
        pspDebugScreenInit();
        pspDebugScreenSetXY(0, 0);
+       printf("PSP Bootstrap, Tewi/%s\n", tw_get_version());
+       int thid = sceKernelCreateThread("update_thread", psp_callback_thread, 0x11, 0xfa0, 0, NULL);
+       if(thid >= 0) {
+               sceKernelStartThread(thid, 0, NULL);
+       } else {
+               printf("Failed to start thread\n");
+               while(running) sceKernelDelayThread(50 * 1000);
+               sceKernelExitGame();
+       }
+       sceCtrlSetSamplingCycle(0);
+       sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
+       sceUtilityLoadNetModule(PSP_NET_MODULE_COMMON);
+       sceUtilityLoadNetModule(PSP_NET_MODULE_INET);
+       if(pspSdkInetInit()) {
+               printf("Could not init the network\n");
+               while(running) sceKernelDelayThread(50 * 1000);
+               sceKernelExitGame();
+       } else {
+               printf("Network initialization successful\n");
+       }
+       if(sceWlanGetSwitchState() != 1) {
+               printf("Turn the Wi-Fi switch on\n");
+               while(sceWlanGetSwitchState() != 1) {
+                       sceKernelDelayThread(1000 * 1000);
+               }
+       } else {
+               printf("Wi-Fi is turned on\n");
+       }
+       int i;
+       int choice[100];
+       int incr = 0;
+       int last = 0;
+       int cur = 0;
+       for(i = 1; i < 100; i++) {
+               choice[i - 1] = 0;
+               netData name;
+               netData data;
+               if(sceUtilityCheckNetParam(i) != 0) continue;
+               choice[incr++] = i;
+               pspDebugScreenSetXY(0, 1 + 3 + incr - 1);
+               if(incr == 1) printf("> ");
+               pspDebugScreenSetXY(2, 1 + 3 + incr - 1);
+               sceUtilityGetNetParam(i, 0, &name);
+               sceUtilityGetNetParam(i, 1, &data);
+               printf("SSID=%s", data.asString);
+               sceUtilityGetNetParam(i, 4, &data);
+               if(data.asString[0]) {
+                       sceUtilityGetNetParam(i, 5, &data);
+                       printf(" IPADDR=%s\n", data.asString);
+               } else {
+                       printf(" DHCP\n");
+               }
+       }
+       int press = 0;
+       while(1) {
+               if(!running) {
+                       sceKernelExitGame();
+               }
+               SceCtrlData c;
+               sceCtrlReadBufferPositive(&c, 1);
+               press = 0;
+               if(c.Buttons & PSP_CTRL_DOWN) {
+                       if(cur < incr - 1) {
+                               cur++;
+                       }
+                       press = 1;
+               } else if(c.Buttons & PSP_CTRL_UP) {
+                       if(cur > 0) {
+                               cur--;
+                       }
+                       press = -1;
+               } else if(c.Buttons & PSP_CTRL_START) {
+                       break;
+               }
+               if(last != cur) {
+                       pspDebugScreenSetXY(0, 1 + 3 + last);
+                       printf("  ");
+                       pspDebugScreenSetXY(0, 1 + 3 + cur);
+                       printf("> ");
+                       last = cur;
+               }
+               if(press != 0) {
+                       while(1) {
+                               SceCtrlData c;
+                               sceCtrlReadBufferPositive(&c, 1);
+                               if(press == 1) {
+                                       if(!(c.Buttons & PSP_CTRL_DOWN)) break;
+                               } else if(press == -1) {
+                                       if(!(c.Buttons & PSP_CTRL_UP)) break;
+                               }
+                       }
+               }
+       }
+       pspDebugScreenSetXY(0, 1 + 3 + incr + 1);
+       int err = sceNetApctlConnect(choice[cur]);
+       if(err != 0) {
+               printf("Apctl initialization failure\n");
+               while(running) sceKernelDelayThread(50 * 1000);
+               sceKernelExitGame();
+       } else {
+               printf("Apctl initialization successful\n");
+       }
+       printf("Apctl connecting\n");
+       while(1) {
+               int state;
+               err = sceNetApctlGetState(&state);
+               if(err != 0) {
+                       printf("Apctl getting status failure\n");
+                       while(running) sceKernelDelayThread(50 * 1000);
+                       sceKernelExitGame();
+               }
+               if(state == 4) {
+                       break;
+               }
+               sceKernelDelayThread(50 * 1000);
+       }
+       union SceNetApctlInfo info;
+       if(sceNetApctlGetInfo(8, &info) != 0) {
+               printf("Got an unknown IP\n");
+               while(running) sceKernelDelayThread(50 * 1000);
+               sceKernelExitGame();
+       }
+       printf("Connected, My IP is %s\n", info.ip);
 #endif
        int st = startup(argc, argv);
-       if(st != -1) return st;
+       if(st != -1) {
+#ifdef _PSP
+               printf("Error code %d\n", st);
+               while(running) sceKernelDelayThread(50 * 1000);
+               sceKernelExitGame();
+#else
+               return st;
+#endif
+       }
        tw_server_loop();
+#endif
+#ifdef _PSP
+       sceKernelExitGame();
 #endif
        return 0;
 }
@@ -123,7 +279,7 @@ int startup(int argc, char** argv) {
                                } else if(strcmp(argv[i], "--config") == 0 || strcmp(argv[i], "-C") == 0) {
                                        i++;
                                        if(argv[i] == NULL) {
-                                               fprintf(stderr, "Missing argument\n");
+                                               STDERR_LOG("Missing argument\n");
                                                return 1;
                                        }
                                        confpath = argv[i];
@@ -131,7 +287,7 @@ int startup(int argc, char** argv) {
                                } else if(strcmp(argv[i], "--logfile") == 0 || strcmp(argv[i], "-l") == 0) {
                                        i++;
                                        if(argv[i] == NULL) {
-                                               fprintf(stderr, "Missing argument\n");
+                                               STDERR_LOG("Missing argument\n");
                                                return 1;
                                        }
                                        if(logfile != NULL && logfile != stderr) {
@@ -139,7 +295,7 @@ int startup(int argc, char** argv) {
                                        }
                                        logfile = fopen(argv[i], "a");
                                        if(logfile == NULL) {
-                                               fprintf(stderr, "Failed to open logfile\n");
+                                               STDERR_LOG("Failed to open logfile\n");
                                                return 1;
                                        }
 #endif
@@ -157,7 +313,7 @@ int startup(int argc, char** argv) {
                                        printf("--version | -V             : Version information\n");
                                        return 0;
                                } else {
-                                       fprintf(stderr, "Unknown option: %s\n", argv[i]);
+                                       STDERR_LOG("Unknown option: %s\n", argv[i]);
                                        return 1;
                                }
                        }
@@ -165,11 +321,11 @@ int startup(int argc, char** argv) {
        }
        tw_config_init();
        if(tw_config_read(confpath) != 0) {
-               fprintf(stderr, "Could not read the config\n");
+               STDERR_LOG("Could not read the config\n");
                return 1;
        }
        if(tw_server_init() != 0) {
-               fprintf(stderr, "Could not initialize the server\n");
+               STDERR_LOG("Could not initialize the server\n");
                return 1;
        }
        sprintf(tw_server, "Tewi/%s (%s)%s", tw_get_version(), tw_get_platform(), config.extension == NULL ? "" : config.extension);
index 9e8374b8a36ff4853ba5111927a6082e3196783b..5e295c1b92e81876e2c2812ddcf4ce6d9a83bffb 100644 (file)
@@ -430,8 +430,10 @@ struct pass_entry {
 unsigned int WINAPI tw_server_pass(void* ptr) {
 #elif defined(__HAIKU__)
 int32_t tw_server_pass(void* ptr) {
+#elif defined(_PSP)
+int tw_server_pass(void* ptr) {
 #endif
-#if defined(__HAIKU__) || defined(__MINGW32__)
+#if defined(__HAIKU__) || defined(__MINGW32__) || defined(_PSP)
        int sock = ((struct pass_entry*)ptr)->sock;
        bool ssl = ((struct pass_entry*)ptr)->ssl;
        int port = ((struct pass_entry*)ptr)->port;
@@ -854,6 +856,8 @@ struct thread_entry {
 };
 #endif
 
+extern int running;
+
 void tw_server_loop(void) {
        int i;
 #if defined(__MINGW32__) || defined(__HAIKU__)
@@ -872,7 +876,7 @@ void tw_server_loop(void) {
                fd_set fdset;
                struct timeval tv;
 #endif
-       while(1) {
+       while(running) {
 #ifdef USE_POLL
                int ret = poll(pollfds, sockcount, 1000);
 #else
@@ -914,7 +918,7 @@ void tw_server_loop(void) {
                                        socklen_t clen = sizeof(claddr);
                                        int sock = accept(sockets[i], (struct sockaddr*)&claddr, &clen);
                                        cm_log("Server", "New connection accepted");
-#if defined(__MINGW32__) || defined(__HAIKU__)
+#if defined(__MINGW32__) || defined(__HAIKU__) || defined(_PSP)
                                        struct pass_entry* e = malloc(sizeof(*e));
                                        e->sock = sock;
                                        e->ssl = config.ports[i] & (1ULL << 32);
@@ -940,29 +944,31 @@ void tw_server_loop(void) {
                                                        break;
                                                }
                                        }
+#elif defined(_PSP)
+                                               tw_server_pass(e);
 #elif defined(__HAIKU__)
-                                               int j;
-                                               for(j = 0; j < sizeof(threads) / sizeof(threads[0]); j++) {
-                                                       if(threads[j].used) {
-                                                               thread_info info;
-                                                               bool kill = false;
-                                                               if(get_thread_info(threads[j].thread, &info) == B_OK) {
-                                                               } else {
-                                                                       kill = true;
-                                                               }
-                                                               if(kill) {
-                                                                       threads[j].used = false;
-                                                               }
+                                       int j;
+                                       for(j = 0; j < sizeof(threads) / sizeof(threads[0]); j++) {
+                                               if(threads[j].used) {
+                                                       thread_info info;
+                                                       bool kill = false;
+                                                       if(get_thread_info(threads[j].thread, &info) == B_OK) {
+                                                       } else {
+                                                               kill = true;
                                                        }
-                                               }
-                                               for(j = 0; j < sizeof(threads) / sizeof(threads[0]); j++) {
-                                                       if(!threads[j].used) {
-                                                               threads[j].thread = spawn_thread(tw_server_pass, "Tewi HTTPd", 60, e);
-                                                               threads[j].used = true;
-                                                               resume_thread(threads[j].thread);
-                                                               break;
+                                                       if(kill) {
+                                                               threads[j].used = false;
                                                        }
                                                }
+                                       }
+                                       for(j = 0; j < sizeof(threads) / sizeof(threads[0]); j++) {
+                                               if(!threads[j].used) {
+                                                       threads[j].thread = spawn_thread(tw_server_pass, "Tewi HTTPd", 60, e);
+                                                       threads[j].used = true;
+                                                       resume_thread(threads[j].thread);
+                                                       break;
+                                               }
+                                       }
 #else
                                        pid_t pid = fork();
                                        if(pid == 0) {
index c4cbb4ccc25519bcf954a65d5a43b9678418b3f0..3d49ce3b2cd9363685ce03cecf82c8189c322092 100644 (file)
@@ -19,6 +19,8 @@ const char* tw_platform =
     "Haiku"
 #elif defined(__CYGWIN__)
     "Cygwin"
+#elif defined(_PSP)
+    "PSP"
 #else
     "Unix"
 #endif