Revise most services to follow these guidelines:
- Each service must have xyzInit/xyzExit (with that name) - xyzInit/xyzExit use reference counting - xyzExit returns void - The utilities in <3ds/result.h> are used instead of manual error checking - The intrinsics in <3ds/synchronization.h> are used instead of inline asm - Other miscellaneous changes - APT now uses a lightweight lock instead of a mutex - Initial handle parameters in PTMU were killed - Explicit init'ion to 0 or NULL has been removed for global variables since they end up on .bss anyway - MIC hasn't been touched because it must be rewritten first - CFGNOR needs a slight touch before converting - SOC is still to be cleaned up
This commit is contained in:
parent
e01dfbc392
commit
2797540a3d
@ -8,7 +8,7 @@
|
||||
Result acInit(void);
|
||||
|
||||
/// Exits AC.
|
||||
Result acExit(void);
|
||||
void acExit(void);
|
||||
|
||||
/**
|
||||
* @brief Gets the current Wifi status.
|
||||
|
@ -19,7 +19,7 @@ typedef struct
|
||||
Result amInit(void);
|
||||
|
||||
/// Exits AM.
|
||||
Result amExit(void);
|
||||
void amExit(void);
|
||||
|
||||
/// Gets the current AM session handle.
|
||||
Handle *amGetSessionHandle(void);
|
||||
|
@ -257,7 +257,7 @@ Result camInit(void);
|
||||
*
|
||||
* This will internally call CAMU_DriverFinalize and close the handle of the service.
|
||||
*/
|
||||
Result camExit(void);
|
||||
void camExit(void);
|
||||
|
||||
/**
|
||||
* Begins capture on the specified camera port.
|
||||
|
@ -30,10 +30,10 @@ typedef enum
|
||||
} CFG_Langage;
|
||||
|
||||
/// Initializes CFGU.
|
||||
Result initCfgu(void);
|
||||
Result cfguInit(void);
|
||||
|
||||
/// Exits CFGU.
|
||||
Result exitCfgu(void);
|
||||
void cfguExit(void);
|
||||
|
||||
/**
|
||||
* @brief Gets the system's region from secure info.
|
||||
|
@ -152,7 +152,7 @@ Result CSND_Reset(void);
|
||||
Result csndInit(void);
|
||||
|
||||
/// Exits CSND.
|
||||
Result csndExit(void);
|
||||
void csndExit(void);
|
||||
|
||||
/**
|
||||
* @brief Adds a command to the list, returning a buffer to write arguments to.
|
||||
|
@ -33,7 +33,7 @@ Result dspInit(void);
|
||||
* @brief Closes the dsp service.
|
||||
* @note This will also unload the DSP binary.
|
||||
*/
|
||||
Result dspExit(void);
|
||||
void dspExit(void);
|
||||
|
||||
/**
|
||||
* @brief Checks if a headphone is inserted.
|
||||
|
@ -113,7 +113,7 @@ typedef struct
|
||||
Result fsInit(void);
|
||||
|
||||
/// Exits FS.
|
||||
Result fsExit(void);
|
||||
void fsExit(void);
|
||||
|
||||
/**
|
||||
* @brief Gets the current FS session handle.
|
||||
|
@ -10,16 +10,16 @@
|
||||
* @param sharedmem_addr Address of the shared memory block to use.
|
||||
* @param sharedmem_size Size of the shared memory block.
|
||||
*/
|
||||
Result IRU_Initialize(u32 *sharedmem_addr, u32 sharedmem_size);
|
||||
Result iruInit(u32 *sharedmem_addr, u32 sharedmem_size);
|
||||
|
||||
/// Shuts down IRU.
|
||||
Result IRU_Shutdown(void);
|
||||
void iruExit(void);
|
||||
|
||||
/**
|
||||
* @brief Gets the IRU service handle.
|
||||
* @return The IRU service handle.
|
||||
*/
|
||||
Handle IRU_GetServHandle(void);
|
||||
Handle iruGetServHandle(void);
|
||||
|
||||
/**
|
||||
* @brief Sends IR data.
|
||||
@ -27,7 +27,7 @@ Handle IRU_GetServHandle(void);
|
||||
* @param size Size of the buffer.
|
||||
* @param wait Whether to wait for the data to be sent.
|
||||
*/
|
||||
Result IRU_SendData(u8 *buf, u32 size, u32 wait);
|
||||
Result iruSendData(u8 *buf, u32 size, bool wait);
|
||||
|
||||
/**
|
||||
* @brief Receives IR data.
|
||||
@ -37,7 +37,7 @@ Result IRU_SendData(u8 *buf, u32 size, u32 wait);
|
||||
* @param transfercount Pointer to write the bytes read to.
|
||||
* @param wait Whether to wait for the data to be received.
|
||||
*/
|
||||
Result IRU_RecvData(u8 *buf, u32 size, u8 flag, u32 *transfercount, u32 wait);
|
||||
Result iruRecvData(u8 *buf, u32 size, u8 flag, u32 *transfercount, bool wait);
|
||||
|
||||
/**
|
||||
* @brief Sets the IR bit rate.
|
||||
|
@ -69,7 +69,7 @@ void mvdstdGenerateDefaultConfig(mvdstdConfig *config, u32 input_width, u32 inpu
|
||||
Result mvdstdInit(mvdstdMode mode, mvdstdTypeInput input_type, mvdstdTypeOutput output_type, u32 size);
|
||||
|
||||
/// Shuts down MVDSTD.
|
||||
Result mvdstdShutdown(void);
|
||||
void mvdstdExit(void);
|
||||
|
||||
/**
|
||||
* @brief Sets the current configuration of MVDSTD.
|
||||
|
@ -8,7 +8,7 @@
|
||||
Result newsInit(void);
|
||||
|
||||
/// Exits NEWS.
|
||||
Result newsExit(void);
|
||||
void newsExit(void);
|
||||
|
||||
/**
|
||||
* @brief Adds a notification to the home menu Notifications applet.
|
||||
|
@ -8,7 +8,7 @@
|
||||
Result nsInit(void);
|
||||
|
||||
/// Exits NS.
|
||||
Result nsExit(void);
|
||||
void nsExit(void);
|
||||
|
||||
/**
|
||||
* @brief Launches a title.
|
||||
|
@ -8,7 +8,7 @@
|
||||
Result pmInit(void);
|
||||
|
||||
/// Exits PM.
|
||||
Result pmExit(void);
|
||||
void pmExit(void);
|
||||
|
||||
/**
|
||||
* @brief Launches a title.
|
||||
|
@ -34,7 +34,7 @@ typedef enum
|
||||
Result psInit(void);
|
||||
|
||||
/// Exits PS.
|
||||
Result psExit(void);
|
||||
void psExit(void);
|
||||
|
||||
/**
|
||||
* @brief Encrypts/Decrypts AES data. Does not support AES CCM.
|
||||
|
@ -8,48 +8,43 @@
|
||||
Result ptmInit(void);
|
||||
|
||||
/// Exits PTM.
|
||||
Result ptmExit(void);
|
||||
void ptmExit(void);
|
||||
|
||||
/// Initializes ptm:sysm.
|
||||
Result ptmSysmInit(void);
|
||||
|
||||
/// Exits ptm:sysm.
|
||||
Result ptmSysmExit(void);
|
||||
void ptmSysmExit(void);
|
||||
|
||||
/**
|
||||
* @brief Gets the system's current shell state.
|
||||
* @param servhandle Optional pointer to the handle to use.
|
||||
* @param out Pointer to write the current shell state to. (0 = closed, 1 = open)
|
||||
*/
|
||||
Result PTMU_GetShellState(Handle* servhandle, u8 *out);
|
||||
Result PTMU_GetShellState(u8 *out);
|
||||
|
||||
/**
|
||||
* @brief Gets the system's current battery level.
|
||||
* @param servhandle Optional pointer to the handle to use.
|
||||
* @param out Pointer to write the current battery level to. (0-5)
|
||||
*/
|
||||
Result PTMU_GetBatteryLevel(Handle* servhandle, u8 *out);
|
||||
Result PTMU_GetBatteryLevel(u8 *out);
|
||||
|
||||
/**
|
||||
* @brief Gets the system's current battery charge state.
|
||||
* @param servhandle Optional pointer to the handle to use.
|
||||
* @param out Pointer to write the current battery charge state to. (0 = not charging, 1 = charging)
|
||||
*/
|
||||
Result PTMU_GetBatteryChargeState(Handle* servhandle, u8 *out);
|
||||
Result PTMU_GetBatteryChargeState(u8 *out);
|
||||
|
||||
/**
|
||||
* @brief Gets the system's current pedometer state.
|
||||
* @param servhandle Optional pointer to the handle to use.
|
||||
* @param out Pointer to write the current pedometer state to. (0 = not counting, 1 = counting)
|
||||
*/
|
||||
Result PTMU_GetPedometerState(Handle* servhandle, u8 *out);
|
||||
Result PTMU_GetPedometerState(u8 *out);
|
||||
|
||||
/**
|
||||
* @brief Gets the pedometer's total step count.
|
||||
* @param servhandle Optional pointer to the handle to use.
|
||||
* @param steps Pointer to write the total step count to.
|
||||
*/
|
||||
Result PTMU_GetTotalStepCount(Handle* servhandle, u32 *steps);
|
||||
Result PTMU_GetTotalStepCount(u32 *steps);
|
||||
|
||||
/**
|
||||
* @brief Configures the New 3DS' CPU clock speed and L2 cache.
|
||||
|
@ -151,7 +151,7 @@ Result y2rInit(void);
|
||||
*
|
||||
* This will internally call Y2RU_DriverFinalize and close the handle of the service.
|
||||
*/
|
||||
Result y2rExit(void);
|
||||
void y2rExit(void);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -99,7 +99,7 @@ void gfxWriteFramebufferInfo(gfxScreen_t screen)
|
||||
framebufferInfoHeader[0x1]=1;
|
||||
}
|
||||
|
||||
void (*screenFree)(void *) = NULL;
|
||||
static void (*screenFree)(void *) = NULL;
|
||||
|
||||
void gfxInit(GSP_FramebufferFormats topFormat, GSP_FramebufferFormats bottomFormat, bool vrambuffers)
|
||||
{
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/result.h>
|
||||
#include <3ds/svc.h>
|
||||
#include <3ds/os.h>
|
||||
#include <3ds/synchronization.h>
|
||||
|
@ -208,16 +208,16 @@ static Result ndspInitialize(bool resume)
|
||||
Result rc;
|
||||
|
||||
rc = ndspLoadComponent();
|
||||
if (rc) return rc;
|
||||
if (R_FAILED(rc)) return rc;
|
||||
|
||||
rc = svcCreateEvent(&irqEvent, 1);
|
||||
if (rc) goto _fail1;
|
||||
if (R_FAILED(rc)) goto _fail1;
|
||||
|
||||
rc = DSP_RegisterInterruptEvents(irqEvent, 2, 2);
|
||||
if (rc) goto _fail2;
|
||||
if (R_FAILED(rc)) goto _fail2;
|
||||
|
||||
rc = DSP_GetSemaphoreHandle(&dspSem);
|
||||
if (rc) goto _fail3;
|
||||
if (R_FAILED(rc)) goto _fail3;
|
||||
|
||||
DSP_SetSemaphoreMask(0x2000);
|
||||
|
||||
@ -383,7 +383,7 @@ void ndspUseComponent(const void* binary, u32 size, u16 progMask, u16 dataMask)
|
||||
componentFree = false;
|
||||
}
|
||||
|
||||
bool ndspFindAndLoadComponent(void)
|
||||
static bool ndspFindAndLoadComponent(void)
|
||||
{
|
||||
extern Handle __get_handle_from_list(const char* name);
|
||||
Result rc;
|
||||
@ -401,11 +401,11 @@ bool ndspFindAndLoadComponent(void)
|
||||
FS_path path = { PATH_CHAR, sizeof(dsp_filename), (u8*)dsp_filename };
|
||||
|
||||
rc = FSUSER_OpenFileDirectly(&rsrc, arch, path, FS_OPEN_READ, FS_ATTRIBUTE_NONE);
|
||||
if (rc) break;
|
||||
if (R_FAILED(rc)) break;
|
||||
|
||||
u64 size = 0;
|
||||
rc = FSFILE_GetSize(rsrc, &size);
|
||||
if (rc) { FSFILE_Close(rsrc); break; }
|
||||
if (R_FAILED(rc)) { FSFILE_Close(rsrc); break; }
|
||||
|
||||
bin = malloc(size);
|
||||
if (!bin) { FSFILE_Close(rsrc); break; }
|
||||
@ -413,7 +413,7 @@ bool ndspFindAndLoadComponent(void)
|
||||
u32 dummy = 0;
|
||||
rc = FSFILE_Read(rsrc, &dummy, 0, bin, size);
|
||||
FSFILE_Close(rsrc);
|
||||
if (rc) { free(bin); return false; }
|
||||
if (R_FAILED(rc)) { free(bin); return false; }
|
||||
|
||||
componentBin = bin;
|
||||
componentSize = size;
|
||||
@ -428,7 +428,7 @@ bool ndspFindAndLoadComponent(void)
|
||||
extern u32 fake_heap_end;
|
||||
u32 mapAddr = (fake_heap_end+0xFFF) &~ 0xFFF;
|
||||
rc = svcMapMemoryBlock(rsrc, mapAddr, 0x3, 0x3);
|
||||
if (rc) break;
|
||||
if (R_FAILED(rc)) break;
|
||||
|
||||
componentSize = *(u32*)(mapAddr + 0x104);
|
||||
bin = malloc(componentSize);
|
||||
@ -450,11 +450,11 @@ static int ndspRefCount = 0;
|
||||
Result ndspInit(void)
|
||||
{
|
||||
Result rc = 0;
|
||||
if (ndspRefCount++) return 0;
|
||||
if (AtomicPostIncrement(&ndspRefCount)) return 0;
|
||||
|
||||
if (!componentBin && !ndspFindAndLoadComponent())
|
||||
{
|
||||
rc = 1018 | (41 << 10) | (4 << 21) | (27 << 27);
|
||||
rc = MAKERESULT(RL_PERMANENT, RS_NOTFOUND, 41, RD_NOT_FOUND);
|
||||
goto _fail0;
|
||||
}
|
||||
|
||||
@ -462,27 +462,27 @@ Result ndspInit(void)
|
||||
ndspInitMaster();
|
||||
ndspiInitChn();
|
||||
|
||||
rc = initCfgu();
|
||||
if (rc==0)
|
||||
rc = cfguInit();
|
||||
if (R_SUCCEEDED(rc))
|
||||
{
|
||||
u8 outMode;
|
||||
rc = CFGU_GetConfigInfoBlk2(sizeof(outMode), 0x70001, &outMode);
|
||||
if (rc==0)
|
||||
if (R_SUCCEEDED(rc))
|
||||
ndspMaster.outputMode = outMode;
|
||||
exitCfgu();
|
||||
cfguExit();
|
||||
}
|
||||
|
||||
rc = dspInit();
|
||||
if (rc) return rc;
|
||||
if (R_FAILED(rc)) return rc;
|
||||
|
||||
rc = ndspInitialize(false);
|
||||
if (rc) goto _fail1;
|
||||
if (R_FAILED(rc)) goto _fail1;
|
||||
|
||||
rc = svcCreateEvent(&sleepEvent, 0);
|
||||
if (rc) goto _fail2;
|
||||
if (R_FAILED(rc)) goto _fail2;
|
||||
|
||||
rc = svcCreateThread(&ndspThread, ndspThreadMain, 0x0, (u32*)(&ndspThreadStack[NDSP_THREAD_STACK_SIZE/8]), 0x31, -2);
|
||||
if (rc) goto _fail3;
|
||||
if (R_FAILED(rc)) goto _fail3;
|
||||
|
||||
aptHook(&aptCookie, ndspAptHook, NULL);
|
||||
return 0;
|
||||
@ -499,14 +499,13 @@ _fail1:
|
||||
componentBin = NULL;
|
||||
}
|
||||
_fail0:
|
||||
ndspRefCount--;
|
||||
AtomicDecrement(&ndspRefCount);
|
||||
return rc;
|
||||
}
|
||||
|
||||
void ndspExit(void)
|
||||
{
|
||||
if (!ndspRefCount) return;
|
||||
if (--ndspRefCount) return;
|
||||
if (AtomicDecrement(&ndspRefCount)) return;
|
||||
if (!bDspReady) return;
|
||||
ndspThreadRun = false;
|
||||
if (bSleeping)
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/result.h>
|
||||
#include <3ds/os.h>
|
||||
#include <3ds/svc.h>
|
||||
#include <3ds/services/ptm.h>
|
||||
@ -138,7 +139,7 @@ const char* osStrError(u32 error) {
|
||||
|
||||
void __ctru_speedup_config(void)
|
||||
{
|
||||
if (ptmSysmInit()==0)
|
||||
if (R_SUCCEEDED(ptmSysmInit()))
|
||||
{
|
||||
PTMSYSM_ConfigureNew3DSCPU(__ctru_speedup ? 3 : 0);
|
||||
ptmSysmExit();
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/result.h>
|
||||
#include <3ds/svc.h>
|
||||
#include <3ds/romfs.h>
|
||||
#include <3ds/services/fs.h>
|
||||
@ -40,7 +41,7 @@ static ssize_t _romfs_read(u64 offset, void* buffer, u32 size)
|
||||
u64 pos = (u64)romFS_offset + offset;
|
||||
u32 read = 0;
|
||||
Result rc = FSFILE_Read(romFS_file, &read, pos, buffer, size);
|
||||
if (rc) return -1;
|
||||
if (R_FAILED(rc)) return -1;
|
||||
return read;
|
||||
}
|
||||
|
||||
@ -140,7 +141,7 @@ Result romfsInit(void)
|
||||
FS_path path = { PATH_WCHAR, (units+1)*2, (u8*)__utf16path };
|
||||
|
||||
Result rc = FSUSER_OpenFileDirectly(&romFS_file, arch, path, FS_OPEN_READ, FS_ATTRIBUTE_NONE);
|
||||
if (rc) return rc;
|
||||
if (R_FAILED(rc)) return rc;
|
||||
|
||||
_3DSX_Header hdr;
|
||||
if (!_romfs_read_chk(0, &hdr, sizeof(hdr))) goto _fail0;
|
||||
@ -158,7 +159,7 @@ Result romfsInit(void)
|
||||
FS_path path = { PATH_BINARY, sizeof(zeros), zeros };
|
||||
|
||||
Result rc = FSUSER_OpenFileDirectly(&romFS_file, arch, path, FS_OPEN_READ, FS_ATTRIBUTE_NONE);
|
||||
if (rc) return rc;
|
||||
if (R_FAILED(rc)) return rc;
|
||||
}
|
||||
|
||||
return romfsInitCommon();
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/result.h>
|
||||
#include <3ds/sdmc.h>
|
||||
#include <3ds/services/fs.h>
|
||||
#include <3ds/util/utf.h>
|
||||
@ -228,7 +229,7 @@ Result sdmcInit(void)
|
||||
return rc;
|
||||
|
||||
rc = FSUSER_OpenArchive(&sdmcArchive);
|
||||
if(rc == 0)
|
||||
if(R_SUCCEEDED(rc))
|
||||
{
|
||||
|
||||
int dev = AddDevice(&sdmc_devoptab);
|
||||
@ -288,7 +289,7 @@ Result sdmcExit(void)
|
||||
if(!sdmcInitialised) return rc;
|
||||
|
||||
rc = FSUSER_CloseArchive(&sdmcArchive);
|
||||
if(rc == 0)
|
||||
if(R_SUCCEEDED(rc))
|
||||
{
|
||||
RemoveDevice("sdmc");
|
||||
sdmcInitialised = false;
|
||||
@ -365,7 +366,7 @@ sdmc_open(struct _reent *r,
|
||||
if((flags & O_CREAT) && (flags & O_EXCL))
|
||||
{
|
||||
rc = FSUSER_CreateFile(sdmcArchive, fs_path, 0);
|
||||
if(rc != 0)
|
||||
if(R_FAILED(rc))
|
||||
{
|
||||
r->_errno = sdmc_translate_error(rc);
|
||||
return -1;
|
||||
@ -379,12 +380,12 @@ sdmc_open(struct _reent *r,
|
||||
/* open the file */
|
||||
rc = FSUSER_OpenFile(&fd, sdmcArchive, fs_path,
|
||||
sdmc_flags, attributes);
|
||||
if(rc == 0)
|
||||
if(R_SUCCEEDED(rc))
|
||||
{
|
||||
if((flags & O_ACCMODE) != O_RDONLY && (flags & O_TRUNC))
|
||||
{
|
||||
rc = FSFILE_SetSize(fd, 0);
|
||||
if(rc != 0)
|
||||
if(R_FAILED(rc))
|
||||
{
|
||||
FSFILE_Close(fd);
|
||||
r->_errno = sdmc_translate_error(rc);
|
||||
@ -420,7 +421,7 @@ sdmc_close(struct _reent *r,
|
||||
sdmc_file_t *file = (sdmc_file_t*)fd;
|
||||
|
||||
rc = FSFILE_Close(file->fd);
|
||||
if(rc == 0)
|
||||
if(R_SUCCEEDED(rc))
|
||||
return 0;
|
||||
|
||||
r->_errno = sdmc_translate_error(rc);
|
||||
@ -465,7 +466,7 @@ sdmc_write(struct _reent *r,
|
||||
{
|
||||
/* append means write from the end of the file */
|
||||
rc = FSFILE_GetSize(file->fd, &file->offset);
|
||||
if(rc != 0)
|
||||
if(R_FAILED(rc))
|
||||
{
|
||||
r->_errno = sdmc_translate_error(rc);
|
||||
return -1;
|
||||
@ -488,7 +489,7 @@ sdmc_write(struct _reent *r,
|
||||
/* write the data */
|
||||
rc = FSFILE_Write(file->fd, &bytes, file->offset,
|
||||
(u32*)tmp_buffer, (u32)toWrite, sync);
|
||||
if(rc != 0)
|
||||
if(R_FAILED(rc))
|
||||
{
|
||||
/* return partial transfer */
|
||||
if(bytesWritten > 0)
|
||||
@ -538,7 +539,7 @@ sdmc_read(struct _reent *r,
|
||||
|
||||
/* read the data */
|
||||
rc = FSFILE_Read(file->fd, &bytes, file->offset, (u32*)ptr, (u32)len);
|
||||
if(rc == 0)
|
||||
if(R_SUCCEEDED(rc))
|
||||
{
|
||||
/* update current file offset */
|
||||
file->offset += bytes;
|
||||
@ -587,7 +588,7 @@ sdmc_seek(struct _reent *r,
|
||||
/* set position relative to the end of the file */
|
||||
case SEEK_END:
|
||||
rc = FSFILE_GetSize(file->fd, &offset);
|
||||
if(rc != 0)
|
||||
if(R_FAILED(rc))
|
||||
{
|
||||
r->_errno = sdmc_translate_error(rc);
|
||||
return -1;
|
||||
@ -632,7 +633,7 @@ sdmc_fstat(struct _reent *r,
|
||||
sdmc_file_t *file = (sdmc_file_t*)fd;
|
||||
|
||||
rc = FSFILE_GetSize(file->fd, &size);
|
||||
if(rc == 0)
|
||||
if(R_SUCCEEDED(rc))
|
||||
{
|
||||
memset(st, 0, sizeof(struct stat));
|
||||
st->st_size = (off_t)size;
|
||||
@ -667,8 +668,8 @@ sdmc_stat(struct _reent *r,
|
||||
if(fs_path.data == NULL)
|
||||
return -1;
|
||||
|
||||
if((rc = FSUSER_OpenFile(&fd, sdmcArchive, fs_path,
|
||||
FS_OPEN_READ, FS_ATTRIBUTE_NONE)) == 0)
|
||||
if(R_SUCCEEDED(rc = FSUSER_OpenFile(&fd, sdmcArchive, fs_path,
|
||||
FS_OPEN_READ, FS_ATTRIBUTE_NONE)))
|
||||
{
|
||||
sdmc_file_t tmpfd = { .fd = fd };
|
||||
rc = sdmc_fstat(r, (int)&tmpfd, st);
|
||||
@ -676,7 +677,7 @@ sdmc_stat(struct _reent *r,
|
||||
|
||||
return rc;
|
||||
}
|
||||
else if((rc = FSUSER_OpenDirectory(&fd, sdmcArchive, fs_path)) == 0)
|
||||
else if(R_SUCCEEDED(rc = FSUSER_OpenDirectory(&fd, sdmcArchive, fs_path)))
|
||||
{
|
||||
memset(st, 0, sizeof(struct stat));
|
||||
st->st_nlink = 1;
|
||||
@ -727,7 +728,7 @@ sdmc_unlink(struct _reent *r,
|
||||
return -1;
|
||||
|
||||
rc = FSUSER_DeleteFile(sdmcArchive, fs_path);
|
||||
if(rc == 0)
|
||||
if(R_SUCCEEDED(rc))
|
||||
return 0;
|
||||
|
||||
r->_errno = sdmc_translate_error(rc);
|
||||
@ -755,7 +756,7 @@ sdmc_chdir(struct _reent *r,
|
||||
return -1;
|
||||
|
||||
rc = FSUSER_OpenDirectory(&fd, sdmcArchive, fs_path);
|
||||
if(rc == 0)
|
||||
if(R_SUCCEEDED(rc))
|
||||
{
|
||||
FSDIR_Close(fd);
|
||||
strncpy(__cwd, __fixedpath, PATH_MAX);
|
||||
@ -796,11 +797,11 @@ sdmc_rename(struct _reent *r,
|
||||
return -1;
|
||||
|
||||
rc = FSUSER_RenameFile(sdmcArchive, fs_path_old, sdmcArchive, fs_path_new);
|
||||
if(rc == 0)
|
||||
if(R_SUCCEEDED(rc))
|
||||
return 0;
|
||||
|
||||
rc = FSUSER_RenameDirectory(sdmcArchive, fs_path_old, sdmcArchive, fs_path_new);
|
||||
if(rc == 0)
|
||||
if(R_SUCCEEDED(rc))
|
||||
return 0;
|
||||
|
||||
r->_errno = sdmc_translate_error(rc);
|
||||
@ -831,7 +832,7 @@ sdmc_mkdir(struct _reent *r,
|
||||
/* TODO: Use mode to set directory attributes. */
|
||||
|
||||
rc = FSUSER_CreateDirectory(sdmcArchive, fs_path);
|
||||
if(rc == 0)
|
||||
if(R_SUCCEEDED(rc))
|
||||
return 0;
|
||||
|
||||
r->_errno = sdmc_translate_error(rc);
|
||||
@ -866,7 +867,7 @@ sdmc_diropen(struct _reent *r,
|
||||
|
||||
/* open the directory */
|
||||
rc = FSUSER_OpenDirectory(&fd, sdmcArchive, fs_path);
|
||||
if(rc == 0)
|
||||
if(R_SUCCEEDED(rc))
|
||||
{
|
||||
dir->fd = fd;
|
||||
memset(&dir->entry_data, 0, sizeof(dir->entry_data));
|
||||
@ -919,7 +920,7 @@ sdmc_dirnext(struct _reent *r,
|
||||
/* fetch the next entry */
|
||||
memset(&dir->entry_data, 0, sizeof(dir->entry_data));
|
||||
rc = FSDIR_Read(dir->fd, &entries, 1, &dir->entry_data);
|
||||
if(rc == 0)
|
||||
if(R_SUCCEEDED(rc))
|
||||
{
|
||||
if(entries == 0)
|
||||
{
|
||||
@ -976,7 +977,7 @@ sdmc_dirclose(struct _reent *r,
|
||||
|
||||
/* close the directory */
|
||||
rc = FSDIR_Close(dir->fd);
|
||||
if(rc == 0)
|
||||
if(R_SUCCEEDED(rc))
|
||||
return 0;
|
||||
|
||||
r->_errno = sdmc_translate_error(rc);
|
||||
@ -1006,7 +1007,7 @@ sdmc_statvfs(struct _reent *r,
|
||||
&numClusters,
|
||||
&freeClusters);
|
||||
|
||||
if(rc == 0)
|
||||
if(R_SUCCEEDED(rc))
|
||||
{
|
||||
buf->f_bsize = clusterSize;
|
||||
buf->f_frsize = clusterSize;
|
||||
@ -1021,7 +1022,7 @@ sdmc_statvfs(struct _reent *r,
|
||||
buf->f_namemax = 0; //??? how to get
|
||||
|
||||
rc = FSUSER_IsSdmcWritable(&writable);
|
||||
if(rc != 0 || !writable)
|
||||
if(R_FAILED(rc) || !writable)
|
||||
buf->f_flag |= ST_RDONLY;
|
||||
|
||||
return 0;
|
||||
@ -1059,7 +1060,7 @@ sdmc_ftruncate(struct _reent *r,
|
||||
|
||||
/* set the new file size */
|
||||
rc = FSFILE_SetSize(file->fd, len);
|
||||
if(rc == 0)
|
||||
if(R_SUCCEEDED(rc))
|
||||
return 0;
|
||||
|
||||
r->_errno = sdmc_translate_error(rc);
|
||||
@ -1084,7 +1085,7 @@ sdmc_fsync(struct _reent *r,
|
||||
sdmc_file_t *file = (sdmc_file_t*)fd;
|
||||
|
||||
rc = FSFILE_Flush(file->fd);
|
||||
if(rc == 0)
|
||||
if(R_SUCCEEDED(rc))
|
||||
return 0;
|
||||
|
||||
r->_errno = sdmc_translate_error(rc);
|
||||
@ -1147,7 +1148,7 @@ sdmc_rmdir(struct _reent *r,
|
||||
return -1;
|
||||
|
||||
rc = FSUSER_DeleteDirectory(sdmcArchive, fs_path);
|
||||
if(rc == 0)
|
||||
if(R_SUCCEEDED(rc))
|
||||
return 0;
|
||||
|
||||
r->_errno = sdmc_translate_error(rc);
|
||||
|
@ -1,22 +1,32 @@
|
||||
#include <stdlib.h>
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/result.h>
|
||||
#include <3ds/svc.h>
|
||||
#include <3ds/srv.h>
|
||||
#include <3ds/synchronization.h>
|
||||
#include <3ds/services/ac.h>
|
||||
#include <3ds/ipc.h>
|
||||
|
||||
static Handle acHandle;
|
||||
static int acRefCount;
|
||||
|
||||
Result acInit(void)
|
||||
{
|
||||
Result ret = srvGetServiceHandle(&acHandle, "ac:u");
|
||||
if(!ret)return ret;
|
||||
return srvGetServiceHandle(&acHandle, "ac:i");
|
||||
Result ret;
|
||||
|
||||
if (AtomicPostIncrement(&acRefCount)) return 0;
|
||||
|
||||
ret = srvGetServiceHandle(&acHandle, "ac:u");
|
||||
if(R_FAILED(ret)) ret = srvGetServiceHandle(&acHandle, "ac:i");
|
||||
if(R_FAILED(ret)) AtomicDecrement(&acRefCount);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Result acExit(void)
|
||||
void acExit(void)
|
||||
{
|
||||
return svcCloseHandle(acHandle);
|
||||
if (AtomicDecrement(&acRefCount)) return;
|
||||
svcCloseHandle(acHandle);
|
||||
}
|
||||
|
||||
// ptr=0x200-byte outbuf
|
||||
@ -33,7 +43,7 @@ Result ACU_CreateDefaultConfig(u32 *ptr)
|
||||
staticbufs[0] = IPC_Desc_StaticBuffer(0x200,0);
|
||||
staticbufs[1] = (u32)ptr;
|
||||
|
||||
if((ret = svcSendSyncRequest(acHandle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(acHandle)))return ret;
|
||||
|
||||
staticbufs[0] = savedValue0;
|
||||
staticbufs[1] = savedValue1;
|
||||
@ -58,7 +68,7 @@ Result ACU_cmd26(u32 *ptr, u8 val)
|
||||
cmdbuf[2] = IPC_Desc_StaticBuffer(0x200,0);
|
||||
cmdbuf[3] = (u32)ptr;
|
||||
|
||||
if((ret = svcSendSyncRequest(acHandle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(acHandle)))return ret;
|
||||
|
||||
staticbufs[0] = savedValue0;
|
||||
staticbufs[1] = savedValue1;
|
||||
@ -73,7 +83,7 @@ Result ACU_GetWifiStatus(u32 *out)
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0xD,0,0); // 0x000D0000
|
||||
|
||||
if((ret = svcSendSyncRequest(acHandle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(acHandle)))return ret;
|
||||
|
||||
*out = cmdbuf[2];
|
||||
|
||||
@ -85,12 +95,12 @@ Result ACU_WaitInternetConnection(void)
|
||||
Result ret=0;
|
||||
u32 outval=0;
|
||||
|
||||
if((ret = acInit())!=0)return ret;
|
||||
if(R_FAILED(ret = acInit()))return ret;
|
||||
|
||||
while(1)
|
||||
{
|
||||
ret = ACU_GetWifiStatus(&outval);
|
||||
if(ret==0 && outval!=0)break;
|
||||
if(R_SUCCEEDED(ret) && outval!=0)break;
|
||||
}
|
||||
|
||||
acExit();
|
||||
|
@ -1,28 +1,35 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/result.h>
|
||||
#include <3ds/svc.h>
|
||||
#include <3ds/srv.h>
|
||||
#include <3ds/synchronization.h>
|
||||
#include <3ds/services/am.h>
|
||||
#include <3ds/ipc.h>
|
||||
|
||||
static Handle amHandle = 0;
|
||||
static Handle amHandle;
|
||||
static int amRefCount;
|
||||
|
||||
Result amInit(void)
|
||||
{
|
||||
if(srvGetServiceHandle(&amHandle, "am:net") == 0)
|
||||
return (Result)0;
|
||||
else if(srvGetServiceHandle(&amHandle, "am:u") == 0)
|
||||
return (Result)0;
|
||||
else if(srvGetServiceHandle(&amHandle, "am:sys") == 0)
|
||||
return (Result)0;
|
||||
else return srvGetServiceHandle(&amHandle, "am:app");
|
||||
Result ret;
|
||||
|
||||
if (AtomicPostIncrement(&amRefCount)) return 0;
|
||||
|
||||
ret = srvGetServiceHandle(&amHandle, "am:net");
|
||||
if (R_FAILED(ret)) ret = srvGetServiceHandle(&amHandle, "am:u");
|
||||
if (R_FAILED(ret)) ret = srvGetServiceHandle(&amHandle, "am:sys");
|
||||
if (R_FAILED(ret)) ret = srvGetServiceHandle(&amHandle, "am:app");
|
||||
if (R_FAILED(ret)) AtomicDecrement(&amRefCount);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Result amExit(void)
|
||||
void amExit(void)
|
||||
{
|
||||
return svcCloseHandle(amHandle);
|
||||
if (AtomicDecrement(&amRefCount)) return;
|
||||
svcCloseHandle(amHandle);
|
||||
}
|
||||
|
||||
Handle *amGetSessionHandle(void)
|
||||
@ -38,7 +45,7 @@ Result AM_GetTitleCount(u8 mediatype, u32 *count)
|
||||
cmdbuf[0] = IPC_MakeHeader(0x1,1,0); // 0x00010040
|
||||
cmdbuf[1] = mediatype;
|
||||
|
||||
if((ret = svcSendSyncRequest(amHandle))!=0) return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(amHandle))) return ret;
|
||||
|
||||
*count = cmdbuf[2];
|
||||
|
||||
@ -56,7 +63,7 @@ Result AM_GetTitleIdList(u8 mediatype, u32 count, u64 *titleIDs)
|
||||
cmdbuf[3] = IPC_Desc_Buffer(count*sizeof(u64),IPC_BUFFER_W);
|
||||
cmdbuf[4] = (u32)titleIDs;
|
||||
|
||||
if((ret = svcSendSyncRequest(amHandle))!=0) return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(amHandle))) return ret;
|
||||
|
||||
return (Result)cmdbuf[1];
|
||||
}
|
||||
@ -74,7 +81,7 @@ Result AM_ListTitles(u8 mediatype, u32 titleCount, u64 *titleIdList, AM_TitleEnt
|
||||
cmdbuf[5] = IPC_Desc_Buffer(titleCount*sizeof(AM_TitleEntry),IPC_BUFFER_W);
|
||||
cmdbuf[6] = (u32)titleList;
|
||||
|
||||
if((ret = svcSendSyncRequest(amHandle))!=0) return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(amHandle))) return ret;
|
||||
|
||||
return (Result)cmdbuf[1];
|
||||
}
|
||||
@ -86,7 +93,7 @@ Result AM_GetDeviceId(u32 *deviceID)
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0xA,0,0); // 0x000A0000
|
||||
|
||||
if((ret = svcSendSyncRequest(amHandle))!=0) return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(amHandle))) return ret;
|
||||
|
||||
*deviceID = cmdbuf[3];
|
||||
|
||||
@ -101,7 +108,7 @@ Result AM_StartCiaInstall(u8 mediatype, Handle *ciaHandle)
|
||||
cmdbuf[0] = IPC_MakeHeader(0x402,1,0); // 0x04020040
|
||||
cmdbuf[1] = mediatype;
|
||||
|
||||
if((ret = svcSendSyncRequest(amHandle))!=0) return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(amHandle))) return ret;
|
||||
|
||||
*ciaHandle = cmdbuf[3];
|
||||
|
||||
@ -115,7 +122,7 @@ Result AM_StartDlpChildCiaInstall(Handle *ciaHandle)
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x403,0,0); // 0x04030000
|
||||
|
||||
if((ret = svcSendSyncRequest(amHandle))!=0) return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(amHandle))) return ret;
|
||||
|
||||
*ciaHandle = cmdbuf[3];
|
||||
|
||||
@ -131,7 +138,7 @@ Result AM_CancelCIAInstall(Handle *ciaHandle)
|
||||
cmdbuf[1] = IPC_Desc_MoveHandles(1);
|
||||
cmdbuf[2] = *ciaHandle;
|
||||
|
||||
if((ret = svcSendSyncRequest(amHandle))!=0) return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(amHandle))) return ret;
|
||||
|
||||
return (Result)cmdbuf[1];
|
||||
}
|
||||
@ -145,7 +152,7 @@ Result AM_FinishCiaInstall(u8 mediatype, Handle *ciaHandle)
|
||||
cmdbuf[1] = IPC_Desc_MoveHandles(1);
|
||||
cmdbuf[2] = *ciaHandle;
|
||||
|
||||
if((ret = svcSendSyncRequest(amHandle))!=0) return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(amHandle))) return ret;
|
||||
|
||||
return (Result)cmdbuf[1];
|
||||
}
|
||||
@ -160,7 +167,7 @@ Result AM_DeleteTitle(u8 mediatype, u64 titleID)
|
||||
cmdbuf[2] = titleID & 0xffffffff;
|
||||
cmdbuf[3] = (u32)(titleID >> 32);
|
||||
|
||||
if((ret = svcSendSyncRequest(amHandle))!=0) return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(amHandle))) return ret;
|
||||
|
||||
return (Result)cmdbuf[1];
|
||||
}
|
||||
@ -175,7 +182,7 @@ Result AM_DeleteAppTitle(u8 mediatype, u64 titleID)
|
||||
cmdbuf[2] = titleID & 0xffffffff;
|
||||
cmdbuf[3] = (u32)(titleID >> 32);
|
||||
|
||||
if((ret = svcSendSyncRequest(amHandle))!=0) return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(amHandle))) return ret;
|
||||
|
||||
return (Result)cmdbuf[1];
|
||||
}
|
||||
@ -187,7 +194,7 @@ Result AM_InstallNativeFirm(void)
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x40F,0,0); // 0x040F0000
|
||||
|
||||
if((ret = svcSendSyncRequest(amHandle))!=0) return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(amHandle))) return ret;
|
||||
|
||||
return (Result)cmdbuf[1];
|
||||
}
|
||||
@ -202,10 +209,10 @@ Result AM_GetTitleProductCode(u8 mediatype, u64 titleID, char* productCode)
|
||||
cmdbuf[2] = titleID & 0xffffffff;
|
||||
cmdbuf[3] = (u32)(titleID >> 32);
|
||||
|
||||
if((ret = svcSendSyncRequest(amHandle))!=0) return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(amHandle))) return ret;
|
||||
|
||||
// The product code string can use the full 16 bytes without NULL terminator
|
||||
if(productCode) snprintf(productCode, 16, "%s", (char*)&cmdbuf[2]);
|
||||
if(productCode) strncpy(productCode, (char*)&cmdbuf[2], 16);
|
||||
|
||||
return (Result)cmdbuf[1];
|
||||
}
|
||||
@ -220,7 +227,7 @@ Result AM_GetCiaFileInfo(u8 mediatype, AM_TitleEntry *titleEntry, Handle fileHan
|
||||
cmdbuf[2] = IPC_Desc_SharedHandles(1);
|
||||
cmdbuf[3] = fileHandle;
|
||||
|
||||
if((ret = svcSendSyncRequest(amHandle))!=0) return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(amHandle))) return ret;
|
||||
|
||||
if(titleEntry) memcpy(titleEntry, &cmdbuf[2], sizeof(AM_TitleEntry));
|
||||
|
||||
|
@ -5,8 +5,10 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/result.h>
|
||||
#include <3ds/svc.h>
|
||||
#include <3ds/srv.h>
|
||||
#include <3ds/synchronization.h>
|
||||
#include <3ds/services/apt.h>
|
||||
#include <3ds/services/gsp.h>
|
||||
#include <3ds/ipc.h>
|
||||
@ -20,11 +22,11 @@ extern u32 __system_runflags;
|
||||
|
||||
NS_APPID currentAppId;
|
||||
|
||||
static char *__apt_servicestr = NULL;
|
||||
static char *__apt_servicenames[3] = {"APT:U", "APT:S", "APT:A"};
|
||||
static const char *__apt_servicestr;
|
||||
static const char * const __apt_servicenames[3] = {"APT:U", "APT:S", "APT:A"};
|
||||
|
||||
static u32 __apt_new3dsflag_initialized = 0;
|
||||
static u8 __apt_new3dsflag = 0;
|
||||
static u32 __apt_new3dsflag_initialized;
|
||||
static u8 __apt_new3dsflag;
|
||||
|
||||
Handle aptLockHandle;
|
||||
Handle aptuHandle;
|
||||
@ -33,12 +35,12 @@ Handle aptEvents[3];
|
||||
Handle aptEventHandlerThread;
|
||||
u64 aptEventHandlerStack[APT_HANDLER_STACKSIZE/8]; // u64 so that it's 8-byte aligned
|
||||
|
||||
Handle aptStatusMutex;
|
||||
Handle aptStatusEvent = 0;
|
||||
LightLock aptStatusMutex;
|
||||
Handle aptStatusEvent;
|
||||
APP_STATUS aptStatus = APP_NOTINITIALIZED;
|
||||
APP_STATUS aptStatusBeforeSleep = APP_NOTINITIALIZED;
|
||||
u32 aptStatusPower = 0;
|
||||
Handle aptSleepSync = 0;
|
||||
u32 aptStatusPower;
|
||||
Handle aptSleepSync;
|
||||
|
||||
u32 aptParameters[0x1000/4]; //TEMP
|
||||
|
||||
@ -90,7 +92,7 @@ static Result __apt_initservicehandle(void)
|
||||
for(i=0; i<3; i++)
|
||||
{
|
||||
ret = srvGetServiceHandle(&aptuHandle, __apt_servicenames[i]);
|
||||
if(ret==0)
|
||||
if(R_SUCCEEDED(ret))
|
||||
{
|
||||
__apt_servicestr = __apt_servicenames[i];
|
||||
return ret;
|
||||
@ -315,7 +317,7 @@ static void __handle_notification(void) {
|
||||
aptOpenSession();
|
||||
ret = APT_InquireNotification(currentAppId, &type);
|
||||
aptCloseSession();
|
||||
if(ret!=0) return;
|
||||
if(R_FAILED(ret)) return;
|
||||
|
||||
_aptDebug(1, type);
|
||||
|
||||
@ -445,37 +447,35 @@ void aptEventHandler(void *arg)
|
||||
svcExitThread();
|
||||
}
|
||||
|
||||
static bool aptInitialised = false;
|
||||
static int aptRefCount = 0;
|
||||
|
||||
Result aptInit(void)
|
||||
{
|
||||
Result ret=0;
|
||||
|
||||
if (aptInitialised) return ret;
|
||||
|
||||
aptStatusMutex = 0;
|
||||
if (AtomicPostIncrement(&aptRefCount)) return 0;
|
||||
|
||||
// Initialize APT stuff, escape load screen.
|
||||
ret = __apt_initservicehandle();
|
||||
if(ret!=0)return ret;
|
||||
if((ret=APT_GetLockHandle(0x0, &aptLockHandle)))return ret;
|
||||
if(R_FAILED(ret)) goto _fail;
|
||||
if(R_FAILED(ret=APT_GetLockHandle(0x0, &aptLockHandle))) goto _fail;
|
||||
svcCloseHandle(aptuHandle);
|
||||
|
||||
currentAppId = __apt_appid;
|
||||
|
||||
svcCreateEvent(&aptStatusEvent, 0);
|
||||
svcCreateEvent(&aptSleepSync, 0);
|
||||
svcCreateMutex(&aptStatusMutex, false);
|
||||
LightLock_Init(&aptStatusMutex);
|
||||
aptStatus=0;
|
||||
|
||||
if(!aptIsCrippled())
|
||||
{
|
||||
aptOpenSession();
|
||||
if((ret=APT_Initialize(currentAppId, &aptEvents[0], &aptEvents[1])))return ret;
|
||||
if(R_FAILED(ret=APT_Initialize(currentAppId, &aptEvents[0], &aptEvents[1])))return ret;
|
||||
aptCloseSession();
|
||||
|
||||
aptOpenSession();
|
||||
if((ret=APT_Enable(0x0)))return ret;
|
||||
if(R_FAILED(ret=APT_Enable(0x0))) goto _fail;
|
||||
aptCloseSession();
|
||||
|
||||
// create APT close event
|
||||
@ -495,7 +495,7 @@ Result aptInit(void)
|
||||
}
|
||||
|
||||
aptOpenSession();
|
||||
if((ret=APT_NotifyToWait(currentAppId)))return ret;
|
||||
if(R_FAILED(ret=APT_NotifyToWait(currentAppId)))return ret;
|
||||
aptCloseSession();
|
||||
|
||||
// create APT event handler thread
|
||||
@ -507,14 +507,16 @@ Result aptInit(void)
|
||||
} else
|
||||
aptAppStarted();
|
||||
|
||||
aptInitialised = true;
|
||||
|
||||
return 0;
|
||||
|
||||
_fail:
|
||||
AtomicDecrement(&aptRefCount);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void aptExit(void)
|
||||
{
|
||||
if (!aptInitialised) return;
|
||||
if (AtomicDecrement(&aptRefCount)) return;
|
||||
|
||||
if(!aptIsCrippled())aptAppletUtility_Exit_RetToApp(0);
|
||||
|
||||
@ -559,11 +561,8 @@ void aptExit(void)
|
||||
|
||||
svcCloseHandle(aptSleepSync);
|
||||
|
||||
svcCloseHandle(aptStatusMutex);
|
||||
svcCloseHandle(aptLockHandle);
|
||||
svcCloseHandle(aptStatusEvent);
|
||||
|
||||
aptInitialised = false;
|
||||
}
|
||||
|
||||
bool aptMainLoop(void)
|
||||
@ -660,15 +659,15 @@ void aptAppStarted(void)
|
||||
APP_STATUS aptGetStatus(void)
|
||||
{
|
||||
APP_STATUS ret;
|
||||
svcWaitSynchronization(aptStatusMutex, U64_MAX);
|
||||
LightLock_Lock(&aptStatusMutex);
|
||||
ret = aptStatus;
|
||||
svcReleaseMutex(aptStatusMutex);
|
||||
LightLock_Unlock(&aptStatusMutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void aptSetStatus(APP_STATUS status)
|
||||
{
|
||||
svcWaitSynchronization(aptStatusMutex, U64_MAX);
|
||||
LightLock_Lock(&aptStatusMutex);
|
||||
|
||||
aptStatus = status;
|
||||
|
||||
@ -680,37 +679,35 @@ void aptSetStatus(APP_STATUS status)
|
||||
svcSignalEvent(aptStatusEvent);
|
||||
//}
|
||||
|
||||
svcReleaseMutex(aptStatusMutex);
|
||||
LightLock_Unlock(&aptStatusMutex);
|
||||
}
|
||||
|
||||
u32 aptGetStatusPower(void)
|
||||
{
|
||||
u32 ret;
|
||||
svcWaitSynchronization(aptStatusMutex, U64_MAX);
|
||||
LightLock_Lock(&aptStatusMutex);
|
||||
ret = aptStatusPower;
|
||||
svcReleaseMutex(aptStatusMutex);
|
||||
LightLock_Unlock(&aptStatusMutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void aptSetStatusPower(u32 status)
|
||||
{
|
||||
svcWaitSynchronization(aptStatusMutex, U64_MAX);
|
||||
LightLock_Lock(&aptStatusMutex);
|
||||
aptStatusPower = status;
|
||||
svcReleaseMutex(aptStatusMutex);
|
||||
LightLock_Unlock(&aptStatusMutex);
|
||||
}
|
||||
|
||||
void aptOpenSession(void)
|
||||
{
|
||||
//Result ret;
|
||||
|
||||
svcWaitSynchronization(aptLockHandle, U64_MAX);
|
||||
LightLock_Lock(&aptStatusMutex);
|
||||
__apt_initservicehandle();
|
||||
}
|
||||
|
||||
void aptCloseSession(void)
|
||||
{
|
||||
svcCloseHandle(aptuHandle);
|
||||
svcReleaseMutex(aptLockHandle);
|
||||
LightLock_Unlock(&aptStatusMutex);
|
||||
}
|
||||
|
||||
void aptSignalReadyForSleep(void)
|
||||
@ -725,7 +722,7 @@ Result APT_GetLockHandle(u16 flags, Handle* lockHandle)
|
||||
cmdbuf[1]=flags;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
|
||||
if(lockHandle)*lockHandle=cmdbuf[5];
|
||||
|
||||
@ -740,7 +737,7 @@ Result APT_Initialize(NS_APPID appId, Handle* eventHandle1, Handle* eventHandle2
|
||||
cmdbuf[2]=0x0;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
|
||||
if(eventHandle1)*eventHandle1=cmdbuf[3]; //return to menu event ?
|
||||
if(eventHandle2)*eventHandle2=cmdbuf[4];
|
||||
@ -755,7 +752,7 @@ Result APT_Finalize(NS_APPID appId)
|
||||
cmdbuf[1]=appId;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -765,7 +762,7 @@ Result APT_HardwareResetAsync()
|
||||
cmdbuf[0]=IPC_MakeHeader(0x4E,0,0); // 0x4E0000
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -777,7 +774,7 @@ Result APT_Enable(u32 a)
|
||||
cmdbuf[1]=a;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -789,7 +786,7 @@ Result APT_GetAppletManInfo(u8 inval, u8 *outval8, u32 *outval32, NS_APPID *menu
|
||||
cmdbuf[1]=inval;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
|
||||
if(outval8)*outval8=cmdbuf[2];
|
||||
if(outval32)*outval32=cmdbuf[3];
|
||||
@ -806,7 +803,7 @@ Result APT_GetAppletInfo(NS_APPID appID, u64* pProgramID, u8* pMediaType, u8* pR
|
||||
cmdbuf[1]=appID;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
|
||||
if(pProgramID)*pProgramID=(u64)cmdbuf[2]|((u64)cmdbuf[3]<<32);
|
||||
if(pMediaType)*pMediaType=cmdbuf[4];
|
||||
@ -825,7 +822,7 @@ Result APT_GetAppletProgramInfo(u32 id, u32 flags, u16 *titleversion)
|
||||
cmdbuf[2]=flags;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
|
||||
if(titleversion)*titleversion=cmdbuf[2];
|
||||
|
||||
@ -839,7 +836,7 @@ Result APT_GetProgramID(u64* pProgramID)
|
||||
cmdbuf[1] = IPC_Desc_CurProcessHandle();
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
|
||||
if(ret==0)ret = cmdbuf[1];
|
||||
|
||||
@ -858,7 +855,7 @@ Result APT_IsRegistered(NS_APPID appID, u8* out)
|
||||
cmdbuf[1]=appID;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
|
||||
if(out)*out=cmdbuf[2];
|
||||
|
||||
@ -872,7 +869,7 @@ Result APT_InquireNotification(u32 appID, u8* signalType)
|
||||
cmdbuf[1]=appID;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
|
||||
if(signalType)*signalType=cmdbuf[2];
|
||||
|
||||
@ -885,7 +882,7 @@ Result APT_PrepareToJumpToHomeMenu(void)
|
||||
cmdbuf[0]=IPC_MakeHeader(0x2B,0,0); // 0x2B0000
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -901,7 +898,7 @@ Result APT_JumpToHomeMenu(const u8 *param, size_t paramSize, Handle handle)
|
||||
cmdbuf[5]= (u32) param;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -913,7 +910,7 @@ Result APT_PrepareToJumpToApplication(u32 a)
|
||||
cmdbuf[1]=a;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -929,7 +926,7 @@ Result APT_JumpToApplication(const u8 *param, size_t paramSize, Handle handle)
|
||||
cmdbuf[5]= (u32) param;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -941,7 +938,7 @@ Result APT_NotifyToWait(NS_APPID appID)
|
||||
cmdbuf[1]=appID;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -961,7 +958,7 @@ Result APT_AppletUtility(u32* out, u32 a, u32 size1, u8* buf1, u32 size2, u8* bu
|
||||
staticbufs[1]=(u32)buf2;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
|
||||
if(out)*out=cmdbuf[2];
|
||||
|
||||
@ -980,7 +977,7 @@ Result APT_GlanceParameter(NS_APPID appID, u32 bufferSize, u32* buffer, u32* act
|
||||
staticbufs[1]=(u32)buffer;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
|
||||
if(signalType)*signalType=cmdbuf[3];
|
||||
if(actualSize)*actualSize=cmdbuf[4];
|
||||
@ -1000,7 +997,7 @@ Result APT_ReceiveParameter(NS_APPID appID, u32 bufferSize, u32* buffer, u32* ac
|
||||
staticbufs[1]=(u32)buffer;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
|
||||
if(signalType)*signalType=cmdbuf[3];
|
||||
if(actualSize)*actualSize=cmdbuf[4];
|
||||
@ -1025,7 +1022,7 @@ Result APT_SendParameter(NS_APPID src_appID, NS_APPID dst_appID, u32 bufferSize,
|
||||
cmdbuf[8] = (u32)buffer;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -1040,7 +1037,7 @@ Result APT_SendCaptureBufferInfo(u32 bufferSize, u32* buffer)
|
||||
cmdbuf[3] = (u32)buffer;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -1053,7 +1050,7 @@ Result APT_ReplySleepQuery(NS_APPID appID, u32 a)
|
||||
cmdbuf[2]=a;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -1065,7 +1062,7 @@ Result APT_ReplySleepNotificationComplete(NS_APPID appID)
|
||||
cmdbuf[1]=appID;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -1077,7 +1074,7 @@ Result APT_PrepareToCloseApplication(u8 a)
|
||||
cmdbuf[1]=a;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -1093,7 +1090,7 @@ Result APT_CloseApplication(const u8 *param, size_t paramSize, Handle handle)
|
||||
cmdbuf[5]= (u32) param;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -1107,7 +1104,7 @@ Result APT_SetAppCpuTimeLimit(u32 percent)
|
||||
cmdbuf[2]=percent;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -1119,7 +1116,7 @@ Result APT_GetAppCpuTimeLimit(u32 *percent)
|
||||
cmdbuf[1]=1;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
|
||||
if(percent)*percent=cmdbuf[2];
|
||||
|
||||
@ -1133,7 +1130,7 @@ Result APT_CheckNew3DS_Application(u8 *out)
|
||||
cmdbuf[0]=IPC_MakeHeader(0x101,0,0); // 0x1010000
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
|
||||
if(ret==0)ret = cmdbuf[1];
|
||||
|
||||
@ -1152,7 +1149,7 @@ Result APT_CheckNew3DS_System(u8 *out)
|
||||
cmdbuf[0]=IPC_MakeHeader(0x102,0,0); // 0x1020000
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
|
||||
if(ret==0)ret = cmdbuf[1];
|
||||
|
||||
@ -1199,7 +1196,7 @@ Result APT_PrepareToDoAppJump(u8 flags, u64 programID, u8 mediatype)
|
||||
cmdbuf[4]=mediatype;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -1216,7 +1213,7 @@ Result APT_DoAppJump(u32 NSbuf0Size, u32 NSbuf1Size, u8 *NSbuf0Ptr, u8 *NSbuf1Pt
|
||||
cmdbuf[6]=(u32)NSbuf1Ptr;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -1228,7 +1225,7 @@ Result APT_PrepareToStartLibraryApplet(NS_APPID appID)
|
||||
cmdbuf[1]=appID;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -1245,7 +1242,7 @@ Result APT_StartLibraryApplet(NS_APPID appID, Handle inhandle, u32 *parambuf, u3
|
||||
cmdbuf[6]=(u32)parambuf;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -1265,7 +1262,7 @@ Result APT_LaunchLibraryApplet(NS_APPID appID, Handle inhandle, u32 *parambuf, u
|
||||
aptOpenSession();
|
||||
ret=APT_PrepareToStartLibraryApplet(appID);
|
||||
aptCloseSession();
|
||||
if(ret!=0)return ret;
|
||||
if(R_FAILED(ret))return ret;
|
||||
|
||||
memset(buf1, 0, 4);
|
||||
aptOpenSession();
|
||||
@ -1277,7 +1274,7 @@ Result APT_LaunchLibraryApplet(NS_APPID appID, Handle inhandle, u32 *parambuf, u
|
||||
aptOpenSession();
|
||||
ret=APT_IsRegistered(appID, &tmp);
|
||||
aptCloseSession();
|
||||
if(ret!=0)return ret;
|
||||
if(R_FAILED(ret))return ret;
|
||||
|
||||
if(tmp!=0)break;
|
||||
}
|
||||
@ -1319,7 +1316,7 @@ Result APT_PrepareToStartSystemApplet(NS_APPID appID)
|
||||
cmdbuf[1]=appID;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -1336,7 +1333,7 @@ Result APT_StartSystemApplet(NS_APPID appID, u32 bufSize, Handle applHandle, u8
|
||||
cmdbuf[6] = (u32)buf;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
@ -2,46 +2,33 @@
|
||||
#include <3ds/services/y2r.h>
|
||||
#include <3ds/srv.h>
|
||||
#include <3ds/svc.h>
|
||||
#include <3ds/synchronization.h>
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/result.h>
|
||||
|
||||
Handle camHandle;
|
||||
static bool initialized = false;
|
||||
static int camRefCount;
|
||||
|
||||
Result camInit(void) {
|
||||
Result ret = 0;
|
||||
|
||||
if (initialized) return 0;
|
||||
if (AtomicPostIncrement(&camRefCount)) return 0;
|
||||
|
||||
if (camHandle == 0)
|
||||
{
|
||||
ret = srvGetServiceHandle(&camHandle, "cam:u");
|
||||
if (ret < 0) return ret;
|
||||
}
|
||||
|
||||
if (R_SUCCEEDED(ret))
|
||||
{
|
||||
ret = CAMU_DriverInitialize();
|
||||
if (ret < 0) return ret;
|
||||
initialized = true;
|
||||
if (R_FAILED(ret)) svcCloseHandle(camHandle);
|
||||
}
|
||||
if (R_FAILED(ret)) AtomicDecrement(&camRefCount);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Result camExit(void) {
|
||||
Result ret = 0;
|
||||
|
||||
if (initialized)
|
||||
{
|
||||
ret = CAMU_DriverFinalize();
|
||||
if (ret < 0) return ret;
|
||||
}
|
||||
|
||||
if (camHandle != 0)
|
||||
{
|
||||
ret = svcCloseHandle(camHandle);
|
||||
if (ret < 0) return ret;
|
||||
camHandle = 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
void camExit(void) {
|
||||
if (AtomicDecrement(&camRefCount)) return;
|
||||
CAMU_DriverFinalize();
|
||||
svcCloseHandle(camHandle);
|
||||
}
|
||||
|
||||
Result CAMU_StartCapture(CAMU_Port port) {
|
||||
@ -50,7 +37,7 @@ Result CAMU_StartCapture(CAMU_Port port) {
|
||||
cmdbuf[0] = 0x00010040;
|
||||
cmdbuf[1] = port;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -60,7 +47,7 @@ Result CAMU_StopCapture(CAMU_Port port) {
|
||||
cmdbuf[0] = 0x00020040;
|
||||
cmdbuf[1] = port;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -70,7 +57,7 @@ Result CAMU_IsBusy(bool* busy, CAMU_Port port) {
|
||||
cmdbuf[0] = 0x00030040;
|
||||
cmdbuf[1] = port;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
*busy = (bool) cmdbuf[2];
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -81,7 +68,7 @@ Result CAMU_ClearBuffer(CAMU_Port port) {
|
||||
cmdbuf[0] = 0x00040040;
|
||||
cmdbuf[1] = port;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -91,7 +78,7 @@ Result CAMU_GetVsyncInterruptEvent(Handle* event, CAMU_Port port) {
|
||||
cmdbuf[0] = 0x00050040;
|
||||
cmdbuf[1] = port;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
*event = cmdbuf[3];
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -102,7 +89,7 @@ Result CAMU_GetBufferErrorInterruptEvent(Handle* event, CAMU_Port port) {
|
||||
cmdbuf[0] = 0x00060040;
|
||||
cmdbuf[1] = port;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
*event = cmdbuf[3];
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -118,7 +105,7 @@ Result CAMU_SetReceiving(Handle* event, void* dst, CAMU_Port port, u32 imageSize
|
||||
cmdbuf[5] = 0;
|
||||
cmdbuf[6] = 0xFFFF8001;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
*event = cmdbuf[3];
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -129,7 +116,7 @@ Result CAMU_IsFinishedReceiving(bool* finishedReceiving, CAMU_Port port) {
|
||||
cmdbuf[0] = 0x00080040;
|
||||
cmdbuf[1] = port;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
*finishedReceiving = (bool) cmdbuf[2];
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -143,7 +130,7 @@ Result CAMU_SetTransferLines(CAMU_Port port, s16 lines, s16 width, s16 height) {
|
||||
cmdbuf[3] = width;
|
||||
cmdbuf[4] = height;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -154,7 +141,7 @@ Result CAMU_GetMaxLines(s16* maxLines, s16 width, s16 height) {
|
||||
cmdbuf[1] = width;
|
||||
cmdbuf[2] = height;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
*maxLines = (s16) cmdbuf[2];
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -168,7 +155,7 @@ Result CAMU_SetTransferBytes(CAMU_Port port, u32 bytes, s16 width, s16 height) {
|
||||
cmdbuf[3] = width;
|
||||
cmdbuf[4] = height;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -178,7 +165,7 @@ Result CAMU_GetTransferBytes(u32* transferBytes, CAMU_Port port) {
|
||||
cmdbuf[0] = 0x000C0040;
|
||||
cmdbuf[1] = port;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
*transferBytes = cmdbuf[2];
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -190,7 +177,7 @@ Result CAMU_GetMaxBytes(u32* maxBytes, s16 width, s16 height) {
|
||||
cmdbuf[1] = width;
|
||||
cmdbuf[2] = height;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
*maxBytes = cmdbuf[2];
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -202,7 +189,7 @@ Result CAMU_SetTrimming(CAMU_Port port, bool trimming) {
|
||||
cmdbuf[1] = port;
|
||||
cmdbuf[2] = trimming;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -212,7 +199,7 @@ Result CAMU_IsTrimming(bool* trimming, CAMU_Port port) {
|
||||
cmdbuf[0] = 0x000F0040;
|
||||
cmdbuf[1] = port;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
*trimming = (bool) cmdbuf[2];
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -227,7 +214,7 @@ Result CAMU_SetTrimmingParams(CAMU_Port port, s16 xStart, s16 yStart, s16 xEnd,
|
||||
cmdbuf[4] = xEnd;
|
||||
cmdbuf[5] = yEnd;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -237,7 +224,7 @@ Result CAMU_GetTrimmingParams(s16* xStart, s16* yStart, s16* xEnd, s16* yEnd, CA
|
||||
cmdbuf[0] = 0x00110040;
|
||||
cmdbuf[1] = port;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
*xStart = (s16) cmdbuf[2];
|
||||
*yStart = (s16) cmdbuf[3];
|
||||
*xEnd = (s16) cmdbuf[4];
|
||||
@ -255,7 +242,7 @@ Result CAMU_SetTrimmingParamsCenter(CAMU_Port port, s16 trimWidth, s16 trimHeigh
|
||||
cmdbuf[4] = camWidth;
|
||||
cmdbuf[5] = camHeight;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -265,7 +252,7 @@ Result CAMU_Activate(CAMU_CameraSelect select) {
|
||||
cmdbuf[0] = 0x00130040;
|
||||
cmdbuf[1] = select;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -276,7 +263,7 @@ Result CAMU_SwitchContext(CAMU_CameraSelect select, CAMU_Context context) {
|
||||
cmdbuf[1] = select;
|
||||
cmdbuf[2] = context;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -287,7 +274,7 @@ Result CAMU_SetExposure(CAMU_CameraSelect select, s8 exposure) {
|
||||
cmdbuf[1] = select;
|
||||
cmdbuf[2] = exposure;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -298,7 +285,7 @@ Result CAMU_SetWhiteBalance(CAMU_CameraSelect select, CAMU_WhiteBalance whiteBal
|
||||
cmdbuf[1] = select;
|
||||
cmdbuf[2] = whiteBalance;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -309,7 +296,7 @@ Result CAMU_SetWhiteBalanceWithoutBaseUp(CAMU_CameraSelect select, CAMU_WhiteBal
|
||||
cmdbuf[1] = select;
|
||||
cmdbuf[2] = whiteBalance;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -320,7 +307,7 @@ Result CAMU_SetSharpness(CAMU_CameraSelect select, s8 sharpness) {
|
||||
cmdbuf[1] = select;
|
||||
cmdbuf[2] = sharpness;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -331,7 +318,7 @@ Result CAMU_SetAutoExposure(CAMU_CameraSelect select, bool autoExposure) {
|
||||
cmdbuf[1] = select;
|
||||
cmdbuf[2] = autoExposure;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -341,7 +328,7 @@ Result CAMU_IsAutoExposure(bool* autoExposure, CAMU_CameraSelect select) {
|
||||
cmdbuf[0] = 0x001A0040;
|
||||
cmdbuf[1] = select;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
*autoExposure = (bool) cmdbuf[2];
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -353,7 +340,7 @@ Result CAMU_SetAutoWhiteBalance(CAMU_CameraSelect select, bool autoWhiteBalance)
|
||||
cmdbuf[1] = select;
|
||||
cmdbuf[2] = autoWhiteBalance;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -363,7 +350,7 @@ Result CAMU_IsAutoWhiteBalance(bool* autoWhiteBalance, CAMU_CameraSelect select)
|
||||
cmdbuf[0] = 0x001C0040;
|
||||
cmdbuf[1] = select;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
*autoWhiteBalance = (bool) cmdbuf[2];
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -376,7 +363,7 @@ Result CAMU_FlipImage(CAMU_CameraSelect select, CAMU_Flip flip, CAMU_Context con
|
||||
cmdbuf[2] = flip;
|
||||
cmdbuf[3] = context;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -393,7 +380,7 @@ Result CAMU_SetDetailSize(CAMU_CameraSelect select, s16 width, s16 height, s16 c
|
||||
cmdbuf[7] = cropY1;
|
||||
cmdbuf[8] = context;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -405,7 +392,7 @@ Result CAMU_SetSize(CAMU_CameraSelect select, CAMU_Size size, CAMU_Context conte
|
||||
cmdbuf[2] = size;
|
||||
cmdbuf[3] = context;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -416,7 +403,7 @@ Result CAMU_SetFrameRate(CAMU_CameraSelect select, CAMU_FrameRate frameRate) {
|
||||
cmdbuf[1] = select;
|
||||
cmdbuf[2] = frameRate;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -427,7 +414,7 @@ Result CAMU_SetPhotoMode(CAMU_CameraSelect select, CAMU_PhotoMode photoMode) {
|
||||
cmdbuf[1] = select;
|
||||
cmdbuf[2] = photoMode;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -439,7 +426,7 @@ Result CAMU_SetEffect(CAMU_CameraSelect select, CAMU_Effect effect, CAMU_Context
|
||||
cmdbuf[2] = effect;
|
||||
cmdbuf[3] = context;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -450,7 +437,7 @@ Result CAMU_SetContrast(CAMU_CameraSelect select, CAMU_Contrast contrast) {
|
||||
cmdbuf[1] = select;
|
||||
cmdbuf[2] = contrast;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -461,7 +448,7 @@ Result CAMU_SetLensCorrection(CAMU_CameraSelect select, CAMU_LensCorrection lens
|
||||
cmdbuf[1] = select;
|
||||
cmdbuf[2] = lensCorrection;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -473,7 +460,7 @@ Result CAMU_SetOutputFormat(CAMU_CameraSelect select, CAMU_OutputFormat format,
|
||||
cmdbuf[2] = format;
|
||||
cmdbuf[3] = context;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -487,7 +474,7 @@ Result CAMU_SetAutoExposureWindow(CAMU_CameraSelect select, s16 x, s16 y, s16 wi
|
||||
cmdbuf[4] = width;
|
||||
cmdbuf[5] = height;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -501,7 +488,7 @@ Result CAMU_SetAutoWhiteBalanceWindow(CAMU_CameraSelect select, s16 x, s16 y, s1
|
||||
cmdbuf[4] = width;
|
||||
cmdbuf[5] = height;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -512,7 +499,7 @@ Result CAMU_SetNoiseFilter(CAMU_CameraSelect select, bool noiseFilter) {
|
||||
cmdbuf[1] = select;
|
||||
cmdbuf[2] = noiseFilter;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -523,7 +510,7 @@ Result CAMU_SynchronizeVsyncTiming(CAMU_CameraSelect select1, CAMU_CameraSelect
|
||||
cmdbuf[1] = select1;
|
||||
cmdbuf[2] = select2;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -536,7 +523,7 @@ Result CAMU_GetLatestVsyncTiming(s64* timing, CAMU_Port port, u32 past) {
|
||||
cmdbuf[49] = (past << 17) | 2;
|
||||
cmdbuf[50] = (u32) timing;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -545,7 +532,7 @@ Result CAMU_GetStereoCameraCalibrationData(CAMU_StereoCameraCalibrationData* dat
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = 0x002B0000;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
*data = *(CAMU_StereoCameraCalibrationData*) cmdbuf[2];
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -556,7 +543,7 @@ Result CAMU_SetStereoCameraCalibrationData(CAMU_StereoCameraCalibrationData data
|
||||
cmdbuf[0] = 0x002C0400;
|
||||
*(CAMU_StereoCameraCalibrationData*) cmdbuf[1] = data;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -568,7 +555,7 @@ Result CAMU_WriteRegisterI2c(CAMU_CameraSelect select, u16 addr, u16 data) {
|
||||
cmdbuf[2] = addr;
|
||||
cmdbuf[3] = data;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -580,7 +567,7 @@ Result CAMU_WriteMcuVariableI2c(CAMU_CameraSelect select, u16 addr, u16 data) {
|
||||
cmdbuf[2] = addr;
|
||||
cmdbuf[3] = data;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -591,7 +578,7 @@ Result CAMU_ReadRegisterI2cExclusive(u16* data, CAMU_CameraSelect select, u16 ad
|
||||
cmdbuf[1] = select;
|
||||
cmdbuf[2] = addr;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
*data = (u16) cmdbuf[2];
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -603,7 +590,7 @@ Result CAMU_ReadMcuVariableI2cExclusive(u16* data, CAMU_CameraSelect select, u16
|
||||
cmdbuf[1] = select;
|
||||
cmdbuf[2] = addr;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
*data = (u16) cmdbuf[2];
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -614,7 +601,7 @@ Result CAMU_SetImageQualityCalibrationData(CAMU_ImageQualityCalibrationData data
|
||||
cmdbuf[0] = 0x00310180;
|
||||
*(CAMU_ImageQualityCalibrationData*) cmdbuf[1] = data;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -623,7 +610,7 @@ Result CAMU_GetImageQualityCalibrationData(CAMU_ImageQualityCalibrationData* dat
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = 0x00320000;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
*data = *(CAMU_ImageQualityCalibrationData*) cmdbuf[2];
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -634,7 +621,7 @@ Result CAMU_SetPackageParameterWithoutContext(CAMU_PackageParameterCameraSelect
|
||||
cmdbuf[0] = 0x003302C0;
|
||||
*(CAMU_PackageParameterCameraSelect*) cmdbuf[1] = param;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -644,7 +631,7 @@ Result CAMU_SetPackageParameterWithContext(CAMU_PackageParameterContext param) {
|
||||
cmdbuf[0] = 0x00340140;
|
||||
*(CAMU_PackageParameterContext*) cmdbuf[1] = param;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -654,7 +641,7 @@ Result CAMU_SetPackageParameterWithContextDetail(CAMU_PackageParameterContextDet
|
||||
cmdbuf[0] = 0x003501C0;
|
||||
*(CAMU_PackageParameterContextDetail*) cmdbuf[1] = param;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -663,7 +650,7 @@ Result CAMU_GetSuitableY2rStandardCoefficient(Y2R_StandardCoefficient* coefficie
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = 0x00360000;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
*coefficient = (Y2R_StandardCoefficient) cmdbuf[2];
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -674,7 +661,7 @@ Result CAMU_PlayShutterSound(CAMU_ShutterSoundType sound) {
|
||||
cmdbuf[0] = 0x00380040;
|
||||
cmdbuf[1] = sound;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -683,7 +670,7 @@ Result CAMU_DriverInitialize(void) {
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = 0x00390000;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -692,7 +679,7 @@ Result CAMU_DriverFinalize(void) {
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = 0x003A0000;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -701,7 +688,7 @@ Result CAMU_GetActivatedCamera(CAMU_CameraSelect* select) {
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = 0x003B0000;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
*select = (CAMU_CameraSelect) cmdbuf[2];
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -711,7 +698,7 @@ Result CAMU_GetSleepCamera(CAMU_CameraSelect* select) {
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = 0x003C0000;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
*select = (CAMU_CameraSelect) cmdbuf[2];
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -722,7 +709,7 @@ Result CAMU_SetSleepCamera(CAMU_CameraSelect select) {
|
||||
cmdbuf[0] = 0x003D0040;
|
||||
cmdbuf[1] = select;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -732,7 +719,7 @@ Result CAMU_SetBrightnessSynchronization(bool brightnessSynchronization) {
|
||||
cmdbuf[0] = 0x003E0040;
|
||||
cmdbuf[1] = brightnessSynchronization;
|
||||
|
||||
if ((ret = svcSendSyncRequest(camHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(camHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,12 @@
|
||||
#include <stdlib.h>
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/result.h>
|
||||
#include <3ds/svc.h>
|
||||
#include <3ds/srv.h>
|
||||
#include <3ds/services/cfgnor.h>
|
||||
#include <3ds/ipc.h>
|
||||
|
||||
Handle CFGNOR_handle = 0;
|
||||
Handle CFGNOR_handle;
|
||||
|
||||
Result CFGNOR_Initialize(u8 value)
|
||||
{
|
||||
@ -13,12 +14,12 @@ Result CFGNOR_Initialize(u8 value)
|
||||
u32 *cmdbuf = getThreadCommandBuffer();
|
||||
|
||||
ret = srvGetServiceHandle(&CFGNOR_handle, "cfg:nor");
|
||||
if(ret!=0)return ret;
|
||||
if(R_FAILED(ret))return ret;
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x1,1,0); // 0x10040
|
||||
cmdbuf[1] = (u32)value;
|
||||
|
||||
if((ret = svcSendSyncRequest(CFGNOR_handle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(CFGNOR_handle)))return ret;
|
||||
|
||||
ret = (Result)cmdbuf[1];
|
||||
return ret;
|
||||
@ -31,7 +32,7 @@ Result CFGNOR_Shutdown(void)
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x2,0,0); // 0x20000
|
||||
|
||||
if((ret = svcSendSyncRequest(CFGNOR_handle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(CFGNOR_handle)))return ret;
|
||||
ret = (Result)cmdbuf[1];
|
||||
|
||||
svcCloseHandle(CFGNOR_handle);
|
||||
@ -51,7 +52,7 @@ Result CFGNOR_ReadData(u32 offset, u32 *buf, u32 size)
|
||||
cmdbuf[3] = IPC_Desc_Buffer(size,IPC_BUFFER_W);
|
||||
cmdbuf[4] = (u32)buf;
|
||||
|
||||
if((ret = svcSendSyncRequest(CFGNOR_handle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(CFGNOR_handle)))return ret;
|
||||
|
||||
ret = (Result)cmdbuf[1];
|
||||
return ret;
|
||||
@ -68,7 +69,7 @@ Result CFGNOR_WriteData(u32 offset, u32 *buf, u32 size)
|
||||
cmdbuf[3] = IPC_Desc_Buffer(size,IPC_BUFFER_R);
|
||||
cmdbuf[4] = (u32)buf;
|
||||
|
||||
if((ret = svcSendSyncRequest(CFGNOR_handle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(CFGNOR_handle)))return ret;
|
||||
|
||||
ret = (Result)cmdbuf[1];
|
||||
return ret;
|
||||
@ -85,7 +86,7 @@ Result CFGNOR_DumpFlash(u32 *buf, u32 size)
|
||||
if(size-pos < chunksize)chunksize = size-pos;
|
||||
|
||||
ret = CFGNOR_ReadData(pos, &buf[pos>>2], chunksize);
|
||||
if(ret!=0)break;
|
||||
if(R_FAILED(ret))break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -1,30 +1,34 @@
|
||||
#include <stdlib.h>
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/result.h>
|
||||
#include <3ds/svc.h>
|
||||
#include <3ds/srv.h>
|
||||
#include <3ds/synchronization.h>
|
||||
#include <3ds/services/cfgu.h>
|
||||
#include <3ds/ipc.h>
|
||||
|
||||
static Handle CFGU_handle = 0;
|
||||
static Handle CFGU_handle;
|
||||
static int CFGU_refCount;
|
||||
|
||||
Result initCfgu()
|
||||
Result cfguInit(void)
|
||||
{
|
||||
Result ret;
|
||||
|
||||
if (AtomicPostIncrement(&CFGU_refCount)) return 0;
|
||||
|
||||
// cfg:i has the most commands, then cfg:s, then cfg:u
|
||||
ret = srvGetServiceHandle(&CFGU_handle, "cfg:i");
|
||||
if(ret) ret = srvGetServiceHandle(&CFGU_handle, "cfg:s");
|
||||
if(ret) ret = srvGetServiceHandle(&CFGU_handle, "cfg:u");
|
||||
if(R_FAILED(ret)) ret = srvGetServiceHandle(&CFGU_handle, "cfg:s");
|
||||
if(R_FAILED(ret)) ret = srvGetServiceHandle(&CFGU_handle, "cfg:u");
|
||||
if(R_FAILED(ret)) AtomicDecrement(&CFGU_refCount);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Result exitCfgu()
|
||||
void cfguExit(void)
|
||||
{
|
||||
Result ret = svcCloseHandle(CFGU_handle);
|
||||
CFGU_handle = 0;
|
||||
|
||||
return ret;
|
||||
if (AtomicDecrement(&CFGU_refCount)) return;
|
||||
svcCloseHandle(CFGU_handle);
|
||||
}
|
||||
|
||||
Result CFGU_SecureInfoGetRegion(u8* region)
|
||||
@ -34,7 +38,7 @@ Result CFGU_SecureInfoGetRegion(u8* region)
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x2,0,0); // 0x20000
|
||||
|
||||
if((ret = svcSendSyncRequest(CFGU_handle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(CFGU_handle)))return ret;
|
||||
|
||||
*region = (u8)cmdbuf[2];
|
||||
|
||||
@ -49,7 +53,7 @@ Result CFGU_GenHashConsoleUnique(u32 appIDSalt, u64* hash)
|
||||
cmdbuf[0] = IPC_MakeHeader(0x3,1,0); // 0x30040
|
||||
cmdbuf[1] = appIDSalt;
|
||||
|
||||
if((ret = svcSendSyncRequest(CFGU_handle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(CFGU_handle)))return ret;
|
||||
|
||||
*hash = (u64)cmdbuf[2];
|
||||
*hash |= ((u64)cmdbuf[3])<<32;
|
||||
@ -64,7 +68,7 @@ Result CFGU_GetRegionCanadaUSA(u8* value)
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x4,0,0); // 0x40000
|
||||
|
||||
if((ret = svcSendSyncRequest(CFGU_handle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(CFGU_handle)))return ret;
|
||||
|
||||
*value = (u8)cmdbuf[2];
|
||||
|
||||
@ -78,7 +82,7 @@ Result CFGU_GetSystemModel(u8* model)
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x5,0,0); // 0x50000
|
||||
|
||||
if((ret = svcSendSyncRequest(CFGU_handle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(CFGU_handle)))return ret;
|
||||
|
||||
*model = (u8)cmdbuf[2];
|
||||
|
||||
@ -92,7 +96,7 @@ Result CFGU_GetModelNintendo2DS(u8* value)
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x6,0,0); // 0x60000
|
||||
|
||||
if((ret = svcSendSyncRequest(CFGU_handle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(CFGU_handle)))return ret;
|
||||
|
||||
*value = (u8)cmdbuf[2];
|
||||
|
||||
@ -107,7 +111,7 @@ Result CFGU_GetCountryCodeString(u16 code, u16* string)
|
||||
cmdbuf[0] = IPC_MakeHeader(0x9,1,0); // 0x90040
|
||||
cmdbuf[1] = (u32)code;
|
||||
|
||||
if((ret = svcSendSyncRequest(CFGU_handle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(CFGU_handle)))return ret;
|
||||
|
||||
*string = (u16)cmdbuf[2];
|
||||
|
||||
@ -122,7 +126,7 @@ Result CFGU_GetCountryCodeID(u16 string, u16* code)
|
||||
cmdbuf[0] = IPC_MakeHeader(0xA,1,0); // 0xA0040
|
||||
cmdbuf[1] = (u32)string;
|
||||
|
||||
if((ret = svcSendSyncRequest(CFGU_handle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(CFGU_handle)))return ret;
|
||||
|
||||
*code = (u16)cmdbuf[2];
|
||||
|
||||
@ -142,7 +146,7 @@ Result CFGU_GetConfigInfoBlk2(u32 size, u32 blkID, u8* outData)
|
||||
cmdbuf[3] = IPC_Desc_Buffer(size,IPC_BUFFER_W);
|
||||
cmdbuf[4] = (u32)outData;
|
||||
|
||||
if((ret = svcSendSyncRequest(CFGU_handle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(CFGU_handle)))return ret;
|
||||
|
||||
return (Result)cmdbuf[1];
|
||||
}
|
||||
|
@ -1,27 +1,30 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/result.h>
|
||||
#include <3ds/svc.h>
|
||||
#include <3ds/srv.h>
|
||||
#include <3ds/mappable.h>
|
||||
#include <3ds/os.h>
|
||||
#include <3ds/services/csnd.h>
|
||||
#include <3ds/ipc.h>
|
||||
#include <3ds/synchronization.h>
|
||||
|
||||
// See here regarding CSND shared-mem commands, etc: http://3dbrew.org/wiki/CSND_Shared_Memory
|
||||
|
||||
vu32* csndSharedMem = NULL;
|
||||
vu32* csndSharedMem;
|
||||
u32 csndSharedMemSize;
|
||||
u32 csndChannels = 0;
|
||||
u32 csndChannels;
|
||||
u32 csndOffsets[4];
|
||||
|
||||
static Handle csndHandle = 0;
|
||||
static Handle csndMutex = 0;
|
||||
static Handle csndSharedMemBlock = 0;
|
||||
static Handle csndHandle;
|
||||
static Handle csndMutex;
|
||||
static Handle csndSharedMemBlock;
|
||||
|
||||
static int csndRefCount;
|
||||
static u32 csndCmdBlockSize = 0x2000;
|
||||
static u32 csndCmdStartOff = 0;
|
||||
static u32 csndCmdCurOff = 0;
|
||||
static u32 csndCmdStartOff;
|
||||
static u32 csndCmdCurOff;
|
||||
|
||||
static Result CSND_Initialize(void)
|
||||
{
|
||||
@ -32,7 +35,7 @@ static Result CSND_Initialize(void)
|
||||
cmdbuf[1] = csndSharedMemSize;
|
||||
memcpy(&cmdbuf[2], &csndOffsets[0], 4*sizeof(u32));
|
||||
|
||||
if((ret = svcSendSyncRequest(csndHandle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(csndHandle)))return ret;
|
||||
|
||||
csndMutex = cmdbuf[3];
|
||||
csndSharedMemBlock = cmdbuf[4];
|
||||
@ -47,7 +50,7 @@ static Result CSND_Shutdown()
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x2,0,0); // 0x20000
|
||||
|
||||
if((ret = svcSendSyncRequest(csndHandle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(csndHandle)))return ret;
|
||||
|
||||
return (Result)cmdbuf[1];
|
||||
}
|
||||
@ -59,7 +62,7 @@ static Result CSND_AcquireSoundChannels(u32* channelMask)
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x5,0,0); // 0x50000
|
||||
|
||||
if((ret = svcSendSyncRequest(csndHandle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(csndHandle)))return ret;
|
||||
|
||||
*channelMask = cmdbuf[2];
|
||||
|
||||
@ -73,7 +76,7 @@ static Result CSND_ReleaseSoundChannels(void)
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x6,0,0); // 0x60000
|
||||
|
||||
if((ret = svcSendSyncRequest(csndHandle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(csndHandle)))return ret;
|
||||
|
||||
return (Result)cmdbuf[1];
|
||||
}
|
||||
@ -85,7 +88,7 @@ Result CSND_AcquireCapUnit(u32* capUnit)
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x7,0,0); // 0x70000
|
||||
|
||||
if((ret = svcSendSyncRequest(csndHandle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(csndHandle)))return ret;
|
||||
|
||||
*capUnit = cmdbuf[2];
|
||||
|
||||
@ -100,7 +103,7 @@ Result CSND_ReleaseCapUnit(u32 capUnit)
|
||||
cmdbuf[0] = IPC_MakeHeader(0x8,1,0); // 0x80040
|
||||
cmdbuf[1] = capUnit;
|
||||
|
||||
if((ret = svcSendSyncRequest(csndHandle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(csndHandle)))return ret;
|
||||
|
||||
return (Result)cmdbuf[1];
|
||||
}
|
||||
@ -112,7 +115,7 @@ Result CSND_Reset(void)
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0xC,0,0); // 0xC0000
|
||||
|
||||
if((ret = svcSendSyncRequest(csndHandle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(csndHandle)))return ret;
|
||||
|
||||
return (Result)cmdbuf[1];
|
||||
}
|
||||
@ -121,10 +124,10 @@ Result csndInit(void)
|
||||
{
|
||||
Result ret=0;
|
||||
|
||||
// TODO: proper error handling!
|
||||
if (AtomicPostIncrement(&csndRefCount)) return ret;
|
||||
|
||||
ret = srvGetServiceHandle(&csndHandle, "csnd:SND");
|
||||
if (ret != 0) return ret;
|
||||
if (R_FAILED(ret)) goto cleanup0;
|
||||
|
||||
// Calculate offsets and sizes required by the CSND module
|
||||
csndOffsets[0] = csndCmdBlockSize; // Offset to DSP semaphore and irq disable flags
|
||||
@ -134,7 +137,7 @@ Result csndInit(void)
|
||||
csndSharedMemSize = csndOffsets[3] + 0x3C; // Total size of the CSND shared memory
|
||||
|
||||
ret = CSND_Initialize();
|
||||
if (ret != 0) goto cleanup1;
|
||||
if (R_FAILED(ret)) goto cleanup1;
|
||||
|
||||
csndSharedMem = (vu32*)mappableAlloc(csndSharedMemSize);
|
||||
if(!csndSharedMem)
|
||||
@ -144,12 +147,12 @@ Result csndInit(void)
|
||||
}
|
||||
|
||||
ret = svcMapMemoryBlock(csndSharedMemBlock, (u32)csndSharedMem, 3, 0x10000000);
|
||||
if (ret != 0) goto cleanup2;
|
||||
if (R_FAILED(ret)) goto cleanup2;
|
||||
|
||||
memset((void*)csndSharedMem, 0, csndSharedMemSize);
|
||||
|
||||
ret = CSND_AcquireSoundChannels(&csndChannels);
|
||||
if (!ret) return 0;
|
||||
if (R_FAILED(ret)) return 0;
|
||||
|
||||
cleanup2:
|
||||
svcCloseHandle(csndSharedMemBlock);
|
||||
@ -160,23 +163,22 @@ cleanup2:
|
||||
}
|
||||
cleanup1:
|
||||
svcCloseHandle(csndHandle);
|
||||
cleanup0:
|
||||
AtomicDecrement(&csndRefCount);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Result csndExit(void)
|
||||
void csndExit(void)
|
||||
{
|
||||
Result ret;
|
||||
if (AtomicDecrement(&csndRefCount)) return;
|
||||
|
||||
//ret = CSND_Reset();
|
||||
//if (ret != 0) return ret;
|
||||
|
||||
ret = CSND_ReleaseSoundChannels();
|
||||
if (ret != 0) return ret;
|
||||
//CSND_Reset();
|
||||
CSND_ReleaseSoundChannels();
|
||||
|
||||
svcUnmapMemoryBlock(csndSharedMemBlock, (u32)csndSharedMem);
|
||||
svcCloseHandle(csndSharedMemBlock);
|
||||
|
||||
ret = CSND_Shutdown();
|
||||
CSND_Shutdown();
|
||||
svcCloseHandle(csndHandle);
|
||||
|
||||
if(csndSharedMem != NULL)
|
||||
@ -184,8 +186,6 @@ Result csndExit(void)
|
||||
mappableFree((void*) csndSharedMem);
|
||||
csndSharedMem = NULL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static Result CSND_ExecuteCommands(u32 offset)
|
||||
@ -196,7 +196,7 @@ static Result CSND_ExecuteCommands(u32 offset)
|
||||
cmdbuf[0] = IPC_MakeHeader(0x3,1,0); // 0x30040
|
||||
cmdbuf[1] = offset;
|
||||
|
||||
if((ret = svcSendSyncRequest(csndHandle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(csndHandle)))return ret;
|
||||
|
||||
return (Result)cmdbuf[1];
|
||||
}
|
||||
@ -253,7 +253,7 @@ Result csndExecCmds(bool waitDone)
|
||||
|
||||
ret = CSND_ExecuteCommands(csndCmdStartOff);
|
||||
csndCmdStartOff = csndCmdCurOff;
|
||||
if (ret != 0) return ret;
|
||||
if (R_FAILED(ret)) return ret;
|
||||
|
||||
// FIXME: This is a really ugly busy waiting loop!
|
||||
while (waitDone && *flag == 0);
|
||||
@ -535,7 +535,7 @@ Result csndGetState(u32 channel, CSND_ChnInfo* out)
|
||||
Result ret = 0;
|
||||
channel = chnGetSharedMemIdx(channel);
|
||||
|
||||
if ((ret = CSND_UpdateInfo(true)) != 0)return ret;
|
||||
if (R_FAILED(ret = CSND_UpdateInfo(true)))return ret;
|
||||
|
||||
memcpy(out, (const void*)&csndSharedMem[(csndOffsets[1] + channel*0xc) >> 2], 0xc);
|
||||
//out[2] -= 0x0c000000;
|
||||
@ -549,7 +549,7 @@ Result csndIsPlaying(u32 channel, u8* status)
|
||||
CSND_ChnInfo entry;
|
||||
|
||||
ret = csndGetState(channel, &entry);
|
||||
if(ret!=0)return ret;
|
||||
if(R_FAILED(ret))return ret;
|
||||
|
||||
*status = entry.active;
|
||||
|
||||
|
@ -1,35 +1,31 @@
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/result.h>
|
||||
#include <3ds/svc.h>
|
||||
#include <3ds/srv.h>
|
||||
#include <3ds/ipc.h>
|
||||
#include <3ds/synchronization.h>
|
||||
#include <3ds/services/dsp.h>
|
||||
|
||||
static Handle dspHandle = 0;
|
||||
static Handle dspHandle;
|
||||
static int dspRefCount;
|
||||
|
||||
Result dspInit(void)
|
||||
{
|
||||
Result ret = 0;
|
||||
if (dspHandle == 0)
|
||||
{
|
||||
|
||||
if (AtomicPostIncrement(&dspRefCount)) return 0;
|
||||
|
||||
ret = srvGetServiceHandle(&dspHandle, "dsp::DSP");
|
||||
if (ret < 0) return ret;
|
||||
}
|
||||
DSP_UnloadComponent();
|
||||
return 0;
|
||||
if (R_SUCCEEDED(ret)) DSP_UnloadComponent();
|
||||
else AtomicDecrement(&dspRefCount);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Result dspExit(void)
|
||||
void dspExit(void)
|
||||
{
|
||||
Result ret = 0;
|
||||
//No need to call unload, it will be done automatically by closing the handle
|
||||
if (dspHandle != 0)
|
||||
{
|
||||
ret = svcCloseHandle(dspHandle);
|
||||
if (ret < 0) return ret;
|
||||
dspHandle = 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
if (AtomicDecrement(&dspRefCount)) return;
|
||||
svcCloseHandle(dspHandle);
|
||||
}
|
||||
|
||||
Result DSP_GetHeadphoneStatus(bool* is_inserted)
|
||||
@ -37,7 +33,7 @@ Result DSP_GetHeadphoneStatus(bool* is_inserted)
|
||||
Result ret = 0;
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(0x1F,0,0);
|
||||
if ((ret = svcSendSyncRequest(dspHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(dspHandle))) return ret;
|
||||
*is_inserted = cmdbuf[2] & 0xFF;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -51,7 +47,7 @@ Result DSP_FlushDataCache(const void* address, u32 size)
|
||||
cmdbuf[2] = size;
|
||||
cmdbuf[3] = IPC_Desc_SharedHandles(1);
|
||||
cmdbuf[4] = CUR_PROCESS_HANDLE;
|
||||
if ((ret = svcSendSyncRequest(dspHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(dspHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -64,7 +60,7 @@ Result DSP_InvalidateDataCache(const void* address, u32 size)
|
||||
cmdbuf[2] = size;
|
||||
cmdbuf[3] = IPC_Desc_SharedHandles(1);
|
||||
cmdbuf[4] = CUR_PROCESS_HANDLE;
|
||||
if ((ret = svcSendSyncRequest(dspHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(dspHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -74,7 +70,7 @@ Result DSP_SetSemaphore(u16 value)
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(0x7,1,0);
|
||||
cmdbuf[1] = value;
|
||||
if ((ret = svcSendSyncRequest(dspHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(dspHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -84,7 +80,7 @@ Result DSP_SetSemaphoreMask(u16 mask)
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(0x17,1,0);
|
||||
cmdbuf[1] = mask;
|
||||
if ((ret = svcSendSyncRequest(dspHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(dspHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -93,7 +89,7 @@ Result DSP_GetSemaphoreHandle(Handle* semaphore)
|
||||
Result ret = 0;
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(0x16,0,0);
|
||||
if ((ret = svcSendSyncRequest(dspHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(dspHandle))) return ret;
|
||||
*semaphore = cmdbuf[3];
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -108,7 +104,7 @@ Result DSP_LoadComponent(const void* component, u32 size, u16 prog_mask, u16 dat
|
||||
cmdbuf[3] = data_mask;
|
||||
cmdbuf[4] = IPC_Desc_Buffer(size,IPC_BUFFER_R);
|
||||
cmdbuf[5] = (u32) component;
|
||||
if ((ret = svcSendSyncRequest(dspHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(dspHandle))) return ret;
|
||||
*is_loaded = cmdbuf[2] & 0xFF;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -118,7 +114,7 @@ Result DSP_UnloadComponent(void)
|
||||
Result ret = 0;
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(0x12,0,0);
|
||||
if ((ret = svcSendSyncRequest(dspHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(dspHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -131,7 +127,7 @@ Result DSP_RegisterInterruptEvents(Handle handle, u32 interrupt, u32 channel)
|
||||
cmdbuf[2] = channel;
|
||||
cmdbuf[3] = IPC_Desc_SharedHandles(1);
|
||||
cmdbuf[4] = handle;
|
||||
if ((ret = svcSendSyncRequest(dspHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(dspHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -152,7 +148,7 @@ Result DSP_ReadPipeIfPossible(u32 channel, u32 peer, void* buffer, u16 length, u
|
||||
staticbufs[0] = IPC_Desc_StaticBuffer(length,0);
|
||||
staticbufs[1] = (u32)buffer;
|
||||
|
||||
if ((ret = svcSendSyncRequest(dspHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(dspHandle))) return ret;
|
||||
|
||||
staticbufs[0] = saved1;
|
||||
staticbufs[1] = saved2;
|
||||
@ -171,7 +167,7 @@ Result DSP_WriteProcessPipe(u32 channel, const void* buffer, u32 length)
|
||||
cmdbuf[2] = length;
|
||||
cmdbuf[3] = IPC_Desc_StaticBuffer(length,1);
|
||||
cmdbuf[4] = (u32)buffer;
|
||||
if ((ret = svcSendSyncRequest(dspHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(dspHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -181,7 +177,7 @@ Result DSP_ConvertProcessAddressFromDspDram(u32 dsp_address, u32* arm_address)
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(0xC,1,0);
|
||||
cmdbuf[1] = dsp_address;
|
||||
if ((ret = svcSendSyncRequest(dspHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(dspHandle))) return ret;
|
||||
*arm_address = cmdbuf[2];
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -192,7 +188,7 @@ Result DSP_RecvData(u16 regNo, u16* value)
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(0x1,1,0);
|
||||
cmdbuf[1] = regNo;
|
||||
if ((ret = svcSendSyncRequest(dspHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(dspHandle))) return ret;
|
||||
*value = cmdbuf[2] & 0xFFFF;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -203,7 +199,7 @@ Result DSP_RecvDataIsReady(u16 regNo, bool* is_ready)
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(0x2,1,0);
|
||||
cmdbuf[1] = regNo;
|
||||
if ((ret = svcSendSyncRequest(dspHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(dspHandle))) return ret;
|
||||
*is_ready = cmdbuf[2] & 0xFF;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -217,7 +213,7 @@ Result DSP_SendData(u16 regNo, u16 value)
|
||||
cmdbuf[0] = IPC_MakeHeader(0x3,2,0);
|
||||
cmdbuf[1] = regNo;
|
||||
cmdbuf[2] = value;
|
||||
if ((ret = svcSendSyncRequest(dspHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(dspHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -227,7 +223,7 @@ Result DSP_SendDataIsEmpty(u16 regNo, bool* is_empty)
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(0x4,1,0);
|
||||
cmdbuf[1] = regNo;
|
||||
if ((ret = svcSendSyncRequest(dspHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(dspHandle))) return ret;
|
||||
*is_empty = cmdbuf[2] & 0xFF;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
#include <string.h>
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/result.h>
|
||||
#include <3ds/svc.h>
|
||||
#include <3ds/srv.h>
|
||||
#include <3ds/synchronization.h>
|
||||
#include <3ds/services/fs.h>
|
||||
#include <3ds/ipc.h>
|
||||
|
||||
@ -34,40 +36,33 @@ FS_makePath(FS_pathType type,
|
||||
return (FS_path){type, strlen(path)+1, (const u8*)path};
|
||||
}
|
||||
|
||||
static int fsRefCount;
|
||||
|
||||
/*! Initialize FS service
|
||||
*
|
||||
* @returns error
|
||||
*/
|
||||
|
||||
static bool fsInitialised = false;
|
||||
|
||||
Result
|
||||
fsInit(void)
|
||||
Result fsInit(void)
|
||||
{
|
||||
Result ret = 0;
|
||||
|
||||
if (fsInitialised) return ret;
|
||||
|
||||
if((ret=srvGetServiceHandle(&fsuHandle, "fs:USER"))!=0)return ret;
|
||||
if(__get_handle_from_list("fs:USER")==0)ret=FSUSER_Initialize(fsuHandle);
|
||||
|
||||
fsInitialised = true;
|
||||
if (AtomicPostIncrement(&fsRefCount)) return 0;
|
||||
|
||||
ret = srvGetServiceHandle(&fsuHandle, "fs:USER");
|
||||
if (R_SUCCEEDED(ret) && __get_handle_from_list("fs:USER")==0)
|
||||
{
|
||||
ret = FSUSER_Initialize(fsuHandle);
|
||||
if (R_FAILED(ret)) svcCloseHandle(fsuHandle);
|
||||
}
|
||||
if (R_FAILED(ret)) AtomicDecrement(&fsRefCount);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*! Deinitialize FS service
|
||||
*
|
||||
* @returns error
|
||||
*/
|
||||
Result
|
||||
fsExit(void)
|
||||
/// Deinitialize FS service
|
||||
void fsExit(void)
|
||||
{
|
||||
if (!fsInitialised) return 0;
|
||||
|
||||
fsInitialised = false;
|
||||
|
||||
return svcCloseHandle(fsuHandle);
|
||||
if (AtomicDecrement(&fsRefCount)) return;
|
||||
svcCloseHandle(fsuHandle);
|
||||
}
|
||||
|
||||
/*! Gets the fsuser service session handle.
|
||||
@ -110,7 +105,7 @@ FSUSER_Initialize(Handle handle)
|
||||
cmdbuf[1] = IPC_Desc_CurProcessHandle();
|
||||
|
||||
Result ret = 0;
|
||||
if((ret = svcSendSyncRequest(handle)))
|
||||
if(R_FAILED(ret = svcSendSyncRequest(handle)))
|
||||
return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
@ -178,7 +173,7 @@ FSUSER_OpenFile(Handle *out,
|
||||
cmdbuf[9] = (u32)fileLowPath.data;
|
||||
|
||||
Result ret = 0;
|
||||
if((ret = svcSendSyncRequest(fsuHandle)))
|
||||
if(R_FAILED(ret = svcSendSyncRequest(fsuHandle)))
|
||||
return ret;
|
||||
|
||||
if(out)
|
||||
@ -255,7 +250,7 @@ FSUSER_OpenFileDirectly(Handle *out,
|
||||
cmdbuf[12] = (u32)fileLowPath.data;
|
||||
|
||||
Result ret = 0;
|
||||
if((ret = svcSendSyncRequest(fsuHandle)))
|
||||
if(R_FAILED(ret = svcSendSyncRequest(fsuHandle)))
|
||||
return ret;
|
||||
|
||||
if(out)
|
||||
@ -309,7 +304,7 @@ FSUSER_DeleteFile(FS_archive archive,
|
||||
cmdbuf[7] = (u32)fileLowPath.data;
|
||||
|
||||
Result ret = 0;
|
||||
if((ret = svcSendSyncRequest(fsuHandle)))
|
||||
if(R_FAILED(ret = svcSendSyncRequest(fsuHandle)))
|
||||
return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
@ -376,7 +371,7 @@ FSUSER_RenameFile(FS_archive srcArchive,
|
||||
cmdbuf[13] = (u32)destFileLowPath.data;
|
||||
|
||||
Result ret = 0;
|
||||
if((ret = svcSendSyncRequest(fsuHandle)))
|
||||
if(R_FAILED(ret = svcSendSyncRequest(fsuHandle)))
|
||||
return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
@ -427,7 +422,7 @@ FSUSER_DeleteDirectory(FS_archive archive,
|
||||
cmdbuf[7] = (u32)dirLowPath.data;
|
||||
|
||||
Result ret = 0;
|
||||
if((ret = svcSendSyncRequest(fsuHandle)))
|
||||
if(R_FAILED(ret = svcSendSyncRequest(fsuHandle)))
|
||||
return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
@ -478,7 +473,7 @@ FSUSER_DeleteDirectoryRecursively(FS_archive archive,
|
||||
cmdbuf[7] = (u32)dirLowPath.data;
|
||||
|
||||
Result ret = 0;
|
||||
if((ret = svcSendSyncRequest(fsuHandle)))
|
||||
if(R_FAILED(ret = svcSendSyncRequest(fsuHandle)))
|
||||
return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
@ -537,7 +532,7 @@ FSUSER_CreateFile(FS_archive archive,
|
||||
cmdbuf[10] = (u32)fileLowPath.data;
|
||||
|
||||
Result ret = 0;
|
||||
if((ret = svcSendSyncRequest(fsuHandle)))
|
||||
if(R_FAILED(ret = svcSendSyncRequest(fsuHandle)))
|
||||
return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
@ -590,7 +585,7 @@ FSUSER_CreateDirectory(FS_archive archive,
|
||||
cmdbuf[8] = (u32)dirLowPath.data;
|
||||
|
||||
Result ret = 0;
|
||||
if((ret = svcSendSyncRequest(fsuHandle)))
|
||||
if(R_FAILED(ret = svcSendSyncRequest(fsuHandle)))
|
||||
return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
@ -657,7 +652,7 @@ FSUSER_RenameDirectory(FS_archive srcArchive,
|
||||
cmdbuf[13] = (u32)destDirLowPath.data;
|
||||
|
||||
Result ret = 0;
|
||||
if((ret = svcSendSyncRequest(fsuHandle)))
|
||||
if(R_FAILED(ret = svcSendSyncRequest(fsuHandle)))
|
||||
return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
@ -709,7 +704,7 @@ FSUSER_OpenDirectory(Handle *out,
|
||||
cmdbuf[6] = (u32)dirLowPath.data;
|
||||
|
||||
Result ret = 0;
|
||||
if((ret = svcSendSyncRequest(fsuHandle)))
|
||||
if(R_FAILED(ret = svcSendSyncRequest(fsuHandle)))
|
||||
return ret;
|
||||
|
||||
if(out)
|
||||
@ -762,7 +757,7 @@ FSUSER_OpenArchive(FS_archive *archive)
|
||||
cmdbuf[5] = (u32)archive->lowPath.data;
|
||||
|
||||
Result ret = 0;
|
||||
if((ret = svcSendSyncRequest(fsuHandle)))
|
||||
if(R_FAILED(ret = svcSendSyncRequest(fsuHandle)))
|
||||
return ret;
|
||||
|
||||
archive->handleLow = cmdbuf[2];
|
||||
@ -808,7 +803,7 @@ FSUSER_CloseArchive(FS_archive *archive)
|
||||
cmdbuf[2] = archive->handleHigh;
|
||||
|
||||
Result ret = 0;
|
||||
if((ret = svcSendSyncRequest(fsuHandle)))
|
||||
if(R_FAILED(ret = svcSendSyncRequest(fsuHandle)))
|
||||
return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
@ -853,7 +848,7 @@ FSUSER_GetSdmcArchiveResource(u32 *sectorSize,
|
||||
cmdbuf[0] = IPC_MakeHeader(0x814,0,0); // 0x8140000
|
||||
|
||||
Result ret = 0;
|
||||
if((ret = svcSendSyncRequest(fsuHandle)))
|
||||
if(R_FAILED(ret = svcSendSyncRequest(fsuHandle)))
|
||||
return ret;
|
||||
|
||||
if(sectorSize)
|
||||
@ -910,7 +905,7 @@ FSUSER_GetNandArchiveResource(u32 *sectorSize,
|
||||
cmdbuf[0] = IPC_MakeHeader(0x815,0,0); // 0x8150000
|
||||
|
||||
Result ret = 0;
|
||||
if((ret = svcSendSyncRequest(fsuHandle)))
|
||||
if(R_FAILED(ret = svcSendSyncRequest(fsuHandle)))
|
||||
return ret;
|
||||
|
||||
if(sectorSize)
|
||||
@ -958,7 +953,7 @@ FSUSER_IsSdmcDetected(u8 *detected)
|
||||
cmdbuf[0] = IPC_MakeHeader(0x817,0,0); // 0x8170000
|
||||
|
||||
Result ret = 0;
|
||||
if((ret = svcSendSyncRequest(fsuHandle)))
|
||||
if(R_FAILED(ret = svcSendSyncRequest(fsuHandle)))
|
||||
return ret;
|
||||
|
||||
if(detected)
|
||||
@ -996,7 +991,7 @@ FSUSER_GetMediaType(u8* mediatype)
|
||||
cmdbuf[0] = IPC_MakeHeader(0x868,0,0); // 0x8680000
|
||||
|
||||
Result ret = 0;
|
||||
if((ret = svcSendSyncRequest(fsuHandle)))
|
||||
if(R_FAILED(ret = svcSendSyncRequest(fsuHandle)))
|
||||
return ret;
|
||||
|
||||
if(mediatype)
|
||||
@ -1035,7 +1030,7 @@ FSUSER_IsSdmcWritable(u8 *writable)
|
||||
cmdbuf[0] = IPC_MakeHeader(0x818,0,0); // 0x8180000
|
||||
|
||||
Result ret = 0;
|
||||
if((ret = svcSendSyncRequest(fsuHandle)))
|
||||
if(R_FAILED(ret = svcSendSyncRequest(fsuHandle)))
|
||||
return ret;
|
||||
|
||||
if(writable)
|
||||
@ -1073,11 +1068,11 @@ FSFILE_Close(Handle handle)
|
||||
cmdbuf[0] = IPC_MakeHeader(0x808,0,0); // 0x8080000
|
||||
|
||||
Result ret = 0;
|
||||
if((ret = svcSendSyncRequest(handle)))
|
||||
if(R_FAILED(ret = svcSendSyncRequest(handle)))
|
||||
return ret;
|
||||
|
||||
ret = cmdbuf[1];
|
||||
if(!ret)ret = svcCloseHandle(handle);
|
||||
if(R_SUCCEEDED(ret))ret = svcCloseHandle(handle);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -1130,7 +1125,7 @@ FSFILE_Read(Handle handle,
|
||||
cmdbuf[5] = (u32)buffer;
|
||||
|
||||
Result ret = 0;
|
||||
if((ret = svcSendSyncRequest(handle)))
|
||||
if(R_FAILED(ret = svcSendSyncRequest(handle)))
|
||||
return ret;
|
||||
|
||||
if(bytesRead)
|
||||
@ -1199,7 +1194,7 @@ FSFILE_Write(Handle handle,
|
||||
cmdbuf[6] = (u32)buffer;
|
||||
|
||||
Result ret = 0;
|
||||
if((ret = svcSendSyncRequest(handle)))
|
||||
if(R_FAILED(ret = svcSendSyncRequest(handle)))
|
||||
return ret;
|
||||
|
||||
if(bytesWritten)
|
||||
@ -1241,7 +1236,7 @@ FSFILE_GetSize(Handle handle,
|
||||
cmdbuf[0] = IPC_MakeHeader(0x804,0,0); // 0x8040000
|
||||
|
||||
Result ret = 0;
|
||||
if((ret = svcSendSyncRequest(handle)))
|
||||
if(R_FAILED(ret = svcSendSyncRequest(handle)))
|
||||
return ret;
|
||||
|
||||
if(size)
|
||||
@ -1285,7 +1280,7 @@ FSFILE_SetSize(Handle handle,
|
||||
cmdbuf[2] = (u32)(size >> 32);
|
||||
|
||||
Result ret = 0;
|
||||
if((ret = svcSendSyncRequest(handle)))
|
||||
if(R_FAILED(ret = svcSendSyncRequest(handle)))
|
||||
return ret;
|
||||
|
||||
|
||||
@ -1324,7 +1319,7 @@ FSFILE_GetAttributes(Handle handle,
|
||||
cmdbuf[0] = IPC_MakeHeader(0x806,0,0); // 0x8060000
|
||||
|
||||
Result ret = 0;
|
||||
if((ret = svcSendSyncRequest(handle)))
|
||||
if(R_FAILED(ret = svcSendSyncRequest(handle)))
|
||||
return ret;
|
||||
|
||||
if(attributes)
|
||||
@ -1366,7 +1361,7 @@ FSFILE_SetAttributes(Handle handle,
|
||||
cmdbuf[1] = attributes;
|
||||
|
||||
Result ret = 0;
|
||||
if((ret = svcSendSyncRequest(handle)))
|
||||
if(R_FAILED(ret = svcSendSyncRequest(handle)))
|
||||
return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
@ -1401,7 +1396,7 @@ FSFILE_Flush(Handle handle)
|
||||
cmdbuf[0] = IPC_MakeHeader(0x809,0,0); // 0x8090000
|
||||
|
||||
Result ret = 0;
|
||||
if((ret = svcSendSyncRequest(handle)))
|
||||
if(R_FAILED(ret = svcSendSyncRequest(handle)))
|
||||
return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
@ -1449,7 +1444,7 @@ FSDIR_Read(Handle handle,
|
||||
cmdbuf[3] = (u32)buffer;
|
||||
|
||||
Result ret = 0;
|
||||
if((ret = svcSendSyncRequest(handle)))
|
||||
if(R_FAILED(ret = svcSendSyncRequest(handle)))
|
||||
return ret;
|
||||
|
||||
if(entriesRead)
|
||||
@ -1487,9 +1482,9 @@ FSDIR_Close(Handle handle)
|
||||
cmdbuf[0] = IPC_MakeHeader(0x802,0,0); // 0x8020000
|
||||
|
||||
Result ret = 0;
|
||||
if((ret = svcSendSyncRequest(handle)))
|
||||
if(R_FAILED(ret = svcSendSyncRequest(handle)))
|
||||
return ret;
|
||||
ret = cmdbuf[1];
|
||||
if(!ret)ret = svcCloseHandle(handle);
|
||||
if(R_SUCCEEDED(ret))ret = svcCloseHandle(handle);
|
||||
return ret;
|
||||
}
|
||||
|
@ -5,14 +5,16 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/result.h>
|
||||
#include <3ds/svc.h>
|
||||
#include <3ds/srv.h>
|
||||
#include <3ds/synchronization.h>
|
||||
#include <3ds/services/gsp.h>
|
||||
|
||||
#define GSP_EVENT_STACK_SIZE 0x1000
|
||||
|
||||
Handle gspGpuHandle=0;
|
||||
Handle gspLcdHandle=0;
|
||||
Handle gspGpuHandle;
|
||||
Handle gspLcdHandle;
|
||||
Handle gspEvents[GSPEVENT_MAX];
|
||||
vu32 gspEventCounts[GSPEVENT_MAX];
|
||||
u64 gspEventStack[GSP_EVENT_STACK_SIZE/sizeof(u64)]; //u64 so that it's 8-byte aligned
|
||||
@ -20,18 +22,24 @@ volatile bool gspRunEvents;
|
||||
Handle gspEventThread;
|
||||
|
||||
static Handle gspEvent;
|
||||
static int gspRefCount, gspLcdRefCount;
|
||||
static vu8* gspEventData;
|
||||
|
||||
static void gspEventThreadMain(void *arg);
|
||||
|
||||
Result gspInit(void)
|
||||
{
|
||||
return srvGetServiceHandle(&gspGpuHandle, "gsp::Gpu");
|
||||
Result res=0;
|
||||
if (AtomicPostIncrement(&gspRefCount)) return 0;
|
||||
res = srvGetServiceHandle(&gspGpuHandle, "gsp::Gpu");
|
||||
if (R_FAILED(res)) AtomicDecrement(&gspRefCount);
|
||||
return res;
|
||||
}
|
||||
|
||||
void gspExit(void)
|
||||
{
|
||||
if(gspGpuHandle)svcCloseHandle(gspGpuHandle);
|
||||
if (AtomicDecrement(&gspRefCount)) return;
|
||||
svcCloseHandle(gspGpuHandle);
|
||||
}
|
||||
|
||||
Result gspInitEventHandler(Handle _gspEvent, vu8* _gspSharedMem, u8 gspThreadId)
|
||||
@ -85,7 +93,7 @@ void gspWaitForEvent(GSP_Event id, bool nextEvent)
|
||||
static int popInterrupt()
|
||||
{
|
||||
int curEvt;
|
||||
u32 strexFailed;
|
||||
bool strexFailed;
|
||||
do {
|
||||
union {
|
||||
struct {
|
||||
@ -97,16 +105,11 @@ static int popInterrupt()
|
||||
u32 as_u32;
|
||||
} header;
|
||||
|
||||
u32* gsp_header_ptr = (u32*)(gspEventData + 0);
|
||||
|
||||
// Do a load on all header fields as an atomic unit
|
||||
__asm__ volatile (
|
||||
"ldrex %[result], %[addr]" :
|
||||
[result]"=r"(header.as_u32) :
|
||||
[addr]"Q"(*gsp_header_ptr));
|
||||
header.as_u32 = __ldrex((s32*)gspEventData);
|
||||
|
||||
if (__builtin_expect(header.count == 0, 0)) {
|
||||
__asm__ volatile ("clrex");
|
||||
__clrex();
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -117,10 +120,7 @@ static int popInterrupt()
|
||||
header.count -= 1;
|
||||
header.err = 0; // Should this really be set?
|
||||
|
||||
__asm__ volatile (
|
||||
"strex %[result], %[val], %[addr]" :
|
||||
[result]"=&r"(strexFailed), [addr]"=Q"(*gsp_header_ptr) :
|
||||
[val]"r"(header.as_u32));
|
||||
strexFailed = __strex((s32*)gspEventData, header.as_u32);
|
||||
} while (__builtin_expect(strexFailed, 0));
|
||||
|
||||
return curEvt;
|
||||
@ -161,7 +161,7 @@ Result GSPGPU_WriteHWRegs(u32 regAddr, u32* data, u8 size)
|
||||
cmdbuf[4]=(u32)data;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(gspGpuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(gspGpuHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -180,7 +180,7 @@ Result GSPGPU_WriteHWRegsWithMask(u32 regAddr, u32* data, u8 datasize, u32* mask
|
||||
cmdbuf[6]=(u32)maskdata;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(gspGpuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(gspGpuHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -197,7 +197,7 @@ Result GSPGPU_ReadHWRegs(u32 regAddr, u32* data, u8 size)
|
||||
cmdbuf[0x40+1]=(u32)data;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(gspGpuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(gspGpuHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -211,7 +211,7 @@ Result GSPGPU_SetBufferSwap(u32 screenid, GSP_FramebufferInfo *framebufinfo)
|
||||
memcpy(&cmdbuf[2], framebufinfo, sizeof(GSP_FramebufferInfo));
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(gspGpuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(gspGpuHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -226,7 +226,7 @@ Result GSPGPU_FlushDataCache(const void* adr, u32 size)
|
||||
cmdbuf[4]=CUR_PROCESS_HANDLE;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(gspGpuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(gspGpuHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -242,7 +242,7 @@ Result GSPGPU_InvalidateDataCache(const void* adr, u32 size)
|
||||
cmdbuf[4] = CUR_PROCESS_HANDLE;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(gspGpuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(gspGpuHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -254,7 +254,7 @@ Result GSPGPU_SetLcdForceBlack(u8 flags)
|
||||
cmdbuf[1]=flags;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(gspGpuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(gspGpuHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -265,7 +265,7 @@ Result GSPGPU_TriggerCmdReqQueue(void)
|
||||
cmdbuf[0]=0x000C0000; //request header code
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(gspGpuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(gspGpuHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -279,7 +279,7 @@ Result GSPGPU_RegisterInterruptRelayQueue(Handle eventHandle, u32 flags, Handle*
|
||||
cmdbuf[3]=eventHandle;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(gspGpuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(gspGpuHandle)))return ret;
|
||||
|
||||
if(threadID)*threadID=cmdbuf[2];
|
||||
if(outMemHandle)*outMemHandle=cmdbuf[4];
|
||||
@ -293,7 +293,7 @@ Result GSPGPU_UnregisterInterruptRelayQueue(void)
|
||||
cmdbuf[0]=0x00140000; //request header code
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(gspGpuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(gspGpuHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -307,7 +307,7 @@ Result GSPGPU_AcquireRight(u8 flags)
|
||||
cmdbuf[3]=CUR_PROCESS_HANDLE;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(gspGpuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(gspGpuHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -318,7 +318,7 @@ Result GSPGPU_ReleaseRight(void)
|
||||
cmdbuf[0]=0x170000; //request header code
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(gspGpuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(gspGpuHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -329,14 +329,12 @@ Result GSPGPU_ImportDisplayCaptureInfo(GSP_CaptureInfo *captureinfo)
|
||||
cmdbuf[0]=0x00180000; //request header code
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(gspGpuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(gspGpuHandle)))return ret;
|
||||
|
||||
ret = cmdbuf[1];
|
||||
|
||||
if(ret==0)
|
||||
{
|
||||
if(R_SUCCEEDED(ret))
|
||||
memcpy(captureinfo, &cmdbuf[2], 0x20);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -347,7 +345,7 @@ Result GSPGPU_SaveVramSysArea(void)
|
||||
cmdbuf[0]=0x00190000; //request header code
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(gspGpuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(gspGpuHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -358,7 +356,7 @@ Result GSPGPU_RestoreVramSysArea(void)
|
||||
cmdbuf[0]=0x001A0000; //request header code
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(gspGpuHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(gspGpuHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -370,8 +368,7 @@ Result GSPGPU_SubmitGxCommand(u32* sharedGspCmdBuf, u32 gxCommand[0x8])
|
||||
{
|
||||
if(!sharedGspCmdBuf || !gxCommand)return -1;
|
||||
|
||||
u32 cmdBufHeader;
|
||||
__asm__ __volatile__ ("ldrex %[result], [%[adr]]" : [result] "=r" (cmdBufHeader) : [adr] "r" (sharedGspCmdBuf));
|
||||
u32 cmdBufHeader = __ldrex((s32*)sharedGspCmdBuf);
|
||||
|
||||
u8 commandIndex=cmdBufHeader&0xFF;
|
||||
u8 totalCommands=(cmdBufHeader>>8)&0xFF;
|
||||
@ -382,18 +379,15 @@ Result GSPGPU_SubmitGxCommand(u32* sharedGspCmdBuf, u32 gxCommand[0x8])
|
||||
u32* dst=&sharedGspCmdBuf[8*(1+nextCmd)];
|
||||
memcpy(dst, gxCommand, 0x20);
|
||||
|
||||
u32 mcrVal=0x0;
|
||||
__asm__ __volatile__ ("mcr p15, 0, %[val], c7, c10, 4" :: [val] "r" (mcrVal)); //Data Synchronization Barrier Register
|
||||
__dsb();
|
||||
totalCommands++;
|
||||
cmdBufHeader=((cmdBufHeader)&0xFFFF00FF)|(((u32)totalCommands)<<8);
|
||||
|
||||
while(1)
|
||||
{
|
||||
u32 strexResult;
|
||||
__asm__ __volatile__ ("strex %[result], %[val], [%[adr]]" : [result] "=&r" (strexResult) : [adr] "r" (sharedGspCmdBuf), [val] "r" (cmdBufHeader));
|
||||
if(!strexResult)break;
|
||||
if (!__strex((s32*)sharedGspCmdBuf, cmdBufHeader)) break;
|
||||
|
||||
__asm__ __volatile__ ("ldrex %[result], [%[adr]]" : [result] "=r" (cmdBufHeader) : [adr] "r" (sharedGspCmdBuf));
|
||||
cmdBufHeader = __ldrex((s32*)sharedGspCmdBuf);
|
||||
totalCommands=((cmdBufHeader&0xFF00)>>8)+1;
|
||||
cmdBufHeader=((cmdBufHeader)&0xFFFF00FF)|((totalCommands<<8)&0xFF00);
|
||||
}
|
||||
@ -404,12 +398,17 @@ Result GSPGPU_SubmitGxCommand(u32* sharedGspCmdBuf, u32 gxCommand[0x8])
|
||||
|
||||
Result gspLcdInit(void)
|
||||
{
|
||||
return srvGetServiceHandle(&gspLcdHandle, "gsp::Lcd");
|
||||
Result res=0;
|
||||
if (AtomicPostIncrement(&gspLcdRefCount)) return 0;
|
||||
res = srvGetServiceHandle(&gspLcdHandle, "gsp::Lcd");
|
||||
if (R_FAILED(res)) AtomicDecrement(&gspLcdRefCount);
|
||||
return res;
|
||||
}
|
||||
|
||||
void gspLcdExit(void)
|
||||
{
|
||||
if(gspLcdHandle)svcCloseHandle(gspLcdHandle);
|
||||
if (AtomicDecrement(&gspLcdRefCount)) return;
|
||||
svcCloseHandle(gspLcdHandle);
|
||||
}
|
||||
|
||||
Result GSPLCD_PowerOffBacklight(GSPLCD_Screens screen)
|
||||
@ -420,7 +419,7 @@ Result GSPLCD_PowerOffBacklight(GSPLCD_Screens screen)
|
||||
cmdbuf[1] = screen;
|
||||
|
||||
Result ret=0;
|
||||
if ((ret = svcSendSyncRequest(gspLcdHandle)))return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(gspLcdHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -433,7 +432,7 @@ Result GSPLCD_PowerOnBacklight(GSPLCD_Screens screen)
|
||||
cmdbuf[1] = screen;
|
||||
|
||||
Result ret=0;
|
||||
if ((ret = svcSendSyncRequest(gspLcdHandle)))return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(gspLcdHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
@ -1,18 +1,26 @@
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/result.h>
|
||||
#include <3ds/svc.h>
|
||||
#include <3ds/srv.h>
|
||||
#include <3ds/synchronization.h>
|
||||
#include <3ds/services/hb.h>
|
||||
#include <3ds/ipc.h>
|
||||
|
||||
static Handle hbHandle;
|
||||
static int hbRefCount;
|
||||
|
||||
Result hbInit(void)
|
||||
{
|
||||
return srvGetServiceHandle(&hbHandle, "hb:HB");
|
||||
Result res=0;
|
||||
if (AtomicPostIncrement(&hbRefCount)) return 0;
|
||||
res = srvGetServiceHandle(&hbHandle, "hb:HB");
|
||||
if (R_FAILED(res)) AtomicDecrement(&hbRefCount);
|
||||
return res;
|
||||
}
|
||||
|
||||
void hbExit(void)
|
||||
{
|
||||
if (AtomicDecrement(&hbRefCount)) return;
|
||||
svcCloseHandle(hbHandle);
|
||||
}
|
||||
|
||||
@ -26,7 +34,7 @@ Result HB_FlushInvalidateCache(void)
|
||||
cmdbuf[2] = IPC_Desc_SharedHandles(1);
|
||||
cmdbuf[3] = CUR_PROCESS_HANDLE;
|
||||
|
||||
if((ret = svcSendSyncRequest(hbHandle))!=0) return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(hbHandle))) return ret;
|
||||
|
||||
return (Result)cmdbuf[1];
|
||||
}
|
||||
@ -38,7 +46,7 @@ Result HB_GetBootloaderAddresses(void** load3dsx, void** setArgv)
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x6,0,0); // 0x60000
|
||||
|
||||
if((ret = svcSendSyncRequest(hbHandle))!=0) return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(hbHandle))) return ret;
|
||||
|
||||
if(load3dsx)*load3dsx=(void*)cmdbuf[2];
|
||||
if(setArgv)*setArgv=(void*)cmdbuf[3];
|
||||
@ -56,11 +64,11 @@ Result HB_ReprotectMemory(u32* addr, u32 pages, u32 mode, u32* reprotectedPages)
|
||||
cmdbuf[2] = pages;
|
||||
cmdbuf[3] = mode;
|
||||
|
||||
if((ret = svcSendSyncRequest(hbHandle))!=0) return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(hbHandle))) return ret;
|
||||
|
||||
if(reprotectedPages)
|
||||
{
|
||||
if(!ret)*reprotectedPages=(u32)cmdbuf[2];
|
||||
if(R_SUCCEEDED(ret))*reprotectedPages=(u32)cmdbuf[2];
|
||||
else *reprotectedPages=0;
|
||||
}
|
||||
|
||||
|
@ -4,9 +4,11 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/result.h>
|
||||
#include <3ds/svc.h>
|
||||
#include <3ds/srv.h>
|
||||
#include <3ds/mappable.h>
|
||||
#include <3ds/synchronization.h>
|
||||
#include <3ds/services/apt.h>
|
||||
#include <3ds/services/hid.h>
|
||||
#include <3ds/services/irrst.h>
|
||||
@ -25,20 +27,22 @@ static circlePosition cPos;
|
||||
static accelVector aVec;
|
||||
static angularRate gRate;
|
||||
|
||||
static bool hidInitialised;
|
||||
static int hidRefCount;
|
||||
|
||||
Result hidInit(void)
|
||||
{
|
||||
u8 val=0;
|
||||
Result ret=0;
|
||||
|
||||
if(hidInitialised) return ret;
|
||||
if (AtomicPostIncrement(&hidRefCount)) return 0;
|
||||
|
||||
// Request service.
|
||||
if((ret=srvGetServiceHandle(&hidHandle, "hid:USER")) && (ret=srvGetServiceHandle(&hidHandle, "hid:SPVR")))return ret;
|
||||
ret = srvGetServiceHandle(&hidHandle, "hid:USER");
|
||||
if (R_FAILED(ret)) ret = srvGetServiceHandle(&hidHandle, "hid:SPVR");
|
||||
if (R_FAILED(ret)) goto cleanup0;
|
||||
|
||||
// Get sharedmem handle.
|
||||
if((ret=HIDUSER_GetHandles(&hidMemHandle, &hidEvents[HIDEVENT_PAD0], &hidEvents[HIDEVENT_PAD1], &hidEvents[HIDEVENT_Accel], &hidEvents[HIDEVENT_Gyro], &hidEvents[HIDEVENT_DebugPad]))) goto cleanup1;
|
||||
if(R_FAILED(ret=HIDUSER_GetHandles(&hidMemHandle, &hidEvents[HIDEVENT_PAD0], &hidEvents[HIDEVENT_PAD1], &hidEvents[HIDEVENT_Accel], &hidEvents[HIDEVENT_Gyro], &hidEvents[HIDEVENT_DebugPad]))) goto cleanup1;
|
||||
|
||||
// Map HID shared memory.
|
||||
hidSharedMem=(vu32*)mappableAlloc(0x2b0);
|
||||
@ -48,7 +52,7 @@ Result hidInit(void)
|
||||
goto cleanup1;
|
||||
}
|
||||
|
||||
if((ret=svcMapMemoryBlock(hidMemHandle, (u32)hidSharedMem, MEMPERM_READ, 0x10000000)))goto cleanup2;
|
||||
if(R_FAILED(ret=svcMapMemoryBlock(hidMemHandle, (u32)hidSharedMem, MEMPERM_READ, 0x10000000)))goto cleanup2;
|
||||
|
||||
APT_CheckNew3DS(&val);
|
||||
|
||||
@ -58,7 +62,6 @@ Result hidInit(void)
|
||||
}
|
||||
|
||||
// Reset internal state.
|
||||
hidInitialised = true;
|
||||
kOld = kHeld = kDown = kUp = 0;
|
||||
return ret;
|
||||
|
||||
@ -71,12 +74,14 @@ cleanup2:
|
||||
}
|
||||
cleanup1:
|
||||
svcCloseHandle(hidHandle);
|
||||
cleanup0:
|
||||
AtomicDecrement(&hidRefCount);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void hidExit(void)
|
||||
{
|
||||
if(!hidInitialised) return;
|
||||
if (AtomicDecrement(&hidRefCount)) return;
|
||||
|
||||
// Unmap HID sharedmem and close handles.
|
||||
u8 val=0;
|
||||
@ -97,8 +102,6 @@ void hidExit(void)
|
||||
mappableFree((void*) hidSharedMem);
|
||||
hidSharedMem = NULL;
|
||||
}
|
||||
|
||||
hidInitialised = false;
|
||||
}
|
||||
|
||||
void hidWaitForEvent(HID_Event id, bool nextEvent)
|
||||
@ -218,7 +221,7 @@ Result HIDUSER_GetHandles(Handle* outMemHandle, Handle *eventpad0, Handle *event
|
||||
cmdbuf[0]=IPC_MakeHeader(0xA,0,0); // 0xA0000
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(hidHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(hidHandle)))return ret;
|
||||
|
||||
if(outMemHandle)*outMemHandle=cmdbuf[3];
|
||||
|
||||
@ -237,7 +240,7 @@ Result HIDUSER_EnableAccelerometer(void)
|
||||
cmdbuf[0]=IPC_MakeHeader(0x11,0,0); // 0x110000
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(hidHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(hidHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -248,7 +251,7 @@ Result HIDUSER_DisableAccelerometer(void)
|
||||
cmdbuf[0]=IPC_MakeHeader(0x12,0,0); // 0x120000
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(hidHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(hidHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -259,7 +262,7 @@ Result HIDUSER_EnableGyroscope(void)
|
||||
cmdbuf[0]=IPC_MakeHeader(0x13,0,0); // 0x130000
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(hidHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(hidHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -270,7 +273,7 @@ Result HIDUSER_DisableGyroscope(void)
|
||||
cmdbuf[0]=IPC_MakeHeader(0x14,0,0); // 0x140000
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(hidHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(hidHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -281,7 +284,7 @@ Result HIDUSER_GetGyroscopeRawToDpsCoefficient(float *coeff)
|
||||
cmdbuf[0]=IPC_MakeHeader(0x15,0,0); // 0x150000
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(hidHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(hidHandle)))return ret;
|
||||
|
||||
*coeff = (float)cmdbuf[2];
|
||||
|
||||
@ -294,7 +297,7 @@ Result HIDUSER_GetSoundVolume(u8 *volume)
|
||||
cmdbuf[0]=IPC_MakeHeader(0x17,0,0); // 0x170000
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(hidHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(hidHandle)))return ret;
|
||||
|
||||
*volume = (u8)cmdbuf[2];
|
||||
|
||||
|
@ -1,32 +1,36 @@
|
||||
#include <string.h>
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/result.h>
|
||||
#include <3ds/svc.h>
|
||||
#include <3ds/srv.h>
|
||||
#include <3ds/synchronization.h>
|
||||
#include <3ds/services/httpc.h>
|
||||
#include <3ds/ipc.h>
|
||||
|
||||
Handle __httpc_servhandle = 0;
|
||||
Handle __httpc_servhandle;
|
||||
static int __httpc_refcount;
|
||||
|
||||
Result httpcInit(void)
|
||||
{
|
||||
Result ret=0;
|
||||
|
||||
if(__httpc_servhandle)return 0;
|
||||
if((ret=srvGetServiceHandle(&__httpc_servhandle, "http:C")))return ret;
|
||||
if (AtomicPostIncrement(&__httpc_refcount)) return 0;
|
||||
|
||||
ret = srvGetServiceHandle(&__httpc_servhandle, "http:C");
|
||||
if (R_SUCCEEDED(ret))
|
||||
{
|
||||
ret = HTTPC_Initialize(__httpc_servhandle);
|
||||
if(ret!=0)return ret;
|
||||
if (R_FAILED(ret)) svcCloseHandle(__httpc_servhandle);
|
||||
}
|
||||
if (R_FAILED(ret)) AtomicDecrement(&__httpc_refcount);
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void httpcExit(void)
|
||||
{
|
||||
if(__httpc_servhandle==0)return;
|
||||
|
||||
if (AtomicDecrement(&__httpc_refcount)) return;
|
||||
svcCloseHandle(__httpc_servhandle);
|
||||
|
||||
__httpc_servhandle = 0;
|
||||
}
|
||||
|
||||
Result httpcOpenContext(httpcContext *context, char* url, u32 use_defaultproxy)
|
||||
@ -34,16 +38,16 @@ Result httpcOpenContext(httpcContext *context, char* url, u32 use_defaultproxy)
|
||||
Result ret=0;
|
||||
|
||||
ret = HTTPC_CreateContext(__httpc_servhandle, url, &context->httphandle);
|
||||
if(ret!=0)return ret;
|
||||
if(R_FAILED(ret))return ret;
|
||||
|
||||
ret = srvGetServiceHandle(&context->servhandle, "http:C");
|
||||
if(ret!=0) {
|
||||
if(R_FAILED(ret)) {
|
||||
HTTPC_CloseContext(__httpc_servhandle, context->httphandle);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = HTTPC_InitializeConnectionSession(context->servhandle, context->httphandle);
|
||||
if(ret!=0) {
|
||||
if(R_FAILED(ret)) {
|
||||
svcCloseHandle(context->servhandle);
|
||||
HTTPC_CloseContext(__httpc_servhandle, context->httphandle);
|
||||
return ret;
|
||||
@ -52,7 +56,7 @@ Result httpcOpenContext(httpcContext *context, char* url, u32 use_defaultproxy)
|
||||
if(use_defaultproxy==0)return 0;
|
||||
|
||||
ret = HTTPC_SetProxyDefault(context->servhandle, context->httphandle);
|
||||
if(ret!=0) {
|
||||
if(R_FAILED(ret)) {
|
||||
svcCloseHandle(context->servhandle);
|
||||
HTTPC_CloseContext(__httpc_servhandle, context->httphandle);
|
||||
return ret;
|
||||
@ -115,7 +119,7 @@ Result httpcDownloadData(httpcContext *context, u8* buffer, u32 size, u32 *downl
|
||||
if(downloadedsize)*downloadedsize = 0;
|
||||
|
||||
ret=httpcGetDownloadSizeState(context, NULL, &contentsize);
|
||||
if(ret!=0)return ret;
|
||||
if(R_FAILED(ret))return ret;
|
||||
|
||||
while(pos < size)
|
||||
{
|
||||
@ -126,9 +130,9 @@ Result httpcDownloadData(httpcContext *context, u8* buffer, u32 size, u32 *downl
|
||||
if(ret==HTTPC_RESULTCODE_DOWNLOADPENDING)
|
||||
{
|
||||
ret=httpcGetDownloadSizeState(context, &pos, NULL);
|
||||
if(ret!=0)return ret;
|
||||
if(R_FAILED(ret))return ret;
|
||||
}
|
||||
else if(ret!=0)
|
||||
else if(R_FAILED(ret))
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
@ -154,7 +158,7 @@ Result HTTPC_Initialize(Handle handle)
|
||||
cmdbuf[5]=0;//Some sort of handle.
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(handle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(handle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -171,7 +175,7 @@ Result HTTPC_CreateContext(Handle handle, char* url, Handle* contextHandle)
|
||||
cmdbuf[4]=(u32)url;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(handle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(handle)))return ret;
|
||||
|
||||
if(contextHandle)*contextHandle=cmdbuf[2];
|
||||
|
||||
@ -187,7 +191,7 @@ Result HTTPC_InitializeConnectionSession(Handle handle, Handle contextHandle)
|
||||
cmdbuf[2]=IPC_Desc_CurProcessHandle();
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(handle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(handle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -200,7 +204,7 @@ Result HTTPC_SetProxyDefault(Handle handle, Handle contextHandle)
|
||||
cmdbuf[1]=contextHandle;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(handle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(handle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -213,7 +217,7 @@ Result HTTPC_CloseContext(Handle handle, Handle contextHandle)
|
||||
cmdbuf[1]=contextHandle;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(handle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(handle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -235,7 +239,7 @@ Result HTTPC_AddRequestHeaderField(Handle handle, Handle contextHandle, char* na
|
||||
cmdbuf[7]=(u32)value;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(handle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(handle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -248,7 +252,7 @@ Result HTTPC_BeginRequest(Handle handle, Handle contextHandle)
|
||||
cmdbuf[1]=contextHandle;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(handle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(handle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -264,7 +268,7 @@ Result HTTPC_ReceiveData(Handle handle, Handle contextHandle, u8* buffer, u32 si
|
||||
cmdbuf[4]=(u32)buffer;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(handle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(handle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -277,7 +281,7 @@ Result HTTPC_GetRequestState(Handle handle, Handle contextHandle, httpcReqStatus
|
||||
cmdbuf[1]=contextHandle;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(handle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(handle)))return ret;
|
||||
|
||||
*out = cmdbuf[2];
|
||||
|
||||
@ -292,7 +296,7 @@ Result HTTPC_GetDownloadSizeState(Handle handle, Handle contextHandle, u32* down
|
||||
cmdbuf[1]=contextHandle;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(handle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(handle)))return ret;
|
||||
|
||||
if(downloadedsize)*downloadedsize = cmdbuf[2];
|
||||
if(contentsize)*contentsize = cmdbuf[3];
|
||||
@ -316,7 +320,7 @@ Result HTTPC_GetResponseHeader(Handle handle, Handle contextHandle, char* name,
|
||||
cmdbuf[7]=(u32)value;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(handle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(handle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -329,7 +333,7 @@ Result HTTPC_GetResponseStatusCode(Handle handle, Handle contextHandle, u32* out
|
||||
cmdbuf[1]=contextHandle;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(handle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(handle)))return ret;
|
||||
|
||||
*out = cmdbuf[2];
|
||||
|
||||
|
@ -1,15 +1,18 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/result.h>
|
||||
#include <3ds/svc.h>
|
||||
#include <3ds/srv.h>
|
||||
#include <3ds/synchronization.h>
|
||||
#include <3ds/services/ir.h>
|
||||
#include <3ds/ipc.h>
|
||||
|
||||
static Handle iru_handle=0;
|
||||
static Handle iru_sharedmem_handle=0;
|
||||
static u32 *iru_sharedmem = NULL;
|
||||
static u32 iru_sharedmem_size = 0;
|
||||
static Handle iru_handle;
|
||||
static Handle iru_sharedmem_handle;
|
||||
static u32 *iru_sharedmem;
|
||||
static u32 iru_sharedmem_size;
|
||||
static int iru_refcount;
|
||||
|
||||
Result irucmd_Initialize(void)
|
||||
{
|
||||
@ -18,7 +21,7 @@ Result irucmd_Initialize(void)
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x1,0,0); // 0x10000
|
||||
|
||||
if((ret = svcSendSyncRequest(iru_handle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(iru_handle)))return ret;
|
||||
ret = (Result)cmdbuf[1];
|
||||
|
||||
return ret;
|
||||
@ -31,7 +34,7 @@ Result irucmd_Shutdown(void)
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x2,0,0); // 0x20000
|
||||
|
||||
if((ret = svcSendSyncRequest(iru_handle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(iru_handle)))return ret;
|
||||
ret = (Result)cmdbuf[1];
|
||||
|
||||
return ret;
|
||||
@ -47,7 +50,7 @@ Result irucmd_StartSendTransfer(u8 *buf, u32 size)
|
||||
cmdbuf[2] = IPC_Desc_Buffer(size,IPC_BUFFER_R);
|
||||
cmdbuf[3] = (u32)buf;
|
||||
|
||||
if((ret = svcSendSyncRequest(iru_handle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(iru_handle)))return ret;
|
||||
ret = (Result)cmdbuf[1];
|
||||
|
||||
return ret;
|
||||
@ -60,7 +63,7 @@ Result irucmd_WaitSendTransfer(void)
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x4,0,0); // 0x40000
|
||||
|
||||
if((ret = svcSendSyncRequest(iru_handle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(iru_handle)))return ret;
|
||||
ret = (Result)cmdbuf[1];
|
||||
|
||||
return ret;
|
||||
@ -78,7 +81,7 @@ Result irucmd_StartRecvTransfer(u32 size, u8 flag)
|
||||
cmdbuf[4] = IPC_Desc_SharedHandles(1);
|
||||
cmdbuf[5] = iru_sharedmem_handle;
|
||||
|
||||
if((ret = svcSendSyncRequest(iru_handle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(iru_handle)))return ret;
|
||||
ret = (Result)cmdbuf[1];
|
||||
|
||||
return ret;
|
||||
@ -91,7 +94,7 @@ Result irucmd_WaitRecvTransfer(u32 *transfercount)
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x6,0,0); // 0x60000
|
||||
|
||||
if((ret = svcSendSyncRequest(iru_handle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(iru_handle)))return ret;
|
||||
ret = (Result)cmdbuf[1];
|
||||
|
||||
*transfercount = cmdbuf[2];
|
||||
@ -107,7 +110,7 @@ Result IRU_SetBitRate(u8 value)
|
||||
cmdbuf[0] = IPC_MakeHeader(0x9,1,0); // 0x90040
|
||||
cmdbuf[1] = (u32)value;
|
||||
|
||||
if((ret = svcSendSyncRequest(iru_handle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(iru_handle)))return ret;
|
||||
ret = (Result)cmdbuf[1];
|
||||
|
||||
return ret;
|
||||
@ -120,7 +123,7 @@ Result IRU_GetBitRate(u8 *out)
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0xA,0,0); // 0xA0000
|
||||
|
||||
if((ret = svcSendSyncRequest(iru_handle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(iru_handle)))return ret;
|
||||
ret = (Result)cmdbuf[1];
|
||||
|
||||
*out = (u8)cmdbuf[2];
|
||||
@ -136,7 +139,7 @@ Result IRU_SetIRLEDState(u32 value)
|
||||
cmdbuf[0] = IPC_MakeHeader(0xB,1,0); // 0xB0040
|
||||
cmdbuf[1] = value;
|
||||
|
||||
if((ret = svcSendSyncRequest(iru_handle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(iru_handle)))return ret;
|
||||
ret = (Result)cmdbuf[1];
|
||||
|
||||
return ret;
|
||||
@ -149,7 +152,7 @@ Result IRU_GetIRLEDRecvState(u32 *out)
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0xC,0,0); // 0xC0000
|
||||
|
||||
if((ret = svcSendSyncRequest(iru_handle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(iru_handle)))return ret;
|
||||
ret = (Result)cmdbuf[1];
|
||||
|
||||
*out = cmdbuf[2];
|
||||
@ -157,75 +160,77 @@ Result IRU_GetIRLEDRecvState(u32 *out)
|
||||
return ret;
|
||||
}
|
||||
|
||||
Result IRU_Initialize(u32 *sharedmem_addr, u32 sharedmem_size)
|
||||
Result iruInit(u32 *sharedmem_addr, u32 sharedmem_size)
|
||||
{
|
||||
Result ret = 0;
|
||||
|
||||
if(iru_handle)return 0;
|
||||
if(AtomicPostIncrement(&iru_refcount)) return 0;
|
||||
|
||||
ret = srvGetServiceHandle(&iru_handle, "ir:u");
|
||||
if(ret!=0)return ret;
|
||||
if(R_FAILED(ret))goto cleanup0;
|
||||
|
||||
ret = irucmd_Initialize();
|
||||
if(ret!=0)return ret;
|
||||
if(R_FAILED(ret))goto cleanup1;
|
||||
|
||||
ret = svcCreateMemoryBlock(&iru_sharedmem_handle, (u32)sharedmem_addr, sharedmem_size, 1, 3);
|
||||
if(ret!=0)return ret;
|
||||
if(R_FAILED(ret))goto cleanup2;
|
||||
|
||||
iru_sharedmem = sharedmem_addr;
|
||||
iru_sharedmem_size = sharedmem_size;
|
||||
|
||||
return ret;
|
||||
|
||||
cleanup2:
|
||||
irucmd_Shutdown();
|
||||
cleanup1:
|
||||
svcCloseHandle(iru_handle);
|
||||
cleanup0:
|
||||
AtomicDecrement(&iru_refcount);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Result IRU_Shutdown(void)
|
||||
void iruExit(void)
|
||||
{
|
||||
Result ret = 0;
|
||||
|
||||
if(iru_handle==0)return 0;
|
||||
|
||||
ret = irucmd_Shutdown();
|
||||
if(ret!=0)return ret;
|
||||
if(AtomicDecrement(&iru_refcount)) return;
|
||||
|
||||
irucmd_Shutdown();
|
||||
svcCloseHandle(iru_handle);
|
||||
svcCloseHandle(iru_sharedmem_handle);
|
||||
|
||||
iru_handle = 0;
|
||||
iru_sharedmem_handle = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Handle IRU_GetServHandle(void)
|
||||
Handle iruGetServHandle(void)
|
||||
{
|
||||
return iru_handle;
|
||||
}
|
||||
|
||||
Result IRU_SendData(u8 *buf, u32 size, u32 wait)
|
||||
Result iruSendData(u8 *buf, u32 size, bool wait)
|
||||
{
|
||||
Result ret = 0;
|
||||
|
||||
ret = irucmd_StartSendTransfer(buf, size);
|
||||
if(ret!=0)return ret;
|
||||
if(R_FAILED(ret))return ret;
|
||||
|
||||
if(wait==0)return 0;
|
||||
if(!wait)return 0;
|
||||
|
||||
return irucmd_WaitSendTransfer();
|
||||
}
|
||||
|
||||
Result IRU_RecvData(u8 *buf, u32 size, u8 flag, u32 *transfercount, u32 wait)
|
||||
Result iruRecvData(u8 *buf, u32 size, u8 flag, u32 *transfercount, bool wait)
|
||||
{
|
||||
Result ret = 0;
|
||||
|
||||
*transfercount = 0;
|
||||
|
||||
ret = irucmd_StartRecvTransfer(size, flag);
|
||||
if(ret!=0)return ret;
|
||||
if(R_FAILED(ret))return ret;
|
||||
|
||||
if(wait)
|
||||
{
|
||||
ret = irucmd_WaitRecvTransfer(transfercount);
|
||||
if(ret!=0)return ret;
|
||||
if(R_FAILED(ret))return ret;
|
||||
|
||||
if(buf)memcpy(buf, iru_sharedmem, size);
|
||||
}
|
||||
|
@ -4,9 +4,11 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/result.h>
|
||||
#include <3ds/svc.h>
|
||||
#include <3ds/srv.h>
|
||||
#include <3ds/mappable.h>
|
||||
#include <3ds/synchronization.h>
|
||||
#include <3ds/services/irrst.h>
|
||||
#include <3ds/ipc.h>
|
||||
|
||||
@ -21,19 +23,19 @@ vu32* irrstSharedMem;
|
||||
|
||||
static u32 kHeld;
|
||||
static circlePosition csPos;
|
||||
static bool irrstUsed = false;
|
||||
static int irrstRefCount;
|
||||
|
||||
Result irrstInit(void)
|
||||
{
|
||||
if(irrstUsed)return 0;
|
||||
if (AtomicPostIncrement(&irrstRefCount)) return 0;
|
||||
|
||||
Result ret=0;
|
||||
|
||||
// Request service.
|
||||
if((ret=srvGetServiceHandle(&irrstHandle, "ir:rst")))return ret;
|
||||
if(R_FAILED(ret=srvGetServiceHandle(&irrstHandle, "ir:rst"))) goto cleanup0;
|
||||
|
||||
// Get sharedmem handle.
|
||||
if((ret=IRRST_GetHandles(&irrstMemHandle, &irrstEvent))) goto cleanup1;
|
||||
if(R_FAILED(ret=IRRST_GetHandles(&irrstMemHandle, &irrstEvent))) goto cleanup1;
|
||||
|
||||
// Initialize ir:rst
|
||||
if(__get_handle_from_list("ir:rst")==0)ret=IRRST_Initialize(10, 0);
|
||||
@ -46,10 +48,9 @@ Result irrstInit(void)
|
||||
goto cleanup1;
|
||||
}
|
||||
|
||||
if((ret=svcMapMemoryBlock(irrstMemHandle, (u32)irrstSharedMem, MEMPERM_READ, 0x10000000)))goto cleanup2;
|
||||
if(R_FAILED(ret=svcMapMemoryBlock(irrstMemHandle, (u32)irrstSharedMem, MEMPERM_READ, 0x10000000)))goto cleanup2;
|
||||
|
||||
// Reset internal state.
|
||||
irrstUsed = true;
|
||||
kHeld = 0;
|
||||
return 0;
|
||||
|
||||
@ -62,14 +63,15 @@ cleanup2:
|
||||
}
|
||||
cleanup1:
|
||||
svcCloseHandle(irrstHandle);
|
||||
cleanup0:
|
||||
AtomicDecrement(&irrstRefCount);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void irrstExit(void)
|
||||
{
|
||||
if(!irrstUsed)return;
|
||||
if (AtomicDecrement(&irrstRefCount)) return;
|
||||
|
||||
irrstUsed = false;
|
||||
svcCloseHandle(irrstEvent);
|
||||
// Unmap ir:rst sharedmem and close handles.
|
||||
svcUnmapMemoryBlock(irrstMemHandle, (u32)irrstSharedMem);
|
||||
@ -108,7 +110,7 @@ u32 irrstCheckSectionUpdateTime(vu32 *sharedmem_section, u32 id)
|
||||
|
||||
void irrstScanInput(void)
|
||||
{
|
||||
if(!irrstUsed)return;
|
||||
if(irrstRefCount==0)return;
|
||||
|
||||
u32 Id=0;
|
||||
kHeld = 0;
|
||||
@ -125,7 +127,7 @@ void irrstScanInput(void)
|
||||
|
||||
u32 irrstKeysHeld(void)
|
||||
{
|
||||
if(irrstUsed)return kHeld;
|
||||
if(irrstRefCount>0)return kHeld;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -140,7 +142,7 @@ Result IRRST_GetHandles(Handle* outMemHandle, Handle* outEventHandle)
|
||||
cmdbuf[0]=IPC_MakeHeader(0x1,0,0); // 0x10000
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(irrstHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(irrstHandle)))return ret;
|
||||
|
||||
if(outMemHandle)*outMemHandle=cmdbuf[3];
|
||||
if(outEventHandle)*outEventHandle=cmdbuf[4];
|
||||
@ -156,7 +158,7 @@ Result IRRST_Initialize(u32 unk1, u8 unk2)
|
||||
cmdbuf[2]=unk2;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(irrstHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(irrstHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -167,7 +169,7 @@ Result IRRST_Shutdown(void)
|
||||
cmdbuf[0]=IPC_MakeHeader(0x3,0,0); // 0x30000
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(irrstHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(irrstHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
@ -5,20 +5,22 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/result.h>
|
||||
#include <3ds/svc.h>
|
||||
#include <3ds/srv.h>
|
||||
#include <3ds/os.h>
|
||||
#include <3ds/linear.h>
|
||||
#include <3ds/synchronization.h>
|
||||
#include <3ds/services/mvd.h>
|
||||
#include <3ds/ipc.h>
|
||||
|
||||
Handle mvdstdHandle;
|
||||
static u32 mvdstdInitialized = 0;
|
||||
static int mvdstdRefCount;
|
||||
static mvdstdMode mvdstd_mode;
|
||||
static mvdstdTypeInput mvdstd_input_type;
|
||||
static mvdstdTypeOutput mvdstd_output_type;
|
||||
static u32 *mvdstd_workbuf = NULL;
|
||||
static size_t mvdstd_workbufsize = 0;
|
||||
static u32 *mvdstd_workbuf;
|
||||
static size_t mvdstd_workbufsize;
|
||||
|
||||
static Result mvdstdipc_Initialize(u32 *buf, u32 bufsize, Handle kprocess)
|
||||
{
|
||||
@ -30,7 +32,7 @@ static Result mvdstdipc_Initialize(u32 *buf, u32 bufsize, Handle kprocess)
|
||||
cmdbuf[4] = kprocess;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(mvdstdHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(mvdstdHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -52,7 +54,7 @@ static Result mvdstdipc_cmd18(void)
|
||||
cmdbuf[0] = IPC_MakeHeader(0x18,0,0); // 0x180000
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(mvdstdHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(mvdstdHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -63,7 +65,7 @@ static Result mvdstdipc_cmd19(void)
|
||||
cmdbuf[0] = IPC_MakeHeader(0x19,0,0); // 0x190000
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(mvdstdHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(mvdstdHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -74,7 +76,7 @@ static Result mvdstdipc_cmd1a(void)
|
||||
cmdbuf[0] = IPC_MakeHeader(0x1A,0,0); // 0x1A0000
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(mvdstdHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(mvdstdHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -90,7 +92,7 @@ Result mvdstdSetConfig(mvdstdConfig *config)
|
||||
cmdbuf[5] = (u32)config;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(mvdstdHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(mvdstdHandle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -137,8 +139,6 @@ Result mvdstdInit(mvdstdMode mode, mvdstdTypeInput input_type, mvdstdTypeOutput
|
||||
{
|
||||
Result ret=0;
|
||||
|
||||
if(mvdstdInitialized)return 0;
|
||||
|
||||
mvdstd_workbufsize = size;
|
||||
mvdstd_mode = mode;
|
||||
mvdstd_input_type = input_type;
|
||||
@ -147,36 +147,35 @@ Result mvdstdInit(mvdstdMode mode, mvdstdTypeInput input_type, mvdstdTypeOutput
|
||||
if(mvdstd_mode==MVDMODE_COLORFORMATCONV)mvdstd_workbufsize = 1;
|
||||
if(mvdstd_mode!=MVDMODE_COLORFORMATCONV)return -2;//Video processing / H.264 isn't supported atm.
|
||||
|
||||
if((ret=srvGetServiceHandle(&mvdstdHandle, "mvd:STD")))return ret;
|
||||
if (AtomicPostIncrement(&mvdstdRefCount)) return 0;
|
||||
|
||||
if(R_FAILED(ret=srvGetServiceHandle(&mvdstdHandle, "mvd:STD"))) goto cleanup0;
|
||||
|
||||
mvdstd_workbuf = linearAlloc(mvdstd_workbufsize);
|
||||
if(mvdstd_workbuf==NULL)return -1;
|
||||
if(mvdstd_workbuf==NULL) goto cleanup1;
|
||||
|
||||
ret = mvdstdipc_Initialize((u32*)osConvertOldLINEARMemToNew((u32)mvdstd_workbuf), mvdstd_workbufsize, CUR_PROCESS_HANDLE);
|
||||
if(ret<0)
|
||||
{
|
||||
svcCloseHandle(mvdstdHandle);
|
||||
linearFree(mvdstd_workbuf);
|
||||
return ret;
|
||||
}
|
||||
if(R_FAILED(ret)) goto cleanup2;
|
||||
|
||||
ret = mvdstdipc_cmd18();
|
||||
if(ret<0)
|
||||
{
|
||||
mvdstdipc_Shutdown();
|
||||
svcCloseHandle(mvdstdHandle);
|
||||
linearFree(mvdstd_workbuf);
|
||||
if(R_FAILED(ret)) goto cleanup3;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
mvdstdInitialized = 1;
|
||||
|
||||
return 0;
|
||||
cleanup3:
|
||||
mvdstdipc_Shutdown();
|
||||
cleanup2:
|
||||
linearFree(mvdstd_workbuf);
|
||||
cleanup1:
|
||||
svcCloseHandle(mvdstdHandle);
|
||||
cleanup0:
|
||||
AtomicDecrement(&mvdstdRefCount);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Result mvdstdShutdown(void)
|
||||
void mvdstdExit(void)
|
||||
{
|
||||
if(!mvdstdInitialized)return 0;
|
||||
if (AtomicDecrement(&mvdstdRefCount)) return;
|
||||
|
||||
if(mvdstd_mode==MVDMODE_COLORFORMATCONV)
|
||||
{
|
||||
@ -188,20 +187,18 @@ Result mvdstdShutdown(void)
|
||||
svcCloseHandle(mvdstdHandle);
|
||||
|
||||
linearFree(mvdstd_workbuf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Result mvdstdProcessFrame(mvdstdConfig *config, u32 *h264_vaddr_inframe, u32 h264_inframesize, u32 h264_frameid)
|
||||
{
|
||||
Result ret;
|
||||
|
||||
if(!mvdstdInitialized)return 0;
|
||||
if(mvdstdRefCount==0)return 0;
|
||||
if(config==NULL)return -1;
|
||||
if(mvdstd_mode!=MVDMODE_COLORFORMATCONV)return -2;
|
||||
|
||||
ret = mvdstdSetConfig(config);
|
||||
if(ret<0)return ret;
|
||||
if(R_FAILED(ret))return ret;
|
||||
|
||||
return mvdstdipc_cmd1a();
|
||||
}
|
||||
|
@ -1,8 +1,10 @@
|
||||
#include <string.h>
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/result.h>
|
||||
#include <3ds/os.h>
|
||||
#include <3ds/svc.h>
|
||||
#include <3ds/srv.h>
|
||||
#include <3ds/synchronization.h>
|
||||
#include <3ds/services/news.h>
|
||||
#include <3ds/ipc.h>
|
||||
|
||||
@ -18,14 +20,20 @@ typedef struct {
|
||||
u16 title[32];
|
||||
} NotificationHeader;
|
||||
|
||||
static Handle newsHandle = 0;
|
||||
static Handle newsHandle;
|
||||
static int newsRefCount;
|
||||
|
||||
Result newsInit(void) {
|
||||
return srvGetServiceHandle(&newsHandle, "news:u");
|
||||
Result res;
|
||||
if (AtomicPostIncrement(&newsRefCount)) return 0;
|
||||
res = srvGetServiceHandle(&newsHandle, "news:u");
|
||||
if (R_FAILED(res)) AtomicDecrement(&newsRefCount);
|
||||
return res;
|
||||
}
|
||||
|
||||
Result newsExit(void) {
|
||||
return svcCloseHandle(newsHandle);
|
||||
void newsExit(void) {
|
||||
if (AtomicDecrement(&newsRefCount)) return;
|
||||
svcCloseHandle(newsHandle);
|
||||
}
|
||||
|
||||
Result NEWSU_AddNotification(const u16* title, u32 titleLength, const u16* message, u32 messageLength, const void* imageData, u32 imageSize, bool jpeg)
|
||||
@ -54,7 +62,7 @@ Result NEWSU_AddNotification(const u16* title, u32 titleLength, const u16* messa
|
||||
cmdbuf[10] = IPC_Desc_Buffer(imageSize,IPC_BUFFER_R);
|
||||
cmdbuf[11] = (u32) imageData;
|
||||
|
||||
if((ret = svcSendSyncRequest(newsHandle))!=0) return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(newsHandle))) return ret;
|
||||
|
||||
return (Result)cmdbuf[1];
|
||||
}
|
||||
|
@ -1,20 +1,28 @@
|
||||
#include <stdlib.h>
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/result.h>
|
||||
#include <3ds/svc.h>
|
||||
#include <3ds/srv.h>
|
||||
#include <3ds/synchronization.h>
|
||||
#include <3ds/services/ns.h>
|
||||
#include <3ds/ipc.h>
|
||||
|
||||
static Handle nsHandle;
|
||||
static int nsRefCount;
|
||||
|
||||
Result nsInit(void)
|
||||
{
|
||||
return srvGetServiceHandle(&nsHandle, "ns:s");
|
||||
Result res;
|
||||
if (AtomicPostIncrement(&nsRefCount)) return 0;
|
||||
res = srvGetServiceHandle(&nsHandle, "ns:s");
|
||||
if (R_FAILED(res)) AtomicDecrement(&nsRefCount);
|
||||
return res;
|
||||
}
|
||||
|
||||
Result nsExit(void)
|
||||
void nsExit(void)
|
||||
{
|
||||
return svcCloseHandle(nsHandle);
|
||||
if (AtomicDecrement(&nsRefCount)) return;
|
||||
svcCloseHandle(nsHandle);
|
||||
}
|
||||
|
||||
Result NS_LaunchTitle(u64 titleid, u32 launch_flags, u32 *procid)
|
||||
@ -27,7 +35,7 @@ Result NS_LaunchTitle(u64 titleid, u32 launch_flags, u32 *procid)
|
||||
cmdbuf[2] = (titleid >> 32) & 0xffffffff;
|
||||
cmdbuf[3] = launch_flags;
|
||||
|
||||
if((ret = svcSendSyncRequest(nsHandle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(nsHandle)))return ret;
|
||||
|
||||
if(procid != NULL)
|
||||
*procid = cmdbuf[2];
|
||||
@ -48,7 +56,7 @@ Result NS_RebootToTitle(u8 mediatype, u64 titleid)
|
||||
cmdbuf[5] = 0x0; // reserved
|
||||
cmdbuf[6] = 0x0;
|
||||
|
||||
if((ret = svcSendSyncRequest(nsHandle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(nsHandle)))return ret;
|
||||
|
||||
return (Result)cmdbuf[1];
|
||||
}
|
@ -1,21 +1,29 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/result.h>
|
||||
#include <3ds/svc.h>
|
||||
#include <3ds/srv.h>
|
||||
#include <3ds/synchronization.h>
|
||||
#include <3ds/services/pm.h>
|
||||
#include <3ds/ipc.h>
|
||||
|
||||
static Handle pmHandle;
|
||||
static int pmRefCount;
|
||||
|
||||
Result pmInit(void)
|
||||
{
|
||||
return srvGetServiceHandle(&pmHandle, "pm:app");
|
||||
Result res;
|
||||
if (AtomicPostIncrement(&pmRefCount)) return 0;
|
||||
res = srvGetServiceHandle(&pmHandle, "pm:app");
|
||||
if (R_FAILED(res)) AtomicDecrement(&pmRefCount);
|
||||
return res;
|
||||
}
|
||||
|
||||
Result pmExit(void)
|
||||
void pmExit(void)
|
||||
{
|
||||
return svcCloseHandle(pmHandle);
|
||||
if (AtomicDecrement(&pmRefCount)) return;
|
||||
svcCloseHandle(pmHandle);
|
||||
}
|
||||
|
||||
Result PM_LaunchTitle(u8 mediatype, u64 titleid, u32 launch_flags)
|
||||
@ -30,7 +38,7 @@ Result PM_LaunchTitle(u8 mediatype, u64 titleid, u32 launch_flags)
|
||||
cmdbuf[4] = 0x0;
|
||||
cmdbuf[5] = launch_flags;
|
||||
|
||||
if((ret = svcSendSyncRequest(pmHandle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(pmHandle)))return ret;
|
||||
|
||||
return (Result)cmdbuf[1];
|
||||
}
|
||||
@ -46,7 +54,7 @@ Result PM_GetTitleExheaderFlags(u8 mediatype, u64 titleid, u8* out)
|
||||
cmdbuf[3] = mediatype;
|
||||
cmdbuf[4] = 0x0;
|
||||
|
||||
if((ret = svcSendSyncRequest(pmHandle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(pmHandle)))return ret;
|
||||
|
||||
memcpy(out, (u8*)(&cmdbuf[2]), 8);
|
||||
|
||||
@ -63,7 +71,7 @@ Result PM_SetFIRMLaunchParams(u32 size, u8* in)
|
||||
cmdbuf[2] = IPC_Desc_Buffer(size,IPC_BUFFER_R);
|
||||
cmdbuf[3] = (u32)in;
|
||||
|
||||
if((ret = svcSendSyncRequest(pmHandle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(pmHandle)))return ret;
|
||||
|
||||
return (Result)cmdbuf[1];
|
||||
}
|
||||
@ -78,7 +86,7 @@ Result PM_GetFIRMLaunchParams(u32 size, u8* out)
|
||||
cmdbuf[2] = IPC_Desc_Buffer(size,IPC_BUFFER_W);
|
||||
cmdbuf[3] = (u32)out;
|
||||
|
||||
if((ret = svcSendSyncRequest(pmHandle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(pmHandle)))return ret;
|
||||
|
||||
return (Result)cmdbuf[1];
|
||||
}
|
||||
@ -94,7 +102,7 @@ Result PM_LaunchFIRMSetParams(u32 firm_titleid_low, u32 size, u8* in)
|
||||
cmdbuf[3] = IPC_Desc_Buffer(size,IPC_BUFFER_R);
|
||||
cmdbuf[4] = (u32)in;
|
||||
|
||||
if((ret = svcSendSyncRequest(pmHandle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(pmHandle)))return ret;
|
||||
|
||||
return (Result)cmdbuf[1];
|
||||
}
|
@ -1,20 +1,28 @@
|
||||
#include <stdlib.h>
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/result.h>
|
||||
#include <3ds/svc.h>
|
||||
#include <3ds/srv.h>
|
||||
#include <3ds/synchronization.h>
|
||||
#include <3ds/services/ps.h>
|
||||
#include <3ds/ipc.h>
|
||||
|
||||
static Handle psHandle;
|
||||
static int psRefCount;
|
||||
|
||||
Result psInit(void)
|
||||
{
|
||||
return srvGetServiceHandle(&psHandle, "ps:ps");
|
||||
Result res;
|
||||
if (AtomicPostIncrement(&psRefCount)) return 0;
|
||||
res = srvGetServiceHandle(&psHandle, "ps:ps");
|
||||
if (R_FAILED(res)) AtomicDecrement(&psRefCount);
|
||||
return res;
|
||||
}
|
||||
|
||||
Result psExit(void)
|
||||
void psExit(void)
|
||||
{
|
||||
return svcCloseHandle(psHandle);
|
||||
if (AtomicDecrement(&psRefCount)) return;
|
||||
svcCloseHandle(psHandle);
|
||||
}
|
||||
|
||||
Result PS_EncryptDecryptAes(u32 size, u8* in, u8* out, u32 aes_algo, u32 key_type, u8* iv)
|
||||
@ -37,7 +45,7 @@ Result PS_EncryptDecryptAes(u32 size, u8* in, u8* out, u32 aes_algo, u32 key_typ
|
||||
cmdbuf[10] = IPC_Desc_PXIBuffer(size,1,false);
|
||||
cmdbuf[11] = (u32)out;
|
||||
|
||||
if((ret = svcSendSyncRequest(psHandle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(psHandle)))return ret;
|
||||
|
||||
_iv[0] = cmdbuf[2];
|
||||
_iv[1] = cmdbuf[3];
|
||||
@ -70,7 +78,7 @@ Result PS_EncryptSignDecryptVerifyAesCcm(u8* in, u32 in_size, u8* out, u32 out_s
|
||||
cmdbuf[10] = IPC_Desc_PXIBuffer(out_size,1,false);
|
||||
cmdbuf[11] = (u32)out;
|
||||
|
||||
if((ret = svcSendSyncRequest(psHandle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(psHandle)))return ret;
|
||||
|
||||
return (Result)cmdbuf[1];
|
||||
}
|
||||
@ -82,7 +90,7 @@ Result PS_GetLocalFriendCodeSeed(u64* seed)
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0xA,0,0); // 0xA0000
|
||||
|
||||
if((ret = svcSendSyncRequest(psHandle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(psHandle)))return ret;
|
||||
|
||||
*seed = (u64)cmdbuf[2] | (u64)cmdbuf[3] << 32;
|
||||
|
||||
@ -96,7 +104,7 @@ Result PS_GetDeviceId(u32* device_id)
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0xB,0,0); // 0xB0000
|
||||
|
||||
if((ret = svcSendSyncRequest(psHandle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(psHandle)))return ret;
|
||||
|
||||
*device_id = cmdbuf[2];
|
||||
|
||||
|
@ -1,102 +1,107 @@
|
||||
#include <stdlib.h>
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/result.h>
|
||||
#include <3ds/svc.h>
|
||||
#include <3ds/srv.h>
|
||||
#include <3ds/synchronization.h>
|
||||
#include <3ds/services/ptm.h>
|
||||
#include <3ds/ipc.h>
|
||||
|
||||
|
||||
static Handle ptmHandle, ptmSysmHandle;
|
||||
static int ptmRefCount, ptmSysmRefCount;
|
||||
|
||||
Result ptmInit(void)
|
||||
{
|
||||
return srvGetServiceHandle(&ptmHandle, "ptm:u");
|
||||
if (AtomicPostIncrement(&ptmRefCount)) return 0;
|
||||
Result res = srvGetServiceHandle(&ptmHandle, "ptm:u");
|
||||
if (R_FAILED(res)) AtomicDecrement(&ptmRefCount);
|
||||
return res;
|
||||
}
|
||||
|
||||
Result ptmExit(void)
|
||||
void ptmExit(void)
|
||||
{
|
||||
return svcCloseHandle(ptmHandle);
|
||||
if (AtomicDecrement(&ptmRefCount)) return;
|
||||
svcCloseHandle(ptmHandle);
|
||||
}
|
||||
|
||||
Result ptmSysmInit(void)
|
||||
{
|
||||
return srvGetServiceHandle(&ptmSysmHandle, "ptm:sysm");
|
||||
if (AtomicPostIncrement(&ptmSysmRefCount)) return 0;
|
||||
Result res = srvGetServiceHandle(&ptmSysmHandle, "ptm:sysm");
|
||||
if (R_FAILED(res)) AtomicDecrement(&ptmSysmHandle);
|
||||
return res;
|
||||
}
|
||||
|
||||
Result ptmSysmExit(void)
|
||||
void ptmSysmExit(void)
|
||||
{
|
||||
return svcCloseHandle(ptmSysmHandle);
|
||||
if (AtomicDecrement(&ptmSysmHandle)) return;
|
||||
svcCloseHandle(ptmSysmHandle);
|
||||
}
|
||||
|
||||
Result PTMU_GetShellState(Handle* servhandle, u8 *out)
|
||||
Result PTMU_GetShellState(u8 *out)
|
||||
{
|
||||
if(!servhandle)servhandle=&ptmHandle;
|
||||
Result ret=0;
|
||||
u32 *cmdbuf = getThreadCommandBuffer();
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x6,0,0); // 0x60000
|
||||
|
||||
if((ret = svcSendSyncRequest(*servhandle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(ptmHandle)))return ret;
|
||||
|
||||
*out = (u8)cmdbuf[2];
|
||||
|
||||
return (Result)cmdbuf[1];
|
||||
}
|
||||
|
||||
Result PTMU_GetBatteryLevel(Handle* servhandle, u8 *out)
|
||||
Result PTMU_GetBatteryLevel(u8 *out)
|
||||
{
|
||||
if(!servhandle)servhandle=&ptmHandle;
|
||||
Result ret=0;
|
||||
u32 *cmdbuf = getThreadCommandBuffer();
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x7,0,0); // 0x70000
|
||||
|
||||
if((ret = svcSendSyncRequest(*servhandle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(ptmHandle)))return ret;
|
||||
|
||||
*out = (u8)cmdbuf[2];
|
||||
|
||||
return (Result)cmdbuf[1];
|
||||
}
|
||||
|
||||
Result PTMU_GetBatteryChargeState(Handle* servhandle, u8 *out)
|
||||
Result PTMU_GetBatteryChargeState(u8 *out)
|
||||
{
|
||||
if(!servhandle)servhandle=&ptmHandle;
|
||||
Result ret=0;
|
||||
u32 *cmdbuf = getThreadCommandBuffer();
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x8,0,0); // 0x80000
|
||||
|
||||
if((ret = svcSendSyncRequest(*servhandle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(ptmHandle)))return ret;
|
||||
|
||||
*out = (u8)cmdbuf[2];
|
||||
|
||||
return (Result)cmdbuf[1];
|
||||
}
|
||||
|
||||
Result PTMU_GetPedometerState(Handle* servhandle, u8 *out)
|
||||
Result PTMU_GetPedometerState(u8 *out)
|
||||
{
|
||||
if(!servhandle)servhandle=&ptmHandle;
|
||||
Result ret=0;
|
||||
u32 *cmdbuf = getThreadCommandBuffer();
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x9,0,0); // 0x90000
|
||||
|
||||
if((ret = svcSendSyncRequest(*servhandle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(ptmHandle)))return ret;
|
||||
|
||||
*out = (u8)cmdbuf[2];
|
||||
|
||||
return (Result)cmdbuf[1];
|
||||
}
|
||||
|
||||
Result PTMU_GetTotalStepCount(Handle* servhandle, u32 *steps)
|
||||
Result PTMU_GetTotalStepCount(u32 *steps)
|
||||
{
|
||||
if(!servhandle)servhandle=&ptmHandle;
|
||||
Result ret=0;
|
||||
u32 *cmdbuf = getThreadCommandBuffer();
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0xC,0,0); // 0xC0000
|
||||
|
||||
if((ret = svcSendSyncRequest(*servhandle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(ptmHandle)))return ret;
|
||||
|
||||
*steps = cmdbuf[2];
|
||||
|
||||
@ -111,7 +116,7 @@ Result PTMSYSM_ConfigureNew3DSCPU(u8 value)
|
||||
cmdbuf[0] = IPC_MakeHeader(0x818,1,0); // 0x08180040
|
||||
cmdbuf[1] = value;
|
||||
|
||||
if((ret = svcSendSyncRequest(ptmSysmHandle))!=0)return ret;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(ptmSysmHandle)))return ret;
|
||||
|
||||
return (Result)cmdbuf[1];
|
||||
}
|
||||
|
@ -4,56 +4,55 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/result.h>
|
||||
#include <3ds/svc.h>
|
||||
#include <3ds/srv.h>
|
||||
#include <3ds/synchronization.h>
|
||||
#include <3ds/services/qtm.h>
|
||||
#include <3ds/ipc.h>
|
||||
|
||||
Handle qtmHandle;
|
||||
|
||||
static bool qtmInitialized = false;
|
||||
static int qtmRefCount;
|
||||
|
||||
Result qtmInit(void)
|
||||
{
|
||||
Result ret=0;
|
||||
|
||||
if(qtmInitialized)return 0;
|
||||
if (AtomicPostIncrement(&qtmRefCount)) return 0;
|
||||
|
||||
if((ret=srvGetServiceHandle(&qtmHandle, "qtm:u")) && (ret=srvGetServiceHandle(&qtmHandle, "qtm:s")) && (ret=srvGetServiceHandle(&qtmHandle, "qtm:sp")))return ret;
|
||||
|
||||
qtmInitialized = true;
|
||||
|
||||
return 0;
|
||||
ret = srvGetServiceHandle(&qtmHandle, "qtm:u");
|
||||
if (R_FAILED(ret)) ret = srvGetServiceHandle(&qtmHandle, "qtm:s");
|
||||
if (R_FAILED(ret)) ret = srvGetServiceHandle(&qtmHandle, "qtm:sp");
|
||||
if (R_FAILED(ret)) AtomicDecrement(&qtmRefCount);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void qtmExit(void)
|
||||
{
|
||||
if(!qtmInitialized)return;
|
||||
|
||||
if (AtomicDecrement(&qtmRefCount)) return;
|
||||
svcCloseHandle(qtmHandle);
|
||||
qtmInitialized = false;
|
||||
}
|
||||
|
||||
bool qtmCheckInitialized(void)
|
||||
{
|
||||
return qtmInitialized;
|
||||
return qtmRefCount>0;
|
||||
}
|
||||
|
||||
Result qtmGetHeadtrackingInfo(u64 val, qtmHeadtrackingInfo *out)
|
||||
{
|
||||
u32* cmdbuf=getThreadCommandBuffer();
|
||||
|
||||
if(!qtmInitialized)return -1;
|
||||
if(!qtmCheckInitialized())return -1;
|
||||
|
||||
cmdbuf[0]=IPC_MakeHeader(0x2,2,0); // 0x20080
|
||||
cmdbuf[1] = val&0xFFFFFFFF;
|
||||
cmdbuf[2] = val>>32;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svcSendSyncRequest(qtmHandle)))return ret;
|
||||
if(R_FAILED(ret=svcSendSyncRequest(qtmHandle)))return ret;
|
||||
|
||||
ret = (Result)cmdbuf[1];
|
||||
if(ret!=0)return ret;
|
||||
if(R_FAILED(ret))return ret;
|
||||
|
||||
if(out)memcpy(out, &cmdbuf[2], sizeof(qtmHeadtrackingInfo));
|
||||
|
||||
|
@ -4,48 +4,34 @@
|
||||
#include <3ds/srv.h>
|
||||
#include <3ds/svc.h>
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/result.h>
|
||||
#include <3ds/ipc.h>
|
||||
#include <3ds/synchronization.h>
|
||||
|
||||
Handle y2rHandle = 0;
|
||||
static bool initialized = false;
|
||||
Handle y2rHandle;
|
||||
static int y2rRefCount;
|
||||
|
||||
Result y2rInit(void)
|
||||
{
|
||||
Result ret = 0;
|
||||
|
||||
if (initialized) return 0;
|
||||
if (AtomicPostIncrement(&y2rRefCount)) return 0;
|
||||
|
||||
if (y2rHandle == 0)
|
||||
{
|
||||
ret = srvGetServiceHandle(&y2rHandle, "y2r:u");
|
||||
if (ret < 0) return ret;
|
||||
}
|
||||
|
||||
if (R_SUCCEEDED(ret))
|
||||
{
|
||||
ret = Y2RU_DriverInitialize();
|
||||
if (ret < 0) return ret;
|
||||
initialized = true;
|
||||
|
||||
return 0;
|
||||
if (R_FAILED(ret)) svcCloseHandle(y2rHandle);
|
||||
}
|
||||
if (R_FAILED(ret)) AtomicDecrement(&y2rRefCount);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Result y2rExit(void)
|
||||
void y2rExit(void)
|
||||
{
|
||||
Result ret = 0;
|
||||
|
||||
if (initialized)
|
||||
{
|
||||
ret = Y2RU_DriverFinalize();
|
||||
if (ret < 0) return ret;
|
||||
}
|
||||
|
||||
if (y2rHandle != 0)
|
||||
{
|
||||
ret = svcCloseHandle(y2rHandle);
|
||||
if (ret < 0) return ret;
|
||||
y2rHandle = 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
if (AtomicDecrement(&y2rRefCount)) return;
|
||||
Y2RU_DriverFinalize();
|
||||
svcCloseHandle(y2rHandle);
|
||||
}
|
||||
|
||||
Result Y2RU_SetInputFormat(Y2R_InputFormat format)
|
||||
@ -55,7 +41,7 @@ Result Y2RU_SetInputFormat(Y2R_InputFormat format)
|
||||
cmdbuf[0] = IPC_MakeHeader(0x1,1,0); // 0x10040
|
||||
cmdbuf[1] = format;
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -65,7 +51,7 @@ Result Y2RU_GetInputFormat(Y2R_InputFormat* format)
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(0x2,0,0); // 0x20000
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
*format = cmdbuf[2] & 0xFF;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -77,7 +63,7 @@ Result Y2RU_SetOutputFormat(Y2R_OutputFormat format)
|
||||
cmdbuf[0] = IPC_MakeHeader(0x3,1,0); // 0x30040
|
||||
cmdbuf[1] = format;
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -87,7 +73,7 @@ Result Y2RU_GetOutputFormat(Y2R_OutputFormat* format)
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(0x4,0,0); // 0x40000
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
*format = cmdbuf[2] & 0xFF;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -99,7 +85,7 @@ Result Y2RU_SetRotation(Y2R_Rotation rotation)
|
||||
cmdbuf[0] = IPC_MakeHeader(0x5,1,0); // 0x50040
|
||||
cmdbuf[1] = rotation;
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -109,7 +95,7 @@ Result Y2RU_GetRotation(Y2R_Rotation* rotation)
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(0x6,0,0); // 0x60000
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
*rotation = cmdbuf[2] & 0xFF;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -121,7 +107,7 @@ Result Y2RU_SetBlockAlignment(Y2R_BlockAlignment alignment)
|
||||
cmdbuf[0] = IPC_MakeHeader(0x7,1,0); // 0x70040
|
||||
cmdbuf[1] = alignment;
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -131,7 +117,7 @@ Result Y2RU_GetBlockAlignment(Y2R_BlockAlignment* alignment)
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(0x8,0,0); // 0x80000
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
*alignment = cmdbuf[2] & 0xFF;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -143,7 +129,7 @@ Result Y2RU_SetSpacialDithering(bool enable)
|
||||
cmdbuf[0] = IPC_MakeHeader(0x9,1,0); // 0x90040
|
||||
cmdbuf[1] = enable;
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -153,7 +139,7 @@ Result Y2RU_GetSpacialDithering(bool* enabled)
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(0xA,0,0); // 0xA0000
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
*enabled = cmdbuf[2] & 0xFF;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -165,7 +151,7 @@ Result Y2RU_SetTemporalDithering(bool enable)
|
||||
cmdbuf[0] = IPC_MakeHeader(0xB,1,0); // 0xB0040
|
||||
cmdbuf[1] = enable;
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -175,7 +161,7 @@ Result Y2RU_GetTemporalDithering(bool* enabled)
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(0xC,0,0); // 0xC0000
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
*enabled = cmdbuf[2] & 0xFF;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -187,7 +173,7 @@ Result Y2RU_SetTransferEndInterrupt(bool should_interrupt)
|
||||
cmdbuf[0] = IPC_MakeHeader(0xD,1,0); // 0xD0040
|
||||
cmdbuf[1] = should_interrupt;
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -197,7 +183,7 @@ Result Y2RU_GetTransferEndInterrupt(bool* should_interrupt)
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(0xE,0,0); // 0xE0000
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
*should_interrupt = cmdbuf[2] & 0xFF;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -214,7 +200,7 @@ Result Y2RU_GetTransferEndEvent(Handle* end_event)
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(0xF,0,0); // 0xF0000
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
|
||||
*end_event = cmdbuf[3];
|
||||
return cmdbuf[1];
|
||||
@ -232,7 +218,7 @@ Result Y2RU_SetSendingY(const void* src_buf, u32 image_size, s16 transfer_unit,
|
||||
cmdbuf[5] = IPC_Desc_SharedHandles(1);
|
||||
cmdbuf[6] = CUR_PROCESS_HANDLE;
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -248,7 +234,7 @@ Result Y2RU_SetSendingU(const void* src_buf, u32 image_size, s16 transfer_unit,
|
||||
cmdbuf[5] = IPC_Desc_SharedHandles(1);
|
||||
cmdbuf[6] = CUR_PROCESS_HANDLE;
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -264,7 +250,7 @@ Result Y2RU_SetSendingV(const void* src_buf, u32 image_size, s16 transfer_unit,
|
||||
cmdbuf[5] = IPC_Desc_SharedHandles(1);
|
||||
cmdbuf[6] = CUR_PROCESS_HANDLE;
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -280,7 +266,7 @@ Result Y2RU_SetSendingYUYV(const void* src_buf, u32 image_size, s16 transfer_uni
|
||||
cmdbuf[5] = IPC_Desc_SharedHandles(1);
|
||||
cmdbuf[6] = CUR_PROCESS_HANDLE;
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -290,7 +276,7 @@ Result Y2RU_IsDoneSendingYUYV(bool* is_done)
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(0x14,0,0); // 0x140000
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
*is_done = cmdbuf[2] & 0xFF;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -301,7 +287,7 @@ Result Y2RU_IsDoneSendingY(bool* is_done)
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(0x15,0,0); // 0x150000
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
*is_done = cmdbuf[2] & 0xFF;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -312,7 +298,7 @@ Result Y2RU_IsDoneSendingU(bool* is_done)
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(0x16,0,0); // 0x160000
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
*is_done = cmdbuf[2] & 0xFF;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -323,7 +309,7 @@ Result Y2RU_IsDoneSendingV(bool* is_done)
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(0x17,0,0); // 0x170000
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
*is_done = cmdbuf[2] & 0xFF;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -340,7 +326,7 @@ Result Y2RU_SetReceiving(void* dst_buf, u32 image_size, s16 transfer_unit, s16 t
|
||||
cmdbuf[5] = IPC_Desc_SharedHandles(1);
|
||||
cmdbuf[6] = CUR_PROCESS_HANDLE;
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -350,7 +336,7 @@ Result Y2RU_IsDoneReceiving(bool* is_done)
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(0x19,0,0); // 0x190000
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
*is_done = cmdbuf[2] & 0xFF;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -362,7 +348,7 @@ Result Y2RU_SetInputLineWidth(u16 line_width)
|
||||
cmdbuf[0] = IPC_MakeHeader(0x1A,1,0); // 0x1A0040
|
||||
cmdbuf[1] = line_width;
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -372,7 +358,7 @@ Result Y2RU_GetInputLineWidth(u16* line_width)
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(0x1B,0,0); // 0x1B0000
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
*line_width = cmdbuf[2] & 0xFFFF;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -384,7 +370,7 @@ Result Y2RU_SetInputLines(u16 num_lines)
|
||||
cmdbuf[0] = IPC_MakeHeader(0x1C,1,0); // 0x1C0040
|
||||
cmdbuf[1] = num_lines;
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -394,7 +380,7 @@ Result Y2RU_GetInputLines(u16* num_lines)
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(0x1D,0,0); // 0x1D0000
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
*num_lines = cmdbuf[2] & 0xFFFF;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -406,7 +392,7 @@ Result Y2RU_SetCoefficients(const Y2R_ColorCoefficients* coefficients)
|
||||
cmdbuf[0] = IPC_MakeHeader(0x1E,4,0); // 0x1E0100
|
||||
memcpy(&cmdbuf[1], coefficients, sizeof(Y2R_ColorCoefficients));
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -416,7 +402,7 @@ Result Y2RU_GetCoefficients(Y2R_ColorCoefficients* coefficients)
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(0x1F,0,0); // 0x1F0000
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
memcpy(coefficients,cmdbuf + 2, sizeof(Y2R_ColorCoefficients));
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -428,7 +414,7 @@ Result Y2RU_SetStandardCoefficient(Y2R_StandardCoefficient coefficient)
|
||||
cmdbuf[0] = IPC_MakeHeader(0x20,1,0); // 0x200040
|
||||
cmdbuf[1] = coefficient;
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -439,7 +425,7 @@ Result Y2RU_GetStandardCoefficient(Y2R_ColorCoefficients* coefficients, Y2R_Stan
|
||||
cmdbuf[0] = IPC_MakeHeader(0x21,1,0); // 0x210040
|
||||
cmdbuf[1] = standardCoeff;
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
memcpy(coefficients,cmdbuf + 2, sizeof(Y2R_ColorCoefficients));
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -451,7 +437,7 @@ Result Y2RU_SetAlpha(u16 alpha)
|
||||
cmdbuf[0] = IPC_MakeHeader(0x22,1,0); // 0x220040
|
||||
cmdbuf[1] = alpha;
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -461,7 +447,7 @@ Result Y2RU_GetAlpha(u16* alpha)
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(0x23,0,0); // 0x230000
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
*alpha = cmdbuf[2] & 0xFFFF;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -474,7 +460,7 @@ Result Y2RU_SetDitheringWeightParams(const Y2R_DitheringWeightParams* params)
|
||||
cmdbuf[0] = IPC_MakeHeader(0x24,8,0); // 0x240200
|
||||
memcpy(&cmdbuf[1], params, sizeof(Y2R_DitheringWeightParams));
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -484,7 +470,7 @@ Result Y2RU_GetDitheringWeightParams(Y2R_DitheringWeightParams* params)
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(0x25,0,0); // 0x250000
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
memcpy(params,cmdbuf+2, sizeof(Y2R_DitheringWeightParams));
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -495,7 +481,7 @@ Result Y2RU_StartConversion(void)
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(0x26,0,0); // 0x260000
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -505,7 +491,7 @@ Result Y2RU_StopConversion(void)
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(0x27,0,0); // 0x270000
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -515,7 +501,7 @@ Result Y2RU_IsBusyConversion(bool* is_busy)
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(0x28,0,0); // 0x280000
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
*is_busy = cmdbuf[2] & 0xFF;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -527,7 +513,7 @@ Result Y2RU_SetConversionParams(const Y2R_ConversionParams* params)
|
||||
cmdbuf[0] = IPC_MakeHeader(0x29,7,0); // 0x2901C0
|
||||
memcpy(&cmdbuf[1], params, sizeof(Y2R_ConversionParams));
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -537,7 +523,7 @@ Result Y2RU_PingProcess(u8* ping)
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(0x2A,0,0); // 0x2A0000
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
*ping = (u8)cmdbuf[2];
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -548,7 +534,7 @@ Result Y2RU_DriverInitialize(void)
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(0x2B,0,0); // 0x2B0000
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
@ -558,6 +544,6 @@ Result Y2RU_DriverFinalize(void)
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = IPC_MakeHeader(0x2C,0,0); // 0x2C0000
|
||||
|
||||
if ((ret = svcSendSyncRequest(y2rHandle)) != 0) return ret;
|
||||
if (R_FAILED(ret = svcSendSyncRequest(y2rHandle))) return ret;
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include <string.h>
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/result.h>
|
||||
#include <3ds/srv.h>
|
||||
#include <3ds/svc.h>
|
||||
#include <3ds/ipc.h>
|
||||
@ -31,7 +32,7 @@ typedef struct {
|
||||
|
||||
extern service_list_t* __service_ptr;
|
||||
|
||||
static Handle g_srv_handle = 0;
|
||||
static Handle g_srv_handle;
|
||||
|
||||
|
||||
static int __name_cmp(const char* a, const char* b) {
|
||||
@ -80,9 +81,9 @@ Result srvInit(void)
|
||||
|
||||
if(g_srv_handle != 0) return rc;
|
||||
|
||||
if((rc = svcConnectToPort(&g_srv_handle, "srv:")))return rc;
|
||||
if(R_FAILED(rc = svcConnectToPort(&g_srv_handle, "srv:")))return rc;
|
||||
|
||||
if((rc = srvRegisterClient())) {
|
||||
if(R_FAILED(rc = srvRegisterClient())) {
|
||||
svcCloseHandle(g_srv_handle);
|
||||
g_srv_handle = 0;
|
||||
}
|
||||
@ -112,7 +113,7 @@ Result srvRegisterClient(void)
|
||||
cmdbuf[0] = IPC_MakeHeader(0x1,0,2); // 0x10002
|
||||
cmdbuf[1] = IPC_Desc_CurProcessHandle();
|
||||
|
||||
if((rc = svcSendSyncRequest(g_srv_handle)))return rc;
|
||||
if(R_FAILED(rc = svcSendSyncRequest(g_srv_handle)))return rc;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -127,7 +128,7 @@ Result srvGetServiceHandleDirect(Handle* out, const char* name)
|
||||
cmdbuf[3] = strlen(name);
|
||||
cmdbuf[4] = 0x0;
|
||||
|
||||
if((rc = svcSendSyncRequest(g_srv_handle)))return rc;
|
||||
if(R_FAILED(rc = svcSendSyncRequest(g_srv_handle)))return rc;
|
||||
|
||||
*out = cmdbuf[3];
|
||||
return cmdbuf[1];
|
||||
@ -156,7 +157,7 @@ Result srvRegisterService(Handle* out, const char* name, int maxSessions)
|
||||
cmdbuf[4] = maxSessions;
|
||||
|
||||
Result rc;
|
||||
if((rc = svcSendSyncRequest(g_srv_handle)))return rc;
|
||||
if(R_FAILED(rc = svcSendSyncRequest(g_srv_handle)))return rc;
|
||||
|
||||
*out = cmdbuf[3];
|
||||
return cmdbuf[1];
|
||||
@ -170,7 +171,7 @@ Result srvUnregisterService(const char* name)
|
||||
cmdbuf[3] = strlen(name);
|
||||
|
||||
Result rc;
|
||||
if((rc = svcSendSyncRequest(g_srv_handle)))return rc;
|
||||
if(R_FAILED(rc = svcSendSyncRequest(g_srv_handle)))return rc;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -180,9 +181,9 @@ Result srvPmInit(void)
|
||||
{
|
||||
Result rc = 0;
|
||||
|
||||
if((rc = svcConnectToPort(&g_srv_handle, "srv:pm")))return rc;
|
||||
if(R_FAILED(rc = svcConnectToPort(&g_srv_handle, "srv:pm")))return rc;
|
||||
|
||||
if((rc = srvRegisterClient())) {
|
||||
if(R_FAILED(rc = srvRegisterClient())) {
|
||||
svcCloseHandle(g_srv_handle);
|
||||
g_srv_handle = 0;
|
||||
}
|
||||
@ -202,7 +203,7 @@ Result srvRegisterProcess(u32 procid, u32 count, void *serviceaccesscontrol)
|
||||
cmdbuf[3] = IPC_Desc_StaticBuffer(count*4,0);
|
||||
cmdbuf[4] = (u32)serviceaccesscontrol;
|
||||
|
||||
if((rc = svcSendSyncRequest(g_srv_handle))) return rc;
|
||||
if(R_FAILED(rc = svcSendSyncRequest(g_srv_handle))) return rc;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@ -216,7 +217,7 @@ Result srvUnregisterProcess(u32 procid)
|
||||
cmdbuf[0] = IPC_MakeHeader(0x404,1,0); // 0x4040040 // <7.x
|
||||
cmdbuf[1] = procid;
|
||||
|
||||
if((rc = svcSendSyncRequest(g_srv_handle))) return rc;
|
||||
if(R_FAILED(rc = svcSendSyncRequest(g_srv_handle))) return rc;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user