Merge branch 'refactor' of github.com:smealum/ctrulib into refactor

This commit is contained in:
smea 2014-08-24 21:01:35 -07:00
commit f9fbfc3c48
13 changed files with 5920 additions and 359 deletions

2
libctru/.gitignore vendored
View File

@ -1,2 +1,4 @@
build build
lib lib
docs
internal_docs

2303
libctru/Doxyfile Normal file

File diff suppressed because it is too large Load Diff

2303
libctru/Doxyfile.internal Normal file

File diff suppressed because it is too large Load Diff

View File

@ -17,7 +17,7 @@ include $(DEVKITARM)/base_rules
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
TARGET := ctru TARGET := ctru
BUILD := build BUILD := build
SOURCES := source source/services SOURCES := source source/services source/gpu
DATA := data DATA := data
INCLUDES := include INCLUDES := include
@ -87,6 +87,10 @@ export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
all: $(BUILD) all: $(BUILD)
dox:
@doxygen Doxyfile
@doxygen Doxyfile.internal
lib: lib:
@[ -d $@ ] || mkdir -p $@ @[ -d $@ ] || mkdir -p $@
@ -97,7 +101,7 @@ $(BUILD): lib
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
clean: clean:
@echo clean ... @echo clean ...
@rm -fr $(BUILD) lib @rm -fr $(BUILD) lib docs internal_docs
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
else else

View File

