[3DS] Update to libctru 2.0
Set USE_CTRULIB_2=1 to build with libctru 2.0. When unset, this code is compatible with the older toolchain. Some 2.0 changes addressed rare problems in earlier versions: - Save / restore stack pointer for init / exit Otherwise, it could be outside of the range we deallocate. - Run aptMainLoop in the audio driver to react correctly to sleep events Other changes for 2.0: - Remove ninjhax1 -- requires outdated APIs that have been removed - Switch from __sync_arbiter to syncArbitrateAddress - Use implicit gxCmdBuf - Use gpuPresentBuffer for double buffering
This commit is contained in:
parent
4177ea4256
commit
9ae2514009
28
Makefile.ctr
28
Makefile.ctr
|
@ -8,6 +8,7 @@ BUILD_3DSX = 1
|
||||||
BUILD_3DS = 0
|
BUILD_3DS = 0
|
||||||
BUILD_CIA = 1
|
BUILD_CIA = 1
|
||||||
LIBCTRU_NO_DEPRECATION = 1
|
LIBCTRU_NO_DEPRECATION = 1
|
||||||
|
USE_CTRULIB_2 = 0
|
||||||
|
|
||||||
APP_TITLE = RetroArch 3DS
|
APP_TITLE = RetroArch 3DS
|
||||||
APP_DESCRIPTION = RetroArch 3DS
|
APP_DESCRIPTION = RetroArch 3DS
|
||||||
|
@ -35,8 +36,7 @@ OBJ += ctr/exec-3dsx/exec_cia.o \
|
||||||
ctr/exec-3dsx/exec_3dsx.o \
|
ctr/exec-3dsx/exec_3dsx.o \
|
||||||
ctr/exec-3dsx/mini-hb-menu/launch.o \
|
ctr/exec-3dsx/mini-hb-menu/launch.o \
|
||||||
ctr/exec-3dsx/mini-hb-menu/loaders/rosalina.o \
|
ctr/exec-3dsx/mini-hb-menu/loaders/rosalina.o \
|
||||||
ctr/exec-3dsx/mini-hb-menu/loaders/hax2.o \
|
ctr/exec-3dsx/mini-hb-menu/loaders/hax2.o
|
||||||
ctr/exec-3dsx/mini-hb-menu/loaders/ninjhax1.o
|
|
||||||
|
|
||||||
ifeq ($(APP_BIG_TEXT_SECTION), 1)
|
ifeq ($(APP_BIG_TEXT_SECTION), 1)
|
||||||
APP_USE_SVCHAX = 1
|
APP_USE_SVCHAX = 1
|
||||||
|
@ -104,6 +104,18 @@ ifeq ($(strip $(CTRULIB)),)
|
||||||
CTRULIB = $(DEVKITPRO)/libctru
|
CTRULIB = $(DEVKITPRO)/libctru
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(strip $(USE_CTRULIB_2)),1)
|
||||||
|
CFLAGS += -DUSE_CTRULIB_2
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(strip $(DEVKITTOOLS)),)
|
||||||
|
ifeq ($(strip $(USE_CTRULIB_2)),1)
|
||||||
|
DEVKITTOOLS = $(DEVKITPRO)/tools
|
||||||
|
else
|
||||||
|
DEVKITTOOLS = $(DEVKITARM)
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
APP_TITLE := $(shell echo "$(APP_TITLE)" | cut -c1-128)
|
APP_TITLE := $(shell echo "$(APP_TITLE)" | cut -c1-128)
|
||||||
APP_DESCRIPTION := $(shell echo "$(APP_DESCRIPTION)" | cut -c1-256)
|
APP_DESCRIPTION := $(shell echo "$(APP_DESCRIPTION)" | cut -c1-256)
|
||||||
APP_AUTHOR := $(shell echo "$(APP_AUTHOR)" | cut -c1-128)
|
APP_AUTHOR := $(shell echo "$(APP_AUTHOR)" | cut -c1-128)
|
||||||
|
@ -225,13 +237,13 @@ else
|
||||||
endif
|
endif
|
||||||
|
|
||||||
%.o: %.vsh %.gsh
|
%.o: %.vsh %.gsh
|
||||||
$(DEVKITARM)/bin/picasso $^ -o $*.shbin
|
$(DEVKITTOOLS)/bin/picasso $^ -o $*.shbin
|
||||||
$(DEVKITARM)/bin/bin2s $*.shbin | $(PREFIX)as -o $@
|
$(DEVKITTOOLS)/bin/bin2s $*.shbin | $(PREFIX)as -o $@
|
||||||
rm $*.shbin
|
rm $*.shbin
|
||||||
|
|
||||||
%.o: %.vsh
|
%.o: %.vsh
|
||||||
$(DEVKITARM)/bin/picasso $^ -o $*.shbin
|
$(DEVKITTOOLS)/bin/picasso $^ -o $*.shbin
|
||||||
$(DEVKITARM)/bin/bin2s $*.shbin | $(PREFIX)as -o $@
|
$(DEVKITTOOLS)/bin/bin2s $*.shbin | $(PREFIX)as -o $@
|
||||||
rm $*.shbin
|
rm $*.shbin
|
||||||
|
|
||||||
%.o: %.cpp
|
%.o: %.cpp
|
||||||
|
@ -252,7 +264,7 @@ endif
|
||||||
%.vsh:
|
%.vsh:
|
||||||
|
|
||||||
$(TARGET).smdh: $(APP_ICON)
|
$(TARGET).smdh: $(APP_ICON)
|
||||||
$(DEVKITARM)/bin/smdhtool --create "$(APP_TITLE)" "$(APP_DESCRIPTION)" "$(APP_AUTHOR)" $(APP_ICON) $@
|
$(DEVKITTOOLS)/bin/smdhtool --create "$(APP_TITLE)" "$(APP_DESCRIPTION)" "$(APP_AUTHOR)" $(APP_ICON) $@
|
||||||
|
|
||||||
$(TARGET).3dsx: $(TARGET).elf
|
$(TARGET).3dsx: $(TARGET).elf
|
||||||
ifeq ($(APP_BIG_TEXT_SECTION), 1)
|
ifeq ($(APP_BIG_TEXT_SECTION), 1)
|
||||||
|
@ -260,7 +272,7 @@ ifeq ($(APP_BIG_TEXT_SECTION), 1)
|
||||||
else
|
else
|
||||||
rm -f $(TARGET).xml
|
rm -f $(TARGET).xml
|
||||||
endif
|
endif
|
||||||
$(DEVKITARM)/bin/3dsxtool $< $@ $(_3DSXFLAGS)
|
$(DEVKITTOOLS)/bin/3dsxtool $< $@ $(_3DSXFLAGS)
|
||||||
|
|
||||||
$(TARGET).elf: ctr/3dsx_custom_crt0.o
|
$(TARGET).elf: ctr/3dsx_custom_crt0.o
|
||||||
$(LD) $(LDFLAGS) $(OBJ) $(LIBDIRS) $(LIBS) -o $@
|
$(LD) $(LDFLAGS) $(OBJ) $(LIBDIRS) $(LIBS) -o $@
|
||||||
|
|
|
@ -5,6 +5,7 @@ DEBUG = 0
|
||||||
BUILD_3DSX = 1
|
BUILD_3DSX = 1
|
||||||
BUILD_3DS = 0
|
BUILD_3DS = 0
|
||||||
BUILD_CIA = 1
|
BUILD_CIA = 1
|
||||||
|
USE_CTRULIB_2 = 0
|
||||||
|
|
||||||
APP_TITLE = RetroArch 3DS
|
APP_TITLE = RetroArch 3DS
|
||||||
APP_DESCRIPTION = RetroArch 3DS
|
APP_DESCRIPTION = RetroArch 3DS
|
||||||
|
@ -46,13 +47,24 @@ OBJ += ctr/exec-3dsx/exec_cia.o \
|
||||||
ctr/exec-3dsx/exec_3dsx.o \
|
ctr/exec-3dsx/exec_3dsx.o \
|
||||||
ctr/exec-3dsx/mini-hb-menu/launch.o \
|
ctr/exec-3dsx/mini-hb-menu/launch.o \
|
||||||
ctr/exec-3dsx/mini-hb-menu/loaders/rosalina.o \
|
ctr/exec-3dsx/mini-hb-menu/loaders/rosalina.o \
|
||||||
ctr/exec-3dsx/mini-hb-menu/loaders/hax2.o \
|
ctr/exec-3dsx/mini-hb-menu/loaders/hax2.o
|
||||||
ctr/exec-3dsx/mini-hb-menu/loaders/ninjhax1.o
|
|
||||||
|
|
||||||
ifeq ($(strip $(DEVKITPRO)),)
|
ifeq ($(strip $(DEVKITPRO)),)
|
||||||
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>devkitpro")
|
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>devkitpro")
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(strip $(USE_CTRULIB_2)),1)
|
||||||
|
CFLAGS += -DUSE_CTRULIB_2
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(strip $(DEVKITTOOLS)),)
|
||||||
|
ifeq ($(strip $(USE_CTRULIB_2)),1)
|
||||||
|
DEVKITTOOLS = $(DEVKITPRO)/tools
|
||||||
|
else
|
||||||
|
DEVKITTOOLS = $(DEVKITARM)
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(strip $(CTRULIB)),)
|
ifeq ($(strip $(CTRULIB)),)
|
||||||
CTRULIB = $(DEVKITPRO)/libctru
|
CTRULIB = $(DEVKITPRO)/libctru
|
||||||
endif
|
endif
|
||||||
|
@ -154,13 +166,13 @@ else
|
||||||
endif
|
endif
|
||||||
|
|
||||||
%.o: %.vsh %.gsh
|
%.o: %.vsh %.gsh
|
||||||
$(DEVKITARM)/bin/picasso $^ -o $*.shbin
|
$(DEVKITTOOLS)/bin/picasso $^ -o $*.shbin
|
||||||
$(DEVKITARM)/bin/bin2s $*.shbin | $(PREFIX)as -o $@
|
$(DEVKITTOOLS)/bin/bin2s $*.shbin | $(PREFIX)as -o $@
|
||||||
rm $*.shbin
|
rm $*.shbin
|
||||||
|
|
||||||
%.o: %.vsh
|
%.o: %.vsh
|
||||||
$(DEVKITARM)/bin/picasso $^ -o $*.shbin
|
$(DEVKITTOOLS)/bin/picasso $^ -o $*.shbin
|
||||||
$(DEVKITARM)/bin/bin2s $*.shbin | $(PREFIX)as -o $@
|
$(DEVKITTOOLS)/bin/bin2s $*.shbin | $(PREFIX)as -o $@
|
||||||
rm $*.shbin
|
rm $*.shbin
|
||||||
|
|
||||||
%.o: %.cpp
|
%.o: %.cpp
|
||||||
|
@ -181,7 +193,7 @@ endif
|
||||||
%.vsh:
|
%.vsh:
|
||||||
|
|
||||||
$(TARGET).smdh: $(APP_ICON)
|
$(TARGET).smdh: $(APP_ICON)
|
||||||
$(DEVKITARM)/bin/smdhtool --create "$(APP_TITLE)" "$(APP_DESCRIPTION)" "$(APP_AUTHOR)" $(APP_ICON) $@
|
$(DEVKITTOOLS)/bin/smdhtool --create "$(APP_TITLE)" "$(APP_DESCRIPTION)" "$(APP_AUTHOR)" $(APP_ICON) $@
|
||||||
|
|
||||||
$(TARGET).3dsx: $(TARGET).elf
|
$(TARGET).3dsx: $(TARGET).elf
|
||||||
ifeq ($(APP_BIG_TEXT_SECTION), 1)
|
ifeq ($(APP_BIG_TEXT_SECTION), 1)
|
||||||
|
@ -189,7 +201,7 @@ ifeq ($(APP_BIG_TEXT_SECTION), 1)
|
||||||
else
|
else
|
||||||
rm -f $(TARGET).xml
|
rm -f $(TARGET).xml
|
||||||
endif
|
endif
|
||||||
$(DEVKITARM)/bin/3dsxtool $< $@ $(_3DSXFLAGS)
|
$(DEVKITTOOLS)/bin/3dsxtool $< $@ $(_3DSXFLAGS)
|
||||||
|
|
||||||
$(TARGET).elf: ctr/3dsx_custom_crt0.o
|
$(TARGET).elf: ctr/3dsx_custom_crt0.o
|
||||||
$(LD) $(LDFLAGS) $(OBJ) $(LIBDIRS) $(LIBS) -o $@
|
$(LD) $(LDFLAGS) $(OBJ) $(LIBDIRS) $(LIBS) -o $@
|
||||||
|
|
|
@ -108,6 +108,15 @@ static ssize_t ctr_dsp_audio_write(void *data, const void *buf, size_t size)
|
||||||
{
|
{
|
||||||
do{
|
do{
|
||||||
svcSleepThread(100000);
|
svcSleepThread(100000);
|
||||||
|
|
||||||
|
/* Run aptMainLoop to update APT state if DSP state
|
||||||
|
* changed, this prevents a hang on sleep. */
|
||||||
|
if(!aptMainLoop())
|
||||||
|
{
|
||||||
|
command_event(CMD_EVENT_QUIT, NULL);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
sample_pos = ndspChnGetSamplePos(ctr->channel);
|
sample_pos = ndspChnGetSamplePos(ctr->channel);
|
||||||
}while (((sample_pos - (ctr->pos + (size >>2))) & CTR_DSP_AUDIO_COUNT_MASK) > (CTR_DSP_AUDIO_COUNT >> 1)
|
}while (((sample_pos - (ctr->pos + (size >>2))) & CTR_DSP_AUDIO_COUNT_MASK) > (CTR_DSP_AUDIO_COUNT >> 1)
|
||||||
|| (((ctr->pos - (CTR_DSP_AUDIO_COUNT >> 4) - sample_pos) & CTR_DSP_AUDIO_COUNT_MASK) > (CTR_DSP_AUDIO_COUNT >> 1)));
|
|| (((ctr->pos - (CTR_DSP_AUDIO_COUNT >> 4) - sample_pos) & CTR_DSP_AUDIO_COUNT_MASK) > (CTR_DSP_AUDIO_COUNT >> 1)));
|
||||||
|
|
|
@ -201,8 +201,7 @@ void* linearMemAlign(size_t size, size_t alignment)
|
||||||
void* linearAlloc(size_t size)
|
void* linearAlloc(size_t size)
|
||||||
{
|
{
|
||||||
#if 0
|
#if 0
|
||||||
extern PrintConsole* currentConsole;
|
if(ctrConsole && ctrConsole->consoleInitialised)
|
||||||
if(currentConsole->consoleInitialised)
|
|
||||||
{
|
{
|
||||||
printf("linearAlloc : 0x%08X\n", size);
|
printf("linearAlloc : 0x%08X\n", size);
|
||||||
DEBUG_HOLD();
|
DEBUG_HOLD();
|
||||||
|
|
|
@ -44,7 +44,9 @@ typedef struct
|
||||||
bool isNew3DS;
|
bool isNew3DS;
|
||||||
u32 kernel_fcram_mapping_offset;
|
u32 kernel_fcram_mapping_offset;
|
||||||
|
|
||||||
|
#ifndef USE_CTRULIB_2
|
||||||
Handle arbiter;
|
Handle arbiter;
|
||||||
|
#endif
|
||||||
volatile u32 alloc_address;
|
volatile u32 alloc_address;
|
||||||
volatile u32 alloc_size;
|
volatile u32 alloc_size;
|
||||||
u8* flush_buffer;
|
u8* flush_buffer;
|
||||||
|
@ -263,7 +265,9 @@ static void do_memchunkhax2(void)
|
||||||
|
|
||||||
svcCloseHandle(mch2.dummy_threads_lock);
|
svcCloseHandle(mch2.dummy_threads_lock);
|
||||||
|
|
||||||
|
#ifndef USE_CTRULIB_2
|
||||||
mch2.arbiter = __sync_get_arbiter();
|
mch2.arbiter = __sync_get_arbiter();
|
||||||
|
#endif
|
||||||
|
|
||||||
svcControlMemory(&linear_buffer, 0, 0, 0x1000,
|
svcControlMemory(&linear_buffer, 0, 0, 0x1000,
|
||||||
MEMOP_ALLOC_LINEAR, MEMPERM_READ | MEMPERM_WRITE);
|
MEMOP_ALLOC_LINEAR, MEMPERM_READ | MEMPERM_WRITE);
|
||||||
|
@ -327,9 +331,14 @@ static void do_memchunkhax2(void)
|
||||||
(ThreadFunc)alloc_thread_entry, (u32)&mch2,
|
(ThreadFunc)alloc_thread_entry, (u32)&mch2,
|
||||||
mch2.threads[MCH2_THREAD_COUNT_MAX - 1].stack_top, 0x3F, 1);
|
mch2.threads[MCH2_THREAD_COUNT_MAX - 1].stack_top, 0x3F, 1);
|
||||||
|
|
||||||
|
#ifdef USE_CTRULIB_2
|
||||||
|
while ((u32) syncArbitrateAddress((s32 *)mch2.alloc_address,
|
||||||
|
ARBITRATION_WAIT_IF_LESS_THAN_TIMEOUT, 0) == 0xD9001814);
|
||||||
|
#else
|
||||||
while ((u32) svcArbitrateAddress(mch2.arbiter, mch2.alloc_address,
|
while ((u32) svcArbitrateAddress(mch2.arbiter, mch2.alloc_address,
|
||||||
ARBITRATION_WAIT_IF_LESS_THAN_TIMEOUT, 0,
|
ARBITRATION_WAIT_IF_LESS_THAN_TIMEOUT, 0,
|
||||||
0) == 0xD9001814);
|
0) == 0xD9001814);
|
||||||
|
#endif
|
||||||
|
|
||||||
GX_TextureCopy((void*)linear_buffer, 0, (void*)dst_memchunk, 0, 16, 8);
|
GX_TextureCopy((void*)linear_buffer, 0, (void*)dst_memchunk, 0, 16, 8);
|
||||||
memcpy(flush_buffer, flush_buffer + 0x4000, 0x4000);
|
memcpy(flush_buffer, flush_buffer + 0x4000, 0x4000);
|
||||||
|
|
|
@ -21,6 +21,8 @@ u32 __heapBase;
|
||||||
u32 __stack_bottom;
|
u32 __stack_bottom;
|
||||||
u32 __stack_size_extra;
|
u32 __stack_size_extra;
|
||||||
|
|
||||||
|
u32 __saved_stack;
|
||||||
|
|
||||||
extern u32 __linear_heap_size_hbl;
|
extern u32 __linear_heap_size_hbl;
|
||||||
extern u32 __heap_size_hbl;
|
extern u32 __heap_size_hbl;
|
||||||
extern void* __service_ptr;
|
extern void* __service_ptr;
|
||||||
|
@ -74,6 +76,11 @@ void __system_allocateHeaps(void)
|
||||||
/* Allocate the linear heap */
|
/* Allocate the linear heap */
|
||||||
svcControlMemory(&__linear_heap, 0x0, 0x0, __linear_heap_size, MEMOP_ALLOC_LINEAR, MEMPERM_READ | MEMPERM_WRITE);
|
svcControlMemory(&__linear_heap, 0x0, 0x0, __linear_heap_size, MEMOP_ALLOC_LINEAR, MEMPERM_READ | MEMPERM_WRITE);
|
||||||
|
|
||||||
|
#ifdef USE_CTRULIB_2
|
||||||
|
/* Mappable allocator init */
|
||||||
|
mappableInit(OS_MAP_AREA_BEGIN, OS_MAP_AREA_END);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Set up newlib heap */
|
/* Set up newlib heap */
|
||||||
fake_heap_end = (char*)0x13F00000;
|
fake_heap_end = (char*)0x13F00000;
|
||||||
}
|
}
|
||||||
|
@ -240,6 +247,9 @@ void __system_initArgv(void)
|
||||||
|
|
||||||
void initSystem(void (*retAddr)(void))
|
void initSystem(void (*retAddr)(void))
|
||||||
{
|
{
|
||||||
|
register u32 sp_val __asm__("sp");
|
||||||
|
__saved_stack = sp_val;
|
||||||
|
|
||||||
__libctru_init(retAddr);
|
__libctru_init(retAddr);
|
||||||
__appInit();
|
__appInit();
|
||||||
__system_initArgv();
|
__system_initArgv();
|
||||||
|
@ -250,6 +260,7 @@ void __attribute__((noreturn)) __ctru_exit(int rc)
|
||||||
{
|
{
|
||||||
__libc_fini_array();
|
__libc_fini_array();
|
||||||
__appExit();
|
__appExit();
|
||||||
|
asm ("mov sp, %[saved_stack] \n\t" : : [saved_stack] "r" (__saved_stack) : "sp");
|
||||||
__libctru_exit(rc);
|
__libctru_exit(rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
|
|
||||||
#include "mini-hb-menu/common.h"
|
#include "mini-hb-menu/common.h"
|
||||||
|
|
||||||
extern const loaderFuncs_s loader_Ninjhax1;
|
|
||||||
extern const loaderFuncs_s loader_Ninjhax2;
|
extern const loaderFuncs_s loader_Ninjhax2;
|
||||||
extern const loaderFuncs_s loader_Rosalina;
|
extern const loaderFuncs_s loader_Rosalina;
|
||||||
|
|
||||||
|
@ -69,12 +68,6 @@ static int exec_3dsx_actual(const char* path,
|
||||||
launch_3dsx = loader_Ninjhax2.launchFile;
|
launch_3dsx = loader_Ninjhax2.launchFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!inited)
|
|
||||||
{
|
|
||||||
inited = loader_Ninjhax1.init();
|
|
||||||
launch_3dsx = loader_Ninjhax1.launchFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inited)
|
if (inited)
|
||||||
{
|
{
|
||||||
osSetSpeedupEnable(false);
|
osSetSpeedupEnable(false);
|
||||||
|
|
|
@ -1,43 +0,0 @@
|
||||||
#include "../common.h"
|
|
||||||
|
|
||||||
static void (*callBootloader_1x)(Handle hb, Handle file);
|
|
||||||
static void (*setArgs_1x)(u32* src, u32 length);
|
|
||||||
static Handle fileHandle;
|
|
||||||
|
|
||||||
static bool init(void)
|
|
||||||
{
|
|
||||||
Result res = hbInit();
|
|
||||||
if (R_FAILED(res))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
HB_GetBootloaderAddresses((void**)&callBootloader_1x, (void**)&setArgs_1x);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void deinit(void)
|
|
||||||
{
|
|
||||||
hbExit();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void bootloaderJump(void)
|
|
||||||
{
|
|
||||||
callBootloader_1x(0x00000000, fileHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void launchFile(const char* path, argData_s* args, executableMetadata_s* em)
|
|
||||||
{
|
|
||||||
fileHandle = launchOpenFile(path);
|
|
||||||
if (fileHandle==0)
|
|
||||||
return;
|
|
||||||
setArgs_1x(args->buf, sizeof(args->buf));
|
|
||||||
__system_retAddr = bootloaderJump;
|
|
||||||
}
|
|
||||||
|
|
||||||
const loaderFuncs_s loader_Ninjhax1 =
|
|
||||||
{
|
|
||||||
.name = "ninjhax 1.x",
|
|
||||||
.flags = LOADER_SHOW_REBOOT,
|
|
||||||
.init = init,
|
|
||||||
.deinit = deinit,
|
|
||||||
.launchFile = launchFile,
|
|
||||||
};
|
|
|
@ -60,6 +60,8 @@
|
||||||
static enum frontend_fork ctr_fork_mode = FRONTEND_FORK_NONE;
|
static enum frontend_fork ctr_fork_mode = FRONTEND_FORK_NONE;
|
||||||
static const char* elf_path_cst = "sdmc:/retroarch/retroarch.3dsx";
|
static const char* elf_path_cst = "sdmc:/retroarch/retroarch.3dsx";
|
||||||
|
|
||||||
|
extern bool ctr_bottom_screen_enabled;
|
||||||
|
|
||||||
#ifdef IS_SALAMANDER
|
#ifdef IS_SALAMANDER
|
||||||
static void get_first_valid_core(char* path_return, size_t len)
|
static void get_first_valid_core(char* path_return, size_t len)
|
||||||
{
|
{
|
||||||
|
@ -135,8 +137,6 @@ static void frontend_ctr_deinit(void* data)
|
||||||
u8 not_2DS;
|
u8 not_2DS;
|
||||||
u8 device_model = 0xFF;
|
u8 device_model = 0xFF;
|
||||||
|
|
||||||
extern PrintConsole* currentConsole;
|
|
||||||
|
|
||||||
(void)data;
|
(void)data;
|
||||||
|
|
||||||
#ifndef IS_SALAMANDER
|
#ifndef IS_SALAMANDER
|
||||||
|
@ -153,8 +153,7 @@ static void frontend_ctr_deinit(void* data)
|
||||||
verbosity_enable();
|
verbosity_enable();
|
||||||
retro_main_log_file_init(NULL, false);
|
retro_main_log_file_init(NULL, false);
|
||||||
|
|
||||||
if ((gfxBottomFramebuffers[0] == (u8*)currentConsole->frameBuffer)
|
if (ctr_bottom_screen_enabled && (ctr_fork_mode == FRONTEND_FORK_NONE))
|
||||||
&& (ctr_fork_mode == FRONTEND_FORK_NONE))
|
|
||||||
wait_for_input();
|
wait_for_input();
|
||||||
|
|
||||||
CFGU_GetModelNintendo2DS(¬_2DS);
|
CFGU_GetModelNintendo2DS(¬_2DS);
|
||||||
|
@ -394,6 +393,36 @@ __attribute__((weak)) u32 __ctr_patch_services;
|
||||||
|
|
||||||
void gfxSetFramebufferInfo(gfxScreen_t screen, u8 id);
|
void gfxSetFramebufferInfo(gfxScreen_t screen, u8 id);
|
||||||
|
|
||||||
|
#ifdef USE_CTRULIB_2
|
||||||
|
u8* gfxTopLeftFramebuffers[2];
|
||||||
|
u8* gfxTopRightFramebuffers[2];
|
||||||
|
u8* gfxBottomFramebuffers[2];
|
||||||
|
|
||||||
|
void gfxSetFramebufferInfo(gfxScreen_t screen, u8 id)
|
||||||
|
{
|
||||||
|
if(screen==GFX_TOP)
|
||||||
|
{
|
||||||
|
u8 enable3d = 0;
|
||||||
|
u8 bit5=(enable3d != 0);
|
||||||
|
gspPresentBuffer(GFX_TOP,
|
||||||
|
id,
|
||||||
|
(u32*)gfxTopLeftFramebuffers[id],
|
||||||
|
enable3d ? (u32*)gfxTopRightFramebuffers[id] : (u32*)gfxTopLeftFramebuffers[id],
|
||||||
|
240 * 3,
|
||||||
|
((1)<<8)|((1^bit5)<<6)|((bit5)<<5)|GSP_BGR8_OES);
|
||||||
|
} else {
|
||||||
|
gspPresentBuffer(GFX_BOTTOM,
|
||||||
|
id,
|
||||||
|
(u32*)gfxBottomFramebuffers[id],
|
||||||
|
(u32*)gfxBottomFramebuffers[id],
|
||||||
|
240 * 2,
|
||||||
|
GSP_RGB565_OES);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
PrintConsole* ctrConsole;
|
||||||
|
|
||||||
static void frontend_ctr_init(void* data)
|
static void frontend_ctr_init(void* data)
|
||||||
{
|
{
|
||||||
#ifndef IS_SALAMANDER
|
#ifndef IS_SALAMANDER
|
||||||
|
@ -407,12 +436,25 @@ static void frontend_ctr_init(void* data)
|
||||||
|
|
||||||
u32 topSize = 400 * 240 * 3;
|
u32 topSize = 400 * 240 * 3;
|
||||||
u32 bottomSize = 320 * 240 * 2;
|
u32 bottomSize = 320 * 240 * 2;
|
||||||
|
|
||||||
|
#ifdef USE_CTRULIB_2
|
||||||
|
linearFree(gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL));
|
||||||
|
linearFree(gfxGetFramebuffer(GFX_TOP, GFX_RIGHT, NULL, NULL));
|
||||||
|
linearFree(gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL));
|
||||||
|
gfxSwapBuffers();
|
||||||
|
|
||||||
|
linearFree(gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL));
|
||||||
|
linearFree(gfxGetFramebuffer(GFX_TOP, GFX_RIGHT, NULL, NULL));
|
||||||
|
linearFree(gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL));
|
||||||
|
gfxSwapBuffers();
|
||||||
|
#else
|
||||||
linearFree(gfxTopLeftFramebuffers [0]);
|
linearFree(gfxTopLeftFramebuffers [0]);
|
||||||
linearFree(gfxTopLeftFramebuffers [1]);
|
linearFree(gfxTopLeftFramebuffers [1]);
|
||||||
linearFree(gfxBottomFramebuffers [0]);
|
linearFree(gfxBottomFramebuffers [0]);
|
||||||
linearFree(gfxBottomFramebuffers [1]);
|
linearFree(gfxBottomFramebuffers [1]);
|
||||||
linearFree(gfxTopRightFramebuffers[0]);
|
linearFree(gfxTopRightFramebuffers[0]);
|
||||||
linearFree(gfxTopRightFramebuffers[1]);
|
linearFree(gfxTopRightFramebuffers[1]);
|
||||||
|
#endif
|
||||||
|
|
||||||
gfxTopLeftFramebuffers [0] = linearAlloc(topSize * 2);
|
gfxTopLeftFramebuffers [0] = linearAlloc(topSize * 2);
|
||||||
gfxTopRightFramebuffers[0] = gfxTopLeftFramebuffers[0] + topSize;
|
gfxTopRightFramebuffers[0] = gfxTopLeftFramebuffers[0] + topSize;
|
||||||
|
@ -427,7 +469,7 @@ static void frontend_ctr_init(void* data)
|
||||||
gfxSetFramebufferInfo(GFX_BOTTOM, 0);
|
gfxSetFramebufferInfo(GFX_BOTTOM, 0);
|
||||||
|
|
||||||
gfxSet3D(true);
|
gfxSet3D(true);
|
||||||
consoleInit(GFX_BOTTOM, NULL);
|
ctrConsole = consoleInit(GFX_BOTTOM, NULL);
|
||||||
|
|
||||||
/* enable access to all service calls when possible. */
|
/* enable access to all service calls when possible. */
|
||||||
if (svchax_init)
|
if (svchax_init)
|
||||||
|
@ -518,7 +560,11 @@ static enum frontend_powerstate frontend_ctr_get_powerstate(
|
||||||
u8 battery_percent = 0;
|
u8 battery_percent = 0;
|
||||||
u8 charging = 0;
|
u8 charging = 0;
|
||||||
|
|
||||||
|
#ifdef USE_CTRULIB_2
|
||||||
|
MCUHWC_GetBatteryLevel(&battery_percent);
|
||||||
|
#else
|
||||||
mcuHwcGetBatteryLevel(&battery_percent);
|
mcuHwcGetBatteryLevel(&battery_percent);
|
||||||
|
#endif
|
||||||
|
|
||||||
*percent = battery_percent;
|
*percent = battery_percent;
|
||||||
/* 3DS does not support seconds of charge remaining */
|
/* 3DS does not support seconds of charge remaining */
|
||||||
|
|
|
@ -24,6 +24,14 @@
|
||||||
#define CTR_TOP_FRAMEBUFFER_WIDTH 400
|
#define CTR_TOP_FRAMEBUFFER_WIDTH 400
|
||||||
#define CTR_TOP_FRAMEBUFFER_HEIGHT 240
|
#define CTR_TOP_FRAMEBUFFER_HEIGHT 240
|
||||||
|
|
||||||
|
#ifdef USE_CTRULIB_2
|
||||||
|
extern u8* gfxTopLeftFramebuffers[2];
|
||||||
|
extern u8* gfxTopRightFramebuffers[2];
|
||||||
|
extern u8* gfxBottomFramebuffers[2];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern PrintConsole* ctrConsole;
|
||||||
|
|
||||||
extern const u8 ctr_sprite_shbin[];
|
extern const u8 ctr_sprite_shbin[];
|
||||||
extern const u32 ctr_sprite_shbin_size;
|
extern const u32 ctr_sprite_shbin_size;
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@
|
||||||
* Have to keep track of bottom screen enable state
|
* Have to keep track of bottom screen enable state
|
||||||
* externally, otherwise cannot detect current state
|
* externally, otherwise cannot detect current state
|
||||||
* when reinitialising... */
|
* when reinitialising... */
|
||||||
static bool ctr_bottom_screen_enabled = true;
|
bool ctr_bottom_screen_enabled = true;
|
||||||
|
|
||||||
static INLINE void ctr_check_3D_slider(ctr_video_t* ctr, ctr_video_mode_enum video_mode)
|
static INLINE void ctr_check_3D_slider(ctr_video_t* ctr, ctr_video_mode_enum video_mode)
|
||||||
{
|
{
|
||||||
|
@ -325,13 +325,12 @@ static void ctr_set_bottom_screen_enable(void* data, bool enabled)
|
||||||
{
|
{
|
||||||
Handle lcd_handle;
|
Handle lcd_handle;
|
||||||
u8 not_2DS;
|
u8 not_2DS;
|
||||||
extern PrintConsole* currentConsole;
|
|
||||||
ctr_video_t *ctr = (ctr_video_t*)data;
|
ctr_video_t *ctr = (ctr_video_t*)data;
|
||||||
|
|
||||||
if (!ctr)
|
if (!ctr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
gfxBottomFramebuffers[0] = enabled ? (u8*)currentConsole->frameBuffer:
|
gfxBottomFramebuffers[0] = enabled ? (u8*)ctrConsole->frameBuffer:
|
||||||
(u8*)ctr->empty_framebuffer;
|
(u8*)ctr->empty_framebuffer;
|
||||||
|
|
||||||
CFGU_GetModelNintendo2DS(¬_2DS);
|
CFGU_GetModelNintendo2DS(¬_2DS);
|
||||||
|
@ -916,6 +915,32 @@ static bool ctr_frame(void* data, const void* frame,
|
||||||
|
|
||||||
/* Swap buffers : */
|
/* Swap buffers : */
|
||||||
|
|
||||||
|
#ifdef USE_CTRULIB_2
|
||||||
|
u32 *buf0, *buf1;
|
||||||
|
u32 stride;
|
||||||
|
|
||||||
|
buf0 = (u32*)gfxTopLeftFramebuffers[ctr->current_buffer_top];
|
||||||
|
|
||||||
|
if(ctr->video_mode == CTR_VIDEO_MODE_2D_800X240)
|
||||||
|
{
|
||||||
|
buf1 = (u32*)(gfxTopLeftFramebuffers[ctr->current_buffer_top] + 240 * 3);
|
||||||
|
stride = 240 * 3 * 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (ctr->enable_3d)
|
||||||
|
buf1 = (u32*)gfxTopRightFramebuffers[ctr->current_buffer_top];
|
||||||
|
else
|
||||||
|
buf1 = buf0;
|
||||||
|
|
||||||
|
stride = 240 * 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
u8 bit5 = (ctr->enable_3d != 0);
|
||||||
|
|
||||||
|
gspPresentBuffer(GFX_TOP, ctr->current_buffer_top, buf0, buf1,
|
||||||
|
stride, (1<<8)|((1^bit5)<<6)|((bit5)<<5)|GSP_BGR8_OES);
|
||||||
|
#else
|
||||||
topFramebufferInfo.
|
topFramebufferInfo.
|
||||||
active_framebuf = ctr->current_buffer_top;
|
active_framebuf = ctr->current_buffer_top;
|
||||||
topFramebufferInfo.
|
topFramebufferInfo.
|
||||||
|
@ -953,6 +978,7 @@ static bool ctr_frame(void* data, const void* frame,
|
||||||
framebufferInfoHeader[0x0] ^= 1;
|
framebufferInfoHeader[0x0] ^= 1;
|
||||||
framebufferInfo[framebufferInfoHeader[0x0]] = topFramebufferInfo;
|
framebufferInfo[framebufferInfoHeader[0x0]] = topFramebufferInfo;
|
||||||
framebufferInfoHeader[0x1] = 1;
|
framebufferInfoHeader[0x1] = 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
ctr->current_buffer_top ^= 1;
|
ctr->current_buffer_top ^= 1;
|
||||||
ctr->p3d_event_pending = true;
|
ctr->p3d_event_pending = true;
|
||||||
|
|
|
@ -58,6 +58,20 @@ extern u32 gpuCmdBufOffset;
|
||||||
extern u32 __linear_heap_size;
|
extern u32 __linear_heap_size;
|
||||||
extern u32 __linear_heap;
|
extern u32 __linear_heap;
|
||||||
|
|
||||||
|
#ifdef USE_CTRULIB_2
|
||||||
|
__attribute__((always_inline))
|
||||||
|
static INLINE Result ctrGspSubmitGxCommand(u32 gxCommand[0x8])
|
||||||
|
{
|
||||||
|
return gspSubmitGxCommand(gxCommand);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
__attribute__((always_inline))
|
||||||
|
static INLINE Result ctrGspSubmitGxCommand(u32 gxCommand[0x8])
|
||||||
|
{
|
||||||
|
return gspSubmitGxCommand(gxCmdBuf, gxCommand);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
__attribute__((always_inline))
|
__attribute__((always_inline))
|
||||||
static INLINE Result ctr_set_parallax_layer(bool state)
|
static INLINE Result ctr_set_parallax_layer(bool state)
|
||||||
{
|
{
|
||||||
|
@ -107,7 +121,7 @@ static INLINE Result ctrGuSetCommandList_First(bool queued, u32* buf0a, u32 buf0
|
||||||
gxCommand[6]=(u32)buf2s; //buf2 size
|
gxCommand[6]=(u32)buf2s; //buf2 size
|
||||||
gxCommand[7]=0x0;
|
gxCommand[7]=0x0;
|
||||||
|
|
||||||
return gspSubmitGxCommand(gxCmdBuf, gxCommand);
|
return ctrGspSubmitGxCommand(gxCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((always_inline))
|
__attribute__((always_inline))
|
||||||
|
@ -121,7 +135,7 @@ static INLINE Result ctrGuSetCommandList_Last(bool queued, u32* buf0a, u32 buf0s
|
||||||
gxCommand[4]=gxCommand[5]=gxCommand[6]=0x0;
|
gxCommand[4]=gxCommand[5]=gxCommand[6]=0x0;
|
||||||
gxCommand[7]=(flags>>1)&1; //when non-zero, call svcFlushProcessDataCache() with the specified buffer
|
gxCommand[7]=(flags>>1)&1; //when non-zero, call svcFlushProcessDataCache() with the specified buffer
|
||||||
|
|
||||||
return gspSubmitGxCommand(gxCmdBuf, gxCommand);
|
return ctrGspSubmitGxCommand(gxCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((always_inline))
|
__attribute__((always_inline))
|
||||||
|
@ -145,7 +159,7 @@ static INLINE Result ctrGuSetMemoryFill(bool queued, u32* buf0a, u32 buf0v, u32*
|
||||||
gxCommand[6]=(u32)buf1e; //buf1 end addr
|
gxCommand[6]=(u32)buf1e; //buf1 end addr
|
||||||
gxCommand[7]=(width0)|(width1<<16);
|
gxCommand[7]=(width0)|(width1<<16);
|
||||||
|
|
||||||
return gspSubmitGxCommand(gxCmdBuf, gxCommand);
|
return ctrGspSubmitGxCommand(gxCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((always_inline))
|
__attribute__((always_inline))
|
||||||
|
@ -167,7 +181,7 @@ static INLINE Result ctrGuCopyImage
|
||||||
| ((dst_w > src_w) ? CTRGU_DMA_TRUNCATE : 0);
|
| ((dst_w > src_w) ? CTRGU_DMA_TRUNCATE : 0);
|
||||||
gxCommand[6]=gxCommand[7]=0x0;
|
gxCommand[6]=gxCommand[7]=0x0;
|
||||||
|
|
||||||
return gspSubmitGxCommand(gxCmdBuf, gxCommand);
|
return ctrGspSubmitGxCommand(gxCommand);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,7 +200,7 @@ static INLINE Result ctrGuDisplayTransfer
|
||||||
gxCommand[5]=(src_fmt << 8) | (dst_fmt << 12) | multisample_lvl;
|
gxCommand[5]=(src_fmt << 8) | (dst_fmt << 12) | multisample_lvl;
|
||||||
gxCommand[6]=gxCommand[7]=0x0;
|
gxCommand[6]=gxCommand[7]=0x0;
|
||||||
|
|
||||||
return gspSubmitGxCommand(gxCmdBuf, gxCommand);
|
return ctrGspSubmitGxCommand(gxCommand);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -234,6 +234,8 @@ retro_time_t cpu_features_get_time_usec(void)
|
||||||
return ticks_to_us(OSGetSystemTime());
|
return ticks_to_us(OSGetSystemTime());
|
||||||
#elif defined(SWITCH) || defined(HAVE_LIBNX)
|
#elif defined(SWITCH) || defined(HAVE_LIBNX)
|
||||||
return (svcGetSystemTick() * 10) / 192;
|
return (svcGetSystemTick() * 10) / 192;
|
||||||
|
#elif defined(_3DS)
|
||||||
|
return osGetTime() * 1000;
|
||||||
#elif defined(_POSIX_MONOTONIC_CLOCK) || defined(__QNX__) || defined(ANDROID) || defined(__MACH__) || defined(DJGPP)
|
#elif defined(_POSIX_MONOTONIC_CLOCK) || defined(__QNX__) || defined(ANDROID) || defined(__MACH__) || defined(DJGPP)
|
||||||
struct timespec tv = {0};
|
struct timespec tv = {0};
|
||||||
if (ra_clock_gettime(CLOCK_MONOTONIC, &tv) < 0)
|
if (ra_clock_gettime(CLOCK_MONOTONIC, &tv) < 0)
|
||||||
|
@ -245,8 +247,6 @@ retro_time_t cpu_features_get_time_usec(void)
|
||||||
return ps2_clock() / PS2_CLOCKS_PER_MSEC * 1000;
|
return ps2_clock() / PS2_CLOCKS_PER_MSEC * 1000;
|
||||||
#elif defined(VITA) || defined(PSP)
|
#elif defined(VITA) || defined(PSP)
|
||||||
return sceKernelGetSystemTimeWide();
|
return sceKernelGetSystemTimeWide();
|
||||||
#elif defined(_3DS)
|
|
||||||
return osGetTime() * 1000;
|
|
||||||
#else
|
#else
|
||||||
#error "Your platform does not have a timer function implemented in cpu_features_get_time_usec(). Cannot continue."
|
#error "Your platform does not have a timer function implemented in cpu_features_get_time_usec(). Cannot continue."
|
||||||
#endif
|
#endif
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue