From: Nishi Date: Fri, 27 Sep 2024 16:15:15 +0000 (+0000) Subject: psp support X-Git-Url: https://git.chaotic.ninja/gitweb/nishi/?a=commitdiff_plain;h=6b990a3b904479f7b47f94ef5ed0d36910d1df87;p=tewi.git psp support git-svn-id: file:///raid/svn-personal/tewi/trunk@183 8739d7e6-ffea-ec47-b151-bdff447c6205 --- diff --git a/Binary/psp.png b/Binary/psp.png new file mode 100644 index 0000000..2610ecb Binary files /dev/null and b/Binary/psp.png differ diff --git a/Platform/psp.mk b/Platform/psp.mk index 385321f..9973bb5 100644 --- a/Platform/psp.mk +++ b/Platform/psp.mk @@ -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 = diff --git a/Server/Makefile b/Server/Makefile index 68322a9..59c05b6 100644 --- a/Server/Makefile +++ b/Server/Makefile @@ -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' $@ diff --git a/Server/main.c b/Server/main.c index 1fef989..cc827b2 100644 --- a/Server/main.c +++ b/Server/main.c @@ -28,11 +28,19 @@ #ifdef _PSP #include #include +#include +#include +#include +#include +#include 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); diff --git a/Server/server.c b/Server/server.c index 9e8374b..5e295c1 100644 --- a/Server/server.c +++ b/Server/server.c @@ -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) { diff --git a/Server/version.c b/Server/version.c index c4cbb4c..3d49ce3 100644 --- a/Server/version.c +++ b/Server/version.c @@ -19,6 +19,8 @@ const char* tw_platform = "Haiku" #elif defined(__CYGWIN__) "Cygwin" +#elif defined(_PSP) + "PSP" #else "Unix" #endif