Exemplo n.º 1
0
void aptAppStarted()
{
	u8 buf1[4], buf2[4];

	svcCreateMutex(&aptStatusMutex, true);
	aptStatus=0;
	svcReleaseMutex(aptStatusMutex);

	aptSetStatus(APP_RUNNING);

	if(!aptIsCrippled())
	{
		memset(buf1, 0, 4);

		buf1[0] = 0x10;
		aptOpenSession();
		APT_AppletUtility(NULL, NULL, 0x7, 0x4, buf1, 0x1, buf2);
		aptCloseSession();

		buf1[0] = 0x00;
		aptOpenSession();
		APT_AppletUtility(NULL, NULL, 0x4, 0x1, buf1, 0x1, buf2);
		aptCloseSession();

		aptOpenSession();
		APT_AppletUtility(NULL, NULL, 0x4, 0x1, buf1, 0x1, buf2);
		aptCloseSession();
	}
}
Exemplo n.º 2
0
Arquivo: apt.c Projeto: Almamu/ctrulib
void aptAppStarted()
{
	u8 buf1[4], buf2[4];

	svcCreateMutex(&aptStatusMutex, true);
	aptStatus=0;
	svcReleaseMutex(aptStatusMutex);

	aptSetStatus(APP_RUNNING);

	if(!(__system_runflags&RUNFLAG_APTWORKAROUND))
	{
		memset(buf1, 0, 4);

		buf1[0] = 0x10;
		aptOpenSession();
		APT_AppletUtility(NULL, NULL, 0x7, 0x4, buf1, 0x1, buf2);
		aptCloseSession();

		buf1[0] = 0x00;
		aptOpenSession();
		APT_AppletUtility(NULL, NULL, 0x4, 0x1, buf1, 0x1, buf2);
		aptCloseSession();

		aptOpenSession();
		APT_AppletUtility(NULL, NULL, 0x4, 0x1, buf1, 0x1, buf2);
		aptCloseSession();
	}
}
Exemplo n.º 3
0
void initPhysicsThread(physicsThread_s* p)
{
	if(!p)return;

	initRequestQueue(&p->privateList);
	initRequestQueue(&p->requestList);

	p->exit=false;
	svcCreateMutex(&p->requestMutex, false);
	Result val = svcCreateThread(&p->thread, physicsThreadMain, (u32)p, (u32*)&p->stack[PHYSICSTHREAD_STACKSIZE/8], 0x18, 1);
	printf("%08X (%08X)\n",(unsigned int)val,(unsigned int)p->thread);
	if(val)
	{
		//thread creation failed ! what do we do ?!
	}
}
Exemplo n.º 4
0
static inline void initPXI(void)
{
    Result res;

    Handle handles[2] = {0};

    PXIReset();

    if(PXISyncInterrupt != 0) svcBreak(USERBREAK_PANIC); //0xE0A0183B
    assertSuccess(svcCreateEvent(&PXISyncInterrupt, RESET_ONESHOT));

    if(PXITransferMutex != 0) svcBreak(USERBREAK_PANIC); //0xE0A0183B
    assertSuccess(svcCreateMutex(&PXITransferMutex, false));

    assertSuccess(svcCreateEvent(&handles[0], RESET_ONESHOT)); //receive FIFO not empty
    assertSuccess(svcCreateEvent(&handles[1], RESET_ONESHOT)); //send FIFO empty
    assertSuccess(bindPXIInterrupts(&PXISyncInterrupt, &handles[0], &handles[1]));

    s32 handleIndex;
    do
    {
        while(!PXIIsSendFIFOFull()) PXISendWord(0);

        res = assertSuccess(svcWaitSynchronization(handles[0], 0LL));
        if(R_DESCRIPTION(res) == RD_TIMEOUT)
            assertSuccess(svcWaitSynchronizationN(&handleIndex, handles, 2, false, -1LL));
        else
            handleIndex = 0;
    } while(handleIndex != 0);



    unbindPXIInterrupts(NULL, &handles[0], &handles[1]);

    PXISendByte(1);
    while(PXIReceiveByte() < 1);

    while (!PXIIsReceiveFIFOEmpty())
        PXIReceiveWord();

    PXISendByte(2);
    while(PXIReceiveByte() < 2);

    svcCloseHandle(handles[0]);
    svcCloseHandle(handles[1]);
}
Exemplo n.º 5
0
Arquivo: ui.c Projeto: XeQMuK3K4/FBI
void ui_init() {
    if(ui_stack_mutex == 0) {
        svcCreateMutex(&ui_stack_mutex, false);
    }
}
Exemplo n.º 6
0
Result task_capture_cam(capture_cam_data* data) {
    if(data == NULL || data->buffer == NULL || data->width <= 0 || data->width > 640 || data->height <= 0 || data->height > 480) {
        return R_APP_INVALID_ARGUMENT;
    }

    data->mutex = 0;

    data->finished = false;
    data->result = 0;
    data->cancelEvent = 0;

    Result res = 0;

    if(R_SUCCEEDED(res = svcCreateEvent(&data->cancelEvent, RESET_STICKY)) && R_SUCCEEDED(res = svcCreateMutex(&data->mutex, false))) {
        if(threadCreate(task_capture_cam_thread, data, 0x10000, 0x1A, 0, true) == NULL) {
            res = R_APP_THREAD_CREATE_FAILED;
        }
    }

    if(R_FAILED(res)) {
        data->finished = true;

        if(data->cancelEvent != 0) {
            svcCloseHandle(data->cancelEvent);
            data->cancelEvent = 0;
        }

        if(data->mutex != 0) {
            svcCloseHandle(data->mutex);
            data->mutex = 0;
        }
    }

    return res;
}
Exemplo n.º 7
0
Result aptInit(void)
{
	Result ret=0;

	if (aptInitialised) return ret;

	aptStatusMutex = 0;

	// Initialize APT stuff, escape load screen.
	ret = __apt_initservicehandle();
	if(ret!=0)return ret;
	if((ret=APT_GetLockHandle(&aptuHandle, 0x0, &aptLockHandle)))return ret;
	svcCloseHandle(aptuHandle);

	currentAppId = __apt_appid;

	svcCreateEvent(&aptStatusEvent, 0);
	svcCreateEvent(&aptSleepSync, 0);
	svcCreateMutex(&aptStatusMutex, false);
	aptStatus=0;

	if(!aptIsCrippled())
	{
		aptOpenSession();
		if((ret=APT_Initialize(NULL, currentAppId, &aptEvents[0], &aptEvents[1])))return ret;
		aptCloseSession();
		
		aptOpenSession();
		if((ret=APT_Enable(NULL, 0x0)))return ret;
		aptCloseSession();
		
		// create APT close event
		svcCreateEvent(&aptEvents[2], 0);

		// After a cycle of APT_Finalize+APT_Initialize APT thinks the
		// application is suspended, so we need to tell it to unsuspend us.
		if (aptIsReinit())
		{
			aptOpenSession();
			APT_PrepareToJumpToApplication(NULL, 0x0);
			aptCloseSession();

			aptOpenSession();
			APT_JumpToApplication(NULL, 0x0, 0x0, 0x0);
			aptCloseSession();
		}
		
		aptOpenSession();
		if((ret=APT_NotifyToWait(NULL, currentAppId)))return ret;
		aptCloseSession();

		// create APT event handler thread
		svcCreateThread(&aptEventHandlerThread, aptEventHandler, 0x0,
			(u32*)(&aptEventHandlerStack[APT_HANDLER_STACKSIZE/8]), 0x31, 0xfffffffe);
	} else
		aptAppStarted();

	aptInitialised = true;

	return 0;
}
Exemplo n.º 8
0
int main() {
	gfxInitDefault();
  consoleInit(GFX_TOP, &LuaBox_MainConsole); // Initialize console

	LuaBox_Running = 1;
	LuaBox_EventList = NULL; // Clear event list
	svcCreateMutex(&LuaBox_ConsoleMutex, 0); // Create the console mutex
	svcCreateMutex(&LuaBox_EventMutex, 0); // Create event list mutex
	svcCreateEvent(&LuaBox_EventSignal, 0); // Create event list mutex

	printf("%s version %s\ninitializing lua state...\n", LUABOX_NAME, LUABOX_VERSION);
	L = luaL_newstate();
	luaL_openlibs(L);

	// Install our apis
	lua_newtable(L);
	lua_pushstring(L, "exists");
	lua_pushcfunction(L, Api_fs_exists);
	lua_settable(L, -3);
	lua_setglobal(L, "fs");

	// Check if boot.lua exists
	FILE* fp = fopen("lua/bios.lua", "r");
	if(fp == NULL) {
		printf("lua/bios.lua does not exist\nplease create and place lua code in it for this to be useful.\npress start to exit.\n");
		while(1) {
			gspWaitForVBlank();
			hidScanInput();

			u32 kDown = hidKeysDown();

			if (kDown & KEY_START)
				break; // break in order to return to hbmenu

			// Flush and swap framebuffers
			gfxFlushBuffers();
			gfxSwapBuffers();
		}
		gfxExit();
		return 0;
	}
	fclose(fp);

	printf("initialized.\ninitializing keyboard...\n");
	SoftKb_Setup(GFX_BOTTOM, 4, 0);
	SoftKb_Draw();
	printf("initialized. use dpad and A button to type.\n");

	// Start lua thread.
	printf("starting lua thread...\n");
	Handle threadHandle;
	u32 *threadStack = memalign(32, LUABOX_THREAD_STACKSIZE);
	svcCreateThread(&threadHandle, LuaThread, 0, &threadStack[LUABOX_THREAD_STACKSIZE/4], 0x3f, 0);

	// Main loop
	while(LuaBox_Running) {
		gspWaitForVBlank();
		hidScanInput();

		u32 kDown = hidKeysDown();
		char out = SoftKb_Handle(kDown);
		if(out >= 32 || out == 10 || out == 7) {
			LuaBox_PushEvent(LUABOX_EVENT_CHAR, out);
		}

		if (kDown & KEY_START)
			break; // break in order to return to hbmenu

		// Flush and swap framebuffers
		gfxFlushBuffers();
		gfxSwapBuffers();
	}

	gfxExit();
	return 0;
}