Merge pull request #11248 from justinweiss/update-libctru

[3DS] Update to libctru 2.0
This commit is contained in:
Autechre 2020-09-10 06:49:54 +02:00 committed by GitHub
commit 2d3c63f545
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 198 additions and 98 deletions

View File

@ -8,6 +8,7 @@ BUILD_3DSX = 1
BUILD_3DS = 0
BUILD_CIA = 1
LIBCTRU_NO_DEPRECATION = 1
USE_CTRULIB_2 = 0
APP_TITLE = 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/mini-hb-menu/launch.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/ninjhax1.o
ctr/exec-3dsx/mini-hb-menu/loaders/hax2.o
ifeq ($(APP_BIG_TEXT_SECTION), 1)
APP_USE_SVCHAX = 1
@ -104,6 +104,18 @@ ifeq ($(strip $(CTRULIB)),)
CTRULIB = $(DEVKITPRO)/libctru
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_DESCRIPTION := $(shell echo "$(APP_DESCRIPTION)" | cut -c1-256)
APP_AUTHOR := $(shell echo "$(APP_AUTHOR)" | cut -c1-128)
@ -225,13 +237,13 @@ else
endif
%.o: %.vsh %.gsh
$(DEVKITARM)/bin/picasso $^ -o $*.shbin
$(DEVKITARM)/bin/bin2s $*.shbin | $(PREFIX)as -o $@
$(DEVKITTOOLS)/bin/picasso $^ -o $*.shbin
$(DEVKITTOOLS)/bin/bin2s $*.shbin | $(PREFIX)as -o $@
rm $*.shbin
%.o: %.vsh
$(DEVKITARM)/bin/picasso $^ -o $*.shbin
$(DEVKITARM)/bin/bin2s $*.shbin | $(PREFIX)as -o $@
$(DEVKITTOOLS)/bin/picasso $^ -o $*.shbin
$(DEVKITTOOLS)/bin/bin2s $*.shbin | $(PREFIX)as -o $@
rm $*.shbin
%.o: %.cpp
@ -252,7 +264,7 @@ endif
%.vsh:
$(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
ifeq ($(APP_BIG_TEXT_SECTION), 1)
@ -260,7 +272,7 @@ ifeq ($(APP_BIG_TEXT_SECTION), 1)
else
rm -f $(TARGET).xml
endif
$(DEVKITARM)/bin/3dsxtool $< $@ $(_3DSXFLAGS)
$(DEVKITTOOLS)/bin/3dsxtool $< $@ $(_3DSXFLAGS)
$(TARGET).elf: ctr/3dsx_custom_crt0.o
$(LD) $(LDFLAGS) $(OBJ) $(LIBDIRS) $(LIBS) -o $@

View File

@ -5,6 +5,7 @@ DEBUG = 0
BUILD_3DSX = 1
BUILD_3DS = 0
BUILD_CIA = 1
USE_CTRULIB_2 = 0
APP_TITLE = RetroArch 3DS
APP_DESCRIPTION = RetroArch 3DS
@ -45,13 +46,24 @@ OBJ += ctr/exec-3dsx/exec_cia.o \
ctr/exec-3dsx/exec_3dsx.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/hax2.o \
ctr/exec-3dsx/mini-hb-menu/loaders/ninjhax1.o
ctr/exec-3dsx/mini-hb-menu/loaders/hax2.o
ifeq ($(strip $(DEVKITPRO)),)
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>devkitpro")
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)),)
CTRULIB = $(DEVKITPRO)/libctru
endif
@ -153,13 +165,13 @@ else
endif
%.o: %.vsh %.gsh
$(DEVKITARM)/bin/picasso $^ -o $*.shbin
$(DEVKITARM)/bin/bin2s $*.shbin | $(PREFIX)as -o $@
$(DEVKITTOOLS)/bin/picasso $^ -o $*.shbin
$(DEVKITTOOLS)/bin/bin2s $*.shbin | $(PREFIX)as -o $@
rm $*.shbin
%.o: %.vsh
$(DEVKITARM)/bin/picasso $^ -o $*.shbin
$(DEVKITARM)/bin/bin2s $*.shbin | $(PREFIX)as -o $@
$(DEVKITTOOLS)/bin/picasso $^ -o $*.shbin
$(DEVKITTOOLS)/bin/bin2s $*.shbin | $(PREFIX)as -o $@
rm $*.shbin
%.o: %.cpp
@ -180,7 +192,7 @@ endif
%.vsh:
$(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
ifeq ($(APP_BIG_TEXT_SECTION), 1)
@ -188,7 +200,7 @@ ifeq ($(APP_BIG_TEXT_SECTION), 1)
else
rm -f $(TARGET).xml
endif
$(DEVKITARM)/bin/3dsxtool $< $@ $(_3DSXFLAGS)
$(DEVKITTOOLS)/bin/3dsxtool $< $@ $(_3DSXFLAGS)
$(TARGET).elf: ctr/3dsx_custom_crt0.o
$(LD) $(LDFLAGS) $(OBJ) $(LIBDIRS) $(LIBS) -o $@

View File

@ -107,6 +107,15 @@ static ssize_t ctr_dsp_audio_write(void *data, const void *buf, size_t size)
{
do{
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);
}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)));

