(PS3) oskutil.c merged with ps3_input.c

This commit is contained in:
Twinaphex 2012-03-26 00:36:40 +02:00
parent 64fa27cdad
commit 45021bda3f
6 changed files with 174 additions and 261 deletions

View File

@ -44,7 +44,6 @@ PPU_SRCS = fifo_buffer.c \
console/librsound/librsound.c \
console/szlib/szlib.c \
ps3/ps3_input.c \
ps3/cellframework2/utility/oskutil.c \
compat/compat.c \
ssnes.c \
driver.c \

View File

@ -37,7 +37,7 @@
#ifdef __CELLOS_LV2__
#include <sys/timer.h>
#include "ps3/cellframework2/utility/oskutil.h"
#include "ps3/ps3_input.h"
#endif
#ifdef XENON

View File

@ -1,171 +0,0 @@
/* -- 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
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "sysutil/sysutil_oskdialog.h"
#include "sys/memory.h"
#include "oskutil.h"
#define OSK_IN_USE (0x00000001)
void oskutil_init(oskutil_params *params, unsigned int containersize)
{
params->flags = 0;
params->is_running = false;
if(containersize)
params->osk_memorycontainer = containersize;
else
params->osk_memorycontainer = 1024*1024*7;
}
static bool oskutil_enable_key_layout()
{
int ret = cellOskDialogSetKeyLayoutOption(CELL_OSKDIALOG_10KEY_PANEL | \
CELL_OSKDIALOG_FULLKEY_PANEL);
if (ret < 0)
return (false);
else
return (true);
}
static void oskutil_create_activation_parameters(oskutil_params *params)
{
// Initial display psition of the OSK (On-Screen Keyboard) dialog [x, y]
params->dialogParam.controlPoint.x = 0.0;
params->dialogParam.controlPoint.y = 0.0;
// Set standard position
int32_t LayoutMode = CELL_OSKDIALOG_LAYOUTMODE_X_ALIGN_CENTER | CELL_OSKDIALOG_LAYOUTMODE_Y_ALIGN_TOP;
cellOskDialogSetLayoutMode(LayoutMode);
//Select panels to be used using flags
// NOTE: We don't need CELL_OSKDIALOG_PANELMODE_JAPANESE_KATAKANA and \
// CELL_OSKDIALOG_PANELMODE_JAPANESE obviously (and Korean), so I'm \
// going to leave that all out
params->dialogParam.allowOskPanelFlg =
CELL_OSKDIALOG_PANELMODE_ALPHABET |
CELL_OSKDIALOG_PANELMODE_NUMERAL |
CELL_OSKDIALOG_PANELMODE_NUMERAL_FULL_WIDTH |
CELL_OSKDIALOG_PANELMODE_ENGLISH;
params->dialogParam.firstViewPanel = CELL_OSKDIALOG_PANELMODE_ENGLISH;
params->dialogParam.prohibitFlgs = 0;
}
void oskutil_write_message(oskutil_params *params, const wchar_t* msg)
{
params->inputFieldInfo.message = (uint16_t*)msg;
}
void oskutil_write_initial_message(oskutil_params *params, const wchar_t* msg)
{
params->inputFieldInfo.init_text = (uint16_t*)msg;
}
bool oskutil_start(oskutil_params *params)
{
memset(params->osk_text_buffer, 0, sizeof(*params->osk_text_buffer));
memset(params->osk_text_buffer_char, 0, 256);
//reset text output state before beginning new session
params->text_can_be_fetched = false;
if (params->flags & OSK_IN_USE)
return (true);
int ret = sys_memory_container_create(&params->containerid, params->osk_memorycontainer);
if(ret < 0)
return (false);
//Length limitation for input text
params->inputFieldInfo.limit_length = CELL_OSKDIALOG_STRING_SIZE;
oskutil_create_activation_parameters(params);
if(!oskutil_enable_key_layout())
return (false);
ret = cellOskDialogLoadAsync(params->containerid, &params->dialogParam, &params->inputFieldInfo);
if(ret < 0)
return (false);
params->flags |= OSK_IN_USE;
params->is_running = true;
return (true);
}
void oskutil_close(oskutil_params *params)
{
cellOskDialogAbort();
}
void oskutil_finished(oskutil_params *params)
{
params->outputInfo.result = CELL_OSKDIALOG_INPUT_FIELD_RESULT_OK; // Result onscreen keyboard dialog termination
params->outputInfo.numCharsResultString = 256; // Specify number of characters for returned text
params->outputInfo.pResultString = (uint16_t *)params->osk_text_buffer; // Buffer storing returned text
cellOskDialogUnloadAsync(&params->outputInfo);
int num;
switch (params->outputInfo.result)
{
case CELL_OSKDIALOG_INPUT_FIELD_RESULT_OK:
//The text we get from the outputInfo is Unicode, needs to be converted
num = wcstombs(params->osk_text_buffer_char, params->osk_text_buffer, 256);
params->osk_text_buffer_char[num]=0;
params->text_can_be_fetched = true;
break;
case CELL_OSKDIALOG_INPUT_FIELD_RESULT_CANCELED:
case CELL_OSKDIALOG_INPUT_FIELD_RESULT_ABORT:
case CELL_OSKDIALOG_INPUT_FIELD_RESULT_NO_INPUT_TEXT:
default:
params->osk_text_buffer_char[0]=0;
params->text_can_be_fetched = false;
break;
}
params->flags &= ~OSK_IN_USE;
}
void oskutil_unload(oskutil_params *params)
{
sys_memory_container_destroy(params->containerid);
params->is_running = false;
}

View File

@ -1,86 +0,0 @@
/* -- 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
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef __OSKUTIL_H__
#define __OSKUTIL_H__
#include <sysutil/sysutil_oskdialog.h>
#include <sysutil/sysutil_common.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#define OSK_IS_RUNNING(object) object.is_running
#define OUTPUT_TEXT_STRING(object) object.osk_text_buffer_char
typedef struct
{
unsigned int osk_memorycontainer;
wchar_t init_message[CELL_OSKDIALOG_STRING_SIZE + 1]; // buffer
wchar_t message[CELL_OSKDIALOG_STRING_SIZE + 1]; //buffer
wchar_t osk_text_buffer[CELL_OSKDIALOG_STRING_SIZE + 1];
char osk_text_buffer_char[CELL_OSKDIALOG_STRING_SIZE + 1];
uint32_t flags;
bool is_running;
bool text_can_be_fetched;
sys_memory_container_t containerid;
CellOskDialogPoint pos;
CellOskDialogInputFieldInfo inputFieldInfo;
CellOskDialogCallbackReturnParam outputInfo;
CellOskDialogParam dialogParam;
} oskutil_params;
#ifdef __cplusplus
extern "C" {
#endif
void oskutil_write_message(oskutil_params *params, const wchar_t* msg);
void oskutil_write_initial_message(oskutil_params *params, const wchar_t* msg);
void oskutil_init(oskutil_params *params, unsigned int containersize);
bool oskutil_start(oskutil_params *params);
void oskutil_stop(oskutil_params *params);
void oskutil_finished(oskutil_params *params);
void oskutil_close(oskutil_params *params);
void oskutil_unload(oskutil_params *params);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -21,6 +21,9 @@
#include <cell/pad.h>
#include <sdk_version.h>
#include <sys/memory.h>
#include <sysutil/sysutil_oskdialog.h>
#include <sysutil/sysutil_common.h>
#include "ps3_input.h"
#include "ps3_video_psgl.h"
@ -30,10 +33,14 @@
#include "../general.h"
#include "shared.h"
static uint64_t state[MAX_PADS];
/*============================================================
PS3 PAD
============================================================ */
#define MAP(x) (x & 0xFF)
static uint64_t state[MAX_PADS];
void cell_pad_input_deinit(void)
{
cellPadEnd();
@ -123,6 +130,136 @@ static int16_t ps3_input_state(void *data, const struct snes_keybind **binds,
return CTRL_MASK(state[player], button) ? 1 : 0;
}
/*============================================================
ON-SCREEN KEYBOARD UTILITY
============================================================ */
#define OSK_IN_USE (0x00000001)
void oskutil_init(oskutil_params *params, unsigned int containersize)
{
params->flags = 0;
params->is_running = false;
if(containersize)
params->osk_memorycontainer = containersize;
else
params->osk_memorycontainer = 1024*1024*7;
}
static bool oskutil_enable_key_layout()
{
int ret = cellOskDialogSetKeyLayoutOption(CELL_OSKDIALOG_10KEY_PANEL | \
CELL_OSKDIALOG_FULLKEY_PANEL);
if (ret < 0)
return (false);
else
return (true);
}
static void oskutil_create_activation_parameters(oskutil_params *params)
{
params->dialogParam.controlPoint.x = 0.0;
params->dialogParam.controlPoint.y = 0.0;
int32_t LayoutMode = CELL_OSKDIALOG_LAYOUTMODE_X_ALIGN_CENTER | CELL_OSKDIALOG_LAYOUTMODE_Y_ALIGN_TOP;
cellOskDialogSetLayoutMode(LayoutMode);
params->dialogParam.allowOskPanelFlg =
CELL_OSKDIALOG_PANELMODE_ALPHABET |
CELL_OSKDIALOG_PANELMODE_NUMERAL |
CELL_OSKDIALOG_PANELMODE_NUMERAL_FULL_WIDTH |
CELL_OSKDIALOG_PANELMODE_ENGLISH;
params->dialogParam.firstViewPanel = CELL_OSKDIALOG_PANELMODE_ENGLISH;
params->dialogParam.prohibitFlgs = 0;
}
void oskutil_write_message(oskutil_params *params, const wchar_t* msg)
{
params->inputFieldInfo.message = (uint16_t*)msg;
}
void oskutil_write_initial_message(oskutil_params *params, const wchar_t* msg)
{
params->inputFieldInfo.init_text = (uint16_t*)msg;
}
bool oskutil_start(oskutil_params *params)
{
memset(params->osk_text_buffer, 0, sizeof(*params->osk_text_buffer));
memset(params->osk_text_buffer_char, 0, 256);
params->text_can_be_fetched = false;
if (params->flags & OSK_IN_USE)
return (true);
int ret = sys_memory_container_create(&params->containerid, params->osk_memorycontainer);
if(ret < 0)
return (false);
params->inputFieldInfo.limit_length = CELL_OSKDIALOG_STRING_SIZE;
oskutil_create_activation_parameters(params);
if(!oskutil_enable_key_layout())
return (false);
ret = cellOskDialogLoadAsync(params->containerid, &params->dialogParam, &params->inputFieldInfo);
if(ret < 0)
return (false);
params->flags |= OSK_IN_USE;
params->is_running = true;
return (true);
}
void oskutil_close(oskutil_params *params)
{
cellOskDialogAbort();
}
void oskutil_finished(oskutil_params *params)
{
int num;
params->outputInfo.result = CELL_OSKDIALOG_INPUT_FIELD_RESULT_OK;
params->outputInfo.numCharsResultString = 256;
params->outputInfo.pResultString = (uint16_t *)params->osk_text_buffer;
cellOskDialogUnloadAsync(&params->outputInfo);
switch (params->outputInfo.result)
{
case CELL_OSKDIALOG_INPUT_FIELD_RESULT_OK:
num = wcstombs(params->osk_text_buffer_char, params->osk_text_buffer, 256);
params->osk_text_buffer_char[num]=0;
params->text_can_be_fetched = true;
break;
case CELL_OSKDIALOG_INPUT_FIELD_RESULT_CANCELED:
case CELL_OSKDIALOG_INPUT_FIELD_RESULT_ABORT:
case CELL_OSKDIALOG_INPUT_FIELD_RESULT_NO_INPUT_TEXT:
default:
params->osk_text_buffer_char[0]=0;
params->text_can_be_fetched = false;
break;
}
params->flags &= ~OSK_IN_USE;
}
void oskutil_unload(oskutil_params *params)
{
sys_memory_container_destroy(params->containerid);
params->is_running = false;
}
/*============================================================
SSNES PS3 INPUT DRIVER
============================================================ */
static void ps3_free_input(void *data)
{
(void)data;

View File

@ -19,6 +19,11 @@
#ifndef _PS3_INPUT_H_
#define _PS3_INPUT_H_
#include <stdbool.h>
#include <wchar.h>
#include <sysutil/sysutil_oskdialog.h>
#include <sysutil/sysutil_common.h>
#define MAX_PADS 7
#define CTRL_SELECT_MASK 0x01
@ -113,12 +118,14 @@
#define RSTICK_UP_SHIFT 54
#define RSTICK_DOWN_SHIFT 55
#define OSK_IS_RUNNING(object) object.is_running
#define OUTPUT_TEXT_STRING(object) object.osk_text_buffer_char
typedef uint64_t cell_input_state_t;
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);
@ -126,4 +133,31 @@ cell_input_state_t cell_pad_input_poll_device(uint32_t id);
void ps3_input_init(void);
void ps3_input_map_dpad_to_stick(uint32_t map_dpad_enum, uint32_t controller_id);
typedef struct
{
unsigned int osk_memorycontainer;
wchar_t init_message[CELL_OSKDIALOG_STRING_SIZE + 1];
wchar_t message[CELL_OSKDIALOG_STRING_SIZE + 1];
wchar_t osk_text_buffer[CELL_OSKDIALOG_STRING_SIZE + 1];
char osk_text_buffer_char[CELL_OSKDIALOG_STRING_SIZE + 1];
uint32_t flags;
bool is_running;
bool text_can_be_fetched;
sys_memory_container_t containerid;
CellOskDialogPoint pos;
CellOskDialogInputFieldInfo inputFieldInfo;
CellOskDialogCallbackReturnParam outputInfo;
CellOskDialogParam dialogParam;
} oskutil_params;
void oskutil_write_message(oskutil_params *params, const wchar_t* msg);
void oskutil_write_initial_message(oskutil_params *params, const wchar_t* msg);
void oskutil_init(oskutil_params *params, unsigned int containersize);
bool oskutil_start(oskutil_params *params);
void oskutil_stop(oskutil_params *params);
void oskutil_finished(oskutil_params *params);
void oskutil_close(oskutil_params *params);
void oskutil_unload(oskutil_params *params);
#endif