예제 #1
0
파일: apt.c 프로젝트: Almamu/ctrulib
bool aptMainLoop()
{
	while(1)
	{
		//if(__system_runflags&RUNFLAG_APTWORKAROUND)__handle_notification();

		switch(aptGetStatus())
		{
			case APP_RUNNING:
				return true;
			case APP_EXITING:
				return false;
			case APP_SUSPENDING:
				aptReturnToMenu();
				break;
			case APP_APPLETSTARTED:
				aptAppletStarted();
				break;
			case APP_APPLETCLOSED:
				aptAppletClosed();
				break;
			case APP_PREPARE_SLEEPMODE:
				aptSignalReadyForSleep();
				// Fall through
			default:
			//case APP_NOTINITIALIZED:
			//case APP_SLEEPMODE:
				aptWaitStatusEvent();
				break;
		}
	}
}
예제 #2
0
파일: main.c 프로젝트: Cruel/ctrulib
int main()
{
	initSrv();
	
	aptInit(APPID_APPLICATION);

	gspGpuInit();

	hidInit(NULL);

	aptSetupEventHandler();

	APP_STATUS status;
	while((status=aptGetStatus())!=APP_EXITING)
	{
		if(status==APP_RUNNING)
		{
			u32 PAD=hidSharedMem[7];
			
			u32 regData=PAD|0x01000000;
			GSPGPU_WriteHWRegs(NULL, 0x202A04, (u32*)&regData, 4);

			renderEffect();
			swapBuffers();
			copyBuffer();
		}
		svc_sleepThread(16666666);
	}

	hidExit();
	gspGpuExit();
	aptExit();
	svc_exitProcess();
	return 0;
}
예제 #3
0
void system_checkPolls() {
    APP_STATUS status;

	while((status=aptGetStatus()) != APP_RUNNING) {

        if(status == APP_SUSPENDING)
        {
            aptReturnToMenu();
        }
        else if(status == APP_PREPARE_SLEEPMODE)
        {
			aptSignalReadyForSleep();
            aptWaitStatusEvent();
        }
        else if (status == APP_SLEEPMODE) {

        }
        else if (status == APP_EXITING) {
            system_cleanup();
            exit(0);
        }

        gspWaitForVBlank();
    }

    gfxFlushBuffers();
    gfxMySwapBuffers();
    consoleCheckFramebuffers();
}
예제 #4
0
static int lua_check(lua_State *L)
{
	int argc = lua_gettop(L);
	#ifndef SKIP_ERROR_HANDLING
		if (argc != 2) return luaL_error(L, "wrong number of arguments.");
	#endif
	u32 pad = luaL_checknumber(L, 1);
	u32 button = luaL_checknumber(L, 2);
	if (button == KEY_HOME){
		APT_AppStatus status = aptGetStatus();
		lua_pushboolean(L,((status == APP_SUSPENDING) && aptGetStatusPower() == 0));
	}else if (button == KEY_POWER){
		APT_AppStatus status = aptGetStatus();
		lua_pushboolean(L,((status == APP_SUSPENDING) && aptGetStatusPower() == 1));
	}else lua_pushboolean(L, ((pad & button) == button));
    return 1;
}
예제 #5
0
파일: apt.c 프로젝트: botanyaki/ctrulib
static bool __handle_incoming_parameter(void) {
	u8 type;

	aptOpenSession();
	APT_ReceiveParameter(currentAppId, 0x1000, aptParameters, NULL, &type);
	aptCloseSession();

	_aptDebug(2, type);

	switch(type)
	{
	case 0x1: // Application just started.
		aptAppStarted();
		return true;

	case 0x3: // "Launched library applet finished loading"
		if (aptGetStatus() != APP_SUSPENDED || __apt_launchapplet_appID==0) return true;
		aptSetStatus(APP_APPLETSTARTED);
		return true;
	case 0xA: // "Launched library applet closed"
		if (aptGetStatus() != APP_SUSPENDED || __apt_launchapplet_appID==0) return true;
		if(__apt_launchapplet_parambuf && __apt_launchapplet_parambufsize)memcpy(__apt_launchapplet_parambuf, aptParameters, __apt_launchapplet_parambufsize);
		aptSetStatus(APP_APPLETCLOSED);
		return true;
	case 0xB: // Just returned from menu.
		if (aptGetStatus() != APP_NOTINITIALIZED)
		{
			GSPGPU_AcquireRight(0x0);
			GSPGPU_RestoreVramSysArea();
			aptAppletUtility_Exit_RetToApp(0);
			aptSetStatus(APP_RUNNING);
		} else
			aptAppStarted();
		return true;

	case 0xC: // Exiting application.
		aptSetStatus(APP_EXITING);
		return false;
	}

	return true;
}
예제 #6
0
파일: apt.c 프로젝트: 0TheMeistro0/ctrulib
void aptExit()
{
	if (!aptInitialised) return;

	if(!aptIsCrippled())aptAppletUtility_Exit_RetToApp(0);

	// This is only executed when application-termination was triggered via the home-menu power-off screen.
	if(aptGetStatusPower() == 1)
	{
		aptOpenSession();
		APT_ReplySleepQuery(NULL, currentAppId, 0x0);
		aptCloseSession();
	}

	if(!aptIsCrippled())
	{
		bool isReinit = aptIsReinit();
		if (aptGetStatus() == APP_EXITING || !isReinit)
		{
			aptOpenSession();
			APT_PrepareToCloseApplication(NULL, 0x1);
			aptCloseSession();
		
			aptOpenSession();
			APT_CloseApplication(NULL, 0x0, 0x0, 0x0);
			aptCloseSession();

			if (isReinit)
			{
				extern void (*__system_retAddr)(void);
				__system_retAddr = NULL;
			}
		} else if (isReinit)
		{
			aptOpenSession();
			APT_Finalize(NULL, currentAppId);
			aptCloseSession();
		}
	}

	svcSignalEvent(aptEvents[2]);
	svcWaitSynchronization(aptEventHandlerThread, U64_MAX);
	svcCloseHandle(aptEventHandlerThread);
	svcCloseHandle(aptEvents[2]);
	
	svcCloseHandle(aptSleepSync);

	svcCloseHandle(aptStatusMutex);
	svcCloseHandle(aptLockHandle);
	svcCloseHandle(aptStatusEvent);
	
	aptInitialised = false;
}
예제 #7
0
파일: main.c 프로젝트: iamn1ck/ctrrpc
void conn_main() {
    APP_STATUS status;
    u32 it = 0;
    int ret = 0;
    int first = 1;
    int exiting = 0;

    while((status = aptGetStatus()) != APP_EXITING)
    {
        hidScanInput();
        consoleClear(&bot);

        print(&bot, "frame: %08x\n", it);
        print(&bot, "ret: %08x\n", ret);
        print(&bot, "last_cmd: %02x\n", last_cmd & 0xFF);

        if(!first) {
            u32 bytes_read = 0;

            while(1) {
                ret = recv(sock, &cmd, sizeof(cmd), 0);
                if(ret < 0) {
                    if(ret == -EWOULDBLOCK)
                        continue;
                    break;
                }

                bytes_read += ret;
                if(bytes_read == sizeof(cmd)) {
                    svcSignalEvent(new_cmd_event);
                    svcWaitSynchronization(cmd_done_event, U64_MAX);
                    svcClearEvent(cmd_done_event);

                    send(sock, &resp, sizeof(resp), 0);

                    if(last_cmd_result == 0xDEAD)
                        exiting = 1;
                    break;
                }
            }
        }

        first = 0;
        it++;

        if(enable_draw)
            renderFrame(); 

        u32 keys = hidKeysUp();
        if(keys & KEY_A || exiting)
            break;     
    }
}
예제 #8
0
파일: apt.c 프로젝트: botanyaki/ctrulib
bool aptMainLoop(void)
{
	while(1)
	{
		//if(aptIsCrippled())__handle_notification();

		switch(aptGetStatus())
		{
			case APP_RUNNING:
				return true;
			case APP_EXITING:
				aptCallHook(APTHOOK_ONEXIT);
				return false;
			case APP_SUSPENDING:
				aptCallHook(APTHOOK_ONSUSPEND);
				aptReturnToMenu();
				if (aptGetStatus() == APP_RUNNING)
					aptCallHook(APTHOOK_ONRESTORE);
				break;
			case APP_APPLETSTARTED:
				aptAppletStarted();
				break;
			case APP_APPLETCLOSED:
				aptAppletClosed();
				aptCallHook(APTHOOK_ONRESTORE);
				break;
			case APP_PREPARE_SLEEPMODE:
				aptCallHook(APTHOOK_ONSLEEP);
				aptSignalReadyForSleep();
				// Fall through
			default:
			//case APP_NOTINITIALIZED:
			//case APP_SLEEPMODE:
				aptWaitStatusEvent();
				aptCallHook(APTHOOK_ONWAKEUP);
				break;
		}
	}
}
예제 #9
0
int main()
{
	//Grab the status of the app (running, suspending, sleeping, exiting)
	APP_STATUS status;

	//Initialize 3ds services
	srvInit();
	fsInit();
	aptInit();
	gfxInit();
	hidInit(NULL);
	//Setup event handler to listen for changes in status
	aptSetupEventHandler();


	while ((status = aptGetStatus()) != APP_EXITING)
	{

		if (status == APP_RUNNING)
		{
			//If the app is currently in the forground running, execute the program.
			program();
		}
		else if (status == APP_SUSPENDING)
		{
			//If the app is currently suspended in the background, return to the home menu.
			aptReturnToMenu();
		}
		else if (status == APP_SLEEPMODE)
		{
			//If the app is currently suspended in sleep mode, wait.
			aptWaitStatusEvent();
		}

		//Wait for GPU
		gspWaitForVBlank();

	}

	//Close all opened services.
	hidExit();
	gfxExit();
	aptExit();
	srvExit();
	//Kill the process.
	svcExitProcess();
	return 0;
}
예제 #10
0
파일: main.c 프로젝트: codlab/ftpony
int main()
{
	srvInit();	
	aptInit();
	hidInit(NULL);
	irrstInit(NULL);
	gfxInit();

	gfxSet3D(false);

	srand(svcGetSystemTick());

	curQuote=rand()%numQuotes;
	superStr[0]=0;
	ftp_init();

	int connfd=ftp_getConnection();

	APP_STATUS status;
	while((status=aptGetStatus())!=APP_EXITING)
	{
		if(status == APP_RUNNING)
		{
			ftp_frame(connfd);
			drawFrame();

			hidScanInput();
			if(hidKeysDown()&KEY_B)break;
		}
		else if(status == APP_SUSPENDING)
		{
			aptReturnToMenu();
		}
		else if(status == APP_SLEEPMODE)
		{
			aptWaitStatusEvent();
		}
		gspWaitForEvent(GSPEVENT_VBlank0, false);
	}

	ftp_exit();
	gfxExit();
	irrstExit();
	hidExit();
	aptExit();
	srvExit();
	return 0;
}
예제 #11
0
파일: main.c 프로젝트: bunnei/ctrulib
int main()
{
	initSrv();
		
	aptInit(APPID_APPLICATION);

	gspGpuInit();

	hidInit(NULL);

	Handle fsuHandle;
	srv_getServiceHandle(NULL, &fsuHandle, "fs:USER");
	FSUSER_Initialize(fsuHandle);

	Handle fileHandle;
	u32 bytesRead;
	FS_archive sdmcArchive=(FS_archive){0x9, (FS_path){PATH_EMPTY, 1, (u8*)""}};
	FS_path filePath=(FS_path){PATH_CHAR, 10, (u8*)"/test.bin"};
	FSUSER_OpenFileDirectly(fsuHandle, &fileHandle, sdmcArchive, filePath, FS_OPEN_READ, FS_ATTRIBUTE_NONE);
	FSFILE_Read(fileHandle, &bytesRead, 0x0, (u32*)gspHeap, 0x46500);
	FSFILE_Close(fileHandle);

	aptSetupEventHandler();
	
	while(!aptGetStatus())
	{
		u32 PAD=hidSharedMem[7];
		renderEffect();
		swapBuffers();
		copyBuffer();
		u32 regData=PAD|0x01000000;
		GSPGPU_WriteHWRegs(NULL, 0x202A04, &regData, 4);
		svc_sleepThread(1000000000);
	}

	svc_closeHandle(fsuHandle);
	hidExit();
	gspGpuInit();
	aptExit();
	svc_exitProcess();
	return 0;
}
예제 #12
0
void system_checkPolls() {
    APT_AppStatus status;

	while((status=aptGetStatus()) != APP_RUNNING) {

        if(status == APP_SUSPENDING)
        {
            aptReturnToMenu();
        }
        else if(status == APP_PREPARE_SLEEPMODE)
        {
			aptSignalReadyForSleep();
            aptWaitStatusEvent();
        }
        else if (status == APP_SLEEPMODE) {
        }
        else if (status == APP_EXITING) {
			handy_3ds_quit();
        }

    }
}
예제 #13
0
파일: gui.c 프로젝트: nop90/Vex3DS
int load_file(char **wildcards, char *result, bool startup)
{

	Handle dirHandle;
    FS_DirectoryEntry entry;
	char current_dir_name[MAX__PATH];
    char prev_dir_name[MAX__PATH];
	char current_dir_short[81];
	u32 current_dir_length;
	u32 total_filenames_allocated;
	u32 total_dirnames_allocated;
	char **file_list;
	char **dir_list;
	u32 num_files;
	u32 num_dirs;
	char *file_name;
	u32 file_name_length;
	u32 ext_pos = -1;
	s32 return_value = 1;
	u32 current_file_selection;
	u32 current_file_scroll_value;
	u32 current_dir_selection;
	u32 current_dir_scroll_value;
	u32 current_file_in_scroll;
	u32 current_dir_in_scroll;
	u32 current_file_number, current_dir_number;
	u32 current_column = 0;
	u32 repeat;
	u32 i;

    strcpy(current_dir_name, config_roms_path);
    strcpy(prev_dir_name, current_dir_name);
	while(return_value == 1) {
		current_file_selection = 0;
		current_file_scroll_value = 0;
		current_dir_selection = 0;
		current_dir_scroll_value = 0;
		current_file_in_scroll = 0;
		current_dir_in_scroll = 0;

		total_filenames_allocated = 32;
		total_dirnames_allocated = 32;
		file_list = (char **)malloc(sizeof(char *) * 32);
		dir_list = (char **)malloc(sizeof(char *) * 32);
		memset(file_list, 0, sizeof(char *) * 32);
		memset(dir_list, 0, sizeof(char *) * 32);

		num_files = 0;
		num_dirs = 0;
        
        file_name= (char*) malloc(0x105);

        FS_Path dirPath = (FS_Path){PATH_ASCII, strlen(current_dir_name)+1, (u8*)current_dir_name};
        FSUSER_OpenDirectory(&dirHandle, sdmcArchive, dirPath);

		// DEBUG
		printf("Current directory: %s\n", current_dir_name);
		u32 nread = 0;
		do {
            if(dirHandle) FSDIR_Read(dirHandle, &nread, 1, &entry);

            if(nread) { //(current_file) {
               strncpy_u2a(file_name, entry.name, 0x105);  //utf-16 to ascii function yoinked from blargSNES
				file_name_length = strlen(file_name);

                if(((file_name[0] != '.') || (file_name[1] == '.'))) {
					//if(S_ISDIR(file_info.st_mode)) {    //!!!!!!!!
                    if(entry.attributes & FS_ATTRIBUTE_DIRECTORY) {
                        if((strcmp(file_name, "filer") != 0) && (strcmp(file_name, "Nintendo 3DS") != 0) && (strcmp(file_name, "private") != 0)) {
                            dir_list[num_dirs] = (char *)malloc(file_name_length + 1);
                            strcpy(dir_list[num_dirs], file_name);

                            num_dirs++;
                        }
					} else {
					// Must match one of the wildcards, also ignore the .
						if(file_name_length >= 4) {
							if(file_name[file_name_length - 4] == '.') ext_pos = file_name_length - 4;
							else if(file_name[file_name_length - 3] == '.') ext_pos = file_name_length - 3;
							else ext_pos = 0;

							for(i = 0; wildcards[i] != NULL; i++) {
								if(!strcasecmp((file_name + ext_pos), wildcards[i])) {
									file_list[num_files] = (char *)malloc(file_name_length + 1);

									strcpy(file_list[num_files], file_name);

									num_files++;
									break;
								}
							}
						}
					}
				}

				if(num_files == total_filenames_allocated) {
					file_list = (char **)realloc(file_list, sizeof(char *) * total_filenames_allocated * 2);
					memset(file_list + total_filenames_allocated, 0, sizeof(char *) * total_filenames_allocated);
					total_filenames_allocated *= 2;
				}

				if(num_dirs == total_dirnames_allocated) {
					dir_list = (char **)realloc(dir_list, sizeof(char *) * total_dirnames_allocated * 2);
					memset(dir_list + total_dirnames_allocated, 0, sizeof(char *) * total_dirnames_allocated);
					total_dirnames_allocated *= 2;
				}
			}
        } while(nread); 

		qsort((void *)file_list, num_files, sizeof(char *), sort_function);
		qsort((void *)dir_list, num_dirs, sizeof(char *), sort_function);

        FSDIR_Close(dirHandle);

		current_dir_length = strlen(current_dir_name);

		if(current_dir_length > 80) {
			memcpy(current_dir_short, "...", 3);
			memcpy(current_dir_short + 3, current_dir_name + current_dir_length - 77, 77);
			current_dir_short[80] = 0;
		} else {
			memcpy(current_dir_short, current_dir_name, current_dir_length + 1);
		}

		repeat = 1;

		if(num_files == 0) current_column = 1;
		if(num_dirs == 0) current_column = 0;

		char print_buffer[81];

		while(repeat) {
			sf2d_start_frame(GFX_BOTTOM, GFX_LEFT); //!!
			sftd_draw_text(font, 0, 4, COLOR_ACTIVE_ITEM, 10, current_dir_short);
			const char strMsg[] = "[A] Select Rom [X] Run BIOS [Y] Dir up [B] Back";
			guitextwidth = sftd_get_text_width(font, 10, strMsg);
			sftd_draw_text(font, (320 - guitextwidth) / 2, 225, COLOR_HELP_TEXT, 10, strMsg);
			
			for(i = 0, current_file_number = i + current_file_scroll_value; i < FILE_LIST_ROWS; i++, current_file_number++) {
				if(current_file_number < num_files) {
                    strncpy(print_buffer,file_list[current_file_number], 30);   //38);
                    print_buffer[30] = 0;   //38] = 0;
					if((current_file_number == current_file_selection) && (current_column == 0)) {
						sftd_draw_text(font, FILE_LIST_POSITION, ((i + 2) * 10), COLOR_ACTIVE_ITEM, 10, print_buffer);
					} else {
						sftd_draw_text(font, FILE_LIST_POSITION, ((i + 2) * 10), COLOR_INACTIVE_ITEM, 10, print_buffer);
					}
				}
			}
			for(i = 0, current_dir_number = i + current_dir_scroll_value; i < FILE_LIST_ROWS; i++, current_dir_number++) {
				if(current_dir_number < num_dirs) {
                    strncpy(print_buffer,dir_list[current_dir_number], 8);  //13);
                    print_buffer[9] = 0;    //14] = 0;
					if((current_dir_number == current_dir_selection) && (current_column == 1)) {
						sftd_draw_text(font, DIR_LIST_POSITION, ((i + 2) * 10), COLOR_ACTIVE_ITEM, 10, print_buffer);
					} else {
						sftd_draw_text(font, DIR_LIST_POSITION, ((i + 2) * 10), COLOR_INACTIVE_ITEM, 10, print_buffer);
					}
				}
			}

			// Catch input
			// change to read key state later
            if (aptGetStatus() == APP_PREPARE_SLEEPMODE) {
                aptSignalReadyForSleep();
                aptWaitStatusEvent();
            } else if (aptGetStatus() == APP_SUSPENDING) {
                aptReturnToMenu();
            }
            hidScanInput();
            u32 keydown = hidKeysDown();
                   if (keydown & KEY_A) {  
						if(current_column == 1) {
							if(num_dirs != 0) {
								repeat = 0;
								strcpy(prev_dir_name, current_dir_name);
								if (strlen(current_dir_name)>1) strcat(current_dir_name, "/");
								strcat(current_dir_name, dir_list[current_dir_selection]);
							}
						} else {
							if(num_files != 0) {
								repeat = 0;
								return_value = 0;
								//strcpy(result, file_list[current_file_selection]);
								sprintf(result, "%s/%s", current_dir_name, file_list[current_file_selection]);
								break;
							}
						}
					}
                    if (keydown & KEY_Y) {
                            repeat = 0;
                            char* findpath = strrchr(current_dir_name,'/');
                        if(findpath > current_dir_name) 
                            findpath[0] = '\0';
                        else 
                            findpath[1] = '\0';
                    }
					if (keydown & KEY_B ) { 
						return_value = -1;
						repeat = 0;
						break;
					}
					if (keydown & KEY_X ) { 
						return_value = 1;
						repeat = 0;
						break;
					}
					if (keydown & KEY_UP) {  
						if(current_column == 0) {
							if(current_file_selection) {
								current_file_selection--;
								if(current_file_in_scroll == 0) {
									//clear_screen(COLOR_BG);
									current_file_scroll_value--;
								} else {
									current_file_in_scroll--;
								}
							}
						} else {
							if(current_dir_selection) {
								current_dir_selection--;
								if(current_dir_in_scroll == 0) {
									//clear_screen(COLOR_BG);
									current_dir_scroll_value--;
								} else {
									current_dir_in_scroll--;
								}
							}
						}
					}
					if (keydown & KEY_DOWN) { 
						if(current_column == 0) {
							if(current_file_selection < (num_files - 1)) {
								current_file_selection++;
								if(current_file_in_scroll == (FILE_LIST_ROWS - 1)) {
									//clear_screen(COLOR_BG);
									current_file_scroll_value++;
								} else {
									current_file_in_scroll++;
								}
							}
						} else {
							if(current_dir_selection < (num_dirs - 1)) {
								current_dir_selection++;
								if(current_dir_in_scroll == (FILE_LIST_ROWS - 1)) {
									//clear_screen(COLOR_BG);
									current_dir_scroll_value++;
								} else {
									current_dir_in_scroll++;
								}
							}
						}
					}
					if (keydown & KEY_L) {  
						if(current_column == 0) {
							if(current_file_selection>FILE_LIST_ROWS) {
								current_file_selection-=FILE_LIST_ROWS;
								current_file_scroll_value -= FILE_LIST_ROWS;
								if (current_file_in_scroll>current_file_selection){
									//clear_screen(COLOR_BG);
									current_file_scroll_value=0;
									current_file_in_scroll=current_file_selection;
								}
							} else {
								current_file_selection=0;
								current_file_scroll_value=0;
								current_file_in_scroll=0;
							}
						} else {
							if(current_dir_selection) {
								current_dir_selection--;
								if(current_dir_in_scroll == 0) {
									//clear_screen(COLOR_BG);
									current_dir_scroll_value--;
								} else {
									current_dir_in_scroll--;
								}
							}
						}
					}
					if (keydown & KEY_R) {  
						if(current_column == 0) {
							if(current_file_selection < (num_files - 1 - FILE_LIST_ROWS)) {
								current_file_selection+=FILE_LIST_ROWS;
								current_file_scroll_value+=FILE_LIST_ROWS;
								if (current_file_scroll_value>(num_files - FILE_LIST_ROWS)){
									//clear_screen(COLOR_BG);
									current_file_scroll_value=num_files - FILE_LIST_ROWS;
									current_file_in_scroll=  FILE_LIST_ROWS - (num_files - current_file_selection);
								}
									//clear_screen(COLOR_BG);
							} else {
								current_file_selection = num_files - 1;
								current_file_in_scroll = (num_files<=FILE_LIST_ROWS - 1)?num_files:FILE_LIST_ROWS - 1;
								current_file_scroll_value = (num_files > FILE_LIST_ROWS)?num_files - FILE_LIST_ROWS:0;
							}
						} else {
							if(current_dir_selection < (num_dirs - 1)) {
								current_dir_selection++;
								if(current_dir_in_scroll == (FILE_LIST_ROWS - 1)) {
									//clear_screen(COLOR_BG);
									current_dir_scroll_value++;
								} else {
									current_dir_in_scroll++;
								}
							}
						}
					}
					if (keydown & KEY_LEFT) { 
						if(current_column == 1) {
							if(num_files != 0) current_column = 0;
						}
					}
					if (keydown & KEY_RIGHT) {  
						if(current_column == 0) {
							if(num_dirs != 0) current_column = 1;
						}
					}

            sf2d_end_frame();
            
			gui_DrawTopScreen();
            
            sf2d_swapbuffers();


		}

		// free pointers
		for(i = 0; i < num_files; i++) free(file_list[i]);
		free(file_list);

		for(i = 0; i < num_dirs; i++) free(dir_list[i]);
		free(dir_list);
        
        free(file_name);
	}
	
	
	return return_value;
}
예제 #14
0
파일: gui.c 프로젝트: nop90/Vex3DS
/*
	Main function that runs all the stuff
*/
void gui_MainMenuRun(MENU *menu)
{
    APT_AppStatus status;
	MENUITEM *mi;

	done = 0;

	while(!done) {
		mi = menu->m + menu->itemCur; // pointer to highlite menu option

		while((status=aptGetStatus()) != APP_RUNNING) {

			if(status == APP_SUSPENDING)
			{
				aptReturnToMenu();
			}
			else if(status == APP_PREPARE_SLEEPMODE)
			{
				aptSignalReadyForSleep();
				aptWaitStatusEvent();
			}
			else if (status == APP_SLEEPMODE) {
			}
			else if (status == APP_EXITING) {
				return;
			}

		}
        
        hidScanInput();
        u32 keydown = hidKeysDown();
		if (keydown & KEY_A) 
            if(mi->itemOnA != NULL) {
//                gui_ClearScreen();
                (*mi->itemOnA)();
            }
		// B - exit or back to previous menu
		if (keydown & KEY_B) 
            return;
		// UP - arrow down
		if (keydown & KEY_UP)  
            if(--menu->itemCur < 0) menu->itemCur = menu->itemNum - 1;
		// DOWN - arrow up
		if (keydown & KEY_DOWN)  
            if(++menu->itemCur == menu->itemNum) menu->itemCur = 0;
		// LEFT - decrease parameter value
        if (keydown & KEY_LEFT) {  
			if(mi->itemPar != NULL && *mi->itemPar > 0) *mi->itemPar -= 1;
		}
		// RIGHT - increase parameter value
        if (keydown & KEY_RIGHT) {  
			if(mi->itemPar != NULL && *mi->itemPar < mi->itemParMaxValue) *mi->itemPar += 1;
		}
 
        sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);
        if(!done) {
            ShowMenu(menu); // show menu items
        }
                
        sf2d_end_frame();
                
		gui_DrawTopScreen();
 
        sf2d_swapbuffers();
	}
}
예제 #15
0
int main() 
{
	int i, x, y;
	
	touchPosition lastTouch;
	u32 repeatkeys = 0;
	int repeatstate = 0;
	int repeatcount = 0;
	
	running = 0;
	pause = 0;
	exitemu = 0;
	
	
		
	PPU_Init();
	
	
	srvInit();
		
	aptInit();
	aptOpenSession();
	APT_SetAppCpuTimeLimit(NULL, 30); // enables syscore usage
	aptCloseSession();

	gfxInit();
	hidInit(NULL);
	fsInit();
	
	GPU_Init(NULL);
	gpuCmdSize = 0x40000;
	gpuCmd = (u32*)linearAlloc(gpuCmdSize*4);
	GPU_Reset(gxCmdBuf, gpuCmd, gpuCmdSize);
	
	shader = SHDR_ParseSHBIN((u32*)blarg_shbin, blarg_shbin_size);
	
	GX_SetMemoryFill(gxCmdBuf, (u32*)gpuOut, 0x404040FF, (u32*)&gpuOut[0x2EE00], 0x201, (u32*)gpuDOut, 0x00000000, (u32*)&gpuDOut[0x2EE00], 0x201);
	gfxSwapBuffersGpu();
	
	UI_SetFramebuffer(gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL));
	
	BorderTex = (u32*)linearAlloc(512*256*4);
	MainScreenTex = (u32*)linearAlloc(512*256*4);
	SubScreenTex = (u32*)linearAlloc(512*256*4);
	BrightnessTex = (u8*)linearAlloc(8*256);
	
	borderVertices = (float*)linearAlloc(5*3 * 2 * sizeof(float));
	screenVertices = (float*)linearAlloc(7*3 * 2 * sizeof(float));
	
	float* fptr = &vertexList[0];
	for (i = 0; i < 5*3*2; i++) borderVertices[i] = *fptr++;
	for (i = 0; i < 7*3*2; i++) screenVertices[i] = *fptr++;
	

	sdmcArchive = (FS_archive){0x9, (FS_path){PATH_EMPTY, 1, (u8*)""}};
	FSUSER_OpenArchive(NULL, &sdmcArchive);
	
	if (!LoadBorder("/blargSnesBorder.bmp"))
		CopyBitmapToTexture(defaultborder, BorderTex, 400, 240, 0xFF, 0, 64, true);
		
	CopyBitmapToTexture(screenfill, PPU_MainBuffer, 256, 224, 0, 16, 64, false);
	memset(PPU_SubBuffer, 0, 256*256*4);
	memset(PPU_Brightness, 0xFF, 224);
	
	UI_Switch(&UI_ROMMenu);
	
	svcCreateEvent(&SPCSync, 0);
	
	aptSetupEventHandler();

	
	APP_STATUS status;
	while((status = aptGetStatus()) != APP_EXITING)
	{
		if(status == APP_RUNNING)
		{
			svcSignalEvent(SPCSync);
			
			hidScanInput();
			u32 press = hidKeysDown();
			u32 held = hidKeysHeld();
			u32 release = hidKeysUp();
			
			GPUCMD_SetBuffer(gpuCmd, gpuCmdSize, 0);
			RenderTopScreen();
			GPUCMD_Finalize();
			GPUCMD_Run(gxCmdBuf);
			
			if (running)
			{
				// emulate
				
				CPU_Run(); // runs the SNES for one frame. Handles PPU rendering.
				
				// SRAM autosave check
				// TODO: also save SRAM under certain circumstances (pausing, returning to home menu, etc)
				framecount++;
				if (!(framecount & 7))
					SNES_SaveSRAM();
			}
			else
			{
				// update UI
				
				if (held & KEY_TOUCH)
				{
					hidTouchRead(&lastTouch);
					UI_Touch(true, lastTouch.px, lastTouch.py);
					held &= ~KEY_TOUCH;
				}
				else if (release & KEY_TOUCH)
				{
					UI_Touch(false, lastTouch.px, lastTouch.py);
					release &= ~KEY_TOUCH;
				}
				
				if (press)
				{
					UI_ButtonPress(press);
					
					// key repeat
					repeatkeys = press & (KEY_UP|KEY_DOWN|KEY_LEFT|KEY_RIGHT);
					repeatstate = 1;
					repeatcount = 15;
				}
				else if (held == repeatkeys)
				{
					repeatcount--;
					if (!repeatcount)
					{
						repeatcount = 7;
						if (repeatstate == 2)
							UI_ButtonPress(repeatkeys);
						else
							repeatstate = 2;
					}
				}
			}
			
			UI_SetFramebuffer(gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL));
			UI_Render();
			
			/*GPUCMD_SetBuffer(gpuCmd, gpuCmdSize, 0);
			RenderTopScreen();
			GPUCMD_Finalize();
			GPUCMD_Run(gxCmdBuf);*/
			
			// flush the bottomscreen cache while the PICA200 is busy rendering
			GSPGPU_FlushDataCache(NULL, gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL), 0x38400);
			
			// wait for the PICA200 to finish drawing
			gspWaitForP3D();
			
			// copy new screen textures
			// SetDisplayTransfer with flags=2 converts linear graphics to the tiled format used for textures
			GX_SetDisplayTransfer(gxCmdBuf, PPU_MainBuffer, 0x01000200, MainScreenTex, 0x01000200, 0x2);
			gspWaitForPPF();
			GX_SetDisplayTransfer(gxCmdBuf, PPU_SubBuffer, 0x01000200, SubScreenTex, 0x01000200, 0x2);
			gspWaitForPPF();
			
			// copy brightness.
			// TODO do better
			u8* bptr = BrightnessTex;
			for (i = 0; i < 224;)
			{
				u32 pixels = *(u32*)&PPU_Brightness[i];
				i += 4;
				
				*bptr = (u8)pixels;
				pixels >>= 8;
				bptr += 2;
				*bptr = (u8)pixels;
				pixels >>= 8;
				bptr += 6;
				
				*bptr = (u8)pixels;
				pixels >>= 8;
				bptr += 2;
				*bptr = (u8)pixels;
				pixels >>= 8;
				bptr += 22;
			}
			
			// transfer the final color buffer to the LCD and clear it
			// we can mostly overlap those two operations
			GX_SetDisplayTransfer(gxCmdBuf, gpuOut, 0x019001E0, (u32*)gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL), 0x019001E0, 0x01001000);
			svcSleepThread(20000);
			GX_SetMemoryFill(gxCmdBuf, gpuOut, 0x404040FF, &gpuOut[0x2EE00], 0x201, gpuDOut, 0x00000000, &gpuDOut[0x2EE00], 0x201);
			gspWaitForPPF();
			gspWaitForPSC0();

			gspWaitForEvent(GSPEVENT_VBlank0, false);
			gfxSwapBuffersGpu();
		}
		else if(status == APP_SUSPENDING)
