2015-04-01 22:14:13 +01:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2015-04-02 01:43:28 +02:00
|
|
|
* Copyright (C) 2014-2015 - Ali Bouhlel
|
2015-04-01 22:14:13 +01:00
|
|
|
*
|
|
|
|
* 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>
|
2015-09-28 14:55:23 +01:00
|
|
|
#include <unistd.h>
|
2015-04-01 22:14:13 +01:00
|
|
|
|
2015-09-15 04:49:10 +02:00
|
|
|
#include <boolean.h>
|
|
|
|
|
|
|
|
#include <3ds.h>
|
|
|
|
|
2015-04-01 22:14:13 +01:00
|
|
|
#include <file/file_path.h>
|
2015-06-15 22:45:02 +02:00
|
|
|
#ifndef IS_SALAMANDER
|
|
|
|
#include <file/file_list.h>
|
|
|
|
#endif
|
|
|
|
|
2015-04-01 22:14:13 +01:00
|
|
|
#include "../../general.h"
|
2015-09-13 22:33:35 +01:00
|
|
|
#include "retroarch.h"
|
2015-04-01 22:14:13 +01:00
|
|
|
|
|
|
|
#ifdef IS_SALAMANDER
|
|
|
|
#include "../../file_ext.h"
|
2015-06-15 22:45:02 +02:00
|
|
|
#else
|
2015-09-13 22:33:35 +01:00
|
|
|
#include "../../menu/menu.h"
|
2015-06-15 22:45:02 +02:00
|
|
|
#include "../../menu/menu_list.h"
|
2015-04-01 22:14:13 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
const char* elf_path_cst = "sdmc:/retroarch/test.3dsx";
|
|
|
|
|
2015-10-04 19:22:23 +01:00
|
|
|
#ifndef DEBUG_HOLD
|
2015-04-01 22:14:13 +01:00
|
|
|
void wait_for_input(void);
|
|
|
|
#define DEBUG_HOLD() do{printf("%s@%s:%d.\n",__FUNCTION__, __FILE__, __LINE__);fflush(stdout);wait_for_input();}while(0)
|
2015-10-04 19:22:23 +01:00
|
|
|
#endif
|
2015-04-01 22:14:13 +01:00
|
|
|
|
2015-10-01 23:18:59 +01:00
|
|
|
#define CTR_APPMEMALLOC_PTR ((u32*)0x1FF80040)
|
|
|
|
|
2015-09-20 07:28:11 +01:00
|
|
|
extern char* fake_heap_start;
|
|
|
|
extern char* fake_heap_end;
|
|
|
|
u32 __linear_heap;
|
|
|
|
u32 __heapBase;
|
2015-10-05 21:45:17 +01:00
|
|
|
static u32 heap_size;
|
|
|
|
extern u32 linear_heap_size;
|
2015-09-20 07:28:11 +01:00
|
|
|
|
|
|
|
extern void (*__system_retAddr)(void);
|
|
|
|
|
|
|
|
void __destroy_handle_list(void);
|
|
|
|
void __appExit();
|
|
|
|
void __libc_fini_array(void);
|
|
|
|
|
|
|
|
void __system_allocateHeaps() {
|
2015-10-02 01:45:34 +01:00
|
|
|
extern unsigned int __service_ptr;
|
|
|
|
u32 tmp=0;
|
2015-09-20 21:46:10 +01:00
|
|
|
int64_t mem_used;
|
2015-10-02 01:45:34 +01:00
|
|
|
u32 app_memory = 0x04000000;
|
|
|
|
|
|
|
|
if(!__service_ptr)
|
|
|
|
app_memory = *CTR_APPMEMALLOC_PTR;
|
|
|
|
|
2015-09-20 21:46:10 +01:00
|
|
|
svcGetSystemInfo(&mem_used, 0, 1);
|
2015-09-20 07:28:11 +01:00
|
|
|
|
2015-10-17 14:13:07 +08:00
|
|
|
// For n3DS running with 124MB, only 110MB appears actually available
|
|
|
|
app_memory = app_memory > 0x6E00000 ? 0x6E00000 : app_memory;
|
|
|
|
|
2015-10-05 21:45:17 +01:00
|
|
|
heap_size = (app_memory - mem_used - linear_heap_size - 0x10000) & 0xFFFFF000;
|
2015-09-20 07:28:11 +01:00
|
|
|
|
|
|
|
// Allocate the application heap
|
|
|
|
__heapBase = 0x08000000;
|
2015-10-05 21:45:17 +01:00
|
|
|
svcControlMemory(&tmp, __heapBase, 0x0, heap_size, MEMOP_ALLOC, MEMPERM_READ | MEMPERM_WRITE);
|
2015-09-20 07:28:11 +01:00
|
|
|
|
|
|
|
// Allocate the linear heap
|
2015-10-05 21:45:17 +01:00
|
|
|
svcControlMemory(&__linear_heap, 0x0, 0x0, linear_heap_size, MEMOP_ALLOC_LINEAR, MEMPERM_READ | MEMPERM_WRITE);
|
2015-09-20 07:28:11 +01:00
|
|
|
// Set up newlib heap
|
|
|
|
fake_heap_start = (char*)__heapBase;
|
2015-10-05 21:45:17 +01:00
|
|
|
fake_heap_end = fake_heap_start + heap_size;
|
2015-09-20 07:28:11 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void __attribute__((noreturn)) __libctru_exit(int rc)
|
|
|
|
{
|
|
|
|
u32 tmp=0;
|
|
|
|
|
|
|
|
// Unmap the linear heap
|
2015-10-05 21:45:17 +01:00
|
|
|
svcControlMemory(&tmp, __linear_heap, 0x0, linear_heap_size, MEMOP_FREE, 0x0);
|
2015-09-20 07:28:11 +01:00
|
|
|
|
|
|
|
// Unmap the application heap
|
2015-10-05 21:45:17 +01:00
|
|
|
svcControlMemory(&tmp, __heapBase, 0x0, heap_size, MEMOP_FREE, 0x0);
|
2015-09-20 07:28:11 +01:00
|
|
|
|
|
|
|
// Close some handles
|
|
|
|
__destroy_handle_list();
|
|
|
|
|
|
|
|
// Jump to the loader if it provided a callback
|
|
|
|
if (__system_retAddr)
|
|
|
|
__system_retAddr();
|
|
|
|
|
|
|
|
// Since above did not jump, end this process
|
|
|
|
svcExitProcess();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-04-01 22:14:13 +01:00
|
|
|
static void frontend_ctr_get_environment_settings(int *argc, char *argv[],
|
|
|
|
void *args, void *params_data)
|
|
|
|
{
|
|
|
|
(void)args;
|
|
|
|
|
|
|
|
#ifndef IS_SALAMANDER
|
|
|
|
#if defined(HAVE_LOGGER)
|
|
|
|
logger_init();
|
|
|
|
#elif defined(HAVE_FILE_LOGGER)
|
|
|
|
global_t *global = global_get_ptr();
|
|
|
|
global->log_file = fopen("sdmc:/retroarch/retroarch-log.txt", "w");
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2015-07-27 17:18:10 +02:00
|
|
|
fill_pathname_basedir(g_defaults.dir.port, elf_path_cst, sizeof(g_defaults.dir.port));
|
|
|
|
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.port,
|
|
|
|
"cores", 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));
|
2015-09-15 10:19:48 -05:00
|
|
|
fill_pathname_join(g_defaults.dir.remap, g_defaults.dir.port,
|
|
|
|
"remaps", sizeof(g_defaults.dir.remap));
|
2015-07-27 17:18:10 +02:00
|
|
|
fill_pathname_join(g_defaults.path.config, g_defaults.dir.port,
|
|
|
|
"retroarch.cfg", sizeof(g_defaults.path.config));
|
2015-04-01 22:14:13 +01:00
|
|
|
|
|
|
|
#ifndef IS_SALAMANDER
|
2015-04-18 17:34:14 +02:00
|
|
|
#if 0
|
|
|
|
if (argv[1] && (argv[1][0] != '\0'))
|
|
|
|
{
|
|
|
|
static char path[PATH_MAX_LENGTH];
|
|
|
|
struct rarch_main_wrap *args = NULL;
|
|
|
|
|
|
|
|
*path = '\0';
|
|
|
|
args = (struct rarch_main_wrap*)params_data;
|
|
|
|
|
|
|
|
if (args)
|
|
|
|
{
|
|
|
|
strlcpy(path, argv[1], sizeof(path));
|
|
|
|
|
|
|
|
args->touched = true;
|
|
|
|
args->no_content = false;
|
|
|
|
args->verbose = false;
|
|
|
|
args->config_path = NULL;
|
|
|
|
args->sram_path = NULL;
|
|
|
|
args->state_path = NULL;
|
|
|
|
args->content_path = path;
|
|
|
|
args->libretro_path = NULL;
|
|
|
|
|
|
|
|
RARCH_LOG("argv[0]: %s\n", argv[0]);
|
|
|
|
RARCH_LOG("argv[1]: %s\n", argv[1]);
|
|
|
|
RARCH_LOG("argv[2]: %s\n", argv[2]);
|
|
|
|
|
|
|
|
RARCH_LOG("Auto-start game %s.\n", argv[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2015-04-01 22:14:13 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void frontend_ctr_deinit(void *data)
|
|
|
|
{
|
2015-10-01 18:12:59 +01:00
|
|
|
extern PrintConsole* currentConsole;
|
|
|
|
Handle lcd_handle;
|
2015-10-03 19:37:01 +01:00
|
|
|
u8 not_2DS;
|
2015-04-01 22:14:13 +01:00
|
|
|
(void)data;
|
|
|
|
#ifndef IS_SALAMANDER
|
|
|
|
global_t *global = global_get_ptr();
|
|
|
|
global->verbosity = true;
|
|
|
|
|
|
|
|
#ifdef HAVE_FILE_LOGGER
|
|
|
|
if (global->log_file)
|
|
|
|
fclose(global->log_file);
|
|
|
|
global->log_file = NULL;
|
|
|
|
#endif
|
|
|
|
|
2015-10-01 18:12:59 +01:00
|
|
|
if(gfxBottomFramebuffers[0] == (u8*)currentConsole->frameBuffer)
|
|
|
|
wait_for_input();
|
|
|
|
|
2015-10-03 19:37:01 +01:00
|
|
|
CFGU_GetModelNintendo2DS(¬_2DS);
|
|
|
|
if(not_2DS && srvGetServiceHandle(&lcd_handle, "gsp::Lcd") >= 0)
|
2015-10-01 18:12:59 +01:00
|
|
|
{
|
|
|
|
u32 *cmdbuf = getThreadCommandBuffer();
|
|
|
|
cmdbuf[0] = 0x00110040;
|
|
|
|
cmdbuf[1] = 2;
|
|
|
|
svcSendSyncRequest(lcd_handle);
|
|
|
|
svcCloseHandle(lcd_handle);
|
|
|
|
}
|
2015-04-05 20:39:18 +01:00
|
|
|
|
2015-10-03 19:37:01 +01:00
|
|
|
exitCfgu();
|
2015-04-10 19:10:34 +01:00
|
|
|
csndExit();
|
2015-04-01 22:14:13 +01:00
|
|
|
gfxExit();
|
2015-04-10 19:10:34 +01:00
|
|
|
|
2015-04-18 17:34:14 +02:00
|
|
|
#if 0
|
|
|
|
sdmcExit();
|
|
|
|
fsExit();
|
|
|
|
hidExit();
|
|
|
|
aptExit();
|
|
|
|
srvExit();
|
|
|
|
#endif
|
2015-04-01 22:14:13 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void frontend_ctr_shutdown(bool unused)
|
|
|
|
{
|
|
|
|
(void)unused;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define PRINTFPOS(X,Y) "\x1b["#X";"#Y"H"
|
|
|
|
#define PRINTFPOS_STR(X,Y) "\x1b["X";"Y"H"
|
2015-04-18 17:34:14 +02:00
|
|
|
|
2015-04-01 22:14:13 +01:00
|
|
|
static void frontend_ctr_init(void *data)
|
|
|
|
{
|
|
|
|
#ifndef IS_SALAMANDER
|
|
|
|
(void)data;
|
|
|
|
global_t *global = global_get_ptr();
|
|
|
|
global->verbosity = true;
|
|
|
|
|
2015-04-18 17:34:14 +02:00
|
|
|
#if 0
|
|
|
|
srvInit();
|
|
|
|
aptInit();
|
|
|
|
hidInit();
|
|
|
|
fsInit();
|
|
|
|
sdmcInit();
|
2015-04-10 19:10:34 +01:00
|
|
|
|
2015-04-18 17:34:14 +02:00
|
|
|
APT_SetAppCpuTimeLimit(NULL, 80);
|
|
|
|
gfxInitDefault();
|
|
|
|
#endif
|
2015-04-05 20:39:18 +01:00
|
|
|
gfxInit(GSP_BGR8_OES,GSP_RGB565_OES,false);
|
2015-04-10 19:10:34 +01:00
|
|
|
csndInit();
|
2015-10-03 19:37:01 +01:00
|
|
|
initCfgu();
|
2015-04-01 22:14:13 +01:00
|
|
|
gfxSet3D(false);
|
|
|
|
consoleInit(GFX_BOTTOM, NULL);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int frontend_ctr_get_rating(void)
|
|
|
|
{
|
2015-04-05 20:39:18 +01:00
|
|
|
return 3;
|
2015-04-01 22:14:13 +01:00
|
|
|
}
|
2015-04-18 17:34:14 +02:00
|
|
|
|
2015-04-01 22:14:13 +01:00
|
|
|
bool select_pressed = false;
|
2015-04-18 17:34:14 +02:00
|
|
|
|
|
|
|
void wait_for_input(void)
|
2015-04-01 22:14:13 +01:00
|
|
|
{
|
2015-04-18 17:34:14 +02:00
|
|
|
printf("\n\nPress Start.\n\n");
|
|
|
|
fflush(stdout);
|
|
|
|
|
2015-04-01 22:14:13 +01:00
|
|
|
while(aptMainLoop())
|
|
|
|
{
|
2015-04-18 17:34:14 +02:00
|
|
|
u32 kDown;
|
|
|
|
|
2015-04-01 22:14:13 +01:00
|
|
|
hidScanInput();
|
2015-04-18 17:34:14 +02:00
|
|
|
|
|
|
|
kDown = hidKeysDown();
|
|
|
|
|
2015-04-01 22:14:13 +01:00
|
|
|
if (kDown & KEY_START)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (kDown & KEY_SELECT)
|
2015-09-19 11:12:48 +01:00
|
|
|
exit(0);
|
2015-09-22 18:55:14 +02:00
|
|
|
#if 0
|
|
|
|
select_pressed = true;
|
|
|
|
#endif
|
2015-04-01 22:14:13 +01:00
|
|
|
|
2015-09-22 18:55:14 +02:00
|
|
|
retro_sleep(1);
|
2015-04-01 22:14:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-19 11:12:48 +01:00
|
|
|
int usleep (useconds_t us)
|
|
|
|
{
|
|
|
|
svcSleepThread((int64_t)us * 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
long sysconf(int name)
|
|
|
|
{
|
|
|
|
switch(name)
|
|
|
|
{
|
|
|
|
case _SC_NPROCESSORS_ONLN:
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-18 20:03:59 +02:00
|
|
|
enum frontend_architecture frontend_ctr_get_architecture(void)
|
|
|
|
{
|
|
|
|
return FRONTEND_ARCH_ARM;
|
|
|
|
}
|
|
|
|
|
2015-06-15 22:45:02 +02:00
|
|
|
static int frontend_ctr_parse_drive_list(void *data)
|
|
|
|
{
|
|
|
|
file_list_t *list = (file_list_t*)data;
|
|
|
|
|
|
|
|
#ifndef IS_SALAMANDER
|
|
|
|
if (!list)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
menu_list_push(list,
|
|
|
|
"sdmc:/", "", MENU_FILE_DIRECTORY, 0, 0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-27 03:44:28 +02:00
|
|
|
frontend_ctx_driver_t frontend_ctx_ctr = {
|
2015-04-18 20:03:59 +02:00
|
|
|
frontend_ctr_get_environment_settings,
|
|
|
|
frontend_ctr_init,
|
|
|
|
frontend_ctr_deinit,
|
2015-04-01 22:14:13 +01:00
|
|
|
NULL, /* exitspawn */
|
|
|
|
NULL, /* process_args */
|
|
|
|
NULL, /* exec */
|
|
|
|
NULL, /* set_fork */
|
2015-04-18 20:03:59 +02:00
|
|
|
frontend_ctr_shutdown,
|
2015-04-01 22:14:13 +01:00
|
|
|
NULL, /* get_name */
|
2015-04-07 22:48:46 +02:00
|
|
|
NULL, /* get_os */
|
2015-04-18 20:03:59 +02:00
|
|
|
frontend_ctr_get_rating,
|
2015-04-01 22:14:13 +01:00
|
|
|
NULL, /* load_content */
|
2015-04-18 20:03:59 +02:00
|
|
|
frontend_ctr_get_architecture,
|
2015-04-18 13:56:26 +02:00
|
|
|
NULL, /* get_powerstate */
|
2015-06-15 22:45:02 +02:00
|
|
|
frontend_ctr_parse_drive_list,
|
2015-04-01 22:14:13 +01:00
|
|
|
"ctr",
|
|
|
|
};
|