View File

@ -201,8 +201,7 @@ void* linearMemAlign(size_t size, size_t alignment)
void* linearAlloc(size_t size)
{
#if 0
extern PrintConsole* currentConsole;
if(currentConsole->consoleInitialised)
if(ctrConsole && ctrConsole->consoleInitialised)
{
printf("linearAlloc : 0x%08X\n", size);
DEBUG_HOLD();

View File

@ -44,7 +44,9 @@ typedef struct
bool isNew3DS;
u32 kernel_fcram_mapping_offset;
#ifndef USE_CTRULIB_2
Handle arbiter;
#endif
volatile u32 alloc_address;
volatile u32 alloc_size;
u8* flush_buffer;
@ -263,7 +265,9 @@ static void do_memchunkhax2(void)
svcCloseHandle(mch2.dummy_threads_lock);
#ifndef USE_CTRULIB_2
mch2.arbiter = __sync_get_arbiter();
#endif
svcControlMemory(&linear_buffer, 0, 0, 0x1000,
MEMOP_ALLOC_LINEAR, MEMPERM_READ | MEMPERM_WRITE);
@ -327,9 +331,14 @@ static void do_memchunkhax2(void)
(ThreadFunc)alloc_thread_entry, (u32)&mch2,
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,
ARBITRATION_WAIT_IF_LESS_THAN_TIMEOUT, 0,
0) == 0xD9001814);
#endif
GX_TextureCopy((void*)linear_buffer, 0, (void*)dst_memchunk, 0, 16, 8);
memcpy(flush_buffer, flush_buffer + 0x4000, 0x4000);

View File