예제 #16
0
파일: main.c 프로젝트: smealum/ctrrpc
void conn_main() {
    APP_STATUS status;
    u32 it = 0;
    int ret = 0;
    int first = 1;
    int exiting = 0;

    while((status = aptGetStatus()) != APP_EXITING)
    {
        hidScanInput();
        consoleClear(&bot);

        print(&bot, "frame: %08x\n", it);
        print(&bot, "ret: %08x\n", ret);
        print(&bot, "last_cmd: %02x\n", last_cmd & 0xFF);
        int i;for(i=0;i<GSPEVENT_MAX;i++)print(&bot, "%d : %08X\n", i, gspEventCounts[i]);

        if(!first) {
            u32 bytes_read = 0;

            while(1) {
                ret = recv(sock, &cmd, 4, 0);
                if(ret < 0) {
                    if(ret == -EWOULDBLOCK)
                        continue;
                    break;
                }

                if(!cmd.numarg)cmd.numarg=7;
                u32 size=cmd.numarg*4;
                ret = recv(sock, &cmd.args, size, 0);
                if(ret < 0) {
                    if(ret == -EWOULDBLOCK)
                        continue;
                    break;
                }

                bytes_read += ret;
                if(bytes_read == size) {
                    svcSignalEvent(new_cmd_event);
                    svcWaitSynchronization(cmd_done_event, U64_MAX);
                    svcClearEvent(cmd_done_event);

                    size=4+4*resp.numarg;
                    send(sock, &resp, size, 0);

                    if(last_cmd_result == 0xDEAD)
                        exiting = 1;
                    break;
                }
            }
        }

        first = 0;
        it++;

        if(enable_draw)
            renderFrame(); 

        u32 keys = hidKeysUp();
        if(keys & KEY_A || exiting)
            break;     
    }
}
예제 #17
0
파일: apt.c 프로젝트: botanyaki/ctrulib
static void __handle_notification(void) {
	APT_Signal type;
	Result ret=0;

	// Get notification type.
	aptOpenSession();
	ret = APT_InquireNotification(currentAppId, &type);
	aptCloseSession();
	if(R_FAILED(ret)) return;

	_aptDebug(1, type);

	switch(type)
	{
	case APTSIGNAL_HOMEBUTTON:
	case APTSIGNAL_POWERBUTTON:
		// The main thread should call aptReturnToMenu() when the status gets set to this.
		if(aptGetStatus() == APP_RUNNING)
		{
			aptOpenSession();
			APT_ReplySleepQuery(currentAppId, 0x0);
			aptCloseSession();
		
			if(type == APTSIGNAL_HOMEBUTTON)  aptSetStatusPower(0);
			if(type == APTSIGNAL_POWERBUTTON) aptSetStatusPower(1);
			aptSetStatus(APP_SUSPENDING);
		}
		break;

	case APTSIGNAL_PREPARESLEEP:
		// Reply to sleep-request.
		aptStatusBeforeSleep = aptGetStatus();
		aptSetStatus(APP_PREPARE_SLEEPMODE);
		svcWaitSynchronization(aptSleepSync, U64_MAX);
		svcClearEvent(aptSleepSync);
		
		aptOpenSession();
		APT_ReplySleepQuery(currentAppId, 0x1);
		aptCloseSession();
		break;

	case APTSIGNAL_ENTERSLEEP:
		if(aptGetStatus() == APP_PREPARE_SLEEPMODE)
		{
			// Report into sleep-mode.
			aptSetStatus(APP_SLEEPMODE);
			
			aptOpenSession();
			APT_ReplySleepNotificationComplete(currentAppId);
			aptCloseSession();
		}
		break;

	// Leaving sleep-mode.
	case APTSIGNAL_WAKEUP:
		if(aptGetStatus() == APP_SLEEPMODE)
		{
			if(aptStatusBeforeSleep == APP_RUNNING)GSPGPU_SetLcdForceBlack(0);

			// Restore old aptStatus.
			aptSetStatus(aptStatusBeforeSleep);
		}
		break;

	default:
		break;
	}
}
예제 #18
0
파일: main.c 프로젝트: smealum/ctrrpc
/*----------------*/
int main(int argc, char *argv[])
{
    APP_STATUS status;

    srvInit();
    aptInit(APPID_APPLICATION);
    gfxInit();
    hidInit(NULL);
    fsInit();

    svcCreateEvent(&new_cmd_event, 0);
    svcCreateEvent(&cmd_done_event, 0);
    svcCreateThread(&thread, cmd_thread_func, 0x0,
                    (u32*)((char*)thread_stack + sizeof(thread_stack)),
                    0x31, 0xfffffffe);

    int where = 0;
    u32 ret = SOC_Initialize((u32*)0x08000000, 0x48000);

    if(ret == 0) {
        listen_socket = socket(AF_INET, SOCK_STREAM, 0);
        if(listen_socket == -1) {
            where = 1;
            ret = SOC_GetErrno();
        }
        else {
            u32 tmp = fcntl(listen_socket, F_GETFL);
            fcntl(listen_socket, F_SETFL, tmp | O_NONBLOCK);

            struct sockaddr_in addr;
            addr.sin_family = AF_INET;
            addr.sin_port = __swap16(PORT);
            addr.sin_addr.s_addr = INADDR_ANY;

            ret = bind(listen_socket, (struct sockaddr *)&addr, sizeof(addr));
            if(ret != 0) {
                where = 2;
                ret = SOC_GetErrno();
            }
            else {
                ret = listen(listen_socket, 1);
                if(ret == -1) {
                    ret = SOC_GetErrno();
                    where = 3;
                }
            }
        }

    }

    u32 it = 0;
    int accept_errno = 0;
    int first = 1;


    while((status = aptGetStatus()) != APP_EXITING)
    {
        hidScanInput();
        consoleClear(&top);

        print(&top, "newver\n");
        print(&top, "ret: %08x, where: %d\n", ret, where);
        print(&top, "frame: %08x\n", it);
        u32 ip = gethostid();
        print(&top, "ip: %d.%d.%d.%d\n", ip & 0xFF, (ip>>8)&0xFF, (ip>>16)&0xFF, (ip>>24)&0xFF);
                
        if(accept_errno != 0) print(&top, "accept returned errno %d\n", accept_errno);

        if(!first) {
            int s = accept(listen_socket, NULL, NULL);
            if(s == -1) {
                int err = SOC_GetErrno();

                if(err != -EWOULDBLOCK)
                    accept_errno = err;
            }
            else {
                sock = s;
                conn_main();
                closesocket(sock);
            }
        }

        it++;
        first = 0;
        if(enable_draw)
            renderFrame(); 

        u32 keys = hidKeysUp();
        if(keys & KEY_A)
            break;
    }

    thread_exit = 1;
    svcSignalEvent(new_cmd_event);
    svcWaitSynchronization(thread, U64_MAX);
    svcCloseHandle(thread);

    svcCloseHandle(new_cmd_event);
    svcCloseHandle(cmd_done_event);

    SOC_Shutdown();
    fsExit();
    hidExit();
    gfxExit();
    aptExit();
    srvExit();
    return 0;
}
예제 #19
0
파일: main.c 프로젝트: Tybus/3Dfrogr
int main()
{
	initSrv();

	aptInit(APPID_APPLICATION);

	gspGpuInit();

	hidInit(NULL);

	Handle fsuHandle;
	srv_getServiceHandle(NULL, &fsuHandle, "fs:USER");
	FSUSER_Initialize(fsuHandle);

	aptSetupEventHandler();
    init_map();
    int i;
    int j;
    int p=4;
    int d=0;
    int q;
    int frogx = 0;
    int frogy = 0;
    int carx[6][9];
    int logx[5][6];

    // Cant use rand.
    //for(d=1;d<6;d++){
    //    while(p>4){
    //        p = rand();
    //    }
    //    carx[d]=26+p;

     for(d=0;d<8;d++){
        carx[0][d]=26;
        if(d<5){
            logx[0][d]=26;
        }
        d++;
    }
    for(d=1;d<8;d++){
        if(d<5){
            logx[0][d]=0;
        }
        carx[0][d]=0;
        d++;
    }
    for(q=0;q<8;q++){

        for(d=1; d<6; d++){
            if(q<5){
                if(d<5){
                    logx[d][q]=26+p+6;
                }
            }
            carx[d][q]=26+p +6;
            p=p+6;
        }
        p=0;
        q++;
    }
    p= 0;
    for(q=1;q<8;q++){

        for(d=1;d<5;d++){
            if(q<5){
                if(d<5){
                    logx[d][q] = p-6;
                }
            }
            carx[d][q]=p-6;
            p=p-6;
        }
        p=0;
        q++;
     }

	while(!aptGetStatus()){
		u32 PAD=hidSharedMem[7];
		if (PAD == BUTTON_UP){
            frogy+= 1;
            }
        else if (PAD == BUTTON_DOWN){
            frogy+= -1;
            }
        else if (PAD == BUTTON_LEFT){
            frogx+= -1;
            }
        else if (PAD == BUTTON_RIGHT){
            frogx+=1;
            }

		u32 regData=PAD|0x01000000;
		init_map();
        for(i=0;i<6;i++){
            for(j=0;j<8;j++){
                draw_car(carx[i][j],15+j*15);
                if(i<5){
                    if(j<5){
                        draw_logs(logx[i][j],150+j*15);
                        }
                }
            }
        }
        draw_frog(frogx,frogy);
		//Checks Colition
        for(i=0;i<6;i++){
            for(j=0;j<8;j++){
                if(frogy==j+1){
                    if(frogx==carx[i][j]){
                        frogy =0;
                        frogx =0;
                    }
                }
            }
        }
        //Checks if frog in poodle
         if(frogy >9){
            for(i=0;i<5;i++){
                for(j=0;j<5;j++){
                    if(frogy==j+10){
                        if(frogx==logx[i][j] || frogx==logx[i][j]+1 || frogx==logx[i][j]+2){
                                frogx= frogx -1;
                        }
                        else{
                            frogx =0;
                            frogy =0;
                            }
                    }
                }
            }
        }
        //reinitialize the cars :D
        // Cant use f*****g rand
        //for(p=0;p<6;p++){
        //    if(carx[p]==0){
        //        d=5;
        //        while(d>4){
        //            d = rand();
        //        }
        //        carx[p]= 26+d;
        //     }
        //    else {
        //    carx[p]=carx[p]-1;
        //    }
        //}
        for(i=0;i<6;i++){
            for(j=0;j<9;j=j+2){
                if(i<5){
                    if(j<5){
                        if(logx[i][j]==0){
                            logx[i][j]=26;
                        }
                        else{
                        logx[i][j]=logx[i][j]-1;
                        }
                    }
                }
                if(carx[i][j]==0){
                    carx[i][j] =26;
                }
                else{
                    carx[i][j]=carx[i][j]-1;
                }
            }
        }
        for(i=0;i<6;i++){
            for(j=1;j<9;j=j+2){
                if(i<5){
                    if(j<5){
                        if(logx[i][j]==26){
                            logx[i][j]=0;
                        }
                        else{
                        logx[i][j]=logx[i][j]+1;
                        }
                    }
                }
                if(carx[i][j]==26){
                    carx[i][j]=0;
                    }
                else{
                    carx[i][j]= carx[i][j]+1;
                }
            }
        }
		copyBuffer();
		swapBuffers();
		GSPGPU_WriteHWRegs(NULL, 0x202A04, &regData, 4);
        svc_sleepThread(220000000);


    }

	svc_closeHandle(fsuHandle);
	hidExit();
	gspGpuInit();
	aptExit();
	svc_exitProcess();
	return 0;
}