From 47dcb54c1fbee748bc2c9a8f8c8e0396122faed3 Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Tue, 13 Mar 2012 00:44:37 +0100 Subject: [PATCH] (PS3/Wii) Make netlogger code portable --- Makefile.ps3 | 2 +- Makefile.ps3.salamander | 2 +- Makefile.wii | 13 ++++- .../fileio => console/logger}/logger.c | 56 ++++++++++--------- .../fileio => console/logger}/logger.h | 23 +------- logger_override.h | 10 ++-- netplay_compat.h | 1 + ps3/salamander/main.c | 8 +-- 8 files changed, 55 insertions(+), 60 deletions(-) rename {ps3/cellframework2/fileio => console/logger}/logger.c (70%) rename {ps3/cellframework2/fileio => console/logger}/logger.h (51%) diff --git a/Makefile.ps3 b/Makefile.ps3 index 2a34d360a6..0c1b40255f 100644 --- a/Makefile.ps3 +++ b/Makefile.ps3 @@ -96,7 +96,7 @@ PPU_CXXFLAGS = $(PPU_OPTIMIZE_LV) $(INCDIRS) $(DEFINES) ifeq ($(HAVE_LOGGER), 1) PPU_CFLAGS += -DHAVE_LOGGER -PPU_SRCS += ps3/cellframework2/fileio/logger.c +PPU_SRCS += console/logger/logger.c endif EXIST_EBOOT_WILDCARD := $(wildcard $(EBOOT_PATH)) diff --git a/Makefile.ps3.salamander b/Makefile.ps3.salamander index 8cf308fd70..c7c53b96d7 100644 --- a/Makefile.ps3.salamander +++ b/Makefile.ps3.salamander @@ -22,7 +22,7 @@ PPU_SRCS = ps3/salamander/main.c strl.c conf/config_file.c ifeq ($(HAVE_LOGGER), 1) PPU_CFLAGS += -DHAVE_LOGGER -PPU_SRCS += ps3/cellframework2/fileio/logger.c +PPU_SRCS += console/logger/logger.c endif PPU_TARGET = ssnes-salamander.elf diff --git a/Makefile.wii b/Makefile.wii index b4a1033b37..80b6f72c88 100644 --- a/Makefile.wii +++ b/Makefile.wii @@ -5,7 +5,11 @@ ### ## -DEBUG = 0 +DEBUG = 0 +HAVE_LOGGER = 0 + +PC_DEVELOPMENT_IP_ADDRESS = "192.168.1.7" +PC_DEVELOPMENT_UDP_PORT = 3490 CC = $(DEVKITPPC)/bin/powerpc-eabi-gcc CXX = $(DEVKITPPC)/bin/powerpc-eabi-g++ @@ -25,7 +29,12 @@ LIBS := -lfat -lsnes -lwiiuse -logc -lbte -lfreetype OBJ = wii/main.o fifo_buffer.o ssnes.o driver.o gfx/fonts.o file.o settings.o message.o rewind.o movie.o ups.o bps.o strl.o screenshot.o audio/hermite.o dynamic.o audio/utils.o conf/config_file.o wii/audio.o wii/input.o wii/video.o console/sgui.o console/list.o console/font.bmpobj console/main_wrap.o console/console_ext.o console/szlib/szlib.o -CFLAGS += -std=gnu99 -DSSNES_CONSOLE -DHAVE_CONFIGFILE=1 -DHAVE_GETOPT_LONG -DHAVE_FREETYPE -DPACKAGE_VERSION=\"0.9.5\" -Dmain=ssnes_main -Wno-char-subscripts +ifeq ($(HAVE_LOGGER), 1) +CFLAGS += -DHAVE_LOGGER +OBJ += console/logger/logger.o +endif + +CFLAGS += -std=gnu99 -DSSNES_CONSOLE -DHAVE_CONFIGFILE=1 -DHAVE_GETOPT_LONG -DHAVE_FREETYPE -DPACKAGE_VERSION=\"0.9.5\" -Dmain=ssnes_main -Wno-char-subscripts -DPC_DEVELOPMENT_IP_ADDRESS=\"$(PC_DEVELOPMENT_IP_ADDRESS)\" -DPC_DEVELOPMENT_UDP_PORT=$(PC_DEVELOPMENT_UDP_PORT) ifeq ($(DEBUG), 1) CFLAGS += -O0 -g diff --git a/ps3/cellframework2/fileio/logger.c b/console/logger/logger.c similarity index 70% rename from ps3/cellframework2/fileio/logger.c rename to console/logger/logger.c index 0769619bda..50c5b32d4a 100644 --- a/ps3/cellframework2/fileio/logger.c +++ b/console/logger/logger.c @@ -1,23 +1,3 @@ -/* -- Cellframework Mk.II - Open framework to abstract the common tasks related to - * PS3 application development. - * - * Copyright (C) 2010-2012 - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - /* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes. * Copyright (C) 2010-2012 - Hans-Kristian Arntzen * Copyright (C) 2011-2012 - Daniel De Matteis @@ -36,17 +16,27 @@ * If not, see . */ +#ifdef __CELLOS_LV2__ #include #include #include -#include -#include #include #include #include #include +#endif + +#ifdef HW_RVL +#include +#endif + +#include +#include +#include #include +#include "../../netplay_compat.h" + #include "logger.h" #if !defined(PC_DEVELOPMENT_IP_ADDRESS) @@ -62,13 +52,26 @@ static int sock; static struct sockaddr_in target; static char sendbuf[4096]; +#ifdef HW_RVL +#define sendto(s, msg, len, flags, addr, tolen) net_sendto(s, msg, len, flags, addr, tolen) +#define socket(domain, type, protocol) net_socket(domain, type, protocol) + +static int inet_pton(int af, const char *src, void *dst) +{ + if (af != AF_INET) + return -1; + return inet_aton (src, dst); +} +#endif + static int if_up_with(int index) { + (void)index; +#ifdef __CELLOS_LV2__ int timeout_count = 10; int state; int ret; - (void)index; ret = cellNetCtlInit(); if (ret < 0) { @@ -94,6 +97,7 @@ static int if_up_with(int index) return (0); } } +#endif sock=socket(AF_INET,SOCK_DGRAM ,0); @@ -107,7 +111,9 @@ static int if_up_with(int index) static int if_down(int sid) { (void)sid; +#ifdef __CELLOS_LV2__ cellNetCtlTerm(); +#endif return (0); } @@ -121,7 +127,7 @@ void logger_shutdown (void) if_down(g_sid); } -void net_send(const char *__format,...) +void logger_send(const char *__format,...) { va_list args; @@ -130,5 +136,5 @@ void net_send(const char *__format,...) va_end(args); int len=strlen(sendbuf); - sendto(sock,sendbuf,len,MSG_DONTWAIT,(const struct sockaddr*)&target,sizeof(target)); + sendto(sock,sendbuf,len,MSG_DONTWAIT,(struct sockaddr*)&target,sizeof(target)); } diff --git a/ps3/cellframework2/fileio/logger.h b/console/logger/logger.h similarity index 51% rename from ps3/cellframework2/fileio/logger.h rename to console/logger/logger.h index 055653f76f..d729aac5cc 100644 --- a/ps3/cellframework2/fileio/logger.h +++ b/console/logger/logger.h @@ -1,23 +1,3 @@ -/* -- Cellframework Mk.II - Open framework to abstract the common tasks related to - * PS3 application development. - * - * Copyright (C) 2010-2012 - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - /* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes. * Copyright (C) 2010-2012 - Hans-Kristian Arntzen * Copyright (C) 2011-2012 - Daniel De Matteis @@ -40,12 +20,11 @@ #define _LOGGER_H_ #define BUFSIZE (64 * 1024) -#define TCPDUMP_FILE (SYS_APP_HOME "/tcpdump.dump") #define TCPDUMP_STACKSIZE (16 * 1024) #define TCPDUMP_PRIO (2048) void logger_init (void); void logger_shutdown (void); -void net_send(const char *__format,...); +void logger_send (const char *__format,...); #endif diff --git a/logger_override.h b/logger_override.h index 8a0595affc..68aa67dc39 100644 --- a/logger_override.h +++ b/logger_override.h @@ -19,20 +19,20 @@ #ifndef __SSNES_LOGGER_OVERRIDE_H #define __SSNES_LOGGER_OVERRIDE_H -#ifdef __CELLOS_LV2__ +#if (defined(__CELLOS_LV2__) || defined(HW_RVL)) && defined(HAVE_LOGGER) -#include "ps3/cellframework2/fileio/logger.h" +#include "console/logger/logger.h" #define SSNES_LOG(...) do { \ - if (g_extern.verbose) net_send("SSNES: " __VA_ARGS__); \ + if (g_extern.verbose) logger_send("SSNES: " __VA_ARGS__); \ } while(0) #define SSNES_ERR(...) do { \ - net_send("SSNES [ERROR] :: " __VA_ARGS__); \ + logger_send("SSNES [ERROR] :: " __VA_ARGS__); \ } while(0) #define SSNES_WARN(...) do { \ - net_send("SSNES [WARN] :: " __VA_ARGS__); \ + logger_send("SSNES [WARN] :: " __VA_ARGS__); \ } while(0) #endif diff --git a/netplay_compat.h b/netplay_compat.h index f920b51322..68f6cfb0a2 100644 --- a/netplay_compat.h +++ b/netplay_compat.h @@ -82,5 +82,6 @@ void freeaddrinfo(struct addrinfo *res); // gai_strerror() not used, so we skip that. #endif + #endif diff --git a/ps3/salamander/main.c b/ps3/salamander/main.c index 6c598c61a7..08f1680dd0 100644 --- a/ps3/salamander/main.c +++ b/ps3/salamander/main.c @@ -36,10 +36,10 @@ #define MAX_PATH_LENGTH 1024 #ifdef HAVE_LOGGER -#include "../cellframework2/fileio/logger.h" -#define SSNES_LOG(...) net_send("SSNES Salamander: " __VA_ARGS__); -#define SSNES_ERR(...) net_send("SSNES Salamander [ERROR] :: " __VA_ARGS__); -#define SSNES_WARN(...) net_send("SSNES Salamander [WARN] :: " __VA_ARGS__); +#include "logger.h" +#define SSNES_LOG(...) logger_send("SSNES Salamander: " __VA_ARGS__); +#define SSNES_ERR(...) logger_send("SSNES Salamander [ERROR] :: " __VA_ARGS__); +#define SSNES_WARN(...) logger_send("SSNES Salamander [WARN] :: " __VA_ARGS__); #else #define SSNES_LOG(...) do { \ fprintf(stderr, "SSNES Salamander: " __VA_ARGS__); \