@ -21,6 +21,8 @@ u32 __heapBase;
u32 __stack_bottom;
u32 __stack_size_extra;
u32 __saved_stack;
extern u32 __linear_heap_size_hbl;
extern u32 __heap_size_hbl;
extern void* __service_ptr;
@ -74,6 +76,11 @@ void __system_allocateHeaps(void)
/* Allocate the linear heap */
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 */
fake_heap_end = (char*)0x13F00000;
}
@ -240,6 +247,9 @@ void __system_initArgv(void)
void initSystem(void (*retAddr)(void))
{
register u32 sp_val __asm__("sp");
__saved_stack = sp_val;
__libctru_init(retAddr);
__appInit();
__system_initArgv();
@ -250,6 +260,7 @@ void __attribute__((noreturn)) __ctru_exit(int rc)
{
__libc_fini_array();
__appExit();
asm ("mov sp, %[saved_stack] \n\t" : : [saved_stack] "r" (__saved_stack) : "sp");
__libctru_exit(rc);
}

View File

@ -5,7 +5,6 @@
#include "mini-hb-menu/common.h"
extern const loaderFuncs_s loader_Ninjhax1;
extern const loaderFuncs_s loader_Ninjhax2;
extern const loaderFuncs_s loader_Rosalina;
@ -69,12 +68,6 @@ static int exec_3dsx_actual(const char* path,
launch_3dsx = loader_Ninjhax2.launchFile;
}
if (!inited)
{
inited = loader_Ninjhax1.init();
launch_3dsx = loader_Ninjhax1.launchFile;
}
if (inited)
{
osSetSpeedupEnable(false);

View File

@ -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,
};

View File

@ -60,6 +60,8 @@
static enum frontend_fork ctr_fork_mode = FRONTEND_FORK_NONE;
static const char* elf_path_cst = "sdmc:/retroarch/retroarch.3dsx";
extern bool ctr_bottom_screen_enabled;
#ifdef IS_SALAMANDER
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 device_model = 0xFF;
extern PrintConsole* currentConsole;
(void)data;
#ifndef IS_SALAMANDER
@ -153,8 +153,7 @@ static void frontend_ctr_deinit(void* data)
verbosity_enable();
retro_main_log_file_init(NULL, false);
if ((gfxBottomFramebuffers[0] == (u8*)currentConsole->frameBuffer)
&& (ctr_fork_mode == FRONTEND_FORK_NONE))
if (ctr_bottom_screen_enabled && (ctr_fork_mode == FRONTEND_FORK_NONE))
wait_for_input();
CFGU_GetModelNintendo2DS(&not_2DS);
@ -394,6 +393,36 @@ __attribute__((weak)) u32 __ctr_patch_services;
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)
{
#ifndef IS_SALAMANDER
@ -407,12 +436,25 @@ static void frontend_ctr_init(void* data)
u32 topSize = 400 * 240 * 3;
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 [1]);
linearFree(gfxBottomFramebuffers [0]);
linearFree(gfxBottomFramebuffers [1]);
linearFree(gfxTopRightFramebuffers[0]);
linearFree(gfxTopRightFramebuffers[1]);
#endif
gfxTopLeftFramebuffers [0] = linearAlloc(topSize * 2);
gfxTopRightFramebuffers[0] = gfxTopLeftFramebuffers[0] + topSize;
@ -427,7 +469,7 @@ static void frontend_ctr_init(void* data)
gfxSetFramebufferInfo(GFX_BOTTOM, 0);
gfxSet3D(true);
consoleInit(GFX_BOTTOM, NULL);
ctrConsole = consoleInit(GFX_BOTTOM, NULL);
/* enable access to all service calls when possible. */
if (svchax_init)
@ -518,7 +560,11 @@ static enum frontend_powerstate frontend_ctr_get_powerstate(
u8 battery_percent = 0;
u8 charging = 0;
#ifdef USE_CTRULIB_2
MCUHWC_GetBatteryLevel(&battery_percent);
#else
mcuHwcGetBatteryLevel(&battery_percent);
#endif
*percent = battery_percent;
/* 3DS does not support seconds of charge remaining */

View File

@ -24,6 +24,14 @@
#define CTR_TOP_FRAMEBUFFER_WIDTH 400
#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 u32 ctr_sprite_shbin_size;

View File

@ -51,7 +51,7 @@
* Have to keep track of bottom screen enable state
* externally, otherwise cannot detect current state
* 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)
{
@ -325,13 +325,12 @@ static void ctr_set_bottom_screen_enable(void* data, bool enabled)
{
Handle lcd_handle;
u8 not_2DS;
extern PrintConsole* currentConsole;
ctr_video_t *ctr = (ctr_video_t*)data;
if (!ctr)
return;
if (!ctr)
return;
gfxBottomFramebuffers[0] = enabled ? (u8*)currentConsole->frameBuffer:
gfxBottomFramebuffers[0] = enabled ? (u8*)ctrConsole->frameBuffer:
(u8*)ctr->empty_framebuffer;
CFGU_GetModelNintendo2DS(&not_2DS);
@ -916,6 +915,32 @@ static bool ctr_frame(void* data, const void* frame,
/* 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.
active_framebuf = ctr->current_buffer_top;
topFramebufferInfo.
@ -953,6 +978,7 @@ static bool ctr_frame(void* data, const void* frame,
framebufferInfoHeader[0x0] ^= 1;
framebufferInfo[framebufferInfoHeader[0x0]] = topFramebufferInfo;
framebufferInfoHeader[0x1] = 1;
#endif
ctr->current_buffer_top ^= 1;
ctr->p3d_event_pending = true;

View File

@ -58,6 +58,20 @@ extern u32 gpuCmdBufOffset;
extern u32 __linear_heap_size;
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))
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[7]=0x0;
return gspSubmitGxCommand(gxCmdBuf, gxCommand);
return ctrGspSubmitGxCommand(gxCommand);
}
__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[7]=(flags>>1)&1; //when non-zero, call svcFlushProcessDataCache() with the specified buffer
return gspSubmitGxCommand(gxCmdBuf, gxCommand);
return ctrGspSubmitGxCommand(gxCommand);
}
__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[7]=(width0)|(width1<<16);
return gspSubmitGxCommand(gxCmdBuf, gxCommand);
return ctrGspSubmitGxCommand(gxCommand);
}
__attribute__((always_inline))
@ -167,7 +181,7 @@ static INLINE Result ctrGuCopyImage
| ((dst_w > src_w) ? CTRGU_DMA_TRUNCATE : 0);
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[6]=gxCommand[7]=0x0;
return gspSubmitGxCommand(gxCmdBuf, gxCommand);
return ctrGspSubmitGxCommand(gxCommand);
}

View File

@ -234,6 +234,8 @@ retro_time_t cpu_features_get_time_usec(void)
return ticks_to_us(OSGetSystemTime());
#elif defined(SWITCH) || defined(HAVE_LIBNX)
return (svcGetSystemTick() * 10) / 192;
#elif defined(_3DS)
return osGetTime() * 1000;
#elif defined(_POSIX_MONOTONIC_CLOCK) || defined(__QNX__) || defined(ANDROID) || defined(__MACH__) || defined(DJGPP)
struct timespec 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;
#elif defined(VITA) || defined(PSP)
return sceKernelGetSystemTimeWide();
#elif defined(_3DS)
return osGetTime() * 1000;
#else
#error "Your platform does not have a timer function implemented in cpu_features_get_time_usec(). Cannot continue."
#endif

View File

@ -32,12 +32,16 @@
#define STACKSIZE (4 * 1024)
#ifndef PTHREAD_SCOPE_PROCESS
/* An earlier version of devkitARM does not define the pthread types. Can remove in r54+. */
typedef Thread pthread_t;
typedef LightLock pthread_mutex_t;
typedef void* pthread_mutexattr_t;
typedef int pthread_attr_t;
typedef LightEvent pthread_cond_t;
typedef int pthread_condattr_t;
#endif
/* libctru threads return void but pthreads return void pointer */
static bool mutex_inited = false;
@ -77,19 +81,19 @@ static INLINE int pthread_create(pthread_t *thread,
return EAGAIN;
}
*thread = new_ctr_thread;
*thread = (pthread_t)new_ctr_thread;
return 0;
}
static INLINE pthread_t pthread_self(void)
{
return threadGetCurrent();
return (pthread_t)threadGetCurrent();
}
static INLINE int pthread_mutex_init(pthread_mutex_t *mutex,
const pthread_mutexattr_t *attr)
{
LightLock_Init(mutex);
LightLock_Init((LightLock *)mutex);
return 0;
}
@ -101,12 +105,12 @@ static INLINE int pthread_mutex_destroy(pthread_mutex_t *mutex)
static INLINE int pthread_mutex_lock(pthread_mutex_t *mutex)
{
return LightLock_TryLock(mutex);
return LightLock_TryLock((LightLock *)mutex);
}
static INLINE int pthread_mutex_unlock(pthread_mutex_t *mutex)
{
LightLock_Unlock(mutex);
LightLock_Unlock((LightLock *)mutex);
return 0;
}
@ -127,18 +131,18 @@ static INLINE int pthread_detach(pthread_t thread)
static INLINE int pthread_join(pthread_t thread, void **retval)
{
/*retval is ignored*/
return threadJoin(thread, U64_MAX);
return threadJoin((Thread)thread, U64_MAX);
}
static INLINE int pthread_mutex_trylock(pthread_mutex_t *mutex)
{
return LightLock_TryLock(mutex);
return LightLock_TryLock((LightLock *)mutex);
}
static INLINE int pthread_cond_wait(pthread_cond_t *cond,
pthread_mutex_t *mutex)
{
LightEvent_Wait(cond);
LightEvent_Wait((LightEvent *)cond);
return 0;
}
@ -154,7 +158,7 @@ static INLINE int pthread_cond_timedwait(pthread_cond_t *cond,
gettimeofday(&tm, NULL);
now.tv_sec = tm.tv_sec;
now.tv_nsec = tm.tv_usec * 1000;
if (LightEvent_TryWait(cond) != 0 || now.tv_sec > abstime->tv_sec || (now.tv_sec == abstime->tv_sec && now.tv_nsec > abstime->tv_nsec))
if (LightEvent_TryWait((LightEvent *)cond) != 0 || now.tv_sec > abstime->tv_sec || (now.tv_sec == abstime->tv_sec && now.tv_nsec > abstime->tv_nsec))
break;
}
@ -164,19 +168,19 @@ static INLINE int pthread_cond_timedwait(pthread_cond_t *cond,
static INLINE int pthread_cond_init(pthread_cond_t *cond,
const pthread_condattr_t *attr)
{
LightEvent_Init(cond, RESET_ONESHOT);
LightEvent_Init((LightEvent *)cond, RESET_ONESHOT);
return 0;
}
static INLINE int pthread_cond_signal(pthread_cond_t *cond)
{
LightEvent_Signal(cond);
LightEvent_Signal((LightEvent *)cond);
return 0;
}
static INLINE int pthread_cond_broadcast(pthread_cond_t *cond)
{
LightEvent_Signal(cond);
LightEvent_Signal((LightEvent *)cond);
return 0;
}
@ -188,7 +192,7 @@ static INLINE int pthread_cond_destroy(pthread_cond_t *cond)
static INLINE int pthread_equal(pthread_t t1, pthread_t t2)
{
if (threadGetHandle(t1) == threadGetHandle(t2))
if (threadGetHandle((Thread)t1) == threadGetHandle((Thread)t2))
return 1;
return 0;
}

Binary file not shown.

Binary file not shown.

Binary file not shown.