@ -1,39 +1,146 @@
#pragma once
#ifndef FS_H #ifndef FS_H
#define FS_H #define FS_H
/*! @file FS.h
*
* Filesystem Services
*/
#include <string.h>
#include <3ds/types.h>
#ifdef __cplusplus
extern "C"
{
#endif
/*! @defgroup fs_open_flags FS Open Flags
*
* @sa FSUSER_OpenFile
* @sa FSUSER_OpenFileDirectly
*
* @{
*/
/*! Open file for read. */
#define FS_OPEN_READ (1<<0) #define FS_OPEN_READ (1<<0)
/*! Open file for write. */
#define FS_OPEN_WRITE (1<<1) #define FS_OPEN_WRITE (1<<1)
/*! Create file if it doesn't exist. */
#define FS_OPEN_CREATE (1<<2) #define FS_OPEN_CREATE (1<<2)
/* @} */
/*! @defgroup fs_create_attributes FS Create Attributes
*
* @sa FSUSER_OpenFile
* @sa FSUSER_OpenFileDirectly
*
* @{
*/
/*! No attributes. */
#define FS_ATTRIBUTE_NONE (0x00000000) #define FS_ATTRIBUTE_NONE (0x00000000)
/*! Create with read-only attribute. */
#define FS_ATTRIBUTE_READONLY (0x00000001) #define FS_ATTRIBUTE_READONLY (0x00000001)
/*! Create with archive attribute. */
#define FS_ATTRIBUTE_ARCHIVE (0x00000100) #define FS_ATTRIBUTE_ARCHIVE (0x00000100)
/*! Create with hidden attribute. */
#define FS_ATTRIBUTE_HIDDEN (0x00010000) #define FS_ATTRIBUTE_HIDDEN (0x00010000)
/*! Create with directory attribute. */
#define FS_ATTRIBUTE_DIRECTORY (0x01000000) #define FS_ATTRIBUTE_DIRECTORY (0x01000000)
/*! @} */
typedef enum{ /*! @defgroup fs_write_flush_flags FS Flush Flags
PATH_INVALID = 0, // Specifies an invalid path. *
PATH_EMPTY = 1, // Specifies an empty path. * @sa FSFILE_Write
PATH_BINARY = 2, // Specifies a binary path, which is non-text based. *
PATH_CHAR = 3, // Specifies a text based path with a 8-bit byte per character. * @{
PATH_WCHAR = 4, // Specifies a text based path with a 16-bit short per character. */
/*! Don't flush */
#define FS_WRITE_NOFLUSH (0x00000000)
/*! Flush */
#define FS_WRITE_FLUSH (0x00010001)
/* @} */
/*! FS path type */
typedef enum
{
PATH_INVALID = 0, //!< Specifies an invalid path.
PATH_EMPTY = 1, //!< Specifies an empty path.
PATH_BINARY = 2, //!< Specifies a binary path, which is non-text based.
PATH_CHAR = 3, //!< Specifies a text based path with a 8-bit byte per character.
PATH_WCHAR = 4, //!< Specifies a text based path with a 16-bit short per character.
} FS_pathType; } FS_pathType;
typedef struct{ /*! FS path */
FS_pathType type; typedef struct
u32 size; {
u8* data; FS_pathType type; //!< FS path type.
u32 size; //!< FS path size.
const u8 *data; //!< Pointer to FS path data.
} FS_path; } FS_path;
typedef struct{ /*! FS archive */
u32 id; typedef struct
FS_path lowPath; {
Handle handleLow, handleHigh; u32 id; //!< Archive ID.
FS_path lowPath; //!< FS path.
Handle handleLow; //!< High word of handle.
Handle handleHigh; //!< Low word of handle.
} FS_archive; } FS_archive;
static inline FS_path FS_makePath(FS_pathType type, char* path) /*! Directory entry */
typedef struct
{ {
return (FS_path){type, strlen(path)+1, (u8*)path}; // 0x00
u16 name[0x106]; //!< UTF-16 encoded name
// 0x20C
u8 shortName[0x09]; //!< 8.3 file name
// 0x215
u8 unknown1; //!< ???
// 0x216
u8 shortExt[0x04]; //!< 8.3 file extension (set to spaces for directories)
// 0x21A
u8 unknown2; //!< ???
// 0x21B
u8 unknown3; //!< ???
// 0x21C
u8 isDirectory; //!< 0x00 for files, 0x01 for directories
// 0x21D
u8 unknown4; //!< ???
// 0x21E
u8 isFile; //!< 0x01 for files, 0x00 for directories
// 0x21F
u8 unknown5; //!< ???
// 0x220
u8 unknown6; //!< ???
// 0x221
u8 unknown7; //!< ???
// 0x222
u8 unknown8; //!< ???
// 0x223
u8 unknown9; //!< ???
// 0x224
u8 padding[0x04]; //!< ???
} FS_dirent;
/*! Create an FS_path from a type and data pointer.
*
* @param[in] type Path type.
* @param[in] path Pointer to path data.
*
* @returns FS_path
*
* @sa FS_pathType
*/
static inline FS_path
FS_makePath(FS_pathType type,
const char *path)
{
return (FS_path){type, strlen(path)+1, (const u8*)path};
} }
Result fsInit(void); Result fsInit(void);
@ -45,14 +152,24 @@ Result FSUSER_OpenDirectory(Handle* handle, Handle* out, FS_archive archive, FS_
Result FSUSER_OpenFile(Handle* handle, Handle* out, FS_archive archive, FS_path fileLowPath, u32 openflags, u32 attributes); Result FSUSER_OpenFile(Handle* handle, Handle* out, FS_archive archive, FS_path fileLowPath, u32 openflags, u32 attributes);
Result FSUSER_OpenFileDirectly(Handle* handle, Handle* out, FS_archive archive, FS_path fileLowPath, u32 openflags, u32 attributes); Result FSUSER_OpenFileDirectly(Handle* handle, Handle* out, FS_archive archive, FS_path fileLowPath, u32 openflags, u32 attributes);
Result FSUSER_CloseArchive(Handle* handle, FS_archive* archive); Result FSUSER_CloseArchive(Handle* handle, FS_archive* archive);
Result FSUSER_CreateDirectory(Handle* handle, FS_archive archive, FS_path dirLowPath);
Result FSUSER_DeleteFile(Handle *handle, FS_archive archive, FS_path fileLowPath);
Result FSUSER_DeleteDirectory(Handle *handle, FS_archive archive, FS_path dirLowPath);
Result FSFILE_Close(Handle handle); Result FSFILE_Close(Handle handle);
Result FSFILE_Read(Handle handle, u32 *bytesRead, u64 offset, u32 *buffer, u32 size); Result FSFILE_Read(Handle handle, u32 *bytesRead, u64 offset, void *buffer, u32 size);
Result FSFILE_Write(Handle handle, u32 *bytesWritten, u64 offset, u32 *buffer, u32 size, u32 flushFlags); Result FSFILE_Write(Handle handle, u32 *bytesWritten, u64 offset, const void *buffer, u32 size, u32 flushFlags);
Result FSFILE_GetSize(Handle handle, u64 *size); Result FSFILE_GetSize(Handle handle, u64 *size);
Result FSFILE_SetSize(Handle handle, u64 size); Result FSFILE_SetSize(Handle handle, u64 size);
Result FSFILE_GetAttributes(Handle handle, u32 *attributes);
Result FSFILE_SetAttributes(Handle handle, u32 attributes);
Result FSFILE_Flush(Handle handle);
Result FSDIR_Read(Handle handle, u32 *entriesRead, u32 entrycount, u16 *buffer); Result FSDIR_Read(Handle handle, u32 *entriesRead, u32 entrycount, FS_dirent *buffer);
Result FSDIR_Close(Handle handle); Result FSDIR_Close(Handle handle);
#ifdef __cplusplus
}
#endif
#endif #endif

View File

@ -79,7 +79,6 @@ Result GSPGPU_ReadHWRegs(Handle *handle, u32 regAddr, u32* data, u8 size);
Result GSPGPU_RegisterInterruptRelayQueue(Handle *handle, Handle eventHandle, u32 flags, Handle* outMemHandle, u8* threadID); Result GSPGPU_RegisterInterruptRelayQueue(Handle *handle, Handle eventHandle, u32 flags, Handle* outMemHandle, u8* threadID);
Result GSPGPU_UnregisterInterruptRelayQueue(Handle* handle); Result GSPGPU_UnregisterInterruptRelayQueue(Handle* handle);
Result GSPGPU_TriggerCmdReqQueue(Handle *handle); Result GSPGPU_TriggerCmdReqQueue(Handle *handle);
Result GSPGPU_SubmitGxCommand(u32* sharedGspCmdBuf, u32 gxCommand[0x8], Handle* handle);
Result GSPGPU_submitGxCommand(u32* sharedGspCmdBuf, u32 gxCommand[0x8], Handle* handle);
#endif #endif

View File

@ -1,3 +1,7 @@
/*
gpu.c _ Advanced GPU commands.
*/
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <3ds/types.h> #include <3ds/types.h>

View File

@ -1,3 +1,7 @@
/*
shdr.c _ Shader loader.
*/
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <3ds/types.h> #include <3ds/types.h>

View File

@ -1,3 +1,7 @@
/*
apt.c _ Applet/NS shell interaction
*/
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <3ds/types.h> #include <3ds/types.h>
@ -20,11 +24,12 @@ u64 aptEventHandlerStack[APT_HANDLER_STACKSIZE/8]; //u64 so that it's 8-byte ali
Handle aptStatusMutex; Handle aptStatusMutex;
Handle aptStatusEvent = 0; Handle aptStatusEvent = 0;
APP_STATUS aptStatus = APP_NOTINITIALIZED; APP_STATUS aptStatus = APP_NOTINITIALIZED;
APP_STATUS aptStatus_beforesleepmode = APP_NOTINITIALIZED; APP_STATUS aptStatusBeforeSleep = APP_NOTINITIALIZED;
u32 aptStatusPower = 0; u32 aptStatusPower = 0;
u32 aptParameters[0x1000/4]; //TEMP u32 aptParameters[0x1000/4]; //TEMP
void aptInitCaptureInfo(u32 *ns_capinfo) void aptInitCaptureInfo(u32 *ns_capinfo)
{ {
u32 tmp=0; u32 tmp=0;
@ -33,30 +38,17 @@ void aptInitCaptureInfo(u32 *ns_capinfo)
memset(&gspcapinfo, 0, sizeof(GSP_CaptureInfo)); memset(&gspcapinfo, 0, sizeof(GSP_CaptureInfo));
// Get display-capture info from GSP.
GSPGPU_ImportDisplayCaptureInfo(NULL, &gspcapinfo); GSPGPU_ImportDisplayCaptureInfo(NULL, &gspcapinfo);
// Fill in display-capture info for NS.
if(gspcapinfo.screencapture[0].framebuf0_vaddr != gspcapinfo.screencapture[1].framebuf0_vaddr)ns_capinfo[1] = 1; if(gspcapinfo.screencapture[0].framebuf0_vaddr != gspcapinfo.screencapture[1].framebuf0_vaddr)ns_capinfo[1] = 1;
ns_capinfo[4] = gspcapinfo.screencapture[0].format & 0x7; ns_capinfo[4] = gspcapinfo.screencapture[0].format & 0x7;
ns_capinfo[7] = gspcapinfo.screencapture[1].format & 0x7; ns_capinfo[7] = gspcapinfo.screencapture[1].format & 0x7;
if(ns_capinfo[4] < 2) main_pixsz = (ns_capinfo[4] < 2) ? 3 : 2;
{ sub_pixsz = (ns_capinfo[7] < 2) ? 3 : 2;
main_pixsz = 3;
}
else
{
main_pixsz = 2;
}
if(ns_capinfo[7] < 2)
{
sub_pixsz = 3;
}
else
{
sub_pixsz = 2;
}
ns_capinfo[2] = sub_pixsz * 0x14000; ns_capinfo[2] = sub_pixsz * 0x14000;
ns_capinfo[3] = ns_capinfo[2]; ns_capinfo[3] = ns_capinfo[2];
@ -122,22 +114,27 @@ void aptReturnToMenu()
u32 ns_capinfo[0x20>>2]; u32 ns_capinfo[0x20>>2];
u32 tmp_params[0x20>>2]; u32 tmp_params[0x20>>2];
if(aptGetStatusPower()==0)//This is only executed when ret-to-menu was triggered via the home-button, not the power-button. // This is only executed when ret-to-menu was triggered via the home-button, not the power-button.
if(aptGetStatusPower() == 0)
{ {
aptOpenSession(); aptOpenSession();
APT_AppletUtility(NULL, NULL, 0x6, 0x4, (u8*)&tmp0, 0x1, (u8*)&tmp1); APT_AppletUtility(NULL, NULL, 0x6, 0x4, (u8*)&tmp0, 0x1, (u8*)&tmp1);
aptCloseSession(); aptCloseSession();
} }
// Prepare for return to menu
aptOpenSession(); aptOpenSession();
APT_PrepareToJumpToHomeMenu(NULL); //prepare for return to menu APT_PrepareToJumpToHomeMenu(NULL);
aptCloseSession(); aptCloseSession();
// Set status to SUSPENDED.
svcClearEvent(aptStatusEvent); svcClearEvent(aptStatusEvent);
aptSetStatus(APP_SUSPENDED); aptSetStatus(APP_SUSPENDED);
// Save Vram
GSPGPU_SaveVramSysArea(NULL); GSPGPU_SaveVramSysArea(NULL);
// Capture screen.
memset(tmp_params, 0, 0x20); memset(tmp_params, 0, 0x20);
memset(ns_capinfo, 0, 0x20); memset(ns_capinfo, 0, 0x20);
@ -145,6 +142,7 @@ void aptReturnToMenu()
menu_appid = aptGetMenuAppID(); menu_appid = aptGetMenuAppID();
// Send capture-screen info to menu.
aptOpenSession(); aptOpenSession();
APT_SendParameter(NULL, currentAppId, menu_appid, 0x20, ns_capinfo, 0x0, 0x10); APT_SendParameter(NULL, currentAppId, menu_appid, 0x20, ns_capinfo, 0x0, 0x10);
aptCloseSession(); aptCloseSession();
@ -153,17 +151,21 @@ void aptReturnToMenu()
APT_SendCaptureBufferInfo(NULL, 0x20, ns_capinfo); APT_SendCaptureBufferInfo(NULL, 0x20, ns_capinfo);
aptCloseSession(); aptCloseSession();
GSPGPU_ReleaseRight(NULL); //disable GSP module access // Release GSP module.
GSPGPU_ReleaseRight(NULL);
// Jump to menu!
aptOpenSession(); aptOpenSession();
APT_JumpToHomeMenu(NULL, 0x0, 0x0, 0x0); //jump ! APT_JumpToHomeMenu(NULL, 0x0, 0x0, 0x0);
aptCloseSession(); aptCloseSession();
// Wait for return to application.
aptOpenSession(); aptOpenSession();
APT_NotifyToWait(NULL, currentAppId); APT_NotifyToWait(NULL, currentAppId);
aptCloseSession(); aptCloseSession();
if(aptGetStatusPower()==0)//This is only executed when ret-to-menu was triggered via the home-button, not the power-button. // This is only executed when ret-to-menu was triggered via the home-button, not the power-button.
if(aptGetStatusPower() == 0)
{ {
tmp0 = 0; tmp0 = 0;
aptOpenSession(); aptOpenSession();
@ -174,54 +176,45 @@ void aptReturnToMenu()
aptWaitStatusEvent(); aptWaitStatusEvent();
} }
void aptEventHandler(u32 arg) static void __handle_notification() {
{ u8 type;
bool runThread=true;
while(runThread)
{
s32 syncedID=0x0;
svcWaitSynchronizationN(&syncedID, aptEvents, 2, 0, U64_MAX);
svcClearEvent(aptEvents[syncedID]);
switch(syncedID)
{
case 0x0: //event 0 means we got a signal from NS (home button, power button etc)
{
u8 signalType;
// Get notification type.
aptOpenSession(); aptOpenSession();
APT_InquireNotification(NULL, currentAppId, &signalType); //check signal type APT_InquireNotification(NULL, currentAppId, &type);
aptCloseSession(); aptCloseSession();
switch(signalType) switch(type)
{ {
case APTSIGNAL_HOMEBUTTON: case APTSIGNAL_HOMEBUTTON:
case APTSIGNAL_POWERBUTTON: case APTSIGNAL_POWERBUTTON:
// The main thread should call aptReturnToMenu() when the status gets set to this.
if(aptGetStatus() == APP_RUNNING) if(aptGetStatus() == APP_RUNNING)
{ {
aptOpenSession(); aptOpenSession();
APT_ReplySleepQuery(NULL, currentAppId, 0x0); APT_ReplySleepQuery(NULL, currentAppId, 0x0);
aptCloseSession(); aptCloseSession();
if(signalType==0x1)aptSetStatusPower(0); if(type == APTSIGNAL_HOMEBUTTON) aptSetStatusPower(0);
if(signalType==0x8)aptSetStatusPower(1); if(type == APTSIGNAL_POWERBUTTON) aptSetStatusPower(1);
aptSetStatus(APP_SUSPENDING);//The main thread should call aptReturnToMenu() when the status gets set to this. aptSetStatus(APP_SUSPENDING);
} }
break; break;
case APTSIGNAL_PREPARESLEEP: case APTSIGNAL_PREPARESLEEP:
aptStatus_beforesleepmode = aptGetStatus(); // Reply to sleep-request.
aptStatusBeforeSleep = aptGetStatus();
aptOpenSession(); aptOpenSession();
APT_ReplySleepQuery(NULL, currentAppId, 0x1); APT_ReplySleepQuery(NULL, currentAppId, 0x1);
aptCloseSession(); aptCloseSession();
aptSetStatus(APP_PREPARE_SLEEPMODE); aptSetStatus(APP_PREPARE_SLEEPMODE);
break; break;
case APTSIGNAL_ENTERSLEEP: case APTSIGNAL_ENTERSLEEP:
if(aptGetStatus() == APP_PREPARE_SLEEPMODE) if(aptGetStatus() == APP_PREPARE_SLEEPMODE)
{ {
// Report into sleep-mode.
aptOpenSession(); aptOpenSession();
APT_ReplySleepNotificationComplete(NULL, currentAppId); APT_ReplySleepNotificationComplete(NULL, currentAppId);
aptCloseSession(); aptCloseSession();
@ -229,45 +222,73 @@ void aptEventHandler(u32 arg)
} }
break; break;
case APTSIGNAL_WAKEUP: // Leaving sleep-mode. // Leaving sleep-mode.
case APTSIGNAL_WAKEUP:
if(aptGetStatus() == APP_SLEEPMODE) if(aptGetStatus() == APP_SLEEPMODE)
{ {
if(aptStatus_beforesleepmode == APP_RUNNING)GSPGPU_SetLcdForceBlack(NULL, 0); if(aptStatusBeforeSleep == APP_RUNNING)GSPGPU_SetLcdForceBlack(NULL, 0);
aptSetStatus(aptStatus_beforesleepmode);
// Restore old aptStatus.
aptSetStatus(aptStatusBeforeSleep);
} }
break; break;
} }
} }
break;
case 0x1: //event 1 means app just started, we're returning to app, exiting app etc. static bool __handle_incoming_parameter() {
{ u8 type;
u8 signalType;
aptOpenSession(); aptOpenSession();
APT_ReceiveParameter(NULL, currentAppId, 0x1000, aptParameters, NULL, &signalType); APT_ReceiveParameter(NULL, currentAppId, 0x1000, aptParameters, NULL, &type);
aptCloseSession(); aptCloseSession();
switch(signalType) switch(type)
{ {
case 0x1: //application just started case 0x1: // Application just started.
break; return true;
case 0xB: //just returned from menu
case 0xB: // Just returned from menu.
GSPGPU_AcquireRight(NULL, 0x0); GSPGPU_AcquireRight(NULL, 0x0);
GSPGPU_RestoreVramSysArea(NULL); GSPGPU_RestoreVramSysArea(NULL);
aptAppletUtility_Exit_RetToApp(); aptAppletUtility_Exit_RetToApp();
aptSetStatus(APP_RUNNING); aptSetStatus(APP_RUNNING);
break; return true;
case 0xC: //exiting application
runThread=false; case 0xC: // Exiting application.
aptSetStatus(APP_EXITING); //app exit signal aptSetStatus(APP_EXITING);
break; return false;
} }
return true;
} }
void aptEventHandler(u32 arg)
{
bool runThread = true;
while(runThread)
{
s32 syncedID = 0;
svcWaitSynchronizationN(&syncedID, aptEvents, 2, 0, U64_MAX);
svcClearEvent(aptEvents[syncedID]);
switch(syncedID)
{
// Event 0 means we got a signal from NS (home button, power button etc).
case 0x0:
__handle_notification();
break; break;
case 0x2: //event 2 means we should exit the thread (event will be added later) // Event 1 means we got an incoming parameter.
case 0x1:
runThread = __handle_incoming_parameter();
break;
// Event 2 means we should exit the thread (event will be added later).
case 0x2:
runThread = false; runThread = false;
break; break;
} }
} }
svcExitThread(); svcExitThread();
} }
@ -275,7 +296,7 @@ Result aptInit(NS_APPID appID)
{ {
Result ret=0; Result ret=0;
//initialize APT stuff, escape load screen // Initialize APT stuff, escape load screen.
srvGetServiceHandle(&aptuHandle, "APT:U"); srvGetServiceHandle(&aptuHandle, "APT:U");
if((ret=APT_GetLockHandle(&aptuHandle, 0x0, &aptLockHandle)))return ret; if((ret=APT_GetLockHandle(&aptuHandle, 0x0, &aptLockHandle)))return ret;
svcCloseHandle(aptuHandle); svcCloseHandle(aptuHandle);
@ -295,7 +316,6 @@ Result aptInit(NS_APPID appID)
aptCloseSession(); aptCloseSession();
svcCreateEvent(&aptStatusEvent, 0); svcCreateEvent(&aptStatusEvent, 0);
return 0; return 0;
} }
@ -303,7 +323,8 @@ void aptExit()
{ {
aptAppletUtility_Exit_RetToApp(); aptAppletUtility_Exit_RetToApp();
if(aptGetStatusPower()==1)//This is only executed when application-termination was triggered via the home-menu power-off screen. // This is only executed when application-termination was triggered via the home-menu power-off screen.
if(aptGetStatusPower() == 1)
{ {
aptOpenSession(); aptOpenSession();
APT_ReplySleepQuery(NULL, currentAppId, 0x0); APT_ReplySleepQuery(NULL, currentAppId, 0x0);
@ -371,8 +392,9 @@ void aptSetupEventHandler()
aptSetStatus(APP_RUNNING); aptSetStatus(APP_RUNNING);
//create thread for stuff handling APT events // Create thread for stuff handling APT events.
svcCreateThread(&aptEventHandlerThread, aptEventHandler, 0x0, (u32*)(&aptEventHandlerStack[APT_HANDLER_STACKSIZE/8]), 0x31, 0xfffffffe); svcCreateThread(&aptEventHandlerThread, aptEventHandler, 0x0,
(u32*)(&aptEventHandlerStack[APT_HANDLER_STACKSIZE/8]), 0x31, 0xfffffffe);
} }
APP_STATUS aptGetStatus() APP_STATUS aptGetStatus()
@ -395,8 +417,8 @@ void aptSetStatus(APP_STATUS status)
if(prevstatus != APP_NOTINITIALIZED) if(prevstatus != APP_NOTINITIALIZED)
{ {
if(status==APP_RUNNING)svcSignalEvent(aptStatusEvent); if(status == APP_RUNNING || status == APP_EXITING)
if(status==APP_EXITING)svcSignalEvent(aptStatusEvent); svcSignalEvent(aptStatusEvent);
} }
svcReleaseMutex(aptStatusMutex); svcReleaseMutex(aptStatusMutex);

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,7 @@
/*
gsp.c _ Gpu/lcd stuff.
*/
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <3ds/types.h> #include <3ds/types.h>
@ -18,6 +22,7 @@ static vu8* gspEventData;
static void gspEventThreadMain(u32 arg); static void gspEventThreadMain(u32 arg);
Result gspInit() Result gspInit()
{ {
return srvGetServiceHandle(&gspGpuHandle, "gsp::Gpu"); return srvGetServiceHandle(&gspGpuHandle, "gsp::Gpu");
@ -348,7 +353,7 @@ Result GSPGPU_RestoreVramSysArea(Handle* handle)
//essentially : get commandIndex and totalCommands, calculate offset of new command, copy command and update totalCommands //essentially : get commandIndex and totalCommands, calculate offset of new command, copy command and update totalCommands
//use LDREX/STREX because this data may also be accessed by the GSP module and we don't want to break stuff //use LDREX/STREX because this data may also be accessed by the GSP module and we don't want to break stuff
//(mostly, we could overwrite the buffer header with wrong data and make the GSP module reexecute old commands) //(mostly, we could overwrite the buffer header with wrong data and make the GSP module reexecute old commands)
Result GSPGPU_submitGxCommand(u32* sharedGspCmdBuf, u32 gxCommand[0x8], Handle* handle) Result GSPGPU_SubmitGxCommand(u32* sharedGspCmdBuf, u32 gxCommand[0x8], Handle* handle)
{ {
if(!sharedGspCmdBuf || !gxCommand)return -1; if(!sharedGspCmdBuf || !gxCommand)return -1;

View File

@ -1,3 +1,7 @@
/*
gx.c _ Sending GPU requests via GSP shared memory.
*/
#include <stdlib.h> #include <stdlib.h>
#include <3ds/types.h> #include <3ds/types.h>
#include <3ds/GSP.h> #include <3ds/GSP.h>
@ -13,7 +17,7 @@ Result GX_RequestDma(u32* gxbuf, u32* src, u32* dst, u32 length)
gxCommand[3]=length; //size gxCommand[3]=length; //size
gxCommand[4]=gxCommand[5]=gxCommand[6]=gxCommand[7]=0x0; gxCommand[4]=gxCommand[5]=gxCommand[6]=gxCommand[7]=0x0;
return GSPGPU_submitGxCommand(gxbuf, gxCommand, NULL); return GSPGPU_SubmitGxCommand(gxbuf, gxCommand, NULL);
} }
Result GX_SetCommandList_Last(u32* gxbuf, u32* buf0a, u32 buf0s, u8 flags) Result GX_SetCommandList_Last(u32* gxbuf, u32* buf0a, u32 buf0s, u8 flags)
@ -26,7 +30,7 @@ Result GX_SetCommandList_Last(u32* gxbuf, u32* buf0a, u32 buf0s, u8 flags)
gxCommand[4]=gxCommand[5]=gxCommand[6]=0x0; gxCommand[4]=gxCommand[5]=gxCommand[6]=0x0;
gxCommand[7]=(flags>>1)&1; //when non-zero, call svcFlushProcessDataCache() with the specified buffer gxCommand[7]=(flags>>1)&1; //when non-zero, call svcFlushProcessDataCache() with the specified buffer
return GSPGPU_submitGxCommand(gxbuf, gxCommand, NULL); return GSPGPU_SubmitGxCommand(gxbuf, gxCommand, NULL);
} }
Result GX_SetMemoryFill(u32* gxbuf, u32* buf0a, u32 buf0v, u32* buf0e, u16 width0, u32* buf1a, u32 buf1v, u32* buf1e, u16 width1) Result GX_SetMemoryFill(u32* gxbuf, u32* buf0a, u32 buf0v, u32* buf0e, u16 width0, u32* buf1a, u32 buf1v, u32* buf1e, u16 width1)
@ -42,7 +46,7 @@ Result GX_SetMemoryFill(u32* gxbuf, u32* buf0a, u32 buf0v, u32* buf0e, u16 width
gxCommand[6]=(u32)buf1e; //buf1 end addr gxCommand[6]=(u32)buf1e; //buf1 end addr
gxCommand[7]=(width0)|(width1<<16); gxCommand[7]=(width0)|(width1<<16);
return GSPGPU_submitGxCommand(gxbuf, gxCommand, NULL); return GSPGPU_SubmitGxCommand(gxbuf, gxCommand, NULL);
} }
// Flags, for applications this is 0x1001000 for the main screen, and 0x1000 for the sub screen. // Flags, for applications this is 0x1001000 for the main screen, and 0x1000 for the sub screen.
@ -57,7 +61,7 @@ Result GX_SetDisplayTransfer(u32* gxbuf, u32* inadr, u32 indim, u32* outadr, u32
gxCommand[5]=flags; gxCommand[5]=flags;
gxCommand[6]=gxCommand[7]=0x0; gxCommand[6]=gxCommand[7]=0x0;
return GSPGPU_submitGxCommand(gxbuf, gxCommand, NULL); return GSPGPU_SubmitGxCommand(gxbuf, gxCommand, NULL);
} }
Result GX_SetTextureCopy(u32* gxbuf, u32* inadr, u32 indim, u32* outadr, u32 outdim, u32 size, u32 flags) Result GX_SetTextureCopy(u32* gxbuf, u32* inadr, u32 indim, u32* outadr, u32 outdim, u32 size, u32 flags)
@ -72,7 +76,7 @@ Result GX_SetTextureCopy(u32* gxbuf, u32* inadr, u32 indim, u32* outadr, u32 out
gxCommand[6]=flags; gxCommand[6]=flags;
gxCommand[7]=0x0; gxCommand[7]=0x0;
return GSPGPU_submitGxCommand(gxbuf, gxCommand, NULL); return GSPGPU_SubmitGxCommand(gxbuf, gxCommand, NULL);
} }
Result GX_SetCommandList_First(u32* gxbuf, u32* buf0a, u32 buf0s, u32* buf1a, u32 buf1s, u32* buf2a, u32 buf2s) Result GX_SetCommandList_First(u32* gxbuf, u32* buf0a, u32 buf0s, u32* buf1a, u32 buf1s, u32* buf2a, u32 buf2s)
@ -87,5 +91,5 @@ Result GX_SetCommandList_First(u32* gxbuf, u32* buf0a, u32 buf0s, u32* buf1a, u3
gxCommand[6]=(u32)buf2s; //buf2 size gxCommand[6]=(u32)buf2s; //buf2 size
gxCommand[7]=0x0; gxCommand[7]=0x0;
return GSPGPU_submitGxCommand(gxbuf, gxCommand, NULL); return GSPGPU_SubmitGxCommand(gxbuf, gxCommand, NULL);
} }