Exemple #1
0
Result backupByConfig(u8 *filebuffer, size_t bufsize) {
	memset(filebuffer, 0, bufsize);
	
	FILE *configfile = fopen("config.txt", "r");
	if (configfile==NULL) return errno;

	char source_path[1000], sd_destination[1000];
	u32 source_archive;
	mediatypes_enum mtype;
	FS_archiveIds atype;
	int buf2size = 0x10000;
	u8 *buf2 = malloc(buf2size);
	if (buf2==NULL)
	{
		printf("malloc failed\n");
		gfxFlushBuffers();
		gfxSwapBuffers();
		return -1;
	}
	memset(buf2, 0, buf2size);
	
	while (fgets((char*) buf2, buf2size, configfile) != NULL) {
		if (sscanf((const char*) buf2, "DUMP \"%x:%999[^\"]\" \"%999[^\"]\"", (unsigned int*) &source_archive, source_path, sd_destination) == 3) {
			if (source_archive >= 0x80000000) {
				mtype = mediatype_NAND;
				atype = ARCH_SHARED_EXTDATA;
			}
			else {
				mtype = mediatype_SDMC;
				atype = ARCH_EXTDATA;
			}
			u32 extdata_archive_lowpathdata[3] = {mtype, source_archive, 0};
			extdata_archive = (FS_archive){atype, (FS_path){PATH_BINARY, 0xC, (u8*)extdata_archive_lowpathdata}};
			Result ret = FSUSER_OpenArchive(NULL, &extdata_archive);
			if(ret!=0)
			{
				printf("could not open archive\n");
				gfxFlushBuffers();
				gfxSwapBuffers();
				continue;
			}
			printf("Dumping from %s\n", source_path);
			gfxFlushBuffers();
			gfxSwapBuffers();
			ret = archive_copyfile(Extdata_Archive, SDArchive, source_path, sd_destination, filebuffer, 0, bufsize, source_path);
			if (ret) {
				printf("Copying failed!\n");
			} else {
				printf("Success.\n");
			}
			gfxFlushBuffers();
			gfxSwapBuffers();
			FSUSER_CloseArchive(NULL, &extdata_archive);
		}
	}
	free(buf2);
	fclose(configfile);
	
	return 0;
}
Exemple #2
0
Result restoreFromSd(u8 *buf, size_t bufsize) {
    memset(buf, 0, bufsize);

    FILE *configfile = fopen("config.txt", "r");
    if (configfile==NULL) return errno;

    char sd_source[1000], destination_path[1000];
    u32 destination_archive;
    mediatypes_enum mtype;
    FS_archiveIds atype;
    u8 *filebuffer2 = malloc(bufsize);
    memset(filebuffer2, 0, bufsize);

    while (fgets((char*) buf, bufsize, configfile) != NULL) {
        if (sscanf((const char*) buf, "RESTORE \"%999[^\"]\" \"%x:%999[^\"]\"", sd_source, (unsigned int*) &destination_archive, destination_path) == 3) {
            if (destination_archive >= 0x80000000) {
                mtype = mediatype_NAND;
                atype = ARCH_SHARED_EXTDATA;
            }
            else {
                mtype = mediatype_SDMC;
                atype = ARCH_EXTDATA;
            }
            u32 extdata_archive_lowpathdata[3] = {mtype, destination_archive, 0};
            extdata_archive = (FS_archive) {
                atype, (FS_path) {
                    PATH_BINARY, 0xC, (u8*)extdata_archive_lowpathdata
                }
            };
            Result ret = FSUSER_OpenArchive(NULL, &extdata_archive);
            if(ret!=0)
            {
                printf("could not open archive\n");
                gfxFlushBuffers();
                gfxSwapBuffers();
                continue;
            }
            printf("Restoring to %s\n", destination_path);
            gfxFlushBuffers();
            gfxSwapBuffers();
            ret = archive_copyfile(SDArchive, Extdata_Archive, sd_source, destination_path, filebuffer2, 0, bufsize, destination_path);
            if (ret) {
                printf("Copying failed!\n");
            } else {
                printf("Success.\n");
            }
            gfxFlushBuffers();
            gfxSwapBuffers();
            FSUSER_CloseArchive(NULL, &extdata_archive);
        }
    }
    free(filebuffer2);
    fclose(configfile);

    return 0;
}
Exemple #3
0
Result archive_copyfile(Archive inarchive, Archive outarchive, char *inpath, char *outpath, u8* buffer, u32 size, u32 maxbufsize, char *display_filepath)
{
	Result ret=0;
	u32 filesize=0;

	ret = archive_getfilesize(inarchive, inpath, &filesize);
	if (ret > 0) {
		printf("archive_getfilesize() ret=0x%08x, size=0x%08x\n", (unsigned int)ret, (unsigned int)filesize);
		gfxFlushBuffers();
		gfxSwapBuffers();
	}
	if(ret!=0)return ret;

	if(size==0 || size>filesize)
	{
		size = filesize;
	}

	if(size>maxbufsize)
	{
		printf("-----Size is too large.-----\n");
		gfxFlushBuffers();
		gfxSwapBuffers();
		ret = -1;
		return ret;
	}

	/*printf("Reading %s...\n", display_filepath);
	gfxFlushBuffers();
	gfxSwapBuffers();*/

	ret = archive_readfile(inarchive, inpath, buffer, size);
	if(ret!=0)
	{
		printf("-----Failed to read %s (%d): 0x%08x-----\n", display_filepath, (unsigned int) size, (unsigned int)ret);
		gfxFlushBuffers();
		gfxSwapBuffers();
		return ret;
	}

	/*printf("Writing %s...\n", display_filepath);
	gfxFlushBuffers();
	gfxSwapBuffers();*/

	ret = archive_writefile(outarchive, outpath, buffer, size);
	if(ret!=0)
	{
		printf("-----Failed to write %s (%d): 0x%08x-----\n", display_filepath, (unsigned int) size, (unsigned int)ret);
		gfxFlushBuffers();
		gfxSwapBuffers();
		return ret;
	}

	return ret;
}
Exemple #4
0
Result http_download(httpcContext *context)
{
	ret=0;
	//u8* framebuf_top;
	u32 statuscode=0;
	//u32 size=0;
	u32 contentsize=0;
	u8 *buf;

	ret = httpcBeginRequest(context);
	if(ret!=0)return ret;

	ret = httpcGetResponseStatusCode(context, &statuscode, 0);
	if(ret!=0)return ret;

	//printf("http status code: %i\n", statuscode);

	if(statuscode!=200){
		printf("status code not 200, it was %i", statuscode);
		gfxFlushBuffers();
		return -2;
	}

	ret=httpcGetDownloadSizeState(context, NULL, &contentsize);
	if(ret!=0)return ret;
	unsigned char *buffer = (unsigned char*)malloc(contentsize+1);

	consoleSelect(&topScreen);

	printf("HTTP status code: %i\n", statuscode);
	printf("%i bytes\n", contentsize);
	gfxFlushBuffers();

	buf = (u8*)malloc(contentsize);
	if(buf==NULL)return -1;
	memset(buf, 0, contentsize);


	ret = httpcDownloadData(context, buffer, contentsize, NULL);
	if(ret!=0)
	{
		free(buf);
		return ret;
	}

	consoleSelect(&bottomScreen);
	printf("%s", buffer);

	free(buf);

	return 0;
}
Exemple #5
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();
}
Exemple #6
0
int main()
{
	gfxInitDefault();
	//gfxSet3D(true); // uncomment if using stereoscopic 3D

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

		// Your code goes here

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

		// Example rendering code that displays a white pixel
		// Please note that the 3DS screens are sideways (thus 240x400 and 240x320)
		u8* fb = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, nullptr, nullptr);
		memset(fb, 127, 240*400*3);
		fb[3*(10+10*240)] = 0xFF;
		fb[3*(10+10*240)+1] = 0xFF;
		fb[3*(10+10*240)+2] = 0xFF;

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

	gfxExit();
	return 0;
}
Exemple #7
0
int main(int argc, char **argv)
{
	// Initialize services
	gfxInitDefault();

	//Initialize console on top screen. Using NULL as the second argument tells the console library to use the internal console structure as current one
	consoleInit(GFX_TOP, NULL);

	//Move the cursor to row 15 and column 19 and then prints "Hello World!" 
	//To move the cursor you have tu print "\x1b[r;cH", where r and c are respectively
	//the row and column where you want your cursor to move
	//The top screen has 30 rows and 50 columns
	//The bottom screen has 30 rows and 40 columns
	printf("\x1b[15;19HHello World!");

	//Move the cursor to the top left corner of the screen
	printf("\x1b[0;0H");

	//Print a REALLY crappy poeam with colored text
	//\x1b[cm set a SGR (Select Graphic Rendition) parameter, where c is the parameter that you want to set
	//Please refer to http://en.wikipedia.org/wiki/ANSI_escape_code#CSI_codes to see all the possible SGR parameters
	//As of now ctrulib support only these parameters:
	//Reset (0), Half bright colors (2), Reverse (7), Text color (30-37) and Background color (40-47)
	printf("Roses are \x1b[31mred\x1b[0m\n");
	printf("Violets are \x1b[34mblue\x1b[0m\n");
	printf("Piracy is bad\n");
	printf("While homebrews are good\n\n");

	//Black text on white background
	//In this example we set two parameter in a single escape sequence by separating them by a semicolon
	//\x1b[47;30m means that it will set a white background (47) and it will print white characters (30)
	//In this we also could have used the 
	printf("\x1b[47;30mBlack text on white background\x1b[0m");


	printf("\x1b[29;15HPress Start to exit.");
	// Main loop
	while (aptMainLoop())
	{
		//Scan all the inputs. This should be done once for each frame
		hidScanInput();

		//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
		u32 kDown = hidKeysDown();

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

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

		//Wait for VBlank
		gspWaitForVBlank();
	}

	// Exit services
	gfxExit();
	
	return 0;
}
Exemple #8
0
void drawFrame()
{
	u8* bufAdr=gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);

	int i, j;
	for(i=1;i<400;i++)
	{
		for(j=1;j<240;j++)
		{
			u32 v=(j+i*240)*3;
			bufAdr[v]=(pcCos(i+cnt)+4096)/32;
			bufAdr[v+1]=(pcCos(j-256+cnt)+4096)/64;
			bufAdr[v+2]=(pcCos(i+128-cnt)+4096)/32;
		}
	}
	gfxDrawText(GFX_TOP, GFX_LEFT, NULL, "ftPONY v0.0003 gamma\n", 240-fontDefault.height*1, 10);
	u32 ip = gethostid();
	char bof[256];
	sprintf(bof, "IP: %lu.%lu.%lu.%lu\n", ip & 0xFF, (ip>>8)&0xFF, (ip>>16)&0xFF, (ip>>24)&0xFF);
	gfxDrawText(GFX_TOP, GFX_LEFT, NULL, bof, 240-fontDefault.height*2, 10);

	gfxDrawText(GFX_TOP, GFX_LEFT, NULL, quotes[curQuote], 240-fontDefault.height*3, 10);
	i = countLines(superStr);
	while(i>240/fontDefault.height-3){cutLine(superStr);i--;}
	gfxDrawText(GFX_TOP, GFX_LEFT, NULL, superStr, 240-fontDefault.height*4, 20);
	cnt++;

	gfxFlushBuffers();
	gfxSwapBuffers();
}
Exemple #9
0
void drawFrames()
{
    drawFrame(GFX_TOP, 0x88, 0x66, 0x00);
    drawFrame(GFX_BOTTOM, 0x00, 0x00, 0x00);
    gfxFlushBuffers();
    gfxSwapBuffers();
}
Exemple #10
0
s32 menu_cb_choose_file (s32 idx, void *param) {
	s32 curidx = idx;
	s32 loaded = 0;

	while (aptMainLoop()) {
		gspWaitForVBlank();

		curidx = print_file_list(curidx, &g_file_list);	           
		u32 kDown = wait_key(); 

		if (kDown & KEY_B) {
			break;
		}
		else if (kDown & KEY_A) {
			consoleClear();
			loaded = menu_execute_function(curidx, &g_file_list, &curidx);
			printf("%s\n", loaded? "[+] Success":"[!] Failure");
			wait_any_key();
			if (loaded)
				break;
		}
		else if (kDown & KEY_UP) {
			curidx--;
		}
		else if (kDown & KEY_DOWN) {
			curidx++;
		}
		gfxFlushBuffers();
		gfxSwapBuffers();
	}
	return 0;
}
Exemple #11
0
void err_show(char file_name[], int line, char message[]) {
  quit_for_err = true;
  // Reset all screens
  consoleInit(GFX_TOP, &top_screen);
  consoleInit(GFX_BOTTOM, &debug_screen);
  consoleInit(GFX_BOTTOM, &instruction_screen);
  consoleSelect(&top_screen);
  printf("%s\n\t\tFATAL ERROR\n\n%s", BG_RED, RESET);
  printf("%s\n", file_name);
  printf("line %d\n", line);
  printf(message);
  printf("\n\nPlease raise an issue at:\ngithub.com/thatguywiththatname/3DES/issues\n");
  printf("With details of this error &\nwhat you were doing at the time\n");
  printf("\nPress A to close app\n");
  while (aptMainLoop()) {
    gspWaitForVBlank();
    hidScanInput();
    u32 exitkDown = hidKeysDown();
    if (exitkDown & KEY_A) {
      return;
    }
    gfxFlushBuffers();
    gfxSwapBuffers();
  }
}
Exemple #12
0
STATIC bool fatal_error(bool restart) {
    bool should_restart = false;
    if (restart) {
        printf("\x1b[28;12HPress Select to restart.");
    }
    printf("\x1b[29;12H  Press Start to exit.  ");

    while (aptMainLoop()) {
        hidScanInput();

        int down = hidKeysDown();
        if (down & KEY_START) {
            break;
        } else if (restart && (down & KEY_SELECT)) {
            should_restart = true;
            break;
        }

        gfxFlushBuffers();
        gfxSwapBuffers();

        gspWaitForVBlank();
    }

    gfxExit();

    return should_restart;
}
Exemple #13
0
/*! draw console to screen */
void
console_render(void)
{
  font_t *font;

  /* clear all screens */
  u8 black_color[] = { 0, 0, 0 };
  clear_screen(GFX_TOP,    GFX_LEFT,  black_color);
  clear_screen(GFX_BOTTOM,    GFX_LEFT,  black_color);

  /* look up font for status bar and draw status bar */
  font = find_font("sans", 10);
  if(font != NULL) {
    draw_text(GFX_BOTTOM, GFX_LEFT,  font, status, 20, 4);
    draw_text(GFX_BOTTOM, GFX_LEFT,  font, STATUS_STRING, 20, 220);
  }
  else
    debug("%s: couldn't find 'sans 10pt'\n", __func__);


  /* look up font for console and draw console */
  font = find_font("sans", 8);
  if(font != NULL)
    draw_text(GFX_TOP, GFX_LEFT,  font, buffer, 20, 5);
  else
    debug("%s: couldn't find 'sans 8pt'\n", __func__);

  /* flush framebuffer */
  gfxFlushBuffers();
  gspWaitForVBlank();
  gfxSwapBuffers();
}
Exemple #14
0
void ui_info_add(const char* info) {
    consoleSelect(&bottom_screen);
    printf(info);
    gfxFlushBuffers();
    gfxSwapBuffers();
    gspWaitForVBlank();
}
int main(int argc, char **argv)

