RetroArch/frontend/drivers/platform_wiiu.c

330 lines
9.1 KiB
C
Raw Normal View History

2016-10-27 01:34:10 +01:00
/* RetroArch - A frontend for libretro.
* Copyright (C) 2014-2016 - Ali Bouhlel
*
* RetroArch 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.
*
* RetroArch 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 RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include <ctype.h>
#include <boolean.h>
#include <file/file_path.h>
#include <lists/file_list.h>
#include "../frontend_driver.h"
#include "../frontend.h"
#include "../../configuration.h"
#include "../../verbosity.h"
#include "../../defaults.h"
#include "../../paths.h"
#include "retroarch.h"
#include "file_path_special.h"
#include "audio/audio_driver.h"
#include "tasks/tasks_internal.h"
#include "runloop.h"
#include "dynamic_libs/os_functions.h"
#include "dynamic_libs/fs_functions.h"
#include "dynamic_libs/gx2_functions.h"
#include "dynamic_libs/sys_functions.h"
#include "dynamic_libs/vpad_functions.h"
#include "dynamic_libs/padscore_functions.h"
#include "dynamic_libs/socket_functions.h"
2016-10-27 19:53:27 +01:00
//#include "dynamic_libs/curl_functions.h"
2016-10-27 01:34:10 +01:00
#include "dynamic_libs/ax_functions.h"
2016-10-27 19:53:27 +01:00
//#include "dynamic_libs/aoc_functions.h"
//#include "dynamic_libs/acp_functions.h"
2016-10-27 01:34:10 +01:00
#include "fs/fs_utils.h"
#include "fs/sd_fat_devoptab.h"
#include "system/memory.h"
2016-10-27 19:53:27 +01:00
#include "system/exception_handler.h"
2016-10-27 23:20:28 +01:00
#include "system/exception.h"
2016-10-27 01:34:10 +01:00
#include "utils/logger.h"
#include "utils/utils.h"
#include "common/common.h"
#include <sys/iosupport.h>
#include "wiiu_dbg.h"
#ifdef HAVE_MENU
#include "../../menu/menu_driver.h"
#endif
static enum frontend_fork wiiu_fork_mode = FRONTEND_FORK_NONE;
static const char* elf_path_cst = "sd:/retroarch/retroarch.elf";
static void frontend_wiiu_get_environment_settings(int *argc, char *argv[],
void *args, void *params_data)
{
(void)args;
DEBUG_LINE();
fill_pathname_basedir(g_defaults.dir.port, elf_path_cst, sizeof(g_defaults.dir.port));
DEBUG_LINE();
RARCH_LOG("port dir: [%s]\n", g_defaults.dir.port);
fill_pathname_join(g_defaults.dir.core_assets, g_defaults.dir.port,
"downloads", sizeof(g_defaults.dir.core_assets));
fill_pathname_join(g_defaults.dir.assets, g_defaults.dir.port,
"media", sizeof(g_defaults.dir.assets));
fill_pathname_join(g_defaults.dir.core, g_defaults.dir.port,
"cores", sizeof(g_defaults.dir.core));
fill_pathname_join(g_defaults.dir.core_info, g_defaults.dir.core,
"info", sizeof(g_defaults.dir.core_info));
fill_pathname_join(g_defaults.dir.savestate, g_defaults.dir.core,
"savestates", sizeof(g_defaults.dir.savestate));
fill_pathname_join(g_defaults.dir.sram, g_defaults.dir.core,
"savefiles", sizeof(g_defaults.dir.sram));
fill_pathname_join(g_defaults.dir.system, g_defaults.dir.core,
"system", sizeof(g_defaults.dir.system));
fill_pathname_join(g_defaults.dir.playlist, g_defaults.dir.core,
"playlists", sizeof(g_defaults.dir.playlist));
fill_pathname_join(g_defaults.dir.menu_config, g_defaults.dir.port,
"config", sizeof(g_defaults.dir.menu_config));
fill_pathname_join(g_defaults.dir.remap, g_defaults.dir.port,
"config/remaps", sizeof(g_defaults.dir.remap));
fill_pathname_join(g_defaults.dir.video_filter, g_defaults.dir.port,
"filters", sizeof(g_defaults.dir.remap));
fill_pathname_join(g_defaults.dir.database, g_defaults.dir.port,
"database/rdb", sizeof(g_defaults.dir.database));
fill_pathname_join(g_defaults.dir.cursor, g_defaults.dir.port,
"database/cursors", sizeof(g_defaults.dir.cursor));
fill_pathname_join(g_defaults.path.config, g_defaults.dir.port,
file_path_str(FILE_PATH_MAIN_CONFIG), sizeof(g_defaults.path.config));
}
static void frontend_wiiu_deinit(void *data)
{
(void)data;
}
static void frontend_wiiu_shutdown(bool unused)
{
(void)unused;
}
static void frontend_wiiu_init(void *data)
{
(void)data;
DEBUG_LINE();
verbosity_enable();
DEBUG_LINE();
}
static int frontend_wiiu_get_rating(void)
{
return 10;
}
enum frontend_architecture frontend_wiiu_get_architecture(void)
{
return FRONTEND_ARCH_PPC;
}
static int frontend_wiiu_parse_drive_list(void *data)
{
file_list_t *list = (file_list_t*)data;
if (!list)
return -1;
menu_entries_append_enum(list,
"sd:/", "", MSG_UNKNOWN, FILE_TYPE_DIRECTORY, 0, 0);
return 0;
}
frontend_ctx_driver_t frontend_ctx_wiiu = {
frontend_wiiu_get_environment_settings,
frontend_wiiu_init,
frontend_wiiu_deinit,
NULL, /* exitspawn */
NULL, /* process_args */
NULL, /* exec */
NULL, /* set_fork */
frontend_wiiu_shutdown,
NULL, /* get_name */
NULL, /* get_os */
frontend_wiiu_get_rating,
NULL, /* load_content */
frontend_wiiu_get_architecture,
NULL, /* get_powerstate */
frontend_wiiu_parse_drive_list,
NULL, /* get_mem_total */
NULL, /* get_mem_free */
NULL, /* install_signal_handler */
NULL, /* get_signal_handler_state */
NULL, /* set_signal_handler_state */
NULL, /* destroy_signal_handler_state */
NULL, /* attach_console */
NULL, /* detach_console */
"wiiu",
};
static int log_socket = -1;
static volatile int log_lock = 0;
void log_init(const char * ipString)
{
log_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (log_socket < 0)
return;
struct sockaddr_in connect_addr;
memset(&connect_addr, 0, sizeof(connect_addr));
connect_addr.sin_family = AF_INET;
connect_addr.sin_port = 4405;
inet_aton(ipString, &connect_addr.sin_addr);
if(connect(log_socket, (struct sockaddr*)&connect_addr, sizeof(connect_addr)) < 0)
{
socketclose(log_socket);
log_socket = -1;
}
}
void log_deinit(void)
{
if(log_socket >= 0)
{
socketclose(log_socket);
log_socket = -1;
}
}
static int log_write(struct _reent *r, int fd, const char *ptr, size_t len)
{
if(log_socket < 0)
return len;
while(log_lock)
OSSleepTicks(((BUS_SPEED/4)) / 1000);
log_lock = 1;
int ret;
while (len > 0) {
int block = len < 1400 ? len : 1400; // take max 1400 bytes per UDP packet
ret = send(log_socket, ptr, block, 0);
if(ret < 0)
break;
len -= ret;
ptr += ret;
}
log_lock = 0;
return len;
}
2016-10-27 23:02:40 +01:00
void net_print(const char* str)
{
log_write(NULL, 0, str, strlen(str));
}
2016-10-27 01:34:10 +01:00
static devoptab_t dotab_stdout = {
"stdout", // device name
0, // size of file structure
NULL, // device open
NULL, // device close
log_write, // device write
NULL, // device read
NULL, // device seek
NULL, // device fstat
NULL, // device stat
NULL, // device link
NULL, // device unlink
NULL, // device chdir
NULL, // device rename
NULL, // device mkdir
0, // dirStateSize
NULL, // device diropen_r
NULL, // device dirreset_r
NULL, // device dirnext_r
NULL, // device dirclose_r
NULL, // device statvfs_r
NULL, // device ftrunctate_r
NULL, // device fsync_r
NULL, // deviceData;
};
int __entry_menu(int argc, char **argv)
{
InitOSFunctionPointers();
InitSocketFunctionPointers();
log_init("10.42.0.1");
devoptab_list[STD_OUT] = &dotab_stdout;
devoptab_list[STD_ERR] = &dotab_stdout;
2016-10-27 19:53:27 +01:00
2016-10-27 01:34:10 +01:00
InitFSFunctionPointers();
2016-10-27 19:53:27 +01:00
InitGX2FunctionPointers();
InitSysFunctionPointers();
2016-10-27 01:34:10 +01:00
InitVPadFunctionPointers();
2016-10-27 19:53:27 +01:00
InitPadScoreFunctionPointers();
InitAXFunctionPointers();
// InitCurlFunctionPointers();
// InitAocFunctionPointers();
// InitACPFunctionPointers();
2016-10-27 01:34:10 +01:00
memoryInitialize();
mount_sd_fat("sd");
2016-10-27 23:20:28 +01:00
// setup_os_exceptions();
InstallExceptionHandler();
2016-10-27 01:34:10 +01:00
VPADInit();
OSScreenInit();
int vpadError = -1;
VPADData vpad;
verbosity_enable();
DEBUG_VAR(argc);
DEBUG_STR(argv[0]);
DEBUG_STR(argv[1]);
#if 0
int argc_ = 2;
char* argv_[] = {"retroarch.elf", "sd:/zz.gb"};
rarch_main(argc_, argv_, NULL);
#else
rarch_main(argc, argv, NULL);
#endif
int frames = 0;
do
{
unsigned sleep_ms = 0;
int ret = runloop_iterate(&sleep_ms);
2016-10-27 23:02:40 +01:00
// if (ret == 1 && sleep_ms > 0)
// retro_sleep(sleep_ms);
2016-10-27 01:34:10 +01:00
task_queue_ctl(TASK_QUEUE_CTL_CHECK, NULL);
if (ret == -1)
break;
}while(1);
// }while(frames++ < 300);
main_exit(NULL);
printf("Unmount SD\n");
unmount_sd_fat("sd");
printf("Release memory\n");
memoryRelease();
log_deinit();
return 0;
}