diff --git a/Makefile.ps3 b/Makefile.ps3 index d290571656..7ff15bb106 100644 --- a/Makefile.ps3 +++ b/Makefile.ps3 @@ -39,7 +39,7 @@ INCDIRS = -I. -Icommon MKFSELF_NPDRM = $(CELL_SDK)/$(HOST_DIR)/bin/make_fself_npdrm MKPKG_NPDRM = $(CELL_SDK)/$(HOST_DIR)/bin/make_package_npdrm -OBJ = ps3/buffer.o ps3/ps3_audio.o ps3/resampler.o getopt.o ssnes.o driver.o settings.o dynamic.o message.o rewind.o movie.o autosave.o gfx/gfx_common.o gfx/gl.c gfx/shader_cg.c gfx/snes_state.c ups.o bps.o strl.o screenshot.o thread.o audio/hermite.o +OBJ = ps3/buffer.o ps3/ps3_audio.o ps3/resampler.o ps3/ps3_input.o getopt.o ssnes.o driver.o settings.o dynamic.o message.o rewind.o movie.o autosave.o gfx/gfx_common.o gfx/gl.c gfx/shader_cg.c gfx/snes_state.c ups.o bps.o strl.o screenshot.o thread.o audio/hermite.o LIBS = -ldbgfont -lPSGL -lgcm_cmd -lgcm_sys_stub -lresc_stub libsnes.a -lm -lio_stub -lfs_stub -lsysutil_stub -lsysmodule_stub -laudio_stub -lnet_stub -lpthread diff --git a/config.def.h b/config.def.h index 0df3eb5815..025a32045f 100644 --- a/config.def.h +++ b/config.def.h @@ -54,9 +54,10 @@ //////////////////////// #define INPUT_SDL 7 #define INPUT_X 12 +#define INPUT_PS3 19 //////////////////////// -#if defined(HAVE_OPENGL) +#if defined(HAVE_OPENGL) || defined(__CELLOS_LV2__) #define VIDEO_DEFAULT_DRIVER VIDEO_GL #elif defined(HAVE_XVIDEO) #define VIDEO_DEFAULT_DRIVER VIDEO_XVIDEO @@ -68,7 +69,9 @@ #error "Need at least one video driver!" #endif -#if defined(HAVE_ALSA) +#if defined(__CELLOS_LV2__) +#define AUDIO_DEFAULT_DRIVER AUDIO_PS3 +#elif defined(HAVE_ALSA) #define AUDIO_DEFAULT_DRIVER AUDIO_ALSA #elif defined(HAVE_PULSE) #define AUDIO_DEFAULT_DRIVER AUDIO_PULSE @@ -98,6 +101,8 @@ #if defined(HAVE_SDL) #define INPUT_DEFAULT_DRIVER INPUT_SDL +#elif defined(__CELLOS_LV2__) +#define INPUT_DEFAULT_DRIVER INPUT_PS3 #elif defined(HAVE_XVIDEO) #define INPUT_DEFAULT_DRIVER INPUT_X #else diff --git a/dynamic.c b/dynamic.c index 29364a9d3d..32f9f189cb 100644 --- a/dynamic.c +++ b/dynamic.c @@ -25,7 +25,7 @@ #include "config.h" #endif -#include +#include "libsnes.hpp" #ifdef _WIN32 #include diff --git a/ps3/gl_debug.h b/ps3/gl_debug.h new file mode 100644 index 0000000000..5494746a7d --- /dev/null +++ b/ps3/gl_debug.h @@ -0,0 +1,40 @@ +#ifndef __DEBUG_H +#define __DEBUG_H + +#include +#include +#ifdef __cplusplus +extern "C" { +#endif + +// Inits debug lib +void init_debug(uint64_t width, uint64_t height); + +void dprintf_console(const char *fmt, ...); +void dprintf(float x, float y, float scale, const char *fmt, ...); + +void uninit_debug(void); +void write_fps(void); +void test_performance(void); + +#ifdef SSNES_DEBUG +#define SSNES_LOG(msg, args...) do { \ + dprintf(0.1f, 0.1f, 1.0f, "SSNES: " msg, ##args); \ + sys_timer_usleep(300000); \ + } while(0) + +#define SSNES_ERR(msg, args...) do { \ + dprintf(0.1f, 0.1f, 1.0f, "SSNES [ERROR] :: " msg, ##args); \ + sys_timer_usleep(300000); \ + } while(0) +#else +#define SSNES_LOG(msg, args...) ((void)0) +#define SSNES_ERR(msg, args...) ((void)0) +#endif // SSNES_DEBUG + + +#ifdef __cplusplus +} +#endif + +#endif // __DEBUG_H diff --git a/ps3/pad_input.h b/ps3/pad_input.h new file mode 100644 index 0000000000..dad7449778 --- /dev/null +++ b/ps3/pad_input.h @@ -0,0 +1,117 @@ +/************************************************************************************* + * -- Cellframework Mk.II - Open framework to abstract the common tasks related to + * PS3 application development. + * + * Copyright (C) 2010 + * + * 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. + ********************************************************************************/ + +/******************************************************************************* + * pad_input.h - Cellframework Mk. II + * + * Created on: Jan 31, 2011 + ********************************************************************************/ + +#ifndef __CELL_PAD_INPUT_H +#define __CELL_PAD_INPUT_H + +#define MAX_PADS 7 + +#define CTRL_SELECT_MASK 0x01 +#define CTRL_L3_MASK 0x2 +#define CTRL_R3_MASK 0x4 +#define CTRL_START_MASK 0x8 +#define CTRL_UP_MASK 0x10 +#define CTRL_RIGHT_MASK 0x20 +#define CTRL_DOWN_MASK 0x40 +#define CTRL_LEFT_MASK 0x80 + +#define CTRL_L2_MASK 0x100 +#define CTRL_R2_MASK 0x200 +#define CTRL_L1_MASK 0x400 +#define CTRL_R1_MASK 0x800 +#define CTRL_TRIANGLE_MASK 0x1000 +#define CTRL_CIRCLE_MASK 0x2000 +#define CTRL_CROSS_MASK 0x4000 +#define CTRL_SQUARE_MASK 0x8000 + +// Big numbers, harhar. +#define CTRL_LSTICK_LEFT_MASK 0x1000000000000LLU +#define CTRL_LSTICK_RIGHT_MASK 0x2000000000000LLU +#define CTRL_LSTICK_UP_MASK 0x4000000000000LLU +#define CTRL_LSTICK_DOWN_MASK 0x8000000000000LLU +#define CTRL_RSTICK_LEFT_MASK 0x10000000000000LLU +#define CTRL_RSTICK_RIGHT_MASK 0x20000000000000LLU +#define CTRL_RSTICK_UP_MASK 0x40000000000000LLU +#define CTRL_RSTICK_DOWN_MASK 0x80000000000000LLU + + +#define CTRL_SELECT(state) (CTRL_SELECT_MASK & state) +#define CTRL_L3(state) (CTRL_L3_MASK & state) +#define CTRL_R3(state) (CTRL_R3_MASK & state) +#define CTRL_START(state) (CTRL_START_MASK & state) +#define CTRL_UP(state) (CTRL_UP_MASK & state) +#define CTRL_RIGHT(state) (CTRL_RIGHT_MASK & state) +#define CTRL_DOWN(state) (CTRL_DOWN_MASK & state) +#define CTRL_LEFT(state) (CTRL_LEFT_MASK & state) + +#define CTRL_L2(state) (CTRL_L2_MASK & state) +#define CTRL_R2(state) (CTRL_R2_MASK & state) +#define CTRL_L1(state) (CTRL_L1_MASK & state) +#define CTRL_R1(state) (CTRL_R1_MASK & state) +#define CTRL_TRIANGLE(state) (CTRL_TRIANGLE_MASK & state) +#define CTRL_CIRCLE(state) (CTRL_CIRCLE_MASK & state) +#define CTRL_CROSS(state) (CTRL_CROSS_MASK & state) +#define CTRL_SQUARE(state) (CTRL_SQUARE_MASK & state) + +#define CTRL_LSTICK_LEFT(state) (CTRL_LSTICK_LEFT_MASK & state) +#define CTRL_LSTICK_RIGHT(state) (CTRL_LSTICK_RIGHT_MASK & state) +#define CTRL_LSTICK_UP(state) (CTRL_LSTICK_UP_MASK & state) +#define CTRL_LSTICK_DOWN(state) (CTRL_LSTICK_DOWN_MASK & state) +#define CTRL_RSTICK_LEFT(state) (CTRL_RSTICK_LEFT_MASK & state) +#define CTRL_RSTICK_RIGHT(state) (CTRL_RSTICK_RIGHT_MASK & state) +#define CTRL_RSTICK_UP(state) (CTRL_RSTICK_UP_MASK & state) +#define CTRL_RSTICK_DOWN(state) (CTRL_RSTICK_DOWN_MASK & state) + +#define CTRL_MASK(state, mask) (state & mask) + +#define CTRL_AXIS_LSTICK_X(state) ((u8)(((0xFF0000LLU & state) >> 16) & 0xFF)) +#define CTRL_AXIS_LSTICK_Y(state) ((u8)(((0xFF000000LLU & state) >> 24) & 0xFF)) +#define CTRL_AXIS_RSTICK_X(state) ((u8)(((0xFF00000000LLU & state) >> 32) & 0xFF)) +#define CTRL_AXIS_RSTICK_Y(state) ((u8)(((0xFF0000000000LLU & state) >> 40) & 0xFF)) + +typedef uint64_t cell_input_state_t; + + +#ifdef __cplusplus +extern "C" { +#endif + +// Init and destruction of device. +int cell_pad_input_init(void); +void cell_pad_input_deinit(void); + +// Get number of pads connected +uint32_t cell_pad_input_pads_connected(void); + +cell_input_state_t cell_pad_input_poll_device(uint32_t id); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/ps3/ps3_input.c b/ps3/ps3_input.c new file mode 100644 index 0000000000..65aa6fb41d --- /dev/null +++ b/ps3/ps3_input.c @@ -0,0 +1,111 @@ +/* SSNES - A Super Ninteno Entertainment System (SNES) Emulator frontend for libsnes. + * Copyright (C) 2010 - Hans-Kristian Arntzen + * + * Some code herein may be based on code found in BSNES. + * + * SSNES 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 Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * SSNES 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 SSNES. + * If not, see . + */ + + +#include "../driver.h" +#include "pad_input.h" +#include +#include "../libsnes.hpp" + +#include "gl_debug.h" + +#include + +static uint64_t state = 0; + +static void ps3_input_poll(void *data) +{ + (void)data; + state = cell_pad_input_poll_device(0); +} + +static int16_t ps3_input_state(void *data, const struct snes_keybind **binds, bool port, unsigned device, unsigned index, unsigned id) +{ + (void)data; + (void)binds; // Hardcoded binds + (void)index; + + if (device != SNES_DEVICE_JOYPAD) + return 0; + if (port == SNES_PORT_2) + return 0; + + uint64_t button = 0; + + switch (id) + { + case SNES_DEVICE_ID_JOYPAD_A: + button = CTRL_CIRCLE_MASK; + break; + case SNES_DEVICE_ID_JOYPAD_B: + button = CTRL_CROSS_MASK; + break; + case SNES_DEVICE_ID_JOYPAD_X: + button = CTRL_TRIANGLE_MASK; + break; + case SNES_DEVICE_ID_JOYPAD_Y: + button = CTRL_SQUARE_MASK; + break; + case SNES_DEVICE_ID_JOYPAD_LEFT: + button = CTRL_LEFT_MASK; + break; + case SNES_DEVICE_ID_JOYPAD_RIGHT: + button = CTRL_RIGHT_MASK; + break; + case SNES_DEVICE_ID_JOYPAD_UP: + button = CTRL_UP_MASK; + break; + case SNES_DEVICE_ID_JOYPAD_DOWN: + button = CTRL_DOWN_MASK; + break; + case SNES_DEVICE_ID_JOYPAD_START: + button = CTRL_START_MASK; + break; + case SNES_DEVICE_ID_JOYPAD_SELECT: + button = CTRL_SELECT_MASK; + break; + case SNES_DEVICE_ID_JOYPAD_L: + button = CTRL_L1_MASK; + break; + case SNES_DEVICE_ID_JOYPAD_R: + button = CTRL_R1_MASK; + break; + default: + button = 0; + } + + return CTRL_MASK(state, button) ? 1 : 0; +} + +static void ps3_free_input(void *data) +{ + free(data); + cell_pad_input_deinit(); +} + +static void* ps3_input_init(void) +{ + cell_pad_input_init(); + return malloc(sizeof(void*)); +} + +const input_driver_t input_ps3 = { + .init = ps3_input_init, + .poll = ps3_input_poll, + .input_state = ps3_input_state, + .free = ps3_free_input +}; diff --git a/settings.c b/settings.c index 3a693fe6b1..102276e40e 100644 --- a/settings.c +++ b/settings.c @@ -106,6 +106,11 @@ static void set_defaults(void) switch (INPUT_DEFAULT_DRIVER) { + #ifdef __CELLOS_LV2__ + case INPUT_PS3: + def_input = "ps3"; + break; + #endif case INPUT_SDL: def_input = "sdl"; break;