{
	
	//Initialize some sounds for high quality sounding moans and SCREAMS from the ACTION!
	srvInit();
	aptInit();
	hidInit();
	csndInit();
	gfxInitDefault();
	consoleInit(GFX_TOP, NULL);



	printf("\x1b[1;5HGuess who is the freshest squid around?");
	wait(10000);
	printf("           ");
	printf("\x1b[5;19H\x1b[32m\ Marie Squid\x1b[0m\n");
	printf("\x1b[16;3HPress Start to know that such fresh exists.");
	printf("\x1b[17;3HPress A to get INTO IT!");

	

	// Main loop
	while (aptMainLoop())
	{
		//Scan all the inputs. This should be done once for each frame mostly for the shoots
		hidScanInput();
		

		//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
		hidScanInput();
		u32 kDown = hidKeysDown();
		if (kDown & KEY_START){   //PRESS START TO RETURN TO HBL
		}
		if (kDown & KEY_A){   // PRESS A TO PLAY
			audio_load("squit.bin");
		}
		
		
		// Flush and swap framebuffers
		gfxFlushBuffers();
		gfxSwapBuffers();

		//Wait for VBlank
		gspWaitForVBlank();
	}

	// Exit services... I know you want to come back...

	audio_stop();
	audio_stop();
	csndExit();
	gfxExit();
	hidExit();
	aptExit();
	srvExit();
	return 0;
}
Exemple #16
0
void dumpFolder(char *path, u32 lowpath_id, char *dumpfolder, u8 *filebuffer, size_t bufsize) {
	Handle extdata_dir;
	Result ret = FSUSER_OpenDirectory(NULL, &extdata_dir, extdata_archive, FS_makePath(PATH_CHAR, path));
	if (ret!=0) {
		printf("could not open dir\n");
		gfxFlushBuffers();
		gfxSwapBuffers();
		return;
	}
	char dirname[0x120];
	sprintf(dirname, "%s/%08x%s", dumpfolder, (unsigned int) lowpath_id, path);
	mkdir(dirname, 0777);
	
	FS_dirent dirStruct;
	char fileName[0x106] = "";
	int cont = 0;
	while(1) {
		u32 dataRead = 0;
		FSDIR_Read(extdata_dir, &dataRead, 1, &dirStruct);
		if(dataRead == 0) break;
		unicodeToChar(fileName, dirStruct.name);
		printf("name: %s%s%s\n", path, fileName, dirStruct.isDirectory ? " (DIRECTORY)" : "");
		gfxFlushBuffers();
		gfxSwapBuffers();
		cont++;
		if (dirStruct.isDirectory) {
			char newpath[0x120];
			sprintf(newpath, "%s%s/", path, fileName);
			dumpFolder(newpath, lowpath_id, dumpfolder, filebuffer, bufsize);
		} else {
			char file_inpath[0x120];
			char file_outpath[0x120];
			char file_display_path[0x120];

			sprintf(file_inpath, "%s%s", path, fileName);
			sprintf(file_outpath, "%s/%08x%s%s", dumpfolder, (unsigned int) lowpath_id, path, fileName);
			sprintf(file_display_path, "%08x%s%s", (unsigned int) lowpath_id, path, fileName);
			archive_copyfile(Extdata_Archive, SDArchive, file_inpath, file_outpath, filebuffer, 0, bufsize, file_display_path);
		}
	}
	printf("total files in 0x%08x%s: %d\n", (unsigned int) lowpath_id, path, (unsigned int) cont);
	gfxFlushBuffers();
	gfxSwapBuffers();
	FSDIR_Close(extdata_dir);
}
Exemple #17
0
void mvd_colorconvert()
{
	Result ret;

	FILE *f = NULL;

	u8* bufAdr = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL);
	u8* gfxtopadr = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);

	MVDSTD_Config config;

	printf("mvd color-format-conversion example.\n");

	f = fopen("sdmc:/mvd_indata.bin", "r");
	if(f)
	{
		fread(inaddr, 1, 0x46500, f);
		fclose(f);
	}
	else
	{
		memcpy(inaddr, bufAdr, 320*240*3);
	}

	memset(gfxtopadr, 0, 0x46500);
	GSPGPU_FlushDataCache(inaddr, 0x46500);
	GSPGPU_FlushDataCache(gfxtopadr, 0x46500);

	ret = mvdstdInit(MVDMODE_COLORFORMATCONV, MVD_INPUT_YUYV422, MVD_OUTPUT_BGR565, 0, NULL);
	printf("mvdstdInit(): 0x%08x\n", (unsigned int)ret);

	if(ret==0)
	{
		mvdstdGenerateDefaultConfig(&config, 320, 240, 320, 240, (u32*)inaddr, (u32*)outaddr, (u32*)&outaddr[0x12c00]);

		ret = mvdstdConvertImage(&config);
		printf("mvdstdConvertImage(): 0x%08x\n", (unsigned int)ret);
	}

	f = fopen("sdmc:/mvd_outdata.bin", "w");
	if(f)
	{
		fwrite(outaddr, 1, 0x100000, f);
		fclose(f);
	}

	memcpy(gfxtopadr, outaddr, 0x46500);

	mvdstdExit();

	gfxFlushBuffers();
	gfxSwapBuffersGpu();
	gspWaitForVBlank();
}
Exemple #18
0
/*! draw console to screen */
void
console_render(void)
{
  /* print tcp table */
  print_tcp_table();

  /* flush framebuffer */
  gfxFlushBuffers();
  gspWaitForVBlank();
  gfxSwapBuffers();
}
Exemple #19
0
void sleep(int milliseconds)
{
    // attempts to emulate sleep in ms by assuming 60 fps
    int i;
    for (i = 0; i < (int)(milliseconds/16.67); i++)
    {
        gspWaitForVBlank();
        gfxFlushBuffers();
        gfxSwapBuffers();
    }
}
Exemple #20
0
int main(int argc, char** argv)
{

    gfxInitDefault();
    InitOutput();

    consoleClear();

    Print("Press A to begin...\n");

    // unsigned int test_counter = 0; // Moving it here causes this app to refuse to boot at all.

    while (aptMainLoop()) {
        gfxFlushBuffers();
        gfxSwapBuffers();

        hidScanInput();
        u32 kDown = hidKeysDown();
        if (kDown & KEY_START) {
            break;
        } else if (kDown & KEY_A) {
            consoleClear();

            unsigned int test_counter = 0; // This configuration works, but obviously only test 0 would run.

            TestCaller tests[] = {
                FS::TestAll,
                CPU::Integer::TestAll,
                CPU::Memory::TestAll,
                Kernel::TestAll,
                GPU::TestAll
            };

            if (test_counter < (sizeof(tests) / sizeof(tests[0]))) {
                tests[test_counter]();
                test_counter++;
            } else {
                break;
            }

            Log("\n");
            Print("Press A to continue...\n");
        }

        gspWaitForVBlank();
    }

    consoleClear();

    gfxExit();
    DeinitOutput();

    return 0;
}
Exemple #21
0
static int netloader_draw_progress(void) {
    char info[1024];
    sprintf(info, "Transferring: %s\n\n%s",netloadedPath,progress);
    drawError(GFX_BOTTOM, "NetLoader", info, 0);
    gfxFlushBuffers();
    gfxSwapBuffers();

    gspWaitForVBlank();

    return 0;
}
Exemple #22
0
void wait_key(const u32 key)
{
    while (aptMainLoop()) {
	hidScanInput();
	if (hidKeysDown() & key) break;

	gfxFlushBuffers();
	gfxSwapBuffers();

	gspWaitForVBlank();
    }
}
Exemple #23
0
int main(int argc, char** argv) {


	gfxInitDefault();

	consoleInit(GFX_TOP, NULL);


	svcCreateEvent(&threadRequest,0);
	u32 *threadStack = memalign(32, STACKSIZE);
	Result ret = svcCreateThread(&threadHandle, threadMain, 0, &threadStack[STACKSIZE/4], 0x3f, 0);

	printf("thread create returned %x\n", ret);

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

		printf("\x1b[5;0H");
		printf("thread counter = %d\n",threadcount);

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

		if (kDown & KEY_A)
			svcSignalEvent(threadRequest);

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

	// tell thread to exit
	threadExit = true;

	// signal the thread
	svcSignalEvent(threadRequest);

	// give it time to exit
	svcSleepThread(10000000ULL);

	// close handles and free allocated stack
	svcCloseHandle(threadRequest);
	svcCloseHandle(threadHandle);
	free(threadStack);


	gfxExit();
	return 0;
}
Exemple #24
0
//---------------------------------------------------------------------------------
static void consoleClearLine(char mode) {
//---------------------------------------------------------------------------------

	int i = 0;
	int colTemp;

	switch (mode)
	{
	case '[':
	case '0':
		{
			colTemp = currentConsole->cursorX ;

			while(i++ < (currentConsole->windowWidth - colTemp)) {
				consolePrintChar(' ');
			}

			currentConsole->cursorX  = colTemp;

			break;
		}
	case '1':
		{
			colTemp = currentConsole->cursorX ;

			currentConsole->cursorX  = 0;

			while(i++ < ((currentConsole->windowWidth - colTemp)-2)) {
				consolePrintChar(' ');
			}

			currentConsole->cursorX  = colTemp;

			break;
		}
	case '2':
		{
			colTemp = currentConsole->cursorX ;

			currentConsole->cursorX  = 0;

			while(i++ < currentConsole->windowWidth) {
				consolePrintChar(' ');
			}

			currentConsole->cursorX  = colTemp;

			break;
		}
	}
	gfxFlushBuffers();
}
Exemple #25
0
void waitForKey() {
    while (aptMainLoop()) {
        gfxSwapBuffers();
        gfxFlushBuffers();
        gspWaitForVBlank();

        hidScanInput();
        u32 kDown = hidKeysDown();

        if (kDown)
            break;
    }
}
Exemple #26
0
s32 main (void) {
	// Initialize services
	//gfxInitDefault();
	//gfxSwapBuffers(); 
	Result res;
	gfxInitDefault();
	gfxSwapBuffers(); 
	
	
	consoleInit(GFX_TOP,NULL);
	//printf("miniPasta2\n\n");

	res=suInit();
	printf("su init: %08X\n",res);

	//res=khaxInit();
	//printf("khax init: %08X\n",res);
	
	res=brahma_init();
	printf("brahma init: %08X\n",res);
	
    load_arm9_payload_from_mem (arm9payload_bin, arm9payload_bin_size);
	printf("payload loaded to RAM\n");
	
	res=firm_reboot();	
	printf("firm reboot: %08X\n",res);
	
	while (aptMainLoop())
	{
		//Scan all the inputs. This should be done once for each frame
		hidScanInput();

		//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
		u32 kDown = hidKeysDown();

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

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

		//Wait for VBlank
		gspWaitForVBlank();
	}
	
	
	
	gfxExit();
	// Return to hbmenu
	return 0;
}
Exemple #27
0
std::string getInput(HB_Keyboard* sHBKB, bool &bCancelled)
{
    sHBKB->HBKB_Clean();
    touchPosition touch;
    u8 KBState = 4;
    std::string input;
    while (KBState != 1 || input.length() == 0)
    {
        if (!aptMainLoop())
        {
            bCancelled = true;
            break;
        }

        hidScanInput();
        hidTouchRead(&touch);
        KBState = sHBKB->HBKB_CallKeyboard(touch);
        input = sHBKB->HBKB_CheckKeyboardInput();

        // If the user cancelled the input
        if (KBState == 3)
        {
            bCancelled = true;
            break;
        }
        // Otherwise if the user has entered a key
        else if (KBState != 4)
        {
            printf("%c[2K\r", 27);

            // If input string is > 50 characters, show just the right hand side
            if (input.length() > 49)
            {
                printf("%s", input.substr(input.length() - 49).c_str());
            }
            else
            {
                printf("%s", input.c_str());
            }
        }

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

        //Wait for VBlank
        gspWaitForVBlank();
    }
    printf("\n");
    return input;
}
Exemple #28
0
//---------------------------------------------------------------------------------
static void consoleCls(char mode) {
//---------------------------------------------------------------------------------

	int i = 0;
	int colTemp,rowTemp;

	switch (mode)
	{
	case '[':
	case '0':
		{
			colTemp = currentConsole->cursorX ;
			rowTemp = currentConsole->cursorY ;

			while(i++ < ((currentConsole->windowHeight * currentConsole->windowWidth) - (rowTemp * currentConsole->consoleWidth + colTemp)))
				consolePrintChar(' ');

			currentConsole->cursorX  = colTemp;
			currentConsole->cursorY  = rowTemp;
			break;
		}
	case '1':
		{
			colTemp = currentConsole->cursorX ;
			rowTemp = currentConsole->cursorY ;

			currentConsole->cursorY  = 0;
			currentConsole->cursorX  = 0;

			while (i++ < (rowTemp * currentConsole->windowWidth + colTemp))
				consolePrintChar(' ');

			currentConsole->cursorX  = colTemp;
			currentConsole->cursorY  = rowTemp;
			break;
		}
	case '2':
		{
			currentConsole->cursorY  = 0;
			currentConsole->cursorX  = 0;

			while(i++ < currentConsole->windowHeight * currentConsole->windowWidth)
				consolePrintChar(' ');

			currentConsole->cursorY  = 0;
			currentConsole->cursorX  = 0;
			break;
		}
	}
	gfxFlushBuffers();
}
Exemple #29
0
int deleteEntry(u64 PID, u8 * buffer, u64 size) {
	u64 *file = (u64 *) buffer;

	u64 entry = 0;
	while (true) {

		if (file[entry * 0x2] == PID)
			break;

		entry++;
		if (entry * ENTRY_SIZE >= size)
			break;
	}

	if (entry * ENTRY_SIZE >= size) {
		printf("Version record not found.\n");
		debug = true;
		return 2;
	} else {
		printf("Version record found at entry %X.\n",
				(unsigned int) (entry & 0xFFFFFFFF));

		gfxFlushBuffers();
		gfxSwapBuffers();

		if (debug) {
			printf("Do you want to remove this record?(A/B)\n");
			gfxFlushBuffers();
			gfxSwapBuffers();
			if (confirm() == false) {
				return 1;
			}
		}

		file[entry * 0x2] = 0x0;
	}
	return 0;
}
Exemple #30
0
void 	waitKey(u32 keyWait)
{
 while (aptMainLoop())
  {
    hidScanInput();

    u32 kPressed = hidKeysDown();
    if (kPressed & keyWait) break;

    gfxFlushBuffers();
    gfxSwapBuffers();
    gspWaitForVBlank();
  } 
}